summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorRandall Spangler <rspangler@chromium.org>2013-10-04 12:38:18 -0700
committerchrome-internal-fetch <chrome-internal-fetch@google.com>2013-10-07 18:30:50 +0000
commit99157c265c8353e166059e17d250d9991d4e7ae0 (patch)
tree386a582966b8b34afa652602a21eec6e6feab931 /common
parent90a6676ad531fd8c53e6398050f8093a921245fc (diff)
downloadchrome-ec-99157c265c8353e166059e17d250d9991d4e7ae0.tar.gz
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>
Diffstat (limited to 'common')
-rw-r--r--common/battery_bq20z453.c3
-rw-r--r--common/battery_bq27541.c6
-rw-r--r--common/battery_common.c (renamed from common/battery.c)2
-rw-r--r--common/battery_link.c2
-rw-r--r--common/battery_smart.c (renamed from common/smart_battery.c)60
-rw-r--r--common/build.mk4
-rw-r--r--common/charge_state.c3
-rw-r--r--common/charger_bq24707a.c4
-rw-r--r--common/charger_bq24715.c2
-rw-r--r--common/charger_bq24725.c3
-rw-r--r--common/charger_bq24738.c3
-rw-r--r--common/charger_common.c1
-rw-r--r--common/extpower_falco.c2
-rw-r--r--common/extpower_spring.c2
-rw-r--r--common/lightbar.c1
-rw-r--r--common/pmu_tps65090_charger.c4
-rw-r--r--common/pmu_tps65090_powerinfo.c2
17 files changed, 36 insertions, 68 deletions
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