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 e536943..5b38ee4 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 95d83e7..69f657c 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 445b7ad..f644a59 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 7ff1002..c73508d 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 632ab3c..f24a917 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 eb4cd96..2524747 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 06e0dd7..8f1864a 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 6783956..c6acb49 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 5aaac60..7b7b0f6 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 22dad5b..9777f6c 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 e8ebef0..22c2a3a 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 5e0d0bc..1ffe9e2 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 915c7c8..8f5af1d 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 aa719d2..626c27d 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 aa79d6e..ce8f2df 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 725173f..c775598 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 37eed59..317b380 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 222250d..24fcb93 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 26f0284..d6065db 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 954bf86..32ec0b4 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 4a4268c..d31b96a 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 4c0a7b0..dfddac1 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 c8289d3..ba7b361 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 5a678d1..03eb51e 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 a12c8cd..5a66d72 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 4078d33..f6d386b 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 4055f07..04c9c2d 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 ab51552..0a368c6 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 4901321..693fd3a 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 2e24d12..5654a34 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 87f51b3..c1da334 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 68f4191..5b7bab7 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 5e8f683..b55e7da 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 beca886..fec051e 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 f21addb..02d13c3 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 3118d14..0062851 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 429aee2..3bd3ba4 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 899eb81..bfa2645 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 9ea4bd4..399e050 100644 (file)
@@ -569,14 +569,6 @@ 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)
  * @phydev: the phy_device struct
index bef8280..874f594 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 500c63a..61ae1db 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));