diff options
Diffstat (limited to 'drivers/net/fsl_pq_mdio.c')
-rw-r--r-- | drivers/net/fsl_pq_mdio.c | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/drivers/net/fsl_pq_mdio.c b/drivers/net/fsl_pq_mdio.c index 25fabb3eedc5..d5160edf2fcf 100644 --- a/drivers/net/fsl_pq_mdio.c +++ b/drivers/net/fsl_pq_mdio.c | |||
@@ -46,6 +46,11 @@ | |||
46 | #include "gianfar.h" | 46 | #include "gianfar.h" |
47 | #include "fsl_pq_mdio.h" | 47 | #include "fsl_pq_mdio.h" |
48 | 48 | ||
49 | struct fsl_pq_mdio_priv { | ||
50 | void __iomem *map; | ||
51 | struct fsl_pq_mdio __iomem *regs; | ||
52 | }; | ||
53 | |||
49 | /* | 54 | /* |
50 | * Write value to the PHY at mii_id at register regnum, | 55 | * Write value to the PHY at mii_id at register regnum, |
51 | * on the bus attached to the local interface, which may be different from the | 56 | * on the bus attached to the local interface, which may be different from the |
@@ -105,7 +110,9 @@ int fsl_pq_local_mdio_read(struct fsl_pq_mdio __iomem *regs, | |||
105 | 110 | ||
106 | static struct fsl_pq_mdio __iomem *fsl_pq_mdio_get_regs(struct mii_bus *bus) | 111 | static struct fsl_pq_mdio __iomem *fsl_pq_mdio_get_regs(struct mii_bus *bus) |
107 | { | 112 | { |
108 | return (void __iomem __force *)bus->priv; | 113 | struct fsl_pq_mdio_priv *priv = bus->priv; |
114 | |||
115 | return priv->regs; | ||
109 | } | 116 | } |
110 | 117 | ||
111 | /* | 118 | /* |
@@ -266,6 +273,7 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev, | |||
266 | { | 273 | { |
267 | struct device_node *np = ofdev->node; | 274 | struct device_node *np = ofdev->node; |
268 | struct device_node *tbi; | 275 | struct device_node *tbi; |
276 | struct fsl_pq_mdio_priv *priv; | ||
269 | struct fsl_pq_mdio __iomem *regs = NULL; | 277 | struct fsl_pq_mdio __iomem *regs = NULL; |
270 | void __iomem *map; | 278 | void __iomem *map; |
271 | u32 __iomem *tbipa; | 279 | u32 __iomem *tbipa; |
@@ -274,14 +282,19 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev, | |||
274 | u64 addr = 0, size = 0; | 282 | u64 addr = 0, size = 0; |
275 | int err = 0; | 283 | int err = 0; |
276 | 284 | ||
285 | priv = kzalloc(sizeof(*priv), GFP_KERNEL); | ||
286 | if (!priv) | ||
287 | return -ENOMEM; | ||
288 | |||
277 | new_bus = mdiobus_alloc(); | 289 | new_bus = mdiobus_alloc(); |
278 | if (NULL == new_bus) | 290 | if (NULL == new_bus) |
279 | return -ENOMEM; | 291 | goto err_free_priv; |
280 | 292 | ||
281 | new_bus->name = "Freescale PowerQUICC MII Bus", | 293 | new_bus->name = "Freescale PowerQUICC MII Bus", |
282 | new_bus->read = &fsl_pq_mdio_read, | 294 | new_bus->read = &fsl_pq_mdio_read, |
283 | new_bus->write = &fsl_pq_mdio_write, | 295 | new_bus->write = &fsl_pq_mdio_write, |
284 | new_bus->reset = &fsl_pq_mdio_reset, | 296 | new_bus->reset = &fsl_pq_mdio_reset, |
297 | new_bus->priv = priv; | ||
285 | fsl_pq_mdio_bus_name(new_bus->id, np); | 298 | fsl_pq_mdio_bus_name(new_bus->id, np); |
286 | 299 | ||
287 | /* Set the PHY base address */ | 300 | /* Set the PHY base address */ |
@@ -291,6 +304,7 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev, | |||
291 | err = -ENOMEM; | 304 | err = -ENOMEM; |
292 | goto err_free_bus; | 305 | goto err_free_bus; |
293 | } | 306 | } |
307 | priv->map = map; | ||
294 | 308 | ||
295 | if (of_device_is_compatible(np, "fsl,gianfar-mdio") || | 309 | if (of_device_is_compatible(np, "fsl,gianfar-mdio") || |
296 | of_device_is_compatible(np, "fsl,gianfar-tbi") || | 310 | of_device_is_compatible(np, "fsl,gianfar-tbi") || |
@@ -298,8 +312,7 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev, | |||
298 | of_device_is_compatible(np, "ucc_geth_phy")) | 312 | of_device_is_compatible(np, "ucc_geth_phy")) |
299 | map -= offsetof(struct fsl_pq_mdio, miimcfg); | 313 | map -= offsetof(struct fsl_pq_mdio, miimcfg); |
300 | regs = map; | 314 | regs = map; |
301 | 315 | priv->regs = regs; | |
302 | new_bus->priv = (void __force *)regs; | ||
303 | 316 | ||
304 | new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL); | 317 | new_bus->irq = kcalloc(PHY_MAX_ADDR, sizeof(int), GFP_KERNEL); |
305 | 318 | ||
@@ -392,10 +405,11 @@ static int fsl_pq_mdio_probe(struct of_device *ofdev, | |||
392 | err_free_irqs: | 405 | err_free_irqs: |
393 | kfree(new_bus->irq); | 406 | kfree(new_bus->irq); |
394 | err_unmap_regs: | 407 | err_unmap_regs: |
395 | iounmap(regs); | 408 | iounmap(priv->map); |
396 | err_free_bus: | 409 | err_free_bus: |
397 | kfree(new_bus); | 410 | kfree(new_bus); |
398 | 411 | err_free_priv: | |
412 | kfree(priv); | ||
399 | return err; | 413 | return err; |
400 | } | 414 | } |
401 | 415 | ||
@@ -404,14 +418,16 @@ static int fsl_pq_mdio_remove(struct of_device *ofdev) | |||
404 | { | 418 | { |
405 | struct device *device = &ofdev->dev; | 419 | struct device *device = &ofdev->dev; |
406 | struct mii_bus *bus = dev_get_drvdata(device); | 420 | struct mii_bus *bus = dev_get_drvdata(device); |
421 | struct fsl_pq_mdio_priv *priv = bus->priv; | ||
407 | 422 | ||
408 | mdiobus_unregister(bus); | 423 | mdiobus_unregister(bus); |
409 | 424 | ||
410 | dev_set_drvdata(device, NULL); | 425 | dev_set_drvdata(device, NULL); |
411 | 426 | ||
412 | iounmap(fsl_pq_mdio_get_regs(bus)); | 427 | iounmap(priv->map); |
413 | bus->priv = NULL; | 428 | bus->priv = NULL; |
414 | mdiobus_free(bus); | 429 | mdiobus_free(bus); |
430 | kfree(priv); | ||
415 | 431 | ||
416 | return 0; | 432 | return 0; |
417 | } | 433 | } |