e970ec3804b97a4f14b50f6e1afd387a4eca2bee
[openwrt/staging/blocktrron.git] /
1 From cb675afcddbbeb2bfa6596e3bc236bc026cd425f Mon Sep 17 00:00:00 2001
2 From: Daniel Golle <daniel@makrotopia.org>
3 Date: Mon, 3 Apr 2023 02:19:13 +0100
4 Subject: [PATCH 14/16] net: dsa: mt7530: introduce separate MDIO driver
5
6 Split MT7530 switch driver into a common part and a part specific
7 for MDIO connected switches and multi-chip modules.
8 Move MDIO-specific functions to newly introduced mt7530-mdio.c while
9 keeping the common parts in mt7530.c.
10 Introduce new Kconfig symbol CONFIG_NET_DSA_MT7530_MDIO which is
11 implied by CONFIG_NET_DSA_MT7530.
12
13 Signed-off-by: Daniel Golle <daniel@makrotopia.org>
14 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
15 Signed-off-by: David S. Miller <davem@davemloft.net>
16 ---
17 MAINTAINERS | 1 +
18 drivers/net/dsa/Kconfig | 15 +-
19 drivers/net/dsa/Makefile | 1 +
20 drivers/net/dsa/mt7530-mdio.c | 271 ++++++++++++++++++++++++++++++++++
21 drivers/net/dsa/mt7530.c | 264 +--------------------------------
22 drivers/net/dsa/mt7530.h | 6 +
23 6 files changed, 300 insertions(+), 258 deletions(-)
24 create mode 100644 drivers/net/dsa/mt7530-mdio.c
25
26 --- a/MAINTAINERS
27 +++ b/MAINTAINERS
28 @@ -11902,6 +11902,7 @@ M: Landen Chao <Landen.Chao@mediatek.com
29 M: DENG Qingfang <dqfext@gmail.com>
30 L: netdev@vger.kernel.org
31 S: Maintained
32 +F: drivers/net/dsa/mt7530-mdio.c
33 F: drivers/net/dsa/mt7530.*
34 F: net/dsa/tag_mtk.c
35
36 --- a/drivers/net/dsa/Kconfig
37 +++ b/drivers/net/dsa/Kconfig
38 @@ -37,10 +37,22 @@ config NET_DSA_MT7530
39 tristate "MediaTek MT753x and MT7621 Ethernet switch support"
40 select NET_DSA_TAG_MTK
41 select MEDIATEK_GE_PHY
42 + imply NET_DSA_MT7530_MDIO
43 + help
44 + This enables support for the MediaTek MT7530 and MT7531 Ethernet
45 + switch chips. Multi-chip module MT7530 in MT7621AT, MT7621DAT,
46 + MT7621ST and MT7623AI SoCs, and built-in switch in MT7988 SoC are
47 + supported as well.
48 +
49 +config NET_DSA_MT7530_MDIO
50 + tristate "MediaTek MT7530 MDIO interface driver"
51 + depends on NET_DSA_MT7530
52 select PCS_MTK_LYNXI
53 help
54 - This enables support for the MediaTek MT7530, MT7531, and MT7621
55 - Ethernet switch chips.
56 + This enables support for the MediaTek MT7530 and MT7531 switch
57 + chips which are connected via MDIO, as well as multi-chip
58 + module MT7530 which can be found in the MT7621AT, MT7621DAT,
59 + MT7621ST and MT7623AI SoCs.
60
61 config NET_DSA_MV88E6060
62 tristate "Marvell 88E6060 ethernet switch chip support"
63 --- a/drivers/net/dsa/Makefile
64 +++ b/drivers/net/dsa/Makefile
65 @@ -7,6 +7,7 @@ obj-$(CONFIG_FIXED_PHY) += dsa_loop_bdi
66 endif
67 obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o
68 obj-$(CONFIG_NET_DSA_MT7530) += mt7530.o
69 +obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
70 obj-$(CONFIG_NET_DSA_MV88E6060) += mv88e6060.o
71 obj-$(CONFIG_NET_DSA_REALTEK_SMI) += realtek-smi.o
72 realtek-smi-objs := realtek-smi-core.o rtl8366.o rtl8366rb.o
73 --- /dev/null
74 +++ b/drivers/net/dsa/mt7530-mdio.c
75 @@ -0,0 +1,271 @@
76 +// SPDX-License-Identifier: GPL-2.0-only
77 +
78 +#include <linux/gpio/consumer.h>
79 +#include <linux/mdio.h>
80 +#include <linux/module.h>
81 +#include <linux/pcs/pcs-mtk-lynxi.h>
82 +#include <linux/of_irq.h>
83 +#include <linux/of_mdio.h>
84 +#include <linux/of_net.h>
85 +#include <linux/of_platform.h>
86 +#include <linux/regmap.h>
87 +#include <linux/reset.h>
88 +#include <linux/regulator/consumer.h>
89 +#include <net/dsa.h>
90 +
91 +#include "mt7530.h"
92 +
93 +static int
94 +mt7530_regmap_write(void *context, unsigned int reg, unsigned int val)
95 +{
96 + struct mii_bus *bus = context;
97 + u16 page, r, lo, hi;
98 + int ret;
99 +
100 + page = (reg >> 6) & 0x3ff;
101 + r = (reg >> 2) & 0xf;
102 + lo = val & 0xffff;
103 + hi = val >> 16;
104 +
105 + /* MT7530 uses 31 as the pseudo port */
106 + ret = bus->write(bus, 0x1f, 0x1f, page);
107 + if (ret < 0)
108 + return ret;
109 +
110 + ret = bus->write(bus, 0x1f, r, lo);
111 + if (ret < 0)
112 + return ret;
113 +
114 + ret = bus->write(bus, 0x1f, 0x10, hi);
115 + return ret;
116 +}
117 +
118 +static int
119 +mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val)
120 +{
121 + struct mii_bus *bus = context;
122 + u16 page, r, lo, hi;
123 + int ret;
124 +
125 + page = (reg >> 6) & 0x3ff;
126 + r = (reg >> 2) & 0xf;
127 +
128 + /* MT7530 uses 31 as the pseudo port */
129 + ret = bus->write(bus, 0x1f, 0x1f, page);
130 + if (ret < 0)
131 + return ret;
132 +
133 + lo = bus->read(bus, 0x1f, r);
134 + hi = bus->read(bus, 0x1f, 0x10);
135 +
136 + *val = (hi << 16) | (lo & 0xffff);
137 +
138 + return 0;
139 +}
140 +
141 +static void
142 +mt7530_mdio_regmap_lock(void *mdio_lock)
143 +{
144 + mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED);
145 +}
146 +
147 +static void
148 +mt7530_mdio_regmap_unlock(void *mdio_lock)
149 +{
150 + mutex_unlock(mdio_lock);
151 +}
152 +
153 +static const struct regmap_bus mt7530_regmap_bus = {
154 + .reg_write = mt7530_regmap_write,
155 + .reg_read = mt7530_regmap_read,
156 +};
157 +
158 +static int
159 +mt7531_create_sgmii(struct mt7530_priv *priv)
160 +{
161 + struct regmap_config *mt7531_pcs_config[2];
162 + struct phylink_pcs *pcs;
163 + struct regmap *regmap;
164 + int i, ret = 0;
165 +
166 + for (i = 0; i < 2; i++) {
167 + mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
168 + sizeof(struct regmap_config),
169 + GFP_KERNEL);
170 + if (!mt7531_pcs_config[i]) {
171 + ret = -ENOMEM;
172 + break;
173 + }
174 +
175 + mt7531_pcs_config[i]->name = i ? "port6" : "port5";
176 + mt7531_pcs_config[i]->reg_bits = 16;
177 + mt7531_pcs_config[i]->val_bits = 32;
178 + mt7531_pcs_config[i]->reg_stride = 4;
179 + mt7531_pcs_config[i]->reg_base = MT7531_SGMII_REG_BASE(5 + i);
180 + mt7531_pcs_config[i]->max_register = 0x17c;
181 + mt7531_pcs_config[i]->lock = mt7530_mdio_regmap_lock;
182 + mt7531_pcs_config[i]->unlock = mt7530_mdio_regmap_unlock;
183 + mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock;
184 +
185 + regmap = devm_regmap_init(priv->dev,
186 + &mt7530_regmap_bus, priv->bus,
187 + mt7531_pcs_config[i]);
188 + if (IS_ERR(regmap)) {
189 + ret = PTR_ERR(regmap);
190 + break;
191 + }
192 + pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
193 + MT7531_PHYA_CTRL_SIGNAL3, 0);
194 + if (!pcs) {
195 + ret = -ENXIO;
196 + break;
197 + }
198 + priv->ports[5 + i].sgmii_pcs = pcs;
199 + }
200 +
201 + if (ret && i)
202 + mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
203 +
204 + return ret;
205 +}
206 +
207 +static const struct of_device_id mt7530_of_match[] = {
208 + { .compatible = "mediatek,mt7621", .data = &mt753x_table[ID_MT7621], },
209 + { .compatible = "mediatek,mt7530", .data = &mt753x_table[ID_MT7530], },
210 + { .compatible = "mediatek,mt7531", .data = &mt753x_table[ID_MT7531], },
211 + { /* sentinel */ },
212 +};
213 +MODULE_DEVICE_TABLE(of, mt7530_of_match);
214 +
215 +static int
216 +mt7530_probe(struct mdio_device *mdiodev)
217 +{
218 + static struct regmap_config *regmap_config;
219 + struct mt7530_priv *priv;
220 + struct device_node *dn;
221 + int ret;
222 +
223 + dn = mdiodev->dev.of_node;
224 +
225 + priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
226 + if (!priv)
227 + return -ENOMEM;
228 +
229 + priv->bus = mdiodev->bus;
230 + priv->dev = &mdiodev->dev;
231 +
232 + ret = mt7530_probe_common(priv);
233 + if (ret)
234 + return ret;
235 +
236 + /* Use medatek,mcm property to distinguish hardware type that would
237 + * cause a little bit differences on power-on sequence.
238 + * Not MCM that indicates switch works as the remote standalone
239 + * integrated circuit so the GPIO pin would be used to complete
240 + * the reset, otherwise memory-mapped register accessing used
241 + * through syscon provides in the case of MCM.
242 + */
243 + priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
244 + if (priv->mcm) {
245 + dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
246 +
247 + priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm");
248 + if (IS_ERR(priv->rstc)) {
249 + dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
250 + return PTR_ERR(priv->rstc);
251 + }
252 + } else {
253 + priv->reset = devm_gpiod_get_optional(&mdiodev->dev, "reset",
254 + GPIOD_OUT_LOW);
255 + if (IS_ERR(priv->reset)) {
256 + dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
257 + return PTR_ERR(priv->reset);
258 + }
259 + }
260 +
261 + if (priv->id == ID_MT7530) {
262 + priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
263 + if (IS_ERR(priv->core_pwr))
264 + return PTR_ERR(priv->core_pwr);
265 +
266 + priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
267 + if (IS_ERR(priv->io_pwr))
268 + return PTR_ERR(priv->io_pwr);
269 + }
270 +
271 + regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config),
272 + GFP_KERNEL);
273 + if (!regmap_config)
274 + return -ENOMEM;
275 +
276 + regmap_config->reg_bits = 16;
277 + regmap_config->val_bits = 32;
278 + regmap_config->reg_stride = 4;
279 + regmap_config->max_register = MT7530_CREV;
280 + regmap_config->disable_locking = true;
281 + priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus,
282 + priv->bus, regmap_config);
283 + if (IS_ERR(priv->regmap))
284 + return PTR_ERR(priv->regmap);
285 +
286 + if (priv->id == ID_MT7531) {
287 + ret = mt7531_create_sgmii(priv);
288 + if (ret)
289 + return ret;
290 + }
291 +
292 + return dsa_register_switch(priv->ds);
293 +}
294 +
295 +static void
296 +mt7530_remove(struct mdio_device *mdiodev)
297 +{
298 + struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev);
299 + int ret = 0, i;
300 +
301 + if (!priv)
302 + return;
303 +
304 + ret = regulator_disable(priv->core_pwr);
305 + if (ret < 0)
306 + dev_err(priv->dev,
307 + "Failed to disable core power: %d\n", ret);
308 +
309 + ret = regulator_disable(priv->io_pwr);
310 + if (ret < 0)
311 + dev_err(priv->dev, "Failed to disable io pwr: %d\n",
312 + ret);
313 +
314 + mt7530_remove_common(priv);
315 +
316 + for (i = 0; i < 2; ++i)
317 + mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs);
318 +}
319 +
320 +static void mt7530_shutdown(struct mdio_device *mdiodev)
321 +{
322 + struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev);
323 +
324 + if (!priv)
325 + return;
326 +
327 + dsa_switch_shutdown(priv->ds);
328 +
329 + dev_set_drvdata(&mdiodev->dev, NULL);
330 +}
331 +
332 +static struct mdio_driver mt7530_mdio_driver = {
333 + .probe = mt7530_probe,
334 + .remove = mt7530_remove,
335 + .shutdown = mt7530_shutdown,
336 + .mdiodrv.driver = {
337 + .name = "mt7530-mdio",
338 + .of_match_table = mt7530_of_match,
339 + },
340 +};
341 +
342 +mdio_module_driver(mt7530_mdio_driver);
343 +
344 +MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
345 +MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch (MDIO)");
346 +MODULE_LICENSE("GPL");
347 --- a/drivers/net/dsa/mt7530.c
348 +++ b/drivers/net/dsa/mt7530.c
349 @@ -14,7 +14,6 @@
350 #include <linux/of_mdio.h>
351 #include <linux/of_net.h>
352 #include <linux/of_platform.h>
353 -#include <linux/pcs/pcs-mtk-lynxi.h>
354 #include <linux/phylink.h>
355 #include <linux/regmap.h>
356 #include <linux/regulator/consumer.h>
357 @@ -193,31 +192,6 @@ core_clear(struct mt7530_priv *priv, u32
358 }
359
360 static int
361 -mt7530_regmap_write(void *context, unsigned int reg, unsigned int val)
362 -{
363 - struct mii_bus *bus = context;
364 - u16 page, r, lo, hi;
365 - int ret;
366 -
367 - page = (reg >> 6) & 0x3ff;
368 - r = (reg >> 2) & 0xf;
369 - lo = val & 0xffff;
370 - hi = val >> 16;
371 -
372 - /* MT7530 uses 31 as the pseudo port */
373 - ret = bus->write(bus, 0x1f, 0x1f, page);
374 - if (ret < 0)
375 - return ret;
376 -
377 - ret = bus->write(bus, 0x1f, r, lo);
378 - if (ret < 0)
379 - return ret;
380 -
381 - ret = bus->write(bus, 0x1f, 0x10, hi);
382 - return ret;
383 -}
384 -
385 -static int
386 mt7530_mii_write(struct mt7530_priv *priv, u32 reg, u32 val)
387 {
388 int ret;
389 @@ -231,29 +205,6 @@ mt7530_mii_write(struct mt7530_priv *pri
390 return ret;
391 }
392
393 -static int
394 -mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val)
395 -{
396 - struct mii_bus *bus = context;
397 - u16 page, r, lo, hi;
398 - int ret;
399 -
400 - page = (reg >> 6) & 0x3ff;
401 - r = (reg >> 2) & 0xf;
402 -
403 - /* MT7530 uses 31 as the pseudo port */
404 - ret = bus->write(bus, 0x1f, 0x1f, page);
405 - if (ret < 0)
406 - return ret;
407 -
408 - lo = bus->read(bus, 0x1f, r);
409 - hi = bus->read(bus, 0x1f, 0x10);
410 -
411 - *val = (hi << 16) | (lo & 0xffff);
412 -
413 - return 0;
414 -}
415 -
416 static u32
417 mt7530_mii_read(struct mt7530_priv *priv, u32 reg)
418 {
419 @@ -3164,72 +3115,6 @@ static const struct phylink_pcs_ops mt75
420 .pcs_an_restart = mt7530_pcs_an_restart,
421 };
422
423 -static void
424 -mt7530_mdio_regmap_lock(void *mdio_lock)
425 -{
426 - mutex_lock_nested(mdio_lock, MDIO_MUTEX_NESTED);
427 -}
428 -
429 -static void
430 -mt7530_mdio_regmap_unlock(void *mdio_lock)
431 -{
432 - mutex_unlock(mdio_lock);
433 -}
434 -
435 -static const struct regmap_bus mt7530_regmap_bus = {
436 - .reg_write = mt7530_regmap_write,
437 - .reg_read = mt7530_regmap_read,
438 -};
439 -
440 -static int
441 -mt7531_create_sgmii(struct mt7530_priv *priv)
442 -{
443 - struct regmap_config *mt7531_pcs_config[2];
444 - struct phylink_pcs *pcs;
445 - struct regmap *regmap;
446 - int i, ret = 0;
447 -
448 - for (i = 0; i < 2; i++) {
449 - mt7531_pcs_config[i] = devm_kzalloc(priv->dev,
450 - sizeof(struct regmap_config),
451 - GFP_KERNEL);
452 - if (!mt7531_pcs_config[i]) {
453 - ret = -ENOMEM;
454 - break;
455 - }
456 -
457 - mt7531_pcs_config[i]->name = i ? "port6" : "port5";
458 - mt7531_pcs_config[i]->reg_bits = 16;
459 - mt7531_pcs_config[i]->val_bits = 32;
460 - mt7531_pcs_config[i]->reg_stride = 4;
461 - mt7531_pcs_config[i]->reg_base = MT7531_SGMII_REG_BASE(5 + i);
462 - mt7531_pcs_config[i]->max_register = 0x17c;
463 - mt7531_pcs_config[i]->lock = mt7530_mdio_regmap_lock;
464 - mt7531_pcs_config[i]->unlock = mt7530_mdio_regmap_unlock;
465 - mt7531_pcs_config[i]->lock_arg = &priv->bus->mdio_lock;
466 -
467 - regmap = devm_regmap_init(priv->dev,
468 - &mt7530_regmap_bus, priv->bus,
469 - mt7531_pcs_config[i]);
470 - if (IS_ERR(regmap)) {
471 - ret = PTR_ERR(regmap);
472 - break;
473 - }
474 - pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
475 - MT7531_PHYA_CTRL_SIGNAL3, 0);
476 - if (!pcs) {
477 - ret = -ENXIO;
478 - break;
479 - }
480 - priv->ports[5 + i].sgmii_pcs = pcs;
481 - }
482 -
483 - if (ret && i)
484 - mtk_pcs_lynxi_destroy(priv->ports[5].sgmii_pcs);
485 -
486 - return ret;
487 -}
488 -
489 static int
490 mt753x_setup(struct dsa_switch *ds)
491 {
492 @@ -3288,7 +3173,7 @@ static int mt753x_set_mac_eee(struct dsa
493 return 0;
494 }
495
496 -static const struct dsa_switch_ops mt7530_switch_ops = {
497 +const struct dsa_switch_ops mt7530_switch_ops = {
498 .get_tag_protocol = mtk_get_tag_protocol,
499 .setup = mt753x_setup,
500 .get_strings = mt7530_get_strings,
501 @@ -3322,8 +3207,9 @@ static const struct dsa_switch_ops mt753
502 .get_mac_eee = mt753x_get_mac_eee,
503 .set_mac_eee = mt753x_set_mac_eee,
504 };
505 +EXPORT_SYMBOL_GPL(mt7530_switch_ops);
506
507 -static const struct mt753x_info mt753x_table[] = {
508 +const struct mt753x_info mt753x_table[] = {
509 [ID_MT7621] = {
510 .id = ID_MT7621,
511 .pcs_ops = &mt7530_pcs_ops,
512 @@ -3356,16 +3242,9 @@ static const struct mt753x_info mt753x_t
513 .mac_port_config = mt7531_mac_config,
514 },
515 };
516 +EXPORT_SYMBOL_GPL(mt753x_table);
517
518 -static const struct of_device_id mt7530_of_match[] = {
519 - { .compatible = "mediatek,mt7621", .data = &mt753x_table[ID_MT7621], },
520 - { .compatible = "mediatek,mt7530", .data = &mt753x_table[ID_MT7530], },
521 - { .compatible = "mediatek,mt7531", .data = &mt753x_table[ID_MT7531], },
522 - { /* sentinel */ },
523 -};
524 -MODULE_DEVICE_TABLE(of, mt7530_of_match);
525 -
526 -static int
527 +int
528 mt7530_probe_common(struct mt7530_priv *priv)
529 {
530 struct device *dev = priv->dev;
531 @@ -3402,88 +3281,9 @@ mt7530_probe_common(struct mt7530_priv *
532
533 return 0;
534 }
535 +EXPORT_SYMBOL_GPL(mt7530_probe_common);
536
537 -static int
538 -mt7530_probe(struct mdio_device *mdiodev)
539 -{
540 - static struct regmap_config *regmap_config;
541 - struct mt7530_priv *priv;
542 - struct device_node *dn;
543 - int ret;
544 -
545 - dn = mdiodev->dev.of_node;
546 -
547 - priv = devm_kzalloc(&mdiodev->dev, sizeof(*priv), GFP_KERNEL);
548 - if (!priv)
549 - return -ENOMEM;
550 -
551 - priv->bus = mdiodev->bus;
552 - priv->dev = &mdiodev->dev;
553 -
554 - ret = mt7530_probe_common(priv);
555 - if (ret)
556 - return ret;
557 -
558 - /* Use medatek,mcm property to distinguish hardware type that would
559 - * cause a little bit differences on power-on sequence.
560 - * Not MCM that indicates switch works as the remote standalone
561 - * integrated circuit so the GPIO pin would be used to complete
562 - * the reset, otherwise memory-mapped register accessing used
563 - * through syscon provides in the case of MCM.
564 - */
565 - priv->mcm = of_property_read_bool(dn, "mediatek,mcm");
566 - if (priv->mcm) {
567 - dev_info(&mdiodev->dev, "MT7530 adapts as multi-chip module\n");
568 -
569 - priv->rstc = devm_reset_control_get(&mdiodev->dev, "mcm");
570 - if (IS_ERR(priv->rstc)) {
571 - dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
572 - return PTR_ERR(priv->rstc);
573 - }
574 - } else {
575 - priv->reset = devm_gpiod_get_optional(&mdiodev->dev, "reset",
576 - GPIOD_OUT_LOW);
577 - if (IS_ERR(priv->reset)) {
578 - dev_err(&mdiodev->dev, "Couldn't get our reset line\n");
579 - return PTR_ERR(priv->reset);
580 - }
581 - }
582 -
583 - if (priv->id == ID_MT7530) {
584 - priv->core_pwr = devm_regulator_get(&mdiodev->dev, "core");
585 - if (IS_ERR(priv->core_pwr))
586 - return PTR_ERR(priv->core_pwr);
587 -
588 - priv->io_pwr = devm_regulator_get(&mdiodev->dev, "io");
589 - if (IS_ERR(priv->io_pwr))
590 - return PTR_ERR(priv->io_pwr);
591 - }
592 -
593 - regmap_config = devm_kzalloc(&mdiodev->dev, sizeof(*regmap_config),
594 - GFP_KERNEL);
595 - if (!regmap_config)
596 - return -ENOMEM;
597 -
598 - regmap_config->reg_bits = 16;
599 - regmap_config->val_bits = 32;
600 - regmap_config->reg_stride = 4;
601 - regmap_config->max_register = MT7530_CREV;
602 - regmap_config->disable_locking = true;
603 - priv->regmap = devm_regmap_init(priv->dev, &mt7530_regmap_bus,
604 - priv->bus, regmap_config);
605 - if (IS_ERR(priv->regmap))
606 - return PTR_ERR(priv->regmap);
607 -
608 - if (priv->id == ID_MT7531) {
609 - ret = mt7531_create_sgmii(priv);
610 - if (ret)
611 - return ret;
612 - }
613 -
614 - return dsa_register_switch(priv->ds);
615 -}
616 -
617 -static void
618 +void
619 mt7530_remove_common(struct mt7530_priv *priv)
620 {
621 if (priv->irq)
622 @@ -3494,57 +3294,6 @@ mt7530_remove_common(struct mt7530_priv
623 mutex_destroy(&priv->reg_mutex);
624 }
625
626 -static void
627 -mt7530_remove(struct mdio_device *mdiodev)
628 -{
629 - struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev);
630 - int ret = 0, i;
631 -
632 - if (!priv)
633 - return;
634 -
635 - ret = regulator_disable(priv->core_pwr);
636 - if (ret < 0)
637 - dev_err(priv->dev,
638 - "Failed to disable core power: %d\n", ret);
639 -
640 - ret = regulator_disable(priv->io_pwr);
641 - if (ret < 0)
642 - dev_err(priv->dev, "Failed to disable io pwr: %d\n",
643 - ret);
644 -
645 - mt7530_remove_common(priv);
646 -
647 - for (i = 0; i < 2; ++i)
648 - mtk_pcs_lynxi_destroy(priv->ports[5 + i].sgmii_pcs);
649 -
650 - dev_set_drvdata(&mdiodev->dev, NULL);
651 -}
652 -
653 -static void mt7530_shutdown(struct mdio_device *mdiodev)
654 -{
655 - struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev);
656 -
657 - if (!priv)
658 - return;
659 -
660 - dsa_switch_shutdown(priv->ds);
661 -
662 - dev_set_drvdata(&mdiodev->dev, NULL);
663 -}
664 -
665 -static struct mdio_driver mt7530_mdio_driver = {
666 - .probe = mt7530_probe,
667 - .remove = mt7530_remove,
668 - .shutdown = mt7530_shutdown,
669 - .mdiodrv.driver = {
670 - .name = "mt7530",
671 - .of_match_table = mt7530_of_match,
672 - },
673 -};
674 -
675 -mdio_module_driver(mt7530_mdio_driver);
676 -
677 MODULE_AUTHOR("Sean Wang <sean.wang@mediatek.com>");
678 MODULE_DESCRIPTION("Driver for Mediatek MT7530 Switch");
679 MODULE_LICENSE("GPL");
680 --- a/drivers/net/dsa/mt7530.h
681 +++ b/drivers/net/dsa/mt7530.h
682 @@ -839,4 +839,10 @@ static inline void INIT_MT7530_DUMMY_POL
683 p->reg = reg;
684 }
685
686 +int mt7530_probe_common(struct mt7530_priv *priv);
687 +void mt7530_remove_common(struct mt7530_priv *priv);
688 +
689 +extern const struct dsa_switch_ops mt7530_switch_ops;
690 +extern const struct mt753x_info mt753x_table[];
691 +
692 #endif /* __MT7530_H */