summaryrefslogtreecommitdiff
path: root/driver
diff options
context:
space:
mode:
authorRong Chang <rongchang@chromium.org>2015-07-07 16:33:26 +0800
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-08-25 13:11:19 +0000
commitf3a5046ed7eac6081680b85fa45b7767c421bd19 (patch)
tree2455faa5093f1e571f5c2cf3d58c75f487a6644d /driver
parent1155520c8a07ef9f9f5066223cb4c0c34e2bf031 (diff)
downloadchrome-ec-f3a5046ed7eac6081680b85fa45b7767c421bd19.tar.gz
glados: oak: Add charger AMONBMON console command
AMONBMON is a charger feature to measure input current and battery output current. ISL9237 output analog value of voltage diff across sense resistor to EC's ADC channel. This change also reorders oak's ADC channel to fix a reading bug. BRANCH=none BUG=chrome-os-partner:42270 TEST=manual in EC serial console, type command 'adc' and check AMON_BMON value. type command 'amonbmon' and check AC current and BAT current. Change-Id: I9db0a72be7c9a428a16d1609eb8c461c6928e548 Signed-off-by: Rong Chang <rongchang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/283665 Reviewed-by: Shawn N <shawnn@chromium.org>
Diffstat (limited to 'driver')
-rw-r--r--driver/charger/isl9237.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/driver/charger/isl9237.c b/driver/charger/isl9237.c
index 29257f85f7..39070bf766 100644
--- a/driver/charger/isl9237.c
+++ b/driver/charger/isl9237.c
@@ -5,6 +5,7 @@
* Intersil ISL9237 battery charger driver.
*/
+#include "adc.h"
#include "battery.h"
#include "battery_smart.h"
#include "charger.h"
@@ -23,6 +24,9 @@
#define AC_REG_TO_CURRENT(REG) ((REG) * DEFAULT_R_AC / R_AC)
#define AC_CURRENT_TO_REG(CUR) ((CUR) * R_AC / DEFAULT_R_AC)
+/* Console output macros */
+#define CPRINTF(format, args...) cprintf(CC_CHARGER, format, ## args)
+
/* Charger parameters */
static const struct charger_info isl9237_charger_info = {
.name = CHARGER_NAME,
@@ -231,3 +235,51 @@ int charger_discharge_on_ac(int enable)
return raw_write16(ISL9237_REG_CONTROL1, control1);
}
+#ifdef CONFIG_CHARGER_ADC_AMON_BMON
+/**
+ * Get charger AMON and BMON current.
+ */
+static int console_command_amon_bmon(int argc, char **argv)
+{
+ int adc, curr, val, ret;
+
+ ret = i2c_read16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ ISL9237_REG_CONTROL1, &val);
+ if (ret)
+ return ret;
+
+ /* Enable monitor */
+ val &= ~ISL9237_C1_DISABLE_MON;
+ if (argc == 1 || (argc >= 2 && argv[1][0] == 'a')) {
+ /* Switch to AMON */
+ val &= ~ISL9237_C1_SELECT_BMON;
+ ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ ISL9237_REG_CONTROL1, val);
+ if (ret)
+ return ret;
+
+ adc = adc_read_channel(ADC_AMON_BMON);
+ curr = adc / CONFIG_CHARGER_SENSE_RESISTOR_AC;
+ CPRINTF("AMON: %d uV, %d mA\n", adc, curr);
+ }
+
+ if (argc == 1 || (argc >= 2 && argv[1][0] == 'b')) {
+ /* Switch to BMON */
+ val |= ISL9237_C1_SELECT_BMON;
+ ret = i2c_write16(I2C_PORT_CHARGER, I2C_ADDR_CHARGER,
+ ISL9237_REG_CONTROL1, val);
+ if (ret)
+ return ret;
+
+ adc = adc_read_channel(ADC_AMON_BMON);
+ curr = adc / CONFIG_CHARGER_SENSE_RESISTOR;
+ CPRINTF("BMON: %d uV, %d mA\n", adc, curr);
+ }
+
+ return ret;
+}
+DECLARE_CONSOLE_COMMAND(amonbmon, console_command_amon_bmon,
+ "amonbmon [a|b]",
+ "Get charger AMON/BMON voltage diff, current",
+ NULL);
+#endif /* CONFIG_CHARGER_ADC_AMON_BMON */