Skip to content

Commit 4bf83d9

Browse files
committed
power: supply: macsmc_power: Report not charging for CHLS thresholds
If a CHLS charge threshold is configured and the current SoC is above the start threshold report a busy BMS as not charging. Signed-off-by: Janne Grunau <j@jannau.net>
1 parent d82cb3e commit 4bf83d9

1 file changed

Lines changed: 19 additions & 8 deletions

File tree

drivers/power/supply/macsmc_power.c

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ static int macsmc_battery_get_status(struct macsmc_power *power)
132132
u64 nocharge_flags;
133133
u32 nopower_flags;
134134
u16 ac_current;
135-
bool chwa_limit = false;
135+
int charge_limit = 0;
136+
bool limited = false;
136137
int ret;
137138

138139
/*
@@ -180,15 +181,25 @@ static int macsmc_battery_get_status(struct macsmc_power *power)
180181
return POWER_SUPPLY_STATUS_FULL;
181182

182183
/*
183-
* If we have charge limits supported and enabled and the SoC is > 75%,
184-
* that means we are not charging for that reason (if not charging).
184+
* If we have charge limits supported and enabled and the SoC is above
185+
* the start threshold, that means we are not charging for that reason
186+
* (if not charging).
185187
*/
186-
if (power->has_chwa && apple_smc_read_flag(power->smc, SMC_KEY(CHWA)) == 1) {
187-
u8 buic = 0;
188+
if (power->has_chls) {
189+
u16 vu16;
190+
ret = apple_smc_read_u16(power->smc, SMC_KEY(CHLS), &vu16);
191+
if (ret == sizeof(vu16) && (vu16 & 0xff) >= CHLS_MIN_END_THRESHOLD)
192+
charge_limit = (vu16 & 0xff) - CHWA_CHLS_FIXED_START_OFFSET;
193+
} else if (power->has_chwa &&
194+
apple_smc_read_flag(power->smc, SMC_KEY(CHWA)) == 1) {
195+
charge_limit = CHWA_FIXED_END_THRESHOLD - CHWA_CHLS_FIXED_START_OFFSET;
196+
}
188197

198+
if (charge_limit > 0) {
199+
u8 buic = 0;
189200
if (apple_smc_read_u8(power->smc, SMC_KEY(BUIC), &buic) >= 0 &&
190-
buic >= (CHWA_FIXED_END_THRESHOLD - CHWA_CHLS_FIXED_START_OFFSET))
191-
chwa_limit = true;
201+
buic >= charge_limit)
202+
limited = true;
192203
}
193204

194205
/* If there are reasons we aren't charging... */
@@ -201,7 +212,7 @@ static int macsmc_battery_get_status(struct macsmc_power *power)
201212
* Or maybe the BMS is just busy doing something, if so call it charging anyway.
202213
* But CHWA limits show up as this, so exclude those.
203214
*/
204-
else if (nocharge_flags == CHNC_BMS_BUSY && !chwa_limit)
215+
else if (nocharge_flags == CHNC_BMS_BUSY && !limited)
205216
return POWER_SUPPLY_STATUS_CHARGING;
206217
/* If we have other reasons we aren't charging, say we aren't */
207218
else if (nocharge_flags)

0 commit comments

Comments
 (0)