boards: ls2088aqds: Add support of I2C driver model.
authorChuanhua Han <chuanhua.han@nxp.com>
Fri, 26 Jul 2019 11:24:01 +0000 (19:24 +0800)
committerPrabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
Thu, 22 Aug 2019 03:37:36 +0000 (09:07 +0530)
Update ls2088aqds board init code to support DM_I2C.

Signed-off-by: Chuanhua Han <chuanhua.han@nxp.com>
Reviewed-by: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>
board/freescale/ls2080aqds/eth.c
board/freescale/ls2080aqds/ls2080aqds.c
include/configs/ls2080aqds.h

index 1b4e6c65fb96088a3567dca065ff56a136528b8d..6a8788c3125498b005ceee1d52d463bd92ba8840 100644 (file)
@@ -90,11 +90,16 @@ struct ls2080a_qds_mdio {
        struct mii_dev *realbus;
 };
 
+struct reg_pair {
+       uint addr;
+       u8 *val;
+};
+
 static void sgmii_configure_repeater(int serdes_port)
 {
        struct mii_dev *bus;
        uint8_t a = 0xf;
-       int i, j, ret;
+       int i, j, k, ret;
        int dpmac_id = 0, dpmac, mii_bus = 0;
        unsigned short value;
        char dev[2][20] = {"LS2080A_QDS_MDIO0", "LS2080A_QDS_MDIO3"};
@@ -105,10 +110,30 @@ static void sgmii_configure_repeater(int serdes_port)
        uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
        uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
 
+       u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
+       struct reg_pair reg_pair[10] = {
+                       {6, &reg_val[0]}, {4, &reg_val[1]},
+                       {8, &reg_val[2]}, {0xf, NULL},
+                       {0x11, NULL}, {0x16, NULL},
+                       {0x18, NULL}, {0x23, &reg_val[3]},
+                       {0x2d, &reg_val[4]}, {4, &reg_val[5]},
+       };
+
        int *riser_phy_addr = &xqsgii_riser_phy_addr[0];
+#ifdef CONFIG_DM_I2C
+       struct udevice *udev;
+#endif
 
        /* Set I2c to Slot 1 */
-       i2c_write(0x77, 0, 0, &a, 1);
+#ifndef CONFIG_DM_I2C
+       ret = i2c_write(0x77, 0, 0, &a, 1);
+#else
+       ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
+       if (!ret)
+               ret = dm_i2c_write(udev, 0, &a, 1);
+#endif
+       if (ret)
+               goto error;
 
        for (dpmac = 0; dpmac < 8; dpmac++) {
                /* Check the PHY status */
@@ -121,7 +146,15 @@ static void sgmii_configure_repeater(int serdes_port)
                        mii_bus = 1;
                        dpmac_id = dpmac + 9;
                        a = 0xb;
-                       i2c_write(0x76, 0, 0, &a, 1);
+#ifndef CONFIG_DM_I2C
+                       ret = i2c_write(0x76, 0, 0, &a, 1);
+#else
+                       ret = i2c_get_chip_for_busnum(0, 0x76, 1, &udev);
+                       if (!ret)
+                               ret = dm_i2c_write(udev, 0, &a, 1);
+#endif
+                       if (ret)
+                               goto error;
                        break;
                }
 
@@ -154,29 +187,29 @@ static void sgmii_configure_repeater(int serdes_port)
 
                for (i = 0; i < 4; i++) {
                        for (j = 0; j < 4; j++) {
-                               a = 0x18;
-                               i2c_write(i2c_addr[dpmac], 6, 1, &a, 1);
-                               a = 0x38;
-                               i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
-                               a = 0x4;
-                               i2c_write(i2c_addr[dpmac], 8, 1, &a, 1);
-
-                               i2c_write(i2c_addr[dpmac], 0xf, 1,
-                                         &ch_a_eq[i], 1);
-                               i2c_write(i2c_addr[dpmac], 0x11, 1,
-                                         &ch_a_ctl2[j], 1);
-
-                               i2c_write(i2c_addr[dpmac], 0x16, 1,
-                                         &ch_b_eq[i], 1);
-                               i2c_write(i2c_addr[dpmac], 0x18, 1,
-                                         &ch_b_ctl2[j], 1);
-
-                               a = 0x14;
-                               i2c_write(i2c_addr[dpmac], 0x23, 1, &a, 1);
-                               a = 0xb5;
-                               i2c_write(i2c_addr[dpmac], 0x2d, 1, &a, 1);
-                               a = 0x20;
-                               i2c_write(i2c_addr[dpmac], 4, 1, &a, 1);
+                               reg_pair[3].val = &ch_a_eq[i];
+                               reg_pair[4].val = &ch_a_ctl2[j];
+                               reg_pair[5].val = &ch_b_eq[i];
+                               reg_pair[6].val = &ch_b_ctl2[j];
+
+                               for (k = 0; k < 10; k++) {
+#ifndef CONFIG_DM_I2C
+                                       ret = i2c_write(i2c_addr[dpmac],
+                                                       reg_pair[k].addr,
+                                                       1, reg_pair[k].val, 1);
+#else
+                                       ret = i2c_get_chip_for_busnum(0,
+                                                           i2c_addr[dpmac],
+                                                           1, &udev);
+                                       if (!ret)
+                                               ret = dm_i2c_write(udev,
+                                                         reg_pair[k].addr,
+                                                         reg_pair[k].val, 1);
+#endif
+                                       if (ret)
+                                               goto error;
+                               }
+
                                mdelay(100);
                                ret = miiphy_read(dev[mii_bus],
                                                  riser_phy_addr[dpmac],
@@ -217,7 +250,7 @@ error:
 static void qsgmii_configure_repeater(int dpmac)
 {
        uint8_t a = 0xf;
-       int i, j;
+       int i, j, k;
        int i2c_phy_addr = 0;
        int phy_addr = 0;
        int i2c_addr[] = {0x58, 0x59, 0x5a, 0x5b};
@@ -227,12 +260,32 @@ static void qsgmii_configure_repeater(int dpmac)
        uint8_t ch_b_eq[] = {0x1, 0x2, 0x3, 0x7};
        uint8_t ch_b_ctl2[] = {0x81, 0x82, 0x83, 0x84};
 
+       u8 reg_val[6] = {0x18, 0x38, 0x4, 0x14, 0xb5, 0x20};
+       struct reg_pair reg_pair[10] = {
+               {6, &reg_val[0]}, {4, &reg_val[1]},
+               {8, &reg_val[2]}, {0xf, NULL},
+               {0x11, NULL}, {0x16, NULL},
+               {0x18, NULL}, {0x23, &reg_val[3]},
+               {0x2d, &reg_val[4]}, {4, &reg_val[5]},
+       };
+
        const char *dev = "LS2080A_QDS_MDIO0";
        int ret = 0;
        unsigned short value;
+#ifdef CONFIG_DM_I2C
+       struct udevice *udev;
+#endif
 
        /* Set I2c to Slot 1 */
-       i2c_write(0x77, 0, 0, &a, 1);
+#ifndef CONFIG_DM_I2C
+       ret = i2c_write(0x77, 0, 0, &a, 1);
+#else
+       ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
+       if (!ret)
+               ret = dm_i2c_write(udev, 0, &a, 1);
+#endif
+       if (ret)
+               goto error;
 
        switch (dpmac) {
        case 1:
@@ -283,25 +336,29 @@ static void qsgmii_configure_repeater(int dpmac)
 
        for (i = 0; i < 4; i++) {
                for (j = 0; j < 4; j++) {
-                       a = 0x18;
-                       i2c_write(i2c_phy_addr, 6, 1, &a, 1);
-                       a = 0x38;
-                       i2c_write(i2c_phy_addr, 4, 1, &a, 1);
-                       a = 0x4;
-                       i2c_write(i2c_phy_addr, 8, 1, &a, 1);
-
-                       i2c_write(i2c_phy_addr, 0xf, 1, &ch_a_eq[i], 1);
-                       i2c_write(i2c_phy_addr, 0x11, 1, &ch_a_ctl2[j], 1);
-
-                       i2c_write(i2c_phy_addr, 0x16, 1, &ch_b_eq[i], 1);
-                       i2c_write(i2c_phy_addr, 0x18, 1, &ch_b_ctl2[j], 1);
-
-                       a = 0x14;
-                       i2c_write(i2c_phy_addr, 0x23, 1, &a, 1);
-                       a = 0xb5;
-                       i2c_write(i2c_phy_addr, 0x2d, 1, &a, 1);
-                       a = 0x20;
-                       i2c_write(i2c_phy_addr, 4, 1, &a, 1);
+                       reg_pair[3].val = &ch_a_eq[i];
+                       reg_pair[4].val = &ch_a_ctl2[j];
+                       reg_pair[5].val = &ch_b_eq[i];
+                       reg_pair[6].val = &ch_b_ctl2[j];
+
+                       for (k = 0; k < 10; k++) {
+#ifndef CONFIG_DM_I2C
+                               ret = i2c_write(i2c_phy_addr,
+                                               reg_pair[k].addr,
+                                               1, reg_pair[k].val, 1);
+#else
+                               ret = i2c_get_chip_for_busnum(0,
+                                                             i2c_phy_addr,
+                                                             1, &udev);
+                               if (!ret)
+                                       ret = dm_i2c_write(udev,
+                                                          reg_pair[k].addr,
+                                                          reg_pair[k].val, 1);
+#endif
+                               if (ret)
+                                       goto error;
+                       }
+
                        mdelay(100);
                        ret = miiphy_read(dev, phy_addr, 0x11, &value);
                        if (ret > 0)
index dc239cf35ce15ffde43bc83e86d1888b84d95d45..91c80353edd61a36ec2c24443afa59cdccafc7c7 100644 (file)
@@ -161,8 +161,16 @@ unsigned long get_board_ddr_clk(void)
 int select_i2c_ch_pca9547(u8 ch)
 {
        int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
 
+       ret = i2c_get_chip_for_busnum(0, I2C_MUX_PCA_ADDR_PRI, 1, &dev);
+       if (!ret)
+               ret = dm_i2c_write(dev, 0, &ch, 1);
+
+#else
        ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
+#endif
        if (ret) {
                puts("PCA: failed to select proper channel\n");
                return ret;
@@ -225,9 +233,15 @@ int board_init(void)
        gd->env_addr = (ulong)&default_environment[0];
 #endif
        select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
+
 #ifdef CONFIG_RTC_ENABLE_32KHZ_OUTPUT
+#ifdef CONFIG_DM_I2C
+       rtc_enable_32khz_output(0, CONFIG_SYS_I2C_RTC_ADDR);
+#else
        rtc_enable_32khz_output();
 #endif
+#endif
+
 #ifdef CONFIG_FSL_CAAM
        sec_init();
 #endif
index 81af1d9ea43da8b3a87a141b8d588fe7c570cd62..e2a897557db1d7f1d31d3badf4d9b3ffd7e1cb69 100644 (file)
@@ -16,7 +16,9 @@ unsigned long get_board_ddr_clk(void);
 
 #ifdef CONFIG_FSL_QSPI
 #define CONFIG_QIXIS_I2C_ACCESS
+#ifndef CONFIG_DM_I2C
 #define CONFIG_SYS_I2C_EARLY_INIT
+#endif
 #define CONFIG_SYS_I2C_IFDR_DIV                0x7e
 #endif
 
@@ -324,6 +326,7 @@ unsigned long get_board_ddr_clk(void);
  */
 #define RTC
 #define CONFIG_RTC_DS3231               1
+#define CONFIG_RTC_ENABLE_32KHZ_OUTPUT
 #define CONFIG_SYS_I2C_RTC_ADDR         0x68
 #define CONFIG_RTC_ENABLE_32KHZ_OUTPUT