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

Message ID e3820a48-cb98-0947-ee23-29169a5d4ff9@yandex.ru
State New
Headers show
Series
  • kernel: add support for realtek rtl8367s
Related show

Commit Message

Serge Vailugin Aug. 27, 2019, 9:49 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

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,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 {