Commit 786e07ec authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Linus Walleij

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarMika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: default avatarDavid Cohen <david.a.cohen@intel.com>
[Rebased on the platform-data set to NULL removal patch]
Signed-off-by: default avatarLinus Walleij <linus.walleij@linaro.org>
parent 64c8cbc1
...@@ -321,55 +321,37 @@ static int lnw_gpio_probe(struct pci_dev *pdev, ...@@ -321,55 +321,37 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
const struct pci_device_id *id) const struct pci_device_id *id)
{ {
void __iomem *base; void __iomem *base;
resource_size_t start, len;
struct lnw_gpio *lnw; struct lnw_gpio *lnw;
u32 gpio_base; u32 gpio_base;
u32 irq_base; u32 irq_base;
int retval; int retval;
int ngpio = id->driver_data; int ngpio = id->driver_data;
retval = pci_enable_device(pdev); retval = pcim_enable_device(pdev);
if (retval) if (retval)
return retval; return retval;
retval = pci_request_regions(pdev, "langwell_gpio"); retval = pcim_iomap_regions(pdev, 1 << 0 | 1 << 1, pci_name(pdev));
if (retval) { if (retval) {
dev_err(&pdev->dev, "error requesting resources\n"); dev_err(&pdev->dev, "I/O memory mapping error\n");
goto err_pci_req_region; return retval;
}
/* get the gpio_base from bar1 */
start = pci_resource_start(pdev, 1);
len = pci_resource_len(pdev, 1);
base = ioremap_nocache(start, len);
if (!base) {
dev_err(&pdev->dev, "error mapping bar1\n");
retval = -EFAULT;
goto err_ioremap;
} }
base = pcim_iomap_table(pdev)[1];
irq_base = readl(base); irq_base = readl(base);
gpio_base = readl(sizeof(u32) + base); gpio_base = readl(sizeof(u32) + base);
/* release the IO mapping, since we already get the info from bar1 */ /* release the IO mapping, since we already get the info from bar1 */
iounmap(base); pcim_iounmap_regions(pdev, 1 << 1);
/* get the register base from bar0 */
start = pci_resource_start(pdev, 0);
len = pci_resource_len(pdev, 0);
base = devm_ioremap_nocache(&pdev->dev, start, len);
if (!base) {
dev_err(&pdev->dev, "error mapping bar0\n");
retval = -EFAULT;
goto err_ioremap;
}
lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL); lnw = devm_kzalloc(&pdev->dev, sizeof(*lnw), GFP_KERNEL);
if (!lnw) { if (!lnw) {
dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n"); dev_err(&pdev->dev, "can't allocate langwell_gpio chip data\n");
retval = -ENOMEM; return -ENOMEM;
goto err_ioremap;
} }
lnw->reg_base = base; lnw->reg_base = pcim_iomap_table(pdev)[0];
lnw->chip.label = dev_name(&pdev->dev); lnw->chip.label = dev_name(&pdev->dev);
lnw->chip.request = lnw_gpio_request; lnw->chip.request = lnw_gpio_request;
lnw->chip.direction_input = lnw_gpio_direction_input; lnw->chip.direction_input = lnw_gpio_direction_input;
...@@ -386,16 +368,14 @@ static int lnw_gpio_probe(struct pci_dev *pdev, ...@@ -386,16 +368,14 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ngpio, irq_base, lnw->domain = irq_domain_add_simple(pdev->dev.of_node, ngpio, irq_base,
&lnw_gpio_irq_ops, lnw); &lnw_gpio_irq_ops, lnw);
if (!lnw->domain) { if (!lnw->domain)
retval = -ENOMEM; return -ENOMEM;
goto err_ioremap;
}
pci_set_drvdata(pdev, lnw); pci_set_drvdata(pdev, lnw);
retval = gpiochip_add(&lnw->chip); retval = gpiochip_add(&lnw->chip);
if (retval) { if (retval) {
dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval); dev_err(&pdev->dev, "langwell gpiochip_add error %d\n", retval);
goto err_ioremap; return retval;
} }
lnw_irq_init_hw(lnw); lnw_irq_init_hw(lnw);
...@@ -407,12 +387,6 @@ static int lnw_gpio_probe(struct pci_dev *pdev, ...@@ -407,12 +387,6 @@ static int lnw_gpio_probe(struct pci_dev *pdev,
pm_runtime_allow(&pdev->dev); pm_runtime_allow(&pdev->dev);
return 0; return 0;
err_ioremap:
pci_release_regions(pdev);
err_pci_req_region:
pci_disable_device(pdev);
return retval;
} }
static struct pci_driver lnw_gpio_driver = { static struct pci_driver lnw_gpio_driver = {
...@@ -430,23 +404,20 @@ static int wp_gpio_probe(struct platform_device *pdev) ...@@ -430,23 +404,20 @@ static int wp_gpio_probe(struct platform_device *pdev)
struct lnw_gpio *lnw; struct lnw_gpio *lnw;
struct gpio_chip *gc; struct gpio_chip *gc;
struct resource *rc; struct resource *rc;
int retval = 0; int retval;
rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!rc)
return -EINVAL;
lnw = kzalloc(sizeof(struct lnw_gpio), GFP_KERNEL); lnw = devm_kzalloc(&pdev->dev, sizeof(struct lnw_gpio), GFP_KERNEL);
if (!lnw) { if (!lnw) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"can't allocate whitneypoint_gpio chip data\n"); "can't allocate whitneypoint_gpio chip data\n");
return -ENOMEM; return -ENOMEM;
} }
lnw->reg_base = ioremap_nocache(rc->start, resource_size(rc));
if (lnw->reg_base == NULL) { rc = platform_get_resource(pdev, IORESOURCE_MEM, 0);
retval = -EINVAL; lnw->reg_base = devm_ioremap_resource(&pdev->dev, rc);
goto err_kmalloc; if (IS_ERR(lnw->reg_base))
} return PTR_ERR(lnw->reg_base);
spin_lock_init(&lnw->lock); spin_lock_init(&lnw->lock);
gc = &lnw->chip; gc = &lnw->chip;
gc->label = dev_name(&pdev->dev); gc->label = dev_name(&pdev->dev);
...@@ -463,15 +434,10 @@ static int wp_gpio_probe(struct platform_device *pdev) ...@@ -463,15 +434,10 @@ static int wp_gpio_probe(struct platform_device *pdev)
if (retval) { if (retval) {
dev_err(&pdev->dev, "whitneypoint gpiochip_add error %d\n", dev_err(&pdev->dev, "whitneypoint gpiochip_add error %d\n",
retval); retval);
goto err_ioremap; return retval;
} }
platform_set_drvdata(pdev, lnw); platform_set_drvdata(pdev, lnw);
return 0; return 0;
err_ioremap:
iounmap(lnw->reg_base);
err_kmalloc:
kfree(lnw);
return retval;
} }
static int wp_gpio_remove(struct platform_device *pdev) static int wp_gpio_remove(struct platform_device *pdev)
...@@ -481,8 +447,6 @@ static int wp_gpio_remove(struct platform_device *pdev) ...@@ -481,8 +447,6 @@ static int wp_gpio_remove(struct platform_device *pdev)
err = gpiochip_remove(&lnw->chip); err = gpiochip_remove(&lnw->chip);
if (err) if (err)
dev_err(&pdev->dev, "failed to remove gpio_chip.\n"); dev_err(&pdev->dev, "failed to remove gpio_chip.\n");
iounmap(lnw->reg_base);
kfree(lnw);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment