Message ID | e3820a48-cb98-0947-ee23-29169a5d4ff9@yandex.ru |
---|---|
State | Changes Requested, archived |
Headers | show |
Series | kernel: add support for realtek rtl8367s | expand |
Hi! On Tue, Aug 27, 2019 at 5:49 PM Serge Vailugin <vasilugin@yandex.ru> wrote: > [...] > @@ -1558,6 +1558,14 @@ int rtl8366_smi_probe_of(struct platform_device > *pdev, struct rtl8366_smi *smi) > goto try_gpio; > } > > + of_property_read_u32(np, "phy_id", &smi->phy_id); > + if(smi->phy_id < 0) { > + smi->phy_id = MDC_REALTEK_PHY_ADDR; > + } When of_property_read_u32 fails, it returns a negative value and leave destination variable unchanged. You should check return value here instead. > + > + dev_info(&pdev->dev, > + "switch phy addr=%d\n", smi->phy_id); > + > return 0; > > try_gpio: Regards, Chuanhong Guo
Hi Serge, On 8/27/19 11:49 AM, Serge Vailugin wrote: > 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 */ I am not sure if we should use the reg property for this instead. Did you check other drivers? > 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 <vasilugin@yandex.ru> > > --- 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()); > @@ -1558,6 +1558,14 @@ int rtl8366_smi_probe_of(struct platform_device > *pdev, struct rtl8366_smi *smi) > goto try_gpio; > } > > + of_property_read_u32(np, "phy_id", &smi->phy_id); > + if(smi->phy_id < 0) { > + smi->phy_id = MDC_REALTEK_PHY_ADDR; > + } You should check the return value of of_property_read_u32() and set it to MDC_REALTEK_PHY_ADDR in case it returned an error like this: if (of_property_read_u32(np, "phy_id", &smi->phy_id)) smi->phy_id = MDC_REALTEK_PHY_ADDR; > + > + dev_info(&pdev->dev, > + "switch phy addr=%d\n", smi->phy_id); > + > return 0; > > try_gpio: > --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h > +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h > @@ -64,6 +64,7 @@ struct rtl8366_smi { > u8 dbg_vlan_4k_page; > #endif > struct mii_bus *ext_mbus; > + u32 phy_id; > }; > > struct rtl8366_vlan_mc { Hauke
--- 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()); @@ -1558,6 +1558,14 @@ int rtl8366_smi_probe_of(struct platform_device *pdev, struct rtl8366_smi *smi) goto try_gpio; } + of_property_read_u32(np, "phy_id", &smi->phy_id); + if(smi->phy_id < 0) { + smi->phy_id = MDC_REALTEK_PHY_ADDR; + } + + dev_info(&pdev->dev, + "switch phy addr=%d\n", smi->phy_id); + return 0; try_gpio: --- a/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h +++ b/target/linux/generic/files/drivers/net/phy/rtl8366_smi.h @@ -64,6 +64,7 @@ struct rtl8366_smi { u8 dbg_vlan_4k_page; #endif struct mii_bus *ext_mbus; + u32 phy_id; }; struct rtl8366_vlan_mc {
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 <vasilugin@yandex.ru> --- serge