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>
This commit is contained in:
Bill Richardson
2013-09-04 14:46:35 -07:00
committed by chrome-internal-fetch
parent b36222723b
commit 3f2eba22c5
6 changed files with 160 additions and 1 deletions

View File

@@ -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

107
common/getset.c Normal file
View File

@@ -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 */

View File

@@ -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

View File

@@ -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 */

26
include/getset.h Normal file
View File

@@ -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 */

View File

@@ -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 */