diff --git a/CHANGELOG.md b/CHANGELOG.md index d8ac0410..c58e0257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,11 @@ is missing or empty. - iPad Air and iPad mini 2 and 3 (A7): Lightning charging draws up to 1.5 A instead of 1.05 A from a charger that offers it, as measured on an iPad mini 2; untested on the iPad Air and iPad mini 3. +- iPad Air and iPad mini 2 and 3 (A7): the Lightning charger does what + iOS 12 does on their D2089 PMIC: with every input-limit write it takes + the PMIC's input out of suspend, and it restarts the PMIC's charge timer + when that has expired below 90 % charge. Meant for an iPad Air at 1 % + that kept discharging on a charger while one at 7 % charged; untested. - iPad mini 2 and 3 (A7): the speakers play, in stereo, through the same CS35L19 amplifier driver as the iPhone 6s Plus's loudspeaker, with the output capped at -12 dB because there is no speaker protection yet. diff --git a/devices/j71/device.toml b/devices/j71/device.toml index 169bef3d..f720fc1d 100644 --- a/devices/j71/device.toml +++ b/devices/j71/device.toml @@ -48,7 +48,7 @@ bluetooth_input = "missing" bluetooth_audio = "missing" cellular = "missing" battery = "untested" # BQ2754x on UART5 HDQ, as on every A7 iPad (ADT uart5/gas-gauge), with the J72 gauge profile; not yet run on this board -charging = "untested" # the shared A7 Tristar charger on the D2089 (ADT pmu,d2089 + tristar,cbtl1610), up to 1500 mA as measured on a J85; not yet run on this board +charging = "untested" # the shared A7 Tristar charger on the D2089 (ADT pmu,d2089 + tristar,cbtl1610), up to 1500 mA as measured on a J85. On a J71 with the series before the D2089 input-suspend and charge-timer handling: at 1 % the battery kept discharging (-224 to -565 mA) on a Mac CDP and a 30 W USB-C charger although the limit was set to 1500 mA; from 7 % (after iBoot charged it while off) a CDP charged it at +823 mA. The current series, which clears 0x10 bit 2 and restarts an expired charge timer as iOS 12 does, has not run on this board charging_control = "untested" # as on the J72: source identified at each plug, grant ramped, back to 100 mA on unplug; not yet run on this board suspend = "untested" resume = "untested" diff --git a/kernel/patches/devices/s5l8960x/0016-arm64-dts-apple-s5l8960x-Describe-the-D2089-charger-.patch b/kernel/patches/devices/s5l8960x/0016-arm64-dts-apple-s5l8960x-Describe-the-D2089-charger-.patch new file mode 100644 index 00000000..34f8c4fe --- /dev/null +++ b/kernel/patches/devices/s5l8960x/0016-arm64-dts-apple-s5l8960x-Describe-the-D2089-charger-.patch @@ -0,0 +1,59 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Tue, 24 Nov 2026 08:05:50 +0100 +Subject: [PATCH] arm64: dts: apple: s5l8960x: Describe the D2089 charger input + and charge timer + +The A7 iPads' Lightning charger now keeps the D2089's input-suspend bit +(0x10 bit 2) in step with the input limit and restarts the charge timer +at 0x4c8, as iOS 12 does. Give it register 0x10 as its "input" range and +extend the control range from 0x4c0 to 0x4c8, in the iPad Air's and the +iPad mini 2's shared files. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/s5l8960x-air1.dtsi | 9 +++++++-- + arch/arm64/boot/dts/apple/s5l8960x-mini2.dtsi | 9 +++++++-- + 2 files changed, 14 insertions(+), 4 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/s5l8960x-air1.dtsi b/arch/arm64/boot/dts/apple/s5l8960x-air1.dtsi +index a886fbafe..a530dedd3 100644 +--- a/arch/arm64/boot/dts/apple/s5l8960x-air1.dtsi ++++ b/arch/arm64/boot/dts/apple/s5l8960x-air1.dtsi +@@ -161,8 +161,13 @@ pmu_events: interrupt-controller { + */ + tristar_charger: charger@60 { + compatible = "apple,d2089-tristar-charger"; +- reg = <0x60 0x0d>, <0x4c0 0x01>, <0x500 0x04>; +- reg-names = "status", "control", "adc"; ++ /* ++ * The control bank reaches the charge timer at 0x4c8; bit 2 of ++ * 0x10 suspends the charger input, as iOS 12 sets it with every ++ * input-limit write. ++ */ ++ reg = <0x60 0x0d>, <0x4c0 0x09>, <0x500 0x04>, <0x10 0x01>; ++ reg-names = "status", "control", "adc", "input"; + interrupt-parent = <&pmu_events>; + /* + * The PMU line and ADC done. No source events, as on the iPad +diff --git a/arch/arm64/boot/dts/apple/s5l8960x-mini2.dtsi b/arch/arm64/boot/dts/apple/s5l8960x-mini2.dtsi +index de928e2ba..831a8cc69 100644 +--- a/arch/arm64/boot/dts/apple/s5l8960x-mini2.dtsi ++++ b/arch/arm64/boot/dts/apple/s5l8960x-mini2.dtsi +@@ -117,8 +117,13 @@ pmu_events: interrupt-controller { + */ + tristar_charger: charger@60 { + compatible = "apple,d2089-tristar-charger"; +- reg = <0x60 0x0d>, <0x4c0 0x01>, <0x500 0x04>; +- reg-names = "status", "control", "adc"; ++ /* ++ * The control bank reaches the charge timer at 0x4c8; bit 2 of ++ * 0x10 suspends the charger input, as iOS 12 sets it with every ++ * input-limit write. ++ */ ++ reg = <0x60 0x0d>, <0x4c0 0x09>, <0x500 0x04>, <0x10 0x01>; ++ reg-names = "status", "control", "adc", "input"; + interrupt-parent = <&pmu_events>; + /* + * The PMU line and ADC done. No source events, as on the iPad diff --git a/kernel/patches/drivers/power/0063-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch b/kernel/patches/drivers/power/0063-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch new file mode 100644 index 00000000..2c7453d8 --- /dev/null +++ b/kernel/patches/drivers/power/0063-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch @@ -0,0 +1,71 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Tue, 24 Nov 2026 08:05:50 +0100 +Subject: [PATCH] dt-bindings: power: supply: apple,tristar-charger: Add the + D2089 input register + +iOS 12 keeps bit 2 of the D2089's register 0x10 in step with the +charger's input-current limit: set below 75 mA, clear otherwise. The +charger also restarts the PMIC's charge timer through 0x4c8, inside the +existing control bank. + +Allow a fourth register range, "input", for that register, required for +the D2089 and not allowed for the other PMICs. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + .../power/supply/apple,tristar-charger.yaml | 23 +++++++++++++++++++ + 1 file changed, 23 insertions(+) + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +index 8b262fca8..2dbc49e83 100644 +--- a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml ++++ b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +@@ -26,6 +26,23 @@ description: | + + allOf: + - $ref: power-supply.yaml# ++ - if: ++ properties: ++ compatible: ++ contains: ++ const: apple,d2089-tristar-charger ++ then: ++ properties: ++ reg: ++ minItems: 4 ++ reg-names: ++ minItems: 4 ++ else: ++ properties: ++ reg: ++ maxItems: 3 ++ reg-names: ++ maxItems: 3 + + properties: + compatible: +@@ -41,16 +58,22 @@ properties: + - const: apple,d2089-tristar-charger + + reg: ++ minItems: 3 + items: + - description: Charger status register bank. + - description: Charger control register bank. + - description: ADC register bank. ++ - description: | ++ The PMIC register whose bit suspends the charger input (D2089 0x10, ++ bit 2). The charger keeps it in step with the input-current limit. + + reg-names: ++ minItems: 3 + items: + - const: status + - const: control + - const: adc ++ - const: input + + interrupts: + minItems: 2 diff --git a/kernel/patches/drivers/power/0064-power-supply-apple_tristar_charger-Resume-the-D2089-.patch b/kernel/patches/drivers/power/0064-power-supply-apple_tristar_charger-Resume-the-D2089-.patch new file mode 100644 index 00000000..50fbe0f1 --- /dev/null +++ b/kernel/patches/drivers/power/0064-power-supply-apple_tristar_charger-Resume-the-D2089-.patch @@ -0,0 +1,215 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Tue, 24 Nov 2026 08:05:50 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: Resume the D2089 input + and restart its charge timer + +On an iPad Air (J71) at 1 % battery the charger identified a CDP and a +USB-C charger and set the D2089's input limit to 1500 mA, yet the battery +kept discharging. After iBoot had charged it to 7 % while powered off, +the same kernel charged at +823 mA. The register state at 1 % was not +captured; this follows what iOS 12 does instead. + +iOS 12 AppleD2089PMUPowerSource, with every input-limit write +(setInputCurrentLimit), first sets bit 2 of PMIC register 0x10 for a +limit below 75 mA and clears it otherwise. And when the charger state +0x62 reports an expired charge timer (bit 4) and the battery is below +90 %, at most every 300 s, it restarts the timer: it reads 0x4c8, writes +back only bit 3 of it, then the value read. + +Do both on the D2089 only: clear the bit before each limit write (every +limit this driver writes is at least 75 mA), logging the first time it +was found set, and restart an expired charge timer while a source is +attached and the battery charge reads below 90 %, logging each restart. +The D2365, D2207 and D2355 are unchanged. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + drivers/power/supply/apple_tristar_charger.c | 99 +++++++++++++++++++- + 1 file changed, 97 insertions(+), 2 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 79eea8d74..3b850ea38 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -107,6 +107,9 @@ struct tristar_pmic { + u8 adc_result; /* ADC bank: two result bytes */ + bool adc_rearm; /* clear the start bit and latch after a read */ + unsigned int plug_event; /* the event that latches on plug and unplug */ ++ u8 input_suspend; /* input bank: set below 75 mA of input, 0: none */ ++ u8 timeout; /* charger state: the charge timer expired, 0: ignored */ ++ u8 charge_timer; /* control bank: rewritten to restart the charge timer */ + }; + + /* D2365 (iPad 5, iPad 6), from iOS 16 AppleD2365PMUPowerSource */ +@@ -150,6 +153,12 @@ static const struct tristar_pmic tristar_d2207 = { + * 0x502 that iOS scales for channel 6 as this driver does, and is cleared + * through 0x501 and 0x500 after each read. ADC done is event 89; the plug + * event is event 0. ++ * ++ * With every input-limit write, iOS 12 (setInputCurrentLimit) first sets ++ * bit 2 of 0x10 for a limit below 75 mA and clears it otherwise. When the ++ * charger state 0x62 reports an expired charge timer (bit 4) and the ++ * battery is below 90 %, it restarts the timer: it reads 0x4c8, writes ++ * back only bit 3 of it, then the value read ("resetting charge TO"). + */ + static const struct tristar_pmic tristar_d2089 = { + .chip = &tristar_d2365_chip, +@@ -161,6 +170,9 @@ static const struct tristar_pmic tristar_d2089 = { + .adc_result = 0x02, + .adc_rearm = true, + .plug_event = 0, ++ .input_suspend = BIT(2), ++ .timeout = BIT(4), ++ .charge_timer = 0x08, + }; + + /* D2355 reads connection state via its own status callback and a companion ADC. */ +@@ -208,6 +220,10 @@ static const struct tristar_pmic tristar_d2355 = { + #define TRISTAR_EVENT_DEBOUNCE_MS 50 + /* More source events than this per second means something is stuck. */ + #define TRISTAR_IRQ_STORM 200 ++/* iOS 12 restarts an expired D2089 charge timer at most this often ... */ ++#define TRISTAR_TIMER_RESTART_MS 300000 ++/* ... and only below this battery charge. */ ++#define TRISTAR_TIMER_RESTART_BELOW 90 + + enum tristar_phase { + TRISTAR_EMPTY, +@@ -247,6 +263,7 @@ struct tristar_charger { + u32 status_base; + u32 control_base; + u32 adc_base; ++ u32 input_base; + unsigned int max_ma; + struct iio_channel *vbus; + bool vbus_fault; +@@ -301,6 +318,10 @@ struct tristar_charger { + struct tristar_accessory *acc; + /* USB data is on, but the device controller is held off for a USB host role. */ + bool usb_held; ++ /* The input-suspend bit was found set once: later finds are debug output. */ ++ bool input_suspend_seen; ++ /* Last charge-timer restart in this attachment, 0: none */ ++ u64 timer_ns; + }; + + static unsigned int tristar_d2365_code_ma(struct tristar_charger *chg, unsigned int code) +@@ -321,9 +342,44 @@ static int tristar_d2365_read_limit(struct tristar_charger *chg, + chg->control_base + chg->pmic->input_limit, code); + } + ++/* ++ * As iOS 12 does on the D2089 with every input-limit write: suspend the ++ * input below 75 mA, resume it otherwise. Every limit this driver writes is ++ * at least 75 mA, so in practice this resumes an input left suspended. ++ */ ++static int tristar_input_suspend(struct tristar_charger *chg, unsigned int code) ++{ ++ u8 bit = chg->pmic->input_suspend; ++ bool suspend = chg->chip->code_ma(chg, code) < 75; ++ unsigned int value; ++ int ret; ++ ++ ret = regmap_read(chg->regmap, chg->input_base, &value); ++ if (ret || !!(value & bit) == suspend) ++ return ret; ++ if (!suspend) { ++ if (!READ_ONCE(chg->input_suspend_seen)) { ++ WRITE_ONCE(chg->input_suspend_seen, true); ++ dev_info(chg->dev, "charger input was suspended (%#x = %#x); resuming it\n", ++ chg->input_base, value); ++ } else { ++ dev_dbg(chg->dev, "charger input was suspended (%#x = %#x); resuming it\n", ++ chg->input_base, value); ++ } ++ } ++ return regmap_update_bits(chg->regmap, chg->input_base, bit, suspend ? bit : 0); ++} ++ + static int tristar_d2365_write_limit(struct tristar_charger *chg, + unsigned int code) + { ++ int ret; ++ ++ if (chg->pmic->input_suspend) { ++ ret = tristar_input_suspend(chg, code); ++ if (ret) ++ return ret; ++ } + return regmap_write(chg->regmap, + chg->control_base + chg->pmic->input_limit, code); + } +@@ -931,6 +987,7 @@ static void tristar_new_attachment(struct tristar_charger *chg, u64 now) + chg->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; + chg->cable_known = false; + chg->epoch_seen = atomic_read(&chg->epoch); ++ chg->timer_ns = 0; + WRITE_ONCE(chg->line_ns, 0); + if (tristar_set_code(chg, chg->chip->attach_code)) + dev_crit(chg->dev, "Attach write failed; input limit unverified\n"); +@@ -1267,6 +1324,40 @@ static bool tristar_input_present(struct tristar_charger *chg) + return chg->present || (connected & chg->pmic->connected_new); + } + ++/* ++ * The PMIC's charge timer expired: it stopped charging the battery. iOS 12 ++ * restarts the D2089's timer while the battery is below 90 %, at most every ++ * five minutes, by rewriting the charger control register at 0x4c8 with only ++ * bit 3 and then with its value. Do the same while a source is attached. ++ * Without a readable battery charge, leave the timer as the PMIC set it. ++ * Caller holds lock. ++ */ ++static void tristar_restart_timer(struct tristar_charger *chg, unsigned int status, u64 now) ++{ ++ unsigned int reg = chg->control_base + chg->pmic->charge_timer, value; ++ struct tristar_pack pack; ++ int ret; ++ ++ if (!chg->pmic->timeout || !(status & chg->pmic->timeout)) ++ return; ++ if (chg->timer_ns && ++ (s64)(now - chg->timer_ns) < (s64)TRISTAR_TIMER_RESTART_MS * NSEC_PER_MSEC) ++ return; ++ if (tristar_read_pack(chg, &pack) || pack.capacity >= TRISTAR_TIMER_RESTART_BELOW) ++ return; ++ chg->timer_ns = now ?: 1; ++ ret = regmap_read(chg->regmap, reg, &value); ++ if (!ret) ++ ret = regmap_write(chg->regmap, reg, value & BIT(3)); ++ if (!ret) ++ ret = regmap_write(chg->regmap, reg, value); ++ if (ret) ++ dev_err(chg->dev, "charge timer restart failed (%d)\n", ret); ++ else ++ dev_info(chg->dev, "charge timer expired (status %#x) at %d %%; restarted it (%#x = %#x)\n", ++ status, pack.capacity, reg, value); ++} ++ + static void tristar_poll(struct work_struct *work) + { + unsigned long ramp_delay = 0; +@@ -1317,6 +1408,7 @@ static void tristar_poll(struct work_struct *work) + tristar_new_attachment(chg, now); + goto again; + } ++ tristar_restart_timer(chg, status, now); + if (IS_REACHABLE(CONFIG_IIO) && chg->vbus && !chg->vbus_fault && + (chg->phase == TRISTAR_RAMPING || chg->phase == TRISTAR_CHARGING) && + tristar_code_ma(chg, chg->target_code) > 1000) { +@@ -1737,9 +1829,12 @@ static int tristar_probe(struct platform_device *pdev) + &chg->status_base); + if (!ret) + ret = tristar_get_bank(dev, "control", +- max_t(unsigned int, chg->chip->control_size, +- chg->pmic->input_limit + 1), ++ max3(chg->chip->control_size, ++ chg->pmic->input_limit + 1u, ++ chg->pmic->timeout ? chg->pmic->charge_timer + 1u : 0u), + &chg->control_base); ++ if (!ret && chg->pmic->input_suspend) ++ ret = tristar_get_bank(dev, "input", 1, &chg->input_base); + if (!ret) + ret = tristar_get_bank(dev, "adc", chg->pmic->adc_result + 2, &chg->adc_base); + if (ret)