]> git.ipfire.org Git - thirdparty/openwrt.git/blob
50e96d7eef503ca25ea7ab9e4dec049e793ab4d7
[thirdparty/openwrt.git] /
1 From b4bd77971f3c290c4694ed710cc6967593b10bc2 Mon Sep 17 00:00:00 2001
2 From: Luiz Angelo Daros de Luca <luizluca@gmail.com>
3 Date: Fri, 9 Feb 2024 02:03:45 -0300
4 Subject: net: dsa: realtek: migrate slave_mii_bus setup to
5 realtek_dsa
6
7 In the user MDIO driver, despite numerous references to SMI, including
8 its compatible string, there's nothing inherently specific about the SMI
9 interface in the user MDIO bus. Consequently, the code has been migrated
10 to the rtl83xx module. All references to SMI have been eliminated.
11
12 The MDIO bus id was changed from Realtek-<switch id> to the switch
13 devname suffixed with :slave_mii, giving more information about the bus
14 it is referencing.
15
16 Signed-off-by: Luiz Angelo Daros de Luca <luizluca@gmail.com>
17 Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
18 Signed-off-by: David S. Miller <davem@davemloft.net>
19 ---
20 drivers/net/dsa/realtek/realtek-smi.c | 57 +---------------------
21 drivers/net/dsa/realtek/rtl83xx.c | 68 +++++++++++++++++++++++++++
22 drivers/net/dsa/realtek/rtl83xx.h | 1 +
23 3 files changed, 70 insertions(+), 56 deletions(-)
24
25 --- a/drivers/net/dsa/realtek/realtek-smi.c
26 +++ b/drivers/net/dsa/realtek/realtek-smi.c
27 @@ -31,7 +31,6 @@
28 #include <linux/spinlock.h>
29 #include <linux/skbuff.h>
30 #include <linux/of.h>
31 -#include <linux/of_mdio.h>
32 #include <linux/delay.h>
33 #include <linux/gpio/consumer.h>
34 #include <linux/platform_device.h>
35 @@ -312,60 +311,6 @@ static int realtek_smi_read(void *ctx, u
36 return realtek_smi_read_reg(priv, reg, val);
37 }
38
39 -static int realtek_smi_mdio_read(struct mii_bus *bus, int addr, int regnum)
40 -{
41 - struct realtek_priv *priv = bus->priv;
42 -
43 - return priv->ops->phy_read(priv, addr, regnum);
44 -}
45 -
46 -static int realtek_smi_mdio_write(struct mii_bus *bus, int addr, int regnum,
47 - u16 val)
48 -{
49 - struct realtek_priv *priv = bus->priv;
50 -
51 - return priv->ops->phy_write(priv, addr, regnum, val);
52 -}
53 -
54 -static int realtek_smi_setup_mdio(struct dsa_switch *ds)
55 -{
56 - struct realtek_priv *priv = ds->priv;
57 - struct device_node *mdio_np;
58 - int ret = 0;
59 -
60 - mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio");
61 - if (!mdio_np) {
62 - dev_err(priv->dev, "no MDIO bus node\n");
63 - return -ENODEV;
64 - }
65 -
66 - priv->slave_mii_bus = devm_mdiobus_alloc(priv->dev);
67 - if (!priv->slave_mii_bus) {
68 - ret = -ENOMEM;
69 - goto err_put_node;
70 - }
71 -
72 - priv->slave_mii_bus->priv = priv;
73 - priv->slave_mii_bus->name = "SMI slave MII";
74 - priv->slave_mii_bus->read = realtek_smi_mdio_read;
75 - priv->slave_mii_bus->write = realtek_smi_mdio_write;
76 - snprintf(priv->slave_mii_bus->id, MII_BUS_ID_SIZE, "SMI-%d",
77 - ds->index);
78 - priv->slave_mii_bus->parent = priv->dev;
79 -
80 - ret = devm_of_mdiobus_register(priv->dev, priv->slave_mii_bus, mdio_np);
81 - if (ret) {
82 - dev_err(priv->dev, "unable to register MDIO bus %s\n",
83 - priv->slave_mii_bus->id);
84 - goto err_put_node;
85 - }
86 -
87 -err_put_node:
88 - of_node_put(mdio_np);
89 -
90 - return ret;
91 -}
92 -
93 static const struct realtek_interface_info realtek_smi_info = {
94 .reg_read = realtek_smi_read,
95 .reg_write = realtek_smi_write,
96 @@ -407,7 +352,7 @@ int realtek_smi_probe(struct platform_de
97 }
98
99 priv->write_reg_noack = realtek_smi_write_reg_noack;
100 - priv->setup_interface = realtek_smi_setup_mdio;
101 + priv->setup_interface = rtl83xx_setup_user_mdio;
102 priv->ds_ops = priv->variant->ds_ops_smi;
103
104 ret = rtl83xx_register_switch(priv);
105 --- a/drivers/net/dsa/realtek/rtl83xx.c
106 +++ b/drivers/net/dsa/realtek/rtl83xx.c
107 @@ -3,6 +3,7 @@
108 #include <linux/module.h>
109 #include <linux/regmap.h>
110 #include <linux/of_device.h> /* krnl 6.1 only */
111 +#include <linux/of_mdio.h>
112
113 #include "realtek.h"
114 #include "rtl83xx.h"
115 @@ -44,6 +45,73 @@ void rtl83xx_unlock(void *ctx)
116 }
117 EXPORT_SYMBOL_NS_GPL(rtl83xx_unlock, REALTEK_DSA);
118
119 +static int rtl83xx_user_mdio_read(struct mii_bus *bus, int addr, int regnum)
120 +{
121 + struct realtek_priv *priv = bus->priv;
122 +
123 + return priv->ops->phy_read(priv, addr, regnum);
124 +}
125 +
126 +static int rtl83xx_user_mdio_write(struct mii_bus *bus, int addr, int regnum,
127 + u16 val)
128 +{
129 + struct realtek_priv *priv = bus->priv;
130 +
131 + return priv->ops->phy_write(priv, addr, regnum, val);
132 +}
133 +
134 +/**
135 + * rtl83xx_setup_user_mdio() - register the user mii bus driver
136 + * @ds: DSA switch associated with this slave_mii_bus
137 + *
138 + * Registers the MDIO bus for built-in Ethernet PHYs, and associates it with
139 + * the mandatory 'mdio' child OF node of the switch.
140 + *
141 + * Context: Can sleep.
142 + * Return: 0 on success, negative value for failure.
143 + */
144 +int rtl83xx_setup_user_mdio(struct dsa_switch *ds)
145 +{
146 + struct realtek_priv *priv = ds->priv;
147 + struct device_node *mdio_np;
148 + struct mii_bus *bus;
149 + int ret = 0;
150 +
151 + mdio_np = of_get_child_by_name(priv->dev->of_node, "mdio");
152 + if (!mdio_np) {
153 + dev_err(priv->dev, "no MDIO bus node\n");
154 + return -ENODEV;
155 + }
156 +
157 + bus = devm_mdiobus_alloc(priv->dev);
158 + if (!bus) {
159 + ret = -ENOMEM;
160 + goto err_put_node;
161 + }
162 +
163 + bus->priv = priv;
164 + bus->name = "Realtek user MII";
165 + bus->read = rtl83xx_user_mdio_read;
166 + bus->write = rtl83xx_user_mdio_write;
167 + snprintf(bus->id, MII_BUS_ID_SIZE, "%s:slave_mii", dev_name(priv->dev));
168 + bus->parent = priv->dev;
169 +
170 + ret = devm_of_mdiobus_register(priv->dev, bus, mdio_np);
171 + if (ret) {
172 + dev_err(priv->dev, "unable to register MDIO bus %s\n",
173 + bus->id);
174 + goto err_put_node;
175 + }
176 +
177 + priv->slave_mii_bus = bus;
178 +
179 +err_put_node:
180 + of_node_put(mdio_np);
181 +
182 + return ret;
183 +}
184 +EXPORT_SYMBOL_NS_GPL(rtl83xx_setup_user_mdio, REALTEK_DSA);
185 +
186 /**
187 * rtl83xx_probe() - probe a Realtek switch
188 * @dev: the device being probed
189 --- a/drivers/net/dsa/realtek/rtl83xx.h
190 +++ b/drivers/net/dsa/realtek/rtl83xx.h
191 @@ -10,6 +10,7 @@ struct realtek_interface_info {
192
193 void rtl83xx_lock(void *ctx);
194 void rtl83xx_unlock(void *ctx);
195 +int rtl83xx_setup_user_mdio(struct dsa_switch *ds);
196 struct realtek_priv *
197 rtl83xx_probe(struct device *dev,
198 const struct realtek_interface_info *interface_info);