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.
---
I thought you'd applied this but it's not showing up in -next.
include/linux/gpio.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
include/linux/gpio.h +14 -0
@@ -66,6 +66,12 @@ static inline int devm_gpio_request(struct device *dev, unsigned gpio,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) {
@@ -93,6 +99,14 @@ static inline void devm_gpio_free(struct device *dev, 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.10
PATCH 2/2 gpiolib: Implement devm_gpio_request_one()
Allow drivers to use the modern request and configure idiom together with devres.
As with plain gpio_request() and gpio_request_one() we can't implement the old school version in terms of _one() as this would force the explicit selection of a direction in gpio_request() which could break systems if we pick the wrong one. Implementing devm_gpio_request_one() in terms of devm_gpio_request() would needlessly complicate things or lead to duplication from the unmanaged version depending on how it's done.
--- drivers/gpio/devres.c | 29 +++++++++++++++++++++++++++++ include/asm-generic/gpio.h | 2 ++ include/linux/gpio.h | 6 ++++++ 3 files changed, 37 insertions(+)
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
@@ -78,6 +78,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.10
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
Quoted 11 lines · Mark Brown
Allow drivers to use the modern request and configure idiom together with devres.
As with plain
gpio_request()andgpio_request_one()we can't implement the old school version in terms of_one()as this would force the explicit selection of a direction ingpio_request()which could break systems if we pick the wrong one. Implementingdevm_gpio_request_one()in terms ofdevm_gpio_request()would needlessly complicate things or lead to duplication from the unmanaged version depending on how it's done.
Quoted 1 line
Signed-off-by Mark Brown <[email protected]>
Any chance we can get this into 3.5? Writing error handling code is boring :)
Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
In reply to Mark BrownQuoted 11 lines · Mark Brown
Allow drivers to use the modern request and configure idiom together with devres.
As with plain
gpio_request()andgpio_request_one()we can't implement the old school version in terms of_one()as this would force the explicit selection of a direction ingpio_request()which could break systems if we pick the wrong one. Implementingdevm_gpio_request_one()in terms ofdevm_gpio_request()would needlessly complicate things or lead to duplication from the unmanaged version depending on how it's done.
Quoted 1 line
Signed-off-by Mark Brown <[email protected]>
Yours,
Linus Walleij
Grant Likely
AppliedRe: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()
In reply to Mark BrownQuoted 12 lines · Mark Brown
Quoted 11 lines · Mark Brown
Allow drivers to use the modern request and configure idiom together with devres.
As with plain
gpio_request()andgpio_request_one()we can't implement the old school version in terms of_one()as this would force the explicit selection of a direction ingpio_request()which could break systems if we pick the wrong one. Implementingdevm_gpio_request_one()in terms ofdevm_gpio_request()would needlessly complicate things or lead to duplication from the unmanaged version depending on how it's done.
Quoted 4 lines
Quoted 1 line
Signed-off-by Mark Brown <[email protected]>Any chance we can get this into 3.5? Writing error handling code is boring :)
Applied, thanks. I'll push it out this evening.
g.
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd.
Quoted 7 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]>---
I thought you'd applied this but it's not showing up in -next.
It was in my local tree. I think I just forgot to push it out.
g.
Quoted 39 lines
include/linux/gpio.h | 14 ++++++++++++++ 1 file changed, 14 insertions(+)include/linux/gpio.h +14
-0@@ -66,6 +66,12 @@ static inline int devm_gpio_request(struct device *dev, unsigned gpio,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) {@@ -93,6 +99,14 @@ static inline void devm_gpio_free(struct device *dev, 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.10
Signature · 2 lines
Grant Likely, B.Sc, P.Eng. Secret Lab Technologies, Ltd.