diff options
author | Shaojie Sun <shaojie.sun@linaro.org> | 2013-07-29 20:11:46 +0800 |
---|---|---|
committer | Sanjay Singh Rawat <sanjay.rawat@linaro.org> | 2013-08-08 10:21:57 +0530 |
commit | 8ac4a2e9930a970da69d9c26d7cd5b5d08b6e184 (patch) | |
tree | 8eddd67588b3d65f79a797f00c800c8381eb53eb | |
parent | 564a1fe7c674bb1c65135c8eef91e773455859bb (diff) | |
download | powerdebug-8ac4a2e9930a970da69d9c26d7cd5b5d08b6e184.tar.gz |
gpio: add modify gpio function in powerdebug tool.
For power consumption test, we can change gpio direction and value
and check that power consumption is falled or not.
use 'D' key to change gpio direction.
And when gpio direction is "out", use 'V' key to change gpio value.
Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
-rw-r--r-- | README | 8 | ||||
-rw-r--r-- | display.c | 18 | ||||
-rw-r--r-- | display.h | 1 | ||||
-rw-r--r-- | gpio.c | 45 | ||||
-rw-r--r-- | utils.c | 36 | ||||
-rw-r--r-- | utils.h | 2 |
6 files changed, 109 insertions, 1 deletions
@@ -7,4 +7,10 @@ information. Current version only displays regulator information and clock tree from debugfs. Support will be added for sensors later. - -- Amit Arora <amit.arora@linaro.org> Fri, 08 Sep 2010 + -- Amit Arora <amit.arora@linaro.org> Fri, 08 Sep 2010 + +Now we add gpio-change function for power consumption need. +When gpio is not in interrupt mode. use 'D' key to change gpio direction. +And when gpio direction is "out", use 'V' key to change gpio value. + + -- Shaojie Sun <shaojie.sun@linaro.org> Mon, 29 Jul 2013 @@ -164,6 +164,17 @@ static int display_select(void) return 0; } +static int display_change(int keyvalue) +{ + if (!(windata[current_win].nrdata)) + return 0; + + if (windata[current_win].ops && windata[current_win].ops->change) + return windata[current_win].ops->change(keyvalue); + + return 0; +} + static int display_next_panel(void) { size_t array_size = sizeof(windata) / sizeof(windata[0]); @@ -406,6 +417,13 @@ static int display_keystroke(int fd, void *data) display_select(); break; + case 'v': + case 'V': + case 'd': + case 'D': + display_change(toupper(keystroke)); + break; + case EOF: case 'q': case 'Q': @@ -20,6 +20,7 @@ struct display_ops { int (*select)(void); int (*find)(const char *); int (*selectf)(void); + int (*change)(int keyvalue); }; extern int display_print_line(int window, int line, char *str, @@ -264,8 +264,53 @@ static int gpio_display(bool refresh) return gpio_print_info(gpio_tree); } +static int gpio_change(int keyvalue) +{ + struct tree *t = display_get_row_data(GPIO); + struct gpio_info *gpio = t->private; + + if (!t || !gpio) + return -1; + + switch (keyvalue) { + case 'D': + /* Only change direction when gpio interrupt not set.*/ + if (!strstr(gpio->edge, "none")) + return 0; + + if (strstr(gpio->direction, "in")) + strcpy(gpio->direction, "out"); + else if (strstr(gpio->direction, "out")) + strcpy(gpio->direction, "in"); + file_write_value(t->path, "direction", "%s", &gpio->direction); + file_read_value(t->path, "direction", "%s", &gpio->direction); + + break; + + case 'V': + /* Only change value when gpio direction is out. */ + if (!strstr(gpio->edge, "none") + || !strstr(gpio->direction, "out")) + return 0; + + if (gpio->value) + file_write_value(t->path, "direction", "%s", &"low"); + else + file_write_value(t->path, "direction", "%s", &"high"); + file_read_value(t->path, "value", "%d", &gpio->value); + + break; + + default: + return -1; + } + + return 0; +} + static struct display_ops gpio_ops = { .display = gpio_display, + .change = gpio_change, }; /* @@ -53,3 +53,39 @@ out_free: free(rpath); return ret; } + +/* + * This functions is a helper to write a specific file content and store + * the content inside a variable pointer passed as parameter, the format + * parameter gives the variable type to be write to the file. + * + * @path : directory path containing the file + * @name : name of the file to be read + * @format : the format of the format + * @value : a pointer to a variable to store the content of the file + * Returns 0 on success, -1 otherwise + */ +int file_write_value(const char *path, const char *name, + const char *format, void *value) +{ + FILE *file; + char *rpath; + int ret; + + ret = asprintf(&rpath, "%s/%s", path, name); + if (ret < 0) + return ret; + + file = fopen(rpath, "w"); + if (!file) { + ret = -1; + goto out_free; + } + + ret = fprintf(file, format, value) < 0 ? -1 : 0; + + fclose(file); +out_free: + free(rpath); + return ret; +} @@ -17,6 +17,8 @@ extern int file_read_value(const char *path, const char *name, const char *format, void *value); +extern int file_write_value(const char *path, const char *name, + const char *format, void *value); #endif |