diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index cae1b8c5b08c..3ca36542e338 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -722,7 +722,7 @@ int gpio_export(unsigned gpio, bool direction_may_change) | |||
722 | unsigned long flags; | 722 | unsigned long flags; |
723 | struct gpio_desc *desc; | 723 | struct gpio_desc *desc; |
724 | int status = -EINVAL; | 724 | int status = -EINVAL; |
725 | char *ioname = NULL; | 725 | const char *ioname = NULL; |
726 | 726 | ||
727 | /* can't export until sysfs is available ... */ | 727 | /* can't export until sysfs is available ... */ |
728 | if (!gpio_class.p) { | 728 | if (!gpio_class.p) { |
@@ -753,7 +753,7 @@ int gpio_export(unsigned gpio, bool direction_may_change) | |||
753 | struct device *dev; | 753 | struct device *dev; |
754 | 754 | ||
755 | dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), | 755 | dev = device_create(&gpio_class, desc->chip->dev, MKDEV(0, 0), |
756 | desc, ioname ? ioname : "gpio%d", gpio); | 756 | desc, ioname ? ioname : "gpio%u", gpio); |
757 | if (!IS_ERR(dev)) { | 757 | if (!IS_ERR(dev)) { |
758 | status = sysfs_create_group(&dev->kobj, | 758 | status = sysfs_create_group(&dev->kobj, |
759 | &gpio_attr_group); | 759 | &gpio_attr_group); |
@@ -1106,7 +1106,7 @@ unlock: | |||
1106 | fail: | 1106 | fail: |
1107 | /* failures here can mean systems won't boot... */ | 1107 | /* failures here can mean systems won't boot... */ |
1108 | if (status) | 1108 | if (status) |
1109 | pr_err("gpiochip_add: gpios %d..%d (%s) not registered\n", | 1109 | pr_err("gpiochip_add: gpios %d..%d (%s) failed to register\n", |
1110 | chip->base, chip->base + chip->ngpio - 1, | 1110 | chip->base, chip->base + chip->ngpio - 1, |
1111 | chip->label ? : "generic"); | 1111 | chip->label ? : "generic"); |
1112 | return status; | 1112 | return status; |
@@ -1447,6 +1447,49 @@ fail: | |||
1447 | } | 1447 | } |
1448 | EXPORT_SYMBOL_GPL(gpio_direction_output); | 1448 | EXPORT_SYMBOL_GPL(gpio_direction_output); |
1449 | 1449 | ||
1450 | /** | ||
1451 | * gpio_set_debounce - sets @debounce time for a @gpio | ||
1452 | * @gpio: the gpio to set debounce time | ||
1453 | * @debounce: debounce time is microseconds | ||
1454 | */ | ||
1455 | int gpio_set_debounce(unsigned gpio, unsigned debounce) | ||
1456 | { | ||
1457 | unsigned long flags; | ||
1458 | struct gpio_chip *chip; | ||
1459 | struct gpio_desc *desc = &gpio_desc[gpio]; | ||
1460 | int status = -EINVAL; | ||
1461 | |||
1462 | spin_lock_irqsave(&gpio_lock, flags); | ||
1463 | |||
1464 | if (!gpio_is_valid(gpio)) | ||
1465 | goto fail; | ||
1466 | chip = desc->chip; | ||
1467 | if (!chip || !chip->set || !chip->set_debounce) | ||
1468 | goto fail; | ||
1469 | gpio -= chip->base; | ||
1470 | if (gpio >= chip->ngpio) | ||
1471 | goto fail; | ||
1472 | status = gpio_ensure_requested(desc, gpio); | ||
1473 | if (status < 0) | ||
1474 | goto fail; | ||
1475 | |||
1476 | /* now we know the gpio is valid and chip won't vanish */ | ||
1477 | |||
1478 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
1479 | |||
1480 | might_sleep_if(extra_checks && chip->can_sleep); | ||
1481 | |||
1482 | return chip->set_debounce(chip, gpio, debounce); | ||
1483 | |||
1484 | fail: | ||
1485 | spin_unlock_irqrestore(&gpio_lock, flags); | ||
1486 | if (status) | ||
1487 | pr_debug("%s: gpio-%d status %d\n", | ||
1488 | __func__, gpio, status); | ||
1489 | |||
1490 | return status; | ||
1491 | } | ||
1492 | EXPORT_SYMBOL_GPL(gpio_set_debounce); | ||
1450 | 1493 | ||
1451 | /* I/O calls are only valid after configuration completed; the relevant | 1494 | /* I/O calls are only valid after configuration completed; the relevant |
1452 | * "is this a valid GPIO" error checks should already have been done. | 1495 | * "is this a valid GPIO" error checks should already have been done. |