@@ -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;
+}
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(+)