[libgpiod][PATCH] tools: gpioget: add new --dir-as-is option for GPO read-back

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxxx>
---
-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




[Index of Archives]     [Linux SPI]     [Linux Kernel]     [Linux ARM (vger)]     [Linux ARM MSM]     [Linux Omap]     [Linux Arm]     [Linux Tegra]     [Fedora ARM]     [Linux for Samsung SOC]     [eCos]     [Linux Fastboot]     [Gcc Help]     [Git]     [DCCP]     [IETF Announce]     [Security]     [Linux MIPS]     [Yosemite Campsites]

  Powered by Linux