From: Mieczyslaw Nalewaj Date: Sat, 27 Jul 2024 12:50:04 +0000 (+0200) Subject: kernel: rtl8367b: use realtek,extif property X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=c0e50ebaf795fd392e4fda4978a48b1382fad5c9;p=openwrt%2Fstaging%2Fwigyori.git kernel: rtl8367b: use realtek,extif property Use realtek,extif property instead of realtek,extif0 to extif2 by extending it with the cpu_port parameter. The extif number is automatically calculated based on cpu_port. Signed-off-by: Mieczyslaw Nalewaj Link: https://github.com/openwrt/openwrt/pull/15749 Signed-off-by: Hauke Mehrtens --- diff --git a/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi b/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi index 9d98776626..7c9faa883f 100644 --- a/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi +++ b/target/linux/apm821xx/dts/netgear-wndap6x0.dtsi @@ -224,7 +224,7 @@ rtl8367b { compatible = "realtek,rtl8367b"; - realtek,extif0 = <1 2 1 1 1 1 1 1 2>; + realtek,extif = <5 1 2 1 1 1 1 1 1 2>; mii-bus = <&mdio0>; }; }; diff --git a/target/linux/generic/files/drivers/net/phy/rtl8367b.c b/target/linux/generic/files/drivers/net/phy/rtl8367b.c index f79f7261a1..534da05517 100644 --- a/target/linux/generic/files/drivers/net/phy/rtl8367b.c +++ b/target/linux/generic/files/drivers/net/phy/rtl8367b.c @@ -709,21 +709,48 @@ static int rtl8367b_extif_init(struct rtl8366_smi *smi, int id, } #ifdef CONFIG_OF -static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id, +static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, const char *name) { struct rtl8367_extif_config *cfg; const __be32 *prop; int size; int err; + unsigned cpu_port; + unsigned id = UINT_MAX; prop = of_get_property(smi->parent->of_node, name, &size); - if (!prop) - return rtl8367b_extif_init(smi, id, NULL); + if (!prop || (size != (10 * sizeof(*prop)))) { + dev_err(smi->parent, "%s property is not defined or invalid\n", name); + err = -EINVAL; + goto err_init; + } - if (size != (9 * sizeof(*prop))) { - dev_err(smi->parent, "%s property is invalid\n", name); - return -EINVAL; + cpu_port = be32_to_cpup(prop++); + switch (cpu_port) { + case RTL8367B_CPU_PORT_NUM: + case RTL8367B_CPU_PORT_NUM + 1: + case RTL8367B_CPU_PORT_NUM + 2: + if (smi->rtl8367b_chip == RTL8367B_CHIP_RTL8367R_VB) { /* for the RTL8367R-VB chip, cpu_port 5 corresponds to extif1 */ + if (cpu_port == RTL8367B_CPU_PORT_NUM) + id = 1; + else { + dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name); + err = -EINVAL; + goto err_init; + } + } else { + id = cpu_port - RTL8367B_CPU_PORT_NUM; + } + if (smi->cpu_port == UINT_MAX) { + dev_info(smi->parent, "cpu_port:%u, assigned to extif%u\n", cpu_port, id); + smi->cpu_port = cpu_port; + } + break; + default: + dev_err(smi->parent, "wrong cpu_port %u in %s property\n", cpu_port, name); + err = -EINVAL; + goto err_init; } cfg = kzalloc(sizeof(struct rtl8367_extif_config), GFP_KERNEL); @@ -743,10 +770,15 @@ static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id, err = rtl8367b_extif_init(smi, id, cfg); kfree(cfg); +err_init: + if (id != 0) rtl8367b_extif_init(smi, 0, NULL); + if (id != 1) rtl8367b_extif_init(smi, 1, NULL); + if (id != 2) rtl8367b_extif_init(smi, 2, NULL); + return err; } #else -static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, int id, +static int rtl8367b_extif_init_of(struct rtl8366_smi *smi, const char *name) { return -EINVAL; @@ -767,15 +799,7 @@ static int rtl8367b_setup(struct rtl8366_smi *smi) /* initialize external interfaces */ if (smi->parent->of_node) { - err = rtl8367b_extif_init_of(smi, 0, "realtek,extif0"); - if (err) - return err; - - err = rtl8367b_extif_init_of(smi, 1, "realtek,extif1"); - if (err) - return err; - - err = rtl8367b_extif_init_of(smi, 2, "realtek,extif2"); + err = rtl8367b_extif_init_of(smi, "realtek,extif"); if (err) return err; } else { @@ -1352,13 +1376,6 @@ static int rtl8367b_detect(struct rtl8366_smi *smi) dev_info(smi->parent, "RTL%s chip found (num:%04x ver:%04x)\n", chip_name, chip_num, chip_ver); - if (of_property_present(smi->parent->of_node, "realtek,extif2")) - smi->cpu_port = RTL8367B_CPU_PORT_NUM + 2; - else if (of_property_present(smi->parent->of_node, "realtek,extif1") && (smi->rtl8367b_chip != RTL8367B_CHIP_RTL8367R_VB)) /* for the RTL8367R-VB chip, extif1 corresponds to cpu_port 5 */ - smi->cpu_port = RTL8367B_CPU_PORT_NUM + 1; - - dev_info(smi->parent, "CPU port: %u\n", smi->cpu_port); - return 0; } @@ -1397,7 +1414,7 @@ static int rtl8367b_probe(struct platform_device *pdev) smi->cmd_write = 0xb8; smi->ops = &rtl8367b_smi_ops; smi->num_ports = RTL8367B_NUM_PORTS; - smi->cpu_port = RTL8367B_CPU_PORT_NUM; + smi->cpu_port = UINT_MAX; /* not defined yet */ smi->num_vlan_mc = RTL8367B_NUM_VLANS; smi->mib_counters = rtl8367b_mib_counters; smi->num_mib_counters = ARRAY_SIZE(rtl8367b_mib_counters); diff --git a/target/linux/ramips/dts/mt7620a_iodata_wn-ac733gr3.dts b/target/linux/ramips/dts/mt7620a_iodata_wn-ac733gr3.dts index d95a4ad99d..19b1538241 100644 --- a/target/linux/ramips/dts/mt7620a_iodata_wn-ac733gr3.dts +++ b/target/linux/ramips/dts/mt7620a_iodata_wn-ac733gr3.dts @@ -77,7 +77,7 @@ compatible = "realtek,rtl8367b"; gpio-sda = <&gpio0 22 GPIO_ACTIVE_HIGH>; gpio-sck = <&gpio0 23 GPIO_ACTIVE_HIGH>; - realtek,extif1 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <6 1 0 1 1 1 1 1 1 2>; }; }; diff --git a/target/linux/ramips/dts/mt7620a_tplink_archer-c2-v1.dts b/target/linux/ramips/dts/mt7620a_tplink_archer-c2-v1.dts index 06f3eba37b..feb619a0c0 100644 --- a/target/linux/ramips/dts/mt7620a_tplink_archer-c2-v1.dts +++ b/target/linux/ramips/dts/mt7620a_tplink_archer-c2-v1.dts @@ -55,7 +55,7 @@ rtl8367rb { compatible = "realtek,rtl8367b"; - realtek,extif1 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <6 1 0 1 1 1 1 1 1 2>; mii-bus = <&mdio0>; }; }; diff --git a/target/linux/ramips/dts/mt7620a_tplink_archer-c5-v4.dts b/target/linux/ramips/dts/mt7620a_tplink_archer-c5-v4.dts index 855e06e9f6..91b3a255c1 100644 --- a/target/linux/ramips/dts/mt7620a_tplink_archer-c5-v4.dts +++ b/target/linux/ramips/dts/mt7620a_tplink_archer-c5-v4.dts @@ -74,7 +74,7 @@ rtl8367s { compatible = "realtek,rtl8367b"; - realtek,extif2 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <7 1 0 1 1 1 1 1 1 2>; mii-bus = <&mdio0>; phy-id = <29>; }; diff --git a/target/linux/ramips/dts/mt7620a_tplink_ec220-g5-v2.dts b/target/linux/ramips/dts/mt7620a_tplink_ec220-g5-v2.dts index 7fc075aedd..a39455cf29 100644 --- a/target/linux/ramips/dts/mt7620a_tplink_ec220-g5-v2.dts +++ b/target/linux/ramips/dts/mt7620a_tplink_ec220-g5-v2.dts @@ -82,7 +82,7 @@ rtl8367s { compatible = "realtek,rtl8367b"; - realtek,extif2 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <7 1 0 1 1 1 1 1 1 2>; mii-bus = <&mdio0>; phy-id = <29>; }; diff --git a/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts b/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts index 0630e8a160..d095b45630 100644 --- a/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts +++ b/target/linux/ramips/dts/mt7620a_zyxel_keenetic-viva.dts @@ -85,7 +85,7 @@ rtl8367rb { compatible = "realtek,rtl8367b"; - realtek,extif2 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <7 1 0 1 1 1 1 1 1 2>; mii-bus = <&mdio0>; }; }; diff --git a/target/linux/ramips/dts/rt3662_dlink_dir-645.dts b/target/linux/ramips/dts/rt3662_dlink_dir-645.dts index 3d6479f44f..8cfa48e195 100644 --- a/target/linux/ramips/dts/rt3662_dlink_dir-645.dts +++ b/target/linux/ramips/dts/rt3662_dlink_dir-645.dts @@ -19,7 +19,7 @@ compatible = "realtek,rtl8367b"; gpio-sda = <&gpio0 1 GPIO_ACTIVE_HIGH>; gpio-sck = <&gpio0 2 GPIO_ACTIVE_HIGH>; - realtek,extif1 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <6 1 0 1 1 1 1 1 1 2>; }; keys { diff --git a/target/linux/ramips/dts/rt3883_belkin_f9k110x.dtsi b/target/linux/ramips/dts/rt3883_belkin_f9k110x.dtsi index a2d1906b89..4d60bb3c05 100644 --- a/target/linux/ramips/dts/rt3883_belkin_f9k110x.dtsi +++ b/target/linux/ramips/dts/rt3883_belkin_f9k110x.dtsi @@ -12,7 +12,7 @@ compatible = "realtek,rtl8367b"; gpio-sda = <&gpio0 1 GPIO_ACTIVE_HIGH>; gpio-sck = <&gpio0 2 GPIO_ACTIVE_HIGH>; - realtek,extif1 = <1 0 1 1 1 1 1 1 2>; + realtek,extif = <5 1 0 1 1 1 1 1 1 2>; }; };