790-v6.4-0010-net-dsa-mt7530-introduce-separate-MDIO-driver.patch 18 KB

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