diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/battery_falco.c | 27 | ||||
-rw-r--r-- | common/battery_link.c | 37 | ||||
-rw-r--r-- | common/battery_peppy.c | 31 | ||||
-rw-r--r-- | common/battery_slippy.c | 31 | ||||
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/charge_state.c | 12 | ||||
-rw-r--r-- | common/mock_charger.c | 43 | ||||
-rw-r--r-- | common/mock_smart_battery_stub.c | 183 | ||||
-rw-r--r-- | common/pmu_tps65090_charger.c | 30 | ||||
-rw-r--r-- | common/smart_battery.c | 21 |
10 files changed, 238 insertions, 178 deletions
diff --git a/common/battery_falco.c b/common/battery_falco.c index c2430fa07e..9a493c19d6 100644 --- a/common/battery_falco.c +++ b/common/battery_falco.c @@ -12,18 +12,21 @@ #define SB_SHIP_MODE_DATA 0x0010 /* FIXME: We need REAL values for all this stuff */ +const struct battery_temperature_ranges bat_temp_ranges = { + .start_charging_min_c = 0, + .start_charging_max_c = 45, + .charging_min_c = 0, + .charging_max_c = 45, + .discharging_min_c = -10, + .discharging_max_c = 60, +}; + static const struct battery_info info = { .voltage_max = 8400, .voltage_normal = 7400, .voltage_min = 6000, - /* Operational temperature range */ - .temp_charge_min = CELSIUS_TO_DECI_KELVIN(0), - .temp_charge_max = CELSIUS_TO_DECI_KELVIN(45), - .temp_discharge_min = CELSIUS_TO_DECI_KELVIN(-10), - .temp_discharge_max = CELSIUS_TO_DECI_KELVIN(60), - /* Pre-charge values. */ .precharge_current = 256, /* mA */ }; @@ -37,18 +40,6 @@ const struct battery_info *battery_get_info(void) * called "smart". Do we really want to second-guess it? For now, let's not. */ void battery_vendor_params(struct batt_params *batt) { -#if 0 - /* Limit charging voltage */ - if (batt->desired_voltage > info.voltage_max) - batt->desired_voltage = info.voltage_max; - - /* Don't charge if outside of allowable temperature range */ - if (batt->temperature >= info.temp_charge_max || - batt->temperature <= info.temp_charge_min) { - batt->desired_voltage = 0; - batt->desired_current = 0; - } -#endif } int battery_command_cut_off(struct host_cmd_handler_args *args) diff --git a/common/battery_link.c b/common/battery_link.c index c92f3dafd2..4e7e9c769b 100644 --- a/common/battery_link.c +++ b/common/battery_link.c @@ -47,6 +47,20 @@ static const int const current_limit[TEMP_RANGE_MAX][VOLT_RANGE_MAX] = { { 800, 1600, 800}, }; +const struct battery_temperature_ranges bat_temp_ranges = { + /* + * Operational temperature range + * 0 <= T_charge <= 50 deg C + * -20 <= T_discharge <= 60 deg C + */ + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 50, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + static const struct battery_info info = { /* * Design voltage @@ -58,16 +72,6 @@ static const struct battery_info info = { .voltage_normal = 7400, .voltage_min = 6000, - /* - * Operational temperature range - * 0 <= T_charge <= 50 deg C - * -20 <= T_discharge <= 60 deg C - */ - .temp_charge_min = CELSIUS_TO_DECI_KELVIN(0), - .temp_charge_max = CELSIUS_TO_DECI_KELVIN(50), - .temp_discharge_min = CELSIUS_TO_DECI_KELVIN(-20), - .temp_discharge_max = CELSIUS_TO_DECI_KELVIN(60), - /* Pre-charge current: I <= 0.01C */ .precharge_current = 64, /* mA */ }; @@ -87,26 +91,27 @@ void battery_vendor_params(struct batt_params *batt) { int *desired_current = &batt->desired_current; int temp_range, volt_range; + int bat_temp_c = DECI_KELVIN_TO_CELSIUS(batt->temperature); /* Limit charging voltage */ if (batt->desired_voltage > info.voltage_max) batt->desired_voltage = info.voltage_max; /* Don't charge if outside of allowable temperature range */ - if (batt->temperature >= info.temp_charge_max || - batt->temperature <= info.temp_charge_min) { + if (bat_temp_c >= bat_temp_ranges.charging_max_c || + bat_temp_c < bat_temp_ranges.charging_min_c) { batt->desired_voltage = 0; batt->desired_current = 0; return; } - if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(10)) + if (bat_temp_c <= 10) temp_range = TEMP_RANGE_10; - else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(23)) + else if (bat_temp_c <= 23) temp_range = TEMP_RANGE_23; - else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(35)) + else if (bat_temp_c <= 35) temp_range = TEMP_RANGE_35; - else if (batt->temperature <= CELSIUS_TO_DECI_KELVIN(45)) + else if (bat_temp_c <= 45) temp_range = TEMP_RANGE_45; else temp_range = TEMP_RANGE_50; diff --git a/common/battery_peppy.c b/common/battery_peppy.c index 086469c9a3..76d2d04395 100644 --- a/common/battery_peppy.c +++ b/common/battery_peppy.c @@ -14,22 +14,21 @@ #define SB_SHIP_MODE_DATA 0xc574 /* Values for 54Wh 3UPF656790-1-T1001 battery */ +const struct battery_temperature_ranges bat_temp_ranges = { + .start_charging_min_c = 0, + .start_charging_max_c = 60, + .charging_min_c = 0, + .charging_max_c = 60, + .discharging_min_c = 0, + .discharging_max_c = 50, +}; + static const struct battery_info info = { .voltage_max = 12600, .voltage_normal = 11100, /* Average of max & min */ .voltage_min = 9000, - /* - * Operational temperature range - * 0 <= T_charge <= 60 deg C - * 0 <= T_discharge <= 50 deg C - */ - .temp_charge_min = CELSIUS_TO_DECI_KELVIN(0), - .temp_charge_max = CELSIUS_TO_DECI_KELVIN(60), - .temp_discharge_min = CELSIUS_TO_DECI_KELVIN(0), - .temp_discharge_max = CELSIUS_TO_DECI_KELVIN(50), - /* Pre-charge values. */ .precharge_current = 256, /* mA */ }; @@ -43,18 +42,6 @@ const struct battery_info *battery_get_info(void) * called "smart". Do we really want to second-guess it? For now, let's not. */ void battery_vendor_params(struct batt_params *batt) { -#if 0 - /* Limit charging voltage */ - if (batt->desired_voltage > info.voltage_max) - batt->desired_voltage = info.voltage_max; - - /* Don't charge if outside of allowable temperature range */ - if (batt->temperature >= info.temp_charge_max || - batt->temperature <= info.temp_charge_min) { - batt->desired_voltage = 0; - batt->desired_current = 0; - } -#endif } int battery_command_cut_off(struct host_cmd_handler_args *args) diff --git a/common/battery_slippy.c b/common/battery_slippy.c index 8d9648d26d..64d5c09d1e 100644 --- a/common/battery_slippy.c +++ b/common/battery_slippy.c @@ -9,22 +9,21 @@ #include "gpio.h" /* FIXME: We need REAL values for all this stuff */ +const struct battery_temperature_ranges bat_temp_ranges = { + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 50, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + static const struct battery_info info = { .voltage_max = 16800, .voltage_normal = 14800, .voltage_min = 10800, - /* - * Operational temperature range - * 0 <= T_charge <= 50 deg C - * -20 <= T_discharge <= 60 deg C - */ - .temp_charge_min = CELSIUS_TO_DECI_KELVIN(0), - .temp_charge_max = CELSIUS_TO_DECI_KELVIN(50), - .temp_discharge_min = CELSIUS_TO_DECI_KELVIN(-20), - .temp_discharge_max = CELSIUS_TO_DECI_KELVIN(60), - /* Pre-charge values. */ .precharge_current = 256, /* mA */ }; @@ -38,18 +37,6 @@ const struct battery_info *battery_get_info(void) * called "smart". Do we really want to second-guess it? For now, let's not. */ void battery_vendor_params(struct batt_params *batt) { -#if 0 - /* Limit charging voltage */ - if (batt->desired_voltage > info.voltage_max) - batt->desired_voltage = info.voltage_max; - - /* Don't charge if outside of allowable temperature range */ - if (batt->temperature >= info.temp_charge_max || - batt->temperature <= info.temp_charge_min) { - batt->desired_voltage = 0; - batt->desired_current = 0; - } -#endif } /** diff --git a/common/build.mk b/common/build.mk index 6f8a0213e0..18644b8b96 100644 --- a/common/build.mk +++ b/common/build.mk @@ -46,6 +46,7 @@ common-$(CONFIG_LED_PEPPY)+=led_peppy.o common-$(CONFIG_LED_SLIPPY)+=led_slippy.o common-$(CONFIG_LID_SWITCH)+=lid_switch.o common-$(CONFIG_LPC)+=port80.o +common-$(CONFIG_MOCK_BATTERY)+=mock_smart_battery_stub.o mock_charger.o common-$(CONFIG_ONEWIRE_LED)+=onewire_led.o common-$(CONFIG_POWER_BUTTON)+=power_button.o common-$(CONFIG_POWER_BUTTON_X86)+=power_button_x86.o diff --git a/common/charge_state.c b/common/charge_state.c index 8d605ec03e..49630ff7be 100644 --- a/common/charge_state.c +++ b/common/charge_state.c @@ -34,6 +34,13 @@ /* Timeout after AP battery shutdown warning before we kill the AP */ #define LOW_BATTERY_SHUTDOWN_TIMEOUT_US (30 * SECOND) +#ifndef TASK_ID_CHARGER +#define TASK_ID_CHARGER TASK_ID_INVALID +#endif +#ifndef TASK_ID_SWITCH +#define TASK_ID_SWITCH TASK_ID_INVALID +#endif + static const char * const state_name[] = POWER_STATE_NAME_TABLE; static int state_machine_force_idle = 0; @@ -483,6 +490,7 @@ static enum power_state state_charge(struct power_state_context *ctx) static enum power_state state_discharge(struct power_state_context *ctx) { struct batt_params *batt = &ctx->curr.batt; + int8_t bat_temp_c = DECI_KELVIN_TO_CELSIUS(batt->temperature); if (ctx->curr.ac) return PWR_STATE_REINIT; @@ -490,8 +498,8 @@ static enum power_state state_discharge(struct power_state_context *ctx) return PWR_STATE_ERROR; /* Handle overtemp in discharging state by powering off host */ - if ((batt->temperature > ctx->battery->temp_discharge_max || - batt->temperature < ctx->battery->temp_discharge_min) && + if ((bat_temp_c >= bat_temp_ranges.discharging_max_c || + bat_temp_c < bat_temp_ranges.discharging_min_c) && chipset_in_state(CHIPSET_STATE_ON)) { CPRINTF("[%T charge force shutdown due to battery temp]\n"); chipset_force_shutdown(); diff --git a/common/mock_charger.c b/common/mock_charger.c index d1d9659ad8..47b2a96079 100644 --- a/common/mock_charger.c +++ b/common/mock_charger.c @@ -78,7 +78,6 @@ int charger_set_current(int current) return EC_SUCCESS; } - int charger_get_voltage(int *voltage) { *voltage = mock_voltage; @@ -94,6 +93,48 @@ int charger_set_voltage(int voltage) } +int charger_get_option(int *option) +{ + return EC_SUCCESS; +} + + +int charger_set_option(int option) +{ + return EC_SUCCESS; +} + + +int charger_manufacturer_id(int *id) +{ + return EC_SUCCESS; +} + + +int charger_device_id(int *id) +{ + return EC_SUCCESS; +} + + +int charger_get_input_current(int *input_current) +{ + return EC_SUCCESS; +} + + +int charger_set_input_current(int input_current) +{ + return EC_SUCCESS; +} + + +int charger_closest_current(int current) +{ + return current; +} + + int charger_post_init(void) { mock_current = CONFIG_CHARGER_INPUT_CURRENT; diff --git a/common/mock_smart_battery_stub.c b/common/mock_smart_battery_stub.c index 49b44859c9..0cf7b70e78 100644 --- a/common/mock_smart_battery_stub.c +++ b/common/mock_smart_battery_stub.c @@ -1,105 +1,124 @@ +/* Copyright (c) 2013 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. + * + * Smart battery driver. + */ + +#include "battery_pack.h" +#include "common.h" #include "console.h" #include "smart_battery.h" #include "smart_battery_stub.h" #include "uart.h" #include "util.h" -static int mock_temperature = 2981; -static int mock_desire_voltage = 7000; -static int mock_desire_current = 3000; -static int mock_voltage = 6000; -static int mock_current = 3000; +static uint16_t mock_smart_battery[SB_MANUFACTURER_DATA + 1]; int sb_read(int cmd, int *param) { - switch (cmd) - { - case SB_TEMPERATURE: - *param = mock_temperature; - break; - case SB_VOLTAGE: - *param = mock_voltage; - break; - case SB_CURRENT: - *param = mock_current; - break; - case SB_RELATIVE_STATE_OF_CHARGE: - case SB_ABSOLUTE_STATE_OF_CHARGE: - *param = 70; /* 70% charged */ - break; - case SB_REMAINING_CAPACITY: - *param = 7000; /* 7000 mAh */ - break; - case SB_FULL_CHARGE_CAPACITY: - case SB_DESIGN_CAPACITY: - *param = 10000; /* 10000 mAh */ - break; - case SB_AVERAGE_TIME_TO_EMPTY: - case SB_RUN_TIME_TO_EMPTY: - *param = 60; /* 60 min to empty */ - break; - case SB_AVERAGE_TIME_TO_FULL: - *param = 30; /* 30 min to full */ - break; - case SB_CHARGING_CURRENT: - *param = mock_desire_current; - break; - case SB_CHARGING_VOLTAGE: - *param = mock_desire_voltage; - break; - case SB_CYCLE_COUNT: - *param = 10; - break; - case SB_DESIGN_VOLTAGE: - *param = 7400; /* 7.4 V */ - break; - case SB_SERIAL_NUMBER: - *param = 112233; - break; - default: - *param = 0; - break; - } + if (cmd >= ARRAY_SIZE(mock_smart_battery)) + return EC_ERROR_UNIMPLEMENTED; + if (cmd < 0 || param == NULL) + return EC_ERROR_INVAL; + *param = mock_smart_battery[cmd]; + return EC_SUCCESS; +} +int sb_write(int cmd, int param) +{ + if (cmd >= ARRAY_SIZE(mock_smart_battery)) + return EC_ERROR_UNIMPLEMENTED; + if (cmd < 0) + return EC_ERROR_INVAL; + mock_smart_battery[cmd] = param; return EC_SUCCESS; } +int battery_manufacturer_name(char *manufacturer_name, int buf_size) +{ + return EC_SUCCESS; +} -int sb_write(int cmd, int param) +int battery_device_name(char *device_name, int buf_size) { - uart_printf("sb_write: cmd = %d, param = %d\n", cmd, param); return EC_SUCCESS; } +int battery_device_chemistry(char *device_chemistry, int buf_size) +{ + return EC_SUCCESS; +} + +int battery_current(int *current) +{ + int rv, d; + + rv = sb_read(SB_CURRENT, &d); + if (rv) + return rv; + + *current = (int16_t)d; + return EC_SUCCESS; +} + +int battery_average_current(int *current) +{ + int rv, d; + + rv = sb_read(SB_AVERAGE_CURRENT, &d); + if (rv) + return rv; -static int command_sb_mock(int argc, char **argv) + *current = (int16_t)d; + return EC_SUCCESS; +} + +int battery_time_at_rate(int rate, int *minutes) { - char *e; - int v; - - if (argc < 3) - return EC_ERROR_PARAM_COUNT; - - v = strtoi(argv[2], &e, 0); - if (*e) - return EC_ERROR_PARAM2; - - if (!strcasecmp(argv[1], "temperature")) - mock_temperature = v; - else if (!strcasecmp(argv[1], "desire_voltage")) - mock_desire_voltage = v; - else if (!strcasecmp(argv[1], "desire_current")) - mock_desire_current = v; - else if (!strcasecmp(argv[1], "voltage")) - mock_voltage = v; - else if (!strcasecmp(argv[1], "current")) - mock_current = v; - else - return EC_ERROR_PARAM1; + return EC_SUCCESS; +} +int battery_manufacturer_date(int *year, int *month, int *day) +{ return EC_SUCCESS; } -DECLARE_CONSOLE_COMMAND(sbmock, command_sb_mock, - "name value", - "Mock smart battery attribute", - NULL); + +/* Fake battery */ +const struct battery_temperature_ranges bat_temp_ranges = { + /* + * Operational temperature range + * 0 <= T_charge <= 50 deg C + * -20 <= T_discharge <= 60 deg C + */ + .start_charging_min_c = 0, + .start_charging_max_c = 50, + .charging_min_c = 0, + .charging_max_c = 50, + .discharging_min_c = -20, + .discharging_max_c = 60, +}; + +static const struct battery_info bat_info = { + /* + * Design voltage + * max = 8.4V + * normal = 7.4V + * min = 6.0V + */ + .voltage_max = 8400, + .voltage_normal = 7400, + .voltage_min = 6000, + + /* Pre-charge current: I <= 0.01C */ + .precharge_current = 64, /* mA */ +}; + +const struct battery_info *battery_get_info(void) +{ + return &bat_info; +} + +void battery_vendor_params(struct batt_params *batt) +{ +} diff --git a/common/pmu_tps65090_charger.c b/common/pmu_tps65090_charger.c index 36fb0d1989..d91a52b83b 100644 --- a/common/pmu_tps65090_charger.c +++ b/common/pmu_tps65090_charger.c @@ -5,6 +5,7 @@ * TI TPS65090 PMU charging task. */ +#include "battery_pack.h" #include "clock.h" #include "chipset.h" #include "common.h" @@ -58,31 +59,30 @@ static void enable_charging(int enable) gpio_set_level(GPIO_CHARGER_EN, enable); } -/* - * TODO(rongchang): move battery vendor specific functions to battery pack - * module - */ -static int battery_temperature_celsius(int t) +static int battery_temperature_celsius(int deci_k) { - return (t - 2731) / 10; + return (deci_k - 2731) / 10; } -static int battery_start_charging_range(int t) +static int battery_start_charging_range(int deci_k) { - t = battery_temperature_celsius(t); - return (t >= 5 && t < 45); + int8_t temp_c = battery_temperature_celsius(deci_k); + return (temp_c >= bat_temp_ranges.start_charging_min_c && + temp_c < bat_temp_ranges.start_charging_max_c); } -static int battery_charging_range(int t) +static int battery_charging_range(int deci_k) { - t = battery_temperature_celsius(t); - return (t >= 5 && t < 60); + int8_t temp_c = battery_temperature_celsius(deci_k); + return (temp_c >= bat_temp_ranges.charging_min_c && + temp_c < bat_temp_ranges.charging_max_c); } -static int battery_discharging_range(int t) +static int battery_discharging_range(int deci_k) { - t = battery_temperature_celsius(t); - return (t >= 0 && t < 100); + int8_t temp_c = battery_temperature_celsius(deci_k); + return (temp_c >= bat_temp_ranges.discharging_min_c && + temp_c < bat_temp_ranges.discharging_max_c); } /* diff --git a/common/smart_battery.c b/common/smart_battery.c index e0bc9c5e46..536959bd82 100644 --- a/common/smart_battery.c +++ b/common/smart_battery.c @@ -106,6 +106,27 @@ int battery_manufacturer_date(int *year, int *month, int *day) return EC_SUCCESS; } +/* Read manufacturer name */ +int battery_manufacturer_name(char *manufacturer_name, int buf_size) +{ + return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, + SB_MANUFACTURER_NAME, manufacturer_name, buf_size); +} + +/* Read device name */ +int battery_device_name(char *device_name, int buf_size) +{ + return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, + SB_DEVICE_NAME, device_name, buf_size); +} + +/* Read battery type/chemistry */ +int battery_device_chemistry(char *device_chemistry, int buf_size) +{ + return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, + SB_DEVICE_CHEMISTRY, device_chemistry, buf_size); +} + /*****************************************************************************/ /* Console commands */ |