aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShaojie Sun <shaojie.sun@linaro.org>2013-07-25 19:02:08 +0800
committerSanjay Singh Rawat <sanjay.rawat@linaro.org>2013-08-08 10:08:26 +0530
commit564a1fe7c674bb1c65135c8eef91e773455859bb (patch)
treea5f1026710af2e815af9370cdd8e485284d994a3
parent3c5f466d29c7a18af517d868fbb3ed26f0a1e028 (diff)
gpio: show gpio direction and egde in string.
In gpio sysfs, direction and egde is shown in string. dierction value is "in" or "out". And egde value is "none", "falling", "rising" or "both". So string must be shown also in powerdebug tool. Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
-rw-r--r--gpio.c22
1 files changed, 13 insertions, 9 deletions
diff --git a/gpio.c b/gpio.c
index f7d2a10..3ecc393 100644
--- a/gpio.c
+++ b/gpio.c
@@ -33,12 +33,14 @@
#define SYSFS_GPIO "/sys/class/gpio"
+#define MAX_VALUE_BYTE 10
+
struct gpio_info {
bool expanded;
int active_low;
int value;
- int direction;
- int edge;
+ char direction[MAX_VALUE_BYTE];
+ char edge[MAX_VALUE_BYTE];
char *prefix;
} *gpios_info;
@@ -51,6 +53,8 @@ static struct gpio_info *gpio_alloc(void)
gi = malloc(sizeof(*gi));
if (gi) {
memset(gi, -1, sizeof(*gi));
+ memset(gi->direction, 0, MAX_VALUE_BYTE);
+ memset(gi->edge, 0, MAX_VALUE_BYTE);
gi->prefix = NULL;
}
@@ -89,8 +93,8 @@ static inline int read_gpio_cb(struct tree *t, void *data)
file_read_value(t->path, "active_low", "%d", &gpio->active_low);
file_read_value(t->path, "value", "%d", &gpio->value);
- file_read_value(t->path, "edge", "%d", &gpio->edge);
- file_read_value(t->path, "direction", "%d", &gpio->direction);
+ file_read_value(t->path, "edge", "%8s", &gpio->edge);
+ file_read_value(t->path, "direction", "%4s", &gpio->direction);
return 0;
}
@@ -150,11 +154,11 @@ static int dump_gpio_cb(struct tree *t, void *data)
if (gpio->value != -1)
printf(", value:%d", gpio->value);
- if (gpio->edge != -1)
- printf(", edge:%d", gpio->edge);
+ if (gpio->edge[0] != 0)
+ printf(", edge:%s", gpio->edge);
- if (gpio->direction != -1)
- printf(", direction:%d", gpio->direction);
+ if (gpio->direction[0] != 0)
+ printf(", direction:%s", gpio->direction);
printf(" )\n");
@@ -183,7 +187,7 @@ static char *gpio_line(struct tree *t)
struct gpio_info *gpio = t->private;
char *gpioline;
- if (asprintf(&gpioline, "%-20s %-10d %-10d %-10d %-10d", t-> name,
+ if (asprintf(&gpioline, "%-20s %-10d %-10d %-10s %-10s", t->name,
gpio->value, gpio->active_low, gpio->edge, gpio->direction) < 0)
return NULL;