linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
To: Ahmad Fatoum <a.fatoum@pengutronix.de>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	linux-gpio <linux-gpio@vger.kernel.org>,
	Sascha Hauer <kernel@pengutronix.de>
Subject: Re: [libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back
Date: Fri, 30 Apr 2021 22:02:21 +0200	[thread overview]
Message-ID: <CAMpxmJVtr9adabOjZ6VQg5rNh7sOyKnr3TtwWW1D2_zzM564rw@mail.gmail.com> (raw)
In-Reply-To: <20210427154224.30372-1-a.fatoum@pengutronix.de>

On Tue, Apr 27, 2021 at 5:42 PM Ahmad Fatoum <a.fatoum@pengutronix.de> wrote:
>
> Both legacy sysfs and new character device API support querying line
> state of a GPIO configured as output. But while sysfs /value can
> be read for these output GPIOs, gpioget unconditionally muxes the
> line as input. To ease migration to the new user API, add a new
> --dir-as-is parameter that doesn't force the line to input.
>
> This is especially useful for GPIO controllers that maintain their
> last configured output state.
>
> Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
> ---
> -n is chosen for the short option because it's the customary short
> option for dry runs, which sounds similar to what a gpio get without
> line state configuration is doing.
> ---
>  tools/gpioget.c | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/tools/gpioget.c b/tools/gpioget.c
> index ceeec566683a..bfbf5ea748be 100644
> --- a/tools/gpioget.c
> +++ b/tools/gpioget.c
> @@ -13,11 +13,12 @@ static const struct option longopts[] = {
>         { "help",       no_argument,            NULL,   'h' },
>         { "version",    no_argument,            NULL,   'v' },
>         { "active-low", no_argument,            NULL,   'l' },
> +       { "dir-as-is",  no_argument,            NULL,   'n' },
>         { "bias",       required_argument,      NULL,   'B' },
>         { GETOPT_NULL_LONGOPT },
>  };
>
> -static const char *const shortopts = "+hvlB:";
> +static const char *const shortopts = "+hvlnB:";
>
>  static void print_help(void)
>  {
> @@ -30,6 +31,7 @@ static void print_help(void)
>         printf("  -h, --help:\t\tdisplay this message and exit\n");
>         printf("  -v, --version:\tdisplay the version and exit\n");
>         printf("  -l, --active-low:\tset the line active state to low\n");
> +       printf("  -n, --dir-as-is:\tdon't force-reconfigure line direction\n");
>         printf("  -B, --bias=[as-is|disable|pull-down|pull-up] (defaults to 'as-is'):\n");
>         printf("                set the line bias\n");
>         printf("\n");
> @@ -40,6 +42,7 @@ int main(int argc, char **argv)
>  {
>         struct gpiod_line_request_config config;
>         int *values, optc, opti, rv, flags = 0;
> +       int request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT;
>         unsigned int *offsets, i, num_lines;
>         struct gpiod_line_bulk *lines;
>         struct gpiod_chip *chip;
> @@ -60,6 +63,9 @@ int main(int argc, char **argv)
>                 case 'l':
>                         flags |= GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW;
>                         break;
> +               case 'n':
> +                       request_type = GPIOD_LINE_REQUEST_DIRECTION_AS_IS;
> +                       break;
>                 case 'B':
>                         flags |= bias_flags(optarg);
>                         break;
> @@ -104,7 +110,7 @@ int main(int argc, char **argv)
>         memset(&config, 0, sizeof(config));
>
>         config.consumer = "gpioget";
> -       config.request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT;
> +       config.request_type = request_type;
>         config.flags = flags;
>
>         rv = gpiod_line_request_bulk(lines, &config, NULL);
> --
> 2.29.2
>

Makes sense, applied to master.

It'll take some time until this is released though, libgpiod v2 is in
the making and I no longer add new features to the v1.6.x branch
anymore.

Thanks!
Bartosz

      reply	other threads:[~2021-04-30 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-27 15:42 [libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back Ahmad Fatoum
2021-04-30 20:02 ` 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=CAMpxmJVtr9adabOjZ6VQg5rNh7sOyKnr3TtwWW1D2_zzM564rw@mail.gmail.com \
    --to=bgolaszewski@baylibre.com \
    --cc=a.fatoum@pengutronix.de \
    --cc=kernel@pengutronix.de \
    --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 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).