ti: remove usage of DM_I2C_COMPAT and don't disable DM_I2C in SPL
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Fri, 7 Dec 2018 13:50:49 +0000 (14:50 +0100)
committerHeiko Schocher <hs@denx.de>
Mon, 10 Dec 2018 06:15:21 +0000 (07:15 +0100)
DM_I2C_COMPAT is a compatibility layer that allows using the non-DM I2C
API when DM_I2C is used. The goal is to eventually remove DM_I2C_COMPAT
when all I2C "clients" have been migrated to use the DM API.
This a step in that direction for the TI based platforms.
Build tested with buildman:
buildman -dle am33xx ti omap3 omap4 omap5 davinci keystone

boot tested with:
am335x_evm, am335x_boneblack, am335x_boneblack_vboot (DM version),
am57xx_evm, dra7xx_evm, k2g_evm, am437x_evm

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Tom Rini <trini@konsulko.com>
Reviewed-by: Heiko Schocher <hs@denx.de>
arch/arm/mach-keystone/ddr3_spd.c
arch/arm/mach-omap2/am33xx/clk_synthesizer.c
arch/arm/mach-omap2/clocks-common.c
board/ti/am335x/board.c
board/ti/am335x/mux.c
board/ti/am43xx/board.c
board/ti/am57xx/board.c
board/ti/common/board_detect.c
board/ti/ks2_evm/board_k2g.c
include/configs/am43xx_evm.h
include/configs/ti_armv7_common.h

index 261309255280b539c9e425f65ead6cc724bc8fff..6eee9ad13a0b30cad794674c017e753ea92bcae9 100644 (file)
@@ -403,6 +403,7 @@ static void init_ddr3param(struct ddr3_spd_cb *spd_cb,
 static int ddr3_read_spd(ddr3_spd_eeprom_t *spd_params)
 {
        int ret;
+#ifndef CONFIG_DM_I2C
        int old_bus;
 
        i2c_init(CONFIG_SYS_DAVINCI_I2C_SPEED, CONFIG_SYS_DAVINCI_I2C_SLAVE);
@@ -413,7 +414,13 @@ static int ddr3_read_spd(ddr3_spd_eeprom_t *spd_params)
        ret = i2c_read(0x53, 0, 1, (unsigned char *)spd_params, 256);
 
        i2c_set_bus_num(old_bus);
+#else
+       struct udevice *dev;
 
+       ret = i2c_get_chip_for_busnum(1, 0x53, 1, &dev);
+       if (!ret)
+               ret = dm_i2c_read(dev, 0, (unsigned char *)spd_params, 256);
+#endif
        if (ret) {
                printf("Cannot read DIMM params\n");
                return 1;
index 0e7ad1d3aff220640c38a2c3d88eee48403b0af4..ff1bfaf84b69e5b260f4590bbc86c7306de8657b 100644 (file)
@@ -14,6 +14,7 @@
 
 /**
  * clk_synthesizer_reg_read - Read register from synthesizer.
+ * dev:                i2c bus device (not used if CONFIG_DM_I2C is not set)
  * @addr:      addr within the i2c device
  * buf:                Buffer to which value is to be read.
  *
  * be send along with enabling byte read more, and then read can happen.
  * Returns 0 on success
  */
-static int clk_synthesizer_reg_read(int addr, uint8_t *buf)
+static int clk_synthesizer_reg_read(struct udevice *dev, int addr, u8 *buf)
 {
        int rc;
 
        /* Enable Bye read */
        addr = addr | CLK_SYNTHESIZER_BYTE_MODE;
 
+#ifndef CONFIG_DM_I2C
        /* Send the command byte */
        rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
        if (rc)
@@ -35,26 +37,46 @@ static int clk_synthesizer_reg_read(int addr, uint8_t *buf)
 
        /* Read the Data */
        return i2c_read(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, buf, 1);
+#else
+       /* Send the command byte */
+       rc = dm_i2c_reg_write(dev, addr, *buf);
+       if (rc)
+               printf("Failed to send command to clock synthesizer\n");
+
+       /* Read the Data */
+       rc = dm_i2c_reg_read(dev, addr);
+       if (rc < 0)
+               return rc;
+
+       *buf = (u8)rc;
+       return 0;
+#endif
+
 }
 
 /**
  * clk_synthesizer_reg_write - Write a value to register in synthesizer.
+ * dev:                i2c bus device (not used if CONFIG_DM_I2C is not set)
  * @addr:      addr within the i2c device
  * val:                Value to be written in the addr.
  *
  * Enable the byte read mode in the address and start the i2c transfer.
  * Returns 0 on success
  */
-static int clk_synthesizer_reg_write(int addr, uint8_t val)
+static int clk_synthesizer_reg_write(struct udevice *dev, int addr, u8 val)
 {
-       uint8_t cmd[2];
+       u8 cmd[2];
        int rc = 0;
 
        /* Enable byte write */
        cmd[0] = addr | CLK_SYNTHESIZER_BYTE_MODE;
        cmd[1] = val;
 
+#ifndef CONFIG_DM_I2C
        rc = i2c_write(CLK_SYNTHESIZER_I2C_ADDR, addr, 1, cmd, 2);
+#else
+       rc = dm_i2c_write(dev, addr, cmd, 2);
+#endif
        if (rc)
                printf("Clock synthesizer reg write failed at addr = 0x%x\n",
                       addr);
@@ -72,30 +94,42 @@ static int clk_synthesizer_reg_write(int addr, uint8_t val)
 int setup_clock_synthesizer(struct clk_synth *data)
 {
        int rc;
-       uint8_t val;
-
+       u8 val = 0;
+       struct udevice *dev = NULL;
+#ifndef CONFIG_DM_I2C
        rc =  i2c_probe(CLK_SYNTHESIZER_I2C_ADDR);
        if (rc) {
                printf("i2c probe failed at address 0x%x\n",
                       CLK_SYNTHESIZER_I2C_ADDR);
                return rc;
        }
-
-       rc = clk_synthesizer_reg_read(CLK_SYNTHESIZER_ID_REG, &val);
+#else
+       rc = i2c_get_chip_for_busnum(0, CLK_SYNTHESIZER_I2C_ADDR, 1, &dev);
+       if (rc) {
+               printf("failed to get device for synthesizer at address 0x%x\n",
+                      CLK_SYNTHESIZER_I2C_ADDR);
+               return rc;
+       }
+#endif
+       rc = clk_synthesizer_reg_read(dev, CLK_SYNTHESIZER_ID_REG, &val);
        if (val != data->id)
                return rc;
 
        /* Crystal Load capacitor selection */
-       rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_XCSEL, data->capacitor);
+       rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_XCSEL,
+                                      data->capacitor);
        if (rc)
                return rc;
-       rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_MUX_REG, data->mux);
+       rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_MUX_REG,
+                                      data->mux);
        if (rc)
                return rc;
-       rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_PDIV2_REG, data->pdiv2);
+       rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV2_REG,
+                                      data->pdiv2);
        if (rc)
                return rc;
-       rc = clk_synthesizer_reg_write(CLK_SYNTHESIZER_PDIV3_REG, data->pdiv3);
+       rc = clk_synthesizer_reg_write(dev, CLK_SYNTHESIZER_PDIV3_REG,
+                                      data->pdiv3);
        if (rc)
                return rc;
 
index 790548ee7996846c2477ee70fbc732773b7abe76..5932d694d3009862400198f772a061860df29d55 100644 (file)
@@ -909,6 +909,7 @@ void prcm_init(void)
                enable_basic_uboot_clocks();
 }
 
+#if !defined(CONFIG_DM_I2C)
 void gpi2c_init(void)
 {
        static int gpi2c = 1;
@@ -919,3 +920,4 @@ void gpi2c_init(void)
                gpi2c = 0;
        }
 }
+#endif
index 13845251afb5ad93e7366895934308ad504e6a28..d67f94ad47baec593946f51f4beffe9384915af8 100644 (file)
@@ -70,8 +70,9 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
 void do_board_detect(void)
 {
        enable_i2c0_pin_mux();
+#ifndef CONFIG_DM_I2C
        i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED, CONFIG_SYS_OMAP24_I2C_SLAVE);
-
+#endif
        if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
                                 CONFIG_EEPROM_CHIP_ADDRESS))
                printf("ti_i2c_eeprom_init failed\n");
@@ -328,8 +329,14 @@ static void scale_vcores_bone(int freq)
        if (board_is_bone() && !strncmp(board_ti_get_rev(), "00A1", 4))
                return;
 
+#ifndef CONFIG_DM_I2C
        if (i2c_probe(TPS65217_CHIP_PM))
                return;
+#else
+       if (power_tps65217_init(0))
+               return;
+#endif
+
 
        /*
         * On Beaglebone White we need to ensure we have AC power
@@ -421,9 +428,13 @@ void scale_vcores_generic(int freq)
         * 1.10V.  For MPU voltage we need to switch based on
         * the frequency we are running at.
         */
+#ifndef CONFIG_DM_I2C
        if (i2c_probe(TPS65910_CTRL_I2C_ADDR))
                return;
-
+#else
+       if (power_tps65910_init(0))
+               return;
+#endif
        /*
         * Depending on MPU clock and PG we will need a different
         * VDD to drive at that speed.
@@ -451,8 +462,10 @@ void gpi2c_init(void)
 
        if (first_time) {
                enable_i2c0_pin_mux();
+#ifndef CONFIG_DM_I2C
                i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
                         CONFIG_SYS_OMAP24_I2C_SLAVE);
+#endif
                first_time = false;
        }
 }
index 41333f93f40dc57fedfcbaec51b93f2aa9446cd9..04f4b8e69347d49e7fde115f9339b4cb35835a49 100644 (file)
@@ -329,12 +329,23 @@ static unsigned short detect_daughter_board_profile(void)
 {
        unsigned short val;
 
+#ifndef CONFIG_DM_I2C
        if (i2c_probe(I2C_CPLD_ADDR))
                return PROFILE_NONE;
 
        if (i2c_read(I2C_CPLD_ADDR, CFG_REG, 1, (unsigned char *)(&val), 2))
                return PROFILE_NONE;
+#else
+       struct udevice *dev = NULL;
+       int rc;
 
+       rc = i2c_get_chip_for_busnum(0, I2C_CPLD_ADDR, 1, &dev);
+       if (rc)
+               return PROFILE_NONE;
+       rc = dm_i2c_read(dev, CFG_REG, (unsigned char *)(&val), 2);
+       if (rc)
+               return PROFILE_NONE;
+#endif
        return (1 << (val & PROFILE_MASK));
 }
 
index 2a59b060351f6fec8a2f004e594937bcf904cf85..31bc0f49a48517f30845b3d143f9447fd4d0ea25 100644 (file)
@@ -43,6 +43,8 @@ static struct ctrl_dev *cdev = (struct ctrl_dev *)CTRL_DEVICE_BASE;
 #ifdef CONFIG_TI_I2C_BOARD_DETECT
 void do_board_detect(void)
 {
+       /* Ensure I2C is initialized for EEPROM access*/
+       gpi2c_init();
        if (ti_i2c_eeprom_am_get(CONFIG_EEPROM_BUS_ADDRESS,
                                 CONFIG_EEPROM_CHIP_ADDRESS))
                printf("ti_i2c_eeprom_init failed\n");
@@ -386,8 +388,13 @@ void scale_vcores_generic(u32 m)
 {
        int mpu_vdd, ddr_volt;
 
+#ifndef CONFIG_DM_I2C
        if (i2c_probe(TPS65218_CHIP_PM))
                return;
+#else
+       if (power_tps65218_init(0))
+               return;
+#endif
 
        switch (m) {
        case 1000:
@@ -439,8 +446,13 @@ void scale_vcores_idk(u32 m)
 {
        int mpu_vdd;
 
+#ifndef CONFIG_DM_I2C
        if (i2c_probe(TPS62362_I2C_ADDR))
                return;
+#else
+       if (power_tps62362_init(0))
+               return;
+#endif
 
        switch (m) {
        case 1000:
@@ -462,14 +474,12 @@ void scale_vcores_idk(u32 m)
                puts("Unknown MPU clock, not scaling\n");
                return;
        }
-
        /* Set VDD_MPU voltage */
        if (tps62362_voltage_update(TPS62362_SET3, mpu_vdd)) {
                printf("%s failure\n", __func__);
                return;
        }
 }
-
 void gpi2c_init(void)
 {
        /* When needed to be invoked prior to BSS initialization */
@@ -477,8 +487,10 @@ void gpi2c_init(void)
 
        if (first_time) {
                enable_i2c0_pin_mux();
+#ifndef CONFIG_DM_I2C
                i2c_init(CONFIG_SYS_OMAP24_I2C_SPEED,
                         CONFIG_SYS_OMAP24_I2C_SLAVE);
+#endif
                first_time = false;
        }
 }
@@ -614,20 +626,32 @@ void sdram_init(void)
 /* setup board specific PMIC */
 int power_init_board(void)
 {
-       struct pmic *p;
-
+       int rc;
+#ifndef CONFIG_DM_I2C
+       struct pmic *p = NULL;
+#endif
        if (board_is_idk()) {
-               power_tps62362_init(I2C_PMIC);
+               rc = power_tps62362_init(0);
+               if (rc)
+                       goto done;
+#ifndef CONFIG_DM_I2C
                p = pmic_get("TPS62362");
-               if (p && !pmic_probe(p))
-                       puts("PMIC:  TPS62362\n");
+               if (!p || pmic_probe(p))
+                       goto done;
+#endif
+               puts("PMIC:  TPS62362\n");
        } else {
-               power_tps65218_init(I2C_PMIC);
+               rc = power_tps65218_init(0);
+               if (rc)
+                       goto done;
+#ifndef CONFIG_DM_I2C
                p = pmic_get("TPS65218_PMIC");
-               if (p && !pmic_probe(p))
-                       puts("PMIC:  TPS65218\n");
+               if (!p || pmic_probe(p))
+                       goto done;
+#endif
+               puts("PMIC:  TPS65218\n");
        }
-
+done:
        return 0;
 }
 
index 177a3246c3dbc2d7b35b57415cddc42546b4e1c6..355ea55609fa9c19b0841b3c875e41495c928a4e 100644 (file)
@@ -623,7 +623,7 @@ void am57x_idk_lcd_detect(void)
 {
        int r = -ENODEV;
        char *idk_lcd = "no";
-       uint8_t buf = 0;
+       u8 buf = 0;
 
        /* Only valid for IDKs */
        if (board_is_x15() || board_is_am572x_evm())
@@ -633,6 +633,7 @@ void am57x_idk_lcd_detect(void)
        if (board_is_am571x_idk() && !am571x_idk_needs_lcd())
                goto out;
 
+#ifndef CONFIG_DM_I2C
        r = i2c_set_bus_num(OSD_TS_FT_BUS_ADDRESS);
        if (r) {
                printf("%s: Failed to set bus address to %d: %d\n",
@@ -657,6 +658,32 @@ void am57x_idk_lcd_detect(void)
                       OSD_TS_FT_REG_ID, r);
                goto out;
        }
+#else
+       struct udevice *dev;
+
+       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())
+                       printf("%s: Touch screen detect failed: %d!\n",
+                              __func__, r);
+               goto out;
+       }
+
+       /* Read FT ID */
+       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;
+       }
+       buf = (u8)r;
+#endif
 
        switch (buf) {
        case OSD_TS_FT_ID_5606:
index 085e7320bd8f426c6913418bf2deef154d9086f0..e258e22f3714c6c8052d8ddf80956cc7a89f779e 100644 (file)
 
 #include "board_detect.h"
 
-#if defined(CONFIG_DM_I2C_COMPAT)
-/**
- * ti_i2c_set_alen - Set chip's i2c address length
- * @bus_addr - I2C bus number
- * @dev_addr - I2C eeprom id
- * @alen     - I2C address length in bytes
- *
- * DM_I2C by default sets the address length to be used to 1. This
- * function allows this address length to be changed to match the
- * eeprom used for board detection.
- */
-int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen)
-{
-       struct udevice *dev;
-       struct udevice *bus;
-       int rc;
-
-       rc = uclass_get_device_by_seq(UCLASS_I2C, bus_addr, &bus);
-       if (rc)
-               return rc;
-       rc = i2c_get_chip(bus, dev_addr, 1, &dev);
-       if (rc)
-               return rc;
-       rc = i2c_set_chip_offset_len(dev, alen);
-       if (rc)
-               return rc;
-
-       return 0;
-}
-#else
-int __maybe_unused ti_i2c_set_alen(int bus_addr, int dev_addr, int alen)
-{
-       return 0;
-}
-#endif
-
-#if !defined(CONFIG_DM_I2C) || defined(CONFIG_DM_I2C_COMPAT)
+#if !defined(CONFIG_DM_I2C)
 /**
  * ti_i2c_eeprom_init - Initialize an i2c bus and probe for a device
  * @i2c_bus: i2c bus number to initialize
@@ -83,17 +47,7 @@ static int __maybe_unused ti_i2c_eeprom_init(int i2c_bus, int dev_addr)
 static int __maybe_unused ti_i2c_eeprom_read(int dev_addr, int offset,
                                             uchar *ep, int epsize)
 {
-       int bus_num, rc, alen;
-
-       bus_num = i2c_get_bus_num();
-
-       alen = 2;
-
-       rc = ti_i2c_set_alen(bus_num, dev_addr, alen);
-       if (rc)
-               return rc;
-
-       return i2c_read(dev_addr, offset, alen, ep, epsize);
+       return i2c_read(dev_addr, offset, 2, ep, epsize);
 }
 #endif
 
@@ -127,7 +81,7 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
        u32 hdr_read;
        int rc;
 
-#if defined(CONFIG_DM_I2C) && !defined(CONFIG_DM_I2C_COMPAT)
+#if defined(CONFIG_DM_I2C)
        struct udevice *dev;
        struct udevice *bus;
 
@@ -185,10 +139,6 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
         */
        byte = 2;
 
-       rc = ti_i2c_set_alen(bus_addr, dev_addr, byte);
-       if (rc)
-               return rc;
-
        rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read, 4);
        if (rc)
                return rc;
@@ -202,10 +152,6 @@ static int __maybe_unused ti_i2c_eeprom_get(int bus_addr, int dev_addr,
                 */
                byte = 1;
                if (rc) {
-                       rc = ti_i2c_set_alen(bus_addr, dev_addr, byte);
-                       if (rc)
-                               return rc;
-
                        rc = i2c_read(dev_addr, 0x0, byte, (uint8_t *)&hdr_read,
                                      4);
                }
index 87dc4d009e2eb7194e3b080fe48f520d836d1fbd..39a782e47960ee13412e2864cdef788c8d5b3c9c 100644 (file)
@@ -251,6 +251,7 @@ int board_fit_config_name_match(const char *name)
 #if defined(CONFIG_DTB_RESELECT)
 static int k2g_alt_board_detect(void)
 {
+#ifndef CONFIG_DM_I2C
        int rc;
 
        rc = i2c_set_bus_num(1);
@@ -260,7 +261,17 @@ static int k2g_alt_board_detect(void)
        rc = i2c_probe(K2G_GP_AUDIO_CODEC_ADDRESS);
        if (rc)
                return rc;
+#else
+       struct udevice *bus, *dev;
+       int rc;
 
+       rc = uclass_get_device_by_seq(UCLASS_I2C, 1, &bus);
+       if (rc)
+               return rc;
+       rc = dm_i2c_probe(bus, K2G_GP_AUDIO_CODEC_ADDRESS, 0, &dev);
+       if (rc)
+               return rc;
+#endif
        ti_i2c_eeprom_am_set("66AK2GGP", "1.0X");
 
        return 0;
index 9d0d342478608d30c6d7fa752f0af7cbcd05d3d7..ed71f4ce56ace9ec24275e12fcecf7e08ee0631d 100644 (file)
 #define CONFIG_SYS_I2C_EEPROM_ADDR_LEN 2
 
 /* Power */
+#ifndef CONFIG_DM_I2C
 #define CONFIG_POWER
 #define CONFIG_POWER_I2C
+#endif
 #define CONFIG_POWER_TPS65218
 #define CONFIG_POWER_TPS62362
 
index 0f892e51d1954dfb812adf3604b77865f2484239..1e2a62dd6fade933ad13fec4c7147ac405564961 100644 (file)
 /* Timer information. */
 #define CONFIG_SYS_PTV                 2       /* Divisor: 2^(PTV+1) => 8 */
 
-/*
- * Disable DM_* for SPL build and can be re-enabled after adding
- * DM support in SPL
- */
-#ifdef CONFIG_SPL_BUILD
-#undef CONFIG_DM_I2C
-#endif
-
-/* I2C IP block */
+/* If DM_I2C, enable non-DM I2C support */
+#if !defined(CONFIG_DM_I2C)
 #define CONFIG_I2C
-#ifndef CONFIG_DM_I2C
 #define CONFIG_SYS_I2C
-#else
-/*
- * Enable CONFIG_DM_I2C_COMPAT temporarily until all the i2c client
- * devices are adopted to DM
- */
-#define CONFIG_DM_I2C_COMPAT
 #endif
 
 /*