aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2013-05-22 06:20:12 -0400
committerLinus Walleij <linus.walleij@linaro.org>2013-05-30 13:31:01 -0400
commit786e07ecb5b2ef896c9d42fa982d02da168e4290 (patch)
tree6b26542dd9986bb252e8811a84a371e3b0ecd33e /drivers/gpio
parent64c8cbc17c8d4af3b600c66247e47eac99e46aaf (diff)
gpio-langwell: use managed functions pcim_* and devm_*
This makes the error handling much more simpler than open-coding everything and in addition makes the probe function smaller an tidier. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com> Acked-by: David Cohen <david.a.cohen@intel.com> [Rebased on the platform-data set to NULL removal patch] Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpio-langwell.c78
1 files changed, 21 insertions, 57 deletions
diff --git a/drivers/gpio/gpio-langwell.c b/drivers/gpio/gpio-langwell.c
index fff661126dc7..54b6caf1742e 100644
--- a/drivers/gpio/gpio-langwell.c
+++ b/drivers/gpio/gpio-langwell.c
@@ -321,55 +321,37 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
321 const struct pci_device_id *id) 321 const struct pci_device_id *id)
322{ 322{
323 void __iomem *base; 323 void __iomem *base;
324 resource_size_t start, len;
325 struct lnw_gpio *lnw; 324 struct lnw_gpio *lnw;
326 u32 gpio_base; 325 u32 gpio_base;
327 u32 irq_base; 326 u32 irq_base;
328 int retval; 327 int retval;
329 int ngpio = id->driver_data; 328 int ngpio = id->driver_data;
330 329
331 retval = pci_enable_device(pdev); 330 retval = pcim_enable_device(pdev);
332 if (retval) 331 if (retval)
333 return retval; 332 return retval;
334 333
335 retval = pci_request_regions(pdev, "langwell_gpio"); 334 retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev));
336 if (retval) { 335 if (retval) {
337 dev_err(&pdev->dev, "error requesting resources\n"); 336 dev_err(&pdev->dev, "I/O memory mapping error\n");
338 goto err_pci_req_region; 337 return retval;
339 }
340 /* get the gpio_base from bar1 */
341 start = pci_resource_start(pdev, 1);
342 len = pci_resource_len(pdev, 1);
343 base = ioremap_nocache(start, len);
344 if (!base) {
345 dev_err(&pdev->dev, "error mapping bar1\n");
346 retval = -EFAULT;
347 goto err_ioremap;
348 } 338 }
349 339
340 base = pcim_iomap_table(pdev)[1];
341
350 irq_base = readl(base); 342 irq_base = readl(base);
351 gpio_base = readl(sizeof(u32) + base); 343 gpio_base = readl(sizeof(u32) + base);
352 344
353 /* release the IO mapping, since we already get the info from bar1 */ 345 /* release the IO mapping, since we already get the info from bar1 */
354 iounmap(base); 346 pcim_iounmap_regions(pdev, 1 << 1);
355 /* get the register base from bar0 */
356 start = pci_resource_start(pdev, 0);
357 len = pci_resource_len(pdev, 0);
358 base = devm_ioremap_nocache(&pdev->dev, start, len);
359 if (!base) {
360 dev_err(&pdev->dev, "error mapping bar0\n");
361 retval = -EFAULT;
362 goto err_ioremap;
363 }
364 347
365 lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL); 348 lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL);
366 if (!lnw) { 349 if (!lnw) {
367 dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n"); 350 dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n");
368 retval = -ENOMEM; 351 return -ENOMEM;
369 goto err_ioremap;
370 } 352 }
371 353
372 lnw->reg_base = base; 354 lnw->reg_base = pcim_iomap_table(pdev)[0];
373 lnw->chip.label = dev_name(&pdev->dev); 355 lnw->chip.label = dev_name(&pdev->dev);
374 lnw->chip.request = lnw_gpio_request; 356 lnw->chip.request = lnw_gpio_request;
375 lnw->chip.direction_input = lnw_gpio_direction_input; 357 lnw->chip.direction_input = lnw_gpio_direction_input;
@@ -386,16 +368,14 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
386 368
387 lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ngpio, irq_base, 369 lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ngpio, irq_base,
388 &lnw_gpio_irq_ops, lnw); 370 &lnw_gpio_irq_ops, lnw);
389 if (!lnw->domain) { 371 if (!lnw->domain)
390 retval = -ENOMEM; 372 return -ENOMEM;
391 goto err_ioremap;
392 }
393 373
394 pci_set_drvdata(pdev, lnw); 374 pci_set_drvdata(pdev, lnw);
395 retval = gpiochip_add(&lnw->chip); 375 retval = gpiochip_add(&lnw->chip);
396 if (retval) { 376 if (retval) {
397 dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval); 377 dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval);
398 goto err_ioremap; 378 return retval;
399 } 379 }
400 380
401 lnw_irq_init_hw(lnw); 381 lnw_irq_init_hw(lnw);
@@ -407,12 +387,6 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
407 pm_runtime_allow(&pdev->dev); 387 pm_runtime_allow(&pdev->dev);
408 388
409 return 0; 389 return 0;
410
411err_ioremap:
412 pci_release_regions(pdev);
413err_pci_req_region:
414 pci_disable_device(pdev);
415 return retval;
416} 390}
417 391
418static struct pci_driver lnw_gpio_driver = { 392static struct pci_driver lnw_gpio_driver = {
@@ -430,23 +404,20 @@ static int wp_gpio_probe(struct platform_device *pdev)
430 struct lnw_gpio *lnw; 404 struct lnw_gpio *lnw;
431 struct gpio_chip *gc; 405 struct gpio_chip *gc;
432 struct resource *rc; 406 struct resource *rc;
433 int retval = 0; 407 int retval;
434
435 rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
436 if (!rc)
437 return -EINVAL;
438 408
439 lnw = kzalloc(sizeof(struct lnw_gpio), GFP_KERNEL); 409 lnw = devm_kzalloc(&pdev->dev, sizeof(struct lnw_gpio), GFP_KERNEL);
440 if (!lnw) { 410 if (!lnw) {
441 dev_err(&pdev->dev, 411 dev_err(&pdev->dev,
442 "can't allocate whitneypoint_gpio chip data\n"); 412 "can't allocate whitneypoint_gpio chip data\n");
443 return -ENOMEM; 413 return -ENOMEM;
444 } 414 }
445 lnw->reg_base = ioremap_nocache(rc->start, resource_size(rc)); 415
446 if (lnw->reg_base == NULL) { 416 rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
447 retval = -EINVAL; 417 lnw->reg_base = devm_ioremap_resource(&pdev->dev, rc);
448 goto err_kmalloc; 418 if (IS_ERR(lnw->reg_base))
449 } 419 return PTR_ERR(lnw->reg_base);
420
450 spin_lock_init(&lnw->lock); 421 spin_lock_init(&lnw->lock);
451 gc = &lnw->chip; 422 gc = &lnw->chip;
452 gc->label = dev_name(&pdev->dev); 423 gc->label = dev_name(&pdev->dev);
@@ -463,15 +434,10 @@ static int wp_gpio_probe(struct platform_device *pdev)
463 if (retval) { 434 if (retval) {
464 dev_err(&pdev->dev, "whitneypoint gpiochip_add error %d\n", 435 dev_err(&pdev->dev, "whitneypoint gpiochip_add error %d\n",
465 retval); 436 retval);
466 goto err_ioremap; 437 return retval;
467 } 438 }
468 platform_set_drvdata(pdev, lnw); 439 platform_set_drvdata(pdev, lnw);
469 return 0; 440 return 0;
470err_ioremap:
471 iounmap(lnw->reg_base);
472err_kmalloc:
473 kfree(lnw);
474 return retval;
475} 441}
476 442
477static int wp_gpio_remove(struct platform_device *pdev) 443static int wp_gpio_remove(struct platform_device *pdev)
@@ -481,8 +447,6 @@ static int wp_gpio_remove(struct platform_device *pdev)
481 err = gpiochip_remove(&lnw->chip); 447 err = gpiochip_remove(&lnw->chip);
482 if (err) 448 if (err)
483 dev_err(&pdev->dev, "failed to remove gpio_chip.\n"); 449 dev_err(&pdev->dev, "failed to remove gpio_chip.\n");
484 iounmap(lnw->reg_base);
485 kfree(lnw);
486 return 0; 450 return 0;
487} 451}
488 452