global: Migrate CONFIG_SYS_FSL* symbols to the CFG_SYS namespace
[platform/kernel/u-boot.git] / board / freescale / ls2080aqds / eth.c
index 6a8788c..6da6e5c 100644 (file)
@@ -5,6 +5,8 @@
 
 #include <common.h>
 #include <env.h>
+#include <log.h>
+#include <net.h>
 #include <netdev.h>
 #include <asm/io.h>
 #include <asm/arch/fsl_serdes.h>
@@ -16,6 +18,7 @@
 #include <miiphy.h>
 #include <fsl-mc/fsl_mc.h>
 #include <fsl-mc/ldpaa_wriop.h>
+#include <linux/delay.h>
 
 #include "../common/qixis.h"
 
@@ -23,6 +26,8 @@
 
 #define MC_BOOT_ENV_VAR "mcinitcmd"
 
+#ifndef CONFIG_DM_ETH
+
 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
  /* - In LS2080A there are only 16 SERDES lanes, spread across 2 SERDES banks.
  *   Bank 1 -> Lanes A, B, C, D, E, F, G, H
@@ -120,12 +125,12 @@ static void sgmii_configure_repeater(int serdes_port)
        };
 
        int *riser_phy_addr = &xqsgii_riser_phy_addr[0];
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
        struct udevice *udev;
 #endif
 
        /* Set I2c to Slot 1 */
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
        ret = i2c_write(0x77, 0, 0, &a, 1);
 #else
        ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
@@ -146,7 +151,7 @@ static void sgmii_configure_repeater(int serdes_port)
                        mii_bus = 1;
                        dpmac_id = dpmac + 9;
                        a = 0xb;
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
                        ret = i2c_write(0x76, 0, 0, &a, 1);
 #else
                        ret = i2c_get_chip_for_busnum(0, 0x76, 1, &udev);
@@ -193,7 +198,7 @@ static void sgmii_configure_repeater(int serdes_port)
                                reg_pair[6].val = &ch_b_ctl2[j];
 
                                for (k = 0; k < 10; k++) {
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
                                        ret = i2c_write(i2c_addr[dpmac],
                                                        reg_pair[k].addr,
                                                        1, reg_pair[k].val, 1);
@@ -272,12 +277,12 @@ static void qsgmii_configure_repeater(int dpmac)
        const char *dev = "LS2080A_QDS_MDIO0";
        int ret = 0;
        unsigned short value;
-#ifdef CONFIG_DM_I2C
+#if CONFIG_IS_ENABLED(DM_I2C)
        struct udevice *udev;
 #endif
 
        /* Set I2c to Slot 1 */
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
        ret = i2c_write(0x77, 0, 0, &a, 1);
 #else
        ret = i2c_get_chip_for_busnum(0, 0x77, 1, &udev);
@@ -342,7 +347,7 @@ static void qsgmii_configure_repeater(int dpmac)
                        reg_pair[6].val = &ch_b_ctl2[j];
 
                        for (k = 0; k < 10; k++) {
-#ifndef CONFIG_DM_I2C
+#if !CONFIG_IS_ENABLED(DM_I2C)
                                ret = i2c_write(i2c_phy_addr,
                                                reg_pair[k].addr,
                                                1, reg_pair[k].val, 1);
@@ -497,7 +502,7 @@ static int ls2080a_qds_mdio_init(char *realbusname, u8 muxval)
  */
 static void initialize_dpmac_to_slot(void)
 {
-       struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
+       struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
        int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
                                FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
                >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
@@ -651,7 +656,7 @@ void ls2080a_handle_phy_interface_sgmii(int dpmac_id)
 {
        int lane, slot;
        struct mii_dev *bus;
-       struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
+       struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
        int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
                                FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
                >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
@@ -794,7 +799,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 {
        int lane = 0, slot;
        struct mii_dev *bus;
-       struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
+       struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
        int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
                                FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
                >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
@@ -859,7 +864,7 @@ void ls2080a_handle_phy_interface_qsgmii(int dpmac_id)
 
 void ls2080a_handle_phy_interface_xsgmii(int i)
 {
-       struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
+       struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
        int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
                                FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
                >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
@@ -869,13 +874,12 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
        case 0x4B:
        case 0x4C:
                /*
-                * XFI does not need a PHY to work, but to avoid U-Boot use
-                * default PHY address which is zero to a MAC when it found
-                * a MAC has no PHY address, we give a PHY address to XFI
-                * MAC, and should not use a real XAUI PHY address, since
-                * MDIO can access it successfully, and then MDIO thinks
-                * the XAUI card is used for the XFI MAC, which will cause
-                * error.
+                * 10GBase-R does not need a PHY to work, but to avoid U-Boot
+                * use default PHY address which is zero to a MAC when it found
+                * a MAC has no PHY address, we give a PHY address to 10GBase-R
+                * MAC, and should not use a real XAUI PHY address, since MDIO
+                * can access it successfully, and then MDIO thinks the XAUI
+                * card is used for the 10GBase-R MAC, which will cause error.
                 */
                wriop_set_phy_address(i, 0, i + 4);
                ls2080a_qds_enable_SFP_TX(SFP_TX);
@@ -888,12 +892,13 @@ void ls2080a_handle_phy_interface_xsgmii(int i)
        }
 }
 #endif
+#endif // !CONFIG_DM_ETH
 
-int board_eth_init(bd_t *bis)
+int board_eth_init(struct bd_info *bis)
 {
-       int error;
+#ifndef CONFIG_DM_ETH
 #if defined(CONFIG_FSL_MC_ENET) && !defined(CONFIG_SPL_BUILD)
-       struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
+       struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
        int serdes1_prtcl = (in_le32(&gur->rcwsr[28]) &
                                FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK)
                >> FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
@@ -905,6 +910,7 @@ int board_eth_init(bd_t *bis)
        struct memac_mdio_info *memac_mdio1_info;
        unsigned int i;
        char *env_hwconfig;
+       int error;
 
        env_hwconfig = env_get("hwconfig");
 
@@ -914,7 +920,7 @@ int board_eth_init(bd_t *bis)
                                        sizeof(struct memac_mdio_info));
        memac_mdio0_info->regs =
                (struct memac_mdio_controller *)
-                                       CONFIG_SYS_FSL_WRIOP1_MDIO1;
+                                       CFG_SYS_FSL_WRIOP1_MDIO1;
        memac_mdio0_info->name = DEFAULT_WRIOP_MDIO1_NAME;
 
        /* Register the real MDIO1 bus */
@@ -924,7 +930,7 @@ int board_eth_init(bd_t *bis)
                                        sizeof(struct memac_mdio_info));
        memac_mdio1_info->regs =
                (struct memac_mdio_controller *)
-                                       CONFIG_SYS_FSL_WRIOP1_MDIO2;
+                                       CFG_SYS_FSL_WRIOP1_MDIO2;
        memac_mdio1_info->name = DEFAULT_WRIOP_MDIO2_NAME;
 
        /* Register the real MDIO2 bus */
@@ -969,8 +975,13 @@ int board_eth_init(bd_t *bis)
                        sgmii_configure_repeater(2);
        }
 #endif
-       error = pci_eth_init(bis);
-       return error;
+#endif // !CONFIG_DM_ETH
+
+#ifdef CONFIG_DM_ETH
+       return 0;
+#else
+       return pci_eth_init(bis);
+#endif
 }
 
 #if defined(CONFIG_RESET_PHY_R)
@@ -979,3 +990,100 @@ void reset_phy(void)
        mc_env_boot();
 }
 #endif /* CONFIG_RESET_PHY_R */
+
+#if defined(CONFIG_DM_ETH) && defined(CONFIG_MULTI_DTB_FIT)
+
+/* Structure to hold SERDES protocols supported in case of
+ * CONFIG_DM_ETH enabled (network interfaces are described in the DTS).
+ *
+ * @serdes_block: the index of the SERDES block
+ * @serdes_protocol: the decimal value of the protocol supported
+ * @dts_needed: DTS notes describing the current configuration are needed
+ *
+ * When dts_needed is true, the board_fit_config_name_match() function
+ * will try to exactly match the current configuration of the block with a DTS
+ * name provided.
+ */
+static struct serdes_configuration {
+       u8 serdes_block;
+       u32 serdes_protocol;
+       bool dts_needed;
+} supported_protocols[] = {
+       /* Serdes block #1 */
+       {1, 42, true},
+
+       /* Serdes block #2 */
+       {2, 65, false},
+};
+
+#define SUPPORTED_SERDES_PROTOCOLS ARRAY_SIZE(supported_protocols)
+
+static bool protocol_supported(u8 serdes_block, u32 protocol)
+{
+       struct serdes_configuration serdes_conf;
+       int i;
+
+       for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
+               serdes_conf = supported_protocols[i];
+               if (serdes_conf.serdes_block == serdes_block &&
+                   serdes_conf.serdes_protocol == protocol)
+                       return true;
+       }
+
+       return false;
+}
+
+static void get_str_protocol(u8 serdes_block, u32 protocol, char *str)
+{
+       struct serdes_configuration serdes_conf;
+       int i;
+
+       for (i = 0; i < SUPPORTED_SERDES_PROTOCOLS; i++) {
+               serdes_conf = supported_protocols[i];
+               if (serdes_conf.serdes_block == serdes_block &&
+                   serdes_conf.serdes_protocol == protocol) {
+                       if (serdes_conf.dts_needed == true)
+                               sprintf(str, "%u", protocol);
+                       else
+                               sprintf(str, "x");
+                       return;
+               }
+       }
+}
+
+int board_fit_config_name_match(const char *name)
+{
+       struct ccsr_gur *gur = (void *)(CFG_SYS_FSL_GUTS_ADDR);
+       u32 rcw_status = in_le32(&gur->rcwsr[28]);
+       char srds_s1_str[2], srds_s2_str[2];
+       u32 srds_s1, srds_s2;
+       char expected_dts[100];
+
+       srds_s1 = rcw_status & FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_MASK;
+       srds_s1 >>= FSL_CHASSIS3_RCWSR28_SRDS1_PRTCL_SHIFT;
+
+       srds_s2 = rcw_status & FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_MASK;
+       srds_s2 >>= FSL_CHASSIS3_RCWSR28_SRDS2_PRTCL_SHIFT;
+
+       /* Check for supported protocols. The default DTS will be used
+        * in this case
+        */
+       if (!protocol_supported(1, srds_s1) ||
+           !protocol_supported(2, srds_s2))
+               return -1;
+
+       get_str_protocol(1, srds_s1, srds_s1_str);
+       get_str_protocol(2, srds_s2, srds_s2_str);
+
+       printf("expected_dts %s\n", expected_dts);
+       sprintf(expected_dts, "fsl-ls2080a-qds-%s-%s",
+               srds_s1_str, srds_s2_str);
+
+       if (!strcmp(name, expected_dts))
+               return 0;
+
+       printf("this is not!\n");
+       return -1;
+}
+
+#endif