mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Andrey Smirnov <andrew.smirnov@gmail.com>
To: Sascha Hauer <s.hauer@pengutronix.de>
Cc: Nikita Yushchenko <nikita.yoush@cogentembedded.com>,
	"barebox@lists.infradead.org" <barebox@lists.infradead.org>,
	Chris Healy <cphealy@gmail.com>
Subject: Re: [PATCH v2 2/4] gpiolib: Add code to support "active low" GPIOs
Date: Thu, 1 Jun 2017 22:47:58 -0700	[thread overview]
Message-ID: <CAHQ1cqEkQCBzYsC9xdsDtmbbcJsr71D+DnvWi4ASEDQA1CH69w@mail.gmail.com> (raw)
In-Reply-To: <20170602052832.h7kf3jtabx5zp3uo@pengutronix.de>

On Thu, Jun 1, 2017 at 10:28 PM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
> On Thu, Jun 01, 2017 at 01:33:55PM -0700, Andrey Smirnov wrote:
>> On Thu, Jun 1, 2017 at 12:19 AM, Sascha Hauer <s.hauer@pengutronix.de> wrote:
>> > On Tue, May 30, 2017 at 07:52:26AM -0700, Andrey Smirnov wrote:
>> >> So far this particular aspect of various DT-bindings has been handled
>> >> on a per-driver basis. With this change, hopefully, we'll have a
>> >> single place to handle necessary logic inversions and eventually
>> >> would be able to migrate existing users as well as avoiding adding
>> >> redundant code to new drivers.
>> >>
>> >> Cc: cphealy@gmail.com
>> >> Cc: Nikita Yushchenko <nikita.yoush@cogentembedded.com>
>> >> Signed-off-by: Andrey Smirnov <andrew.smirnov@gmail.com>
>> >> ---
>> >>  drivers/gpio/gpiolib.c | 42 ++++++++++++++++++++++++++++++++++++++++--
>> >>  include/gpio.h         | 20 ++++++++++++++++++++
>> >>  2 files changed, 60 insertions(+), 2 deletions(-)
>> >>
>> >> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
>> >> index 1f57c76..36d8874 100644
>> >> --- a/drivers/gpio/gpiolib.c
>> >> +++ b/drivers/gpio/gpiolib.c
>> >> @@ -13,6 +13,7 @@ static LIST_HEAD(chip_list);
>> >>  struct gpio_info {
>> >>       struct gpio_chip *chip;
>> >>       bool requested;
>> >> +     bool active_low;
>> >>       char *label;
>> >>  };
>> >>
>> >> @@ -45,6 +46,15 @@ static struct gpio_info *gpio_to_desc(unsigned gpio)
>> >>       return NULL;
>> >>  }
>> >>
>> >> +static int gpio_adjust_value(struct gpio_info *gi,
>> >> +                          int value)
>> >> +{
>> >> +     if (value < 0)
>> >> +             return value;
>> >> +
>> >> +     return !!value ^ gi->active_low;
>> >> +}
>> >> +
>> >>  int gpio_request(unsigned gpio, const char *label)
>> >>  {
>> >>       struct gpio_info *gi = gpio_to_desc(gpio);
>> >> @@ -69,6 +79,7 @@ int gpio_request(unsigned gpio, const char *label)
>> >>       }
>> >>
>> >>       gi->requested = true;
>> >> +     gi->active_low = false;
>> >>       gi->label = xstrdup(label);
>> >>
>> >>  done:
>> >> @@ -93,6 +104,7 @@ void gpio_free(unsigned gpio)
>> >>               gi->chip->ops->free(gi->chip, gpio - gi->chip->base);
>> >>
>> >>       gi->requested = false;
>> >> +     gi->active_low = false;
>> >>       free(gi->label);
>> >>       gi->label = NULL;
>> >>  }
>> >> @@ -111,10 +123,15 @@ int gpio_request_one(unsigned gpio, unsigned long flags, const char *label)
>> >>       if (err)
>> >>               return err;
>> >>
>> >> +     if (flags & GPIOF_ACTIVE_LOW) {
>> >> +             struct gpio_info *gi = gpio_to_desc(gpio);
>> >> +             gi->active_low = true;
>> >> +     }
>> >> +
>> >>       if (flags & GPIOF_DIR_IN)
>> >>               err = gpio_direction_input(gpio);
>> >>       else
>> >> -             err = gpio_direction_output(gpio,
>> >> +             err = gpio_direction_active(gpio,
>> >>                               (flags & GPIOF_INIT_HIGH) ? 1 : 0);
>> >
>> > And here things get messy.
>> >
>> > For me 'high' and 'low' represent the physical values of a GPIO whereas
>> > "active" and "inactive" represent the logical values of a GPIO. The flag
>> > is named GPIOF_INIT_*HIGH*, not GPIOF_INIT_*ACTIVE*, which means a GPIO
>> > with this flag should get the physical 'high' value, not the logical
>> > 'active' value.
>> >
>> > They goofed the binding in the kernel, so I'm afraid there's nothing we
>> > can do about this :(
>>
>> So do we want to:
>>
>> a) Keep things as is in v2(I am assuming that is not really an option)
>> b) Improve the optics by introducing GPIOF_INIT_ACTIVE, but keeping
>> the behavior of hog nodes consistent with Linux kernel
>
> We must keep the behaviour consistent with the Kernel, everything else
> is not an option. A GPIOF_INIT_ACTIVE flag sounds like a good idea. The
> place where "output-[high|low]" is translated into this flag seems a
> good place to put a big comment what is going on.
>

Sounds good. I'll update the patchset accordingly.

Thanks,
Andrey Smirnov

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  reply	other threads:[~2017-06-02  5:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-30 14:52 [PATCH v2 0/4] GPIO "active low", hogging and usb-nop-xceive 'reset-gpio' support Andrey Smirnov
2017-05-30 14:52 ` [PATCH v2 1/4] gpio-imx: Do not use gpio_set_value() Andrey Smirnov
2017-05-30 14:52 ` [PATCH v2 2/4] gpiolib: Add code to support "active low" GPIOs Andrey Smirnov
2017-06-01  7:19   ` Sascha Hauer
2017-06-01 20:33     ` Andrey Smirnov
2017-06-02  5:28       ` Sascha Hauer
2017-06-02  5:47         ` Andrey Smirnov [this message]
2017-05-30 14:52 ` [PATCH v2 3/4] gpiolib: Add support for GPIO "hog" nodes Andrey Smirnov
2017-05-30 14:52 ` [PATCH v2 4/4] usb-nop-xceiv: Add support for 'reset-gpios' binding Andrey Smirnov

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=CAHQ1cqEkQCBzYsC9xdsDtmbbcJsr71D+DnvWi4ASEDQA1CH69w@mail.gmail.com \
    --to=andrew.smirnov@gmail.com \
    --cc=barebox@lists.infradead.org \
    --cc=cphealy@gmail.com \
    --cc=nikita.yoush@cogentembedded.com \
    --cc=s.hauer@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox