diff mbox

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

Message ID 1335905416-22535-2-git-send-email-marex@denx.de
State Changes Requested
Delegated to: Mike Frysinger
Headers show

Commit Message

Marek Vasut May 1, 2012, 8:50 p.m. UTC
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@denx.de>
Cc: Detlev Zundel <dzu@denx.de>
Cc: Mike Frysinger <vapier@gentoo.org>
Cc: Stefano Babic <sbabic@denx.de>
---
 drivers/gpio/mxs_gpio.c |   32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
diff mbox

Patch

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;
+}