[U-Boot] [PATCH 2/2] GPIO: Implement gpio_{from, to}_string on M28EVK

Marek Vasut marex at denx.de
Tue May 1 22:50:15 CEST 2012


Implement the above two functions. The format of input parameters is
"x_y", where x is the bank number and y is the pin number in that bank.

Example:
  => gpio i 3_13
  gpio: pin 3_13 (gpio 107) value is 0

Signed-off-by: Marek Vasut <marex at denx.de>
Cc: Detlev Zundel <dzu at denx.de>
Cc: Mike Frysinger <vapier at gentoo.org>
Cc: Stefano Babic <sbabic at denx.de>
---
 drivers/gpio/mxs_gpio.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/drivers/gpio/mxs_gpio.c b/drivers/gpio/mxs_gpio.c
index 38dbc81..988b105 100644
--- a/drivers/gpio/mxs_gpio.c
+++ b/drivers/gpio/mxs_gpio.c
@@ -130,3 +130,35 @@ int gpio_free(unsigned gpio)
 {
 	return 0;
 }
+
+int gpio_from_string(const char *cname)
+{
+	char *name = (char *)cname;
+	char *bank, *pin, *endp;
+	int b, p;
+
+	bank = strtok(name, "_");
+	if (!bank)
+		return -1;
+
+	pin = strtok(NULL, "_");
+	if (!pin)
+		return -1;
+
+	b = simple_strtol(bank, &endp, 10);
+	if (*endp != '\0')
+		return -1;
+
+	p = simple_strtol(pin, &endp, 10);
+	if (*endp != '\0')
+		return -1;
+
+	return MXS_IOMUX_PAD(b, p, 0, 0, 0, 0);
+}
+
+int gpio_to_string(int gpio, char *buf, int buflen)
+{
+	int ret;
+	ret = snprintf(buf, buflen, "%i_%i", PAD_BANK(gpio), PAD_PIN(gpio));
+	return ret < buflen;
+}
-- 
1.7.10



More information about the U-Boot mailing list