[OpenWrt-Devel,1/3] kernel: rtl8366_smi: explicitly set phy addr for switch
diff mbox series

Message ID e0eb9887-28eb-a008-96e2-66d4de81ff11@yandex.ru
State Changes Requested, archived
Headers show
Series
  • kernel: add support for realtek rtl8367s
Related show

Commit Message

Serge Vailugin Aug. 15, 2019, 8:27 a.m. UTC
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

Comments

Vincent Wiemann Aug. 17, 2019, 5:59 p.m. UTC | #1
Hi Serge,

thank you very much for this contribution. I can only give some cosmetic
advice. I'm not sure about the functionality.

On 15.08.19 10:27, Serge Vasilugin 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 */
>         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,12 @@ 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;
> +    }

Please add a newline here.

> +    dev_info(&pdev->dev,
> +        "switch phy addr=%d\n", smi->phy_id);

Please add a newline here.

>      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;
> +    int phy_id;

u32 here?

>  };
> 
>  struct rtl8366_vlan_mc {
> ---
> serge
> 
> _______________________________________________
> openwrt-devel mailing list
> openwrt-devel@lists.openwrt.org
> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
> 

Regards,

Vincent

Patch
diff mbox series

--- 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,12 @@  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;
+	int phy_id;
  };

  struct rtl8366_vlan_mc {