From c7b04769a76032102ba65c8ece6caacd50079365 Mon Sep 17 00:00:00 2001 From: Lech Perczak Date: Sat, 28 May 2022 22:35:26 +0200 Subject: [PATCH] ath79: ag71xx: use "builtin-switch" property to set link configuration To support reporting link state of PHYs attached to built-in switch, add a device tree knob which allows to force 1000Mbps/FD mode, which is the link mode between eth1 MAC and the on-chip switch, even if no "fixed-link" node is present. Re-use the "builtin-switch" name already used in respective MDIO nodes. This way, a phy-handle property can be added to eth1 node, and devices, which have a single port attached through the built-in switch, can report proper link state of that to userspace. To perform that, one needs to delete the 'fixed-link' node and map the correct swphy node to 'phy-handle' property. One of those is still required to be present in the eth1 node. Signed-off-by: Lech Perczak Link: https://github.com/openwrt/openwrt/pull/9971 Signed-off-by: Hauke Mehrtens --- .../drivers/net/ethernet/atheros/ag71xx/ag71xx.h | 1 + .../net/ethernet/atheros/ag71xx/ag71xx_main.c | 12 ++++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h index da716d94c3..c90dc2d4cd 100644 --- a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h +++ b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx.h @@ -160,6 +160,7 @@ struct ag71xx { u16 rx_buf_size; u8 rx_buf_offset; u8 tx_hang_workaround:1; + u8 builtin_switch:1; struct net_device *dev; struct platform_device *pdev; diff --git a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c index 8e387af27b..745a8d9ff4 100644 --- a/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c +++ b/target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c @@ -868,6 +868,7 @@ __ag71xx_link_adjust(struct ag71xx *ag, bool update) u32 cfg2; u32 ifctl; u32 fifo5; + unsigned int speed; if (!ag->link && update) { ag71xx_hw_stop(ag); @@ -883,7 +884,7 @@ __ag71xx_link_adjust(struct ag71xx *ag, bool update) cfg2 = ag71xx_rr(ag, AG71XX_REG_MAC_CFG2); cfg2 &= ~(MAC_CFG2_IF_1000 | MAC_CFG2_IF_10_100 | MAC_CFG2_FDX); - cfg2 |= (ag->duplex) ? MAC_CFG2_FDX : 0; + cfg2 |= (ag->duplex || ag->builtin_switch) ? MAC_CFG2_FDX : 0; ifctl = ag71xx_rr(ag, AG71XX_REG_MAC_IFCTL); ifctl &= ~(MAC_IFCTL_SPEED); @@ -891,7 +892,11 @@ __ag71xx_link_adjust(struct ag71xx *ag, bool update) fifo5 = ag71xx_rr(ag, AG71XX_REG_FIFO_CFG5); fifo5 &= ~FIFO_CFG5_BM; - switch (ag->speed) { + speed = ag->speed; + if (ag->builtin_switch) + speed = SPEED_1000; + + switch (speed) { case SPEED_1000: cfg2 |= MAC_CFG2_IF_1000; fifo5 |= FIFO_CFG5_BM; @@ -1568,6 +1573,9 @@ static int ag71xx_probe(struct platform_device *pdev) ag->pllregmap = NULL; } + if (of_property_read_bool(np, "builtin-switch")) + ag->builtin_switch = 1; + ag->mac_base = devm_ioremap(&pdev->dev, res->start, res->end - res->start + 1); if (!ag->mac_base)