diff options
Diffstat (limited to 'drivers/gpio')
-rw-r--r-- | drivers/gpio/gpio-clps711x.c | 39 | ||||
-rw-r--r-- | drivers/gpio/gpiolib.c | 26 |
2 files changed, 44 insertions, 21 deletions
diff --git a/drivers/gpio/gpio-clps711x.c b/drivers/gpio/gpio-clps711x.c index feead51527..2f12439e0f 100644 --- a/drivers/gpio/gpio-clps711x.c +++ b/drivers/gpio/gpio-clps711x.c @@ -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 * 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) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cafef907ef..193c36ca29 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -50,22 +50,33 @@ int gpio_request(unsigned gpio, const char *label) struct gpio_info *gi = gpio_to_desc(gpio); int ret; - if (!gi) - return -ENODEV; + if (!gi) { + ret = -ENODEV; + goto done; + } - if (gi->requested) - return -EBUSY; + if (gi->requested) { + ret = -EBUSY; + goto done; + } + + ret = 0; if (gi->chip->ops->request) { ret = gi->chip->ops->request(gi->chip, gpio - gi->chip->base); if (ret) - return ret; + goto done; } gi->requested = true; gi->label = xstrdup(label); - return 0; +done: + if (ret) + pr_err("_gpio_request: gpio-%d (%s) status %d\n", + gpio, label ? : "?", ret); + + return ret; } void gpio_free(unsigned gpio) @@ -83,6 +94,7 @@ void gpio_free(unsigned gpio) gi->requested = false; free(gi->label); + gi->label = NULL; } /** @@ -322,7 +334,7 @@ static int do_gpiolib(int argc, char *argv[]) 3, (dir < 0) ? "unk" : ((dir == GPIOF_DIR_IN) ? "in" : "out"), 3, (val < 0) ? "unk" : ((val == 0) ? "lo" : "hi"), 9, gi->requested ? "true" : "false", - gi->label ? gi->label : ""); + (gi->requested && gi->label) ? gi->label : ""); } return 0; |