diff --git a/devices/n66/device.toml b/devices/n66/device.toml index 71eea464..fc9b567c 100644 --- a/devices/n66/device.toml +++ b/devices/n66/device.toml @@ -56,7 +56,7 @@ resume = "untested" usb_serial = "untested" usb_network = "untested" usb_host = "missing" # Needs the Tristar VBUS path on the iPhone's Antigua PMU; only the iPad 5's D2365 one exists -audio_output = "missing" # No Linux driver for the CS42L71 codec +audio_output = "working" # speaker only; no speaker protection (V/I sense) yet, output capped at -12 dB; CS35L21 on MCA2: 440 Hz tone heard, 60 s pink-noise soak at the caps with no OTW/OTE/AMP_SHORT (RAM boots 2026-11-23) audio_input = "missing" # No Linux driver for the CS42L71 codec camera = "missing" video_decode_hevc = "untested" # VXD on for every A9; vxd-deva.bin from the recipe diff --git a/devices/n66/firmware.json b/devices/n66/firmware.json index aa376bcf..8048a71a 100644 --- a/devices/n66/firmware.json +++ b/devices/n66/firmware.json @@ -113,6 +113,17 @@ "coprocessor": "AOP_ext" } ] + }, + { + "destination": "lib/firmware/apple/s8000-smartio.bin", + "sha256": "98242f13a7a201121f1b5029b3ba848505e1d6ca26d019fc818a77e344becc03", + "steps": [ + { + "step": "smartio-from-kernelcache@2", + "input": "kernelcache", + "kext": "com.apple.driver.AppleS8000SmartIO" + } + ] } ] } diff --git a/devices/n66m/device.toml b/devices/n66m/device.toml index 193abe5e..c555c587 100644 --- a/devices/n66m/device.toml +++ b/devices/n66m/device.toml @@ -55,7 +55,7 @@ resume = "untested" usb_serial = "untested" usb_network = "untested" usb_host = "missing" # Needs the Tristar VBUS path on the iPhone's Antigua PMU; only the iPad 5's D2365 one exists -audio_output = "missing" # No Linux driver for the CS42L71 codec +audio_output = "untested" # the N66 speaker description (shared s800x-n66.dtsi); speaker only, no speaker protection yet, capped at -12 dB audio_input = "missing" # No Linux driver for the CS42L71 codec camera = "missing" video_decode_hevc = "untested" # VXD on for every A9; vxd-deva.bin from the recipe diff --git a/docs/compatibility.md b/docs/compatibility.md index 84fc2e37..9f1309db 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -39,8 +39,8 @@ Every device Orchard installs on. ✅ works · ❌ doesn't work yet · – no su | iPad 5 (Wi-Fi) | A9, TSMC | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | [brkosebay](https://github.com/brkosebay) | | iPhone 6s | A9, Samsung | 🤔 | 🤔 | 🤔 | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | – | | iPhone 6s | A9, TSMC | 🤔 | 🤔 | 🤔 | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | – | -| iPhone 6s Plus | A9, Samsung | ✅ | 🤔 | ✅ | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | [ricktav](https://github.com/ricktav) | -| iPhone 6s Plus | A9, TSMC | 🤔 | 🤔 | 🤔 | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | – | +| iPhone 6s Plus | A9, Samsung | ✅ | 🤔 | ✅ | ❌ | ❌ | ✅ | 🤔 | 🤔 | 🤔 | [ricktav](https://github.com/ricktav) | +| iPhone 6s Plus | A9, TSMC | 🤔 | 🤔 | 🤔 | ❌ | ❌ | 🤔 | 🤔 | 🤔 | 🤔 | – | | iPhone SE | A9, Samsung | 🤔 | 🤔 | 🤔 | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | – | | iPhone SE | A9, TSMC | 🤔 | 🤔 | 🤔 | ❌ | ❌ | ❌ | 🤔 | 🤔 | 🤔 | – | | iPad 6 (Cellular) | A10 | 🤔 | 🤔 | 🤔 | 🤔 | 🤔 | 🤔 | 🤔 | 🤔 | 🤔 | – | @@ -213,12 +213,12 @@ Boards Orchard builds for. States: working, untested, missing, none (no such har | `j82` | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | untested | untested | missing | untested | missing | missing | missing | | `j71s` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | none | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | | `j72s` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | -| `n66` | working | untested | working | untested | working | working | untested | untested | working | missing | working | working | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | +| `n66` | working | untested | working | untested | working | working | untested | untested | working | missing | working | working | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | working | missing | missing | untested | | `n69u` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | | `n71` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | | `j71t` | working | working | working | working | working | working | working | working | working | missing | working | working | working | working | untested | none | working | working | working | working | working | working | working | working | working | working | missing | working | | `j72t` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | missing | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | -| `n66m` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | +| `n66m` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | untested | missing | missing | untested | | `n69` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | | `n71m` | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | missing | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | missing | missing | missing | missing | untested | | `j127` | untested | missing | untested | missing | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | @@ -270,14 +270,14 @@ A yes means an enabled device tree node binds a driver in `7.3.0-rc1-orchard-app | `j82` | experimental | yes | yes | yes | – | – | – | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | – | – | | `j71s` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | | `j72s` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | -| `n66` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | -| `n69u` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | -| `n71` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | +| `n66` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | +| `n69u` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | +| `n71` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | | `j71t` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | | `j72t` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | -| `n66m` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | -| `n69` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | -| `n71m` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | – | – | yes | +| `n66m` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | +| `n69` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | +| `n71m` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | – | – | – | yes | yes | yes | yes | – | yes | – | yes | | `j127` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | | `j128` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | | `j98a` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | @@ -321,5 +321,9 @@ A yes means an enabled device tree node binds a driver in `7.3.0-rc1-orchard-app | `n53` | Speakers | missing, but a driver binds | | `j71s` | Microphone | untested, but no driver binds | | `j72s` | Microphone | untested, but no driver binds | +| `n69u` | Speakers | missing, but a driver binds | +| `n71` | Speakers | missing, but a driver binds | | `j71t` | Microphone | working, but no driver binds | | `j72t` | Microphone | untested, but no driver binds | +| `n69` | Speakers | missing, but a driver binds | +| `n71m` | Speakers | missing, but a driver binds | diff --git a/kernel/configs/apple-16k/config b/kernel/configs/apple-16k/config index fdef34a3..6aa89902 100644 --- a/kernel/configs/apple-16k/config +++ b/kernel/configs/apple-16k/config @@ -4570,6 +4570,7 @@ CONFIG_SND_SOC_I2C_AND_SPI=m # CONFIG_SND_SOC_BT_SCO is not set # CONFIG_SND_SOC_CHV3_CODEC is not set # CONFIG_SND_SOC_CS35L32 is not set +CONFIG_SND_SOC_CS35L19=m # CONFIG_SND_SOC_CS35L33 is not set # CONFIG_SND_SOC_CS35L34 is not set # CONFIG_SND_SOC_CS35L35 is not set diff --git a/kernel/patches/devices/t8010/0042-arm64-dts-apple-s800-0-3-Add-the-NCO-and-MCA2.patch b/kernel/patches/devices/t8010/0042-arm64-dts-apple-s800-0-3-Add-the-NCO-and-MCA2.patch new file mode 100644 index 00000000..5e000c76 --- /dev/null +++ b/kernel/patches/devices/t8010/0042-arm64-dts-apple-s800-0-3-Add-the-NCO-and-MCA2.patch @@ -0,0 +1,124 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:39:57 +0100 +Subject: [PATCH] arm64: dts: apple: s800-0-3: Add the NCO and MCA2 + +Describe the NCO (ADT /arm-io/nco, nco,s8000: the T8010 block at the +same address, five channels 0x4000 apart) with its 800 MHz reference +(the n66 ADT's clock-frequencies entry for clock-id 269), and MCA2, the +iPhones' speaker TDM link on pad 2: SmartIO endpoint 0x2c, MCLK control +word 0x20a002008, AIC 203, bitclock from NCO channel 2. + +The NCO, MCA2, SmartIO and I2C1 are SoC blocks every S8000 and S8003 +has, so they are enabled here; boards add only their wiring (the +i2s-switch route and what sits on the bus). The iPad 5's SmartIO +override is no longer needed. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/s800-0-3.dtsi | 47 +++++++++++++++++++++- + arch/arm64/boot/dts/apple/s800x-ipad5.dtsi | 4 -- + 2 files changed, 45 insertions(+), 6 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/s800-0-3.dtsi b/arch/arm64/boot/dts/apple/s800-0-3.dtsi +index 29f9d1dc3..646ea1f3d 100644 +--- a/arch/arm64/boot/dts/apple/s800-0-3.dtsi ++++ b/arch/arm64/boot/dts/apple/s800-0-3.dtsi +@@ -50,6 +50,18 @@ spi3_nclk: clock-spi3-nclk { + clock-output-names = "spi3-nclk"; + }; + ++ /* ++ * The NCO's reference: the ADT's clock-frequencies entry for the ++ * NCO's first clock-id (269), 800 MHz on the n66. A board whose ADT ++ * says otherwise overrides it. ++ */ ++ nco_clkref: clock-ref-nco { ++ compatible = "fixed-clock"; ++ #clock-cells = <0>; ++ clock-frequency = <800000000>; ++ clock-output-names = "nco_ref"; ++ }; ++ + cpus { + #address-cells = <2>; + #size-cells = <0>; +@@ -260,6 +272,28 @@ mca0: mca@20a0a0000 { + status = "disabled"; + }; + ++ /* ++ * ADT /arm-io/mca2: the speaker TDM link of the iPhones (pad 2), ++ * SmartIO endpoint 0x2c, bitclock from NCO 2. ++ */ ++ mca2: mca@20a0a8000 { ++ compatible = "apple,s8000-mca-tdm"; ++ reg = <0x2 0x0a0a8000 0x0 0x4000>, ++ <0x2 0x0a002008 0x0 0x4>; ++ reg-names = "mca", "mclk"; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ power-domains = <&ps_mca2>; ++ clocks = <&nco 2>; ++ clock-names = "bitclk"; ++ dmas = <&sio 0x2c>; ++ dma-names = "tx"; ++ #clock-cells = <0>; ++ clock-output-names = "mca2-mclk"; ++ #sound-dai-cells = <0>; ++ status = "okay"; ++ }; ++ + serial0: serial@20a0c0000 { + compatible = "apple,s5l-uart"; + reg = <0x2 0x0a0c0000 0x0 0x4000>; +@@ -335,7 +369,7 @@ i2c1: i2c@20a111000 { + power-domains = <&ps_i2c1>; + #address-cells = <1>; + #size-cells = <0>; +- status = "disabled"; ++ status = "okay"; + }; + + i2c2: i2c@20a112000 { +@@ -368,7 +402,7 @@ sio: dma-controller@20ae00000 { + firmware-name = "apple/s8000-smartio.bin"; + dma-channels = <64>; + #dma-cells = <1>; +- status = "disabled"; ++ status = "okay"; + }; + + bus@20c000000 { +@@ -468,6 +502,15 @@ touchclk: clock-controller@78000 { + }; + }; + ++ /* ADT /arm-io/nco: nco,s8000, five channels 0x4000 apart */ ++ nco: clock-controller@20e044000 { ++ compatible = "apple,s8000-nco", "apple,t8010-nco"; ++ reg = <0x2 0x0e044000 0x0 0x14000>; ++ clocks = <&nco_clkref>; ++ #clock-cells = <1>; ++ status = "okay"; ++ }; ++ + pmgr_misc: power-management@20e068000 { + compatible = "apple,s8000-pmgr-misc"; + reg = <0x2 0x0e068000 0x0 0x4>; +diff --git a/arch/arm64/boot/dts/apple/s800x-ipad5.dtsi b/arch/arm64/boot/dts/apple/s800x-ipad5.dtsi +index dfd1b2d42..376c15bd1 100644 +--- a/arch/arm64/boot/dts/apple/s800x-ipad5.dtsi ++++ b/arch/arm64/boot/dts/apple/s800x-ipad5.dtsi +@@ -324,10 +324,6 @@ battery: fuel-gauge { + }; + }; + +-&sio { +- status = "okay"; +-}; +- + &spi1 { + /* ADT function-spi_cs0 */ + cs-gpios = <&pinctrl_ap 16 GPIO_ACTIVE_LOW>; diff --git a/kernel/patches/devices/t8010/0043-arm64-dts-apple-n66-Add-the-loudspeaker.patch b/kernel/patches/devices/t8010/0043-arm64-dts-apple-n66-Add-the-loudspeaker.patch new file mode 100644 index 00000000..b137f88f --- /dev/null +++ b/kernel/patches/devices/t8010/0043-arm64-dts-apple-n66-Add-the-loudspeaker.patch @@ -0,0 +1,87 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:40:11 +0100 +Subject: [PATCH] arm64: dts: apple: n66: Add the loudspeaker + +The iPhone 6s Plus loudspeaker is a CS35L19 at i2c1 0x40 (ADT +audio-control,cs35l19, reset AP GPIO 70) on the TDM link of pad 2, fed +by MCA2: 8 slots of 16 bits, the speaker in slot 1. Route aud2 to pin2, +describe the amplifier with the 6s Plus's speaker-config and tie both +together in a simple-audio-card, in the file the Samsung (N66) and TSMC +(N66m) models share. + +iOS clocks this link from the CS42L71 codec's ASP; without a CS42L71 +driver, MCA2 provides the clocks and the codec is left untouched. The +Taptic Engine's CS35L19 (0x41) is not described. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + arch/arm64/boot/dts/apple/s800x-n66.dtsi | 54 ++++++++++++++++++++++++ + 1 file changed, 54 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/s800x-n66.dtsi b/arch/arm64/boot/dts/apple/s800x-n66.dtsi +index 34fc1191c..08a9f59ac 100644 +--- a/arch/arm64/boot/dts/apple/s800x-n66.dtsi ++++ b/arch/arm64/boot/dts/apple/s800x-n66.dtsi +@@ -18,6 +18,60 @@ &touchscreen { + touchscreen-size-y = <1920>; + }; + ++/ { ++ /* ++ * The loudspeaker: MCA2 to the CS35L19 at i2c1 0x40 on the TDM link of ++ * pad 2, speaker in slot 1 of 8 x 16 bit (ADT mca2/audio-speaker). iOS ++ * clocks this link from the CS42L71 codec, which has no driver yet; ++ * here MCA2 provides the clocks and the codec's port stays untouched. ++ */ ++ sound-speaker { ++ compatible = "simple-audio-card"; ++ simple-audio-card,name = "iPhone Speaker"; ++ simple-audio-card,format = "dsp_a"; ++ simple-audio-card,bitclock-master = <&speaker_cpu>; ++ simple-audio-card,frame-master = <&speaker_cpu>; ++ simple-audio-card,widgets = "Speaker", "Speaker"; ++ simple-audio-card,routing = "Speaker", "SPK"; ++ ++ speaker_cpu: simple-audio-card,cpu { ++ sound-dai = <&mca2>; ++ }; ++ ++ simple-audio-card,codec { ++ sound-dai = <&speaker_amp>; ++ dai-tdm-slot-num = <8>; ++ dai-tdm-slot-width = <16>; ++ dai-tdm-slot-rx-mask = <0 1 0 0 0 0 0 0>; ++ }; ++ }; ++}; ++ ++/* ADT mca2 function-i2s_route: aud2 -> pin2 */ ++&mca2 { ++ apple,i2s-switch = <&i2s_switch 2 2>; ++}; ++ ++&i2c1 { ++ /* ++ * ADT i2c1/audio-speaker: audio-control,cs35l19 @0x40, reset AP GPIO ++ * 70 (0x46), interrupt AP GPIO 68 (unused). speaker-config is the ++ * 6s Plus's 20-byte blob (N66 ADT). The Taptic Engine's CS35L19 (@0x41, ++ * reset 116) is left alone. ++ */ ++ speaker_amp: amplifier@40 { ++ compatible = "cirrus,cs35l19"; ++ reg = <0x40>; ++ reset-gpios = <&pinctrl_ap 70 GPIO_ACTIVE_LOW>; ++ clocks = <&mca2>; ++ clock-names = "mclk"; ++ apple,speaker-config = /bits/ 8 <0xaa 0x30 0x02 0x70 0x6a 0x80 0x30 ++ 0x1e 0x02 0x04 0x14 0x89 0x8c 0x10 ++ 0x73 0x03 0x05 0xd0 0x04 0x40>; ++ #sound-dai-cells = <0>; ++ }; ++}; ++ + /* ADT charger charge-limits[0] */ + &battery_info { + constant-charge-current-max-microamp = <1924000>; diff --git a/kernel/patches/drivers/sound/0031-ASoC-codecs-Add-the-Cirrus-Logic-CS35L19-speaker-amp.patch b/kernel/patches/drivers/sound/0031-ASoC-codecs-Add-the-Cirrus-Logic-CS35L19-speaker-amp.patch new file mode 100644 index 00000000..8392e9aa --- /dev/null +++ b/kernel/patches/drivers/sound/0031-ASoC-codecs-Add-the-Cirrus-Logic-CS35L19-speaker-amp.patch @@ -0,0 +1,478 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: rzxvx +Date: Fri, 16 Oct 2026 18:07:30 +0300 +Subject: [PATCH] ASoC: codecs: Add the Cirrus Logic CS35L19 speaker amplifier + +The CS35L19 is an Apple-specific sibling of the CS35L33 with the same +register map. This driver runs iOS's AppleCS35L19Amp power-on sequence: +MCLK on before the amplifier leaves power-down, the Apple trim writes +behind the 0x99 test key, the boost and amplifier settings from the +board's speaker-config, and a TDM receiver with the sense outputs off. + +Taken unchanged from Project Cascadia (rzxvx, devices/a5 at 091d441), +where it drives the iPad mini 1 speakers; Orchard carries it for the +apple-armv7 platform as kernel/patches/import/cascadia/0018. The A9 +iPhone 6s and 6s Plus use the same amplifier. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/Kconfig | 8 + + sound/soc/codecs/Makefile | 2 + + sound/soc/codecs/cs35l19.c | 408 +++++++++++++++++++++++++++++++++++++ + 3 files changed, 418 insertions(+) + create mode 100644 sound/soc/codecs/cs35l19.c + +diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig +index 2e909a86e..018c37ff6 100644 +--- a/sound/soc/codecs/Kconfig ++++ b/sound/soc/codecs/Kconfig +@@ -804,6 +804,14 @@ config SND_SOC_CS35L32 + tristate "Cirrus Logic CS35L32 CODEC" + depends on I2C + ++config SND_SOC_CS35L19 ++ tristate "Cirrus Logic CS35L19 speaker amplifier" ++ depends on I2C ++ select REGMAP_I2C ++ help ++ The boosted class-D speaker amplifier of the iPad mini 1, a ++ sibling of the CS35L33, with Apple's power-on sequence. ++ + config SND_SOC_CS35L33 + tristate "Cirrus Logic CS35L33 CODEC" + depends on I2C +diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile +index a90619a7e..d4ca25792 100644 +--- a/sound/soc/codecs/Makefile ++++ b/sound/soc/codecs/Makefile +@@ -65,6 +65,7 @@ snd-soc-cros-ec-codec-y := cros_ec_codec.o + snd-soc-cs-amp-lib-y := cs-amp-lib.o + snd-soc-cs-amp-lib-test-y := cs-amp-lib-test.o + snd-soc-cs35l32-y := cs35l32.o ++snd-soc-cs35l19-y := cs35l19.o + snd-soc-cs35l33-y := cs35l33.o + snd-soc-cs35l34-y := cs35l34.o + snd-soc-cs35l35-y := cs35l35.o +@@ -511,6 +512,7 @@ obj-$(CONFIG_SND_SOC_CROS_EC_CODEC) += snd-soc-cros-ec-codec.o + obj-$(CONFIG_SND_SOC_CS_AMP_LIB) += snd-soc-cs-amp-lib.o + obj-$(CONFIG_SND_SOC_CS_AMP_LIB_TEST) += snd-soc-cs-amp-lib-test.o + obj-$(CONFIG_SND_SOC_CS35L32) += snd-soc-cs35l32.o ++obj-$(CONFIG_SND_SOC_CS35L19) += snd-soc-cs35l19.o + obj-$(CONFIG_SND_SOC_CS35L33) += snd-soc-cs35l33.o + obj-$(CONFIG_SND_SOC_CS35L34) += snd-soc-cs35l34.o + obj-$(CONFIG_SND_SOC_CS35L35) += snd-soc-cs35l35.o +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +new file mode 100644 +index 000000000..af83a78bc +--- /dev/null ++++ b/sound/soc/codecs/cs35l19.c +@@ -0,0 +1,408 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* ++ * Cirrus Logic CS35L19 boosted class-D speaker amplifier (iPad mini 1). ++ * ++ * The CS35L19 is the CS35L33's sibling -- the register map matches it reset ++ * value for reset value -- with Apple's power-on sequence, which is what this ++ * driver runs, taken from iOS 8.4.1's AppleCS35L19Amp (12H321, text ++ * 0x80af4de0; docs/research/p105-audio.md): ++ * ++ * - the amp needs MCLK (12.000 MHz) before it leaves power-down: without it ++ * INT_STATUS_2 keeps PDN_DONE whatever else is right; ++ * - it watches a KEEPALIVE input and stops when nobody toggles it; iOS ++ * flips the pin every 20 ms, and so does this driver; ++ * - its serial port is a TDM receiver: the audio slot's byte offset and ++ * depth go in RX_AUD (0x36), the sense outputs (0x2d..0x35) stay off. ++ * ++ * Both amps of the iPad share one reset line and one keep-alive line; the ++ * reset is requested non-exclusively, and only the node that carries the ++ * keep-alive GPIO toggles it. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define CS35L19_DEVID_AB 0x01 ++#define CS35L19_REV_ID 0x05 ++#define CS35L19_PWRCTL1 0x06 ++#define CS35L19_PWRCTL2 0x07 ++#define CS35L19_CLK_CTL 0x08 ++#define CS35L19_BST_PEAK 0x09 ++#define CS35L19_BST_CTL1 0x0b ++#define CS35L19_BST_CTL2 0x0c ++#define CS35L19_ADSP_CTL 0x0d ++#define CS35L19_ADC_CTL 0x0e ++#define CS35L19_DAC_CTL 0x0f ++#define CS35L19_DIG_VOL 0x10 ++#define CS35L19_CLASSD_CTL 0x11 ++#define CS35L19_AMP_CTL 0x12 ++#define CS35L19_INT_STATUS_1 0x15 ++#define CS35L19_INT_STATUS_2 0x16 ++#define CS35L19_TX_VMON 0x2d /* .. 0x31: V, I, VP, VBST, FLAG */ ++#define CS35L19_TX_EN1 0x32 /* .. 0x35 */ ++#define CS35L19_RX_AUD 0x36 ++#define CS35L19_RX_SPLY 0x37 ++#define CS35L19_RX_ALIVE 0x38 ++#define CS35L19_MAX_REG 0x7f ++ ++#define CS35L19_VOL_MUTE 0x19 /* what iOS writes to mute */ ++#define CS35L19_CFG_LEN 20 ++ ++/* The ADT's speaker-config for P105AP, the same for both amps. */ ++static const u8 cs35l19_default_cfg[CS35L19_CFG_LEN] = { ++ 0xff, 0x26, 0x02, 0x70, 0x6a, 0x80, 0x30, 0x1e, 0x02, 0x04, ++ 0x0c, 0x8a, 0x8a, 0x10, 0x74, 0x03, 0x05, 0x00, 0x00, 0x00, ++}; ++ ++struct cs35l19 { ++ struct device *dev; ++ struct regmap *regmap; ++ struct clk *mclk; ++ struct gpio_desc *reset; ++ struct gpio_desc *keepalive; ++ struct delayed_work alive_work; ++ bool alive_level; ++ u8 cfg[CS35L19_CFG_LEN]; ++ unsigned int rev; ++ unsigned int rate_code; ++ unsigned int slot; /* TDM slot index (slots are 32 bits) */ ++}; ++ ++static void cs35l19_alive(struct work_struct *work) ++{ ++ struct cs35l19 *cs = container_of(to_delayed_work(work), struct cs35l19, ++ alive_work); ++ ++ cs->alive_level = !cs->alive_level; ++ gpiod_set_value_cansleep(cs->keepalive, cs->alive_level); ++ schedule_delayed_work(&cs->alive_work, msecs_to_jiffies(20)); ++} ++ ++static void cs35l19_alive_start(struct cs35l19 *cs) ++{ ++ if (cs->keepalive) ++ schedule_delayed_work(&cs->alive_work, 0); ++} ++ ++static void cs35l19_alive_stop(struct cs35l19 *cs) ++{ ++ if (cs->keepalive) ++ cancel_delayed_work_sync(&cs->alive_work); ++} ++ ++/* AppleCS35L19Amp's power-on (0x80af55d4) and serial port (0x80af5be0). */ ++static int cs35l19_power_on(struct cs35l19 *cs) ++{ ++ struct regmap *map = cs->regmap; ++ const u8 *cfg = cs->cfg; ++ unsigned int vol, st1, st2, i; ++ int ret; ++ ++ ret = regmap_read(map, CS35L19_DIG_VOL, &vol); ++ if (ret) ++ return ret; ++ ++ if (cs->rev >= 0xb0) { ++ regmap_write(map, 0x00, 0x99); ++ regmap_write(map, 0x45, 0x3f); ++ regmap_write(map, 0x46, cfg[16]); ++ regmap_write(map, 0x51, 0xff); ++ regmap_write(map, 0x59, 0x0a); ++ regmap_write(map, 0x6b, 0x20); ++ if (cfg[18]) ++ regmap_write(map, 0x54, cfg[18]); ++ regmap_write(map, 0x00, 0x00); ++ } ++ if (cfg[17]) { ++ regmap_write(map, 0x00, 0x99); ++ regmap_write(map, 0x66, cfg[17]); ++ regmap_write(map, 0x00, 0x00); ++ } ++ regmap_write(map, CS35L19_BST_CTL1, cfg[1] & 0x3f); ++ regmap_update_bits(map, CS35L19_BST_CTL2, 0x03, cfg[2] & 0x03); ++ ++ regmap_write(map, CS35L19_PWRCTL1, 0x80); /* all on but the amp */ ++ regmap_write(map, CS35L19_PWRCTL2, 0xf8); /* no V/I/VP/VBST sense, TDM */ ++ regmap_update_bits(map, CS35L19_CLK_CTL, 0xc0, 0x40); /* MCLK / 2 */ ++ regmap_write(map, CS35L19_BST_PEAK, cfg[0]); ++ regmap_write(map, CS35L19_DIG_VOL, CS35L19_VOL_MUTE); ++ regmap_update_bits(map, CS35L19_DAC_CTL, 0x10, 0); ++ regmap_write(map, CS35L19_CLASSD_CTL, 0x1c); /* calibrate */ ++ regmap_update_bits(map, CS35L19_ADC_CTL, 0xcf, 0xc4); ++ regmap_update_bits(map, CS35L19_AMP_CTL, 0xf0, cfg[3] & 0xf0); ++ for (i = 0; i < 4; i++) ++ regmap_write(map, 0x3a + i, cfg[12 + i]); ++ usleep_range(10000, 11000); ++ regmap_write(map, CS35L19_PWRCTL1, 0x00); ++ usleep_range(8000, 9000); ++ ++ regmap_read(map, CS35L19_INT_STATUS_1, &st1); ++ regmap_read(map, CS35L19_INT_STATUS_1, &st1); ++ regmap_read(map, CS35L19_INT_STATUS_2, &st2); ++ regmap_read(map, CS35L19_INT_STATUS_2, &st2); ++ if (st2 & 0x01) ++ dev_warn(cs->dev, "still powered down after power-up (status %02x %02x): no MCLK?\n", ++ st1, st2); ++ ++ for (i = 0; i < 8; i++) ++ regmap_write(map, 0x23 + i, cfg[4 + i]); ++ regmap_update_bits(map, 0x29, 0x7f, 0x14); ++ regmap_write(map, CS35L19_CLASSD_CTL, 0x14); /* calibration done */ ++ ++ /* the serial port: the audio slot only, nothing sent back */ ++ for (i = 0; i < 5; i++) ++ regmap_write(map, CS35L19_TX_VMON + i, 0x80); ++ for (i = 0; i < 4; i++) ++ regmap_write(map, CS35L19_TX_EN1 + i, 0); ++ regmap_write(map, CS35L19_ADSP_CTL, 3); ++ regmap_write(map, CS35L19_CLK_CTL, cs->rate_code); ++ regmap_write(map, CS35L19_RX_AUD, (cs->slot * 4) | (3 << 5)); ++ regmap_write(map, CS35L19_RX_SPLY, 0x80); ++ regmap_write(map, CS35L19_RX_ALIVE, 0x80); ++ ++ return regmap_write(map, CS35L19_DIG_VOL, vol); ++} ++ ++static void cs35l19_power_off(struct cs35l19 *cs) ++{ ++ struct regmap *map = cs->regmap; ++ unsigned int vol; ++ ++ if (regmap_read(map, CS35L19_DIG_VOL, &vol)) ++ return; ++ regmap_write(map, CS35L19_DIG_VOL, CS35L19_VOL_MUTE); ++ regmap_update_bits(map, CS35L19_PWRCTL1, 0x80, 0x80); ++ regmap_write(map, CS35L19_PWRCTL2, 0xfe); ++ usleep_range(1000, 2000); ++ regmap_write(map, CS35L19_PWRCTL1, 0x87); ++ usleep_range(4000, 5000); ++ regmap_write(map, CS35L19_DIG_VOL, vol); ++} ++ ++static int cs35l19_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 cs35l19 *cs = snd_soc_component_get_drvdata(component); ++ int ret; ++ ++ switch (event) { ++ case SND_SOC_DAPM_PRE_PMU: ++ /* ++ * Looked up here, not at probe: MCLK's provider is the sound ++ * card's own driver, which waits for this one to probe. ++ */ ++ if (!cs->mclk) { ++ struct clk *mclk = devm_clk_get(cs->dev, "mclk"); ++ ++ if (IS_ERR(mclk)) ++ return dev_err_probe(cs->dev, PTR_ERR(mclk), "no MCLK\n"); ++ cs->mclk = mclk; ++ } ++ ret = clk_prepare_enable(cs->mclk); ++ if (ret) ++ return ret; ++ cs35l19_alive_start(cs); ++ ret = cs35l19_power_on(cs); ++ if (ret) { ++ cs35l19_alive_stop(cs); ++ clk_disable_unprepare(cs->mclk); ++ } ++ return ret; ++ case SND_SOC_DAPM_POST_PMD: ++ cs35l19_power_off(cs); ++ cs35l19_alive_stop(cs); ++ clk_disable_unprepare(cs->mclk); ++ return 0; ++ } ++ return 0; ++} ++ ++/* 0.5 dB steps around 0 dB: 0x34 is -102 dB, 0x00 0 dB, 0x18 +12 dB */ ++static const DECLARE_TLV_DB_SCALE(cs35l19_vol_tlv, -10200, 50, 0); ++ ++static const struct snd_kcontrol_new cs35l19_controls[] = { ++ SOC_SINGLE_SX_TLV("Speaker Volume", CS35L19_DIG_VOL, 0, 0x34, 0xe4, ++ cs35l19_vol_tlv), ++}; ++ ++static const struct snd_soc_dapm_widget cs35l19_widgets[] = { ++ SND_SOC_DAPM_AIF_IN("SDIN", "Playback", 0, SND_SOC_NOPM, 0, 0), ++ SND_SOC_DAPM_OUT_DRV_E("AMP", SND_SOC_NOPM, 0, 0, NULL, 0, ++ cs35l19_amp_event, ++ SND_SOC_DAPM_PRE_PMU | SND_SOC_DAPM_POST_PMD), ++ SND_SOC_DAPM_OUTPUT("SPK"), ++}; ++ ++static const struct snd_soc_dapm_route cs35l19_routes[] = { ++ { "AMP", NULL, "SDIN" }, ++ { "SPK", NULL, "AMP" }, ++}; ++ ++static int cs35l19_hw_params(struct snd_pcm_substream *substream, ++ struct snd_pcm_hw_params *params, ++ struct snd_soc_dai *dai) ++{ ++ struct cs35l19 *cs = snd_soc_component_get_drvdata(dai->component); ++ ++ /* the rate codes iOS writes to CLK_CTL, with MCLK = 12 MHz */ ++ switch (params_rate(params)) { ++ case 48000: ++ cs->rate_code = 0x49; ++ break; ++ case 44100: ++ cs->rate_code = 0x4b; ++ break; ++ case 32000: ++ cs->rate_code = 0x4d; ++ break; ++ default: ++ return -EINVAL; ++ } ++ return 0; ++} ++ ++static int cs35l19_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, ++ unsigned int rx_mask, int slots, int slot_width) ++{ ++ struct cs35l19 *cs = snd_soc_component_get_drvdata(dai->component); ++ ++ if (slot_width != 32 || !rx_mask) ++ return -EINVAL; ++ cs->slot = __ffs(rx_mask); ++ return 0; ++} ++ ++static const struct snd_soc_dai_ops cs35l19_dai_ops = { ++ .hw_params = cs35l19_hw_params, ++ .set_tdm_slot = cs35l19_set_tdm_slot, ++}; ++ ++static struct snd_soc_dai_driver cs35l19_dai = { ++ .name = "cs35l19", ++ .playback = { ++ .stream_name = "Playback", ++ .channels_min = 1, ++ .channels_max = 2, ++ .rates = SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | ++ SNDRV_PCM_RATE_48000, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE, ++ }, ++ .ops = &cs35l19_dai_ops, ++}; ++ ++static const struct snd_soc_component_driver cs35l19_component = { ++ .controls = cs35l19_controls, ++ .num_controls = ARRAY_SIZE(cs35l19_controls), ++ .dapm_widgets = cs35l19_widgets, ++ .num_dapm_widgets = ARRAY_SIZE(cs35l19_widgets), ++ .dapm_routes = cs35l19_routes, ++ .num_dapm_routes = ARRAY_SIZE(cs35l19_routes), ++ .use_pmdown_time = 1, ++ .endianness = 1, ++}; ++ ++static const struct regmap_config cs35l19_regmap = { ++ .reg_bits = 8, ++ .val_bits = 8, ++ .max_register = CS35L19_MAX_REG, ++ .cache_type = REGCACHE_NONE, ++ /* the amp does not step the register address within a transfer */ ++ .use_single_read = true, ++ .use_single_write = true, ++}; ++ ++static int cs35l19_i2c_probe(struct i2c_client *client) ++{ ++ struct device *dev = &client->dev; ++ struct cs35l19 *cs; ++ u8 id[3]; ++ int ret, n; ++ ++ cs = devm_kzalloc(dev, sizeof(*cs), GFP_KERNEL); ++ if (!cs) ++ return -ENOMEM; ++ cs->dev = dev; ++ cs->rate_code = 0x49; ++ cs->slot = client->addr & 1; ++ INIT_DELAYED_WORK(&cs->alive_work, cs35l19_alive); ++ i2c_set_clientdata(client, cs); ++ ++ cs->regmap = devm_regmap_init_i2c(client, &cs35l19_regmap); ++ if (IS_ERR(cs->regmap)) ++ return PTR_ERR(cs->regmap); ++ ++ /* shared by both amps: out of reset, and left there */ ++ cs->reset = devm_gpiod_get_optional(dev, "reset", ++ GPIOD_OUT_LOW | GPIOD_FLAGS_BIT_NONEXCLUSIVE); ++ if (IS_ERR(cs->reset)) ++ return dev_err_probe(dev, PTR_ERR(cs->reset), "reset GPIO\n"); ++ cs->keepalive = devm_gpiod_get_optional(dev, "cirrus,keepalive", ++ GPIOD_OUT_LOW); ++ if (IS_ERR(cs->keepalive)) ++ return dev_err_probe(dev, PTR_ERR(cs->keepalive), "keep-alive GPIO\n"); ++ if (cs->reset) ++ usleep_range(2000, 3000); ++ ++ memcpy(cs->cfg, cs35l19_default_cfg, sizeof(cs->cfg)); ++ n = of_property_count_u8_elems(dev->of_node, "apple,speaker-config"); ++ if (n == CS35L19_CFG_LEN) ++ of_property_read_u8_array(dev->of_node, "apple,speaker-config", ++ cs->cfg, CS35L19_CFG_LEN); ++ ++ ret = regmap_bulk_read(cs->regmap, CS35L19_DEVID_AB, id, 3); ++ if (ret) ++ return dev_err_probe(dev, ret, "no answer\n"); ++ if (id[0] != 0x35 || id[1] != 0xa1 || (id[2] & 0xf0) != 0x90) ++ return dev_err_probe(dev, -ENODEV, "device ID %02x%02x%02x, not a CS35L19\n", ++ id[0], id[1], id[2]); ++ ret = regmap_read(cs->regmap, CS35L19_REV_ID, &cs->rev); ++ if (ret) ++ return ret; ++ dev_info(dev, "CS35L19 revision %02x\n", cs->rev); ++ ++ return devm_snd_soc_register_component(dev, &cs35l19_component, ++ &cs35l19_dai, 1); ++} ++ ++static void cs35l19_i2c_remove(struct i2c_client *client) ++{ ++ struct cs35l19 *cs = i2c_get_clientdata(client); ++ ++ cancel_delayed_work_sync(&cs->alive_work); ++} ++ ++static const struct of_device_id cs35l19_of_match[] = { ++ { .compatible = "cirrus,cs35l19" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, cs35l19_of_match); ++ ++static const struct i2c_device_id cs35l19_id[] = { ++ { "cs35l19" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(i2c, cs35l19_id); ++ ++static struct i2c_driver cs35l19_i2c_driver = { ++ .driver = { ++ .name = "cs35l19", ++ .of_match_table = cs35l19_of_match, ++ }, ++ .id_table = cs35l19_id, ++ .probe = cs35l19_i2c_probe, ++ .remove = cs35l19_i2c_remove, ++}; ++module_i2c_driver(cs35l19_i2c_driver); ++ ++MODULE_DESCRIPTION("Cirrus Logic CS35L19 speaker amplifier (iPad mini 1)"); ++MODULE_LICENSE("GPL"); diff --git a/kernel/patches/drivers/sound/0032-ASoC-cs35l19-Accept-16-bit-TDM-slots.patch b/kernel/patches/drivers/sound/0032-ASoC-cs35l19-Accept-16-bit-TDM-slots.patch new file mode 100644 index 00000000..cce1da29 --- /dev/null +++ b/kernel/patches/drivers/sound/0032-ASoC-cs35l19-Accept-16-bit-TDM-slots.patch @@ -0,0 +1,64 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:37:56 +0100 +Subject: [PATCH] ASoC: cs35l19: Accept 16-bit TDM slots + +The iPhone 6s Plus runs its speaker amplifier on an 8 x 16-bit TDM link. +Take the slot width from set_tdm_slot and program RX_AUD the way iOS +15's AppleCS35L19Amp does: the slot's byte offset in bits 4:0 and the +slot width in bytes minus one in bits 6:5 (0x60 for the 32-bit slots +used so far, 0x20 for 16-bit slots). + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/cs35l19.c | 13 ++++++++++--- + 1 file changed, 10 insertions(+), 3 deletions(-) + +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +index af83a78bc..3f05be281 100644 +--- a/sound/soc/codecs/cs35l19.c ++++ b/sound/soc/codecs/cs35l19.c +@@ -74,7 +74,8 @@ struct cs35l19 { + u8 cfg[CS35L19_CFG_LEN]; + unsigned int rev; + unsigned int rate_code; +- unsigned int slot; /* TDM slot index (slots are 32 bits) */ ++ unsigned int slot; /* TDM slot index */ ++ unsigned int slot_bytes; /* TDM slot width in bytes, 2 or 4 */ + }; + + static void cs35l19_alive(struct work_struct *work) +@@ -165,7 +166,9 @@ static int cs35l19_power_on(struct cs35l19 *cs) + regmap_write(map, CS35L19_TX_EN1 + i, 0); + regmap_write(map, CS35L19_ADSP_CTL, 3); + regmap_write(map, CS35L19_CLK_CTL, cs->rate_code); +- regmap_write(map, CS35L19_RX_AUD, (cs->slot * 4) | (3 << 5)); ++ /* RX_AUD: [4:0] byte offset of the slot, [6:5] its width in bytes - 1 */ ++ regmap_write(map, CS35L19_RX_AUD, (cs->slot * cs->slot_bytes) | ++ ((cs->slot_bytes - 1) << 5)); + regmap_write(map, CS35L19_RX_SPLY, 0x80); + regmap_write(map, CS35L19_RX_ALIVE, 0x80); + +@@ -276,9 +279,12 @@ static int cs35l19_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, + { + struct cs35l19 *cs = snd_soc_component_get_drvdata(dai->component); + +- if (slot_width != 32 || !rx_mask) ++ if ((slot_width != 16 && slot_width != 32) || !rx_mask) + return -EINVAL; + cs->slot = __ffs(rx_mask); ++ cs->slot_bytes = slot_width / 8; ++ if (cs->slot * cs->slot_bytes > 0x1f) ++ return -EINVAL; + return 0; + } + +@@ -334,6 +340,7 @@ static int cs35l19_i2c_probe(struct i2c_client *client) + cs->dev = dev; + cs->rate_code = 0x49; + cs->slot = client->addr & 1; ++ cs->slot_bytes = 4; + INIT_DELAYED_WORK(&cs->alive_work, cs35l19_alive); + i2c_set_clientdata(client, cs); + diff --git a/kernel/patches/drivers/sound/0033-dt-bindings-sound-apple-s8000-mca-Add-the-S8000-TDM-.patch b/kernel/patches/drivers/sound/0033-dt-bindings-sound-apple-s8000-mca-Add-the-S8000-TDM-.patch new file mode 100644 index 00000000..937814e2 --- /dev/null +++ b/kernel/patches/drivers/sound/0033-dt-bindings-sound-apple-s8000-mca-Add-the-S8000-TDM-.patch @@ -0,0 +1,47 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:38:48 +0100 +Subject: [PATCH] dt-bindings: sound: apple,s8000-mca: Add the S8000 TDM + speaker link + +The iPhone 6s Plus speaker amplifier sits on an 8-slot TDM link of MCA2. +Add a compatible for an A9 MCA that clocks that link itself from an AP +NCO channel, like the T8010 and T7001 speaker links. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + .../devicetree/bindings/sound/apple,s8000-mca.yaml | 6 +++++- + 1 file changed, 5 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +index 917689968..c2e15fcc5 100644 +--- a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +@@ -17,7 +17,9 @@ description: | + moved by SmartIO DMA. T8010 uses the same register layout (version 5), + 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 ++ to the headphone codec. apple,s8000-mca-tdm is an A9 MCA driving its own ++ clocks from an AP NCO channel, the playback-only speaker link (TDM) of the ++ iPhone 6s Plus. The MCAs are the same block; the compatible names + 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 +@@ -32,6 +34,7 @@ allOf: + properties: + compatible: + enum: ++ - apple,s8000-mca-tdm + - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s +@@ -54,6 +57,7 @@ properties: + enum: + - apple,s5l8960x-mca + - apple,s8000-mca ++ - apple,s8000-mca-tdm + - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s diff --git a/kernel/patches/drivers/sound/0034-ASoC-apple-s8000-mca-Add-the-S8000-TDM-speaker-link.patch b/kernel/patches/drivers/sound/0034-ASoC-apple-s8000-mca-Add-the-S8000-TDM-speaker-link.patch new file mode 100644 index 00000000..9198fe76 --- /dev/null +++ b/kernel/patches/drivers/sound/0034-ASoC-apple-s8000-mca-Add-the-S8000-TDM-speaker-link.patch @@ -0,0 +1,92 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:38:48 +0100 +Subject: [PATCH] ASoC: apple: s8000-mca: Add the S8000 TDM speaker link + +Add the link the iPhone 6s Plus speaker amplifier needs, from its ADT's +/arm-io/mca2/audio-speaker iisConfig (the phone's live ADT): 8 slots of 16 bits +in a 128-bit frame with a 16-bit sync pulse and one bit of data delay, +the speaker in slot 1, a 12 MHz MCLK output, and SmartIO endpoint 0x2c +with a 0x60-byte FIFO and a 0x30 trigger. + +iOS runs this MCA as a clock consumer of the CS42L71 codec's ASP. Linux +has no CS42L71 driver, so the MCA provides the frame itself from an NCO +channel, with the polarity bit _setIISConfig_v4 sets for format flags +0x12 as provider (as on J81). + +As on J71b and J81, the output is capped at -12 dB, unconditionally, as +there is no speaker protection yet: iOS limits the speaker from the +amplifier's voltage and current sense, Linux does not. The cap is part of +the variant's table; no ALSA control or device tree property lifts it, +and mmap stays off so every sample is attenuated. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/apple/s8000-mca.c | 46 +++++++++++++++++++++++++++++++++++++ + 1 file changed, 46 insertions(+) + +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index 3e8095148..4cb23eb88 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -1316,6 +1316,51 @@ static const struct s8000_mca_hw s8000_mca_hw = { + .sio_trigger = 0x180, + }; + ++/* ++ * N66 (iPhone 6s Plus) MCA2 TX to the CS35L19 speaker amplifier, from the ++ * ADT's /arm-io/mca2/audio-speaker iisConfig (the phone's live ADT, iOS 15): ++ * ++ * 10 12 00 00 08 00 01 00 00 1b b7 00 00 00 10 00 ++ * 30 00 01 00 02 00 00 00 0c 00 00 00 01 02 10 10 00 00 00 00 ++ * ++ * 8 slots of 16 bits (a 128-bit frame) with a 16-bit sync pulse and one bit ++ * of data delay, format flags 0x12, the speaker in slot 1, a 12 MHz MCLK ++ * output. iOS runs this MCA as a clock consumer of the CS42L71 codec's ASP, ++ * which Linux does not drive yet, so the MCA provides the clocks itself from ++ * NCO 2 (6.144 MHz at 48 kHz), with the polarity bit _setIISConfig_v4 sets ++ * for flags 0x12 in that role (as on J81). The SmartIO shim words are the ++ * ADT's dma-channels for endpoint 0x2c (FIFO 0x60, trigger 0x30). ++ * ++ * The output is capped at -12 dB (attenuation 4), unconditionally: there is ++ * no speaker protection yet. iOS reads the amplifier's voltage and current ++ * sense back and keeps the speaker in its limits; Linux does not. The cap ++ * lives in this table only, so no ALSA control or device tree property can ++ * lift it, and with mmap off every sample passes through mca_attenuate(). ++ */ ++static const struct s8000_mca_hw s8000_tdm_mca_hw = { ++ .version = 4, ++ .regs = &mca_v4_regs, ++ .clock_provider = true, ++ .dai_format = SND_SOC_DAIFMT_DSP_A, ++ .channels = 1, ++ .slots = 8, ++ .tx_slots = 0x2, ++ .tx_cfg = 0x133, ++ .rx_cfg = 0x137, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ .frame_flags = MCA_FRAME_POL, ++ .sync_bits = 16, ++ .stream_irqs = MCA_IRQ_FRAME_ERROR, ++ .attenuation = 4, ++ .mclk_ctl = 0x58, ++ .mclk_rate = 12000000, ++ .sio_xfer16 = 0x21, ++ .sio_xfer32 = 0x22, ++ .sio_timeout = 0, ++ .sio_fifo = 0x60, ++ .sio_trigger = 0x30, ++}; ++ + /* + * J71b MCA2 TX: iPadOS 17.7.11 audio-speaker iisConfig and dma-channels, not + * the A9 MCA0 values. Slots 0-3 carry the four amplifiers; which speaker sits +@@ -1428,6 +1473,7 @@ static const struct s8000_mca_hw s5l8960x_mca_hw = { + static const struct of_device_id s8000_mca_of_match[] = { + { .compatible = "apple,s5l8960x-mca", .data = &s5l8960x_mca_hw }, + { .compatible = "apple,s8000-mca", .data = &s8000_mca_hw }, ++ { .compatible = "apple,s8000-mca-tdm", .data = &s8000_tdm_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 }, diff --git a/kernel/patches/drivers/sound/0035-dt-bindings-clock-apple-nco-Add-the-S8000.patch b/kernel/patches/drivers/sound/0035-dt-bindings-clock-apple-nco-Add-the-S8000.patch new file mode 100644 index 00000000..79fc7574 --- /dev/null +++ b/kernel/patches/drivers/sound/0035-dt-bindings-clock-apple-nco-Add-the-S8000.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 15:38:55 +0100 +Subject: [PATCH] dt-bindings: clock: apple,nco: Add the S8000 + +The A9's NCO is the T8010's block at the same address with the same +channel stride (the ADT's pmgr-nco-page-size is 0x4000 on both), so it +falls back to apple,t8010-nco. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + Documentation/devicetree/bindings/clock/apple,nco.yaml | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/Documentation/devicetree/bindings/clock/apple,nco.yaml b/Documentation/devicetree/bindings/clock/apple,nco.yaml +index a23660034..d8915d404 100644 +--- a/Documentation/devicetree/bindings/clock/apple,nco.yaml ++++ b/Documentation/devicetree/bindings/clock/apple,nco.yaml +@@ -22,6 +22,9 @@ properties: + oneOf: + - const: apple,t7001-nco + - const: apple,t8010-nco ++ - items: ++ - const: apple,s8000-nco ++ - const: apple,t8010-nco + - items: + - const: apple,t6020-nco + - const: apple,t8103-nco diff --git a/kernel/patches/drivers/sound/0036-ASoC-cs35l19-Accept-the-CS35L21.patch b/kernel/patches/drivers/sound/0036-ASoC-cs35l19-Accept-the-CS35L21.patch new file mode 100644 index 00000000..6f84e5eb --- /dev/null +++ b/kernel/patches/drivers/sound/0036-ASoC-cs35l19-Accept-the-CS35L21.patch @@ -0,0 +1,38 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 16:21:46 +0100 +Subject: [PATCH] ASoC: cs35l19: Accept the CS35L21 + +The iPhone 6s Plus's speaker amplifier answers with device ID 35 A2 10, +a CS35L21. iOS drives it with the same AppleCS35L19Amp driver and +register layout as the CS35L19, which it tells apart by the ID only. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/cs35l19.c | 8 +++++--- + 1 file changed, 5 insertions(+), 3 deletions(-) + +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +index 3f05be281..0d0379a35 100644 +--- a/sound/soc/codecs/cs35l19.c ++++ b/sound/soc/codecs/cs35l19.c +@@ -369,13 +369,15 @@ static int cs35l19_i2c_probe(struct i2c_client *client) + ret = regmap_bulk_read(cs->regmap, CS35L19_DEVID_AB, id, 3); + if (ret) + return dev_err_probe(dev, ret, "no answer\n"); +- if (id[0] != 0x35 || id[1] != 0xa1 || (id[2] & 0xf0) != 0x90) +- return dev_err_probe(dev, -ENODEV, "device ID %02x%02x%02x, not a CS35L19\n", ++ /* iOS's AppleCS35L19Amp drives the CS35L21 (35 A2 1x) the same way. */ ++ if (id[0] != 0x35 || !((id[1] == 0xa1 && (id[2] & 0xf0) == 0x90) || ++ (id[1] == 0xa2 && (id[2] & 0xf0) == 0x10))) ++ return dev_err_probe(dev, -ENODEV, "device ID %02x%02x%02x, not a CS35L19 or CS35L21\n", + id[0], id[1], id[2]); + ret = regmap_read(cs->regmap, CS35L19_REV_ID, &cs->rev); + if (ret) + return ret; +- dev_info(dev, "CS35L19 revision %02x\n", cs->rev); ++ dev_info(dev, "CS35L%s revision %02x\n", id[1] == 0xa2 ? "21" : "19", cs->rev); + + return devm_snd_soc_register_component(dev, &cs35l19_component, + &cs35l19_dai, 1); diff --git a/kernel/patches/drivers/sound/0037-ASoC-cs35l19-Turn-the-alive-watchdog-off-without-a-k.patch b/kernel/patches/drivers/sound/0037-ASoC-cs35l19-Turn-the-alive-watchdog-off-without-a-k.patch new file mode 100644 index 00000000..1ddf161c --- /dev/null +++ b/kernel/patches/drivers/sound/0037-ASoC-cs35l19-Turn-the-alive-watchdog-off-without-a-k.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 16:28:26 +0100 +Subject: [PATCH] ASoC: cs35l19: Turn the alive watchdog off without a + keep-alive line + +The iPhone 6s Plus wires no keep-alive GPIO to its speaker amplifier, so +the amp's alive watchdog tripped (INT_STATUS_1 bit 5) and muted the +output while the serial port and the DMA ran. With the watchdog off, the +way cs35l33 sets it up, the speaker plays. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/cs35l19.c | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +index 0d0379a35..64e13870c 100644 +--- a/sound/soc/codecs/cs35l19.c ++++ b/sound/soc/codecs/cs35l19.c +@@ -37,6 +37,7 @@ + #define CS35L19_PWRCTL2 0x07 + #define CS35L19_CLK_CTL 0x08 + #define CS35L19_BST_PEAK 0x09 ++#define CS35L19_PROTECT_CTL 0x0a + #define CS35L19_BST_CTL1 0x0b + #define CS35L19_BST_CTL2 0x0c + #define CS35L19_ADSP_CTL 0x0d +@@ -130,6 +131,15 @@ static int cs35l19_power_on(struct cs35l19 *cs) + } + regmap_write(map, CS35L19_BST_CTL1, cfg[1] & 0x3f); + regmap_update_bits(map, CS35L19_BST_CTL2, 0x03, cfg[2] & 0x03); ++ /* ++ * Without a keep-alive line (the iPhone 6s Plus has none) the alive ++ * watchdog trips (INT_STATUS_1 bit 5) and mutes the output; turn it ++ * off the way cs35l33 does. ++ */ ++ if (!cs->keepalive) { ++ regmap_update_bits(map, CS35L19_PROTECT_CTL, 0x0c, 0x08); ++ regmap_update_bits(map, CS35L19_BST_CTL2, 0x08, 0x08); ++ } + + regmap_write(map, CS35L19_PWRCTL1, 0x80); /* all on but the amp */ + regmap_write(map, CS35L19_PWRCTL2, 0xf8); /* no V/I/VP/VBST sense, TDM */ diff --git a/kernel/patches/drivers/sound/0038-ASoC-cs35l19-Cap-the-gain-at-0-dB-without-speaker-pr.patch b/kernel/patches/drivers/sound/0038-ASoC-cs35l19-Cap-the-gain-at-0-dB-without-speaker-pr.patch new file mode 100644 index 00000000..7e604242 --- /dev/null +++ b/kernel/patches/drivers/sound/0038-ASoC-cs35l19-Cap-the-gain-at-0-dB-without-speaker-pr.patch @@ -0,0 +1,94 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 16:44:56 +0100 +Subject: [PATCH] ASoC: cs35l19: Cap the gain at 0 dB without speaker + protection + +The amplifier's digital volume goes up to +12 dB. iOS may use that range +because its speaker protection reads the amp's voltage and current sense +back and keeps the speaker in its limits; Linux has no speaker protection +yet. Stop the "Speaker Volume" control at 0 dB, and clamp the volume the +driver restores after a power-up or power-down too, so that a value left +in the register by anything else cannot raise the gain above 0 dB. + +This holds for every board with this amplifier: none of them has speaker +protection under Linux. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/cs35l19.c | 30 ++++++++++++++++++++++++++---- + 1 file changed, 26 insertions(+), 4 deletions(-) + +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +index 64e13870c..087d680ab 100644 +--- a/sound/soc/codecs/cs35l19.c ++++ b/sound/soc/codecs/cs35l19.c +@@ -56,6 +56,7 @@ + #define CS35L19_MAX_REG 0x7f + + #define CS35L19_VOL_MUTE 0x19 /* what iOS writes to mute */ ++#define CS35L19_VOL_0DB 0x00 + #define CS35L19_CFG_LEN 20 + + /* The ADT's speaker-config for P105AP, the same for both amps. */ +@@ -79,6 +80,24 @@ struct cs35l19 { + unsigned int slot_bytes; /* TDM slot width in bytes, 2 or 4 */ + }; + ++/* ++ * DIG_VOL counts 0.5 dB steps: 0x34 is -102 dB, 0xff -0.5 dB, 0x00 0 dB and ++ * 0x18 +12 dB; 0x19 is iOS's mute. iOS may go above 0 dB because its speaker ++ * protection (the amp's V/I sense, read back on the serial port) keeps the ++ * speaker in its limits. Linux has no speaker protection yet, so the gain ++ * stays at 0 dB or below: a positive gain, however it got into the register, ++ * becomes 0 dB, and the codes above +12 dB become the mute. ++ */ ++static unsigned int cs35l19_safe_vol(unsigned int vol) ++{ ++ vol &= 0xff; ++ if (vol > CS35L19_VOL_0DB && vol < CS35L19_VOL_MUTE) ++ return CS35L19_VOL_0DB; ++ if (vol >= CS35L19_VOL_MUTE && vol < 0x34) ++ return CS35L19_VOL_MUTE; ++ return vol; ++} ++ + static void cs35l19_alive(struct work_struct *work) + { + struct cs35l19 *cs = container_of(to_delayed_work(work), struct cs35l19, +@@ -182,7 +201,7 @@ static int cs35l19_power_on(struct cs35l19 *cs) + regmap_write(map, CS35L19_RX_SPLY, 0x80); + regmap_write(map, CS35L19_RX_ALIVE, 0x80); + +- return regmap_write(map, CS35L19_DIG_VOL, vol); ++ return regmap_write(map, CS35L19_DIG_VOL, cs35l19_safe_vol(vol)); + } + + static void cs35l19_power_off(struct cs35l19 *cs) +@@ -198,7 +217,7 @@ static void cs35l19_power_off(struct cs35l19 *cs) + usleep_range(1000, 2000); + regmap_write(map, CS35L19_PWRCTL1, 0x87); + usleep_range(4000, 5000); +- regmap_write(map, CS35L19_DIG_VOL, vol); ++ regmap_write(map, CS35L19_DIG_VOL, cs35l19_safe_vol(vol)); + } + + static int cs35l19_amp_event(struct snd_soc_dapm_widget *w, +@@ -240,11 +259,14 @@ static int cs35l19_amp_event(struct snd_soc_dapm_widget *w, + return 0; + } + +-/* 0.5 dB steps around 0 dB: 0x34 is -102 dB, 0x00 0 dB, 0x18 +12 dB */ ++/* ++ * -102 dB (0x34) up to 0 dB (0x00), 204 steps of 0.5 dB: the amp could go to ++ * +12 dB, but without speaker protection 0 dB is the top (cs35l19_safe_vol). ++ */ + static const DECLARE_TLV_DB_SCALE(cs35l19_vol_tlv, -10200, 50, 0); + + static const struct snd_kcontrol_new cs35l19_controls[] = { +- SOC_SINGLE_SX_TLV("Speaker Volume", CS35L19_DIG_VOL, 0, 0x34, 0xe4, ++ SOC_SINGLE_SX_TLV("Speaker Volume", CS35L19_DIG_VOL, 0, 0x34, 0xcc, + cs35l19_vol_tlv), + }; + diff --git a/kernel/patches/drivers/sound/0039-ASoC-cs35l19-Watch-the-over-temperature-and-short-pr.patch b/kernel/patches/drivers/sound/0039-ASoC-cs35l19-Watch-the-over-temperature-and-short-pr.patch new file mode 100644 index 00000000..c19a59fb --- /dev/null +++ b/kernel/patches/drivers/sound/0039-ASoC-cs35l19-Watch-the-over-temperature-and-short-pr.patch @@ -0,0 +1,139 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: ricktav <82380971+ricktav@users.noreply.github.com> +Date: Mon, 23 Nov 2026 16:45:50 +0100 +Subject: [PATCH] ASoC: cs35l19: Watch the over-temperature and short + protections + +The amplifier shuts its output down by itself on over-temperature (OTE) +or a shorted output (AMP_SHORT), and stays down until the release bits +in AMP_CTL are toggled; the driver never toggles them and leaves the +interrupt masks at their reset value, as iOS does: the masks gate only +the INT pin, not the protections. + +Nothing said so, though. While the amp is on, poll INT_STATUS_1 every +500 ms (its bits are sticky and clear on read), warn on the +over-temperature warning (OTW), OTE and AMP_SHORT, and on OTE or +AMP_SHORT also mute and power the amp stage down until the stream +stops, so that the volume control cannot bring the output back. + +Assisted-by: LLM +Signed-off-by: ricktav <82380971+ricktav@users.noreply.github.com> +--- + sound/soc/codecs/cs35l19.c | 60 +++++++++++++++++++++++++++++++++++++- + 1 file changed, 59 insertions(+), 1 deletion(-) + +diff --git a/sound/soc/codecs/cs35l19.c b/sound/soc/codecs/cs35l19.c +index 087d680ab..f66ca9981 100644 +--- a/sound/soc/codecs/cs35l19.c ++++ b/sound/soc/codecs/cs35l19.c +@@ -48,6 +48,11 @@ + #define CS35L19_AMP_CTL 0x12 + #define CS35L19_INT_STATUS_1 0x15 + #define CS35L19_INT_STATUS_2 0x16 ++#define CS35L19_INT_OTE BIT(0) /* INT_STATUS_1: over-temperature shutdown */ ++#define CS35L19_INT_OTW BIT(1) /* over-temperature warning */ ++#define CS35L19_INT_AMP_SHORT BIT(2) /* output short shutdown */ ++#define CS35L19_PDN_AMP BIT(7) /* PWRCTL1 */ ++#define CS35L19_WATCH_MS 500 + #define CS35L19_TX_VMON 0x2d /* .. 0x31: V, I, VP, VBST, FLAG */ + #define CS35L19_TX_EN1 0x32 /* .. 0x35 */ + #define CS35L19_RX_AUD 0x36 +@@ -73,6 +78,9 @@ struct cs35l19 { + struct gpio_desc *keepalive; + struct delayed_work alive_work; + bool alive_level; ++ struct delayed_work watch_work; ++ bool faulted; /* OTE or AMP_SHORT seen: amp held off */ ++ unsigned int fault_vol; /* DIG_VOL before the fault mute */ + u8 cfg[CS35L19_CFG_LEN]; + unsigned int rev; + unsigned int rate_code; +@@ -120,6 +128,46 @@ static void cs35l19_alive_stop(struct cs35l19 *cs) + cancel_delayed_work_sync(&cs->alive_work); + } + ++/* ++ * The amp's own protections: on over-temperature (OTE) or a shorted output ++ * (AMP_SHORT) it shuts its output down by itself, and it stays down until ++ * the release bits in AMP_CTL[3:0] are toggled, which this driver never ++ * does (power_on changes only AMP_CTL[7:4]). INT_MASK_1/2 gate only the INT ++ * pin, not the protections; they stay at their reset value, all masked, as ++ * iOS leaves them, and no interrupt is wired here. The status bits are ++ * sticky and clear on read: poll them while the amp is on, warn on any of ++ * the three, and on OTE or AMP_SHORT also mute and power the amp stage down ++ * until the stream stops, so that nothing (not even the volume control) ++ * brings the output back during this stream. ++ */ ++static void cs35l19_watch(struct work_struct *work) ++{ ++ struct cs35l19 *cs = container_of(to_delayed_work(work), struct cs35l19, ++ watch_work); ++ struct regmap *map = cs->regmap; ++ unsigned int st1; ++ ++ if (!regmap_read(map, CS35L19_INT_STATUS_1, &st1)) { ++ if (st1 & CS35L19_INT_OTW) ++ dev_warn(cs->dev, "over-temperature warning (status %02x)\n", ++ st1); ++ if ((st1 & (CS35L19_INT_OTE | CS35L19_INT_AMP_SHORT)) && ++ !cs->faulted) { ++ dev_warn(cs->dev, "%s (status %02x): muted until the stream stops\n", ++ st1 & CS35L19_INT_AMP_SHORT ? "output short" : ++ "over-temperature shutdown", ++ st1); ++ if (regmap_read(map, CS35L19_DIG_VOL, &cs->fault_vol)) ++ cs->fault_vol = CS35L19_VOL_MUTE; ++ cs->faulted = true; ++ regmap_write(map, CS35L19_DIG_VOL, CS35L19_VOL_MUTE); ++ regmap_update_bits(map, CS35L19_PWRCTL1, CS35L19_PDN_AMP, ++ CS35L19_PDN_AMP); ++ } ++ } ++ schedule_delayed_work(&cs->watch_work, msecs_to_jiffies(CS35L19_WATCH_MS)); ++} ++ + /* AppleCS35L19Amp's power-on (0x80af55d4) and serial port (0x80af5be0). */ + static int cs35l19_power_on(struct cs35l19 *cs) + { +@@ -211,6 +259,10 @@ static void cs35l19_power_off(struct cs35l19 *cs) + + if (regmap_read(map, CS35L19_DIG_VOL, &vol)) + return; ++ if (cs->faulted) { ++ vol = cs->fault_vol; ++ cs->faulted = false; ++ } + regmap_write(map, CS35L19_DIG_VOL, CS35L19_VOL_MUTE); + regmap_update_bits(map, CS35L19_PWRCTL1, 0x80, 0x80); + regmap_write(map, CS35L19_PWRCTL2, 0xfe); +@@ -248,9 +300,13 @@ static int cs35l19_amp_event(struct snd_soc_dapm_widget *w, + if (ret) { + cs35l19_alive_stop(cs); + clk_disable_unprepare(cs->mclk); ++ return ret; + } +- return ret; ++ schedule_delayed_work(&cs->watch_work, ++ msecs_to_jiffies(CS35L19_WATCH_MS)); ++ return 0; + case SND_SOC_DAPM_POST_PMD: ++ cancel_delayed_work_sync(&cs->watch_work); + cs35l19_power_off(cs); + cs35l19_alive_stop(cs); + clk_disable_unprepare(cs->mclk); +@@ -374,6 +430,7 @@ static int cs35l19_i2c_probe(struct i2c_client *client) + cs->slot = client->addr & 1; + cs->slot_bytes = 4; + INIT_DELAYED_WORK(&cs->alive_work, cs35l19_alive); ++ INIT_DELAYED_WORK(&cs->watch_work, cs35l19_watch); + i2c_set_clientdata(client, cs); + + cs->regmap = devm_regmap_init_i2c(client, &cs35l19_regmap); +@@ -419,6 +476,7 @@ static void cs35l19_i2c_remove(struct i2c_client *client) + { + struct cs35l19 *cs = i2c_get_clientdata(client); + ++ cancel_delayed_work_sync(&cs->watch_work); + cancel_delayed_work_sync(&cs->alive_work); + } + diff --git a/tools/catalog/drivers.json b/tools/catalog/drivers.json index 26e67140..0c3758eb 100644 --- a/tools/catalog/drivers.json +++ b/tools/catalog/drivers.json @@ -564,6 +564,7 @@ ], "n66": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons", @@ -579,6 +580,7 @@ ], "n66m": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons", @@ -594,6 +596,7 @@ ], "n69": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons", @@ -609,6 +612,7 @@ ], "n69u": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons", @@ -624,6 +628,7 @@ ], "n71": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons", @@ -639,6 +644,7 @@ ], "n71m": [ "accelerometer", + "audio_output", "backlight", "battery", "buttons",