All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michael Hennerich <michael.hennerich@analog.com>
To: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio@vger.kernel.org,
	Alexandre Courbot <acourbot@nvidia.com>
Subject: Re: [PATCH] gpio: support native single-ended hardware drivers
Date: Wed, 23 Mar 2016 11:10:04 +0100	[thread overview]
Message-ID: <56F26B7C.8000302@analog.com> (raw)
In-Reply-To: <1458640626-2669-1-git-send-email-linus.walleij@linaro.org>

On 03/22/2016 10:57 AM, Linus Walleij wrote:
> Some GPIO controllers has a special hardware bit we can flip
> to support open drain / source. This means that on these hardwares
> we do not need to emulate OD/OS by setting the line to input
> instead of actively driving it high/low. Add an optional vtable
> callback to the driver set_single_ended() so that driver can
> implement this in hardware if they have it.
>
> We may need a pinctrl_gpio_set_config() call at some point to
> propagate this down to a backing pin control device on systems
> with split GPIO/pin control.
>
> Reported-by: Michael Hennerich <michael.hennerich@analog.com>
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
> ---
> Michael, please have a look at this and consider testing it with
> your hardware and adding a .set_single_ended() callback in your
> driver to see if it does what you want. I'm ready to merge this
> if at least one driver make use of it.


Hi Linus,

I think the patch looks good.

Unfortunately it only applies against your gpio/for-next branch.

for some reason on that 4.5 kernel the SDHCI interface on my test board 
doesn't work any more.

So I can't really fully test it at the moment.


diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c
index 4019e44..efb7442 100644
--- a/drivers/iio/dac/ad5592r-base.c
+++ b/drivers/iio/dac/ad5592r-base.c
@@ -127,6 +127,38 @@ static int ad5592r_gpio_request(struct gpio_chip 
*chip, unsigned offset)
         return 0;
  }

+static int ad5592r_gpio_set_single_ended(struct gpio_chip *chip,
+                                        unsigned offset,
+                                        enum single_ended_mode mode)
+{
+       struct ad5592r_state *st = gpiochip_get_data(chip);
+       int ret = 0;
+
+       mutex_lock(&st->gpio_lock);
+
+       switch (mode) {
+       case LINE_MODE_PUSH_PULL:
+               st->gpio_opendrain &= ~BIT(offset);
+               break;
+
+       case LINE_MODE_OPEN_DRAIN:
+               st->gpio_opendrain |= BIT(offset);
+               break;
+
+       case LINE_MODE_OPEN_SOURCE:
+       default:
+               ret = -ENOTSUPP;
+       }
+
+       mutex_unlock(&st->gpio_lock);
+
+       if (ret)
+               return ret;
+
+       return st->ops->reg_write(st, AD5592R_REG_OPEN_DRAIN,
+                                 st->gpio_opendrain);
+}
+
  static int ad5592r_gpio_init(struct ad5592r_state *st)
  {
         if (!st->gpio_map)
@@ -139,6 +171,7 @@ static int ad5592r_gpio_init(struct ad5592r_state *st)
         st->gpiochip.can_sleep = true;
         st->gpiochip.direction_input = ad5592r_gpio_direction_input;
         st->gpiochip.direction_output = ad5592r_gpio_direction_output;
+       st->gpiochip.set_single_ended = ad5592r_gpio_set_single_ended;
         st->gpiochip.get = ad5592r_gpio_get;
         st->gpiochip.set = ad5592r_gpio_set;
         st->gpiochip.request = ad5592r_gpio_request;
diff --git a/drivers/iio/dac/ad5592r-base.h b/drivers/iio/dac/ad5592r-base.h
index 2753385..09d545b 100644
--- a/drivers/iio/dac/ad5592r-base.h
+++ b/drivers/iio/dac/ad5592r-base.h
@@ -66,6 +66,7 @@ struct ad5592r_state {
         u8 gpio_out;
         u8 gpio_in;
         u8 gpio_val;
+       u8 gpio_opendrain;

         __be16 spi_msg ____cacheline_aligned;
         __be16 spi_msg_nop;





-- 
Greetings,
Michael

--
Analog Devices GmbH      Wilhelm-Wagenfeld-Str. 6      80807 Muenchen
Sitz der Gesellschaft: Muenchen; Registergericht: Muenchen HRB 40368;
Geschaeftsfuehrer:Dr.Carsten Suckrow, Thomas Wessel, William A. Martin,
Margaret Seif

      reply	other threads:[~2016-03-23 10:17 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-22  9:57 [PATCH] gpio: support native single-ended hardware drivers Linus Walleij
2016-03-23 10:10 ` Michael Hennerich [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56F26B7C.8000302@analog.com \
    --to=michael.hennerich@analog.com \
    --cc=acourbot@nvidia.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.