From de80616b4d0ca6cb9cf7616e33997001b7640791 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:54 +0100 Subject: [PATCH 001/112] dt-bindings: apple: Add the T8152 AOP and its audio service The T8152 (M6) Always-On Processor differs from the T8140 one: its setup port is not reachable from the AP, so it has one mailbox, and its audio service uses six serializer power domains and the jack, speaker and speaker-sense ADMAC channels. Signed-off-by: Thomas Glanzmann --- .../bindings/soc/apple/apple,t8152-aop.yaml | 80 ++++++++++++++++++ .../bindings/sound/apple,t8152-aop-audio.yaml | 82 +++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/apple/apple,t8152-aop.yaml create mode 100644 Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8152-aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8152-aop.yaml new file mode 100644 index 0000000000000..de41937be0259 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8152-aop.yaml @@ -0,0 +1,80 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/apple/apple,t8152-aop.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 Always-On Processor + +maintainers: + - Thomas Glanzmann + +description: + The Always-On Processor provides audio services through firmware loaded by + the bootloader. Unlike on T8140, its setup port is not reachable from the + application processor, so only the primary mailbox is described. + +properties: + compatible: + const: apple,t8152-aop + + reg: + items: + - description: AOP register and boot-argument window + - description: ASC wrapper and processor control registers + + reg-names: + items: + - const: mmio + - const: asc + + mboxes: + maxItems: 1 + + mbox-names: + items: + - const: mbox + + iommus: + maxItems: 1 + + apple,dma-range: + $ref: /schemas/types.yaml#/definitions/uint64-array + minItems: 2 + maxItems: 2 + description: + Host DMA allocation window as a base and nonzero size. The window must + occupy root slots available to the host on this AOP DART stream. + + audio: + type: object + $ref: /schemas/sound/apple,t8152-aop-audio.yaml# + +required: + - compatible + - reg + - reg-names + - mboxes + - mbox-names + - iommus + - apple,dma-range + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + aop@310c00000 { + compatible = "apple,t8152-aop"; + reg = <0x3 0x10c00000 0x0 0x1e0000>, + <0x3 0x10600000 0x0 0x4000>; + reg-names = "mmio", "asc"; + mboxes = <&aop_mbox>; + mbox-names = "mbox"; + iommus = <&sbr_dart 0>; + apple,dma-range = <0x110 0x0 0x10 0x0>; + }; + }; diff --git a/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml new file mode 100644 index 0000000000000..fa643fe62a9df --- /dev/null +++ b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/sound/apple,t8152-aop-audio.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 AOP audio + +maintainers: + - Thomas Glanzmann + +description: + Audio services of the T8152 Always-On Processor firmware, a child of the + AOP node. The firmware owns the audio fabric; the host feeds and drains the + serializers through ADMAC channels. + +allOf: + - $ref: dai-common.yaml# + +properties: + compatible: + const: apple,t8152-aop-audio + + dmas: + items: + - description: Headset jack output + - description: Headset microphone input + - description: Internal speaker output + - description: Speaker sense input + + dma-names: + items: + - const: cout + - const: cin + - const: spkr + - const: sense + + power-domains: + items: + - description: Serializer 0 + - description: Serializer 1 + - description: Serializer 2 + - description: Serializer 3 + - description: Serializer 4 + - description: Serializer 5 + + power-domain-names: + items: + - const: mca0 + - const: mca1 + - const: mca2 + - const: mca3 + - const: mca4 + - const: mca5 + + "#sound-dai-cells": + const: 1 + description: + AOP audio DAI identifier. 0 is the headset back-end, 3 the speaker + back-end. + +required: + - compatible + - dmas + - dma-names + - power-domains + - power-domain-names + - "#sound-dai-cells" + +unevaluatedProperties: false + +examples: + - | + audio { + compatible = "apple,t8152-aop-audio"; + dmas = <&admac 10>, <&admac 11>, <&admac 2>, <&admac 3>; + dma-names = "cout", "cin", "spkr", "sense"; + power-domains = <&ps_mca0>, <&ps_mca1>, <&ps_mca2>, + <&ps_mca3>, <&ps_mca4>, <&ps_mca5>; + power-domain-names = "mca0", "mca1", "mca2", "mca3", "mca4", "mca5"; + #sound-dai-cells = <1>; + }; From 3fd4c1beb0192540dcdb4439c99ef69be930200c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:54 +0100 Subject: [PATCH 002/112] dt-bindings: sound: apple,macaudio: Add J873 Add the Mac mini M6 (J873) sound card. Signed-off-by: Thomas Glanzmann --- Documentation/devicetree/bindings/sound/apple,macaudio.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml index e593b7b6d68c4..4ce5f8f2f0a8b 100644 --- a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml @@ -27,6 +27,7 @@ properties: - apple,j700-macaudio - apple,j713-macaudio - apple,j713-macaudio-jack + - apple,j873-macaudio - const: apple,macaudio "#address-cells": From 8dd4d517119dd14590ab7dd61e575144ef9f08c9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:31 +0100 Subject: [PATCH 003/112] soc: apple: aop: support T8152 The J873 (Mac mini M6) AOP runs the same firmware generation as T8140 (EPIC v4, iBoot-loaded, started by the AP), but the T8140 "setup port" is not reachable from the AP: mailbox 1 of the AOP's mailbox bank and the ADT aop-exclave-mailbox both bus-error. The firmware boots without it: RTKit protocol 12, then its "audio" EPIC service. Add apple,t8152-aop with the T8140 configuration minus the setup port, starting every advertised endpoint. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/aop.rs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 20e78e2b542cb..73df7cf27deaa 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -2665,6 +2665,20 @@ const HW_CFG_T8140: AopHwConfig = AopHwConfig { bootargs_word_access: false, halt_on_failed_start: false, }; +/// T8152: like T8140, but the setup port (mailbox 1 of the AOP bank, and the +/// ADT aop-exclave-mailbox) is not reachable from the AP: both bus-error. +const HW_CFG_T8152: AopHwConfig = AopHwConfig { + ec0p: 0, + aopt: 0, + alig: 0, + patch_bootargs: false, + epic_v4: true, + setup_port: false, + quiesce_on_unbind: true, + required_endpoints: &[], + fw_regions: false, + halt_on_failed_start: false, +}; kernel::of_device_table!( OF_TABLE, @@ -2677,6 +2691,7 @@ kernel::of_device_table!( (of::DeviceId::new(c_str!("apple,t8140-aop")), &HW_CFG_T8140), (of::DeviceId::new(c_str!("apple,t6041-aop")), &HW_CFG_T6040), (of::DeviceId::new(c_str!("apple,t8132-aop")), &HW_CFG_T8132), + (of::DeviceId::new(c_str!("apple,t8152-aop")), &HW_CFG_T8152), ] ); From 53a18f3f84a740088484f9670f5d3d4a8201b464 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:16:38 +0100 Subject: [PATCH 004/112] dt-bindings: sound: ti,tas27xx: add ti,bclk-ratio The Mac mini (M6, J873) speaker runs a 250-BCLK TDM frame, which the SN012776's ratio auto-detection rejects. Describe the property that fixes the ratio instead. Signed-off-by: Thomas Glanzmann --- Documentation/devicetree/bindings/sound/ti,tas27xx.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/ti,tas27xx.yaml b/Documentation/devicetree/bindings/sound/ti,tas27xx.yaml index e9a7e87325448..2a02a98ae7ce9 100644 --- a/Documentation/devicetree/bindings/sound/ti,tas27xx.yaml +++ b/Documentation/devicetree/bindings/sound/ti,tas27xx.yaml @@ -122,6 +122,14 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 description: TDM TX voltage sense time slot. + ti,bclk-ratio: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [250] + description: + Fixed BCLK/FS ratio of the TDM frame, for a frame the amplifier's ratio + auto-detection does not accept (250 BCLKs on the Mac mini (M6, J873) + speaker). + '#sound-dai-cells': # The codec has a single DAI, the #sound-dai-cells=<1>; case is left in for backward # compatibility but is deprecated. From 9415ba9f8d608f35770436be3013fd82a3c0266d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:31 +0100 Subject: [PATCH 005/112] ASoC: tas2764: support a fixed BCLK/FS ratio The J873 (Mac mini M6) AOP runs the speaker frame at 250 BCLKs of 12 MHz. The SN012776 cannot auto-detect that ratio and mutes with "fault: bad TDM clock". With TAS2764_CLK_CFG (register 0x60) set to 0x30 and TDM_CFG0 bit 6 set it accepts the frame and plays. Do that when the new ti,bclk-ratio property names the ratio; only this one ratio is supported. Source of the value: the register write was first seen in the macOS SN012776 driver; it is a single register value, and its effect (no fault, correct playback) was verified on J873 hardware. No table or code was taken from macOS. The field is initialised in probe, so non-OF matches keep auto-detection. Signed-off-by: Thomas Glanzmann --- sound/soc/codecs/tas2764.c | 41 ++++++++++++++++++++++++++++++++++++++ sound/soc/codecs/tas2764.h | 8 ++++++++ 2 files changed, 49 insertions(+) diff --git a/sound/soc/codecs/tas2764.c b/sound/soc/codecs/tas2764.c index c7886269a2dd4..3cec2ba9da430 100644 --- a/sound/soc/codecs/tas2764.c +++ b/sound/soc/codecs/tas2764.c @@ -66,6 +66,8 @@ struct tas2764_priv { int v_sense_slot; int i_sense_slot; + /* TAS2764_CLK_CFG value for a fixed BCLK/FS ratio, or -1 to auto-detect */ + int bclk_ratio_code; bool dac_powered; bool unmuted; @@ -1155,6 +1157,19 @@ static int tas2764_codec_probe(struct snd_soc_component *component) break; } + if (tas2764->bclk_ratio_code >= 0) { + ret = snd_soc_component_write(component, TAS2764_CLK_CFG, + tas2764->bclk_ratio_code); + if (ret < 0) + return ret; + + ret = snd_soc_component_update_bits(component, TAS2764_TDM_CFG0, + TAS2764_TDM_CFG0_FIXED_RATIO, + TAS2764_TDM_CFG0_FIXED_RATIO); + if (ret < 0) + return ret; + } + /* * Last, so that no failure leaves the handler behind. The component owns the IRQ and * the remove frees it; not a devres of the I2C device, which outlives the component @@ -1407,9 +1422,24 @@ static int tas2764_parse_tx_zd_config(struct device *dev, struct tas2764_priv *t return 0; } +/* + * BCLK/FS ratios and the TAS2764_CLK_CFG value that makes the amplifier + * accept them. Only the J873 speaker frame (250 BCLKs, which the ratio + * auto-detection rejects with "bad TDM clock") is verified on hardware; + * other ratios are left to the auto-detection. + */ +static const struct { + u16 ratio; + u8 code; +} tas2764_bclk_ratio_codes[] = { + { 250, 0x30 }, +}; + static int tas2764_parse_dt(struct device *dev, struct tas2764_priv *tas2764) { + u32 ratio; int ret = 0; + int i; /* * The SDZ supply is optional: most boards drive SDZ from a GPIO @@ -1467,6 +1497,15 @@ static int tas2764_parse_dt(struct device *dev, struct tas2764_priv *tas2764) if (ret) return ret; + if (!fwnode_property_read_u32(dev->fwnode, "ti,bclk-ratio", &ratio)) { + for (i = 0; i < ARRAY_SIZE(tas2764_bclk_ratio_codes); i++) + if (tas2764_bclk_ratio_codes[i].ratio == ratio) + tas2764->bclk_ratio_code = tas2764_bclk_ratio_codes[i].code; + if (tas2764->bclk_ratio_code < 0) + return dev_err_probe(dev, -EINVAL, + "unsupported ti,bclk-ratio %u\n", ratio); + } + return tas2764_group_join(dev, tas2764); } @@ -1488,6 +1527,8 @@ static int tas2764_i2c_probe(struct i2c_client *client) result = devm_mutex_init(&client->dev, &tas2764->fault_lock); if (result) return result; + /* Auto-detect the ratio unless the firmware node sets one. */ + tas2764->bclk_ratio_code = -1; i2c_set_clientdata(client, tas2764); dev_set_drvdata(&client->dev, tas2764); diff --git a/sound/soc/codecs/tas2764.h b/sound/soc/codecs/tas2764.h index e6c6b064d6cc2..7f72f99734512 100644 --- a/sound/soc/codecs/tas2764.h +++ b/sound/soc/codecs/tas2764.h @@ -58,6 +58,12 @@ #define TAS2764_TDM_CFG0_44_1_48KHZ BIT(3) #define TAS2764_TDM_CFG0_88_2_96KHZ (BIT(3) | BIT(1)) #define TAS2764_TDM_CFG0_FRAME_START BIT(0) +/* + * Set by the macOS SN012776 driver together with an explicit BCLK/FS + * ratio in TAS2764_CLK_CFG; without it the ratio is auto-detected, which + * fails ("bad TDM clock") for frames such as 250 BCLKs. + */ +#define TAS2764_TDM_CFG0_FIXED_RATIO BIT(6) /* TDM Configuration Reg1 */ #define TAS2764_TDM_CFG1 TAS2764_REG(0X0, 0x09) @@ -123,6 +129,8 @@ /* Clock/IRQ Settings */ #define TAS2764_INT_CLK_CFG TAS2764_REG(0x0, 0x5c) +/* BCLK/FS ratio code, written by macOS for the J873 speaker frame */ +#define TAS2764_CLK_CFG TAS2764_REG(0x0, 0x60) #define TAS2764_INT_CLK_CFG_IRQZ_CLR BIT(2) #define TAS2764_BOP_CFG0 TAS2764_REG(0X0, 0x1d) From 4579f2e7936b7f504e754a6c2881ef0f1f439041 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 1 Nov 2026 21:36:59 +0100 Subject: [PATCH 006/112] ASoC: cs42l84: Route SDOUT1 from the ASP input The SDOUT1 mux offers the ASP receive channels as a source, but no DAPM route connected them, so selecting "ASP RX CH1" or "ASP RX CH2" left the capture path without an input. The J873 and J813 AOP audio services use it to loop the playback stream back. Signed-off-by: Thomas Glanzmann --- sound/soc/codecs/cs42l84.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sound/soc/codecs/cs42l84.c b/sound/soc/codecs/cs42l84.c index 022420be6bfb5..07a47433ef4d9 100644 --- a/sound/soc/codecs/cs42l84.c +++ b/sound/soc/codecs/cs42l84.c @@ -279,6 +279,8 @@ static const struct snd_soc_dapm_route cs42l84_audio_map[] = { {"ADC", NULL, "HS"}, {"SDOUT1 Select", "ADC", "ADC"}, + {"SDOUT1 Select", "ASP RX CH1", "SDIN1"}, + {"SDOUT1 Select", "ASP RX CH2", "SDIN2"}, {"SDOUT1", NULL, "SDOUT1 Select"}, {"Capture", NULL, "SDOUT1"}, From 7981f33f77bd186b4b68fb1e22e74eb3aaa4594c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:31 +0100 Subject: [PATCH 007/112] ASoC: apple: add the T8152 AOP audio driver On T8152 (J873, Mac mini M6) the AOP firmware owns the audio fabric, as on T8140. Its "audio" EPIC service offers cout/cin (the CS42L84 jack, base-ns ADMAC TX5/RX5, MCA4) and spkr (the SN012776 speaker, TX1, MCA0). Each service is an ASoC back-end DAI: startup attaches it, requests pw0 (which raises the audio fabric) and powers the MCA leaves, all of which are required. pwrd starts the serializer clocks at prepare, before ASoC unmutes the codecs: the jack codec locks its PLL to the bit clock, and the speaker amplifier reports "bad TDM clock" whenever it runs without one. The jack restarts its clocks on every prepare so that a stream restarted after an underrun begins on a frame boundary; the mono speaker (one slot per frame) keeps them running. The front-ends are dmaengine PCMs on the base-ns channels: the jack in stereo, the speaker in mono (its serializer runs one 32-bit slot; stereo frames play at half pitch). The firmware's serializer configuration (property 701) is byte-identical to the one macOS publishes, so the driver leaves it alone. Signed-off-by: Thomas Glanzmann --- sound/soc/apple/Kconfig | 11 + sound/soc/apple/Makefile | 3 + sound/soc/apple/t8152_aop_audio.rs | 995 +++++++++++++++++++++++++++++ 3 files changed, 1009 insertions(+) create mode 100644 sound/soc/apple/t8152_aop_audio.rs diff --git a/sound/soc/apple/Kconfig b/sound/soc/apple/Kconfig index 92ffcb6073797..74ea1fe4de8e8 100644 --- a/sound/soc/apple/Kconfig +++ b/sound/soc/apple/Kconfig @@ -14,6 +14,17 @@ config SND_SOC_APPLE_AOP_AUDIO machines, and on T8140 the back-end DAIs for the headphone jack and the internal speaker, which the macaudio driver links into its card. +config SND_SOC_APPLE_T8152_AOP_AUDIO + tristate "Apple T8152 AOP audio driver" + depends on ARCH_APPLE || COMPILE_TEST + depends on RUST + select APPLE_AOP + select SND_DMAENGINE_PCM + help + This option enables a driver for the audio paths owned by the AOP + co-processor on Apple T8152 SoCs (Mac mini M6): the headphone jack + and the internal speaker. + config SND_SOC_APPLE_MCA tristate "Apple Silicon MCA driver" depends on ARCH_APPLE || COMPILE_TEST diff --git a/sound/soc/apple/Makefile b/sound/soc/apple/Makefile index 52d4abf30916b..71885319572cf 100644 --- a/sound/soc/apple/Makefile +++ b/sound/soc/apple/Makefile @@ -3,6 +3,9 @@ snd-soc-aop-y := aop_audio.o obj-$(CONFIG_SND_SOC_APPLE_AOP_AUDIO) += snd-soc-aop.o +snd-soc-t8152-aop-audio-y := t8152_aop_audio.o +obj-$(CONFIG_SND_SOC_APPLE_T8152_AOP_AUDIO) += snd-soc-t8152-aop-audio.o + snd-soc-apple-mca-y := mca.o obj-$(CONFIG_SND_SOC_APPLE_MCA) += snd-soc-apple-mca.o diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs new file mode 100644 index 0000000000000..31f562e7fc64d --- /dev/null +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -0,0 +1,995 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT + +//! Apple T8152 (J873, Mac mini M6) AOP audio +//! +//! The AOP firmware owns the audio fabric, as on T8140. The ADT +//! (/arm-io/iop-audio-controller) names its services; all of them run on the +//! base-ns ADMAC: +//! +//! * `cout`/`cin`: the CS42L84 headphone jack, base-ns TX5/RX5 (Linux +//! channels 10 and 11). +//! * `spkr`: the SN012776 speaker amplifier, base-ns TX1 (channel 2), its +//! sense data on RX1. +//! +//! Each service is an ASoC back-end DAI: startup attaches it and requests +//! `pw0 ` (which also brings up the audio fabric), prepare requests `pwrd` +//! (the firmware then runs the serializer and its clocks) and shutdown goes +//! back to `pw0 `. The serializer (MCA) leaves are the AP's to power. The +//! front-end PCMs are plain dmaengine PCMs on the base-ns channels; macaudio +//! links them to the codecs. +//! +//! Copyright (C) The Asahi Linux Contributors +//! Copyright (C) 2026 The Aurora Silicon Contributors + +use core::{mem, ptr, slice}; + +use kernel::{ + bindings, c_str, + device, + device::Core, + error::from_err_ptr, + module_platform_driver, of, platform, + prelude::*, + soc::apple::aop::{from_fourcc, EPICService, AOP}, + sync::{ + aref::ARef, + atomic::{Atomic, AtomicFlag, Relaxed}, + Arc, + }, + types::Opaque, +}; + +const EPIC_SUBTYPE_WRAPPED_CALL: u16 = 0x20; +const CALLTYPE_AUDIO_ATTACH_DEVICE: u32 = 0xc3000002; +const CALLTYPE_AUDIO_GET_PROP: u32 = 0xc3000004; +const CALLTYPE_AUDIO_SET_PROP: u32 = 0xc3000005; +const PROP_POWER_STATE: u32 = 200; +const PROP_POWER_REQUEST: u32 = 202; +const POWER_STATE_PW0: u32 = from_fourcc(b"pw0 "); +const POWER_STATE_PWRD: u32 = from_fourcc(b"pwrd"); +/// kIOReturnBusy: the device is already attached (a module reload). +const AUDIO_RET_BUSY: u32 = 0xe00002d5; +const AOP_TIMEBASE_HZ: u64 = 24_000_000; + +/// Leaf power-up attempts while the firmware raises the fabric after `pw0 `. +const PD_GET_ATTEMPTS: u32 = 60; +const PD_GET_RETRY_MS: i64 = 10; +/// The MCA serializer leaves (audio_mca0_m .. audio_mca5_m). +const MCA_COUNT: usize = 6; +const MCA_NAMES: [&CStr; MCA_COUNT] = [c"mca0", c"mca1", c"mca2", c"mca3", c"mca4", c"mca5"]; + +fn aop_timestamp() -> u64 { + // SAFETY: both helpers read the architected timer and take no arguments. + let (counter, rate) = + unsafe { (bindings::arch_timer_counter(), bindings::arch_timer_rate()) }; + let rate = u64::from(rate); + (counter / rate) * AOP_TIMEBASE_HZ + (counter % rate) * AOP_TIMEBASE_HZ / rate +} + +fn le_u32(buf: &[u8], off: usize) -> Result { + let b = buf.get(off..off + 4).ok_or(EINVAL)?; + Ok(u32::from_le_bytes([b[0], b[1], b[2], b[3]])) +} + +#[repr(C, packed(4))] +#[derive(Clone, Copy, Default)] +struct AudioAttachDevice { + _zero0: u32, + unk0: u32, + calltype: u32, + _zero1: [u8; 16], + cookie: u32, + len: u64, + dev_id: u32, + _zero2: u32, +} + +#[repr(C, packed(4))] +#[derive(Clone, Copy, Default)] +struct AudioGetDeviceProp { + _zero0: u32, + unk0: u32, + calltype: u32, + _zero1: [u8; 16], + _pad0: u32, + len: u64, + dev_id: u32, + modifier: u32, + unk6: u32, +} + +#[repr(C, packed(4))] +#[derive(Clone, Copy, Default)] +struct AudioSetDeviceProp { + _zero0: u32, + unk0: u32, + calltype: u32, + _zero1: [u8; 16], + _pad0: u32, + len: u64, + dev_id: u32, + modifier: u32, + len2: u32, + data: T, +} + +/// Property 202: the device, a per-device sequence, the request time in the +/// firmware's 24 MHz timebase and the target state. +#[repr(C, packed(4))] +#[derive(Clone, Copy, Default)] +struct PowerRequest { + dev_id: u32, + sequence: u32, + timestamp: u64, + _zero0: u32, + state: u32, + param: u32, + _zero1: [u8; 20], +} + +/// A named power domain of this device, runtime-powered around the streams +/// that need it. +struct PowerDomain { + dev: ptr::NonNull, +} + +// SAFETY: the virtual domain device belongs to the PM core, which serializes +// its runtime-PM state; this handle only passes the pointer to those calls. +unsafe impl Send for PowerDomain {} +// SAFETY: as for `Send`. +unsafe impl Sync for PowerDomain {} + +impl PowerDomain { + fn attach(dev: &device::Device, name: &CStr) -> Result> { + // SAFETY: `dev` is live for the call and `name` is NUL-terminated. + let pd = from_err_ptr(unsafe { + bindings::dev_pm_domain_attach_by_name(dev.as_raw(), name.as_char_ptr()) + })?; + Ok(ptr::NonNull::new(pd).map(|dev| PowerDomain { dev })) + } + + /// Takes a runtime-PM reference, retrying while the parent fabric that + /// the firmware brings up after `pw0 ` is still off. + fn get(&self) -> Result<()> { + let mut rc = 0; + for _ in 0..PD_GET_ATTEMPTS { + // SAFETY: the domain device stays attached for the lifetime of `self`. + rc = unsafe { bindings::pm_runtime_get_sync(self.dev.as_ptr()) }; + if rc >= 0 { + return Ok(()); + } + // SAFETY: as above; undo the usage count and the error state. + unsafe { + bindings::pm_runtime_put_noidle(self.dev.as_ptr()); + bindings::__pm_runtime_set_status( + self.dev.as_ptr(), + bindings::rpm_status_RPM_SUSPENDED as u32, + ); + } + kernel::time::delay::fsleep(kernel::time::Delta::from_millis(PD_GET_RETRY_MS)); + } + Err(Error::from_errno(rc)) + } + + fn put(&self) { + // SAFETY: the domain device stays attached for the lifetime of `self`. + unsafe { bindings::pm_runtime_put_sync(self.dev.as_ptr()) }; + } +} + +impl Drop for PowerDomain { + fn drop(&mut self) { + // SAFETY: attached in `attach`; every `get` has been balanced by then. + unsafe { bindings::dev_pm_domain_detach(self.dev.as_ptr(), true) }; + } +} + +/// One firmware audio service driven as an ASoC back-end. +struct Service { + dev_id: u32, + name: &'static str, + sequence: Atomic, + /// In `pwrd`. + running: AtomicFlag, + /// Stop and restart the serializer on every prepare, so that a stream + /// restarted after an underrun begins on a frame boundary. The mono + /// speaker has one slot per frame and keeps its clocks running instead: + /// its amplifier stays unmuted between prepares and reports "bad TDM + /// clock" whenever the bit clock stops under it. + restart_on_prepare: bool, +} + +impl Service { + const fn new(dev_id: u32, name: &'static str, restart_on_prepare: bool) -> Service { + Service { + dev_id, + name, + sequence: Atomic::new(0), + running: AtomicFlag::new(false), + restart_on_prepare, + } + } +} + +#[pin_data] +struct T8152AopAudio { + dev: ARef, + adata: Arc, + service: EPICService, + cout: Service, + cin: Service, + spkr: Service, + mca: KVec, +} + +impl T8152AopAudio { + fn call_ret(&self, data: &T, ret_len: usize) -> Result<(u32, KVec)> { + // SAFETY: T is a plain packed firmware record. + let msg = unsafe { + slice::from_raw_parts(ptr::from_ref(data).cast::(), mem::size_of::()) + }; + self.adata + .epic_call_ret(&self.service, EPIC_SUBTYPE_WRAPPED_CALL, msg, ret_len) + } + + fn call(&self, data: &T) -> Result { + // SAFETY: T is a plain packed firmware record. + let msg = unsafe { + slice::from_raw_parts(ptr::from_ref(data).cast::(), mem::size_of::()) + }; + self.adata + .epic_call(&self.service, EPIC_SUBTYPE_WRAPPED_CALL, msg) + } + + /// The firmware keeps attachments for its lifetime, so a module reload + /// sees kIOReturnBusy. + fn attach(&self, svc: &Service) -> Result<()> { + let ret = self.call(&AudioAttachDevice { + unk0: 0xffffffff, + calltype: CALLTYPE_AUDIO_ATTACH_DEVICE, + len: 0x2c, + dev_id: svc.dev_id, + ..Default::default() + })?; + match ret { + 0 | AUDIO_RET_BUSY => Ok(()), + _ => { + dev_err!(self.dev, "unable to attach {}: {:#x}\n", svc.name, ret); + Err(EIO) + } + } + } + + fn power_state(&self, svc: &Service) -> Result { + let (ret, data) = self.call_ret( + &AudioGetDeviceProp { + unk0: 0xffffffff, + calltype: CALLTYPE_AUDIO_GET_PROP, + len: 0x30, + dev_id: svc.dev_id, + modifier: PROP_POWER_STATE, + unk6: 1, + ..Default::default() + }, + 8, + )?; + if ret != 0 { + return Err(EIO); + } + le_u32(&data, 4) + } + + fn set_power(&self, svc: &Service, state: u32) -> Result<()> { + let req = PowerRequest { + dev_id: svc.dev_id, + sequence: svc.sequence.fetch_add(1, Relaxed) + 1, + timestamp: aop_timestamp(), + state, + ..Default::default() + }; + let ret = self.call(&AudioSetDeviceProp { + unk0: 0xffffffff, + calltype: CALLTYPE_AUDIO_SET_PROP, + len: mem::size_of::() as u64 + 0x30, + dev_id: svc.dev_id, + modifier: PROP_POWER_REQUEST, + len2: mem::size_of::() as u32, + data: req, + ..Default::default() + })?; + if ret != 0 { + dev_err!( + self.dev, + "{}: power request {:#x} rejected: {:#x}\n", + svc.name, + state, + ret + ); + return Err(EIO); + } + let now = self.power_state(svc)?; + if now != state { + dev_err!( + self.dev, + "{}: power state {:#x} after requesting {:#x}\n", + svc.name, + now, + state + ); + return Err(EIO); + } + Ok(()) + } + + fn mca_up(&self) -> Result<()> { + for (i, pd) in self.mca.iter().enumerate() { + if let Err(e) = pd.get() { + dev_err!(self.dev, "MCA leaf {} did not power up: {:?}\n", i, e); + for pd in self.mca[..i].iter().rev() { + pd.put(); + } + return Err(e); + } + } + Ok(()) + } + + fn mca_down(&self) { + for pd in self.mca.iter().rev() { + pd.put(); + } + } + + /// Back-end startup: attach, `pw0 ` (which raises the fabric), then the + /// serializer leaves. + fn startup(&self, svc: &Service) -> Result<()> { + self.attach(svc)?; + self.set_power(svc, POWER_STATE_PW0)?; + if let Err(e) = self.mca_up() { + let _ = self.set_power(svc, POWER_STATE_PW0); + return Err(e); + } + svc.running.store(false, Relaxed); + Ok(()) + } + + /// `pwrd`: the firmware starts the serializer clocks and the stream. + fn run(&self, svc: &Service) -> Result<()> { + if svc.running.load(Relaxed) { + return Ok(()); + } + self.set_power(svc, POWER_STATE_PWRD)?; + svc.running.store(true, Relaxed); + Ok(()) + } + + /// The clocks run from prepare on: the codecs see a bit clock as soon + /// as ASoC powers and unmutes them. A PCM underrun stops the DMA + /// without closing the back-end; a service that restarts on prepare + /// retires its run so that the next start begins afresh. + fn prepare(&self, svc: &Service) -> Result<()> { + if svc.restart_on_prepare && svc.running.load(Relaxed) { + self.set_power(svc, POWER_STATE_PW0)?; + svc.running.store(false, Relaxed); + } + self.run(svc) + } + + fn shutdown(&self, svc: &Service) { + if svc.running.load(Relaxed) { + if let Err(e) = self.set_power(svc, POWER_STATE_PW0) { + dev_err!(self.dev, "{}: pw0 failed: {:?}\n", svc.name, e); + } + svc.running.store(false, Relaxed); + } + self.mca_down(); + } +} + +// ---- the ASoC component ---- + +/// Front-end index of a runtime by CPU DAI id; back-ends have none. +const FE_DAI_ID_BASE: u32 = 1; +const FE_COUNT: usize = 3; +const BE_DAI_ID_COUT: u32 = 10; +const BE_DAI_ID_SPKR: u32 = 11; +/// DMA channel names (dma-names on the audio node) per front-end, [playback, +/// capture]: the jack, the speaker and the speaker's sense data. +const FE_DMA_NAMES: [[Option<&CStr>; 2]; FE_COUNT] = [ + [Some(c"cout"), Some(c"cin")], + [Some(c"spkr"), None], + [None, Some(c"sense")], +]; + +const PCM_BUFFER_MAX: usize = 1024 * 1024; +const PCM_PERIOD_BYTES_MIN: usize = 256; +const PCM_PERIOD_BYTES_MAX: usize = 0x10000; + +/// The AOP-run serializers take 24-bit samples in 32-bit words. +const FORMATS: u64 = bindings::BINDINGS_SNDRV_PCM_FMTBIT_S24_LE; + +/// # Safety +/// +/// `substream` must be live and belong to one of this component's links. +unsafe fn substream_rtd( + substream: *mut bindings::snd_pcm_substream, +) -> *mut bindings::snd_soc_pcm_runtime { + // SAFETY: by the caller's contract. + unsafe { (*substream).private_data.cast() } +} + +/// # Safety +/// +/// `rtd` must be a live ASoC runtime. +unsafe fn rtd_is_be(rtd: *mut bindings::snd_soc_pcm_runtime) -> bool { + // SAFETY: by the caller's contract. + unsafe { (*(*rtd).dai_link).no_pcm() != 0 } +} + +/// # Safety +/// +/// `rtd` must be a live ASoC runtime of one of this component's links. +unsafe fn fe_index(rtd: *mut bindings::snd_soc_pcm_runtime) -> Option { + // SAFETY: by the caller's contract. + let id = unsafe { (**(*rtd).dais).id } as u32; + if (FE_DAI_ID_BASE..FE_DAI_ID_BASE + FE_COUNT as u32).contains(&id) { + Some((id - FE_DAI_ID_BASE) as usize) + } else { + None + } +} + +/// # Safety +/// +/// `substream` must be live. +unsafe fn is_playback(substream: *mut bindings::snd_pcm_substream) -> bool { + // SAFETY: by the caller's contract. + unsafe { (*substream).stream == bindings::SNDRV_PCM_STREAM_PLAYBACK as i32 } +} + +/// The context behind the component's descriptor (its first field). +#[repr(C)] +struct AsocContext { + component: bindings::snd_soc_component_driver, + data: Arc, + dais: KBox>, + _ops: KBox, +} + +const _: () = assert!(mem::offset_of!(AsocContext, component) == 0); + +/// # Safety +/// +/// `component` must be this driver's live registered component. +unsafe fn component_data<'a>(component: *mut bindings::snd_soc_component) -> &'a T8152AopAudio { + // SAFETY: by the caller's contract; C keeps the descriptor pointer we + // registered, which is the start of the `AsocContext`. + unsafe { &(*(*component).driver.cast::()).data } +} + +/// # Safety +/// +/// `dai` must be a live DAI of this driver's registered component. +unsafe fn dai_data<'a>(dai: *mut bindings::snd_soc_dai) -> &'a T8152AopAudio { + // SAFETY: by the caller's contract. + unsafe { component_data((*dai).component) } +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_open( + component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, +) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { component_data(component) }; + // SAFETY: as above. + let rtd = unsafe { substream_rtd(substream) }; + // SAFETY: as above. + if unsafe { rtd_is_be(rtd) } { + return 0; + } + // SAFETY: as above. + let Some(fe) = (unsafe { fe_index(rtd) }) else { + return EINVAL.to_errno(); + }; + // SAFETY: as above. + let playback = unsafe { is_playback(substream) }; + let Some(name) = FE_DMA_NAMES[fe][usize::from(!playback)] else { + return ENODEV.to_errno(); + }; + // SAFETY: the device is live and the name is NUL-terminated. + let chan = match from_err_ptr(unsafe { + bindings::dma_request_chan(data.dev.as_raw(), name.as_char_ptr()) + }) { + Ok(chan) => chan, + Err(e) => { + dev_err!(data.dev, "DMA channel {:?} unavailable: {:?}\n", name, e); + return e.to_errno(); + } + }; + let mut hw = bindings::snd_pcm_hardware { + info: bindings::SNDRV_PCM_INFO_MMAP + | bindings::SNDRV_PCM_INFO_MMAP_VALID + | bindings::SNDRV_PCM_INFO_INTERLEAVED, + buffer_bytes_max: PCM_BUFFER_MAX, + period_bytes_min: PCM_PERIOD_BYTES_MIN, + period_bytes_max: PCM_PERIOD_BYTES_MAX, + periods_min: 2, + periods_max: (PCM_BUFFER_MAX / PCM_PERIOD_BYTES_MIN) as u32, + fifo_size: 16, + ..Default::default() + }; + // SAFETY: the substream and the channel are live. + let ret = unsafe { + let mut ret = 0; + if (*substream).dma_buffer.dev.type_ == bindings::SNDRV_DMA_TYPE_UNKNOWN as i32 { + ret = bindings::snd_pcm_set_managed_buffer( + substream, + bindings::SNDRV_DMA_TYPE_DEV as i32, + (*(*chan).device).dev, + 0, + 0, + ); + } + if ret == 0 { + let mut dma_data = bindings::snd_dmaengine_dai_dma_data::default(); + ret = bindings::snd_dmaengine_pcm_refine_runtime_hwparams( + substream, + &mut dma_data, + &mut hw, + chan, + ); + } + if ret == 0 { + hw.formats &= FORMATS; + (*(*substream).runtime).hw = hw; + ret = bindings::snd_dmaengine_pcm_open(substream, chan); + } + ret + }; + if ret < 0 { + // SAFETY: the open failed, so the channel is still ours. + unsafe { bindings::dma_release_channel(chan) }; + } + ret +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_close( + _component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, +) -> i32 { + // SAFETY: by the caller's contract. + if unsafe { rtd_is_be(substream_rtd(substream)) } { + return 0; + } + // SAFETY: the dmaengine runtime was set up in `asoc_pcm_open`. + unsafe { bindings::snd_dmaengine_pcm_close_release_chan(substream) } +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_hw_params( + _component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, + params: *mut bindings::snd_pcm_hw_params, +) -> i32 { + // SAFETY: by the caller's contract. + if unsafe { rtd_is_be(substream_rtd(substream)) } { + return 0; + } + // SAFETY: the dmaengine runtime was set up in `asoc_pcm_open`. + let chan = unsafe { bindings::snd_dmaengine_pcm_get_chan(substream) }; + let mut cfg = bindings::dma_slave_config::default(); + // SAFETY: the substream and the parameters are live for the op. + let rc = unsafe { bindings::snd_hwparams_to_dma_slave_config(substream, params, &mut cfg) }; + if rc < 0 { + return rc; + } + // SAFETY: ASoC calls hw_params with live parameters. + let channels = unsafe { + (*params).intervals[(bindings::SNDRV_PCM_HW_PARAM_CHANNELS + - bindings::SNDRV_PCM_HW_PARAM_FIRST_INTERVAL) as usize] + .min + }; + // One frame per burst, up to four words. + let window = core::cmp::min(channels, 4); + // SAFETY: the substream is live. + if unsafe { is_playback(substream) } { + cfg.dst_port_window_size = window; + } else { + cfg.src_port_window_size = window; + } + // SAFETY: `chan` is the live channel behind the substream. + unsafe { + match (*(*chan).device).device_config { + Some(f) => f(chan, &mut cfg), + None => ENOSYS.to_errno(), + } + } +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_trigger( + _component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, + cmd: i32, +) -> i32 { + // SAFETY: by the caller's contract. + if unsafe { rtd_is_be(substream_rtd(substream)) } { + return 0; + } + // SAFETY: the dmaengine runtime was set up in `asoc_pcm_open`. + unsafe { bindings::snd_dmaengine_pcm_trigger(substream, cmd) } +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_pointer( + _component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, +) -> bindings::snd_pcm_uframes_t { + // SAFETY: by the caller's contract. + if unsafe { rtd_is_be(substream_rtd(substream)) } { + return (-i64::from(bindings::ENOTSUPP)) as bindings::snd_pcm_uframes_t; + } + // SAFETY: the dmaengine runtime was set up in `asoc_pcm_open`. + unsafe { bindings::snd_dmaengine_pcm_pointer(substream) } +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component. +unsafe extern "C" fn dai_accept_fmt(_dai: *mut bindings::snd_soc_dai, _fmt: u32) -> i32 { + // The firmware runs the serializers; format, slots and clocks are its. + 0 +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component. +unsafe extern "C" fn dai_accept_sysclk( + _dai: *mut bindings::snd_soc_dai, + _id: i32, + _freq: u32, + _dir: i32, +) -> i32 { + 0 +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component. +unsafe extern "C" fn dai_accept_bclk_ratio(_dai: *mut bindings::snd_soc_dai, _ratio: u32) -> i32 { + 0 +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component. +unsafe extern "C" fn dai_accept_tdm_slot( + _dai: *mut bindings::snd_soc_dai, + _tx_mask: u32, + _rx_mask: u32, + _slots: i32, + _slot_width: i32, +) -> i32 { + 0 +} + +/// The back-end's service for a stream; `None` for the speaker's sense +/// capture, which runs with the speaker's playback. +/// +/// # Safety +/// +/// `dai` must be a live DAI of this component, `substream` live. +unsafe fn be_service<'a>( + dai: *mut bindings::snd_soc_dai, + substream: *mut bindings::snd_pcm_substream, +) -> Option<(&'a T8152AopAudio, &'a Service)> { + // SAFETY: by the caller's contract. + let (data, id, playback) = unsafe { (dai_data(dai), (*dai).id as u32, is_playback(substream)) }; + let svc = match (id, playback) { + (BE_DAI_ID_COUT, true) => &data.cout, + (BE_DAI_ID_COUT, false) => &data.cin, + (BE_DAI_ID_SPKR, true) => &data.spkr, + _ => return None, + }; + Some((data, svc)) +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component and a live substream. +unsafe extern "C" fn be_startup( + substream: *mut bindings::snd_pcm_substream, + dai: *mut bindings::snd_soc_dai, +) -> i32 { + // SAFETY: by the caller's contract. + let Some((data, svc)) = (unsafe { be_service(dai, substream) }) else { + return 0; + }; + match data.startup(svc) { + Ok(()) => 0, + Err(e) => e.to_errno(), + } +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component and a live substream. +unsafe extern "C" fn be_prepare( + substream: *mut bindings::snd_pcm_substream, + dai: *mut bindings::snd_soc_dai, +) -> i32 { + // SAFETY: by the caller's contract. + let Some((data, svc)) = (unsafe { be_service(dai, substream) }) else { + return 0; + }; + match data.prepare(svc) { + Ok(()) => 0, + Err(e) => e.to_errno(), + } +} + +/// # Safety +/// +/// Called by ASoC with a live DAI of this component and a live substream. +unsafe extern "C" fn be_shutdown( + substream: *mut bindings::snd_pcm_substream, + dai: *mut bindings::snd_soc_dai, +) { + // SAFETY: by the caller's contract. + if let Some((data, svc)) = unsafe { be_service(dai, substream) } { + data.shutdown(svc); + } +} + +struct DaiOps { + be: bindings::snd_soc_dai_ops, + fe: bindings::snd_soc_dai_ops, +} + +impl DaiOps { + fn new() -> Self { + let fe = bindings::snd_soc_dai_ops { + set_fmt: Some(dai_accept_fmt), + set_sysclk: Some(dai_accept_sysclk), + set_bclk_ratio: Some(dai_accept_bclk_ratio), + set_tdm_slot: Some(dai_accept_tdm_slot), + ..Default::default() + }; + DaiOps { + be: bindings::snd_soc_dai_ops { + startup: Some(be_startup), + prepare: Some(be_prepare), + shutdown: Some(be_shutdown), + ..fe + }, + fe, + } + } +} + +fn pcm_stream(name: &'static CStr, channels: u32) -> bindings::snd_soc_pcm_stream { + bindings::snd_soc_pcm_stream { + stream_name: name.as_char_ptr(), + formats: FORMATS, + rates: bindings::SNDRV_PCM_RATE_48000, + rate_min: 48000, + rate_max: 48000, + channels_min: channels, + channels_max: channels, + ..Default::default() + } +} + +/// The DAI table, indexed by `sound-dai = <&aop_audio N>` in the DTS: +/// 0 cout (jack back-end), 1 and 2 the playback front-ends, 3 spkr (speaker +/// back-end), 4 the sense front-end. +const DAI_COUNT: usize = 2 + FE_COUNT; + +fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { + [ + bindings::snd_soc_dai_driver { + name: c"cout".as_char_ptr(), + id: BE_DAI_ID_COUT, + ops: &ops.be, + playback: pcm_stream(c"COUT TX", 2), + capture: pcm_stream(c"CIN RX", 1), + ..Default::default() + }, + bindings::snd_soc_dai_driver { + name: c"j873-pcm-0".as_char_ptr(), + id: FE_DAI_ID_BASE, + ops: &ops.fe, + playback: pcm_stream(c"PCM0 TX", 2), + capture: pcm_stream(c"PCM0 RX", 1), + ..Default::default() + }, + // The speaker: one 32-bit slot per frame (the firmware's spkr + // serializer runs a single channel). + bindings::snd_soc_dai_driver { + name: c"j873-pcm-1".as_char_ptr(), + id: FE_DAI_ID_BASE + 1, + ops: &ops.fe, + playback: pcm_stream(c"PCM1 TX", 1), + ..Default::default() + }, + bindings::snd_soc_dai_driver { + name: c"spkr".as_char_ptr(), + id: BE_DAI_ID_SPKR, + ops: &ops.be, + playback: pcm_stream(c"SPKR TX", 1), + capture: pcm_stream(c"SPKR RX", 2), + ..Default::default() + }, + bindings::snd_soc_dai_driver { + name: c"j873-pcm-2".as_char_ptr(), + id: FE_DAI_ID_BASE + 2, + ops: &ops.fe, + capture: pcm_stream(c"PCM2 RX", 2), + ..Default::default() + }, + ] +} + +impl AsocContext { + fn new(data: Arc) -> Result> { + let ops = KBox::new(DaiOps::new(), GFP_KERNEL)?; + let dais = KBox::new(Opaque::new(dai_drivers(&ops)), GFP_KERNEL)?; + let component = bindings::snd_soc_component_driver { + name: c"t8152-aop-audio".as_char_ptr(), + open: Some(asoc_pcm_open), + close: Some(asoc_pcm_close), + hw_params: Some(asoc_pcm_hw_params), + trigger: Some(asoc_pcm_trigger), + pointer: Some(asoc_pcm_pointer), + ..Default::default() + }; + Ok(KBox::new( + Self { + component, + data, + dais, + _ops: ops, + }, + GFP_KERNEL, + )?) + } +} + +struct T8152AopAudioDriver { + dev: ARef, + asoc: KBox, + registered: AtomicFlag, +} + +// SAFETY: the ASoC context is only touched by ASoC callbacks and by probe and +// remove, which the driver core serializes. +unsafe impl Send for T8152AopAudioDriver {} +// SAFETY: as for `Send`. +unsafe impl Sync for T8152AopAudioDriver {} + +impl T8152AopAudioDriver { + /// Unregisters the component. Must run from unbind: the component is + /// device-managed and freed with the device's resources after unbind. + fn unregister(&self) { + if !self.registered.xchg(false, Relaxed) { + return; + } + // SAFETY: registered in probe; the context outlives the unregister. + unsafe { + bindings::snd_soc_unregister_component_by_driver( + self.dev.as_raw(), + &self.asoc.component, + ) + }; + } +} + +kernel::of_device_table!( + OF_TABLE, + ::IdInfo, + [(of::DeviceId::new(c_str!("apple,t8152-aop-audio")), ())] +); + +impl platform::Driver for T8152AopAudioDriver { + type IdInfo = (); + type Data<'bound> = Self; + + const OF_ID_TABLE: Option> = Some(&OF_TABLE); + + fn probe<'bound>( + pdev: &'bound platform::Device>, + _info: Option<&'bound Self::IdInfo>, + ) -> impl PinInit, Error> + 'bound { + let dev = ARef::::from(pdev.as_ref()); + // SAFETY: this is a service device the AOP core registered. + let adata = unsafe { ::from_child(pdev.as_ref()) }?; + // SAFETY: the AOP core sets the child's platform data to its EPIC service. + let service = unsafe { (*dev.as_raw()).platform_data as *const EPICService }; + if service.is_null() { + return Err(ENODEV); + } + // SAFETY: checked above; it lives as long as the child. + let service = unsafe { *service }; + + // Every serializer leaf is required: the firmware's streams run on + // them, so the driver must not bind without one (or before its + // provider has probed). + let mut mca = KVec::new(); + for name in MCA_NAMES { + match PowerDomain::attach(&dev, name) { + Ok(Some(pd)) => mca.push(pd, GFP_KERNEL)?, + Ok(None) => { + dev_err!(dev, "power domain {:?} is missing\n", name); + return Err(ENODEV); + } + Err(e) => { + if e != EPROBE_DEFER { + dev_err!(dev, "power domain {:?}: {:?}\n", name, e); + } + return Err(e); + } + } + } + + let data_dev = dev.clone(); + let data = Arc::pin_init( + pin_init!(T8152AopAudio { + dev: data_dev, + adata, + service, + cout: Service::new(from_fourcc(b"cout"), "cout", true), + cin: Service::new(from_fourcc(b"cin "), "cin", true), + spkr: Service::new(from_fourcc(b"spkr"), "spkr", false), + mca, + }), + GFP_KERNEL, + )?; + for svc in [&data.cout, &data.cin, &data.spkr] { + data.attach(svc)?; + } + + let asoc = AsocContext::new(data)?; + // SAFETY: the descriptor and the DAI table are heap allocations owned + // by `asoc`, which the driver data keeps until after unregister. + let ret = unsafe { + bindings::snd_soc_register_component_d( + dev.as_raw(), + &asoc.component, + asoc.dais.get().cast(), + DAI_COUNT as i32, + ) + }; + if ret < 0 { + dev_err!(dev, "unable to register the ASoC component: {}\n", ret); + return Err(Error::from_errno(ret)); + } + Ok(Self { + dev, + asoc, + registered: AtomicFlag::new(true), + }) + } + + fn unbind(_dev: &platform::Device>, this: Pin<&Self>) { + this.unregister(); + } +} + +module_platform_driver! { + type: T8152AopAudioDriver, + name: "snd_soc_t8152_aop_audio", + description: "Apple T8152 AOP audio: headphone jack and speaker", + license: "Dual MIT/GPL", +} From 5aa269280d70ec7b21d523b3a0a77e6bad1c3f84 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:32 +0100 Subject: [PATCH 008/112] ASoC: apple: macaudio: add J873 The J873 (Mac mini M6) uses the T8152 AOP audio driver as its CPU component: the CS42L84 jack on "cout" (DSP_A | IB_NF, one-BCLK sync pulse) and one SN012776 on "spkr" (I2S, NB_IF: data sampled on the rising edge, as macOS programs the amp). Each AOP front-end owns the DMA channel of one serializer, so the speaker can only be fed from the secondary front-end; the new spk_secondary_only sets the speaker mux accordingly, and spk_dai_fmt gives the speaker link its own format. There is no qualified speaker protection for J873 yet (no verified sense path, thermal model or power budget), so the speaker fails closed: it is only enabled with please_blow_up_my_speakers. Opted in, it runs as macOS runs it: amp gain 15 (ADT speaker-config) and no volume lock (safe_vol 0), since there is no sense stream for a protection daemon. The jack is not affected. Signed-off-by: Thomas Glanzmann --- sound/soc/apple/macaudio.c | 47 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index ba04b1eec6141..4743ba5db026b 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -136,6 +136,13 @@ struct macaudio_platform_cfg { * keep the first slots in codec order; the others carry silence. */ unsigned int speaker_fe_channels; + /* The speaker links' DAI format, if not dai_fmt */ + unsigned int spk_dai_fmt; + /* + * The speakers can only be fed from the secondary front-end: each + * front-end owns the DMA channel of one serializer (AOP-fed models). + */ + bool spk_secondary_only; }; static const char *volume_control_names[] = { @@ -1215,6 +1222,8 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma) link_props->is_speakers = speakers; link_props->is_headphones = !speakers; + if (speakers && ma->cfg->spk_dai_fmt) + link->dai_fmt = ma->cfg->spk_dai_fmt; link_props->codecs = devm_kcalloc(dev, ncodecs_per_cpu, sizeof(struct ma_codec_idle), GFP_KERNEL); @@ -2035,6 +2044,9 @@ static int macaudio_fixup_controls(struct snd_soc_card *card) return ret; } + if (ma->cfg->spk_secondary_only) + CHECK(snd_soc_set_enum_kctl, "Speaker Playback Mux", "Secondary", 1); + /* * This needs some care to avoid matches against cs42l84's * "Jack HPF Corner Frequency". @@ -2353,6 +2365,39 @@ struct macaudio_platform_cfg macaudio_j700_cfg = { .primary_bclk_ratio = 125, }; +/* + * J873 (T8152, Mac mini M6): as on J700, the AOP firmware owns the audio + * fabric and the CPU component is the T8152 AOP audio driver. The jack is a + * CS42L84 on the AOP's "cout" back-end, the speaker one SN012776 on "spkr"; + * both serializers run on the firmware's clocks. The speaker frame is 250 + * BCLKs of 12 MHz (the amp is told so by its ti,bclk-ratio), with the data + * sampled on the rising edge, as macOS programs the amp. + */ +struct macaudio_platform_cfg macaudio_j873_cfg = { + /* + * No qualified speaker protection exists for J873 yet (no verified + * sense path, thermal model or power budget), so the speaker stays off + * unless please_blow_up_my_speakers is set; the jack is unaffected. + */ + .enable_speakers = false, + .amp = AMP_SN012776, + .speakers = SPKR_1W, + .stereo = false, + /* + * With the speaker opted in, as macOS runs it: ADT speaker-config + * amp_gain 15, and no volume lock (safe_vol 0), since there is no + * sense stream for a protection daemon to unlock it from. + */ + .amp_gain = 15, + .safe_vol = 0, + .fe_dai_names = { "j873-pcm-0", "j873-pcm-1", "j873-pcm-2" }, + /* jack: a one-BCLK sync pulse, data launched on the rising edge */ + .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBC_CFC | SND_SOC_DAIFMT_IB_NF, + .spk_dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBC_CFC | + SND_SOC_DAIFMT_GATED | SND_SOC_DAIFMT_NB_IF, + .spk_secondary_only = true, +}; + struct macaudio_platform_cfg macaudio_j314_cfg = { true, AMP_SN012776, SPKR_2W1T, true, 0, -20, }; @@ -2539,6 +2584,8 @@ static const struct of_device_id macaudio_snd_device_id[] = { { .compatible = "apple,j713-macaudio", .data = &macaudio_j713_cfg }, /* The J713 jack runs on the AOP like the J616s one. */ { .compatible = "apple,j713-macaudio-jack", .data = &macaudio_j616_jack_cfg }, + /* j873 AID48 sn012776 15 1x 1W (AOP-fed, no protection) */ + { .compatible = "apple,j873-macaudio", .data = &macaudio_j873_cfg }, /* Fallback, jack only */ { .compatible = "apple,macaudio"}, { } From 7c876b1bdf9f509757fb70733434647456f58ddc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 1 Nov 2026 21:39:33 +0100 Subject: [PATCH 009/112] soc: apple: rtkit: Take a crash buffer the firmware maps itself The T8142 AOP keeps its crash buffer in its own slot of its DART stream and asks for it on endpoint 1 with that IOVA. A client without shmem_setup refused the request, so the firmware never got its crash buffer acknowledged. APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG takes such a buffer as the firmware's, without a CPU mapping, and acknowledges the request unchanged; a later crash is reported without a log. RtKit::new_with_firmware_crashlog() selects it at runtime, so a driver can use it for one SoC only. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/rtkit.c | 15 +++++++++++++++ include/linux/soc/apple/rtkit.h | 7 +++++++ rust/bindings/bindings_helper.h | 1 + rust/kernel/soc/apple/rtkit.rs | 16 ++++++++++++++++ 4 files changed, 39 insertions(+) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index d352083aaa26c..9eaa28d16c46d 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -410,6 +410,13 @@ static int apple_rtkit_common_rx_get_buffer(struct apple_rtkit *rtk, dev_dbg(rtk->dev, "RTKit: buffer request for 0x%zx bytes at %pad\n", request.size, &request.iova); + if ((rtk->ops->flags & APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG) && + ep == APPLE_RTKIT_EP_CRASHLOG && request.iova) { + *buffer = request; + buffer->is_mapped = true; + return apple_rtkit_send_message(rtk, ep, msg, NULL, false); + } + if (request.iova && !rtk->ops->shmem_setup && !rtk->ops->shmem_setup_ep) { err = -EINVAL; goto error; @@ -734,6 +741,14 @@ static void apple_rtkit_crashlog_rx(struct apple_rtkit *rtk, u64 msg) dev_err(rtk->dev, "RTKit: co-processor has crashed\n"); + /* A firmware-owned crash buffer has no CPU mapping to read the log from. */ + if (!rtk->crashlog_buffer.buffer && !rtk->crashlog_buffer.iomem) { + rtk->crashed = true; + if (rtk->ops->crashed) + rtk->ops->crashed(rtk->cookie, NULL, 0); + return; + } + /* * create a shadow copy here to make sure the co-processor isn't able * to change the log while we're dumping it. this also ensures diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 65bd28a6f0240..4c27e012c2c75 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -57,6 +57,13 @@ struct apple_rtkit_inherited_buffer { /* This client requires endpoint 7 setup before IOP power can be acknowledged. */ #define APPLE_RTKIT_NEEDS_COREANALYTICS BIT(1) +/* + * The co-processor keeps its crash buffer in memory it maps itself (the T8142 + * AOP) and asks for it with that IOVA: take the buffer as the firmware's, + * without a CPU mapping, and acknowledge the request unchanged. + */ +#define APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG BIT(2) + /* * Struct to represent implementation-specific RTKit operations. * diff --git a/rust/bindings/bindings_helper.h b/rust/bindings/bindings_helper.h index 56f9f84689804..2731a39a0255c 100644 --- a/rust/bindings/bindings_helper.h +++ b/rust/bindings/bindings_helper.h @@ -158,6 +158,7 @@ const blk_features_t RUST_CONST_HELPER_BLK_FEAT_ROTATIONAL = BLK_FEAT_ROTATIONAL const fop_flags_t RUST_CONST_HELPER_FOP_UNSIGNED_OFFSET = FOP_UNSIGNED_OFFSET; const u32 RUST_CONST_HELPER_APPLE_RTKIT_COPROC_PLACES_BUFFERS = APPLE_RTKIT_COPROC_PLACES_BUFFERS; const u32 RUST_CONST_HELPER_APPLE_RTKIT_NEEDS_COREANALYTICS = APPLE_RTKIT_NEEDS_COREANALYTICS; +const u32 RUST_CONST_HELPER_APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG = APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG; const u64 BINDINGS_SNDRV_PCM_FMTBIT_FLOAT_LE = SNDRV_PCM_FMTBIT_FLOAT_LE; const u64 BINDINGS_SNDRV_PCM_FMTBIT_S32_LE = SNDRV_PCM_FMTBIT_S32_LE; diff --git a/rust/kernel/soc/apple/rtkit.rs b/rust/kernel/soc/apple/rtkit.rs index 73896fea53e00..ef9c9e7f27b0f 100644 --- a/rust/kernel/soc/apple/rtkit.rs +++ b/rust/kernel/soc/apple/rtkit.rs @@ -245,6 +245,11 @@ impl RtKit { ..Self::VTABLE }; + const FIRMWARE_CRASHLOG_VTABLE: bindings::apple_rtkit_ops = bindings::apple_rtkit_ops { + flags: Self::VTABLE.flags | bindings::APPLE_RTKIT_FIRMWARE_OWNED_CRASHLOG, + ..Self::VTABLE + }; + /// Creates a new RTKit client for a given device and optional mailbox name or index. pub fn new( dev: &device::Device, @@ -268,6 +273,17 @@ impl RtKit { Self::new_with_ops(dev, mbox_name, mbox_idx, data, &Self::COREANALYTICS_VTABLE) } + /// Creates a client whose co-processor keeps its crash buffer in memory it + /// maps itself and asks for it with that IOVA (the T8142 AOP). + pub fn new_with_firmware_crashlog( + dev: &device::Device, + mbox_name: Option<&'static CStr>, + mbox_idx: usize, + data: T::Data, + ) -> Result { + Self::new_with_ops(dev, mbox_name, mbox_idx, data, &Self::FIRMWARE_CRASHLOG_VTABLE) + } + fn new_with_ops( dev: &device::Device, mbox_name: Option<&'static CStr>, From faa5ea2e77b24ce198cfad1e79975671b2d54bc6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 31 Oct 2026 22:14:50 +0100 Subject: [PATCH 010/112] soc: apple: aop: Boot the T8142 (M5) AOP through its setup port The T8142 AOP (MacBook Air J813) waits for the host on a setup port, as the T8140 one does: the ADT's aop-exclave-mailbox at 0x3d067c000 (AOP ASC + 0x4007c000, not behind the arm-io translation). Its EPMAP announces other service endpoints than T8140's fixed set (0x4, 0x20, 0x23 and 0x32 on J813), so take the endpoints that must get buffers from the EPMAP when the match data says so. The firmware places its own crash log buffer in its firmware-mapped DART slot; accept it as the firmware's, as for G17P. After the setup boot all AFK endpoints start, and with the audio fabric left to the firmware (see the J813 device tree) the firmware announces its "audio" EPIC service. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/aop.rs | 87 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 73df7cf27deaa..eb99bc4652175 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -169,6 +169,8 @@ const SETUP_BUFFER_ENTRY_SIZE: usize = 16; /// The service endpoints that request buffers; boot completes once all of /// them have theirs. const SETUP_ENDPOINTS: [u8; 5] = [0x20, 0x21, 0x23, 0x30, 0x32]; +/// Service endpoints a setup port may announce in its EPMAP. +const SETUP_MAX_ENDPOINTS: usize = 16; const SETUP_BOOT_TIMEOUT_MS: u32 = 15000; // A request to a service endpoint: the payload goes into the endpoint's // message page, (3 << 60) | length announces it, the firmware answers with a @@ -1021,7 +1023,12 @@ struct SetupState { arena: Option>, /// The next unassigned page of the arena. next_page: usize, - endpoints: [Option; SETUP_ENDPOINTS.len()], + endpoints: [Option; SETUP_MAX_ENDPOINTS], + /// The service endpoints that must get buffers: T8140's fixed set, or + /// those the EPMAP announces. + expected: [u8; SETUP_MAX_ENDPOINTS], + expected_count: usize, + epmap_endpoints: bool, map_done: bool, ap_ready: bool, power_sent: bool, @@ -1030,12 +1037,21 @@ struct SetupState { } impl SetupState { - fn new() -> SetupState { + fn new(epmap_endpoints: bool) -> SetupState { + let mut expected = [0; SETUP_MAX_ENDPOINTS]; + let mut expected_count = 0; + if !epmap_endpoints { + expected[..SETUP_ENDPOINTS.len()].copy_from_slice(&SETUP_ENDPOINTS); + expected_count = SETUP_ENDPOINTS.len(); + } SetupState { mbox: None, arena: None, next_page: 0, - endpoints: [None; SETUP_ENDPOINTS.len()], + endpoints: [None; SETUP_MAX_ENDPOINTS], + expected, + expected_count, + epmap_endpoints, map_done: false, ap_ready: false, power_sent: false, @@ -1077,7 +1093,8 @@ impl SetupState { /// Boot is complete once the AP power state is on and every service /// endpoint has its buffers. fn ready(&self) -> bool { - self.ap_ready && self.endpoint_count() == SETUP_ENDPOINTS.len() + self.ap_ready && self.expected_count != 0 + && self.endpoint_count() == self.expected_count } /// Sends one word to a setup-port endpoint. Callers run in process @@ -1375,7 +1392,7 @@ impl AopData { required_endpoints: cfg.required_endpoints, setup_queue, setup_lost: Atomic::new(false), - setup <- new_mutex!(SetupState::new()), + setup <- new_mutex!(SetupState::new(cfg.setup_epmap_endpoints)), setup_cv <- new_condvar!(), rtkit <- new_mutex!(None), endpoints <- pin_init::pin_init_array_from_fn(|i| { @@ -2188,6 +2205,24 @@ impl AopData { // Each fragment of the endpoint map is acknowledged by // echoing it. st.send(SETUP_MGMT_EP, word)?; + if st.epmap_endpoints { + // RTKit layout: a 32-endpoint bitmap, its base in + // bits 32..34. Endpoint 0 is this management one. + let base = ((word >> 32) & 7) as u8 * 32; + dev_dbg!(self.dev, "setup port: EPMAP {:#x}\n", word); + for bit in 0..32u8 { + let ep = base + bit; + if word & (1 << bit) != 0 && ep != SETUP_MGMT_EP + && !st.expected[..st.expected_count].contains(&ep) + { + if st.expected_count == SETUP_MAX_ENDPOINTS { + return Err(ENOSPC); + } + st.expected[st.expected_count] = ep; + st.expected_count += 1; + } + } + } if word & SETUP_EPMAP_LAST != 0 { st.map_done = true; } @@ -2244,7 +2279,7 @@ impl AopData { /// from the arena. fn setup_endpoint_request(&self, st: &mut SetupState, ep: u8, word: u64) -> Result<()> { let requested = (word & 0xffff_ffff) as usize; - let slot = SETUP_ENDPOINTS + let slot = st.expected[..st.expected_count] .iter() .position(|e| *e == ep) .ok_or(EINVAL)?; @@ -2485,7 +2520,7 @@ impl AopData { "setup port: boot incomplete (AP power on: {}, endpoints: {}/{}): {:?}", st.ap_ready, st.endpoint_count(), - SETUP_ENDPOINTS.len(), + st.expected_count, e ); return Err(e); @@ -2553,6 +2588,8 @@ struct AopHwConfig { epic_v4: bool, /// The firmware boots through a second, "setup", mailbox as well. setup_port: bool, + /// Its service endpoints are the ones its EPMAP announces, not T8140's. + setup_epmap_endpoints: bool, /// Shut the co-processor down on unbind and retain its buffers if the /// shutdown cannot be confirmed. quiesce_on_unbind: bool, @@ -2575,6 +2612,7 @@ const HW_CFG_T8103: AopHwConfig = AopHwConfig { patch_bootargs: true, epic_v4: false, setup_port: false, + setup_epmap_endpoints: false, quiesce_on_unbind: false, required_endpoints: &[], fw_regions: false, @@ -2589,6 +2627,7 @@ const HW_CFG_T8112: AopHwConfig = AopHwConfig { patch_bootargs: true, epic_v4: false, setup_port: false, + setup_epmap_endpoints: false, quiesce_on_unbind: false, required_endpoints: &[], fw_regions: false, @@ -2603,6 +2642,7 @@ const HW_CFG_T6000: AopHwConfig = AopHwConfig { patch_bootargs: true, epic_v4: false, setup_port: false, + setup_epmap_endpoints: false, quiesce_on_unbind: false, required_endpoints: &[], fw_regions: false, @@ -2617,6 +2657,7 @@ const HW_CFG_T6020: AopHwConfig = AopHwConfig { patch_bootargs: true, epic_v4: false, setup_port: false, + setup_epmap_endpoints: false, quiesce_on_unbind: false, required_endpoints: &[], fw_regions: false, @@ -2636,6 +2677,7 @@ const HW_CFG_T6040: AopHwConfig = AopHwConfig { patch_bootargs: true, epic_v4: false, setup_port: false, + setup_epmap_endpoints: false, quiesce_on_unbind: true, required_endpoints: &[], fw_regions: true, @@ -2659,6 +2701,7 @@ const HW_CFG_T8140: AopHwConfig = AopHwConfig { patch_bootargs: false, epic_v4: true, setup_port: true, + setup_epmap_endpoints: false, quiesce_on_unbind: true, required_endpoints: &[0x20, 0x21, 0x22, 0x23, 0x2b], fw_regions: false, @@ -2674,6 +2717,26 @@ const HW_CFG_T8152: AopHwConfig = AopHwConfig { patch_bootargs: false, epic_v4: true, setup_port: false, + setup_epmap_endpoints: false, + quiesce_on_unbind: true, + required_endpoints: &[], + fw_regions: false, + halt_on_failed_start: false, +}; + +/// T8142 (M5): booted through a setup port as on T8140, at the ADT's +/// aop-exclave-mailbox (0x3d067c000, AOP ASC + 0x4007c000, untranslated), +/// whose EPMAP names the service endpoints (0x4, 0x20, 0x23 and 0x32 on the +/// MacBook Air J813, not T8140's set). EPIC and AFK as on T8152; the +/// firmware runs with the boot arguments iBoot left. +const HW_CFG_T8142: AopHwConfig = AopHwConfig { + ec0p: 0, + aopt: 0, + alig: 0, + patch_bootargs: false, + epic_v4: true, + setup_port: true, + setup_epmap_endpoints: true, quiesce_on_unbind: true, required_endpoints: &[], fw_regions: false, @@ -2691,6 +2754,7 @@ kernel::of_device_table!( (of::DeviceId::new(c_str!("apple,t8140-aop")), &HW_CFG_T8140), (of::DeviceId::new(c_str!("apple,t6041-aop")), &HW_CFG_T6040), (of::DeviceId::new(c_str!("apple,t8132-aop")), &HW_CFG_T8132), + (of::DeviceId::new(c_str!("apple,t8142-aop")), &HW_CFG_T8142), (of::DeviceId::new(c_str!("apple,t8152-aop")), &HW_CFG_T8152), ] ); @@ -2741,7 +2805,14 @@ impl platform::Driver for AopDriver { cfg.bootargs_word_access, )?; } - let rtkit = rtkit::RtKit::::new(pdev.as_ref(), None, 0, data.clone())?; + // The T8142 AOP places its own crashlog buffer in its firmware-mapped + // DART slot and asks for it on endpoint 1 with that IOVA; take it as + // the firmware's instead of refusing the request. + let rtkit = if cfg.setup_epmap_endpoints { + rtkit::RtKit::::new_with_firmware_crashlog(pdev.as_ref(), None, 0, data.clone())? + } else { + rtkit::RtKit::::new(pdev.as_ref(), None, 0, data.clone())? + }; data.rtkit.lock().as_mut().set(Some(rtkit)); if cfg.setup_port { AopData::setup_open(&data, pdev.as_ref())?; From b91f6a984cf0fae18d69f546c6d0f2f8438e92a4 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 31 Oct 2026 22:15:04 +0100 Subject: [PATCH 011/112] dmaengine: apple-admac: Restart a paused capture at a frame boundary Behind an AOP the serializer feeding a capture channel is the firmware's, and it stops in the middle of a frame whenever it likes. A capture that stays open across such stops (the speaker V/I sense, which a protection daemon reads for as long as it runs) then carries the partial frame forward: every later frame is off by its words, and the samples of one amplifier are read as another's. On the MacBook Air J813 one restart in three slipped by one 16-bit word. Let a client pass the frame size in bytes as a u32 in dma_slave_config.peripheral_config. A paused cyclic capture on such a channel resumes at the next frame boundary of its current period: the reports completed before the pause are accounted for, the rings are reset and the rest of the period is submitted from the aligned address, then whole periods as before. Without a frame size nothing changes. Signed-off-by: Thomas Glanzmann --- drivers/dma/apple-admac.c | 93 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 7 deletions(-) diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index 90d51641a6a35..741d1e27f893d 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -128,6 +128,8 @@ struct admac_chan { spinlock_t lock; struct admac_tx *current_tx; int nperiod_acks; + /* frame size a paused capture restarts aligned to on resume, or 0 */ + u32 realign_bytes; /* * We maintain a 'submitted' and 'issued' list mainly for interface @@ -337,6 +339,21 @@ static struct dma_async_tx_descriptor *admac_prep_dma_cyclic( return &adtx->tx; } +/* + * Write one hardware descriptor. + */ +static void admac_write_hw_desc(struct admac_data *ad, int channo, + dma_addr_t addr, size_t len) +{ + dev_dbg(ad->dev, "ch%d descriptor: addr=0x%pad len=0x%zx flags=0x%lx\n", + channo, &addr, len, FLAG_DESC_NOTIFY); + + writel_relaxed(lower_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); + writel_relaxed(upper_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); + writel_relaxed(len, ad->base + REG_DESC_WRITE(channo)); + writel_relaxed(FLAG_DESC_NOTIFY, ad->base + REG_DESC_WRITE(channo)); +} + /* * Write one hardware descriptor for a dmaengine cyclic transaction. */ @@ -353,13 +370,7 @@ static bool admac_cyclic_write_one_desc(struct admac_data *ad, int channo, /* If happens means we have buggy code */ WARN_ON_ONCE(addr + tx->period_len > tx->buf_end); - dev_dbg(ad->dev, "ch%d descriptor: addr=0x%pad len=0x%zx flags=0x%lx\n", - channo, &addr, tx->period_len, FLAG_DESC_NOTIFY); - - writel_relaxed(lower_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); - writel_relaxed(upper_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); - writel_relaxed(tx->period_len, ad->base + REG_DESC_WRITE(channo)); - writel_relaxed(FLAG_DESC_NOTIFY, ad->base + REG_DESC_WRITE(channo)); + admac_write_hw_desc(ad, channo, addr, tx->period_len); /* Include a descriptor already consumed while the ring is refilled. */ tx->nperiods_outstanding++; @@ -609,6 +620,62 @@ static int admac_pause(struct dma_chan *chan) return 0; } +static int admac_drain_reports(struct admac_data *ad, int channo); + +/* + * Restart a paused cyclic capture at the next frame boundary of the current + * period. A source that stopped in the middle of a frame (a serializer that + * firmware stops whenever it likes) leaves a partial frame in the buffer, and + * without this every later frame would be off by its words. Called with the + * channel stopped and the lock held. + */ +static void admac_cyclic_realign(struct admac_chan *adchan) +{ + struct admac_data *ad = adchan->host; + struct admac_tx *tx = adchan->current_tx; + int ch = adchan->no; + size_t done, aligned; + int nreports; + + /* Periods completed before the pause */ + nreports = admac_drain_reports(ad, ch); + tx->nperiods_outstanding -= min_t(unsigned int, nreports, tx->nperiods_outstanding); + adchan->nperiod_acks += nreports; + tx->reclaimed_pos += nreports * tx->period_len; + tx->reclaimed_pos %= 2 * tx->buf_len; + + done = tx->period_len - + min_t(size_t, readl_relaxed(ad->base + REG_RESIDUE(ad, ch)), tx->period_len); + aligned = roundup(done, adchan->realign_bytes); + if (aligned >= tx->period_len) { + adchan->nperiod_acks++; + tx->reclaimed_pos += tx->period_len; + tx->reclaimed_pos %= 2 * tx->buf_len; + aligned = 0; + } + if (adchan->nperiod_acks) + tasklet_schedule(&adchan->tasklet); + + dev_dbg(ad->dev, "ch%d realign: %zu bytes into the period, restart at %zu\n", + ch, done, aligned); + + admac_reset_rings(adchan); + writel_relaxed(0, ad->base + REG_CHAN_CTL(ad, ch)); + /* The reset dropped every descriptor still in the ring. */ + tx->nperiods_outstanding = 0; + + /* The rest of the current period, then whole periods as before */ + tx->submitted_pos = tx->reclaimed_pos; + admac_write_hw_desc(ad, ch, tx->buf_addr + (tx->submitted_pos % tx->buf_len) + aligned, + tx->period_len - aligned); + tx->nperiods_outstanding++; + tx->submitted_pos += tx->period_len; + tx->submitted_pos %= 2 * tx->buf_len; + + admac_start_chan(adchan); + admac_cyclic_write_desc(ad, ch, tx); +} + static int admac_resume(struct dma_chan *chan) { struct admac_chan *adchan = to_admac_chan(chan); @@ -618,6 +685,9 @@ static int admac_resume(struct dma_chan *chan) spin_lock_irqsave(&adchan->lock, flags); if (adchan->current_tx && adchan->current_tx->error) ret = -EIO; + else if (adchan->realign_bytes && adchan->current_tx && + admac_chan_direction(adchan->no) == DMA_DEV_TO_MEM) + admac_cyclic_realign(adchan); else admac_start_chan(adchan); spin_unlock_irqrestore(&adchan->lock, flags); @@ -971,6 +1041,15 @@ static int admac_device_config(struct dma_chan *chan, writel_relaxed(bus_width, ad->base + REG_BUS_WIDTH(ad, adchan->no)); + /* + * Optional: a u32 frame size in bytes, which a paused capture is + * restarted aligned to on resume (see admac_cyclic_realign()). + */ + if (config->peripheral_config && config->peripheral_size == sizeof(u32)) + adchan->realign_bytes = *(u32 *)config->peripheral_config; + else + adchan->realign_bytes = 0; + /* * By FIFOCTL_LIMIT we seem to set the maximal number of bytes allowed to be * held in controller's per-channel FIFO. Transfers seem to be triggered From 06f1b4a8027408b3b76ea2a27fa04be64ecca7d3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 31 Oct 2026 22:15:04 +0100 Subject: [PATCH 012/112] ASoC: apple: t8152-aop-audio: Add T8142 (MacBook Air J813) The J813 speaker stream (ADT iop-audio-controller/audio-speaker) differs from J873's: four SN012776 in 32-bit playback slots 0-3, and their voltage and current sense back on the same stream's RX side (base-ns RX0) as eight 16-bit slots. Make the speaker and sense shapes per-SoC match data: J873 keeps one playback channel; T8142 gets four, and an 8-channel S16_LE "Speaker Sense" front-end. The sense capture is the speaker serializer's RX, which the firmware stops anywhere in a frame. Before every `pwrd` of the speaker, restart a running sense capture at a frame boundary (apple-admac realignment, the partial frame reads as zeros), so that a protection daemon that keeps it open attributes each amplifier's voltage and current to the right one. The sense back-end also attaches the speaker service and requests `pw0 ` at startup: its front-end requests the ADMAC channel next, and the ADMAC only answers while the firmware holds the audio fabric up. Opening the sense before any other stream since the AOP started (speakersafetyd at boot) otherwise faults the bus. Signed-off-by: Thomas Glanzmann --- sound/soc/apple/t8152_aop_audio.rs | 160 ++++++++++++++++++++++++++--- 1 file changed, 144 insertions(+), 16 deletions(-) diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs index 31f562e7fc64d..4c61092d0cea1 100644 --- a/sound/soc/apple/t8152_aop_audio.rs +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! Apple T8152 (J873, Mac mini M6) AOP audio +//! Apple T8152 (J873, Mac mini M6) and T8142 (J813, MacBook Air M5) AOP audio //! //! The AOP firmware owns the audio fabric, as on T8140. The ADT //! (/arm-io/iop-audio-controller) names its services; all of them run on the @@ -220,6 +220,9 @@ struct T8152AopAudio { cin: Service, spkr: Service, mca: KVec, + cfg: &'static HwConfig, + /// The open sense capture front-end, if any. + sense: Atomic<*mut bindings::snd_pcm_substream>, } impl T8152AopAudio { @@ -353,16 +356,68 @@ impl T8152AopAudio { Ok(()) } + /// The sense capture's back-end. Its front-end requests the ADMAC + /// channel next, and the ADMAC only answers while the firmware holds + /// the audio fabric up, which it does while a service is in `pw0 ` or + /// `pwrd`. Opening the sense before any other stream since boot (as + /// speakersafetyd does) otherwise faults the bus (SError). Shutdown + /// leaves the service in `pw0 `, as the other streams do. + fn sense_startup(&self) -> Result<()> { + self.attach(&self.spkr)?; + if !self.spkr.running.load(Relaxed) { + self.set_power(&self.spkr, POWER_STATE_PW0)?; + } + Ok(()) + } + /// `pwrd`: the firmware starts the serializer clocks and the stream. fn run(&self, svc: &Service) -> Result<()> { if svc.running.load(Relaxed) { return Ok(()); } + if ptr::eq(svc, &self.spkr) && self.cfg.realign_sense { + self.realign_sense(); + } self.set_power(svc, POWER_STATE_PWRD)?; svc.running.store(true, Relaxed); Ok(()) } + /// Before the speaker's serializer starts, restart a running sense + /// capture at a frame boundary. The sense words are the serializer's RX, + /// which the firmware stops anywhere in a frame; a capture that stays + /// open across speaker streams (speakersafetyd keeps it) would carry + /// the partial frame forward and attribute one amplifier's voltage and + /// current to another. Nothing flows while the serializer is stopped, + /// so this loses no data; the partial frame reads as zeros. + fn realign_sense(&self) { + let ss = self.sense.load(Relaxed); + if ss.is_null() { + return; + } + // SAFETY: the sense front-end's open and close and this back-end's + // prepare all run under the card's DPCM mutex, so `ss` is live; its + // stream lock orders this against the front-end's trigger. + unsafe { + bindings::snd_pcm_stream_lock_irq(ss); + let rt = (*ss).runtime; + if !rt.is_null() && (*rt).state == SNDRV_PCM_STATE_RUNNING { + let chan = bindings::snd_dmaengine_pcm_get_chan(ss); + let ops = &*(*chan).device; + if let (Some(pause), Some(resume)) = (ops.device_pause, ops.device_resume) { + pause(chan); + let frame = ((*rt).frame_bits / 8) as usize; + let pos = bindings::snd_dmaengine_pcm_pointer(ss) as usize; + if frame != 0 && pos < (*rt).buffer_size as usize && !(*rt).dma_area.is_null() { + ptr::write_bytes((*rt).dma_area.add(pos * frame), 0, frame); + } + resume(chan); + } + } + bindings::snd_pcm_stream_unlock_irq(ss); + } + } + /// The clocks run from prepare on: the codecs see a bit clock as soon /// as ASoC powers and unmutes them. A PCM underrun stops the DMA /// without closing the back-end; a service that restarts on prepare @@ -407,6 +462,42 @@ const PCM_PERIOD_BYTES_MAX: usize = 0x10000; /// The AOP-run serializers take 24-bit samples in 32-bit words. const FORMATS: u64 = bindings::BINDINGS_SNDRV_PCM_FMTBIT_S24_LE; +/// SNDRV_PCM_FMTBIT_S16_LE (1 << SNDRV_PCM_FORMAT_S16_LE), which the +/// bindings do not export. +const FMTBIT_S16_LE: u64 = 1 << 2; +/// SNDRV_PCM_STATE_RUNNING, likewise. +const SNDRV_PCM_STATE_RUNNING: bindings::snd_pcm_state_t = 3; + +/// What differs between the machines: the shape of the firmware's `spkr` +/// stream (ADT iop-audio-controller/audio-speaker). +struct HwConfig { + /// Speaker slots (one per amplifier). + spkr_channels: u32, + /// Words the amplifiers send back on the stream's RX side (V/I sense). + sense_channels: u32, + sense_formats: u64, + /// The sense capture is the speaker stream's RX: restart it at a frame + /// boundary whenever the speaker starts (see `realign_sense`). + realign_sense: bool, +} + +/// J873: one amplifier in one 32-bit slot, nothing sent back. +static HW_CFG_T8152: HwConfig = HwConfig { + spkr_channels: 1, + sense_channels: 2, + sense_formats: FORMATS, + realign_sense: false, +}; + +/// J813: four amplifiers (left woofer, left tweeter, right woofer, right +/// tweeter) in 32-bit slots 0-3, their voltage and current sense back as +/// eight 16-bit slots (V, I per amplifier) on the stream's RX (base-ns RX0). +static HW_CFG_T8142: HwConfig = HwConfig { + spkr_channels: 4, + sense_channels: 8, + sense_formats: FMTBIT_S16_LE, + realign_sense: true, +}; /// # Safety /// @@ -543,7 +634,7 @@ unsafe extern "C" fn asoc_pcm_open( ); } if ret == 0 { - hw.formats &= FORMATS; + hw.formats &= if fe == 2 { data.cfg.sense_formats } else { FORMATS }; (*(*substream).runtime).hw = hw; ret = bindings::snd_dmaengine_pcm_open(substream, chan); } @@ -552,6 +643,8 @@ unsafe extern "C" fn asoc_pcm_open( if ret < 0 { // SAFETY: the open failed, so the channel is still ours. unsafe { bindings::dma_release_channel(chan) }; + } else if fe == 2 && !playback { + data.sense.store(substream, Relaxed); } ret } @@ -560,13 +653,18 @@ unsafe extern "C" fn asoc_pcm_open( /// /// Called by ASoC on this driver's component with live arguments. unsafe extern "C" fn asoc_pcm_close( - _component: *mut bindings::snd_soc_component, + component: *mut bindings::snd_soc_component, substream: *mut bindings::snd_pcm_substream, ) -> i32 { // SAFETY: by the caller's contract. if unsafe { rtd_is_be(substream_rtd(substream)) } { return 0; } + // SAFETY: as above. + let data = unsafe { component_data(component) }; + if data.sense.load(Relaxed) == substream { + data.sense.store(ptr::null_mut(), Relaxed); + } // SAFETY: the dmaengine runtime was set up in `asoc_pcm_open`. unsafe { bindings::snd_dmaengine_pcm_close_release_chan(substream) } } @@ -575,7 +673,7 @@ unsafe extern "C" fn asoc_pcm_close( /// /// Called by ASoC on this driver's component with live arguments. unsafe extern "C" fn asoc_pcm_hw_params( - _component: *mut bindings::snd_soc_component, + component: *mut bindings::snd_soc_component, substream: *mut bindings::snd_pcm_substream, params: *mut bindings::snd_pcm_hw_params, ) -> i32 { @@ -605,6 +703,15 @@ unsafe extern "C" fn asoc_pcm_hw_params( } else { cfg.src_port_window_size = window; } + // The sense capture: the frame size its channel restarts aligned to + // (apple-admac reads a u32 here; see `realign_sense`). + // SAFETY: by the caller's contract. + let data = unsafe { component_data(component) }; + let mut frame_bytes = channels * cfg.src_addr_width as u32; + if ptr::eq(substream, data.sense.load(Relaxed)) && data.cfg.realign_sense { + cfg.peripheral_config = ptr::from_mut(&mut frame_bytes).cast(); + cfg.peripheral_size = mem::size_of::(); + } // SAFETY: `chan` is the live channel behind the substream. unsafe { match (*(*chan).device).device_config { @@ -715,6 +822,14 @@ unsafe extern "C" fn be_startup( ) -> i32 { // SAFETY: by the caller's contract. let Some((data, svc)) = (unsafe { be_service(dai, substream) }) else { + // SAFETY: as above. + let (data, id) = unsafe { (dai_data(dai), (*dai).id as u32) }; + if id == BE_DAI_ID_SPKR { + return match data.sense_startup() { + Ok(()) => 0, + Err(e) => e.to_errno(), + }; + } return 0; }; match data.startup(svc) { @@ -780,9 +895,17 @@ impl DaiOps { } fn pcm_stream(name: &'static CStr, channels: u32) -> bindings::snd_soc_pcm_stream { + pcm_stream_fmt(name, channels, FORMATS) +} + +fn pcm_stream_fmt( + name: &'static CStr, + channels: u32, + formats: u64, +) -> bindings::snd_soc_pcm_stream { bindings::snd_soc_pcm_stream { stream_name: name.as_char_ptr(), - formats: FORMATS, + formats, rates: bindings::SNDRV_PCM_RATE_48000, rate_min: 48000, rate_max: 48000, @@ -797,7 +920,7 @@ fn pcm_stream(name: &'static CStr, channels: u32) -> bindings::snd_soc_pcm_strea /// back-end), 4 the sense front-end. const DAI_COUNT: usize = 2 + FE_COUNT; -fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { +fn dai_drivers(ops: &DaiOps, cfg: &HwConfig) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { [ bindings::snd_soc_dai_driver { name: c"cout".as_char_ptr(), @@ -815,28 +938,27 @@ fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { capture: pcm_stream(c"PCM0 RX", 1), ..Default::default() }, - // The speaker: one 32-bit slot per frame (the firmware's spkr - // serializer runs a single channel). + // The speaker: one 32-bit slot per amplifier. bindings::snd_soc_dai_driver { name: c"j873-pcm-1".as_char_ptr(), id: FE_DAI_ID_BASE + 1, ops: &ops.fe, - playback: pcm_stream(c"PCM1 TX", 1), + playback: pcm_stream(c"PCM1 TX", cfg.spkr_channels), ..Default::default() }, bindings::snd_soc_dai_driver { name: c"spkr".as_char_ptr(), id: BE_DAI_ID_SPKR, ops: &ops.be, - playback: pcm_stream(c"SPKR TX", 1), - capture: pcm_stream(c"SPKR RX", 2), + playback: pcm_stream(c"SPKR TX", cfg.spkr_channels), + capture: pcm_stream_fmt(c"SPKR RX", cfg.sense_channels, cfg.sense_formats), ..Default::default() }, bindings::snd_soc_dai_driver { name: c"j873-pcm-2".as_char_ptr(), id: FE_DAI_ID_BASE + 2, ops: &ops.fe, - capture: pcm_stream(c"PCM2 RX", 2), + capture: pcm_stream_fmt(c"PCM2 RX", cfg.sense_channels, cfg.sense_formats), ..Default::default() }, ] @@ -845,7 +967,7 @@ fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { impl AsocContext { fn new(data: Arc) -> Result> { let ops = KBox::new(DaiOps::new(), GFP_KERNEL)?; - let dais = KBox::new(Opaque::new(dai_drivers(&ops)), GFP_KERNEL)?; + let dais = KBox::new(Opaque::new(dai_drivers(&ops, data.cfg)), GFP_KERNEL)?; let component = bindings::snd_soc_component_driver { name: c"t8152-aop-audio".as_char_ptr(), open: Some(asoc_pcm_open), @@ -899,20 +1021,24 @@ impl T8152AopAudioDriver { kernel::of_device_table!( OF_TABLE, ::IdInfo, - [(of::DeviceId::new(c_str!("apple,t8152-aop-audio")), ())] + [ + (of::DeviceId::new(c_str!("apple,t8142-aop-audio")), &HW_CFG_T8142), + (of::DeviceId::new(c_str!("apple,t8152-aop-audio")), &HW_CFG_T8152), + ] ); impl platform::Driver for T8152AopAudioDriver { - type IdInfo = (); + type IdInfo = &'static HwConfig; type Data<'bound> = Self; const OF_ID_TABLE: Option> = Some(&OF_TABLE); fn probe<'bound>( pdev: &'bound platform::Device>, - _info: Option<&'bound Self::IdInfo>, + info: Option<&'bound Self::IdInfo>, ) -> impl PinInit, Error> + 'bound { let dev = ARef::::from(pdev.as_ref()); + let cfg: &'static HwConfig = info.copied().unwrap_or(&HW_CFG_T8152); // SAFETY: this is a service device the AOP core registered. let adata = unsafe { ::from_child(pdev.as_ref()) }?; // SAFETY: the AOP core sets the child's platform data to its EPIC service. @@ -953,6 +1079,8 @@ impl platform::Driver for T8152AopAudioDriver { cin: Service::new(from_fourcc(b"cin "), "cin", true), spkr: Service::new(from_fourcc(b"spkr"), "spkr", false), mca, + cfg, + sense: Atomic::new(ptr::null_mut()), }), GFP_KERNEL, )?; From 9bee3709a110999cc0bbf33ed340bef21f814301 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 31 Oct 2026 22:15:04 +0100 Subject: [PATCH 013/112] ASoC: apple: macaudio: Add J813 MacBook Air 13" M5 (T8142): as on J873 the AOP firmware owns the audio fabric and the CPU component is the T8152-style AOP audio driver. The jack is a CS42L84 on "cout", the speakers four SN012776 (one woofer and one tweeter per side) on "spkr", with their V/I sense on the same stream. As on the other SN012776 laptops the speaker volume stays locked until a protection daemon (speakersafetyd) holds it. Signed-off-by: Thomas Glanzmann --- sound/soc/apple/macaudio.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index 4743ba5db026b..58ecbf21e3152 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -2398,6 +2398,29 @@ struct macaudio_platform_cfg macaudio_j873_cfg = { .spk_secondary_only = true, }; +/* + * J813 (T8142, MacBook Air M5 13"): as on J873, the AOP firmware owns the + * audio fabric and the CPU component is the T8152-style AOP audio driver. + * The jack is a CS42L84 on "cout"; the speakers are four SN012776 (one + * woofer and one tweeter per side) on "spkr", whose voltage and current + * sense return on the same stream. As on the other SN012776 laptops, the + * speaker volume stays locked until a protection daemon (speakersafetyd) + * holds it. + */ +struct macaudio_platform_cfg macaudio_j813_cfg = { + .enable_speakers = true, + .amp = AMP_SN012776, + .speakers = SPKR_1W1T, + .stereo = true, + .amp_gain = 15, + .safe_vol = -20, + .fe_dai_names = { "j873-pcm-0", "j873-pcm-1", "j873-pcm-2" }, + .dai_fmt = SND_SOC_DAIFMT_DSP_A | SND_SOC_DAIFMT_CBC_CFC | SND_SOC_DAIFMT_IB_NF, + .spk_dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBC_CFC | + SND_SOC_DAIFMT_GATED | SND_SOC_DAIFMT_NB_IF, + .spk_secondary_only = true, +}; + struct macaudio_platform_cfg macaudio_j314_cfg = { true, AMP_SN012776, SPKR_2W1T, true, 0, -20, }; @@ -2586,6 +2609,8 @@ static const struct of_device_id macaudio_snd_device_id[] = { { .compatible = "apple,j713-macaudio-jack", .data = &macaudio_j616_jack_cfg }, /* j873 AID48 sn012776 15 1x 1W (AOP-fed, no protection) */ { .compatible = "apple,j873-macaudio", .data = &macaudio_j873_cfg }, + /* j813 AID? sn012776 15 2x 1W+1T (AOP-fed, V/I sense) */ + { .compatible = "apple,j813-macaudio", .data = &macaudio_j813_cfg }, /* Fallback, jack only */ { .compatible = "apple,macaudio"}, { } From c69b295447bb26fd843235c65f7f348d67ea2338 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 31 Oct 2026 23:44:39 +0100 Subject: [PATCH 014/112] ASoC: apple: t8152-aop-audio: Add the J813 microphone array The MacBook Air J813's three microphones are the AOP's "hpai" service (ADT iop-audio-controller/audio-hp-mic): the firmware runs the PDM part and delivers 48 kHz float32 frames of three channels (the ADT's audio-hp-mic-proxy description: 12 bytes per frame) on leap-s ADMAC RX0. There is no codec, so it gets a card of its own with one capture PCM, named like the other AOP microphone cards (AppleJ813HPAI, "MacBook Air J813 High-Power Audio Interface", driver aop_audio) so that the existing UCM and DSP configurations for those apply. As on T8140: open attaches the service and requests pw0 (which raises the LEAP fabric), powers the LEAP leaves (leap-s ADMAC, RX0, LEAP MCA), and only then requests the channel, whose registers fault without them. The trigger starts the DMA and queues pwrd behind it; started earlier, the LEAP produces into a channel nobody services. Close releases the channel, then pw0 and the leaves. The card exists only where the DT gives the LEAP power domains (all three); J873 is unchanged. The dmaengine substream setup moves into a helper shared with the ASoC front-ends. Tested on J813: a tone from the speakers reads -44 to -49 dBFS on all three channels, 70 dB over the quiet floor, exactly while it plays; PipeWire picks up the card with asahi-audio's J613 beamformer graph. Signed-off-by: Thomas Glanzmann --- sound/soc/apple/t8152_aop_audio.rs | 478 ++++++++++++++++++++++++++--- 1 file changed, 429 insertions(+), 49 deletions(-) diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs index 4c61092d0cea1..9976684a8d7d8 100644 --- a/sound/soc/apple/t8152_aop_audio.rs +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -10,6 +10,9 @@ //! channels 10 and 11). //! * `spkr`: the SN012776 speaker amplifier, base-ns TX1 (channel 2), its //! sense data on RX1. +//! * `hpai` (J813): the microphone array, three PDM microphones the firmware +//! delivers as float32 on leap-s ADMAC RX0. It has no codec, so it is the +//! capture PCM of a small card of its own. //! //! Each service is an ASoC back-end DAI: startup attaches it and requests //! `pw0 ` (which also brings up the audio fabric), prepare requests `pwrd` @@ -31,12 +34,14 @@ use kernel::{ module_platform_driver, of, platform, prelude::*, soc::apple::aop::{from_fourcc, EPICService, AOP}, + str::CString, sync::{ aref::ARef, atomic::{Atomic, AtomicFlag, Relaxed}, - Arc, + Arc, ArcBorrow, }, - types::Opaque, + types::{ForeignOwnable, Opaque}, + workqueue::{self, impl_has_work, new_work, Work, WorkItem}, }; const EPIC_SUBTYPE_WRAPPED_CALL: u16 = 0x20; @@ -57,6 +62,15 @@ const PD_GET_RETRY_MS: i64 = 10; /// The MCA serializer leaves (audio_mca0_m .. audio_mca5_m). const MCA_COUNT: usize = 6; const MCA_NAMES: [&CStr; MCA_COUNT] = [c"mca0", c"mca1", c"mca2", c"mca3", c"mca4", c"mca5"]; +/// The microphone array's LEAP leaves: the leap-s ADMAC, its RX0 channel and +/// the LEAP serializer. A LEAP ADMAC's channel registers only answer with +/// these powered (an access without them faults the bus). +const LEAP_NAMES: [&CStr; 3] = [c"leap_s_a", c"leap_rx0", c"leap_mca"]; +/// The microphone array's stream (ADT audio-hp-mic-proxy physical +/// description): 48 kHz, three float32 channels. +const HPAI_RATE: u32 = 48000; +const HPAI_CHANNELS: u32 = 3; +const HPAI_START_WORK: u64 = 1; fn aop_timestamp() -> u64 { // SAFETY: both helpers read the architected timer and take no arguments. @@ -223,6 +237,30 @@ struct T8152AopAudio { cfg: &'static HwConfig, /// The open sense capture front-end, if any. sense: Atomic<*mut bindings::snd_pcm_substream>, + hpai: Service, + /// The microphone array's leaves (`LEAP_NAMES`); empty without one. + leap: KVec, + /// The microphone capture is triggered. + hpai_want_run: AtomicFlag, + #[pin] + hpai_start_work: Work, +} + +impl_has_work! { + impl HasWork for T8152AopAudio { self.hpai_start_work } +} + +/// The microphone array's `pwrd`, queued by the capture trigger (a sleeping +/// firmware call). The ADMAC is running by then: started before it, the LEAP +/// produces into a channel nobody services and the capture stays noise. +impl WorkItem for T8152AopAudio { + type Pointer = Arc; + + fn run(this: Arc) { + if let Err(e) = this.hpai_go() { + dev_err!(this.dev, "hpai: start failed: {:?}\n", e); + } + } } impl T8152AopAudio { @@ -324,11 +362,11 @@ impl T8152AopAudio { Ok(()) } - fn mca_up(&self) -> Result<()> { - for (i, pd) in self.mca.iter().enumerate() { + fn leaves_up(&self, pds: &[PowerDomain], what: &str) -> Result<()> { + for (i, pd) in pds.iter().enumerate() { if let Err(e) = pd.get() { - dev_err!(self.dev, "MCA leaf {} did not power up: {:?}\n", i, e); - for pd in self.mca[..i].iter().rev() { + dev_err!(self.dev, "{} leaf {} did not power up: {:?}\n", what, i, e); + for pd in pds[..i].iter().rev() { pd.put(); } return Err(e); @@ -337,12 +375,20 @@ impl T8152AopAudio { Ok(()) } - fn mca_down(&self) { - for pd in self.mca.iter().rev() { + fn leaves_down(pds: &[PowerDomain]) { + for pd in pds.iter().rev() { pd.put(); } } + fn mca_up(&self) -> Result<()> { + self.leaves_up(&self.mca, "MCA") + } + + fn mca_down(&self) { + Self::leaves_down(&self.mca) + } + /// Back-end startup: attach, `pw0 ` (which raises the fabric), then the /// serializer leaves. fn startup(&self, svc: &Service) -> Result<()> { @@ -439,6 +485,39 @@ impl T8152AopAudio { } self.mca_down(); } + + /// Microphone open: attach, `pw0 ` (which raises the fabric), then the + /// LEAP leaves, before the capture requests its ADMAC channel. + fn hpai_startup(&self) -> Result<()> { + self.attach(&self.hpai)?; + self.set_power(&self.hpai, POWER_STATE_PW0)?; + self.leaves_up(&self.leap, "LEAP")?; + self.hpai.running.store(false, Relaxed); + Ok(()) + } + + fn hpai_go(&self) -> Result<()> { + if !self.hpai_want_run.load(Relaxed) { + return Ok(()); + } + self.run(&self.hpai) + } + + /// Microphone close, after the channel is released: a queued start + /// finishes first, then `pw0 ` and the leaves. + fn hpai_shutdown(&self) { + self.hpai_want_run.store(false, Relaxed); + // SAFETY: the work item lives in `self`; flushing waits for a queued + // `hpai_go`. + unsafe { bindings::flush_work(Work::raw_get(&self.hpai_start_work)) }; + if self.hpai.running.load(Relaxed) { + if let Err(e) = self.set_power(&self.hpai, POWER_STATE_PW0) { + dev_err!(self.dev, "hpai: pw0 failed: {:?}\n", e); + } + self.hpai.running.store(false, Relaxed); + } + Self::leaves_down(&self.leap); + } } // ---- the ASoC component ---- @@ -566,41 +645,11 @@ unsafe fn dai_data<'a>(dai: *mut bindings::snd_soc_dai) -> &'a T8152AopAudio { unsafe { component_data((*dai).component) } } -/// # Safety -/// -/// Called by ASoC on this driver's component with live arguments. -unsafe extern "C" fn asoc_pcm_open( - component: *mut bindings::snd_soc_component, - substream: *mut bindings::snd_pcm_substream, -) -> i32 { - // SAFETY: by the caller's contract. - let data = unsafe { component_data(component) }; - // SAFETY: as above. - let rtd = unsafe { substream_rtd(substream) }; - // SAFETY: as above. - if unsafe { rtd_is_be(rtd) } { - return 0; - } - // SAFETY: as above. - let Some(fe) = (unsafe { fe_index(rtd) }) else { - return EINVAL.to_errno(); - }; - // SAFETY: as above. - let playback = unsafe { is_playback(substream) }; - let Some(name) = FE_DMA_NAMES[fe][usize::from(!playback)] else { - return ENODEV.to_errno(); - }; - // SAFETY: the device is live and the name is NUL-terminated. - let chan = match from_err_ptr(unsafe { - bindings::dma_request_chan(data.dev.as_raw(), name.as_char_ptr()) - }) { - Ok(chan) => chan, - Err(e) => { - dev_err!(data.dev, "DMA channel {:?} unavailable: {:?}\n", name, e); - return e.to_errno(); - } - }; - let mut hw = bindings::snd_pcm_hardware { +/// The dmaengine PCMs' common description: mmap-able, interleaved, periods +/// from 256 bytes to the ADMAC's segment size. Rates, channels and formats +/// are left to the caller (for a front-end, ASoC fills them in from the DAI). +fn pcm_hw() -> bindings::snd_pcm_hardware { + bindings::snd_pcm_hardware { info: bindings::SNDRV_PCM_INFO_MMAP | bindings::SNDRV_PCM_INFO_MMAP_VALID | bindings::SNDRV_PCM_INFO_INTERLEAVED, @@ -611,9 +660,25 @@ unsafe extern "C" fn asoc_pcm_open( periods_max: (PCM_BUFFER_MAX / PCM_PERIOD_BYTES_MIN) as u32, fifo_size: 16, ..Default::default() - }; - // SAFETY: the substream and the channel are live. - let ret = unsafe { + } +} + +/// Sets up a dmaengine substream on `chan`: a managed buffer on the DMA +/// device (once per substream), `hw` refined by the channel and narrowed to +/// `formats`, then the dmaengine runtime. On failure the channel is still +/// the caller's. +/// +/// # Safety +/// +/// `substream` must be live and `chan` a channel the caller requested. +unsafe fn dmaengine_open( + substream: *mut bindings::snd_pcm_substream, + chan: *mut bindings::dma_chan, + mut hw: bindings::snd_pcm_hardware, + formats: u64, +) -> i32 { + // SAFETY: by the caller's contract. + unsafe { let mut ret = 0; if (*substream).dma_buffer.dev.type_ == bindings::SNDRV_DMA_TYPE_UNKNOWN as i32 { ret = bindings::snd_pcm_set_managed_buffer( @@ -634,12 +699,51 @@ unsafe extern "C" fn asoc_pcm_open( ); } if ret == 0 { - hw.formats &= if fe == 2 { data.cfg.sense_formats } else { FORMATS }; + hw.formats &= formats; (*(*substream).runtime).hw = hw; ret = bindings::snd_dmaengine_pcm_open(substream, chan); } ret + } +} + +/// # Safety +/// +/// Called by ASoC on this driver's component with live arguments. +unsafe extern "C" fn asoc_pcm_open( + component: *mut bindings::snd_soc_component, + substream: *mut bindings::snd_pcm_substream, +) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { component_data(component) }; + // SAFETY: as above. + let rtd = unsafe { substream_rtd(substream) }; + // SAFETY: as above. + if unsafe { rtd_is_be(rtd) } { + return 0; + } + // SAFETY: as above. + let Some(fe) = (unsafe { fe_index(rtd) }) else { + return EINVAL.to_errno(); + }; + // SAFETY: as above. + let playback = unsafe { is_playback(substream) }; + let Some(name) = FE_DMA_NAMES[fe][usize::from(!playback)] else { + return ENODEV.to_errno(); }; + // SAFETY: the device is live and the name is NUL-terminated. + let chan = match from_err_ptr(unsafe { + bindings::dma_request_chan(data.dev.as_raw(), name.as_char_ptr()) + }) { + Ok(chan) => chan, + Err(e) => { + dev_err!(data.dev, "DMA channel {:?} unavailable: {:?}\n", name, e); + return e.to_errno(); + } + }; + let formats = if fe == 2 { data.cfg.sense_formats } else { FORMATS }; + // SAFETY: the substream is live and the channel was requested above. + let ret = unsafe { dmaengine_open(substream, chan, pcm_hw(), formats) }; if ret < 0 { // SAFETY: the open failed, so the channel is still ours. unsafe { bindings::dma_release_channel(chan) }; @@ -989,14 +1093,256 @@ impl AsocContext { } } +// ---- the microphone array's card ---- + +/// # Safety +/// +/// `substream` must be a live substream of the microphone PCM, whose private +/// data is the `Arc` leaked into it by `MicCard::new` (released in +/// `mic_pcm_free` after the last op). +unsafe fn mic_data<'a>(substream: *mut bindings::snd_pcm_substream) -> ArcBorrow<'a, T8152AopAudio> { + // SAFETY: by the caller's contract. + unsafe { Arc::::borrow((*(*substream).pcm).private_data.cast()) } +} + +/// The LEAP produces float32 into the channel requested here; the channel's +/// registers only answer with the LEAP leaves up, so the service (and with +/// it the leaves) comes up before the request and goes down after the +/// release. +/// +/// # Safety +/// +/// Called by ALSA with a live substream of the microphone PCM. +unsafe extern "C" fn mic_pcm_open(substream: *mut bindings::snd_pcm_substream) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { mic_data(substream) }; + // A failed startup has undone its leaves; the service stays in `pw0 `. + if let Err(e) = data.hpai_startup() { + return e.to_errno(); + } + // SAFETY: the device is live and the name is NUL-terminated. + let chan = match from_err_ptr(unsafe { + bindings::dma_request_chan(data.dev.as_raw(), c"hpai".as_char_ptr()) + }) { + Ok(chan) => chan, + Err(e) => { + dev_err!(data.dev, "hpai: DMA channel unavailable: {:?}\n", e); + data.hpai_shutdown(); + return e.to_errno(); + } + }; + let hw = bindings::snd_pcm_hardware { + rates: bindings::SNDRV_PCM_RATE_48000, + rate_min: HPAI_RATE, + rate_max: HPAI_RATE, + channels_min: HPAI_CHANNELS, + channels_max: HPAI_CHANNELS, + ..pcm_hw() + }; + // SAFETY: the substream is live and the channel was requested above. + let ret = unsafe { + dmaengine_open(substream, chan, hw, bindings::BINDINGS_SNDRV_PCM_FMTBIT_FLOAT_LE) + }; + if ret < 0 { + // SAFETY: the open failed, so the channel is still ours. + unsafe { bindings::dma_release_channel(chan) }; + data.hpai_shutdown(); + } + ret +} + +/// # Safety +/// +/// Called by ALSA with a live substream of the microphone PCM. +unsafe extern "C" fn mic_pcm_close(substream: *mut bindings::snd_pcm_substream) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { mic_data(substream) }; + // SAFETY: the dmaengine runtime was set up in `mic_pcm_open`. + let ret = unsafe { bindings::snd_dmaengine_pcm_close_release_chan(substream) }; + data.hpai_shutdown(); + ret +} + +/// # Safety +/// +/// Called by ALSA with a live substream of the microphone PCM and live +/// parameters. +unsafe extern "C" fn mic_pcm_hw_params( + substream: *mut bindings::snd_pcm_substream, + params: *mut bindings::snd_pcm_hw_params, +) -> i32 { + // SAFETY: the dmaengine runtime was set up in `mic_pcm_open`. + let chan = unsafe { bindings::snd_dmaengine_pcm_get_chan(substream) }; + let mut cfg = bindings::dma_slave_config::default(); + // SAFETY: the substream and the parameters are live for the op. + let rc = unsafe { bindings::snd_hwparams_to_dma_slave_config(substream, params, &mut cfg) }; + if rc < 0 { + return rc; + } + // Three words per frame, which the ADMAC cannot mark (it frames 2 or 4): + // a plain word stream. + // SAFETY: `chan` is the live channel behind the substream. + unsafe { + match (*(*chan).device).device_config { + Some(f) => f(chan, &mut cfg), + None => ENOSYS.to_errno(), + } + } +} + +/// ALSA calls prepare unconditionally. Nothing to arm: the DMA start and +/// the queued firmware run belong to trigger. +/// +/// # Safety +/// +/// Called by ALSA with a live substream of the microphone PCM. +unsafe extern "C" fn mic_pcm_prepare(_substream: *mut bindings::snd_pcm_substream) -> i32 { + 0 +} + +/// With the stream lock held: the DMA first, then the firmware's `pwrd` +/// queued behind it. +/// +/// # Safety +/// +/// Called by ALSA with a live substream of the microphone PCM. +unsafe extern "C" fn mic_pcm_trigger(substream: *mut bindings::snd_pcm_substream, cmd: i32) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { mic_data(substream) }; + // SAFETY: the dmaengine runtime was set up in `mic_pcm_open`. + let ret = unsafe { bindings::snd_dmaengine_pcm_trigger(substream, cmd) }; + if ret < 0 { + return ret; + } + match cmd as u32 { + bindings::SNDRV_PCM_TRIGGER_START + | bindings::SNDRV_PCM_TRIGGER_RESUME + | bindings::SNDRV_PCM_TRIGGER_PAUSE_RELEASE => { + data.hpai_want_run.store(true, Relaxed); + // Err: already queued, and that run sees `hpai_want_run`. + let _ = workqueue::system().enqueue::<_, HPAI_START_WORK>(Arc::from(data)); + } + _ => data.hpai_want_run.store(false, Relaxed), + } + 0 +} + +/// # Safety +/// +/// Called once by ALSA when the PCM goes away. +unsafe extern "C" fn mic_pcm_free(pcm: *mut bindings::snd_pcm) { + // SAFETY: the `Arc` leaked into the private data by `MicCard::new`. + drop(unsafe { Arc::::from_foreign((*pcm).private_data.cast()) }); +} + +static MIC_PCM_OPS: bindings::snd_pcm_ops = bindings::snd_pcm_ops { + open: Some(mic_pcm_open), + close: Some(mic_pcm_close), + ioctl: None, + hw_params: Some(mic_pcm_hw_params), + hw_free: None, + prepare: Some(mic_pcm_prepare), + trigger: Some(mic_pcm_trigger), + sync_stop: None, + pointer: Some(bindings::snd_dmaengine_pcm_pointer), + get_time_info: None, + fill_silence: None, + copy: None, + page: None, + mmap: None, + ack: None, +}; + +/// Copies a NUL-terminated string into a fixed-size field, truncated to fit. +fn copy_str(target: &mut [u8], source: &CStr) { + let b = source.to_bytes(); + let n = b.len().min(target.len() - 1); + target[..n].copy_from_slice(&b[..n]); + target[n] = 0; +} + +/// The microphone array's card: one capture PCM, named like the other AOP +/// microphone cards (AppleJxxxHPAI) so that the UCM and DSP configurations +/// for those find it. +struct MicCard(*mut bindings::snd_card); + +impl MicCard { + fn new(data: &Arc) -> Result { + let fwnode = data.dev.fwnode().ok_or(ENODEV)?; + let chassis = fwnode + .property_read::(c_str!("apple,chassis-name")) + .required_by(&data.dev)?; + let kind = fwnode + .property_read::(c_str!("apple,machine-kind")) + .required_by(&data.dev)?; + let id = CString::try_from_fmt(fmt!("Apple{}HPAI", *chassis))?; + let shortname = CString::try_from_fmt(fmt!("{} {} HPAI", *kind, *chassis))?; + let longname = + CString::try_from_fmt(fmt!("{} {} High-Power Audio Interface", *kind, *chassis))?; + let mut card = ptr::null_mut(); + // SAFETY: the device and the module are live; `card` receives the card. + let ret = unsafe { + bindings::snd_card_new( + data.dev.as_raw(), + -1, + ptr::null(), + kernel::module::this_module::().as_ptr(), + 0, + &mut card, + ) + }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + // From here on, dropping `this` frees the card. + let this = MicCard(card); + // SAFETY: the card is new and unregistered. + unsafe { + copy_str(&mut (*card).driver, c"aop_audio"); + copy_str(&mut (*card).id, &id); + copy_str(&mut (*card).shortname, &shortname); + copy_str(&mut (*card).longname, &longname); + } + let mut pcm = ptr::null_mut(); + // SAFETY: the card is live; `pcm` receives the PCM. + let ret = unsafe { bindings::snd_pcm_new(card, c"hpai".as_char_ptr(), 0, 0, 1, &mut pcm) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + // SAFETY: `pcm` is live; the ops are static and the private data is + // an `Arc` that `mic_pcm_free` releases. + unsafe { + bindings::snd_pcm_set_ops(pcm, bindings::SNDRV_PCM_STREAM_CAPTURE as i32, &MIC_PCM_OPS); + (*pcm).private_data = data.clone().into_foreign().cast(); + (*pcm).private_free = Some(mic_pcm_free); + copy_str(&mut (*pcm).name, c"Microphone Array"); + } + // SAFETY: the card is live and complete. + let ret = unsafe { bindings::snd_card_register(card) }; + if ret < 0 { + return Err(Error::from_errno(ret)); + } + Ok(this) + } +} + +impl Drop for MicCard { + fn drop(&mut self) { + // SAFETY: created by `snd_card_new`; this waits for open files. + unsafe { bindings::snd_card_free(self.0) }; + } +} + struct T8152AopAudioDriver { dev: ARef, asoc: KBox, registered: AtomicFlag, + /// Held for its drop, which frees the card after unbind. + _mic: Option, } -// SAFETY: the ASoC context is only touched by ASoC callbacks and by probe and -// remove, which the driver core serializes. +// SAFETY: the ASoC context and the card are only touched by ALSA/ASoC +// callbacks and by probe and remove, which the driver core serializes. unsafe impl Send for T8152AopAudioDriver {} // SAFETY: as for `Send`. unsafe impl Sync for T8152AopAudioDriver {} @@ -1069,6 +1415,21 @@ impl platform::Driver for T8152AopAudioDriver { } } + // The microphone array, where the DT describes it: all of its leaves + // or none. + let mut leap = KVec::new(); + for name in LEAP_NAMES { + match PowerDomain::attach(&dev, name) { + Ok(Some(pd)) => leap.push(pd, GFP_KERNEL)?, + Ok(None) => {} + Err(e) => return Err(e), + } + } + if !leap.is_empty() && leap.len() != LEAP_NAMES.len() { + dev_err!(dev, "incomplete microphone power domains\n"); + return Err(ENODEV); + } + let data_dev = dev.clone(); let data = Arc::pin_init( pin_init!(T8152AopAudio { @@ -1081,6 +1442,10 @@ impl platform::Driver for T8152AopAudioDriver { mca, cfg, sense: Atomic::new(ptr::null_mut()), + hpai: Service::new(from_fourcc(b"hpai"), "hpai", false), + leap, + hpai_want_run: AtomicFlag::new(false), + hpai_start_work <- new_work!("T8152AopAudio::hpai_start_work"), }), GFP_KERNEL, )?; @@ -1088,6 +1453,20 @@ impl platform::Driver for T8152AopAudioDriver { data.attach(svc)?; } + // The microphones are optional: the speakers and the jack stay + // usable without them. + let mic = if data.leap.is_empty() { + None + } else { + match MicCard::new(&data) { + Ok(card) => Some(card), + Err(e) => { + dev_err!(dev, "microphone card: {:?}\n", e); + None + } + } + }; + let asoc = AsocContext::new(data)?; // SAFETY: the descriptor and the DAI table are heap allocations owned // by `asoc`, which the driver data keeps until after unregister. @@ -1107,6 +1486,7 @@ impl platform::Driver for T8152AopAudioDriver { dev, asoc, registered: AtomicFlag::new(true), + _mic: mic, }) } From e42e2b87695ab30e8793dd6c26c332c5d2b2fc01 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 5 Nov 2026 20:11:17 +0100 Subject: [PATCH 015/112] soc: apple: aop: Set the T8152 and T8142 boot-argument fields integration/aurora added the nCal boot argument and word-wise boot-argument access to AopHwConfig. Both machine configurations keep the firmware's own boot arguments unchanged, so set ncal to zero and leave word access off. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/aop.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index eb99bc4652175..ec863dfde8feb 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -2712,6 +2712,7 @@ const HW_CFG_T8140: AopHwConfig = AopHwConfig { /// ADT aop-exclave-mailbox) is not reachable from the AP: both bus-error. const HW_CFG_T8152: AopHwConfig = AopHwConfig { ec0p: 0, + ncal: 0, aopt: 0, alig: 0, patch_bootargs: false, @@ -2721,6 +2722,7 @@ const HW_CFG_T8152: AopHwConfig = AopHwConfig { quiesce_on_unbind: true, required_endpoints: &[], fw_regions: false, + bootargs_word_access: false, halt_on_failed_start: false, }; @@ -2731,6 +2733,7 @@ const HW_CFG_T8152: AopHwConfig = AopHwConfig { /// firmware runs with the boot arguments iBoot left. const HW_CFG_T8142: AopHwConfig = AopHwConfig { ec0p: 0, + ncal: 0, aopt: 0, alig: 0, patch_bootargs: false, @@ -2740,6 +2743,7 @@ const HW_CFG_T8142: AopHwConfig = AopHwConfig { quiesce_on_unbind: true, required_endpoints: &[], fw_regions: false, + bootargs_word_access: false, halt_on_failed_start: false, }; From f03c37323e5c1dc1352985fde73cc67035eead39 Mon Sep 17 00:00:00 2001 From: Ryan Murray Date: Sat, 7 Nov 2026 01:13:12 +1100 Subject: [PATCH 016/112] arm64: dts: apple: t604x-j614-j616: Describe the boot NOR flash supply Every boot on the J616s logged "spi-nor spi0.0: supply vcc not found, using dummy regulator". The M1, M2, M3, J713 and J700 trees describe the flash's always-on PMU rail as a fixed regulator; the M4 Pro/Max tree came later and has none. Add the same regulator and point the flash at it. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi index 7f12ea2491967..9453cd912127b 100644 --- a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi @@ -1625,6 +1625,16 @@ }; }; + /* + * The boot NOR runs from a PMU rail that is on whenever the SoC is + * and that no OS switches. The ADT gives the flash no supply. + */ + nor_flash_vcc: regulator-nor-flash-vcc { + compatible = "regulator-fixed"; + regulator-name = "nor-flash-vcc"; + regulator-always-on; + }; + /* * The speaker amps' shared shutdown line (SDZ, AP pin 54, low = * shutdown). One fixed regulator, the SDZ supply of all six, not @@ -1756,6 +1766,7 @@ spi-max-frequency = <10000000>; spi-rx-bus-width = <1>; spi-tx-bus-width = <1>; + vcc-supply = <&nor_flash_vcc>; partitions { compatible = "fixed-partitions"; From 12165bc25529cb20f8fa1a93c996b5b313e40437 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 12:40:04 -0500 Subject: [PATCH 017/112] ASoC: apple: initialize J813 output standby before microphone registration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Test whether COUT standby supplies the missing cold-boot fabric setup. A muted zero-data jack stream permitted HPAI capture and subsequent capture-only opens on J813; standby without any playback is the next hardware qualification step. Preserve Thomas Glanzmann’s driver and adapt the T8140 DMA sync-stop pattern from Ryan Murray, also flushing queued HPAI work before DMA teardown. No LPAI buffer binding or codec unmute is performed. --- sound/soc/apple/t8152_aop_audio.rs | 34 +++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs index 9976684a8d7d8..9aad831ad7a61 100644 --- a/sound/soc/apple/t8152_aop_audio.rs +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -503,13 +503,17 @@ impl T8152AopAudio { self.run(&self.hpai) } - /// Microphone close, after the channel is released: a queued start - /// finishes first, then `pw0 ` and the leaves. - fn hpai_shutdown(&self) { + /// Finish a queued firmware start before retiring the DMA runtime. + fn flush_hpai_start(&self) { self.hpai_want_run.store(false, Relaxed); // SAFETY: the work item lives in `self`; flushing waits for a queued // `hpai_go`. unsafe { bindings::flush_work(Work::raw_get(&self.hpai_start_work)) }; + } + + /// Microphone close, after the channel is released: `pw0 ` then leaves. + fn hpai_shutdown(&self) { + self.flush_hpai_start(); if self.hpai.running.load(Relaxed) { if let Err(e) = self.set_power(&self.hpai, POWER_STATE_PW0) { dev_err!(self.dev, "hpai: pw0 failed: {:?}\n", e); @@ -1157,12 +1161,27 @@ unsafe extern "C" fn mic_pcm_open(substream: *mut bindings::snd_pcm_substream) - unsafe extern "C" fn mic_pcm_close(substream: *mut bindings::snd_pcm_substream) -> i32 { // SAFETY: by the caller's contract. let data = unsafe { mic_data(substream) }; + data.flush_hpai_start(); // SAFETY: the dmaengine runtime was set up in `mic_pcm_open`. let ret = unsafe { bindings::snd_dmaengine_pcm_close_release_chan(substream) }; data.hpai_shutdown(); ret } +/// Finish queued firmware work and asynchronous DMA termination before ALSA +/// reuses or frees the capture buffer, as in the T8140 capture path. +/// +/// # Safety +/// +/// Called by ALSA with a live microphone substream and dmaengine runtime. +unsafe extern "C" fn mic_pcm_sync_stop(substream: *mut bindings::snd_pcm_substream) -> i32 { + // SAFETY: by the caller's contract. + let data = unsafe { mic_data(substream) }; + data.flush_hpai_start(); + // SAFETY: the runtime remains live until close. + unsafe { bindings::snd_dmaengine_pcm_sync_stop(substream) } +} + /// # Safety /// /// Called by ALSA with a live substream of the microphone PCM and live @@ -1243,7 +1262,7 @@ static MIC_PCM_OPS: bindings::snd_pcm_ops = bindings::snd_pcm_ops { hw_free: None, prepare: Some(mic_pcm_prepare), trigger: Some(mic_pcm_trigger), - sync_stop: None, + sync_stop: Some(mic_pcm_sync_stop), pointer: Some(bindings::snd_dmaengine_pcm_pointer), get_time_info: None, fill_silence: None, @@ -1458,7 +1477,12 @@ impl platform::Driver for T8152AopAudioDriver { let mic = if data.leap.is_empty() { None } else { - match MicCard::new(&data) { + // Initialize the shared output service before exposing HPAI. + // This is standby only: no DMA, running state or codec unmute. + // No userspace stream can race this before card registration. + match data.set_power(&data.cout, POWER_STATE_PW0) + .and_then(|_| MicCard::new(&data)) + { Ok(card) => Some(card), Err(e) => { dev_err!(dev, "microphone card: {:?}\n", e); From ad4910ce6ec1aef2b663e9f6fc8af2436a739742 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 12:44:24 -0500 Subject: [PATCH 018/112] ASoC: apple: validate J813 audio topology and use the default worker queue Describe the T8142 microphone DMA and LEAP power domains and card names in the shared audio binding. Queue sleeping firmware power requests on system_dfl instead of the deprecated system workqueue, as directed by the runtime warning observed during hardware capture tests. --- .../bindings/sound/apple,t8152-aop-audio.yaml | 56 ++++++++++++++++++- sound/soc/apple/t8152_aop_audio.rs | 7 ++- 2 files changed, 58 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml index fa643fe62a9df..b067077a213a1 100644 --- a/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/sound/apple,t8152-aop-audio.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8152 AOP audio +title: Apple T8142 and T8152 AOP audio maintainers: - Thomas Glanzmann @@ -16,26 +16,63 @@ description: allOf: - $ref: dai-common.yaml# + - if: + properties: + compatible: + contains: + const: apple,t8142-aop-audio + then: + properties: + dmas: + minItems: 5 + dma-names: + minItems: 5 + power-domains: + minItems: 9 + power-domain-names: + minItems: 9 + required: + - apple,chassis-name + - apple,machine-kind + else: + properties: + dmas: + maxItems: 4 + dma-names: + maxItems: 4 + power-domains: + maxItems: 6 + power-domain-names: + maxItems: 6 properties: compatible: - const: apple,t8152-aop-audio + oneOf: + - const: apple,t8152-aop-audio + - items: + - const: apple,t8142-aop-audio + - const: apple,t8152-aop-audio dmas: + minItems: 4 items: - description: Headset jack output - description: Headset microphone input - description: Internal speaker output - description: Speaker sense input + - description: Internal microphone array input dma-names: + minItems: 4 items: - const: cout - const: cin - const: spkr - const: sense + - const: hpai power-domains: + minItems: 6 items: - description: Serializer 0 - description: Serializer 1 @@ -43,8 +80,12 @@ properties: - description: Serializer 3 - description: Serializer 4 - description: Serializer 5 + - description: Secure LEAP ADMAC + - description: LEAP receive channel 0 + - description: LEAP serializer power-domain-names: + minItems: 6 items: - const: mca0 - const: mca1 @@ -52,6 +93,17 @@ properties: - const: mca3 - const: mca4 - const: mca5 + - const: leap_s_a + - const: leap_rx0 + - const: leap_mca + + apple,chassis-name: + $ref: /schemas/types.yaml#/definitions/string + description: Chassis identifier used to name the microphone card + + apple,machine-kind: + $ref: /schemas/types.yaml#/definitions/string + description: Human-readable machine family used to name the microphone card "#sound-dai-cells": const: 1 diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs index 9aad831ad7a61..81a224f697491 100644 --- a/sound/soc/apple/t8152_aop_audio.rs +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -1239,7 +1239,7 @@ unsafe extern "C" fn mic_pcm_trigger(substream: *mut bindings::snd_pcm_substream | bindings::SNDRV_PCM_TRIGGER_PAUSE_RELEASE => { data.hpai_want_run.store(true, Relaxed); // Err: already queued, and that run sees `hpai_want_run`. - let _ = workqueue::system().enqueue::<_, HPAI_START_WORK>(Arc::from(data)); + let _ = workqueue::system_dfl().enqueue::<_, HPAI_START_WORK>(Arc::from(data)); } _ => data.hpai_want_run.store(false, Relaxed), } @@ -1477,7 +1477,8 @@ impl platform::Driver for T8152AopAudioDriver { let mic = if data.leap.is_empty() { None } else { - // Initialize the shared output service before exposing HPAI. + // J813 needs an output service initialized before HPAI can raise + // the shared fabric, even when no playback stream is requested. // This is standby only: no DMA, running state or codec unmute. // No userspace stream can race this before card registration. match data.set_power(&data.cout, POWER_STATE_PW0) @@ -1485,7 +1486,7 @@ impl platform::Driver for T8152AopAudioDriver { { Ok(card) => Some(card), Err(e) => { - dev_err!(dev, "microphone card: {:?}\n", e); + dev_err!(dev, "microphone initialization: {:?}\n", e); None } } From 9b4cf0e9aff84039c9ba2cd83c909c4151d89db1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:06:54 +0100 Subject: [PATCH 019/112] dt-bindings: iommu: apple,sart: Add T8152 compatible The T8152 (M6) SART (ADT sart-version 4) keeps the per-entry configuration, address and size registers in three separate arrays, so it is not compatible with the earlier SARTs. Add apple,t8152-sart. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/iommu/apple,sart.yaml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index e6482453d6dac..021fb3eb5b8f5 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -26,6 +26,9 @@ description: SART3, first seen in M1 Pro/Max, extends both the address space and filter entry size to 42 bit. + SART4, found in T8152 (M6), moves the configuration, address and size + registers into separate arrays. + properties: compatible: oneOf: @@ -45,6 +48,7 @@ properties: - apple,t6000-sart - apple,t8015-sart - apple,t8103-sart + - apple,t8152-sart reg: maxItems: 1 From b16eae52b77a9fdc9d32b0a62597fe2c73e184b1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:06:54 +0100 Subject: [PATCH 020/112] dt-bindings: nvme: apple,nvme-ans: Add T8152 compatible T8152 (M6) uses the secure ANS2 register layout and is not compatible with the earlier controllers. There is no T8152 PMGR provider yet; the loader leaves ANS powered and the driver treats the reset as optional, so do not require resets and power domains for apple,t8152-nvme-ans2. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- .../devicetree/bindings/nvme/apple,nvme-ans.yaml | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index a6dafcf594289..b0f21ee126b01 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -22,6 +22,7 @@ properties: - apple,t8122-nvme-ans2 - const: apple,t8103-nvme-ans2 - const: apple,t8132-nvme-ans2 + - const: apple,t8152-nvme-ans2 - items: - const: apple,t8132-nvme-ans2 - const: apple,t8103-nvme-ans2 @@ -110,6 +111,18 @@ properties: buffers must remain reserved and protected by the SART. allOf: + - if: + properties: + compatible: + not: + contains: + const: apple,t8152-nvme-ans2 + then: + required: + - resets + - power-domains + - power-domain-names + - if: properties: compatible: @@ -170,9 +183,6 @@ required: - compatible - reg - reg-names - - resets - - power-domains - - power-domain-names - mboxes - interrupts - apple,sart From 359d13aada8142ec35896d9030aa50ba99ddbb32 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:06:54 +0100 Subject: [PATCH 021/112] dt-bindings: mailbox: apple,mailbox: Add T8152 ANS mailbox The T8152 (M6) ANS co-processor is reached through a 0x80 window in the post-office mailbox bank. No interrupts are described for it and the host polls it. Add apple,t8152-ans-mailbox and only require interrupts for the other mailboxes. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- .../bindings/mailbox/apple,mailbox.yaml | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index cd19124e724c3..1a40e2e38786b 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -75,6 +75,11 @@ properties: AOP setup-port mailbox with a separate register layout. const: apple,t8140-aop-setup-mailbox + - description: + T8152 ANS post-office mailbox, a 0x80 window in the post-office + bank. No interrupts are described for it; the host polls it. + const: apple,t8152-ans-mailbox + - description: An older ASC mailbox interface found on T2 and A11 that is also used for the NVMe coprocessor and the system management @@ -148,6 +153,20 @@ allOf: - const: send-empty - const: recv-not-empty + - if: + properties: + compatible: + contains: + const: apple,t8152-ans-mailbox + then: + properties: + interrupts: false + interrupt-names: false + else: + required: + - interrupts + - interrupt-names + - if: properties: compatible: @@ -211,8 +230,6 @@ allOf: required: - compatible - reg - - interrupts - - interrupt-names - "#mbox-cells" additionalProperties: false From 2c87179a0c0888cb5d9d4b80c2df50754662d93f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 13:30:24 +0200 Subject: [PATCH 022/112] soc: apple: sart: add the T8152 coastguard SART (sart-version 4) Config, paddr and size registers at 0x00, 0x60 and 0xc0 per entry, in 4 KiB units, as m1n1 src/sart.c. Needed by ANS2 on the M6 Mac mini. Signed-off-by: Thomas Glanzmann [Acelogic: Exercised on the ported code by a read-only probe on the M6; write testing was done on Thomas Glanzmann's original J873 series.] Signed-off-by: Acelogic --- drivers/soc/apple/sart.c | 41 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index 6cedcb867c61b..c44b14c655be8 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -195,6 +195,43 @@ static void sart3_set_entry(struct apple_sart *sart, int index, u8 flags, writel(flags, sart->regs + APPLE_SART3_CONFIG(index)); } +#define APPLE_SART4_CONFIG(idx) (0x00 + 4 * (idx)) +#define APPLE_SART4_PADDR(idx) (0x60 + 4 * (idx)) +#define APPLE_SART4_PADDR_SHIFT 12 +#define APPLE_SART4_SIZE(idx) (0xc0 + 4 * (idx)) +#define APPLE_SART4_SIZE_SHIFT 12 +#define APPLE_SART4_SIZE_MAX GENMASK(29, 0) +#define APPLE_SART4_FLAGS_ALLOW 0xff + +/* T8152 "coastguard" SART (ADT sart-version 4), layout as m1n1 src/sart.c. */ +static void sart4_get_entry(struct apple_sart *sart, int index, u8 *flags, + phys_addr_t *paddr, size_t *size) +{ + phys_addr_t paddr_ = readl(sart->regs + APPLE_SART4_PADDR(index)); + size_t size_ = readl(sart->regs + APPLE_SART4_SIZE(index)); + + *flags = readl(sart->regs + APPLE_SART4_CONFIG(index)); + *size = size_ << APPLE_SART4_SIZE_SHIFT; + *paddr = paddr_ << APPLE_SART4_PADDR_SHIFT; +} + +static void sart4_set_entry(struct apple_sart *sart, int index, u8 flags, + phys_addr_t paddr_shifted, size_t size_shifted) +{ + writel(paddr_shifted, sart->regs + APPLE_SART4_PADDR(index)); + writel(size_shifted, sart->regs + APPLE_SART4_SIZE(index)); + writel(flags, sart->regs + APPLE_SART4_CONFIG(index)); +} + +static struct apple_sart_ops sart_ops_v4 = { + .get_entry = sart4_get_entry, + .set_entry = sart4_set_entry, + .flags_allow = APPLE_SART4_FLAGS_ALLOW, + .size_shift = APPLE_SART4_SIZE_SHIFT, + .paddr_shift = APPLE_SART4_PADDR_SHIFT, + .size_max = APPLE_SART4_SIZE_MAX, +}; + static struct apple_sart_ops sart_ops_v3 = { .get_entry = sart3_get_entry, .set_entry = sart3_set_entry, @@ -409,6 +446,10 @@ static void apple_sart_shutdown(struct platform_device *pdev) } static const struct of_device_id apple_sart_of_match[] = { + { + .compatible = "apple,t8152-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t6000-sart", .data = &sart_ops_v3, From 83e97d02765cd2e67204615e97a732c3a681fec5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 13:30:24 +0200 Subject: [PATCH 023/112] soc: apple: mailbox: add the J873 ANS post-office mailbox Add a polled, interrupt-free provider for the ANS post-office window. ANS uses mailbox 3 of the non-alias post-office bank (0x316010300), a 0x80-byte window with the same counted-FIFO layout as the T8152 SMC mailbox. No interrupt is described for it, so the provider claims none: receive runs on the receive poller of the GFX ASCWrap v8 provider, send polls the FIFO status, and the receive hold/release hooks do nothing for it. It binds only on the J873, at exactly that window. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, which has no PMP post-office provider: the original made the PMP provider's J873 window check per hardware entry and added ANS next to PMP; here the polled mode is added for the ANS entry alone. Exercised on the ported code by a read-only probe on the M6; write testing was done on Thomas Glanzmann's original J873 series.] Co-developed-by: Acelogic Signed-off-by: Acelogic --- drivers/soc/apple/mailbox.c | 63 +++++++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 3 deletions(-) diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index c13c03f9d92ab..8e864229d5efe 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -220,6 +220,10 @@ struct apple_mbox_hw { unsigned int num_ascwrap_v6_roles; /* T8152 GPU ASCWrap v8: wrapper + iop-vbar + post-office window + PSD. */ bool is_ascwrap_v8; + /* No interrupts are described; receive and send are polled. */ + bool rx_poll_required; + /* J873 post-office window a polled provider must sit at. */ + u64 j873_window; /* Status word counts RX occupancy and free TX slots; paired transfers. */ bool counted_fifo; bool ap_initializes_mailboxes; @@ -251,7 +255,7 @@ struct apple_mbox_priv { struct apple_mbox mbox; /* ASCWrap v8 only: the provider's PMGR2 PSD service block (read-only). */ void __iomem *psd_regs; - /* ASCWrap v8 only: receive by polling; fixed at probe. */ + /* ASCWrap v8 and polled providers: receive by polling; fixed at probe. */ bool rx_poll_only; /* rx_lock: recv interrupt enabled and not yet disabled again. */ bool rx_irq_live; @@ -270,7 +274,7 @@ static struct apple_mbox_priv *apple_mbox_to_priv(struct apple_mbox *mbox) /* Only providers allocated by apple_mbox_probe() have a receive poller. */ static bool apple_mbox_has_rx_poller(const struct apple_mbox *mbox) { - return mbox->hw->is_ascwrap_v8; + return mbox->hw->is_ascwrap_v8 || mbox->hw->rx_poll_required; } /* Both ASCWrap generations share the consumer lifecycle API below. */ @@ -1038,12 +1042,17 @@ EXPORT_SYMBOL(apple_mbox_stop); void apple_mbox_hold_rx(struct apple_mbox *mbox) { + /* A polled provider claims no receive interrupt. */ + if (mbox->hw->rx_poll_required) + return; disable_irq(mbox->irq_recv_not_empty); } EXPORT_SYMBOL(apple_mbox_hold_rx); void apple_mbox_release_rx(struct apple_mbox *mbox) { + if (mbox->hw->rx_poll_required) + return; enable_irq(mbox->irq_recv_not_empty); } EXPORT_SYMBOL(apple_mbox_release_rx); @@ -1105,7 +1114,8 @@ static void apple_mbox_quiesce(void *data) if (mbox->irq_send_empty >= 0) synchronize_irq(mbox->irq_send_empty); complete_all(&mbox->tx_empty); - synchronize_irq(mbox->irq_recv_not_empty); + if (mbox->irq_recv_not_empty >= 0) + synchronize_irq(mbox->irq_recv_not_empty); spin_lock_irqsave(&mbox->rx_lock, flags); had_rx = mbox->rx; @@ -1369,6 +1379,16 @@ static int apple_mbox_probe(struct platform_device *pdev) return ret; } else { res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + /* + * A polled provider must be exactly its own 0x80-byte window of + * the J873 post-office bank; the rest belongs to other roles. + */ + if (mbox->hw->rx_poll_required && + (!of_machine_is_compatible("apple,j873g") || !res || + res->start != mbox->hw->j873_window || + resource_size(res) != APPLE_ASCWRAP_V8_MBOX_SIZE)) + return dev_err_probe(dev, -EINVAL, + "post-office window does not match the J873 profile\n"); if (!res || resource_size(res) < mbox->hw->reg_offset + mbox->hw->i2a_recv1 + sizeof(u64)) return dev_err_probe(dev, -EINVAL, @@ -1380,6 +1400,21 @@ static int apple_mbox_probe(struct platform_device *pdev) mbox->regs = (u8 __iomem *)mbox->regs + mbox->hw->reg_offset; } + if (mbox->hw->rx_poll_required) { + mbox->rx_util_min = -1; + mbox->rx_util_min_applied = -1; + spin_lock_init(&mbox->rx_lock); + spin_lock_init(&mbox->tx_lock); + mutex_init(&mbox->lifecycle_lock); + init_completion(&mbox->tx_empty); + priv->rx_poll_only = true; + INIT_DELAYED_WORK(&priv->rx_poll_work, apple_mbox_v8_rx_poll_work); + mbox->irq_recv_not_empty = -ENXIO; + mbox->irq_send_empty = -ENXIO; + dev_info(dev, "J873 post-office: paired transfers, bounded polling, no IRQ claim\n"); + goto setup_pm; + } + mbox->irq_recv_not_empty = platform_get_irq_byname(pdev, "recv-not-empty"); if (mbox->irq_recv_not_empty < 0) @@ -1431,6 +1466,7 @@ static int apple_mbox_probe(struct platform_device *pdev) return ret; } +setup_pm: ret = devm_pm_runtime_enable(dev); if (ret) return ret; @@ -1706,8 +1742,29 @@ static const struct apple_mbox_hw apple_mbox_t8152_smc_hw = { .has_irq_controls = false, }; +/* + * T8152 ANS: msgbox-mailbox-num 3 in the non-alias post-office bank, the + * same counted FIFO as the SMC mailbox. Its interrupt ordering is not known, + * so no interrupt is described and both directions are polled. + */ +static const struct apple_mbox_hw apple_mbox_t8152_ans_hw = { + .rx_poll_required = true, + .j873_window = 0x316010300ULL, + .counted_fifo = true, + .control_full = GENMASK(11, 8), /* free TX slots */ + .control_empty = GENMASK(3, 0), /* RX occupancy */ + .a2i_control = 0x20, + .a2i_send0 = 0x10, + .a2i_send1 = 0x18, + .i2a_control = 0x20, + .i2a_recv0 = 0x00, + .i2a_recv1 = 0x08, + .has_irq_controls = false, +}; + static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t8152-smc-mailbox", .data = &apple_mbox_t8152_smc_hw }, + { .compatible = "apple,t8152-ans-mailbox", .data = &apple_mbox_t8152_ans_hw }, { .compatible = "apple,t6031-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8122-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8152-gfx-ascwrap-v8", .data = &apple_mbox_t8152_gfx_ascwrap_v8_hw }, From 81bc2a911813a8367a10fde004b7eb2bce28625c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 13:30:25 +0200 Subject: [PATCH 024/112] nvme: apple: add T8152 (M6) with the secure register layout The M6 ADT marks ANS2 with nvme-secure-reg-layout: as in macOS AppleANS2NVMeController with its 0x92a flag, AQA/ASQ/ACQ and the I/O queue registers move up by 0x4000 and LINEAR_SQ_CTRL moves to 0x2813c; CC/CSTS, doorbells and NVMMU stay. NVMe and NVMMU share one window, and there is no reset provider yet. Reads and writes verified on J873. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the T8152 entry joins the T8142 and T6040 ones and sets NVME_QUIRK_BROKEN_FUA like the T8132, T8140 and T8142 entries, and the moved LINEAR_SQ_CTRL is used inside the existing lsq_in_nvmmu check. The read and write verification above was on Thomas Glanzmann's original J873 series; the ported code is exercised by a read-only probe on the M6.] Signed-off-by: Acelogic --- drivers/nvme/host/apple.c | 68 ++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index e4c9a1ccd38a0..08ec93ad92780 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -65,6 +65,15 @@ #define APPLE_ANS_LINEAR_ASQ_DB 0x2490c #define APPLE_ANS_LINEAR_IOSQ_DB 0x24910 +/* + * ADT nvme-secure-reg-layout (T8152, macOS AppleANS2NVMeController with its + * 0x92a flag set): AQA/ASQ/ACQ and the I/O queue registers move up by + * 0x4000 and LINEAR_SQ_CTRL moves into the NVMMU block. CC/CSTS, the + * doorbells and the NVMMU TCB registers stay where they are. + */ +#define APPLE_ANS_SECURE_QREG_SHIFT 0x4000 +#define APPLE_ANS_SECURE_LINEAR_SQ_CTRL 0x2813c + #define APPLE_NVMMU_NUM_TCBS 0x28100 #define APPLE_NVMMU_ASQ_TCB_BASE 0x28108 #define APPLE_NVMMU_IOSQ_TCB_BASE 0x28110 @@ -208,6 +217,9 @@ struct apple_nvme_hw { bool needs_ioq_registers; /* T8132 needs a PMGR reset when starting a stopped coprocessor. */ bool cold_reset; + /* No reset provider yet; only an adopted live session can come up. */ + bool optional_reset; + bool secure_reg_layout; u32 max_queue_depth; unsigned long quirks; }; @@ -377,6 +389,17 @@ static int apple_nvme_read_handoff(struct apple_nvme *anv) return apple_nvme_can_adopt_rtkit(anv) ? 0 : -EIO; } +static u32 apple_nvme_qreg(const struct apple_nvme *anv, u32 reg) +{ + return anv->hw->secure_reg_layout ? reg + APPLE_ANS_SECURE_QREG_SHIFT : reg; +} + +static u32 apple_nvme_lsq_ctrl(const struct apple_nvme *anv) +{ + return anv->hw->secure_reg_layout ? APPLE_ANS_SECURE_LINEAR_SQ_CTRL : + APPLE_ANS_LINEAR_SQ_CTRL; +} + static inline struct apple_nvme *queue_to_apple_nvme(struct apple_nvme_queue *q) { if (q->is_adminq) @@ -1786,10 +1809,10 @@ static void apple_nvme_reset_work(struct work_struct *work) */ if (!anv->hw->lsq_in_nvmmu) { writel(APPLE_ANS_LINEAR_SQ_EN, - anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + anv->mmio_nvme + apple_nvme_lsq_ctrl(anv)); if (anv->hw->needs_ioq_registers) { u32 lsq_ctrl = readl(anv->mmio_nvme + - APPLE_ANS_LINEAR_SQ_CTRL); + apple_nvme_lsq_ctrl(anv)); if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN)) { dev_err(anv->dev, @@ -1812,9 +1835,11 @@ static void apple_nvme_reset_work(struct work_struct *work) if (anv->hw->needs_ioq_registers) ioqa_depth--; ioqa = ioqa_depth | (ioqa_depth << 16); - writel(ioqa, anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL); + writel(ioqa, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)); if (anv->hw->needs_ioq_registers && - readl(anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL) != ioqa) { + readl(anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)) != ioqa) { dev_err(anv->dev, "failed to program I/O queue aperture\n"); ret = -EIO; goto out; @@ -1828,11 +1853,11 @@ static void apple_nvme_reset_work(struct work_struct *work) /* Setup the admin queue */ aqa = APPLE_NVME_AQ_DEPTH - 1; aqa |= aqa << 16; - writel(aqa, anv->mmio_nvme + NVME_REG_AQA); + writel(aqa, anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_AQA)); apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, - anv->mmio_nvme + NVME_REG_ASQ); + anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_ASQ)); apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, - anv->mmio_nvme + NVME_REG_ACQ); + anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_ACQ)); if (anv->hw->has_lsq_nvmmu) { /* Setup NVMMU for both queues */ @@ -1899,10 +1924,10 @@ static void apple_nvme_reset_work(struct work_struct *work) * dedicated registers. Without them it crashes and its crash log * reports null I/O SQ and CQ addresses. */ - apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOCQ_REGISTER); - apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOSQ_REGISTER); + apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_IOCQ_REGISTER)); + apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_IOSQ_REGISTER)); } nr_io_queues = 1; if (anv->hw->has_queue_count) { @@ -2393,7 +2418,10 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) goto out_detach_genpd; } - anv->reset = devm_reset_control_array_get_exclusive(anv->dev); + if (anv->hw->optional_reset) + anv->reset = devm_reset_control_array_get_optional_exclusive(anv->dev); + else + anv->reset = devm_reset_control_array_get_exclusive(anv->dev); if (IS_ERR(anv->reset)) { ret = dev_err_probe(dev, PTR_ERR(anv->reset), "Failed to get reset control"); @@ -2754,6 +2782,21 @@ static const struct apple_nvme_hw apple_nvme_t6040_hw = { .quirks = NVME_QUIRK_NO_APST, }; +/* + * T8152 uses the post-M4 queue setup, but its NVMe registers and NVMMU share + * one window (0x325cc0000 on J873) like T8103, with the secure register + * layout. There is no T8152 PMGR driver yet, so the controller has no reset + * line in the DT. + */ +static const struct apple_nvme_hw apple_nvme_t8152_hw = { + .has_lsq_nvmmu = true, + .needs_ioq_registers = true, + .optional_reset = true, + .secure_reg_layout = true, + .max_queue_depth = 64, + .quirks = NVME_QUIRK_BROKEN_FUA, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t6041-nvme-ans2", .data = &apple_nvme_t6040_hw }, { .compatible = "apple,t8015-nvme-ans2", .data = &apple_nvme_t8015_hw }, @@ -2761,6 +2804,7 @@ static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, { .compatible = "apple,t8140-nvme-ans2", .data = &apple_nvme_t8140_hw }, { .compatible = "apple,t8142-nvme-ans2", .data = &apple_nvme_t8142_hw }, + { .compatible = "apple,t8152-nvme-ans2", .data = &apple_nvme_t8152_hw }, { .compatible = "apple,nvme-ans2", .data = &apple_nvme_t8103_hw }, {}, }; From a400e257002e585430953a2a24082acd1c716f7f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 15:11:45 +0100 Subject: [PATCH 025/112] nvme: apple: send the shutdown notification on T8152 The post-M4 disable path only clears CC.EN, so the ANS firmware treats every system shutdown as unclean: on the next boot it logs "uncleanReboot yes" and abandons its open bands (host SLC, parity, CLOG). On T8152, send the NVMe shutdown notification (CC.SHN normal, wait for CSTS.SHST complete) before the CC.EN clear on system shutdown. The RTKit co-processor is still left running, as before. Tested on a J873 (Mac mini M6): after a reboot the firmware no longer reports an unclean reboot (0 instead of 4 "uncleanReboot yes" messages). Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, which already sends the notification at the final system shutdown of every post-M4 controller: T8152 also sends it when the driver is removed, as the original did, but not for system sleep. The test above was on Thomas Glanzmann's original J873 series; the ported code is exercised by a read-only probe on the M6.] Signed-off-by: Acelogic --- drivers/nvme/host/apple.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 08ec93ad92780..5d59726edeb13 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -220,6 +220,8 @@ struct apple_nvme_hw { /* No reset provider yet; only an adopted live session can come up. */ bool optional_reset; bool secure_reg_layout; + /* Also send the NVMe shutdown notification (CC.SHN) on removal. */ + bool shutdown_notify; u32 max_queue_depth; unsigned long quirks; }; @@ -1376,10 +1378,13 @@ static int apple_nvme_disable_locked(struct apple_nvme *anv, bool shutdown) * The final system shutdown is the exception for SHN: without it the * controller counts every Linux shutdown as unsafe (SMART * unsafe_shutdowns) and recovers on the next start, which slows the - * loader and the first seconds of I/O. A failed SHN changes nothing: - * the CC.EN clear below still runs. + * loader and the first seconds of I/O. Where the firmware handles it, + * removal sends it too. A failed SHN changes nothing: the CC.EN clear + * below still runs. */ - if (READ_ONCE(anv->final_shutdown) && !apple_rtkit_is_crashed(anv->rtk)) { + if ((READ_ONCE(anv->final_shutdown) || + (shutdown && anv->hw->shutdown_notify && READ_ONCE(anv->removing))) && + !apple_rtkit_is_crashed(anv->rtk)) { ret = nvme_disable_ctrl(&anv->ctrl, true); if (ret) dev_warn(anv->dev, "shutdown notification failed: %d\n", ret); @@ -2793,6 +2798,7 @@ static const struct apple_nvme_hw apple_nvme_t8152_hw = { .needs_ioq_registers = true, .optional_reset = true, .secure_reg_layout = true, + .shutdown_notify = true, .max_queue_depth = 64, .quirks = NVME_QUIRK_BROKEN_FUA, }; From 8eb5187fd12c0b3798aa3a5ca1c9381c662484f1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 13:30:25 +0200 Subject: [PATCH 026/112] arm64: dts: apple: j873: ANS2 NVMe Mailbox, SART and NVMe nodes for the internal SSD. The driver wakes iBoot's running ANS firmware with a fresh RTKit handshake. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the nodes go into t8152-j873-nvme.dtsi, which t8152-j873g.dts includes, instead of a separate t8152-j873-nvme.dtb layered on the USB tree. Exercised on the ported code by a read-only probe on the M6; write testing was done on Thomas Glanzmann's original J873 series.] Signed-off-by: Acelogic --- .../arm64/boot/dts/apple/t8152-j873-nvme.dtsi | 35 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 36 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi new file mode 100644 index 0000000000000..c53059ab55d34 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi @@ -0,0 +1,35 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g ANS2 NVMe. + * iBoot leaves the ANS firmware running with the NVMe controller disabled; + * the driver wakes it with a fresh RTKit handshake (as m1n1 does). NVMe + * registers and NVMMU share the 0x325cc0000 window. The mailbox is the ANS + * post-office window (msgbox-mailbox-num 3, no alias: 0x316000000 + + * 0x10300). No PMGR power or reset yet. + * Resources are from the 26A434 ADT: ans, sart-ans. + */ + +/ { + soc { + ans_mbox: mailbox@316010300 { + compatible = "apple,t8152-ans-mailbox"; + reg = <0x3 0x16010300 0x0 0x80>; + #mbox-cells = <0>; + }; + + sart: iommu@325c50000 { + compatible = "apple,t8152-sart"; + reg = <0x3 0x25c50000 0x0 0xc000>; + }; + + nvme: nvme@325cc0000 { + compatible = "apple,t8152-nvme-ans2"; + reg = <0x3 0x25cc0000 0x0 0x60000>, + <0x3 0x21600000 0x0 0x4000>; + reg-names = "nvme", "ans"; + interrupts = ; + mboxes = <&ans_mbox>; + apple,sart = <&sart>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 1513a2abbc83f..77e5e1abdf18a 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -286,3 +286,4 @@ #include "t8152-j873-pmc.dtsi" #include "t8152-j873-qspi.dtsi" +#include "t8152-j873-nvme.dtsi" From 9c56293bc07aab63f5b09dd1502bf5e35f0c0425 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 12:35:44 +0200 Subject: [PATCH 027/112] arm64: dts: apple: j873: USB1 (back-left) USB2 host bring-up Describe usb-drd1 as a plain DWC3 host behind its two T8110-style DARTs. The loader powers the controller, wakes the port's HPM (SSPS 0) and initialises the eUSB2 PHY in host mode before Linux starts. Resources are from the 26A434 ADT. A USB keyboard enumerates. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the nodes go into t8152-j873-usb.dtsi, which t8152-j873g.dts includes, instead of a separate t8152-j873-usb.dtb. dtbs_check warns that the snps,dwc3 binding allows one iommus entry; the controller sits behind two DARTs, as described here.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 37 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 38 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi new file mode 100644 index 0000000000000..59f0dcf394617 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g USB1 (usb-drd1, back-left port) USB2 host bring-up. + * The loader powers the controller and initialises the eUSB2 PHY in host + * mode before Linux starts (no PMGR, PHY or Type-C driver yet), so the + * controller is described as a plain DWC3 host behind its two DARTs. + * Resources are from the 26A434 ADT: dart-usb1, usb-drd1. + */ + +/ { + soc { + usb1_dart0: iommu@40b020000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x4 0x0b020000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + usb1_dart1: iommu@40b040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + usb1: usb@40a430000 { + compatible = "snps,dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&usb1_dart0 0>, <&usb1_dart1 1>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 77e5e1abdf18a..ac38151e0acb0 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -287,3 +287,4 @@ #include "t8152-j873-pmc.dtsi" #include "t8152-j873-qspi.dtsi" #include "t8152-j873-nvme.dtsi" +#include "t8152-j873-usb.dtsi" From 7c13f45712128843ebce56d9238330339162c627 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 12:42:59 +0200 Subject: [PATCH 028/112] arm64: dts: apple: j873: USB2 host for the front ports (usb-drd2) usb-drd2 feeds the on-board VL822 hub (05ac:800f) behind the two front USB-C ports. Describe it like usb-drd1: plain DWC3 host behind its two DARTs (0x383020000/0x383040000, IRQ 1750), controller IRQ 1763. The loader also releases the hub from reset (nub-gpio 39). Signed-off-by: Thomas Glanzmann [Acelogic: the nodes go into t8152-j873-usb.dtsi; dtbs_check gives the same snps,dwc3 iommus warning as for usb-drd1.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 35 ++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index 59f0dcf394617..e5cd25e427fe4 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -1,10 +1,11 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT /* - * J873g USB1 (usb-drd1, back-left port) USB2 host bring-up. - * The loader powers the controller and initialises the eUSB2 PHY in host + * J873g USB2 host bring-up: usb-drd1 (back-left port) and usb-drd2 + * (front ports via the on-board hub). + * The loader powers the controllers and initialises the eUSB2 PHYs in host * mode before Linux starts (no PMGR, PHY or Type-C driver yet), so the - * controller is described as a plain DWC3 host behind its two DARTs. - * Resources are from the 26A434 ADT: dart-usb1, usb-drd1. + * controllers are described as plain DWC3 hosts behind their two DARTs. + * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2. */ / { @@ -33,5 +34,31 @@ snps,dis_u2_susphy_quirk; snps,dis_u3_susphy_quirk; }; + + usb2_dart0: iommu@383020000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x83020000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + usb2_dart1: iommu@383040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x83040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ + usb2: usb@382430000 { + compatible = "snps,dwc3"; + reg = <0x3 0x82430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&usb2_dart0 0>, <&usb2_dart1 1>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; }; }; From 199c58c9e45672d45f34bbfe12d4b4f737fa3e59 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 09:45:57 +0100 Subject: [PATCH 029/112] PCI: apple: keep T8152 endpoints at the reset Max_Read_Request_Size On T8152 (J873) the on-board RTL8127A transmits much slower with large read requests: r8169 sets MRRS to 4096, which limits 9000-byte frames to 7.0 Gbit/s (UDP, iperf3 to an ixgbe peer). At 2048 it reaches 7.9, at 1024, 512 or 256 the full 9.93 Gbit/s; at MTU 1500 TCP Tx goes from 9.1 to 9.4 Gbit/s and UDP Tx from 7.9 to 9.5. Set no_inc_mrrs on the T8152 host bridge so devices keep the 512-byte reset value and drivers cannot raise it. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- drivers/pci/controller/pcie-apple.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 3173186c85209..a378955bb922c 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -224,6 +224,12 @@ struct hw_info { * lane PIPE reset status, then release PORT_T8152_PIPE_RST. */ bool pipe_rst; + /* + * Keep endpoints at their reset Max_Read_Request_Size (512 bytes). + * On T8152 an RTL8127 at MRRS 4096 (what r8169 asks for) transmits + * 9000-byte frames at 7.0 Gbit/s; at 512 it reaches 9.93. + */ + bool no_inc_mrrs; }; static const struct hw_info t8103_hw = { @@ -279,6 +285,7 @@ static const struct hw_info t8152_hw = { .max_rid2sid = 512, .refbuf_off = true, .pipe_rst = true, + .no_inc_mrrs = true, }; static const struct hw_info t8103_pciec_hw = { @@ -3116,6 +3123,7 @@ static int apple_pcie_probe(struct platform_device *pdev) pcie = pci_host_bridge_priv(bridge); pcie->dev = dev; pcie->hw = hw; + bridge->no_inc_mrrs = hw->no_inc_mrrs; if (of_property_present(dev->of_node, "apple,managed-sids")) { u32 ids[15]; int count = of_property_count_u32_elems(dev->of_node, "apple,managed-sids"); From 1ef5ecd7bc670f4a678d4698e36ae8a017da7552 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 24 Oct 2026 14:58:10 +0200 Subject: [PATCH 030/112] arm64: dts: apple: j873: apcie port 2 with the on-board 10GbE NIC Describe apcie port 2 next to port 0 (N1): its DART (dart-apcie2), the port with PERST# on AP GPIO 5 and its INTx controller and bus range like the other Apple root ports, and the NIC (MAC address filled in by the loader). The ADT names an aqc107 there; the device has PCI ID 10ec:8127 and is driven by r8169. pcie-apple brings the port up with the T602x port layout plus two steps from macOS: clear PHY_LANE_CFG bit 4 in the refclk handshake (AppleT8152PCIePort::_initializeRefclkBuffer), and after PERST# wait for the lane PIPE reset status (port 0xa8) and clear port 0x82c bit 16 (APCIECoreRCGen5Port::enablePortHardware). The loader must first ungate the AUS5 PHY and write lane-cfg to RC reg 4. Link: Gen3 x1, 10Gbps. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, where the T8152 hw entry, both macOS steps, the AP GPIO controller and port 0 (N1) already exist: only the device tree part remains, in t8152-j873-ethernet.dtsi, squashed with the original follow-up that describes the port per the binding, and the subject changed to match. Port 2 is bus 2 (RID 0x200 to dart-apcie2 stream 1), and the per-port interrupts are listed up to port 2. A port 2 setup failure (lanes stuck in PIPE reset, for example) fails the whole host, port 0 included, so the aura loader's j873_pcie_prep() (PHY tunables, AUS5 ungate, lane-cfg, dart-apcie0/2 tunables) must run before Linux starts. At runtime the NIC identifies as RTL8125CP (XID 0x708).] Signed-off-by: Acelogic --- .../boot/dts/apple/t8152-j873-ethernet.dtsi | 67 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 68 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi new file mode 100644 index 0000000000000..a2350ed7bee4e --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g internal PCIe (apcie) port 2: the on-board 10GbE NIC (ADT + * /arm-io/apcie/pci-bridge2/lan0; the ADT names an aqc107, the device has + * PCI ID 10ec:8127 and identifies as a Realtek RTL8125CP, XID 0x708). + * iBoot leaves the APCIE power domains on and + * the root complex enabled, but the AUS5 PHY gated and the lanes assigned + * to port 0; the loader ungates the PHY, writes the ADT lane-cfg and applies + * the dart-apcie2 tunables first. Port setup follows the T602x/T8122 + * register layout. Port 0 (N1) is bus 1, port 2 is bus 2. + * Resources are from the 26A434 ADT: apcie, dart-apcie2, gpio0. + */ +#include + +/ { + soc { + pcie2_dart: iommu@38a000000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x8a000000 0x0 0xc000>; + #iommu-cells = <1>; + interrupts = ; + }; + }; +}; + +&pcie { + reg = <0x1c 0xb0000000 0x0 0x1000000>, /* config */ + <0x3 0x8c000000 0x0 0x4000>, /* rc */ + <0x3 0x88028000 0x0 0x4000>, /* port0 */ + <0x3 0x8f010000 0x0 0x4000>, /* phy0 */ + <0x3 0x8a028000 0x0 0x4000>, /* port2 */ + <0x3 0x8f018000 0x0 0x4000>; /* phy2 */ + reg-names = "config", "rc", "port0", "phy0", "port2", "phy2"; + /* One per root port, indexed by the port number. */ + interrupts = , + , + ; + iommu-map = <0x100 &pcie0_dart 1 1>, + <0x101 &pcie0_dart 2 1>, + <0x102 &pcie0_dart 3 1>, + <0x200 &pcie2_dart 1 1>; + bus-range = <0 7>; + + port02: pci@2,0 { + device_type = "pci"; + reg = <0x1000 0x0 0x0 0x0 0x0>; + reset-gpios = <&pinctrl_ap 5 GPIO_ACTIVE_LOW>; + bus-range = <2 2>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &port02 0 0 0 0>, + <0 0 0 2 &port02 0 0 0 1>, + <0 0 0 3 &port02 0 0 0 2>, + <0 0 0 4 &port02 0 0 0 3>; + + ethernet0: ethernet@0,0 { + reg = <0x20000 0x0 0x0 0x0 0x0>; + /* Filled in by the loader from the ADT. */ + local-mac-address = [00 00 00 00 00 00]; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index ac38151e0acb0..67c7c9c0d4f44 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -288,3 +288,4 @@ #include "t8152-j873-qspi.dtsi" #include "t8152-j873-nvme.dtsi" #include "t8152-j873-usb.dtsi" +#include "t8152-j873-ethernet.dtsi" From cef0a05d16eccf6b7f4394d66f4666953eb7b6e8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 22:53:27 +0100 Subject: [PATCH 031/112] arm64: dts: apple: j873: ethernet0 alias Boot loaders (m1n1, aura) fill in the on-board NIC's MAC address through the ethernet0 alias, as on the other Apple machines. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the alias goes into t8152-j873-ethernet.dtsi.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi index a2350ed7bee4e..66965f04af13d 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi @@ -13,6 +13,10 @@ #include / { + aliases { + ethernet0 = ðernet0; + }; + soc { pcie2_dart: iommu@38a000000 { compatible = "apple,t8152-dart", "apple,t8110-dart"; From 4d0152993810f42ce8b172ec5484ce2397ce4d15 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:19:57 +0100 Subject: [PATCH 032/112] dt-bindings: watchdog: apple,wdt: Add T8152 compatible The T8152 (M6) watchdog is compatible with the T8103 one. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/watchdog/apple,wdt.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml index 00b0f2ec2bdb4..0a21eb27ad083 100644 --- a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml @@ -24,6 +24,7 @@ properties: - apple,t8122-wdt - apple,t8132-wdt - apple,t8140-wdt + - apple,t8152-wdt - const: apple,t8103-wdt - items: - enum: From c9eeda6528376098cc38f3c5ad4cb3ee41c7a0a1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:19:57 +0100 Subject: [PATCH 033/112] dt-bindings: spmi: apple,spmi: Add T8152 compatible The T8152 (M6) SPMI controller is a fourth generation with its FIFO registers moved to 0x200, so it is not compatible with the T8103 one. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, which already describes the gen-4 T8142 controller and drives its layout: T8152 takes an apple,t8142-spmi fallback instead of a driver match of its own.] Signed-off-by: Acelogic --- Documentation/devicetree/bindings/spmi/apple,spmi.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml index ac2e7407ef780..e504ed9a8871a 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -38,6 +38,11 @@ properties: - apple,t8132-spmi - apple,t8140-spmi - const: apple,t8103-spmi + - description: + The gen-4 controller of T8152, with its FIFO registers at 0x200. + items: + - const: apple,t8152-spmi + - const: apple,t8142-spmi reg: minItems: 1 From 8c011c1b0d126d784645a3a7f737e614b43df44c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:19:57 +0100 Subject: [PATCH 034/112] dt-bindings: nvmem: apple,spmi-nvmem: Add woodcote PMIC The primary PMU of T8152 (M6) machines is "woodcote" (ADT pmu-main), with the boot flags in the same scratchpad layout as the other Apple PMICs. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml index fe8b2001f4fa5..4a2ba5158b0f6 100644 --- a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml +++ b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml @@ -28,6 +28,7 @@ properties: - apple,simetra-pmic - apple,stowe-pmic - apple,vale-pmic + - apple,woodcote-pmic - const: apple,spmi-nvmem reg: From 5ba4dea4e64d6eeed57f7409999f37a87e10e976 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 14:56:45 +0100 Subject: [PATCH 035/112] mfd: macsmc: register macsmc-reboot on T8152 T8152 registers only macsmc-hwmon. The reboot function only writes the MBSE key, and key writes already work on this SMC. Register macsmc-reboot as well; notifications, GPIO and the power supply stay unregistered. On a J873 (Mac mini M6), reboot then sends MBSE = rest, then phra, and the machine restarts with the boot chime; poweroff sends offw, then off1, and it switches off. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, whose T8152 hwmon leaves fan control to the firmware: its fan keys are read-only unless the unsafe fan_control parameter is set (in the original, macsmc-hwmon drove the fan through F0md/F0Tg), and the comment says so. The reboot and power off test above was on Thomas Glanzmann's original J873 series.] Signed-off-by: Acelogic --- drivers/mfd/macsmc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 546e5cdbb72ad..2050127a98c57 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -63,9 +63,15 @@ static const struct mfd_cell apple_smc_devs[] = { static const struct mfd_cell apple_smc_low_gpio_dev = MFD_CELL_OF("macsmc-low-gpio", NULL, NULL, 0, 0, "apple,smc-low-gpio"); -/* T8152 currently exposes read-only telemetry; firmware owns fan control. */ +/* + * T8152: temperatures and fans (hwmon; the fan keys are read-only unless the + * unsafe fan_control parameter is set) and power off/restart (reboot, which + * only writes the MBSE key). Notifications, GPIO and the power supply are not + * qualified there yet. + */ static const struct mfd_cell apple_smc_telemetry_devs[] = { MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"), + MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"), }; static void apple_smc_read_sram(struct apple_smc *smc, void *buf, size_t size) @@ -546,7 +552,7 @@ static int apple_smc_probe(struct platform_device *pdev) return dev_err_probe(smc->dev, ret, "Failed to get key count"); smc->key_count = be32_to_cpu(count); - /* Notifications, GPIO and power management are not qualified on T8152. */ + /* T8152: key reads and writes are qualified; notifications and GPIO are not. */ if (of_device_is_compatible(dev->of_node, "apple,t8152-smc")) return devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, apple_smc_telemetry_devs, From 0c2a84ea8f8df23b8318f8b491ac94c0407a482e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 14:56:45 +0100 Subject: [PATCH 036/112] arm64: dts: apple: j873: SMC power off/restart and the watchdog Describe the SMC reboot function (apple,smc-reboot) and the watchdog (ADT /arm-io/wdt, wdt,t8152, IRQ 447), with a 24 MHz clkref (the ADT timebase-frequency) as on T8103. The PMU NVMEM boot flags are not described yet; macsmc-reboot treats them as optional. The watchdog registers at 24 MHz and provides /dev/watchdog and a restart fallback. Signed-off-by: Thomas Glanzmann [Acelogic: the nodes use the labels of t8152-j873g.dts.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873g.dts | 26 +++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 67c7c9c0d4f44..36c14293fb6db 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -205,6 +205,15 @@ opp-level = <3>; }; }; + + /* The 24 MHz timebase (ADT timebase-frequency), as on T8103. */ + clkref: clock-ref { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + clock-output-names = "clkref"; + }; + timer { compatible = "arm,armv8-timer"; interrupts = , @@ -241,6 +250,14 @@ #performance-domain-cells = <0>; }; + /* ADT /arm-io/wdt (wdt,t8152): restart fallback and /dev/watchdog. */ + wdt: watchdog@3082b0000 { + compatible = "apple,t8152-wdt", "apple,t8103-wdt"; + reg = <3 0x082b0000 0 0x4000>; + clocks = <&clkref>; + interrupts = ; + }; + smc_mbox: mailbox@30c710080 { compatible = "apple,t8152-smc-mailbox"; reg = <3 0x0c710080 0 0x80>; @@ -257,6 +274,15 @@ reg-names = "smc", "sram"; mboxes = <&smc_mbox>; + /* + * Power off (MBSE = off1) and restart (MBSE = phra). The + * PMU NVMEM boot flags are not described yet; the driver + * treats them as optional. + */ + smc_reboot: reboot { + compatible = "apple,smc-reboot"; + }; + hwmon { compatible = "apple,smc-hwmon"; apple,discover-temperatures; From 6061934c7964cea3f15b6c06498e511d847abfa3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 15:11:45 +0100 Subject: [PATCH 037/112] arm64: dts: apple: j873: PMU boot flags on SPMI for power off 'off1' only keeps the machine off when the PMU shutdown flag is set; without it the J873 powered back on into m1n1 at once. Describe nub-spmi0 (gen 4, 0x308714000, 16 KiB) and its primary PMU (pmu-main, "woodcote", slave 0xe) as an apple,spmi-nvmem with the boot flags in its legacy scratchpad (ADT info-leg_scrpad = 0xf800, laid out as on T8103 and T8140): boot_stage 0xf801 (read 0x30, kernel started), boot_error_count and panic_count 0xf802, shutdown_flag 0xf80f bit 3. Hand them to macsmc-reboot. Tested: poweroff now leaves the Mac mini off; reboot still restarts. Signed-off-by: Thomas Glanzmann [Acelogic: the controller takes the apple,t8142-spmi fallback of the aurora-wip binding.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873g.dts | 59 +++++++++++++++++++++-- 1 file changed, 54 insertions(+), 5 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 36c14293fb6db..180b435f1d969 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -10,6 +10,7 @@ #include #include +#include / { compatible = "apple,j873g", "apple,t8152", "apple,arm-platform"; @@ -250,6 +251,54 @@ #performance-domain-cells = <0>; }; + /* + * ADT /arm-io/nub-spmi0 (gen 4) and its primary PMU, pmu-main + * ("woodcote", slave 0xe). The boot flags live in the legacy + * scratchpad (info-leg_scrpad = 0xf800), laid out as on T8103 + * and T8140; boot_stage read 0x30 (kernel started) here. + */ + nub_spmi0: spmi@308714000 { + /* + * Gen 4: FIFO registers at 0x200 (the block is 0x4000 + * long); polled, so no interrupts are described yet. + */ + compatible = "apple,t8152-spmi", "apple,t8142-spmi"; + reg = <0x3 0x08714000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + + pmic@e { + compatible = "apple,woodcote-pmic", "apple,spmi-nvmem"; + reg = <0xe SPMI_USID>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + boot_stage: boot-stage@f801 { + reg = <0xf801 0x1>; + }; + + boot_error_count: boot-error-count@f802,0 { + reg = <0xf802 0x1>; + bits = <0 4>; + }; + + panic_count: panic-count@f802,4 { + reg = <0xf802 0x1>; + bits = <4 4>; + }; + + /* Set before off1, or the machine powers back on. */ + shutdown_flag: shutdown-flag@f80f,3 { + reg = <0xf80f 0x1>; + bits = <3 1>; + }; + }; + }; + }; + /* ADT /arm-io/wdt (wdt,t8152): restart fallback and /dev/watchdog. */ wdt: watchdog@3082b0000 { compatible = "apple,t8152-wdt", "apple,t8103-wdt"; @@ -274,13 +323,13 @@ reg-names = "smc", "sram"; mboxes = <&smc_mbox>; - /* - * Power off (MBSE = off1) and restart (MBSE = phra). The - * PMU NVMEM boot flags are not described yet; the driver - * treats them as optional. - */ + /* Power off (MBSE = off1) and restart (MBSE = phra). */ smc_reboot: reboot { compatible = "apple,smc-reboot"; + nvmem-cells = <&shutdown_flag>, <&boot_stage>, + <&boot_error_count>, <&panic_count>; + nvmem-cell-names = "shutdown_flag", "boot_stage", + "boot_error_count", "panic_count"; }; hwmon { From edd345ad332ce915af32cbb99ae537c50e635fbf Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:53 +0100 Subject: [PATCH 038/112] dt-bindings: arm: apple: apple,pmgr: Add T8152 compatible The T8152 (M6) PMGR blocks are compatible with the T8103 ones. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index 5d9f55c3e5899..b059430cee63d 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -45,6 +45,7 @@ properties: - apple,t8132-pmgr - apple,t8140-pmgr - apple,t8142-pmgr + - apple,t8152-pmgr - const: apple,t8103-pmgr - const: syscon - const: simple-mfd From 2c943f48e8d467f0f8119f61fcdddae8c2270fb0 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:53 +0100 Subject: [PATCH 039/112] dt-bindings: power: apple,pmgr-pwrstate: Add T8152 compatible The T8152 (M6) PMGR power state registers are compatible with the T8103 ones. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index 1c3bd5a5b5d2c..eeaf5f20827f9 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -69,6 +69,7 @@ properties: - apple,t8132-pmgr-pwrstate - apple,t8140-pmgr-pwrstate - apple,t8142-pmgr-pwrstate + - apple,t8152-pmgr-pwrstate - const: apple,t8103-pmgr-pwrstate reg: From 5e49fec7858a20e35fcf5c9c335c265aecec3513 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:54 +0100 Subject: [PATCH 040/112] dt-bindings: i2c: apple,i2c: Add T8152 compatible The T8152 (M6) I2C controllers are compatible with the T8103 ones. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/i2c/apple,i2c.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml index 5c827af153cb5..f117341886ca5 100644 --- a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml +++ b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml @@ -30,6 +30,7 @@ properties: - apple,t8122-i2c - apple,t8132-i2c - apple,t8140-i2c + - apple,t8152-i2c - const: apple,t8103-i2c - items: - enum: From 523a1caa53ea200de6bdd23aebf912d8149f26af Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:53 +0100 Subject: [PATCH 041/112] dt-bindings: mailbox: apple,mailbox: Add T8152 ASC wrapper mailbox The T8152 (M6) SMC and AOP mailboxes are ASC wrapper v8 instances, described with two interrupts (send-empty, recv-not-empty) like the T8140 AOP setup port, but without an IOMMU or DMA window. Add apple,t8152-ascwrap-v8-mailbox and split the conditions into interrupt layout and setup-port resources. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, where the SMC mailbox already has its own apple,t8152-smc-mailbox compatible with this interrupt layout: the new compatible is described for the AOP mailbox and joins that interrupt condition. The T8140 setup-port conditions are unchanged.] Signed-off-by: Acelogic --- .../devicetree/bindings/mailbox/apple,mailbox.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 1a40e2e38786b..5c112f77a53a2 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -27,6 +27,12 @@ properties: masking provided by the interrupt controller. const: apple,t8152-smc-mailbox + - description: + T8152 ASC wrapper (v8) mailbox of the AOP, with the counted + FIFOs of the SMC mailbox, described with its send-empty and + recv-not-empty interrupts. + const: apple,t8152-ascwrap-v8-mailbox + - description: ASC mailboxes are the most common variant found on the M1 used for example for the display controller, the system management @@ -142,7 +148,9 @@ allOf: properties: compatible: contains: - const: apple,t8152-smc-mailbox + enum: + - apple,t8152-ascwrap-v8-mailbox + - apple,t8152-smc-mailbox then: properties: interrupts: @@ -215,6 +223,8 @@ allOf: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox - apple,t8140-aop-setup-mailbox + - apple,t8152-ans-mailbox + - apple,t8152-ascwrap-v8-mailbox - apple,t8152-smc-mailbox then: properties: From d237a9aa748912da5ce1d383decb585bf2639026 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:53 +0100 Subject: [PATCH 042/112] dt-bindings: dma: apple,admac: Add T8152 compatible The T8152 (M6) ADMAC (ADT admac-evolution,t8152) has its own register layout, so it is not compatible with the earlier ones. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- Documentation/devicetree/bindings/dma/apple,admac.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/dma/apple,admac.yaml b/Documentation/devicetree/bindings/dma/apple,admac.yaml index 64d80cd5f4bcd..17e3f37e673c5 100644 --- a/Documentation/devicetree/bindings/dma/apple,admac.yaml +++ b/Documentation/devicetree/bindings/dma/apple,admac.yaml @@ -44,6 +44,7 @@ properties: - items: - const: apple,t6041-admac - const: apple,t8132-admac + - const: apple,t8152-admac reg: maxItems: 1 From f1ce875e034a3449bf08a60b2e29729f6826c738 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:16:37 +0100 Subject: [PATCH 043/112] dt-bindings: iommu: apple,dart: add apple,retain-translation On T8152 iBoot hands dart-sbr over translating for the AOP and the audio ADMAC without setting the lock bit, and the AOP firmware keeps using the inherited mappings. Describe the property that tells the OS to inherit such a DART instead of resetting it, and who owns which root entries. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- .../devicetree/bindings/iommu/apple,dart.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 514b17641bf5b..9968b519a6db7 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -169,6 +169,17 @@ properties: and filtering state without a separate page-table root. Source and destination must differ, and both must exist on the controller. + apple,retain-translation: + type: boolean + description: > + The bootloader hands this DART over translating, with stream page + tables that a co-processor's firmware keeps using, but without setting + the hardware lock. The operating system then treats the DART as locked: + it does not reset it or replace the inherited stream roots, adds its + own mappings only in root entries that are empty at handoff, and on + detach clears only the entries it added. The entries present at handoff + stay owned by the firmware, which may keep using them at any time. + required: - compatible - reg From 76188ec353b94e2274566d0f736954897d8c54a9 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sat, 7 Nov 2026 21:53:37 -0500 Subject: [PATCH 044/112] soc: apple: mailbox: match the T8152 AOP ASC wrapper mailbox The T8152 AOP mailbox (ADT aop, iop,ascwrap-v8, mailbox 0 of the bank at 0x310740000) is the same counted FIFO as the SMC mailbox, with the same send-empty and recv-not-empty interrupts. Match apple,t8152-ascwrap-v8-mailbox, the compatible of the J873 AOP mailbox node, to the SMC mailbox layout. Signed-off-by: Acelogic --- drivers/soc/apple/mailbox.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 8e864229d5efe..4f39be303968a 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -1764,6 +1764,8 @@ static const struct apple_mbox_hw apple_mbox_t8152_ans_hw = { static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t8152-smc-mailbox", .data = &apple_mbox_t8152_smc_hw }, + /* The AOP's ASC wrapper mailbox has the SMC mailbox's counted FIFOs. */ + { .compatible = "apple,t8152-ascwrap-v8-mailbox", .data = &apple_mbox_t8152_smc_hw }, { .compatible = "apple,t8152-ans-mailbox", .data = &apple_mbox_t8152_ans_hw }, { .compatible = "apple,t6031-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8122-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, From 613be379ab9198402eecc007409a65e6c29fad81 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:31 +0100 Subject: [PATCH 045/112] iommu: apple-dart: inherit an unlocked bootloader translation on request On T8152 iBoot leaves dart-sbr translating for the AOP and the audio ADMAC: streams 0, 1 and 42 have live page tables, and the firmware's own mappings sit in root slot 16 of each. Unlike the DARTs SPTM locks, the lock bit is not set, so the driver would reset the DART and pull the tables out from under the AOP firmware. With apple,retain-translation the DART is treated as locked: the inherited roots are kept and Linux publishes its mappings into vacant root slots. Signed-off-by: Thomas Glanzmann Signed-off-by: Acelogic --- drivers/iommu/apple-dart.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index d39ee78d9d73c..94c79671db6fd 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -3976,6 +3976,14 @@ static irqreturn_t apple_dart_irq(int irq, void *dev) static bool apple_dart_is_locked(struct apple_dart *dart) { + /* + * apple,retain-translation: the bootloader left live stream tables + * that a co-processor's firmware depends on, but did not set the lock + * bit (T8152 dart-sbr: AOP and audio ADMAC streams). Treat it as + * locked so the tables are inherited rather than reset. + */ + if (of_property_read_bool(dart->dev->of_node, "apple,retain-translation")) + return true; return !!(apple_dart_readl(dart, dart->hw->lock) & dart->hw->lock_bit); } From 5bef582af4beafab3bd4c02e85ec133253f0111c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:31 +0100 Subject: [PATCH 046/112] dmaengine: apple-admac: support the T8152 layout The T8152 ADMAC (ADT admac-evolution,t8152; worked out from the macOS AudioDMAController-T8152 driver and on hardware) keeps the per-channel register block and the global start/stop/interrupt registers, but: - the channel blocks are 0x4000 apart, TX n at 0x40000 + 0x4000 n and RX n at 0x80000 + 0x4000 n; - a channel is put in state 2 (+0x30 bits 3:0) and +0x4 is written 0x029b0000 before it is started, as macOS does; - the last descriptor word carries a descriptor id 1..255 in its low byte, which macOS never leaves at 0; - the SRAM size registers carry the channel count in bits 31:24, and the AP's carveouts start above the firmware's (base 0x1000, 1 KiB blocks); - only the word size is set in the bus width register. The descriptor and report FIFO ports are the legacy ones: the RX descriptor port answers at 0x14000 + 4n, not at the 0x10040 + 4n the ADT lists. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the descriptor id is set in admac_write_hw_desc(), which writes every descriptor there, the SRAM carveout bounds combine with the T8132 split-channel handling, and the state register is the +0x30 one that aurora-wip programs as REG_CHAN_BURST on T8132.] Signed-off-by: Acelogic --- drivers/dma/apple-admac.c | 80 +++++++++++++++++++++++++++++++++++---- 1 file changed, 72 insertions(+), 8 deletions(-) diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index 60b8c04530634..bdafb0ff4aecb 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -70,13 +70,29 @@ */ #define REG_CHAN_BASE_LEGACY(ch) (0x8000 + (ch) * 0x200) #define REG_CHAN_BASE_EVOLVED(ch) (((ch) & 1 ? 0xc000 : 0x8000) + ((ch) / 2) * 0x200) -#define REG_CHAN_BASE(ad, ch) ((ad)->evolved_layout ? \ +/* + * T8152 (ADT admac-evolution,t8152; the macOS AudioDMAController-T8152 + * driver): the same per-channel block, 0x4000 apart, TX at 0x40000 and RX + * at 0x80000, and a channel has to be put in state 2 (+0x30 bits 3:0) + * before it is started. The descriptor and report FIFO ports are the legacy + * ones (the RX descriptor port answers at 0x14000 + 4n, not at the ADT's + * 0x10040 + 4n). + */ +#define REG_CHAN_BASE_T8152(ch) (((ch) & 1 ? 0x80000 : 0x40000) + ((ch) / 2) * 0x4000) +#define REG_CHAN_BASE(ad, ch) ((ad)->t8152_layout ? REG_CHAN_BASE_T8152(ch) : \ + (ad)->evolved_layout ? \ REG_CHAN_BASE_EVOLVED(ch) : REG_CHAN_BASE_LEGACY(ch)) #define REG_CHAN_CTL(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x00) #define REG_CHAN_CTL_RST_RINGS BIT(0) #define REG_CHAN_CONFIG(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x04) +/* macOS writes this for the T8152 base-ns channels before every start */ +#define CHAN_CONFIG_T8152 0x029b0000 #define REG_CHAN_BURST(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x30) +/* T8152: the low nibble of the same register is the channel state */ +#define REG_CHAN_STATE(ad, ch) REG_CHAN_BURST(ad, ch) +#define CHAN_STATE_MASK GENMASK(3, 0) +#define CHAN_STATE_READY 2 #define REG_DESC_RING(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x70) #define REG_REPORT_RING(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x74) @@ -104,6 +120,11 @@ #define REG_DESC_WRITE(ch) (0x10000 + ((ch) / 2) * 0x4 + ((ch) & 1) * 0x4000) #define REG_REPORT_READ(ch) (0x10100 + ((ch) / 2) * 0x4 + ((ch) & 1) * 0x4000) +/* T8152: the AP's share of each SRAM pool starts above the firmware's. */ +#define T8152_SRAM_BASE 0x1000 +#define T8152_SRAM_BLOCK 1024 +#define SRAM_SIZE_MASK GENMASK(15, 0) + #define REG_TX_INTSTATE(idx) (0x0030 + (idx) * 4) #define REG_RX_INTSTATE(idx) (0x0040 + (idx) * 4) #define REG_GLOBAL_INTSTATE(idx) (0x0050 + (idx) * 4) @@ -124,6 +145,8 @@ struct admac_chan { struct tasklet_struct tasklet; u32 carveout; + /* T8152: transfer descriptor id, 1..255 */ + u8 desc_id; spinlock_t lock; struct admac_tx *current_tx; @@ -164,6 +187,7 @@ struct admac_data { bool set_unk28; bool evolved_layout; bool split_channels; + bool t8152_layout; bool ctl_programmed; int irq; int irq_index; @@ -193,6 +217,7 @@ struct admac_hw { bool set_unk28; bool evolved_layout; bool split_channels; + bool t8152_layout; }; static int admac_alloc_sram_carveout(struct admac_data *ad, @@ -201,6 +226,8 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, { struct admac_sram *sram; int i, ret = 0, nblocks; + u32 first = 0, block = SRAM_BLOCK; + ad->txcache.size = readl_relaxed(ad->base + REG_TX_SRAM_SIZE); ad->rxcache.size = readl_relaxed(ad->base + REG_RX_SRAM_SIZE); /* T8132 reports channel metadata in the upper half of these words. */ @@ -208,6 +235,13 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, ad->txcache.size &= GENMASK(15, 0); ad->rxcache.size &= GENMASK(15, 0); } + if (ad->t8152_layout) { + /* bits 31:24 are the channel count */ + ad->txcache.size &= SRAM_SIZE_MASK; + ad->rxcache.size &= SRAM_SIZE_MASK; + first = T8152_SRAM_BASE; + block = T8152_SRAM_BLOCK; + } if (dir == DMA_MEM_TO_DEV) sram = &ad->txcache; @@ -216,14 +250,14 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, mutex_lock(&ad->cache_alloc_lock); - nblocks = sram->size / SRAM_BLOCK; + nblocks = sram->size > first ? (sram->size - first) / block : 0; for (i = ad->split_channels ? 1 : 0; i < nblocks; i++) if (!(sram->allocated & BIT(i))) break; if (i < nblocks) { - *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, i * SRAM_BLOCK) | - FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, SRAM_BLOCK); + *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, first + i * block) | + FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, block); sram->allocated |= BIT(i); } else { ret = -EBUSY; @@ -240,18 +274,24 @@ static void admac_free_sram_carveout(struct admac_data *ad, { struct admac_sram *sram; u32 base = FIELD_GET(CHAN_SRAM_CARVEOUT_BASE, carveout); + u32 first = 0, block = SRAM_BLOCK; int i; + if (ad->t8152_layout) { + first = T8152_SRAM_BASE; + block = T8152_SRAM_BLOCK; + } + if (dir == DMA_MEM_TO_DEV) sram = &ad->txcache; else sram = &ad->rxcache; - if (WARN_ON(base >= sram->size)) + if (WARN_ON(base < first || base >= sram->size)) return; mutex_lock(&ad->cache_alloc_lock); - i = base / SRAM_BLOCK; + i = (base - first) / block; sram->allocated &= ~BIT(i); mutex_unlock(&ad->cache_alloc_lock); } @@ -354,7 +394,19 @@ static void admac_write_hw_desc(struct admac_data *ad, int channo, writel_relaxed(lower_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); writel_relaxed(upper_32_bits(addr), ad->base + REG_DESC_WRITE(channo)); writel_relaxed(len, ad->base + REG_DESC_WRITE(channo)); - writel_relaxed(FLAG_DESC_NOTIFY, ad->base + REG_DESC_WRITE(channo)); + if (ad->t8152_layout) { + /* + * T8152: the low byte of the last word is a descriptor id, + * which macOS counts 1..255 and never leaves at 0. + */ + struct admac_chan *adchan = &ad->channels[channo]; + + adchan->desc_id = adchan->desc_id == 255 ? 1 : adchan->desc_id + 1; + writel_relaxed(FLAG_DESC_NOTIFY | adchan->desc_id, + ad->base + REG_DESC_WRITE(channo)); + } else { + writel_relaxed(FLAG_DESC_NOTIFY, ad->base + REG_DESC_WRITE(channo)); + } } /* @@ -570,6 +622,11 @@ static void admac_start_chan(struct admac_chan *adchan) ad->base + REG_CHAN_INTSTATUS(ad, adchan->no, ad->irq_index)); writel_relaxed(STATUS_DESC_DONE | STATUS_ERR, ad->base + REG_CHAN_INTMASK(ad, adchan->no, ad->irq_index)); + if (ad->t8152_layout) { + writel_relaxed(CHAN_CONFIG_T8152, ad->base + REG_CHAN_CONFIG(ad, adchan->no)); + admac_modify(ad, REG_CHAN_STATE(ad, adchan->no), CHAN_STATE_MASK, + CHAN_STATE_READY); + } switch (admac_chan_direction(adchan->no)) { case DMA_MEM_TO_DEV: @@ -1091,7 +1148,8 @@ static int admac_device_config(struct dma_chan *chan, * of words position in a frame. That's where the importance of this control * comes from. */ - switch (is_tx ? config->dst_port_window_size : config->src_port_window_size) { + switch (ad->t8152_layout ? 0 : + is_tx ? config->dst_port_window_size : config->src_port_window_size) { case 0 ... 1: break; case 2: @@ -1202,6 +1260,7 @@ static int admac_probe(struct platform_device *pdev) ad->set_unk28 = hw->set_unk28; ad->evolved_layout = hw->evolved_layout; ad->split_channels = hw->split_channels; + ad->t8152_layout = hw->t8152_layout; mutex_init(&ad->cache_alloc_lock); /* @@ -1353,7 +1412,12 @@ static const struct admac_hw admac_t8140_hw = { .evolved_layout = true, }; +static const struct admac_hw admac_t8152_hw = { + .t8152_layout = true, +}; + static const struct of_device_id admac_of_match[] = { + { .compatible = "apple,t8152-admac", .data = &admac_t8152_hw }, { .compatible = "apple,t8140-admac", .data = &admac_t8140_hw }, { .compatible = "apple,t8132-admac", .data = &admac_t8132_hw }, { .compatible = "apple,t8122-admac", .data = &admac_t8122_hw }, From dd923f2443834d36260286aeb9c27355db9aae05 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 20:17:32 +0100 Subject: [PATCH 047/112] arm64: dts: apple: j873: audio Describe the J873 (Mac mini M6) audio: the AOP (mailbox 0x310740080, firmware started by Linux), dart-sbr (shared with the PMP; apple,retain-translation for the firmware's tables), the base-ns ADMAC, the AOP audio node with its DMA channels and MCA power leaves, the I2C1/I2C3 power states and buses with the CS42L84 jack codec and the SN012776 speaker amp (ti,bclk-ratio = <250>), and the macaudio card. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip: the nodes go into t8152-j873-audio.dtsi, which t8152-j873g.dts includes. There is no PMP device tree here, so dart-sbr is described directly (as an apple,t8152-dart with apple,t8110-dart fallback, like the other J873 DARTs), and the I2C power states join the PMGR node that t8152-j873-qspi.dtsi already describes. The speaker stays off by default: the J873 macaudio configuration does not admit it.] Signed-off-by: Acelogic --- .../boot/dts/apple/t8152-j873-audio.dtsi | 261 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 262 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi new file mode 100644 index 0000000000000..0ecfd9746beb9 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g audio: the AOP (always-on processor) owns the audio fabric, as + * on T8140. iBoot loads the AOP firmware (j873gaop) and leaves the CPU + * stopped; Linux starts it. The jack codec (CS42L84) and the speaker amp + * (SN012776) are on AP I2C buses; their data goes through AOP services on + * the base-ns ADMAC. Resources are from the 26A434 ADT: aop, dart-sbr, + * admac-base-ns, iop-audio-controller, i2c1, i2c3, pmgr. + */ +#include + +/ { + soc { + /* + * ADT aop: iop,ascwrap-v8, msgbox-mailbox-num 0, using-alias, + * not post-office: mailbox 0, aperture 1 of the bank at reg[2] + * (0x310740000) = 0x310740080. ADT interrupts [627, 626, 628]; + * the first two in the SMC order (send-empty, recv-not-empty). + */ + aop_mbox: mailbox@310740080 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x10740080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* + * ADT dart-sbr, shared with the PMP: mapper-aop 0, + * mapper-admac-base-ns 42. iBoot leaves streams 0, 1 and 42 + * translating (root slot 16 owned by the firmware) without + * setting the lock bit. + */ + sbr_dart: iommu@318100000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x18100000 0x0 0xc000>; + #iommu-cells = <1>; + interrupts = ; + apple,retain-translation; + }; + + /* + * ADT admac-base-ns (admac-evolution,t8152): 13 TX and 13 RX + * channels, interrupt destination 0, dart-sbr stream 42. + */ + admac_base_ns: dma-controller@313900000 { + compatible = "apple,t8152-admac"; + reg = <0x3 0x13900000 0x0 0xb4000>; + dma-channels = <26>; + interrupts-extended = <&aic AIC_IRQ 640 IRQ_TYPE_LEVEL_HIGH>, + <0>, <0>, <0>; + #dma-cells = <1>; + iommus = <&sbr_dart 42>; + /* slot 17: slot 16 of stream 42 belongs to the firmware */ + apple,dma-range = <0x110 0x0 0x0 0x10000000>; + }; + + /* + * The AOP's PMGR (ADT pmgr devices AUDIO_MCA0_M..AUDIO_MCA5_M at + * 0x308284400 + 0x20 * N). Their parent audio_p is the + * firmware's: it is up while a service is in pw0 or pwrd. + */ + pmgr_aop: power-management@308284000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", + "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x08284000 0x0 0x1000>; + + ps_audio_mca0_m: power-controller@400 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x400 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca0_m"; + }; + + ps_audio_mca1_m: power-controller@420 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x420 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca1_m"; + }; + + ps_audio_mca2_m: power-controller@440 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x440 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca2_m"; + }; + + ps_audio_mca3_m: power-controller@460 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x460 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca3_m"; + }; + + ps_audio_mca4_m: power-controller@480 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x480 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca4_m"; + }; + + ps_audio_mca5_m: power-controller@4a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x4a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca5_m"; + }; + }; + + /* ADT i2c1: the CS42L84 jack codec (and the aqc NIC's EEPROM). */ + i2c1: i2c@331014000 { + compatible = "apple,t8152-i2c", "apple,t8103-i2c"; + reg = <0x3 0x31014000 0x0 0x4000>; + clocks = <&clkref>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + power-domains = <&ps_i2c1>; + + /* + * ADT audio-codec-output: function-reset GPIO 0xcc, + * interrupt on gpio0 pin 203. + */ + jack_codec: codec@4b { + compatible = "cirrus,cs42l84"; + reg = <0x4b>; + reset-gpios = <&pinctrl_ap 204 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 203 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Jack"; + }; + }; + + /* ADT i2c3: the SN012776 speaker amplifier. */ + i2c3: i2c@33101c000 { + compatible = "apple,t8152-i2c", "apple,t8103-i2c"; + reg = <0x3 0x3101c000 0x0 0x4000>; + clocks = <&clkref>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + power-domains = <&ps_i2c3>; + + /* + * ADT audio-speaker: function-reset GPIO 0xca, interrupt + * on gpio0 pin 193, speaker-config rx_slot 0, + * vsense_slot 0, isense_slot 2. + */ + speaker_amp: codec@38 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x38>; + shutdown-gpios = <&pinctrl_ap 202 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 193 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + ti,imon-slot-no = <2>; + ti,vmon-slot-no = <0>; + /* the AOP's speaker frame: 250 BCLKs at 12 MHz */ + ti,bclk-ratio = <250>; + }; + }; + + aop: aop@310c00000 { + compatible = "apple,t8152-aop"; + reg = <0x3 0x10c00000 0x0 0x1e0000>, + <0x3 0x10600000 0x0 0x4000>; + reg-names = "mmio", "asc"; + mboxes = <&aop_mbox>; + mbox-names = "mbox"; + iommus = <&sbr_dart 0>; + /* slot 17: slot 16 belongs to the firmware */ + apple,dma-range = <0x110 0x0 0x10 0x0>; + + /* + * Bound by name to the firmware's "audio" EPIC service. + * ADT iop-audio-controller: cout/cin on base-ns TX5/RX5, + * spkr on TX1 with its sense data on RX1; Linux ADMAC + * channel = 2 * N for TX N, 2 * N + 1 for RX N. + */ + aop_audio: audio { + compatible = "apple,t8152-aop-audio"; + dmas = <&admac_base_ns 10>, <&admac_base_ns 11>, + <&admac_base_ns 2>, <&admac_base_ns 3>; + dma-names = "cout", "cin", "spkr", "sense"; + power-domains = <&ps_audio_mca0_m>, <&ps_audio_mca1_m>, + <&ps_audio_mca2_m>, <&ps_audio_mca3_m>, + <&ps_audio_mca4_m>, <&ps_audio_mca5_m>; + power-domain-names = "mca0", "mca1", "mca2", + "mca3", "mca4", "mca5"; + #sound-dai-cells = <1>; + }; + }; + }; + + sound { + compatible = "apple,j873-macaudio", "apple,macaudio"; + model = "Mac mini J873"; + #address-cells = <1>; + #size-cells = <0>; + + dai-link@0 { + reg = <0>; + link-name = "Headphone Jack"; + + cpu { + sound-dai = <&aop_audio 0>; + }; + codec { + sound-dai = <&jack_codec>; + }; + }; + + dai-link@1 { + reg = <1>; + link-name = "Speaker"; + + cpu { + sound-dai = <&aop_audio 3>; + }; + codec { + sound-dai = <&speaker_amp>; + }; + }; + }; +}; + +/* The I2C power states (PMGR, parent SIO_CPU is always on). */ +&pmgr { + ps_i2c1: power-controller@cc0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xcc0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c1"; + }; + + ps_i2c3: power-controller@d00 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xd00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c3"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 180b435f1d969..2da1a88dc8cf1 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -364,3 +364,4 @@ #include "t8152-j873-nvme.dtsi" #include "t8152-j873-usb.dtsi" #include "t8152-j873-ethernet.dtsi" +#include "t8152-j873-audio.dtsi" From bc141c0a6c9bf48786169920cd2f6ddb74e647e5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 10:31:26 +0100 Subject: [PATCH 048/112] arm64: dts: apple: j873: describe the fan target and mode keys The J873 SMC has F0Tg (target, flt) and F0md (mode, ui8; lowercase, unlike the F0Md of other machines). With them macsmc_hwmon exposes fan1_target; with fan_control=1 the fan follows it (2500 -> 2499 RPM within 3 s). In automatic mode the SMC keeps the fan at its 1000 RPM minimum even at 93 C under full load, so the OS has to drive it. Signed-off-by: Thomas Glanzmann [Acelogic: adapted for aurora-wip, whose T8152 hwmon leaves fan control to the firmware: the fan node has no apple,fan-manual-control, so the keys only add a read-only fan1_target. The target becomes writable only with the fan_control module parameter (unsafe, off by default); nothing in the kernel writes F0md or F0Tg by itself.] Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873g.dts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 2da1a88dc8cf1..db37673de92bb 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -340,6 +340,8 @@ apple,key-id = "F0Ac"; apple,fan-minimum = "F0Mn"; apple,fan-maximum = "F0Mx"; + apple,fan-target = "F0Tg"; + apple,fan-mode = "F0md"; label = "Fan"; }; }; From 6962da594d81907a7a1445db331fa95c322ec5ef Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sun, 8 Nov 2026 02:04:43 -0500 Subject: [PATCH 049/112] arm64: dts: apple: j873: leave the USB 2 hosts to a follow-up The J873g USB 2 host nodes describe the back-left (usb-drd1) and front (usb-drd2) controllers as plain "snps,dwc3" with both DART instances in iommus. The generic dwc3 binding allows a single iommu, so these nodes add two dtbs_check warnings. The Apple dwc3 binding, which does allow two DARTs, needs resets, a USB role switch and PHY descriptions that the J873g does not have yet. Return the J873g USB description to the shared, disabled state that aurora-wip has, until the M6 USB controllers can be described properly: - drop t8152-j873-usb.dtsi and its include; - restore aurora-wip's dwc3_1_dart and dwc3_2_dart overrides. The USB 2 hosts worked on the M6 with the earlier description (both xHCI hosts and the front-port hub enumerated), and they will come back in a follow-up together with the binding work. Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 67 ------------------- arch/arm64/boot/dts/apple/t8152-j873g.dts | 17 ++++- 2 files changed, 15 insertions(+), 69 deletions(-) delete mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi deleted file mode 100644 index 5ecd42f9e7135..0000000000000 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ /dev/null @@ -1,67 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0+ OR MIT -/* - * J873g USB2 host bring-up: usb-drd1 (back-left port) and usb-drd2 - * (front ports via the on-board hub). - * The loader powers the controllers and initialises the eUSB2 PHYs in host - * mode before Linux starts (no PMGR, PHY or Type-C driver yet), so the - * controllers are described as plain DWC3 hosts behind their two DARTs. - * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2. - * - * dart-usb1 and dart-usb2 each have two DART instances (ADT reg[0] and - * reg[1], 0xc000 each, sharing one interrupt). t8152-peripherals.dtsi lists - * both windows on one node (dwc3_1_dart, dwc3_2_dart), but the DART driver - * drives one instance per node and the binding reads a second reg entry as - * DAPF or auxiliary registers. Keep instance 0 on the shared node, with its - * own window only, and describe instance 1 as a node of its own. - */ - -&dwc3_1_dart { - reg = <0x4 0x0b020000 0x0 0xc000>; - status = "okay"; -}; - -&dwc3_2_dart { - reg = <0x3 0x83020000 0x0 0xc000>; - status = "okay"; -}; - -/ { - soc { - dwc3_1_dart_1: iommu@40b040000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x4 0x0b040000 0x0 0xc000>; - interrupts = ; - #iommu-cells = <1>; - }; - - usb1: usb@40a430000 { - compatible = "snps,dwc3"; - reg = <0x4 0x0a430000 0x0 0xcd00>; - interrupts = ; - dr_mode = "host"; - maximum-speed = "high-speed"; - iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; - snps,dis_u2_susphy_quirk; - snps,dis_u3_susphy_quirk; - }; - - dwc3_2_dart_1: iommu@383040000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x3 0x83040000 0x0 0xc000>; - interrupts = ; - #iommu-cells = <1>; - }; - - /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ - usb2: usb@382430000 { - compatible = "snps,dwc3"; - reg = <0x3 0x82430000 0x0 0xcd00>; - interrupts = ; - dr_mode = "host"; - maximum-speed = "high-speed"; - iommus = <&dwc3_2_dart 0>, <&dwc3_2_dart_1 1>; - snps,dis_u2_susphy_quirk; - snps,dis_u3_susphy_quirk; - }; - }; -}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 0f98b07748b01..d4900374f1470 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -372,6 +372,12 @@ <0x4 0x3040000 0x0 0xc000>; }; +/* Retain the register view published by this board's live hardware capture. */ +&dwc3_1_dart { + reg = <0x4 0xb020000 0x0 0xc000>, + <0x4 0xb040000 0x0 0xc000>; +}; + /* Retain the register view published by this board's live hardware capture. */ &dwc3_3_dart { reg = <0x4 0x13020000 0x0 0xc000>, @@ -494,11 +500,18 @@ <0x3 0xa0000000 0x0 0x8000>; }; +/* Unexposed chassis port instances remain described and disabled. */ + +/* Retain the register view published by this board's live hardware capture. */ +&dwc3_2_dart { + reg = <0x3 0x83020000 0x0 0xc000>, + <0x3 0x83040000 0x0 0xc000>; +}; + /* * The J873g fragments enable and refine nodes of t8152-peripherals.dtsi - * (the USB, apcie port 2 and dart-sbr DARTs), so they come after it. + * (the apcie port 2 and dart-sbr DARTs), so they come after it. */ #include "t8152-j873-nvme.dtsi" -#include "t8152-j873-usb.dtsi" #include "t8152-j873-ethernet.dtsi" #include "t8152-j873-audio.dtsi" From e5ac50732aac6366a90bc9c8e9307cb10e37f20b Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sun, 8 Nov 2026 02:33:35 -0500 Subject: [PATCH 050/112] arm64: dts: apple: j873: bring back the USB 2 hosts Restore the J873g USB 2 host description that linux#1197 set aside: the back-left controller (usb-drd1) and the front ports (usb-drd2, behind the on-board hub), each behind its two DART instances. aura prepares these ports before Linux starts (j873_usb_prep()). This is the description that worked on the M6, where both xHCI hosts and the front-port hub enumerated. It still describes the controllers as plain "snps,dwc3" with two iommus, which the generic dwc3 binding rejects. Before it can merge, the nodes need to move to the Apple dwc3 binding, or the binding needs an M6 USB 2 host variant. Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 67 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 17 +---- 2 files changed, 69 insertions(+), 15 deletions(-) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi new file mode 100644 index 0000000000000..5ecd42f9e7135 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -0,0 +1,67 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g USB2 host bring-up: usb-drd1 (back-left port) and usb-drd2 + * (front ports via the on-board hub). + * The loader powers the controllers and initialises the eUSB2 PHYs in host + * mode before Linux starts (no PMGR, PHY or Type-C driver yet), so the + * controllers are described as plain DWC3 hosts behind their two DARTs. + * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2. + * + * dart-usb1 and dart-usb2 each have two DART instances (ADT reg[0] and + * reg[1], 0xc000 each, sharing one interrupt). t8152-peripherals.dtsi lists + * both windows on one node (dwc3_1_dart, dwc3_2_dart), but the DART driver + * drives one instance per node and the binding reads a second reg entry as + * DAPF or auxiliary registers. Keep instance 0 on the shared node, with its + * own window only, and describe instance 1 as a node of its own. + */ + +&dwc3_1_dart { + reg = <0x4 0x0b020000 0x0 0xc000>; + status = "okay"; +}; + +&dwc3_2_dart { + reg = <0x3 0x83020000 0x0 0xc000>; + status = "okay"; +}; + +/ { + soc { + dwc3_1_dart_1: iommu@40b040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + usb1: usb@40a430000 { + compatible = "snps,dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + + dwc3_2_dart_1: iommu@383040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x83040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + }; + + /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ + usb2: usb@382430000 { + compatible = "snps,dwc3"; + reg = <0x3 0x82430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&dwc3_2_dart 0>, <&dwc3_2_dart_1 1>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index d4900374f1470..0f98b07748b01 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -372,12 +372,6 @@ <0x4 0x3040000 0x0 0xc000>; }; -/* Retain the register view published by this board's live hardware capture. */ -&dwc3_1_dart { - reg = <0x4 0xb020000 0x0 0xc000>, - <0x4 0xb040000 0x0 0xc000>; -}; - /* Retain the register view published by this board's live hardware capture. */ &dwc3_3_dart { reg = <0x4 0x13020000 0x0 0xc000>, @@ -500,18 +494,11 @@ <0x3 0xa0000000 0x0 0x8000>; }; -/* Unexposed chassis port instances remain described and disabled. */ - -/* Retain the register view published by this board's live hardware capture. */ -&dwc3_2_dart { - reg = <0x3 0x83020000 0x0 0xc000>, - <0x3 0x83040000 0x0 0xc000>; -}; - /* * The J873g fragments enable and refine nodes of t8152-peripherals.dtsi - * (the apcie port 2 and dart-sbr DARTs), so they come after it. + * (the USB, apcie port 2 and dart-sbr DARTs), so they come after it. */ #include "t8152-j873-nvme.dtsi" +#include "t8152-j873-usb.dtsi" #include "t8152-j873-ethernet.dtsi" #include "t8152-j873-audio.dtsi" From 26670aa724b0ebf60114629d9c67e52e6180d588 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sun, 8 Nov 2026 03:58:53 -0500 Subject: [PATCH 051/112] dt-bindings: usb: apple,dwc3: Add T8152 The T8152 (M6) USB-C controllers are Apple DWC3 DRD controllers like those on earlier SoCs, each with its own ATC PHY. There is no T8152 USB power-domain, ATC PHY or Type-C support yet. Instead, the bootloader can hand a controller over already running: powered, with the USB2 side of its ATC PHY set up for host mode. Add a standalone "apple,t8152-dwc3" compatible for such a controller, following the T8132 exception already in this binding. It is described by its DWC3 core region, as a host, so dr_mode = "host" is required. The PHY reset and power domain, and on a Type-C port the USB role switch, exist on T8152 but are left to the bootloader, so they are optional there. Every other compatible still requires reg-names, resets, usb-role-switch and two reg entries. There is no apple,t8103-dwc3 fallback: the T8152 layout of the Apple region is not established, and without its ATC PHY the controller cannot switch roles, so the Apple dwc3 glue must not bind it. When T8152 ATC PHY and Type-C support lands, full Type-C operation can key on resets and usb-role-switch being present, so these minimal descriptions stay valid and the dr_mode rule can be relaxed. Signed-off-by: Acelogic --- .../devicetree/bindings/usb/apple,dwc3.yaml | 54 ++++++++++++++++--- 1 file changed, 48 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml index d68a4b68d77ca..df755601429cd 100644 --- a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml @@ -13,6 +13,12 @@ description: Apple Silicon SoCs use a Synopsys DesignWare DWC3 based controller for each of their Type-C ports. + On T8152 the bootloader can hand a controller over already running, powered + and with the USB2 side of its ATC PHY set up for host mode. Such a controller + is described by its DWC3 core region, as a host. Its PHY reset and power + domain, and on a Type-C port its USB role switch, exist but are left to the + bootloader, so they are optional. + allOf: - $ref: snps,dwc3-common.yaml# - if: @@ -20,10 +26,33 @@ allOf: compatible: not: contains: - const: apple,t8132-dwc3 + enum: + - apple,t8132-dwc3 + - apple,t8152-dwc3 then: required: - power-domains + - if: + properties: + compatible: + contains: + const: apple,t8152-dwc3 + then: + properties: + dr_mode: + const: host + required: + - dr_mode + else: + properties: + reg: + minItems: 2 + reg-names: + minItems: 2 + required: + - reg-names + - resets + - usb-role-switch $defs: apple,tunable: @@ -56,16 +85,17 @@ properties: - const: apple,t8103-dwc3 - const: apple,t8103-dwc3 - const: apple,t8132-dwc3 + - const: apple,t8152-dwc3 reg: - minItems: 2 + minItems: 1 items: - description: Core DWC3 region - description: Apple-specific DWC3 region - description: Controller configuration block (T6040) reg-names: - minItems: 2 + minItems: 1 items: - const: dwc3-core - const: dwc3-apple @@ -106,11 +136,8 @@ properties: required: - compatible - reg - - reg-names - interrupts - iommus - - resets - - usb-role-switch unevaluatedProperties: false @@ -131,3 +158,18 @@ examples: usb-role-switch; }; + + - | + #include + #include + + usb@82430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x82430000 0xcd00>; + interrupts = ; + iommus = <&dwc3_2_dart_0 0>, <&dwc3_2_dart_1 1>; + dr_mode = "host"; + maximum-speed = "high-speed"; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; From 846d101cb4c7be32b91ece8890a7965ce3bfd030 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sun, 8 Nov 2026 03:58:53 -0500 Subject: [PATCH 052/112] usb: dwc3: core: Bind the Apple T8152 controller On T8152 (M6) the Apple dwc3 glue cannot drive the controller yet: it needs the ATC PHY as reset provider and a Type-C role switch, and T8152 has no driver for either. The bootloader powers the controller, sets up the USB2 side of its ATC PHY for host mode and selects the host role before the kernel starts, which leaves only the DWC3 core to the kernel. Match "apple,t8152-dwc3" in the dwc3 core driver. dwc3_probe() uses no match data, so the controller probes exactly as a "snps,dwc3" node does, and dr_mode, maximum-speed and the quirks are read from the node as before. dwc3-apple does not match this compatible, so only the core binds it. This entry is to move to dwc3-apple once that driver supports the T8152 ATC PHY and Type-C role switch, so that the two never match the same compatible. Signed-off-by: Acelogic --- drivers/usb/dwc3/core.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 7f68eba95e1f1..3566533dda5a2 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2962,6 +2962,10 @@ static const struct of_device_id of_dwc3_match[] = { { .compatible = "synopsys,dwc3" }, + { + /* Handed over in host mode by the bootloader, see apple,dwc3.yaml */ + .compatible = "apple,t8152-dwc3" + }, { }, }; MODULE_DEVICE_TABLE(of, of_dwc3_match); From 35833f6358e400ef01d27c4ef38fb7ecf9b8d88d Mon Sep 17 00:00:00 2001 From: Acelogic Date: Sun, 8 Nov 2026 03:58:53 -0500 Subject: [PATCH 053/112] arm64: dts: apple: j873: Describe the USB 2 hosts as T8152 DWC3 The back-left (usb-drd1) and front (usb-drd2) USB 2 host nodes are "snps,dwc3" with two iommus, one per DART instance. The generic dwc3 binding allows a single iommu, so dtbs_check rejects both nodes. Use the T8152 Apple dwc3 compatible instead. It allows both DART instances and documents the bootloader handover these nodes rely on. Nothing else changes: the nodes keep their core region, interrupt, DARTs, host mode, speed limit and SUSPHY quirks, and the same dwc3 core driver binds them. Signed-off-by: Acelogic --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index 5ecd42f9e7135..6f1a956bd68e3 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -2,9 +2,12 @@ /* * J873g USB2 host bring-up: usb-drd1 (back-left port) and usb-drd2 * (front ports via the on-board hub). - * The loader powers the controllers and initialises the eUSB2 PHYs in host - * mode before Linux starts (no PMGR, PHY or Type-C driver yet), so the - * controllers are described as plain DWC3 hosts behind their two DARTs. + * The loader powers the controllers and sets up the USB2 side of their ATC + * PHYs for host mode before Linux starts (there is no T8152 USB power-domain, + * ATC PHY or Type-C support yet). + * The controllers are described by their DWC3 core region, as hosts behind + * their two DARTs (apple,t8152-dwc3); their PHY reset and power domain, and on + * the Type-C port the role switch, exist but are left to the loader. * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2. * * dart-usb1 and dart-usb2 each have two DART instances (ADT reg[0] and @@ -35,7 +38,7 @@ }; usb1: usb@40a430000 { - compatible = "snps,dwc3"; + compatible = "apple,t8152-dwc3"; reg = <0x4 0x0a430000 0x0 0xcd00>; interrupts = ; dr_mode = "host"; @@ -54,7 +57,7 @@ /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ usb2: usb@382430000 { - compatible = "snps,dwc3"; + compatible = "apple,t8152-dwc3"; reg = <0x3 0x82430000 0x0 0xcd00>; interrupts = ; dr_mode = "host"; From f8c95e25fc069253e1e3baf42d6cd22ff8b6dfab Mon Sep 17 00:00:00 2001 From: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Date: Sun, 8 Nov 2026 21:40:58 +1100 Subject: [PATCH 054/112] dt-bindings: nvme: apple,nvme-ans: exempt T6050 and T8152 from one rule The integration merge brought in two rules for the required resets and power domains. aurora-wip had "required unless T8152", and integration had "forbidden on T6050, else required". Together they required the properties on T6050 nodes that must not have them, and on T8152 nodes where they are optional. dt-checks flagged that on every T6050 board and on J873g. Keep one rule: required unless T6050 or T8152. T6050 still forbids them. Signed-off-by: Ryan Murray <81541646+RyanTheTide@users.noreply.github.com> Assisted-by: LLM --- .../devicetree/bindings/nvme/apple,nvme-ans.yaml | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index 326d8d538947b..b7fcf03af696f 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -117,7 +117,9 @@ allOf: compatible: not: contains: - const: apple,t8152-nvme-ans2 + enum: + - apple,t6050-nvme-ans2 + - apple,t8152-nvme-ans2 then: required: - resets @@ -195,11 +197,6 @@ allOf: resets: false power-domains: false power-domain-names: false - else: - required: - - resets - - power-domains - - power-domain-names required: - compatible From 210c8f6e6ffd28d41fdf688ab5e3f7ecb674272f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Mon, 9 Nov 2026 21:42:07 -0600 Subject: [PATCH 055/112] ASoC: apple: t8152-aop-audio: Match the T6050 AOP audio node (#1410) The binding and the J714c device tree name the AOP audio service "apple,t6050-aop-audio", but the driver matched only t8142 and t8152, so that node never bound. Add a T6050 hardware config. The J714c ADT audio-speaker stream header (DeviceTree.j714cap) has the same layout as J813's with six amplifiers in place of four: 6 speaker slots and 12 sense words (V, I per amplifier), at 16 bits, on slots vsense 0,4,..20 / isense 2,6,..22. J813's header has 4 slots, 8 sense words and vsense 0..12 / isense 2..14. HW_CFG_T8152 (one amplifier, two sense words) would expose the wrong channel counts, so it is not reused. The sense width and the sense realignment are taken from J813's config by analogy; they are not tested on a J714c. Tested: builds as a module with Rust enabled (clang 19, arm64 defconfig plus CONFIG_RUST, CONFIG_SND_SOC_APPLE_T8152_AOP_AUDIO=m); the object carries the apple,t6050-aop-audio match string. Not tested: no J714c boot, no sound. --- sound/soc/apple/t8152_aop_audio.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sound/soc/apple/t8152_aop_audio.rs b/sound/soc/apple/t8152_aop_audio.rs index 81a224f697491..f0080ccb50669 100644 --- a/sound/soc/apple/t8152_aop_audio.rs +++ b/sound/soc/apple/t8152_aop_audio.rs @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only OR MIT -//! Apple T8152 (J873, Mac mini M6) and T8142 (J813, MacBook Air M5) AOP audio +//! Apple T8152 (J873, Mac mini M6), T8142 (J813, MacBook Air M5) and T6050 +//! (J714c, MacBook Pro 14-inch M5 Max) AOP audio //! //! The AOP firmware owns the audio fabric, as on T8140. The ADT //! (/arm-io/iop-audio-controller) names its services; all of them run on the @@ -582,6 +583,17 @@ static HW_CFG_T8142: HwConfig = HwConfig { realign_sense: true, }; +/// J714c: six amplifiers (left and right woofer 1, woofer 2 and tweeter) in +/// 32-bit slots 0-5, their voltage and current sense back as twelve 16-bit +/// slots (V, I per amplifier) on the stream's RX, as on J813. The ADT +/// audio-speaker stream header gives 6 amplifier slots and 12 sense words. +static HW_CFG_T6050: HwConfig = HwConfig { + spkr_channels: 6, + sense_channels: 12, + sense_formats: FMTBIT_S16_LE, + realign_sense: true, +}; + /// # Safety /// /// `substream` must be live and belong to one of this component's links. @@ -1389,6 +1401,7 @@ kernel::of_device_table!( [ (of::DeviceId::new(c_str!("apple,t8142-aop-audio")), &HW_CFG_T8142), (of::DeviceId::new(c_str!("apple,t8152-aop-audio")), &HW_CFG_T8152), + (of::DeviceId::new(c_str!("apple,t6050-aop-audio")), &HW_CFG_T6050), ] ); From 17cb9963559ce47b667bfb39edd71fae8b80eaed Mon Sep 17 00:00:00 2001 From: LiamRay11 <228416644+LiamRay11@users.noreply.github.com> Date: Mon, 16 Nov 2026 08:35:22 -0800 Subject: [PATCH 056/112] dt-bindings: mailbox: apple,mailbox: add the other T8152 post-office mailboxes On T8152 the NVMe (ANS), display (DCP), keyboard and trackpad (MTP) and SEP coprocessors talk through windows of the same post-office block as the SMC: counted FIFOs sharing one status register, with interrupt masking left to the interrupt controller. The register layout is the one apple,t8152-smc-mailbox already describes. Add a compatible per coprocessor, each with apple,t8152-smc-mailbox as its fallback, so the existing driver match serves them without a code change and a later difference can still be keyed on the specific compatible. All four carry traffic on a MacBook Pro (M6, J804), with the single-compatible form of these nodes: NVMe, the keyboard and trackpad, and Touch ID run through them, and the DCP driver exchanges its messages through the DCP window. Signed-off-by: LiamRay11 <228416644+LiamRay11@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 [Thomas: taken from aurora-silicon/linux#2105 for the J873g ANS node; placed before the T8152 ASCWrap v8 entry this branch adds] Signed-off-by: Thomas Glanzmann --- .../bindings/mailbox/apple,mailbox.yaml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 9dc9c7d7f0b88..a00459b368cfa 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -27,6 +27,17 @@ properties: masking provided by the interrupt controller. const: apple,t8152-smc-mailbox + - description: + The other T8152 post-office mailboxes. Each coprocessor has its own + window of the same counted-FIFO block as the SMC's. + items: + - enum: + - apple,t8152-ans-mailbox + - apple,t8152-dcp-mailbox + - apple,t8152-mtp-mailbox + - apple,t8152-sep-mailbox + - const: apple,t8152-smc-mailbox + - description: T8152 ASC wrapper (v8) mailbox of the AOP, with the counted FIFOs of the SMC mailbox, described with its send-empty and @@ -270,6 +281,20 @@ required: additionalProperties: false examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + mailbox@316020300 { + compatible = "apple,t8152-ans-mailbox", "apple,t8152-smc-mailbox"; + reg = <0x3 0x16020300 0x0 0x80>; + interrupts = <1 302 4>, <1 262 4>; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + }; + - | mailbox@77408000 { compatible = "apple,t8103-asc-mailbox", "apple,asc-mailbox-v4"; From 15d51203cf03692fa920d79c98ea5bbfa29128ee Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:21:18 +0100 Subject: [PATCH 057/112] arm64: dts: apple: j873: describe the ANS mailbox like the J804's Describe the J873g ANS post-office mailbox as the J804 does: with apple,t8152-smc-mailbox as the fallback compatible and the window's send-empty and recv-not-empty interrupts. The ADT's ans node lists interrupts 302, 262, 222 and 1349 (the last is NVMe's, nvme-interrupt-idx 3). Every post-office mailbox's list starts with 299 + its msgbox-mailbox-num and 259 + that number, and for the SMC (760, 759) and the DCP (304, 264) mailboxes, which run on their interrupts on the J873g, the first is send-empty and the second recv-not-empty. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi index c53059ab55d34..741162fe483ff 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi @@ -5,15 +5,21 @@ * the driver wakes it with a fresh RTKit handshake (as m1n1 does). NVMe * registers and NVMMU share the 0x325cc0000 window. The mailbox is the ANS * post-office window (msgbox-mailbox-num 3, no alias: 0x316000000 + - * 0x10300). No PMGR power or reset yet. + * 0x10300), the SMC mailbox's counted FIFO. Its interrupts are the first two + * of the ADT's ans list, in the order the SMC and DCP mailboxes' ADT lists + * give theirs: send-empty, recv-not-empty. No PMGR power or reset yet. * Resources are from the 26A434 ADT: ans, sart-ans. */ / { soc { ans_mbox: mailbox@316010300 { - compatible = "apple,t8152-ans-mailbox"; + compatible = "apple,t8152-ans-mailbox", + "apple,t8152-smc-mailbox"; reg = <0x3 0x16010300 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; #mbox-cells = <0>; }; From a9b13e8bb40fb9d7845550db817160a17a16ab50 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:21:42 +0100 Subject: [PATCH 058/112] soc: apple: mailbox: drop the polled T8152 ANS profile The J873g ANS node now carries apple,t8152-smc-mailbox as its fallback and describes its interrupts, so the SMC mailbox's match data serves it on its interrupts, as it serves the J804's. Remove the profile that polled both directions without interrupts: its match entry, the rx_poll_required and j873_window fields, and the machine and fixed address check in probe. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/mailbox.c | 55 ++----------------------------------- 1 file changed, 2 insertions(+), 53 deletions(-) diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index c0d245339de88..5b5b69500db34 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -227,10 +227,6 @@ struct apple_mbox_hw { unsigned int num_ascwrap_v6_roles; /* T8152 GPU ASCWrap v8: wrapper + iop-vbar + post-office window + PSD. */ bool is_ascwrap_v8; - /* No interrupts are described; receive and send are polled. */ - bool rx_poll_required; - /* J873 post-office window a polled provider must sit at. */ - u64 j873_window; /* Status word counts RX occupancy and free TX slots; paired transfers. */ bool counted_fifo; bool ap_initializes_mailboxes; @@ -264,7 +260,7 @@ struct apple_mbox_priv { struct apple_mbox mbox; /* ASCWrap v8 only: the provider's PMGR2 PSD service block (read-only). */ void __iomem *psd_regs; - /* ASCWrap v8 and polled providers: receive by polling; fixed at probe. */ + /* ASCWrap v8 only: receive by polling; fixed at probe. */ bool rx_poll_only; /* rx_lock: recv interrupt enabled and not yet disabled again. */ bool rx_irq_live; @@ -283,7 +279,7 @@ static struct apple_mbox_priv *apple_mbox_to_priv(struct apple_mbox *mbox) /* Only providers allocated by apple_mbox_probe() have a receive poller. */ static bool apple_mbox_has_rx_poller(const struct apple_mbox *mbox) { - return mbox->hw->is_ascwrap_v8 || mbox->hw->rx_poll_required; + return mbox->hw->is_ascwrap_v8; } /* Both ASCWrap generations share the consumer lifecycle API below. */ @@ -1592,16 +1588,6 @@ static int apple_mbox_probe(struct platform_device *pdev) return ret; } else { res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - /* - * A polled provider must be exactly its own 0x80-byte window of - * the J873 post-office bank; the rest belongs to other roles. - */ - if (mbox->hw->rx_poll_required && - (!of_machine_is_compatible("apple,j873g") || !res || - res->start != mbox->hw->j873_window || - resource_size(res) != APPLE_ASCWRAP_V8_MBOX_SIZE)) - return dev_err_probe(dev, -EINVAL, - "post-office window does not match the J873 profile\n"); if (!res || resource_size(res) < mbox->hw->reg_offset + mbox->hw->i2a_recv1 + sizeof(u64)) return dev_err_probe(dev, -EINVAL, @@ -1613,21 +1599,6 @@ static int apple_mbox_probe(struct platform_device *pdev) mbox->regs = (u8 __iomem *)mbox->regs + mbox->hw->reg_offset; } - if (mbox->hw->rx_poll_required) { - mbox->rx_util_min = -1; - mbox->rx_util_min_applied = -1; - spin_lock_init(&mbox->rx_lock); - spin_lock_init(&mbox->tx_lock); - mutex_init(&mbox->lifecycle_lock); - init_completion(&mbox->tx_empty); - priv->rx_poll_only = true; - INIT_DELAYED_WORK(&priv->rx_poll_work, apple_mbox_v8_rx_poll_work); - mbox->irq_recv_not_empty = -ENXIO; - mbox->irq_send_empty = -ENXIO; - dev_info(dev, "J873 post-office: paired transfers, bounded polling, no IRQ claim\n"); - goto setup_pm; - } - if (mbox->hw->polled) { mbox->irq_recv_not_empty = -ENXIO; mbox->irq_send_empty = -ENXIO; @@ -1687,7 +1658,6 @@ static int apple_mbox_probe(struct platform_device *pdev) return ret; } -setup_pm: ret = devm_pm_runtime_enable(dev); if (ret) return ret; @@ -1981,31 +1951,10 @@ static const struct apple_mbox_hw apple_mbox_t8152_smc_hw = { .has_irq_controls = false, }; -/* - * T8152 ANS: msgbox-mailbox-num 3 in the non-alias post-office bank, the - * same counted FIFO as the SMC mailbox. Its interrupt ordering is not known, - * so no interrupt is described and both directions are polled. - */ -static const struct apple_mbox_hw apple_mbox_t8152_ans_hw = { - .rx_poll_required = true, - .j873_window = 0x316010300ULL, - .counted_fifo = true, - .control_full = GENMASK(11, 8), /* free TX slots */ - .control_empty = GENMASK(3, 0), /* RX occupancy */ - .a2i_control = 0x20, - .a2i_send0 = 0x10, - .a2i_send1 = 0x18, - .i2a_control = 0x20, - .i2a_recv0 = 0x00, - .i2a_recv1 = 0x08, - .has_irq_controls = false, -}; - static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t8152-smc-mailbox", .data = &apple_mbox_t8152_smc_hw }, /* The AOP's ASC wrapper mailbox has the SMC mailbox's counted FIFOs. */ { .compatible = "apple,t8152-ascwrap-v8-mailbox", .data = &apple_mbox_t8152_smc_hw }, - { .compatible = "apple,t8152-ans-mailbox", .data = &apple_mbox_t8152_ans_hw }, { .compatible = "apple,t6031-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8122-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8152-gfx-ascwrap-v8", .data = &apple_mbox_t8152_gfx_ascwrap_v8_hw }, From fad2b80d3dd11ca9b9ec392b143142e33cd7a35e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:21:51 +0100 Subject: [PATCH 059/112] dt-bindings: mailbox: apple,mailbox: drop the standalone T8152 ANS mailbox The J873g ANS mailbox is now described with the apple,t8152-smc-mailbox fallback and its interrupts. Remove the standalone, interrupt-less apple,t8152-ans-mailbox entry and its conditions. Signed-off-by: Thomas Glanzmann --- .../bindings/mailbox/apple,mailbox.yaml | 20 +------------------ 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index a00459b368cfa..7626c8afcedbd 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -109,11 +109,6 @@ properties: - apple,t8142-aop-setup-mailbox - const: apple,t8140-aop-setup-mailbox - - description: - T8152 ANS post-office mailbox, a 0x80 window in the post-office - bank. No interrupts are described for it; the host polls it. - const: apple,t8152-ans-mailbox - - description: An older ASC mailbox interface found on T2 and A11 that is also used for the NVMe coprocessor and the system management @@ -177,9 +172,7 @@ allOf: properties: compatible: contains: - enum: - - apple,secure-rtbuddy-proxy - - apple,t8152-ans-mailbox + const: apple,secure-rtbuddy-proxy then: required: - interrupts @@ -201,16 +194,6 @@ allOf: - const: send-empty - const: recv-not-empty - - if: - properties: - compatible: - contains: - const: apple,t8152-ans-mailbox - then: - properties: - interrupts: false - interrupt-names: false - - if: properties: compatible: @@ -259,7 +242,6 @@ allOf: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox - apple,t8140-aop-setup-mailbox - - apple,t8152-ans-mailbox - apple,t8152-ascwrap-v8-mailbox - apple,t8152-smc-mailbox then: From ec172bbcc1ed9d7866b3ba69a2e50cceed4fa10f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:56:43 +0100 Subject: [PATCH 060/112] arm64: dts: apple: j873: note the USB DARTs' power domains The J873g USB controllers and their DARTs are powered by PMGR2 PSD services 175 (usb-drd1) and 176 (usb-drd2). Say so on the DART nodes, and that the domain waits on the T8152 PSD provider and has to stay on until Linux can restore the USB2 PHY setup the loader leaves. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index 6f1a956bd68e3..dc4b2fb720f89 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -18,6 +18,11 @@ * own window only, and describe instance 1 as a node of its own. */ +/* + * The USB DARTs' power domain is PSD service 175 (usb-drd1) and 176 (usb-drd2). + * It waits on the T8152 PSD provider (aurora-silicon/linux#2459), and must stay + * on until Linux can restore the USB2 PHY setup the loader leaves behind. + */ &dwc3_1_dart { reg = <0x4 0x0b020000 0x0 0xc000>; status = "okay"; @@ -30,6 +35,7 @@ / { soc { + /* Power domain: PSD service 175, see dwc3_1_dart above. */ dwc3_1_dart_1: iommu@40b040000 { compatible = "apple,t8152-dart", "apple,t8110-dart"; reg = <0x4 0x0b040000 0x0 0xc000>; @@ -48,6 +54,7 @@ snps,dis_u3_susphy_quirk; }; + /* Power domain: PSD service 176, see dwc3_1_dart above. */ dwc3_2_dart_1: iommu@383040000 { compatible = "apple,t8152-dart", "apple,t8110-dart"; reg = <0x3 0x83040000 0x0 0xc000>; From 0c20271a290634dc9713b0c3fca580241eaa6ff6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:54:10 +0100 Subject: [PATCH 061/112] soc: apple: rtkit: let clients register adopted endpoints A co-processor adopted from the bootloader has already sent its endpoint map, to the bootloader, so the application endpoints a client starts on it by hand are not in rtk->endpoints. Every message on them is then logged as one to an undiscovered endpoint. The T8152 DCP driver would get one per SET_SURFACE, about 60 lines a second during video. Add apple_rtkit_adopt_ep() for a client to register an application endpoint of such a session. Signed-off-by: Thomas Glanzmann --- drivers/soc/apple/rtkit.c | 12 ++++++++++++ include/linux/soc/apple/rtkit.h | 10 ++++++++++ 2 files changed, 22 insertions(+) diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index 22a7fad956426..28275cc950c43 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2058,6 +2058,18 @@ bool apple_rtkit_v27_rx_drained(struct apple_rtkit *rtk) } EXPORT_SYMBOL_GPL(apple_rtkit_v27_rx_drained); +/* + * A co-processor adopted from the bootloader has already sent its endpoint + * map. A client that starts one of its application endpoints by hand + * registers it here, so its messages are not reported as undiscovered. + */ +void apple_rtkit_adopt_ep(struct apple_rtkit *rtk, u8 ep) +{ + if (ep >= APPLE_RTKIT_APP_ENDPOINT_START) + set_bit(ep, rtk->endpoints); +} +EXPORT_SYMBOL_GPL(apple_rtkit_adopt_ep); + int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint) { u64 msg; diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 4db916bb89f09..c76e50bd67d59 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -512,4 +512,14 @@ struct apple_rtkit *devm_apple_rtkit_init_m5_saved(struct device *dev, void *coo const char *mbox_name, int mbox_idx, const struct apple_rtkit_ops *ops); +/* + * Registers an application endpoint the client started itself on a + * co-processor whose endpoint map the bootloader consumed, so that its + * messages are not reported as undiscovered + * + * @rtk: RTKit reference + * @ep: endpoint to register + */ +void apple_rtkit_adopt_ep(struct apple_rtkit *rtk, u8 ep); + #endif /* _LINUX_APPLE_RTKIT_H_ */ From c6e38b3a09e8762ad1716ac99c061917bd88cbcf Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:55:49 +0100 Subject: [PATCH 062/112] dt-bindings: iommu: apple,dart: add the T8152 Gen3 display DARTs The DARTs in front of the T8152 display coprocessors (DCP, DCPEXT) and their display pipes (ADT "dart,gen3", version 0x300) use the T8110 register layout, but they belong to the SPTM, and the bootloader hands them over locked. Their TLB command register at 0x80 answers translation queries instead of flushing. A stream is invalidated the way iBoot does it: a payload naming the DART and the stream is written to the SoC's TLB invalidation aperture, which these DARTs share, and a broadcast TLBI follows. Add apple,t8152-dart-gen3 for them, without the apple,t8110-dart fallback, since a T8110 driver would flush through the wrong register, and a "tlbi" register entry for the DART's window in the aperture. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/iommu/apple,dart.yaml | 37 ++++++++++++++++++- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 034e70bdc6558..d7e8e332951ad 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -32,6 +32,7 @@ properties: - apple,t8103-usb4-dart - apple,t8110-dart - apple,t6000-dart + - apple,t8152-dart-gen3 - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -87,13 +88,16 @@ properties: fabric filter (GAPF) that protects the power state of the coprocessor CPU behind this DART, cleared to power that CPU down, or the shared PS write-disable register that holds this DART's - bit for the same purpose (T8142) + bit for the same purpose (T8142), or on a T8152 Gen3 DART its + window in the SoC's TLB invalidation aperture (ADT + dart-tlbi-aperture plus tlbi-aperture-offset), which the Gen3 + DARTs share reg-names: minItems: 1 items: - const: dart - - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - enum: [dapf, gapf, ps-wr-dis, auxiliary, tlbi] interrupts: maxItems: 1 @@ -361,6 +365,35 @@ allOf: then: required: - reg-names + - if: + properties: + compatible: + contains: + const: apple,t8152-dart-gen3 + then: + description: + The T8152 Gen3 DARTs in front of the display coprocessors and their + display pipes belong to the SPTM. The bootloader hands them over + locked, and the operating system only adds page table entries in + root slots that are empty at handoff. Their TLB command register + answers translation queries; a stream is invalidated through the + TLB invalidation aperture instead. + properties: + reg: + minItems: 2 + reg-names: + items: + - const: dart + - const: tlbi + required: + - reg-names + else: + properties: + reg-names: + minItems: 1 + items: + - const: dart + - enum: [dapf, gapf, ps-wr-dis, auxiliary] additionalProperties: false From 0f1ea4292f9f85796c11df9c97732a7e1103fb5b Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:57:36 +0100 Subject: [PATCH 063/112] iommu: apple-dart: support the locked Gen3 DARTs of T8152 The T8152 display DARTs (ADT "dart,gen3", version 0x300) use the T8110 register layout but belong to the SPTM: their TLB command register at 0x80 answers translation queries instead of flushing. A stream is invalidated the way iBoot does it, by writing a 128-bit payload (valid, route, SID) to the SoC's shared TLBI aperture and broadcasting a TLBI, which the DART snoops. The route is the DART's 0x4604 register. Admit a Gen3 DART only when the bootloader hands it over locked (its streams cannot be set up cold yet), map the aperture from a second "tlbi" reg entry without claiming it, since every Gen3 DART shares it, flush the whole stream where a range flush would go through 0x80, and do not claim the fault interrupt or drain stale exceptions, whose handling acknowledges through that register as well. The range flush test fixture gains the new hw flag. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 113 +++++++++++++++++++++++++- tools/asahi/apple-dart-range-tests.py | 2 +- 2 files changed, 111 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 5a9d715d22126..a1550faf6fb15 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -277,6 +277,8 @@ struct apple_dart; struct apple_dart_hw { enum dart_type type; + /* T8110 register layout, SPTM-owned TLB invalidation (T8152) */ + bool gen3; irqreturn_t (*irq_handler)(int irq, void *dev); int (*invalidate_tlb)(struct apple_dart_stream_map *stream_map); void (*enable_remap)(struct apple_dart *dart, int sid, int remap_to); @@ -540,6 +542,10 @@ struct apple_dart { unsigned int sleep_writers; bool sleep_closed; + /* Gen3: shared TLBI aperture and this DART's route in it */ + void __iomem *tlbi; + u8 tlbi_route; + DECLARE_BITMAP(remapped, DART_MAX_STREAMS); u8 remap_target[DART_MAX_STREAMS]; @@ -1985,6 +1991,43 @@ static int apple_dart_fw_invalidate(struct apple_dart_stream_map *stream_map, return 0; } +#define DART_GEN3_TLBI_ROUTE 0x4604 +#define DART_GEN3_TLBI_VALID BIT_ULL(60) +#define DART_GEN3_TLBI_ROUTE_FIELD GENMASK_ULL(59, 56) +#define DART_GEN3_TLBI_SID GENMASK_ULL(55, 48) + +/* + * Gen3 DARTs (T8152) are owned by the SPTM, and their TLB command register at + * 0x80 answers translation queries instead of flushing. A stream is + * invalidated the way iBoot does it: write a 128-bit payload (valid, route, + * SID) to the shared TLBI aperture, then broadcast a TLBI, which the DART + * snoops and applies to that stream. + */ +static int +apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + struct apple_dart *dart = stream_map->dart; + unsigned long flags; + int sid; + + spin_lock_irqsave(&dart->lock, flags); + for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { + u64 lo = DART_GEN3_TLBI_VALID | + FIELD_PREP(DART_GEN3_TLBI_ROUTE_FIELD, dart->tlbi_route) | + FIELD_PREP(DART_GEN3_TLBI_SID, sid); + + dma_wmb(); + asm volatile("stp %0, xzr, [%1]\n" + "dsb ish\n" + ".inst 0xd50881bf\n" /* tlbi vale1os, xzr */ + "dsb osh\n" + : : "r"(lo), "r"(dart->tlbi) : "memory"); + } + spin_unlock_irqrestore(&dart->lock, flags); + + return 0; +} + static int apple_dart_t8020_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) { @@ -2723,8 +2766,11 @@ static int apple_dart_domain_flush_tlb_range(struct apple_dart_domain *domain, /* The range registers take the DVA the device issues. */ start = first + domain->dma_offset; end = last + domain->dma_offset; - if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && - stream.dart->version >= 0x0202) + /* Gen3 has no range command; invalidate the complete stream. */ + if (stream.dart->hw->gen3) + ret = stream.dart->hw->invalidate_tlb(&stream); + else if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && + stream.dart->version >= 0x0202) ret = apple_dart_fw_invalidate(&stream, start, end); else if (range && stream.dart->locked && stream.dart->version >= 0x0202) ret = apple_dart_t8110_hw_tlb_command_range(&stream, op, true, @@ -5619,6 +5665,13 @@ static int apple_dart_probe(struct platform_device *pdev) * not admitted: never enable that level IRQ for one block alone. */ dart->irq = -1; + } else if (dart->hw->gen3) { + /* + * The T8110 fault handler acknowledges through the TLB command + * register, which a Gen3 DART uses for translation queries. + * Leave its faults to the firmware for now. + */ + dart->irq = -1; } else if (dart->preserve_display || j713_radio) { dart->irq = platform_get_irq_optional(pdev, 0); if (dart->irq == -ENXIO) @@ -6005,8 +6058,34 @@ static int apple_dart_probe(struct platform_device *pdev) goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* Only an iBoot-provisioned (locked) Gen3 stream is supported. */ + if (!dart->locked) { + dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); + ret = -ENODEV; + goto err_clk_disable; + } + /* The aperture is shared by every Gen3 DART: map, do not claim. */ + tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); + if (!tlbi || resource_size(tlbi) < 16) { + dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); + ret = -EINVAL; + goto err_clk_disable; + } + dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); + if (!dart->tlbi) { + ret = -ENOMEM; + goto err_clk_disable; + } + dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; + dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", + dart->version, dart->tlbi_route); + } + /* Borrowed display state: never acknowledge someone else's fault. */ - if (dart->locked && !dart->preserve_display) + if (dart->locked && !dart->preserve_display && !dart->hw->gen3) apple_dart_drain_stale_exceptions(dart); /* Refuse an already pending inherited fault before joining the shared IRQ. */ @@ -6361,6 +6440,33 @@ static const struct apple_dart_hw apple_dart_hw_t6000 = { .ttbr_count = 4, }; +static const struct apple_dart_hw apple_dart_hw_gen3 = { + .type = DART_T8110, + .gen3 = true, + .irq_handler = apple_dart_t8110_irq, + .invalidate_tlb = apple_dart_gen3_hw_invalidate_tlb, + .fmt = APPLE_DART2, + .max_sid_count = 256, + + .enable_streams = DART_T8110_ENABLE_STREAMS, + .lock = DART_T8110_PROTECT, + .lock_bit = DART_T8110_PROTECT_TTBR_TCR, + + .error = DART_T8110_ERROR, + + .tcr = DART_T8110_TCR, + .tcr_enabled = DART_T8110_TCR_TRANSLATE_ENABLE, + .tcr_disabled = 0, + .tcr_bypass = DART_T8110_TCR_BYPASS_DAPF | DART_T8110_TCR_BYPASS_DART, + .tcr_4level = DART_T8110_TCR_FOUR_LEVEL, + + .ttbr = DART_T8110_TTBR, + .ttbr_valid = DART_T8110_TTBR_VALID, + .ttbr_addr_field_shift = DART_T8110_TTBR_ADDR_FIELD_SHIFT, + .ttbr_shift = DART_T8110_TTBR_SHIFT, + .ttbr_count = 1, +}; + static const struct apple_dart_hw apple_dart_hw_t8110 = { .type = DART_T8110, .irq_handler = apple_dart_t8110_irq, @@ -7139,6 +7245,7 @@ static const struct dev_pm_ops apple_dart_pm_ops = { }; static const struct of_device_id apple_dart_of_match[] = { + { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, diff --git a/tools/asahi/apple-dart-range-tests.py b/tools/asahi/apple-dart-range-tests.py index edebda6eb6a9d..8939de0a74e85 100644 --- a/tools/asahi/apple-dart-range-tests.py +++ b/tools/asahi/apple-dart-range-tests.py @@ -44,7 +44,7 @@ def main(): #define io_pgtable_ops_to_pgtable(x) ((struct io_pgtable *)(x)) struct apple_dart; struct apple_dart_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; -struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); }; +struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); bool gen3; }; struct apple_dart { int num_streams, locked, version; bool fw_mirror, fw_handoff, managed_sids, display_dark, display_tlb_stale; void *dev; struct apple_dart_hw *hw; }; struct apple_dart_atomic_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; struct apple_dart_domain { From edb7e7ee1ead5fadb79f240dcc7dd612415a6ee6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:58:00 +0100 Subject: [PATCH 064/112] iommu: apple-dart: issue the Gen3 TLBI in the EL1&0 regime on VHE The Gen3 DART snoops the broadcast TLBI that follows the aperture write. iBoot and the aura bootloader issue TLBI VALE1OS at EL2 without VHE, which targets the EL1&0 regime. On a VHE kernel the same instruction targets EL2&0 while HCR_EL2.TGE is set, so clear TGE around it, as KVM does to reach the EL1&0 regime. The J873g display works with this in place; the effect of the change on its own has not been isolated on hardware. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index a1550faf6fb15..e9a3769485925 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -57,6 +57,9 @@ #include #include +#include +#include + #include "dma-iommu.h" #if IS_ENABLED(CONFIG_APPLE_DART_KUNIT_TEST) @@ -2008,9 +2011,21 @@ apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) { struct apple_dart *dart = stream_map->dart; unsigned long flags; + u64 hcr = 0; int sid; spin_lock_irqsave(&dart->lock, flags); + /* + * The DART snoops an EL1&0 TLBI, as iBoot and aura (EL2 without VHE) + * issue it. A VHE kernel's TLBI VALE1OS targets EL2&0 while + * HCR_EL2.TGE is set, so clear TGE around it, as KVM does to reach + * the EL1&0 regime. + */ + if (is_kernel_in_hyp_mode()) { + hcr = read_sysreg(hcr_el2); + write_sysreg(hcr & ~HCR_TGE, hcr_el2); + isb(); + } for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { u64 lo = DART_GEN3_TLBI_VALID | FIELD_PREP(DART_GEN3_TLBI_ROUTE_FIELD, dart->tlbi_route) | @@ -2023,6 +2038,10 @@ apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) "dsb osh\n" : : "r"(lo), "r"(dart->tlbi) : "memory"); } + if (is_kernel_in_hyp_mode()) { + write_sysreg(hcr, hcr_el2); + isb(); + } spin_unlock_irqrestore(&dart->lock, flags); return 0; From a9439033025cb42b042bb4d47eba91171c09af16 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:58:41 +0100 Subject: [PATCH 065/112] dt-bindings: display: add the Apple T8152 DCP on the iBoot interface The display coprocessor (DCP) of the Apple T8152 runs RTKit firmware that offers a small display service, "disp0-service", next to the full IOMobileFramebuffer protocol; iBoot drives the displays through it. The DCP fetches through its own DART, and the display pipe scans out through another one that is locked with a root of its own, so the scanout stream is a child node. The DCP's DPTX port drives either the ATC PHY of a USB-C port, whose PD controller reports the DisplayPort alt mode and the plug orientation, or, on the Mac mini (J873g), the dedicated DisplayPort PHY that feeds the HDMI port through a DisplayPort-to-HDMI converter. The sink's EDID is read through the AP's DisplayPort AUX controller. Signed-off-by: Thomas Glanzmann --- .../display/apple,t8152-dcp-iboot.yaml | 235 ++++++++++++++++++ 1 file changed, 235 insertions(+) create mode 100644 Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml new file mode 100644 index 0000000000000..37b14961bbe77 --- /dev/null +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -0,0 +1,235 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/apple,t8152-dcp-iboot.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 DCP on the iBoot display interface + +maintainers: + - Thomas Glanzmann + +description: | + The Display Coprocessor (DCP) of the Apple T8152 SoC runs RTKit firmware + that offers a small iBoot display interface (disp0-service) next to the + full IOMobileFramebuffer protocol. This binding describes the DCP driven + through that interface, together with the DisplayPort PHY its DPTX port + is routed to. The DCP fetches through its own DART, the display pipe + scans out through another one, which sees each scanout buffer at the same + address. + +properties: + compatible: + const: apple,t8152-dcp-iboot + + reg: + minItems: 2 + maxItems: 7 + + reg-names: + oneOf: + - items: + - const: coproc + - const: atc + - const: dp-clock + - const: atc-ps + - const: atc-psd + - const: aux + - const: aux-ps + minItems: 5 + description: + DCP coprocessor, ATC DisplayPort PHY (USB-C), the PMGR clock + control of its DisplayPort link, the PMGR power states the PHY + depends on, and optionally the AP DisplayPort AUX controller that + reads the sink's EDID with its PMGR power state + - items: + - const: coproc + - const: phy-core + - const: phy-apb + - const: aux + - const: aux-ps + minItems: 3 + description: + DCP coprocessor, the HDMI dptx-phy blocks, and optionally the AP + DisplayPort AUX controller that reads the sink's EDID with its + PMGR power state + - items: + - const: coproc + - const: dp-clock + - const: aux + - const: aux-ps + minItems: 2 + description: + DCP coprocessor, the PMGR clock control of the ATC DisplayPort + link (shared by the ports), and optionally the AP DisplayPort AUX + controller with its PMGR power state; the USB-C ports follow as + usb-c child nodes + + apple,tunable-pre: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the ATC PHY block + - description: mask + - description: value + description: + ATC PHY tunables (ADT ACIOPHY_CMN and CIOPLL_CORE defaults), applied + before the lane crossbar setup when the PHY starts from cold. + + apple,tunable-post: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the ATC PHY block + - description: mask + - description: value + description: + ATC PHY tunables (ADT ATC_FABRIC, DPPLL and AUX defaults), applied + after the lane crossbar setup. + + apple,hdmi: + type: boolean + description: + The DCP drives the HDMI port through the dedicated dptx-phy and an + on-board DisplayPort-to-HDMI converter, instead of an ATC USB-C PHY. + + apple,usb-pd: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The USB-C port's PD controller (SPMI), polled for the DisplayPort alt + mode connection and the plug orientation. + + hpd-gpios: + maxItems: 1 + description: + Hot plug detect line of the connector, if the AP can read it (J873g + HDMI); without it the sink is assumed to stay connected. + + mboxes: + maxItems: 1 + + iommus: + maxItems: 1 + description: DCP DART stream + + scanout: + type: object + additionalProperties: false + description: + The display pipe's scanout stream. Its DART is locked with its own + root, so it is a separate device that sees each scanout buffer at the + DCP's address. + properties: + iommus: + maxItems: 1 + dma-coherent: true + required: + - iommus + + dma-coherent: true + + apple,die: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Die of the DPTX connection target, 0 if absent. + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + ranges: true + +patternProperties: + "^usb-c@[0-9a-f]+$": + type: object + additionalProperties: false + description: + A USB-C port whose ATC PHY the DCP can drive. The DCP drives one port + at a time, the one a DisplayPort sink is plugged into. + properties: + reg: + maxItems: 3 + reg-names: + items: + - const: atc + - const: atc-ps + - const: atc-psd + description: + ATC DisplayPort PHY, the PMGR power states it depends on (DP_0, + DP_1 and USB_AON) and its common power domain (PSD) + apple,dfp-endpoint: + $ref: /schemas/types.yaml#/definitions/uint32 + description: The ATC's display-crossbar0 DFP endpoint (ATC instance). + apple,usb-pd: + $ref: /schemas/types.yaml#/definitions/phandle + description: The port's PD controller (SPMI). + apple,tunable-pre: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: As the node's apple,tunable-pre, for this port's PHY. + apple,tunable-post: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: As the node's apple,tunable-post, for this port's PHY. + required: + - reg + - reg-names + - apple,dfp-endpoint + - apple,usb-pd + +required: + - compatible + - reg + - reg-names + - mboxes + - iommus + - scanout + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display@286e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x86e00000 0x0 0x74000>, + <0x4 0x13000000 0x0 0x84000>, + <0x3 0x0002005c 0x0 0x4>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "coproc", "atc", "dp-clock", "atc-ps", "atc-psd"; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + + scanout { + iommus = <&disp0_dart 0>; + }; + }; + + display@296e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x96e00000 0x0 0x74000>, + <0x3 0x0002005c 0x0 0x4>; + reg-names = "coproc", "dp-clock"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + + scanout { + iommus = <&disp0_dart 0>; + }; + + usb-c@413000000 { + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <3>; + apple,usb-pd = <&hpm3>; + }; + }; + }; From a96a3fb906ebbd9257610a07747728fcdbe27da9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 10:01:10 +0100 Subject: [PATCH 066/112] drm/apple_dcpib: add the T8152 DCP display driver on the iBoot interface The T8152 DCP firmware (AppleDCP-1317) offers a small "disp0-service" next to the full IOMobileFramebuffer protocol that drm/apple speaks. iBoot and the aura bootloader drive the Mac mini (J873g) displays through it. This driver uses only that service, the DPTX port service the firmware calls back into for the PHY, and the DPAV controller services it expects to be opened, all over AFKEPV2 rings. It is a port of aura's afk.c, dcp_iboot.c, dcp/dptx_port_ep.c, dcp/atc_phy.c and dcp/dptx_phy.c. The driver takes over the displays the bootloader brought up: - The DCP does not acknowledge AP QUIESCED, and an IOP INIT while its AP power is still ON panics it ("Invalid AP power: 32"). The RTKit session is adopted as it runs, and the application endpoints are started with explicit START_EP messages. The bootloader stops its AFK endpoints first: an AFK INIT on a live endpoint asserts in the firmware. - A new iBoot session has no surface, and a pipe still running then fetches from a null base (IOMFB axi_rd_err, firmware NMI). The display is powered off until a surface is set. - The DCP fetches through dart-dcp, the display pipe scans out through dart-disp0, and both are locked with live roots of their own. The scanout stream is a child device with a domain of its own. Scanout buffers are mapped there at their DCP address, cacheable, since the pipe faults on entries with the DART's no-cache bit, and away from the firmware's own mappings. - Changing the surface between buffers made later SET_MODEs crash the firmware. Three scanout buffers are allocated at probe, large enough for the largest mode; a frame is copied into one that is not on screen and swapped in with SET_SURFACE, at most once per refresh, since there is no vblank interrupt. - The firmware takes only width, height and refresh rate for a mode and picks the timing itself. It does not hand out the EDID on this interface, so the EDID is read through the AP's DisplayPort AUX controllers. On USB-C, the DCP drives the ATC PHY of the rear port that has a DisplayPort sink, which the port's ACE3 PD controller reports over SPMI together with the plug orientation. The J873g HDMI port has a dedicated DisplayPort PHY behind a PS190 DP-to-HDMI converter. Both PHYs keep the bootloader's setup and reprogram what a link training changes. With a USB-C display at boot, the bootloader drives HDMI from DCPEXT0; without one, it drives HDMI from the main DCP and never starts DCPEXT0. The driver follows the source select it finds in the HDMI PHY. HDMI hotplug is polled from the converter's HPD line, USB-C hotplug from the PD controller, and display power follows the CRTC. Signed-off-by: Thomas Glanzmann --- MAINTAINERS | 7 + drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/Makefile | 1 + drivers/gpu/drm/apple_dcpib/Kconfig | 19 + drivers/gpu/drm/apple_dcpib/Makefile | 3 + drivers/gpu/drm/apple_dcpib/afk.c | 740 ++++++++++++++++++++++++ drivers/gpu/drm/apple_dcpib/atc.c | 789 +++++++++++++++++++++++++ drivers/gpu/drm/apple_dcpib/aux.c | 196 +++++++ drivers/gpu/drm/apple_dcpib/dcpib.h | 334 +++++++++++ drivers/gpu/drm/apple_dcpib/dptx.c | 324 +++++++++++ drivers/gpu/drm/apple_dcpib/drv.c | 514 +++++++++++++++++ drivers/gpu/drm/apple_dcpib/hdmi.c | 337 +++++++++++ drivers/gpu/drm/apple_dcpib/iboot.c | 243 ++++++++ drivers/gpu/drm/apple_dcpib/kms.c | 833 +++++++++++++++++++++++++++ drivers/gpu/drm/apple_dcpib/pd.c | 176 ++++++ 15 files changed, 4517 insertions(+) create mode 100644 drivers/gpu/drm/apple_dcpib/Kconfig create mode 100644 drivers/gpu/drm/apple_dcpib/Makefile create mode 100644 drivers/gpu/drm/apple_dcpib/afk.c create mode 100644 drivers/gpu/drm/apple_dcpib/atc.c create mode 100644 drivers/gpu/drm/apple_dcpib/aux.c create mode 100644 drivers/gpu/drm/apple_dcpib/dcpib.h create mode 100644 drivers/gpu/drm/apple_dcpib/dptx.c create mode 100644 drivers/gpu/drm/apple_dcpib/drv.c create mode 100644 drivers/gpu/drm/apple_dcpib/hdmi.c create mode 100644 drivers/gpu/drm/apple_dcpib/iboot.c create mode 100644 drivers/gpu/drm/apple_dcpib/kms.c create mode 100644 drivers/gpu/drm/apple_dcpib/pd.c diff --git a/MAINTAINERS b/MAINTAINERS index 3f919f3e327f3..55374e1146d1f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2150,6 +2150,13 @@ F: tools/testing/kunit/configs/mt7932.config F: tools/testing/selftests/drivers/apple/aop-las.py F: tools/testing/selftests/drivers/gpu/apple-dcp/ +APPLE T8152 DCP DISPLAY DRIVER (IBOOT INTERFACE) +M: Thomas Glanzmann +L: dri-devel@lists.freedesktop.org +S: Maintained +F: Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +F: drivers/gpu/drm/apple_dcpib/ + APPLETALK NETWORK LAYER L: netdev@vger.kernel.org S: Obsolete diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 89c899e836797..d80f7832f6f27 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -302,6 +302,7 @@ config DRM_PRIVACY_SCREEN source "drivers/gpu/drm/adp/Kconfig" source "drivers/gpu/drm/amd/amdgpu/Kconfig" source "drivers/gpu/drm/apple/Kconfig" +source "drivers/gpu/drm/apple_dcpib/Kconfig" source "drivers/gpu/drm/arm/Kconfig" source "drivers/gpu/drm/armada/Kconfig" source "drivers/gpu/drm/asahi/Kconfig" diff --git a/drivers/gpu/drm/Makefile b/drivers/gpu/drm/Makefile index cd966b1b5b47e..ccc1d8ef193c8 100644 --- a/drivers/gpu/drm/Makefile +++ b/drivers/gpu/drm/Makefile @@ -231,6 +231,7 @@ obj-$(CONFIG_DRM_APPLE_FABRIC_CORE) += apple/dcp-fabric-core.o obj-$(CONFIG_DRM_APPLE_FABRIC_KUNIT_TEST) += apple/dcp-fabric-test.o obj-$(CONFIG_DRM_APPLE) += apple/ obj-$(CONFIG_DRM_APPLE_KUNIT_TEST) += apple/iomfb-state-test.o +obj-$(CONFIG_DRM_APPLE_DCPIB) += apple_dcpib/ obj-$(CONFIG_DRM_ASPEED_GFX) += aspeed/ obj-$(CONFIG_DRM_MCDE) += mcde/ obj-$(CONFIG_DRM_TIDSS) += tidss/ diff --git a/drivers/gpu/drm/apple_dcpib/Kconfig b/drivers/gpu/drm/apple_dcpib/Kconfig new file mode 100644 index 0000000000000..64dd695889b2f --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/Kconfig @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0-only OR MIT +config DRM_APPLE_DCPIB + tristate "Apple T8152 DCP display (iBoot interface)" + depends on DRM && OF && ARM64 + depends on ARCH_APPLE || COMPILE_TEST + depends on APPLE_RTKIT + depends on SPMI + select APERTURE_HELPERS + select DRM_CLIENT_SELECTION + select DRM_GEM_DMA_HELPER + select DRM_KMS_HELPER + help + Display driver for the DCP of the Apple T8152 (Mac mini J873g) on + the firmware's small iBoot interface. It takes over the displays + the bootloader brought up, with the DCP's firmware session still + running: a USB-C display on one of the rear ports and the HDMI port. + + To compile this driver as a module, choose M here: the module will + be called apple_dcpib. diff --git a/drivers/gpu/drm/apple_dcpib/Makefile b/drivers/gpu/drm/apple_dcpib/Makefile new file mode 100644 index 0000000000000..5a288e7df1a29 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only OR MIT +apple_dcpib-y := drv.o afk.o iboot.o dptx.o atc.o hdmi.o kms.o pd.o aux.o +obj-$(CONFIG_DRM_APPLE_DCPIB) += apple_dcpib.o diff --git a/drivers/gpu/drm/apple_dcpib/afk.c b/drivers/gpu/drm/apple_dcpib/afk.c new file mode 100644 index 0000000000000..01ca8668e44f6 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/afk.c @@ -0,0 +1,740 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * AFKEPV2 ring-buffer endpoints of the T8152 DCP (port of aura src/afk.c). + * + * Each endpoint shares one DMA buffer with the firmware, which carves a TX + * and an RX ring out of it. Messages carry an afkv2 header (interface, seq) + * and a message header (token, type, category). The firmware publishes + * services (REPORT/PUBLISH), which the AP opens; AP commands use out-of-band + * TX/RX buffers, firmware callbacks are inline standard service calls. + */ + +#include +#include +#include +#include + +#include "dcpib.h" + +#define RBEP_TYPE GENMASK_ULL(63, 48) +#define RBEP_INIT 0x80 +#define RBEP_INIT_ACK 0xa0 +#define RBEP_GETBUF 0x89 +#define RBEP_GETBUF_ACK 0xa1 +#define RBEP_INIT_TX 0x8a +#define RBEP_INIT_RX 0x8b +#define RBEP_START 0xa3 +#define RBEP_START_ACK 0x86 +#define RBEP_SEND 0xa2 +#define RBEP_RECV 0x85 +#define RBEP_SHUTDOWN 0xc0 +#define RBEP_SHUTDOWN_ACK 0xc1 + +#define BLOCK_SHIFT 6 +#define GETBUF_SIZE GENMASK_ULL(31, 16) +#define GETBUF_TAG GENMASK_ULL(15, 0) +#define GETBUF_ACK_DVA GENMASK_ULL(47, 0) +#define INITRB_OFFSET GENMASK_ULL(47, 32) +#define INITRB_SIZE GENMASK_ULL(31, 16) +#define INITRB_TAG GENMASK_ULL(15, 0) +#define SEND_WPTR GENMASK_ULL(31, 0) + +#define QE_MAGIC 0x20504f49 /* ' POI' */ +#define SERVICE_CALL_MAGIC 0x69706378 + +#define AFKV2_REPORT 0 +#define AFKV2_COMMAND 1 +#define AFKV2_RESPONSE 2 +#define AFKV2_PUBLISH 0x11 +#define AFKV2_OPEN 0x12 +#define AFKV2_STD_SERVICE 0xc0 + +#define DCPIB_BUF_SIZE 0x4000 +#define DCPIB_TIMEOUT msecs_to_jiffies(3000) + +struct afk_qe { + __le32 magic; + __le32 size; + __le32 channel; + __le32 type; + u8 data[]; +} __packed; + +struct afkv2_hdr { + u8 seq; + u8 reserved; + __le16 interface; + __le32 length; +} __packed; + +struct afkv2_msg { + __le64 token; + u8 type; + u8 category; + u8 flags; + u8 reserved[5]; +} __packed; + +struct afkv2_cmd { + u8 flags; + u8 id; + __le16 reserved; + __le32 value; /* command: response capacity; response: IOReturn */ +} __packed; + +struct afkv2_oob { + __le64 rxbuf; + __le64 txbuf; + __le32 rxlen; + __le32 txlen; +} __packed; + +struct afkv2_service_call { + __le16 reserved; + __le16 group; + __le32 command; + __le32 length; + __le32 magic; + u8 padding[48]; +} __packed; + +struct afk_announce { + char name[32]; + u8 props[]; +} __packed; + +int dcpib_dma_alloc(struct dcpib *dcp, struct dcpib_dma *dma, size_t size) +{ + dma->size = PAGE_ALIGN(size); + dma->cpu = dma_alloc_coherent(dcp->dev, dma->size, &dma->iova, + GFP_KERNEL); + return dma->cpu ? 0 : -ENOMEM; +} + +void dcpib_dma_free(struct dcpib *dcp, struct dcpib_dma *dma) +{ + if (dma->cpu) + dma_free_coherent(dcp->dev, dma->size, dma->cpu, dma->iova); + dma->cpu = NULL; +} + +static int dcpib_send(struct dcpib_ep *ep, u64 msg) +{ + return apple_rtkit_send_message(ep->dcp->rtk, ep->ep, msg, NULL, false); +} + +static int dcpib_ring_init(struct dcpib_ep *ep, struct dcpib_ring *rb, u64 base, + u64 size) +{ + u32 bufsz, block; + void *hdr; + + if (!ep->ring.cpu || base > ep->ring.size || + size > ep->ring.size - base || size < 4 * 0x40) + return -EINVAL; + + hdr = ep->ring.cpu + base; + bufsz = le32_to_cpu(READ_ONCE(*(__le32 *)hdr)); + /* Three blocks hold size, read pointer and write pointer. */ + if (!bufsz || bufsz >= size || (size - bufsz) % 3) + return -EINVAL; + block = (size - bufsz) / 3; + if (block < 0x40 || !is_power_of_2(block) || bufsz % block) + return -EINVAL; + + rb->rptr = hdr + block; + rb->wptr = hdr + 2 * block; + rb->buf = hdr + 3 * block; + rb->bufsz = bufsz; + rb->block = block; + if (READ_ONCE(*rb->rptr) >= bufsz || READ_ONCE(*rb->wptr) >= bufsz) + return -EINVAL; + rb->ready = true; + return 0; +} + +/* Queue one message on the TX ring and tell the firmware. */ +static int dcpib_tx(struct dcpib_ep *ep, const void *data, size_t size) +{ + struct dcpib_ring *rb = &ep->tx; + struct afk_qe *qe; + u32 rptr, wptr, advance; + int ret; + + mutex_lock(&ep->tx_lock); + if (!rb->ready || size > rb->bufsz - sizeof(*qe)) { + ret = -EINVAL; + goto out; + } + + rptr = le32_to_cpu(READ_ONCE(*rb->rptr)); + wptr = le32_to_cpu(READ_ONCE(*rb->wptr)); + advance = ALIGN(sizeof(*qe) + size, rb->block); + + if (wptr < rptr && advance >= rptr - wptr) + goto full; + if (wptr >= rptr) { + bool fits = advance < rb->bufsz - wptr || + (advance == rb->bufsz - wptr && rptr); + + if (!fits && advance >= rptr) + goto full; + } + + qe = rb->buf + wptr; + qe->magic = cpu_to_le32(QE_MAGIC); + qe->size = cpu_to_le32(size); + qe->channel = 0; + qe->type = 0; + wptr += sizeof(*qe); + /* A payload that does not fit before the end starts at offset 0. */ + if (size > rb->bufsz - wptr) { + memcpy(rb->buf, qe, sizeof(*qe)); + qe = rb->buf; + wptr = sizeof(*qe); + } + memcpy(qe->data, data, size); + wptr = ALIGN(wptr + size, rb->block); + if (wptr >= rb->bufsz) + wptr = 0; + + dma_mb(); + WRITE_ONCE(*rb->wptr, cpu_to_le32(wptr)); + dma_wmb(); + ret = dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SEND) | + FIELD_PREP(SEND_WPTR, wptr)); + goto out; +full: + dev_err(ep->dcp->dev, "AFK[%02x]: TX ring full\n", ep->ep); + ret = -ENOSPC; +out: + mutex_unlock(&ep->tx_lock); + return ret; +} + +static int dcpib_tx_v2(struct dcpib_ep *ep, u16 interface, void *packet, + size_t size) +{ + struct afkv2_hdr *hdr = packet; + + mutex_lock(&ep->tx_lock); + hdr->seq = ep->seq++; + mutex_unlock(&ep->tx_lock); + hdr->interface = cpu_to_le16(interface); + hdr->length = cpu_to_le32(size - sizeof(*hdr)); + return dcpib_tx(ep, packet, size); +} + +static struct dcpib_service *dcpib_find_service(struct dcpib_ep *ep, + u16 interface) +{ + for (unsigned int i = 0; i < ep->nr_services; i++) + if (ep->services[i].interface == interface) + return &ep->services[i]; + return NULL; +} + +static void dcpib_announce(struct dcpib_ep *ep, u16 interface, + const void *payload, size_t size) +{ + const struct afk_announce *ann = payload; + struct dcpib_service *service; + struct { + struct afkv2_hdr hdr; + struct afkv2_msg msg; + } __packed open = { + .msg = { .type = AFKV2_OPEN, .category = AFKV2_REPORT, .flags = 1 }, + }; + + if (!interface || size < sizeof(*ann) || + strnlen(ann->name, sizeof(ann->name)) == sizeof(ann->name)) + return; + if (dcpib_find_service(ep, interface)) + return; + if (ep->nr_services >= DCPIB_MAX_SERVICES) { + dev_warn(ep->dcp->dev, "AFK[%02x]: no room for service %s\n", + ep->ep, ann->name); + return; + } + + service = &ep->services[ep->nr_services]; + service->ep = ep; + service->ops = ep->ops; + service->interface = interface; + service->unit = ep->nr_services; + strscpy(service->name, ann->name, sizeof(service->name)); + ep->nr_services++; + + dev_info(ep->dcp->dev, "AFK[%02x]: opening %s on interface %u\n", + ep->ep, service->name, interface); + if (dcpib_tx_v2(ep, interface, &open, sizeof(open))) + dev_err(ep->dcp->dev, "AFK[%02x]: failed to open %s\n", ep->ep, + service->name); + if (ep->nr_services == ep->expected) + complete_all(&ep->services_done); +} + +/* Answer a firmware callback we cannot handle: empty, kIOReturnUnsupported. */ +static void dcpib_reject(struct dcpib_ep *ep, u16 interface, + const struct afkv2_msg *msg, + const struct afkv2_cmd *cmd, bool oob) +{ + struct { + struct afkv2_hdr hdr; + struct afkv2_msg msg; + struct afkv2_cmd cmd; + struct afkv2_oob oob; + } __packed reply = { + .msg = { .token = msg->token, .type = msg->type, + .category = AFKV2_RESPONSE }, + .cmd = { .flags = cmd->flags, .id = cmd->id, + .value = cpu_to_le32(KIO_RETURN_UNSUPPORTED) }, + }; + size_t len = sizeof(reply) - sizeof(reply.oob); + + if (oob) { + const struct afkv2_oob *o = (const void *)(cmd + 1); + + /* Keep the descriptors, return no data; never touch them. */ + reply.oob.rxbuf = o->rxbuf; + reply.oob.txbuf = o->txbuf; + len += sizeof(reply.oob); + } + dev_dbg(ep->dcp->dev, "AFK[%02x]: rejecting callback type %#x\n", + ep->ep, msg->type); + dcpib_tx_v2(ep, interface, &reply, len); +} + +static void dcpib_callback(struct dcpib_ep *ep, u16 interface, + const struct afkv2_msg *msg, const void *payload, + size_t size) +{ + const struct afkv2_cmd *cmd = payload; + const struct afkv2_service_call *call; + struct dcpib_service *service; + struct afkv2_hdr *rhdr; + struct afkv2_msg *rmsg; + struct afkv2_cmd *rcmd; + struct afkv2_service_call *rcall; + size_t body, len; + __le32 status; + u8 *reply; + + if (size < sizeof(*cmd) || cmd->flags & ~1) + return; + if ((cmd->flags & 1) && size < sizeof(*cmd) + sizeof(struct afkv2_oob)) + return; + + service = dcpib_find_service(ep, interface); + body = size - sizeof(*cmd); + call = (const void *)(cmd + 1); + /* Only the inline standard service call form is supported. */ + if (msg->type != AFKV2_STD_SERVICE || cmd->flags || !service || + !service->ops || !service->ops->call || + body < sizeof(*call) + sizeof(u32) || + le32_to_cpu(cmd->value) < body || + le32_to_cpu(call->magic) != SERVICE_CALL_MAGIC || + le32_to_cpu(call->length) != body - sizeof(*call)) { + dcpib_reject(ep, interface, msg, cmd, cmd->flags & 1); + return; + } + + len = sizeof(*rhdr) + sizeof(*rmsg) + size; + reply = kzalloc(len, GFP_KERNEL); + if (!reply) + return; + rhdr = (void *)reply; + rmsg = (void *)(rhdr + 1); + rcmd = (void *)(rmsg + 1); + rcall = (void *)(rcmd + 1); + rmsg->token = msg->token; + rmsg->type = msg->type; + rmsg->category = AFKV2_RESPONSE; + rcmd->id = cmd->id; + memcpy(rcall, call, body); + status = cpu_to_le32(service->ops->call(service, + le16_to_cpu(call->group), + le32_to_cpu(call->command), call + 1, + le32_to_cpu(call->length), rcall + 1, + le32_to_cpu(call->length))); + memcpy(rcall + 1, &status, sizeof(status)); + if (status) + dev_dbg(ep->dcp->dev, + "AFK[%02x]: callback %s group %u command %u -> %#x\n", + ep->ep, service->name, le16_to_cpu(call->group), + le32_to_cpu(call->command), le32_to_cpu(status)); + dcpib_tx_v2(ep, interface, reply, len); + kfree(reply); +} + +static void dcpib_response(struct dcpib_ep *ep, u16 interface, + const struct afkv2_msg *msg, const void *payload, + size_t size) +{ + const struct afkv2_cmd *cmd = payload; + const void *data; + size_t len; + int ret = 0; + + if (!ep->cmd_waiting || interface != ep->cmd_interface || + msg->type != ep->cmd_type || size < sizeof(*cmd) || + cmd->id != ep->cmd_id) { + dev_warn(ep->dcp->dev, + "AFK[%02x]: unexpected response on interface %u\n", + ep->ep, interface); + return; + } + + data = cmd + 1; + len = size - sizeof(*cmd); + if (cmd->flags & ~1) { + ret = -EPROTO; + } else if (le32_to_cpu(cmd->value)) { + dev_dbg(ep->dcp->dev, "AFK[%02x]: command %#x returned %#x\n", + ep->ep, msg->type, le32_to_cpu(cmd->value)); + ret = -EIO; + } else if (cmd->flags & 1) { + const struct afkv2_oob *oob = data; + + if (len < sizeof(*oob)) { + ret = -EPROTO; + } else { + data = oob + 1; + len -= sizeof(*oob); + if (le32_to_cpu(oob->rxlen)) { + if (le64_to_cpu(oob->rxbuf) != ep->rxbuf.iova || + le32_to_cpu(oob->rxlen) > ep->rxbuf.size) { + ret = -EPROTO; + } else { + dma_rmb(); + data = ep->rxbuf.cpu; + len = le32_to_cpu(oob->rxlen); + } + } + } + } + if (!ret && len > ep->cmd_out_len) + ret = -EOVERFLOW; + if (!ret && len) + memcpy(ep->cmd_out, data, len); + ep->cmd_out_len = ret ? 0 : len; + ep->cmd_ret = ret; + ep->cmd_waiting = false; + complete(&ep->cmd_done); +} + +static void dcpib_rx_work(struct work_struct *work) +{ + struct dcpib_ep *ep = container_of(work, struct dcpib_ep, rx_work); + struct dcpib_ring *rb = &ep->rx; + + if (!rb->ready) + return; + + for (;;) { + const struct afkv2_hdr *hdr; + const struct afkv2_msg *msg; + struct afk_qe *qe; + u32 rptr, wptr, qsize; + + dma_rmb(); + rptr = le32_to_cpu(READ_ONCE(*rb->rptr)); + wptr = le32_to_cpu(READ_ONCE(*rb->wptr)); + if (rptr == wptr) + break; + if (rptr >= rb->bufsz || rptr % rb->block) + goto corrupt; + + qe = rb->buf + rptr; + qsize = le32_to_cpu(qe->size); + if (le32_to_cpu(qe->magic) != QE_MAGIC || + qsize > rb->bufsz - sizeof(*qe)) + goto corrupt; + /* An entry that does not fit before the end is at offset 0. */ + if (sizeof(*qe) + qsize > rb->bufsz - rptr) { + rptr = 0; + qe = rb->buf; + qsize = le32_to_cpu(qe->size); + if (le32_to_cpu(qe->magic) != QE_MAGIC || + qsize > rb->bufsz - sizeof(*qe)) + goto corrupt; + } + + hdr = (const void *)qe->data; + msg = (const void *)(hdr + 1); + if (!qe->channel && !qe->type && + qsize >= sizeof(*hdr) + sizeof(*msg) && + le32_to_cpu(hdr->length) == qsize - sizeof(*hdr)) { + u16 interface = le16_to_cpu(hdr->interface); + const void *payload = msg + 1; + size_t size = qsize - sizeof(*hdr) - sizeof(*msg); + + if (msg->category == AFKV2_REPORT && + msg->type == AFKV2_PUBLISH) + dcpib_announce(ep, interface, payload, size); + else if (msg->category == AFKV2_RESPONSE) + dcpib_response(ep, interface, msg, payload, + size); + else if (msg->category == AFKV2_COMMAND) + dcpib_callback(ep, interface, msg, payload, + size); + else + dev_dbg(ep->dcp->dev, "AFK[%02x]: if %u cat %u type %#x: %*ph\n", + ep->ep, interface, msg->category, msg->type, + (int)min_t(size_t, size, 96), payload); + } else { + dev_dbg(ep->dcp->dev, "AFK[%02x]: ignoring message\n", + ep->ep); + } + + dma_mb(); + rptr = ALIGN(rptr + sizeof(*qe) + qsize, rb->block); + if (rptr >= rb->bufsz) + rptr = 0; + WRITE_ONCE(*rb->rptr, cpu_to_le32(rptr)); + } + return; + +corrupt: + dev_err(ep->dcp->dev, "AFK[%02x]: corrupt RX ring, stopping it\n", + ep->ep); + rb->ready = false; +} + +void dcpib_ep_recv(struct dcpib_ep *ep, u64 message) +{ + u32 type = FIELD_GET(RBEP_TYPE, message); + u64 base, size; + int ret; + + switch (type) { + case RBEP_INIT_ACK: + break; + case RBEP_GETBUF: + size = FIELD_GET(GETBUF_SIZE, message) << BLOCK_SHIFT; + ep->tag = FIELD_GET(GETBUF_TAG, message); + if (ep->ring.cpu || dcpib_dma_alloc(ep->dcp, &ep->ring, size)) { + dev_err(ep->dcp->dev, "AFK[%02x]: no ring buffer\n", + ep->ep); + break; + } + dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_GETBUF_ACK) | + FIELD_PREP(GETBUF_ACK_DVA, ep->ring.iova)); + break; + case RBEP_INIT_TX: + case RBEP_INIT_RX: + base = FIELD_GET(INITRB_OFFSET, message) << BLOCK_SHIFT; + size = FIELD_GET(INITRB_SIZE, message) << BLOCK_SHIFT; + if (FIELD_GET(INITRB_TAG, message) != ep->tag) { + dev_err(ep->dcp->dev, "AFK[%02x]: wrong ring tag\n", + ep->ep); + break; + } + ret = dcpib_ring_init(ep, type == RBEP_INIT_RX ? &ep->rx : &ep->tx, + base, size); + if (ret) { + dev_err(ep->dcp->dev, "AFK[%02x]: bad ring %#llx+%#llx\n", + ep->ep, base, size); + break; + } + if (ep->rx.ready && ep->tx.ready) + dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_START)); + break; + case RBEP_START_ACK: + complete_all(&ep->started); + break; + case RBEP_RECV: + queue_work(ep->dcp->wq, &ep->rx_work); + break; + case RBEP_SHUTDOWN_ACK: + complete_all(&ep->stopped); + break; + default: + dev_warn(ep->dcp->dev, "AFK[%02x]: unknown message %#llx\n", + ep->ep, message); + break; + } +} + +struct dcpib_ep *dcpib_ep_start(struct dcpib *dcp, u8 epnum, + const struct dcpib_service_ops *ops, + unsigned int expected) +{ + struct dcpib_ep *ep; + int ret; + + if (epnum < DCPIB_FIRST_EP || epnum >= DCPIB_FIRST_EP + DCPIB_NR_EPS) + return ERR_PTR(-EINVAL); + + ep = devm_kzalloc(dcp->dev, sizeof(*ep), GFP_KERNEL); + if (!ep) + return ERR_PTR(-ENOMEM); + ep->dcp = dcp; + ep->ep = epnum; + ep->ops = ops; + ep->expected = expected; + init_completion(&ep->started); + init_completion(&ep->stopped); + init_completion(&ep->services_done); + init_completion(&ep->cmd_done); + mutex_init(&ep->tx_lock); + mutex_init(&ep->cmd_lock); + INIT_WORK(&ep->rx_work, dcpib_rx_work); + + ret = dcpib_dma_alloc(dcp, &ep->txbuf, DCPIB_BUF_SIZE); + if (!ret) + ret = dcpib_dma_alloc(dcp, &ep->rxbuf, DCPIB_BUF_SIZE); + if (ret) + goto err; + + dcp->eps[epnum - DCPIB_FIRST_EP] = ep; + /* + * START_EP for an application endpoint of the adopted session; the + * bootloader consumed the endpoint map, so apple_rtkit_start_ep() + * does not know it. + */ + ret = apple_rtkit_send_message(dcp->rtk, 0, + FIELD_PREP(GENMASK_ULL(59, 52), 5) | + FIELD_PREP(GENMASK_ULL(39, 32), epnum) | + BIT_ULL(1), NULL, false); + if (ret) { + dev_err(dcp->dev, "failed to start endpoint %#x: %d\n", epnum, ret); + goto err_unregister; + } + apple_rtkit_adopt_ep(dcp->rtk, epnum); + ret = dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_INIT)); + if (ret) + goto err_unregister; + if (!wait_for_completion_timeout(&ep->started, DCPIB_TIMEOUT)) { + dev_err(dcp->dev, "endpoint %#x did not start\n", epnum); + ret = -ETIMEDOUT; + goto err_unregister; + } + if (!wait_for_completion_timeout(&ep->services_done, DCPIB_TIMEOUT) && + !ep->nr_services) { + dev_err(dcp->dev, "endpoint %#x announced no service\n", epnum); + ret = -ETIMEDOUT; + goto err_unregister; + } + if (ep->nr_services < expected) + dev_warn(dcp->dev, "endpoint %#x: %u of %u services\n", epnum, + ep->nr_services, expected); + return ep; + +err_unregister: + /* The firmware may still own the rings; keep them allocated. */ + return ERR_PTR(ret); +err: + dcpib_dma_free(dcp, &ep->txbuf); + dcpib_dma_free(dcp, &ep->rxbuf); + return ERR_PTR(ret); +} + +void dcpib_ep_stop(struct dcpib_ep *ep) +{ + reinit_completion(&ep->stopped); + if (dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)) || + !wait_for_completion_timeout(&ep->stopped, DCPIB_TIMEOUT)) { + dev_err(ep->dcp->dev, "endpoint %#x did not stop\n", ep->ep); + return; + } + ep->rx.ready = ep->tx.ready = false; + flush_work(&ep->rx_work); +} + +int dcpib_command(struct dcpib_service *service, u8 type, const void *tx, + size_t txlen, void *rx, size_t *rxlen) +{ + struct dcpib_ep *ep = service->ep; + size_t cap = rxlen ? *rxlen : 0; + struct { + struct afkv2_hdr hdr; + struct afkv2_msg msg; + struct afkv2_cmd cmd; + struct afkv2_oob oob; + } __packed packet = { + .msg = { .type = type, .category = AFKV2_COMMAND }, + }; + int ret; + + if (txlen > ep->txbuf.size || cap > ep->rxbuf.size) + return -EINVAL; + + mutex_lock(&ep->cmd_lock); + memcpy(ep->txbuf.cpu, tx, txlen); + packet.cmd.flags = 1; + packet.cmd.id = ep->next_cmd_id++; + packet.cmd.value = cpu_to_le32(cap); + packet.oob.rxbuf = cpu_to_le64(cap ? ep->rxbuf.iova : 0); + packet.oob.txbuf = cpu_to_le64(ep->txbuf.iova); + packet.oob.rxlen = cpu_to_le32(cap); + packet.oob.txlen = cpu_to_le32(txlen); + + reinit_completion(&ep->cmd_done); + ep->cmd_interface = service->interface; + ep->cmd_type = type; + ep->cmd_id = packet.cmd.id; + ep->cmd_out = rx; + ep->cmd_out_len = cap; + ep->cmd_ret = -ETIMEDOUT; + WRITE_ONCE(ep->cmd_waiting, true); + + ret = dcpib_tx_v2(ep, service->interface, &packet, sizeof(packet)); + if (!ret && !wait_for_completion_timeout(&ep->cmd_done, DCPIB_TIMEOUT)) + ret = -ETIMEDOUT; + if (!ret) + ret = ep->cmd_ret; + if (!ret && rxlen) + *rxlen = ep->cmd_out_len; + WRITE_ONCE(ep->cmd_waiting, false); + /* A late response must not land in the caller's buffer. */ + flush_work(&ep->rx_work); + mutex_unlock(&ep->cmd_lock); + + if (ret) + dev_dbg(ep->dcp->dev, "AFK[%02x]: command %#x on %s: %d\n", + ep->ep, type, service->name, ret); + return ret; +} + +/* An AP-initiated standard service call (aura afk_service_call). */ +int dcpib_service_call(struct dcpib_service *service, u16 group, u32 command, + const void *data, size_t data_len, size_t data_pad, + void *output, size_t output_len, size_t output_pad) +{ + struct afkv2_service_call *call; + size_t len = max(data_len + data_pad, output_len + output_pad) + + sizeof(*call); + size_t rxlen = len; + u8 *buf; + int ret; + + buf = kzalloc(len, GFP_KERNEL); + if (!buf) + return -ENOMEM; + call = (void *)buf; + call->group = cpu_to_le16(group); + call->command = cpu_to_le32(command); + call->length = cpu_to_le32(data_len + data_pad); + call->magic = cpu_to_le32(SERVICE_CALL_MAGIC); + if (data_len) + memcpy(call + 1, data, data_len); + + ret = dcpib_command(service, AFKV2_STD_SERVICE, buf, len, buf, &rxlen); + if (ret) + goto out; + if (rxlen < sizeof(*call) || + le32_to_cpu(call->magic) != SERVICE_CALL_MAGIC || + le16_to_cpu(call->group) != group || + le32_to_cpu(call->command) != command || + le32_to_cpu(call->length) > rxlen - sizeof(*call) || + le32_to_cpu(call->length) < output_len) { + ret = -EPROTO; + goto out; + } + if (output && output_len) + memcpy(output, call + 1, output_len); +out: + kfree(buf); + return ret; +} diff --git a/drivers/gpu/drm/apple_dcpib/atc.c b/drivers/gpu/drm/apple_dcpib/atc.c new file mode 100644 index 0000000000000..65b0e80810fb6 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/atc.c @@ -0,0 +1,789 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * T8152/J873g ATC DisplayPort PHYs for the DCP's DPTX port (from aura + * src/dcp/atc_phy.c, which drives ATC3). + * + * The bootloader trains the USB-C display before Linux starts; this driver + * takes that link over and then follows the firmware: link rate changes + * (stop and set up the lanes again), drive settings, the DCP0 -> ATCn/DFP0 + * display crossbar route, and with the display off or unplugged a full + * power down and a cold start. The DCP drives one USB-C port at a time: + * the one a sink is plugged into (each port's PD controller is polled). + */ + +#include +#include +#include +#include +#include +#include + +#include "dcpib.h" + +#define ATC_AON 0x1e00 +#define ATC_CFG 0x60000 +#define ATC_XBAR 0x74000 +#define ATC_TIMEOUT_US 10000 + +struct dcpib_atc_port { + void __iomem *base; + unsigned int index; /* ATC instance */ + /* display-crossbar0 DFP endpoint of this ATC */ + u32 dfp; + struct spmi_device *pd; + /* AP DisplayPort AUX controller aux0 (shared), for the EDID */ + struct dcpib_aux *aux; + /* PMGR power states of the four ATC dependencies (aura gate_addr) */ + void __iomem *ps; + void __iomem *psd; + /* the dependencies this driver powered up, and may power down */ + u8 owned; + /* {offset, mask, value} tunables from the ADT, before/after xbar config */ + const __be32 *tunable[2]; + int tunable_len[2]; + /* PMGR DP clock control (shared): the divider selects the link rate */ + void __iomem *dp_clock; + bool swap; + bool active; + bool route_started; + u32 link_rate; +}; + +struct dcpib_atc { + struct dcpib_aux aux; + struct dcpib_atc_port port[4]; + unsigned int nports; + /* the port the DCP drives, and the one a sink was found on */ + struct dcpib_atc_port *cur, *next; +}; + +static struct dcpib_atc_port *atc_cur(struct dcpib *dcp) +{ + return ((struct dcpib_atc *)dcp->phy_priv)->cur; +} + +static const u32 atc_rates[] = { + DCPIB_LINK_RATE_RBR, DCPIB_LINK_RATE_HBR, DCPIB_LINK_RATE_HBR2, + DCPIB_LINK_RATE_HBR3, +}; + +static void atc_update(struct dcpib_atc_port *atc, u32 offset, u32 mask, u32 value) +{ + u32 reg = readl(atc->base + offset); + + writel((reg & ~mask) | value, atc->base + offset); +} + +static int atc_poll(struct dcpib_atc_port *atc, u32 offset, u32 mask, u32 value) +{ + u32 reg; + + return readl_poll_timeout(atc->base + offset, reg, + (reg & mask) == value, 1, ATC_TIMEOUT_US); +} + +static int atc_route_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) +{ + if (!atc->route_started) + return 0; + atc_update(atc, ATC_XBAR + 0x3c, 1, 0); + atc_update(atc, ATC_XBAR, 1, 0); + atc_update(atc, ATC_XBAR + 0xc, 1, 0); + atc_update(atc, ATC_XBAR + 0x24, 0x100, 0); + udelay(1); + /* + * With the pipe powered off (the bootloader hands the display over + * that way) nothing acknowledges the stop; the route is idle then, so + * finish it anyway. + */ + if (atc_poll(atc, ATC_XBAR + 0x800, 1, 0) || + atc_poll(atc, ATC_XBAR + 0x808, 1, 0) || + atc_poll(atc, ATC_XBAR + 0x81c, 0x100, 0)) + dev_info(dcp->dev, "ATC%u: no crossbar stop acknowledgment\n", atc->index); + atc_update(atc, ATC_XBAR + 8, 1, 0); + atc_update(atc, ATC_XBAR + 0x20, 7, 0); + atc_update(atc, ATC_XBAR + 0x38, 0x700, 0); + atc_update(atc, ATC_XBAR + 4, 1, 1); + atc_update(atc, ATC_XBAR + 0x1c, 1, 1); + atc_update(atc, ATC_XBAR + 0x34, 0x100, 0x100); + atc->route_started = false; + dev_dbg(dcp->dev, "ATC%u: display route disabled\n", atc->index); + return 0; +} + +/* + * A source -> ATCn/DFP0 route, PCLK1: both DFP0 mux fields select the + * source (AppleT8142ATCDPXBAR::connect): DCP0 or an AP AUX controller. + */ +#define ATC_SEL_DCP0 0 +#define ATC_SEL_AUX0 9 /* UFP endpoint 5 + 4 (getMuxSelector) */ + +static int atc_route_start_sel(struct dcpib *dcp, struct dcpib_atc_port *atc, + u32 sel) +{ + if (atc->route_started) + return 0; + atc_update(atc, ATC_XBAR + 0x44, 0x00f00000, sel << 20); + atc_update(atc, ATC_XBAR + 0x44, 0x00000f00, sel << 8); + atc_update(atc, ATC_XBAR + 4, 1, 0); + atc_update(atc, ATC_XBAR + 0x1c, 1, 0); + atc_update(atc, ATC_XBAR + 0x34, 0x100, 0); + udelay(1); + if (atc_poll(atc, ATC_XBAR + 0x804, 1, 0) || + atc_poll(atc, ATC_XBAR + 0x818, 1, 0) || + atc_poll(atc, ATC_XBAR + 0x82c, 0x100, 0)) { + dev_err(dcp->dev, "ATC%u: crossbar reset acknowledgment timeout\n", atc->index); + return -ETIMEDOUT; + } + atc_update(atc, ATC_XBAR + 8, 1, 1); + atc_update(atc, ATC_XBAR + 0x20, 7, 1); + atc_update(atc, ATC_XBAR + 0x38, 0x700, 0x100); + atc_update(atc, ATC_XBAR + 0x48, 1, 0); + atc_update(atc, ATC_XBAR, 1, 1); + atc_update(atc, ATC_XBAR + 0xc, 1, 1); + atc_update(atc, ATC_XBAR + 0x24, 0x100, 0x100); + atc_update(atc, ATC_XBAR + 0x4c, 0x100, 0x100); + atc_update(atc, ATC_XBAR + 0x3c, 1, 1); + atc->route_started = true; + dev_dbg(dcp->dev, "ATC%u: source %u to local DFP0 route configured\n", atc->index, sel); + return 0; +} + +static int atc_route_start(struct dcpib *dcp, struct dcpib_atc_port *atc) +{ + return atc_route_start_sel(dcp, atc, ATC_SEL_DCP0); +} + +/* Common four-lane setup; the rate-dependent fields follow in atc_dp_start. */ +static const struct { + u32 offset, mask, value; +} atc_dp_setup[] = { + { 0x2044, 0xffff, 0x4b0 }, + { 0x4c, 0x3c0000, 0x3c0000 }, + { 0x4c80, 0x40, 0x40 }, + { 0xdc80, 0x40, 0x40 }, + { 0x4fd4, 0x2000000, 0x2000000 }, + { 0x4fd4, 0x1800000, 0x800000 }, + { 0xdfd4, 0x2000000, 0x2000000 }, + { 0xdfd4, 0x1800000, 0x800000 }, + { 0x4d84, 0x1c0000, 0 }, + { 0x4fd4, 1, 0 }, + { 0x4fd4, 8, 0 }, + { 0x4fd4, 2, 2 }, + { 0x4fd4, 0x10, 0x10 }, + { 0x8904, 0x1c0000, 0 }, + { 0x8800, 0x10000000, 0 }, + { 0x8800, 0x80000000, 0 }, + { 0x8800, 0x20000000, 0x20000000 }, + { 0x8804, 1, 1 }, + { 0xdd84, 0x1c0000, 0 }, + { 0xdfd4, 1, 0 }, + { 0xdfd4, 8, 0 }, + { 0xdfd4, 2, 2 }, + { 0xdfd4, 0x10, 0x10 }, + { 0x11904, 0x1c0000, 0 }, + { 0x11800, 0x10000000, 0 }, + { 0x11800, 0x80000000, 0 }, + { 0x11800, 0x20000000, 0x20000000 }, + { 0x11804, 1, 1 }, + { 0x3c04, 2, 2 }, + { 0x3c04, 1, 1 }, + { 0xcc04, 2, 2 }, + { 0xcc04, 1, 1 }, +}; + +/* Program the PMGR DP clock divider and wait for the change to settle. */ +static int atc_clock_write(struct dcpib_atc_port *atc, u32 divider) +{ + u32 reg = readl(atc->dp_clock); + + writel((reg & ~0x0f000000) | (divider << 24), atc->dp_clock); + return readl_poll_timeout(atc->dp_clock, reg, !(reg & BIT(30)), 1, + ATC_TIMEOUT_US); +} + +/* Stop the DP lanes: route, shim clock, then both PMAs (aura atc_dp_stop). */ +static int atc_dp_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) +{ + u32 reg; + + atc_route_stop(dcp, atc); + atc_update(atc, ATC_CFG + 0x14, 7, 7); + atc_update(atc, ATC_CFG + 0x18, 1, 0); + if (readl_poll_timeout(atc->base + ATC_CFG + 0x1c, reg, !(reg & 1), 1, + ATC_TIMEOUT_US)) { + dev_err(dcp->dev, "ATC%u: DPTX clock stop failed\n", atc->index); + return -ETIMEDOUT; + } + atc_update(atc, 0x2040, BIT(16), 0); + udelay(5); + atc_update(atc, 0x2000, BIT(15), 0); + atc_update(atc, 0x2000, BIT(13), 0); + atc_update(atc, 0x2000, BIT(14), 0); + atc_update(atc, 0x2000, BIT(2), 0); + atc_update(atc, 0x2000, BIT(3), BIT(3)); + atc_update(atc, 0xe10, BIT(2), BIT(2)); + atc_update(atc, 0xe08, BIT(29), BIT(29)); + /* Remove both PMA clock requests, then clamp and power down both lanes. */ + atc_update(atc, ATC_AON + 0x24, BIT(12) | BIT(16) | BIT(14) | BIT(18), 0); + udelay(1); + for (u32 offset = 0x1e18; offset <= 0x1e1c; offset += 4) { + atc_update(atc, offset, BIT(5), 0); + udelay(1); + atc_update(atc, offset, BIT(0), BIT(0)); + udelay(1); + atc_update(atc, offset, BIT(2), 0); + udelay(1); + atc_update(atc, offset, BIT(1), 0); + udelay(1); + } + atc->link_rate = 0; + return 0; +} + +/* Four-lane DP setup at rate index r (aura atc_phy_set_link_rate). */ +static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) +{ + static const u32 tx_ctrl[] = { 0x4eb0, 0x8b10, 0xdeb0, 0x11b10 }; + static const u32 wake_count[] = { 0xbb5, 0xbb7, 0xbb8, 0xbb9 }; + int ret; + + if (readl(atc->dp_clock) & BIT(30)) + return -EBUSY; + atc_update(atc, ATC_CFG + 0x14, 7, 0); + atc_update(atc, ATC_CFG + 0x18, 1, 1); + if (!r) { + atc_update(atc, 0xe10, BIT(2), BIT(2)); + atc_update(atc, 0xe08, BIT(29), BIT(29)); + } + for (u32 i = 0; i < 2; i++) { + u32 offset = 0x1e18 + 4 * i; + + atc_update(atc, ATC_AON + 0x24, BIT(12 + 2 * i), BIT(12 + 2 * i)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(16 + 2 * i), BIT(16 + 2 * i)); + udelay(1); + atc_update(atc, offset, BIT(1), BIT(1)); + udelay(1); + atc_update(atc, offset, BIT(2), BIT(2)); + udelay(1); + atc_update(atc, offset, BIT(0), 0); + udelay(1); + atc_update(atc, offset, BIT(5), BIT(5)); + udelay(2); + } + atc_update(atc, 0x2000, 0x380000, r << 19); + for (unsigned int i = 0; i < ARRAY_SIZE(atc_dp_setup); i++) + atc_update(atc, atc_dp_setup[i].offset, atc_dp_setup[i].mask, + atc_dp_setup[i].value); + for (u32 i = 0; i < 2; i++) { + atc_update(atc, 0x8684 + i * 0x9000, 3, r ? 0 : 1); + atc_update(atc, 0x4c80 + i * 0x9000, 0x30, r ? 0 : 0x10); + } + for (unsigned int i = 0; i < ARRAY_SIZE(tx_ctrl); i++) { + atc_update(atc, tx_ctrl[i], 0x7e07ff, 1); + atc_update(atc, tx_ctrl[i] - 0x14, 0x7f, r < 2 ? 0x65 : 0x40); + } + atc_update(atc, 0x2000, 0x70, 0x10); + atc_update(atc, 0x2000, BIT(13), BIT(13)); + atc_update(atc, 0x2044, 0xffff0000, wake_count[r] << 16); + atc_update(atc, atc->swap ? 0x89f0 : 0x119f0, BIT(14), BIT(14)); + atc_update(atc, 0x2000, BIT(2), BIT(2)); + atc_update(atc, 0x2000, BIT(3), BIT(3)); + atc_update(atc, 0x2040, BIT(16), BIT(16)); + + ret = atc_clock_write(atc, 10 - r); + if (ret) { + dev_err(dcp->dev, "ATC%u: DP clock change timeout\n", atc->index); + return ret; + } + ret = atc_route_start(dcp, atc); + if (ret) + return ret; + atc->link_rate = atc_rates[r]; + dev_info(dcp->dev, "ATC%u: four-lane DPTX setup at rate %#x\n", atc->index, + atc->link_rate); + return 0; +} + +/* + * The power dependencies, in order: the ATC's USB AON (PS +0x100), its common + * PSD, then its two DP PS registers (+0, +0x20), with the values they idle at + * (ATC3: PS 0x1c0, PSD 58, PS 0xc0, 0xe0). + */ +#define ATC_PSD_TARGET 0x90 +#define ATC_PSD_STATE 0x80 +static const u32 atc_ps_offset[] = { 0x100, 0, 0x0, 0x20 }; +static const u32 atc_ps_idle[] = { 0x300, 6, 0x244, 0x244 }; + +static int atc_psd_wait(struct dcpib_atc_port *atc, u32 state) +{ + u32 reg; + + /* + * Only the state: the acknowledge bit aura also waits for stays clear + * when Linux switches the PSD, in either direction. + */ + return readl_poll_timeout(atc->psd + ATC_PSD_STATE, reg, + (reg & 7) == state, 1, ATC_TIMEOUT_US); +} + +static int atc_gate(struct dcpib_atc_port *atc, unsigned int i, bool on) +{ + u32 value = on ? (atc_ps_idle[i] & 0xfffffcf0) | 15 : atc_ps_idle[i]; + u32 reg; + + /* Already up (the bootloader's or an earlier activation's). */ + if (on && (i == 1 ? !(readl(atc->psd + ATC_PSD_STATE) & 7) : + (readl(atc->ps + atc_ps_offset[i]) & 0xf0) == 0xf0)) + return 0; + if (on) + atc->owned |= BIT(i); + else + atc->owned &= ~BIT(i); + if (i == 1) { + writel(on ? 0 : atc_ps_idle[i], atc->psd + ATC_PSD_TARGET); + return atc_psd_wait(atc, on ? 0 : atc_ps_idle[i]); + } + writel(value, atc->ps + atc_ps_offset[i]); + return readl_poll_timeout(atc->ps + atc_ps_offset[i], reg, + (reg & 0xf0) == ((value & 15) << 4), 1, + ATC_TIMEOUT_US); +} + +static void atc_apply_tunables(struct dcpib_atc_port *atc, unsigned int which) +{ + const __be32 *t = atc->tunable[which]; + + for (int i = 0; i + 3 <= atc->tunable_len[which]; i += 3) + atc_update(atc, be32_to_cpu(t[i]), be32_to_cpu(t[i + 1]), + be32_to_cpu(t[i + 2])); +} + +/* + * Cold start: the power dependencies, the common block and AUX (aura + * atc_gates_enable and atc_phy_activate), then the DP lanes at HBR. + */ +static int atc_activate(struct dcpib *dcp) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + void __iomem *cfg = atc->base + ATC_CFG; + unsigned int gates = 0; + u32 reg; + + if (atc->active) + return 0; + if (!atc->tunable[0] || !atc->tunable[1]) + return -EOPNOTSUPP; + for (; gates < ARRAY_SIZE(atc_ps_idle); gates++) + if (atc_gate(atc, gates, true)) + goto fail; + if (readl(cfg) != 4 || (readl(cfg + 4) & 3) || readl(cfg + 0x30)) + goto fail; + writel(readl(cfg + 0x30) | BIT(0), cfg + 0x30); + udelay(1); + writel(readl(cfg) | BIT(0), cfg); + if (readl_poll_timeout(cfg + 4, reg, reg & BIT(0), 1, ATC_TIMEOUT_US)) + goto fail; + writel(readl(cfg) | BIT(1), cfg); + if (readl_poll_timeout(cfg + 4, reg, reg & BIT(1), 1, ATC_TIMEOUT_US)) + goto fail; + writel(readl(cfg) & ~BIT(2), cfg); + udelay(1); + writel(readl(cfg) | BIT(3), cfg); + + atc_apply_tunables(atc, 0); + /* aciophy_xbar_config(mode=3): both PMAs carry DisplayPort. */ + atc_update(atc, 0x4c, 0x1f, 0x14); + atc_update(atc, 0x4c, 0x3ffe0, atc->swap ? 0x100 : 0x22000); + atc_apply_tunables(atc, 1); + atc_update(atc, ATC_CFG + 8, BIT(1), atc->swap ? BIT(1) : 0); + writel(readl(cfg) | BIT(4), cfg); + if ((readl(cfg) & 0x1f) != 0x1b) + goto fail; + /* aciophy_aux_init: release small/big sleep, then the AUX clamp. */ + atc_update(atc, ATC_AON + 0x24, BIT(8), BIT(8)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(6), BIT(6)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(10), 0); + udelay(1); + atc->active = true; + dev_info(dcp->dev, "ATC%u: common PHY and AUX up from cold\n", atc->index); + /* + * As aura's activation: the lanes start at HBR right away. From cold, + * AUX only works with the DP PLL and PMAs running (without them the + * firmware reports DEVICE_NOT_RESPONDING); the firmware switches to + * its rate afterwards. + */ + return atc_dp_start(dcp, atc, 1); +fail: + dev_err(dcp->dev, "ATC%u: cold start failed (gates %u, cfg %#x/%#x)\n", atc->index, + gates, gates == ARRAY_SIZE(atc_ps_idle) ? readl(cfg) : 0, + gates == ARRAY_SIZE(atc_ps_idle) ? readl(cfg + 4) : 0); + return -EIO; +} + +/* Power the PHY down (aura atc_phy_deactivate), dependencies included. */ +static int atc_deactivate(struct dcpib *dcp) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + void __iomem *cfg = atc->base + ATC_CFG; + int ret = 0; + u32 reg; + + if (!atc->active) + return 0; + if (atc->link_rate && atc_dp_stop(dcp, atc)) { + dev_err(dcp->dev, "ATC%u: DP stop failed\n", atc->index); + return -EIO; + } + atc_route_stop(dcp, atc); + atc_update(atc, ATC_AON + 0x24, BIT(10), BIT(10)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(6), 0); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(8), 0); + udelay(1); + writel(readl(cfg) & ~BIT(4), cfg); + udelay(1); + writel(readl(cfg) & ~BIT(3), cfg); + writel(readl(cfg) | BIT(2), cfg); + writel(readl(cfg) & ~BIT(1), cfg); + if (readl_poll_timeout(cfg + 4, reg, !(reg & BIT(1)), 1, ATC_TIMEOUT_US)) { + dev_err(dcp->dev, "ATC%u: big-sleep entry timeout\n", atc->index); + ret = -ETIMEDOUT; + } + writel(readl(cfg) & ~BIT(0), cfg); + if (readl_poll_timeout(cfg + 4, reg, !(reg & BIT(0)), 1, ATC_TIMEOUT_US)) { + dev_err(dcp->dev, "ATC%u: small-sleep entry timeout\n", atc->index); + ret = -ETIMEDOUT; + } + writel(readl(cfg + 0x30) & ~BIT(0), cfg + 0x30); + atc->active = false; + /* + * Then the power dependencies it powered up: the next activation starts + * it cold. The USB controller of a port keeps the ones it uses. + */ + for (int i = ARRAY_SIZE(atc_ps_idle) - 1; i >= 0; i--) + if ((atc->owned & BIT(i)) && atc_gate(atc, i, false)) + ret = -ETIMEDOUT; + dev_info(dcp->dev, "ATC%u: powered down: %d\n", atc->index, ret); + return ret; +} + +static int atc_set_link_rate(struct dcpib *dcp, u32 rate) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + + u32 r; + int ret; + + /* The firmware drops the link (rate 0) before it retrains. */ + if (!rate || rate == atc->link_rate) + return 0; + for (r = 0; r < ARRAY_SIZE(atc_rates); r++) + if (atc_rates[r] == rate) + break; + if (r == ARRAY_SIZE(atc_rates) || !atc->active) + return -EINVAL; + dev_info(dcp->dev, "ATC%u: link rate %#x, was %#x\n", atc->index, rate, atc->link_rate); + if (atc->link_rate) { + ret = atc_dp_stop(dcp, atc); + if (ret) + return ret; + } + return atc_dp_start(dcp, atc, r); +} + +static int atc_set_route(struct dcpib *dcp, bool enable) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + + if (!enable) + return atc_route_stop(dcp, atc); + if (!atc->active) + return -ENODEV; + if (atc_route_start(dcp, atc)) + return -EIO; + mdelay(5); + return 0; +} + +/* + * Matching T8152 fallback table, indexed by voltage * 4 + pre-emphasis; the + * ADT has no rate-specific dp-training-table, so it serves every rate. + */ +static const u32 atc_drive_presets[16] = { + 0x025, 0x420, 0x717, 0x90f, 0x019, 0x397, 0x78f, 0x025, + 0x011, 0x38f, 0x025, 0x025, 0x000, 0x025, 0x025, 0x025, +}; + +static int atc_set_drive(struct dcpib *dcp, + const struct dcpib_drive_settings *settings, u32 count) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + u32 presets[4]; + + if (!count) + return 0; + if (count > 4 || !atc->active || !atc->link_rate) + return -EINVAL; + /* Validate the entire request before changing any lane. */ + for (u32 i = 0; i < count; i++) { + u32 v = le32_to_cpu(settings[i].voltage); + u32 e = le32_to_cpu(settings[i].pre_emphasis); + + if (settings[i].format || v > 3 || e > 3 || v + e > 3) + return -EINVAL; + presets[i] = atc_drive_presets[v * 4 + e]; + } + for (u32 i = 0; i < count; i++) { + u32 pma = (i / 2) ^ !atc->swap; + /* Even DP lanes use the PMA RX pair, odd lanes its TX pair. */ + u32 offset = ((i & 1) ? 0x4eb0 : 0x8b10) + pma * 0x9000; + u32 preset = presets[i]; + u32 control = 1 | (((preset >> 13) & 0x3f) << 17) | + (((preset >> 7) & 0x3f) << 5); + + atc_update(atc, offset, 0x7e07ff, control); + atc_update(atc, offset - 0x14, 0x7f, (preset & 0x3f) | 0x40); + } + return 0; +} + +static void atc_set_orientation(struct dcpib *dcp, bool flipped) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + + /* Applied by the next cold start; a running PHY keeps its own. */ + if (atc->active && atc->swap != flipped) + dev_warn(dcp->dev, "ATC%u: orientation changed while active\n", atc->index); + atc->swap = flipped; +} + +/* + * The sink's EDID through the AP AUX controller aux0, which reaches the ATC + * through crossbar UFP aux0 like the DCP: the DCP's route comes down for + * the read, so this runs while the firmware does no AUX itself (display + * off, HPD not asserted yet). + */ +static int atc_read_edid(struct dcpib *dcp, u8 *buf, size_t size) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + bool was_started = atc->route_started; + int ret; + + if (!atc->active || !atc->aux->regs) + return -ENODEV; + ret = dcpib_aux_init(dcp, atc->aux); + if (ret) + return ret; + atc_route_stop(dcp, atc); + ret = atc_route_start_sel(dcp, atc, ATC_SEL_AUX0); + if (!ret) + ret = dcpib_aux_read_edid(dcp, atc->aux, buf, size); + atc_route_stop(dcp, atc); + if (was_started) + atc_route_start(dcp, atc); + return ret; +} + +/* + * 1 with a sink on one of the ports: the current one first, then the + * others; select() switches to a port found that way. + */ +static int atc_detect(struct dcpib *dcp, bool *flipped) +{ + struct dcpib_atc *atc = dcp->phy_priv; + int ret = dcpib_pd_sink(atc->cur->pd, flipped); + + atc->next = atc->cur; + if (ret) + return ret; + for (unsigned int i = 0; i < atc->nports; i++) { + struct dcpib_atc_port *port = &atc->port[i]; + + if (port == atc->cur || dcpib_pd_sink(port->pd, flipped) <= 0) + continue; + atc->next = port; + /* A plug the other port's HPD state does not show yet. */ + dcp->hpd = 0; + return 1; + } + return 0; +} + +/* + * Drive the port a sink was found on: power the old one down and connect + * the DPTX port to the new one's display crossbar endpoint. + */ +static void atc_select(struct dcpib *dcp) +{ + struct dcpib_atc *atc = dcp->phy_priv; + struct dcpib_atc_port *port = atc->next; + + if (!port || port == atc->cur) + return; + if (atc->cur->active) + atc_deactivate(dcp); + dev_info(dcp->dev, "USB-C display on ATC%u now, was ATC%u\n", + port->index, atc->cur->index); + atc->cur = port; + dcp->pd = port->pd; + dcp->dcp_output = port->dfp; + if (dcpib_dptx_connect(dcp, 0)) + dev_err(dcp->dev, "DPTX connect to ATC%u failed\n", port->index); +} + +static const struct dcpib_phy_ops atc_ops = { + .activate = atc_activate, + .deactivate = atc_deactivate, + .set_link_rate = atc_set_link_rate, + .set_drive = atc_set_drive, + .set_route = atc_set_route, + .set_orientation = atc_set_orientation, + .read_edid = atc_read_edid, + .detect = atc_detect, + .select = atc_select, + .max_link_rate = DCPIB_LINK_RATE_HBR2, + /* + * Modes up to 1920x1080@60 and 1600x1200@60 (and 2560x1440@30) show, + * 1920x1200@60 and anything faster stay black at HBR2 with no error: + * the DCP's pixel clock on the ATC path tops out between 162 and + * about 190 MHz with the firmware on its iBoot interface. + */ + .max_pixel_rate = 130000000, + /* + * 720x480@60 and 720x576@50 (27 MHz) show, 640x480@60 (25.2 MHz) + * stays black here while HDMI shows it. + */ + .min_pixel_rate = 20000000, +}; + +/* PMGR registers, inside blocks their power domain driver has claimed. */ +static void __iomem *atc_map(struct dcpib *dcp, struct device_node *np, + const char *name) +{ + int i = of_property_match_string(np, "reg-names", name); + struct resource res; + + if (i < 0 || of_address_to_resource(np, i, &res)) + return NULL; + return devm_ioremap(dcp->dev, res.start, resource_size(&res)); +} + +static int atc_port_init(struct dcpib *dcp, struct dcpib_atc *atc, + struct device_node *np, void __iomem *dp_clock) +{ + struct dcpib_atc_port *port = &atc->port[atc->nports]; + u32 cfg, r; + + port->base = atc_map(dcp, np, "atc"); + port->ps = atc_map(dcp, np, "atc-ps"); + port->psd = atc_map(dcp, np, "atc-psd"); + if (!port->base || !port->ps || !port->psd) + return -ENOMEM; + port->pd = dcpib_pd_get(dcp, np); + if (IS_ERR_OR_NULL(port->pd)) + return port->pd ? PTR_ERR(port->pd) : -ENODEV; + /* The node without ports is ATC3's (J873g back-right). */ + port->dfp = 3; + of_property_read_u32(np, "apple,dfp-endpoint", &port->dfp); + port->index = port->dfp; + port->dp_clock = dp_clock; + port->aux = &atc->aux; + port->tunable[0] = of_get_property(np, "apple,tunable-pre", + &port->tunable_len[0]); + port->tunable[1] = of_get_property(np, "apple,tunable-post", + &port->tunable_len[1]); + port->tunable_len[0] /= sizeof(__be32); + port->tunable_len[1] /= sizeof(__be32); + atc->nports++; + + /* + * The PHY block hangs the bus while it is power-gated: look at it only + * with its DP dependencies and the common PSD up. + */ + if ((readl(port->ps) & 0xf0) != 0xf0 || + (readl(port->psd + ATC_PSD_STATE) & 7)) { + dev_info(dcp->dev, "ATC%u: powered down\n", port->index); + return 0; + } + /* Common block out of reset and AUX up, as aura's activation leaves it. */ + cfg = readl(port->base + ATC_CFG); + port->active = (cfg & 0x1f) == 0x1b; + port->swap = (readl(port->base + 0x4c) & 0x3ffe0) == 0x100; + port->route_started = (readl(port->base + ATC_XBAR) & 1) && + (readl(port->base + ATC_XBAR + 0x3c) & 1); + r = (readl(port->base + 0x2000) >> 19) & 7; + if (port->active && (readl(port->base + 0x2040) & BIT(16)) && + r < ARRAY_SIZE(atc_rates)) + port->link_rate = atc_rates[r]; + /* The bootloader's display: its dependencies are the display's. */ + if (port->active) + port->owned = GENMASK(ARRAY_SIZE(atc_ps_idle) - 1, 0); + dev_info(dcp->dev, + "ATC%u: inherited state: active %d, rate %#x, route %d, reversed %d (cfg %#x)\n", + port->index, port->active, port->link_rate, port->route_started, + port->swap, cfg); + return 0; +} + +int dcpib_atc_init(struct dcpib *dcp) +{ + struct device_node *np = dcp->dev->of_node; + void __iomem *dp_clock; + struct dcpib_atc *atc; + bool flipped; + int ret; + + atc = devm_kzalloc(dcp->dev, sizeof(*atc), GFP_KERNEL); + if (!atc) + return -ENOMEM; + dp_clock = atc_map(dcp, np, "dp-clock"); + if (!dp_clock) + return -ENOMEM; + /* AUX output select 9: the crossbar's UFP aux0 */ + dcpib_aux_probe(dcp, &atc->aux, 9); + + /* One child per USB-C port, or the node itself for ATC3 alone. */ + for_each_child_of_node_scoped(np, child) { + if (!of_property_present(child, "apple,dfp-endpoint")) + continue; + if (atc->nports == ARRAY_SIZE(atc->port)) + break; + ret = atc_port_init(dcp, atc, child, dp_clock); + if (ret) + return ret; + } + if (!atc->nports) { + ret = atc_port_init(dcp, atc, np, dp_clock); + if (ret) + return ret; + } + + /* The bootloader's display port, else one with a sink, else the first. */ + atc->cur = &atc->port[0]; + for (unsigned int i = 0; i < atc->nports; i++) { + if (atc->port[i].active) { + atc->cur = &atc->port[i]; + goto found; + } + } + for (unsigned int i = 0; i < atc->nports; i++) { + if (dcpib_pd_sink(atc->port[i].pd, &flipped) > 0) { + atc->cur = &atc->port[i]; + break; + } + } +found: + atc->next = atc->cur; + dcp->phy = &atc_ops; + dcp->phy_priv = atc; + dcp->pd = atc->cur->pd; + dcp->dcp_output = atc->cur->dfp; + dev_info(dcp->dev, "USB-C display on ATC%u (%u ports)\n", atc->cur->index, + atc->nports); + return 0; +} diff --git a/drivers/gpu/drm/apple_dcpib/aux.c b/drivers/gpu/drm/apple_dcpib/aux.c new file mode 100644 index 0000000000000..c8c6bf9ce3137 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/aux.c @@ -0,0 +1,196 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The AP's DisplayPort AUX controllers aux0/aux1 (ADT dptx0-aux, dptx1-aux; + * macOS AppleAUXDPTX): Analogix-derived DPTX cores with Apple's request + * framing (AppleDPTXController::setupAuxTransaction, readDPCDGated). They + * attach to the display crossbar as UFP endpoints 5 and 6; the phy code + * routes one to its port for the time of a read. Used for the sink's EDID, + * which the DCP firmware does not hand out on its iBoot interface. + */ + +#include +#include +#include +#include +#include +#include + +#include + +#include "dcpib.h" + +#define AUX_TIMEOUT_US 10000 +#define AUX_SEL 0x000 /* output: 9 crossbar UFP aux0, 0x10 lpdptx phy */ +#define AUX_FUNC_EN_2 0x01c +#define AUX_FUNC_EN_N BIT(2) +#define AUX_HW_RETRY 0x390 +#define AUX_INT_STA 0x3dc +#define AUX_REPLY BIT(1) +#define AUX_ERROR BIT(0) +#define AUX_CH_STA 0x780 +#define AUX_DEFER_CTL 0x788 +#define AUX_RX_COMM 0x78c +#define AUX_BUF_CTL 0x790 +#define AUX_BUF_CLR BIT(9) +#define AUX_BUF_COUNT GENMASK(8, 0) +#define AUX_LEN 0x794 +#define AUX_ADDR_7_0 0x798 +#define AUX_ADDR_15_8 0x79c +#define AUX_CMD_ADDR 0x7a0 /* request in [7:4], address [19:16] */ +#define AUX_CTL 0x7a4 +#define AUX_GO BIT(0) +#define AUX_ADDR_ONLY BIT(1) +#define AUX_DATA 0xc00 /* one byte per word */ +#define AUX_MAX 16 + +#define AUX_NATIVE_WRITE 0x80 +#define AUX_I2C_WRITE 0x00 +#define AUX_I2C_READ 0x10 +#define AUX_I2C_MOT 0x40 +#define DDC_ADDR 0x50 +#define DPCD_SET_POWER 0x600 +#define DP_SET_POWER_D0 1 + +static void aux_update(void __iomem *reg, u32 mask, u32 value) +{ + writel((readl(reg) & ~mask) | value, reg); +} + +int dcpib_aux_init(struct dcpib *dcp, struct dcpib_aux *aux) +{ + u32 reg; + + /* PMGR GLOBAL_AUX_CTRLn */ + aux_update(aux->ps, 0xf, 0xf); + if (readl_poll_timeout(aux->ps, reg, ((reg >> 4) & 0xf) == 0xf, 1, + AUX_TIMEOUT_US)) { + dev_err(dcp->dev, "AUX: controller does not power up\n"); + return -ETIMEDOUT; + } + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, AUX_FUNC_EN_N); + udelay(10); + aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, 0); + writel(3 << 8, aux->regs + AUX_HW_RETRY); + writel(BIT(7) | 1, aux->regs + AUX_DEFER_CTL); + aux_update(aux->regs + AUX_SEL, 0x3f, aux->sel); + return 0; +} + +/* One AUX request of up to 16 bytes; returns the bytes transferred. */ +static int aux_xfer(struct dcpib_aux *aux, u32 cmd, u32 addr, u8 *buf, + u32 len, bool write) +{ + u32 sta, n; + int i; + + for (int tries = 0; tries < 7; tries++) { + writel(AUX_BUF_CLR, aux->regs + AUX_BUF_CTL); + writel(len ? len - 1 : 0, aux->regs + AUX_LEN); + writel(addr & 0xff, aux->regs + AUX_ADDR_7_0); + writel((addr >> 8) & 0xff, aux->regs + AUX_ADDR_15_8); + writel((cmd & 0xf0) | ((addr >> 16) & 0xf), aux->regs + AUX_CMD_ADDR); + aux_update(aux->regs + AUX_CTL, AUX_ADDR_ONLY, len ? 0 : AUX_ADDR_ONLY); + for (i = 0; write && i < len; i++) + writel(buf[i], aux->regs + AUX_DATA + 4 * i); + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + aux_update(aux->regs + AUX_CTL, AUX_GO, AUX_GO); + if (readl_poll_timeout(aux->regs + AUX_INT_STA, sta, + sta & (AUX_REPLY | AUX_ERROR), 10, 20000)) + return -ETIMEDOUT; + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + if ((sta & AUX_ERROR) || (readl(aux->regs + AUX_CH_STA) & 0xf)) + return -EIO; + /* [3:2] I2C and [1:0] AUX reply: 0 ACK, 1 NACK, 2 DEFER */ + sta = readl(aux->regs + AUX_RX_COMM); + if (sta & 0x5) + return -ENXIO; + if (sta & 0xa) { + usleep_range(500, 1000); + continue; + } + if (write) + return len; + n = min(readl(aux->regs + AUX_BUF_CTL) & AUX_BUF_COUNT, len); + for (i = 0; i < n; i++) + buf[i] = readl(aux->regs + AUX_DATA + 4 * i); + return n; + } + return -EBUSY; +} + +/* DDC over I2C-over-AUX: offset 0, then 16-byte reads up to @size. */ +static int aux_ddc_read(struct dcpib_aux *aux, u8 *buf, size_t size) +{ + u8 offset = 0; + size_t done = 0; + int ret; + + ret = aux_xfer(aux, AUX_I2C_WRITE | AUX_I2C_MOT, DDC_ADDR, + &offset, 1, true); + while (ret >= 0 && done < size) { + ret = aux_xfer(aux, AUX_I2C_READ | AUX_I2C_MOT, DDC_ADDR, + buf + done, min_t(size_t, size - done, AUX_MAX), + false); + if (ret > 0) + done += ret; + else if (!ret) + ret = -EIO; + } + /* End the I2C transaction with an address-only read without MOT. */ + aux_xfer(aux, AUX_I2C_READ, DDC_ADDR, NULL, 0, false); + return ret < 0 ? ret : done; +} + +/* + * The EDID over DDC, the base block and its extensions; the sink answers + * AUX only some time after the path is up, and a sink just plugged in a + * little later still. + */ +int dcpib_aux_read_edid(struct dcpib *dcp, struct dcpib_aux *aux, u8 *buf, + size_t size) +{ + int ret = -EIO, ext; + + u8 d0 = DP_SET_POWER_D0; + + for (int i = 0; i < 30 && (ret == -EIO || ret == -ETIMEDOUT); i++) { + msleep(i ? 100 : 20); + /* + * A sink left in D3 (after an unplug) NACKs DDC: wake it + * first, as the DP spec asks before AUX use. + */ + ret = aux_xfer(aux, AUX_NATIVE_WRITE, DPCD_SET_POWER, &d0, 1, true); + if (ret < 0) + continue; + usleep_range(1000, 2000); + ret = aux_ddc_read(aux, buf, min_t(size_t, size, EDID_LENGTH)); + } + if (ret != EDID_LENGTH) + return ret < 0 ? ret : -EIO; + ext = min_t(size_t, buf[0x7e], size / EDID_LENGTH - 1); + return ext ? aux_ddc_read(aux, buf, (1 + ext) * EDID_LENGTH) : ret; +} + +/* The optional "aux" and "aux-ps" (PMGR, mapped without claiming) regs. */ +/* The controller named by np's "aux" and "aux-ps" regs (np need not be dcp's). */ +void dcpib_aux_probe_node(struct dcpib *dcp, struct dcpib_aux *aux, u32 sel, + struct device_node *np) +{ + int ps = of_property_match_string(np, "reg-names", "aux-ps"); + int regs = of_property_match_string(np, "reg-names", "aux"); + struct resource res; + + aux->sel = sel; + if (ps < 0 || regs < 0 || of_address_to_resource(np, ps, &res)) + return; + aux->ps = devm_ioremap(dcp->dev, res.start, resource_size(&res)); + aux->regs = devm_of_iomap(dcp->dev, np, regs, NULL); + if (IS_ERR(aux->regs) || !aux->ps) + aux->regs = NULL; +} + +void dcpib_aux_probe(struct dcpib *dcp, struct dcpib_aux *aux, u32 sel) +{ + dcpib_aux_probe_node(dcp, aux, sel, dcp->dev->of_node); +} diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h new file mode 100644 index 0000000000000..b7449e7a3b2f0 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -0,0 +1,334 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple DCP display driver on the iBoot interface (T8152). + * + * The T8152 DCP firmware (AppleDCP-1317) offers a small "disp0-service", the + * interface iBoot and aura use, next to the full IOMobileFramebuffer protocol. + * This driver uses only that service, the DPTX port service the firmware + * calls back into for the PHY and the DPAV controller services it expects to + * be opened, all over AFKEPV2. It is a port of aura's src/afk.c, + * src/dcp_iboot.c, src/dcp/dptx_port_ep.c and src/dcp/atc_phy.c. + */ +#ifndef __APPLE_DCPIB_H__ +#define __APPLE_DCPIB_H__ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +struct dcpib; +struct dcpib_ep; +struct dcpib_service; +struct spmi_device; +struct drm_edid; + +#define DCPIB_EP_IBOOT 0x23 +#define DCPIB_EP_DPAV 0x24 +#define DCPIB_EP_DPTX 0x2a +#define DCPIB_FIRST_EP 0x20 +#define DCPIB_NR_EPS 0x10 + +#define DCPIB_MAX_SERVICES 8 + +/* IOReturn values the firmware understands. */ +#define KIO_RETURN_SUCCESS 0 +#define KIO_RETURN_ERROR 0xe00002bcU +#define KIO_RETURN_BAD_ARG 0xe00002c2U +#define KIO_RETURN_UNSUPPORTED 0xe00002c7U +#define KIO_RETURN_NOT_READY 0xe00002d8U + +/* DPCD link rates in units of 0.27 Gbps */ +#define DCPIB_LINK_RATE_RBR 0x06 +#define DCPIB_LINK_RATE_HBR 0x0a +#define DCPIB_LINK_RATE_HBR2 0x14 +#define DCPIB_LINK_RATE_HBR3 0x1e + +struct dcpib_dma { + void *cpu; + dma_addr_t iova; + size_t size; +}; + +struct dcpib_service_ops { + /* Firmware-initiated standard service call; returns an IOReturn. */ + u32 (*call)(struct dcpib_service *service, u16 group, u32 command, + const void *data, size_t data_size, void *reply, + size_t reply_size); +}; + +struct dcpib_service { + struct dcpib_ep *ep; + const struct dcpib_service_ops *ops; + char name[32]; + u16 interface; + unsigned int unit; + void *cookie; +}; + +struct dcpib_ring { + bool ready; + u32 *rptr; + u32 *wptr; + void *buf; + u32 bufsz; + u32 block; +}; + +struct dcpib_ep { + struct dcpib *dcp; + u8 ep; + const struct dcpib_service_ops *ops; + + struct dcpib_dma ring; + u16 tag; + struct dcpib_ring tx, rx; + struct dcpib_dma txbuf, rxbuf; + + struct completion started; + struct completion stopped; + struct work_struct rx_work; + + /* Serialises TX ring writes and the sequence number. */ + struct mutex tx_lock; + u8 seq; + + struct dcpib_service services[DCPIB_MAX_SERVICES]; + unsigned int nr_services; + unsigned int expected; + struct completion services_done; + + /* One outstanding AP command at a time. */ + struct mutex cmd_lock; + bool cmd_waiting; + u16 cmd_interface; + u8 cmd_type; + u8 cmd_id; + u8 next_cmd_id; + void *cmd_out; + size_t cmd_out_len; + int cmd_ret; + struct completion cmd_done; +}; + +struct dcpib_timing_mode { + __le32 valid; + __le32 width; + __le32 height; + __le32 fps; /* 16.16 */ + u8 pad[8]; +} __packed; + +struct dcpib_color_mode { + __le32 valid; + __le32 colorimetry; + __le32 eotf; + __le32 encoding; + __le32 bpp; + u8 pad[4]; +} __packed; + +struct dcpib_drive_settings { + __le32 format; + __le32 voltage; + __le32 pre_emphasis; +} __packed; + +/* The phy behind the DCP's DPTX port. */ +struct dcpib_phy_ops { + int (*activate)(struct dcpib *dcp); + int (*deactivate)(struct dcpib *dcp); + int (*set_link_rate)(struct dcpib *dcp, u32 rate); /* DPCD units */ + int (*set_lane_count)(struct dcpib *dcp, u32 lanes); /* optional */ + int (*set_drive)(struct dcpib *dcp, + const struct dcpib_drive_settings *settings, u32 count); + int (*set_route)(struct dcpib *dcp, bool enable); + /* optional: plug orientation for the next activation */ + void (*set_orientation)(struct dcpib *dcp, bool flipped); + /* optional: the sink's EDID, returns its length */ + int (*read_edid)(struct dcpib *dcp, u8 *buf, size_t size); + /* + * optional: 1 with a sink on one of the phy's ports, 0 without; the + * port it found is taken by select() in the plug path + */ + int (*detect)(struct dcpib *dcp, bool *flipped); + void (*select)(struct dcpib *dcp); + u32 max_link_rate; /* DPCD units */ + /* active pixels per second the path scans out, 0 if not limited */ + u64 min_pixel_rate, max_pixel_rate; +}; + +struct dcpib_port { + struct dcpib_service *service; + u32 link_rate; /* DPCD units */ + u32 lanes; + /* lanes of the last training, kept while the link is down */ + u32 trained_lanes; + /* last drive settings the firmware set, for GET_DRIVE_SETTINGS */ + struct dcpib_drive_settings drive[4]; + u32 drive_count; +}; + +struct dcpib { + struct device *dev; + struct drm_device drm; + struct apple_rtkit *rtk; + struct workqueue_struct *wq; + + struct dcpib_ep *eps[DCPIB_NR_EPS]; + struct dcpib_ep *iboot_ep; + struct dcpib_ep *dpav_ep; + /* the sink's EDID, read by the phy (NULL if unavailable) */ + const struct drm_edid *edid; + struct dcpib_ep *dptx_ep; + struct dcpib_service *iboot; + struct dcpib_port port[2]; + + /* The scanout DART's own device and domain (see dcpib_scanout_init). */ + struct platform_device *scanout; + struct iommu_domain *scanout_dom; + + /* + * Scanout buffers (dcpib_boot_surface), each for the largest mode: a + * frame is copied into one not on screen, which SET_SURFACE then shows. + * Copying into the buffer being scanned out tore every frame. Three, so + * the one written next left the screen a frame ago. + */ +#define DCPIB_SCANOUT_BUFS 3 + struct dcpib_dma scan[DCPIB_SCANOUT_BUFS]; + /* their pages write-combined: the pipe does not snoop the CPU caches */ + void *scan_wc[DCPIB_SCANOUT_BUFS]; + /* their addresses in the display pipe's DART (dcpib_scan_free_dva) */ + dma_addr_t scan_dva[DCPIB_SCANOUT_BUFS]; + /* scan[front] is on screen (or set as the surface next power on) */ + unsigned int front; + /* the part of the current picture scan[i] does not hold yet */ + struct drm_rect stale[DCPIB_SCANOUT_BUFS]; + /* when scan[i] stopped being the requested surface */ + ktime_t retired[DCPIB_SCANOUT_BUFS]; + /* the last SET_SURFACE of a new buffer */ + ktime_t last_swap; + /* + * A frame written within one refresh of the last swap waits in + * scan[pending] (-1: none) for swap_timer, at most one swap per + * refresh; a newer frame overwrites it. + */ + int pending; + u32 pending_w, pending_h, pending_pitch; + struct hrtimer swap_timer; + struct work_struct swap_work; + u32 boot_w, boot_h, boot_stride; + + const struct dcpib_phy_ops *phy; + void *phy_priv; + /* display-crossbar DFP endpoint the DCP drives */ + u32 dcp_output; + /* optional sink HPD line (J873g HDMI), polled; last level seen */ + struct gpio_desc *hpd_gpio; + int hpd; + /* USB-C: the PD controller of the port in use, polled the same way */ + struct spmi_device *pd; + /* HDMI phy: DCPEXT0, or the main DCP on the bootloader's HDMI-only route */ + bool hdmi; + u32 die; + + /* iBoot state below, under lock */ + struct mutex lock; + bool powered; + struct dcpib_timing_mode *tmodes; + unsigned int nr_tmodes; + struct dcpib_color_mode *cmodes; + unsigned int nr_cmodes; + struct dcpib_timing_mode cur_mode; + bool mode_set; + /* SET_MODE of cur_mode failed; the next plug sets it again */ + bool mode_failed; + /* USB-C: re-enter DP alt mode when the sink stopped answering */ + struct work_struct pd_reset_work; + unsigned long pd_reset_time; + + struct drm_plane plane; + struct drm_crtc crtc; + struct drm_encoder encoder; + struct drm_connector connector; +}; + +static inline struct dcpib *to_dcpib(struct drm_device *drm) +{ + return container_of(drm, struct dcpib, drm); +} + +/* afk.c */ +struct dcpib_ep *dcpib_ep_start(struct dcpib *dcp, u8 ep, + const struct dcpib_service_ops *ops, + unsigned int expected); +void dcpib_ep_stop(struct dcpib_ep *ep); +void dcpib_ep_recv(struct dcpib_ep *ep, u64 message); +int dcpib_command(struct dcpib_service *service, u8 type, const void *tx, + size_t txlen, void *rx, size_t *rxlen); +int dcpib_service_call(struct dcpib_service *service, u16 group, u32 command, + const void *data, size_t data_len, size_t data_pad, + void *output, size_t output_len, size_t output_pad); +int dcpib_dma_alloc(struct dcpib *dcp, struct dcpib_dma *dma, size_t size); +void dcpib_dma_free(struct dcpib *dcp, struct dcpib_dma *dma); + +/* iboot.c */ +int dcpib_iboot_init(struct dcpib *dcp); +int dcpib_ib_set_power(struct dcpib *dcp, bool on); +int dcpib_ib_get_hpd(struct dcpib *dcp, u32 *timings, u32 *colors); +int dcpib_ib_get_modes(struct dcpib *dcp); +int dcpib_ib_set_mode(struct dcpib *dcp, const struct dcpib_timing_mode *t, + const struct dcpib_color_mode *c); +int dcpib_ib_set_surface(struct dcpib *dcp, u64 iova, u32 width, u32 height, + u32 stride); + +/* drv.c */ +int dcpib_wait_hpd(struct dcpib *dcp); + +/* dptx.c */ +int dcpib_dptx_init(struct dcpib *dcp); +int dcpib_dpav_init(struct dcpib *dcp); +int dcpib_dptx_connect(struct dcpib *dcp, unsigned int port); +int dcpib_dptx_set_hpd(struct dcpib *dcp, unsigned int port, bool hpd); + +/* aux.c */ +struct dcpib_aux { + void __iomem *regs; + void __iomem *ps; + u32 sel; /* output select of the core */ +}; + +void dcpib_aux_probe(struct dcpib *dcp, struct dcpib_aux *aux, u32 sel); +void dcpib_aux_probe_node(struct dcpib *dcp, struct dcpib_aux *aux, u32 sel, + struct device_node *np); +int dcpib_aux_init(struct dcpib *dcp, struct dcpib_aux *aux); +int dcpib_aux_read_edid(struct dcpib *dcp, struct dcpib_aux *aux, u8 *buf, + size_t size); + +/* atc.c, hdmi.c */ +int dcpib_atc_init(struct dcpib *dcp); +struct device_node *dcpib_hdmi_node(void); +int dcpib_hdmi_source(struct device_node *np); +int dcpib_hdmi_init(struct dcpib *dcp, struct device_node *np); + +/* pd.c */ +struct spmi_device *dcpib_pd_get(struct dcpib *dcp, struct device_node *np); +int dcpib_pd_sink(struct spmi_device *pd, bool *flipped); +int dcpib_pd_reconnect(struct dcpib *dcp); + +/* kms.c */ +int dcpib_kms_init(struct dcpib *dcp); +int dcpib_set_boot_mode(struct dcpib *dcp); +void dcpib_update_edid(struct dcpib *dcp); + +#endif diff --git a/drivers/gpu/drm/apple_dcpib/dptx.c b/drivers/gpu/drm/apple_dcpib/dptx.c new file mode 100644 index 0000000000000..55752bd74e056 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/dptx.c @@ -0,0 +1,324 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * DCP DPTX port service and DPAV controllers (port of aura + * src/dcp/dptx_port_ep.c and src/dcp/dpav_ep.c, AFKEPV2 form only). + */ + +#include +#include +#include + +#include "dcpib.h" + +enum dptx_apcall { + DPTX_APCALL_ACTIVATE = 0, + DPTX_APCALL_DEACTIVATE = 1, + DPTX_APCALL_GET_MAX_DRIVE_SETTINGS = 2, + DPTX_APCALL_SET_DRIVE_SETTINGS = 3, + DPTX_APCALL_GET_DRIVE_SETTINGS = 4, + DPTX_APCALL_WILL_CHANGE_LINK_CONFIG = 5, + DPTX_APCALL_DID_CHANGE_LINK_CONFIG = 6, + DPTX_APCALL_GET_MAX_LINK_RATE = 7, + DPTX_APCALL_GET_LINK_RATE = 8, + DPTX_APCALL_SET_LINK_RATE = 9, + DPTX_APCALL_GET_MAX_LANE_COUNT = 10, + DPTX_APCALL_GET_ACTIVE_LANE_COUNT = 11, + DPTX_APCALL_SET_ACTIVE_LANE_COUNT = 12, + DPTX_APCALL_GET_SUPPORTS_DOWN_SPREAD = 13, + DPTX_APCALL_GET_DOWN_SPREAD = 14, + DPTX_APCALL_SET_DOWN_SPREAD = 15, + DPTX_APCALL_GET_SUPPORTS_LANE_MAPPING = 16, + DPTX_APCALL_SET_LANE_MAP = 17, + DPTX_APCALL_GET_SUPPORTS_HPD = 18, + DPTX_APCALL_FORCE_HOTPLUG_DETECT = 19, + DPTX_APCALL_INACTIVE_SINK_DETECTED = 20, + DPTX_APCALL_SET_TILED_DISPLAY_HINTS = 21, + DPTX_APCALL_DEVICE_NOT_RESPONDING = 22, + DPTX_APCALL_DEVICE_BUSY_TIMEOUT = 23, + DPTX_APCALL_DEVICE_NOT_STARTED = 24, + DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE = 26, +}; + +#define DPTX_REMOTE_PORT_CORE GENMASK(3, 0) +#define DPTX_REMOTE_PORT_DFP GENMASK(7, 4) +#define DPTX_REMOTE_PORT_DIE GENMASK(11, 8) +#define DPTX_REMOTE_PORT_CONNECTED BIT(15) + +struct dptx_connection { + __le32 unk; + __le32 target; +} __packed; + +struct dptx_connection_reply { + __le32 unk; + __le32 target; + __le64 reserved; + __le32 status; + u8 padding[12]; +} __packed; + +struct dptx_hotplug { + u8 pad[16]; + __le32 unk; +} __packed; + +static bool dptx_needs_port(u32 command) +{ + switch (command) { + case DPTX_APCALL_ACTIVATE: + case DPTX_APCALL_DEACTIVATE: + case DPTX_APCALL_WILL_CHANGE_LINK_CONFIG: + case DPTX_APCALL_DID_CHANGE_LINK_CONFIG: + case DPTX_APCALL_SET_LINK_RATE: + case DPTX_APCALL_SET_DOWN_SPREAD: + case DPTX_APCALL_SET_ACTIVE_LANE_COUNT: + case DPTX_APCALL_SET_DRIVE_SETTINGS: + case DPTX_APCALL_GET_LINK_RATE: + case DPTX_APCALL_GET_ACTIVE_LANE_COUNT: + case DPTX_APCALL_GET_DRIVE_SETTINGS: + return true; + default: + return false; + } +} + +/* Requests carry their argument, replies their value, at offset 16. */ +static u32 dptx_call(struct dcpib_service *service, u16 group, u32 command, + const void *data, size_t data_size, void *reply, + size_t reply_size) +{ + struct dcpib *dcp = service->ep->dcp; + struct dcpib_port *port = service->cookie; + const struct dcpib_phy_ops *phy = dcp->phy; + u64 value; + u32 arg; + + if (group && !(group == 1 && (command == DPTX_APCALL_SET_DRIVE_SETTINGS || + command == DPTX_APCALL_GET_DRIVE_SETTINGS))) + return KIO_RETURN_UNSUPPORTED; + + dev_dbg(dcp->dev, "DPTX: port %u group %u command %u size %zu\n", + service->unit, group, command, data_size); + if ((!port || !phy) && dptx_needs_port(command)) + return KIO_RETURN_NOT_READY; + + switch (command) { + case DPTX_APCALL_ACTIVATE: + if (phy->activate(dcp)) + return KIO_RETURN_ERROR; + port->link_rate = DCPIB_LINK_RATE_HBR; + return 0; + case DPTX_APCALL_DEACTIVATE: + if (phy->deactivate(dcp)) + return KIO_RETURN_ERROR; + port->link_rate = 0; + return 0; + case DPTX_APCALL_WILL_CHANGE_LINK_CONFIG: + case DPTX_APCALL_DID_CHANGE_LINK_CONFIG: + return phy->set_route(dcp, command == + DPTX_APCALL_DID_CHANGE_LINK_CONFIG) ? + KIO_RETURN_ERROR : 0; + case DPTX_APCALL_GET_MAX_LINK_RATE: + value = phy ? phy->max_link_rate : DCPIB_LINK_RATE_HBR; + break; + case DPTX_APCALL_GET_LINK_RATE: + value = port->link_rate; + break; + case DPTX_APCALL_SET_LINK_RATE: + if (data_size < 17) + return KIO_RETURN_BAD_ARG; + arg = ((const u8 *)data)[16]; + if (arg > phy->max_link_rate) + return KIO_RETURN_UNSUPPORTED; + if (phy->set_link_rate(dcp, arg)) + return KIO_RETURN_ERROR; + port->link_rate = arg; + return 0; + case DPTX_APCALL_GET_MAX_LANE_COUNT: + value = 4; + break; + case DPTX_APCALL_GET_ACTIVE_LANE_COUNT: + value = port->lanes; + break; + case DPTX_APCALL_SET_ACTIVE_LANE_COUNT: + if (data_size < 20) + return KIO_RETURN_BAD_ARG; + arg = get_unaligned_le32(data + 16); + if (arg == 3 || arg > 4) + return KIO_RETURN_BAD_ARG; + dev_info(dcp->dev, "DPTX: %u active lanes\n", arg); + if (phy->set_lane_count && phy->set_lane_count(dcp, arg)) + return KIO_RETURN_ERROR; + port->lanes = arg; + if (arg) + port->trained_lanes = arg; + return 0; + case DPTX_APCALL_GET_MAX_DRIVE_SETTINGS: { + const struct dcpib_drive_settings maximum = { + 0, cpu_to_le32(3), cpu_to_le32(3) + }; + + if (reply_size < 16 + sizeof(maximum)) + return KIO_RETURN_BAD_ARG; + memcpy(reply + 16, &maximum, sizeof(maximum)); + return 0; + } + case DPTX_APCALL_SET_DRIVE_SETTINGS: { + struct dcpib_drive_settings settings[4]; + + if (group != 1) + return KIO_RETURN_UNSUPPORTED; + if (data_size < 32) + return KIO_RETURN_BAD_ARG; + arg = get_unaligned_le32(data + 16); + if (arg > 4 || data_size < 32 + arg * sizeof(settings[0])) + return KIO_RETURN_BAD_ARG; + memcpy(settings, data + 32, arg * sizeof(settings[0])); + if (phy->set_drive(dcp, settings, arg)) + return KIO_RETURN_ERROR; + memcpy(port->drive, settings, arg * sizeof(settings[0])); + port->drive_count = arg; + return 0; + } + case DPTX_APCALL_GET_DRIVE_SETTINGS: + /* + * The firmware reads back what it set during link training; an + * unsupported reply here was followed by a firmware crash. + * Same layout as SET: count at 16, settings from 32. + */ + if (group != 1) + return KIO_RETURN_UNSUPPORTED; + if (reply_size < 32 + port->drive_count * sizeof(port->drive[0])) + return KIO_RETURN_BAD_ARG; + memcpy(reply, data, min(reply_size, data_size)); + put_unaligned_le32(port->drive_count, reply + 16); + memcpy(reply + 32, port->drive, + port->drive_count * sizeof(port->drive[0])); + return 0; + case DPTX_APCALL_SET_DOWN_SPREAD: + if (data_size < 17) + return KIO_RETURN_BAD_ARG; + /* The qualified link setup runs with downspread disabled. */ + return ((const u8 *)data)[16] ? KIO_RETURN_UNSUPPORTED : 0; + case DPTX_APCALL_GET_SUPPORTS_DOWN_SPREAD: + case DPTX_APCALL_GET_DOWN_SPREAD: + case DPTX_APCALL_GET_SUPPORTS_LANE_MAPPING: + case DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE: + value = 0; + break; + case DPTX_APCALL_GET_SUPPORTS_HPD: + value = 1; + break; + case DPTX_APCALL_INACTIVE_SINK_DETECTED: + case DPTX_APCALL_DEVICE_NOT_RESPONDING: + case DPTX_APCALL_DEVICE_BUSY_TIMEOUT: + case DPTX_APCALL_DEVICE_NOT_STARTED: + /* Link fault reports: acknowledged with a zeroed retcode. */ + dev_info(dcp->dev, "DPTX: firmware reports link fault %u\n", + command); + memcpy(reply, data, min(reply_size, data_size)); + if (reply_size > 4) + memset(reply, 0, 4); + return 0; + case DPTX_APCALL_SET_TILED_DISPLAY_HINTS: + memcpy(reply, data, min(reply_size, data_size)); + if (reply_size >= 4) + *(__le32 *)reply = cpu_to_le32(1); + return 0; + default: + dev_info(dcp->dev, "DPTX: unsupported call %u\n", command); + return KIO_RETURN_UNSUPPORTED; + } + + if (reply_size < 16 + sizeof(value)) + return KIO_RETURN_BAD_ARG; + put_unaligned_le64(value, reply + 16); + return 0; +} + +static const struct dcpib_service_ops dptx_ops = { + .call = dptx_call, +}; + +int dcpib_dptx_init(struct dcpib *dcp) +{ + struct dcpib_ep *ep = dcpib_ep_start(dcp, DCPIB_EP_DPTX, &dptx_ops, 2); + + if (IS_ERR(ep)) + return PTR_ERR(ep); + dcp->dptx_ep = ep; + /* Ports in the order the firmware announced them. */ + for (unsigned int i = 0; i < ep->nr_services && i < 2; i++) { + dcp->port[i].service = &ep->services[i]; + ep->services[i].cookie = &dcp->port[i]; + } + return 0; +} + +int dcpib_dpav_init(struct dcpib *dcp) +{ + struct dcpib_ep *ep = dcpib_ep_start(dcp, DCPIB_EP_DPAV, NULL, 4); + + if (IS_ERR(ep)) + return PTR_ERR(ep); + dcp->dpav_ep = ep; + return 0; +} + +/* connectTo, then requestDisplay, as aura dcp_dptx_connect. */ +int dcpib_dptx_connect(struct dcpib *dcp, unsigned int port) +{ + struct dcpib_service *service = dcp->port[port].service; + u32 target = FIELD_PREP(DPTX_REMOTE_PORT_CORE, 0) | + FIELD_PREP(DPTX_REMOTE_PORT_DFP, dcp->dcp_output) | + FIELD_PREP(DPTX_REMOTE_PORT_DIE, dcp->die) | + DPTX_REMOTE_PORT_CONNECTED; + struct dptx_connection cmd = { + /* IODPTXPortAttributes supportsHPD */ + .unk = cpu_to_le32(0x100), + .target = cpu_to_le32(target), + }; + struct dptx_connection_reply resp = {}; + __le32 status = 0; + int ret; + + if (!service) + return -ENODEV; + ret = dcpib_service_call(service, 0, 11, &cmd, sizeof(cmd), 24, &resp, + sizeof(resp), 0); + if (ret) + return ret; + if (resp.status) { + dev_err(dcp->dev, "DPTX: connect returned %#x\n", + le32_to_cpu(resp.status)); + return -EIO; + } + if (le32_to_cpu(resp.target) != target || + le32_to_cpu(resp.unk) != 0x100) + return -EPROTO; + + ret = dcpib_service_call(service, 0, 6, NULL, 0, 16, &status, + sizeof(status), 12); + if (!ret && status) { + dev_err(dcp->dev, "DPTX: requestDisplay returned %#x\n", + le32_to_cpu(status)); + ret = -EIO; + } + return ret; +} + +int dcpib_dptx_set_hpd(struct dcpib *dcp, unsigned int port, bool hpd) +{ + struct dcpib_service *service = dcp->port[port].service; + struct dptx_hotplug cmd = { .unk = cpu_to_le32(hpd) }, resp = {}; + int ret; + + if (!service) + return -ENODEV; + ret = dcpib_service_call(service, 8, 8, &cmd, sizeof(cmd), 12, &resp, + sizeof(resp), 12); + if (ret) + return ret; + /* The status is the first word of the reply. */ + return get_unaligned_le32(resp.pad) ? -EIO : 0; +} diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c new file mode 100644 index 0000000000000..ab6622086ae76 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -0,0 +1,514 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 DCP on the iBoot interface: probe and bring-up. + * + * The bootloader (aura) trains the display and hands the DCP over with its + * RTKit session running. This driver adopts that session, starts the iBoot, + * DPAV and DPTX port endpoints, reconnects the DPTX port and asserts HPD, + * then registers a DRM device whose flips are iBoot SET_SURFACE calls, in + * the order aura's display_init_t8152 uses. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "dcpib.h" + +#define DCPIB_HPD_TIMEOUT_MS 10000 + +static void dcpib_rtk_recv(void *cookie, u8 ep, u64 message) +{ + struct dcpib *dcp = cookie; + struct dcpib_ep *e = NULL; + + if (ep >= DCPIB_FIRST_EP && ep < DCPIB_FIRST_EP + DCPIB_NR_EPS) + e = dcp->eps[ep - DCPIB_FIRST_EP]; + if (e) + dcpib_ep_recv(e, message); + else + dev_dbg(dcp->dev, "message %#llx for idle endpoint %#x\n", + message, ep); +} + +static void dcpib_rtk_crashed(void *cookie, const void *crashlog, size_t size) +{ + struct dcpib *dcp = cookie; + + dev_err(dcp->dev, "DCP firmware crashed\n"); +} + +/* Buffers the firmware pre-allocated in its own DART mappings, or new ones. */ +static int dcpib_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) +{ + struct dcpib *dcp = cookie; + + if (bfr->iova) { + struct iommu_domain *domain = iommu_get_domain_for_dev(dcp->dev); + phys_addr_t phys; + + if (!domain) + return -ENOMEM; + phys = iommu_iova_to_phys(domain, bfr->iova); + if (!phys) { + dev_warn(dcp->dev, "no mapping for firmware buffer %pad\n", + &bfr->iova); + return -ENOMEM; + } + /* The firmware writes these behind the CPU's back. */ + bfr->buffer = memremap(phys, bfr->size, MEMREMAP_WC); + if (!bfr->buffer) + return -ENOMEM; + bfr->is_mapped = true; + return 0; + } + + bfr->buffer = dma_alloc_coherent(dcp->dev, bfr->size, &bfr->iova, + GFP_KERNEL); + return bfr->buffer ? 0 : -ENOMEM; +} + +static void dcpib_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +{ + struct dcpib *dcp = cookie; + + if (bfr->is_mapped) + memunmap(bfr->buffer); + else + dma_free_coherent(dcp->dev, bfr->size, bfr->buffer, bfr->iova); +} + +static const struct apple_rtkit_ops dcpib_rtkit_ops = { + .crashed = dcpib_rtk_crashed, + .recv_message = dcpib_rtk_recv, + .shmem_setup = dcpib_rtk_shmem_setup, + .shmem_destroy = dcpib_rtk_shmem_destroy, +}; + +DEFINE_DRM_GEM_DMA_FOPS(dcpib_fops); + +static const struct drm_driver dcpib_drm_driver = { + /* + * Frames are copied by the CPU, imported ones too: a compositor + * driving both displays imports one device's buffers into the other. + */ + DRM_GEM_DMA_DRIVER_OPS_VMAP, + DRM_FBDEV_DMA_DRIVER_OPS, + .name = "apple-dcpib", + .desc = "Apple DCP (iBoot interface)", + .major = 1, + .minor = 0, + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + .fops = &dcpib_fops, +}; + +/* + * Adopt the bootloader's RTKit session. The T8152 DCP does not acknowledge + * AP QUIESCED, so a quiesced handoff cannot be negotiated, and an IOP INIT + * while its AP power is still ON panics the firmware ("Invalid AP power: + * 32"). Keep the running session instead and start the application + * endpoints explicitly (dcpib_ep_start), as drm/apple does for live M5 + * sessions. + */ +static void dcpib_rtkit_free(void *data) +{ + apple_rtkit_free(data); +} + +static int dcpib_boot(struct dcpib *dcp) +{ + int ret; + + dcp->rtk = apple_rtkit_init_adopted(dcp->dev, dcp, NULL, 0, + &dcpib_rtkit_ops); + if (IS_ERR(dcp->rtk)) + return PTR_ERR(dcp->rtk); + ret = devm_add_action_or_reset(dcp->dev, dcpib_rtkit_free, dcp->rtk); + if (ret) + return ret; + return apple_rtkit_adopt_running(dcp->rtk); +} + +/* + * The display pipe scans out through dart-disp0, the DCP fetches through + * dart-dcp. Both are locked with their own live root, so each needs its own + * device and domain: one domain spanning both would publish dart-dcp's root + * into dart-disp0 and drop the scanout mappings the bootloader left there + * (the pipe then faults, IOMFB axi_rd_err). Scanout buffers are allocated on + * the DCP device and mapped into the scanout domain at the same address. + */ +static int dcpib_scanout_init(struct dcpib *dcp) +{ + struct device_node *np __free(device_node) = + of_get_child_by_name(dcp->dev->of_node, "scanout"); + int ret; + + if (!np) + return -ENODEV; + dcp->scanout = of_platform_device_create(np, NULL, dcp->dev); + if (!dcp->scanout) + dcp->scanout = of_find_device_by_node(np); + if (!dcp->scanout) + return -ENODEV; + ret = dma_set_mask_and_coherent(&dcp->scanout->dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + ret = of_dma_configure(&dcp->scanout->dev, np, true); + if (ret) + return ret; + dcp->scanout_dom = iommu_get_domain_for_dev(&dcp->scanout->dev); + return dcp->scanout_dom ? 0 : -ENODEV; +} + +static void *dcpib_vmap_wc(struct sg_table *sgt) +{ + unsigned int n = 0, count = 0; + struct sg_page_iter iter; + struct page **pages; + void *vaddr; + + for_each_sgtable_page(sgt, &iter, 0) + count++; + pages = kvmalloc_array(count, sizeof(*pages), GFP_KERNEL); + if (!pages) + return NULL; + for_each_sgtable_page(sgt, &iter, 0) + pages[n++] = sg_page_iter_page(&iter); + vaddr = vmap(pages, count, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + kvfree(pages); + return vaddr; +} + +/* + * The display pipe's DART is locked and comes with the firmware's own + * mappings. The address the coprocessor's allocator handed out for a scanout + * buffer can be one of them, and mapping over it corrupts what the pipe + * fetches every frame (the picture flickers). Start at @dva and go down until + * a range with no mapping is found. + */ +static dma_addr_t dcpib_scan_free_dva(struct dcpib *dcp, dma_addr_t dva, + size_t size) +{ + const size_t step = SZ_16K; + + size = ALIGN(size, step); + for (int tries = 0; tries < 64 && dva >= size; tries++) { + size_t off; + + for (off = 0; off < size; off += step) + if (iommu_iova_to_phys(dcp->scanout_dom, dva + off)) + break; + if (off == size) + return dva; + dev_info(dcp->dev, "scanout DART: %pad+%#zx is in use, moving down\n", + &dva, off); + dva -= size; + } + return 0; +} + +/* One scanout buffer: allocated, cleared, mapped for the CPU and the pipe. */ +static int dcpib_scan_alloc(struct dcpib *dcp, int i, size_t size) +{ + struct dcpib_dma *fb = &dcp->scan[i]; + struct sg_table sgt; + ssize_t mapped; + dma_addr_t dva; + int ret; + + ret = dcpib_dma_alloc(dcp, fb, size); + if (ret) + return ret; + ret = dma_get_sgtable(dcp->dev, &sgt, fb->cpu, fb->iova, fb->size); + if (ret) + return ret; + /* + * The DCP is coherent, the display pipe is not: it reads memory past + * the CPU caches, and frames written through the cacheable mapping + * show only once evicted. Write through a write-combined mapping of + * the same pages, with the zeroing of the allocation cleaned out first. + */ + arch_wb_cache_pmem(fb->cpu, fb->size); + dcp->scan_wc[i] = dcpib_vmap_wc(&sgt); + if (!dcp->scan_wc[i]) { + sg_free_table(&sgt); + return -ENOMEM; + } + memset(dcp->scan_wc[i], 0, fb->size); + /* + * Cacheable, as iBoot maps scanout buffers: the pipe faults on + * entries with the DART's no-cache bit (IOMFB axi_rd_err). + */ + dva = dcpib_scan_free_dva(dcp, fb->iova, fb->size); + if (!dva) { + sg_free_table(&sgt); + return -ENOSPC; + } + mapped = iommu_map_sgtable(dcp->scanout_dom, dva, &sgt, + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + sg_free_table(&sgt); + if (mapped < (ssize_t)fb->size) + return mapped < 0 ? mapped : -ENOMEM; + dcp->scan_dva[i] = dva; + dev_info(dcp->dev, "scanout buffer %d: %zu bytes at %pad\n", i, fb->size, &dva); + return 0; +} + +/* + * A fresh iBoot session has no surface. Whenever the pipe runs without one + * (the link retrains when the DPTX services restart, SET_MODE turns it on), + * it fetches from a null base and the firmware takes an NMI (IOMFB + * axi_rd_err). Hand it a black buffer of the boot mode at once, sized from + * the bootloader's simple-framebuffer. + */ +static int dcpib_boot_surface(struct dcpib *dcp) +{ + /* + * The boot display's framebuffer is /chosen's; the bootloader adds the + * second display's (HDMI) at the root. + */ + struct device_node *chosen __free(device_node) = + of_find_node_by_path("/chosen"); + struct device_node *parent __free(device_node) = + of_property_read_bool(dcp->dev->of_node, "apple,hdmi") ? + of_find_node_by_path("/") : of_node_get(chosen); + u32 width = 1280, height = 720, stride = 1280 * 4; + int ret; + + for_each_child_of_node_scoped(parent, np) { + struct resource res; + + if (!of_device_is_compatible(np, "simple-framebuffer")) + continue; + of_property_read_u32(np, "width", &width); + of_property_read_u32(np, "height", &height); + of_property_read_u32(np, "stride", &stride); + /* + * Take the display over from simpledrm on the bootloader's + * framebuffer, so it does not shadow this driver's output + * (fbcon on a framebuffer nothing scans out). + */ + if (!of_address_to_resource(np, 0, &res)) { + ret = aperture_remove_conflicting_devices(res.start, + resource_size(&res), dcpib_drm_driver.name); + if (ret) + dev_warn(dcp->dev, "simpledrm stays: %d\n", ret); + } + break; + } + /* + * Large enough for the largest mode: while a SET_MODE switches, the + * pipe briefly scans the current surface with the new mode's size. + */ + size_t size = (size_t)stride * height; + + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) + size = max_t(size_t, size, (size_t)le32_to_cpu(dcp->tmodes[i].width) * + le32_to_cpu(dcp->tmodes[i].height) * 4); + dcp->boot_w = width; + dcp->boot_h = height; + dcp->boot_stride = stride; + for (int i = 0; i < ARRAY_SIZE(dcp->scan); i++) { + ret = dcpib_scan_alloc(dcp, i, size); + if (ret) + return ret; + } + dcp->front = 0; + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[0], width, height, + stride); + dev_info(dcp->dev, "boot surface %ux%u at %pad: %d\n", width, height, + &dcp->scan_dva[0], ret); + return ret; +} + +/* Wait until the firmware reports a sink with modes, as aura does. */ +int dcpib_wait_hpd(struct dcpib *dcp) +{ + unsigned long timeout = jiffies + msecs_to_jiffies(DCPIB_HPD_TIMEOUT_MS); + u32 timings = 0, colors = 0; + int hpd; + + do { + hpd = dcpib_ib_get_hpd(dcp, &timings, &colors); + if (hpd > 0 && timings && colors) { + dev_info(dcp->dev, "sink: %u timing, %u color modes\n", + timings, colors); + return 0; + } + msleep(100); + } while (time_before(jiffies, timeout)); + + dev_err(dcp->dev, "no sink (hpd %d, %u timing, %u color modes)\n", hpd, + timings, colors); + return hpd < 0 ? hpd : -ENODEV; +} + +static int dcpib_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *hdmi_np __free(device_node) = dcpib_hdmi_node(); + int source = hdmi_np ? dcpib_hdmi_source(hdmi_np) : -ENODEV; + struct dcpib *dcp; + int ret; + + /* + * Without a USB-C display the bootloader drives HDMI from the main DCP + * (source 0) and never starts DCPEXT0. + */ + if (dev->of_node == hdmi_np && source == 0) { + dev_info(dev, "HDMI is on the main DCP\n"); + return -ENODEV; + } + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + + dcp = devm_drm_dev_alloc(dev, &dcpib_drm_driver, struct dcpib, drm); + if (IS_ERR(dcp)) + return PTR_ERR(dcp); + dcp->dev = dev; + platform_set_drvdata(pdev, dcp); + mutex_init(&dcp->lock); + of_property_read_u32(dev->of_node, "apple,die", &dcp->die); + + dcp->wq = devm_alloc_ordered_workqueue(dev, "dcpib", WQ_MEM_RECLAIM); + if (!dcp->wq) + return -ENOMEM; + + ret = dcpib_scanout_init(dcp); + if (ret) + return dev_err_probe(dev, ret, "no scanout DART stream\n"); + + dcp->hdmi = dev->of_node == hdmi_np || source == 0; + if (dcp->hdmi && dev->of_node != hdmi_np) + dev_info(dev, "HDMI from the main DCP (no USB-C display at boot)\n"); + /* Read only: the pin belongs to a controller the AOP runs. */ + dcp->hpd_gpio = devm_fwnode_gpiod_get(dev, + of_fwnode_handle(dcp->hdmi ? hdmi_np : dev->of_node), "hpd", + GPIOD_ASIS, "hpd"); + if (PTR_ERR(dcp->hpd_gpio) == -ENOENT) + dcp->hpd_gpio = NULL; + if (IS_ERR(dcp->hpd_gpio)) + return dev_err_probe(dev, PTR_ERR(dcp->hpd_gpio), "no HPD GPIO\n"); + dcp->hpd = 1; + ret = dcp->hdmi ? dcpib_hdmi_init(dcp, hdmi_np) : dcpib_atc_init(dcp); + if (ret) + return dev_err_probe(dev, ret, "no DisplayPort phy\n"); + + ret = dcpib_boot(dcp); + if (ret) + return dev_err_probe(dev, ret, "cannot adopt the DCP\n"); + + ret = dcpib_iboot_init(dcp); + if (ret) + return dev_err_probe(dev, ret, "no disp0-service\n"); + /* + * The new iBoot session has dropped the surface while the pipe still + * runs: it fetches from a null base (IOMFB axi_rd_err, firmware NMI) + * unless it is powered off at once. It comes back on below, after a + * surface is set. + */ + ret = dcpib_ib_set_power(dcp, false); + if (ret) + return dev_err_probe(dev, ret, "display power off failed\n"); + ret = dcpib_dpav_init(dcp); + if (ret) + return dev_err_probe(dev, ret, "no DPAV controllers\n"); + ret = dcpib_dptx_init(dcp); + if (ret) + return dev_err_probe(dev, ret, "no DPTX port service\n"); + + ret = dcpib_dptx_connect(dcp, 0); + if (ret) + return dev_err_probe(dev, ret, "DPTX connect failed\n"); + ret = dcpib_dptx_set_hpd(dcp, 0, true); + if (ret) + return dev_err_probe(dev, ret, "DPTX hotplug failed\n"); + + ret = dcpib_wait_hpd(dcp); + if (ret) + return ret; + ret = dcpib_ib_get_modes(dcp); + if (ret) + return dev_err_probe(dev, ret, "no modes\n"); + ret = dcpib_boot_surface(dcp); + if (ret) + return dev_err_probe(dev, ret, "no boot surface\n"); + /* + * Without the bootloader's link (no display on the port at boot) the + * phy starts cold, the right way round for the plug. + */ + if (dcp->phy->detect && dcp->phy->set_orientation) { + bool flipped; + + if (dcp->phy->detect(dcp, &flipped) > 0) { + if (dcp->phy->select) + dcp->phy->select(dcp); + dcp->phy->set_orientation(dcp, flipped); + } + } + ret = dcp->phy->activate(dcp); + if (ret) + return dev_err_probe(dev, ret, "phy activation failed\n"); + /* While the display is still off and the firmware does no AUX. */ + dcpib_update_edid(dcp); + ret = dcpib_ib_set_power(dcp, true); + if (ret) + return dev_err_probe(dev, ret, "set_power failed\n"); + dcp->powered = true; + dev_info(dev, "%u timing modes, %u color modes\n", dcp->nr_tmodes, + dcp->nr_cmodes); + + ret = dcpib_kms_init(dcp); + if (ret) + return ret; + ret = dcpib_set_boot_mode(dcp); + if (ret) + dev_warn(dev, "boot mode not set again: %d\n", ret); + ret = drm_dev_register(&dcp->drm, 0); + if (ret) + return ret; + if (dcp->hpd_gpio || dcp->pd) + drmm_kms_helper_poll_init(&dcp->drm); + drm_client_setup(&dcp->drm, NULL); + return 0; +} + +static const struct of_device_id dcpib_of_match[] = { + { .compatible = "apple,t8152-dcp-iboot" }, + {} +}; +MODULE_DEVICE_TABLE(of, dcpib_of_match); + +static struct platform_driver dcpib_platform_driver = { + .driver = { + .name = "apple-dcpib", + .of_match_table = dcpib_of_match, + /* The DCP and the link cannot be handed back yet. */ + .suppress_bind_attrs = true, + }, + .probe = dcpib_probe, +}; +module_platform_driver(dcpib_platform_driver); + +MODULE_DESCRIPTION("Apple T8152 DCP display driver (iBoot interface)"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/gpu/drm/apple_dcpib/hdmi.c b/drivers/gpu/drm/apple_dcpib/hdmi.c new file mode 100644 index 0000000000000..36d7ee6135573 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/hdmi.c @@ -0,0 +1,337 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The J873g HDMI port: the dedicated T8152 dptx-phy in display-crossbar0's + * lpdptx slot, driven by DCPEXT0 and converted by a PS190 (aura + * src/dcp/dptx_phy.c, DPTX_PHY_T8152_HDMI). + * + * The bootloader powers the phy up, applies its tunables, selects the DCP + * and trains the link. This keeps that setup and reprograms what a link + * training changes: the PLL for a new link rate and the active lanes. Drive + * settings are only recorded, as on macOS, and there is no per-link route. + */ + +#include +#include +#include +#include +#include +#include + +#include "dcpib.h" + +#define HDMI_LANES 4 +#define HDMI_LANE0 0x4500 +#define HDMI_LANE_STRIDE 0x2800 + +struct dcpib_hdmi { + void __iomem *core; + void __iomem *apb; + /* AP DisplayPort AUX controller aux1, for the EDID */ + struct dcpib_aux aux; +}; + +/* AppleT8112DPTXPort::setDPTXSourceSelect: crossbar UFP feeding the phy */ +#define HDMI_SOURCE_SELECT 0x10 +#define HDMI_SOURCE_AUX1 6 /* UFP endpoint of dptx1-aux */ + +/* AppleT8152DPTXPort::setBitsInReg */ +static void hdmi_set_bits(struct dcpib_hdmi *hdmi, u32 offset, u32 shift, + u32 mask, u32 value) +{ + u32 reg = readl(hdmi->core + offset); + + writel((reg & ~mask) | (value << shift), hdmi->core + offset); +} + +static void hdmi_apb_update(struct dcpib_hdmi *hdmi, u32 offset, u32 mask, + u32 value) +{ + u32 reg = readl(hdmi->apb + offset); + + writel((reg & ~mask) | value, hdmi->apb + offset); +} + +/* + * AppleT8152DPTXPort::getTunableConfig: the DPPLLConfig words for each link + * rate (constant tables in AppleDisplayCrossbar, 26A434). + */ +static const struct { + u32 rate; /* DPCD units */ + u32 w[22]; +} hdmi_pll_configs[] = { + { DCPIB_LINK_RATE_RBR, + { 1, 0x21c, 0, 0, 1, 0x13, 1, 0, 0, 0x1a, 1, 0x3c, 2, 1, 0, 0, 1, 0, + 0, 0, 1, 3 } }, + { DCPIB_LINK_RATE_HBR, + { 1, 0x1c2, 0x1fff, 0x3ffe, 1, 0x13, 1, 0, 0, 0x1a, 1, 0x32, 2, 1, 0, + 0, 1, 0, 0, 0, 1, 3 } }, + { DCPIB_LINK_RATE_HBR2, + { 0, 0x1c2, 0x1fff, 0x3ffe, 1, 9, 1, 0, 0, 0x1a, 1, 0x32, 1, 0, 0, 1, + 0, 0, 0, 1, 1, 3 } }, + { DCPIB_LINK_RATE_HBR3, + { 0, 0x2a3, 0x2ffd, 0x3ffc, 1, 9, 1, 0, 0, 0x1a, 1, 0x5a, 1, 0, 0, 1, + 0, 0, 0, 1, 1, 3 } }, +}; + +/* + * AppleT8152DPTXPort::pllPowerUp/pllPowerDown: command in 0x408[2:0], + * request bit 3, acknowledge bit 19. + */ +static int hdmi_pll_command(struct dcpib *dcp, struct dcpib_hdmi *hdmi, + u32 command) +{ + int i; + + hdmi_set_bits(hdmi, 0x408, 6, 0x40, 1); + hdmi_set_bits(hdmi, 0x408, 0, 0x7, command); + hdmi_set_bits(hdmi, 0x408, 3, 0x8, 1); + for (i = 0; i < 10; i++) { + udelay(16); + if (readl(hdmi->core + 0x408) & BIT(19)) + break; + } + hdmi_set_bits(hdmi, 0x408, 3, 0x8, 0); + hdmi_set_bits(hdmi, 0x408, 6, 0x40, 0); + if (i == 10) { + dev_err(dcp->dev, "HDMI: no ACK to PLL command %u\n", command); + return -ETIMEDOUT; + } + return 0; +} + +/* + * AppleT8152DPTXPort::phySetActiveLaneCount: lane-disable bits, 0x2420 holds + * the mask of unused lanes. + */ +static void hdmi_set_lanes(struct dcpib_hdmi *hdmi, u32 lanes) +{ + static const u32 offsets[] = { 0x64, 0x24, 0x24, 0x48, 0x48, 0x5c, 0x5c, 0x48 }; + static const u32 shifts[] = { 4, 4, 1, 0, 1, 2, 3, 4 }; + static const u32 masks[] = { 0x10, 0x10, 0x2, 0x1, 0x2, 0x4, 0x8, 0x10 }; + u32 lane, i; + + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 0); + for (lane = 0; lane < HDMI_LANES; lane++) { + u32 base = HDMI_LANE0 + lane * HDMI_LANE_STRIDE; + + for (i = 0; i < ARRAY_SIZE(offsets); i++) + hdmi_set_bits(hdmi, base + offsets[i], shifts[i], + masks[i], lane >= lanes); + } + hdmi_set_bits(hdmi, 0x2420, 0, 0xf, 0xf & ~((1 << lanes) - 1)); + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 1); +} + +static int hdmi_activate(struct dcpib *dcp) +{ + return 0; +} + +static int hdmi_deactivate(struct dcpib *dcp) +{ + dev_info(dcp->dev, "HDMI: keeping the link up on deactivate\n"); + return 0; +} + +/* + * AppleDPTXPort::setLinkRate with the T8152 hooks: phyPowerDown, + * pllPowerDown, pllConfigureFrequency, phy/pllSetHalfLinkRate, pllPowerUp. + */ +static int hdmi_set_link_rate(struct dcpib *dcp, u32 rate) +{ + struct dcpib_hdmi *hdmi = dcp->phy_priv; + const u32 *w = NULL; + bool half; + size_t i; + int ret; + + for (i = 0; i < ARRAY_SIZE(hdmi_pll_configs); i++) + if (hdmi_pll_configs[i].rate == rate) + w = hdmi_pll_configs[i].w; + if (!w) + return -EINVAL; + + dev_info(dcp->dev, "HDMI: link rate %#x\n", rate); + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 0); + ret = hdmi_pll_command(dcp, hdmi, 0); + if (ret) + return ret; + + /* pllConfigureFrequency, downspread off */ + hdmi_set_bits(hdmi, 0x6c0, 0, 0x7ff, w[1]); + hdmi_set_bits(hdmi, 0x6c0, 11, 0x800, w[6]); + hdmi_set_bits(hdmi, 0x6c0, 13, 0x2000, w[10]); + hdmi_set_bits(hdmi, 0x6c0, 18, 0x3c0000, w[21]); + hdmi_set_bits(hdmi, 0x6c4, 14, 0xfffc000, w[2]); + hdmi_set_bits(hdmi, 0x6c4, 0, 0x3fff, + (!(w[7] & 1) && w[2] < 2) ? 0 : w[3]); + hdmi_set_bits(hdmi, 0x6c8, 14, 0xc000, w[0]); + hdmi_set_bits(hdmi, 0x6c8, 8, 0x100, 0); + hdmi_set_bits(hdmi, 0x6c8, 0, 0xff, w[8]); + hdmi_set_bits(hdmi, 0x6c8, 9, 0x3e00, w[5]); + hdmi_set_bits(hdmi, 0x6c8, 16, 0x10000, w[17]); + hdmi_set_bits(hdmi, 0x6c8, 26, 0xfc000000, w[9]); + hdmi_set_bits(hdmi, 0x6cc, 0, 0x7f, w[11]); + hdmi_set_bits(hdmi, 0x6cc, 9, 0x600, w[13]); + hdmi_set_bits(hdmi, 0x6cc, 11, 0x7800, w[14]); + hdmi_set_bits(hdmi, 0x6cc, 15, 0x38000, w[15]); + hdmi_set_bits(hdmi, 0x6cc, 20, 0x100000, w[16]); + hdmi_set_bits(hdmi, 0x6cc, 21, 0x200000, w[18]); + hdmi_set_bits(hdmi, 0x6cc, 22, 0xc00000, w[19]); + hdmi_set_bits(hdmi, 0x6cc, 24, 0x3000000, w[4]); + hdmi_set_bits(hdmi, 0x6cc, 26, 0xc000000, w[20]); + + /* AppleT8112DPTXPort::updateLinkRateDependentShadowRegisters */ + hdmi_apb_update(hdmi, 0xa0, BIT(3), BIT(3)); + hdmi_apb_update(hdmi, 0xa0, BIT(2), BIT(2)); + hdmi_apb_update(hdmi, 0xa0, BIT(18), BIT(18)); + hdmi_apb_update(hdmi, 0xa0, BIT(18), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(19), BIT(19)); + hdmi_apb_update(hdmi, 0xa0, BIT(19), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(2), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(3), 0); + + /* No UHBR rates; half link rate from HBR up. */ + half = rate >= DCPIB_LINK_RATE_HBR; + hdmi_set_bits(hdmi, 0x2400, 2, 0x4, 0); + hdmi_set_bits(hdmi, 0x2400, 3, 0x8, !half); + hdmi_set_bits(hdmi, 0x0000, 17, 0x20000, !half); + + ret = hdmi_pll_command(dcp, hdmi, 7); + if (ret) + return ret; + if (!(readl(hdmi->core + 0x438) & BIT(30))) { + dev_err(dcp->dev, "HDMI: PLL failed to lock at rate %#x\n", rate); + return -EIO; + } + return 0; +} + +static int hdmi_set_lane_count(struct dcpib *dcp, u32 lanes) +{ + /* T8152 takes no zero lane count. */ + if (lanes) + hdmi_set_lanes(dcp->phy_priv, lanes); + return 0; +} + +static int hdmi_set_drive(struct dcpib *dcp, + const struct dcpib_drive_settings *settings, u32 count) +{ + return 0; +} + +static int hdmi_set_route(struct dcpib *dcp, bool enable) +{ + return 0; +} + +/* + * The sink's EDID through the AP AUX controller aux1: the phy takes its + * source from aux1 for the read (its AUX reaches the PS190, which reads the + * monitor's DDC), then from the DCP again. The display is off meanwhile. + */ +static int hdmi_read_edid(struct dcpib *dcp, u8 *buf, size_t size) +{ + struct dcpib_hdmi *hdmi = dcp->phy_priv; + u32 src; + int ret; + + if (!hdmi->aux.regs) + return -ENODEV; + ret = dcpib_aux_init(dcp, &hdmi->aux); + if (ret) + return ret; + src = readl(hdmi->apb + HDMI_SOURCE_SELECT); + writel((src & ~0xf) | HDMI_SOURCE_AUX1, hdmi->apb + HDMI_SOURCE_SELECT); + ret = dcpib_aux_read_edid(dcp, &hdmi->aux, buf, size); + writel(src, hdmi->apb + HDMI_SOURCE_SELECT); + return ret; +} + +static const struct dcpib_phy_ops hdmi_ops = { + .activate = hdmi_activate, + .deactivate = hdmi_deactivate, + .set_link_rate = hdmi_set_link_rate, + .set_lane_count = hdmi_set_lane_count, + .set_drive = hdmi_set_drive, + .set_route = hdmi_set_route, + .read_edid = hdmi_read_edid, + .max_link_rate = DCPIB_LINK_RATE_HBR3, + /* display-crossbar0 DFP endpoint of the lpdptx slot */ +}; + +/* The DCP node that describes the HDMI phy (DCPEXT0's). */ +struct device_node *dcpib_hdmi_node(void) +{ + struct device_node *np; + + for_each_compatible_node(np, NULL, "apple,t8152-dcp-iboot") + if (of_property_read_bool(np, "apple,hdmi")) + return np; + return NULL; +} + +static void __iomem *hdmi_map(struct device *dev, struct device_node *np, + const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + + if (index < 0) + return IOMEM_ERR_PTR(index); + return devm_of_iomap(dev, np, index, NULL); +} + +/* + * The DCP the bootloader wired to the phy (aura writes its DCP index: 0 for + * the main DCP on the HDMI-only route, 1 for DCPEXT0 next to a USB-C + * display), or -ENODEV if it left the PLL unlocked. + */ +int dcpib_hdmi_source(struct device_node *np) +{ + int core = of_property_match_string(np, "reg-names", "phy-core"); + int apb = of_property_match_string(np, "reg-names", "phy-apb"); + void __iomem *core_regs, *apb_regs; + int ret = -ENODEV; + + if (core < 0 || apb < 0) + return -ENODEV; + core_regs = of_iomap(np, core); + apb_regs = of_iomap(np, apb); + if (core_regs && apb_regs && readl(core_regs + 0x438) & BIT(30)) + ret = readl(apb_regs + HDMI_SOURCE_SELECT) & 0xf; + if (apb_regs) + iounmap(apb_regs); + if (core_regs) + iounmap(core_regs); + return ret; +} + +/* The phy, its AUX controller and its HPD line come from np. */ +int dcpib_hdmi_init(struct dcpib *dcp, struct device_node *np) +{ + struct dcpib_hdmi *hdmi; + + hdmi = devm_kzalloc(dcp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_map(dcp->dev, np, "phy-core"); + if (IS_ERR(hdmi->core)) + return PTR_ERR(hdmi->core); + hdmi->apb = hdmi_map(dcp->dev, np, "phy-apb"); + if (IS_ERR(hdmi->apb)) + return PTR_ERR(hdmi->apb); + + /* AUX output select 0x10: the lpdptx phy */ + dcpib_aux_probe_node(dcp, &hdmi->aux, 0x10, np); + + dev_info(dcp->dev, "HDMI: inherited source select %u, PLL %slocked\n", + readl(hdmi->apb + HDMI_SOURCE_SELECT) & 0xf, + readl(hdmi->core + 0x438) & BIT(30) ? "" : "not "); + + dcp->phy = &hdmi_ops; + dcp->phy_priv = hdmi; + /* display-crossbar0 DFP endpoint lpdptx */ + dcp->dcp_output = 4; + return 0; +} diff --git a/drivers/gpu/drm/apple_dcpib/iboot.c b/drivers/gpu/drm/apple_dcpib/iboot.c new file mode 100644 index 0000000000000..b6a0b0bf32a03 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/iboot.c @@ -0,0 +1,243 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* The DCP "disp0-service" iBoot interface (port of aura src/dcp_iboot.c). */ + +#include +#include + +#include "dcpib.h" + +#define IBOOT_SET_SURFACE 1 +#define IBOOT_SET_POWER 2 +#define IBOOT_GET_HPD 3 +#define IBOOT_GET_TIMING_MODES 4 +#define IBOOT_GET_COLOR_MODES 5 +#define IBOOT_SET_MODE 6 + +#define IBOOT_BUF_SIZE 0x4000 + +#define FMT_BGRA 1 +#define ADDR_PLANAR 1 +#define EOTF_GAMMA_SDR 1 + +struct iboot_txcmd { + __le32 op; + __le32 len; + __le32 unk1; + __le32 unk2; +} __packed; + +struct iboot_rxcmd { + __le32 op; + __le32 len; +} __packed; + +struct iboot_hpd { + u8 hpd; + u8 pad[3]; + __le32 timing_cnt; + __le32 color_cnt; +} __packed; + +struct iboot_plane { + __le32 unk1; + __le64 addr; + __le32 tile_size; + __le32 stride; + __le32 unk2[4]; + __le32 addr_format; + __le32 unk3; +} __packed; + +struct iboot_layer { + struct iboot_plane planes[3]; + __le32 unk; + __le32 plane_cnt; + __le32 width; + __le32 height; + __le32 surface_fmt; + __le32 colorspace; + __le32 eotf; + u8 transform; + u8 padding[3]; +} __packed; + +static int dcpib_ib_disp0_init(struct dcpib *dcp) +{ + struct dcpib_ep *ep = dcp->iboot_ep; + + for (unsigned int i = 0; i < ep->nr_services; i++) { + if (!strcmp(ep->services[i].name, "disp0-service") || + !strcmp(ep->services[i].name, "dispext-service")) { + dcp->iboot = &ep->services[i]; + return 0; + } + } + return -ENODEV; +} + +int dcpib_iboot_init(struct dcpib *dcp) +{ + struct dcpib_ep *ep = dcpib_ep_start(dcp, DCPIB_EP_IBOOT, NULL, 1); + + if (IS_ERR(ep)) + return PTR_ERR(ep); + dcp->iboot_ep = ep; + return dcpib_ib_disp0_init(dcp); +} + +/* + * The AFKEPV2 setters answer with transport status alone: supplying a reply + * buffer makes the firmware try to copy an empty message and assert. + */ +static int dcpib_ib_cmd(struct dcpib *dcp, u32 op, const void *in, + size_t in_size, void *out, size_t out_cap, + size_t min_size) +{ + struct iboot_txcmd *tx; + struct iboot_rxcmd *rx = NULL; + bool setter = op == IBOOT_SET_POWER || op == IBOOT_SET_MODE || + op == IBOOT_SET_SURFACE; + size_t rxlen = IBOOT_BUF_SIZE; + int ret; + + if (!dcp->iboot) + return -ENODEV; + tx = kzalloc(sizeof(*tx) + in_size, GFP_KERNEL); + if (!tx) + return -ENOMEM; + tx->op = cpu_to_le32(op); + tx->len = cpu_to_le32(sizeof(*tx) + in_size); + if (in_size) + memcpy(tx + 1, in, in_size); + + if (!setter) { + rx = kzalloc(rxlen, GFP_KERNEL); + if (!rx) { + ret = -ENOMEM; + goto out; + } + } + ret = dcpib_command(dcp->iboot, 0xc0, tx, sizeof(*tx) + in_size, rx, + setter ? NULL : &rxlen); + if (ret || setter) + goto out; + + if (rxlen < sizeof(*rx) || le32_to_cpu(rx->len) < sizeof(*rx) || + le32_to_cpu(rx->len) > rxlen) { + dev_err(dcp->dev, "iboot: bad response length for op %u\n", op); + ret = -EPROTO; + goto out; + } + rxlen = le32_to_cpu(rx->len) - sizeof(*rx); + if (rxlen < min_size) { + ret = -EPROTO; + goto out; + } + memcpy(out, rx + 1, min(rxlen, out_cap)); +out: + kfree(rx); + kfree(tx); + return ret; +} + +int dcpib_ib_set_power(struct dcpib *dcp, bool on) +{ + __le32 power = cpu_to_le32(on); + + /* The command carries one byte of payload. */ + return dcpib_ib_cmd(dcp, IBOOT_SET_POWER, &power, 1, NULL, 0, 0); +} + +int dcpib_ib_get_hpd(struct dcpib *dcp, u32 *timings, u32 *colors) +{ + struct iboot_hpd hpd; + int ret = dcpib_ib_cmd(dcp, IBOOT_GET_HPD, NULL, 0, &hpd, sizeof(hpd), + sizeof(hpd)); + + if (ret) + return ret; + if (timings) + *timings = le32_to_cpu(hpd.timing_cnt); + if (colors) + *colors = le32_to_cpu(hpd.color_cnt); + return !!hpd.hpd; +} + +static int dcpib_ib_get_list(struct dcpib *dcp, u32 op, size_t entry, + void **list, unsigned int *count) +{ + u8 *buf; + u32 n; + int ret; + + buf = kzalloc(IBOOT_BUF_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + ret = dcpib_ib_cmd(dcp, op, NULL, 0, buf, IBOOT_BUF_SIZE, sizeof(__le32)); + if (ret) + goto out; + /* The response holds a count followed by the entries. */ + n = le32_to_cpu(*(__le32 *)buf); + if (n > (IBOOT_BUF_SIZE - sizeof(__le32)) / entry) { + ret = -EPROTO; + goto out; + } + kfree(*list); + *list = kmemdup(buf + sizeof(__le32), n * entry, GFP_KERNEL); + *count = *list ? n : 0; + ret = *list ? 0 : -ENOMEM; +out: + kfree(buf); + return ret; +} + +int dcpib_ib_get_modes(struct dcpib *dcp) +{ + int ret; + + ret = dcpib_ib_get_list(dcp, IBOOT_GET_TIMING_MODES, + sizeof(struct dcpib_timing_mode), + (void **)&dcp->tmodes, &dcp->nr_tmodes); + if (ret) + return ret; + return dcpib_ib_get_list(dcp, IBOOT_GET_COLOR_MODES, + sizeof(struct dcpib_color_mode), + (void **)&dcp->cmodes, &dcp->nr_cmodes); +} + +int dcpib_ib_set_mode(struct dcpib *dcp, const struct dcpib_timing_mode *t, + const struct dcpib_color_mode *c) +{ + dev_dbg(dcp->dev, "SET_MODE %ux%u fps %#x, bpp %u\n", + le32_to_cpu(t->width), le32_to_cpu(t->height), + le32_to_cpu(t->fps), le32_to_cpu(c->bpp)); + struct { + struct dcpib_timing_mode t; + struct dcpib_color_mode c; + } __packed cmd = { *t, *c }; + + return dcpib_ib_cmd(dcp, IBOOT_SET_MODE, &cmd, sizeof(cmd), NULL, 0, 0); +} + +int dcpib_ib_set_surface(struct dcpib *dcp, u64 iova, u32 width, u32 height, + u32 stride) +{ + dev_dbg(dcp->dev, "SET_SURFACE %#llx %ux%u stride %u\n", iova, width, + height, stride); + struct iboot_layer layer = { + .planes = { { + .addr = cpu_to_le64(iova), + .stride = cpu_to_le32(stride), + .addr_format = cpu_to_le32(ADDR_PLANAR), + } }, + .plane_cnt = cpu_to_le32(1), + .width = cpu_to_le32(width), + .height = cpu_to_le32(height), + .surface_fmt = cpu_to_le32(FMT_BGRA), + .colorspace = cpu_to_le32(2), + .eotf = cpu_to_le32(EOTF_GAMMA_SDR), + }; + + return dcpib_ib_cmd(dcp, IBOOT_SET_SURFACE, &layer, sizeof(layer), + NULL, 0, 0); +} diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c new file mode 100644 index 0000000000000..392948a006bb7 --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -0,0 +1,833 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * KMS on the iBoot interface: one primary plane, CRTC, encoder and + * connector. The firmware only takes width, height and refresh rate for a + * mode and picks the timing itself, so the modes are built with CVT for + * userspace. + * + * The pipe always scans out one buffer, the boot surface, which holds the + * largest mode; framebuffers are shadow buffers copied into it, and a + * modeset only changes its geometry, as aura does. Changing the surface + * address between Linux buffers made later modesets crash the firmware + * (IOMFB axi_rd_err). There is no vblank interrupt. + */ + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dcpib.h" + +/* + * Swap between the scanout buffers per frame. Off: frames are copied into + * the buffer on screen, which tears during motion. + */ +static bool buffered = true; +module_param(buffered, bool, 0644); +MODULE_PARM_DESC(buffered, "Copy each frame into a scanout buffer that is not on screen (default: on)"); + +static const u32 dcpib_formats[] = { + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, +}; + +static int dcpib_refresh(const struct dcpib_timing_mode *t) +{ + return (le32_to_cpu(t->fps) + 0x8000) >> 16; +} + +/* + * Whether @t works: the link at the PHY's highest rate must carry it (24 bpp + * plus about 12% blanking against rate x lanes x 0.8 for 8b/10b), and the + * pixel rate must stay within what the PHY's path scans out; a mode beyond + * either only blanks the display. + */ +static bool dcpib_mode_fits(struct dcpib *dcp, const struct dcpib_timing_mode *t) +{ + /* The link's lanes even while the display is off and it is down. */ + u32 lanes = dcp->port[0].trained_lanes ?: 2; + u64 link = (u64)dcp->phy->max_link_rate * 270000000ULL * lanes * 8 / 10; + u64 pixels = (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) * + dcpib_refresh(t); + + if (pixels < dcp->phy->min_pixel_rate || + (dcp->phy->max_pixel_rate && pixels > dcp->phy->max_pixel_rate)) + return false; + return pixels * 24 * 112 / 100 <= link; +} + +/* + * The firmware mode for @mode: same size, refresh rate within 1 Hz (EDID's + * 59.94 against the firmware's 60.00), the nearest one. + */ +static const struct dcpib_timing_mode * +dcpib_find_mode(struct dcpib *dcp, const struct drm_display_mode *mode) +{ + const struct dcpib_timing_mode *best = NULL; + int refresh = drm_mode_vrefresh(mode); + + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + const struct dcpib_timing_mode *t = &dcp->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != mode->hdisplay || + le32_to_cpu(t->height) != mode->vdisplay || + abs(dcpib_refresh(t) - refresh) > 1 || + !dcpib_mode_fits(dcp, t)) + continue; + if (!best || abs(dcpib_refresh(t) - refresh) < + abs(dcpib_refresh(best) - refresh)) + best = t; + } + return best; +} + +/* + * aura's display_choose_color_mode: valid, at most 32 bpp, the highest + * depth, then the lowest colorimetry, encoding and EOTF. Deeper modes the + * HDMI converter offers are refused by SET_MODE. + */ +static bool dcpib_color_better(const struct dcpib_color_mode *a, + const struct dcpib_color_mode *b) +{ + u32 abpp = le32_to_cpu(a->bpp), bbpp = le32_to_cpu(b->bpp); + + if (!!a->valid != !!b->valid) + return a->valid; + if ((abpp <= 32) != (bbpp <= 32)) + return abpp <= 32; + if (abpp != bbpp) + return abpp > bbpp; + if (a->colorimetry != b->colorimetry) + return le32_to_cpu(a->colorimetry) < le32_to_cpu(b->colorimetry); + if (a->encoding != b->encoding) + return le32_to_cpu(a->encoding) < le32_to_cpu(b->encoding); + return le32_to_cpu(a->eotf) < le32_to_cpu(b->eotf); +} + +static const struct dcpib_color_mode *dcpib_find_color(struct dcpib *dcp) +{ + const struct dcpib_color_mode *best = NULL; + + for (unsigned int i = 0; i < dcp->nr_cmodes; i++) + if (!best || dcpib_color_better(&dcp->cmodes[i], best)) + best = &dcp->cmodes[i]; + return best && best->valid ? best : NULL; +} + +/* + * The largest mode from 50 to 60 Hz for the console, up to 1920x1080 on + * USB-C: on the 2-lane HBR link of the J873g USB-C monitor 1920x1080@60 + * works, while SET_MODE 1920x1200@60 crashes the firmware. Low refresh + * modes (2560x1440@30) are left to userspace. + */ +static const struct dcpib_timing_mode *dcpib_preferred(struct dcpib *dcp) +{ + const struct dcpib_timing_mode *best = NULL; + + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + const struct dcpib_timing_mode *t = &dcp->tmodes[i]; + + /* + * Byte 0 bit 6 marks standard modes a converter adds on its own + * (the J873g PS190 lists 3840x2160 for a 2560x1440 monitor), as + * aura's "max" mode skips them. + */ + if (!t->valid || dcpib_refresh(t) > 60 || dcpib_refresh(t) < 50 || + (t->pad[0] & 0x40) || + (!dcp->hdmi && (le32_to_cpu(t->width) > 1920 || + le32_to_cpu(t->height) > 1080)) || + !dcpib_mode_fits(dcp, t)) + continue; + if (!best || (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) > + (u64)le32_to_cpu(best->width) * le32_to_cpu(best->height) || + (t->width == best->width && t->height == best->height && + le32_to_cpu(t->fps) > le32_to_cpu(best->fps))) + best = t; + } + return best; +} + +/* + * The sink's EDID modes the firmware also has (mode_valid drops the rest), + * the largest of them preferred: firmware modes the sink does not list, + * such as 1400x1050 on the J873g EV2780, stay black. + */ +static int dcpib_edid_get_modes(struct drm_connector *connector) +{ + struct dcpib *dcp = to_dcpib(connector->dev); + struct drm_display_mode *mode, *best = NULL; + int count = drm_edid_connector_add_modes(connector); + + mutex_lock(&dcp->lock); + list_for_each_entry(mode, &connector->probed_modes, head) { + mode->type &= ~DRM_MODE_TYPE_PREFERRED; + if (!dcpib_find_mode(dcp, mode)) + continue; + if (!best || mode->hdisplay * mode->vdisplay > + best->hdisplay * best->vdisplay || + (mode->hdisplay * mode->vdisplay == + best->hdisplay * best->vdisplay && + drm_mode_vrefresh(mode) > drm_mode_vrefresh(best))) + best = mode; + } + if (best) + best->type |= DRM_MODE_TYPE_PREFERRED; + mutex_unlock(&dcp->lock); + return count; +} + +static int dcpib_connector_get_modes(struct drm_connector *connector) +{ + struct dcpib *dcp = to_dcpib(connector->dev); + const struct dcpib_timing_mode *preferred; + int count = 0; + + drm_edid_connector_update(connector, dcp->edid); + if (dcp->edid) + return dcpib_edid_get_modes(connector); + + /* Without an EDID, the firmware's list. */ + mutex_lock(&dcp->lock); + preferred = dcpib_preferred(dcp); + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + const struct dcpib_timing_mode *t = &dcp->tmodes[i]; + struct drm_display_mode *mode; + + if (!t->valid || !dcpib_mode_fits(dcp, t)) + continue; + mode = drm_cvt_mode(connector->dev, le32_to_cpu(t->width), + le32_to_cpu(t->height), dcpib_refresh(t), + false, false, false); + if (!mode) + continue; + if (t == preferred) + mode->type |= DRM_MODE_TYPE_PREFERRED; + drm_mode_probed_add(connector, mode); + count++; + } + mutex_unlock(&dcp->lock); + return count; +} + +static enum drm_mode_status +dcpib_connector_mode_valid(struct drm_connector *connector, + const struct drm_display_mode *mode) +{ + struct dcpib *dcp = to_dcpib(connector->dev); + + return dcpib_find_mode(dcp, mode) ? MODE_OK : MODE_NOMODE; +} + +static const struct drm_connector_helper_funcs dcpib_connector_helper = { + .get_modes = dcpib_connector_get_modes, + .mode_valid = dcpib_connector_mode_valid, +}; + +static int dcpib_set_mode_locked(struct dcpib *dcp, + const struct dcpib_timing_mode *t, + const struct dcpib_color_mode *c); + +/* Read the sink's EDID through the phy, if it can, and keep it. */ +void dcpib_update_edid(struct dcpib *dcp) +{ + const struct drm_edid *edid = NULL; + u8 *buf; + int len; + + if (!dcp->phy->read_edid) + return; + buf = kzalloc(4 * EDID_LENGTH, GFP_KERNEL); + if (!buf) + return; + len = dcp->phy->read_edid(dcp, buf, 4 * EDID_LENGTH); + if (len >= EDID_LENGTH) { + edid = drm_edid_alloc(buf, len); + if (edid && !drm_edid_valid(edid)) { + drm_edid_free(edid); + edid = NULL; + } + } + if (!edid) + dev_warn(dcp->dev, "no EDID: %d\n", len); + else + dev_info(dcp->dev, "EDID: %d bytes\n", len); + drm_edid_free(dcp->edid); + dcp->edid = edid; + kfree(buf); +} + +static enum drm_connector_status +dcpib_connector_detect(struct drm_connector *connector, bool force) +{ + struct dcpib *dcp = to_dcpib(connector->dev); + bool flipped = false; + int hpd; + + if (dcp->hpd_gpio) + hpd = gpiod_get_value_cansleep(dcp->hpd_gpio); + else if (dcp->phy->detect) + hpd = dcp->phy->detect(dcp, &flipped); + else + return dcp->nr_tmodes ? connector_status_connected : + connector_status_disconnected; + if (hpd < 0) + return connector_status_unknown; + if (hpd != dcp->hpd) { + dev_info(dcp->dev, "sink %s\n", hpd ? "plugged" : "unplugged"); + dcp->hpd = hpd; + mutex_lock(&dcp->lock); + /* + * USB-C: the DPTX port's HPD follows the PD controller, and a + * new plug may come the other way round. + */ + if (dcp->pd) { + /* + * A plug while the display stayed on (unplug and plug + * between two polls): start the PHY cold again, the + * new plug may come the other way round. + */ + if (hpd && dcp->powered) + dcp->phy->deactivate(dcp); + /* The sink may be on another port now. */ + if (hpd && dcp->phy->select) + dcp->phy->select(dcp); + if (hpd && dcp->phy->set_orientation) + dcp->phy->set_orientation(dcp, flipped); + /* The firmware talks AUX as soon as it sees HPD. */ + if (hpd && dcp->phy->activate(dcp)) + dev_err(dcp->dev, "phy activation failed\n"); + if (dcpib_dptx_set_hpd(dcp, 0, hpd)) + dev_err(dcp->dev, "DPTX HPD update failed\n"); + } + /* A new sink: the firmware reads its EDID, take the new lists. */ + if (hpd && (dcpib_wait_hpd(dcp) || dcpib_ib_get_modes(dcp))) + dev_err(dcp->dev, "no modes from the new sink\n"); + /* + * The EDID once the firmware has read it, so the sink's DDC + * answers, and before SET_MODE: reading it borrows the AUX path + * while the firmware does no AUX. + */ + if (hpd) + dcpib_update_edid(dcp); + /* The unplug dropped the link; SET_MODE trains it again. */ + if (hpd && dcp->powered && (dcp->mode_set || dcp->mode_failed)) { + struct dcpib_timing_mode t = dcp->cur_mode; + const struct dcpib_color_mode *c = dcpib_find_color(dcp); + + if (c) + dcpib_set_mode_locked(dcp, &t, c); + } + mutex_unlock(&dcp->lock); + } + return hpd && dcp->nr_tmodes ? connector_status_connected : + connector_status_disconnected; +} + +static const struct drm_connector_funcs dcpib_connector_funcs = { + .detect = dcpib_connector_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = drm_connector_cleanup, + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; + +static int dcpib_plane_atomic_check(struct drm_plane *plane, + struct drm_atomic_commit *state) +{ + struct drm_plane_state *new = drm_atomic_get_new_plane_state(state, plane); + struct drm_crtc_state *crtc_state = NULL; + + if (new->crtc) + crtc_state = drm_atomic_get_new_crtc_state(state, new->crtc); + /* The surface fills the whole mode; no scaling or positioning. */ + return drm_atomic_helper_check_plane_state(new, crtc_state, + DRM_PLANE_NO_SCALING, + DRM_PLANE_NO_SCALING, + false, false); +} + +static void dcpib_rect_grow(struct drm_rect *r, const struct drm_rect *add) +{ + if (!drm_rect_visible(r)) { + *r = *add; + return; + } + r->x1 = min(r->x1, add->x1); + r->y1 = min(r->y1, add->y1); + r->x2 = max(r->x2, add->x2); + r->y2 = max(r->y2, add->y2); +} + +/* The current mode's refresh period, from its exact 16.16 rate. */ +static s64 dcpib_period_ns(struct dcpib *dcp) +{ + u32 fps = le32_to_cpu(dcp->cur_mode.fps); + + if (fps < (24 << 16)) + fps = 60 << 16; + return div64_u64((u64)NSEC_PER_SEC << 16, fps); +} + +/* Show scan[buf]. Called with dcp->lock held. */ +static void dcpib_swap_locked(struct dcpib *dcp, unsigned int buf, u32 w, + u32 h, u32 pitch) +{ + int ret; + + /* The pipe must see the whole frame before it is swapped in. */ + wmb(); + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[buf], w, h, pitch); + if (ret) { + /* Still on the old buffer, which misses this frame. */ + dev_err_ratelimited(dcp->dev, "swap failed: %d\n", ret); + dcp->stale[dcp->front] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + return; + } + dcp->last_swap = ktime_get(); + dcp->retired[dcp->front] = dcp->last_swap; + dcp->front = buf; +} + +static void dcpib_swap_work(struct work_struct *work) +{ + struct dcpib *dcp = container_of(work, struct dcpib, swap_work); + + mutex_lock(&dcp->lock); + if (dcp->pending >= 0) { + dcpib_swap_locked(dcp, dcp->pending, dcp->pending_w, + dcp->pending_h, dcp->pending_pitch); + dcp->pending = -1; + } + mutex_unlock(&dcp->lock); +} + +static enum hrtimer_restart dcpib_swap_timer(struct hrtimer *t) +{ + struct dcpib *dcp = container_of(t, struct dcpib, swap_timer); + + queue_work(system_highpri_wq, &dcp->swap_work); + return HRTIMER_NORESTART; +} + +/* + * Copy the frame into a scanout buffer that is not on screen and show it. + * That buffer already holds an older frame: copy this frame's damage and + * what changed since that buffer was last written. + * + * SET_SURFACE returns before the pipe takes the buffer at its next frame + * start, and there is no vblank interrupt. Several swaps within one refresh + * let an older frame stay on screen (a cursor that jumps back), so swaps are + * spaced one refresh apart: a frame that comes sooner waits in a pending + * buffer, which a newer frame overwrites, and a timer swaps it in. The + * commit itself never waits, so a client's next frame is not held up. + */ +static void dcpib_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_commit *state) +{ + struct drm_plane_state *old = drm_atomic_get_old_plane_state(state, plane); + struct drm_plane_state *new = drm_atomic_get_new_plane_state(state, plane); + struct drm_shadow_plane_state *shadow = to_drm_shadow_plane_state(new); + struct dcpib *dcp = to_dcpib(plane->dev); + struct drm_framebuffer *fb = new->fb; + struct drm_atomic_helper_damage_iter iter; + struct drm_rect clip, damage = { 0, 0, 0, 0 }; + struct drm_rect full = DRM_RECT_INIT(0, 0, fb ? fb->width : 0, + fb ? fb->height : 0); + unsigned int pitch, back; + struct iosys_map dst; + s64 period, since; + + if (!fb || !new->visible) + return; + pitch = (new->src_w >> 16) * 4; + drm_atomic_helper_damage_iter_init(&iter, old, new); + drm_atomic_for_each_plane_damage(&iter, &clip) + dcpib_rect_grow(&damage, &clip); + if (!drm_rect_visible(&damage)) + return; + + mutex_lock(&dcp->lock); + period = dcpib_period_ns(dcp); + if (!READ_ONCE(buffered)) { + /* Into the buffer on screen (tears during motion). */ + back = dcp->front; + } else if (dcp->pending >= 0) { + back = dcp->pending; + } else { + /* The other buffer that left the screen first. */ + unsigned int a = (dcp->front + 1) % DCPIB_SCANOUT_BUFS; + unsigned int b = (dcp->front + 2) % DCPIB_SCANOUT_BUFS; + s64 wait; + + back = ktime_before(dcp->retired[a], dcp->retired[b]) ? a : b; + /* Off screen for a full refresh: only after a mode change. */ + wait = period - ktime_to_ns(ktime_sub(ktime_get(), dcp->retired[back])); + if (dcp->mode_set && wait > 0) + usleep_range(div_s64(wait, NSEC_PER_USEC), + div_s64(wait, NSEC_PER_USEC) + 100); + } + clip = dcp->stale[back]; + dcpib_rect_grow(&clip, &damage); + if (drm_rect_intersect(&clip, &full)) { + iosys_map_set_vaddr(&dst, dcp->scan_wc[back]); + iosys_map_incr(&dst, drm_fb_clip_offset(pitch, fb->format, &clip)); + drm_fb_memcpy(&dst, &pitch, shadow->data, fb, &clip); + } + dcp->stale[back] = (struct drm_rect){ 0, 0, 0, 0 }; + for (unsigned int i = 0; i < DCPIB_SCANOUT_BUFS; i++) + if (i != back) + dcpib_rect_grow(&dcp->stale[i], &damage); + if (back == dcp->front) + goto out; + + since = ktime_to_ns(ktime_sub(ktime_get(), dcp->last_swap)); + if (dcp->pending < 0 && (!dcp->mode_set || since >= period)) { + dcpib_swap_locked(dcp, back, new->src_w >> 16, new->src_h >> 16, + pitch); + goto out; + } + dcp->pending_w = new->src_w >> 16; + dcp->pending_h = new->src_h >> 16; + dcp->pending_pitch = pitch; + if (dcp->pending < 0) { + dcp->pending = back; + hrtimer_start(&dcp->swap_timer, + ktime_add_ns(dcp->last_swap, period), + HRTIMER_MODE_ABS); + } +out: + mutex_unlock(&dcp->lock); +} + +static const struct drm_plane_helper_funcs dcpib_plane_helper = { + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, + .atomic_check = dcpib_plane_atomic_check, + .atomic_update = dcpib_plane_atomic_update, +}; + +static const struct drm_plane_funcs dcpib_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + DRM_GEM_SHADOW_PLANE_FUNCS, +}; + +static int dcpib_crtc_atomic_check(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcpib *dcp = to_dcpib(crtc->dev); + + /* No vblank interrupt: the helpers complete events after the flush. */ + new->no_vblank = true; + if (new->enable && !dcpib_find_mode(dcp, &new->mode)) + return -EINVAL; + return 0; +} + +/* SET_MODE, then the scanout buffer with the new mode's geometry. */ +static int dcpib_set_mode_locked(struct dcpib *dcp, + const struct dcpib_timing_mode *t, + const struct dcpib_color_mode *c) +{ + int ret; + + /* + * Right after power on the firmware still trains the link and fails + * SET_MODE with kIOReturnError; it takes the mode once it is up. + */ + for (int i = 0; i < 5; i++) { + ret = dcpib_ib_set_mode(dcp, t, c); + if (ret != -EIO) + break; + msleep(200); + } + if (ret) { + dev_err(dcp->dev, "set_mode failed: %d\n", ret); + /* + * USB-C: a sink that no longer answers AUX (seen after the + * monitor's deep sleep) comes back with a fresh DP alt mode + * entry; the plug that follows sets the mode again. At most + * once a minute, so a dead sink does not loop. + */ + if (dcp->pd && time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { + dcp->cur_mode = *t; + dcp->mode_failed = true; + dcp->pd_reset_time = jiffies; + schedule_work(&dcp->pd_reset_work); + } + return ret; + } + dcp->cur_mode = *t; + dcp->mode_set = true; + dcp->mode_failed = false; + /* Both buffers hold the old geometry: the next frame is copied whole. */ + for (unsigned int i = 0; i < DCPIB_SCANOUT_BUFS; i++) + dcp->stale[i] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + /* A pending frame has the old geometry. */ + dcp->pending = -1; + /* As aura swaps after a modeset. */ + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], le32_to_cpu(t->width), + le32_to_cpu(t->height), + le32_to_cpu(t->width) * 4); + if (ret) + dev_err(dcp->dev, "set_surface failed: %d\n", ret); + return ret; +} + +/* + * The boot mode again: a display powered on without SET_MODE counts as idle + * to the firmware's AV stack, which powers the link off after 30 s. + */ +int dcpib_set_boot_mode(struct dcpib *dcp) +{ + const struct dcpib_timing_mode *best = NULL; + const struct dcpib_color_mode *c; + int ret = -ENOENT; + + mutex_lock(&dcp->lock); + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + const struct dcpib_timing_mode *t = &dcp->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != dcp->boot_w || + le32_to_cpu(t->height) != dcp->boot_h || + dcpib_refresh(t) > 60) + continue; + if (!best || le32_to_cpu(t->fps) > le32_to_cpu(best->fps)) + best = t; + } + c = dcpib_find_color(dcp); + if (best && c) + ret = dcpib_set_mode_locked(dcp, best, c); + mutex_unlock(&dcp->lock); + return ret; +} + +static void dcpib_crtc_atomic_enable(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcpib *dcp = to_dcpib(crtc->dev); + const struct dcpib_timing_mode *t; + const struct dcpib_color_mode *c; + int ret; + + mutex_lock(&dcp->lock); + t = dcpib_find_mode(dcp, &new->mode); + c = dcpib_find_color(dcp); + if (!t || !c) + goto out; + if (!dcp->powered) { + /* The phy starts cold first; the firmware then trains. */ + ret = dcp->phy->activate(dcp); + if (ret) + dev_err(dcp->dev, "phy activation failed: %d\n", ret); + /* A pipe powered on without a surface fetches from a null base. */ + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], dcp->boot_w, + dcp->boot_h, dcp->boot_stride); + if (ret) + dev_err(dcp->dev, "set_surface failed: %d\n", ret); + ret = dcpib_ib_set_power(dcp, true); + if (ret) + dev_err(dcp->dev, "set_power failed: %d\n", ret); + dcp->powered = !ret; + } + if (dcp->mode_set && !memcmp(t, &dcp->cur_mode, sizeof(*t))) + goto out; + dev_info(dcp->dev, "modeset %ux%u@%d\n", le32_to_cpu(t->width), + le32_to_cpu(t->height), dcpib_refresh(t)); + /* + * As aura's display_configure: query the sink and both mode lists + * again before SET_MODE, and look the mode up in the fresh list. The + * DPTX port stays connected; reconnecting it here drops the link and + * the HDMI firmware then fails SET_MODE. + */ + ret = dcpib_ib_set_power(dcp, true); + if (!ret) + ret = dcpib_ib_get_hpd(dcp, NULL, NULL) < 0; + if (!ret) + ret = dcpib_ib_get_modes(dcp); + if (ret) + dev_err(dcp->dev, "refreshing the modes failed: %d\n", ret); + t = dcpib_find_mode(dcp, &new->mode); + c = dcpib_find_color(dcp); + if (!t || !c) + goto out; + dcpib_set_mode_locked(dcp, t, c); +out: + mutex_unlock(&dcp->lock); +} + +static void dcpib_crtc_atomic_disable(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcpib *dcp = to_dcpib(crtc->dev); + int ret; + + /* A mode change: SET_MODE alone switches, as before. */ + if (new->active) + return; + /* + * Display off (DPMS, blanking): the firmware stops the pipe and the + * monitor goes to sleep. The next enable sets the mode again. + */ + mutex_lock(&dcp->lock); + if (dcp->powered) { + ret = dcpib_ib_set_power(dcp, false); + if (ret) { + dev_err(dcp->dev, "set_power off failed: %d\n", ret); + } else { + dev_info(dcp->dev, "display off\n"); + /* Nothing scans out: power the phy down as well. */ + if (!dcp->phy->deactivate(dcp)) + dcp->port[0].link_rate = 0; + } + dcp->powered = !!ret; + dcp->mode_set = false; + } + mutex_unlock(&dcp->lock); +} + +static const struct drm_crtc_helper_funcs dcpib_crtc_helper = { + .atomic_check = dcpib_crtc_atomic_check, + .atomic_enable = dcpib_crtc_atomic_enable, + .atomic_disable = dcpib_crtc_atomic_disable, +}; + +static const struct drm_crtc_funcs dcpib_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static const struct drm_encoder_funcs dcpib_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +/* Modeset before the plane update, which copies at the new geometry. */ +static const struct drm_mode_config_helper_funcs dcpib_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; + +static const struct drm_mode_config_funcs dcpib_mode_config_funcs = { + /* fbdev writes reach the scanout buffer through the dirty damage */ + .fb_create = drm_gem_fb_create_with_dirty, + .atomic_check = drm_atomic_helper_check, + .atomic_commit = drm_atomic_helper_commit, +}; + +static void dcpib_pd_reset_work(struct work_struct *work) +{ + struct dcpib *dcp = container_of(work, struct dcpib, pd_reset_work); + int ret; + + dev_info(dcp->dev, "USB-C sink does not answer, entering DP alt mode again\n"); + ret = dcpib_pd_reconnect(dcp); + if (ret) { + dev_err(dcp->dev, "DP alt mode entry failed: %d\n", ret); + return; + } + /* The controller unplugged and plugged: run the plug path. */ + mutex_lock(&dcp->lock); + dcp->hpd = 0; + mutex_unlock(&dcp->lock); + drm_kms_helper_hotplug_event(&dcp->drm); +} + +static void dcpib_swap_stop(void *data) +{ + struct dcpib *dcp = data; + + hrtimer_cancel(&dcp->swap_timer); + cancel_work_sync(&dcp->swap_work); +} + +int dcpib_kms_init(struct dcpib *dcp) +{ + struct drm_device *drm = &dcp->drm; + u32 max_w = 1920, max_h = 1080; + int ret; + + dcp->pending = -1; + INIT_WORK(&dcp->swap_work, dcpib_swap_work); + hrtimer_setup(&dcp->swap_timer, dcpib_swap_timer, CLOCK_MONOTONIC, + HRTIMER_MODE_ABS); + ret = devm_add_action_or_reset(dcp->dev, dcpib_swap_stop, dcp); + if (ret) + return ret; + + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + max_w = max(max_w, le32_to_cpu(dcp->tmodes[i].width)); + max_h = max(max_h, le32_to_cpu(dcp->tmodes[i].height)); + } + + ret = drmm_mode_config_init(drm); + if (ret) + return ret; + INIT_WORK(&dcp->pd_reset_work, dcpib_pd_reset_work); + dcp->pd_reset_time = jiffies - 61 * HZ; + + drm->mode_config.min_width = 320; + drm->mode_config.min_height = 240; + drm->mode_config.max_width = max_w; + drm->mode_config.max_height = max_h; + drm->mode_config.preferred_depth = 24; + drm->mode_config.funcs = &dcpib_mode_config_funcs; + drm->mode_config.helper_private = &dcpib_mode_config_helpers; + + ret = drm_universal_plane_init(drm, &dcp->plane, 0, &dcpib_plane_funcs, + dcpib_formats, ARRAY_SIZE(dcpib_formats), + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ret; + drm_plane_helper_add(&dcp->plane, &dcpib_plane_helper); + drm_plane_enable_fb_damage_clips(&dcp->plane); + + ret = drm_crtc_init_with_planes(drm, &dcp->crtc, &dcp->plane, NULL, + &dcpib_crtc_funcs, NULL); + if (ret) + return ret; + drm_crtc_helper_add(&dcp->crtc, &dcpib_crtc_helper); + + ret = drm_encoder_init(drm, &dcp->encoder, &dcpib_encoder_funcs, + DRM_MODE_ENCODER_TMDS, NULL); + if (ret) + return ret; + dcp->encoder.possible_crtcs = drm_crtc_mask(&dcp->crtc); + + ret = drm_connector_init(drm, &dcp->connector, &dcpib_connector_funcs, + dcp->hdmi ? DRM_MODE_CONNECTOR_HDMIA : + DRM_MODE_CONNECTOR_DisplayPort); + if (ret) + return ret; + drm_connector_helper_add(&dcp->connector, &dcpib_connector_helper); + if (dcp->hpd_gpio || dcp->pd) + dcp->connector.polled = DRM_CONNECTOR_POLL_CONNECT | + DRM_CONNECTOR_POLL_DISCONNECT; + ret = drm_connector_attach_encoder(&dcp->connector, &dcp->encoder); + if (ret) + return ret; + + drm_mode_config_reset(drm); + return 0; +} diff --git a/drivers/gpu/drm/apple_dcpib/pd.c b/drivers/gpu/drm/apple_dcpib/pd.c new file mode 100644 index 0000000000000..84ea367feb1cb --- /dev/null +++ b/drivers/gpu/drm/apple_dcpib/pd.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * USB-C plug state from the port's ACE3 PD controller (J873g hpm3) over + * SPMI, for the USB-C display's hotplug: the DP alt mode connection and the + * plug orientation. Logical registers are read through a window (aura + * src/ace3.c): select with a register-zero write, wait for the busy bit to + * clear, read the size at 0x1f and the data from 0x20. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "dcpib.h" + +#define ACE3_SELECT 0x00 +#define ACE3_SELECT_BUSY BIT(7) +#define ACE3_SIZE 0x1f +#define ACE3_DATA 0x20 +#define ACE3_BURST 16 + +#define ACE3_REG_CMD1 0x08 +#define ACE3_REG_DATA1 0x09 +#define ACE3_REG_STATUS 0x1a +#define ACE3_REG_DATA_STATUS 0x5f + +#define STATUS_PLUG_PRESENT BIT(0) +#define STATUS_UPSIDE_DOWN BIT(4) +#define DATA_DP_CONNECTION BIT(8) +#define DATA_HPD_LEVEL BIT(15) /* CD321x, as tipd */ + +static int ace3_read(struct spmi_device *sdev, u8 reg, u8 *buf, size_t len) +{ + u8 sel, size; + int ret, err = 0; + + ret = spmi_register_zero_write(sdev, reg); + if (ret) + return ret; + ret = read_poll_timeout(spmi_ext_register_read, err, + err || !(sel & ACE3_SELECT_BUSY), 50, 20000, + false, sdev, ACE3_SELECT, &sel, 1); + if (ret || err) + return ret ?: err; + ret = spmi_ext_register_read(sdev, ACE3_SIZE, &size, 1); + if (ret) + return ret; + if (size < len) + return -EIO; + for (size_t done = 0; done < len; done += ACE3_BURST) { + ret = spmi_ext_register_read(sdev, ACE3_DATA + done, buf + done, + min_t(size_t, len - done, ACE3_BURST)); + if (ret) + return ret; + } + return 0; +} + +static int ace3_select(struct spmi_device *sdev, u8 reg) +{ + u8 sel; + int ret, err = 0; + + ret = spmi_register_zero_write(sdev, reg); + if (ret) + return ret; + ret = read_poll_timeout(spmi_ext_register_read, err, + err || !(sel & ACE3_SELECT_BUSY), 50, 20000, + false, sdev, ACE3_SELECT, &sel, 1); + return ret ?: err; +} + +static int ace3_write(struct spmi_device *sdev, u8 reg, const u8 *buf, + size_t len) +{ + int ret = ace3_select(sdev, reg); + + return ret ?: spmi_ext_register_write(sdev, ACE3_DATA, (u8 *)buf, len); +} + +/* A 4CC command with an optional data byte; 0 once the controller took it. */ +static int ace3_cmd(struct spmi_device *sdev, const char *cmd, int data) +{ + u8 val[4]; + int ret; + + ret = spmi_command_wakeup(sdev); + if (ret) + return ret; + if (data >= 0) { + u8 d = data; + + ret = ace3_write(sdev, ACE3_REG_DATA1, &d, 1); + if (ret) + return ret; + } + ret = ace3_write(sdev, ACE3_REG_CMD1, cmd, 4); + if (ret) + return ret; + for (int i = 0; i < 1000; i++) { + ret = ace3_read(sdev, ACE3_REG_CMD1, val, sizeof(val)); + if (ret) + return ret; + if (!memcmp(val, "!CMD", 4)) + return -EIO; + if (!memcmp(val, "\0\0\0\0", 4)) + return 0; + usleep_range(1000, 2000); + } + return -ETIMEDOUT; +} + +/* + * Leave and enter DP alt mode again, as unplugging and plugging the cable + * does: reset the controller (Gaid), then power the port up again once it + * takes commands (SSPS 0, as aura). A sink that stopped answering AUX after + * a monitor's deep sleep comes back this way. + */ +int dcpib_pd_reconnect(struct dcpib *dcp) +{ + int ret; + + /* Gaid resets the controller before it can report completion. */ + ret = spmi_command_wakeup(dcp->pd); + if (!ret) + ret = ace3_write(dcp->pd, ACE3_REG_CMD1, "Gaid", 4); + if (ret) + return ret; + for (int i = 0; i < 60; i++) { + msleep(500); + ret = ace3_cmd(dcp->pd, "SSPS", 0); + if (!ret) + return 0; + } + return ret; +} + +/* 1 with a DisplayPort sink in DP alt mode and HPD high, 0 without. */ +int dcpib_pd_sink(struct spmi_device *pd, bool *flipped) +{ + u8 status[4], data[4]; + int ret; + + /* Without a plug the controller sleeps and ignores selects. */ + ret = spmi_command_wakeup(pd); + if (ret) + return ret; + ret = ace3_read(pd, ACE3_REG_STATUS, status, sizeof(status)); + if (!ret) + ret = ace3_read(pd, ACE3_REG_DATA_STATUS, data, sizeof(data)); + if (ret) + return ret; + *flipped = status[0] & STATUS_UPSIDE_DOWN; + /* The sink answers AUX once it raised HPD, not at alt mode entry. */ + return (status[0] & STATUS_PLUG_PRESENT) && + (get_unaligned_le32(data) & DATA_DP_CONNECTION) && + (get_unaligned_le32(data) & DATA_HPD_LEVEL); +} + +/* The PD controller @np's apple,usb-pd points at, NULL without one. */ +struct spmi_device *dcpib_pd_get(struct dcpib *dcp, struct device_node *np) +{ + struct device_node *pd_np = of_parse_phandle(np, "apple,usb-pd", 0); + struct spmi_device *pd; + + if (!pd_np) + return NULL; + /* Holds a reference for the lifetime of the (unbindable) device. */ + pd = spmi_find_device_by_of_node(pd_np); + of_node_put(pd_np); + return pd ?: ERR_PTR(-EPROBE_DEFER); +} From 7a88c840fbcf9bcca1344105cf0be9deb615968f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 5 Nov 2026 07:24:40 +0100 Subject: [PATCH 067/112] drm/apple_dcpib: re-send SET_MODE when the DCPAV video interface starts The DCPAV service starts its idle power off timer when its video interface starts; a powered-on display without a following SET_MODE counts as idle and the firmware takes the link down 30 s later. At boot the probe's SET_MODE comes before the interface is (re)announced, so HDMI went dark 30 s after boot while sway still reported the output active. Re-send SET_MODE for the current mode a second after a dcpav-video-interface opens, from a delayed work on system_percpu_wq: dcp->wq is ordered and runs the AFK receive work that completes the SET_MODE reply. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/afk.c | 9 ++++++++- drivers/gpu/drm/apple_dcpib/dcpib.h | 7 +++++++ drivers/gpu/drm/apple_dcpib/drv.c | 9 +++++++++ drivers/gpu/drm/apple_dcpib/kms.c | 23 +++++++++++++++++++++++ 4 files changed, 47 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple_dcpib/afk.c b/drivers/gpu/drm/apple_dcpib/afk.c index 01ca8668e44f6..ce450456f42b2 100644 --- a/drivers/gpu/drm/apple_dcpib/afk.c +++ b/drivers/gpu/drm/apple_dcpib/afk.c @@ -267,9 +267,16 @@ static void dcpib_announce(struct dcpib_ep *ep, u16 interface, dev_info(ep->dcp->dev, "AFK[%02x]: opening %s on interface %u\n", ep->ep, service->name, interface); - if (dcpib_tx_v2(ep, interface, &open, sizeof(open))) + if (dcpib_tx_v2(ep, interface, &open, sizeof(open))) { dev_err(ep->dcp->dev, "AFK[%02x]: failed to open %s\n", ep->ep, service->name); + } else if (strstr(service->name, "dcpav-video-interface")) { + /* + * The AV service powers the display on with this interface and + * starts its idle power off timer: SET_MODE again once it is up. + */ + dcpib_av_started(ep->dcp); + } if (ep->nr_services == ep->expected) complete_all(&ep->services_done); } diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index b7449e7a3b2f0..0a49cc956845e 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -256,6 +256,11 @@ struct dcpib { /* USB-C: re-enter DP alt mode when the sink stopped answering */ struct work_struct pd_reset_work; unsigned long pd_reset_time; + /* + * The DCPAV video interface started: SET_MODE again, or the + * firmware's idle power off timer takes the link down 30 s later. + */ + struct delayed_work av_work; struct drm_plane plane; struct drm_crtc crtc; @@ -330,5 +335,7 @@ int dcpib_pd_reconnect(struct dcpib *dcp); int dcpib_kms_init(struct dcpib *dcp); int dcpib_set_boot_mode(struct dcpib *dcp); void dcpib_update_edid(struct dcpib *dcp); +void dcpib_reset_mode(struct dcpib *dcp); +void dcpib_av_started(struct dcpib *dcp); #endif diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index ab6622086ae76..fdb831e9acb4a 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -361,6 +361,14 @@ int dcpib_wait_hpd(struct dcpib *dcp) return hpd < 0 ? hpd : -ENODEV; } +static void dcpib_av_work(struct work_struct *work) +{ + struct dcpib *dcp = container_of(to_delayed_work(work), struct dcpib, + av_work); + + dcpib_reset_mode(dcp); +} + static int dcpib_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -388,6 +396,7 @@ static int dcpib_probe(struct platform_device *pdev) dcp->dev = dev; platform_set_drvdata(pdev, dcp); mutex_init(&dcp->lock); + INIT_DELAYED_WORK(&dcp->av_work, dcpib_av_work); of_property_read_u32(dev->of_node, "apple,die", &dcp->die); dcp->wq = devm_alloc_ordered_workqueue(dev, "dcpib", WQ_MEM_RECLAIM); diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index 392948a006bb7..edbf3a4efe82b 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -619,6 +619,29 @@ int dcpib_set_boot_mode(struct dcpib *dcp) return ret; } +/* + * The DCPAV service starts the firmware's idle power off timer when its video + * interface comes up: until a SET_MODE follows, it counts the powered-on + * display as idle and takes the link down 30 s later. The probe's SET_MODE + * comes before the interface starts, so one follows it here. + */ +void dcpib_reset_mode(struct dcpib *dcp) +{ + const struct dcpib_color_mode *c; + + mutex_lock(&dcp->lock); + c = dcpib_find_color(dcp); + if (c && dcp->powered && dcp->mode_set) + dcpib_set_mode_locked(dcp, &dcp->cur_mode, c); + mutex_unlock(&dcp->lock); +} + +void dcpib_av_started(struct dcpib *dcp) +{ + /* Let the firmware finish opening the interface before the SET_MODE. */ + queue_delayed_work(system_percpu_wq, &dcp->av_work, msecs_to_jiffies(1000)); +} + static void dcpib_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_commit *state) { From 17f24d7a134a61dfefc3e3b435f4b36b0307a38c Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 04:26:19 -0500 Subject: [PATCH 068/112] drm/apple_dcpib: retain adopted firmware resources on failed startup Use the current non-devm RTKit adoption API. Gate incoming endpoint work, drain senders, and detach RTKit while preserving live DMA buffers after a startup failure. Keep the failed device bound to prevent a retry over that session. The driver has no safe firmware shutdown yet, so omit module exit and retain the existing suppressed bind attributes. Initialize and drain the PD reset worker together with the flip workers, and defer AV mode repair until DRM registration. Signed-off-by: Acelogic [Thomas: on this tree the RTKit session was freed by a devm action rather than devm_apple_rtkit_init_adopted(); drop that action instead] Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/dcpib.h | 7 ++++ drivers/gpu/drm/apple_dcpib/drv.c | 62 +++++++++++++++++++++++------ drivers/gpu/drm/apple_dcpib/kms.c | 14 +++++-- 3 files changed, 67 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index 0a49cc956845e..1a64cc498872e 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -180,6 +180,11 @@ struct dcpib_port { }; struct dcpib { + /* Stop new endpoint work before detaching a failed live session. */ + struct mutex rx_gate; + bool stopping; + bool ready; + bool kms_work_ready; struct device *dev; struct drm_device drm; struct apple_rtkit *rtk; @@ -289,6 +294,8 @@ void dcpib_dma_free(struct dcpib *dcp, struct dcpib_dma *dma); /* iboot.c */ int dcpib_iboot_init(struct dcpib *dcp); + +void dcpib_kms_stop(struct dcpib *dcp); int dcpib_ib_set_power(struct dcpib *dcp, bool on); int dcpib_ib_get_hpd(struct dcpib *dcp, u32 *timings, u32 *colors); int dcpib_ib_get_modes(struct dcpib *dcp); diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index fdb831e9acb4a..81ba7b84a8753 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -40,6 +40,9 @@ static void dcpib_rtk_recv(void *cookie, u8 ep, u64 message) struct dcpib *dcp = cookie; struct dcpib_ep *e = NULL; + mutex_lock(&dcp->rx_gate); + if (dcp->stopping) + goto out; if (ep >= DCPIB_FIRST_EP && ep < DCPIB_FIRST_EP + DCPIB_NR_EPS) e = dcp->eps[ep - DCPIB_FIRST_EP]; if (e) @@ -47,6 +50,8 @@ static void dcpib_rtk_recv(void *cookie, u8 ep, u64 message) else dev_dbg(dcp->dev, "message %#llx for idle endpoint %#x\n", message, ep); +out: + mutex_unlock(&dcp->rx_gate); } static void dcpib_rtk_crashed(void *cookie, const void *crashlog, size_t size) @@ -128,22 +133,12 @@ static const struct drm_driver dcpib_drm_driver = { * endpoints explicitly (dcpib_ep_start), as drm/apple does for live M5 * sessions. */ -static void dcpib_rtkit_free(void *data) -{ - apple_rtkit_free(data); -} - static int dcpib_boot(struct dcpib *dcp) { - int ret; - dcp->rtk = apple_rtkit_init_adopted(dcp->dev, dcp, NULL, 0, &dcpib_rtkit_ops); if (IS_ERR(dcp->rtk)) return PTR_ERR(dcp->rtk); - ret = devm_add_action_or_reset(dcp->dev, dcpib_rtkit_free, dcp->rtk); - if (ret) - return ret; return apple_rtkit_adopt_running(dcp->rtk); } @@ -366,10 +361,11 @@ static void dcpib_av_work(struct work_struct *work) struct dcpib *dcp = container_of(to_delayed_work(work), struct dcpib, av_work); - dcpib_reset_mode(dcp); + if (READ_ONCE(dcp->ready)) + dcpib_reset_mode(dcp); } -static int dcpib_probe(struct platform_device *pdev) +static int dcpib_probe_inner(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *hdmi_np __free(device_node) = dcpib_hdmi_node(); @@ -396,6 +392,7 @@ static int dcpib_probe(struct platform_device *pdev) dcp->dev = dev; platform_set_drvdata(pdev, dcp); mutex_init(&dcp->lock); + mutex_init(&dcp->rx_gate); INIT_DELAYED_WORK(&dcp->av_work, dcpib_av_work); of_property_read_u32(dev->of_node, "apple,die", &dcp->die); @@ -496,12 +493,45 @@ static int dcpib_probe(struct platform_device *pdev) ret = drm_dev_register(&dcp->drm, 0); if (ret) return ret; + WRITE_ONCE(dcp->ready, true); if (dcp->hpd_gpio || dcp->pd) drmm_kms_helper_poll_init(&dcp->drm); drm_client_setup(&dcp->drm, NULL); return 0; } +static int dcpib_probe(struct platform_device *pdev) +{ + struct dcpib *dcp; + int ret; + + platform_set_drvdata(pdev, NULL); + ret = dcpib_probe_inner(pdev); + dcp = platform_get_drvdata(pdev); + if (!ret || !dcp || IS_ERR_OR_NULL(dcp->rtk)) + return ret; + + /* + * Once adopted, the DCP may still DMA into our buffers on any error. + * Gate RX before draining endpoint work; keep RTKit available until + * every sender has stopped. Do not reclaim firmware-visible storage + * or let driver-core retry a partially started session. + */ + WRITE_ONCE(dcp->ready, false); + mutex_lock(&dcp->rx_gate); + dcp->stopping = true; + mutex_unlock(&dcp->rx_gate); + flush_workqueue(dcp->wq); + cancel_delayed_work_sync(&dcp->av_work); + dcpib_kms_stop(dcp); + apple_rtkit_free_retaining_buffers(dcp->rtk); + dcp->rtk = NULL; + dev_err(dcp->dev, + "initialization failed (%d); live DMA resources retained until reboot\n", + ret); + return 0; +} + static const struct of_device_id dcpib_of_match[] = { { .compatible = "apple,t8152-dcp-iboot" }, {} @@ -517,7 +547,13 @@ static struct platform_driver dcpib_platform_driver = { }, .probe = dcpib_probe, }; -module_platform_driver(dcpib_platform_driver); + +/* There is no safe firmware shutdown/handoff yet; never unload this module. */ +static int __init dcpib_init(void) +{ + return platform_driver_register(&dcpib_platform_driver); +} +module_init(dcpib_init); MODULE_DESCRIPTION("Apple T8152 DCP display driver (iBoot interface)"); MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index edbf3a4efe82b..25481d4bd4f25 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -777,12 +777,19 @@ static void dcpib_pd_reset_work(struct work_struct *work) drm_kms_helper_hotplug_event(&dcp->drm); } -static void dcpib_swap_stop(void *data) +void dcpib_kms_stop(struct dcpib *dcp) { - struct dcpib *dcp = data; + if (!dcp->kms_work_ready) + return; hrtimer_cancel(&dcp->swap_timer); cancel_work_sync(&dcp->swap_work); + cancel_work_sync(&dcp->pd_reset_work); +} + +static void dcpib_swap_stop(void *data) +{ + dcpib_kms_stop(data); } int dcpib_kms_init(struct dcpib *dcp) @@ -793,8 +800,10 @@ int dcpib_kms_init(struct dcpib *dcp) dcp->pending = -1; INIT_WORK(&dcp->swap_work, dcpib_swap_work); + INIT_WORK(&dcp->pd_reset_work, dcpib_pd_reset_work); hrtimer_setup(&dcp->swap_timer, dcpib_swap_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); + dcp->kms_work_ready = true; ret = devm_add_action_or_reset(dcp->dev, dcpib_swap_stop, dcp); if (ret) return ret; @@ -807,7 +816,6 @@ int dcpib_kms_init(struct dcpib *dcp) ret = drmm_mode_config_init(drm); if (ret) return ret; - INIT_WORK(&dcp->pd_reset_work, dcpib_pd_reset_work); dcp->pd_reset_time = jiffies - 61 * HZ; drm->mode_config.min_width = 320; From 274c714f1f1c631ce0b25d4b5ebe37e88e7b81f3 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:00:57 -0500 Subject: [PATCH 069/112] dt-bindings: display: apple,t8152-dcp-iboot: add the HDMI power states A USB-C-only J873 boot leaves DPTX_PHY off, and reading the HDMI PHY then raises an SError. Describe the read-only PMGR power states of the HDMI PHY (DPTX_PHY) and of the DCPEXT CPU (DISPEXT0_CPU) with the HDMI PHY's register layout, so that the driver can check them before it touches the PHY. Signed-off-by: Acelogic [Thomas: split out of the driver change] Signed-off-by: Thomas Glanzmann --- .../bindings/display/apple,t8152-dcp-iboot.yaml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index 37b14961bbe77..20b5b31e6b0a4 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -48,11 +48,14 @@ properties: - const: phy-apb - const: aux - const: aux-ps - minItems: 3 + - const: phy-ps + - const: coproc-ps description: - DCP coprocessor, the HDMI dptx-phy blocks, and optionally the AP + DCP coprocessor, the HDMI dptx-phy blocks, the AP DisplayPort AUX controller that reads the sink's EDID with its - PMGR power state + PMGR power state, and the read-only PMGR power states for the + HDMI PHY and DCPEXT CPU. The driver only adopts the bootloader's + powered link and must check these states before accessing the PHY. - items: - const: coproc - const: dp-clock From ec5e6df47803baea41cd5e00dc6b8bb965a941e5 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:00:57 -0500 Subject: [PATCH 070/112] drm/apple_dcpib: reject an unpowered HDMI PHY before register access A USB-C-only J873 boot leaves DPTX_PHY off. Reading its PLL register while discovering the HDMI source raises an SError before the main DCP can probe. Check the always-on PMGR requested and actual states before touching the PHY, and only adopt DCPEXT when a powered HDMI link selects it. Missing state resources fail closed. Signed-off-by: Acelogic [Thomas: the binding and device tree parts are separate changes] Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/drv.c | 5 +++-- drivers/gpu/drm/apple_dcpib/hdmi.c | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index 81ba7b84a8753..4e2b498ae351b 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -377,8 +377,9 @@ static int dcpib_probe_inner(struct platform_device *pdev) * Without a USB-C display the bootloader drives HDMI from the main DCP * (source 0) and never starts DCPEXT0. */ - if (dev->of_node == hdmi_np && source == 0) { - dev_info(dev, "HDMI is on the main DCP\n"); + if (dev->of_node == hdmi_np && source != 1) { + dev_info(dev, "%s\n", source == 0 ? "HDMI is on the main DCP" : + "no bootloader HDMI link to adopt"); return -ENODEV; } diff --git a/drivers/gpu/drm/apple_dcpib/hdmi.c b/drivers/gpu/drm/apple_dcpib/hdmi.c index 36d7ee6135573..1a154b2c3c162 100644 --- a/drivers/gpu/drm/apple_dcpib/hdmi.c +++ b/drivers/gpu/drm/apple_dcpib/hdmi.c @@ -282,10 +282,27 @@ static void __iomem *hdmi_map(struct device *dev, struct device_node *np, return devm_of_iomap(dev, np, index, NULL); } +static bool hdmi_power_active(struct device_node *np, const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + void __iomem *regs; + u32 state; + + if (index < 0) + return false; + regs = of_iomap(np, index); + if (!regs) + return false; + state = readl(regs); + iounmap(regs); + /* Both the requested and actual PMGR states must be active. */ + return (state & GENMASK(7, 0)) == GENMASK(7, 0); +} + /* * The DCP the bootloader wired to the phy (aura writes its DCP index: 0 for * the main DCP on the HDMI-only route, 1 for DCPEXT0 next to a USB-C - * display), or -ENODEV if it left the PLL unlocked. + * display), or -ENODEV if it left the PHY off or the PLL unlocked. */ int dcpib_hdmi_source(struct device_node *np) { @@ -294,7 +311,8 @@ int dcpib_hdmi_source(struct device_node *np) void __iomem *core_regs, *apb_regs; int ret = -ENODEV; - if (core < 0 || apb < 0) + /* The PHY aperture aborts while gated, including on a USB-C-only boot. */ + if (core < 0 || apb < 0 || !hdmi_power_active(np, "phy-ps")) return -ENODEV; core_regs = of_iomap(np, core); apb_regs = of_iomap(np, apb); @@ -304,6 +322,10 @@ int dcpib_hdmi_source(struct device_node *np) iounmap(apb_regs); if (core_regs) iounmap(core_regs); + if (ret == 1 && !hdmi_power_active(np, "coproc-ps")) + return -ENODEV; + if (ret != 0 && ret != 1) + return -ENODEV; return ret; } From 3ba2c04088eff911bffe7c70ba2b4351b8cce5c0 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:08:51 -0500 Subject: [PATCH 071/112] dt-bindings: display: apple,t8152-dcp-iboot: add apple,afk-active-endpoints The bootloader may hand the DCP over with AFK endpoints still running, and an AFK INIT on a live endpoint asserts in the firmware. Add a property the bootloader fills in at boot with the endpoints it left running, so that the operating system can stop them before it starts a session of its own. Signed-off-by: Acelogic [Thomas: split out of the driver change, added the description] Signed-off-by: Thomas Glanzmann --- .../bindings/display/apple,t8152-dcp-iboot.yaml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index 20b5b31e6b0a4..f1396f44990db 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -22,6 +22,17 @@ properties: compatible: const: apple,t8152-dcp-iboot + apple,afk-active-endpoints: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 65535 + description: + Runtime handoff from the bootloader. Bit N records that AFK endpoint + 0x20 + N is running and must acknowledge shutdown before a new session + starts. A zero bit means stopped. The bootloader inserts this only + for controllers whose complete endpoint state it owns, and reserves + the old session's buffers. The driver refuses takeover if absent. + This property must not be hard-coded in a board device tree. + reg: minItems: 2 maxItems: 7 From 6b2b3e8fc00e53562c1aef89999c9387fd51a126 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:08:51 -0500 Subject: [PATCH 072/112] drm/apple_dcpib: stop advertised live AFK sessions before reinitializing The bootloader may leave the DCP's AFK endpoints running with its scanout, and an AFK INIT on a live endpoint asserts in the firmware. Read the endpoints it left running from apple,afk-active-endpoints, and send each of them a SHUTDOWN and wait for its acknowledgment before the INIT; the old session's buffers stay reserved by the bootloader. Without the property there is no telling whether an endpoint is live, so the driver refuses to take the DCP over. The endpoint is registered with RTKit before the SHUTDOWN, so that its reply is not reported as one to an undiscovered endpoint. Signed-off-by: Acelogic [Thomas: the binding is a separate change, added the description] Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/afk.c | 20 +++++++++++++++++++- drivers/gpu/drm/apple_dcpib/dcpib.h | 1 + drivers/gpu/drm/apple_dcpib/drv.c | 8 ++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple_dcpib/afk.c b/drivers/gpu/drm/apple_dcpib/afk.c index ce450456f42b2..a9528ed5b071e 100644 --- a/drivers/gpu/drm/apple_dcpib/afk.c +++ b/drivers/gpu/drm/apple_dcpib/afk.c @@ -595,6 +595,25 @@ struct dcpib_ep *dcpib_ep_start(struct dcpib *dcp, u8 epnum, goto err; dcp->eps[epnum - DCPIB_FIRST_EP] = ep; + apple_rtkit_adopt_ep(dcp->rtk, epnum); + /* + * Aura leaves these sessions running with its scanout. INIT while the + * messenger is active asserts in firmware. Stop only an explicitly + * advertised live endpoint and require its acknowledgment before INIT. + * Its old buffers remain reserved by the bootloader throughout. + */ + if (dcp->inherited_afk_endpoints & BIT(epnum - DCPIB_FIRST_EP)) { + ret = dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); + if (ret) + goto err_unregister; + if (!wait_for_completion_timeout(&ep->stopped, DCPIB_TIMEOUT)) { + dev_err(dcp->dev, "inherited endpoint %#x did not stop\n", epnum); + ret = -ETIMEDOUT; + goto err_unregister; + } + dcp->inherited_afk_endpoints &= ~BIT(epnum - DCPIB_FIRST_EP); + dev_info(dcp->dev, "inherited endpoint %#x stopped\n", epnum); + } /* * START_EP for an application endpoint of the adopted session; the * bootloader consumed the endpoint map, so apple_rtkit_start_ep() @@ -608,7 +627,6 @@ struct dcpib_ep *dcpib_ep_start(struct dcpib *dcp, u8 epnum, dev_err(dcp->dev, "failed to start endpoint %#x: %d\n", epnum, ret); goto err_unregister; } - apple_rtkit_adopt_ep(dcp->rtk, epnum); ret = dcpib_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_INIT)); if (ret) goto err_unregister; diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index 1a64cc498872e..6f894fb20b38b 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -189,6 +189,7 @@ struct dcpib { struct drm_device drm; struct apple_rtkit *rtk; struct workqueue_struct *wq; + u32 inherited_afk_endpoints; struct dcpib_ep *eps[DCPIB_NR_EPS]; struct dcpib_ep *iboot_ep; diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index 4e2b498ae351b..f2cf9b5c80b95 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -371,6 +371,7 @@ static int dcpib_probe_inner(struct platform_device *pdev) struct device_node *hdmi_np __free(device_node) = dcpib_hdmi_node(); int source = hdmi_np ? dcpib_hdmi_source(hdmi_np) : -ENODEV; struct dcpib *dcp; + u32 inherited_afk_endpoints; int ret; /* @@ -383,6 +384,12 @@ static int dcpib_probe_inner(struct platform_device *pdev) return -ENODEV; } + ret = of_property_read_u32(dev->of_node, "apple,afk-active-endpoints", + &inherited_afk_endpoints); + if (ret || inherited_afk_endpoints & ~GENMASK(15, 0)) + return dev_err_probe(dev, -EINVAL, + "bootloader AFK endpoint handoff required\n"); + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); if (ret) return ret; @@ -391,6 +398,7 @@ static int dcpib_probe_inner(struct platform_device *pdev) if (IS_ERR(dcp)) return PTR_ERR(dcp); dcp->dev = dev; + dcp->inherited_afk_endpoints = inherited_afk_endpoints; platform_set_drvdata(pdev, dcp); mutex_init(&dcp->lock); mutex_init(&dcp->rx_gate); From f07a9b242f215800f1367142b013dd3981d5f063 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 10:07:11 +0100 Subject: [PATCH 073/112] arm64: dts: apple: t8152: describe the display DARTs as Gen3 The DARTs of the main DCP and of DCPEXT0, and those of their display pipes (ADT dart-dcp, dart-disp0, dart-dcpext0 and dart-dispext0), belong to the SPTM, and the bootloader hands them over locked. Their TLB is invalidated through the SoC's TLB invalidation aperture (dart-tlbi-aperture), not through the T8110 TLB command register. Describe them as apple,t8152-dart-gen3 with their windows in the aperture (ADT tlbi-aperture-offset 0x400 and 0x480). The second register window of the display pipe DARTs, their SMMU instance, is not used and is dropped. The other display DARTs keep their description until something uses them. Signed-off-by: Thomas Glanzmann --- .../boot/dts/apple/t8152-peripherals.dtsi | 22 ++++++++++++------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi index 1cbd604c41a47..a0c5fac66cf18 100644 --- a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi @@ -110,17 +110,20 @@ }; dcp_dart: iommu@286340000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x2 0x86340000 0x0 0x20000>; + compatible = "apple,t8152-dart-gen3"; + reg = <0x2 0x86340000 0x0 0x20000>, + <0x2 0x00000400 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; }; disp0_dart: iommu@286300000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; + compatible = "apple,t8152-dart-gen3"; reg = <0x2 0x86300000 0x0 0xc000>, - <0x2 0x86314000 0x0 0x4000>; + <0x2 0x00000400 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; @@ -135,17 +138,20 @@ }; dcpext0_dart: iommu@32a340000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x3 0x2a340000 0x0 0x20000>; + compatible = "apple,t8152-dart-gen3"; + reg = <0x3 0x2a340000 0x0 0x20000>, + <0x2 0x00000480 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; }; dispext0_dart: iommu@32a300000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; + compatible = "apple,t8152-dart-gen3"; reg = <0x3 0x2a300000 0x0 0xc000>, - <0x3 0x2a314000 0x0 0x4000>; + <0x2 0x00000480 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; From 2e964bb79264454f21dd1f8700da38c02b63a69a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 10:08:50 +0100 Subject: [PATCH 074/112] arm64: dts: apple: j873: add the USB-C and HDMI displays The bootloader trains the J873g displays through the DCP firmware's iBoot interface and hands both DCPs over with their RTKit sessions running: the main DCP drives a USB-C display on one of the rear ports, or HDMI when no USB-C display is attached at boot, and DCPEXT0 drives the HDMI port next to a USB-C display. Add both DCPs with their post-office mailboxes and enable their Gen3 DARTs, with the DMA window in the upper half of the firmware's 64 GiB window, above the firmware's and the bootloader's mappings. The main DCP lists the three rear USB-C ports with their ATC PHY, PMGR power states, tunables and PD controllers on nub-spmi-a0. DCPEXT0 has the HDMI PHY, the read-only PMGR power states of the PHY and of its CPU, and the HPD line of the DP-to-HDMI converter on the AOP's GPIO controller, which is polled since its interrupts belong to the AOP. Each DCP has the AP DisplayPort AUX controller that reads the sink's EDID. Resources are from the 26A434 ADT. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 471 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 472 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi new file mode 100644 index 0000000000000..e41c4008c425f --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -0,0 +1,471 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g displays: the rear USB-C ports and the HDMI port, driven through + * the DCP firmware's iBoot interface (apple,t8152-dcp-iboot). The + * bootloader trains the displays and hands both DCPs over with their RTKit + * sessions running. + * + * Resources are from the 26A434 ADT: dcp (iop,ascwrap-v8, post-office + * mailbox 5 with alias: 0x316020000 + 2 * 5 * 0x80), dart-dcp (SID 23), + * dart-disp0 (scanout SID 0), and the atc-phyN PHY windows. The Gen3 + * display DARTs stay locked by iBoot, each with its own live root, so the + * scanout stream is a child device with its own domain. Linux tables are + * published into vacant root slots, so the DMA window is the upper half of + * the 64 GiB vm-base window, above the firmware's and the bootloader's + * mappings. + */ +#include +#include + +&dcp_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + +&disp0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + +&dcpext0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + +&dispext0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + +/ { + soc { + /* + * ADT /arm-io/nub-spmi-a0 (gen 4): the USB-C PD controllers of + * the three rear ports, each of which can carry the USB-C display. + */ + nub_spmi_a0: spmi@308908000 { + compatible = "apple,t8152-spmi", "apple,t8142-spmi"; + reg = <0x3 0x08908000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + + /* back-middle */ + hpm0: usb-pd@c { + compatible = "apple,sn201202x"; + reg = <0xc SPMI_USID>; + }; + + /* back-left */ + hpm1: usb-pd@a { + compatible = "apple,sn201202x"; + reg = <0xa SPMI_USID>; + }; + + /* back-right */ + hpm3: usb-pd@8 { + compatible = "apple,sn201202x"; + reg = <0x8 SPMI_USID>; + }; + }; + + /* + * ADT aop-gpio. Its interrupts are the AOP's, so it has no + * interrupt controller here; the HDMI HPD line is polled. + */ + pinctrl_aop: pinctrl@310824000 { + compatible = "apple,t8152-pinctrl", "apple,t8103-pinctrl"; + reg = <0x3 0x10824000 0x0 0x4000>; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&pinctrl_aop 0 0 77>; + apple,npins = <77>; + }; + + dcp_mbox: mailbox@316020500 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020500 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + dcp_iboot: display@286e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x86e00000 0x0 0x74000>, + <0x3 0x0002005c 0x0 0x4>, + <0x3 0x1a760000 0x0 0x4000>, + <0x3 0x00700460 0x0 0x4>; + /* aux: ADT dptx0-aux, aux-ps: PMGR GLOBAL_AUX_CTRL0 */ + reg-names = "coproc", "dp-clock", "aux", "aux-ps"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + /* + * Cacheable DMA, as iBoot maps DCP buffers: the firmware + * faults on entries with the DART's no-cache bit. + */ + dma-coherent; + + /* + * The display pipe's own stream: a separate device, so + * its domain imports dart-disp0's root, not dart-dcp's. + */ + scanout { + iommus = <&disp0_dart 0>; + dma-coherent; + }; + + /* + * USB-C back-middle: ADT atc-phy0. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain. Tunables before and after the lane crossbar setup. + */ + usb-c@403000000 { + reg = <0x4 0x03000000 0x0 0x84000>, + <0x3 0x08290000 0x0 0x104>, + <0x3 0x03a13700 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <0>; + apple,usb-pd = <&hpm0>; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bca4>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + }; + + /* + * USB-C back-left: ADT atc-phy1. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain. Tunables before and after the lane crossbar setup. + */ + usb-c@40b000000 { + reg = <0x4 0x0b000000 0x0 0x84000>, + <0x3 0x08290040 0x0 0x104>, + <0x3 0x03a13800 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <1>; + apple,usb-pd = <&hpm1>; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + }; + + /* + * USB-C back-right: ADT atc-phy3. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain. Tunables before and after the lane crossbar setup. + */ + usb-c@413000000 { + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <3>; + apple,usb-pd = <&hpm3>; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + }; + }; + + /* + * HDMI: DCPEXT0 (post-office mailbox 6) drives the dedicated + * dptx-phy through the PS190 converter. ADT dcpext0, + * dart-dcpext0 and dart-dispext0. + */ + dcpext_mbox: mailbox@316020600 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020600 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + dcpext_iboot: display@32ae00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x3 0x2ae00000 0x0 0x74000>, + <0x3 0x1a740000 0x0 0x10000>, + <0x3 0x1a700000 0x0 0x4000>, + <0x3 0x1a764000 0x0 0x4000>, + <0x3 0x00700480 0x0 0x4>, + <0x3 0x007016c0 0x0 0x4>, + <0x3 0x00700e00 0x0 0x4>; + /* aux: ADT dptx1-aux, aux-ps: PMGR GLOBAL_AUX_CTRL1 */ + /* Read-only PMGR DPTX_PHY and DISPEXT0_CPU admission checks. */ + reg-names = "coproc", "phy-core", "phy-apb", "aux", "aux-ps", + "phy-ps", "coproc-ps"; + mboxes = <&dcpext_mbox>; + iommus = <&dcpext0_dart 23>; + dma-coherent; + apple,hdmi; + /* ADT dp2hdmi-gpio0 function-hdmi_hpd */ + hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; + + scanout { + iommus = <&dispext0_dart 0>; + dma-coherent; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 0f98b07748b01..169298a6c9e6c 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -502,3 +502,4 @@ #include "t8152-j873-usb.dtsi" #include "t8152-j873-ethernet.dtsi" #include "t8152-j873-audio.dtsi" +#include "t8152-j873-dcp.dtsi" From 523e6ad29fc4620a1c2c437570d671e71dc47673 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 15 Nov 2026 20:17:20 +0100 Subject: [PATCH 075/112] arm64: configs: asahi: build the T8152 DCP display driver The Mac mini (M6, J873g) drives its HDMI and USB-C displays through apple_dcpib, the DCP driver on the iBoot interface. Build it beside the DCP driver, as the shared defaults require of every native driver. Signed-off-by: Thomas Glanzmann --- arch/arm64/configs/asahi.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 9921de094ba9f..3da2ab3df0430 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -90,6 +90,7 @@ CONFIG_DRM_APPLE=m CONFIG_DRM_APPLE_DCP_T8132=y CONFIG_DRM_APPLE_AUDIO=y CONFIG_DRM_APPLE_DCP_T6030_AUDIO=y +CONFIG_DRM_APPLE_DCPIB=m CONFIG_DRM_ACCEL=y CONFIG_DRM_ACCEL_ANE=m CONFIG_DRM_SIMPLEDRM=y From 8f6c8ed637b4d57b81e1a6e906d19f8d31078200 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 21:22:30 +0100 Subject: [PATCH 076/112] iommu: apple-dart: report T8152 Gen3 DART faults A T8152 Gen3 DART reports a fault as a v2 DART does: a bitmap of the streams with a pending exception at 0x4000, a record per stream at 0x8000 (status, address), acknowledged by writing the bitmap back. Request its interrupt and let apple_dart_t8110_v2_irq() report and acknowledge its faults instead of leaving them to the firmware. Only the unlock after a lock-on-error exception differs: a Gen3 DART's TLB command register serves translation queries, so it is not used to unlock. A Gen3 DART with lock-on-error set says that its stream stays stopped. The J873g's Gen3 DARTs have it clear. Tested on the J873g by clearing the AVD DART's SID 0 TTBR during an H.264 decode: one interrupt, "translation fault: SID:0 write TTBR invalid at 0x10fff000000 (status 0x00000100)", the bitmap acknowledged with no repeat, and the decoder retired by its recovery path. After the TTBR was restored and the decoder reloaded, the same file decoded bit-exact again. None of the other eight Gen3 DART fault lines fired, including those of the locked display DARTs with three displays running. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index e9a3769485925..da2cb77719985 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -2217,6 +2217,15 @@ static int apple_dart_t8110_v2_unlock(struct apple_dart *dart) return -EPERM; if (!(readl(dart->regs + DART_T8110_DIAG_LOCK) & DART_T8110_DIAG_LOCK_ON_ERR)) return 0; + /* + * A Gen3 DART's TLB command register serves translation queries and + * cannot unlock it. Its streams stay stopped until the DART is reset. + */ + if (dart->hw->gen3) { + dev_err_ratelimited(dart->dev, + "locked on error; a Gen3 DART is not unlocked\n"); + return -EOPNOTSUPP; + } /* Unlock after acknowledging a lock-on-error exception. */ __set_bit(0, stream_map.sidmap); @@ -5686,11 +5695,16 @@ static int apple_dart_probe(struct platform_device *pdev) dart->irq = -1; } else if (dart->hw->gen3) { /* - * The T8110 fault handler acknowledges through the TLB command - * register, which a Gen3 DART uses for translation queries. - * Leave its faults to the firmware for now. + * Gen3 reports a fault like a v2 DART: the per-SID exception + * bitmap and records, acknowledged by writing the bitmap back + * (apple_dart_t8110_v2_irq()). Only the unlock after a + * lock-on-error exception differs: see apple_dart_t8110_v2_unlock(). */ - dart->irq = -1; + dart->irq = platform_get_irq_optional(pdev, 0); + if (dart->irq == -ENXIO) + dart->irq = -1; + else if (dart->irq < 0) + return dart->irq; } else if (dart->preserve_display || j713_radio) { dart->irq = platform_get_irq_optional(pdev, 0); if (dart->irq == -ENXIO) From d3d52009ca0e2735047cc11e727a9af3c6786c6a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:53:55 +0100 Subject: [PATCH 077/112] dt-bindings: display: apple,t8152-dcp-iboot: describe DCPEXT1 and shared USB-C ports All three T8152 display controllers can drive the rear USB-C ports through the one display crossbar. Describe what a controller needs for that: - apple,dp-source: its crossbar UFP endpoint (0 DCP, 1 DCPEXT0, 2 DCPEXT1); - apple,usb-c-ports: the node holding the shared usb-c port children, the DP clock dividers and the AUX controller; - coproc-psd: the read-only PMGR2 PSD admission state of a DCPEXT, checked before its coprocessor is touched (a read while it is gated hangs the machine), and the coproc + coproc-psd layout of an extra controller without PHY resources of its own; - apple,rtkit-wake: set by the loader for an unused DCPEXT whose firmware iBoot loaded and powered and which waits for an RTKit wake. The dp-clock resource now spans the PMGR ATC DP clock dividers of all ATCs (one every eight bytes from ATC0) instead of ATC3's alone. Signed-off-by: Thomas Glanzmann --- .../display/apple,t8152-dcp-iboot.yaml | 45 ++++++++++++++++--- 1 file changed, 38 insertions(+), 7 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index f1396f44990db..d4f007202ae65 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -33,9 +33,31 @@ properties: the old session's buffers. The driver refuses takeover if absent. This property must not be hard-coded in a board device tree. + apple,dp-source: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 2 + description: + Display-crossbar UFP endpoint, 0 for DCP, 1 for DCPEXT0, 2 for DCPEXT1. + The driver uses DPTX port zero, whose ATC mux selector is twice this. + + apple,usb-c-ports: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Controller node containing the shared USB-C port children, dp-clock, + aux and aux-ps resources. Each connected port has one controller owner. + + apple,rtkit-wake: + type: boolean + description: + Runtime handoff for an unused DCPEXT whose firmware is loaded, powered, + and awaiting RTKit wake. The loader must reserve its firmware mappings + and buffers and supply apple,afk-active-endpoints. This property must + not be hard-coded in a board tree. An adopted HDMI session is already + running and takes precedence over this unused-controller indication. + reg: minItems: 2 - maxItems: 7 + maxItems: 8 reg-names: oneOf: @@ -61,12 +83,20 @@ properties: - const: aux-ps - const: phy-ps - const: coproc-ps + - const: coproc-psd + minItems: 7 description: DCP coprocessor, the HDMI dptx-phy blocks, the AP DisplayPort AUX controller that reads the sink's EDID with its PMGR power state, and the read-only PMGR power states for the HDMI PHY and DCPEXT CPU. The driver only adopts the bootloader's powered link and must check these states before accessing the PHY. + - items: + - const: coproc + - const: coproc-psd + description: + Additional display controller and its PMGR2 PSD admission state; + PHY resources are shared through apple,usb-c-ports. - items: - const: coproc - const: dp-clock @@ -75,9 +105,9 @@ properties: minItems: 2 description: DCP coprocessor, the PMGR clock control of the ATC DisplayPort - link (shared by the ports), and optionally the AP DisplayPort AUX - controller with its PMGR power state; the USB-C ports follow as - usb-c child nodes + links (one divider every eight bytes, starting with ATC0), and + optionally the AP DisplayPort AUX controller with its PMGR power + state; the USB-C ports follow as usb-c child nodes apple,tunable-pre: $ref: /schemas/types.yaml#/definitions/uint32-matrix @@ -105,7 +135,8 @@ properties: type: boolean description: The DCP drives the HDMI port through the dedicated dptx-phy and an - on-board DisplayPort-to-HDMI converter, instead of an ATC USB-C PHY. + on-board DisplayPort-to-HDMI converter. With apple,usb-c-ports it can + instead claim a USB-C port when the bootloader has not assigned HDMI. apple,usb-pd: $ref: /schemas/types.yaml#/definitions/phandle @@ -210,7 +241,7 @@ examples: compatible = "apple,t8152-dcp-iboot"; reg = <0x2 0x86e00000 0x0 0x74000>, <0x4 0x13000000 0x0 0x84000>, - <0x3 0x0002005c 0x0 0x4>, + <0x3 0x00020044 0x0 0x1c>, <0x3 0x082900c0 0x0 0x104>, <0x3 0x03a13a00 0x0 0xc0>; reg-names = "coproc", "atc", "dp-clock", "atc-ps", "atc-psd"; @@ -225,7 +256,7 @@ examples: display@296e00000 { compatible = "apple,t8152-dcp-iboot"; reg = <0x2 0x96e00000 0x0 0x74000>, - <0x3 0x0002005c 0x0 0x4>; + <0x3 0x00020044 0x0 0x1c>; reg-names = "coproc", "dp-clock"; #address-cells = <2>; #size-cells = <2>; From 2ce5f3b3ca8ea4c10c0ba7c65bbe5303cedad0dc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:53:55 +0100 Subject: [PATCH 078/112] drm/apple_dcpib: drive the rear USB-C ports from all three DCPs The driver drove one USB-C display from the main DCP, and HDMI from DCPEXT0 or the main DCP. The J873g mini has three display controllers and three rear USB-C ports. Let every controller drive any free port, so two USB-C displays and HDMI run at the same time, and fix what kept ports other than ATC3 and sinks other than one EIZO from working: - Shared ports: each DCP claims a free ATC under a mutex and releases it on unplug. The crossbar's upstream reset, clock and enable fields are indexed by DCP endpoint * 2 + DPTX port (AppleT8142ATCDPXBAR::bringConnectionUp); they were fixed to DCP0. The DFP0 mux selects that endpoint. - Each ATC has its own PMGR DP clock divider at 0x300020044 + 8 * n; every port wrote ATC3's. - AUX: the AP AUX controller's output select is instance * 3 + local DFP (AppleAUXDPTX::getAuxSelValue), not ATC3's 9 for every port. The reply timeout is a 14-bit field at bits 21:8 (AppleDPTXController::initAuxReplyTimeout, 3200), not Analogix's three-bit delay: the old value timed out EDID reads through a USB-C to HDMI adapter. All DCPs share aux0, so reads are serialized. - Two-lane DisplayPort: a monitor with USB3 negotiates pin D (DATA_STATUS bit 5). Report two lanes to the firmware and set up only the PMA that carries DP. - PD: a controller in power state 7 enters alt mode only after SSPS 0, not after an SPMI wakeup alone. Its select/data window is held under the SPMI device's lock for the whole exchange, which the USB4 port monitor takes as well. - Startup: wake a quiesced RTKit session instead of adopting it as running. That is an unused DCPEXT the loader marks apple,rtkit-wake, after its PSD admission check, or a main DCP the loader quiesced after a failed display setup (apple,dcp-rtkit-quiesced; the J873 aura build v0.1.0-259-ga30a589a predates that property and is recognized by its 640x1136 placeholder framebuffer). Release the inherited DPTX link before the first connection. - Hotplug: register a USB-C connector idle; a 250 ms worker owns all USB-C links. A PD reset releases DPTX and powers the PHY down first, and a quick reconnect restores a CRTC that was enabled. - KMS: scan out the checked, clipped source rectangle with damage made output-relative, and a 64-byte aligned pitch. The firmware rejected an unaligned bytesPerRow (verify_surfaces). Restore the requested mode's surface geometry before power on; cancel pending swaps on disable, unplug and PD reset; stop submitting while the controller is off, disconnected or crashed; send no AFK messages after a crash. Scanout buffers are sized for 3840x2160 so a monitor plugged in later fits. - The ATC path's pixel-rate cap is 140 Mpixel/s, which lets 1920x1200@60 through a USB-C to HDMI adapter (154 MHz) work. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/afk.c | 5 + drivers/gpu/drm/apple_dcpib/atc.c | 228 +++++++++++++++++++--------- drivers/gpu/drm/apple_dcpib/aux.c | 8 +- drivers/gpu/drm/apple_dcpib/dcpib.h | 7 +- drivers/gpu/drm/apple_dcpib/dptx.c | 17 ++- drivers/gpu/drm/apple_dcpib/drv.c | 179 +++++++++++++++++----- drivers/gpu/drm/apple_dcpib/kms.c | 214 ++++++++++++++++++++------ drivers/gpu/drm/apple_dcpib/pd.c | 34 ++++- 8 files changed, 536 insertions(+), 156 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/afk.c b/drivers/gpu/drm/apple_dcpib/afk.c index a9528ed5b071e..a4f10843cbf18 100644 --- a/drivers/gpu/drm/apple_dcpib/afk.c +++ b/drivers/gpu/drm/apple_dcpib/afk.c @@ -162,6 +162,11 @@ static int dcpib_tx(struct dcpib_ep *ep, const void *data, size_t size) int ret; mutex_lock(&ep->tx_lock); + /* Do not publish more ring entries after a firmware crash. */ + if (apple_rtkit_is_crashed(ep->dcp->rtk)) { + ret = -EIO; + goto out; + } if (!rb->ready || size > rb->bufsz - sizeof(*qe)) { ret = -EINVAL; goto out; diff --git a/drivers/gpu/drm/apple_dcpib/atc.c b/drivers/gpu/drm/apple_dcpib/atc.c index 65b0e80810fb6..8a2d7ff1bae29 100644 --- a/drivers/gpu/drm/apple_dcpib/atc.c +++ b/drivers/gpu/drm/apple_dcpib/atc.c @@ -5,10 +5,10 @@ * * The bootloader trains the USB-C display before Linux starts; this driver * takes that link over and then follows the firmware: link rate changes - * (stop and set up the lanes again), drive settings, the DCP0 -> ATCn/DFP0 + * (stop and set up the lanes again), drive settings, the DCP -> ATCn/DFP0 * display crossbar route, and with the display off or unplugged a full * power down and a cold start. The DCP drives one USB-C port at a time: - * the one a sink is plugged into (each port's PD controller is polled). + * the one it claims from the shared ports while polling their PD controllers. */ #include @@ -41,12 +41,13 @@ struct dcpib_atc_port { /* {offset, mask, value} tunables from the ADT, before/after xbar config */ const __be32 *tunable[2]; int tunable_len[2]; - /* PMGR DP clock control (shared): the divider selects the link rate */ + /* This ATC's PMGR DP clock divider selects the link rate. */ void __iomem *dp_clock; bool swap; bool active; bool route_started; u32 link_rate; + u32 lanes, next_lanes; }; struct dcpib_atc { @@ -57,6 +58,12 @@ struct dcpib_atc { struct dcpib_atc_port *cur, *next; }; +/* J873 has one display crossbar. Claims outlive firmware PHY power cycles. */ +static DEFINE_MUTEX(atc_owner_lock); +static struct device *atc_owner[4]; +/* All three DCPs borrow the same AP AUX controller for EDID reads. */ +static DEFINE_MUTEX(atc_aux_lock); + static struct dcpib_atc_port *atc_cur(struct dcpib *dcp) { return ((struct dcpib_atc *)dcp->phy_priv)->cur; @@ -67,6 +74,20 @@ static const u32 atc_rates[] = { DCPIB_LINK_RATE_HBR3, }; +static bool atc_dp_pma(struct dcpib_atc_port *atc, u32 pma) +{ + return atc->lanes == 4 || pma == !atc->swap; +} + +static bool atc_dp_register(struct dcpib_atc_port *atc, u32 offset) +{ + if (offset >= 0x3000 && offset < 0xc000) + return atc_dp_pma(atc, 0); + if (offset >= 0xc000 && offset < 0x15000) + return atc_dp_pma(atc, 1); + return true; +} + static void atc_update(struct dcpib_atc_port *atc, u32 offset, u32 mask, u32 value) { u32 reg = readl(atc->base + offset); @@ -84,11 +105,14 @@ static int atc_poll(struct dcpib_atc_port *atc, u32 offset, u32 mask, u32 value) static int atc_route_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) { + u32 ufp = dcp->dp_source * 2; + u32 mask = BIT(ufp); + if (!atc->route_started) return 0; - atc_update(atc, ATC_XBAR + 0x3c, 1, 0); - atc_update(atc, ATC_XBAR, 1, 0); - atc_update(atc, ATC_XBAR + 0xc, 1, 0); + atc_update(atc, ATC_XBAR + 0x3c, mask, 0); + atc_update(atc, ATC_XBAR, mask, 0); + atc_update(atc, ATC_XBAR + 0xc, mask, 0); atc_update(atc, ATC_XBAR + 0x24, 0x100, 0); udelay(1); /* @@ -96,15 +120,15 @@ static int atc_route_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) * that way) nothing acknowledges the stop; the route is idle then, so * finish it anyway. */ - if (atc_poll(atc, ATC_XBAR + 0x800, 1, 0) || - atc_poll(atc, ATC_XBAR + 0x808, 1, 0) || + if (atc_poll(atc, ATC_XBAR + 0x800, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x808, mask, 0) || atc_poll(atc, ATC_XBAR + 0x81c, 0x100, 0)) dev_info(dcp->dev, "ATC%u: no crossbar stop acknowledgment\n", atc->index); - atc_update(atc, ATC_XBAR + 8, 1, 0); - atc_update(atc, ATC_XBAR + 0x20, 7, 0); + atc_update(atc, ATC_XBAR + 8, mask, 0); + atc_update(atc, ATC_XBAR + 0x20, 7 << (3 * ufp), 0); atc_update(atc, ATC_XBAR + 0x38, 0x700, 0); - atc_update(atc, ATC_XBAR + 4, 1, 1); - atc_update(atc, ATC_XBAR + 0x1c, 1, 1); + atc_update(atc, ATC_XBAR + 4, mask, mask); + atc_update(atc, ATC_XBAR + 0x1c, mask, mask); atc_update(atc, ATC_XBAR + 0x34, 0x100, 0x100); atc->route_started = false; dev_dbg(dcp->dev, "ATC%u: display route disabled\n", atc->index); @@ -113,37 +137,41 @@ static int atc_route_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) /* * A source -> ATCn/DFP0 route, PCLK1: both DFP0 mux fields select the - * source (AppleT8142ATCDPXBAR::connect): DCP0 or an AP AUX controller. + * source (AppleT8142ATCDPXBAR::connect). Upstream reset, clock and enable + * fields are indexed by DCP endpoint * 2 + DPTX port, independently of + * the downstream DFP0 fields. AUX borrowing keeps that DCP's clock path. */ -#define ATC_SEL_DCP0 0 #define ATC_SEL_AUX0 9 /* UFP endpoint 5 + 4 (getMuxSelector) */ static int atc_route_start_sel(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 sel) { + u32 ufp = dcp->dp_source * 2; + u32 mask = BIT(ufp); + if (atc->route_started) return 0; atc_update(atc, ATC_XBAR + 0x44, 0x00f00000, sel << 20); atc_update(atc, ATC_XBAR + 0x44, 0x00000f00, sel << 8); - atc_update(atc, ATC_XBAR + 4, 1, 0); - atc_update(atc, ATC_XBAR + 0x1c, 1, 0); + atc_update(atc, ATC_XBAR + 4, mask, 0); + atc_update(atc, ATC_XBAR + 0x1c, mask, 0); atc_update(atc, ATC_XBAR + 0x34, 0x100, 0); udelay(1); - if (atc_poll(atc, ATC_XBAR + 0x804, 1, 0) || - atc_poll(atc, ATC_XBAR + 0x818, 1, 0) || + if (atc_poll(atc, ATC_XBAR + 0x804, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x818, mask, 0) || atc_poll(atc, ATC_XBAR + 0x82c, 0x100, 0)) { dev_err(dcp->dev, "ATC%u: crossbar reset acknowledgment timeout\n", atc->index); return -ETIMEDOUT; } - atc_update(atc, ATC_XBAR + 8, 1, 1); - atc_update(atc, ATC_XBAR + 0x20, 7, 1); + atc_update(atc, ATC_XBAR + 8, mask, mask); + atc_update(atc, ATC_XBAR + 0x20, 7 << (3 * ufp), 1 << (3 * ufp)); atc_update(atc, ATC_XBAR + 0x38, 0x700, 0x100); atc_update(atc, ATC_XBAR + 0x48, 1, 0); - atc_update(atc, ATC_XBAR, 1, 1); - atc_update(atc, ATC_XBAR + 0xc, 1, 1); + atc_update(atc, ATC_XBAR, mask, mask); + atc_update(atc, ATC_XBAR + 0xc, mask, mask); atc_update(atc, ATC_XBAR + 0x24, 0x100, 0x100); atc_update(atc, ATC_XBAR + 0x4c, 0x100, 0x100); - atc_update(atc, ATC_XBAR + 0x3c, 1, 1); + atc_update(atc, ATC_XBAR + 0x3c, mask, mask); atc->route_started = true; dev_dbg(dcp->dev, "ATC%u: source %u to local DFP0 route configured\n", atc->index, sel); return 0; @@ -151,7 +179,7 @@ static int atc_route_start_sel(struct dcpib *dcp, struct dcpib_atc_port *atc, static int atc_route_start(struct dcpib *dcp, struct dcpib_atc_port *atc) { - return atc_route_start_sel(dcp, atc, ATC_SEL_DCP0); + return atc_route_start_sel(dcp, atc, dcp->dp_source * 2); } /* Common four-lane setup; the rate-dependent fields follow in atc_dp_start. */ @@ -225,9 +253,14 @@ static int atc_dp_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) atc_update(atc, 0xe10, BIT(2), BIT(2)); atc_update(atc, 0xe08, BIT(29), BIT(29)); /* Remove both PMA clock requests, then clamp and power down both lanes. */ - atc_update(atc, ATC_AON + 0x24, BIT(12) | BIT(16) | BIT(14) | BIT(18), 0); - udelay(1); for (u32 offset = 0x1e18; offset <= 0x1e1c; offset += 4) { + u32 pma = (offset - 0x1e18) / 4; + + if (!atc_dp_pma(atc, pma)) + continue; + atc_update(atc, ATC_AON + 0x24, + BIT(12 + 2 * pma) | BIT(16 + 2 * pma), 0); + udelay(1); atc_update(atc, offset, BIT(5), 0); udelay(1); atc_update(atc, offset, BIT(0), BIT(0)); @@ -259,6 +292,8 @@ static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) for (u32 i = 0; i < 2; i++) { u32 offset = 0x1e18 + 4 * i; + if (!atc_dp_pma(atc, i)) + continue; atc_update(atc, ATC_AON + 0x24, BIT(12 + 2 * i), BIT(12 + 2 * i)); udelay(1); atc_update(atc, ATC_AON + 0x24, BIT(16 + 2 * i), BIT(16 + 2 * i)); @@ -274,13 +309,18 @@ static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) } atc_update(atc, 0x2000, 0x380000, r << 19); for (unsigned int i = 0; i < ARRAY_SIZE(atc_dp_setup); i++) - atc_update(atc, atc_dp_setup[i].offset, atc_dp_setup[i].mask, - atc_dp_setup[i].value); + if (atc_dp_register(atc, atc_dp_setup[i].offset)) + atc_update(atc, atc_dp_setup[i].offset, atc_dp_setup[i].mask, + atc_dp_setup[i].value); for (u32 i = 0; i < 2; i++) { + if (!atc_dp_pma(atc, i)) + continue; atc_update(atc, 0x8684 + i * 0x9000, 3, r ? 0 : 1); atc_update(atc, 0x4c80 + i * 0x9000, 0x30, r ? 0 : 0x10); } for (unsigned int i = 0; i < ARRAY_SIZE(tx_ctrl); i++) { + if (!atc_dp_register(atc, tx_ctrl[i])) + continue; atc_update(atc, tx_ctrl[i], 0x7e07ff, 1); atc_update(atc, tx_ctrl[i] - 0x14, 0x7f, r < 2 ? 0x65 : 0x40); } @@ -301,8 +341,8 @@ static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) if (ret) return ret; atc->link_rate = atc_rates[r]; - dev_info(dcp->dev, "ATC%u: four-lane DPTX setup at rate %#x\n", atc->index, - atc->link_rate); + dev_info(dcp->dev, "ATC%u: %u-lane DPTX setup at rate %#x\n", atc->index, + atc->lanes, atc->link_rate); return 0; } @@ -371,6 +411,8 @@ static int atc_activate(struct dcpib *dcp) unsigned int gates = 0; u32 reg; + if (READ_ONCE(atc_owner[atc->index]) != dcp->dev) + return -EBUSY; if (atc->active) return 0; if (!atc->tunable[0] || !atc->tunable[1]) @@ -393,9 +435,11 @@ static int atc_activate(struct dcpib *dcp) writel(readl(cfg) | BIT(3), cfg); atc_apply_tunables(atc, 0); - /* aciophy_xbar_config(mode=3): both PMAs carry DisplayPort. */ - atc_update(atc, 0x4c, 0x1f, 0x14); - atc_update(atc, 0x4c, 0x3ffe0, atc->swap ? 0x100 : 0x22000); + /* Pin D/F keeps the other PMA out of the DP path. */ + atc_update(atc, 0x4c, 0x1f, + atc->lanes == 2 ? (atc->swap ? 0x11 : 0x10) : 0x14); + atc_update(atc, 0x4c, 0x3ffe0, + atc->lanes == 2 || atc->swap ? 0x100 : 0x22000); atc_apply_tunables(atc, 1); atc_update(atc, ATC_CFG + 8, BIT(1), atc->swap ? BIT(1) : 0); writel(readl(cfg) | BIT(4), cfg); @@ -527,7 +571,7 @@ static int atc_set_drive(struct dcpib *dcp, if (!count) return 0; - if (count > 4 || !atc->active || !atc->link_rate) + if (count > atc->lanes || !atc->active || !atc->link_rate) return -EINVAL; /* Validate the entire request before changing any lane. */ for (u32 i = 0; i < count; i++) { @@ -560,6 +604,12 @@ static void atc_set_orientation(struct dcpib *dcp, bool flipped) if (atc->active && atc->swap != flipped) dev_warn(dcp->dev, "ATC%u: orientation changed while active\n", atc->index); atc->swap = flipped; + atc->lanes = atc->next_lanes; +} + +static u32 atc_max_lane_count(struct dcpib *dcp) +{ + return atc_cur(dcp)->lanes; } /* @@ -576,9 +626,12 @@ static int atc_read_edid(struct dcpib *dcp, u8 *buf, size_t size) if (!atc->active || !atc->aux->regs) return -ENODEV; + mutex_lock(&atc_aux_lock); + /* AppleAUXDPTX::getAuxSelValue: ATC instance * 3 + local DFP. */ + atc->aux->sel = atc->index * 3; ret = dcpib_aux_init(dcp, atc->aux); if (ret) - return ret; + goto out; atc_route_stop(dcp, atc); ret = atc_route_start_sel(dcp, atc, ATC_SEL_AUX0); if (!ret) @@ -586,6 +639,8 @@ static int atc_read_edid(struct dcpib *dcp, u8 *buf, size_t size) atc_route_stop(dcp, atc); if (was_started) atc_route_start(dcp, atc); +out: + mutex_unlock(&atc_aux_lock); return ret; } @@ -596,22 +651,37 @@ static int atc_read_edid(struct dcpib *dcp, u8 *buf, size_t size) static int atc_detect(struct dcpib *dcp, bool *flipped) { struct dcpib_atc *atc = dcp->phy_priv; - int ret = dcpib_pd_sink(atc->cur->pd, flipped); + int ret = 0; + mutex_lock(&atc_owner_lock); atc->next = atc->cur; - if (ret) - return ret; + /* Keep a monitor on its controller, including while userspace blanks it. */ + if (atc_owner[atc->cur->index] == dcp->dev) { + ret = dcpib_pd_sink(atc->cur->pd, flipped, &atc->cur->next_lanes); + if (ret > 0 && (atc->cur->swap != *flipped || + atc->cur->lanes != atc->cur->next_lanes)) + dcp->hpd = 0; + if (ret) + goto out; + /* Unplug powers down in KMS; release on the next poll. */ + if (!atc->cur->active) + atc_owner[atc->cur->index] = NULL; + } for (unsigned int i = 0; i < atc->nports; i++) { struct dcpib_atc_port *port = &atc->port[i]; - if (port == atc->cur || dcpib_pd_sink(port->pd, flipped) <= 0) + if (atc_owner[port->index] || + dcpib_pd_sink(port->pd, flipped, &port->next_lanes) <= 0) continue; + atc_owner[port->index] = dcp->dev; atc->next = port; - /* A plug the other port's HPD state does not show yet. */ dcp->hpd = 0; - return 1; + ret = 1; + break; } - return 0; +out: + mutex_unlock(&atc_owner_lock); + return ret; } /* @@ -625,21 +695,24 @@ static void atc_select(struct dcpib *dcp) if (!port || port == atc->cur) return; - if (atc->cur->active) - atc_deactivate(dcp); + if (atc->cur->active && atc_deactivate(dcp)) + return; + mutex_lock(&atc_owner_lock); + if (atc_owner[atc->cur->index] == dcp->dev) + atc_owner[atc->cur->index] = NULL; + mutex_unlock(&atc_owner_lock); dev_info(dcp->dev, "USB-C display on ATC%u now, was ATC%u\n", port->index, atc->cur->index); atc->cur = port; dcp->pd = port->pd; dcp->dcp_output = port->dfp; - if (dcpib_dptx_connect(dcp, 0)) - dev_err(dcp->dev, "DPTX connect to ATC%u failed\n", port->index); } static const struct dcpib_phy_ops atc_ops = { .activate = atc_activate, .deactivate = atc_deactivate, .set_link_rate = atc_set_link_rate, + .max_lane_count = atc_max_lane_count, .set_drive = atc_set_drive, .set_route = atc_set_route, .set_orientation = atc_set_orientation, @@ -648,12 +721,12 @@ static const struct dcpib_phy_ops atc_ops = { .select = atc_select, .max_link_rate = DCPIB_LINK_RATE_HBR2, /* - * Modes up to 1920x1080@60 and 1600x1200@60 (and 2560x1440@30) show, - * 1920x1200@60 and anything faster stay black at HBR2 with no error: - * the DCP's pixel clock on the ATC path tops out between 162 and - * about 190 MHz with the firmware on its iBoot interface. + * Keep the iBoot path within the tested active-pixel budget. This + * permits 2560x1440@30 and 1920x1200@60; the latter is verified + * through a USB-C to HDMI adapter at a 154 MHz pixel clock. + * Higher-rate modes still need display-clock bring-up. */ - .max_pixel_rate = 130000000, + .max_pixel_rate = 140000000, /* * 720x480@60 and 720x576@50 (27 MHz) show, 640x480@60 (25.2 MHz) * stays black here while HDMI shows it. @@ -691,7 +764,10 @@ static int atc_port_init(struct dcpib *dcp, struct dcpib_atc *atc, port->dfp = 3; of_property_read_u32(np, "apple,dfp-endpoint", &port->dfp); port->index = port->dfp; - port->dp_clock = dp_clock; + port->lanes = port->next_lanes = 4; + if (port->index >= 4) + return -EINVAL; + port->dp_clock = dp_clock + port->index * 8; port->aux = &atc->aux; port->tunable[0] = of_get_property(np, "apple,tunable-pre", &port->tunable_len[0]); @@ -710,12 +786,20 @@ static int atc_port_init(struct dcpib *dcp, struct dcpib_atc *atc, dev_info(dcp->dev, "ATC%u: powered down\n", port->index); return 0; } + /* A different DCP may already be driving this port. */ + if (atc_owner[port->index] || + ((readl(port->base + ATC_XBAR + 0x44) >> 20) & 0xf) != + dcp->dp_source * 2) + return 0; /* Common block out of reset and AUX up, as aura's activation leaves it. */ cfg = readl(port->base + ATC_CFG); port->active = (cfg & 0x1f) == 0x1b; - port->swap = (readl(port->base + 0x4c) & 0x3ffe0) == 0x100; - port->route_started = (readl(port->base + ATC_XBAR) & 1) && - (readl(port->base + ATC_XBAR + 0x3c) & 1); + if ((readl(port->base + 0x4c) & 0x1f) == 0x10 || + (readl(port->base + 0x4c) & 0x1f) == 0x11) + port->lanes = port->next_lanes = 2; + port->swap = !!(readl(port->base + ATC_CFG + 8) & BIT(1)); + port->route_started = (readl(port->base + ATC_XBAR) & BIT(dcp->dp_source * 2)) && + (readl(port->base + ATC_XBAR + 0x3c) & BIT(dcp->dp_source * 2)); r = (readl(port->base + 0x2000) >> 19) & 7; if (port->active && (readl(port->base + 0x2040) & BIT(16)) && r < ARRAY_SIZE(atc_rates)) @@ -732,21 +816,35 @@ static int atc_port_init(struct dcpib *dcp, struct dcpib_atc *atc, int dcpib_atc_init(struct dcpib *dcp) { - struct device_node *np = dcp->dev->of_node; + struct device_node *ports __free(device_node) = + of_parse_phandle(dcp->dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: dcp->dev->of_node; + struct resource clock_res; void __iomem *dp_clock; struct dcpib_atc *atc; - bool flipped; int ret; atc = devm_kzalloc(dcp->dev, sizeof(*atc), GFP_KERNEL); if (!atc) return -ENOMEM; - dp_clock = atc_map(dcp, np, "dp-clock"); + ret = of_property_match_string(np, "reg-names", "dp-clock"); + if (ret < 0 || of_address_to_resource(np, ret, &clock_res)) + return -EINVAL; + /* Older J873 DTs describe ATC3's divider alone; each ATC has its own. */ + if (resource_size(&clock_res) == 4 && clock_res.start == 0x30002005cULL) + clock_res.start -= 3 * 8; + if (resource_size(&clock_res) < 28) + return -EINVAL; + dp_clock = devm_ioremap(dcp->dev, clock_res.start, resource_size(&clock_res)); if (!dp_clock) return -ENOMEM; - /* AUX output select 9: the crossbar's UFP aux0 */ - dcpib_aux_probe(dcp, &atc->aux, 9); + /* Shared AUX0 is serialized by atc_aux_lock. */ + atc->aux.regs = atc_map(dcp, np, "aux"); + atc->aux.ps = atc_map(dcp, np, "aux-ps"); + if (!atc->aux.ps) + atc->aux.regs = NULL; + guard(mutex)(&atc_owner_lock); /* One child per USB-C port, or the node itself for ATC3 alone. */ for_each_child_of_node_scoped(np, child) { if (!of_property_present(child, "apple,dfp-endpoint")) @@ -763,21 +861,15 @@ int dcpib_atc_init(struct dcpib *dcp) return ret; } - /* The bootloader's display port, else one with a sink, else the first. */ + /* Only adopt a bootloader route belonging to this DCP. */ atc->cur = &atc->port[0]; for (unsigned int i = 0; i < atc->nports; i++) { if (atc->port[i].active) { atc->cur = &atc->port[i]; - goto found; - } - } - for (unsigned int i = 0; i < atc->nports; i++) { - if (dcpib_pd_sink(atc->port[i].pd, &flipped) > 0) { - atc->cur = &atc->port[i]; + atc_owner[atc->cur->index] = dcp->dev; break; } } -found: atc->next = atc->cur; dcp->phy = &atc_ops; dcp->phy_priv = atc; diff --git a/drivers/gpu/drm/apple_dcpib/aux.c b/drivers/gpu/drm/apple_dcpib/aux.c index c8c6bf9ce3137..8de5877739c18 100644 --- a/drivers/gpu/drm/apple_dcpib/aux.c +++ b/drivers/gpu/drm/apple_dcpib/aux.c @@ -71,7 +71,13 @@ int dcpib_aux_init(struct dcpib *dcp, struct dcpib_aux *aux) aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, AUX_FUNC_EN_N); udelay(10); aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, 0); - writel(3 << 8, aux->regs + AUX_HW_RETRY); + /* + * AppleDPTXController::initAuxReplyTimeout: bits 21:8 are a 14-bit + * reply timeout, not Analogix's three-bit expected-delay field. + * The old value 3 let native reads pass but timed out EDID through + * a USB-C to HDMI adapter. Use Apple's timeout and retry interval. + */ + writel((3200 << 8) | (3 << 3), aux->regs + AUX_HW_RETRY); writel(BIT(7) | 1, aux->regs + AUX_DEFER_CTL); aux_update(aux->regs + AUX_SEL, 0x3f, aux->sel); return 0; diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index 6f894fb20b38b..56ef40e8fb35f 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -150,6 +150,7 @@ struct dcpib_phy_ops { int (*deactivate)(struct dcpib *dcp); int (*set_link_rate)(struct dcpib *dcp, u32 rate); /* DPCD units */ int (*set_lane_count)(struct dcpib *dcp, u32 lanes); /* optional */ + u32 (*max_lane_count)(struct dcpib *dcp); int (*set_drive)(struct dcpib *dcp, const struct dcpib_drive_settings *settings, u32 count); int (*set_route)(struct dcpib *dcp, bool enable); @@ -190,6 +191,7 @@ struct dcpib { struct apple_rtkit *rtk; struct workqueue_struct *wq; u32 inherited_afk_endpoints; + u32 dp_source; /* display-crossbar UFP endpoint; DPTX port 0 */ struct dcpib_ep *eps[DCPIB_NR_EPS]; struct dcpib_ep *iboot_ep; @@ -250,6 +252,7 @@ struct dcpib { /* iBoot state below, under lock */ struct mutex lock; + bool enabled; bool powered; struct dcpib_timing_mode *tmodes; unsigned int nr_tmodes; @@ -267,6 +270,7 @@ struct dcpib { * firmware's idle power off timer takes the link down 30 s later. */ struct delayed_work av_work; + struct delayed_work hpd_work; struct drm_plane plane; struct drm_crtc crtc; @@ -312,6 +316,7 @@ int dcpib_wait_hpd(struct dcpib *dcp); int dcpib_dptx_init(struct dcpib *dcp); int dcpib_dpav_init(struct dcpib *dcp); int dcpib_dptx_connect(struct dcpib *dcp, unsigned int port); +int dcpib_dptx_disconnect(struct dcpib *dcp, unsigned int port); int dcpib_dptx_set_hpd(struct dcpib *dcp, unsigned int port, bool hpd); /* aux.c */ @@ -336,7 +341,7 @@ int dcpib_hdmi_init(struct dcpib *dcp, struct device_node *np); /* pd.c */ struct spmi_device *dcpib_pd_get(struct dcpib *dcp, struct device_node *np); -int dcpib_pd_sink(struct spmi_device *pd, bool *flipped); +int dcpib_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes); int dcpib_pd_reconnect(struct dcpib *dcp); /* kms.c */ diff --git a/drivers/gpu/drm/apple_dcpib/dptx.c b/drivers/gpu/drm/apple_dcpib/dptx.c index 55752bd74e056..7a26e6ed22d82 100644 --- a/drivers/gpu/drm/apple_dcpib/dptx.c +++ b/drivers/gpu/drm/apple_dcpib/dptx.c @@ -135,7 +135,7 @@ static u32 dptx_call(struct dcpib_service *service, u16 group, u32 command, port->link_rate = arg; return 0; case DPTX_APCALL_GET_MAX_LANE_COUNT: - value = 4; + value = phy->max_lane_count ? phy->max_lane_count(dcp) : 4; break; case DPTX_APCALL_GET_ACTIVE_LANE_COUNT: value = port->lanes; @@ -307,6 +307,21 @@ int dcpib_dptx_connect(struct dcpib *dcp, unsigned int port) return ret; } +int dcpib_dptx_disconnect(struct dcpib *dcp, unsigned int port) +{ + struct dcpib_service *service = dcp->port[port].service; + __le32 status = 0; + int ret; + + if (!service) + return -ENODEV; + ret = dcpib_service_call(service, 8, 7, NULL, 0, 16, &status, + sizeof(status), 12); + if (ret || status) + return ret ?: -EIO; + return dcpib_dptx_set_hpd(dcp, port, false); +} + int dcpib_dptx_set_hpd(struct dcpib *dcp, unsigned int port, bool hpd) { struct dcpib_service *service = dcp->port[port].service; diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index f2cf9b5c80b95..cfda141d1d306 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -2,8 +2,9 @@ /* * Apple T8152 DCP on the iBoot interface: probe and bring-up. * - * The bootloader (aura) trains the display and hands the DCP over with its - * RTKit session running. This driver adopts that session, starts the iBoot, + * The bootloader (aura) leaves a successful display's RTKit session running, + * or quiesces it after a failed setup. This driver adopts or wakes that + * session, starts the iBoot, * DPAV and DPTX port endpoints, reconnects the DPTX port and asserts HPD, * then registers a DRM device whose flips are iBoot SET_SURFACE calls, in * the order aura's display_init_t8152 uses. @@ -101,11 +102,21 @@ static void dcpib_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) dma_free_coherent(dcp->dev, bfr->size, bfr->buffer, bfr->iova); } +static bool dcpib_rtk_syslog_debug(void *cookie, const char *context, + const char *message) +{ + /* Surface logging through fbcon would itself submit another surface. */ + return strstr(message, "setSurfaceRequest") || + strstr(message, "swap_submit_dcp") || + strstr(message, "validateRequest: inSize"); +} + static const struct apple_rtkit_ops dcpib_rtkit_ops = { .crashed = dcpib_rtk_crashed, .recv_message = dcpib_rtk_recv, .shmem_setup = dcpib_rtk_shmem_setup, .shmem_destroy = dcpib_rtk_shmem_destroy, + .syslog_is_debug = dcpib_rtk_syslog_debug, }; DEFINE_DRM_GEM_DMA_FOPS(dcpib_fops); @@ -125,16 +136,85 @@ static const struct drm_driver dcpib_drm_driver = { .fops = &dcpib_fops, }; -/* - * Adopt the bootloader's RTKit session. The T8152 DCP does not acknowledge - * AP QUIESCED, so a quiesced handoff cannot be negotiated, and an IOP INIT - * while its AP power is still ON panics the firmware ("Invalid AP power: - * 32"). Keep the running session instead and start the application - * endpoints explicitly (dcpib_ep_start), as drm/apple does for live M5 - * sessions. - */ +static bool dcpib_handoff_quiesced(struct dcpib *dcp) +{ + struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); + const char *version; + u32 running; + + if (dcp->hdmi || !chosen) + return false; + /* Despite its name, the loader property is one for a running core. */ + if (!of_property_read_u32(chosen, "apple,dcp-rtkit-quiesced", &running)) + return running == 0; + /* + * This older J873 loader predates the state property. Its failed + * display setup quiesces DCP and keeps iBoot's placeholder framebuffer; + * a successful setup hands over ON. Restrict this fallback to the + * verified loader build, rather than guessing for other handoffs. + */ + if (of_property_read_string(chosen, "asahi,m1n1-stage2-version", &version) || + strcmp(version, "v0.1.0-259-ga30a589a")) + return false; + for_each_child_of_node_scoped(chosen, np) { + u32 width, height; + + if (of_device_is_compatible(np, "simple-framebuffer") && + !of_property_read_u32(np, "width", &width) && + !of_property_read_u32(np, "height", &height)) + return width == 640 && height == 1136; + } + return false; +} + +/* The unused DCPEXT firmware is loaded and powered by iBoot. */ +static int dcpib_check_wake(struct dcpib *dcp) +{ + struct platform_device *pdev = to_platform_device(dcp->dev); + struct resource *res; + void __iomem *psd, *coproc; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "coproc-psd"); + if (!res) + return -EINVAL; + psd = devm_ioremap(dcp->dev, res->start, resource_size(res)); + if (!psd) + return -ENOMEM; + /* A read from the coprocessor while gated hangs the machine. */ + if (readl(psd + 0x80) & 7) + return -ENODEV; + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "coproc"); + if (!res) + return -EINVAL; + coproc = devm_ioremap(dcp->dev, res->start, resource_size(res)); + if (!coproc) + return -ENOMEM; + dev_info(dcp->dev, "firmware handoff: CPU control %#x status %#x\n", + readl(coproc + 0x44), readl(coproc + 0x48)); + return (readl(coproc + 0x44) & BIT(4)) ? 0 : -ENODEV; +} + +/* Wake only a quiesced session: IOP INIT on a running DCP can panic it. */ static int dcpib_boot(struct dcpib *dcp) { + if ((!dcp->hdmi && + of_property_read_bool(dcp->dev->of_node, "apple,rtkit-wake")) || + dcpib_handoff_quiesced(dcp)) { + int ret; + + if (of_property_read_bool(dcp->dev->of_node, "apple,rtkit-wake")) { + ret = dcpib_check_wake(dcp); + if (ret) + return ret; + } + dcp->rtk = apple_rtkit_init(dcp->dev, dcp, NULL, 0, + &dcpib_rtkit_ops); + if (IS_ERR(dcp->rtk)) + return PTR_ERR(dcp->rtk); + ret = apple_rtkit_wake(dcp->rtk); + dev_info(dcp->dev, "quiesced DCP wake: %d\n", ret); + return ret; + } dcp->rtk = apple_rtkit_init_adopted(dcp->dev, dcp, NULL, 0, &dcpib_rtkit_ops); if (IS_ERR(dcp->rtk)) @@ -283,7 +363,7 @@ static int dcpib_boot_surface(struct dcpib *dcp) struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); struct device_node *parent __free(device_node) = - of_property_read_bool(dcp->dev->of_node, "apple,hdmi") ? + dcp->dp_source ? of_find_node_by_path("/") : of_node_get(chosen); u32 width = 1280, height = 720, stride = 1280 * 4; int ret; @@ -313,7 +393,8 @@ static int dcpib_boot_surface(struct dcpib *dcp) * Large enough for the largest mode: while a SET_MODE switches, the * pipe briefly scans the current surface with the new mode's size. */ - size_t size = (size_t)stride * height; + /* A monitor may first appear after probe, with a larger mode list. */ + size_t size = max_t(size_t, (size_t)stride * height, 3840 * 2160 * 4); for (unsigned int i = 0; i < dcp->nr_tmodes; i++) size = max_t(size_t, size, (size_t)le32_to_cpu(dcp->tmodes[i].width) * @@ -372,13 +453,15 @@ static int dcpib_probe_inner(struct platform_device *pdev) int source = hdmi_np ? dcpib_hdmi_source(hdmi_np) : -ENODEV; struct dcpib *dcp; u32 inherited_afk_endpoints; + bool sink = true; int ret; /* * Without a USB-C display the bootloader drives HDMI from the main DCP * (source 0) and never starts DCPEXT0. */ - if (dev->of_node == hdmi_np && source != 1) { + if (dev->of_node == hdmi_np && source != 1 && + !of_property_present(dev->of_node, "apple,usb-c-ports")) { dev_info(dev, "%s\n", source == 0 ? "HDMI is on the main DCP" : "no bootloader HDMI link to adopt"); return -ENODEV; @@ -398,6 +481,10 @@ static int dcpib_probe_inner(struct platform_device *pdev) if (IS_ERR(dcp)) return PTR_ERR(dcp); dcp->dev = dev; + dcp->dp_source = dev->of_node == hdmi_np ? 1 : 0; + of_property_read_u32(dev->of_node, "apple,dp-source", &dcp->dp_source); + if (dcp->dp_source > 2) + return -EINVAL; dcp->inherited_afk_endpoints = inherited_afk_endpoints; platform_set_drvdata(pdev, dcp); mutex_init(&dcp->lock); @@ -413,18 +500,18 @@ static int dcpib_probe_inner(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "no scanout DART stream\n"); - dcp->hdmi = dev->of_node == hdmi_np || source == 0; + dcp->hdmi = source >= 0 && source == dcp->dp_source; if (dcp->hdmi && dev->of_node != hdmi_np) dev_info(dev, "HDMI from the main DCP (no USB-C display at boot)\n"); /* Read only: the pin belongs to a controller the AOP runs. */ - dcp->hpd_gpio = devm_fwnode_gpiod_get(dev, - of_fwnode_handle(dcp->hdmi ? hdmi_np : dev->of_node), "hpd", - GPIOD_ASIS, "hpd"); + dcp->hpd_gpio = dcp->hdmi ? + devm_fwnode_gpiod_get(dev, of_fwnode_handle(hdmi_np), "hpd", + GPIOD_ASIS, "hpd") : NULL; if (PTR_ERR(dcp->hpd_gpio) == -ENOENT) dcp->hpd_gpio = NULL; if (IS_ERR(dcp->hpd_gpio)) return dev_err_probe(dev, PTR_ERR(dcp->hpd_gpio), "no HPD GPIO\n"); - dcp->hpd = 1; + dcp->hpd = 0; ret = dcp->hdmi ? dcpib_hdmi_init(dcp, hdmi_np) : dcpib_atc_init(dcp); if (ret) return dev_err_probe(dev, ret, "no DisplayPort phy\n"); @@ -451,23 +538,41 @@ static int dcpib_probe_inner(struct platform_device *pdev) ret = dcpib_dptx_init(dcp); if (ret) return dev_err_probe(dev, ret, "no DPTX port service\n"); + if (dcp->pd) { + ret = dcpib_dptx_disconnect(dcp, 0); + if (ret) + return dev_err_probe(dev, ret, "cannot release inherited DP link\n"); + } - ret = dcpib_dptx_connect(dcp, 0); - if (ret) - return dev_err_probe(dev, ret, "DPTX connect failed\n"); - ret = dcpib_dptx_set_hpd(dcp, 0, true); - if (ret) - return dev_err_probe(dev, ret, "DPTX hotplug failed\n"); - - ret = dcpib_wait_hpd(dcp); - if (ret) - return ret; - ret = dcpib_ib_get_modes(dcp); - if (ret) - return dev_err_probe(dev, ret, "no modes\n"); + /* + * USB-C negotiation can outlive probe or fail while a monitor sleeps. + * Register the connector first; the hotplug path owns all USB-C links. + */ + if (dcp->pd) + sink = false; + if (sink) { + ret = dcpib_dptx_connect(dcp, 0); + if (ret) + return dev_err_probe(dev, ret, "DPTX connect failed\n"); + ret = dcpib_dptx_set_hpd(dcp, 0, true); + if (ret) + return dev_err_probe(dev, ret, "DPTX hotplug failed\n"); + ret = dcpib_wait_hpd(dcp); + if (ret) + return ret; + ret = dcpib_ib_get_modes(dcp); + if (ret) + return dev_err_probe(dev, ret, "no modes\n"); + } ret = dcpib_boot_surface(dcp); if (ret) return dev_err_probe(dev, ret, "no boot surface\n"); + /* Keep an idle connector registered while the PD controller negotiates. */ + if (!sink) { + dev_info(dev, "waiting for a USB-C display\n"); + goto register_kms; + } + dcp->hpd = 1; /* * Without the bootloader's link (no display on the port at boot) the * phy starts cold, the right way round for the plug. @@ -493,18 +598,24 @@ static int dcpib_probe_inner(struct platform_device *pdev) dev_info(dev, "%u timing modes, %u color modes\n", dcp->nr_tmodes, dcp->nr_cmodes); +register_kms: ret = dcpib_kms_init(dcp); if (ret) return ret; - ret = dcpib_set_boot_mode(dcp); - if (ret) - dev_warn(dev, "boot mode not set again: %d\n", ret); + if (sink) { + ret = dcpib_set_boot_mode(dcp); + if (ret) + dev_warn(dev, "boot mode not set again: %d\n", ret); + } ret = drm_dev_register(&dcp->drm, 0); if (ret) return ret; WRITE_ONCE(dcp->ready, true); if (dcp->hpd_gpio || dcp->pd) drmm_kms_helper_poll_init(&dcp->drm); + if (dcp->pd) + queue_delayed_work(system_freezable_wq, &dcp->hpd_work, + msecs_to_jiffies(250)); drm_client_setup(&dcp->drm, NULL); return 0; } diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index 25481d4bd4f25..a93d5feb863c2 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -65,6 +65,10 @@ static bool dcpib_mode_fits(struct dcpib *dcp, const struct dcpib_timing_mode *t u64 pixels = (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) * dcpib_refresh(t); + /* Hotplug may return modes larger than the buffers allocated at probe. */ + if ((u64)ALIGN(le32_to_cpu(t->width) * 4, 64) * le32_to_cpu(t->height) > + dcp->scan[0].size) + return false; if (pixels < dcp->phy->min_pixel_rate || (dcp->phy->max_pixel_rate && pixels > dcp->phy->max_pixel_rate)) return false; @@ -130,10 +134,9 @@ static const struct dcpib_color_mode *dcpib_find_color(struct dcpib *dcp) } /* - * The largest mode from 50 to 60 Hz for the console, up to 1920x1080 on - * USB-C: on the 2-lane HBR link of the J873g USB-C monitor 1920x1080@60 - * works, while SET_MODE 1920x1200@60 crashes the firmware. Low refresh - * modes (2560x1440@30) are left to userspace. + * A conservative console mode from 50 to 60 Hz, up to 1920x1080 on + * USB-C. Userspace can select the larger modes, including 2560x1440@30 + * and 1920x1200@60, after the sink's EDID is available. */ static const struct dcpib_timing_mode *dcpib_preferred(struct dcpib *dcp) { @@ -242,6 +245,13 @@ static int dcpib_set_mode_locked(struct dcpib *dcp, const struct dcpib_timing_mode *t, const struct dcpib_color_mode *c); +/* With dcp->lock held; queued work will observe the cleared pending slot. */ +static void dcpib_cancel_swap_locked(struct dcpib *dcp) +{ + hrtimer_cancel(&dcp->swap_timer); + dcp->pending = -1; +} + /* Read the sink's EDID through the phy, if it can, and keep it. */ void dcpib_update_edid(struct dcpib *dcp) { @@ -276,32 +286,47 @@ dcpib_connector_detect(struct drm_connector *connector, bool force) { struct dcpib *dcp = to_dcpib(connector->dev); bool flipped = false; + enum drm_connector_status status; int hpd; + mutex_lock(&dcp->lock); if (dcp->hpd_gpio) hpd = gpiod_get_value_cansleep(dcp->hpd_gpio); else if (dcp->phy->detect) hpd = dcp->phy->detect(dcp, &flipped); - else - return dcp->nr_tmodes ? connector_status_connected : + else { + status = dcp->nr_tmodes ? connector_status_connected : connector_status_disconnected; - if (hpd < 0) - return connector_status_unknown; + goto out; + } + if (hpd < 0) { + status = connector_status_unknown; + goto out; + } if (hpd != dcp->hpd) { dev_info(dcp->dev, "sink %s\n", hpd ? "plugged" : "unplugged"); dcp->hpd = hpd; - mutex_lock(&dcp->lock); /* * USB-C: the DPTX port's HPD follows the PD controller, and a * new plug may come the other way round. */ if (dcp->pd) { + if (!hpd || dcp->powered) { + dcpib_cancel_swap_locked(dcp); + if (dcpib_dptx_disconnect(dcp, 0)) + dev_err(dcp->dev, "DPTX release failed\n"); + if (!dcpib_ib_set_power(dcp, false)) { + dcp->powered = false; + dcp->mode_set = false; + dcp->phy->deactivate(dcp); + } + } /* * A plug while the display stayed on (unplug and plug * between two polls): start the PHY cold again, the * new plug may come the other way round. */ - if (hpd && dcp->powered) + if (hpd) dcp->phy->deactivate(dcp); /* The sink may be on another port now. */ if (hpd && dcp->phy->select) @@ -311,31 +336,65 @@ dcpib_connector_detect(struct drm_connector *connector, bool force) /* The firmware talks AUX as soon as it sees HPD. */ if (hpd && dcp->phy->activate(dcp)) dev_err(dcp->dev, "phy activation failed\n"); - if (dcpib_dptx_set_hpd(dcp, 0, hpd)) + if (hpd && dcpib_dptx_connect(dcp, 0)) + dev_err(dcp->dev, "DPTX connect failed\n"); + if (hpd && dcpib_dptx_set_hpd(dcp, 0, true)) dev_err(dcp->dev, "DPTX HPD update failed\n"); } /* A new sink: the firmware reads its EDID, take the new lists. */ - if (hpd && (dcpib_wait_hpd(dcp) || dcpib_ib_get_modes(dcp))) + if (hpd && (dcpib_wait_hpd(dcp) || dcpib_ib_get_modes(dcp))) { dev_err(dcp->dev, "no modes from the new sink\n"); + dcp->nr_tmodes = 0; + dcp->nr_cmodes = 0; + /* A sleeping EIZO may need a fresh DP alt mode entry. */ + if (dcp->pd && time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { + dcp->pd_reset_time = jiffies; + schedule_work(&dcp->pd_reset_work); + } + } /* * The EDID once the firmware has read it, so the sink's DDC * answers, and before SET_MODE: reading it borrows the AUX path * while the firmware does no AUX. */ - if (hpd) + if (hpd && dcp->nr_tmodes) dcpib_update_edid(dcp); - /* The unplug dropped the link; SET_MODE trains it again. */ - if (hpd && dcp->powered && (dcp->mode_set || dcp->mode_failed)) { - struct dcpib_timing_mode t = dcp->cur_mode; + /* + * A fast reconnect can finish before userspace disables the CRTC. + * Restore its requested state even though unplug powered it off. + */ + if (hpd && dcp->enabled && dcp->cur_mode.valid) { + const struct dcpib_timing_mode *t = NULL; const struct dcpib_color_mode *c = dcpib_find_color(dcp); - - if (c) - dcpib_set_mode_locked(dcp, &t, c); + int ret = 0; + + for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { + const struct dcpib_timing_mode *candidate = &dcp->tmodes[i]; + + if (candidate->valid && candidate->width == dcp->cur_mode.width && + candidate->height == dcp->cur_mode.height && + candidate->fps == dcp->cur_mode.fps) { + t = candidate; + break; + } + } + if (t && c && !dcp->powered) { + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], + le32_to_cpu(t->width), le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (!ret) + ret = dcpib_ib_set_power(dcp, true); + dcp->powered = !ret; + } + if (t && c && !ret) + dcpib_set_mode_locked(dcp, t, c); } - mutex_unlock(&dcp->lock); } - return hpd && dcp->nr_tmodes ? connector_status_connected : - connector_status_disconnected; + status = hpd && dcp->nr_tmodes ? connector_status_connected : + connector_status_disconnected; +out: + mutex_unlock(&dcp->lock); + return status; } static const struct drm_connector_funcs dcpib_connector_funcs = { @@ -352,14 +411,25 @@ static int dcpib_plane_atomic_check(struct drm_plane *plane, { struct drm_plane_state *new = drm_atomic_get_new_plane_state(state, plane); struct drm_crtc_state *crtc_state = NULL; + struct dcpib *dcp = to_dcpib(plane->dev); + u32 width, height; + int ret; if (new->crtc) crtc_state = drm_atomic_get_new_crtc_state(state, new->crtc); /* The surface fills the whole mode; no scaling or positioning. */ - return drm_atomic_helper_check_plane_state(new, crtc_state, + ret = drm_atomic_helper_check_plane_state(new, crtc_state, DRM_PLANE_NO_SCALING, DRM_PLANE_NO_SCALING, false, false); + if (ret || !new->visible) + return ret; + /* The helper clips src/dst; raw src_w/src_h may exceed the CRTC. */ + if ((new->src.x1 | new->src.y1 | new->src.x2 | new->src.y2) & 0xffff) + return -EINVAL; + width = drm_rect_width(&new->src) >> 16; + height = drm_rect_height(&new->src) >> 16; + return (u64)ALIGN(width * 4, 64) * height <= dcp->scan[0].size ? 0 : -EINVAL; } static void dcpib_rect_grow(struct drm_rect *r, const struct drm_rect *add) @@ -390,6 +460,10 @@ static void dcpib_swap_locked(struct dcpib *dcp, unsigned int buf, u32 w, { int ret; + if (!dcp->powered || !dcp->mode_set || !dcp->hpd || + apple_rtkit_is_crashed(dcp->rtk)) + return; + /* The pipe must see the whole frame before it is swapped in. */ wmb(); ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[buf], w, h, pitch); @@ -446,23 +520,32 @@ static void dcpib_plane_atomic_update(struct drm_plane *plane, struct dcpib *dcp = to_dcpib(plane->dev); struct drm_framebuffer *fb = new->fb; struct drm_atomic_helper_damage_iter iter; - struct drm_rect clip, damage = { 0, 0, 0, 0 }; - struct drm_rect full = DRM_RECT_INIT(0, 0, fb ? fb->width : 0, - fb ? fb->height : 0); + struct drm_rect clip, source_clip, src, full, damage = { 0, 0, 0, 0 }; unsigned int pitch, back; struct iosys_map dst; s64 period, since; if (!fb || !new->visible) return; - pitch = (new->src_w >> 16) * 4; + src = DRM_RECT_INIT(new->src.x1 >> 16, new->src.y1 >> 16, + drm_rect_width(&new->src) >> 16, + drm_rect_height(&new->src) >> 16); + full = DRM_RECT_INIT(0, 0, drm_rect_width(&src), drm_rect_height(&src)); + pitch = ALIGN(drm_rect_width(&full) * 4, 64); drm_atomic_helper_damage_iter_init(&iter, old, new); - drm_atomic_for_each_plane_damage(&iter, &clip) + drm_atomic_for_each_plane_damage(&iter, &clip) { + if (!drm_rect_intersect(&clip, &src)) + continue; + drm_rect_translate(&clip, -src.x1, -src.y1); dcpib_rect_grow(&damage, &clip); + } if (!drm_rect_visible(&damage)) return; mutex_lock(&dcp->lock); + if (!dcp->powered || !dcp->mode_set || !dcp->hpd || + apple_rtkit_is_crashed(dcp->rtk)) + goto out; period = dcpib_period_ns(dcp); if (!READ_ONCE(buffered)) { /* Into the buffer on screen (tears during motion). */ @@ -487,7 +570,9 @@ static void dcpib_plane_atomic_update(struct drm_plane *plane, if (drm_rect_intersect(&clip, &full)) { iosys_map_set_vaddr(&dst, dcp->scan_wc[back]); iosys_map_incr(&dst, drm_fb_clip_offset(pitch, fb->format, &clip)); - drm_fb_memcpy(&dst, &pitch, shadow->data, fb, &clip); + source_clip = clip; + drm_rect_translate(&source_clip, src.x1, src.y1); + drm_fb_memcpy(&dst, &pitch, shadow->data, fb, &source_clip); } dcp->stale[back] = (struct drm_rect){ 0, 0, 0, 0 }; for (unsigned int i = 0; i < DCPIB_SCANOUT_BUFS; i++) @@ -498,12 +583,12 @@ static void dcpib_plane_atomic_update(struct drm_plane *plane, since = ktime_to_ns(ktime_sub(ktime_get(), dcp->last_swap)); if (dcp->pending < 0 && (!dcp->mode_set || since >= period)) { - dcpib_swap_locked(dcp, back, new->src_w >> 16, new->src_h >> 16, + dcpib_swap_locked(dcp, back, drm_rect_width(&full), drm_rect_height(&full), pitch); goto out; } - dcp->pending_w = new->src_w >> 16; - dcp->pending_h = new->src_h >> 16; + dcp->pending_w = drm_rect_width(&full); + dcp->pending_h = drm_rect_height(&full); dcp->pending_pitch = pitch; if (dcp->pending < 0) { dcp->pending = back; @@ -581,11 +666,11 @@ static int dcpib_set_mode_locked(struct dcpib *dcp, for (unsigned int i = 0; i < DCPIB_SCANOUT_BUFS; i++) dcp->stale[i] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); /* A pending frame has the old geometry. */ - dcp->pending = -1; + dcpib_cancel_swap_locked(dcp); /* As aura swaps after a modeset. */ ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], le32_to_cpu(t->width), le32_to_cpu(t->height), - le32_to_cpu(t->width) * 4); + ALIGN(le32_to_cpu(t->width) * 4, 64)); if (ret) dev_err(dcp->dev, "set_surface failed: %d\n", ret); return ret; @@ -656,19 +741,27 @@ static void dcpib_crtc_atomic_enable(struct drm_crtc *crtc, c = dcpib_find_color(dcp); if (!t || !c) goto out; + dcp->enabled = true; if (!dcp->powered) { /* The phy starts cold first; the firmware then trains. */ ret = dcp->phy->activate(dcp); - if (ret) + if (ret) { dev_err(dcp->dev, "phy activation failed: %d\n", ret); + goto out; + } /* A pipe powered on without a surface fetches from a null base. */ - ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], dcp->boot_w, - dcp->boot_h, dcp->boot_stride); - if (ret) + ret = dcpib_ib_set_surface(dcp, dcp->scan_dva[dcp->front], + le32_to_cpu(t->width), le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (ret) { dev_err(dcp->dev, "set_surface failed: %d\n", ret); + goto out; + } ret = dcpib_ib_set_power(dcp, true); - if (ret) + if (ret) { dev_err(dcp->dev, "set_power failed: %d\n", ret); + goto out; + } dcp->powered = !ret; } if (dcp->mode_set && !memcmp(t, &dcp->cur_mode, sizeof(*t))) @@ -712,6 +805,8 @@ static void dcpib_crtc_atomic_disable(struct drm_crtc *crtc, * monitor goes to sleep. The next enable sets the mode again. */ mutex_lock(&dcp->lock); + dcp->enabled = false; + dcpib_cancel_swap_locked(dcp); if (dcp->powered) { ret = dcpib_ib_set_power(dcp, false); if (ret) { @@ -765,23 +860,51 @@ static void dcpib_pd_reset_work(struct work_struct *work) int ret; dev_info(dcp->dev, "USB-C sink does not answer, entering DP alt mode again\n"); - ret = dcpib_pd_reconnect(dcp); + /* The reset may finish between polls. Release the old link explicitly. */ + mutex_lock(&dcp->lock); + dcpib_cancel_swap_locked(dcp); + ret = dcpib_dptx_disconnect(dcp, 0); + if (!ret) + ret = dcpib_ib_set_power(dcp, false); + if (!ret) { + dcp->powered = false; + dcp->mode_set = false; + ret = dcp->phy->deactivate(dcp); + } if (ret) { - dev_err(dcp->dev, "DP alt mode entry failed: %d\n", ret); + mutex_unlock(&dcp->lock); + dev_err(dcp->dev, "cannot release old DP link: %d\n", ret); return; } - /* The controller unplugged and plugged: run the plug path. */ - mutex_lock(&dcp->lock); dcp->hpd = 0; + ret = dcpib_pd_reconnect(dcp); mutex_unlock(&dcp->lock); + if (ret) { + dev_err(dcp->dev, "DP alt mode entry failed: %d\n", ret); + return; + } drm_kms_helper_hotplug_event(&dcp->drm); } +static void dcpib_hpd_work(struct work_struct *work) +{ + struct dcpib *dcp = container_of(to_delayed_work(work), struct dcpib, + hpd_work); + + if (!READ_ONCE(dcp->ready)) + return; + drm_helper_hpd_irq_event(&dcp->drm); + if (READ_ONCE(dcp->ready)) + queue_delayed_work(system_freezable_wq, &dcp->hpd_work, + msecs_to_jiffies(250)); +} + void dcpib_kms_stop(struct dcpib *dcp) { if (!dcp->kms_work_ready) return; + cancel_delayed_work_sync(&dcp->hpd_work); hrtimer_cancel(&dcp->swap_timer); cancel_work_sync(&dcp->swap_work); cancel_work_sync(&dcp->pd_reset_work); @@ -795,12 +918,13 @@ static void dcpib_swap_stop(void *data) int dcpib_kms_init(struct dcpib *dcp) { struct drm_device *drm = &dcp->drm; - u32 max_w = 1920, max_h = 1080; + u32 max_w = 3840, max_h = 2160; int ret; dcp->pending = -1; INIT_WORK(&dcp->swap_work, dcpib_swap_work); INIT_WORK(&dcp->pd_reset_work, dcpib_pd_reset_work); + INIT_DELAYED_WORK(&dcp->hpd_work, dcpib_hpd_work); hrtimer_setup(&dcp->swap_timer, dcpib_swap_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); dcp->kms_work_ready = true; @@ -855,6 +979,8 @@ int dcpib_kms_init(struct dcpib *dcp) if (dcp->hpd_gpio || dcp->pd) dcp->connector.polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; + if (dcp->pd) + dcp->connector.polled = DRM_CONNECTOR_POLL_HPD; ret = drm_connector_attach_encoder(&dcp->connector, &dcp->encoder); if (ret) return ret; diff --git a/drivers/gpu/drm/apple_dcpib/pd.c b/drivers/gpu/drm/apple_dcpib/pd.c index 84ea367feb1cb..45b46c67622cd 100644 --- a/drivers/gpu/drm/apple_dcpib/pd.c +++ b/drivers/gpu/drm/apple_dcpib/pd.c @@ -26,6 +26,7 @@ #define ACE3_REG_CMD1 0x08 #define ACE3_REG_DATA1 0x09 #define ACE3_REG_STATUS 0x1a +#define ACE3_REG_POWER_STATE 0x20 #define ACE3_REG_DATA_STATUS 0x5f #define STATUS_PLUG_PRESENT BIT(0) @@ -124,41 +125,60 @@ int dcpib_pd_reconnect(struct dcpib *dcp) { int ret; + device_lock(&dcp->pd->dev); /* Gaid resets the controller before it can report completion. */ ret = spmi_command_wakeup(dcp->pd); if (!ret) ret = ace3_write(dcp->pd, ACE3_REG_CMD1, "Gaid", 4); if (ret) - return ret; + goto out; for (int i = 0; i < 60; i++) { msleep(500); ret = ace3_cmd(dcp->pd, "SSPS", 0); if (!ret) - return 0; + break; } +out: + device_unlock(&dcp->pd->dev); return ret; } /* 1 with a DisplayPort sink in DP alt mode and HPD high, 0 without. */ -int dcpib_pd_sink(struct spmi_device *pd, bool *flipped) +int dcpib_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes) { - u8 status[4], data[4]; + u8 status[4], data[4], power; int ret; + /* Serialize the logical register window with the USB4 port monitor. */ + device_lock(&pd->dev); /* Without a plug the controller sleeps and ignores selects. */ ret = spmi_command_wakeup(pd); if (ret) - return ret; + goto out; + ret = ace3_read(pd, ACE3_REG_POWER_STATE, &power, sizeof(power)); + if (ret) + goto out; + /* Register access alone does not enable the alt-mode policy engine. */ + if (power) { + ret = ace3_cmd(pd, "SSPS", 0); + if (ret) + goto out; + } ret = ace3_read(pd, ACE3_REG_STATUS, status, sizeof(status)); if (!ret) ret = ace3_read(pd, ACE3_REG_DATA_STATUS, data, sizeof(data)); if (ret) - return ret; + goto out; *flipped = status[0] & STATUS_UPSIDE_DOWN; + /* Pin D/F shares the cable with USB3; C/E uses all four DP lanes. */ + *lanes = get_unaligned_le32(data) & BIT(5) ? 2 : 4; /* The sink answers AUX once it raised HPD, not at alt mode entry. */ - return (status[0] & STATUS_PLUG_PRESENT) && + ret = (status[0] & STATUS_PLUG_PRESENT) && (get_unaligned_le32(data) & DATA_DP_CONNECTION) && (get_unaligned_le32(data) & DATA_HPD_LEVEL); +out: + device_unlock(&pd->dev); + return ret; } /* The PD controller @np's apple,usb-pd points at, NULL without one. */ From 839885561f657384263d5323c77520407e1ced16 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:53:55 +0100 Subject: [PATCH 079/112] arm64: dts: apple: j873: add DCPEXT1 and share the USB-C ports Describe DCPEXT1 (ADT dcpext1: ASC at 0x502e00000, post-office mailbox 7, IRQs 306/266, DARTs dart-dcpext1 SID 23 and dart-dispext1 SID 0) with its PMGR2 PSD admission register. Give each controller its crossbar source, let DCPEXT0 and DCPEXT1 use the main DCP's USB-C port children, and widen dp-clock to the PMGR ATC DP clock dividers of all ATCs. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 58 ++++++++++++++++--- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi index e41c4008c425f..8929f26c8bcc5 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -1,9 +1,10 @@ // SPDX-License-Identifier: GPL-2.0+ OR MIT /* - * J873g displays: the rear USB-C ports and the HDMI port, driven through + * J873g displays: three controllers for the rear USB-C and HDMI ports, + * driven through * the DCP firmware's iBoot interface (apple,t8152-dcp-iboot). The - * bootloader trains the displays and hands both DCPs over with their RTKit - * sessions running. + * bootloader hands over running or quiesced RTKit sessions. Unused + * controllers can claim another USB-C monitor through the shared crossbar. * * Resources are from the 26A434 ADT: dcp (iop,ascwrap-v8, post-office * mailbox 5 with alias: 0x316020000 + 2 * 5 * 0x80), dart-dcp (SID 23), @@ -37,6 +38,17 @@ status = "okay"; }; +&dcpext1_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + +&dispext1_dart { + reg-names = "dart", "dapf"; + apple,dma-range = <0x108 0x0 0x8 0x0>; + status = "okay"; +}; + / { soc { /* @@ -93,7 +105,7 @@ dcp_iboot: display@286e00000 { compatible = "apple,t8152-dcp-iboot"; reg = <0x2 0x86e00000 0x0 0x74000>, - <0x3 0x0002005c 0x0 0x4>, + <0x3 0x00020044 0x0 0x1c>, <0x3 0x1a760000 0x0 0x4000>, <0x3 0x00700460 0x0 0x4>; /* aux: ADT dptx0-aux, aux-ps: PMGR GLOBAL_AUX_CTRL0 */ @@ -108,6 +120,7 @@ * faults on entries with the DART's no-cache bit. */ dma-coherent; + apple,dp-source = <0>; /* * The display pipe's own stream: a separate device, so @@ -429,7 +442,7 @@ }; /* - * HDMI: DCPEXT0 (post-office mailbox 6) drives the dedicated + * DCPEXT0 (post-office mailbox 6) can drive USB-C, or the dedicated * dptx-phy through the PS190 converter. ADT dcpext0, * dart-dcpext0 and dart-dispext0. */ @@ -450,14 +463,17 @@ <0x3 0x1a764000 0x0 0x4000>, <0x3 0x00700480 0x0 0x4>, <0x3 0x007016c0 0x0 0x4>, - <0x3 0x00700e00 0x0 0x4>; + <0x3 0x00700e00 0x0 0x4>, + <0x3 0x03a12c00 0x0 0xc0>; /* aux: ADT dptx1-aux, aux-ps: PMGR GLOBAL_AUX_CTRL1 */ /* Read-only PMGR DPTX_PHY and DISPEXT0_CPU admission checks. */ reg-names = "coproc", "phy-core", "phy-apb", "aux", "aux-ps", - "phy-ps", "coproc-ps"; + "phy-ps", "coproc-ps", "coproc-psd"; mboxes = <&dcpext_mbox>; iommus = <&dcpext0_dart 23>; dma-coherent; + apple,dp-source = <1>; + apple,usb-c-ports = <&dcp_iboot>; apple,hdmi; /* ADT dp2hdmi-gpio0 function-hdmi_hpd */ hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; @@ -467,5 +483,33 @@ dma-coherent; }; }; + + dcpext1_mbox: mailbox@316020700 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020700 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* ADT dcpext1: crossbar UFP2, firmware SID23, scanout SID0. */ + dcpext1_iboot: display@502e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x5 0x02e00000 0x0 0x74000>, + <0x3 0x03a12d00 0x0 0xc0>; + reg-names = "coproc", "coproc-psd"; + mboxes = <&dcpext1_mbox>; + iommus = <&dcpext1_dart 23>; + dma-coherent; + apple,dp-source = <2>; + apple,usb-c-ports = <&dcp_iboot>; + + scanout { + iommus = <&dispext1_dart 0>; + dma-coherent; + }; + }; + }; }; From f9241cd7222d60de4483fcde970c066424dfd5f2 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 07:22:36 +0100 Subject: [PATCH 080/112] drm/apple_dcpib: match the firmware mode on the exact refresh rate The firmware takes a mode as width, height and a 16.16 refresh rate and picks the timing itself. For the EIZO EV2780 on a J873g rear USB-C port it lists 2560x1440 twice near 60 Hz: the sink's detailed timing at 59.951 Hz (241.5 MHz, CVT reduced blanking) and a 60.000 Hz standard mode it adds on its own (byte 0 bit 6), which it drives with CVT at 312.25 MHz (htotal 3488, vtotal 1493, an 89.5 kHz line rate). dcpib_find_mode() compared whole Hz, so both matched the EDID's 2560x1440@59.951 and the first, the standard mode, won. The EV2780 does not take that line rate and shows an error instead of a picture, while the link trains and the sink's DP test CRC still counts frames. Compare the DRM mode's exact rate, computed as drm_mode_vrefresh() does, with the firmware's, and take the nearest within 1 Hz. Tested on the J873g together with the following USB-C clock fix (before it, USB-C does not offer 2560x1440@60): the EV2780 gets 2560x1440 at 241.5 MHz (htotal 2720, vtotal 1481) instead of 312.25 MHz and shows the picture. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/kms.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index a93d5feb863c2..63b84366a71d9 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -75,26 +75,44 @@ static bool dcpib_mode_fits(struct dcpib *dcp, const struct dcpib_timing_mode *t return pixels * 24 * 112 / 100 <= link; } +/* @mode's refresh rate in 16.16, as drm_mode_vrefresh() computes it. */ +static u32 dcpib_mode_fps(const struct drm_display_mode *mode) +{ + u64 num = mul_u32_u32(mode->clock, 1000) << 16; + u64 den = mul_u32_u32(mode->htotal, mode->vtotal); + + if (mode->flags & DRM_MODE_FLAG_INTERLACE) + num *= 2; + if (mode->flags & DRM_MODE_FLAG_DBLSCAN) + den *= 2; + if (mode->vscan > 1) + den *= mode->vscan; + return den ? DIV64_U64_ROUND_CLOSEST(num, den) : 0; +} + /* * The firmware mode for @mode: same size, refresh rate within 1 Hz (EDID's - * 59.94 against the firmware's 60.00), the nearest one. + * 59.94 against the firmware's 60.00), the nearest one by the exact rate. + * The firmware picks the timing from the rate, and next to the sink's + * 2560x1440@59.951 (241.5 MHz) it lists a 60.000 standard mode that it + * drives with CVT at 312.25 MHz, which the J873g's USB-C EV2780 rejects. */ static const struct dcpib_timing_mode * dcpib_find_mode(struct dcpib *dcp, const struct drm_display_mode *mode) { const struct dcpib_timing_mode *best = NULL; - int refresh = drm_mode_vrefresh(mode); + u32 fps = dcpib_mode_fps(mode); for (unsigned int i = 0; i < dcp->nr_tmodes; i++) { const struct dcpib_timing_mode *t = &dcp->tmodes[i]; if (!t->valid || le32_to_cpu(t->width) != mode->hdisplay || le32_to_cpu(t->height) != mode->vdisplay || - abs(dcpib_refresh(t) - refresh) > 1 || + abs_diff(le32_to_cpu(t->fps), fps) > 0x10000 || !dcpib_mode_fits(dcp, t)) continue; - if (!best || abs(dcpib_refresh(t) - refresh) < - abs(dcpib_refresh(best) - refresh)) + if (!best || abs_diff(le32_to_cpu(t->fps), fps) < + abs_diff(le32_to_cpu(best->fps), fps)) best = t; } return best; From c5722846651b087e7666f1a387df7b8e8d445caa Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:57:23 +0100 Subject: [PATCH 081/112] drm/apple_dcpib: clock USB-C DisplayPort from the ATC's PMGR DP clock USB-C modes above about 165 MHz pixel clock stayed black with no error: the link trained, the firmware set the mode, and the monitor showed nothing. So did 640x480 (25.2 MHz). The driver capped the ATC path at 140 and floored it at 20 Mpixel/s, which left 2560x1440 at 30 Hz. The ATC's DP clock switch (ATCPHY_DP_CLKSWITCH_SELECT/ENABLE/STATUS at the PHY's CFG block + 0x14/0x18/0x1c) chooses where each DP pixel clock comes from. AppleT8152TypeCPhy::aciophy_configure_dp_clks programs the PMGR DP clock divider for the link rate (setATCDPClkSrcSel), then aciophy_configure_dp_clkswitch_control(pclk, rate) sets SWITCHn_CLK_SELECT to n (PMGR DP clock n - 1), DPTX_OUT_CLKn_MODE to 0, and the switch's PMGR enable (bit 1 + 7 * (n - 1)), and waits for the matching status bit. The driver selected source 0 with enable bit 0 instead, so the stream clock never followed the divider. That is also why changing the divider moved nothing but the link. Select PCLK1 from PMGR DP0 after the divider is written, and stop it the same way. Drop the pixel-rate cap and floor. Tested on the J873g with an EIZO EV2780 on a rear USB-C port (two lanes at HBR2): 2560x1440@59.951 (241.5 MHz) shows. For 640x480@60, @59.94 and 720x480 the link trains and the sink's DP test CRC (DPCD 0x246 TEST_CRC_COUNT) advances once per frame, stable for a still picture and changing with the content. A USB-C to HDMI adapter (1920x1200@59.95) and HDMI are unchanged. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/atc.c | 55 +++++++++++++++++++++---------- drivers/gpu/drm/apple_dcpib/kms.c | 4 +-- 2 files changed, 39 insertions(+), 20 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/atc.c b/drivers/gpu/drm/apple_dcpib/atc.c index 8a2d7ff1bae29..83cbf64ca205a 100644 --- a/drivers/gpu/drm/apple_dcpib/atc.c +++ b/drivers/gpu/drm/apple_dcpib/atc.c @@ -23,6 +23,22 @@ #define ATC_AON 0x1e00 #define ATC_CFG 0x60000 #define ATC_XBAR 0x74000 +/* + * ATCPHY_CFG_BLK_ATCPHY_DP_CLKSWITCH_{SELECT,ENABLE,STATUS}_CONTROL_REGS + * (AppleT8152TypeCPhy::aciophy_configure_dp_clkswitch_control). DP pixel + * clock n (1..4) runs from switch n: SELECT field n is n for PMGR DP clock + * n - 1, 7 for none, and ENABLE/STATUS bit 1 + 7 * (n - 1) gates that + * PMGR clock. This driver uses PCLK1, from PMGR DP0, whose divider + * atc_clock_write() sets for the link rate. + */ +#define ATC_CLKSW_SELECT (ATC_CFG + 0x14) +#define ATC_CLKSW_ENABLE (ATC_CFG + 0x18) +#define ATC_CLKSW_STATUS (ATC_CFG + 0x1c) +#define ATC_CLKSW_PCLK1_SEL GENMASK(2, 0) +#define ATC_CLKSW_PCLK1_MODE BIT(12) +#define ATC_CLKSW_PCLK1_OFF 7 +#define ATC_CLKSW_PCLK1_DP0 1 +#define ATC_CLKSW_PCLK1_EN BIT(1) #define ATC_TIMEOUT_US 10000 struct dcpib_atc_port { @@ -236,10 +252,11 @@ static int atc_dp_stop(struct dcpib *dcp, struct dcpib_atc_port *atc) u32 reg; atc_route_stop(dcp, atc); - atc_update(atc, ATC_CFG + 0x14, 7, 7); - atc_update(atc, ATC_CFG + 0x18, 1, 0); - if (readl_poll_timeout(atc->base + ATC_CFG + 0x1c, reg, !(reg & 1), 1, - ATC_TIMEOUT_US)) { + atc_update(atc, ATC_CLKSW_SELECT, ATC_CLKSW_PCLK1_SEL | ATC_CLKSW_PCLK1_MODE, + ATC_CLKSW_PCLK1_OFF); + atc_update(atc, ATC_CLKSW_ENABLE, ATC_CLKSW_PCLK1_EN, 0); + if (readl_poll_timeout(atc->base + ATC_CLKSW_STATUS, reg, + !(reg & ATC_CLKSW_PCLK1_EN), 1, ATC_TIMEOUT_US)) { dev_err(dcp->dev, "ATC%u: DPTX clock stop failed\n", atc->index); return -ETIMEDOUT; } @@ -279,12 +296,11 @@ static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) { static const u32 tx_ctrl[] = { 0x4eb0, 0x8b10, 0xdeb0, 0x11b10 }; static const u32 wake_count[] = { 0xbb5, 0xbb7, 0xbb8, 0xbb9 }; + u32 reg; int ret; if (readl(atc->dp_clock) & BIT(30)) return -EBUSY; - atc_update(atc, ATC_CFG + 0x14, 7, 0); - atc_update(atc, ATC_CFG + 0x18, 1, 1); if (!r) { atc_update(atc, 0xe10, BIT(2), BIT(2)); atc_update(atc, 0xe08, BIT(29), BIT(29)); @@ -337,6 +353,21 @@ static int atc_dp_start(struct dcpib *dcp, struct dcpib_atc_port *atc, u32 r) dev_err(dcp->dev, "ATC%u: DP clock change timeout\n", atc->index); return ret; } + /* + * Clock the stream from PMGR DP0 at the link-rate divider just set, + * as AppleT8152TypeCPhy::aciophy_configure_dp_clks does after + * setATCDPClkSrcSel. Selecting source 0 instead left the pixel + * clock independent of the divider and blanked every mode above + * about 165 MHz. + */ + atc_update(atc, ATC_CLKSW_SELECT, ATC_CLKSW_PCLK1_SEL | ATC_CLKSW_PCLK1_MODE, + ATC_CLKSW_PCLK1_DP0); + atc_update(atc, ATC_CLKSW_ENABLE, ATC_CLKSW_PCLK1_EN, ATC_CLKSW_PCLK1_EN); + if (readl_poll_timeout(atc->base + ATC_CLKSW_STATUS, reg, + reg & ATC_CLKSW_PCLK1_EN, 1, ATC_TIMEOUT_US)) { + dev_err(dcp->dev, "ATC%u: DP pixel clock does not start\n", atc->index); + return -ETIMEDOUT; + } ret = atc_route_start(dcp, atc); if (ret) return ret; @@ -720,18 +751,6 @@ static const struct dcpib_phy_ops atc_ops = { .detect = atc_detect, .select = atc_select, .max_link_rate = DCPIB_LINK_RATE_HBR2, - /* - * Keep the iBoot path within the tested active-pixel budget. This - * permits 2560x1440@30 and 1920x1200@60; the latter is verified - * through a USB-C to HDMI adapter at a 154 MHz pixel clock. - * Higher-rate modes still need display-clock bring-up. - */ - .max_pixel_rate = 140000000, - /* - * 720x480@60 and 720x576@50 (27 MHz) show, 640x480@60 (25.2 MHz) - * stays black here while HDMI shows it. - */ - .min_pixel_rate = 20000000, }; /* PMGR registers, inside blocks their power domain driver has claimed. */ diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index 63b84366a71d9..a239162e32363 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -153,8 +153,8 @@ static const struct dcpib_color_mode *dcpib_find_color(struct dcpib *dcp) /* * A conservative console mode from 50 to 60 Hz, up to 1920x1080 on - * USB-C. Userspace can select the larger modes, including 2560x1440@30 - * and 1920x1200@60, after the sink's EDID is available. + * USB-C. Userspace can select the larger modes, including 2560x1440@60, + * after the sink's EDID is available. */ static const struct dcpib_timing_mode *dcpib_preferred(struct dcpib *dcp) { From c6ab3a3d4f3254307089887401b7058ad17c9622 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 08:12:02 +0100 Subject: [PATCH 082/112] drm/apple_dcpib: check modes against the route's lanes dcpib_mode_fits() measured a mode against the lane count of the last link training. That is not the link's capability: when an EIZO EV2780 on a rear USB-C port drops and reasserts HPD while the display is off (it does so a few seconds into its power save), the firmware trains the link without a stream, with a single lane. 2560x1440@60 then no longer fits one HBR2 lane, the atomic check refuses it, and the display stays off when the compositor powers the outputs back on. Use the lane count the firmware may train, which GET_MAX_LANE_COUNT already reports: the USB-C route's from the DP alt mode pin assignment, four for the other phys. The link rate in the same check is already the PHY's maximum rather than the trained one. Tested on the J873g: the stuck state had trained_lanes 1 on DCPEXT0 with the EV2780 at 2560x1440@59.951; with the fix, a display-off cycle with a PD disconnect and reconnect of that monitor in between brings all three outputs (two USB-C, HDMI) back at their modes. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/dcpib.h | 2 -- drivers/gpu/drm/apple_dcpib/dptx.c | 2 -- drivers/gpu/drm/apple_dcpib/kms.c | 8 ++++++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index 56ef40e8fb35f..a77fa023e2ef3 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -173,8 +173,6 @@ struct dcpib_port { struct dcpib_service *service; u32 link_rate; /* DPCD units */ u32 lanes; - /* lanes of the last training, kept while the link is down */ - u32 trained_lanes; /* last drive settings the firmware set, for GET_DRIVE_SETTINGS */ struct dcpib_drive_settings drive[4]; u32 drive_count; diff --git a/drivers/gpu/drm/apple_dcpib/dptx.c b/drivers/gpu/drm/apple_dcpib/dptx.c index 7a26e6ed22d82..70968390285b3 100644 --- a/drivers/gpu/drm/apple_dcpib/dptx.c +++ b/drivers/gpu/drm/apple_dcpib/dptx.c @@ -150,8 +150,6 @@ static u32 dptx_call(struct dcpib_service *service, u16 group, u32 command, if (phy->set_lane_count && phy->set_lane_count(dcp, arg)) return KIO_RETURN_ERROR; port->lanes = arg; - if (arg) - port->trained_lanes = arg; return 0; case DPTX_APCALL_GET_MAX_DRIVE_SETTINGS: { const struct dcpib_drive_settings maximum = { diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index a239162e32363..9eb227e9ff07c 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -59,8 +59,12 @@ static int dcpib_refresh(const struct dcpib_timing_mode *t) */ static bool dcpib_mode_fits(struct dcpib *dcp, const struct dcpib_timing_mode *t) { - /* The link's lanes even while the display is off and it is down. */ - u32 lanes = dcp->port[0].trained_lanes ?: 2; + /* + * The lanes the firmware may train, as GET_MAX_LANE_COUNT reports them: + * the USB-C route's. Not the last training's: a sink that replugs while + * the display is off is trained with a single lane. + */ + u32 lanes = (dcp->phy->max_lane_count ? dcp->phy->max_lane_count(dcp) : 4) ?: 2; u64 link = (u64)dcp->phy->max_link_rate * 270000000ULL * lanes * 8 / 10; u64 pixels = (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) * dcpib_refresh(t); From 0874aa06c9b0b00d40ba685e424f3d6cf3ac8799 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 09:37:59 +0100 Subject: [PATCH 083/112] drm/apple_dcpib: take a woken DCPEXT's oslog ring as the firmware's When the driver wakes an unused DCPEXT (apple,rtkit-wake), the firmware's oslog endpoint offers a 0x5ff8-byte ring at 0x100033cc000: the log segment of its own firmware, addressed with the coprocessor's DRAM tag in bit 40. Only the firmware's retained DART tables map it, not the domain Linux has for the controller, so iommu_iova_to_phys() found nothing, the shmem setup failed with -ENOMEM and RTKit logged a failed buffer request on every boot. With the request failed, the oslog buffer stayed unset and RTKit rejected the firmware's write counters as invalid instead of acknowledging them, which AppleDCP waits for before AP power transitions. Linux never reads that ring. Through the endpoint-aware shmem hook, take an oslog ring the domain cannot translate as the firmware's, without a CPU mapping; RTKit sends no reply for a mapped buffer, and aura sends none for this request either. Other endpoints still fail without a mapping. The destroy hook skips the unmap for such a buffer. Tested on the J873g: both DCPEXTs wake without the buffer error or an invalid oslog notification, and a display off/on cycle brings both USB-C outputs and HDMI back. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/drv.c | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index cfda141d1d306..c0dc7c9cf6ab9 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -62,8 +62,12 @@ static void dcpib_rtk_crashed(void *cookie, const void *crashlog, size_t size) dev_err(dcp->dev, "DCP firmware crashed\n"); } +/* RTKit's oslog system endpoint. */ +#define DCPIB_RTKIT_EP_OSLOG 8 + /* Buffers the firmware pre-allocated in its own DART mappings, or new ones. */ -static int dcpib_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) +static int dcpib_rtk_shmem_setup(void *cookie, u8 endpoint, + struct apple_rtkit_shmem *bfr) { struct dcpib *dcp = cookie; @@ -74,6 +78,17 @@ static int dcpib_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) if (!domain) return -ENOMEM; phys = iommu_iova_to_phys(domain, bfr->iova); + /* + * A woken DCPEXT offers the oslog ring in its own firmware + * segment, at an address only the firmware's retained DART + * tables map. Linux never reads that ring and only acknowledges + * its write counters: take it as the firmware's, without a CPU + * mapping. The request needs no reply; aura sends none either. + */ + if (!phys && endpoint == DCPIB_RTKIT_EP_OSLOG) { + bfr->is_mapped = true; + return 0; + } if (!phys) { dev_warn(dcp->dev, "no mapping for firmware buffer %pad\n", &bfr->iova); @@ -96,10 +111,12 @@ static void dcpib_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) { struct dcpib *dcp = cookie; - if (bfr->is_mapped) - memunmap(bfr->buffer); - else + if (bfr->is_mapped) { + if (bfr->buffer) + memunmap(bfr->buffer); + } else { dma_free_coherent(dcp->dev, bfr->size, bfr->buffer, bfr->iova); + } } static bool dcpib_rtk_syslog_debug(void *cookie, const char *context, @@ -114,7 +131,7 @@ static bool dcpib_rtk_syslog_debug(void *cookie, const char *context, static const struct apple_rtkit_ops dcpib_rtkit_ops = { .crashed = dcpib_rtk_crashed, .recv_message = dcpib_rtk_recv, - .shmem_setup = dcpib_rtk_shmem_setup, + .shmem_setup_ep = dcpib_rtk_shmem_setup, .shmem_destroy = dcpib_rtk_shmem_destroy, .syslog_is_debug = dcpib_rtk_syslog_debug, }; From ae7e7018ddfc5211b2e2807b85fab0bec6439a1c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 11:03:18 +0100 Subject: [PATCH 084/112] dt-bindings: display: apple,t8152-dcp-iboot: describe the HDMI cold start The J873g HDMI port works only if the bootloader brought it up. For the driver to start it itself, the HDMI node needs the PMGR2 PSD service of the dptx-phy (phy-psd), the phy tunables from the ADT (apple,tunable-phy), and the SMC writes that power the PS190 DisplayPort-to-HDMI converter (apple,smc, apple,pcon-power). The phy's PMGR power state is no longer only read. Signed-off-by: Thomas Glanzmann --- .../display/apple,t8152-dcp-iboot.yaml | 39 +++++++++++++++++-- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index d4f007202ae65..7c4e2b1db5ab9 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -57,7 +57,7 @@ properties: reg: minItems: 2 - maxItems: 8 + maxItems: 9 reg-names: oneOf: @@ -84,13 +84,15 @@ properties: - const: phy-ps - const: coproc-ps - const: coproc-psd + - const: phy-psd minItems: 7 description: DCP coprocessor, the HDMI dptx-phy blocks, the AP DisplayPort AUX controller that reads the sink's EDID with its - PMGR power state, and the read-only PMGR power states for the - HDMI PHY and DCPEXT CPU. The driver only adopts the bootloader's - powered link and must check these states before accessing the PHY. + PMGR power state, the PMGR power state of the HDMI PHY, the read + only power state of the DCPEXT CPU, and the PMGR2 PSD service of + the HDMI PHY. The PHY is accessed only once its power states read + powered; with phy-psd it is powered up for a cold HDMI start. - items: - const: coproc - const: coproc-psd @@ -138,6 +140,35 @@ properties: on-board DisplayPort-to-HDMI converter. With apple,usb-c-ports it can instead claim a USB-C port when the bootloader has not assigned HDMI. + apple,tunable-phy: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the HDMI dptx-phy core block + - description: mask + - description: value + description: + HDMI dptx-phy tunables (ADT dptx-phy asdc and lane-shm-regs groups), + applied when the PHY starts from cold. + + apple,smc: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The SMC that switches the power of the DisplayPort-to-HDMI converter. + + apple,pcon-power: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: SMC key + - description: value, bits 63:32 + - description: value, bits 31:0 + description: + SMC writes, in order, that power the DisplayPort-to-HDMI converter + (ADT dp2hdmi-gpio0 function-dp2hdmi_pwr_en and function-hdmi_pwr_en). + The converter drives the HDMI hot-plug detect line only while it is + powered. + apple,usb-pd: $ref: /schemas/types.yaml#/definitions/phandle description: From 07646125ba259343b7ed2a0268afc7bba3143eec Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 11:03:18 +0100 Subject: [PATCH 085/112] drm/apple_dcpib: start an HDMI port the bootloader left off The driver only drove HDMI that the bootloader had powered up, tuned and trained, and gave it to the DCP the bootloader had wired to the phy. After a boot without an HDMI monitor (the bootloader's HDMI setup fails and leaves the PLL unlocked) or with a USB-C display on the main DCP, no DCP took HDMI, and a monitor plugged in later stayed dark. Make such an HDMI port one of the shared ports. A DCP that may feed the phy (the main DCP or DCPEXT0, the source selects aura uses) and drives no USB-C display takes it when its HPD line goes high: it gives up its claim on a powered-down USB-C port, switches its phy operations, crossbar endpoint and HPD source to HDMI, and runs the existing plug path. The phy starts from cold the way aura's dptx_t8152_activate does: PMGR and PSD power, the PS190 powered through the SMC, source select, PLL, AUX and phy power, the ADT tunables, PLL and phy activation, four lanes and the impedance calibration. As with the bootloader's HDMI, the link is then kept up across display off. Once the sink is gone and the plug path has released the link, the DCP gives the port back and polls its USB-C ports again. The HPD line is requested once and shared by the DCPs that may take the port. The connector stays a DisplayPort one. Tested on the J873g with two USB-C EIZOs and an HDMI EV2780: booted without HDMI, the main DCP and DCPEXT1 drive the USB-C monitors; HDMI plugged in later, DCPEXT0 takes the port, starts the phy from cold and runs 2560x1440@60 at HBR3 within 0.6 s. Unplugged, the port is given back; plugged again, it is taken and the mode set without a cold start. A boot with HDMI connected keeps the bootloader's HDMI as before. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/Kconfig | 3 + drivers/gpu/drm/apple_dcpib/atc.c | 16 ++ drivers/gpu/drm/apple_dcpib/dcpib.h | 13 ++ drivers/gpu/drm/apple_dcpib/drv.c | 6 + drivers/gpu/drm/apple_dcpib/hdmi.c | 309 +++++++++++++++++++++++++++- drivers/gpu/drm/apple_dcpib/kms.c | 7 +- 6 files changed, 348 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/Kconfig b/drivers/gpu/drm/apple_dcpib/Kconfig index 64dd695889b2f..8f30120d29d9b 100644 --- a/drivers/gpu/drm/apple_dcpib/Kconfig +++ b/drivers/gpu/drm/apple_dcpib/Kconfig @@ -5,6 +5,7 @@ config DRM_APPLE_DCPIB depends on ARCH_APPLE || COMPILE_TEST depends on APPLE_RTKIT depends on SPMI + depends on MFD_MACSMC select APERTURE_HELPERS select DRM_CLIENT_SELECTION select DRM_GEM_DMA_HELPER @@ -14,6 +15,8 @@ config DRM_APPLE_DCPIB the firmware's small iBoot interface. It takes over the displays the bootloader brought up, with the DCP's firmware session still running: a USB-C display on one of the rear ports and the HDMI port. + An HDMI port the bootloader left off is started by the driver, with + the DisplayPort-to-HDMI converter powered through the SMC. To compile this driver as a module, choose M here: the module will be called apple_dcpib. diff --git a/drivers/gpu/drm/apple_dcpib/atc.c b/drivers/gpu/drm/apple_dcpib/atc.c index 83cbf64ca205a..3bc713bf9ef77 100644 --- a/drivers/gpu/drm/apple_dcpib/atc.c +++ b/drivers/gpu/drm/apple_dcpib/atc.c @@ -739,6 +739,22 @@ static void atc_select(struct dcpib *dcp) dcp->dcp_output = port->dfp; } +/* + * Before the DCP drives another phy (the HDMI port): give up the claim on a + * port that is powered down. False while the current port is still up. + */ +bool dcpib_atc_release(struct dcpib *dcp) +{ + struct dcpib_atc_port *atc = atc_cur(dcp); + + if (atc->active) + return false; + guard(mutex)(&atc_owner_lock); + if (atc_owner[atc->index] == dcp->dev) + atc_owner[atc->index] = NULL; + return true; +} + static const struct dcpib_phy_ops atc_ops = { .activate = atc_activate, .deactivate = atc_deactivate, diff --git a/drivers/gpu/drm/apple_dcpib/dcpib.h b/drivers/gpu/drm/apple_dcpib/dcpib.h index a77fa023e2ef3..d3fcb2ebc8277 100644 --- a/drivers/gpu/drm/apple_dcpib/dcpib.h +++ b/drivers/gpu/drm/apple_dcpib/dcpib.h @@ -246,6 +246,16 @@ struct dcpib { struct spmi_device *pd; /* HDMI phy: DCPEXT0, or the main DCP on the bootloader's HDMI-only route */ bool hdmi; + /* + * The HDMI port of the shared ports when the bootloader brought HDMI + * up on no DCP: taken while this DCP drives no USB-C display, with the + * USB-C phy kept to switch back. + */ + struct dcpib_hdmi *hdmi_port; + bool on_hdmi; + const struct dcpib_phy_ops *usbc_phy; + void *usbc_phy_priv; + u32 usbc_output; u32 die; /* iBoot state below, under lock */ @@ -333,9 +343,12 @@ int dcpib_aux_read_edid(struct dcpib *dcp, struct dcpib_aux *aux, u8 *buf, /* atc.c, hdmi.c */ int dcpib_atc_init(struct dcpib *dcp); +bool dcpib_atc_release(struct dcpib *dcp); struct device_node *dcpib_hdmi_node(void); int dcpib_hdmi_source(struct device_node *np); int dcpib_hdmi_init(struct dcpib *dcp, struct device_node *np); +int dcpib_hdmi_port_init(struct dcpib *dcp, struct device_node *np); +void dcpib_hdmi_port_poll(struct dcpib *dcp); /* pd.c */ struct spmi_device *dcpib_pd_get(struct dcpib *dcp, struct device_node *np); diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index c0dc7c9cf6ab9..deac1d5275ba0 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -532,6 +532,12 @@ static int dcpib_probe_inner(struct platform_device *pdev) ret = dcp->hdmi ? dcpib_hdmi_init(dcp, hdmi_np) : dcpib_atc_init(dcp); if (ret) return dev_err_probe(dev, ret, "no DisplayPort phy\n"); + /* Nobody has HDMI from the bootloader: it is one of the shared ports. */ + if (!dcp->hdmi && source < 0 && hdmi_np) { + ret = dcpib_hdmi_port_init(dcp, hdmi_np); + if (ret) + return dev_err_probe(dev, ret, "no shared HDMI port\n"); + } ret = dcpib_boot(dcp); if (ret) diff --git a/drivers/gpu/drm/apple_dcpib/hdmi.c b/drivers/gpu/drm/apple_dcpib/hdmi.c index 1a154b2c3c162..497c3620008d7 100644 --- a/drivers/gpu/drm/apple_dcpib/hdmi.c +++ b/drivers/gpu/drm/apple_dcpib/hdmi.c @@ -4,17 +4,25 @@ * lpdptx slot, driven by DCPEXT0 and converted by a PS190 (aura * src/dcp/dptx_phy.c, DPTX_PHY_T8152_HDMI). * - * The bootloader powers the phy up, applies its tunables, selects the DCP - * and trains the link. This keeps that setup and reprograms what a link - * training changes: the PLL for a new link rate and the active lanes. Drive - * settings are only recorded, as on macOS, and there is no per-link route. + * When the bootloader brought HDMI up, this keeps its setup and reprograms + * what a link training changes: the PLL for a new link rate and the active + * lanes. Drive settings are only recorded, as on macOS, and there is no + * per-link route. When it did not (no HDMI monitor at boot, or a USB-C + * display on the main DCP), the HDMI port joins the shared USB-C ports: a + * DCP without a USB-C display takes it on a plug and starts the phy and the + * PS190 from cold. */ #include #include +#include #include +#include +#include +#include #include #include +#include #include #include "dcpib.h" @@ -28,8 +36,32 @@ struct dcpib_hdmi { void __iomem *apb; /* AP DisplayPort AUX controller aux1, for the EDID */ struct dcpib_aux aux; + /* The cold start of the HDMI port taken from the shared ports: */ + void __iomem *ps; /* PMGR DPTX_PHY */ + void __iomem *psd; /* PMGR2 PSD service of the phy */ + struct gpio_desc *hpd; + struct device_node *smc_np; + const __be32 *pcon, *tunable; + int pcon_len, tunable_len; + bool active; }; +/* + * The DCP driving the HDMI port taken from the shared ports, if any, and its + * HPD line, requested once for all the DCPs that may take the port. + */ +static DEFINE_MUTEX(hdmi_port_lock); +static struct device *hdmi_port_owner; +static struct gpio_desc *hdmi_port_hpd; +static unsigned int hdmi_port_users; + +#define HDMI_PS_TARGET GENMASK(3, 0) +#define HDMI_PS_ACTUAL GENMASK(7, 4) +#define HDMI_PS_FLAGS GENMASK(9, 8) /* write-one-to-clear */ +#define HDMI_PSD_STATE 0x80 +#define HDMI_PSD_TARGET 0x90 +#define HDMI_POWER_TIMEOUT_US 100000 + /* AppleT8112DPTXPort::setDPTXSourceSelect: crossbar UFP feeding the phy */ #define HDMI_SOURCE_SELECT 0x10 #define HDMI_SOURCE_AUX1 6 /* UFP endpoint of dptx1-aux */ @@ -261,6 +293,275 @@ static const struct dcpib_phy_ops hdmi_ops = { /* display-crossbar0 DFP endpoint of the lpdptx slot */ }; +/* + * The phy's PMGR and PSD power, then the PS190's through the SMC (aura + * dcp_init and dcp_hdmi_dptx_init). + */ +static int hdmi_power_up(struct dcpib *dcp, struct dcpib_hdmi *hdmi) +{ + struct platform_device *smc_pdev; + struct apple_smc *smc; + int ret = 0; + u32 val; + + if ((readl(hdmi->ps) & HDMI_PS_ACTUAL) != HDMI_PS_ACTUAL) { + val = readl(hdmi->ps) & ~(HDMI_PS_TARGET | HDMI_PS_FLAGS); + writel(val | HDMI_PS_TARGET, hdmi->ps); + ret = readl_poll_timeout(hdmi->ps, val, + (val & HDMI_PS_ACTUAL) == HDMI_PS_ACTUAL, + 10, HDMI_POWER_TIMEOUT_US); + if (ret) { + dev_err(dcp->dev, "HDMI: phy power state stays %#x\n", val); + return ret; + } + } + if (readl(hdmi->psd + HDMI_PSD_STATE) & 7) { + writel(0, hdmi->psd + HDMI_PSD_TARGET); + ret = readl_poll_timeout(hdmi->psd + HDMI_PSD_STATE, val, !(val & 7), + 10, HDMI_POWER_TIMEOUT_US); + if (ret) { + dev_err(dcp->dev, "HDMI: phy PSD state stays %#x\n", val); + return ret; + } + } + + smc_pdev = of_find_device_by_node(hdmi->smc_np); + smc = smc_pdev ? platform_get_drvdata(smc_pdev) : NULL; + if (!smc) { + dev_err(dcp->dev, "HDMI: no SMC to power the PS190\n"); + ret = -ENODEV; + goto out; + } + for (int i = 0; i + 3 <= hdmi->pcon_len; i += 3) { + u64 value = (u64)be32_to_cpu(hdmi->pcon[i + 1]) << 32 | + be32_to_cpu(hdmi->pcon[i + 2]); + + ret = apple_smc_write(smc, be32_to_cpu(hdmi->pcon[i]), &value, + sizeof(value)); + if (ret) { + dev_err(dcp->dev, "HDMI: PS190 power failed: %d\n", ret); + goto out; + } + } + msleep(25); +out: + if (smc_pdev) + put_device(&smc_pdev->dev); + return ret; +} + +/* AppleT8152DPTXPort::performImpedanceCalibration */ +static void hdmi_impedance_calibration(struct dcpib *dcp, struct dcpib_hdmi *hdmi) +{ + u32 val; + + if (readl_poll_timeout(hdmi->core + 0x1c04, val, val & 1, 10, 1000000)) + dev_warn(dcp->dev, "HDMI: impedance calibration timed out\n"); + hdmi_set_bits(hdmi, 0x1c00, 4, 0x3f0, 0x3f); + val = readl(hdmi->core + 0x1c24); + hdmi_set_bits(hdmi, 0x1c18, 15, 0x3f8000, (val >> 6) & 0x7f); + hdmi_set_bits(hdmi, 0x1c18, 14, 0x4000, 1); +} + +/* + * AppleDPTXPort::handleActivate for T8152 (aura dptx_t8152_activate): power, + * source select, PLL, AUX and phy power, the ADT tunables, the PLL and phy + * activation, four lanes and the impedance calibration. Once up, the link is + * kept on deactivate, as for the bootloader's HDMI. + */ +static int hdmi_port_activate(struct dcpib *dcp) +{ + struct dcpib_hdmi *hdmi = dcp->phy_priv; + int ret; + + if (hdmi->active) + return 0; + ret = hdmi_power_up(dcp, hdmi); + if (ret) + return ret; + /* AppleT8112DPTXPort::setDPTXSourceSelect: only the low nibble */ + hdmi_apb_update(hdmi, HDMI_SOURCE_SELECT, 0xf, dcp->dp_source); + /* pllSetPowerEnabled, auxSetPowerEnabled, phySetPowerEnabled */ + hdmi_apb_update(hdmi, 0x48, 0x010, 0x010); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x020, 0x020); + hdmi_apb_update(hdmi, 0x48, 0x040, 0); + hdmi_apb_update(hdmi, 0x48, 0x100, 0x100); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x200, 0x200); + hdmi_apb_update(hdmi, 0x48, 0x400, 0); + hdmi_apb_update(hdmi, 0x48, 0x001, 0x001); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x002, 0x002); + hdmi_apb_update(hdmi, 0x48, 0x004, 0); + + for (int i = 0; i + 3 <= hdmi->tunable_len; i += 3) { + void __iomem *reg = hdmi->core + be32_to_cpu(hdmi->tunable[i]); + + writel((readl(reg) & ~be32_to_cpu(hdmi->tunable[i + 1])) | + be32_to_cpu(hdmi->tunable[i + 2]), reg); + } + + hdmi_set_bits(hdmi, 0x08d0, 4, 0x10, 1); /* single-ended PLL clock */ + hdmi_set_bits(hdmi, 0x0000, 1, 0x02, 1); /* activatePll */ + hdmi_set_bits(hdmi, 0x1400, 0, 0x01, 0); /* auxSetupCmnControl */ + hdmi_set_bits(hdmi, 0x1c00, 4, 0x3f0, 0x3c); /* activatePhy */ + hdmi_set_bits(hdmi, 0x0000, 0, 0x01, 1); + usleep_range(1000, 2000); + hdmi_set_lanes(hdmi, HDMI_LANES); + hdmi_impedance_calibration(dcp, hdmi); + hdmi->active = true; + dev_info(dcp->dev, "HDMI: phy up from cold, source %u\n", dcp->dp_source); + return 0; +} + +static const struct dcpib_phy_ops hdmi_port_ops = { + .activate = hdmi_port_activate, + .deactivate = hdmi_deactivate, + .set_link_rate = hdmi_set_link_rate, + .set_lane_count = hdmi_set_lane_count, + .set_drive = hdmi_set_drive, + .set_route = hdmi_set_route, + .read_edid = hdmi_read_edid, + .max_link_rate = DCPIB_LINK_RATE_HBR3, +}; + +/* Registers shared with the other DCPs that may take the HDMI port. */ +static void __iomem *hdmi_ioremap(struct dcpib *dcp, struct device_node *np, + const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + struct resource res; + + if (index < 0 || of_address_to_resource(np, index, &res)) + return NULL; + return devm_ioremap(dcp->dev, res.start, resource_size(&res)); +} + +static void hdmi_put_smc(void *data) +{ + of_node_put(data); +} + +static void hdmi_port_put(void *data) +{ + guard(mutex)(&hdmi_port_lock); + if (!--hdmi_port_users) { + gpiod_put(hdmi_port_hpd); + hdmi_port_hpd = NULL; + } +} + +static struct gpio_desc *hdmi_port_get(struct dcpib *dcp, struct device_node *np) +{ + struct gpio_desc *hpd; + int ret; + + scoped_guard(mutex, &hdmi_port_lock) { + if (!hdmi_port_users) { + hpd = fwnode_gpiod_get_index(of_fwnode_handle(np), "hpd", 0, + GPIOD_ASIS, "hdmi-hpd"); + if (IS_ERR(hpd)) + return hpd; + hdmi_port_hpd = hpd; + } + hdmi_port_users++; + hpd = hdmi_port_hpd; + } + ret = devm_add_action_or_reset(dcp->dev, hdmi_port_put, NULL); + return ret ? ERR_PTR(ret) : hpd; +} + +/* + * The HDMI port of the shared ports, for a DCP whose crossbar endpoint the + * phy's source select takes (the main DCP and DCPEXT0, as aura uses it). + * Without the cold start description in np, HDMI stays the bootloader's. + */ +int dcpib_hdmi_port_init(struct dcpib *dcp, struct device_node *np) +{ + struct dcpib_hdmi *hdmi; + int ret; + + if (dcp->dp_source > 1 || !of_property_present(np, "apple,pcon-power")) + return 0; + hdmi = devm_kzalloc(dcp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_ioremap(dcp, np, "phy-core"); + hdmi->apb = hdmi_ioremap(dcp, np, "phy-apb"); + hdmi->ps = hdmi_ioremap(dcp, np, "phy-ps"); + hdmi->psd = hdmi_ioremap(dcp, np, "phy-psd"); + hdmi->aux.regs = hdmi_ioremap(dcp, np, "aux"); + hdmi->aux.ps = hdmi_ioremap(dcp, np, "aux-ps"); + /* AUX output select 0x10: the lpdptx phy */ + hdmi->aux.sel = 0x10; + if (!hdmi->core || !hdmi->apb || !hdmi->ps || !hdmi->psd) + return -ENOMEM; + if (!hdmi->aux.ps) + hdmi->aux.regs = NULL; + hdmi->pcon = of_get_property(np, "apple,pcon-power", &hdmi->pcon_len); + hdmi->pcon_len /= sizeof(__be32); + hdmi->tunable = of_get_property(np, "apple,tunable-phy", + &hdmi->tunable_len); + hdmi->tunable_len /= sizeof(__be32); + hdmi->smc_np = of_parse_phandle(np, "apple,smc", 0); + if (!hdmi->smc_np) + return -EINVAL; + ret = devm_add_action_or_reset(dcp->dev, hdmi_put_smc, hdmi->smc_np); + if (ret) + return ret; + /* Every DCP that may take the port watches the same line. */ + hdmi->hpd = hdmi_port_get(dcp, np); + if (IS_ERR(hdmi->hpd)) + return PTR_ERR(hdmi->hpd); + dcp->hdmi_port = hdmi; + dev_info(dcp->dev, "HDMI: port shared, taken without a USB-C display\n"); + return 0; +} + +/* + * Take the HDMI port when a sink is plugged in and this DCP drives no USB-C + * display; give it back once the sink is gone and the plug path has + * released the link. Called from the connector's detect with dcp->lock held. + */ +void dcpib_hdmi_port_poll(struct dcpib *dcp) +{ + struct dcpib_hdmi *hdmi = dcp->hdmi_port; + int hpd; + + if (!hdmi) + return; + hpd = gpiod_get_value_cansleep(hdmi->hpd); + if (hpd < 0) + return; + guard(mutex)(&hdmi_port_lock); + if (dcp->on_hdmi) { + if (hpd || dcp->hpd) + return; + dcp->phy = dcp->usbc_phy; + dcp->phy_priv = dcp->usbc_phy_priv; + dcp->dcp_output = dcp->usbc_output; + dcp->hpd_gpio = NULL; + dcp->on_hdmi = false; + hdmi_port_owner = NULL; + dev_info(dcp->dev, "HDMI: port given back\n"); + return; + } + if (!hpd || dcp->hpd || hdmi_port_owner || !dcpib_atc_release(dcp)) + return; + hdmi_port_owner = dcp->dev; + dcp->usbc_phy = dcp->phy; + dcp->usbc_phy_priv = dcp->phy_priv; + dcp->usbc_output = dcp->dcp_output; + dcp->phy = &hdmi_port_ops; + dcp->phy_priv = hdmi; + /* display-crossbar0 DFP endpoint lpdptx */ + dcp->dcp_output = 4; + dcp->hpd_gpio = hdmi->hpd; + dcp->on_hdmi = true; + dev_info(dcp->dev, "HDMI: sink plugged, taking the HDMI port\n"); +} + /* The DCP node that describes the HDMI phy (DCPEXT0's). */ struct device_node *dcpib_hdmi_node(void) { diff --git a/drivers/gpu/drm/apple_dcpib/kms.c b/drivers/gpu/drm/apple_dcpib/kms.c index 9eb227e9ff07c..033b823b28bdc 100644 --- a/drivers/gpu/drm/apple_dcpib/kms.c +++ b/drivers/gpu/drm/apple_dcpib/kms.c @@ -312,6 +312,7 @@ dcpib_connector_detect(struct drm_connector *connector, bool force) int hpd; mutex_lock(&dcp->lock); + dcpib_hdmi_port_poll(dcp); if (dcp->hpd_gpio) hpd = gpiod_get_value_cansleep(dcp->hpd_gpio); else if (dcp->phy->detect) @@ -369,7 +370,8 @@ dcpib_connector_detect(struct drm_connector *connector, bool force) dcp->nr_tmodes = 0; dcp->nr_cmodes = 0; /* A sleeping EIZO may need a fresh DP alt mode entry. */ - if (dcp->pd && time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { + if (dcp->pd && !dcp->on_hdmi && + time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { dcp->pd_reset_time = jiffies; schedule_work(&dcp->pd_reset_work); } @@ -673,7 +675,8 @@ static int dcpib_set_mode_locked(struct dcpib *dcp, * entry; the plug that follows sets the mode again. At most * once a minute, so a dead sink does not loop. */ - if (dcp->pd && time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { + if (dcp->pd && !dcp->on_hdmi && + time_after(jiffies, dcp->pd_reset_time + 60 * HZ)) { dcp->cur_mode = *t; dcp->mode_failed = true; dcp->pd_reset_time = jiffies; From 030ebfa8ecae035b628d10923dd19f8c936a7f94 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 11:03:18 +0100 Subject: [PATCH 086/112] arm64: dts: apple: j873: describe the HDMI cold start Give the HDMI node the dptx-phy's PSD service (5), the SMC writes that power the PS190 (ADT dp2hdmi-gpio0 function-dp2hdmi_pwr_en and function-hdmi_pwr_en, SMC key pcIO) and the dptx-phy tunables from the ADT, so that apple_dcpib can start HDMI without the bootloader. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi index 8929f26c8bcc5..ebfae0dbbd1d0 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -464,11 +464,12 @@ <0x3 0x00700480 0x0 0x4>, <0x3 0x007016c0 0x0 0x4>, <0x3 0x00700e00 0x0 0x4>, - <0x3 0x03a12c00 0x0 0xc0>; + <0x3 0x03a12c00 0x0 0xc0>, + <0x3 0x03a10500 0x0 0xc0>; /* aux: ADT dptx1-aux, aux-ps: PMGR GLOBAL_AUX_CTRL1 */ - /* Read-only PMGR DPTX_PHY and DISPEXT0_CPU admission checks. */ + /* PMGR DPTX_PHY, read-only DISPEXT0_CPU, PSD service 5 (dptx-phy) */ reg-names = "coproc", "phy-core", "phy-apb", "aux", "aux-ps", - "phy-ps", "coproc-ps", "coproc-psd"; + "phy-ps", "coproc-ps", "coproc-psd", "phy-psd"; mboxes = <&dcpext_mbox>; iommus = <&dcpext0_dart 23>; dma-coherent; @@ -477,6 +478,38 @@ apple,hdmi; /* ADT dp2hdmi-gpio0 function-hdmi_hpd */ hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; + /* function-dp2hdmi_pwr_en, function-hdmi_pwr_en (SMC pcIO) */ + apple,smc = <&smc>; + apple,pcon-power = <0x7063494f 0x00140000 0x00000001>, + <0x7063494f 0x000f0000 0x00800001>; + /* ADT dptx-phy tunables, in AppleT8152DPTXPort::handleSetTunables order */ + apple,tunable-phy = <0x5180 0x1fff000 0x723000>, + <0x5184 0xffffffff 0x2bc>, + <0x7980 0x1fff000 0x723000>, + <0x7984 0xffffffff 0x2bc>, + <0xa180 0x1fff000 0x723000>, + <0xa184 0xffffffff 0x2bc>, + <0xc980 0x1fff000 0x723000>, + <0xc984 0xffffffff 0x2bc>, + <0x4524 0x3800000 0x2800000>, + <0x6d24 0x3800000 0x2800000>, + <0x9524 0x3800000 0x2800000>, + <0xbd24 0x3800000 0x2800000>, + <0x840 0xc 0x8>, + <0x860 0x1c000 0xc000>, + <0x898 0xf00 0x800>, + <0x89c 0xfe000 0xfe000>, + <0x908 0x7c00000 0x4000000>, + <0x90c 0x7c 0x10>, + <0x68c 0x7f 0x3c>, + <0x69c 0x7f 0x32>, + <0x6ac 0x7f 0x32>, + <0x6bc 0x7f 0x5a>, + <0x1408 0xfc 0x84>, + <0x1c4c 0xff800 0xff800>, + <0x1c5c 0xff 0x80>, + <0x1c60 0x7fffff 0x52bba7>, + <0x1c64 0x2c00000 0x800000>; scanout { iommus = <&dispext0_dart 0>; From 9314a0d5a2d5c48d4b09f5f430c51e5adad42995 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 12:12:20 +0100 Subject: [PATCH 087/112] drm/apple_dcpib: power the PS190 before reading HPD or EDID The driver powered the PS190 DisplayPort-to-HDMI converter through the SMC only when a DCP took the shared HDMI port, and a DCP takes the port once the HDMI HPD line goes high. The PS190 drives that line only while it is powered. The AP AUX controller that reads the USB-C monitors' EDID also gets no reply from any USB-C port while the PS190 is off: every request ends with AUX channel status 2, a timeout. Both only worked because the bootloader's HDMI setup had already powered the PS190. When the bootloader's display setup failed before that point, Linux never saw the HDMI monitor, and the USB-C monitors came up without an EDID, at 1920x1080 and 1680x1050 instead of 2560x1440 and 1920x1200. Power the PS190 when the shared HDMI port is set up in probe, before the DCP is started. If the SMC is not bound yet, defer the probe. Tested on the J873g with the bootloader's internal DCP start failing on purpose (AFK init after the RTKit boot), with HDMI and two USB-C EIZOs connected. Before this change: HDMI HPD low, and the EDID reads failed on both USB-C ports. Writing the SMC values by hand made HPD go high within 200 ms, and DPCD and EDID then read fine on both ports. With this change the same boot brings up HDMI at 2560x1440@60 on the main DCP, and the USB-C monitors at 2560x1440@60 and 1920x1200@60, each from its EDID. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/hdmi.c | 66 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/hdmi.c b/drivers/gpu/drm/apple_dcpib/hdmi.c index 497c3620008d7..3eaeb21f244a0 100644 --- a/drivers/gpu/drm/apple_dcpib/hdmi.c +++ b/drivers/gpu/drm/apple_dcpib/hdmi.c @@ -294,14 +294,41 @@ static const struct dcpib_phy_ops hdmi_ops = { }; /* - * The phy's PMGR and PSD power, then the PS190's through the SMC (aura - * dcp_init and dcp_hdmi_dptx_init). + * The PS190's power through the SMC (aura dcp_hdmi_dptx_init). The PS190 + * drives the HDMI HPD line only while it is powered. */ -static int hdmi_power_up(struct dcpib *dcp, struct dcpib_hdmi *hdmi) +static int hdmi_pcon_power(struct dcpib *dcp, struct dcpib_hdmi *hdmi) { - struct platform_device *smc_pdev; - struct apple_smc *smc; + struct platform_device *smc_pdev = of_find_device_by_node(hdmi->smc_np); + struct apple_smc *smc = smc_pdev ? platform_get_drvdata(smc_pdev) : NULL; int ret = 0; + + if (!smc) { + ret = -EPROBE_DEFER; + goto out; + } + for (int i = 0; i + 3 <= hdmi->pcon_len; i += 3) { + u64 value = (u64)be32_to_cpu(hdmi->pcon[i + 1]) << 32 | + be32_to_cpu(hdmi->pcon[i + 2]); + + ret = apple_smc_write(smc, be32_to_cpu(hdmi->pcon[i]), &value, + sizeof(value)); + if (ret) { + dev_err(dcp->dev, "HDMI: PS190 power failed: %d\n", ret); + goto out; + } + } + msleep(25); +out: + if (smc_pdev) + put_device(&smc_pdev->dev); + return ret; +} + +/* The phy's PMGR and PSD power, then the PS190's (aura dcp_init). */ +static int hdmi_power_up(struct dcpib *dcp, struct dcpib_hdmi *hdmi) +{ + int ret; u32 val; if ((readl(hdmi->ps) & HDMI_PS_ACTUAL) != HDMI_PS_ACTUAL) { @@ -324,30 +351,7 @@ static int hdmi_power_up(struct dcpib *dcp, struct dcpib_hdmi *hdmi) return ret; } } - - smc_pdev = of_find_device_by_node(hdmi->smc_np); - smc = smc_pdev ? platform_get_drvdata(smc_pdev) : NULL; - if (!smc) { - dev_err(dcp->dev, "HDMI: no SMC to power the PS190\n"); - ret = -ENODEV; - goto out; - } - for (int i = 0; i + 3 <= hdmi->pcon_len; i += 3) { - u64 value = (u64)be32_to_cpu(hdmi->pcon[i + 1]) << 32 | - be32_to_cpu(hdmi->pcon[i + 2]); - - ret = apple_smc_write(smc, be32_to_cpu(hdmi->pcon[i]), &value, - sizeof(value)); - if (ret) { - dev_err(dcp->dev, "HDMI: PS190 power failed: %d\n", ret); - goto out; - } - } - msleep(25); -out: - if (smc_pdev) - put_device(&smc_pdev->dev); - return ret; + return hdmi_pcon_power(dcp, hdmi); } /* AppleT8152DPTXPort::performImpedanceCalibration */ @@ -508,6 +512,10 @@ int dcpib_hdmi_port_init(struct dcpib *dcp, struct device_node *np) if (!hdmi->smc_np) return -EINVAL; ret = devm_add_action_or_reset(dcp->dev, hdmi_put_smc, hdmi->smc_np); + if (ret) + return ret; + /* Without the bootloader's HDMI nothing else powers the PS190. */ + ret = hdmi_pcon_power(dcp, hdmi); if (ret) return ret; /* Every DCP that may take the port watches the same line. */ From e5821502a00ee47780b90bd95da6feb55044bab8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 12:56:46 +0100 Subject: [PATCH 088/112] drm/apple_dcpib: let DCPEXT1 take the shared HDMI port Only the main DCP and DCPEXT0, the two source selects aura uses, took the shared HDMI port. After a boot without the bootloader's HDMI, a monitor plugged into HDMI later stayed dark whenever the main DCP and DCPEXT0 held the two USB-C monitors. Which DCPs end up with those depends on which one polls first when the slower monitor shows up. DCPEXT1 was then free but could not take the port. The phy's source select also takes DCPEXT1's crossbar endpoint, 2. Share the port with every DCP. Tested on the J873g, booted without HDMI, with a test build in which only DCPEXT1 takes the HDMI port and DCPEXT1 stays off the USB-C ports. The main DCP and DCPEXT0 drove the two USB-C EIZOs. With HDMI plugged in, DCPEXT1 took the port, started the phy from cold with source select 2, trained four lanes at HBR3, read the EDID and ran 2560x1440@60. The monitor showed the desktop. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/hdmi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/hdmi.c b/drivers/gpu/drm/apple_dcpib/hdmi.c index 3eaeb21f244a0..a71c75155ff88 100644 --- a/drivers/gpu/drm/apple_dcpib/hdmi.c +++ b/drivers/gpu/drm/apple_dcpib/hdmi.c @@ -477,16 +477,16 @@ static struct gpio_desc *hdmi_port_get(struct dcpib *dcp, struct device_node *np } /* - * The HDMI port of the shared ports, for a DCP whose crossbar endpoint the - * phy's source select takes (the main DCP and DCPEXT0, as aura uses it). - * Without the cold start description in np, HDMI stays the bootloader's. + * The HDMI port of the shared ports, for every DCP: the phy's source select + * takes each one's crossbar endpoint. Without the cold start description in + * np, HDMI stays the bootloader's. */ int dcpib_hdmi_port_init(struct dcpib *dcp, struct device_node *np) { struct dcpib_hdmi *hdmi; int ret; - if (dcp->dp_source > 1 || !of_property_present(np, "apple,pcon-power")) + if (!of_property_present(np, "apple,pcon-power")) return 0; hdmi = devm_kzalloc(dcp->dev, sizeof(*hdmi), GFP_KERNEL); if (!hdmi) From 9496fb2082440a69c38297f3a07b70a86fd3ea7f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 17:49:53 +0100 Subject: [PATCH 089/112] dt-bindings: chosen: add apple,dcp-rtkit-running The loader reports whether the internal DCP's RTKit was running at the hand-off (1) or whether it quiesced the coprocessor after a failed display setup (0). apple,dcp-rtkit-quiesced carries the same values under a name that reads the other way round, so the T8152 loader and apple_dcpib use this name instead. Signed-off-by: Thomas Glanzmann --- .../chosen/apple,dcp-rtkit-running.yaml | 37 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 38 insertions(+) create mode 100644 Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml diff --git a/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml b/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml new file mode 100644 index 0000000000000..38a4dcb4044a5 --- /dev/null +++ b/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chosen/apple,dcp-rtkit-running.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple DCP RTKit state at the loader hand-off + +maintainers: + - Thomas Glanzmann + +description: + The loader records whether the internal display coprocessor's RTKit was + running when it handed over to the kernel, or whether the loader quiesced + it after a failed display setup. The loader omits this property when it + never started the coprocessor. + +select: + properties: + $nodename: + const: chosen + required: + - $nodename + +properties: + $nodename: + const: chosen + + apple,dcp-rtkit-running: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + description: + One if the internal DCP's RTKit was running at the hand-off, zero if + the loader quiesced it. + +additionalProperties: true +... diff --git a/MAINTAINERS b/MAINTAINERS index 55374e1146d1f..cffc3d570d40c 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2093,6 +2093,7 @@ F: drivers/soc/apple/pmp.rs F: include/linux/mt7932.h F: include/linux/soc/apple/pmp-report.h F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-quiesced.yaml +F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml F: Documentation/devicetree/bindings/chosen/aurora,ctxr-exec-window.yaml F: Documentation/devicetree/bindings/display/apple,dcp.yaml F: Documentation/devicetree/bindings/display/apple,display-subsystem.yaml From eb06bc81cbaf3c05e6bd002bac2819104c37423c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 17:50:00 +0100 Subject: [PATCH 090/112] drm/apple_dcpib: read the DCP hand-off state from apple,dcp-rtkit-running The loader now publishes the internal DCP's RTKit state at the hand-off as apple,dcp-rtkit-running, 1 running and 0 quiesced, the values that apple,dcp-rtkit-quiesced carried under a name that read backwards. Read the new name. A loader that publishes neither falls back to the existing check for the older J873 loader build. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple_dcpib/drv.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple_dcpib/drv.c b/drivers/gpu/drm/apple_dcpib/drv.c index deac1d5275ba0..43f173ba0f9d7 100644 --- a/drivers/gpu/drm/apple_dcpib/drv.c +++ b/drivers/gpu/drm/apple_dcpib/drv.c @@ -161,8 +161,7 @@ static bool dcpib_handoff_quiesced(struct dcpib *dcp) if (dcp->hdmi || !chosen) return false; - /* Despite its name, the loader property is one for a running core. */ - if (!of_property_read_u32(chosen, "apple,dcp-rtkit-quiesced", &running)) + if (!of_property_read_u32(chosen, "apple,dcp-rtkit-running", &running)) return running == 0; /* * This older J873 loader predates the state property. Its failed From 5876367d01fd4aff67d26f42a9ef09ba7032644b Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 091/112] dt-bindings: power: add the Apple T8152 PSD service On T8152 the video decoder, the USB4 routers and their PHYs and the USB controllers are powered through PMGR2 PSD services instead of PMGR power-state registers. Each service has a 0x100-byte block with a target state, an acknowledge bit and the current state. Describe one service per node as a power domain, with an optional apple,always-on for a service whose consumers cannot restore what another agent set up in its blocks yet. Signed-off-by: Thomas Glanzmann --- .../bindings/power/apple,t8152-psd.yaml | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/apple,t8152-psd.yaml diff --git a/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml new file mode 100644 index 0000000000000..fa61de7d3d7e7 --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/apple,t8152-psd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 PMGR2 PSD service + +maintainers: + - Thomas Glanzmann + +description: + On T8152 several blocks (the video decoder, the USB4 routers and their + PHYs, the USB controllers) are powered through PMGR2 PSD services rather + than through PMGR power-state registers. Each service has its own 0x100 + byte register block at the PSD base plus 0x100 times the service number, + with a target-state request, an acknowledge bit and the current state + (0 powered, 6 cold). Reading the state consumes the acknowledge. One node + describes one service as a power domain. + +allOf: + - $ref: power-domain.yaml# + +properties: + compatible: + const: apple,t8152-psd + + reg: + maxItems: 1 + + '#power-domain-cells': + const: 0 + + label: + description: The service's name, for the power domain. + + apple,always-on: + type: boolean + description: + Keep the service powered. For a service whose consumers cannot yet + restore the state another agent set up in its blocks, such as a PHY + configured by the bootloader. + +required: + - compatible + - reg + - '#power-domain-cells' + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + power-controller@303a13200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13200 0x0 0x100>; + #power-domain-cells = <0>; + label = "avd"; + }; + }; From 64484b4569501f4fb959a8d96d8d1ed0fa150a5f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 092/112] pmdomain: apple: add the T8152 PSD power domains Provide each T8152 PMGR2 PSD service as a power domain. Power-on requests state 0 and power-off the cold state 6. The driver waits for the acknowledge before it reads the state, because reading the state consumes the acknowledge. A service marked apple,always-on is powered at probe and kept on. Otherwise the domain starts in the state the hardware reports, so genpd powers off a service that nothing uses. The consumers include IRQ-safe devices, the DARTs, so the domains are IRQ-safe and a transition is polled atomically, as the PMGR power states are. On the J873g the AVD service (50) reaches state 0 in 390-500 us and the cold state in about 240 us; the timeout is 10 ms. The AVD and the USB4 routers' CIO services, which so far each had their own variant of this, and the USB controllers (services 175 and 176) use it. Signed-off-by: Thomas Glanzmann --- drivers/pmdomain/apple/Makefile | 1 + drivers/pmdomain/apple/pmgr-psd.c | 151 ++++++++++++++++++++++++++++++ 2 files changed, 152 insertions(+) create mode 100644 drivers/pmdomain/apple/pmgr-psd.c diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index ef35dddc526f1..c7ac608079081 100644 --- a/drivers/pmdomain/apple/Makefile +++ b/drivers/pmdomain/apple/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_APPLE_PMP_DRAM_KUNIT_TEST) += pmp-dram-test.o obj-$(CONFIG_APPLE_PMC) += pmc.o obj-$(CONFIG_APPLE_PMP_ANE_KUNIT_TEST) += pmp-ane-test.o obj-$(CONFIG_APPLE_PMP_J613_FLOOR_KUNIT_TEST) += pmp-j613-floor-gov-test.o +obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += pmgr-psd.o diff --git a/drivers/pmdomain/apple/pmgr-psd.c b/drivers/pmdomain/apple/pmgr-psd.c new file mode 100644 index 0000000000000..04bbf0d35e948 --- /dev/null +++ b/drivers/pmdomain/apple/pmgr-psd.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 PMGR2 PSD services as power domains. + * + * Each service has a 0x100 byte register block: the target state at +0x90, + * the acknowledge in bit 0 of +0xbc, and the current state in bits 2:0 of + * +0x80 (0 powered, 6 cold). Reading the state consumes the acknowledge, so + * the state is read only once the acknowledge is set. + * + * The consumers include IRQ-safe devices (DARTs), so the domains are IRQ-safe + * and a transition is polled atomically, as for the PMGR power states. + */ +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PSD_STATE 0x80 +#define APPLE_PSD_STATE_CUR GENMASK(2, 0) +#define APPLE_PSD_TARGET 0x90 +#define APPLE_PSD_ACK 0xbc +#define APPLE_PSD_ACK_DONE BIT(0) + +#define APPLE_PSD_ON 0 +#define APPLE_PSD_COLD 6 + +#define APPLE_PSD_TIMEOUT_US 10000 + +struct apple_psd { + struct generic_pm_domain genpd; + struct device *dev; + void __iomem *regs; +}; + +static u32 apple_psd_state(struct apple_psd *psd) +{ + return readl(psd->regs + APPLE_PSD_STATE) & APPLE_PSD_STATE_CUR; +} + +static bool apple_psd_reached(struct apple_psd *psd, u32 target, u32 *ack, + u32 *state) +{ + *ack = readl(psd->regs + APPLE_PSD_ACK); + if (!(*ack & APPLE_PSD_ACK_DONE)) + return false; + *state = apple_psd_state(psd); + return *state == target; +} + +static int apple_psd_set_state(struct generic_pm_domain *genpd, u32 target) +{ + struct apple_psd *psd = container_of(genpd, struct apple_psd, genpd); + u32 ack = 0, state; + bool done; + int ret; + + state = apple_psd_state(psd); + if (state == target) + return 0; + writel(target, psd->regs + APPLE_PSD_TARGET); + ret = read_poll_timeout_atomic(apple_psd_reached, done, done, 1, + APPLE_PSD_TIMEOUT_US, false, psd, target, + &ack, &state); + if (ret) { + dev_err(psd->dev, "%s: state %u not reached: ack %#x, state %u\n", + genpd->name, target, ack, state); + return ret; + } + return 0; +} + +static int apple_psd_power_on(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_ON); +} + +static int apple_psd_power_off(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_COLD); +} + +static void apple_psd_remove_provider(void *data) +{ + struct apple_psd *psd = data; + + of_genpd_del_provider(psd->dev->of_node); + pm_genpd_remove(&psd->genpd); +} + +static int apple_psd_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct apple_psd *psd; + bool is_off; + int ret; + + psd = devm_kzalloc(dev, sizeof(*psd), GFP_KERNEL); + if (!psd) + return -ENOMEM; + psd->dev = dev; + psd->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(psd->regs)) + return PTR_ERR(psd->regs); + + if (of_property_read_string(np, "label", &psd->genpd.name)) + psd->genpd.name = dev_name(dev); + psd->genpd.power_on = apple_psd_power_on; + psd->genpd.power_off = apple_psd_power_off; + psd->genpd.flags = GENPD_FLAG_IRQ_SAFE; + + if (of_property_read_bool(np, "apple,always-on")) { + psd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; + ret = apple_psd_power_on(&psd->genpd); + if (ret) + return ret; + } + is_off = apple_psd_state(psd) != APPLE_PSD_ON; + + ret = pm_genpd_init(&psd->genpd, NULL, is_off); + if (ret) + return ret; + ret = of_genpd_add_provider_simple(np, &psd->genpd); + if (ret) { + pm_genpd_remove(&psd->genpd); + return ret; + } + return devm_add_action_or_reset(dev, apple_psd_remove_provider, psd); +} + +static const struct of_device_id apple_psd_match[] = { + { .compatible = "apple,t8152-psd" }, + {} +}; +MODULE_DEVICE_TABLE(of, apple_psd_match); + +static struct platform_driver apple_psd_driver = { + .probe = apple_psd_probe, + .driver = { + .name = "apple-pmgr-psd", + .of_match_table = apple_psd_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(apple_psd_driver); + +MODULE_LICENSE("Dual MIT/GPL"); +MODULE_DESCRIPTION("Apple T8152 PMGR2 PSD power domains"); From 59f9dfe1ea861b5baab695d6f6a99c9d66151226 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 093/112] dt-bindings: iommu: apple,dart: describe the T8152 AVD instance The AVD Gen3 DART uses the shared TLBI aperture like the display DARTs, but Linux initializes it from an unlocked state with inactive streams. Require its PSD power domain, DMA aperture and initialization tunables. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/iommu/apple,dart.yaml | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index d7e8e332951ad..ba49a093eccee 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -33,6 +33,7 @@ properties: - apple,t8110-dart - apple,t6000-dart - apple,t8152-dart-gen3 + - apple,t8152-avd-dart - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -369,7 +370,9 @@ allOf: properties: compatible: contains: - const: apple,t8152-dart-gen3 + enum: + - apple,t8152-dart-gen3 + - apple,t8152-avd-dart then: description: The T8152 Gen3 DARTs in front of the display coprocessors and their @@ -377,7 +380,9 @@ allOf: locked, and the operating system only adds page table entries in root slots that are empty at handoff. Their TLB command register answers translation queries; a stream is invalidated through the - TLB invalidation aperture instead. + TLB invalidation aperture instead. The T8152 AVD instance uses the + same invalidation aperture, but starts unlocked with inactive streams + and is initialized by the operating system after its PSD domain is on. properties: reg: minItems: 2 @@ -395,6 +400,17 @@ allOf: - const: dart - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - if: + properties: + compatible: + contains: + const: apple,t8152-avd-dart + then: + required: + - power-domains + - apple,dma-range + - apple,tunable + additionalProperties: false examples: From 0b218b71721b6b7cc074a11f21ca337f2187d37a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 094/112] iommu: apple-dart: initialize the inactive T8152 AVD Gen3 DART Admit cold Gen3 setup only for the instance its apple,t8152-avd-dart compatible selects, with version 0x300, 16 streams, its PSD domain, ADT tunables and inactive streams 0..2. Clear those streams, apply their tunables and use the Gen3 TLBI aperture before enabling translation. Map the TLBI aperture before reset and select a two-level 16K page table inside a single 64 GiB high DMA window. Keep the existing locked display DART admission and all other unlocked Gen3 instances unchanged. On J873g this maps all three decoder streams for bit-exact H.264, HEVC, HEVC Main10, VP9 and AV1 decoding. Gen3 fault IRQ handling and suspend recovery remain outside this initial bring-up. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 83 ++++++++++++++++++++++++++------------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index da2cb77719985..df8380c2eece9 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,6 +361,7 @@ struct apple_dart_fw_tree { #define APPLE_DART_GAPF_PROTECT BIT(4) struct apple_dart { + bool cold_gen3; struct device *dev; const struct apple_dart_hw *hw; @@ -2648,6 +2649,17 @@ static int apple_dart_hw_reset(struct apple_dart *dart) struct apple_dart_stream_map stream_map; int i; + if (dart->cold_gen3) { + stream_map.dart = dart; + bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS); + bitmap_set(stream_map.sidmap, 0, 3); + apple_dart_hw_disable_dma(&stream_map); + apple_dart_hw_clear_all_ttbrs(&stream_map); + apple_dart_apply_own_tunables(dart); + apple_dart_writel(dart, 7, dart->hw->enable_streams); + return dart->hw->invalidate_tlb(&stream_map); + } + if (dart->isp_host) return apple_dart_isp_host_reset(dart); if (dart->managed_sids || dart->cold_ane) @@ -3380,6 +3392,17 @@ static int __apple_dart_finalize_domain(struct apple_dart_domain *dart_domain, .iommu_dev = dart->dev, }; + if (dart->cold_gen3) { + if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(36)) { + ret = -ERANGE; + goto done; + } + /* Gen3 selects the high DMA window separately from its two-level + * 16K page-table indices, as with iBoot's display streams. + */ + pgtbl_cfg.ias = 36; + } + if (dart->locked) { unsigned long *sidmap; int sid; @@ -5535,6 +5558,7 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); dart->tunneled = tunneled; + dart->cold_gen3 = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart"); dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-ane-dart"); if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) @@ -5951,6 +5975,38 @@ static int apple_dart_probe(struct platform_device *pdev) ret = -EBUSY; goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* Cold initialization is qualified only for the AVD instance. */ + if (!dart->locked && !dart->cold_gen3) { + dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); + ret = -ENODEV; + goto err_clk_disable; + } + if (dart->cold_gen3 && (dart->locked || dart->version != 0x300 || + dart->num_streams != 16 || !dev->pm_domain || !dart->tunables || + (apple_dart_readl(dart, dart->hw->enable_streams) & 7))) { + ret = -EINVAL; + goto err_clk_disable; + } + /* The aperture is shared by every Gen3 DART: map, do not claim. */ + tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); + if (!tlbi || resource_size(tlbi) < 16) { + dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); + ret = -EINVAL; + goto err_clk_disable; + } + dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); + if (!dart->tlbi) { + ret = -ENOMEM; + goto err_clk_disable; + } + dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; + dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", + dart->version, dart->tlbi_route); + } + apple_dart_parse_sleep_list(dart, res, "apple,sleep-prepare", &dart->sleep_prepare); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore", &dart->sleep_restore); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore-late", @@ -6091,32 +6147,6 @@ static int apple_dart_probe(struct platform_device *pdev) goto err_clk_disable; } - if (dart->hw->gen3) { - struct resource *tlbi; - - /* Only an iBoot-provisioned (locked) Gen3 stream is supported. */ - if (!dart->locked) { - dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); - ret = -ENODEV; - goto err_clk_disable; - } - /* The aperture is shared by every Gen3 DART: map, do not claim. */ - tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); - if (!tlbi || resource_size(tlbi) < 16) { - dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); - ret = -EINVAL; - goto err_clk_disable; - } - dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); - if (!dart->tlbi) { - ret = -ENOMEM; - goto err_clk_disable; - } - dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; - dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", - dart->version, dart->tlbi_route); - } - /* Borrowed display state: never acknowledge someone else's fault. */ if (dart->locked && !dart->preserve_display && !dart->hw->gen3) apple_dart_drain_stale_exceptions(dart); @@ -7279,6 +7309,7 @@ static const struct dev_pm_ops apple_dart_pm_ops = { static const struct of_device_id apple_dart_of_match[] = { { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-avd-dart", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, From 445f35036ac76ea67be7f34a129a1a49ee77b234 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 095/112] media: dt-bindings: describe the T8152 Kopsia decoder Describe the Kopsia MCU, decoder, wrapper and PIODMA register apertures, its three DART streams and its shared PSD power domain. The initial transport submits from the host with the MCU halted and polls completion; it does not use the PostOffice mailbox or the legacy decoder reset line. Signed-off-by: Thomas Glanzmann --- .../bindings/media/apple,t8152-avd.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/apple,t8152-avd.yaml diff --git a/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml b/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml new file mode 100644 index 0000000000000..585a0a897fed7 --- /dev/null +++ b/Documentation/devicetree/bindings/media/apple,t8152-avd.yaml @@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/apple,t8152-avd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 Kopsia video decoder + +maintainers: + - Thomas Glanzmann + +description: + Kopsia is the T8152 stateless video decoder. Its decoder, PIODMA and + auxiliary data streams share a Gen3 DART and a PSD power domain. The host + submits codec programs with the MCU halted and polls decoder status; + the PostOffice mailbox transport is not used by this implementation. + +properties: + compatible: + const: apple,t8152-avd + + reg: + items: + - description: MCU code memory + - description: MCU control registers + - description: Decoder control registers + - description: Decoder wrapper registers + - description: PIODMA registers + + reg-names: + items: + - const: code + - const: mbox + - const: ctrl + - const: wrap + - const: dma + + iommus: + items: + - description: Decoder stream + - description: PIODMA stream + - description: Auxiliary data stream + + power-domains: + maxItems: 1 + +required: + - compatible + - reg + - reg-names + - iommus + - power-domains + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + video-codec@485400000 { + compatible = "apple,t8152-avd"; + reg = <0x4 0x85400000 0x0 0x12000>, + <0x4 0x85500000 0x0 0x4000>, + <0x4 0x85100000 0x0 0x10000>, + <0x4 0x850c0000 0x0 0x4000>, + <0x4 0x85070000 0x0 0x4000>; + reg-names = "code", "mbox", "ctrl", "wrap", "dma"; + iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>; + power-domains = <&ps_avd>; + }; + }; From ed499a996a0f1cf6acce8e5993c8a76f9d3ec153 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 12:16:30 +0100 Subject: [PATCH 096/112] media: apple: avd: add a polled host backend for T8152 Kopsia T8152 Kopsia retains the T8142 codec program format but uses different initialization and completion registers. Add a host backend that halts the MCU, initializes the wrapper and PIODMA, and reuses the existing codec submission and completion logic with one frame in flight. Poll VP/PP status only while a frame is active. Enable H.264, HEVC, VP9 and AV1 on this variant without an external firmware image. Retain the 128-byte H.264 MV and HEVC v5 header quirks. Disable recovery reset: the existing watchdog parks DMA and retires the decoder instead of issuing an unqualified reset. The 346 register tunables are unchanged from the MIT-licensed avd-fw v5/tier2 table. The J873g ADT's avd node carries no tunables of its own (unlike its DART's), so there is nothing T8152-specific to describe in the device tree. The table was checked on the J873g by its output: with it, H.264, HEVC, HEVC Main10, VP9 and AV1 decode bit-exact against software (60 frames each), 4K60 H.264 runs at about 150 fps, and the results stay exact across hundreds of power-domain cycles, each of which applies the table again. On J873g, forced DRM PRIME decode and download compares exactly with software for 60 frames of each codec, including HEVC Main10; mpv also renders through DRM PRIME and seeks in both directions. The decoder is runtime power-gated through its PSD domain: the backend is set up again on every resume. A DART fault (injected on the J873g) retires the decoder through the existing recovery path until the module is reloaded. PostOffice completion and suspend/resume remain outstanding. Link: https://github.com/aurora-silicon/avd-fw/blob/ea3a65cc9c0c41907e6ad2714b813e4be6858485/src/hw/tunables/tunables_v5t2.h Signed-off-by: Thomas Glanzmann --- drivers/media/platform/apple/avd/Kconfig | 4 +- drivers/media/platform/apple/avd/Makefile | 2 +- .../platform/apple/avd/avd-backend-kopsia.c | 176 +++++++++ .../platform/apple/avd/avd-backend-open.c | 24 +- drivers/media/platform/apple/avd/avd-drv.c | 53 ++- .../platform/apple/avd/avd-kopsia-tunables.h | 350 ++++++++++++++++++ drivers/media/platform/apple/avd/avd.h | 5 + 7 files changed, 595 insertions(+), 19 deletions(-) create mode 100644 drivers/media/platform/apple/avd/avd-backend-kopsia.c create mode 100644 drivers/media/platform/apple/avd/avd-kopsia-tunables.h diff --git a/drivers/media/platform/apple/avd/Kconfig b/drivers/media/platform/apple/avd/Kconfig index d3bb9763b6230..4aa061da424e6 100644 --- a/drivers/media/platform/apple/avd/Kconfig +++ b/drivers/media/platform/apple/avd/Kconfig @@ -14,7 +14,9 @@ config VIDEO_APPLE_AVD help Support the Apple Silicon stateless video decoder. - Build the decoder firmware from https://github.com/aurora-silicon/avd-fw + T8152 uses host submission and does not need a firmware image. + + For earlier SoCs, build the decoder firmware from https://github.com/aurora-silicon/avd-fw and install it under /lib/firmware/apple/. J700/T8140 uses the avd-fw-v5-t0.bin image. Firmware is supplied separately from this driver. diff --git a/drivers/media/platform/apple/avd/Makefile b/drivers/media/platform/apple/avd/Makefile index 60560dbab592a..66b8e3c61356a 100644 --- a/drivers/media/platform/apple/avd/Makefile +++ b/drivers/media/platform/apple/avd/Makefile @@ -2,7 +2,7 @@ apple-avd-y := avd-drv.o avd-v4l2.o avd-hw.o avd-pm.o avd-h264.o avd-vp9.o \ avd-hevc.o avd-av1.o avd-av1-entropymode.o avd-queue.o avd-backend-open.o \ - avd-backend-apple.o avd-backend-queue.o + avd-backend-apple.o avd-backend-queue.o avd-backend-kopsia.o apple-avd-$(CONFIG_VIDEO_APPLE_AVD_KUNIT_TEST) += avd-h264-test.o avd-queue-test.o \ avd-pm-test.o obj-$(CONFIG_VIDEO_APPLE_AVD) += apple-avd.o diff --git a/drivers/media/platform/apple/avd/avd-backend-kopsia.c b/drivers/media/platform/apple/avd/avd-backend-kopsia.c new file mode 100644 index 0000000000000..f242e90d4be8a --- /dev/null +++ b/drivers/media/platform/apple/avd/avd-backend-kopsia.c @@ -0,0 +1,176 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * T8152 Kopsia bring-up: host submission and polled VP/PP completion. + * + * Completion is polled because no decoder interrupt is described: the ADT's + * avd node lists only its PostOffice mailbox pair (AIC 308 and 268, mailbox + * 9's send-empty and recv-not-empty), and with the MCU halted nothing is known + * to raise them. The poll runs only while a frame is active. + */ +#include +#include +#include "avd.h" + +#define KOPSIA_STATUS(n) (0x194 + 4 * (n)) +#define KOPSIA_ERROR BIT(1) +#define KOPSIA_DONE BIT(2) +#define KOPSIA_PP 13 + +struct avd_kopsia_tunable { u32 off, mask, val; }; +#include "avd-kopsia-tunables.h" + +struct avd_kopsia { + struct avd_dev *avd; + void __iomem *wrap; + void __iomem *dma; + struct work_struct poll_work; + bool running; +}; + +static void kopsia_update(void __iomem *reg, u32 mask, u32 value) +{ + writel((readl(reg) & ~mask) | value, reg); +} + +static int avd_kopsia_boot(struct avd_dev *avd) +{ + struct avd_kopsia *k = avd->backend_priv; + unsigned int i; + + if (readl(avd->ctrl) != 0x40030) + return -ENODEV; + + /* Keep the MCU halted: this transport owns the hardware status bits. */ + writel(0xe, avd->mbox + 0x28); + kopsia_update(avd->mbox + 0x40, BIT(24), BIT(24)); + writel(0, avd->mbox + 0x104); + writel(1, k->wrap + 0x18); + writel(0, k->dma); + writel(0x20, avd->ctrl + 0x1cc); + writel(U32_MAX, avd->ctrl + 0xe6d0); + writel(U32_MAX, avd->ctrl + 0xe6d4); + writel(U32_MAX, avd->ctrl + 0xe710); + writel(U32_MAX, avd->ctrl + 0xe714); + for (i = 0; i < ARRAY_SIZE(kopsia_tunables); i++) { + const struct avd_kopsia_tunable *t = &kopsia_tunables[i]; + + kopsia_update(avd->ctrl + t->off, t->mask, t->val); + } + kopsia_update(k->wrap + 0x14, 1, 1); + kopsia_update(k->wrap + 0x18, 1, 1); + kopsia_update(k->wrap + 0x4c, 1, 1); + kopsia_update(k->dma, 2, 0); + kopsia_update(k->dma + 0x10, 0x1ff8000f, 2); + kopsia_update(k->dma + 0x14, 0x1ff8000f, 2); + kopsia_update(k->dma + 0x18, 0x1ff8000f, 3); + kopsia_update(k->dma + 0x1c, 0xf, 0); + kopsia_update(k->dma + 0x20, 0xf, 0); + for (i = 0; i <= KOPSIA_PP; i++) + writel(KOPSIA_DONE | KOPSIA_ERROR, avd->ctrl + KOPSIA_STATUS(i)); + k->running = true; + dev_info_once(avd->dev, "Kopsia host backend, decoder %#x (polled completion)\n", + readl(avd->ctrl)); + return 0; +} + +static void avd_kopsia_shutdown(struct avd_dev *avd) +{ + struct avd_kopsia *k = avd->backend_priv; + + /* Serialized against polling by queue_mutex or the idle PM reference. */ + WRITE_ONCE(k->running, false); +} + +static void avd_kopsia_poll(struct work_struct *work) +{ + struct avd_kopsia *k = container_of(work, struct avd_kopsia, poll_work); + struct avd_dev *avd = k->avd; + + for (;;) { + struct avd_frame *f; + u32 vp, status; + bool active; + + mutex_lock(&avd->queue_mutex); + f = avd->compat_active; + if (!READ_ONCE(k->running) || !f || avd->stopping || avd->faulted) { + mutex_unlock(&avd->queue_mutex); + break; + } + vp = avd->variant->vp_slot_base[f->cmd[0]]; + status = readl(avd->ctrl + KOPSIA_STATUS(vp)); + if (status & KOPSIA_ERROR) { + writel(KOPSIA_ERROR, avd->ctrl + KOPSIA_STATUS(vp)); + avd_status(avd, vp); + avd_open_complete(avd, vp); + mutex_unlock(&avd->queue_mutex); + break; + } + if (status & KOPSIA_DONE) { + writel(KOPSIA_DONE, avd->ctrl + KOPSIA_STATUS(vp)); + avd_open_complete(avd, 0x100 | vp); + } + status = readl(avd->ctrl + KOPSIA_STATUS(KOPSIA_PP)); + if (status & KOPSIA_DONE) { + writel(KOPSIA_DONE, avd->ctrl + KOPSIA_STATUS(KOPSIA_PP)); + avd_open_complete(avd, 0x1000); + } + active = avd->compat_active != NULL; + mutex_unlock(&avd->queue_mutex); + if (!active) + break; + usleep_range(100, 200); + } +} + +static int avd_kopsia_submit(struct avd_dev *avd, struct avd_frame *f) +{ + struct avd_kopsia *k = avd->backend_priv; + int ret = avd_open_submit(avd, f); + + if (!ret) + queue_work(system_dfl_wq, &k->poll_work); + return ret; +} + +static unsigned int avd_kopsia_max_inflight(struct avd_dev *avd) +{ + return 1; +} + +static void avd_kopsia_cleanup(void *data) +{ + struct avd_kopsia *k = data; + + WRITE_ONCE(k->running, false); + cancel_work_sync(&k->poll_work); +} + +static int avd_kopsia_probe(struct avd_dev *avd) +{ + struct avd_kopsia *k = devm_kzalloc(avd->dev, sizeof(*k), GFP_KERNEL); + + if (!k) + return -ENOMEM; + k->avd = avd; + k->wrap = devm_platform_ioremap_resource_byname(avd->pdev, "wrap"); + if (IS_ERR(k->wrap)) + return PTR_ERR(k->wrap); + k->dma = devm_platform_ioremap_resource_byname(avd->pdev, "dma"); + if (IS_ERR(k->dma)) + return PTR_ERR(k->dma); + INIT_WORK(&k->poll_work, avd_kopsia_poll); + avd->backend_priv = k; + return devm_add_action_or_reset(avd->dev, avd_kopsia_cleanup, k); +} + +const struct avd_backend_ops avd_kopsia_backend = { + .name = "kopsia-host", + .probe = avd_kopsia_probe, + .boot = avd_kopsia_boot, + .shutdown = avd_kopsia_shutdown, + .max_inflight = avd_kopsia_max_inflight, + .submit = avd_kopsia_submit, + .suspend = avd_pm_backend_suspend, + .resume = avd_pm_backend_resume, +}; diff --git a/drivers/media/platform/apple/avd/avd-backend-open.c b/drivers/media/platform/apple/avd/avd-backend-open.c index d2054d06f948b..527b7fadd5543 100644 --- a/drivers/media/platform/apple/avd/avd-backend-open.c +++ b/drivers/media/platform/apple/avd/avd-backend-open.c @@ -74,7 +74,7 @@ static unsigned int avd_open_max_inflight(struct avd_dev *avd) return 1; } -static int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) +int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) { struct avd_ctx *ctx = f->ctx; u32 codec = f->cmd[0], vp = 0; @@ -131,13 +131,9 @@ static int avd_open_submit(struct avd_dev *avd, struct avd_frame *f) return 0; } -static irqreturn_t avd_open_irq(struct avd_dev *avd) +irqreturn_t avd_open_complete(struct avd_dev *avd, u32 status) { struct avd_frame *f = avd->compat_active; - u32 status; - - if (!avd_mbox_pop(avd, &status)) - return IRQ_HANDLED; if (!f) { /* * The old driver kicked PP for every VP DONE. A VP DONE with no @@ -177,6 +173,15 @@ static irqreturn_t avd_open_irq(struct avd_dev *avd) return IRQ_HANDLED; } +static irqreturn_t avd_open_irq(struct avd_dev *avd) +{ + u32 status; + + if (!avd_mbox_pop(avd, &status)) + return IRQ_HANDLED; + return avd_open_complete(avd, status); +} + const struct avd_backend_ops avd_open_backend = { .name = "open-compat", .boot = avd_boot, @@ -236,6 +241,13 @@ int avd_backend_select(struct avd_dev *avd) { int ret; + if (avd->variant->quirks & AVD_QUIRK_KOPSIA) { + avd->backend = &avd_kopsia_backend; + avd->capabilities = avd->variant->capabilities; + avd->fw_capabilities = avd->capabilities; + return avd->backend->probe(avd); + } + /* Apple probe returns -ENOENT only when no usable image is present. */ if (avd->variant->apple) { ret = avd_apple_backend.probe(avd); diff --git a/drivers/media/platform/apple/avd/avd-drv.c b/drivers/media/platform/apple/avd/avd-drv.c index b0ad4b2e261b2..8b96dd1eddb40 100644 --- a/drivers/media/platform/apple/avd/avd-drv.c +++ b/drivers/media/platform/apple/avd/avd-drv.c @@ -585,8 +585,35 @@ static const struct avd_variant avd_t8142_variant = { .quirks = AVD_QUIRK_HEVC_V5_HEADER | AVD_QUIRK_H264_MV_128, }; +static const struct avd_variant avd_t8152_variant = { + .vp_slots = { + [AVD_CODEC_HEVC] = 2, + [AVD_CODEC_H264] = 1, + [AVD_CODEC_VP9] = 1, + [AVD_CODEC_AV1] = 1, + }, + .vp_slot_base = { + [AVD_CODEC_HEVC] = 0, + [AVD_CODEC_H264] = 4, + [AVD_CODEC_VP9] = 8, + [AVD_CODEC_AV1] = 9, + }, + .fifo_slots = 7, + .configure_stream = t8122_configure_stream, + .capabilities = AVD_CAPABILITY_H264 | AVD_CAPABILITY_HEVC | + AVD_CAPABILITY_VP9 | AVD_CAPABILITY_AV1, + .revision = 4, + .vp_slot_offset = 0xc, + .submit_offset = 0x40, + .submit_queue_max_offset = 0x44, + .submit_queue_status_offset = 0x7c, + .quirks = AVD_QUIRK_HEVC_V5_HEADER | AVD_QUIRK_H264_MV_128 | + AVD_QUIRK_NO_RECOVERY_RESET | AVD_QUIRK_KOPSIA, +}; + /* can also be derived from a version register */ static const struct of_device_id avd_of_match[] = { + { .compatible = "apple,t8152-avd", .data = &avd_t8152_variant }, { .compatible = "apple,t8103-avd", .data = &avd_t8103_variant @@ -662,7 +689,8 @@ static int avd_probe(struct platform_device *pdev) match = of_match_node(avd_of_match, pdev->dev.of_node); avd->variant = match->data; - avd->rstc = devm_reset_control_get_exclusive(avd->dev, NULL); + avd->rstc = avd->variant->quirks & AVD_QUIRK_KOPSIA ? NULL : + devm_reset_control_get_exclusive(avd->dev, NULL); if (IS_ERR(avd->rstc)) return PTR_ERR(avd->rstc); @@ -724,16 +752,19 @@ static int avd_probe(struct platform_device *pdev) return ret; } - irq = platform_get_irq(pdev, 1); - if (irq < 0) - return irq; - avd->pm.irq = irq; - ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, - avd_irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, - dev_name(&pdev->dev), avd); - if (ret) { - dev_err(avd->dev, "Could not request IRQ 1"); - return ret; + /* Kopsia has no described completion interrupt; its backend polls. */ + if (!(avd->variant->quirks & AVD_QUIRK_KOPSIA)) { + irq = platform_get_irq(pdev, 1); + if (irq < 0) + return irq; + avd->pm.irq = irq; + ret = devm_request_threaded_irq(&pdev->dev, irq, NULL, + avd_irq_handler, IRQF_ONESHOT | IRQF_NO_AUTOEN, + dev_name(&pdev->dev), avd); + if (ret) { + dev_err(avd->dev, "Could not request IRQ 1"); + return ret; + } } /* diff --git a/drivers/media/platform/apple/avd/avd-kopsia-tunables.h b/drivers/media/platform/apple/avd/avd-kopsia-tunables.h new file mode 100644 index 0000000000000..95fb2d6d4792a --- /dev/null +++ b/drivers/media/platform/apple/avd/avd-kopsia-tunables.h @@ -0,0 +1,350 @@ +/* SPDX-License-Identifier: MIT */ +/* avd-fw v5/tier2 table, Copyright The Asahi Linux Contributors. */ +static const struct avd_kopsia_tunable kopsia_tunables[] = { + {0x0008, 0x80000000, 0x80000000}, /* MCTL_MODE */ + {0x1000, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1100, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1200, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1300, 0x80000000, 0x80000000}, /* HEVC_MODE */ + {0x1400, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1500, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1600, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1700, 0x80000000, 0x80000000}, /* H264_MODE */ + {0x1800, 0x80000000, 0x80000000}, /* VP9_MODE */ + {0x1900, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x1a00, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x1b00, 0x80000000, 0x80000000}, /* AV1_MODE */ + {0x4000, 0x80000000, 0x80000000}, /* QT_MODE */ + {0x4100, 0x80000000, 0x80000000}, /* IPMC_MODE */ + {0x4200, 0x80000000, 0x80000000}, /* LF_MODE */ + {0x4300, 0x80000000, 0x80000000}, /* MV_MODE */ + {0x4400, 0x80000000, 0x80000000}, /* TP_MODE */ + {0x4500, 0x80000000, 0x80000000}, /* PC_MODE */ + {0x4600, 0x80000000, 0x80000000}, /* SW_MODE */ + {0x4700, 0x80000000, 0x80000000}, /* LR_MODE */ + {0xc000, 0x00000001, 0x00000001}, /* VP_TOP_CLOCK_GATING */ + {0xc080, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc084, 0x1fff1fff, 0x00000028}, /* BUF */ + {0xc090, 0x000000ff, 0x00000001}, /* EXT */ + {0xc0c0, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc0c4, 0x1fff1fff, 0x00280028}, /* BUF */ + {0xc0d0, 0x000000ff, 0x00000002}, /* EXT */ + {0xc100, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc104, 0x1fff1fff, 0x00500028}, /* BUF */ + {0xc110, 0x000000ff, 0x00000003}, /* EXT */ + {0xc140, 0x800f0000, 0x80020000}, /* R_HEVC_BITS */ + {0xc144, 0x1fff1fff, 0x00780028}, /* BUF */ + {0xc150, 0x000000ff, 0x00000004}, /* EXT */ + {0xc180, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc184, 0x0fff0fff, 0x00be0028}, /* BUF */ + {0xc190, 0x000000ff, 0x00000056}, /* EXT */ + {0xc1c0, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc1c4, 0x0fff0fff, 0x00e60028}, /* BUF */ + {0xc1d0, 0x000000ff, 0x00000057}, /* EXT */ + {0xc200, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc204, 0x0fff0fff, 0x010e0028}, /* BUF */ + {0xc210, 0x000000ff, 0x00000058}, /* EXT */ + {0xc240, 0x800f0000, 0x80010000}, /* W_HEVC_INSN */ + {0xc244, 0x0fff0fff, 0x01360028}, /* BUF */ + {0xc250, 0x000000ff, 0x00000059}, /* EXT */ + {0xc280, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc284, 0x1fff1fff, 0x00a00020}, /* BUF */ + {0xc290, 0x000000ff, 0x0000000d}, /* EXT */ + {0xc2c0, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc2c4, 0x1fff1fff, 0x00c00020}, /* BUF */ + {0xc2d0, 0x000000ff, 0x0000000e}, /* EXT */ + {0xc300, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc304, 0x1fff1fff, 0x00e00020}, /* BUF */ + {0xc310, 0x000000ff, 0x0000000f}, /* EXT */ + {0xc340, 0x800f0000, 0x80020000}, /* R_H264_BITS */ + {0xc344, 0x1fff1fff, 0x01000020}, /* BUF */ + {0xc350, 0x000000ff, 0x00000010}, /* EXT */ + {0xc380, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc384, 0x0fff0fff, 0x00000004}, /* BUF */ + {0xc390, 0x000000ff, 0x00000011}, /* EXT */ + {0xc3c0, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc3c4, 0x0fff0fff, 0x00040004}, /* BUF */ + {0xc3d0, 0x000000ff, 0x00000012}, /* EXT */ + {0xc400, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc404, 0x0fff0fff, 0x00080004}, /* BUF */ + {0xc410, 0x000000ff, 0x00000013}, /* EXT */ + {0xc440, 0x800f0000, 0x80020000}, /* W_H264_ABOVE_INFO */ + {0xc444, 0x0fff0fff, 0x000c0004}, /* BUF */ + {0xc450, 0x000000ff, 0x00000014}, /* EXT */ + {0xc480, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc484, 0x1fff1fff, 0x01200006}, /* BUF */ + {0xc490, 0x000000ff, 0x00000015}, /* EXT */ + {0xc4c0, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc4c4, 0x1fff1fff, 0x01260006}, /* BUF */ + {0xc4d0, 0x000000ff, 0x00000016}, /* EXT */ + {0xc500, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc504, 0x1fff1fff, 0x012c0006}, /* BUF */ + {0xc510, 0x000000ff, 0x00000017}, /* EXT */ + {0xc540, 0x800f0000, 0x80020000}, /* R_H264_ABOVE_INFO */ + {0xc544, 0x1fff1fff, 0x01320006}, /* BUF */ + {0xc550, 0x000000ff, 0x00000018}, /* EXT */ + {0xc580, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc584, 0x0fff0fff, 0x015e0020}, /* BUF */ + {0xc590, 0x000000ff, 0x0000005a}, /* EXT */ + {0xc5c0, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc5c4, 0x0fff0fff, 0x017e0020}, /* BUF */ + {0xc5d0, 0x000000ff, 0x0000005b}, /* EXT */ + {0xc600, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc604, 0x0fff0fff, 0x019e0020}, /* BUF */ + {0xc610, 0x000000ff, 0x0000005c}, /* EXT */ + {0xc640, 0x800f0000, 0x80010000}, /* W_H264_INSN */ + {0xc644, 0x0fff0fff, 0x01be0020}, /* BUF */ + {0xc650, 0x000000ff, 0x0000005d}, /* EXT */ + {0xc680, 0x800f0000, 0x80020000}, /* R_VP9_BITS */ + {0xc684, 0x1fff1fff, 0x01380018}, /* BUF */ + {0xc690, 0x000000ff, 0x00000021}, /* EXT */ + {0xc6c0, 0x800f0000, 0x80020000}, /* W_VP9_ABOVE_INFO */ + {0xc6c4, 0x0fff0fff, 0x0010000a}, /* BUF */ + {0xc6d0, 0x000000ff, 0x00000022}, /* EXT */ + {0xc700, 0x800f0000, 0x80020000}, /* R_VP9_ABOVE_INFO */ + {0xc704, 0x1fff1fff, 0x0150000e}, /* BUF */ + {0xc710, 0x000000ff, 0x00000023}, /* EXT */ + {0xc740, 0x800f0000, 0x80020000}, /* W_VP9_SEG */ + {0xc744, 0x0fff0fff, 0x001a000a}, /* BUF */ + {0xc750, 0x000000ff, 0x00000024}, /* EXT */ + {0xc780, 0x800f0000, 0x80020000}, /* R_VP9_SEG */ + {0xc784, 0x1fff1fff, 0x015e000a}, /* BUF */ + {0xc790, 0x000000ff, 0x00000025}, /* EXT */ + {0xc7c0, 0x800f0000, 0x80020000}, /* W_VP9_COLOR */ + {0xc7c4, 0x0fff0fff, 0x0024000c}, /* BUF */ + {0xc7d0, 0x000000ff, 0x00000026}, /* EXT */ + {0xc800, 0x800f0000, 0x80020000}, /* R_VP9_COLOR */ + {0xc804, 0x1fff1fff, 0x01680012}, /* BUF */ + {0xc810, 0x000000ff, 0x00000027}, /* EXT */ + {0xc840, 0x800f0000, 0x80020000}, /* W_VP9_STATE */ + {0xc844, 0x0fff0fff, 0x0030000a}, /* BUF */ + {0xc850, 0x000000ff, 0x00000028}, /* EXT */ + {0xc880, 0x800f0000, 0x80020000}, /* R_VP9_STATE */ + {0xc884, 0x1fff1fff, 0x017a000a}, /* BUF */ + {0xc890, 0x000000ff, 0x00000029}, /* EXT */ + {0xc8c0, 0x800f0000, 0x80010000}, /* W_VP9_INSN */ + {0xc8c4, 0x0fff0fff, 0x01de0018}, /* BUF */ + {0xc8d0, 0x000000ff, 0x0000005e}, /* EXT */ + {0xc900, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc904, 0x1fff1fff, 0x01840016}, /* BUF */ + {0xc910, 0x000000ff, 0x0000002a}, /* EXT */ + {0xc940, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc944, 0x1fff1fff, 0x019a0016}, /* BUF */ + {0xc950, 0x000000ff, 0x0000002b}, /* EXT */ + {0xc980, 0x800f0000, 0x80020000}, /* R_AV1_BITS */ + {0xc984, 0x1fff1fff, 0x01b00016}, /* BUF */ + {0xc990, 0x000000ff, 0x0000002c}, /* EXT */ + {0xca00, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca04, 0x0fff0fff, 0x003a000a}, /* BUF */ + {0xca10, 0x000000ff, 0x0000002e}, /* EXT */ + {0xca40, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca44, 0x0fff0fff, 0x0044000a}, /* BUF */ + {0xca50, 0x000000ff, 0x0000002f}, /* EXT */ + {0xca80, 0x800f0000, 0x80020000}, /* W_AV1_ABOVE_INFO */ + {0xca84, 0x0fff0fff, 0x004e000a}, /* BUF */ + {0xca90, 0x000000ff, 0x00000030}, /* EXT */ + {0xcb00, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb04, 0x1fff1fff, 0x01c60014}, /* BUF */ + {0xcb10, 0x000000ff, 0x00000032}, /* EXT */ + {0xcb40, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb44, 0x1fff1fff, 0x01da0014}, /* BUF */ + {0xcb50, 0x000000ff, 0x00000033}, /* EXT */ + {0xcb80, 0x800f0000, 0x80020000}, /* R_AV1_ABOVE_INFO */ + {0xcb84, 0x1fff1fff, 0x01ee0014}, /* BUF */ + {0xcb90, 0x000000ff, 0x00000034}, /* EXT */ + {0xcc00, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc04, 0x0fff0fff, 0x00580004}, /* BUF */ + {0xcc10, 0x000000ff, 0x00000036}, /* EXT */ + {0xcc40, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc44, 0x0fff0fff, 0x005c0004}, /* BUF */ + {0xcc50, 0x000000ff, 0x00000037}, /* EXT */ + {0xcc80, 0x800f0000, 0x80020000}, /* W_AV1_SEG */ + {0xcc84, 0x0fff0fff, 0x00600004}, /* BUF */ + {0xcc90, 0x000000ff, 0x00000038}, /* EXT */ + {0xcd00, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd04, 0x1fff1fff, 0x02020008}, /* BUF */ + {0xcd10, 0x000000ff, 0x0000003a}, /* EXT */ + {0xcd40, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd44, 0x1fff1fff, 0x020a0008}, /* BUF */ + {0xcd50, 0x000000ff, 0x0000003b}, /* EXT */ + {0xcd80, 0x800f0000, 0x80020000}, /* R_AV1_SEG */ + {0xcd84, 0x1fff1fff, 0x02120008}, /* BUF */ + {0xcd90, 0x000000ff, 0x0000003c}, /* EXT */ + {0xce00, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce04, 0x0fff0fff, 0x00640008}, /* BUF */ + {0xce10, 0x000000ff, 0x0000003e}, /* EXT */ + {0xce40, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce44, 0x0fff0fff, 0x006c0008}, /* BUF */ + {0xce50, 0x000000ff, 0x0000003f}, /* EXT */ + {0xce80, 0x800f0000, 0x80020000}, /* W_AV1_COLOR */ + {0xce84, 0x0fff0fff, 0x00740008}, /* BUF */ + {0xce90, 0x000000ff, 0x00000040}, /* EXT */ + {0xcf00, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf04, 0x1fff1fff, 0x021a0010}, /* BUF */ + {0xcf10, 0x000000ff, 0x00000042}, /* EXT */ + {0xcf40, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf44, 0x1fff1fff, 0x022a0010}, /* BUF */ + {0xcf50, 0x000000ff, 0x00000043}, /* EXT */ + {0xcf80, 0x800f0000, 0x80020000}, /* R_AV1_COLOR0 */ + {0xcf84, 0x1fff1fff, 0x023a0010}, /* BUF */ + {0xcf90, 0x000000ff, 0x00000044}, /* EXT */ + {0xd000, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd004, 0x1fff1fff, 0x024a0010}, /* BUF */ + {0xd010, 0x000000ff, 0x00000046}, /* EXT */ + {0xd040, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd044, 0x1fff1fff, 0x025a0010}, /* BUF */ + {0xd050, 0x000000ff, 0x00000047}, /* EXT */ + {0xd080, 0x800f0000, 0x80020000}, /* R_AV1_COLOR1 */ + {0xd084, 0x1fff1fff, 0x026a0010}, /* BUF */ + {0xd090, 0x000000ff, 0x00000048}, /* EXT */ + {0xd100, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd104, 0x1fff1fff, 0x027a0010}, /* BUF */ + {0xd110, 0x000000ff, 0x0000004a}, /* EXT */ + {0xd140, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd144, 0x1fff1fff, 0x028a0010}, /* BUF */ + {0xd150, 0x000000ff, 0x0000004b}, /* EXT */ + {0xd180, 0x800f0000, 0x80020000}, /* R_AV1_COLOR2 */ + {0xd184, 0x1fff1fff, 0x029a0010}, /* BUF */ + {0xd190, 0x000000ff, 0x0000004c}, /* EXT */ + {0xd200, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd204, 0x0fff0fff, 0x007c0016}, /* BUF */ + {0xd210, 0x000000ff, 0x0000004e}, /* EXT */ + {0xd240, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd244, 0x0fff0fff, 0x00920016}, /* BUF */ + {0xd250, 0x000000ff, 0x0000004f}, /* EXT */ + {0xd280, 0x800f0000, 0x80020000}, /* W_AV1_PROBS */ + {0xd284, 0x0fff0fff, 0x00a80016}, /* BUF */ + {0xd290, 0x000000ff, 0x00000050}, /* EXT */ + {0xd300, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd304, 0x1fff1fff, 0x02aa0074}, /* BUF */ + {0xd310, 0x000000ff, 0x00000052}, /* EXT */ + {0xd340, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd344, 0x1fff1fff, 0x031e0074}, /* BUF */ + {0xd350, 0x000000ff, 0x00000053}, /* EXT */ + {0xd380, 0x800f0000, 0x80020000}, /* R_AV1_PROBS */ + {0xd384, 0x1fff1fff, 0x03920074}, /* BUF */ + {0xd390, 0x000000ff, 0x00000054}, /* EXT */ + {0xd400, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd404, 0x0fff0fff, 0x01f60016}, /* BUF */ + {0xd410, 0x000000ff, 0x0000005f}, /* EXT */ + {0xd440, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd444, 0x0fff0fff, 0x020c0016}, /* BUF */ + {0xd450, 0x000000ff, 0x00000060}, /* EXT */ + {0xd480, 0x800f0000, 0x80010000}, /* W_AV1_INSN */ + {0xd484, 0x0fff0fff, 0x02220016}, /* BUF */ + {0xd490, 0x000000ff, 0x00000061}, /* EXT */ + {0xd500, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd504, 0x1fff1fff, 0x040600f2}, /* BUF */ + {0xd510, 0x000000ff, 0x00000063}, /* EXT */ + {0xd540, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd544, 0x1fff1fff, 0x04f800f2}, /* BUF */ + {0xd550, 0x000000ff, 0x00000064}, /* EXT */ + {0xd580, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd584, 0x1fff1fff, 0x05ea00f2}, /* BUF */ + {0xd590, 0x000000ff, 0x00000065}, /* EXT */ + {0xd5c0, 0x800f3c00, 0x80011000}, /* R_PIPE_INSN */ + {0xd5c4, 0x1fff1fff, 0x06dc00f2}, /* BUF */ + {0xd5d0, 0x000000ff, 0x00000066}, /* EXT */ + {0xe000, 0x00000001, 0x00000001}, /* INTRA_TOP_CLOCK_GATING */ + {0xe080, 0x800f0000, 0x80020000}, /* W_IP_ABOVE_PIX */ + {0xe084, 0x0fff0fff, 0x0000001c}, /* BUF */ + {0xe090, 0x000000ff, 0x00000069}, /* EXT */ + {0xe0c0, 0x800f0000, 0x80020000}, /* R_IP_ABOVE_PIX */ + {0xe0c4, 0x1fff1fff, 0x0000002e}, /* BUF */ + {0xe0d0, 0x000000ff, 0x0000006a}, /* EXT */ + {0xe100, 0x800f0000, 0x80020000}, /* W_LF_ABOVE_PIX */ + {0xe104, 0x0fff0fff, 0x001c0054}, /* BUF */ + {0xe110, 0x000000ff, 0x00000071}, /* EXT */ + {0xe140, 0x800f0000, 0x80020000}, /* R_LF_ABOVE_PIX */ + {0xe144, 0x1fff1fff, 0x002e009e}, /* BUF */ + {0xe150, 0x000000ff, 0x00000072}, /* EXT */ + {0xe180, 0x800f0000, 0x80020000}, /* W_LF_ABOVE_INFO */ + {0xe184, 0x0fff0fff, 0x00700016}, /* BUF */ + {0xe190, 0x000000ff, 0x0000006f}, /* EXT */ + {0xe1c0, 0x800f0000, 0x80020000}, /* R_LF_ABOVE_INFO */ + {0xe1c4, 0x1fff1fff, 0x00cc0022}, /* BUF */ + {0xe1d0, 0x000000ff, 0x00000070}, /* EXT */ + {0xe200, 0x800f0000, 0x80020000}, /* W_LF_LEFT_PIX */ + {0xe204, 0x0fff0fff, 0x00860032}, /* BUF */ + {0xe210, 0x000000ff, 0x00000075}, /* EXT */ + {0xe240, 0x800f0000, 0x80020000}, /* R_LF_LEFT_PIX */ + {0xe244, 0x1fff1fff, 0x00ee0032}, /* BUF */ + {0xe250, 0x000000ff, 0x00000076}, /* EXT */ + {0xe280, 0x800f0000, 0x80020000}, /* W_LF_LEFT_INFO */ + {0xe284, 0x0fff0fff, 0x00b8000c}, /* BUF */ + {0xe290, 0x000000ff, 0x00000073}, /* EXT */ + {0xe2c0, 0x800f0000, 0x80020000}, /* R_LF_LEFT_INFO */ + {0xe2c4, 0x1fff1fff, 0x0120000c}, /* BUF */ + {0xe2d0, 0x000000ff, 0x00000074}, /* EXT */ + {0xe300, 0x800f0000, 0x80020000}, /* W_SR_LEFT_PIX */ + {0xe304, 0x0fff0fff, 0x00c40046}, /* BUF */ + {0xe310, 0x000000ff, 0x00000077}, /* EXT */ + {0xe340, 0x800f0000, 0x80020000}, /* R_SR_LEFT_PIX */ + {0xe344, 0x1fff1fff, 0x012c0046}, /* BUF */ + {0xe350, 0x000000ff, 0x00000078}, /* EXT */ + {0xe380, 0x800f0000, 0x80020000}, /* W_RF_ABOVE_INFO */ + {0xe384, 0x0fff0fff, 0x010a001a}, /* BUF */ + {0xe390, 0x000000ff, 0x00000079}, /* EXT */ + {0xe3c0, 0x800f0000, 0x80020000}, /* R_RF_ABOVE_INFO */ + {0xe3c4, 0x1fff1fff, 0x01720032}, /* BUF */ + {0xe3d0, 0x000000ff, 0x0000007a}, /* EXT */ + {0xe400, 0x800f0000, 0x80020000}, /* W_RF_LEFT_PIX */ + {0xe404, 0x0fff0fff, 0x0124002a}, /* BUF */ + {0xe410, 0x000000ff, 0x0000007d}, /* EXT */ + {0xe440, 0x800f0000, 0x80020000}, /* R_RF_LEFT_PIX */ + {0xe444, 0x1fff1fff, 0x01a4002a}, /* BUF */ + {0xe450, 0x000000ff, 0x0000007e}, /* EXT */ + {0xe480, 0x800f0000, 0x80020000}, /* W_RF_LEFT_INFO */ + {0xe484, 0x0fff0fff, 0x014e000a}, /* BUF */ + {0xe490, 0x000000ff, 0x0000007b}, /* EXT */ + {0xe4c0, 0x800f0000, 0x80020000}, /* R_RF_LEFT_INFO */ + {0xe4c4, 0x1fff1fff, 0x01ce000a}, /* BUF */ + {0xe4d0, 0x000000ff, 0x0000007c}, /* EXT */ + {0xe500, 0x800f7c00, 0x80027c00}, /* W_SW_PIX */ + {0xe504, 0x0fff0fff, 0x016800d0}, /* BUF */ + {0xe510, 0x000000ff, 0x00000085}, /* EXT */ + {0xe540, 0x800f0000, 0x80020000}, /* W_SW_LEFT */ + {0xe544, 0x0fff0fff, 0x015c000c}, /* BUF */ + {0xe550, 0x000000ff, 0x00000083}, /* EXT */ + {0xe580, 0x800f0000, 0x80020000}, /* R_SW_LEFT */ + {0xe584, 0x1fff1fff, 0x01d8000c}, /* BUF */ + {0xe590, 0x000000ff, 0x00000084}, /* EXT */ + {0xe5c0, 0x800f0000, 0x80020000}, /* W_AZ_ABOVE_PIX */ + {0xe5c4, 0x0fff0fff, 0x02380012}, /* BUF */ + {0xe5d0, 0x000000ff, 0x0000007f}, /* EXT */ + {0xe600, 0x800f0000, 0x80020000}, /* R_AZ_ABOVE_PIX */ + {0xe604, 0x1fff1fff, 0x01e40020}, /* BUF */ + {0xe610, 0x000000ff, 0x00000080}, /* EXT */ + {0xe640, 0x800f0000, 0x80020000}, /* W_AZ_LEFT_PIX */ + {0xe644, 0x0fff0fff, 0x024a006c}, /* BUF */ + {0xe650, 0x000000ff, 0x00000081}, /* EXT */ + {0xe680, 0x800f0000, 0x80020000}, /* R_AZ_LEFT_PIX */ + {0xe684, 0x1fff1fff, 0x02040060}, /* BUF */ + {0xe690, 0x000000ff, 0x00000082}, /* EXT */ + {0xe6c0, 0x800ff000, 0x80034000}, /* W_ZIP */ + {0xe6c8, 0x0fff0fff, 0x02ce009e}, /* BUF (CMP) */ + {0xe6cc, 0x0fff0fff, 0x02b6000c}, /* BUF (HDR) */ + {0xe6ec, 0x0000ffff, 0x00008789}, /* EXT */ + {0xe700, 0x800ff000, 0x80034000}, /* W_ZIP */ + {0xe708, 0x0fff0fff, 0x036c009e}, /* BUF (CMP) */ + {0xe70c, 0x0fff0fff, 0x02c2000c}, /* BUF (HDR) */ + {0xe72c, 0x0000ffff, 0x0000888a}, /* EXT */ + {0xe740, 0x800f0000, 0x80020000}, /* W_PIPE_STATS */ + {0xe744, 0x0fff0fff, 0x01580004}, /* BUF */ + {0xe750, 0x000000ff, 0x00000067}, /* EXT */ + {0xe800, 0x00000001, 0x00000001}, /* INTER_TOP_CLOCK_GATING */ + {0xe880, 0x800f0000, 0x80020000}, /* W_MV_ABOVE_INFO */ + {0xe884, 0x0fff0fff, 0x00000016}, /* BUF */ + {0xe890, 0x000000ff, 0x0000006b}, /* EXT */ + {0xe8c0, 0x800f0000, 0x80020000}, /* R_MV_ABOVE_INFO */ + {0xe8c4, 0x1fff1fff, 0x00000022}, /* BUF */ + {0xe8d0, 0x000000ff, 0x0000006c}, /* EXT */ + {0xe900, 0x800f0000, 0x80020000}, /* W_MV_COLOR */ + {0xe904, 0x0fff0fff, 0x00160022}, /* BUF */ + {0xe910, 0x000000ff, 0x0000006d}, /* EXT */ + {0xe940, 0x800f0000, 0x80020000}, /* R_MV_COLOR */ + {0xe944, 0x1fff1fff, 0x0022003e}, /* BUF */ + {0xe950, 0x000000ff, 0x0000006e}, /* EXT */ + {0xe980, 0x80ff0004, 0x80550004}, /* R_ZIP */ + {0xe9a8, 0xffffffff, 0x8d8f8c8e}, /* EXT */ +}; diff --git a/drivers/media/platform/apple/avd/avd.h b/drivers/media/platform/apple/avd/avd.h index 568cbfc6d06f8..7437b54be580d 100644 --- a/drivers/media/platform/apple/avd/avd.h +++ b/drivers/media/platform/apple/avd/avd.h @@ -46,6 +46,8 @@ /* A reset after a timeout hangs the machine: stay parked and retire the decoder */ #define AVD_QUIRK_NO_RECOVERY_RESET BIT(5) +#define AVD_QUIRK_KOPSIA BIT(6) + #define VP_SLOT_NONE 255 #define INST_FIFO_SLOT_NONE 255 @@ -410,6 +412,9 @@ void avd_queue_add_ctx(struct avd_ctx *ctx); void avd_queue_del_ctx(struct avd_ctx *ctx); int avd_open_build_program(struct avd_ctx *ctx); extern const struct avd_backend_ops avd_open_backend; +extern const struct avd_backend_ops avd_kopsia_backend; +int avd_open_submit(struct avd_dev *avd, struct avd_frame *f); +irqreturn_t avd_open_complete(struct avd_dev *avd, u32 status); extern const struct avd_backend_ops avd_apple_backend; extern const struct avd_backend_ops avd_qfw_backend; struct avd_qfw; From 61b8503ba140378c1041e7a264c610eca48aa5d4 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:29:22 +0100 Subject: [PATCH 097/112] arm64: dts: apple: t8152: describe the Kopsia video decoder Describe the T8152 Kopsia decoder in the SoC peripherals, disabled, so every T8152 board can enable it: its five register banks, PSD service 50 (apple,t8152-psd) as the power domain shared by the decoder and its DART, powered off by genpd while both are idle, and the DART as the apple,t8152-avd-dart instance with its Gen3 TLBI aperture, its initialization tunables and a 64 GiB window at 1 TiB inside the native 1..4 TiB DMA aperture. The tunables are those of the J873g's ADT. Signed-off-by: Thomas Glanzmann --- .../boot/dts/apple/t8152-peripherals.dtsi | 55 ++++++++++++++++++- 1 file changed, 53 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi index a0c5fac66cf18..20a776a76d6e5 100644 --- a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi @@ -216,11 +216,62 @@ status = "disabled"; }; + /* Kopsia decoder: PSD service 50, Gen3 DART streams 0..2. */ + ps_avd: power-controller@303a13200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13200 0x0 0x100>; + #power-domain-cells = <0>; + label = "avd"; + status = "disabled"; + }; + avd_dart: iommu@485020000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x4 0x85020000 0x0 0x20000>; + compatible = "apple,t8152-avd-dart"; + reg = <0x4 0x85020000 0x0 0x20000>, <0x2 0x300 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_avd>; + /* A 64-GiB window within the ADT's 1..4-TiB DMA aperture. */ + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = < + 0x20c 0x80000121 0x80000121 + 0x220 0xf0f 0xf0f + 0x224 0xffff 0x909 + 0x300 0x1f31 0x1 + 0x308 0x3ffffffc 0x10000000 + 0x310 0x3ffffffc 0x3ffffffc + 0x800 0xf007f 0x10000 + 0x804 0xf007f 0x20002 + 0x808 0xf007f 0x50006 + 0x80c 0xf007f 0x20026 + 0x810 0xf007f 0x3002a + 0x814 0xf007f 0x40032 + 0x818 0xf007f 0x0 + 0x81c 0xf007f 0x0 + 0x820 0xf007f 0x0 + 0x824 0xf007f 0x0 + 0x828 0xf007f 0x0 + 0x82c 0xf007f 0x0 + 0x830 0xf007f 0x0 + 0x834 0xf007f 0x0 + 0x838 0xf007f 0x0 + 0x83c 0xf007f 0x0 + 0x4600 0x2 0x2 + >; + status = "disabled"; + }; + + avd: video-codec@485400000 { + compatible = "apple,t8152-avd"; + reg = <0x4 0x85400000 0x0 0x12000>, + <0x4 0x85500000 0x0 0x4000>, + <0x4 0x85100000 0x0 0x10000>, + <0x4 0x850c0000 0x0 0x4000>, + <0x4 0x85070000 0x0 0x4000>; + reg-names = "code", "mbox", "ctrl", "wrap", "dma"; + power-domains = <&ps_avd>; + iommus = <&avd_dart 0>, <&avd_dart 1>, <&avd_dart 2>; status = "disabled"; }; From 082d3bea4bff283312c48a5093ae8c5aa925d144 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:29:27 +0100 Subject: [PATCH 098/112] arm64: dts: apple: j873: enable the Kopsia video decoder Enable the T8152 decoder, its PSD domain and its DART on the J873g. This enables the request decoder node used by FFmpeg and mpv on the M6 Mac mini. The PSD provider supplies both AVD and DART so translation is initialized only after their shared domain is powered. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi | 14 ++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 15 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi new file mode 100644 index 0000000000000..d36cd5ef242b2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-avd.dtsi @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* J873g: the Kopsia video decoder (described in t8152-peripherals.dtsi). */ + +&ps_avd { + status = "okay"; +}; + +&avd_dart { + status = "okay"; +}; + +&avd { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 169298a6c9e6c..5c229e74d5b0a 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -503,3 +503,4 @@ #include "t8152-j873-ethernet.dtsi" #include "t8152-j873-audio.dtsi" #include "t8152-j873-dcp.dtsi" +#include "t8152-j873-avd.dtsi" From d72a96be1126e1d4d946f93038807997212ae3b1 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 14:31:49 +0100 Subject: [PATCH 099/112] dt-bindings: apple: describe T8142 USB4 and PCIe-C Allow the five ACIO register windows, LSTX GPIO and router firmware tunables used by T8142. Describe its native PCIe-C compatible and require the shared MSI vector base. Include the T8142 pinctrl fallback chain used by the AOP LSTX pin. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/pci/apple,pcie.yaml | 3 +++ .../thunderbolt/apple,t8103-usb4-acio.yaml | 27 +++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index a9fd4822fd127..06405f7179fe8 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -101,6 +101,7 @@ properties: - const: apple,t8103-pciec - const: apple,t6000-pciec - const: apple,t6050-pciec + - const: apple,t8142-pciec - items: - const: apple,t8132-pciec - const: apple,t8122-pciec @@ -374,6 +375,7 @@ allOf: contains: enum: - apple,t8132-pciec + - apple,t8142-pciec - apple,t6040-pciec then: required: @@ -501,6 +503,7 @@ allOf: - apple,t6000-pciec - apple,t6040-pciec - apple,t6050-pciec + - apple,t8142-pciec then: properties: reg: diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index 01592811223d2..29c64e3b3c33e 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -52,8 +52,8 @@ properties: PCIe adapter configuration space of the USB4 router. Present where the root complex exposes the adapter separately, so that the tunnel can be configured before a PCIe-C link is brought up. - - description: MxWrap co-processor control registers, on T8132 and T6050 - - description: PCIe router AP firmware registers, on T6050 + - description: MxWrap co-processor control registers, on T8132, T8142 and T6050 + - description: PCIe router AP firmware registers, on T8142 and T6050 reg-names: oneOf: @@ -253,6 +253,7 @@ allOf: enum: - apple,t6040-usb4-acio - apple,t8132-usb4-acio + - apple,t8142-usb4-acio then: properties: reg: @@ -267,6 +268,7 @@ allOf: - apple,t6040-usb4-acio - apple,t6050-usb4-acio - apple,t8132-usb4-acio + - apple,t8142-usb4-acio then: properties: pinctrl-names: @@ -309,7 +311,28 @@ allOf: properties: power-domains: maxItems: 4 + - if: + properties: + compatible: + not: + contains: + enum: + - apple,t6050-usb4-acio + - apple,t8142-usb4-acio + then: + properties: apple,tunable-router-ap-fw: false + - if: + properties: + compatible: + contains: + const: apple,t8142-usb4-acio + then: + properties: + reg: + minItems: 5 + reg-names: + minItems: 5 additionalProperties: false From a99ebe3284a5ed4e252a8397e72f50b58d5a2fc2 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 14:31:49 +0100 Subject: [PATCH 100/112] PCI: apple: support T8142 PCIe-C MSI slices T8142 uses the Intr2AXI controller layout but its three-cell AIC interrupt specifier and MSI window differ from T6050. Match it natively. This allows a tunnelled NVMe controller to allocate working MSI-X interrupts. For T8132 and T8142 the slice is checked against the device tree alone. msi-ranges names the AIC input of global vector apple,msi-vector-base in a linear window, so the window's AIC base is msi-ranges minus apple,msi-vector-base, and the slice is checked by its shape: an edge-rising SPI, 32 vectors, 32-aligned, above the internal port's vectors and inside the 8-bit map target. This replaces T8132's table of ECAM apertures and its AIC base 1506 behind a machine check. The T8132 trees give 1602 - 0x60 = 1634 - 0x80 = 1506, and every J813 PCIe node gives 1741. Signed-off-by: Thomas Glanzmann --- drivers/pci/controller/pcie-apple.c | 53 ++++++++++++++++++++--------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 83c51324f65f8..66123f4e575ea 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -480,6 +480,22 @@ static const struct hw_info t6050_pciec_hw = { .mps_timers = true, }; +/* T8142 shares this register layout, with its own three-cell AIC MSI slice. */ +static const struct hw_info t8142_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = PORT_T6050_TUNCTRL, + .max_rid2sid = 256, + .tunneled = true, + .tunnel_intr2axi = true, + .no_port_reset = true, + .msimap_by_vector = true, + .mps_timers = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -3391,8 +3407,25 @@ static int apple_msi_init(struct apple_pcie *pcie) * 32-vector slice. Keep endpoint MSI data local, and route its table * entry to the corresponding shared-window vector. */ - if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || - pcie->hw == &t6040_pciec_hw) { + if (pcie->hw == &t8132_pciec_hw || pcie->hw == &t8142_pciec_hw) { + /* + * msi-ranges names the AIC input of global vector + * apple,msi-vector-base in a linear window, so the slice is + * checked by its shape only: an edge-rising SPI, 32 vectors, + * 32-aligned, above the internal port's vectors and inside the + * 8-bit map target. + */ + if (args.args_count != 3 || args.args[0] != 0 || + args.args[2] != IRQ_TYPE_EDGE_RISING || + of_property_read_u32(to_of_node(fwnode), + "apple,msi-vector-base", + &pcie->msi_vector_base) || + args.args[1] < pcie->msi_vector_base || + !apple_t6030_msi_slice_valid(pcie->msi_vector_base, + pcie->nvecs, args.args[1], + args.args[1] - pcie->msi_vector_base)) + goto invalid_slice; + } else if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t6040_pciec_hw) { struct resource ecam; u32 expected_base, aic_base; @@ -3429,19 +3462,6 @@ static int apple_msi_init(struct apple_pcie *pcie) default: goto invalid_slice; } - } else if (of_machine_is_compatible("apple,t8132")) { - aic_base = 1506; - switch (ecam.start) { - /* The internal port's bridges own vectors 0..95. */ - case 0x1c50000000ULL: - expected_base = 0x60; - break; - case 0x1c60000000ULL: - expected_base = 0x80; - break; - default: - goto invalid_slice; - } } else { goto invalid_slice; } @@ -3475,7 +3495,7 @@ static int apple_msi_init(struct apple_pcie *pcie) /* Keep map targets within the supported 8-bit range. */ if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || - pcie->hw == &t6040_pciec_hw) && + pcie->hw == &t6040_pciec_hw || pcie->hw == &t8142_pciec_hw) && (!pcie->nvecs || pcie->nvecs > 256 || pcie->msi_vector_base > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 - pcie->nvecs)) { @@ -7492,6 +7512,7 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, { .compatible = "apple,t6050-pciec", .data = &t6050_pciec_hw }, + { .compatible = "apple,t8142-pciec", .data = &t8142_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, From 2859f5ba4a105ceff2552aa9c8e2d378584f8b9e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:58:23 +0100 Subject: [PATCH 101/112] dt-bindings: mailbox: apple,mailbox: add the T8152 ACIO mailbox Each T8152 USB4 router's coprocessor has a 0x80-byte mailbox window with the counted FIFOs of the SMC mailbox, at offset 0x80 of its register block. Describe it with apple,t8152-smc-mailbox as the fallback, so the SMC mailbox's match data serves it, and with its send-empty and recv-not-empty interrupts. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/mailbox/apple,mailbox.yaml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 7626c8afcedbd..caa9e431a4a10 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -44,6 +44,14 @@ properties: recv-not-empty interrupts. const: apple,t8152-ascwrap-v8-mailbox + - description: + T8152 ACIO mailbox of a USB4 router's coprocessor, a 0x80 window + with the counted FIFOs of the SMC mailbox, described with its + send-empty and recv-not-empty interrupts. + items: + - const: apple,t8152-cio-mailbox + - const: apple,t8152-smc-mailbox + - description: ASC mailboxes are the most common variant found on the M1 used for example for the display controller, the system management From f150987ca39d0906049efb9399b35e0d21cc6956 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:08 +0100 Subject: [PATCH 102/112] dt-bindings: reset: apple,t8103-cio-reset: add T8152 The T8152 CIO reset block resets the rear USB4 routers of the J873g. It has a request and an acknowledge register instead of T8142's control register, so it gets its own compatible. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/reset/apple,t8103-cio-reset.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index 3b05fab7e7af1..f72d6e97577cc 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -38,6 +38,7 @@ properties: - enum: - apple,t8103-cio-reset - apple,t8142-cio-reset + - apple,t8152-cio-reset - apple,t6050-cio-reset - apple,t6000-cio-reset - apple,t6041-cio-reset From 162bb88d571974a4ffca5e9919642fc990caedd3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 103/112] dt-bindings: iommu: apple,dart: add the T8152 ACIO and PCIe-C DARTs The DARTs of the J873g rear USB4 routers (NHI streams) and of their PCIe-C tunnels are Gen3 DARTs that start unlocked with inactive streams, like the AVD's. Each has its own slot in the shared TLB invalidation aperture, and its ADT tunables and DMA window. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/iommu/apple,dart.yaml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index ba49a093eccee..8e3fcd354795e 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -34,6 +34,8 @@ properties: - apple,t6000-dart - apple,t8152-dart-gen3 - apple,t8152-avd-dart + - apple,t8152-acio-dart + - apple,t8152-pciec-dart - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -373,6 +375,8 @@ allOf: enum: - apple,t8152-dart-gen3 - apple,t8152-avd-dart + - apple,t8152-acio-dart + - apple,t8152-pciec-dart then: description: The T8152 Gen3 DARTs in front of the display coprocessors and their @@ -383,6 +387,8 @@ allOf: TLB invalidation aperture instead. The T8152 AVD instance uses the same invalidation aperture, but starts unlocked with inactive streams and is initialized by the operating system after its PSD domain is on. + So do the DARTs of the rear USB4 routers (ACIO NHI streams) and of + their PCIe-C tunnels, each at its own aperture slot. properties: reg: minItems: 2 @@ -411,6 +417,18 @@ allOf: - apple,dma-range - apple,tunable + - if: + properties: + compatible: + contains: + enum: + - apple,t8152-acio-dart + - apple,t8152-pciec-dart + then: + required: + - apple,dma-range + - apple,tunable + additionalProperties: false examples: From 76988e647e0d0adffeef83785dd40a5bc7adfaf5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 104/112] dt-bindings: pci: apple,pcie: add T8152 PCIe-C The PCIe-C ports tunnelled through the J873g rear USB4 routers are laid out like T8142's: Intr2AXI MSI slices, the T6050 tunnel controls, and no port reset of their own. Signed-off-by: Thomas Glanzmann --- Documentation/devicetree/bindings/pci/apple,pcie.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 06405f7179fe8..70700cb86b839 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -102,6 +102,7 @@ properties: - const: apple,t6000-pciec - const: apple,t6050-pciec - const: apple,t8142-pciec + - const: apple,t8152-pciec - items: - const: apple,t8132-pciec - const: apple,t8122-pciec @@ -376,6 +377,7 @@ allOf: enum: - apple,t8132-pciec - apple,t8142-pciec + - apple,t8152-pciec - apple,t6040-pciec then: required: @@ -504,6 +506,7 @@ allOf: - apple,t6040-pciec - apple,t6050-pciec - apple,t8142-pciec + - apple,t8152-pciec then: properties: reg: From 28d7ab4e7c4b95570fea687f32466cbbe37675c8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 105/112] dt-bindings: thunderbolt: add T8152 USB4 routers and USB-C ports Add the T8152 ACIO and NHI. The T8152 router CPU is started by a reconfiguration request through its mailbox, so it has no cpu window. A second range maps the shared Gen3 TLB invalidation aperture for the router's DART. Describe a J873g rear USB-C port as its USB4 router sees it. The port has no Type-C driver, because the display driver owns its PD controller for DisplayPort alternate mode. The node gives the ATC PHY, its PMGR power states and PSD service, the PD controller, and the ADT tunables for CIO mode, linked to the router's Thunderbolt switch. Signed-off-by: Thomas Glanzmann --- .../thunderbolt/apple,t8103-usb4-acio.yaml | 30 ++++- .../thunderbolt/apple,t8103-usb4-nhi.yaml | 3 + .../thunderbolt/apple,t8152-usb4-port.yaml | 108 ++++++++++++++++++ 3 files changed, 139 insertions(+), 2 deletions(-) create mode 100644 Documentation/devicetree/bindings/thunderbolt/apple,t8152-usb4-port.yaml diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index 29c64e3b3c33e..70a883b4696fe 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -30,6 +30,7 @@ properties: oneOf: - const: apple,t8103-usb4-acio - const: apple,t8142-usb4-acio + - const: apple,t8152-usb4-acio - const: apple,t6040-usb4-acio - const: apple,t6050-usb4-acio - items: @@ -69,6 +70,14 @@ properties: - const: rc - const: sram - const: cpu + - description: + T8152, whose router CPU is started by a reconfiguration request + through its mailbox and has no window of its own + items: + - const: rc + - const: sram + - const: pcie-adapter + - const: router-ap-fw mboxes: maxItems: 1 @@ -185,8 +194,12 @@ properties: const: 1 ranges: - maxItems: 1 - description: Single 16 MiB MMIO window containing all child registers + minItems: 1 + maxItems: 2 + description: + 16 MiB MMIO window containing the child registers. On T8152 a second + range maps the shared Gen3 DART TLB invalidation aperture for the + router's DART. nonposted-mmio: true @@ -254,12 +267,23 @@ allOf: - apple,t6040-usb4-acio - apple,t8132-usb4-acio - apple,t8142-usb4-acio + - apple,t8152-usb4-acio then: properties: reg: minItems: 4 reg-names: minItems: 4 + - if: + properties: + compatible: + not: + contains: + const: apple,t8152-usb4-acio + then: + properties: + ranges: + maxItems: 1 - if: properties: compatible: @@ -269,6 +293,7 @@ allOf: - apple,t6050-usb4-acio - apple,t8132-usb4-acio - apple,t8142-usb4-acio + - apple,t8152-usb4-acio then: properties: pinctrl-names: @@ -319,6 +344,7 @@ allOf: enum: - apple,t6050-usb4-acio - apple,t8142-usb4-acio + - apple,t8152-usb4-acio then: properties: apple,tunable-router-ap-fw: false diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml index 28718fed167c5..c68f883b10d0f 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml @@ -22,6 +22,7 @@ properties: oneOf: - const: apple,t8103-usb4-nhi - const: apple,t8142-usb4-nhi + - const: apple,t8152-usb4-nhi - const: apple,t6040-usb4-nhi - const: apple,t6050-usb4-nhi - items: @@ -131,6 +132,7 @@ allOf: contains: enum: - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi - apple,t6040-usb4-nhi - apple,t6050-usb4-nhi then: @@ -155,6 +157,7 @@ allOf: - apple,t8122-usb4-nhi - apple,t8132-usb4-nhi - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi - apple,t6040-usb4-nhi - apple,t6050-usb4-nhi then: diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8152-usb4-port.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8152-usb4-port.yaml new file mode 100644 index 0000000000000..9fa0bb136958a --- /dev/null +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8152-usb4-port.yaml @@ -0,0 +1,108 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thunderbolt/apple,t8152-usb4-port.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 USB-C port in USB4 mode + +maintainers: + - Thomas Glanzmann + +description: + A rear USB-C port of the J873g (M6 Mac mini) as seen by its USB4 router. + The port's ACE3 PD controller has no Type-C driver; the display driver + uses it for DisplayPort alternate mode. This node describes the ATC PHY, + its PMGR power states and PSD service, and the ADT tunables that put the + PHY into CIO mode, so that a USB4 cable reported by the PD controller can + be handed to the router's Thunderbolt switch. The ATC register blocks are + shared with the display driver and are mapped without being claimed. + +properties: + compatible: + const: apple,t8152-usb4-port + + reg: + items: + - description: ATC PHY + - description: PMGR power states DP_0 (+0), DP_1 (+0x20), USB_AON (+0x100) + - description: PMGR2 PSD service of the ATC common block + + reg-names: + items: + - const: phy + - const: ps + - const: psd + + label: + description: Name of the connector on the chassis. + + apple,usb-pd: + $ref: /schemas/types.yaml#/definitions/phandle + description: The port's PD controller on the SPMI bus. + + apple,tunable-phy-pre: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: PHY register offset + - description: mask + - description: value + description: + ADT tunables applied once the PHY's register bus is up, before the + lanes are configured (atc-phyN tunable_ACIOPHY_CMN_DFLT and + tunable_CIOPLL_CORE_DFLT at their register blocks). + + apple,tunable-phy-post: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: PHY register offset + - description: mask + - description: value + description: + ADT tunables applied after the crossbar is set to CIO mode + (tunable_ATC_FABRIC, tunable_ATC_COMMON_CFG and the CIO lane groups). + + port: + $ref: /schemas/graph.yaml#/properties/port + description: Link to the Thunderbolt switch of the port's USB4 router. + +required: + - compatible + - reg + - reg-names + - apple,usb-pd + - apple,tunable-phy-pre + - apple,tunable-phy-post + - port + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + hpm3: usb-pd { + }; + + usb4-port@413000000 { + compatible = "apple,t8152-usb4-port"; + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0x100>; + reg-names = "phy", "ps", "psd"; + label = "USB-C Back-right"; + apple,usb-pd = <&hpm3>; + apple,tunable-phy-pre = <0x4000 0x1 0x1>; + apple,tunable-phy-post = <0x60000 0x2 0x2>; + + port { + usb4_port3_sw: endpoint { + remote-endpoint = <&usb4_port3_sw>; + }; + }; + }; + }; From 018d691e1f2889925f4a68cc080dfda1e9cf6e71 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 106/112] reset: apple-cio: add T8152 The T8152 CIO reset block requests a router reset in register 0x68 and acknowledges it in 0x6c. Wait for the router's pair of busy bits to clear, request, wait for the acknowledgment and clear it. Signed-off-by: Thomas Glanzmann --- drivers/reset/reset-apple-cio.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/drivers/reset/reset-apple-cio.c b/drivers/reset/reset-apple-cio.c index e5755ebb39aff..b2dd69f30fde3 100644 --- a/drivers/reset/reset-apple-cio.c +++ b/drivers/reset/reset-apple-cio.c @@ -200,6 +200,31 @@ static int t8142_cio_deassert(struct apple_cio_reset *priv, unsigned long id) APPLE_CIO_RESET_TIMEOUT_US); } +static int t8152_cio_deassert(struct apple_cio_reset *priv, unsigned long id) +{ + u32 val, busy = id < 2 ? 3 : 12; + int ret; + + guard(mutex)(&priv->lock); + ret = regmap_read_poll_timeout(priv->regmap, 0x68, val, + !(val & busy), 10, 192000); + if (ret) + return ret; + ret = regmap_write(priv->regmap, 0x68, BIT(id)); + if (ret) + return ret; + ret = regmap_read_poll_timeout(priv->regmap, 0x6c, val, + val & BIT(id), 10, 192000); + if (ret) + return ret; + return regmap_write(priv->regmap, 0x6c, BIT(id)); +} + +static const struct apple_cio_reset_variant apple_t8152_cio_reset = { + .nr_resets = 4, + .deassert = t8152_cio_deassert, +}; + static const struct apple_cio_reset_variant apple_t8142_cio_reset = { .nr_resets = 4, .ctrl = T8142_CIO_CTRL, @@ -330,6 +355,7 @@ static int apple_cio_reset_probe(struct platform_device *pdev) } static const struct of_device_id apple_cio_reset_match[] = { + { .compatible = "apple,t8152-cio-reset", .data = &apple_t8152_cio_reset }, { .compatible = "apple,t6050-cio-reset", .data = &apple_t6050_cio_reset, From 2a843012fa6b499f19f263e1e512bfdac7f2744a Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 107/112] iommu: apple-dart: initialize the cold T8152 ACIO and PCIe-C DARTs The DARTs of the T8152 USB4 routers and their PCIe-C tunnels start unlocked with inactive streams, like the AVD's. Initialize the instances their compatibles select the same way: - ACIO DART (apple,t8152-acio-dart): NHI streams 0-11 and 16-27. - PCIe-C DART (apple,t8152-pciec-dart): translated streams 0-252, with 253 and 255 in bypass for host transactions and MSI writes to the AIC (the ADT reserves them), firmware's stream 254 preserved, 16K pages, 42-bit addresses. Without the bypass on 255, NVMe completions were polled and the DART faulted at the AIC. Each DART invalidates through the TLBI slot its "tlbi" resource names. The slot has to be the port's own: with port 3's slot on port 1's DART, reads returned wrong data with DART faults. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 75 ++++++++++++++++++++++++++++++++++---- 1 file changed, 68 insertions(+), 7 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index df8380c2eece9..79a14bec1c36e 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -362,6 +362,8 @@ struct apple_dart_fw_tree { struct apple_dart { bool cold_gen3; + u32 cold_gen3_sids; + bool cold_gen3_pcie; struct device *dev; const struct apple_dart_hw *hw; @@ -2652,11 +2654,33 @@ static int apple_dart_hw_reset(struct apple_dart *dart) if (dart->cold_gen3) { stream_map.dart = dart; bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS); - bitmap_set(stream_map.sidmap, 0, 3); + for (i = 0; i < 32; i++) + if (dart->cold_gen3_sids & BIT(i)) + __set_bit(i, stream_map.sidmap); + if (dart->cold_gen3_pcie) + bitmap_set(stream_map.sidmap, 0, 253); apple_dart_hw_disable_dma(&stream_map); apple_dart_hw_clear_all_ttbrs(&stream_map); apple_dart_apply_own_tunables(dart); - apple_dart_writel(dart, 7, dart->hw->enable_streams); + apple_dart_writel(dart, apple_dart_readl(dart, dart->hw->enable_streams) | + dart->cold_gen3_sids, dart->hw->enable_streams); + if (dart->cold_gen3_pcie) { + /* ADT reserves 253/255 for host transactions, including MSI + * writes to AIC. Stream 254 belongs to firmware; preserve it. + */ + for (i = 253; i <= 255; i += 2) { + apple_dart_writel(dart, DART_T8110_TCR_BYPASS_DART, + DART_TCR(dart, i)); + __set_bit(i, stream_map.sidmap); + } + for (i = 0; i < 8; i++) { + u32 reg = dart->hw->enable_streams + i * 4; + u32 enabled = apple_dart_readl(dart, reg); + + enabled |= i == 7 ? (U32_MAX & ~BIT(30)) : U32_MAX; + apple_dart_writel(dart, enabled, reg); + } + } return dart->hw->invalidate_tlb(&stream_map); } @@ -4024,6 +4048,9 @@ static int apple_dart_of_xlate(struct device *dev, return i; sid = args->args[0]; + if (dart->cold_gen3 && (dart->cold_gen3_pcie ? (sid < 0 || sid >= 253) : + (sid < 0 || sid >= 32 || !(dart->cold_gen3_sids & BIT(sid))))) + return -EPERM; if (dart->isp_host && sid != 0 && sid != 12) return -EINVAL; if (dart->cold_ane && sid != 0) @@ -5559,6 +5586,16 @@ static int apple_dart_probe(struct platform_device *pdev) dart->hw = of_device_get_match_data(dev); dart->tunneled = tunneled; dart->cold_gen3 = of_device_is_compatible(dev->of_node, "apple,t8152-avd-dart"); + dart->cold_gen3_sids = dart->cold_gen3 ? 7 : 0; + if (of_device_is_compatible(dev->of_node, "apple,t8152-acio-dart")) { + dart->cold_gen3 = true; + dart->cold_gen3_sids = 0x0fff0fff; + } + if (of_device_is_compatible(dev->of_node, "apple,t8152-pciec-dart")) { + dart->cold_gen3 = true; + dart->cold_gen3_pcie = true; + dart->cold_gen3_sids = U32_MAX; + } dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-ane-dart"); if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) @@ -5765,7 +5802,7 @@ static int apple_dart_probe(struct platform_device *pdev) ret = devm_pm_runtime_enable(dev); if (ret) goto err_clk_disable; - if (tunneled && dart->tunables) { + if (tunneled && dart->tunables && !dart->cold_gen3) { dev_dbg(dev, "applying %zu PCIe-C DART tunables\n", dart->tunables->sz); apple_dart_apply_tunables(dart, dart->tunables); @@ -5781,7 +5818,14 @@ static int apple_dart_probe(struct platform_device *pdev) * pages, a 32-bit IOVA, a 36-bit PA and as many streams as its * register block describes. */ - if (dart->hw->type == DART_T8110) { + if (dart->cold_gen3_pcie) { + dart->pgsize = SZ_16K; + dart->supports_bypass = true; + dart->ias = dart->oas = 42; + dart->num_streams = 256; + dart->four_level = false; + dart->version = 0x300; + } else if (dart->hw->type == DART_T8110) { dart->pgsize = 1 << DART_PCIEC_PAGE_SHIFT; dart->supports_bypass = true; dart->ias = DART_PCIEC_ADDR_WIDTH; @@ -5978,18 +6022,33 @@ static int apple_dart_probe(struct platform_device *pdev) if (dart->hw->gen3) { struct resource *tlbi; - /* Cold initialization is qualified only for the AVD instance. */ + /* Cold setup only for the instances a T8152 compatible selects. */ if (!dart->locked && !dart->cold_gen3) { dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); ret = -ENODEV; goto err_clk_disable; } if (dart->cold_gen3 && (dart->locked || dart->version != 0x300 || - dart->num_streams != 16 || !dev->pm_domain || !dart->tunables || - (apple_dart_readl(dart, dart->hw->enable_streams) & 7))) { + !dart->tunables || + (dart->cold_gen3_pcie ? (!tunneled || !dev->pm_domain) : + dart->cold_gen3_sids == 7 ? + (dart->num_streams != 16 || !dev->pm_domain) : + dart->num_streams != 32) || + (apple_dart_readl(dart, dart->hw->enable_streams) & dart->cold_gen3_sids))) { ret = -EINVAL; goto err_clk_disable; } + if (dart->cold_gen3_pcie) { + for (sid = 0; sid < 8; sid++) { + u32 mask = sid == 7 ? GENMASK(28, 0) : U32_MAX; + u32 reg = dart->hw->enable_streams + sid * 4; + + if (apple_dart_readl(dart, reg) & mask) { + ret = -EBUSY; + goto err_clk_disable; + } + } + } /* The aperture is shared by every Gen3 DART: map, do not claim. */ tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); if (!tlbi || resource_size(tlbi) < 16) { @@ -7310,6 +7369,8 @@ static const struct dev_pm_ops apple_dart_pm_ops = { static const struct of_device_id apple_dart_of_match[] = { { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8152-avd-dart", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-acio-dart", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-pciec-dart", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, From de6a358009387ac4c5739b84b272f61eab964a86 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:59:15 +0100 Subject: [PATCH 108/112] PCI: apple: add T8152 PCIe-C The T8152 tunnelled PCIe-C ports use the T6050 tunnel controls with the Intr2AXI MSI path, like T8142, and their MSI slices are checked the same way: from msi-ranges and apple,msi-vector-base alone. The J873g's three bridges use 0x60 (CIO0, ECAM 0x1c50000000), 0x80 (CIO1, 0x1c60000000) and 0xc0 (CIO3, 0x1c80000000) of the window at AIC 1879. Signed-off-by: Thomas Glanzmann --- drivers/pci/controller/pcie-apple.c | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 66123f4e575ea..a7929618b416e 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -496,6 +496,22 @@ static const struct hw_info t8142_pciec_hw = { .mps_timers = true, }; +/* T8152 PCIe-C: the T8142 layout, with a third PCIe-C bridge (CIO3). */ +static const struct hw_info t8152_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = PORT_T6050_TUNCTRL, + .max_rid2sid = 256, + .tunneled = true, + .tunnel_intr2axi = true, + .no_port_reset = true, + .msimap_by_vector = true, + .mps_timers = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -3407,7 +3423,8 @@ static int apple_msi_init(struct apple_pcie *pcie) * 32-vector slice. Keep endpoint MSI data local, and route its table * entry to the corresponding shared-window vector. */ - if (pcie->hw == &t8132_pciec_hw || pcie->hw == &t8142_pciec_hw) { + if (pcie->hw == &t8132_pciec_hw || pcie->hw == &t8142_pciec_hw || + pcie->hw == &t8152_pciec_hw) { /* * msi-ranges names the AIC input of global vector * apple,msi-vector-base in a linear window, so the slice is @@ -3495,7 +3512,8 @@ static int apple_msi_init(struct apple_pcie *pcie) /* Keep map targets within the supported 8-bit range. */ if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || - pcie->hw == &t6040_pciec_hw || pcie->hw == &t8142_pciec_hw) && + pcie->hw == &t6040_pciec_hw || pcie->hw == &t8142_pciec_hw || + pcie->hw == &t8152_pciec_hw) && (!pcie->nvecs || pcie->nvecs > 256 || pcie->msi_vector_base > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 - pcie->nvecs)) { @@ -7513,6 +7531,7 @@ static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, { .compatible = "apple,t6050-pciec", .data = &t6050_pciec_hw }, { .compatible = "apple,t8142-pciec", .data = &t8142_pciec_hw }, + { .compatible = "apple,t8152-pciec", .data = &t8152_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, From e5e2fa1aa7d39bc272beb527d3b928c2fbb173e7 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 109/112] thunderbolt: apple: support the T8152 routers The T8152 router is a Type 7 MXWrap-v2p3 that a reconfiguration request starts through its counted mailbox. Its DP IN path is not qualified. Release the CIO domains in reverse order and suspend each one synchronously, because deleting the device link only queues an idle request: the PHY reset and the next router start need them cold. Signed-off-by: Thomas Glanzmann --- drivers/thunderbolt/apple.c | 57 +++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 15 deletions(-) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index ac8e1a4205098..6ffc8fdbaa462 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -171,6 +171,8 @@ struct apple_cio_hw { bool gen4_link_recovery; /* Leave the host router's TMU to its firmware; host TMU constants. */ bool host_tmu; + /* Drain PSD runtime power-off before the PHY is reset or reused. */ + bool psd_power_cycle; const struct apple_dpin_policy *dp; }; @@ -206,6 +208,17 @@ static const struct apple_cio_hw apple_cio_t8132_hw = { .dp = &apple_dpin_m4, }; +/* MXWrap-v2p3 is started by reconfiguration, using its counted mailbox. */ +static const struct apple_cio_hw apple_cio_t8152_hw = { + .psd_power_cycle = true, + .type7 = true, + .lstx_after_boot = true, + .strict_fw_ready = true, + .no_host_clx = true, + .no_asym = true, + .dp = &apple_dpin_disabled, +}; + /* Type 7 uses its existing ready-state check and has no qualified DP route. */ static const struct apple_cio_hw apple_cio_t8142_hw = { .type7 = true, @@ -1305,7 +1318,8 @@ static void apple_cio_of_node_put(void *data) static bool apple_cio_pciec_eligible(const struct device_node *np) { - return of_device_is_compatible(np, "apple,t6040-pciec") || + return of_device_is_compatible(np, "apple,t8152-pciec") || + of_device_is_compatible(np, "apple,t6040-pciec") || of_device_is_compatible(np, "apple,t8103-pciec") || of_device_is_compatible(np, "apple,t6000-pciec") || of_device_is_compatible(np, "apple,t6050-pciec"); @@ -2591,7 +2605,8 @@ static int apple_nhi_probe(struct platform_device *pdev) /* The T6050 router is the Type 7 one released by a RUN store. */ if (acio->type7 != - (of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || + (of_device_is_compatible(pdev->dev.of_node, "apple,t8152-usb4-nhi") || + of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi") || of_device_is_compatible(pdev->dev.of_node, "apple,t6050-usb4-nhi")) || acio->hw->run_store != @@ -3091,6 +3106,7 @@ static const struct of_device_id apple_nhi_match[] = { { .compatible = "apple,t6050-usb4-nhi", }, + { .compatible = "apple,t8152-usb4-nhi" }, { .compatible = "apple,t8142-usb4-nhi", }, @@ -3301,6 +3317,26 @@ static void apple_cio_test_log_guards(struct apple_cio *acio) dev_info(acio->dev, "TEST sv6t7: ACIO stop, its domain links go next: PS_PROT%s\n", buf); } +static void apple_cio_release_domains(struct apple_cio *acio) +{ + int n, i, ret; + + for (n = 0; n < acio->pd_list->num_pds; n++) { + i = acio->hw->psd_power_cycle ? acio->pd_list->num_pds - 1 - n : n; + dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); + if (!acio->pd_list->pd_links[i]) + continue; + device_link_del(acio->pd_list->pd_links[i]); + acio->pd_list->pd_links[i] = NULL; + if (!acio->hw->psd_power_cycle) + continue; + /* Link removal only queues idle; finish it before returning. */ + ret = pm_runtime_suspend(acio->pd_list->pd_devs[i]); + if (ret < 0) + dev_warn(acio->dev, "PSD domain %d failed to suspend: %d\n", i, ret); + } +} + /** * apple_cio_stop - Stop and power down the ACIO complex * @acio: ACIO complex to stop @@ -3311,7 +3347,7 @@ static void apple_cio_test_log_guards(struct apple_cio *acio) */ static void apple_cio_stop(struct apple_cio *acio) { - int ret, i; + int ret; lockdep_assert_held(&acio->lock); if (!acio->current_cable_info) @@ -3336,12 +3372,7 @@ static void apple_cio_stop(struct apple_cio *acio) apple_cio_test_log_guards(acio); /* Finally, remove the links to the PD domains to power everything off */ - for (i = 0; i < acio->pd_list->num_pds; i++) { - if (acio->pd_list->pd_links[i]) - device_link_del(acio->pd_list->pd_links[i]); - acio->pd_list->pd_links[i] = NULL; - dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); - } + apple_cio_release_domains(acio); acio->current_cable_info = 0; acio->resume_link_failed = false; @@ -3602,12 +3633,7 @@ static int apple_cio_start(struct apple_cio *acio) acio->rtk = NULL; apple_cio_cpu_halt(acio); /* Cut power to reset the entire block */ - for (i = 0; i < acio->pd_list->num_pds; i++) { - if (acio->pd_list->pd_links[i]) - device_link_del(acio->pd_list->pd_links[i]); - acio->pd_list->pd_links[i] = NULL; - dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); - } + apple_cio_release_domains(acio); return ret; } @@ -4759,6 +4785,7 @@ static const struct of_device_id apple_acio_match[] = { .compatible = "apple,t6050-usb4-acio", .data = &apple_cio_t6050_hw, }, + { .compatible = "apple,t8152-usb4-acio", .data = &apple_cio_t8152_hw }, { .compatible = "apple,t8142-usb4-acio", .data = &apple_cio_t8142_hw, From f17bfeb605445329b865e48e7dc64bdccdb4e70f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 110/112] thunderbolt: add the T8152 USB-C port monitor The J873g's rear USB-C ports have no Type-C port driver, because the display driver uses their ACE3 PD controllers for DisplayPort alternate mode. Add a monitor that polls a port's controller every 250 ms, under the controller's device lock: - A USB4 cable (STATUS plug, DATA_STATUS bit 23): power the ATC up (USB AON, the common block's PSD, DP_0, DP_1) and take the PHY only when its CIO control shows it idle. Apply the ADT tunables, configure both lanes and the crossbar for the orientation, then hand the cable with its EUDO to the router's Thunderbolt switch. - An unplug or a changed cable: stop the router, then run the firmware's CIO shutdown and return the PSD to its cold state, so the next cable starts cold. A switch notification asks for a fresh poll, which catches a reconnect shorter than the poll period. - No cable: wake a sleeping controller with SSPS 0, otherwise it never reports one. - An upstream host (the debug USB link) is left alone. Setup failures are retried three times per cable. A reboot notifier stops the router before the PCIe and DART devices shut down. sysfs "state" shows the PD registers and counters; "enabled" stops and restarts a port. Signed-off-by: Thomas Glanzmann --- drivers/thunderbolt/Kconfig | 13 + drivers/thunderbolt/Makefile | 2 + drivers/thunderbolt/apple-t8152-port.c | 732 +++++++++++++++++++++++++ 3 files changed, 747 insertions(+) create mode 100644 drivers/thunderbolt/apple-t8152-port.c diff --git a/drivers/thunderbolt/Kconfig b/drivers/thunderbolt/Kconfig index 0e1e1864c927f..e7172d5d13259 100644 --- a/drivers/thunderbolt/Kconfig +++ b/drivers/thunderbolt/Kconfig @@ -89,6 +89,19 @@ config USB4_APPLE_SOC To compile the driver as a module, choose M here. The module will be called thunderbolt_apple. +config USB4_APPLE_T8152_PORT + tristate "Apple T8152 rear USB-C ports in USB4 mode" + depends on USB4_APPLE_SOC && SPMI + select APPLE_TUNABLE + help + Say Y here to use USB4 devices on the rear USB-C ports of the + Apple M6 Mac mini (J873g). The driver watches the ports' PD + controllers for a USB4 cable, brings the ATC PHY up in CIO mode + and starts the port's USB4 router. + + To compile the driver as a module, choose M here. The module + will be called apple-t8152-usb4-port. + config USB4_APPLE_DPIN_KUNIT_TEST bool "Apple DP-IN lifecycle tests" if !KUNIT_ALL_TESTS depends on USB4_APPLE_SOC && KUNIT=y diff --git a/drivers/thunderbolt/Makefile b/drivers/thunderbolt/Makefile index bf542c5f108ed..819a8acd59b51 100644 --- a/drivers/thunderbolt/Makefile +++ b/drivers/thunderbolt/Makefile @@ -20,3 +20,5 @@ obj-$(CONFIG_USB4_STREAM) += thunderbolt_stream.o obj-$(CONFIG_USB4_APPLE_SOC) += thunderbolt_apple.o thunderbolt_apple-y := apple.o apple-dpin-state.o thunderbolt_apple-$(CONFIG_USB4_APPLE_DPIN_KUNIT_TEST) += apple-dpin-test.o +obj-$(CONFIG_USB4_APPLE_T8152_PORT) += apple-t8152-usb4-port.o +apple-t8152-usb4-port-y := apple-t8152-port.o diff --git a/drivers/thunderbolt/apple-t8152-port.c b/drivers/thunderbolt/apple-t8152-port.c new file mode 100644 index 0000000000000..749f799446bb5 --- /dev/null +++ b/drivers/thunderbolt/apple-t8152-port.c @@ -0,0 +1,732 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 (J873g) rear USB-C ports in USB4 mode + * + * The J873g's rear ports have no Type-C port controller driver: the display + * driver (apple_dcpib) talks to the ACE3 PD controllers itself for DP alt + * mode. This driver watches the same controllers for a USB4 cable, powers + * the port's ATC PHY up in CIO mode with the ADT tunables, and hands the + * cable to the ACIO router through its Thunderbolt switch. On unplug it + * stops the router and takes the PHY down with the firmware's CIO shutdown + * sequence, so that the next cable, in either orientation, starts from a + * cold PHY and a cold router. + * + * The ATC register blocks are shared with apple_dcpib, which drives the same + * PHY for DisplayPort: the PHY is only taken over when its control register + * shows it idle, and the PD controller's register window is used under its + * device lock. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* ATC PHY: lane controls in the AON block, CIO power control in CFG. */ +#define ATC_XBAR_CFG 0x4c +#define ATC_XBAR_CIO_MASK GENMASK(4, 0) +#define ATC_LANE_CTRL(n) (0x1e18 + 4 * (n)) +#define ATC_LANE_PMA_EN BIT(5) +#define ATC_LANE_PMA_CLAMP BIT(0) +#define ATC_LANE_PMA_RST_N BIT(2) +#define ATC_LANE_PMA_PWR BIT(1) +#define ATC_LANE_CLK 0x1e24 +#define ATC_LANE_CLK_REQ(n) BIT(12 + 2 * (n)) +#define ATC_LANE_CLK_EN(n) BIT(16 + 2 * (n)) +#define ATC_CIO_CTRL 0x60000 +#define ATC_CIO_CTRL_SB BIT(0) +#define ATC_CIO_CTRL_PLL BIT(1) +#define ATC_CIO_CTRL_ISO BIT(2) +#define ATC_CIO_CTRL_BUS BIT(3) +#define ATC_CIO_CTRL_READY BIT(4) +#define ATC_CIO_CTRL_IDLE ATC_CIO_CTRL_ISO +#define ATC_CIO_STATUS 0x60004 +#define ATC_CIO_SWAP 0x60008 +#define ATC_CIO_SWAP_FLIP BIT(1) +#define ATC_CIO_CLK 0x60030 +#define ATC_CIO_CLK_EN BIT(0) +#define ATC_TIMEOUT_US 10000 + +/* PMGR power states of the port: DP_0 (+0), DP_1 (+0x20), USB AON (+0x100). */ +#define PS_DP0 0x000 +#define PS_DP1 0x020 +#define PS_USB_AON 0x100 +#define PS_TARGET 0xf +#define PS_ACTUAL GENMASK(7, 4) +#define PS_RESET_MASK 0x30f + +/* PMGR2 PSD service of the ATC: state 0 powered, 6 cold. */ +#define PSD_STATE 0x80 +#define PSD_STATE_MASK GENMASK(2, 0) +#define PSD_TARGET 0x90 +#define PSD_ACK 0xbc +#define PSD_ON 0 +#define PSD_COLD 6 + +/* ACE3 PD controller: a register selector with a 32-byte data window. */ +#define ACE3_SELECT 0x00 +#define ACE3_DATA 0x20 +#define ACE3_CMD1 0x08 +#define ACE3_DATA1 0x09 +#define ACE3_STATUS 0x1a +#define ACE3_STATUS_PLUG BIT(0) +#define ACE3_STATUS_FLIP BIT(4) +#define ACE3_POWER_STATE 0x20 +#define ACE3_USB4_STATUS 0x24 +#define ACE3_DATA_STATUS 0x5f +#define ACE3_DS_UPSTREAM BIT(7) +#define ACE3_DS_USB4_TRAINING BIT(20) +#define ACE3_DS_USB4 BIT(23) + +#define POLL_MS 250 +#define RETRY_MS 1000 +#define MAX_RETRIES 3 + +struct apple_t8152_port { + struct device *dev; + void __iomem *phy; + void __iomem *ps; + void __iomem *psd; + struct apple_tunable *tunable_pre, *tunable_post; + struct spmi_device *pd; + struct typec_thunderbolt_switch *sw; + struct typec_thunderbolt_switch_data cable; + struct notifier_block reboot_nb, switch_nb; + struct delayed_work work; + struct mutex lock; /* port state, PHY and router transitions */ + unsigned int retries, connections, disconnects; + unsigned long healthy_since; + u32 status, data_status; + int last_error; + bool enabled, stopping, active, phy_owned; +}; + +static struct workqueue_struct *apple_t8152_port_wq; + +static void port_update(void __iomem *reg, u32 mask, u32 set) +{ + writel((readl(reg) & ~mask) | set, reg); + udelay(1); +} + +static void port_apply_tunable(void __iomem *base, const struct apple_tunable *t) +{ + for (size_t i = 0; i < t->sz; i++) + port_update(base + t->values[i].offset, t->values[i].mask, + t->values[i].value); +} + +static int port_psd_set(struct apple_t8152_port *port, u32 target) +{ + u32 state = readl(port->psd + PSD_STATE), ack; + int ret; + + if ((state & PSD_STATE_MASK) == target) + return 0; + writel(target, port->psd + PSD_TARGET); + ret = readl_poll_timeout(port->psd + PSD_ACK, ack, ack & 1, 10, 1000000); + state = readl(port->psd + PSD_STATE); + if (ret || (state & PSD_STATE_MASK) != target) { + dev_err(port->dev, "PSD state %u not reached: state %#x ack %#x\n", + target, state, ack); + return ret ?: -EIO; + } + return 0; +} + +static int port_ps_on(struct apple_t8152_port *port, unsigned int offset) +{ + u32 val; + + port_update(port->ps + offset, PS_RESET_MASK, PS_TARGET); + return readl_poll_timeout(port->ps + offset, val, + (val & PS_ACTUAL) == PS_ACTUAL, 10, 100000); +} + +/* The firmware's CIO shutdown; the router must already be stopped. */ +static int port_phy_off(struct apple_t8152_port *port) +{ + void __iomem *phy = port->phy; + u32 val; + int ret; + + /* A failed power-up may not have released the register bus yet. */ + if (readl(phy + ATC_CIO_CTRL) & ATC_CIO_CTRL_BUS) { + port_update(phy + ATC_LANE_CLK, 0, BIT(10)); + port_update(phy + ATC_LANE_CLK, BIT(6), 0); + port_update(phy + ATC_LANE_CLK, BIT(8), 0); + for (int lane = 0; lane < 2; lane++) { + port_update(phy + ATC_LANE_CLK, ATC_LANE_CLK_REQ(lane), 0); + port_update(phy + ATC_LANE_CLK, ATC_LANE_CLK_EN(lane), 0); + } + for (int lane = 0; lane < 2; lane++) { + void __iomem *ctrl = phy + ATC_LANE_CTRL(lane); + + port_update(ctrl, ATC_LANE_PMA_EN, 0); + port_update(ctrl, 0, ATC_LANE_PMA_CLAMP); + port_update(ctrl, ATC_LANE_PMA_RST_N, 0); + port_update(ctrl, ATC_LANE_PMA_PWR, 0); + } + } + port_update(phy + ATC_CIO_CTRL, ATC_CIO_CTRL_READY, 0); + port_update(phy + ATC_CIO_CTRL, ATC_CIO_CTRL_BUS, 0); + port_update(phy + ATC_CIO_CTRL, 0, ATC_CIO_CTRL_ISO); + port_update(phy + ATC_CIO_CTRL, ATC_CIO_CTRL_PLL, 0); + ret = readl_poll_timeout(phy + ATC_CIO_STATUS, val, + !(val & ATC_CIO_CTRL_PLL), 1, ATC_TIMEOUT_US); + if (ret) + return ret; + port_update(phy + ATC_CIO_CTRL, ATC_CIO_CTRL_SB, 0); + ret = readl_poll_timeout(phy + ATC_CIO_STATUS, val, + !(val & ATC_CIO_CTRL_SB), 1, ATC_TIMEOUT_US); + if (ret) + return ret; + port_update(phy + ATC_CIO_CLK, ATC_CIO_CLK_EN, 0); + if (readl(phy + ATC_CIO_CTRL) != ATC_CIO_CTRL_IDLE) + return -EIO; + /* Retraining from a powered common block asserts in the router firmware. */ + return port_psd_set(port, PSD_COLD); +} + +static int port_phy_on(struct apple_t8152_port *port, bool reversed) +{ + void __iomem *phy = port->phy; + u32 val; + int ret; + + ret = port_ps_on(port, PS_USB_AON); + if (!ret) + ret = port_psd_set(port, PSD_ON); + if (!ret) + ret = port_ps_on(port, PS_DP0); + if (!ret) + ret = port_ps_on(port, PS_DP1); + if (ret) + return ret; + /* Anything else means the display driver or a USB3 link owns it. */ + if (readl(phy + ATC_CIO_CTRL) != ATC_CIO_CTRL_IDLE) + return -EBUSY; + port->phy_owned = true; + port_update(phy + ATC_CIO_CLK, 0, ATC_CIO_CLK_EN); + port_update(phy + ATC_CIO_CTRL, 0, ATC_CIO_CTRL_SB); + ret = readl_poll_timeout(phy + ATC_CIO_STATUS, val, val & ATC_CIO_CTRL_SB, + 1, ATC_TIMEOUT_US); + if (ret) + return ret; + port_update(phy + ATC_CIO_CTRL, 0, ATC_CIO_CTRL_PLL); + ret = readl_poll_timeout(phy + ATC_CIO_STATUS, val, val & ATC_CIO_CTRL_PLL, + 1, ATC_TIMEOUT_US); + if (ret) + return ret; + port_update(phy + ATC_CIO_CTRL, ATC_CIO_CTRL_ISO, 0); + port_update(phy + ATC_CIO_CTRL, 0, ATC_CIO_CTRL_BUS); + port_apply_tunable(phy, port->tunable_pre); + for (int lane = 0; lane < 2; lane++) { + void __iomem *ctrl = phy + ATC_LANE_CTRL(lane); + + port_update(phy + ATC_LANE_CLK, 0, ATC_LANE_CLK_REQ(lane)); + port_update(phy + ATC_LANE_CLK, 0, ATC_LANE_CLK_EN(lane)); + port_update(ctrl, 0, ATC_LANE_PMA_PWR); + port_update(ctrl, 0, ATC_LANE_PMA_RST_N); + port_update(ctrl, ATC_LANE_PMA_CLAMP, 0); + port_update(ctrl, 0, ATC_LANE_PMA_EN); + } + port_update(phy + ATC_XBAR_CFG, ATC_XBAR_CIO_MASK, reversed ? 1 : 0); + port_apply_tunable(phy, port->tunable_post); + port_update(phy + ATC_CIO_SWAP, ATC_CIO_SWAP_FLIP, + reversed ? ATC_CIO_SWAP_FLIP : 0); + port_update(phy + ATC_CIO_CTRL, 0, ATC_CIO_CTRL_READY); + dev_dbg(port->dev, "PHY in CIO mode: ctrl %#x xbar %#x lanes %#x %#x\n", + readl(phy + ATC_CIO_CTRL), readl(phy + ATC_XBAR_CFG), + readl(phy + ATC_LANE_CTRL(0)), readl(phy + ATC_LANE_CTRL(1))); + return 0; +} + +static int ace3_select(struct spmi_device *pd, u8 reg) +{ + u8 sel; + int ret = spmi_register_zero_write(pd, reg); + + if (ret) + return ret; + for (int i = 0; i < 100; i++) { + ret = spmi_ext_register_read(pd, ACE3_SELECT, &sel, 1); + if (ret) + return ret; + if (sel == reg) + return 0; + usleep_range(1000, 2000); + } + return -ETIMEDOUT; +} + +static int ace3_read(struct spmi_device *pd, u8 reg, u8 *buf, size_t len) +{ + int ret = ace3_select(pd, reg); + + return ret ?: spmi_ext_register_read(pd, ACE3_DATA, buf, len); +} + +static int ace3_write(struct spmi_device *pd, u8 reg, u8 *buf, size_t len) +{ + int ret = ace3_select(pd, reg); + + return ret ?: spmi_ext_register_write(pd, ACE3_DATA, buf, len); +} + +/* A sleeping controller only detects a cable after SSPS 0. */ +static int port_pd_wake(struct apple_t8152_port *port) +{ + u8 buf[4] = {}, cmd[4] = "SSPS"; + int ret; + + ret = ace3_read(port->pd, ACE3_POWER_STATE, buf, 1); + if (ret || !buf[0]) + return ret; + dev_dbg(port->dev, "waking PD power state %#x\n", buf[0]); + buf[0] = 0; + ret = ace3_write(port->pd, ACE3_DATA1, buf, 1); + if (!ret) + ret = ace3_write(port->pd, ACE3_CMD1, cmd, 4); + if (ret) + return ret; + for (int i = 0; i < 1000; i++) { + ret = ace3_read(port->pd, ACE3_CMD1, buf, 4); + if (ret) + return ret; + if (!get_unaligned_le32(buf)) + return 0; + if (!memcmp(buf, "!CMD", 4)) + return -EIO; + usleep_range(2000, 3000); + } + return -ETIMEDOUT; +} + +/* Remove tunnelled devices and DMA users before resetting the PHY. */ +static int port_stop(struct apple_t8152_port *port) +{ + struct typec_thunderbolt_switch_data off = { + .state = TYPEC_THUNDERBOLT_SWITCH_OFF, + }; + int ret; + + lockdep_assert_held(&port->lock); + if (port->active) { + ret = typec_thunderbolt_switch_set(port->sw, &off); + if (ret) + return ret; + port->active = false; + port->disconnects++; + } + if (port->phy_owned) { + ret = port_phy_off(port); + if (ret) + return ret; + port->phy_owned = false; + dev_info(port->dev, "router stopped, PHY reset for the next cable\n"); + } + return 0; +} + +static int port_start(struct apple_t8152_port *port, + const struct typec_thunderbolt_switch_data *data) +{ + int ret; + + lockdep_assert_held(&port->lock); + if (port->phy_owned) { + ret = port_stop(port); + if (ret) + return ret; + } + ret = port_phy_on(port, data->orientation == TYPEC_ORIENTATION_REVERSE); + if (!ret) + ret = typec_thunderbolt_switch_set(port->sw, data); + if (ret) { + /* The switch unwinds a failed start before it returns. */ + if (port->phy_owned) { + int err = port_phy_off(port); + + if (err) + dev_err(port->dev, "PHY cleanup failed: %d\n", err); + else + port->phy_owned = false; + } + return ret; + } + port->cable = *data; + port->active = true; + port->healthy_since = jiffies; + port->connections++; + dev_info(port->dev, "USB4 cable: EUDO %#x, flipped %d, connection %u\n", + data->usb4.eudo, data->orientation == TYPEC_ORIENTATION_REVERSE, + port->connections); + return 0; +} + +static void port_poll(struct work_struct *work) +{ + struct apple_t8152_port *port = + container_of(to_delayed_work(work), struct apple_t8152_port, work); + struct typec_thunderbolt_switch_data data = { + .state = TYPEC_THUNDERBOLT_SWITCH_USB4, + }; + unsigned int delay = POLL_MS; + u32 status, ds; + u8 buf[12]; + int ret; + + mutex_lock(&port->lock); + if (READ_ONCE(port->stopping) || !port->enabled) + goto unlock; + /* One register selector, shared with apple_dcpib's DP alt mode. */ + device_lock(&port->pd->dev); + ret = ace3_read(port->pd, ACE3_STATUS, buf, 5); + if (ret) + goto error; + status = get_unaligned_le32(buf); + ret = ace3_read(port->pd, ACE3_DATA_STATUS, buf, 5); + if (ret) + goto error; + ds = get_unaligned_le32(buf); + port->status = status; + port->data_status = ds; + + /* Never take the port from an upstream host (the debug USB link). */ + if (ds & ACE3_DS_UPSTREAM) { + ret = port_stop(port); + if (ret) + goto error; + port->retries = 0; + goto again; + } + if (!(status & ACE3_STATUS_PLUG) || !(ds & ACE3_DS_USB4)) { + ret = port_stop(port); + if (ret) + goto error; + port->retries = 0; + ret = port_pd_wake(port); + if (ret) + goto error; + goto again; + } + + ret = ace3_read(port->pd, ACE3_USB4_STATUS, buf, 9); + if (ret) + goto error; + data.orientation = status & ACE3_STATUS_FLIP ? + TYPEC_ORIENTATION_REVERSE : TYPEC_ORIENTATION_NORMAL; + data.usb4.eudo = get_unaligned_le32(buf + 1); + data.usb4.active_link_training = !!(ds & ACE3_DS_USB4_TRAINING); + if (port->active) { + if (data.orientation != port->cable.orientation || + data.usb4.eudo != port->cable.usb4.eudo || + data.usb4.active_link_training != + port->cable.usb4.active_link_training) { + ret = port_stop(port); + if (ret) + goto error; + goto again; /* read a fresh snapshot after teardown */ + } + /* Revalidation catches a disconnect shorter than a poll. */ + ret = typec_thunderbolt_switch_set(port->sw, &data); + if (ret == -EAGAIN) + goto again; + if (!ret) { + if (time_after(jiffies, port->healthy_since + 10 * HZ)) + port->retries = 0; + goto again; + } + dev_warn(port->dev, "connection lost (%d), restarting\n", ret); + port->retries++; + ret = port_stop(port); + if (ret) + goto error; + delay = RETRY_MS; + goto again; + } + if (port->retries >= MAX_RETRIES) + goto queue; + ret = port_start(port, &data); + if (ret) { + port->retries++; + goto error; + } +again: + port->last_error = 0; + goto queue; +error: + if (ret != port->last_error) + dev_warn(port->dev, "port transition failed: %d (attempt %u)\n", + ret, port->retries); + port->last_error = ret; + delay = RETRY_MS; +queue: + device_unlock(&port->pd->dev); + if (!READ_ONCE(port->stopping) && port->enabled) + queue_delayed_work(apple_t8152_port_wq, &port->work, + msecs_to_jiffies(delay)); +unlock: + mutex_unlock(&port->lock); +} + +static int port_switch_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct apple_t8152_port *port = + container_of(nb, struct apple_t8152_port, switch_nb); + + /* Called with router locks held: only ask for a fresh poll. */ + if (!READ_ONCE(port->stopping) && READ_ONCE(port->enabled)) + mod_delayed_work(apple_t8152_port_wq, &port->work, 0); + return NOTIFY_OK; +} + +static void port_shutdown(struct apple_t8152_port *port) +{ + WRITE_ONCE(port->stopping, true); + cancel_delayed_work_sync(&port->work); + mutex_lock(&port->lock); + if (port_stop(port)) + dev_err(port->dev, "port shutdown failed\n"); + mutex_unlock(&port->lock); +} + +/* Stop the router before device_shutdown() gates the PCIe and DART devices. */ +static int port_reboot_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + port_shutdown(container_of(nb, struct apple_t8152_port, reboot_nb)); + return NOTIFY_DONE; +} + +static ssize_t enabled_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct apple_t8152_port *port = dev_get_drvdata(dev); + + return sysfs_emit(buf, "%u\n", READ_ONCE(port->enabled)); +} + +static ssize_t enabled_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct apple_t8152_port *port = dev_get_drvdata(dev); + bool enabled; + int ret = kstrtobool(buf, &enabled); + + if (ret) + return ret; + mutex_lock(&port->lock); + if (READ_ONCE(port->stopping)) { + mutex_unlock(&port->lock); + return -ESHUTDOWN; + } + port->enabled = enabled; + port->retries = 0; + if (!enabled) + ret = port_stop(port); + else + mod_delayed_work(apple_t8152_port_wq, &port->work, 0); + mutex_unlock(&port->lock); + return ret ?: count; +} +static DEVICE_ATTR_RW(enabled); + +static ssize_t state_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct apple_t8152_port *port = dev_get_drvdata(dev); + ssize_t n; + + mutex_lock(&port->lock); + n = sysfs_emit(buf, + "active=%u phy=%u status=%#x data=%#x connects=%u disconnects=%u retries=%u error=%d\n", + port->active, port->phy_owned, port->status, + port->data_status, port->connections, port->disconnects, + port->retries, port->last_error); + mutex_unlock(&port->lock); + return n; +} +static DEVICE_ATTR_RO(state); + +static struct attribute *apple_t8152_port_attrs[] = { + &dev_attr_enabled.attr, + &dev_attr_state.attr, + NULL, +}; +ATTRIBUTE_GROUPS(apple_t8152_port); + +static void __iomem *port_map(struct platform_device *pdev, const char *name, + struct resource **res) +{ + void __iomem *base; + + *res = platform_get_resource_byname(pdev, IORESOURCE_MEM, name); + if (!*res) + return IOMEM_ERR_PTR(-EINVAL); + /* Shared with apple_dcpib: map without claiming. */ + base = devm_ioremap(&pdev->dev, (*res)->start, resource_size(*res)); + return base ?: IOMEM_ERR_PTR(-ENOMEM); +} + +static void port_put_pd(void *data) +{ + put_device(data); +} + +static void port_put_switch(void *data) +{ + typec_thunderbolt_switch_put(data); +} + +static int apple_t8152_port_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct apple_t8152_port *port; + struct device_node *pd_np; + struct resource *phy_res, *res; + const char *label = dev_name(dev); + int ret; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + return -ENOMEM; + port->dev = dev; + mutex_init(&port->lock); + INIT_DELAYED_WORK(&port->work, port_poll); + platform_set_drvdata(pdev, port); + + port->phy = port_map(pdev, "phy", &phy_res); + if (IS_ERR(port->phy)) + return PTR_ERR(port->phy); + port->ps = port_map(pdev, "ps", &res); + if (IS_ERR(port->ps)) + return PTR_ERR(port->ps); + if (resource_size(res) < PS_USB_AON + 4) + return -EINVAL; + port->psd = port_map(pdev, "psd", &res); + if (IS_ERR(port->psd)) + return PTR_ERR(port->psd); + if (resource_size(res) < PSD_ACK + 4) + return -EINVAL; + port->tunable_pre = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-phy-pre", phy_res); + if (IS_ERR(port->tunable_pre)) + return dev_err_probe(dev, PTR_ERR(port->tunable_pre), + "invalid apple,tunable-phy-pre\n"); + port->tunable_post = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-phy-post", phy_res); + if (IS_ERR(port->tunable_post)) + return dev_err_probe(dev, PTR_ERR(port->tunable_post), + "invalid apple,tunable-phy-post\n"); + + pd_np = of_parse_phandle(dev->of_node, "apple,usb-pd", 0); + if (!pd_np) + return dev_err_probe(dev, -EINVAL, "no apple,usb-pd\n"); + port->pd = spmi_find_device_by_of_node(pd_np); + of_node_put(pd_np); + if (!port->pd) + return -EPROBE_DEFER; + ret = devm_add_action_or_reset(dev, port_put_pd, &port->pd->dev); + if (ret) + return ret; + /* A Type-C driver bound to the controller would own the port. */ + if (device_is_bound(&port->pd->dev)) + return dev_err_probe(dev, -EBUSY, "PD controller has a driver\n"); + + port->sw = typec_thunderbolt_switch_get(dev); + if (IS_ERR(port->sw)) + return dev_err_probe(dev, PTR_ERR(port->sw), "no USB4 switch\n"); + if (!port->sw) + return dev_err_probe(dev, -ENODEV, "no USB4 switch connection\n"); + ret = devm_add_action_or_reset(dev, port_put_switch, port->sw); + if (ret) + return ret; + + ret = spmi_command_wakeup(port->pd); + if (ret) + return ret; + usleep_range(10000, 11000); + + port->switch_nb.notifier_call = port_switch_notify; + ret = typec_thunderbolt_switch_register_notifier(port->sw, &port->switch_nb); + if (ret) + return ret; + port->reboot_nb.notifier_call = port_reboot_notify; + ret = register_reboot_notifier(&port->reboot_nb); + if (ret) { + typec_thunderbolt_switch_unregister_notifier(port->sw, &port->switch_nb); + return ret; + } + port->enabled = true; + queue_delayed_work(apple_t8152_port_wq, &port->work, 0); + of_property_read_string(dev->of_node, "label", &label); + dev_info(dev, "watching %s for USB4 cables\n", label); + return 0; +} + +static void apple_t8152_port_remove(struct platform_device *pdev) +{ + struct apple_t8152_port *port = platform_get_drvdata(pdev); + + unregister_reboot_notifier(&port->reboot_nb); + typec_thunderbolt_switch_unregister_notifier(port->sw, &port->switch_nb); + port_shutdown(port); +} + +static const struct of_device_id apple_t8152_port_of_match[] = { + { .compatible = "apple,t8152-usb4-port" }, + {} +}; +MODULE_DEVICE_TABLE(of, apple_t8152_port_of_match); + +static struct platform_driver apple_t8152_port_driver = { + .probe = apple_t8152_port_probe, + .remove = apple_t8152_port_remove, + .driver = { + .name = "apple-t8152-usb4-port", + .of_match_table = apple_t8152_port_of_match, + .dev_groups = apple_t8152_port_groups, + .suppress_bind_attrs = true, + }, +}; + +static int __init apple_t8152_port_init(void) +{ + int ret; + + /* Freezable: no PHY or router transitions across system sleep. */ + apple_t8152_port_wq = alloc_ordered_workqueue("apple-t8152-usb4", WQ_FREEZABLE); + if (!apple_t8152_port_wq) + return -ENOMEM; + ret = platform_driver_register(&apple_t8152_port_driver); + if (ret) + destroy_workqueue(apple_t8152_port_wq); + return ret; +} +module_init(apple_t8152_port_init); + +static void __exit apple_t8152_port_exit(void) +{ + platform_driver_unregister(&apple_t8152_port_driver); + destroy_workqueue(apple_t8152_port_wq); +} +module_exit(apple_t8152_port_exit); + +MODULE_DESCRIPTION("Apple T8152 rear USB-C ports in USB4 mode"); +MODULE_LICENSE("Dual MIT/GPL"); From fdedff060667ffb026fb1f2e0923f37d78db8d91 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 111/112] arm64: dts: apple: j873: enable the rear USB4 ports Describe the three rear USB4 routers (ADT acio0, acio1, acio3) with their mailboxes, NHI, ACIO DARTs, PCIe-C tunnels and their DARTs, the CIO reset block, the PSD services they need, the LSTX pins, and one port monitor per rear USB-C port. Generated from the J873g ADT, including the router, NHI, DART and PCIe-C tunables and the router DROMs, whose UID field is the port index. The ATC PHY tunables are the atc-phyN groups, at the PHY register blocks they apply to. Each router coprocessor's mailbox has apple,t8152-smc-mailbox as its fallback and the two interrupts of the ADT's acio-cpuN node, which list send-empty first, as the SMC mailbox's do. Signed-off-by: Thomas Glanzmann --- .../arm64/boot/dts/apple/t8152-j873-usb4.dtsi | 1961 +++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 1962 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi new file mode 100644 index 0000000000000..6e14c1efe9e41 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi @@ -0,0 +1,1961 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g rear USB-C ports in USB4 mode: three ACIO host routers with their + * NHI, PCIe-C tunnel and DARTs, the T8152 PSD services they need, and the + * port monitors that bring the ATC PHYs up for a USB4 cable. + * + * Generated from the J873g ADT (27.2 iBoot): /arm-io/acio{0,1,3}, acio-cpuN, + * dart-acioN, apciecN, dart-apciecN and atc-phyN. ATC PHY tunable groups are + * placed at the PHY register blocks they apply to for each port. + * + * Each router coprocessor's mailbox is the 0x80 window at +0x80 of its + * acio-cpuN register block, with the SMC mailbox's counted FIFOs. Its + * interrupts are acio-cpuN's two, in the order the SMC mailbox's ADT list + * gives its own: send-empty, recv-not-empty. + */ + +#include + +/ { + soc { + cio_reset: reset-controller@300780000 { + compatible = "apple,t8152-cio-reset"; + reg = <0x3 0x00780000 0x0 0x4000>; + #reset-cells = <1>; + }; + + cio_psd59: power-controller@303a13b00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13b00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd60: power-controller@303a13c00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13c00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd62: power-controller@303a13e00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13e00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd63: power-controller@303a13f00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13f00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd64: power-controller@303a14000 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14000 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd66: power-controller@303a14200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14200 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd67: power-controller@303a14300 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14300 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd68: power-controller@303a14400 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14400 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd70: power-controller@303a14600 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14600 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd86: power-controller@303a15600 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15600 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd87: power-controller@303a15700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15700 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd89: power-controller@303a15900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15900 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio0_mbox: mailbox@401178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x1178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_0: acio@401ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x1ac0000 0x0 0xc000>, + <0x4 0x1080000 0x0 0x26000>, + <0x4 0x1e44000 0x0 0x4000>, + <0x4 0x1c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x1000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio0_mbox>; + resets = <&cio_reset 0>; + power-domains = <&cio_psd59>, <&cio_psd63>, <&cio_psd67>, <&cio_psd86>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_0_lstx_pins>; + lstx-gpios = <&pinctrl_aop 19 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_0_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_0_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000100 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_0_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_0_dart 0>, <&usb4_0_dart 1>, <&usb4_0_dart 2>, + <&usb4_0_dart 3>, <&usb4_0_dart 4>, <&usb4_0_dart 5>, + <&usb4_0_dart 6>, <&usb4_0_dart 7>, <&usb4_0_dart 8>, + <&usb4_0_dart 9>, <&usb4_0_dart 10>, <&usb4_0_dart 11>, + <&usb4_0_dart 16>, <&usb4_0_dart 17>, <&usb4_0_dart 18>, + <&usb4_0_dart 19>, <&usb4_0_dart 20>, <&usb4_0_dart 21>, + <&usb4_0_dart 22>, <&usb4_0_dart 23>, <&usb4_0_dart 24>, + <&usb4_0_dart 25>, <&usb4_0_dart 26>, <&usb4_0_dart 27>; + apple,thunderbolt-drom = + [db 00 00 00 00 00 00 00 00 5d 2d 12 e9 01 42 00 + 01 00 0f 00 01 00 08 81 80 02 80 00 00 00 08 82 + 90 01 80 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 05 88 09 01 00 0d 01 41 70 + 70 6c 65 20 49 6e 63 2e 00 06 02 69 4f 53 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_0_sw: endpoint { + remote-endpoint = <&usb4_port0_sw>; + }; + }; + }; + }; + + usb4_port0: usb4-port@403000000 { + compatible = "apple,t8152-usb4-port"; + reg = <0x4 0x3000000 0x0 0x84000>, + <0x3 0x8290000 0x0 0x104>, + <0x3 0x3a13700 0x0 0x100>; + reg-names = "phy", "ps", "psd"; + label = "USB-C Back-middle"; + apple,usb-pd = <&hpm0>; + apple,tunable-phy-pre = + <0x800 0xfc0000 0xfc0000>, + <0x84c 0xff800 0xff800>, + <0x85c 0xff 0x80>, + <0x860 0x7fffff 0x52bca4>, + <0x864 0x2c00000 0x800000>, + <0x1614 0x3ffc0 0x1e5c0>, + <0x1640 0x7 0x3>, + <0x1668 0xffc 0x5f0>; + apple,tunable-phy-post = + <0x6c004 0x3f003f 0x200020>, + <0x6c00c 0xf1 0xa1>, + <0x6c010 0x801f 0x4>, + <0x6c018 0x3f003f 0x200020>, + <0x6c020 0xf1 0xa1>, + <0x6c024 0x801f 0x4>, + <0x6c02c 0x7f007f 0x410041>, + <0x6c034 0xf1 0x71>, + <0x6c038 0x801f 0x4>, + <0x6c040 0x1f 0x10>, + <0x6c048 0x801f 0x4>, + <0x6c050 0x7f007f 0x450045>, + <0x6c058 0xf1 0x51>, + <0x6c05c 0x801f 0x4>, + <0x6c064 0x3f 0x20>, + <0x6c06c 0x801f 0x4>, + <0x6c074 0x1 0x1>, + <0x6c078 0x801f 0x4>, + <0x6c080 0x1f001f 0x100010>, + <0x6c084 0xf1 0x11>, + <0x6c088 0x1 0x1>, + <0x6c08c 0x1 0x1>, + <0x6c090 0x801f 0x4>, + <0x6c098 0x1f001f 0x100010>, + <0x6c09c 0xf1 0x11>, + <0x6c0a0 0x801f 0x4>, + <0x6c0a8 0xff 0xa0>, + <0x6c0ac 0x801f 0x4>, + <0x6c0b4 0x3f 0x20>, + <0x6c0bc 0x801f 0x4>, + <0x6c0c4 0x3f 0x20>, + <0x6c0cc 0x801f 0x4>, + <0x6c0d4 0xf 0x8>, + <0x6c0d8 0x801f 0x4>, + <0x6c0e0 0x1f001f 0x180018>, + <0x6c0e4 0x801f 0x4>, + <0x6c0ec 0x1f001f 0x180018>, + <0x6c0f0 0x801f 0x4>, + <0x6c0f8 0x1f001f 0x180018>, + <0x6c0fc 0x801f 0x4>, + <0x6c104 0x1f001f 0x180018>, + <0x6c108 0x801f 0x4>, + <0x6c110 0x1 0x1>, + <0x6c114 0x801f 0x4>, + <0x6c11c 0x801f 0x4>, + <0x6c124 0x801f 0x4>, + <0x6c12c 0x801f 0x4>, + <0x6c134 0x801f 0x4>, + <0x6c13c 0xffffffff 0x1010101>, + <0x6c140 0x801f 0x4>, + <0x6c148 0x801f 0x4>, + <0x6c150 0xffffffff 0x1010101>, + <0x6c154 0xffff 0x101>, + <0x6c158 0x801f 0x4>, + <0x6c160 0x801f 0x4>, + <0x6c168 0x801f 0x4>, + <0x6c170 0x801f 0x4>, + <0x6c178 0x801f 0x4>, + <0x6c180 0xffffffff 0x1010101>, + <0x6c184 0x801f 0x4>, + <0x6c18c 0x801f 0x4>, + <0x6c194 0x801f 0x4>, + <0x1040 0xc 0x8>, + <0x1060 0x1c000 0xc000>, + <0x1098 0xf00 0x800>, + <0x109c 0xfe000 0xfe000>, + <0x1108 0x7c00000 0x4000000>, + <0x110c 0x7c 0x10>, + <0xe8c 0x7f 0x3c>, + <0xe9c 0x7f 0x32>, + <0xeac 0x7f 0x32>, + <0xebc 0x7f 0x5a>, + <0x1488 0x1ff 0x128>, + <0x1494 0x100 0x100>, + <0x1a44 0x40f 0x40f>, + <0x1a48 0x40f 0x40f>, + <0x82d8 0xf0000000 0x70000000>, + <0x82dc 0xf 0x7>, + <0x8cf4 0x20 0x20>, + <0x77c4 0x3ff00 0xfa00>, + <0x7dbc 0x78 0x30>, + <0x7dd8 0x3f0 0x0>, + <0x7de8 0x3 0x3>, + <0x7dec 0x2 0x2>, + <0x7a00 0xf0 0x10>, + <0x7a08 0xfff 0x1>, + <0x7a28 0xff00000 0xcf00000>, + <0x7a40 0x7ffffff 0x28154a5>, + <0x7a7c 0x20000000 0x0>, + <0x7a80 0x1f 0x2>, + <0x7b98 0x3f00003f 0x31000014>, + <0x7b9c 0x3ffff 0xef4b>, + <0x7ba8 0xfc1f800 0x5005000>, + <0x7bac 0x7ffffe0 0x13f0e40>, + <0x7bbc 0x1c7 0x145>, + <0x7bc8 0x7f8 0x18>, + <0x8728 0x10f 0x10f>, + <0x878c 0xfc000000 0xfc000000>, + <0x8790 0x1 0x1>, + <0x87b4 0xe018000 0x6008000>, + <0x8708 0x40000000 0x40000000>, + <0x4c80 0x3f800000 0x0>, + <0x4c88 0x1fffff 0x0>, + <0x4fd4 0x3800000 0x2800000>, + <0x4e20 0xfff000 0x723000>, + <0x8980 0xfff000 0x723000>, + <0x85e4 0x4 0x0>, + <0x8628 0xff0 0x660>, + <0x862c 0xff0 0xea0>, + <0x8000 0xa 0x0>, + <0x8014 0x3ff 0x42>, + <0x7304 0xf 0x6>, + <0x7334 0x1ffffff 0x1004ea>, + <0x7284 0xf 0x6>, + <0x72cc 0x3ffff 0x4ea>, + <0x4d84 0x1c0000 0x0>, + <0x7f80 0xffffffff 0x148>, + <0x7f90 0x3ff00 0x2f700>, + <0x7fd0 0x100 0x0>, + <0x7d88 0xff 0x41>, + <0x7da8 0xffff0000 0x22110000>, + <0x7dac 0xff 0x44>, + <0x7dd8 0xc000 0x0>, + <0x7ddc 0x3 0x0>, + <0x7a1c 0xff8 0x528>, + <0x7a2c 0x3ffff 0x140aa>, + <0x7a30 0x1e00 0x1000>, + <0x7a34 0xff0000 0xa0000>, + <0x7b84 0xff 0x28>, + <0x7b88 0xf00f 0x7008>, + <0x7b8c 0xf00f 0x6007>, + <0x7b90 0xf00f 0x4005>, + <0x7bb4 0x703f 0x502d>, + <0x7bb8 0x703f 0x2013>, + <0x7bbc 0xe00 0x600>, + <0x8af4 0x1fe0000 0x1540000>, + <0x8af8 0x3fc000 0x2a8000>, + <0x4e94 0x1fe0000 0x1540000>, + <0x4e98 0x3fc000 0x2a8000>, + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0xf 0x7>, + <0x11cf4 0x20 0x20>, + <0x107c4 0x3ff00 0xfa00>, + <0x10dbc 0x78 0x30>, + <0x10dd8 0x3f0 0x0>, + <0x10de8 0x3 0x3>, + <0x10dec 0x2 0x2>, + <0x10a00 0xf0 0x10>, + <0x10a08 0xfff 0x1>, + <0x10a28 0xff00000 0xcf00000>, + <0x10a40 0x7ffffff 0x28154a5>, + <0x10a7c 0x20000000 0x0>, + <0x10a80 0x1f 0x2>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x3ffff 0xef4b>, + <0x10ba8 0xfc1f800 0x5005000>, + <0x10bac 0x7ffffe0 0x13f0e40>, + <0x10bbc 0x1c7 0x145>, + <0x10bc8 0x7f8 0x18>, + <0x11728 0x10f 0x10f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x1 0x1>, + <0x117b4 0xe018000 0x6008000>, + <0x11708 0x40000000 0x40000000>, + <0xdc80 0x3f800000 0x0>, + <0xdc88 0x1fffff 0x0>, + <0xdfd4 0x3800000 0x2800000>, + <0xde20 0xfff000 0x723000>, + <0x11980 0xfff000 0x723000>, + <0x115e4 0x4 0x0>, + <0x11628 0xff0 0x660>, + <0x1162c 0xff0 0xea0>, + <0x11000 0xa 0x0>, + <0x11014 0x3ff 0x42>, + <0x10304 0xf 0x6>, + <0x10334 0x1ffffff 0x1004ea>, + <0x10284 0xf 0x6>, + <0x102cc 0x3ffff 0x4ea>, + <0xdd84 0x1c0000 0x0>, + <0x10f80 0xffffffff 0x148>, + <0x10f90 0x3ff00 0x2f700>, + <0x10fd0 0x100 0x0>, + <0x10d88 0xff 0x41>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0xff 0x44>, + <0x10dd8 0xc000 0x0>, + <0x10ddc 0x3 0x0>, + <0x10a1c 0xff8 0x528>, + <0x10a2c 0x3ffff 0x140aa>, + <0x10a30 0x1e00 0x1000>, + <0x10a34 0xff0000 0xa0000>, + <0x10b84 0xff 0x28>, + <0x10b88 0xf00f 0x7008>, + <0x10b8c 0xf00f 0x6007>, + <0x10b90 0xf00f 0x4005>, + <0x10bb4 0x703f 0x502d>, + <0x10bb8 0x703f 0x2013>, + <0x10bbc 0xe00 0x600>, + <0x11af4 0x1fe0000 0x1540000>, + <0x11af8 0x3fc000 0x2a8000>, + <0xde94 0x1fe0000 0x1540000>, + <0xde98 0x3fc000 0x2a8000>; + + port { + usb4_port0_sw: endpoint { + remote-endpoint = <&usb4_0_sw>; + }; + }; + }; + + cio1_mbox: mailbox@409178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x9178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_1: acio@409ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x9ac0000 0x0 0xc000>, + <0x4 0x9080000 0x0 0x26000>, + <0x4 0x9e44000 0x0 0x4000>, + <0x4 0x9c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x9000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio1_mbox>; + resets = <&cio_reset 1>; + power-domains = <&cio_psd60>, <&cio_psd64>, <&cio_psd68>, <&cio_psd87>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_1_lstx_pins>; + lstx-gpios = <&pinctrl_aop 21 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_1_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_1_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000180 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_1_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_1_dart 0>, <&usb4_1_dart 1>, <&usb4_1_dart 2>, + <&usb4_1_dart 3>, <&usb4_1_dart 4>, <&usb4_1_dart 5>, + <&usb4_1_dart 6>, <&usb4_1_dart 7>, <&usb4_1_dart 8>, + <&usb4_1_dart 9>, <&usb4_1_dart 10>, <&usb4_1_dart 11>, + <&usb4_1_dart 16>, <&usb4_1_dart 17>, <&usb4_1_dart 18>, + <&usb4_1_dart 19>, <&usb4_1_dart 20>, <&usb4_1_dart 21>, + <&usb4_1_dart 22>, <&usb4_1_dart 23>, <&usb4_1_dart 24>, + <&usb4_1_dart 25>, <&usb4_1_dart 26>, <&usb4_1_dart 27>; + apple,thunderbolt-drom = + [c8 01 00 00 00 00 00 00 00 06 7e 74 db 01 42 00 + 01 00 0f 00 01 00 08 81 81 02 81 00 00 00 08 82 + 91 01 81 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 05 88 09 01 00 0d 01 41 70 + 70 6c 65 20 49 6e 63 2e 00 06 02 69 4f 53 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_1_sw: endpoint { + remote-endpoint = <&usb4_port1_sw>; + }; + }; + }; + }; + + usb4_port1: usb4-port@40b000000 { + compatible = "apple,t8152-usb4-port"; + reg = <0x4 0xb000000 0x0 0x84000>, + <0x3 0x8290040 0x0 0x104>, + <0x3 0x3a13800 0x0 0x100>; + reg-names = "phy", "ps", "psd"; + label = "USB-C Back-left"; + apple,usb-pd = <&hpm1>; + apple,tunable-phy-pre = + <0x800 0xfc0000 0xfc0000>, + <0x84c 0xff800 0xff800>, + <0x85c 0xff 0x80>, + <0x860 0x7fffff 0x52bc26>, + <0x864 0x2c00000 0x800000>, + <0x1614 0x3ffc0 0x1e5c0>, + <0x1640 0x7 0x3>, + <0x1668 0xffc 0x5f0>; + apple,tunable-phy-post = + <0x6c004 0x3f003f 0x200020>, + <0x6c00c 0xf1 0xa1>, + <0x6c010 0x801f 0x4>, + <0x6c018 0x3f003f 0x200020>, + <0x6c020 0xf1 0xa1>, + <0x6c024 0x801f 0x4>, + <0x6c02c 0x7f007f 0x410041>, + <0x6c034 0xf1 0x71>, + <0x6c038 0x801f 0x4>, + <0x6c040 0x1f 0x10>, + <0x6c048 0x801f 0x4>, + <0x6c050 0x7f007f 0x450045>, + <0x6c058 0xf1 0x51>, + <0x6c05c 0x801f 0x4>, + <0x6c064 0x3f 0x20>, + <0x6c06c 0x801f 0x4>, + <0x6c074 0x1 0x1>, + <0x6c078 0x801f 0x4>, + <0x6c080 0x1f001f 0x100010>, + <0x6c084 0xf1 0x11>, + <0x6c088 0x1 0x1>, + <0x6c08c 0x1 0x1>, + <0x6c090 0x801f 0x4>, + <0x6c098 0x1f001f 0x100010>, + <0x6c09c 0xf1 0x11>, + <0x6c0a0 0x801f 0x4>, + <0x6c0a8 0xff 0xa0>, + <0x6c0ac 0x801f 0x4>, + <0x6c0b4 0x3f 0x20>, + <0x6c0bc 0x801f 0x4>, + <0x6c0c4 0x3f 0x20>, + <0x6c0cc 0x801f 0x4>, + <0x6c0d4 0xf 0x8>, + <0x6c0d8 0x801f 0x4>, + <0x6c0e0 0x1f001f 0x180018>, + <0x6c0e4 0x801f 0x4>, + <0x6c0ec 0x1f001f 0x180018>, + <0x6c0f0 0x801f 0x4>, + <0x6c0f8 0x1f001f 0x180018>, + <0x6c0fc 0x801f 0x4>, + <0x6c104 0x1f001f 0x180018>, + <0x6c108 0x801f 0x4>, + <0x6c110 0x1 0x1>, + <0x6c114 0x801f 0x4>, + <0x6c11c 0x801f 0x4>, + <0x6c124 0x801f 0x4>, + <0x6c12c 0x801f 0x4>, + <0x6c134 0x801f 0x4>, + <0x6c13c 0xffffffff 0x1010101>, + <0x6c140 0x801f 0x4>, + <0x6c148 0x801f 0x4>, + <0x6c150 0xffffffff 0x1010101>, + <0x6c154 0xffff 0x101>, + <0x6c158 0x801f 0x4>, + <0x6c160 0x801f 0x4>, + <0x6c168 0x801f 0x4>, + <0x6c170 0x801f 0x4>, + <0x6c178 0x801f 0x4>, + <0x6c180 0xffffffff 0x1010101>, + <0x6c184 0x801f 0x4>, + <0x6c18c 0x801f 0x4>, + <0x6c194 0x801f 0x4>, + <0x1040 0xc 0x8>, + <0x1060 0x1c000 0xc000>, + <0x1098 0xf00 0x800>, + <0x109c 0xfe000 0xfe000>, + <0x1108 0x7c00000 0x4000000>, + <0x110c 0x7c 0x10>, + <0xe8c 0x7f 0x3c>, + <0xe9c 0x7f 0x32>, + <0xeac 0x7f 0x32>, + <0xebc 0x7f 0x5a>, + <0x1488 0x1ff 0x128>, + <0x1494 0x100 0x100>, + <0x1a44 0x40f 0x40f>, + <0x1a48 0x40f 0x40f>, + <0x82d8 0xf0000000 0x70000000>, + <0x82dc 0xf 0x7>, + <0x8cf4 0x20 0x20>, + <0x77c4 0x3ff00 0xfa00>, + <0x7dbc 0x78 0x30>, + <0x7dd8 0x3f0 0x0>, + <0x7de8 0x3 0x3>, + <0x7dec 0x2 0x2>, + <0x7a00 0xf0 0x10>, + <0x7a08 0xfff 0x1>, + <0x7a28 0xff00000 0xcf00000>, + <0x7a40 0x7ffffff 0x28154a5>, + <0x7a7c 0x20000000 0x0>, + <0x7a80 0x1f 0x2>, + <0x7b98 0x3f00003f 0x31000014>, + <0x7b9c 0x3ffff 0xef4b>, + <0x7ba8 0xfc1f800 0x5005000>, + <0x7bac 0x7ffffe0 0x13f0e40>, + <0x7bbc 0x1c7 0x145>, + <0x7bc8 0x7f8 0x18>, + <0x8728 0x10f 0x10f>, + <0x878c 0xfc000000 0xfc000000>, + <0x8790 0x1 0x1>, + <0x87b4 0xe018000 0x6008000>, + <0x8708 0x40000000 0x40000000>, + <0x4c80 0x3f800000 0x0>, + <0x4c88 0x1fffff 0x0>, + <0x4fd4 0x3800000 0x2800000>, + <0x4e20 0xfff000 0x723000>, + <0x8980 0xfff000 0x723000>, + <0x85e4 0x4 0x0>, + <0x8628 0xff0 0x660>, + <0x862c 0xff0 0xea0>, + <0x8000 0xa 0x0>, + <0x8014 0x3ff 0x42>, + <0x7304 0xf 0x6>, + <0x7334 0x1ffffff 0x1004ea>, + <0x7284 0xf 0x6>, + <0x72cc 0x3ffff 0x4ea>, + <0x4d84 0x1c0000 0x0>, + <0x7f80 0xffffffff 0x148>, + <0x7f90 0x3ff00 0x2f700>, + <0x7fd0 0x100 0x0>, + <0x7d88 0xff 0x41>, + <0x7da8 0xffff0000 0x22110000>, + <0x7dac 0xff 0x44>, + <0x7dd8 0xc000 0x0>, + <0x7ddc 0x3 0x0>, + <0x7a1c 0xff8 0x528>, + <0x7a2c 0x3ffff 0x140aa>, + <0x7a30 0x1e00 0x1000>, + <0x7a34 0xff0000 0xa0000>, + <0x7b84 0xff 0x28>, + <0x7b88 0xf00f 0x7008>, + <0x7b8c 0xf00f 0x6007>, + <0x7b90 0xf00f 0x4005>, + <0x7bb4 0x703f 0x502d>, + <0x7bb8 0x703f 0x2013>, + <0x7bbc 0xe00 0x600>, + <0x8af4 0x1fe0000 0x1540000>, + <0x8af8 0x3fc000 0x2a8000>, + <0x4e94 0x1fe0000 0x1540000>, + <0x4e98 0x3fc000 0x2a8000>, + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0xf 0x7>, + <0x11cf4 0x20 0x20>, + <0x107c4 0x3ff00 0xfa00>, + <0x10dbc 0x78 0x30>, + <0x10dd8 0x3f0 0x0>, + <0x10de8 0x3 0x3>, + <0x10dec 0x2 0x2>, + <0x10a00 0xf0 0x10>, + <0x10a08 0xfff 0x1>, + <0x10a28 0xff00000 0xcf00000>, + <0x10a40 0x7ffffff 0x28154a5>, + <0x10a7c 0x20000000 0x0>, + <0x10a80 0x1f 0x2>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x3ffff 0xef4b>, + <0x10ba8 0xfc1f800 0x5005000>, + <0x10bac 0x7ffffe0 0x13f0e40>, + <0x10bbc 0x1c7 0x145>, + <0x10bc8 0x7f8 0x18>, + <0x11728 0x10f 0x10f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x1 0x1>, + <0x117b4 0xe018000 0x6008000>, + <0x11708 0x40000000 0x40000000>, + <0xdc80 0x3f800000 0x0>, + <0xdc88 0x1fffff 0x0>, + <0xdfd4 0x3800000 0x2800000>, + <0xde20 0xfff000 0x723000>, + <0x11980 0xfff000 0x723000>, + <0x115e4 0x4 0x0>, + <0x11628 0xff0 0x660>, + <0x1162c 0xff0 0xea0>, + <0x11000 0xa 0x0>, + <0x11014 0x3ff 0x42>, + <0x10304 0xf 0x6>, + <0x10334 0x1ffffff 0x1004ea>, + <0x10284 0xf 0x6>, + <0x102cc 0x3ffff 0x4ea>, + <0xdd84 0x1c0000 0x0>, + <0x10f80 0xffffffff 0x148>, + <0x10f90 0x3ff00 0x2f700>, + <0x10fd0 0x100 0x0>, + <0x10d88 0xff 0x41>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0xff 0x44>, + <0x10dd8 0xc000 0x0>, + <0x10ddc 0x3 0x0>, + <0x10a1c 0xff8 0x528>, + <0x10a2c 0x3ffff 0x140aa>, + <0x10a30 0x1e00 0x1000>, + <0x10a34 0xff0000 0xa0000>, + <0x10b84 0xff 0x28>, + <0x10b88 0xf00f 0x7008>, + <0x10b8c 0xf00f 0x6007>, + <0x10b90 0xf00f 0x4005>, + <0x10bb4 0x703f 0x502d>, + <0x10bb8 0x703f 0x2013>, + <0x10bbc 0xe00 0x600>, + <0x11af4 0x1fe0000 0x1540000>, + <0x11af8 0x3fc000 0x2a8000>, + <0xde94 0x1fe0000 0x1540000>, + <0xde98 0x3fc000 0x2a8000>; + + port { + usb4_port1_sw: endpoint { + remote-endpoint = <&usb4_1_sw>; + }; + }; + }; + + cio3_mbox: mailbox@411178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x11178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_3: acio@411ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x11ac0000 0x0 0xc000>, + <0x4 0x11080000 0x0 0x26000>, + <0x4 0x11e44000 0x0 0x4000>, + <0x4 0x11c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x11000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio3_mbox>; + resets = <&cio_reset 3>; + power-domains = <&cio_psd62>, <&cio_psd66>, <&cio_psd70>, <&cio_psd89>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_3_lstx_pins>; + lstx-gpios = <&pinctrl_aop 25 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_3_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_3_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000280 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_3_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_3_dart 0>, <&usb4_3_dart 1>, <&usb4_3_dart 2>, + <&usb4_3_dart 3>, <&usb4_3_dart 4>, <&usb4_3_dart 5>, + <&usb4_3_dart 6>, <&usb4_3_dart 7>, <&usb4_3_dart 8>, + <&usb4_3_dart 9>, <&usb4_3_dart 10>, <&usb4_3_dart 11>, + <&usb4_3_dart 16>, <&usb4_3_dart 17>, <&usb4_3_dart 18>, + <&usb4_3_dart 19>, <&usb4_3_dart 20>, <&usb4_3_dart 21>, + <&usb4_3_dart 22>, <&usb4_3_dart 23>, <&usb4_3_dart 24>, + <&usb4_3_dart 25>, <&usb4_3_dart 26>, <&usb4_3_dart 27>; + apple,thunderbolt-drom = + [ee 03 00 00 00 00 00 00 00 4e bc d0 4b 01 3d 00 + 01 00 0f 00 01 00 08 81 83 02 83 00 00 00 08 82 + 93 01 83 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 0d 01 41 70 70 6c 65 20 49 + 6e 63 2e 00 06 02 69 4f 53 00 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_3_sw: endpoint { + remote-endpoint = <&usb4_port3_sw>; + }; + }; + }; + }; + + usb4_port3: usb4-port@413000000 { + compatible = "apple,t8152-usb4-port"; + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x82900c0 0x0 0x104>, + <0x3 0x3a13a00 0x0 0x100>; + reg-names = "phy", "ps", "psd"; + label = "USB-C Back-right"; + apple,usb-pd = <&hpm3>; + apple,tunable-phy-pre = + <0x800 0xfc0000 0xfc0000>, + <0x84c 0xff800 0xff800>, + <0x85c 0xff 0x80>, + <0x860 0x7fffff 0x52bc26>, + <0x864 0x2c00000 0x800000>, + <0x1614 0x3ffc0 0x1e5c0>, + <0x1640 0x7 0x3>, + <0x1668 0xffc 0x5f0>; + apple,tunable-phy-post = + <0x6c004 0x3f003f 0x200020>, + <0x6c00c 0xf1 0xa1>, + <0x6c010 0x801f 0x4>, + <0x6c018 0x3f003f 0x200020>, + <0x6c020 0xf1 0xa1>, + <0x6c024 0x801f 0x4>, + <0x6c02c 0x7f007f 0x410041>, + <0x6c034 0xf1 0x71>, + <0x6c038 0x801f 0x4>, + <0x6c040 0x1f 0x10>, + <0x6c048 0x801f 0x4>, + <0x6c050 0x7f007f 0x450045>, + <0x6c058 0xf1 0x51>, + <0x6c05c 0x801f 0x4>, + <0x6c064 0x3f 0x20>, + <0x6c06c 0x801f 0x4>, + <0x6c074 0x1 0x1>, + <0x6c078 0x801f 0x4>, + <0x6c080 0x1f001f 0x100010>, + <0x6c084 0xf1 0x11>, + <0x6c088 0x1 0x1>, + <0x6c08c 0x1 0x1>, + <0x6c090 0x801f 0x4>, + <0x6c098 0x1f001f 0x100010>, + <0x6c09c 0xf1 0x11>, + <0x6c0a0 0x801f 0x4>, + <0x6c0a8 0xff 0xa0>, + <0x6c0ac 0x801f 0x4>, + <0x6c0b4 0x3f 0x20>, + <0x6c0bc 0x801f 0x4>, + <0x6c0c4 0x3f 0x20>, + <0x6c0cc 0x801f 0x4>, + <0x6c0d4 0xf 0x8>, + <0x6c0d8 0x801f 0x4>, + <0x6c0e0 0x1f001f 0x180018>, + <0x6c0e4 0x801f 0x4>, + <0x6c0ec 0x1f001f 0x180018>, + <0x6c0f0 0x801f 0x4>, + <0x6c0f8 0x1f001f 0x180018>, + <0x6c0fc 0x801f 0x4>, + <0x6c104 0x1f001f 0x180018>, + <0x6c108 0x801f 0x4>, + <0x6c110 0x1 0x1>, + <0x6c114 0x801f 0x4>, + <0x6c11c 0x801f 0x4>, + <0x6c124 0x801f 0x4>, + <0x6c12c 0x801f 0x4>, + <0x6c134 0x801f 0x4>, + <0x6c13c 0xffffffff 0x1010101>, + <0x6c140 0x801f 0x4>, + <0x6c148 0x801f 0x4>, + <0x6c150 0xffffffff 0x1010101>, + <0x6c154 0xffff 0x101>, + <0x6c158 0x801f 0x4>, + <0x6c160 0x801f 0x4>, + <0x6c168 0x801f 0x4>, + <0x6c170 0x801f 0x4>, + <0x6c178 0x801f 0x4>, + <0x6c180 0xffffffff 0x1010101>, + <0x6c184 0x801f 0x4>, + <0x6c18c 0x801f 0x4>, + <0x6c194 0x801f 0x4>, + <0x1040 0xc 0x8>, + <0x1060 0x1c000 0xc000>, + <0x1098 0xf00 0x800>, + <0x109c 0xfe000 0xfe000>, + <0x1108 0x7c00000 0x4000000>, + <0x110c 0x7c 0x10>, + <0xe8c 0x7f 0x3c>, + <0xe9c 0x7f 0x32>, + <0xeac 0x7f 0x32>, + <0xebc 0x7f 0x5a>, + <0x1488 0x1ff 0x128>, + <0x1494 0x100 0x100>, + <0x1a44 0x40f 0x40f>, + <0x1a48 0x40f 0x40f>, + <0x82d8 0xf0000000 0x70000000>, + <0x82dc 0xf 0x7>, + <0x8cf4 0x20 0x20>, + <0x77c4 0x3ff00 0xfa00>, + <0x7dbc 0x78 0x30>, + <0x7dd8 0x3f0 0x0>, + <0x7de8 0x3 0x3>, + <0x7dec 0x2 0x2>, + <0x7a00 0xf0 0x10>, + <0x7a08 0xfff 0x1>, + <0x7a28 0xff00000 0xcf00000>, + <0x7a40 0x7ffffff 0x28154a5>, + <0x7a7c 0x20000000 0x0>, + <0x7a80 0x1f 0x2>, + <0x7b98 0x3f00003f 0x31000014>, + <0x7b9c 0x3ffff 0xef4b>, + <0x7ba8 0xfc1f800 0x5005000>, + <0x7bac 0x7ffffe0 0x13f0e40>, + <0x7bbc 0x1c7 0x145>, + <0x7bc8 0x7f8 0x18>, + <0x8728 0x10f 0x10f>, + <0x878c 0xfc000000 0xfc000000>, + <0x8790 0x1 0x1>, + <0x87b4 0xe018000 0x6008000>, + <0x8708 0x40000000 0x40000000>, + <0x4c80 0x3f800000 0x0>, + <0x4c88 0x1fffff 0x0>, + <0x4fd4 0x3800000 0x2800000>, + <0x4e20 0xfff000 0x723000>, + <0x8980 0xfff000 0x723000>, + <0x85e4 0x4 0x0>, + <0x8628 0xff0 0x660>, + <0x862c 0xff0 0xea0>, + <0x8000 0xa 0x0>, + <0x8014 0x3ff 0x42>, + <0x7304 0xf 0x6>, + <0x7334 0x1ffffff 0x1004ea>, + <0x7284 0xf 0x6>, + <0x72cc 0x3ffff 0x4ea>, + <0x4d84 0x1c0000 0x0>, + <0x7f80 0xffffffff 0x148>, + <0x7f90 0x3ff00 0x2f700>, + <0x7fd0 0x100 0x0>, + <0x7d88 0xff 0x41>, + <0x7da8 0xffff0000 0x22110000>, + <0x7dac 0xff 0x44>, + <0x7dd8 0xc000 0x0>, + <0x7ddc 0x3 0x0>, + <0x7a1c 0xff8 0x528>, + <0x7a2c 0x3ffff 0x140aa>, + <0x7a30 0x1e00 0x1000>, + <0x7a34 0xff0000 0xa0000>, + <0x7b84 0xff 0x28>, + <0x7b88 0xf00f 0x7008>, + <0x7b8c 0xf00f 0x6007>, + <0x7b90 0xf00f 0x4005>, + <0x7bb4 0x703f 0x502d>, + <0x7bb8 0x703f 0x2013>, + <0x7bbc 0xe00 0x600>, + <0x8af4 0x1fe0000 0x1540000>, + <0x8af8 0x3fc000 0x2a8000>, + <0x4e94 0x1fe0000 0x1540000>, + <0x4e98 0x3fc000 0x2a8000>, + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0xf 0x7>, + <0x11cf4 0x20 0x20>, + <0x107c4 0x3ff00 0xfa00>, + <0x10dbc 0x78 0x30>, + <0x10dd8 0x3f0 0x0>, + <0x10de8 0x3 0x3>, + <0x10dec 0x2 0x2>, + <0x10a00 0xf0 0x10>, + <0x10a08 0xfff 0x1>, + <0x10a28 0xff00000 0xcf00000>, + <0x10a40 0x7ffffff 0x28154a5>, + <0x10a7c 0x20000000 0x0>, + <0x10a80 0x1f 0x2>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x3ffff 0xef4b>, + <0x10ba8 0xfc1f800 0x5005000>, + <0x10bac 0x7ffffe0 0x13f0e40>, + <0x10bbc 0x1c7 0x145>, + <0x10bc8 0x7f8 0x18>, + <0x11728 0x10f 0x10f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x1 0x1>, + <0x117b4 0xe018000 0x6008000>, + <0x11708 0x40000000 0x40000000>, + <0xdc80 0x3f800000 0x0>, + <0xdc88 0x1fffff 0x0>, + <0xdfd4 0x3800000 0x2800000>, + <0xde20 0xfff000 0x723000>, + <0x11980 0xfff000 0x723000>, + <0x115e4 0x4 0x0>, + <0x11628 0xff0 0x660>, + <0x1162c 0xff0 0xea0>, + <0x11000 0xa 0x0>, + <0x11014 0x3ff 0x42>, + <0x10304 0xf 0x6>, + <0x10334 0x1ffffff 0x1004ea>, + <0x10284 0xf 0x6>, + <0x102cc 0x3ffff 0x4ea>, + <0xdd84 0x1c0000 0x0>, + <0x10f80 0xffffffff 0x148>, + <0x10f90 0x3ff00 0x2f700>, + <0x10fd0 0x100 0x0>, + <0x10d88 0xff 0x41>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0xff 0x44>, + <0x10dd8 0xc000 0x0>, + <0x10ddc 0x3 0x0>, + <0x10a1c 0xff8 0x528>, + <0x10a2c 0x3ffff 0x140aa>, + <0x10a30 0x1e00 0x1000>, + <0x10a34 0xff0000 0xa0000>, + <0x10b84 0xff 0x28>, + <0x10b88 0xf00f 0x7008>, + <0x10b8c 0xf00f 0x6007>, + <0x10b90 0xf00f 0x4005>, + <0x10bb4 0x703f 0x502d>, + <0x10bb8 0x703f 0x2013>, + <0x10bbc 0xe00 0x600>, + <0x11af4 0x1fe0000 0x1540000>, + <0x11af8 0x3fc000 0x2a8000>, + <0xde94 0x1fe0000 0x1540000>, + <0xde98 0x3fc000 0x2a8000>; + + port { + usb4_port3_sw: endpoint { + remote-endpoint = <&usb4_3_sw>; + }; + }; + }; + + }; + + usb4_0_tunnel: usb4-pcie-tunnel-0 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_0_pcie_dart: iommu@404000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0x4000000 0x0 0xc000>, + <0x2 0x100 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd86>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_0_pcie: pcie@1c50000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x50000000 0x0 0x10000000>, + <0x4 0x4034000 0x0 0x4000>, + <0x4 0x4020000 0x0 0x8000>, + <0x4 0x4038000 0x0 0x4000>, + <0x4 0x4060000 0x0 0x4000>, + <0x4 0x402c000 0x0 0x4000>, + <0x4 0x4028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd86>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_0_pcie>; + msi-ranges = <&aic AIC_IRQ 1975 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <96>; + iommu-map = <0 &usb4_0_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <1>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x8 0x0 0x8 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0xa 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0xa 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_0_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_0_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_0_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_0_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_0_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; + + usb4_1_tunnel: usb4-pcie-tunnel-1 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_1_pcie_dart: iommu@40c000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0xc000000 0x0 0xc000>, + <0x2 0x180 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd87>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_1_pcie: pcie@1c60000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x60000000 0x0 0x10000000>, + <0x4 0xc034000 0x0 0x4000>, + <0x4 0xc020000 0x0 0x8000>, + <0x4 0xc038000 0x0 0x4000>, + <0x4 0xc060000 0x0 0x4000>, + <0x4 0xc02c000 0x0 0x4000>, + <0x4 0xc028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd87>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_1_pcie>; + msi-ranges = <&aic AIC_IRQ 2007 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <128>; + iommu-map = <0 &usb4_1_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <2>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0xc 0x0 0xc 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0xe 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0xe 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_1_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_1_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_1_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_1_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_1_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; + + usb4_3_tunnel: usb4-pcie-tunnel-3 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_3_pcie_dart: iommu@414000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0x14000000 0x0 0xc000>, + <0x2 0x280 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd89>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_3_pcie: pcie@1c80000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x80000000 0x0 0x10000000>, + <0x4 0x14034000 0x0 0x4000>, + <0x4 0x14020000 0x0 0x8000>, + <0x4 0x14038000 0x0 0x4000>, + <0x4 0x14060000 0x0 0x4000>, + <0x4 0x1402c000 0x0 0x4000>, + <0x4 0x14028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd89>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_3_pcie>; + msi-ranges = <&aic AIC_IRQ 2071 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <192>; + iommu-map = <0 &usb4_3_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <4>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x14 0x0 0x14 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0x16 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0x16 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_3_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_3_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_3_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_3_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_3_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; + +}; + +&pinctrl_aop { + usb4_0_lstx_pins: usb4-0-lstx-pins { + pinmux = <0x10013>; + }; + + usb4_1_lstx_pins: usb4-1-lstx-pins { + pinmux = <0x10015>; + }; + + usb4_3_lstx_pins: usb4-3-lstx-pins { + pinmux = <0x10019>; + }; + +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 5c229e74d5b0a..c3416ac0fd457 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -504,3 +504,4 @@ #include "t8152-j873-audio.dtsi" #include "t8152-j873-dcp.dtsi" #include "t8152-j873-avd.dtsi" +#include "t8152-j873-usb4.dtsi" From 6f9724a9c27233b858679a3c21ecb871c4042c82 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:20 +0100 Subject: [PATCH 112/112] arm64: configs: asahi: build the T8152 USB-C port monitor Build the monitor that starts USB4 on the rear USB-C ports of the M6 Mac mini (J873g), next to the Apple USB4 router driver. Signed-off-by: Thomas Glanzmann --- arch/arm64/configs/asahi.config | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 3da2ab3df0430..57f3cfe3aea8e 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -117,6 +117,7 @@ CONFIG_USB_VL122_HUB=m CONFIG_TYPEC=m CONFIG_USB4=m CONFIG_USB4_APPLE_SOC=m +CONFIG_USB4_APPLE_T8152_PORT=m CONFIG_USB_XHCI_PCI_ASMEDIA=y CONFIG_TYPEC_SN201202X=m CONFIG_RTC_DRV_MACSMC=y