diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-24 12:58:33 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-25 11:24:02 -0700 |
commit | 2957c3cf8b2275a1a6803bc4e141a30533cc2f1e (patch) | |
tree | ffe990e9e523b93023375dc0cce28a767adbbd02 /common/gpio_commands.c | |
parent | cbee62d01e94ef5fc8539742ca995cc62b0ee96a (diff) | |
download | chrome-ec-2957c3cf8b2275a1a6803bc4e141a30533cc2f1e.tar.gz |
Clean up GPIO module
Just code cleanup; no functional changes
BUG=chrome-os-partner:15579
BRANCH=none
TEST=build code; boot link; gpioget still works
Change-Id: If0770c1a5ce0d5c51ba528fbe2944a73fafa949b
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36556
Reviewed-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'common/gpio_commands.c')
-rw-r--r-- | common/gpio_commands.c | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/common/gpio_commands.c b/common/gpio_commands.c index 2768540115..e429bc09a9 100644 --- a/common/gpio_commands.c +++ b/common/gpio_commands.c @@ -12,12 +12,15 @@ #include "system.h" #include "util.h" - static uint8_t last_val[(GPIO_COUNT + 7) / 8]; - -/* Find a GPIO signal by name. Returns the signal index, or GPIO_COUNT if - * no match. */ +/** + * Find a GPIO signal by name. + * + * @param name Signal name to find + * + * @return the signal index, or GPIO_COUNT if no match. + */ static enum gpio_signal find_signal_by_name(const char *name) { const struct gpio_info *g = gpio_list; @@ -34,9 +37,14 @@ static enum gpio_signal find_signal_by_name(const char *name) return GPIO_COUNT; } - -/* If v is different from the last value for index i, updates the last value - * and returns 1; else returns 0. */ +/** + * Update last_val + * + * @param i Index of last_val[] to update + * @param v New value for last_val[i] + * + * @return 1 if last_val[i] was updated, 0 if last_val[i]==v. + */ static int last_val_changed(int i, int v) { if (v && !(last_val[i / 8] & (1 << (i % 8)))) { @@ -80,8 +88,7 @@ static int command_gpio_get(int argc, char **argv) changed = last_val_changed(i, v); ccprintf(" %d%c %s\n", v, (changed ? '*' : ' '), g->name); - /* We have enough GPIOs that we'll overflow the output buffer - * without flushing */ + /* Flush console to avoid truncating output */ cflush(); } return EC_SUCCESS; @@ -91,7 +98,6 @@ DECLARE_CONSOLE_COMMAND(gpioget, command_gpio_get, "Read GPIO value(s)", NULL); - static int command_gpio_set(int argc, char **argv) { const struct gpio_info *g; @@ -116,7 +122,9 @@ static int command_gpio_set(int argc, char **argv) if (*e) return EC_ERROR_PARAM2; - return gpio_set_level(i, v); + gpio_set_level(i, v); + + return EC_SUCCESS; } DECLARE_CONSOLE_COMMAND(gpioset, command_gpio_set, "name <0 | 1>", @@ -145,7 +153,6 @@ static int gpio_command_get(struct host_cmd_handler_args *args) } DECLARE_HOST_COMMAND(EC_CMD_GPIO_GET, gpio_command_get, EC_VER_MASK(0)); - static int gpio_command_set(struct host_cmd_handler_args *args) { const struct ec_params_gpio_set *p = args->params; @@ -166,8 +173,8 @@ static int gpio_command_set(struct host_cmd_handler_args *args) if (!(g->flags & GPIO_OUTPUT)) return EC_RES_ERROR; - if (gpio_set_level(i, p->val) != EC_SUCCESS) - return EC_RES_ERROR; + gpio_set_level(i, p->val); + return EC_RES_SUCCESS; } DECLARE_HOST_COMMAND(EC_CMD_GPIO_SET, gpio_command_set, EC_VER_MASK(0)); |