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

Serge Vailugin vasilugin at yandex.ru
Tue Aug 27 05:49:18 EDT 2019


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 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;
+	}
+
+	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 {
---
serge

_______________________________________________
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