linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] gpio: create an API to detect open drain/source on lines
@ 2016-02-16 14:46 Linus Walleij
  2016-02-17  0:21 ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2016-02-16 14:46 UTC (permalink / raw)
  To: linux-gpio, Alexandre Courbot, Stephen Rothwell
  Cc: Linus Walleij, Nicolas Saenz Julienne

My left hand merges code to privatize the descriptor handling
while my right hand merges drivers that poke around and
disrespect with the same gpiolib internals.

So let's expose the proper APIs for drivers to ask the gpiolib
core if a line is marked as open drain or open source and
get some order around things so this driver compiles again.

Reported-by: Stephen Rothwell <sfr@canb.auug.org.au>
Cc: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>
Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/gpio/gpio-tps65218.c |  9 ++++-----
 drivers/gpio/gpiolib.c       | 18 ++++++++++++++++++
 include/linux/gpio/driver.h  |  4 ++++
 3 files changed, 26 insertions(+), 5 deletions(-)

diff --git a/drivers/gpio/gpio-tps65218.c b/drivers/gpio/gpio-tps65218.c
index 7b02f7be9bc9..9eb1a5ab2d95 100644
--- a/drivers/gpio/gpio-tps65218.c
+++ b/drivers/gpio/gpio-tps65218.c
@@ -71,17 +71,16 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset)
 {
 	struct tps65218_gpio *tps65218_gpio = gpiochip_get_data(gc);
 	struct tps65218 *tps65218 = tps65218_gpio->tps65218;
-	unsigned long flags = gc->desc[offset].flags;
 	int ret;
 
-	if (flags & FLAG_OPEN_SOURCE) {
+	if (gpiochip_line_is_open_source(gc, offset)) {
 		dev_err(gc->parent, "can't work as open source\n");
 		return -EINVAL;
 	}
 
 	switch (offset) {
 	case 0:
-		if (!(flags & FLAG_OPEN_DRAIN)) {
+		if (!gpiochip_line_is_open_drain(gc, offset)) {
 			dev_err(gc->parent, "GPO1 works only as open drain\n");
 			return -EINVAL;
 		}
@@ -103,7 +102,7 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset)
 		break;
 	case 1:
 		/* GP02 is push-pull by default, can be set as open drain. */
-		if (flags & FLAG_OPEN_DRAIN) {
+		if (gpiochip_line_is_open_drain(gc, offset)) {
 			ret = tps65218_clear_bits(tps65218,
 						  TPS65218_REG_CONFIG1,
 						  TPS65218_CONFIG1_GPO2_BUF,
@@ -122,7 +121,7 @@ static int tps65218_gpio_request(struct gpio_chip *gc, unsigned offset)
 		break;
 
 	case 2:
-		if (!(flags & FLAG_OPEN_DRAIN)) {
+		if (!gpiochip_line_is_open_drain(gc, offset)) {
 			dev_err(gc->parent, "GPO3 works only as open drain\n");
 			return -EINVAL;
 		}
diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
index aa4a60e19339..d8511cd68e7b 100644
--- a/drivers/gpio/gpiolib.c
+++ b/drivers/gpio/gpiolib.c
@@ -1901,6 +1901,24 @@ bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset)
 }
 EXPORT_SYMBOL_GPL(gpiochip_line_is_irq);
 
+bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset)
+{
+	if (offset >= chip->ngpio)
+		return false;
+
+	return test_bit(FLAG_OPEN_DRAIN, &chip->gpiodev->descs[offset].flags);
+}
+EXPORT_SYMBOL_GPL(gpiochip_line_is_open_drain);
+
+bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset)
+{
+	if (offset >= chip->ngpio)
+		return false;
+
+	return test_bit(FLAG_OPEN_SOURCE, &chip->gpiodev->descs[offset].flags);
+}
+EXPORT_SYMBOL_GPL(gpiochip_line_is_open_source);
+
 /**
  * gpiod_get_raw_value_cansleep() - return a gpio's raw value
  * @desc: gpio whose value will be returned
diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h
index b92ab9efdb69..ff96d0f9fceb 100644
--- a/include/linux/gpio/driver.h
+++ b/include/linux/gpio/driver.h
@@ -199,6 +199,10 @@ int gpiochip_lock_as_irq(struct gpio_chip *chip, unsigned int offset);
 void gpiochip_unlock_as_irq(struct gpio_chip *chip, unsigned int offset);
 bool gpiochip_line_is_irq(struct gpio_chip *chip, unsigned int offset);
 
+/* Line status inquiry for drivers */
+bool gpiochip_line_is_open_drain(struct gpio_chip *chip, unsigned int offset);
+bool gpiochip_line_is_open_source(struct gpio_chip *chip, unsigned int offset);
+
 /* get driver data */
 void *gpiochip_get_data(struct gpio_chip *chip);
 
-- 
2.4.3


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

* Re: [PATCH] gpio: create an API to detect open drain/source on lines
  2016-02-16 14:46 [PATCH] gpio: create an API to detect open drain/source on lines Linus Walleij
@ 2016-02-17  0:21 ` Nicolas Saenz Julienne
  2016-02-18 20:47   ` Linus Walleij
  0 siblings, 1 reply; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2016-02-17  0:21 UTC (permalink / raw)
  To: Linus Walleij; +Cc: linux-gpio, Alexandre Courbot, Stephen Rothwell

On Tue, Feb 16, 2016 at 03:46:19PM +0100, Linus Walleij wrote:
> My left hand merges code to privatize the descriptor handling
> while my right hand merges drivers that poke around and
> disrespect with the same gpiolib internals.
>
> So let's expose the proper APIs for drivers to ask the gpiolib
> core if a line is marked as open drain or open source and
> get some order around things so this driver compiles again.

Thanks, looks way better now, I'd suggest to remove the "gpiolib.h"
include since it's not needed anymore. I can do it's on a separate patch
on top of this one if you prefer :)

Acked-by: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>

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

* Re: [PATCH] gpio: create an API to detect open drain/source on lines
  2016-02-17  0:21 ` Nicolas Saenz Julienne
@ 2016-02-18 20:47   ` Linus Walleij
  2016-02-18 21:20     ` Nicolas Saenz Julienne
  0 siblings, 1 reply; 4+ messages in thread
From: Linus Walleij @ 2016-02-18 20:47 UTC (permalink / raw)
  To: Nicolas Saenz Julienne
  Cc: linux-gpio@vger.kernel.org, Alexandre Courbot, Stephen Rothwell

On Wed, Feb 17, 2016 at 1:21 AM, Nicolas Saenz Julienne
<nicolassaenzj@gmail.com> wrote:
> On Tue, Feb 16, 2016 at 03:46:19PM +0100, Linus Walleij wrote:
>> My left hand merges code to privatize the descriptor handling
>> while my right hand merges drivers that poke around and
>> disrespect with the same gpiolib internals.
>>
>> So let's expose the proper APIs for drivers to ask the gpiolib
>> core if a line is marked as open drain or open source and
>> get some order around things so this driver compiles again.
>
> Thanks, looks way better now, I'd suggest to remove the "gpiolib.h"
> include since it's not needed anymore. I can do it's on a separate patch
> on top of this one if you prefer :)

I don't understand this comment? That is our internal library header
so that different files in gpiolib can share functions.

>
> Acked-by: Nicolas Saenz Julienne <nicolassaenzj@gmail.com>

Thanks!

Yours,
Linus Walleij

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

* Re: [PATCH] gpio: create an API to detect open drain/source on lines
  2016-02-18 20:47   ` Linus Walleij
@ 2016-02-18 21:20     ` Nicolas Saenz Julienne
  0 siblings, 0 replies; 4+ messages in thread
From: Nicolas Saenz Julienne @ 2016-02-18 21:20 UTC (permalink / raw)
  To: Linus Walleij
  Cc: linux-gpio@vger.kernel.org, Alexandre Courbot, Stephen Rothwell

On Thu, Feb 18, 2016 at 09:47:07PM +0100, Linus Walleij wrote:
> On Wed, Feb 17, 2016 at 1:21 AM, Nicolas Saenz Julienne
> <nicolassaenzj@gmail.com> wrote:
> > On Tue, Feb 16, 2016 at 03:46:19PM +0100, Linus Walleij wrote:
> >> My left hand merges code to privatize the descriptor handling
> >> while my right hand merges drivers that poke around and
> >> disrespect with the same gpiolib internals.
> >>
> >> So let's expose the proper APIs for drivers to ask the gpiolib
> >> core if a line is marked as open drain or open source and
> >> get some order around things so this driver compiles again.
> >
> > Thanks, looks way better now, I'd suggest to remove the "gpiolib.h"
> > include since it's not needed anymore. I can do it's on a separate patch
> > on top of this one if you prefer :)

Sorry I wasn't more clear. What I meant to say it's that we can now remove the
#include "gpiolib.h" from gpio-tps65218 driver since the line config query
functions are included in "gpio/driver.h".

--
Nicolas

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

end of thread, other threads:[~2016-02-18 21:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-02-16 14:46 [PATCH] gpio: create an API to detect open drain/source on lines Linus Walleij
2016-02-17  0:21 ` Nicolas Saenz Julienne
2016-02-18 20:47   ` Linus Walleij
2016-02-18 21:20     ` Nicolas Saenz Julienne

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).