bcmmii.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Broadcom GENET MDIO routines
  4. *
  5. * Copyright (c) 2014-2025 Broadcom
  6. */
  7. #include <linux/acpi.h>
  8. #include <linux/types.h>
  9. #include <linux/delay.h>
  10. #include <linux/wait.h>
  11. #include <linux/mii.h>
  12. #include <linux/ethtool.h>
  13. #include <linux/bitops.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/phy.h>
  17. #include <linux/phy_fixed.h>
  18. #include <linux/brcmphy.h>
  19. #include <linux/of.h>
  20. #include <linux/of_net.h>
  21. #include <linux/of_mdio.h>
  22. #include <linux/platform_data/mdio-bcm-unimac.h>
  23. #include "bcmgenet.h"
  24. static void bcmgenet_mac_config(struct net_device *dev)
  25. {
  26. struct bcmgenet_priv *priv = netdev_priv(dev);
  27. struct phy_device *phydev = dev->phydev;
  28. u32 reg, cmd_bits = 0;
  29. /* speed */
  30. if (phydev->speed == SPEED_1000)
  31. cmd_bits = CMD_SPEED_1000;
  32. else if (phydev->speed == SPEED_100)
  33. cmd_bits = CMD_SPEED_100;
  34. else
  35. cmd_bits = CMD_SPEED_10;
  36. cmd_bits <<= CMD_SPEED_SHIFT;
  37. /* duplex */
  38. if (phydev->duplex != DUPLEX_FULL) {
  39. cmd_bits |= CMD_HD_EN |
  40. CMD_RX_PAUSE_IGNORE | CMD_TX_PAUSE_IGNORE;
  41. } else {
  42. /* pause capability defaults to Symmetric */
  43. if (priv->autoneg_pause) {
  44. bool tx_pause = 0, rx_pause = 0;
  45. if (phydev->autoneg)
  46. phy_get_pause(phydev, &tx_pause, &rx_pause);
  47. if (!tx_pause)
  48. cmd_bits |= CMD_TX_PAUSE_IGNORE;
  49. if (!rx_pause)
  50. cmd_bits |= CMD_RX_PAUSE_IGNORE;
  51. }
  52. /* Manual override */
  53. if (!priv->rx_pause)
  54. cmd_bits |= CMD_RX_PAUSE_IGNORE;
  55. if (!priv->tx_pause)
  56. cmd_bits |= CMD_TX_PAUSE_IGNORE;
  57. }
  58. /* Program UMAC and RGMII block based on established
  59. * link speed, duplex, and pause. The speed set in
  60. * umac->cmd tell RGMII block which clock to use for
  61. * transmit -- 25MHz(100Mbps) or 125MHz(1Gbps).
  62. * Receive clock is provided by the PHY.
  63. */
  64. reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL);
  65. reg |= RGMII_LINK;
  66. bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
  67. spin_lock_bh(&priv->reg_lock);
  68. reg = bcmgenet_umac_readl(priv, UMAC_CMD);
  69. reg &= ~((CMD_SPEED_MASK << CMD_SPEED_SHIFT) |
  70. CMD_HD_EN |
  71. CMD_RX_PAUSE_IGNORE | CMD_TX_PAUSE_IGNORE);
  72. reg |= cmd_bits;
  73. if (reg & CMD_SW_RESET) {
  74. reg &= ~CMD_SW_RESET;
  75. bcmgenet_umac_writel(priv, reg, UMAC_CMD);
  76. udelay(2);
  77. reg |= CMD_TX_EN | CMD_RX_EN;
  78. }
  79. bcmgenet_umac_writel(priv, reg, UMAC_CMD);
  80. spin_unlock_bh(&priv->reg_lock);
  81. }
  82. /* setup netdev link state when PHY link status change and
  83. * update UMAC and RGMII block when link up
  84. */
  85. void bcmgenet_mii_setup(struct net_device *dev)
  86. {
  87. struct bcmgenet_priv *priv = netdev_priv(dev);
  88. struct phy_device *phydev = dev->phydev;
  89. u32 reg;
  90. if (phydev->link) {
  91. bcmgenet_mac_config(dev);
  92. } else {
  93. reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL);
  94. reg &= ~RGMII_LINK;
  95. bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
  96. }
  97. bcmgenet_eee_enable_set(dev, phydev->enable_tx_lpi);
  98. phy_print_status(phydev);
  99. }
  100. static int bcmgenet_fixed_phy_link_update(struct net_device *dev,
  101. struct fixed_phy_status *status)
  102. {
  103. struct bcmgenet_priv *priv;
  104. u32 reg;
  105. if (dev && dev->phydev && status) {
  106. priv = netdev_priv(dev);
  107. reg = bcmgenet_umac_readl(priv, UMAC_MODE);
  108. status->link = !!(reg & MODE_LINK_STATUS);
  109. }
  110. return 0;
  111. }
  112. void bcmgenet_phy_pause_set(struct net_device *dev, bool rx, bool tx)
  113. {
  114. struct phy_device *phydev = dev->phydev;
  115. linkmode_mod_bit(ETHTOOL_LINK_MODE_Pause_BIT, phydev->advertising, rx);
  116. linkmode_mod_bit(ETHTOOL_LINK_MODE_Asym_Pause_BIT, phydev->advertising,
  117. rx | tx);
  118. phy_start_aneg(phydev);
  119. mutex_lock(&phydev->lock);
  120. if (phydev->link)
  121. bcmgenet_mac_config(dev);
  122. mutex_unlock(&phydev->lock);
  123. }
  124. void bcmgenet_phy_power_set(struct net_device *dev, bool enable)
  125. {
  126. struct bcmgenet_priv *priv = netdev_priv(dev);
  127. u32 reg = 0;
  128. /* EXT_GPHY_CTRL is only valid for GENETv4 and onward */
  129. if (GENET_IS_V4(priv) || bcmgenet_has_ephy_16nm(priv)) {
  130. reg = bcmgenet_ext_readl(priv, EXT_GPHY_CTRL);
  131. if (enable) {
  132. reg &= ~EXT_CK25_DIS;
  133. bcmgenet_ext_writel(priv, reg, EXT_GPHY_CTRL);
  134. mdelay(1);
  135. reg &= ~(EXT_CFG_IDDQ_BIAS | EXT_CFG_PWR_DOWN |
  136. EXT_CFG_IDDQ_GLOBAL_PWR);
  137. reg |= EXT_GPHY_RESET;
  138. bcmgenet_ext_writel(priv, reg, EXT_GPHY_CTRL);
  139. mdelay(1);
  140. reg &= ~EXT_GPHY_RESET;
  141. } else {
  142. reg |= EXT_GPHY_RESET;
  143. bcmgenet_ext_writel(priv, reg, EXT_GPHY_CTRL);
  144. mdelay(1);
  145. reg |= EXT_CFG_IDDQ_BIAS | EXT_CFG_PWR_DOWN |
  146. EXT_CFG_IDDQ_GLOBAL_PWR;
  147. bcmgenet_ext_writel(priv, reg, EXT_GPHY_CTRL);
  148. mdelay(1);
  149. reg |= EXT_CK25_DIS;
  150. }
  151. bcmgenet_ext_writel(priv, reg, EXT_GPHY_CTRL);
  152. udelay(60);
  153. } else {
  154. mdelay(1);
  155. }
  156. }
  157. static void bcmgenet_moca_phy_setup(struct bcmgenet_priv *priv)
  158. {
  159. if (bcmgenet_has_moca_link_det(priv))
  160. fixed_phy_set_link_update(priv->dev->phydev,
  161. bcmgenet_fixed_phy_link_update);
  162. }
  163. int bcmgenet_mii_config(struct net_device *dev, bool init)
  164. {
  165. struct bcmgenet_priv *priv = netdev_priv(dev);
  166. struct phy_device *phydev = dev->phydev;
  167. struct device *kdev = &priv->pdev->dev;
  168. const char *phy_name = NULL;
  169. u32 id_mode_dis = 0;
  170. u32 port_ctrl;
  171. u32 reg;
  172. switch (priv->phy_interface) {
  173. case PHY_INTERFACE_MODE_INTERNAL:
  174. phy_name = "internal PHY";
  175. fallthrough;
  176. case PHY_INTERFACE_MODE_MOCA:
  177. /* Irrespective of the actually configured PHY speed (100 or
  178. * 1000) GENETv4 only has an internal GPHY so we will just end
  179. * up masking the Gigabit features from what we support, not
  180. * switching to the EPHY
  181. */
  182. if (GENET_IS_V4(priv))
  183. port_ctrl = PORT_MODE_INT_GPHY;
  184. else
  185. port_ctrl = PORT_MODE_INT_EPHY;
  186. if (!phy_name) {
  187. phy_name = "MoCA";
  188. if (!GENET_IS_V5(priv))
  189. port_ctrl |= LED_ACT_SOURCE_MAC;
  190. bcmgenet_moca_phy_setup(priv);
  191. }
  192. break;
  193. case PHY_INTERFACE_MODE_MII:
  194. phy_name = "external MII";
  195. phy_set_max_speed(phydev, SPEED_100);
  196. port_ctrl = PORT_MODE_EXT_EPHY;
  197. break;
  198. case PHY_INTERFACE_MODE_REVMII:
  199. phy_name = "external RvMII";
  200. /* of_mdiobus_register took care of reading the 'max-speed'
  201. * PHY property for us, effectively limiting the PHY supported
  202. * capabilities, use that knowledge to also configure the
  203. * Reverse MII interface correctly.
  204. */
  205. if (linkmode_test_bit(ETHTOOL_LINK_MODE_1000baseT_Full_BIT,
  206. dev->phydev->supported))
  207. port_ctrl = PORT_MODE_EXT_RVMII_50;
  208. else
  209. port_ctrl = PORT_MODE_EXT_RVMII_25;
  210. break;
  211. case PHY_INTERFACE_MODE_RGMII:
  212. /* RGMII_NO_ID: TXC transitions at the same time as TXD
  213. * (requires PCB or receiver-side delay)
  214. *
  215. * ID is implicitly disabled for 100Mbps (RG)MII operation.
  216. */
  217. phy_name = "external RGMII (no delay)";
  218. id_mode_dis = BIT(16);
  219. port_ctrl = PORT_MODE_EXT_GPHY;
  220. break;
  221. case PHY_INTERFACE_MODE_RGMII_TXID:
  222. /* RGMII_TXID: Add 2ns delay on TXC (90 degree shift) */
  223. phy_name = "external RGMII (TX delay)";
  224. port_ctrl = PORT_MODE_EXT_GPHY;
  225. break;
  226. case PHY_INTERFACE_MODE_RGMII_RXID:
  227. phy_name = "external RGMII (RX delay)";
  228. port_ctrl = PORT_MODE_EXT_GPHY;
  229. break;
  230. default:
  231. dev_err(kdev, "unknown phy mode: %d\n", priv->phy_interface);
  232. return -EINVAL;
  233. }
  234. bcmgenet_sys_writel(priv, port_ctrl, SYS_PORT_CTRL);
  235. priv->ext_phy = !priv->internal_phy &&
  236. (priv->phy_interface != PHY_INTERFACE_MODE_MOCA);
  237. /* This is an external PHY (xMII), so we need to enable the RGMII
  238. * block for the interface to work, unconditionally clear the
  239. * Out-of-band disable since we do not need it.
  240. */
  241. mutex_lock(&phydev->lock);
  242. reg = bcmgenet_ext_readl(priv, EXT_RGMII_OOB_CTRL);
  243. reg &= ~OOB_DISABLE;
  244. if (priv->ext_phy) {
  245. reg &= ~ID_MODE_DIS;
  246. reg |= id_mode_dis;
  247. if (GENET_IS_V1(priv) || GENET_IS_V2(priv) || GENET_IS_V3(priv))
  248. reg |= RGMII_MODE_EN_V123;
  249. else
  250. reg |= RGMII_MODE_EN;
  251. }
  252. bcmgenet_ext_writel(priv, reg, EXT_RGMII_OOB_CTRL);
  253. mutex_unlock(&phydev->lock);
  254. if (init)
  255. dev_info(kdev, "configuring instance for %s\n", phy_name);
  256. return 0;
  257. }
  258. int bcmgenet_mii_probe(struct net_device *dev)
  259. {
  260. struct bcmgenet_priv *priv = netdev_priv(dev);
  261. struct device *kdev = &priv->pdev->dev;
  262. struct device_node *dn = kdev->of_node;
  263. phy_interface_t phy_iface = priv->phy_interface;
  264. struct phy_device *phydev;
  265. u32 phy_flags = PHY_BRCM_AUTO_PWRDWN_ENABLE |
  266. PHY_BRCM_DIS_TXCRXC_NOENRGY |
  267. PHY_BRCM_IDDQ_SUSPEND;
  268. int ret;
  269. /* Communicate the integrated PHY revision */
  270. if (priv->internal_phy)
  271. phy_flags = priv->gphy_rev;
  272. /* This is an ugly quirk but we have not been correctly interpreting
  273. * the phy_interface values and we have done that across different
  274. * drivers, so at least we are consistent in our mistakes.
  275. *
  276. * When the Generic PHY driver is in use either the PHY has been
  277. * strapped or programmed correctly by the boot loader so we should
  278. * stick to our incorrect interpretation since we have validated it.
  279. *
  280. * Now when a dedicated PHY driver is in use, we need to reverse the
  281. * meaning of the phy_interface_mode values to something that the PHY
  282. * driver will interpret and act on such that we have two mistakes
  283. * canceling themselves so to speak. We only do this for the two
  284. * modes that GENET driver officially supports on Broadcom STB chips:
  285. * PHY_INTERFACE_MODE_RGMII and PHY_INTERFACE_MODE_RGMII_TXID. Other
  286. * modes are not *officially* supported with the boot loader and the
  287. * scripted environment generating Device Tree blobs for those
  288. * platforms.
  289. *
  290. * Note that internal PHY, MoCA and fixed-link configurations are not
  291. * affected because they use different phy_interface_t values or the
  292. * Generic PHY driver.
  293. */
  294. switch (priv->phy_interface) {
  295. case PHY_INTERFACE_MODE_RGMII:
  296. phy_iface = PHY_INTERFACE_MODE_RGMII_ID;
  297. break;
  298. case PHY_INTERFACE_MODE_RGMII_TXID:
  299. phy_iface = PHY_INTERFACE_MODE_RGMII_RXID;
  300. break;
  301. default:
  302. break;
  303. }
  304. if (dn) {
  305. phydev = of_phy_connect(dev, priv->phy_dn, bcmgenet_mii_setup,
  306. phy_flags, phy_iface);
  307. if (!phydev) {
  308. pr_err("could not attach to PHY\n");
  309. return -ENODEV;
  310. }
  311. } else {
  312. if (has_acpi_companion(kdev)) {
  313. char mdio_bus_id[MII_BUS_ID_SIZE];
  314. struct mii_bus *unimacbus;
  315. snprintf(mdio_bus_id, MII_BUS_ID_SIZE, "%s-%d",
  316. UNIMAC_MDIO_DRV_NAME, priv->pdev->id);
  317. unimacbus = mdio_find_bus(mdio_bus_id);
  318. if (!unimacbus) {
  319. pr_err("Unable to find mii\n");
  320. return -ENODEV;
  321. }
  322. phydev = phy_find_first(unimacbus);
  323. put_device(&unimacbus->dev);
  324. if (!phydev) {
  325. pr_err("Unable to find PHY\n");
  326. return -ENODEV;
  327. }
  328. } else {
  329. phydev = dev->phydev;
  330. }
  331. phydev->dev_flags = phy_flags;
  332. ret = phy_connect_direct(dev, phydev, bcmgenet_mii_setup,
  333. phy_iface);
  334. if (ret) {
  335. pr_err("could not attach to PHY\n");
  336. return -ENODEV;
  337. }
  338. }
  339. /* Configure port multiplexer based on what the probed PHY device since
  340. * reading the 'max-speed' property determines the maximum supported
  341. * PHY speed which is needed for bcmgenet_mii_config() to configure
  342. * things appropriately.
  343. */
  344. ret = bcmgenet_mii_config(dev, true);
  345. if (ret) {
  346. phy_disconnect(dev->phydev);
  347. return ret;
  348. }
  349. /* The internal PHY has its link interrupts routed to the
  350. * Ethernet MAC ISRs. On GENETv5 there is a hardware issue
  351. * that prevents the signaling of link UP interrupts when
  352. * the link operates at 10Mbps, so fallback to polling for
  353. * those versions of GENET.
  354. */
  355. if (priv->internal_phy && !GENET_IS_V5(priv))
  356. dev->phydev->irq = PHY_MAC_INTERRUPT;
  357. /* Indicate that the MAC is responsible for PHY PM */
  358. dev->phydev->mac_managed_pm = true;
  359. if (!GENET_IS_V1(priv))
  360. phy_support_eee(dev->phydev);
  361. return 0;
  362. }
  363. static struct device_node *bcmgenet_mii_of_find_mdio(struct bcmgenet_priv *priv)
  364. {
  365. struct device_node *dn = priv->pdev->dev.of_node;
  366. struct device *kdev = &priv->pdev->dev;
  367. char *compat;
  368. compat = kasprintf(GFP_KERNEL, "brcm,genet-mdio-v%d", priv->version);
  369. if (!compat)
  370. return NULL;
  371. priv->mdio_dn = of_get_compatible_child(dn, compat);
  372. kfree(compat);
  373. if (!priv->mdio_dn) {
  374. dev_err(kdev, "unable to find MDIO bus node\n");
  375. return NULL;
  376. }
  377. return priv->mdio_dn;
  378. }
  379. static int bcmgenet_mii_wait(void *wait_func_data)
  380. {
  381. struct bcmgenet_priv *priv = wait_func_data;
  382. wait_event_timeout(priv->wq,
  383. !(bcmgenet_umac_readl(priv, UMAC_MDIO_CMD)
  384. & MDIO_START_BUSY),
  385. HZ / 100);
  386. return 0;
  387. }
  388. static int bcmgenet_mii_register(struct bcmgenet_priv *priv)
  389. {
  390. struct platform_device *pdev = priv->pdev;
  391. struct device_node *dn = pdev->dev.of_node;
  392. struct unimac_mdio_pdata ppd;
  393. struct platform_device *ppdev;
  394. struct resource *pres, res;
  395. int id, ret;
  396. pres = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  397. if (!pres) {
  398. dev_err(&pdev->dev, "Invalid resource\n");
  399. return -EINVAL;
  400. }
  401. memset(&res, 0, sizeof(res));
  402. memset(&ppd, 0, sizeof(ppd));
  403. ppd.wait_func = bcmgenet_mii_wait;
  404. ppd.wait_func_data = priv;
  405. ppd.bus_name = "bcmgenet MII bus";
  406. /* Pass a reference to our "main" clock which is used for MDIO
  407. * transfers
  408. */
  409. ppd.clk = priv->clk;
  410. /* Unimac MDIO bus controller starts at UniMAC offset + MDIO_CMD
  411. * and is 2 * 32-bits word long, 8 bytes total.
  412. */
  413. res.start = pres->start + GENET_UMAC_OFF + UMAC_MDIO_CMD;
  414. res.end = res.start + 8;
  415. res.flags = IORESOURCE_MEM;
  416. if (dn)
  417. id = of_alias_get_id(dn, "eth");
  418. else
  419. id = pdev->id;
  420. ppdev = platform_device_alloc(UNIMAC_MDIO_DRV_NAME, id);
  421. if (!ppdev)
  422. return -ENOMEM;
  423. /* Retain this platform_device pointer for later cleanup */
  424. priv->mii_pdev = ppdev;
  425. ppdev->dev.parent = &pdev->dev;
  426. if (dn)
  427. ppdev->dev.of_node = bcmgenet_mii_of_find_mdio(priv);
  428. else
  429. ppd.phy_mask = ~0;
  430. ret = platform_device_add_resources(ppdev, &res, 1);
  431. if (ret)
  432. goto out;
  433. ret = platform_device_add_data(ppdev, &ppd, sizeof(ppd));
  434. if (ret)
  435. goto out;
  436. ret = platform_device_add(ppdev);
  437. if (ret)
  438. goto out;
  439. return 0;
  440. out:
  441. platform_device_put(ppdev);
  442. return ret;
  443. }
  444. static int bcmgenet_phy_interface_init(struct bcmgenet_priv *priv)
  445. {
  446. struct device *kdev = &priv->pdev->dev;
  447. int phy_mode = device_get_phy_mode(kdev);
  448. if (phy_mode < 0) {
  449. dev_err(kdev, "invalid PHY mode property\n");
  450. return phy_mode;
  451. }
  452. priv->phy_interface = phy_mode;
  453. /* We need to specifically look up whether this PHY interface is
  454. * internal or not *before* we even try to probe the PHY driver
  455. * over MDIO as we may have shut down the internal PHY for power
  456. * saving purposes.
  457. */
  458. if (priv->phy_interface == PHY_INTERFACE_MODE_INTERNAL)
  459. priv->internal_phy = true;
  460. return 0;
  461. }
  462. static int bcmgenet_mii_of_init(struct bcmgenet_priv *priv)
  463. {
  464. struct device_node *dn = priv->pdev->dev.of_node;
  465. struct phy_device *phydev;
  466. int ret;
  467. /* Fetch the PHY phandle */
  468. priv->phy_dn = of_parse_phandle(dn, "phy-handle", 0);
  469. /* In the case of a fixed PHY, the DT node associated
  470. * to the PHY is the Ethernet MAC DT node.
  471. */
  472. if (!priv->phy_dn && of_phy_is_fixed_link(dn)) {
  473. ret = of_phy_register_fixed_link(dn);
  474. if (ret)
  475. return ret;
  476. priv->phy_dn = of_node_get(dn);
  477. }
  478. /* Get the link mode */
  479. ret = bcmgenet_phy_interface_init(priv);
  480. if (ret)
  481. return ret;
  482. /* Make sure we initialize MoCA PHYs with a link down */
  483. if (priv->phy_interface == PHY_INTERFACE_MODE_MOCA) {
  484. phydev = of_phy_find_device(dn);
  485. if (phydev) {
  486. phydev->link = 0;
  487. put_device(&phydev->mdio.dev);
  488. }
  489. }
  490. return 0;
  491. }
  492. static int bcmgenet_mii_bus_init(struct bcmgenet_priv *priv)
  493. {
  494. struct device *kdev = &priv->pdev->dev;
  495. struct device_node *dn = kdev->of_node;
  496. if (dn)
  497. return bcmgenet_mii_of_init(priv);
  498. else if (has_acpi_companion(kdev))
  499. return bcmgenet_phy_interface_init(priv);
  500. else
  501. return -EINVAL;
  502. }
  503. int bcmgenet_mii_init(struct net_device *dev)
  504. {
  505. struct bcmgenet_priv *priv = netdev_priv(dev);
  506. int ret;
  507. ret = bcmgenet_mii_register(priv);
  508. if (ret)
  509. return ret;
  510. ret = bcmgenet_mii_bus_init(priv);
  511. if (ret)
  512. goto out;
  513. return 0;
  514. out:
  515. bcmgenet_mii_exit(dev);
  516. return ret;
  517. }
  518. void bcmgenet_mii_exit(struct net_device *dev)
  519. {
  520. struct bcmgenet_priv *priv = netdev_priv(dev);
  521. struct device_node *dn = priv->pdev->dev.of_node;
  522. if (of_phy_is_fixed_link(dn))
  523. of_phy_deregister_fixed_link(dn);
  524. of_node_put(priv->phy_dn);
  525. platform_device_unregister(priv->mii_pdev);
  526. }