diff options
Diffstat (limited to 'drivers/gpio/gpiolib.c')
-rw-r--r-- | drivers/gpio/gpiolib.c | 52 |
1 files changed, 16 insertions, 36 deletions
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 570771ed19e6..be74bd370f1f 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c | |||
@@ -1352,14 +1352,6 @@ static int __gpiod_request(struct gpio_desc *desc, const char *label) | |||
1352 | spin_lock_irqsave(&gpio_lock, flags); | 1352 | spin_lock_irqsave(&gpio_lock, flags); |
1353 | } | 1353 | } |
1354 | done: | 1354 | done: |
1355 | if (status < 0) { | ||
1356 | /* Clear flags that might have been set by the caller before | ||
1357 | * requesting the GPIO. | ||
1358 | */ | ||
1359 | clear_bit(FLAG_ACTIVE_LOW, &desc->flags); | ||
1360 | clear_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
1361 | clear_bit(FLAG_OPEN_SOURCE, &desc->flags); | ||
1362 | } | ||
1363 | spin_unlock_irqrestore(&gpio_lock, flags); | 1355 | spin_unlock_irqrestore(&gpio_lock, flags); |
1364 | return status; | 1356 | return status; |
1365 | } | 1357 | } |
@@ -2587,28 +2579,13 @@ struct gpio_desc *__must_check gpiod_get_optional(struct device *dev, | |||
2587 | } | 2579 | } |
2588 | EXPORT_SYMBOL_GPL(gpiod_get_optional); | 2580 | EXPORT_SYMBOL_GPL(gpiod_get_optional); |
2589 | 2581 | ||
2590 | /** | ||
2591 | * gpiod_parse_flags - helper function to parse GPIO lookup flags | ||
2592 | * @desc: gpio to be setup | ||
2593 | * @lflags: gpio_lookup_flags - returned from of_find_gpio() or | ||
2594 | * of_get_gpio_hog() | ||
2595 | * | ||
2596 | * Set the GPIO descriptor flags based on the given GPIO lookup flags. | ||
2597 | */ | ||
2598 | static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags) | ||
2599 | { | ||
2600 | if (lflags & GPIO_ACTIVE_LOW) | ||
2601 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | ||
2602 | if (lflags & GPIO_OPEN_DRAIN) | ||
2603 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
2604 | if (lflags & GPIO_OPEN_SOURCE) | ||
2605 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | ||
2606 | } | ||
2607 | 2582 | ||
2608 | /** | 2583 | /** |
2609 | * gpiod_configure_flags - helper function to configure a given GPIO | 2584 | * gpiod_configure_flags - helper function to configure a given GPIO |
2610 | * @desc: gpio whose value will be assigned | 2585 | * @desc: gpio whose value will be assigned |
2611 | * @con_id: function within the GPIO consumer | 2586 | * @con_id: function within the GPIO consumer |
2587 | * @lflags: gpio_lookup_flags - returned from of_find_gpio() or | ||
2588 | * of_get_gpio_hog() | ||
2612 | * @dflags: gpiod_flags - optional GPIO initialization flags | 2589 | * @dflags: gpiod_flags - optional GPIO initialization flags |
2613 | * | 2590 | * |
2614 | * Return 0 on success, -ENOENT if no GPIO has been assigned to the | 2591 | * Return 0 on success, -ENOENT if no GPIO has been assigned to the |
@@ -2616,10 +2593,17 @@ static void gpiod_parse_flags(struct gpio_desc *desc, unsigned long lflags) | |||
2616 | * occurred while trying to acquire the GPIO. | 2593 | * occurred while trying to acquire the GPIO. |
2617 | */ | 2594 | */ |
2618 | static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, | 2595 | static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id, |
2619 | enum gpiod_flags dflags) | 2596 | unsigned long lflags, enum gpiod_flags dflags) |
2620 | { | 2597 | { |
2621 | int status; | 2598 | int status; |
2622 | 2599 | ||
2600 | if (lflags & GPIO_ACTIVE_LOW) | ||
2601 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | ||
2602 | if (lflags & GPIO_OPEN_DRAIN) | ||
2603 | set_bit(FLAG_OPEN_DRAIN, &desc->flags); | ||
2604 | if (lflags & GPIO_OPEN_SOURCE) | ||
2605 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | ||
2606 | |||
2623 | /* No particular flag request, return here... */ | 2607 | /* No particular flag request, return here... */ |
2624 | if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { | 2608 | if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) { |
2625 | pr_debug("no flags found for %s\n", con_id); | 2609 | pr_debug("no flags found for %s\n", con_id); |
@@ -2686,13 +2670,11 @@ struct gpio_desc *__must_check gpiod_get_index(struct device *dev, | |||
2686 | return desc; | 2670 | return desc; |
2687 | } | 2671 | } |
2688 | 2672 | ||
2689 | gpiod_parse_flags(desc, lookupflags); | ||
2690 | |||
2691 | status = gpiod_request(desc, con_id); | 2673 | status = gpiod_request(desc, con_id); |
2692 | if (status < 0) | 2674 | if (status < 0) |
2693 | return ERR_PTR(status); | 2675 | return ERR_PTR(status); |
2694 | 2676 | ||
2695 | status = gpiod_configure_flags(desc, con_id, flags); | 2677 | status = gpiod_configure_flags(desc, con_id, lookupflags, flags); |
2696 | if (status < 0) { | 2678 | if (status < 0) { |
2697 | dev_dbg(dev, "setup of GPIO %s failed\n", con_id); | 2679 | dev_dbg(dev, "setup of GPIO %s failed\n", con_id); |
2698 | gpiod_put(desc); | 2680 | gpiod_put(desc); |
@@ -2748,6 +2730,10 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | |||
2748 | if (IS_ERR(desc)) | 2730 | if (IS_ERR(desc)) |
2749 | return desc; | 2731 | return desc; |
2750 | 2732 | ||
2733 | ret = gpiod_request(desc, NULL); | ||
2734 | if (ret) | ||
2735 | return ERR_PTR(ret); | ||
2736 | |||
2751 | if (active_low) | 2737 | if (active_low) |
2752 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); | 2738 | set_bit(FLAG_ACTIVE_LOW, &desc->flags); |
2753 | 2739 | ||
@@ -2758,10 +2744,6 @@ struct gpio_desc *fwnode_get_named_gpiod(struct fwnode_handle *fwnode, | |||
2758 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); | 2744 | set_bit(FLAG_OPEN_SOURCE, &desc->flags); |
2759 | } | 2745 | } |
2760 | 2746 | ||
2761 | ret = gpiod_request(desc, NULL); | ||
2762 | if (ret) | ||
2763 | return ERR_PTR(ret); | ||
2764 | |||
2765 | return desc; | 2747 | return desc; |
2766 | } | 2748 | } |
2767 | EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod); | 2749 | EXPORT_SYMBOL_GPL(fwnode_get_named_gpiod); |
@@ -2814,8 +2796,6 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, | |||
2814 | chip = gpiod_to_chip(desc); | 2796 | chip = gpiod_to_chip(desc); |
2815 | hwnum = gpio_chip_hwgpio(desc); | 2797 | hwnum = gpio_chip_hwgpio(desc); |
2816 | 2798 | ||
2817 | gpiod_parse_flags(desc, lflags); | ||
2818 | |||
2819 | local_desc = gpiochip_request_own_desc(chip, hwnum, name); | 2799 | local_desc = gpiochip_request_own_desc(chip, hwnum, name); |
2820 | if (IS_ERR(local_desc)) { | 2800 | if (IS_ERR(local_desc)) { |
2821 | status = PTR_ERR(local_desc); | 2801 | status = PTR_ERR(local_desc); |
@@ -2824,7 +2804,7 @@ int gpiod_hog(struct gpio_desc *desc, const char *name, | |||
2824 | return status; | 2804 | return status; |
2825 | } | 2805 | } |
2826 | 2806 | ||
2827 | status = gpiod_configure_flags(desc, name, dflags); | 2807 | status = gpiod_configure_flags(desc, name, lflags, dflags); |
2828 | if (status < 0) { | 2808 | if (status < 0) { |
2829 | pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n", | 2809 | pr_err("setup of hog GPIO %s (chip %s, offset %d) failed, %d\n", |
2830 | name, chip->label, hwnum, status); | 2810 | name, chip->label, hwnum, status); |