All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v4 16/16] gpio: Add a way to read 3-way strapping pins
Date: Mon, 8 Feb 2021 16:41:56 -0700	[thread overview]
Message-ID: <CAPnjgZ1H_eOfSFKmkfOKQYJEHSou82zDk6DHDRvyitNCSPPsXA@mail.gmail.com> (raw)
In-Reply-To: <79c5d3a4-b6a5-69fe-1718-7b562817634c@foss.st.com>

Hi Patrick,

On Mon, 8 Feb 2021 at 11:13, Patrick DELAUNAY
<patrick.delaunay@foss.st.com> wrote:
>
> Hi Simon,
>
> On 2/5/21 5:22 AM, Simon Glass wrote:
> > Using the internal vs. external pull resistors it is possible to get
> > 27 different combinations from 3 strapping pins. Add an implementation
> > of this.
> >
> > This involves updating the sandbox GPIO driver to model external and
> > (weaker) internal pull resistors. The get_value() method now takes account
> > of what is driving a pin:
> >
> >     sandbox: GPIOD_EXT_DRIVEN - in which case GPIO_EXT_HIGH provides the
> >            value
> >     outside source - in which case GPIO_EXT_PULL_UP/DOWN indicates the
> >            external state and we work the final state using those flags and
> >            the internal GPIOD_PULL_UP/DOWN flags
> >
> > Of course the outside source does not really exist in sandbox. We are just
> > modelling it for test purpose.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> > (no changes since v3)
> >
> > Changes in v3:
> > - Use bits 28, 29 for the new flags
> > - Assert that count parameter is within range
> > - Redo digit logic to be easier to understand
> > - Update function comment to explain the meaning of the digits
> > - Fix 'compare' typo
> >
> >   arch/sandbox/include/asm/gpio.h |  5 +-
> >   drivers/gpio/gpio-uclass.c      | 81 +++++++++++++++++++++++++++
> >   drivers/gpio/sandbox.c          | 13 +++--
> >   include/asm-generic/gpio.h      | 40 ++++++++++++++
> >   test/dm/gpio.c                  | 98 +++++++++++++++++++++++++++++++++
> >   5 files changed, 232 insertions(+), 5 deletions(-)
> >
> (...)
> > diff --git a/drivers/gpio/sandbox.c b/drivers/gpio/sandbox.c
> > index 700098446b5..d008fdd2224 100644
> > --- a/drivers/gpio/sandbox.c
> > +++ b/drivers/gpio/sandbox.c
> > @@ -19,7 +19,6 @@
> >   #include <dt-bindings/gpio/gpio.h>
> >   #include <dt-bindings/gpio/sandbox-gpio.h>
> >
> > -
> >   struct gpio_state {
> >       const char *label;      /* label given by requester */
> >       ulong flags;            /* flags (GPIOD_...) */
> > @@ -81,10 +80,16 @@ int sandbox_gpio_get_value(struct udevice *dev, unsigned offset)
> >       if (get_gpio_flag(dev, offset, GPIOD_IS_OUT))
> >               debug("sandbox_gpio: get_value on output gpio %u\n", offset);
> >
> > -     if (state->flags & GPIOD_EXT_DRIVEN)
> > +     if (state->flags & GPIOD_EXT_DRIVEN) {
> >               val = state->flags & GPIOD_EXT_HIGH;
>
> bool here, not int
>
> + val = !!(state->flags & GPIOD_EXT_HIGH);
>
>
> > -     else
> > -             val = false;
> > +     } else {
> > +             if (state->flags & GPIOD_EXT_PULL_UP)
> > +                     val = true;
> > +             else if (state->flags & GPIOD_EXT_PULL_DOWN)
> > +                     val = false;
> > +             else
> > +                     val = state->flags & GPIOD_PULL_UP;
>
> bool also
>
> + val = !!(state->flags & GPIOD_PULL_UP );
>
>
> > +     }
> >
> >       return val;
> >   }
>
>
> (...)
>
> Just to be sure that the sandbox gpio value is 0 or 1
>
> with the current code, sandbox_gpio_get_value can return GPIOD_EXT_HIGH
> or GPIOD_PULL_UP, and it is strange (even if result in int).

I think that is a hack to work around not having a 'bool' type, but we
do have one in U-Boot, so I feel it is better to use it, instead using
!!

See the 'bool val;' in that function.

>
>
> with these 2 changes, you can add my  Reviewed-by

Regards,
Simon

  reply	other threads:[~2021-02-08 23:41 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-05  4:21 [PATCH v4 00/16] gpio: Update and simplify the uclass API Simon Glass
2021-02-05  4:21 ` [PATCH v4 01/16] gpio: Disable functions not used with of-platdata Simon Glass
2021-03-04 18:13   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 02/16] dm: gpio: Rename set_dir_flags() method to update_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 03/16] dm: gpio: Rename get_dir_flags() method to get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 04/16] gpio: Rename dm_gpio_get_dir_flags() to dm_gpio_get_flags() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 05/16] gpio: Drop dm_gpio_set_dir() Simon Glass
2021-03-03 20:39   ` Tom Rini
2021-03-04 14:22     ` Simon Glass
2021-03-04 15:09       ` Tom Rini
2021-02-05  4:21 ` [PATCH v4 06/16] gpio: sandbox: Rename GPIO dir_flags to flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 07/16] gpio: sandbox: Use a separate flag for the value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 08/16] gpio: sandbox: Fully separate pin value from output value Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 09/16] gpio: sandbox: Make sandbox_gpio_set_flags() set all flags Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 10/16] dm: gpio: Add a way to update flags Simon Glass
2021-02-08  9:00   ` Köry Maincent
2021-02-08 17:33   ` Patrick DELAUNAY
2021-02-09  4:28     ` Simon Glass
2021-02-10  8:38       ` Patrick DELAUNAY
2021-02-13  4:17         ` Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 11/16] gpio: Replace direction_input() and direction_output() Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 12/16] gpio: Use an 'ops' variable everywhere Simon Glass
2021-03-04 18:14   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 13/16] gpio: x86: Drop the deprecated methods in intel_gpio Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 14/16] gpio: sandbox: Track whether a GPIO is driven Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 15/16] gpio: Define the log category in the uclass Simon Glass
2021-03-04 18:15   ` Tom Rini
2021-02-05  4:22 ` [PATCH v4 16/16] gpio: Add a way to read 3-way strapping pins Simon Glass
2021-02-08 18:13   ` Patrick DELAUNAY
2021-02-08 23:41     ` Simon Glass [this message]
2021-03-04 18:15   ` Tom Rini

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=CAPnjgZ1H_eOfSFKmkfOKQYJEHSou82zDk6DHDRvyitNCSPPsXA@mail.gmail.com \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.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 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.