diff options
author | Sanjay Singh Rawat <sanjay.rawat@linaro.org> | 2014-06-19 17:55:09 +0530 |
---|---|---|
committer | Sanjay Singh Rawat <sanjay.rawat@linaro.org> | 2014-06-19 17:55:09 +0530 |
commit | 75eadf3a05d571a038f65e0eee1f6ff1d82524e0 (patch) | |
tree | 99e90c65fc24e29744ee9873400f421714df9070 | |
parent | 03fdbc0dae549db0eb333732807607cf40e80d55 (diff) |
gpio: expose free gpios to user
- GPIOs in the SoC will be free/used state, this patch make free gpios
accessible to the user by exporting them.
- bug 1229658
Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
-rw-r--r-- | gpio.c | 27 |
1 files changed, 15 insertions, 12 deletions
@@ -320,10 +320,10 @@ static struct display_ops gpio_ops = { .change = gpio_change, }; -void export_gpios(void) +void export_free_gpios(void) { FILE *fgpio, *fgpio_export; - int gpio[256], num = 0; + int i, gpio_max = 0; char *line = NULL; ssize_t read, len; @@ -340,15 +340,18 @@ void export_gpios(void) } /* export the gpios */ - while (read = getline(&line, &len, fgpio) != -1) { - char *str; - - if (strstr(line, "gpio-")) { - str = strtok(line, " "); - sscanf(str, "gpio-%d", &gpio[num]); - fprintf(fgpio_export, "%d", gpio[num]); - num++; - } + while ((read = getline(&line, &len, fgpio)) != -1) { + if (strstr(line, "GPIOs")) + sscanf(line, "%*[^-]-%d%*", &gpio_max); + } + + printf("log: total gpios = %d\n", gpio_max); + for (i = 0 ; i <= gpio_max ; i++) { + char command[50] = ""; + + sprintf(command, "echo %d > /sys/class/gpio/export", i); + if (system(command) < 0) + printf("error: failed to export gpio-%d\n", i); } out: return; @@ -368,7 +371,7 @@ int gpio_init(void) if (access(SYSFS_GPIO, F_OK)) gpio_error = true; /* set the flag */ - export_gpios(); + export_free_gpios(); gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false); if (!gpio_tree) |