All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] gpio: add flags to export GPIOs when requesting
@ 2011-11-15 22:44 Wolfram Sang
  2011-11-15 23:05 ` Denis Kuzmenko
  0 siblings, 1 reply; 8+ messages in thread
From: Wolfram Sang @ 2011-11-15 22:44 UTC (permalink / raw)
  To: linux-kernel; +Cc: Wolfram Sang, Linus Walleij

Introduce new flags to automatically export GPIOs when using the convenience
functions gpio_request_one() or gpio_request_array(). This eases support for
custom boards where lots of GPIOs need to be exported for customer
applications.

Signed-off-by: Wolfram Sang <w.sang@pengutronix.de>
Cc: Linus Walleij <linus.walleij@linaro.org>
---

Based on 3.2-rc2

 Documentation/gpio.txt |    3 +++
 drivers/gpio/gpiolib.c |   12 +++++++++++-
 include/linux/gpio.h   |    5 +++++
 3 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/Documentation/gpio.txt b/Documentation/gpio.txt
index 792faa3..9e28c05 100644
--- a/Documentation/gpio.txt
+++ b/Documentation/gpio.txt
@@ -303,6 +303,9 @@ where 'flags' is currently defined to specify the following properties:
 	* GPIOF_INIT_LOW	- as output, set initial level to LOW
 	* GPIOF_INIT_HIGH	- as output, set initial level to HIGH
 
+	* GPIOF_EXPORT_DIR_FIXED	- export gpio to sysfs, keep direction
+	* GPIOF_EXPORT_DIR_CHANGEABLE	- also export, allow changing direction
+
 since GPIOF_INIT_* are only valid when configured as output, so group valid
 combinations as:
 
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index a971e3d..65ba047 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1285,8 +1285,18 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
 				(flags & GPIOF_INIT_HIGH) ? 1 : 0);
 
 	if (err)
-		gpio_free(gpio);
+		goto free_gpio;
+
+	if (flags & GPIOF_EXPORT) {
+		err = gpio_export(gpio, flags & GPIOF_EXPORT_CHANGEABLE);
+		if (err)
+			goto free_gpio;
+	}
+
+	return 0;
 
+ free_gpio:
+	gpio_free(gpio);
 	return err;
 }
 EXPORT_SYMBOL_GPL(gpio_request_one);
diff --git a/include/linux/gpio.h b/include/linux/gpio.h
index 38ac48b..38afe24 100644
--- a/include/linux/gpio.h
+++ b/include/linux/gpio.h
@@ -14,6 +14,11 @@
 #define GPIOF_OUT_INIT_LOW	(GPIOF_DIR_OUT | GPIOF_INIT_LOW)
 #define GPIOF_OUT_INIT_HIGH	(GPIOF_DIR_OUT | GPIOF_INIT_HIGH)
 
+#define GPIOF_EXPORT		(1 << 2)
+#define GPIOF_EXPORT_CHANGEABLE	(1 << 3)
+#define GPIOF_EXPORT_DIR_FIXED	(GPIOF_EXPORT)
+#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
+
 /**
  * struct gpio - a structure describing a GPIO with configuration
  * @gpio:	the GPIO number
-- 
1.7.2.5


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-15 22:44 [PATCH] gpio: add flags to export GPIOs when requesting Wolfram Sang
@ 2011-11-15 23:05 ` Denis Kuzmenko
  2011-11-15 23:32   ` Stephen Warren
  0 siblings, 1 reply; 8+ messages in thread
From: Denis Kuzmenko @ 2011-11-15 23:05 UTC (permalink / raw)
  To: Wolfram Sang; +Cc: linux-kernel, Linus Walleij, Grant Likely

Hi Wolfram,
On 11/16/2011 12:44 AM, Wolfram Sang wrote:
> Introduce new flags to automatically export GPIOs when using the convenience
> functions gpio_request_one() or gpio_request_array(). This eases support for
> custom boards where lots of GPIOs need to be exported for customer
> applications.

Adding GPIO maintainer Grant Likely to CC.

> +#define GPIOF_EXPORT		(1 << 2)
> +#define GPIOF_EXPORT_CHANGEABLE	(1 << 3)
> +#define GPIOF_EXPORT_DIR_FIXED	(GPIOF_EXPORT)
> +#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)

Maybe, it's better to write like this:

#define GPIOF_EXPORT			(1 << 2)
#define GPIOF_EXPORT_DIR_CHANGEABLE	(3 << 2)

So you don't need additional defines (GPIOF_EXPORT_DIR_FIXED and
GPIOF_EXPORT_DIR_CHANGEABLE). This will not brake your logic and improve
readability IMHO.

-- 
Best regards, Denis Kuzmenko.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-15 23:05 ` Denis Kuzmenko
@ 2011-11-15 23:32   ` Stephen Warren
  2011-11-16  8:19     ` Denis Kuzmenko
  0 siblings, 1 reply; 8+ messages in thread
From: Stephen Warren @ 2011-11-15 23:32 UTC (permalink / raw)
  To: Denis Kuzmenko, Wolfram Sang, Dong Aisheng
  Cc: linux-kernel@vger.kernel.org, Linus Walleij, Grant Likely

Denis Kuzmenko wrote at Tuesday, November 15, 2011 4:05 PM:
> Hi Wolfram,
> On 11/16/2011 12:44 AM, Wolfram Sang wrote:
> > Introduce new flags to automatically export GPIOs when using the convenience
> > functions gpio_request_one() or gpio_request_array(). This eases support for
> > custom boards where lots of GPIOs need to be exported for customer
> > applications.
> 
> Adding GPIO maintainer Grant Likely to CC.
> 
> > +#define GPIOF_EXPORT		(1 << 2)
> > +#define GPIOF_EXPORT_CHANGEABLE	(1 << 3)
> > +#define GPIOF_EXPORT_DIR_FIXED	(GPIOF_EXPORT)
> > +#define GPIOF_EXPORT_DIR_CHANGEABLE (GPIOF_EXPORT | GPIOF_EXPORT_CHANGEABLE)
> 
> Maybe, it's better to write like this:
> 
> #define GPIOF_EXPORT			(1 << 2)
> #define GPIOF_EXPORT_DIR_CHANGEABLE	(3 << 2)

Then you won't have a single flag to check if the dir is changeable.

Personally, I'd go for the two single-bit flags, and force boards to OR
them together if they want the GPIO exported and with a changeable
direction; just get rid of the two _DIR_ flags. That said, Wolfram's
patch seems to follow the conventions already in the file.

Dong Aisheng posted patch "gpio: introduce gpio_export_array to ease
export for gpio arrays". Which should we pick; it doesn't seem like we
need both mechanisms.

-- 
nvpublic


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-15 23:32   ` Stephen Warren
@ 2011-11-16  8:19     ` Denis Kuzmenko
  2011-11-16  9:10       ` Wolfram Sang
  0 siblings, 1 reply; 8+ messages in thread
From: Denis Kuzmenko @ 2011-11-16  8:19 UTC (permalink / raw)
  To: Stephen Warren
  Cc: Wolfram Sang, Dong Aisheng, linux-kernel@vger.kernel.org,
	Linus Walleij, Grant Likely

Hi Stephen,

On 11/16/2011 01:32 AM, Stephen Warren wrote:
> Denis Kuzmenko wrote at Tuesday, November 15, 2011 4:05 PM:
>> Hi Wolfram,
>> On 11/16/2011 12:44 AM, Wolfram Sang wrote:
>>
>> #define GPIOF_EXPORT			(1 << 2)
>> #define GPIOF_EXPORT_DIR_CHANGEABLE	(3 << 2)
> 
> Then you won't have a single flag to check if the dir is changeable.
> 
> Personally, I'd go for the two single-bit flags, and force boards to OR
> them together if they want the GPIO exported and with a changeable
> direction; just get rid of the two _DIR_ flags. That said, Wolfram's
> patch seems to follow the conventions already in the file.

Your truth.

> Dong Aisheng posted patch "gpio: introduce gpio_export_array to ease
> export for gpio arrays". Which should we pick; it doesn't seem like we
> need both mechanisms.

I vote for GPIOF_* variant (this one) since it can deal with different
settings for each gpio pin in array.

-- 
Best regards, Denis Kuzmenko.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-16  8:19     ` Denis Kuzmenko
@ 2011-11-16  9:10       ` Wolfram Sang
  2011-11-16 15:57         ` Stephen Warren
  2011-11-17  9:10         ` Linus Walleij
  0 siblings, 2 replies; 8+ messages in thread
From: Wolfram Sang @ 2011-11-16  9:10 UTC (permalink / raw)
  To: Denis Kuzmenko
  Cc: Stephen Warren, Dong Aisheng, linux-kernel@vger.kernel.org,
	Linus Walleij, Grant Likely

[-- Attachment #1: Type: text/plain, Size: 1257 bytes --]

Hi,

> >> #define GPIOF_EXPORT			(1 << 2)
> >> #define GPIOF_EXPORT_DIR_CHANGEABLE	(3 << 2)
> > 
> > Then you won't have a single flag to check if the dir is changeable.

I played with both versions you mentioned and came to like this one
better, for this reason...

> > direction; just get rid of the two _DIR_ flags. That said, Wolfram's
> > patch seems to follow the conventions already in the file.
> 
> Your truth.

...and this reason :)

> > Dong Aisheng posted patch "gpio: introduce gpio_export_array to ease
> > export for gpio arrays". Which should we pick; it doesn't seem like we
> > need both mechanisms.
> 
> I vote for GPIOF_* variant (this one) since it can deal with different
> settings for each gpio pin in array.

Huh? I really missed Aisheng's one, otherwise I would have responded to
that. I also think my version is less intrusive and I surely need the
option that some pins may change directions and others may not.

BTW I didn't CC Grant, because he is on sabbatical right now, so Stephen
you are taking care of GPIO?

Thanks,

   Wolfram

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* RE: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-16  9:10       ` Wolfram Sang
@ 2011-11-16 15:57         ` Stephen Warren
  2011-11-17  9:10         ` Linus Walleij
  1 sibling, 0 replies; 8+ messages in thread
From: Stephen Warren @ 2011-11-16 15:57 UTC (permalink / raw)
  To: Wolfram Sang, Denis Kuzmenko
  Cc: Dong Aisheng, linux-kernel@vger.kernel.org, Linus Walleij,
	Grant Likely

Wolfram Sang wrote at Wednesday, November 16, 2011 2:10 AM:
...
> BTW I didn't CC Grant, because he is on sabbatical right now, so Stephen
> you are taking care of GPIO?

No, I believe Linus Walleij is handling GPIO right now. Grant had just
asked for some help with reviews in a few places, so I picked a few things
to look at.

-- 
nvpublic


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-16  9:10       ` Wolfram Sang
  2011-11-16 15:57         ` Stephen Warren
@ 2011-11-17  9:10         ` Linus Walleij
  2011-11-17  9:31           ` Wolfram Sang
  1 sibling, 1 reply; 8+ messages in thread
From: Linus Walleij @ 2011-11-17  9:10 UTC (permalink / raw)
  To: Wolfram Sang
  Cc: Denis Kuzmenko, Stephen Warren, Dong Aisheng,
	linux-kernel@vger.kernel.org, Grant Likely

On Wed, Nov 16, 2011 at 10:10 AM, Wolfram Sang <w.sang@pengutronix.de> wrote:

> BTW I didn't CC Grant, because he is on sabbatical right now, so Stephen
> you are taking care of GPIO?

I'm taking care of prepping GPIO patches for the -rc series for some
two weeks. I think this patch is for-next so I won't be merging it
anyplace. Grant wanted new and reviewed stuff as pull
requests when he gets back.

Linus Walleij

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] gpio: add flags to export GPIOs when requesting
  2011-11-17  9:10         ` Linus Walleij
@ 2011-11-17  9:31           ` Wolfram Sang
  0 siblings, 0 replies; 8+ messages in thread
From: Wolfram Sang @ 2011-11-17  9:31 UTC (permalink / raw)
  To: Linus Walleij
  Cc: Denis Kuzmenko, Stephen Warren, Dong Aisheng,
	linux-kernel@vger.kernel.org, Grant Likely

[-- Attachment #1: Type: text/plain, Size: 459 bytes --]


> I'm taking care of prepping GPIO patches for the -rc series for some
> two weeks. I think this patch is for-next so I won't be merging it
> anyplace. Grant wanted new and reviewed stuff as pull
> requests when he gets back.

So anyone got tags to donate? I can set up my own branch then...

-- 
Pengutronix e.K.                           | Wolfram Sang                |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-11-17  9:31 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-15 22:44 [PATCH] gpio: add flags to export GPIOs when requesting Wolfram Sang
2011-11-15 23:05 ` Denis Kuzmenko
2011-11-15 23:32   ` Stephen Warren
2011-11-16  8:19     ` Denis Kuzmenko
2011-11-16  9:10       ` Wolfram Sang
2011-11-16 15:57         ` Stephen Warren
2011-11-17  9:10         ` Linus Walleij
2011-11-17  9:31           ` Wolfram Sang

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.