aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-05-16 10:58:47 +0530
committerSanjay Singh Rawat <sanjay.rawat@linaro.org>2014-05-16 11:05:01 +0530
commitb21205477658e0ba9eb5af8ac2ee5f0877b1d380 (patch)
tree9370fb7c09efd148ca78c311b7cafc7b52a1ce2c
parentd715f63e70fad226a90bab47d881a9b472b321fe (diff)
gpio: add function to export gpios
Many platforms don't have gpio signals available to userspace in gpio class. This function adds support to export gpios. Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
-rw-r--r--gpio.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/gpio.c b/gpio.c
index 7cc16f7..4006a5a 100644
--- a/gpio.c
+++ b/gpio.c
@@ -314,11 +314,49 @@ static struct display_ops gpio_ops = {
.change = gpio_change,
};
+void export_gpios(void)
+{
+ FILE *fgpio, *fgpio_export;
+ int ret = 0, gpio[256], num = 0;
+ char *line;
+ ssize_t read, len;
+
+ fgpio = fopen("/sys/kernel/debug/gpio", "r");
+ if (!fgpio) {
+ printf("failed to read debugfs gpio file\n");
+ ret = -1;
+ goto out;
+ }
+
+ fgpio_export = fopen("/sys/class/gpio/export", "w");
+ if (!fgpio_export) {
+ printf("failed to write open gpio-export file\n");
+ ret = -1;
+ goto out;
+ }
+
+ /* 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++;
+ }
+ }
+out:
+ return;
+}
+
/*
* Initialize the gpio framework
*/
int gpio_init(void)
{
+ export_gpios();
+
gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false);
if (!gpio_tree)
return -1;