aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2011-08-25 15:46:13 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2011-08-25 15:46:13 +0200
commit5e26728f1f4ed90ae9335bcc007eecfdbe3ee99c (patch)
treee377d28ad5fa13f85790312011f96640b14d2a04
parent9d8475b39bcdb958ea80f667a043b216c3ae80df (diff)
downloadpowerdebug-5e26728f1f4ed90ae9335bcc007eecfdbe3ee99c.tar.gz
dump the gpio informations
Now we dump the output to the stdout. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--gpio.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/gpio.c b/gpio.c
index 8e7499d..562a11d 100644
--- a/gpio.c
+++ b/gpio.c
@@ -39,6 +39,7 @@ struct gpio_info {
int value;
int direction;
int edge;
+ char *prefix;
} *gpios_info;
static struct tree *gpio_tree = NULL;
@@ -48,8 +49,10 @@ static struct gpio_info *gpio_alloc(void)
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,11 +151,47 @@ static int fill_gpio_tree(void)
return tree_for_each(gpio_tree, fill_gpio_cb, NULL);
}
-int gpio_dump(void)
+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)
+{
+ int ret;
+
+ printf("\nGpio Tree :\n");
+ printf("***********\n");
+ ret = dump_gpio_info();
+ printf("\n\n");
+
+ return ret;
+}
+
/*
* Initialize the gpio framework
*/