Commit 9381fc5d authored by Andy Shevchenko's avatar Andy Shevchenko

gpio: sodaville: Convert to 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>
parent 6ad02b29
...@@ -155,8 +155,10 @@ static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd, ...@@ -155,8 +155,10 @@ static int sdv_register_irqsupport(struct sdv_gpio_chip_data *sd,
* we unmask & ACK the IRQ before the source of the interrupt is gone * we unmask & ACK the IRQ before the source of the interrupt is gone
* then the interrupt is active again. * then the interrupt is active again.
*/ */
sd->gc = irq_alloc_generic_chip("sdv-gpio", 1, sd->irq_base, sd->gc = devm_irq_alloc_generic_chip(&pdev->dev, "sdv-gpio", 1,
sd->gpio_pub_base, handle_fasteoi_irq); sd->irq_base,
sd->gpio_pub_base,
handle_fasteoi_irq);
if (!sd->gc) if (!sd->gc)
return -ENOMEM; return -ENOMEM;
...@@ -186,70 +188,52 @@ static int sdv_gpio_probe(struct pci_dev *pdev, ...@@ -186,70 +188,52 @@ static int sdv_gpio_probe(struct pci_dev *pdev,
const struct pci_device_id *pci_id) const struct pci_device_id *pci_id)
{ {
struct sdv_gpio_chip_data *sd; struct sdv_gpio_chip_data *sd;
unsigned long addr;
const void *prop;
int len;
int ret; int ret;
u32 mux_val; u32 mux_val;
sd = kzalloc(sizeof(struct sdv_gpio_chip_data), GFP_KERNEL); sd = devm_kzalloc(&pdev->dev, sizeof(*sd), GFP_KERNEL);
if (!sd) if (!sd)
return -ENOMEM; return -ENOMEM;
ret = pci_enable_device(pdev);
ret = pcim_enable_device(pdev);
if (ret) { if (ret) {
dev_err(&pdev->dev, "can't enable device.\n"); dev_err(&pdev->dev, "can't enable device.\n");
goto done; return ret;
} }
ret = pci_request_region(pdev, GPIO_BAR, DRV_NAME); ret = pcim_iomap_regions(pdev, 1 << GPIO_BAR, DRV_NAME);
if (ret) { if (ret) {
dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR); dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR);
goto disable_pci; return ret;
} }
addr = pci_resource_start(pdev, GPIO_BAR); sd->gpio_pub_base = pcim_iomap_table(pdev)[GPIO_BAR];
if (!addr) {
ret = -ENODEV;
goto release_reg;
}
sd->gpio_pub_base = ioremap(addr, pci_resource_len(pdev, GPIO_BAR));
prop = of_get_property(pdev->dev.of_node, "intel,muxctl", &len); ret = of_property_read_u32(pdev->dev.of_node, "intel,muxctl", &mux_val);
if (prop && len == 4) { if (!ret)
mux_val = of_read_number(prop, 1);
writel(mux_val, sd->gpio_pub_base + GPMUXCTL); writel(mux_val, sd->gpio_pub_base + GPMUXCTL);
}
ret = bgpio_init(&sd->chip, &pdev->dev, 4, ret = bgpio_init(&sd->chip, &pdev->dev, 4,
sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR, sd->gpio_pub_base + GPINR, sd->gpio_pub_base + GPOUTR,
NULL, sd->gpio_pub_base + GPOER, NULL, 0); NULL, sd->gpio_pub_base + GPOER, NULL, 0);
if (ret) if (ret)
goto unmap; return ret;
sd->chip.ngpio = SDV_NUM_PUB_GPIOS; sd->chip.ngpio = SDV_NUM_PUB_GPIOS;
ret = gpiochip_add_data(&sd->chip, sd); ret = devm_gpiochip_add_data(&pdev->dev, &sd->chip, sd);
if (ret < 0) { if (ret < 0) {
dev_err(&pdev->dev, "gpiochip_add() failed.\n"); dev_err(&pdev->dev, "gpiochip_add() failed.\n");
goto unmap; return ret;
} }
ret = sdv_register_irqsupport(sd, pdev); ret = sdv_register_irqsupport(sd, pdev);
if (ret) if (ret)
goto unmap; return ret;
pci_set_drvdata(pdev, sd); pci_set_drvdata(pdev, sd);
dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n"); dev_info(&pdev->dev, "Sodaville GPIO driver registered.\n");
return 0; return 0;
unmap:
iounmap(sd->gpio_pub_base);
release_reg:
pci_release_region(pdev, GPIO_BAR);
disable_pci:
pci_disable_device(pdev);
done:
kfree(sd);
return ret;
} }
static const struct pci_device_id sdv_gpio_pci_ids[] = { static const struct pci_device_id sdv_gpio_pci_ids[] = {
......
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