Commit ab278159 authored by Linus Torvalds's avatar Linus Torvalds

Merge tag 'gpio-v4.15-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio

Pull GPIO fix from Linus Walleij:
 "Fix a raw vs elaborate GPIO descriptor bug introduced by yours truly"

* tag 'gpio-v4.15-4' of git://git.kernel.org/pub/scm/linux/kernel/git/linusw/linux-gpio:
  gpio: Add missing open drain/source handling to gpiod_set_value_cansleep()
parents cbd0a6a2 1e77fc82
...@@ -2892,6 +2892,27 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int value) ...@@ -2892,6 +2892,27 @@ void gpiod_set_raw_value(struct gpio_desc *desc, int value)
} }
EXPORT_SYMBOL_GPL(gpiod_set_raw_value); EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
/**
* gpiod_set_value_nocheck() - set a GPIO line value without checking
* @desc: the descriptor to set the value on
* @value: value to set
*
* This sets the value of a GPIO line backing a descriptor, applying
* different semantic quirks like active low and open drain/source
* handling.
*/
static void gpiod_set_value_nocheck(struct gpio_desc *desc, int value)
{
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags))
value = !value;
if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
gpio_set_open_drain_value_commit(desc, value);
else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
gpio_set_open_source_value_commit(desc, value);
else
gpiod_set_raw_value_commit(desc, value);
}
/** /**
* gpiod_set_value() - assign a gpio's value * gpiod_set_value() - assign a gpio's value
* @desc: gpio whose value will be assigned * @desc: gpio whose value will be assigned
...@@ -2906,16 +2927,8 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_value); ...@@ -2906,16 +2927,8 @@ EXPORT_SYMBOL_GPL(gpiod_set_raw_value);
void gpiod_set_value(struct gpio_desc *desc, int value) void gpiod_set_value(struct gpio_desc *desc, int value)
{ {
VALIDATE_DESC_VOID(desc); VALIDATE_DESC_VOID(desc);
/* Should be using gpiod_set_value_cansleep() */
WARN_ON(desc->gdev->chip->can_sleep); WARN_ON(desc->gdev->chip->can_sleep);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) gpiod_set_value_nocheck(desc, value);
value = !value;
if (test_bit(FLAG_OPEN_DRAIN, &desc->flags))
gpio_set_open_drain_value_commit(desc, value);
else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags))
gpio_set_open_source_value_commit(desc, value);
else
gpiod_set_raw_value_commit(desc, value);
} }
EXPORT_SYMBOL_GPL(gpiod_set_value); EXPORT_SYMBOL_GPL(gpiod_set_value);
...@@ -3243,9 +3256,7 @@ void gpiod_set_value_cansleep(struct gpio_desc *desc, int value) ...@@ -3243,9 +3256,7 @@ void gpiod_set_value_cansleep(struct gpio_desc *desc, int value)
{ {
might_sleep_if(extra_checks); might_sleep_if(extra_checks);
VALIDATE_DESC_VOID(desc); VALIDATE_DESC_VOID(desc);
if (test_bit(FLAG_ACTIVE_LOW, &desc->flags)) gpiod_set_value_nocheck(desc, value);
value = !value;
gpiod_set_raw_value_commit(desc, value);
} }
EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep); EXPORT_SYMBOL_GPL(gpiod_set_value_cansleep);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment