[PATCH 3/4] gpio: clps711x: Update driver
Alexander Shiyan
shc_work at mail.ru
Thu Jan 23 12:22:06 EST 2014
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 at mail.ru>
---
drivers/gpio/gpio-clps711x.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c
index feead51..2f12439 100644
--- a/drivers/gpio/gpio-clps711x.c
+++ b/drivers/gpio/gpio-clps711x.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2013 Alexander Shiyan <shc_work at mail.ru>
+ * Copyright (C) 2013-2014 Alexander Shiyan <shc_work at mail.ru>
*
* This program is free software; you can redistribute it and/or
* 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)
{
- int err;
+ int err, id = dev->id;
void __iomem *dat, *dir = NULL, *dir_inv = NULL;
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;
dat = dev_request_mem_region(dev, 0);
- switch (dev->id) {
+ switch (id) {
case 3:
dir_inv = dev_request_mem_region(dev, 1);
break;
@@ -40,27 +43,35 @@ static int clps711x_gpio_probe(struct device_d *dev)
return -ENOMEM;
err = bgpio_init(bgc, dev, 1, dat, NULL, NULL, dir, dir_inv, 0);
- if (err) {
- free(bgc);
- return err;
- }
+ if (err)
+ goto out_err;
- bgc->gc.base = dev->id * 8;
- switch (dev->id) {
+ bgc->gc.base = id * 8;
+ switch (id) {
case 4:
bgc->gc.ngpio = 3;
break;
default:
- bgc->gc.ngpio = 8;
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 = {
- .name = "clps711x-gpio",
- .probe = clps711x_gpio_probe,
+ .name = "clps711x-gpio",
+ .probe = clps711x_gpio_probe,
+ .of_compatible = DRV_OF_COMPAT(clps711x_gpio_dt_ids),
};
static __init int clps711x_gpio_register(void)
--
1.8.3.2
More information about the barebox
mailing list