diff options
author | Vincent Palatin <vpalatin@chromium.org> | 2013-01-15 09:42:31 -0800 |
---|---|---|
committer | ChromeBot <chrome-bot@google.com> | 2013-01-19 10:59:20 -0800 |
commit | c8a61c39ef25411e9ac28cbf3e42954a19aca7a3 (patch) | |
tree | fdec4c65a5b8ca28b83f5ccd060093b27a32c42e | |
parent | f0cd8251cc72ae20bd46c103a9f91678c0d030f4 (diff) | |
download | chrome-ec-c8a61c39ef25411e9ac28cbf3e42954a19aca7a3.tar.gz |
Add a pass-through for the smart battery
Allow to send commands to the smart battery using EC commands when the
battery is connected to an I2C bus behind the EC.
Signed-off-by: Vincent Palatin <vpalatin@chromium.org>
BRANCH=none
BUG=chrome-os-partner:14314
TEST=on Spring, with a kernel including patch to use the pass-through
for the sbs-battery driver, run "power-supply-info" and see the correct
information.
Change-Id: Ie10f1c95afe4a33cf0b55d5a0de7640d5971ebb3
Reviewed-on: https://gerrit.chromium.org/gerrit/41289
Reviewed-by: Vic Yang <victoryang@chromium.org>
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
-rw-r--r-- | common/smart_battery.c | 77 | ||||
-rw-r--r-- | include/ec_commands.h | 35 |
2 files changed, 112 insertions, 0 deletions
diff --git a/common/smart_battery.c b/common/smart_battery.c index 0438d6309f..2c4eb32f1f 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -6,6 +6,7 @@ */ #include "console.h" +#include "host_command.h" #include "smart_battery.h" #include "timer.h" #include "util.h" @@ -278,3 +279,79 @@ DECLARE_CONSOLE_COMMAND(sb, command_sb, "Read/write smart battery data", NULL); +/*****************************************************************************/ +/* Smart battery pass-through + */ +#ifdef CONFIG_I2C_PASSTHROUGH +static int host_command_sb_read_word(struct host_cmd_handler_args *args) +{ + int rv; + int val; + const struct ec_params_sb_rd *p = args->params; + struct ec_response_sb_rd_word *r = args->response; + + if (p->reg > 0x1c) + return EC_RES_INVALID_PARAM; + rv = i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, p->reg, &val); + if (rv) + return EC_RES_ERROR; + + r->value = val; + args->response_size = sizeof(struct ec_response_sb_rd_word); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_SB_READ_WORD, + host_command_sb_read_word, + EC_VER_MASK(0)); + +static int host_command_sb_write_word(struct host_cmd_handler_args *args) +{ + int rv; + const struct ec_params_sb_wr_word *p = args->params; + + if (p->reg > 0x1c) + return EC_RES_INVALID_PARAM; + rv = i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, p->reg, p->value); + if (rv) + return EC_RES_ERROR; + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_SB_WRITE_WORD, + host_command_sb_write_word, + EC_VER_MASK(0)); + +static int host_command_sb_read_block(struct host_cmd_handler_args *args) +{ + int rv; + const struct ec_params_sb_rd *p = args->params; + struct ec_response_sb_rd_block *r = args->response; + + if ((p->reg != SB_MANUFACTURER_NAME) && + (p->reg != SB_DEVICE_NAME) && + (p->reg != SB_DEVICE_CHEMISTRY) && + (p->reg != SB_MANUFACTURER_DATA)) + return EC_RES_INVALID_PARAM; + rv = i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, p->reg, + r->data, 32); + if (rv) + return EC_RES_ERROR; + + args->response_size = sizeof(struct ec_response_sb_rd_block); + + return EC_RES_SUCCESS; +} +DECLARE_HOST_COMMAND(EC_CMD_SB_READ_BLOCK, + host_command_sb_read_block, + EC_VER_MASK(0)); + +static int host_command_sb_write_block(struct host_cmd_handler_args *args) +{ + /* Not implemented */ + return EC_RES_INVALID_COMMAND; +} +DECLARE_HOST_COMMAND(EC_CMD_SB_WRITE_BLOCK, + host_command_sb_write_block, + EC_VER_MASK(0)); +#endif diff --git a/include/ec_commands.h b/include/ec_commands.h index 02fa46f1bf..54dcbd314a 100644 --- a/include/ec_commands.h +++ b/include/ec_commands.h @@ -1261,6 +1261,41 @@ struct ec_params_current_limit { } __packed; /*****************************************************************************/ +/* Smart battery pass-through */ + +/* Get / Set 16-bit smart battery registers */ +#define EC_CMD_SB_READ_WORD 0xb0 +#define EC_CMD_SB_WRITE_WORD 0xb1 + +/* Get / Set string smart battery parameters + * formatted as SMBUS "block". + */ +#define EC_CMD_SB_READ_BLOCK 0xb2 +#define EC_CMD_SB_WRITE_BLOCK 0xb3 + +struct ec_params_sb_rd { + uint8_t reg; +} __packed; + +struct ec_response_sb_rd_word { + uint16_t value; +} __packed; + +struct ec_params_sb_wr_word { + uint8_t reg; + uint16_t value; +} __packed; + +struct ec_response_sb_rd_block { + uint8_t data[32]; +} __packed; + +struct ec_params_sb_wr_block { + uint8_t reg; + uint16_t data[32]; +} __packed; + +/*****************************************************************************/ /* System commands */ /* |