Skip to content
Snippets Groups Projects
Commit 3a912fbc authored by Ahmad Fatoum's avatar Ahmad Fatoum Committed by Bartosz Golaszewski
Browse files

tools: gpioget: add new --dir-as-is option for GPO read-back


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: default avatarAhmad Fatoum <a.fatoum@pengutronix.de>
Signed-off-by: default avatarBartosz Golaszewski <brgl@bgdev.pl>
parent 55a8c62e
No related branches found
No related tags found
No related merge requests found
......@@ -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");
......@@ -38,6 +40,7 @@ static void print_help(void)
int main(int argc, char **argv)
{
int request_type = GPIOD_LINE_REQUEST_DIRECTION_INPUT;
struct gpiod_line_request_config config;
int *values, optc, opti, rv, flags = 0;
unsigned int *offsets, i, num_lines;
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment