From 63429076b3473ab261316a1136c02ab376256c20 Mon Sep 17 00:00:00 2001 From: Vincent Palatin Date: Wed, 9 Jul 2014 20:18:57 -0700 Subject: battery: fix BQ27541/BQ27741 gas gauge driver Update the code to be compatible with charge v2 expectations : never return EC_ERROR_UNIMPLEMENTED for battery information else the charge code continuously tries to read them again. Fix the State Of Charge reading : on BQ27741 the gas gauge gets confused if we do a 16-bit I2C read while a 8-bit read works perfectly. Signed-off-by: Vincent Palatin BRANCH=none BUG=none TEST=run a Ryu connected to a Kirby battery and check the output of the "battery" command. Change-Id: Ic1d6128dc02efa47662fa5ca5b9e5de62420ebe8 Reviewed-on: https://chromium-review.googlesource.com/207273 Reviewed-by: Vic Yang Tested-by: Vic Yang Commit-Queue: Vic Yang --- driver/battery/bq27541.c | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'driver/battery') diff --git a/driver/battery/bq27541.c b/driver/battery/bq27541.c index 81d0a0dc42..ee8d2cc61d 100644 --- a/driver/battery/bq27541.c +++ b/driver/battery/bq27541.c @@ -136,22 +136,30 @@ int battery_time_at_rate(int rate, int *minutes) int battery_manufacturer_name(char *dest, int size) { - return EC_ERROR_UNIMPLEMENTED; + strzcpy(dest, "", size); + + return EC_SUCCESS; } int battery_device_chemistry(char *dest, int size) { - return EC_ERROR_UNIMPLEMENTED; + strzcpy(dest, "", size); + + return EC_SUCCESS; } int battery_serial_number(int *serial) { - return EC_ERROR_UNIMPLEMENTED; + *serial = 0x0BAD0BAD; + + return EC_SUCCESS; } int battery_design_voltage(int *voltage) { - return EC_ERROR_UNIMPLEMENTED; + *voltage = battery_get_info()->voltage_normal; + + return EC_SUCCESS; } /** @@ -193,7 +201,7 @@ void battery_get_params(struct batt_params *batt) else batt->flags |= BATT_FLAG_RESPONSIVE; /* Battery is responding */ - if (bq27541_read(REG_STATE_OF_CHARGE, &batt->state_of_charge)) + if (bq27541_read8(REG_STATE_OF_CHARGE, &batt->state_of_charge)) batt->flags |= BATT_FLAG_BAD_STATE_OF_CHARGE; if (bq27541_read(REG_VOLTAGE, &batt->voltage)) @@ -219,10 +227,17 @@ void battery_get_params(struct batt_params *batt) * current. */ batt->desired_voltage = battery_get_info()->voltage_max; - batt->desired_current = 99999; + batt->desired_current = 4096; } } +/* Wait until battery is totally stable */ +int battery_wait_for_stable(void) +{ + /* TODO(crosbug.com/p/30426): implement me */ + return EC_SUCCESS; +} + #ifdef CONFIG_BATTERY_REVIVE_DISCONNECT /* * Check if battery is in disconnect state, a state entered by pulling -- cgit v1.2.1