diff options
38 files changed, 328 insertions, 244 deletions
diff --git a/board/daisy/board.c b/board/daisy/board.c index 24f4580143..be42ffcbd8 100644 --- a/board/daisy/board.c +++ b/board/daisy/board.c @@ -4,7 +4,7 @@ */ /* Daisy board-specific configuration */ -#include "battery_pack.h" +#include "battery.h" #include "common.h" #include "gaia_power.h" #include "gpio.h" diff --git a/board/falco/battery.c b/board/falco/battery.c index 554e3cf7c2..9acac12c7b 100644 --- a/board/falco/battery.c +++ b/board/falco/battery.c @@ -5,9 +5,9 @@ * Battery pack vendor provided charging profile */ -#include "battery_pack.h" +#include "battery.h" +#include "battery_smart.h" #include "host_command.h" -#include "smart_battery.h" #define SB_SHIP_MODE_DATA 0x0010 diff --git a/board/host/smart_battery.c b/board/host/battery.c index 3465f83431..02fc263fc1 100644 --- a/board/host/smart_battery.c +++ b/board/host/battery.c @@ -5,12 +5,11 @@ * Smart battery driver. */ -#include "battery_pack.h" +#include "battery.h" +#include "battery_smart.h" #include "common.h" #include "console.h" -#include "smart_battery.h" #include "test_util.h" -#include "uart.h" #include "util.h" static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1]; diff --git a/board/host/build.mk b/board/host/build.mk index 42cd2f61b9..21e5383d86 100644 --- a/board/host/build.mk +++ b/board/host/build.mk @@ -10,4 +10,4 @@ CHIP:=host board-y=board.o board-$(HAS_TASK_CHIPSET)+=chipset.o -board-$(CONFIG_BATTERY_MOCK)+=smart_battery.o charger.o +board-$(CONFIG_BATTERY_MOCK)+=battery.o charger.o diff --git a/board/host/charger.c b/board/host/charger.c index f63eebbea3..d5396c7418 100644 --- a/board/host/charger.c +++ b/board/host/charger.c @@ -5,11 +5,10 @@ * Mock battery charger driver. */ +#include "battery_smart.h" #include "charger.h" #include "console.h" #include "common.h" -#include "smart_battery.h" -#include "uart.h" #include "util.h" static const struct charger_info mock_charger_info = { @@ -74,7 +73,7 @@ int charger_set_current(int current) current = info->current_max; if (mock_current != current) - uart_printf("Charger set current: %d\n", current); + ccprintf("Charger set current: %d\n", current); mock_current = current; return EC_SUCCESS; } @@ -89,7 +88,7 @@ int charger_get_voltage(int *voltage) int charger_set_voltage(int voltage) { mock_voltage = voltage; - uart_printf("Charger set voltage: %d\n", voltage); + ccprintf("Charger set voltage: %d\n", voltage); return EC_SUCCESS; } diff --git a/board/kirby/battery.c b/board/kirby/battery.c index a149ba7aed..e57ac9b996 100644 --- a/board/kirby/battery.c +++ b/board/kirby/battery.c @@ -5,7 +5,7 @@ * Battery pack info for Kirby */ -#include "battery_pack.h" +#include "battery.h" /* Battery temperature ranges in degrees C */ const struct battery_temperature_ranges bat_temp_ranges = { diff --git a/board/peppy/battery.c b/board/peppy/battery.c index 59a7580bfc..2fd90823fb 100644 --- a/board/peppy/battery.c +++ b/board/peppy/battery.c @@ -5,10 +5,10 @@ * Battery pack vendor provided charging profile */ -#include "battery_pack.h" +#include "battery.h" +#include "battery_smart.h" #include "gpio.h" #include "host_command.h" -#include "smart_battery.h" #define SB_SHIP_MODE_ADDR 0x3a #define SB_SHIP_MODE_DATA 0xc574 diff --git a/board/pit/board.c b/board/pit/board.c index af7d12715f..9f4ca08a1e 100644 --- a/board/pit/board.c +++ b/board/pit/board.c @@ -4,7 +4,7 @@ */ /* Pit board-specific configuration */ -#include "battery_pack.h" +#include "battery.h" #include "common.h" #include "extpower.h" #include "gaia_power.h" diff --git a/board/puppy/board.c b/board/puppy/board.c index 8be5a970a6..f874ed2ad5 100644 --- a/board/puppy/board.c +++ b/board/puppy/board.c @@ -4,7 +4,7 @@ */ /* Puppy board-specific configuration */ -#include "battery_pack.h" +#include "battery.h" #include "common.h" #include "extpower.h" #include "gaia_power.h" diff --git a/board/slippy/battery.c b/board/slippy/battery.c index 75a179f291..27bb494343 100644 --- a/board/slippy/battery.c +++ b/board/slippy/battery.c @@ -5,7 +5,7 @@ * Battery pack vendor provided charging profile */ -#include "battery_pack.h" +#include "battery.h" #include "gpio.h" /* FIXME: We need REAL values for all this stuff */ diff --git a/board/snow/board.c b/board/snow/board.c index 4369956924..4120356175 100644 --- a/board/snow/board.c +++ b/board/snow/board.c @@ -4,7 +4,7 @@ */ /* Snow board-specific configuration */ -#include "battery_pack.h" +#include "battery.h" #include "board_config.h" #include "chipset.h" #include "common.h" diff --git a/board/spring/battery.c b/board/spring/battery.c index 4604671b8e..c5a9393b01 100644 --- a/board/spring/battery.c +++ b/board/spring/battery.c @@ -5,14 +5,25 @@ * Smart battery driver for Spring. */ +#include "battery.h" +#include "battery_smart.h" #include "host_command.h" #include "i2c.h" -#include "smart_battery.h" #include "util.h" #define PARAM_CUT_OFF_LOW 0x10 #define PARAM_CUT_OFF_HIGH 0x00 +/* Battery temperature ranges in degrees C */ +const struct battery_temperature_ranges bat_temp_ranges = { + .start_charging_min_c = 5, + .start_charging_max_c = 45, + .charging_min_c = 5, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 100, +}; + int battery_command_cut_off(struct host_cmd_handler_args *args) { int rv; diff --git a/board/spring/board.c b/board/spring/board.c index 58cb4ed9bd..fd9acaf6d5 100644 --- a/board/spring/board.c +++ b/board/spring/board.c @@ -5,7 +5,6 @@ /* Spring board-specific configuration */ #include "adc.h" -#include "battery_pack.h" #include "board_config.h" #include "chipset.h" #include "common.h" @@ -106,16 +105,6 @@ const struct gpio_alt_func gpio_alt_funcs[] = { }; const int gpio_alt_funcs_count = ARRAY_SIZE(gpio_alt_funcs); -/* Battery temperature ranges in degrees C */ -const struct battery_temperature_ranges bat_temp_ranges = { - .start_charging_min_c = 5, - .start_charging_max_c = 45, - .charging_min_c = 5, - .charging_max_c = 60, - .discharging_min_c = 0, - .discharging_max_c = 100, -}; - /* ADC channels */ const struct adc_t adc_channels[] = { /* diff --git a/board/spring/led.c b/board/spring/led.c index 3d6e316426..a793afda33 100644 --- a/board/spring/led.c +++ b/board/spring/led.c @@ -5,14 +5,13 @@ * Battery LED state machine to drive RGB LED on LP5562 */ +#include "battery.h" #include "common.h" -#include "ec_commands.h" #include "extpower.h" #include "hooks.h" #include "host_command.h" #include "lp5562.h" #include "pmu_tpschrome.h" -#include "smart_battery.h" #include "timer.h" #include "util.h" diff --git a/common/battery_bq20z453.c b/common/battery_bq20z453.c index bcfeb2536f..cda3a7cbdb 100644 --- a/common/battery_bq20z453.c +++ b/common/battery_bq20z453.c @@ -5,9 +5,8 @@ * Smart battery driver for BQ20Z453. */ +#include "battery_smart.h" #include "host_command.h" -#include "smart_battery.h" -#include "timer.h" #define PARAM_CUT_OFF 0x0010 diff --git a/common/battery_bq27541.c b/common/battery_bq27541.c index f733e8b893..3dce19ea54 100644 --- a/common/battery_bq27541.c +++ b/common/battery_bq27541.c @@ -159,12 +159,12 @@ int battery_time_at_rate(int rate, int *minutes) return bq27541_read(REG_AT_RATE_TIME_TO_EMPTY, minutes); } -int battery_manufacturer_name(char *name, int buf_size) +int battery_manufacturer_name(char *dest, int size) { return EC_ERROR_UNIMPLEMENTED; } -int battery_device_chemistry(char *chemistry, int buf_size) +int battery_device_chemistry(char *dest, int size) { return EC_ERROR_UNIMPLEMENTED; } @@ -200,7 +200,7 @@ int battery_desired_current(int *current) return EC_ERROR_UNIMPLEMENTED; } -int battery_get_battery_mode(int *mode) +int battery_get_mode(int *mode) { return EC_ERROR_UNIMPLEMENTED; } diff --git a/common/battery.c b/common/battery_common.c index 0c25486101..25c4bcf1f9 100644 --- a/common/battery.c +++ b/common/battery_common.c @@ -86,7 +86,7 @@ static int print_battery_info(void) ccprintf("0x%04x = %d mA\n", value, value); print_item_name("Mode:"); - if (check_print_error(battery_get_battery_mode(&value))) + if (check_print_error(battery_get_mode(&value))) ccprintf("0x%04x\n", value); battery_is_in_10mw_mode(&value); diff --git a/common/battery_link.c b/common/battery_link.c index 4e7e9c769b..a7877529a8 100644 --- a/common/battery_link.c +++ b/common/battery_link.c @@ -5,7 +5,7 @@ * Battery pack vendor provided charging profile */ -#include "battery_pack.h" +#include "battery.h" /* * Design capacity diff --git a/common/smart_battery.c b/common/battery_smart.c index 609c3acd2e..29af6286ad 100644 --- a/common/smart_battery.c +++ b/common/battery_smart.c @@ -5,8 +5,10 @@ * Smart battery driver. */ +#include "battery.h" +#include "battery_smart.h" #include "host_command.h" -#include "smart_battery.h" +#include "i2c.h" #include "timer.h" test_mockable int sbc_read(int cmd, int *param) @@ -29,13 +31,12 @@ int sb_write(int cmd, int param) return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); } -/* Get/set battery mode */ -int battery_get_battery_mode(int *mode) +int battery_get_mode(int *mode) { return sb_read(SB_BATTERY_MODE, mode); } -int battery_set_battery_mode(int mode) +int battery_set_mode(int mode) { return sb_write(SB_BATTERY_MODE, mode); } @@ -43,7 +44,7 @@ int battery_set_battery_mode(int mode) int battery_is_in_10mw_mode(int *ret) { int val; - int rv = battery_get_battery_mode(&val); + int rv = battery_get_mode(&val); if (rv) return rv; *ret = val & MODE_CAPACITY; @@ -53,59 +54,46 @@ int battery_is_in_10mw_mode(int *ret) int battery_set_10mw_mode(int enabled) { int val, rv; - rv = battery_get_battery_mode(&val); + rv = battery_get_mode(&val); if (rv) return rv; if (enabled) val |= MODE_CAPACITY; else val &= ~MODE_CAPACITY; - return battery_set_battery_mode(val); + return battery_set_mode(val); } -/* Read battery temperature - * unit: 0.1 K - */ int battery_temperature(int *deci_kelvin) { return sb_read(SB_TEMPERATURE, deci_kelvin); } -/* Read battery voltage - * unit: mV - */ int battery_voltage(int *voltage) { return sb_read(SB_VOLTAGE, voltage); } -/* Relative state of charge in percent */ int battery_state_of_charge(int *percent) { return sb_read(SB_RELATIVE_STATE_OF_CHARGE, percent); } -/* Absolute state of charge in percent */ int battery_state_of_charge_abs(int *percent) { return sb_read(SB_ABSOLUTE_STATE_OF_CHARGE, percent); } -/* Battery remaining capacity - * unit: mAh or 10mW, depends on battery mode - */ int battery_remaining_capacity(int *capacity) { return sb_read(SB_REMAINING_CAPACITY, capacity); } -/* Battery full charge capacity */ int battery_full_charge_capacity(int *capacity) { return sb_read(SB_FULL_CHARGE_CAPACITY, capacity); } -/* Time in minutes left when discharging */ int battery_time_to_empty(int *minutes) { return sb_read(SB_AVERAGE_TIME_TO_EMPTY, minutes); @@ -116,33 +104,29 @@ int battery_run_time_to_empty(int *minutes) return sb_read(SB_RUN_TIME_TO_EMPTY, minutes); } -/* Time in minutes to full when charging */ int battery_time_to_full(int *minutes) { return sb_read(SB_AVERAGE_TIME_TO_FULL, minutes); } -/* The current battery desired to charge - * unit: mA - */ int battery_desired_current(int *current) { return sb_read(SB_CHARGING_CURRENT, current); } -/* The voltage battery desired to charge - * unit: mV - */ int battery_desired_voltage(int *voltage) { return sb_read(SB_CHARGING_VOLTAGE, voltage); } -/* Check if battery allows charging */ int battery_charging_allowed(int *allowed) { int v, c, rv; + /* + * TODO(rspangler): This re-reads the battery current and voltage, + * which is silly because charge_state.c just read them. + */ rv = battery_desired_voltage(&v) | battery_desired_current(&c); if (rv) return rv; @@ -213,11 +197,6 @@ int battery_average_current(int *current) return EC_SUCCESS; } -/* Calculate battery time in minutes, under a charging rate - * rate > 0: charging, negative time to full - * rate < 0: discharging, positive time to empty - * rate == 0: invalid input, time = 0 - */ test_mockable int battery_time_at_rate(int rate, int *minutes) { int rv; @@ -259,8 +238,7 @@ test_mockable int battery_time_at_rate(int rate, int *minutes) return EC_ERROR_TIMEOUT; } -/* Read manufacturer date */ -test_mockable int battery_manufacturer_date(int *year, int *month, int *day) +test_mockable int battery_manufacture_date(int *year, int *month, int *day) { int rv; int ymd; @@ -280,24 +258,24 @@ test_mockable int battery_manufacturer_date(int *year, int *month, int *day) } /* Read manufacturer name */ -test_mockable int battery_manufacturer_name(char *name, int buf_size) +test_mockable int battery_manufacturer_name(char *dest, int size) { return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, - SB_MANUFACTURER_NAME, name, buf_size); + SB_MANUFACTURER_NAME, dest, size); } /* Read device name */ -test_mockable int battery_device_name(char *device_name, int buf_size) +test_mockable int battery_device_name(char *dest, int size) { return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, - SB_DEVICE_NAME, device_name, buf_size); + SB_DEVICE_NAME, dest, size); } /* Read battery type/chemistry */ -test_mockable int battery_device_chemistry(char *device_chemistry, int buf_size) +test_mockable int battery_device_chemistry(char *dest, int size) { return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, - SB_DEVICE_CHEMISTRY, device_chemistry, buf_size); + SB_DEVICE_CHEMISTRY, dest, size); } /*****************************************************************************/ diff --git a/common/build.mk b/common/build.mk index 7452ffec8a..d4151e0245 100644 --- a/common/build.mk +++ b/common/build.mk @@ -16,9 +16,9 @@ common-$(BOARD_snow)+=extpower_snow.o common-$(CONFIG_BACKLIGHT_LID)+=backlight_lid.o common-$(CONFIG_BATTERY_BQ20Z453)+=battery_bq20z453.o -common-$(CONFIG_BATTERY_BQ27541)+=battery.o battery_bq27541.o +common-$(CONFIG_BATTERY_BQ27541)+=battery_common.o battery_bq27541.o common-$(CONFIG_BATTERY_LINK)+=battery_link.o -common-$(CONFIG_BATTERY_SMART)+=battery.o smart_battery.o +common-$(CONFIG_BATTERY_SMART)+=battery_common.o battery_smart.o common-$(CONFIG_CHARGER)+=charge_state.o charger_common.o common-$(CONFIG_CHARGER_BQ24192)+=charger_bq24192.o common-$(CONFIG_CHARGER_BQ24715)+=charger_bq24715.o diff --git a/common/charge_state.c b/common/charge_state.c index e959c8cc57..8b7f0e9919 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -6,8 +6,6 @@ */ #include "battery.h" -#include "battery_pack.h" -#include "board.h" #include "charge_state.h" #include "charger.h" #include "chipset.h" @@ -18,7 +16,6 @@ #include "hooks.h" #include "host_command.h" #include "printf.h" -#include "smart_battery.h" #include "system.h" #include "task.h" #include "timer.h" diff --git a/common/charger_bq24707a.c b/common/charger_bq24707a.c index e6afa629da..43bd32eb91 100644 --- a/common/charger_bq24707a.c +++ b/common/charger_bq24707a.c @@ -5,14 +5,12 @@ * TI bq24707A battery charger driver. */ +#include "battery_smart.h" #include "charger.h" #include "charger_bq24707a.h" #include "console.h" #include "common.h" -#include "i2c.h" -#include "smart_battery.h" #include "util.h" -#include "printf.h" /* Sense resistor configurations and macros */ #define DEFAULT_SENSE_RESISTOR 10 diff --git a/common/charger_bq24715.c b/common/charger_bq24715.c index 7ee2ebf70e..d90b35b021 100644 --- a/common/charger_bq24715.c +++ b/common/charger_bq24715.c @@ -5,11 +5,11 @@ * TI bq24715 battery charger driver. */ +#include "battery_smart.h" #include "charger.h" #include "charger_bq24715.h" #include "console.h" #include "common.h" -#include "smart_battery.h" #include "util.h" /* Sense resistor configurations and macros */ diff --git a/common/charger_bq24725.c b/common/charger_bq24725.c index 64eb81400b..3e418c7216 100644 --- a/common/charger_bq24725.c +++ b/common/charger_bq24725.c @@ -5,12 +5,11 @@ * TI bq24725 battery charger driver. */ +#include "battery_smart.h" #include "charger.h" #include "charger_bq24725.h" #include "console.h" #include "common.h" -#include "i2c.h" -#include "smart_battery.h" #include "util.h" /* Sense resistor configurations and macros */ diff --git a/common/charger_bq24738.c b/common/charger_bq24738.c index cb5047b5b5..057e71c12f 100644 --- a/common/charger_bq24738.c +++ b/common/charger_bq24738.c @@ -5,12 +5,11 @@ * TI bq24738 battery charger driver. */ +#include "battery_smart.h" #include "charger.h" #include "charger_bq24738.h" #include "console.h" #include "common.h" -#include "i2c.h" -#include "smart_battery.h" #include "util.h" /* Sense resistor configurations and macros */ diff --git a/common/charger_common.c b/common/charger_common.c index 4d025f532c..15bdf8f73c 100644 --- a/common/charger_common.c +++ b/common/charger_common.c @@ -10,7 +10,6 @@ #include "console.h" #include "host_command.h" #include "printf.h" -#include "smart_battery.h" #include "util.h" /* Console output macros */ diff --git a/common/extpower_falco.c b/common/extpower_falco.c index bc308b6408..e1db0fecb7 100644 --- a/common/extpower_falco.c +++ b/common/extpower_falco.c @@ -15,6 +15,7 @@ #include <limits.h> /* part of the compiler */ #include "adc.h" +#include "battery_smart.h" #include "charge_state.h" #include "charger.h" #include "charger_bq24738.h" @@ -25,7 +26,6 @@ #include "extpower_falco.h" #include "hooks.h" #include "host_command.h" -#include "smart_battery.h" #include "throttle_ap.h" #include "util.h" diff --git a/common/extpower_spring.c b/common/extpower_spring.c index 28db352327..2e14d82e13 100644 --- a/common/extpower_spring.c +++ b/common/extpower_spring.c @@ -6,6 +6,7 @@ /* USB charging control for spring board */ #include "adc.h" +#include "battery.h" #include "chipset.h" #include "clock.h" #include "console.h" @@ -17,7 +18,6 @@ #include "pmu_tpschrome.h" #include "pwm.h" #include "registers.h" -#include "smart_battery.h" #include "stm32_adc.h" #include "system.h" #include "task.h" diff --git a/common/lightbar.c b/common/lightbar.c index e90cc06497..420435270f 100644 --- a/common/lightbar.c +++ b/common/lightbar.c @@ -6,7 +6,6 @@ */ #include "battery.h" -#include "battery_pack.h" #include "charge_state.h" #include "common.h" #include "console.h" diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index 9611a95a20..6afb72d988 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -5,7 +5,8 @@ * TI TPS65090 PMU charging task. */ -#include "battery_pack.h" +#include "battery.h" +#include "battery_smart.h" #include "clock.h" #include "chipset.h" #include "common.h" @@ -14,7 +15,6 @@ #include "hooks.h" #include "gpio.h" #include "pmu_tpschrome.h" -#include "smart_battery.h" #include "system.h" #include "task.h" #include "timer.h" diff --git a/common/pmu_tps65090_powerinfo.c b/common/pmu_tps65090_powerinfo.c index ec3c62ef54..e840feba77 100644 --- a/common/pmu_tps65090_powerinfo.c +++ b/common/pmu_tps65090_powerinfo.c @@ -5,11 +5,11 @@ * TPSChrome powerinfo commands. */ +#include "battery.h" #include "console.h" #include "extpower.h" #include "host_command.h" #include "pmu_tpschrome.h" -#include "smart_battery.h" #include "util.h" /* FIXME: move all the constants to pmu_tpschrome, make diff --git a/include/battery.h b/include/battery.h index c5177d6cae..10d0b6dcd0 100644 --- a/include/battery.h +++ b/include/battery.h @@ -8,6 +8,8 @@ #ifndef __CROS_EC_BATTERY_H #define __CROS_EC_BATTERY_H +#include "common.h" + /* Stop charge when charging and battery level >= this percentage */ #define BATTERY_LEVEL_FULL 100 @@ -31,110 +33,296 @@ */ #define BATTERY_LEVEL_SHUTDOWN 3 +/* Battery parameters */ +struct batt_params { + int temperature; /* Temperature in 0.1 K */ + int state_of_charge; /* State of charge (percent, 0-100) */ + int voltage; /* Battery voltage (mV) */ + int current; /* Battery current (mA) */ + int desired_voltage; /* Charging voltage desired by battery (mV) */ + int desired_current; /* Charging current desired by battery (mA) */ +}; + +/* Working temperature ranges in degrees C */ +struct battery_temperature_ranges { + int8_t start_charging_min_c; + int8_t start_charging_max_c; + int8_t charging_min_c; + int8_t charging_max_c; + int8_t discharging_min_c; + int8_t discharging_max_c; +}; +extern const struct battery_temperature_ranges bat_temp_ranges; + +/* Battery constants */ +struct battery_info { + /* Design voltage in mV */ + int voltage_max; + int voltage_normal; + int voltage_min; + /* Pre-charge current in mA */ + int precharge_current; +}; + +/** + * Return vendor-provided battery constants. + */ +const struct battery_info *battery_get_info(void); + +/** + * Modify battery parameters to match vendor charging profile. + * + * @param batt Battery parameters to modify + */ +void battery_vendor_params(struct batt_params *batt); + +/** + * Attempt communication with the battery. + * + * @return non-zero if the battery responds. + */ +int battery_is_connected(void); + +/** + * Get battery mode. + * + * See MODE_* constants in smart_battery.h + * + * @param mode Destination for current mode. + * @return non-zero if error. + */ +int battery_get_mode(int *mode); + +/** + * Set battery mode. + * + * See MODE_* constants in smart_battery.h + * + * @param mode New mode. + * @return non-zero if error. + */ +int battery_set_mode(int mode); -/* Get/set battery mode */ -int battery_get_battery_mode(int *mode); +/** + * Check if battery is reporting capacity in 10 mW units. + * + * @param val Destination for capacity units; set zero if mAh or + * non-zero if 10 mW. + * @return non-zero if error. + */ +int battery_is_in_10mw_mode(int *val); -int battery_set_battery_mode(int mode); +/** + * Set battery capacity units. + * + * @param enabled Set mode to mAh (=0) or 10 mW (=1) + * @return non-zero if error. + */ +int battery_set_10mw_mode(int enabled); -/* Read battery temperature - * unit: 0.1 K +/** + * Read battery temperature. + * + * @param deci_kelvin Destination for battery temperature in units of 0.1 K + * @return non-zero if error. */ int battery_temperature(int *deci_kelvin); -/* Read battery voltage - * unit: mV +/** + * Read battery voltage. + * + * @param voltage Destination for voltage in mW + * @return non-zero if error. */ int battery_voltage(int *voltage); -/* Relative state of charge in percent */ -int battery_state_of_charge(int *percent); +/** + * Read nominal voltage battery is designed to supply. + * + * @param voltage Destination for voltage in mW + * @return non-zero if error. + */ +int battery_design_voltage(int *voltage); -/* Absolute state of charge in percent */ -int battery_state_of_charge_abs(int *percent); +/** + * Read charging voltage desired by battery. + * + * @param voltage Destination for voltage in mV. + * @return non-zero if error. + */ +int battery_desired_voltage(int *voltage); -/* - * Set 'val' to non-zero if the battery is reporting capacity in 10mW. - * Otherwise, in mAh. +/** + * Read battery discharging current. + * + * @param current Destination for discharge current in mA; negative + * value indicates charging. + * @return non-zero if error. */ -int battery_is_in_10mw_mode(int *val); +int battery_current(int *current); -/* Set battery capacity mode to mAh(=0) or 10mW(=1). */ -int battery_set_10mw_mode(int enabled); +/** + * Read averaged battery discharging current. + * + * @param current Destination for discharge current in mA; negative + * value indicates charging. + * @return non-zero if error. + */ +int battery_average_current(int *current); -/* - * Battery remaining capacity - * unit: mAh or 10mW, depends on battery mode +/** + * Read charging current desired by battery. + * + * @param current Destination for current in mA. + * @return non-zero if error. + */ +int battery_desired_current(int *current); + +/** + * Read battery relative state of charge. + * + * @param percent Destination for charge in percent + * @return non-zero if error. + */ +int battery_state_of_charge(int *percent); + +/** + * Read absolute state of charge. + * + * @param percent Destination for charge in percent + * @return non-zero if error. + */ +int battery_state_of_charge_abs(int *percent); + +/** + * Read battery remaining capacity. + * + * @param capacity Destination for capacity; units are mAh or 10 mW, + * depending on battery_is_in_10mw_mode(). + * @return non-zero if error. */ int battery_remaining_capacity(int *capacity); -/* Battery full charge capacity */ +/** + * Read battery full charge capacity. + * + * @param capacity Destination for capacity; units are mAh or 10 mW, + * depending on battery_is_in_10mw_mode(). + * @return non-zero if error. + */ int battery_full_charge_capacity(int *capacity); -/* Time in minutes left when discharging */ +/** + * Read the nominal capacity the battery is designed to supply when new. + * + * @param capacity Destination for capacity; units are mAh or 10 mW, + * depending on battery_is_in_10mw_mode(). + * @return non-zero if error. + */ +int battery_design_capacity(int *capacity); + +/** + * Read time in minutes left when discharging. + * + * @param capacity Destination for remaining time in minutes. + * @return non-zero if error. + */ int battery_time_to_empty(int *minutes); +/** + * Read run time in minutes left when discharging. + * + * @param capacity Destination for remaining time in minutes. + * @return non-zero if error. + */ int battery_run_time_to_empty(int *minutes); -/* Time in minutes to full when charging */ +/** + * Read time in minutes left to full capacity when charging. + * + * @param capacity Destination for remaining time in minutes. + * @return non-zero if error. + */ int battery_time_to_full(int *minutes); -/* The current battery desired to charge - * unit: mA +/** + * Calculate battery time in minutes, under an assumed current. + * + * @param rate Current to use for calculation, in mA. + * If > 0, calculates charging time; if < 0, calculates + * discharging time; 0 is invalid and sets minutes=0. + * @param minutes Destination for calculated time in minutes. + * @return non-zero if error. */ -int battery_desired_current(int *current); +int battery_time_at_rate(int rate, int *minutes); -/* The voltage battery desired to charge - * unit: mV +/** + * Check if battery allows charging. + * + * @param allowed Non-zero if charging allowed; zero if not allowed. + * @return non-zero if error. */ -int battery_desired_voltage(int *voltage); - -/* Check if battery allows charging */ int battery_charging_allowed(int *allowed); -/* Read battery status */ +/** + * Read battery status. + * + * @param status Destination for status; see STATUS_* in smart_battery.h. + * @return non-zero if error. + */ int battery_status(int *status); -/* Battery charge cycle count */ -int battery_cycle_count(int *count); - -/* Designed battery capacity - * unit: mAh or 10mW depends on battery mode +/** + * Read battery charge cycle count. + * + * @param count Destination for count. + * @return non-zero if error. */ -int battery_design_capacity(int *capacity); +int battery_cycle_count(int *count); -/* Designed battery output voltage - * unit: mV +/** + * Read battery serial number. + * + * @param serial Destination for serial number. + * @return non-zero if error. */ -int battery_design_voltage(int *voltage); - -/* Read serial number */ int battery_serial_number(int *serial); -/* Read manufacturer name */ -int battery_manufacturer_name(char *manufacturer_name, int buf_size); - -/* Read device name */ -int battery_device_name(char *device_name, int buf_size); - -/* Read battery type/chemistry */ -int battery_device_chemistry(char *device_chemistry, int buf_size); +/** + * Read manufacturer name. + * + * @param dest Destination buffer. + * @param size Length of destination buffer in chars. + * @return non-zero if error. + */ +int battery_manufacturer_name(char *dest, int size); -/* Read battery discharging current - * unit: mA - * negative value: charging +/** + * Read device name. + * + * @param dest Destination buffer. + * @param size Length of destination buffer in chars. + * @return non-zero if error. */ -int battery_current(int *current); -int battery_average_current(int *current); +int battery_device_name(char *dest, int size); -/* Calculate battery time in minutes, under a charging rate - * rate > 0: charging, negative time to full - * rate < 0: discharging, positive time to empty - * rate == 0: invalid input, time = 0 +/** + * Read battery type/chemistry. + * + * @param dest Destination buffer. + * @param size Length of destination buffer in chars. + * @return non-zero if error. */ -int battery_time_at_rate(int rate, int *minutes); +int battery_device_chemistry(char *dest, int size); -/* Read manufacturer date */ +/** + * Read device manufacture date. + * + * @param year Destination for year + * @param month Destination for month + * @param day Destination for day + * @return non-zero if error. + */ int battery_manufacturer_date(int *year, int *month, int *day); #endif /* __CROS_EC_BATTERY_H */ diff --git a/include/battery_pack.h b/include/battery_pack.h deleted file mode 100644 index 9cd068478b..0000000000 --- a/include/battery_pack.h +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - * - * Common API for battery pack vendor provided charging profile - */ -#ifndef __CROS_EC_BATTERY_PACK_H -#define __CROS_EC_BATTERY_PACK_H - -#include "common.h" - -/* Battery parameters */ -struct batt_params { - int temperature; /* Temperature in 0.1 K */ - int state_of_charge; /* State of charge (percent, 0-100) */ - int voltage; /* Battery voltage (mV) */ - int current; /* Battery current (mA) */ - int desired_voltage; /* Charging voltage desired by battery (mV) */ - int desired_current; /* Charging current desired by battery (mA) */ -}; - -/* Working temperature ranges in degrees C */ -struct battery_temperature_ranges { - int8_t start_charging_min_c; - int8_t start_charging_max_c; - int8_t charging_min_c; - int8_t charging_max_c; - int8_t discharging_min_c; - int8_t discharging_max_c; -}; -extern const struct battery_temperature_ranges bat_temp_ranges; - -/* Battery constants */ -struct battery_info { - /* Design voltage in mV */ - int voltage_max; - int voltage_normal; - int voltage_min; - /* Pre-charge current in mA */ - int precharge_current; -}; - -/** - * Return vendor-provided battery constants. - */ -const struct battery_info *battery_get_info(void); - -#ifdef CONFIG_BATTERY_VENDOR_PARAMS -/** - * Modify battery parameters to match vendor charging profile. - * - * @param batt Battery parameters to modify - */ -void battery_vendor_params(struct batt_params *batt); -#endif - -#ifdef CONFIG_BATTERY_CHECK_CONNECTED -/** - * Attempt communication with the battery. - * - * @return non-zero if the battery responds. - */ -int battery_is_connected(void); -#endif /* CONFIG_BATTERY_CHECK_CONNECTED */ - -#endif /* __CROS_EC_BATTERY_PACK_H */ diff --git a/include/smart_battery.h b/include/battery_smart.h index 9d457fef47..6324f1c31d 100644 --- a/include/smart_battery.h +++ b/include/battery_smart.h @@ -8,9 +8,7 @@ #ifndef __CROS_EC_SMART_BATTERY_H #define __CROS_EC_SMART_BATTERY_H -#include "battery.h" #include "common.h" -#include "i2c.h" /* Smart battery and charger I2C address */ #define BATTERY_ADDR 0x16 @@ -60,14 +58,15 @@ #define SB_MANUFACTURER_DATA 0x23 /* Battery mode */ -#define MODE_CAPACITY (1 << 15) -#define MODE_CHARGER (1 << 14) -#define MODE_ALARM (1 << 13) -#define MODE_PRIMARY_BATTERY (1 << 9) -#define MODE_CHARGE_CONTROLLER_ENABLED (1 << 8) -#define MODE_CONDITION_CYCLE (1 << 7) -#define MODE_PRIMARY_BATTERY_SUPPORT (1 << 1) #define MODE_INTERNAL_CHARGE_CONTROLLER (1 << 0) +#define MODE_PRIMARY_BATTERY_SUPPORT (1 << 1) +#define MODE_CONDITION_CYCLE (1 << 7) +#define MODE_CHARGE_CONTROLLER_ENABLED (1 << 8) +#define MODE_PRIMARY_BATTERY (1 << 9) +#define MODE_ALARM (1 << 13) +#define MODE_CHARGER (1 << 14) +#define MODE_CAPACITY (1 << 15) + /* Battery status */ #define STATUS_ERR_CODE_MASK 0xf #define STATUS_CODE_OK 0 diff --git a/include/charge_state.h b/include/charge_state.h index 722de8cd4f..5511dde496 100644 --- a/include/charge_state.h +++ b/include/charge_state.h @@ -3,7 +3,7 @@ * found in the LICENSE file. */ -#include "battery_pack.h" +#include "battery.h" #include "timer.h" #ifndef __CROS_EC_CHARGE_STATE_H diff --git a/test/led_spring.c b/test/led_spring.c index 79f01b297f..92f358cb04 100644 --- a/test/led_spring.c +++ b/test/led_spring.c @@ -5,12 +5,12 @@ * Test lid switch. */ +#include "battery_smart.h" #include "common.h" #include "console.h" #include "host_command.h" #include "lp5562.h" #include "pmu_tpschrome.h" -#include "smart_battery.h" #include "test_util.h" #include "timer.h" #include "util.h" diff --git a/test/sbs_charging.c b/test/sbs_charging.c index adfc053e01..fc74cc8624 100644 --- a/test/sbs_charging.c +++ b/test/sbs_charging.c @@ -5,15 +5,13 @@ * Test lid switch. */ -#include "battery_pack.h" +#include "battery_smart.h" #include "charge_state.h" #include "chipset.h" #include "common.h" -#include "ec_commands.h" #include "gpio.h" #include "hooks.h" #include "host_command.h" -#include "smart_battery.h" #include "task.h" #include "test_util.h" #include "util.h" diff --git a/test/thermal_falco.c b/test/thermal_falco.c index 0d56f4fe16..87a00f57bb 100644 --- a/test/thermal_falco.c +++ b/test/thermal_falco.c @@ -5,7 +5,8 @@ * Test thermal engine. */ -#include "battery_pack.h" +#include "battery.h" +#include "battery_smart.h" #include "chipset.h" #include "common.h" #include "console.h" @@ -15,7 +16,6 @@ #include "hooks.h" #include "host_command.h" #include "printf.h" -#include "smart_battery.h" #include "temp_sensor.h" #include "test_util.h" #include "thermal.h" |