summaryrefslogtreecommitdiff
path: root/driver/battery
diff options
context:
space:
mode:
authorPaul Fagerburg <pfagerburg@chromium.org>2019-11-11 14:36:56 -0700
committerCommit Bot <commit-bot@chromium.org>2019-11-12 02:32:21 +0000
commite10f5bf1eeb83f6b8e146f5b28c7cbe9fae46c5e (patch)
tree54b8f75229f88b63375c67568633de0f52281a9c /driver/battery
parentddca51c3ede9dce5af08d13cf69e86402f5ee997 (diff)
downloadchrome-ec-e10f5bf1eeb83f6b8e146f5b28c7cbe9fae46c5e.tar.gz
driver/battery: add command to fake battery temperature
The 'batttempfake' command allows overriding the battery temperature reading, to test scenarios where the battery temperature affects the charging operations. BUG=None BRANCH=None TEST=Set GBB flags to disable software sync and disable rollback checks $ make -j BOARD=kohaku $ ./util/flash_ec --board=kohaku When the system reboots, open the EC console and execute the commands: > help batttempfake Usage: batttempfake temperature (-1 = use real temperature) Set fake battery temperature in deciKelvin (2731 = 273.1 K = 0 deg C) > batttempfake 2731 Fake batt temperature 273.1 K > battery ... Temp: 0x0aab = 273.1 K (0.0 C) ... > batttempfake -1 > battery ... Temp: 0x0bc9 = 301.7 K (28.6 C) ... Change-Id: I4c1fff13f3fec34e9e20d0016f66bd5c693e1537 Signed-off-by: Paul Fagerburg <pfagerburg@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1910582 Reviewed-by: Justin TerAvest <teravest@chromium.org>
Diffstat (limited to 'driver/battery')
-rw-r--r--driver/battery/smart.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/driver/battery/smart.c b/driver/battery/smart.c
index 89a99623af..69a90e72f6 100644
--- a/driver/battery/smart.c
+++ b/driver/battery/smart.c
@@ -20,6 +20,7 @@
#define BATTERY_NO_RESPONSE_TIMEOUT (1000*MSEC)
static int fake_state_of_charge = -1;
+static int fake_temperature = -1;
test_mockable int sb_read(int cmd, int *param)
{
@@ -311,9 +312,14 @@ void battery_get_params(struct batt_params *batt)
struct batt_params batt_new = {0};
int v;
- if (sb_read(SB_TEMPERATURE, &batt_new.temperature))
+ if (sb_read(SB_TEMPERATURE, &batt_new.temperature)
+ && fake_temperature < 0)
batt_new.flags |= BATT_FLAG_BAD_TEMPERATURE;
+ /* If temperature is faked, override with faked data */
+ if (fake_temperature >= 0)
+ batt_new.temperature = fake_temperature;
+
if (sb_read(SB_RELATIVE_STATE_OF_CHARGE, &batt_new.state_of_charge)
&& fake_state_of_charge < 0)
batt_new.flags |= BATT_FLAG_BAD_STATE_OF_CHARGE;
@@ -448,6 +454,29 @@ static int command_battfake(int argc, char **argv)
DECLARE_CONSOLE_COMMAND(battfake, command_battfake,
"percent (-1 = use real level)",
"Set fake battery level");
+
+static int command_batttempfake(int argc, char **argv)
+{
+ char *e;
+ int t;
+
+ if (argc == 2) {
+ t = strtoi(argv[1], &e, 0);
+ if (*e || t < -1 || t > 5000)
+ return EC_ERROR_PARAM1;
+
+ fake_temperature = t;
+ }
+
+ if (fake_temperature >= 0)
+ ccprintf("Fake batt temperature %d.%d K\n",
+ fake_temperature / 10, fake_temperature % 10);
+
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(batttempfake, command_batttempfake,
+ "temperature (-1 = use real temperature)",
+ "Set fake battery temperature in deciKelvin (2731 = 273.1 K = 0 deg C)");
#endif
#ifdef CONFIG_CMD_BATT_MFG_ACCESS