diff options
-rw-r--r-- | common/build.mk | 2 | ||||
-rw-r--r-- | common/getset.c | 107 | ||||
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | include/ec_commands.h | 14 | ||||
-rw-r--r-- | include/getset.h | 26 | ||||
-rw-r--r-- | include/getset_value_list.h | 11 |
6 files changed, 160 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 */ diff --git a/include/config.h b/include/config.h index 7513b6aa7b..fd01b20398 100644 --- a/include/config.h +++ b/include/config.h @@ -177,6 +177,7 @@ #undef CONFIG_CMD_COMXTEST #undef CONFIG_CMD_ECTEMP +#undef CONFIG_CMD_GSV #undef CONFIG_CMD_PLL #undef CONFIG_CMD_PMU #undef CONFIG_CMD_POWERLED diff --git a/include/ec_commands.h b/include/ec_commands.h index b3feff7ce1..0287e659ca 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -635,6 +635,20 @@ struct ec_response_get_protocol_info { uint32_t flags; } __packed; + +/* Get/Set miscellaneous values */ +#define EC_CMD_GET_SET_VALUE 0x0c + +/* The upper byte of .flags tells what to do (nothing means "get") */ +#define EC_GSV_SET 0x80000000 +/* The lower three bytes of .flags identifies the parameter */ +#define EC_GSV_PARAM_MASK 0x00ffffff +/* The same struct is sent in both directions */ +struct ec_cmd_get_set_value { + uint32_t flags; + uint32_t value; +} __packed; + /*****************************************************************************/ /* Flash commands */ diff --git a/include/getset.h b/include/getset.h new file mode 100644 index 0000000000..d1721b3e6c --- /dev/null +++ b/include/getset.h @@ -0,0 +1,26 @@ +/* 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. + */ + +/* List of valid params for the generic get/set value operation */ + +#ifndef __CROS_EC_GETSET_H +#define __CROS_EC_GETSET_H + +#include <stdint.h> +#include "ec_commands.h" + +/* Define the params. */ +#define GSV_ITEM(n, v) GSV_PARAM_##n, +#include "getset_value_list.h" +enum gsv_param_id { + GSV_LIST + NUM_GSV_PARAMS +}; +#undef GSV_ITEM + +/* Declare the storage where the values will be kept. */ +extern uint32_t gsv[]; + +#endif /* __CROS_EC_GETSET_H */ diff --git a/include/getset_value_list.h b/include/getset_value_list.h new file mode 100644 index 0000000000..99f6beefc1 --- /dev/null +++ b/include/getset_value_list.h @@ -0,0 +1,11 @@ +/* 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. + */ + +/** + * List of get/set value items: <name, init_val> + */ +#define GSV_LIST \ + GSV_ITEM(s5, 0xdeadbeef) \ + /* end */ |