diff options
author | Olof Johansson <olof@lixom.net> | 2007-11-04 16:44:15 -0500 |
---|---|---|
committer | Olof Johansson <olof@lixom.net> | 2007-11-29 23:30:44 -0500 |
commit | 2dd3c0016090543e12aa0c5aee574ded6a88b886 (patch) | |
tree | 69a1eba208b5ee0ed3d67836206ebab0719063a2 /arch/powerpc/platforms/pasemi | |
parent | 0b47759db54f82df68ed179ddc5cb2becea56158 (diff) |
[POWERPC] pasemi: clean up mdio_gpio a bit
Misc cleanups of mdio_gpio:
* Better error handling/unrolling in case of init/alloc failures
* Go through child nodes and get their interrupts instead of using
hardcoded values
* Remap the GPIO registers at module load/driver init instead of during probe
* Coding style and other misc cleanups
Signed-off-by: Olof Johansson <olof@lixom.net>
Diffstat (limited to 'arch/powerpc/platforms/pasemi')
-rw-r--r-- | arch/powerpc/platforms/pasemi/gpio_mdio.c | 88 |
1 files changed, 51 insertions, 37 deletions
diff --git a/arch/powerpc/platforms/pasemi/gpio_mdio.c b/arch/powerpc/platforms/pasemi/gpio_mdio.c index dae9f658122e..95d0c78cf634 100644 --- a/arch/powerpc/platforms/pasemi/gpio_mdio.c +++ b/arch/powerpc/platforms/pasemi/gpio_mdio.c | |||
@@ -218,45 +218,27 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
218 | const struct of_device_id *match) | 218 | const struct of_device_id *match) |
219 | { | 219 | { |
220 | struct device *dev = &ofdev->dev; | 220 | struct device *dev = &ofdev->dev; |
221 | struct device_node *np = ofdev->node; | 221 | struct device_node *phy_dn, *np = ofdev->node; |
222 | struct device_node *gpio_np; | ||
223 | struct mii_bus *new_bus; | 222 | struct mii_bus *new_bus; |
224 | struct resource res; | ||
225 | struct gpio_priv *priv; | 223 | struct gpio_priv *priv; |
226 | const unsigned int *prop; | 224 | const unsigned int *prop; |
227 | int err = 0; | 225 | int err; |
228 | int i; | 226 | int i; |
229 | 227 | ||
230 | gpio_np = of_find_compatible_node(NULL, "gpio", "1682m-gpio"); | 228 | err = -ENOMEM; |
231 | |||
232 | if (!gpio_np) | ||
233 | return -ENODEV; | ||
234 | |||
235 | err = of_address_to_resource(gpio_np, 0, &res); | ||
236 | of_node_put(gpio_np); | ||
237 | |||
238 | if (err) | ||
239 | return -EINVAL; | ||
240 | |||
241 | if (!gpio_regs) | ||
242 | gpio_regs = ioremap(res.start, 0x100); | ||
243 | |||
244 | if (!gpio_regs) | ||
245 | return -EPERM; | ||
246 | |||
247 | priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL); | 229 | priv = kzalloc(sizeof(struct gpio_priv), GFP_KERNEL); |
248 | if (priv == NULL) | 230 | if (!priv) |
249 | return -ENOMEM; | 231 | goto out; |
250 | 232 | ||
251 | new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); | 233 | new_bus = kzalloc(sizeof(struct mii_bus), GFP_KERNEL); |
252 | 234 | ||
253 | if (new_bus == NULL) | 235 | if (!new_bus) |
254 | return -ENOMEM; | 236 | goto out_free_priv; |
255 | 237 | ||
256 | new_bus->name = "pasemi gpio mdio bus", | 238 | new_bus->name = "pasemi gpio mdio bus"; |
257 | new_bus->read = &gpio_mdio_read, | 239 | new_bus->read = &gpio_mdio_read; |
258 | new_bus->write = &gpio_mdio_write, | 240 | new_bus->write = &gpio_mdio_write; |
259 | new_bus->reset = &gpio_mdio_reset, | 241 | new_bus->reset = &gpio_mdio_reset; |
260 | 242 | ||
261 | prop = of_get_property(np, "reg", NULL); | 243 | prop = of_get_property(np, "reg", NULL); |
262 | new_bus->id = *prop; | 244 | new_bus->id = *prop; |
@@ -265,9 +247,24 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
265 | new_bus->phy_mask = 0; | 247 | new_bus->phy_mask = 0; |
266 | 248 | ||
267 | new_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); | 249 | new_bus->irq = kmalloc(sizeof(int)*PHY_MAX_ADDR, GFP_KERNEL); |
268 | for(i = 0; i < PHY_MAX_ADDR; ++i) | ||
269 | new_bus->irq[i] = irq_create_mapping(NULL, 10); | ||
270 | 250 | ||
251 | if (!new_bus->irq) | ||
252 | goto out_free_bus; | ||
253 | |||
254 | for (i = 0; i < PHY_MAX_ADDR; i++) | ||
255 | new_bus->irq[i] = NO_IRQ; | ||
256 | |||
257 | for (phy_dn = of_get_next_child(np, NULL); | ||
258 | phy_dn != NULL; | ||
259 | phy_dn = of_get_next_child(np, phy_dn)) { | ||
260 | const unsigned int *ip, *regp; | ||
261 | |||
262 | ip = of_get_property(phy_dn, "interrupts", NULL); | ||
263 | regp = of_get_property(phy_dn, "reg", NULL); | ||
264 | if (!ip || !regp || *regp >= PHY_MAX_ADDR) | ||
265 | continue; | ||
266 | new_bus->irq[*regp] = irq_create_mapping(NULL, *ip); | ||
267 | } | ||
271 | 268 | ||
272 | prop = of_get_property(np, "mdc-pin", NULL); | 269 | prop = of_get_property(np, "mdc-pin", NULL); |
273 | priv->mdc_pin = *prop; | 270 | priv->mdc_pin = *prop; |
@@ -280,17 +277,21 @@ static int __devinit gpio_mdio_probe(struct of_device *ofdev, | |||
280 | 277 | ||
281 | err = mdiobus_register(new_bus); | 278 | err = mdiobus_register(new_bus); |
282 | 279 | ||
283 | if (0 != err) { | 280 | if (err != 0) { |
284 | printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n", | 281 | printk(KERN_ERR "%s: Cannot register as MDIO bus, err %d\n", |
285 | new_bus->name, err); | 282 | new_bus->name, err); |
286 | goto bus_register_fail; | 283 | goto out_free_irq; |
287 | } | 284 | } |
288 | 285 | ||
289 | return 0; | 286 | return 0; |
290 | 287 | ||
291 | bus_register_fail: | 288 | out_free_irq: |
289 | kfree(new_bus->irq); | ||
290 | out_free_bus: | ||
292 | kfree(new_bus); | 291 | kfree(new_bus); |
293 | 292 | out_free_priv: | |
293 | kfree(priv); | ||
294 | out: | ||
294 | return err; | 295 | return err; |
295 | } | 296 | } |
296 | 297 | ||
@@ -330,12 +331,25 @@ static struct of_platform_driver gpio_mdio_driver = | |||
330 | 331 | ||
331 | int gpio_mdio_init(void) | 332 | int gpio_mdio_init(void) |
332 | { | 333 | { |
334 | struct device_node *np; | ||
335 | |||
336 | np = of_find_compatible_node(NULL, "gpio", "1682m-gpio"); | ||
337 | if (!np) | ||
338 | return -ENODEV; | ||
339 | gpio_regs = of_iomap(np, 0); | ||
340 | of_node_put(np); | ||
341 | |||
342 | if (!gpio_regs) | ||
343 | return -ENODEV; | ||
344 | |||
333 | return of_register_platform_driver(&gpio_mdio_driver); | 345 | return of_register_platform_driver(&gpio_mdio_driver); |
334 | } | 346 | } |
347 | module_init(gpio_mdio_init); | ||
335 | 348 | ||
336 | void gpio_mdio_exit(void) | 349 | void gpio_mdio_exit(void) |
337 | { | 350 | { |
338 | of_unregister_platform_driver(&gpio_mdio_driver); | 351 | of_unregister_platform_driver(&gpio_mdio_driver); |
352 | if (gpio_regs) | ||
353 | iounmap(gpio_regs); | ||
339 | } | 354 | } |
340 | device_initcall(gpio_mdio_init); | 355 | module_exit(gpio_mdio_exit); |
341 | |||