linux-gpio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back
@ 2021-04-27 15:42 Ahmad Fatoum
  2021-04-30 20:02 ` Bartosz Golaszewski
  0 siblings, 1 reply; 2+ messages in thread
From: Ahmad Fatoum @ 2021-04-27 15:42 UTC (permalink / raw)
  To: Linus Walleij, Bartosz Golaszewski, linux-gpio; +Cc: kernel, Ahmad Fatoum

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


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back
  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
  0 siblings, 0 replies; 2+ messages in thread
From: Bartosz Golaszewski @ 2021-04-30 20:02 UTC (permalink / raw)
  To: Ahmad Fatoum; +Cc: Linus Walleij, linux-gpio, Sascha Hauer

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-04-30 20:02 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).