diff options
author | Pi-Hsun Shih <pihsun@chromium.org> | 2020-06-16 13:45:37 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-07-23 23:21:27 +0000 |
commit | c10bb98f5381a477540a094dcddfe1d1c5ee7ade (patch) | |
tree | 952e68c725fd53941ad41fe6182d77f6dd06425f | |
parent | 23748c2f49b52a279970e7e2f6862ba336726346 (diff) | |
download | chrome-ec-c10bb98f5381a477540a094dcddfe1d1c5ee7ade.tar.gz |
ec_commands: Add host commands for regulator control.
BUG=b:149274957
TEST=build
BRANCH=none
Change-Id: I9c7b5dec7e2f66ab64750b48acd914a1c86dfd3d
Signed-off-by: Pi-Hsun Shih <pihsun@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2247431
Reviewed-by: Jett Rink <jettrink@chromium.org>
Commit-Queue: Jett Rink <jettrink@chromium.org>
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/regulator.c | 99 | ||||
-rw-r--r-- | include/config.h | 7 | ||||
-rw-r--r-- | include/ec_commands.h | 83 | ||||
-rw-r--r-- | include/regulator.h | 55 |
5 files changed, 245 insertions, 0 deletions
diff --git a/common/build.mk b/common/build.mk index 8bb9197596..de4d9def39 100644 --- a/common/build.mk +++ b/common/build.mk @@ -79,6 +79,7 @@ common-$(CONFIG_GESTURE_SW_DETECTION)+=gesture.o common-$(CONFIG_HOSTCMD_EVENTS)+=host_event_commands.o common-$(CONFIG_HOSTCMD_GET_UPTIME_INFO)+=uptime.o common-$(CONFIG_HOSTCMD_PD)+=host_command_master.o +common-$(CONFIG_HOSTCMD_REGULATOR)+=regulator.o common-$(CONFIG_HOSTCMD_RTC)+=rtc.o common-$(CONFIG_I2C_DEBUG)+=i2c_trace.o common-$(CONFIG_I2C_HID_TOUCHPAD)+=i2c_hid_touchpad.o diff --git a/common/regulator.c b/common/regulator.c new file mode 100644 index 0000000000..c3f5d0b99d --- /dev/null +++ b/common/regulator.c @@ -0,0 +1,99 @@ +/* Copyright 2020 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. + */ + +/* Regulator control module for Chrome EC */ + +#include "common.h" +#include "console.h" +#include "ec_commands.h" +#include "host_command.h" +#include "regulator.h" + +static enum ec_status +hc_regulator_get_info(struct host_cmd_handler_args *args) +{ + const struct ec_params_regulator_get_info *p = args->params; + struct ec_response_regulator_get_info *r = args->response; + int rv; + + rv = board_regulator_get_info(p->index, r->name, &r->num_voltages, + r->voltages_mv); + + if (rv) + return EC_RES_ERROR; + + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_GET_INFO, hc_regulator_get_info, + EC_VER_MASK(0)); + +static enum ec_status +hc_regulator_enable(struct host_cmd_handler_args *args) +{ + const struct ec_params_regulator_enable *p = args->params; + int rv; + + rv = board_regulator_enable(p->index, p->enable); + + if (rv) + return EC_RES_ERROR; + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_ENABLE, hc_regulator_enable, + EC_VER_MASK(0)); + +static enum ec_status +hc_regulator_is_enabled(struct host_cmd_handler_args *args) +{ + const struct ec_params_regulator_is_enabled *p = args->params; + struct ec_response_regulator_is_enabled *r = args->response; + int rv; + + rv = board_regulator_is_enabled(p->index, &r->enabled); + + if (rv) + return EC_RES_ERROR; + + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_IS_ENABLED, hc_regulator_is_enabled, + EC_VER_MASK(0)); + +static enum ec_status +hc_regulator_get_voltage(struct host_cmd_handler_args *args) +{ + const struct ec_params_regulator_get_voltage *p = args->params; + struct ec_response_regulator_get_voltage *r = args->response; + int rv; + + rv = board_regulator_get_voltage(p->index, &r->voltage_mv); + + if (rv) + return EC_RES_ERROR; + + args->response_size = sizeof(*r); + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_GET_VOLTAGE, hc_regulator_get_voltage, + EC_VER_MASK(0)); + +static enum ec_status +hc_regulator_set_voltage(struct host_cmd_handler_args *args) +{ + const struct ec_params_regulator_set_voltage *p = args->params; + int rv; + + rv = board_regulator_set_voltage(p->index, p->min_mv, p->max_mv); + + if (rv) + return EC_RES_ERROR; + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_REGULATOR_SET_VOLTAGE, hc_regulator_set_voltage, + EC_VER_MASK(0)); diff --git a/include/config.h b/include/config.h index 61dca89f01..c94be56206 100644 --- a/include/config.h +++ b/include/config.h @@ -2096,6 +2096,13 @@ /* Command to issue AP reset */ #undef CONFIG_HOSTCMD_AP_RESET +/* + * Support voltage regulator host command + * If defined, the board should also implement board functions defined in + * include/regulator.h + */ +#undef CONFIG_HOSTCMD_REGULATOR + /* Flash commands over PD */ #define CONFIG_HOSTCMD_FLASHPD diff --git a/include/ec_commands.h b/include/ec_commands.h index d141996c41..49e861b151 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -6181,6 +6181,89 @@ struct ec_response_smart_discharge { }; /*****************************************************************************/ +/* Voltage regulator controls */ + +/* + * Get basic info of voltage regulator for given index. + * + * Returns the regulator name and supported voltage list in mV. + */ +#define EC_CMD_REGULATOR_GET_INFO 0x012C + +/* Maximum length of regulator name */ +#define EC_REGULATOR_NAME_MAX_LEN 16 + +/* Maximum length of the supported voltage list. */ +#define EC_REGULATOR_VOLTAGE_MAX_COUNT 16 + +struct ec_params_regulator_get_info { + uint32_t index; +} __ec_align4; + +struct ec_response_regulator_get_info { + char name[EC_REGULATOR_NAME_MAX_LEN]; + uint16_t num_voltages; + uint16_t voltages_mv[EC_REGULATOR_VOLTAGE_MAX_COUNT]; +} __ec_align2; + +/* + * Configure the regulator as enabled / disabled. + */ +#define EC_CMD_REGULATOR_ENABLE 0x012D + +struct ec_params_regulator_enable { + uint32_t index; + uint8_t enable; +} __ec_align4; + +/* + * Query if the regulator is enabled. + * + * Returns 1 if the regulator is enabled, 0 if not. + */ +#define EC_CMD_REGULATOR_IS_ENABLED 0x012E + +struct ec_params_regulator_is_enabled { + uint32_t index; +} __ec_align4; + +struct ec_response_regulator_is_enabled { + uint8_t enabled; +} __ec_align1; + +/* + * Set voltage for the voltage regulator within the range specified. + * + * The driver should select the voltage in range closest to min_mv. + * + * Also note that this might be called before the regulator is enabled, and the + * setting should be in effect after the regulator is enabled. + */ +#define EC_CMD_REGULATOR_SET_VOLTAGE 0x012F + +struct ec_params_regulator_set_voltage { + uint32_t index; + uint32_t min_mv; + uint32_t max_mv; +} __ec_align4; + +/* + * Get the currently configured voltage for the voltage regulator. + * + * Note that this might be called before the regulator is enabled, and this + * should return the configured output voltage if the regulator is enabled. + */ +#define EC_CMD_REGULATOR_GET_VOLTAGE 0x0130 + +struct ec_params_regulator_get_voltage { + uint32_t index; +} __ec_align4; + +struct ec_response_regulator_get_voltage { + uint32_t voltage_mv; +} __ec_align4; + +/*****************************************************************************/ /* The command range 0x200-0x2FF is reserved for Rotor. */ /*****************************************************************************/ diff --git a/include/regulator.h b/include/regulator.h new file mode 100644 index 0000000000..9dae7233c1 --- /dev/null +++ b/include/regulator.h @@ -0,0 +1,55 @@ +/* Copyright 2020 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. + */ + +#ifndef __CROS_EC_REGULATOR_H +#define __CROS_EC_REGULATOR_H + +#include "common.h" + +/* + * Board dependent hooks on voltage regulators. + * + * These functions should be implemented by boards which + * CONFIG_HOSTCMD_REGULATOR is defined. + */ + +/* + * Get basic info of voltage regulator for given index. + * + * Note that the maximum length of name is EC_REGULATOR_NAME_MAX_LEN, and the + * maximum length of the voltages_mv list is EC_REGULATOR_VOLTAGE_MAX_COUNT. + */ +int board_regulator_get_info(uint32_t index, char *name, + uint16_t *voltage_count, uint16_t *voltages_mv); + +/* + * Configure the regulator as enabled / disabled. + */ +int board_regulator_enable(uint32_t index, uint8_t enable); + +/* + * Query if the regulator is enabled. + */ +int board_regulator_is_enabled(uint32_t index, uint8_t *enabled); + +/* + * Set voltage for the voltage regulator within the range specified. + * + * The driver should select the voltage in range closest to min_mv. + * + * Also note that this might be called before the regulator is enabled, and the + * setting should be in effect after the regulator is enabled. + */ +int board_regulator_set_voltage(uint32_t index, uint32_t min_mv, + uint32_t max_mv); + +/* + * Get the currently configured voltage for the voltage regulator. + * + * Note that this might be called before the regulator is enabled. + */ +int board_regulator_get_voltage(uint32_t index, uint32_t *voltage_mv); + +#endif /* !defined(__CROS_EC_REGULATOR_H) */ |