nyan: add info_precharge for drained battery

Charger v2 assumes the battery_get_info() always returns non-NULL even
if the battery is not detected, for example, in the over-drained
situation. Thus, add a new struct so that we know what the conservative
setting is to pre-charge the unknown battery.

BUG=chrome-os-partner:28112
BRANCH=nyan,big,blaze
TEST=See issue tracker for the test procedure.

Change-Id: Ica4fe75d154e2f195eb1da19ba045346da383b6c
Signed-off-by: Louis Yung-Chieh Lo <yjlou@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/195596
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Reviewed-by: Devin Lu <Devin.Lu@quantatw.com>
Tested-by: Devin Lu <Devin.Lu@quantatw.com>
This commit is contained in:
Louis Yung-Chieh Lo
2014-04-18 12:59:57 -07:00
committed by chrome-internal-fetch
parent 4b530d9fce
commit 67698db7da
4 changed files with 107 additions and 15 deletions

View File

@@ -30,6 +30,29 @@ struct battery_device {
int support_cut_off;
};
/*
* Used for the case that battery cannot be detected, such as the pre-charge
* case. In this case, we need to provide the battery with the enough voltage
* (usually the highest voltage among batteries, but the smallest precharge
* current). This should be as conservative as possible.
*/
static struct battery_info info_precharge = {
.voltage_max = 12900, /* the max voltage among batteries */
.voltage_normal = 11400,
.voltage_min = 9000,
/* Pre-charge values. */
.precharge_current = 256, /* mA, the min current among batteries */
.start_charging_min_c = 0,
.start_charging_max_c = 50,
.charging_min_c = 0,
.charging_max_c = 60,
.discharging_min_c = 0,
.discharging_max_c = 75,
};
static struct battery_info info_2s = {
/*
* Design voltage
@@ -252,16 +275,16 @@ const struct battery_info *battery_get_info(void)
if (battery_manufacturer_name(manuf, sizeof(manuf))) {
CPRINTF("[%T Failed to get MANUF name]\n");
return NULL;
return &info_precharge;
}
if (battery_device_name(device, sizeof(device))) {
CPRINTF("[%T Failed to get DEVICE name]\n");
return NULL;
return &info_precharge;
}
if (battery_design_voltage((int *)&design_mv)) {
CPRINTF("[%T Failed to get DESIGN_VOLTAGE]\n");
return NULL;
return &info_precharge;
}
for (i = 0; i < ARRAY_SIZE(support_batteries); ++i) {
@@ -276,7 +299,9 @@ const struct battery_info *battery_get_info(void)
}
}
return NULL;
CPRINTF("[%T un-recognized battery Manuf:%s, Device:%s]\n",
manuf, device);
return &info_precharge;
}
int battery_command_cut_off(struct host_cmd_handler_args *args)

View File

@@ -29,6 +29,30 @@ struct battery_device {
int support_cut_off;
};
/*
* Used for the case that battery cannot be detected, such as the pre-charge
* case. In this case, we need to provide the battery with the enough voltage
* (usually the highest voltage among batteries, but the smallest precharge
* current). This should be as conservative as possible.
*/
static struct battery_info info_precharge = {
.voltage_max = 13050, /* the max voltage among batteries */
.voltage_normal = 11400,
.voltage_min = 9000,
/* Pre-charge values. */
.precharge_current = 392, /* mA, the min current among batteries */
.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 = 60,
};
static struct battery_info info_3s = {
.voltage_max = 13050,
@@ -176,16 +200,16 @@ const struct battery_info *battery_get_info(void)
if (battery_manufacturer_name(manuf, sizeof(manuf))) {
CPRINTF("[%T Failed to get MANUF name]\n");
return NULL;
return &info_precharge;
}
if (battery_device_name(device, sizeof(device))) {
CPRINTF("[%T Failed to get DEVICE name]\n");
return NULL;
return &info_precharge;
}
if (battery_design_voltage((int *)&design_mv)) {
CPRINTF("[%T Failed to get DESIGN_VOLTAGE]\n");
return NULL;
return &info_precharge;
}
for (i = 0; i < ARRAY_SIZE(support_batteries); ++i) {
@@ -200,7 +224,9 @@ const struct battery_info *battery_get_info(void)
}
}
return NULL;
CPRINTF("[%T un-recognized battery Manuf:%s, Device:%s]\n",
manuf, device);
return &info_precharge;
}
static int cutoff(void)

View File

@@ -30,6 +30,39 @@ struct battery_device {
int support_cut_off;
};
/*
* Used for the case that battery cannot be detected, such as the pre-charge
* case. In this case, we need to provide the battery with the enough voltage
* (usually the highest voltage among batteries, but the smallest precharge
* current). This should be as conservative as possible.
*/
static struct battery_info info_precharge = {
/*
* Design voltage
* max = 8.4V
* normal = 7.4V
* min = 6.0V
*/
.voltage_max = 12600, /* the max voltage among batteries */
.voltage_normal = 11100,
.voltage_min = 9000,
/* Pre-charge current: I <= 0.01C */
.precharge_current = 64, /* mA, the min current among batteries */
/*
* 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 = 0,
.discharging_max_c = 60,
};
static struct battery_info info_2s = {
/*
* Design voltage
@@ -204,16 +237,16 @@ const struct battery_info *battery_get_info(void)
if (battery_manufacturer_name(manuf, sizeof(manuf))) {
CPRINTF("[%T Failed to get MANUF name]\n");
return NULL;
return &info_precharge;
}
if (battery_device_name(device, sizeof(device))) {
CPRINTF("[%T Failed to get DEVICE name]\n");
return NULL;
return &info_precharge;
}
if (battery_design_voltage((int *)&design_mv)) {
CPRINTF("[%T Failed to get DESIGN_VOLTAGE]\n");
return NULL;
return &info_precharge;
}
for (i = 0; i < ARRAY_SIZE(support_batteries); ++i) {
@@ -228,7 +261,9 @@ const struct battery_info *battery_get_info(void)
}
}
return NULL;
CPRINTF("[%T un-recognized battery Manuf:%s, Device=%s]\n",
manuf, device);
return &info_precharge;
}
int battery_command_cut_off(struct host_cmd_handler_args *args)

View File

@@ -284,12 +284,12 @@ static int charge_request(int voltage, int current)
CPRINTF("[%T %s(%dmV, %dmA)]\n", __func__, voltage, current);
if (voltage > 0)
if (voltage >= 0)
r1 = charger_set_voltage(voltage);
if (r1 != EC_SUCCESS)
problem(PR_SET_VOLTAGE, r1);
if (current > 0)
if (current >= 0)
r2 = charger_set_current(current);
if (r2 != EC_SUCCESS)
problem(PR_SET_CURRENT, r2);
@@ -538,8 +538,14 @@ void charger_task(void)
} else {
/* The battery is responding. Yay. Try to use it. */
if (curr.state == ST_PRECHARGE ||
battery_seems_to_be_dead)
battery_seems_to_be_dead) {
ccprintf("[%T battery woke up]\n");
/* Update the battery-specific values */
batt_info = battery_get_info();
need_static = 1;
}
battery_seems_to_be_dead = 0;
curr.state = ST_CHARGE;
}