Skip to content

Commit 7d65ee4

Browse files
marcanjgouly
authored andcommitted
power: supply: macsmc_power: Driver for Apple SMC power/battery stats
This driver implements support for battery stats on top of the macsmc framework, to support Apple M1 Mac machines. power: supply: macsmc_power: Add cycle count and health props power: supply: macsmc_power: Add present prop power: supply: macsmc_power: Add more props, rework others power: supply: macsmc_power: Use BUIC instead of BRSC for charge power: supply: macsmc_power: Turn off OBC flags if macOS left them on power: supply: macsmc_power: Add AC power supply power: supply: macsmc_power: Add critical level shutdown & misc events power: supply: macsmc_power: Add CHWA charge thresholds This is a hardcoded charge threshold feature present in firmware 13.0 or newer. Userspace settings are rounded to one of the two possible behaviors. power: supply: macsmc_power: Report available charge_behaviours The generic handling if charge_behaviours in the power_supply core requires power_supply_desc.charge_behaviours to be set. power: supply: macsmc_power: Add more properties Report more voltages from the battery, and also fudge energy numbers from charge numbers. This way userspace doesn't try to convert on its own (and gets it very wrong). power: supply: macsmc_power: Add CHLS charge thresholds Since macOS Sequoia firmware, CHLS replaced CHWA and now allows an arbitrary end charge threshold to be configured. Prefer CHWA over CHLS since the SMC firmware from iBoot-10151.1.1 (macOS 14.0) is not compatible with our CHGLS usage. It was working with the SMC firmware from iBoot-10151.121.1 (macOS 14.5). power: supply: macsmc_power: Remove CSIL Gone in Sequoia firmware. 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. power: supply: macsmc_power: Report only supported properties The SMC firmware in macOS 15.4 dropped "AC-i" and "AC-n" (and all keys with lower case last letter) without obvious replacement. Stop reporting VOLTAGE_NOW / INPUT_CURRENT_LIMIT if "AC-n" is not present. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Co-developed-by: Thomas Weißschuh <linux@weissschuh.net> Signed-off-by: Janne Grunau <j@jannau.net> Co-developed-by: Janne Grunau <j@jannau.net> Co-authored-by: Joey Gouly <joey.gouly@arm.com> Signed-off-by: Hector Martin <marcan@marcan.st>
1 parent 5182e1e commit 7d65ee4

4 files changed

Lines changed: 819 additions & 0 deletions

File tree

drivers/mfd/macsmc.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646

4747
static const struct mfd_cell apple_smc_devs[] = {
4848
MFD_CELL_NAME("macsmc-input"),
49+
MFD_CELL_NAME("macsmc-power"),
4950
MFD_CELL_OF("macsmc-gpio", NULL, NULL, 0, 0, "apple,smc-gpio"),
5051
MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"),
5152
MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"),

drivers/power/supply/Kconfig

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,4 +1132,11 @@ config FUEL_GAUGE_MM8013
11321132
the state of charge, temperature, cycle count, actual and design
11331133
capacity, etc.
11341134

1135+
config CHARGER_MACSMC
1136+
tristate "Apple SMC Charger / Battery support"
1137+
depends on MFD_MACSMC
1138+
help
1139+
Say Y here to enable support for the charger and battery controls on
1140+
Apple SMC controllers, as used on Apple Silicon Macs.
1141+
11351142
endif # POWER_SUPPLY

drivers/power/supply/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ obj-$(CONFIG_CHARGER_GPIO) += gpio-charger.o
8181
obj-$(CONFIG_CHARGER_MANAGER) += charger-manager.o
8282
obj-$(CONFIG_CHARGER_LT3651) += lt3651-charger.o
8383
obj-$(CONFIG_CHARGER_LTC4162L) += ltc4162-l-charger.o
84+
obj-$(CONFIG_CHARGER_MACSMC) += macsmc-power.o
8485
obj-$(CONFIG_CHARGER_MAX14577) += max14577_charger.o
8586
obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o
8687
obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o

0 commit comments

Comments
 (0)