From 107b14e36eaafebdc28666a9d5fecdd4044a59e3 Mon Sep 17 00:00:00 2001 From: Vladimir Oltean Date: Wed, 23 Feb 2022 15:20:55 +0200 Subject: net: phy: dp83867: avoid error in dp83867_of_init() when PHY has no OF node A DM_ETH driver may use phy_connect() towards a PHY address on an MDIO bus which is not specified in the device tree, as evidenced by: pfe_eth_probe -> pfe_phy_configure -> phy_connect When this happens, the PHY will have an invalid OF node. The dp83867_config() method has extra initialization steps which are bypassed when the PHY lacks an OF node, which is undesirable because it will lead to broken networking. Allow the rest of the code to run. Fixes: 085445ca4104 ("net: phy: ti: Allow the driver to be more configurable") Signed-off-by: Vladimir Oltean Reviewed-by: Ramon Fried --- drivers/net/phy/dp83867.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index eada454..49978d0 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -158,7 +158,7 @@ static int dp83867_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; /* Optional configuration */ ret = ofnode_read_u32(node, "ti,clk-output-sel", -- cgit v1.1 From 5faf161d07099d25fcb67f203c5576f258a11fbf Mon Sep 17 00:00:00 2001 From: Vladimir Oltean Date: Wed, 23 Feb 2022 15:20:56 +0200 Subject: net: phy: atheros: avoid error in ar803x_of_init() when PHY has no OF node A DM_ETH driver may use phy_connect() towards a PHY address on an MDIO bus which is not specified in the device tree, as evidenced by: pfe_eth_probe -> pfe_phy_configure -> phy_connect When this happens, the PHY will have an invalid OF node. When ar803x_config() runs, it silently fails at ar803x_of_init(), and therefore, fails to run the rest of the initialization. This makes MII_BMCR contain what it had after BMCR_RESET (0x8000) has been written into it by phy_reset(). Since BMCR_RESET is volatile and self-clearing, the MII_BMCR ends up having a value of 0x0. The further configuration of this register, which is supposed to be handled by genphy_config_aneg() lower in ar803x_config(), never gets a chance to run due to this early error from ar803x_of_init(). As a result of having MII_BMCR as 0, the following symptom appears: => setenv ethact pfe_eth0 => setenv ipaddr 10.0.0.1 => ping 10.0.0.2 pfe_eth0 Waiting for PHY auto negotiation to complete......... TIMEOUT ! Could not initialize PHY pfe_eth0 Manually writing 0x1140 into register 0 of the PHY makes the connection work, but it is rather desirable that the port works without any manual intervention. Fixes: fe6293a80959 ("phy: atheros: add device tree bindings and config") Signed-off-by: Vladimir Oltean Reviewed-by: Ramon Fried --- drivers/net/phy/atheros.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/atheros.c b/drivers/net/phy/atheros.c index f922fec..fa1fe08 100644 --- a/drivers/net/phy/atheros.c +++ b/drivers/net/phy/atheros.c @@ -199,7 +199,7 @@ static int ar803x_of_init(struct phy_device *phydev) node = phy_get_ofnode(phydev); if (!ofnode_valid(node)) - return -EINVAL; + return 0; priv = malloc(sizeof(*priv)); if (!priv) -- cgit v1.1 From e2b6cf5cadc0b71f4addbe0019f7da0c8578c194 Mon Sep 17 00:00:00 2001 From: Haolin Li Date: Sat, 19 Mar 2022 07:02:42 -0700 Subject: net: phy: dp83867: Fix a never true comparison The type of the return value of phy_read() and phy_read_mmd() is int. Change the variable to not be unsigned so that we not get into an unsigned compared against 0. Signed-off-by: Haolin Li Reviewed-by: Ramon Fried --- drivers/net/phy/dp83867.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/dp83867.c b/drivers/net/phy/dp83867.c index 49978d0..3d86263 100644 --- a/drivers/net/phy/dp83867.c +++ b/drivers/net/phy/dp83867.c @@ -266,7 +266,7 @@ static int dp83867_of_init(struct phy_device *phydev) static int dp83867_config(struct phy_device *phydev) { struct dp83867_private *dp83867; - unsigned int val, delay, cfg2; + int val, delay, cfg2; int ret, bs; dp83867 = (struct dp83867_private *)phydev->priv; @@ -291,8 +291,11 @@ static int dp83867_config(struct phy_device *phydev) if (phy_interface_is_rgmii(phydev)) { val = phy_read(phydev, MDIO_DEVAD_NONE, MII_DP83867_PHYCTRL); - if (val < 0) + if (val < 0) { + ret = val; goto err_out; + } + val &= ~DP83867_PHYCR_FIFO_DEPTH_MASK; val |= (dp83867->fifo_depth << DP83867_PHYCR_FIFO_DEPTH_SHIFT); -- cgit v1.1 From 9c06b4815ce1d663085c214133762614bba79fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:00 +0200 Subject: net: phy: fix parsing wrong property MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "phy-interface-type" property should be "phy-connection-type". Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- drivers/net/phy/phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 92fff5b..c8289d3 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -989,7 +989,7 @@ struct phy_device *fixed_phy_create(ofnode node) if_str = ofnode_read_string(node, "phy-mode"); if (!if_str) { - if_str = ofnode_read_string(node, "phy-interface-type"); + if_str = ofnode_read_string(node, "phy-connection-type"); } if (if_str) { interface = phy_get_interface_by_name(if_str); -- cgit v1.1 From 123ca114e07ecf28aa2538748d733e2b22d8b8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:01 +0200 Subject: net: introduce helpers to get PHY interface mode from a device/ofnode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: Ramon Fried Tested-by: Patrice Chotard --- drivers/net/phy/phy.c | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'drivers/net/phy') 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 @@ 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; -} -- cgit v1.1 From 6706d7dcbee15ac41f3ddb50b31ff96d16567883 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:02 +0200 Subject: treewide: Rename PHY_INTERFACE_MODE_COUNT to PHY_INTERFACE_MODE_MAX MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Rename constant PHY_INTERFACE_MODE_COUNT to PHY_INTERFACE_MODE_MAX to make it compatible with Linux' naming. Signed-off-by: Marek Behún Reviewed-by: Stefan Roese Reviewed-by: Vladimir Oltean --- drivers/net/phy/aquantia.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/aquantia.c b/drivers/net/phy/aquantia.c index 83075f7..7e950fe 100644 --- a/drivers/net/phy/aquantia.c +++ b/drivers/net/phy/aquantia.c @@ -305,7 +305,7 @@ struct { u16 syscfg; int cnt; u16 start_rate; -} aquantia_syscfg[PHY_INTERFACE_MODE_COUNT] = { +} aquantia_syscfg[PHY_INTERFACE_MODE_MAX] = { [PHY_INTERFACE_MODE_SGMII] = {0x04b, AQUANTIA_VND1_GSYSCFG_1G, AQUANTIA_VND1_GSTART_RATE_1G}, [PHY_INTERFACE_MODE_2500BASEX] = {0x144, AQUANTIA_VND1_GSYSCFG_2_5G, -- cgit v1.1 From f961b3abf88d2922e064a0b83525929aab917f1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:05 +0200 Subject: net: phy: xilinx: Check interface type in ->config(), not ->probe() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We want to be able to have phydev->interface uninitialized during ->probe(). We should assume that phydev->interface is initialized only before ->config(). Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/phy/xilinx_gmii2rgmii.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index 635c057..d92a364 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -26,6 +26,11 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) debug("%s\n", __func__); + if (phydev->interface != PHY_INTERFACE_MODE_GMII) { + printf("Incorrect interface type\n"); + return -EINVAL; + } + if (!ofnode_valid(node)) return -EINVAL; @@ -114,11 +119,6 @@ static int xilinxgmiitorgmii_probe(struct phy_device *phydev) { debug("%s\n", __func__); - if (phydev->interface != PHY_INTERFACE_MODE_GMII) { - printf("Incorrect interface type\n"); - return -EINVAL; - } - phydev->flags |= PHY_FLAG_BROKEN_RESET; return 0; -- cgit v1.1 From 79bef5fb1f0ce6b090017d2525a42f94e1577673 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:06 +0200 Subject: net: phy: use ->is_c45 instead of is_10g_interface() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use phydev->is_c45 instead of is_10g_interface(phydev->interface) to determine whether clause 45 protocol should be used. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried --- drivers/net/phy/phy.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index ba7b361..7f21c55 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -632,10 +632,10 @@ static int phy_probe(struct phy_device *phydev) return err; } -static struct phy_driver *generic_for_interface(phy_interface_t interface) +static struct phy_driver *generic_for_phy(struct phy_device *phydev) { #ifdef CONFIG_PHYLIB_10G - if (is_10g_interface(interface)) + if (phydev->is_c45) return &gen10g_driver; #endif @@ -656,7 +656,7 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, } /* If we made it here, there's no driver for this PHY */ - return generic_for_interface(interface); + return generic_for_phy(phydev); } struct phy_device *phy_device_create(struct mii_dev *bus, int addr, @@ -859,7 +859,7 @@ int phy_reset(struct phy_device *phydev) #ifdef CONFIG_PHYLIB_10G /* If it's 10G, we need to issue reset through one of the MMDs */ - if (is_10g_interface(phydev->interface)) { + if (phydev->is_c45) { if (!phydev->mmds) gen10g_discover_mmds(phydev); -- cgit v1.1 From e24b58f5ed4f9a0b5b1c80a5f35aa71fcad7f233 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Beh=C3=BAn?= Date: Thu, 7 Apr 2022 00:33:08 +0200 Subject: net: phy: don't require PHY interface mode during PHY creation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we require PHY interface mode to be known when finding/creating the PHY - the functions * phy_connect_phy_id() * phy_device_create() * create_phy_by_mask() * search_for_existing_phy() * get_phy_device_by_mask() * phy_find_by_mask() all require the interface parameter, but the only thing done with it is that it is assigned to phydev->interface. This makes it impossible to find a PHY device without overwriting the set mode. Since the interface mode is not used during .probe() and should be used at first in .config(), drop the interface parameter from these functions. Make the default value of phydev->interface (in phy_device_create()) to be PHY_INTERFACE_MODE_NA. Move the interface parameter to phy_connect_dev(), where it should be. Change all occurrences treewide. In occurrences where we don't call phy_connect_dev() for some reason (they only configure the PHY without connecting it to an ethernet controller), set phydev->interface = value from phy_find_by_mask call. Signed-off-by: Marek Behún Reviewed-by: Ramon Fried Reviewed-by: Vladimir Oltean --- drivers/net/phy/ethernet_id.c | 5 +-- drivers/net/phy/phy.c | 88 ++++++++++++++++--------------------- drivers/net/phy/xilinx_gmii2rgmii.c | 4 +- 3 files changed, 41 insertions(+), 56 deletions(-) (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/ethernet_id.c b/drivers/net/phy/ethernet_id.c index 5617ac3..38a8dca 100644 --- a/drivers/net/phy/ethernet_id.c +++ b/drivers/net/phy/ethernet_id.c @@ -11,8 +11,7 @@ #include #include -struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, - phy_interface_t interface) +struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev) { struct phy_device *phydev; struct ofnode_phandle_args phandle_args; @@ -61,7 +60,7 @@ struct phy_device *phy_connect_phy_id(struct mii_dev *bus, struct udevice *dev, } id = vendor << 16 | device; - phydev = phy_device_create(bus, 0, id, false, interface); + phydev = phy_device_create(bus, 0, id, false); if (phydev) phydev->node = node; diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index 7f21c55..bc83846 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -642,8 +642,7 @@ static struct phy_driver *generic_for_phy(struct phy_device *phydev) return &genphy_driver; } -static struct phy_driver *get_phy_driver(struct phy_device *phydev, - phy_interface_t interface) +static struct phy_driver *get_phy_driver(struct phy_device *phydev) { struct list_head *entry; int phy_id = phydev->phy_id; @@ -660,8 +659,7 @@ static struct phy_driver *get_phy_driver(struct phy_device *phydev, } struct phy_device *phy_device_create(struct mii_dev *bus, int addr, - u32 phy_id, bool is_c45, - phy_interface_t interface) + u32 phy_id, bool is_c45) { struct phy_device *dev; @@ -680,7 +678,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->duplex = -1; dev->link = 0; - dev->interface = interface; + dev->interface = PHY_INTERFACE_MODE_NA; #ifdef CONFIG_DM_ETH dev->node = ofnode_null(); @@ -693,7 +691,7 @@ struct phy_device *phy_device_create(struct mii_dev *bus, int addr, dev->is_c45 = is_c45; dev->bus = bus; - dev->drv = get_phy_driver(dev, interface); + dev->drv = get_phy_driver(dev); if (phy_probe(dev)) { printf("%s, PHY probe failed\n", __func__); @@ -742,8 +740,7 @@ int __weak get_phy_id(struct mii_dev *bus, int addr, int devad, u32 *phy_id) } static struct phy_device *create_phy_by_mask(struct mii_dev *bus, - uint phy_mask, int devad, - phy_interface_t interface) + uint phy_mask, int devad) { u32 phy_id = 0xffffffff; bool is_c45; @@ -764,8 +761,7 @@ static struct phy_device *create_phy_by_mask(struct mii_dev *bus, /* If the PHY ID is mostly f's, we didn't find anything */ if (r == 0 && (phy_id & 0x1fffffff) != 0x1fffffff) { is_c45 = (devad == MDIO_DEVAD_NONE) ? false : true; - return phy_device_create(bus, addr, phy_id, is_c45, - interface); + return phy_device_create(bus, addr, phy_id, is_c45); } next: phy_mask &= ~(1 << addr); @@ -774,25 +770,22 @@ next: } static struct phy_device *search_for_existing_phy(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { /* If we have one, return the existing device, with new interface */ while (phy_mask) { int addr = ffs(phy_mask) - 1; - if (bus->phymap[addr]) { - bus->phymap[addr]->interface = interface; + if (bus->phymap[addr]) return bus->phymap[addr]; - } + phy_mask &= ~(1 << addr); } return NULL; } static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, - uint phy_mask, - phy_interface_t interface) + uint phy_mask) { struct phy_device *phydev; int devad[] = { @@ -808,13 +801,12 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, int i, devad_cnt; devad_cnt = sizeof(devad)/sizeof(int); - phydev = search_for_existing_phy(bus, phy_mask, interface); + phydev = search_for_existing_phy(bus, phy_mask); if (phydev) return phydev; /* try different access clauses */ for (i = 0; i < devad_cnt; i++) { - phydev = create_phy_by_mask(bus, phy_mask, - devad[i], interface); + phydev = create_phy_by_mask(bus, phy_mask, devad[i]); if (IS_ERR(phydev)) return NULL; if (phydev) @@ -842,10 +834,9 @@ static struct phy_device *get_phy_device_by_mask(struct mii_dev *bus, * Description: Reads the ID registers of the PHY at @addr on the * @bus, then allocates and returns the phy_device to represent it. */ -static struct phy_device *get_phy_device(struct mii_dev *bus, int addr, - phy_interface_t interface) +static struct phy_device *get_phy_device(struct mii_dev *bus, int addr) { - return get_phy_device_by_mask(bus, 1 << addr, interface); + return get_phy_device_by_mask(bus, 1 << addr); } int phy_reset(struct phy_device *phydev) @@ -904,18 +895,12 @@ int miiphy_reset(const char *devname, unsigned char addr) struct mii_dev *bus = miiphy_get_dev_by_name(devname); struct phy_device *phydev; - /* - * miiphy_reset was only used on standard PHYs, so we'll fake it here. - * If later code tries to connect with the right interface, this will - * be corrected by get_phy_device in phy_connect() - */ - phydev = get_phy_device(bus, addr, PHY_INTERFACE_MODE_MII); + phydev = get_phy_device(bus, addr); return phy_reset(phydev); } -struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, - phy_interface_t interface) +struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask) { /* Reset the bus */ if (bus->reset) { @@ -925,13 +910,15 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, uint phy_mask, mdelay(15); } - return get_phy_device_by_mask(bus, phy_mask, interface); + return get_phy_device_by_mask(bus, phy_mask); } #ifdef CONFIG_DM_ETH -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev) +void phy_connect_dev(struct phy_device *phydev, struct udevice *dev, + phy_interface_t interface) #else -void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) +void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev, + phy_interface_t interface) #endif { /* Soft Reset the PHY */ @@ -942,13 +929,14 @@ void phy_connect_dev(struct phy_device *phydev, struct eth_device *dev) phydev->dev->name, dev->name); } phydev->dev = dev; - debug("%s connected to %s\n", dev->name, phydev->drv->name); + phydev->interface = interface; + debug("%s connected to %s mode %s\n", dev->name, phydev->drv->name, + phy_string_for_interface(interface)); } #ifdef CONFIG_PHY_XILINX_GMII2RGMII static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { struct phy_device *phydev = NULL; ofnode node; @@ -957,8 +945,7 @@ static struct phy_device *phy_connect_gmii2rgmii(struct mii_dev *bus, node = ofnode_by_compatible(node, "xlnx,gmii-to-rgmii-1.0"); if (ofnode_valid(node)) { phydev = phy_device_create(bus, 0, - PHY_GMII2RGMII_ID, false, - interface); + PHY_GMII2RGMII_ID, false); if (phydev) phydev->node = node; break; @@ -990,24 +977,23 @@ struct phy_device *fixed_phy_create(ofnode node) return NULL; } - phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false, - ofnode_read_phy_mode(node)); + phydev = phy_device_create(NULL, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; + phydev->interface = ofnode_read_phy_mode(node); + return phydev; } static struct phy_device *phy_connect_fixed(struct mii_dev *bus, - struct udevice *dev, - phy_interface_t interface) + struct udevice *dev) { ofnode node = dev_ofnode(dev), subnode; struct phy_device *phydev = NULL; if (ofnode_phy_is_fixed_link(node, &subnode)) { - phydev = phy_device_create(bus, 0, PHY_FIXED_ID, - false, interface); + phydev = phy_device_create(bus, 0, PHY_FIXED_ID, false); if (phydev) phydev->node = subnode; } @@ -1030,29 +1016,29 @@ struct phy_device *phy_connect(struct mii_dev *bus, int addr, uint mask = (addr >= 0) ? (1 << addr) : 0xffffffff; #ifdef CONFIG_PHY_FIXED - phydev = phy_connect_fixed(bus, dev, interface); + phydev = phy_connect_fixed(bus, dev); #endif #ifdef CONFIG_PHY_NCSI if (!phydev) - phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false, interface); + phydev = phy_device_create(bus, 0, PHY_NCSI_ID, false); #endif #ifdef CONFIG_PHY_ETHERNET_ID if (!phydev) - phydev = phy_connect_phy_id(bus, dev, interface); + phydev = phy_connect_phy_id(bus, dev); #endif #ifdef CONFIG_PHY_XILINX_GMII2RGMII if (!phydev) - phydev = phy_connect_gmii2rgmii(bus, dev, interface); + phydev = phy_connect_gmii2rgmii(bus, dev); #endif if (!phydev) - phydev = phy_find_by_mask(bus, mask, interface); + phydev = phy_find_by_mask(bus, mask); if (phydev) - phy_connect_dev(phydev, dev); + phy_connect_dev(phydev, dev, interface); else printf("Could not get PHY for %s: addr %d\n", bus->name, addr); return phydev; diff --git a/drivers/net/phy/xilinx_gmii2rgmii.c b/drivers/net/phy/xilinx_gmii2rgmii.c index d92a364..7376283 100644 --- a/drivers/net/phy/xilinx_gmii2rgmii.c +++ b/drivers/net/phy/xilinx_gmii2rgmii.c @@ -42,13 +42,13 @@ static int xilinxgmiitorgmii_config(struct phy_device *phydev) ext_phyaddr = ofnode_read_u32_default(phandle.node, "reg", -1); ext_phydev = phy_find_by_mask(phydev->bus, - 1 << ext_phyaddr, - PHY_INTERFACE_MODE_RGMII); + 1 << ext_phyaddr); if (!ext_phydev) { printf("%s, No external phy device found\n", __func__); return -EINVAL; } + ext_phydev->interface = PHY_INTERFACE_MODE_RGMII; ext_phydev->node = phandle.node; phydev->priv = ext_phydev; -- cgit v1.1 From d79f1a85697e3af24a97728f6e4f16635bdc8290 Mon Sep 17 00:00:00 2001 From: Nate Drude Date: Fri, 8 Apr 2022 11:28:14 -0500 Subject: phy: adin: add driver for Analog Devices ADIN1300 PHY The current implementation configures RGMII using device tree phy-mode property and then calls genphy_config adin_config_rgmii_mode is derived from: https://github.com/varigit/linux-imx/blob/lf-5.10.y_var04/drivers/net/phy/adin.c#L218-L262 Signed-off-by: Nate Drude Reviewed-by: Ramon Fried --- drivers/net/phy/Kconfig | 5 ++ drivers/net/phy/Makefile | 1 + drivers/net/phy/adin.c | 228 +++++++++++++++++++++++++++++++++++++++++++++++ drivers/net/phy/phy.c | 3 + 4 files changed, 237 insertions(+) create mode 100644 drivers/net/phy/adin.c (limited to 'drivers/net/phy') diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig index 014a4de..2f90ab0 100644 --- a/drivers/net/phy/Kconfig +++ b/drivers/net/phy/Kconfig @@ -68,6 +68,11 @@ endif # MV88E61XX_SWITCH config PHYLIB_10G bool "Generic 10G PHY support" +config PHY_ADIN + bool "Analog Devices Industrial Ethernet PHYs" + help + Add support for configuring RGMII on Analog Devices ADIN PHYs. + menuconfig PHY_AQUANTIA bool "Aquantia Ethernet PHYs support" select PHY_GIGE diff --git a/drivers/net/phy/Makefile b/drivers/net/phy/Makefile index b28440b..a4dd105 100644 --- a/drivers/net/phy/Makefile +++ b/drivers/net/phy/Makefile @@ -10,6 +10,7 @@ obj-$(CONFIG_MV88E6352_SWITCH) += mv88e6352.o obj-$(CONFIG_PHYLIB) += phy.o obj-$(CONFIG_PHYLIB_10G) += generic_10g.o +obj-$(CONFIG_PHY_ADIN) += adin.o obj-$(CONFIG_PHY_AQUANTIA) += aquantia.o obj-$(CONFIG_PHY_ATHEROS) += atheros.o obj-$(CONFIG_PHY_BROADCOM) += broadcom.o diff --git a/drivers/net/phy/adin.c b/drivers/net/phy/adin.c new file mode 100644 index 0000000..cff841a --- /dev/null +++ b/drivers/net/phy/adin.c @@ -0,0 +1,228 @@ +// SPDX-License-Identifier: GPL-2.0+ +/** + * Driver for Analog Devices Industrial Ethernet PHYs + * + * Copyright 2019 Analog Devices Inc. + * Copyright 2022 Variscite Ltd. + */ +#include +#include +#include +#include + +#define PHY_ID_ADIN1300 0x0283bc30 +#define ADIN1300_EXT_REG_PTR 0x10 +#define ADIN1300_EXT_REG_DATA 0x11 +#define ADIN1300_GE_RGMII_CFG 0xff23 +#define ADIN1300_GE_RGMII_RX_MSK GENMASK(8, 6) +#define ADIN1300_GE_RGMII_RX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_RX_MSK, x) +#define ADIN1300_GE_RGMII_GTX_MSK GENMASK(5, 3) +#define ADIN1300_GE_RGMII_GTX_SEL(x) \ + FIELD_PREP(ADIN1300_GE_RGMII_GTX_MSK, x) +#define ADIN1300_GE_RGMII_RXID_EN BIT(2) +#define ADIN1300_GE_RGMII_TXID_EN BIT(1) +#define ADIN1300_GE_RGMII_EN BIT(0) + +/* RGMII internal delay settings for rx and tx for ADIN1300 */ +#define ADIN1300_RGMII_1_60_NS 0x0001 +#define ADIN1300_RGMII_1_80_NS 0x0002 +#define ADIN1300_RGMII_2_00_NS 0x0000 +#define ADIN1300_RGMII_2_20_NS 0x0006 +#define ADIN1300_RGMII_2_40_NS 0x0007 + +/** + * struct adin_cfg_reg_map - map a config value to aregister value + * @cfg value in device configuration + * @reg value in the register + */ +struct adin_cfg_reg_map { + int cfg; + int reg; +}; + +static const struct adin_cfg_reg_map adin_rgmii_delays[] = { + { 1600, ADIN1300_RGMII_1_60_NS }, + { 1800, ADIN1300_RGMII_1_80_NS }, + { 2000, ADIN1300_RGMII_2_00_NS }, + { 2200, ADIN1300_RGMII_2_20_NS }, + { 2400, ADIN1300_RGMII_2_40_NS }, + { }, +}; + +static int adin_lookup_reg_value(const struct adin_cfg_reg_map *tbl, int cfg) +{ + size_t i; + + for (i = 0; tbl[i].cfg; i++) { + if (tbl[i].cfg == cfg) + return tbl[i].reg; + } + + return -EINVAL; +} + +static u32 adin_get_reg_value(struct phy_device *phydev, + const char *prop_name, + const struct adin_cfg_reg_map *tbl, + u32 dflt) +{ + u32 val; + int rc; + + ofnode node = phy_get_ofnode(phydev); + if (!ofnode_valid(node)) { + printf("%s: failed to get node\n", __func__); + return -EINVAL; + } + + if (ofnode_read_u32(node, prop_name, &val)) { + printf("%s: failed to find %s, using default %d\n", + __func__, prop_name, dflt); + return dflt; + } + + debug("%s: %s = '%d'\n", __func__, prop_name, val); + + rc = adin_lookup_reg_value(tbl, val); + if (rc < 0) { + printf("%s: Unsupported value %u for %s using default (%u)\n", + __func__, val, prop_name, dflt); + return dflt; + } + + return rc; +} + +/** + * adin_get_phy_mode_override - Get phy-mode override for adin PHY + * + * The function gets phy-mode string from property 'adi,phy-mode-override' + * and return its index in phy_interface_strings table, or -1 in error case. + */ +int adin_get_phy_mode_override(struct phy_device *phydev) +{ + ofnode node = phy_get_ofnode(phydev); + const char *phy_mode_override; + const char *prop_phy_mode_override = "adi,phy-mode-override"; + int override_interface; + + phy_mode_override = ofnode_read_string(node, prop_phy_mode_override); + if (!phy_mode_override) + return -ENODEV; + + debug("%s: %s = '%s'\n", + __func__, prop_phy_mode_override, phy_mode_override); + + override_interface = phy_get_interface_by_name(phy_mode_override); + + if (override_interface < 0) + printf("%s: %s = '%s' is not valid\n", + __func__, prop_phy_mode_override, phy_mode_override); + + return override_interface; +} + +static u16 adin_ext_read(struct phy_device *phydev, const u32 regnum) +{ + u16 val; + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + val = phy_read(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA); + + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + return val; +} + +static int adin_ext_write(struct phy_device *phydev, const u32 regnum, const u16 val) +{ + debug("%s: adin@0x%x 0x%x=0x%x\n", __func__, phydev->addr, regnum, val); + + phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_PTR, regnum); + + return phy_write(phydev, MDIO_DEVAD_NONE, ADIN1300_EXT_REG_DATA, val); +} + +static int adin_config_rgmii_mode(struct phy_device *phydev) +{ + u16 reg_val; + u32 val; + int phy_mode_override = adin_get_phy_mode_override(phydev); + + if (phy_mode_override >= 0) { + phydev->interface = (phy_interface_t) phy_mode_override; + } + + reg_val = adin_ext_read(phydev, ADIN1300_GE_RGMII_CFG); + + if (!phy_interface_is_rgmii(phydev)) { + /* Disable RGMII */ + reg_val &= ~ADIN1300_GE_RGMII_EN; + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); + } + + /* Enable RGMII */ + reg_val |= ADIN1300_GE_RGMII_EN; + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_RXID) { + reg_val |= ADIN1300_GE_RGMII_RXID_EN; + + val = adin_get_reg_value(phydev, "adi,rx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_RX_MSK; + reg_val |= ADIN1300_GE_RGMII_RX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_RXID_EN; + } + + /* Enable / Disable RGMII RX Delay */ + if (phydev->interface == PHY_INTERFACE_MODE_RGMII_ID || + phydev->interface == PHY_INTERFACE_MODE_RGMII_TXID) { + reg_val |= ADIN1300_GE_RGMII_TXID_EN; + + val = adin_get_reg_value(phydev, "adi,tx-internal-delay-ps", + adin_rgmii_delays, + ADIN1300_RGMII_2_00_NS); + reg_val &= ~ADIN1300_GE_RGMII_GTX_MSK; + reg_val |= ADIN1300_GE_RGMII_GTX_SEL(val); + } else { + reg_val &= ~ADIN1300_GE_RGMII_TXID_EN; + } + + return adin_ext_write(phydev, ADIN1300_GE_RGMII_CFG, reg_val); +} + +static int adin1300_config(struct phy_device *phydev) +{ + int ret; + + printf("ADIN1300 PHY detected at addr %d\n", phydev->addr); + + ret = adin_config_rgmii_mode(phydev); + + if (ret < 0) + return ret; + + return genphy_config(phydev); +} + +static struct phy_driver ADIN1300_driver = { + .name = "ADIN1300", + .uid = PHY_ID_ADIN1300, + .mask = 0xffffffff, + .features = PHY_GBIT_FEATURES, + .config = adin1300_config, + .startup = genphy_startup, + .shutdown = genphy_shutdown, +}; + +int phy_adin_init(void) +{ + phy_register(&ADIN1300_driver); + + return 0; +} diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index bc83846..e0b37a9 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -490,6 +490,9 @@ int phy_init(void) #ifdef CONFIG_MV88E61XX_SWITCH phy_mv88e61xx_init(); #endif +#ifdef CONFIG_PHY_ADIN + phy_adin_init(); +#endif #ifdef CONFIG_PHY_AQUANTIA phy_aquantia_init(); #endif -- cgit v1.1