summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVijay Hiremath <vijay.p.hiremath@intel.com>2016-11-09 23:16:05 -0800
committerchrome-bot <chrome-bot@chromium.org>2016-11-12 23:55:08 -0800
commit98402bb466e53cbe7b0d47287823126f7de0fdb8 (patch)
treee7e5c3263a32d7413b16a53fb00524f066d16815
parent4975e8db75d0af415931e027180977df2f3a2610 (diff)
downloadchrome-ec-98402bb466e53cbe7b0d47287823126f7de0fdb8.tar.gz
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 <vijay.p.hiremath@intel.com> Reviewed-on: https://chromium-review.googlesource.com/409638 Commit-Ready: Vijay P Hiremath <vijay.p.hiremath@intel.com> Tested-by: Vijay P Hiremath <vijay.p.hiremath@intel.com> Reviewed-by: Shawn N <shawnn@chromium.org>
-rw-r--r--board/reef/board.h1
-rw-r--r--driver/battery/smart.c57
-rw-r--r--include/config.h1
3 files changed, 59 insertions, 0 deletions
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