aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/gpio
diff options
context:
space:
mode:
authorAlexandre Courbot <acourbot@nvidia.com>2013-12-10 21:32:28 -0500
committerLinus Walleij <linus.walleij@linaro.org>2013-12-12 13:33:59 -0500
commit2a3cf6a3599e901528d3e0025a1bd0722a8d3575 (patch)
tree67bb549dbb30bf8a0a40395176aac02466a25c23 /drivers/gpio
parent3b31d0eca5fd8d7d485c7cb7319a5cd6a3207726 (diff)
gpiolib: return -ENOENT if no GPIO mapping exists
Some devices drivers make use of optional GPIO parameters. For such drivers, it is important to discriminate between the case where no GPIO mapping has been defined for the function they are requesting, and the case where a mapping exists but an error occured while resolving it or when acquiring the GPIO. This patch changes the family of gpiod_get() functions such that they will return -ENOENT if and only if no GPIO mapping is defined for the requested function. Other error codes are used when an actual error occured during the GPIO resolution. Signed-off-by: Alexandre Courbot <acourbot@nvidia.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Mika Westerberg <mika.westerberg@linux.intel.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/gpio')
-rw-r--r--drivers/gpio/gpiolib.c34
1 files changed, 17 insertions, 17 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index 12e47dfabd8d..c0b06a9adad9 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -2367,7 +2367,7 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2367 unsigned int idx, 2367 unsigned int idx,
2368 enum gpio_lookup_flags *flags) 2368 enum gpio_lookup_flags *flags)
2369{ 2369{
2370 struct gpio_desc *desc = ERR_PTR(-ENODEV); 2370 struct gpio_desc *desc = ERR_PTR(-ENOENT);
2371 struct gpiod_lookup_table *table; 2371 struct gpiod_lookup_table *table;
2372 struct gpiod_lookup *p; 2372 struct gpiod_lookup *p;
2373 2373
@@ -2389,19 +2389,22 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2389 chip = find_chip_by_name(p->chip_label); 2389 chip = find_chip_by_name(p->chip_label);
2390 2390
2391 if (!chip) { 2391 if (!chip) {
2392 dev_warn(dev, "cannot find GPIO chip %s\n", 2392 dev_err(dev, "cannot find GPIO chip %s\n",
2393 p->chip_label); 2393 p->chip_label);
2394 continue; 2394 return ERR_PTR(-ENODEV);
2395 } 2395 }
2396 2396
2397 if (chip->ngpio <= p->chip_hwnum) { 2397 if (chip->ngpio <= p->chip_hwnum) {
2398 dev_warn(dev, "GPIO chip %s has %d GPIOs\n", 2398 dev_err(dev,
2399 chip->label, chip->ngpio); 2399 "requested GPIO %d is out of range [0..%d] for chip %s\n",
2400 continue; 2400 idx, chip->ngpio, chip->label);
2401 return ERR_PTR(-EINVAL);
2401 } 2402 }
2402 2403
2403 desc = gpiochip_offset_to_desc(chip, p->chip_hwnum); 2404 desc = gpiochip_offset_to_desc(chip, p->chip_hwnum);
2404 *flags = p->flags; 2405 *flags = p->flags;
2406
2407 return desc;
2405 } 2408 }
2406 2409
2407 return desc; 2410 return desc;
@@ -2413,7 +2416,8 @@ static struct gpio_desc *gpiod_find(struct device *dev, const char *con_id,
2413 * @con_id: function within the GPIO consumer 2416 * @con_id: function within the GPIO consumer
2414 * 2417 *
2415 * Return the GPIO descriptor corresponding to the function con_id of device 2418 * Return the GPIO descriptor corresponding to the function con_id of device
2416 * dev, or an IS_ERR() condition if an error occured. 2419 * dev, -ENOENT if no GPIO has been assigned to the requested function, or
2420 * another IS_ERR() code if an error occured while trying to acquire the GPIO.
2417 */ 2421 */
2418struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id) 2422struct gpio_desc *__must_check gpiod_get(struct device *dev, const char *con_id)
2419{ 2423{
@@ -2430,7 +2434,9 @@ EXPORT_SYMBOL_GPL(gpiod_get);
2430 * This variant of gpiod_get() allows to access GPIOs other than the first 2434 * This variant of gpiod_get() allows to access GPIOs other than the first
2431 * defined one for functions that define several GPIOs. 2435 * defined one for functions that define several GPIOs.
2432 * 2436 *
2433 * Return a valid GPIO descriptor, or an IS_ERR() condition in case of error. 2437 * Return a valid GPIO descriptor, -ENOENT if no GPIO has been assigned to the
2438 * requested function and/or index, or another IS_ERR() code if an error
2439 * occured while trying to acquire the GPIO.
2434 */ 2440 */
2435struct gpio_desc *__must_check gpiod_get_index(struct device *dev, 2441struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2436 const char *con_id, 2442 const char *con_id,
@@ -2455,15 +2461,9 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev,
2455 * Either we are not using DT or ACPI, or their lookup did not return 2461 * Either we are not using DT or ACPI, or their lookup did not return
2456 * a result. In that case, use platform lookup as a fallback. 2462 * a result. In that case, use platform lookup as a fallback.
2457 */ 2463 */
2458 if (!desc || IS_ERR(desc)) { 2464 if (!desc || desc == ERR_PTR(-ENOENT)) {
2459 struct gpio_desc *pdesc;
2460
2461 dev_dbg(dev, "using lookup tables for GPIO lookup"); 2465 dev_dbg(dev, "using lookup tables for GPIO lookup");
2462 pdesc = gpiod_find(dev, con_id, idx, &flags); 2466 desc = gpiod_find(dev, con_id, idx, &flags);
2463
2464 /* If used as fallback, do not replace the previous error */
2465 if (!IS_ERR(pdesc) || !desc)
2466 desc = pdesc;
2467 } 2467 }
2468 2468
2469 if (IS_ERR(desc)) { 2469 if (IS_ERR(desc)) {