Merge tag 'video-next' of https://gitlab.denx.de/u-boot/custodians/u-boot-video into...
[platform/kernel/u-boot.git] / board / freescale / t102xqds / t102xqds.c
index 1affa0b..fd48985 100644 (file)
@@ -1,12 +1,17 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright 2014 Freescale Semiconductor, Inc.
- *
- * SPDX-License-Identifier:    GPL-2.0+
+ * Copyright 2020 NXP
  */
 
 #include <common.h>
 #include <command.h>
+#include <env.h>
+#include <fdt_support.h>
 #include <i2c.h>
+#include <image.h>
+#include <init.h>
+#include <log.h>
 #include <netdev.h>
 #include <linux/compiler.h>
 #include <asm/mmu.h>
@@ -73,11 +78,24 @@ int checkboard(void)
        return 0;
 }
 
-int select_i2c_ch_pca9547(u8 ch)
+int select_i2c_ch_pca9547(u8 ch, int bus_num)
 {
        int ret;
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
 
+       ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
+                                     1, &dev);
+       if (ret) {
+               printf("%s: Cannot find udev for a bus %d\n", __func__,
+                      bus_num);
+               return 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;
@@ -152,7 +170,7 @@ static int board_mux_lane_to_slot(void)
        return 0;
 }
 
-#ifdef CONFIG_PPC_T1024
+#ifdef CONFIG_ARCH_T1024
 static void board_mux_setup(void)
 {
        u8 brdcfg15;
@@ -189,6 +207,82 @@ void board_retimer_ds125df111_init(void)
 {
        u8 reg;
 
+#ifdef CONFIG_DM_I2C
+       struct udevice *dev;
+       int ret, bus_num = 0;
+
+       ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_PRI,
+                                     1, &dev);
+       if (ret)
+               goto failed;
+
+       /* Retimer DS125DF111 is connected to I2C1_CH7_CH5 */
+       reg = I2C_MUX_CH7;
+       dm_i2c_write(dev, 0, &reg, 1);
+
+       ret = i2c_get_chip_for_busnum(bus_num, I2C_MUX_PCA_ADDR_SEC,
+                                     1, &dev);
+       if (ret)
+               goto failed;
+
+       reg = I2C_MUX_CH5;
+       dm_i2c_write(dev, 0, &reg, 1);
+
+       /* Access to Control/Shared register */
+       ret = i2c_get_chip_for_busnum(bus_num, I2C_RETIMER_ADDR,
+                                     1, &dev);
+       if (ret)
+               goto failed;
+       reg = 0x0;
+       dm_i2c_write(dev, 0xff, &reg, 1);
+
+       /* Read device revision and ID */
+       dm_i2c_read(dev, 1, &reg, 1);
+       debug("Retimer version id = 0x%x\n", reg);
+
+       /* Enable Broadcast */
+       reg = 0x0c;
+       dm_i2c_write(dev, 0xff, &reg, 1);
+
+       /* Reset Channel Registers */
+       dm_i2c_read(dev, 0, &reg, 1);
+       reg |= 0x4;
+       dm_i2c_write(dev, 0, &reg, 1);
+
+       /* Enable override divider select and Enable Override Output Mux */
+       dm_i2c_read(dev, 9, &reg, 1);
+       reg |= 0x24;
+       dm_i2c_write(dev, 9, &reg, 1);
+
+       /* Select VCO Divider to full rate (000) */
+       dm_i2c_read(dev, 0x18, &reg, 1);
+       reg &= 0x8f;
+       dm_i2c_write(dev, 0x18, &reg, 1);
+
+       /* Select active PFD MUX input as re-timed data (001) */
+       dm_i2c_read(dev, 0x1e, &reg, 1);
+       reg &= 0x3f;
+       reg |= 0x20;
+       dm_i2c_write(dev, 0x1e, &reg, 1);
+
+       /* Set data rate as 10.3125 Gbps */
+       reg = 0x0;
+       dm_i2c_write(dev, 0x60, &reg, 1);
+       reg = 0xb2;
+       dm_i2c_write(dev, 0x61, &reg, 1);
+       reg = 0x90;
+       dm_i2c_write(dev, 0x62, &reg, 1);
+       reg = 0xb3;
+       dm_i2c_write(dev, 0x63, &reg, 1);
+       reg = 0xcd;
+       dm_i2c_write(dev, 0x64, &reg, 1);
+       return;
+
+failed:
+       printf("%s: Cannot find udev for a bus %d\n", __func__,
+              bus_num);
+       return;
+#else
        /* Retimer DS125DF111 is connected to I2C1_CH7_CH5 */
        reg = I2C_MUX_CH7;
        i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &reg, 1);
@@ -239,6 +333,7 @@ void board_retimer_ds125df111_init(void)
        i2c_write(I2C_RETIMER_ADDR, 0x63, 1, &reg, 1);
        reg = 0xcd;
        i2c_write(I2C_RETIMER_ADDR, 0x64, 1, &reg, 1);
+#endif
 }
 
 int board_early_init_f(void)
@@ -279,7 +374,7 @@ int board_early_init_r(void)
                MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
                0, flash_esel, BOOKE_PAGESZ_256M, 1);
 #endif
-       select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
+       select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT, 0);
        board_mux_lane_to_slot();
        board_retimer_ds125df111_init();
 
@@ -332,7 +427,7 @@ unsigned long get_board_ddr_clk(void)
 #define NUM_SRDS_PLL   2
 int misc_init_r(void)
 {
-#ifdef CONFIG_PPC_T1024
+#ifdef CONFIG_ARCH_T1024
        board_mux_setup();
 #endif
        return 0;
@@ -363,8 +458,8 @@ int ft_board_setup(void *blob, bd_t *bd)
 
        ft_cpu_setup(blob, bd);
 
-       base = getenv_bootm_low();
-       size = getenv_bootm_size();
+       base = env_get_bootm_low();
+       size = env_get_bootm_size();
 
        fdt_fixup_memory(blob, (u64)base, (u64)size);
 
@@ -379,7 +474,9 @@ int ft_board_setup(void *blob, bd_t *bd)
 #endif
 
 #ifdef CONFIG_SYS_DPAA_FMAN
+#ifndef CONFIG_DM_ETH
        fdt_fixup_fman_ethernet(blob);
+#endif
        fdt_fixup_board_enet(blob);
 #endif
        fdt_fixup_spi_mux(blob);