aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/phy/phy_device.c
diff options
context:
space:
mode:
authorGrant Likely <grant.likely@secretlab.ca>2009-04-25 08:52:46 -0400
committerDavid S. Miller <davem@davemloft.net>2009-04-27 05:53:45 -0400
commit4dea547fef1ba23f9d23f5e7f5218187a7dcf1b3 (patch)
tree5d3ef6350d21c5a8ad952ef6f89f7d47099caf0a /drivers/net/phy/phy_device.c
parent739649c53d7f78f5bf41bdfd1a858ee90c7a687a (diff)
phylib: rework to prepare for OF registration of PHYs
This patch makes changes in preparation for supporting open firmware device tree descriptions of MDIO busses. Changes include: - Cleanup handling of phy_map[] entries; they are already NULLed when registering and so don't need to be re-cleared, and it is good practice to clear them out when unregistering. - Split phy_device registration out into a new function so that the OF helpers can do two stage registration (separate allocation and registration steps). Signed-off-by: Grant Likely <grant.likely@secretlab.ca> Acked-by: Andy Fleming <afleming@freescale.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/phy/phy_device.c')
-rw-r--r--drivers/net/phy/phy_device.c45
1 files changed, 41 insertions, 4 deletions
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 0a06e4fd37d9..9352ca8fa2cc 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -39,20 +39,21 @@ MODULE_DESCRIPTION("PHY library");
39MODULE_AUTHOR("Andy Fleming"); 39MODULE_AUTHOR("Andy Fleming");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42static struct phy_driver genphy_driver;
43extern int mdio_bus_init(void);
44extern void mdio_bus_exit(void);
45
46void phy_device_free(struct phy_device *phydev) 42void phy_device_free(struct phy_device *phydev)
47{ 43{
48 kfree(phydev); 44 kfree(phydev);
49} 45}
46EXPORT_SYMBOL(phy_device_free);
50 47
51static void phy_device_release(struct device *dev) 48static void phy_device_release(struct device *dev)
52{ 49{
53 phy_device_free(to_phy_device(dev)); 50 phy_device_free(to_phy_device(dev));
54} 51}
55 52
53static struct phy_driver genphy_driver;
54extern int mdio_bus_init(void);
55extern void mdio_bus_exit(void);
56
56static LIST_HEAD(phy_fixup_list); 57static LIST_HEAD(phy_fixup_list);
57static DEFINE_MUTEX(phy_fixup_lock); 58static DEFINE_MUTEX(phy_fixup_lock);
58 59
@@ -166,6 +167,10 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id)
166 dev->addr = addr; 167 dev->addr = addr;
167 dev->phy_id = phy_id; 168 dev->phy_id = phy_id;
168 dev->bus = bus; 169 dev->bus = bus;
170 dev->dev.parent = bus->parent;
171 dev->dev.bus = &mdio_bus_type;
172 dev->irq = bus->irq != NULL ? bus->irq[addr] : PHY_POLL;
173 dev_set_name(&dev->dev, PHY_ID_FMT, bus->id, addr);
169 174
170 dev->state = PHY_DOWN; 175 dev->state = PHY_DOWN;
171 176
@@ -235,6 +240,38 @@ struct phy_device * get_phy_device(struct mii_bus *bus, int addr)
235 240
236 return dev; 241 return dev;
237} 242}
243EXPORT_SYMBOL(get_phy_device);
244
245/**
246 * phy_device_register - Register the phy device on the MDIO bus
247 * @phy_device: phy_device structure to be added to the MDIO bus
248 */
249int phy_device_register(struct phy_device *phydev)
250{
251 int err;
252
253 /* Don't register a phy if one is already registered at this
254 * address */
255 if (phydev->bus->phy_map[phydev->addr])
256 return -EINVAL;
257 phydev->bus->phy_map[phydev->addr] = phydev;
258
259 /* Run all of the fixups for this PHY */
260 phy_scan_fixups(phydev);
261
262 err = device_register(&phydev->dev);
263 if (err) {
264 pr_err("phy %d failed to register\n", phydev->addr);
265 goto out;
266 }
267
268 return 0;
269
270 out:
271 phydev->bus->phy_map[phydev->addr] = NULL;
272 return err;
273}
274EXPORT_SYMBOL(phy_device_register);
238 275
239/** 276/**
240 * phy_prepare_link - prepares the PHY layer to monitor link status 277 * phy_prepare_link - prepares the PHY layer to monitor link status