mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] power: supply: smb347: Set the USB input current limit from APSD
@ 2026-11-21  9:30 Patrick Fischer via B4 Relay
  2026-11-21  9:30 ` [PATCH 1/3] dt-bindings: power: supply: summit,smb347: Clarify the USB current limit Patrick Fischer via B4 Relay
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Patrick Fischer via B4 Relay @ 2026-11-21  9:30 UTC (permalink / raw)
  To: Sebastian Reichel, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, David Heidelberg, Dmitry Osipenko
  Cc: Svyatoslav Ryhel, Bruce Robertson, Martin Jücker,
	Mithil Bavishi, linux-pm, devicetree, linux-kernel,
	Patrick Fischer

The SMB347 driver programs the USB input current limit once at probe
from "summit,usb-current-limit-microamp". Boards either leave it at the
chip's NVM default, which is 900 mA on the Nexus 7 (2012), or set it to
1800 mA (exynos4412-p4note, omap4-samsung-espresso10). The first makes
the original 2 A charger no faster than a PC port, the second loads PC
ports with 1.8 A.

The charger detects the port type itself (APSD). This series reads the
result after the input became valid, sets the limit for the port type
(SDP 500 mA, CDP 1.5 A, DCP the DT value or 1.5 A) and reports it as
POWER_SUPPLY_PROP_USB_TYPE. Patch 1 updates the binding text, patch 2
makes the registers readable, patch 3 does the detection.

Measured on a Nexus 7 (2012, E1565), median current into the battery
(bq27541) over 5-30 minutes, battery charge in brackets:

                       before (NVM 900 mA)  this series
  laptop port (CDP)    505 mA (84-89 %)     640 mA (85-90 %)    1.5 A
  2 A charger (DCP)    561 mA (84-86 %)     968 mA (74-78 %)    1.5 A
                                            972 mA (79-82 %)    1.8 A *
  same, display off    596 mA (31-33 %)    1161 mA (37-39 %)    1.5 A
                                           1147 mA (45-47 %)    1.8 A *

  * with summit,usb-current-limit-microamp = <1800000> added to the
    grouper DT for the test; it gives no gain over 1.5 A, so this
    series does not touch the grouper DT.

The display was on unless noted.

The laptop port turned out to be a CDP. A PC port detected as SDP was
not available for testing. With 1800 mA in the device tree and without
this series, AICL ended once at the lowest step directly after boot at
the laptop port (the battery got 120 mA); with the series it did not
happen in seven boots and several reconnections. Directly after probe the
charger NAKs the write to CFG_VARIOUS_FUNCTION; patch 3 therefore does
the first detection 500 ms after probe, as after a new connection.
A quick move from the laptop port to the charger once left the driver
with the CDP limit (two interrupts, input state unchanged in the
driver), so patch 3 detects the port type after every USB input
interrupt; quick moves in both directions work with that.

There is no public datasheet with the register map that I could find.
The STAT_D, AICL and APSD bits are taken from the Android 3.1 kernel for
the Nexus 7 [1], which uses them the same way (900 mA for SDP, 1800 mA
for the other types). That is why only the SMB347 uses APSD, and
SMB345/SMB358 stay as they are.

Questions:

- Is 500 mA for an SDP acceptable? It is the USB 2.0 value, but less
  than the NVM default of 900 mA on the Nexus 7 and than the 1800 mA
  p4note and espresso10 use today at a PC port.
- APSD result "other" (non-BC 1.2 chargers) gets 500 mA here; the
  Android driver uses the charger limit. Is someone able to check the
  meaning of the remaining STAT_D values on SMB345/SMB358?

Bruce Robertson posted an RFC for a Rust SMB347 driver [2], which does
not handle interrupts or USB OTG yet. This series is for the existing C
driver; I am happy to test the Rust driver on the Nexus 7 as well.

Tested with v7.4-rc3 on a Nexus 7 (2012, E1565) at a laptop port (CDP)
and the original 2 A charger (DCP), including unplugging, replugging and
quick moves between them.
An SDP, chargers reported as "other" and USB host mode (OTG) were not
tested. The series is build tested on top of power-supply for-next.

Tool use (see Documentation/process/generated-content.rst): the patches,
their changelogs and this cover letter were prepared with an LLM coding
assistant (Claude Code). It compared the Android and mainline drivers,
wrote the code and drafted the texts from my measurements and
instructions. I reviewed the changes and ran all tests on the device.

[1] drivers/power/smb347-charger.c, branch
    android-tegra3-grouper-3.1-lollipop-release of
    https://android.googlesource.com/kernel/tegra
[2] https://lore.kernel.org/all/20260708214738.25008-1-brucer42@gmail.com/

---
Patrick Fischer (3):
      dt-bindings: power: supply: summit,smb347: Clarify the USB current limit
      power: supply: smb347: Make the APSD and AICL registers readable
      power: supply: smb347: Set the USB input current limit from APSD

 .../power/supply/summit,smb347-charger.yaml        |   5 +-
 drivers/power/supply/smb347-charger.c              | 258 ++++++++++++++++++++-
 2 files changed, 260 insertions(+), 3 deletions(-)
---
base-commit: abbe0a96bdbadae9e29489a1528fa436c55aca25
change-id: 20261120-upstream-smb347-apsd-98b4edefb06f

Best regards,
--  
Patrick Fischer <admin@tsv-stahl-riesa.de>



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-11-21 20:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-21  9:30 [PATCH 0/3] power: supply: smb347: Set the USB input current limit from APSD Patrick Fischer via B4 Relay
2026-11-21  9:30 ` [PATCH 1/3] dt-bindings: power: supply: summit,smb347: Clarify the USB current limit Patrick Fischer via B4 Relay
2026-11-21  9:30 ` [PATCH 2/3] power: supply: smb347: Make the APSD and AICL registers readable Patrick Fischer via B4 Relay
2026-11-21  9:30 ` [PATCH 3/3] power: supply: smb347: Set the USB input current limit from APSD Patrick Fischer via B4 Relay
2026-11-21 20:59 ` [PATCH 0/3] " David Heidelberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®