Repository navigation
power: supply: max17042_battery: wait out the MAX77759's alert - #170
Conversation
The MAX77759's gauge keeps ALRT asserted until its next task period after Status is cleared, up to 351 ms with the TaskPeriod its battery models set. The interrupt is level-low and oneshot, so as soon as the thread returns it runs again, and each alert becomes a burst: on a Pixel 7, every 1 % step of RepSOC fired the gauge's interrupt about 420 times within half a second, with Status already clear on each later run. Sleep one task period at the end of the thread on the MAX77759, before the interrupt is unmasked. Google's driver for the same gauge does the same (max1720x_fg_irq_thread_fn() sleeps 500 ms, "gauge will take up to 351 ms to clear ALRM1"). Alerts arriving meanwhile are kept by the level interrupt and handled on the next run. Tested on a Pixel 7 (7.3.0-rc6) with its battery model loaded: before this change, unplugged and discharging, three 1 % steps of RepSOC fired the interrupt 424, 429 and 453 times. With it, five alerts in 18 minutes (RepSOC reaching 90 % on the cable, then four steps down to 86 % unplugged) fired it once each, the thresholds moved with each step, and the gauge reported as before. Assisted-by: Claude Opus 5.5 Signed-off-by: Alejandro Garcia <skipper.pelygro@gmail.com>
|
Tested on a Pixel 8 Pro (husky), and I see the same burst you describe, and your patch removes it. Setup: 7.3.0-rc6 (@greenbrettmichael's c6 plus the four commits of #163), the MAX77759 gauge with Google's default-a1-0k model loaded through a DT overlay, so TaskPeriod is 0x2d00 and your sleep is the 351 ms. A small logger on the phone reads the gauge's line in /proc/interrupts (summed over the CPUs) every 30 seconds together with the battery level, and I forced a few 1% steps with a CPU load (about 450 to 650 mA). Without your patch: the count jumped by 466 for the 75 to 74 step (803 to 1269) and by 402 for 74 to 73 (1269 to 1671), so roughly 400 to 470 interrupts per 1% step, the same size as on your Pixel 7. With your patch: it applied cleanly to our tree, I rebuilt only max17042_battery.ko with the release name pinned and swapped it on the running phone (rmmod, insmod, the model stayed loaded, Status POR stayed clear). The 73 to 72 step added 1 interrupt (1671 to 1672) and 72 to 71 added 1 (1672 to 1673). What I did not test: the Pixel 7 Pro, a different pack or model, more than two steps with the patch, or anything else the patch might change (the percentage and temperature kept reading normally, nothing else I looked at changed). Thanks for this one. |
|
Thank you, @nesmeck, for tracking this down, and for the before/after counts per 1 % step; that table makes the problem and the fix easy to see. Thanks also to @Somnius for the independent run on the Pixel 8 Pro. The change itself looks right to me:
Our gate agrees with yours on today's The one thing left is on my side. The Pixel 7 Pro has the same gauge on the same interrupt (gpa9-3, level low), with a battery model that sets the same TaskPeriod, so this changes the reference phone on purpose. Our rule for shared drivers (CONTRIBUTING §6.2) is that a deliberate Pixel 7 Pro change merges after it has run there. The driver file is identical on One small thing you could tidy if you touch it again, not a blocker: the early |
|
Thanks for checking it against Google's handler, and for running it on the Pixel 7 Pro before merging. You're right about the early return: when the Status read fails, How would you like it, given that you're testing exactly this commit on your phone?
Either is fine with me. On the Pixel 7 I'd check the follow-up the same way as before: one interrupt per 1 % step, with the gauge readings unchanged. The error path itself I can't trigger safely on the MAX77759's bus. 🤖 Generated with Claude Code |
|
@nesmeck thanks, the common exit sounds right to me. @derekross if it helps with your choice between (a) and (b): I can run the final version on my Pixel 8 Pro as well, it has the same MAX77759 gauge and I already ran this commit there before (one interrupt per 1 % step, gauge readings unchanged). I'd just rebuild max17042_battery with the change on my kernel and read /proc/interrupts across a few steps, same as last time, so nothing extra needed on your side. Tell me which version you end up with and I'll run it. |
|
Thanks, I'm taking this one. I had an equivalent fix on my integration branch (a 1.5-period hold-off, plus an Tested on a Pixel 7 Pro ( |
|
@derekross thank you for taking it. @nesmeck when the common-exit follow-up PR is up, ping me and I'll run it on my Pixel 8 Pro the same way as before: the interrupt count per 1 % step, gauge readings unchanged. I can't trigger the I2C error path safely on this bus either. |
On the MAX77759, every gauge alert turns into a burst of hundreds of interrupts. The gauge keeps ALRT asserted until its next task period after Status is cleared: up to 351 ms with the TaskPeriod (0x2d00) its battery models set. The interrupt is level-low and oneshot, so as soon as
max17042_thread_handler()returns, it runs again, about once a millisecond, until the gauge lets go.The fix. On the MAX77759 only, the thread sleeps one task period after clearing Status. The period is computed from
chip->task_period, in units of 1/32768 s: 351 ms with a model, 176 ms at the default 0x1680. An alert that arrives during the sleep isn't lost: the level interrupt stays pending and is handled on the next run. Nothing new is written to the gauge.Google's GPL driver for the same gauge does the same.
max1720x_fg_irq_thread_fn()inkernel/google-modules/bms,max1720x_battery.c, branchandroid-gs-pantah-6.1-android16, ends withmsleep(MAX1720X_TICLR_MS)(500 ms) and the comment "oneshot w/o filter will unmask on return but gauge will take up to 351 ms to clear ALRM1".Tested on a Pixel 7 (slot B, 7.3.0-rc6), with stock's battery model loaded (the battery PR, to follow) and a logger reading the interrupt count with Status and the gauge's SOC registers every 250 ms:
…-ge654d41e556f)…-g51074200c999, only this change added)Before the fix, Status already read 0 after each burst, and nothing fired between steps. After it, SALRT_Th moved with each step, and the gauge's readings (capacity, voltage, current, temperature) were as before.
The Pixel 7 Pro uses the same gauge and driver, so it should see the same bursts. I haven't tested it there.
Checks:
tools/kernel-pr-check --build OUT --merge origin/omamobilepasses everything:🤖 Generated with Claude Code