summaryrefslogtreecommitdiff
path: root/common/gpio_commands.c
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2012-07-11 10:10:47 +0800
committerGerrit <chrome-bot@google.com>2012-07-13 12:24:00 -0700
commit37f19ecc84d506ece33d5c19b5e02b7ab71549dc (patch)
tree51870677ed0dc3de0739d01389b9ce3939ce9126 /common/gpio_commands.c
parentdbefb29f028108c6faadb40acebf942dfe51b92c (diff)
downloadchrome-ec-37f19ecc84d506ece33d5c19b5e02b7ab71549dc.tar.gz
Add GPIO get/set host command
These commands are used in factory test. If system is locked, GPIO commands are disabled for security reason. BUG=chrome-os-partner:11164 TEST= - 'ectool gpioget enable_backlight' gives 1. - 'ectool gpioset enable_backlight 0' turns off display. - Lock system. Check these commands return error. Change-Id: I3ea41285075ebe963ba7d30e4ae183cef9b1c105 Reviewed-on: https://gerrit.chromium.org/gerrit/27019 Commit-Ready: Vic Yang <victoryang@chromium.org> Reviewed-by: Vic Yang <victoryang@chromium.org> Tested-by: Vic Yang <victoryang@chromium.org>
Diffstat (limited to 'common/gpio_commands.c')
-rw-r--r--common/gpio_commands.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/common/gpio_commands.c b/common/gpio_commands.c
index 3327e9ae9c..67529dc86b 100644
--- a/common/gpio_commands.c
+++ b/common/gpio_commands.c
@@ -8,6 +8,8 @@
#include "board.h"
#include "console.h"
#include "gpio.h"
+#include "host_command.h"
+#include "system.h"
#include "util.h"
@@ -48,6 +50,8 @@ static int last_val_changed(int i, int v)
}
}
+/*****************************************************************************/
+/* Console commands */
static int command_gpio_get(int argc, char **argv)
{
@@ -118,3 +122,55 @@ DECLARE_CONSOLE_COMMAND(gpioset, command_gpio_set,
"name <0 | 1>",
"Set a GPIO",
NULL);
+
+/*****************************************************************************/
+/* Host commands */
+
+static int gpio_command_get(struct host_cmd_handler_args *args)
+{
+ struct ec_params_gpio_get *p =
+ (struct ec_params_gpio_get *)args->params;
+ struct ec_response_gpio_get *r =
+ (struct ec_response_gpio_get *)args->response;
+ int i;
+
+ if (system_is_locked())
+ return EC_RES_ACCESS_DENIED;
+
+ i = find_signal_by_name(p->name);
+ if (i == GPIO_COUNT)
+ return EC_RES_ERROR;
+
+ r->val = gpio_get_level(i);
+ args->response_size = sizeof(struct ec_response_gpio_get);
+ return EC_RES_SUCCESS;
+}
+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)
+{
+ struct ec_params_gpio_set *p =
+ (struct ec_params_gpio_set *)args->params;
+ int i;
+ const struct gpio_info *g;
+
+ if (system_is_locked())
+ return EC_RES_ACCESS_DENIED;
+
+ i = find_signal_by_name(p->name);
+ if (i == GPIO_COUNT)
+ return EC_RES_ERROR;
+ g = gpio_list + i;
+
+ if (!g->mask)
+ return EC_RES_ERROR;
+
+ if (!(g->flags & GPIO_OUTPUT))
+ return EC_RES_ERROR;
+
+ if (gpio_set_level(i, p->val) != EC_SUCCESS)
+ return EC_RES_ERROR;
+ return EC_RES_SUCCESS;
+}
+DECLARE_HOST_COMMAND(EC_CMD_GPIO_SET, gpio_command_set, EC_VER_MASK(0));