summaryrefslogtreecommitdiff
path: root/drivers/power/supply
AgeCommit message (Collapse)Author
4 daysMerge tag 'for-v7.4' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply and reset updates from Sebastian Reichel: "Power-supply core: - introduce LOAD_SWITCH property - pack power_supply_desc to optimize memory - prevent power-supply device unregistration while callback runs - drop last CONFIG_OF build-time dependencies from the core - documentation fixes Power-supply drivers: - bq27xxx: add support for bq27z746, bq28z620 - ab8500: add AB8505 support - bq257xx: fix probe time configuration race condition - multiple: convert drivers with custom LOAD_SWITCH properties to the new standard one - cros_charge-control: restore EC state on resume - qcom_battmgr: fix USB type reporting, notify charger online state, report full batteries and correct capacity on X1E - gpio-charger: always report as discharging if input power is missing - bq24190_charger: don't reset registers across system suspend - qcom_smbx: a lot of independent fixes - lots of error and module removal path fixes - misc fixes Reset drivers - misc fixes" * tag 'for-v7.4' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (77 commits) power: supply: gpio-charger: Report discharging without input power power: supply: qcom_battmgr: report full batteries power_supply: serialize property access with unregister power: supply: bq257xx: Describe the dev field in the driver data structure power: supply: qcom_battmgr: Notify charger supplies of online changes power: supply: generic-adc-battery: fix status with no supplier power: supply: qcom_battmgr: report the USB type from USB_ADAP_TYPE power: supply: sysfs: Ratelimit "unavailable enum value" warning power: supply: cros_charge-control: restore EC state on resume power: supply: qcom_smbx: set the charge enable after software control power: supply: generic-adc-battery: Propagate charged GPIO errors power: supply: sbs-battery: disable polling before supply teardown power: supply: pf1550: drain IRQ work before unregistering supplies power: supply: bq256xx: Expose VBUS state through extcon power: supply: ab8500_fg: Avoid reserved AB8505 CCConf bit power: supply: ab8500_fg: Finalize current measurements power: supply: ab8500_charger: Recover inactive AB8505 charger power: supply: ab8500_charger: Retry AB8505 USB detection power: supply: ab8500_charger: Skip absent AB8505 main charger power: supply: ab8500_charger: Handle detection errors ...
2026-10-18power: supply: gpio-charger: Report discharging without input powerIgor Velkov
The status property follows only the charge-status GPIO. Without input power a charger such as the BQ24133 releases its open-drain STAT pin, and depending on the board the GPIO then reads as charging. On Kobol Helios64 the board runs from its battery after a mains loss, and the charger reports online 0 with status "Charging". Report "Discharging" whenever the online GPIO is present and inactive. Fixes: df68c44c720a ("power: supply: gpio-charger: Add support for charger status.") Assisted-by: LLM Signed-off-by: Igor Velkov <iav@iav.lv> Link: https://patch.msgid.link/20261018-gpio-charger-offline-v2-1-482795f9e27c@iav.lv Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-18power: supply: qcom_battmgr: report full batteriesBjorn Andersson
The SC8280XP battery-status response has no explicit full state. When a battery reaches its full capacity on external power, neither the charging nor discharging bit is set. The driver consequently reports "Not charging", which can make userspace show the system as battery powered. Use the response's power-online bit and the reported capacity to identify a battery that is full while externally powered. Preserve "Not charging" for a battery whose charging is inhibited below its full capacity. Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply") Assisted-by: LLM Signed-off-by: Bjorn Andersson <bjorn.andersson@oss.qualcomm.com> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://patch.msgid.link/20261008-battmgr-full-v1-1-4f5485a9c421@oss.qualcomm.com [put variable definition in Reverse-Christmas-tree order] Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-18power_supply: serialize property access with unregisterHang Nan
Extend 5b4bd13e0552 ("power: supply: core: prevent unregistering a power supply while a callback runs") fix to also cover the get and set property hooks. This has been tested with a small out-of-tree module registering a supply whose get property function caches its drv_data pointer and then sleeps 300 ms, while the module's main thread calls power_supply_unregister() and then frees that drv_data: unpatched: unregister() returns after 78 us callback then reads drv_data 0x6b6b6b6b (slub poison) => the driver callback read freed memory patched: unregister() returns after 302549 us (the 300 ms callback) callback then reads drv_data 0x12345678 (intact) => power_supply_unregister() waits for the in-flight callback The lock is taken in the wrappers rather than in the helper so that the _direct() variants stay lockless: a caller that has to read its own supply from within a callback uses those, and rwsem read locking is not recursive once a writer is waiting. Fixes: bc1540561c9e ("power_supply: Add API for safe access of power supply function attrs") Fixes: 5b4bd13e0552 ("power: supply: core: prevent unregistering a power supply while a callback runs") Signed-off-by: Hang Nan <2122295973@qq.com> [massively trim down AI commit message and comments] Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-18Merge power-supply fixes branchSebastian Reichel
Merge power-supply fixes branch to extend the epc_sem unregister fix contained in it from external_power_changed to also cover get/set property. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: bq257xx: Describe the dev field in the driver data structureAlexey Charkov
The commit moving the device initialization to the new .init callback missed the description of the newly introduced dev field in the driver data structure - add an entry to the kerneldoc. No code changes. Reported-by: kernel test robot <lkp@intel.com> Closes: https://lore.kernel.org/oe-kbuild-all/202610120726.XkN50Smh-lkp@intel.com/ Signed-off-by: Alexey Charkov <alchark@flipper.net> Link: https://patch.msgid.link/20261015-bq257xx-dev-comment-v1-1-c87ee6a3b251@flipper.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: qcom_battmgr: Notify charger supplies of online changesBrandon Williams
On SC8280XP and X1E80100 the AC, USB and wireless supplies take their online state from the charging source in the battery status response. The firmware sends no notification for those supplies when the charging source changes, and the driver only announces the battery, so userspace never learns that the charger was plugged in or out. UPower keeps the state it read at startup: a laptop booted on the charger never goes on battery. Call power_supply_changed() for a supply whose online state changes when a status response is parsed. A supply that is not registered yet, when the battery is read during probe, reports its state when it registers. Tested on a Microsoft Surface Pro 11 (X1E80100): after restarting UPower on the charger, unplugging now sets OnBattery, and plugging in clears it. Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Brandon Williams <turbine.bmw@gmail.com> Link: https://patch.msgid.link/20261013-upstream-battmgr-charger-online-v1-1-731973e133a0@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: generic-adc-battery: fix status with no supplierTim Douglas
power_supply_am_i_supplied() returns -ENODEV when no registered power supply supplies the battery. generic-adc-battery's gab_work() tests this return value as a boolean, so -ENODEV takes the supplied branch and reports CHARGING, or NOT_CHARGING if the charge-finished GPIO is asserted, instead of DISCHARGING. This was noticed while bringing up an out-of-tree Linux port to the WikiReader: the driver reported CHARGING on a device powered by two AAA batteries with no charging hardware. Only a positive return value indicates an online supplier, so treat zero and negative returns as discharging. Fixes: 46cecd130d55 ("power: supply: Fix power_supply_am_i_supplied to return -ENODEV when apropriate") Cc: stable@vger.kernel.org Signed-off-by: Tim Douglas <me@timdoug.com> Link: https://patch.msgid.link/20261013022153.6707-1-me@timdoug.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: qcom_battmgr: report the USB type from USB_ADAP_TYPEJoonhoe Kim
On SM8350 and SM8550 class firmware the USB power supply reads its usb_type from the USB_TYPE property. On a Kaanapali (SM8850) tablet that property is 1 (SDP) whatever is plugged in, while USB_ADAP_TYPE reports the adapter, using the same numbering as POWER_SUPPLY_USB_TYPE_*: PC port USB_TYPE 1 USB_ADAP_TYPE 1 (SDP) USB-C dock, 5 V PD USB_TYPE 1 USB_ADAP_TYPE 6 (PD) 65 W PPS charger USB_TYPE 1 USB_ADAP_TYPE 8 (PD_PPS) Qualcomm's downstream qti_battery_charger driver also maps USB_ADAP_TYPE to POWER_SUPPLY_PROP_USB_TYPE. Request USB_ADAP_TYPE for POWER_SUPPLY_PROP_USB_TYPE instead. Tested on a Lenovo Legion Tab Y700 gen 5 (qcom,kaanapali-pmic-glink, which uses the SM8550 path). Only tested on this device; the SM8350 variant shares the property map and was not tested. Fixes: 29e8142b5623 ("power: supply: Introduce Qualcomm PMIC GLINK power supply") Reviewed-by: Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com> Assisted-by: LLM Signed-off-by: Joonhoe Kim <26rote@gmail.com> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://patch.msgid.link/20261012130053.442-1-26rote@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: sysfs: Ratelimit "unavailable enum value" warningRobert Killick
power_supply_show_enum_with_available() warns every time a driver reports a value that is not in its declared set of available values. For usb_type this happens on every sysfs read and on every uevent, so a driver that reports such a value and calls power_supply_changed() frequently can flood the kernel log. This can happen with drivers that pass a firmware-provided value through unchanged, as qcom_battmgr does for usb_type. On a OnePlus 10 Pro (SM8450), whose firmware reports a vendor-specific usb_type, this produced ~128 warnings per second and kept systemd-journald at ~30% CPU. The bug that causes the bad value needs fixing in the driver itself, but one misbehaving driver should not be able to flood the kernel log. Use dev_warn_ratelimited(), as power_supply_show_property() already does for its own errors, so the problem is still reported, just not on every read. Signed-off-by: Robert Killick <robert@killick.dev> Link: https://patch.msgid.link/20261005-ratelimit-enum-warn-v1-1-b77b48de3c47@killick.dev Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: cros_charge-control: restore EC state on resumeAndrew Pam
The EC resets its charge control configuration when the AP powers off, so configured sustainer thresholds and charge behaviour are lost across hibernation. Nothing notices the reset. Commit 4fc88ba435da ("power: supply: cros_charge-control: adopt EC charge state on probe"), in the power-supply tree, made the driver adopt the EC's charge state, but only at probe, and a resume is not a probe. Sysfs therefore keeps reporting the configured values while the EC charges the battery to full. On a Framework Laptop 16 (Ryzen AI 300, charge control command version 3) with charge_control_end_threshold set to 80, a hibernate and resume cycle leaves the attribute still reading 80 while the battery charges past it to 100%. Add a system sleep resume hook that reprograms the EC from the cached state. The same EC behaviour and the same fix already exist for another driver, see commit 2643187ccb86 ("platform/x86: ayaneo-ec: Add suspend hook"). Reprogramming the EC is only strictly required after hibernation, but it is cheap and idempotent, so hook every resume path rather than rely on the EC preserving its state across each kind of sleep transition. Note that re-reading the state from the EC on resume, by reusing cros_chctl_init_state() or otherwise, would be wrong even on the command versions that support GET: the EC has been reset to its defaults by the time the hook runs, so adopting that state would silently discard the configuration the user asked for. The driver's cached state is the only remaining record of it, which is why it is pushed to the EC rather than refreshed from it. Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Andrew Pam <andrew@fastmailteam.com> Reviewed-by: Tzung-Bi Shih <tzungbi@kernel.org> Acked-by: Thomas Weißschuh <linux@weissschuh.net> Link: https://patch.msgid.link/20261005043418.243937-1-andrew@fastmailteam.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-17power: supply: qcom_smbx: set the charge enable after software controlFabricio Akio
The init sequence sets CHARGING_ENABLE_CMD before CHGR_CFG2 selects software control of the charge enable. The Motorola Moto X4's bootloader leaves the charger watchdog armed to disable charging when it bites, which it does after a few minutes in fastboot. Charging then stays disabled in the next boot until the cable is replugged. Setting the command after CHGR_CFG2 re-enables it. Fixes: 8648aeb5d7b7 ("power: supply: add Qualcomm PMI8998 SMB2 Charger driver") Cc: stable@vger.kernel.org Signed-off-by: Fabricio Akio <fabricioakio@gmail.com> Link: https://patch.msgid.link/20261002-qcom-smbx-enable-order-v1-1-7df92bd809db@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-13Merge tag 'for-v7.3-rc' of ↵Linus Torvalds
git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply fixes from Sebastian Reichel: "power-supply core: - prevent unregistering a power supply while a callback runs power-supply drivers: - generic-adc-battery: Fix temperature IIO channel conversion - ds2780: Fix ds2780_get_capacity() returning raw value - max17042_battery: Fix vmin assigned instead of vmax in DT parsing - Fix maintenance charge table kernel-doc" * tag 'for-v7.3-rc' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: power: supply: core: prevent unregistering a power supply while a callback runs power: supply: generic-adc-battery: Fix temperature IIO channel conversion power: supply: ds2780: Fix ds2780_get_capacity() returning raw value power: supply: Fix maintenance charge table kernel-doc power: supply: max17042_battery: Fix vmin assigned instead of vmax in DT parsing
2026-10-12power: supply: generic-adc-battery: Propagate charged GPIO errorsbui duc phuc
devm_gpiod_get_optional() may return an error pointer such as -EPROBE_DEFER, but gab_probe() only checks for NULL. The error pointer is then passed to gpiod_to_irq() and the original error, including -EPROBE_DEFER, is lost. Check the return value and propagate errors from the charged GPIO lookup. Fixes: b0327ffb133f ("power: supply: generic-adc-battery: Use GPIO descriptors") Signed-off-by: bui duc phuc <phucduc.bui@gmail.com> Reviewed-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20261009112429.33318-1-phucduc.bui@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-05power: supply: sbs-battery: disable polling before supply teardownMyeonghun Pak
The managed poll-work cancellation is registered before the power supply, so cleanup unregisters the supply before draining polling. A pending or running poller can then call power_supply_changed() on the released supply. Commit 8d59cf3887fb ("power: supply: sbs-battery: Fix use-after-free in power_supply_changed()") moved the IRQ request after supply registration, but did not change the poll-work cancellation order. Add a later managed action that disables and drains polling before supply teardown. Its retained disabled state prevents external-power callbacks from rearming the poll work after it has been drained. Keep the original autocancel to initialize work before supply callbacks can run and to cover failed supply registration. The teardown ordering issue was found by static analysis. Fixes: 6d0c5de2fd84 ("power: supply: Clean-up few drivers by using managed work init") Cc: stable@vger.kernel.org # 6.10+ Assisted-by: LLM Co-developed-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Myeonghun Pak <mhun512@gmail.com> Link: https://patch.msgid.link/20261004041019.1123723-1-mhun512@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-05power: supply: pf1550: drain IRQ work before unregistering suppliesMyeonghun Pak
The VBUS work calls power_supply_changed(), but its managed cancellation is registered before the supplies. Cleanup can therefore unregister a supply while IRQ-triggered work is still pending. Commit 838767f50747 ("power: supply: pf1550: Fix use-after-free in power_supply_changed()") moved IRQ requests after supply registration, but left work cancellation before the supplies. That change protects the direct IRQ callbacks, while this fix drains the work they queue. Register the three work items after both supplies and before the IRQs. Cleanup then frees the IRQ producers, drains the work, and unregisters the supplies. The teardown ordering issue was found by static analysis. Fixes: 4b6b6433a97d ("power: supply: pf1550: add battery charger support") Cc: stable@vger.kernel.org Assisted-by: LLM Co-developed-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Ijae Kim <ae878000@gmail.com> Signed-off-by: Myeonghun Pak <mhun512@gmail.com> Link: https://patch.msgid.link/20261004043728.1140015-1-mhun512@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: bq256xx: Expose VBUS state through extconReza Kurniawan
Useful for USB controllers needing to sense VBUS state changes. This is needed for devices like Xiaomi Redmi 5A (riva) that doesn't have its VBUS session comparator wired directly to the USB connector pin to automatically enable certain USB functions upon the presence of a USB power input. Signed-off-by: Reza Kurniawan <imkyufie@gmail.com> Link: https://patch.msgid.link/20260912-riva-usb-v2-1-997fe0171ee5@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_fg: Avoid reserved AB8505 CCConf bitLinus Walleij
AB8500 defines CCConf bit 1 as CCDeepSleepEna, but AB8505 reserves bits 7:1 and only defines bit 0, CCPwrUpEna. The fuel-gauge driver currently writes both bits whenever it starts the coulomb counter. The Samsung-GT-S7710-Skomer and related Samsung product trees use the same unconditional value in their fuel-gauge drivers, so they provide no AB8505 workaround to carry over. Select the value from the detected PMIC variant instead, retaining the deep-sleep enable bit on all existing non-AB8505 paths and avoiding the reserved bit on AB8505. Fixes: a982362c1723 ("mfd: Support for the AB8500 AB8505 variant") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-15-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_fg: Finalize current measurementsLinus Walleij
ab8500_fg_inst_curr_start() returns with cc_lock held and the CCEOC IRQ enabled. The bounded sampling loop in the load-compensated voltage path returns without calling ab8500_fg_inst_curr_finalize() when it expires, leaving both resources active. The next fuel-gauge work item then blocks on cc_lock and all cached power-supply values stop updating. The Samsung-GT-I8530-Gavini, Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle and Samsung-SGH-T599-Codina-TMO product trees use a bounded sampling loop in drivers/battery/abb_fuelgauge.c but still call the finalizer. Follow that pattern so the normal completion timeout also performs the required cleanup. Check the start result as well and return an uncompensated voltage if the instantaneous current transaction cannot be started or completed. Fixes: edc400e1632f ("power: supply: ab8500_fg: Break loop for measurement") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-14-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Recover inactive AB8505 chargerLinus Walleij
UsbChCtrl1.UsbChEna can remain set while UsbChStatus1.UsbChOn is clear. The existing recovery only checks the control bit, so it considers the charger enabled and leaves charging stopped. The Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle, and Samsung-SGH-T599-Codina-TMO product trees are reference points for checking both bits and cycling the charger when they disagree. Extend the USB charger check to detect this AB8505 state and enable the check in the charging algorithm for AB8505. Only cycle the charger when VBUS is debounced and no charger-not-OK, thermal, overvoltage, or watchdog fault accounts for the inactive hardware. Fixes: 4dcdf57773fd ("ab8500-bm: Quick re-attach charging behaviour") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-13-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Retry AB8505 USB detectionLinus Walleij
AB8505 reports UsbLink1Status state 14 when the USB charger port is not OK. The manual says that software can return the port detector to the detection state by setting the self-clearing ChargerCtrl.DropCountReset bit. The Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle, and Samsung-SGH-T599-Codina-TMO product trees are reference points for a workaround that cycles the USB charger and retries detection three times before rejecting VBUS. Only the Kyle tree writes 1 to DropCountReset; the other two write 0 and therefore do not request the documented reset. Add the same bounded recovery for AB8505, preserving the configured USB charger control bits across each cycle. Keep the charger connected while recovering, then report the fault and disconnect it if all three attempts fail. Leave AB8500 behavior unchanged. Fixes: d4337660d069 ("ab8500-charger: Add AB8505_USB_LINK_STATUS") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-12-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Skip absent AB8505 main chargerLinus Walleij
AB8505 contains only the USB charger. It has no integrated main charger, main-charger status register, or main-charger interrupts. Avoid reading the missing status register, requesting the five missing interrupts, or disabling an AC charger which was never enabled. This lets the driver bind using only the AB8505 USB charger resources. Fixes: d4337660d069 ("ab8500-charger: Add AB8505_USB_LINK_STATUS") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-11-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Handle detection errorsLinus Walleij
ab8500_charger_detect_chargers() returns either a charger bitmask or a negative register-access error. The probe and component-bind paths use a negative return value as a bitmask, making failed reads appear as both AC and USB connections. Propagate detection errors and release the bind-time workqueue on failure. Fixes: 84edbeeab67c ("ab8500-charger: AB8500 charger driver") Fixes: 1c1f13a006ed ("power: supply: ab8500: Move to componentized binding") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-10-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Respect AB8505 register layoutLinus Walleij
Several AB8505 charger fields differ from AB8500. Its long VBUS falling debounce is 300 ms rather than 100 ms, and its VBUS overvoltage selector has a different encoding programmed through OTP. Writing the AB8500 6.3 V value selects 9 V on AB8505. AB8505 revision 3 also defines SwControlFallback as reserved, correcting older documentation which led the driver to support autopower there. Preserve the AB8505 overvoltage setting, wait for its documented debounce, and reject the unsupported autopower setting. Fixes: 0ed5107fa860 ("ab8500-charger: Do not touch VBUSOVV bits") Fixes: b016322293c7 ("ab8500-charger: Add support for autopower on AB8505 and AB9540") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-9-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Decode AB8505 USB statusLinus Walleij
AB8505 keeps USB link status in the same bit position as AB8500 but defines a different five-bit value table. Reusing the AB8500 enum treats several reserved AB8505 values as chargers and misidentifies the AB8505 charger-fault and DM-high states. Add an AB8505 decoder, reject reserved and non-charging states, and retain conservative current limits for supported charger types. Restrict the invalid-link workaround to AB8500 and stop processing when the status register cannot be read. Fixes: d4337660d069 ("ab8500-charger: Add AB8505_USB_LINK_STATUS") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-8-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_charger: Fix AC charger re-enableLinus Walleij
The AC check-enable callback passes the embedded USB charger object to ab8500_charger_ac_en(). That helper derives the parent with the AC charger offset, so the wrong object yields an invalid ab8500_charger pointer. Pass the AC charger object when re-enabling AC charging. Fixes: bc6e02871402 ("power: supply: ab8500: Standardize CV voltage") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-7-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500: Preserve battery termination currentLinus Walleij
The battery-info parser uses a negative value for an unspecified termination current. Testing the value as a boolean instead replaces every valid positive current from the battery description with 200 mA. Apply the default only when the property is unspecified so batteries retain their described charging termination current. Fixes: 9c20899da46b ("power: supply: ab8500: Standardize termination current") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-6-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_btemp: Fix event temperature reportingLinus Walleij
The event-aware path initializes its local temperature to zero and compares that zero against the thermal thresholds. Consequently some events report the measured temperature after it crosses the event threshold, while others always report the threshold. Start with the measured temperature, clamp it according to the active event, and convert to tenths of a degree only once. This path is used by AB8505 and later variants. Fixes: 1f855824757e ("ab8500-btemp: AB8500 battery temperature driver") Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-5-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_fg: Drop nonexistent AB8505 controlsLinus Walleij
The AB8505 RTC register map has no register at offset 0x15, but the fuel-gauge driver initializes and exposes that offset as a power-cut flag-time control. PcutCtlAndStatus bit 4, exposed as powercut_flag, is reserved as well. Remove both nonexistent controls and their internal configuration field so the driver no longer accesses reserved hardware locations. Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-4-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500: Correct register definitionsLinus Walleij
The charger LED PWM register encodes its duty cycle as (N + 1) / 256. The value for 252/256 is therefore 0xfb, not 0xbf. Both output-current codes 0xe and 0xf select 1.5 A, while 0x3f cannot fit in the four-bit field. Also correct the AB8505 BatCtrl bit 0 current source from 18 uA to 8 uA. Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-3-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_fg: Report sub-percent charge changesLinus Walleij
The fuel gauge updates bat_cap.mah from the coulomb counter but exposes bat_cap.prev_mah through CHARGE_NOW and ENERGY_NOW. It only refreshes prev_mah when the rounded integer capacity percentage changes, making the momentary properties appear frozen between percentage steps. Refresh prev_mah and notify userspace whenever the new charge remains within the currently accepted percentage. If a discharge estimate tries to cross upward into a higher percentage, the existing rejection still leaves both the reported percentage and charge unchanged. The AB8500 fuel-gauge implementations in the Samsung-GT-I8160-Codina, Samsung-GT-I8160_HD-Codina, Samsung-GT-I8530-Gavini, Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle and Samsung-SGH-T599-Codina-TMO product trees retain the same percentage-gated prev_mah update and contain no finer-grained reporting workaround. Fixes: 13151631b5bd ("ab8500-fg: A8500 fuel gauge driver") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-2-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ab8500_fg: Accept status from supplied powerLinus Walleij
Commit dc77721ea4aa ("power: supply: ab8500: Set typing and props") changed the charging algorithm power supply type from battery to unknown so userspace would not mistake it for a second battery. The fuel gauge, however, processes status changes only from battery-type supplies. It therefore never learns that charging started and keeps running its discharge state machine. The power supply relationship already limits the callback to supplies naming the fuel gauge in supplied_to. Accept status from any such supply while retaining the battery type checks for battery-specific properties. The Samsung-GT-I8160-Codina and Samsung-GT-I8160_HD-Codina product trees keep the charging algorithm typed as a battery. The Samsung-GT-I8530-Gavini, Samsung-GT-S7710-Skomer, Samsung-SGH-I407-Kyle and Samsung-SGH-T599-Codina-TMO alternative fuel-gauge drivers instead pass cable state directly. Both approaches preserve the charging state handoff that was lost in mainline. Fixes: dc77721ea4aa ("power: supply: ab8500: Set typing and props") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Linus Walleij <linusw@kernel.org> Link: https://patch.msgid.link/20260916-ab8500-charging-v1-1-e986ed321cc6@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: max17042_battery: Make the fractional macros safeBabanpreet Singh
The fractional LSB macros expand to a plain division, so they only work when multiplied first and evaluate to 0 anywhere else. Take the value as a macro argument and apply it with mult_frac(), which properly handles it. Reported-by: kernel test robot <lkp@intel.com> Reported-by: Dan Carpenter <error27@gmail.com> Closes: https://lore.kernel.org/r/202606062322.TyvCPB3l-lkp@intel.com/ Assisted-by: LLM Signed-off-by: Babanpreet Singh <bbnpreetsingh@gmail.com> Link: https://patch.msgid.link/20260915052529.7-1-bbnpreetsingh@gmail.com [fixed commit message, dropped useless AI comment] Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: Use %pe to print error pointers symbolicallySumeet Pawnikar
Replace PTR_ERR() and %ld/%li with %pe and pass the original pointer directly to dev_info(), dev_Warn and dev_dbg(). The %pe format specifier prints a symbolic error name (e.g. -ENOMEM) when CONFIG_SYMBOLIC_ERRNAME is enabled, otherwise it falls back gracefully and prints the raw integer value. This makes messages more readable without any functional change. Signed-off-by: Sumeet Pawnikar <sumeet4linux@gmail.com> Link: https://patch.msgid.link/20260912191156.185448-2-sumeet4linux@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: use tabs in power_supply_get_property_directIván Ezequiel Rodriguez
The return statement was indented with spaces; use tabs to match kernel coding style and silence checkpatch. Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com> Link: https://patch.msgid.link/20260831155339.181487-6-ivanrwcm25@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: restore hwmon if extension update failsIván Ezequiel Rodriguez
power_supply_update_sysfs_and_hwmon() removes the existing hwmon group before recreating it. If recreation fails, register_extension() rolled back the extension but left hwmon absent. After tearing down the failed extension, best-effort recreate hwmon so the supply keeps its previous monitoring attributes when possible. Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com> Link: https://patch.msgid.link/20260831155339.181487-3-ivanrwcm25@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: return -ENOMEM on OCV table alloc failureIván Ezequiel Rodriguez
power_supply_get_battery_info() maps a failed kcalloc() for the OCV capacity table to -EINVAL. Return -ENOMEM instead, matching the resistance-temp-table allocation path in the same function. Signed-off-by: Iván Ezequiel Rodriguez <ivanrwcm25@gmail.com> Link: https://patch.msgid.link/20260831155339.181487-2-ivanrwcm25@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: bq257xx: Convert parameters setup to the new .init callbackAlexey Charkov
Switch the battery parsing and hardware initialization from happening inside the probe routine (after the power supply is registered) to the new .init callback which gets run during the registration, thus avoiding the exposure of a not-yet-fully-configured power supply to the rest of the system. Signed-off-by: Alexey Charkov <alchark@flipper.net> Link: https://patch.msgid.link/20260910-bq257xx-init-v3-3-4e219a1a04a5@flipper.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: bq257xx: Use psy directly instead of driver dataAlexey Charkov
bq257xx_external_power_changed() is handed the power supply it is called for, but passes pdata->charger to power_supply_am_i_supplied(). Those are not equivalent during probe or teardown, and a supplier's changed_work can reach power_supply_external_power_changed() when pdata->charger doesn't point anywhere meaningful (e.g. freed memory during teardown). Use the psy argument, which is valid whenever the callback runs. Fixes: 1cc017b7f9c7 ("power: supply: bq257xx: Add support for BQ257XX charger") Signed-off-by: Alexey Charkov <alchark@flipper.net> Link: https://patch.msgid.link/20260910-bq257xx-init-v3-2-4e219a1a04a5@flipper.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: core: prevent unregistering a power supply while a callback runsAlexey Charkov
Once a power supply is registered, its callbacks can immediately start firing from other contexts, such as external_power_changed() triggered by the TCPM stack. If a power supply is unregistered while the callback is still running, the driver data can already be freed when the callback tries to access it, leading to a use-after-free. This happens e.g. when the hardware bus carrying the power supply device malfunctions (e.g. I2C is hogged down by another malfunctioning device) immediately after the power supply is registered, and thus the core is still processing the callbacks which were queued up when the driver starts the removal, leading in some cases to a kernel crash, e.g.: [ 11.645942] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000005 [ 11.646751] Mem abort info: [ 11.647006] ESR = 0x0000000096000004 [ 11.647338] EC = 0x25: DABT (current EL), IL = 32 bits [ 11.647806] SET = 0, FnV = 0 [ 11.648077] EA = 0, S1PTW = 0 [ 11.648356] FSC = 0x04: level 0 translation fault [ 11.648785] Data abort info: [ 11.649041] ISV = 0, ISS = 0x00000004, ISS2 = 0x00000000 [ 11.649524] CM = 0, WnR = 0, TnD = 0, TagAccess = 0 [ 11.649981] GCS = 0, Overlay = 0, DirtyBit = 0 [ 11.650390] [0000000000000005] user address but active_mm is swapper [ 11.650955] Internal error: Oops: 0000000096000004 [#1] SMP [ 11.651460] Modules linked in: [ 11.651742] CPU: 1 UID: 0 PID: 144 Comm: kworker/1:2 Not tainted 7.2.0-rc6-g62a9297af2cd #1 PREEMPT [ 11.652553] Hardware name: Flipper One rev. F0B1C2 (DT) [ 11.653024] Workqueue: events power_supply_changed_work [ 11.653511] pstate: 60000005 (nZCv daif -PAN -UAO -TCO -DIT -SSBS BTYPE=--) [ 11.654135] pc : __power_supply_is_supplied_by+0x18/0x100 [ 11.654624] lr : __power_supply_am_i_supplied+0x40/0xb8 [ 11.655098] sp : ffff80008192bb30 [ 11.655399] x29: ffff80008192bb30 x28: 0000000000000000 x27: 0000000000000000 [ 11.656049] x26: 0000000000000000 x25: 0000000000000000 x24: 0000000000000000 [ 11.656695] x23: ffff0000c19f4200 x22: ffffdb2232ba4ea8 x21: ffff80008192bc28 [ 11.657344] x20: ffff0000c1eef000 x19: ffff80008192bc18 x18: 00000000a0886e62 [ 11.657991] x17: 000000040044ffff x16: 04500072b5503510 x15: 0000000000000000 [ 11.658639] x14: 0000000000000000 x13: 0000000000000220 x12: 0000000000000000 [ 11.659286] x11: 0000000000000000 x10: ffff0000c1fdb2b0 x9 : ffffdb2232ba5590 [ 11.659934] x8 : 00000000e5b906e6 x7 : ffff0000c2502778 x6 : ffffdb22339793d0 [ 11.660581] x5 : ffff80008192bc18 x4 : ffff0000c19cbca0 x3 : 0000000000000000 [ 11.661228] x2 : ffff0000c1fdaf40 x1 : ffffffffffffffed x0 : ffff0000c1eef000 [ 11.661878] Call trace: [ 11.662103] __power_supply_is_supplied_by+0x18/0x100 (P) [ 11.662596] __power_supply_am_i_supplied+0x40/0xb8 [ 11.663040] psy_for_each_psy_cb+0x20/0x40 [ 11.663416] class_for_each_device+0x110/0x150 [ 11.663825] power_supply_am_i_supplied+0x68/0x100 [ 11.664262] bq257xx_external_power_changed+0x58/0x140 [ 11.664733] __power_supply_changed_work+0x60/0x80 [ 11.665170] psy_for_each_psy_cb+0x20/0x40 [ 11.665545] class_for_each_device+0x110/0x150 [ 11.665953] power_supply_changed_work+0x98/0x1b8 [ 11.666382] process_one_work+0x164/0x4c0 [ 11.666758] worker_thread+0x19c/0x320 [ 11.667104] kthread+0x138/0x150 [ 11.667408] ret_from_fork+0x10/0x20 [ 11.667744] Code: d503233f a9bd7bfd 910003fd a90153f3 (f9400c34) [ 11.668294] ---[ end trace 0000000000000000 ]--- Add a read-write semaphore between external_power_changed() and power_supply_unregister() to prevent the latter from returning (and thus the driver from freeing its data) while the callback is still running. Fixes: bc1540561c9e ("power_supply: Add API for safe access of power supply function attrs") Signed-off-by: Alexey Charkov <alchark@flipper.net> Link: https://patch.msgid.link/20260910-bq257xx-init-v3-1-4e219a1a04a5@flipper.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: ltc2941: Fix of_node reference leak in ltc294x_i2c_probe()Wentao Liang
ltc294x_i2c_probe() takes a reference on the device node with of_node_get(), but never drops it, so the reference leaks on every return path, including the success path. The node is only used to read the battery properties and to set info->supply_desc.name, so release it after its last use and also on the lltc,resistor-sense error path. Fixes: 085bc24d1553 ("Add LTC2941/LTC2943 Battery Gauge Driver") Cc: stable@vger.kernel.org Signed-off-by: Wentao Liang <vulab@iscas.ac.cn> Link: https://patch.msgid.link/20260917142127.2156568-1-vulab@iscas.ac.cn Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: bq27xxx: add support for BQ28Z620Alexey Charkov
Match the BQ28Z620 under its own chip ID so that code touching its relocated data flash can tell it apart from the BQ28Z610. Reuse the BQ28Z610 register map and properties, as the standard commands the driver reads are unchanged. Keep the 10 mW scaling of AveragePower() even though the BQ28Z620 TRM lists it in mW: readings on hardware match V * I only in 10 mW units. Signed-off-by: Alexey Charkov <alchark@flipper.net> Link: https://patch.msgid.link/20261002-bq28z620-v1-2-bdcc10d42519@flipper.net Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: qcom_smbx: Remove const from desc allocation typeKees Cook
In preparation for making the devm_kmalloc family of allocators type aware, we need to make sure that the returned type from the allocation matches the type of the variable being assigned. (Before, the allocator would always return "void *", which can be implicitly cast to any pointer type.) The assigned type is "struct power_supply_desc *", but the converted allocation type would be "const struct power_supply_desc *", as the size was taken from "smb_psy_desc", which is a "static const struct power_supply_desc". As there is no general way to remove const qualifiers, take the size from the assignment target instead. No change in allocation size results. Build tested ARCH=x86_64 allmodconfig with GCC 16.2.0: drivers/power/supply/qcom_smbx.o Assisted-by: LLM coccinelle Signed-off-by: Kees Cook <kees+treewide@kernel.org> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://patch.msgid.link/20260917211309.i.765-kees@kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: axp20x_usb: Improve probe error reportingUwe Kleine-König
Don't be silent about probe fail issues. Just having axp20x-usb-power-supply in /sys/kernel/debug/devices_deferred without a reason is making it harder than necessary to debug the actual issue. So be a bit more cooperative and add an error message for the typical failure points. Exit paths where the error is -ENOMEM and register write failures are skipped, these should be quite obvious even without a dedicated error message. Signed-off-by: Uwe Kleine-König <ukleinek@debian.org> Reviewed-by: Chen-Yu Tsai <wens@kernel.org> Link: https://patch.msgid.link/b699f8251afed736af454a981630926e45eb7da7.1789983244.git.ukleinek@debian.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: axp20x_usb: Introduce a helper variable for &pdev->devUwe Kleine-König
With the next commit adding several new usages of &pdev->dev, a helper variable is well justified. To not clutter that commit, split out the introduction of the helper out in this separate change to simplify review. Signed-off-by: Uwe Kleine-König <ukleinek@debian.org> Reviewed-by: Chen-Yu Tsai <wens@kernel.org> Link: https://patch.msgid.link/f0e6c7ff8dce9f1a0903d83ff3ef782a18cd63d2.1789983244.git.ukleinek@debian.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: axp20x*: Drop check for disabled devicesUwe Kleine-König
Since commit 6b5c350648b8 ("mfd: mfd-core: Honour Device Tree's request to disable a child-device") the mfd core checks for disabled devices, so there is no use in doing that again in the mfd child driver. Drop the check in the two power drivers. Signed-off-by: Uwe Kleine-König <ukleinek@debian.org> Reviewed-by: Chen-Yu Tsai <wens@kernel.org> Link: https://patch.msgid.link/c17a6c915abdb99612a52d2bb8cff78050f6b0a6.1789983244.git.ukleinek@debian.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: qcom_battmgr: Report capacity on X1E80100Liviu Nicoara
Commit 3f87baacea4d ("power: supply: qcom_battmgr: Report battery capacity") added POWER_SUPPLY_PROP_CAPACITY to the SC8280XP battery properties, computed from the firmware's charge and last-full values. When commit cc3e883a0625 ("power: supply: qcom_battmgr: Add charge control support") later gave X1E80100 a property table of its own, the table was copied without the capacity property, so X1E80100 machines expose energy_now and energy_full but no capacity. The percentage is already computed for this variant in the shared SC8280XP callback; only the property list is missing it. Add it, in the same place it sits in the SC8280XP table. Tested on a Dell XPS 13 9345: capacity reads 94 with energy_now 52640000 and energy_full 55540000. Fixes: cc3e883a0625 ("power: supply: qcom_battmgr: Add charge control support") Signed-off-by: Liviu Nicoara <lnicoara@thinkoid.org> Reviewed-by: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com> Link: https://patch.msgid.link/20260920193402.2402-1-lnicoara@thinkoid.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: core: Honor supplied-from with CONFIG_OF=yMaurizio Casciano
The supplied-from device property is the name-based counterpart to firmware-node power-supplies references. It was added for non-DT platforms, but its parser is compiled only when CONFIG_OF is disabled. CONFIG_OF is a global kernel option, so x86 systems commonly enable it even when individual power supplies are described by software nodes. Consequently, these consumers never populate supplied_from and supplier notifications do not reach their external_power_changed() callbacks. On a Lenovo Yoga Book YB1-X91L, ftrace showed the Whiskey Cove supplier notification running without invoking the BQ25892 callback, leaving the input current limit at its boot-time value. Use a single power_supply_check_supplies() implementation for all configurations. Preserve firmware-node power-supplies references as the preferred firmware description and use the name-based supplied-from property only when no references are specified. Continue to honor an explicitly provided supplied_from list first and propagate errors from specified firmware references. With the fix, ftrace shows the BQ25892 callback on hotplug. A boot-offline test changes its input current limit from 500 mA to 2 A. Fixes: 58a36bb06891 ("power: supply: core: Add support for supplied-from device-property") Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Maurizio Casciano <mauriziocasciano7@gmail.com> Link: https://patch.msgid.link/20260924225152.985489-1-mauriziocasciano7@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: generic-adc-battery: Fix temperature IIO channel conversionSvyatoslav Ryhel
Temperature IIO channel data is provided in milli-degrees, while POWER_SUPPLY_PROP_TEMP is expected to be in deci-degrees. Adjust the existing logic to reflect this conversion properly. Fixes: 33088c0513818 ("power: supply: generic-adc-battery: add temperature support") Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> Link: https://patch.msgid.link/20260926142905.206215-2-clamor95@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2026-10-04power: supply: bq24190_charger: don't reset registers across system suspendRyan Brue
bq24190_pm_suspend() calls bq24190_register_reset(), which returns every register to its power-on default, and bq24190_pm_resume() does it again before re-applying the probe-time configuration. On any board that wires the charger's interrupt this makes system suspend unusable. The reset re-arms the chip's 40 s i2c watchdog. bq24190_set_config() turns that watchdog off at probe, deliberately: as the comment there explains, the same write also takes the part out of default mode into host mode. Nothing pets it while the system is asleep, so it expires, resets the registers again and pulses INT. The charger interrupt is a system wake source -- armed unconditionally in probe since commit f385e6e2a153 ("power: bq24190_charger: Use PM runtime autosuspend"), and still enabled by default after the conversion to the wake irq API [1] -- so the pulse wakes the machine. Measured on an MT8173 board (Amazon Fire HD 10 2017, BQ24297) by swapping only this driver between builds with and without this change, asking for a 150 s suspend each time: on charger, with the reset: 41-43 s, 7 runs of 7 on charger, without the reset: 150 s, 3 runs of 3 on battery, with the reset: 40-41 s, 3 runs of 3 on battery, without the reset: 150 s, 3 runs of 3 It is not a charging-only problem. The watchdog runs from VBUS or from the battery, so an unplugged tablet loses suspend in the same way. ftrace names the wake source. Across the resume, the first device interrupt after the machine comes back is the charger: 1270.760799: suspend_resume: machine_suspend[3] end 1270.775683: irq_handler_entry: irq=25 name=bq24190-charger 1270.776156: irq_handler_entry: irq=250 name=11010000.i2c Everything between is IPI and arch_timer from bringing the secondary CPUs back up, and no RTC interrupt appears anywhere in the trace -- the 150 s wake alarm never fired. The cause leaves nothing behind for userspace to find, because WATCHDOG_FAULT is in the latch-on-read fault register and the driver's own interrupt handler has already consumed it. The reset also discards host configuration that nothing restores. Resume calls bq24190_set_config(), which writes only the watchdog, SYS_MIN, IPRECHG, ITERM, ICHG and VREG, so: - IINLIM returns to its power-on default. Boards without a charger-type detector set the input limit from userspace; measured here, one ordinary suspend/resume silently took input_current_limit from 1500 mA to 500 mA, and to 100 mA when running from the battery, where the default differs. - EN_HIZ is cleared, so a charger the host put into high-impedance mode starts drawing from VBUS again the moment the system sleeps. There is no way to have both. Default mode is what the reset is for, and on this part default mode and a disarmed watchdog are mutually exclusive: a write to any register moves the chip into host mode, and it only returns to default mode when the watchdog times out. Parking it in default mode for the sleep therefore always leaves a timer armed that will fire, and on any board that wires INT that firing is a wake. A per-board opt-out would not be choosing between two workable configurations, only between a working suspend and a broken one. Resetting in suspend buys nothing worth this. The part is in host mode with its watchdog off; it charges on its own, switching from constant current to constant voltage and terminating when the battery is full, and nothing in it can expire or change while the host sleeps. Resetting on resume is weaker still: the host is awake and about to reconfigure the chip, so the reset only guarantees the loss. The one thing the reset does guard against is a host that never comes back: a chip in host mode keeps whatever it was last told, where default mode would revert to the power-on values. But that is the state the driver leaves it in for all of normal runtime operation already, so sleep is not special, and the part still makes its own constant-current to constant-voltage transition and terminates when the battery is full. So drop it in both directions. The suspend callback has nothing left to do and goes away. Resume re-applies the probe-time configuration, which is idempotent and also recovers a part that did somehow fall back to default mode, since bq24190_set_config() starts by turning the watchdog off. This has been proposed before. Hans de Goede sent the same change in 2017 [2] and Sebastian Reichel agreed with the reasoning [3], but v6 kept the reset on by default and added the "disable-reset" device property instead [4]. That property cannot answer this: it is set only from x86 platform code -- i2c-cht-wc and x86-android-tablets -- and is not in bq24190.yaml, so no DT board can reach it. Every in-tree DT user of this driver (tegra124-xiaomi-mocha, qcom-msm8974-lge-nexus5-hammerhead, qcom-msm8974pro-oneplus-bacon, rk3188-bqedison2qc) wires the charger interrupt and so has the same wake armed, with no way to opt out. If some board does want the reset, it would be better expressed the other way round. The vendor kernel for this board does not reset across suspend either: its driver, drivers/power/mt81xx/bq24297.c, only masks the charger interrupt on suspend and unmasks it on resume. Reproduced on a BQ24297. The reasoning applies to the family, but the other parts were not available to test. [1] https://lore.kernel.org/all/20260908-rbrue-suez-upstreaming-bq24190_charger-use-wake-irq-api-v1-1-c3f10ae2a34a@gmail.com/ [2] https://lore.kernel.org/all/20170322145536.30570-5-hdegoede@redhat.com/ [3] https://lore.kernel.org/all/20170323112052.ukyazi4pnji7n6st@earth/ [4] https://lore.kernel.org/all/20170414165233.4532-1-hdegoede@redhat.com/ Fixes: d7bf353fd0aa ("bq24190_charger: Add support for TI BQ24190 Battery Charger") Assisted-by: LLM Signed-off-by: Ryan Brue <ryanbrue.dev@gmail.com> Reviewed-by: Hans de Goede <johannes.goede@oss.qualcomm.com> Link: https://patch.msgid.link/20260928-rbrue-suez-upstreaming-bq24190_charger-no-reset-regs-sys-suspend-v1-1-9a7689f12c05@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>