[PATCH] USB: Rename hcd->hub_suspend to hcd->bus_suspend
[linux/fpc-iii.git] / drivers / net / phy / mdio_bus.c
blobad93b0da87f020b2e4c1de55f9de52db271bc089
1 /*
2 * drivers/net/phy/mdio_bus.c
4 * MDIO Bus interface
6 * Author: Andy Fleming
8 * Copyright (c) 2004 Freescale Semiconductor, Inc.
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License as published by the
12 * Free Software Foundation; either version 2 of the License, or (at your
13 * option) any later version.
16 #include <linux/config.h>
17 #include <linux/kernel.h>
18 #include <linux/sched.h>
19 #include <linux/string.h>
20 #include <linux/errno.h>
21 #include <linux/unistd.h>
22 #include <linux/slab.h>
23 #include <linux/interrupt.h>
24 #include <linux/init.h>
25 #include <linux/delay.h>
26 #include <linux/netdevice.h>
27 #include <linux/etherdevice.h>
28 #include <linux/skbuff.h>
29 #include <linux/spinlock.h>
30 #include <linux/mm.h>
31 #include <linux/module.h>
32 #include <linux/version.h>
33 #include <linux/mii.h>
34 #include <linux/ethtool.h>
35 #include <linux/phy.h>
37 #include <asm/io.h>
38 #include <asm/irq.h>
39 #include <asm/uaccess.h>
41 /* mdiobus_register
43 * description: Called by a bus driver to bring up all the PHYs
44 * on a given bus, and attach them to the bus
46 int mdiobus_register(struct mii_bus *bus)
48 int i;
49 int err = 0;
51 spin_lock_init(&bus->mdio_lock);
53 if (NULL == bus || NULL == bus->name ||
54 NULL == bus->read ||
55 NULL == bus->write)
56 return -EINVAL;
58 if (bus->reset)
59 bus->reset(bus);
61 for (i = 0; i < PHY_MAX_ADDR; i++) {
62 struct phy_device *phydev;
64 phydev = get_phy_device(bus, i);
66 if (IS_ERR(phydev))
67 return PTR_ERR(phydev);
69 /* There's a PHY at this address
70 * We need to set:
71 * 1) IRQ
72 * 2) bus_id
73 * 3) parent
74 * 4) bus
75 * 5) mii_bus
76 * And, we need to register it */
77 if (phydev) {
78 phydev->irq = bus->irq[i];
80 phydev->dev.parent = bus->dev;
81 phydev->dev.bus = &mdio_bus_type;
82 sprintf(phydev->dev.bus_id, "phy%d:%d", bus->id, i);
84 phydev->bus = bus;
86 err = device_register(&phydev->dev);
88 if (err)
89 printk(KERN_ERR "phy %d failed to register\n",
90 i);
93 bus->phy_map[i] = phydev;
96 pr_info("%s: probed\n", bus->name);
98 return err;
100 EXPORT_SYMBOL(mdiobus_register);
102 void mdiobus_unregister(struct mii_bus *bus)
104 int i;
106 for (i = 0; i < PHY_MAX_ADDR; i++) {
107 if (bus->phy_map[i]) {
108 device_unregister(&bus->phy_map[i]->dev);
109 kfree(bus->phy_map[i]);
113 EXPORT_SYMBOL(mdiobus_unregister);
115 /* mdio_bus_match
117 * description: Given a PHY device, and a PHY driver, return 1 if
118 * the driver supports the device. Otherwise, return 0
120 static int mdio_bus_match(struct device *dev, struct device_driver *drv)
122 struct phy_device *phydev = to_phy_device(dev);
123 struct phy_driver *phydrv = to_phy_driver(drv);
125 return (phydrv->phy_id == (phydev->phy_id & phydrv->phy_id_mask));
128 /* Suspend and resume. Copied from platform_suspend and
129 * platform_resume
131 static int mdio_bus_suspend(struct device * dev, pm_message_t state)
133 int ret = 0;
134 struct device_driver *drv = dev->driver;
136 if (drv && drv->suspend)
137 ret = drv->suspend(dev, state);
139 return ret;
142 static int mdio_bus_resume(struct device * dev)
144 int ret = 0;
145 struct device_driver *drv = dev->driver;
147 if (drv && drv->resume)
148 ret = drv->resume(dev);
150 return ret;
153 struct bus_type mdio_bus_type = {
154 .name = "mdio_bus",
155 .match = mdio_bus_match,
156 .suspend = mdio_bus_suspend,
157 .resume = mdio_bus_resume,
160 int __init mdio_bus_init(void)
162 return bus_register(&mdio_bus_type);
165 void mdio_bus_exit(void)
167 bus_unregister(&mdio_bus_type);