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

login
register
mail settings
Submitter Joe Hershberger
Date Aug. 10, 2011, 6:27 a.m.
Message ID <1312957662-1181-1-git-send-email-joe.hershberger@ni.com>
Download mbox | patch
Permalink /patch/109328/
State Rejected
Headers show

Comments

Joe Hershberger - Aug. 10, 2011, 6:27 a.m.
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(-)
Mike Frysinger - Aug. 11, 2011, 1:33 a.m.
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
Joe Hershberger - Aug. 11, 2011, 2:07 a.m.
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
Mike Frysinger - Aug. 11, 2011, 3:44 a.m.
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

Patch

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");