aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-06-19 17:55:09 +0530
committerSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-06-19 17:55:09 +0530
commit75eadf3a05d571a038f65e0eee1f6ff1d82524e0 (patch)
tree99e90c65fc24e29744ee9873400f421714df9070
parent03fdbc0dae549db0eb333732807607cf40e80d55 (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.c27
1 files changed, 15 insertions, 12 deletions
diff --git a/gpio.c b/gpio.c
index 4a42cb7..39480b0 100644
--- a/gpio.c
+++ b/gpio.c
@@ -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)