]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
net: introduce helpers to get PHY interface mode from a device/ofnode
authorMarek Behún <marek.behun@nic.cz>
Wed, 6 Apr 2022 22:33:01 +0000 (00:33 +0200)
committerRamon Fried <ramon@neureality.ai>
Sun, 10 Apr 2022 05:44:12 +0000 (08:44 +0300)
Add helpers ofnode_read_phy_mode() and dev_read_phy_mode() to parse the
"phy-mode" / "phy-connection-type" property. Add corresponding UT test.

Use them treewide.

This allows us to inline the phy_get_interface_by_name() into
ofnode_read_phy_mode(), since the former is not used anymore.

Signed-off-by: Marek Behún <marek.behun@nic.cz>
Reviewed-by: Ramon Fried <rfried.dev@gmail.com>
Tested-by: Patrice Chotard <patrice.chotard@foss.st.com>
41 files changed:
arch/sandbox/dts/test.dts
board/st/stm32f746-disco/stm32f746-disco.c
drivers/core/ofnode.c
drivers/core/read.c
drivers/net/ag7xxx.c
drivers/net/altera_tse.c
drivers/net/bcm6348-eth.c
drivers/net/bcmgenet.c
drivers/net/designware.c
drivers/net/dwc_eth_qos.c
drivers/net/fec_mxc.c
drivers/net/fm/eth.c
drivers/net/fsl_enetc.c
drivers/net/ftgmac100.c
drivers/net/higmacv300.c
drivers/net/ldpaa_eth/ldpaa_eth.c
drivers/net/macb.c
drivers/net/mt7620-eth.c
drivers/net/mtk_eth.c
drivers/net/mvgbe.c
drivers/net/mvneta.c
drivers/net/mvpp2.c
drivers/net/phy/phy.c
drivers/net/pic32_eth.c
drivers/net/qe/dm_qe_uec.c
drivers/net/ravb.c
drivers/net/sh_eth.c
drivers/net/sni_ave.c
drivers/net/sni_netsec.c
drivers/net/sun8i_emac.c
drivers/net/ti/am65-cpsw-nuss.c
drivers/net/ti/cpsw.c
drivers/net/ti/keystone_net.c
drivers/net/tsec.c
drivers/net/xilinx_axi_emac.c
drivers/net/zynq_gem.c
include/dm/ofnode.h
include/dm/read.h
include/phy.h
net/mdio-uclass.c
test/dm/ofnode.c

index e536943503df645e6703c34bf474898626097014..5b38ee4a5f9a0440ebf5d3f30cc129444f942d26 100644 (file)
                reg = <0x10007000 0x1000>;
                fake-host-hwaddr = [00 00 66 44 22 77];
                phy-handle = <&ethphy1>;
+               phy-mode = "2500base-x";
        };
 
        dsa_eth0: dsa-test-eth {
index 95d83e73ee89e86cbbae363bd9836618f965f166..69f657c54b88e61d1ccd93da6936ab78a399923b 100644 (file)
@@ -117,16 +117,13 @@ int board_late_init(void)
 int board_init(void)
 {
 #ifdef CONFIG_ETH_DESIGNWARE
-       const char *phy_mode;
-       int node;
+       ofnode node;
 
-       node = fdt_node_offset_by_compatible(gd->fdt_blob, 0, "st,stm32-dwmac");
-       if (node < 0)
+       node = ofnode_by_compatible(ofnode_null(), "st,stm32-dwmac");
+       if (!ofnode_valid(node))
                return -1;
 
-       phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
-
-       switch (phy_get_interface_by_name(phy_mode)) {
+       switch (ofnode_read_phy_mode(node)) {
        case PHY_INTERFACE_MODE_RMII:
                STM32_SYSCFG->pmc |= SYSCFG_PMC_MII_RMII_SEL;
                break;
@@ -134,7 +131,7 @@ int board_init(void)
                STM32_SYSCFG->pmc &= ~SYSCFG_PMC_MII_RMII_SEL;
                break;
        default:
-               printf("PHY interface %s not supported !\n", phy_mode);
+               printf("Unsupported PHY interface!\n");
        }
 #endif
 
index 445b7ad5add39e64899cfba1ffb3e67238e345bf..f644a593d32ee5a00e8eff5f2a0219b192cbf9fd 100644 (file)
@@ -1219,3 +1219,26 @@ ofnode ofnode_get_phy_node(ofnode node)
 
        return args.node;
 }
+
+phy_interface_t ofnode_read_phy_mode(ofnode node)
+{
+       const char *mode;
+       int i;
+
+       assert(ofnode_valid(node));
+
+       mode = ofnode_read_string(node, "phy-mode");
+       if (!mode)
+               mode = ofnode_read_string(node, "phy-connection-type");
+
+       if (!mode)
+               return PHY_INTERFACE_MODE_NONE;
+
+       for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++)
+               if (!strcmp(mode, phy_interface_strings[i]))
+                       return i;
+
+       debug("%s: Invalid PHY interface '%s'\n", __func__, mode);
+
+       return PHY_INTERFACE_MODE_NONE;
+}
index 7ff100218d3181b31edae0d52198f85909c35193..c73508d2760805a65a25b567b189ce614220a640 100644 (file)
@@ -403,3 +403,8 @@ ofnode dev_get_phy_node(const struct udevice *dev)
 {
        return ofnode_get_phy_node(dev_ofnode(dev));
 }
+
+phy_interface_t dev_read_phy_mode(const struct udevice *dev)
+{
+       return ofnode_read_phy_mode(dev_ofnode(dev));
+}
index 632ab3c1e5d1d526da6b3cc28d7f093198281c85..f24a917bd43acba1f5a4b48dd3bf913c4c164bcb 100644 (file)
@@ -1254,7 +1254,6 @@ static const struct eth_ops ag7xxx_eth_ops = {
 static int ag7xxx_eth_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
        int ret;
 
        pdata->iobase = dev_read_addr(dev);
@@ -1265,13 +1264,9 @@ static int ag7xxx_eth_of_to_plat(struct udevice *dev)
        if (ret <= 0)
                return ret;
 
-       phy_mode = fdt_getprop(gd->fdt_blob, ret, "phy-mode", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        return 0;
 }
index eb4cd96763bd3cb1c72b1631ed70f0e3a8f4f76f..25247472b033bf1aca875915a3b321d74490709a 100644 (file)
@@ -676,17 +676,10 @@ static int altera_tse_probe(struct udevice *dev)
 static int altera_tse_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
-
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        return 0;
 }
index 06e0dd74a5bf8ada5a4d5567e19a555600705aef..8f1864a334c7299b3f10b1862316d9f20b6aabd4 100644 (file)
@@ -415,7 +415,6 @@ static int bcm6348_eth_probe(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct bcm6348_eth_priv *priv = dev_get_priv(dev);
        struct ofnode_phandle_args phy;
-       const char *phy_mode;
        int ret, i;
 
        /* get base address */
@@ -425,10 +424,7 @@ static int bcm6348_eth_probe(struct udevice *dev)
        pdata->iobase = (phys_addr_t) priv->base;
 
        /* get phy mode */
-       pdata->phy_interface = PHY_INTERFACE_MODE_NONE;
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
        if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -ENODEV;
 
index 67839563dbe4891558aeda99cf5e904dcc01e1ae..c6acb4932b480a677efb61818b3b05968adfddb7 100644 (file)
@@ -690,20 +690,14 @@ static int bcmgenet_eth_of_to_plat(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct bcmgenet_eth_priv *priv = dev_get_priv(dev);
        struct ofnode_phandle_args phy_node;
-       const char *phy_mode;
        int ret;
 
        pdata->iobase = dev_read_addr(dev);
 
        /* Get phy mode from DT */
-       pdata->phy_interface = -1;
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
                                         &phy_node);
index 5aaac603a0eccecf93688760ed5ab7ce9de267f5..7b7b0f65780828c07394a4d028c621c3add23bb0 100644 (file)
@@ -914,21 +914,15 @@ int designware_eth_of_to_plat(struct udevice *dev)
        struct dw_eth_dev *priv = dev_get_priv(dev);
 #endif
        struct eth_pdata *pdata = &dw_pdata->eth_pdata;
-       const char *phy_mode;
 #if CONFIG_IS_ENABLED(DM_GPIO)
        int reset_flags = GPIOD_IS_OUT;
 #endif
        int ret = 0;
 
        pdata->iobase = dev_read_addr(dev);
-       pdata->phy_interface = -1;
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0);
 
index 22dad5b2030a4eb37bc056ad9c0e2a2c5a20f26c..9777f6cb9c60d280a12b32ee074a61f9344eb74b 100644 (file)
@@ -270,7 +270,7 @@ struct eqos_config {
        int config_mac;
        int config_mac_mdio;
        unsigned int axi_bus_width;
-       phy_interface_t (*interface)(struct udevice *dev);
+       phy_interface_t (*interface)(const struct udevice *dev);
        struct eqos_ops *ops;
 };
 
@@ -1729,21 +1729,7 @@ err_probe:
        return ret;
 }
 
-static phy_interface_t eqos_get_interface_stm32(struct udevice *dev)
-{
-       const char *phy_mode;
-       phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
-
-       debug("%s(dev=%p):\n", __func__, dev);
-
-       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-       if (phy_mode)
-               interface = phy_get_interface_by_name(phy_mode);
-
-       return interface;
-}
-
-static phy_interface_t eqos_get_interface_tegra186(struct udevice *dev)
+static phy_interface_t eqos_get_interface_tegra186(const struct udevice *dev)
 {
        return PHY_INTERFACE_MODE_MII;
 }
@@ -1766,20 +1752,6 @@ static int eqos_probe_resources_imx(struct udevice *dev)
        return 0;
 }
 
-static phy_interface_t eqos_get_interface_imx(struct udevice *dev)
-{
-       const char *phy_mode;
-       phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
-
-       debug("%s(dev=%p):\n", __func__, dev);
-
-       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-       if (phy_mode)
-               interface = phy_get_interface_by_name(phy_mode);
-
-       return interface;
-}
-
 static int eqos_remove_resources_tegra186(struct udevice *dev)
 {
        struct eqos_priv *eqos = dev_get_priv(dev);
@@ -1985,7 +1957,7 @@ static const struct eqos_config __maybe_unused eqos_stm32_config = {
        .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_AV,
        .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
        .axi_bus_width = EQOS_AXI_WIDTH_64,
-       .interface = eqos_get_interface_stm32,
+       .interface = dev_read_phy_mode,
        .ops = &eqos_stm32_ops
 };
 
@@ -2013,7 +1985,7 @@ struct eqos_config __maybe_unused eqos_imx_config = {
        .config_mac = EQOS_MAC_RXQ_CTRL0_RXQ0EN_ENABLED_DCB,
        .config_mac_mdio = EQOS_MAC_MDIO_ADDRESS_CR_250_300,
        .axi_bus_width = EQOS_AXI_WIDTH_64,
-       .interface = eqos_get_interface_imx,
+       .interface = dev_read_phy_mode,
        .ops = &eqos_imx_ops
 };
 
index e8ebef09032aa0c065e7c3584ff92f106575a804..22c2a3a30f29992e5256341270584f51dac29418 100644 (file)
@@ -1310,20 +1310,13 @@ static int fecmxc_of_to_plat(struct udevice *dev)
        int ret = 0;
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct fec_priv *priv = dev_get_priv(dev);
-       const char *phy_mode;
 
        pdata->iobase = dev_read_addr(dev);
        priv->eth = (struct ethernet_regs *)pdata->iobase;
 
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
 #ifdef CONFIG_DM_REGULATOR
        device_get_supply_regulator(dev, "phy-supply", &priv->phy_supply);
index 5e0d0bca9b53b4a684537a79941660890c9791b1..1ffe9e2b7a583ba8602602cc7e7b43d9821aaf95 100644 (file)
@@ -954,17 +954,6 @@ int fm_eth_initialize(struct ccsr_fman *reg, struct fm_eth_info *info)
        return 0;
 }
 #else /* CONFIG_DM_ETH */
-#ifdef CONFIG_PHYLIB
-phy_interface_t fman_read_sys_if(struct udevice *dev)
-{
-       const char *if_str;
-
-       if_str = ofnode_read_string(dev_ofnode(dev), "phy-connection-type");
-       debug("MAC system interface mode %s\n", if_str);
-
-       return phy_get_interface_by_name(if_str);
-}
-#endif
 
 static int fm_eth_bind(struct udevice *dev)
 {
@@ -1038,7 +1027,7 @@ static int fm_eth_probe(struct udevice *dev)
        reg = (void *)(uintptr_t)dev_read_addr(dev);
        fm_eth->mac_type = dev_get_driver_data(dev);
 #ifdef CONFIG_PHYLIB
-       fm_eth->enet_if = fman_read_sys_if(dev);
+       fm_eth->enet_if = dev_read_phy_mode(dev);
 #else
        fm_eth->enet_if = PHY_INTERFACE_MODE_SGMII;
        printf("%s: warning - unable to determine interface type\n", __func__);
index 915c7c80256fd7e1b5e424a5fa97f609ee863126..8f5af1dbc03bd4332b12aedc2d3781fdccf1cce2 100644 (file)
@@ -260,9 +260,6 @@ static int enetc_init_sxgmii(struct udevice *dev)
 static void enetc_start_pcs(struct udevice *dev)
 {
        struct enetc_priv *priv = dev_get_priv(dev);
-       const char *if_str;
-
-       priv->if_type = PHY_INTERFACE_MODE_NONE;
 
        /* register internal MDIO for debug purposes */
        if (enetc_read_port(priv, ENETC_PCAPR0) & ENETC_PCAPRO_MDIO) {
@@ -279,14 +276,12 @@ static void enetc_start_pcs(struct udevice *dev)
                return;
        }
 
-       if_str = ofnode_read_string(dev_ofnode(dev), "phy-mode");
-       if (if_str)
-               priv->if_type = phy_get_interface_by_name(if_str);
-       else
+       priv->if_type = dev_read_phy_mode(dev);
+       if (priv->if_type == PHY_INTERFACE_MODE_NONE) {
                enetc_dbg(dev,
                          "phy-mode property not found, defaulting to SGMII\n");
-       if (priv->if_type < 0)
-               priv->if_type = PHY_INTERFACE_MODE_NONE;
+               priv->if_type = PHY_INTERFACE_MODE_SGMII;
+       }
 
        switch (priv->if_type) {
        case PHY_INTERFACE_MODE_SGMII:
index aa719d295f3d201e0f61520c0c83abc1dbe5fb43..626c27d7bf8c95962f543312c5f3c44b8c5b44dc 100644 (file)
@@ -549,17 +549,12 @@ static int ftgmac100_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct ftgmac100_data *priv = dev_get_priv(dev);
-       const char *phy_mode;
 
        pdata->iobase = dev_read_addr(dev);
-       pdata->phy_interface = -1;
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
+
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        pdata->max_speed = dev_read_u32_default(dev, "max-speed", 0);
 
index aa79d6eda815db00eb30d9c91041f9e58cb4a006..ce8f2dfd09870d7429778f8c7523a98ea0e988d8 100644 (file)
@@ -561,19 +561,14 @@ static int higmac_remove(struct udevice *dev)
 static int higmac_of_to_plat(struct udevice *dev)
 {
        struct higmac_priv *priv = dev_get_priv(dev);
-       int phyintf = PHY_INTERFACE_MODE_NONE;
-       const char *phy_mode;
        ofnode phy_node;
 
        priv->base = dev_remap_addr_index(dev, 0);
        priv->macif_ctrl = dev_remap_addr_index(dev, 1);
 
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode)
-               phyintf = phy_get_interface_by_name(phy_mode);
-       if (phyintf == PHY_INTERFACE_MODE_NONE)
+       priv->phyintf = dev_read_phy_mode(dev);
+       if (priv->phyintf == PHY_INTERFACE_MODE_NONE)
                return -ENODEV;
-       priv->phyintf = phyintf;
 
        phy_node = dev_read_subnode(dev, "phy");
        if (!ofnode_valid(phy_node)) {
index 725173f6273789323ba097c5a1661c0ba1ce1468..c775598b91f96f84cb9d7054ee80262317fec803 100644 (file)
@@ -1120,31 +1120,14 @@ static uint32_t ldpaa_eth_get_dpmac_id(struct udevice *dev)
        return fdtdec_get_uint(gd->fdt_blob, port_node, "reg", -1);
 }
 
-static const char *ldpaa_eth_get_phy_mode_str(struct udevice *dev)
-{
-       int port_node = dev_of_offset(dev);
-       const char *phy_mode_str;
-
-       phy_mode_str = fdt_getprop(gd->fdt_blob, port_node,
-                                  "phy-connection-type", NULL);
-       if (phy_mode_str)
-               return phy_mode_str;
-
-       phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL);
-       return phy_mode_str;
-}
-
 static int ldpaa_eth_bind(struct udevice *dev)
 {
-       const char *phy_mode_str = NULL;
        uint32_t dpmac_id;
        char eth_name[16];
        int phy_mode = -1;
 
-       phy_mode_str = ldpaa_eth_get_phy_mode_str(dev);
-       if (phy_mode_str)
-               phy_mode = phy_get_interface_by_name(phy_mode_str);
-       if (phy_mode == -1) {
+       phy_mode = dev_read_phy_mode(dev);
+       if (phy_mode == PHY_INTERFACE_MODE_NONE) {
                dev_err(dev, "incorrect phy mode\n");
                return -EINVAL;
        }
@@ -1155,7 +1138,8 @@ static int ldpaa_eth_bind(struct udevice *dev)
                return -EINVAL;
        }
 
-       sprintf(eth_name, "DPMAC%d@%s", dpmac_id, phy_mode_str);
+       sprintf(eth_name, "DPMAC%d@%s", dpmac_id,
+               phy_string_for_interface(phy_mode));
        device_set_name(dev, eth_name);
 
        return 0;
@@ -1164,11 +1148,9 @@ static int ldpaa_eth_bind(struct udevice *dev)
 static int ldpaa_eth_of_to_plat(struct udevice *dev)
 {
        struct ldpaa_eth_priv *priv = dev_get_priv(dev);
-       const char *phy_mode_str;
 
        priv->dpmac_id = ldpaa_eth_get_dpmac_id(dev);
-       phy_mode_str = ldpaa_eth_get_phy_mode_str(dev);
-       priv->phy_mode = phy_get_interface_by_name(phy_mode_str);
+       priv->phy_mode = dev_read_phy_mode(dev);
 
        return 0;
 }
index 37eed59a69eeb581ba0d64390e502d87ce47398e..317b380e8fe1acd44da112f9e89f216c0f784ccb 100644 (file)
@@ -1360,17 +1360,11 @@ static int macb_eth_probe(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct macb_device *macb = dev_get_priv(dev);
        struct ofnode_phandle_args phandle_args;
-       const char *phy_mode;
        int ret;
 
-       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-
-       if (phy_mode)
-               macb->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (macb->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       macb->phy_interface = dev_read_phy_mode(dev);
+       if (macb->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        /* Read phyaddr from DT */
        if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
index 222250d52ad046fcd5730968fc1a0d349c879554..24fcb9373f83d0ed021036e331918a0af35e1d99 100644 (file)
@@ -1048,33 +1048,20 @@ static int mt7620_eth_parse_gsw_port(struct mt7620_eth_priv *priv, u32 idx,
                                     ofnode node)
 {
        ofnode subnode;
-       const char *str;
-       int mode, speed, ret;
+       int speed, ret;
        u32 phy_addr;
 
-       str = ofnode_read_string(node, "phy-mode");
-       if (str) {
-               mode = phy_get_interface_by_name(str);
-               if (mode < 0) {
-                       dev_err(priv->dev, "mt7620_eth: invalid phy-mode\n");
-                       return -EINVAL;
-               }
-
-               switch (mode) {
-               case PHY_INTERFACE_MODE_MII:
-               case PHY_INTERFACE_MODE_RMII:
-               case PHY_INTERFACE_MODE_RGMII:
-               case PHY_INTERFACE_MODE_NONE:
-                       break;
-               default:
-                       dev_err(priv->dev,
-                               "mt7620_eth: unsupported phy-mode\n");
-                       return -ENOTSUPP;
-               }
+       priv->port_cfg[idx].mode = ofnode_read_phy_mode(node);
 
-               priv->port_cfg[idx].mode = mode;
-       } else {
-               priv->port_cfg[idx].mode = PHY_INTERFACE_MODE_NONE;
+       switch (priv->port_cfg[idx].mode) {
+       case PHY_INTERFACE_MODE_MII:
+       case PHY_INTERFACE_MODE_RMII:
+       case PHY_INTERFACE_MODE_RGMII:
+       case PHY_INTERFACE_MODE_NONE:
+               break;
+       default:
+               dev_err(priv->dev, "mt7620_eth: unsupported phy-mode\n");
+               return -ENOTSUPP;
        }
 
        subnode = ofnode_find_subnode(node, "fixed-link");
index 26f02847a2e7bf411ba41c8f67c093b227d81b9e..d6065db5fb71cc55b4f7885654acff9dfb8587e1 100644 (file)
@@ -1447,11 +1447,9 @@ static int mtk_eth_of_to_plat(struct udevice *dev)
        priv->gmac_id = dev_read_u32_default(dev, "mediatek,gmac-id", 0);
 
        /* Interface mode is required */
-       str = dev_read_string(dev, "phy-mode");
-       if (str) {
-               pdata->phy_interface = phy_get_interface_by_name(str);
-               priv->phy_interface = pdata->phy_interface;
-       } else {
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       priv->phy_interface = pdata->phy_interface;
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) {
                printf("error: phy-mode is not set\n");
                return -EINVAL;
        }
index 954bf86121a4988197fd965f81e4af6d477ef4d5..32ec0b437d3b631c376ef6bf490774fd4d389026 100644 (file)
@@ -993,7 +993,6 @@ static int mvgbe_of_to_plat(struct udevice *dev)
        struct mvgbe_device *dmvgbe = dev_get_priv(dev);
        void *blob = (void *)gd->fdt_blob;
        int node = dev_of_offset(dev);
-       const char *phy_mode;
        int fl_node;
        int pnode;
        unsigned long addr;
@@ -1005,10 +1004,8 @@ static int mvgbe_of_to_plat(struct udevice *dev)
                                              "marvell,kirkwood-eth-port");
 
        /* Get phy-mode / phy_interface from DT */
-       phy_mode = fdt_getprop(gd->fdt_blob, pnode, "phy-mode", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       else
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                pdata->phy_interface = PHY_INTERFACE_MODE_GMII;
 
        dmvgbe->phy_interface = pdata->phy_interface;
index 4a4268c2b2cc07ee0670e5808cdc6d0acc416215..d31b96a9d82b4b97ba0598ca1a756b1a0807722d 100644 (file)
@@ -1799,20 +1799,13 @@ static const struct eth_ops mvneta_ops = {
 static int mvneta_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
 
        pdata->iobase = dev_read_addr(dev);
 
        /* Get phy-mode / phy_interface from DT */
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        return 0;
 }
index 4c0a7b0a9f5c6df2c68e2d61e26e31d9a1cadd30..dfddac180fd7214ae5d822dfc205ebf820d74405 100644 (file)
@@ -4786,11 +4786,9 @@ static int mvpp2_port_init(struct udevice *dev, struct mvpp2_port *port)
 static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
 {
        int port_node = dev_of_offset(dev);
-       const char *phy_mode_str;
        int phy_node;
        u32 id;
        u32 phyaddr = 0;
-       int phy_mode = -1;
        int fixed_link = 0;
        int ret;
 
@@ -4821,10 +4819,8 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
                phyaddr = PHY_MAX_ADDR;
        }
 
-       phy_mode_str = fdt_getprop(gd->fdt_blob, port_node, "phy-mode", NULL);
-       if (phy_mode_str)
-               phy_mode = phy_get_interface_by_name(phy_mode_str);
-       if (phy_mode == -1) {
+       port->phy_interface = dev_read_phy_mode(dev);
+       if (port->phy_interface == PHY_INTERFACE_MODE_NONE) {
                dev_err(dev, "incorrect phy mode\n");
                return -EINVAL;
        }
@@ -4847,7 +4843,6 @@ static int phy_info_parse(struct udevice *dev, struct mvpp2_port *port)
                port->first_rxq = port->id * rxq_number;
        else
                port->first_rxq = port->id * port->priv->max_port_rxqs;
-       port->phy_interface = phy_mode;
        port->phyaddr = phyaddr;
 
        return 0;
index c8289d38898e9c736c4cca4a46d2cadc293fca60..ba7b361c3d9a19a49fc900db1a89cb2f82f90e2b 100644 (file)
@@ -982,25 +982,16 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus,
  */
 struct phy_device *fixed_phy_create(ofnode node)
 {
-       phy_interface_t interface = PHY_INTERFACE_MODE_NONE;
        struct phy_device *phydev;
-       const char *if_str;
        ofnode subnode;
 
-       if_str = ofnode_read_string(node, "phy-mode");
-       if (!if_str) {
-               if_str = ofnode_read_string(node, "phy-connection-type");
-       }
-       if (if_str) {
-               interface = phy_get_interface_by_name(if_str);
-       }
-
        subnode = ofnode_find_subnode(node, "fixed-link");
        if (!ofnode_valid(subnode)) {
                return NULL;
        }
 
-       phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, interface);
+       phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false,
+                                  ofnode_read_phy_mode(node));
        if (phydev)
                phydev->node = subnode;
 
@@ -1098,15 +1089,3 @@ int phy_shutdown(struct phy_device *phydev)
 
        return 0;
 }
-
-int phy_get_interface_by_name(const char *str)
-{
-       int i;
-
-       for (i = 0; i < PHY_INTERFACE_MODE_COUNT; i++) {
-               if (!strcmp(str, phy_interface_strings[i]))
-                       return i;
-       }
-
-       return -1;
-}
index 5a678d1cf95274d286bea4f51673b1c6c5f46bc3..03eb51e51d585c9d6ee715f57087a93af126057b 100644 (file)
@@ -534,7 +534,6 @@ static int pic32_eth_probe(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct pic32eth_dev *priv = dev_get_priv(dev);
-       const char *phy_mode;
        void __iomem *iobase;
        fdt_addr_t addr;
        fdt_size_t size;
@@ -550,15 +549,9 @@ static int pic32_eth_probe(struct udevice *dev)
        pdata->iobase = (phys_addr_t)addr;
 
        /* get phy mode */
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        /* get phy addr */
        offset = fdtdec_lookup_phandle(gd->fdt_blob, dev_of_offset(dev),
index a12c8cd2ac5c3fbc8138e03357a843274c98401d..5a66d726cd6bb1f860aa0d7424e5ac4a5ce63505 100644 (file)
@@ -1133,19 +1133,12 @@ static int qe_uec_remove(struct udevice *dev)
 static int qe_uec_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
 
        pdata->iobase = (phys_addr_t)devfdt_get_addr(dev);
 
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev),
-                              "phy-connection-type", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        return 0;
 }
index 4078d33bb5edd40308ac11f94eae47ec3449b70e..f6d386bd6b8bd1a388ad2b75ffab3895de543284 100644 (file)
@@ -674,20 +674,13 @@ static const struct eth_ops ravb_ops = {
 int ravb_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
        const fdt32_t *cell;
-       int ret = 0;
 
        pdata->iobase = dev_read_addr(dev);
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        pdata->max_speed = 1000;
        cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL);
@@ -696,7 +689,7 @@ int ravb_of_to_plat(struct udevice *dev)
 
        sprintf(bb_miiphy_buses[0].name, dev->name);
 
-       return ret;
+       return 0;
 }
 
 static const struct udevice_id ravb_ids[] = {
index 4055f07b2feb660a3e1e0852a61ff67abe34650b..04c9c2d968f17a7c3406459612c1738f44340a35 100644 (file)
@@ -915,20 +915,13 @@ static const struct eth_ops sh_ether_ops = {
 int sh_ether_of_to_plat(struct udevice *dev)
 {
        struct eth_pdata *pdata = dev_get_plat(dev);
-       const char *phy_mode;
        const fdt32_t *cell;
-       int ret = 0;
 
        pdata->iobase = dev_read_addr(dev);
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        pdata->max_speed = 1000;
        cell = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed", NULL);
@@ -937,7 +930,7 @@ int sh_ether_of_to_plat(struct udevice *dev)
 
        sprintf(bb_miiphy_buses[0].name, dev->name);
 
-       return ret;
+       return 0;
 }
 
 static const struct udevice_id sh_ether_ids[] = {
index ab51552ed88b031fd414ccd11b869ab4aaec4e8d..0a368c6d03a8e699d53c24a5fe48d845a20282c7 100644 (file)
@@ -738,7 +738,6 @@ static int ave_of_to_plat(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct ave_private *priv = dev_get_priv(dev);
        struct ofnode_phandle_args args;
-       const char *phy_mode;
        const u32 *valp;
        int ret, nc, nr;
        const char *name;
@@ -748,15 +747,10 @@ static int ave_of_to_plat(struct udevice *dev)
                return -EINVAL;
 
        pdata->iobase = dev_read_addr(dev);
-       pdata->phy_interface = -1;
-       phy_mode = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "phy-mode",
-                              NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               dev_err(dev, "Invalid PHY interface '%s'\n", phy_mode);
+
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        pdata->max_speed = 0;
        valp = fdt_getprop(gd->fdt_blob, dev_of_offset(dev), "max-speed",
index 4901321d0cf2f8f46fc49294c0041e56706287c5..693fd3a35db94b2c40a4b3f4f05d5be2986d4848 100644 (file)
@@ -1029,19 +1029,13 @@ static int netsec_of_to_plat(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct netsec_priv *priv = dev_get_priv(dev);
        struct ofnode_phandle_args phandle_args;
-       const char *phy_mode;
 
        pdata->iobase = dev_read_addr_index(dev, 0);
        priv->eeprom_base = dev_read_addr_index(dev, 1) - EERPROM_MAP_OFFSET;
 
-       pdata->phy_interface = -1;
-       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               pr_err("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        if (!dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0,
                                        &phandle_args))
index 2e24d1221414e4305070dd2965fd3c40939ee411..5654a3430e2c8111293a2d3a1b7269bc90146b38 100644 (file)
@@ -882,7 +882,6 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
        struct sun8i_eth_pdata *sun8i_pdata = dev_get_plat(dev);
        struct eth_pdata *pdata = &sun8i_pdata->eth_pdata;
        struct emac_eth_dev *priv = dev_get_priv(dev);
-       const char *phy_mode;
        const fdt32_t *reg;
        int node = dev_of_offset(dev);
        int offset = 0;
@@ -946,16 +945,10 @@ static int sun8i_emac_eth_of_to_plat(struct udevice *dev)
        }
        priv->phyaddr = fdtdec_get_int(gd->fdt_blob, offset, "reg", -1);
 
-       phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
-
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
        printf("phy interface%d\n", pdata->phy_interface);
-
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        if (priv->variant == H3_EMAC) {
                ret = sun8i_handle_internal_phy(dev, priv);
index 87f51b3b99b6cb5da5797ab38c5cbd929d5f7d8f..c1da33473958d543df0712d47887618e2f0c51a6 100644 (file)
@@ -602,21 +602,14 @@ static int am65_cpsw_ofdata_parse_phy(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct am65_cpsw_priv *priv = dev_get_priv(dev);
        struct ofnode_phandle_args out_args;
-       const char *phy_mode;
        int ret = 0;
 
        dev_read_u32(dev, "reg", &priv->port_id);
 
-       phy_mode = dev_read_string(dev, "phy-mode");
-       if (phy_mode) {
-               pdata->phy_interface =
-                               phy_get_interface_by_name(phy_mode);
-               if (pdata->phy_interface == -1) {
-                       dev_err(dev, "Invalid PHY mode '%s', port %u\n",
-                               phy_mode, priv->port_id);
-                       ret = -EINVAL;
-                       goto out;
-               }
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE) {
+               dev_err(dev, "Invalid PHY mode, port %u\n", priv->port_id);
+               return -EINVAL;
        }
 
        dev_read_u32(dev, "max-speed", (u32 *)&pdata->max_speed);
index 68f4191fe978cb34896e518c63359dd9dafdf1dc..5b7bab734e468295128e5a9a37c78cc6692de290 100644 (file)
@@ -1194,15 +1194,12 @@ static void cpsw_eth_of_parse_slave(struct cpsw_platform_data *data,
 {
        struct ofnode_phandle_args out_args;
        struct cpsw_slave_data *slave_data;
-       const char *phy_mode;
        u32 phy_id[2];
        int ret;
 
        slave_data = &data->slave_data[slave_index];
 
-       phy_mode = ofnode_read_string(subnode, "phy-mode");
-       if (phy_mode)
-               slave_data->phy_if = phy_get_interface_by_name(phy_mode);
+       slave_data->phy_if = ofnode_read_phy_mode(subnode);
 
        ret = ofnode_parse_phandle_with_args(subnode, "phy-handle",
                                             NULL, 0, 0, &out_args);
@@ -1348,11 +1345,8 @@ static int cpsw_eth_of_to_plat(struct udevice *dev)
        }
 
        pdata->phy_interface = data->slave_data[data->active_slave].phy_if;
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__,
-                     phy_string_for_interface(pdata->phy_interface));
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
 
        return 0;
 }
index 5e8f683c29e32b7b2857069dbc99e77d6fd17688..b55e7da4c1820bc6a3ebe8e8200fe0819785810e 100644 (file)
@@ -687,7 +687,6 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave,
        int phy;
        int dma_count;
        u32 dma_channel[8];
-       const char *phy_mode;
 
        priv->slave_port = fdtdec_get_int(fdt, slave, "slave-port", -1);
        priv->net_rx_buffs.rx_flow = priv->slave_port * 8;
@@ -728,20 +727,19 @@ static int ks2_eth_parse_slave_interface(int netcp, int slave,
                priv->sgmii_link_type = SGMII_LINK_MAC_PHY;
                priv->has_mdio = true;
        } else if (priv->link_type == LINK_TYPE_RGMII_LINK_MAC_PHY) {
-               phy_mode = fdt_getprop(fdt, slave, "phy-mode", NULL);
-               if (phy_mode) {
-                       priv->phy_if = phy_get_interface_by_name(phy_mode);
-                       if (priv->phy_if != PHY_INTERFACE_MODE_RGMII &&
-                           priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID &&
-                           priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID &&
-                           priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) {
-                               pr_err("invalid phy-mode\n");
-                               return -EINVAL;
-                       }
-               } else {
+               priv->phy_if = ofnode_read_phy_mode(offset_to_ofnode(slave));
+               if (priv->phy_if == PHY_INTERFACE_MODE_NONE)
                        priv->phy_if = PHY_INTERFACE_MODE_RGMII;
-               }
                pdata->phy_interface = priv->phy_if;
+
+               if (priv->phy_if != PHY_INTERFACE_MODE_RGMII &&
+                   priv->phy_if != PHY_INTERFACE_MODE_RGMII_ID &&
+                   priv->phy_if != PHY_INTERFACE_MODE_RGMII_RXID &&
+                   priv->phy_if != PHY_INTERFACE_MODE_RGMII_TXID) {
+                       pr_err("invalid phy-mode\n");
+                       return -EINVAL;
+               }
+
                priv->has_mdio = true;
        }
 
index beca886b256cd1a8bf2c136a7396101859ccd7bc..fec051ebb7c1b85188a309d5271049bb3a9a3760 100644 (file)
@@ -834,7 +834,6 @@ int tsec_probe(struct udevice *dev)
        struct ofnode_phandle_args phandle_args;
        u32 tbiaddr = CONFIG_SYS_TBIPA_VALUE;
        struct tsec_data *data;
-       const char *phy_mode;
        ofnode parent, child;
        fdt_addr_t reg;
        u32 max_speed;
@@ -894,12 +893,8 @@ int tsec_probe(struct udevice *dev)
 
        priv->tbiaddr = tbiaddr;
 
-       phy_mode = dev_read_prop(dev, "phy-connection-type", NULL);
-       if (!phy_mode)
-               phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1)
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                pdata->phy_interface = tsec_get_interface(priv);
 
        priv->interface = pdata->phy_interface;
index f21addb4d08898154c49bbbf3d40f57e74b5bb35..02d13c3e0ad6dc74f6b462d6357929cf31d95b9a 100644 (file)
@@ -821,7 +821,6 @@ static int axi_emac_of_to_plat(struct udevice *dev)
        struct eth_pdata *pdata = &plat->eth_pdata;
        int node = dev_of_offset(dev);
        int offset = 0;
-       const char *phy_mode;
 
        pdata->iobase = dev_read_addr(dev);
        plat->mactype = dev_get_driver_data(dev);
@@ -850,14 +849,9 @@ static int axi_emac_of_to_plat(struct udevice *dev)
                        plat->phy_of_handle = offset;
                }
 
-               phy_mode = fdt_getprop(gd->fdt_blob, node, "phy-mode", NULL);
-               if (phy_mode)
-                       pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-               if (pdata->phy_interface == -1) {
-                       printf("%s: Invalid PHY interface '%s'\n", __func__,
-                              phy_mode);
+               pdata->phy_interface = dev_read_phy_mode(dev);
+               if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                        return -EINVAL;
-               }
 
                plat->eth_hasnobuf = fdtdec_get_bool(gd->fdt_blob, node,
                                                     "xlnx,eth-hasnobuf");
index 3118d1472669e9e10f35b08ac6772329d278817a..0062851134d8c365c5297cb6915295ae55c079e8 100644 (file)
@@ -827,7 +827,6 @@ static int zynq_gem_of_to_plat(struct udevice *dev)
        struct eth_pdata *pdata = dev_get_plat(dev);
        struct zynq_gem_priv *priv = dev_get_priv(dev);
        struct ofnode_phandle_args phandle_args;
-       const char *phy_mode;
 
        pdata->iobase = (phys_addr_t)dev_read_addr(dev);
        priv->iobase = (struct zynq_gem_regs *)pdata->iobase;
@@ -859,13 +858,9 @@ static int zynq_gem_of_to_plat(struct udevice *dev)
                }
        }
 
-       phy_mode = dev_read_prop(dev, "phy-mode", NULL);
-       if (phy_mode)
-               pdata->phy_interface = phy_get_interface_by_name(phy_mode);
-       if (pdata->phy_interface == -1) {
-               debug("%s: Invalid PHY interface '%s'\n", __func__, phy_mode);
+       pdata->phy_interface = dev_read_phy_mode(dev);
+       if (pdata->phy_interface == PHY_INTERFACE_MODE_NONE)
                return -EINVAL;
-       }
        priv->interface = pdata->phy_interface;
 
        priv->int_pcs = dev_read_bool(dev, "is-internal-pcspma");
index 429aee28126cb725604d14601962a5515df964d3..3bd3ba492539f3c002f9de82d91d96bc3660e6c4 100644 (file)
@@ -12,6 +12,7 @@
 #include <dm/of.h>
 #include <dm/of_access.h>
 #include <log.h>
+#include <phy_interface.h>
 
 /* Enable checks to protect against invalid calls */
 #undef OF_CHECKS
@@ -1231,4 +1232,16 @@ const char *ofnode_conf_read_str(const char *prop_name);
  */
 ofnode ofnode_get_phy_node(ofnode eth_node);
 
+/**
+ * ofnode_read_phy_mode() - Read PHY connection type from a MAC node
+ *
+ * This function parses the "phy-mode" / "phy-connection-type" property and
+ * returns the corresponding PHY interface type.
+ *
+ * @mac_node:  ofnode containing the property
+ * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on
+ *        error
+ */
+phy_interface_t ofnode_read_phy_mode(ofnode mac_node);
+
 #endif
index 899eb813fded63646fa9dd93e6550013aed773b2..bfa26459674bc95a710b684901a45bed10956960 100644 (file)
@@ -757,6 +757,18 @@ int dev_decode_display_timing(const struct udevice *dev, int index,
  */
 ofnode dev_get_phy_node(const struct udevice *dev);
 
+/**
+ * dev_read_phy_mode() - Read PHY connection type from a MAC
+ *
+ * This function parses the "phy-mode" / "phy-connection-type" property and
+ * returns the corresponding PHY interface type.
+ *
+ * @dev: device representing the MAC
+ * Return: one of PHY_INTERFACE_MODE_* constants, PHY_INTERFACE_MODE_NONE on
+ *        error
+ */
+phy_interface_t dev_read_phy_mode(const struct udevice *dev);
+
 #else /* CONFIG_DM_DEV_READ_INLINE is enabled */
 #include <asm/global_data.h>
 
@@ -1111,6 +1123,11 @@ static inline ofnode dev_get_phy_node(const struct udevice *dev)
        return ofnode_get_phy_node(dev_ofnode(dev));
 }
 
+static inline phy_interface_t dev_read_phy_mode(const struct udevice *dev)
+{
+       return ofnode_read_phy_mode(dev_ofnode(dev));
+}
+
 #endif /* CONFIG_DM_DEV_READ_INLINE */
 
 /**
index 9ea4bd42db4de6a71ee6efcbb21ffb629b0368fc..399e050abae3cd1725c32debd95cfd4b8fe69341 100644 (file)
@@ -568,14 +568,6 @@ int phy_xilinx_gmii2rgmii_init(void);
 int board_phy_config(struct phy_device *phydev);
 int get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id);
 
-/**
- * phy_get_interface_by_name() - Look up a PHY interface name
- *
- * @str:       PHY interface name, e.g. "mii"
- * @return: PHY_INTERFACE_MODE_... value, or -1 if not found
- */
-int phy_get_interface_by_name(const char *str);
-
 /**
  * phy_interface_is_rgmii - Convenience function for testing if a PHY interface
  * is RGMII (all variants)
index bef8280e210410837d143fecd2ee8a26d2ca77b1..874f59413a2685290a4a46b0f82e84a7d618b583 100644 (file)
 #include <dm/uclass-internal.h>
 #include <linux/compat.h>
 
-/* DT node properties for MAC-PHY interface */
-static const char * const phy_mode_str[] = {
-       "phy-mode", "phy-connection-type"
-};
-
 void dm_mdio_probe_devices(void)
 {
        struct udevice *it;
@@ -195,26 +190,15 @@ out:
 /* Connect to a PHY linked in eth DT node */
 struct phy_device *dm_eth_phy_connect(struct udevice *ethdev)
 {
-       const char *if_str;
        phy_interface_t interface;
        struct phy_device *phy;
-       int i;
 
        if (!dev_has_ofnode(ethdev)) {
                debug("%s: supplied eth dev has no DT node!\n", ethdev->name);
                return NULL;
        }
 
-       interface = PHY_INTERFACE_MODE_NONE;
-       for (i = 0; i < ARRAY_SIZE(phy_mode_str); i++) {
-               if_str = dev_read_string(ethdev, phy_mode_str[i]);
-               if (if_str) {
-                       interface = phy_get_interface_by_name(if_str);
-                       break;
-               }
-       }
-       if (interface < 0)
-               interface = PHY_INTERFACE_MODE_NONE;
+       interface = dev_read_phy_mode(ethdev);
        if (interface == PHY_INTERFACE_MODE_NONE)
                dev_dbg(ethdev, "can't find interface mode, default to NONE\n");
 
index 500c63aef5a37ba86e3fd63be8850ccb491f0b52..61ae1db62d76528b5c49312aec72b407ce051807 100644 (file)
@@ -451,11 +451,15 @@ DM_TEST(dm_test_ofnode_string_err, UT_TESTF_LIVE_TREE);
 static int dm_test_ofnode_get_phy(struct unit_test_state *uts)
 {
        ofnode eth_node, phy_node;
+       phy_interface_t mode;
        u32 reg;
 
        eth_node = ofnode_path("/phy-test-eth");
        ut_assert(ofnode_valid(eth_node));
 
+       mode = ofnode_read_phy_mode(eth_node);
+       ut_assert(mode == PHY_INTERFACE_MODE_2500BASEX);
+
        phy_node = ofnode_get_phy_node(eth_node);
        ut_assert(ofnode_valid(phy_node));