gpiolib: Add !CONFIG_GPIOLIB definitions of devm_ functions
Subsystems (2)
PATCH 1/2 gpiolib: Add !CONFIG_GPIOLIB definitions of devm_ functions
Currently the managed gpio_request() and gpio_free() are not stubbed out for configurations not using gpiolib - do that to aid use in drivers.
--- include/linux/gpio.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)
include/linux/gpio.h +14 -0
@@ -89,6 +89,12 @@ static inline int gpio_request(unsigned gpio, const char *label)return -ENOSYS ; } +static inline int devm_gpio_request (struct device *dev,unsigned gpio, +const char *label) +{ +return -ENOSYS ; +} +static inline int gpio_request_one (unsigned gpio,unsigned long flags,const char *label) {
@@ -108,6 +114,14 @@ static inline void gpio_free(unsigned gpio)WARN_ON (1 ); } +static inline void devm_gpio_free (struct device *dev,unsigned gpio) +{ +might_sleep (); + +/* GPIO can never have been requested */ +WARN_ON (1 ); +} +static inline void gpio_free_array (const struct gpio *array,size_t num) {might_sleep ();
Signature · 1 line
1.7.9.1
PATCH 2/2 gpiolib: Implement devm_gpio_request_one()
Allow drivers to use the modern request and configure idiom together with devres.
--- drivers/gpio/devres.c | 29 +++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 2 ++ include/linux/gpio.h | 6 ++++++ 3 files changed, 37 insertions(+), 0 deletions(-)
drivers/gpio/devres.c +29 -0
@@ -71,6 +71,35 @@ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)EXPORT_SYMBOL (devm_gpio_request);/** +* devm_gpio_request_one - request a single GPIO with initial setup +* @dev: device to request for +* @gpio: the GPIO number +* @flags: GPIO configuration as specified by GPIOF_* +* @label: a literal description string of this GPIO +*/ +int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label) +{ +unsigned *dr; +int rc; + + dr =devres_alloc (devm_gpio_release,sizeof (unsigned ),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + rc =gpio_request_one (gpio, flags, label); +if (rc) { +devres_free (dr); +return rc; + } + + *dr = gpio; +devres_add (dev, dr); + +return 0 ; +} + +/** * devm_gpio_free - free an interrupt * @dev: device to free gpio for * @gpio: gpio to free
include/asm-generic/gpio.h +2 -0
@@ -179,6 +179,8 @@ extern void gpio_free_array(const struct gpio *array, size_t num);/* bindings for managed devices that want to request gpios */ int devm_gpio_request (struct device *dev,unsigned gpio,const char *label); +int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label);void devm_gpio_free (struct device *dev,unsigned int gpio);#ifdef CONFIG_GPIO_SYSFS
include/linux/gpio.h +6 -0
@@ -101,6 +101,12 @@ static inline int gpio_request_one(unsigned gpio,return -ENOSYS ; } +static inline int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label) +{ +return -ENOSYS ; +} +static inline int gpio_request_array (const struct gpio *array,size_t num) {return -ENOSYS ;
Signature · 1 line
1.7.9.1
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
Quoted 35 lines · Mark Brown
Allow drivers to use the modern request and configure idiom together with devres.
Signed-off-by Mark Brown <[email protected]>--- drivers/gpio/devres.c | 29 +++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 2 ++ include/linux/gpio.h | 6 ++++++ 3 files changed, 37 insertions(+), 0 deletions(-)drivers/gpio/devres.c +17
-0@@ -71,6 +71,35 @@ int devm_gpio_request(struct device *dev, unsigned gpio, const char *label)EXPORT_SYMBOL (devm_gpio_request);/** +* devm_gpio_request_one - request a single GPIO with initial setup +* @dev: device to request for +* @gpio: the GPIO number +* @flags: GPIO configuration as specified by GPIOF_* +* @label: a literal description string of this GPIO +*/ +int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label) +{ +unsigned *dr; +int rc; + + dr =devres_alloc (devm_gpio_release,sizeof (unsigned ),GFP_KERNEL ); +if (!dr) +return -ENOMEM ; + + rc =gpio_request_one (gpio, flags, label);
drivers/gpio/devres.c int devm_gpio_request(struct device *dev, unsigned gpio, const char *label) · line 100
Quoted 10 lines
drivers/gpio/devres.c +10
-0+if (rc) { +devres_free (dr); +return rc; + } + + *dr = gpio; +devres_add (dev, dr); + +return 0 ; +}
Can we make devm_gpio_request a static inline wrapper around devm_gpio_request_one() with the flags field set to '0'? I don't liek the duplication of this function.
Similarily, gpio_request() should actually be a static inline around gpio_request_one() instead of the other way around as it is currently written.
Quoted 38 lines
drivers/gpio/devres.c +2
-0+ +/** * devm_gpio_free - free an interrupt * @dev: device to free gpio for * @gpio: gpio to free include/asm-generic/gpio.h +2
-0@@ -179,6 +179,8 @@ extern void gpio_free_array(const struct gpio *array, size_t num);/* bindings for managed devices that want to request gpios */ int devm_gpio_request (struct device *dev,unsigned gpio,const char *label); +int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label);void devm_gpio_free (struct device *dev,unsigned int gpio);#ifdef CONFIG_GPIO_SYSFS include/linux/gpio.h +6
-0@@ -101,6 +101,12 @@ static inline int gpio_request_one(unsigned gpio,return -ENOSYS ; } +static inline int devm_gpio_request_one (struct device *dev,unsigned gpio, +unsigned long flags,const char *label) +{ +return -ENOSYS ; +} +static inline int gpio_request_array (const struct gpio *array,size_t num) {return -ENOSYS ;Signature · 1 line
1.7.9.1
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies,Ltd.
Grant Likely
AppliedQuoted 4 lines · Mark Brown
Currently the managed
gpio_request()andgpio_free()are not stubbed out for configurations not using gpiolib - do that to aid use in drivers.Signed-off-by Mark Brown <[email protected]>
Applied, thanks.
g.
Quoted 39 lines
--- include/linux/gpio.h | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-)include/linux/gpio.h +14
-0@@ -89,6 +89,12 @@ static inline int gpio_request(unsigned gpio, const char *label)return -ENOSYS ; } +static inline int devm_gpio_request (struct device *dev,unsigned gpio, +const char *label) +{ +return -ENOSYS ; +} +static inline int gpio_request_one (unsigned gpio,unsigned long flags,const char *label) {@@ -108,6 +114,14 @@ static inline void gpio_free(unsigned gpio)WARN_ON (1 ); } +static inline void devm_gpio_free (struct device *dev,unsigned gpio) +{ +might_sleep (); + +/* GPIO can never have been requested */ +WARN_ON (1 ); +} +static inline void gpio_free_array (const struct gpio *array,size_t num) {might_sleep ();Signature · 1 line
1.7.9.1
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies,Ltd.
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
In reply to Grant LikelyQuoted 7 lines · Grant Likely
Can we make
devm_gpio_requesta static inline wrapper arounddevm_gpio_request_one()with the flags field set to '0'? I don't liek the duplication of this function.Similarily,
gpio_request()should actually be a static inline aroundgpio_request_one()instead of the other way around as it is currently written.
Yeah, I couldn't understand why the non-managed functions were written in this way so I followed the same pattern when I added the managed one assuming that the original code was sane.
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
Quoted 6 lines · Mark Brown
Quoted 3 lines · Grant Likely
Can we make
devm_gpio_requesta static inline wrapper arounddevm_gpio_request_one()with the flags field set to '0'? I don't liek the duplication of this function.
Quoted 7 lines
Quoted 3 lines
Similarily,
gpio_request()should actually be a static inline aroundgpio_request_one()instead of the other way around as it is currently written.Yeah, I couldn't understand why the non-managed functions were written in this way so I followed the same pattern when I added the managed one assuming that the original code was sane.
Actually, I looked at it again, and the _one version behaves subtly different from the non-_one version. That may be irrelevant though.
g.
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies,Ltd.
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
Quoted 8 lines · Grant Likely
Quoted 3 lines · Mark Brown
Yeah, I couldn't understand why the non-managed functions were written in this way so I followed the same pattern when I added the managed one assuming that the original code was sane.
Actually, I looked at it again, and the
_oneversion behaves subtly different from the non-_one version. That may be irrelevant though.
It always does a direction set, yes. This will make a difference if the direction call either fails or blocks future reconfigurations, what was puzzling me was if this was an issue or not and like I say I decided to assume it was and stick with the same pattern.
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
Quoted 9 lines · Mark Brown
Quoted 2 lines · Grant Likely
Actually, I looked at it again, and the
_oneversion behaves subtly different from the non-_one version. That may be irrelevant though.It always does a direction set, yes. This will make a difference if the direction call either fails or blocks future reconfigurations, what was puzzling me was if this was an issue or not and like I say I decided to assume it was and stick with the same pattern.
Just after sending this (isn't that always the way?) I realised there is one important case where it makes a difference: if the code does this:
gpio_request(foo, "bar"); gpio_direction_output(foo, 1);
then if the GPIO was already driving out high we will maintain steady state. If, however, we were to do:
gpio_request(foo, "bar"); gpio_direction_input(); gpio_direction_output(foo, 1);
where the first two calls are the natural result of implementing gpio_request() in terms of gpio_request_one() then the GPIO would glitch high Z during the process which might have unfortunate consequences for whatever the GPIO is controlling.
I think instead of redoing the implementation we need start a campaign to convert gpio_request() users to gpio_request_one() - coccinelle can probably take a large chunk of the work but it'll need some manual help I expect.