mirror of
https://github.com/torvalds/linux.git
synced 2026-09-22 12:44:03 +02:00
Power Supply Fixes for 7.2 cycle
* Documentation build fix for bd71828 * max17040: handle missing status supplier * macsmc: Support macOS 27 SMC firmware * bq25890: fix the -10 C NTC lookup entry -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEE72YNB0Y/i3JqeVQT2O7X88g7+poFAmpr0SAACgkQ2O7X88g7 +prOoRAAgASEjdh5CoNT1PKA7rY8ER+u8mPaO4cQlPIzYC9Hw9S4H3E4/TKcm7DW fd7+w9cdLPrS3rRT/vqoofuIcdhtj0v9A6vd1lHi29njfwvj0DNvMu5Y1AludvOj P5rpSfgBM0pwMh/N58Y7alDnTy7q7v/ODA5MzsGGQy2MRPgWskozZdluuKL0C1ii vh+GWY2ua7CVKRLeH4IilVWWIzzLh2Fb0k1+FzgX+liOwmEvS56KQ3KOh0HXFxXX PTCD83WYIujuO9Sg7zQMm0uuxKXqXMhbtMjGsEdDPlHfc63ozYmycBdcev2pI7zL ERY0rkQ907y+9mRf7/EunLn8J2EUPd+Ilk5zQydgSFFpuz8/KXkRnwBds61Sl8KY n0WeF/r1UIgPikrCMnLWoEKqOYlm9MH+5OY6Aw49593eOR1D1Youc/GIUTILkjwV lyLcEkbJvF9I8eq4MPE4kJlX+lfEOM2Y+9UxU/ljGZneO37UGvPz6mAZAjSsdxlK qECboK4XRU6ZQmLJjFgV6sXMzxeRSXmzNRUIOSW6jdnnX/PLgKPUTZVJiKVEMcUJ yd3z8l7RsQSYLwpk09aaXFJbzadVqUFk4rvs4gtJETWVjbhS74fqlg443eTxQPRW AGVhDsLA/bD34YyEe5D4FBFIIgJp9Y+CXr7oboCzLDCsYEjopMU= =avMt -----END PGP SIGNATURE----- Merge tag 'for-v7.2-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply fixes from Sebastian Reichel: - Documentation build fix for bd71828 - max17040: handle missing status supplier - macsmc: Support macOS 27 SMC firmware - bq25890: fix the -10 C NTC lookup entry * tag 'for-v7.2-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: power: supply: bq25890: fix the -10 C NTC lookup entry power: supply: macsmc: Support macOS 27 SMC firmware power: supply: max17040: handle missing status supplier power: supply: bd71828: add a terminating table border
This commit is contained in:
commit
a11f030c83
|
|
@ -10,3 +10,4 @@ Description:
|
|||
0 no adjustment of input current limit. This
|
||||
helps for more unusual power sources like
|
||||
solar modules.
|
||||
============ ===========================================
|
||||
|
|
|
|||
|
|
@ -320,7 +320,7 @@ static const u32 bq25890_tspct_tbl[] = {
|
|||
145, 140, 130, 120, 115, 110, 100, 90,
|
||||
80, 70, 60, 50, 40, 30, 20, 10,
|
||||
0, -10, -20, -30, -40, -60, -70, -80,
|
||||
-90, -10, -120, -140, -150, -170, -190, -210,
|
||||
-90, -100, -120, -140, -150, -170, -190, -210,
|
||||
};
|
||||
|
||||
#define BQ25890_TSPCT_TBL_SIZE ARRAY_SIZE(bq25890_tspct_tbl)
|
||||
|
|
|
|||
|
|
@ -86,6 +86,11 @@ struct macsmc_power {
|
|||
bool has_ch0i; /* Force discharge (Older firmware) */
|
||||
bool has_ch0c; /* Inhibit charge (Older firmware) */
|
||||
bool has_chte; /* Inhibit charge (Modern firmware) */
|
||||
/*
|
||||
* Battery critical key is 1 byte and charge key is little endian
|
||||
* (Modern firmware)
|
||||
*/
|
||||
bool fw_ge_27;
|
||||
|
||||
u8 num_cells;
|
||||
int nominal_voltage_mv;
|
||||
|
|
@ -273,6 +278,20 @@ static int macsmc_battery_get_date(const char *s, int *out)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int macsmc_battery_read_bcf0(struct macsmc_power *power, u32 *val)
|
||||
{
|
||||
u8 tval = 0;
|
||||
int ret;
|
||||
|
||||
if (power->fw_ge_27) {
|
||||
ret = apple_smc_read_u8(power->smc, SMC_KEY(BCF0), &tval);
|
||||
*val = tval;
|
||||
return ret;
|
||||
}
|
||||
|
||||
return apple_smc_read_u32(power->smc, SMC_KEY(BCF0), val);
|
||||
}
|
||||
|
||||
static int macsmc_battery_get_capacity_level(struct macsmc_power *power)
|
||||
{
|
||||
bool flag;
|
||||
|
|
@ -280,7 +299,7 @@ static int macsmc_battery_get_capacity_level(struct macsmc_power *power)
|
|||
int ret;
|
||||
|
||||
/* Check for emergency shutdown condition */
|
||||
if (apple_smc_read_u32(power->smc, SMC_KEY(BCF0), &val) >= 0 && val)
|
||||
if (macsmc_battery_read_bcf0(power, &val) >= 0 && val)
|
||||
return POWER_SUPPLY_CAPACITY_LEVEL_CRITICAL;
|
||||
|
||||
/* Check AC status for whether we could boot in this state */
|
||||
|
|
@ -303,6 +322,12 @@ static int macsmc_battery_get_capacity_level(struct macsmc_power *power)
|
|||
return POWER_SUPPLY_CAPACITY_LEVEL_NORMAL;
|
||||
}
|
||||
|
||||
static s16 macsmc_swap_b0rm(struct macsmc_power *power, s16 b0rm)
|
||||
{
|
||||
/* B0RM was Big Endian, likely pass through from TI gas gauge */
|
||||
return power->fw_ge_27 ? b0rm : (s16)swab16(b0rm);
|
||||
}
|
||||
|
||||
static int macsmc_battery_get_property(struct power_supply *psy,
|
||||
enum power_supply_property psp,
|
||||
union power_supply_propval *val)
|
||||
|
|
@ -397,8 +422,7 @@ static int macsmc_battery_get_property(struct power_supply *psy,
|
|||
break;
|
||||
case POWER_SUPPLY_PROP_CHARGE_NOW:
|
||||
ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RM), &vu16);
|
||||
/* B0RM is Big Endian, likely pass through from TI gas gauge */
|
||||
val->intval = (s16)swab16(vu16) * 1000;
|
||||
val->intval = macsmc_swap_b0rm(power, vu16) * 1000;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN:
|
||||
ret = apple_smc_read_u16(power->smc, SMC_KEY(B0DC), &vu16);
|
||||
|
|
@ -410,8 +434,7 @@ static int macsmc_battery_get_property(struct power_supply *psy,
|
|||
break;
|
||||
case POWER_SUPPLY_PROP_ENERGY_NOW:
|
||||
ret = apple_smc_read_u16(power->smc, SMC_KEY(B0RM), &vu16);
|
||||
/* B0RM is Big Endian, likely pass through from TI gas gauge */
|
||||
val->intval = (s16)swab16(vu16) * power->nominal_voltage_mv;
|
||||
val->intval = macsmc_swap_b0rm(power, vu16) * power->nominal_voltage_mv;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_TEMP:
|
||||
ret = apple_smc_read_u16(power->smc, SMC_KEY(B0AT), &vu16);
|
||||
|
|
@ -577,7 +600,7 @@ static void macsmc_power_critical_work(struct work_struct *wrk)
|
|||
* Check if SMC flagged the battery as empty.
|
||||
* We trigger a graceful shutdown to let the OS save data.
|
||||
*/
|
||||
if (apple_smc_read_u32(power->smc, SMC_KEY(BCF0), &bcf0) == 0 && bcf0 != 0) {
|
||||
if (macsmc_battery_read_bcf0(power, &bcf0) == 0 && bcf0 != 0) {
|
||||
power->orderly_shutdown_triggered = true;
|
||||
dev_crit(power->dev, "Battery critical (empty flag set). Triggering orderly shutdown.\n");
|
||||
orderly_poweroff(true);
|
||||
|
|
@ -616,6 +639,7 @@ static int macsmc_power_probe(struct platform_device *pdev)
|
|||
struct device *dev = &pdev->dev;
|
||||
struct apple_smc *smc = dev_get_drvdata(pdev->dev.parent);
|
||||
struct power_supply_config psy_cfg = {};
|
||||
struct apple_smc_key_info info;
|
||||
struct macsmc_power *power;
|
||||
bool has_battery = false;
|
||||
bool has_ac_adapter = false;
|
||||
|
|
@ -714,6 +738,20 @@ static int macsmc_power_probe(struct platform_device *pdev)
|
|||
if (apple_smc_key_exists(smc, SMC_KEY(CH0I)))
|
||||
power->has_ch0i = true;
|
||||
|
||||
ret = apple_smc_get_key_info(power->smc, SMC_KEY(BCF0), &info);
|
||||
if (ret) {
|
||||
dev_err(&pdev->dev, "Failed to determine BCF0 key size\n");
|
||||
return ret;
|
||||
}
|
||||
if (info.size == 1)
|
||||
power->fw_ge_27 = true;
|
||||
else if (info.size == 4)
|
||||
power->fw_ge_27 = false;
|
||||
else {
|
||||
dev_err(&pdev->dev, "Unexpected BCF0 key size %d\n", info.size);
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Reset "Optimised Battery Charging" flags to default state */
|
||||
if (power->has_chte)
|
||||
apple_smc_write_u32(smc, SMC_KEY(CHTE), 0);
|
||||
|
|
@ -766,7 +804,7 @@ static int macsmc_power_probe(struct platform_device *pdev)
|
|||
power->nominal_voltage_mv = MACSMC_NOMINAL_CELL_VOLTAGE_MV * power->num_cells;
|
||||
|
||||
/* Enable critical shutdown notifications by reading status once */
|
||||
apple_smc_read_u32(power->smc, SMC_KEY(BCF0), &val32);
|
||||
macsmc_battery_read_bcf0(power, &val32);
|
||||
|
||||
psy_cfg.drv_data = power;
|
||||
power->batt = devm_power_supply_register(dev, &power->batt_desc, &psy_cfg);
|
||||
|
|
|
|||
|
|
@ -405,7 +405,11 @@ static int max17040_get_property(struct power_supply *psy,
|
|||
val->intval = chip->low_soc_alert;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_STATUS:
|
||||
power_supply_get_property_from_supplier(psy, psp, val);
|
||||
ret = power_supply_get_property_from_supplier(psy, psp, val);
|
||||
if (ret == -ENODEV)
|
||||
val->intval = POWER_SUPPLY_STATUS_UNKNOWN;
|
||||
else if (ret)
|
||||
return ret;
|
||||
break;
|
||||
case POWER_SUPPLY_PROP_TEMP:
|
||||
if (!chip->channel_temp)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user