Commit df966694 authored by Andres Salomon's avatar Andres Salomon Committed by Samuel Ortiz

gpio: Convert cs5535 from pci device to platform device

The cs5535-mfd driver now takes care of the PCI BAR handling; this
simplifies the gpio driver a lot.
Signed-off-by: default avatarAndres Salomon <dilinger@queued.net>
Signed-off-by: default avatarSamuel Ortiz <sameo@linux.intel.com>
parent 816b4580
...@@ -11,14 +11,13 @@ ...@@ -11,14 +11,13 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/pci.h> #include <linux/platform_device.h>
#include <linux/gpio.h> #include <linux/gpio.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/cs5535.h> #include <linux/cs5535.h>
#include <asm/msr.h> #include <asm/msr.h>
#define DRV_NAME "cs5535-gpio" #define DRV_NAME "cs5535-gpio"
#define GPIO_BAR 1
/* /*
* Some GPIO pins * Some GPIO pins
...@@ -47,7 +46,7 @@ static struct cs5535_gpio_chip { ...@@ -47,7 +46,7 @@ static struct cs5535_gpio_chip {
struct gpio_chip chip; struct gpio_chip chip;
resource_size_t base; resource_size_t base;
struct pci_dev *pdev; struct platform_device *pdev;
spinlock_t lock; spinlock_t lock;
} cs5535_gpio_chip; } cs5535_gpio_chip;
...@@ -301,10 +300,10 @@ static struct cs5535_gpio_chip cs5535_gpio_chip = { ...@@ -301,10 +300,10 @@ static struct cs5535_gpio_chip cs5535_gpio_chip = {
}, },
}; };
static int __init cs5535_gpio_probe(struct pci_dev *pdev, static int __devinit cs5535_gpio_probe(struct platform_device *pdev)
const struct pci_device_id *pci_id)
{ {
int err; struct resource *res;
int err = -EIO;
ulong mask_orig = mask; ulong mask_orig = mask;
/* There are two ways to get the GPIO base address; one is by /* There are two ways to get the GPIO base address; one is by
...@@ -314,25 +313,24 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev, ...@@ -314,25 +313,24 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev,
* it turns out to be unreliable in the face of crappy BIOSes, we * it turns out to be unreliable in the face of crappy BIOSes, we
* can always go back to using MSRs.. */ * can always go back to using MSRs.. */
err = pci_enable_device_io(pdev); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (err) { if (!res) {
dev_err(&pdev->dev, "can't enable device IO\n"); dev_err(&pdev->dev, "can't fetch device resource info\n");
goto done; goto done;
} }
err = pci_request_region(pdev, GPIO_BAR, DRV_NAME); if (!request_region(res->start, resource_size(res), pdev->name)) {
if (err) { dev_err(&pdev->dev, "can't request region\n");
dev_err(&pdev->dev, "can't alloc PCI BAR #%d\n", GPIO_BAR);
goto done; goto done;
} }
/* set up the driver-specific struct */ /* set up the driver-specific struct */
cs5535_gpio_chip.base = pci_resource_start(pdev, GPIO_BAR); cs5535_gpio_chip.base = res->start;
cs5535_gpio_chip.pdev = pdev; cs5535_gpio_chip.pdev = pdev;
spin_lock_init(&cs5535_gpio_chip.lock); spin_lock_init(&cs5535_gpio_chip.lock);
dev_info(&pdev->dev, "allocated PCI BAR #%d: base 0x%llx\n", GPIO_BAR, dev_info(&pdev->dev, "region 0x%x - 0x%x reserved\n",
(unsigned long long) cs5535_gpio_chip.base); res->start, res->end);
/* mask out reserved pins */ /* mask out reserved pins */
mask &= 0x1F7FFFFF; mask &= 0x1F7FFFFF;
...@@ -350,78 +348,49 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev, ...@@ -350,78 +348,49 @@ static int __init cs5535_gpio_probe(struct pci_dev *pdev,
if (err) if (err)
goto release_region; goto release_region;
dev_info(&pdev->dev, DRV_NAME ": GPIO support successfully loaded.\n"); dev_info(&pdev->dev, "GPIO support successfully loaded.\n");
return 0; return 0;
release_region: release_region:
pci_release_region(pdev, GPIO_BAR); release_region(res->start, resource_size(res));
done: done:
return err; return err;
} }
static void __exit cs5535_gpio_remove(struct pci_dev *pdev) static int __devexit cs5535_gpio_remove(struct platform_device *pdev)
{ {
struct resource *r;
int err; int err;
err = gpiochip_remove(&cs5535_gpio_chip.chip); err = gpiochip_remove(&cs5535_gpio_chip.chip);
if (err) { if (err) {
/* uhh? */ /* uhh? */
dev_err(&pdev->dev, "unable to remove gpio_chip?\n"); dev_err(&pdev->dev, "unable to remove gpio_chip?\n");
return err;
} }
pci_release_region(pdev, GPIO_BAR);
}
static struct pci_device_id cs5535_gpio_pci_tbl[] = {
{ PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_CS5535_ISA) },
{ PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA) },
{ 0, },
};
MODULE_DEVICE_TABLE(pci, cs5535_gpio_pci_tbl);
/* r = platform_get_resource(pdev, IORESOURCE_IO, 0);
* We can't use the standard PCI driver registration stuff here, since release_region(r->start, resource_size(r));
* that allows only one driver to bind to each PCI device (and we want return 0;
* multiple drivers to be able to bind to the device). Instead, manually
* scan for the PCI device, request a single region, and keep track of the
* devices that we're using.
*/
static int __init cs5535_gpio_scan_pci(void)
{
struct pci_dev *pdev;
int err = -ENODEV;
int i;
for (i = 0; i < ARRAY_SIZE(cs5535_gpio_pci_tbl); i++) {
pdev = pci_get_device(cs5535_gpio_pci_tbl[i].vendor,
cs5535_gpio_pci_tbl[i].device, NULL);
if (pdev) {
err = cs5535_gpio_probe(pdev, &cs5535_gpio_pci_tbl[i]);
if (err)
pci_dev_put(pdev);
/* we only support a single CS5535/6 southbridge */
break;
}
}
return err;
} }
static void __exit cs5535_gpio_free_pci(void) static struct platform_driver cs5535_gpio_drv = {
{ .driver = {
cs5535_gpio_remove(cs5535_gpio_chip.pdev); .name = DRV_NAME,
pci_dev_put(cs5535_gpio_chip.pdev); .owner = THIS_MODULE,
} },
.probe = cs5535_gpio_probe,
.remove = __devexit_p(cs5535_gpio_remove),
};
static int __init cs5535_gpio_init(void) static int __init cs5535_gpio_init(void)
{ {
return cs5535_gpio_scan_pci(); return platform_driver_register(&cs5535_gpio_drv);
} }
static void __exit cs5535_gpio_exit(void) static void __exit cs5535_gpio_exit(void)
{ {
cs5535_gpio_free_pci(); platform_driver_unregister(&cs5535_gpio_drv);
} }
module_init(cs5535_gpio_init); module_init(cs5535_gpio_init);
......
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