Skip to content

Commit 9b59e86

Browse files
Josh-Tsaikiram9
authored andcommitted
fwk: implement the battery extender feature
The purpose of this function is to automatically drop the battery max charge voltage if the system is left plugged in to 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=marigold BUG=https://app.clickup.com/t/86eq06zen TEST=when timer expired, the charge voltage will reduce to 97% and 96% battery maximum charge voltage TEST=charge voltage will recover when the user unplugs the adapter for 30 minutes when the system in S0/S0ix. Signed-off-by: Josh-Tsai <[email protected]>
1 parent 514710a commit 9b59e86

File tree

5 files changed

+367
-0
lines changed

5 files changed

+367
-0
lines changed

common/charge_state.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,12 @@ int charge_request(bool use_curr, bool is_full)
479479
#endif
480480
}
481481

482+
#ifdef CONFIG_CUSTOMIZED_DESIGN
483+
/* Override the voltage if the battery extender is on */
484+
if (battery_extender_stage_voltage(battery_get_info()->voltage_max))
485+
voltage = battery_extender_stage_voltage(battery_get_info()->voltage_max);
486+
#endif
487+
482488
if (curr.ac) {
483489
if (prev_volt != voltage || prev_curr != current)
484490
CPRINTS("%s(%dmV, %dmA)", __func__, voltage, current);
@@ -1640,6 +1646,15 @@ void charger_task(void *u)
16401646

16411647
prev_full = is_full;
16421648

1649+
#ifdef CONFIG_CUSTOMIZED_DESIGN
1650+
/**
1651+
* Run the battery extender function to check the timer,
1652+
* if the timer expired, will override the voltage in the
1653+
* charge_request() function.
1654+
*/
1655+
battery_extender();
1656+
#endif
1657+
16431658
adjust_requested_vi(info, is_full);
16441659

16451660
process_preferred_voltage();

include/charge_state.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,19 @@ int board_want_charger_change_mode(void);
433433
#include "charge_state.h"
434434

435435
#ifdef CONFIG_CUSTOMIZED_DESIGN
436+
/**
437+
* Callback for boards to return voltage value.
438+
*
439+
* @param voltage battery maximum voltage
440+
* @return battery extender stage voltage (stage1: 97% * voltage; stage2: 96% * voltage).
441+
*/
442+
int battery_extender_stage_voltage(uint16_t voltage);
443+
444+
/**
445+
* Callback for boards to count the battery extender timer.
446+
*/
447+
void battery_extender(void);
448+
436449
void battery_customize(struct charge_state_data *curr_batt);
437450
#endif
438451

zephyr/program/framework/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON
2323
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_LED_COMMON
2424
"src/led.c")
2525

26+
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGE_MANAGER
27+
"src/battery_extender.c")
28+
2629
if(DEFINED CONFIG_BOARD_LOTUS)
2730
project(lotus)
2831
cros_ec_library_include_directories_ifdef(CONFIG_BOARD_LOTUS include)

zephyr/program/framework/include/board_host_command.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,4 +430,29 @@ struct ec_response_get_cutoff_status {
430430
uint8_t status;
431431
} __ec_align1;
432432

433+
/*****************************************************************************/
434+
/*
435+
* Battery extender control
436+
*/
437+
#define EC_CMD_BATTERY_EXTENDER 0x3E24
438+
439+
struct ec_params_battery_extender {
440+
uint8_t disable;
441+
uint8_t days;
442+
uint16_t minutes;
443+
uint8_t cmd;
444+
uint8_t manual;
445+
} __ec_align1;
446+
447+
struct ec_response_battery_extender {
448+
uint8_t current_stage;
449+
uint16_t days;
450+
uint16_t minutes;
451+
} __ec_align1;
452+
453+
enum battery_extender_cmd {
454+
BATT_EXTENDER_WRITE_CMD,
455+
BATT_EXTENDER_READ_CMD,
456+
};
457+
433458
#endif /* __BOARD_HOST_COMMAND_H */

0 commit comments

Comments
 (0)