diff --git a/devices/j120/README.md b/devices/j120/README.md new file mode 100644 index 00000000..ddf3ba71 --- /dev/null +++ b/devices/j120/README.md @@ -0,0 +1,17 @@ +# iPad Pro 12.9-inch (2017), Wi-Fi + +J120 (A1670, iPad7,1) boots from internal storage through a J120-capable +m1n1 binary. The loader must be able to read the internal FAT boot partition, +supply the NVMe handoff in the Linux device tree and start the saved Linux entry. + +Supply the loader separately as `m1n1.bin`. When assembling release inputs, +pass the file to Orchard's `orchard.inputs` module with `--m1n1 FILE`. +The generic Orchard `v0.3.2` loader has not been qualified for J120 internal boot. + +## Loader source + +The J120 build used AsahiLinux/m1n1 at +`c9ef56f7356e93e6f6cac116c529d31c277ef6a6` with local J120 changes. Orchard +carries its standard loader changes in [boot/m1n1/patches](../../boot/m1n1/patches/). +The additional J120 source patch is pending a separate export from the loader +maintainer. diff --git a/devices/j120/device.toml b/devices/j120/device.toml index a4b71078..a211d474 100644 --- a/devices/j120/device.toml +++ b/devices/j120/device.toml @@ -1,5 +1,4 @@ -# iPad Pro 2 (12.9-inch, Wi-Fi) (J120): identity from public sources -# (tools/catalog/generate). In its platform's kernel, no bring-up yet; see docs/device-bring-up.md. +# iPad Pro 12.9-inch (2017), Wi-Fi: J120 / iPad7,1 / A1670. schema = 1 kind = "hardware.device" @@ -14,46 +13,43 @@ chip = 0x8011 board = 0x0c [boot] -methods = ["checkm8-pongo"] # palera1n's device list (palera.in); not run with Orchard yet. +methods = ["checkm8-pongo"] # RAM and tethered internal ext4 boot on J120. [kernel] platform = "apple-16k" dtb = "t8011-j120" # arch/arm64/boot/dts/apple/.dtb [firmware] -recipe = "firmware.json" # Pins this board's public IPSW; converts nothing until bring-up needs it. +recipe = "firmware.json" # Pinned touch, BCM4355 C0 WLAN and AOP firmware. [support] status = "experimental" -# States: working, untested, missing, none (features.toml). Nothing here has run on -# this board with Orchard: "untested" means a driver binds in its device tree -# (tools/catalog/drivers.json), plus the display's boot console. [features] -display = "untested" +display = "working" screen_off = "missing" -backlight = "untested" -touch = "missing" -buttons = "untested" -accelerometer = "missing" -gyroscope = "missing" -light_sensor = "missing" +backlight = "working" +touch = "working" +buttons = "working" # Power/Home and polled Smart Cover close. Cover-open wake needs an IRQ. +accelerometer = "working" +gyroscope = "untested" +light_sensor = "working" touch_id = "missing" -storage_read = "missing" -storage_write = "missing" -wifi = "missing" -bluetooth_input = "missing" -bluetooth_audio = "missing" -cellular = "missing" -battery = "missing" -charging = "missing" +storage_read = "working" +storage_write = "working" +wifi = "working" +bluetooth_input = "working" +bluetooth_audio = "working" +cellular = "none" +battery = "working" +charging = "working" # Guarded Lightning charging. charging_control = "missing" -suspend = "untested" -resume = "untested" -usb_serial = "untested" -usb_network = "untested" +suspend = "working" +resume = "working" +usb_serial = "working" +usb_network = "working" usb_host = "missing" -audio_output = "missing" -audio_input = "missing" +audio_output = "working" +audio_input = "working" camera = "missing" -video_decode_hevc = "missing" +video_decode_hevc = "working" diff --git a/devices/j120/firmware.json b/devices/j120/firmware.json index e95d8616..9052a176 100644 --- a/devices/j120/firmware.json +++ b/devices/j120/firmware.json @@ -9,12 +9,211 @@ "sha256": "c84ad24b6981a859eec499b1802be9ac593acfd3dc0a185a76d06e4d767a1451" }, "inputs": { - "DeviceTree.im4p": { + "J120.mtprops": { "ipsw": { - "zip": "Firmware/all_flash/DeviceTree.j120ap.im4p" + "rootfs": "usr/share/firmware/multitouch/J120.mtprops" }, - "sha256": "3f612f64819fbf6a8aacc03fabeda08ba897c4bf5385df995c59815c0c80c8f0" + "device": "/usr/share/firmware/multitouch/J120.mtprops", + "sha256": "c70b61fe6b93d52f09bb1a61cc5ccb0f03960d1ab8a377831437ac985a7ba3b4" + }, + "joya.trx": { + "ipsw": { + "rootfs": "System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.trx" + }, + "device": "/System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.trx", + "sha256": "010cba55ca64d54659b6b036f5a3aa671ba1ef9fc53da3dd611b79a37c3b7ace" + }, + "joya.clmb": { + "ipsw": { + "rootfs": "System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.clmb" + }, + "device": "/System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.clmb", + "sha256": "510e223ec2ea1dfe7fe23ded44fc53b15f6cf7d868fbdb68af83a8cc9fd9f097" + }, + "joya.txcb": { + "ipsw": { + "rootfs": "System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.txcb" + }, + "device": "/System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/joya.txcb", + "sha256": "1922ad54c98774877e7d4bcedfb51b68465ea9233c136b9a48b8bb0b35868c1f" + }, + "P-joya_M-YSBC_V-u__m-4.1.txt": { + "ipsw": { + "rootfs": "System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/P-joya_M-YSBC_V-u__m-4.1.txt" + }, + "device": "/System/Library/DriverExtensions/com.apple.DriverKit-AppleBCMWLAN.dext/Firmware/C-4355__s-C0/P-joya_M-YSBC_V-u__m-4.1.txt", + "sha256": "193f6555e82334313ae02bcbc7ef5216da56edcad0fbac85e815a8c0094b0e31" + }, + "aop.im4p": { + "ipsw": { + "zip": "Firmware/AOP/aopfw-ipad7aop.RELEASE.im4p" + }, + "sha256": "853be8f95f14740231c605cec954af5dd6d1994a66cfeb9513eb6dfcf706d90b" + }, + "BlueTool": { + "ipsw": { + "rootfs": "usr/sbin/BlueTool" + }, + "device": "/usr/sbin/BlueTool", + "sha256": "1dd532b7f9fb25a5348011bad7041ce029b6bd990b68cfe9e5f076a073d1f5bf" + }, + "kernelcache": { + "ipsw": { + "kernelcache": true + }, + "device": { + "kernelcache": "active" + }, + "sha256": "f18b4df865405f2a287b84977d7aca745e056d656d9fc9df1662970ce2969de7" } }, - "outputs": [] + "outputs": [ + { + "destination": "lib/firmware/apple/t8011-smartio.bin", + "sha256": "8a6e5a1bcdd2768db4515d714c7ee311d7089656e83b5073efa70b625b762b9e", + "steps": [ + { + "step": "smartio-from-kernelcache@2", + "input": "kernelcache", + "kext": "com.apple.driver.AppleT8011SmartIO" + } + ] + }, + { + "destination": "lib/firmware/apple/j120-touch-K1F18,3.z2fw", + "sha256": "b12aecc2c895561c7d9edb7d1bfb7295d041b5a0efe3c466cef54b89194a7ace", + "steps": [ + { + "step": "z2fw-from-mtprops@1", + "input": "J120.mtprops", + "profile": "K1F18,3", + "packet": "K1HBPP14", + "load_address": 1048576, + "hbpp_version": 260 + } + ] + }, + { + "destination": "lib/firmware/brcm/brcmfmac4355-pcie.apple,j120.bin", + "sha256": "010cba55ca64d54659b6b036f5a3aa671ba1ef9fc53da3dd611b79a37c3b7ace", + "steps": [ + { + "step": "copy@1", + "input": "joya.trx" + } + ] + }, + { + "destination": "lib/firmware/brcm/brcmfmac4355-pcie.apple,j120.clm_blob", + "sha256": "510e223ec2ea1dfe7fe23ded44fc53b15f6cf7d868fbdb68af83a8cc9fd9f097", + "steps": [ + { + "step": "copy@1", + "input": "joya.clmb" + } + ] + }, + { + "destination": "lib/firmware/brcm/brcmfmac4355-pcie.apple,j120.txcap_blob", + "sha256": "1922ad54c98774877e7d4bcedfb51b68465ea9233c136b9a48b8bb0b35868c1f", + "steps": [ + { + "step": "copy@1", + "input": "joya.txcb" + } + ] + }, + { + "destination": "lib/firmware/brcm/brcmfmac4355-pcie.apple,j120-YSBC-u-4.1.txt", + "sha256": "193f6555e82334313ae02bcbc7ef5216da56edcad0fbac85e815a8c0094b0e31", + "steps": [ + { + "step": "copy@1", + "input": "P-joya_M-YSBC_V-u__m-4.1.txt" + } + ] + }, + { + "destination": "lib/firmware/apple/aop-ipad7.bin", + "sha256": "a2bac8975ab0658295ecb5824187962d3606cc569e38a673770f7d1d4d1f8f54", + "steps": [ + { + "step": "im4p-payload@1", + "input": "aop.im4p" + }, + { + "step": "aop-image@1", + "coprocessor": "AOP" + } + ] + }, + { + "destination": "lib/firmware/apple/aop-ipad7-ext.bin", + "sha256": "28bfaad8cbfdaa9fceb55d02e68a323a16f107f40840fb2fdabaafcd5f2c6eb1", + "steps": [ + { + "step": "im4p-payload@1", + "input": "aop.im4p" + }, + { + "step": "aop-image@1", + "coprocessor": "AOP_ext" + } + ] + }, + { + "destination": "lib/firmware/brcm/BCM.apple,j120-u.hcd", + "sha256": "df14e4a858108b5381d5699999becb50dd86a41841f93ed26b0e6e3527464632", + "steps": [ + { + "step": "bluetool-hcd@1", + "input": "BlueTool" + } + ] + }, + { + "destination": "lib/firmware/brcm/BCM.apple,j120-m.hcd", + "sha256": "b6fc9fb2a0eec9fd7b3b233d78cbe2541667542296e3889425f56b3f744e02ec", + "steps": [ + { + "step": "bluetool-hcd@1", + "input": "BlueTool" + } + ] + }, + { + "destination": "lib/firmware/brcm/BCM.apple,j120-u.regulatory", + "sha256": "b48cdcdc06db1573cc8793ca80373af59219a7bba8d28a89a352597e9db5779a", + "steps": [ + { + "step": "bluetool-regulatory@1", + "input": "BlueTool", + "address": 4304523153, + "size": 210 + } + ] + }, + { + "destination": "lib/firmware/brcm/BCM.apple,j120-m.regulatory", + "sha256": "b48cdcdc06db1573cc8793ca80373af59219a7bba8d28a89a352597e9db5779a", + "steps": [ + { + "step": "bluetool-regulatory@1", + "input": "BlueTool", + "address": 4304523363, + "size": 210 + } + ] + }, + { + "destination": "lib/firmware/apple/vxd-deva.bin", + "sha256": "bf5167652e81540471aaca141943fd33d71c3990c137f145471305f5f5ade83b", + "steps": [ + { + "step": "vxd-firmware-from-kernelcache@1", + "input": "kernelcache" + } + ] + } + ] } diff --git a/docs/compatibility.md b/docs/compatibility.md index 596cd84d..16516345 100644 --- a/docs/compatibility.md +++ b/docs/compatibility.md @@ -92,7 +92,7 @@ Generated by `tools/catalog/generate matrix` from `devices/`, `chips/` and `meth | A10 | `j172` | iPad 7 (Cellular) | iPad7,12 | experimental | yes | checkm8-pongo | yes | yes | 21H16 | | A10 | `j71b` | iPad 6 (Wi-Fi) | iPad7,5 | supported | yes | checkm8-pongo | yes | yes | 21H461 | | A10 | `j72b` | iPad 6 (Cellular) | iPad7,6 | experimental | yes | checkm8-pongo | yes | yes | 21H461 | -| A10X | `j120` | iPad Pro 2 (12.9-inch, Wi-Fi) | iPad7,1 | experimental | – | checkm8-pongo | yes | yes | 21H461 | +| A10X | `j120` | iPad Pro 2 (12.9-inch, Wi-Fi) | iPad7,1 | experimental | yes | checkm8-pongo | yes | yes | 21H461 | | A10X | `j121` | iPad Pro 2 (12.9-inch, Cellular) | iPad7,2 | experimental | – | checkm8-pongo | yes | yes | 21H461 | | A10X | `j207` | iPad Pro (10.5-inch, Wi-Fi) | iPad7,3 | experimental | – | checkm8-pongo | yes | yes | 21H461 | | A10X | `j208` | iPad Pro (10.5-inch, Cellular) | iPad7,4 | experimental | – | checkm8-pongo | yes | yes | 21H461 | @@ -178,7 +178,7 @@ Boards Orchard builds for. States: working, untested, missing, none (no such har | `j172` | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | untested | missing | missing | missing | untested | untested | missing | untested | untested | untested | untested | untested | untested | untested | missing | untested | | `j71b` | working | working | working | working | working | working | untested | untested | missing | working | working | working | working | working | none | working | working | working | working | working | working | working | untested | working | working | missing | untested | | `j72b` | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | untested | untested | missing | missing | missing | untested | untested | untested | untested | untested | untested | untested | untested | untested | untested | missing | untested | -| `j120` | untested | missing | untested | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | +| `j120` | working | missing | working | working | working | working | untested | working | missing | working | working | working | working | working | none | working | working | missing | working | working | working | working | missing | working | working | missing | working | | `j121` | untested | missing | untested | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | | `j207` | untested | missing | untested | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | | `j208` | untested | missing | untested | missing | untested | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | missing | untested | untested | untested | untested | missing | missing | missing | missing | missing | @@ -233,7 +233,7 @@ A yes means an enabled device tree node binds a driver in `7.3.0-rc1-orchard-app | `j172` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | | `j71b` | supported | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | | `j72b` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | -| `j120` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | +| `j120` | experimental | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | yes | – | yes | yes | yes | | `j121` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | | `j207` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | | `j208` | experimental | yes | – | yes | – | – | – | – | – | – | – | – | – | – | yes | yes | – | – | – | – | diff --git a/kernel/configs/apple-16k/config b/kernel/configs/apple-16k/config index 172fb954..b992a1b4 100644 --- a/kernel/configs/apple-16k/config +++ b/kernel/configs/apple-16k/config @@ -2431,6 +2431,7 @@ CONFIG_TOUCHSCREEN_APPLE_Z2=m # CONFIG_TOUCHSCREEN_ZINITIX is not set # CONFIG_TOUCHSCREEN_HIMAX_HX83112B is not set CONFIG_INPUT_MISC=y +CONFIG_INPUT_APPLE_J120_COVER=m # CONFIG_INPUT_AD714X is not set # CONFIG_INPUT_ATMEL_CAPTOUCH is not set # CONFIG_INPUT_AW86927 is not set @@ -4399,6 +4400,7 @@ CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y # CONFIG_SND_SOC_APPLE_MCA is not set CONFIG_SND_SOC_APPLE_S8000_MCA=m CONFIG_SND_SOC_APPLE_T8010_PDM=m +CONFIG_SND_SOC_APPLE_J120_SPEAKERS=m # end of Apple # @@ -5521,7 +5523,7 @@ CONFIG_DEVFREQ_GOV_SIMPLE_ONDEMAND=y # CONFIG_PM_DEVFREQ_EVENT is not set # CONFIG_EXTCON is not set # CONFIG_MEMORY is not set -CONFIG_IIO=m +CONFIG_IIO=y CONFIG_IIO_BUFFER=y # CONFIG_IIO_BUFFER_CB is not set # CONFIG_IIO_BUFFER_DMA is not set @@ -5625,6 +5627,7 @@ CONFIG_APPLE_AOP_ACCEL=m # CONFIG_AD799X is not set # CONFIG_AD9467 is not set # CONFIG_ADE9000 is not set +CONFIG_APPLE_ORION_VBUS=y # CONFIG_CC10001_ADC is not set # CONFIG_ENVELOPE_DETECTOR is not set # CONFIG_GEHC_PMC_ADC is not set @@ -5946,6 +5949,7 @@ CONFIG_APPLE_AOP_GYRO=m # CONFIG_AL3000A is not set # CONFIG_AL3010 is not set # CONFIG_AL3320A is not set +CONFIG_AMS_CT709=m # CONFIG_APDS9160 is not set # CONFIG_APDS9300 is not set # CONFIG_APDS9306 is not set @@ -6264,6 +6268,7 @@ CONFIG_NVMEM_LAYOUTS=y # # Layout Types # +CONFIG_NVMEM_LAYOUT_BRCM_APPLE_OTP=m # CONFIG_NVMEM_LAYOUT_APPLE_SYSCFG is not set # CONFIG_NVMEM_LAYOUT_SL28_VPD is not set # CONFIG_NVMEM_LAYOUT_ONIE_TLV is not set diff --git a/kernel/configs/apple-4k/config b/kernel/configs/apple-4k/config index 44d8f77d..63916b46 100644 --- a/kernel/configs/apple-4k/config +++ b/kernel/configs/apple-4k/config @@ -2432,6 +2432,7 @@ CONFIG_TOUCHSCREEN_APPLE_Z2=m # CONFIG_TOUCHSCREEN_ZINITIX is not set # CONFIG_TOUCHSCREEN_HIMAX_HX83112B is not set CONFIG_INPUT_MISC=y +# CONFIG_INPUT_APPLE_J120_COVER is not set # CONFIG_INPUT_AD714X is not set # CONFIG_INPUT_ATMEL_CAPTOUCH is not set # CONFIG_INPUT_AW86927 is not set @@ -4400,6 +4401,7 @@ CONFIG_SND_SOC_GENERIC_DMAENGINE_PCM=y # CONFIG_SND_SOC_APPLE_MCA is not set CONFIG_SND_SOC_APPLE_S8000_MCA=m # CONFIG_SND_SOC_APPLE_T8010_PDM is not set +# CONFIG_SND_SOC_APPLE_J120_SPEAKERS is not set # end of Apple # @@ -5623,6 +5625,7 @@ CONFIG_IIO_CONSUMERS_PER_TRIGGER=2 # CONFIG_AD799X is not set # CONFIG_AD9467 is not set # CONFIG_ADE9000 is not set +# CONFIG_APPLE_ORION_VBUS is not set # CONFIG_CC10001_ADC is not set # CONFIG_ENVELOPE_DETECTOR is not set # CONFIG_GEHC_PMC_ADC is not set @@ -5943,6 +5946,7 @@ CONFIG_IIO_CONSUMERS_PER_TRIGGER=2 # CONFIG_AL3000A is not set # CONFIG_AL3010 is not set # CONFIG_AL3320A is not set +# CONFIG_AMS_CT709 is not set # CONFIG_APDS9160 is not set # CONFIG_APDS9300 is not set # CONFIG_APDS9306 is not set @@ -6260,6 +6264,7 @@ CONFIG_NVMEM_LAYOUTS=y # # Layout Types # +CONFIG_NVMEM_LAYOUT_BRCM_APPLE_OTP=m # CONFIG_NVMEM_LAYOUT_APPLE_SYSCFG is not set # CONFIG_NVMEM_LAYOUT_SL28_VPD is not set # CONFIG_NVMEM_LAYOUT_ONIE_TLV is not set diff --git a/kernel/patches/devices/t8011/0001-arm64-dts-apple-enable-J120-touch-Wi-Fi-and-accelero.patch b/kernel/patches/devices/t8011/0001-arm64-dts-apple-enable-J120-touch-Wi-Fi-and-accelero.patch new file mode 100644 index 00000000..5cf26b95 --- /dev/null +++ b/kernel/patches/devices/t8011/0001-arm64-dts-apple-enable-J120-touch-Wi-Fi-and-accelero.patch @@ -0,0 +1,339 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:57 +0100 +Subject: [PATCH] arm64: dts: apple: enable J120 touch, Wi-Fi and accelerometer + +Wire the J120 SPI3 touchscreen, August analog rail, Autumn WLAN enable and T8011 Wi-Fi-only PCIe/DART resources. Add AOP SRAM/mailbox resources and target 1 with the measured accelerometer mounting matrix. Use bootloader aliases for per-unit touch/WLAN/AOP data. Existing August backlight support is retained; charging, Bluetooth, storage, native display, GPU and video remain outside this change. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 243 ++++++++++++++++++++++ + arch/arm64/boot/dts/apple/t8011-pmgr.dtsi | 14 +- + arch/arm64/boot/dts/apple/t8011.dtsi | 26 +++ + 3 files changed, 277 insertions(+), 6 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 1b49bb5c9..0c6e23a13 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -13,4 +13,247 @@ + / { + compatible = "apple,j120", "apple,t8011", "apple,arm-platform"; + model = "Apple iPad Pro 2 (12.9-inch) (Wi-Fi)"; ++ ++ aliases { ++ aop = &aop; ++ touchscreen0 = &touchscreen; ++ wifi0 = &wifi; ++ }; ++ ++ /* WLAN REG_ON is driven by the Autumn PMIC. */ ++ wlan_vdd: regulator-wlan-vdd { ++ compatible = "regulator-fixed"; ++ regulator-name = "wlan-vdd"; ++ gpio = <&autumn_gpio 1 GPIO_ACTIVE_HIGH>; ++ enable-active-high; ++ status = "okay"; ++ }; ++ ++ /* Runtime ADT clock ID 0x134; the bootloader configures this source. */ ++ spi3_nclk: clock-spi3-nclk { ++ compatible = "fixed-clock"; ++ #clock-cells = <0>; ++ clock-frequency = <61538461>; ++ clock-output-names = "spi3-nclk"; ++ }; ++}; ++ ++&aop { ++ /* Runtime firmware region ends at the bootloader's RECFG reservation. */ ++ reg = <0x2 0x10800000 0x0 0x4000>, ++ <0x2 0x10000500 0x0 0x100>, ++ <0x2 0x10e00000 0x0 0xd8000>; ++ firmware-name = "apple/aop-ipad7.bin", "apple/aop-ipad7-ext.bin"; ++ apple,aop-target = <1>; ++ status = "okay"; ++}; ++ ++&aop_accel { ++ mount-matrix = "-1", "0", "0", ++ "0", "-1", "0", ++ "0", "0", "1"; ++}; ++ ++&{/soc} { ++ spi3: spi@20a08c000 { ++ compatible = "apple,t8011-spi", "apple,t8010-spi", "apple,spi"; ++ reg = <0x2 0x0a08c000 0x0 0x4000>; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ clocks = <&spi3_nclk>; ++ power-domains = <&ps_spi3>; ++ cs-gpios = <&pinctrl_ap 203 GPIO_ACTIVE_LOW>; ++ #address-cells = <1>; ++ #size-cells = <0>; ++ /* Preserve the bootloader's SPI pad mux. */ ++ status = "okay"; ++ ++ touchscreen: touchscreen@0 { ++ compatible = "apple,j120-touchscreen"; ++ reg = <0>; ++ spi-max-frequency = <24390243>; ++ spi-cpha; ++ spi-cpol; ++ interrupt-parent = <&pinctrl_ap>; ++ interrupts = <104 IRQ_TYPE_EDGE_FALLING>; ++ reset-gpios = <&pinctrl_ap 103 GPIO_ACTIVE_LOW>; ++ power-ldo-gpios = <&pinctrl_ap 120 GPIO_ACTIVE_HIGH>; ++ ana-supply = <&touch_analog>; ++ clocks = <&touchclk>; ++ pinctrl-names = "display-sync-active", "display-sync-inactive"; ++ pinctrl-0 = <&touch_sync_active>; ++ pinctrl-1 = <&touch_sync_inactive>; ++ firmware-name = "apple/j120-touch-K1F18,3.z2fw"; ++ touchscreen-size-x = <2048>; ++ touchscreen-size-y = <2732>; ++ /* Calibration is supplied per unit by m1n1 via touchscreen0. */ ++ status = "okay"; ++ }; ++ }; ++ ++ wlan_uart2: wlan-platform-control@20a0c8000 { ++ compatible = "apple,t8010-wlan-uart-provider"; ++ reg = <0x2 0x0a0c8000 0x0 0x4000>; ++ pinctrl-0 = <&wlan_uart2_pins>; ++ pinctrl-names = "default"; ++ power-domains = <&ps_uart2>; ++ status = "okay"; ++ }; ++ ++ pcie0_dart2: iommu@603008000 { ++ compatible = "apple,t8011-dart", "apple,s5l8960x-dart"; ++ reg = <0x6 0x03008000 0x0 0x4000>; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ power-domains = <&ps_pcie>; ++ #iommu-cells = <5>; ++ apple,error-reflector = /bits/ 64 <0x20fffc000>; ++ apple,fetch-config = <0x000e0303>; ++ apple,diag-config = <0x00000100>; ++ status = "okay"; ++ }; ++ ++ pcie0: pcie@610000000 { ++ compatible = "apple,j120-pcie", "apple,t8011-pcie"; ++ device_type = "pci"; ++ reg = <0x6 0x10000000 0x0 0x1000000>, ++ <0x6 0x00000000 0x0 0x8000>, ++ <0x6 0x00008000 0x0 0x4000>, ++ <0x6 0x0a000000 0x0 0x40000>, ++ <0x6 0x01000000 0x0 0x4000>, ++ <0x6 0x02000000 0x0 0x4000>, ++ <0x6 0x03000000 0x0 0x4000>, ++ <0x6 0x04000000 0x0 0x4000>, ++ <0x6 0x05000000 0x0 0x4000>, ++ <0x6 0x06000000 0x0 0x4000>; ++ reg-names = "config", "rc", "phy", "phy-ip", ++ "port0", "port1", "port2", "port3", "port4", "port5"; ++ ++ interrupt-parent = <&aic>; ++ interrupts = , ++ , ++ , ++ , ++ , ++ ; ++ interrupt-names = "port0", "port1", "port2", "port3", "port4", "port5"; ++ interrupt-controller; ++ #interrupt-cells = <1>; ++ ++ msi-controller; ++ msi-parent = <&pcie0>; ++ msi-ranges = <&aic AIC_IRQ 288 IRQ_TYPE_EDGE_RISING 32>; ++ apple,msi-doorbell = <0xbffff000>; ++ ++ /* Bus 1 serves the only enabled child, Wi-Fi on port 2. */ ++ iommu-map = <0x100 &pcie0_dart2 0 0x0 0x80000000 0x0 0x3ffff000 1>; ++ iommu-map-mask = <0xff00>; ++ ++ #address-cells = <3>; ++ #size-cells = <2>; ++ bus-range = <0 8>; ++ ranges = <0x43000000 0x6 0x20000000 0x6 0x20000000 0x1 0xa0000000>, ++ <0x02000000 0x0 0xc0000000 0x7 0xc0000000 0x0 0x40000000>; ++ ++ power-domains = <&ps_pcie>; ++ clocks = <&ps_pcie_aux>, <&ps_pcie_ref>; ++ clock-names = "aux", "ref"; ++ pinctrl-0 = <&wifi_clkreq>; ++ pinctrl-names = "default"; ++ status = "okay"; ++ ++ pci@2,0 { ++ compatible = "apple,j120-wifi-pcie-port", "pciclass,0604"; ++ device_type = "pci"; ++ reg = <0x1000 0x0 0x0 0x0 0x0>; ++ bus-range = <1 1>; ++ max-link-speed = <1>; ++ reset-gpios = <&pinctrl_ap 100 GPIO_ACTIVE_LOW>; ++ apple,msi-vector-range = <16 4>; ++ apple,manual-availability-iommu = <&pcie0_dart2 0>; ++ apple,endpoint-power-after-link-setup; ++ apple,wlan-uart = <&wlan_uart2>; ++ vdd-supply = <&wlan_vdd>; ++ ++ #address-cells = <3>; ++ #size-cells = <2>; ++ ranges; ++ ++ wifi: wifi@0,0 { ++ compatible = "pci14e4,43dc"; ++ reg = <0x10000 0x0 0x0 0x0 0x0>; ++ brcm,board-type = "apple,j120"; ++ ++ }; ++ }; ++ }; ++}; ++ ++&august_pmic { ++ touch_analog: regulator-touch-analog { ++ compatible = "apple,august-touch-analog-regulator"; ++ regulator-name = "touch-analog"; ++ }; ++}; ++ ++/* Touch reference clock; the consumer controls its gate. */ ++&pmgr { ++ touchclk: clock-controller@78000 { ++ compatible = "apple,t8011-touch-clock", "apple,t8010-touch-clock"; ++ reg = <0x78000 0x8>; ++ #clock-cells = <0>; ++ clocks = <&clkref>; ++ clock-output-names = "touchclk"; ++ clock-frequency = <24000000>; ++ status = "okay"; ++ }; ++}; ++ ++/* Native GPIO function modes: active peripheral 1, inactive GPIO output. */ ++&pinctrl_ap { ++ compatible = "apple,t8011-pinctrl", "apple,s8000-pinctrl", "apple,pinctrl"; ++ ++ wifi_clkreq: wifi-clkreq-pins { ++ pinmux = ; ++ }; ++ ++ wlan_uart2_pins: wlan-uart2-pins { ++ pinmux = , ++ ; ++ }; ++ ++ touch_sync_active: touch-sync-active-pins { ++ pinmux = , ++ , ++ ; ++ }; ++ ++ touch_sync_inactive: touch-sync-inactive-pins { ++ pinmux = , ++ , ++ ; ++ }; ++}; ++ ++/* Only the qualified WLAN enable GPIO is available to consumers. */ ++&autumn_pmic { ++ autumn_gpio: gpio { ++ compatible = "apple,d2401-pmic-gpio"; ++ gpio-controller; ++ #gpio-cells = <2>; ++ gpio-reserved-ranges = <0 1>, <2 18>; ++ status = "okay"; ++ }; ++}; ++ ++&aop_mbox { ++ status = "okay"; ++}; ++ ++&ps_pcie_aux { ++ status = "okay"; ++}; ++ ++&ps_pcie_ref { ++ status = "okay"; + }; +diff --git a/arch/arm64/boot/dts/apple/t8011-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8011-pmgr.dtsi +index 773b3fe7a..9e3ea29e2 100644 +--- a/arch/arm64/boot/dts/apple/t8011-pmgr.dtsi ++++ b/arch/arm64/boot/dts/apple/t8011-pmgr.dtsi +@@ -104,11 +104,12 @@ ps_pms: power-controller@80120 { + apple,always-on; /* Core device */ + }; + +- ps_pcie_ref: power-controller@80148 { ++ ps_pcie_ref: clock-controller@80148 { + compatible = "apple,t8010-pmgr-pwrstate", "apple,pmgr-pwrstate"; + reg = <0x80148 4>; +- #power-domain-cells = <0>; +- #reset-cells = <0>; ++ #clock-cells = <0>; ++ apple,clock-gate-only; ++ status = "disabled"; + label = "pcie_ref"; + }; + +@@ -632,11 +633,12 @@ ps_pcie: power-controller@80328 { + label = "pcie"; + }; + +- ps_pcie_aux: power-controller@80330 { ++ ps_pcie_aux: clock-controller@80330 { + compatible = "apple,t8010-pmgr-pwrstate", "apple,pmgr-pwrstate"; + reg = <0x80330 4>; +- #power-domain-cells = <0>; +- #reset-cells = <0>; ++ #clock-cells = <0>; ++ apple,clock-gate-only; ++ status = "disabled"; + label = "pcie_aux"; + }; + +diff --git a/arch/arm64/boot/dts/apple/t8011.dtsi b/arch/arm64/boot/dts/apple/t8011.dtsi +index 01c3a0d55..9fa6dae21 100644 +--- a/arch/arm64/boot/dts/apple/t8011.dtsi ++++ b/arch/arm64/boot/dts/apple/t8011.dtsi +@@ -364,6 +364,32 @@ pmgr_mini: power-management@210200000 { + reg = <0x2 0x10200000 0 0x84000>; + }; + ++ aop: aop@210800000 { ++ compatible = "apple,t8011-aop"; ++ reg = <0x2 0x10800000 0x0 0x4000>, ++ <0x2 0x10000500 0x0 0x100>, ++ <0x2 0x10e00000 0x0 0xa0000>; ++ reg-names = "akf", "control", "sram"; ++ mboxes = <&aop_mbox>; ++ mbox-names = "mbox"; ++ status = "disabled"; ++ ++ aop_accel: accel { ++ compatible = "apple,t8010-aop-accel"; ++ }; ++ }; ++ ++ aop_mbox: mbox@210804000 { ++ compatible = "apple,t8010-a7iop-mailbox"; ++ reg = <0x2 0x10804000 0x0 0x1000>; ++ interrupt-parent = <&aic>; ++ interrupts = , ++ ; ++ interrupt-names = "send-empty", "recv-not-empty"; ++ #mbox-cells = <0>; ++ status = "disabled"; ++ }; ++ + wdt: watchdog@2102b0000 { + compatible = "apple,t8010-wdt", "apple,wdt"; + reg = <0x2 0x102b0000 0x0 0x4000>; diff --git a/kernel/patches/devices/t8011/0002-arm64-dts-apple-enable-J120-Bluetooth-with-module-id.patch b/kernel/patches/devices/t8011/0002-arm64-dts-apple-enable-J120-Bluetooth-with-module-id.patch new file mode 100644 index 00000000..73538ada --- /dev/null +++ b/kernel/patches/devices/t8011/0002-arm64-dts-apple-enable-J120-Bluetooth-with-module-id.patch @@ -0,0 +1,91 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:41 +0100 +Subject: [PATCH] arm64: dts: apple: enable J120 Bluetooth with module identity + +Wire UART3, the shared Autumn enable GPIO, unit-address alias and Wi-Fi OTP vendor cell for the J120 module. Retain the cleaned touch, Wi-Fi and AOP board support. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 40 +++++++++++++++++++++++- + 1 file changed, 39 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 0c6e23a13..7e210104a 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -16,6 +16,7 @@ / { + + aliases { + aop = &aop; ++ bluetooth0 = &bluetooth; + touchscreen0 = &touchscreen; + wifi0 = &wifi; + }; +@@ -100,6 +101,32 @@ wlan_uart2: wlan-platform-control@20a0c8000 { + status = "okay"; + }; + ++ serial3: serial@20a0cc000 { ++ compatible = "apple,t8010-uart", "apple,s5l-uart"; ++ reg = <0x2 0x0a0cc000 0x0 0x4000>; ++ reg-io-width = <4>; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ clocks = <&clkref>, <&clkref>; ++ clock-names = "uart", "clk_uart_baud0"; ++ power-domains = <&ps_uart3>; ++ pinctrl-0 = <&bluetooth_uart3_pins>; ++ pinctrl-names = "default"; ++ uart-has-rtscts; ++ status = "okay"; ++ ++ bluetooth: bluetooth { ++ compatible = "apple,j120-bcm4355c0-bt", "brcm,bcm4355c0-bt"; ++ max-speed = <3000000>; ++ shutdown-gpios = <&autumn_gpio 0 GPIO_ACTIVE_HIGH>; ++ device-wakeup-gpios = <&pinctrl_ap 166 GPIO_ACTIVE_HIGH>; ++ nvmem-cells = <&bluetooth_module_vendor>; ++ nvmem-cell-names = "module-vendor"; ++ /* Filled from this unit's ADT by m1n1. */ ++ local-bd-address = [00 00 00 00 00 00]; ++ }; ++ }; ++ + pcie0_dart2: iommu@603008000 { + compatible = "apple,t8011-dart", "apple,s5l8960x-dart"; + reg = <0x6 0x03008000 0x0 0x4000>; +@@ -184,6 +211,11 @@ wifi: wifi@0,0 { + reg = <0x10000 0x0 0x0 0x0 0x0>; + brcm,board-type = "apple,j120"; + ++ nvmem-layout { ++ compatible = "brcm,apple-otp-layout"; ++ bluetooth_module_vendor: module-vendor {}; ++ }; ++ + }; + }; + }; +@@ -222,6 +254,12 @@ wlan_uart2_pins: wlan-uart2-pins { + ; + }; + ++ /* The native UART3 node describes TX and RTS. */ ++ bluetooth_uart3_pins: bluetooth-uart3-pins { ++ pinmux = , ++ ; ++ }; ++ + touch_sync_active: touch-sync-active-pins { + pinmux = , + , +@@ -241,7 +279,7 @@ autumn_gpio: gpio { + compatible = "apple,d2401-pmic-gpio"; + gpio-controller; + #gpio-cells = <2>; +- gpio-reserved-ranges = <0 1>, <2 18>; ++ gpio-reserved-ranges = <2 18>; + status = "okay"; + }; + }; diff --git a/kernel/patches/devices/t8011/0003-arm64-dts-apple-describe-the-disabled-J120-charging-.patch b/kernel/patches/devices/t8011/0003-arm64-dts-apple-describe-the-disabled-J120-charging-.patch new file mode 100644 index 00000000..92ad0e80 --- /dev/null +++ b/kernel/patches/devices/t8011/0003-arm64-dts-apple-describe-the-disabled-J120-charging-.patch @@ -0,0 +1,91 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:12 +0100 +Subject: [PATCH] arm64: dts: apple: describe the disabled J120 charging trial + +Keep the standard J120 tree intact and describe the separately selected charging trial, including the disabled PMIC nodes and USB role link. + +Assisted-by: LLM +--- + .../boot/dts/apple/t8011-j120-charging.dts | 72 +++++++++++++++++++ + 1 file changed, 72 insertions(+) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-charging.dts + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +new file mode 100644 +index 000000000..d4a099437 +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +@@ -0,0 +1,72 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* Local RAM experiment only. No automatic charger/event activation. */ ++#include "t8011-j120.dts" ++ ++&i2c0 { ++ tristar_test: port-controller@1a { ++ compatible = "nxp,cbtl1610"; ++ reg = <0x1a>; ++ }; ++ ++ d2355_test: pmic@75 { ++ compatible = "apple,d2355-pmic", "apple,i2c-pmic"; ++ reg = <0x75>; ++ #address-cells = <1>; ++ #size-cells = <1>; ++ status = "disabled"; ++ ++ d2355_events_test: events { ++ compatible = "apple,d2355-pmic-events"; ++ status = "disabled"; ++ interrupt-parent = <&pinctrl_ap>; ++ interrupts = <204 IRQ_TYPE_LEVEL_LOW>; ++ interrupt-controller; ++ #interrupt-cells = <2>; ++ #address-cells = <0>; ++ }; ++ ++ charger_test: charger@80 { ++ compatible = "apple,d2355-tristar-charger"; ++ reg = <0x80 0x0a>, <0x443 0x0c>, <0x4000 0x03>; ++ reg-names = "status", "control", "adc"; ++ interrupts-extended = <&d2355_events_test 80 IRQ_TYPE_EDGE_RISING>, ++ <&august_events_test 168 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 40 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 42 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 53 IRQ_TYPE_EDGE_RISING>; ++ apple,tristar = <&tristar_test>; ++ apple,adc-pmic = <&august_pmic>; ++ firmware-name = "apple/j120/usb-input-limit-calibration-hv.bin"; ++ /* Conservative RAM-test window, not vendor production limits. */ ++ apple,pack-limits = <150 350 3400000 4200000 (-2000000) 2000000>; ++ input-current-limit-microamp = <500000>; ++ status = "disabled"; ++ port { ++ charger_usb_test: endpoint { ++ remote-endpoint = <&usb_charger_test>; ++ }; ++ }; ++ }; ++ }; ++}; ++ ++&august_pmic { ++ august_events_test: events { ++ compatible = "apple,august-pmic-events"; ++ interrupt-parent = <&pinctrl_aop>; ++ interrupts = <26 IRQ_TYPE_LEVEL_LOW>; ++ interrupt-controller; ++ #interrupt-cells = <2>; ++ #address-cells = <0>; ++ status = "disabled"; ++ }; ++}; ++ ++&usb2dev { ++ usb-role-switch; ++ port { ++ usb_charger_test: endpoint { ++ remote-endpoint = <&charger_usb_test>; ++ }; ++ }; ++}; diff --git a/kernel/patches/devices/t8011/0004-arm64-dts-apple-wire-the-J120-charging-trial-battery.patch b/kernel/patches/devices/t8011/0004-arm64-dts-apple-wire-the-J120-charging-trial-battery.patch new file mode 100644 index 00000000..d09b6732 --- /dev/null +++ b/kernel/patches/devices/t8011/0004-arm64-dts-apple-wire-the-J120-charging-trial-battery.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:26:06 +0100 +Subject: [PATCH] arm64: dts: apple: wire the J120 charging trial battery gauge + +Assisted-by: LLM +--- + .../boot/dts/apple/t8011-j120-charging.dts | 1 + + arch/arm64/boot/dts/apple/t8011-j120-hdq.dtsi | 31 +++++++++++++++++++ + 2 files changed, 32 insertions(+) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-hdq.dtsi + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +index d4a099437..15acef055 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120-charging.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +@@ -1,6 +1,7 @@ + // SPDX-License-Identifier: GPL-2.0-only + /* Local RAM experiment only. No automatic charger/event activation. */ + #include "t8011-j120.dts" ++#include "t8011-j120-hdq.dtsi" + + &i2c0 { + tristar_test: port-controller@1a { +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-hdq.dtsi b/arch/arm64/boot/dts/apple/t8011-j120-hdq.dtsi +new file mode 100644 +index 000000000..467a55e2a +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-hdq.dtsi +@@ -0,0 +1,31 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++ ++&{/soc} { ++ serial5: serial@20a0d4000 { ++ compatible = "apple,t8010-uart", "apple,s5l-uart"; ++ reg = <0x2 0x0a0d4000 0x0 0x4000>; ++ reg-io-width = <4>; ++ interrupt-parent = <&aic>; ++ interrupts = <0 221 IRQ_TYPE_LEVEL_HIGH>; ++ clocks = <&clkref>, <&clkref>; ++ clock-names = "uart", "clk_uart_baud0"; ++ power-domains = <&ps_uart5>; ++ pinctrl-0 = <&battery_swi_pins>; ++ pinctrl-names = "default"; ++ status = "okay"; ++ ++ hdq { ++ compatible = "apple,j120-hdq-uart", "ti,hdq-uart"; ++ ++ fuel-gauge { ++ compatible = "apple,j120-bq27540", "ti,bq27540-hdq"; ++ }; ++ }; ++ }; ++}; ++ ++&pinctrl_ap { ++ battery_swi_pins: battery-swi-pins { ++ pinmux = ; ++ }; ++}; diff --git a/kernel/patches/devices/t8011/0005-arm64-dts-apple-describe-the-disabled-T8011-video-de.patch b/kernel/patches/devices/t8011/0005-arm64-dts-apple-describe-the-disabled-T8011-video-de.patch new file mode 100644 index 00000000..a3d3f2f4 --- /dev/null +++ b/kernel/patches/devices/t8011/0005-arm64-dts-apple-describe-the-disabled-T8011-video-de.patch @@ -0,0 +1,32 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 09:38:35 +0100 +Subject: [PATCH] arm64: dts: apple: describe the disabled T8011 video decoder + +Use the J120 device-tree register ranges, interrupt 169 and VDEC0 power domain. Leave activation for hardware qualification. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011.dtsi | 9 +++++++++ + 1 file changed, 9 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011.dtsi b/arch/arm64/boot/dts/apple/t8011.dtsi +index 9fa6dae21..d0800adfa 100644 +--- a/arch/arm64/boot/dts/apple/t8011.dtsi ++++ b/arch/arm64/boot/dts/apple/t8011.dtsi +@@ -225,6 +225,15 @@ i2c3: i2c@20a113000 { + status = "disabled"; + }; + ++ vxd: video-codec@208100000 { ++ compatible = "apple,t8011-vxd", "apple,t8010-vxd"; ++ reg = <0x2 0x08100000 0x0 0x30000>, ++ <0x2 0x08130000 0x0 0x1000>; ++ interrupts = ; ++ power-domains = <&ps_vdec0>; ++ status = "disabled"; ++ }; ++ + bus@20c000000 { + compatible = "apple,t8011-usb-complex", "simple-pm-bus"; + #address-cells = <2>; diff --git a/kernel/patches/devices/t8011/0006-arm64-dts-apple-enable-the-J120-video-decoder.patch b/kernel/patches/devices/t8011/0006-arm64-dts-apple-enable-the-J120-video-decoder.patch new file mode 100644 index 00000000..92ea318e --- /dev/null +++ b/kernel/patches/devices/t8011/0006-arm64-dts-apple-enable-the-J120-video-decoder.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 09:52:27 +0100 +Subject: [PATCH] arm64: dts: apple: enable the J120 video decoder + +The J120 VXD decoded 720p H.264 and HEVC through V4L2 stateless requests. Each of 96 frames per codec matched software decoding. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 7e210104a..f8131255b 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -295,3 +295,7 @@ &ps_pcie_aux { + &ps_pcie_ref { + status = "okay"; + }; ++ ++&vxd { ++ status = "okay"; ++}; diff --git a/kernel/patches/devices/t8011/0007-arm64-dts-apple-enable-J120-stereo-microphone-captur.patch b/kernel/patches/devices/t8011/0007-arm64-dts-apple-enable-J120-stereo-microphone-captur.patch new file mode 100644 index 00000000..b0e55f2c --- /dev/null +++ b/kernel/patches/devices/t8011/0007-arm64-dts-apple-enable-J120-stereo-microphone-captur.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:19:14 +0100 +Subject: [PATCH] arm64: dts: apple: enable J120 stereo microphone capture + +Describe SmartIO, the AOP audio clock, and the two-channel PDM capture path on J120. + +Assisted-by: LLM +--- + .../dts/apple/t8011-j120-microphones.dtsi | 59 +++++++++++++++++++ + arch/arm64/boot/dts/apple/t8011-j120.dts | 2 + + 2 files changed, 61 insertions(+) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-microphones.dtsi + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-microphones.dtsi b/arch/arm64/boot/dts/apple/t8011-j120-microphones.dtsi +new file mode 100644 +index 000000000..da7cf64c7 +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-microphones.dtsi +@@ -0,0 +1,59 @@ ++// SPDX-License-Identifier: GPL-2.0+ OR MIT ++ ++/ { ++ dmics: audio-codec { ++ compatible = "dmic-codec"; ++ #sound-dai-cells = <0>; ++ num-channels = <2>; ++ }; ++ ++ sound-microphones { ++ compatible = "simple-audio-card"; ++ simple-audio-card,name = "J120 Microphones"; ++ ++ simple-audio-card,cpu { ++ sound-dai = <&pdm>; ++ }; ++ ++ simple-audio-card,codec { ++ sound-dai = <&dmics>; ++ }; ++ }; ++ ++ soc { ++ sio: dma-controller@20ae00000 { ++ compatible = "apple,t8011-sio"; ++ reg = <0x2 0x0ae00000 0x0 0x10000>; ++ reg-names = "a7iop"; ++ interrupt-parent = <&aic>; ++ interrupts = , ++ , ++ , ++ ; ++ power-domains = <&ps_sio>; ++ firmware-name = "apple/t8011-smartio.bin"; ++ #dma-cells = <1>; ++ }; ++ ++ pdm: pdm@20a0b4000 { ++ compatible = "apple,t8011-pdm"; ++ reg = <0x2 0x0a0b4000 0x0 0x1000>, ++ <0x2 0x0a120000 0x0 0x4000>, ++ <0x2 0x0a124000 0x0 0x4000>; ++ reg-names = "pdm", "dec0", "dec1"; ++ interrupts = ; ++ clocks = <&aop_audio>; ++ power-domains = <&ps_hfd0>; ++ dmas = <&sio 0x5b>; ++ dma-names = "rx"; ++ #sound-dai-cells = <0>; ++ }; ++ }; ++}; ++ ++&aop { ++ aop_audio: aop_audio { ++ compatible = "apple,t8010-aop-audio"; ++ #clock-cells = <0>; ++ }; ++}; +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index f8131255b..d45a64cfa 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -299,3 +299,5 @@ &ps_pcie_ref { + &vxd { + status = "okay"; + }; ++ ++#include "t8011-j120-microphones.dtsi" diff --git a/kernel/patches/devices/t8011/0008-arm64-dts-apple-add-a-guarded-J120-1-A-charging-prof.patch b/kernel/patches/devices/t8011/0008-arm64-dts-apple-add-a-guarded-J120-1-A-charging-prof.patch new file mode 100644 index 00000000..af445455 --- /dev/null +++ b/kernel/patches/devices/t8011/0008-arm64-dts-apple-add-a-guarded-J120-1-A-charging-prof.patch @@ -0,0 +1,51 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 16:39:55 +0100 +Subject: [PATCH] arm64: dts: apple: add a guarded J120 1 A charging profile + +Provide a separate bootable device tree with the tested D2355 input limit, battery telemetry window and calibration requirement. Keep the base board available for recovery. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/Makefile | 1 + + .../boot/dts/apple/t8011-j120-charging-1a.dts | 19 +++++++++++++++++++ + 2 files changed, 20 insertions(+) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts + +diff --git a/arch/arm64/boot/dts/apple/Makefile b/arch/arm64/boot/dts/apple/Makefile +index 9fea43f76..ddf8d64ce 100644 +--- a/arch/arm64/boot/dts/apple/Makefile ++++ b/arch/arm64/boot/dts/apple/Makefile +@@ -43,6 +43,7 @@ dtb-$(CONFIG_ARCH_APPLE) += t8010-j72b.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8010-n112.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8011-j105a.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8011-j120.dtb ++dtb-$(CONFIG_ARCH_APPLE) += t8011-j120-charging-1a.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8011-j121.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8011-j207.dtb + dtb-$(CONFIG_ARCH_APPLE) += t8011-j208.dtb +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +new file mode 100644 +index 000000000..31ed853b0 +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +@@ -0,0 +1,19 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++#include "t8011-j120-charging.dts" ++ ++&d2355_test { ++ status = "okay"; ++}; ++ ++&d2355_events_test { ++ status = "okay"; ++}; ++ ++&august_events_test { ++ status = "okay"; ++}; ++ ++&charger_test { ++ input-current-limit-microamp = <1000000>; ++ status = "okay"; ++}; diff --git a/kernel/patches/devices/t8011/0009-arm64-dts-apple-enable-Tristar-in-the-J120-charging-.patch b/kernel/patches/devices/t8011/0009-arm64-dts-apple-enable-Tristar-in-the-J120-charging-.patch new file mode 100644 index 00000000..99012ba1 --- /dev/null +++ b/kernel/patches/devices/t8011/0009-arm64-dts-apple-enable-Tristar-in-the-J120-charging-.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 16:51:33 +0100 +Subject: [PATCH] arm64: dts: apple: enable Tristar in the J120 charging + profile + +The installed base explicitly disables the Tristar node. Enable it with the PMIC charger to satisfy the client dependency at probe. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +index 31ed853b0..88c4e61c8 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +@@ -1,6 +1,10 @@ + // SPDX-License-Identifier: GPL-2.0-only + #include "t8011-j120-charging.dts" + ++&tristar_test { ++ status = "okay"; ++}; ++ + &d2355_test { + status = "okay"; + }; diff --git a/kernel/patches/devices/t8011/0010-arm64-dts-apple-wire-the-J120-headphone-and-speaker-.patch b/kernel/patches/devices/t8011/0010-arm64-dts-apple-wire-the-J120-headphone-and-speaker-.patch new file mode 100644 index 00000000..317e8f6a --- /dev/null +++ b/kernel/patches/devices/t8011/0010-arm64-dts-apple-wire-the-J120-headphone-and-speaker-.patch @@ -0,0 +1,174 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:38:31 +0100 +Subject: [PATCH] arm64: dts: apple: wire the J120 headphone and speaker cards + +Assisted-by: LLM +--- + .../boot/dts/apple/t8011-j120-audio.dtsi | 87 +++++++++++++++++++ + .../boot/dts/apple/t8011-j120-speakers.dtsi | 51 +++++++++++ + arch/arm64/boot/dts/apple/t8011-j120.dts | 2 + + 3 files changed, 140 insertions(+) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-audio.dtsi + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-speakers.dtsi + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-audio.dtsi b/arch/arm64/boot/dts/apple/t8011-j120-audio.dtsi +new file mode 100644 +index 000000000..cfac5c476 +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-audio.dtsi +@@ -0,0 +1,87 @@ ++// SPDX-License-Identifier: GPL-2.0+ OR MIT ++ ++&i2c2 { ++ status = "okay"; ++ ++ jack_codec: audio-codec@48 { ++ compatible = "cirrus,cs42l83"; ++ reg = <0x48>; ++ reset-gpios = <&pinctrl_ap 67 GPIO_ACTIVE_HIGH>; ++ interrupts-extended = <&pinctrl_ap 50 IRQ_TYPE_LEVEL_LOW>; ++ #sound-dai-cells = <0>; ++ sound-name-prefix = "Jack"; ++ }; ++}; ++ ++/ { ++ nco_clkref: clock-ref-nco { ++ compatible = "fixed-clock"; ++ #clock-cells = <0>; ++ clock-frequency = <800000000>; ++ clock-output-names = "nco_ref"; ++ }; ++ ++ sound-headphones { ++ compatible = "simple-audio-card"; ++ simple-audio-card,name = "J120 Headphones"; ++ simple-audio-card,format = "i2s"; ++ simple-audio-card,bitclock-master = <&jack_cpu>; ++ simple-audio-card,frame-master = <&jack_cpu>; ++ simple-audio-card,widgets = "Headphone", "Headphones"; ++ simple-audio-card,routing = "Headphones", "Jack HP"; ++ simple-audio-card,pin-switches = "Headphones"; ++ simple-audio-card,aux-devs = <&jack_codec>; ++ ++ jack_cpu: simple-audio-card,cpu { ++ sound-dai = <&mca4>; ++ }; ++ ++ simple-audio-card,codec { ++ sound-dai = <&jack_codec>; ++ }; ++ }; ++ ++ soc { ++ i2s_switch: syscon@20a004000 { ++ compatible = "apple,t8010-i2s-switch", "syscon"; ++ reg = <0x2 0x0a004000 0x0 0x1000>; ++ }; ++ ++ aop_i2s_switch: syscon@210540000 { ++ compatible = "apple,t8010-aop-i2s-switch", "syscon"; ++ reg = <0x2 0x10540000 0x0 0x1000>; ++ }; ++ ++ aop_i2s_oe: syscon@210000600 { ++ compatible = "apple,t8010-aop-i2s-oe", "syscon"; ++ reg = <0x2 0x10000600 0x0 0x4>; ++ }; ++ ++ mca4: mca@20a0b0000 { ++ compatible = "apple,t8010-mca-i2s"; ++ reg = <0x2 0x0a0b0000 0x0 0x4000>, ++ <0x2 0x0a002010 0x0 0x4>; ++ reg-names = "mca", "mclk"; ++ interrupts = ; ++ power-domains = <&ps_mca4>; ++ clocks = <&nco 4>; ++ clock-names = "bitclk"; ++ dmas = <&sio 0x30>; ++ dma-names = "tx"; ++ #clock-cells = <0>; ++ clock-output-names = "mca4-mclk"; ++ #sound-dai-cells = <0>; ++ apple,i2s-switch = <&i2s_switch 4 4>; ++ apple,aop-i2s-route = <&aop_i2s_switch 0x0 0x00010101>, ++ <&aop_i2s_switch 0xc 0x00080818>, ++ <&aop_i2s_oe 0x0 0xf>; ++ }; ++ ++ nco: clock-controller@20e044000 { ++ compatible = "apple,t8010-nco"; ++ reg = <0x2 0x0e044000 0x0 0x14000>; ++ clocks = <&nco_clkref>; ++ #clock-cells = <1>; ++ }; ++ }; ++}; +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-speakers.dtsi b/arch/arm64/boot/dts/apple/t8011-j120-speakers.dtsi +new file mode 100644 +index 000000000..b421dfc2a +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-speakers.dtsi +@@ -0,0 +1,51 @@ ++// SPDX-License-Identifier: GPL-2.0+ OR MIT ++ ++&i2c1 { ++ status = "okay"; ++}; ++ ++&{/soc} { ++ ++ mca2: mca@20a0a8000 { ++ compatible = "apple,t8011-mca"; ++ 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>, <&sio 0x2d>; ++ dma-names = "tx", "rx"; ++ #clock-cells = <0>; ++ clock-output-names = "mca2-mclk"; ++ #sound-dai-cells = <0>; ++ apple,i2s-switch = <&i2s_switch 2 2>; ++ }; ++}; ++ ++&{/} { ++ speaker_amps: speaker-transport-codec { ++ compatible = "apple,j120-speaker-amplifiers"; ++ reset-gpios = <&pinctrl_ap 119 GPIO_ACTIVE_LOW>; ++ speaker-buses = <&i2c1>, <&i2c2>; ++ #sound-dai-cells = <0>; ++ }; ++ ++ sound-speaker-transport { ++ compatible = "simple-audio-card"; ++ simple-audio-card,name = "J120 Speakers"; ++ simple-audio-card,format = "dsp_a"; ++ simple-audio-card,bitclock-master = <&speaker_cpu>; ++ simple-audio-card,frame-master = <&speaker_cpu>; ++ ++ speaker_cpu: simple-audio-card,cpu { ++ sound-dai = <&mca2>; ++ }; ++ ++ simple-audio-card,codec { ++ sound-dai = <&speaker_amps>; ++ }; ++ }; ++}; +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index d45a64cfa..6ace619fa 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -301,3 +301,5 @@ &vxd { + }; + + #include "t8011-j120-microphones.dtsi" ++#include "t8011-j120-audio.dtsi" ++#include "t8011-j120-speakers.dtsi" diff --git a/kernel/patches/devices/t8011/0011-arm64-dts-apple-describe-the-J120-internal-storage-p.patch b/kernel/patches/devices/t8011/0011-arm64-dts-apple-describe-the-J120-internal-storage-p.patch new file mode 100644 index 00000000..c77391f1 --- /dev/null +++ b/kernel/patches/devices/t8011/0011-arm64-dts-apple-describe-the-J120-internal-storage-p.patch @@ -0,0 +1,153 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:42:34 +0100 +Subject: [PATCH] arm64: dts: apple: describe the J120 internal storage port + and DART + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 67 ++++++++++++++++++++---- + 1 file changed, 58 insertions(+), 9 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 6ace619fa..6a9e491c5 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -15,12 +15,25 @@ / { + model = "Apple iPad Pro 2 (12.9-inch) (Wi-Fi)"; + + aliases { ++ nvme-hmb = &nvme_hmb; + aop = &aop; + bluetooth0 = &bluetooth; + touchscreen0 = &touchscreen; + wifi0 = &wifi; + }; + ++ reserved-memory { ++ #address-cells = <2>; ++ #size-cells = <2>; ++ ranges; ++ ++ /* m1n1 fills this from this boot's ADT sart-region. */ ++ nvme_hmb: nvme-hmb@0 { ++ reg = <0 0 0 0>; ++ no-map; ++ }; ++ }; ++ + /* WLAN REG_ON is driven by the Autumn PMIC. */ + wlan_vdd: regulator-wlan-vdd { + compatible = "regulator-fixed"; +@@ -127,6 +140,19 @@ bluetooth: bluetooth { + }; + }; + ++ pcie0_dart0: iommu@601008000 { ++ compatible = "apple,t8011-dart", "apple,s5l8960x-dart"; ++ reg = <0x6 0x01008000 0x0 0x4000>; ++ interrupt-parent = <&aic>; ++ interrupts = ; ++ power-domains = <&ps_pcie>; ++ #iommu-cells = <5>; ++ apple,error-reflector = /bits/ 64 <0x20fffc000>; ++ apple,fetch-config = <0x000e0303>; ++ apple,diag-config = <0x00000100>; ++ status = "okay"; ++ }; ++ + pcie0_dart2: iommu@603008000 { + compatible = "apple,t8011-dart", "apple,s5l8960x-dart"; + reg = <0x6 0x03008000 0x0 0x4000>; +@@ -152,9 +178,10 @@ pcie0: pcie@610000000 { + <0x6 0x03000000 0x0 0x4000>, + <0x6 0x04000000 0x0 0x4000>, + <0x6 0x05000000 0x0 0x4000>, +- <0x6 0x06000000 0x0 0x4000>; ++ <0x6 0x06000000 0x0 0x4000>, ++ <0x6 0x01004000 0x0 0x4000>; + reg-names = "config", "rc", "phy", "phy-ip", +- "port0", "port1", "port2", "port3", "port4", "port5"; ++ "port0", "port1", "port2", "port3", "port4", "port5", "nvmmu"; + + interrupt-parent = <&aic>; + interrupts = , +@@ -162,8 +189,9 @@ pcie0: pcie@610000000 { + , + , + , +- ; +- interrupt-names = "port0", "port1", "port2", "port3", "port4", "port5"; ++ , ++ ; ++ interrupt-names = "port0", "port1", "port2", "port3", "port4", "port5", "nvmmu"; + interrupt-controller; + #interrupt-cells = <1>; + +@@ -171,9 +199,12 @@ pcie0: pcie@610000000 { + msi-parent = <&pcie0>; + msi-ranges = <&aic AIC_IRQ 288 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-doorbell = <0xbffff000>; ++ apple,nvme-hmb = <&nvme_hmb>; ++ apple,nvmmu-iova = <0xbc000000>; + +- /* Bus 1 serves the only enabled child, Wi-Fi on port 2. */ +- iommu-map = <0x100 &pcie0_dart2 0 0x0 0x80000000 0x0 0x3ffff000 1>; ++ /* Storage is bus 1; Wi-Fi is bus 2, each behind its own DART. */ ++ iommu-map = <0x100 &pcie0_dart0 0 0x0 0x80000000 0x0 0x3c000000 1>, ++ <0x200 &pcie0_dart2 0 0x0 0x80000000 0x0 0x3ffff000 1>; + iommu-map-mask = <0xff00>; + + #address-cells = <3>; +@@ -185,15 +216,29 @@ pcie0: pcie@610000000 { + power-domains = <&ps_pcie>; + clocks = <&ps_pcie_aux>, <&ps_pcie_ref>; + clock-names = "aux", "ref"; +- pinctrl-0 = <&wifi_clkreq>; ++ pinctrl-0 = <&storage_clkreq>, <&wifi_clkreq>; + pinctrl-names = "default"; + status = "okay"; + ++ storage_port: pci@0,0 { ++ compatible = "pciclass,0604"; ++ device_type = "pci"; ++ reg = <0 0 0 0 0>; ++ bus-range = <1 1>; ++ max-link-speed = <3>; ++ reset-gpios = <&pinctrl_ap 10 GPIO_ACTIVE_LOW>; ++ apple,msi-vector-range = <0 8>; ++ apple,manual-availability-iommu = <&pcie0_dart0 0>; ++ #address-cells = <3>; ++ #size-cells = <2>; ++ ranges; ++ }; ++ + pci@2,0 { + compatible = "apple,j120-wifi-pcie-port", "pciclass,0604"; + device_type = "pci"; + reg = <0x1000 0x0 0x0 0x0 0x0>; +- bus-range = <1 1>; ++ bus-range = <2 2>; + max-link-speed = <1>; + reset-gpios = <&pinctrl_ap 100 GPIO_ACTIVE_LOW>; + apple,msi-vector-range = <16 4>; +@@ -208,7 +253,7 @@ pci@2,0 { + + wifi: wifi@0,0 { + compatible = "pci14e4,43dc"; +- reg = <0x10000 0x0 0x0 0x0 0x0>; ++ reg = <0x20000 0x0 0x0 0x0 0x0>; + brcm,board-type = "apple,j120"; + + nvmem-layout { +@@ -245,6 +290,10 @@ touchclk: clock-controller@78000 { + &pinctrl_ap { + compatible = "apple,t8011-pinctrl", "apple,s8000-pinctrl", "apple,pinctrl"; + ++ storage_clkreq: storage-clkreq-pins { ++ pinmux = ; ++ }; ++ + wifi_clkreq: wifi-clkreq-pins { + pinmux = ; + }; diff --git a/kernel/patches/devices/t8011/0012-arm64-dts-apple-use-guarded-charging-on-J120.patch b/kernel/patches/devices/t8011/0012-arm64-dts-apple-use-guarded-charging-on-J120.patch new file mode 100644 index 00000000..1a4602a9 --- /dev/null +++ b/kernel/patches/devices/t8011/0012-arm64-dts-apple-use-guarded-charging-on-J120.patch @@ -0,0 +1,221 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:47:43 +0100 +Subject: [PATCH] arm64: dts: apple: use guarded charging on J120 + +Assisted-by: LLM +--- + .../boot/dts/apple/t8011-j120-charger.dtsi | 71 +++++++++++++++++ + .../boot/dts/apple/t8011-j120-charging-1a.dts | 23 +----- + .../boot/dts/apple/t8011-j120-charging.dts | 76 ++++--------------- + arch/arm64/boot/dts/apple/t8011-j120.dts | 2 + + 4 files changed, 87 insertions(+), 85 deletions(-) + create mode 100644 arch/arm64/boot/dts/apple/t8011-j120-charger.dtsi + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charger.dtsi b/arch/arm64/boot/dts/apple/t8011-j120-charger.dtsi +new file mode 100644 +index 000000000..09aff4ae8 +--- /dev/null ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charger.dtsi +@@ -0,0 +1,71 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++ ++&i2c0 { ++ tristar_test: port-controller@1a { ++ compatible = "nxp,cbtl1610"; ++ reg = <0x1a>; ++ status = "okay"; ++ }; ++ ++ d2355_test: pmic@75 { ++ compatible = "apple,d2355-pmic", "apple,i2c-pmic"; ++ reg = <0x75>; ++ #address-cells = <1>; ++ #size-cells = <1>; ++ status = "okay"; ++ ++ d2355_events_test: events { ++ compatible = "apple,d2355-pmic-events"; ++ status = "okay"; ++ interrupt-parent = <&pinctrl_ap>; ++ interrupts = <204 IRQ_TYPE_LEVEL_LOW>; ++ interrupt-controller; ++ #interrupt-cells = <2>; ++ #address-cells = <0>; ++ }; ++ ++ charger_test: charger@80 { ++ compatible = "apple,d2355-tristar-charger"; ++ reg = <0x80 0x0a>, <0x443 0x0c>, <0x4000 0x03>; ++ reg-names = "status", "control", "adc"; ++ interrupts-extended = <&d2355_events_test 80 IRQ_TYPE_EDGE_RISING>, ++ <&august_events_test 168 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 40 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 42 IRQ_TYPE_EDGE_RISING>, ++ <&d2355_events_test 53 IRQ_TYPE_EDGE_RISING>; ++ apple,tristar = <&tristar_test>; ++ apple,adc-pmic = <&august_pmic>; ++ firmware-name = "apple/j120/usb-input-limit-calibration-hv.bin"; ++ /* Conservative RAM-test window, not vendor production limits. */ ++ apple,pack-limits = <150 350 3400000 4200000 (-2000000) 2000000>; ++ input-current-limit-microamp = <1000000>; ++ status = "okay"; ++ port { ++ charger_usb_test: endpoint { ++ remote-endpoint = <&usb_charger_test>; ++ }; ++ }; ++ }; ++ }; ++}; ++ ++&august_pmic { ++ august_events_test: events { ++ compatible = "apple,august-pmic-events"; ++ interrupt-parent = <&pinctrl_aop>; ++ interrupts = <26 IRQ_TYPE_LEVEL_LOW>; ++ interrupt-controller; ++ #interrupt-cells = <2>; ++ #address-cells = <0>; ++ status = "okay"; ++ }; ++}; ++ ++&usb2dev { ++ usb-role-switch; ++ port { ++ usb_charger_test: endpoint { ++ remote-endpoint = <&charger_usb_test>; ++ }; ++ }; ++}; +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +index 88c4e61c8..4197b9a45 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging-1a.dts +@@ -1,23 +1,2 @@ + // SPDX-License-Identifier: GPL-2.0-only +-#include "t8011-j120-charging.dts" +- +-&tristar_test { +- status = "okay"; +-}; +- +-&d2355_test { +- status = "okay"; +-}; +- +-&d2355_events_test { +- status = "okay"; +-}; +- +-&august_events_test { +- status = "okay"; +-}; +- +-&charger_test { +- input-current-limit-microamp = <1000000>; +- status = "okay"; +-}; ++#include "t8011-j120.dts" +diff --git a/arch/arm64/boot/dts/apple/t8011-j120-charging.dts b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +index 15acef055..6a4f73bd9 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120-charging.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120-charging.dts +@@ -1,73 +1,23 @@ + // SPDX-License-Identifier: GPL-2.0-only +-/* Local RAM experiment only. No automatic charger/event activation. */ + #include "t8011-j120.dts" +-#include "t8011-j120-hdq.dtsi" + +-&i2c0 { +- tristar_test: port-controller@1a { +- compatible = "nxp,cbtl1610"; +- reg = <0x1a>; +- }; +- +- d2355_test: pmic@75 { +- compatible = "apple,d2355-pmic", "apple,i2c-pmic"; +- reg = <0x75>; +- #address-cells = <1>; +- #size-cells = <1>; +- status = "disabled"; ++&tristar_test { ++ /delete-property/ status; ++}; + +- d2355_events_test: events { +- compatible = "apple,d2355-pmic-events"; +- status = "disabled"; +- interrupt-parent = <&pinctrl_ap>; +- interrupts = <204 IRQ_TYPE_LEVEL_LOW>; +- interrupt-controller; +- #interrupt-cells = <2>; +- #address-cells = <0>; +- }; ++&d2355_test { ++ status = "disabled"; ++}; + +- charger_test: charger@80 { +- compatible = "apple,d2355-tristar-charger"; +- reg = <0x80 0x0a>, <0x443 0x0c>, <0x4000 0x03>; +- reg-names = "status", "control", "adc"; +- interrupts-extended = <&d2355_events_test 80 IRQ_TYPE_EDGE_RISING>, +- <&august_events_test 168 IRQ_TYPE_EDGE_RISING>, +- <&d2355_events_test 40 IRQ_TYPE_EDGE_RISING>, +- <&d2355_events_test 42 IRQ_TYPE_EDGE_RISING>, +- <&d2355_events_test 53 IRQ_TYPE_EDGE_RISING>; +- apple,tristar = <&tristar_test>; +- apple,adc-pmic = <&august_pmic>; +- firmware-name = "apple/j120/usb-input-limit-calibration-hv.bin"; +- /* Conservative RAM-test window, not vendor production limits. */ +- apple,pack-limits = <150 350 3400000 4200000 (-2000000) 2000000>; +- input-current-limit-microamp = <500000>; +- status = "disabled"; +- port { +- charger_usb_test: endpoint { +- remote-endpoint = <&usb_charger_test>; +- }; +- }; +- }; +- }; ++&d2355_events_test { ++ status = "disabled"; + }; + +-&august_pmic { +- august_events_test: events { +- compatible = "apple,august-pmic-events"; +- interrupt-parent = <&pinctrl_aop>; +- interrupts = <26 IRQ_TYPE_LEVEL_LOW>; +- interrupt-controller; +- #interrupt-cells = <2>; +- #address-cells = <0>; +- status = "disabled"; +- }; ++&august_events_test { ++ status = "disabled"; + }; + +-&usb2dev { +- usb-role-switch; +- port { +- usb_charger_test: endpoint { +- remote-endpoint = <&charger_usb_test>; +- }; +- }; ++&charger_test { ++ input-current-limit-microamp = <500000>; ++ status = "disabled"; + }; +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 6a9e491c5..290298e6d 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -352,3 +352,5 @@ &vxd { + #include "t8011-j120-microphones.dtsi" + #include "t8011-j120-audio.dtsi" + #include "t8011-j120-speakers.dtsi" ++#include "t8011-j120-hdq.dtsi" ++#include "t8011-j120-charger.dtsi" diff --git a/kernel/patches/devices/t8011/0013-arm64-dts-apple-describe-both-J120-ambient-light-sen.patch b/kernel/patches/devices/t8011/0013-arm64-dts-apple-describe-both-J120-ambient-light-sen.patch new file mode 100644 index 00000000..298c18ae --- /dev/null +++ b/kernel/patches/devices/t8011/0013-arm64-dts-apple-describe-both-J120-ambient-light-sen.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:15:12 +0100 +Subject: [PATCH] arm64: dts: apple: describe both J120 ambient light sensors + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 14 ++++++++++++++ + 1 file changed, 14 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 290298e6d..805602626 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -345,6 +345,20 @@ &ps_pcie_ref { + status = "okay"; + }; + ++&i2c3 { ++ status = "okay"; ++ ++ light-sensor@29 { ++ compatible = "apple,ct709"; ++ reg = <0x29>; ++ }; ++ ++ light-sensor@39 { ++ compatible = "apple,ct709"; ++ reg = <0x39>; ++ }; ++}; ++ + &vxd { + status = "okay"; + }; diff --git a/kernel/patches/devices/t8011/0014-arm64-dts-apple-describe-the-J120-AOP-gyro-and-press.patch b/kernel/patches/devices/t8011/0014-arm64-dts-apple-describe-the-J120-AOP-gyro-and-press.patch new file mode 100644 index 00000000..a8acfa03 --- /dev/null +++ b/kernel/patches/devices/t8011/0014-arm64-dts-apple-describe-the-J120-AOP-gyro-and-press.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:17:06 +0100 +Subject: [PATCH] arm64: dts: apple: describe the J120 AOP gyro and pressure + services + +Provide the child nodes used for AOP service matching and per-unit calibration handoff. The J120 gyro has an identity orientation matrix. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 11 +++++++++++ + 1 file changed, 11 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 805602626..99abcdcfd 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -60,6 +60,17 @@ &aop { + firmware-name = "apple/aop-ipad7.bin", "apple/aop-ipad7-ext.bin"; + apple,aop-target = <1>; + status = "okay"; ++ ++ gyro { ++ compatible = "apple,t8010-aop-gyro"; ++ mount-matrix = "1", "0", "0", ++ "0", "1", "0", ++ "0", "0", "1"; ++ }; ++ ++ pressure { ++ compatible = "apple,t8010-aop-pressure"; ++ }; + }; + + &aop_accel { diff --git a/kernel/patches/devices/t8011/0015-arm64-dts-apple-identify-the-J120-ambient-calibratio.patch b/kernel/patches/devices/t8011/0015-arm64-dts-apple-identify-the-J120-ambient-calibratio.patch new file mode 100644 index 00000000..852c4a12 --- /dev/null +++ b/kernel/patches/devices/t8011/0015-arm64-dts-apple-identify-the-J120-ambient-calibratio.patch @@ -0,0 +1,35 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 00:44:34 +0100 +Subject: [PATCH] arm64: dts: apple: identify the J120 ambient calibration + target + +Orchard uses als0 to pass the per-unit factory light calibration to Linux. Point it at the CT709 at address 0x29. The shared factory record contains the calibration for both sensor orientations. + +Assisted-by: LLM +Signed-off-by: tom +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 99abcdcfd..426c16b41 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -15,6 +15,7 @@ / { + model = "Apple iPad Pro 2 (12.9-inch) (Wi-Fi)"; + + aliases { ++ als0 = &als0; + nvme-hmb = &nvme_hmb; + aop = &aop; + bluetooth0 = &bluetooth; +@@ -359,7 +360,7 @@ &ps_pcie_ref { + &i2c3 { + status = "okay"; + +- light-sensor@29 { ++ als0: light-sensor@29 { + compatible = "apple,ct709"; + reg = <0x29>; + }; diff --git a/kernel/patches/devices/t8011/0016-arm64-dts-apple-correct-the-J120-accelerometer-mount.patch b/kernel/patches/devices/t8011/0016-arm64-dts-apple-correct-the-J120-accelerometer-mount.patch new file mode 100644 index 00000000..9e0f7553 --- /dev/null +++ b/kernel/patches/devices/t8011/0016-arm64-dts-apple-correct-the-J120-accelerometer-mount.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 11:27:00 +0100 +Subject: [PATCH] arm64: dts: apple: correct the J120 accelerometer mount + matrix + +With the Home button down, the accelerometer reports negative Y. Inverting the two in-plane axes makes SensorProxy report bottom-up and rotates the display by 180 degrees. Use the identity matrix, verified via a runtime override in portrait and landscape. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 426c16b41..c413f9169 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -75,8 +75,8 @@ pressure { + }; + + &aop_accel { +- mount-matrix = "-1", "0", "0", +- "0", "-1", "0", ++ mount-matrix = "1", "0", "0", ++ "0", "1", "0", + "0", "0", "1"; + }; + diff --git a/kernel/patches/devices/t8011/0017-arm64-dts-apple-describe-the-J120-boot-scanout-contr.patch b/kernel/patches/devices/t8011/0017-arm64-dts-apple-describe-the-J120-boot-scanout-contr.patch new file mode 100644 index 00000000..ad55fcc4 --- /dev/null +++ b/kernel/patches/devices/t8011/0017-arm64-dts-apple-describe-the-J120-boot-scanout-contr.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 16:07:49 +0100 +Subject: [PATCH] arm64: dts: apple: describe the J120 boot scanout controller + +Reuse the firmware framebuffer while switching H9G between the verified two and four subframe cadences. Keep the boot cadence on other hardware and restore it on driver removal. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index c413f9169..b57d4daf5 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -80,7 +80,17 @@ &aop_accel { + "0", "0", "1"; + }; + ++&framebuffer0 { ++ display = <&j120_display>; ++}; ++ + &{/soc} { ++ j120_display: display-controller@206000000 { ++ compatible = "apple,t8011-h9g-display"; ++ reg = <0x2 0x06000000 0x0 0xe0000>; ++ status = "disabled"; ++ }; ++ + spi3: spi@20a08c000 { + compatible = "apple,t8011-spi", "apple,t8010-spi", "apple,spi"; + reg = <0x2 0x0a08c000 0x0 0x4000>; diff --git a/kernel/patches/devices/t8011/0018-arm64-dts-apple-describe-the-J120-Lightning-VBUS-ADC.patch b/kernel/patches/devices/t8011/0018-arm64-dts-apple-describe-the-J120-Lightning-VBUS-ADC.patch new file mode 100644 index 00000000..07dca822 --- /dev/null +++ b/kernel/patches/devices/t8011/0018-arm64-dts-apple-describe-the-J120-Lightning-VBUS-ADC.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 16:40:47 +0100 +Subject: [PATCH] arm64: dts: apple: describe the J120 Lightning VBUS ADC + +Enable read-only input voltage telemetry on J120. + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index b57d4daf5..877718c65 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -367,6 +367,13 @@ &ps_pcie_ref { + status = "okay"; + }; + ++&i2c1 { ++ adc@13 { ++ compatible = "apple,orion-bellatrix-vbus"; ++ reg = <0x13>; ++ }; ++}; ++ + &i2c3 { + status = "okay"; + diff --git a/kernel/patches/devices/t8011/0019-arm64-dts-apple-use-the-guarded-1.5-A-charging-profi.patch b/kernel/patches/devices/t8011/0019-arm64-dts-apple-use-the-guarded-1.5-A-charging-profi.patch new file mode 100644 index 00000000..0af3fe34 --- /dev/null +++ b/kernel/patches/devices/t8011/0019-arm64-dts-apple-use-the-guarded-1.5-A-charging-profi.patch @@ -0,0 +1,36 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 12:45:19 +0100 +Subject: [PATCH] arm64: dts: apple: use the guarded 1.5 A charging profile on + J120 + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 877718c65..776307625 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -368,8 +368,9 @@ &ps_pcie_ref { + }; + + &i2c1 { +- adc@13 { ++ orion_vbus: adc@13 { + compatible = "apple,orion-bellatrix-vbus"; ++ #io-channel-cells = <1>; + reg = <0x13>; + }; + }; +@@ -397,3 +398,9 @@ &vxd { + #include "t8011-j120-speakers.dtsi" + #include "t8011-j120-hdq.dtsi" + #include "t8011-j120-charger.dtsi" ++ ++&charger_test { ++ io-channels = <&orion_vbus 0>; ++ io-channel-names = "vbus"; ++ input-current-limit-microamp = <1500000>; ++}; diff --git a/kernel/patches/devices/t8011/0020-arm64-dts-apple-add-the-J120-magnetic-cover-switch.patch b/kernel/patches/devices/t8011/0020-arm64-dts-apple-add-the-J120-magnetic-cover-switch.patch new file mode 100644 index 00000000..596f650e --- /dev/null +++ b/kernel/patches/devices/t8011/0020-arm64-dts-apple-add-the-J120-magnetic-cover-switch.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 02:35:33 +0100 +Subject: [PATCH] arm64: dts: apple: add the J120 magnetic cover switch + +Assisted-by: LLM +--- + arch/arm64/boot/dts/apple/t8011-j120.dts | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/arch/arm64/boot/dts/apple/t8011-j120.dts b/arch/arm64/boot/dts/apple/t8011-j120.dts +index 776307625..2336e7d74 100644 +--- a/arch/arm64/boot/dts/apple/t8011-j120.dts ++++ b/arch/arm64/boot/dts/apple/t8011-j120.dts +@@ -289,6 +289,10 @@ nvmem-layout { + }; + + &august_pmic { ++ cover-switch { ++ compatible = "apple,j120-cover-switch"; ++ }; ++ + touch_analog: regulator-touch-analog { + compatible = "apple,august-touch-analog-regulator"; + regulator-name = "touch-analog"; diff --git a/kernel/patches/drivers/bluetooth/0008-dt-bindings-net-bluetooth-describe-the-J120-BCM4355-.patch b/kernel/patches/drivers/bluetooth/0008-dt-bindings-net-bluetooth-describe-the-J120-BCM4355-.patch new file mode 100644 index 00000000..23745e41 --- /dev/null +++ b/kernel/patches/drivers/bluetooth/0008-dt-bindings-net-bluetooth-describe-the-J120-BCM4355-.patch @@ -0,0 +1,80 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:32 +0100 +Subject: [PATCH] dt-bindings: net: bluetooth: describe the J120 BCM4355 C0 + module + +Describe the module vendor NVMEM cell and bootloader-provided unit address/calibration required by J120 Apple radio setup. Do not embed per-unit data in the board sources. + +Assisted-by: LLM +--- + .../net/bluetooth/brcm,bluetooth.yaml | 39 ++++++++++++++++++- + 1 file changed, 38 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml b/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml +index 793857de0..3875b42de 100644 +--- a/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml ++++ b/Documentation/devicetree/bindings/net/bluetooth/brcm,bluetooth.yaml +@@ -19,7 +19,9 @@ properties: + - const: brcm,bcm4355c0-bt + - const: brcm,bcm4345c5 + - items: +- - const: apple,j71t-bcm4355c0-bt ++ - enum: ++ - apple,j71t-bcm4355c0-bt ++ - apple,j120-bcm4355c0-bt + - const: brcm,bcm4355c0-bt + - items: + - enum: +@@ -103,6 +105,29 @@ properties: + vddio-supply: + description: phandle to regulator supply for VDDIO + ++ local-bd-address: ++ $ref: /schemas/types.yaml#/definitions/uint8-array ++ minItems: 6 ++ maxItems: 6 ++ description: Device Bluetooth address in least significant byte first order ++ ++ brcm,taurus-cal-blob: ++ $ref: /schemas/types.yaml#/definitions/uint8-array ++ minItems: 1 ++ maxItems: 15073280 ++ description: ++ Per-device Taurus calibration supplied by the bootloader. Do not put ++ calibration bytes in board source files. The transport supports at most ++ 65536 blocks of 230 bytes. ++ ++ nvmem-cells: ++ maxItems: 1 ++ description: Vendor identity of the shared Wi-Fi/Bluetooth module. ++ ++ nvmem-cell-names: ++ items: ++ - const: module-vendor ++ + brcm,bt-pcm-int-params: + $ref: /schemas/types.yaml#/definitions/uint8-array + minItems: 5 +@@ -145,9 +170,21 @@ required: + + dependencies: + brcm,requires-autobaud-mode: [ shutdown-gpios ] ++ nvmem-cells: [ nvmem-cell-names ] ++ nvmem-cell-names: [ nvmem-cells ] + + allOf: + - $ref: /schemas/serial/serial-peripheral-props.yaml# ++ - if: ++ properties: ++ compatible: ++ contains: ++ const: apple,j120-bcm4355c0-bt ++ then: ++ required: ++ - nvmem-cells ++ - nvmem-cell-names ++ - local-bd-address + - if: + not: + properties: diff --git a/kernel/patches/drivers/bluetooth/0009-Bluetooth-btbcm-support-pinned-Apple-firmware-and-ra.patch b/kernel/patches/drivers/bluetooth/0009-Bluetooth-btbcm-support-pinned-Apple-firmware-and-ra.patch new file mode 100644 index 00000000..bf7593e9 --- /dev/null +++ b/kernel/patches/drivers/bluetooth/0009-Bluetooth-btbcm-support-pinned-Apple-firmware-and-ra.patch @@ -0,0 +1,231 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:38 +0100 +Subject: [PATCH] Bluetooth: btbcm: support pinned Apple firmware and radio + setup + +Add exact-name firmware loading without generic fallback and the native Taurus calibration and single-command regulatory transports. Preserve existing initialization for callers without a module-specific image. + +Assisted-by: LLM +--- + drivers/bluetooth/btbcm.c | 122 +++++++++++++++++++++++++++++++++++--- + drivers/bluetooth/btbcm.h | 24 ++++++++ + 2 files changed, 137 insertions(+), 9 deletions(-) + +diff --git a/drivers/bluetooth/btbcm.c b/drivers/bluetooth/btbcm.c +index baba42563..9832b0530 100644 +--- a/drivers/bluetooth/btbcm.c ++++ b/drivers/bluetooth/btbcm.c +@@ -172,6 +172,75 @@ int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) + } + EXPORT_SYMBOL_GPL(btbcm_set_bdaddr); + ++/* Taurus calibration uses fixed-size, zero-padded vendor command packets. */ ++int btbcm_send_calibration(struct hci_dev *hdev, const void *data, size_t size) ++{ ++ struct { ++ u8 type; ++ __le16 blocks_left; ++ u8 data[230]; ++ } __packed cmd; ++ const u8 *cursor = data; ++ size_t blocks, len; ++ struct sk_buff *skb; ++ int err; ++ ++ if (!data || !size) ++ return -EINVAL; ++ ++ /* The remaining-block count on the wire has only 16 bits. */ ++ if (size > sizeof(cmd.data) * ((size_t)U16_MAX + 1)) ++ return -E2BIG; ++ ++ blocks = DIV_ROUND_UP(size, sizeof(cmd.data)); ++ while (blocks) { ++ len = min(size, sizeof(cmd.data)); ++ memset(&cmd, 0, sizeof(cmd)); ++ cmd.type = 3; ++ cmd.blocks_left = cpu_to_le16(--blocks); ++ memcpy(cmd.data, cursor, len); ++ ++ skb = __hci_cmd_sync(hdev, 0xfd97, sizeof(cmd), &cmd, ++ HCI_INIT_TIMEOUT); ++ if (IS_ERR(skb)) ++ return PTR_ERR(skb); ++ ++ /* J120 firmware also returns a zero-extended status reply. */ ++ if ((skb->len != 1 && skb->len != 2) || ++ skb->data[0] || (skb->len == 2 && skb->data[1])) { ++ err = (skb->len == 1 || skb->len == 2) && skb->data[0] ? ++ -bt_to_errno(skb->data[0]) : -EIO; ++ kfree_skb(skb); ++ return err; ++ } ++ kfree_skb(skb); ++ cursor += len; ++ size -= len; ++ } ++ ++ return 0; ++} ++EXPORT_SYMBOL_GPL(btbcm_send_calibration); ++ ++/* Legacy controllers accept the regulatory table in one vendor command. */ ++int btbcm_send_regulatory(struct hci_dev *hdev, const void *data, size_t size) ++{ ++ struct sk_buff *skb; ++ int err = 0; ++ ++ if (!data || !size || size > U8_MAX) ++ return -EINVAL; ++ ++ skb = __hci_cmd_sync(hdev, 0xfd98, size, data, HCI_INIT_TIMEOUT); ++ if (IS_ERR(skb)) ++ return PTR_ERR(skb); ++ if (skb->len != 1 || skb->data[0]) ++ err = skb->len == 1 ? -bt_to_errno(skb->data[0]) : -EIO; ++ kfree_skb(skb); ++ return err; ++} ++EXPORT_SYMBOL_GPL(btbcm_send_regulatory); ++ + int btbcm_read_pcm_int_params(struct hci_dev *hdev, + struct bcm_set_pcm_int_params *params) + { +@@ -575,13 +644,26 @@ static const char *btbcm_get_board_name(struct device *dev) + #endif + } + +-/* +- * @variant names the module a board's controller sits on, when the board +- * comes with modules from several vendors that each need their own Patchram. +- * Its file names are tried before the generic ones. +- */ +-int btbcm_initialize_variant(struct hci_dev *hdev, bool *fw_load_done, +- bool use_autobaud_mode, const char *variant) ++static int btbcm_load_firmware(struct hci_dev *hdev, const char *name, ++ bool *fw_load_done) ++{ ++ const struct firmware *fw; ++ int err; ++ ++ err = firmware_request_nowarn(&fw, name, &hdev->dev); ++ if (err) ++ return err; ++ err = btbcm_patchram(hdev, fw); ++ release_firmware(fw); ++ if (err) ++ return err; ++ *fw_load_done = true; ++ return 0; ++} ++ ++static int __btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done, ++ bool use_autobaud_mode, const char *variant, ++ const char *firmware_name) + { + u16 subver, rev, pid, vid; + struct sk_buff *skb; +@@ -646,6 +728,10 @@ int btbcm_initialize_variant(struct hci_dev *hdev, bool *fw_load_done, + if (*fw_load_done) + return 0; + ++ /* An explicitly selected module image must never use generic fallback. */ ++ if (firmware_name) ++ return btbcm_load_firmware(hdev, firmware_name, fw_load_done); ++ + if (hdev->bus == HCI_USB) { + /* Read USB Product Info */ + skb = btbcm_read_usb_product(hdev); +@@ -722,15 +808,33 @@ int btbcm_initialize_variant(struct hci_dev *hdev, bool *fw_load_done, + kfree(fw_name); + return 0; + } ++/* ++ * Variant names distinguish board modules that need different Patchram. ++ * Try their firmware names before the generic ones. ++ */ ++int btbcm_initialize_variant(struct hci_dev *hdev, bool *fw_load_done, ++ bool use_autobaud_mode, const char *variant) ++{ ++ return __btbcm_initialize(hdev, fw_load_done, use_autobaud_mode, variant, NULL); ++} + EXPORT_SYMBOL_GPL(btbcm_initialize_variant); + + int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode) + { +- return btbcm_initialize_variant(hdev, fw_load_done, use_autobaud_mode, +- NULL); ++ return __btbcm_initialize(hdev, fw_load_done, use_autobaud_mode, NULL, NULL); + } + EXPORT_SYMBOL_GPL(btbcm_initialize); + ++int btbcm_initialize_with_firmware(struct hci_dev *hdev, bool *fw_load_done, ++ bool use_autobaud_mode, const char *firmware_name) ++{ ++ if (!firmware_name || !*firmware_name) ++ return -EINVAL; ++ return __btbcm_initialize(hdev, fw_load_done, use_autobaud_mode, NULL, ++ firmware_name); ++} ++EXPORT_SYMBOL_GPL(btbcm_initialize_with_firmware); ++ + int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode) + { + int err; +diff --git a/drivers/bluetooth/btbcm.h b/drivers/bluetooth/btbcm.h +index b902c2c32..943b85673 100644 +--- a/drivers/bluetooth/btbcm.h ++++ b/drivers/bluetooth/btbcm.h +@@ -55,6 +55,8 @@ int btbcm_check_bdaddr(struct hci_dev *hdev); + int btbcm_reset(struct hci_dev *hdev); + int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr); + int btbcm_patchram(struct hci_dev *hdev, const struct firmware *fw); ++int btbcm_send_calibration(struct hci_dev *hdev, const void *data, size_t size); ++int btbcm_send_regulatory(struct hci_dev *hdev, const void *data, size_t size); + int btbcm_read_pcm_int_params(struct hci_dev *hdev, + struct bcm_set_pcm_int_params *params); + int btbcm_write_pcm_int_params(struct hci_dev *hdev, +@@ -66,6 +68,8 @@ int btbcm_setup_apple(struct hci_dev *hdev); + int btbcm_initialize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode); + int btbcm_initialize_variant(struct hci_dev *hdev, bool *fw_load_done, + bool use_autobaud_mode, const char *variant); ++int btbcm_initialize_with_firmware(struct hci_dev *hdev, bool *fw_load_done, ++ bool use_autobaud_mode, const char *firmware_name); + int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode); + + #else +@@ -85,6 +89,18 @@ static inline int btbcm_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) + return -EOPNOTSUPP; + } + ++static inline int btbcm_send_regulatory(struct hci_dev *hdev, ++ const void *data, size_t size) ++{ ++ return -EOPNOTSUPP; ++} ++ ++static inline int btbcm_send_calibration(struct hci_dev *hdev, ++ const void *data, size_t size) ++{ ++ return -EOPNOTSUPP; ++} ++ + static inline int btbcm_read_pcm_int_params(struct hci_dev *hdev, + struct bcm_set_pcm_int_params *params) + { +@@ -125,6 +141,14 @@ static inline int btbcm_initialize_variant(struct hci_dev *hdev, + return 0; + } + ++static inline int btbcm_initialize_with_firmware(struct hci_dev *hdev, ++ bool *fw_load_done, ++ bool use_autobaud_mode, ++ const char *firmware_name) ++{ ++ return -EOPNOTSUPP; ++} ++ + static inline int btbcm_finalize(struct hci_dev *hdev, bool *fw_load_done, bool use_autobaud_mode) + { + return 0; diff --git a/kernel/patches/drivers/bluetooth/0010-Bluetooth-hci_bcm-add-the-J120-JoyA-C0-setup-path.patch b/kernel/patches/drivers/bluetooth/0010-Bluetooth-hci_bcm-add-the-J120-JoyA-C0-setup-path.patch new file mode 100644 index 00000000..1f2866d3 --- /dev/null +++ b/kernel/patches/drivers/bluetooth/0010-Bluetooth-hci_bcm-add-the-J120-JoyA-C0-setup-path.patch @@ -0,0 +1,426 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:39 +0100 +Subject: [PATCH] Bluetooth: hci_bcm: add the J120 JoyA C0 setup path + +Select module firmware from OTP before acquiring power, validate bootloader unit data and regulatory inputs, and reuse H4 setup with the J120 baud and advertising-report quirks. Restore the unit address before calibration and power down across HCI closes, repeating setup on reopen. Keyboard and audio profiles require full-image qualification. + +Assisted-by: LLM +--- + drivers/bluetooth/hci_bcm.c | 284 +++++++++++++++++++++++++++++++++++- + 1 file changed, 280 insertions(+), 4 deletions(-) + +diff --git a/drivers/bluetooth/hci_bcm.c b/drivers/bluetooth/hci_bcm.c +index 45682e4d4..1df0f83de 100644 +--- a/drivers/bluetooth/hci_bcm.c ++++ b/drivers/bluetooth/hci_bcm.c +@@ -26,6 +26,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -57,9 +58,13 @@ + * @set_baudrate_before_patch: switch to operational speed before Patchram + * @broken_read_transmit_power: controller cannot read LE min/max TX power + * @fixup_le_adv_report_evt_type: controller uses reserved advertising bits ++ * @use_bdaddr_property: require the unit address supplied by firmware ++ * @power_off_on_close: power-cycle and repeat setup across HCI opens + * @no_uart_clock_set: UART clock set command for >3Mbps mode is unavailable + * @max_autobaud_speed: max baudrate supported by device in autobaud mode + * @max_speed: max baudrate supported ++ * @firmware_prefix: module firmware prefix requiring the OTP vendor cell ++ * @regulatory_size: native Apple table length, or zero without Taurus setup + */ + struct bcm_device_data { + bool no_early_set_baudrate; +@@ -68,9 +73,21 @@ struct bcm_device_data { + bool set_baudrate_before_patch; + bool broken_read_transmit_power; + bool fixup_le_adv_report_evt_type; ++ bool use_bdaddr_property; ++ bool power_off_on_close; + bool no_uart_clock_set; + u32 max_autobaud_speed; + u32 max_speed; ++ const char *firmware_prefix; ++ size_t regulatory_size; ++}; ++ ++struct bcm_apple_data { ++ bdaddr_t bdaddr; ++ const u8 *calibration; ++ size_t calibration_size; ++ const u8 *regulatory; ++ size_t regulatory_size; + }; + + /** +@@ -116,12 +133,18 @@ struct bcm_device_data { + * @set_baudrate_before_patch: switch to operational speed before Patchram + * @broken_read_transmit_power: controller cannot read LE min/max TX power + * @fixup_le_adv_report_evt_type: controller uses reserved advertising bits ++ * @use_bdaddr_property: require the unit address supplied by firmware + * @no_uart_clock_set: UART clock set command for >3Mbps mode is unavailable + * @pcm_int_params: keep the initial PCM configuration + * @use_autobaud_mode: start Bluetooth device in autobaud mode + * @max_autobaud_speed: max baudrate supported by device in autobaud mode + * @fw_variant: module vendor whose Patchram this controller needs, if the + * board comes with modules from several vendors ++ * @firmware_name: exact module image selected from the OTP vendor ++ * @apple_data: validated unit identity and Apple radio setup data ++ * @power_off_on_close: power-cycle the controller across HCI opens ++ * @hci_open: original serdev HCI open callback ++ * @hci_close: original serdev HCI close callback + */ + struct bcm_device { + /* Must be the first member, hci_serdev.c expects this. */ +@@ -163,8 +186,14 @@ struct bcm_device { + bool set_baudrate_before_patch; + bool broken_read_transmit_power; + bool fixup_le_adv_report_evt_type; ++ bool use_bdaddr_property; ++ bool power_off_on_close; ++ int (*hci_open)(struct hci_dev *hdev); ++ int (*hci_close)(struct hci_dev *hdev); + bool no_uart_clock_set; + bool use_autobaud_mode; ++ const char *firmware_name; ++ struct bcm_apple_data *apple_data; + u8 pcm_int_params[5]; + u32 max_autobaud_speed; + const char *fw_variant; +@@ -620,6 +649,109 @@ static int bcm_flush(struct hci_uart *hu) + return 0; + } + ++/* HCI serializes open/close; the serdev parent outlives HCI unregister. */ ++static int bcm_apple_hci_open(struct hci_dev *hdev) ++{ ++ struct hci_uart *hu = hci_get_drvdata(hdev); ++ struct bcm_data *bcm = hu->priv; ++ struct bcm_device *dev = bcm->dev; ++ int err, close_err; ++ ++ err = dev->hci_open(hdev); ++ if (err) ++ return err; ++ ++ mutex_lock(&bcm_device_lock); ++ err = dev->res_enabled ? 0 : bcm_gpio_set_power(dev, true); ++ mutex_unlock(&bcm_device_lock); ++ if (err) { ++ close_err = dev->hci_close(hdev); ++ if (close_err) ++ bt_dev_err(hdev, "UART close after power failure: %d", ++ close_err); ++ } ++ ++ return err; ++} ++ ++static int bcm_apple_hci_close(struct hci_dev *hdev) ++{ ++ struct hci_uart *hu = hci_get_drvdata(hdev); ++ struct bcm_data *bcm = hu->priv; ++ struct bcm_device *dev = bcm->dev; ++ int err; ++ ++ err = dev->hci_close(hdev); ++ if (err) ++ return err; ++ ++ mutex_lock(&bcm_device_lock); ++ err = dev->res_enabled ? bcm_gpio_set_power(dev, false) : 0; ++ mutex_unlock(&bcm_device_lock); ++ if (err) ++ bt_dev_err(hdev, "Failed to power off controller: %d", err); ++ ++ return err; ++} ++ ++static void bcm_apple_install_lifecycle(struct hci_uart *hu) ++{ ++ struct bcm_data *bcm = hu->priv; ++ struct bcm_device *dev = bcm->dev; ++ struct hci_dev *hdev = hu->hdev; ++ ++ if (!hu->serdev || !dev || !dev->power_off_on_close || dev->hci_open) ++ return; ++ ++ dev->hci_open = hdev->open; ++ dev->hci_close = hdev->close; ++ hdev->open = bcm_apple_hci_open; ++ hdev->close = bcm_apple_hci_close; ++ hci_set_quirk(hdev, HCI_QUIRK_NON_PERSISTENT_SETUP); ++} ++ ++static int bcm_setup_apple_radio(struct hci_dev *hdev, ++ const struct bcm_apple_data *radio) ++{ ++ struct hci_rp_read_bd_addr *reply; ++ struct sk_buff *skb; ++ int err; ++ ++ err = btbcm_set_bdaddr(hdev, &radio->bdaddr); ++ if (err) ++ return err; ++ skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL, ++ HCI_INIT_TIMEOUT); ++ if (IS_ERR(skb)) ++ return PTR_ERR(skb); ++ if (skb->len != sizeof(*reply)) { ++ err = -EIO; ++ } else { ++ reply = (void *)skb->data; ++ if (reply->status) ++ err = -bt_to_errno(reply->status); ++ else if (bacmp(&reply->bdaddr, &radio->bdaddr)) ++ err = -EADDRNOTAVAIL; ++ } ++ kfree_skb(skb); ++ if (err) ++ return err; ++ err = btbcm_send_calibration(hdev, radio->calibration, ++ radio->calibration_size); ++ if (err) ++ return err; ++ err = btbcm_send_regulatory(hdev, radio->regulatory, ++ radio->regulatory_size); ++ if (err) ++ return err; ++ ++ /* Address repair is complete; do not repeat it after radio calibration. */ ++ bacpy(&hdev->public_addr, &radio->bdaddr); ++ hci_clear_quirk(hdev, HCI_QUIRK_INVALID_BDADDR); ++ hci_clear_quirk(hdev, HCI_QUIRK_USE_BDADDR_PROPERTY); ++ return 0; ++} ++ + static int bcm_setup(struct hci_uart *hu) + { + struct bcm_data *bcm = hu->priv; +@@ -632,6 +764,7 @@ static int bcm_setup(struct hci_uart *hu) + bt_dev_dbg(hu->hdev, "hu %p", hu); + + hu->hdev->set_diag = bcm_set_diag; ++ bcm_apple_install_lifecycle(hu); + hu->hdev->set_bdaddr = btbcm_set_bdaddr; + + if (bcm->dev && bcm->dev->broken_read_transmit_power) +@@ -642,6 +775,13 @@ static int bcm_setup(struct hci_uart *hu) + hci_set_quirk(hu->hdev, + HCI_QUIRK_FIXUP_LE_ADV_REPORT_EVT_TYPE); + ++ if (bcm->dev && bcm->dev->use_bdaddr_property) ++ hci_set_quirk(hu->hdev, HCI_QUIRK_USE_BDADDR_PROPERTY); ++ ++ /* Match the tested H4 policy: no core reset after unit radio setup. */ ++ if (bcm->dev && bcm->dev->apple_data) ++ hci_set_quirk(hu->hdev, HCI_QUIRK_RESET_ON_CLOSE); ++ + baudrate_set_before_patch = bcm->dev && + bcm->dev->set_baudrate_before_patch && + bcm->dev->oper_speed; +@@ -658,9 +798,13 @@ static int bcm_setup(struct hci_uart *hu) + host_set_baudrate(hu, speed); + } + +- err = btbcm_initialize_variant(hu->hdev, &fw_load_done, +- use_autobaud_mode, +- bcm->dev ? bcm->dev->fw_variant : NULL); ++ if (bcm->dev && bcm->dev->firmware_name) ++ err = btbcm_initialize_with_firmware(hu->hdev, &fw_load_done, ++ use_autobaud_mode, bcm->dev->firmware_name); ++ else ++ err = btbcm_initialize_variant(hu->hdev, &fw_load_done, ++ use_autobaud_mode, ++ bcm->dev ? bcm->dev->fw_variant : NULL); + if (err) + return err; + +@@ -708,6 +852,12 @@ static int bcm_setup(struct hci_uart *hu) + if (err) + return err; + ++ if (bcm->dev && bcm->dev->apple_data) { ++ err = bcm_setup_apple_radio(hu->hdev, bcm->dev->apple_data); ++ if (err) ++ return err; ++ } ++ + /* Some devices ship with the controller default address. + * Allow the bootloader to set a valid address through the + * device tree. +@@ -1631,6 +1781,99 @@ static struct platform_driver bcm_driver = { + }, + }; + ++static int bcm_prepare_apple_data(struct bcm_device *bdev, size_t regulatory_size) ++{ ++ struct device *dev = bdev->dev; ++ struct bcm_apple_data *radio; ++ const struct firmware *fw; ++ u8 *calibration; ++ char *name; ++ size_t length; ++ int count, err; ++ ++ if (!bdev->firmware_name || !regulatory_size || regulatory_size > U8_MAX) ++ return -EINVAL; ++ radio = devm_kzalloc(dev, sizeof(*radio), GFP_KERNEL); ++ if (!radio) ++ return -ENOMEM; ++ count = device_property_count_u8(dev, "local-bd-address"); ++ if (count != sizeof(radio->bdaddr)) ++ return -EINVAL; ++ err = device_property_read_u8_array(dev, "local-bd-address", ++ radio->bdaddr.b, sizeof(radio->bdaddr)); ++ if (err) ++ return err; ++ /* local-bd-address is in Bluetooth (least significant byte first) order. */ ++ if (!bacmp(&radio->bdaddr, BDADDR_ANY) || (radio->bdaddr.b[5] & 1)) ++ return -EINVAL; ++ count = device_property_count_u8(dev, "brcm,taurus-cal-blob"); ++ if (count <= 0) ++ return count ? count : -EINVAL; ++ if ((size_t)count > 230 * ((size_t)U16_MAX + 1)) ++ return -E2BIG; ++ calibration = devm_kmalloc(dev, count, GFP_KERNEL); ++ if (!calibration) ++ return -ENOMEM; ++ err = device_property_read_u8_array(dev, "brcm,taurus-cal-blob", ++ calibration, count); ++ if (err) ++ return err; ++ if (count >= 7 && !memcmp(calibration, "syscfg/", 7)) ++ return -EINVAL; ++ radio->calibration = calibration; ++ radio->calibration_size = count; ++ length = strlen(bdev->firmware_name); ++ if (length < 4 || strcmp(bdev->firmware_name + length - 4, ".hcd")) ++ return -EINVAL; ++ name = kasprintf(GFP_KERNEL, "%.*s.regulatory", (int)length - 4, ++ bdev->firmware_name); ++ if (!name) ++ return -ENOMEM; ++ err = firmware_request_nowarn(&fw, name, dev); ++ kfree(name); ++ if (err) ++ return err; ++ if (fw->size != regulatory_size) { ++ err = -EINVAL; ++ } else { ++ radio->regulatory = devm_kmemdup(dev, fw->data, fw->size, GFP_KERNEL); ++ radio->regulatory_size = fw->size; ++ if (!radio->regulatory) ++ err = -ENOMEM; ++ } ++ release_firmware(fw); ++ if (err) ++ return err; ++ bdev->apple_data = radio; ++ return 0; ++} ++ ++static int bcm_select_module_firmware(struct bcm_device *bdev, const char *prefix) ++{ ++ struct nvmem_cell *cell; ++ char *vendor; ++ size_t size; ++ ++ cell = nvmem_cell_get(bdev->dev, "module-vendor"); ++ if (IS_ERR(cell)) ++ return dev_err_probe(bdev->dev, PTR_ERR(cell), ++ "Failed to get module vendor cell\n"); ++ vendor = nvmem_cell_read(cell, &size); ++ nvmem_cell_put(cell); ++ if (IS_ERR(vendor)) ++ return dev_err_probe(bdev->dev, PTR_ERR(vendor), ++ "Failed to read module vendor\n"); ++ if (size != 1 || (*vendor != 'u' && *vendor != 'm')) { ++ kfree(vendor); ++ return dev_err_probe(bdev->dev, -EINVAL, ++ "Unsupported module vendor\n"); ++ } ++ bdev->firmware_name = devm_kasprintf(bdev->dev, GFP_KERNEL, ++ "%s-%c.hcd", prefix, *vendor); ++ kfree(vendor); ++ return bdev->firmware_name ? 0 : -ENOMEM; ++} ++ + static int bcm_serdev_probe(struct serdev_device *serdev) + { + struct bcm_device *bcmdev; +@@ -1648,6 +1891,21 @@ static int bcm_serdev_probe(struct serdev_device *serdev) + bcmdev->serdev_hu.serdev = serdev; + serdev_device_set_drvdata(serdev, bcmdev); + ++ /* Resolve the shared module identity before acquiring power resources. */ ++ data = device_get_match_data(bcmdev->dev); ++ if (data && data->firmware_prefix) { ++ err = bcm_select_module_firmware(bcmdev, data->firmware_prefix); ++ if (err) ++ return err; ++ } ++ ++ if (data && data->regulatory_size) { ++ err = bcm_prepare_apple_data(bcmdev, data->regulatory_size); ++ if (err) ++ return dev_err_probe(bcmdev->dev, err, ++ "Failed to prepare Apple radio data\n"); ++ } ++ + /* Initialize routing field to an unused value */ + bcmdev->pcm_int_params[0] = 0xff; + +@@ -1672,7 +1930,6 @@ static int bcm_serdev_probe(struct serdev_device *serdev) + if (err) + dev_err(&serdev->dev, "Failed to power down\n"); + +- data = device_get_match_data(bcmdev->dev); + if (data) { + bcmdev->max_autobaud_speed = data->max_autobaud_speed; + bcmdev->no_early_set_baudrate = data->no_early_set_baudrate; +@@ -1684,6 +1941,8 @@ static int bcm_serdev_probe(struct serdev_device *serdev) + data->broken_read_transmit_power; + bcmdev->fixup_le_adv_report_evt_type = + data->fixup_le_adv_report_evt_type; ++ bcmdev->use_bdaddr_property = data->use_bdaddr_property; ++ bcmdev->power_off_on_close = data->power_off_on_close; + bcmdev->no_uart_clock_set = data->no_uart_clock_set; + if (data->max_speed && bcmdev->oper_speed > data->max_speed) + bcmdev->oper_speed = data->max_speed; +@@ -1717,6 +1976,21 @@ static struct bcm_device_data bcm4355_j71b_device_data = { + .fixup_le_adv_report_evt_type = true, + }; + ++/* ++ * J120 JoyA C0 uses the native wake-before-power and early-baud sequence. ++ * Its firmware also reports reserved bits in LE advertising event types. ++ */ ++static struct bcm_device_data bcm4355_j120_device_data = { ++ .power_off_on_close = true, ++ .no_early_set_baudrate = true, ++ .wake_before_power_cycle = true, ++ .set_baudrate_before_patch = true, ++ .fixup_le_adv_report_evt_type = true, ++ .use_bdaddr_property = true, ++ .firmware_prefix = "brcm/BCM.apple,j120", ++ .regulatory_size = 210, ++}; ++ + static struct bcm_device_data bcm4355_j172_device_data = { + .no_early_set_baudrate = true, + .wake_before_power_cycle = true, +@@ -1753,6 +2027,8 @@ static const struct of_device_id bcm_bluetooth_of_match[] = { + .data = &bcm4355_j172_device_data }, + /* The iPad Air 2 BCM4350C2 runs the plain sequence at 115,200 baud. */ + { .compatible = "apple,j81-bcm4350c2-bt" }, ++ { .compatible = "apple,j120-bcm4355c0-bt", ++ .data = &bcm4355_j120_device_data }, + { .compatible = "apple,j71b-bcm4355c1-bt", + .data = &bcm4355_j71b_device_data }, + { .compatible = "apple,j172-bcm4355c1-bt", diff --git a/kernel/patches/drivers/clk/0010-dt-bindings-clock-describe-the-T8011-touch-clock.patch b/kernel/patches/drivers/clk/0010-dt-bindings-clock-describe-the-T8011-touch-clock.patch new file mode 100644 index 00000000..815c20e9 --- /dev/null +++ b/kernel/patches/drivers/clk/0010-dt-bindings-clock-describe-the-T8011-touch-clock.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:50 +0100 +Subject: [PATCH] dt-bindings: clock: describe the T8011 touch clock + +T8011 reuses the T8010 gate/divider at PMGR offset 0x78000. Describe its compatible with the existing T8010 fallback. + +Assisted-by: LLM +--- + .../devicetree/bindings/clock/apple,t8010-touch-clock.yaml | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/clock/apple,t8010-touch-clock.yaml b/Documentation/devicetree/bindings/clock/apple,t8010-touch-clock.yaml +index f49ce6014..277d877b4 100644 +--- a/Documentation/devicetree/bindings/clock/apple,t8010-touch-clock.yaml ++++ b/Documentation/devicetree/bindings/clock/apple,t8010-touch-clock.yaml +@@ -14,7 +14,8 @@ description: + reference clock consumed by the touchscreen controller. The S8000 PMGR has + the same block at the same offset; the iPad 5 N1 touchscreen runs it at + 32768 Hz. So has the T8015 PMGR, whose iPhone X touchscreen runs it at +- 24 MHz. ++ 24 MHz. The T8011 PMGR also uses this block at offset 0x78000; its J120 ++ touchscreen runs from the 24 MHz reference. + + properties: + compatible: +@@ -25,6 +26,7 @@ properties: + - items: + - enum: + - apple,s8000-touch-clock ++ - apple,t8011-touch-clock + - apple,t8015-touch-clock + - const: apple,t8010-touch-clock + diff --git a/kernel/patches/drivers/clk/0011-clk-apple-support-the-T8011-AOP-microphone-clock-com.patch b/kernel/patches/drivers/clk/0011-clk-apple-support-the-T8011-AOP-microphone-clock-com.patch new file mode 100644 index 00000000..37fa54ef --- /dev/null +++ b/kernel/patches/drivers/clk/0011-clk-apple-support-the-T8011-AOP-microphone-clock-com.patch @@ -0,0 +1,129 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:08:43 +0100 +Subject: [PATCH] clk: apple: support the T8011 AOP microphone clock command + +T8011 firmware handles the audio clock command directly and rejects the wrapped PDM attach used by T8010. On T8011 send an EPIC prefix followed by the clock source and rate in Hz. Select the 24 MHz crystal for the J120 2.4 MHz PDM clock and disable the source when the clock is released. + +Assisted-by: LLM +--- + drivers/clk/clk-apple-aop-audio.c | 52 ++++++++++++++++++++++++------- + 1 file changed, 40 insertions(+), 12 deletions(-) + +diff --git a/drivers/clk/clk-apple-aop-audio.c b/drivers/clk/clk-apple-aop-audio.c +index 06164fe0a..af9be5162 100644 +--- a/drivers/clk/clk-apple-aop-audio.c ++++ b/drivers/clk/clk-apple-aop-audio.c +@@ -10,7 +10,8 @@ + * word to halt it. The calls are wrapped audio calls, as on the M1's AOP. + * + * The firmware talks to its devices only after they were attached, so the +- * driver attaches "pdm0" when it binds. ++ * driver attaches "pdm0" when it binds on A10. A10X firmware instead ++ * accepts a direct clock command with a source index and a rate in Hz. + */ + + #include +@@ -19,7 +20,7 @@ + #include + #include + +-#define AOP_AUDIO_WRAPPED_CALL 0x20 ++#define AOP_AUDIO_COMMAND 0x20 + #define AOP_AUDIO_CALL_ATTACH 0xc3000002 + #define AOP_AUDIO_CALL_SET_PROP 0xc3000005 + +@@ -28,6 +29,16 @@ + #define AOP_AUDIO_PDM_CLOCK_START 0x78693020 /* 'xi0 ' */ + #define AOP_AUDIO_PDM_CLOCK_STOP 0x6f666620 /* 'off ' */ + ++#define AOP_T8011_CLOCK_DISABLE 0 ++#define AOP_T8011_CLOCK_XIO 1 ++#define AOP_T8011_PDM_RATE 2400000 ++ ++struct aop_t8011_clock_config { ++ __le32 reserved; /* EPIC prefix before the clock payload */ ++ __le32 source; ++ __le32 rate; ++}; ++ + struct aop_audio_call_hdr { + __le32 zero0; + __le32 target; /* 0xffffffff */ +@@ -56,6 +67,7 @@ struct aop_audio { + struct apple_aop_service service; + struct clk_hw hw; + unsigned long rate; ++ bool direct_clock; + }; + + static void aop_audio_hdr(struct aop_audio_call_hdr *hdr, u32 type, size_t size) +@@ -72,7 +84,7 @@ static int aop_audio_call(struct aop_audio *audio, const void *call, size_t size + { + int ret; + +- ret = apple_aop_call(&audio->service, AOP_AUDIO_WRAPPED_CALL, call, size, ++ ret = apple_aop_call(&audio->service, AOP_AUDIO_COMMAND, call, size, + NULL, 0); + if (ret > 0) { + dev_err(audio->dev, "%s: firmware returned %#x\n", what, ret); +@@ -92,11 +104,21 @@ static int aop_audio_pdm_clock(struct aop_audio *audio, u32 mode, u32 rate) + .mode = cpu_to_le32(mode), + .rate = cpu_to_le32(rate), + }; ++ const char *what = mode == AOP_AUDIO_PDM_CLOCK_STOP ? ++ "stop PDM clock" : "start PDM clock"; ++ ++ if (audio->direct_clock) { ++ struct aop_t8011_clock_config config = { ++ .source = cpu_to_le32(rate ? AOP_T8011_CLOCK_XIO : ++ AOP_T8011_CLOCK_DISABLE), ++ .rate = cpu_to_le32(rate), ++ }; ++ ++ return aop_audio_call(audio, &config, sizeof(config), what); ++ } + + aop_audio_hdr(&call.hdr, AOP_AUDIO_CALL_SET_PROP, sizeof(call)); +- return aop_audio_call(audio, &call, sizeof(call), +- mode == AOP_AUDIO_PDM_CLOCK_STOP ? "stop PDM clock" : +- "start PDM clock"); ++ return aop_audio_call(audio, &call, sizeof(call), what); + } + + static struct aop_audio *to_aop_audio(struct clk_hw *hw) +@@ -124,10 +146,12 @@ static unsigned long aop_audio_clk_recalc_rate(struct clk_hw *hw, + return to_aop_audio(hw)->rate; + } + +-/* The firmware derives the rate itself; any PDM rate is passed on. */ + static int aop_audio_clk_determine_rate(struct clk_hw *hw, + struct clk_rate_request *req) + { ++ if (to_aop_audio(hw)->direct_clock) ++ return req->rate == AOP_T8011_PDM_RATE ? 0 : -EINVAL; ++ + req->rate = clamp_t(unsigned long, req->rate, 1, U32_MAX); + return 0; + } +@@ -170,11 +194,15 @@ static int aop_audio_probe(struct platform_device *pdev) + return -ENOMEM; + audio->dev = dev; + audio->service = *service; +- +- aop_audio_hdr(&attach.hdr, AOP_AUDIO_CALL_ATTACH, sizeof(attach)); +- ret = aop_audio_call(audio, &attach, sizeof(attach), "attach pdm0"); +- if (ret) +- return ret; ++ audio->direct_clock = of_device_is_compatible(dev->parent->of_node, ++ "apple,t8011-aop"); ++ ++ if (!audio->direct_clock) { ++ aop_audio_hdr(&attach.hdr, AOP_AUDIO_CALL_ATTACH, sizeof(attach)); ++ ret = aop_audio_call(audio, &attach, sizeof(attach), "attach pdm0"); ++ if (ret) ++ return ret; ++ } + + init.name = devm_kasprintf(dev, GFP_KERNEL, "%s-pdm", dev_name(dev)); + if (!init.name) diff --git a/kernel/patches/drivers/drm/0012-drm-simpledrm-expose-the-Apple-J120-boot-scanout-cad.patch b/kernel/patches/drivers/drm/0012-drm-simpledrm-expose-the-Apple-J120-boot-scanout-cad.patch new file mode 100644 index 00000000..5ab554c8 --- /dev/null +++ b/kernel/patches/drivers/drm/0012-drm-simpledrm-expose-the-Apple-J120-boot-scanout-cad.patch @@ -0,0 +1,225 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 16:07:49 +0100 +Subject: [PATCH] drm/simpledrm: expose the Apple J120 boot scanout cadences + +Reuse the firmware framebuffer while switching H9G between the verified two and four subframe cadences. Keep the boot cadence on other hardware and restore it on driver removal. + +Assisted-by: LLM +--- + .../display/apple,t8011-h9g-display.yaml | 28 ++++ + drivers/gpu/drm/sysfb/simpledrm.c | 131 +++++++++++++++++- + 2 files changed, 157 insertions(+), 2 deletions(-) + create mode 100644 Documentation/devicetree/bindings/display/apple,t8011-h9g-display.yaml + +diff --git a/Documentation/devicetree/bindings/display/apple,t8011-h9g-display.yaml b/Documentation/devicetree/bindings/display/apple,t8011-h9g-display.yaml +new file mode 100644 +index 000000000..feee15f18 +--- /dev/null ++++ b/Documentation/devicetree/bindings/display/apple,t8011-h9g-display.yaml +@@ -0,0 +1,28 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/display/apple,t8011-h9g-display.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple A10X H9G display controller ++ ++maintainers: ++ - tom ++ ++description: | ++ The H9G display controller scans out to the internal panel. The bootloader ++ may leave the controller, link and panel running with a simple framebuffer. ++ The simple-framebuffer node's display phandle identifies the controller. ++ ++properties: ++ compatible: ++ const: apple,t8011-h9g-display ++ ++ reg: ++ maxItems: 1 ++ ++required: ++ - compatible ++ - reg ++ ++additionalProperties: false +diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c +index 21ddf4502..4b5c64527 100644 +--- a/drivers/gpu/drm/sysfb/simpledrm.c ++++ b/drivers/gpu/drm/sysfb/simpledrm.c +@@ -2,6 +2,7 @@ + + #include + #include ++#include + #include + #include + #include +@@ -227,6 +228,9 @@ static int simplefb_get_panel_height_mm_of(struct drm_device *dev, + + struct simpledrm_device { + struct drm_sysfb_device sysfb; ++ void __iomem *h9g; ++ struct drm_display_mode h9g_fast_mode; ++ u16 h9g_boot_subframes; + + /* clocks */ + #if defined CONFIG_OF && defined CONFIG_COMMON_CLK +@@ -570,6 +574,126 @@ static int simpledrm_device_attach_genpd(struct simpledrm_device *sdev) + * Modesetting + */ + ++#define H9G_M3_CONTROL 0x8008 ++#define H9G_MODE 0x15808 ++#define H9G_IRQ_ENABLE 0x15824 ++#define H9G_OUTPUT_ENABLE 0x18060 ++#define H9G_EXTRA_SUBFRAMES 0x18050 ++#define H9G_SUBFRAME_LINES 0x18708 ++#define H9G_ACTIVE_SUBFRAMES 0x1870c ++#define H9G_EXTRA_SUBFRAMES_WRITE 0x98050 ++ ++static bool simpledrm_h9g_write(struct simpledrm_device *sdev, u16 subframes) ++{ ++ u32 value; ++ ++ writel(subframes, sdev->h9g + H9G_EXTRA_SUBFRAMES_WRITE); ++ return !readl_poll_timeout(sdev->h9g + H9G_EXTRA_SUBFRAMES, value, ++ (u16)value == subframes, 10, 1000); ++} ++ ++static void simpledrm_h9g_restore(void *data) ++{ ++ struct simpledrm_device *sdev = data; ++ ++ if (!simpledrm_h9g_write(sdev, sdev->h9g_boot_subframes)) ++ drm_err(&sdev->sysfb.dev, "failed to restore H9G boot cadence\n"); ++} ++ ++static void simpledrm_h9g_init(struct simpledrm_device *sdev) ++{ ++ struct drm_sysfb_device *sysfb = &sdev->sysfb; ++ struct device *dev = sysfb->dev.dev; ++ struct device_node *display; ++ struct resource res; ++ void __iomem *regs; ++ u16 subframes; ++ int ret = -ENODEV; ++ ++ if (!of_machine_is_compatible("apple,j120") || ++ sysfb->fb_mode.hdisplay != 2048 || sysfb->fb_mode.vdisplay != 2732) ++ return; ++ display = of_parse_phandle(dev->of_node, "display", 0); ++ if (!display) ++ return; ++ if (of_device_is_compatible(display, "apple,t8011-h9g-display")) ++ ret = of_address_to_resource(display, 0, &res); ++ of_node_put(display); ++ if (ret || resource_size(&res) < H9G_EXTRA_SUBFRAMES_WRITE + sizeof(u32)) ++ return; ++ regs = devm_ioremap_resource(dev, &res); ++ if (IS_ERR(regs)) ++ return; ++ subframes = readl(regs + H9G_EXTRA_SUBFRAMES); ++ /* Adopt only the boot scanout with the firmware processor stopped. */ ++ if (readl(regs + H9G_M3_CONTROL) != 3 || readl(regs + H9G_MODE) != 1 || ++ readl(regs + H9G_IRQ_ENABLE) || readl(regs + H9G_OUTPUT_ENABLE) || ++ readl(regs + H9G_SUBFRAME_LINES) != 1497 || ++ readl(regs + H9G_ACTIVE_SUBFRAMES) != 0x200 || ++ subframes != 2) ++ return; ++ ++ sdev->h9g = regs; ++ sdev->h9g_boot_subframes = subframes; ++ if (devm_add_action_or_reset(dev, simpledrm_h9g_restore, sdev)) { ++ sdev->h9g = NULL; ++ return; ++ } ++ ++ /* The boot link runs at the same pixel clock for both cadences. */ ++ sysfb->fb_mode.clock = 750001; ++ sysfb->fb_mode.htotal = 2088; ++ sysfb->fb_mode.vtotal = 5988; ++ sdev->h9g_fast_mode = sysfb->fb_mode; ++ sdev->h9g_fast_mode.vtotal = 2994; ++} ++ ++static enum drm_mode_status simpledrm_mode_valid(struct drm_crtc *crtc, ++ const struct drm_display_mode *mode) ++{ ++ struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev); ++ struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); ++ ++ if (!sdev->h9g) ++ return drm_sysfb_crtc_helper_mode_valid(crtc, mode); ++ if (drm_mode_equal(mode, &sysfb->fb_mode) || drm_mode_equal(mode, &sdev->h9g_fast_mode)) ++ return MODE_OK; ++ return MODE_BAD; ++} ++ ++static void simpledrm_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_commit *state) ++{ ++ struct drm_sysfb_device *sysfb = to_drm_sysfb_device(crtc->dev); ++ struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); ++ const struct drm_crtc_state *new_state = drm_atomic_get_new_crtc_state(state, crtc); ++ u16 subframes; ++ ++ if (!sdev->h9g) ++ return; ++ subframes = drm_mode_equal(&new_state->mode, &sdev->h9g_fast_mode) ? ++ 0 : sdev->h9g_boot_subframes; ++ if (!simpledrm_h9g_write(sdev, subframes)) ++ drm_err(crtc->dev, "failed to set H9G extra subframes to %u\n", subframes); ++} ++ ++static int simpledrm_get_modes(struct drm_connector *connector) ++{ ++ struct drm_sysfb_device *sysfb = to_drm_sysfb_device(connector->dev); ++ struct simpledrm_device *sdev = container_of(sysfb, struct simpledrm_device, sysfb); ++ struct drm_display_mode *fast; ++ int count = drm_sysfb_connector_helper_get_modes(connector); ++ ++ if (!sdev->h9g) ++ return count; ++ fast = drm_mode_duplicate(connector->dev, &sdev->h9g_fast_mode); ++ if (!fast) ++ return count; ++ fast->type = DRM_MODE_TYPE_DRIVER; ++ drm_mode_set_name(fast); ++ drm_mode_probed_add(connector, fast); ++ return count + 1; ++} ++ + static const u64 simpledrm_primary_plane_format_modifiers[] = { + DRM_SYSFB_PLANE_FORMAT_MODIFIERS, + }; +@@ -584,7 +708,9 @@ static const struct drm_plane_funcs simpledrm_primary_plane_funcs = { + }; + + static const struct drm_crtc_helper_funcs simpledrm_crtc_helper_funcs = { +- DRM_SYSFB_CRTC_HELPER_FUNCS, ++ .mode_valid = simpledrm_mode_valid, ++ .atomic_check = drm_sysfb_crtc_helper_atomic_check, ++ .atomic_enable = simpledrm_atomic_enable, + }; + + static const struct drm_crtc_funcs simpledrm_crtc_funcs = { +@@ -597,7 +723,7 @@ static const struct drm_encoder_funcs simpledrm_encoder_funcs = { + }; + + static const struct drm_connector_helper_funcs simpledrm_connector_helper_funcs = { +- DRM_SYSFB_CONNECTOR_HELPER_FUNCS, ++ .get_modes = simpledrm_get_modes, + }; + + static const struct drm_connector_funcs simpledrm_connector_funcs = { +@@ -735,6 +861,7 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv, + sysfb->fb_mode = drm_sysfb_mode(width, height, width_mm, height_mm); + sysfb->fb_format = format; + sysfb->fb_pitch = stride; ++ simpledrm_h9g_init(sdev); + + drm_dbg(dev, "display mode={" DRM_MODE_FMT "}\n", DRM_MODE_ARG(&sysfb->fb_mode)); + drm_dbg(dev, "framebuffer format=%p4cc, size=%dx%d, stride=%d byte\n", diff --git a/kernel/patches/drivers/gpio/0012-dt-bindings-gpio-describe-Autumn-D2401-boot-configur.patch b/kernel/patches/drivers/gpio/0012-dt-bindings-gpio-describe-Autumn-D2401-boot-configur.patch new file mode 100644 index 00000000..20800fc6 --- /dev/null +++ b/kernel/patches/drivers/gpio/0012-dt-bindings-gpio-describe-Autumn-D2401-boot-configur.patch @@ -0,0 +1,64 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:54 +0100 +Subject: [PATCH] dt-bindings: gpio: describe Autumn D2401 boot-configured + outputs + +Describe the J120 radio-enable GPIO provider. Only inherited output modes are supported; direction changes and the PMIC event block remain unavailable. + +Assisted-by: LLM +--- + .../bindings/gpio/apple,d2365-pmic-gpio.yaml | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/Documentation/devicetree/bindings/gpio/apple,d2365-pmic-gpio.yaml b/Documentation/devicetree/bindings/gpio/apple,d2365-pmic-gpio.yaml +index 978a5a25e..28eb24b3a 100644 +--- a/Documentation/devicetree/bindings/gpio/apple,d2365-pmic-gpio.yaml ++++ b/Documentation/devicetree/bindings/gpio/apple,d2365-pmic-gpio.yaml +@@ -4,7 +4,7 @@ + $id: http://devicetree.org/schemas/gpio/apple,d2365-pmic-gpio.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple A8/A9/A10 PMIC GPIO and event interrupt controller ++title: Apple A8/A9/A10/A10X PMIC GPIO and event interrupt controller + + maintainers: + - Paul Praschl +@@ -15,6 +15,10 @@ description: | + respectively. The controller is accessed through the regmap exported by the + parent Apple I2C PMIC device. + ++ The Autumn D2401 provides 20 GPIOs. Only boot-configured outputs are ++ currently supported; direction switching and PMU event interrupts are not. ++ Boards must reserve lines that must remain under firmware control. ++ + The D2207 and D2365 also latch 112 and 240 PMU events respectively + (charger, ADC, GPIO edges and others) in one read-to-clear block and + signal them on a single active-low line to the AP. As an interrupt +@@ -37,6 +41,7 @@ properties: + - apple,d2207-pmic-gpio + - apple,d2333-pmic-gpio + - apple,d2365-pmic-gpio ++ - apple,d2401-pmic-gpio + + gpio-controller: true + +@@ -44,6 +49,7 @@ properties: + const: 2 + + gpio-reserved-ranges: ++ minItems: 1 + maxItems: 3 + + interrupt-controller: true +@@ -84,7 +90,9 @@ allOf: + - if: + properties: + compatible: +- const: apple,d2333-pmic-gpio ++ enum: ++ - apple,d2333-pmic-gpio ++ - apple,d2401-pmic-gpio + then: + properties: + interrupt-controller: false diff --git a/kernel/patches/drivers/gpio/0013-gpio-apple-pmic-support-D2401-boot-configured-output.patch b/kernel/patches/drivers/gpio/0013-gpio-apple-pmic-support-D2401-boot-configured-output.patch new file mode 100644 index 00000000..a6807f22 --- /dev/null +++ b/kernel/patches/drivers/gpio/0013-gpio-apple-pmic-support-D2401-boot-configured-output.patch @@ -0,0 +1,134 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:54 +0100 +Subject: [PATCH] gpio: apple-pmic: support D2401 boot-configured outputs + +Use the D2401 two-byte GPIO configuration stride and native output masks. Reject unqualified direction changes and preserve firmware configuration outside the selected level/function bits. + +Assisted-by: LLM +--- + drivers/gpio/gpio-apple-d2365.c | 61 +++++++++++++++++++++++++++++++++ + 1 file changed, 61 insertions(+) + +diff --git a/drivers/gpio/gpio-apple-d2365.c b/drivers/gpio/gpio-apple-d2365.c +index 8ff38fcb7..baf4b242b 100644 +--- a/drivers/gpio/gpio-apple-d2365.c ++++ b/drivers/gpio/gpio-apple-d2365.c +@@ -119,6 +119,9 @@ struct apple_pmic_gpio_info { + unsigned int input_mode; + unsigned int output_mode; + unsigned int function_mask; ++ /* Some PMICs only have a verified, boot-configured output mode. */ ++ bool preserve_boot_direction; ++ unsigned int output_update_mask; + unsigned int (*config_reg)(unsigned int offset); + const struct apple_pmic_event_info *events; + }; +@@ -857,6 +860,25 @@ static DEFINE_SIMPLE_DEV_PM_OPS(apple_pmic_gpio_pm_ops, apple_pmic_gpio_suspend, + + /* ---- GPIO ---- */ + ++/* D2401: only alter the level/function bits used by native _setGPIOFunction. */ ++static int apple_pmic_gpio_set_boot_output(struct apple_pmic_gpio *gpio, ++ unsigned int offset, int value) ++{ ++ const struct apple_pmic_gpio_info *info = gpio->info; ++ unsigned int config; ++ int ret; ++ ++ ret = regmap_read(gpio->regmap, info->config_reg(offset), &config); ++ if (ret) ++ return ret; ++ if ((config & info->direction_mask) != info->output_mode) ++ return -EOPNOTSUPP; ++ ++ return regmap_update_bits(gpio->regmap, info->config_reg(offset), ++ info->output_update_mask, ++ value ? info->value_mask : 0); ++} ++ + static int apple_pmic_gpio_get_direction(struct gpio_chip *chip, + unsigned int offset) + { +@@ -870,6 +892,9 @@ static int apple_pmic_gpio_get_direction(struct gpio_chip *chip, + return ret; + if (value & info->function_mask) + return -EINVAL; ++ if (info->preserve_boot_direction && ++ (value & info->direction_mask) != info->output_mode) ++ return -EOPNOTSUPP; + + if ((value & info->direction_mask) == info->input_mode) + return GPIO_LINE_DIRECTION_IN; +@@ -885,6 +910,9 @@ static int apple_pmic_gpio_direction_input(struct gpio_chip *chip, + struct apple_pmic_gpio *gpio = gpiochip_get_data(chip); + const struct apple_pmic_gpio_info *info = gpio->info; + ++ if (info->preserve_boot_direction) ++ return -EOPNOTSUPP; ++ + return regmap_update_bits(gpio->regmap, + info->config_reg(offset), + info->direction_mask | info->value_mask, +@@ -897,6 +925,9 @@ static int apple_pmic_gpio_direction_output(struct gpio_chip *chip, + struct apple_pmic_gpio *gpio = gpiochip_get_data(chip); + const struct apple_pmic_gpio_info *info = gpio->info; + ++ if (info->preserve_boot_direction) ++ return apple_pmic_gpio_set_boot_output(gpio, offset, value); ++ + return regmap_update_bits(gpio->regmap, + info->config_reg(offset), + info->direction_mask | info->value_mask, +@@ -916,6 +947,8 @@ static int apple_pmic_gpio_get(struct gpio_chip *chip, unsigned int offset) + return ret; + if ((value & info->direction_mask) == info->output_mode) + return !!(value & info->value_mask); ++ if (info->preserve_boot_direction) ++ return -EOPNOTSUPP; + if ((value & info->direction_mask) != info->input_mode) + return -EINVAL; + +@@ -933,6 +966,9 @@ static int apple_pmic_gpio_set(struct gpio_chip *chip, unsigned int offset, + struct apple_pmic_gpio *gpio = gpiochip_get_data(chip); + const struct apple_pmic_gpio_info *info = gpio->info; + ++ if (info->preserve_boot_direction) ++ return apple_pmic_gpio_set_boot_output(gpio, offset, value); ++ + return regmap_update_bits(gpio->regmap, + info->config_reg(offset), + info->value_mask, +@@ -1029,7 +1065,32 @@ static const struct apple_pmic_gpio_info d2365_gpio_info = { + .events = &d2365_event_info, + }; + ++/* ++ * Autumn/D2401 has 20 GPIOs with linear, two-byte configuration slots. ++ * J120 radio enables inherit mode 0x80. Direction switching is not established; ++ * preserve that mode, reject other modes and leave the PMU event block alone. ++ */ ++static unsigned int d2401_gpio_config_reg(unsigned int offset) ++{ ++ return 0x900 + 2 * offset; ++} ++ ++static const struct apple_pmic_gpio_info d2401_gpio_info = { ++ .label = "d2401-pmic-gpio", ++ .ngpio = 20, ++ .value_mask = BIT(0), ++ .direction_mask = GENMASK(7, 6), ++ .output_mode = BIT(7), ++ .config_reg = d2401_gpio_config_reg, ++ .preserve_boot_direction = true, ++ .output_update_mask = BIT(4) | BIT(3) | BIT(0), ++}; ++ + static const struct of_device_id d2365_gpio_of_match[] = { ++ { ++ .compatible = "apple,d2401-pmic-gpio", ++ .data = &d2401_gpio_info, ++ }, + { + .compatible = "apple,d2207-pmic-gpio", + .data = &d2207_gpio_info, diff --git a/kernel/patches/drivers/gpio/0014-gpio-apple-d2365-support-D2355-and-August-event-inte.patch b/kernel/patches/drivers/gpio/0014-gpio-apple-d2365-support-D2355-and-August-event-inte.patch new file mode 100644 index 00000000..91a602ed --- /dev/null +++ b/kernel/patches/drivers/gpio/0014-gpio-apple-d2365-support-D2355-and-August-event-inte.patch @@ -0,0 +1,118 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:11 +0100 +Subject: [PATCH] gpio: apple-d2365: support D2355 and August event interrupts + +Restore the J120 experiment's PMIC event-bank match data in the existing interrupt owner. Register saved-mask restoration before writing the initial mask to cover partial transfer failures. + +Assisted-by: LLM +--- + drivers/gpio/gpio-apple-d2365.c | 49 +++++++++++++++++++++++++++++---- + 1 file changed, 43 insertions(+), 6 deletions(-) + +diff --git a/drivers/gpio/gpio-apple-d2365.c b/drivers/gpio/gpio-apple-d2365.c +index baf4b242b..577ce7f0a 100644 +--- a/drivers/gpio/gpio-apple-d2365.c ++++ b/drivers/gpio/gpio-apple-d2365.c +@@ -94,7 +94,7 @@ + #define D2365_EVENT_BYTES 30 + #define D2365_GPIO_EVENT 0x30 + +-#define APPLE_PMIC_EVENT_BYTES_MAX 30 ++#define APPLE_PMIC_EVENT_BYTES_MAX 32 + #define APPLE_PMIC_EVENTS_MAX (APPLE_PMIC_EVENT_BYTES_MAX * 8) + /* The events plus the line interrupt, hwirq nevents. */ + #define APPLE_PMIC_IRQS_MAX (APPLE_PMIC_EVENTS_MAX + 1) +@@ -520,9 +520,12 @@ static int apple_pmic_gpio_to_irq(struct gpio_chip *chip, unsigned int offset) + static void apple_pmic_event_restore_mask(void *data) + { + struct apple_pmic_gpio *gpio = data; ++ int ret; + +- regmap_bulk_write(gpio->regmap, gpio->info->events->mask_base, +- gpio->boot_mask, gpio->info->events->bytes); ++ ret = regmap_bulk_write(gpio->regmap, gpio->info->events->mask_base, ++ gpio->boot_mask, gpio->info->events->bytes); ++ if (ret) ++ dev_err(gpio->chip.parent, "failed to restore the event mask: %d\n", ret); + } + + static void apple_pmic_event_remove_domain(void *data) +@@ -604,15 +607,17 @@ static int apple_pmic_event_probe(struct platform_device *pdev, + if (ret) + return dev_err_probe(dev, ret, "failed to read the event mask\n"); + ++ /* A failed bulk write can still change part of the mask. */ ++ ret = devm_add_action(dev, apple_pmic_event_restore_mask, gpio); ++ if (ret) ++ return ret; ++ + /* As iOS does at probe: mask all, unmask only what has a consumer. */ + memset(gpio->mask, 0xff, sizeof(gpio->mask)); + ret = regmap_bulk_write(gpio->regmap, ev->mask_base, gpio->mask, + ev->bytes); + if (ret) + return dev_err_probe(dev, ret, "failed to mask the events\n"); +- ret = devm_add_action_or_reset(dev, apple_pmic_event_restore_mask, gpio); +- if (ret) +- return ret; + + /* The events, then the line interrupt (hwirq nevents). */ + gpio->domain = irq_domain_create_linear(dev_fwnode(dev), +@@ -995,10 +1000,14 @@ static int apple_pmic_gpio_probe(struct platform_device *pdev) + return dev_err_probe(dev, -ENODEV, "parent regmap unavailable\n"); + gpio->chip.parent = dev; + ++ gpio->chip.parent = dev; + ret = apple_pmic_event_probe(pdev, gpio); + if (ret) + return ret; + ++ if (!gpio->info->ngpio) ++ return gpio->domain ? 0 : -EINVAL; ++ + gpio->chip.label = gpio->info->label; + gpio->chip.owner = THIS_MODULE; + gpio->chip.base = -1; +@@ -1052,6 +1061,26 @@ static const struct apple_pmic_event_info d2365_event_info = { + .gpio_event = D2365_GPIO_EVENT, + }; + ++static const struct apple_pmic_event_info d2355_event_info = { ++ .status_base = 0x060, ++ .mask_base = 0x0a0, ++ .bytes = 10, ++}; ++ ++static const struct apple_pmic_gpio_info d2355_events_only = { ++ .events = &d2355_event_info, ++}; ++ ++static const struct apple_pmic_event_info d2400_event_info = { ++ .status_base = 0x140, ++ .mask_base = 0x1c0, ++ .bytes = 32, ++}; ++ ++static const struct apple_pmic_gpio_info d2400_events_only = { ++ .events = &d2400_event_info, ++}; ++ + static const struct apple_pmic_gpio_info d2365_gpio_info = { + .label = "d2365-pmic-gpio", + .ngpio = 24, +@@ -1087,6 +1116,14 @@ static const struct apple_pmic_gpio_info d2401_gpio_info = { + }; + + static const struct of_device_id d2365_gpio_of_match[] = { ++ { ++ .compatible = "apple,august-pmic-events", ++ .data = &d2400_events_only, ++ }, ++ { ++ .compatible = "apple,d2355-pmic-events", ++ .data = &d2355_events_only, ++ }, + { + .compatible = "apple,d2401-pmic-gpio", + .data = &d2401_gpio_info, diff --git a/kernel/patches/drivers/i2c/0002-i2c-pasemi-wait-for-Apple-controller-idle-after-comp.patch b/kernel/patches/drivers/i2c/0002-i2c-pasemi-wait-for-Apple-controller-idle-after-comp.patch new file mode 100644 index 00000000..8c43acb4 --- /dev/null +++ b/kernel/patches/drivers/i2c/0002-i2c-pasemi-wait-for-Apple-controller-idle-after-comp.patch @@ -0,0 +1,82 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 13:30:32 +0100 +Subject: [PATCH] i2c: pasemi: wait for Apple controller idle after completion + +On T8010 and compatible Apple hardware, a combined read can report transfer-ended while busy is still set. Give the final STOP a bounded interval to settle before reporting a stuck bus. Preserve the existing error handling for NACK, timeout and arbitration loss. + +Assisted-by: LLM +--- + drivers/i2c/busses/i2c-pasemi-core.c | 10 ++++++++++ + drivers/i2c/busses/i2c-pasemi-core.h | 1 + + drivers/i2c/busses/i2c-pasemi-platform.c | 3 +++ + 3 files changed, 14 insertions(+) + +diff --git a/drivers/i2c/busses/i2c-pasemi-core.c b/drivers/i2c/busses/i2c-pasemi-core.c +index 4d554ff9a..d5d6c4b7e 100644 +--- a/drivers/i2c/busses/i2c-pasemi-core.c ++++ b/drivers/i2c/busses/i2c-pasemi-core.c +@@ -52,6 +52,7 @@ + #define CTL_CLK_M GENMASK(7, 0) + + #define SMSTA_XFER_CLEAR (SMSTA_XEN | SMSTA_MTO | SMSTA_MTN | SMSTA_TOM) ++#define SMSTA_XFER_ERROR (SMSTA_TOM | SMSTA_MTO | SMSTA_MTA | SMSTA_MTN) + + /* + * The hardware (supposedly) has a 25ms timeout for clock stretching, thus +@@ -202,6 +203,15 @@ static int pasemi_smb_waitready(struct pasemi_smbus *smbus) + } + } + ++ /* Apple's engine can report XEN before the final STOP makes it idle. */ ++ if (smbus->wait_for_idle && (status & (SMSTA_XEN | SMSTA_XIP)) == ++ (SMSTA_XEN | SMSTA_XIP) && !(status & SMSTA_XFER_ERROR)) { ++ /* Preserve the existing bus-stuck error if the busy bit persists. */ ++ readx_poll_timeout(ioread32, smbus->ioaddr + REG_SMSTA, status, ++ !(status & SMSTA_XIP) || (status & SMSTA_XFER_ERROR), ++ 10, USEC_PER_MSEC); ++ } ++ + /* Controller timeout? */ + if (status & SMSTA_TOM) { + dev_err(smbus->dev, "Controller timeout, status 0x%08x\n", status); +diff --git a/drivers/i2c/busses/i2c-pasemi-core.h b/drivers/i2c/busses/i2c-pasemi-core.h +index 1381336bc..c81ce0d19 100644 +--- a/drivers/i2c/busses/i2c-pasemi-core.h ++++ b/drivers/i2c/busses/i2c-pasemi-core.h +@@ -21,6 +21,7 @@ struct pasemi_smbus { + unsigned int ctl_flags; + int hw_rev; + int use_irq; ++ bool wait_for_idle; + void (*hw_init)(struct pasemi_smbus *smbus); + struct completion irq_completion; + }; +diff --git a/drivers/i2c/busses/i2c-pasemi-platform.c b/drivers/i2c/busses/i2c-pasemi-platform.c +index ee51a01fc..248723b25 100644 +--- a/drivers/i2c/busses/i2c-pasemi-platform.c ++++ b/drivers/i2c/busses/i2c-pasemi-platform.c +@@ -26,6 +26,7 @@ + struct pasemi_platform_i2c_match_data { + void (*hw_init)(struct pasemi_smbus *smbus); + u32 ctl_flags; ++ bool wait_for_idle; + }; + + struct pasemi_platform_i2c_data { +@@ -48,6 +49,7 @@ static void pasemi_platform_i2c_t8010_init(struct pasemi_smbus *smbus) + static const struct pasemi_platform_i2c_match_data t8010_i2c_data = { + .hw_init = pasemi_platform_i2c_t8010_init, + .ctl_flags = 0, ++ .wait_for_idle = true, + }; + + static int +@@ -94,6 +96,7 @@ static int pasemi_platform_i2c_probe(struct platform_device *pdev) + if (match_data) { + smbus->hw_init = match_data->hw_init; + smbus->ctl_flags = match_data->ctl_flags; ++ smbus->wait_for_idle = match_data->wait_for_idle; + } + + smbus->ioaddr = devm_platform_ioremap_resource(pdev, 0); diff --git a/kernel/patches/drivers/iio/0010-iio-light-add-raw-CT709-color-channels-on-J120.patch b/kernel/patches/drivers/iio/0010-iio-light-add-raw-CT709-color-channels-on-J120.patch new file mode 100644 index 00000000..2f0ea8e9 --- /dev/null +++ b/kernel/patches/drivers/iio/0010-iio-light-add-raw-CT709-color-channels-on-J120.patch @@ -0,0 +1,458 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:15:12 +0100 +Subject: [PATCH] iio: light: add raw CT709 color channels on J120 + +Assisted-by: LLM +--- + drivers/iio/light/Kconfig | 7 ++ + drivers/iio/light/Makefile | 1 + + drivers/iio/light/ams-ct709.c | 189 ++++++++++++++++++++++++++++++ + drivers/iio/light/ams-ct709.h | 212 ++++++++++++++++++++++++++++++++++ + 4 files changed, 409 insertions(+) + create mode 100644 drivers/iio/light/ams-ct709.c + create mode 100644 drivers/iio/light/ams-ct709.h + +diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig +index c8d8084a3..025ad3ee2 100644 +--- a/drivers/iio/light/Kconfig ++++ b/drivers/iio/light/Kconfig +@@ -76,6 +76,13 @@ config AL3320A + To compile this driver as a module, choose M here: the + module will be called al3320a. + ++config AMS_CT709 ++ tristate "CT709 four-channel light sensor" ++ depends on I2C ++ help ++ Read the clear, red, green and blue channels of the CT709 light ++ sensors on the Apple J120. The module is called ams-ct709. ++ + config APDS9160 + tristate "APDS9160 combined als and proximity sensor" + depends on I2C +diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile +index fdbef07f8..6540b0512 100644 +--- a/drivers/iio/light/Makefile ++++ b/drivers/iio/light/Makefile +@@ -10,6 +10,7 @@ obj-$(CONFIG_ADUX1020) += adux1020.o + obj-$(CONFIG_AL3000A) += al3000a.o + obj-$(CONFIG_AL3010) += al3010.o + obj-$(CONFIG_AL3320A) += al3320a.o ++obj-$(CONFIG_AMS_CT709) += ams-ct709.o + obj-$(CONFIG_APDS9160) += apds9160.o + obj-$(CONFIG_APDS9300) += apds9300.o + obj-$(CONFIG_APDS9306) += apds9306.o +diff --git a/drivers/iio/light/ams-ct709.c b/drivers/iio/light/ams-ct709.c +new file mode 100644 +index 000000000..1bbb372ee +--- /dev/null ++++ b/drivers/iio/light/ams-ct709.c +@@ -0,0 +1,189 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* CT709-family bounded raw IIO candidate; IRQ, IR and lux remain unqualified. ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "ams-ct709.h" ++ ++struct ct709_data { ++ struct i2c_client *client; ++ struct mutex lock; ++ u64 deadline; ++ bool stopping; ++ bool faulted; ++}; ++static int ct709_read(void *ctx, u8 reg, u8 *value) ++{ ++ struct ct709_data *d = ctx; ++ int ret = i2c_smbus_read_byte_data(d->client, reg); ++ ++ if (ret < 0) ++ return ret; ++ *value = ret; ++ return 0; ++} ++static int ct709_write(void *ctx, u8 reg, u8 value) ++{ ++ struct ct709_data *d = ctx; ++ ++ if (!((reg == 0x80 && (value == 0 || value == 1 || value == 3)) || ++ (reg == 0x81 && (value == 0xff || value == 0xf6)) || ++ (reg == 0x8f && (value == 0 || value == 2)))) ++ return -EPERM; ++ return i2c_smbus_write_byte_data(d->client, reg, value); ++} ++static int ct709_block(void *ctx, u8 reg, u8 *bytes, unsigned int count) ++{ ++ struct ct709_data *d = ctx; ++ struct i2c_msg messages[] = { ++ {.addr = d->client->addr, .len = 1, .buf = ®}, ++ {.addr = d->client->addr, ++ .flags = I2C_M_RD, ++ .len = 8, ++ .buf = bytes}, ++ }; ++ int ret; ++ ++ if (reg != 0x94 || count != 8) ++ return -EINVAL; ++ ret = i2c_transfer(d->client->adapter, messages, ARRAY_SIZE(messages)); ++ return ret < 0 ? ret : ret == ARRAY_SIZE(messages) ? 0 : -EIO; ++} ++static int ct709_delay(void *ctx, unsigned int us) ++{ ++ (void)ctx; ++ usleep_range(us, us + 500); ++ return 0; ++} ++static bool ct709_expired(void *ctx) ++{ ++ struct ct709_data *d = ctx; ++ ++ return ktime_get_ns() >= d->deadline; ++} ++static const struct als_ops ct709_ops = { ++ .read = ct709_read, ++ .write = ct709_write, ++ .block = ct709_block, ++ .delay = ct709_delay, ++ .expired = ct709_expired, ++}; ++static int ct709_read_raw(struct iio_dev *indio, ++ const struct iio_chan_spec *channel, int *value, ++ int *value2, long mask) ++{ ++ struct ct709_data *d = iio_priv(indio); ++ struct als_result result; ++ int ret; ++ ++ if (mask == IIO_CHAN_INFO_HARDWAREGAIN) { ++ *value = 16; ++ return IIO_VAL_INT; ++ } ++ if (mask == IIO_CHAN_INFO_INT_TIME) { ++ *value = 0; ++ *value2 = 27800; ++ return IIO_VAL_INT_PLUS_MICRO; ++ } ++ if (mask != IIO_CHAN_INFO_RAW || channel->address >= 4) ++ return -EINVAL; ++ mutex_lock(&d->lock); ++ if (d->stopping || d->faulted) { ++ ret = -ESHUTDOWN; ++ goto out; ++ } ++ d->deadline = ktime_get_ns() + 5ULL * NSEC_PER_SEC; ++ ret = als_once(&ct709_ops, d, &result); ++ if (ret || !result.valid || !result.restored) { ++ d->faulted = true; ++ if (!ret) ++ ret = -EIO; ++ dev_err(&d->client->dev, ++ "capture failed %d, restore %d, verified %u\n", ret, ++ result.restore_error, result.restored); ++ goto out; ++ } ++ *value = result.channels[channel->address]; ++ ret = IIO_VAL_INT; ++out: ++ mutex_unlock(&d->lock); ++ return ret; ++} ++#define CT709_CHANNEL(color, index) \ ++ { \ ++ .type = IIO_INTENSITY, \ ++ .modified = 1, \ ++ .channel2 = IIO_MOD_LIGHT_##color, \ ++ .address = index, \ ++ .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), \ ++ .info_mask_shared_by_type = \ ++ BIT(IIO_CHAN_INFO_HARDWAREGAIN) | BIT(IIO_CHAN_INFO_INT_TIME), \ ++ } ++static const struct iio_chan_spec ct709_channels[] = { ++ CT709_CHANNEL(CLEAR, 0), ++ CT709_CHANNEL(RED, 1), ++ CT709_CHANNEL(GREEN, 2), ++ CT709_CHANNEL(BLUE, 3), ++}; ++static const struct iio_info ct709_info = {.read_raw = ct709_read_raw}; ++static int ct709_probe(struct i2c_client *client) ++{ ++ struct iio_dev *indio; ++ struct ct709_data *d; ++ int ret; ++ ++ if (!i2c_check_functionality(client->adapter, ++ I2C_FUNC_I2C | I2C_FUNC_SMBUS_BYTE_DATA)) ++ return -EOPNOTSUPP; ++ ret = i2c_smbus_read_byte_data(client, 0x92); ++ if (ret < 0) ++ return ret; ++ if (ret != 0x8f) ++ return -ENODEV; ++ ret = i2c_smbus_read_byte_data(client, 0x91); ++ if (ret < 0) ++ return ret; ++ if (ret != 0x31) ++ return -ENODEV; ++ indio = devm_iio_device_alloc(&client->dev, sizeof(*d)); ++ if (!indio) ++ return -ENOMEM; ++ d = iio_priv(indio); ++ d->client = client; ++ mutex_init(&d->lock); ++ i2c_set_clientdata(client, indio); ++ indio->name = "ct709"; ++ indio->info = &ct709_info; ++ indio->modes = INDIO_DIRECT_MODE; ++ indio->channels = ct709_channels; ++ indio->num_channels = ARRAY_SIZE(ct709_channels); ++ return devm_iio_device_register(&client->dev, indio); ++} ++static void ct709_remove(struct i2c_client *client) ++{ ++ struct ct709_data *d = iio_priv(i2c_get_clientdata(client)); ++ ++ mutex_lock(&d->lock); ++ d->stopping = true; ++ mutex_unlock(&d->lock); ++} ++static const struct of_device_id ct709_of_match[] = { ++ {.compatible = "apple,ct709"}, {}}; ++MODULE_DEVICE_TABLE(of, ct709_of_match); ++static const struct i2c_device_id ct709_ids[] = {{"ct709"}, {}}; ++MODULE_DEVICE_TABLE(i2c, ct709_ids); ++static struct i2c_driver ct709_driver = { ++ .driver = {.name = "ct709", .of_match_table = ct709_of_match}, ++ .probe = ct709_probe, ++ .remove = ct709_remove, ++ .id_table = ct709_ids, ++}; ++module_i2c_driver(ct709_driver); ++MODULE_LICENSE("GPL"); ++MODULE_DESCRIPTION( ++ "Bounded raw CT709 IIO candidate with verified per-frame restore"); +diff --git a/drivers/iio/light/ams-ct709.h b/drivers/iio/light/ams-ct709.h +new file mode 100644 +index 000000000..7f26a62ab +--- /dev/null ++++ b/drivers/iio/light/ams-ct709.h +@@ -0,0 +1,212 @@ ++/* SPDX-License-Identifier: MIT */ ++#ifdef __KERNEL__ ++#include ++#include ++#else ++#include ++#include ++#include ++typedef uint8_t u8; ++typedef uint16_t u16; ++#endif ++struct als_ops { ++ int (*read)(void *ctx, u8 reg, u8 *value); ++ int (*write)(void *ctx, u8 reg, u8 value); ++ int (*block)(void *ctx, u8 reg, u8 *bytes, unsigned int count); ++ int (*delay)(void *ctx, unsigned int us); ++ bool (*expired)(void *ctx); ++}; ++struct als_result { ++ bool changed, restored, valid; ++ u8 original, status; ++ u16 channels[4]; ++ int error, restore_error; ++}; ++ ++static int als_read(const struct als_ops *o, void *ctx, u8 reg, u8 *value) ++{ ++ return o->expired(ctx) ? -ETIMEDOUT : o->read(ctx, reg, value); ++} ++ ++static int als_write(const struct als_ops *o, void *ctx, u8 reg, u8 value) ++{ ++ return o->expired(ctx) ? -ETIMEDOUT : o->write(ctx, reg, value); ++} ++ ++static int als_block(const struct als_ops *o, void *ctx, u8 reg, u8 *bytes, ++ unsigned int count) ++{ ++ return o->expired(ctx) ? -ETIMEDOUT : o->block(ctx, reg, bytes, count); ++} ++ ++static int als_delay(const struct als_ops *o, void *ctx, unsigned int us) ++{ ++ return o->expired(ctx) ? -ETIMEDOUT : o->delay(ctx, us); ++} ++ ++static int als_once(const struct als_ops *o, void *ctx, struct als_result *r) ++{ ++ u8 v, bytes[8]; ++ int ret = 0, wr, rd, err; ++ bool configured = false, disabled, settings; ++ ++ *r = (struct als_result){0}; ++ ++ ret = als_read(o, ctx, 0x92, &v); ++ ++ if (ret) ++ ++ goto finish; ++ if (v != 0x8f) { ++ ret = -ENODEV; ++ goto finish; ++ } ++ ret = als_read(o, ctx, 0x91, &v); ++ if (ret) ++ goto finish; ++ if (v != 0x31) { ++ ret = -ENODEV; ++ goto finish; ++ } ++ ret = als_read(o, ctx, 0x80, &r->original); ++ if (ret) ++ goto finish; ++ if (r->original != 0) { ++ ret = -EBUSY; ++ goto finish; ++ } ++ ret = als_read(o, ctx, 0x81, &v); ++ if (ret) ++ goto finish; ++ if (v != 0xff) { ++ ret = -EPERM; ++ goto finish; ++ } ++ ret = als_read(o, ctx, 0x8f, &v); ++ if (ret) ++ goto finish; ++ if (v != 0) { ++ ret = -EPERM; ++ goto finish; ++ } ++ /* ++ * Configure only after exact original admission; any write can be ++ * ambiguous. ++ */ ++ if (o->expired(ctx)) { ++ ret = -ETIMEDOUT; ++ goto finish; ++ } ++ r->changed = true; ++ configured = true; ++ ret = o->write(ctx, 0x81, 0xf6); ++ if (ret) ++ goto finish; ++ ret = als_read(o, ctx, 0x81, &v); ++ if (ret) ++ goto finish; ++ if (v != 0xf6) { ++ ret = -EIO; ++ goto finish; ++ } ++ ret = als_write(o, ctx, 0x8f, 2); ++ if (ret) ++ goto finish; ++ ret = als_read(o, ctx, 0x8f, &v); ++ if (ret) ++ goto finish; ++ if (v != 2) { ++ ret = -EIO; ++ goto finish; ++ } ++ /* ++ * A failed write can still have taken effect. Restore on every later ++ * exit. ++ */ ++ if (o->expired(ctx)) { ++ ret = -ETIMEDOUT; ++ goto finish; ++ } ++ r->changed = true; ++ ret = o->write(ctx, 0x80, 1); ++ if (ret) ++ goto finish; ++ ret = als_read(o, ctx, 0x80, &v); ++ if (ret) ++ goto finish; ++ if (v != 1) { ++ ret = -EIO; ++ goto finish; ++ } ++ ret = als_delay(o, ctx, 5000); ++ if (ret) ++ goto finish; ++ ret = als_write(o, ctx, 0x80, 3); ++ if (ret) ++ goto finish; ++ ret = als_read(o, ctx, 0x80, &v); ++ if (ret) ++ goto finish; ++ if (v != 3) { ++ ret = -EIO; ++ goto finish; ++ } ++ for (unsigned int i = 0; i < 20; i++) { ++ ret = als_delay(o, ctx, 5000); ++ if (ret) ++ goto finish; ++ ret = als_read(o, ctx, 0x93, &r->status); ++ if (ret) ++ goto finish; ++ if (r->status & 0x80) { ++ ret = -ERANGE; ++ goto finish; ++ } ++ if (r->status & 1) ++ break; ++ } ++ if (!(r->status & 1)) { ++ ret = -ETIMEDOUT; ++ goto finish; ++ } ++ ret = als_block(o, ctx, 0x94, bytes, 8); ++ if (ret) ++ goto finish; ++ for (unsigned int i = 0; i < 4; i++) ++ r->channels[i] = (u16)bytes[2 * i] | (u16)bytes[2 * i + 1] << 8; ++ r->valid = true; ++finish: ++ r->error = ret; ++ if (r->changed) { ++ /* ++ * Restoration is attempted even after deadline/signal; never ++ * retry enable. ++ */ ++ wr = o->write(ctx, 0x80, r->original); ++ rd = o->read(ctx, 0x80, &v); ++ disabled = !rd && v == r->original; ++ err = wr ? wr : rd ? rd : disabled ? 0 : -EIO; ++ settings = disabled; ++ if (disabled && configured) { ++ wr = o->write(ctx, 0x81, 0xff); ++ rd = o->read(ctx, 0x81, &v); ++ settings = settings && !rd && v == 0xff; ++ if (!err) ++ err = wr ? wr : rd ? rd : v == 0xff ? 0 : -EIO; ++ wr = o->write(ctx, 0x8f, 0); ++ rd = o->read(ctx, 0x8f, &v); ++ settings = settings && !rd && v == 0; ++ if (!err) ++ err = wr ? wr : rd ? rd : v == 0 ? 0 : -EIO; ++ rd = o->read(ctx, 0x80, &v); ++ settings = settings && !rd && v == 0; ++ if (!err) ++ err = rd ? rd : v == 0 ? 0 : -EIO; ++ } ++ r->restored = disabled && settings; ++ r->restore_error = err; ++ if (!ret) ++ ret = r->restore_error; ++ } ++ return ret; ++} diff --git a/kernel/patches/drivers/iio/0011-dt-bindings-iio-light-describe-Apple-CT709-sensors.patch b/kernel/patches/drivers/iio/0011-dt-bindings-iio-light-describe-Apple-CT709-sensors.patch new file mode 100644 index 00000000..c1b30ef5 --- /dev/null +++ b/kernel/patches/drivers/iio/0011-dt-bindings-iio-light-describe-Apple-CT709-sensors.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:15:43 +0100 +Subject: [PATCH] dt-bindings: iio: light: describe Apple CT709 sensors + +Document the I2C compatible used for the paired J120 color sensors. + +Assisted-by: LLM +--- + .../bindings/iio/light/apple,ct709.yaml | 27 +++++++++++++++++++ + 1 file changed, 27 insertions(+) + create mode 100644 Documentation/devicetree/bindings/iio/light/apple,ct709.yaml + +diff --git a/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml b/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml +new file mode 100644 +index 000000000..5a91701fd +--- /dev/null ++++ b/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml +@@ -0,0 +1,27 @@ ++# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/iio/light/apple,ct709.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple CT709 four-channel ambient light sensor ++ ++maintainers: ++ - Linux IIO ++ ++description: ++ The CT709 measures clear, red, green and blue light intensity over I2C. ++ The J120 board uses two independently addressed sensors. ++ ++properties: ++ compatible: ++ const: apple,ct709 ++ ++ reg: ++ maxItems: 1 ++ ++required: ++ - compatible ++ - reg ++ ++additionalProperties: false diff --git a/kernel/patches/drivers/iio/0012-iio-apple-aop-describe-the-fixed-three-axis-scan-lay.patch b/kernel/patches/drivers/iio/0012-iio-apple-aop-describe-the-fixed-three-axis-scan-lay.patch new file mode 100644 index 00000000..8114a9b2 --- /dev/null +++ b/kernel/patches/drivers/iio/0012-iio-apple-aop-describe-the-fixed-three-axis-scan-lay.patch @@ -0,0 +1,57 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 00:03:53 +0100 +Subject: [PATCH] iio: apple-aop: describe the fixed three-axis scan layout + +The accelerometer and gyroscope push a complete XYZ scan. Advertise that layout so the IIO core can select the requested axes when a buffer consumer enables only a subset. + +Assisted-by: LLM +--- + drivers/iio/accel/apple_aop_accel.c | 4 ++++ + drivers/iio/gyro/apple_aop_gyro.c | 4 ++++ + 2 files changed, 8 insertions(+) + +diff --git a/drivers/iio/accel/apple_aop_accel.c b/drivers/iio/accel/apple_aop_accel.c +index a6447e8a7..ec8999760 100644 +--- a/drivers/iio/accel/apple_aop_accel.c ++++ b/drivers/iio/accel/apple_aop_accel.c +@@ -202,6 +202,9 @@ static const struct iio_chan_spec_ext_info apple_aop_accel_ext_info[] = { + .ext_info = apple_aop_accel_ext_info, \ + } + ++/* Firmware reports always contain all three axes. */ ++static const unsigned long apple_aop_accel_scan_masks[] = { GENMASK(2, 0), 0 }; ++ + static const struct iio_chan_spec apple_aop_accel_channels[] = { + APPLE_AOP_ACCEL_CHANNEL(X, 0), + APPLE_AOP_ACCEL_CHANNEL(Y, 1), +@@ -257,6 +260,7 @@ static int apple_aop_accel_probe(struct platform_device *pdev) + + indio_dev->name = "apple-aop-accel"; + indio_dev->info = &apple_aop_accel_info; ++ indio_dev->available_scan_masks = apple_aop_accel_scan_masks; + indio_dev->channels = apple_aop_accel_channels; + indio_dev->num_channels = ARRAY_SIZE(apple_aop_accel_channels); + indio_dev->modes = INDIO_DIRECT_MODE; +diff --git a/drivers/iio/gyro/apple_aop_gyro.c b/drivers/iio/gyro/apple_aop_gyro.c +index 3341164bf..da79af983 100644 +--- a/drivers/iio/gyro/apple_aop_gyro.c ++++ b/drivers/iio/gyro/apple_aop_gyro.c +@@ -189,6 +189,9 @@ static const struct iio_chan_spec_ext_info apple_aop_gyro_ext_info[] = { + .ext_info = apple_aop_gyro_ext_info, \ + } + ++/* Firmware reports always contain all three axes. */ ++static const unsigned long apple_aop_gyro_scan_masks[] = { GENMASK(2, 0), 0 }; ++ + static const struct iio_chan_spec apple_aop_gyro_channels[] = { + APPLE_AOP_GYRO_CHANNEL(X, 0), + APPLE_AOP_GYRO_CHANNEL(Y, 1), +@@ -243,6 +246,7 @@ static int apple_aop_gyro_probe(struct platform_device *pdev) + + indio_dev->name = "apple-aop-gyro"; + indio_dev->info = &apple_aop_gyro_info; ++ indio_dev->available_scan_masks = apple_aop_gyro_scan_masks; + indio_dev->channels = apple_aop_gyro_channels; + indio_dev->num_channels = ARRAY_SIZE(apple_aop_gyro_channels); + indio_dev->modes = INDIO_DIRECT_MODE; diff --git a/kernel/patches/drivers/iio/0013-dt-bindings-iio-light-describe-CT709-factory-calibra.patch b/kernel/patches/drivers/iio/0013-dt-bindings-iio-light-describe-CT709-factory-calibra.patch new file mode 100644 index 00000000..005d5f26 --- /dev/null +++ b/kernel/patches/drivers/iio/0013-dt-bindings-iio-light-describe-CT709-factory-calibra.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 00:45:34 +0100 +Subject: [PATCH] dt-bindings: iio: light: describe CT709 factory calibration + +The bootloader passes the per-unit dual-sensor record at the aliased node. Describe the resolved byte array, including the padding present on J120. + +Assisted-by: LLM +Signed-off-by: tom +--- + .../devicetree/bindings/iio/light/apple,ct709.yaml | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml b/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml +index 5a91701fd..59a918861 100644 +--- a/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml ++++ b/Documentation/devicetree/bindings/iio/light/apple,ct709.yaml +@@ -20,6 +20,16 @@ properties: + reg: + maxItems: 1 + ++ apple,als-calibration: ++ $ref: /schemas/types.yaml#/definitions/uint8-array ++ minItems: 6696 ++ maxItems: 9992 ++ description: ++ Factory calibration supplied by the bootloader from the resolved Apple ++ device tree alsCalibration property. On J120 the eight-byte header and ++ two 3344-byte orientation records can be followed by padding. The ++ property on the als0 node contains records for both sensors. ++ + required: + - compatible + - reg diff --git a/kernel/patches/drivers/iio/0014-iio-light-ct709-check-the-auxiliary-gain-before-samp.patch b/kernel/patches/drivers/iio/0014-iio-light-ct709-check-the-auxiliary-gain-before-samp.patch new file mode 100644 index 00000000..168d5d5e --- /dev/null +++ b/kernel/patches/drivers/iio/0014-iio-light-ct709-check-the-auxiliary-gain-before-samp.patch @@ -0,0 +1,46 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 00:46:31 +0100 +Subject: [PATCH] iio: light: ct709: check the auxiliary gain before sampling + +The fixed 16x capture uses gain index 4, which requires AUX=0 as well as GAIN=2. Reject unsupported auxiliary settings before writing to the device and allow the caller to sample again when the setting changes. + +Assisted-by: LLM +Signed-off-by: tom +--- + drivers/iio/light/ams-ct709.c | 2 ++ + drivers/iio/light/ams-ct709.h | 8 ++++++++ + 2 files changed, 10 insertions(+) + +diff --git a/drivers/iio/light/ams-ct709.c b/drivers/iio/light/ams-ct709.c +index 1bbb372ee..d3172c467 100644 +--- a/drivers/iio/light/ams-ct709.c ++++ b/drivers/iio/light/ams-ct709.c +@@ -99,6 +99,8 @@ static int ct709_read_raw(struct iio_dev *indio, + } + d->deadline = ktime_get_ns() + 5ULL * NSEC_PER_SEC; + ret = als_once(&ct709_ops, d, &result); ++ if (ret == -EOPNOTSUPP && !result.changed) ++ goto out; + if (ret || !result.valid || !result.restored) { + d->faulted = true; + if (!ret) +diff --git a/drivers/iio/light/ams-ct709.h b/drivers/iio/light/ams-ct709.h +index 7f26a62ab..9e9fb24ff 100644 +--- a/drivers/iio/light/ams-ct709.h ++++ b/drivers/iio/light/ams-ct709.h +@@ -89,6 +89,14 @@ static int als_once(const struct als_ops *o, void *ctx, struct als_result *r) + ret = -EPERM; + goto finish; + } ++ /* GAIN=2 gives the advertised 16x range only with AUX gain disabled. */ ++ ret = als_read(o, ctx, 0x90, &v); ++ if (ret) ++ goto finish; ++ if (v != 0) { ++ ret = -EOPNOTSUPP; ++ goto finish; ++ } + /* + * Configure only after exact original admission; any write can be + * ambiguous. diff --git a/kernel/patches/drivers/iio/0015-iio-light-ct709-expose-factory-calibrated-illuminanc.patch b/kernel/patches/drivers/iio/0015-iio-light-ct709-expose-factory-calibrated-illuminanc.patch new file mode 100644 index 00000000..bf0564f0 --- /dev/null +++ b/kernel/patches/drivers/iio/0015-iio-light-ct709-expose-factory-calibrated-illuminanc.patch @@ -0,0 +1,248 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 00:50:51 +0100 +Subject: [PATCH] iio: light: ct709: expose factory-calibrated illuminance on + J120 + +Read the per-unit two-sensor record from the aliased light sensor. Select the orientation for each address and compute illuminance from one fixed-exposure RGBC frame using integer arithmetic. Retain the raw channels when calibration is unavailable. + +Assisted-by: LLM +Signed-off-by: tom +--- + drivers/iio/light/ams-ct709-lux.h | 100 ++++++++++++++++++++++++++++++ + drivers/iio/light/ams-ct709.c | 72 +++++++++++++++++++-- + 2 files changed, 166 insertions(+), 6 deletions(-) + create mode 100644 drivers/iio/light/ams-ct709-lux.h + +diff --git a/drivers/iio/light/ams-ct709-lux.h b/drivers/iio/light/ams-ct709-lux.h +new file mode 100644 +index 000000000..f27ba94f8 +--- /dev/null ++++ b/drivers/iio/light/ams-ct709-lux.h +@@ -0,0 +1,100 @@ ++/* SPDX-License-Identifier: GPL-2.0-only */ ++#ifndef AMS_CT709_LUX_H ++#define AMS_CT709_LUX_H ++ ++#include ++#include ++#include ++#include ++ ++/* Fixed exposure: 16x sensor gain and ten integration cycles. */ ++struct ct709_lux_cal { ++ u32 gain_q20[4]; ++ u16 offset_milli[4]; ++ s32 coefficient[4]; ++ u32 exposure; ++}; ++ ++static u32 ct709_gain_step(u16 word) ++{ ++ /* Factory gain transitions are Q8. Normalize the ratio to [1.75, 2.4]. */ ++ static const u8 num[] = { 1, 1, 5, 2 }; ++ static const u8 den[] = { 1, 2, 14, 1 }; ++ unsigned int i; ++ ++ for (i = 0; i < ARRAY_SIZE(num); i++) { ++ u32 n = word * num[i], d = 256 * den[i]; ++ ++ if (4 * n >= 7 * d && 5 * n <= 12 * d) ++ return DIV_ROUND_CLOSEST_ULL((u64)n << 20, d); ++ } ++ return DIV_ROUND_CLOSEST_ULL((u64)word * 14 << 12, 5); ++} ++ ++/* The caller selects an orientation record validated as native type 3. */ ++static int ct709_lux_parse(const u8 *p, size_t size, struct ct709_lux_cal *cal) ++{ ++ u32 usec, cycles; ++ unsigned int i, j; ++ ++ if (size != 3344 || p[0x68] != 3 || p[16] < 4 || p[16] > 8) ++ return -EINVAL; ++ usec = get_unaligned_le16(p + 10) * 1000; ++ cycles = (usec >> 10) > 694 ? 255 : ((u64)(usec >> 2) * 0x05e4be11) >> 36; ++ cal->exposure = cycles * get_unaligned_le16(p + 8); ++ if (!cal->exposure) ++ return -EINVAL; ++ for (i = 0; i < 4; i++) { ++ const u8 *gains = p + 0x1c + 20 * i; ++ u32 gain = 1U << 20; ++ ++ for (j = 4; j < p[16]; j++) { ++ u32 step = ct709_gain_step(get_unaligned_le16(gains + 2 * j)); ++ u64 next = ((u64)gain * step + BIT(19)) >> 20; ++ ++ if (!next || next > U32_MAX) ++ return -ERANGE; ++ gain = next; ++ } ++ cal->gain_q20[i] = gain; ++ cal->offset_milli[i] = get_unaligned_le16(gains - 3); ++ cal->coefficient[i] = (s32)get_unaligned_le32(p + 0x6c + 4 * i); ++ } ++ return 0; ++} ++ ++static int ct709_millilux(const struct ct709_lux_cal *cal, ++ const u16 channels[4], int *value) ++{ ++ const u64 divisor = 2550ULL * 1000000; ++ const u64 ceiling = 150000000ULL * divisor; ++ s64 count[4], sum = 0; ++ unsigned int i; ++ ++ /* The frame is CRGB, while the calibration record is RGBC. */ ++ for (i = 0; i < 4; i++) { ++ count[i] = ((u64)channels[(i + 1) % 4] * cal->gain_q20[i] * ++ 1000 + BIT(19)) >> 20; ++ if (channels[1]) ++ count[i] += cal->offset_milli[i]; ++ } ++ if (!channels[1]) ++ count[0] = div_s64(max_t(s64, 0, 108 * count[3] - ++ 97 * count[1] - 112 * count[2]), 100); ++ for (i = 0; i < 4; i++) { ++ s64 term; ++ ++ if (check_mul_overflow(count[i], (s64)cal->coefficient[i], &term) || ++ check_add_overflow(sum, term, &sum)) ++ return -ERANGE; ++ } ++ if (sum <= 0) ++ *value = 0; ++ else if ((u64)sum > div_u64(ceiling, cal->exposure)) ++ *value = 150000000; ++ else ++ *value = DIV_ROUND_CLOSEST_ULL((u64)sum * cal->exposure, divisor); ++ return 0; ++} ++ ++#endif +diff --git a/drivers/iio/light/ams-ct709.c b/drivers/iio/light/ams-ct709.c +index d3172c467..691e80fed 100644 +--- a/drivers/iio/light/ams-ct709.c ++++ b/drivers/iio/light/ams-ct709.c +@@ -1,6 +1,5 @@ + // SPDX-License-Identifier: GPL-2.0-only +-/* CT709-family bounded raw IIO candidate; IRQ, IR and lux remain unqualified. +- */ ++/* CT709 four-channel ambient light sensor. */ + #include + #include + #include +@@ -9,10 +8,12 @@ + #include + #include + #include "ams-ct709.h" ++#include "ams-ct709-lux.h" + + struct ct709_data { + struct i2c_client *client; + struct mutex lock; ++ struct ct709_lux_cal calibration; + u64 deadline; + bool stopping; + bool faulted; +@@ -90,7 +91,8 @@ static int ct709_read_raw(struct iio_dev *indio, + *value2 = 27800; + return IIO_VAL_INT_PLUS_MICRO; + } +- if (mask != IIO_CHAN_INFO_RAW || channel->address >= 4) ++ if (mask != IIO_CHAN_INFO_PROCESSED && ++ (mask != IIO_CHAN_INFO_RAW || channel->address >= 4)) + return -EINVAL; + mutex_lock(&d->lock); + if (d->stopping || d->faulted) { +@@ -110,6 +112,17 @@ static int ct709_read_raw(struct iio_dev *indio, + result.restore_error, result.restored); + goto out; + } ++ if (mask == IIO_CHAN_INFO_PROCESSED) { ++ int millilux; ++ ++ ret = ct709_millilux(&d->calibration, result.channels, &millilux); ++ if (ret) ++ goto out; ++ *value = millilux / 1000; ++ *value2 = (millilux % 1000) * 1000; ++ ret = IIO_VAL_INT_PLUS_MICRO; ++ goto out; ++ } + *value = result.channels[channel->address]; + ret = IIO_VAL_INT; + out: +@@ -131,8 +144,54 @@ static const struct iio_chan_spec ct709_channels[] = { + CT709_CHANNEL(RED, 1), + CT709_CHANNEL(GREEN, 2), + CT709_CHANNEL(BLUE, 3), ++ { .type = IIO_LIGHT, .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) }, + }; + static const struct iio_info ct709_info = {.read_raw = ct709_read_raw}; ++/* J120 stores both orientations in the factory record on the als0 node. */ ++static bool ct709_read_calibration(struct i2c_client *client, ++ struct ct709_lux_cal *cal) ++{ ++ struct device_node *owner; ++ const u8 *blob, *record; ++ unsigned int orientation, other, i; ++ int len; ++ ++ if (!client->dev.of_node || !of_machine_is_compatible("apple,j120")) ++ return false; ++ owner = of_find_node_by_path("als0"); ++ if (!owner) ++ return false; ++ if (!of_device_is_compatible(owner, "apple,ct709") || ++ owner->parent != client->dev.of_node->parent) ++ goto out; ++ blob = of_get_property(owner, "apple,als-calibration", &len); ++ if (!blob || len < 6696 || memcmp(blob, "\x02\x01\x02\x08", 4) || ++ get_unaligned_le16(blob + 4) != 6696) ++ goto out; ++ if (client->addr != 0x29 && client->addr != 0x39) ++ goto out; ++ orientation = client->addr == 0x29 ? 6 : 5; ++ other = orientation == 6 ? 5 : 6; ++ record = NULL; ++ for (i = 0; i < 2; i++) { ++ const u8 *p = blob + 8 + 3344 * i; ++ ++ if (p[0] != 2 || p[1] != 1 || p[3] != 1 || ++ get_unaligned_le32(p + 4) != 3344 || p[0x68] != 3) ++ goto out; ++ if (p[2] == orientation && !record) ++ record = p; ++ else if (p[2] != other) ++ goto out; ++ } ++ if (record && !ct709_lux_parse(record, 3344, cal)) { ++ of_node_put(owner); ++ return true; ++ } ++out: ++ of_node_put(owner); ++ return false; ++} + static int ct709_probe(struct i2c_client *client) + { + struct iio_dev *indio; +@@ -163,7 +222,9 @@ static int ct709_probe(struct i2c_client *client) + indio->info = &ct709_info; + indio->modes = INDIO_DIRECT_MODE; + indio->channels = ct709_channels; +- indio->num_channels = ARRAY_SIZE(ct709_channels); ++ indio->num_channels = ARRAY_SIZE(ct709_channels) - 1; ++ if (ct709_read_calibration(client, &d->calibration)) ++ indio->num_channels++; + return devm_iio_device_register(&client->dev, indio); + } + static void ct709_remove(struct i2c_client *client) +@@ -187,5 +248,4 @@ static struct i2c_driver ct709_driver = { + }; + module_i2c_driver(ct709_driver); + MODULE_LICENSE("GPL"); +-MODULE_DESCRIPTION( +- "Bounded raw CT709 IIO candidate with verified per-frame restore"); ++MODULE_DESCRIPTION("Apple CT709 ambient light sensor"); diff --git a/kernel/patches/drivers/iio/0016-iio-adc-add-Apple-Orion-Bellatrix-Lightning-VBUS-tel.patch b/kernel/patches/drivers/iio/0016-iio-adc-add-Apple-Orion-Bellatrix-Lightning-VBUS-tel.patch new file mode 100644 index 00000000..8da0bb64 --- /dev/null +++ b/kernel/patches/drivers/iio/0016-iio-adc-add-Apple-Orion-Bellatrix-Lightning-VBUS-tel.patch @@ -0,0 +1,285 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 16:40:47 +0100 +Subject: [PATCH] iio: adc: add Apple Orion Bellatrix Lightning VBUS telemetry + +Read the J120 Lightning VBUS ADC on demand. Serialize conversions, bound the wait and verify restoration of the control register before returning a measurement. + +Assisted-by: LLM +--- + .../iio/adc/apple,orion-bellatrix-vbus.yaml | 26 +++ + drivers/iio/adc/Kconfig | 10 + + drivers/iio/adc/Makefile | 1 + + drivers/iio/adc/apple-orion-vbus.c | 197 ++++++++++++++++++ + 4 files changed, 234 insertions(+) + create mode 100644 Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml + create mode 100644 drivers/iio/adc/apple-orion-vbus.c + +diff --git a/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml b/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml +new file mode 100644 +index 000000000..265eb4086 +--- /dev/null ++++ b/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml +@@ -0,0 +1,26 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/iio/adc/apple,orion-bellatrix-vbus.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple Orion Bellatrix Lightning VBUS ADC ++ ++maintainers: ++ - tom ++ ++description: ++ Orion Bellatrix provides an ADC input wired to Lightning VBUS on J120. ++ ++properties: ++ compatible: ++ const: apple,orion-bellatrix-vbus ++ ++ reg: ++ maxItems: 1 ++ ++required: ++ - compatible ++ - reg ++ ++additionalProperties: false +diff --git a/drivers/iio/adc/Kconfig b/drivers/iio/adc/Kconfig +index 415e519ad..77e77517e 100644 +--- a/drivers/iio/adc/Kconfig ++++ b/drivers/iio/adc/Kconfig +@@ -617,6 +617,16 @@ config ADI_AXI_ADC + To compile this driver as a module, choose M here: the + module will be called adi-axi-adc. + ++config APPLE_ORION_VBUS ++ tristate "Apple Orion Bellatrix Lightning VBUS ADC" ++ depends on I2C && OF ++ help ++ Read the input voltage at the Lightning connector on boards with ++ the Orion Bellatrix ADC wired to VBUS. ++ ++ To compile this driver as a module, choose M here. The module ++ will be called apple-orion-vbus. ++ + config ASPEED_ADC + tristate "Aspeed ADC" + depends on ARCH_ASPEED || COMPILE_TEST +diff --git a/drivers/iio/adc/Makefile b/drivers/iio/adc/Makefile +index dcec0abb0..29cddf9b4 100644 +--- a/drivers/iio/adc/Makefile ++++ b/drivers/iio/adc/Makefile +@@ -52,6 +52,7 @@ obj-$(CONFIG_AD799X) += ad799x.o + obj-$(CONFIG_AD9467) += ad9467.o + obj-$(CONFIG_ADE9000) += ade9000.o + obj-$(CONFIG_ADI_AXI_ADC) += adi-axi-adc.o ++obj-$(CONFIG_APPLE_ORION_VBUS) += apple-orion-vbus.o + obj-$(CONFIG_ASPEED_ADC) += aspeed_adc.o + obj-$(CONFIG_AT91_ADC) += at91_adc.o + obj-$(CONFIG_AT91_SAMA5D2_ADC) += at91-sama5d2_adc.o +diff --git a/drivers/iio/adc/apple-orion-vbus.c b/drivers/iio/adc/apple-orion-vbus.c +new file mode 100644 +index 000000000..3e72ccfce +--- /dev/null ++++ b/drivers/iio/adc/apple-orion-vbus.c +@@ -0,0 +1,197 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* Lightning VBUS ADC on the Apple Orion Bellatrix. */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++#define ORION_CONTROL 0x00 ++#define ORION_STATUS 0x0c ++#define ORION_READY 0x17 ++#define ORION_ADC_COMMAND 0xa0 ++#define ORION_ADC_STATUS 0xa2 ++#define ORION_ADC_LOW 0xa4 ++#define ORION_ADC_HIGH 0xa5 ++#define ORION_CONTROL_IDLE 0x81 ++#define ORION_CONTROL_ADC (ORION_CONTROL_IDLE | BIT(4)) ++#define ORION_ADC_VBUS 2 ++#define ORION_ADC_DONE BIT(0) ++ ++struct orion_vbus { ++ struct i2c_client *client; ++ struct mutex lock; ++ bool restore_failed; ++}; ++ ++static int orion_restore(struct i2c_client *client) ++{ ++ int ret, state; ++ ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state < 0) ++ return state; ++ if (state == ORION_CONTROL_IDLE) ++ return 0; ++ if (state != ORION_CONTROL_ADC) ++ return -EIO; ++ ++ ret = i2c_smbus_write_byte_data(client, ORION_CONTROL, ORION_CONTROL_IDLE); ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state == ORION_CONTROL_IDLE) ++ return ret; ++ return state < 0 ? state : -EIO; ++} ++ ++static int orion_convert(struct i2c_client *client) ++{ ++ int state, ret, low, high, attempt; ++ ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state != ORION_CONTROL_ADC) ++ return state < 0 ? state : -EIO; ++ ret = i2c_smbus_read_byte_data(client, ORION_ADC_STATUS); ++ if (ret < 0) ++ return ret; ++ ++ ret = i2c_smbus_write_byte_data(client, ORION_ADC_COMMAND, ORION_ADC_VBUS); ++ if (ret < 0) ++ return ret; ++ ++ for (attempt = 0; ; attempt++) { ++ ret = i2c_smbus_read_byte_data(client, ORION_ADC_STATUS); ++ if (ret < 0) ++ return ret; ++ if (ret & ORION_ADC_DONE) ++ break; ++ if (attempt == 5) ++ return -ETIMEDOUT; ++ msleep(10); ++ } ++ ++ low = i2c_smbus_read_byte_data(client, ORION_ADC_LOW); ++ if (low < 0) ++ return low; ++ high = i2c_smbus_read_byte_data(client, ORION_ADC_HIGH); ++ if (high < 0) ++ return high; ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state != ORION_CONTROL_ADC) ++ return state < 0 ? state : -EIO; ++ ++ ret = low | ((high & 3) << 8); ++ return ret == 1023 ? -ERANGE : ret; ++} ++ ++static int orion_sample(struct orion_vbus *vbus) ++{ ++ struct i2c_client *client = vbus->client; ++ int state, ret, restore; ++ ++ if (vbus->restore_failed) ++ return -EIO; ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state != ORION_CONTROL_IDLE) ++ return state < 0 ? state : -EBUSY; ++ state = i2c_smbus_read_byte_data(client, ORION_STATUS); ++ if (state < 0) ++ return state; ++ if (!(state & BIT(2))) { ++ state = i2c_smbus_read_byte_data(client, ORION_READY); ++ if (state < 0) ++ return state; ++ if (state & (BIT(1) | BIT(0))) ++ return -EBUSY; ++ } ++ state = i2c_smbus_read_byte_data(client, ORION_CONTROL); ++ if (state != ORION_CONTROL_IDLE) ++ return state < 0 ? state : -EBUSY; ++ ++ ret = i2c_smbus_write_byte_data(client, ORION_CONTROL, ORION_CONTROL_ADC); ++ if (!ret) ++ ret = orion_convert(client); ++ restore = orion_restore(client); ++ if (restore) { ++ vbus->restore_failed = true; ++ dev_err(&client->dev, "ADC control restore failed: %d\n", restore); ++ return restore; ++ } ++ ++ return ret; ++} ++ ++static int orion_vbus_read_raw(struct iio_dev *indio_dev, ++ const struct iio_chan_spec *chan, ++ int *val, int *val2, long mask) ++{ ++ struct orion_vbus *vbus = iio_priv(indio_dev); ++ int ret; ++ ++ if (mask != IIO_CHAN_INFO_PROCESSED) ++ return -EINVAL; ++ ++ mutex_lock(&vbus->lock); ++ ret = orion_sample(vbus); ++ mutex_unlock(&vbus->lock); ++ if (ret < 0) ++ return ret; ++ ++ /* Orion Bellatrix ADC2 is scaled in 16 mV steps. */ ++ *val = ret * 16; ++ return IIO_VAL_INT; ++} ++ ++static const struct iio_info orion_vbus_info = { ++ .read_raw = orion_vbus_read_raw, ++}; ++ ++static const struct iio_chan_spec orion_vbus_channel = { ++ .type = IIO_VOLTAGE, ++ .indexed = 1, ++ .channel = 0, ++ .datasheet_name = "vbus", ++ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED), ++}; ++ ++static int orion_vbus_probe(struct i2c_client *client) ++{ ++ struct iio_dev *indio_dev; ++ struct orion_vbus *vbus; ++ ++ if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) ++ return -EOPNOTSUPP; ++ ++ indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*vbus)); ++ if (!indio_dev) ++ return -ENOMEM; ++ ++ vbus = iio_priv(indio_dev); ++ vbus->client = client; ++ mutex_init(&vbus->lock); ++ indio_dev->name = "orion-vbus"; ++ indio_dev->info = &orion_vbus_info; ++ indio_dev->modes = INDIO_DIRECT_MODE; ++ indio_dev->channels = &orion_vbus_channel; ++ indio_dev->num_channels = 1; ++ ++ return devm_iio_device_register(&client->dev, indio_dev); ++} ++ ++static const struct of_device_id orion_vbus_of_match[] = { ++ { .compatible = "apple,orion-bellatrix-vbus" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, orion_vbus_of_match); ++ ++static struct i2c_driver orion_vbus_driver = { ++ .driver = { ++ .name = "apple-orion-vbus", ++ .of_match_table = orion_vbus_of_match, ++ }, ++ .probe = orion_vbus_probe, ++}; ++module_i2c_driver(orion_vbus_driver); ++ ++MODULE_DESCRIPTION("Apple Orion Bellatrix Lightning VBUS ADC"); ++MODULE_LICENSE("GPL"); diff --git a/kernel/patches/drivers/iio/0017-dt-bindings-iio-describe-the-Orion-VBUS-channel.patch b/kernel/patches/drivers/iio/0017-dt-bindings-iio-describe-the-Orion-VBUS-channel.patch new file mode 100644 index 00000000..bc44ebe8 --- /dev/null +++ b/kernel/patches/drivers/iio/0017-dt-bindings-iio-describe-the-Orion-VBUS-channel.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 12:45:19 +0100 +Subject: [PATCH] dt-bindings: iio: describe the Orion VBUS channel + +Assisted-by: LLM +--- + .../bindings/iio/adc/apple,orion-bellatrix-vbus.yaml | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml b/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml +index 265eb4086..c3eb58e0b 100644 +--- a/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml ++++ b/Documentation/devicetree/bindings/iio/adc/apple,orion-bellatrix-vbus.yaml +@@ -13,6 +13,9 @@ description: + Orion Bellatrix provides an ADC input wired to Lightning VBUS on J120. + + properties: ++ "#io-channel-cells": ++ const: 1 ++ + compatible: + const: apple,orion-bellatrix-vbus + diff --git a/kernel/patches/drivers/input/0032-dt-bindings-input-apple-z2-describe-the-J120-touchsc.patch b/kernel/patches/drivers/input/0032-dt-bindings-input-apple-z2-describe-the-J120-touchsc.patch new file mode 100644 index 00000000..3a25a3f0 --- /dev/null +++ b/kernel/patches/drivers/input/0032-dt-bindings-input-apple-z2-describe-the-J120-touchsc.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:53 +0100 +Subject: [PATCH] dt-bindings: input: apple-z2: describe the J120 touchscreen + +Describe the J120 touchscreen supply, enable GPIO, display-sync pin states and firmware calibration properties. + +Assisted-by: LLM +--- + .../touchscreen/apple,z2-multitouch.yaml | 29 +++++++++++++++++++ + 1 file changed, 29 insertions(+) + +diff --git a/Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml b/Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml +index 4a89d6bbe..3d3b9320c 100644 +--- a/Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml ++++ b/Documentation/devicetree/bindings/input/touchscreen/apple,z2-multitouch.yaml +@@ -22,6 +22,7 @@ properties: + - apple,j72-touchscreen + - apple,j81-touchscreen + - apple,j96-touchscreen ++ - apple,j120-touchscreen + - apple,j172-touchscreen + - apple,d11-touchscreen + - apple,d111-touchscreen +@@ -155,6 +156,33 @@ required: + - touchscreen-size-y + + allOf: ++ - if: ++ properties: ++ compatible: ++ const: apple,j120-touchscreen ++ then: ++ properties: ++ pinctrl-names: ++ items: ++ - const: display-sync-active ++ - const: display-sync-inactive ++ power-ana-gpios: false ++ display-sync-gpios: false ++ display-sync1-gpios: false ++ hv-supply: false ++ core-supply: false ++ attn-gpios: false ++ apple,z2-bpw16-min-len: false ++ apple,z2-no-init-ack: false ++ required: ++ - clocks ++ - ana-supply ++ - power-ldo-gpios ++ - pinctrl-0 ++ - pinctrl-1 ++ - pinctrl-names ++ - spi-cpha ++ - spi-cpol + - $ref: touchscreen.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + - if: +@@ -238,6 +266,7 @@ allOf: + - apple,j72-touchscreen + - apple,j81-touchscreen + - apple,j96-touchscreen ++ - apple,j120-touchscreen + - apple,n61-touchscreen + then: + properties: diff --git a/kernel/patches/drivers/input/0033-Input-apple_z2-support-J120-HBPP14-and-float-contact.patch b/kernel/patches/drivers/input/0033-Input-apple_z2-support-J120-HBPP14-and-float-contact.patch new file mode 100644 index 00000000..965ee00a --- /dev/null +++ b/kernel/patches/drivers/input/0033-Input-apple_z2-support-J120-HBPP14-and-float-contact.patch @@ -0,0 +1,1025 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:53 +0100 +Subject: [PATCH] Input: apple_z2: support J120 HBPP14 and float contact + reports + +Reuse HBPP14 upload and the existing floating-point contact parser for J120. Preserve chip-specific power sequencing, native SPI timing, split PIO replies and empty-reply counter advancement. Validate per-unit calibration and geometry before registering multitouch input; quiesce the IRQ before teardown. Do not expose bring-up capture interfaces or diagnostic module parameters. + +Assisted-by: LLM +--- + drivers/input/touchscreen/apple_z2.c | 564 ++++++++++++++++++++++++--- + 1 file changed, 512 insertions(+), 52 deletions(-) + +diff --git a/drivers/input/touchscreen/apple_z2.c b/drivers/input/touchscreen/apple_z2.c +index 0621a0b60..c3f3587b0 100644 +--- a/drivers/input/touchscreen/apple_z2.c ++++ b/drivers/input/touchscreen/apple_z2.c +@@ -140,6 +140,7 @@ enum apple_z2_protocol_state { + enum apple_z2_variant { + APPLE_Z2_VARIANT_GENERIC, + APPLE_Z2_VARIANT_J172, ++ APPLE_Z2_VARIANT_J120, + APPLE_Z2_VARIANT_J71B, + APPLE_Z2_VARIANT_J71T, + APPLE_Z2_VARIANT_D11, +@@ -227,6 +228,8 @@ struct apple_z2_chip_info { + unsigned int upload_hz; /* firmware upload clock, if above the device's */ + }; + ++#define APPLE_Z2_J120_MAX_PACKET_SIZE 16384 ++ + struct apple_z2 { + struct spi_device *spidev; + const struct apple_z2_chip_info *info; +@@ -252,6 +255,10 @@ struct apple_z2 { + bool j72_contacts_active; + int j72_layout_error; + int j72_spi_error; ++ struct delayed_work stop_work; ++ u8 *packet_buf; ++ bool j120_input_registered; ++ int runtime_error; + struct work_struct resume_work; + bool boot_due; /* resumed: boot once every device is back */ + unsigned int rearm_attempts; +@@ -307,6 +314,11 @@ static bool apple_z2_uses_ipad_protocol(const struct apple_z2 *z2) + z2->variant == APPLE_Z2_VARIANT_J71B; + } + ++static bool apple_z2_is_j120(const struct apple_z2 *z2) ++{ ++ return z2->variant == APPLE_Z2_VARIANT_J120; ++} ++ + static bool apple_z2_is_j71b(const struct apple_z2 *z2) + { + return z2->variant == APPLE_Z2_VARIANT_J71B; +@@ -385,6 +397,13 @@ static bool apple_z2_is_iphone7_plus(const struct apple_z2 *z2) + return apple_z2_is_d11(z2) || apple_z2_is_d111(z2); + } + ++/* HBPP14 boot framing is shared independently of the runtime protocol. */ ++static bool apple_z2_uses_hbpp14(const struct apple_z2 *z2) ++{ ++ return apple_z2_uses_ipad_protocol(z2) || ++ apple_z2_is_iphone7_plus(z2) || apple_z2_is_j120(z2); ++} ++ + struct apple_z2_finger { + u8 finger; + u8 state; +@@ -449,6 +468,8 @@ static void apple_z2_j72_power_off(struct apple_z2 *z2); + static int apple_z2_j72_finish_boot(struct apple_z2 *z2); + static void apple_z2_j72_work(struct work_struct *work); + static void apple_z2_resume_work(struct work_struct *work); ++static void apple_z2_stop(struct apple_z2 *z2); ++static int apple_z2_set_surface(struct apple_z2 *z2, const u8 *descriptor); + + static bool apple_z2_float_to_integer(const u8 *raw, s64 *value) + { +@@ -539,13 +560,13 @@ static void apple_z2_parse_j172_touches(struct apple_z2 *z2, + unsigned int contact_offset; + unsigned int contact_bytes; + unsigned int nfingers; +- unsigned int x; +- unsigned int y; ++ unsigned int x[APPLE_Z2_J172_MAX_CONTACTS]; ++ unsigned int y[APPLE_Z2_J172_MAX_CONTACTS]; ++ bool seen[256] = { false }; + unsigned int i; + const u8 *contact; + int slot; + bool active; +- bool coords_valid; + + if (msg_len < APPLE_Z2_J172_HEADER_SIZE) + return; +@@ -571,6 +592,25 @@ static void apple_z2_parse_j172_touches(struct apple_z2 *z2, + return; + } + ++ /* Validate the complete frame before changing any input slot state. */ ++ contact = msg + contact_offset; ++ for (i = 0; i < nfingers; i++, contact += APPLE_Z2_J172_CONTACT_SIZE) { ++ if (seen[contact[0]]) ++ return; ++ seen[contact[0]] = true; ++ active = contact[1] == APPLE_Z2_TOUCH_STARTED || ++ contact[1] == APPLE_Z2_TOUCH_MOVED; ++ if (!active) ++ continue; ++ if (!apple_z2_scale_j172_coord(contact + 4, ++ z2->sensor_max_x, z2->sensor_min_x, ++ z2->props.max_x, &x[i]) || ++ !apple_z2_scale_j172_coord(contact + 8, ++ z2->sensor_max_y, z2->sensor_min_y, ++ z2->props.max_y, &y[i])) ++ return; ++ } ++ + contact = msg + contact_offset; + for (i = 0; i < nfingers; i++, contact += APPLE_Z2_J172_CONTACT_SIZE) { + slot = input_mt_get_slot_by_key(z2->input_dev, contact[0]); +@@ -586,23 +626,8 @@ static void apple_z2_parse_j172_touches(struct apple_z2 *z2, + if (!input_mt_report_slot_state(z2->input_dev, MT_TOOL_FINGER, active)) + continue; + +- coords_valid = apple_z2_scale_j172_coord(contact + 4, +- z2->sensor_max_x, +- z2->sensor_min_x, +- z2->props.max_x, &x); +- if (coords_valid) +- coords_valid = apple_z2_scale_j172_coord(contact + 8, +- z2->sensor_max_y, +- z2->sensor_min_y, +- z2->props.max_y, &y); +- if (!coords_valid) { +- dev_warn_ratelimited(&z2->spidev->dev, +- "invalid J172 touch coordinates\n"); +- continue; +- } +- +- touchscreen_report_pos(z2->input_dev, &z2->props, x, +- z2->props.max_y - y, true); ++ touchscreen_report_pos(z2->input_dev, &z2->props, x[i], ++ z2->props.max_y - y[i], true); + } + + input_mt_sync_frame(z2->input_dev); +@@ -924,6 +949,103 @@ static int apple_z2_gen1_exchange(struct apple_z2 *z2, u8 *buf, size_t len) + return error; + } + ++/* J120 keeps CS asserted across short PIO chunks for long replies. */ ++static int apple_z2_j120_short_xfer(struct apple_z2 *z2, u8 *buffer, size_t length) ++{ ++ struct spi_transfer *chunks __free(kfree) = NULL; ++ unsigned int count, i; ++ size_t offset = 0; ++ ++ if (!length || length > APPLE_Z2_J120_MAX_PACKET_SIZE) ++ return -EMSGSIZE; ++ count = DIV_ROUND_UP(length, APPLE_Z2_CMD_SIZE); ++ chunks = kcalloc(count, sizeof(*chunks), GFP_KERNEL); ++ if (!chunks) ++ return -ENOMEM; ++ for (i = 0; i < count; i++) { ++ chunks[i].tx_buf = buffer + offset; ++ chunks[i].rx_buf = buffer + offset; ++ chunks[i].len = min_t(size_t, APPLE_Z2_CMD_SIZE, length - offset); ++ chunks[i].bits_per_word = 8; ++ offset += chunks[i].len; ++ } ++ return spi_sync_transfer(z2->spidev, chunks, count); ++} ++ ++/* Only the observed J120 float-contact envelope may reach Linux input. */ ++static void apple_z2_j120_report_input(struct apple_z2 *z2, const u8 *wire) ++{ ++ size_t length = get_unaligned_le16(wire + 2) - 2; ++ const u8 *payload = wire + 5; ++ const u8 *report = payload + 4; ++ size_t report_len; ++ ++ if (!z2->j120_input_registered || length < 4 || ++ payload[0] != APPLE_Z2_FRAME_INPUT_REPORT || ++ !(payload[1] & APPLE_Z2_INTERFACE_GRAPE)) ++ return; ++ report_len = get_unaligned_le16(payload + 2); ++ if (report_len < APPLE_Z2_J172_HEADER_SIZE || report_len != length - 4 || ++ report[0] != APPLE_Z2_HID_REPORT_ID || report[3] != 4) ++ return; ++ apple_z2_parse_j172_touches(z2, report, report_len); ++} ++ ++/* Receive the checked J120 envelope and dispatch native-scaled Linux input. */ ++static int apple_z2_j120_read_packet(struct apple_z2 *z2) ++{ ++ struct spi_transfer xfer = { ++ .tx_buf = z2->tx_buf, ++ .rx_buf = z2->rx_buf, ++ .len = APPLE_Z2_CMD_SIZE, ++ .bits_per_word = 8, ++ }; ++ size_t length; ++ u16 payload; ++ u8 counter = z2->index_parity + 1; ++ int error; ++ ++ z2->runtime_frame_valid = false; ++ memset(z2->tx_buf, 0, APPLE_Z2_CMD_SIZE); ++ memset(z2->rx_buf, 0, APPLE_Z2_CMD_SIZE); ++ z2->tx_buf[0] = APPLE_Z2_CMD_READ_INTERRUPT_DATA; ++ z2->tx_buf[1] = counter; ++ apple_z2_z2_checksum(z2->tx_buf, APPLE_Z2_CMD_SIZE); ++ error = spi_sync_transfer(z2->spidev, &xfer, 1); ++ if (error) ++ return error; ++ ++ apple_z2_post_z2_xfer_delay(z2); ++ if (!apple_z2_z2_checksum_valid(z2->rx_buf, APPLE_Z2_CMD_SIZE)) ++ return -EBADMSG; ++ if (z2->rx_buf[0] != APPLE_Z2_REPLY_INTERRUPT_DATA) ++ return -EPROTO; ++ payload = get_unaligned_le16(z2->rx_buf + 1); ++ if (!payload) { ++ /* Native ProtocolZ2 advances its counter on empty replies too. */ ++ z2->index_parity = !z2->index_parity; ++ ++ return 0; ++ } ++ length = ((size_t)payload + 8) & ~(size_t)3; ++ if (length < 7 || length > APPLE_Z2_J120_MAX_PACKET_SIZE) ++ return -EMSGSIZE; ++ memset(z2->packet_buf, 0xa5, length); ++ error = apple_z2_j120_short_xfer(z2, z2->packet_buf, length); ++ if (error) ++ return error; ++ apple_z2_post_z2_xfer_delay(z2); ++ ++ if (!apple_z2_gen2_packet_valid(z2->packet_buf, length, ++ counter, true, true)) ++ return -EBADMSG; ++ apple_z2_j120_report_input(z2, z2->packet_buf); ++ ++ z2->runtime_frame_valid = true; ++ z2->index_parity = !z2->index_parity; ++ return 0; ++} ++ + static int apple_z2_read_packet(struct apple_z2 *z2) + { + struct spi_transfer xfer = { }; +@@ -936,6 +1058,9 @@ static int apple_z2_read_packet(struct apple_z2 *z2) + u16 payload_len; + u8 counter; + ++ if (apple_z2_is_j120(z2)) ++ return apple_z2_j120_read_packet(z2); ++ + z2->runtime_frame_valid = false; + z2->runtime_queue_empty = false; + z2->runtime_control_reply = false; +@@ -1114,8 +1239,13 @@ static int apple_z2_advance_protocol(struct apple_z2 *z2, + enum apple_z2_protocol_state expected, + enum apple_z2_protocol_state next) + { +- if (z2->protocol_state != expected) ++ if (z2->protocol_state != expected) { ++ if (apple_z2_is_j120(z2)) ++ dev_err(&z2->spidev->dev, ++ "J120 protocol state %u expected %u before %u\n", ++ z2->protocol_state, expected, next); + return -EPROTO; ++ } + + z2->protocol_state = next; + return 0; +@@ -1160,6 +1290,8 @@ static unsigned int apple_z2_effective_cs_delay_us(struct apple_z2 *z2) + /* J172 firmware expresses this field in ns; Linux SPI uses us here. */ + if (apple_z2_uses_gen1_data(z2)) + return z2->info->cs_setup_us; ++ if (apple_z2_is_j120(z2)) ++ return DIV_ROUND_UP(z2->z2_cs_delay_us, 1000); + return apple_z2_uses_ipad_protocol(z2) ? 10 : z2->z2_cs_delay_us; + } + +@@ -1208,7 +1340,8 @@ static void apple_z2_avoid_short_dma(struct apple_z2 *z2, + * an RX buffer makes shorter writes full-duplex, which the T8010 + * controller handles through PIO without changing the wire transfer. + */ +- if (!apple_z2_is_iphone7_plus(z2) || !z2->dma_min_len || ++ if ((!apple_z2_is_iphone7_plus(z2) && !apple_z2_is_j120(z2)) || ++ !z2->dma_min_len || + !xfer->tx_buf || xfer->rx_buf || + xfer->len >= z2->dma_min_len) + return; +@@ -1279,8 +1412,10 @@ static int apple_z2_read_device_info_locked(struct apple_z2 *z2) + u16 max_packet_size; + u8 interface_version; + u8 platform_id; ++ bool checksum_valid; + int error; + ++ /* Matching K1 ProtocolZ2 supports wake before DeviceInfo discovery. */ + error = apple_z2_z2_cmd_locked_delay(z2, APPLE_Z2_CMD_WAKE, 0, + "device-info-wake", false); + if (error) +@@ -1291,21 +1426,37 @@ static int apple_z2_read_device_info_locked(struct apple_z2 *z2) + "device-info", false); + if (error) + return error; ++ + apple_z2_post_z2_xfer_delay(z2); + ++ /* Matching K1 ProtocolZ2 retrieves DeviceInfo with LAST (0xe1). */ + error = apple_z2_z2_cmd_locked_delay(z2, APPLE_Z2_CMD_LAST, 0, +- "device-info-last", false); ++ "device-info-reply", false); + if (error) + return error; + +- if (z2->rx_buf[0] != APPLE_Z2_CMD_DEVICE_INFO || +- !apple_z2_z2_checksum_valid(z2->rx_buf, APPLE_Z2_CMD_SIZE)) ++ checksum_valid = apple_z2_z2_checksum_valid(z2->rx_buf, APPLE_Z2_CMD_SIZE); ++ if (z2->rx_buf[0] != APPLE_Z2_CMD_DEVICE_INFO || !checksum_valid) { ++ if (apple_z2_is_j120(z2)) ++ dev_err(&z2->spidev->dev, ++ "J120 DeviceInfo rejected: opcode=%#x checksum-valid=%u\n", ++ z2->rx_buf[0], checksum_valid); + return -EPROTO; ++ } + + platform_id = z2->rx_buf[1]; + interface_version = z2->rx_buf[2]; + max_packet_size = get_unaligned_le16(z2->rx_buf + 3); + ++ if (apple_z2_is_j120(z2)) { ++ if (max_packet_size < APPLE_Z2_CMD_SIZE || ++ max_packet_size > APPLE_Z2_J120_MAX_PACKET_SIZE - 8) ++ return -EMSGSIZE; ++ dev_info(&z2->spidev->dev, ++ "J120 DeviceInfo: platform=%u interface=%u max-packet=%u\n", ++ platform_id, interface_version, max_packet_size); ++ } ++ + dev_dbg(&z2->spidev->dev, + "device info: platform=%u interface=%u max-packet=%u\n", + platform_id, interface_version, max_packet_size); +@@ -1445,7 +1596,10 @@ static int apple_z2_read_report_locked(struct apple_z2 *z2, u8 report, + xfer.tx_buf = z2->rx_buf; + xfer.rx_buf = z2->rx_buf; + xfer.len = data_len; +- error = apple_z2_spi_transfer(z2, &xfer, 1); ++ if (apple_z2_is_j120(z2)) ++ error = apple_z2_j120_short_xfer(z2, z2->rx_buf, data_len); ++ else ++ error = apple_z2_spi_transfer(z2, &xfer, 1); + } + if (error) + return error; +@@ -1455,6 +1609,32 @@ static int apple_z2_read_report_locked(struct apple_z2 *z2, u8 report, + return 0; + } + ++/* Obtain the native sensor extent before registering the input device. */ ++static int apple_z2_j120_read_surface(struct apple_z2 *z2) ++{ ++ u16 length; ++ u8 status; ++ int error; ++ ++ /* Allow the firmware to finish initializing its surface metadata. */ ++ msleep(100); ++ error = apple_z2_read_report_info_locked(z2, APPLE_Z2_REPORT_SURFACE, ++ &status, &length, "j120-surface"); ++ if (error) ++ return error; ++ if (status || length != APPLE_Z2_SURFACE_DESCRIPTOR_SIZE) ++ return -EPROTO; ++ error = apple_z2_read_report_locked(z2, APPLE_Z2_REPORT_SURFACE, ++ length, "j120-surface-read"); ++ if (error) ++ return error; ++ if (z2->rx_buf[0] != APPLE_Z2_CMD_CTRL_READ_LONG || ++ z2->rx_buf[1] != APPLE_Z2_REPORT_SURFACE || z2->rx_buf[2] || ++ !apple_z2_z2_checksum_valid(z2->rx_buf, length + 5)) ++ return -EPROTO; ++ return apple_z2_set_surface(z2, z2->rx_buf + 3); ++} ++ + /* + * Surface descriptor (report 0xd9): LE32 width and height in 0.01 mm, then + * the signed LE16 left, bottom, right and top edges. +@@ -2284,6 +2464,44 @@ static void apple_z2_queue_control_recovery(struct apple_z2 *z2) + schedule_delayed_work(&z2->rearm_work, 0); + } + ++/* Block new runtime work and drain even an IRQ that masked itself on error. */ ++static void apple_z2_j120_quiesce_irq(struct apple_z2 *z2) ++{ ++ bool irq_on; ++ ++ mutex_lock(&z2->io_lock); ++ z2->stopping = true; ++ irq_on = z2->irq_on; ++ z2->irq_on = false; ++ mutex_unlock(&z2->io_lock); ++ if (irq_on) ++ disable_irq(z2->spidev->irq); ++ else ++ synchronize_irq(z2->spidev->irq); ++} ++ ++/* No IRQ may queue stop_work after cancellation returns. */ ++static void apple_z2_cancel_runtime_stop(struct apple_z2 *z2) ++{ ++ if (apple_z2_is_j120(z2)) ++ apple_z2_j120_quiesce_irq(z2); ++ cancel_delayed_work_sync(&z2->stop_work); ++} ++ ++static void apple_z2_j120_runtime_stop(struct work_struct *work) ++{ ++ struct apple_z2 *z2 = container_of(to_delayed_work(work), ++ struct apple_z2, stop_work); ++ ++ mutex_lock(&z2->io_lock); ++ z2->stopping = true; ++ mutex_unlock(&z2->io_lock); ++ synchronize_irq(z2->spidev->irq); ++ apple_z2_stop(z2); ++ dev_info(&z2->spidev->dev, "J120 input stopped (error %d)\n", ++ z2->runtime_error); ++} ++ + static irqreturn_t apple_z2_irq(int irq, void *data) + { + struct apple_z2 *z2 = data; +@@ -2293,6 +2511,19 @@ static irqreturn_t apple_z2_irq(int irq, void *data) + return IRQ_HANDLED; + if (unlikely(!z2->booted)) { + complete(&z2->boot_irq); ++ } else if (apple_z2_is_j120(z2)) { ++ mutex_lock(&z2->io_lock); ++ if (!z2->stopping && z2->irq_on) { ++ error = apple_z2_j120_read_packet(z2); ++ z2->runtime_error = error; ++ if (error) { ++ z2->stopping = true; ++ z2->irq_on = false; ++ disable_irq_nosync(z2->spidev->irq); ++ mod_delayed_work(system_wq, &z2->stop_work, 0); ++ } ++ } ++ mutex_unlock(&z2->io_lock); + } else if (apple_z2_is_j71t(z2)) { + mutex_lock(&z2->io_lock); + apple_z2_n1_irq_locked(z2); +@@ -2456,6 +2687,33 @@ static void apple_z2_platform_power_off(struct apple_z2 *z2) + if (apple_z2_is_gen1(z2)) + apple_z2_gen1_restore_irq_type(z2); + ++ if (apple_z2_is_j120(z2)) { ++ gpiod_set_value_cansleep(z2->reset_gpio, 1); ++ if (z2->clk_enabled) { ++ clk_disable_unprepare(z2->clk); ++ z2->clk_enabled = false; ++ } ++ error = pinctrl_select_state(z2->sync_pinctrl, ++ z2->sync_inactive); ++ if (error) ++ dev_warn(&z2->spidev->dev, ++ "failed to stop J120 display sync: %d\n", error); ++ apple_z2_set_gpio(z2->power_ldo_gpio, 0); ++ if (z2->ana_enabled) { ++ error = regulator_disable(z2->ana_supply); ++ if (error) { ++ dev_warn(&z2->spidev->dev, ++ "failed to disable J120 analog supply: %d\n", ++ error); ++ } else { ++ z2->ana_enabled = false; ++ usleep_range(10000, 11000); ++ } ++ } ++ z2->platform_powered = false; ++ return; ++ } ++ + if (apple_z2_uses_n1(z2)) { + gpiod_set_value_cansleep(z2->reset_gpio, 1); + error = z2->sync_active ? +@@ -2489,7 +2747,7 @@ static void apple_z2_platform_power_off(struct apple_z2 *z2) + clk_disable_unprepare(z2->clk); + z2->clk_enabled = false; + } +- if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) ++ if (apple_z2_uses_hbpp14(z2)) + usleep_range(1000, 2000); + + if (apple_z2_is_j71b(z2)) { +@@ -2523,7 +2781,7 @@ static void apple_z2_platform_power_off(struct apple_z2 *z2) + return; + } + +- if (apple_z2_uses_ipad_protocol(z2)) { ++ if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_j120(z2)) { + error = apple_z2_j172_sync_set_inactive(z2); + if (error) + dev_warn(&z2->spidev->dev, +@@ -2553,6 +2811,45 @@ static int apple_z2_enable_clock(struct apple_z2 *z2) + return 0; + } + ++/* J120 ADT: analog, LDO, all three sync pins, reference clock, 15 ms. */ ++static int apple_z2_j120_power_on(struct apple_z2 *z2) ++{ ++ const char *stage = "analog supply"; ++ int error; ++ ++ gpiod_set_value_cansleep(z2->reset_gpio, 1); ++ /* A failed analog disable must not accumulate regulator enable counts. */ ++ if (z2->ana_enabled) ++ return -EBUSY; ++ error = regulator_enable(z2->ana_supply); ++ if (error) ++ return dev_err_probe(&z2->spidev->dev, error, ++ "J120 analog supply enable failed\n"); ++ z2->ana_enabled = true; ++ apple_z2_set_gpio(z2->power_ldo_gpio, 1); ++ stage = "active sync pins"; ++ error = pinctrl_select_state(z2->sync_pinctrl, z2->sync_active); ++ if (error) ++ goto err_power_off; ++ stage = "reference clock"; ++ error = apple_z2_enable_clock(z2); ++ if (error) ++ goto err_power_off; ++ usleep_range(15000, 16000); ++ stage = "powered protocol state"; ++ error = apple_z2_advance_protocol(z2, APPLE_Z2_STATE_OFF, ++ APPLE_Z2_STATE_POWERED); ++ if (error) ++ goto err_power_off; ++ z2->platform_powered = true; ++ return 0; ++ ++err_power_off: ++ apple_z2_platform_power_off(z2); ++ return dev_err_probe(&z2->spidev->dev, error, ++ "J120 power-on failed at %s\n", stage); ++} ++ + static int apple_z2_j172_power_on(struct apple_z2 *z2) + { + int error; +@@ -2730,6 +3027,8 @@ static int apple_z2_platform_power_on(struct apple_z2 *z2) + if (z2->platform_powered) + return 0; + ++ if (apple_z2_is_j120(z2)) ++ return apple_z2_j120_power_on(z2); + if (apple_z2_is_j71b(z2)) + return apple_z2_j71b_power_on(z2); + if (apple_z2_uses_n1(z2)) +@@ -3387,6 +3686,7 @@ static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data, + .len = 2, + .bits_per_word = 8, + }; ++ u16 expected_ack = 0; + bool ready; + int error; + +@@ -3399,7 +3699,7 @@ static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data, + * swap every byte pair a second time. + */ + if (!init && !apple_z2_is_iphone7_plus(z2) && +- size >= z2->bpw16_min_len) ++ !apple_z2_is_j120(z2) && size >= z2->bpw16_min_len) + blob_xfer.bits_per_word = 16; + if (init && apple_z2_is_j71b(z2)) + blob_xfer.speed_hz = 500000; +@@ -3409,7 +3709,7 @@ static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data, + dev_dbg(&z2->spidev->dev, "firmware blob len=%u bpw=%u\n", + size, blob_xfer.bits_per_word); + +- if ((apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) && init) { ++ if (apple_z2_uses_hbpp14(z2) && init) { + if (size != 4 || data[0] != 0x1a || data[1] != 0xa1 || + data[2] != 0x18 || data[3] != 0xe1) + return dev_err_probe(&z2->spidev->dev, -EINVAL, +@@ -3422,12 +3722,25 @@ static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data, + z2->tx_buf[0] = 0x1a; + z2->tx_buf[1] = 0xa1; + apple_z2_avoid_short_dma(z2, &ack_xfer); ++ if (apple_z2_is_j120(z2) && !init) { ++ if (size >= 20 && get_unaligned_be32(data) == 0x18e13001) { ++ expected_ack = APPLE_Z2_HBPP_ACK_BLOB; ++ } else if (size == 16 && get_unaligned_be16(data) == 0x1e33) { ++ /* The final boot write transitions into the runtime. */ ++ expected_ack = defer_irq_wait ? 0 : APPLE_Z2_HBPP_ACK_WRITE; ++ } else { ++ return -EINVAL; ++ } ++ memset(z2->rx_buf, 0, ack_xfer.len); ++ ack_xfer.rx_buf = z2->rx_buf; ++ } ++ + reinit_completion(&z2->boot_irq); + error = spi_sync_transfer(z2->spidev, &blob_xfer, 1); + if (error) + return error; + +- if ((apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) && init) { ++ if (apple_z2_uses_hbpp14(z2) && init) { + ready = z2->rx_buf[0] == 0x1f && z2->rx_buf[1] == 0x01; + if (!ready) + return dev_err_probe(&z2->spidev->dev, -EPROTO, +@@ -3439,9 +3752,13 @@ static int apple_z2_send_firmware_blob(struct apple_z2 *z2, const u8 *data, + error = spi_sync_transfer(z2->spidev, &ack_xfer, 1); + if (error) + return error; ++ if (expected_ack && ++ get_unaligned_be16(z2->rx_buf) != expected_ack) ++ return dev_err_probe(&z2->spidev->dev, -EPROTO, ++ "J120 HBPP acknowledgment mismatch\n"); + apple_z2_post_ack_delay(z2); + } +- if ((apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) && init) { ++ if (apple_z2_uses_hbpp14(z2) && init) { + error = apple_z2_advance_protocol(z2, APPLE_Z2_STATE_BOOT_IRQ, + APPLE_Z2_STATE_HBPP_READY); + if (error) +@@ -3533,9 +3850,11 @@ static bool apple_z2_wait_firmware_irq(struct apple_z2 *z2, u32 timeout_ms) + + static int apple_z2_wait_ready_irq(struct apple_z2 *z2, u32 timeout_ms) + { ++ + if (!apple_z2_wait_firmware_irq(z2, timeout_ms)) + return -ETIMEDOUT; +- if (!apple_z2_uses_ipad_protocol(z2) && !apple_z2_is_iphone7_plus(z2)) ++ ++ if (!apple_z2_uses_hbpp14(z2)) + return 0; + + if (apple_z2_uses_ipad_protocol(z2) && +@@ -3559,6 +3878,7 @@ static int apple_z2_apply_fw_config(struct apple_z2 *z2, const u8 *data, + struct spi_device *spi = z2->spidev; + u32 valid, min_dma, z2_delay, cs_delay, cpha, cpol, boot_timeout; + u32 mode = spi->mode; ++ u32 old_speed_hz = spi->max_speed_hz; + int error; + + if (size < APPLE_Z2_FW_CONFIG_WORDS * sizeof(__le32)) +@@ -3574,7 +3894,7 @@ static int apple_z2_apply_fw_config(struct apple_z2 *z2, const u8 *data, + z2->hbpp_version = (valid & APPLE_Z2_FW_CONFIG_HBPP_VERSION) ? + apple_z2_fw_config_word(data, 10) : 0; + if ((valid & APPLE_Z2_FW_CONFIG_MIN_DMA) && min_dma) { +- if (apple_z2_is_iphone7_plus(z2)) { ++ if (apple_z2_is_iphone7_plus(z2) || apple_z2_is_j120(z2)) { + if (min_dma > APPLE_Z2_RX_BUF_SIZE) + return -EINVAL; + z2->dma_min_len = min_dma; +@@ -3608,13 +3928,24 @@ static int apple_z2_apply_fw_config(struct apple_z2 *z2, const u8 *data, + mode &= ~SPI_CPOL; + } + +- if (mode != spi->mode) { ++ if (apple_z2_is_j120(z2)) { ++ u32 period_ns = apple_z2_fw_config_word(data, 7); ++ ++ /* Native SamsungSPI uses ceil(nclk * period / 10^9). */ ++ if (!period_ns || period_ns > NSEC_PER_SEC || ++ !cs_delay || cs_delay > U16_MAX * 1000U) ++ return -EINVAL; ++ spi->max_speed_hz = NSEC_PER_SEC / period_ns; ++ } ++ ++ if (mode != spi->mode || apple_z2_is_j120(z2)) { + u32 old_mode = spi->mode; + + spi->mode = mode; + error = spi_setup(spi); + if (error) { + spi->mode = old_mode; ++ spi->max_speed_hz = old_speed_hz; + return error; + } + } +@@ -3666,6 +3997,11 @@ static int apple_z2_upload_firmware(struct apple_z2 *z2) + size = get_unaligned_le32(fw->data + fw_idx); + fw_idx += sizeof(__le32); + ++ if (apple_z2_is_j120(z2)) ++ dev_info(&z2->spidev->dev, ++ "J120 firmware command %u offset %zu size %zu\n", ++ load_cmd, fw_idx, size); ++ + /* + * The N1 bootloader is found by its NOP probe and needs no boot + * interrupt; its packets are checked through ATN_ACK, and its +@@ -3754,7 +4090,8 @@ static int apple_z2_upload_firmware(struct apple_z2 *z2) + + if (!apple_z2_is_iphone7_plus(z2) && + !apple_z2_uses_ipad_protocol(z2) && +- !apple_z2_is_n61(z2) && !apple_z2_uses_n1(z2)) ++ !apple_z2_is_n61(z2) && !apple_z2_uses_n1(z2) && ++ !apple_z2_is_j120(z2)) + return -EINVAL; + if (size != sizeof(struct apple_z2_fw_calibration) || + size > fw->size - fw_idx) +@@ -3806,11 +4143,14 @@ static int apple_z2_upload_firmware(struct apple_z2 *z2) + error = apple_z2_wait_ready_irq(z2, timeout_ms); + if (error) + return error; +- if (apple_z2_uses_ipad_protocol(z2)) { ++ if (apple_z2_is_j120(z2)) ++ dev_info(&z2->spidev->dev, ++ "J120 runtime readiness IRQ/state accepted\n"); ++ if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_j120(z2)) { + apple_z2_irq_off(z2); + error = apple_z2_read_device_info_locked(z2); + /* J71b: stay masked until its first reports are read. */ +- if (apple_z2_is_j71b(z2)) ++ if (apple_z2_is_j71b(z2) || apple_z2_is_j120(z2)) + z2->upload_irq_masked = true; + else + apple_z2_irq_on(z2); +@@ -3825,6 +4165,30 @@ static int apple_z2_upload_firmware(struct apple_z2 *z2) + fw_idx = round_up(fw_idx, 4); + } + ++ if (apple_z2_is_j120(z2)) { ++ error = apple_z2_j120_read_surface(z2); ++ if (error) ++ return dev_err_probe(&z2->spidev->dev, error, ++ "J120 surface query failed\n"); ++ error = apple_z2_advance_protocol(z2, APPLE_Z2_STATE_DEVICE_INFO, ++ APPLE_Z2_STATE_RUNTIME); ++ if (error) ++ return error; ++ if (!z2->j120_input_registered) { ++ error = input_register_device(z2->input_dev); ++ if (error) ++ return error; ++ z2->j120_input_registered = true; ++ } ++ mutex_lock(&z2->io_lock); ++ z2->stopping = false; ++ z2->booted = true; ++ z2->upload_irq_masked = false; ++ apple_z2_irq_on(z2); ++ mutex_unlock(&z2->io_lock); ++ return 0; ++ } ++ + if (apple_z2_is_j72(z2)) + return apple_z2_j72_finish_boot(z2); + if (apple_z2_uses_n1(z2)) +@@ -4091,6 +4455,7 @@ static int apple_z2_j71t_boot(struct apple_z2 *z2) + + static int apple_z2_boot(struct apple_z2 *z2) + { ++ const char *stage = "platform power"; + bool irq_enabled = false; + int error; + +@@ -4102,15 +4467,21 @@ static int apple_z2_boot(struct apple_z2 *z2) + z2->booted = false; + apple_z2_reset_protocol(z2); + error = apple_z2_platform_power_on(z2); +- if (error) ++ if (error) { ++ if (apple_z2_is_j120(z2)) ++ dev_err_probe(&z2->spidev->dev, error, ++ "J120 bootstrap failed at %s\n", stage); + return error; ++ } + +- if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) { ++ if (apple_z2_uses_hbpp14(z2)) { ++ stage = "initial firmware SPI config"; + error = apple_z2_apply_initial_config(z2); + if (error) + goto err_stop; + } +- if (apple_z2_uses_ipad_protocol(z2)) { ++ if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_j120(z2)) { ++ stage = "SPI zero preamble"; + error = apple_z2_boot_preamble(z2, false); + if (error) + goto err_stop; +@@ -4135,7 +4506,8 @@ static int apple_z2_boot(struct apple_z2 *z2) + /* J71b boots on reset release; a pulse would restart it. */ + gpiod_set_value_cansleep(z2->reset_gpio, 0); + error = 0; +- } else if (apple_z2_uses_ipad_protocol(z2)) { ++ } else if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_j120(z2)) { ++ stage = "reset pulse"; + error = apple_z2_pulse_reset(z2); + } else if (apple_z2_is_iphone7_plus(z2)) { + gpiod_set_value_cansleep(z2->reset_gpio, 0); +@@ -4148,12 +4520,14 @@ static int apple_z2_boot(struct apple_z2 *z2) + if (error) + goto err_stop; + ++ stage = "initial readiness IRQ"; + if (!wait_for_completion_timeout(&z2->boot_irq, + msecs_to_jiffies(z2->boot_timeout_ms))) { + error = -ETIMEDOUT; + goto err_stop; + } +- if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) { ++ if (apple_z2_uses_hbpp14(z2)) { ++ stage = "boot IRQ protocol state"; + error = apple_z2_advance_protocol(z2, + APPLE_Z2_STATE_SPI_CONFIGURED, + APPLE_Z2_STATE_BOOT_IRQ); +@@ -4166,11 +4540,12 @@ static int apple_z2_boot(struct apple_z2 *z2) + goto err_stop; + } + +- if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_iphone7_plus(z2)) { ++ if (apple_z2_uses_hbpp14(z2)) { + apple_z2_irq_off(z2); + z2->upload_irq_masked = true; + } + ++ stage = "firmware upload/runtime setup"; + error = apple_z2_upload_firmware(z2); + if (error) + goto err_stop; +@@ -4178,6 +4553,9 @@ static int apple_z2_boot(struct apple_z2 *z2) + return 0; + + err_stop: ++ if (apple_z2_is_j120(z2)) ++ dev_err_probe(&z2->spidev->dev, error, ++ "J120 bootstrap failed at %s\n", stage); + z2->booted = false; + if (z2->upload_irq_masked) { + z2->upload_irq_masked = false; +@@ -4744,6 +5122,11 @@ static const struct apple_z2_chip_info apple_z2_j72_info = { + .n1 = &apple_z2_j72_n1, + }; + ++static const struct apple_z2_chip_info apple_z2_j120_info = { ++ .name = "iPad Pro 12.9 (2017) Touchscreen", ++ .variant = APPLE_Z2_VARIANT_J120, ++}; ++ + static const struct apple_z2_chip_info apple_z2_j172_info = { + .name = "iPad 7 Touchscreen", + .variant = APPLE_Z2_VARIANT_J172, +@@ -4822,6 +5205,7 @@ static int apple_z2_probe(struct spi_device *spi) + apple_z2_control_rearm_work : apple_z2_n1_rearm_work); + INIT_DELAYED_WORK(&z2->j72_work, apple_z2_j72_work); + INIT_WORK(&z2->resume_work, apple_z2_resume_work); ++ INIT_DELAYED_WORK(&z2->stop_work, apple_z2_j120_runtime_stop); + spi_set_drvdata(spi, z2); + + z2->reset_gpio = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); +@@ -4891,6 +5275,26 @@ static int apple_z2_probe(struct spi_device *spi) + + if (apple_z2_is_j72(z2) && (!z2->sync_active || !z2->sync_inactive)) + return dev_err_probe(dev, -EINVAL, "missing J72 display-sync states\n"); ++ if (apple_z2_is_j120(z2)) { ++ z2->ana_supply = devm_regulator_get(dev, "ana"); ++ if (IS_ERR(z2->ana_supply)) ++ return dev_err_probe(dev, PTR_ERR(z2->ana_supply), ++ "unable to get J120 analog supply\n"); ++ z2->sync_pinctrl = devm_pinctrl_get(dev); ++ if (IS_ERR(z2->sync_pinctrl)) ++ return dev_err_probe(dev, PTR_ERR(z2->sync_pinctrl), ++ "unable to get J120 sync pins\n"); ++ z2->sync_active = pinctrl_lookup_state(z2->sync_pinctrl, ++ "display-sync-active"); ++ if (IS_ERR(z2->sync_active)) ++ return dev_err_probe(dev, PTR_ERR(z2->sync_active), ++ "missing J120 active sync state\n"); ++ z2->sync_inactive = pinctrl_lookup_state(z2->sync_pinctrl, ++ "display-sync-inactive"); ++ if (IS_ERR(z2->sync_inactive)) ++ return dev_err_probe(dev, PTR_ERR(z2->sync_inactive), ++ "missing J120 inactive sync state\n"); ++ } + + z2->power_ana_gpio = + devm_gpiod_get_optional(dev, "power-ana", GPIOD_OUT_LOW); +@@ -4902,6 +5306,8 @@ static int apple_z2_probe(struct spi_device *spi) + if (IS_ERR(z2->power_ldo_gpio)) + return dev_err_probe(dev, PTR_ERR(z2->power_ldo_gpio), + "unable to get LDO power GPIO\n"); ++ if (apple_z2_is_j120(z2) && !z2->power_ldo_gpio) ++ return dev_err_probe(dev, -EINVAL, "missing J120 LDO GPIO\n"); + z2->display_sync_gpio = + devm_gpiod_get_optional(dev, "display-sync", GPIOD_OUT_LOW); + if (IS_ERR(z2->display_sync_gpio)) +@@ -4913,7 +5319,7 @@ static int apple_z2_probe(struct spi_device *spi) + return dev_err_probe(dev, PTR_ERR(z2->display_sync1_gpio), + "unable to get display-sync1 GPIO\n"); + +- if (apple_z2_is_n61(z2) || apple_z2_is_j72(z2)) ++ if (apple_z2_is_n61(z2) || apple_z2_is_j72(z2) || apple_z2_is_j120(z2)) + z2->clk = devm_clk_get(dev, NULL); + else + z2->clk = devm_clk_get_optional(dev, NULL); +@@ -4956,6 +5362,47 @@ static int apple_z2_probe(struct spi_device *spi) + } + } + ++ if (apple_z2_is_j120(z2)) { ++ static const struct { ++ const char *name; ++ unsigned int maximum; ++ } calibration[] = { ++ { CAL_PROP_NAME, 4096 }, ++ { DISPLAY_OFFSET_CAL_PROP_NAME, 512 }, ++ { FIREFLY_CAL_PROP_NAME, 5120 }, ++ }; ++ unsigned int i; ++ ++ for (i = 0; i < ARRAY_SIZE(calibration); i++) { ++ cal_size = device_property_count_u8(dev, calibration[i].name); ++ if (cal_size <= 0 || cal_size > calibration[i].maximum) ++ return dev_err_probe(dev, -EINVAL, ++ "missing or invalid J120 calibration %s\n", ++ calibration[i].name); ++ } ++ z2->packet_buf = devm_kmalloc(dev, APPLE_Z2_J120_MAX_PACKET_SIZE, ++ GFP_KERNEL); ++ if (!z2->packet_buf) ++ return -ENOMEM; ++ z2->input_dev = devm_input_allocate_device(dev); ++ if (!z2->input_dev) ++ return -ENOMEM; ++ z2->input_dev->name = "iPad Pro 12.9 (2017) Touchscreen"; ++ z2->input_dev->phys = "apple_z2"; ++ z2->input_dev->id.bustype = BUS_SPI; ++ input_set_abs_params(z2->input_dev, ABS_MT_POSITION_X, 0, 0, 0, 0); ++ input_set_abs_params(z2->input_dev, ABS_MT_POSITION_Y, 0, 0, 0, 0); ++ touchscreen_parse_properties(z2->input_dev, true, &z2->props); ++ if (!z2->props.max_x || !z2->props.max_y) ++ return -EINVAL; ++ error = input_mt_init_slots(z2->input_dev, APPLE_Z2_J172_MAX_CONTACTS, ++ INPUT_MT_DIRECT | INPUT_MT_DROP_UNUSED); ++ if (error) ++ return error; ++ /* Registration follows successful native geometry validation. */ ++ return apple_z2_boot(z2); ++ } ++ + /* The bootloader copies the unit's calibration from the ADT. */ + if (info->n1) { + cal_size = device_property_count_u8(dev, CAL_PROP_NAME); +@@ -5036,13 +5483,19 @@ static void apple_z2_stop(struct apple_z2 *z2) + cancel_delayed_work_sync(&z2->j72_work); + } + +- /* The iPad 5 interrupt thread may mask the interrupt itself. */ +- mutex_lock(&z2->io_lock); +- irq_on = z2->irq_on; +- z2->irq_on = false; +- mutex_unlock(&z2->io_lock); +- if (irq_on) +- disable_irq(z2->spidev->irq); ++ if (apple_z2_is_j120(z2)) { ++ apple_z2_j120_quiesce_irq(z2); ++ } else { ++ /* The iPad 5 interrupt thread may mask the interrupt itself. */ ++ mutex_lock(&z2->io_lock); ++ irq_on = z2->irq_on; ++ z2->irq_on = false; ++ mutex_unlock(&z2->io_lock); ++ if (irq_on) ++ disable_irq(z2->spidev->irq); ++ } ++ if (apple_z2_is_j120(z2) && z2->j120_input_registered) ++ apple_z2_release_contacts(z2); + if (apple_z2_is_j72(z2)) { + z2->booted = false; + /* A failed parent disable must not be retried or rebalanced. */ +@@ -5065,6 +5518,7 @@ static void apple_z2_remove(struct spi_device *spi) + struct apple_z2 *z2 = spi_get_drvdata(spi); + + cancel_work_sync(&z2->resume_work); ++ apple_z2_cancel_runtime_stop(z2); + apple_z2_stop(z2); + } + +@@ -5082,6 +5536,7 @@ static int apple_z2_suspend(struct device *dev) + + /* A controller still booting from the last resume stops first */ + cancel_work_sync(&z2->resume_work); ++ apple_z2_cancel_runtime_stop(z2); + apple_z2_stop(z2); + + return 0; +@@ -5126,6 +5581,9 @@ static int apple_z2_resume(struct device *dev) + { + struct apple_z2 *z2 = spi_get_drvdata(to_spi_device(dev)); + ++ if (apple_z2_is_j120(z2)) ++ return 0; ++ + z2->stopping = false; + z2->recovering = false; + z2->boot_due = true; +@@ -5156,6 +5614,7 @@ static const struct of_device_id apple_z2_of_match[] = { + { .compatible = "apple,j72-touchscreen", .data = &apple_z2_j72_info }, + { .compatible = "apple,j81-touchscreen", .data = &apple_z2_j81_info }, + { .compatible = "apple,j96-touchscreen", .data = &apple_z2_j96_info }, ++ { .compatible = "apple,j120-touchscreen", .data = &apple_z2_j120_info }, + { .compatible = "apple,j172-touchscreen", .data = &apple_z2_j172_info }, + { .compatible = "apple,d11-touchscreen", .data = &apple_z2_d11_info }, + { .compatible = "apple,d111-touchscreen", .data = &apple_z2_d111_info }, +@@ -5172,6 +5631,7 @@ static struct spi_device_id apple_z2_of_id[] = { + { .name = "j72-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_j72_info }, + { .name = "j81-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_j81_info }, + { .name = "j96-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_j96_info }, ++ { .name = "j120-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_j120_info }, + { .name = "j172-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_j172_info }, + { .name = "d11-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_d11_info }, + { .name = "d111-touchscreen", .driver_data = (kernel_ulong_t)&apple_z2_d111_info }, diff --git a/kernel/patches/drivers/input/0034-Input-apple_z2-restart-J120-touch-after-system-resum.patch b/kernel/patches/drivers/input/0034-Input-apple_z2-restart-J120-touch-after-system-resum.patch new file mode 100644 index 00000000..20787169 --- /dev/null +++ b/kernel/patches/drivers/input/0034-Input-apple_z2-restart-J120-touch-after-system-resum.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 14:29:57 +0100 +Subject: [PATCH] Input: apple_z2: restart J120 touch after system resume + +The suspend callback powers the controller down on J120, but the resume callback skips scheduling a new firmware upload. Queue the existing post-resume work for J120 and leave report handling stopped until its runtime setup succeeds. + +Assisted-by: LLM +--- + drivers/input/touchscreen/apple_z2.c | 7 +++---- + 1 file changed, 3 insertions(+), 4 deletions(-) + +diff --git a/drivers/input/touchscreen/apple_z2.c b/drivers/input/touchscreen/apple_z2.c +index c3f3587b0..8665e8843 100644 +--- a/drivers/input/touchscreen/apple_z2.c ++++ b/drivers/input/touchscreen/apple_z2.c +@@ -5581,10 +5581,9 @@ static int apple_z2_resume(struct device *dev) + { + struct apple_z2 *z2 = spi_get_drvdata(to_spi_device(dev)); + +- if (apple_z2_is_j120(z2)) +- return 0; +- +- z2->stopping = false; ++ /* J120 clears stopping when firmware setup reaches runtime. */ ++ if (!apple_z2_is_j120(z2)) ++ z2->stopping = false; + z2->recovering = false; + z2->boot_due = true; + return 0; diff --git a/kernel/patches/drivers/input/0035-Input-apple_z2-let-J120-runtime-settle-before-discov.patch b/kernel/patches/drivers/input/0035-Input-apple_z2-let-J120-runtime-settle-before-discov.patch new file mode 100644 index 00000000..9bcc1389 --- /dev/null +++ b/kernel/patches/drivers/input/0035-Input-apple_z2-let-J120-runtime-settle-before-discov.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 14:52:45 +0100 +Subject: [PATCH] Input: apple_z2: let J120 runtime settle before discovery + +On J120, a warm bootstrap accepts the image, calibration and final boot writes but immediately querying DeviceInfo returns HBPP words instead of a runtime packet. A 100 ms settling interval after the readiness wait allowed a live reprobe and a subsequent device suspend/resume cycle to complete DeviceInfo and surface discovery. Keep this empirical delay scoped to J120. Full s2idle and repeated-cycle qualification remain pending. + +Assisted-by: LLM +--- + drivers/input/touchscreen/apple_z2.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/drivers/input/touchscreen/apple_z2.c b/drivers/input/touchscreen/apple_z2.c +index 8665e8843..a2dd2737e 100644 +--- a/drivers/input/touchscreen/apple_z2.c ++++ b/drivers/input/touchscreen/apple_z2.c +@@ -4148,6 +4148,12 @@ static int apple_z2_upload_firmware(struct apple_z2 *z2) + "J120 runtime readiness IRQ/state accepted\n"); + if (apple_z2_uses_ipad_protocol(z2) || apple_z2_is_j120(z2)) { + apple_z2_irq_off(z2); ++ /* ++ * J120 may signal before runtime commands are ready. ++ * Allow startup to settle before querying DeviceInfo. ++ */ ++ if (apple_z2_is_j120(z2)) ++ msleep(100); + error = apple_z2_read_device_info_locked(z2); + /* J71b: stay masked until its first reports are read. */ + if (apple_z2_is_j71b(z2) || apple_z2_is_j120(z2)) diff --git a/kernel/patches/drivers/input/0036-Input-add-Apple-J120-magnetic-cover-switch.patch b/kernel/patches/drivers/input/0036-Input-add-Apple-J120-magnetic-cover-switch.patch new file mode 100644 index 00000000..dd8f1476 --- /dev/null +++ b/kernel/patches/drivers/input/0036-Input-add-Apple-J120-magnetic-cover-switch.patch @@ -0,0 +1,152 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 02:35:33 +0100 +Subject: [PATCH] Input: add Apple J120 magnetic cover switch + +Read the two August PMIC Hall inputs without changing their pin modes. Report SW_MACHINE_COVER after two consecutive samples agree. + +Assisted-by: LLM +--- + drivers/input/misc/Kconfig | 10 +++ + drivers/input/misc/Makefile | 1 + + drivers/input/misc/apple-j120-cover.c | 98 +++++++++++++++++++++++++++ + 3 files changed, 109 insertions(+) + create mode 100644 drivers/input/misc/apple-j120-cover.c + +diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig +index 3938d7ec6..c43883632 100644 +--- a/drivers/input/misc/Kconfig ++++ b/drivers/input/misc/Kconfig +@@ -13,6 +13,16 @@ menuconfig INPUT_MISC + + if INPUT_MISC + ++config INPUT_APPLE_J120_COVER ++ tristate "Apple J120 magnetic cover switch" ++ depends on OF && MFD_SIMPLE_MFD_I2C ++ help ++ Report the magnetic cover on the 2017 12.9-inch Wi-Fi iPad Pro. ++ This driver reads the two Hall inputs through the August PMIC. ++ ++ To compile this driver as a module, choose M here: the module ++ will be called apple-j120-cover. ++ + config INPUT_88PM860X_ONKEY + tristate "88PM860x ONKEY support" + depends on MFD_88PM860X +diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile +index 5593e5f10..07615beb8 100644 +--- a/drivers/input/misc/Makefile ++++ b/drivers/input/misc/Makefile +@@ -17,6 +17,7 @@ obj-$(CONFIG_INPUT_ADXL34X_I2C) += adxl34x-i2c.o + obj-$(CONFIG_INPUT_ADXL34X_SPI) += adxl34x-spi.o + obj-$(CONFIG_INPUT_AMD_SFH_TABLETMODE) += amd_sfh_tabletmode.o + obj-$(CONFIG_INPUT_APANEL) += apanel.o ++obj-$(CONFIG_INPUT_APPLE_J120_COVER) += apple-j120-cover.o + obj-$(CONFIG_INPUT_ARIEL_PWRBUTTON) += ariel-pwrbutton.o + obj-$(CONFIG_INPUT_ARIZONA_HAPTICS) += arizona-haptics.o + obj-$(CONFIG_INPUT_ATC260X_ONKEY) += atc260x-onkey.o +diff --git a/drivers/input/misc/apple-j120-cover.c b/drivers/input/misc/apple-j120-cover.c +new file mode 100644 +index 000000000..a88a73f1a +--- /dev/null ++++ b/drivers/input/misc/apple-j120-cover.c +@@ -0,0 +1,98 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define D2400_GPIO_INPUT_BASE 0x186 ++#define J120_COVER_POLL_MS 200 ++ ++struct j120_cover { ++ struct regmap *regmap; ++ int last_sample; ++}; ++ ++static void j120_cover_poll(struct input_dev *input) ++{ ++ struct j120_cover *cover = input_get_drvdata(input); ++ bool near_hall, far_hall; ++ u8 levels[2]; ++ int ret; ++ ++ /* Read GPIO 0 and GPIO 10 without touching the PMIC pin settings. */ ++ ret = regmap_bulk_read(cover->regmap, D2400_GPIO_INPUT_BASE, levels, ++ ARRAY_SIZE(levels)); ++ if (ret) { ++ cover->last_sample = -1; ++ return; ++ } ++ ++ near_hall = !(levels[0] & BIT(0)); ++ far_hall = !(levels[1] & BIT(2)); ++ /* Keep the previous switch state until both inputs agree twice. */ ++ if (near_hall != far_hall) { ++ cover->last_sample = -1; ++ return; ++ } ++ ++ if (cover->last_sample == near_hall) { ++ input_report_switch(input, SW_MACHINE_COVER, near_hall); ++ input_sync(input); ++ } ++ cover->last_sample = near_hall; ++} ++ ++static int j120_cover_probe(struct platform_device *pdev) ++{ ++ struct device *dev = &pdev->dev; ++ struct input_dev *input; ++ struct j120_cover *cover; ++ int ret; ++ ++ cover = devm_kzalloc(dev, sizeof(*cover), GFP_KERNEL); ++ if (!cover) ++ return -ENOMEM; ++ ++ cover->regmap = dev_get_regmap(dev->parent, NULL); ++ if (!cover->regmap) ++ return dev_err_probe(dev, -ENODEV, "August PMIC register map unavailable\n"); ++ cover->last_sample = -1; ++ ++ input = devm_input_allocate_device(dev); ++ if (!input) ++ return -ENOMEM; ++ ++ input->name = "Apple J120 Magnetic Cover"; ++ input->id.bustype = BUS_I2C; ++ input_set_drvdata(input, cover); ++ input_set_capability(input, EV_SW, SW_MACHINE_COVER); ++ ++ ret = input_setup_polling(input, j120_cover_poll); ++ if (ret) ++ return ret; ++ input_set_poll_interval(input, J120_COVER_POLL_MS); ++ input_set_min_poll_interval(input, J120_COVER_POLL_MS); ++ input_set_max_poll_interval(input, J120_COVER_POLL_MS); ++ ++ return input_register_device(input); ++} ++ ++static const struct of_device_id j120_cover_of_match[] = { ++ { .compatible = "apple,j120-cover-switch" }, ++ { } ++}; ++MODULE_DEVICE_TABLE(of, j120_cover_of_match); ++ ++static struct platform_driver j120_cover_driver = { ++ .probe = j120_cover_probe, ++ .driver = { ++ .name = "apple-j120-cover", ++ .of_match_table = j120_cover_of_match, ++ }, ++}; ++module_platform_driver(j120_cover_driver); ++ ++MODULE_DESCRIPTION("Apple J120 magnetic cover switch"); ++MODULE_LICENSE("GPL"); diff --git a/kernel/patches/drivers/input/0037-Input-apple-j120-cover-reset-debounce-when-reopened.patch b/kernel/patches/drivers/input/0037-Input-apple-j120-cover-reset-debounce-when-reopened.patch new file mode 100644 index 00000000..127f3b6d --- /dev/null +++ b/kernel/patches/drivers/input/0037-Input-apple-j120-cover-reset-debounce-when-reopened.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 04:27:48 +0100 +Subject: [PATCH] Input: apple-j120-cover: reset debounce when reopened + +The polling queue stops when the final consumer closes or the input device is inhibited. Discard the cached sample at open so it cannot count toward two agreeing reads after polling restarts. + +Assisted-by: LLM +--- + drivers/input/misc/apple-j120-cover.c | 12 ++++++++++-- + 1 file changed, 10 insertions(+), 2 deletions(-) + +diff --git a/drivers/input/misc/apple-j120-cover.c b/drivers/input/misc/apple-j120-cover.c +index a88a73f1a..a2738116c 100644 +--- a/drivers/input/misc/apple-j120-cover.c ++++ b/drivers/input/misc/apple-j120-cover.c +@@ -14,6 +14,15 @@ struct j120_cover { + int last_sample; + }; + ++static int j120_cover_open(struct input_dev *input) ++{ ++ struct j120_cover *cover = input_get_drvdata(input); ++ ++ /* The first poll after reopening must start a new debounce window. */ ++ cover->last_sample = -1; ++ return 0; ++} ++ + static void j120_cover_poll(struct input_dev *input) + { + struct j120_cover *cover = input_get_drvdata(input); +@@ -58,14 +67,13 @@ static int j120_cover_probe(struct platform_device *pdev) + cover->regmap = dev_get_regmap(dev->parent, NULL); + if (!cover->regmap) + return dev_err_probe(dev, -ENODEV, "August PMIC register map unavailable\n"); +- cover->last_sample = -1; +- + input = devm_input_allocate_device(dev); + if (!input) + return -ENOMEM; + + input->name = "Apple J120 Magnetic Cover"; + input->id.bustype = BUS_I2C; ++ input->open = j120_cover_open; + input_set_drvdata(input, cover); + input_set_capability(input, EV_SW, SW_MACHINE_COVER); + diff --git a/kernel/patches/drivers/interrupt-controller/0001-dt-bindings-interrupt-controller-describe-Apple-PMIC.patch b/kernel/patches/drivers/interrupt-controller/0001-dt-bindings-interrupt-controller-describe-Apple-PMIC.patch new file mode 100644 index 00000000..112b8af6 --- /dev/null +++ b/kernel/patches/drivers/interrupt-controller/0001-dt-bindings-interrupt-controller-describe-Apple-PMIC.patch @@ -0,0 +1,62 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:11 +0100 +Subject: [PATCH] dt-bindings: interrupt-controller: describe Apple PMIC event + banks + +Describe the event-only interrupt domains for D2355 and August D2400 and their parent-line notification. + +Assisted-by: LLM +--- + .../apple,pmic-events.yaml | 42 +++++++++++++++++++ + 1 file changed, 42 insertions(+) + create mode 100644 Documentation/devicetree/bindings/interrupt-controller/apple,pmic-events.yaml + +diff --git a/Documentation/devicetree/bindings/interrupt-controller/apple,pmic-events.yaml b/Documentation/devicetree/bindings/interrupt-controller/apple,pmic-events.yaml +new file mode 100644 +index 000000000..8552eaedf +--- /dev/null ++++ b/Documentation/devicetree/bindings/interrupt-controller/apple,pmic-events.yaml +@@ -0,0 +1,42 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/interrupt-controller/apple,pmic-events.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple Dialog PMIC event interrupt controller ++ ++maintainers: ++ - Paul Praschl ++ ++description: | ++ These PMICs expose latched events through the parent PMIC register map and ++ signal them on one active-low interrupt. D2355 has 80 event bits and the ++ August D2400 has 256. The first interrupt cell is the event number, or the ++ event count for the parent-line notification delivered before reading events. ++ The second cell specifies edge trigger flags for the nested interrupt. ++ ++properties: ++ compatible: ++ enum: ++ - apple,august-pmic-events ++ - apple,d2355-pmic-events ++ ++ interrupt-controller: true ++ ++ "#interrupt-cells": ++ const: 2 ++ ++ "#address-cells": ++ const: 0 ++ ++ interrupts: ++ maxItems: 1 ++ ++required: ++ - compatible ++ - interrupt-controller ++ - "#interrupt-cells" ++ - interrupts ++ ++additionalProperties: false diff --git a/kernel/patches/drivers/iommu/0015-dt-bindings-iommu-allow-the-T8011-legacy-DART-compat.patch b/kernel/patches/drivers/iommu/0015-dt-bindings-iommu-allow-the-T8011-legacy-DART-compat.patch new file mode 100644 index 00000000..03e5ee12 --- /dev/null +++ b/kernel/patches/drivers/iommu/0015-dt-bindings-iommu-allow-the-T8011-legacy-DART-compat.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:55 +0100 +Subject: [PATCH] dt-bindings: iommu: allow the T8011 legacy DART compatible + +T8011 PCIe uses the existing legacy Apple DART implementation with a chip-specific compatible and the S5L8960X fallback. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/iommu/apple,dart.yaml | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml +index 9bbc29f33..dee8c93b2 100644 +--- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml ++++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml +@@ -37,6 +37,7 @@ properties: + - apple,t7000-dart + - apple,s8000-dart + - apple,t8010-dart ++ - apple,t8011-dart + - apple,t8015-dart + - const: apple,s5l8960x-dart + diff --git a/kernel/patches/drivers/media/0013-dt-bindings-media-describe-the-T8011-VXD-decoder.patch b/kernel/patches/drivers/media/0013-dt-bindings-media-describe-the-T8011-VXD-decoder.patch new file mode 100644 index 00000000..f07ca670 --- /dev/null +++ b/kernel/patches/drivers/media/0013-dt-bindings-media-describe-the-T8011-VXD-decoder.patch @@ -0,0 +1,50 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 09:38:35 +0100 +Subject: [PATCH] dt-bindings: media: describe the T8011 VXD decoder + +T8011 reports decoder version 10, with the same two register ranges as T8010. Describe its specific compatible with the T8010 fallback. + +Assisted-by: LLM +--- + .../bindings/media/apple,s8000-vxd.yaml | 19 ++++++++++++------- + 1 file changed, 12 insertions(+), 7 deletions(-) + +diff --git a/Documentation/devicetree/bindings/media/apple,s8000-vxd.yaml b/Documentation/devicetree/bindings/media/apple,s8000-vxd.yaml +index a6c1aebb7..cb60e14c8 100644 +--- a/Documentation/devicetree/bindings/media/apple,s8000-vxd.yaml ++++ b/Documentation/devicetree/bindings/media/apple,s8000-vxd.yaml +@@ -13,21 +13,26 @@ description: + The Apple "VXD" block is a multi-standard hardware video decoder, an + Imagination PowerVR MSVDX core whose MTX (META) microcontroller runs the + DEVA firmware. Apple has used this IP family since the S5L8940X (A4); the +- S8000/S8003 (A9) reports vxd-version 7 in the Apple device tree, the T8010 +- (A10) vxd-version 10. The block has no DART; it translates its own memory accesses through a two-level +- "GART" that the host programs through the MTX MMU registers. ++ S8000/S8003 (A9) reports vxd-version 7 in the Apple device tree, and T8010 ++ (A10) and T8011 (A10X) report vxd-version 10. The block has no DART; it ++ translates its own memory accesses through a two-level "GART" that the host ++ programs through the MTX MMU registers. + + properties: + compatible: +- enum: +- - apple,s8000-vxd +- - apple,t8010-vxd ++ oneOf: ++ - enum: ++ - apple,s8000-vxd ++ - apple,t8010-vxd ++ - items: ++ - const: apple,t8011-vxd ++ - const: apple,t8010-vxd + + reg: + minItems: 1 + items: + - description: decoder core registers +- - description: second register range of the T8010 block ++ - description: integration registers on T8010 and T8011 + + interrupts: + maxItems: 1 diff --git a/kernel/patches/drivers/nvmem/0001-dt-bindings-nvmem-describe-Apple-Broadcom-OTP-module.patch b/kernel/patches/drivers/nvmem/0001-dt-bindings-nvmem-describe-Apple-Broadcom-OTP-module.patch new file mode 100644 index 00000000..8e3d6fd3 --- /dev/null +++ b/kernel/patches/drivers/nvmem/0001-dt-bindings-nvmem-describe-Apple-Broadcom-OTP-module.patch @@ -0,0 +1,63 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:33 +0100 +Subject: [PATCH] dt-bindings: nvmem: describe Apple Broadcom OTP module + identity + +Describe the dynamic vendor identity field shared by the Wi-Fi and Bluetooth functions of Apple radio modules. + +Assisted-by: LLM +--- + .../nvmem/layouts/brcm,apple-otp-layout.yaml | 43 +++++++++++++++++++ + 1 file changed, 43 insertions(+) + create mode 100644 Documentation/devicetree/bindings/nvmem/layouts/brcm,apple-otp-layout.yaml + +diff --git a/Documentation/devicetree/bindings/nvmem/layouts/brcm,apple-otp-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/brcm,apple-otp-layout.yaml +new file mode 100644 +index 000000000..f2a5c1f53 +--- /dev/null ++++ b/Documentation/devicetree/bindings/nvmem/layouts/brcm,apple-otp-layout.yaml +@@ -0,0 +1,43 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/nvmem/layouts/brcm,apple-otp-layout.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple module identity layout in Broadcom radio OTP ++ ++maintainers: ++ - tompta1 <546706+tompta1@users.noreply.github.com> ++ ++description: ++ Apple Broadcom radio modules contain type-length-value OTP records. The ++ SYS_VENDOR record includes a chip-parameter string and a board-parameter ++ string after a four-byte header. The board parameters identify the module ++ vendor in a V= field. Its position is discovered from the record contents, ++ not a fixed byte offset. A shared Bluetooth radio uses this identity to ++ select its matching firmware. The provider supplies the raw record region ++ beginning with the first type byte, rather than the entire OTP address space. ++ ++properties: ++ compatible: ++ const: brcm,apple-otp-layout ++ ++ module-vendor: ++ type: object ++ description: Module vendor string, without the V= prefix or terminator. ++ additionalProperties: false ++ ++required: ++ - compatible ++ - module-vendor ++ ++additionalProperties: false ++ ++examples: ++ - | ++ nvmem-layout { ++ compatible = "brcm,apple-otp-layout"; ++ ++ module_vendor: module-vendor { ++ }; ++ }; diff --git a/kernel/patches/drivers/nvmem/0002-nvmem-add-the-Apple-Broadcom-OTP-module-layout.patch b/kernel/patches/drivers/nvmem/0002-nvmem-add-the-Apple-Broadcom-OTP-module-layout.patch new file mode 100644 index 00000000..af59a0f1 --- /dev/null +++ b/kernel/patches/drivers/nvmem/0002-nvmem-add-the-Apple-Broadcom-OTP-module-layout.patch @@ -0,0 +1,188 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:37 +0100 +Subject: [PATCH] nvmem: add the Apple Broadcom OTP module layout + +Locate the V= module vendor field in bounded native SYS_VENDOR records and publish a read-only cell. Reject malformed and ambiguous records instead of guessing a firmware vendor. + +Assisted-by: LLM +--- + drivers/nvmem/layouts/Kconfig | 11 ++ + drivers/nvmem/layouts/Makefile | 1 + + drivers/nvmem/layouts/brcm-apple-otp.c | 136 +++++++++++++++++++++++++ + 3 files changed, 148 insertions(+) + create mode 100644 drivers/nvmem/layouts/brcm-apple-otp.c + +diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig +index 790b45bbf..6ad3d41fe 100644 +--- a/drivers/nvmem/layouts/Kconfig ++++ b/drivers/nvmem/layouts/Kconfig +@@ -8,6 +8,17 @@ if NVMEM_LAYOUTS + + menu "Layout Types" + ++config NVMEM_LAYOUT_BRCM_APPLE_OTP ++ tristate "Apple Broadcom radio OTP layout" ++ help ++ Parse Apple module identity records in Broadcom radio OTP and expose ++ the module vendor as an NVMEM cell for the shared Bluetooth radio. ++ The provider must supply the raw SYS_VENDOR record region. The vendor ++ field is found from its contents so firmware selection does not depend ++ on a fixed offset within a particular module revision. ++ ++ If unsure, say N. ++ + config NVMEM_LAYOUT_APPLE_SYSCFG + tristate "Apple SysCfg layout support" + help +diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile +index 912fa14d3..4de603a9f 100644 +--- a/drivers/nvmem/layouts/Makefile ++++ b/drivers/nvmem/layouts/Makefile +@@ -8,3 +8,4 @@ obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o + obj-$(CONFIG_NVMEM_LAYOUT_APPLE_SYSCFG) += apple-syscfg.o + obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o + obj-$(CONFIG_NVMEM_LAYOUT_U_BOOT_ENV) += u-boot-env.o ++obj-$(CONFIG_NVMEM_LAYOUT_BRCM_APPLE_OTP) += brcm-apple-otp.o +diff --git a/drivers/nvmem/layouts/brcm-apple-otp.c b/drivers/nvmem/layouts/brcm-apple-otp.c +new file mode 100644 +index 000000000..85969c053 +--- /dev/null ++++ b/drivers/nvmem/layouts/brcm-apple-otp.c +@@ -0,0 +1,136 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* Apple module identity records in Broadcom radio OTP. */ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define BRCM_APPLE_SYS_VENDOR 0x15 ++#define BRCM_APPLE_VENDOR_HEADER 8 ++ ++static int brcm_apple_otp_vendor(const u8 *data, size_t size, ++ unsigned int *offset, unsigned int *bytes) ++{ ++ const u8 *record, *chip_end, *board_end, *p, *end; ++ size_t pos = 0, length; ++ bool found = false; ++ ++ while (pos < size) { ++ if (!data[pos] || data[pos] == 0xff) ++ break; ++ if (size - pos < 2) ++ return -EINVAL; ++ length = data[pos + 1]; ++ if (length > size - pos - 2) ++ return -EINVAL; ++ if (data[pos] != BRCM_APPLE_SYS_VENDOR) ++ goto next; ++ ++ record = data + pos + 2; ++ if (length < 6 || ++ get_unaligned_le32(record) != BRCM_APPLE_VENDOR_HEADER) ++ return -EINVAL; ++ chip_end = memchr(record + 4, 0, length - 4); ++ if (!chip_end || chip_end + 1 == record + length) ++ return -EINVAL; ++ p = chip_end + 1; ++ board_end = memchr(p, 0, record + length - p); ++ if (!board_end) ++ return -EINVAL; ++ ++ while (p < board_end) { ++ while (p < board_end && isspace(*p)) ++ p++; ++ if (p == board_end) ++ break; ++ if (board_end - p < 3 || p[1] != '=') ++ return -EINVAL; ++ end = p + 2; ++ while (end < board_end && !isspace(*end)) ++ end++; ++ if (end == p + 2) ++ return -EINVAL; ++ if (*p == 'V') { ++ /* Ambiguous identities must never select firmware. */ ++ if (found) ++ return -EINVAL; ++ *offset = p + 2 - data; ++ *bytes = end - p - 2; ++ found = true; ++ } ++ p = end; ++ } ++next: ++ pos += length + 2; ++ } ++ ++ return found ? 0 : -ENOENT; ++} ++ ++static int brcm_apple_otp_add_cells(struct nvmem_layout *layout) ++{ ++ struct nvmem_device *nvmem = layout->nvmem; ++ struct device_node *np __free(device_node) = ++ of_nvmem_layout_get_container(nvmem); ++ struct nvmem_cell_info cell = { .name = "module-vendor" }; ++ size_t size = nvmem_dev_size(nvmem); ++ u8 *data; ++ int ret; ++ ++ if (!np || !size) ++ return -EINVAL; ++ data = kmalloc(size, GFP_KERNEL); ++ if (!data) ++ return -ENOMEM; ++ ret = nvmem_device_read(nvmem, 0, size, data); ++ if (ret < 0) ++ goto out_free; ++ if (ret != size) { ++ ret = -EIO; ++ goto out_free; ++ } ++ ret = brcm_apple_otp_vendor(data, size, &cell.offset, &cell.bytes); ++out_free: ++ kfree(data); ++ if (ret) ++ return ret; ++ cell.np = of_get_child_by_name(np, cell.name); ++ if (!cell.np) ++ return -ENOENT; ++ ret = nvmem_add_one_cell(nvmem, &cell); ++ if (ret) ++ of_node_put(cell.np); ++ return ret; ++} ++ ++static int brcm_apple_otp_probe(struct nvmem_layout *layout) ++{ ++ layout->add_cells = brcm_apple_otp_add_cells; ++ return nvmem_layout_register(layout); ++} ++ ++static void brcm_apple_otp_remove(struct nvmem_layout *layout) ++{ ++ nvmem_layout_unregister(layout); ++} ++ ++static const struct of_device_id brcm_apple_otp_of_match[] = { ++ { .compatible = "brcm,apple-otp-layout" }, ++ {} ++}; ++MODULE_DEVICE_TABLE(of, brcm_apple_otp_of_match); ++ ++static struct nvmem_layout_driver brcm_apple_otp_driver = { ++ .driver = { ++ .name = "brcm-apple-otp-layout", ++ .of_match_table = brcm_apple_otp_of_match, ++ }, ++ .probe = brcm_apple_otp_probe, ++ .remove = brcm_apple_otp_remove, ++}; ++module_nvmem_layout_driver(brcm_apple_otp_driver); ++ ++MODULE_LICENSE("GPL"); ++MODULE_DESCRIPTION("NVMEM layout for Apple Broadcom module identity"); diff --git a/kernel/patches/drivers/pci/0041-dt-bindings-pci-describe-the-J120-six-port-Wi-Fi-hos.patch b/kernel/patches/drivers/pci/0041-dt-bindings-pci-describe-the-J120-six-port-Wi-Fi-hos.patch new file mode 100644 index 00000000..559d43b0 --- /dev/null +++ b/kernel/patches/drivers/pci/0041-dt-bindings-pci-describe-the-J120-six-port-Wi-Fi-hos.patch @@ -0,0 +1,209 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:54 +0100 +Subject: [PATCH] dt-bindings: pci: describe the J120 six-port Wi-Fi host + +Describe T8011 controller resources and its J120 Wi-Fi port, four-vector MSI allocation, deferred endpoint power and WLAN UART dependency. Keep the storage NVMMU outside this profile. + +Assisted-by: LLM +--- + .../bindings/pci/apple,t8010-pcie.yaml | 116 ++++++++++++++++-- + 1 file changed, 104 insertions(+), 12 deletions(-) + +diff --git a/Documentation/devicetree/bindings/pci/apple,t8010-pcie.yaml b/Documentation/devicetree/bindings/pci/apple,t8010-pcie.yaml +index bf96da5b1..74cc83f72 100644 +--- a/Documentation/devicetree/bindings/pci/apple,t8010-pcie.yaml ++++ b/Documentation/devicetree/bindings/pci/apple,t8010-pcie.yaml +@@ -4,7 +4,7 @@ + $id: http://devicetree.org/schemas/pci/apple,t8010-pcie.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple S8003, T7000, T8010 and T8015 PCIe host controller ++title: Apple S8003, T7000, T8010, T8011 and T8015 PCIe host controller + + maintainers: + - Paul Praschl +@@ -16,6 +16,10 @@ description: | + register windows, and a local MSI block. The SoCs share this register map + but need different power-up and link training sequences. + ++ The T8011 has six root ports and different common/pipe-clock registers. ++ The J120 description exposes its Wi-Fi port with a four-vector MSI range; ++ its storage-port NVMMU is omitted from this description. ++ + The storage port also contains an NVMMU which translates the proprietary + Apple ANS FlatDMA format. Unlike a general-purpose IOMMU, this block uses a + loader-provided, physically contiguous host-memory buffer and a fixed IOVA +@@ -107,6 +111,78 @@ allOf: + required: + - clocks + - clock-names ++ - if: ++ properties: ++ compatible: ++ contains: ++ const: apple,t8011-pcie ++ then: ++ properties: ++ reg: ++ minItems: 10 ++ maxItems: 10 ++ reg-names: ++ items: ++ - const: config ++ - const: rc ++ - const: phy ++ - const: phy-ip ++ - const: port0 ++ - const: port1 ++ - const: port2 ++ - const: port3 ++ - const: port4 ++ - const: port5 ++ interrupts: ++ minItems: 6 ++ maxItems: 6 ++ interrupt-names: ++ items: ++ - const: port0 ++ - const: port1 ++ - const: port2 ++ - const: port3 ++ - const: port4 ++ - const: port5 ++ apple,nvmmu-iova: false ++ apple,nvme-hmb: false ++ apple,preinit-phy-port-mask: false ++ pci@2,0: ++ type: object ++ properties: ++ compatible: ++ items: ++ - const: apple,j120-wifi-pcie-port ++ - const: pciclass,0604 ++ vdd-supply: ++ description: WLAN REG_ON supply controlled before enumeration. ++ required: ++ - compatible ++ - apple,wlan-uart ++ - vdd-supply ++ - apple,endpoint-power-after-link-setup ++ required: ++ - clocks ++ - clock-names ++ - pci@2,0 ++ else: ++ properties: ++ interrupts: ++ maxItems: 5 ++ interrupt-names: ++ items: ++ - const: port0 ++ - const: port1 ++ - const: port2 ++ - const: port3 ++ - const: nvmmu ++ patternProperties: ++ '^pci@[45],0$': false ++ '^pci@[0-3],0$': ++ properties: ++ apple,phy-lane: ++ maximum: 3 ++ + - if: + not: + properties: +@@ -114,6 +190,7 @@ allOf: + contains: + enum: + - apple,t7000-pcie ++ - apple,t8011-pcie + - apple,t8015-pcie + then: + properties: +@@ -121,7 +198,6 @@ allOf: + minItems: 9 + maxItems: 9 + reg-names: +- maxItems: 9 + items: + - const: config + - const: rc +@@ -152,33 +228,33 @@ properties: + - apple,t7000-pcie + - apple,t8010-pcie + - apple,t8015-pcie ++ - items: ++ - const: apple,j120-pcie ++ - const: apple,t8011-pcie + - items: + - const: apple,j172-pcie + - const: apple,t8010-pcie + + reg: + minItems: 4 +- maxItems: 9 ++ maxItems: 10 + + reg-names: + minItems: 4 +- maxItems: 9 ++ maxItems: 10 + + interrupts: + description: + One state interrupt for each root port followed, on the SoCs with a + storage-port NVMMU, by its fault interrupt. + minItems: 2 +- maxItems: 5 ++ maxItems: 6 + + interrupt-names: + minItems: 2 ++ maxItems: 6 + items: +- - const: port0 +- - const: port1 +- - const: port2 +- - const: port3 +- - const: nvmmu ++ enum: [port0, port1, port2, port3, port4, port5, nvmmu] + + clocks: + minItems: 2 +@@ -238,7 +314,7 @@ properties: + const: 1 + + patternProperties: +- '^pci@[0-3],0$': ++ '^pci@[0-5],0$': + type: object + properties: + reg: +@@ -268,9 +344,25 @@ patternProperties: + the controller's Link Capabilities registers when runtime speed + retraining is not implemented for the port. + ++ apple,wlan-uart: ++ $ref: /schemas/types.yaml#/definitions/phandle ++ description: WLAN UART provider required before enabling REG_ON. ++ ++ apple,msi-vector-range: ++ $ref: /schemas/types.yaml#/definitions/uint32-array ++ description: ++ First local MSI vector and number of consecutive vectors assigned to ++ this port. The range must fit the host MSI window, be aligned to its ++ power-of-two size and not overlap another enabled port. When omitted, ++ the port uses eight vectors starting at eight times its port index. ++ items: ++ - minimum: 0 ++ maximum: 31 ++ - enum: [1, 2, 4, 8] ++ + apple,phy-lane: + $ref: /schemas/types.yaml#/definitions/uint32 +- maximum: 3 ++ maximum: 5 + description: + PHY IP calibration lane used by this root port. If omitted, the + root-port number is used. diff --git a/kernel/patches/drivers/pci/0042-PCI-apple-h9p-support-the-J120-T8011-Wi-Fi-link.patch b/kernel/patches/drivers/pci/0042-PCI-apple-h9p-support-the-J120-T8011-Wi-Fi-link.patch new file mode 100644 index 00000000..ba5b32de --- /dev/null +++ b/kernel/patches/drivers/pci/0042-PCI-apple-h9p-support-the-J120-T8011-Wi-Fi-link.patch @@ -0,0 +1,983 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:56 +0100 +Subject: [PATCH] PCI: apple-h9p: support the J120 T8011 Wi-Fi link + +Select the T8011 six-port register layout, native PHY tunables and J120 port-2 power sequence through match data. Validate the Wi-Fi-only DART/MSI profile before hardware setup, retain PERST during REG_ON preparation and disable the link before endpoint teardown. Other controller matches retain their port counts and setup paths; no J120 storage path is enabled. + +Assisted-by: LLM +--- + drivers/pci/controller/pcie-apple-h9p.c | 580 +++++++++++++++++-- + drivers/pci/pwrctrl/pci-pwrctrl-apple-wifi.c | 34 +- + 2 files changed, 559 insertions(+), 55 deletions(-) + +diff --git a/drivers/pci/controller/pcie-apple-h9p.c b/drivers/pci/controller/pcie-apple-h9p.c +index 8a39638b5..494f90ff9 100644 +--- a/drivers/pci/controller/pcie-apple-h9p.c ++++ b/drivers/pci/controller/pcie-apple-h9p.c +@@ -32,6 +32,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -48,6 +49,7 @@ + #include "pci-host-common.h" + + #define H9P_NUM_PORTS 4 ++#define H9P_MAX_PORTS 6 + #define H9P_NUM_MSI 32 + #define H9P_MSI_PER_PORT (H9P_NUM_MSI / H9P_NUM_PORTS) + #define H9P_NUM_CLOCKS 2 +@@ -88,6 +90,11 @@ + #define H9P_RC_COMMON_STAT_INIT_DONE BIT(4) + #define H9P_RC_COMMON_STAT_READY BIT(0) + #define H9P_RC_PORT_LINK_RATE(port) (0x4020 + (port) * 0x0040) ++#define T8011_RC_COMMON_STAT 0x0024 ++#define T8011_RC_NAND_SYSCLK 0x0110 ++#define T8011_RC_PORT_STAT(port) (0x0104 + (port) * H9P_RC_PORT_STRIDE) ++#define T8011_RC_PORT_PIPE_RESET(port) (0x0128 + (port) * H9P_RC_PORT_STRIDE) ++ + #define H9P_PHY_PORTMASK 0x000c + + #define H9P_PHY_IP_EQ_COMMON0 0x0180 +@@ -124,7 +131,6 @@ + #define H9P_PORT_IRQMASK_LINK_UP 0xff002f0f + /* MSI control: enable | log2(vectors per port) << 4 (AppleS800xPCIePort) */ + #define H9P_PORT_MSICTL 0x0124 +-#define H9P_PORT_MSICTL_INIT (1 | ilog2(H9P_MSI_PER_PORT) << 4) + #define H9P_PORT_MSIVECBASE 0x0128 + #define H9P_PORT_ENABLE 0x0140 + #define H9P_PORT_ENABLE_APPLE BIT(31) +@@ -577,6 +583,117 @@ static const struct apple_h9p_tunable t8015_port_tunables[] = { + { 0x0140, 0x8073ffff, 0x00703d09 }, + }; + ++/* ++ * T8011 register tunables from J120's firmware-generated ADT. These describe ++ * board register fields, not per-unit identity/calibration or firmware code. ++ * Common port windows are applied only for enabled ports; preserve ordering. ++ */ ++static const struct apple_h9p_tunable t8011_phy_tunables[] = { ++ { 0x0814, 0x00000001, 0x00000001 }, ++ { 0x0914, 0x0000001f, 0x00000006 }, ++ { 0x0918, 0x0000001f, 0x00000006 }, ++ { 0x091c, 0x0000001f, 0x00000006 }, ++ { 0x0934, 0x00000007, 0x00000007 }, ++ { 0x0958, 0x0000001f, 0x00000018 }, ++ { 0x095c, 0x0000000f, 0x00000000 }, ++ { 0x0960, 0x0000000f, 0x00000000 }, ++ { 0x0964, 0x00000001, 0x00000001 }, ++ { 0x09ac, 0x0000001f, 0x00000006 }, ++ { 0x09b0, 0x0000001f, 0x00000006 }, ++ { 0x09b4, 0x0000001f, 0x00000006 }, ++ { 0x0a3c, 0x0000001f, 0x00000006 }, ++ { 0x0a40, 0x0000001f, 0x00000006 }, ++ { 0x0a44, 0x0000001f, 0x00000006 }, ++ { 0x0acc, 0x0000001f, 0x00000006 }, ++ { 0x0ad0, 0x0000001f, 0x00000006 }, ++ { 0x0ad4, 0x0000001f, 0x00000006 }, ++ { 0x0b5c, 0x0000001f, 0x00000006 }, ++ { 0x0b60, 0x0000001f, 0x00000006 }, ++ { 0x0b64, 0x0000001f, 0x00000006 }, ++ { 0x0bec, 0x0000001f, 0x00000006 }, ++ { 0x0bf0, 0x0000001f, 0x00000006 }, ++ { 0x0bf4, 0x0000001f, 0x00000006 }, ++}; ++ ++static const struct apple_h9p_tunable t8011_rc_common_tunables[] = { ++ { 0x0008, 0x7f7f7f7f, 0x00000000 }, ++ { 0x000c, 0x00073f3f, 0x00043f00 }, ++ { 0x0010, 0x00000700, 0x00000000 }, ++ { 0x0018, 0x00ffffff, 0x000c0960 }, ++ { 0x001c, 0x00001fff, 0x0000092c }, ++ { 0x0028, 0x000000ff, 0x00000009 }, ++ { 0x0100, 0x31100010, 0x21000000 }, ++ { 0x0108, 0x00000707, 0x00000000 }, ++ { 0x010c, 0x00073f3f, 0x00043f00 }, ++ { 0x0114, 0x00000011, 0x00000001 }, ++ { 0x0118, 0x00000007, 0x00000000 }, ++ { 0x011c, 0x00073f3f, 0x00043f00 }, ++ { 0x0120, 0x0333003f, 0x0111000f }, ++ { 0x0130, 0x000000ff, 0x0000000f }, ++ { 0x0138, 0x000001ff, 0x000000f2 }, ++ { 0x0180, 0x31100010, 0x21000000 }, ++ { 0x0188, 0x00000707, 0x00000000 }, ++ { 0x018c, 0x00073f3f, 0x00043f00 }, ++ { 0x01a0, 0x0333003f, 0x0111000f }, ++ { 0x01b0, 0x000000ff, 0x0000000f }, ++ { 0x01b8, 0x000001ff, 0x000000f2 }, ++ { 0x0200, 0x31100010, 0x21000000 }, ++ { 0x0208, 0x00000707, 0x00000000 }, ++ { 0x020c, 0x00073f3f, 0x00043f00 }, ++ { 0x0214, 0x00000011, 0x00000001 }, ++ { 0x0218, 0x00000007, 0x00000000 }, ++ { 0x021c, 0x00073f3f, 0x00043f00 }, ++ { 0x0220, 0x0333003f, 0x0111000f }, ++ { 0x0230, 0x000000ff, 0x0000000f }, ++ { 0x0238, 0x000001ff, 0x000000f2 }, ++ { 0x0280, 0x31100010, 0x21000000 }, ++ { 0x0288, 0x00000707, 0x00000000 }, ++ { 0x028c, 0x00073f3f, 0x00043f00 }, ++ { 0x02a0, 0x0333003f, 0x0111000f }, ++ { 0x02b0, 0x000000ff, 0x0000000f }, ++ { 0x02b8, 0x000001ff, 0x000000f2 }, ++ { 0x0300, 0x31100010, 0x21000000 }, ++ { 0x0308, 0x00000707, 0x00000000 }, ++ { 0x030c, 0x00073f3f, 0x00043f00 }, ++ { 0x0320, 0x0333003f, 0x0111000f }, ++ { 0x0330, 0x000000ff, 0x0000000f }, ++ { 0x0338, 0x000001ff, 0x000000f2 }, ++ { 0x0380, 0x31100010, 0x21000000 }, ++ { 0x0388, 0x00000707, 0x00000000 }, ++ { 0x038c, 0x00073f3f, 0x00043f00 }, ++ { 0x03a0, 0x0333003f, 0x0111000f }, ++ { 0x03b0, 0x000000ff, 0x0000000f }, ++ { 0x03b8, 0x000001ff, 0x000000f2 }, ++ { 0x0100, 0x00000010, 0x00000010 }, ++ { 0x0180, 0x00000010, 0x00000000 }, ++ { 0x0200, 0x00000010, 0x00000010 }, ++ { 0x0280, 0x00000010, 0x00000000 }, ++ { 0x0300, 0x00000010, 0x00000000 }, ++ { 0x0380, 0x00000010, 0x00000000 }, ++}; ++ ++/* J120 Wi-Fi port2 register settings, in native firmware order. */ ++static const struct apple_h9p_tunable t8011_wifi_config_tunables[] = { ++ { 0x0164, 0x00f8ff00, 0x00000000 }, ++ { 0x08a8, 0x00ffff0f, 0x00001001 }, ++ { 0x08e0, 0x00000005, 0x00000005 }, ++}; ++ ++static const struct apple_h9p_tunable t8011_wifi_port_tunables[] = { ++ { 0x0090, 0x00ffffff, 0x0003a980 }, ++ { 0x0130, 0x0000000f, 0x00000007 }, ++ { 0x0134, 0x00000001, 0x00000001 }, ++ { 0x0138, 0x00007f7f, 0x00000000 }, ++ { 0x013c, 0x00000003, 0x00000002 }, ++ { 0x0140, 0x0073ffff, 0x00703d09 }, ++ { 0x0090, 0x00ffffff, 0x0003a980 }, ++ { 0x0130, 0x0000000f, 0x00000007 }, ++ { 0x0134, 0x00000001, 0x00000001 }, ++ { 0x0138, 0x00007f7f, 0x00000000 }, ++ { 0x013c, 0x00000003, 0x00000002 }, ++ { 0x0140, 0x0073ffff, 0x00703d09 }, ++}; ++ + struct apple_h9p_tunables { + const struct apple_h9p_tunable *regs; + unsigned int count; +@@ -664,6 +781,7 @@ enum apple_h9p_port_result { + * @j172_bridge_quirk: replay J172 firmware's bridge transactions on port 3 + */ + struct apple_h9p_hw { ++ u8 num_ports; + int (*parse)(struct apple_h9p_pcie *pcie); + int (*setup_common)(struct apple_h9p_pcie *pcie); + int (*setup_port)(struct apple_h9p_pcie *pcie, unsigned int port, +@@ -691,6 +809,9 @@ struct apple_h9p_hw { + }; + + struct apple_h9p_pcie { ++ u8 num_ports; ++ u8 msi_first[H9P_MAX_PORTS]; ++ u8 msi_count[H9P_MAX_PORTS]; + struct device *dev; + struct platform_device *pdev; + struct pci_host_bridge *bridge; +@@ -702,19 +823,19 @@ struct apple_h9p_pcie { + void __iomem *base_rc; + void __iomem *base_phy; + void __iomem *base_phy_ip; +- void __iomem *base_port[H9P_NUM_PORTS]; ++ void __iomem *base_port[H9P_MAX_PORTS]; + + struct clk_bulk_data clks[H9P_NUM_CLOCKS]; + unsigned int clks_enabled; +- struct device_node *port_nodes[H9P_NUM_PORTS]; +- struct device_node *manual_dart[H9P_NUM_PORTS]; +- u32 manual_dart_sid[H9P_NUM_PORTS]; +- struct gpio_desc *perst[H9P_NUM_PORTS]; +- struct gpio_desc *clkreq[H9P_NUM_PORTS]; +- struct apple_h9p_port_irq port_irq[H9P_NUM_PORTS]; +- u8 phy_lane[H9P_NUM_PORTS]; +- u8 max_link_speed[H9P_NUM_PORTS]; +- u16 pcie_cap[H9P_NUM_PORTS]; ++ struct device_node *port_nodes[H9P_MAX_PORTS]; ++ struct device_node *manual_dart[H9P_MAX_PORTS]; ++ u32 manual_dart_sid[H9P_MAX_PORTS]; ++ struct gpio_desc *perst[H9P_MAX_PORTS]; ++ struct gpio_desc *clkreq[H9P_MAX_PORTS]; ++ struct apple_h9p_port_irq port_irq[H9P_MAX_PORTS]; ++ u8 phy_lane[H9P_MAX_PORTS]; ++ u8 max_link_speed[H9P_MAX_PORTS]; ++ u16 pcie_cap[H9P_MAX_PORTS]; + struct pinctrl *pinctrl; + u32 enabled_ports; + u32 preinit_phy_ports; +@@ -742,7 +863,7 @@ struct apple_h9p_pcie { + struct device_link **pd_link; + int pd_count; + +- DECLARE_BITMAP(used_msi[H9P_NUM_PORTS], H9P_MSI_PER_PORT); ++ DECLARE_BITMAP(used_msi[H9P_MAX_PORTS], H9P_MSI_PER_PORT); + u64 msi_doorbell; + /* Protects the per-port MSI allocation bitmaps. */ + spinlock_t used_msi_lock; +@@ -1201,7 +1322,7 @@ static int apple_h9p_pcie_request_port_irqs(struct apple_h9p_pcie *pcie) + if (pcie->hw->no_port_irqs) + return 0; + +- for (port = 0; port < H9P_NUM_PORTS; port++) { ++ for (port = 0; port < pcie->num_ports; port++) { + struct apple_h9p_port_irq *port_irq = &pcie->port_irq[port]; + bool armed_later; + char name[8]; +@@ -1285,7 +1406,7 @@ static int apple_h9p_pcie_config_read(struct pci_bus *bus, unsigned int devfn, + if (bus->number == cfg->busr.start) { + pcie = apple_h9p_pcie_lookup(cfg->parent); + port = PCI_SLOT(devfn); +- if (!pcie || port >= H9P_NUM_PORTS || ++ if (!pcie || port >= pcie->num_ports || + !(pcie->enabled_ports & BIT(port))) + return PCIBIOS_DEVICE_NOT_FOUND; + } else { +@@ -1329,7 +1450,7 @@ static int apple_h9p_pcie_config_write(struct pci_bus *bus, unsigned int devfn, + + if (bus->number == cfg->busr.start) { + pcie = apple_h9p_pcie_lookup(cfg->parent); +- if (!pcie || PCI_SLOT(devfn) >= H9P_NUM_PORTS || ++ if (!pcie || PCI_SLOT(devfn) >= pcie->num_ports || + !(pcie->enabled_ports & BIT(PCI_SLOT(devfn)))) + return PCIBIOS_DEVICE_NOT_FOUND; + } +@@ -1348,7 +1469,7 @@ static unsigned int apple_h9p_pcie_bus_to_port(struct apple_h9p_pcie *pcie, + { + unsigned int port; + +- for (port = 0; port < H9P_NUM_PORTS; port++) { ++ for (port = 0; port < pcie->num_ports; port++) { + u32 cfg, sec, sub; + + if (!(pcie->enabled_ports & BIT(port))) +@@ -1365,7 +1486,7 @@ static unsigned int apple_h9p_pcie_bus_to_port(struct apple_h9p_pcie *pcie, + return port; + } + +- return H9P_NUM_PORTS; ++ return pcie->num_ports; + } + + static int apple_h9p_pcie_device_port(struct apple_h9p_pcie *pcie, +@@ -1383,6 +1504,53 @@ static int apple_h9p_pcie_device_port(struct apple_h9p_pcie *pcie, + return apple_h9p_pcie_bus_to_port(pcie, pdev->bus->number); + } + ++static int apple_h9p_set_msi_range(struct apple_h9p_pcie *pcie, ++ unsigned int port, u32 first, u32 count) ++{ ++ unsigned int i; ++ ++ if (port >= pcie->num_ports || !is_power_of_2(count) || ++ count > H9P_MSI_PER_PORT || first > H9P_NUM_MSI - count || ++ (first & (count - 1))) ++ return -EINVAL; ++ ++ for (i = 0; i < pcie->num_ports; i++) { ++ if (i == port || !pcie->msi_count[i]) ++ continue; ++ if (first < pcie->msi_first[i] + pcie->msi_count[i] && ++ pcie->msi_first[i] < first + count) ++ return -EINVAL; ++ } ++ ++ pcie->msi_first[port] = first; ++ pcie->msi_count[port] = count; ++ return 0; ++} ++ ++static unsigned int apple_h9p_msi_port(struct apple_h9p_pcie *pcie, ++ irq_hw_number_t hwirq) ++{ ++ unsigned int port; ++ ++ for (port = 0; port < pcie->num_ports; port++) ++ if (pcie->msi_count[port] && hwirq >= pcie->msi_first[port] && ++ hwirq - pcie->msi_first[port] < pcie->msi_count[port]) ++ return port; ++ ++ return pcie->num_ports; ++} ++ ++static u32 apple_h9p_msi_control(struct apple_h9p_pcie *pcie, unsigned int port) ++{ ++ return 1 | ilog2(pcie->msi_count[port]) << 4; ++} ++ ++static u32 apple_h9p_msi_vector_base(struct apple_h9p_pcie *pcie, ++ unsigned int port) ++{ ++ return pcie->msi_first[port] * 0x10001; ++} ++ + static void apple_h9p_msi_compose_msg(struct irq_data *d, struct msi_msg *msg) + { + struct apple_h9p_pcie *pcie = irq_data_get_irq_chip_data(d); +@@ -1422,14 +1590,14 @@ static int apple_h9p_msi_alloc(struct irq_domain *domain, unsigned int virq, + return -ENOSPC; + + port = apple_h9p_pcie_bus_to_port(pcie, pdev->bus->number); +- if (port >= H9P_NUM_PORTS) ++ if (port >= pcie->num_ports) + return -ENOSPC; + if (!(pcie->enabled_ports & BIT(port))) + return -ENOSPC; + + spin_lock_irqsave(&pcie->used_msi_lock, flags); +- slot = find_first_zero_bit(pcie->used_msi[port], H9P_MSI_PER_PORT); +- if (slot >= H9P_MSI_PER_PORT) { ++ slot = find_first_zero_bit(pcie->used_msi[port], pcie->msi_count[port]); ++ if (slot >= pcie->msi_count[port]) { + spin_unlock_irqrestore(&pcie->used_msi_lock, flags); + return -ENOSPC; + } +@@ -1437,7 +1605,7 @@ static int apple_h9p_msi_alloc(struct irq_domain *domain, unsigned int virq, + spin_unlock_irqrestore(&pcie->used_msi_lock, flags); + + fwspec.param[fwspec.param_count - 2] += +- port * H9P_MSI_PER_PORT + slot; ++ pcie->msi_first[port] + slot; + ret = irq_domain_alloc_irqs_parent(domain, virq, 1, &fwspec); + if (ret) { + spin_lock_irqsave(&pcie->used_msi_lock, flags); +@@ -1447,7 +1615,7 @@ static int apple_h9p_msi_alloc(struct irq_domain *domain, unsigned int virq, + } + + irq_domain_set_hwirq_and_chip(domain, virq, +- port * H9P_MSI_PER_PORT + slot, ++ pcie->msi_first[port] + slot, + &apple_h9p_msi_bottom_chip, pcie); + return 0; + } +@@ -1470,11 +1638,11 @@ static void apple_h9p_msi_free(struct irq_domain *domain, unsigned int virq, + spin_lock_irqsave(&pcie->used_msi_lock, flags); + for (i = 0; i < nr_irqs; i++) { + irq_hw_number_t irq = hwirq + i; +- unsigned int port = irq / H9P_MSI_PER_PORT; +- unsigned int slot = irq % H9P_MSI_PER_PORT; ++ unsigned int port = apple_h9p_msi_port(pcie, irq); + +- if (port < H9P_NUM_PORTS) +- __clear_bit(slot, pcie->used_msi[port]); ++ if (port < pcie->num_ports) ++ __clear_bit(irq - pcie->msi_first[port], ++ pcie->used_msi[port]); + } + spin_unlock_irqrestore(&pcie->used_msi_lock, flags); + } +@@ -2008,6 +2176,76 @@ static int apple_h9p_enable_rc_port(struct apple_h9p_pcie *pcie, + return 0; + } + ++/* ++ * J120 port 0 NVMe mode. The no-nand-sysclk-gating flag is absent ++ * from the native J120 tree, so RC common control 1 takes value 1. ++ * Connect this only to the storage port's setup and unwind. ++ */ ++/* ++ * T8011 uses LINKSTS bit 2 for pipe-clock gating. Require two consecutive ++ * ungated samples, as AppleT8011PCIePort does, but always keep a deadline. ++ */ ++static int apple_t8011_wait_pipe_clock(struct apple_h9p_pcie *pcie, unsigned int port) ++{ ++ ktime_t deadline = ktime_add_us(ktime_get(), 250000); ++ unsigned int ready = 0; ++ ++ while (ktime_before(ktime_get(), deadline)) { ++ usleep_range(5000, 5500); ++ if (readl(pcie->base_port[port] + H9P_PORT_LINKSTS) & BIT(2)) ++ ready = 0; ++ else if (++ready == 2) ++ return 0; ++ } ++ ++ return -ETIMEDOUT; ++} ++ ++static int apple_t8011_enable_rc_port(struct apple_h9p_pcie *pcie, unsigned int port, ++ bool appclk_auto_dis, bool muxed_auxclk_auto_dis, ++ unsigned int refclk_to_perst_us) ++{ ++ void __iomem *rc = pcie->base_rc; ++ int ret; ++ ++ h9p_rmw(rc + H9P_RC_PORT_CTL2(port), BIT(0), 0); ++ h9p_rmw(rc + H9P_RC_PORT_CTL1(port), 0, BIT(0)); ++ ++ ret = apple_h9p_wait(rc + T8011_RC_COMMON_STAT, BIT(4), BIT(4), BIT(4), ++ 250000); ++ if (ret) { ++ dev_err(pcie->dev, "port %u common port-ready wait failed: %d\n", port, ret); ++ return ret; ++ } ++ ++ usleep_range(100, 200); ++ h9p_rmw(rc + T8011_RC_PORT_PIPE_RESET(port), BIT(4), 0); ++ ret = apple_h9p_wait(rc + T8011_RC_PORT_STAT(port), BIT(0), 0, 0, ++ 250000); ++ if (ret) { ++ dev_err(pcie->dev, "port %u port reset wait failed: %d\n", port, ret); ++ return ret; ++ } ++ ++ h9p_rmw(rc + H9P_RC_PORT_CTL0(port), 0, BIT(0)); ++ h9p_rmw(rc + H9P_RC_PORT_CTL0(port), BIT(8), ++ appclk_auto_dis ? BIT(8) : 0); ++ if (muxed_auxclk_auto_dis) ++ h9p_rmw(rc + H9P_RC_PORT_CTL0(port), 0, BIT(20)); ++ ++ usleep_range(refclk_to_perst_us, refclk_to_perst_us + 100); ++ h9p_rmw(rc + H9P_RC_PORT_CTL2(port), 0, BIT(0)); ++ ++ ret = apple_t8011_wait_pipe_clock(pcie, port); ++ if (ret) { ++ dev_err(pcie->dev, "port %u pipe clock wait failed: %d\n", port, ret); ++ return ret; ++ } ++ ++ writel(H9P_LINK_SPEED_8GT, rc + H9P_RC_PORT_LINK_RATE(port)); ++ return 0; ++} ++ + static int apple_h9p_preinit_phy_port(struct apple_h9p_pcie *pcie, + unsigned int port) + { +@@ -2173,8 +2411,8 @@ static int apple_t8010_setup_port(struct apple_h9p_pcie *pcie, unsigned int port + + h9p_rmw(pcie->base_port[port] + H9P_PORT_ENABLE, 0, + H9P_PORT_ENABLE_APPLE); +- writel(H9P_PORT_MSICTL_INIT, pcie->base_port[port] + H9P_PORT_MSICTL); +- writel(port * 0x10001 * H9P_MSI_PER_PORT, ++ writel(apple_h9p_msi_control(pcie, port), pcie->base_port[port] + H9P_PORT_MSICTL); ++ writel(apple_h9p_msi_vector_base(pcie, port), + pcie->base_port[port] + H9P_PORT_MSIVECBASE); + + if (port == 3) { +@@ -2316,6 +2554,174 @@ static int apple_h9p_recover_port(struct apple_h9p_pcie *pcie, + return apple_h9p_resume_port(pcie, port); + } + ++static void apple_j120_pcie_power_off(void *data) ++{ ++ struct apple_h9p_pcie *pcie = data; ++ void __iomem *base = pcie->base_port[2]; ++ int ret; ++ ++ h9p_rmw(base + H9P_PORT_LTSSMCTL, H9P_PORT_LTSSM_ENABLE, 0); ++ readl(base + H9P_PORT_LTSSMCTL); ++ ret = gpiod_direction_output(pcie->perst[2], 1); ++ if (ret) ++ dev_warn(pcie->dev, "failed to assert Wi-Fi PERST#: %d\n", ret); ++ pci_pwrctrl_power_off_devices(pcie->dev); ++ pcie->pwrctrl_powered = false; ++} ++ ++static int apple_t8011_setup_port(struct apple_h9p_pcie *pcie, unsigned int port, ++ enum apple_h9p_port_result *result) ++{ ++ struct device *dev = pcie->dev; ++ void __iomem *config; ++ void __iomem *base; ++ u32 linksts, speed; ++ u64 cap; ++ int ret; ++ ++ *result = APPLE_H9P_PORT_DISABLED; ++ if (port >= pcie->num_ports) ++ return -EOPNOTSUPP; ++ if (port != 2) ++ return -EOPNOTSUPP; ++ speed = pcie->max_link_speed[port] ?: H9P_LINK_SPEED_2_5GT; ++ if (speed != H9P_LINK_SPEED_2_5GT) ++ return -EOPNOTSUPP; ++ ++ config = pcie->base_config + port * H9P_CFG_PORT_STRIDE; ++ base = pcie->base_port[port]; ++ ret = gpiod_direction_output(pcie->perst[port], 1); ++ if (ret) ++ return ret; ++ usleep_range(100, 200); ++ ++ ret = apple_t8011_enable_rc_port(pcie, port, false, false, 100); ++ if (ret) ++ return ret; ++ ++ if (pcie->manual_dart[port]) { ++ ret = apple_dart_reload_configuration(pcie->manual_dart[port], ++ pcie->manual_dart_sid[port]); ++ if (ret) ++ return ret; ++ } ++ ++ cap = apple_h9p_read_pci_cap(pcie, port << 3, PCI_CAP_ID_EXP); ++ if (!cap) ++ return -ENODEV; ++ pcie->pcie_cap[port] = cap; ++ h9p_rmww(config + cap + PCI_EXP_LNKCTL2, PCI_EXP_LNKCTL2_TLS, speed); ++ apple_h9p_apply_tunables(config, t8011_wifi_config_tunables, ++ ARRAY_SIZE(t8011_wifi_config_tunables)); ++ apple_h9p_apply_tunables(base, t8011_wifi_port_tunables, ++ ARRAY_SIZE(t8011_wifi_port_tunables)); ++ ++ /* AppleT8011PCIePort's overrides after the parent port setup. */ ++ h9p_rmw(config + 0x8e0, 0, BIT(0)); ++ h9p_rmw(config + 0x80c, 0, BIT(17)); ++ h9p_rmw(config + 0x890, 0, BIT(9) | BIT(12)); ++ ++ writel(H9P_PORT_IRQMASK_PRE_LINK, base + H9P_PORT_IRQMASK); ++ writel(H9P_PORT_IRQSTAT_PRE_LINK, base + H9P_PORT_IRQSTAT); ++ h9p_rmw(base + H9P_PORT_ENABLE, 0, H9P_PORT_ENABLE_APPLE); ++ writel(apple_h9p_msi_control(pcie, port), base + H9P_PORT_MSICTL); ++ writel(apple_h9p_msi_vector_base(pcie, port), base + H9P_PORT_MSIVECBASE); ++ writel(H9P_PORT_IRQMASK_LINK_UP, base + H9P_PORT_IRQMASK); ++ ++ ret = pci_pwrctrl_power_on_devices(dev); ++ if (ret) ++ return ret; ++ pcie->pwrctrl_powered = true; ++ ret = devm_add_action_or_reset(dev, apple_j120_pcie_power_off, pcie); ++ if (ret) ++ return ret; ++ ++ ret = gpiod_direction_output(pcie->perst[port], 0); ++ if (ret) ++ return ret; ++ ++ h9p_rmw(base + H9P_PORT_LTSSMCTL, 0, H9P_PORT_LTSSM_ENABLE); ++ ret = apple_h9p_wait_link(pcie, port, &linksts); ++ if (ret) ++ return ret; ++ ++ *result = APPLE_H9P_PORT_READY; ++ return 0; ++} ++ ++/* Validate the J120 profile before enabling link clocks or programming PCIe. */ ++static int apple_j120_pcie_parse(struct apple_h9p_pcie *pcie) ++{ ++ struct device_node *np = pcie->dev->of_node; ++ struct platform_device *dart_pdev; ++ struct device_node *mapped; ++ struct resource dart_res; ++ resource_size_t dart_base; ++ unsigned int port; ++ u32 aperture; ++ u32 map[8], doorbell, mask; ++ int ret; ++ ++ if (pcie->num_ports != 6 || pcie->lane_cfg || ++ pcie->preinit_phy_ports || pcie->link_retry_ports || ++ pcie->hardware_trained_phy_ports || pcie->inherited_perst_ports) ++ return -EOPNOTSUPP; ++ ++ if (pcie->enabled_ports != BIT(2)) ++ return -EOPNOTSUPP; ++ port = 2; ++ aperture = 0x3ffff000; ++ dart_base = 0x603008000ULL; ++ if (pcie->msi_first[port] != 16 || pcie->msi_count[port] != 4 || ++ pcie->max_link_speed[port] != H9P_LINK_SPEED_2_5GT || ++ pcie->deferred_power_ports != BIT(2) || ++ !of_device_is_compatible(pcie->port_nodes[port], "apple,j120-wifi-pcie-port") || ++ !of_property_present(pcie->port_nodes[port], "vdd-supply") || ++ !of_property_present(pcie->port_nodes[port], "apple,wlan-uart")) ++ return -EINVAL; ++ if (!pcie->manual_dart[port] || pcie->manual_dart_sid[port] || ++ !of_device_is_compatible(pcie->port_nodes[port], "pciclass,0604")) ++ return -EINVAL; ++ ++ ret = of_property_count_u32_elems(np, "iommu-map"); ++ if (ret != ARRAY_SIZE(map)) ++ return -EINVAL; ++ ret = of_property_read_u32_array(np, "iommu-map", map, ARRAY_SIZE(map)); ++ if (ret) ++ return ret; ++ if (map[0] != 0x100 || map[2] || map[3] || map[4] != 0x80000000 || ++ map[5] || map[6] != aperture || map[7] != 1) ++ return -EINVAL; ++ mapped = of_find_node_by_phandle(map[1]); ++ if (!mapped) ++ return -EINVAL; ++ ret = of_address_to_resource(mapped, 0, &dart_res); ++ if (!ret && (mapped != pcie->manual_dart[port] || ++ !of_device_is_available(mapped) || ++ !of_device_is_compatible(mapped, "apple,s5l8960x-dart") || ++ dart_res.start != dart_base || ++ resource_size(&dart_res) != 0x4000)) ++ ret = -EINVAL; ++ of_node_put(mapped); ++ if (ret) ++ return ret; ++ ++ ret = of_property_read_u32(np, "iommu-map-mask", &mask); ++ if (ret || mask != 0xff00) ++ return -EINVAL; ++ ret = of_property_read_u32(np, "apple,msi-doorbell", &doorbell); ++ if (ret || doorbell != H9P_DEFAULT_MSI_DOORBELL) ++ return -EINVAL; ++ ++ /* Wait for DART registration before starting the shared PHY. */ ++ dart_pdev = of_find_device_by_node(pcie->manual_dart[port]); ++ if (!dart_pdev) ++ return -EPROBE_DEFER; ++ ret = device_is_bound(&dart_pdev->dev) ? 0 : -EPROBE_DEFER; ++ platform_device_put(dart_pdev); ++ return ret; ++} ++ + static int apple_t8010_setup_common(struct apple_h9p_pcie *pcie) + { + int ret; +@@ -2355,6 +2761,52 @@ static int apple_t8010_setup_common(struct apple_h9p_pcie *pcie) + return 0; + } + ++/* Keep disabled port register windows untouched, including storage port 0. */ ++static void apple_t8011_apply_common_tunables(struct apple_h9p_pcie *pcie) ++{ ++ unsigned int i; ++ ++ for (i = 0; i < ARRAY_SIZE(t8011_rc_common_tunables); i++) { ++ const struct apple_h9p_tunable *t = &t8011_rc_common_tunables[i]; ++ ++ if (t->offset >= 0x100 && ++ t->offset < 0x100 + H9P_MAX_PORTS * H9P_RC_PORT_STRIDE) { ++ unsigned int port = (t->offset - 0x100) / H9P_RC_PORT_STRIDE; ++ ++ if (!(pcie->enabled_ports & BIT(port))) ++ continue; ++ } ++ apple_h9p_apply_tunables(pcie->base_rc, t, 1); ++ } ++} ++ ++/* T8011 common initialization for the verified six-x1 lane configuration. */ ++static int apple_t8011_setup_common(struct apple_h9p_pcie *pcie) ++{ ++ int ret; ++ ++ /* J120's verified lane configuration has six independent x1 lanes. */ ++ if (pcie->lane_cfg) ++ return -EOPNOTSUPP; ++ ++ writel(H9P_RC_COMMON_CTL_INIT, pcie->base_rc + H9P_RC_COMMON_CTL0); ++ apple_h9p_apply_tunables(pcie->base_phy, t8011_phy_tunables, ++ ARRAY_SIZE(t8011_phy_tunables)); ++ writel(H9P_RC_COMMON_CTL_ENABLE, ++ pcie->base_rc + H9P_RC_COMMON_CTL3); ++ ++ ret = apple_h9p_wait(pcie->base_rc + T8011_RC_COMMON_STAT, ++ BIT(0), BIT(0), BIT(0), 250000); ++ if (ret) { ++ dev_err(pcie->dev, "common PHY initialization wait failed: %d\n", ret); ++ return ret; ++ } ++ ++ h9p_rmw(pcie->base_rc + 0x30, BIT(0), 0); ++ apple_t8011_apply_common_tunables(pcie); ++ return 0; ++} ++ + /* + * AppleT8015PCIe's initCommon: the lane configuration and the PHY tunables + * first, then the port-complex enable, then the common tunables. The D221 +@@ -2569,8 +3021,8 @@ static int apple_t8015_setup_port(struct apple_h9p_pcie *pcie, unsigned int port + } + + h9p_rmw(base + H9P_PORT_ENABLE, 0, H9P_PORT_ENABLE_APPLE); +- writel(H9P_PORT_MSICTL_INIT, base + H9P_PORT_MSICTL); +- writel(port * 0x10001 * H9P_MSI_PER_PORT, ++ writel(apple_h9p_msi_control(pcie, port), base + H9P_PORT_MSICTL); ++ writel(apple_h9p_msi_vector_base(pcie, port), + base + H9P_PORT_MSIVECBASE); + + ret = gpiod_direction_output(pcie->perst[port], 0); +@@ -2684,8 +3136,8 @@ static int apple_t7000_setup_port(struct apple_h9p_pcie *pcie, unsigned int port + h9p_writel_flush(T7000_PORT_IRQMASK_INIT, base + H9P_PORT_IRQMASK); + h9p_writel_flush(T7000_PORT_IRQSTAT_INIT, base + H9P_PORT_IRQSTAT); + /* MSI enable with 2^3 vectors. */ +- h9p_writel_flush(H9P_PORT_MSICTL_INIT, base + H9P_PORT_MSICTL); +- h9p_writel_flush(port * 0x10001 * H9P_MSI_PER_PORT, ++ h9p_writel_flush(apple_h9p_msi_control(pcie, port), base + H9P_PORT_MSICTL); ++ h9p_writel_flush(apple_h9p_msi_vector_base(pcie, port), + base + H9P_PORT_MSIVECBASE); + + ret = gpiod_direction_output(pcie->perst[port], 0); +@@ -3087,8 +3539,8 @@ static int apple_s8003_start_link(struct apple_h9p_pcie *pcie, + writel(H9P_PORT_IRQMASK_PRE_LINK, pb + H9P_PORT_IRQMASK); + writel(H9P_PORT_IRQSTAT_PRE_LINK, pb + H9P_PORT_IRQSTAT); + h9p_rmw(pb + H9P_PORT_ENABLE, 0, H9P_PORT_ENABLE_APPLE); +- writel(H9P_PORT_MSICTL_INIT, pb + H9P_PORT_MSICTL); +- writel(port * 0x10001 * H9P_MSI_PER_PORT, pb + H9P_PORT_MSIVECBASE); ++ writel(apple_h9p_msi_control(pcie, port), pb + H9P_PORT_MSICTL); ++ writel(apple_h9p_msi_vector_base(pcie, port), pb + H9P_PORT_MSIVECBASE); + + msleep(S8003_PERST_HOLD_MS); + ret = gpiod_direction_output(pcie->perst[port], 0); +@@ -3292,7 +3744,7 @@ static int apple_s8003_setup_ports(struct apple_h9p_pcie *pcie) + unsigned int port; + int ret; + +- for_each_set_bit(port, &ports, H9P_NUM_PORTS) { ++ for_each_set_bit(port, &ports, pcie->num_ports) { + ret = apple_s8003_setup_storage_port(pcie, port); + if (ret) { + dev_warn(pcie->dev, "disabling port %u: %d\n", port, ret); +@@ -3311,7 +3763,7 @@ static int apple_s8003_setup_ports(struct apple_h9p_pcie *pcie) + } + + ports = others; +- for_each_set_bit(port, &ports, H9P_NUM_PORTS) { ++ for_each_set_bit(port, &ports, pcie->num_ports) { + ret = apple_s8003_setup_endpoint_port(pcie, port); + if (ret == -EPROBE_DEFER) + pcie->late_ports |= BIT(port); +@@ -3334,7 +3786,7 @@ static void apple_s8003_late_ports_work(struct work_struct *work) + unsigned int port; + int ret; + +- for_each_set_bit(port, &pending, H9P_NUM_PORTS) { ++ for_each_set_bit(port, &pending, pcie->num_ports) { + ret = apple_s8003_setup_endpoint_port(pcie, port); + if (ret == -EPROBE_DEFER) { + retry = true; +@@ -3384,7 +3836,7 @@ static int apple_h9p_prepare_phy_ports(struct apple_h9p_pcie *pcie) + unsigned int port; + int ret; + +- for (port = 0; port < H9P_NUM_PORTS; port++) { ++ for (port = 0; port < pcie->num_ports; port++) { + if (!(pcie->preinit_phy_ports & BIT(port))) + continue; + +@@ -3401,7 +3853,7 @@ static int apple_h9p_setup_ports(struct apple_h9p_pcie *pcie) + unsigned int port; + int ret; + +- for (port = 0; port < H9P_NUM_PORTS; port++) { ++ for (port = 0; port < pcie->num_ports; port++) { + enum apple_h9p_port_result result; + + if (!(pcie->enabled_ports & BIT(port))) +@@ -3765,7 +4217,7 @@ static int apple_h9p_pcie_map_resources(struct platform_device *pdev, + return PTR_ERR(pcie->base_phy_ip); + } + +- for (i = 0; i < H9P_NUM_PORTS; i++) { ++ for (i = 0; i < pcie->num_ports; i++) { + char name[8]; + + if (!(pcie->enabled_ports & BIT(i))) +@@ -3793,9 +4245,9 @@ static void apple_h9p_pcie_put_port_nodes(void *data) + struct apple_h9p_pcie *pcie = data; + unsigned int i; + +- for (i = 0; i < H9P_NUM_PORTS; i++) ++ for (i = 0; i < pcie->num_ports; i++) + of_node_put(pcie->port_nodes[i]); +- for (i = 0; i < H9P_NUM_PORTS; i++) ++ for (i = 0; i < pcie->num_ports; i++) + of_node_put(pcie->manual_dart[i]); + } + +@@ -3811,7 +4263,7 @@ static int apple_h9p_pcie_parse_ports(struct apple_h9p_pcie *pcie) + &pcie->preinit_phy_ports); + if (ret && ret != -EINVAL) + return ret; +- if (pcie->preinit_phy_ports & ~GENMASK(H9P_NUM_PORTS - 1, 0)) ++ if (pcie->preinit_phy_ports & ~GENMASK(pcie->num_ports - 1, 0)) + return -EINVAL; + if (pcie->preinit_phy_ports && !pcie->hw->has_phy) + return -EINVAL; +@@ -3825,11 +4277,32 @@ static int apple_h9p_pcie_parse_ports(struct apple_h9p_pcie *pcie) + goto out_put_child; + + port = reg >> 11; +- if (port >= H9P_NUM_PORTS || pcie->port_nodes[port]) { ++ if (port >= pcie->num_ports || pcie->port_nodes[port]) { + ret = -EINVAL; + goto out_put_child; + } + ++ { ++ u32 range[2] = { port * H9P_MSI_PER_PORT, H9P_MSI_PER_PORT }; ++ ++ if (of_find_property(np, "apple,msi-vector-range", NULL)) { ++ ret = of_property_count_u32_elems(np, ++ "apple,msi-vector-range"); ++ if (ret != ARRAY_SIZE(range)) { ++ ret = -EINVAL; ++ goto out_put_child; ++ } ++ ret = of_property_read_u32_array(np, ++ "apple,msi-vector-range", ++ range, ARRAY_SIZE(range)); ++ if (ret) ++ goto out_put_child; ++ } ++ ret = apple_h9p_set_msi_range(pcie, port, range[0], range[1]); ++ if (ret) ++ goto out_put_child; ++ } ++ + pcie->port_nodes[port] = of_node_get(np); + pcie->enabled_ports |= BIT(port); + if (of_property_read_bool(np, +@@ -3849,7 +4322,7 @@ static int apple_h9p_pcie_parse_ports(struct apple_h9p_pcie *pcie) + ret = of_property_read_u32(np, "apple,phy-lane", &phy_lane); + if (ret && ret != -EINVAL) + goto out_put_child; +- if (phy_lane >= H9P_NUM_PORTS) { ++ if (phy_lane >= pcie->num_ports) { + ret = -EINVAL; + goto out_put_child; + } +@@ -3900,7 +4373,7 @@ static int apple_h9p_pcie_get_gpios(struct apple_h9p_pcie *pcie) + struct device *dev = pcie->dev; + unsigned int i; + +- for (i = 0; i < H9P_NUM_PORTS; i++) { ++ for (i = 0; i < pcie->num_ports; i++) { + struct fwnode_handle *fwnode; + struct gpio_desc *gpio; + enum gpiod_flags flags; +@@ -3961,6 +4434,9 @@ static int apple_h9p_pcie_probe(struct platform_device *pdev) + pcie->hw = of_device_get_match_data(dev); + if (!pcie->hw) + return -ENODEV; ++ pcie->num_ports = pcie->hw->num_ports ?: H9P_NUM_PORTS; ++ if (pcie->num_ports > H9P_MAX_PORTS) ++ return -EINVAL; + if (pcie->hw->j172_bridge_quirk) { + pcie->j172_quirk_state = + devm_kzalloc(dev, sizeof(*pcie->j172_quirk_state), +@@ -4118,6 +4594,17 @@ static const struct apple_h9p_hw apple_h9p_hw_t7000 = { + .no_port_irqs = true, + }; + ++/* J120 uses separate Wi-Fi and storage enumeration profiles. */ ++static const struct apple_h9p_hw apple_h9p_hw_j120 = { ++ .num_ports = 6, ++ .parse = apple_j120_pcie_parse, ++ .setup_common = apple_t8011_setup_common, ++ .setup_port = apple_t8011_setup_port, ++ .link_settle_ms = 100, ++ .has_clocks = true, ++ .has_phy = true, ++}; ++ + static const struct apple_h9p_hw apple_h9p_hw_t8010 = { + .setup_common = apple_t8010_setup_common, + .setup_port = apple_t8010_setup_port, +@@ -4185,6 +4672,7 @@ static const struct apple_h9p_hw apple_h9p_hw_s8003 = { + }; + + static const struct of_device_id apple_h9p_pcie_of_match[] = { ++ { .compatible = "apple,j120-pcie", .data = &apple_h9p_hw_j120 }, + { .compatible = "apple,s8003-pcie", .data = &apple_h9p_hw_s8003 }, + { .compatible = "apple,j172-pcie", .data = &apple_h9p_hw_j172 }, + { .compatible = "apple,t8015-pcie", .data = &apple_h9p_hw_t8015 }, +diff --git a/drivers/pci/pwrctrl/pci-pwrctrl-apple-wifi.c b/drivers/pci/pwrctrl/pci-pwrctrl-apple-wifi.c +index cf9016547..e09030698 100644 +--- a/drivers/pci/pwrctrl/pci-pwrctrl-apple-wifi.c ++++ b/drivers/pci/pwrctrl/pci-pwrctrl-apple-wifi.c +@@ -16,6 +16,7 @@ + #include + + struct apple_wifi_pwrctrl_data { ++ bool reg_on_only; + bool pulse_device_wake; + bool assert_device_wake; + unsigned int step_delay_min_us; +@@ -40,6 +41,12 @@ static const struct apple_wifi_pwrctrl_data apple_j172_wifi_data = { + .stabilization_delay_ms = 100, + }; + ++/* Initial J120 link qualification uses REG_ON with PERST# asserted. */ ++static const struct apple_wifi_pwrctrl_data apple_j120_wifi_data = { ++ .reg_on_only = true, ++ .stabilization_delay_ms = 100, ++}; ++ + /* + * BCM4350 (iPad Air 2): REG_ON, 100 ms, then DEVICE_WAKE held asserted. + * iOS drives DEVICE_WAKE through AppleEmbeddedPCIEPort::setDeviceWake() +@@ -132,7 +139,7 @@ static int apple_wifi_power_off(struct pci_pwrctrl *pwrctrl) + int wake_ret; + int ret; + +- wake_ret = apple_wifi_set_device_wake(wifi, 0); ++ wake_ret = wifi->data->reg_on_only ? 0 : apple_wifi_set_device_wake(wifi, 0); + apple_wifi_step_delay(wifi); + ret = apple_wifi_set_vdd(wifi, false); + apple_wifi_step_delay(wifi); +@@ -140,7 +147,7 @@ static int apple_wifi_power_off(struct pci_pwrctrl *pwrctrl) + return ret ?: wake_ret; + } + +-static int apple_wifi_link_uart_provider(struct device *dev) ++static int apple_wifi_link_uart_provider(struct device *dev, bool required) + { + struct platform_device *uart_pdev; + struct device_node *uart_np; +@@ -149,7 +156,7 @@ static int apple_wifi_link_uart_provider(struct device *dev) + + uart_np = of_parse_phandle(dev->of_node, "apple,wlan-uart", 0); + if (!uart_np) +- return 0; ++ return required ? -EINVAL : 0; + + uart_pdev = of_find_device_by_node(uart_np); + of_node_put(uart_np); +@@ -187,17 +194,22 @@ static int apple_wifi_pwrctrl_probe(struct platform_device *pdev) + if (!wifi->data) + return dev_err_probe(dev, -EINVAL, "missing match data\n"); + +- wifi->device_wake = devm_gpiod_get(dev, "device-wake", GPIOD_OUT_LOW); +- if (IS_ERR(wifi->device_wake)) +- return dev_err_probe(dev, PTR_ERR(wifi->device_wake), +- "failed to get device-wake GPIO\n"); ++ if (!wifi->data->reg_on_only) { ++ wifi->device_wake = devm_gpiod_get(dev, "device-wake", GPIOD_OUT_LOW); ++ if (IS_ERR(wifi->device_wake)) ++ return dev_err_probe(dev, PTR_ERR(wifi->device_wake), ++ "failed to get device-wake GPIO\n"); ++ } + +- wifi->vdd = devm_regulator_get(dev, "vdd"); ++ if (wifi->data->reg_on_only) ++ wifi->vdd = devm_regulator_get_optional(dev, "vdd"); ++ else ++ wifi->vdd = devm_regulator_get(dev, "vdd"); + if (IS_ERR(wifi->vdd)) + return dev_err_probe(dev, PTR_ERR(wifi->vdd), + "failed to get VDD supply\n"); + +- ret = apple_wifi_link_uart_provider(dev); ++ ret = apple_wifi_link_uart_provider(dev, wifi->data->reg_on_only); + if (ret) + return ret; + +@@ -214,6 +226,10 @@ static int apple_wifi_pwrctrl_probe(struct platform_device *pdev) + } + + static const struct of_device_id apple_wifi_pwrctrl_of_match[] = { ++ { ++ .compatible = "apple,j120-wifi-pcie-port", ++ .data = &apple_j120_wifi_data, ++ }, + { + .compatible = "apple,d11-bcm4355-wifi", + .data = &apple_iphone7_plus_wifi_data, diff --git a/kernel/patches/drivers/pci/0043-PCI-apple-h9p-bring-up-the-J120-storage-port-alongsi.patch b/kernel/patches/drivers/pci/0043-PCI-apple-h9p-bring-up-the-J120-storage-port-alongsi.patch new file mode 100644 index 00000000..05a6a886 --- /dev/null +++ b/kernel/patches/drivers/pci/0043-PCI-apple-h9p-bring-up-the-J120-storage-port-alongsi.patch @@ -0,0 +1,355 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:40:48 +0100 +Subject: [PATCH] PCI: apple-h9p: bring up the J120 storage port alongside + Wi-Fi + +Assisted-by: LLM +--- + drivers/pci/controller/pcie-apple-h9p.c | 227 +++++++++++++++++++----- + 1 file changed, 187 insertions(+), 40 deletions(-) + +diff --git a/drivers/pci/controller/pcie-apple-h9p.c b/drivers/pci/controller/pcie-apple-h9p.c +index 494f90ff9..7905c62c2 100644 +--- a/drivers/pci/controller/pcie-apple-h9p.c ++++ b/drivers/pci/controller/pcie-apple-h9p.c +@@ -673,6 +673,22 @@ static const struct apple_h9p_tunable t8011_rc_common_tunables[] = { + }; + + /* J120 Wi-Fi port2 register settings, in native firmware order. */ ++static const struct apple_h9p_tunable t8011_storage_config_tunables[] = { ++ { 0x0164, 0x00f8ff00, 0x00000000 }, ++ { 0x08a8, 0x00ffff0f, 0x00001001 }, ++ { 0x08e0, 0x00000005, 0x00000005 }, ++}; ++ ++static const struct apple_h9p_tunable t8011_storage_port_tunables[] = { ++ { 0x0090, 0x00ffffff, 0x0003a980 }, ++ { 0x0130, 0x0000000f, 0x00000007 }, ++ { 0x0134, 0x00000001, 0x00000001 }, ++ { 0x0138, 0x00007f7f, 0x00000000 }, ++ { 0x013c, 0x00000003, 0x00000002 }, ++ { 0x0140, 0x0073ffff, 0x00703d09 }, ++ { 0x0130, 0x00000002, 0x00000000 }, ++}; ++ + static const struct apple_h9p_tunable t8011_wifi_config_tunables[] = { + { 0x0164, 0x00f8ff00, 0x00000000 }, + { 0x08a8, 0x00ffff0f, 0x00001001 }, +@@ -2185,6 +2201,16 @@ static int apple_h9p_enable_rc_port(struct apple_h9p_pcie *pcie, + * T8011 uses LINKSTS bit 2 for pipe-clock gating. Require two consecutive + * ungated samples, as AppleT8011PCIePort does, but always keep a deadline. + */ ++static void apple_j120_set_nvme_mode(struct apple_h9p_pcie *pcie, ++ bool enable) ++{ ++ if (enable) { ++ writel(1, pcie->base_rc + H9P_RC_COMMON_CTL1); ++ usleep_range(100, 200); ++ } ++ h9p_writel_flush(enable, pcie->base_rc + T8011_RC_NAND_SYSCLK); ++} ++ + static int apple_t8011_wait_pipe_clock(struct apple_h9p_pcie *pcie, unsigned int port) + { + ktime_t deadline = ktime_add_us(ktime_get(), 250000); +@@ -2214,7 +2240,8 @@ static int apple_t8011_enable_rc_port(struct apple_h9p_pcie *pcie, unsigned int + ret = apple_h9p_wait(rc + T8011_RC_COMMON_STAT, BIT(4), BIT(4), BIT(4), + 250000); + if (ret) { +- dev_err(pcie->dev, "port %u common port-ready wait failed: %d\n", port, ret); ++ dev_err(pcie->dev, "port %u common port-ready wait failed: %d (RC[%#x]=%#x)\n", ++ port, ret, T8011_RC_COMMON_STAT, readl(rc + T8011_RC_COMMON_STAT)); + return ret; + } + +@@ -2223,7 +2250,9 @@ static int apple_t8011_enable_rc_port(struct apple_h9p_pcie *pcie, unsigned int + ret = apple_h9p_wait(rc + T8011_RC_PORT_STAT(port), BIT(0), 0, 0, + 250000); + if (ret) { +- dev_err(pcie->dev, "port %u port reset wait failed: %d\n", port, ret); ++ dev_err(pcie->dev, "port %u port reset wait failed: %d (RC[%#x]=%#x)\n", ++ port, ret, T8011_RC_PORT_STAT(port), ++ readl(rc + T8011_RC_PORT_STAT(port))); + return ret; + } + +@@ -2238,7 +2267,8 @@ static int apple_t8011_enable_rc_port(struct apple_h9p_pcie *pcie, unsigned int + + ret = apple_t8011_wait_pipe_clock(pcie, port); + if (ret) { +- dev_err(pcie->dev, "port %u pipe clock wait failed: %d\n", port, ret); ++ dev_err(pcie->dev, "port %u pipe clock wait failed: %d (LINKSTS=%#x)\n", ++ port, ret, readl(pcie->base_port[port] + H9P_PORT_LINKSTS)); + return ret; + } + +@@ -2569,6 +2599,77 @@ static void apple_j120_pcie_power_off(void *data) + pcie->pwrctrl_powered = false; + } + ++static void apple_j120_storage_disable(void *data) ++{ ++ struct apple_h9p_pcie *pcie = data; ++ ++ h9p_rmw(pcie->base_port[0] + H9P_PORT_LTSSMCTL, H9P_PORT_LTSSM_ENABLE, 0); ++ if (gpiod_direction_output(pcie->perst[0], 1)) ++ dev_warn(pcie->dev, "failed to assert storage PERST#\n"); ++ apple_j120_set_nvme_mode(pcie, false); ++} ++ ++static int apple_j120_setup_storage_port(struct apple_h9p_pcie *pcie, ++ enum apple_h9p_port_result *result) ++{ ++ void __iomem *config = pcie->base_config; ++ void __iomem *base = pcie->base_port[0]; ++ u32 linksts; ++ u64 cap; ++ int ret; ++ ++ ret = gpiod_direction_output(pcie->perst[0], 1); ++ if (ret) ++ return ret; ++ ++ apple_j120_set_nvme_mode(pcie, true); ++ ret = apple_t8011_enable_rc_port(pcie, 0, false, false, 100); ++ if (ret) { ++ apple_j120_set_nvme_mode(pcie, false); ++ return ret; ++ } ++ ++ ret = devm_add_action_or_reset(pcie->dev, apple_j120_storage_disable, pcie); ++ if (ret) ++ return ret; ++ ++ ret = apple_dart_reload_configuration(pcie->manual_dart[0], pcie->manual_dart_sid[0]); ++ if (ret) ++ return ret; ++ ++ cap = apple_h9p_read_pci_cap(pcie, 0, PCI_CAP_ID_EXP); ++ if (!cap) ++ return -ENODEV; ++ pcie->pcie_cap[0] = cap; ++ h9p_rmww(config + cap + PCI_EXP_LNKCTL2, PCI_EXP_LNKCTL2_TLS, H9P_LINK_SPEED_8GT); ++ apple_h9p_apply_tunables(config, t8011_storage_config_tunables, ++ ARRAY_SIZE(t8011_storage_config_tunables)); ++ apple_h9p_apply_tunables(base, t8011_storage_port_tunables, ++ ARRAY_SIZE(t8011_storage_port_tunables)); ++ ++ h9p_rmw(config + 0x8e0, 0, BIT(0)); ++ h9p_rmw(config + 0x80c, 0, BIT(17)); ++ h9p_rmw(config + 0x890, 0, BIT(9) | BIT(12)); ++ ++ writel(H9P_PORT_IRQMASK_PRE_LINK, base + H9P_PORT_IRQMASK); ++ writel(H9P_PORT_IRQSTAT_PRE_LINK, base + H9P_PORT_IRQSTAT); ++ h9p_rmw(base + H9P_PORT_ENABLE, 0, H9P_PORT_ENABLE_APPLE); ++ writel(apple_h9p_msi_control(pcie, 0), base + H9P_PORT_MSICTL); ++ writel(apple_h9p_msi_vector_base(pcie, 0), base + H9P_PORT_MSIVECBASE); ++ writel(H9P_PORT_IRQMASK_LINK_UP, base + H9P_PORT_IRQMASK); ++ ++ ret = gpiod_direction_output(pcie->perst[0], 0); ++ if (ret) ++ return ret; ++ h9p_rmw(base + H9P_PORT_LTSSMCTL, 0, H9P_PORT_LTSSM_ENABLE); ++ ret = apple_h9p_wait_link(pcie, 0, &linksts); ++ if (ret) ++ return ret; ++ ++ *result = APPLE_H9P_PORT_READY; ++ return 0; ++} ++ + static int apple_t8011_setup_port(struct apple_h9p_pcie *pcie, unsigned int port, + enum apple_h9p_port_result *result) + { +@@ -2582,6 +2683,8 @@ static int apple_t8011_setup_port(struct apple_h9p_pcie *pcie, unsigned int port + *result = APPLE_H9P_PORT_DISABLED; + if (port >= pcie->num_ports) + return -EOPNOTSUPP; ++ if (!port) ++ return apple_j120_setup_storage_port(pcie, result); + if (port != 2) + return -EOPNOTSUPP; + speed = pcie->max_link_speed[port] ?: H9P_LINK_SPEED_2_5GT; +@@ -2649,47 +2752,50 @@ static int apple_t8011_setup_port(struct apple_h9p_pcie *pcie, unsigned int port + return 0; + } + +-/* Validate the J120 profile before enabling link clocks or programming PCIe. */ +-static int apple_j120_pcie_parse(struct apple_h9p_pcie *pcie) ++static int apple_j120_pcie_parse_port(struct apple_h9p_pcie *pcie, ++ unsigned int port, unsigned int bus, ++ const u32 *map) + { +- struct device_node *np = pcie->dev->of_node; + struct platform_device *dart_pdev; + struct device_node *mapped; + struct resource dart_res; + resource_size_t dart_base; +- unsigned int port; +- u32 aperture; +- u32 map[8], doorbell, mask; ++ u32 aperture, bus_range[2]; + int ret; + +- if (pcie->num_ports != 6 || pcie->lane_cfg || +- pcie->preinit_phy_ports || pcie->link_retry_ports || +- pcie->hardware_trained_phy_ports || pcie->inherited_perst_ports) +- return -EOPNOTSUPP; +- +- if (pcie->enabled_ports != BIT(2)) ++ switch (port) { ++ case 0: ++ aperture = 0x3c000000; ++ dart_base = 0x601008000ULL; ++ if (pcie->msi_first[port] || pcie->msi_count[port] != 8 || ++ pcie->max_link_speed[port] != H9P_LINK_SPEED_8GT || ++ of_property_present(pcie->port_nodes[port], "vdd-supply") || ++ of_property_present(pcie->port_nodes[port], "apple,wlan-uart")) ++ return -EINVAL; ++ break; ++ case 2: ++ aperture = 0x3ffff000; ++ dart_base = 0x603008000ULL; ++ if (pcie->msi_first[port] != 16 || pcie->msi_count[port] != 4 || ++ pcie->max_link_speed[port] != H9P_LINK_SPEED_2_5GT || ++ !of_device_is_compatible(pcie->port_nodes[port], "apple,j120-wifi-pcie-port") || ++ !of_property_present(pcie->port_nodes[port], "vdd-supply") || ++ !of_property_present(pcie->port_nodes[port], "apple,wlan-uart")) ++ return -EINVAL; ++ break; ++ default: + return -EOPNOTSUPP; +- port = 2; +- aperture = 0x3ffff000; +- dart_base = 0x603008000ULL; +- if (pcie->msi_first[port] != 16 || pcie->msi_count[port] != 4 || +- pcie->max_link_speed[port] != H9P_LINK_SPEED_2_5GT || +- pcie->deferred_power_ports != BIT(2) || +- !of_device_is_compatible(pcie->port_nodes[port], "apple,j120-wifi-pcie-port") || +- !of_property_present(pcie->port_nodes[port], "vdd-supply") || +- !of_property_present(pcie->port_nodes[port], "apple,wlan-uart")) +- return -EINVAL; ++ } + if (!pcie->manual_dart[port] || pcie->manual_dart_sid[port] || + !of_device_is_compatible(pcie->port_nodes[port], "pciclass,0604")) + return -EINVAL; + +- ret = of_property_count_u32_elems(np, "iommu-map"); +- if (ret != ARRAY_SIZE(map)) +- return -EINVAL; +- ret = of_property_read_u32_array(np, "iommu-map", map, ARRAY_SIZE(map)); ++ ret = of_property_read_u32_array(pcie->port_nodes[port], "bus-range", ++ bus_range, ARRAY_SIZE(bus_range)); + if (ret) + return ret; +- if (map[0] != 0x100 || map[2] || map[3] || map[4] != 0x80000000 || ++ if (bus_range[0] != bus || bus_range[1] != bus || ++ map[0] != (bus << 8) || map[2] || map[3] || map[4] != 0x80000000 || + map[5] || map[6] != aperture || map[7] != 1) + return -EINVAL; + mapped = of_find_node_by_phandle(map[1]); +@@ -2706,6 +2812,38 @@ static int apple_j120_pcie_parse(struct apple_h9p_pcie *pcie) + if (ret) + return ret; + ++ /* Every enabled port's DART must bind before starting the shared PHY. */ ++ dart_pdev = of_find_device_by_node(pcie->manual_dart[port]); ++ if (!dart_pdev) ++ return -EPROBE_DEFER; ++ ret = device_is_bound(&dart_pdev->dev) ? 0 : -EPROBE_DEFER; ++ platform_device_put(dart_pdev); ++ return ret; ++} ++ ++/* Validate both independent J120 ports before enabling the common PHY. */ ++static int apple_j120_pcie_parse(struct apple_h9p_pcie *pcie) ++{ ++ struct device_node *np = pcie->dev->of_node; ++ u32 map[16], doorbell, mask; ++ unsigned int port, bus = 1, cells; ++ int ret; ++ ++ if (pcie->num_ports != 6 || pcie->lane_cfg || ++ pcie->preinit_phy_ports || pcie->link_retry_ports || ++ pcie->hardware_trained_phy_ports || pcie->inherited_perst_ports || ++ !pcie->enabled_ports || (pcie->enabled_ports & ~(BIT(0) | BIT(2)))) ++ return -EOPNOTSUPP; ++ if (pcie->deferred_power_ports != (pcie->enabled_ports & BIT(2))) ++ return -EINVAL; ++ ++ cells = hweight32(pcie->enabled_ports) * 8; ++ ret = of_property_count_u32_elems(np, "iommu-map"); ++ if (ret != cells) ++ return -EINVAL; ++ ret = of_property_read_u32_array(np, "iommu-map", map, cells); ++ if (ret) ++ return ret; + ret = of_property_read_u32(np, "iommu-map-mask", &mask); + if (ret || mask != 0xff00) + return -EINVAL; +@@ -2713,13 +2851,16 @@ static int apple_j120_pcie_parse(struct apple_h9p_pcie *pcie) + if (ret || doorbell != H9P_DEFAULT_MSI_DOORBELL) + return -EINVAL; + +- /* Wait for DART registration before starting the shared PHY. */ +- dart_pdev = of_find_device_by_node(pcie->manual_dart[port]); +- if (!dart_pdev) +- return -EPROBE_DEFER; +- ret = device_is_bound(&dart_pdev->dev) ? 0 : -EPROBE_DEFER; +- platform_device_put(dart_pdev); +- return ret; ++ /* Bus assignment follows ascending root-port order, as PCI enumeration. */ ++ for (port = 0; port < H9P_MAX_PORTS; port++) { ++ if (!(pcie->enabled_ports & BIT(port))) ++ continue; ++ ret = apple_j120_pcie_parse_port(pcie, port, bus, &map[(bus - 1) * 8]); ++ if (ret) ++ return ret; ++ bus++; ++ } ++ return 0; + } + + static int apple_t8010_setup_common(struct apple_h9p_pcie *pcie) +@@ -2798,7 +2939,9 @@ static int apple_t8011_setup_common(struct apple_h9p_pcie *pcie) + ret = apple_h9p_wait(pcie->base_rc + T8011_RC_COMMON_STAT, + BIT(0), BIT(0), BIT(0), 250000); + if (ret) { +- dev_err(pcie->dev, "common PHY initialization wait failed: %d\n", ret); ++ dev_err(pcie->dev, "common PHY initialization wait failed: %d (RC[%#x]=%#x)\n", ++ ret, T8011_RC_COMMON_STAT, ++ readl(pcie->base_rc + T8011_RC_COMMON_STAT)); + return ret; + } + +@@ -4230,7 +4373,7 @@ static int apple_h9p_pcie_map_resources(struct platform_device *pdev, + return PTR_ERR(pcie->base_port[i]); + } + +- if (pcie->hw->has_nvmmu) { ++ if (pcie->hw->has_nvmmu && (pcie->enabled_ports & BIT(0))) { + pcie->nvmmu.base = + devm_platform_ioremap_resource_byname(pdev, "nvmmu"); + if (IS_ERR(pcie->nvmmu.base)) +@@ -4594,15 +4737,19 @@ static const struct apple_h9p_hw apple_h9p_hw_t7000 = { + .no_port_irqs = true, + }; + +-/* J120 uses separate Wi-Fi and storage enumeration profiles. */ ++/* J120 uses separate Wi-Fi and storage profiles. */ + static const struct apple_h9p_hw apple_h9p_hw_j120 = { + .num_ports = 6, + .parse = apple_j120_pcie_parse, + .setup_common = apple_t8011_setup_common, + .setup_port = apple_t8011_setup_port, + .link_settle_ms = 100, ++ /* AppleT8011PCIe's AppleNVMeMMU polls the init bit itself, not bit 4. */ ++ .nvmmu_init_busy = H9P_NVMMU_TCB_CTRL_INIT, + .has_clocks = true, + .has_phy = true, ++ .has_nvmmu = true, ++ .nvmmu_optional = true, + }; + + static const struct apple_h9p_hw apple_h9p_hw_t8010 = { diff --git a/kernel/patches/drivers/pci/0044-nvme-apple-support-the-J120-controller-with-bounded-.patch b/kernel/patches/drivers/pci/0044-nvme-apple-support-the-J120-controller-with-bounded-.patch new file mode 100644 index 00000000..289d98b2 --- /dev/null +++ b/kernel/patches/drivers/pci/0044-nvme-apple-support-the-J120-controller-with-bounded-.patch @@ -0,0 +1,247 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:40:24 +0100 +Subject: [PATCH] nvme: apple: support the J120 controller with bounded + namespace writes + +Assisted-by: LLM +--- + drivers/nvme/host/core.c | 16 +++++++++- + drivers/nvme/host/nvme.h | 10 ++++++ + drivers/nvme/host/pci-apple-ans.c | 27 ++++++++++++++++ + drivers/nvme/host/pci-internal.h | 1 + + drivers/nvme/host/pci.c | 51 +++++++++++++++++++++++++++++++ + 5 files changed, 104 insertions(+), 1 deletion(-) + +diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c +index 1322c678f..ebfdb0b26 100644 +--- a/drivers/nvme/host/core.c ++++ b/drivers/nvme/host/core.c +@@ -2155,6 +2155,12 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, + else + lim->max_hw_discard_sectors = 0; + ++ /* The primary-namespace trial admits ordinary Write and Flush only. */ ++ if (ctrl->quirks & NVME_QUIRK_PRIMARY_NS_WRITES) { ++ lim->max_write_zeroes_sectors = 0; ++ lim->max_hw_discard_sectors = 0; ++ } ++ + /* + * NVMe namespaces advertise both a preferred deallocate granularity + * (for a discard length) and alignment (for a discard starting offset). +@@ -2194,7 +2200,10 @@ static bool nvme_update_disk_info(struct nvme_ns *ns, struct nvme_id_ns *id, + + static bool nvme_ns_is_readonly(struct nvme_ns *ns, struct nvme_ns_info *info) + { +- return info->is_readonly || test_bit(NVME_NS_FORCE_RO, &ns->flags); ++ return info->is_readonly || test_bit(NVME_NS_FORCE_RO, &ns->flags) || ++ ((ns->ctrl->quirks & NVME_QUIRK_READ_ONLY) && ++ (!(ns->ctrl->quirks & NVME_QUIRK_PRIMARY_NS_WRITES) || ++ ns->head->ns_id != 1)); + } + + static inline bool nvme_first_scan(struct gendisk *disk) +@@ -3791,6 +3800,10 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) + ctrl->queue_count = 1; + } + ++ /* Read-only bring-up leaves optional controller features untouched. */ ++ if (ctrl->quirks & NVME_QUIRK_READ_ONLY) ++ goto skip_optional_features; ++ + ret = nvme_configure_apst(ctrl); + if (ret < 0) + return ret; +@@ -3805,6 +3818,7 @@ int nvme_init_ctrl_finish(struct nvme_ctrl *ctrl, bool was_suspended) + + nvme_configure_opal(ctrl, was_suspended); + ++skip_optional_features: + if (!ctrl->identified && !nvme_discovery_ctrl(ctrl)) { + /* + * Do not return errors unless we are in a controller reset, +diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h +index 75e5d5a8a..48bd6aaa4 100644 +--- a/drivers/nvme/host/nvme.h ++++ b/drivers/nvme/host/nvme.h +@@ -183,6 +183,12 @@ enum nvme_quirks { + * Admin queue DMA buffers must be page aligned + */ + NVME_QUIRK_ADMIN_PAGE_ALIGN = (1 << 23), ++ ++ /* Diagnostic host: expose namespaces read-only and reject media changes. */ ++ NVME_QUIRK_READ_ONLY = (1 << 24), ++ ++ /* With READ_ONLY: permit only namespace 1 Write/Flush for bring-up. */ ++ NVME_QUIRK_PRIMARY_NS_WRITES = (1 << 25), + }; + + static inline char *nvme_quirk_name(enum nvme_quirks q) +@@ -236,6 +242,10 @@ static inline char *nvme_quirk_name(enum nvme_quirks q) + return "dmapool_align_512"; + case NVME_QUIRK_ADMIN_PAGE_ALIGN: + return "admin_page_align"; ++ case NVME_QUIRK_READ_ONLY: ++ return "read_only"; ++ case NVME_QUIRK_PRIMARY_NS_WRITES: ++ return "primary_ns_writes"; + } + + return "unknown"; +diff --git a/drivers/nvme/host/pci-apple-ans.c b/drivers/nvme/host/pci-apple-ans.c +index 96da756a2..262b17aab 100644 +--- a/drivers/nvme/host/pci-apple-ans.c ++++ b/drivers/nvme/host/pci-apple-ans.c +@@ -58,6 +58,8 @@ struct apple_ans_nvme_req { + * @sleep_stop: the controller's port loses power in system sleep: stop the + * controller first, as iOS (AppleEmbeddedNVMeController) does, + * and bring it up from reset on resume ++ * @read_only: diagnostic host rejects media changes and optional feature setup ++ * @primary_ns_writes: diagnostic exception for namespace 1 Write and Flush + */ + struct apple_ans_host { + u32 l1ss_ctl1; +@@ -65,6 +67,8 @@ struct apple_ans_host { + unsigned int rdy_timeout_ms; + bool late_bus_master; + bool sleep_stop; ++ bool read_only; ++ bool primary_ns_writes; + }; + + static const struct apple_ans_host apple_ans_host_s8003 = { +@@ -84,6 +88,16 @@ static const struct apple_ans_host apple_ans_host_t8010 = { + .sleep_stop = true, + }; + ++/* J120 uses the same L1SS control, verified against its native port data. */ ++static const struct apple_ans_host apple_ans_host_j120 = { ++ .l1ss_ctl1 = APPLE_ANS_L1SS_CTL1_T8010, ++ .sleep_stop = true, ++ /* Namespace writes and their recovery path are not yet qualified. */ ++ .read_only = true, ++ /* Isolated write-qualification candidate; never enable auxiliary writes. */ ++ .primary_ns_writes = true, ++}; ++ + struct apple_ans_nvme { + const struct apple_ans_host *host; + /* Last CC written through the register hook, and when */ +@@ -105,6 +119,7 @@ static struct apple_ans_nvme *nvme_pci_apple_ans(struct nvme_dev *dev) + } + + static const struct of_device_id nvme_pci_apple_ans_hosts[] = { ++ { .compatible = "apple,j120-pcie", .data = &apple_ans_host_j120 }, + { .compatible = "apple,s8003-pcie", .data = &apple_ans_host_s8003 }, + { .compatible = "apple,t8010-pcie", .data = &apple_ans_host_t8010 }, + { } +@@ -139,6 +154,18 @@ bool nvme_pci_apple_ans_match(struct pci_dev *pdev) + nvme_pci_apple_ans_host_match(pdev); + } + ++unsigned long nvme_pci_apple_ans_quirks(struct pci_dev *pdev) ++{ ++ const struct of_device_id *match = nvme_pci_apple_ans_host_match(pdev); ++ const struct apple_ans_host *host = match ? match->data : NULL; ++ ++ /* Avoid automatic power-state programming during read-only bring-up. */ ++ if (!host || !host->read_only) ++ return 0; ++ return NVME_QUIRK_READ_ONLY | NVME_QUIRK_NO_APST | ++ (host->primary_ns_writes ? NVME_QUIRK_PRIMARY_NS_WRITES : 0); ++} ++ + static int nvme_pci_apple_ans_init(struct nvme_dev *dev, int node) + { + const struct of_device_id *match; +diff --git a/drivers/nvme/host/pci-internal.h b/drivers/nvme/host/pci-internal.h +index e789f1e2e..9d9a69b58 100644 +--- a/drivers/nvme/host/pci-internal.h ++++ b/drivers/nvme/host/pci-internal.h +@@ -205,5 +205,6 @@ struct nvme_iod { + extern const struct nvme_pci_dma_ops nvme_pci_apple_ans_ops; + + bool nvme_pci_apple_ans_match(struct pci_dev *pdev); ++unsigned long nvme_pci_apple_ans_quirks(struct pci_dev *pdev); + + #endif /* _NVME_PCI_INTERNAL_H */ +diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c +index 327668425..6708a4458 100644 +--- a/drivers/nvme/host/pci.c ++++ b/drivers/nvme/host/pci.c +@@ -1267,9 +1267,46 @@ static blk_status_t nvme_map_metadata(struct request *req) + return nvme_pci_setup_meta_mptr(req); + } + ++/* ++ * Fail closed before mapping DMA, including privileged ioctl/io_uring requests. ++ * The only I/O command is Read. Admin commands can inspect the controller and ++ * manage volatile queues/events, but cannot change namespaces or saved state. ++ */ ++static bool nvme_readonly_cmd_allowed(u8 opcode, bool admin, u32 feature_id) ++{ ++ if (!admin) ++ return opcode == nvme_cmd_read; ++ ++ switch (opcode) { ++ case nvme_admin_delete_sq: ++ case nvme_admin_create_sq: ++ case nvme_admin_get_log_page: ++ case nvme_admin_delete_cq: ++ case nvme_admin_create_cq: ++ case nvme_admin_identify: ++ case nvme_admin_abort_cmd: ++ case nvme_admin_get_features: ++ case nvme_admin_async_event: ++ return true; ++ case nvme_admin_set_features: ++ /* No Save bit or reserved bits, and only volatile queue/event setup. */ ++ return feature_id == NVME_FEAT_NUM_QUEUES || ++ feature_id == NVME_FEAT_ASYNC_EVENT; ++ default: ++ return false; ++ } ++} ++ ++static bool nvme_primary_write_allowed(u8 opcode, bool admin, u32 nsid) ++{ ++ return !admin && nsid == 1 && ++ (opcode == nvme_cmd_write || opcode == nvme_cmd_flush); ++} ++ + static blk_status_t nvme_prep_rq(struct request *req) + { + struct nvme_iod *iod = blk_mq_rq_to_pdu(req); ++ struct nvme_queue *nvmeq = req->mq_hctx->driver_data; + blk_status_t ret; + + iod->flags = 0; +@@ -1284,6 +1321,19 @@ static blk_status_t nvme_prep_rq(struct request *req) + if (ret) + return ret; + ++ if (unlikely(nvmeq->dev->ctrl.quirks & NVME_QUIRK_READ_ONLY) && ++ !nvme_readonly_cmd_allowed(iod->cmd.common.opcode, !nvmeq->qid, ++ le32_to_cpu(iod->cmd.features.fid)) && ++ !((nvmeq->dev->ctrl.quirks & NVME_QUIRK_PRIMARY_NS_WRITES) && ++ nvme_primary_write_allowed(iod->cmd.common.opcode, !nvmeq->qid, ++ le32_to_cpu(iod->cmd.common.nsid)))) { ++ dev_warn_ratelimited(nvmeq->dev->dev, ++ "read-only bring-up: rejected %s opcode %#x\n", ++ nvmeq->qid ? "I/O" : "admin", iod->cmd.common.opcode); ++ ret = BLK_STS_PROTECTION; ++ goto out_free_cmd; ++ } ++ + if (blk_rq_nr_phys_segments(req)) { + ret = nvme_map_data(req); + if (ret) +@@ -3809,6 +3859,7 @@ static struct nvme_dev *nvme_pci_alloc_dev(struct pci_dev *pdev, + dev->dma_ops = &nvme_pci_apple_ans_ops; + /* One MSI and shared tags, as for 106b:2002 */ + quirks |= NVME_QUIRK_SINGLE_VECTOR | NVME_QUIRK_SHARED_TAGS; ++ quirks |= nvme_pci_apple_ans_quirks(pdev); + } + if (dev->dma_ops) { + ret = dev->dma_ops->init(dev, node); diff --git a/kernel/patches/drivers/pinctrl/0004-dt-bindings-pinctrl-describe-the-T8011-S8000-compati.patch b/kernel/patches/drivers/pinctrl/0004-dt-bindings-pinctrl-describe-the-T8011-S8000-compati.patch new file mode 100644 index 00000000..8bb3f723 --- /dev/null +++ b/kernel/patches/drivers/pinctrl/0004-dt-bindings-pinctrl-describe-the-T8011-S8000-compati.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:52 +0100 +Subject: [PATCH] dt-bindings: pinctrl: describe the T8011 S8000-compatible + GPIO block + +T8011 uses the existing S8000 pin-function semantics. Describe the explicit chip compatible and its two fallbacks. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +index f08d2c4f5..0fb1d8cb0 100644 +--- a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml ++++ b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +@@ -17,6 +17,10 @@ description: | + properties: + compatible: + oneOf: ++ - items: ++ - const: apple,t8011-pinctrl ++ - const: apple,s8000-pinctrl ++ - const: apple,pinctrl + - items: + - enum: + - apple,t6020-pinctrl diff --git a/kernel/patches/drivers/pinctrl/0005-pinctrl-apple-retain-parent-IRQ-arrays-for-the-GPIO-.patch b/kernel/patches/drivers/pinctrl/0005-pinctrl-apple-retain-parent-IRQ-arrays-for-the-GPIO-.patch new file mode 100644 index 00000000..3a3e6252 --- /dev/null +++ b/kernel/patches/drivers/pinctrl/0005-pinctrl-apple-retain-parent-IRQ-arrays-for-the-GPIO-.patch @@ -0,0 +1,61 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:52 +0100 +Subject: [PATCH] pinctrl: apple: retain parent IRQ arrays for the GPIO + lifetime + +gpiolib retains the parent IRQ and handler-data arrays after registration. Allocate both with device-managed lifetime instead of freeing them on successful registration. Match T8011 to the existing S8000 mux implementation. + +Assisted-by: LLM +--- + drivers/pinctrl/pinctrl-apple-gpio.c | 14 +++++++------- + 1 file changed, 7 insertions(+), 7 deletions(-) + +diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c +index b97023c97..df9366544 100644 +--- a/drivers/pinctrl/pinctrl-apple-gpio.c ++++ b/drivers/pinctrl/pinctrl-apple-gpio.c +@@ -427,19 +427,20 @@ static int apple_gpio_register(struct apple_gpio_pinctrl *pctl) + gpio_irq_chip_set_chip(girq, &apple_gpio_irqchip); + girq->parent_handler = apple_gpio_irq_handler; + +- girq->parents = kmalloc_array(girq->num_parents, ++ girq->parents = devm_kcalloc(pctl->dev, girq->num_parents, + sizeof(*girq->parents), + GFP_KERNEL); +- irq_data = kmalloc_objs(*irq_data, girq->num_parents); ++ irq_data = devm_kcalloc(pctl->dev, girq->num_parents, ++ sizeof(*irq_data), GFP_KERNEL); + if (!girq->parents || !irq_data) { + ret = -ENOMEM; +- goto out_free_irq_data; ++ goto out_return; + } + + for (i = 0; i < girq->num_parents; i++) { + ret = platform_get_irq(to_platform_device(pctl->dev), i); + if (ret < 0) +- goto out_free_irq_data; ++ goto out_return; + + girq->parents[i] = ret; + pctl->irqgrps[i] = i; +@@ -454,9 +455,7 @@ static int apple_gpio_register(struct apple_gpio_pinctrl *pctl) + + ret = devm_gpiochip_add_data(pctl->dev, &pctl->gpio_chip, pctl); + +-out_free_irq_data: +- kfree(girq->parents); +- kfree(irq_data); ++out_return: + + return ret; + } +@@ -558,6 +557,7 @@ static const struct apple_gpio_soc_data apple_gpio_s8000_data = { + + static const struct of_device_id apple_gpio_pinctrl_of_match[] = { + { .compatible = "apple,s8000-pinctrl", .data = &apple_gpio_s8000_data }, ++ { .compatible = "apple,t8011-pinctrl", .data = &apple_gpio_s8000_data }, + { .compatible = "apple,t8103-pinctrl", }, + { .compatible = "apple,pinctrl", }, + { } diff --git a/kernel/patches/drivers/pmdomain/0002-pmdomain-apple-verify-PMGR-reset-state.patch b/kernel/patches/drivers/pmdomain/0002-pmdomain-apple-verify-PMGR-reset-state.patch new file mode 100644 index 00000000..57eb7925 --- /dev/null +++ b/kernel/patches/drivers/pmdomain/0002-pmdomain-apple-verify-PMGR-reset-state.patch @@ -0,0 +1,114 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sat, 21 Nov 2026 20:12:17 +0100 +Subject: [PATCH] pmdomain: apple: verify PMGR reset state + +Propagate register access errors and check that both reset and device-disable bits match the requested state. A client that uses reset to stop device DMA must be able to distinguish a confirmed reset from an unsuccessful register write. + +Assisted-by: LLM +--- + drivers/pmdomain/apple/pmgr-pwrstate.c | 53 +++++++++++++++++++++----- + 1 file changed, 43 insertions(+), 10 deletions(-) + +diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c +index 2a03318b2..0499a5b43 100644 +--- a/drivers/pmdomain/apple/pmgr-pwrstate.c ++++ b/drivers/pmdomain/apple/pmgr-pwrstate.c +@@ -190,10 +190,29 @@ static const struct clk_ops apple_pmgr_clk_ops = { + .is_enabled = apple_pmgr_clk_is_enabled, + }; + ++/* ++ * Confirm both the bus-disable and reset bits. Callers that retain DMA ++ * buffers until reset succeeds need a hardware readback, not just a ++ * successful software write. ++ */ ++static int apple_pmgr_reset_verify(struct apple_pmgr_ps *ps, bool asserted) ++{ ++ u32 mask = APPLE_PMGR_DEV_DISABLE | APPLE_PMGR_RESET; ++ u32 val; ++ int ret; ++ ++ ret = regmap_read(ps->regmap, ps->offset, &val); ++ if (ret) ++ return ret; ++ ++ return (val & mask) == (asserted ? mask : 0) ? 0 : -EIO; ++} ++ + static int apple_pmgr_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) + { + struct apple_pmgr_ps *ps = rcdev_to_apple_pmgr_ps(rcdev); + unsigned long flags; ++ int ret; + + spin_lock_irqsave(&ps->lock, flags); + +@@ -202,33 +221,44 @@ static int apple_pmgr_reset_assert(struct reset_controller_dev *rcdev, unsigned + + dev_dbg(ps->dev, "PS 0x%x: assert reset\n", ps->offset); + /* Quiesce device before asserting reset */ +- regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, +- APPLE_PMGR_DEV_DISABLE); +- regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, +- APPLE_PMGR_RESET); ++ ret = regmap_update_bits(ps->regmap, ps->offset, ++ APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, ++ APPLE_PMGR_DEV_DISABLE); ++ if (!ret) ++ ret = regmap_update_bits(ps->regmap, ps->offset, ++ APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, ++ APPLE_PMGR_RESET); ++ if (!ret) ++ ret = apple_pmgr_reset_verify(ps, true); + + spin_unlock_irqrestore(&ps->lock, flags); + +- return 0; ++ return ret; + } + + static int apple_pmgr_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) + { + struct apple_pmgr_ps *ps = rcdev_to_apple_pmgr_ps(rcdev); + unsigned long flags; ++ int ret; + + spin_lock_irqsave(&ps->lock, flags); + + dev_dbg(ps->dev, "PS 0x%x: deassert reset\n", ps->offset); +- regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, 0); +- regmap_update_bits(ps->regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, 0); ++ ret = regmap_update_bits(ps->regmap, ps->offset, ++ APPLE_PMGR_FLAGS | APPLE_PMGR_RESET, 0); ++ if (!ret) ++ ret = regmap_update_bits(ps->regmap, ps->offset, ++ APPLE_PMGR_FLAGS | APPLE_PMGR_DEV_DISABLE, 0); ++ if (!ret) ++ ret = apple_pmgr_reset_verify(ps, false); + + if (ps->genpd.status == GENPD_STATE_OFF) + dev_err(ps->dev, "PS 0x%x: RESET was deasserted while powered down\n", ps->offset); + + spin_unlock_irqrestore(&ps->lock, flags); + +- return 0; ++ return ret; + } + + static int apple_pmgr_reset_reset(struct reset_controller_dev *rcdev, unsigned long id) +@@ -247,9 +277,12 @@ static int apple_pmgr_reset_reset(struct reset_controller_dev *rcdev, unsigned l + static int apple_pmgr_reset_status(struct reset_controller_dev *rcdev, unsigned long id) + { + struct apple_pmgr_ps *ps = rcdev_to_apple_pmgr_ps(rcdev); +- u32 reg = 0; ++ u32 reg; ++ int ret; + +- regmap_read(ps->regmap, ps->offset, ®); ++ ret = regmap_read(ps->regmap, ps->offset, ®); ++ if (ret) ++ return ret; + + return !!(reg & APPLE_PMGR_RESET); + } diff --git a/kernel/patches/drivers/power/0044-dt-bindings-power-supply-describe-the-Apple-D2355-Tr.patch b/kernel/patches/drivers/power/0044-dt-bindings-power-supply-describe-the-Apple-D2355-Tr.patch new file mode 100644 index 00000000..6365f709 --- /dev/null +++ b/kernel/patches/drivers/power/0044-dt-bindings-power-supply-describe-the-Apple-D2355-Tr.patch @@ -0,0 +1,109 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:11 +0100 +Subject: [PATCH] dt-bindings: power: supply: describe the Apple D2355 Tristar + charger + +Describe the split charger and ADC suppliers, calibration input and current and battery limits for J120. + +Assisted-by: LLM +--- + .../supply/apple,d2355-tristar-charger.yaml | 89 +++++++++++++++++++ + 1 file changed, 89 insertions(+) + create mode 100644 Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml b/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml +new file mode 100644 +index 000000000..23f5c5769 +--- /dev/null ++++ b/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml +@@ -0,0 +1,89 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/power/supply/apple,d2355-tristar-charger.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple D2355 Tristar Lightning charger ++ ++maintainers: ++ - Henrik Klee ++ ++description: | ++ The D2355 sets the Lightning input current on the iPad Pro 12.9-inch (2017). ++ A Tristar port controller identifies the attached source using the ADC in the ++ August PMIC. The charger controls the role of the USB device controller while ++ identifying the source. ++ ++allOf: ++ - $ref: power-supply.yaml# ++ ++properties: ++ compatible: ++ const: apple,d2355-tristar-charger ++ ++ reg: ++ items: ++ - description: Charger status register bank. ++ - description: Charger control register bank. ++ - description: ADC register bank in the August PMIC. ++ ++ reg-names: ++ items: ++ - const: status ++ - const: control ++ - const: adc ++ ++ interrupts-extended: ++ items: ++ - description: D2355 parent-line notification. ++ - description: August ADC conversion complete. ++ - description: D2355 source event 40. ++ - description: D2355 source event 42. ++ - description: D2355 source event 53. ++ ++ apple,tristar: ++ $ref: /schemas/types.yaml#/definitions/phandle ++ description: The Tristar port controller. ++ ++ apple,adc-pmic: ++ $ref: /schemas/types.yaml#/definitions/phandle ++ description: The August PMIC providing the ADC registers. ++ ++ firmware-name: ++ maxItems: 1 ++ description: The D2355 input-limit calibration for this unit. ++ ++ apple,pack-limits: ++ $ref: /schemas/types.yaml#/definitions/int32-array ++ description: | ++ Minimum and maximum battery temperature in tenths of a degree Celsius, ++ voltage in microvolts, and signed current in microamps, in that order. ++ items: ++ - description: Minimum temperature. ++ - description: Maximum temperature. ++ - description: Minimum voltage. ++ - description: Maximum voltage. ++ - description: Minimum current. ++ - description: Maximum current. ++ ++ input-current-limit-microamp: ++ description: Board maximum input current. ++ ++ port: ++ $ref: /schemas/graph.yaml#/properties/port ++ description: Link to the USB controller whose role the charger sets. ++ ++required: ++ - compatible ++ - reg ++ - reg-names ++ - interrupts-extended ++ - apple,tristar ++ - apple,adc-pmic ++ - firmware-name ++ - apple,pack-limits ++ - input-current-limit-microamp ++ - port ++ ++unevaluatedProperties: false diff --git a/kernel/patches/drivers/power/0045-power-supply-apple_tristar_charger-support-calibrate.patch b/kernel/patches/drivers/power/0045-power-supply-apple_tristar_charger-support-calibrate.patch new file mode 100644 index 00000000..7b16b80c --- /dev/null +++ b/kernel/patches/drivers/power/0045-power-supply-apple_tristar_charger-support-calibrate.patch @@ -0,0 +1,1160 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:11 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: support calibrated + D2355 input + +Integrate the retained J120 Tristar backend and guarded probe cleanup. Use the tested attachment predicate and the August ADC. Withdraw to fallback on pack-read failure and clear unsampled cable details. + +Assisted-by: LLM +--- + .../power/supply/apple_d2355_calibration.h | 129 +++++++ + drivers/power/supply/apple_d2355_current.h | 40 +++ + drivers/power/supply/apple_tristar_charger.c | 319 +++++++++++++----- + drivers/power/supply/apple_tristar_d2355.h | 278 +++++++++++++++ + 4 files changed, 682 insertions(+), 84 deletions(-) + create mode 100644 drivers/power/supply/apple_d2355_calibration.h + create mode 100644 drivers/power/supply/apple_d2355_current.h + create mode 100644 drivers/power/supply/apple_tristar_d2355.h + +diff --git a/drivers/power/supply/apple_d2355_calibration.h b/drivers/power/supply/apple_d2355_calibration.h +new file mode 100644 +index 000000000..585398d17 +--- /dev/null ++++ b/drivers/power/supply/apple_d2355_calibration.h +@@ -0,0 +1,129 @@ ++/* SPDX-License-Identifier: GPL-2.0-only */ ++#ifndef _APPLE_D2355_CALIBRATION_H ++#define _APPLE_D2355_CALIBRATION_H ++ ++#include ++#include ++#include ++#include ++#include ++ ++#define D2355_CAL_POINTS 5 ++#define D2355_CAL_RANGES 4 ++#define D2355_CAL_HV_BYTES 84 ++#define D2355_CAL_ONE 65536 ++ ++struct d2355_calibration { ++ u32 selector; ++ s32 measured[D2355_CAL_RANGES][D2355_CAL_POINTS]; ++}; ++ ++/* Property words are private per-unit Q16 values, not register settings. */ ++static inline int d2355_calibration_parse_hv(const void *data, size_t len, ++ struct d2355_calibration *cal) ++{ ++ struct d2355_calibration parsed; ++ const u8 *bytes = data; ++ unsigned int range, point; ++ u32 word; ++ ++ if (!data || !cal || len != D2355_CAL_HV_BYTES) ++ return -EINVAL; ++ parsed.selector = get_unaligned_le32(bytes); ++ if (parsed.selector < 1 || parsed.selector > 3) ++ return -EINVAL; ++ for (range = 0; range < D2355_CAL_RANGES; range++) { ++ for (point = 0; point < D2355_CAL_POINTS; point++) { ++ word = get_unaligned_le32(bytes + 4 + 20 * range + 4 * point); ++ if (!word || word > S32_MAX) ++ return -EINVAL; ++ if (point && word <= (u32)parsed.measured[range][point - 1]) ++ return -EINVAL; ++ parsed.measured[range][point] = word; ++ } ++ } ++ *cal = parsed; ++ return 0; ++} ++ ++/* Native public nominal landmarks; high ranges depend on format selector. */ ++static const s32 d2355_calibration_nominal[4][5] = { ++ { 100, 500, 1000, 2100, 2400 }, ++ { 100, 480, 500, 1000, 2000 }, ++ { 100, 500, 1000, 1500, 2000 }, ++ { 100, 480, 1000, 1500, 2000 }, ++}; ++ ++/* ++ * No hardware or source admission here. The caller must supply a qualified ++ * active range; this helper never selects voltage modes or authorizes current. ++ * Reject arithmetic outside the representable domain instead of wrapping it. ++ */ ++static inline int d2355_calibration_apply(const struct d2355_calibration *cal, ++ unsigned int range, s32 target_q16, ++ s32 *result_q16) ++{ ++ const s32 *nominal, *measured; ++ s64 numerator, slope, candidate, low, high; ++ s32 dx, dy; ++ unsigned int point, index = 3, percent, correction = 0; ++ ++ if (!cal || !result_q16 || range >= D2355_CAL_RANGES || ++ cal->selector < 1 || cal->selector > 3) ++ return -EINVAL; ++ if (target_q16 < 0 || target_q16 > 2549 * D2355_CAL_ONE) ++ return -ERANGE; ++ nominal = d2355_calibration_nominal[range ? cal->selector : 0]; ++ measured = cal->measured[range]; ++ for (point = 0; point < D2355_CAL_POINTS; point++) ++ if (measured[point] <= 0 || ++ (point && measured[point] <= measured[point - 1])) ++ return -EINVAL; ++ ++ candidate = target_q16; ++ if (target_q16 >= nominal[0] * D2355_CAL_ONE) { ++ for (point = 1; point < D2355_CAL_POINTS; point++) { ++ if (nominal[point] * D2355_CAL_ONE > target_q16) { ++ index = point - 1; ++ break; ++ } ++ } ++ dx = (nominal[index + 1] - nominal[index]) * D2355_CAL_ONE; ++ dy = measured[index + 1] - measured[index]; ++ numerator = (s64)dx * D2355_CAL_ONE; ++ slope = div_s64(numerator, dy); ++ if (slope <= 0 || slope > S32_MAX) ++ return -ERANGE; ++ candidate = (s64)nominal[index] * D2355_CAL_ONE + ++ ((slope * ((s64)target_q16 - measured[index])) >> 16); ++ if (candidate < 0 || candidate > S32_MAX) ++ return -ERANGE; ++ } ++ ++ percent = cal->selector == 2 ? 20 : 15; ++ /* Preserve native integer-mA rounding before the strict bound checks. */ ++ low = div_s64(((100 - percent) * (s64)target_q16) >> 16, 100) * ++ D2355_CAL_ONE; ++ high = div_s64(((100 + percent) * (s64)target_q16) >> 16, 100) * ++ D2355_CAL_ONE; ++ if (candidate <= low || candidate >= high) ++ candidate = target_q16; ++ ++ if (target_q16 >= 100 * D2355_CAL_ONE && cal->selector != 2 && ++ candidate > 10 * D2355_CAL_ONE) { ++ if ((u32)target_q16 >> 18 > 124) { ++ correction = 20; ++ if ((u32)target_q16 >> 19 > 124) { ++ correction = 40; ++ if ((u32)target_q16 >> 18 > 374) ++ correction = target_q16 > 2000 * D2355_CAL_ONE ? 70 : 60; ++ } ++ } ++ candidate -= (10 + correction) * D2355_CAL_ONE; ++ } ++ if (candidate < 0 || candidate > S32_MAX) ++ return -ERANGE; ++ *result_q16 = candidate; ++ return 0; ++} ++#endif +diff --git a/drivers/power/supply/apple_d2355_current.h b/drivers/power/supply/apple_d2355_current.h +new file mode 100644 +index 000000000..43f0aec6b +--- /dev/null ++++ b/drivers/power/supply/apple_d2355_current.h +@@ -0,0 +1,40 @@ ++/* SPDX-License-Identifier: GPL-2.0-only */ ++#ifndef _APPLE_D2355_CURRENT_H ++#define _APPLE_D2355_CURRENT_H ++ ++#include "apple_d2355_calibration.h" ++ ++/* ++ * Convert an already admitted target, using a separately qualified range. ++ * This does not program the input-disable bit or the current-limit register. ++ * Both outputs stay unchanged on error; the caller owns hardware sequencing. ++ */ ++static inline int d2355_current_encode(const struct d2355_calibration *cal, ++ unsigned int range, unsigned int target_ma, ++ u8 *code, bool *disable_input) ++{ ++ s32 calibrated_q16; ++ unsigned int calibrated_ma; ++ u8 encoded; ++ int ret; ++ ++ if (!code || !disable_input) ++ return -EINVAL; ++ if (target_ma > 2549) ++ return -ERANGE; ++ ret = d2355_calibration_apply(cal, range, target_ma * D2355_CAL_ONE, ++ &calibrated_q16); ++ if (ret) ++ return ret; ++ calibrated_ma = calibrated_q16 / D2355_CAL_ONE; ++ if (calibrated_ma < 80) ++ encoded = 8; ++ else if (calibrated_ma > 2549) ++ encoded = 255; ++ else ++ encoded = calibrated_ma / 10; ++ *code = encoded; ++ *disable_input = calibrated_ma < 80; ++ return 0; ++} ++#endif +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index f2c11557c..fa3f28b60 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -37,6 +37,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -67,7 +68,11 @@ + * device tree gives, and how its ADC is driven. The functions are the same + * on both PMICs; the addresses are not. + */ ++static const struct tristar_chip_info tristar_d2365_chip; ++static const struct tristar_chip_info tristar_d2355_chip; ++ + struct tristar_pmic { ++ const struct tristar_chip_info *chip; + u8 connected; /* status bank: connection state */ + u8 connected_new; /* the bit that also marks a new connection */ + u8 status; /* status bank: battery charger state */ +@@ -80,6 +85,7 @@ struct tristar_pmic { + + /* D2365 (iPad 5, iPad 6), from iOS 16 AppleD2365PMUPowerSource */ + static const struct tristar_pmic tristar_d2365 = { ++ .chip = &tristar_d2365_chip, + .connected = 0x09, + .connected_new = BIT(1), + .status = 0x0a, +@@ -97,6 +103,7 @@ static const struct tristar_pmic tristar_d2365 = { + * after each read. The plug event is event 0. + */ + static const struct tristar_pmic tristar_d2207 = { ++ .chip = &tristar_d2365_chip, + .connected = 0x00, + .connected_new = BIT(3), + .status = 0x02, +@@ -107,6 +114,14 @@ static const struct tristar_pmic tristar_d2207 = { + .plug_event = 0, + }; + ++/* D2355 reads connection state via its own status callback and a companion ADC. */ ++static const struct tristar_pmic tristar_d2355 = { ++ .chip = &tristar_d2355_chip, ++ .adc_start = 1, ++ .adc_result = 1, ++ .plug_event = 72, ++}; ++ + /* Interrupts: the PMU line, ADC completion, then the source-change events. */ + #define TRISTAR_IRQ_LINE 0 + #define TRISTAR_IRQ_ADC 1 +@@ -163,9 +178,37 @@ enum cbtl_route { + CBTL_ROUTE_UART2, + }; + ++struct tristar_charger; ++struct tristar_pack; ++ ++/* Keep shared charging policy independent of the PMIC input-limit registers. */ ++struct tristar_chip_info { ++ int (*prepare)(struct tristar_charger *chg); ++ bool (*pack_allows)(struct tristar_charger *chg, const struct tristar_pack *pack); ++ unsigned int status_size, control_size; ++ u8 adc_error_mask; ++ bool strict_limit_errors; ++ bool require_pack_telemetry; ++ bool invalidate_on_line; ++ int (*read_limit)(struct tristar_charger *chg, unsigned int *code); ++ int (*write_limit)(struct tristar_charger *chg, unsigned int code); ++ unsigned int (*code_ma)(struct tristar_charger *chg, unsigned int code); ++ unsigned int (*ma_code)(struct tristar_charger *chg, unsigned int ma); ++ int (*read_status)(struct tristar_charger *chg, unsigned int *status); ++ unsigned int handoff_code; ++ unsigned int attach_code; ++ unsigned int online_status; ++ unsigned int ramp_step_ms; ++ unsigned int fallback_code; ++}; ++ + struct tristar_charger { ++ const struct tristar_chip_info *chip; ++ void *chip_data; ++ bool probe_ready; + struct device *dev; + struct regmap *regmap; ++ struct regmap *adc_regmap; + struct i2c_client *tristar; + struct power_supply *psy; + struct usb_role_switch *role_sw; +@@ -176,9 +219,8 @@ struct tristar_charger { + unsigned int nirqs; + int plug_irq; /* wakes the system, 0 without one */ + const struct tristar_pmic *pmic; +- u32 connected_reg; +- u32 status_reg; +- u32 limit_reg; ++ u32 status_base; ++ u32 control_base; + u32 adc_base; + unsigned int max_ma; + +@@ -234,26 +276,68 @@ struct tristar_charger { + bool usb_held; + }; + +-static unsigned int tristar_code_ma(unsigned int code) ++static unsigned int tristar_d2365_code_ma(struct tristar_charger *chg, unsigned int code) + { + return code * 25 / 2 + 75; + } + + /* Round down: quantization must never exceed a permitted current. */ +-static unsigned int tristar_ma_code(unsigned int ma) ++static unsigned int tristar_d2365_ma_code(struct tristar_charger *chg, unsigned int ma) + { + return ma <= 75 ? 0 : (ma - 75) * 2 / 25; + } + ++static int tristar_d2365_read_limit(struct tristar_charger *chg, ++ unsigned int *code) ++{ ++ return regmap_read(chg->regmap, ++ chg->control_base + chg->pmic->input_limit, code); ++} ++ ++static int tristar_d2365_write_limit(struct tristar_charger *chg, ++ unsigned int code) ++{ ++ return regmap_write(chg->regmap, ++ chg->control_base + chg->pmic->input_limit, code); ++} ++ ++static int tristar_d2365_read_status(struct tristar_charger *chg, ++ unsigned int *status) ++{ ++ return regmap_read(chg->regmap, ++ chg->status_base + chg->pmic->status, status); ++} ++ ++static const struct tristar_chip_info tristar_d2365_chip = { ++ .adc_error_mask = 0x80, ++ .read_limit = tristar_d2365_read_limit, ++ .write_limit = tristar_d2365_write_limit, ++ .code_ma = tristar_d2365_code_ma, ++ .ma_code = tristar_d2365_ma_code, ++ .read_status = tristar_d2365_read_status, ++ .handoff_code = TRISTAR_CHG_HANDOFF_CODE, ++ .attach_code = TRISTAR_CHG_HANDOFF_CODE, ++ .fallback_code = TRISTAR_CHG_FALLBACK_CODE, ++}; ++ ++static unsigned int tristar_code_ma(struct tristar_charger *chg, unsigned int code) ++{ ++ return chg->chip->code_ma(chg, code); ++} ++ ++static unsigned int tristar_ma_code(struct tristar_charger *chg, unsigned int ma) ++{ ++ return chg->chip->ma_code(chg, ma); ++} ++ + static int tristar_set_code(struct tristar_charger *chg, unsigned int code) + { +- u32 reg = chg->limit_reg; + unsigned int readback; + int ret; + +- ret = regmap_write(chg->regmap, reg, code); ++ ret = chg->chip->write_limit(chg, code); + if (!ret) +- ret = regmap_read(chg->regmap, reg, &readback); ++ ret = chg->chip->read_limit(chg, &readback); + if (!ret && readback != code) + ret = -EIO; + if (!ret) +@@ -308,8 +392,10 @@ static int tristar_read_pack(struct tristar_pack *pack) + } + + /* Grants above the fallback are allowed only inside these pack limits. */ +-static bool tristar_pack_allows_grant(const struct tristar_pack *pack) ++static bool tristar_pack_allows_grant(struct tristar_charger *chg, const struct tristar_pack *pack) + { ++ if (chg->chip->pack_allows) ++ return chg->chip->pack_allows(chg, pack); + return pack->temp >= 50 && pack->temp <= 400 && + pack->voltage_uv >= 3200000 && pack->voltage_uv <= 4350000 && + pack->current_ua >= -3000000 && pack->current_ua <= 3000000; +@@ -466,7 +552,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, chg->pmic->adc_start); ++ ret = regmap_write(chg->adc_regmap, chg->adc_base, chg->pmic->adc_start); + if (ret) { + WRITE_ONCE(chg->adc_waiting, false); + return ret; +@@ -477,18 +563,18 @@ 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 + chg->pmic->adc_result, ++ ret = regmap_bulk_read(chg->adc_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, ++ ret = regmap_update_bits(chg->adc_regmap, chg->adc_base, + TRISTAR_CHG_ADC_START, 0); + if (!ret) +- ret = regmap_update_bits(chg->regmap, chg->adc_base + 1, ++ ret = regmap_update_bits(chg->adc_regmap, chg->adc_base + 1, + TRISTAR_CHG_ADC_LATCH, 0); + } + if (ret) + return ret; +- if (value[0] & 0x80) ++ if (value[0] & chg->chip->adc_error_mask) + return -EIO; + raw = (value[0] & 0x0f) | ((u32)value[1] << 4); + *mv = (((u64)raw * 5000 * 16 + 40 * 65536) / 1000) * 1000 / 65536; +@@ -765,9 +851,9 @@ static unsigned int tristar_target_code(struct tristar_charger *chg) + { + unsigned int ma = max(chg->source_ma, tristar_usb_ma(chg)); + +- if (ma <= tristar_code_ma(TRISTAR_CHG_FALLBACK_CODE)) +- return TRISTAR_CHG_FALLBACK_CODE; +- return tristar_ma_code(min(ma, chg->max_ma)); ++ if (ma <= tristar_code_ma(chg, chg->chip->fallback_code)) ++ return chg->chip->fallback_code; ++ return tristar_ma_code(chg, min(ma, chg->max_ma)); + } + + /* Follow a changed allowance once the source is identified. Caller holds lock. */ +@@ -809,9 +895,8 @@ static void tristar_new_attachment(struct tristar_charger *chg, u64 now) + chg->cable_known = false; + chg->epoch_seen = READ_ONCE(chg->epoch); + WRITE_ONCE(chg->line_ns, 0); +- /* iOS draws nothing above the attach default before the grant ramps. */ +- if (tristar_set_code(chg, TRISTAR_CHG_HANDOFF_CODE)) +- dev_crit(chg->dev, "Handoff write failed; input limit unverified\n"); ++ if (tristar_set_code(chg, chg->chip->attach_code)) ++ dev_crit(chg->dev, "Attach write failed; input limit unverified\n"); + dev_dbg(chg->dev, "power connected, identifying source\n"); + } + +@@ -820,7 +905,7 @@ static void tristar_mux_fault(struct tristar_charger *chg) + { + chg->phase = TRISTAR_FAULT; + strscpy(chg->source, "Tristar mux restore failed", sizeof(chg->source)); +- tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); ++ tristar_withdraw(chg, chg->chip->fallback_code); + dev_err(chg->dev, "Tristar mux restore unverified; holding the fallback until reboot\n"); + } + +@@ -833,7 +918,7 @@ static void tristar_grant(struct tristar_charger *chg) + chg->phase = chg->code < chg->target_code ? TRISTAR_RAMPING : TRISTAR_CHARGING; + chg->step_ns = 0; + dev_dbg(chg->dev, "%s: up to %u mA\n", chg->source, +- tristar_code_ma(chg->target_code)); ++ tristar_code_ma(chg, chg->target_code)); + } + + /* +@@ -853,7 +938,8 @@ static void tristar_accept(struct tristar_charger *chg, const struct tristar_ide + chg->cable_known = id->sampled; + chg->usbc = id->usbc; + chg->orientation = id->orientation; +- tristar_set_usb(chg, id->type != POWER_SUPPLY_USB_TYPE_DCP); ++ tristar_set_usb(chg, chg->chip != &tristar_d2365_chip || ++ id->type != POWER_SUPPLY_USB_TYPE_DCP); + tristar_grant(chg); + } + +@@ -942,33 +1028,37 @@ static bool tristar_debouncing(struct tristar_charger *chg, u64 now) + static void tristar_ramp_step(struct tristar_charger *chg, u64 now) + { + struct tristar_pack pack; +- unsigned int next, from_ma = tristar_code_ma(chg->code); ++ unsigned int next, from_ma = tristar_code_ma(chg, chg->code); + u64 wait; + + if (tristar_debouncing(chg, now) || + (chg->step_ns && now - chg->step_ns < chg->step_wait_ns)) + return; +- /* A read that fails says nothing about the battery: hold, and look again. */ +- if (tristar_read_pack(&pack)) ++ if (tristar_read_pack(&pack)) { ++ if (chg->chip->require_pack_telemetry) ++ tristar_withdraw(chg, chg->chip->fallback_code); + return; +- if (!tristar_pack_allows_grant(&pack)) { ++ } ++ if (!tristar_pack_allows_grant(chg, &pack)) { + chg->phase = TRISTAR_CHARGING; +- tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); ++ tristar_withdraw(chg, chg->chip->fallback_code); + dev_warn(chg->dev, "battery outside the charging window; holding the fallback\n"); + return; + } +- if (!chg->step_ns && chg->code <= TRISTAR_CHG_HANDOFF_CODE) { ++ if (chg->chip->ramp_step_ms) { ++ next = min(chg->target_code, tristar_ma_code(chg, from_ma + TRISTAR_RAMP_STEP_MA)); ++ wait = chg->chip->ramp_step_ms * NSEC_PER_MSEC; ++ } else if (!chg->step_ns && chg->code <= chg->chip->handoff_code) { + /* From nothing, iOS writes 100 mA and holds it. */ +- next = TRISTAR_CHG_HANDOFF_CODE; ++ next = chg->chip->handoff_code; + wait = TRISTAR_RAMP_HOLD_MS * NSEC_PER_MSEC; + } else { +- next = min(chg->target_code, +- tristar_ma_code(tristar_code_ma(chg->code) + TRISTAR_RAMP_STEP_MA)); +- wait = (u64)(tristar_code_ma(next) - from_ma) * (NSEC_PER_MSEC / 10); ++ next = min(chg->target_code, tristar_ma_code(chg, from_ma + TRISTAR_RAMP_STEP_MA)); ++ wait = (u64)(tristar_code_ma(chg, next) - from_ma) * (NSEC_PER_MSEC / 10); + } + if (tristar_set_code(chg, next)) { + chg->phase = TRISTAR_FAULT; +- tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); ++ tristar_withdraw(chg, chg->chip->fallback_code); + dev_err(chg->dev, "input-limit write failed; holding the fallback\n"); + return; + } +@@ -1006,23 +1096,32 @@ static unsigned long tristar_ramp_delay(struct tristar_charger *chg, u64 now) + */ + static void tristar_check_limit(struct tristar_charger *chg) + { +- u32 reg = chg->limit_reg; + unsigned int hw, code = chg->code; + +- if (regmap_read(chg->regmap, reg, &hw) || hw == code) ++ int ret = chg->chip->read_limit(chg, &hw); ++ ++ if (ret) { ++ if (chg->chip->strict_limit_errors) { ++ tristar_set_code(chg, chg->chip->fallback_code); ++ chg->phase = TRISTAR_FAULT; ++ dev_err_ratelimited(chg->dev, "input limit unverified (%d); holding fallback\n", ret); ++ } ++ return; ++ } ++ if (hw == code) + return; + dev_warn_ratelimited(chg->dev, "input limit changed to %u mA by the PMIC; restoring\n", +- tristar_code_ma(hw)); ++ tristar_code_ma(chg, hw)); + if (hw > code) { + if (tristar_set_code(chg, code)) + dev_crit(chg->dev, "Input-limit write failed; limit unverified\n"); + return; + } +- if (tristar_set_code(chg, min_t(unsigned int, code, TRISTAR_CHG_FALLBACK_CODE))) { ++ if (tristar_set_code(chg, min_t(unsigned int, code, chg->chip->fallback_code))) { + dev_crit(chg->dev, "Fallback write failed; input limit unverified\n"); + return; + } +- if (code > TRISTAR_CHG_FALLBACK_CODE) { ++ if (code > chg->chip->fallback_code) { + chg->phase = TRISTAR_RAMPING; + chg->step_ns = 0; + } +@@ -1038,12 +1137,15 @@ static void tristar_guard(struct tristar_charger *chg, u64 now) + tristar_check_limit(chg); + if (chg->phase != TRISTAR_CHARGING) + return; +- if (tristar_read_pack(&pack)) ++ if (tristar_read_pack(&pack)) { ++ if (chg->chip->require_pack_telemetry) ++ tristar_withdraw(chg, chg->chip->fallback_code); + return; +- if (chg->code > TRISTAR_CHG_FALLBACK_CODE && !tristar_pack_allows_grant(&pack)) { +- tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); ++ } ++ if (chg->code > chg->chip->fallback_code && !tristar_pack_allows_grant(chg, &pack)) { ++ tristar_withdraw(chg, chg->chip->fallback_code); + dev_warn(chg->dev, "battery outside the charging window; holding the fallback\n"); +- } else if (chg->code < chg->target_code && tristar_pack_allows_grant(&pack)) { ++ } else if (chg->code < chg->target_code && tristar_pack_allows_grant(chg, &pack)) { + /* Back inside the window: no replug needed to charge again. */ + chg->phase = TRISTAR_RAMPING; + chg->step_ns = 0; +@@ -1119,7 +1221,7 @@ static bool tristar_input_present(struct tristar_charger *chg) + { + unsigned int connected; + +- if (regmap_read(chg->regmap, chg->connected_reg, &connected)) { ++ if (regmap_read(chg->regmap, chg->status_base + chg->pmic->connected, &connected)) { + dev_err_ratelimited(chg->dev, "PMIC connection state unreadable\n"); + return chg->online; + } +@@ -1144,12 +1246,12 @@ 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_reg, &status)) { +- tristar_withdraw(chg, TRISTAR_CHG_FALLBACK_CODE); ++ if (chg->chip->read_status(chg, &status)) { ++ tristar_withdraw(chg, chg->chip->fallback_code); + dev_err_ratelimited(chg->dev, "PMIC status unreadable; holding the fallback\n"); + goto again; + } +- chg->online = tristar_input_present(chg); ++ chg->online = chg->chip->online_status ? status != 0 : tristar_input_present(chg); + if (!chg->online) { + /* The hold of the next attachment starts when input returns. */ + chg->hold_ns = now; +@@ -1161,13 +1263,19 @@ static void tristar_poll(struct work_struct *work) + chg->source_ma = 0; + chg->usb_ma = 0; + chg->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; +- if (tristar_set_code(chg, TRISTAR_CHG_HANDOFF_CODE)) ++ if (tristar_set_code(chg, chg->chip->handoff_code)) + dev_crit(chg->dev, "Handoff write failed; input limit unverified\n"); + dev_dbg(chg->dev, "disconnected\n"); + } + tristar_no_source(chg, status, now); + goto again; + } ++ if (chg->chip->online_status && status != chg->chip->online_status) { ++ /* Transitional input state: no grant. */ ++ tristar_withdraw(chg, chg->chip->fallback_code); ++ tristar_no_source(chg, status, now); ++ goto again; ++ } + if (!chg->present) { + tristar_new_attachment(chg, now); + goto again; +@@ -1194,7 +1302,7 @@ static void tristar_poll(struct work_struct *work) + /* The status was read again after the debounce: the input stayed. */ + cmpxchg(&chg->line_ns, line_ns, 0); + dev_dbg(chg->dev, "source event debounced, %u mA kept\n", +- tristar_code_ma(chg->code)); ++ tristar_code_ma(chg, chg->code)); + } + tristar_follow_accessory(chg, now); + switch (chg->phase) { +@@ -1234,15 +1342,14 @@ static void tristar_poll(struct work_struct *work) + */ + static bool tristar_event_withdraw(struct tristar_charger *chg) + { +- u32 reg = chg->limit_reg; + unsigned int readback; + +- if (READ_ONCE(chg->code) <= TRISTAR_CHG_FALLBACK_CODE) ++ if (READ_ONCE(chg->code) <= chg->chip->fallback_code) + return false; +- if (!regmap_write(chg->regmap, reg, TRISTAR_CHG_FALLBACK_CODE) && +- !regmap_read(chg->regmap, reg, &readback) && +- readback == TRISTAR_CHG_FALLBACK_CODE) +- WRITE_ONCE(chg->code, TRISTAR_CHG_FALLBACK_CODE); ++ if (!chg->chip->write_limit(chg, chg->chip->fallback_code) && ++ !chg->chip->read_limit(chg, &readback) && ++ readback == chg->chip->fallback_code) ++ WRITE_ONCE(chg->code, chg->chip->fallback_code); + else + dev_crit(chg->dev, "PMU event: withdrawal write failed\n"); + return true; +@@ -1254,6 +1361,16 @@ static bool tristar_event_withdraw(struct tristar_charger *chg) + */ + static irqreturn_t tristar_line_irq(int irq, void *data) + { ++ struct tristar_charger *chg = data; ++ ++ if (!chg->chip->invalidate_on_line) ++ return IRQ_HANDLED; ++ ++ /* J120 ADC and source events arrive through different controllers. */ ++ WRITE_ONCE(chg->epoch, READ_ONCE(chg->epoch) + 1); ++ smp_mb(); /* Publish invalidation before checking the grant. */ ++ if (tristar_event_withdraw(chg)) ++ WRITE_ONCE(chg->line_ns, ktime_get_ns() ?: 1); + return IRQ_HANDLED; + } + +@@ -1284,11 +1401,10 @@ static bool tristar_event_debounce(struct tristar_charger *chg) + */ + static void tristar_source_event(struct tristar_charger *chg) + { +- u32 reg = chg->limit_reg; + unsigned int i; + u64 now; + +- if (tristar_event_debounce(chg)) { ++ if (!chg->chip->invalidate_on_line && tristar_event_debounce(chg)) { + now = ktime_get_ns(); + goto count; + } +@@ -1307,8 +1423,8 @@ static void tristar_source_event(struct tristar_charger *chg) + } + if (++chg->storm_count > TRISTAR_IRQ_STORM) { + dev_crit(chg->dev, "PMU source events storming; holding the fallback\n"); +- regmap_write(chg->regmap, reg, TRISTAR_CHG_FALLBACK_CODE); +- WRITE_ONCE(chg->code, TRISTAR_CHG_FALLBACK_CODE); ++ chg->chip->write_limit(chg, chg->chip->fallback_code); ++ WRITE_ONCE(chg->code, chg->chip->fallback_code); + WRITE_ONCE(chg->phase, TRISTAR_FAULT); + for (i = TRISTAR_IRQ_SOURCE; i < chg->nirqs; i++) + disable_irq_nosync(chg->irqs[i]); +@@ -1365,7 +1481,7 @@ static int tristar_get_property(struct power_supply *psy, + val->intval = POWER_SUPPLY_USB_TYPE_SDP; + break; + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: +- val->intval = tristar_code_ma(chg->code) * 1000; ++ val->intval = tristar_code_ma(chg, chg->code) * 1000; + break; + case POWER_SUPPLY_PROP_CURRENT_MAX: + /* What the identified source or USB host allows; 0 when unknown. */ +@@ -1489,6 +1605,8 @@ static void tristar_put_role_switch(void *data) + usb_role_switch_put(data); + } + ++#include "apple_tristar_d2355.h" ++ + /* Leave the limit as iBoot did, so a reboot or a kexec'd kernel starts safe. */ + static void tristar_stop(struct tristar_charger *chg, const char *reason) + { +@@ -1502,7 +1620,7 @@ static void tristar_stop(struct tristar_charger *chg, const char *reason) + cancel_delayed_work_sync(&chg->poll_work); + tristar_accessory_stop(chg->acc); + mutex_lock(&chg->lock); +- if (tristar_set_code(chg, TRISTAR_CHG_HANDOFF_CODE)) ++ if (tristar_set_code(chg, chg->chip->handoff_code)) + dev_crit(chg->dev, "%s: handoff restore failed\n", reason); + /* Without this driver nothing holds USB data off. */ + tristar_set_usb(chg, true); +@@ -1514,6 +1632,24 @@ static void tristar_stop_action(void *data) + tristar_stop(data, "remove"); + } + ++/* IRQ resources unwind first; stop work before the power supply is freed. */ ++static void tristar_abort_probe(void *data) ++{ ++ struct tristar_charger *chg = data; ++ ++ if (chg->probe_ready) ++ return; ++ mutex_lock(&chg->lock); ++ chg->stopping = true; ++ mutex_unlock(&chg->lock); ++ cancel_delayed_work_sync(&chg->poll_work); ++ mutex_lock(&chg->lock); ++ if (tristar_set_code(chg, chg->chip->handoff_code)) ++ dev_crit(chg->dev, "probe failure: input handoff failed\n"); ++ tristar_set_usb(chg, true); ++ mutex_unlock(&chg->lock); ++} ++ + static int tristar_probe(struct platform_device *pdev) + { + struct device *dev = &pdev->dev; +@@ -1521,31 +1657,33 @@ static int tristar_probe(struct platform_device *pdev) + struct tristar_charger *chg; + struct device_node *np; + unsigned int code, i; +- u32 max_ua, base; ++ u32 max_ua; + int ret; + + chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); + if (!chg) + return -ENOMEM; + chg->dev = dev; ++ chg->pmic = device_get_match_data(dev); ++ if (!chg->pmic) ++ return -ENODEV; ++ chg->chip = chg->pmic->chip; + chg->regmap = dev_get_regmap(dev->parent, NULL); + if (!chg->regmap) + return dev_err_probe(dev, -ENODEV, "parent regmap unavailable\n"); + +- chg->pmic = device_get_match_data(dev); +- if (!chg->pmic) +- return -ENODEV; ++ chg->adc_regmap = chg->regmap; + 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); ++ max_t(unsigned int, chg->chip->status_size, ++ max(chg->pmic->connected, chg->pmic->status) + 1), ++ &chg->status_base); ++ if (!ret) ++ ret = tristar_get_bank(dev, "control", ++ max_t(unsigned int, chg->chip->control_size, ++ chg->pmic->input_limit + 1), ++ &chg->control_base); ++ if (!ret) ++ ret = tristar_get_bank(dev, "adc", chg->pmic->adc_result + 2, &chg->adc_base); + if (ret) + return ret; + +@@ -1553,6 +1691,11 @@ static int tristar_probe(struct platform_device *pdev) + if (ret) + return dev_err_probe(dev, ret, "missing board input-current maximum\n"); + chg->max_ma = max_ua / 1000; ++ if (chg->chip->prepare) { ++ ret = chg->chip->prepare(chg); ++ if (ret) ++ return dev_err_probe(dev, ret, "PMIC preparation failed\n"); ++ } + + np = of_parse_phandle(dev->of_node, "apple,tristar", 0); + if (!np) +@@ -1607,17 +1750,10 @@ 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->limit_reg, &code); ++ ret = chg->chip->read_limit(chg, &code); + if (ret) + return dev_err_probe(dev, ret, "failed to read the input-current limit\n"); + chg->code = code; +- if (code > TRISTAR_CHG_FALLBACK_CODE) { +- dev_warn(dev, "Input limit %u mA at probe; dropping to %u mA\n", +- tristar_code_ma(code), tristar_code_ma(TRISTAR_CHG_FALLBACK_CODE)); +- ret = tristar_set_code(chg, TRISTAR_CHG_FALLBACK_CODE); +- if (ret) +- return dev_err_probe(dev, ret, "failed to lower the input-current limit\n"); +- } + + config.drv_data = chg; + config.fwnode = dev_fwnode(dev); +@@ -1625,6 +1761,19 @@ static int tristar_probe(struct platform_device *pdev) + if (IS_ERR(chg->psy)) + return dev_err_probe(dev, PTR_ERR(chg->psy), "failed to register power supply\n"); + ++ /* Register before changing limits or requesting IRQs. */ ++ ret = devm_add_action_or_reset(dev, tristar_abort_probe, chg); ++ if (ret) ++ return ret; ++ if (code > chg->chip->fallback_code) { ++ dev_warn(dev, "Input limit %u mA at probe; dropping to %u mA\n", ++ tristar_code_ma(chg, code), tristar_code_ma(chg, chg->chip->fallback_code)); ++ ret = tristar_set_code(chg, chg->chip->fallback_code); ++ if (ret) ++ return dev_err_probe(dev, ret, "failed to lower the input-current limit\n"); ++ } ++ ++ + for (i = 0; i < chg->nirqs; i++) { + ret = devm_request_threaded_irq(dev, chg->irqs[i], NULL, + i == TRISTAR_IRQ_LINE ? tristar_line_irq : +@@ -1639,6 +1788,7 @@ static int tristar_probe(struct platform_device *pdev) + ret = devm_add_action_or_reset(dev, tristar_stop_action, chg); + if (ret) + return ret; ++ chg->probe_ready = true; + + if (chg->plug_irq) { + ret = device_init_wakeup(dev, true); +@@ -1730,7 +1880,7 @@ static int tristar_suspend(struct device *dev) + if (!keep) { + chg->present = false; + chg->phase = TRISTAR_EMPTY; +- ret = tristar_set_code(chg, TRISTAR_CHG_HANDOFF_CODE); ++ ret = tristar_set_code(chg, chg->chip->handoff_code); + if (ret) + chg->stopping = false; + } +@@ -1771,6 +1921,7 @@ static const struct dev_pm_ops tristar_pm_ops = { + static const struct of_device_id tristar_of_match[] = { + { .compatible = "apple,d2207-tristar-charger", .data = &tristar_d2207 }, + { .compatible = "apple,tristar-charger", .data = &tristar_d2365 }, ++ { .compatible = "apple,d2355-tristar-charger", .data = &tristar_d2355 }, + { } + }; + MODULE_DEVICE_TABLE(of, tristar_of_match); +diff --git a/drivers/power/supply/apple_tristar_d2355.h b/drivers/power/supply/apple_tristar_d2355.h +new file mode 100644 +index 000000000..a52b54268 +--- /dev/null ++++ b/drivers/power/supply/apple_tristar_d2355.h +@@ -0,0 +1,278 @@ ++/* SPDX-License-Identifier: GPL-2.0-only */ ++/* D2355 hardware operations for the shared Tristar charging policy. */ ++#include "apple_d2355_current.h" ++ ++struct tristar_d2355 { ++ struct d2355_calibration calibration; ++ struct mutex io_lock; ++ s32 pack_limits[6]; ++ unsigned int requested; ++ u8 raw, control; ++ bool verified, fault; ++}; ++ ++static int tristar_d2355_disable(struct tristar_charger *chg) ++{ ++ unsigned int control, check; ++ int ret; ++ ++ ret = regmap_read(chg->regmap, chg->control_base, &control); ++ if (!ret) ++ ret = regmap_write(chg->regmap, chg->control_base, control | BIT(2)); ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base, &check); ++ if (!ret && check != (control | BIT(2))) ++ ret = -EIO; ++ return ret; ++} ++ ++static int tristar_d2355_read_limit(struct tristar_charger *chg, unsigned int *code) ++{ ++ struct tristar_d2355 *hw = chg->chip_data; ++ unsigned int before, raw, after, result; ++ int ret; ++ ++ mutex_lock(&hw->io_lock); ++ ret = regmap_read(chg->regmap, chg->control_base, &before); ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base + 0xb, &raw); ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base, &after); ++ if (ret) ++ goto out; ++ if (before != after) { ++ ret = -ESTALE; ++ goto out; ++ } ++ if (after & BIT(2)) { ++ result = 0; ++ } else if (after & BIT(1)) { ++ ret = -EOPNOTSUPP; /* Only verified low-voltage range zero. */ ++ goto out; ++ } else if (hw->verified) { ++ if (raw != hw->raw || after != hw->control) { ++ ret = -ESTALE; ++ goto out; ++ } ++ result = hw->requested; ++ } else { ++ /* Initial handoff setting only; never adopt a higher grant. */ ++ result = max(raw, 8U); ++ } ++ *code = result; ++out: ++ mutex_unlock(&hw->io_lock); ++ return ret; ++} ++ ++static unsigned int tristar_d2355_code_ma(struct tristar_charger *chg, ++ unsigned int code) ++{ ++ return code * 10; ++} ++ ++static unsigned int tristar_d2355_ma_code(struct tristar_charger *chg, ++ unsigned int ma) ++{ ++ return ma < 80 ? 0 : min(ma / 10, 254U); ++} ++ ++static int tristar_d2355_write_limit(struct tristar_charger *chg, unsigned int code) ++{ ++ struct tristar_d2355 *hw = chg->chip_data; ++ unsigned int control, check, epoch = READ_ONCE(chg->epoch); ++ unsigned int allowance; ++ u8 raw = 8; ++ bool disabled; ++ int ret, recovery; ++ ++ if (code > 254) ++ return -ERANGE; ++ mutex_lock(&hw->io_lock); ++ if (hw->fault && code) { ++ ret = -EIO; ++ goto out; ++ } ++ if (code > chg->chip->fallback_code) { ++ allowance = max(chg->source_ma, tristar_usb_ma(chg)); ++ if (!chg->present || epoch != chg->epoch_seen || ++ code * 10 > min(allowance, chg->max_ma)) { ++ ret = -ESTALE; ++ goto out; ++ } ++ } ++ ret = regmap_read(chg->regmap, chg->control_base, &control); ++ if (ret) ++ goto out; ++ if (code && (control & BIT(1))) { ++ ret = -EOPNOTSUPP; ++ goto out; ++ } ++ if (code) { ++ ret = d2355_current_encode(&hw->calibration, 0, code * 10, ++ &raw, &disabled); ++ if (ret) ++ goto out; ++ if (disabled) { ++ ret = -ERANGE; ++ goto out; ++ } ++ } ++ hw->verified = false; ++ ret = tristar_d2355_disable(chg); ++ if (ret) { ++ hw->fault = true; ++ goto out; ++ } ++ if (!code) ++ goto verified; ++ ret = regmap_write(chg->regmap, chg->control_base + 0xb, raw); ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base + 0xb, &check); ++ if (!ret && check != raw) ++ ret = -EIO; ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base, &check); ++ if (!ret && check != (control | BIT(2))) ++ ret = -ESTALE; ++ if (!ret && code > chg->chip->fallback_code && ++ epoch != READ_ONCE(chg->epoch)) ++ ret = -ESTALE; ++ if (!ret) ++ ret = regmap_write(chg->regmap, chg->control_base, control & ~BIT(2)); ++ if (!ret) ++ ret = regmap_read(chg->regmap, chg->control_base, &check); ++ if (!ret && check != (control & ~BIT(2))) ++ ret = -EIO; ++ /* Publish before the final epoch check: an IRQ must see the grant and ++ * wait for io_lock, or invalidate this check and force recovery below. ++ */ ++ if (!ret) { ++ WRITE_ONCE(chg->code, code); ++ smp_mb(); /* Pairs with invalidation before IRQ withdrawal. */ ++ } ++ if (!ret && code > chg->chip->fallback_code && ++ epoch != READ_ONCE(chg->epoch)) ++ ret = -ESTALE; ++ if (ret) { ++ recovery = tristar_d2355_disable(chg); ++ if (recovery) ++ hw->fault = true; ++ else ++ WRITE_ONCE(chg->code, 0); ++ goto out; ++ } ++verified: ++ hw->requested = code; ++ hw->raw = raw; ++ hw->control = code ? control & ~BIT(2) : control | BIT(2); ++ hw->verified = true; ++ WRITE_ONCE(chg->code, code); ++out: ++ mutex_unlock(&hw->io_lock); ++ return ret; ++} ++ ++static int tristar_d2355_read_status(struct tristar_charger *chg, unsigned int *status) ++{ ++ u8 bytes[10]; ++ int ret = regmap_bulk_read(chg->regmap, chg->status_base, bytes, sizeof(bytes)); ++ ++ /* ++ * Attachment starts source identification. Register 0x86 bit 5 is ++ * charger feedback and can be clear while the input limit is set. ++ */ ++ if (!ret) ++ *status = bytes[1] & BIT(7) ? TRISTAR_CHG_STATUS_ONLINE : 0; ++ return ret; ++} ++ ++static bool tristar_d2355_pack_allows(struct tristar_charger *chg, ++ const struct tristar_pack *pack) ++{ ++ struct tristar_d2355 *hw = chg->chip_data; ++ ++ return pack->temp >= hw->pack_limits[0] && pack->temp <= hw->pack_limits[1] && ++ pack->voltage_uv >= hw->pack_limits[2] && pack->voltage_uv <= hw->pack_limits[3] && ++ pack->current_ua >= hw->pack_limits[4] && pack->current_ua <= hw->pack_limits[5]; ++} ++ ++static int tristar_d2355_prepare(struct tristar_charger *chg) ++{ ++ struct device *dev = chg->dev; ++ struct tristar_d2355 *hw; ++ struct device_node *np; ++ struct i2c_client *adc; ++ const struct firmware *firmware; ++ const char *name; ++ u32 limits[6]; ++ unsigned int i; ++ int ret; ++ ++ if (chg->max_ma > 2540 || chg->max_ma < 80) ++ return -EINVAL; ++ hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL); ++ if (!hw) ++ return -ENOMEM; ++ ret = devm_mutex_init(dev, &hw->io_lock); ++ if (ret) ++ return ret; ++ ret = device_property_read_u32_array(dev, "apple,pack-limits", limits, 6); ++ if (ret) ++ return ret; ++ for (i = 0; i < 6; i++) ++ hw->pack_limits[i] = (s32)limits[i]; ++ for (i = 0; i < 6; i += 2) ++ if (hw->pack_limits[i] > hw->pack_limits[i + 1]) ++ return -EINVAL; ++ if (hw->pack_limits[2] <= 0) ++ return -EINVAL; ++ ret = device_property_read_string(dev, "firmware-name", &name); ++ if (ret) ++ return ret; ++ ret = request_firmware(&firmware, name, dev); ++ if (ret) ++ return ret; ++ ret = d2355_calibration_parse_hv(firmware->data, firmware->size, &hw->calibration); ++ release_firmware(firmware); ++ if (ret) ++ return ret; ++ np = of_parse_phandle(dev->of_node, "apple,adc-pmic", 0); ++ if (!np) ++ return -EINVAL; ++ adc = of_find_i2c_device_by_node(np); ++ of_node_put(np); ++ if (!adc) ++ return -EPROBE_DEFER; ++ ret = devm_add_action_or_reset(dev, tristar_put_client, adc); ++ if (ret) ++ return ret; ++ chg->adc_regmap = dev_get_regmap(&adc->dev, NULL); ++ if (!chg->adc_regmap) ++ return -EPROBE_DEFER; ++ if (!device_link_add(dev, &adc->dev, DL_FLAG_AUTOREMOVE_CONSUMER)) ++ return -ENOMEM; ++ chg->chip_data = hw; ++ return 0; ++} ++ ++static const struct tristar_chip_info tristar_d2355_chip = { ++ .prepare = tristar_d2355_prepare, ++ .pack_allows = tristar_d2355_pack_allows, ++ .status_size = 10, ++ .control_size = 12, ++ .adc_error_mask = 0xc0, ++ .strict_limit_errors = true, ++ .require_pack_telemetry = true, ++ .invalidate_on_line = true, ++ .read_limit = tristar_d2355_read_limit, ++ .write_limit = tristar_d2355_write_limit, ++ .code_ma = tristar_d2355_code_ma, ++ .ma_code = tristar_d2355_ma_code, ++ .read_status = tristar_d2355_read_status, ++ .handoff_code = 0, ++ .attach_code = 8, ++ .online_status = 0x42, ++ .ramp_step_ms = 500, ++ .fallback_code = 8, /* Preserve measured J120 80 mA baseline until identified. */ ++}; diff --git a/kernel/patches/drivers/power/0046-power-supply-restore-the-cached-J120-HDQ-gauge-profi.patch b/kernel/patches/drivers/power/0046-power-supply-restore-the-cached-J120-HDQ-gauge-profi.patch new file mode 100644 index 00000000..b544636e --- /dev/null +++ b/kernel/patches/drivers/power/0046-power-supply-restore-the-cached-J120-HDQ-gauge-profi.patch @@ -0,0 +1,234 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:26:06 +0100 +Subject: [PATCH] power: supply: restore the cached J120 HDQ gauge profile + +Assisted-by: LLM +--- + .../power/supply/apple,j120-bq27540.yaml | 38 +++++++++++++++++++ + .../bindings/w1/apple,j120-hdq-uart.yaml | 29 ++++++++++++++ + drivers/power/supply/bq27xxx_battery.c | 19 +++++++++- + drivers/power/supply/bq27xxx_battery_hdq.c | 29 +++++++++++++- + include/linux/power/bq27xxx_battery.h | 4 ++ + 5 files changed, 115 insertions(+), 4 deletions(-) + create mode 100644 Documentation/devicetree/bindings/power/supply/apple,j120-bq27540.yaml + create mode 100644 Documentation/devicetree/bindings/w1/apple,j120-hdq-uart.yaml + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,j120-bq27540.yaml b/Documentation/devicetree/bindings/power/supply/apple,j120-bq27540.yaml +new file mode 100644 +index 000000000..c311167ea +--- /dev/null ++++ b/Documentation/devicetree/bindings/power/supply/apple,j120-bq27540.yaml +@@ -0,0 +1,38 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/power/supply/apple,j120-bq27540.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple J120 BQ27540 HDQ fuel gauge ++ ++maintainers: ++ - tompta1 <546706+tompta1@users.noreply.github.com> ++ ++description: | ++ The J120 battery gauge uses HDQ and the BQ27541 register layout. Its ++ telemetry profile uses RemainingCapacity rather than NominalAvailableCapacity. ++ It is a child of an HDQ bus, not an I2C device. ++ ++properties: ++ compatible: ++ items: ++ - const: apple,j120-bq27540 ++ - const: ti,bq27540-hdq ++ ++ monitored-battery: ++ $ref: /schemas/types.yaml#/definitions/phandle ++ description: Battery characteristics, if independently known. ++ ++required: ++ - compatible ++ ++additionalProperties: false ++ ++examples: ++ - | ++ hdq { ++ fuel-gauge { ++ compatible = "apple,j120-bq27540", "ti,bq27540-hdq"; ++ }; ++ }; +diff --git a/Documentation/devicetree/bindings/w1/apple,j120-hdq-uart.yaml b/Documentation/devicetree/bindings/w1/apple,j120-hdq-uart.yaml +new file mode 100644 +index 000000000..1fcd15052 +--- /dev/null ++++ b/Documentation/devicetree/bindings/w1/apple,j120-hdq-uart.yaml +@@ -0,0 +1,29 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/w1/apple,j120-hdq-uart.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple J120 UART HDQ battery bus ++ ++maintainers: ++ - tompta1 <546706+tompta1@users.noreply.github.com> ++ ++description: | ++ The J120 battery gauge uses an HDQ bus driven by UART symbols. The ++ board-specific compatible selects bounded, read-only telemetry transactions. ++ ++properties: ++ compatible: ++ items: ++ - const: apple,j120-hdq-uart ++ - const: ti,hdq-uart ++ ++ fuel-gauge: ++ $ref: /schemas/power/supply/apple,j120-bq27540.yaml# ++ ++required: ++ - compatible ++ - fuel-gauge ++ ++additionalProperties: false +diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c +index 14fb964aa..73cb465af 100644 +--- a/drivers/power/supply/bq27xxx_battery.c ++++ b/drivers/power/supply/bq27xxx_battery.c +@@ -1192,7 +1192,14 @@ static inline int bq27xxx_read(struct bq27xxx_device_info *di, int reg_index, + if (!di || di->regs[reg_index] == INVALID_REG_ADDR) + return -EINVAL; + ++ if (di->cache_read_active && ++ time_after_eq(jiffies, di->cache_read_deadline)) ++ return -ETIMEDOUT; ++ + ret = di->bus.read(di, di->regs[reg_index], single); ++ if (ret >= 0 && di->cache_read_active && ++ time_after_eq(jiffies, di->cache_read_deadline)) ++ ret = -ETIMEDOUT; + if (ret < 0) + dev_dbg(di->dev, "failed to read register 0x%02x (index %d)\n", + di->regs[reg_index], reg_index); +@@ -2118,6 +2125,11 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + mutex_lock(&di->lock); + if (di->removed) + goto out_unlock; ++ if (di->cache_read_budget_ms) { ++ di->cache_read_deadline = jiffies + ++ msecs_to_jiffies(di->cache_read_budget_ms); ++ di->cache_read_active = true; ++ } + + cache = di->cache; + +@@ -2202,6 +2214,7 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + power_supply_changed(di->bat); + + out_unlock: ++ di->cache_read_active = false; + if (!di->removed && di->cache_refresh_ms) + queue_delayed_work(system_freezable_wq, &di->work, + msecs_to_jiffies(di->cache_refresh_ms)); +@@ -2591,9 +2604,11 @@ int bq27xxx_battery_setup(struct bq27xxx_device_info *di) + di->dm_regs = bq27xxx_chip_data[di->chip].dm_regs; + di->opts = bq27xxx_chip_data[di->chip].opts; + +- if (di->cache_only && di->chip != BQ27545) ++ if (di->cache_only && di->chip != BQ27545 && ++ (di->chip != BQ27541 || !di->cache_properties || ++ !di->num_cache_properties)) + return dev_err_probe(di->dev, -EINVAL, +- "cache-only mode only supports BQ27545\n"); ++ "unsupported or missing battery cache profile\n"); + if (di->cache_only && !di->cache_properties) { + di->cache_properties = bq27545_cache_props; + di->num_cache_properties = ARRAY_SIZE(bq27545_cache_props); +diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c +index 2bacf7d59..bbfea79a2 100644 +--- a/drivers/power/supply/bq27xxx_battery_hdq.c ++++ b/drivers/power/supply/bq27xxx_battery_hdq.c +@@ -42,11 +42,24 @@ static const enum power_supply_property bq27545_iphone7_plus_cache_props[] = { + POWER_SUPPLY_PROP_MANUFACTURER, + }; + ++/* J120 exposes RemainingCapacity; do not query NominalAvailableCapacity. */ ++static const enum power_supply_property bq27540_j120_cache_props[] = { ++ POWER_SUPPLY_PROP_STATUS, ++ POWER_SUPPLY_PROP_PRESENT, ++ POWER_SUPPLY_PROP_VOLTAGE_NOW, ++ POWER_SUPPLY_PROP_CURRENT_NOW, ++ POWER_SUPPLY_PROP_CAPACITY, ++ POWER_SUPPLY_PROP_TEMP, ++ POWER_SUPPLY_PROP_CHARGE_NOW, ++ POWER_SUPPLY_PROP_CHARGE_FULL, ++}; ++ + struct bq27xxx_hdq_data { + enum bq27xxx_chip chip; + const enum power_supply_property *cache_properties; + size_t num_cache_properties; + bool use_remaining_capacity; ++ unsigned int read_budget_ms; + }; + + static int w1_bq27000_read(struct w1_slave *sl, unsigned int reg) +@@ -109,19 +122,22 @@ static int bq27xxx_battery_hdq_add_slave(struct w1_slave *sl) + + di->dev = &sl->dev; + match = of_match_node(sl->family->of_match_table, sl->dev.of_node); ++ if (sl->master->dev.parent && !match) ++ return -ENODEV; + if (match) { + const struct bq27xxx_hdq_data *data = match->data; + + di->chip = data->chip; + di->name = "battery"; +- /* Only the BQ27545 profile needs cached telemetry. */ +- di->cache_only = di->chip == BQ27545; ++ /* Retain the generic BQ27545 cached profile by default. */ ++ di->cache_only = di->chip == BQ27545 || data->read_budget_ms; + di->cache_refresh_ms = di->cache_only ? 30000 : 0; + if (data->cache_properties) { + di->cache_properties = data->cache_properties; + di->num_cache_properties = data->num_cache_properties; + } + di->cache_use_remaining_capacity = data->use_remaining_capacity; ++ di->cache_read_budget_ms = data->read_budget_ms; + } else { + di->chip = BQ27000; + di->name = "bq27000-battery"; +@@ -176,7 +192,16 @@ static const struct bq27xxx_hdq_data bq27541_data = { + .chip = BQ27541, + }; + ++static const struct bq27xxx_hdq_data bq27540_j120_data = { ++ .chip = BQ27541, ++ .read_budget_ms = 5000, ++ .cache_properties = bq27540_j120_cache_props, ++ .num_cache_properties = ARRAY_SIZE(bq27540_j120_cache_props), ++ .use_remaining_capacity = true, ++}; ++ + static const struct of_device_id bq27xxx_battery_hdq_of_match[] = { ++ { .compatible = "apple,j120-bq27540", .data = &bq27540_j120_data }, + { .compatible = "apple,d11-bq27545", .data = &bq27545_iphone7_plus_data }, + { .compatible = "apple,d111-bq27545", .data = &bq27545_iphone7_plus_data }, + { .compatible = "apple,j72-bq27545", .data = &bq27545_ipad_air_data }, +diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h +index 25c142419..5a930ed1c 100644 +--- a/include/linux/power/bq27xxx_battery.h ++++ b/include/linux/power/bq27xxx_battery.h +@@ -83,6 +83,10 @@ struct bq27xxx_device_info { + bool cache_use_remaining_capacity; + /* Optional periodic refresh interval for cache-only transports. */ + unsigned int cache_refresh_ms; ++ /* Bound admission of new register reads during a cached refresh. */ ++ unsigned int cache_read_budget_ms; ++ unsigned long cache_read_deadline; ++ bool cache_read_active; + int charge_design_full; + int voltage_min_design; + int voltage_max_design; diff --git a/kernel/patches/drivers/power/0047-power-supply-share-the-D2355-online-status-encoding.patch b/kernel/patches/drivers/power/0047-power-supply-share-the-D2355-online-status-encoding.patch new file mode 100644 index 00000000..3aea4667 --- /dev/null +++ b/kernel/patches/drivers/power/0047-power-supply-share-the-D2355-online-status-encoding.patch @@ -0,0 +1,41 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 19:34:23 +0100 +Subject: [PATCH] power: supply: share the D2355 online status encoding + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_d2355.h | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_d2355.h b/drivers/power/supply/apple_tristar_d2355.h +index a52b54268..8963d4fb9 100644 +--- a/drivers/power/supply/apple_tristar_d2355.h ++++ b/drivers/power/supply/apple_tristar_d2355.h +@@ -2,6 +2,8 @@ + /* D2355 hardware operations for the shared Tristar charging policy. */ + #include "apple_d2355_current.h" + ++#define D2355_TRISTAR_STATUS_ONLINE 0x42 ++ + struct tristar_d2355 { + struct d2355_calibration calibration; + struct mutex io_lock; +@@ -183,7 +185,7 @@ static int tristar_d2355_read_status(struct tristar_charger *chg, unsigned int * + * charger feedback and can be clear while the input limit is set. + */ + if (!ret) +- *status = bytes[1] & BIT(7) ? TRISTAR_CHG_STATUS_ONLINE : 0; ++ *status = bytes[1] & BIT(7) ? D2355_TRISTAR_STATUS_ONLINE : 0; + return ret; + } + +@@ -272,7 +274,7 @@ static const struct tristar_chip_info tristar_d2355_chip = { + .read_status = tristar_d2355_read_status, + .handoff_code = 0, + .attach_code = 8, +- .online_status = 0x42, ++ .online_status = D2355_TRISTAR_STATUS_ONLINE, + .ramp_step_ms = 500, + .fallback_code = 8, /* Preserve measured J120 80 mA baseline until identified. */ + }; diff --git a/kernel/patches/drivers/power/0048-power-supply-bq27xxx-expire-stale-J120-pack-measurem.patch b/kernel/patches/drivers/power/0048-power-supply-bq27xxx-expire-stale-J120-pack-measurem.patch new file mode 100644 index 00000000..da3182aa --- /dev/null +++ b/kernel/patches/drivers/power/0048-power-supply-bq27xxx-expire-stale-J120-pack-measurem.patch @@ -0,0 +1,106 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 19:49:04 +0100 +Subject: [PATCH] power: supply: bq27xxx: expire stale J120 pack measurements + +Start the validity window with the first register read and count elapsed suspend time. Return ENODATA for an expired cache so the D2355 charger withdraws its higher input-current grant until the gauge reports a fresh sample. + +Assisted-by: LLM +--- + drivers/power/supply/bq27xxx_battery.c | 18 +++++++++++++++++- + drivers/power/supply/bq27xxx_battery_hdq.c | 2 ++ + include/linux/power/bq27xxx_battery.h | 3 +++ + 3 files changed, 22 insertions(+), 1 deletion(-) + +diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c +index 73cb465af..18dcd87c9 100644 +--- a/drivers/power/supply/bq27xxx_battery.c ++++ b/drivers/power/supply/bq27xxx_battery.c +@@ -53,6 +53,7 @@ + #include + #include + #include ++#include + + #include + +@@ -2108,6 +2109,12 @@ void bq27xxx_battery_update(struct bq27xxx_device_info *di) + } + EXPORT_SYMBOL_GPL(bq27xxx_battery_update); + ++static bool bq27xxx_cache_expired(const struct bq27xxx_device_info *di) ++{ ++ return di->cache_max_age_ms && di->cache.flags >= 0 && ++ !ktime_before(ktime_get_boottime(), di->cache_valid_until); ++} ++ + static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + { + union power_supply_propval current_now; +@@ -2116,6 +2123,7 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + union power_supply_propval value; + union power_supply_propval voltage; + struct bq27xxx_reg_cache cache; ++ ktime_t valid_until = 0; + bool single_flags; + bool changed; + int capacity; +@@ -2125,6 +2133,8 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + mutex_lock(&di->lock); + if (di->removed) + goto out_unlock; ++ if (di->cache_max_age_ms) ++ valid_until = ktime_add_ms(ktime_get_boottime(), di->cache_max_age_ms); + if (di->cache_read_budget_ms) { + di->cache_read_deadline = jiffies + + msecs_to_jiffies(di->cache_read_budget_ms); +@@ -2189,8 +2199,10 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + bq27xxx_cache_value(&cache.power_avg, ret, &value); + } + +- changed = memcmp(&di->cache, &cache, sizeof(cache)) != 0; ++ changed = memcmp(&di->cache, &cache, sizeof(cache)) != 0 || ++ bq27xxx_cache_expired(di); + di->cache = cache; ++ di->cache_valid_until = valid_until; + di->last_status = status; + di->last_update = jiffies; + +@@ -2404,6 +2416,10 @@ static int bq27xxx_battery_get_cached_property(struct power_supply *psy, + int ret; + + mutex_lock(&di->lock); ++ if (bq27xxx_cache_expired(di)) { ++ ret = -ENODATA; ++ goto out_unlock; ++ } + if (psp != POWER_SUPPLY_PROP_PRESENT && di->cache.flags < 0) { + ret = di->cache.flags; + goto out_unlock; +diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c +index bbfea79a2..424ff7081 100644 +--- a/drivers/power/supply/bq27xxx_battery_hdq.c ++++ b/drivers/power/supply/bq27xxx_battery_hdq.c +@@ -138,6 +138,8 @@ static int bq27xxx_battery_hdq_add_slave(struct w1_slave *sl) + } + di->cache_use_remaining_capacity = data->use_remaining_capacity; + di->cache_read_budget_ms = data->read_budget_ms; ++ if (data->read_budget_ms) ++ di->cache_max_age_ms = di->cache_refresh_ms + data->read_budget_ms; + } else { + di->chip = BQ27000; + di->name = "bq27000-battery"; +diff --git a/include/linux/power/bq27xxx_battery.h b/include/linux/power/bq27xxx_battery.h +index 5a930ed1c..f665762a3 100644 +--- a/include/linux/power/bq27xxx_battery.h ++++ b/include/linux/power/bq27xxx_battery.h +@@ -83,6 +83,9 @@ struct bq27xxx_device_info { + bool cache_use_remaining_capacity; + /* Optional periodic refresh interval for cache-only transports. */ + unsigned int cache_refresh_ms; ++ /* Optional maximum age of a sample, measured from the first register read. */ ++ unsigned int cache_max_age_ms; ++ ktime_t cache_valid_until; + /* Bound admission of new register reads during a cached refresh. */ + unsigned int cache_read_budget_ms; + unsigned long cache_read_deadline; diff --git a/kernel/patches/drivers/power/0049-power-supply-apple_tristar_charger-order-source-inva.patch b/kernel/patches/drivers/power/0049-power-supply-apple_tristar_charger-order-source-inva.patch new file mode 100644 index 00000000..eecb97c1 --- /dev/null +++ b/kernel/patches/drivers/power/0049-power-supply-apple_tristar_charger-order-source-inva.patch @@ -0,0 +1,183 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 19:50:06 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: order source + invalidation before withdrawal + +On D2355 the PMU line and source events may run on different IRQ threads. Count both atomically and publish the reset before reading the current grant so the write-side epoch checks can reject an in-flight grant. + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 42 +++++++++++--------- + drivers/power/supply/apple_tristar_d2355.h | 6 +-- + 2 files changed, 27 insertions(+), 21 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index fa3f28b60..54bbd0970 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -32,6 +32,7 @@ + * Copyright The Orchard Linux contributors + */ + ++#include + #include + #include + #include +@@ -229,10 +230,10 @@ struct tristar_charger { + + /* + * Event attribution: a new epoch invalidates an identification in +- * progress. Written only by the event handlers, which the PMIC event +- * controller runs one after another from one thread. ++ * progress. D2355 line and source handlers can run on separate IRQ ++ * threads and must each invalidate the grant under consideration. + */ +- unsigned int epoch; ++ atomic_t epoch; + bool adc_waiting; + u64 storm_start_ns; + unsigned int storm_count; +@@ -561,7 +562,7 @@ static int tristar_adc_mv(struct tristar_charger *chg, unsigned int epoch, + WRITE_ONCE(chg->adc_waiting, false); + return -ETIMEDOUT; + } +- if (READ_ONCE(chg->epoch) != epoch) ++ if (atomic_read(&chg->epoch) != epoch) + return -ESTALE; + ret = regmap_bulk_read(chg->adc_regmap, chg->adc_base + chg->pmic->adc_result, + value, sizeof(value)); +@@ -764,7 +765,7 @@ static int tristar_identify_usba(struct tristar_charger *chg, unsigned int orien + /* Caller holds lock. */ + static int tristar_identify(struct tristar_charger *chg, struct tristar_ident *id) + { +- unsigned int epoch = READ_ONCE(chg->epoch), orientation; ++ unsigned int epoch = atomic_read(&chg->epoch), orientation; + const char *holder; + bool usbc; + u8 route, state; +@@ -893,7 +894,7 @@ static void tristar_new_attachment(struct tristar_charger *chg, u64 now) + chg->source_ma = 0; + chg->usb_type = POWER_SUPPLY_USB_TYPE_UNKNOWN; + chg->cable_known = false; +- chg->epoch_seen = READ_ONCE(chg->epoch); ++ chg->epoch_seen = atomic_read(&chg->epoch); + WRITE_ONCE(chg->line_ns, 0); + if (tristar_set_code(chg, chg->chip->attach_code)) + dev_crit(chg->dev, "Attach write failed; input limit unverified\n"); +@@ -963,13 +964,13 @@ static void tristar_reconfirm(struct tristar_charger *chg, u64 now, bool expired + return; + } + ret = cbtl_capability(chg, &usbc, &orientation); +- if (!ret && READ_ONCE(chg->epoch) == chg->epoch_seen && ++ if (!ret && atomic_read(&chg->epoch) == chg->epoch_seen && + usbc == chg->usbc && orientation == chg->orientation) { + dev_dbg(chg->dev, "same cable after the source event\n"); + tristar_grant(chg); + return; + } +- chg->epoch_seen = READ_ONCE(chg->epoch); ++ chg->epoch_seen = atomic_read(&chg->epoch); + if (!expired) + return; /* look again on the next poll */ + dev_dbg(chg->dev, "cable changed during the USB session (%d)\n", ret); +@@ -998,9 +999,9 @@ static void tristar_run_identification(struct tristar_charger *chg, u64 now) + tristar_mux_fault(chg); + return; + } +- if (ret || READ_ONCE(chg->epoch) != chg->epoch_seen) { ++ if (ret || atomic_read(&chg->epoch) != chg->epoch_seen) { + /* The source changed while identifying: look again once it settles. */ +- chg->epoch_seen = READ_ONCE(chg->epoch); ++ chg->epoch_seen = atomic_read(&chg->epoch); + if (!expired) { + chg->attach_ns = now; + return; +@@ -1288,9 +1289,9 @@ static void tristar_poll(struct work_struct *work) + tristar_unhold_usb(chg); + goto again; + } +- if (READ_ONCE(chg->epoch) != chg->epoch_seen && chg->phase != TRISTAR_SETTLING) { ++ if (atomic_read(&chg->epoch) != chg->epoch_seen && chg->phase != TRISTAR_SETTLING) { + /* An event the identification did not see: identify again. */ +- chg->epoch_seen = READ_ONCE(chg->epoch); ++ chg->epoch_seen = atomic_read(&chg->epoch); + chg->phase = TRISTAR_SETTLING; + chg->attach_ns = now; + chg->hold_ns = now; +@@ -1355,6 +1356,14 @@ static bool tristar_event_withdraw(struct tristar_charger *chg) + return true; + } + ++static bool tristar_invalidate_source(struct tristar_charger *chg) ++{ ++ atomic_inc(&chg->epoch); ++ /* Publish invalidation before checking for a concurrent current grant. */ ++ smp_mb__after_atomic(); ++ return tristar_event_withdraw(chg); ++} ++ + /* + * The PMU line asserted and the event controller has not read the events + * yet. iOS acts only on the events themselves, so there is nothing to do. +@@ -1366,10 +1375,7 @@ static irqreturn_t tristar_line_irq(int irq, void *data) + if (!chg->chip->invalidate_on_line) + return IRQ_HANDLED; + +- /* J120 ADC and source events arrive through different controllers. */ +- WRITE_ONCE(chg->epoch, READ_ONCE(chg->epoch) + 1); +- smp_mb(); /* Publish invalidation before checking the grant. */ +- if (tristar_event_withdraw(chg)) ++ if (tristar_invalidate_source(chg)) + WRITE_ONCE(chg->line_ns, ktime_get_ns() ?: 1); + return IRQ_HANDLED; + } +@@ -1409,8 +1415,7 @@ static void tristar_source_event(struct tristar_charger *chg) + goto count; + } + +- tristar_event_withdraw(chg); +- WRITE_ONCE(chg->epoch, chg->epoch + 1); ++ tristar_invalidate_source(chg); + /* The USB session may continue: ask its controller for a fresh report. */ + power_supply_changed(chg->psy); + mod_delayed_work(chg->wq, &chg->poll_work, 0); +@@ -1664,6 +1669,7 @@ static int tristar_probe(struct platform_device *pdev) + if (!chg) + return -ENOMEM; + chg->dev = dev; ++ atomic_set(&chg->epoch, 0); + chg->pmic = device_get_match_data(dev); + if (!chg->pmic) + return -ENODEV; +diff --git a/drivers/power/supply/apple_tristar_d2355.h b/drivers/power/supply/apple_tristar_d2355.h +index 8963d4fb9..4d632873b 100644 +--- a/drivers/power/supply/apple_tristar_d2355.h ++++ b/drivers/power/supply/apple_tristar_d2355.h +@@ -82,7 +82,7 @@ static unsigned int tristar_d2355_ma_code(struct tristar_charger *chg, + static int tristar_d2355_write_limit(struct tristar_charger *chg, unsigned int code) + { + struct tristar_d2355 *hw = chg->chip_data; +- unsigned int control, check, epoch = READ_ONCE(chg->epoch); ++ unsigned int control, check, epoch = atomic_read(&chg->epoch); + unsigned int allowance; + u8 raw = 8; + bool disabled; +@@ -138,7 +138,7 @@ static int tristar_d2355_write_limit(struct tristar_charger *chg, unsigned int c + if (!ret && check != (control | BIT(2))) + ret = -ESTALE; + if (!ret && code > chg->chip->fallback_code && +- epoch != READ_ONCE(chg->epoch)) ++ epoch != atomic_read(&chg->epoch)) + ret = -ESTALE; + if (!ret) + ret = regmap_write(chg->regmap, chg->control_base, control & ~BIT(2)); +@@ -154,7 +154,7 @@ static int tristar_d2355_write_limit(struct tristar_charger *chg, unsigned int c + smp_mb(); /* Pairs with invalidation before IRQ withdrawal. */ + } + if (!ret && code > chg->chip->fallback_code && +- epoch != READ_ONCE(chg->epoch)) ++ epoch != atomic_read(&chg->epoch)) + ret = -ESTALE; + if (ret) { + recovery = tristar_d2355_disable(chg); diff --git a/kernel/patches/drivers/power/0050-power-supply-apple_tristar_charger-reject-invalid-pa.patch b/kernel/patches/drivers/power/0050-power-supply-apple_tristar_charger-reject-invalid-pa.patch new file mode 100644 index 00000000..851aae8a --- /dev/null +++ b/kernel/patches/drivers/power/0050-power-supply-apple_tristar_charger-reject-invalid-pa.patch @@ -0,0 +1,30 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 04:17:55 +0100 +Subject: [PATCH] power: supply: apple_tristar_charger: reject invalid pack + capacity + +Reject successful capacity reads outside 0..100 before using the pack +snapshot. An invalid SOC currently passes the D2355 pack check when +temperature, voltage and current are in range, retaining a higher input +limit. Returning -ERANGE makes the required-telemetry guard withdraw to +the fallback instead. + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 2 ++ + 1 file changed, 2 insertions(+) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 54bbd0970..9e6381985 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -374,6 +374,8 @@ static int tristar_read_pack(struct tristar_pack *pack) + ret = -ENODEV; + if (!ret) + ret = power_supply_get_property(battery, POWER_SUPPLY_PROP_CAPACITY, &val); ++ if (!ret && (val.intval < 0 || val.intval > 100)) ++ ret = -ERANGE; + if (!ret) { + pack->capacity = val.intval; + ret = power_supply_get_property(battery, POWER_SUPPLY_PROP_TEMP, &val); diff --git a/kernel/patches/drivers/power/0051-power-supply-report-the-cached-J120-battery-cycle-co.patch b/kernel/patches/drivers/power/0051-power-supply-report-the-cached-J120-battery-cycle-co.patch new file mode 100644 index 00000000..5a9de44b --- /dev/null +++ b/kernel/patches/drivers/power/0051-power-supply-report-the-cached-J120-battery-cycle-co.patch @@ -0,0 +1,39 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 08:56:58 +0100 +Subject: [PATCH] power: supply: report the cached J120 battery cycle count + +Expose CycleCount in the J120 profile. Treat a failed optional cycle read as unavailable so it cannot abort a battery uevent with otherwise valid pack readings. + +Assisted-by: LLM +--- + drivers/power/supply/bq27xxx_battery.c | 3 ++- + drivers/power/supply/bq27xxx_battery_hdq.c | 1 + + 2 files changed, 3 insertions(+), 1 deletion(-) + +diff --git a/drivers/power/supply/bq27xxx_battery.c b/drivers/power/supply/bq27xxx_battery.c +index 18dcd87c9..6369b922f 100644 +--- a/drivers/power/supply/bq27xxx_battery.c ++++ b/drivers/power/supply/bq27xxx_battery.c +@@ -2191,7 +2191,8 @@ static void bq27xxx_battery_refresh_cache(struct bq27xxx_device_info *di) + + if (bq27xxx_cache_has_prop(di, POWER_SUPPLY_PROP_CYCLE_COUNT)) { + ret = bq27xxx_battery_read_cyct(di, &value); +- bq27xxx_cache_value(&cache.cycle_count, ret, &value); ++ /* Keep optional telemetry errors out of the battery uevent. */ ++ bq27xxx_cache_value(&cache.cycle_count, ret ? -ENODATA : 0, &value); + } + + if (bq27xxx_cache_has_prop(di, POWER_SUPPLY_PROP_POWER_AVG)) { +diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c +index 424ff7081..8d939390e 100644 +--- a/drivers/power/supply/bq27xxx_battery_hdq.c ++++ b/drivers/power/supply/bq27xxx_battery_hdq.c +@@ -52,6 +52,7 @@ static const enum power_supply_property bq27540_j120_cache_props[] = { + POWER_SUPPLY_PROP_TEMP, + POWER_SUPPLY_PROP_CHARGE_NOW, + POWER_SUPPLY_PROP_CHARGE_FULL, ++ POWER_SUPPLY_PROP_CYCLE_COUNT, + }; + + struct bq27xxx_hdq_data { diff --git a/kernel/patches/drivers/power/0052-power-supply-verify-Tristar-fallback-on-IRQ-storms.patch b/kernel/patches/drivers/power/0052-power-supply-verify-Tristar-fallback-on-IRQ-storms.patch new file mode 100644 index 00000000..166387ab --- /dev/null +++ b/kernel/patches/drivers/power/0052-power-supply-verify-Tristar-fallback-on-IRQ-storms.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 09:11:15 +0100 +Subject: [PATCH] power: supply: verify Tristar fallback on IRQ storms + +Keep the last verified limit if a storm-triggered fallback write or readback fails, and flag the discrepancy as unverified. + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 7 ++++--- + 1 file changed, 4 insertions(+), 3 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 9e6381985..cfe8a36fb 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -1429,10 +1429,11 @@ static void tristar_source_event(struct tristar_charger *chg) + chg->storm_count = 0; + } + if (++chg->storm_count > TRISTAR_IRQ_STORM) { +- dev_crit(chg->dev, "PMU source events storming; holding the fallback\n"); +- chg->chip->write_limit(chg, chg->chip->fallback_code); +- WRITE_ONCE(chg->code, chg->chip->fallback_code); + WRITE_ONCE(chg->phase, TRISTAR_FAULT); ++ if (tristar_set_code(chg, chg->chip->fallback_code)) ++ dev_crit(chg->dev, "PMU source events storming; input limit unverified\n"); ++ else ++ dev_crit(chg->dev, "PMU source events storming; holding the fallback\n"); + for (i = TRISTAR_IRQ_SOURCE; i < chg->nirqs; i++) + disable_irq_nosync(chg->irqs[i]); + } diff --git a/kernel/patches/drivers/power/0053-power-supply-limit-D2355-input-when-the-J120-gauge-r.patch b/kernel/patches/drivers/power/0053-power-supply-limit-D2355-input-when-the-J120-gauge-r.patch new file mode 100644 index 00000000..d139e3f9 --- /dev/null +++ b/kernel/patches/drivers/power/0053-power-supply-limit-D2355-input-when-the-J120-gauge-r.patch @@ -0,0 +1,89 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:40:22 +0100 +Subject: [PATCH] power: supply: limit D2355 input when the J120 gauge reports + full + +Expose the J120 gauge full flag through cached capacity level. A full pack retains only the 80 mA fallback even if it starts to discharge. Resume ramping under the existing telemetry checks after the flag clears. + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 13 ++++++++++--- + drivers/power/supply/apple_tristar_d2355.h | 4 +++- + drivers/power/supply/bq27xxx_battery_hdq.c | 1 + + 3 files changed, 14 insertions(+), 4 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index cfe8a36fb..a878cbae6 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -359,9 +359,10 @@ struct tristar_pack { + int temp; + int voltage_uv; + int current_ua; ++ bool full; + }; + +-static int tristar_read_pack(struct tristar_pack *pack) ++static int tristar_read_pack(struct tristar_charger *chg, struct tristar_pack *pack) + { + struct power_supply *battery = power_supply_get_by_name("battery"); + union power_supply_propval val; +@@ -390,6 +391,12 @@ static int tristar_read_pack(struct tristar_pack *pack) + } + if (!ret) + pack->current_ua = val.intval; ++ pack->full = false; ++ if (!ret && chg->chip->require_pack_telemetry) { ++ ret = power_supply_get_property(battery, POWER_SUPPLY_PROP_CAPACITY_LEVEL, &val); ++ if (!ret) ++ pack->full = val.intval == POWER_SUPPLY_CAPACITY_LEVEL_FULL; ++ } + power_supply_put(battery); + return ret; + } +@@ -1037,7 +1044,7 @@ static void tristar_ramp_step(struct tristar_charger *chg, u64 now) + if (tristar_debouncing(chg, now) || + (chg->step_ns && now - chg->step_ns < chg->step_wait_ns)) + return; +- if (tristar_read_pack(&pack)) { ++ if (tristar_read_pack(chg, &pack)) { + if (chg->chip->require_pack_telemetry) + tristar_withdraw(chg, chg->chip->fallback_code); + return; +@@ -1140,7 +1147,7 @@ static void tristar_guard(struct tristar_charger *chg, u64 now) + tristar_check_limit(chg); + if (chg->phase != TRISTAR_CHARGING) + return; +- if (tristar_read_pack(&pack)) { ++ if (tristar_read_pack(chg, &pack)) { + if (chg->chip->require_pack_telemetry) + tristar_withdraw(chg, chg->chip->fallback_code); + return; +diff --git a/drivers/power/supply/apple_tristar_d2355.h b/drivers/power/supply/apple_tristar_d2355.h +index 4d632873b..dd117a006 100644 +--- a/drivers/power/supply/apple_tristar_d2355.h ++++ b/drivers/power/supply/apple_tristar_d2355.h +@@ -194,7 +194,9 @@ static bool tristar_d2355_pack_allows(struct tristar_charger *chg, + { + struct tristar_d2355 *hw = chg->chip_data; + +- return pack->temp >= hw->pack_limits[0] && pack->temp <= hw->pack_limits[1] && ++ /* The gauge's full flag remains valid when the pack supplies power. */ ++ return !pack->full && ++ pack->temp >= hw->pack_limits[0] && pack->temp <= hw->pack_limits[1] && + pack->voltage_uv >= hw->pack_limits[2] && pack->voltage_uv <= hw->pack_limits[3] && + pack->current_ua >= hw->pack_limits[4] && pack->current_ua <= hw->pack_limits[5]; + } +diff --git a/drivers/power/supply/bq27xxx_battery_hdq.c b/drivers/power/supply/bq27xxx_battery_hdq.c +index 8d939390e..453f6b622 100644 +--- a/drivers/power/supply/bq27xxx_battery_hdq.c ++++ b/drivers/power/supply/bq27xxx_battery_hdq.c +@@ -44,6 +44,7 @@ static const enum power_supply_property bq27545_iphone7_plus_cache_props[] = { + + /* J120 exposes RemainingCapacity; do not query NominalAvailableCapacity. */ + static const enum power_supply_property bq27540_j120_cache_props[] = { ++ POWER_SUPPLY_PROP_CAPACITY_LEVEL, + POWER_SUPPLY_PROP_STATUS, + POWER_SUPPLY_PROP_PRESENT, + POWER_SUPPLY_PROP_VOLTAGE_NOW, diff --git a/kernel/patches/drivers/power/0054-dt-bindings-power-describe-the-D2355-VBUS-monitor.patch b/kernel/patches/drivers/power/0054-dt-bindings-power-describe-the-D2355-VBUS-monitor.patch new file mode 100644 index 00000000..b7c70fa0 --- /dev/null +++ b/kernel/patches/drivers/power/0054-dt-bindings-power-describe-the-D2355-VBUS-monitor.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 12:45:19 +0100 +Subject: [PATCH] dt-bindings: power: describe the D2355 VBUS monitor + +Assisted-by: LLM +--- + .../bindings/power/supply/apple,d2355-tristar-charger.yaml | 6 ++++++ + 1 file changed, 6 insertions(+) + +diff --git a/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml b/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml +index 23f5c5769..1dba6fb63 100644 +--- a/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml ++++ b/Documentation/devicetree/bindings/power/supply/apple,d2355-tristar-charger.yaml +@@ -19,6 +19,12 @@ allOf: + - $ref: power-supply.yaml# + + properties: ++ io-channels: ++ maxItems: 1 ++ ++ io-channel-names: ++ const: vbus ++ + compatible: + const: apple,d2355-tristar-charger + diff --git a/kernel/patches/drivers/power/0055-power-supply-guard-J120-1.5-A-charging-with-VBUS-tel.patch b/kernel/patches/drivers/power/0055-power-supply-guard-J120-1.5-A-charging-with-VBUS-tel.patch new file mode 100644 index 00000000..d59953a3 --- /dev/null +++ b/kernel/patches/drivers/power/0055-power-supply-guard-J120-1.5-A-charging-with-VBUS-tel.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 12:45:19 +0100 +Subject: [PATCH] power: supply: guard J120 1.5 A charging with VBUS telemetry + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 27 ++++++++++++++++++++ + 1 file changed, 27 insertions(+) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index a878cbae6..5f2d06485 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -38,6 +38,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -224,6 +225,8 @@ struct tristar_charger { + u32 control_base; + u32 adc_base; + unsigned int max_ma; ++ struct iio_channel *vbus; ++ bool vbus_fault; + + /* Serializes policy state and PMIC/Tristar sequences. */ + struct mutex lock; +@@ -896,6 +899,7 @@ static void tristar_new_attachment(struct tristar_charger *chg, u64 now) + /* Before anything else: a host must not start a session yet. */ + tristar_set_usb(chg, false); + chg->present = true; ++ chg->vbus_fault = false; + chg->phase = TRISTAR_SETTLING; + chg->attach_ns = now; + chg->hold_ns = now; +@@ -1290,6 +1294,21 @@ static void tristar_poll(struct work_struct *work) + tristar_new_attachment(chg, now); + goto again; + } ++ if (IS_REACHABLE(CONFIG_IIO) && chg->vbus && !chg->vbus_fault && ++ (chg->phase == TRISTAR_RAMPING || chg->phase == TRISTAR_CHARGING) && ++ tristar_code_ma(chg, chg->target_code) > 1000) { ++ int mv, ret; ++ ++ ret = iio_read_channel_processed(chg->vbus, &mv); ++ if (ret || mv < 4750 || mv > 5500) { ++ chg->vbus_fault = true; ++ chg->phase = TRISTAR_FAULT; ++ dev_warn(chg->dev, "VBUS guard tripped (sample %d mV, error %d)\n", ++ ret ? 0 : mv, ret); ++ } ++ } ++ if (chg->vbus_fault) ++ tristar_withdraw(chg, chg->chip->fallback_code); + if (chg->phase == TRISTAR_FAULT) { + /* USB data must not depend on charging working. */ + if (!chg->usb_on) +@@ -1707,6 +1726,14 @@ static int tristar_probe(struct platform_device *pdev) + if (ret) + return dev_err_probe(dev, ret, "missing board input-current maximum\n"); + chg->max_ma = max_ua / 1000; ++ if (device_property_present(dev, "io-channels")) { ++ if (!IS_REACHABLE(CONFIG_IIO)) ++ return -EOPNOTSUPP; ++ chg->vbus = devm_iio_channel_get(dev, "vbus"); ++ if (IS_ERR(chg->vbus)) ++ return dev_err_probe(dev, PTR_ERR(chg->vbus), "VBUS telemetry unavailable\n"); ++ } ++ + if (chg->chip->prepare) { + ret = chg->chip->prepare(chg); + if (ret) diff --git a/kernel/patches/drivers/power/0056-dt-bindings-mfd-add-D2355-and-PMIC-event-children.patch b/kernel/patches/drivers/power/0056-dt-bindings-mfd-add-D2355-and-PMIC-event-children.patch new file mode 100644 index 00000000..ba81c0b0 --- /dev/null +++ b/kernel/patches/drivers/power/0056-dt-bindings-mfd-add-D2355-and-PMIC-event-children.patch @@ -0,0 +1,43 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:10:11 +0100 +Subject: [PATCH] dt-bindings: mfd: add D2355 and PMIC event children + +Allow the new D2355 charger child and the PMIC event child while preserving the existing D2365 charger binding. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/mfd/apple,pmic.yaml | 8 +++++++- + 1 file changed, 7 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/mfd/apple,pmic.yaml b/Documentation/devicetree/bindings/mfd/apple,pmic.yaml +index 294a323aa..21fece323 100644 +--- a/Documentation/devicetree/bindings/mfd/apple,pmic.yaml ++++ b/Documentation/devicetree/bindings/mfd/apple,pmic.yaml +@@ -40,6 +40,7 @@ properties: + - apple,aria-pmic + - apple,august-pmic + - apple,autumn-pmic ++ - apple,d2355-pmic + - const: apple,i2c-pmic + - items: + - enum: +@@ -62,12 +63,17 @@ properties: + gpio: + $ref: /schemas/gpio/apple,d2365-pmic-gpio.yaml + ++ events: ++ $ref: /schemas/interrupt-controller/apple,pmic-events.yaml ++ + poweroff: + $ref: /schemas/power/reset/apple,d2365-poweroff.yaml# + + patternProperties: + "^charger@[0-9a-f]+$": +- $ref: /schemas/power/supply/apple,d2365-charger.yaml ++ oneOf: ++ - $ref: /schemas/power/supply/apple,d2365-charger.yaml ++ - $ref: /schemas/power/supply/apple,d2355-tristar-charger.yaml + + "^backlight(@[0-9a-f]+)?$": + $ref: /schemas/leds/backlight/apple,pmic-bl.yaml diff --git a/kernel/patches/drivers/power/0057-dt-bindings-mfd-describe-the-J120-cover-switch.patch b/kernel/patches/drivers/power/0057-dt-bindings-mfd-describe-the-J120-cover-switch.patch new file mode 100644 index 00000000..50299b9f --- /dev/null +++ b/kernel/patches/drivers/power/0057-dt-bindings-mfd-describe-the-J120-cover-switch.patch @@ -0,0 +1,31 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 02:35:33 +0100 +Subject: [PATCH] dt-bindings: mfd: describe the J120 cover switch + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/mfd/apple,pmic.yaml | 10 ++++++++++ + 1 file changed, 10 insertions(+) + +diff --git a/Documentation/devicetree/bindings/mfd/apple,pmic.yaml b/Documentation/devicetree/bindings/mfd/apple,pmic.yaml +index 21fece323..5ec317d11 100644 +--- a/Documentation/devicetree/bindings/mfd/apple,pmic.yaml ++++ b/Documentation/devicetree/bindings/mfd/apple,pmic.yaml +@@ -66,6 +66,16 @@ properties: + events: + $ref: /schemas/interrupt-controller/apple,pmic-events.yaml + ++ cover-switch: ++ type: object ++ description: Magnetic cover switch wired to GPIOs 0 and 10 on the J120 August PMIC. ++ properties: ++ compatible: ++ const: apple,j120-cover-switch ++ required: ++ - compatible ++ additionalProperties: false ++ + poweroff: + $ref: /schemas/power/reset/apple,d2365-poweroff.yaml# + diff --git a/kernel/patches/drivers/power/0058-power-supply-define-Tristar-operations-before-PMIC-m.patch b/kernel/patches/drivers/power/0058-power-supply-define-Tristar-operations-before-PMIC-m.patch new file mode 100644 index 00000000..2920bcaa --- /dev/null +++ b/kernel/patches/drivers/power/0058-power-supply-define-Tristar-operations-before-PMIC-m.patch @@ -0,0 +1,79 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 21:11:03 +0100 +Subject: [PATCH] power: supply: define Tristar operations before PMIC match + data + +Clang warns about the file-scope tentative definitions while the operations type is incomplete. Declare the type before the two chip tables. + +Assisted-by: LLM +--- + drivers/power/supply/apple_tristar_charger.c | 48 ++++++++++---------- + 1 file changed, 24 insertions(+), 24 deletions(-) + +diff --git a/drivers/power/supply/apple_tristar_charger.c b/drivers/power/supply/apple_tristar_charger.c +index 5f2d06485..2eb0a6223 100644 +--- a/drivers/power/supply/apple_tristar_charger.c ++++ b/drivers/power/supply/apple_tristar_charger.c +@@ -65,6 +65,30 @@ + #define TRISTAR_CHG_ADC_START BIT(7) /* D2207 ADC control */ + #define TRISTAR_CHG_ADC_LATCH GENMASK(7, 3) /* D2207 ADC control + 1 */ + ++struct tristar_charger; ++struct tristar_pack; ++ ++/* Keep shared charging policy independent of the PMIC input-limit registers. */ ++struct tristar_chip_info { ++ int (*prepare)(struct tristar_charger *chg); ++ bool (*pack_allows)(struct tristar_charger *chg, const struct tristar_pack *pack); ++ unsigned int status_size, control_size; ++ u8 adc_error_mask; ++ bool strict_limit_errors; ++ bool require_pack_telemetry; ++ bool invalidate_on_line; ++ int (*read_limit)(struct tristar_charger *chg, unsigned int *code); ++ int (*write_limit)(struct tristar_charger *chg, unsigned int code); ++ unsigned int (*code_ma)(struct tristar_charger *chg, unsigned int code); ++ unsigned int (*ma_code)(struct tristar_charger *chg, unsigned int ma); ++ int (*read_status)(struct tristar_charger *chg, unsigned int *status); ++ unsigned int handoff_code; ++ unsigned int attach_code; ++ unsigned int online_status; ++ unsigned int ramp_step_ms; ++ unsigned int fallback_code; ++}; ++ + /* + * 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 +@@ -180,30 +204,6 @@ enum cbtl_route { + CBTL_ROUTE_UART2, + }; + +-struct tristar_charger; +-struct tristar_pack; +- +-/* Keep shared charging policy independent of the PMIC input-limit registers. */ +-struct tristar_chip_info { +- int (*prepare)(struct tristar_charger *chg); +- bool (*pack_allows)(struct tristar_charger *chg, const struct tristar_pack *pack); +- unsigned int status_size, control_size; +- u8 adc_error_mask; +- bool strict_limit_errors; +- bool require_pack_telemetry; +- bool invalidate_on_line; +- int (*read_limit)(struct tristar_charger *chg, unsigned int *code); +- int (*write_limit)(struct tristar_charger *chg, unsigned int code); +- unsigned int (*code_ma)(struct tristar_charger *chg, unsigned int code); +- unsigned int (*ma_code)(struct tristar_charger *chg, unsigned int ma); +- int (*read_status)(struct tristar_charger *chg, unsigned int *status); +- unsigned int handoff_code; +- unsigned int attach_code; +- unsigned int online_status; +- unsigned int ramp_step_ms; +- unsigned int fallback_code; +-}; +- + struct tristar_charger { + const struct tristar_chip_info *chip; + void *chip_data; diff --git a/kernel/patches/drivers/regulator/0011-dt-bindings-regulator-describe-the-August-touch-anal.patch b/kernel/patches/drivers/regulator/0011-dt-bindings-regulator-describe-the-August-touch-anal.patch new file mode 100644 index 00000000..822e64fe --- /dev/null +++ b/kernel/patches/drivers/regulator/0011-dt-bindings-regulator-describe-the-August-touch-anal.patch @@ -0,0 +1,34 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:51 +0100 +Subject: [PATCH] dt-bindings: regulator: describe the August touch analog + supply + +Add the J120 analog LDO compatible to the existing Apple PMIC touch regulator binding. + +Assisted-by: LLM +--- + .../bindings/regulator/apple,pmic-touch-regulator.yaml | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml b/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml +index f02ee8ccb..df5ab7032 100644 +--- a/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml ++++ b/Documentation/devicetree/bindings/regulator/apple,pmic-touch-regulator.yaml +@@ -11,7 +11,7 @@ maintainers: + + description: + Fixed touchscreen supply switches provided by the D2089, D2186, D2207, Adelyn, +- Angel, Chestnut and Acorn PMICs. The compatible identifies both the PMIC and the physical supply; ++ Angel, August, Chestnut and Acorn PMICs. The compatible identifies both the PMIC and the physical supply; + register layout is an implementation detail of the regulator driver. + + allOf: +@@ -23,6 +23,7 @@ properties: + - apple,acorn-touch-analog-regulator + - apple,adelyn-touch-core-regulator + - apple,angel-touch-analog-regulator ++ - apple,august-touch-analog-regulator + - apple,chestnut-touch-hv-regulator + - apple,d2089-touch-analog-regulator + - apple,d2089-touch-core-regulator diff --git a/kernel/patches/drivers/regulator/0012-regulator-apple-pmic-touch-support-the-August-analog.patch b/kernel/patches/drivers/regulator/0012-regulator-apple-pmic-touch-support-the-August-analog.patch new file mode 100644 index 00000000..7f2b5f73 --- /dev/null +++ b/kernel/patches/drivers/regulator/0012-regulator-apple-pmic-touch-support-the-August-analog.patch @@ -0,0 +1,52 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:52 +0100 +Subject: [PATCH] regulator: apple-pmic-touch: support the August analog LDO + +The J120 touch analog rail uses control register 0x312, bit 0. Select the register through compatible match data and preserve unrelated PMIC bits. + +Assisted-by: LLM +--- + .../regulator/apple-pmic-touch-regulator.c | 22 +++++++++++++++++++ + 1 file changed, 22 insertions(+) + +diff --git a/drivers/regulator/apple-pmic-touch-regulator.c b/drivers/regulator/apple-pmic-touch-regulator.c +index 49e241471..710bf9145 100644 +--- a/drivers/regulator/apple-pmic-touch-regulator.c ++++ b/drivers/regulator/apple-pmic-touch-regulator.c +@@ -64,6 +64,24 @@ static const struct regulator_desc apple_d2089_touch_core = { + .disable_val = 0, + }; + ++/* ++ * August (D2400, J120) pmuL(0x30c) encodes LDO index 12 and options 3, ++ * not a register address. In iPadOS 17.7.11 (21H461), _setLDO at ++ * 0xfffffff0064bd8b0 indexes 12-byte entries at 0xfffffff005551a54. ++ * Entry 12 selects control register 0x312 and enable mask 0x01; the ++ * native read/modify/write at 0xfffffff0064bdaac preserves the other bits. ++ */ ++static const struct regulator_desc apple_august_touch_analog = { ++ .name = "august-touch-analog", ++ .ops = &apple_pmic_touch_regulator_ops, ++ .type = REGULATOR_VOLTAGE, ++ .owner = THIS_MODULE, ++ .enable_reg = 0x312, ++ .enable_mask = 0x01, ++ .enable_val = 0x01, ++ .disable_val = 0, ++}; ++ + static const struct regulator_desc apple_d2186_touch_core = { + .name = "d2186-touch-core", + .ops = &apple_pmic_touch_regulator_ops, +@@ -229,6 +247,10 @@ static const struct of_device_id apple_pmic_touch_regulator_of_match[] = { + .compatible = "apple,d2089-touch-core-regulator", + .data = &apple_d2089_touch_core, + }, ++ { ++ .compatible = "apple,august-touch-analog-regulator", ++ .data = &apple_august_touch_analog, ++ }, + { + .compatible = "apple,d2186-touch-core-regulator", + .data = &apple_d2186_touch_core, diff --git a/kernel/patches/drivers/soc-apple/0033-dt-bindings-soc-apple-describe-A10-and-A10X-AOP-reso.patch b/kernel/patches/drivers/soc-apple/0033-dt-bindings-soc-apple-describe-A10-and-A10X-AOP-reso.patch new file mode 100644 index 00000000..9c0daa43 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0033-dt-bindings-soc-apple-describe-A10-and-A10X-AOP-reso.patch @@ -0,0 +1,115 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:56 +0100 +Subject: [PATCH] dt-bindings: soc: apple: describe A10 and A10X AOP resources + +Describe RTKit mailbox, SRAM, firmware and sensor children. Allow an optional board target and a bootloader-supplied unit identity without encoding per-unit values in source. + +Assisted-by: LLM +--- + .../bindings/soc/apple/apple,aop.yaml | 96 +++++++++++++++++++ + 1 file changed, 96 insertions(+) + create mode 100644 Documentation/devicetree/bindings/soc/apple/apple,aop.yaml + +diff --git a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +new file mode 100644 +index 000000000..128887714 +--- /dev/null ++++ b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +@@ -0,0 +1,96 @@ ++# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) ++%YAML 1.2 ++--- ++$id: http://devicetree.org/schemas/soc/apple/apple,aop.yaml# ++$schema: http://devicetree.org/meta-schemas/core.yaml# ++ ++title: Apple A10 and A10X Always-On Processor ++ ++maintainers: ++ - Dalton Alexandre ++ ++description: | ++ The AOP loads RTKit firmware into SRAM and uses an A7 IOP mailbox and EPIC ++ services. Its main image and external segment are separate firmware files. ++ The SRAM resource must cover the firmware's RTSZ working extent and exclude ++ bootloader reservations. Firmware can only be started once per system boot. ++ ++properties: ++ compatible: ++ enum: ++ - apple,t8010-aop ++ - apple,t8011-aop ++ ++ reg: ++ items: ++ - description: AOP AKF registers ++ - description: Auto-boot control registers ++ - description: Reserved SRAM firmware and working region ++ ++ reg-names: ++ items: ++ - const: akf ++ - const: control ++ - const: sram ++ ++ mboxes: ++ maxItems: 1 ++ ++ mbox-names: ++ const: mbox ++ ++ firmware-name: ++ $ref: /schemas/types.yaml#/definitions/string-array ++ items: ++ - description: Main AOP firmware image ++ - description: External AOP firmware segment ++ ++ apple,aop-target: ++ $ref: /schemas/types.yaml#/definitions/uint32 ++ description: | ++ Board target passed in the firmware's AOPt boot argument. If absent, ++ preserve the firmware default used by existing A10 boards. ++ ++ apple,ecid: ++ $ref: /schemas/types.yaml#/definitions/uint64 ++ description: | ++ Unit identity inserted by the bootloader for firmware initialization. ++ The driver consumes and removes this property. Do not encode an identity ++ in a source device tree. ++ ++ accel: ++ type: object ++ additionalProperties: false ++ properties: ++ compatible: ++ const: apple,t8010-aop-accel ++ mount-matrix: ++ $ref: /schemas/types.yaml#/definitions/string-array ++ minItems: 9 ++ maxItems: 9 ++ status: true ++ required: ++ - compatible ++ ++patternProperties: ++ "^(gyro|compass|pressure)$": ++ type: object ++ additionalProperties: false ++ properties: ++ compatible: ++ enum: ++ - apple,t8010-aop-gyro ++ - apple,t8010-aop-compass ++ - apple,t8010-aop-pressure ++ status: true ++ required: ++ - compatible ++ ++required: ++ - compatible ++ - reg ++ - reg-names ++ - mboxes ++ - mbox-names ++ ++additionalProperties: false diff --git a/kernel/patches/drivers/soc-apple/0034-soc-apple-support-the-T8011-AOP-firmware-target.patch b/kernel/patches/drivers/soc-apple/0034-soc-apple-support-the-T8011-AOP-firmware-target.patch new file mode 100644 index 00000000..11c202e9 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0034-soc-apple-support-the-T8011-AOP-firmware-target.patch @@ -0,0 +1,103 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:57 +0100 +Subject: [PATCH] soc: apple: support the T8011 AOP firmware target + +Check the firmware RTSZ working extent against SRAM and optionally patch AOPt from board data. Match T8011 to the existing A10 AOP path. If firmware cannot halt after a probe error, retain the bound owner and its RTKit/DMA resources until reboot. + +Assisted-by: LLM +--- + drivers/soc/apple/aop.c | 34 ++++++++++++++++++++++++++++++++-- + 1 file changed, 32 insertions(+), 2 deletions(-) + +diff --git a/drivers/soc/apple/aop.c b/drivers/soc/apple/aop.c +index 5c23317d1..ac2066540 100644 +--- a/drivers/soc/apple/aop.c ++++ b/drivers/soc/apple/aop.c +@@ -71,6 +71,7 @@ + #define APPLE_AOP_BOOTARG_SOCR APPLE_AOP_FOURCC('S', 'O', 'C', 'R') + #define APPLE_AOP_BOOTARG_STKG APPLE_AOP_FOURCC('S', 'T', 'K', 'G') + #define APPLE_AOP_MAX_BOOTARGS 10 ++#define APPLE_AOP_BOOTARG_RTSZ APPLE_AOP_FOURCC('R', 'T', 'S', 'Z') + + #define APPLE_AOP_HALT_TIMEOUT_US 10000 + +@@ -282,6 +283,7 @@ static int apple_aop_patch_bootargs(struct apple_aop *aop, u8 *image, size_t siz + struct apple_aop_bootarg *args, unsigned int count) + { + size_t offset, end, pos; ++ bool runtime_size_found = false; + unsigned int i; + + offset = get_unaligned_le32(image + APPLE_AOP_IMAGE_BOOTARGS_OFFSET); +@@ -298,6 +300,15 @@ static int apple_aop_patch_bootargs(struct apple_aop *aop, u8 *image, size_t siz + if (len > end - pos) + return -EINVAL; + ++ /* Native loading reserves max(image size, RTSZ), not just the file. */ ++ if (key == APPLE_AOP_BOOTARG_RTSZ) { ++ if (len != sizeof(u32) || runtime_size_found) ++ return -EINVAL; ++ runtime_size_found = true; ++ if (get_unaligned_le32(image + pos) > aop->sram_size) ++ return -EINVAL; ++ } ++ + for (i = 0; i < count; i++) { + if (args[i].key != key) + continue; +@@ -354,11 +365,21 @@ static int apple_aop_load(struct apple_aop *aop, u64 ecid) + struct device_node *np = aop->dev->of_node; + u8 prng[32], nonce[8], guard[4], ncal = 0; + __le64 ecid_le = cpu_to_le64(ecid), ext_le, wrapper_le; +- __le32 target_le, chip_le, revision_le; ++ __le32 target_le = 0, chip_le, revision_le; + unsigned int count = 0; ++ u32 target; ++ bool has_target = !aop->hw->soc_bootargs && ++ of_property_present(np, "apple,aop-target"); + u8 *image; + int ret; + ++ if (has_target) { ++ ret = of_property_read_u32(np, "apple,aop-target", &target); ++ if (ret) ++ return dev_err_probe(aop->dev, ret, "invalid AOP target\n"); ++ target_le = cpu_to_le32(target); ++ } ++ + ret = of_property_read_string_index(np, "firmware-name", 0, &main_name); + if (!ret) + ret = of_property_read_string_index(np, "firmware-name", 1, &ext_name); +@@ -423,6 +444,10 @@ static int apple_aop_load(struct apple_aop *aop, u64 ecid) + apple_aop_add_bootarg(args, &count, APPLE_AOP_BOOTARG_STKG, guard, sizeof(guard)); + } + ++ if (has_target) ++ apple_aop_add_bootarg(args, &count, APPLE_AOP_BOOTARG_AOPT, ++ &target_le, sizeof(target_le)); ++ + ret = apple_aop_patch_bootargs(aop, image, main_fw->size, args, count); + if (ret) + dev_err(aop->dev, "unexpected boot arguments in %s: %d\n", main_name, ret); +@@ -1082,7 +1107,11 @@ static int apple_aop_probe(struct platform_device *pdev) + apple_rtkit_free(aop->rtk); + apple_aop_free_buffers(aop); + } else { +- dev_err(dev, "failed to halt; keeping its memory\n"); ++ /* RTKit still refers to the devm state: retain the bound device too. */ ++ aop->removing = true; ++ platform_set_drvdata(pdev, aop); ++ dev_crit(dev, "failed to halt; retaining bound device until reboot\n"); ++ return 0; + } + return ret; + +@@ -1125,6 +1154,7 @@ static const struct apple_aop_hw apple_aop_t8010_hw = { + static const struct of_device_id apple_aop_of_match[] = { + { .compatible = "apple,s8000-aop", .data = &apple_aop_s8000_hw }, + { .compatible = "apple,t8010-aop", .data = &apple_aop_t8010_hw }, ++ { .compatible = "apple,t8011-aop", .data = &apple_aop_t8010_hw }, + {} + }; + MODULE_DEVICE_TABLE(of, apple_aop_of_match); diff --git a/kernel/patches/drivers/soc-apple/0035-soc-apple-rtkit-Return-endpoint-start-send-errors.patch b/kernel/patches/drivers/soc-apple/0035-soc-apple-rtkit-Return-endpoint-start-send-errors.patch new file mode 100644 index 00000000..eb73e24c --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0035-soc-apple-rtkit-Return-endpoint-start-send-errors.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 10:53:20 +0100 +Subject: [PATCH] soc: apple: rtkit: Return endpoint start send errors + +The management send can fail, but apple_rtkit_start_ep() currently returns zero after it. Propagate the send error so application drivers can stop initialization when the firmware could not be sent the endpoint start request. + +Assisted-by: LLM +--- + drivers/soc/apple/rtkit.c | 4 +--- + 1 file changed, 1 insertion(+), 3 deletions(-) + +diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c +index b54688f56..ccadd6c4e 100644 +--- a/drivers/soc/apple/rtkit.c ++++ b/drivers/soc/apple/rtkit.c +@@ -676,9 +676,7 @@ int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint) + + msg = FIELD_PREP(APPLE_RTKIT_MGMT_STARTEP_EP, endpoint); + msg |= APPLE_RTKIT_MGMT_STARTEP_FLAG; +- apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_STARTEP, msg); +- +- return 0; ++ return apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_STARTEP, msg); + } + EXPORT_SYMBOL_GPL(apple_rtkit_start_ep); + diff --git a/kernel/patches/drivers/soc-apple/0036-soc-apple-rtkit-Report-hello-reply-send-failures-dur.patch b/kernel/patches/drivers/soc-apple/0036-soc-apple-rtkit-Report-hello-reply-send-failures-dur.patch new file mode 100644 index 00000000..2c08d2dc --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0036-soc-apple-rtkit-Report-hello-reply-send-failures-dur.patch @@ -0,0 +1,42 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 10:58:39 +0100 +Subject: [PATCH] soc: apple: rtkit: Report hello reply send failures during + boot + +If the hello reply cannot be sent, endpoint discovery will not complete. Wake the boot waiter with the mailbox error using the existing handshake failure path, instead of waiting for the endpoint-map timeout. + +Assisted-by: LLM +--- + drivers/soc/apple/rtkit.c | 9 +++++---- + 1 file changed, 5 insertions(+), 4 deletions(-) + +diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c +index ccadd6c4e..68ae42a7f 100644 +--- a/drivers/soc/apple/rtkit.c ++++ b/drivers/soc/apple/rtkit.c +@@ -121,6 +121,7 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) + int min_ver = FIELD_GET(APPLE_RTKIT_MGMT_HELLO_MINVER, msg); + int max_ver = FIELD_GET(APPLE_RTKIT_MGMT_HELLO_MAXVER, msg); + int want_ver = min(APPLE_RTKIT_MAX_SUPPORTED_VERSION, max_ver); ++ int ret = -EINVAL; + + /* + * Protocol 10 firmware carries its minor version in the HELLO's +@@ -161,12 +162,12 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) + reply = FIELD_PREP(APPLE_RTKIT_MGMT_HELLO_MINVER, + rtk->version == 10 ? rtk->minor_version : want_ver); + reply |= FIELD_PREP(APPLE_RTKIT_MGMT_HELLO_MAXVER, want_ver); +- apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_HELLO_REPLY, reply); +- +- return; ++ ret = apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_HELLO_REPLY, reply); ++ if (!ret) ++ return; + + abort_boot: +- rtk->boot_result = -EINVAL; ++ rtk->boot_result = ret; + complete_all(&rtk->epmap_completion); + } + diff --git a/kernel/patches/drivers/soc-apple/0037-soc-apple-rtkit-propagate-endpoint-discovery-send-fa.patch b/kernel/patches/drivers/soc-apple/0037-soc-apple-rtkit-propagate-endpoint-discovery-send-fa.patch new file mode 100644 index 00000000..45456b90 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0037-soc-apple-rtkit-propagate-endpoint-discovery-send-fa.patch @@ -0,0 +1,102 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 19:53:16 +0100 +Subject: [PATCH] soc: apple: rtkit: propagate endpoint-discovery send failures + +An endpoint-map reply or system endpoint start can fail before the application endpoints are available. Fail the boot wait on the send error and retain it until the mailbox is reinitialized. + +Assisted-by: LLM +--- + drivers/soc/apple/rtkit.c | 28 +++++++++++++++++++++------- + 1 file changed, 21 insertions(+), 7 deletions(-) + +diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c +index 68ae42a7f..0e62714c7 100644 +--- a/drivers/soc/apple/rtkit.c ++++ b/drivers/soc/apple/rtkit.c +@@ -123,6 +123,9 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) + int want_ver = min(APPLE_RTKIT_MAX_SUPPORTED_VERSION, max_ver); + int ret = -EINVAL; + ++ if (rtk->boot_result) ++ return; ++ + /* + * Protocol 10 firmware carries its minor version in the HELLO's + * minimum-version field (10.0 to 10.2), not a lower major version. +@@ -167,7 +170,7 @@ static void apple_rtkit_management_rx_hello(struct apple_rtkit *rtk, u64 msg) + return; + + abort_boot: +- rtk->boot_result = ret; ++ WRITE_ONCE(rtk->boot_result, ret); + complete_all(&rtk->epmap_completion); + } + +@@ -177,6 +180,10 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) + u64 reply; + unsigned long bitmap = FIELD_GET(APPLE_RTKIT_MGMT_EPMAP_BITMAP, msg); + u32 base = FIELD_GET(APPLE_RTKIT_MGMT_EPMAP_BASE, msg); ++ int ret; ++ ++ if (rtk->boot_result) ++ return; + + dev_dbg(rtk->dev, + "RTKit: received endpoint bitmap 0x%lx with base 0x%x\n", +@@ -196,7 +203,9 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) + reply |= APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE; + } + +- apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_EPMAP_REPLY, reply); ++ ret = apple_rtkit_management_send(rtk, APPLE_RTKIT_MGMT_EPMAP_REPLY, reply); ++ if (ret) ++ goto done; + + if (rtk->version > 10 && !(msg & APPLE_RTKIT_MGMT_EPMAP_LAST)) + return; +@@ -215,7 +224,9 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) + case APPLE_RTKIT_EP_OSLOG: + dev_dbg(rtk->dev, + "RTKit: Starting system endpoint 0x%02x\n", ep); +- apple_rtkit_start_ep(rtk, ep); ++ ret = apple_rtkit_start_ep(rtk, ep); ++ if (ret) ++ goto done; + break; + + default: +@@ -225,10 +236,11 @@ static void apple_rtkit_management_rx_epmap(struct apple_rtkit *rtk, u64 msg) + } + } + +- rtk->boot_result = 0; ++done: ++ WRITE_ONCE(rtk->boot_result, ret); + complete_all(&rtk->epmap_completion); + +- if (rtk->ops->epmap_done) ++ if (!ret && rtk->ops->epmap_done) + rtk->ops->epmap_done(rtk->cookie); + } + +@@ -781,6 +793,7 @@ int apple_rtkit_reinit(struct apple_rtkit *rtk) + bitmap_zero(rtk->endpoints, APPLE_RTKIT_MAX_ENDPOINTS); + set_bit(APPLE_RTKIT_EP_MGMT, rtk->endpoints); + ++ rtk->boot_result = 0; + reinit_completion(&rtk->epmap_completion); + reinit_completion(&rtk->iop_pwr_ack_completion); + reinit_completion(&rtk->ap_pwr_ack_completion); +@@ -885,8 +898,9 @@ int apple_rtkit_boot(struct apple_rtkit *rtk) + ret = apple_rtkit_wait_for_completion(&rtk->epmap_completion); + if (ret) + return ret; +- if (rtk->boot_result) +- return rtk->boot_result; ++ ret = READ_ONCE(rtk->boot_result); ++ if (ret) ++ return ret; + + dev_dbg(rtk->dev, "RTKit: waiting for IOP power state ACK\n"); + ret = apple_rtkit_wait_for_completion(&rtk->iop_pwr_ack_completion); diff --git a/kernel/patches/drivers/soc-apple/0038-dt-bindings-describe-T8011-SmartIO-and-AOP-audio.patch b/kernel/patches/drivers/soc-apple/0038-dt-bindings-describe-T8011-SmartIO-and-AOP-audio.patch new file mode 100644 index 00000000..c57a70c9 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0038-dt-bindings-describe-T8011-SmartIO-and-AOP-audio.patch @@ -0,0 +1,95 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:19:14 +0100 +Subject: [PATCH] dt-bindings: describe T8011 SmartIO and AOP audio + +Describe the T8011 SmartIO register resource and allow the AOP firmware audio service node used for PDM clock control. + +Assisted-by: LLM +--- + .../devicetree/bindings/dma/apple,sio.yaml | 24 ++++++++++++++++--- + .../bindings/soc/apple/apple,aop.yaml | 13 ++++++++++ + 2 files changed, 34 insertions(+), 3 deletions(-) + +diff --git a/Documentation/devicetree/bindings/dma/apple,sio.yaml b/Documentation/devicetree/bindings/dma/apple,sio.yaml +index b19e66a2a..d0d2af00d 100644 +--- a/Documentation/devicetree/bindings/dma/apple,sio.yaml ++++ b/Documentation/devicetree/bindings/dma/apple,sio.yaml +@@ -4,10 +4,10 @@ + $id: http://devicetree.org/schemas/dma/apple,sio.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple T7000/S8000/T8010 SmartIO coprocessor and DMA controller ++title: Apple T7000/S8000/T8010/T8011 SmartIO coprocessor and DMA controller + + description: | +- The T7000 (A8, A8X), S8000 (A9) and T8010 (A10) SmartIO coprocessor ++ The T7000 (A8, A8X), S8000 (A9), T8010 (A10) and T8011 (A10X) 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 +@@ -18,6 +18,24 @@ maintainers: + + allOf: + - $ref: dma-controller.yaml# ++ - if: ++ properties: ++ compatible: ++ const: apple,t8011-sio ++ then: ++ properties: ++ reg: ++ maxItems: 1 ++ reg-names: ++ maxItems: 1 ++ else: ++ properties: ++ reg: ++ minItems: 2 ++ reg-names: ++ minItems: 2 ++ required: ++ - dma-channels + + properties: + compatible: +@@ -25,6 +43,7 @@ properties: + - apple,t7000-sio + - apple,s8000-sio + - apple,t8010-sio ++ - apple,t8011-sio + + reg: + minItems: 1 +@@ -95,7 +114,6 @@ required: + - interrupts + - power-domains + - firmware-name +- - dma-channels + - '#dma-cells' + + additionalProperties: false +diff --git a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +index 128887714..61437c676 100644 +--- a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml ++++ b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +@@ -73,6 +73,19 @@ properties: + - compatible + + patternProperties: ++ "^aop[-_]audio$": ++ type: object ++ additionalProperties: false ++ properties: ++ compatible: ++ const: apple,t8010-aop-audio ++ "#clock-cells": ++ const: 0 ++ status: true ++ required: ++ - compatible ++ - "#clock-cells" ++ + "^(gyro|compass|pressure)$": + type: object + additionalProperties: false diff --git a/kernel/patches/drivers/soc-apple/0039-soc-apple-support-T8011-SmartIO-audio-DMA-endpoints.patch b/kernel/patches/drivers/soc-apple/0039-soc-apple-support-T8011-SmartIO-audio-DMA-endpoints.patch new file mode 100644 index 00000000..767462d1 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0039-soc-apple-support-T8011-SmartIO-audio-DMA-endpoints.patch @@ -0,0 +1,48 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:19:14 +0100 +Subject: [PATCH] soc: apple: support T8011 SmartIO audio DMA endpoints + +Allow the J120 audio firmware endpoints for MCA4 transmit and PDM receive. + +Assisted-by: LLM +--- + drivers/soc/apple/apple-sio-core.c | 16 +++++++++++++++- + 1 file changed, 15 insertions(+), 1 deletion(-) + +diff --git a/drivers/soc/apple/apple-sio-core.c b/drivers/soc/apple/apple-sio-core.c +index c0558b16b..b7a968293 100644 +--- a/drivers/soc/apple/apple-sio-core.c ++++ b/drivers/soc/apple/apple-sio-core.c +@@ -1187,10 +1187,23 @@ static const struct apple_sio_hw apple_sio_t7000_hw = { + .num_dma_ranges = ARRAY_SIZE(apple_sio_t7000_dma_ranges), + }; + ++/* J120 MCA4 transmit and PDM receive. */ ++static const struct apple_sio_dma_range apple_sio_t8011_dma_ranges[] = { ++ { 0x30, 0x30 }, ++ { 0x5b, 0x5b }, ++}; ++ ++static const struct apple_sio_hw apple_sio_t8011_hw = { ++ .regs = &apple_sio_regs_v2, ++ .dma_ranges = apple_sio_t8011_dma_ranges, ++ .num_dma_ranges = ARRAY_SIZE(apple_sio_t8011_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 }, ++ { .compatible = "apple,t8011-sio", .data = &apple_sio_t8011_hw }, + {} + }; + MODULE_DEVICE_TABLE(of, apple_sio_of_match); +@@ -1210,5 +1223,6 @@ 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 T7000/S8000/T8010 SmartIO coprocessor driver"); ++MODULE_FIRMWARE("apple/t8011-smartio.bin"); ++MODULE_DESCRIPTION("Apple T7000/S8000/T8010/T8011 SmartIO coprocessor driver"); + MODULE_LICENSE("Dual MIT/GPL"); diff --git a/kernel/patches/drivers/soc-apple/0040-dt-bindings-apple-use-the-standard-AOP-sensor-mount-.patch b/kernel/patches/drivers/soc-apple/0040-dt-bindings-apple-use-the-standard-AOP-sensor-mount-.patch new file mode 100644 index 00000000..bf461f29 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0040-dt-bindings-apple-use-the-standard-AOP-sensor-mount-.patch @@ -0,0 +1,28 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:20:54 +0100 +Subject: [PATCH] dt-bindings: apple: use the standard AOP sensor mount matrix + +A mount matrix can contain repeated entries. Use the standard property schema for the accelerometer. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/soc/apple/apple,aop.yaml | 5 +---- + 1 file changed, 1 insertion(+), 4 deletions(-) + +diff --git a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +index 61437c676..89ab88843 100644 +--- a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml ++++ b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +@@ -64,10 +64,7 @@ properties: + properties: + compatible: + const: apple,t8010-aop-accel +- mount-matrix: +- $ref: /schemas/types.yaml#/definitions/string-array +- minItems: 9 +- maxItems: 9 ++ mount-matrix: true + status: true + required: + - compatible diff --git a/kernel/patches/drivers/soc-apple/0041-soc-apple-match-the-legacy-T8011-AOP-audio-child-nam.patch b/kernel/patches/drivers/soc-apple/0041-soc-apple-match-the-legacy-T8011-AOP-audio-child-nam.patch new file mode 100644 index 00000000..b9328d8c --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0041-soc-apple-match-the-legacy-T8011-AOP-audio-child-nam.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:00:35 +0100 +Subject: [PATCH] soc: apple: match the legacy T8011 AOP audio child name + +Assisted-by: LLM +--- + drivers/soc/apple/aop.c | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/drivers/soc/apple/aop.c b/drivers/soc/apple/aop.c +index ac2066540..e036f64ed 100644 +--- a/drivers/soc/apple/aop.c ++++ b/drivers/soc/apple/aop.c +@@ -532,6 +532,10 @@ static void apple_aop_register_service(struct work_struct *work) + char name[32]; + + np = of_get_child_by_name(aop->dev->of_node, rw->service.name); ++ /* Earlier T8011 trees named the firmware's aop_audio service aop-audio. */ ++ if (!np && !strcmp(rw->service.name, "aop_audio") && ++ of_device_is_compatible(aop->dev->of_node, "apple,t8011-aop")) ++ np = of_get_child_by_name(aop->dev->of_node, "aop-audio"); + if (!np || !of_device_is_available(np)) + goto out; + diff --git a/kernel/patches/drivers/soc-apple/0042-dt-bindings-soc-apple-allow-the-AOP-sensor-mounting-.patch b/kernel/patches/drivers/soc-apple/0042-dt-bindings-soc-apple-allow-the-AOP-sensor-mounting-.patch new file mode 100644 index 00000000..408f8103 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0042-dt-bindings-soc-apple-allow-the-AOP-sensor-mounting-.patch @@ -0,0 +1,24 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 23:18:11 +0100 +Subject: [PATCH] dt-bindings: soc: apple: allow the AOP sensor mounting matrix + +J120 describes the gyroscope mounting orientation for the IIO driver. Accept mount-matrix on the motion service nodes as for the accelerometer. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/soc/apple/apple,aop.yaml | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +index 89ab88843..6e5632498 100644 +--- a/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml ++++ b/Documentation/devicetree/bindings/soc/apple/apple,aop.yaml +@@ -92,6 +92,7 @@ patternProperties: + - apple,t8010-aop-gyro + - apple,t8010-aop-compass + - apple,t8010-aop-pressure ++ mount-matrix: true + status: true + required: + - compatible diff --git a/kernel/patches/drivers/soc-apple/0043-dmaengine-apple-sio-quiesce-submission-before-draini.patch b/kernel/patches/drivers/soc-apple/0043-dmaengine-apple-sio-quiesce-submission-before-draini.patch new file mode 100644 index 00000000..71823de2 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0043-dmaengine-apple-sio-quiesce-submission-before-draini.patch @@ -0,0 +1,29 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:37:56 +0100 +Subject: [PATCH] dmaengine: apple-sio: quiesce submission before draining + callbacks + +Assisted-by: LLM +--- + drivers/dma/apple-sio-dma.c | 7 +++++++ + 1 file changed, 7 insertions(+) + +diff --git a/drivers/dma/apple-sio-dma.c b/drivers/dma/apple-sio-dma.c +index aa304dc66..33a7aa430 100644 +--- a/drivers/dma/apple-sio-dma.c ++++ b/drivers/dma/apple-sio-dma.c +@@ -478,6 +478,13 @@ static void sio_dma_stop_work(struct work_struct *work) + bool busy, issued; + int ret; + ++ /* ++ * A submission already outside vc.lock can still publish a request or ++ * roll back its block after an allocation failure. Quiesce it before ++ * draining callbacks and releasing the active descriptor. ++ */ ++ cancel_work_sync(&chan->submit_work); ++ + spin_lock_irqsave(&chan->vc.lock, flags); + busy = chan->inflight; + spin_unlock_irqrestore(&chan->vc.lock, flags); diff --git a/kernel/patches/drivers/soc-apple/0044-soc-apple-admit-T8011-speaker-DMA-endpoint.patch b/kernel/patches/drivers/soc-apple/0044-soc-apple-admit-T8011-speaker-DMA-endpoint.patch new file mode 100644 index 00000000..873dca4d --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0044-soc-apple-admit-T8011-speaker-DMA-endpoint.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 15:57:03 +0100 +Subject: [PATCH] soc: apple: admit T8011 speaker DMA endpoint + +The J120 MCA2 describes SmartIO transmit endpoint 0x2c. Admit it alongside the existing headphone and microphone endpoints. + +Assisted-by: LLM +--- + drivers/soc/apple/apple-sio-core.c | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/drivers/soc/apple/apple-sio-core.c b/drivers/soc/apple/apple-sio-core.c +index b7a968293..f4caefda8 100644 +--- a/drivers/soc/apple/apple-sio-core.c ++++ b/drivers/soc/apple/apple-sio-core.c +@@ -1187,8 +1187,9 @@ static const struct apple_sio_hw apple_sio_t7000_hw = { + .num_dma_ranges = ARRAY_SIZE(apple_sio_t7000_dma_ranges), + }; + +-/* J120 MCA4 transmit and PDM receive. */ ++/* J120 ADT: MCA2 speaker TX, MCA4 headphone TX and PDM microphone RX. */ + static const struct apple_sio_dma_range apple_sio_t8011_dma_ranges[] = { ++ { 0x2c, 0x2c }, + { 0x30, 0x30 }, + { 0x5b, 0x5b }, + }; diff --git a/kernel/patches/drivers/soc-apple/0045-soc-apple-protect-pending-SmartIO-requests-in-IRQ-co.patch b/kernel/patches/drivers/soc-apple/0045-soc-apple-protect-pending-SmartIO-requests-in-IRQ-co.patch new file mode 100644 index 00000000..d02a50c6 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0045-soc-apple-protect-pending-SmartIO-requests-in-IRQ-co.patch @@ -0,0 +1,52 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:37:56 +0100 +Subject: [PATCH] soc: apple: protect pending SmartIO requests in IRQ context + and expose MCA2 RX + +Assisted-by: LLM +--- + drivers/soc/apple/apple-sio-core.c | 15 +++++++++++---- + 1 file changed, 11 insertions(+), 4 deletions(-) + +diff --git a/drivers/soc/apple/apple-sio-core.c b/drivers/soc/apple/apple-sio-core.c +index f4caefda8..cd9f434f1 100644 +--- a/drivers/soc/apple/apple-sio-core.c ++++ b/drivers/soc/apple/apple-sio-core.c +@@ -563,7 +563,14 @@ apple_sio_request_async_common(struct apple_sio *sio, u8 endpoint, u8 opcode, + request->status = -EINPROGRESS; + request->active = true; + +- ret = xa_insert(&sio->pending, request->key, request, gfp); ++ /* Setup replies submit requests from hard IRQ context. */ ++ if (atomic) { ++ xa_lock_irqsave(&sio->pending, flags); ++ ret = __xa_insert(&sio->pending, request->key, request, gfp); ++ xa_unlock_irqrestore(&sio->pending, flags); ++ } else { ++ ret = xa_insert_irq(&sio->pending, request->key, request, gfp); ++ } + if (ret) { + apple_sio_tag_free(sio, endpoint, tag); + apple_sio_async_put(request); +@@ -1016,7 +1023,7 @@ static int apple_sio_probe(struct platform_device *pdev) + mutex_init(&sio->tx_lock); + spin_lock_init(&sio->tx_hw_lock); + spin_lock_init(&sio->tag_lock); +- xa_init(&sio->pending); ++ xa_init_flags(&sio->pending, XA_FLAGS_LOCK_IRQ); + spin_lock_init(&sio->desc0_lock); + platform_set_drvdata(pdev, sio); + +@@ -1187,9 +1194,9 @@ static const struct apple_sio_hw apple_sio_t7000_hw = { + .num_dma_ranges = ARRAY_SIZE(apple_sio_t7000_dma_ranges), + }; + +-/* J120 ADT: MCA2 speaker TX, MCA4 headphone TX and PDM microphone RX. */ ++/* J120 MCA2 transmit/receive, MCA4 transmit and PDM receive. */ + static const struct apple_sio_dma_range apple_sio_t8011_dma_ranges[] = { +- { 0x2c, 0x2c }, ++ { 0x2c, 0x2d }, + { 0x30, 0x30 }, + { 0x5b, 0x5b }, + }; diff --git a/kernel/patches/drivers/soc-apple/0046-soc-apple-balance-mailbox-TX-IRQ-across-senders-and-.patch b/kernel/patches/drivers/soc-apple/0046-soc-apple-balance-mailbox-TX-IRQ-across-senders-and-.patch new file mode 100644 index 00000000..65b79e15 --- /dev/null +++ b/kernel/patches/drivers/soc-apple/0046-soc-apple-balance-mailbox-TX-IRQ-across-senders-and-.patch @@ -0,0 +1,136 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 20:40:00 +0100 +Subject: [PATCH] soc: apple: balance mailbox TX IRQ across senders and + timeouts + +Serialize sleepable senders that share the TX completion. Disable and drain the IRQ on timeout or interruption before another sender can arm it. + +Assisted-by: LLM +--- + drivers/soc/apple/mailbox.c | 53 ++++++++++++++++++++++++++++++------- + drivers/soc/apple/mailbox.h | 4 +++ + 2 files changed, 47 insertions(+), 10 deletions(-) + +diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c +index 16be0dbf5..a6521e1c3 100644 +--- a/drivers/soc/apple/mailbox.c ++++ b/drivers/soc/apple/mailbox.c +@@ -139,8 +139,18 @@ struct apple_mbox_hw { + unsigned int irq_bit_send_empty; + }; + +-int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, +- bool atomic) ++static void apple_mbox_disarm_tx_irq(struct apple_mbox *mbox) ++{ ++ lockdep_assert_held(&mbox->tx_lock); ++ ++ if (mbox->tx_irq_armed) { ++ disable_irq_nosync(mbox->irq_send_empty); ++ mbox->tx_irq_armed = false; ++ } ++} ++ ++static int apple_mbox_send_locked(struct apple_mbox *mbox, ++ const struct apple_mbox_msg msg, bool atomic) + { + unsigned long flags; + int ret; +@@ -182,19 +192,22 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, + writel_relaxed(mbox->hw->irq_bit_send_empty, + mbox->regs + mbox->hw->irq_ack); + } +- enable_irq(mbox->irq_send_empty); + reinit_completion(&mbox->tx_empty); ++ mbox->tx_irq_armed = true; ++ enable_irq(mbox->irq_send_empty); + spin_unlock_irqrestore(&mbox->tx_lock, flags); + + t = wait_for_completion_interruptible_timeout( + &mbox->tx_empty, + msecs_to_jiffies(APPLE_MBOX_TX_TIMEOUT)); +- if (t < 0) +- return t; +- else if (t == 0) +- return -ETIMEDOUT; +- + spin_lock_irqsave(&mbox->tx_lock, flags); ++ if (t <= 0) { ++ apple_mbox_disarm_tx_irq(mbox); ++ spin_unlock_irqrestore(&mbox->tx_lock, flags); ++ /* Drain a handler already dispatched before the disable. */ ++ synchronize_irq(mbox->irq_send_empty); ++ return t < 0 ? t : -ETIMEDOUT; ++ } + mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); + } + +@@ -212,6 +225,23 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, + + return 0; + } ++ ++int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, ++ bool atomic) ++{ ++ int ret; ++ ++ if (atomic) ++ return apple_mbox_send_locked(mbox, msg, true); ++ ++ ret = mutex_lock_interruptible(&mbox->tx_mutex); ++ if (ret) ++ return ret; ++ ret = apple_mbox_send_locked(mbox, msg, false); ++ mutex_unlock(&mbox->tx_mutex); ++ ++ return ret; ++} + EXPORT_SYMBOL(apple_mbox_send); + + static irqreturn_t apple_mbox_send_empty_irq(int irq, void *data) +@@ -226,8 +256,10 @@ static irqreturn_t apple_mbox_send_empty_irq(int irq, void *data) + * it at the main controller again. + */ + spin_lock(&mbox->tx_lock); +- disable_irq_nosync(mbox->irq_send_empty); +- complete(&mbox->tx_empty); ++ if (mbox->tx_irq_armed) { ++ apple_mbox_disarm_tx_irq(mbox); ++ complete(&mbox->tx_empty); ++ } + spin_unlock(&mbox->tx_lock); + + return IRQ_HANDLED; +@@ -464,6 +496,7 @@ static int apple_mbox_probe(struct platform_device *pdev) + + spin_lock_init(&mbox->rx_lock); + spin_lock_init(&mbox->tx_lock); ++ mutex_init(&mbox->tx_mutex); + init_completion(&mbox->tx_empty); + + irqname = devm_kasprintf(dev, GFP_KERNEL, "%s-recv", dev_name(dev)); +diff --git a/drivers/soc/apple/mailbox.h b/drivers/soc/apple/mailbox.h +index a65a45f9a..4f7442f0f 100644 +--- a/drivers/soc/apple/mailbox.h ++++ b/drivers/soc/apple/mailbox.h +@@ -9,6 +9,7 @@ + #define _APPLE_MAILBOX_H_ + + #include ++#include + #include + + /* encodes a single 96bit message sent over the single channel */ +@@ -29,7 +30,10 @@ struct apple_mbox { + spinlock_t rx_lock; + spinlock_t tx_lock; + ++ /* Only one sleepable sender may own the TX completion. */ ++ struct mutex tx_mutex; + struct completion tx_empty; ++ bool tx_irq_armed; /* protected by tx_lock */ + + /** Receive callback for incoming messages */ + void (*rx)(struct apple_mbox *mbox, struct apple_mbox_msg msg, void *cookie); diff --git a/kernel/patches/drivers/sound/0028-ASoC-dt-bindings-apple-describe-the-T8011-PDM-contro.patch b/kernel/patches/drivers/sound/0028-ASoC-dt-bindings-apple-describe-the-T8011-PDM-contro.patch new file mode 100644 index 00000000..fa38a97f --- /dev/null +++ b/kernel/patches/drivers/sound/0028-ASoC-dt-bindings-apple-describe-the-T8011-PDM-contro.patch @@ -0,0 +1,45 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:16:24 +0100 +Subject: [PATCH] ASoC: dt-bindings: apple: describe the T8011 PDM controller + +The A10X PDM controller uses the same register layout with different SmartIO DMA configuration. Give it a separate compatible to select the DMA data. + +Assisted-by: LLM +--- + .../devicetree/bindings/sound/apple,t8010-pdm.yaml | 9 ++++++--- + 1 file changed, 6 insertions(+), 3 deletions(-) + +diff --git a/Documentation/devicetree/bindings/sound/apple,t8010-pdm.yaml b/Documentation/devicetree/bindings/sound/apple,t8010-pdm.yaml +index 4a311d690..93928c249 100644 +--- a/Documentation/devicetree/bindings/sound/apple,t8010-pdm.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,t8010-pdm.yaml +@@ -4,14 +4,15 @@ + $id: http://devicetree.org/schemas/sound/apple,t8010-pdm.yaml# + $schema: http://devicetree.org/meta-schemas/core.yaml# + +-title: Apple T8010 PDM microphone controller ++title: Apple T8010 and T8011 PDM microphone controller + + maintainers: + - Henrik Klee + + description: + The PDM microphone controller of the Apple A10 records the built-in +- PDM microphones. Each microphone has a HiFi decimator that filters its ++ PDM microphones. T8011 uses a different SmartIO FIFO and trigger pair. ++ Each microphone has a HiFi decimator that filters its + bit stream down to PCM; the controller hands the samples to SmartIO + DMA. The PDM clock comes from the Always-On Processor's audio service. + +@@ -20,7 +21,9 @@ allOf: + + properties: + compatible: +- const: apple,t8010-pdm ++ enum: ++ - apple,t8010-pdm ++ - apple,t8011-pdm + + reg: + minItems: 2 diff --git a/kernel/patches/drivers/sound/0029-ASoC-apple-select-PDM-DMA-configuration-for-T8011.patch b/kernel/patches/drivers/sound/0029-ASoC-apple-select-PDM-DMA-configuration-for-T8011.patch new file mode 100644 index 00000000..30accdd9 --- /dev/null +++ b/kernel/patches/drivers/sound/0029-ASoC-apple-select-PDM-DMA-configuration-for-T8011.patch @@ -0,0 +1,74 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:16:24 +0100 +Subject: [PATCH] ASoC: apple: select PDM DMA configuration for T8011 + +Select the FIFO and trigger through compatible match data. T8011 stereo capture uses FIFO 0x600 and trigger 0xac on SmartIO channel 0x5b. Preserve the T8010 values for existing users. + +Assisted-by: LLM +--- + sound/soc/apple/t8010-pdm.c | 27 ++++++++++++++++++++++++--- + 1 file changed, 24 insertions(+), 3 deletions(-) + +diff --git a/sound/soc/apple/t8010-pdm.c b/sound/soc/apple/t8010-pdm.c +index 8e00762de..0b8b41299 100644 +--- a/sound/soc/apple/t8010-pdm.c ++++ b/sound/soc/apple/t8010-pdm.c +@@ -209,8 +209,14 @@ static const u32 t8010_pdm_dec_timing1[] = { + #define PDM_SIO_FIFO 0x398 + #define PDM_SIO_TRIGGER 0x190 + ++struct t8010_pdm_dma_hw { ++ u32 fifo; ++ u32 trigger; ++}; ++ + struct t8010_pdm { + struct device *dev; ++ const struct t8010_pdm_dma_hw *dma_hw; + void __iomem *base; + void __iomem *dec[PDM_MAX_MICS]; + unsigned int num_mics; +@@ -573,8 +579,8 @@ static int t8010_pdm_prepare_slave_config(struct snd_pcm_substream *substream, + */ + pdm->sio_cfg = (struct apple_sio_dma_config) { + .xfer = PDM_SIO_XFER16, +- .fifo = PDM_SIO_FIFO, +- .trigger = PDM_SIO_TRIGGER, ++ .fifo = pdm->dma_hw->fifo, ++ .trigger = pdm->dma_hw->trigger, + .limit = 2 * round_up(params_rate(params) * + params_channels(params) / 1000, 4), + }; +@@ -640,6 +646,9 @@ static int t8010_pdm_probe(struct platform_device *pdev) + if (!pdm) + return -ENOMEM; + pdm->dev = dev; ++ pdm->dma_hw = device_get_match_data(dev); ++ if (!pdm->dma_hw) ++ return -ENODEV; + pdm->gain = PDM_GAIN_DEFAULT; + spin_lock_init(&pdm->lock); + platform_set_drvdata(pdev, pdm); +@@ -699,8 +708,20 @@ static int t8010_pdm_probe(struct platform_device *pdev) + return 0; + } + ++static const struct t8010_pdm_dma_hw t8010_pdm_dma_hw = { ++ .fifo = PDM_SIO_FIFO, ++ .trigger = PDM_SIO_TRIGGER, ++}; ++ ++/* J120 PDM 16-bit DMA record, channel 0x5b. */ ++static const struct t8010_pdm_dma_hw t8011_pdm_dma_hw = { ++ .fifo = 0x600, ++ .trigger = 0xac, ++}; ++ + static const struct of_device_id t8010_pdm_of_match[] = { +- { .compatible = "apple,t8010-pdm" }, ++ { .compatible = "apple,t8010-pdm", .data = &t8010_pdm_dma_hw }, ++ { .compatible = "apple,t8011-pdm", .data = &t8011_pdm_dma_hw }, + {} + }; + MODULE_DEVICE_TABLE(of, t8010_pdm_of_match); diff --git a/kernel/patches/drivers/sound/0030-ASoC-apple-use-the-T8011-speaker-slot-width.patch b/kernel/patches/drivers/sound/0030-ASoC-apple-use-the-T8011-speaker-slot-width.patch new file mode 100644 index 00000000..60e2181d --- /dev/null +++ b/kernel/patches/drivers/sound/0030-ASoC-apple-use-the-T8011-speaker-slot-width.patch @@ -0,0 +1,98 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 16:25:12 +0100 +Subject: [PATCH] ASoC: apple: use the T8011 speaker slot width + +J120 describes eight slots in a 256-clock frame with 16-bit samples. Keep FIFO access tied to the PCM sample width and use the wider slots for frame timing. + +Assisted-by: LLM +--- + .../devicetree/bindings/sound/apple,s8000-mca.yaml | 7 +++++-- + sound/soc/apple/s8000-mca.c | 10 ++++++++-- + 2 files changed, 13 insertions(+), 4 deletions(-) + +diff --git a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +index fcadf6dbc..501c31030 100644 +--- a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +@@ -21,7 +21,8 @@ description: | + 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. ++ NCO channel running at twice the bit clock. The T8011 speaker link uses wider ++ serial slots while keeping 16-bit PCM. + + allOf: + - $ref: dai-common.yaml# +@@ -32,6 +33,7 @@ allOf: + - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s ++ - apple,t8011-mca + then: + properties: + dmas: +@@ -53,11 +55,12 @@ properties: + - apple,t7001-mca + - apple,t8010-mca + - apple,t8010-mca-i2s ++ - apple,t8011-mca + + clocks: + maxItems: 1 + description: +- AP NCO channel supplying the bitclock (T7001, T8010). On T7001 the ++ AP NCO channel supplying the bitclock (T7001, T8010 and T8011). On T7001 the + MCA divides it by two. + + clock-names: +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index dc8cbcc55..7afaba459 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -286,6 +286,7 @@ struct s8000_mca { + struct device *dev; + const struct s8000_mca_hw *hw; + const struct s8000_mca_regs *regs; ++ unsigned int slot_width; + void __iomem *base; + void __iomem *mclk_reg; + struct clk_hw mclk_hw; +@@ -507,7 +508,8 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? &mca->dma_tx : + &mca->dma_rx; + unsigned int bits = params_width(params); +- unsigned int slot = params_physical_width(params); ++ unsigned int pcm_width = params_physical_width(params); ++ unsigned int slot = mca->slot_width ?: pcm_width; + unsigned int channels = params_channels(params); + unsigned int slots = mca->hw->slots, depth; + unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots; +@@ -568,7 +570,7 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + mca->frame |= MCA_FRAME_MASTER; + } + +- dma->addr_width = slot == 16 ? DMA_SLAVE_BUSWIDTH_2_BYTES : ++ dma->addr_width = pcm_width == 16 ? DMA_SLAVE_BUSWIDTH_2_BYTES : + DMA_SLAVE_BUSWIDTH_4_BYTES; + /* informational: the SmartIO limit comes from the shim record */ + dma->maxburst = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? depth : +@@ -1185,6 +1187,9 @@ static int s8000_mca_probe(struct platform_device *pdev) + if (!mca->hw) + return -ENODEV; + mca->regs = mca->hw->regs; ++ /* J120 iisConfig spans 256 clocks over eight slots with S16 samples. */ ++ if (of_device_is_compatible(dev->of_node, "apple,t8011-mca")) ++ mca->slot_width = 32; + spin_lock_init(&mca->hw_lock); + mca->irq_mask = MCA_IRQ_ALL; + platform_set_drvdata(pdev, mca); +@@ -1391,6 +1396,7 @@ static const struct of_device_id s8000_mca_of_match[] = { + { .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 }, ++ { .compatible = "apple,t8011-mca", .data = &t8010_mca_hw }, + { } + }; + MODULE_DEVICE_TABLE(of, s8000_mca_of_match); diff --git a/kernel/patches/drivers/sound/0031-ASoC-apple-pad-the-T8011-speaker-frame-after-its-slo.patch b/kernel/patches/drivers/sound/0031-ASoC-apple-pad-the-T8011-speaker-frame-after-its-slo.patch new file mode 100644 index 00000000..090729ed --- /dev/null +++ b/kernel/patches/drivers/sound/0031-ASoC-apple-pad-the-T8011-speaker-frame-after-its-slo.patch @@ -0,0 +1,76 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 16:28:50 +0100 +Subject: [PATCH] ASoC: apple: pad the T8011 speaker frame after its slots + +The native iisConfig helper derives 16-bit slots from the sample widths and writes the frame remainder to MCA_PAD. Preserve that slot alignment while retaining the 256-clock frame. + +Assisted-by: LLM +--- + .../devicetree/bindings/sound/apple,s8000-mca.yaml | 4 ++-- + sound/soc/apple/s8000-mca.c | 13 ++++++------- + 2 files changed, 8 insertions(+), 9 deletions(-) + +diff --git a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +index 501c31030..406059c65 100644 +--- a/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml ++++ b/Documentation/devicetree/bindings/sound/apple,s8000-mca.yaml +@@ -21,8 +21,8 @@ description: | + 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. The T8011 speaker link uses wider +- serial slots while keeping 16-bit PCM. ++ NCO channel running at twice the bit clock. The T8011 speaker link appends ++ padding clocks after its 16-bit slots. + + allOf: + - $ref: dai-common.yaml# +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index 7afaba459..423e2ee32 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -286,7 +286,7 @@ struct s8000_mca { + struct device *dev; + const struct s8000_mca_hw *hw; + const struct s8000_mca_regs *regs; +- unsigned int slot_width; ++ unsigned int frame_padding; + void __iomem *base; + void __iomem *mclk_reg; + struct clk_hw mclk_hw; +@@ -508,11 +508,10 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? &mca->dma_tx : + &mca->dma_rx; + unsigned int bits = params_width(params); +- unsigned int pcm_width = params_physical_width(params); +- unsigned int slot = mca->slot_width ?: pcm_width; ++ unsigned int slot = params_physical_width(params); + unsigned int channels = params_channels(params); + unsigned int slots = mca->hw->slots, depth; +- unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots; ++ unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots + mca->frame_padding; + unsigned int sync_bits = mca->hw->sync_bits ?: frame_bits / 2; + u32 width_code; + +@@ -570,7 +569,7 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + mca->frame |= MCA_FRAME_MASTER; + } + +- dma->addr_width = pcm_width == 16 ? DMA_SLAVE_BUSWIDTH_2_BYTES : ++ dma->addr_width = slot == 16 ? DMA_SLAVE_BUSWIDTH_2_BYTES : + DMA_SLAVE_BUSWIDTH_4_BYTES; + /* informational: the SmartIO limit comes from the shim record */ + dma->maxburst = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? depth : +@@ -1187,9 +1186,9 @@ static int s8000_mca_probe(struct platform_device *pdev) + if (!mca->hw) + return -ENODEV; + mca->regs = mca->hw->regs; +- /* J120 iisConfig spans 256 clocks over eight slots with S16 samples. */ ++ /* J120 iisConfig uses eight 16-bit slots and 128 trailing clocks. */ + if (of_device_is_compatible(dev->of_node, "apple,t8011-mca")) +- mca->slot_width = 32; ++ mca->frame_padding = 128; + spin_lock_init(&mca->hw_lock); + mca->irq_mask = MCA_IRQ_ALL; + platform_set_drvdata(pdev, mca); diff --git a/kernel/patches/drivers/sound/0032-ASoC-apple-align-T8011-speaker-DMA-depth-to-PCM-fram.patch b/kernel/patches/drivers/sound/0032-ASoC-apple-align-T8011-speaker-DMA-depth-to-PCM-fram.patch new file mode 100644 index 00000000..f3ae93be --- /dev/null +++ b/kernel/patches/drivers/sound/0032-ASoC-apple-align-T8011-speaker-DMA-depth-to-PCM-fram.patch @@ -0,0 +1,119 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 17:39:31 +0100 +Subject: [PATCH] ASoC: apple: align T8011 speaker DMA depth to PCM frames + +Use the J120 firmware FIFO and trigger sizes for T8011 MCA2. Limit the +TX depth to whole interleaved frames so the 204-byte FIFO results in +a 200-byte request for four 16-bit channels. + +A RAM probe using this configuration primed and drained the stream. +The unaligned request timed out before enabling the amplifier. + +Assisted-by: LLM +--- + sound/soc/apple/s8000-mca.c | 40 ++++++++++++++++++++++++++++++------- + 1 file changed, 33 insertions(+), 7 deletions(-) + +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index 423e2ee32..43b453a53 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -280,13 +280,13 @@ struct s8000_mca_hw { + u32 sio_timeout; + u32 sio_fifo; + u32 sio_trigger; ++ bool align_sio_tx_depth; + }; + + struct s8000_mca { + struct device *dev; + const struct s8000_mca_hw *hw; + const struct s8000_mca_regs *regs; +- unsigned int frame_padding; + void __iomem *base; + void __iomem *mclk_reg; + struct clk_hw mclk_hw; +@@ -511,7 +511,7 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + unsigned int slot = params_physical_width(params); + unsigned int channels = params_channels(params); + unsigned int slots = mca->hw->slots, depth; +- unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots + mca->frame_padding; ++ unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots; + unsigned int sync_bits = mca->hw->sync_bits ?: frame_bits / 2; + u32 width_code; + +@@ -951,6 +951,7 @@ static int mca_prepare_slave_config(struct snd_pcm_substream *substream, + const struct s8000_mca_hw *hw = mca->hw; + unsigned int bytes = params_physical_width(params) / 8; + unsigned int per_ms; ++ u32 limit; + int ret; + + ret = snd_dmaengine_pcm_prepare_slave_config(substream, params, sc); +@@ -966,12 +967,17 @@ static int mca_prepare_slave_config(struct snd_pcm_substream *substream, + */ + per_ms = round_up(params_rate(params) * params_channels(params) / 1000, + 4); ++ limit = bytes * per_ms; ++ if (hw->align_sio_tx_depth && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ++ limit = rounddown(min(limit, hw->sio_fifo), ++ bytes * params_channels(params)); ++ + *cfg = (struct apple_sio_dma_config) { + .xfer = bytes == 2 ? hw->sio_xfer16 : hw->sio_xfer32, + .timeout = hw->sio_timeout, + .fifo = hw->sio_fifo, + .trigger = hw->sio_trigger, +- .limit = bytes * per_ms, ++ .limit = limit, + }; + sc->peripheral_config = cfg; + sc->peripheral_size = sizeof(*cfg); +@@ -1186,9 +1192,6 @@ static int s8000_mca_probe(struct platform_device *pdev) + if (!mca->hw) + return -ENODEV; + mca->regs = mca->hw->regs; +- /* J120 iisConfig uses eight 16-bit slots and 128 trailing clocks. */ +- if (of_device_is_compatible(dev->of_node, "apple,t8011-mca")) +- mca->frame_padding = 128; + spin_lock_init(&mca->hw_lock); + mca->irq_mask = MCA_IRQ_ALL; + platform_set_drvdata(pdev, mca); +@@ -1390,12 +1393,35 @@ static const struct s8000_mca_hw t7001_mca_hw = { + .sio_trigger = 0xac, + }; + ++/* J120 MCA2 uses eight 16-bit slots followed by 128 padding clocks. */ ++static const struct s8000_mca_hw t8011_mca_hw = { ++ .version = 5, ++ .regs = &mca_v4_regs, ++ .clock_provider = true, ++ .dai_format = SND_SOC_DAIFMT_DSP_A, ++ .channels = 4, ++ .slots = 8, ++ .frame_bits = 256, ++ .tx_slots = 0x0f, ++ .tx_cfg = 0x133, ++ .rx_cfg = 0x137, ++ .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ .sync_bits = 1, ++ .stream_irqs = MCA_IRQ_FRAME_ERROR, ++ .attenuation = 4, ++ .sio_xfer16 = 0x21, ++ .sio_xfer32 = 0x22, ++ .sio_fifo = 0xcc, ++ .sio_trigger = 0xac, ++ .align_sio_tx_depth = true, ++}; ++ + 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 }, +- { .compatible = "apple,t8011-mca", .data = &t8010_mca_hw }, ++ { .compatible = "apple,t8011-mca", .data = &t8011_mca_hw }, + { } + }; + MODULE_DEVICE_TABLE(of, s8000_mca_of_match); diff --git a/kernel/patches/drivers/sound/0033-ASoC-apple-drive-the-four-J120-speaker-amplifiers.patch b/kernel/patches/drivers/sound/0033-ASoC-apple-drive-the-four-J120-speaker-amplifiers.patch new file mode 100644 index 00000000..7735b87b --- /dev/null +++ b/kernel/patches/drivers/sound/0033-ASoC-apple-drive-the-four-J120-speaker-amplifiers.patch @@ -0,0 +1,313 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:37:23 +0100 +Subject: [PATCH] ASoC: apple: drive the four J120 speaker amplifiers + +Assisted-by: LLM +--- + sound/soc/apple/Kconfig | 7 + + sound/soc/apple/Makefile | 1 + + sound/soc/apple/j120-speaker-amps.c | 269 ++++++++++++++++++++++++++++ + 3 files changed, 277 insertions(+) + create mode 100644 sound/soc/apple/j120-speaker-amps.c + +diff --git a/sound/soc/apple/Kconfig b/sound/soc/apple/Kconfig +index 7b4d7a85b..d0dd6f15f 100644 +--- a/sound/soc/apple/Kconfig ++++ b/sound/soc/apple/Kconfig +@@ -35,4 +35,11 @@ config SND_SOC_APPLE_T8010_PDM + controller of the Apple A10, which records the built-in + microphones of the iPad 6 and iPad 7. + ++config SND_SOC_APPLE_J120_SPEAKERS ++ tristate "Apple J120 built-in speaker amplifiers" ++ depends on I2C && GPIOLIB && OF ++ select REGMAP_I2C ++ help ++ Drive the four MAX98723 speaker amplifiers on the J120 iPad Pro. ++ + endmenu +diff --git a/sound/soc/apple/Makefile b/sound/soc/apple/Makefile +index 062309b6b..04529f3b8 100644 +--- a/sound/soc/apple/Makefile ++++ b/sound/soc/apple/Makefile +@@ -6,3 +6,4 @@ snd-soc-apple-t8010-pdm-y := t8010-pdm.o + obj-$(CONFIG_SND_SOC_APPLE_MCA) += snd-soc-apple-mca.o + obj-$(CONFIG_SND_SOC_APPLE_S8000_MCA) += snd-soc-apple-s8000-mca.o + obj-$(CONFIG_SND_SOC_APPLE_T8010_PDM) += snd-soc-apple-t8010-pdm.o ++obj-$(CONFIG_SND_SOC_APPLE_J120_SPEAKERS) += j120-speaker-amps.o +diff --git a/sound/soc/apple/j120-speaker-amps.c b/sound/soc/apple/j120-speaker-amps.c +new file mode 100644 +index 000000000..63243030e +--- /dev/null ++++ b/sound/soc/apple/j120-speaker-amps.c +@@ -0,0 +1,269 @@ ++// SPDX-License-Identifier: GPL-2.0-only ++/* J120 uses four MAX98723 amplifiers sharing one reset line. */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++struct speaker_bank { ++ struct device *dev; ++ struct gpio_desc *reset; ++ struct regmap *amps[4]; ++ struct mutex lock; ++ unsigned int users; ++ unsigned long enabled_mask; ++ bool faulted; ++}; ++ ++static const struct regmap_config amp_registers = { ++ .reg_bits = 16, ++ .val_bits = 8, ++ .reg_format_endian = REGMAP_ENDIAN_BIG, ++ .max_register = 0x1ff, ++}; ++ ++static int configure_amp(struct regmap *amp, unsigned int slot) ++{ ++ unsigned int enabled, value, i; ++ unsigned int feedback = 3 << (2 * slot); ++ const struct reg_sequence serial[] = { ++ { 0x3a, 0 }, /* Keep the speaker muted. */ ++ { 0x18, BIT(slot) }, /* PCM input */ ++ { 0x21, 0x65 }, { 0x22, 0 }, { 0x25, 0x88 }, ++ { 0x1c, 0xff ^ feedback }, { 0x1d, 0xff }, ++ { 0x1a, feedback }, { 0x1b, 0 }, ++ { 0x1e, 0x10 + 0x22 * slot }, { 0x3e, 3 }, ++ /* J120 speaker-config from the board device tree. */ ++ { 0x28, 0xf ^ BIT(slot) }, { 0x2b, BIT(slot) }, ++ { 0x2e, 2 }, { 0x31, 2 }, { 0x37, 0x33 }, { 0x3f, 0xf7 }, ++ }; ++ int ret; ++ ++ /* Slots 0 and 1 are the connector-side amplifiers. */ ++ if (slot < 2) { ++ ret = regmap_write(amp, 0x100, 1); ++ if (ret) ++ return dev_err_probe(regmap_get_device(amp), ret, ++ "software reset write failed\n"); ++ msleep(12); ++ } ++ ret = regmap_read(amp, 0xff, &enabled); ++ if (ret) ++ return dev_err_probe(regmap_get_device(amp), ret, ++ "initial global enable read failed\n"); ++ if (enabled) ++ return -EBUSY; ++ ++ ret = regmap_multi_reg_write(amp, serial, ARRAY_SIZE(serial)); ++ if (ret) ++ return ret; ++ ret = regmap_update_bits(amp, 0x26, 0xcf, slot); ++ if (ret) ++ return ret; ++ ret = regmap_update_bits(amp, 0x23, 0x0f, 8); ++ if (ret) ++ return ret; ++ ret = regmap_update_bits(amp, 0x24, 0x0f, 8); ++ if (ret) ++ return ret; ++ ret = regmap_update_bits(amp, 0x42, 0x3f, 0x28); ++ if (ret) ++ return ret; ++ for (i = 0; i < ARRAY_SIZE(serial); i++) { ++ ret = regmap_read(amp, serial[i].reg, &value); ++ if (ret) ++ return ret; ++ if (value != serial[i].def) ++ return -EIO; ++ } ++ ret = regmap_read(amp, 0x42, &value); ++ if (ret) ++ return ret; ++ return (value & 0x3f) == 0x28 ? 0 : -EIO; ++} ++ ++static int bank_startup(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) ++{ ++ struct speaker_bank *bank = dev_get_drvdata(dai->dev); ++ unsigned int i; ++ int ret; ++ ++ guard(mutex)(&bank->lock); ++ if (bank->users && bank->faulted) ++ return -EIO; ++ if (!bank->users) { ++ bank->faulted = false; ++ gpiod_set_value_cansleep(bank->reset, 0); ++ msleep(100); ++ for (i = 0; i < ARRAY_SIZE(bank->amps); i++) { ++ ret = configure_amp(bank->amps[i], i); ++ if (ret) { ++ gpiod_set_value_cansleep(bank->reset, 1); ++ dev_err(bank->dev, "amp %u: startup failed: %d\n", i, ret); ++ return ret; ++ } ++ } ++ } ++ bank->users++; ++ return 0; ++} ++ ++static int set_output(struct speaker_bank *bank, unsigned int slot, bool on) ++{ ++ struct regmap *amp = bank->amps[slot]; ++ const unsigned int regs[] = { on ? 0x3a : 0xff, on ? 0xff : 0x3a }; ++ unsigned int i, value; ++ int ret; ++ ++ for (i = 0; i < ARRAY_SIZE(regs); i++) { ++ ret = regmap_write(amp, regs[i], on); ++ if (ret) ++ goto reset; ++ /* Allow global enable to settle before readback. */ ++ if (on && regs[i] == 0xff) ++ usleep_range(2000, 2500); ++ ret = regmap_read(amp, regs[i], &value); ++ if (ret) ++ goto reset; ++ if ((value & 1) != on) { ++ ret = -EIO; ++ goto reset; ++ } ++ } ++ __assign_bit(slot, &bank->enabled_mask, on); ++ return 0; ++ ++reset: ++ gpiod_set_value_cansleep(bank->reset, 1); ++ bank->faulted = true; ++ bank->enabled_mask = 0; ++ dev_err(bank->dev, "amp %u: output transition failed, reset asserted: %d\n", ++ slot, ret); ++ return ret; ++} ++ ++static int mute_outputs(struct speaker_bank *bank) ++{ ++ int ret; ++ ++ while (bank->enabled_mask) { ++ ret = set_output(bank, __ffs(bank->enabled_mask), false); ++ if (ret) ++ return ret; ++ } ++ return 0; ++} ++ ++static int bank_mute_stream(struct snd_soc_dai *dai, int mute, int direction) ++{ ++ struct speaker_bank *bank = dev_get_drvdata(dai->dev); ++ ++ unsigned int slot; ++ int ret; ++ ++ guard(mutex)(&bank->lock); ++ if (mute) ++ return mute_outputs(bank); ++ if (bank->faulted) ++ return -EIO; ++ for (slot = 0; slot < ARRAY_SIZE(bank->amps); slot++) { ++ if (test_bit(slot, &bank->enabled_mask)) ++ continue; ++ ret = set_output(bank, slot, true); ++ if (ret) ++ return ret; ++ } ++ return 0; ++} ++ ++static void bank_shutdown(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) ++{ ++ struct speaker_bank *bank = dev_get_drvdata(dai->dev); ++ ++ guard(mutex)(&bank->lock); ++ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ++ mute_outputs(bank); ++ if (--bank->users == 0) ++ gpiod_set_value_cansleep(bank->reset, 1); ++} ++ ++static const struct snd_soc_dai_ops bank_ops = { ++ .startup = bank_startup, ++ .shutdown = bank_shutdown, ++ .mute_stream = bank_mute_stream, ++ .no_capture_mute = 1, ++}; ++ ++static struct snd_soc_dai_driver bank_dai = { ++ .name = "max98723-bank", ++ .playback = { ++ .stream_name = "Speakers", .channels_min = 4, .channels_max = 4, ++ .rates = SNDRV_PCM_RATE_48000, .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ }, ++ .capture = { ++ .stream_name = "Feedback", .channels_min = 8, .channels_max = 8, ++ .rates = SNDRV_PCM_RATE_48000, .formats = SNDRV_PCM_FMTBIT_S16_LE, ++ }, ++ .ops = &bank_ops, ++}; ++ ++static const struct snd_soc_component_driver bank_component = { ++ .name = "j120-max98723", ++}; ++ ++static int bank_probe(struct platform_device *pdev) ++{ ++ struct device *dev = &pdev->dev; ++ struct speaker_bank *bank; ++ unsigned int i; ++ ++ bank = devm_kzalloc(dev, sizeof(*bank), GFP_KERNEL); ++ if (!bank) ++ return -ENOMEM; ++ bank->dev = dev; ++ mutex_init(&bank->lock); ++ bank->reset = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); ++ if (IS_ERR(bank->reset)) ++ return PTR_ERR(bank->reset); ++ for (i = 0; i < ARRAY_SIZE(bank->amps); i++) { ++ struct device_node *bus; ++ struct i2c_adapter *adapter; ++ struct i2c_client *amp; ++ ++ bus = of_parse_phandle(dev->of_node, "speaker-buses", i / 2); ++ if (!bus) ++ return -EINVAL; ++ adapter = of_get_i2c_adapter_by_node(bus); ++ of_node_put(bus); ++ if (!adapter) ++ return -EPROBE_DEFER; ++ amp = devm_i2c_new_dummy_device(dev, adapter, 0x31 + i % 2); ++ i2c_put_adapter(adapter); ++ if (IS_ERR(amp)) ++ return PTR_ERR(amp); ++ bank->amps[i] = devm_regmap_init_i2c(amp, &_registers); ++ if (IS_ERR(bank->amps[i])) ++ return PTR_ERR(bank->amps[i]); ++ } ++ ++ platform_set_drvdata(pdev, bank); ++ return devm_snd_soc_register_component(dev, &bank_component, &bank_dai, 1); ++} ++ ++static const struct of_device_id bank_match[] = { ++ { .compatible = "apple,j120-speaker-amplifiers" }, ++ {} ++}; ++MODULE_DEVICE_TABLE(of, bank_match); ++ ++static struct platform_driver bank_driver = { ++ .probe = bank_probe, ++ .driver = { .name = "j120-max98723", .of_match_table = bank_match }, ++}; ++module_platform_driver(bank_driver); ++MODULE_LICENSE("GPL"); ++MODULE_DESCRIPTION("J120 MAX98723 speaker amplifiers"); diff --git a/kernel/patches/drivers/sound/0034-ASoC-apple-configure-J120-speaker-playback-and-feedb.patch b/kernel/patches/drivers/sound/0034-ASoC-apple-configure-J120-speaker-playback-and-feedb.patch new file mode 100644 index 00000000..168efd1f --- /dev/null +++ b/kernel/patches/drivers/sound/0034-ASoC-apple-configure-J120-speaker-playback-and-feedb.patch @@ -0,0 +1,171 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 22:37:57 +0100 +Subject: [PATCH] ASoC: apple: configure J120 speaker playback and feedback + streams + +Assisted-by: LLM +--- + sound/soc/apple/s8000-mca.c | 54 ++++++++++++++++++++++++------------- + 1 file changed, 36 insertions(+), 18 deletions(-) + +diff --git a/sound/soc/apple/s8000-mca.c b/sound/soc/apple/s8000-mca.c +index 43b453a53..21fa7f1ad 100644 +--- a/sound/soc/apple/s8000-mca.c ++++ b/sound/soc/apple/s8000-mca.c +@@ -249,6 +249,9 @@ struct s8000_mca_hw { + * drives SCLK while TX is enabled, so TX stays enabled as well. + */ + bool clocks_at_prepare; ++ bool frame_at_prepare; ++ bool mask_stream_irqs; ++ unsigned int capture_channels; + unsigned int dai_format; /* SND_SOC_DAIFMT_* */ + unsigned int channels; + unsigned int slots; +@@ -280,7 +283,6 @@ struct s8000_mca_hw { + u32 sio_timeout; + u32 sio_fifo; + u32 sio_trigger; +- bool align_sio_tx_depth; + }; + + struct s8000_mca { +@@ -512,10 +514,13 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + unsigned int channels = params_channels(params); + unsigned int slots = mca->hw->slots, depth; + unsigned int frame_bits = mca->hw->frame_bits ?: slot * slots; ++ unsigned int expected_channels = mca->hw->channels; + unsigned int sync_bits = mca->hw->sync_bits ?: frame_bits / 2; + u32 width_code; + +- if (channels != mca->hw->channels) ++ if (substream->stream == SNDRV_PCM_STREAM_CAPTURE && mca->hw->capture_channels) ++ expected_channels = mca->hw->capture_channels; ++ if (channels != expected_channels) + return -EINVAL; + /* Qualify one clock family first; no unverified v5 capture or TDM. */ + if (mca->hw->clock_provider && params_rate(params) != 48000) +@@ -544,7 +549,7 @@ static int mca_hw_params(struct snd_pcm_substream *substream, + 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); ++ depth = mca_tx_depth(mca, params_rate(params), mca->hw->channels); + mca->tx_fifo_cfg = depth | (depth - 1) << 16; + mca->tx_slots = mca->hw->tx_slots; + mca->rx_slots = mca->hw->rx_slots; +@@ -743,14 +748,16 @@ static int mca_prepare(struct snd_pcm_substream *substream, + + spin_lock_irqsave(&mca->hw_lock, flags); + mca->prep_mask |= BIT(dir); +- mca->irq_mask &= ~(tx ? MCA_IRQ_TX_CAUSES | mca->hw->stream_irqs : +- MCA_IRQ_RX_CAUSES); ++ if (!mca->hw->mask_stream_irqs) ++ mca->irq_mask &= ~(tx ? MCA_IRQ_TX_CAUSES | mca->hw->stream_irqs : ++ MCA_IRQ_RX_CAUSES); + mca_irq_set_mask(mca, mca->irq_mask); + if (first && tx && mca->hw->clocks_at_prepare) + mca_write(mca, mca->regs->tx_cfg, mca->tx_cfg | MCA_XX_CFG_EN); + if (first) + mca_write(mca, mca->regs->frame, mca->frame | +- (mca->hw->clocks_at_prepare ? MCA_FRAME_RUN : 0)); ++ (mca->hw->clocks_at_prepare || mca->hw->frame_at_prepare ? ++ MCA_FRAME_RUN : 0)); + mca->prep_frame = mca->frame; + spin_unlock_irqrestore(&mca->hw_lock, flags); + +@@ -951,7 +958,6 @@ static int mca_prepare_slave_config(struct snd_pcm_substream *substream, + const struct s8000_mca_hw *hw = mca->hw; + unsigned int bytes = params_physical_width(params) / 8; + unsigned int per_ms; +- u32 limit; + int ret; + + ret = snd_dmaengine_pcm_prepare_slave_config(substream, params, sc); +@@ -967,18 +973,20 @@ static int mca_prepare_slave_config(struct snd_pcm_substream *substream, + */ + per_ms = round_up(params_rate(params) * params_channels(params) / 1000, + 4); +- limit = bytes * per_ms; +- if (hw->align_sio_tx_depth && substream->stream == SNDRV_PCM_STREAM_PLAYBACK) +- limit = rounddown(min(limit, hw->sio_fifo), +- bytes * params_channels(params)); +- + *cfg = (struct apple_sio_dma_config) { + .xfer = bytes == 2 ? hw->sio_xfer16 : hw->sio_xfer32, + .timeout = hw->sio_timeout, + .fifo = hw->sio_fifo, + .trigger = hw->sio_trigger, +- .limit = limit, ++ .limit = bytes * per_ms, + }; ++ if (hw->capture_channels) { ++ unsigned int max_depth = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? ++ hw->sio_fifo : hw->sio_trigger; ++ ++ cfg->limit = rounddown(min(max_depth, bytes * per_ms), ++ bytes * params_channels(params)); ++ } + sc->peripheral_config = cfg; + sc->peripheral_size = sizeof(*cfg); + return 0; +@@ -1273,6 +1281,12 @@ static int s8000_mca_probe(struct platform_device *pdev) + mca->dai_drv.playback.rates = SNDRV_PCM_RATE_48000; + if (!mca->capture) + memset(&mca->dai_drv.capture, 0, sizeof(mca->dai_drv.capture)); ++ else if (mca->hw->capture_channels) { ++ mca->dai_drv.capture.channels_min = mca->hw->capture_channels; ++ mca->dai_drv.capture.channels_max = mca->hw->capture_channels; ++ mca->dai_drv.capture.formats = mca->hw->formats; ++ mca->dai_drv.capture.rates = SNDRV_PCM_RATE_48000; ++ } + + ret = devm_snd_soc_register_component(dev, &mca_component, + &mca->dai_drv, 1); +@@ -1281,7 +1295,7 @@ static int s8000_mca_probe(struct platform_device *pdev) + + mca->pcm_hw = mca_dma_hw; + mca->pcm_hw.channels_min = mca->hw->channels; +- mca->pcm_hw.channels_max = mca->hw->channels; ++ mca->pcm_hw.channels_max = mca->hw->capture_channels ?: mca->hw->channels; + mca->pcm_hw.formats = mca->hw->formats; + mca->pcm_config = mca_dma_config; + mca->pcm_config.pcm_hardware = &mca->pcm_hw; +@@ -1400,28 +1414,32 @@ static const struct s8000_mca_hw t8011_mca_hw = { + .clock_provider = true, + .dai_format = SND_SOC_DAIFMT_DSP_A, + .channels = 4, +- .slots = 8, ++ .capture_channels = 8, ++ .rx_slots = 0xff, + .frame_bits = 256, ++ .frame_at_prepare = true, ++ .mask_stream_irqs = true, ++ .slots = 8, + .tx_slots = 0x0f, + .tx_cfg = 0x133, + .rx_cfg = 0x137, + .formats = SNDRV_PCM_FMTBIT_S16_LE, + .sync_bits = 1, + .stream_irqs = MCA_IRQ_FRAME_ERROR, +- .attenuation = 4, ++ .attenuation = 1, + .sio_xfer16 = 0x21, + .sio_xfer32 = 0x22, ++ .sio_timeout = 0, + .sio_fifo = 0xcc, + .sio_trigger = 0xac, +- .align_sio_tx_depth = true, + }; + + 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,t8011-mca", .data = &t8011_mca_hw }, + { .compatible = "apple,t8010-mca", .data = &t8010_mca_hw }, + { .compatible = "apple,t8010-mca-i2s", .data = &t8010_i2s_mca_hw }, +- { .compatible = "apple,t8011-mca", .data = &t8011_mca_hw }, + { } + }; + MODULE_DEVICE_TABLE(of, s8000_mca_of_match); diff --git a/kernel/patches/drivers/spi/0011-dt-bindings-spi-describe-T8011-PIO-status-setup.patch b/kernel/patches/drivers/spi/0011-dt-bindings-spi-describe-T8011-PIO-status-setup.patch new file mode 100644 index 00000000..f8f6b0e8 --- /dev/null +++ b/kernel/patches/drivers/spi/0011-dt-bindings-spi-describe-T8011-PIO-status-setup.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:50 +0100 +Subject: [PATCH] dt-bindings: spi: describe T8011 PIO status setup + +Allow the T8011 compatible before the T8010 and generic SPI fallbacks. Its long full-duplex PIO transfers require the native status configuration. + +Assisted-by: LLM +--- + Documentation/devicetree/bindings/spi/apple,spi.yaml | 4 +++- + 1 file changed, 3 insertions(+), 1 deletion(-) + +diff --git a/Documentation/devicetree/bindings/spi/apple,spi.yaml b/Documentation/devicetree/bindings/spi/apple,spi.yaml +index c8ed3039b..1fce58692 100644 +--- a/Documentation/devicetree/bindings/spi/apple,spi.yaml ++++ b/Documentation/devicetree/bindings/spi/apple,spi.yaml +@@ -28,7 +28,9 @@ properties: + compatible: + oneOf: + - items: +- - const: apple,t8015-spi ++ - enum: ++ - apple,t8011-spi ++ - apple,t8015-spi + - const: apple,t8010-spi + - const: apple,spi + - items: diff --git a/kernel/patches/drivers/spi/0012-spi-apple-restore-status-configuration-for-T8011-PIO.patch b/kernel/patches/drivers/spi/0012-spi-apple-restore-status-configuration-for-T8011-PIO.patch new file mode 100644 index 00000000..42f5d2c5 --- /dev/null +++ b/kernel/patches/drivers/spi/0012-spi-apple-restore-status-configuration-for-T8011-PIO.patch @@ -0,0 +1,58 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 11:39:51 +0100 +Subject: [PATCH] spi: apple: restore status configuration for T8011 PIO + transfers + +Select the native PIO status configuration through T8011 match data. Retain the existing descriptor-only behavior on other chips. + +Assisted-by: LLM +--- + drivers/spi/spi-apple.c | 13 ++++++++++++- + 1 file changed, 12 insertions(+), 1 deletion(-) + +diff --git a/drivers/spi/spi-apple.c b/drivers/spi/spi-apple.c +index 8ef0f11b5..0668441d2 100644 +--- a/drivers/spi/spi-apple.c ++++ b/drivers/spi/spi-apple.c +@@ -127,6 +127,8 @@ + struct apple_spi_hw { + bool legacy_status; + bool has_descriptor_dma; ++ /* Restore native STATUS setup before long PIO as well as short transfers. */ ++ bool pio_status_config; + /* T7000: the SPI version 1 configuration register layout. */ + bool spi_v1; + /* +@@ -183,7 +185,7 @@ static bool apple_spi_t8010_uses_descriptor(struct spi_transfer *t, + static void apple_spi_t8010_write_status_config(struct apple_spi *spi, + bool use_descriptor) + { +- if (use_descriptor) ++ if (use_descriptor || spi->hw->pio_status_config) + reg_write(spi, APPLE_SPI_STATUS, + APPLE_SPI_T8010_DESC_STATUS_CFG); + } +@@ -1402,6 +1404,14 @@ static const struct apple_spi_hw apple_spi_hw_t8010 = { + .cfg_base = APPLE_SPI_CFG_T8010_BASE, + }; + ++static const struct apple_spi_hw apple_spi_hw_t8011 = { ++ .legacy_status = true, ++ .has_descriptor_dma = true, ++ .pio_status_config = true, ++ .min_clk_div = 2, ++ .cfg_base = APPLE_SPI_CFG_T8010_BASE, ++}; ++ + static const struct apple_spi_hw apple_spi_hw_t7000 = { + .legacy_status = true, + .spi_v1 = true, +@@ -1417,6 +1427,7 @@ static const struct of_device_id apple_spi_of_match[] = { + { .compatible = "apple,s5l8960x-spi", .data = &apple_spi_hw_s5l8960x, }, + { .compatible = "apple,t7000-spi", .data = &apple_spi_hw_t7000, }, + { .compatible = "apple,s8000-spi", .data = &apple_spi_hw_s8000, }, ++ { .compatible = "apple,t8011-spi", .data = &apple_spi_hw_t8011, }, + { .compatible = "apple,t8010-spi", .data = &apple_spi_hw_t8010, }, + { .compatible = "apple,t8103-spi", .data = &apple_spi_hw_default, }, + { .compatible = "apple,spi", .data = &apple_spi_hw_default, }, diff --git a/kernel/patches/drivers/w1/0003-w1-retain-bounded-read-only-J120-HDQ-transfers.patch b/kernel/patches/drivers/w1/0003-w1-retain-bounded-read-only-J120-HDQ-transfers.patch new file mode 100644 index 00000000..7a7c78e2 --- /dev/null +++ b/kernel/patches/drivers/w1/0003-w1-retain-bounded-read-only-J120-HDQ-transfers.patch @@ -0,0 +1,473 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Thu, 19 Nov 2026 00:26:06 +0100 +Subject: [PATCH] w1: retain bounded read-only J120 HDQ transfers + +Assisted-by: LLM +--- + drivers/w1/masters/w1-uart.c | 172 ++++++++++++++++++++++++++++++++--- + drivers/w1/w1.c | 21 ++++- + drivers/w1/w1_int.c | 17 +++- + include/linux/w1.h | 2 + + 4 files changed, 193 insertions(+), 19 deletions(-) + +diff --git a/drivers/w1/masters/w1-uart.c b/drivers/w1/masters/w1-uart.c +index c953c1b65..9583af243 100644 +--- a/drivers/w1/masters/w1-uart.c ++++ b/drivers/w1/masters/w1-uart.c +@@ -13,7 +13,9 @@ + */ + + #include ++#include + #include ++#include + #include + #include + #include +@@ -50,7 +52,12 @@ enum w1_uart_mode { + }; + + struct w1_uart_variant { ++ bool hdq_fail_stop; ++ const u8 *hdq_read_regs; ++ size_t hdq_num_read_regs; ++ unsigned int hdq_budget_ms; + enum w1_uart_mode mode; ++ bool voltage_diagnostic; + }; + + /** +@@ -86,6 +93,12 @@ struct w1_uart_config { + * @hdq_response_valid: whether @hdq_response is ready for the W1 client + */ + struct w1_uart_device { ++ bool hdq_faulted; ++ bool hdq_fail_stop; ++ const u8 *hdq_read_regs; ++ size_t hdq_num_read_regs; ++ unsigned long hdq_deadline; ++ unsigned int hdq_budget_ms; + struct serdev_device *serdev; + struct w1_bus_master bus; + enum w1_uart_mode mode; +@@ -110,6 +123,8 @@ struct w1_uart_device { + u8 hdq_rx_bit; + bool hdq_receiving; + bool hdq_response_valid; ++ bool voltage_diagnostic; ++ unsigned long diagnostic_attempted; + }; + + /** +@@ -347,6 +362,19 @@ static int w1_uart_hdq_break(struct w1_uart_device *w1dev) + * accepted by the receive callback, so the response then never completes + * and the cycle ends with -ETIMEDOUT. + */ ++/* Zero is rejected by the caller: serdev treats a zero timeout as infinite. */ ++static unsigned long w1_uart_hdq_wait_budget(struct w1_uart_device *w1dev, ++ unsigned long legacy) ++{ ++ unsigned long now = jiffies; ++ ++ if (!w1dev->hdq_budget_ms) ++ return legacy; ++ if (time_after_eq(now, w1dev->hdq_deadline)) ++ return 0; ++ return min(legacy, w1dev->hdq_deadline - now); ++} ++ + static int w1_uart_hdq_xfer_once(struct w1_uart_device *w1dev) + { + struct serdev_device *serdev = w1dev->serdev; +@@ -355,6 +383,8 @@ static int w1_uart_hdq_xfer_once(struct w1_uart_device *w1dev) + ssize_t written; + int ret; + ++ if (!w1_uart_hdq_wait_budget(w1dev, HZ)) ++ return -ETIMEDOUT; + ret = w1_uart_hdq_break(w1dev); + if (ret) + return ret; +@@ -367,8 +397,13 @@ static int w1_uart_hdq_xfer_once(struct w1_uart_device *w1dev) + w1dev->hdq_response_valid = false; + spin_unlock_irqrestore(&w1dev->hdq_rx_lock, flags); + ++ timeout = w1_uart_hdq_wait_budget(w1dev, HZ); ++ if (!timeout) { ++ ret = -ETIMEDOUT; ++ goto cancel_receive; ++ } + written = serdev_device_write(serdev, w1dev->hdq_command, +- sizeof(w1dev->hdq_command), HZ); ++ sizeof(w1dev->hdq_command), timeout); + if (written < 0) { + ret = written; + goto cancel_receive; +@@ -378,13 +413,24 @@ static int w1_uart_hdq_xfer_once(struct w1_uart_device *w1dev) + goto cancel_receive; + } + +- serdev_device_wait_until_sent(serdev, HZ); +- timeout = wait_for_completion_timeout(&w1dev->rx_byte_received, +- W1_UART_HDQ_TIMEOUT); ++ timeout = w1_uart_hdq_wait_budget(w1dev, HZ); ++ if (!timeout) { ++ ret = -ETIMEDOUT; ++ goto cancel_receive; ++ } ++ serdev_device_wait_until_sent(serdev, timeout); ++ ++ timeout = w1_uart_hdq_wait_budget(w1dev, W1_UART_HDQ_TIMEOUT); + if (!timeout) { + ret = -ETIMEDOUT; + goto cancel_receive; + } ++ timeout = wait_for_completion_timeout(&w1dev->rx_byte_received, ++ timeout); ++ if (!timeout || !w1_uart_hdq_wait_budget(w1dev, HZ)) { ++ ret = -ETIMEDOUT; ++ goto cancel_receive; ++ } + + return 0; + +@@ -394,7 +440,21 @@ static int w1_uart_hdq_xfer_once(struct w1_uart_device *w1dev) + return ret; + } + +-static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command) ++static bool w1_uart_hdq_command_allowed(struct w1_uart_device *w1dev, ++ u8 command) ++{ ++ size_t i; ++ ++ if (!w1dev->hdq_read_regs) ++ return true; ++ for (i = 0; i < w1dev->hdq_num_read_regs; i++) ++ if (command == w1dev->hdq_read_regs[i]) ++ return true; ++ return false; ++} ++ ++static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command, ++ unsigned int tries) + { + unsigned int bit; + unsigned int try; +@@ -402,11 +462,21 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command) + int deselect_ret; + + w1_uart_hdq_cancel_receive(w1dev); ++ if (w1dev->hdq_faulted) ++ return -ESHUTDOWN; ++ if (!w1_uart_hdq_command_allowed(w1dev, command)) ++ return -EACCES; ++ if (w1dev->hdq_budget_ms) ++ w1dev->hdq_deadline = jiffies + ++ msecs_to_jiffies(w1dev->hdq_budget_ms); + + if (w1dev->hdq_mux) { + ret = mux_state_select(w1dev->hdq_mux); +- if (ret) ++ if (ret) { ++ if (w1dev->hdq_fail_stop) ++ w1dev->hdq_faulted = true; + return ret; ++ } + } + + for (bit = 0; bit < W1_UART_HDQ_BITS_PER_BYTE; bit++) +@@ -417,13 +487,13 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command) + * Retry a lost cycle: the gauge's response window is long over after + * the timeout, and the next break resynchronizes its HDQ state. + */ +- for (try = 0; try < W1_UART_HDQ_TRIES; try++) { ++ for (try = 0; try < tries; try++) { + ret = w1_uart_hdq_xfer_once(w1dev); +- if (ret != -ETIMEDOUT) ++ if (ret != -ETIMEDOUT || w1dev->hdq_fail_stop) + break; + dev_dbg(&w1dev->serdev->dev, + "HDQ command %02x timed out (try %u/%u)\n", +- command, try + 1, W1_UART_HDQ_TRIES); ++ command, try + 1, tries); + } + + if (w1dev->hdq_mux) { +@@ -434,6 +504,10 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command) + } + } + ++ if (ret && w1dev->hdq_fail_stop) { ++ w1_uart_hdq_cancel_receive(w1dev); ++ w1dev->hdq_faulted = true; ++ } + return ret; + } + +@@ -601,7 +675,7 @@ static void w1_uart_hdq_write_byte(void *data, u8 byte) + struct w1_uart_device *w1dev = data; + int ret; + +- ret = w1_uart_hdq_xfer(w1dev, byte); ++ ret = w1_uart_hdq_xfer(w1dev, byte, W1_UART_HDQ_TRIES); + if (ret) + dev_dbg(&w1dev->serdev->dev, "HDQ transfer failed: %d\n", ret); + } +@@ -628,17 +702,24 @@ static u8 w1_uart_hdq_reset_bus(void *data) + struct w1_uart_device *w1dev = data; + int ret; + ++ if (w1dev->hdq_faulted) ++ return 1; + w1_uart_hdq_cancel_receive(w1dev); + if (w1dev->hdq_mux) { + ret = mux_state_select(w1dev->hdq_mux); +- if (ret) ++ if (ret) { ++ if (w1dev->hdq_fail_stop) ++ w1dev->hdq_faulted = true; + return 1; ++ } + } + + ret = w1_uart_hdq_break(w1dev); + if (w1dev->hdq_mux && mux_state_deselect(w1dev->hdq_mux) && !ret) + ret = -EIO; + ++ if (ret && w1dev->hdq_fail_stop) ++ w1dev->hdq_faulted = true; + return ret ? 1 : 0; + } + +@@ -672,6 +753,36 @@ static void w1_uart_hdq_search(void *data, struct w1_master *master, + slave_found(master, (u64)crc << 56 | module_id); + } + ++/* Local J120 RAM diagnostic: one coherent voltage word, no W1 scan. */ ++static ssize_t voltage_mv_show(struct device *dev, ++ struct device_attribute *attr, char *buf) ++{ ++ struct w1_uart_device *w1dev = dev_get_drvdata(dev); ++ static const u8 command[] = { 0x09, 0x08, 0x09 }; ++ u8 bytes[ARRAY_SIZE(command)]; ++ unsigned int i; ++ int ret; ++ ++ if (test_and_set_bit(0, &w1dev->diagnostic_attempted)) ++ return -EALREADY; ++ ++ for (i = 0; i < ARRAY_SIZE(command); i++) { ++ ret = w1_uart_hdq_xfer(w1dev, command[i], 1); ++ if (ret) ++ return dev_err_probe(dev, ret, "HDQ voltage read %#x failed\n", ++ command[i]); ++ if (!w1_uart_hdq_take_response(w1dev, &bytes[i])) ++ return -EIO; ++ } ++ ++ if (bytes[0] != bytes[2]) ++ return -EAGAIN; ++ if (!(bytes[0] | bytes[1]) || (bytes[0] == 0xff && bytes[1] == 0xff)) ++ return -ENODATA; ++ return sysfs_emit(buf, "%u\n", (unsigned int)bytes[0] << 8 | bytes[1]); ++} ++static DEVICE_ATTR_RO(voltage_mv); ++ + static int w1_uart_probe(struct serdev_device *serdev) + { + struct device *dev = &serdev->dev; +@@ -685,8 +796,14 @@ static int w1_uart_probe(struct serdev_device *serdev) + w1dev->serdev = serdev; + w1dev->bus.data = w1dev; + variant = device_get_match_data(dev); +- if (variant) ++ if (variant) { + w1dev->mode = variant->mode; ++ w1dev->hdq_fail_stop = variant->hdq_fail_stop; ++ w1dev->hdq_read_regs = variant->hdq_read_regs; ++ w1dev->hdq_num_read_regs = variant->hdq_num_read_regs; ++ w1dev->hdq_budget_ms = variant->hdq_budget_ms; ++ w1dev->voltage_diagnostic = variant->voltage_diagnostic; ++ } + + if (w1dev->mode == W1_UART_MODE_HDQ) { + w1dev->hdq_mux = devm_mux_state_get_optional(dev, "hdq"); +@@ -714,6 +831,11 @@ static int w1_uart_probe(struct serdev_device *serdev) + if (ret < 0) + return ret; + ++ if (w1dev->voltage_diagnostic) ++ return device_create_file(dev, &dev_attr_voltage_mv); ++ ++ if (w1dev->hdq_fail_stop) ++ return w1_add_master_device_parent(&w1dev->bus, dev); + return w1_add_master_device(&w1dev->bus); + } + +@@ -721,6 +843,11 @@ static void w1_uart_remove(struct serdev_device *serdev) + { + struct w1_uart_device *w1dev = serdev_device_get_drvdata(serdev); + ++ if (w1dev->voltage_diagnostic) { ++ device_remove_file(&serdev->dev, &dev_attr_voltage_mv); ++ return; ++ } ++ + /* + * Waits until w1-uart callbacks are finished, serdev is closed + * and its device data released automatically by devres (waits +@@ -737,7 +864,28 @@ static const struct w1_uart_variant w1_uart_hdq = { + .mode = W1_UART_MODE_HDQ, + }; + ++static const struct w1_uart_variant w1_uart_j120_voltage = { ++ .mode = W1_UART_MODE_HDQ, ++ .voltage_diagnostic = true, ++}; ++ ++/* Read-command bytes only; HDQ write opcodes (bit7) are never admitted. */ ++static const u8 w1_uart_j120_hdq_read_regs[] = { ++ 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x10, ++ 0x11, 0x12, 0x13, 0x14, 0x15, 0x2c, 0x2d, ++}; ++ ++static const struct w1_uart_variant w1_uart_j120_hdq = { ++ .hdq_fail_stop = true, ++ .hdq_read_regs = w1_uart_j120_hdq_read_regs, ++ .hdq_num_read_regs = ARRAY_SIZE(w1_uart_j120_hdq_read_regs), ++ .mode = W1_UART_MODE_HDQ, ++ .hdq_budget_ms = 100, ++}; ++ + static const struct of_device_id w1_uart_of_match[] = { ++ { .compatible = "apple,j120-hdq-uart", .data = &w1_uart_j120_hdq }, ++ { .compatible = "apple,j120-hdq-voltage-diagnostic", .data = &w1_uart_j120_voltage }, + { .compatible = "w1-uart", .data = &w1_uart_1wire }, + { .compatible = "ti,hdq-uart", .data = &w1_uart_hdq }, + {}, +diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c +index c16946642..fd6098cbb 100644 +--- a/drivers/w1/w1.c ++++ b/drivers/w1/w1.c +@@ -78,6 +78,7 @@ static void w1_slave_release(struct device *dev) + + dev_dbg(dev, "%s: Releasing %s [%p]\n", __func__, sl->name, sl); + ++ of_node_put(sl->dev.of_node); + w1_family_put(sl->family); + sl->master->slave_count--; + } +@@ -666,6 +667,22 @@ static int w1_family_notify(unsigned long action, struct w1_slave *sl) + return 0; + } + ++static struct device_node *w1_slave_of_node(struct w1_slave *sl) ++{ ++ struct device *parent = sl->master->dev.parent; ++ struct device_node *child; ++ ++ if (!parent) ++ return of_find_matching_node(sl->master->dev.of_node, ++ sl->family->of_match_table); ++ if (!parent->of_node) ++ return NULL; ++ for_each_available_child_of_node(parent->of_node, child) ++ if (of_match_node(sl->family->of_match_table, child)) ++ return child; ++ return NULL; ++} ++ + static int __w1_attach_slave_device(struct w1_slave *sl) + { + int err; +@@ -675,8 +692,7 @@ static int __w1_attach_slave_device(struct w1_slave *sl) + sl->dev.bus = &w1_bus_type; + sl->dev.release = &w1_slave_release; + sl->dev.groups = w1_slave_groups; +- sl->dev.of_node = of_find_matching_node(sl->master->dev.of_node, +- sl->family->of_match_table); ++ sl->dev.of_node = w1_slave_of_node(sl); + + dev_set_name(&sl->dev, "%02x-%012llx", + (unsigned int) sl->reg_num.family, +@@ -697,7 +713,6 @@ static int __w1_attach_slave_device(struct w1_slave *sl) + dev_err(&sl->dev, + "Device registration [%s] failed. err=%d\n", + dev_name(&sl->dev), err); +- of_node_put(sl->dev.of_node); + put_device(&sl->dev); + return err; + } +diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c +index 19a0ea28e..06b39ecc8 100644 +--- a/drivers/w1/w1_int.c ++++ b/drivers/w1/w1_int.c +@@ -23,7 +23,7 @@ module_param_named(enable_pullup, w1_enable_pullup, int, 0); + + static struct w1_master *w1_alloc_dev(u32 id, int slave_count, int slave_ttl, + struct device_driver *driver, +- struct device *device) ++ struct device *device, struct device *parent) + { + struct w1_master *dev; + int err; +@@ -58,6 +58,7 @@ static struct w1_master *w1_alloc_dev(u32 id, int slave_count, int slave_ttl, + mutex_init(&dev->list_mutex); + + memcpy(&dev->dev, device, sizeof(struct device)); ++ dev->dev.parent = parent; + dev_set_name(&dev->dev, "w1_bus_master%u", dev->id); + snprintf(dev->name, sizeof(dev->name), "w1_bus_master%u", dev->id); + dev->dev.init_name = dev->name; +@@ -82,10 +83,12 @@ static void w1_free_dev(struct w1_master *dev) + } + + /** +- * w1_add_master_device() - registers a new master device ++ * w1_add_master_device_parent() - register a master with an optional parent + * @master: master bus device to register ++ * @parent: transport device owning this bus, or NULL for legacy masters + */ +-int w1_add_master_device(struct w1_bus_master *master) ++int w1_add_master_device_parent(struct w1_bus_master *master, ++ struct device *parent) + { + struct w1_master *dev, *entry; + int retval = 0; +@@ -116,7 +119,7 @@ int w1_add_master_device(struct w1_bus_master *master) + } while (found); + + dev = w1_alloc_dev(id, w1_max_slave_count, w1_max_slave_ttl, +- &w1_master_driver, &w1_master_device); ++ &w1_master_driver, &w1_master_device, parent); + if (!dev) { + mutex_unlock(&w1_mlock); + return -ENOMEM; +@@ -164,6 +167,12 @@ int w1_add_master_device(struct w1_bus_master *master) + + return retval; + } ++EXPORT_SYMBOL(w1_add_master_device_parent); ++ ++int w1_add_master_device(struct w1_bus_master *master) ++{ ++ return w1_add_master_device_parent(master, NULL); ++} + EXPORT_SYMBOL(w1_add_master_device); + + void __w1_remove_master_device(struct w1_master *dev) +diff --git a/include/linux/w1.h b/include/linux/w1.h +index 064805bfa..c60924e5f 100644 +--- a/include/linux/w1.h ++++ b/include/linux/w1.h +@@ -242,6 +242,8 @@ struct w1_master { + }; + + int w1_add_master_device(struct w1_bus_master *master); ++int w1_add_master_device_parent(struct w1_bus_master *master, ++ struct device *parent); + void w1_remove_master_device(struct w1_bus_master *master); + + /** diff --git a/kernel/patches/drivers/w1/0004-w1-allow-reading-the-J120-battery-cycle-count.patch b/kernel/patches/drivers/w1/0004-w1-allow-reading-the-J120-battery-cycle-count.patch new file mode 100644 index 00000000..a7fbc80f --- /dev/null +++ b/kernel/patches/drivers/w1/0004-w1-allow-reading-the-J120-battery-cycle-count.patch @@ -0,0 +1,25 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 08:56:57 +0100 +Subject: [PATCH] w1: allow reading the J120 battery cycle count + +Admit the two CycleCount bytes to the J120 HDQ read allowlist. Keep the existing deadline, fail-stop behavior and write exclusion. + +Assisted-by: LLM +--- + drivers/w1/masters/w1-uart.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +diff --git a/drivers/w1/masters/w1-uart.c b/drivers/w1/masters/w1-uart.c +index 9583af243..69e34d522 100644 +--- a/drivers/w1/masters/w1-uart.c ++++ b/drivers/w1/masters/w1-uart.c +@@ -872,7 +872,7 @@ static const struct w1_uart_variant w1_uart_j120_voltage = { + /* Read-command bytes only; HDQ write opcodes (bit7) are never admitted. */ + static const u8 w1_uart_j120_hdq_read_regs[] = { + 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x10, +- 0x11, 0x12, 0x13, 0x14, 0x15, 0x2c, 0x2d, ++ 0x11, 0x12, 0x13, 0x14, 0x15, 0x2a, 0x2b, 0x2c, 0x2d, + }; + + static const struct w1_uart_variant w1_uart_j120_hdq = { diff --git a/kernel/patches/drivers/w1/0005-w1-avoid-recursive-family-autoload-during-reconnect.patch b/kernel/patches/drivers/w1/0005-w1-avoid-recursive-family-autoload-during-reconnect.patch new file mode 100644 index 00000000..7322f251 --- /dev/null +++ b/kernel/patches/drivers/w1/0005-w1-avoid-recursive-family-autoload-during-reconnect.patch @@ -0,0 +1,66 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:44:04 +0100 +Subject: [PATCH] w1: avoid recursive family autoload during reconnect + +Reconnecting a slave already runs inside family registration or removal with the master list locked. Attach using the current family mapping without waiting for a module whose init or exit needs to complete the same reconnect. + +Assisted-by: LLM +--- + drivers/w1/w1.c | 21 +++++++++++++++------ + 1 file changed, 15 insertions(+), 6 deletions(-) + +diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c +index fd6098cbb..e92d425dc 100644 +--- a/drivers/w1/w1.c ++++ b/drivers/w1/w1.c +@@ -728,7 +728,8 @@ static int __w1_attach_slave_device(struct w1_slave *sl) + return 0; + } + +-int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) ++static int w1_attach_slave(struct w1_master *dev, struct w1_reg_num *rn, ++ bool load_family) + { + struct w1_slave *sl; + struct w1_family *f; +@@ -756,10 +757,12 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) + dev_info(&dev->dev, "Attaching one wire slave %02x.%012llx crc %02x\n", + rn->family, (unsigned long long)rn->id, rn->crc); + +- /* slave modules need to be loaded in a context with unlocked mutex */ +- mutex_unlock(&dev->mutex); +- request_module("w1-family-0x%02X", rn->family); +- mutex_lock(&dev->mutex); ++ if (load_family) { ++ /* Family registration may take the master mutex. */ ++ mutex_unlock(&dev->mutex); ++ request_module("w1-family-0x%02X", rn->family); ++ mutex_lock(&dev->mutex); ++ } + + spin_lock(&w1_flock); + f = w1_family_registered(rn->family); +@@ -792,6 +795,11 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) + return 0; + } + ++int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn) ++{ ++ return w1_attach_slave(dev, rn, true); ++} ++ + int w1_unref_slave(struct w1_slave *sl) + { + struct w1_master *dev = sl->master; +@@ -909,8 +917,9 @@ void w1_reconnect_slaves(struct w1_family *f, int attach) + /* If it was already in use let the automatic + * scan pick it up again later. + */ ++ /* Reconnect runs inside family registration or removal. */ + if (!w1_slave_detach(sl)) +- w1_attach_slave_device(dev, &rn); ++ w1_attach_slave(dev, &rn, false); + mutex_lock(&dev->list_mutex); + } + } diff --git a/kernel/patches/drivers/w1/0006-w1-log-the-first-guarded-HDQ-transport-failure.patch b/kernel/patches/drivers/w1/0006-w1-log-the-first-guarded-HDQ-transport-failure.patch new file mode 100644 index 00000000..32c51972 --- /dev/null +++ b/kernel/patches/drivers/w1/0006-w1-log-the-first-guarded-HDQ-transport-failure.patch @@ -0,0 +1,77 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Fri, 20 Nov 2026 11:58:36 +0100 +Subject: [PATCH] w1: log the first guarded HDQ transport failure + +The J120 guard stops transfers after the first transport error. Report that error and its operation before later gauge reads lose it behind a generic I/O error. + +Assisted-by: LLM +--- + drivers/w1/masters/w1-uart.c | 26 ++++++++++++++++---------- + 1 file changed, 16 insertions(+), 10 deletions(-) + +diff --git a/drivers/w1/masters/w1-uart.c b/drivers/w1/masters/w1-uart.c +index 69e34d522..af7e69f4a 100644 +--- a/drivers/w1/masters/w1-uart.c ++++ b/drivers/w1/masters/w1-uart.c +@@ -337,6 +337,18 @@ static void w1_uart_hdq_cancel_receive(struct w1_uart_device *w1dev) + spin_unlock_irqrestore(&w1dev->hdq_rx_lock, flags); + } + ++static void w1_uart_hdq_stop_on_error(struct w1_uart_device *w1dev, ++ const char *operation, int ret) ++{ ++ if (!ret || !w1dev->hdq_fail_stop) ++ return; ++ ++ w1_uart_hdq_cancel_receive(w1dev); ++ w1dev->hdq_faulted = true; ++ dev_err(&w1dev->serdev->dev, "HDQ %s failed (%d), stopping transfers\n", ++ operation, ret); ++} ++ + static int w1_uart_hdq_break(struct w1_uart_device *w1dev) + { + struct serdev_device *serdev = w1dev->serdev; +@@ -473,8 +485,7 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command, + if (w1dev->hdq_mux) { + ret = mux_state_select(w1dev->hdq_mux); + if (ret) { +- if (w1dev->hdq_fail_stop) +- w1dev->hdq_faulted = true; ++ w1_uart_hdq_stop_on_error(w1dev, "mux select", ret); + return ret; + } + } +@@ -504,10 +515,7 @@ static int w1_uart_hdq_xfer(struct w1_uart_device *w1dev, u8 command, + } + } + +- if (ret && w1dev->hdq_fail_stop) { +- w1_uart_hdq_cancel_receive(w1dev); +- w1dev->hdq_faulted = true; +- } ++ w1_uart_hdq_stop_on_error(w1dev, "read", ret); + return ret; + } + +@@ -708,8 +716,7 @@ static u8 w1_uart_hdq_reset_bus(void *data) + if (w1dev->hdq_mux) { + ret = mux_state_select(w1dev->hdq_mux); + if (ret) { +- if (w1dev->hdq_fail_stop) +- w1dev->hdq_faulted = true; ++ w1_uart_hdq_stop_on_error(w1dev, "reset mux select", ret); + return 1; + } + } +@@ -718,8 +725,7 @@ static u8 w1_uart_hdq_reset_bus(void *data) + if (w1dev->hdq_mux && mux_state_deselect(w1dev->hdq_mux) && !ret) + ret = -EIO; + +- if (ret && w1dev->hdq_fail_stop) +- w1dev->hdq_faulted = true; ++ w1_uart_hdq_stop_on_error(w1dev, "reset", ret); + return ret ? 1 : 0; + } + diff --git a/kernel/patches/drivers/wifi/0011-dt-bindings-net-brcmfmac-allow-the-Apple-OTP-layout.patch b/kernel/patches/drivers/wifi/0011-dt-bindings-net-brcmfmac-allow-the-Apple-OTP-layout.patch new file mode 100644 index 00000000..d7e11095 --- /dev/null +++ b/kernel/patches/drivers/wifi/0011-dt-bindings-net-brcmfmac-allow-the-Apple-OTP-layout.patch @@ -0,0 +1,27 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:34 +0100 +Subject: [PATCH] dt-bindings: net: brcmfmac: allow the Apple OTP layout + +Allow an optional read-only module identity layout on the Wi-Fi OTP provider for a shared Bluetooth consumer. + +Assisted-by: LLM +--- + .../devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml | 4 ++++ + 1 file changed, 4 insertions(+) + +diff --git a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +index 000060f30..f451203f1 100644 +--- a/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml ++++ b/Documentation/devicetree/bindings/net/wireless/brcm,bcm4329-fmac.yaml +@@ -150,6 +150,10 @@ properties: + - const: mac-address + - const: calibration + ++ nvmem-layout: ++ $ref: /schemas/nvmem/layouts/brcm,apple-otp-layout.yaml# ++ description: Read-only Apple module identity records from the radio OTP. ++ + brcm,board-type: + $ref: /schemas/types.yaml#/definitions/string + description: Overrides the board type, which is normally the compatible of diff --git a/kernel/patches/drivers/wifi/0012-wifi-brcmfmac-expose-a-board-selected-read-only-OTP-.patch b/kernel/patches/drivers/wifi/0012-wifi-brcmfmac-expose-a-board-selected-read-only-OTP-.patch new file mode 100644 index 00000000..6589dab2 --- /dev/null +++ b/kernel/patches/drivers/wifi/0012-wifi-brcmfmac-expose-a-board-selected-read-only-OTP-.patch @@ -0,0 +1,125 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tompta1 <546706+tompta1@users.noreply.github.com> +Date: Fri, 13 Nov 2026 12:55:36 +0100 +Subject: [PATCH] wifi: brcmfmac: expose a board-selected read-only OTP + snapshot + +Publish the already-read OTP bytes only when the device tree selects the Apple module layout. Keep hardware reads inside the existing Wi-Fi ownership path; never let another consumer issue concurrent PCI transactions. + +Assisted-by: LLM +--- + .../broadcom/brcm80211/brcmfmac/pcie.c | 74 ++++++++++++++++++- + 1 file changed, 70 insertions(+), 4 deletions(-) + +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +index af8af4b45..314030754 100644 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/pcie.c +@@ -18,6 +18,8 @@ + #include + #include + #include ++#include ++#include + + #include + #include +@@ -2080,6 +2082,64 @@ brcmf_pcie_parse_otp(struct brcmf_pciedev_info *devinfo, u8 *otp, size_t size) + return ret; + } + ++struct brcmf_pcie_otp_snapshot { ++ size_t size; ++ u8 data[]; ++}; ++ ++static int brcmf_pcie_otp_read(void *priv, unsigned int offset, ++ void *value, size_t bytes) ++{ ++ struct brcmf_pcie_otp_snapshot *snapshot = priv; ++ ++ if (offset > snapshot->size || bytes > snapshot->size - offset) ++ return -EINVAL; ++ ++ memcpy(value, snapshot->data + offset, bytes); ++ return 0; ++} ++ ++static int brcmf_pcie_publish_otp(struct brcmf_pciedev_info *devinfo, ++ const u16 *otp, size_t words) ++{ ++ struct device *dev = &devinfo->pdev->dev; ++ struct device_node *layout __free(device_node) = ++ of_get_child_by_name(dev_of_node(dev), "nvmem-layout"); ++ struct brcmf_pcie_otp_snapshot *snapshot; ++ struct nvmem_device *nvmem; ++ struct nvmem_config config = { ++ .dev = dev, ++ .name = "brcmfmac-otp", ++ .id = NVMEM_DEVID_AUTO, ++ .owner = THIS_MODULE, ++ .type = NVMEM_TYPE_OTP, ++ .read_only = true, ++ .root_only = true, ++ .reg_read = brcmf_pcie_otp_read, ++ .word_size = 1, ++ .stride = 1, ++ }; ++ size_t i; ++ ++ /* Only boards explicitly describing this layout expose the snapshot. */ ++ if (!of_device_is_compatible(layout, "brcm,apple-otp-layout")) ++ return 0; ++ ++ snapshot = devm_kzalloc(dev, struct_size(snapshot, data, words * 2), ++ GFP_KERNEL); ++ if (!snapshot) ++ return -ENOMEM; ++ ++ snapshot->size = words * 2; ++ for (i = 0; i < words; i++) ++ put_unaligned_le16(otp[i], snapshot->data + i * 2); ++ ++ config.priv = snapshot; ++ config.size = snapshot->size; ++ nvmem = devm_nvmem_register(dev, &config); ++ return PTR_ERR_OR_ZERO(nvmem); ++} ++ + static int brcmf_pcie_read_otp(struct brcmf_pciedev_info *devinfo) + { + const struct pci_dev *pdev = devinfo->pdev; +@@ -2152,16 +2212,17 @@ static int brcmf_pcie_read_otp(struct brcmf_pciedev_info *devinfo) + "OTP unavailable, using default firmware\n"); + return 0; + } +- +- /* Map OTP to shadow area */ +- WRITECC32(devinfo, sromcontrol, +- sromctl | BCMA_CC_SROM_CONTROL_OTPSEL); + } + + otp = kcalloc(words, sizeof(u16), GFP_KERNEL); + if (!otp) + return -ENOMEM; + ++ /* Map OTP to shadow area only after the allocation can no longer fail. */ ++ if (coreid == BCMA_CORE_CHIPCOMMON) ++ WRITECC32(devinfo, sromcontrol, ++ sromctl | BCMA_CC_SROM_CONTROL_OTPSEL); ++ + /* Map bus window to SROM/OTP shadow area in core */ + base = brcmf_pcie_buscore_prep_addr(devinfo->pdev, base + core->base); + +@@ -2177,6 +2238,11 @@ static int brcmf_pcie_read_otp(struct brcmf_pciedev_info *devinfo) + } + + ret = brcmf_pcie_parse_otp(devinfo, (u8 *)otp, 2 * words); ++ if (!ret) { ++ ret = brcmf_pcie_publish_otp(devinfo, otp, words); ++ kfree(otp); ++ return ret; ++ } + kfree(otp); + + if (ret && optional) { diff --git a/kernel/patches/drivers/wifi/0013-wifi-brcmfmac-quirk-P2P-for-J120-BCM4355-firmware.patch b/kernel/patches/drivers/wifi/0013-wifi-brcmfmac-quirk-P2P-for-J120-BCM4355-firmware.patch new file mode 100644 index 00000000..2d4532ce --- /dev/null +++ b/kernel/patches/drivers/wifi/0013-wifi-brcmfmac-quirk-P2P-for-J120-BCM4355-firmware.patch @@ -0,0 +1,33 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: tom +Date: Sun, 22 Nov 2026 04:07:05 +0100 +Subject: [PATCH] wifi: brcmfmac: quirk P2P for J120 BCM4355 firmware + +The J120 firmware 01-c372c45d advertises P2P but returns -EBADE when setting up a P2P device. Mask P2P for this exact firmware ID, using the existing BCM4355 quirk table. + +Assisted-by: LLM +--- + drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c | 6 ++++-- + 1 file changed, 4 insertions(+), 2 deletions(-) + +diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +index 3e140019f..c37970234 100644 +--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c ++++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/feature.c +@@ -107,12 +107,14 @@ static const struct brcmf_feat_fwfeat brcmf_feat_fwfeat_map[] = { + /* Features a given firmware build advertises but can't actually do */ + static const struct brcmf_feat_fwfeat brcmf_feat_fwfeat_disable_map[] = { + /* +- * Apple BCM4355 firmware answers the "p2p" iovar but fails +- * "p2p_da_override" with -52, so every P2P device creation fails. ++ * These Apple BCM4355 builds advertise P2P but reject P2P device ++ * setup with -EBADE. + * Apple uses AWDL, not Wi-Fi P2P. + */ + /* iOS 16 C0 "FearA" (iPad 5), 9.44.205.0.3.50.46 */ + { "01-9787ef4d", BIT(BRCMF_FEAT_P2P) }, ++ /* J120, 9.44.205.0.3.50.46 */ ++ { "01-c372c45d", BIT(BRCMF_FEAT_P2P) }, + /* iPadOS 17.7 C1 (iPad 6), 9.30.503.2.3.50.99 */ + { "01-d0cb7703", BIT(BRCMF_FEAT_P2P) }, + }; diff --git a/src/orchard/apple/adt.py b/src/orchard/apple/adt.py index b0f04d4b..a36bca04 100644 --- a/src/orchard/apple/adt.py +++ b/src/orchard/apple/adt.py @@ -47,3 +47,25 @@ def node(depth, parent=()): if len(device_ids) != 1 or not device_ids[0]: raise ValueError('Ambiguous device identity in ADT') return device_ids[0] + + +def j120_charger_calibration(blob, ecid): + """Extract the calibrated D2355 input-current table for the connected unit.""" + from .adt_tree import parse + if validate(blob) != ecid: + raise ValueError('Calibration ADT identity differs from the selected device') + tree = parse(blob) + if tree.properties.get('model', b'').rstrip(b'\0') != b'iPad7,1': + raise ValueError('Expected a J120 calibration ADT') + tables = [node.properties.get('usb-input-limit-calibration-hv', b'') + for path, node in tree.walk() if path == '/device-tree/charger'] + if len(tables) != 1 or len(tables[0]) != 84: + raise ValueError('Expected one J120 charger calibration table') + words = struct.unpack('<21i', tables[0]) + if words[0] not in (1, 2, 3): + raise ValueError('Invalid D2355 calibration selector') + for offset in range(1, 21, 5): + row = words[offset:offset + 5] + if row[0] <= 0 or any(a >= b for a, b in zip(row, row[1:])): + raise ValueError('Invalid D2355 calibration range') + return tables[0] diff --git a/src/orchard/apple/bluetool.py b/src/orchard/apple/bluetool.py index 8511e041..d7e8bc4e 100644 --- a/src/orchard/apple/bluetool.py +++ b/src/orchard/apple/bluetool.py @@ -1,6 +1,8 @@ """BlueTool's embedded Bluetooth firmware; board recipes and selections are callers' policy.""" import hashlib +from orchard.apple.macho import macho + WRITE_RAM, LAUNCH_RAM = 0xfc4c, 0xfc4e @@ -39,3 +41,28 @@ def hcd_from_binary(data, expected): if hashlib.sha256(data[start:end]).hexdigest() == expected: return data[start:end] offset = end + + +def regulatory_from_binary(data, address, size, expected=None): + """Read a pinned, single-command regulatory table at its native VM address. + + The recipe records the address/length from the board's native registration. + Both the BlueTool input and table output are hash-pinned by the recipe runner. + Only file-backed bytes in one unambiguous Mach-O segment are accepted. + """ + if address < 0 or not 1 <= size <= 255: + raise ValueError('Invalid single-command Bluetooth regulatory range') + _, segments, _ = macho(data) + matches = [segment for segment in segments + if segment['vm'] <= address and + address + size <= segment['vm'] + segment['size']] + if len(matches) != 1: + raise ValueError('Bluetooth regulatory range must map to one file-backed segment') + segment = matches[0] + offset = segment['offset'] + address - segment['vm'] + if offset + size > len(data): + raise ValueError('Truncated Bluetooth regulatory table') + table = data[offset:offset + size] + if expected is not None and hashlib.sha256(table).hexdigest() != expected: + raise ValueError('Bluetooth regulatory table differs from pinned hash') + return table diff --git a/src/orchard/apple/smartio.py b/src/orchard/apple/smartio.py index 3b42b64e..fcb524ad 100644 --- a/src/orchard/apple/smartio.py +++ b/src/orchard/apple/smartio.py @@ -3,9 +3,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; -T7000 for A8 and A8X). +For MH_FILESET kernels use the upstream ipsw kext extractor. The caller +selects the bundle identifier for the target SoC. """ import argparse import hashlib @@ -16,8 +15,9 @@ T8010 = 'com.apple.driver.AppleT8010SmartIO' S8000 = 'com.apple.driver.AppleS8000SmartIO' +T8011 = 'com.apple.driver.AppleT8011SmartIO' T7000 = 'com.apple.driver.AppleT7000SmartIO' -BUNDLES = (T8010, S8000, T7000) +BUNDLES = (T8010, S8000, T7000, T8011) def extract(blob, bundle=T8010): diff --git a/src/orchard/boot-entries b/src/orchard/boot-entries index 0530db9f..e4291aec 100755 --- a/src/orchard/boot-entries +++ b/src/orchard/boot-entries @@ -228,6 +228,22 @@ put() { mv -f "$2.new" "$2" } +put_initrd() { + # The built-in J120 charger requests its unit calibration before switch_root. + addon=$r/usr/lib/firmware/apple/j120/usb-input-limit-calibration-initrd.cpio.gz + if [ "$devicetree" != t8011-j120.dtb ] || [ ! -f "$addon" ] || [ -L "$addon" ]; then + put "$1" "$2" + return + fi + if [ -f "$2" ] && command -v cmp > /dev/null 2>&1 && + cat "$1" "$addon" | cmp -s - "$2"; then + return + fi + # Linux accepts concatenated initramfs archives. + (umask 077; cat "$1" "$addon" > "$2.new") + mv -f "$2.new" "$2" +} + # The BLS architecture: arm for a 32-bit ARM zImage (magic 0x016f2818 at 0x24), aa64 otherwise. architecture() { magic=$(od -An -tx1 -j 36 -N 4 "$1" 2>/dev/null | tr -d ' \n') @@ -246,7 +262,7 @@ write_entry() { directory=$boot/$token/$version mkdir -p "$directory" "$boot/loader/entries" put "$source/vmlinuz" "$directory/linux" - put "$source/initrd" "$directory/initrd" + put_initrd "$source/initrd" "$directory/initrd" put "$source/dtb/$devicetree" "$directory/$devicetree" if [ -f "$splash" ] && [ ! -L "$splash" ]; then put "$splash" "$directory/splash" diff --git a/src/orchard/contracts.py b/src/orchard/contracts.py index 50d0b7ec..d48cc999 100644 --- a/src/orchard/contracts.py +++ b/src/orchard/contracts.py @@ -113,4 +113,5 @@ def firmware_cached(self) -> bool: ... def firmware_inputs(self, clock: Clock, progress: Progress, *, allow_download: bool = True) -> Path: ... - def prepare_mixin(self, firmware_dir: Path, outdir: Path) -> Tuple[Path, MixinReceipt]: ... + def prepare_mixin(self, firmware_dir: Path, outdir: Path, *, unit_adt: Optional[bytes] = None, + ecid: Optional[int] = None) -> Tuple[Path, MixinReceipt]: ... diff --git a/src/orchard/firmware.py b/src/orchard/firmware.py index 7a728b95..d3331888 100644 --- a/src/orchard/firmware.py +++ b/src/orchard/firmware.py @@ -4,6 +4,7 @@ import json from pathlib import Path import shutil +import stat import tarfile from .cache import cache_root @@ -147,9 +148,15 @@ def read_input(name): return result -def mixin(profile, firmware_dir, outdir): +def mixin(profile, firmware_dir, outdir, *, unit_adt=None, ecid=None): """Stage the recipe's outputs under their destinations and pack the data-only mixin.""" recipe = recipe_for(profile) + calibration = None + if unit_adt is not None: + if profile != 'j120': + raise ValueError('Unit charger calibration is supported on J120 only') + from .apple.adt import j120_charger_calibration + calibration = j120_charger_calibration(unit_adt, ecid) if outdir.exists(): raise ValueError('Choose a new private output directory') outdir.mkdir(parents=True, mode=0o700) @@ -164,4 +171,19 @@ def mixin(profile, firmware_dir, outdir): shutil.copyfile(source, target) target.chmod(0o600) files[output['destination']] = {'bytes': target.stat().st_size, 'sha256': output['sha256']} + if calibration is not None: + from .image import initramfs + + name = 'lib/firmware/apple/j120/usb-input-limit-calibration-hv.bin' + checksum = hashlib.sha256(calibration).hexdigest() + store_input(prepared / 'firmware' / name, calibration, checksum) + files[name] = {'bytes': len(calibration), 'sha256': checksum} + addon_name = 'lib/firmware/apple/j120/usb-input-limit-calibration-initrd.cpio.gz' + entries = {parent.as_posix(): (stat.S_IFDIR | 0o755, b'') + for parent in Path(name).parents if parent != Path('.')} + entries[name] = (stat.S_IFREG | 0o600, calibration) + addon = prepared / 'firmware' / addon_name + initramfs.write(entries, addon) + addon.chmod(0o600) + files[addon_name] = {'bytes': addon.stat().st_size, 'sha256': digest(addon)} return pack_mixin(prepared, {'schema': 1, 'profile': profile, 'files': files}, outdir) diff --git a/src/orchard/install_device.py b/src/orchard/install_device.py index aae3e643..6dda0357 100644 --- a/src/orchard/install_device.py +++ b/src/orchard/install_device.py @@ -675,13 +675,17 @@ def install_firmware(bundle, root, *, size, sha256): continue if not (member.isfile() and name.startswith('lib/firmware/')): raise InstallError('unsafe-archive', 'Firmware bundle may contain only firmware files') + mode = 0o600 if name in ( + 'lib/firmware/apple/j120/usb-input-limit-calibration-hv.bin', + 'lib/firmware/apple/j120/usb-input-limit-calibration-initrd.cpio.gz', + ) else 0o644 parent, leaf = parent_fd(root_fd, 'usr/' + name) try: - fd = os.open(leaf, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, 0o644, dir_fd=parent) + fd = os.open(leaf, os.O_WRONLY | os.O_CREAT | os.O_TRUNC | os.O_NOFOLLOW, mode, dir_fd=parent) with os.fdopen(fd, 'wb') as output: output.write(archive.extractfile(member).read()) os.fchown(output.fileno(), 0, 0) - os.fchmod(output.fileno(), 0o644) + os.fchmod(output.fileno(), mode) count += 1 finally: os.close(parent) diff --git a/src/orchard/install_direct.py b/src/orchard/install_direct.py index c509ad26..4327fa3d 100644 --- a/src/orchard/install_direct.py +++ b/src/orchard/install_direct.py @@ -644,5 +644,14 @@ def kernel_package(connection, layer, directory, base=None): def unmount_new_root(connection, root_partuuid, boot=True): """Everything on storage, then the initrd carries on into the new root.""" points = ('/newroot/boot ' if boot else '') + '/newroot/run/orchard /newroot/run /newroot/dev /newroot/sys /newroot/proc /newroot' - shell(connection, f'sync; for point in {points}; do umount "$point" || exit 1; done; sync', timeout=300) + commands = [] + if boot: + commands.append("""boot_node=$(awk '$2 == "/newroot/boot" && $3 == "vfat" {print $1}' /proc/mounts) +[ -b "$boot_node" ] || exit 1""") + commands.append(f'sync; for point in {points}; do umount "$point" || exit 1; done; sync') + if boot: + # Flush the FAT directory entries and metadata written during unmount + # before the next loader reads the partition directly. + commands.append('dd if=/dev/null of="$boot_node" conv=notrunc,fsync || exit 1') + shell(connection, '\n'.join(commands), timeout=300) shell(connection, f"echo {root_partuuid} > /run/orchard/done.part && mv /run/orchard/done.part /run/orchard/done") diff --git a/src/orchard/install_remote.py b/src/orchard/install_remote.py index 97bf3a26..eac4183b 100644 --- a/src/orchard/install_remote.py +++ b/src/orchard/install_remote.py @@ -32,6 +32,24 @@ def put(connection, data, name, timeout=120): result.stderr.decode(errors='replace').strip()[-500:]) +def read_unit_adt(connection): + """Read the selected unit's named ADT partition over its pinned SSH session.""" + connection.check() + command = r"""set -eu +set -- $(sed -n 's/^mtd\([0-9][0-9]*\): \([0-9a-fA-F][0-9a-fA-F]*\) [0-9a-fA-F]* "adt"$/\1 \2/p' /proc/mtd) +[ "$#" -eq 2 ] +size=$((0x$2)) +[ "$size" -gt 0 ] && [ "$size" -le 16777216 ] || exit 1 +device=/dev/mtd${1}ro +[ -c "$device" ] +head -c "$size" "$device" +""" + result = subprocess.run(connection.argv + [command], capture_output=True, timeout=30) + if result.returncode: + raise RemoteError("Could not read the selected unit's runtime ADT") + return result.stdout + + def put_scripts(connection): """install_device.py and the boot-entries script it runs, from this CLI.""" put(connection, SCRIPT.read_bytes(), SCRIPT.name) diff --git a/src/orchard/manifests.py b/src/orchard/manifests.py index 02076d61..b9528d82 100644 --- a/src/orchard/manifests.py +++ b/src/orchard/manifests.py @@ -96,6 +96,13 @@ def validate(document, *, schema=None): error = errors[0] location = '.'.join(map(str, error.absolute_path)) or '' raise ManifestError(f'{location}: {error.message}') + if kind == 'orchard.install' and document.get('root', {}).get('format') == 'blocks': + if 'install_tools' not in document: + raise ManifestError('Block-image installation requires install_tools') + if 'map' not in document['root']: + raise ManifestError('Block-image installation requires root.map') + if ('m1n1' in document) == ('cascadia' in document): + raise ManifestError('Block-image installation requires exactly one of m1n1 or cascadia') for where, source in sources(document): check_source(source, where) if kind == 'hardware.device': diff --git a/src/orchard/recipe.py b/src/orchard/recipe.py index e2a118e9..bcc15ee8 100644 --- a/src/orchard/recipe.py +++ b/src/orchard/recipe.py @@ -20,6 +20,10 @@ def _bluetool_hcd(step, data, expected): return bluetool.hcd_from_binary(data, expected) +def _bluetool_regulatory(step, data, expected): + return bluetool.regulatory_from_binary(data, step['address'], step['size'], expected) + + def _trx(step, data, expected): firmware, nvram = data return trx.add_nvram(firmware, nvram, step['placeholder_mac']) @@ -113,6 +117,7 @@ def _z2fw_mtfw(step, data, expected): 'trx-add-nvram@1': (_trx, {'nvram': str, 'placeholder_mac': str}), 'sgx543-from-kernelcache@1': (_sgx, {'build': str}), 'bluetool-hcd@1': (_bluetool_hcd, {}), + 'bluetool-regulatory@1': (_bluetool_regulatory, {'address': int, 'size': int}), # T8010 SmartIO kext (iPad 6/7, iPhone 7). 'smartio-from-kernelcache@1': (_smartio, {}), # SmartIO kext named by bundle identifier (S8000 for A9). diff --git a/src/orchard/service.py b/src/orchard/service.py index 064ef7d7..72f56582 100644 --- a/src/orchard/service.py +++ b/src/orchard/service.py @@ -193,6 +193,13 @@ def check_started(connection, user, ready, progress, seconds=180, *, hosts=None, if ready else 'The system did not answer over SSH within 3 minutes') +def install_mixin(adapter, connection, firmware, directory): + if adapter.PROFILE != 'j120': + return adapter.prepare_mixin(firmware, directory) + tree = remote.read_unit_adt(connection) + return adapter.prepare_mixin(firmware, directory, unit_adt=tree, ecid=connection.scope.device.ecid) + + def install_direct(adapter, device, name, files, firmware_files, boot_files, chain_files, secrets, answered, *, clock, input_fn, secrets_fn, progress): """An install from a block image: no recovery, see install_direct.py.""" @@ -239,7 +246,7 @@ def install_direct(adapter, device, name, files, firmware_files, boot_files, cha root = record['assets']['root'] progress.section('Installing ' + name) progress.step('Preparing the installation') - mixin, mixin_record = adapter.prepare_mixin(firmware, Path(directory) / 'mixin') + mixin, mixin_record = install_mixin(adapter, connection, firmware, Path(directory) / 'mixin') remote.put(connection, mixin.read_bytes(), 'firmware.tar.gz') layer = record['assets']['layer'] remote.put(connection, assets['layer'].read_bytes(), 'platform.tar.gz', timeout=600) @@ -413,7 +420,7 @@ def install(manifest=None, *, input_fn=input, secrets_fn=ask_secrets, progress=N progress.section('Installing ' + name) progress.step('Preparing the installation') with tempfile.TemporaryDirectory(prefix='installation-', dir=private) as directory: - mixin, mixin_record = adapter.prepare_mixin(firmware, Path(directory) / 'mixin') + mixin, mixin_record = install_mixin(adapter, connection, firmware, Path(directory) / 'mixin') remote.put(connection, mixin.read_bytes(), 'firmware.tar.gz') layer = record['assets']['layer'] remote.put(connection, assets['layer'].read_bytes(), 'platform.tar.gz', timeout=600) diff --git a/system/defaults/usr/lib/orchard/reprobe-j120-charger b/system/defaults/usr/lib/orchard/reprobe-j120-charger new file mode 100755 index 00000000..9232b124 --- /dev/null +++ b/system/defaults/usr/lib/orchard/reprobe-j120-charger @@ -0,0 +1,3 @@ +#!/bin/sh +# Kernel device names arrive as one udev argument. +printf '%s' "$1" > /sys/bus/platform/drivers_probe diff --git a/system/defaults/usr/lib/udev/rules.d/71-orchard-j120-charger.rules b/system/defaults/usr/lib/udev/rules.d/71-orchard-j120-charger.rules new file mode 100644 index 00000000..b7abf7d9 --- /dev/null +++ b/system/defaults/usr/lib/udev/rules.d/71-orchard-j120-charger.rules @@ -0,0 +1,3 @@ +# The built-in driver can probe before the installed root supplies this +# unit's calibration. Retry an unbound charger during rootfs coldplug. +ACTION=="add", SUBSYSTEM=="platform", ENV{OF_COMPATIBLE_0}=="apple,d2355-tristar-charger", TEST!="driver", TEST=="/lib/firmware/apple/j120/usb-input-limit-calibration-hv.bin", RUN+="/usr/lib/orchard/reprobe-j120-charger %k" diff --git a/system/defaults/usr/share/alsa/ucm2/Orchard/j120/HiFi.conf b/system/defaults/usr/share/alsa/ucm2/Orchard/j120/HiFi.conf new file mode 100644 index 00000000..6f9ba5a8 --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/Orchard/j120/HiFi.conf @@ -0,0 +1,24 @@ +# J120 MCA4 and CS42L83: stereo playback on PCM 0. +SectionVerb { + Value.TQ "HiFi" +} + +SectionDevice."Headphones" { + Comment "Headphones" + + EnableSequence [ + cset "name='Jack Mixer Volume' 43" + cset "name='Headphones Switch' on" + ] + DisableSequence [ + cset "name='Headphones Switch' off" + ] + + Value { + PlaybackPriority 200 + PlaybackPCM "hw:${CardId},0" + PlaybackChannels 2 + PlaybackMixerElem "Jack Mixer" + JackControl "cs42l83.1-0048-jack Jack" + } +} diff --git a/system/defaults/usr/share/alsa/ucm2/Orchard/j120/Speakers.conf b/system/defaults/usr/share/alsa/ucm2/Orchard/j120/Speakers.conf new file mode 100644 index 00000000..081636cd --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/Orchard/j120/Speakers.conf @@ -0,0 +1,13 @@ +SectionVerb { + Value.TQ "HiFi" +} + +SectionDevice."Speaker" { + Comment "Built-in speakers" + Value { + PlaybackPCM "hw:${CardId},0" + PlaybackChannels 4 + PlaybackRate 48000 + PlaybackPriority 100 + } +} diff --git a/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Headphones.conf b/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Headphones.conf new file mode 100644 index 00000000..e4f95f4c --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Headphones.conf @@ -0,0 +1,6 @@ +Syntax 4 + +SectionUseCase."HiFi" { + Comment "Headphones" + File "/Orchard/j120/HiFi.conf" +} diff --git a/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Speakers.conf b/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Speakers.conf new file mode 100644 index 00000000..bc270c54 --- /dev/null +++ b/system/defaults/usr/share/alsa/ucm2/conf.d/simple-card/J120 Speakers.conf @@ -0,0 +1,6 @@ +Syntax 4 + +SectionUseCase."HiFi" { + Comment "Built-in speakers" + File "/Orchard/j120/Speakers.conf" +} diff --git a/tests/test_catalog.py b/tests/test_catalog.py index 30b9f79b..4b3aceba 100644 --- a/tests/test_catalog.py +++ b/tests/test_catalog.py @@ -246,7 +246,7 @@ def test_the_boards_with_every_requirement_can_install(self): from orchard import hardware boards = {path.parent.name for path in DESCRIPTORS if not hardware.install_blockers(path.parent.name)} self.assertEqual(boards, {'d10', 'd101', 'd11', 'd111', 'd20', 'd201', 'd21', 'd211', 'd22', 'd221', - 'j171', 'j172', 'j71b', 'j71t', 'j72', 'j72b', 'j72t', 'j81'}) + 'j120', 'j171', 'j172', 'j71b', 'j71t', 'j72', 'j72b', 'j72t', 'j81'}) def test_data_can_name_a_method_this_code_does_not_implement(self): from orchard import hardware diff --git a/tools/catalog/drivers.json b/tools/catalog/drivers.json index 383c7051..8ff15c23 100644 --- a/tools/catalog/drivers.json +++ b/tools/catalog/drivers.json @@ -108,10 +108,24 @@ "wifi" ], "j120": [ + "accelerometer", + "audio_input", + "audio_output", "backlight", + "battery", + "bluetooth_audio", + "bluetooth_input", "buttons", + "charging", + "gyroscope", + "light_sensor", + "storage_read", + "storage_write", + "touch", "usb_network", - "usb_serial" + "usb_serial", + "video_decode_hevc", + "wifi" ], "j121": [ "backlight", diff --git a/tools/catalog/feature-drivers.toml b/tools/catalog/feature-drivers.toml index 54d4354d..7005fe70 100644 --- a/tools/catalog/feature-drivers.toml +++ b/tools/catalog/feature-drivers.toml @@ -7,7 +7,7 @@ buttons = ["gpio_keys"] backlight = ["apple_dwi_bl", "apple_pmic_bl", "apple_dsi_bl"] accelerometer = ["apple_aop_accel"] gyroscope = ["apple_aop_gyro"] -light_sensor = ["tsl2583"] +light_sensor = ["tsl2583", "ams_ct709"] storage_read = ["nvme_apple", "pcie_apple_h9p:apple,nvme-hmb"] storage_write = ["nvme_apple", "pcie_apple_h9p:apple,nvme-hmb"] wifi = ["pci_pwrctrl_apple_wifi"]