From 98402bb466e53cbe7b0d47287823126f7de0fdb8 Mon Sep 17 00:00:00 2001 From: Vijay Hiremath Date: Wed, 9 Nov 2016 23:16:05 -0800 Subject: smart_battery: Add console command to read ManufacturerAccess() data Added console command to read ManufacturerAccess() data on a given register block. BUG=chrome-os-partner:59660 BRANCH=none TEST=Enabled config on Reef. Successfully able to read ManufacturerAccess() data Change-Id: Ic86ae1b44ca8016634c48b54b1130d30fdd2d3fa Signed-off-by: Vijay Hiremath Reviewed-on: https://chromium-review.googlesource.com/409638 Commit-Ready: Vijay P Hiremath Tested-by: Vijay P Hiremath Reviewed-by: Shawn N --- board/reef/board.h | 1 + driver/battery/smart.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ include/config.h | 1 + 3 files changed, 59 insertions(+) diff --git a/board/reef/board.h b/board/reef/board.h index a4bc9c32de..066dd79bdc 100644 --- a/board/reef/board.h +++ b/board/reef/board.h @@ -26,6 +26,7 @@ /* EC console commands */ #define CONFIG_CMD_ACCELS #define CONFIG_CMD_ACCEL_INFO +#define CONFIG_CMD_BATT_MFG_ACCESS #define CONFIG_CMD_CHARGER_ADC_AMON_BMON #define CONFIG_CHARGER_SENSE_RESISTOR 10 #define CONFIG_CHARGER_SENSE_RESISTOR_AC 10 diff --git a/driver/battery/smart.c b/driver/battery/smart.c index 15dd72ff29..81a74917a9 100644 --- a/driver/battery/smart.c +++ b/driver/battery/smart.c @@ -389,6 +389,63 @@ DECLARE_CONSOLE_COMMAND(battfake, command_battfake, "Set fake battery level"); #endif +#ifdef CONFIG_CMD_BATT_MFG_ACCESS +static int command_batt_mfg_access_read(int argc, char **argv) +{ + char *e; + uint8_t data[32]; + int cmd, block, len = 6; + int rv; + + if (argc < 3 || argc > 4) + return EC_ERROR_PARAM_COUNT; + + cmd = strtoi(argv[1], &e, 0); + if (*e || cmd < 0) + return EC_ERROR_PARAM1; + + block = strtoi(argv[2], &e, 0); + if (*e || block < 0) + return EC_ERROR_PARAM2; + + if (argc > 3) { + len = strtoi(argv[3], &e, 0); + len += 2; + if (*e || len < 1 || len > sizeof(data)) + return EC_ERROR_PARAM3; + } + + /* Send manufacturer access command */ + rv = sb_write(SB_MANUFACTURER_ACCESS, cmd); + if (rv) + return rv; + + /* + * Read data on the register block. + * First two bytes returned are command sent, + * rest are actual data LSB to MSB. + */ + rv = sb_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, + block, data, len); + if (rv) + return rv; + if (data[0] != (cmd & 0xff) || data[1] != (cmd >> 8 & 0xff)) + return EC_ERROR_UNKNOWN; + + ccprintf("data[MSB->LSB]=0x"); + do { + len--; + ccprintf("%02x ", data[len]); + } while (len > 2); + ccprintf("\n"); + + return EC_SUCCESS; +} +DECLARE_CONSOLE_COMMAND(battmfgacc, command_batt_mfg_access_read, + "cmd block | len", + "Read battery manufacture access data"); +#endif /* CONFIG_CMD_BATT_MFG_ACCESS */ + /*****************************************************************************/ /* Smart battery pass-through */ diff --git a/include/config.h b/include/config.h index 596a51b36c..f56239d303 100644 --- a/include/config.h +++ b/include/config.h @@ -585,6 +585,7 @@ #define CONFIG_CMD_APTHROTTLE #undef CONFIG_CMD_BATDEBUG #define CONFIG_CMD_BATTFAKE +#undef CONFIG_CMD_BATT_MFG_ACCESS #undef CONFIG_CMD_BUTTON #define CONFIG_CMD_CHARGER #undef CONFIG_CMD_CHARGER_ADC_AMON_BMON -- cgit v1.2.1