diff mbox

[POWERDEBUG] gpio: expose free gpios to user

Message ID 1401698808-31421-1-git-send-email-sanjay.rawat@linaro.org
State New
Headers show

Commit Message

Sanjay Singh Rawat June 2, 2014, 8:46 a.m. UTC
- 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>
---
 gpio.c |   27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)
diff mbox

Patch

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)