[OpenWrt-Devel] [PATCH v2 1/3] kernel: rtl8366_smi: explicitly set phy addr for switch

Hauke Mehrtens hauke at hauke-m.de
Sun Sep 29 12:50:36 EDT 2019


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 at 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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.infradead.org/pipermail/openwrt-devel/attachments/20190929/3335dbe1/attachment.sig>
-------------- next part --------------
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel


More information about the openwrt-devel mailing list