Skip to content

hwmon: (applesmc) add charge_control_end_threshold support

Jordan Brough chrome-platform linux-acpi linux-hwmon linux-pm lkml platform-driver-x86 3 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 13 repliesIn review
  2. v22 patches 1 replySuperseded
  3. v12 patches 2 repliesSuperseded

Changes in v3 from the cover letter

- Patch 1 is new: acpi_ prefix for the exported hook functions, with their callers updated.
- Patch 2:
- Renamed battery_hook.c to battery_hooks.c, built only when ACPI_BATTERY or ACPI_SBS is, through a hidden ACPI_BATTERY_HOOKS symbol that both select.
- Renamed the struct and the new functions as suggested, exported the new functions in the ACPI_BATTERY_HOOKS namespace, used mutex guards and updated the file header.
- battery_hook_exit() is gone, so hooks now stay registered across a reload of battery.ko or sbs.ko.
- Patch 3:
- BFCL is only written when the SMC has the key, and the BCLM write is read back, at the suggestion of Michal Szpakowski, whose MacBookPro13,1 has no BFCL.
- No BFCL margin at a limit of 100.
- The lower limit of 20 is conservative: 20 works and 10 is not accepted on the hardware I tried, but I did not find the exact floor. I am happy to change it.
- Dropped the applesmc_hooked_battery tracking and the mutex in applesmc_bat_get_property().
- The hook is only registered when CONFIG_ACPI_BATTERY_HOOKS is reachable.

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3ACPI: battery: add acpi_ prefix to the battery hook APIdrivers/acpi/battery.c drivers/platform/x86/asus-wmi.c drivers/platform/x86/ayaneo-ec.c +17 more+50 -4812 replies
2/3ACPI: battery: add unified battery hook mechanism for ACPI and SBS batteriesdrivers/acpi/Kconfig drivers/acpi/Makefile drivers/acpi/battery.c +3 more+185 -1631 reply
3/3hwmon: (applesmc) add charge_control_end_threshold supportdrivers/hwmon/Kconfig drivers/hwmon/applesmc.c+147 -00 replies

Reviews trailers per patch

1 of 3 patches has a Reviewed-by or Acked-by.

PatchMichal SzpakowskiArmin WolfDerek J. ClarkMark PearsonAntheas KapenekakisRong ZhangSebastian ReichelIlpo JärvinenJonathan Woithe
1/3R-b R-b R-b R-b R-b A-b A-b A-b
2/3
3/3T-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 9 reviewers.

Read the v3 thread

Cover letter [PATCH v3 0/3] hwmon: (applesmc) add charge_control_end_threshold support

This series adds charge_control_end_threshold to the applesmc driver for Intel MacBooks, using the power_supply extension API.

Some of these machines have an SBS battery (drivers/acpi/sbs.c), which, unlike battery.c, has no battery hook mechanism. Patch 2 moves the hook code into a helper that both drivers use, and patch 3 adds the applesmc support. Patch 1 is the acpi_ prefix rename of the existing hook functions that Rafael asked for; it is separate because it touches 18 callers in other subsystems.

The series is based on linux-pm's bleeding-edge branch (4c18627a1dfb). Patch 3 depends on patch 2, so the series would need to go in through the ACPI tree with an ack from the hwmon side, or I can resend patch 3 once patches 1 and 2 are in, whichever is easier.

Changes in v3 (thanks to Rafael for the review):
- Patch 1 is new: acpi_ prefix for the exported hook functions, with their callers updated.
- Patch 2:
- Renamed battery_hook.c to battery_hooks.c, built only when ACPI_BATTERY or ACPI_SBS is, through a hidden ACPI_BATTERY_HOOKS symbol that both select.
- Renamed the struct and the new functions as suggested, exported the new functions in the ACPI_BATTERY_HOOKS namespace, used mutex guards and updated the file header.
- battery_hook_exit() is gone, so hooks now stay registered across a reload of battery.ko or sbs.ko.
- Patch 3:
- BFCL is only written when the SMC has the key, and the BCLM write is read back, at the suggestion of Michal Szpakowski, whose MacBookPro13,1 has no BFCL.
- No BFCL margin at a limit of 100.
- The lower limit of 20 is conservative: 20 works and 10 is not accepted on the hardware I tried, but I did not find the exact floor. I am happy to change it.
- Dropped the applesmc_hooked_battery tracking and the mutex in applesmc_bat_get_property().
- The hook is only registered when CONFIG_ACPI_BATTERY_HOOKS is reachable.

Testing:
- MacBookAir6,2 (SBS battery), on an earlier revision: limits from 20 to 100 match the SMC keys, charging stops at the limit, repeated module reloads caused no errors, and the threshold was unchanged after a suspend/resume.
- MacBookPro13,1 (SBS battery, no BFCL), by Michal Szpakowski, before the acpi_ rename: valid limits read back exactly, invalid ones are rejected, applesmc reload and an acpi-sbs unbind/rebind re-attach the attribute, and charging stops at the limit.
- Lenovo ideapad FLEX 4-1480 (Control Method battery, ideapad_laptop), on Fedora's 7.2.7 kernel with the series applied on top (a rebase of the patches, not this exact tree): the ideapad_laptop hook registers and its charge_types attribute appears on BAT1, charge_types can be read and written back unchanged, 25 battery unbind/bind cycles re-attach it each time, and unloading and reloading ideapad_laptop removes and re-adds it. There were no warnings in dmesg. That kernel did not have lockdep enabled.
- Built and linked with ACPI_BATTERY and ACPI_SBS as y/m/n and applesmc as y/m, and an x86 allmodconfig build of the touched files with W=1 shows no warnings; each patch builds on its own.
- Applies with git am on linux-pm bleeding-edge, and with git am --3way on hwmon-next.

Jordan Brough (3):
ACPI: battery: add acpi_ prefix to the battery hook API
ACPI: battery: add unified battery hook mechanism for ACPI and SBS
batteries
hwmon: (applesmc) add charge_control_end_threshold support

 drivers/acpi/Kconfig                         |   5 +
 drivers/acpi/Makefile                        |   1 +
 drivers/acpi/battery.c                       | 166 +------------------
 drivers/acpi/battery_hooks.c                 | 159 ++++++++++++++++++
 drivers/acpi/sbs.c                           |   8 +-
 drivers/hwmon/Kconfig                        |   1 +
 drivers/hwmon/applesmc.c                     | 146 ++++++++++++++++
 drivers/platform/x86/asus-wmi.c              |   4 +-
 drivers/platform/x86/ayaneo-ec.c             |   2 +-
 drivers/platform/x86/dell/dell-laptop.c      |   4 +-
 drivers/platform/x86/dell/dell-wmi-ddv.c     |   2 +-
 drivers/platform/x86/fujitsu-laptop.c        |   4 +-
 drivers/platform/x86/huawei-wmi.c            |   4 +-
 drivers/platform/x86/lenovo/ideapad-laptop.c |   4 +-
 drivers/platform/x86/lenovo/thinkpad_acpi.c  |   4 +-
 drivers/platform/x86/lenovo/wmi-other.c      |   4 +-
 drivers/platform/x86/lg-laptop.c             |   4 +-
 drivers/platform/x86/msi-ec.c                |   4 +-
 drivers/platform/x86/oxpec.c                 |   2 +-
 drivers/platform/x86/samsung-galaxybook.c    |   3 +-
 drivers/platform/x86/samsung-laptop.c        |   4 +-
 drivers/platform/x86/system76_acpi.c         |   4 +-
 drivers/platform/x86/toshiba_acpi.c          |   4 +-
 drivers/platform/x86/uniwill/uniwill-acpi.c  |   2 +-
 drivers/power/supply/cros_charge-control.c   |   2 +-
 include/acpi/battery.h                       |  16 +-
 26 files changed, 367 insertions(+), 196 deletions(-)
 create mode 100644 drivers/acpi/battery_hooks.c

base-commit: 4c18627a1dfbfe537580f831e60218644c94ce12

Signature · 1 line
2.56.0