blob: 7c66ea095a4625735c97874c68f170f34230ffcc [file] [log] [blame]
Sergei Shtylyov02d320c2014-01-05 03:18:27 +03001/* MDIO Bus interface
Andy Fleming00db8182005-07-30 19:31:23 -04002 *
3 * Author: Andy Fleming
4 *
5 * Copyright (c) 2004 Freescale Semiconductor, Inc.
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
11 *
12 */
Joe Perches8d242482012-06-09 07:49:07 +000013
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
Andy Fleming00db8182005-07-30 19:31:23 -040016#include <linux/kernel.h>
Andy Fleming00db8182005-07-30 19:31:23 -040017#include <linux/string.h>
18#include <linux/errno.h>
19#include <linux/unistd.h>
20#include <linux/slab.h>
21#include <linux/interrupt.h>
22#include <linux/init.h>
23#include <linux/delay.h>
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -080024#include <linux/device.h>
David Daneya30e2c12012-06-27 07:33:37 +000025#include <linux/of_device.h>
Mark Brown4085a7f2012-10-08 22:55:43 +000026#include <linux/of_mdio.h>
Andy Fleming00db8182005-07-30 19:31:23 -040027#include <linux/netdevice.h>
28#include <linux/etherdevice.h>
29#include <linux/skbuff.h>
30#include <linux/spinlock.h>
31#include <linux/mm.h>
32#include <linux/module.h>
Andy Fleming00db8182005-07-30 19:31:23 -040033#include <linux/mii.h>
34#include <linux/ethtool.h>
35#include <linux/phy.h>
Sergei Shtylyov02d320c2014-01-05 03:18:27 +030036#include <linux/io.h>
37#include <linux/uaccess.h>
Andy Fleming00db8182005-07-30 19:31:23 -040038
Andy Fleming00db8182005-07-30 19:31:23 -040039#include <asm/irq.h>
Andy Fleming00db8182005-07-30 19:31:23 -040040
Randy Dunlapb3df0da2007-03-06 02:41:48 -080041/**
Timur Tabieb8a54a72012-01-12 15:23:04 -080042 * mdiobus_alloc_size - allocate a mii_bus structure
Randy Dunlapaf58f1d2012-01-21 09:03:04 +000043 * @size: extra amount of memory to allocate for private storage.
44 * If non-zero, then bus->priv is points to that memory.
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -070045 *
46 * Description: called by a bus driver to allocate an mii_bus
47 * structure to fill in.
48 */
Timur Tabieb8a54a72012-01-12 15:23:04 -080049struct mii_bus *mdiobus_alloc_size(size_t size)
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -070050{
Lennert Buytenhek46abc022008-10-08 16:33:40 -070051 struct mii_bus *bus;
Timur Tabieb8a54a72012-01-12 15:23:04 -080052 size_t aligned_size = ALIGN(sizeof(*bus), NETDEV_ALIGN);
53 size_t alloc_size;
Lennert Buytenhek46abc022008-10-08 16:33:40 -070054
Timur Tabieb8a54a72012-01-12 15:23:04 -080055 /* If we alloc extra space, it should be aligned */
56 if (size)
57 alloc_size = aligned_size + size;
58 else
59 alloc_size = sizeof(*bus);
60
61 bus = kzalloc(alloc_size, GFP_KERNEL);
62 if (bus) {
Lennert Buytenhek46abc022008-10-08 16:33:40 -070063 bus->state = MDIOBUS_ALLOCATED;
Timur Tabieb8a54a72012-01-12 15:23:04 -080064 if (size)
65 bus->priv = (void *)bus + aligned_size;
66 }
Lennert Buytenhek46abc022008-10-08 16:33:40 -070067
68 return bus;
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -070069}
Timur Tabieb8a54a72012-01-12 15:23:04 -080070EXPORT_SYMBOL(mdiobus_alloc_size);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -070071
72/**
Lennert Buytenhek46abc022008-10-08 16:33:40 -070073 * mdiobus_release - mii_bus device release callback
Randy Dunlap78c36b12008-10-13 18:46:22 -070074 * @d: the target struct device that contains the mii_bus
Lennert Buytenhek46abc022008-10-08 16:33:40 -070075 *
76 * Description: called when the last reference to an mii_bus is
77 * dropped, to free the underlying memory.
78 */
79static void mdiobus_release(struct device *d)
80{
81 struct mii_bus *bus = to_mii_bus(d);
Krzysztof Halasa161c8d22008-12-25 16:50:41 -080082 BUG_ON(bus->state != MDIOBUS_RELEASED &&
83 /* for compatibility with error handling in drivers */
84 bus->state != MDIOBUS_ALLOCATED);
Lennert Buytenhek46abc022008-10-08 16:33:40 -070085 kfree(bus);
86}
87
88static struct class mdio_bus_class = {
89 .name = "mdio_bus",
90 .dev_release = mdiobus_release,
91};
92
Bjørn Morkb943fbb2012-05-11 05:47:01 +000093#if IS_ENABLED(CONFIG_OF_MDIO)
David Daney25106022012-05-02 15:16:37 +000094/* Helper function for of_mdio_find_bus */
Michał Mirosław9f3b7952013-02-01 20:40:17 +010095static int of_mdio_bus_match(struct device *dev, const void *mdio_bus_np)
David Daney25106022012-05-02 15:16:37 +000096{
97 return dev->of_node == mdio_bus_np;
98}
99/**
100 * of_mdio_find_bus - Given an mii_bus node, find the mii_bus.
Randy Dunlapf41ef2e2012-06-08 14:07:19 +0000101 * @mdio_bus_np: Pointer to the mii_bus.
David Daney25106022012-05-02 15:16:37 +0000102 *
103 * Returns a pointer to the mii_bus, or NULL if none found.
104 *
105 * Because the association of a device_node and mii_bus is made via
106 * of_mdiobus_register(), the mii_bus cannot be found before it is
107 * registered with of_mdiobus_register().
108 *
109 */
110struct mii_bus *of_mdio_find_bus(struct device_node *mdio_bus_np)
111{
112 struct device *d;
113
114 if (!mdio_bus_np)
115 return NULL;
116
117 d = class_find_device(&mdio_bus_class, NULL, mdio_bus_np,
118 of_mdio_bus_match);
119
120 return d ? to_mii_bus(d) : NULL;
121}
122EXPORT_SYMBOL(of_mdio_find_bus);
123#endif
124
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700125/**
Randy Dunlapb3df0da2007-03-06 02:41:48 -0800126 * mdiobus_register - bring up all the PHYs on a given bus and attach them to bus
127 * @bus: target mii_bus
Andy Fleminge1393452005-08-24 18:46:21 -0500128 *
Randy Dunlapb3df0da2007-03-06 02:41:48 -0800129 * Description: Called by a bus driver to bring up all the PHYs
130 * on a given bus, and attach them to the bus.
131 *
132 * Returns 0 on success or < 0 on error.
Andy Fleminge1393452005-08-24 18:46:21 -0500133 */
134int mdiobus_register(struct mii_bus *bus)
135{
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800136 int i, err;
Andy Fleminge1393452005-08-24 18:46:21 -0500137
Andy Fleminge1393452005-08-24 18:46:21 -0500138 if (NULL == bus || NULL == bus->name ||
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300139 NULL == bus->read || NULL == bus->write)
Andy Fleminge1393452005-08-24 18:46:21 -0500140 return -EINVAL;
141
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700142 BUG_ON(bus->state != MDIOBUS_ALLOCATED &&
143 bus->state != MDIOBUS_UNREGISTERED);
144
145 bus->dev.parent = bus->parent;
146 bus->dev.class = &mdio_bus_class;
147 bus->dev.groups = NULL;
Stephen Hemminger036b6682009-02-26 10:19:36 +0000148 dev_set_name(&bus->dev, "%s", bus->id);
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700149
150 err = device_register(&bus->dev);
151 if (err) {
Joe Perches8d242482012-06-09 07:49:07 +0000152 pr_err("mii_bus %s failed to register\n", bus->id);
Levente Kurusa0c692d02014-01-30 15:45:46 -0800153 put_device(&bus->dev);
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700154 return -EINVAL;
155 }
156
Adrian Bunkd1e7fe42008-02-20 02:13:53 +0200157 mutex_init(&bus->mdio_lock);
158
Andy Fleminge1393452005-08-24 18:46:21 -0500159 if (bus->reset)
160 bus->reset(bus);
161
162 for (i = 0; i < PHY_MAX_ADDR; i++) {
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200163 if ((bus->phy_mask & (1 << i)) == 0) {
164 struct phy_device *phydev;
Andy Fleminge1393452005-08-24 18:46:21 -0500165
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200166 phydev = mdiobus_scan(bus, i);
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800167 if (IS_ERR(phydev)) {
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200168 err = PTR_ERR(phydev);
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800169 goto error;
170 }
Herbert Valerio Riedel64b1c2b2006-05-10 12:12:57 -0400171 }
Andy Fleminge1393452005-08-24 18:46:21 -0500172 }
173
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800174 bus->state = MDIOBUS_REGISTERED;
Andy Fleminge1393452005-08-24 18:46:21 -0500175 pr_info("%s: probed\n", bus->name);
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800176 return 0;
Andy Fleminge1393452005-08-24 18:46:21 -0500177
Krzysztof Halasa161c8d22008-12-25 16:50:41 -0800178error:
179 while (--i >= 0) {
180 if (bus->phy_map[i])
181 device_unregister(&bus->phy_map[i]->dev);
182 }
183 device_del(&bus->dev);
Andy Fleminge1393452005-08-24 18:46:21 -0500184 return err;
185}
186EXPORT_SYMBOL(mdiobus_register);
187
188void mdiobus_unregister(struct mii_bus *bus)
189{
190 int i;
191
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700192 BUG_ON(bus->state != MDIOBUS_REGISTERED);
193 bus->state = MDIOBUS_UNREGISTERED;
194
Lennert Buytenhek3e440172008-11-09 05:34:47 +0100195 device_del(&bus->dev);
Andy Fleminge1393452005-08-24 18:46:21 -0500196 for (i = 0; i < PHY_MAX_ADDR; i++) {
Anton Vorontsov6f4a7f42007-12-04 16:17:33 +0300197 if (bus->phy_map[i])
Andy Fleminge1393452005-08-24 18:46:21 -0500198 device_unregister(&bus->phy_map[i]->dev);
Grant Likely4dea5472009-04-25 12:52:46 +0000199 bus->phy_map[i] = NULL;
Andy Fleminge1393452005-08-24 18:46:21 -0500200 }
201}
202EXPORT_SYMBOL(mdiobus_unregister);
203
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700204/**
205 * mdiobus_free - free a struct mii_bus
206 * @bus: mii_bus to free
207 *
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700208 * This function releases the reference to the underlying device
209 * object in the mii_bus. If this is the last reference, the mii_bus
210 * will be freed.
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700211 */
212void mdiobus_free(struct mii_bus *bus)
213{
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300214 /* For compatibility with error handling in drivers. */
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700215 if (bus->state == MDIOBUS_ALLOCATED) {
216 kfree(bus);
217 return;
218 }
219
220 BUG_ON(bus->state != MDIOBUS_UNREGISTERED);
221 bus->state = MDIOBUS_RELEASED;
222
223 put_device(&bus->dev);
Lennert Buytenhek298cf9b2008-10-08 16:29:57 -0700224}
225EXPORT_SYMBOL(mdiobus_free);
226
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200227struct phy_device *mdiobus_scan(struct mii_bus *bus, int addr)
228{
229 struct phy_device *phydev;
230 int err;
231
David Daneyac28b9f2012-06-27 07:33:35 +0000232 phydev = get_phy_device(bus, addr, false);
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200233 if (IS_ERR(phydev) || phydev == NULL)
234 return phydev;
235
Grant Likely4dea5472009-04-25 12:52:46 +0000236 err = phy_device_register(phydev);
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200237 if (err) {
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200238 phy_device_free(phydev);
Grant Likely4dea5472009-04-25 12:52:46 +0000239 return NULL;
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200240 }
241
Lennert Buytenhek4fd5f812008-08-26 13:08:46 +0200242 return phydev;
243}
244EXPORT_SYMBOL(mdiobus_scan);
245
Randy Dunlapb3df0da2007-03-06 02:41:48 -0800246/**
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000247 * mdiobus_read - Convenience function for reading a given MII mgmt register
248 * @bus: the mii_bus struct
249 * @addr: the phy address
250 * @regnum: register number to read
251 *
252 * NOTE: MUST NOT be called from interrupt context,
253 * because the bus read/write functions may wait for an interrupt
254 * to conclude the operation.
255 */
Jason Gunthorpeabf35df2010-03-09 09:17:42 +0000256int mdiobus_read(struct mii_bus *bus, int addr, u32 regnum)
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000257{
258 int retval;
259
260 BUG_ON(in_interrupt());
261
262 mutex_lock(&bus->mdio_lock);
263 retval = bus->read(bus, addr, regnum);
264 mutex_unlock(&bus->mdio_lock);
265
266 return retval;
267}
268EXPORT_SYMBOL(mdiobus_read);
269
270/**
271 * mdiobus_write - Convenience function for writing a given MII mgmt register
272 * @bus: the mii_bus struct
273 * @addr: the phy address
274 * @regnum: register number to write
275 * @val: value to write to @regnum
276 *
277 * NOTE: MUST NOT be called from interrupt context,
278 * because the bus read/write functions may wait for an interrupt
279 * to conclude the operation.
280 */
Jason Gunthorpeabf35df2010-03-09 09:17:42 +0000281int mdiobus_write(struct mii_bus *bus, int addr, u32 regnum, u16 val)
Lennert Buytenhek2e888102008-09-29 17:12:35 +0000282{
283 int err;
284
285 BUG_ON(in_interrupt());
286
287 mutex_lock(&bus->mdio_lock);
288 err = bus->write(bus, addr, regnum, val);
289 mutex_unlock(&bus->mdio_lock);
290
291 return err;
292}
293EXPORT_SYMBOL(mdiobus_write);
294
295/**
Randy Dunlapb3df0da2007-03-06 02:41:48 -0800296 * mdio_bus_match - determine if given PHY driver supports the given PHY device
297 * @dev: target PHY device
298 * @drv: given PHY driver
Andy Fleming00db8182005-07-30 19:31:23 -0400299 *
Randy Dunlapb3df0da2007-03-06 02:41:48 -0800300 * Description: Given a PHY device, and a PHY driver, return 1 if
301 * the driver supports the device. Otherwise, return 0.
Andy Fleming00db8182005-07-30 19:31:23 -0400302 */
303static int mdio_bus_match(struct device *dev, struct device_driver *drv)
304{
305 struct phy_device *phydev = to_phy_device(dev);
306 struct phy_driver *phydrv = to_phy_driver(drv);
307
David Daneya30e2c12012-06-27 07:33:37 +0000308 if (of_driver_match_device(dev, drv))
309 return 1;
310
311 if (phydrv->match_phy_device)
312 return phydrv->match_phy_device(phydev);
313
Florian Fainelli6f901b72013-12-17 21:38:10 -0800314 return (phydrv->phy_id & phydrv->phy_id_mask) ==
315 (phydev->phy_id & phydrv->phy_id_mask);
Andy Fleming00db8182005-07-30 19:31:23 -0400316}
317
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000318#ifdef CONFIG_PM
319
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800320static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
321{
322 struct device_driver *drv = phydev->dev.driver;
323 struct phy_driver *phydrv = to_phy_driver(drv);
324 struct net_device *netdev = phydev->attached_dev;
325
326 if (!drv || !phydrv->suspend)
327 return false;
328
329 /* PHY not attached? May suspend. */
330 if (!netdev)
331 return true;
332
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300333 /* Don't suspend PHY if the attched netdev parent may wakeup.
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800334 * The parent may point to a PCI device, as in tg3 driver.
335 */
336 if (netdev->dev.parent && device_may_wakeup(netdev->dev.parent))
337 return false;
338
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300339 /* Also don't suspend PHY if the netdev itself may wakeup. This
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800340 * is the case for devices w/o underlaying pwr. mgmt. aware bus,
341 * e.g. SoC devices.
342 */
343 if (device_may_wakeup(&netdev->dev))
344 return false;
345
346 return true;
347}
348
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000349static int mdio_bus_suspend(struct device *dev)
Andy Fleming00db8182005-07-30 19:31:23 -0400350{
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800351 struct phy_driver *phydrv = to_phy_driver(dev->driver);
Giuseppe Cavallaro0f0ca342008-11-28 16:24:56 -0800352 struct phy_device *phydev = to_phy_device(dev);
Andy Fleming00db8182005-07-30 19:31:23 -0400353
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300354 /* We must stop the state machine manually, otherwise it stops out of
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000355 * control, possibly with the phydev->lock held. Upon resume, netdev
356 * may call phy routines that try to grab the same lock, and that may
357 * lead to a deadlock.
358 */
Simon Guinotfddd9102010-09-13 22:12:01 +0000359 if (phydev->attached_dev && phydev->adjust_link)
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000360 phy_stop_machine(phydev);
361
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800362 if (!mdio_bus_phy_may_suspend(phydev))
363 return 0;
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000364
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800365 return phydrv->suspend(phydev);
Andy Fleming00db8182005-07-30 19:31:23 -0400366}
367
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000368static int mdio_bus_resume(struct device *dev)
Andy Fleming00db8182005-07-30 19:31:23 -0400369{
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800370 struct phy_driver *phydrv = to_phy_driver(dev->driver);
Giuseppe Cavallaro0f0ca342008-11-28 16:24:56 -0800371 struct phy_device *phydev = to_phy_device(dev);
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000372 int ret;
Andy Fleming00db8182005-07-30 19:31:23 -0400373
Anton Vorontsov3d1e4db2009-02-01 00:53:34 -0800374 if (!mdio_bus_phy_may_suspend(phydev))
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000375 goto no_resume;
376
377 ret = phydrv->resume(phydev);
378 if (ret < 0)
379 return ret;
380
381no_resume:
Simon Guinotfddd9102010-09-13 22:12:01 +0000382 if (phydev->attached_dev && phydev->adjust_link)
Sergei Shtylyov29935ae2014-01-05 03:27:17 +0300383 phy_start_machine(phydev);
Anton Vorontsov541cd3e2009-12-30 08:23:28 +0000384
385 return 0;
Andy Fleming00db8182005-07-30 19:31:23 -0400386}
387
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000388static int mdio_bus_restore(struct device *dev)
389{
390 struct phy_device *phydev = to_phy_device(dev);
391 struct net_device *netdev = phydev->attached_dev;
392 int ret;
393
394 if (!netdev)
395 return 0;
396
397 ret = phy_init_hw(phydev);
398 if (ret < 0)
399 return ret;
400
401 /* The PHY needs to renegotiate. */
402 phydev->link = 0;
403 phydev->state = PHY_UP;
404
Sergei Shtylyov29935ae2014-01-05 03:27:17 +0300405 phy_start_machine(phydev);
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000406
407 return 0;
408}
409
Sergei Shtylyov02d320c2014-01-05 03:18:27 +0300410static const struct dev_pm_ops mdio_bus_pm_ops = {
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000411 .suspend = mdio_bus_suspend,
412 .resume = mdio_bus_resume,
413 .freeze = mdio_bus_suspend,
414 .thaw = mdio_bus_resume,
415 .restore = mdio_bus_restore,
416};
417
418#define MDIO_BUS_PM_OPS (&mdio_bus_pm_ops)
419
420#else
421
422#define MDIO_BUS_PM_OPS NULL
423
424#endif /* CONFIG_PM */
425
Nick Bowler56277f42012-11-07 06:20:34 +0000426static ssize_t
427phy_id_show(struct device *dev, struct device_attribute *attr, char *buf)
428{
429 struct phy_device *phydev = to_phy_device(dev);
430
431 return sprintf(buf, "0x%.8lx\n", (unsigned long)phydev->phy_id);
432}
Greg Kroah-Hartman4192c742013-10-06 23:55:41 -0700433static DEVICE_ATTR_RO(phy_id);
Nick Bowler56277f42012-11-07 06:20:34 +0000434
Florian Fainelli3d055d82014-02-11 17:27:40 -0800435static ssize_t
436phy_interface_show(struct device *dev, struct device_attribute *attr, char *buf)
437{
438 struct phy_device *phydev = to_phy_device(dev);
439
440 return sprintf(buf, "%s\n", phy_modes(phydev->interface));
441}
442static DEVICE_ATTR_RO(phy_interface);
443
Greg Kroah-Hartman4192c742013-10-06 23:55:41 -0700444static struct attribute *mdio_dev_attrs[] = {
445 &dev_attr_phy_id.attr,
Florian Fainelli3d055d82014-02-11 17:27:40 -0800446 &dev_attr_phy_interface.attr,
Greg Kroah-Hartman4192c742013-10-06 23:55:41 -0700447 NULL,
Nick Bowler56277f42012-11-07 06:20:34 +0000448};
Greg Kroah-Hartman4192c742013-10-06 23:55:41 -0700449ATTRIBUTE_GROUPS(mdio_dev);
Nick Bowler56277f42012-11-07 06:20:34 +0000450
Andy Fleming00db8182005-07-30 19:31:23 -0400451struct bus_type mdio_bus_type = {
452 .name = "mdio_bus",
453 .match = mdio_bus_match,
Anton Vorontsov2f5cb432009-12-30 08:23:30 +0000454 .pm = MDIO_BUS_PM_OPS,
Greg Kroah-Hartman4192c742013-10-06 23:55:41 -0700455 .dev_groups = mdio_dev_groups,
Andy Fleming00db8182005-07-30 19:31:23 -0400456};
Vitaly Bordug11b0bac2006-08-14 23:00:29 -0700457EXPORT_SYMBOL(mdio_bus_type);
Andy Fleming00db8182005-07-30 19:31:23 -0400458
Jeff Garzik67c4f3f2005-08-11 02:07:25 -0400459int __init mdio_bus_init(void)
Andy Fleming00db8182005-07-30 19:31:23 -0400460{
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700461 int ret;
462
463 ret = class_register(&mdio_bus_class);
464 if (!ret) {
465 ret = bus_register(&mdio_bus_type);
466 if (ret)
467 class_unregister(&mdio_bus_class);
468 }
469
470 return ret;
Andy Fleming00db8182005-07-30 19:31:23 -0400471}
472
Peter Chubbdc85dec2005-09-03 14:05:06 -0700473void mdio_bus_exit(void)
Andy Fleminge1393452005-08-24 18:46:21 -0500474{
Lennert Buytenhek46abc022008-10-08 16:33:40 -0700475 class_unregister(&mdio_bus_class);
Andy Fleminge1393452005-08-24 18:46:21 -0500476 bus_unregister(&mdio_bus_type);
477}