summaryrefslogtreecommitdiff
path: root/driver
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 /driver
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>
Diffstat (limited to 'driver')
-rw-r--r--driver/battery/smart.c57
1 files changed, 57 insertions, 0 deletions
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
*/