linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <brgl@bgdev.pl>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: "open list:GPIO SUBSYSTEM" <linux-gpio@vger.kernel.org>,
	Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	stable <stable@vger.kernel.org>,
	Kent Gibson <warthog618@gmail.com>
Subject: Re: [PATCH] gpiolib: don't clear FLAG_IS_OUT when emulating open-drain/open-source
Date: Tue, 17 Sep 2019 09:54:34 +0200	[thread overview]
Message-ID: <CAMRc=MdtN9E7dP1eSgC52oa7eQ_2HTo6gf9s1cgoxS=j57CK-Q@mail.gmail.com> (raw)
In-Reply-To: <20190910082138.30193-1-brgl@bgdev.pl>

wt., 10 wrz 2019 o 10:22 Bartosz Golaszewski <brgl@bgdev.pl> napisał(a):
>
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
>
> When emulating open-drain/open-source by not actively driving the output
> lines - we're simply changing their mode to input. This is wrong as it
> will then make it impossible to change the value of such line - it's now
> considered to actually be in input mode. If we want to still use the
> direction_input() callback for simplicity then we need to set FLAG_IS_OUT
> manually in gpiod_direction_output() and not clear it in
> gpio_set_open_drain_value_commit() and
> gpio_set_open_source_value_commit().
>
> Fixes: c663e5f56737 ("gpio: support native single-ended hardware drivers")
> Cc: stable@vger.kernel.org
> Reported-by: Kent Gibson <warthog618@gmail.com>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---
>  drivers/gpio/gpiolib.c | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c
> index cca749010cd0..6bb4191d3844 100644
> --- a/drivers/gpio/gpiolib.c
> +++ b/drivers/gpio/gpiolib.c
> @@ -2769,8 +2769,10 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
>                 if (!ret)
>                         goto set_output_value;
>                 /* Emulate open drain by not actively driving the line high */
> -               if (value)
> -                       return gpiod_direction_input(desc);
> +               if (value) {
> +                       ret = gpiod_direction_input(desc);
> +                       goto set_output_flag;
> +               }
>         }
>         else if (test_bit(FLAG_OPEN_SOURCE, &desc->flags)) {
>                 ret = gpio_set_config(gc, gpio_chip_hwgpio(desc),
> @@ -2778,8 +2780,10 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
>                 if (!ret)
>                         goto set_output_value;
>                 /* Emulate open source by not actively driving the line low */
> -               if (!value)
> -                       return gpiod_direction_input(desc);
> +               if (!value) {
> +                       ret = gpiod_direction_input(desc);
> +                       goto set_output_flag;
> +               }
>         } else {
>                 gpio_set_config(gc, gpio_chip_hwgpio(desc),
>                                 PIN_CONFIG_DRIVE_PUSH_PULL);
> @@ -2787,6 +2791,17 @@ int gpiod_direction_output(struct gpio_desc *desc, int value)
>
>  set_output_value:
>         return gpiod_direction_output_raw_commit(desc, value);
> +
> +set_output_flag:
> +       /*
> +        * When emulating open-source or open-drain functionalities by not
> +        * actively driving the line (setting mode to input) we still need to
> +        * set the IS_OUT flag or otherwise we won't be able to set the line
> +        * value anymore.
> +        */
> +       if (ret == 0)
> +               set_bit(FLAG_IS_OUT, &desc->flags);
> +       return ret;
>  }
>  EXPORT_SYMBOL_GPL(gpiod_direction_output);
>
> @@ -3147,8 +3162,6 @@ static void gpio_set_open_drain_value_commit(struct gpio_desc *desc, bool value)
>
>         if (value) {
>                 err = chip->direction_input(chip, offset);
> -               if (!err)
> -                       clear_bit(FLAG_IS_OUT, &desc->flags);
>         } else {
>                 err = chip->direction_output(chip, offset, 0);
>                 if (!err)
> @@ -3178,8 +3191,6 @@ static void gpio_set_open_source_value_commit(struct gpio_desc *desc, bool value
>                         set_bit(FLAG_IS_OUT, &desc->flags);
>         } else {
>                 err = chip->direction_input(chip, offset);
> -               if (!err)
> -                       clear_bit(FLAG_IS_OUT, &desc->flags);
>         }
>         trace_gpio_direction(desc_to_gpio(desc), !value, err);
>         if (err < 0)
> --
> 2.21.0
>

Queued for fixes.

Bart

      parent reply	other threads:[~2019-09-17  7:54 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-10  8:21 [PATCH] gpiolib: don't clear FLAG_IS_OUT when emulating open-drain/open-source Bartosz Golaszewski
     [not found] ` <20190910104829.983FE2067B@mail.kernel.org>
2019-09-11  5:55   ` Bartosz Golaszewski
2019-09-17  7:54 ` Bartosz Golaszewski [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='CAMRc=MdtN9E7dP1eSgC52oa7eQ_2HTo6gf9s1cgoxS=j57CK-Q@mail.gmail.com' \
    --to=brgl@bgdev.pl \
    --cc=bgolaszewski@baylibre.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    --cc=warthog618@gmail.com \
    /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;
as well as URLs for NNTP newsgroup(s).