public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH 1/2] GPIO: Extend the cmd_gpio API by gpio_{from, to}_string()
@ 2012-05-01 20:50 Marek Vasut
  2012-05-01 20:50 ` [U-Boot] [PATCH 2/2] GPIO: Implement gpio_{from, to}_string on M28EVK Marek Vasut
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Marek Vasut @ 2012-05-01 20:50 UTC (permalink / raw)
  To: u-boot

The gpio_from_string() call shall parse the incoming GPIO name taken
from the command line and return the GPIO number used within U-Boot or
return -1 on error.

The gpio_to_string() on the other hand allows nicer reporting of GPIO
name in the output of cmd_gpio.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Stefano Babic <sbabic@denx.de>
---
 common/cmd_gpio.c |   27 +++++++++++++++++++++++----
 1 file changed, 23 insertions(+), 4 deletions(-)

diff --git a/common/cmd_gpio.c b/common/cmd_gpio.c
index 47eee89..12870ef 100644
--- a/common/cmd_gpio.c
+++ b/common/cmd_gpio.c
@@ -15,6 +15,22 @@
 #define name_to_gpio(name) simple_strtoul(name, NULL, 10)
 #endif
 
+int __gpio_from_string(const char *name)
+{
+	return name_to_gpio(name);
+}
+
+int gpio_from_string(const char *name)
+	__attribute__((weak, alias("__gpio_from_string")));
+
+int __gpio_to_string(int gpio, char *buf, int buflen)
+{
+	return 0;
+}
+
+int gpio_to_string(int gpio, char *buf, int buflen)
+	__attribute__((weak, alias("__gpio_from_string")));
+
 enum gpio_cmd {
 	GPIO_INPUT,
 	GPIO_SET,
@@ -27,7 +43,9 @@ 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;
+	char str_gpio[16] = { 0 };
+	int ret;
 
 #ifdef gpio_status
 	if (argc == 2 && !strcmp(argv[1], "status")) {
@@ -40,7 +58,6 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  show_usage:
 		return CMD_RET_USAGE;
 	str_cmd = argv[1];
-	str_gpio = argv[2];
 
 	/* parse the behavior */
 	switch (*str_cmd) {
@@ -52,7 +69,7 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 	}
 
 	/* turn the gpio name into a gpio number */
-	gpio = name_to_gpio(str_gpio);
+	gpio = gpio_from_string(argv[2]);
 	if (gpio < 0)
 		goto show_usage;
 
@@ -75,8 +92,10 @@ static int do_gpio(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
 		}
 		gpio_direction_output(gpio, value);
 	}
+
+	ret = gpio_to_string(gpio, str_gpio, sizeof(str_gpio));
 	printf("gpio: pin %s (gpio %i) value is %lu\n",
-		str_gpio, gpio, value);
+		ret ? str_gpio : argv[2], gpio, value);
 
 	gpio_free(gpio);
 
-- 
1.7.10

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

end of thread, other threads:[~2012-08-02 17:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-05-01 20:50 [U-Boot] [PATCH 1/2] GPIO: Extend the cmd_gpio API by gpio_{from, to}_string() Marek Vasut
2012-05-01 20:50 ` [U-Boot] [PATCH 2/2] GPIO: Implement gpio_{from, to}_string on M28EVK Marek Vasut
2012-05-09 18:29 ` [U-Boot] [PATCH 1/2] GPIO: Extend the cmd_gpio API by gpio_{from, to}_string() Marek Vasut
2012-05-14  5:51 ` Mike Frysinger
2012-05-14 11:31   ` Marek Vasut
2012-05-14 16:14     ` Mike Frysinger
2012-05-14 18:25       ` Marek Vasut
2012-05-15  5:11         ` Mike Frysinger
2012-05-15  5:53           ` Marek Vasut
2012-05-18  2:53             ` Mike Frysinger
2012-08-02 10:05       ` Marek Vasut
2012-08-02 17:50         ` Mike Frysinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox