[U-Boot] [PATCH] gpio: Expand cmd_gpio functionality and script friendliness

Add quiet parameter to cmd_gpio for use when part of a script Enable repeat... especially useful when used with input and toggle Add "outstate" command that will return and print the state of an output
Signed-off-by: Joe Hershberger joe.hershberger@ni.com Cc: Joe Hershberger joe.hershberger@gmail.com Cc: Mike Frysinger vapier@gentoo.org --- common/cmd_gpio.c | 39 ++++++++++++++++++++++++--------------- 1 files changed, 24 insertions(+), 15 deletions(-)
diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c index 9cc790a..0acb93e 100644 --- a/common/cmd_gpio.c +++ b/common/cmd_gpio.c @@ -20,6 +20,7 @@ enum gpio_cmd { GPIO_SET, GPIO_CLEAR, GPIO_TOGGLE, + GPIO_OUTSTATE, };
static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) @@ -27,7 +28,7 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) int gpio; enum gpio_cmd sub_cmd; ulong value; - const char *str_cmd, *str_gpio; + const char *str_cmd, *str_gpio, *str_quiet = "0";
#ifdef gpio_status if (argc == 2 && !strcmp(argv[1], "status")) { @@ -36,18 +37,22 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) } #endif
- if (argc != 3) + if (argc != 3 && argc != 4) show_usage: return cmd_usage(cmdtp); + str_cmd = argv[1]; str_gpio = argv[2]; + if (argc == 4) + str_quiet = argv[3];
/* parse the behavior */ switch (*str_cmd) { - case 'i': sub_cmd = GPIO_INPUT; break; - case 's': sub_cmd = GPIO_SET; break; - case 'c': sub_cmd = GPIO_CLEAR; break; - case 't': sub_cmd = GPIO_TOGGLE; break; + case 'i': sub_cmd = GPIO_INPUT; break; + case 's': sub_cmd = GPIO_SET; break; + case 'c': sub_cmd = GPIO_CLEAR; break; + case 't': sub_cmd = GPIO_TOGGLE; break; + case 'o': sub_cmd = GPIO_OUTSTATE; break; default: goto show_usage; }
@@ -68,22 +73,26 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) value = gpio_get_value(gpio); } else { switch (sub_cmd) { - case GPIO_SET: value = 1; break; - case GPIO_CLEAR: value = 0; break; - case GPIO_TOGGLE: value = !gpio_get_value(gpio); break; + case GPIO_SET: value = 1; break; + case GPIO_CLEAR: value = 0; break; + case GPIO_TOGGLE: value = !gpio_get_value(gpio); break; + case GPIO_OUTSTATE: value = gpio_get_value(gpio); break; default: goto show_usage; } gpio_direction_output(gpio, value); } - printf("gpio: pin %s (gpio %i) value is %lu\n", - str_gpio, gpio, value); + + if (*str_quiet == '0') + printf("gpio: pin %s (gpio %i) value is %lu\n", + str_gpio, gpio, value);
gpio_free(gpio);
return value; }
-U_BOOT_CMD(gpio, 3, 0, do_gpio, - "input/set/clear/toggle gpio pins", - "<input|set|clear|toggle> <pin>\n" - " - input/set/clear/toggle the specified pin"); +U_BOOT_CMD(gpio, 4, 1, do_gpio, + "input/set/clear/toggle/outstate gpio pins", + "<input|set|clear|toggle|outstate> <pin> [quiet]\n" + " - input/set/clear/toggle/outstate the specified pin\n" + " - quiet: if 1, do not print");

On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:
Add quiet parameter to cmd_gpio for use when part of a script Enable repeat... especially useful when used with input and toggle Add "outstate" command that will return and print the state of an output
a similar patch was posted somewhat recently but was declined. please see the archive for more info. -mike

Hi Mike,
On Wed, Aug 10, 2011 at 8:33 PM, Mike Frysinger vapier@gentoo.org wrote:
On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:
Add quiet parameter to cmd_gpio for use when part of a script Enable repeat... especially useful when used with input and toggle Add "outstate" command that will return and print the state of an output
a similar patch was posted somewhat recently but was declined. please see the archive for more info.
I attempted to locate what you are referring to, but had no luck. I saw nothing that referenced "cmd_gpio" that was similar. Any clues about what aspects were rejected so I'll have a better idea what to search for? Possibly who rejected it?
Thanks, -Joe

On Wednesday, August 10, 2011 22:07:28 Joe Hershberger wrote:
On Wed, Aug 10, 2011 at 8:33 PM, Mike Frysinger wrote:
On Wednesday, August 10, 2011 02:27:42 Joe Hershberger wrote:
Add quiet parameter to cmd_gpio for use when part of a script Enable repeat... especially useful when used with input and toggle Add "outstate" command that will return and print the state of an output
a similar patch was posted somewhat recently but was declined. please see the archive for more info.
I attempted to locate what you are referring to, but had no luck. I saw nothing that referenced "cmd_gpio" that was similar. Any clues about what aspects were rejected so I'll have a better idea what to search for? Possibly who rejected it?
[U-Boot] [RFC] gpio command: return value on write, additional actions -mike
participants (3)
-
Joe Hershberger
-
Joe Hershberger
-
Mike Frysinger