[PATCH 0/2] power: supply: max8903: add GPIO-controlled input current-limit

Herman van Hazendonk posted 2 patches 4 days, 22 hours ago
.../bindings/power/supply/maxim,max8903.yaml  |  58 +++
drivers/power/supply/max8903_charger.c        | 369 +++++++++++++++++-
2 files changed, 416 insertions(+), 11 deletions(-)
[PATCH 0/2] power: supply: max8903: add GPIO-controlled input current-limit
Posted by Herman van Hazendonk 4 days, 22 hours ago
The MAX8903 charger exposes two hardware pins for input current control:
IDC (DC path, pin 11) and IUSB (USB path, pin 7). On many boards these
are driven by GPIO lines to a resistor mux or logic selector, letting
software select the input current limit. The driver currently has no
mechanism to set POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT at all.

This series adds that capability via two optional DT property groups:

  DC path: "dc-current-limit-gpios" + "dc-current-limit-mapping"
  A 1..4-GPIO array drives a resistor mux connected to the MAX8903 IDC
  pin. The IDC pin programs the step-down DC input current limit from
  0.5 A to 2 A (R_IDC = 6000V/I_DC_MAX) when the DCM mode pin is
  logic-high. The mapping table (uint32-matrix of {microamps,
  gpio_bit_pattern} pairs) lists every step the board supports. The
  driver picks the largest step at or below the requested limit.

  USB path: "usb-current-limit-gpios" + "usb-current-limit-values"
  A single GPIO drives the MAX8903 IUSB pin. Logic-low selects 100 mA,
  logic-high selects 500 mA per the MAX8903 spec. The two microamp
  values are described in DT so boards with non-standard IUSB thresholds
  can override them. Requests below the lower value are rejected with
  -EINVAL rather than silently programming a higher-than-requested limit.

The dispatch between the two paths is guarded by a new mutex (source_lock)
that is also taken in the IRQ handlers that update the "source online"
flags, preventing a race between set_property and a concurrent DOK/UOK
IRQ flip. The IRQs are already requested IRQF_ONESHOT so the sleepable
mutex is the appropriate primitive.

Motivation: the HP TouchPad carries a MAX8903B charger with two TLMM GPIO
lines feeding a four-step IDC resistor mux (500 mA, 1 A, 1.5 A, 2 A DC
input current limit) and a third TLMM line driving IUSB for the 100 mA /
500 mA USB limit. Without this series, the charger always draws its
hardware-default current irrespective of what the USB host negotiated.

Both patches are purely additive; platforms that don't provide the new DT
properties continue to behave exactly as before.

Herman van Hazendonk (2):
  dt-bindings: power: supply: maxim,max8903: add DC and USB input
    current-limit controls
  power: supply: max8903: add DC and USB input current-limit GPIO
    controls

 .../bindings/power/supply/maxim,max8903.yaml  |  58 +++
 drivers/power/supply/max8903_charger.c        | 369 +++++++++++++++++-
 2 files changed, 416 insertions(+), 11 deletions(-)

-- 
2.43.0