aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/macb.c
diff options
context:
space:
mode:
authorLennert Buytenhek <buytenh@marvell.com>2008-10-08 19:29:57 -0400
committerDavid S. Miller <davem@davemloft.net>2008-10-08 19:29:57 -0400
commit298cf9beb9679522de995e249eccbd82f7c51999 (patch)
treecabbc9c696a063982aea9a24d8caa667daa33a1a /drivers/net/macb.c
parent18ee49ddb0d242ed1d0e273038d5e4f6de7379d3 (diff)
phylib: move to dynamic allocation of struct mii_bus
This patch introduces mdiobus_alloc() and mdiobus_free(), and makes all mdio bus drivers use these functions to allocate their struct mii_bus'es dynamically. Signed-off-by: Lennert Buytenhek <buytenh@marvell.com> Signed-off-by: David S. Miller <davem@davemloft.net> Acked-by: Andy Fleming <afleming@freescale.com>
Diffstat (limited to 'drivers/net/macb.c')
-rw-r--r--drivers/net/macb.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/drivers/net/macb.c b/drivers/net/macb.c
index 045361fe3d6a..01f7a31bac76 100644
--- a/drivers/net/macb.c
+++ b/drivers/net/macb.c
@@ -195,8 +195,8 @@ static int macb_mii_probe(struct net_device *dev)
195 195
196 /* find the first phy */ 196 /* find the first phy */
197 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) { 197 for (phy_addr = 0; phy_addr < PHY_MAX_ADDR; phy_addr++) {
198 if (bp->mii_bus.phy_map[phy_addr]) { 198 if (bp->mii_bus->phy_map[phy_addr]) {
199 phydev = bp->mii_bus.phy_map[phy_addr]; 199 phydev = bp->mii_bus->phy_map[phy_addr];
200 break; 200 break;
201 } 201 }
202 } 202 }
@@ -244,30 +244,36 @@ static int macb_mii_init(struct macb *bp)
244 /* Enable managment port */ 244 /* Enable managment port */
245 macb_writel(bp, NCR, MACB_BIT(MPE)); 245 macb_writel(bp, NCR, MACB_BIT(MPE));
246 246
247 bp->mii_bus.name = "MACB_mii_bus"; 247 bp->mii_bus = mdiobus_alloc();
248 bp->mii_bus.read = &macb_mdio_read; 248 if (bp->mii_bus == NULL) {
249 bp->mii_bus.write = &macb_mdio_write; 249 err = -ENOMEM;
250 bp->mii_bus.reset = &macb_mdio_reset; 250 goto err_out;
251 snprintf(bp->mii_bus.id, MII_BUS_ID_SIZE, "%x", bp->pdev->id); 251 }
252 bp->mii_bus.priv = bp; 252
253 bp->mii_bus.parent = &bp->dev->dev; 253 bp->mii_bus->name = "MACB_mii_bus";
254 bp->mii_bus->read = &macb_mdio_read;
255 bp->mii_bus->write = &macb_mdio_write;
256 bp->mii_bus->reset = &macb_mdio_reset;
257 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%x", bp->pdev->id);
258 bp->mii_bus->priv = bp;
259 bp->mii_bus->parent = &bp->dev->dev;
254 pdata = bp->pdev->dev.platform_data; 260 pdata = bp->pdev->dev.platform_data;
255 261
256 if (pdata) 262 if (pdata)
257 bp->mii_bus.phy_mask = pdata->phy_mask; 263 bp->mii_bus->phy_mask = pdata->phy_mask;
258 264
259 bp->mii_bus.irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); 265 bp->mii_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL);
260 if (!bp->mii_bus.irq) { 266 if (!bp->mii_bus->irq) {
261 err = -ENOMEM; 267 err = -ENOMEM;
262 goto err_out; 268 goto err_out_free_mdiobus;
263 } 269 }
264 270
265 for (i = 0; i < PHY_MAX_ADDR; i++) 271 for (i = 0; i < PHY_MAX_ADDR; i++)
266 bp->mii_bus.irq[i] = PHY_POLL; 272 bp->mii_bus->irq[i] = PHY_POLL;
267 273
268 platform_set_drvdata(bp->dev, &bp->mii_bus); 274 platform_set_drvdata(bp->dev, bp->mii_bus);
269 275
270 if (mdiobus_register(&bp->mii_bus)) 276 if (mdiobus_register(bp->mii_bus))
271 goto err_out_free_mdio_irq; 277 goto err_out_free_mdio_irq;
272 278
273 if (macb_mii_probe(bp->dev) != 0) { 279 if (macb_mii_probe(bp->dev) != 0) {
@@ -277,9 +283,11 @@ static int macb_mii_init(struct macb *bp)
277 return 0; 283 return 0;
278 284
279err_out_unregister_bus: 285err_out_unregister_bus:
280 mdiobus_unregister(&bp->mii_bus); 286 mdiobus_unregister(bp->mii_bus);
281err_out_free_mdio_irq: 287err_out_free_mdio_irq:
282 kfree(bp->mii_bus.irq); 288 kfree(bp->mii_bus->irq);
289err_out_free_mdiobus:
290 mdiobus_free(bp->mii_bus);
283err_out: 291err_out:
284 return err; 292 return err;
285} 293}
@@ -1261,8 +1269,9 @@ static int __exit macb_remove(struct platform_device *pdev)
1261 bp = netdev_priv(dev); 1269 bp = netdev_priv(dev);
1262 if (bp->phy_dev) 1270 if (bp->phy_dev)
1263 phy_disconnect(bp->phy_dev); 1271 phy_disconnect(bp->phy_dev);
1264 mdiobus_unregister(&bp->mii_bus); 1272 mdiobus_unregister(bp->mii_bus);
1265 kfree(bp->mii_bus.irq); 1273 kfree(bp->mii_bus->irq);
1274 mdiobus_free(bp->mii_bus);
1266 unregister_netdev(dev); 1275 unregister_netdev(dev);
1267 free_irq(dev->irq, dev); 1276 free_irq(dev->irq, dev);
1268 iounmap(bp->regs); 1277 iounmap(bp->regs);