net: mediatek: mt7988: various fixup + MDIO detach
Subsystems (2)
cover net: mediatek: mt7988: various fixup + MDIO detach
This series is really required for Airoha AN7581 to provide support for the MMIO MDIO bus. But to accomplish this, rework is needed to the current MT7531 driver to prevent additional code duplication.
While at it also multiple BUG were notice on the MT7988 driver.
The additional MDIO MMIO driver expose an internal variant to access the function directly from a manually crafted mii_bus but also provide DM support used by AN7581.
Christian Marangi (5):
net: mediatek: mt7988: fix broken phy_setting config
net: mediatek: mt7988: restore PHY page on PHY setting exit
net: mediatek: mt7988: free allocated MDIO bus on cleanup
net: mediatek: move MT7531 MMIO MDIO to dedicated driver
net: airoha: bind MDIO controller on Ethernet load
drivers/net/Kconfig | 4 + drivers/net/Makefile | 1 + drivers/net/airoha_eth.c | 26 +++++ drivers/net/mdio-mt7531-mmio.c | 168 +++++++++++++++++++++++++++++++++ drivers/net/mdio-mt7531-mmio.h | 9 ++ drivers/net/mtk_eth/Kconfig | 1 + drivers/net/mtk_eth/mt7988.c | 92 +++++++++++++++--- 7 files changed, 287 insertions(+), 14 deletions(-) create mode 100644 drivers/net/mdio-mt7531-mmio.c create mode 100644 drivers/net/mdio-mt7531-mmio.h
Signature · 1 line
2.51.0
PATCH 1/5 net: mediatek: mt7988: fix broken phy_setting config
The PHY setting for MT7988 are actually never configured for the affected PHY as we are read/writing to the wrong PHY address.
This is caused by the fact that we use the index of the NUM_PHYS loop as the PHY address without first offsetting it to the base address.
Correctly offset the PHY address before configuring the PHY setting.
--- drivers/net/mtk_eth/mt7988.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/net/mtk_eth/mt7988.c +7 -5
@@ -34,16 +34,18 @@ static void mt7988_phy_setting(struct mt753x_switch_priv *priv)u32 i;for (i =0 ; i <MT753X_NUM_PHYS ; i++) { +u16 addr =MT753X_PHY_ADDR (priv->phy_base, i); +/* Enable HW auto downshift */ -mt7531_mii_write (priv, i,0x1f ,0x1 ); - val =mt7531_mii_read (priv, i,PHY_EXT_REG_14 ); +mt7531_mii_write (priv, addr,0x1f ,0x1 ); + val =mt7531_mii_read (priv, addr,PHY_EXT_REG_14 ); val |=PHY_EN_DOWN_SHFIT ; -mt7531_mii_write (priv, i,PHY_EXT_REG_14 , val); +mt7531_mii_write (priv, addr,PHY_EXT_REG_14 , val);/* PHY link down power saving enable */ - val =mt7531_mii_read (priv, i,PHY_EXT_REG_17 ); + val =mt7531_mii_read (priv, addr,PHY_EXT_REG_17 ); val |=PHY_LINKDOWN_POWER_SAVING_EN ; -mt7531_mii_write (priv, i,PHY_EXT_REG_17 , val); +mt7531_mii_write (priv, addr,PHY_EXT_REG_17 , val); } }
Signature · 1 line
2.51.0
PATCH 2/5 net: mediatek: mt7988: restore PHY page on PHY setting exit
In reply to Christian MarangiOn exiting the phy_setting function for MT7988, the PHY page is never restored to Page 0. This can cause all kind of problem with reading the status of the PHY at runtime.
Correctly restore PHY page on exiting the PHY setting function.
--- drivers/net/mtk_eth/mt7988.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/net/mtk_eth/mt7988.c +6 -1
@@ -36,8 +36,10 @@ static void mt7988_phy_setting(struct mt753x_switch_priv *priv)for (i =0 ; i <MT753X_NUM_PHYS ; i++) {u16 addr =MT753X_PHY_ADDR (priv->phy_base, i); -/* Enable HW auto downshift */ +/* Set PHY to PHY page 1 */ mt7531_mii_write (priv, addr,0x1f ,0x1 ); + +/* Enable HW auto downshift */ val =mt7531_mii_read (priv, addr,PHY_EXT_REG_14 ); val |=PHY_EN_DOWN_SHFIT ;mt7531_mii_write (priv, addr,PHY_EXT_REG_14 , val);
@@ -46,6 +48,9 @@ static void mt7988_phy_setting(struct mt753x_switch_priv *priv) val =mt7531_mii_read (priv, addr,PHY_EXT_REG_17 ); val |=PHY_LINKDOWN_POWER_SAVING_EN ;mt7531_mii_write (priv, addr,PHY_EXT_REG_17 , val); + +/* Restore PHY to PHY page 0 */ +mt7531_mii_write (priv, addr,0x1f ,0x0 ); } }
Signature · 1 line
2.51.0
PATCH 3/5 net: mediatek: mt7988: free allocated MDIO bus on cleanup
In reply to Christian MarangiCorrectly free the MDIO Bus on calling cleanup function. While at it also fix a copy-paste error and rename the cleanup function name to the more specific name.
--- drivers/net/mtk_eth/mt7988.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/net/mtk_eth/mt7988.c +5 -3
@@ -146,11 +146,13 @@ static int mt7988_setup(struct mtk_eth_switch_priv *swpriv)return mt7531_mdio_register (priv); } -static int mt7531_cleanup (struct mtk_eth_switch_priv *swpriv) +static int mt7988_cleanup (struct mtk_eth_switch_priv *swpriv) {struct mt753x_switch_priv *priv = (struct mt753x_switch_priv *)swpriv; +struct mii_dev *mdio_bus = priv->mdio_bus; -mdio_unregister (priv->mdio_bus); +mdio_unregister (mdio_bus); +mdio_free (mdio_bus);return 0 ; }
@@ -162,6 +164,6 @@ MTK_ETH_SWITCH(mt7988) = { .reset_wait_time = 50, .setup = mt7988_setup, - .cleanup = mt7531_cleanup, + .cleanup = mt7988_cleanup, .mac_control = mt7988_mac_control, };
Signature · 1 line
2.51.0
PATCH 4/5 net: mediatek: move MT7531 MMIO MDIO to dedicated driver
In reply to Christian MarangiIn preparation for support of MDIO on AN7581, move the MT7531 MMIO logic to a dedicated driver and permit usage of the mdio read/write function to the mtk_eth driver.
This only affect MT7988 that can use MMIO operation to access the Switch register. The MT7988 code is updated to make use of the external driver.
This permits Airoha driver to make use of DM_MDIO to bind for the MT7531 driver that have the same exact register.
--- drivers/net/Kconfig | 3 + drivers/net/Makefile | 1 + drivers/net/mdio-mt7531-mmio.c | 168 +++++++++++++++++++++++++++++++++ drivers/net/mdio-mt7531-mmio.h | 9 ++ drivers/net/mtk_eth/Kconfig | 1 + drivers/net/mtk_eth/mt7988.c | 79 +++++++++++++--- 6 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 drivers/net/mdio-mt7531-mmio.c create mode 100644 drivers/net/mdio-mt7531-mmio.h
drivers/net/Kconfig +3 -0
@@ -966,6 +966,9 @@ config TSEC_ENET This driver implements support for the (Enhanced) Three-Speed Ethernet Controller found on Freescale SoCs. +config MDIO_MT7531_MMIO + bool + source "drivers/net/mtk_eth/Kconfig" config HIFEMAC_ETH
drivers/net/Makefile +1 -0
@@ -63,6 +63,7 @@ obj-$(CONFIG_MACB) += macb.o obj-$(CONFIG_MCFFEC) += mcffec.o mcfmii.o obj-$(CONFIG_MDIO_IPQ4019) += mdio-ipq4019.o obj-$(CONFIG_MDIO_GPIO_BITBANG) += mdio_gpio.o +obj-$(CONFIG_MDIO_MT7531_MMIO) += mdio-mt7531-mmio.o obj-$(CONFIG_MDIO_MUX_I2CREG) += mdio_mux_i2creg.o obj-$(CONFIG_MDIO_MUX_MESON_G12A) += mdio_mux_meson_g12a.o obj-$(CONFIG_MDIO_MUX_MESON_GXL) += mdio_mux_meson_gxl.o
drivers/net/mdio-mt7531-mmio.c new file +168 -0
168 lines not on this page · raw message
drivers/net/mdio-mt7531-mmio.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +struct mt7531_mdio_mmio_priv { +phys_addr_t switch_regs; +}; + +int mt7531_mdio_mmio_read (struct mii_dev *bus,int addr,int devad,int reg); +int mt7531_mdio_mmio_write (struct mii_dev *bus,int addr,int devad, +int reg,u16 value);
drivers/net/mtk_eth/Kconfig +1 -0
@@ -30,6 +30,7 @@ config MTK_ETH_SWITCH_MT7531 config MTK_ETH_SWITCH_MT7988 bool "Support for MediaTek MT7988 built-in ethernet switch" depends on TARGET_MT7988 + select MDIO_MT7531_MMIO default y config MTK_ETH_SWITCH_AN8855
drivers/net/mtk_eth/mt7988.c +67 -12
149 lines not on this page · raw message
Signature · 1 line
2.51.0
PATCH 5/5 net: airoha: bind MDIO controller on Ethernet load
In reply to Christian MarangiBind MDIO controller on Ethernet Controller load. The Airoha AN7581 SoC have an integrated Switch based on MT7531 (or more saying MT7988).
Attach it to the switch node to support scanning for MDIO devices on the BUS.
--- drivers/net/Kconfig | 1 + drivers/net/airoha_eth.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
drivers/net/Kconfig +1 -0
@@ -126,6 +126,7 @@ config AIROHA_ETH depends on ARCH_AIROHA select PHYLIB select DM_RESET + select MDIO_MT7531 help This Driver support Airoha Ethernet QDMA Driver Say Y to enable support for the Airoha Ethernet QDMA.
drivers/net/airoha_eth.c +26 -0
@@ -971,6 +971,31 @@ static int arht_eth_write_hwaddr(struct udevice *dev)return 0 ; } +static int airoha_eth_bind (struct udevice *dev) +{ +struct airoha_eth_soc_data *data = (void *)dev_get_driver_data (dev); +struct udevice *mdio_dev; +ofnode switch_node; +int ret =0 ; + +if (!CONFIG_IS_ENABLED (MDIO_MT7531 )) +return 0 ; + + switch_node =ofnode_by_compatible (ofnode_null (), +"airoha,en7581-switch" ); +if (!ofnode_valid (switch_node)) { +debug ("Warning: missing switch node\n" ); +return 0 ; + } + + ret =device_bind_driver_to_node (dev,"mt7531-mdio" ,"mdio" , + switch_node, &mdio_dev); +if (ret) +debug ("Warning: failed to bind mdio controller\n" ); + +return 0 ; +} +static const struct udevice_id airoha_eth_ids[] = { { .compatible ="airoha,en7581-eth" }, { }
@@ -990,6 +1015,7 @@ U_BOOT_DRIVER(airoha_eth) = { .id = UCLASS_ETH, .of_match = airoha_eth_ids, .probe = airoha_eth_probe, + .bind = airoha_eth_bind, .ops = &airoha_eth_ops, .priv_auto = sizeof(struct airoha_eth), .plat_auto = sizeof(struct eth_pdata),
Signature · 1 line
2.51.0