Skip to content

power: supply: max77759: report CHGIN at most once a second - #298

Draft
Somnius wants to merge 2 commits into
derekross:omamobilefrom
Somnius:husky-chgin-debounce-1125
Draft

Somnius wants to merge 2 commits into
derekross:omamobilefrom
Somnius:husky-chgin-debounce-1125

Conversation

@Somnius

@Somnius Somnius commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Draft for now, I haven't run this on the phone yet. It's built and tested on the desktop only.

On one 8 Pro boot the charger's CHGIN interrupt fired 26 061 times (irq max77759-charger.2.auto:CHGIN in /proc/interrupts), going by the unit start times almost all near the end of a charge from a desktop USB port (/proc/interrupts is only a per-boot total). The battery kept charging the whole time (+333 to 500 mA, status Charging), but online read 0 for about 11 minutes. Every CHGIN edge calls power_supply_changed(), and our udev rule in omamobile started omamobile-charge-limit-apply.service 6 968 times that boot, peaking around 10 a second (per-minute average). The SoC went from 53-54 C to 57-59 C over the same window and came back after. That's only a timing match, I didn't measure CPU per process.

The other charger IRQs stayed small (AICL 156, CHG 174, DONE 1). Why CHGIN bounced is still unknown: I didn't read CHG_DETAILS_00 during the window. That needs a logged charge from the same port, and that's next.

What this does: CHGIN now goes through a delayed work that's only queued when it isn't already pending. So at most one power_supply_changed() a second from CHGIN, and the last state still goes out within a second. The downside is that a real plug or unplug reaches userspace about 1 s later from CHGIN (another charger IRQ in the meantime can still report sooner). The other IRQs are unchanged. The driver holds its own wakeup source for 2 s from each edge, so a change shouldn't have to wait for the next resume (that only blocks suspend when userspace uses wakeup_count or autosleep, the same limit as the power supply core's own hold, and it's untested). I didn't use the psy's wakeup source because the power supply core takes and drops it on its own and it doesn't nest. The work is set up before the IRQs, so devm frees the IRQs first, then cancels the work, then drops the wakeup source.

It doesn't change what online reports. If the input really is at the edge, debouncing online itself would be a separate patch.

The numbers came from my test kernel, which carries our charger series plus test-only patches, and that charge ran at a raised 4.45 V float (the run from derekross/omamobile#761 (comment)). So I can't say yet whether it happens at the stock float. The grey band is where online read 0:

charge 79 % to full, desktop port

This patch is on omamobile and doesn't depend on #265, #266, #267 or #277. It merges cleanly with each of them:
#265
#266
#267
#277

Tested:

Not tested: anything on the phone. The check there is one charge from the same port with /proc/interrupts and a udevadm monitor count, plus a plug/unplug to see the 1 s delay.

The userspace side (start the unit on add only, keep systemd's start limit) is a separate omamobile PR: derekross/omamobile#1068

@Somnius

Somnius commented Nov 25, 2026

Copy link
Copy Markdown
Contributor Author

Tested on my 8 Pro tonight. I built the charger module with this commit on top of the one already on the phone (same release, updates/), rebooted once, then charged from 87 % to 100 %, moving from the desktop port to a Baseus charger halfway through.

  • CHGIN interrupts for the whole boot: 2, the unplug and the plug at 21:32. The night before, without this, it was 26 061 in one boot.
  • omamobile-charge-limit-apply count isn't a result for this PR: with omamobile-device-husky: apply the charge limit once per boot, not again on every charger event omamobile#1068's rule installed it didn't start at all, which is a bug on that PR (details there).
  • About 0.5 A on the desktop port, about 1.0 A on the Baseus. Battery 35-38 C, SoC 50-57 C (the 57 was on the desktop port before the move, then 50-53). Last night's run peaked at 57-59 C during the storm.

Still a draft until it runs a few more charges, but the CHGIN part does what it says.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Lef. The 26,061 to 2 result is a good first sign, and it's useful that the description says exactly what wasn't measured.

One thing before this leaves draft: max77759_charger is also my 7 Pro's charger driver, and as written the new CHGIN handler and its wakeup source apply on every board that has the MAX77759, the 7 Pro, the Pixel 7 and akita included. I haven't seen a CHGIN storm on the 7 Pro, and the cause on your 8 Pro isn't known yet, so I'd rather this sat behind husky's board data, the per-board table the charger already has. If you think the 7 Pro needs it too, say why and I'll run it on mine first.

Two notes for the next round, not conditions. A read of CHG_DETAILS_00 while CHGIN bounces would tell whether the input really drops near the end of the charge or the interrupt fires without a change, which decides whether a debounce is the fix. And since your evidence charge was at the 4.45 V float, the follow-up at the published float would show whether it happens there at all.

On one husky boot the CHGIN interrupt fired about 26000 times, going by
the unit start times nearly all near the end of a charge from a desktop
USB port, while the battery kept charging at 333-500 mA. Why CHGIN
bounced is not known yet. Each edge calls power_supply_changed(), and
udev started a oneshot unit nearly 7000 times (up to about 10 a second,
per-minute average).

Send CHGIN through a delayed work that is queued only when it is not
already pending: at most one power_supply_changed() a second, and the
last state still goes out within a second. A real plug or unplug now
reaches userspace about a second later. The driver holds a wakeup
source of its own for 2 s from each CHGIN edge, so a change need not
wait for the next resume. The psy's own wakeup source is not used, as
the power supply core takes and drops it on its own. The other
interrupts are unchanged.

Signed-off-by: Lef <me@lefteros.com>
The CHGIN storm has only been seen on husky, and its cause is not known
yet, so the debounce should not change the 7 Pro, the Pixel 7 or akita.

Add a chgin_debounce flag to the per-board guard table and set it only
in husky's. The guard table is now picked before the CHGIN work and
wakeup source are set up, and both are set up only when the flag is on.
On every other board CHGIN goes through irq_handler() and no wakeup
source is registered, as before the debounce.

Add a KUnit case that checks the flag is on for husky and off in the
default table.

Signed-off-by: Lef <me@lefteros.com>
@Somnius
Somnius force-pushed the husky-chgin-debounce-1125 branch from 83f0519 to 6cf1884 Compare November 27, 2026 05:30
@Somnius

Somnius commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Fixed, thanks. The debounce is husky only now.

I added a chgin_debounce flag to the per-board guard table from #265 and set it only in guard_table_husky. The table is now picked earlier in probe, and the CHGIN work, the max77759-chgin wakeup source and the CHGIN handler are only set up when the flag is on. On the 7 Pro, Pixel 7, akita and any other board on the default table, CHGIN goes through plain irq_handler() again and no extra wakeup source gets registered, so they behave the same as before this PR. It's one new commit on top. I also rebased the branch on current omamobile so it sits on #265/#266 (no conflicts).

I don't have a reason to think the 7 Pro needs it, so I left it off there.

Tested: the charger object builds clean with W=1 (clang, arm64), with and without CONFIG_CHARGER_MAX77759_KUNIT_TEST. KUnit under UML passes 27/27, including a new case that checks the flag is on for husky and off in the default table. That case only covers the table, not the probe wiring that picks the handler from it; I checked that part by reading it. checkpatch --strict is clean. I haven't run it on the phone yet.

On your two notes, both are fair and neither is done yet. I don't have a CHG_DETAILS_00 read while CHGIN bounces, so I can't say yet whether the input really drops or the interrupt fires with no change, and that does decide if a debounce is the right fix or just hides something. And the evidence charge was at 4.45 V, so I don't know if it happens at the published float at all. Both need an attended charge on the phone, so I'll do them together in one run (log CHG_DETAILS_00 on each CHGIN edge, published float) and post what I get. I'll keep this in draft until then.

@derekross derekross left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Lef, that's the gate I asked for: on every board but husky, CHGIN goes through irq_handler() as before and no wakeup source is registered, and the teardown order is right.

One thing before it leaves draft: the gate is a second commit, and kernel PRs land commit by commit, so the first commit would sit on omamobile with the debounce on for every board, the 7 Pro included. Please fold the gate into the first commit, so the debounce arrives husky-only in one step.

And as you say, the attended charge at the published float with CHG_DETAILS_00 logged on each edge decides whether a debounce is the right fix. Small thing for the message: the wakeup source doesn't stop a logind suspend (only wakeup_count users see it), so "need not wait for the next resume" says a bit more than it does. It also conflicts with #277 and #267 at one line in probe; keep #277's stop_last line after guard_band = -2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants