aboutsummaryrefslogtreecommitdiff
path: root/drivers/net/ti
diff options
context:
space:
mode:
authorMarek BehĂșn <marek.behun@nic.cz>2022-04-07 00:33:01 +0200
committerRamon Fried <ramon@neureality.ai>2022-04-10 08:44:12 +0300
commit123ca114e07ecf28aa2538748d733e2b22d8b8b5 (patch)
tree0a5481e51e4e50b33daf4d10f37574f6f797b04f /drivers/net/ti
parent9c06b4815ce1d663085c214133762614bba79fbe (diff)
downloadu-boot-123ca114e07ecf28aa2538748d733e2b22d8b8b5.zip
u-boot-123ca114e07ecf28aa2538748d733e2b22d8b8b5.tar.gz
u-boot-123ca114e07ecf28aa2538748d733e2b22d8b8b5.tar.bz2
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>
Diffstat (limited to 'drivers/net/ti')
-rw-r--r--drivers/net/ti/am65-cpsw-nuss.c15
-rw-r--r--drivers/net/ti/cpsw.c10
-rw-r--r--drivers/net/ti/keystone_net.c24
3 files changed, 17 insertions, 32 deletions
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 @@ 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);
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 @@ 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;
}
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 @@ 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;
}