net: introduce helpers to get PHY interface mode from a device/ofnode
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>
diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index e536943..5b38ee4 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -535,6 +535,7 @@
reg = <0x10007000 0x1000>;
fake-host-hwaddr = [00 00 66 44 22 77];
phy-handle = <ðphy1>;
+ phy-mode = "2500base-x";
};
dsa_eth0: dsa-test-eth {
diff --git a/board/st/stm32f746-disco/stm32f746-disco.c b/board/st/stm32f746-disco/stm32f746-disco.c
index 95d83e7..69f657c 100644
--- a/board/st/stm32f746-disco/stm32f746-disco.c
+++ b/board/st/stm32f746-disco/stm32f746-disco.c
@@ -117,16 +117,13 @@
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 @@
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
diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
index 445b7ad..f644a59 100644
--- a/drivers/core/ofnode.c
+++ b/drivers/core/ofnode.c
@@ -1219,3 +1219,26 @@
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;
+}
diff --git a/drivers/core/read.c b/drivers/core/read.c
index 7ff1002..c73508d 100644
--- a/drivers/core/read.c
+++ b/drivers/core/read.c
@@ -403,3 +403,8 @@
{
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));
+}
diff --git a/drivers/net/ag7xxx.c b/drivers/net/ag7xxx.c
index 632ab3c..f24a917 100644
--- a/drivers/net/ag7xxx.c
+++ b/drivers/net/ag7xxx.c
@@ -1254,7 +1254,6 @@
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 @@
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;
}
diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c
index eb4cd96..2524747 100644
--- a/drivers/net/altera_tse.c
+++ b/drivers/net/altera_tse.c
@@ -676,17 +676,10 @@
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;
}
diff --git a/drivers/net/bcm6348-eth.c b/drivers/net/bcm6348-eth.c
index 06e0dd7..8f1864a 100644
--- a/drivers/net/bcm6348-eth.c
+++ b/drivers/net/bcm6348-eth.c
@@ -415,7 +415,6 @@
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 @@
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;
diff --git a/drivers/net/bcmgenet.c b/drivers/net/bcmgenet.c
index 6783956..c6acb49 100644
--- a/drivers/net/bcmgenet.c
+++ b/drivers/net/bcmgenet.c
@@ -690,20 +690,14 @@
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);
diff --git a/drivers/net/designware.c b/drivers/net/designware.c
index 5aaac60..7b7b0f6 100644
--- a/drivers/net/designware.c
+++ b/drivers/net/designware.c
@@ -914,21 +914,15 @@
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);
diff --git a/drivers/net/dwc_eth_qos.c b/drivers/net/dwc_eth_qos.c
index 22dad5b..9777f6c 100644
--- a/drivers/net/dwc_eth_qos.c
+++ b/drivers/net/dwc_eth_qos.c
@@ -270,7 +270,7 @@
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 @@
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 @@
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 @@
.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 @@
.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
};
diff --git a/drivers/net/fec_mxc.c b/drivers/net/fec_mxc.c
index e8ebef0..22c2a3a 100644
--- a/drivers/net/fec_mxc.c
+++ b/drivers/net/fec_mxc.c
@@ -1310,20 +1310,13 @@
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);
diff --git a/drivers/net/fm/eth.c b/drivers/net/fm/eth.c
index 5e0d0bc..1ffe9e2 100644
--- a/drivers/net/fm/eth.c
+++ b/drivers/net/fm/eth.c
@@ -954,17 +954,6 @@
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 @@
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__);
diff --git a/drivers/net/fsl_enetc.c b/drivers/net/fsl_enetc.c
index 915c7c8..8f5af1d 100644
--- a/drivers/net/fsl_enetc.c
+++ b/drivers/net/fsl_enetc.c
@@ -260,9 +260,6 @@
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 @@
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:
diff --git a/drivers/net/ftgmac100.c b/drivers/net/ftgmac100.c
index aa719d2..626c27d 100644
--- a/drivers/net/ftgmac100.c
+++ b/drivers/net/ftgmac100.c
@@ -549,17 +549,12 @@
{
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);
diff --git a/drivers/net/higmacv300.c b/drivers/net/higmacv300.c
index aa79d6e..ce8f2df 100644
--- a/drivers/net/higmacv300.c
+++ b/drivers/net/higmacv300.c
@@ -561,19 +561,14 @@
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)) {
diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c b/drivers/net/ldpaa_eth/ldpaa_eth.c
index 725173f..c775598 100644
--- a/drivers/net/ldpaa_eth/ldpaa_eth.c
+++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
@@ -1120,31 +1120,14 @@
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 @@
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_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;
}
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 37eed59..317b380 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -1360,17 +1360,11 @@
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,
diff --git a/drivers/net/mt7620-eth.c b/drivers/net/mt7620-eth.c
index 222250d..24fcb93 100644
--- a/drivers/net/mt7620-eth.c
+++ b/drivers/net/mt7620-eth.c
@@ -1048,33 +1048,20 @@
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;
- }
+ priv->port_cfg[idx].mode = ofnode_read_phy_mode(node);
- 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 = 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");
diff --git a/drivers/net/mtk_eth.c b/drivers/net/mtk_eth.c
index 26f0284..d6065db 100644
--- a/drivers/net/mtk_eth.c
+++ b/drivers/net/mtk_eth.c
@@ -1447,11 +1447,9 @@
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;
}
diff --git a/drivers/net/mvgbe.c b/drivers/net/mvgbe.c
index 954bf86..32ec0b4 100644
--- a/drivers/net/mvgbe.c
+++ b/drivers/net/mvgbe.c
@@ -993,7 +993,6 @@
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 @@
"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;
diff --git a/drivers/net/mvneta.c b/drivers/net/mvneta.c
index 4a4268c..d31b96a 100644
--- a/drivers/net/mvneta.c
+++ b/drivers/net/mvneta.c
@@ -1799,20 +1799,13 @@
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;
}
diff --git a/drivers/net/mvpp2.c b/drivers/net/mvpp2.c
index 4c0a7b0..dfddac1 100644
--- a/drivers/net/mvpp2.c
+++ b/drivers/net/mvpp2.c
@@ -4786,11 +4786,9 @@
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 @@
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 @@
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;
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index c8289d3..ba7b361 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -982,25 +982,16 @@
*/
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 @@
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;
-}
diff --git a/drivers/net/pic32_eth.c b/drivers/net/pic32_eth.c
index 5a678d1..03eb51e 100644
--- a/drivers/net/pic32_eth.c
+++ b/drivers/net/pic32_eth.c
@@ -534,7 +534,6 @@
{
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 @@
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),
diff --git a/drivers/net/qe/dm_qe_uec.c b/drivers/net/qe/dm_qe_uec.c
index a12c8cd..5a66d72 100644
--- a/drivers/net/qe/dm_qe_uec.c
+++ b/drivers/net/qe/dm_qe_uec.c
@@ -1133,19 +1133,12 @@
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;
}
diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
index 4078d33..f6d386b 100644
--- a/drivers/net/ravb.c
+++ b/drivers/net/ravb.c
@@ -674,20 +674,13 @@
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 @@
sprintf(bb_miiphy_buses[0].name, dev->name);
- return ret;
+ return 0;
}
static const struct udevice_id ravb_ids[] = {
diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
index 4055f07..04c9c2d 100644
--- a/drivers/net/sh_eth.c
+++ b/drivers/net/sh_eth.c
@@ -915,20 +915,13 @@
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 @@
sprintf(bb_miiphy_buses[0].name, dev->name);
- return ret;
+ return 0;
}
static const struct udevice_id sh_ether_ids[] = {
diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c
index ab51552..0a368c6 100644
--- a/drivers/net/sni_ave.c
+++ b/drivers/net/sni_ave.c
@@ -738,7 +738,6 @@
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 @@
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",
diff --git a/drivers/net/sni_netsec.c b/drivers/net/sni_netsec.c
index 4901321..693fd3a 100644
--- a/drivers/net/sni_netsec.c
+++ b/drivers/net/sni_netsec.c
@@ -1029,19 +1029,13 @@
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))
diff --git a/drivers/net/sun8i_emac.c b/drivers/net/sun8i_emac.c
index 2e24d12..5654a34 100644
--- a/drivers/net/sun8i_emac.c
+++ b/drivers/net/sun8i_emac.c
@@ -882,7 +882,6 @@
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 @@
}
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);
diff --git a/drivers/net/ti/am65-cpsw-nuss.c b/drivers/net/ti/am65-cpsw-nuss.c
index 87f51b3..c1da334 100644
--- a/drivers/net/ti/am65-cpsw-nuss.c
+++ b/drivers/net/ti/am65-cpsw-nuss.c
@@ -602,21 +602,14 @@
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);
diff --git a/drivers/net/ti/cpsw.c b/drivers/net/ti/cpsw.c
index 68f4191..5b7bab7 100644
--- a/drivers/net/ti/cpsw.c
+++ b/drivers/net/ti/cpsw.c
@@ -1194,15 +1194,12 @@
{
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 @@
}
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;
}
diff --git a/drivers/net/ti/keystone_net.c b/drivers/net/ti/keystone_net.c
index 5e8f683..b55e7da 100644
--- a/drivers/net/ti/keystone_net.c
+++ b/drivers/net/ti/keystone_net.c
@@ -687,7 +687,6 @@
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 @@
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;
}
diff --git a/drivers/net/tsec.c b/drivers/net/tsec.c
index beca886..fec051e 100644
--- a/drivers/net/tsec.c
+++ b/drivers/net/tsec.c
@@ -834,7 +834,6 @@
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 @@
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;
diff --git a/drivers/net/xilinx_axi_emac.c b/drivers/net/xilinx_axi_emac.c
index f21addb..02d13c3 100644
--- a/drivers/net/xilinx_axi_emac.c
+++ b/drivers/net/xilinx_axi_emac.c
@@ -821,7 +821,6 @@
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 @@
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");
diff --git a/drivers/net/zynq_gem.c b/drivers/net/zynq_gem.c
index 3118d14..0062851 100644
--- a/drivers/net/zynq_gem.c
+++ b/drivers/net/zynq_gem.c
@@ -827,7 +827,6 @@
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 @@
}
}
- 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");
diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
index 429aee2..3bd3ba4 100644
--- a/include/dm/ofnode.h
+++ b/include/dm/ofnode.h
@@ -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 @@
*/
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
diff --git a/include/dm/read.h b/include/dm/read.h
index 899eb81..bfa2645 100644
--- a/include/dm/read.h
+++ b/include/dm/read.h
@@ -757,6 +757,18 @@
*/
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 @@
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 */
/**
diff --git a/include/phy.h b/include/phy.h
index 9ea4bd4..399e050 100644
--- a/include/phy.h
+++ b/include/phy.h
@@ -569,14 +569,6 @@
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
diff --git a/net/mdio-uclass.c b/net/mdio-uclass.c
index bef8280..874f594 100644
--- a/net/mdio-uclass.c
+++ b/net/mdio-uclass.c
@@ -15,11 +15,6 @@
#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 @@
/* 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");
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index 500c63a..61ae1db 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -451,11 +451,15 @@
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));