Skip to content

Commit c280451

Browse files
LeoCX-Tsaiquinchou77
authored andcommitted
fwk: implement Battery Charge Limiting battery status
In the ACPI spec _BST(battery status) has a feature 3.9.6 Battery Charge Limiting follows the spec to implement the behavior. This way the operating system can tell that the battery is not charging anymore because it has reached the configured charge state limit. Windows recognizes this and calls it smart charging: https://support.microsoft.com/en-us/windows/use-smart-charging-in-windows-2ac1b4ba-6027-410a-b80e-f6767d867002 Linux has also added support: torvalds/linux@526294e Previously our ACPI code would mask off this bit, so to use this EC change, the BIOS has to be updated not to mask this bit. BRANCH=fwk-main BUG=https://app.clickup.com/t/86et2u0ve (Question 3) TEST= test on azalea, setting charger limit to 80% and Limiting has reached the steady state (CHG state = idle), check namespec 0x4c Bit7(Limit active) is 1, bit2(discharging) and bit3(charging) is 0. TEST= test on azalea, setting charger limit to 80% and battery has discharging(higher than 80%) check namespec 0x4c Bit7(Limit active) and bit2(discharging is 1, and bit3(charging) is 0. TEST= test on azalea, setting charger limit to 80% and battery has charging(lower than 80%) check namespec 0x4c Bit7(Limit active) and bit3(charging is 1, and bit2(discharging) is 0. TEST= test on azalea, disable charger limit and batt extender, check namespec 0x4c Bit7(Limit active) is 0. Signed-off-by: LeoCX_Tsai <[email protected]> (cherry picked from commit f82e3ffef8bcb5b233f17170f348981289fffc23)
1 parent 457ac14 commit c280451

File tree

4 files changed

+27
-1
lines changed

4 files changed

+27
-1
lines changed

common/battery_v2.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,23 @@ void update_dynamic_battery_info(void)
481481
tmp |= curr->batt_is_charging ? EC_BATT_FLAG_CHARGING :
482482
EC_BATT_FLAG_DISCHARGING;
483483
}
484+
485+
/*
486+
* in ACPI spec _BST(battery status) have a feature
487+
* 3.9.6 Battery Charge Limiting follows the spec
488+
* to return limiting status to OS and if Limiting is engaged
489+
* and the battery has reached the steady state need to
490+
* clear CHARGING and DISCHARGING flag.
491+
*/
492+
if (battery_sustainer_enabled()) {
493+
tmp |= EC_BATT_FLAG_LIMIT_ACTIVE;
494+
if (get_chg_ctrl_mode() == CHARGE_CONTROL_IDLE) {
495+
tmp &= ~EC_BATT_FLAG_CHARGING;
496+
tmp &= ~EC_BATT_FLAG_DISCHARGING;
497+
}
498+
} else
499+
tmp &= ~EC_BATT_FLAG_LIMIT_ACTIVE;
500+
484501
#else
485502
tmp |= curr->batt_is_charging ? EC_BATT_FLAG_CHARGING :
486503
EC_BATT_FLAG_DISCHARGING;

common/charge_state.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ void reset_prev_disp_charge(void)
193193
prev_disp_charge = -1;
194194
}
195195

196-
test_export_static bool battery_sustainer_enabled(void)
196+
bool battery_sustainer_enabled(void)
197197
{
198198
return sustain_soc.lower != -1 && sustain_soc.upper != -1;
199199
}

include/charge_state.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,14 @@ int board_want_charger_change_mode(void);
399399
*/
400400
int battery_sustainer_set(int8_t lower, int8_t upper);
401401

402+
/**
403+
* return the sustainer is active or not
404+
* lower and upper == -1 is mean disable
405+
*
406+
* @return if sustain_soc.lower and sustain_soc.upper != -1 will be true
407+
*/
408+
bool battery_sustainer_enabled(void);
409+
402410
/* Config Charger */
403411
#include "charge_state.h"
404412

include/ec_commands.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ extern "C" {
271271
/* Set if some of the static/dynamic data is invalid (or outdated). */
272272
#define EC_BATT_FLAG_INVALID_DATA 0x20
273273
#define EC_BATT_FLAG_CUT_OFF 0x40
274+
#define EC_BATT_FLAG_LIMIT_ACTIVE 0x80
274275

275276
/* Switch flags at EC_MEMMAP_SWITCHES */
276277
#define EC_SWITCH_LID_OPEN 0x01

0 commit comments

Comments
 (0)