9
0
Fork 0

gpio: clps711x: Update driver

This patch updates the CLPS711X GPIO driver.
The update adds support for use with devicetree and
optimizes "probe" a bit.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
This commit is contained in:
Alexander Shiyan 2014-01-23 21:22:06 +04:00 committed by Sascha Hauer
parent 624454160b
commit 6c3e620e57
1 changed files with 25 additions and 14 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright (C) 2013 Alexander Shiyan <shc_work@mail.ru> * Copyright (C) 2013-2014 Alexander Shiyan <shc_work@mail.ru>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@ -15,15 +15,18 @@
static int clps711x_gpio_probe(struct device_d *dev) static int clps711x_gpio_probe(struct device_d *dev)
{ {
int err; int err, id = dev->id;
void __iomem *dat, *dir = NULL, *dir_inv = NULL; void __iomem *dat, *dir = NULL, *dir_inv = NULL;
struct bgpio_chip *bgc; struct bgpio_chip *bgc;
if ((dev->id < 0) || (dev->id > 4)) if (dev->device_node)
id = of_alias_get_id(dev->device_node, "gpio");
if (id < 0 || id > 4)
return -ENODEV; return -ENODEV;
dat = dev_request_mem_region(dev, 0); dat = dev_request_mem_region(dev, 0);
switch (dev->id) { switch (id) {
case 3: case 3:
dir_inv = dev_request_mem_region(dev, 1); dir_inv = dev_request_mem_region(dev, 1);
break; break;
@ -40,27 +43,35 @@ static int clps711x_gpio_probe(struct device_d *dev)
return -ENOMEM; return -ENOMEM;
err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0); err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
if (err) { if (err)
free(bgc); goto out_err;
return err;
}
bgc->gc.base = dev->id * 8; bgc->gc.base = id * 8;
switch (dev->id) { switch (id) {
case 4: case 4:
bgc->gc.ngpio = 3; bgc->gc.ngpio = 3;
break; break;
default: default:
bgc->gc.ngpio = 8;
break; break;
} }
return gpiochip_add(&bgc->gc); err = gpiochip_add(&bgc->gc);
out_err:
if (err)
free(bgc);
return err;
} }
static struct of_device_id __maybe_unused clps711x_gpio_dt_ids[] = {
{ .compatible = "cirrus,clps711x-gpio", },
};
static struct driver_d clps711x_gpio_driver = { static struct driver_d clps711x_gpio_driver = {
.name = "clps711x-gpio", .name = "clps711x-gpio",
.probe = clps711x_gpio_probe, .probe = clps711x_gpio_probe,
.of_compatible = DRV_OF_COMPAT(clps711x_gpio_dt_ids),
}; };
static __init int clps711x_gpio_register(void) static __init int clps711x_gpio_register(void)