dump the gpio informations

Now we dump the output to the stdout.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
diff --git a/gpio.c b/gpio.c
index 8e7499d..562a11d 100644
--- a/gpio.c
+++ b/gpio.c
@@ -39,6 +39,7 @@
 	int value;
 	int direction;
 	int edge;
+	char *prefix;
 } *gpios_info;
 
 static struct tree *gpio_tree = NULL;
@@ -48,8 +49,10 @@
 	struct gpio_info *gi;
 
 	gi = malloc(sizeof(*gi));
-	if (gi)
-		memset(gi, 0, sizeof(*gi));
+	if (gi) {
+		memset(gi, -1, sizeof(*gi));
+		gi->prefix = NULL;
+	}
 
 	return gi;
 }
@@ -148,9 +151,45 @@
 	return tree_for_each(gpio_tree, fill_gpio_cb, NULL);
 }
 
+static int dump_gpio_cb(struct tree *t, void *data)
+{
+	struct gpio_info *gpio = t->private;
+	struct gpio_info *pgpio;
+
+	if (!t->parent) {
+		printf("/\n");
+		gpio->prefix = "";
+		return 0;
+	}
+
+	pgpio = t->parent->private;
+
+	if (!gpio->prefix)
+		if (asprintf(&gpio->prefix, "%s%s%s", pgpio->prefix,
+			     t->depth > 1 ? "   ": "", t->next ? "|" : " ") < 0)
+			return -1;
+
+	printf("%s%s-- %s (active_low:%d)\n",
+	       gpio->prefix,  !t->next ? "`" : "", t->name, gpio->active_low);
+
+	return 0;
+}
+
+int dump_gpio_info(void)
+{
+	return tree_for_each(gpio_tree, dump_gpio_cb, NULL);
+}
+
 int gpio_dump(void)
 {
-	return 0;
+	int ret;
+
+	printf("\nGpio Tree :\n");
+	printf("***********\n");
+	ret = dump_gpio_info();
+	printf("\n\n");
+
+	return ret;
 }
 
 /*