Skip to content

power: supply: max17042_battery: wait out the alert after a failed read too - #180

Merged
derekross merged 1 commit into
derekross:omamobilefrom
nesmeck:omamobile-max17042-alert-common-exit
Nov 2, 2026
Merged

derekross merged 1 commit into
derekross:omamobilefrom
nesmeck:omamobile-max17042-alert-common-exit

Conversation

@nesmeck

@nesmeck nesmeck commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #170, as suggested there.

max17042_thread_handler() returned early when the Status read failed, so it skipped the MAX77759's wait. An I2C error during an alert would then unmask the oneshot interrupt while ALRT was still asserted, and the alert would burst as before #170. The read failure now goes to a common exit (goto out), and the MAX77759 sleep sits there, so both paths wait one task period. Nothing else changes: the sleep is still gated on MAXIM_DEVICE_TYPE_MAX77759.

Tested on a Pixel 7 (7.3.0-rc6-omamobile-push1-gd50ff8bdd671): the kernel it ran before, with only this commit added.

  • With the cable out for 15 minutes and a logger reading the gauge's interrupt count every 250 ms, there were seven alerts: RepSOC reaching 99 % on the cable, then six 1 % steps down to 93 %. Each fired the interrupt once, the same as with power: supply: max17042_battery: wait out the MAX77759's alert #170 alone.
  • The gauge's readings (capacity, voltage, current, temperature) were as before.
  • Not tested: the failed-read path itself. I can't trigger an I2C error safely on the MAX77759's bus.

@Somnius, as you offered on #170: a run on the Pixel 8 Pro would be very welcome (the interrupt count per 1 % step, with the gauge readings unchanged).

Checks: tools/kernel-pr-check --build OUT --merge origin/omamobile passes everything:

  • a clean merge onto 8698185;
  • the sign-off;
  • checkpatch --strict with no warnings;
  • the W=1 build of the driver.

🤖 Generated with Claude Code

…ad too

The MAX77759 sleep added at the end of max17042_thread_handler() is
skipped when the Status read fails: the handler returns early, the
oneshot interrupt is unmasked while ALRT is still asserted, and an I2C
error during an alert would burst as before. Move the sleep to a common
exit, so both paths wait one task period.

Tested on a Pixel 7 (7.3.0-rc6), with only this change on top of the
kernel it ran before: with the cable out for 15 minutes, seven alerts
(RepSOC reaching 99 % on the cable, then six steps down to 93 %) fired
the gauge's interrupt once each, as before this change, and the gauge
read as before. The failed-read path itself wasn't triggered.

Suggested-by: Derek Ross <derekross@gmail.com>
Assisted-by: Claude Opus 5.5
Signed-off-by: Alejandro Garcia <skipper.pelygro@gmail.com>
@Somnius

Somnius commented Nov 1, 2026

Copy link
Copy Markdown
Contributor

@nesmeck thanks for the patch, I ran it on the 8 Pro as you asked on #170.

Kernel on the phone: 7.3.0-rc6-omamobile-push1-g5899fec2bd28 (Brett's c6 base plus my husky commits). It doesn't have #170 or #180 in it, so I built only max17042_battery.ko with both patches applied (#170, then #180 on top), kept the same vermagic, and swapped it in live with rmmod and insmod, no reboot. A logger read the gauge's interrupt (the line named max170xx_battery) every 250 ms and wrote a line whenever the count or the capacity changed.

With both patches: 25 minutes, capacity 73 % to 78 % in five 1 % steps, and the interrupt count went up by exactly 5, one per step, under a second after each capacity change. Voltage 4.136 to 4.180 V, temperature 36.2 to 36.3 C, current about +320 to +520 mA, no I2C errors in dmesg.

Same phone, same setup, the original module (neither patch): 13 minutes, two steps, 954 interrupts. The first step gave +207 and +280 within one second, the second +344 and +123. So the burst you describe is there without the fix and gone with it.

What I didn't test: the failed-read path itself, same as you, I can't trigger an I2C error safely. And these were charging steps: the phone was on the cable for nearly all of it (near the end of the control run the gauge briefly read Discharging, -309 mA, during the second step, with the cable still in, I haven't looked into why), so the discharge steps you ran aren't covered. I can repeat it with the cable out if you want that too. The two logs are in my notes and I can post them.

@derekross

Copy link
Copy Markdown
Owner

Thank you, @nesmeck, for sending the common exit so quickly, and @Somnius for the run on the Pixel 8 Pro. A before/after on the same phone and setup is the clearest evidence we could ask for: 954 interrupts over two steps without the fixes, 5 over five steps with both.

The change is what I suggested on #170. The failed Status read now goes to the same exit as the normal path, so the MAX77759 waits one task period either way, and the other gauges this driver serves still skip the sleep. Our gate passes on today's omamobile: a clean merge, the sign-off, checkpatch with no warnings and a clean W=1 build. CI is green.

Because this touches the Pixel 7 Pro's gauge, I also compared the compiled handler before and after. On the normal path the instructions are identical. The only difference is that the failed-read branch now jumps to the task-period sleep instead of straight to the return. So nothing my phone runs day to day changes, and the new path is one that none of us can trigger safely. I'll still put it on my Pixel 7 Pro with my next push, as our rule for shared drivers asks, and check that a 1 % step still fires the gauge's interrupt once. I'll merge it after that.

@Somnius, no need for a cable-out run on my account. @nesmeck's discharge steps on the Pixel 7 cover that direction, on the same gauge. The brief "Discharging" with the cable in during your control run came from the unpatched module, so it's not something this PR has to answer. If it shows up again with the fix loaded, a separate issue would be the right place for it.

@nesmeck

nesmeck commented Nov 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks a lot, @Somnius. That's a clean confirmation: five 1 % steps with exactly five interrupts and both patches in, against 954 interrupts in two steps without them, on a different phone and pack. Your charging steps complement my Pixel 7 run, which was unplugged and discharging. Between the two, both directions are covered, so I don't think you need to repeat it with the cable out.

About the "Discharging, -309 mA with the cable still in": I saw the same on the Pixel 7, and on mine the cause was the charger's input limit, not the gauge.

  • With no charger driver, or with ours at its default 500 mA input, the MAX77759's own BC1.2 detection sets the effective limit.
  • At boot my laptop's port was detected as CDP (1.5 A), so the battery took about 800 mA.
  • After a replug, BC_STATUS1 (TCPC 0x87) read 0x00 (no detection), so the limit fell back to 500 mA. With the screen on and a video playing, the battery then read about -50 mA while the charger was still in fast charge.

So it may be the same effect on the 8 Pro, if the input dropped back to the register's limit while the phone drew more. Reading 0x25/0x87 (bits 1:0: 1 SDP, 2 CDP, 3 DCP) and the charger's input limit would tell. It's unrelated to this patch, though.

🤖 Generated with Claude Code

@derekross
derekross merged commit 91d3f15 into derekross:omamobile Nov 2, 2026
1 check passed
@derekross

Copy link
Copy Markdown
Owner

Merged. Tested on my Pixel 7 Pro (7.3.0-rc6-omamobile-push1-gde2f7b69334d, my integration kernel with this on top): five 1 % steps (100-99-100-99-98, on and off the cable) fired the gauge's interrupt five times, once each. Thanks, @nesmeck, and @Somnius for the 8 Pro run.

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.

3 participants