From: Mieczyslaw Nalewaj Date: Wed, 14 Feb 2024 12:14:10 +0000 (+0100) Subject: kernel: rtl8366_smi: explicitly set phy addr for switch X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=dca146cc778cdab2858b46e4ef3a3073fd02ab50;p=openwrt%2Fstaging%2Fdangole.git kernel: rtl8366_smi: explicitly set phy addr for switch By default rtl8366_smi use phy addr 0 at mii-bus to access switch registers. This patch allow to set it explicitly in dts-file: rtl8367 { compatible = "realtek,rtl8367b"; phy-id = <29>; /* switch address at mii-bus */ realtek,extif2 = <1 0 1 1 1 1 1 1 2>; mii-bus = <&mdio>; cpu-port = <7>; } Use default 0 address if not set. Backward compatibility tested on tplink archer c2 v1 (rtl8367rb switch) Signed-off-by: Serge Vasilugin [code style fixes, add explicit phy_id assignment in probe_plat, use phy-id instead of phy_id for of property name] Signed-off-by: Chuanhong Guo [rebase] Signed-off-by: Gaspare Bruno [added phy_id to struct rtl8366_smi] Signed-off-by: Mieczyslaw Nalewaj --- diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c index 028b9916e7..a26fd204cb 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.c @@ -256,7 +256,7 @@ static int __rtl8366_smi_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) int __rtl8366_mdio_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) { - u32 phy_id = MDC_REALTEK_PHY_ADDR; + u32 phy_id = smi->phy_id; struct mii_bus *mbus = smi->ext_mbus; BUG_ON(in_interrupt()); @@ -293,7 +293,7 @@ int __rtl8366_mdio_read_reg(struct rtl8366_smi *smi, u32 addr, u32 *data) static int __rtl8366_mdio_write_reg(struct rtl8366_smi *smi, u32 addr, u32 data) { - u32 phy_id = MDC_REALTEK_PHY_ADDR; + u32 phy_id = smi->phy_id; struct mii_bus *mbus = smi->ext_mbus; BUG_ON(in_interrupt()); @@ -1547,6 +1547,9 @@ int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi) goto try_gpio; } + if (of_property_read_u32(np, "phy-id", &smi->phy_id)) + smi->phy_id = MDC_REALTEK_PHY_ADDR; + return 0; try_gpio: @@ -1586,6 +1589,7 @@ int rtl8366_smi_probe_plat(struct platform_device *pdev, struct rtl8366_smi *smi smi->gpio_sda = pdata->gpio_sda; smi->gpio_sck = pdata->gpio_sck; smi->hw_reset = pdata->hw_reset; + smi->phy_id = MDC_REALTEK_PHY_ADDR; return 0; } diff --git a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h index fabc940278..3fcae81fa4 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h @@ -63,6 +63,7 @@ struct rtl8366_smi { u16 dbg_reg; u8 dbg_vlan_4k_page; #endif + u32 phy_id; struct mii_bus *ext_mbus; };