diff options
author | Bill Richardson <wfrichar@chromium.org> | 2013-09-04 14:46:35 -0700 |
---|---|---|
committer | chrome-internal-fetch <chrome-internal-fetch@google.com> | 2013-09-05 03:10:54 +0000 |
commit | 3f2eba22c5d3e771904f6451a4b63a41cc6964cb (patch) | |
tree | 04358b4424d5597f8bd1864f277729c7c2f5961b /common | |
parent | b36222723b071e003729f75c11d9c42d812abbe3 (diff) | |
download | chrome-ec-3f2eba22c5d3e771904f6451a4b63a41cc6964cb.tar.gz |
Add a generic get/set host command
This adds EC_CMD_GET_SET_VALUE to the list of host commands. We have a bunch
of single-value getter/setter commands, which is wasteful. This is a start
towards unifying them into a simpler command.
BUG=chromium:285358
BRANCH=ToT,falco
TEST=none
There's nothing to test just yet. This just adds the command and some basic
interfaces. A future commit will make use of it.
Change-Id: Iee986b9d273b422bb06f3a0c9b7af50617f03d7f
Signed-off-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/168083
Reviewed-by: Randall Spangler <rspangler@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/getset.c | 107 |
2 files changed, 108 insertions, 1 deletions
diff --git a/common/build.mk b/common/build.mk index 9d28ea307b..143a7e0576 100644 --- a/common/build.mk +++ b/common/build.mk @@ -8,7 +8,7 @@ common-y=main.o util.o console_output.o uart_buffering.o common-y+=memory_commands.o shared_mem.o system_common.o hooks.o -common-y+=gpio_common.o version.o printf.o queue.o +common-y+=gpio_common.o version.o printf.o queue.o getset.o common-$(BOARD_bolt)+=battery_link.o common-$(BOARD_daisy)+=extpower_snow.o diff --git a/common/getset.c b/common/getset.c new file mode 100644 index 0000000000..0ac5b840cd --- /dev/null +++ b/common/getset.c @@ -0,0 +1,107 @@ +/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +/* Generic get/set value stuff. */ + +#include "common.h" +#include "console.h" +#include "getset.h" +#include "host_command.h" +#include "util.h" + +/* Declare and initialize the values */ +#define GSV_ITEM(n, v) v, +#include "getset_value_list.h" +uint32_t gsv[] = { + GSV_LIST +}; +#undef GSV_ITEM + +BUILD_ASSERT(ARRAY_SIZE(gsv) == NUM_GSV_PARAMS); + +static enum ec_status get_set_value(struct ec_cmd_get_set_value *ptr) +{ + unsigned int index = ptr->flags & EC_GSV_PARAM_MASK; + if (index >= NUM_GSV_PARAMS) + return EC_RES_INVALID_PARAM; + + /* Handle flags correctly - we may add new ones some day */ + if (ptr->flags & EC_GSV_SET) + gsv[index] = ptr->value; + + ptr->value = gsv[index]; + return EC_RES_SUCCESS; +} + +static int host_command_get_set_value(struct host_cmd_handler_args *args) +{ + const struct ec_cmd_get_set_value *p = args->params; + struct ec_cmd_get_set_value *r = args->response; + args->response_size = sizeof(*r); + + if (p != r) + memcpy(r, p, sizeof(*p)); + + return get_set_value(r); +} +DECLARE_HOST_COMMAND(EC_CMD_GET_SET_VALUE, + host_command_get_set_value, + EC_VER_MASK(0)); + + +#ifdef CONFIG_CMD_GSV + +#define STRINGIFY0(name) #name +#define STRINGIFY(name) STRINGIFY0(name) +#define GSV_ITEM(n, v) STRINGIFY(n), +#include "getset_value_list.h" +static const char const *gsv_name[] = { + GSV_LIST +}; +#undef GSV_ITEM + +static int console_command_get_set_value(int argc, char **argv) +{ + unsigned int i; + struct ec_cmd_get_set_value s = {0, 0}; + char *e; + int ret; + + if (argc < 2) { + for (i = 0; i < NUM_GSV_PARAMS; i++) + ccprintf("%s = 0x%08x\n", gsv_name[i], gsv[i]); + return EC_SUCCESS; + } + + for (i = 0; i < NUM_GSV_PARAMS; i++) + if (!strcasecmp(gsv_name[i], argv[1])) + break; + + if (i >= NUM_GSV_PARAMS) { + ccprintf("Can't find param \"%s\"\n", argv[1]); + return EC_ERROR_UNKNOWN; + } + s.flags = i; + + if (argc > 2) { + s.flags |= EC_GSV_SET; + s.value = strtoi(argv[2], &e, 0); + if (*e) + return EC_ERROR_INVAL; + } + + ret = get_set_value(&s); + + if (ret == EC_RES_SUCCESS) + ccprintf("%s = 0x%08x\n", argv[1], s.value); + + return ret; +} +DECLARE_CONSOLE_COMMAND(gsv, console_command_get_set_value, + "[name [value]]", + "get/set the value of named parameters", + NULL); + +#endif /* CONFIG_CMD_GSV */ |