Skip to content

Commit 05f479b

Browse files
charleskeepaxLinus Walleij
authored andcommitted
gpio: Add new flags to control sleep status of GPIOs
Add new flags to allow users to specify that they are not concerned with the status of GPIOs whilst in a sleep/low power state. Signed-off-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Acked-by: Rob Herring <robh@kernel.org> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
1 parent f9e3a41 commit 05f479b

7 files changed

Lines changed: 26 additions & 0 deletions

File tree

‎drivers/gpio/gpiolib-of.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ struct gpio_desc *of_find_gpio(struct device *dev, const char *con_id,
153153
*flags |= GPIO_OPEN_SOURCE;
154154
}
155155

156+
if (of_flags & OF_GPIO_SLEEP_MAY_LOOSE_VALUE)
157+
*flags |= GPIO_SLEEP_MAY_LOOSE_VALUE;
158+
156159
return desc;
157160
}
158161

‎drivers/gpio/gpiolib.c‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,6 +2869,16 @@ bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset)
28692869
}
28702870
EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source);
28712871

2872+
bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset)
2873+
{
2874+
if (offset >= chip->ngpio)
2875+
return false;
2876+
2877+
return !test_bit(FLAG_SLEEP_MAY_LOOSE_VALUE,
2878+
&chip->gpiodev->descs[offset].flags);
2879+
}
2880+
EXPORT_SYMBOL_GPL(gpiochip_line_is_persistent);
2881+
28722882
/**
28732883
* gpiod_get_raw_value_cansleep() - return a gpio's raw value
28742884
* @desc: gpio whose value will be returned
@@ -3225,6 +3235,8 @@ static int gpiod_configure_flags(struct gpio_desc *desc, const char *con_id,
32253235
set_bit(FLAG_OPEN_DRAIN, &desc->flags);
32263236
if (lflags & GPIO_OPEN_SOURCE)
32273237
set_bit(FLAG_OPEN_SOURCE, &desc->flags);
3238+
if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE)
3239+
set_bit(FLAG_SLEEP_MAY_LOOSE_VALUE, &desc->flags);
32283240

32293241
/* No particular flag request, return here... */
32303242
if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) {

‎drivers/gpio/gpiolib.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ struct gpio_desc {
190190
#define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */
191191
#define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */
192192
#define FLAG_IS_HOGGED 11 /* GPIO is hogged */
193+
#define FLAG_SLEEP_MAY_LOOSE_VALUE 12 /* GPIO may loose value in sleep */
193194

194195
/* Connection label */
195196
const char *label;

‎include/dt-bindings/gpio/gpio.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,8 @@
2828
#define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN)
2929
#define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE)
3030

31+
/* Bit 3 express GPIO suspend/resume persistence */
32+
#define GPIO_SLEEP_MAINTAIN_VALUE 0
33+
#define GPIO_SLEEP_MAY_LOOSE_VALUE 8
34+
3135
#endif

‎include/linux/gpio/driver.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset);
213213
bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset);
214214
bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset);
215215

216+
/* Sleep persistence inquiry for drivers */
217+
bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset);
218+
216219
/* get driver data */
217220
void *gpiochip_get_data(struct gpio_chip *chip);
218221

‎include/linux/gpio/machine.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ enum gpio_lookup_flags {
99
GPIO_ACTIVE_LOW = (1 << 0),
1010
GPIO_OPEN_DRAIN = (1 << 1),
1111
GPIO_OPEN_SOURCE = (1 << 2),
12+
GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3),
13+
GPIO_SLEEP_MAY_LOOSE_VALUE = (1 << 3),
1214
};
1315

1416
/**

‎include/linux/of_gpio.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ enum of_gpio_flags {
3131
OF_GPIO_ACTIVE_LOW = 0x1,
3232
OF_GPIO_SINGLE_ENDED = 0x2,
3333
OF_GPIO_OPEN_DRAIN = 0x4,
34+
OF_GPIO_SLEEP_MAY_LOOSE_VALUE = 0x8,
3435
};
3536

3637
#ifdef CONFIG_OF_GPIO

0 commit comments

Comments
 (0)