From: Marek Vasut Date: Tue, 1 May 2012 22:50:15 +0200 Subject: [U-Boot] [PATCH 2/2] GPIO: Implement gpio_{from, to}_string on M28EVK In-Reply-To: <1335905416-22535-1-git-send-email-marex@denx.de> References: <1335905416-22535-1-git-send-email-marex@denx.de> Message-ID: <1335905416-22535-2-git-send-email-marex@denx.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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 Cc: Detlev Zundel Cc: Mike Frysinger Cc: Stefano Babic --- 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