summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/gpio/gpio-pch.c64
1 files changed, 12 insertions, 52 deletions
diff --git a/drivers/gpio/gpio-pch.c b/drivers/gpio/gpio-pch.c
index ffce0ab912ed..789e60ea2ac5 100644
--- a/drivers/gpio/gpio-pch.c
+++ b/drivers/gpio/gpio-pch.c
@@ -367,29 +367,24 @@ static int pch_gpio_probe(struct pci_dev *pdev,
367 int irq_base; 367 int irq_base;
368 u32 msk; 368 u32 msk;
369 369
370 chip = kzalloc(sizeof(*chip), GFP_KERNEL); 370 chip = devm_kzalloc(&pdev->dev, sizeof(*chip), GFP_KERNEL);
371 if (chip == NULL) 371 if (chip == NULL)
372 return -ENOMEM; 372 return -ENOMEM;
373 373
374 chip->dev = &pdev->dev; 374 chip->dev = &pdev->dev;
375 ret = pci_enable_device(pdev); 375 ret = pcim_enable_device(pdev);
376 if (ret) { 376 if (ret) {
377 dev_err(&pdev->dev, "%s : pci_enable_device FAILED", __func__); 377 dev_err(&pdev->dev, "%s : pci_enable_device FAILED", __func__);
378 goto err_pci_enable; 378 return ret;
379 } 379 }
380 380
381 ret = pci_request_regions(pdev, KBUILD_MODNAME); 381 ret = pcim_iomap_regions(pdev, 1 << 1, KBUILD_MODNAME);
382 if (ret) { 382 if (ret) {
383 dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret); 383 dev_err(&pdev->dev, "pci_request_regions FAILED-%d", ret);
384 goto err_request_regions; 384 return ret;
385 } 385 }
386 386
387 chip->base = pci_iomap(pdev, 1, 0); 387 chip->base = pcim_iomap_table(pdev)[1];
388 if (!chip->base) {
389 dev_err(&pdev->dev, "%s : pci_iomap FAILED", __func__);
390 ret = -ENOMEM;
391 goto err_iomap;
392 }
393 388
394 if (pdev->device == 0x8803) 389 if (pdev->device == 0x8803)
395 chip->ioh = INTEL_EG20T_PCH; 390 chip->ioh = INTEL_EG20T_PCH;
@@ -405,10 +400,10 @@ static int pch_gpio_probe(struct pci_dev *pdev,
405#ifdef CONFIG_OF_GPIO 400#ifdef CONFIG_OF_GPIO
406 chip->gpio.of_node = pdev->dev.of_node; 401 chip->gpio.of_node = pdev->dev.of_node;
407#endif 402#endif
408 ret = gpiochip_add_data(&chip->gpio, chip); 403 ret = devm_gpiochip_add_data(&pdev->dev, &chip->gpio, chip);
409 if (ret) { 404 if (ret) {
410 dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n"); 405 dev_err(&pdev->dev, "PCH gpio: Failed to register GPIO\n");
411 goto err_gpiochip_add; 406 return ret;
412 } 407 }
413 408
414 irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0, 409 irq_base = devm_irq_alloc_descs(&pdev->dev, -1, 0,
@@ -416,7 +411,7 @@ static int pch_gpio_probe(struct pci_dev *pdev,
416 if (irq_base < 0) { 411 if (irq_base < 0) {
417 dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n"); 412 dev_warn(&pdev->dev, "PCH gpio: Failed to get IRQ base num\n");
418 chip->irq_base = -1; 413 chip->irq_base = -1;
419 goto end; 414 return 0;
420 } 415 }
421 chip->irq_base = irq_base; 416 chip->irq_base = irq_base;
422 417
@@ -427,47 +422,13 @@ static int pch_gpio_probe(struct pci_dev *pdev,
427 422
428 ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler, 423 ret = devm_request_irq(&pdev->dev, pdev->irq, pch_gpio_handler,
429 IRQF_SHARED, KBUILD_MODNAME, chip); 424 IRQF_SHARED, KBUILD_MODNAME, chip);
430 if (ret != 0) { 425 if (ret) {
431 dev_err(&pdev->dev, 426 dev_err(&pdev->dev,
432 "%s request_irq failed\n", __func__); 427 "%s request_irq failed\n", __func__);
433 goto err_request_irq; 428 return ret;
434 } 429 }
435 430
436 ret = pch_gpio_alloc_generic_chip(chip, irq_base, 431 return pch_gpio_alloc_generic_chip(chip, irq_base, gpio_pins[chip->ioh]);
437 gpio_pins[chip->ioh]);
438 if (ret)
439 goto err_request_irq;
440
441end:
442 return 0;
443
444err_request_irq:
445 gpiochip_remove(&chip->gpio);
446
447err_gpiochip_add:
448 pci_iounmap(pdev, chip->base);
449
450err_iomap:
451 pci_release_regions(pdev);
452
453err_request_regions:
454 pci_disable_device(pdev);
455
456err_pci_enable:
457 kfree(chip);
458 dev_err(&pdev->dev, "%s Failed returns %d\n", __func__, ret);
459 return ret;
460}
461
462static void pch_gpio_remove(struct pci_dev *pdev)
463{
464 struct pch_gpio *chip = pci_get_drvdata(pdev);
465
466 gpiochip_remove(&chip->gpio);
467 pci_iounmap(pdev, chip->base);
468 pci_release_regions(pdev);
469 pci_disable_device(pdev);
470 kfree(chip);
471} 432}
472 433
473#ifdef CONFIG_PM 434#ifdef CONFIG_PM
@@ -538,7 +499,6 @@ static struct pci_driver pch_gpio_driver = {
538 .name = "pch_gpio", 499 .name = "pch_gpio",
539 .id_table = pch_gpio_pcidev_id, 500 .id_table = pch_gpio_pcidev_id,
540 .probe = pch_gpio_probe, 501 .probe = pch_gpio_probe,
541 .remove = pch_gpio_remove,
542 .suspend = pch_gpio_suspend, 502 .suspend = pch_gpio_suspend,
543 .resume = pch_gpio_resume 503 .resume = pch_gpio_resume
544}; 504};