From 2bbdaa3209a13653b63a2e5c3f48e878732db9d3 Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Sat, 21 Nov 2026 20:49:07 +0100 Subject: [PATCH 1/5] j81: charging The iPad Air 2 drained on a cable: iBoot leaves the D2207 PMIC's input current limit at 100 mA and nothing raised it. The Lightning charger driver now supports the D2207 (its charger registers, ADC and plug state, as iOS 15.8 uses them), and the J81 device tree describes the Tristar and the charger. A computer's charging port or an Apple adapter gets up to 1.5 A. Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 3 + devices/j81/device.toml | 4 +- docs/compatibility.md | 3 +- ...le-t7001-air2-Add-Lightning-charging.patch | 105 ++++++ ...r-supply-apple-tristar-charger-Add-t.patch | 77 +++++ ...le_tristar_charger-Support-the-D2207.patch | 311 ++++++++++++++++++ 6 files changed, 500 insertions(+), 3 deletions(-) create mode 100644 kernel/patches/devices/t7001/0012-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch create mode 100644 kernel/patches/drivers/power/0040-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch create mode 100644 kernel/patches/drivers/power/0041-power-supply-apple_tristar_charger-Support-the-D2207.patch diff --git a/CHANGELOG.md b/CHANGELOG.md index 92ec8554..a55c9f37 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,9 @@ is missing or empty. - iPad Air 2 (Wi-Fi): internal storage works, so Omarchy installs with `orchard install` and starts from the iPad with `orchard launch`, next to iPadOS. The A8X storage controller (ANS1) has a kernel driver now. +- iPad Air 2 (Wi-Fi): it charges. The Lightning charger driver supports the + iPad Air 2's D2207 PMIC, so a computer's charging port or an Apple adapter + gets up to 1.5 A instead of iBoot's 100 mA. ### Install & launch diff --git a/devices/j81/device.toml b/devices/j81/device.toml index a2c90ee6..c9ff3eee 100644 --- a/devices/j81/device.toml +++ b/devices/j81/device.toml @@ -46,8 +46,8 @@ bluetooth_input = "untested" bluetooth_audio = "untested" cellular = "none" battery = "working" -charging = "missing" -charging_control = "missing" +charging = "working" # Mac USB-C port (BC1.2 charging port) and Apple USB-C adapter: 1500 mA; installed Omarchy and RAM boot; J81 2026-11-21 +charging_control = "working" # source identified at each plug and after sleep, grant withdrawn on unplug; J81 2026-11-21 suspend = "untested" resume = "untested" usb_serial = "working" diff --git a/docs/compatibility.md b/docs/compatibility.md index 23a88477..f42e4e98 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -154,7 +154,7 @@ Boards Orchard builds for. States: working, untested, missing, none (no such har | `j97` | untested | missing | untested | untested | untested | missing | missing | missing | missing | missing | missing | untested | missing | missing | missing | untested | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | | `n56` | untested | missing | untested | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | | `n61` | working | untested | untested | working | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | missing | missing | untested | untested | working | untested | missing | missing | missing | missing | missing | -| `j81` | working | untested | working | working | working | missing | missing | missing | missing | working | working | working | untested | untested | none | working | missing | missing | untested | untested | working | working | missing | missing | missing | missing | missing | +| `j81` | working | untested | working | working | working | missing | missing | missing | missing | working | working | working | untested | untested | none | working | working | working | untested | untested | working | working | missing | missing | missing | missing | missing | | `j82` | untested | untested | untested | untested | untested | missing | missing | missing | missing | missing | missing | untested | untested | untested | missing | untested | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | | `j71s` | untested | untested | untested | untested | untested | untested | untested | untested | missing | missing | missing | missing | untested | untested | none | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | | `j72s` | untested | untested | untested | untested | untested | untested | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | @@ -250,6 +250,7 @@ A yes means an enabled device tree node binds a driver in `7.3.0-rc1-orchard-app | --- | --- | --- | | `j81` | Internal storage read | working, but no driver binds | | `j81` | Internal storage write | working, but no driver binds | +| `j81` | Charging | working, but no driver binds | | `j71s` | Microphone | untested, but no driver binds | | `j72s` | Microphone | untested, but no driver binds | | `j71t` | Microphone | working, but no driver binds | diff --git a/kernel/patches/devices/t7001/0012-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch b/kernel/patches/devices/t7001/0012-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch new file mode 100644 index 00000000..a0a676a4 --- /dev/null +++ b/kernel/patches/devices/t7001/0012-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch @@ -0,0 +1,105 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Add Lightning charging + +iBoot leaves the D2207's input-current limit at 100 mA, so the iPad Air 2 +drains on a cable. Describe the Tristar (CBTL1610) at i2c0 0x1a and the +Lightning charger on the PMIC, with the PMU line (112) and ADC done (89). +The ADT's charger node allows 0x960 = 2400 mA of input. Link the charger +to the USB device controller, which reports the host's allowance to it. + +No source events. With the plug event (0) subscribed, it stays unmasked +when the iPad is reset into DFU from a running Linux; that reset skips +iBoot, which would mask it. The cable replugs of the next boot latch it, +and that boot froze before userspace, then the watchdog reset it: 4 to 5 +times out of 5 after a charging session. Without it, 3 of 3 such resets +booted. The charger's 100 ms poll of the connection state sees plug and +unplug instead. + +On a J81 the charger identifies a Mac's USB-C port as a BC1.2 charging +port and an Apple USB-C power adapter by its 1.5 A advertisement, and +grants 1500 mA for both; the battery goes from about -0.7 A to +0.9 A. +Unplugging withdraws the grant, and the next plug identifies the source +again. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 49 +++++++++++++++++++++++ + 1 file changed, 49 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index 246790a7f..d6092dcc3 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -130,6 +130,12 @@ &serial0 { + &i2c0 { + status = "okay"; + ++ /* The Lightning port controller, from the ADT i2c0/tristar node. */ ++ tristar: port-controller@1a { ++ compatible = "nxp,cbtl1610"; ++ reg = <0x1a>; ++ }; ++ + pmic@3c { + compatible = "apple,arabela-pmic", "apple,i2c-pmic"; + reg = <0x3c>; +@@ -155,6 +161,37 @@ pmu_gpio: gpio { + apple,wake-events = <0x24>; + }; + ++ /* ++ * Lightning charging, at the D2207's registers as iOS 15.8 ++ * AppleD2207PMU uses them: connection and charger state at ++ * 0x60, the input-current limit at 0x4c0, the ADC at 0x500. ++ * The ADT's charger node allows 0x960 = 2400 mA of input. ++ */ ++ tristar_charger: charger@60 { ++ compatible = "apple,j81-tristar-charger", "apple,d2207-tristar-charger"; ++ reg = <0x60 0x0d>, <0x4c0 0x01>, <0x500 0x04>; ++ reg-names = "status", "control", "adc"; ++ interrupt-parent = <&pmu_gpio>; ++ /* ++ * The PMU line and ADC done. No source events: the plug ++ * event (0) stays unmasked across a reset that bypasses ++ * iBoot (DFU entered from Linux), latches on the replugs ++ * of the next boot and froze that boot. The charger's ++ * 100 ms poll of 0x60 sees plug and unplug. ++ */ ++ interrupts = <112 IRQ_TYPE_EDGE_RISING>, ++ <89 IRQ_TYPE_EDGE_RISING>; ++ apple,tristar = <&tristar>; ++ input-current-limit-microamp = <2400000>; ++ ++ /* The charger decides when USB data may come on. */ ++ port { ++ tristar_charger_usb: endpoint { ++ remote-endpoint = <&usbdev_role>; ++ }; ++ }; ++ }; ++ + rtc@5c0 { + compatible = "apple,arabela-pmic-rtc", "apple,amber-pmic-rtc"; + reg = <0x5c0 0x10>; +@@ -259,6 +296,18 @@ &touchclk { + status = "okay"; + }; + ++/* Tell the Lightning charger what the USB host allows. */ ++&usbdev { ++ usb-psy-name = "lightning"; ++ usb-role-switch; ++ ++ port { ++ usbdev_role: endpoint { ++ remote-endpoint = <&tristar_charger_usb>; ++ }; ++ }; ++}; ++ + /* + * The BCM4350C2's Bluetooth on UART3, from the ADT uart3/bluetooth node: + * power enable on D2207 GPIO 2, BT_WAKE on GPIO 164. m1n1 adds the device diff --git a/kernel/patches/drivers/power/0040-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch b/kernel/patches/drivers/power/0040-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch new file mode 100644 index 00000000..c2f2620b --- /dev/null +++ b/kernel/patches/drivers/power/0040-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch @@ -0,0 +1,77 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] dt-bindings: power: supply: apple,tristar-charger: Add the + D2207 + +The iPad Air 2 charges through the same Tristar port controller, with a +D2207 PMIC instead of a D2365. The D2207 has the same charger functions +at other register addresses, so its compatible names the PMIC: +apple,d2207-tristar-charger, with apple,j81-tristar-charger for the +board. + +The source events become optional: the iPad Air 2 subscribes none (see +its device tree), and the charger's poll of the connection state notices +a change without them. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + .../power/supply/apple,tristar-charger.yaml | 23 ++++++++++++------- + 1 file changed, 15 insertions(+), 8 deletions(-) + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +index c8556e9c3..8e4acf9f7 100644 +--- a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml ++++ b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +@@ -11,7 +11,9 @@ maintainers: + + description: | + Charging on Apple devices whose Lightning port uses a Tristar (NXP CBTL1610) +- port controller and a D2365-family PMIC, such as the iPad 5 and iPad 6. The ++ port controller and a D2365-family PMIC, such as the iPad 5 and iPad 6 (D2365) ++ and the iPad Air 2 (D2207). The PMICs have the same charger functions at ++ different register addresses, so the compatible names the PMIC. The + node is a child of the PMIC. It identifies the attached source through the + Tristar and the PMIC ADC and sets the PMIC input-current limit, which iBoot + leaves at 100 mA. PMU events come from the PMIC's event interrupt +@@ -27,11 +29,15 @@ allOf: + + properties: + compatible: +- items: +- - enum: +- - apple,j71b-tristar-charger +- - apple,j71t-tristar-charger +- - const: apple,tristar-charger ++ oneOf: ++ - items: ++ - enum: ++ - apple,j71b-tristar-charger ++ - apple,j71t-tristar-charger ++ - const: apple,tristar-charger ++ - items: ++ - const: apple,j81-tristar-charger ++ - const: apple,d2207-tristar-charger + + reg: + items: +@@ -46,7 +52,7 @@ properties: + - const: adc + + interrupts: +- minItems: 3 ++ minItems: 2 + maxItems: 16 + description: | + From the PMIC's event interrupt controller. The first is the PMU event +@@ -54,7 +60,8 @@ properties: + withdraws a grant there, before it knows which event it was. The + second is ADC conversion complete. Every further entry is an event + that can signal a change of the attached source (attach, detach, +- charger state); any of them starts a new identification. ++ charger state); any of them starts a new identification. Without ++ them, the charger's poll of the connection state notices a change. + + apple,tristar: + $ref: /schemas/types.yaml#/definitions/phandle diff --git a/kernel/patches/drivers/power/0041-power-supply-apple_tristar_charger-Support-the-D2207.patch b/kernel/patches/drivers/power/0041-power-supply-apple_tristar_charger-Support-the-D2207.patch new file mode 100644 index 00000000..e0a674d6 --- /dev/null +++ b/kernel/patches/drivers/power/0041-power-supply-apple_tristar_charger-Support-the-D2207.patch @@ -0,0 +1,311 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: Support the D2207 + +The iPad Air 2's D2207 has the D2365's charger functions at other +addresses, as iOS 15.8's AppleD2207PMU accesses them: + + function D2365 (bank + offset) D2207 + connection state status + 0x09 0x60 + "new connection" bit bit 1 bit 3 + charger state status + 0x0a 0x62 + input-current limit control + 0x03 0x4c0 + ADC start adc + 0, value 1 0x500, 0x80 | channel 6 + ADC result adc + 1 0x502 + plug event 72 0 + +The input-limit encoding (mA = code * 12.5 + 75) and the ADC result +format are the same. After reading a D2207 conversion, iOS clears the +start bit and the latch in 0x501; do the same. + +Describe each PMIC in match data and compute the register addresses at +probe. apple,tristar-charger keeps the D2365 layout. + +Accept a node without source events: the 100 ms poll reads the +connection state and starts the identification on its own. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + drivers/power/supply/apple_tristar_charger.c | 131 +++++++++++++------ + 1 file changed, 94 insertions(+), 37 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 66d169810..f2c11557c 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -1,7 +1,7 @@ + // SPDX-License-Identifier: GPL-2.0-only + /* + * Lightning charging for Apple devices with a Tristar (CBTL1610) port +- * controller and a D2365-family PMIC. ++ * controller and a D2365-family PMIC (D2365, or the iPad Air 2's D2207). + * + * iBoot leaves the PMIC input-current limit at 100 mA. On every attachment + * this driver identifies the source and grants what it advertises, up to the +@@ -57,21 +57,60 @@ + + #include "apple_tristar_accessory.h" + +-/* PMIC registers, relative to their banks */ +-#define TRISTAR_CHG_CONNECTED 0x09 /* status bank */ ++/* PMIC connection state: bit 0 is "connected" on every PMIC */ + #define TRISTAR_CHG_CONNECTED_NOW BIT(0) +-#define TRISTAR_CHG_CONNECTED_NEW BIT(1) +-#define TRISTAR_CHG_STATUS 0x0a /* status bank */ +-#define TRISTAR_CHG_INPUT_LIMIT 0x03 /* control bank */ +-#define TRISTAR_CHG_ADC_SELECT 0x00 /* ADC bank */ +-#define TRISTAR_CHG_ADC_RESULT 0x01 ++#define TRISTAR_CHG_ADC_START BIT(7) /* D2207 ADC control */ ++#define TRISTAR_CHG_ADC_LATCH GENMASK(7, 3) /* D2207 ADC control + 1 */ ++ ++/* ++ * Where a PMIC keeps the charger registers, relative to the banks the ++ * device tree gives, and how its ADC is driven. The functions are the same ++ * on both PMICs; the addresses are not. ++ */ ++struct tristar_pmic { ++ u8 connected; /* status bank: connection state */ ++ u8 connected_new; /* the bit that also marks a new connection */ ++ u8 status; /* status bank: battery charger state */ ++ u8 input_limit; /* control bank: input-current limit */ ++ u8 adc_start; /* written to the ADC bank to start a conversion */ ++ 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 */ ++}; ++ ++/* D2365 (iPad 5, iPad 6), from iOS 16 AppleD2365PMUPowerSource */ ++static const struct tristar_pmic tristar_d2365 = { ++ .connected = 0x09, ++ .connected_new = BIT(1), ++ .status = 0x0a, ++ .input_limit = 0x03, ++ .adc_start = 0x01, ++ .adc_result = 0x01, ++ .plug_event = 72, ++}; ++ ++/* ++ * D2207 (iPad Air 2), from iOS 15.8 AppleD2207PMU: connection state 0x60, ++ * charger state 0x62, input limit 0x4c0, ADC control 0x500 with the result ++ * at 0x502. A conversion starts with bit 7 and the channel, 6 for the ++ * Tristar's BrickID line; iOS clears the start bit and the latch in 0x501 ++ * after each read. The plug event is event 0. ++ */ ++static const struct tristar_pmic tristar_d2207 = { ++ .connected = 0x00, ++ .connected_new = BIT(3), ++ .status = 0x02, ++ .input_limit = 0x00, ++ .adc_start = TRISTAR_CHG_ADC_START | 6, ++ .adc_result = 0x02, ++ .adc_rearm = true, ++ .plug_event = 0, ++}; + + /* Interrupts: the PMU line, ADC completion, then the source-change events. */ + #define TRISTAR_IRQ_LINE 0 + #define TRISTAR_IRQ_ADC 1 + #define TRISTAR_IRQ_SOURCE 2 +-/* The D2365 event that latches on every plug and unplug. */ +-#define TRISTAR_EVENT_PLUG 72 + #define TRISTAR_IRQS_MAX 16 + + /* Input-current limit encoding: mA = code * 12.5 + 75 */ +@@ -136,8 +175,10 @@ struct tristar_charger { + int irqs[TRISTAR_IRQS_MAX]; + unsigned int nirqs; + int plug_irq; /* wakes the system, 0 without one */ +- u32 status_base; +- u32 control_base; ++ const struct tristar_pmic *pmic; ++ u32 connected_reg; ++ u32 status_reg; ++ u32 limit_reg; + u32 adc_base; + unsigned int max_ma; + +@@ -206,7 +247,7 @@ static unsigned int tristar_ma_code(unsigned int ma) + + static int tristar_set_code(struct tristar_charger *chg, unsigned int code) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int readback; + int ret; + +@@ -425,7 +466,7 @@ static int tristar_adc_mv(struct tristar_charger *chg, unsigned int epoch, + + reinit_completion(&chg->adc_done); + WRITE_ONCE(chg->adc_waiting, true); +- ret = regmap_write(chg->regmap, chg->adc_base + TRISTAR_CHG_ADC_SELECT, 1); ++ ret = regmap_write(chg->regmap, chg->adc_base, chg->pmic->adc_start); + if (ret) { + WRITE_ONCE(chg->adc_waiting, false); + return ret; +@@ -436,8 +477,15 @@ static int tristar_adc_mv(struct tristar_charger *chg, unsigned int epoch, + } + if (READ_ONCE(chg->epoch) != epoch) + return -ESTALE; +- ret = regmap_bulk_read(chg->regmap, chg->adc_base + TRISTAR_CHG_ADC_RESULT, ++ ret = regmap_bulk_read(chg->regmap, chg->adc_base + chg->pmic->adc_result, + value, sizeof(value)); ++ if (!ret && chg->pmic->adc_rearm) { ++ ret = regmap_update_bits(chg->regmap, chg->adc_base, ++ TRISTAR_CHG_ADC_START, 0); ++ if (!ret) ++ ret = regmap_update_bits(chg->regmap, chg->adc_base + 1, ++ TRISTAR_CHG_ADC_LATCH, 0); ++ } + if (ret) + return ret; + if (value[0] & 0x80) +@@ -958,7 +1006,7 @@ static unsigned long tristar_ramp_delay(struct tristar_charger *chg, u64 now) + */ + static void tristar_check_limit(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int hw, code = chg->code; + + if (regmap_read(chg->regmap, reg, &hw) || hw == code) +@@ -1053,7 +1101,8 @@ static void tristar_follow_accessory(struct tristar_charger *chg, u64 now) + /* + * Input presence is the D2365's connection state 0x189, as iOS 16 decides it + * (AppleD2365PMUPowerSource): bit 0 is "connected", and a new connection also +- * needs bit 1. The charger status 0x18a is not presence. Its bits describe ++ * needs bit 1. The D2207's 0x60 has the same meaning, with bit 3 for a new ++ * connection (iOS 15.8 AppleD2207PMU). The charger status 0x18a is not presence. Its bits describe + * the battery charger: the same method takes bits 1:0 as charging, bit 2 as + * charge end and bit 4 as charge timeout, for the charging and fully charged + * state only. It can also read 0 with the input still there: behind the +@@ -1063,21 +1112,20 @@ static void tristar_follow_accessory(struct tristar_charger *chg, u64 now) + * the PMIC reports input limiting, which the D2365 never does, so a charger + * that finished, timed out or does not charge keeps the grant. + * +- * Every board this driver binds has a D2365: the status, control and ADC +- * registers above are the D2365's. An unreadable 0x189 says nothing: keep +- * the last decision. ++ * The D2207's charger state 0x62 has the same bits. An unreadable connection ++ * state says nothing: keep the last decision. + */ + static bool tristar_input_present(struct tristar_charger *chg) + { + unsigned int connected; + +- if (regmap_read(chg->regmap, chg->status_base + TRISTAR_CHG_CONNECTED, &connected)) { ++ if (regmap_read(chg->regmap, chg->connected_reg, &connected)) { + dev_err_ratelimited(chg->dev, "PMIC connection state unreadable\n"); + return chg->online; + } + if (!(connected & TRISTAR_CHG_CONNECTED_NOW)) + return false; +- return chg->present || (connected & TRISTAR_CHG_CONNECTED_NEW); ++ return chg->present || (connected & chg->pmic->connected_new); + } + + static void tristar_poll(struct work_struct *work) +@@ -1096,7 +1144,7 @@ static void tristar_poll(struct work_struct *work) + old_online = chg->online; + old_present = chg->present; + old_usb_on = chg->usb_on; +- if (regmap_read(chg->regmap, chg->status_base + TRISTAR_CHG_STATUS, &status)) { ++ if (regmap_read(chg->regmap, chg->status_reg, &status)) { + tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); + dev_err_ratelimited(chg->dev, "PMIC status unreadable; holding the fallback\n"); + goto again; +@@ -1186,7 +1234,7 @@ static void tristar_poll(struct work_struct *work) + */ + static bool tristar_event_withdraw(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int readback; + + if (READ_ONCE(chg->code) <= TRISTAR_CHG_FALLBACK_CODE) +@@ -1236,7 +1284,7 @@ static bool tristar_event_debounce(struct tristar_charger *chg) + */ + static void tristar_source_event(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int i; + u64 now; + +@@ -1473,7 +1521,7 @@ static int tristar_probe(struct platform_device *pdev) + struct tristar_charger *chg; + struct device_node *np; + unsigned int code, i; +- u32 max_ua; ++ u32 max_ua, base; + int ret; + + chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); +@@ -1484,12 +1532,20 @@ static int tristar_probe(struct platform_device *pdev) + if (!chg->regmap) + return dev_err_probe(dev, -ENODEV, "parent regmap unavailable\n"); + +- ret = tristar_get_bank(dev, "status", TRISTAR_CHG_STATUS + 1, &chg->status_base); +- if (!ret) +- ret = tristar_get_bank(dev, "control", TRISTAR_CHG_INPUT_LIMIT + 1, +- &chg->control_base); +- if (!ret) +- ret = tristar_get_bank(dev, "adc", TRISTAR_CHG_ADC_RESULT + 2, &chg->adc_base); ++ chg->pmic = device_get_match_data(dev); ++ if (!chg->pmic) ++ return -ENODEV; ++ ret = tristar_get_bank(dev, "status", ++ max(chg->pmic->connected, chg->pmic->status) + 1, &base); ++ if (ret) ++ return ret; ++ chg->connected_reg = base + chg->pmic->connected; ++ chg->status_reg = base + chg->pmic->status; ++ ret = tristar_get_bank(dev, "control", chg->pmic->input_limit + 1, &base); ++ if (ret) ++ return ret; ++ chg->limit_reg = base + chg->pmic->input_limit; ++ ret = tristar_get_bank(dev, "adc", chg->pmic->adc_result + 2, &chg->adc_base); + if (ret) + return ret; + +@@ -1524,16 +1580,16 @@ static int tristar_probe(struct platform_device *pdev) + ret = platform_irq_count(pdev); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to count the PMU event interrupts\n"); +- if (ret <= TRISTAR_IRQ_SOURCE || ret > TRISTAR_IRQS_MAX) ++ if (ret < TRISTAR_IRQ_SOURCE || ret > TRISTAR_IRQS_MAX) + return dev_err_probe(dev, -EINVAL, +- "expected PMU line, ADC and source event interrupts\n"); ++ "expected the PMU line and ADC interrupts\n"); + chg->nirqs = ret; + for (i = 0; i < chg->nirqs; i++) { + chg->irqs[i] = platform_get_irq(pdev, i); + if (chg->irqs[i] < 0) + return chg->irqs[i]; + if (i >= TRISTAR_IRQ_SOURCE && +- irqd_to_hwirq(irq_get_irq_data(chg->irqs[i])) == TRISTAR_EVENT_PLUG) ++ irqd_to_hwirq(irq_get_irq_data(chg->irqs[i])) == chg->pmic->plug_event) + chg->plug_irq = chg->irqs[i]; + } + +@@ -1551,7 +1607,7 @@ static int tristar_probe(struct platform_device *pdev) + return ret; + + /* Never adopt a limit we cannot explain; anything higher drops to the fallback. */ +- ret = regmap_read(chg->regmap, chg->control_base + TRISTAR_CHG_INPUT_LIMIT, &code); ++ ret = regmap_read(chg->regmap, chg->limit_reg, &code); + if (ret) + return dev_err_probe(dev, ret, "failed to read the input-current limit\n"); + chg->code = code; +@@ -1713,7 +1769,8 @@ static const struct dev_pm_ops tristar_pm_ops = { + }; + + static const struct of_device_id tristar_of_match[] = { +- { .compatible = "apple,tristar-charger" }, ++ { .compatible = "apple,d2207-tristar-charger", .data = &tristar_d2207 }, ++ { .compatible = "apple,tristar-charger", .data = &tristar_d2365 }, + { } + }; + MODULE_DEVICE_TABLE(of, tristar_of_match); From 66e06b82e778465569588bb3569cf6f115106538 Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:54:07 +0800 Subject: [PATCH 2/5] j81: the speakers work (from #192) SmartIO on the A8/A8X (AppleA7IOP version 1), MCA version 1 in the S8000 MCA driver, the MAX98721 speaker amplifier driver, the T7001 NCO, the device tree and a UCM profile; both speakers play in stereo. The headphone jack and the microphones are not part of it. Squashed from ricktav's j81/audio (17aa5eb1); patch files renumbered to follow main. --- devices/j81/device.toml | 2 +- devices/j81/firmware.json | 19 + docs/j81-audio.md | 137 ++++ kernel/configs/apple-16k/config | 4 +- kernel/configs/apple-4k/config | 4 +- ...m64-dts-apple-t7001-air2-Enable-I2C1.patch | 36 + ...ple-t7001-Add-the-speaker-audio-path.patch | 107 +++ ...-dts-apple-t7001-air2-Enable-SmartIO.patch | 33 + ...e-t7001-air2-Enable-the-speaker-link.patch | 54 ++ ...ts-apple-t7001-air2-Add-the-speakers.patch | 142 ++++ ...-apple-nco-Add-the-T7001-A8X-variant.patch | 95 +++ ...bindings-dma-apple-sio-Add-the-T7000.patch | 82 ++ ...pport-the-T7000-AppleA7IOP-version-1.patch | 374 ++++++++++ ...nd-apple-s8000-mca-Add-the-T7001-MCA.patch | 70 ++ ...8000-mca-Add-the-T7001-MCA-version-1.patch | 706 ++++++++++++++++++ ...ound-maxim-max98925-Add-the-MAX98721.patch | 104 +++ ...the-Maxim-MAX98721-speaker-amplifier.patch | 495 ++++++++++++ ...-mfd-syscon-Add-the-T7001-i2s-switch.patch | 30 + ...ndings-clock-apple-nco-Add-the-T7001.patch | 29 + ...d-apple-s8000-mca-Allow-a-graph-port.patch | 34 + ...-card2-Fix-the-multi-port-references.patch | 108 +++ src/orchard/apple/smartio.py | 6 +- .../alsa/ucm2/Orchard/ipad-air2/HiFi.conf | 28 + .../conf.d/J81_Speakers/J81 Speakers.conf | 10 + tools/catalog/drivers.json | 1 + 25 files changed, 2705 insertions(+), 5 deletions(-) create mode 100644 docs/j81-audio.md create mode 100644 kernel/patches/devices/t7001/0013-arm64-dts-apple-t7001-air2-Enable-I2C1.patch create mode 100644 kernel/patches/devices/t7001/0014-arm64-dts-apple-t7001-Add-the-speaker-audio-path.patch create mode 100644 kernel/patches/devices/t7001/0015-arm64-dts-apple-t7001-air2-Enable-SmartIO.patch create mode 100644 kernel/patches/devices/t7001/0016-arm64-dts-apple-t7001-air2-Enable-the-speaker-link.patch create mode 100644 kernel/patches/devices/t7001/0017-arm64-dts-apple-t7001-air2-Add-the-speakers.patch create mode 100644 kernel/patches/drivers/clk/0009-clk-apple-nco-Add-the-T7001-A8X-variant.patch create mode 100644 kernel/patches/drivers/soc-apple/0031-dt-bindings-dma-apple-sio-Add-the-T7000.patch create mode 100644 kernel/patches/drivers/soc-apple/0032-soc-apple-sio-Support-the-T7000-AppleA7IOP-version-1.patch create mode 100644 kernel/patches/drivers/sound/0020-dt-bindings-sound-apple-s8000-mca-Add-the-T7001-MCA.patch create mode 100644 kernel/patches/drivers/sound/0021-ASoC-apple-s8000-mca-Add-the-T7001-MCA-version-1.patch create mode 100644 kernel/patches/drivers/sound/0022-dt-bindings-sound-maxim-max98925-Add-the-MAX98721.patch create mode 100644 kernel/patches/drivers/sound/0023-ASoC-codecs-Add-the-Maxim-MAX98721-speaker-amplifier.patch create mode 100644 kernel/patches/drivers/sound/0024-dt-bindings-mfd-syscon-Add-the-T7001-i2s-switch.patch create mode 100644 kernel/patches/drivers/sound/0025-dt-bindings-clock-apple-nco-Add-the-T7001.patch create mode 100644 kernel/patches/drivers/sound/0026-dt-bindings-sound-apple-s8000-mca-Allow-a-graph-port.patch create mode 100644 kernel/patches/drivers/sound/0027-ASoC-audio-graph-card2-Fix-the-multi-port-references.patch create mode 100644 system/defaults/usr/share/alsa/ucm2/Orchard/ipad-air2/HiFi.conf create mode 100644 system/defaults/usr/share/alsa/ucm2/conf.d/J81_Speakers/J81 Speakers.conf diff --git a/devices/j81/device.toml b/devices/j81/device.toml index a2c90ee6..a77c719b 100644 --- a/devices/j81/device.toml +++ b/devices/j81/device.toml @@ -53,7 +53,7 @@ resume = "untested" usb_serial = "working" usb_network = "working" usb_host = "missing" -audio_output = "missing" +audio_output = "working" # Both speakers (MAX98721 on MCA3); tested 2026-11-20. The headphone jack (CS42L81) is not supported yet. audio_input = "missing" camera = "missing" video_decode_hevc = "missing" diff --git a/devices/j81/firmware.json b/devices/j81/firmware.json index e40065ed..c6889d6e 100644 --- a/devices/j81/firmware.json +++ b/devices/j81/firmware.json @@ -133,6 +133,14 @@ "rootfs": "usr/sbin/BlueTool" }, "device": "/usr/sbin/BlueTool" + }, + "kernelcache": { + "ipsw": { + "kernelcache": true + }, + "device": { + "kernelcache": "active" + } } }, "outputs": [ @@ -318,6 +326,17 @@ "input": "BlueTool" } ] + }, + { + "destination": "lib/firmware/apple/t7000-smartio.bin", + "sha256": "5fc96ee702d88b9a8f6a2526f566dd266c6c0d463b10490ba288db8e77434bd3", + "steps": [ + { + "step": "smartio-from-kernelcache@2", + "input": "kernelcache", + "kext": "com.apple.driver.AppleT7000SmartIO" + } + ] } ] } diff --git a/docs/j81-audio.md b/docs/j81-audio.md new file mode 100644 index 00000000..88e24611 --- /dev/null +++ b/docs/j81-audio.md @@ -0,0 +1,137 @@ +# J81 (iPad Air 2) audio bring-up + +Working notes for speaker and headphone audio on the iPad Air 2 (J81, A8X / +T7001). Status: **both speakers play**, from a RAM boot and from an installed +Omarchy through PipeWire (`audio_output` is `working`). The headphone codec +and the microphones are not supported yet (`audio_input` stays `missing`). + +Sources: +- Apple's device tree `Firmware/all_flash/DeviceTree.j81ap.im4p` + (sha256 `3021ec21…a48e`, as pinned in `devices/j81/boot.json`). +- The kernelcache `kernelcache.release.ipad5b` (19H422, sha256 `69120a77…9f59`; + matches the BuildManifest digest). Both are read from the pinned public + IPSW by byte range. + +## Hardware (from the ADT) + +| Block | ADT | Notes | +| --- | --- | --- | +| SmartIO | `/arm-io/sio`, `iop,s5l8960x`, reg `0x20ae00000` | DMA parent of every MCA and of spi1 | +| MCA0 | `0x20a0a0000`, SIO endpoints 0x28/0x29 | headphone/mic codec | +| MCA1 | `0x20a0a4000` | voice | +| MCA3 | `0x20a0ac000`, SIO endpoints 0x2e/0x2f | **speakers**; TDM, 8 slots (like J71b) | +| MCA4 | `0x20a0b0000` | Bluetooth | +| I2S switch | `0x20a003000`, `i2s-switch,t7001` | same class as S8000 | +| Speaker amps | 2× MAX98721 on i2c1, 0x31 and 0x34 | IRQ GPIO 8 / 9; `function-alive` GPIO 101; calibration in syscfg `SpCl` | +| Headset codec | CS42L81 on spi1 (`0x20a084000`) | CS GPIO 157, IRQ GPIO 116 | + +The MCAs report `mca-version` 1. The J81 Linux DT already has the PMGR +power states (`ps_sio`, `ps_sio_p`, `ps_mca0`–`4`, `ps_spi1`, `ps_i2c1`) and a +disabled i2c1 node; SIO, the I2S switch, spi1, the MCAs, the codec, the amps +and the sound card are missing. + +## What the A9/A10 audio path gives us, and what is new + +The J81 is closest to the S8000/T8010 path (SmartIO DMA + MCA), not to the A5 +(Cascadia) path. + +**SmartIO firmware.** `com.apple.driver.AppleT7000SmartIO` carries it in +`__DATA,__firmware` (0x788e0 bytes, sha256 `5fc96ee7…4bd3`, a 32-bit ARM +image, `KF-SIO`). `orchard.apple.smartio.extract()` already extracts it; the +recipe needs the bundle in `smartio.BUNDLES` and a +`smartio-from-kernelcache@2` step in `devices/j81/firmware.json`. The message +protocol matches A9/A10 (ready message op 0x6d, protocol version 3). + +**SmartIO registers (new work).** The J81's SIO is an A7 IOP version 1 (iOS: +AppleA7IOPV1), while S8000/T8010 use version 2. `apple-sio-core` needs a V1 +register backend. The J81 ANS (also V1, already working through `asp`) shows +part of the layout (remap registers 0x08–0x1c, CPU control 0x28, mailbox at ++0x1000); the queue, interrupt-status and timebase registers are not known +yet. + +**MCA v1 (new work, small).** iOS's `AppleAE2Audio` handles MCA versions 0, 1, +4 and 5 in one driver. Its v4 register offsets match `s8000-mca.c`; its v0/v1 +offsets match the A5 Cascadia `s5l-audio.c` map (for example TX_CFG 0x18, +RX_CFG 0x2c, FRAME 0x0c; FIFO size register 0x04 reads 0x80). Plan: a v1 +register map inside the `s8000-mca.c` framework. + +**MAX98721 amps (new work).** iOS's `AppleMAX98721Amp` uses 8-bit registers +that match the upstream MAX98925 map. Init, as iOS does it: +- FORMAT `0x20` = 0x57 / 0x97 / 0xd7 (16/24/32-bit, TDM, one bit of delay). +- MAP `0x11`–`0x19` = `c0 00 00 f0 00 ab 89 00 00`; `0x22`–`0x26` = 0; `0x2b` = 2. +- Per amp from the ADT `speaker-config`: `0x2c`, `0x2e`, `0x2f`, `0x30`–`0x35`, `0x37`. +- Enable: `0x36` = `0xb0` | per-amp bits, then `0x38` = 0x80, wait 1.5 ms. + +Base: upstream `max98925.c` with a new compatible, the MAX98721 revision ID +(unknown yet; upstream accepts 0x51/0x80), the ADT values and TDM slots. + +**NCO (new work, small).** The ADT's `/arm-io/nco` (`nco,t7001`, +`nco,s5l8960x`) is the block the T8010 driver variant already handles (iOS: +`AppleS5L8960XNCO`, same control bits). The only difference is the channel +stride: iOS reads `pmgr-nco-page-size` and falls back to 0x1000, and the J81 +ADT has no such property. Its window is 0x5000 bytes, so five channels 0x1000 +apart; MCA0, 1, 3 and 4 use channels 0, 1, 3 and 4 (`function-mclk_frequency`). +The reference rate is in `/arm-io` `clock-frequencies`, which the IPSW ADT +leaves zero for iBoot to fill in; it has to be read from the live ADT (m1n1 +exposes it as MTD `adt`). A running J81 reports 342857142 Hz (2.4 GHz / 7) +at index 10 (clock-id 0x10a minus 0x100), the rate iOS special-cases for +precision. + +**I2S switch.** iOS binds `AppleAE2I2SSwitch3` to `i2s-switch,s5l8960x`, the +layout `s8000-mca.c` programs. MCA3's route is `aud3` to `pin3`. + +**Headset codec.** CS42L81 has a driver on the A9/A10 path; the J81 MCA0 +record starts like J71t's. + +## Plan + +1. **Read-only probe** (no audio driver): enable i2c1 with no clients, read the + amps' revision register `0xff` and dump `0x00`–`0x3a` at 0x31 and 0x34. + Read PMGR power states for MCA0/MCA3/SIO, and only for powered blocks the + MCA version/FIFO registers and SIO CPU control. No writes. +2. SmartIO firmware recipe for the J81. +3. SmartIO V1 register backend; SIO reaches "ready". +4. MCA v1 and the DT nodes; validate the TDM stream with the amp outputs off. +5. MAX98721 driver; low-gain `speaker-test`, one amp at a time. +6. Headphones and microphones through CS42L81. + +## Status + +| Piece | State | +| --- | --- | +| SmartIO firmware (`smartio-from-kernelcache@2`, `AppleT7000SmartIO`) | done | +| SmartIO V1 register backend (`apple,t7000-sio`) | works on a J81: firmware boots, setup completes, 4 DMA channels | +| MCA v1 (`apple,t7001-mca`, MCA3 speaker link) | plays on a J81: TDM 8×16 in a 256-bit frame, bit clock from NCO channel 3 (24.576 MHz at 48 kHz) | +| MAX98721 driver | both amplifiers play on a J81 (0x31 slot 0, 0x34 slot 1) | +| NCO (`apple,t7001-nco`, 0x1000 channel stride) | written, builds | +| DT: SIO, I2S switch, MCA3, NCO in `t7001.dtsi` (disabled); SmartIO enabled on the Air 2 | written | +| NCO reference rate | 342857142 Hz (live ADT `clock-frequencies[10]`); NCO, I2S switch and MCA3 enabled on the Air 2 | +| DT: amplifiers and sound card (`audio-graph-card2`, two codecs on one link) | card "J81 Speakers" registers and plays; parsing the `multi` node logs OF refcount warnings in audio-graph-card2, to be fixed | + +## Speaker safety + +iOS protects the speakers in software (amp current/voltage feedback plus the +`SpCl` calibration); Linux will have neither at first. Use the ADT's hardware +limiter and boost settings, start with low gain, test one amp at a time, and +check the stream with the speaker outputs disabled first: a wrong TDM slot or +format can produce full-scale noise (J71b's plain-I2S attempt gave loud +static). + +## Test log + +| Date | Step | Result | +| --- | --- | --- | +| 2026-11-19 | ADT and kernelcache analysis (offline) | hardware above identified; no device access | +| 2026-11-19 | SmartIO firmware recipe | `t7000-smartio.bin` extracted, sha256 matches | +| 2026-11-19 | SmartIO V1 backend, MCA v1, MAX98721 driver (offline) | build as modules for apple-4k; patch audit passes for apple-4k and apple-16k; not run on hardware | +| 2026-11-20 | Live ADT read from Omarchy (read-only) | NCO reference 342857142 Hz | +| 2026-11-20 | RAM probe: amplifiers (read-only) | both answer at 0x31/0x34, revision 0x80; registers hold iOS's MAP values, global enable (0x38) and channel enables (0x36) off | +| 2026-11-20 | RAM probe: SmartIO | firmware boots; first build failed setup with -EBUSY: the send FIFO stays disabled on V1 (TX status 0x00020000) until the AP enables it; fixed in the V1 backend | +| 2026-11-20 | RAM probe: NCO and MCA3 | both bind; MCA version register reads 0x00010002 (version in the upper half on v1), check fixed | +| 2026-11-20 | RAM boots with the speaker DT | 4 of 5 freeze within ~1-12 s of /init (no console output, no USB), before any audio driver loads (they are blacklisted). Bisected by enabling one node at a time, one boot each: main kernel, +I2C1+SIO, +NCO, +I2S switch all boot; +MCA3 freezes. On a running system MCA3 can be powered (PMGR 0x20e020148) and its registers read (0x00010002) without a hang, so the suspect is how the boot treats the enabled MCA3 node: with a consumer that never probes, genpd keeps the domain in its boot state (sync_state pending) | +| 2026-11-20 | NCO variant and DT nodes (offline) | NCO layout from iOS's `AppleS5L8960XNCO`; patch audit passes for apple-4k and apple-16k; not run on hardware | +| 2026-11-20 | RAM boots with the speaker DT, DFU entered from Recovery | 2 of 2 boot normally; PMGR at handoff: MCA0-4 `0x200` (off), SIO on. The earlier freezes all followed DFU entered straight from iPadOS, so they may be the same bootchain problem rather than MCA3; open until more boots confirm it | +| 2026-11-20 | First playback (SmartIO firmware loaded by hand, modules loaded in order) | 440 Hz at -20 dBFS (-32 dBFS after the driver's attenuation) heard from amp0 at gain 8; 660 Hz in channel 1 heard from amp1. During playback: hw_ptr advances at 48000 frames/s, MCA3 TX_CFG 0x109 and FRAME 0x0f107007 (running), no underflow; i2s-switch aud3/pin3 routed with output enables; both amps global enable 0x80, blocks 0xb0, no status flags. A -30 dBFS tone at gain 4 was inaudible | +| 2026-11-20 | Stereo test (portrait, Home button down) | channel 0 / amp0 (0x31, slot 0) is the bottom-left speaker, channel 1 / amp1 (0x34, slot 1) the bottom-right; both together play cleanly | +| 2026-11-20 | Installed Omarchy (platform layer from this branch, SmartIO firmware copied in, `boot-entries sync`) | card and drivers come up on boot, no refcount warnings; without a UCM profile PipeWire plays silence (both gain controls start at 0); with `ucm2/conf.d/J81_Speakers` WirePlumber offers "Built-in Audio Speakers", sets both gains to 22, and `pw-play` is heard | +| 2026-11-20 | Lesson | reading MCA3 offset 0x64 (not a v1 register) resets the SoC; read only the registers the driver names | diff --git a/kernel/configs/apple-16k/config b/kernel/configs/apple-16k/config index bfdcfe2c..172fb954 100644 --- a/kernel/configs/apple-16k/config +++ b/kernel/configs/apple-16k/config @@ -4625,6 +4625,7 @@ CONFIG_SND_SOC_DMIC=m CONFIG_SND_SOC_MAX98357A=m # CONFIG_SND_SOC_MAX98504 is not set # CONFIG_SND_SOC_MAX9867 is not set +CONFIG_SND_SOC_MAX98721=m # CONFIG_SND_SOC_MAX98927 is not set # CONFIG_SND_SOC_MAX98520 is not set # CONFIG_SND_SOC_MAX98373_I2C is not set @@ -4763,7 +4764,8 @@ CONFIG_SND_SOC_SIMPLE_AMPLIFIER=m CONFIG_SND_SIMPLE_CARD_UTILS=m CONFIG_SND_SIMPLE_CARD=m # CONFIG_SND_AUDIO_GRAPH_CARD is not set -# CONFIG_SND_AUDIO_GRAPH_CARD2 is not set +CONFIG_SND_AUDIO_GRAPH_CARD2=m +# CONFIG_SND_AUDIO_GRAPH_CARD2_CUSTOM_SAMPLE is not set # CONFIG_SND_TEST_COMPONENT is not set # end of Generic drivers diff --git a/kernel/configs/apple-4k/config b/kernel/configs/apple-4k/config index 2f68d10e..44d8f77d 100644 --- a/kernel/configs/apple-4k/config +++ b/kernel/configs/apple-4k/config @@ -4625,6 +4625,7 @@ CONFIG_SND_SOC_CS42L81=m CONFIG_SND_SOC_MAX98357A=m # CONFIG_SND_SOC_MAX98504 is not set # CONFIG_SND_SOC_MAX9867 is not set +CONFIG_SND_SOC_MAX98721=m # CONFIG_SND_SOC_MAX98927 is not set # CONFIG_SND_SOC_MAX98520 is not set # CONFIG_SND_SOC_MAX98373_I2C is not set @@ -4763,7 +4764,8 @@ CONFIG_SND_SOC_SIMPLE_AMPLIFIER=m CONFIG_SND_SIMPLE_CARD_UTILS=m CONFIG_SND_SIMPLE_CARD=m # CONFIG_SND_AUDIO_GRAPH_CARD is not set -# CONFIG_SND_AUDIO_GRAPH_CARD2 is not set +CONFIG_SND_AUDIO_GRAPH_CARD2=m +# CONFIG_SND_AUDIO_GRAPH_CARD2_CUSTOM_SAMPLE is not set # CONFIG_SND_TEST_COMPONENT is not set # end of Generic drivers diff --git a/kernel/patches/devices/t7001/0013-arm64-dts-apple-t7001-air2-Enable-I2C1.patch b/kernel/patches/devices/t7001/0013-arm64-dts-apple-t7001-air2-Enable-I2C1.patch new file mode 100644 index 00000000..22be72c5 --- /dev/null +++ b/kernel/patches/devices/t7001/0013-arm64-dts-apple-t7001-air2-Enable-I2C1.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 20:42:11 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Enable I2C1 + +I2C1 carries the iPad Air 2's two speaker amplifiers (MAX98721, at 0x31 +and 0x34 in Apple's device tree). Enable the bus without clients so the +amplifiers can be identified from user space before a codec driver is +written. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index d4b114f73..6f7db2f1c 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -174,6 +174,15 @@ rtc_offset: rtc-offset@4 { + }; + }; + ++/* ++ * Speaker amplifiers (two MAX98721, at 0x31 and 0x34 in Apple's device ++ * tree). No driver binds them yet; the bus is enabled so they can be ++ * identified from user space. ++ */ ++&i2c1 { ++ status = "okay"; ++}; ++ + &serial5 { + pinctrl-0 = <&uart5_pins>; + pinctrl-names = "default"; diff --git a/kernel/patches/devices/t7001/0014-arm64-dts-apple-t7001-Add-the-speaker-audio-path.patch b/kernel/patches/devices/t7001/0014-arm64-dts-apple-t7001-Add-the-speaker-audio-path.patch new file mode 100644 index 00000000..ada3ef8e --- /dev/null +++ b/kernel/patches/devices/t7001/0014-arm64-dts-apple-t7001-Add-the-speaker-audio-path.patch @@ -0,0 +1,107 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 09:16:24 +0100 +Subject: [PATCH] arm64: dts: apple: t7001: Add the speaker audio path + +Describe the blocks the iPad Air 2's speakers are played through, all +disabled: the SmartIO DMA coprocessor (AppleA7IOP version 1, endpoints +from Apple's device tree), the i2s-switch, MCA3 (the speaker link, NCO +channel 3, MCLK word at 0x20a00200c) and the NCO with its reference +clock. The NCO reference rate is filled in by iBoot in Apple's device +tree, so the board sets it. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/t7001.dtsi | 61 ++++++++++++++++++++++++++++ + 1 file changed, 61 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001.dtsi b/arch/arm64/boot/dts/apple/t7001.dtsi +index 892ff78bd..8716534b6 100644 +--- a/arch/arm64/boot/dts/apple/t7001.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001.dtsi +@@ -30,6 +30,17 @@ clkref: clock-ref { + clock-output-names = "clkref"; + }; + ++ /* ++ * The NCO's reference. Its rate is in the clock-frequencies table that ++ * iBoot fills in (the NCO's first clock-id); the IPSW ADT leaves it 0, ++ * so each board sets it. ++ */ ++ nco_clkref: clock-ref-nco { ++ compatible = "fixed-clock"; ++ #clock-cells = <0>; ++ clock-output-names = "nco_ref"; ++ }; ++ + spi3_clk: clock-spi3 { + compatible = "fixed-clock"; + #clock-cells = <0>; +@@ -165,6 +176,47 @@ ans_mbox: mbox@208041000 { + power-domains = <&ps_ans>; + }; + ++ /* ADT i2s-switch,t7001: AppleAE2I2SSwitch3, as on S8000 */ ++ i2s_switch: syscon@20a003000 { ++ compatible = "apple,t7001-i2s-switch", "syscon"; ++ reg = <0x2 0x0a003000 0x0 0x1000>; ++ status = "disabled"; ++ }; ++ ++ mca3: mca@20a0ac000 { ++ compatible = "apple,t7001-mca"; ++ reg = <0x2 0x0a0ac000 0x0 0x4000>, ++ <0x2 0x0a00200c 0x0 0x4>; ++ reg-names = "mca", "mclk"; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ power-domains = <&ps_mca3>; ++ clocks = <&nco 3>; ++ clock-names = "bitclk"; ++ dmas = <&sio 0x2e>; ++ dma-names = "tx"; ++ #clock-cells = <0>; ++ clock-output-names = "mca3-mclk"; ++ #sound-dai-cells = <0>; ++ status = "disabled"; ++ }; ++ ++ sio: dma-controller@20ae00000 { ++ compatible = "apple,t7000-sio"; ++ reg = <0x2 0x0ae00000 0x0 0x2000>; ++ reg-names = "a7iop"; ++ interrupt-parent = <&aic>; ++ interrupts = , ++ , ++ , ++ ; ++ power-domains = <&ps_sio>; ++ firmware-name = "apple/t7000-smartio.bin"; ++ dma-channels = <64>; ++ #dma-cells = <1>; ++ status = "disabled"; ++ }; ++ + serial0: serial@20a0c0000 { + compatible = "apple,s5l-uart"; + reg = <0x2 0x0a0c0000 0x0 0x4000>; +@@ -341,6 +393,15 @@ pmgr: power-management@20e000000 { + reg = <0x2 0xe000000 0 0x24000>; + }; + ++ /* Five channels 0x1000 apart; MCA0-4 use 0, 1, 3 and 4 */ ++ nco: clock-controller@20e011000 { ++ compatible = "apple,t7001-nco"; ++ reg = <0x2 0x0e011000 0x0 0x5000>; ++ clocks = <&nco_clkref>; ++ #clock-cells = <1>; ++ status = "disabled"; ++ }; ++ + wdt: watchdog@20e027000 { + compatible = "apple,t7000-wdt", "apple,wdt"; + reg = <0x2 0x0e027000 0x0 0x1000>; +-- +2.56.0 + diff --git a/kernel/patches/devices/t7001/0015-arm64-dts-apple-t7001-air2-Enable-SmartIO.patch b/kernel/patches/devices/t7001/0015-arm64-dts-apple-t7001-air2-Enable-SmartIO.patch new file mode 100644 index 00000000..c4cd685d --- /dev/null +++ b/kernel/patches/devices/t7001/0015-arm64-dts-apple-t7001-air2-Enable-SmartIO.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 09:16:25 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Enable SmartIO + +Start the SmartIO coprocessor, the DMA engine of the speaker link. Its +firmware is staged from the kernelcache (apple/t7000-smartio.bin). + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 5 +++++ + 1 file changed, 5 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index 613dd1bea..1d33fef01 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -193,6 +193,11 @@ &i2c1 { + status = "okay"; + }; + ++/* SmartIO: the DMA engine of every MCA and of spi1 */ ++&sio { ++ status = "okay"; ++}; ++ + &serial5 { + pinctrl-0 = <&uart5_pins>; + pinctrl-names = "default"; +-- +2.56.0 + diff --git a/kernel/patches/devices/t7001/0016-arm64-dts-apple-t7001-air2-Enable-the-speaker-link.patch b/kernel/patches/devices/t7001/0016-arm64-dts-apple-t7001-air2-Enable-the-speaker-link.patch new file mode 100644 index 00000000..08421c80 --- /dev/null +++ b/kernel/patches/devices/t7001/0016-arm64-dts-apple-t7001-air2-Enable-the-speaker-link.patch @@ -0,0 +1,54 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 11:35:49 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Enable the speaker link + +Set the NCO reference to the rate iBoot reports in a running J81's +Apple device tree (/arm-io clock-frequencies[10] = 342857142 Hz, 2.4 GHz +/ 7; the IPSW device tree leaves it 0), and enable the NCO, the +i2s-switch and MCA3 with its route from aud3 to pin3. No codec is +attached yet, so no sound card appears. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 23 +++++++++++++++++++++++ + 1 file changed, 23 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index 1d33fef01..29e355181 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -198,6 +198,29 @@ &sio { + status = "okay"; + }; + ++/* ++ * The NCO reference as iBoot reports it in a running J81's ADT ++ * (/arm-io clock-frequencies[10], the NCO's first clock-id 0x10a): ++ * 2.4 GHz / 7. iOS special-cases this rate for its divider precision. ++ */ ++&nco_clkref { ++ clock-frequency = <342857142>; ++}; ++ ++&nco { ++ status = "okay"; ++}; ++ ++&i2s_switch { ++ status = "okay"; ++}; ++ ++/* The speaker link: MCA3 to pad 3 (ADT function-i2s_route aud3 -> pin3) */ ++&mca3 { ++ apple,i2s-switch = <&i2s_switch 3 3>; ++ status = "okay"; ++}; ++ + &serial5 { + pinctrl-0 = <&uart5_pins>; + pinctrl-names = "default"; +-- +2.56.0 + diff --git a/kernel/patches/devices/t7001/0017-arm64-dts-apple-t7001-air2-Add-the-speakers.patch b/kernel/patches/devices/t7001/0017-arm64-dts-apple-t7001-air2-Add-the-speakers.patch new file mode 100644 index 00000000..322ef89e --- /dev/null +++ b/kernel/patches/devices/t7001/0017-arm64-dts-apple-t7001-air2-Add-the-speakers.patch @@ -0,0 +1,142 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 12:09:31 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Add the speakers + +Describe the two MAX98721 amplifiers on I2C1 at 0x31 and 0x34 (Apple's +/arm-io/i2c1 audio-speaker nodes; both read revision 0x80 on a J81) and +a sound card for them: MCA3 drives both on one TDM link, 8 slots of 16 +bits, amplifier 0x31 in slot 0 and 0x34 in slot 1. One CPU to two +codecs is audio-graph-card2's "semi-multi" link. + +The channels are named after the speakers they drive (portrait, Home +button down): slot 0 is the left speaker, slot 1 the right. + +The amplifiers' interrupts (GPIO 8 and 9) and the 0x31 amplifier's +"function-alive" GPIO 101 are not described yet. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 95 ++++++++++++++++++++++- + 1 file changed, 92 insertions(+), 3 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index 29e355181..98320109c 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -185,12 +185,46 @@ rtc_offset: rtc-offset@4 { + }; + + /* +- * Speaker amplifiers (two MAX98721, at 0x31 and 0x34 in Apple's device +- * tree). No driver binds them yet; the bus is enabled so they can be +- * identified from user space. ++ * The two speaker amplifiers, fed by MCA3 in TDM slots 0 (0x31) and 1 ++ * (0x34); both read revision 0x80 on a J81. Their driver holds them off ++ * until a sound card runs a stream through them. Their interrupts (GPIO 8 ++ * and 9) and the 0x31 amplifier's "function-alive" GPIO 101 are not ++ * described yet. + */ + &i2c1 { + status = "okay"; ++ ++ speaker_amp0: amplifier@31 { ++ compatible = "maxim,max98721"; ++ reg = <0x31>; ++ #sound-dai-cells = <0>; ++ sound-name-prefix = "Left"; ++ ++ port { ++ amp0_ep: endpoint { ++ remote-endpoint = <&speaker_amp0_ep>; ++ dai-tdm-slot-num = <8>; ++ dai-tdm-slot-width = <16>; ++ dai-tdm-slot-rx-mask = <1>; /* slot 0 */ ++ }; ++ }; ++ }; ++ ++ speaker_amp1: amplifier@34 { ++ compatible = "maxim,max98721"; ++ reg = <0x34>; ++ #sound-dai-cells = <0>; ++ sound-name-prefix = "Right"; ++ ++ port { ++ amp1_ep: endpoint { ++ remote-endpoint = <&speaker_amp1_ep>; ++ dai-tdm-slot-num = <8>; ++ dai-tdm-slot-width = <16>; ++ dai-tdm-slot-rx-mask = <0 1>; /* slot 1 */ ++ }; ++ }; ++ }; + }; + + /* SmartIO: the DMA engine of every MCA and of spi1 */ +@@ -219,6 +253,61 @@ &i2s_switch { + &mca3 { + apple,i2s-switch = <&i2s_switch 3 3>; + status = "okay"; ++ ++ mca3_port: port { ++ mca3_ep: endpoint { ++ remote-endpoint = <&speakers_cpu_ep>; ++ format = "dsp_a"; ++ bitclock-master; ++ frame-master; ++ }; ++ }; ++}; ++ ++/* ++ * The speakers: MCA3 playing to both amplifiers on one TDM link ++ * (audio-graph-card2 "semi-multi", one CPU to two codecs). Channel 0 is ++ * slot 0 (amplifier 0x31, the left speaker in portrait), channel 1 slot 1 ++ * (0x34, the right speaker). ++ */ ++/ { ++ sound-speakers { ++ compatible = "audio-graph-card2"; ++ label = "J81 Speakers"; ++ links = <&mca3_port>; ++ ++ multi { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ ports@0 { ++ reg = <0>; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ port@0 { ++ reg = <0>; ++ speakers_cpu_ep: endpoint { ++ remote-endpoint = <&mca3_ep>; ++ }; ++ }; ++ ++ port@1 { ++ reg = <1>; ++ speaker_amp0_ep: endpoint { ++ remote-endpoint = <&0_ep>; ++ }; ++ }; ++ ++ port@2 { ++ reg = <2>; ++ speaker_amp1_ep: endpoint { ++ remote-endpoint = <&1_ep>; ++ }; ++ }; ++ }; ++ }; ++ }; + }; + + &serial5 { +-- +2.56.0 + diff --git a/kernel/patches/drivers/clk/0009-clk-apple-nco-Add-the-T7001-A8X-variant.patch b/kernel/patches/drivers/clk/0009-clk-apple-nco-Add-the-T7001-A8X-variant.patch new file mode 100644 index 00000000..84fad085 --- /dev/null +++ b/kernel/patches/drivers/clk/0009-clk-apple-nco-Add-the-T7001-A8X-variant.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 09:14:05 +0100 +Subject: [PATCH] clk: apple-nco: Add the T7001 (A8X) variant + +The A7 to A8X NCO uses the same control bits as the T8010 (enable bit +12, accumulator mode bit 31), but its channel registers are 0x1000 +apart. iOS's AppleS5L8960XNCO reads the stride from the ADT property +"pmgr-nco-page-size" and falls back to 0x1000; the T7001 ADT has no +such property, and its NCO window is 0x5000 bytes for five channels +(MCA0 to MCA4 use channels 0, 1, 3 and 4). + +Make the stride part of the variant data, keep 0x4000 for T8010 and +for the compatibles without variant data, and add apple,t7001-nco with +0x1000. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + drivers/clk/clk-apple-nco.c | 23 +++++++++++++++++++---- + 1 file changed, 19 insertions(+), 4 deletions(-) + +diff --git a/drivers/clk/clk-apple-nco.c b/drivers/clk/clk-apple-nco.c +index 12eeb65f5..478dd6546 100644 +--- a/drivers/clk/clk-apple-nco.c ++++ b/drivers/clk/clk-apple-nco.c +@@ -67,6 +67,7 @@ struct applnco_tables { + }; + + struct applnco_hw { ++ u32 stride; + u32 enable_mask; + u32 control_set; + u32 control_clear; +@@ -284,7 +285,7 @@ static int applnco_probe(struct platform_device *pdev) + void __iomem *base; + struct resource *res; + struct applnco_tables *tbl; +- unsigned int nchannels; ++ unsigned int nchannels, stride; + const struct applnco_hw *soc = device_get_match_data(&pdev->dev); + int ret, i; + +@@ -303,10 +304,10 @@ static int applnco_probe(struct platform_device *pdev) + if (IS_ERR(base)) + return PTR_ERR(base); + ++ stride = soc ? soc->stride : NCO_CHANNEL_STRIDE; + if (resource_size(res) < NCO_CHANNEL_REGSIZE) + return -EINVAL; +- nchannels = (resource_size(res) - NCO_CHANNEL_REGSIZE) +- / NCO_CHANNEL_STRIDE + 1; ++ nchannels = (resource_size(res) - NCO_CHANNEL_REGSIZE) / stride + 1; + + onecell_data = devm_kzalloc(&pdev->dev, struct_size(onecell_data, hws, + nchannels), GFP_KERNEL); +@@ -326,7 +327,7 @@ static int applnco_probe(struct platform_device *pdev) + if (!chan) + return -ENOMEM; + chan->soc = soc; +- chan->base = base + NCO_CHANNEL_STRIDE * i; ++ chan->base = base + stride * i; + chan->tbl = tbl; + spin_lock_init(&chan->lock); + +@@ -355,12 +356,26 @@ static int applnco_probe(struct platform_device *pdev) + + /* AppleS5L8960XNCO: parent 0, no alternate prescaler, accumulator mode. */ + static const struct applnco_hw t8010_nco_hw = { ++ .stride = NCO_CHANNEL_STRIDE, ++ .enable_mask = BIT(12), ++ .control_set = BIT(31), ++ .control_clear = BIT(24) | BIT(29), ++}; ++ ++/* ++ * The same block on the A7 to A8X, with its channels 0x1000 apart: iOS's ++ * AppleS5L8960XNCO takes the stride from "pmgr-nco-page-size" and falls back ++ * to 0x1000, which T7001's ADT relies on (reg size 0x5000, five channels). ++ */ ++static const struct applnco_hw t7001_nco_hw = { ++ .stride = 0x1000, + .enable_mask = BIT(12), + .control_set = BIT(31), + .control_clear = BIT(24) | BIT(29), + }; + + static const struct of_device_id applnco_ids[] = { ++ { .compatible = "apple,t7001-nco", .data = &t7001_nco_hw }, + { .compatible = "apple,t8010-nco", .data = &t8010_nco_hw }, + { .compatible = "apple,t8103-nco" }, + { .compatible = "apple,nco" }, +-- +2.56.0 + diff --git a/kernel/patches/drivers/soc-apple/0031-dt-bindings-dma-apple-sio-Add-the-T7000.patch b/kernel/patches/drivers/soc-apple/0031-dt-bindings-dma-apple-sio-Add-the-T7000.patch new file mode 100644 index 00000000..31299ae6 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0031-dt-bindings-dma-apple-sio-Add-the-T7000.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 22:15:03 +0100 +Subject: [PATCH 1/2] dt-bindings: dma: apple,sio: Add the T7000 + +The A8 and A8X SmartIO is an AppleA7IOP version 1: a single 0x2000 +register window, with no shim registers in Apple's device tree. Add +apple,t7000-sio and make the shim region apply to S8000 and T8010 only. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + .../devicetree/bindings/dma/apple,sio.yaml | 31 +++++++++++++++++-- + 1 file changed, 29 insertions(+), 2 deletions(-) + +diff --git a/Documentation/devicetree/bindings/dma/apple,sio.yaml b/Documentation/devicetree/bindings/dma/apple,sio.yaml +index 8dc7114af..b19e66a2a 100644 +--- a/Documentation/devicetree/bindings/dma/apple,sio.yaml ++++ b/Documentation/devicetree/bindings/dma/apple,sio.yaml +@@ -4,10 +4,11 @@ + $id: http://devicetree.org/schemas/dma/apple,sio.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple S8000/T8010 SmartIO coprocessor and DMA controller ++title: Apple T7000/S8000/T8010 SmartIO coprocessor and DMA controller + + description: | +- The S8000 (A9) and T8010 (A10) SmartIO coprocessor provides DMA channels ++ The T7000 (A8, A8X), S8000 (A9) and T8010 (A10) SmartIO coprocessor ++ provides DMA channels + for peripheral controllers. The application processor boots the SmartIO + firmware and submits DMA commands through the SIO message queues. Clients + select the firmware endpoint number used by their peripheral. +@@ -21,15 +22,18 @@ allOf: + properties: + compatible: + enum: ++ - apple,t7000-sio + - apple,s8000-sio + - apple,t8010-sio + + reg: ++ minItems: 1 + items: + - description: AppleA7IOP coprocessor and message queue registers + - description: SmartIO DMA shim registers + + reg-names: ++ minItems: 1 + items: + - const: a7iop + - const: shim +@@ -61,6 +65,29 @@ properties: + Clients specify the SmartIO DMA endpoint number, for example 0x1a for + SPI3 transmit, 0x1b for SPI3 receive or 0x28 for MCA0 transmit. + ++if: ++ properties: ++ compatible: ++ contains: ++ enum: ++ - apple,s8000-sio ++ - apple,t8010-sio ++then: ++ properties: ++ reg: ++ minItems: 2 ++ reg-names: ++ minItems: 2 ++else: ++ description: ++ The T7000's AppleA7IOP version 1 block is a single 0x2000 window, and ++ Apple's device tree describes no shim registers for it. ++ properties: ++ reg: ++ maxItems: 1 ++ reg-names: ++ maxItems: 1 ++ + required: + - compatible + - reg diff --git a/kernel/patches/drivers/soc-apple/0032-soc-apple-sio-Support-the-T7000-AppleA7IOP-version-1.patch b/kernel/patches/drivers/soc-apple/0032-soc-apple-sio-Support-the-T7000-AppleA7IOP-version-1.patch new file mode 100644 index 00000000..53f9a29e --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0032-soc-apple-sio-Support-the-T7000-AppleA7IOP-version-1.patch @@ -0,0 +1,374 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 22:15:04 +0100 +Subject: [PATCH] soc: apple: sio: Support the T7000 (AppleA7IOP version 1) + +The A8 and A8X SmartIO is an AppleA7IOP version 1 coprocessor. It runs +the same firmware protocol as the S8000 and T8010 (ready message 0x6d, +protocol version 3), and iOS's AppleA7IOPV1 boots it in the same order +as AppleA7IOPV2, but its registers sit elsewhere: + + V2 (S8000, T8010) V1 (T7000, T7001) + remap AP lo/hi 0x08/0x10 0x08/0x0c + remap IOP lo/hi 0x18/0x20 0x10/0x14 + remap size lo/hi 0x28/0x30 0x18/0x1c + remap enable 0x38 0x20 + CPU control 0x44 0x28 + mailbox base 0x4000 0x1000 + timebase lo/hi 0xc030/0xc038 0x810/0x818 + +The V1 mailbox has the same layout as the V2 one (and as the mailbox +driver's A7 IOP variant). V1 has no mirror of the mask registers at +0xc00/0xc04 and no status register at 0xb84; the IRQ status at 0xb88 and +the timebase control at 0x80c are shared. The V1 offsets come from +iOS 15's AppleA7IOPV1 for the iPad Air 2 (19H422) and match the A8X ANS +registers the asp block driver uses. + +Move the offsets into a per-version table selected by the match data, +rename QUEUE_INIT/QUEUE_START to the mask set/clear registers they are, +and add apple,t7000-sio with the MCA0 and MCA3 endpoints of the J81. +S8000 and T8010 write the same registers in the same order as before. + + +On version 1 the AP also enables the A2I (send) FIFO, as the A7IOP +mailbox driver does for the ANS: SmartIO firmware leaves it disabled, and +the first reply to its ready message failed with -EBUSY on a J81. +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + drivers/soc/apple/apple-sio-core.c | 182 ++++++++++++++++++++--------- + 1 file changed, 129 insertions(+), 53 deletions(-) + +diff --git a/drivers/soc/apple/apple-sio-core.c b/drivers/soc/apple/apple-sio-core.c +index 1a59aed33..c0558b16b 100644 +--- a/drivers/soc/apple/apple-sio-core.c ++++ b/drivers/soc/apple/apple-sio-core.c +@@ -30,28 +30,73 @@ + #include + #include + +-#define APPLE_SIO_REMAP_AP_LO 0x0008 +-#define APPLE_SIO_REMAP_AP_HI 0x0010 +-#define APPLE_SIO_REMAP_IOP_LO 0x0018 +-#define APPLE_SIO_REMAP_IOP_HI 0x0020 +-#define APPLE_SIO_REMAP_SIZE_LO 0x0028 +-#define APPLE_SIO_REMAP_SIZE_HI 0x0030 +-#define APPLE_SIO_REMAP_ENABLE 0x0038 +-#define APPLE_SIO_CPU_CONTROL 0x0044 ++/* ++ * AppleA7IOP register layout. Version 2 (S8000, T8010) and version 1 (T7000 ++ * and T7001, the A8 and A8X) differ only in where the registers sit; iOS's ++ * AppleA7IOPV1 and AppleA7IOPV2 program them in the same order. ++ */ ++struct apple_sio_regs { ++ u32 remap_ap_lo; ++ u32 remap_ap_hi; ++ u32 remap_iop_lo; ++ u32 remap_iop_hi; ++ u32 remap_size_lo; ++ u32 remap_size_hi; ++ u32 remap_enable; ++ u32 cpu_control; ++ u32 time_lo; ++ u32 time_hi; ++ u32 mbox; /* base of the mailbox registers below */ ++ bool mirror; /* V2: mask writes are mirrored at 0xc00/0xc04 */ ++ bool legacy_status; /* V2: an older IRQ status at 0xb84 */ ++ bool enable_tx; /* V1: the AP enables the A2I FIFO itself */ ++}; ++ + #define APPLE_SIO_CPU_RUN BIT(4) + #define APPLE_SIO_TIME_CONTROL 0x080c + #define APPLE_SIO_IRQ_STATUS_LEGACY 0x0b84 + #define APPLE_SIO_IRQ_STATUS 0x0b88 +-#define APPLE_SIO_QUEUE_INIT_B 0x0c00 +-#define APPLE_SIO_QUEUE_START_B 0x0c04 +-#define APPLE_SIO_QUEUE_INIT_A 0x4000 +-#define APPLE_SIO_QUEUE_START_A 0x4004 +-#define APPLE_SIO_TX_STATUS 0x4008 +-#define APPLE_SIO_TX_MESSAGE 0x4010 +-#define APPLE_SIO_RX_STATUS 0x4020 +-#define APPLE_SIO_RX_MESSAGE 0x4038 +-#define APPLE_SIO_TIME_LO 0xc030 +-#define APPLE_SIO_TIME_HI 0xc038 ++#define APPLE_SIO_MASK_SET_MIRROR 0x0c00 ++#define APPLE_SIO_MASK_CLEAR_MIRROR 0x0c04 ++ ++/* Mailbox registers, relative to apple_sio_regs.mbox */ ++#define APPLE_SIO_MASK_SET 0x00 ++#define APPLE_SIO_MASK_CLEAR 0x04 ++#define APPLE_SIO_TX_STATUS 0x08 ++#define APPLE_SIO_TX_MESSAGE 0x10 ++#define APPLE_SIO_RX_STATUS 0x20 ++#define APPLE_SIO_RX_MESSAGE 0x38 ++ ++static const struct apple_sio_regs apple_sio_regs_v2 = { ++ .remap_ap_lo = 0x08, ++ .remap_ap_hi = 0x10, ++ .remap_iop_lo = 0x18, ++ .remap_iop_hi = 0x20, ++ .remap_size_lo = 0x28, ++ .remap_size_hi = 0x30, ++ .remap_enable = 0x38, ++ .cpu_control = 0x44, ++ .time_lo = 0xc030, ++ .time_hi = 0xc038, ++ .mbox = 0x4000, ++ .mirror = true, ++ .legacy_status = true, ++}; ++ ++static const struct apple_sio_regs apple_sio_regs_v1 = { ++ .remap_ap_lo = 0x08, ++ .remap_ap_hi = 0x0c, ++ .remap_iop_lo = 0x10, ++ .remap_iop_hi = 0x14, ++ .remap_size_lo = 0x18, ++ .remap_size_hi = 0x1c, ++ .remap_enable = 0x20, ++ .cpu_control = 0x28, ++ .time_lo = 0x810, ++ .time_hi = 0x818, ++ .mbox = 0x1000, ++ .enable_tx = true, ++}; + + #define APPLE_SIO_MBOX_ENABLE BIT(0) + #define APPLE_SIO_MBOX_EMPTY BIT(17) +@@ -82,6 +127,7 @@ + #define APPLE_SIO_SETUP_COMMANDS 10 + + struct apple_sio_hw { ++ const struct apple_sio_regs *regs; + const struct apple_sio_dma_range *dma_ranges; + unsigned int num_dma_ranges; + }; +@@ -114,6 +160,8 @@ struct apple_sio { + bool irq_requested; + bool irq_enabled; + void __iomem *base; ++ void __iomem *mbox; ++ const struct apple_sio_regs *regs; + void *firmware_buffer; + dma_addr_t firmware_dma; + size_t firmware_size; +@@ -363,17 +411,18 @@ static irqreturn_t apple_sio_irq(int irq, void *data) + u32 status; + + sio->irq_count++; +- sio->last_irq_legacy = +- readl_relaxed(sio->base + APPLE_SIO_IRQ_STATUS_LEGACY); ++ if (sio->regs->legacy_status) ++ sio->last_irq_legacy = ++ readl_relaxed(sio->base + APPLE_SIO_IRQ_STATUS_LEGACY); + sio->last_irq = readl_relaxed(sio->base + APPLE_SIO_IRQ_STATUS); + while (count < APPLE_SIO_RX_DRAIN_LIMIT) { +- status = readl_relaxed(sio->base + APPLE_SIO_RX_STATUS); ++ status = readl_relaxed(sio->mbox + APPLE_SIO_RX_STATUS); + sio->last_rx_status = status; + if (!apple_sio_can_read(status)) + break; + + sio->last_rx_message = +- readq_relaxed(sio->base + APPLE_SIO_RX_MESSAGE); ++ readq_relaxed(sio->mbox + APPLE_SIO_RX_MESSAGE); + apple_sio_dispatch(sio, sio->last_rx_message); + count++; + } +@@ -396,7 +445,7 @@ static int apple_sio_send(struct apple_sio *sio, u64 message) + goto out_unlock; + } + +- ret = readl_poll_timeout(sio->base + APPLE_SIO_TX_STATUS, status, ++ ret = readl_poll_timeout(sio->mbox + APPLE_SIO_TX_STATUS, status, + apple_sio_can_write(status), 10, + APPLE_SIO_TX_TIMEOUT_US); + if (ret) +@@ -408,7 +457,7 @@ static int apple_sio_send(struct apple_sio *sio, u64 message) + goto out_hw_unlock; + } + +- status = readl_relaxed(sio->base + APPLE_SIO_TX_STATUS); ++ status = readl_relaxed(sio->mbox + APPLE_SIO_TX_STATUS); + if (!apple_sio_can_write(status)) { + ret = -EBUSY; + goto out_hw_unlock; +@@ -416,7 +465,7 @@ static int apple_sio_send(struct apple_sio *sio, u64 message) + + dma_wmb(); + sio->last_tx_message = message; +- writeq_relaxed(message, sio->base + APPLE_SIO_TX_MESSAGE); ++ writeq_relaxed(message, sio->mbox + APPLE_SIO_TX_MESSAGE); + + out_hw_unlock: + spin_unlock_irqrestore(&sio->tx_hw_lock, flags); +@@ -437,7 +486,7 @@ static int apple_sio_send_atomic(struct apple_sio *sio, u64 message) + goto out_unlock; + } + +- status = readl_relaxed(sio->base + APPLE_SIO_TX_STATUS); ++ status = readl_relaxed(sio->mbox + APPLE_SIO_TX_STATUS); + sio->last_tx_status = status; + if (!apple_sio_can_write(status)) { + ret = -EBUSY; +@@ -446,7 +495,7 @@ static int apple_sio_send_atomic(struct apple_sio *sio, u64 message) + + dma_wmb(); + sio->last_tx_message = message; +- writeq_relaxed(message, sio->base + APPLE_SIO_TX_MESSAGE); ++ writeq_relaxed(message, sio->mbox + APPLE_SIO_TX_MESSAGE); + + out_unlock: + spin_unlock_irqrestore(&sio->tx_hw_lock, flags); +@@ -785,11 +834,11 @@ static void apple_sio_stop(struct apple_sio *sio) + } + mutex_lock(&sio->tx_lock); + spin_lock_irq(&sio->tx_hw_lock); +- control = readl(sio->base + APPLE_SIO_CPU_CONTROL); ++ control = readl(sio->base + sio->regs->cpu_control); + writel(control & ~APPLE_SIO_CPU_RUN, +- sio->base + APPLE_SIO_CPU_CONTROL); +- readl(sio->base + APPLE_SIO_CPU_CONTROL); +- writel(0, sio->base + APPLE_SIO_REMAP_ENABLE); ++ sio->base + sio->regs->cpu_control); ++ readl(sio->base + sio->regs->cpu_control); ++ writel(0, sio->base + sio->regs->remap_enable); + spin_unlock_irq(&sio->tx_hw_lock); + mutex_unlock(&sio->tx_lock); + +@@ -808,11 +857,11 @@ static int apple_sio_start(struct apple_sio *sio, const char *firmware_name) + u32 status; + int ret; + +- control = readl(sio->base + APPLE_SIO_CPU_CONTROL); ++ control = readl(sio->base + sio->regs->cpu_control); + if (control & APPLE_SIO_CPU_RUN) { + /* Left running by the boot chain: reset it through the PMGR. */ + ret = device_reset_optional(sio->dev); +- control = readl(sio->base + APPLE_SIO_CPU_CONTROL); ++ control = readl(sio->base + sio->regs->cpu_control); + if (ret || (control & APPLE_SIO_CPU_RUN)) + return dev_err_probe(sio->dev, ret ?: -EBUSY, + "SmartIO CPU is already running\n"); +@@ -841,37 +890,46 @@ static int apple_sio_start(struct apple_sio *sio, const char *firmware_name) + sio->firmware_dma = dma; + sio->firmware_size = size; + +- writel(0, sio->base + APPLE_SIO_REMAP_IOP_LO); +- writel(0, sio->base + APPLE_SIO_REMAP_IOP_HI); +- writel(lower_32_bits(size), sio->base + APPLE_SIO_REMAP_SIZE_LO); +- writel(upper_32_bits(size), sio->base + APPLE_SIO_REMAP_SIZE_HI); +- writel(lower_32_bits(dma), sio->base + APPLE_SIO_REMAP_AP_LO); +- writel(upper_32_bits(dma), sio->base + APPLE_SIO_REMAP_AP_HI); +- writel(1, sio->base + APPLE_SIO_REMAP_ENABLE); ++ writel(0, sio->base + sio->regs->remap_iop_lo); ++ writel(0, sio->base + sio->regs->remap_iop_hi); ++ writel(lower_32_bits(size), sio->base + sio->regs->remap_size_lo); ++ writel(upper_32_bits(size), sio->base + sio->regs->remap_size_hi); ++ writel(lower_32_bits(dma), sio->base + sio->regs->remap_ap_lo); ++ writel(upper_32_bits(dma), sio->base + sio->regs->remap_ap_hi); ++ writel(1, sio->base + sio->regs->remap_enable); + +- writel(0x1111, sio->base + APPLE_SIO_QUEUE_INIT_A); +- writel(0x1111, sio->base + APPLE_SIO_QUEUE_INIT_B); +- writel(1, sio->base + APPLE_SIO_QUEUE_START_A); +- writel(1, sio->base + APPLE_SIO_QUEUE_START_B); +- writel(0x1000, sio->base + APPLE_SIO_QUEUE_START_A); +- writel(0x1000, sio->base + APPLE_SIO_QUEUE_START_B); +- status = readl(sio->base + APPLE_SIO_RX_STATUS); ++ /* Mask everything, then unmask inbox-empty and outbox-not-empty. */ ++ writel(0x1111, sio->mbox + APPLE_SIO_MASK_SET); ++ if (sio->regs->mirror) ++ writel(0x1111, sio->base + APPLE_SIO_MASK_SET_MIRROR); ++ writel(1, sio->mbox + APPLE_SIO_MASK_CLEAR); ++ if (sio->regs->mirror) ++ writel(1, sio->base + APPLE_SIO_MASK_CLEAR_MIRROR); ++ writel(0x1000, sio->mbox + APPLE_SIO_MASK_CLEAR); ++ if (sio->regs->mirror) ++ writel(0x1000, sio->base + APPLE_SIO_MASK_CLEAR_MIRROR); ++ status = readl(sio->mbox + APPLE_SIO_RX_STATUS); + writel(status | APPLE_SIO_MBOX_ENABLE, +- sio->base + APPLE_SIO_RX_STATUS); ++ sio->mbox + APPLE_SIO_RX_STATUS); ++ if (sio->regs->enable_tx) { ++ status = readl(sio->mbox + APPLE_SIO_TX_STATUS); ++ writel(status | APPLE_SIO_MBOX_ENABLE, ++ sio->mbox + APPLE_SIO_TX_STATUS); ++ } + + control = readl(sio->base + APPLE_SIO_TIME_CONTROL); + writel(control & ~BIT(1), sio->base + APPLE_SIO_TIME_CONTROL); + counter = arch_timer_read_counter(); +- writel(lower_32_bits(counter), sio->base + APPLE_SIO_TIME_LO); +- writel(upper_32_bits(counter), sio->base + APPLE_SIO_TIME_HI); ++ writel(lower_32_bits(counter), sio->base + sio->regs->time_lo); ++ writel(upper_32_bits(counter), sio->base + sio->regs->time_hi); + writel(control | BIT(1), sio->base + APPLE_SIO_TIME_CONTROL); + + /* Requested disabled: a stale interrupt must not start region setup. */ + sio->irq_enabled = true; + enable_irq(sio->irq); +- control = readl(sio->base + APPLE_SIO_CPU_CONTROL); ++ control = readl(sio->base + sio->regs->cpu_control); + writel(control | APPLE_SIO_CPU_RUN, +- sio->base + APPLE_SIO_CPU_CONTROL); ++ sio->base + sio->regs->cpu_control); + + ready_timeout = msecs_to_jiffies(APPLE_SIO_READY_TIMEOUT_MS); + if (!wait_for_completion_timeout(&sio->ready, ready_timeout)) { +@@ -977,6 +1035,8 @@ static int apple_sio_probe(struct platform_device *pdev) + ret = PTR_ERR(sio->base); + goto out_pm_put; + } ++ sio->regs = hw->regs; ++ sio->mbox = sio->base + hw->regs->mbox; + + irq = platform_get_irq(pdev, APPLE_SIO_RX_IRQ_INDEX); + if (irq < 0) { +@@ -1093,6 +1153,7 @@ static const struct apple_sio_dma_range apple_sio_s8000_dma_ranges[] = { + }; + + static const struct apple_sio_hw apple_sio_s8000_hw = { ++ .regs = &apple_sio_regs_v2, + .dma_ranges = apple_sio_s8000_dma_ranges, + .num_dma_ranges = ARRAY_SIZE(apple_sio_s8000_dma_ranges), + }; +@@ -1109,11 +1170,25 @@ static const struct apple_sio_dma_range apple_sio_t8010_dma_ranges[] = { + }; + + static const struct apple_sio_hw apple_sio_t8010_hw = { ++ .regs = &apple_sio_regs_v2, + .dma_ranges = apple_sio_t8010_dma_ranges, + .num_dma_ranges = ARRAY_SIZE(apple_sio_t8010_dma_ranges), + }; + ++/* MCA0 (headset codec) and MCA3 (speakers), as described by the J81 ADT. */ ++static const struct apple_sio_dma_range apple_sio_t7000_dma_ranges[] = { ++ { 0x28, 0x29 }, ++ { 0x2e, 0x2f }, ++}; ++ ++static const struct apple_sio_hw apple_sio_t7000_hw = { ++ .regs = &apple_sio_regs_v1, ++ .dma_ranges = apple_sio_t7000_dma_ranges, ++ .num_dma_ranges = ARRAY_SIZE(apple_sio_t7000_dma_ranges), ++}; ++ + static const struct of_device_id apple_sio_of_match[] = { ++ { .compatible = "apple,t7000-sio", .data = &apple_sio_t7000_hw }, + { .compatible = "apple,s8000-sio", .data = &apple_sio_s8000_hw }, + { .compatible = "apple,t8010-sio", .data = &apple_sio_t8010_hw }, + {} +@@ -1132,7 +1207,8 @@ static struct platform_driver apple_sio_driver = { + }; + module_platform_driver(apple_sio_driver); + ++MODULE_FIRMWARE("apple/t7000-smartio.bin"); + MODULE_FIRMWARE("apple/s8000-smartio.bin"); + MODULE_FIRMWARE("apple/t8010-smartio.bin"); +-MODULE_DESCRIPTION("Apple S8000/T8010 SmartIO coprocessor driver"); ++MODULE_DESCRIPTION("Apple T7000/S8000/T8010 SmartIO coprocessor driver"); + MODULE_LICENSE("Dual MIT/GPL"); +-- +2.56.0 + diff --git a/kernel/patches/drivers/sound/0020-dt-bindings-sound-apple-s8000-mca-Add-the-T7001-MCA.patch b/kernel/patches/drivers/sound/0020-dt-bindings-sound-apple-s8000-mca-Add-the-T7001-MCA.patch new file mode 100644 index 00000000..6fdaf697 --- /dev/null +++ b/kernel/patches/drivers/sound/0020-dt-bindings-sound-apple-s8000-mca-Add-the-T7001-MCA.patch @@ -0,0 +1,70 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 22:22:32 +0100 +Subject: [PATCH] dt-bindings: sound: apple,s8000-mca: Add the T7001 MCA + +The iPad Air 2 (A8X, T7001) has the MCA in its "mca-version 1" form: the +fields of the A9/A10 MCA at the older A5-era register offsets. Its +speaker link (MCA3, two MAX98721 amplifiers in TDM slots) runs with the +MCA as clock provider from an AP NCO channel, like the T8010 speaker +link, and takes a single playback DMA channel. Name it apple,t7001-mca. + +The NCO runs at twice the bit clock on this version (iOS forces an +MCLK/SCLK ratio of at least two); say so in the clock description. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + .../devicetree/bindings/sound/apple,s8000-mca.yaml | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +index b9eda41..b17cd99 100644 +--- a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +@@ -4,7 +4,7 @@ + $id: http://devicetree.org/schemas/sound/apple,s8000-mca.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple S8000/T8010 MCA I2S controller ++title: Apple T7001/S8000/T8010 MCA I2S controller + + maintainers: + - Berkay Kösebay +@@ -18,7 +18,10 @@ description: | + with an AP NCO bitclock: apple,t8010-mca is the playback-only digital + speaker link (TDM), apple,t8010-mca-i2s the playback-only stereo I2S link + to the headphone codec. The MCAs are the same block; the compatible names +- the link setup iOS programs into it. ++ the link setup iOS programs into it. The T7001 (A8X) MCA is the older ++ "mca-version 1" register layout with the same fields: apple,t7001-mca is ++ the playback-only speaker link (TDM) of the iPad Air 2, clocked from an AP ++ NCO channel running at twice the bit clock. + + allOf: + - $ref: dai-common.yaml# +@@ -26,6 +29,7 @@ allOf: + properties: + compatible: + enum: ++ - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s + then: +@@ -46,12 +50,15 @@ properties: + compatible: + enum: + - apple,s8000-mca ++ - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s + + clocks: + maxItems: 1 +- description: AP NCO channel supplying the T8010 bitclock ++ description: ++ AP NCO channel supplying the bitclock (T7001, T8010). On T7001 the ++ MCA divides it by two. + + clock-names: + const: bitclk diff --git a/kernel/patches/drivers/sound/0021-ASoC-apple-s8000-mca-Add-the-T7001-MCA-version-1.patch b/kernel/patches/drivers/sound/0021-ASoC-apple-s8000-mca-Add-the-T7001-MCA-version-1.patch new file mode 100644 index 00000000..859fa275 --- /dev/null +++ b/kernel/patches/drivers/sound/0021-ASoC-apple-s8000-mca-Add-the-T7001-MCA-version-1.patch @@ -0,0 +1,706 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 22:22:53 +0100 +Subject: [PATCH] ASoC: apple: s8000-mca: Add the T7001 MCA (version 1) + +The iPad Air 2's MCAs (A8X, ADT mca,t7001, mca-version 1) are the block +iOS drives with the same AppleAE2MCA as the A9/A10 ones, through +_setIISConfig_v1 instead of _v4 (iOS 15.8, 19H422). The fields match: +SAMPLE (0x08) and PAD (0x14) are where they are on version 4, FRAME has +the same layout at 0x0c, TX/RX_CFG keep the enable bit and the data +delay in bits 16:8, the FIFO and slot words keep their encoding, and +RESET (TX bit 0, RX bit 1) and FLUSH (bit 0) work the same way. What +differs: + +- offsets: RESET 0x44, FLUSH 0x48, FRAME 0x0c, TX_CFG/FIFO/SLOTS + 0x18/0x20/0x24, RX_CFG/FIFO/SLOTS 0x2c/0x34/0x38, no SLOTS_HI; +- interrupts: one status word at 0x40 (TX underflow/overflow bits + 12/13, RX underflow/overflow 28/29, frame error 31, write 1 to + clear) and an enable word at 0x10 (bit 0 FIFO errors of both + directions, bit 1 frame error) instead of the status/mask pair; +- iOS writes 0xd to 0x1c and 0x30 (meaning unknown) and waits only + for the flush after the block reset; +- the MCLK divider divides by 2 * (div + 1), and iOS runs the NCO at + at least twice SCLK; +- the CFG constants: 0x9 base, the clock edge bit at bit 1. + +Add the offsets that differ as a per-version table selected by the hw +description, translate the version 4 interrupt causes the driver keeps +to the version 1 status and enables, and allow a fixed frame longer than +its slots (PAD). Version 4 and 5 variants program the same registers +with the same values in the same order as before. + +Add apple,t7001-mca for the J81 speaker link, MCA3: _setIISConfig_v1 +evaluated for its ADT iisConfig gives a provider frame of 8 x 16-bit +slots in 256 bits with a 16-bit sync pulse, TX in slots 0-1 (the two +MAX98721 amplifiers), TX_CFG 0x109, FRAME 0x0f107005, PAD 128, and the +bitclock NCO at 24.576 MHz for 48 kHz. Output is bounded to -12 dB as on +J71b. + +Compile-tested only; not run on hardware. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + sound/soc/apple/s8000-mca.c | 366 +++++++++++++++++++++++++++++------- + 1 file changed, 300 insertions(+), 66 deletions(-) + +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index 5499db8..dc8cbcc 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -10,6 +10,13 @@ + * exported as a clock (the codec's MCLK), and the MCA's route in the shared + * i2s-switch (AppleAE2I2SSwitch3). + * ++ * The T7001 (A8X) MCA is "mca-version 1": the same frame, slot, sample and ++ * channel config fields as version 4 in the A5-era register layout, with ++ * one interrupt status word and two interrupt enables instead of a status ++ * and a mask register (iOS 15.8 19H422's AppleAE2MCA::_setIISConfig_v1 and its ++ * v0/v1 stop and interrupt paths). The offsets that differ are in a ++ * per-version table, struct s8000_mca_regs. ++ * + * Samples are moved by SmartIO DMA (endpoint 0x28 for MCA0 TX, 0x29 for + * MCA0 RX) through the generic dmaengine PCM. The SmartIO shim record of + * the endpoint is passed as the slave config's peripheral_config. +@@ -48,6 +55,7 @@ + #define MCA_FRAME 0x10 + #define MCA_FRAME_MASTER BIT(0) + #define MCA_FRAME_RUN BIT(1) ++#define MCA_FRAME_POL BIT(2) /* set if format flag bit 0 != provider */ + #define MCA_FRAME_FMT BIT(3) /* set unless format flag bit 1 */ + #define MCA_FRAME_DUTY BIT(6) + #define MCA_FRAME_MCLK_DIV GENMASK(11, 8) +@@ -93,6 +101,39 @@ + #define MCA_RX_SLOTS_HI 0x8c + #define MCA_XX_CFG_EN BIT(0) + ++/* ++ * Version 1 (T7001), from iOS 15.8 _setIISConfig_v1: VERSION, FIFO_SIZE, ++ * SAMPLE and PAD as above (FIFO_SIZE reads 0x80), FRAME at 0x0c with the ++ * version 4 fields except the MCLK divider (SCLK = NCO / (2 * (div + 1))), ++ * TX/RX_CFG with their own bit encoding (0x9 base instead of 0x33, the ++ * clock edge bit at 1 instead of 2, data delay in bits 16:8 as before). ++ * RESET (TX bit 0, RX bit 1) and FLUSH (bit 0) clear themselves. ++ */ ++#define MCA_V1_FRAME 0x0c ++#define MCA_V1_IRQ_EN 0x10 ++#define MCA_V1_IRQ_EN_FIFO BIT(0) /* both directions' FIFO errors */ ++#define MCA_V1_IRQ_EN_FRAME BIT(1) /* frame error (fixed frame length) */ ++#define MCA_V1_TX_CFG 0x18 ++#define MCA_V1_TX_CTL 0x1c ++#define MCA_V1_TX_FIFO_CFG 0x20 ++#define MCA_V1_TX_SLOTS 0x24 ++#define MCA_V1_RX_CFG 0x2c ++#define MCA_V1_RX_CTL 0x30 ++#define MCA_V1_XX_CTL_IOS 0xd /* written by iOS, meaning unknown */ ++#define MCA_V1_RX_FIFO_CFG 0x34 ++#define MCA_V1_RX_SLOTS 0x38 ++/* causes latch whether they are enabled or not; write 1 to clear */ ++#define MCA_V1_IRQ_STATUS 0x40 ++#define MCA_V1_IRQ_TX_UNDERFLOW BIT(12) ++#define MCA_V1_IRQ_TX_OVERFLOW BIT(13) ++#define MCA_V1_IRQ_RX_UNDERFLOW BIT(28) ++#define MCA_V1_IRQ_RX_OVERFLOW BIT(29) ++#define MCA_V1_IRQ_FRAME_ERROR BIT(31) ++#define MCA_V1_RESET 0x44 ++#define MCA_V1_FLUSH 0x48 ++/* the version 4 causes MCA_V1_IRQ_EN_FIFO stands for */ ++#define MCA_IRQ_V1_FIFO (MCA_IRQ_TX_CAUSES | MCA_IRQ_RX_CAUSES) ++ + /* iOS _setIISConfig_v4 values for MCA0 */ + #define MCA_TX_CFG_I2S (BIT(8) | 0x33 | 0x4) /* enabled: 0x137 */ + #define MCA_RX_CFG_I2S (BIT(8) | 0x33) /* enabled: 0x133 */ +@@ -136,19 +177,68 @@ + SNDRV_PCM_RATE_48000) + #define MCA_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE) + ++/* The registers whose offset or meaning depends on the MCA version */ ++struct s8000_mca_regs { ++ u32 reset; ++ u32 flush; ++ u32 frame; ++ u32 tx_cfg, tx_fifo_cfg, tx_slots, tx_slots_hi; /* _hi: 0 if absent */ ++ u32 rx_cfg, rx_fifo_cfg, rx_slots, rx_slots_hi; ++ /* ++ * Version 1: MCA_V1_IRQ_* instead of MCA_IRQ_STATUS/MASK, the TX/RX ++ * CTL words, and iOS waits for the flush only, not for the reset, when ++ * it sets up the whole block. ++ */ ++ bool v1; ++ unsigned int nco_per_sclk; /* bitclock NCO rate / SCLK rate */ ++}; ++ ++static const struct s8000_mca_regs mca_v4_regs = { ++ .reset = MCA_RESET, ++ .flush = MCA_FLUSH, ++ .frame = MCA_FRAME, ++ .tx_cfg = MCA_TX_CFG, ++ .tx_fifo_cfg = MCA_TX_FIFO_CFG, ++ .tx_slots = MCA_TX_SLOTS, ++ .tx_slots_hi = MCA_TX_SLOTS_HI, ++ .rx_cfg = MCA_RX_CFG, ++ .rx_fifo_cfg = MCA_RX_FIFO_CFG, ++ .rx_slots = MCA_RX_SLOTS, ++ .rx_slots_hi = MCA_RX_SLOTS_HI, ++ .nco_per_sclk = 1, ++}; ++ ++/* iOS forces the MCLK/SCLK ratio of version 0/1 to at least 2 */ ++static const struct s8000_mca_regs mca_v1_regs = { ++ .reset = MCA_V1_RESET, ++ .flush = MCA_V1_FLUSH, ++ .frame = MCA_V1_FRAME, ++ .tx_cfg = MCA_V1_TX_CFG, ++ .tx_fifo_cfg = MCA_V1_TX_FIFO_CFG, ++ .tx_slots = MCA_V1_TX_SLOTS, ++ .rx_cfg = MCA_V1_RX_CFG, ++ .rx_fifo_cfg = MCA_V1_RX_FIFO_CFG, ++ .rx_slots = MCA_V1_RX_SLOTS, ++ .v1 = true, ++ .nco_per_sclk = 2, ++}; ++ + /* +- * Both variants are _setIISConfig_v4 evaluated for the board's iisConfig (the +- * "reg" of the ADT's audio-data node below the MCA): ++ * The variants are _setIISConfig_v4 (J81: _v1) evaluated for the board's ++ * iisConfig (the "reg" of the ADT's audio-data node below the MCA): + * + * J71t mca0 10 00 00 00 02 00 01 00 ... consumer, I2S, 2 x 16 bit + * J71b mca2 01 13 00 00 08 00 01 00 ... provider, 8 x 16 bit, slots 0-3 + * J171 mca4 01 13 00 00 02 00 01 00 ... provider, 2 slots, slots 0-1 ++ * J81 mca3 01 12 00 00 08 00 00 00 ... provider, 8 x 16 bit in a ++ * 256-bit frame, slots 0-1 + * + * Bytes 0xc/0xe of the J71b record are the 128-bit frame and its 1-bit sync + * pulse: the amplifiers run in TDM mode, as MAX98357 calls it. + */ + struct s8000_mca_hw { + u32 version; ++ const struct s8000_mca_regs *regs; + bool clock_provider; + /* + * Run the provider clocks from prepare to hw_free, not from trigger +@@ -162,6 +252,7 @@ struct s8000_mca_hw { + unsigned int dai_format; /* SND_SOC_DAIFMT_* */ + unsigned int channels; + unsigned int slots; ++ unsigned int frame_bits; /* 0: slots x slot width, no pad */ + u32 tx_slots; + u32 tx_cfg; + u32 rx_cfg; +@@ -194,6 +285,7 @@ struct s8000_mca_hw { + struct s8000_mca { + struct device *dev; + const struct s8000_mca_hw *hw; ++ const struct s8000_mca_regs *regs; + void __iomem *base; + void __iomem *mclk_reg; + struct clk_hw mclk_hw; +@@ -224,7 +316,7 @@ struct s8000_mca { + struct apple_sio_dma_config sio_cfg[2]; /* per SNDRV_PCM_STREAM_* */ + + /* computed in hw_params, written in prepare */ +- u32 sample, frame, tx_cfg, tx_fifo_cfg, tx_slots, rx_slots; ++ u32 sample, frame, pad, tx_cfg, tx_fifo_cfg, tx_slots, rx_slots; + + /* + * BIT(SNDRV_PCM_STREAM_*): prepared (prepare .. hw_free) and running +@@ -232,7 +324,7 @@ struct s8000_mca { + */ + spinlock_t hw_lock; + unsigned int prep_mask, run_mask; +- u32 irq_mask; /* current MCA_IRQ_MASK value */ ++ u32 irq_mask; /* current MCA_IRQ_MASK value (v1: its causes) */ + u32 prep_frame; /* frame the prepared block runs */ + }; + +@@ -246,6 +338,59 @@ static inline u32 mca_read(struct s8000_mca *mca, u32 off) + return readl_relaxed(mca->base + off); + } + ++/* ++ * Interrupt causes are handled as version 4 MCA_IRQ_* bits; on version 1 ++ * they are translated to MCA_V1_IRQ_STATUS bits (low and high water have ++ * no version 1 cause) and the mask to the two enables. ++ */ ++static u32 mca_v1_irq_bits(u32 causes) ++{ ++ return (causes & MCA_IRQ_TX_UNDERFLOW ? MCA_V1_IRQ_TX_UNDERFLOW : 0) | ++ (causes & MCA_IRQ_TX_OVERFLOW ? MCA_V1_IRQ_TX_OVERFLOW : 0) | ++ (causes & MCA_IRQ_RX_UNDERFLOW ? MCA_V1_IRQ_RX_UNDERFLOW : 0) | ++ (causes & MCA_IRQ_RX_OVERFLOW ? MCA_V1_IRQ_RX_OVERFLOW : 0) | ++ (causes & MCA_IRQ_FRAME_ERROR ? MCA_V1_IRQ_FRAME_ERROR : 0); ++} ++ ++static u32 mca_irq_status(struct s8000_mca *mca) ++{ ++ u32 raw; ++ ++ if (!mca->regs->v1) ++ return mca_read(mca, MCA_IRQ_STATUS); ++ ++ raw = mca_read(mca, MCA_V1_IRQ_STATUS); ++ return (raw & MCA_V1_IRQ_TX_UNDERFLOW ? MCA_IRQ_TX_UNDERFLOW : 0) | ++ (raw & MCA_V1_IRQ_TX_OVERFLOW ? MCA_IRQ_TX_OVERFLOW : 0) | ++ (raw & MCA_V1_IRQ_RX_UNDERFLOW ? MCA_IRQ_RX_UNDERFLOW : 0) | ++ (raw & MCA_V1_IRQ_RX_OVERFLOW ? MCA_IRQ_RX_OVERFLOW : 0) | ++ (raw & MCA_V1_IRQ_FRAME_ERROR ? MCA_IRQ_FRAME_ERROR : 0); ++} ++ ++static void mca_irq_ack(struct s8000_mca *mca, u32 causes) ++{ ++ if (mca->regs->v1) ++ mca_write(mca, MCA_V1_IRQ_STATUS, mca_v1_irq_bits(causes)); ++ else ++ mca_write(mca, MCA_IRQ_STATUS, causes); ++} ++ ++static void mca_irq_set_mask(struct s8000_mca *mca, u32 mask) ++{ ++ u32 en = 0; ++ ++ if (!mca->regs->v1) { ++ mca_write(mca, MCA_IRQ_MASK, mask); ++ return; ++ } ++ ++ if (~mask & MCA_IRQ_V1_FIFO) ++ en |= MCA_V1_IRQ_EN_FIFO; ++ if (~mask & MCA_IRQ_FRAME_ERROR) ++ en |= MCA_V1_IRQ_EN_FRAME; ++ mca_write(mca, MCA_V1_IRQ_EN, en); ++} ++ + static struct s8000_mca *hw_to_mca(struct clk_hw *hw) + { + return container_of(hw, struct s8000_mca, mclk_hw); +@@ -364,7 +509,8 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + unsigned int bits = params_width(params); + unsigned int slot = params_physical_width(params); + unsigned int channels = params_channels(params); +- unsigned int slots = mca->hw->slots, frame_bits = slot * slots, depth; ++ unsigned int slots = mca->hw->slots, depth; ++ unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots; + unsigned int sync_bits = mca->hw->sync_bits ?: frame_bits / 2; + u32 width_code; + +@@ -384,6 +530,8 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + default: + return -EINVAL; + } ++ if (frame_bits < slot * slots) ++ return -EINVAL; + + /* + * _setIISConfig_v4 for the board's iisConfig. The DAI is symmetric, +@@ -391,6 +539,10 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + * writes the half (or the block) it owns. + */ + mca->sample = (32 - bits) << 8 | (32 - bits); ++ /* clocks after the last slot; split in two for a 2-slot I2S frame */ ++ mca->pad = frame_bits - slot * slots; ++ if (!mca->hw->sync_bits && slots == 2) ++ mca->pad = (mca->pad / 2) << 16 | mca->pad / 2; + depth = mca_tx_depth(mca, params_rate(params), channels); + mca->tx_fifo_cfg = depth | (depth - 1) << 16; + mca->tx_slots = mca->hw->tx_slots; +@@ -404,7 +556,8 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + mca->hw->frame_flags; + + if (mca->hw->clock_provider) { +- unsigned long bitclk = params_rate(params) * frame_bits; ++ unsigned long bitclk = params_rate(params) * frame_bits * ++ mca->regs->nco_per_sclk; + int ret; + + ret = clk_set_rate(mca->bitclk, bitclk); +@@ -426,23 +579,37 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + + static void mca_write_tx(struct s8000_mca *mca) + { +- mca_write(mca, MCA_TX_FIFO_CFG, mca->tx_fifo_cfg); +- mca_write(mca, MCA_TX_SLOTS, mca->tx_slots); +- mca_write(mca, MCA_TX_SLOTS_HI, 0); +- mca_write(mca, MCA_TX_CFG, mca->tx_cfg & ~MCA_XX_CFG_EN); ++ const struct s8000_mca_regs *regs = mca->regs; ++ ++ if (regs->v1) ++ mca_write(mca, MCA_V1_TX_CTL, MCA_V1_XX_CTL_IOS); ++ mca_write(mca, regs->tx_fifo_cfg, mca->tx_fifo_cfg); ++ mca_write(mca, regs->tx_slots, mca->tx_slots); ++ if (regs->tx_slots_hi) ++ mca_write(mca, regs->tx_slots_hi, 0); ++ mca_write(mca, regs->tx_cfg, mca->tx_cfg & ~MCA_XX_CFG_EN); + } + + static void mca_write_rx(struct s8000_mca *mca) + { +- mca_write(mca, MCA_RX_FIFO_CFG, MCA_RX_FIFO_CFG_IOS); +- mca_write(mca, MCA_RX_SLOTS, mca->rx_slots); +- mca_write(mca, MCA_RX_SLOTS_HI, 0); +- mca_write(mca, MCA_RX_CFG, mca->hw->rx_cfg & ~MCA_XX_CFG_EN); ++ const struct s8000_mca_regs *regs = mca->regs; ++ ++ if (regs->v1) ++ mca_write(mca, MCA_V1_RX_CTL, MCA_V1_XX_CTL_IOS); ++ mca_write(mca, regs->rx_fifo_cfg, MCA_RX_FIFO_CFG_IOS); ++ mca_write(mca, regs->rx_slots, mca->rx_slots); ++ if (regs->rx_slots_hi) ++ mca_write(mca, regs->rx_slots_hi, 0); ++ mca_write(mca, regs->rx_cfg, mca->hw->rx_cfg & ~MCA_XX_CFG_EN); + } + +-/* The whole block, as _setIISConfig_v4: only while no direction is prepared */ ++/* ++ * The whole block, as _setIISConfig_v4 (or _v1): only while no direction is ++ * prepared ++ */ + static int mca_init_block(struct s8000_mca *mca) + { ++ const struct s8000_mca_regs *regs = mca->regs; + unsigned long flags; + u32 val; + int ret; +@@ -451,35 +618,45 @@ static int mca_init_block(struct s8000_mca *mca) + mca->irq_mask = MCA_IRQ_ALL; + spin_unlock_irqrestore(&mca->hw_lock, flags); + +- mca_write(mca, MCA_RESET, MCA_RESET_TX | MCA_RESET_RX); +- ret = readl_relaxed_poll_timeout(mca->base + MCA_RESET, val, +- !(val & (MCA_RESET_TX | MCA_RESET_RX)), +- MCA_POLL_US, MCA_TIMEOUT_US); +- if (ret) { +- dev_err(mca->dev, "reset timed out (%#x)\n", val); +- return ret; ++ mca_write(mca, regs->reset, MCA_RESET_TX | MCA_RESET_RX); ++ /* _setIISConfig_v1 resets and then waits for the flush only */ ++ if (!regs->v1) { ++ ret = readl_relaxed_poll_timeout(mca->base + regs->reset, val, ++ !(val & (MCA_RESET_TX | MCA_RESET_RX)), ++ MCA_POLL_US, MCA_TIMEOUT_US); ++ if (ret) { ++ dev_err(mca->dev, "reset timed out (%#x)\n", val); ++ return ret; ++ } + } + +- mca_write(mca, MCA_FLUSH, 1); +- ret = readl_relaxed_poll_timeout(mca->base + MCA_FLUSH, val, !(val & 1), +- MCA_POLL_US, MCA_TIMEOUT_US); ++ mca_write(mca, regs->flush, 1); ++ ret = readl_relaxed_poll_timeout(mca->base + regs->flush, val, ++ !(val & 1), MCA_POLL_US, ++ MCA_TIMEOUT_US); + if (ret) { + dev_err(mca->dev, "flush timed out (%#x)\n", val); + return ret; + } + +- mca_write(mca, MCA_IRQ_MASK, MCA_IRQ_ALL); +- mca_write(mca, MCA_IRQ_STATUS, MCA_IRQ_ALL); ++ mca_irq_set_mask(mca, MCA_IRQ_ALL); ++ mca_irq_ack(mca, MCA_IRQ_ALL); ++ if (regs->v1) { ++ mca_write(mca, MCA_V1_TX_CTL, MCA_V1_XX_CTL_IOS); ++ mca_write(mca, MCA_V1_RX_CTL, MCA_V1_XX_CTL_IOS); ++ } + mca_write(mca, MCA_SAMPLE, mca->sample); +- mca_write(mca, MCA_TX_FIFO_CFG, mca->tx_fifo_cfg); +- mca_write(mca, MCA_RX_FIFO_CFG, MCA_RX_FIFO_CFG_IOS); +- mca_write(mca, MCA_PAD, 0); +- mca_write(mca, MCA_TX_SLOTS, mca->tx_slots); +- mca_write(mca, MCA_TX_SLOTS_HI, 0); +- mca_write(mca, MCA_RX_SLOTS, mca->rx_slots); +- mca_write(mca, MCA_RX_SLOTS_HI, 0); +- mca_write(mca, MCA_TX_CFG, mca->tx_cfg & ~MCA_XX_CFG_EN); +- mca_write(mca, MCA_RX_CFG, mca->hw->rx_cfg & ~MCA_XX_CFG_EN); ++ mca_write(mca, regs->tx_fifo_cfg, mca->tx_fifo_cfg); ++ mca_write(mca, regs->rx_fifo_cfg, MCA_RX_FIFO_CFG_IOS); ++ mca_write(mca, MCA_PAD, mca->pad); ++ mca_write(mca, regs->tx_slots, mca->tx_slots); ++ if (regs->tx_slots_hi) ++ mca_write(mca, regs->tx_slots_hi, 0); ++ mca_write(mca, regs->rx_slots, mca->rx_slots); ++ if (regs->rx_slots_hi) ++ mca_write(mca, regs->rx_slots_hi, 0); ++ mca_write(mca, regs->tx_cfg, mca->tx_cfg & ~MCA_XX_CFG_EN); ++ mca_write(mca, regs->rx_cfg, mca->hw->rx_cfg & ~MCA_XX_CFG_EN); + return 0; + } + +@@ -489,8 +666,8 @@ static int mca_init_dir(struct s8000_mca *mca, bool tx) + u32 bit = tx ? MCA_RESET_TX : MCA_RESET_RX, val; + int ret; + +- mca_write(mca, MCA_RESET, bit); +- ret = readl_relaxed_poll_timeout(mca->base + MCA_RESET, val, ++ mca_write(mca, mca->regs->reset, bit); ++ ret = readl_relaxed_poll_timeout(mca->base + mca->regs->reset, val, + !(val & bit), MCA_POLL_US, + MCA_TIMEOUT_US); + if (ret) { +@@ -504,7 +681,7 @@ static int mca_init_dir(struct s8000_mca *mca, bool tx) + mca_write_tx(mca); + else + mca_write_rx(mca); +- mca_write(mca, MCA_IRQ_STATUS, tx ? MCA_IRQ_TX_ALL : MCA_IRQ_RX_ALL); ++ mca_irq_ack(mca, tx ? MCA_IRQ_TX_ALL : MCA_IRQ_RX_ALL); + return 0; + } + +@@ -540,7 +717,7 @@ static int mca_prepare(struct snd_pcm_substream *substream, + */ + if (mca->hw->clocks_at_prepare && (mca->prep_mask & BIT(dir)) && + mca->prep_frame == mca->frame && +- mca_read(mca, MCA_FRAME) == (mca->frame | MCA_FRAME_RUN)) { ++ mca_read(mca, mca->regs->frame) == (mca->frame | MCA_FRAME_RUN)) { + spin_unlock_irqrestore(&mca->hw_lock, flags); + return 0; + } +@@ -567,11 +744,11 @@ static int mca_prepare(struct snd_pcm_substream *substream, + mca->prep_mask |= BIT(dir); + mca->irq_mask &= ~(tx ? MCA_IRQ_TX_CAUSES | mca->hw->stream_irqs : + MCA_IRQ_RX_CAUSES); +- mca_write(mca, MCA_IRQ_MASK, mca->irq_mask); ++ mca_irq_set_mask(mca, mca->irq_mask); + if (first && tx && mca->hw->clocks_at_prepare) +- mca_write(mca, MCA_TX_CFG, mca->tx_cfg | MCA_XX_CFG_EN); ++ mca_write(mca, mca->regs->tx_cfg, mca->tx_cfg | MCA_XX_CFG_EN); + if (first) +- mca_write(mca, MCA_FRAME, mca->frame | ++ mca_write(mca, mca->regs->frame, mca->frame | + (mca->hw->clocks_at_prepare ? MCA_FRAME_RUN : 0)); + mca->prep_frame = mca->frame; + spin_unlock_irqrestore(&mca->hw_lock, flags); +@@ -586,9 +763,9 @@ static void mca_stop_tx(struct s8000_mca *mca) + { + u32 val; + +- mca_write(mca, MCA_TX_CFG, 0); +- mca_write(mca, MCA_RESET, MCA_RESET_TX); +- if (readl_relaxed_poll_timeout_atomic(mca->base + MCA_RESET, val, ++ mca_write(mca, mca->regs->tx_cfg, 0); ++ mca_write(mca, mca->regs->reset, MCA_RESET_TX); ++ if (readl_relaxed_poll_timeout_atomic(mca->base + mca->regs->reset, val, + !(val & MCA_RESET_TX), 1, 1000)) + dev_warn(mca->dev, "TX reset timed out\n"); + } +@@ -613,12 +790,12 @@ static int mca_hw_free(struct snd_pcm_substream *substream, + mca->irq_mask = MCA_IRQ_ALL; + if (mca->hw->clocks_at_prepare) + mca_stop_tx(mca); +- mca_write(mca, MCA_FRAME, 0); ++ mca_write(mca, mca->regs->frame, 0); + } else { + mca->irq_mask |= dir == SNDRV_PCM_STREAM_PLAYBACK ? + MCA_IRQ_TX_ALL : MCA_IRQ_RX_ALL; + } +- mca_write(mca, MCA_IRQ_MASK, mca->irq_mask); ++ mca_irq_set_mask(mca, mca->irq_mask); + spin_unlock_irqrestore(&mca->hw_lock, flags); + + if (last) { +@@ -647,14 +824,16 @@ static int mca_trigger(struct snd_pcm_substream *substream, int cmd, + case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: + spin_lock_irqsave(&mca->hw_lock, flags); + /* the other direction's pending causes are not ours to clear */ +- mca_write(mca, MCA_IRQ_STATUS, !mca->run_mask ? MCA_IRQ_ALL : +- tx ? MCA_IRQ_TX_ALL : MCA_IRQ_RX_ALL); ++ mca_irq_ack(mca, !mca->run_mask ? MCA_IRQ_ALL : ++ tx ? MCA_IRQ_TX_ALL : MCA_IRQ_RX_ALL); + if (tx) +- mca_write(mca, MCA_TX_CFG, mca->tx_cfg | MCA_XX_CFG_EN); ++ mca_write(mca, mca->regs->tx_cfg, ++ mca->tx_cfg | MCA_XX_CFG_EN); + else +- mca_write(mca, MCA_RX_CFG, mca->hw->rx_cfg | MCA_XX_CFG_EN); ++ mca_write(mca, mca->regs->rx_cfg, ++ mca->hw->rx_cfg | MCA_XX_CFG_EN); + mca->run_mask |= BIT(dir); +- mca_write(mca, MCA_FRAME, mca->frame | MCA_FRAME_RUN); ++ mca_write(mca, mca->regs->frame, mca->frame | MCA_FRAME_RUN); + spin_unlock_irqrestore(&mca->hw_lock, flags); + return 0; + case SNDRV_PCM_TRIGGER_STOP: +@@ -667,17 +846,18 @@ static int mca_trigger(struct snd_pcm_substream *substream, int cmd, + spin_unlock_irqrestore(&mca->hw_lock, flags); + return 0; + } +- mca_write(mca, tx ? MCA_TX_CFG : MCA_RX_CFG, 0); ++ mca_write(mca, tx ? mca->regs->tx_cfg : mca->regs->rx_cfg, 0); + /* + * MAX98357 asks not to lose LRCLK while BCLK runs and the amp + * is on, and the amp stops after this DAI: a provider keeps + * the frame running until hw_free. + */ + if (!mca->run_mask && !mca->hw->clock_provider) +- mca_write(mca, MCA_FRAME, mca->frame); +- /* TX stops with RESET = 1, RX with RESET = 2 (iOS) */ +- mca_write(mca, MCA_RESET, reset); +- ret = readl_relaxed_poll_timeout_atomic(mca->base + MCA_RESET, ++ mca_write(mca, mca->regs->frame, mca->frame); ++ /* TX stops with RESET = 1, RX with RESET = 2 (iOS, v1 and v4) */ ++ mca_write(mca, mca->regs->reset, reset); ++ ret = readl_relaxed_poll_timeout_atomic(mca->base + ++ mca->regs->reset, + val, !(val & reset), 1, + 1000); + spin_unlock_irqrestore(&mca->hw_lock, flags); +@@ -823,7 +1003,7 @@ static irqreturn_t mca_irq(int irq, void *data) + u32 raw, status; + + spin_lock(&mca->hw_lock); +- raw = mca_read(mca, MCA_IRQ_STATUS); ++ raw = mca_irq_status(mca); + /* + * Only bits 12:0 are interrupt causes (iOS tests status & 0x1fff and + * reports anything else as spurious). Bit 31 also reads as set while +@@ -834,13 +1014,13 @@ static irqreturn_t mca_irq(int irq, void *data) + status = raw & MCA_IRQ_ALL & ~mca->irq_mask; + if (!status) { + /* resync the hardware mask, so a stale open mask cannot storm */ +- mca_write(mca, MCA_IRQ_MASK, mca->irq_mask); +- mca_write(mca, MCA_IRQ_STATUS, raw & MCA_IRQ_ALL); ++ mca_irq_set_mask(mca, mca->irq_mask); ++ mca_irq_ack(mca, raw & MCA_IRQ_ALL); + spin_unlock(&mca->hw_lock); + return IRQ_NONE; + } + +- mca_write(mca, MCA_IRQ_STATUS, status); ++ mca_irq_ack(mca, status); + if (status & MCA_IRQ_ERRORS) { + /* + * Error causes re-latch every frame while the condition lasts +@@ -848,7 +1028,10 @@ static irqreturn_t mca_irq(int irq, void *data) + * prepare instead of taking an interrupt per frame. + */ + mca->irq_mask |= status & MCA_IRQ_ERRORS; +- mca_write(mca, MCA_IRQ_MASK, mca->irq_mask); ++ /* v1 has one enable for both directions' FIFO errors */ ++ if (mca->regs->v1 && (status & MCA_IRQ_V1_FIFO)) ++ mca->irq_mask |= MCA_IRQ_V1_FIFO; ++ mca_irq_set_mask(mca, mca->irq_mask); + dev_dbg_ratelimited(mca->dev, "irq status %#x, masked\n", + status); + } +@@ -867,7 +1050,7 @@ static int mca_runtime_suspend(struct device *dev) + struct s8000_mca *mca = dev_get_drvdata(dev); + + disable_irq(mca->irq); +- mca_write(mca, MCA_IRQ_MASK, MCA_IRQ_ALL); ++ mca_irq_set_mask(mca, MCA_IRQ_ALL); + return 0; + } + +@@ -882,8 +1065,8 @@ static int mca_runtime_resume(struct device *dev) + * unmasks what a stream needs. + */ + mca->irq_mask = MCA_IRQ_ALL; +- mca_write(mca, MCA_IRQ_MASK, MCA_IRQ_ALL); +- mca_write(mca, MCA_IRQ_STATUS, MCA_IRQ_ALL); ++ mca_irq_set_mask(mca, MCA_IRQ_ALL); ++ mca_irq_ack(mca, MCA_IRQ_ALL); + enable_irq(mca->irq); + return 0; + } +@@ -965,6 +1148,7 @@ static int s8000_mca_get_route(struct s8000_mca *mca) + */ + static const struct s8000_mca_hw t8010_i2s_mca_hw = { + .version = 5, ++ .regs = &mca_v4_regs, + .clock_provider = true, + .clocks_at_prepare = true, + .dai_format = SND_SOC_DAIFMT_I2S, +@@ -1000,6 +1184,7 @@ static int s8000_mca_probe(struct platform_device *pdev) + mca->hw = device_get_match_data(dev); + if (!mca->hw) + return -ENODEV; ++ mca->regs = mca->hw->regs; + spin_lock_init(&mca->hw_lock); + mca->irq_mask = MCA_IRQ_ALL; + platform_set_drvdata(pdev, mca); +@@ -1046,6 +1231,9 @@ static int s8000_mca_probe(struct platform_device *pdev) + fifo = mca_read(mca, MCA_FIFO_SIZE); + pm_runtime_put(dev); + ++ /* Version 1 keeps the version in the upper half (0x00010002 on a J81) */ ++ if (mca->hw->version == 1) ++ ver >>= 16; + mca->fifo_tx = FIELD_GET(MCA_FIFO_SIZE_TX, fifo); + if (ver != mca->hw->version || mca->fifo_tx < 8) + dev_warn(dev, "unexpected MCA version %u, TX FIFO %u\n", ver, +@@ -1106,6 +1294,7 @@ static int s8000_mca_probe(struct platform_device *pdev) + /* MCA0 on S8000/S8003, from iOS 16.7.10 AppleAE2MCA and the J71t ADT */ + static const struct s8000_mca_hw s8000_mca_hw = { + .version = 4, ++ .regs = &mca_v4_regs, + .dai_format = SND_SOC_DAIFMT_I2S, + .channels = 2, + .slots = 2, +@@ -1135,6 +1324,7 @@ static const struct s8000_mca_hw s8000_mca_hw = { + */ + static const struct s8000_mca_hw t8010_mca_hw = { + .version = 5, ++ .regs = &mca_v4_regs, + .clock_provider = true, + .dai_format = SND_SOC_DAIFMT_DSP_A, + .channels = 4, +@@ -1153,8 +1343,52 @@ static const struct s8000_mca_hw t8010_mca_hw = { + .sio_trigger = 0xcc, + }; + ++/* ++ * J81 (iPad Air 2) MCA3 TX, from the ADT's /arm-io/mca3/audio-speaker0 ++ * iisConfig (iOS 15.8 19H422): ++ * ++ * 01 12 00 00 08 00 00 00 00 00 00 00 00 01 10 00 ++ * 00 00 00 00 03 00 00 00 ff 00 00 00 02 08 10 10 00 00 00 00 ++ * ++ * provider, format flags 0x12, 8 slots in a fixed 256-bit frame with a ++ * 16-bit sync pulse, two TX channels in slots 0-1 (the two MAX98721 ++ * amplifiers), eight RX channels (not used here), 16-bit samples. Under ++ * _setIISConfig_v1 that is TX_CFG 0x109 (data delay 1), RX_CFG 0x00b, ++ * FRAME 0x0f107005 + RUN, PAD 128, TX_SLOTS 0x3, and a bitclock NCO ++ * (function-mclk_frequency, NCO 3) at twice SCLK: 24.576 MHz at 48 kHz. ++ * The MCLK word stays 0: iisConfig[0] bit 4 (MCLK output) is clear. The ++ * SmartIO shim words are the ADT's dma-channels (FIFO 0xcc, trigger 0xac). ++ * ++ * As on J71b, the output is bounded to -12 dB until the amplifiers have ++ * a driver and speaker protection. ++ */ ++static const struct s8000_mca_hw t7001_mca_hw = { ++ .version = 1, ++ .regs = &mca_v1_regs, ++ .clock_provider = true, ++ .dai_format = SND_SOC_DAIFMT_DSP_A, ++ .channels = 2, ++ .slots = 8, ++ .frame_bits = 256, ++ .tx_slots = 0x3, ++ .tx_cfg = 0x109, ++ .rx_cfg = 0x00b, ++ .rx_slots = 0xff, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ .frame_flags = MCA_FRAME_POL, ++ .sync_bits = 16, ++ .stream_irqs = MCA_IRQ_FRAME_ERROR, ++ .attenuation = 4, ++ .sio_xfer16 = 0x21, ++ .sio_xfer32 = 0x22, ++ .sio_timeout = 0, ++ .sio_fifo = 0xcc, ++ .sio_trigger = 0xac, ++}; ++ + static const struct of_device_id s8000_mca_of_match[] = { + { .compatible = "apple,s8000-mca", .data = &s8000_mca_hw }, ++ { .compatible = "apple,t7001-mca", .data = &t7001_mca_hw }, + { .compatible = "apple,t8010-mca", .data = &t8010_mca_hw }, + { .compatible = "apple,t8010-mca-i2s", .data = &t8010_i2s_mca_hw }, + { } +-- +2.56.0 + diff --git a/kernel/patches/drivers/sound/0022-dt-bindings-sound-maxim-max98925-Add-the-MAX98721.patch b/kernel/patches/drivers/sound/0022-dt-bindings-sound-maxim-max98925-Add-the-MAX98721.patch new file mode 100644 index 00000000..ea5cb928 --- /dev/null +++ b/kernel/patches/drivers/sound/0022-dt-bindings-sound-maxim-max98925-Add-the-MAX98721.patch @@ -0,0 +1,104 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 23:10:00 +0100 +Subject: [PATCH] dt-bindings: sound: maxim,max98925: Add the MAX98721 + +The MAX98721 is the speaker amplifier of the iPad Air 2. It has no public +datasheet, but every register iOS programs matches the MAX98925 map, so +describe it in the MAX98925 binding. It runs as a TDM consumer and takes +its playback slot from its DAI link, so allow a graph port, and its +interrupt line. + +sound-name-prefix comes from dai-common.yaml, which additionalProperties +does not see; use unevaluatedProperties so a board with two amplifiers +can name them apart. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + .../bindings/sound/maxim,max98925.yaml | 41 ++++++++++++++++++- + 1 file changed, 39 insertions(+), 2 deletions(-) + +diff --git a/Documentation/devicetree/bindings/sound/maxim,max98925.yaml b/Documentation/devicetree/bindings/sound/maxim,max98925.yaml +index 121e8d2..7d42740 100644 +--- a/Documentation/devicetree/bindings/sound/maxim,max98925.yaml ++++ b/Documentation/devicetree/bindings/sound/maxim,max98925.yaml +@@ -4,14 +4,20 @@ + $id: http://devicetree.org/schemas/sound/maxim,max98925.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Maxim Integrated MAX98925/MAX98926/MAX98927 speaker amplifier ++title: Maxim Integrated MAX98721/MAX98925/MAX98926/MAX98927 speaker amplifier + + maintainers: + - Ryan Lee + ++description: ++ The MAX98721 is a variant of the MAX98925 found in Apple devices. It runs ++ as a TDM consumer and plays the first slot of its DAI link's ++ dai-tdm-slot-rx-mask. ++ + properties: + compatible: + enum: ++ - maxim,max98721 + - maxim,max98925 + - maxim,max98926 + - maxim,max98927 +@@ -19,12 +25,19 @@ properties: + reg: + maxItems: 1 + ++ interrupts: ++ maxItems: 1 ++ + reset-gpios: + maxItems: 1 + + '#sound-dai-cells': + const: 0 + ++ port: ++ $ref: audio-graph-port.yaml# ++ unevaluatedProperties: false ++ + vmon-slot-no: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0 +@@ -73,7 +86,7 @@ allOf: + minimum: 0 + maximum: 15 + +-additionalProperties: false ++unevaluatedProperties: false + + examples: + - | +@@ -96,3 +109,27 @@ examples: + imon-slot-no = <0>; + }; + }; ++ ++ - | ++ #include ++ i2c { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ ++ amplifier@31 { ++ compatible = "maxim,max98721"; ++ reg = <0x31>; ++ interrupts-extended = <&pinctrl 8 IRQ_TYPE_LEVEL_LOW>; ++ #sound-dai-cells = <0>; ++ sound-name-prefix = "Amp0"; ++ ++ port { ++ endpoint { ++ remote-endpoint = <&speaker_amp0_ep>; ++ dai-tdm-slot-num = <8>; ++ dai-tdm-slot-width = <32>; ++ dai-tdm-slot-rx-mask = <1>; ++ }; ++ }; ++ }; ++ }; diff --git a/kernel/patches/drivers/sound/0023-ASoC-codecs-Add-the-Maxim-MAX98721-speaker-amplifier.patch b/kernel/patches/drivers/sound/0023-ASoC-codecs-Add-the-Maxim-MAX98721-speaker-amplifier.patch new file mode 100644 index 00000000..57815fc6 --- /dev/null +++ b/kernel/patches/drivers/sound/0023-ASoC-codecs-Add-the-Maxim-MAX98721-speaker-amplifier.patch @@ -0,0 +1,495 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Thu, 19 Nov 2026 23:12:00 +0100 +Subject: [PATCH] ASoC: codecs: Add the Maxim MAX98721 speaker amplifier + +The iPad Air 2 drives its two speakers through MAX98721 amplifiers on +I2C (0x31 and 0x34), fed by MCA3 in TDM. The part has no public +datasheet; every register iOS 15's AppleMAX98721Amp programs matches the +MAX98925 map, so reuse that header. The MAX98925 driver itself does not +fit: it wants an MCLK-derived clock at 32-64 BCLKs per frame and a +known revision, and programs its own limiter and boost defaults. + +This driver does what iOS does, for a playback-only link: + +- probe: read the revision (iOS checks only that the part answers), + turn the global and block enables off, write the flag map, TDM format, + DOUT off and Hi-Z, and the protection settings from Apple's device + tree record for the J81 (DC-block filter, ALC limiter on at threshold + 0x0a, boost voltage code 0 (8.5 V on the MAX98925) with skip mode, + boost current limit 0x0a); +- hw_params: TDM with one bit of delay, word size, sample rate code, + consumer clocked from BCLK, 256 BCLKs per frame (iOS's value for every + word size; MCA3 pads its eight 16-bit slots to 256 bits); +- set_tdm_slot: the first slot of rx_mask, on both DAI inputs (iOS gives + amplifier n slot n); +- DAPM: block enable (boost, clock monitor, speaker), then global enable + and 1.5 ms; on the way down global disable, 9 ms, block disable. + +For speaker safety the gain starts at 0 (mute in iOS's use), the volume +control stops at iOS's gain (0x16), the limiter and boost limits are +fixed, and the amplifier is enabled only while a stream runs. The +IV-sense ADCs and their DOUT slots, which iOS's speaker protection uses, +stay off. If the interrupt is wired, thermal, overcurrent and slot +errors are logged and cleared. + +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +Co-Authored-By: Claude Opus 5.5 +--- + sound/soc/codecs/Kconfig | 10 + + sound/soc/codecs/Makefile | 2 + + sound/soc/codecs/max98721.c | 397 ++++++++++++++++++++++++++++++++++++ + 3 files changed, 409 insertions(+) + create mode 100644 sound/soc/codecs/max98721.c + +diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig +index 5d21695..2e909a8 100644 +--- a/sound/soc/codecs/Kconfig ++++ b/sound/soc/codecs/Kconfig +@@ -151,6 +151,7 @@ config SND_SOC_ALL_CODECS + imply SND_SOC_MAX98504 + imply SND_SOC_MAX98520 + imply SND_SOC_MAX9867 ++ imply SND_SOC_MAX98721 + imply SND_SOC_MAX98925 + imply SND_SOC_MAX98926 + imply SND_SOC_MAX98927 +@@ -1459,6 +1460,15 @@ config SND_SOC_MAX9867 + tristate "Maxim MAX9867 CODEC" + depends on I2C + ++config SND_SOC_MAX98721 ++ tristate "Maxim MAX98721 speaker amplifier" ++ depends on I2C ++ select REGMAP_I2C ++ help ++ Enable support for the Maxim MAX98721 boosted class-D speaker ++ amplifier, as used in the Apple iPad Air 2. It is driven as a TDM ++ consumer with the register map of the MAX98925. ++ + config SND_SOC_MAX98925 + tristate + depends on I2C +diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile +index a23e914..a90619a 100644 +--- a/sound/soc/codecs/Makefile ++++ b/sound/soc/codecs/Makefile +@@ -174,6 +174,7 @@ snd-soc-max98095-y := max98095.o + snd-soc-max98357a-y := max98357a.o + snd-soc-max98371-y := max98371.o + snd-soc-max9867-y := max9867.o ++snd-soc-max98721-y := max98721.o + snd-soc-max98925-y := max98925.o + snd-soc-max98926-y := max98926.o + snd-soc-max98927-y := max98927.o +@@ -614,6 +615,7 @@ obj-$(CONFIG_SND_SOC_MAX98095) += snd-soc-max98095.o + obj-$(CONFIG_SND_SOC_MAX98357A) += snd-soc-max98357a.o + obj-$(CONFIG_SND_SOC_MAX98371) += snd-soc-max98371.o + obj-$(CONFIG_SND_SOC_MAX9867) += snd-soc-max9867.o ++obj-$(CONFIG_SND_SOC_MAX98721) += snd-soc-max98721.o + obj-$(CONFIG_SND_SOC_MAX98925) += snd-soc-max98925.o + obj-$(CONFIG_SND_SOC_MAX98926) += snd-soc-max98926.o + obj-$(CONFIG_SND_SOC_MAX98927) += snd-soc-max98927.o +diff --git a/sound/soc/codecs/max98721.c b/sound/soc/codecs/max98721.c +new file mode 100644 +index 0000000..3695a82 +--- /dev/null ++++ b/sound/soc/codecs/max98721.c +@@ -0,0 +1,397 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * MAX98721 speaker amplifier, as used in the Apple iPad Air 2 ++ * ++ * The MAX98721 has no public datasheet. Every register that iOS touches ++ * matches the MAX98925 map, so this driver uses that map. The sequence ++ * follows iOS 15's AppleMAX98721Amp: TDM consumer clocked from BCLK, one ++ * playback slot per amplifier, the protection settings Apple's device tree ++ * gives (limiter, boost and boost current limit) and the global enable only ++ * while a stream runs. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "max98925.h" ++ ++/* FORMAT as iOS sets it: TDM, one bit of delay, BCI, EXTBCLK_HIZ. */ ++#define MAX98721_FORMAT_TDM (M98925_DAI_EXTBCLK_HIZ_MASK | \ ++ M98925_DAI_BCI_MASK | \ ++ M98925_DAI_DLY_MASK | \ ++ M98925_DAI_TDM_MASK) ++ ++/* DAI_CLK_MODE1: clocked from BCLK, MDLL multiplier 6, as iOS sets it. */ ++#define MAX98721_CLK_MODE1_MASK (M98925_DAI_CLK_SOURCE_MASK | \ ++ M98925_MDLL_MULT_MASK) ++#define MAX98721_CLK_MODE1 (M98925_DAI_CLK_SOURCE_MASK | 6) ++ ++/* BLOCK_ENABLE: boost, clock monitor and speaker; no IV-sense ADCs. */ ++#define MAX98721_BLOCK_EN (M98925_BST_EN_MASK | M98925_CLKMON_EN_MASK | \ ++ M98925_SPK_EN_MASK) ++ ++/* The gain iOS uses on J81 (speaker-config byte 1); never exceeded. */ ++#define MAX98721_GAIN_MAX 0x16 ++ ++struct max98721_priv { ++ struct regmap *regmap; ++}; ++ ++/* ++ * Written once at probe, with both enables off. The protection values are ++ * the iPad Air 2's speaker-config from Apple's device tree; both amplifiers ++ * use the same record. ++ */ ++static const struct reg_sequence max98721_init[] = { ++ { MAX98925_GLOBAL_ENABLE, 0x00 }, ++ { MAX98925_BLOCK_ENABLE, 0x00 }, ++ /* Flag-to-DOUT map, as iOS writes it. */ ++ { MAX98925_MAP0, 0xc0 }, ++ { MAX98925_MAP1, 0x00 }, ++ { MAX98925_MAP2, 0x00 }, ++ { MAX98925_MAP3, 0xf0 }, ++ { MAX98925_MAP4, 0x00 }, ++ { MAX98925_MAP5, 0xab }, ++ { MAX98925_MAP6, 0x89 }, ++ { MAX98925_MAP7, 0x00 }, ++ { MAX98925_MAP8, 0x00 }, ++ { MAX98925_FORMAT, M98925_DAI_CHANSZ_16 | ++ MAX98721_FORMAT_TDM }, ++ /* Playback slot 0; DOUT (IV sense) off and Hi-Z in every slot. */ ++ { MAX98925_TDM_SLOT_SELECT, M98925_DAI_DIN_EN_MASK }, ++ { MAX98925_DOUT_CFG_VMON, 0x00 }, ++ { MAX98925_DOUT_CFG_IMON, 0x00 }, ++ { MAX98925_DOUT_CFG_VBAT, 0x00 }, ++ { MAX98925_DOUT_CFG_VBST, 0x00 }, ++ { MAX98925_DOUT_CFG_FLAG, 0x00 }, ++ { MAX98925_DOUT_HIZ_CFG1, 0xff }, ++ { MAX98925_DOUT_HIZ_CFG2, 0xff }, ++ { MAX98925_DOUT_HIZ_CFG3, 0xff }, ++ { MAX98925_DOUT_HIZ_CFG4, 0xff }, ++ { MAX98925_DOUT_DRV_STRENGTH, 0x02 }, ++ /* speaker-config bytes 0 and 2-9 */ ++ { MAX98925_FILTERS, 0xd1 }, /* dither, IV DC block, DC-block HPF */ ++ { MAX98925_GAIN_RAMPING, 0x00 }, ++ { MAX98925_SPK_AMP, 0x00 }, ++ { MAX98925_THRESHOLD, 0x2a }, /* ALC on, threshold 0x0a */ ++ { MAX98925_ALC_ATTACK, 0x00 }, ++ { MAX98925_ALC_ATTEN_RLS, 0x84 }, ++ { MAX98925_ALC_HOLD_RLS, 0x00 }, ++ { MAX98925_ALC_CONFIGURATION, 0x03 }, ++ { MAX98925_BOOST_CONVERTER, 0x01 }, ++ { MAX98925_CONFIGURATION, 0x03 }, /* iOS ORs 3 into byte 9 (0) */ ++ /* Clear stale interrupt flags. */ ++ { MAX98925_IRQ_CLEAR0, 0xff }, ++ { MAX98925_IRQ_CLEAR1, 0xff }, ++ { MAX98925_IRQ_CLEAR2, 0xff }, ++}; ++ ++/* 0 mutes; 1 is -6 dB, in 1 dB steps (inferred from iOS writing 0 to mute). */ ++static const DECLARE_TLV_DB_SCALE(max98721_gain_tlv, -700, 100, 1); ++ ++static const struct snd_kcontrol_new max98721_controls[] = { ++ SOC_SINGLE_TLV("Speaker Volume", MAX98925_GAIN, M98925_SPK_GAIN_SHIFT, ++ MAX98721_GAIN_MAX, 0, max98721_gain_tlv), ++}; ++ ++/* ++ * iOS turns the blocks on first and the global enable last, then waits ++ * 1.5 ms; it turns the global enable off first and waits 9 ms before it ++ * turns the blocks off. ++ */ ++static int max98721_amp_event(struct snd_soc_dapm_widget *w, ++ struct snd_kcontrol *kcontrol, int event) ++{ ++ struct snd_soc_component *component = snd_soc_dapm_to_component(w->dapm); ++ struct max98721_priv *priv = snd_soc_component_get_drvdata(component); ++ ++ switch (event) { ++ case SND_SOC_DAPM_PRE_PMU: ++ return regmap_write(priv->regmap, MAX98925_BLOCK_ENABLE, ++ MAX98721_BLOCK_EN); ++ case SND_SOC_DAPM_POST_PMU: ++ regmap_write(priv->regmap, MAX98925_GLOBAL_ENABLE, ++ M98925_EN_MASK); ++ usleep_range(1500, 2000); ++ break; ++ case SND_SOC_DAPM_PRE_PMD: ++ regmap_write(priv->regmap, MAX98925_GLOBAL_ENABLE, 0); ++ usleep_range(9000, 10000); ++ break; ++ case SND_SOC_DAPM_POST_PMD: ++ regmap_write(priv->regmap, MAX98925_BLOCK_ENABLE, 0); ++ break; ++ } ++ ++ return 0; ++} ++ ++static const struct snd_soc_dapm_widget max98721_dapm_widgets[] = { ++ SND_SOC_DAPM_AIF_IN("AIFIN", "HiFi Playback", 0, SND_SOC_NOPM, 0, 0), ++ SND_SOC_DAPM_OUT_DRV_E("Amp", SND_SOC_NOPM, 0, 0, NULL, 0, ++ max98721_amp_event, ++ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMU | ++ SND_SOC_DAPM_PRE_PMD | SND_SOC_DAPM_POST_PMD), ++ SND_SOC_DAPM_OUTPUT("OUT"), ++}; ++ ++static const struct snd_soc_dapm_route max98721_dapm_routes[] = { ++ { "Amp", NULL, "AIFIN" }, ++ { "OUT", NULL, "Amp" }, ++}; ++ ++/* The sample rate codes iOS uses, which match the MAX98925's. */ ++static const unsigned int max98721_rates[] = { ++ 8000, 11025, 12000, 16000, 22050, 24000, 32000, 44100, 48000, ++}; ++ ++static int max98721_hw_params(struct snd_pcm_substream *substream, ++ struct snd_pcm_hw_params *params, ++ struct snd_soc_dai *dai) ++{ ++ struct snd_soc_component *component = dai->component; ++ struct max98721_priv *priv = snd_soc_component_get_drvdata(component); ++ unsigned int chansz, sr; ++ int i; ++ ++ switch (params_width(params)) { ++ case 16: ++ chansz = M98925_DAI_CHANSZ_16; ++ break; ++ case 24: ++ chansz = M98925_DAI_CHANSZ_24; ++ break; ++ case 32: ++ chansz = M98925_DAI_CHANSZ_32; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ for (i = 0; i < ARRAY_SIZE(max98721_rates); i++) ++ if (max98721_rates[i] == params_rate(params)) ++ break; ++ if (i == ARRAY_SIZE(max98721_rates)) ++ return -EINVAL; ++ sr = i; ++ ++ regmap_write(priv->regmap, MAX98925_FORMAT, ++ chansz | MAX98721_FORMAT_TDM); ++ regmap_update_bits(priv->regmap, MAX98925_DAI_CLK_MODE1, ++ MAX98721_CLK_MODE1_MASK, MAX98721_CLK_MODE1); ++ /* ++ * Consumer (DAI_MAS clear), with the 256-BCLK frame iOS sets for every ++ * word size: the J81's MCA3 pads its eight slots to 256 bits. ++ */ ++ return regmap_write(priv->regmap, MAX98925_DAI_CLK_MODE2, ++ (sr << M98925_DAI_SR_SHIFT) | M98925_DAI_BSEL_256); ++} ++ ++static int max98721_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) ++{ ++ /* The only mode iOS uses: MCA-clocked TDM, data one bit late. */ ++ if ((fmt & SND_SOC_DAIFMT_CLOCK_PROVIDER_MASK) != SND_SOC_DAIFMT_CBC_CFC || ++ (fmt & SND_SOC_DAIFMT_FORMAT_MASK) != SND_SOC_DAIFMT_DSP_A || ++ (fmt & SND_SOC_DAIFMT_INV_MASK) != SND_SOC_DAIFMT_NB_NF) ++ return -EINVAL; ++ ++ return 0; ++} ++ ++/* The amplifier plays the first slot of rx_mask, on both of its inputs. */ ++static int max98721_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, ++ unsigned int rx_mask, int slots, int slot_width) ++{ ++ struct max98721_priv *priv = snd_soc_component_get_drvdata(dai->component); ++ unsigned int slot = 0; ++ ++ if (slots) { ++ if (!rx_mask || __ffs(rx_mask) > 7) ++ return -EINVAL; ++ slot = __ffs(rx_mask); ++ } ++ ++ return regmap_write(priv->regmap, MAX98925_TDM_SLOT_SELECT, ++ M98925_DAI_DIN_EN_MASK | ++ (slot << M98925_DAI_INR_SOURCE_SHIFT) | ++ (slot << M98925_DAI_INL_SOURCE_SHIFT)); ++} ++ ++static const struct snd_soc_dai_ops max98721_dai_ops = { ++ .hw_params = max98721_hw_params, ++ .set_fmt = max98721_set_fmt, ++ .set_tdm_slot = max98721_set_tdm_slot, ++}; ++ ++static struct snd_soc_dai_driver max98721_dai = { ++ .name = "max98721-aif", ++ .playback = { ++ .stream_name = "HiFi Playback", ++ .channels_min = 1, ++ .channels_max = 8, ++ .rates = SNDRV_PCM_RATE_8000_48000, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE | ++ SNDRV_PCM_FMTBIT_S24_LE | ++ SNDRV_PCM_FMTBIT_S32_LE, ++ }, ++ .ops = &max98721_dai_ops, ++}; ++ ++static const struct snd_soc_component_driver max98721_component = { ++ .controls = max98721_controls, ++ .num_controls = ARRAY_SIZE(max98721_controls), ++ .dapm_widgets = max98721_dapm_widgets, ++ .num_dapm_widgets = ARRAY_SIZE(max98721_dapm_widgets), ++ .dapm_routes = max98721_dapm_routes, ++ .num_dapm_routes = ARRAY_SIZE(max98721_dapm_routes), ++ .endianness = 1, ++}; ++ ++static bool max98721_volatile_reg(struct device *dev, unsigned int reg) ++{ ++ return reg <= MAX98925_IRQ_CLEAR2 || reg == MAX98925_REV_VERSION; ++} ++ ++static bool max98721_readable_reg(struct device *dev, unsigned int reg) ++{ ++ switch (reg) { ++ case MAX98925_VBAT_DATA ... MAX98925_IRQ_ENABLE2: ++ case MAX98925_MAP0 ... MAX98925_ALC_ATTEN_RLS: ++ case MAX98925_ALC_CONFIGURATION ... MAX98925_GLOBAL_ENABLE: ++ case MAX98925_BOOST_LIMITER: ++ case MAX98925_REV_VERSION: ++ return true; ++ default: ++ return false; ++ } ++} ++ ++static bool max98721_writeable_reg(struct device *dev, unsigned int reg) ++{ ++ switch (reg) { ++ case MAX98925_IRQ_ENABLE0 ... MAX98925_GLOBAL_ENABLE: ++ case MAX98925_BOOST_LIMITER: ++ return true; ++ default: ++ return false; ++ } ++} ++ ++static const struct regmap_config max98721_regmap = { ++ .reg_bits = 8, ++ .val_bits = 8, ++ .max_register = MAX98925_REV_VERSION, ++ .volatile_reg = max98721_volatile_reg, ++ .readable_reg = max98721_readable_reg, ++ .writeable_reg = max98721_writeable_reg, ++ .cache_type = REGCACHE_MAPLE, ++}; ++ ++/* iOS reads and clears the flags but enables no interrupt; report a few. */ ++static irqreturn_t max98721_irq(int irq, void *data) ++{ ++ struct device *dev = data; ++ struct max98721_priv *priv = dev_get_drvdata(dev); ++ unsigned int flag[3] = {}; ++ int i; ++ ++ for (i = 0; i < 3; i++) ++ regmap_read(priv->regmap, MAX98925_FLAG0 + i, &flag[i]); ++ for (i = 0; i < 3; i++) ++ regmap_write(priv->regmap, MAX98925_IRQ_CLEAR0 + i, 0xff); ++ ++ if (!(flag[0] | flag[1] | flag[2])) ++ return IRQ_NONE; ++ ++ dev_warn_ratelimited(dev, "interrupt: flags %02x %02x %02x\n", ++ flag[0], flag[1], flag[2]); ++ return IRQ_HANDLED; ++} ++ ++static int max98721_i2c_probe(struct i2c_client *i2c) ++{ ++ struct device *dev = &i2c->dev; ++ struct max98721_priv *priv; ++ unsigned int rev; ++ int ret; ++ ++ priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); ++ if (!priv) ++ return -ENOMEM; ++ i2c_set_clientdata(i2c, priv); ++ ++ priv->regmap = devm_regmap_init_i2c(i2c, &max98721_regmap); ++ if (IS_ERR(priv->regmap)) ++ return dev_err_probe(dev, PTR_ERR(priv->regmap), ++ "failed to init regmap\n"); ++ ++ /* iOS reads the revision only to see the part answer. */ ++ ret = regmap_read(priv->regmap, MAX98925_REV_VERSION, &rev); ++ if (ret) ++ return dev_err_probe(dev, ret, "failed to read revision\n"); ++ dev_info(dev, "MAX98721 revision 0x%02x\n", rev); ++ ++ ret = regmap_multi_reg_write(priv->regmap, max98721_init, ++ ARRAY_SIZE(max98721_init)); ++ if (ret) ++ return dev_err_probe(dev, ret, "failed to initialise\n"); ++ ++ /* Start muted; the volume control never goes above iOS's gain. */ ++ regmap_update_bits(priv->regmap, MAX98925_GAIN, M98925_SPK_GAIN_MASK, 0); ++ /* Boost current limit from speaker-config byte 10 (0x50). */ ++ regmap_update_bits(priv->regmap, MAX98925_BOOST_LIMITER, ++ M98925_BST_ILIM_MASK, 0x50); ++ ++ if (i2c->irq) { ++ ret = devm_request_threaded_irq(dev, i2c->irq, NULL, ++ max98721_irq, IRQF_ONESHOT, ++ dev_name(dev), dev); ++ if (ret) ++ return dev_err_probe(dev, ret, "failed to get IRQ\n"); ++ ++ /* Thermal shutdown/warning, speaker overcurrent, slot errors. */ ++ regmap_write(priv->regmap, MAX98925_IRQ_ENABLE0, ++ M98925_THERMSHDN_BGN_EN_MASK | ++ M98925_THERMWARN_BGN_EN_MASK); ++ regmap_write(priv->regmap, MAX98925_IRQ_ENABLE1, ++ M98925_SPKCURNT_EN_MASK); ++ regmap_write(priv->regmap, MAX98925_IRQ_ENABLE2, ++ M98925_SLOTOVRN_EN_MASK | M98925_INVALSLOT_EN_MASK | ++ M98925_SLOTCNFLT_EN_MASK); ++ } ++ ++ return devm_snd_soc_register_component(dev, &max98721_component, ++ &max98721_dai, 1); ++} ++ ++static const struct i2c_device_id max98721_i2c_id[] = { ++ { "max98721" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(i2c, max98721_i2c_id); ++ ++static const struct of_device_id max98721_of_match[] = { ++ { .compatible = "maxim,max98721" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, max98721_of_match); ++ ++static struct i2c_driver max98721_i2c_driver = { ++ .driver = { ++ .name = "max98721", ++ .of_match_table = max98721_of_match, ++ }, ++ .probe = max98721_i2c_probe, ++ .id_table = max98721_i2c_id, ++}; ++module_i2c_driver(max98721_i2c_driver); ++ ++MODULE_DESCRIPTION("ASoC MAX98721 speaker amplifier driver"); ++MODULE_LICENSE("GPL"); diff --git a/kernel/patches/drivers/sound/0024-dt-bindings-mfd-syscon-Add-the-T7001-i2s-switch.patch b/kernel/patches/drivers/sound/0024-dt-bindings-mfd-syscon-Add-the-T7001-i2s-switch.patch new file mode 100644 index 00000000..a963453f --- /dev/null +++ b/kernel/patches/drivers/sound/0024-dt-bindings-mfd-syscon-Add-the-T7001-i2s-switch.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 09:16:35 +0100 +Subject: [PATCH] dt-bindings: mfd: syscon: Add the T7001 i2s-switch + +The A8X i2s-switch (Apple's i2s-switch,t7001) is the S8000 routing +block (AppleAE2I2SSwitch3) at its own address; the MCA driver programs +it as a syscon. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + Documentation/devicetree/bindings/mfd/syscon.yaml | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Documentation/devicetree/bindings/mfd/syscon.yaml b/Documentation/devicetree/bindings/mfd/syscon.yaml +index c74985051..6ce14ebaf 100644 +--- a/Documentation/devicetree/bindings/mfd/syscon.yaml ++++ b/Documentation/devicetree/bindings/mfd/syscon.yaml +@@ -47,6 +47,7 @@ properties: + - apm,xgene-rb + - apm,xgene-scu + - apple,s8000-i2s-switch ++ - apple,t7001-i2s-switch + - apple,t8010-aop-i2s-oe + - apple,t8010-aop-i2s-switch + - apple,t8010-i2s-switch +-- +2.56.0 + diff --git a/kernel/patches/drivers/sound/0025-dt-bindings-clock-apple-nco-Add-the-T7001.patch b/kernel/patches/drivers/sound/0025-dt-bindings-clock-apple-nco-Add-the-T7001.patch new file mode 100644 index 00000000..97416b6f --- /dev/null +++ b/kernel/patches/drivers/sound/0025-dt-bindings-clock-apple-nco-Add-the-T7001.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 09:14:04 +0100 +Subject: [PATCH] dt-bindings: clock: apple,nco: Add the T7001 + +The A8X NCO is the T8010 block with its channels 0x1000 apart instead +of 0x4000. Add apple,t7001-nco. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + Documentation/devicetree/bindings/clock/apple,nco.yaml | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Documentation/devicetree/bindings/clock/apple,nco.yaml b/Documentation/devicetree/bindings/clock/apple,nco.yaml +index 9a1997e62..a23660034 100644 +--- a/Documentation/devicetree/bindings/clock/apple,nco.yaml ++++ b/Documentation/devicetree/bindings/clock/apple,nco.yaml +@@ -20,6 +20,7 @@ description: | + properties: + compatible: + oneOf: ++ - const: apple,t7001-nco + - const: apple,t8010-nco + - items: + - const: apple,t6020-nco +-- +2.56.0 + diff --git a/kernel/patches/drivers/sound/0026-dt-bindings-sound-apple-s8000-mca-Allow-a-graph-port.patch b/kernel/patches/drivers/sound/0026-dt-bindings-sound-apple-s8000-mca-Allow-a-graph-port.patch new file mode 100644 index 00000000..a5e7d4e1 --- /dev/null +++ b/kernel/patches/drivers/sound/0026-dt-bindings-sound-apple-s8000-mca-Allow-a-graph-port.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 12:09:53 +0100 +Subject: [PATCH] dt-bindings: sound: apple,s8000-mca: Allow a graph port + +The iPad Air 2's speaker card is an audio-graph-card2 card (one MCA, +two amplifiers), which links to the MCA through a port. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + .../devicetree/bindings/sound/apple,s8000-mca.yaml | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +index b17cd9939..fcadf6dbc 100644 +--- a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +@@ -94,6 +94,12 @@ properties: + '#sound-dai-cells': + const: 0 + ++ port: ++ $ref: audio-graph-port.yaml# ++ unevaluatedProperties: false ++ description: ++ The link to the codecs when an audio-graph-card2 card uses this MCA. ++ + '#clock-cells': + const: 0 + +-- +2.56.0 + diff --git a/kernel/patches/drivers/sound/0027-ASoC-audio-graph-card2-Fix-the-multi-port-references.patch b/kernel/patches/drivers/sound/0027-ASoC-audio-graph-card2-Fix-the-multi-port-references.patch new file mode 100644 index 00000000..2c57014f --- /dev/null +++ b/kernel/patches/drivers/sound/0027-ASoC-audio-graph-card2-Fix-the-multi-port-references.patch @@ -0,0 +1,108 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Fri, 20 Nov 2026 16:10:01 +0100 +Subject: [PATCH] ASoC: audio-graph-card2: Fix the multi port references + +graph_get_next_multi_ep() drops the reference of the port it is given +and returns the next one. Two callers drop that reference again: + +- graph_link_init() puts port_cpu/port_codec right after handing it to + graph_get_next_multi_ep() as multi_cpu_port/multi_codec_port. +- graph_parse_node_multi() hands it the port its caller still owns + (and frees with __free), so it is put once here and once there. + +Each probe of a card with a "multi" node therefore drops the +reference count of the multi node's port@0 below zero; a card that is +probed again after -EPROBE_DEFER then warns "refcount_t: addition on 0; +use-after-free" from of_graph_get_remote_port() in graph_count_normal(). + +Drop the extra put in graph_link_init(), take a reference of our own in +graph_parse_node_multi(), and also put the endpoints the per-DAI loops +of graph_link_init() and the ports node of graph_counter() leaked. + +Seen on an iPad Air 2 (one MCA to two MAX98721 amplifiers, a +"semi-multi" link): three refcount warnings at every deferred probe of +the card; none with this change. + +Co-Authored-By: Claude Opus 5.5 +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/generic/audio-graph-card2.c | 18 +++++++++++++----- + 1 file changed, 13 insertions(+), 5 deletions(-) + +diff --git a/sound/soc/generic/audio-graph-card2.c b/sound/soc/generic/audio-graph-card2.c +index 9fb3d3df5..e683750f0 100644 +--- a/sound/soc/generic/audio-graph-card2.c ++++ b/sound/soc/generic/audio-graph-card2.c +@@ -601,6 +601,9 @@ static int graph_parse_node_multi(struct simple_util_priv *priv, + int nm_idx = 0; + int nm_max = max(dai_link->num_cpus, dai_link->num_codecs); + ++ /* graph_get_next_multi_ep() drops the port it is given: keep ours */ ++ of_node_get(port); ++ + /* + * create ch_maps if CPU:Codec = N:M + * DPCM is out of scope +@@ -651,6 +654,7 @@ static int graph_parse_node_multi(struct simple_util_priv *priv, + ret = -EINVAL; + + multi_err: ++ of_node_put(port); + return graph_ret(priv, ret); + } + +@@ -753,8 +757,8 @@ static void graph_link_init(struct simple_util_priv *priv, + + if (graph_lnk_is_multi(port_cpu)) { + multi_cpu_port = port_cpu; ++ /* this drops the reference of port_cpu */ + ep_cpu = graph_get_next_multi_ep(&multi_cpu_port, multi_cpu_port_idx++); +- of_node_put(port_cpu); + port_cpu = ep_to_port(ep_cpu); + } else { + of_node_get(ep_cpu); +@@ -763,8 +767,8 @@ static void graph_link_init(struct simple_util_priv *priv, + + if (graph_lnk_is_multi(port_codec)) { + multi_codec_port = port_codec; ++ /* this drops the reference of port_codec */ + ep_codec = graph_get_next_multi_ep(&multi_codec_port, multi_codec_port_idx++); +- of_node_put(port_codec); + port_codec = ep_to_port(ep_codec); + } else { + of_node_get(ep_codec); +@@ -806,15 +810,19 @@ static void graph_link_init(struct simple_util_priv *priv, + for_each_link_cpus(dai_link, i, dlc) { + dlc->ext_fmt = graph_parse_bitframe(ep_cpu); + +- if (multi_cpu_port) ++ if (multi_cpu_port) { ++ of_node_put(ep_cpu); + ep_cpu = graph_get_next_multi_ep(&multi_cpu_port, multi_cpu_port_idx++); ++ } + } + + for_each_link_codecs(dai_link, i, dlc) { + dlc->ext_fmt = graph_parse_bitframe(ep_codec); + +- if (multi_codec_port) ++ if (multi_codec_port) { ++ of_node_put(ep_codec); + ep_codec = graph_get_next_multi_ep(&multi_codec_port, multi_codec_port_idx++); ++ } + } + + /*** Don't use port_cpu / port_codec after here ***/ +@@ -1115,7 +1123,7 @@ static int graph_counter(struct device_node *lnk) + * ignore first lnk part + */ + if (graph_lnk_is_multi(lnk)) { +- struct device_node *ports = port_to_ports(lnk); ++ struct device_node *ports __free(device_node) = port_to_ports(lnk); + + /* + * CPU/Codec = N:M case has many endpoints. +-- +2.56.0 + diff --git a/src/orchard/apple/smartio.py b/src/orchard/apple/smartio.py index 0c4ea2b7..3b42b64e 100644 --- a/src/orchard/apple/smartio.py +++ b/src/orchard/apple/smartio.py @@ -4,7 +4,8 @@ No hardcoded offsets; select the exact kext via its prelink metadata, then map its section virtual address through the outer kernel's file-backed segments. For MH_FILESET kernels use the upstream ipsw kext extractor instead. The kext -bundle identifier is the caller's board policy (T8010 by default; S8000 for A9). +bundle identifier is the caller's board policy (T8010 by default; S8000 for A9; +T7000 for A8 and A8X). """ import argparse import hashlib @@ -15,7 +16,8 @@ T8010 = 'com.apple.driver.AppleT8010SmartIO' S8000 = 'com.apple.driver.AppleS8000SmartIO' -BUNDLES = (T8010, S8000) +T7000 = 'com.apple.driver.AppleT7000SmartIO' +BUNDLES = (T8010, S8000, T7000) def extract(blob, bundle=T8010): diff --git a/system/defaults/usr/share/alsa/ucm2/Orchard/ipad-air2/HiFi.conf b/system/defaults/usr/share/alsa/ucm2/Orchard/ipad-air2/HiFi.conf new file mode 100644 index 00000000..00c5ce3b --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/Orchard/ipad-air2/HiFi.conf @@ -0,0 +1,28 @@ +# iPad Air 2 (J81): the two bottom speakers on MCA3 through MAX98721 +# amplifiers, slot 0 left and slot 1 right. Each amplifier has its own gain +# control (0 mutes, 22 is the most the driver allows, the level iOS uses); +# the speakers play at that gain and PipeWire's software volume applies on +# top. The MCA driver bounds the output to -12 dB until there is speaker +# protection. +SectionVerb { + Value.TQ "HiFi" +} + +SectionDevice."Speaker" { + Comment "Speakers" + + EnableSequence [ + cset "name='Left Speaker Volume' 22" + cset "name='Right Speaker Volume' 22" + ] + DisableSequence [ + cset "name='Left Speaker Volume' 0" + cset "name='Right Speaker Volume' 0" + ] + + Value { + PlaybackPriority 100 + PlaybackPCM "hw:${CardId},0" + PlaybackChannels 2 + } +} diff --git a/system/defaults/usr/share/alsa/ucm2/conf.d/J81_Speakers/J81 Speakers.conf b/system/defaults/usr/share/alsa/ucm2/conf.d/J81_Speakers/J81 Speakers.conf new file mode 100644 index 00000000..64204759 --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/conf.d/J81_Speakers/J81 Speakers.conf @@ -0,0 +1,10 @@ +# iPad Air 2 (J81): the speaker card of audio-graph-card2 "J81 Speakers" +# (arch/arm64/boot/dts/apple/t7001-air2.dtsi). audio-graph-card2 sets no +# driver name, so alsa-lib finds this file by the card name (driver +# "J81_Speakers") and its long name. +Syntax 4 + +SectionUseCase."HiFi" { + Comment "Speakers" + File "/Orchard/ipad-air2/HiFi.conf" +} diff --git a/tools/catalog/drivers.json b/tools/catalog/drivers.json index cc3d6380..884e130f 100644 --- a/tools/catalog/drivers.json +++ b/tools/catalog/drivers.json @@ -314,6 +314,7 @@ "usb_serial" ], "j81": [ + "audio_output", "backlight", "battery", "bluetooth_audio", From 41b1bfa79976f68b161b081e61278b00f474e027 Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:54:07 +0800 Subject: [PATCH 3/5] j81: Bluetooth audio and input work (from #193) From ricktav's j81/bluetooth (988f955c). --- devices/j81/device.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devices/j81/device.toml b/devices/j81/device.toml index a77c719b..37622b71 100644 --- a/devices/j81/device.toml +++ b/devices/j81/device.toml @@ -42,8 +42,8 @@ touch_id = "missing" storage_read = "working" storage_write = "working" wifi = "working" -bluetooth_input = "untested" -bluetooth_audio = "untested" +bluetooth_input = "working" # Bluetooth keyboard with touchpad: typing in a terminal and moving the pointer, 2026-11-20 +bluetooth_audio = "working" # A2DP to Bose QC45 headphones from Omarchy, 2026-11-20; crackles while the CPU and memory are saturated cellular = "none" battery = "working" charging = "missing" From af930925b765196ad89efc561951984374f1e6b3 Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:54:07 +0800 Subject: [PATCH 4/5] j81: screen off, suspend and resume work (from #194) From ricktav's j81/power (2806bca8). --- devices/j81/device.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/devices/j81/device.toml b/devices/j81/device.toml index 37622b71..37ca0a41 100644 --- a/devices/j81/device.toml +++ b/devices/j81/device.toml @@ -31,7 +31,7 @@ status = "experimental" # States: working, untested, missing, none (features.toml). [features] display = "working" -screen_off = "untested" +screen_off = "working" # dark on idle and on Power, Home or Power lights it again; J81 2026-11-20 backlight = "working" touch = "working" buttons = "working" @@ -48,8 +48,8 @@ cellular = "none" battery = "working" charging = "missing" charging_control = "missing" -suspend = "untested" -resume = "untested" +suspend = "working" # s2idle from idle and from Power, cable in and out, 5 of 5 (21 s to 1 h; about 2%/h battery); J81 2026-11-20 +resume = "working" # Home or Power wakes it: display, touch, Wi-Fi, Bluetooth and USB network come back; J81 2026-11-20 usb_serial = "working" usb_network = "working" usb_host = "missing" From dd525b690a84d44826b5e6777b4f37280ed81b2a Mon Sep 17 00:00:00 2001 From: ricktav <82380971+ricktav@users.noreply.github.com> Date: Mon, 23 Nov 2026 01:54:07 +0800 Subject: [PATCH 5/5] j81: charging (from #197) The Lightning charger driver learns the iPad Air 2's D2207 PMIC, so a charging port or an Apple adapter gets up to 1.5 A instead of iBoot's 100 mA. From ricktav's j81/charging (2bbdaa32); patch files renumbered to follow main. --- devices/j81/device.toml | 4 +- ...le-t7001-air2-Add-Lightning-charging.patch | 105 ++++++ ...r-supply-apple-tristar-charger-Add-t.patch | 77 +++++ ...le_tristar_charger-Support-the-D2207.patch | 311 ++++++++++++++++++ 4 files changed, 495 insertions(+), 2 deletions(-) create mode 100644 kernel/patches/devices/t7001/0018-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch create mode 100644 kernel/patches/drivers/power/0042-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch create mode 100644 kernel/patches/drivers/power/0043-power-supply-apple_tristar_charger-Support-the-D2207.patch diff --git a/devices/j81/device.toml b/devices/j81/device.toml index 37ca0a41..33cf1220 100644 --- a/devices/j81/device.toml +++ b/devices/j81/device.toml @@ -46,8 +46,8 @@ bluetooth_input = "working" # Bluetooth keyboard with touchpad: typing in a term bluetooth_audio = "working" # A2DP to Bose QC45 headphones from Omarchy, 2026-11-20; crackles while the CPU and memory are saturated cellular = "none" battery = "working" -charging = "missing" -charging_control = "missing" +charging = "working" # Mac USB-C port (BC1.2 charging port) and Apple USB-C adapter: 1500 mA; installed Omarchy and RAM boot; J81 2026-11-21 +charging_control = "working" # source identified at each plug and after sleep, grant withdrawn on unplug; J81 2026-11-21 suspend = "working" # s2idle from idle and from Power, cable in and out, 5 of 5 (21 s to 1 h; about 2%/h battery); J81 2026-11-20 resume = "working" # Home or Power wakes it: display, touch, Wi-Fi, Bluetooth and USB network come back; J81 2026-11-20 usb_serial = "working" diff --git a/kernel/patches/devices/t7001/0018-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch b/kernel/patches/devices/t7001/0018-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch new file mode 100644 index 00000000..a0a676a4 --- /dev/null +++ b/kernel/patches/devices/t7001/0018-arm64-dts-apple-t7001-air2-Add-Lightning-charging.patch @@ -0,0 +1,105 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] arm64: dts: apple: t7001-air2: Add Lightning charging + +iBoot leaves the D2207's input-current limit at 100 mA, so the iPad Air 2 +drains on a cable. Describe the Tristar (CBTL1610) at i2c0 0x1a and the +Lightning charger on the PMIC, with the PMU line (112) and ADC done (89). +The ADT's charger node allows 0x960 = 2400 mA of input. Link the charger +to the USB device controller, which reports the host's allowance to it. + +No source events. With the plug event (0) subscribed, it stays unmasked +when the iPad is reset into DFU from a running Linux; that reset skips +iBoot, which would mask it. The cable replugs of the next boot latch it, +and that boot froze before userspace, then the watchdog reset it: 4 to 5 +times out of 5 after a charging session. Without it, 3 of 3 such resets +booted. The charger's 100 ms poll of the connection state sees plug and +unplug instead. + +On a J81 the charger identifies a Mac's USB-C port as a BC1.2 charging +port and an Apple USB-C power adapter by its 1.5 A advertisement, and +grants 1500 mA for both; the battery goes from about -0.7 A to +0.9 A. +Unplugging withdraws the grant, and the next plug identifies the source +again. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + arch/arm64/boot/dts/apple/t7001-air2.dtsi | 49 +++++++++++++++++++++++ + 1 file changed, 49 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t7001-air2.dtsi b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +index 246790a7f..d6092dcc3 100644 +--- a/arch/arm64/boot/dts/apple/t7001-air2.dtsi ++++ b/arch/arm64/boot/dts/apple/t7001-air2.dtsi +@@ -130,6 +130,12 @@ &serial0 { + &i2c0 { + status = "okay"; + ++ /* The Lightning port controller, from the ADT i2c0/tristar node. */ ++ tristar: port-controller@1a { ++ compatible = "nxp,cbtl1610"; ++ reg = <0x1a>; ++ }; ++ + pmic@3c { + compatible = "apple,arabela-pmic", "apple,i2c-pmic"; + reg = <0x3c>; +@@ -155,6 +161,37 @@ pmu_gpio: gpio { + apple,wake-events = <0x24>; + }; + ++ /* ++ * Lightning charging, at the D2207's registers as iOS 15.8 ++ * AppleD2207PMU uses them: connection and charger state at ++ * 0x60, the input-current limit at 0x4c0, the ADC at 0x500. ++ * The ADT's charger node allows 0x960 = 2400 mA of input. ++ */ ++ tristar_charger: charger@60 { ++ compatible = "apple,j81-tristar-charger", "apple,d2207-tristar-charger"; ++ reg = <0x60 0x0d>, <0x4c0 0x01>, <0x500 0x04>; ++ reg-names = "status", "control", "adc"; ++ interrupt-parent = <&pmu_gpio>; ++ /* ++ * The PMU line and ADC done. No source events: the plug ++ * event (0) stays unmasked across a reset that bypasses ++ * iBoot (DFU entered from Linux), latches on the replugs ++ * of the next boot and froze that boot. The charger's ++ * 100 ms poll of 0x60 sees plug and unplug. ++ */ ++ interrupts = <112 IRQ_TYPE_EDGE_RISING>, ++ <89 IRQ_TYPE_EDGE_RISING>; ++ apple,tristar = <&tristar>; ++ input-current-limit-microamp = <2400000>; ++ ++ /* The charger decides when USB data may come on. */ ++ port { ++ tristar_charger_usb: endpoint { ++ remote-endpoint = <&usbdev_role>; ++ }; ++ }; ++ }; ++ + rtc@5c0 { + compatible = "apple,arabela-pmic-rtc", "apple,amber-pmic-rtc"; + reg = <0x5c0 0x10>; +@@ -259,6 +296,18 @@ &touchclk { + status = "okay"; + }; + ++/* Tell the Lightning charger what the USB host allows. */ ++&usbdev { ++ usb-psy-name = "lightning"; ++ usb-role-switch; ++ ++ port { ++ usbdev_role: endpoint { ++ remote-endpoint = <&tristar_charger_usb>; ++ }; ++ }; ++}; ++ + /* + * The BCM4350C2's Bluetooth on UART3, from the ADT uart3/bluetooth node: + * power enable on D2207 GPIO 2, BT_WAKE on GPIO 164. m1n1 adds the device diff --git a/kernel/patches/drivers/power/0042-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch b/kernel/patches/drivers/power/0042-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch new file mode 100644 index 00000000..c2f2620b --- /dev/null +++ b/kernel/patches/drivers/power/0042-dt-bindings-power-supply-apple-tristar-charger-Add-t.patch @@ -0,0 +1,77 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] dt-bindings: power: supply: apple,tristar-charger: Add the + D2207 + +The iPad Air 2 charges through the same Tristar port controller, with a +D2207 PMIC instead of a D2365. The D2207 has the same charger functions +at other register addresses, so its compatible names the PMIC: +apple,d2207-tristar-charger, with apple,j81-tristar-charger for the +board. + +The source events become optional: the iPad Air 2 subscribes none (see +its device tree), and the charger's poll of the connection state notices +a change without them. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + .../power/supply/apple,tristar-charger.yaml | 23 ++++++++++++------- + 1 file changed, 15 insertions(+), 8 deletions(-) + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +index c8556e9c3..8e4acf9f7 100644 +--- a/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml ++++ b/Documentation/devicetree/bindings/power/supply/apple,tristar-charger.yaml +@@ -11,7 +11,9 @@ maintainers: + + description: | + Charging on Apple devices whose Lightning port uses a Tristar (NXP CBTL1610) +- port controller and a D2365-family PMIC, such as the iPad 5 and iPad 6. The ++ port controller and a D2365-family PMIC, such as the iPad 5 and iPad 6 (D2365) ++ and the iPad Air 2 (D2207). The PMICs have the same charger functions at ++ different register addresses, so the compatible names the PMIC. The + node is a child of the PMIC. It identifies the attached source through the + Tristar and the PMIC ADC and sets the PMIC input-current limit, which iBoot + leaves at 100 mA. PMU events come from the PMIC's event interrupt +@@ -27,11 +29,15 @@ allOf: + + properties: + compatible: +- items: +- - enum: +- - apple,j71b-tristar-charger +- - apple,j71t-tristar-charger +- - const: apple,tristar-charger ++ oneOf: ++ - items: ++ - enum: ++ - apple,j71b-tristar-charger ++ - apple,j71t-tristar-charger ++ - const: apple,tristar-charger ++ - items: ++ - const: apple,j81-tristar-charger ++ - const: apple,d2207-tristar-charger + + reg: + items: +@@ -46,7 +52,7 @@ properties: + - const: adc + + interrupts: +- minItems: 3 ++ minItems: 2 + maxItems: 16 + description: | + From the PMIC's event interrupt controller. The first is the PMU event +@@ -54,7 +60,8 @@ properties: + withdraws a grant there, before it knows which event it was. The + second is ADC conversion complete. Every further entry is an event + that can signal a change of the attached source (attach, detach, +- charger state); any of them starts a new identification. ++ charger state); any of them starts a new identification. Without ++ them, the charger's poll of the connection state notices a change. + + apple,tristar: + $ref: /schemas/types.yaml#/definitions/phandle diff --git a/kernel/patches/drivers/power/0043-power-supply-apple_tristar_charger-Support-the-D2207.patch b/kernel/patches/drivers/power/0043-power-supply-apple_tristar_charger-Support-the-D2207.patch new file mode 100644 index 00000000..e0a674d6 --- /dev/null +++ b/kernel/patches/drivers/power/0043-power-supply-apple_tristar_charger-Support-the-D2207.patch @@ -0,0 +1,311 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Sat, 21 Nov 2026 16:34:11 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: Support the D2207 + +The iPad Air 2's D2207 has the D2365's charger functions at other +addresses, as iOS 15.8's AppleD2207PMU accesses them: + + function D2365 (bank + offset) D2207 + connection state status + 0x09 0x60 + "new connection" bit bit 1 bit 3 + charger state status + 0x0a 0x62 + input-current limit control + 0x03 0x4c0 + ADC start adc + 0, value 1 0x500, 0x80 | channel 6 + ADC result adc + 1 0x502 + plug event 72 0 + +The input-limit encoding (mA = code * 12.5 + 75) and the ADC result +format are the same. After reading a D2207 conversion, iOS clears the +start bit and the latch in 0x501; do the same. + +Describe each PMIC in match data and compute the register addresses at +probe. apple,tristar-charger keeps the D2365 layout. + +Accept a node without source events: the 100 ms poll reads the +connection state and starts the identification on its own. + +Assisted-by: LLM +Co-Authored-By: Claude Opus 5.5 +--- + drivers/power/supply/apple_tristar_charger.c | 131 +++++++++++++------ + 1 file changed, 94 insertions(+), 37 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 66d169810..f2c11557c 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -1,7 +1,7 @@ + // SPDX-License-Identifier: GPL-2.0-only + /* + * Lightning charging for Apple devices with a Tristar (CBTL1610) port +- * controller and a D2365-family PMIC. ++ * controller and a D2365-family PMIC (D2365, or the iPad Air 2's D2207). + * + * iBoot leaves the PMIC input-current limit at 100 mA. On every attachment + * this driver identifies the source and grants what it advertises, up to the +@@ -57,21 +57,60 @@ + + #include "apple_tristar_accessory.h" + +-/* PMIC registers, relative to their banks */ +-#define TRISTAR_CHG_CONNECTED 0x09 /* status bank */ ++/* PMIC connection state: bit 0 is "connected" on every PMIC */ + #define TRISTAR_CHG_CONNECTED_NOW BIT(0) +-#define TRISTAR_CHG_CONNECTED_NEW BIT(1) +-#define TRISTAR_CHG_STATUS 0x0a /* status bank */ +-#define TRISTAR_CHG_INPUT_LIMIT 0x03 /* control bank */ +-#define TRISTAR_CHG_ADC_SELECT 0x00 /* ADC bank */ +-#define TRISTAR_CHG_ADC_RESULT 0x01 ++#define TRISTAR_CHG_ADC_START BIT(7) /* D2207 ADC control */ ++#define TRISTAR_CHG_ADC_LATCH GENMASK(7, 3) /* D2207 ADC control + 1 */ ++ ++/* ++ * Where a PMIC keeps the charger registers, relative to the banks the ++ * device tree gives, and how its ADC is driven. The functions are the same ++ * on both PMICs; the addresses are not. ++ */ ++struct tristar_pmic { ++ u8 connected; /* status bank: connection state */ ++ u8 connected_new; /* the bit that also marks a new connection */ ++ u8 status; /* status bank: battery charger state */ ++ u8 input_limit; /* control bank: input-current limit */ ++ u8 adc_start; /* written to the ADC bank to start a conversion */ ++ 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 */ ++}; ++ ++/* D2365 (iPad 5, iPad 6), from iOS 16 AppleD2365PMUPowerSource */ ++static const struct tristar_pmic tristar_d2365 = { ++ .connected = 0x09, ++ .connected_new = BIT(1), ++ .status = 0x0a, ++ .input_limit = 0x03, ++ .adc_start = 0x01, ++ .adc_result = 0x01, ++ .plug_event = 72, ++}; ++ ++/* ++ * D2207 (iPad Air 2), from iOS 15.8 AppleD2207PMU: connection state 0x60, ++ * charger state 0x62, input limit 0x4c0, ADC control 0x500 with the result ++ * at 0x502. A conversion starts with bit 7 and the channel, 6 for the ++ * Tristar's BrickID line; iOS clears the start bit and the latch in 0x501 ++ * after each read. The plug event is event 0. ++ */ ++static const struct tristar_pmic tristar_d2207 = { ++ .connected = 0x00, ++ .connected_new = BIT(3), ++ .status = 0x02, ++ .input_limit = 0x00, ++ .adc_start = TRISTAR_CHG_ADC_START | 6, ++ .adc_result = 0x02, ++ .adc_rearm = true, ++ .plug_event = 0, ++}; + + /* Interrupts: the PMU line, ADC completion, then the source-change events. */ + #define TRISTAR_IRQ_LINE 0 + #define TRISTAR_IRQ_ADC 1 + #define TRISTAR_IRQ_SOURCE 2 +-/* The D2365 event that latches on every plug and unplug. */ +-#define TRISTAR_EVENT_PLUG 72 + #define TRISTAR_IRQS_MAX 16 + + /* Input-current limit encoding: mA = code * 12.5 + 75 */ +@@ -136,8 +175,10 @@ struct tristar_charger { + int irqs[TRISTAR_IRQS_MAX]; + unsigned int nirqs; + int plug_irq; /* wakes the system, 0 without one */ +- u32 status_base; +- u32 control_base; ++ const struct tristar_pmic *pmic; ++ u32 connected_reg; ++ u32 status_reg; ++ u32 limit_reg; + u32 adc_base; + unsigned int max_ma; + +@@ -206,7 +247,7 @@ static unsigned int tristar_ma_code(unsigned int ma) + + static int tristar_set_code(struct tristar_charger *chg, unsigned int code) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int readback; + int ret; + +@@ -425,7 +466,7 @@ static int tristar_adc_mv(struct tristar_charger *chg, unsigned int epoch, + + reinit_completion(&chg->adc_done); + WRITE_ONCE(chg->adc_waiting, true); +- ret = regmap_write(chg->regmap, chg->adc_base + TRISTAR_CHG_ADC_SELECT, 1); ++ ret = regmap_write(chg->regmap, chg->adc_base, chg->pmic->adc_start); + if (ret) { + WRITE_ONCE(chg->adc_waiting, false); + return ret; +@@ -436,8 +477,15 @@ static int tristar_adc_mv(struct tristar_charger *chg, unsigned int epoch, + } + if (READ_ONCE(chg->epoch) != epoch) + return -ESTALE; +- ret = regmap_bulk_read(chg->regmap, chg->adc_base + TRISTAR_CHG_ADC_RESULT, ++ ret = regmap_bulk_read(chg->regmap, chg->adc_base + chg->pmic->adc_result, + value, sizeof(value)); ++ if (!ret && chg->pmic->adc_rearm) { ++ ret = regmap_update_bits(chg->regmap, chg->adc_base, ++ TRISTAR_CHG_ADC_START, 0); ++ if (!ret) ++ ret = regmap_update_bits(chg->regmap, chg->adc_base + 1, ++ TRISTAR_CHG_ADC_LATCH, 0); ++ } + if (ret) + return ret; + if (value[0] & 0x80) +@@ -958,7 +1006,7 @@ static unsigned long tristar_ramp_delay(struct tristar_charger *chg, u64 now) + */ + static void tristar_check_limit(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int hw, code = chg->code; + + if (regmap_read(chg->regmap, reg, &hw) || hw == code) +@@ -1053,7 +1101,8 @@ static void tristar_follow_accessory(struct tristar_charger *chg, u64 now) + /* + * Input presence is the D2365's connection state 0x189, as iOS 16 decides it + * (AppleD2365PMUPowerSource): bit 0 is "connected", and a new connection also +- * needs bit 1. The charger status 0x18a is not presence. Its bits describe ++ * needs bit 1. The D2207's 0x60 has the same meaning, with bit 3 for a new ++ * connection (iOS 15.8 AppleD2207PMU). The charger status 0x18a is not presence. Its bits describe + * the battery charger: the same method takes bits 1:0 as charging, bit 2 as + * charge end and bit 4 as charge timeout, for the charging and fully charged + * state only. It can also read 0 with the input still there: behind the +@@ -1063,21 +1112,20 @@ static void tristar_follow_accessory(struct tristar_charger *chg, u64 now) + * the PMIC reports input limiting, which the D2365 never does, so a charger + * that finished, timed out or does not charge keeps the grant. + * +- * Every board this driver binds has a D2365: the status, control and ADC +- * registers above are the D2365's. An unreadable 0x189 says nothing: keep +- * the last decision. ++ * The D2207's charger state 0x62 has the same bits. An unreadable connection ++ * state says nothing: keep the last decision. + */ + static bool tristar_input_present(struct tristar_charger *chg) + { + unsigned int connected; + +- if (regmap_read(chg->regmap, chg->status_base + TRISTAR_CHG_CONNECTED, &connected)) { ++ if (regmap_read(chg->regmap, chg->connected_reg, &connected)) { + dev_err_ratelimited(chg->dev, "PMIC connection state unreadable\n"); + return chg->online; + } + if (!(connected & TRISTAR_CHG_CONNECTED_NOW)) + return false; +- return chg->present || (connected & TRISTAR_CHG_CONNECTED_NEW); ++ return chg->present || (connected & chg->pmic->connected_new); + } + + static void tristar_poll(struct work_struct *work) +@@ -1096,7 +1144,7 @@ static void tristar_poll(struct work_struct *work) + old_online = chg->online; + old_present = chg->present; + old_usb_on = chg->usb_on; +- if (regmap_read(chg->regmap, chg->status_base + TRISTAR_CHG_STATUS, &status)) { ++ if (regmap_read(chg->regmap, chg->status_reg, &status)) { + tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); + dev_err_ratelimited(chg->dev, "PMIC status unreadable; holding the fallback\n"); + goto again; +@@ -1186,7 +1234,7 @@ static void tristar_poll(struct work_struct *work) + */ + static bool tristar_event_withdraw(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int readback; + + if (READ_ONCE(chg->code) <= TRISTAR_CHG_FALLBACK_CODE) +@@ -1236,7 +1284,7 @@ static bool tristar_event_debounce(struct tristar_charger *chg) + */ + static void tristar_source_event(struct tristar_charger *chg) + { +- u32 reg = chg->control_base + TRISTAR_CHG_INPUT_LIMIT; ++ u32 reg = chg->limit_reg; + unsigned int i; + u64 now; + +@@ -1473,7 +1521,7 @@ static int tristar_probe(struct platform_device *pdev) + struct tristar_charger *chg; + struct device_node *np; + unsigned int code, i; +- u32 max_ua; ++ u32 max_ua, base; + int ret; + + chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); +@@ -1484,12 +1532,20 @@ static int tristar_probe(struct platform_device *pdev) + if (!chg->regmap) + return dev_err_probe(dev, -ENODEV, "parent regmap unavailable\n"); + +- ret = tristar_get_bank(dev, "status", TRISTAR_CHG_STATUS + 1, &chg->status_base); +- if (!ret) +- ret = tristar_get_bank(dev, "control", TRISTAR_CHG_INPUT_LIMIT + 1, +- &chg->control_base); +- if (!ret) +- ret = tristar_get_bank(dev, "adc", TRISTAR_CHG_ADC_RESULT + 2, &chg->adc_base); ++ chg->pmic = device_get_match_data(dev); ++ if (!chg->pmic) ++ return -ENODEV; ++ ret = tristar_get_bank(dev, "status", ++ max(chg->pmic->connected, chg->pmic->status) + 1, &base); ++ if (ret) ++ return ret; ++ chg->connected_reg = base + chg->pmic->connected; ++ chg->status_reg = base + chg->pmic->status; ++ ret = tristar_get_bank(dev, "control", chg->pmic->input_limit + 1, &base); ++ if (ret) ++ return ret; ++ chg->limit_reg = base + chg->pmic->input_limit; ++ ret = tristar_get_bank(dev, "adc", chg->pmic->adc_result + 2, &chg->adc_base); + if (ret) + return ret; + +@@ -1524,16 +1580,16 @@ static int tristar_probe(struct platform_device *pdev) + ret = platform_irq_count(pdev); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to count the PMU event interrupts\n"); +- if (ret <= TRISTAR_IRQ_SOURCE || ret > TRISTAR_IRQS_MAX) ++ if (ret < TRISTAR_IRQ_SOURCE || ret > TRISTAR_IRQS_MAX) + return dev_err_probe(dev, -EINVAL, +- "expected PMU line, ADC and source event interrupts\n"); ++ "expected the PMU line and ADC interrupts\n"); + chg->nirqs = ret; + for (i = 0; i < chg->nirqs; i++) { + chg->irqs[i] = platform_get_irq(pdev, i); + if (chg->irqs[i] < 0) + return chg->irqs[i]; + if (i >= TRISTAR_IRQ_SOURCE && +- irqd_to_hwirq(irq_get_irq_data(chg->irqs[i])) == TRISTAR_EVENT_PLUG) ++ irqd_to_hwirq(irq_get_irq_data(chg->irqs[i])) == chg->pmic->plug_event) + chg->plug_irq = chg->irqs[i]; + } + +@@ -1551,7 +1607,7 @@ static int tristar_probe(struct platform_device *pdev) + return ret; + + /* Never adopt a limit we cannot explain; anything higher drops to the fallback. */ +- ret = regmap_read(chg->regmap, chg->control_base + TRISTAR_CHG_INPUT_LIMIT, &code); ++ ret = regmap_read(chg->regmap, chg->limit_reg, &code); + if (ret) + return dev_err_probe(dev, ret, "failed to read the input-current limit\n"); + chg->code = code; +@@ -1713,7 +1769,8 @@ static const struct dev_pm_ops tristar_pm_ops = { + }; + + static const struct of_device_id tristar_of_match[] = { +- { .compatible = "apple,tristar-charger" }, ++ { .compatible = "apple,d2207-tristar-charger", .data = &tristar_d2207 }, ++ { .compatible = "apple,tristar-charger", .data = &tristar_d2365 }, + { } + }; + MODULE_DEVICE_TABLE(of, tristar_of_match);