cleanup: Battery header files and filenames

battery.h is the high-level interface.  battery_smart.h is the
low-level interface.  Most things don't need the low-level interface,
but were including smart_battery.h solely to get at battery.h.  Fixed
this.  Also merged battery_pack.h into battery.h, since it was odd to
split that data across multiple header files.  Tidied the function
comments in battery.h as well.

No functional changes, just renaming files and adding comments.

BUG=chrome-os-partner:18343
BRANCH=none
TEST=build all boards; pass unit tests

Change-Id: I5ef372f0a5f8f5f36e09a3a1ce24008685c1fd0d
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/171967
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
This commit is contained in:
Randall Spangler
2013-10-04 12:38:18 -07:00
committed by chrome-internal-fetch
parent 90a6676ad5
commit 99157c265c
38 changed files with 341 additions and 257 deletions

View File

@@ -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"

View File

@@ -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

View File

@@ -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];

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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 = {

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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 */

View File

@@ -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"

View File

@@ -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;

View File

@@ -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[] = {
/*

View File

@@ -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"

View File

@@ -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

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -5,7 +5,7 @@
* Battery pack vendor provided charging profile
*/
#include "battery_pack.h"
#include "battery.h"
/*
* Design capacity

View File

@@ -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);
}
/*****************************************************************************/

View File

@@ -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

View File

@@ -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"

View File

@@ -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

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -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 */

View File

@@ -10,7 +10,6 @@
#include "console.h"
#include "host_command.h"
#include "printf.h"
#include "smart_battery.h"
#include "util.h"
/* Console output macros */

View File

@@ -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"

View File

@@ -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"

View File

@@ -6,7 +6,6 @@
*/
#include "battery.h"
#include "battery_pack.h"
#include "charge_state.h"
#include "common.h"
#include "console.h"

View File

@@ -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"

View File

@@ -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

View File

@@ -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) */
};
/* Get/set battery mode */
int battery_get_battery_mode(int *mode);
/* 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;
int battery_set_battery_mode(int mode);
/* 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;
};
/* Read battery temperature
* unit: 0.1 K
/**
* Return vendor-provided battery constants.
*/
int battery_temperature(int *deci_kelvin);
const struct battery_info *battery_get_info(void);
/* Read battery voltage
* unit: mV
/**
* Modify battery parameters to match vendor charging profile.
*
* @param batt Battery parameters to modify
*/
int battery_voltage(int *voltage);
void battery_vendor_params(struct batt_params *batt);
/* Relative state of charge in percent */
int battery_state_of_charge(int *percent);
/**
* Attempt communication with the battery.
*
* @return non-zero if the battery responds.
*/
int battery_is_connected(void);
/* Absolute state of charge in percent */
int battery_state_of_charge_abs(int *percent);
/**
* 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 'val' to non-zero if the battery is reporting capacity in 10mW.
* Otherwise, in mAh.
/**
* 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);
/**
* 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);
/* Set battery capacity mode to mAh(=0) or 10mW(=1). */
/**
* 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);
/*
* Battery remaining capacity
* unit: mAh or 10mW, depends on battery mode
/**
* Read battery temperature.
*
* @param deci_kelvin Destination for battery temperature in units of 0.1 K
* @return non-zero if error.
*/
int battery_remaining_capacity(int *capacity);
int battery_temperature(int *deci_kelvin);
/* Battery full charge capacity */
int battery_full_charge_capacity(int *capacity);
/* Time in minutes left when discharging */
int battery_time_to_empty(int *minutes);
int battery_run_time_to_empty(int *minutes);
/* Time in minutes to full when charging */
int battery_time_to_full(int *minutes);
/* The current battery desired to charge
* unit: mA
/**
* Read battery voltage.
*
* @param voltage Destination for voltage in mW
* @return non-zero if error.
*/
int battery_desired_current(int *current);
int battery_voltage(int *voltage);
/* The voltage battery desired to charge
* unit: mV
*/
int battery_desired_voltage(int *voltage);
/* Check if battery allows charging */
int battery_charging_allowed(int *allowed);
/* Read battery status */
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
*/
int battery_design_capacity(int *capacity);
/* Designed battery output voltage
* unit: mV
/**
* 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);
/* Read serial number */
int battery_serial_number(int *serial);
/**
* Read charging voltage desired by battery.
*
* @param voltage Destination for voltage in mV.
* @return non-zero if error.
*/
int battery_desired_voltage(int *voltage);
/* 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 battery discharging current
* unit: mA
* negative value: charging
/**
* Read battery discharging current.
*
* @param current Destination for discharge current in mA; negative
* value indicates charging.
* @return non-zero if error.
*/
int battery_current(int *current);
/**
* 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);
/* 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 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);
/**
* 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);
/**
* 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);
/**
* 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);
/**
* 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_time_at_rate(int rate, int *minutes);
/* Read manufacturer date */
/**
* Check if battery allows charging.
*
* @param allowed Non-zero if charging allowed; zero if not allowed.
* @return non-zero if error.
*/
int battery_charging_allowed(int *allowed);
/**
* Read battery status.
*
* @param status Destination for status; see STATUS_* in smart_battery.h.
* @return non-zero if error.
*/
int battery_status(int *status);
/**
* Read battery charge cycle count.
*
* @param count Destination for count.
* @return non-zero if error.
*/
int battery_cycle_count(int *count);
/**
* Read battery serial number.
*
* @param serial Destination for serial number.
* @return non-zero if error.
*/
int battery_serial_number(int *serial);
/**
* 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 device name.
*
* @param dest Destination buffer.
* @param size Length of destination buffer in chars.
* @return non-zero if error.
*/
int battery_device_name(char *dest, int size);
/**
* Read battery type/chemistry.
*
* @param dest Destination buffer.
* @param size Length of destination buffer in chars.
* @return non-zero if error.
*/
int battery_device_chemistry(char *dest, int size);
/**
* 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 */

View File

@@ -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 */

View File

@@ -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

View File

@@ -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

View File

@@ -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"

View File

@@ -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"

View File

@@ -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"