Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Charles Keepax and committed by
Linus Walleij
05f479bf f9e3a419

+26
+3
drivers/gpio/gpiolib-of.c
··· 153 153 *flags |= GPIO_OPEN_SOURCE; 154 154 } 155 155 156 + if (of_flags & OF_GPIO_SLEEP_MAY_LOOSE_VALUE) 157 + *flags |= GPIO_SLEEP_MAY_LOOSE_VALUE; 158 + 156 159 return desc; 157 160 } 158 161
+12
drivers/gpio/gpiolib.c
··· 2869 2869 } 2870 2870 EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source); 2871 2871 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 + 2872 2882 /** 2873 2883 * gpiod_get_raw_value_cansleep() - return a gpio's raw value 2874 2884 * @desc: gpio whose value will be returned ··· 3235 3225 set_bit(FLAG_OPEN_DRAIN, &desc->flags); 3236 3226 if (lflags & GPIO_OPEN_SOURCE) 3237 3227 set_bit(FLAG_OPEN_SOURCE, &desc->flags); 3228 + if (lflags & GPIO_SLEEP_MAY_LOOSE_VALUE) 3229 + set_bit(FLAG_SLEEP_MAY_LOOSE_VALUE, &desc->flags); 3238 3230 3239 3231 /* No particular flag request, return here... */ 3240 3232 if (!(dflags & GPIOD_FLAGS_BIT_DIR_SET)) {
+1
drivers/gpio/gpiolib.h
··· 190 190 #define FLAG_OPEN_SOURCE 8 /* Gpio is open source type */ 191 191 #define FLAG_USED_AS_IRQ 9 /* GPIO is connected to an IRQ */ 192 192 #define FLAG_IS_HOGGED 11 /* GPIO is hogged */ 193 + #define FLAG_SLEEP_MAY_LOOSE_VALUE 12 /* GPIO may loose value in sleep */ 193 194 194 195 /* Connection label */ 195 196 const char *label;
+4
include/dt-bindings/gpio/gpio.h
··· 28 28 #define GPIO_OPEN_DRAIN (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_DRAIN) 29 29 #define GPIO_OPEN_SOURCE (GPIO_SINGLE_ENDED | GPIO_LINE_OPEN_SOURCE) 30 30 31 + /* Bit 3 express GPIO suspend/resume persistence */ 32 + #define GPIO_SLEEP_MAINTAIN_VALUE 0 33 + #define GPIO_SLEEP_MAY_LOOSE_VALUE 8 34 + 31 35 #endif
+3
include/linux/gpio/driver.h
··· 213 213 bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset); 214 214 bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset); 215 215 216 + /* Sleep persistence inquiry for drivers */ 217 + bool gpiochip_line_is_persistent(struct gpio_chip *chip, unsigned int offset); 218 + 216 219 /* get driver data */ 217 220 void *gpiochip_get_data(struct gpio_chip *chip); 218 221
+2
include/linux/gpio/machine.h
··· 9 9 GPIO_ACTIVE_LOW = (1 << 0), 10 10 GPIO_OPEN_DRAIN = (1 << 1), 11 11 GPIO_OPEN_SOURCE = (1 << 2), 12 + GPIO_SLEEP_MAINTAIN_VALUE = (0 << 3), 13 + GPIO_SLEEP_MAY_LOOSE_VALUE = (1 << 3), 12 14 }; 13 15 14 16 /**
+1
include/linux/of_gpio.h
··· 31 31 OF_GPIO_ACTIVE_LOW = 0x1, 32 32 OF_GPIO_SINGLE_ENDED = 0x2, 33 33 OF_GPIO_OPEN_DRAIN = 0x4, 34 + OF_GPIO_SLEEP_MAY_LOOSE_VALUE = 0x8, 34 35 }; 35 36 36 37 #ifdef CONFIG_OF_GPIO