Skip to content

Commit 5424fdc

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 <josh_tsai@compal.com>
1 parent 27049f0 commit 5424fdc

5 files changed

Lines changed: 367 additions & 0 deletions

File tree

common/charge_state.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,12 @@ int charge_request(bool use_curr, bool is_full)
491491
#endif
492492
}
493493

494+
#ifdef CONFIG_CUSTOMIZED_DESIGN
495+
/* Override the voltage if the battery extender is on */
496+
if (battery_extender_stage_voltage(battery_get_info()->voltage_max))
497+
voltage = battery_extender_stage_voltage(battery_get_info()->voltage_max);
498+
#endif
499+
494500
if (curr.ac) {
495501
if (prev_volt != voltage || prev_curr != current)
496502
CPRINTS("%s(%dmV, %dmA)", __func__, voltage, current);
@@ -1713,6 +1719,15 @@ void charger_task(void *u)
17131719

17141720
prev_full = is_full;
17151721

1722+
#ifdef CONFIG_CUSTOMIZED_DESIGN
1723+
/**
1724+
* Run the battery extender function to check the timer,
1725+
* if the timer expired, will override the voltage in the
1726+
* charge_request() function.
1727+
*/
1728+
battery_extender();
1729+
#endif
1730+
17161731
adjust_requested_vi(info, is_full);
17171732

17181733
process_preferred_voltage();

include/charge_state.h

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

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

zephyr/program/framework/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ zephyr_library_sources_ifdef(CONFIG_PD_CHIP_CCG6
3535
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_TOUCHPAD_CUSTOMIZED
3636
"src/ps2mouse.c")
3737

38+
zephyr_library_sources_ifdef(CONFIG_PLATFORM_EC_CHARGE_MANAGER
39+
"src/battery_extender.c")
40+
3841
if(DEFINED CONFIG_BOARD_LOTUS)
3942
project(lotus)
4043
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
@@ -535,4 +535,29 @@ struct ec_response_get_pd_port_state {
535535
uint8_t pd_alt_mode_status;
536536
} __ec_align1;
537537

538+
/*****************************************************************************/
539+
/*
540+
* Battery extender control
541+
*/
542+
#define EC_CMD_BATTERY_EXTENDER 0x3E24
543+
544+
struct ec_params_battery_extender {
545+
uint8_t disable;
546+
uint8_t days;
547+
uint16_t minutes;
548+
uint8_t cmd;
549+
uint8_t manual;
550+
} __ec_align1;
551+
552+
struct ec_response_battery_extender {
553+
uint8_t current_stage;
554+
uint16_t days;
555+
uint16_t minutes;
556+
} __ec_align1;
557+
558+
enum battery_extender_cmd {
559+
BATT_EXTENDER_WRITE_CMD,
560+
BATT_EXTENDER_READ_CMD,
561+
};
562+
538563
#endif /* __BOARD_HOST_COMMAND_H */

0 commit comments

Comments
 (0)