common: Move some board functions out of common.h
[platform/kernel/u-boot.git] / board / ti / am57xx / board.c
index 8dfb2ee..c755821 100644 (file)
@@ -8,8 +8,11 @@
  */
 
 #include <common.h>
+#include <env.h>
+#include <init.h>
 #include <palmas.h>
 #include <sata.h>
+#include <serial.h>
 #include <usb.h>
 #include <asm/omap_common.h>
 #include <asm/omap_sec_common.h>
 #include <asm/arch/sata.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/omap.h>
-#include <environment.h>
 #include <usb.h>
 #include <linux/usb/gadget.h>
 #include <dwc3-uboot.h>
 #include <dwc3-omap-uboot.h>
 #include <ti-usb-phy-uboot.h>
 #include <mmc.h>
+#include <dm/uclass.h>
 
 #include "../common/board_detect.h"
 #include "mux_data.h"
@@ -623,7 +626,7 @@ void am57x_idk_lcd_detect(void)
 {
        int r = -ENODEV;
        char *idk_lcd = "no";
-       uint8_t buf = 0;
+       struct udevice *dev;
 
        /* Only valid for IDKs */
        if (board_is_x15() || board_is_am572x_evm())
@@ -633,32 +636,29 @@ void am57x_idk_lcd_detect(void)
        if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
                goto out;
 
-       r = i2c_set_bus_num(OSD_TS_FT_BUS_ADDRESS);
-       if (r) {
-               printf("%s: Failed to set bus address to %d: %d\n",
-                      __func__, OSD_TS_FT_BUS_ADDRESS, r);
-               goto out;
-       }
-       r = i2c_probe(OSD_TS_FT_CHIP_ADDRESS);
+       r = i2c_get_chip_for_busnum(OSD_TS_FT_BUS_ADDRESS,
+                                   OSD_TS_FT_CHIP_ADDRESS, 1, &dev);
        if (r) {
+               printf("%s: Failed to get I2C device %d/%d (ret %d)\n",
+                      __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
+                      r);
                /* AM572x IDK has no explicit settings for optional LCD kit */
-               if (board_is_am571x_idk()) {
+               if (board_is_am571x_idk())
                        printf("%s: Touch screen detect failed: %d!\n",
                               __func__, r);
-               }
                goto out;
        }
 
        /* Read FT ID */
-       r = i2c_read(OSD_TS_FT_CHIP_ADDRESS, OSD_TS_FT_REG_ID, 1, &buf, 1);
-       if (r) {
+       r = dm_i2c_reg_read(dev, OSD_TS_FT_REG_ID);
+       if (r < 0) {
                printf("%s: Touch screen ID read %d:0x%02x[0x%02x] failed:%d\n",
                       __func__, OSD_TS_FT_BUS_ADDRESS, OSD_TS_FT_CHIP_ADDRESS,
                       OSD_TS_FT_REG_ID, r);
                goto out;
        }
 
-       switch (buf) {
+       switch (r) {
        case OSD_TS_FT_ID_5606:
                idk_lcd = "osd101t2045";
                break;
@@ -667,7 +667,7 @@ void am57x_idk_lcd_detect(void)
                break;
        default:
                printf("%s: Unidentifed Touch screen ID 0x%02x\n",
-                      __func__, buf);
+                      __func__, r);
                /* we will let default be "no lcd" */
        }
 out:
@@ -692,6 +692,7 @@ int board_late_init(void)
 {
        setup_board_eeprom_env();
        u8 val;
+       struct udevice *dev;
 
        /*
         * DEV_CTRL.DEV_ON = 1 please - else palmas switches off in 8 seconds
@@ -723,6 +724,9 @@ int board_late_init(void)
 
        am57x_idk_lcd_detect();
 
+       /* Just probe the potentially supported cdce913 device */
+       uclass_get_device(UCLASS_CLK, 0, &dev);
+
 #if !defined(CONFIG_SPL_BUILD)
        board_ti_set_ethaddr(2);
 #endif
@@ -1099,6 +1103,16 @@ int board_fit_config_name_match(const char *name)
 }
 #endif
 
+#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
+int fastboot_set_reboot_flag(void)
+{
+       printf("Setting reboot to fastboot flag ...\n");
+       env_set("dofastboot", "1");
+       env_save();
+       return 0;
+}
+#endif
+
 #ifdef CONFIG_TI_SECURE_DEVICE
 void board_fit_image_post_process(void **p_image, size_t *p_size)
 {
@@ -1110,15 +1124,5 @@ void board_tee_image_process(ulong tee_image, size_t tee_size)
        secure_tee_install((u32)tee_image);
 }
 
-#if CONFIG_IS_ENABLED(FASTBOOT) && !CONFIG_IS_ENABLED(ENV_IS_NOWHERE)
-int fastboot_set_reboot_flag(void)
-{
-       printf("Setting reboot to fastboot flag ...\n");
-       env_set("dofastboot", "1");
-       env_save();
-       return 0;
-}
-#endif
-
 U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_TEE, board_tee_image_process);
 #endif