blob: fdf8221f46fa577174e8744b26856fabcd9f36eb [file] [log] [blame]
b.liue9582032025-04-17 19:18:16 +08001// SPDX-License-Identifier: GPL-2.0+
2/* MDIO Bus interface
3 *
4 * Author: Andy Fleming
5 *
6 * Copyright (c) 2004 Freescale Semiconductor, Inc.
7 */
8
9#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10
11#include <linux/kernel.h>
12#include <linux/string.h>
13#include <linux/errno.h>
14#include <linux/unistd.h>
15#include <linux/slab.h>
16#include <linux/interrupt.h>
17#include <linux/init.h>
18#include <linux/delay.h>
19#include <linux/device.h>
20#include <linux/gpio.h>
21#include <linux/gpio/consumer.h>
22#include <linux/of_device.h>
23#include <linux/of_mdio.h>
24#include <linux/of_gpio.h>
25#include <linux/netdevice.h>
26#include <linux/etherdevice.h>
27#include <linux/reset.h>
28#include <linux/skbuff.h>
29#include <linux/spinlock.h>
30#include <linux/mm.h>
31#include <linux/module.h>
32#include <linux/mii.h>
33#include <linux/ethtool.h>
34#include <linux/phy.h>
35#include <linux/io.h>
36#include <linux/uaccess.h>
37
38#define CREATE_TRACE_POINTS
39#include <trace/events/mdio.h>
40
41#include "mdio-boardinfo.h"
42
43static int mdiobus_register_gpiod(struct mdio_device *mdiodev)
44{
45 int error;
46
47 /* Deassert the optional reset signal */
48 mdiodev->reset_gpio = gpiod_get_optional(&mdiodev->dev,
49 "reset", GPIOD_OUT_LOW);
50 error = PTR_ERR_OR_ZERO(mdiodev->reset_gpio);
51 if (error)
52 return error;
53
54 if (mdiodev->reset_gpio)
55 gpiod_set_consumer_name(mdiodev->reset_gpio, "PHY reset");
56
57 return 0;
58}
59
60static int mdiobus_register_reset(struct mdio_device *mdiodev)
61{
62 struct reset_control *reset = NULL;
63
64 if (mdiodev->dev.of_node)
65 reset = of_reset_control_get_exclusive(mdiodev->dev.of_node,
66 "phy");
67 if (IS_ERR(reset)) {
68 if (PTR_ERR(reset) == -ENOENT || PTR_ERR(reset) == -ENOTSUPP)
69 reset = NULL;
70 else
71 return PTR_ERR(reset);
72 }
73
74 mdiodev->reset_ctrl = reset;
75
76 return 0;
77}
78
79int mdiobus_register_device(struct mdio_device *mdiodev)
80{
81 int err;
82
83 if (mdiodev->bus->mdio_map[mdiodev->addr])
84 return -EBUSY;
85
86 if (mdiodev->flags & MDIO_DEVICE_FLAG_PHY) {
87 err = mdiobus_register_gpiod(mdiodev);
88 if (err)
89 return err;
90
91 err = mdiobus_register_reset(mdiodev);
92 if (err)
93 return err;
94
95 /* Assert the reset signal */
96 mdio_device_reset(mdiodev, 1);
97 }
98
99 mdiodev->bus->mdio_map[mdiodev->addr] = mdiodev;
100
101 return 0;
102}
103EXPORT_SYMBOL(mdiobus_register_device);
104
105int mdiobus_unregister_device(struct mdio_device *mdiodev)
106{
107 if (mdiodev->bus->mdio_map[mdiodev->addr] != mdiodev)
108 return -EINVAL;
109
110 reset_control_put(mdiodev->reset_ctrl);
111
112 mdiodev->bus->mdio_map[mdiodev->addr] = NULL;
113
114 return 0;
115}
116EXPORT_SYMBOL(mdiobus_unregister_device);
117
118struct phy_device *mdiobus_get_phy(struct mii_bus *bus, int addr)
119{
120 struct mdio_device *mdiodev;
121
122 if (addr < 0 || addr >= ARRAY_SIZE(bus->mdio_map))
123 return NULL;
124
125 mdiodev = bus->mdio_map[addr];
126
127 if (!mdiodev)
128 return NULL;
129
130 if (!(mdiodev->flags & MDIO_DEVICE_FLAG_PHY))
131 return NULL;
132
133 return container_of(mdiodev, struct phy_device, mdio);
134}
135EXPORT_SYMBOL(mdiobus_get_phy);
136
137bool mdiobus_is_registered_device(struct mii_bus *bus, int addr)
138{
139 return bus->mdio_map[addr];
140}
141EXPORT_SYMBOL(mdiobus_is_registered_device);
142
143/**
144 * mdiobus_alloc_size - allocate a mii_bus structure
145 * @size: extra amount of memory to allocate for private storage.
146 * If non-zero, then bus->priv is points to that memory.
147 *
148 * Description: called by a bus driver to allocate an mii_bus
149 * structure to fill in.
150 */
151struct mii_bus *mdiobus_alloc_size(size_t size)
152{
153 struct mii_bus *bus;
154 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
155 size_t alloc_size;
156 int i;
157
158 /* If we alloc extra space, it should be aligned */
159 if (size)
160 alloc_size = aligned_size + size;
161 else
162 alloc_size = sizeof(*bus);
163
164 bus = kzalloc(alloc_size, GFP_KERNEL);
165 if (!bus)
166 return NULL;
167
168 bus->state = MDIOBUS_ALLOCATED;
169 if (size)
170 bus->priv = (void *)bus + aligned_size;
171
172 /* Initialise the interrupts to polling */
173 for (i = 0; i < PHY_MAX_ADDR; i++)
174 bus->irq[i] = PHY_POLL;
175
176 return bus;
177}
178EXPORT_SYMBOL(mdiobus_alloc_size);
179
180static void _devm_mdiobus_free(struct device *dev, void *res)
181{
182 mdiobus_free(*(struct mii_bus **)res);
183}
184
185static int devm_mdiobus_match(struct device *dev, void *res, void *data)
186{
187 struct mii_bus **r = res;
188
189 if (WARN_ON(!r || !*r))
190 return 0;
191
192 return *r == data;
193}
194
195/**
196 * devm_mdiobus_alloc_size - Resource-managed mdiobus_alloc_size()
197 * @dev: Device to allocate mii_bus for
198 * @sizeof_priv: Space to allocate for private structure.
199 *
200 * Managed mdiobus_alloc_size. mii_bus allocated with this function is
201 * automatically freed on driver detach.
202 *
203 * If an mii_bus allocated with this function needs to be freed separately,
204 * devm_mdiobus_free() must be used.
205 *
206 * RETURNS:
207 * Pointer to allocated mii_bus on success, NULL on failure.
208 */
209struct mii_bus *devm_mdiobus_alloc_size(struct device *dev, int sizeof_priv)
210{
211 struct mii_bus **ptr, *bus;
212
213 ptr = devres_alloc(_devm_mdiobus_free, sizeof(*ptr), GFP_KERNEL);
214 if (!ptr)
215 return NULL;
216
217 /* use raw alloc_dr for kmalloc caller tracing */
218 bus = mdiobus_alloc_size(sizeof_priv);
219 if (bus) {
220 *ptr = bus;
221 devres_add(dev, ptr);
222 } else {
223 devres_free(ptr);
224 }
225
226 return bus;
227}
228EXPORT_SYMBOL_GPL(devm_mdiobus_alloc_size);
229
230/**
231 * devm_mdiobus_free - Resource-managed mdiobus_free()
232 * @dev: Device this mii_bus belongs to
233 * @bus: the mii_bus associated with the device
234 *
235 * Free mii_bus allocated with devm_mdiobus_alloc_size().
236 */
237void devm_mdiobus_free(struct device *dev, struct mii_bus *bus)
238{
239 int rc;
240
241 rc = devres_release(dev, _devm_mdiobus_free,
242 devm_mdiobus_match, bus);
243 WARN_ON(rc);
244}
245EXPORT_SYMBOL_GPL(devm_mdiobus_free);
246
247/**
248 * mdiobus_release - mii_bus device release callback
249 * @d: the target struct device that contains the mii_bus
250 *
251 * Description: called when the last reference to an mii_bus is
252 * dropped, to free the underlying memory.
253 */
254static void mdiobus_release(struct device *d)
255{
256 struct mii_bus *bus = to_mii_bus(d);
257 BUG_ON(bus->state != MDIOBUS_RELEASED &&
258 /* for compatibility with error handling in drivers */
259 bus->state != MDIOBUS_ALLOCATED);
260 kfree(bus);
261}
262
263static struct class mdio_bus_class = {
264 .name = "mdio_bus",
265 .dev_release = mdiobus_release,
266};
267
268#if IS_ENABLED(CONFIG_OF_MDIO)
269/**
270 * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
271 * @mdio_bus_np: Pointer to the mii_bus.
272 *
273 * Returns a reference to the mii_bus, or NULL if none found. The
274 * embedded struct device will have its reference count incremented,
275 * and this must be put once the bus is finished with.
276 *
277 * Because the association of a device_node and mii_bus is made via
278 * of_mdiobus_register(), the mii_bus cannot be found before it is
279 * registered with of_mdiobus_register().
280 *
281 */
282struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
283{
284 struct device *d;
285
286 if (!mdio_bus_np)
287 return NULL;
288
289 d = class_find_device_by_of_node(&mdio_bus_class, mdio_bus_np);
290 return d ? to_mii_bus(d) : NULL;
291}
292EXPORT_SYMBOL(of_mdio_find_bus);
293
294/* Walk the list of subnodes of a mdio bus and look for a node that
295 * matches the mdio device's address with its 'reg' property. If
296 * found, set the of_node pointer for the mdio device. This allows
297 * auto-probed phy devices to be supplied with information passed in
298 * via DT.
299 */
300static void of_mdiobus_link_mdiodev(struct mii_bus *bus,
301 struct mdio_device *mdiodev)
302{
303 struct device *dev = &mdiodev->dev;
304 struct device_node *child;
305
306 if (dev->of_node || !bus->dev.of_node)
307 return;
308
309 for_each_available_child_of_node(bus->dev.of_node, child) {
310 int addr;
311
312 addr = of_mdio_parse_addr(dev, child);
313 if (addr < 0)
314 continue;
315
316 if (addr == mdiodev->addr) {
317 dev->of_node = child;
318 dev->fwnode = of_fwnode_handle(child);
319 return;
320 }
321 }
322}
323#else /* !IS_ENABLED(CONFIG_OF_MDIO) */
324static inline void of_mdiobus_link_mdiodev(struct mii_bus *mdio,
325 struct mdio_device *mdiodev)
326{
327}
328#endif
329
330/**
331 * mdiobus_create_device_from_board_info - create a full MDIO device given
332 * a mdio_board_info structure
333 * @bus: MDIO bus to create the devices on
334 * @bi: mdio_board_info structure describing the devices
335 *
336 * Returns 0 on success or < 0 on error.
337 */
338static int mdiobus_create_device(struct mii_bus *bus,
339 struct mdio_board_info *bi)
340{
341 struct mdio_device *mdiodev;
342 int ret = 0;
343
344 mdiodev = mdio_device_create(bus, bi->mdio_addr);
345 if (IS_ERR(mdiodev))
346 return -ENODEV;
347
348 strncpy(mdiodev->modalias, bi->modalias,
349 sizeof(mdiodev->modalias));
350 mdiodev->bus_match = mdio_device_bus_match;
351 mdiodev->dev.platform_data = (void *)bi->platform_data;
352
353 ret = mdio_device_register(mdiodev);
354 if (ret)
355 mdio_device_free(mdiodev);
356
357 return ret;
358}
359
360/**
361 * __mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
362 * @bus: target mii_bus
363 * @owner: module containing bus accessor functions
364 *
365 * Description: Called by a bus driver to bring up all the PHYs
366 * on a given bus, and attach them to the bus. Drivers should use
367 * mdiobus_register() rather than __mdiobus_register() unless they
368 * need to pass a specific owner module. MDIO devices which are not
369 * PHYs will not be brought up by this function. They are expected to
370 * to be explicitly listed in DT and instantiated by of_mdiobus_register().
371 *
372 * Returns 0 on success or < 0 on error.
373 */
374int __mdiobus_register(struct mii_bus *bus, struct module *owner)
375{
376 struct mdio_device *mdiodev;
377 int i, err;
378 struct gpio_desc *gpiod;
379
380 if (NULL == bus || NULL == bus->name ||
381 NULL == bus->read || NULL == bus->write)
382 return -EINVAL;
383
384 BUG_ON(bus->state != MDIOBUS_ALLOCATED &&
385 bus->state != MDIOBUS_UNREGISTERED);
386
387 bus->owner = owner;
388 bus->dev.parent = bus->parent;
389 bus->dev.class = &mdio_bus_class;
390 bus->dev.groups = NULL;
391 dev_set_name(&bus->dev, "%s", bus->id);
392
393 /* We need to set state to MDIOBUS_UNREGISTERED to correctly release
394 * the device in mdiobus_free()
395 *
396 * State will be updated later in this function in case of success
397 */
398 bus->state = MDIOBUS_UNREGISTERED;
399
400 err = device_register(&bus->dev);
401 if (err) {
402 pr_err("mii_bus %s failed to register\n", bus->id);
403 return -EINVAL;
404 }
405
406 mutex_init(&bus->mdio_lock);
407
408 /* de-assert bus level PHY GPIO reset */
409 gpiod = devm_gpiod_get_optional(&bus->dev, "reset", GPIOD_OUT_LOW);
410 if (IS_ERR(gpiod)) {
411 dev_err(&bus->dev, "mii_bus %s couldn't get reset GPIO\n",
412 bus->id);
413 device_del(&bus->dev);
414 return PTR_ERR(gpiod);
415 } else if (gpiod) {
416 bus->reset_gpiod = gpiod;
417
418 gpiod_set_value_cansleep(gpiod, 1);
419 udelay(bus->reset_delay_us);
420 gpiod_set_value_cansleep(gpiod, 0);
421 }
422
423 if (bus->reset)
424 bus->reset(bus);
425
426 for (i = 0; i < PHY_MAX_ADDR; i++) {
427 if ((bus->phy_mask & BIT(i)) == 0) {
428 struct phy_device *phydev;
429
430 phydev = mdiobus_scan(bus, i);
431 if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV)) {
432 err = PTR_ERR(phydev);
433 goto error;
434 }
435 }
436 }
437
438 mdiobus_setup_mdiodev_from_board_info(bus, mdiobus_create_device);
439
440 bus->state = MDIOBUS_REGISTERED;
441 dev_dbg(&bus->dev, "probed\n");
442 return 0;
443
444error:
445 while (--i >= 0) {
446 mdiodev = bus->mdio_map[i];
447 if (!mdiodev)
448 continue;
449
450 mdiodev->device_remove(mdiodev);
451 mdiodev->device_free(mdiodev);
452 }
453
454 /* Put PHYs in RESET to save power */
455 if (bus->reset_gpiod)
456 gpiod_set_value_cansleep(bus->reset_gpiod, 1);
457
458 device_del(&bus->dev);
459 return err;
460}
461EXPORT_SYMBOL(__mdiobus_register);
462
463void mdiobus_unregister(struct mii_bus *bus)
464{
465 struct mdio_device *mdiodev;
466 int i;
467
468 if (WARN_ON_ONCE(bus->state != MDIOBUS_REGISTERED))
469 return;
470 bus->state = MDIOBUS_UNREGISTERED;
471
472 for (i = 0; i < PHY_MAX_ADDR; i++) {
473 mdiodev = bus->mdio_map[i];
474 if (!mdiodev)
475 continue;
476
477 if (mdiodev->reset_gpio)
478 gpiod_put(mdiodev->reset_gpio);
479
480 mdiodev->device_remove(mdiodev);
481 mdiodev->device_free(mdiodev);
482 }
483
484 /* Put PHYs in RESET to save power */
485 if (bus->reset_gpiod)
486 gpiod_set_value_cansleep(bus->reset_gpiod, 1);
487
488 device_del(&bus->dev);
489}
490EXPORT_SYMBOL(mdiobus_unregister);
491
492/**
493 * mdiobus_free - free a struct mii_bus
494 * @bus: mii_bus to free
495 *
496 * This function releases the reference to the underlying device
497 * object in the mii_bus. If this is the last reference, the mii_bus
498 * will be freed.
499 */
500void mdiobus_free(struct mii_bus *bus)
501{
502 /* For compatibility with error handling in drivers. */
503 if (bus->state == MDIOBUS_ALLOCATED) {
504 kfree(bus);
505 return;
506 }
507
508 BUG_ON(bus->state != MDIOBUS_UNREGISTERED);
509 bus->state = MDIOBUS_RELEASED;
510
511 put_device(&bus->dev);
512}
513EXPORT_SYMBOL(mdiobus_free);
514
515/**
516 * mdiobus_scan - scan a bus for MDIO devices.
517 * @bus: mii_bus to scan
518 * @addr: address on bus to scan
519 *
520 * This function scans the MDIO bus, looking for devices which can be
521 * identified using a vendor/product ID in registers 2 and 3. Not all
522 * MDIO devices have such registers, but PHY devices typically
523 * do. Hence this function assumes anything found is a PHY, or can be
524 * treated as a PHY. Other MDIO devices, such as switches, will
525 * probably not be found during the scan.
526 */
527struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
528{
529 struct phy_device *phydev;
530 int err;
531
532 phydev = get_phy_device(bus, addr, false);
533 if (IS_ERR(phydev))
534 return phydev;
535
536 /*
537 * For DT, see if the auto-probed phy has a correspoding child
538 * in the bus node, and set the of_node pointer in this case.
539 */
540 of_mdiobus_link_mdiodev(bus, &phydev->mdio);
541
542 err = phy_device_register(phydev);
543 if (err) {
544 phy_device_free(phydev);
545 return ERR_PTR(-ENODEV);
546 }
547
548 return phydev;
549}
550EXPORT_SYMBOL(mdiobus_scan);
551
552/**
553 * __mdiobus_read - Unlocked version of the mdiobus_read function
554 * @bus: the mii_bus struct
555 * @addr: the phy address
556 * @regnum: register number to read
557 *
558 * Read a MDIO bus register. Caller must hold the mdio bus lock.
559 *
560 * NOTE: MUST NOT be called from interrupt context.
561 */
562int __mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
563{
564 int retval;
565
566 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
567
568 retval = bus->read(bus, addr, regnum);
569
570 trace_mdio_access(bus, 1, addr, regnum, retval, retval);
571
572 return retval;
573}
574EXPORT_SYMBOL(__mdiobus_read);
575
576/**
577 * __mdiobus_write - Unlocked version of the mdiobus_write function
578 * @bus: the mii_bus struct
579 * @addr: the phy address
580 * @regnum: register number to write
581 * @val: value to write to @regnum
582 *
583 * Write a MDIO bus register. Caller must hold the mdio bus lock.
584 *
585 * NOTE: MUST NOT be called from interrupt context.
586 */
587int __mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
588{
589 int err;
590
591 WARN_ON_ONCE(!mutex_is_locked(&bus->mdio_lock));
592
593 err = bus->write(bus, addr, regnum, val);
594
595 trace_mdio_access(bus, 0, addr, regnum, val, err);
596
597 return err;
598}
599EXPORT_SYMBOL(__mdiobus_write);
600
601/**
602 * mdiobus_read_nested - Nested version of the mdiobus_read function
603 * @bus: the mii_bus struct
604 * @addr: the phy address
605 * @regnum: register number to read
606 *
607 * In case of nested MDIO bus access avoid lockdep false positives by
608 * using mutex_lock_nested().
609 *
610 * NOTE: MUST NOT be called from interrupt context,
611 * because the bus read/write functions may wait for an interrupt
612 * to conclude the operation.
613 */
614int mdiobus_read_nested(struct mii_bus *bus, int addr, u32 regnum)
615{
616 int retval;
617
618 BUG_ON(in_interrupt());
619
620 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
621 retval = __mdiobus_read(bus, addr, regnum);
622 mutex_unlock(&bus->mdio_lock);
623
624 return retval;
625}
626EXPORT_SYMBOL(mdiobus_read_nested);
627
628/**
629 * mdiobus_read - Convenience function for reading a given MII mgmt register
630 * @bus: the mii_bus struct
631 * @addr: the phy address
632 * @regnum: register number to read
633 *
634 * NOTE: MUST NOT be called from interrupt context,
635 * because the bus read/write functions may wait for an interrupt
636 * to conclude the operation.
637 */
638int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
639{
640 int retval;
641
642 BUG_ON(in_interrupt());
643
644 mutex_lock(&bus->mdio_lock);
645 retval = __mdiobus_read(bus, addr, regnum);
646 mutex_unlock(&bus->mdio_lock);
647
648 return retval;
649}
650EXPORT_SYMBOL(mdiobus_read);
651
652/**
653 * mdiobus_write_nested - Nested version of the mdiobus_write function
654 * @bus: the mii_bus struct
655 * @addr: the phy address
656 * @regnum: register number to write
657 * @val: value to write to @regnum
658 *
659 * In case of nested MDIO bus access avoid lockdep false positives by
660 * using mutex_lock_nested().
661 *
662 * NOTE: MUST NOT be called from interrupt context,
663 * because the bus read/write functions may wait for an interrupt
664 * to conclude the operation.
665 */
666int mdiobus_write_nested(struct mii_bus *bus, int addr, u32 regnum, u16 val)
667{
668 int err;
669
670 BUG_ON(in_interrupt());
671
672 mutex_lock_nested(&bus->mdio_lock, MDIO_MUTEX_NESTED);
673 err = __mdiobus_write(bus, addr, regnum, val);
674 mutex_unlock(&bus->mdio_lock);
675
676 return err;
677}
678EXPORT_SYMBOL(mdiobus_write_nested);
679
680/**
681 * mdiobus_write - Convenience function for writing a given MII mgmt register
682 * @bus: the mii_bus struct
683 * @addr: the phy address
684 * @regnum: register number to write
685 * @val: value to write to @regnum
686 *
687 * NOTE: MUST NOT be called from interrupt context,
688 * because the bus read/write functions may wait for an interrupt
689 * to conclude the operation.
690 */
691int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
692{
693 int err;
694
695 BUG_ON(in_interrupt());
696
697 mutex_lock(&bus->mdio_lock);
698 err = __mdiobus_write(bus, addr, regnum, val);
699 mutex_unlock(&bus->mdio_lock);
700
701 return err;
702}
703EXPORT_SYMBOL(mdiobus_write);
704
705/**
706 * mdio_bus_match - determine if given MDIO driver supports the given
707 * MDIO device
708 * @dev: target MDIO device
709 * @drv: given MDIO driver
710 *
711 * Description: Given a MDIO device, and a MDIO driver, return 1 if
712 * the driver supports the device. Otherwise, return 0. This may
713 * require calling the devices own match function, since different classes
714 * of MDIO devices have different match criteria.
715 */
716static int mdio_bus_match(struct device *dev, struct device_driver *drv)
717{
718 struct mdio_device *mdio = to_mdio_device(dev);
719
720 if (of_driver_match_device(dev, drv))
721 return 1;
722
723 if (mdio->bus_match)
724 return mdio->bus_match(dev, drv);
725
726 return 0;
727}
728
729static int mdio_uevent(struct device *dev, struct kobj_uevent_env *env)
730{
731 int rc;
732
733 /* Some devices have extra OF data and an OF-style MODALIAS */
734 rc = of_device_uevent_modalias(dev, env);
735 if (rc != -ENODEV)
736 return rc;
737
738 return 0;
739}
740
741struct bus_type mdio_bus_type = {
742 .name = "mdio_bus",
743 .match = mdio_bus_match,
744 .uevent = mdio_uevent,
745};
746EXPORT_SYMBOL(mdio_bus_type);
747
748int __init mdio_bus_init(void)
749{
750 int ret;
751
752 ret = class_register(&mdio_bus_class);
753 if (!ret) {
754 ret = bus_register(&mdio_bus_type);
755 if (ret)
756 class_unregister(&mdio_bus_class);
757 }
758
759 return ret;
760}
761
762#if IS_ENABLED(CONFIG_PHYLIB)
763void mdio_bus_exit(void)
764{
765 class_unregister(&mdio_bus_class);
766 bus_unregister(&mdio_bus_type);
767}
768EXPORT_SYMBOL_GPL(mdio_bus_exit);
769#else
770module_init(mdio_bus_init);
771/* no module_exit, intentional */
772MODULE_LICENSE("GPL");
773MODULE_DESCRIPTION("MDIO bus/device layer");
774#endif