Skip to content

Commit

Permalink
gpio: add gpiod_toggle_active_low()
Browse files Browse the repository at this point in the history
Add possibility to toggle active-low flag of a gpio descriptor. This is
useful for compatibility code, where defaults are inverted vs DT gpio
flags or the active-low flag is taken from elsewhere.

Acked-by: Linus Walleij <[email protected]>
Signed-off-by: Michał Mirosław <[email protected]>
Link: https://lore.kernel.org/r/7ce0338e01ad17fa5a227176813941b41a7c35c1.1576031637.git.mirq-linux@rere.qmqm.pl
Signed-off-by: Ulf Hansson <[email protected]>
  • Loading branch information
osctobe authored and storulf committed Dec 18, 2019
1 parent 2c3039c commit d3a5bcb
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions drivers/gpio/gpiolib.c
Original file line number Diff line number Diff line change
Expand Up @@ -3363,6 +3363,17 @@ int gpiod_is_active_low(const struct gpio_desc *desc)
}
EXPORT_SYMBOL_GPL(gpiod_is_active_low);

/**
* gpiod_toggle_active_low - toggle whether a GPIO is active-low or not
* @desc: the gpio descriptor to change
*/
void gpiod_toggle_active_low(struct gpio_desc *desc)
{
VALIDATE_DESC_VOID(desc);
change_bit(FLAG_ACTIVE_LOW, &desc->flags);
}
EXPORT_SYMBOL_GPL(gpiod_toggle_active_low);

/* I/O calls are only valid after configuration completed; the relevant
* "is this a valid GPIO" error checks should already have been done.
*
Expand Down
7 changes: 7 additions & 0 deletions include/linux/gpio/consumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ int gpiod_set_raw_array_value_cansleep(unsigned int array_size,

int gpiod_set_debounce(struct gpio_desc *desc, unsigned debounce);
int gpiod_set_transitory(struct gpio_desc *desc, bool transitory);
void gpiod_toggle_active_low(struct gpio_desc *desc);

int gpiod_is_active_low(const struct gpio_desc *desc);
int gpiod_cansleep(const struct gpio_desc *desc);
Expand Down Expand Up @@ -483,6 +484,12 @@ static inline int gpiod_set_transitory(struct gpio_desc *desc, bool transitory)
return -ENOSYS;
}

static inline void gpiod_toggle_active_low(struct gpio_desc *desc)
{
/* GPIO can never have been requested */
WARN_ON(desc);
}

static inline int gpiod_is_active_low(const struct gpio_desc *desc)
{
/* GPIO can never have been requested */
Expand Down

0 comments on commit d3a5bcb

Please sign in to comment.