Skip to content

Commit 73f1196

Browse files
LeoCX-Tsaikiram9
authored andcommitted
fwk: implement the battery extender feature
cherry pick Google CLs for battery exceeded list: [Update EC_CMD_CHARGE_CONTROL to version 2](https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929340) [chgstv2: Add unit test for battery sustainer](https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2987734/4) [chgstv2: Add battery sustainer](https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2929347) [chgstv2: Refactor charger_discharge_on_ac](https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2986848) manual add CLs [charge_state: Add EC_CMD_CHARGE_CONTROL V3](https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/4824703) fwk CLs: [fwk: override the display charge value for Windows system](FrameworkComputer/ec#1042) The purpose of this function is to automatically drop the battery max charge voltage if the system is left plugged into AC for a long time to preserve battery life. When the timer is exceeded the battery charge voltage should be reduced to 4.35V/cell. Two additional days after the timer has exceeded, the battery charge voltage shall be reduced to 4.3V/cell. The timer should reset to 0 days any time the system is in S0/S0ix and not attached to AC for 30 minutes or longer. BRANCH=fwk-hx20-hx30-4410 BUG=https://app.clickup.com/t/86eq06zen TEST=zmake build hx30 pass TEST=trigger extender timer check chg ctl mode is discharge(2) battery also has discharge after battery percentage trace to upper value chg ctl mode change to IDLE Signed-off-by: LeoCX_Tsai <[email protected]>
1 parent b8d7b29 commit 73f1196

11 files changed

+509
-42
lines changed

baseboard/fwk/baseboard.h

+1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
#ifndef __CROS_EC_BASEBOARD_H
99
#define __CROS_EC_BASEBOARD_H
1010

11+
uint32_t get_system_percentage(void);
1112

1213
#endif /* __CROS_EC_BASEBOARD_H */

baseboard/fwk/baseboard_host_commands.h

+28
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,32 @@ struct ec_response_privacy_switches_check {
1515
uint8_t camera;
1616
} __ec_align1;
1717

18+
/*****************************************************************************/
19+
/*
20+
* Battery extender control
21+
*/
22+
#define EC_CMD_BATTERY_EXTENDER 0x3E24
23+
24+
struct ec_params_battery_extender {
25+
uint8_t disable;
26+
uint8_t trigger_days;
27+
uint16_t reset_minutes;
28+
uint8_t cmd;
29+
uint8_t manual;
30+
} __ec_align1;
31+
32+
struct ec_response_battery_extender {
33+
uint8_t current_stage;
34+
uint16_t trigger_days;
35+
uint16_t reset_minutes;
36+
uint8_t disable;
37+
uint64_t trigger_timedelta;
38+
uint64_t reset_timedelta;
39+
} __ec_align1;
40+
41+
enum battery_extender_cmd {
42+
BATT_EXTENDER_WRITE_CMD,
43+
BATT_EXTENDER_READ_CMD,
44+
};
45+
1846
#endif /* __BASEBOARD_HOST_COMMANDS_H */

baseboard/fwk/battery.c

+36-5
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,21 @@ enum battery_present battery_is_present(void)
212212
return batt_pres;
213213
}
214214

215+
uint32_t get_system_percentage(void)
216+
{
217+
static uint32_t pre_os_percentage;
218+
uint32_t memmap_cap = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_CAP);
219+
uint32_t memmap_lfcc = *(uint32_t *)host_get_memmap(EC_MEMMAP_BATT_LFCC);
220+
uint32_t os_percentage = 1000 * memmap_cap / (memmap_lfcc + 1);
221+
222+
/* ensure this value is valid */
223+
if (os_percentage <= 1000 && os_percentage >= 0) {
224+
pre_os_percentage = os_percentage;
225+
return os_percentage;
226+
} else
227+
return pre_os_percentage;
228+
}
229+
215230
#ifdef CONFIG_EMI_REGION1
216231

217232
void battery_customize(struct charge_state_data *emi_info)
@@ -248,7 +263,7 @@ void battery_customize(struct charge_state_data *emi_info)
248263

249264
*host_get_customer_memmap(EC_MEMMAP_ER1_BATT_AVER_TEMP) =
250265
(emi_info->batt.temperature - 2731)/10;
251-
*host_get_customer_memmap(EC_MEMMAP_ER1_BATT_PERCENTAGE) = emi_info->batt.display_charge/10;
266+
*host_get_customer_memmap(EC_MEMMAP_ER1_BATT_PERCENTAGE) = get_system_percentage() / 10;
252267

253268
if (emi_info->batt.status & STATUS_FULLY_CHARGED)
254269
*host_get_customer_memmap(EC_MEMMAP_ER1_BATT_STATUS) |= EC_BATT_FLAG_FULL;
@@ -314,24 +329,37 @@ void battery_customize(struct charge_state_data *emi_info)
314329
static void battery_percentage_control(void)
315330
{
316331
enum ec_charge_control_mode new_mode;
332+
static int in_percentage_control;
333+
uint32_t batt_os_percentage = get_system_percentage();
317334
int rv;
318335

336+
/**
337+
* If the host command EC_CMD_CHARGE_CONTROL set control mode to CHARGE_CONTROL_DISCHARGE
338+
* or CHARGE_CONTROL_IDLE, ignore the battery_percentage_control();
339+
*/
340+
if (!in_percentage_control && get_chg_ctrl_mode() != CHARGE_CONTROL_NORMAL)
341+
return;
319342

320343
if (charging_maximum_level == NEED_RESTORE)
321344
system_get_bbram(SYSTEM_BBRAM_IDX_CHG_MAX, &charging_maximum_level);
322345

323346
if (charging_maximum_level & CHG_LIMIT_OVERRIDE) {
324347
new_mode = CHARGE_CONTROL_NORMAL;
325-
if (charge_get_percent() == 100)
348+
if (batt_os_percentage == 1000)
326349
charging_maximum_level = charging_maximum_level | 0x64;
327350
} else if (charging_maximum_level < 20)
328351
new_mode = CHARGE_CONTROL_NORMAL;
329-
else if (charge_get_percent() > charging_maximum_level)
352+
else if (batt_os_percentage > charging_maximum_level * 10) {
330353
new_mode = CHARGE_CONTROL_DISCHARGE;
331-
else if (charge_get_percent() == charging_maximum_level)
354+
in_percentage_control = 1;
355+
} else if (batt_os_percentage == charging_maximum_level * 10) {
332356
new_mode = CHARGE_CONTROL_IDLE;
333-
else
357+
in_percentage_control = 1;
358+
} else {
334359
new_mode = CHARGE_CONTROL_NORMAL;
360+
in_percentage_control = 0;
361+
}
362+
335363

336364
ccprints("Charge Limit mode = %d", new_mode);
337365

@@ -445,6 +473,9 @@ __override void board_battery_compensate_params(struct batt_params *batt)
445473
batt->flags &= ~BATT_FLAG_BAD_ANY;
446474
batt->flags |= BATT_FLAG_RESPONSIVE;
447475
batt_cache.flags |= BATT_FLAG_RESPONSIVE;
476+
477+
/* override the display charge value for Windows system */
478+
batt->display_charge = get_system_percentage();
448479
}
449480

450481
/*****************************************************************************/

0 commit comments

Comments
 (0)