Skip to content

Commit 9361a4a

Browse files
kiram9Terrails
authored andcommitted
fwk: move battery extender to use common
rewrite our timer based extender functionality to use common battery extender functionality as upstream. BRANCH=marigold BUG=https://app.clickup.com/t/86eq06zen TEST=When the timer expired the battery SOC will be lowered to 90-95% for stage 1, and 85-87 for stage 2. The battery extender will be reset after going off AC for 30 minutes. toggling enable/disable will reactivate the timers -get the charge state and battery extender setting chgstate battextender - set the deadline timer values sometime in the future. battextender timeext 15 s battextender timeext2 20 s battextender timerst 20 s - set the reload values for trigger and reset battextender trigger 60 s battextender reset 30 s battextender enable battextender disable Signed-off-by: Kieran Levin <[email protected]>
1 parent d3de3b6 commit 9361a4a

File tree

4 files changed

+209
-240
lines changed

4 files changed

+209
-240
lines changed

common/charge_state.c

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -207,12 +207,19 @@ void reset_prev_disp_charge(void)
207207
prev_disp_charge = -1;
208208
}
209209

210-
static int battery_sustainer_set(int8_t lower, int8_t upper)
210+
static bool battery_sustainer_enabled(void)
211+
{
212+
return sustain_soc.lower != -1 && sustain_soc.upper != -1;
213+
}
214+
215+
int battery_sustainer_set(int8_t lower, int8_t upper)
211216
{
212217
if (lower == -1 || upper == -1) {
213-
CPRINTS("Sustainer disabled");
214-
sustain_soc.lower = -1;
215-
sustain_soc.upper = -1;
218+
if (battery_sustainer_enabled()) {
219+
CPRINTS("Sustainer disabled");
220+
sustain_soc.lower = -1;
221+
sustain_soc.upper = -1;
222+
}
216223
return EC_SUCCESS;
217224
}
218225

@@ -235,14 +242,9 @@ static void battery_sustainer_disable(void)
235242
battery_sustainer_set(-1, -1);
236243
}
237244

238-
static bool battery_sustainer_enabled(void)
239-
{
240-
return sustain_soc.lower != -1 && sustain_soc.upper != -1;
241-
}
242-
243245
static const char *const state_list[] = { "idle", "discharge", "charge",
244246
"precharge" };
245-
BUILD_ASSERT(ARRAY_SIZE(state_list) == NUM_STATES_V2);
247+
BUILD_ASSERT(ARRAY_SIZE(state_list) == CHARGE_STATE_COUNT);
246248
static const char *const batt_pres[] = {
247249
"NO",
248250
"YES",
@@ -479,12 +481,6 @@ int charge_request(bool use_curr, bool is_full)
479481
#endif
480482
}
481483

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-
488484
if (curr.ac) {
489485
if (prev_volt != voltage || prev_curr != current)
490486
CPRINTS("%s(%dmV, %dmA)", __func__, voltage, current);
@@ -1646,15 +1642,6 @@ void charger_task(void *u)
16461642

16471643
prev_full = is_full;
16481644

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-
16581645
adjust_requested_vi(info, is_full);
16591646

16601647
process_preferred_voltage();

include/charge_state.h

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -429,23 +429,20 @@ int board_should_charger_bypass(void);
429429
int board_want_charger_change_mode(void);
430430
#endif
431431

432-
/* Config Charger */
433-
#include "charge_state.h"
434-
435-
#ifdef CONFIG_CUSTOMIZED_DESIGN
436432
/**
437-
* Callback for boards to return voltage value.
433+
* Set the battery sustainer mode.
438434
*
439-
* @param voltage battery maximum voltage
440-
* @return battery extender stage voltage (stage1: 97% * voltage; stage2: 96% * voltage).
435+
* @param lower: lower battery soc charge limit [1-100%] or -1 to disable
436+
* @param upper: upper battery soc charge limit [1-100%] or -1 to disable
437+
*
438+
* @return EC_SUCCESS or EC_ERROR_INVAL
441439
*/
442-
int battery_extender_stage_voltage(uint16_t voltage);
440+
int battery_sustainer_set(int8_t lower, int8_t upper);
443441

444-
/**
445-
* Callback for boards to count the battery extender timer.
446-
*/
447-
void battery_extender(void);
442+
/* Config Charger */
443+
#include "charge_state.h"
448444

445+
#ifdef CONFIG_CUSTOMIZED_DESIGN
449446
void battery_customize(struct charge_state_data *curr_batt);
450447
#endif
451448

zephyr/program/framework/include/board_host_command.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -438,16 +438,19 @@ struct ec_response_get_cutoff_status {
438438

439439
struct ec_params_battery_extender {
440440
uint8_t disable;
441-
uint8_t days;
442-
uint16_t minutes;
441+
uint8_t trigger_days;
442+
uint16_t reset_minutes;
443443
uint8_t cmd;
444444
uint8_t manual;
445445
} __ec_align1;
446446

447447
struct ec_response_battery_extender {
448448
uint8_t current_stage;
449-
uint16_t days;
450-
uint16_t minutes;
449+
uint16_t trigger_days;
450+
uint16_t reset_minutes;
451+
uint8_t disable;
452+
uint64_t trigger_timedelta;
453+
uint64_t reset_timedelta;
451454
} __ec_align1;
452455

453456
enum battery_extender_cmd {

0 commit comments

Comments
 (0)