Skip to contentSkip to conversation

gpiolib: Add !CONFIG_GPIOLIB definitions of devm_ functions

PATCH Applied Mark Brown 3 participants 6 messages May 2, 2012 – May 18, 2012

Subsystems (2)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

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
index d1890d46..8e0fe1b 100644
@@ -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
author
#1 lore raw

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
index 3dd2939..d21a9ff 100644
@@ -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
index 5f52690..4ead123 100644
@@ -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
index 8e0fe1b..a68024e 100644
@@ -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
author
#2 lore raw

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() 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.

Quoted 1 line

Any chance we can get this into 3.5? Writing error handling code is boring :)

Applied
#3 lore raw

Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()

Quoted 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() 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.

Quoted 4 lines
Quoted 1 line

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.
Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] gpiolib: Implement devm_gpio_request_one()

In reply to 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() 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.

Quoted 1 line

Yours,
Linus Walleij

#5 lore raw
In reply to Mark Brown
Quoted 7 lines · Mark Brown

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.

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
index d1890d46..8e0fe1b 100644
@@ -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.