From de80616b4d0ca6cb9cf7616e33997001b7640791 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 25 Oct 2026 21:44:54 +0100 Subject: [PATCH 001/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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/121] 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 3d6cd443e5898fe4cf7062cc27b0f8b791a85110 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 22 Nov 2026 15:21:39 +0100 Subject: [PATCH 061/121] arm64: dts: apple: t8152-j873g: power domains for the USB and Ethernet DARTs Every enabled DART must name the power state of the engine it serves (scripts/dtc/apple-dart-pd-check.py). The J873g USB and Ethernet DARTs named none. USB: the controllers' state is the ATC PMGR's ATC1_USB (usb-drd1, on atc-phy1) and ATC2_USB (usb-drd2, on atc-phy2), as for the dwc3 DARTs on T8132. The ADT also gives usb-drd1/2 service-gates 175/176, but those PSD service blocks take a bus error from the CPU. The loader leaves ATCn_USB and ATCn_USB_AON on (read back as 0x3ff on J873g), and they hold the controllers' reset and the USB2 PHY setup it did, which Linux cannot redo yet. So all four stay on, without automatic power management. ATCn_USB is a child of ATCn_USB_AON, as on T8132, so the order holds if that ever changes. The DWC3 nodes take the same state as their DARTs. Ethernet: dart-apcie2 takes APCIE_SYS_GP (child of APCIE_GP), as pcie2_dart does on T8142. iBoot leaves both on (0x2ff and 0x1f0003ff), and the loader's PHY and lane setup for port 2 cannot be redone by Linux, so both stay on. APCIE_GP has no automatic state set, and automatic power management would power gate it, so it stays off for both. Offsets are from the 26A434 ADT pmgr device list. Signed-off-by: Thomas Glanzmann --- .../boot/dts/apple/t8152-j873-ethernet.dtsi | 33 +++++++ arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 88 ++++++++++++++++--- 2 files changed, 109 insertions(+), 12 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi index 8b4f0f007df54..b40923e9fec9e 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi @@ -18,6 +18,38 @@ }; }; +/* + * The internal PCIe power states (ADT pmgr devices APCIE_GP and APCIE_SYS_GP, + * the latter's parent the former). iBoot leaves both on, and Linux cannot redo + * the PHY and lane setup the loader does on them, so they stay on, without + * automatic power management: APCIE_GP has no automatic state set and would + * be power gated by it. dart-apcie2 takes APCIE_SYS_GP, as on T8142. + */ +&pmgr { + ps_apcie_gp: power-controller@8c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x8c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_apcie_sys_gp: power-controller@ec0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xec0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_gp"; + power-domains = <&ps_apcie_gp>; + apple,no-auto-pm; + apple,always-on; + }; +}; + /* * dart-apcie2, described in t8152-peripherals.dtsi. The ADT window is * 0x20000; keep the 0xc000 this port was brought up with, the size that @@ -25,6 +57,7 @@ */ &pcie2_dart { reg = <0x3 0x8a000000 0x0 0xc000>; + power-domains = <&ps_apcie_sys_gp>; status = "okay"; }; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index dc4b2fb720f89..924df52e3622b 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -3,12 +3,13 @@ * 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 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). + * PHYs for host mode before Linux starts (there is no T8152 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. + * their two DARTs (apple,t8152-dwc3); their PHY reset, 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 (on atc-phy1 and + * atc-phy2) and the pmgr devices ATC1_USB_AON/USB and ATC2_USB_AON/USB. * * 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 @@ -18,29 +19,90 @@ * 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>; + power-domains = <&ps_atc1_usb>; status = "okay"; }; &dwc3_2_dart { reg = <0x3 0x83020000 0x0 0xc000>; + power-domains = <&ps_atc2_usb>; status = "okay"; }; / { soc { - /* Power domain: PSD service 175, see dwc3_1_dart above. */ + /* + * The ATCs' PMGR power states (ADT pmgr devices ATCn_USB_AON and + * ATCn_USB from 0x308290100, 0x40 apart per ATC). The ADT gives + * usb-drd1/2 service-gates 175/176, but those PSD service blocks + * (0x303a1af00, 0x303a1b000) take a bus error from the CPU. + * + * The loader leaves them on; they hold the controllers' reset and + * the USB2 PHY setup it did, which Linux cannot redo yet. So they + * stay on, without automatic power management. + */ + pmgr_atc: power-management@308290000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", + "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x08290000 0x0 0x1000>; + + ps_atc1_usb_aon: power-controller@140 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc1_usb: power-controller@160 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb"; + power-domains = <&ps_atc1_usb_aon>; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc2_usb_aon: power-controller@180 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc2_usb: power-controller@1a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb"; + power-domains = <&ps_atc2_usb_aon>; + apple,no-auto-pm; + apple,always-on; + }; + }; + dwc3_1_dart_1: iommu@40b040000 { compatible = "apple,t8152-dart", "apple,t8110-dart"; reg = <0x4 0x0b040000 0x0 0xc000>; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_atc1_usb>; }; usb1: usb@40a430000 { @@ -50,16 +112,17 @@ dr_mode = "host"; maximum-speed = "high-speed"; iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; + power-domains = <&ps_atc1_usb>; snps,dis_u2_susphy_quirk; 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>; interrupts = ; #iommu-cells = <1>; + power-domains = <&ps_atc2_usb>; }; /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ @@ -70,6 +133,7 @@ dr_mode = "host"; maximum-speed = "high-speed"; iommus = <&dwc3_2_dart 0>, <&dwc3_2_dart_1 1>; + power-domains = <&ps_atc2_usb>; snps,dis_u2_susphy_quirk; snps,dis_u3_susphy_quirk; }; From 93e075ab40609df821dd6d71a420da9e4ba54216 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:54:10 +0100 Subject: [PATCH 062/121] 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 e529b4d4dd4c6..e516f9d6cb6a9 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2125,6 +2125,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 521710f1e6d11b10392169ef5d0251ad4af9d2b6 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:55:49 +0100 Subject: [PATCH 063/121] 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 8db08f946b24fa8d2bea6692bbdd107a0feef845 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:57:36 +0100 Subject: [PATCH 064/121] 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 +- .../drivers/apple/bcm4377-radio-sids.py | 1 + 3 files changed, 112 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 9e009107f5a9d..a6c45cf639964 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]; @@ -1998,6 +2004,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) { @@ -2736,8 +2779,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, @@ -5632,6 +5678,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) @@ -6021,8 +6074,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. */ @@ -6377,6 +6456,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, @@ -7254,6 +7360,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 { diff --git a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py index 3d1026008cbd9..e13025a6157c5 100755 --- a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py +++ b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py @@ -97,6 +97,7 @@ def main(): u32 tcr_enabled, tcr_4level, ttbr_shift, ttbr_addr_field_shift; void (*enable_remap)(struct apple_dart *, int, int); int (*invalidate_tlb)(struct apple_dart_stream_map *); + bool gen3; }; struct apple_dart { const struct apple_dart_hw *hw; From 86cfe489b4f4648639881c370a29422c32e52f89 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:58:00 +0100 Subject: [PATCH 065/121] 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 a6c45cf639964..52a87ddcd878b 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) @@ -2021,9 +2024,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) | @@ -2036,6 +2051,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 dde587e5821f1a62cef61c9ff2ddecd2ceb190bc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 09:58:41 +0100 Subject: [PATCH 066/121] 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 a72cd78404ae38e1dcb0d514416fda9f890336e0 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:00:57 -0500 Subject: [PATCH 067/121] 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 0c39402095736ca2610d26be794fafa3033ca176 Mon Sep 17 00:00:00 2001 From: Acelogic Date: Fri, 6 Nov 2026 05:08:51 -0500 Subject: [PATCH 068/121] 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 0b06c6c57f9b70f8663dd919c7e22afdfa3c2ce9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:53:55 +0100 Subject: [PATCH 069/121] 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 56993478070c892749ad37b7d0e10baabf5287cd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 11:03:18 +0100 Subject: [PATCH 070/121] 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 949f02b3303c3b84a90a80f821313dffe55e16f4 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 17:49:53 +0100 Subject: [PATCH 071/121] 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 DCP driver 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 5c8fc89e51d00..cb48635b6e368 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 8cd49af527ad877498ef7c827a9db958cd8d952d Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 21:22:30 +0100 Subject: [PATCH 072/121] 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 52a87ddcd878b..938e6f519efa6 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -2230,6 +2230,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); @@ -5699,11 +5708,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 f2d7db867726de83720139725236abbbace91109 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:21:46 +0100 Subject: [PATCH 073/121] drm/apple: let the match data select the AFKv2 wire afk_init() picks the AFKv2 wire for firmware 27 and for the T8122 external processor on 26.x, both recognised by their IOMFB interface. The T8152 DCP firmware speaks AFKv2 on every endpoint of its iBoot interface (the display service, the DPAV controller services and the DPTX port services), and drm/apple drives no IOMFB interface of it that a version could key on. Add hw.afk_v2, which selects AFKv2 for all endpoints of a processor. No match entry sets it yet. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 3 ++- drivers/gpu/drm/apple/dcp-internal.h | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 3c5eaf725d02a..27fc612d460bb 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -115,7 +115,8 @@ struct apple_dcp_afkep *afk_init(struct apple_dcp *dcp, u32 endpoint, afkep->ops = ops; afkep->dcp = dcp; - afkep->wire_v2 = dcp->fw_compat == DCP_FIRMWARE_V_27_0 || dcp_is_ext26(dcp); + afkep->wire_v2 = dcp->fw_compat == DCP_FIRMWARE_V_27_0 || dcp_is_ext26(dcp) || + dcp->hw.afk_v2; afkep->endpoint = endpoint; afkep->wq = alloc_ordered_workqueue("apple-dcp-afkep%02x", WQ_MEM_RECLAIM, endpoint); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f09..943019c89f8af 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -345,6 +345,12 @@ struct apple_dcp_hw_data { * firmware 27.0 and 27.2.1), so there is no secure port to idle before the IOP. */ bool s2r_no_secure_port; + /* + * Every AFK endpoint speaks AFKv2 (see afk_init()), whatever the + * firmware interface: for a firmware that does so on all of them + * without an IOMFB interface version that implies it. + */ + bool afk_v2; }; enum dcp_test_point { From d3c2919e810dafd75114ade807f24de3d5e41acd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:23:44 +0100 Subject: [PATCH 074/121] drm/apple: start AFK endpoints of an RTKit session taken without its map The T8152 DCP does not acknowledge AP QUIESCED, and an IOP INIT while its AP power is still on panics the firmware ("Invalid AP power: 32"). A session the bootloader leaves running can only be taken over as it runs, with apple_rtkit_init_adopted(), without the HELLO/EPMAP handshake: the endpoint map went to the bootloader, and apple_rtkit_start_ep() refuses an endpoint RTKit does not know. Add hw.afk_adopt_endpoints. With it afk_start() registers the endpoint with apple_rtkit_adopt_ep() before it sends anything to it, so its START_EP goes out and its replies are not taken for an unknown endpoint's. No match entry sets it yet. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 7 +++++++ drivers/gpu/drm/apple/dcp-internal.h | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 27fc612d460bb..ff105620dfc09 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -249,6 +249,13 @@ int afk_start(struct apple_dcp_afkep *ep) } reinit_completion(&ep->started); + /* + * An adopted session's endpoint map went to the bootloader, and RTKit + * starts only endpoints it knows. Registered before anything is sent, + * the endpoint's replies are not reported as an unknown endpoint's. + */ + if (ep->dcp->hw.afk_adopt_endpoints) + apple_rtkit_adopt_ep(ep->dcp->rtk, ep->endpoint); ret = apple_rtkit_start_ep(ep->dcp->rtk, ep->endpoint); if (ret) return ret; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 943019c89f8af..ef548bb14ae56 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -351,6 +351,12 @@ struct apple_dcp_hw_data { * without an IOMFB interface version that implies it. */ bool afk_v2; + /* + * The RTKit session is taken over without its endpoint map (see + * apple_rtkit_init_adopted()): afk_start() registers each endpoint + * with RTKit before starting it. + */ + bool afk_adopt_endpoints; }; enum dcp_test_point { From 3898e1fb053f64737ec24362caeb77ac2264746f Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:25:35 +0100 Subject: [PATCH 075/121] drm/apple: stop the AFK endpoints a bootloader left running A bootloader that drives the display through the DCP firmware can leave AFK endpoints running with its scanout when it hands over, as the T8152 loader does with the iBoot interface's endpoints. An AFK INIT on a live endpoint asserts in the firmware. Add dcp->afk_live_endpoints, bit N for endpoint 0x20 + N, which a processor's probe fills from such a hand-off (the T8152 loader's apple,afk-active-endpoints). afk_start() sends an endpoint whose bit is set a SHUTDOWN and waits for its acknowledgment before START_EP and INIT, after registering it with an adopted RTKit session so that the acknowledgment is not taken for an unknown endpoint's. The old session's ring stays the bootloader's, which keeps it reserved. The mask is zero on every processor that sets nothing, so their start is unchanged. The stop of the live endpoints is based on a change by Acelogic for the T8152 hand-off. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 32 ++++++++++++++++++++++++++++ drivers/gpu/drm/apple/dcp-internal.h | 6 ++++++ 2 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index ff105620dfc09..d0f6f84d5704a 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -236,6 +236,35 @@ static int afk_start_polled(struct apple_dcp_afkep *ep) return -ETIMEDOUT; } +/* + * An endpoint the bootloader left running (afk_live_endpoints): an INIT + * on a live endpoint asserts in the firmware. Stop it and wait for the + * acknowledgment first. Its old ring stays with the bootloader, which + * keeps it reserved. + */ +static int afk_stop_live(struct apple_dcp_afkep *ep) +{ + u32 bit; + + if (ep->endpoint < 0x20 || ep->endpoint >= 0x40) + return 0; + bit = BIT(ep->endpoint - 0x20); + if (!(ep->dcp->afk_live_endpoints & bit)) + return 0; + reinit_completion(&ep->stopped); + afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); + if (!wait_for_completion_timeout(&ep->stopped, msecs_to_jiffies(1000))) { + dev_err(ep->dcp->dev, "AFK[ep:%02x]: inherited endpoint did not stop\n", + ep->endpoint); + return -ETIMEDOUT; + } + reinit_completion(&ep->stopped); + ep->dcp->afk_live_endpoints &= ~bit; + dev_info(ep->dcp->dev, "AFK[ep:%02x]: inherited endpoint stopped\n", + ep->endpoint); + return 0; +} + int afk_start(struct apple_dcp_afkep *ep) { int ret; @@ -256,6 +285,9 @@ int afk_start(struct apple_dcp_afkep *ep) */ if (ep->dcp->hw.afk_adopt_endpoints) apple_rtkit_adopt_ep(ep->dcp->rtk, ep->endpoint); + ret = afk_stop_live(ep); + if (ret) + return ret; ret = apple_rtkit_start_ep(ep->dcp->rtk, ep->endpoint); if (ret) return ret; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index ef548bb14ae56..bc5449a12f97d 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -575,6 +575,12 @@ struct apple_dcp { enum dcp_firmware_version fw_compat; /* Bumped by every iomfb poweron; see afk_compact_slot(). */ u32 afk_power_gen; + /* + * AFK endpoints the bootloader left running, bit N for endpoint + * 0x20 + N, from its hand-off: afk_start() stops each before its + * INIT. Zero for a processor without such a hand-off. + */ + u32 afk_live_endpoints; /* Firmware 27.x: the method IDs of this build (iomfb_v27_methods()). */ const struct dcp_method_entry *v27_methods; bool external; From c4f5c4edf067c57a7cc37e3063dcfdf771307cf5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:27:27 +0100 Subject: [PATCH 076/121] drm/apple: send AFK commands without output without a reply buffer afk_send_command() allocates a reply buffer of the output length and names it in the command, even for a length of zero. The AFKv2 setters of the T8152 DCP firmware's iBoot interface (SET_POWER, SET_MODE, SET_SURFACE) answer with a transport status alone. Given a reply buffer, the firmware copies an empty reply into it and asserts. Give a command without output no reply buffer: its descriptor carries address and length zero, which the AFKv2 codec already accepts and checks the reply against. Every current caller passes an output length, so none of them changes. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index d0f6f84d5704a..2a52c9fd63c18 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -3308,11 +3308,20 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, goto err_put_service; } - rxbuf = dma_alloc_coherent(ep->dcp->dev, output_len, &rxbuf_dma, - GFP_KERNEL); - if (!rxbuf) { - ret = -ENOMEM; - goto err_put_service; + /* + * A command without output carries no reply buffer: firmware that + * answers some commands with a status alone asserts when it is given + * one, since it then copies an empty reply. + */ + rxbuf = NULL; + rxbuf_dma = 0; + if (output_len) { + rxbuf = dma_alloc_coherent(ep->dcp->dev, output_len, &rxbuf_dma, + GFP_KERNEL); + if (!rxbuf) { + ret = -ENOMEM; + goto err_put_service; + } } txbuf = dma_alloc_coherent(ep->dcp->dev, payload_len, &txbuf_dma, GFP_KERNEL); @@ -3470,7 +3479,7 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, if (!dcp_is_ext26(ep->dcp)) dma_free_coherent(ep->dcp->dev, payload_len, txbuf, txbuf_dma); err_free_rxbuf: - if (!dcp_is_ext26(ep->dcp)) + if (rxbuf && !dcp_is_ext26(ep->dcp)) dma_free_coherent(ep->dcp->dev, output_len, rxbuf, rxbuf_dma); err_put_service: afk_service_put(service); From 293a032adc991ea8d1ffc8c9bbe3e6366f2957a9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:29:25 +0100 Subject: [PATCH 077/121] drm/apple: match AFK services by their announced name afk_recv_handle_init() parses the properties that follow a service's announced name whenever there are any, and matches the service by the EPIC provider class found there. Which keys it accepts depends on the firmware interface version. The T8152 DCP firmware's iBoot service (disp0-service, dispext-service) is announced by name alone, and the properties of its DPTX and DPAV services are not needed to drive it: a property set the parser rejects would leave such a service unopened. Add hw.afk_announced_names. With it the properties are not parsed, the service is matched by its announced name, and that name is what its handler gets as the EPIC name. No match entry sets it yet. The startup host test's and the apple-dcp service rebind test's processors gain the flag, and the latter kstrdup(). The provider admission test looks for the announcement's OPEN in the first 7000 bytes of afk_recv_handle_init() instead of 6500, which no longer reach it. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 15 ++++++++++++--- drivers/gpu/drm/apple/dcp-internal.h | 5 +++++ tools/asahi/dcpext26-startup-tests.py | 3 ++- .../selftests/drivers/gpu/apple-dcp/edid.py | 6 ++++-- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 2a52c9fd63c18..630acfdc5af17 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1779,7 +1779,7 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, * EPICProviderClass was used. If the init call has props parse them and * use EPICProviderClass to match the service. */ - if (props_size > 36) { + if (props_size > 36 && !ep->dcp->hw.afk_announced_names) { int ret = parse(props, props_size, &ctx); if (ret) { dev_err(ep->dcp->dev, @@ -1824,8 +1824,17 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, service_name = epic_class; } } else { - service_name = name; - } + service_name = name; + /* + * hw.afk_announced_names: the announced name is the service's + * identity, and its handler gets it as the EPIC name. + */ + if (ep->dcp->hw.afk_announced_names) { + epic_name = kstrdup(name, GFP_KERNEL); + if (!epic_name) + return; + } + } if (ep->match_epic_name) ops = afk_match_service(ep, epic_name); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index bc5449a12f97d..1621c62f1a4a0 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -357,6 +357,11 @@ struct apple_dcp_hw_data { * with RTKit before starting it. */ bool afk_adopt_endpoints; + /* + * AFK services are matched by the name in their announcement; the + * properties after it are not parsed (afk_recv_handle_init()). + */ + bool afk_announced_names; }; enum dcp_test_point { diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index 0811ada7ce526..c71308f06d258 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -59,6 +59,7 @@ def run(name,code,reject=False): #define kmalloc(n,f) malloc(n) #define kzalloc_obj(v) calloc(1,sizeof(v)) #define kfree(p) free((void *)(p)) +#define kstrdup(s,f) strdup(s) #define max(a,b) ((a)>(b)?(a):(b)) #define dev_info(...) ((void)0) #define dev_err(...) ((void)0) @@ -93,7 +94,7 @@ def run(name,code,reject=False): struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);}; struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; -struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index fe2e56e1f46ea..bc5eb6f352967 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -100,7 +100,7 @@ def function(file,signature): struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; bool external_physically_absent,hpd_mutex,quiescing,typec_cable_connected;u64 typec_generation;unsigned int nr_modes; - struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; + struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints,afk_announced_names; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; struct { bool lock,enabled;u64 epoch;int enable_completion;struct apple_epic_service *service,*opened; u64 opened_epoch,close_gen,terminated_epoch,close_epoch;bool opening;struct work_struct close_wq; } dcpavserv; /* A J714s firmware 27 processor's: this one is not. */ @@ -146,6 +146,8 @@ def function(file,signature): struct dcp_parse_ctx { struct item *items;unsigned int count,index;bool key; }; struct iterator { struct dcp_parse_ctx *handle;unsigned int idx,len; }; #define kfree(p) free((void *)(p)) +#define GFP_KERNEL 0 +#define kstrdup(s,f) strdup(s) #define PTR_ERR(p) ((int)(intptr_t)(p)) static struct item announcement_items[3]; static int parse(u8 *p,size_t n,struct dcp_parse_ctx *ctx) @@ -574,7 +576,7 @@ def function(file, signature): av = (base / 'epic/dpavservep.c').read_text() af = (base / 'afk.c').read_text() - announce = af[af.index('static void afk_recv_handle_init('):af.index('static void afk_recv_handle_init(') + 6500] + announce = af[af.index('static void afk_recv_handle_init('):af.index('static void afk_recv_handle_init(') + 7000] assert announce.index('ops->prepare(service,') < announce.index('EPIC_CAT_REPORT, AFKV2_OPEN') assert '.prepare = dcpavserv_prepare,' in av and '.prepare = dcpdpserv_prepare,' in av prefix = r''' From 94f53b5f51e90c62908bc9cdbef48d07d6e6b28c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:31:15 +0100 Subject: [PATCH 078/121] drm/apple: open AFK services that have no handler An announced service that no entry of its endpoint's ops table names is left unopened, apart from two firmware-specific exceptions that bind it to the endpoint's first entry. The T8152 DCP firmware's DPAV controller endpoint announces four services and expects all of them to be opened, among them dcpav-video-interface, whose opening starts the firmware's idle power off timer for the display. None of them takes commands from the host. Add ep->unmatched_ops, bound to every announced service that no entry of the endpoint's ops table matches, which is then opened and initialised like a matched one. It is NULL on every existing endpoint, whose unmatched services stay unopened as before. The startup host test's and the apple-dcp service rebind test's endpoints gain the field. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 2 ++ drivers/gpu/drm/apple/afk.h | 5 +++++ tools/asahi/dcpext26-startup-tests.py | 2 +- tools/testing/selftests/drivers/gpu/apple-dcp/edid.py | 2 +- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 630acfdc5af17..7b0e00d052b47 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1857,6 +1857,8 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, if (!ops && dcp_is_ext26(ep->dcp) && ep->ops && !strcmp(ep->ops->name, "native26-observer")) ops = ep->ops; + if (!ops) + ops = ep->unmatched_ops; if (!ops) { dev_err(ep->dcp->dev, "AFK[ep:%02x]: unable to match service %s on channel %d\n", diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index b2c7c5deddb29..da51a5fa0daee 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -580,6 +580,11 @@ struct apple_dcp_afkep { void *compact_rx_data; const struct apple_epic_service_ops *ops; + /* + * Bound to an announced service no entry of @ops names, which is then + * opened like a matched one. NULL leaves such a service unopened. + */ + const struct apple_epic_service_ops *unmatched_ops; struct apple_epic_service services[AFK_MAX_CHANNEL]; u32 num_channels; diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index c71308f06d258..bc8a0aa89a992 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -95,7 +95,7 @@ def run(name,code,reject=False): struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; -struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; +struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops,*unmatched_ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} static bool dcp_is_v14_7_external(struct apple_dcp *d){return false;} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index bc5eb6f352967..b4ea075b85f27 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -95,7 +95,7 @@ def function(file,signature): bool pending_open;const char *pending_name,*pending_class;s64 pending_unit; }; /* v27_closed_teardown: set only by a J714s firmware 27 sleep. */ -struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; +struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops,*unmatched_ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; struct apple_connector { void *dcp;bool connected,edid_invalidation_pending;struct { int registration_state; } base;unsigned int hotplug_wq; }; struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; From 0c78a077cde0962c2393bb4091ac5fe3493d9cdd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:33:32 +0100 Subject: [PATCH 079/121] drm/apple: let the match data set the AFK timeout AFK waits one second for an endpoint to start or stop and for a command or service call to be answered. The T8152 DCP firmware's iBoot display commands answer only once the DisplayPort work they start is done: SET_POWER and SET_MODE wait for the link training, during which the firmware calls into the AP for the PHY. The T8152 displays have been run on the hardware with three seconds for each of these. Add hw.afk_timeout_ms, the time afk_start(), afk_shutdown(), the inherited endpoint stop, afk_send_command(), afk_service_call() and afk_service_call_len() wait. Zero keeps one second, so every processor that sets nothing waits as before. Callers that pass their own timeout, and the legacy reply-length calls, are unchanged. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 27 +++++++++++++++++++++------ drivers/gpu/drm/apple/dcp-internal.h | 6 ++++++ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 7b0e00d052b47..6b65f13e05209 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -83,6 +83,18 @@ void afk_service_retry(struct apple_dcp_afkep *ep) } EXPORT_SYMBOL_IF_KUNIT(afk_service_retry); +/* How long the host waits for the firmware: the processor's own, or one second. */ +static unsigned int afk_timeout_ms(struct apple_dcp_afkep *ep) +{ + return ep->dcp->hw.afk_timeout_ms ?: MSEC_PER_SEC; +} + +/* The same for a service the caller may not have; the call fails without one. */ +static unsigned int afk_service_timeout_ms(struct apple_epic_service *service) +{ + return service ? afk_timeout_ms(service->ep) : MSEC_PER_SEC; +} + static void afk_send(struct apple_dcp_afkep *ep, u64 message) { dcp_send_message(ep->dcp, ep->endpoint, message); @@ -185,7 +197,8 @@ void afk_shutdown(struct apple_dcp_afkep *afkep) afk_send(afkep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); int ret; - ret = wait_for_completion_timeout(&afkep->stopped, msecs_to_jiffies(1000)); + ret = wait_for_completion_timeout(&afkep->stopped, + msecs_to_jiffies(afk_timeout_ms(afkep))); if (ret <= 0) { dev_err(afkep->dcp->dev, "Timed out shutting down AFK endpoint %02x", afkep->endpoint); } @@ -253,7 +266,8 @@ static int afk_stop_live(struct apple_dcp_afkep *ep) return 0; reinit_completion(&ep->stopped); afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); - if (!wait_for_completion_timeout(&ep->stopped, msecs_to_jiffies(1000))) { + if (!wait_for_completion_timeout(&ep->stopped, + msecs_to_jiffies(afk_timeout_ms(ep)))) { dev_err(ep->dcp->dev, "AFK[ep:%02x]: inherited endpoint did not stop\n", ep->endpoint); return -ETIMEDOUT; @@ -296,7 +310,8 @@ int afk_start(struct apple_dcp_afkep *ep) return afk_start_polled(ep); afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_INIT)); - ret = wait_for_completion_timeout(&ep->started, msecs_to_jiffies(1000)); + ret = wait_for_completion_timeout(&ep->started, + msecs_to_jiffies(afk_timeout_ms(ep))); if (ret <= 0 && ep->dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) dev_warn(ep->dcp->dev, @@ -3187,7 +3202,7 @@ int afk_send_command(struct apple_epic_service *service, u8 type, { return afk_send_command_timeout(service, type, payload, payload_len, output, output_len, retcode, - MSEC_PER_SEC); + afk_service_timeout_ms(service)); } static u16 afk_command_tag(struct apple_epic_service *service, u8 slot) @@ -3503,7 +3518,7 @@ int afk_service_call(struct apple_epic_service *service, u16 group, u32 command, { return afk_service_call_timeout(service, group, command, data, data_len, data_pad, output, output_len, - output_pad, MSEC_PER_SEC); + output_pad, afk_service_timeout_ms(service)); } int afk_service_call_len(struct apple_epic_service *service, u16 group, @@ -3513,7 +3528,7 @@ int afk_service_call_len(struct apple_epic_service *service, u16 group, { return afk_service_call_timeout_len(service, group, command, data, data_len, data_pad, output, output_len, output_pad, - MSEC_PER_SEC, received); + afk_service_timeout_ms(service), received); } int afk_service_call_timeout(struct apple_epic_service *service, u16 group, diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 1621c62f1a4a0..f3a8c15ec3d74 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -362,6 +362,12 @@ struct apple_dcp_hw_data { * properties after it are not parsed (afk_recv_handle_init()). */ bool afk_announced_names; + /* + * How long AFK waits for the firmware to start or stop an endpoint + * and to answer a command or service call (afk_timeout_ms()); zero + * for one second. + */ + unsigned int afk_timeout_ms; }; enum dcp_test_point { From e5ccb7e2acec86b5b1cb088dce99354601507ff0 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:37:26 +0100 Subject: [PATCH 080/121] drm/apple: add iBoot SET_SURFACE and display commands for other users ibootep.c sends the iBoot interface's display commands only for the T6030 external role's first-pixel diagnostic: the queries and setters are reachable from its sysfs file and pattern path alone, gated on dcp->external, and the surface is set through the swap operations 15/16/18/19. The T8152 DCP firmware is driven through this interface alone and sets its surface with operation 1, SET_SURFACE. - Add DCP_FIRMWARE_IBOOT, a DCP driven through the iBoot interface alone, and dcp_is_iboot(). No match entry selects it yet. - Build SET_SURFACE (operation 1, one 164-byte layer) and the three queries in iboot_build_pattern_request(). - Export ibootep_set_power(), ibootep_get_hpd(), ibootep_get_timing_modes(), ibootep_get_color_modes(), ibootep_set_mode() and ibootep_set_surface(), with the mode records in ibootep.h. On AFKv2 the setters go out without a reply buffer, as the firmware asserts on one, and a reply is checked against the length the transport reports, through the new afk_send_command_len(). SET_SURFACE scans out one linear BGRA plane in colour space 2, as the bootloader sets it on T8152. - Open the service for a DCP_FIRMWARE_IBOOT processor under either of its names (disp0-service on the main DCP, dispext-service on the external ones), without the manual query file: its display driver sends every command. The T6030 external role keeps its gate, its service name, its sysfs file and its pattern and frame commands as they were. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 9 ++ drivers/gpu/drm/apple/afk.h | 7 + drivers/gpu/drm/apple/dcp-internal.h | 6 + drivers/gpu/drm/apple/ibootep.c | 205 +++++++++++++++++++++++++- drivers/gpu/drm/apple/ibootep.h | 38 +++++ drivers/gpu/drm/apple/version_utils.h | 6 + 6 files changed, 266 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 6b65f13e05209..ad684ae5e954b 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -3247,6 +3247,15 @@ int afk_send_command_timeout(struct apple_epic_service *service, u8 type, output, output_len, retcode, timeout_ms, NULL); } +int afk_send_command_len(struct apple_epic_service *service, u8 type, + const void *payload, size_t payload_len, void *output, + size_t output_len, u32 *retcode, size_t *received) +{ + return afk_send_command_timeout_len(service, type, payload, payload_len, + output, output_len, retcode, + afk_service_timeout_ms(service), received); +} + /* * @reply_len (legacy EPIC only): return just the bytes the firmware reported * in its reply instead of the whole allocated output. diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index da51a5fa0daee..c01022b6b0f87 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -646,6 +646,13 @@ int afk_send_command_timeout(struct apple_epic_service *service, u8 type, const void *payload, size_t payload_len, void *output, size_t output_len, u32 *retcode, unsigned int timeout_ms); +/* + * As afk_send_command(), and @received is set to the number of bytes of + * @output the reply filled: an AFKv2 reply may be shorter than @output_len. + */ +int afk_send_command_len(struct apple_epic_service *service, u8 type, + const void *payload, size_t payload_len, void *output, + size_t output_len, u32 *retcode, size_t *received); int afk_service_call(struct apple_epic_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); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index f3a8c15ec3d74..9618011b29c56 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -1211,6 +1211,12 @@ struct apple_dcp { struct dcp_cec *cec; }; +/* A DCP driven through the firmware's iBoot interface alone. */ +static inline bool dcp_is_iboot(const struct apple_dcp *dcp) +{ + return dcp->fw_compat == DCP_FIRMWARE_IBOOT; +} + /* T8132 firmware uses its own wire codec, with the common DRM/KMS owner. */ static inline bool iomfb_is_m4(const struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/ibootep.c b/drivers/gpu/drm/apple/ibootep.c index 7f90f68bf26f6..1a12fb947d2cc 100644 --- a/drivers/gpu/drm/apple/ibootep.c +++ b/drivers/gpu/drm/apple/ibootep.c @@ -22,9 +22,12 @@ #define IBOOT_PATTERN_STRIDE DCPEXT_STRIDE enum iboot_query_op { + IBOOT_SET_SURFACE = 1, + IBOOT_SET_POWER = 2, IBOOT_GET_HPD = 3, IBOOT_GET_TIMING_MODES = 4, IBOOT_GET_COLOR_MODES = 5, + IBOOT_SET_MODE = 6, }; /* Packed layouts from m1n1 src/dcp_iboot.h and swap_set_layer_cmd_v13_3. */ @@ -148,15 +151,25 @@ static int iboot_parse_swap_begin(const u8 *reply, size_t received, u32 *id) return 0; } -static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) +/* A mode list: a count, then as many 24-byte records. */ +static int iboot_parse_mode_count(const u8 *payload, size_t size, u32 *count) { - u32 i; - if (size < 4) return -EPROTO; *count = get_unaligned_le32(payload); if (*count > (size - 4) / IBOOT_MODE_SIZE) return -EPROTO; + return 0; +} + +static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) +{ + u32 i; + int ret; + + ret = iboot_parse_mode_count(payload, size, count); + if (ret) + return ret; for (i = 0; i < *count; i++) if (get_unaligned_le32(payload + 4 + i * IBOOT_MODE_SIZE) > 1) return -EPROTO; @@ -234,7 +247,13 @@ static int iboot_build_pattern_request(u32 op, const void *data, size_t data_siz size_t expected; switch (op) { + case 1: /* SetSurface */ + expected = sizeof(struct iboot_layer); + break; case 2: expected = 1; break; /* SetPower */ + case 3 ... 5: /* GetHPD, GetTimingModes, GetColorModes */ + expected = 0; + break; case 6: expected = 2 * IBOOT_MODE_SIZE; break; /* SetMode */ case 15: expected = 0; break; /* SwapBegin */ case 16: expected = sizeof(struct iboot_swap_layer_v13_3); break; @@ -401,7 +420,7 @@ static struct iboot_query *iboot_find_query(struct apple_dcp *dcp) struct apple_dcp_afkep *ep = READ_ONCE(dcp->ibootep); u32 i; - if (!dcp->external || !ep) + if ((!dcp->external && !dcp_is_iboot(dcp)) || !ep) return ERR_PTR(-ENODEV); for (i = 0; i < AFK_MAX_CHANNEL; i++) { struct iboot_query *query = smp_load_acquire(&ep->services[i].cookie); @@ -668,6 +687,157 @@ int ibootep_present_pattern(struct apple_dcp *dcp, u64 iova, size_t size, u32 st return ret; } +/* + * One display command of the iBoot interface, with its reply payload copied + * to @out (at least @min_size bytes of it; returns the bytes copied), or a + * setter if @out is NULL. On AFKv2 the setters answer with a transport + * status alone: given a reply buffer, the firmware copies an empty reply + * into it and asserts, so they go out without one. Only the reply's own + * length is checked, not that its first word repeats @op. + */ +static int iboot_command(struct apple_dcp *dcp, u32 op, const void *data, + size_t size, void *out, size_t out_size, size_t min_size) +{ + struct iboot_query *query = iboot_find_query(dcp); + u8 request[16 + sizeof(struct iboot_swap_layer_v13_3)]; + size_t len, received = 0; + u32 retcode = 0, reply_len; + u8 *reply = NULL; + int ret; + + if (IS_ERR(query)) + return PTR_ERR(query); + ret = iboot_build_pattern_request(op, data, size, request, + sizeof(request), &len); + if (ret) + return ret; + if (out || !query->service->ep->wire_v2) { + reply = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); + if (!reply) + return -ENOMEM; + } + ret = afk_send_command_len(query->service, EPIC_SUBTYPE_STD_SERVICE, + request, len, reply, + reply ? IBOOT_QUERY_RX_SIZE : 0, &retcode, + &received); + if (!ret && retcode) { + dev_dbg(dcp->dev, "iBoot command %u returned %#x\n", op, retcode); + ret = -EIO; + } + if (ret || !out) + goto out; + reply_len = received >= 8 ? get_unaligned_le32(reply + 4) : 0; + if (reply_len < 8 || reply_len > received || reply_len - 8 < min_size) { + dev_err(dcp->dev, "iBoot: bad response length for command %u\n", op); + ret = -EPROTO; + goto out; + } + ret = min_t(size_t, reply_len - 8, out_size); + memcpy(out, reply + 8, ret); +out: + kfree(reply); + return ret; +} + +int ibootep_set_power(struct apple_dcp *dcp, bool on) +{ + u8 power = on; + + return iboot_command(dcp, IBOOT_SET_POWER, &power, sizeof(power), NULL, + 0, 0); +} + +int ibootep_get_hpd(struct apple_dcp *dcp, u32 *timings, u32 *colors) +{ + u8 payload[12]; + u32 timing_count, color_count; + bool hpd; + int ret; + + ret = iboot_command(dcp, IBOOT_GET_HPD, NULL, 0, payload, sizeof(payload), + sizeof(payload)); + if (ret >= 0) + ret = iboot_parse_hpd(payload, ret, &hpd, &timing_count, + &color_count); + if (ret) + return ret; + if (timings) + *timings = timing_count; + if (colors) + *colors = color_count; + return hpd; +} + +static int iboot_get_modes(struct apple_dcp *dcp, u32 op, void **modes, + unsigned int *count) +{ + u32 n; + u8 *buf; + int ret; + + buf = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + ret = iboot_command(dcp, op, NULL, 0, buf, IBOOT_QUERY_RX_SIZE, 4); + if (ret >= 0) + ret = iboot_parse_mode_count(buf, ret, &n); + if (!ret) { + *modes = kmemdup(buf + 4, n * IBOOT_MODE_SIZE, GFP_KERNEL); + if (*modes) + *count = n; + else + ret = -ENOMEM; + } + kfree(buf); + return ret; +} + +int ibootep_get_timing_modes(struct apple_dcp *dcp, + struct iboot_timing_mode **modes, + unsigned int *count) +{ + return iboot_get_modes(dcp, IBOOT_GET_TIMING_MODES, (void **)modes, count); +} + +int ibootep_get_color_modes(struct apple_dcp *dcp, + struct iboot_color_mode **modes, unsigned int *count) +{ + return iboot_get_modes(dcp, IBOOT_GET_COLOR_MODES, (void **)modes, count); +} + +int ibootep_set_mode(struct apple_dcp *dcp, const struct iboot_timing_mode *timing, + const struct iboot_color_mode *color) +{ + struct { + struct iboot_timing_mode timing; + struct iboot_color_mode color; + } __packed mode = { *timing, *color }; + + return iboot_command(dcp, IBOOT_SET_MODE, &mode, sizeof(mode), NULL, 0, 0); +} + +int ibootep_set_surface(struct apple_dcp *dcp, u64 iova, u32 width, u32 height, + u32 stride) +{ + /* One linear BGRA plane, SDR, in colour space 2 as the bootloader sets. */ + struct iboot_layer layer = { + .planes = { { + .addr = cpu_to_le64(iova), + .stride = cpu_to_le32(stride), + .addr_format = cpu_to_le32(1), + } }, + .plane_count = cpu_to_le32(1), + .width = cpu_to_le32(width), + .height = cpu_to_le32(height), + .surface_format = cpu_to_le32(1), + .colorspace = cpu_to_le32(2), + .eotf = cpu_to_le32(1), + }; + + return iboot_command(dcp, IBOOT_SET_SURFACE, &layer, sizeof(layer), NULL, + 0, 0); +} + static ssize_t dcpext_modes_query_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -699,7 +869,7 @@ static void disp_service_init(struct apple_epic_service *service, const char *na struct iboot_query *query; int ret; - if (!dcp->external) + if (!dcp->external && !dcp_is_iboot(dcp)) return; query = devm_kzalloc(dcp->dev, sizeof(*query), GFP_KERNEL); if (!query) @@ -710,6 +880,16 @@ static void disp_service_init(struct apple_epic_service *service, const char *na ret = devm_add_action_or_reset(dcp->dev, iboot_query_cancel, query); if (ret) return; + /* + * A DCP driven through this interface alone has a display driver that + * sends every command (the exported ibootep_* calls); it takes no + * manual queries next to them. + */ + if (dcp_is_iboot(dcp)) { + /* Published for iboot_find_query()'s acquire. */ + smp_store_release(&service->cookie, query); + return; + } /* Remove the sysfs entry before cancelling work during device cleanup. */ ret = devm_device_add_group(dcp->dev, &iboot_query_group); if (ret) { @@ -741,6 +921,19 @@ static const struct apple_epic_service_ops external_ibootep_ops[] = { {} }; +/* DCP_FIRMWARE_IBOOT: the main DCP's service, or an external one's. */ +static const struct apple_epic_service_ops iboot_variant_ops[] = { + { + .name = "disp0-service", + .init = disp_service_init, + }, + { + .name = "dispext-service", + .init = disp_service_init, + }, + {} +}; + int ibootep_init(struct apple_dcp *dcp) { const struct apple_epic_service_ops *ops = ibootep_ops; @@ -751,6 +944,8 @@ int ibootep_init(struct apple_dcp *dcp) return -EBUSY; if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) ops = external_ibootep_ops; + if (dcp_is_iboot(dcp)) + ops = iboot_variant_ops; dcp->ibootep = afk_init(dcp, DISP0_ENDPOINT, ops); if (IS_ERR(dcp->ibootep)) { ret = PTR_ERR(dcp->ibootep); diff --git a/drivers/gpu/drm/apple/ibootep.h b/drivers/gpu/drm/apple/ibootep.h index aa44c2f8754e4..aa6ad17a61be1 100644 --- a/drivers/gpu/drm/apple/ibootep.h +++ b/drivers/gpu/drm/apple/ibootep.h @@ -27,4 +27,42 @@ int ibootep_rearm_pattern(struct apple_dcp *dcp); */ int ibootep_present_frame(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride); +/* + * The iBoot interface's display commands, for a DCP driven through it + * (DCP_FIRMWARE_IBOOT) and for the T6030 external role. Sleepable callers + * outside the AFK receive queue; the caller serializes them. + */ +struct iboot_timing_mode { + __le32 valid; + __le32 width; + __le32 height; + __le32 fps; /* 16.16 */ + /* byte 0 bit 6: a standard mode the firmware adds on its own */ + u8 flags[8]; +} __packed; + +struct iboot_color_mode { + __le32 valid; + __le32 colorimetry; + __le32 eotf; + __le32 encoding; + __le32 bpp; + u8 pad[4]; +} __packed; + +int ibootep_set_power(struct apple_dcp *dcp, bool on); +/* 1 with a sink, 0 without; the counts of its timing and colour modes. */ +int ibootep_get_hpd(struct apple_dcp *dcp, u32 *timings, u32 *colors); +/* The sink's mode lists, newly allocated; the caller frees them. */ +int ibootep_get_timing_modes(struct apple_dcp *dcp, + struct iboot_timing_mode **modes, + unsigned int *count); +int ibootep_get_color_modes(struct apple_dcp *dcp, + struct iboot_color_mode **modes, unsigned int *count); +int ibootep_set_mode(struct apple_dcp *dcp, const struct iboot_timing_mode *timing, + const struct iboot_color_mode *color); +/* SET_SURFACE: scan out one linear BGRA plane at @iova. */ +int ibootep_set_surface(struct apple_dcp *dcp, u64 iova, u32 width, u32 height, + u32 stride); + #endif diff --git a/drivers/gpu/drm/apple/version_utils.h b/drivers/gpu/drm/apple/version_utils.h index 8cf36e39d3f24..fe19968ee5f1e 100644 --- a/drivers/gpu/drm/apple/version_utils.h +++ b/drivers/gpu/drm/apple/version_utils.h @@ -62,6 +62,12 @@ enum dcp_firmware_version { */ DCP_FIRMWARE_V_26_6_DESKTOP, DCP_FIRMWARE_V_27_0, + /* + * A DCP driven through its firmware's iBoot interface alone + * (disp0-service, dispext-service; see ibootep.c), not through + * IOMFB: the T8152 one. + */ + DCP_FIRMWARE_IBOOT, }; #endif /*__APPLE_VERSION_UTILS_H__*/ From b623d3179bc3a162fcd67cf6717c5fb03c3b1172 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:48:46 +0100 Subject: [PATCH 081/121] drm/apple: add the interim T8152 DisplayPort hardware The T8152 (Mac mini J873g) DCPs drive their displays through hardware no subsystem driver covers yet: the rear USB-C ports' ATC PHYs have no DisplayPort mode in drivers/phy/apple/atc.c for T8152, the HDMI port's DisplayPort PHY has no T8152 type in drivers/phy/apple/dptx.c (its lanes are 0x2800 apart from 0x4500), the PS190 DisplayPort-to-HDMI converter behind it is powered through the SMC, the ports' ACE3 PD controllers do not report to the Type-C route layer, and the DCP firmware's iBoot interface does not hand out the sink's EDID. Add the T8152 code for them as separate files, each marked interim until atc.c's DisplayPort mode, tipd and the Type-C route layer take over. The bootloader trains the displays before Linux starts; the PHYs keep its setup and reprogram what a link training changes, as the DCP firmware calls into the AP for them. t8152_atc.c, the USB-C ports: - The three DCPs share the three rear ports through the one display crossbar. A DCP claims a free ATC under a mutex and gives it up on unplug; a monitor stays with its DCP while userspace blanks it. The crossbar's upstream reset, clock and enable fields are indexed by DCP endpoint * 2 + DPTX port, independently of the downstream DFP0 mux fields, which select that endpoint. - Each ATC has its own PMGR DP clock divider, at 0x300020044 + 8 * n. - The ATC's DP clock switch (PHY CFG block + 0x14 select, + 0x18 enable, + 0x1c status) chooses where each DP pixel clock comes from. PCLK1 is switched to PMGR DP clock 0 (select field 1, enable and status bit 1) after the divider for the link rate is written, and switched off the same way. With source 0 selected the stream clock never followed the divider: modes above about 165 MHz pixel clock, and 640x480, stayed black while the link trained and the firmware set the mode. - A monitor that also carries USB3 negotiates pin assignment D (data status bit 5): two DisplayPort lanes, and only the PMA that carries them is set up. GET_MAX_LANE_COUNT reports the route's lanes. - A cold start powers the ATC's dependencies (USB AON, the common PSD, both DP power states), the common block and AUX, and starts the lanes at HBR at once: from cold, AUX only works with the DP PLL and PMAs running. A power down undoes what it powered up. - The EDID is read through the AP AUX controller aux0, which the three DCPs share and take in turn; its output select for an ATC port is the ATC instance * 3 + its local DFP. t8152_hdmi.c, the HDMI port: - The bootloader wires the HDMI PHY (source select, APB 0x10) to the main DCP (0) when no USB-C display is attached at boot, and then never starts DCPEXT0; next to a USB-C display it wires DCPEXT0 (1). The source select is read only while the PHY's PMGR power state is requested and active: a USB-C-only boot leaves the PHY off, and a read of its registers then raises an SError. - When the bootloader left HDMI off (no monitor at boot leaves its PLL unlocked), the HDMI port becomes one of the shared ports. A DCP that drives no USB-C display takes it when the HPD line goes high, starts the PHY from cold (PMGR and PSD power, the PS190, source select, PLL, AUX and PHY power, the tunables, PLL and PHY activation, four lanes, impedance calibration), keeps the link up across display off, and gives the port back once the sink is gone. The source select takes every DCP's crossbar endpoint, DCPEXT1's 2 included, so DCPEXT1 takes the port while the other two drive USB-C monitors. The HPD line is requested once for all of them. - The PS190 is powered through the SMC when the port is set up, before anything reads HPD or an EDID: it drives the HPD line only while it is powered, and while it is off every AUX request on the USB-C ports ends with channel status 2 as well. Without the SMC bound yet, the setup is deferred. t8152_aux.c: the AUX controllers' request framing. Bits 21:8 of the retry register are a 14-bit reply timeout, set to 3200; read as a three-bit delay, the EDID through a USB-C to HDMI adapter timed out. A sink left in D3 is woken before DDC. t8152_pd.c: the ACE3 plug, orientation, DP alt mode and HPD state over SPMI, read through the logical register window under the SPMI device's lock, which the USB4 port monitor takes as well. A controller in power state 7 enters alt mode only after SSPS 0. A sink that stopped answering AUX after a monitor's deep sleep comes back after a reset (Gaid) and SSPS 0. t8152_dptx.c: the DPTX port service's calls into the AP apply link rate, lanes and drive settings to these PHYs and read the drive settings back as they were set; an unsupported GET_DRIVE_SETTINGS was followed by a firmware crash. The port's release is group 8 command 7, and its HPD call (group 8 command 8) carries a status in its reply's first word. dptxep.c serves the same calls for PHY framework PHYs, the crossbar mux and Thunderbolt tunnels; its connect and display request, its call numbers and its port records are used here. The HDMI PHY's power state check is based on a change by Acelogic. The files are built with the new DRM_APPLE_DCP_T8152, enabled in asahi.config, and nothing uses them yet. A MAINTAINERS entry for the T8152 display covers them and the binding. Signed-off-by: Thomas Glanzmann --- MAINTAINERS | 7 + arch/arm64/configs/asahi.config | 1 + drivers/gpu/drm/apple/Kconfig | 16 + drivers/gpu/drm/apple/Makefile | 2 + drivers/gpu/drm/apple/dcp-internal.h | 3 + drivers/gpu/drm/apple/t8152_atc.c | 924 ++++++++++++++++++++++++++ drivers/gpu/drm/apple/t8152_aux.c | 200 ++++++ drivers/gpu/drm/apple/t8152_display.h | 140 ++++ drivers/gpu/drm/apple/t8152_dptx.c | 315 +++++++++ drivers/gpu/drm/apple/t8152_hdmi.c | 669 +++++++++++++++++++ drivers/gpu/drm/apple/t8152_pd.c | 211 ++++++ 11 files changed, 2488 insertions(+) create mode 100644 drivers/gpu/drm/apple/t8152_atc.c create mode 100644 drivers/gpu/drm/apple/t8152_aux.c create mode 100644 drivers/gpu/drm/apple/t8152_display.h create mode 100644 drivers/gpu/drm/apple/t8152_dptx.c create mode 100644 drivers/gpu/drm/apple/t8152_hdmi.c create mode 100644 drivers/gpu/drm/apple/t8152_pd.c diff --git a/MAINTAINERS b/MAINTAINERS index cb48635b6e368..1afb033e7ffcd 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2151,6 +2151,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/t8152_* + APPLETALK NETWORK LAYER L: netdev@vger.kernel.org S: Obsolete diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 3173021d4f19d..ff74ba4c8dad6 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -88,6 +88,7 @@ CONFIG_DRM_ASAHI_M3_T8122=y CONFIG_DRM_ADP=m CONFIG_DRM_APPLE=m CONFIG_DRM_APPLE_DCP_T8132=y +CONFIG_DRM_APPLE_DCP_T8152=y CONFIG_DRM_APPLE_CEC=y CONFIG_DRM_APPLE_AUDIO=y CONFIG_DRM_APPLE_DCP_T6030_AUDIO=y diff --git a/drivers/gpu/drm/apple/Kconfig b/drivers/gpu/drm/apple/Kconfig index 99632ffe1535c..d27d975da6f41 100644 --- a/drivers/gpu/drm/apple/Kconfig +++ b/drivers/gpu/drm/apple/Kconfig @@ -75,6 +75,22 @@ config DRM_APPLE_DCP_T8132 Load appledrm explicitly before the GPU, with its alias autoload disabled, after guarded admission of the inherited display DARTs. +config DRM_APPLE_DCP_T8152 + bool "Mac mini M6 (J873g) displays" + depends on DRM_APPLE + depends on SPMI=y || SPMI=DRM_APPLE + depends on MFD_MACSMC=y || MFD_MACSMC=DRM_APPLE + help + Lets the common Apple display driver drive the three display + coprocessors of the T8152 Mac mini (J873g) through their firmware's + iBoot interface: the HDMI port, whose DisplayPort-to-HDMI converter + is powered through the SMC, and displays on the rear USB-C ports, + whose PD controllers are polled over SPMI. + + The boot loader hands each coprocessor over, running or quiesced, + with the AFK endpoints it left running. The adopted sessions cannot + be stopped; their DMA stays retained until reboot. + config DRM_APPLE_DEBUG bool "Enable additional driver debugging" depends on DRM_APPLE diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index a6687d7cccd65..3a0953cf6628a 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -18,6 +18,8 @@ appledrm-y += iomfb_v14_7_tpl.o appledrm-y += iomfb_v26_6_desktop.o appledrm-y += iomfb_v14_7.o iomfb_v14_7_link.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8132) += iomfb_m4.o t8132_ext_drm.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_atc.o t8152_aux.o t8152_dptx.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_pd.o appledrm-y += iomfb_h17p.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_external_hdr_hints_test.o diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 9618011b29c56..857ece5849156 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -462,6 +462,7 @@ struct dcp_desktop_state { /* TODO: move IOMFB members to its own struct */ struct dcpext_scanout; +struct t8152_display; struct dcp_hdmi; struct dcp_cec; @@ -584,6 +585,8 @@ struct apple_dcp { /* firmware version and compatible firmware version */ enum dcp_firmware_version fw_compat; + /* T8152: the DisplayPort hardware behind the DPTX port (t8152_display.h) */ + struct t8152_display *t8152; /* Bumped by every iomfb poweron; see afk_compact_slot(). */ u32 afk_power_gen; /* diff --git a/drivers/gpu/drm/apple/t8152_atc.c b/drivers/gpu/drm/apple/t8152_atc.c new file mode 100644 index 0000000000000..ce4b6a84602de --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_atc.c @@ -0,0 +1,924 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * T8152 (J873g) ATC PHYs as DisplayPort outputs of the DCPs' DPTX ports. + * + * Interim, until drivers/phy/apple/atc.c has a DisplayPort mode for T8152 + * and the display crossbar driver and the Type-C route layer of + * dcp-fabric.c take over the route and the choice of port: this programs + * the PHY's DisplayPort lanes, its pixel clock and the crossbar route + * itself. + * + * The bootloader trains a USB-C display before Linux starts; this takes + * that link over and then follows the firmware: link rate changes (stop and + * set up the lanes again), drive settings, the DCP -> ATCn/DFP0 crossbar + * route, and with the display off or unplugged a full power down and a cold + * start. A DCP drives one USB-C port at a time: the one it claims from the + * shared ports while polling their PD controllers. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dptxep.h" +#include "t8152_display.h" + +#define ATC_AON 0x1e00 +#define ATC_CFG 0x60000 +#define ATC_XBAR 0x74000 +/* + * The DP clock switch at CFG + 0x14 (select), + 0x18 (enable) and + 0x1c + * (status). 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. PCLK1 is used here, 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 t8152_atc_port { + void __iomem *base; + unsigned int index; /* ATC instance */ + /* display crossbar DFP endpoint of this ATC */ + u32 dfp; + struct spmi_device *pd; + /* AP DisplayPort AUX controller aux0 (shared), for the EDID */ + struct t8152_aux *aux; + /* PMGR power states of the four ATC dependencies */ + void __iomem *ps; + void __iomem *psd; + /* the dependencies this driver powered up, and may power down */ + u8 owned; + /* {offset, mask, value} tunables, before and after the lane setup */ + const __be32 *tunable[2]; + int tunable_len[2]; + /* 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 t8152_atc { + struct t8152_aux aux; + struct t8152_atc_port port[4]; + unsigned int nports; + /* the port the DCP drives, and the one a sink was found on */ + struct t8152_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 t8152_atc_port *atc_cur(struct t8152_display *disp) +{ + return ((struct t8152_atc *)disp->phy_priv)->cur; +} + +static const u32 atc_rates[] = { + LINK_RATE_RBR, LINK_RATE_HBR, LINK_RATE_HBR2, LINK_RATE_HBR3, +}; + +static bool atc_dp_pma(struct t8152_atc_port *atc, u32 pma) +{ + return atc->lanes == 4 || pma == !atc->swap; +} + +static bool atc_dp_register(struct t8152_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 t8152_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 t8152_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 t8152_display *disp, struct t8152_atc_port *atc) +{ + u32 ufp = disp->dp_source * 2; + u32 mask = BIT(ufp); + + if (!atc->route_started) + return 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); + /* + * 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, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x808, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x81c, 0x100, 0)) + dev_info(disp->dev, "ATC%u: no crossbar stop acknowledgment\n", atc->index); + 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, mask, mask); + atc_update(atc, ATC_XBAR + 0x1c, mask, mask); + atc_update(atc, ATC_XBAR + 0x34, 0x100, 0x100); + atc->route_started = false; + dev_dbg(disp->dev, "ATC%u: display route disabled\n", atc->index); + return 0; +} + +/* + * A source -> ATCn/DFP0 route, PCLK1: both DFP0 mux fields (0x44 bits 23:20 + * and 11:8) select the source. The 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_AUX0 9 /* UFP endpoint 5 (aux0) + 4 */ + +static int atc_route_start_sel(struct t8152_display *disp, + struct t8152_atc_port *atc, u32 sel) +{ + u32 ufp = disp->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, 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, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x818, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x82c, 0x100, 0)) { + dev_err(disp->dev, "ATC%u: crossbar reset acknowledgment timeout\n", + atc->index); + return -ETIMEDOUT; + } + 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, 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, mask, mask); + atc->route_started = true; + dev_dbg(disp->dev, "ATC%u: source %u to local DFP0 route configured\n", + atc->index, sel); + return 0; +} + +static int atc_route_start(struct t8152_display *disp, struct t8152_atc_port *atc) +{ + return atc_route_start_sel(disp, atc, disp->dp_source * 2); +} + +/* 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 t8152_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, pixel clock, then both PMAs. */ +static int atc_dp_stop(struct t8152_display *disp, struct t8152_atc_port *atc) +{ + u32 reg; + + atc_route_stop(disp, atc); + 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(disp->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. */ + 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)); + 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; +} + +/* DP lane setup at rate index r. */ +static int atc_dp_start(struct t8152_display *disp, struct t8152_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; + 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; + + 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)); + 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++) + 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); + } + 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(disp->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. + * With source 0 selected instead, the pixel clock does not follow the + * divider, and every mode above about 165 MHz stays black. + */ + 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(disp->dev, "ATC%u: DP pixel clock does not start\n", atc->index); + return -ETIMEDOUT; + } + ret = atc_route_start(disp, atc); + if (ret) + return ret; + atc->link_rate = atc_rates[r]; + dev_info(disp->dev, "ATC%u: %u-lane DPTX setup at rate %#x\n", atc->index, + atc->lanes, 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 t8152_atc_port *atc, u32 state) +{ + u32 reg; + + /* + * Only the state: the acknowledge bit 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 t8152_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 t8152_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, then the lanes at HBR. */ +static int atc_activate(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + void __iomem *cfg = atc->base + ATC_CFG; + unsigned int gates = 0; + u32 reg; + + if (READ_ONCE(atc_owner[atc->index]) != disp->dev) + return -EBUSY; + 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); + /* 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); + if ((readl(cfg) & 0x1f) != 0x1b) + goto fail; + /* AUX: release small and 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(disp->dev, "ATC%u: common PHY and AUX up from cold\n", atc->index); + /* + * 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(disp, atc, 1); +fail: + dev_err(disp->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, dependencies included. */ +static int atc_deactivate(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + void __iomem *cfg = atc->base + ATC_CFG; + int ret = 0; + u32 reg; + + if (!atc->active) + return 0; + if (atc->link_rate && atc_dp_stop(disp, atc)) { + dev_err(disp->dev, "ATC%u: DP stop failed\n", atc->index); + return -EIO; + } + atc_route_stop(disp, 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(disp->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(disp->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(disp->dev, "ATC%u: powered down: %d\n", atc->index, ret); + return ret; +} + +static int atc_set_link_rate(struct t8152_display *disp, u32 rate) +{ + struct t8152_atc_port *atc = atc_cur(disp); + 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(disp->dev, "ATC%u: link rate %#x, was %#x\n", atc->index, rate, + atc->link_rate); + if (atc->link_rate) { + ret = atc_dp_stop(disp, atc); + if (ret) + return ret; + } + return atc_dp_start(disp, atc, r); +} + +static int atc_set_route(struct t8152_display *disp, bool enable) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + if (!enable) + return atc_route_stop(disp, atc); + if (!atc->active) + return -ENODEV; + if (atc_route_start(disp, atc)) + return -EIO; + mdelay(5); + return 0; +} + +/* + * Lane drive presets, indexed by voltage * 4 + pre-emphasis; they serve + * every link 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 t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count) +{ + struct t8152_atc_port *atc = atc_cur(disp); + u32 presets[4]; + + if (!count) + return 0; + 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++) { + 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 t8152_display *disp, bool flipped) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + /* Applied by the next cold start; a running PHY keeps its own. */ + if (atc->active && atc->swap != flipped) + dev_warn(disp->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 t8152_display *disp) +{ + return atc_cur(disp)->lanes; +} + +/* + * 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 t8152_display *disp, u8 *buf, size_t size) +{ + struct t8152_atc_port *atc = atc_cur(disp); + bool was_started = atc->route_started; + int ret; + + if (!atc->active || !atc->aux->regs) + return -ENODEV; + mutex_lock(&atc_aux_lock); + /* The AUX output select of an ATC port: ATC instance * 3 + local DFP. */ + atc->aux->sel = atc->index * 3; + ret = t8152_aux_init(disp, atc->aux); + if (ret) + goto out; + atc_route_stop(disp, atc); + ret = atc_route_start_sel(disp, atc, ATC_SEL_AUX0); + if (!ret) + ret = t8152_aux_read_edid(disp, atc->aux, buf, size); + atc_route_stop(disp, atc); + if (was_started) + atc_route_start(disp, atc); +out: + mutex_unlock(&atc_aux_lock); + 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 t8152_display *disp, bool *flipped) +{ + struct t8152_atc *atc = disp->phy_priv; + int ret = 0; + + mutex_lock(&atc_owner_lock); + atc->next = atc->cur; + /* Keep a monitor on its controller, including while userspace blanks it. */ + if (atc_owner[atc->cur->index] == disp->dev) { + ret = t8152_pd_sink(atc->cur->pd, flipped, &atc->cur->next_lanes); + if (ret > 0 && (atc->cur->swap != *flipped || + atc->cur->lanes != atc->cur->next_lanes)) + disp->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 t8152_atc_port *port = &atc->port[i]; + + if (atc_owner[port->index] || + t8152_pd_sink(port->pd, flipped, &port->next_lanes) <= 0) + continue; + atc_owner[port->index] = disp->dev; + atc->next = port; + disp->hpd = 0; + ret = 1; + break; + } +out: + mutex_unlock(&atc_owner_lock); + return ret; +} + +/* + * 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 t8152_display *disp) +{ + struct t8152_atc *atc = disp->phy_priv; + struct t8152_atc_port *port = atc->next; + + if (!port || port == atc->cur) + return; + if (atc->cur->active && atc_deactivate(disp)) + return; + mutex_lock(&atc_owner_lock); + if (atc_owner[atc->cur->index] == disp->dev) + atc_owner[atc->cur->index] = NULL; + mutex_unlock(&atc_owner_lock); + dev_info(disp->dev, "USB-C display on ATC%u now, was ATC%u\n", + port->index, atc->cur->index); + atc->cur = port; + disp->pd = port->pd; + disp->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 t8152_atc_release(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + if (atc->active) + return false; + guard(mutex)(&atc_owner_lock); + if (atc_owner[atc->index] == disp->dev) + atc_owner[atc->index] = NULL; + return true; +} + +static const struct t8152_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, + .read_edid = atc_read_edid, + .detect = atc_detect, + .select = atc_select, + .max_link_rate = LINK_RATE_HBR2, +}; + +/* PMGR registers, inside blocks their power domain driver has claimed. */ +static void __iomem *atc_map(struct t8152_display *disp, 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(disp->dev, res.start, resource_size(&res)); +} + +static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, + struct device_node *np, void __iomem *dp_clock) +{ + struct t8152_atc_port *port = &atc->port[atc->nports]; + u32 cfg, r; + + port->base = atc_map(disp, np, "atc"); + port->ps = atc_map(disp, np, "atc-ps"); + port->psd = atc_map(disp, np, "atc-psd"); + if (!port->base || !port->ps || !port->psd) + return -ENOMEM; + port->pd = t8152_pd_get(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->lanes = 4; + 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]); + 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(disp->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) != + disp->dp_source * 2) + return 0; + /* Common block out of reset and AUX up, as the bootloader leaves it. */ + cfg = readl(port->base + ATC_CFG); + port->active = (cfg & 0x1f) == 0x1b; + if ((readl(port->base + 0x4c) & 0x1f) == 0x10 || + (readl(port->base + 0x4c) & 0x1f) == 0x11) { + port->lanes = 2; + port->next_lanes = 2; + } + port->swap = !!(readl(port->base + ATC_CFG + 8) & BIT(1)); + port->route_started = + (readl(port->base + ATC_XBAR) & BIT(disp->dp_source * 2)) && + (readl(port->base + ATC_XBAR + 0x3c) & BIT(disp->dp_source * 2)); + 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(disp->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 t8152_atc_init(struct t8152_display *disp) +{ + struct device_node *ports __free(device_node) = + of_parse_phandle(disp->dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: disp->dev->of_node; + struct resource clock_res; + void __iomem *dp_clock; + struct t8152_atc *atc; + int ret; + + atc = devm_kzalloc(disp->dev, sizeof(*atc), GFP_KERNEL); + if (!atc) + return -ENOMEM; + 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(disp->dev, clock_res.start, resource_size(&clock_res)); + if (!dp_clock) + return -ENOMEM; + /* Shared AUX0 is serialized by atc_aux_lock. */ + atc->aux.regs = atc_map(disp, np, "aux"); + atc->aux.ps = atc_map(disp, 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")) + continue; + if (atc->nports == ARRAY_SIZE(atc->port)) + break; + ret = atc_port_init(disp, atc, child, dp_clock); + if (ret) + return ret; + } + if (!atc->nports) { + ret = atc_port_init(disp, atc, np, dp_clock); + if (ret) + return ret; + } + + /* 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]; + atc_owner[atc->cur->index] = disp->dev; + break; + } + } + atc->next = atc->cur; + disp->phy = &atc_ops; + disp->phy_priv = atc; + disp->pd = atc->cur->pd; + disp->dcp_output = atc->cur->dfp; + dev_info(disp->dev, "USB-C display on ATC%u (%u ports)\n", atc->cur->index, + atc->nports); + return 0; +} diff --git a/drivers/gpu/drm/apple/t8152_aux.c b/drivers/gpu/drm/apple/t8152_aux.c new file mode 100644 index 0000000000000..8e2dbd2d2bd0c --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_aux.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The T8152 AP's DisplayPort AUX controllers aux0 and aux1: Analogix-derived + * DPTX cores with their own request framing. 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. + * + * Interim, until the DCP's DPAV service or a DRM DP AUX channel provides the + * EDID on T8152. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "t8152_display.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 t8152_aux_init(struct t8152_display *disp, struct t8152_aux *aux) +{ + u32 reg; + + /* PMGR power state of the controller */ + aux_update(aux->ps, 0xf, 0xf); + if (readl_poll_timeout(aux->ps, reg, ((reg >> 4) & 0xf) == 0xf, 1, + AUX_TIMEOUT_US)) { + dev_err(disp->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); + usleep_range(10, 20); + aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, 0); + /* + * Bits 21:8 of AUX_HW_RETRY are a 14-bit reply timeout, not Analogix's + * three-bit expected-delay field: the value 3 let native reads pass + * but timed out the EDID through a USB-C to HDMI adapter. 3200, with + * a retry interval of 3. + */ + 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; +} + +/* One AUX request of up to 16 bytes; returns the bytes transferred. */ +static int aux_xfer(struct t8152_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 t8152_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 t8152_aux_read_edid(struct t8152_display *disp, struct t8152_aux *aux, + u8 *buf, size_t size) +{ + u8 d0 = DP_SET_POWER_D0; + int ret = -EIO, ext; + + 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 controller named by np's "aux" and "aux-ps" regs (np need not be the + * DCP's own node); the PMGR register is mapped without claiming it. + */ +void t8152_aux_probe(struct t8152_display *disp, struct t8152_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(disp->dev, res.start, resource_size(&res)); + aux->regs = devm_of_iomap(disp->dev, np, regs, NULL); + if (IS_ERR(aux->regs) || !aux->ps) + aux->regs = NULL; +} diff --git a/drivers/gpu/drm/apple/t8152_display.h b/drivers/gpu/drm/apple/t8152_display.h new file mode 100644 index 0000000000000..b26baf6b04924 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_display.h @@ -0,0 +1,140 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * The T8152 (Mac mini J873g) DisplayPort hardware behind a DCP's DPTX port + * that no subsystem driver covers yet: the ATC PHYs' DisplayPort lanes and + * their display crossbar route (t8152_atc.c), the HDMI port's dedicated + * DisplayPort PHY and PS190 converter (t8152_hdmi.c), the AP's DisplayPort + * AUX controllers that read the sink's EDID (t8152_aux.c), the rear USB-C + * ports' ACE3 PD controllers (t8152_pd.c), and the DPTX port service the + * DCP firmware calls into for the PHY (t8152_dptx.c). + * + * Interim: the ATC DisplayPort mode moves to drivers/phy/apple/atc.c, the + * ACE3 controllers to tipd, and the choice of port with DP alt mode to the + * Type-C route layer of dcp-fabric.c, each in its own change. Until then + * these files program the registers themselves, for the iBoot interface + * DCPs of iomfb_iboot.c alone. + */ +#ifndef __APPLE_T8152_DISPLAY_H__ +#define __APPLE_T8152_DISPLAY_H__ + +#include + +struct apple_dcp; +struct apple_epic_service_ops; +struct device; +struct device_node; +struct gpio_desc; +struct spmi_device; +struct t8152_display; +struct t8152_hdmi; + +/* SET_DRIVE_SETTINGS and GET_DRIVE_SETTINGS records, one per lane */ +struct t8152_drive_settings { + __le32 format; + __le32 voltage; + __le32 pre_emphasis; +} __packed; + +/* The PHY behind the DCP's DPTX port; link rates in DPCD units. */ +struct t8152_phy_ops { + int (*activate)(struct t8152_display *disp); + int (*deactivate)(struct t8152_display *disp); + int (*set_link_rate)(struct t8152_display *disp, u32 rate); + /* optional */ + int (*set_lane_count)(struct t8152_display *disp, u32 lanes); + u32 (*max_lane_count)(struct t8152_display *disp); + int (*set_drive)(struct t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count); + int (*set_route)(struct t8152_display *disp, bool enable); + /* optional: plug orientation for the next activation */ + void (*set_orientation)(struct t8152_display *disp, bool flipped); + /* optional: the sink's EDID, returns its length */ + int (*read_edid)(struct t8152_display *disp, 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 t8152_display *disp, bool *flipped); + void (*select)(struct t8152_display *disp); + u32 max_link_rate; +}; + +/* The DPTX port state the firmware's calls set and read back. */ +struct t8152_port { + u32 link_rate; + u32 lanes; + /* the drive settings the firmware set last, for GET_DRIVE_SETTINGS */ + struct t8152_drive_settings drive[4]; + u32 drive_count; +}; + +/* An AP DisplayPort AUX controller, and its output select */ +struct t8152_aux { + void __iomem *regs; + void __iomem *ps; + u32 sel; +}; + +/* The DisplayPort side of one DCP */ +struct t8152_display { + struct apple_dcp *dcp; + struct device *dev; + /* display crossbar UFP endpoint of the DCP; DPTX port 0 */ + u32 dp_source; + /* display crossbar DFP endpoint the DCP drives */ + u32 dcp_output; + u32 die; + + const struct t8152_phy_ops *phy; + void *phy_priv; + /* optional sink HPD line (HDMI), polled; the last level seen */ + struct gpio_desc *hpd_gpio; + int hpd; + /* USB-C: the PD controller of the port in use */ + struct spmi_device *pd; + /* HDMI PHY: DCPEXT0's, or the main DCP's on an HDMI-only boot */ + 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 t8152_hdmi *hdmi_port; + bool on_hdmi; + const struct t8152_phy_ops *usbc_phy; + void *usbc_phy_priv; + u32 usbc_output; + + struct t8152_port port[2]; +}; + +/* t8152_atc.c */ +int t8152_atc_init(struct t8152_display *disp); +bool t8152_atc_release(struct t8152_display *disp); + +/* t8152_hdmi.c */ +struct device_node *t8152_hdmi_node(void); +int t8152_hdmi_source(struct device_node *np); +int t8152_hdmi_init(struct t8152_display *disp, struct device_node *np); +int t8152_hdmi_port_init(struct t8152_display *disp, struct device_node *np); +void t8152_hdmi_port_poll(struct t8152_display *disp); + +/* t8152_aux.c */ +void t8152_aux_probe(struct t8152_display *disp, struct t8152_aux *aux, + u32 sel, struct device_node *np); +int t8152_aux_init(struct t8152_display *disp, struct t8152_aux *aux); +int t8152_aux_read_edid(struct t8152_display *disp, struct t8152_aux *aux, + u8 *buf, size_t size); + +/* t8152_pd.c */ +struct spmi_device *t8152_pd_get(struct device_node *np); +int t8152_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes); +int t8152_pd_reconnect(struct t8152_display *disp); + +/* t8152_dptx.c */ +extern const struct apple_epic_service_ops t8152_dptx_port_ops; +int t8152_dptx_connect(struct t8152_display *disp, unsigned int port); +int t8152_dptx_disconnect(struct t8152_display *disp, unsigned int port); +int t8152_dptx_set_hpd(struct t8152_display *disp, unsigned int port, bool hpd); + +#endif diff --git a/drivers/gpu/drm/apple/t8152_dptx.c b/drivers/gpu/drm/apple/t8152_dptx.c new file mode 100644 index 0000000000000..14da33f3c7c3e --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_dptx.c @@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The DPTX port service of a T8152 iBoot interface DCP: the calls the + * firmware makes into the AP for the PHY behind its DPTX port, and the + * port's release and HPD calls. + * + * dptxep.c serves the same calls for the PHYs of the PHY framework, the + * display crossbar mux and Thunderbolt tunnels. The T8152 PHYs are + * programmed by t8152_atc.c and t8152_hdmi.c instead: their link rate, + * lanes and drive settings are applied here, and the drive settings are + * read back as they were set. The port's connect and display request are + * dptxep.c's. Interim, until the T8152 PHYs are PHY framework providers + * and dptxep.c can host this service. + */ + +#include +#include +#include + +#include "afk.h" +#include "dcp-internal.h" +#include "dptx-service.h" +#include "dptxep.h" +#include "t8152_display.h" + +/* IOReturn values the firmware takes as call status */ +#define KIO_RETURN_ERROR 0xe00002bcU +#define KIO_RETURN_BAD_ARG 0xe00002c2U +#define KIO_RETURN_UNSUPPORTED 0xe00002c7U +#define KIO_RETURN_NOT_READY 0xe00002d8U + +static bool dptx_needs_port(u32 command) +{ + switch (command) { + case DPTX_APCALL_ACTIVATE: + case DPTX_APCALL_DEACTIVATE: + case DPTX_APCALL_WILL_CHANGE_LINKG_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; + } +} + +/* + * One call; the IOReturn status. Requests carry their argument, replies + * their value, at offset 16. @reply holds a copy of the request. + */ +static u32 dptx_apcall(struct t8152_display *disp, struct t8152_port *port, + u16 group, u32 command, const void *data, size_t data_size, + void *reply, size_t reply_size) +{ + const struct t8152_phy_ops *phy = disp->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; + + if ((!port || !phy) && dptx_needs_port(command)) + return KIO_RETURN_NOT_READY; + + switch (command) { + case DPTX_APCALL_ACTIVATE: + if (phy->activate(disp)) + return KIO_RETURN_ERROR; + port->link_rate = LINK_RATE_HBR; + return 0; + case DPTX_APCALL_DEACTIVATE: + if (phy->deactivate(disp)) + return KIO_RETURN_ERROR; + port->link_rate = 0; + return 0; + case DPTX_APCALL_WILL_CHANGE_LINKG_CONFIG: + case DPTX_APCALL_DID_CHANGE_LINK_CONFIG: + return phy->set_route(disp, command == + DPTX_APCALL_DID_CHANGE_LINK_CONFIG) ? + KIO_RETURN_ERROR : 0; + case DPTX_APCALL_GET_MAX_LINK_RATE: + value = phy ? phy->max_link_rate : 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(disp, arg)) + return KIO_RETURN_ERROR; + port->link_rate = arg; + return 0; + case DPTX_APCALL_GET_MAX_LANE_COUNT: + value = phy && phy->max_lane_count ? phy->max_lane_count(disp) : 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(disp->dev, "DPTX: %u active lanes\n", arg); + if (phy->set_lane_count && phy->set_lane_count(disp, arg)) + return KIO_RETURN_ERROR; + port->lanes = arg; + return 0; + case DPTX_APCALL_GET_MAX_DRIVE_SETTINGS: { + const struct t8152_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 t8152_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(disp, 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; + 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 link is set up 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 zero status. */ + dev_info(disp->dev, "DPTX: firmware reports link fault %u\n", + command); + return 0; + case DPTX_APCALL_SET_TILED_DISPLAY_HINTS: + /* Acknowledged, the hints unused. */ + return 0; + default: + dev_info(disp->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; +} + +/* + * The reply starts as a copy of the request and carries the call's status + * in its first word; the transport status is always success. + */ +static int t8152_dptx_call(struct apple_epic_service *service, u16 group, + u32 command, const void *data, size_t size, + void *reply, size_t room) +{ + struct apple_dcp *dcp = service->ep->dcp; + struct dptx_port *dptx = service->cookie; + struct t8152_display *disp = READ_ONCE(dcp->t8152); + u32 status; + + dev_dbg(dcp->dev, "DPTX: port %d group %u command %u size %zu\n", + dptx ? (int)dptx->unit : -1, group, command, size); + memcpy(reply, data, min(room, size)); + if (disp) + status = dptx_apcall(disp, dptx ? &disp->port[dptx->unit] : NULL, + group, command, data, size, reply, room); + else + status = KIO_RETURN_NOT_READY; + if (status) + dev_dbg(dcp->dev, "DPTX: group %u command %u -> %#x\n", group, + command, status); + put_unaligned_le32(status, reply); + return 0; +} + +/* + * The ports in the order the firmware announces them. A further service is + * opened as well, without a port. + */ +static int t8152_dptx_prepare(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + struct apple_dcp *dcp = service->ep->dcp; + + for (unsigned int i = 0; i < ARRAY_SIZE(dcp->dptxport); i++) + if (!dcp->dptxport[i].service) + return dptx_service_bind(service, &dcp->dptxport[i], i); + return 0; +} + +static void t8152_dptx_init(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + if (service->cookie) + dptx_service_publish(service); +} + +/* Bound to every service of the DPTX endpoint (afk unmatched_ops). */ +const struct apple_epic_service_ops t8152_dptx_port_ops = { + .name = "dcpdptx-port", + .prepare = t8152_dptx_prepare, + .init = t8152_dptx_init, + .call_v2 = t8152_dptx_call, +}; + +static struct apple_epic_service *t8152_dptx_service(struct t8152_display *disp, + unsigned int port) +{ + struct dptx_port *dptx = &disp->dcp->dptxport[port]; + + return dptx_service_available(dptx) ? dptx->service : NULL; +} + +/* Connect the port to the PHY the DCP drives and request the display. */ +int t8152_dptx_connect(struct t8152_display *disp, unsigned int port) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + int ret; + + if (!service) + return -ENODEV; + ret = dptxport_connect(service, 0, disp->dcp_output, disp->die, true); + if (!ret) + ret = dptxport_request_display(service); + return ret; +} + +/* + * HPD as the port reports it to the firmware (group 8, command 8): the + * reply's first word is the call's status. + */ +int t8152_dptx_set_hpd(struct t8152_display *disp, unsigned int port, bool hpd) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + struct { + u8 pad[16]; + __le32 hpd; + } __packed cmd = { .hpd = cpu_to_le32(hpd) }, resp = {}; + size_t received; + int ret; + + if (!service) + return -ENODEV; + ret = afk_service_call_len(service, 8, 8, &cmd, sizeof(cmd), 12, &resp, + sizeof(resp), 12, &received); + if (ret) + return ret; + return get_unaligned_le32(resp.pad) ? -EIO : 0; +} + +/* Release the display (group 8, command 7), then HPD low. */ +int t8152_dptx_disconnect(struct t8152_display *disp, unsigned int port) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + __le32 status = 0; + size_t received; + int ret; + + if (!service) + return -ENODEV; + ret = afk_service_call_len(service, 8, 7, NULL, 0, 16, &status, + sizeof(status), 12, &received); + if (ret || status) + return ret ?: -EIO; + return t8152_dptx_set_hpd(disp, port, false); +} diff --git a/drivers/gpu/drm/apple/t8152_hdmi.c b/drivers/gpu/drm/apple/t8152_hdmi.c new file mode 100644 index 0000000000000..5b11879b1724b --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_hdmi.c @@ -0,0 +1,669 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The J873g HDMI port: the T8152's dedicated DisplayPort PHY in display + * crossbar 0's lpdptx slot, converted by a PS190. + * + * Interim, until drivers/phy/apple/dptx.c has a T8152 type (its lanes are + * 0x2800 apart from 0x4500) and the PS190's power through the SMC is + * described as a supply: this programs the PHY and powers the converter + * itself. + * + * 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, 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 "dptxep.h" +#include "t8152_display.h" + +#define HDMI_LANES 4 +#define HDMI_LANE0 0x4500 +#define HDMI_LANE_STRIDE 0x2800 + +struct t8152_hdmi { + void __iomem *core; + void __iomem *apb; + /* AP DisplayPort AUX controller aux1, for the EDID */ + struct t8152_aux aux; + /* The cold start of the HDMI port taken from the shared ports: */ + void __iomem *ps; /* PMGR power state of the PHY */ + void __iomem *psd; /* PMGR 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 + +/* APB 0x10 bits 3:0: the crossbar UFP feeding the PHY */ +#define HDMI_SOURCE_SELECT 0x10 +#define HDMI_SOURCE_AUX1 6 /* UFP endpoint of the aux1 controller */ + +static void hdmi_set_bits(struct t8152_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 t8152_hdmi *hdmi, u32 offset, u32 mask, + u32 value) +{ + u32 reg = readl(hdmi->apb + offset); + + writel((reg & ~mask) | value, hdmi->apb + offset); +} + +/* The PLL configuration words for each link rate (DPCD units). */ +static const struct { + u32 rate; + u32 w[22]; +} hdmi_pll_configs[] = { + { 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 } }, + { 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 } }, + { 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 } }, + { 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 } }, +}; + +/* A PLL command: command in 0x408[2:0], request bit 3, acknowledge bit 19. */ +static int hdmi_pll_command(struct t8152_display *disp, struct t8152_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++) { + usleep_range(16, 32); + 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(disp->dev, "HDMI: no ACK to PLL command %u\n", command); + return -ETIMEDOUT; + } + return 0; +} + +/* The lane-disable bits of each lane; 0x2420 holds the mask of unused lanes. */ +static void hdmi_set_lanes(struct t8152_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 t8152_display *disp) +{ + return 0; +} + +static int hdmi_deactivate(struct t8152_display *disp) +{ + dev_info(disp->dev, "HDMI: keeping the link up on deactivate\n"); + return 0; +} + +/* + * A new link rate: lanes off, PLL down, the PLL frequency, half link rate, + * PLL up again. + */ +static int hdmi_set_link_rate(struct t8152_display *disp, u32 rate) +{ + struct t8152_hdmi *hdmi = disp->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(disp->dev, "HDMI: link rate %#x\n", rate); + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 0); + ret = hdmi_pll_command(disp, hdmi, 0); + if (ret) + return ret; + + /* The PLL frequency, 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]); + + /* Latch the link rate dependent shadow registers (APB 0xa0). */ + 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 >= 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(disp, hdmi, 7); + if (ret) + return ret; + if (!(readl(hdmi->core + 0x438) & BIT(30))) { + dev_err(disp->dev, "HDMI: PLL failed to lock at rate %#x\n", rate); + return -EIO; + } + return 0; +} + +static int hdmi_set_lane_count(struct t8152_display *disp, u32 lanes) +{ + /* The PHY takes no zero lane count. */ + if (lanes) + hdmi_set_lanes(disp->phy_priv, lanes); + return 0; +} + +static int hdmi_set_drive(struct t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count) +{ + return 0; +} + +static int hdmi_set_route(struct t8152_display *disp, 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 t8152_display *disp, u8 *buf, size_t size) +{ + struct t8152_hdmi *hdmi = disp->phy_priv; + u32 src; + int ret; + + if (!hdmi->aux.regs) + return -ENODEV; + ret = t8152_aux_init(disp, &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 = t8152_aux_read_edid(disp, &hdmi->aux, buf, size); + writel(src, hdmi->apb + HDMI_SOURCE_SELECT); + return ret; +} + +static const struct t8152_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 = LINK_RATE_HBR3, +}; + +/* + * The PS190's power through the SMC: the {key, value} writes of + * apple,pcon-power. The PS190 drives the HDMI HPD line only while it is + * powered, and the AP AUX controller that reads the USB-C monitors' EDID + * gets no reply from any USB-C port while it is off. Nothing here waits + * for it to come up: a DCP takes the port only once it sees HPD + * (t8152_hdmi_port_poll()), and an EDID read retries until the AUX + * replies (t8152_aux_read_edid()). On a port taken over, these writes find + * the PS190 powered since probe. + */ +static int hdmi_pcon_power(struct t8152_display *disp, struct t8152_hdmi *hdmi) +{ + 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(disp->dev, "HDMI: PS190 power failed: %d\n", ret); + goto out; + } + } +out: + if (smc_pdev) + put_device(&smc_pdev->dev); + return ret; +} + +/* The PHY's PMGR and PSD power, then the PS190's. */ +static int hdmi_power_up(struct t8152_display *disp, struct t8152_hdmi *hdmi) +{ + int ret; + 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(disp->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(disp->dev, "HDMI: PHY PSD state stays %#x\n", val); + return ret; + } + } + return hdmi_pcon_power(disp, hdmi); +} + +/* The impedance calibration: wait for 0x1c04 bit 0, take 0x1c24 bits 12:6. */ +static void hdmi_impedance_calibration(struct t8152_display *disp, + struct t8152_hdmi *hdmi) +{ + u32 val; + + if (readl_poll_timeout(hdmi->core + 0x1c04, val, val & 1, 10, 1000000)) + dev_warn(disp->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); +} + +/* + * The cold start, as the bootloader does it: power, source select, PLL, AUX + * and PHY power, the 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 t8152_display *disp) +{ + struct t8152_hdmi *hdmi = disp->phy_priv; + int ret; + + if (hdmi->active) + return 0; + ret = hdmi_power_up(disp, hdmi); + if (ret) + return ret; + /* The source select: only the low nibble */ + hdmi_apb_update(hdmi, HDMI_SOURCE_SELECT, 0xf, disp->dp_source); + /* PLL, AUX and PHY power enables */ + 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); /* PLL on */ + hdmi_set_bits(hdmi, 0x1400, 0, 0x01, 0); /* AUX common control */ + hdmi_set_bits(hdmi, 0x1c00, 4, 0x3f0, 0x3c); /* PHY on */ + hdmi_set_bits(hdmi, 0x0000, 0, 0x01, 1); + usleep_range(1000, 2000); + hdmi_set_lanes(hdmi, HDMI_LANES); + hdmi_impedance_calibration(disp, hdmi); + hdmi->active = true; + dev_info(disp->dev, "HDMI: PHY up from cold, source %u\n", disp->dp_source); + return 0; +} + +static const struct t8152_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 = LINK_RATE_HBR3, +}; + +/* Registers shared with the other DCPs that may take the HDMI port. */ +static void __iomem *hdmi_ioremap(struct t8152_display *disp, + 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(disp->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 t8152_display *disp, + 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(disp->dev, hdmi_port_put, NULL); + return ret ? ERR_PTR(ret) : hpd; +} + +/* + * 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 t8152_hdmi_port_init(struct t8152_display *disp, struct device_node *np) +{ + struct t8152_hdmi *hdmi; + int ret; + + if (!of_property_present(np, "apple,pcon-power")) + return 0; + hdmi = devm_kzalloc(disp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_ioremap(disp, np, "phy-core"); + hdmi->apb = hdmi_ioremap(disp, np, "phy-apb"); + hdmi->ps = hdmi_ioremap(disp, np, "phy-ps"); + hdmi->psd = hdmi_ioremap(disp, np, "phy-psd"); + hdmi->aux.regs = hdmi_ioremap(disp, np, "aux"); + hdmi->aux.ps = hdmi_ioremap(disp, 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(disp->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(disp, hdmi); + if (ret) + return ret; + /* Every DCP that may take the port watches the same line. */ + hdmi->hpd = hdmi_port_get(disp, np); + if (IS_ERR(hdmi->hpd)) + return PTR_ERR(hdmi->hpd); + disp->hdmi_port = hdmi; + dev_info(disp->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 the display + * lock held. + */ +void t8152_hdmi_port_poll(struct t8152_display *disp) +{ + struct t8152_hdmi *hdmi = disp->hdmi_port; + int hpd; + + if (!hdmi) + return; + hpd = gpiod_get_value_cansleep(hdmi->hpd); + if (hpd < 0) + return; + guard(mutex)(&hdmi_port_lock); + if (disp->on_hdmi) { + if (hpd || disp->hpd) + return; + disp->phy = disp->usbc_phy; + disp->phy_priv = disp->usbc_phy_priv; + disp->dcp_output = disp->usbc_output; + disp->hpd_gpio = NULL; + disp->on_hdmi = false; + hdmi_port_owner = NULL; + dev_info(disp->dev, "HDMI: port given back\n"); + return; + } + if (!hpd || disp->hpd || hdmi_port_owner || !t8152_atc_release(disp)) + return; + hdmi_port_owner = disp->dev; + disp->usbc_phy = disp->phy; + disp->usbc_phy_priv = disp->phy_priv; + disp->usbc_output = disp->dcp_output; + disp->phy = &hdmi_port_ops; + disp->phy_priv = hdmi; + /* display crossbar DFP endpoint lpdptx */ + disp->dcp_output = 4; + disp->hpd_gpio = hdmi->hpd; + disp->on_hdmi = true; + dev_info(disp->dev, "HDMI: sink plugged, taking the HDMI port\n"); +} + +/* The DCP node that describes the HDMI PHY (DCPEXT0's). */ +struct device_node *t8152_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); +} + +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 (its source select: 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 PHY off or the PLL unlocked. + */ +int t8152_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; + + /* 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); + 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); + if (ret == 1 && !hdmi_power_active(np, "coproc-ps")) + return -ENODEV; + if (ret != 0 && ret != 1) + return -ENODEV; + return ret; +} + +/* The PHY, its AUX controller and its HPD line come from np. */ +int t8152_hdmi_init(struct t8152_display *disp, struct device_node *np) +{ + struct t8152_hdmi *hdmi; + + hdmi = devm_kzalloc(disp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_map(disp->dev, np, "phy-core"); + if (IS_ERR(hdmi->core)) + return PTR_ERR(hdmi->core); + hdmi->apb = hdmi_map(disp->dev, np, "phy-apb"); + if (IS_ERR(hdmi->apb)) + return PTR_ERR(hdmi->apb); + + /* AUX output select 0x10: the lpdptx PHY */ + t8152_aux_probe(disp, &hdmi->aux, 0x10, np); + + dev_info(disp->dev, "HDMI: inherited source select %u, PLL %slocked\n", + readl(hdmi->apb + HDMI_SOURCE_SELECT) & 0xf, + readl(hdmi->core + 0x438) & BIT(30) ? "" : "not "); + + disp->phy = &hdmi_ops; + disp->phy_priv = hdmi; + /* display crossbar DFP endpoint lpdptx */ + disp->dcp_output = 4; + return 0; +} diff --git a/drivers/gpu/drm/apple/t8152_pd.c b/drivers/gpu/drm/apple/t8152_pd.c new file mode 100644 index 0000000000000..8c514d17d69d2 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_pd.c @@ -0,0 +1,211 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * USB-C plug state from the rear ports' ACE3 PD controllers over SPMI, for + * the USB-C displays' hotplug: the DP alt mode connection, its pin + * assignment and the plug orientation. Logical registers are read through a + * window: select with a register-zero write, wait for the busy bit to + * clear, read the size at 0x1f and the data from 0x20. + * + * Interim, until tipd owns these controllers and reports DP alt mode to the + * Type-C route layer of dcp-fabric.c: tipd and this share the SPMI devices, + * serialized by the device lock. + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "t8152_display.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_POWER_STATE 0x20 +#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). A sink that stopped answering AUX after a + * monitor's deep sleep comes back this way. + */ +int t8152_pd_reconnect(struct t8152_display *disp) +{ + struct spmi_device *pd = disp->pd; + int ret; + + device_lock(&pd->dev); + /* Gaid resets the controller before it can report completion. */ + ret = spmi_command_wakeup(pd); + if (!ret) + ret = ace3_write(pd, ACE3_REG_CMD1, "Gaid", 4); + if (ret) + goto out; + /* + * The controller restarts: on the J873g ports its mode register read + * "BOOT" about 22 ms after Gaid, it acknowledged no SPMI command from + * about 215 ms on, and it read "APP " and took SSPS again after about + * 290 ms. Polling it through that gap only gets NACKs, which the SPMI + * controller logs as errors, and nothing signals the restart's end. + * So SSPS is first sent 500 ms after Gaid, and every 500 ms after that + * for a controller that takes longer. + */ + for (int i = 0; i < 60; i++) { + msleep(500); + ret = ace3_cmd(pd, "SSPS", 0); + if (!ret) + break; + } +out: + device_unlock(&pd->dev); + return ret; +} + +/* 1 with a DisplayPort sink in DP alt mode and HPD high, 0 without. */ +int t8152_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes) +{ + 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) + 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) + 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. */ + 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. */ +struct spmi_device *t8152_pd_get(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 (retained) device. */ + pd = spmi_find_device_by_of_node(pd_np); + of_node_put(pd_np); + return pd ?: ERR_PTR(-EPROBE_DEFER); +} From dfe1946a4c44798c0058d744e990967374513e06 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 07:21:03 +0100 Subject: [PATCH 082/121] drm/apple: wake AFK waiters when a service opens A caller that needs an endpoint's services, or the state one of their init callbacks sets up, can only poll for them. Give each endpoint a wait queue that is woken once a service has opened and its init callback has run, on each path that opens one: compact, AFKv2 and a deferred AFKv2 open. The host-test fixtures that build those paths get the wait queue too. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/afk.c | 3 +++ drivers/gpu/drm/apple/afk.h | 3 +++ tools/asahi/dcpext26-parity-tests.py | 3 ++- tools/asahi/dcpext26-startup-tests.py | 3 ++- tools/testing/selftests/drivers/gpu/apple-dcp/edid.py | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index ad684ae5e954b..75152de0a85dd 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -1024,6 +1024,7 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep, if (ops->init) ops->init(service, service_name, service_name, unit); + wake_up_all(&ep->service_wq); dev_info(ep->dcp->dev, "AFK[ep:%02x]: new compact service %s on interface %u%s\n", @@ -1713,6 +1714,7 @@ static void afk_retry_service_init(struct apple_dcp_afkep *ep) if (ops->init) ops->init(service, service->pending_name, service->pending_class, service->pending_unit); + wake_up_all(&ep->service_wq); if (service->enabled) afk_populate_service_debugfs(service); kfree(service->pending_name); @@ -1951,6 +1953,7 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, ops->init_props(service, epic_unit, props, props_size); if (ops->init) ops->init(service, epic_name, epic_class, epic_unit); + wake_up_all(&ep->service_wq); dev_info(ep->dcp->dev, "AFK[ep:%02x]: new service %s on channel %d\n", ep->endpoint, service_name, channel); diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index c01022b6b0f87..cf214e1eb1b68 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -587,6 +587,8 @@ struct apple_dcp_afkep { const struct apple_epic_service_ops *unmatched_ops; struct apple_epic_service services[AFK_MAX_CHANNEL]; u32 num_channels; + /* Woken once a service has opened and its init callback has run. */ + wait_queue_head_t service_wq; struct dentry *debugfs_entry; @@ -606,6 +608,7 @@ static inline void afk_ep_init_state(struct apple_dcp_afkep *ep) spin_lock_init(&ep->lock); INIT_LIST_HEAD(&ep->compact_cmds); init_waitqueue_head(&ep->compact_orphan_wq); + init_waitqueue_head(&ep->service_wq); mutex_init(&ep->compact_tx_lock); init_completion(&ep->started); init_completion(&ep->stopped); diff --git a/tools/asahi/dcpext26-parity-tests.py b/tools/asahi/dcpext26-parity-tests.py index 08e8fddb71e0f..bbdff169ae2e9 100644 --- a/tools/asahi/dcpext26-parity-tests.py +++ b/tools/asahi/dcpext26-parity-tests.py @@ -158,7 +158,8 @@ def run(name,code): struct apple_epic_service {bool pending_open,enabled;const struct apple_epic_service_ops *ops;const char *pending_name,*pending_class;int pending_unit;u32 channel;}; struct apple_dcp {bool ext26_services_open;struct apple_dcp_afkep *dptxep;}; static bool dptx_native_controllers_ready(struct apple_dcp *d){return true;} -struct apple_dcp_afkep {struct apple_dcp *dcp;unsigned num_channels;struct apple_epic_service services[2];}; +struct apple_dcp_afkep {struct apple_dcp *dcp;unsigned num_channels;struct apple_epic_service services[2];int service_wq;}; +#define wake_up_all(q) ((void)(q)) static bool dcp_is_ext26(struct apple_dcp *d){return true;} static unsigned sent,published,discarded,initialized;static int fault; static void afk_discard_pending_open(struct apple_epic_service *s){discarded++;s->pending_open=false;} diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index bc8a0aa89a992..98b984e597554 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -95,7 +95,8 @@ def run(name,code,reject=False): struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; -struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops,*unmatched_ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; +struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops,*unmatched_ops;struct apple_epic_service services[AFK_MAX_CHANNEL];int service_wq;}; +#define wake_up_all(q) ((void)(q)) static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} static bool dcp_is_v14_7_external(struct apple_dcp *d){return false;} diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index b4ea075b85f27..6898b7b368801 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -95,7 +95,8 @@ def function(file,signature): bool pending_open;const char *pending_name,*pending_class;s64 pending_unit; }; /* v27_closed_teardown: set only by a J714s firmware 27 sleep. */ -struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops,*unmatched_ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; +struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops,*unmatched_ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;int service_wq;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; +#define wake_up_all(q) ((void)(q)) struct apple_connector { void *dcp;bool connected,edid_invalidation_pending;struct { int registration_state; } base;unsigned int hotplug_wq; }; struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; From fb856df0a5ff7218112dd760185475e4ce98a10b Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:59:43 +0100 Subject: [PATCH 083/121] drm/apple: drive the T8152 DCPs through the iBoot interface The T8152 (Mac mini J873g) DCP firmware offers a small display service, disp0-service on the main DCP and dispext-service on the DCPEXTs, next to its IOMFB interface. The bootloader drives the J873g displays through it, with the DPTX port service that the firmware calls into the AP for the PHY and the DPAV controller services it expects to be opened, all over AFKv2. Add these DCPs to drm/apple as the DCP_FIRMWARE_IBOOT variant, matched by apple,t8152-dcp-iboot, with the shared AFK code and the iBoot commands of ibootep.c. The match data selects AFKv2 on every endpoint, endpoints registered with an RTKit session taken without its map, services matched by their announced name and a three-second AFK timeout. dcp_platform_probe() hands such a DCP to iomfb_iboot.c. Taking the session over: - A running session is adopted without the RTKit handshake (apple_rtkit_init_adopted(), apple_rtkit_adopt_running()): the DCP does not acknowledge AP QUIESCED, and an IOP INIT while its AP power is on panics it. A session the loader quiesced after a failed display setup (/chosen apple,dcp-rtkit-running = 0; the older J873 loader build v0.1.0-259-ga30a589a predates the property and is recognised by its 640x1136 placeholder framebuffer) is woken instead, and so is an unused DCPEXT the loader marks apple,rtkit-wake, once its PSD reads powered (a read of the coprocessor while it is gated hangs the machine) and its CPU runs. - The loader's AFK endpoint hand-off (apple,afk-active-endpoints) is required and fills dcp->afk_live_endpoints, so afk_start() stops each endpoint the loader left running: an AFK INIT on a live endpoint asserts in the firmware. Without the property there is no telling whether an endpoint is live, and the DCP is not taken over. - A woken DCPEXT'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, which only the firmware's retained DART tables map. With that buffer request failed, RTKit rejected the firmware's write counters as invalid instead of acknowledging them, which the firmware waits for before AP power transitions. The ring is taken as the firmware's, without a CPU mapping; the other buffers go through drm/apple's RTKit shared memory hooks. The surface log lines go to the debug level. - Once the session is taken it is retained until reboot like the other live sessions (dcp_retain_live_session(), split out of dcp_pin_live_session()). A failed start stops the endpoint work, detaches RTKit with its buffers kept and leaves the device bound, so nothing retries over a partly started session. Starting the display: - A new iBoot session has no surface, and a pipe that still runs then fetches from a null base (IOMFB axi_rd_err, firmware NMI): the display is powered off at once and powered on only after a SET_SURFACE. - The DPAV controller endpoint's four services are opened without a handler. Opening dcpav-video-interface starts the firmware's idle power off timer: a powered display without a following SET_MODE counts as idle, and the firmware takes the link down 30 s later, as it did with HDMI 30 s after boot while the compositor still had the output on. SET_MODE is sent again a second after that interface opens, from a work outside the AFK receive queues. - The DPTX port services are bound in the order they are announced. On USB-C the inherited DPTX link is released before the first connection. - The DCP fetches through dart-dcp and the display pipe scans out through dart-disp0; both are locked, with live roots of their own. One domain over both would publish dart-dcp's root into dart-disp0 and drop the bootloader's scanout mappings, so 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 below any range the firmware already maps there (a buffer mapped over one flickered). They are written through a write-combined mapping: the pipe does not snoop the CPU caches. - The bootloader's simple-framebuffer is taken over. KMS (iboot_drm.c), one DRM device per DCP: - Changing the surface between Linux buffers made later SET_MODEs crash the firmware. Three scanout buffers of at least 3840x2160 are allocated at probe; a frame's damage is copied by the CPU into one that is not on screen, which SET_SURFACE then shows, at most once per refresh by an hrtimer: there is no vblank interrupt, and several swaps within one refresh let an older frame stay on screen. The pitch is 64-byte aligned, as the firmware refuses an unaligned one. - The firmware takes a mode as width, height and a 16.16 refresh rate and picks the timing itself. The modes are the sink's EDID modes the firmware also lists, or the firmware's list with CVT timings. A DRM mode is matched to the firmware mode nearest by the exact refresh rate, within 1 Hz: next to an EIZO EV2780's 2560x1440@59.951 (241.5 MHz) the firmware lists a 60.000 Hz standard mode of its own (byte 0 bit 6), which it drives at 312.25 MHz and the monitor does not take. - The EDID is read through the AP's DisplayPort AUX controllers while the firmware does no AUX itself, since the iBoot interface does not hand it out. - A mode must fit the lanes the route may train, as GET_MAX_LANE_COUNT reports them, not those of the last training: a monitor that drops and reasserts HPD while the display is off is trained without a stream on a single lane, and 2560x1440@60 then failed the atomic check when the outputs came back on. - Right after power on the firmware still trains the link and fails SET_MODE; it takes the mode once the link is up, so SET_MODE is retried. The colour mode is the deepest valid one up to 32 bpp, as SET_MODE refuses the deeper ones the HDMI converter offers. - USB-C hotplug is polled from the PD controllers every 250 ms, HDMI from the converter's HPD line. An unplug releases DPTX and powers the PHY down, a sink that no longer answers after a monitor's deep sleep gets a fresh DP alt mode entry at most once a minute, and a quick reconnect restores a CRTC that was enabled. - drm/apple's per-DCP DRM device of dcpext_drm.c and dcpext_scanout.c does not fit: it is the T6030 external role's diagnostic, with one fixed 3840x2160 mode and the swap operations instead of SET_SURFACE. The DRM driver is named "apple-dcpib" (DCP iBoot interface), apart from the display subsystem's "apple"; appledrm.iboot_buffered=0 copies frames into the buffer on screen instead. Removal, shutdown and system sleep leave the firmware session alone. An unbind unplugs the DRM device, releases its committed state without touching the firmware, and detaches RTKit; the session stays retained, and a new bind is refused until reboot. The live endpoint hand-off and the retained failed start are based on changes by Acelogic. Tested on the J873g with HDMI and two rear USB-C monitors: all three come up, HDMI-A-1 at 2560x1440@59.951, DP-1 at 2560x1440@59.951 and DP-2 at 1920x1200@59.950. DPMS off and on works on each output, and so does HDMI at 1920x1080 and back. mpv runs fullscreen at 60 fps with no dropped frame after the first five. Unbinding DCPEXT1 removes its DRM device without a warning, and a new bind is refused with -EBUSY. Earlier runs of the same display code on the J873g: booted without HDMI, a monitor plugged in later is taken by a free DCP (DCPEXT0, and in another run DCPEXT1 with source select 2), which starts the PHY from cold and runs 2560x1440@60 at HBR3, DCPEXT0 within 0.6 s; with the bootloader's DCP start failing on purpose, HDMI and both USB-C monitors come up at their EDID modes; woken DCPEXTs log no buffer error. Signed-off-by: Thomas Glanzmann --- MAINTAINERS | 2 + drivers/gpu/drm/apple/Kconfig | 1 + drivers/gpu/drm/apple/Makefile | 1 + drivers/gpu/drm/apple/dcp-internal.h | 10 + drivers/gpu/drm/apple/dcp.c | 103 ++- drivers/gpu/drm/apple/iboot_drm.c | 1081 ++++++++++++++++++++++++++ drivers/gpu/drm/apple/iomfb_iboot.c | 840 ++++++++++++++++++++ drivers/gpu/drm/apple/iomfb_iboot.h | 139 ++++ 8 files changed, 2169 insertions(+), 8 deletions(-) create mode 100644 drivers/gpu/drm/apple/iboot_drm.c create mode 100644 drivers/gpu/drm/apple/iomfb_iboot.c create mode 100644 drivers/gpu/drm/apple/iomfb_iboot.h diff --git a/MAINTAINERS b/MAINTAINERS index 1afb033e7ffcd..8bd740eea9930 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2156,6 +2156,8 @@ 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/iboot_drm.c +F: drivers/gpu/drm/apple/iomfb_iboot.* F: drivers/gpu/drm/apple/t8152_* APPLETALK NETWORK LAYER diff --git a/drivers/gpu/drm/apple/Kconfig b/drivers/gpu/drm/apple/Kconfig index d27d975da6f41..876ebbd58605e 100644 --- a/drivers/gpu/drm/apple/Kconfig +++ b/drivers/gpu/drm/apple/Kconfig @@ -80,6 +80,7 @@ config DRM_APPLE_DCP_T8152 depends on DRM_APPLE depends on SPMI=y || SPMI=DRM_APPLE depends on MFD_MACSMC=y || MFD_MACSMC=DRM_APPLE + select APERTURE_HELPERS help Lets the common Apple display driver drive the three display coprocessors of the T8152 Mac mini (J873g) through their firmware's diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index 3a0953cf6628a..e6752d0f28516 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -20,6 +20,7 @@ appledrm-y += iomfb_v14_7.o iomfb_v14_7_link.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8132) += iomfb_m4.o t8132_ext_drm.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_atc.o t8152_aux.o t8152_dptx.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_pd.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += iomfb_iboot.o iboot_drm.o appledrm-y += iomfb_h17p.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_external_hdr_hints_test.o diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 857ece5849156..f55c05d9f1793 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -463,6 +463,7 @@ struct dcp_desktop_state { /* TODO: move IOMFB members to its own struct */ struct dcpext_scanout; struct t8152_display; +struct dcp_iboot; struct dcp_hdmi; struct dcp_cec; @@ -587,6 +588,8 @@ struct apple_dcp { enum dcp_firmware_version fw_compat; /* T8152: the DisplayPort hardware behind the DPTX port (t8152_display.h) */ struct t8152_display *t8152; + /* DCP_FIRMWARE_IBOOT: the display driven through it (iomfb_iboot.h) */ + struct dcp_iboot *iboot; /* Bumped by every iomfb poweron; see afk_compact_slot(). */ u32 afk_power_gen; /* @@ -1220,6 +1223,13 @@ static inline bool dcp_is_iboot(const struct apple_dcp *dcp) return dcp->fw_compat == DCP_FIRMWARE_IBOOT; } +struct apple_rtkit_shmem; +/* The common RTKit shared memory hooks, for a processor with its own RTKit ops. */ +int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr); +void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr); +/* Keep a session that cannot be stopped, its DMA and this driver until reboot. */ +int dcp_retain_live_session(struct apple_dcp *dcp); + /* T8132 firmware uses its own wire codec, with the common DRM/KMS owner. */ static inline bool iomfb_is_m4(const struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b16995083020d..396b62c988ecb 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -77,6 +77,7 @@ #include "dptx-service.h" #include "iomfb.h" #include "iomfb_internal.h" +#include "iomfb_iboot.h" #include "iomfb_m4.h" #include "ibootep.h" #include "iomfb_internal.h" @@ -114,15 +115,15 @@ static bool dcp_session_retained(struct device *dev) return retained; } -static int dcp_pin_live_session(struct apple_dcp *dcp) +/* + * Keep a live session's DMA device, domain use and this driver until reboot, + * and refuse a new probe of its device after an unbind. + */ +int dcp_retain_live_session(struct apple_dcp *dcp) { struct dcp_session_ref *session; - if ((!dcp->hw.adopt_live_session && - dcp->hw.iomfb_method_profile != - DCP_IOMFB_METHODS_H17P_EXTERNAL) || - !dcp_fail_stop(dcp) || - dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || dcp->retain_dma) + if (dcp->retain_dma) return 0; session = kzalloc_obj(*session); if (!session) @@ -143,6 +144,17 @@ static int dcp_pin_live_session(struct apple_dcp *dcp) return 0; } +static int dcp_pin_live_session(struct apple_dcp *dcp) +{ + if ((!dcp->hw.adopt_live_session && + dcp->hw.iomfb_method_profile != + DCP_IOMFB_METHODS_H17P_EXTERNAL) || + !dcp_fail_stop(dcp) || + dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || dcp->retain_dma) + return 0; + return dcp_retain_live_session(dcp); +} + static void dcp_release_dma_domain(void *data) { struct apple_dcp *dcp = data; @@ -1843,7 +1855,7 @@ static int dcp_check_iova_contiguous(struct iommu_domain *domain, return 0; } -static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) +int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; int ret; @@ -1904,7 +1916,7 @@ static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) return 0; } -static void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; @@ -7884,13 +7896,51 @@ static int dcp_platform_probe_t8132_ext(struct platform_device *pdev) * bind's, may still appear (bounded by the deferred probe timeout); on any * other failure join as an unusable pipe. */ +/* + * A DCP driven through the iBoot interface alone (DCP_FIRMWARE_IBOOT, + * iomfb_iboot.c): no component of a display subsystem, with a DRM device of + * its own. Its adopted session cannot be stopped: once the firmware is + * touched, its DMA and this driver stay until reboot, and a failed start + * leaves the device bound without a display. + */ +static int dcp_platform_probe_iboot(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct apple_dcp *dcp; + int ret; + + if (dcp_session_retained(dev)) + return dev_err_probe(dev, -EBUSY, "Previous live DCP session requires a reboot\n"); + dcp = kzalloc_obj(*dcp); + if (!dcp) + return -ENOMEM; + ret = devm_add_action_or_reset(dev, dcp_release_context, dcp); + if (ret) + return ret; + dcp->dev = dev; + dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); + dcp->fw_compat = dcp->hw.firmware_compat; + ret = iommu_device_use_default_domain(dev); + if (ret) + return ret; + ret = devm_add_action_or_reset(dev, dcp_release_dma_domain, dcp); + if (ret) + return ret; + platform_set_drvdata(pdev, dcp); + return dcp_iboot_probe(dcp); +} + static int dcp_platform_probe(struct platform_device *pdev) { + const struct apple_dcp_hw_data *hw = of_device_get_match_data(&pdev->dev); struct device *dev = &pdev->dev; struct apple_dcp *dcp; void *group; int ret; + if (hw->firmware_compat == DCP_FIRMWARE_IBOOT) + return dcp_platform_probe_iboot(pdev); + /* t6041_dcpext=0: stay off the external processors' hardware. */ if (of_device_is_compatible(dev->of_node, "apple,t6041-dcpext") && !t6041_dcpext) { @@ -7949,6 +7999,11 @@ static void dcp_platform_remove(struct platform_device *pdev) { struct apple_dcp *dcp = platform_get_drvdata(pdev); + /* No component and none of the works below; see dcp_iboot_remove(). */ + if (dcp && dcp_is_iboot(dcp)) { + dcp_iboot_remove(dcp); + return; + } if (dcp) { cancel_work_sync(&dcp->s2r_prewarm_work); cancel_delayed_work_sync(&dcp->s2r_prewarm_off_wq); @@ -8008,6 +8063,9 @@ VISIBLE_IF_KUNIT void dcp_platform_shutdown(struct platform_device *pdev) if (dcp_takeover_was_aborted(dcp)) return; + /* The iBoot interface's display stays as it is: no component to remove. */ + if (dcp && dcp_is_iboot(dcp)) + return; if (dcp && iomfb_is_m4(dcp)) { dcp_comp_unbind(&pdev->dev, NULL, NULL); @@ -8239,6 +8297,9 @@ static void dcp_platform_complete(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); + /* The iBoot interface's display stays powered across system sleep. */ + if (dcp_is_iboot(dcp)) + return; if (dcp_is_ext26(dcp)) { WRITE_ONCE(dcp->ext26_pm_preparing, false); if (dcp->ext26_pm_work_off && !READ_ONCE(dcp->ext26_blocked) && @@ -9724,6 +9785,9 @@ static int dcp_platform_suspend(struct device *dev) /* Its power sequences may crash the DCP and blank the panel. */ if (dcp_takeover_was_aborted(dcp)) return -EBUSY; + /* The iBoot interface's display stays powered across system sleep. */ + if (dcp_is_iboot(dcp)) + return 0; /* * An external DCP given up at probe may never have set up the works @@ -9877,6 +9941,8 @@ static int dcp_platform_resume(struct device *dev) if (dcp_takeover_was_aborted(dcp)) return 0; + if (dcp_is_iboot(dcp)) + return 0; if (dcp_v27_sleep_selected(dcp) && READ_ONCE(dcp->sleep_v27_closed)) return dcp_v27_sleep_resume(dcp); @@ -10113,8 +10179,29 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { .s2r_layout = &dcp_s2r_t8142_ext[0], }; +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) +/* + * T8152 (J873g): the DCP and both DCPEXTs, driven through the firmware's + * iBoot interface (disp0-service, dispext-service) over AFKv2, with the + * DPAV controller and DPTX port endpoints opened as the firmware expects + * them. The bootloader leaves each session running or quiesced; a running + * one is taken without the RTKit handshake. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8152_iboot = { + .num_dptx_ports = 2, + .firmware_compat = DCP_FIRMWARE_IBOOT, + .afk_v2 = true, + .afk_adopt_endpoints = true, + .afk_announced_names = true, + .afk_timeout_ms = 3000, +}; +#endif + static const struct of_device_id of_match[] = { { .compatible = "apple,t8142-dcpext", .data = &apple_dcp_hw_t8142_dcpext }, +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) + { .compatible = "apple,t8152-dcp-iboot", .data = &apple_dcp_hw_t8152_iboot }, +#endif { .compatible = "apple,t6041-dcp", .data = &apple_dcp_hw_t6041, }, { .compatible = "apple,t6041-dcpext", .data = &apple_dcp_hw_t6041_dcpext, }, { .compatible = "apple,t6050-dcp", .data = &apple_dcp_hw_t6050 }, diff --git a/drivers/gpu/drm/apple/iboot_drm.c b/drivers/gpu/drm/apple/iboot_drm.c new file mode 100644 index 0000000000000..c0b3bd2311962 --- /dev/null +++ b/drivers/gpu/drm/apple/iboot_drm.c @@ -0,0 +1,1081 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * KMS of a DCP driven through the iBoot interface (DCP_FIRMWARE_IBOOT): a DRM + * device of its own per DCP with one primary plane, CRTC, encoder and + * connector. The firmware only takes width, height and refresh rate for a + * mode and picks the timing itself; the modes come from the sink's EDID, or + * from the firmware's list built with CVT. + * + * Framebuffers are shadow buffers copied by the CPU into the scanout + * buffers, and a modeset only changes their geometry, as the bootloader + * does. Changing the surface address between Linux buffers made later + * modesets crash the firmware (IOMFB axi_rd_err), so the scanout buffers + * are the only surfaces the firmware gets. There is no vblank interrupt. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dcp-internal.h" +#include "ibootep.h" +#include "iomfb_iboot.h" +#include "t8152_display.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_named(iboot_buffered, buffered, bool, 0444); +MODULE_PARM_DESC(iboot_buffered, "iBoot interface displays: copy each frame into a scanout buffer that is not on screen (default: on)"); + +DEFINE_DRM_GEM_DMA_FOPS(dcp_iboot_fops); + +/* + * Not the display subsystem's "apple": these DCPs take no direct scanout, + * every frame is copied, so userspace must not treat them as that one. + */ +static const struct drm_driver dcp_iboot_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 = &dcp_iboot_fops, +}; + +struct dcp_iboot *dcp_iboot_alloc(struct device *dev) +{ + return devm_drm_dev_alloc(dev, &dcp_iboot_drm_driver, struct dcp_iboot, drm); +} + +const char *dcp_iboot_driver_name(void) +{ + return dcp_iboot_drm_driver.name; +} + +static const u32 dcp_iboot_formats[] = { + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, +}; + +static int iboot_refresh(const struct iboot_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); a mode + * beyond that only blanks the display. + */ +static bool iboot_mode_fits(struct dcp_iboot *ib, const struct iboot_timing_mode *t) +{ + const struct t8152_phy_ops *phy = ib->disp.phy; + /* + * 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 = (phy->max_lane_count ? phy->max_lane_count(&ib->disp) : 4) ?: 2; + u64 link = (u64)phy->max_link_rate * 270000000ULL * lanes * 8 / 10; + u64 pixels = (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) * + iboot_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) > + ib->scan[0].size) + return false; + return pixels * 24 * 112 / 100 <= link; +} + +/* @mode's refresh rate in 16.16, as drm_mode_vrefresh() computes it. */ +static u32 iboot_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 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 iboot_timing_mode * +iboot_find_mode(struct dcp_iboot *ib, const struct drm_display_mode *mode) +{ + const struct iboot_timing_mode *best = NULL; + u32 fps = iboot_mode_fps(mode); + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != mode->hdisplay || + le32_to_cpu(t->height) != mode->vdisplay || + abs_diff(le32_to_cpu(t->fps), fps) > 0x10000 || + !iboot_mode_fits(ib, t)) + continue; + if (!best || abs_diff(le32_to_cpu(t->fps), fps) < + abs_diff(le32_to_cpu(best->fps), fps)) + best = t; + } + return best; +} + +/* + * Valid, at most 32 bpp, the highest depth, then the lowest colorimetry, + * encoding and EOTF, as the bootloader chooses. Deeper modes the HDMI + * converter offers are refused by SET_MODE. + */ +static bool iboot_color_better(const struct iboot_color_mode *a, + const struct iboot_color_mode *b) +{ + u32 abpp = le32_to_cpu(a->bpp), bbpp = le32_to_cpu(b->bpp); + bool afits = abpp <= 32, bfits = bbpp <= 32; + + if (!!a->valid != !!b->valid) + return a->valid; + if (afits != bfits) + return afits; + 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 iboot_color_mode *iboot_find_color(struct dcp_iboot *ib) +{ + const struct iboot_color_mode *best = NULL; + + for (unsigned int i = 0; i < ib->nr_cmodes; i++) + if (!best || iboot_color_better(&ib->cmodes[i], best)) + best = &ib->cmodes[i]; + return best && best->valid ? best : NULL; +} + +/* + * A conservative console mode from 50 to 60 Hz, up to 1920x1080 on + * USB-C. Userspace can select the larger modes, including 2560x1440@60, + * after the sink's EDID is available. + */ +static const struct iboot_timing_mode *iboot_preferred(struct dcp_iboot *ib) +{ + const struct iboot_timing_mode *best = NULL; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + /* + * Byte 0 bit 6 marks standard modes a converter adds on its own + * (the J873g PS190 lists 3840x2160 for a 2560x1440 monitor); + * the bootloader's largest mode skips them too. + */ + if (!t->valid || iboot_refresh(t) > 60 || iboot_refresh(t) < 50 || + (t->flags[0] & 0x40) || + (!ib->disp.hdmi && (le32_to_cpu(t->width) > 1920 || + le32_to_cpu(t->height) > 1080)) || + !iboot_mode_fits(ib, 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 iboot_edid_get_modes(struct drm_connector *connector) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + struct drm_display_mode *mode, *best = NULL; + int count = drm_edid_connector_add_modes(connector); + + mutex_lock(&ib->lock); + list_for_each_entry(mode, &connector->probed_modes, head) { + mode->type &= ~DRM_MODE_TYPE_PREFERRED; + if (!iboot_find_mode(ib, 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(&ib->lock); + return count; +} + +static int iboot_connector_get_modes(struct drm_connector *connector) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + const struct iboot_timing_mode *preferred; + int count = 0; + + drm_edid_connector_update(connector, ib->edid); + if (ib->edid) + return iboot_edid_get_modes(connector); + + /* Without an EDID, the firmware's list. */ + mutex_lock(&ib->lock); + preferred = iboot_preferred(ib); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + struct drm_display_mode *mode; + + if (!t->valid || !iboot_mode_fits(ib, t)) + continue; + mode = drm_cvt_mode(connector->dev, le32_to_cpu(t->width), + le32_to_cpu(t->height), iboot_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(&ib->lock); + return count; +} + +static enum drm_mode_status +iboot_connector_mode_valid(struct drm_connector *connector, + const struct drm_display_mode *mode) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + + return iboot_find_mode(ib, mode) ? MODE_OK : MODE_NOMODE; +} + +static const struct drm_connector_helper_funcs iboot_connector_helper = { + .get_modes = iboot_connector_get_modes, + .mode_valid = iboot_connector_mode_valid, +}; + +static int iboot_set_mode_locked(struct dcp_iboot *ib, + const struct iboot_timing_mode *t, + const struct iboot_color_mode *c); + +/* With ib->lock held; queued work will observe the cleared pending slot. */ +static void iboot_cancel_swap_locked(struct dcp_iboot *ib) +{ + hrtimer_cancel(&ib->swap_timer); + ib->pending = -1; +} + +/* Read the sink's EDID through the PHY, if it can, and keep it. */ +void dcp_iboot_update_edid(struct dcp_iboot *ib) +{ + const struct drm_edid *edid = NULL; + u8 *buf; + int len; + + if (!ib->disp.phy->read_edid) + return; + buf = kzalloc(4 * EDID_LENGTH, GFP_KERNEL); + if (!buf) + return; + len = ib->disp.phy->read_edid(&ib->disp, 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(ib->dcp->dev, "no EDID: %d\n", len); + else + dev_info(ib->dcp->dev, "EDID: %d bytes\n", len); + drm_edid_free(ib->edid); + ib->edid = edid; + kfree(buf); +} + +static enum drm_connector_status +iboot_connector_detect(struct drm_connector *connector, bool force) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + struct t8152_display *disp = &ib->disp; + struct apple_dcp *dcp = ib->dcp; + enum drm_connector_status status; + bool flipped = false; + int hpd; + + mutex_lock(&ib->lock); + t8152_hdmi_port_poll(disp); + if (disp->hpd_gpio) { + hpd = gpiod_get_value_cansleep(disp->hpd_gpio); + } else if (disp->phy->detect) { + hpd = disp->phy->detect(disp, &flipped); + } else { + status = ib->nr_tmodes ? connector_status_connected : + connector_status_disconnected; + goto out; + } + if (hpd < 0) { + status = connector_status_unknown; + goto out; + } + if (hpd != disp->hpd) { + dev_info(dcp->dev, "sink %s\n", hpd ? "plugged" : "unplugged"); + disp->hpd = hpd; + /* + * USB-C: the DPTX port's HPD follows the PD controller, and a + * new plug may come the other way round. + */ + if (disp->pd) { + if (!hpd || ib->powered) { + iboot_cancel_swap_locked(ib); + if (t8152_dptx_disconnect(disp, 0)) + dev_err(dcp->dev, "DPTX release failed\n"); + if (!ibootep_set_power(dcp, false)) { + ib->powered = false; + ib->mode_set = false; + disp->phy->deactivate(disp); + } + } + /* + * 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) + disp->phy->deactivate(disp); + /* The sink may be on another port now. */ + if (hpd && disp->phy->select) + disp->phy->select(disp); + if (hpd && disp->phy->set_orientation) + disp->phy->set_orientation(disp, flipped); + /* The firmware talks AUX as soon as it sees HPD. */ + if (hpd && disp->phy->activate(disp)) + dev_err(dcp->dev, "PHY activation failed\n"); + if (hpd && t8152_dptx_connect(disp, 0)) + dev_err(dcp->dev, "DPTX connect failed\n"); + if (hpd && t8152_dptx_set_hpd(disp, 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 && (dcp_iboot_wait_hpd(ib) || dcp_iboot_get_modes(ib))) { + dev_err(dcp->dev, "no modes from the new sink\n"); + ib->nr_tmodes = 0; + ib->nr_cmodes = 0; + /* A sleeping EIZO may need a fresh DP alt mode entry. */ + if (disp->pd && !disp->on_hdmi && + time_after(jiffies, ib->pd_reset_time + 60 * HZ)) { + ib->pd_reset_time = jiffies; + schedule_work(&ib->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 && ib->nr_tmodes) + dcp_iboot_update_edid(ib); + /* + * A fast reconnect can finish before userspace disables the CRTC. + * Restore its requested state even though unplug powered it off. + */ + if (hpd && ib->enabled && ib->cur_mode.valid) { + const struct iboot_timing_mode *t = NULL; + const struct iboot_color_mode *c = iboot_find_color(ib); + int ret = 0; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *candidate = &ib->tmodes[i]; + + if (candidate->valid && candidate->width == ib->cur_mode.width && + candidate->height == ib->cur_mode.height && + candidate->fps == ib->cur_mode.fps) { + t = candidate; + break; + } + } + if (t && c && !ib->powered) { + ret = ibootep_set_surface(dcp, ib->scan_dva[ib->front], + le32_to_cpu(t->width), + le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (!ret) + ret = ibootep_set_power(dcp, true); + ib->powered = !ret; + } + if (t && c && !ret) + iboot_set_mode_locked(ib, t, c); + } + } + status = hpd && ib->nr_tmodes ? connector_status_connected : + connector_status_disconnected; +out: + mutex_unlock(&ib->lock); + return status; +} + +static const struct drm_connector_funcs iboot_connector_funcs = { + .detect = iboot_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 iboot_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 dcp_iboot *ib = to_dcp_iboot(plane->dev); + struct drm_crtc_state *crtc_state = NULL; + 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. */ + 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 <= ib->scan[0].size ? 0 : -EINVAL; +} + +static void iboot_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 iboot_period_ns(struct dcp_iboot *ib) +{ + u32 fps = le32_to_cpu(ib->cur_mode.fps); + + if (fps < (24 << 16)) + fps = 60 << 16; + return div64_u64((u64)NSEC_PER_SEC << 16, fps); +} + +/* Whether a frame may be shown: the display is on, set up and alive. */ +static bool iboot_scanning_locked(struct dcp_iboot *ib) +{ + struct apple_rtkit *rtk = READ_ONCE(ib->dcp->rtk); + + return ib->powered && ib->mode_set && ib->disp.hpd && rtk && + !apple_rtkit_is_crashed(rtk); +} + +/* Show scan[buf]. Called with ib->lock held. */ +static void iboot_swap_locked(struct dcp_iboot *ib, unsigned int buf, u32 w, + u32 h, u32 pitch) +{ + int ret; + + if (!iboot_scanning_locked(ib)) + return; + + /* The pipe must see the whole frame before it is swapped in. */ + wmb(); + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[buf], w, h, pitch); + if (ret) { + /* Still on the old buffer, which misses this frame. */ + dev_err_ratelimited(ib->dcp->dev, "swap failed: %d\n", ret); + ib->stale[ib->front] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + return; + } + ib->last_swap = ktime_get(); + ib->retired[ib->front] = ib->last_swap; + ib->front = buf; +} + +static void iboot_swap_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(work, struct dcp_iboot, swap_work); + + mutex_lock(&ib->lock); + if (ib->pending >= 0) { + iboot_swap_locked(ib, ib->pending, ib->pending_w, + ib->pending_h, ib->pending_pitch); + ib->pending = -1; + } + mutex_unlock(&ib->lock); +} + +static enum hrtimer_restart iboot_swap_timer(struct hrtimer *t) +{ + struct dcp_iboot *ib = container_of(t, struct dcp_iboot, swap_timer); + + queue_work(system_highpri_wq, &ib->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 iboot_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 dcp_iboot *ib = to_dcp_iboot(plane->dev); + struct drm_framebuffer *fb = new->fb; + struct drm_atomic_helper_damage_iter iter; + 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; + 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) { + if (!drm_rect_intersect(&clip, &src)) + continue; + drm_rect_translate(&clip, -src.x1, -src.y1); + iboot_rect_grow(&damage, &clip); + } + if (!drm_rect_visible(&damage)) + return; + + mutex_lock(&ib->lock); + if (!iboot_scanning_locked(ib)) + goto out; + period = iboot_period_ns(ib); + if (!READ_ONCE(buffered)) { + /* Into the buffer on screen (tears during motion). */ + back = ib->front; + } else if (ib->pending >= 0) { + back = ib->pending; + } else { + /* The other buffer that left the screen first. */ + unsigned int a = (ib->front + 1) % DCP_IBOOT_SCANOUT_BUFS; + unsigned int b = (ib->front + 2) % DCP_IBOOT_SCANOUT_BUFS; + s64 wait; + + back = ktime_before(ib->retired[a], ib->retired[b]) ? a : b; + /* Off screen for a full refresh: only after a mode change. */ + wait = period - ktime_to_ns(ktime_sub(ktime_get(), ib->retired[back])); + if (ib->mode_set && wait > 0) + usleep_range(div_s64(wait, NSEC_PER_USEC), + div_s64(wait, NSEC_PER_USEC) + 100); + } + clip = ib->stale[back]; + iboot_rect_grow(&clip, &damage); + if (drm_rect_intersect(&clip, &full)) { + iosys_map_set_vaddr(&dst, ib->scan_wc[back]); + iosys_map_incr(&dst, drm_fb_clip_offset(pitch, fb->format, &clip)); + source_clip = clip; + drm_rect_translate(&source_clip, src.x1, src.y1); + drm_fb_memcpy(&dst, &pitch, shadow->data, fb, &source_clip); + } + ib->stale[back] = (struct drm_rect){ 0, 0, 0, 0 }; + for (unsigned int i = 0; i < DCP_IBOOT_SCANOUT_BUFS; i++) + if (i != back) + iboot_rect_grow(&ib->stale[i], &damage); + if (back == ib->front) + goto out; + + since = ktime_to_ns(ktime_sub(ktime_get(), ib->last_swap)); + if (ib->pending < 0 && (!ib->mode_set || since >= period)) { + iboot_swap_locked(ib, back, drm_rect_width(&full), + drm_rect_height(&full), pitch); + goto out; + } + ib->pending_w = drm_rect_width(&full); + ib->pending_h = drm_rect_height(&full); + ib->pending_pitch = pitch; + if (ib->pending < 0) { + ib->pending = back; + hrtimer_start(&ib->swap_timer, ktime_add_ns(ib->last_swap, period), + HRTIMER_MODE_ABS); + } +out: + mutex_unlock(&ib->lock); +} + +static const struct drm_plane_helper_funcs iboot_plane_helper = { + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, + .atomic_check = iboot_plane_atomic_check, + .atomic_update = iboot_plane_atomic_update, +}; + +static const struct drm_plane_funcs iboot_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 iboot_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 dcp_iboot *ib = to_dcp_iboot(crtc->dev); + + /* No vblank interrupt: the helpers complete events after the flush. */ + new->no_vblank = true; + if (new->enable && !iboot_find_mode(ib, &new->mode)) + return -EINVAL; + return 0; +} + +/* SET_MODE, then the scanout buffer with the new mode's geometry. */ +static int iboot_set_mode_locked(struct dcp_iboot *ib, + const struct iboot_timing_mode *t, + const struct iboot_color_mode *c) +{ + int ret; + + /* + * Right after power on the firmware may still train the link, and it + * fails SET_MODE with an error status until the link is up. It sends + * no message once it is: the DPTX calls it makes while training (link + * configuration, rate, lane count) have no last one, and a sink can + * be trained twice in a row. So SET_MODE is retried. In the traced + * J873g modesets the link was up 76 to 229 ms after power on; one + * failed SET_MODE takes about 200 ms itself, so 200 ms between tries + * cover a second training, and five tries give up after about two + * seconds. On USB-C the DP alt mode reentry below takes over then. + */ + for (int i = 0; i < 5; i++) { + ret = ibootep_set_mode(ib->dcp, t, c); + if (ret != -EIO) + break; + msleep(200); + } + if (ret) { + dev_err(ib->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 (ib->disp.pd && !ib->disp.on_hdmi && + time_after(jiffies, ib->pd_reset_time + 60 * HZ)) { + ib->cur_mode = *t; + ib->mode_failed = true; + ib->pd_reset_time = jiffies; + schedule_work(&ib->pd_reset_work); + } + return ret; + } + ib->cur_mode = *t; + ib->mode_set = true; + ib->mode_failed = false; + /* The buffers hold the old geometry: the next frame is copied whole. */ + for (unsigned int i = 0; i < DCP_IBOOT_SCANOUT_BUFS; i++) + ib->stale[i] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + /* A pending frame has the old geometry. */ + iboot_cancel_swap_locked(ib); + /* As the bootloader swaps after a modeset. */ + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[ib->front], + le32_to_cpu(t->width), le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (ret) + dev_err(ib->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 dcp_iboot_set_boot_mode(struct dcp_iboot *ib) +{ + const struct iboot_timing_mode *best = NULL; + const struct iboot_color_mode *c; + int ret = -ENOENT; + + mutex_lock(&ib->lock); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != ib->boot_w || + le32_to_cpu(t->height) != ib->boot_h || + iboot_refresh(t) > 60) + continue; + if (!best || le32_to_cpu(t->fps) > le32_to_cpu(best->fps)) + best = t; + } + c = iboot_find_color(ib); + if (best && c) + ret = iboot_set_mode_locked(ib, best, c); + mutex_unlock(&ib->lock); + 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 dcp_iboot_reset_mode(struct dcp_iboot *ib) +{ + const struct iboot_color_mode *c; + + mutex_lock(&ib->lock); + c = iboot_find_color(ib); + if (c && ib->powered && ib->mode_set) + iboot_set_mode_locked(ib, &ib->cur_mode, c); + mutex_unlock(&ib->lock); +} + +/* + * From the AFK receive work of the DPAV endpoint: let the firmware finish + * opening the interface before the SET_MODE, which waits for a reply that + * another endpoint's receive work completes. + */ +void dcp_iboot_av_started(struct dcp_iboot *ib) +{ + queue_delayed_work(system_percpu_wq, &ib->av_work, msecs_to_jiffies(1000)); +} + +static void iboot_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 dcp_iboot *ib = to_dcp_iboot(crtc->dev); + struct apple_dcp *dcp = ib->dcp; + const struct iboot_timing_mode *t; + const struct iboot_color_mode *c; + int ret; + + mutex_lock(&ib->lock); + t = iboot_find_mode(ib, &new->mode); + c = iboot_find_color(ib); + if (!t || !c) + goto out; + ib->enabled = true; + if (!ib->powered) { + /* The PHY starts cold first; the firmware then trains. */ + ret = ib->disp.phy->activate(&ib->disp); + 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 = ibootep_set_surface(dcp, ib->scan_dva[ib->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 = ibootep_set_power(dcp, true); + if (ret) { + dev_err(dcp->dev, "set_power failed: %d\n", ret); + goto out; + } + ib->powered = true; + } + if (ib->mode_set && !memcmp(t, &ib->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), iboot_refresh(t)); + /* + * As the bootloader configures a display: 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 = ibootep_set_power(dcp, true); + if (!ret) + ret = ibootep_get_hpd(dcp, NULL, NULL) < 0; + if (!ret) + ret = dcp_iboot_get_modes(ib); + if (ret) + dev_err(dcp->dev, "refreshing the modes failed: %d\n", ret); + t = iboot_find_mode(ib, &new->mode); + c = iboot_find_color(ib); + if (!t || !c) + goto out; + iboot_set_mode_locked(ib, t, c); +out: + mutex_unlock(&ib->lock); +} + +static void iboot_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 dcp_iboot *ib = to_dcp_iboot(crtc->dev); + int ret, idx; + + /* A mode change: SET_MODE alone switches, as before. */ + if (new->active) + return; + /* + * After an unbind the firmware session is retained as it is, and the + * shutdown commit only releases the state. + */ + if (!drm_dev_enter(crtc->dev, &idx)) + 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(&ib->lock); + ib->enabled = false; + iboot_cancel_swap_locked(ib); + if (ib->powered) { + ret = ibootep_set_power(ib->dcp, false); + if (ret) { + dev_err(ib->dcp->dev, "set_power off failed: %d\n", ret); + } else { + dev_info(ib->dcp->dev, "display off\n"); + /* Nothing scans out: power the PHY down as well. */ + if (!ib->disp.phy->deactivate(&ib->disp)) + ib->disp.port[0].link_rate = 0; + } + ib->powered = !!ret; + ib->mode_set = false; + } + mutex_unlock(&ib->lock); + drm_dev_exit(idx); +} + +static const struct drm_crtc_helper_funcs iboot_crtc_helper = { + .atomic_check = iboot_crtc_atomic_check, + .atomic_enable = iboot_crtc_atomic_enable, + .atomic_disable = iboot_crtc_atomic_disable, +}; + +static const struct drm_crtc_funcs iboot_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 iboot_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 iboot_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; + +static const struct drm_mode_config_funcs iboot_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 iboot_pd_reset_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(work, struct dcp_iboot, pd_reset_work); + struct t8152_display *disp = &ib->disp; + int ret; + + dev_info(ib->dcp->dev, "USB-C sink does not answer, entering DP alt mode again\n"); + /* The reset may finish between polls. Release the old link explicitly. */ + mutex_lock(&ib->lock); + iboot_cancel_swap_locked(ib); + ret = t8152_dptx_disconnect(disp, 0); + if (!ret) + ret = ibootep_set_power(ib->dcp, false); + if (!ret) { + ib->powered = false; + ib->mode_set = false; + ret = disp->phy->deactivate(disp); + } + if (ret) { + mutex_unlock(&ib->lock); + dev_err(ib->dcp->dev, "cannot release old DP link: %d\n", ret); + return; + } + disp->hpd = 0; + ret = t8152_pd_reconnect(disp); + mutex_unlock(&ib->lock); + if (ret) { + dev_err(ib->dcp->dev, "DP alt mode entry failed: %d\n", ret); + return; + } + drm_kms_helper_hotplug_event(&ib->drm); +} + +static void iboot_hpd_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(to_delayed_work(work), struct dcp_iboot, + hpd_work); + + if (!READ_ONCE(ib->ready)) + return; + drm_helper_hpd_irq_event(&ib->drm); + if (READ_ONCE(ib->ready)) + queue_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(250)); +} + +void dcp_iboot_kms_stop(struct dcp_iboot *ib) +{ + if (!ib->kms_work_ready) + return; + + cancel_delayed_work_sync(&ib->hpd_work); + hrtimer_cancel(&ib->swap_timer); + cancel_work_sync(&ib->swap_work); + cancel_work_sync(&ib->pd_reset_work); +} + +static void iboot_swap_stop(void *data) +{ + dcp_iboot_kms_stop(data); +} + +int dcp_iboot_kms_init(struct dcp_iboot *ib) +{ + struct drm_device *drm = &ib->drm; + u32 max_w = 3840, max_h = 2160; + int ret; + + ib->pending = -1; + INIT_WORK(&ib->swap_work, iboot_swap_work); + INIT_WORK(&ib->pd_reset_work, iboot_pd_reset_work); + INIT_DELAYED_WORK(&ib->hpd_work, iboot_hpd_work); + hrtimer_setup(&ib->swap_timer, iboot_swap_timer, CLOCK_MONOTONIC, + HRTIMER_MODE_ABS); + ib->kms_work_ready = true; + ret = devm_add_action_or_reset(ib->dcp->dev, iboot_swap_stop, ib); + if (ret) + return ret; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + max_w = max(max_w, le32_to_cpu(ib->tmodes[i].width)); + max_h = max(max_h, le32_to_cpu(ib->tmodes[i].height)); + } + + ret = drmm_mode_config_init(drm); + if (ret) + return ret; + ib->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 = &iboot_mode_config_funcs; + drm->mode_config.helper_private = &iboot_mode_config_helpers; + + ret = drm_universal_plane_init(drm, &ib->plane, 0, &iboot_plane_funcs, + dcp_iboot_formats, ARRAY_SIZE(dcp_iboot_formats), + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ret; + drm_plane_helper_add(&ib->plane, &iboot_plane_helper); + drm_plane_enable_fb_damage_clips(&ib->plane); + + ret = drm_crtc_init_with_planes(drm, &ib->crtc, &ib->plane, NULL, + &iboot_crtc_funcs, NULL); + if (ret) + return ret; + drm_crtc_helper_add(&ib->crtc, &iboot_crtc_helper); + + ret = drm_encoder_init(drm, &ib->encoder, &iboot_encoder_funcs, + DRM_MODE_ENCODER_TMDS, NULL); + if (ret) + return ret; + ib->encoder.possible_crtcs = drm_crtc_mask(&ib->crtc); + + ret = drm_connector_init(drm, &ib->connector, &iboot_connector_funcs, + ib->disp.hdmi ? DRM_MODE_CONNECTOR_HDMIA : + DRM_MODE_CONNECTOR_DisplayPort); + if (ret) + return ret; + drm_connector_helper_add(&ib->connector, &iboot_connector_helper); + if (ib->disp.hpd_gpio || ib->disp.pd) + ib->connector.polled = DRM_CONNECTOR_POLL_CONNECT | + DRM_CONNECTOR_POLL_DISCONNECT; + if (ib->disp.pd) + ib->connector.polled = DRM_CONNECTOR_POLL_HPD; + ret = drm_connector_attach_encoder(&ib->connector, &ib->encoder); + if (ret) + return ret; + + drm_mode_config_reset(drm); + return 0; +} diff --git a/drivers/gpu/drm/apple/iomfb_iboot.c b/drivers/gpu/drm/apple/iomfb_iboot.c new file mode 100644 index 0000000000000..757b122dc8e42 --- /dev/null +++ b/drivers/gpu/drm/apple/iomfb_iboot.c @@ -0,0 +1,840 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * DCP_FIRMWARE_IBOOT: the T8152 DCPs, driven through their firmware's + * iBoot interface alone. + * + * The bootloader leaves a successful display's RTKit session running, or + * quiesces it after a failed setup, and leaves an unused DCPEXT's firmware + * loaded and waiting for an RTKit wake (apple,rtkit-wake). This adopts or + * wakes that session, stops the AFK endpoints the bootloader left running + * and starts the iBoot (disp0-service or dispext-service), DPAV and DPTX + * port endpoints, reconnects the DPTX port and asserts HPD, then registers + * a DRM device whose flips are iBoot SET_SURFACE calls (iboot_drm.c), in + * the order the bootloader brings the display up. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "afk.h" +#include "dcp.h" +#include "dcp-internal.h" +#include "ibootep.h" +#include "iomfb_iboot.h" +#include "t8152_display.h" + +#define DCP_IBOOT_HPD_TIMEOUT_MS 10000 +/* RTKit's oslog system endpoint */ +#define DCP_IBOOT_RTKIT_EP_OSLOG 8 +/* The coprocessor's CPU control (bit 4: run) and status registers */ +#define DCP_IBOOT_CPU_CONTROL 0x44 +#define DCP_IBOOT_CPU_CONTROL_RUN BIT(4) +#define DCP_IBOOT_CPU_STATUS 0x48 + +static void dcp_iboot_rtk_crashed(void *cookie, const void *crashlog, size_t size) +{ + struct apple_dcp *dcp = cookie; + + WRITE_ONCE(dcp->crashed, true); + dev_err(dcp->dev, "DCP firmware crashed\n"); +} + +static void dcp_iboot_rtk_recv(void *cookie, u8 endpoint, u64 message) +{ + struct apple_dcp *dcp = cookie; + struct apple_dcp_afkep *ep = NULL; + + if (READ_ONCE(dcp->quiescing)) + return; + switch (endpoint) { + case DISP0_ENDPOINT: + ep = READ_ONCE(dcp->ibootep); + break; + case DPTX_CONTROLLER_ENDPOINT: + ep = READ_ONCE(dcp->dptx_controller_ep); + break; + case DPTX_ENDPOINT: + ep = READ_ONCE(dcp->dptxep); + break; + } + if (IS_ERR_OR_NULL(ep)) { + dev_dbg(dcp->dev, "message %#llx for idle endpoint %#x\n", + message, endpoint); + return; + } + afk_receive_message(ep, message); +} + +/* + * Buffers the firmware placed in its own DART mappings, or new ones, as for + * every DCP; and a woken DCPEXT's oslog ring. + */ +static int dcp_iboot_rtk_shmem_setup(void *cookie, u8 endpoint, + struct apple_rtkit_shmem *bfr) +{ + struct apple_dcp *dcp = cookie; + + /* + * 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; + * the bootloader sends none either. + */ + if (bfr->iova && endpoint == DCP_IBOOT_RTKIT_EP_OSLOG) { + struct iommu_domain *domain = iommu_get_domain_for_dev(dcp->dev); + + if (domain && !iommu_iova_to_phys(domain, bfr->iova)) { + bfr->is_mapped = true; + return 0; + } + } + return dcp_rtk_shmem_setup(cookie, bfr); +} + +static void dcp_iboot_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +{ + /* The firmware's oslog ring, taken without a mapping */ + if (bfr->is_mapped && !bfr->buffer) + return; + dcp_rtk_shmem_destroy(cookie, bfr); +} + +static bool dcp_iboot_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 dcp_iboot_rtkit_ops = { + .crashed = dcp_iboot_rtk_crashed, + .recv_message = dcp_iboot_rtk_recv, + .shmem_setup_ep = dcp_iboot_rtk_shmem_setup, + .shmem_destroy = dcp_iboot_rtk_shmem_destroy, + .syslog_is_debug = dcp_iboot_rtk_syslog_debug, +}; + +static bool dcp_iboot_handoff_quiesced(struct dcp_iboot *ib) +{ + struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); + const char *version; + u32 running; + + if (ib->disp.hdmi || !chosen) + return false; + if (!of_property_read_u32(chosen, "apple,dcp-rtkit-running", &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 dcp_iboot_check_wake(struct apple_dcp *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 + DCP_IBOOT_CPU_CONTROL), + readl(coproc + DCP_IBOOT_CPU_STATUS)); + return (readl(coproc + DCP_IBOOT_CPU_CONTROL) & + DCP_IBOOT_CPU_CONTROL_RUN) ? 0 : -ENODEV; +} + +/* + * Wake only a quiesced session: IOP INIT on a running DCP can panic it. A + * running one is taken as it runs, without the HELLO/EPMAP handshake; + * its AFK endpoints are then registered as they start (hw.afk_adopt_endpoints). + */ +static int dcp_iboot_boot(struct dcp_iboot *ib) +{ + struct apple_dcp *dcp = ib->dcp; + bool wake = of_property_read_bool(dcp->dev->of_node, "apple,rtkit-wake"); + struct apple_rtkit *rtk; + int ret; + + if ((!ib->disp.hdmi && wake) || dcp_iboot_handoff_quiesced(ib)) { + if (wake) { + ret = dcp_iboot_check_wake(dcp); + if (ret) + return ret; + } + rtk = apple_rtkit_init(dcp->dev, dcp, NULL, 0, &dcp_iboot_rtkit_ops); + if (IS_ERR(rtk)) + return PTR_ERR(rtk); + dcp->rtk = rtk; + ret = apple_rtkit_wake(rtk); + dev_info(dcp->dev, "quiesced DCP wake: %d\n", ret); + return ret; + } + rtk = apple_rtkit_init_adopted(dcp->dev, dcp, NULL, 0, &dcp_iboot_rtkit_ops); + if (IS_ERR(rtk)) + return PTR_ERR(rtk); + dcp->rtk = rtk; + return apple_rtkit_adopt_running(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 dcp_iboot_scanout_init(struct dcp_iboot *ib) +{ + struct device *dev = ib->dcp->dev; + struct device_node *np __free(device_node) = + of_get_child_by_name(dev->of_node, "scanout"); + int ret; + + if (!np) + return -ENODEV; + ib->scanout = of_platform_device_create(np, NULL, dev); + if (!ib->scanout) + ib->scanout = of_find_device_by_node(np); + if (!ib->scanout) + return -ENODEV; + ret = dma_set_mask_and_coherent(&ib->scanout->dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + ret = of_dma_configure(&ib->scanout->dev, np, true); + if (ret) + return ret; + ib->scanout_dom = iommu_get_domain_for_dev(&ib->scanout->dev); + return ib->scanout_dom ? 0 : -ENODEV; +} + +/* Firmware-visible memory: never freed, the firmware may still use it. */ +static int dcp_iboot_dma_alloc(struct dcp_iboot *ib, struct dcp_iboot_dma *dma, + size_t size) +{ + dma->size = PAGE_ALIGN(size); + dma->cpu = dma_alloc_coherent(ib->dcp->dev, dma->size, &dma->iova, + GFP_KERNEL); + return dma->cpu ? 0 : -ENOMEM; +} + +static void *dcp_iboot_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 dcp_iboot_scan_free_dva(struct dcp_iboot *ib, 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(ib->scanout_dom, dva + off)) + break; + if (off == size) + return dva; + dev_info(ib->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 dcp_iboot_scan_alloc(struct dcp_iboot *ib, int i, size_t size) +{ + struct dcp_iboot_dma *fb = &ib->scan[i]; + struct sg_table sgt; + ssize_t mapped; + dma_addr_t dva; + int ret; + + ret = dcp_iboot_dma_alloc(ib, fb, size); + if (ret) + return ret; + ret = dma_get_sgtable(ib->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); + ib->scan_wc[i] = dcp_iboot_vmap_wc(&sgt); + if (!ib->scan_wc[i]) { + sg_free_table(&sgt); + return -ENOMEM; + } + memset(ib->scan_wc[i], 0, fb->size); + /* + * Cacheable, as the bootloader maps scanout buffers: the pipe faults on + * entries with the DART's no-cache bit (IOMFB axi_rd_err). + */ + dva = dcp_iboot_scan_free_dva(ib, fb->iova, fb->size); + if (!dva) { + sg_free_table(&sgt); + return -ENOSPC; + } + mapped = iommu_map_sgtable(ib->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; + ib->scan_dva[i] = dva; + dev_info(ib->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 dcp_iboot_boot_surface(struct dcp_iboot *ib) +{ + /* + * 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) = + ib->disp.dp_source ? + of_find_node_by_path("/") : of_node_get(chosen); + u32 width = 1280, height = 720, stride = 1280 * 4; + size_t size; + 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), + dcp_iboot_driver_name()); + if (ret) + dev_warn(ib->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. + * A monitor may first appear after probe, with a larger mode list. + */ + size = max_t(size_t, (size_t)stride * height, 3840 * 2160 * 4); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) + size = max_t(size_t, size, (size_t)le32_to_cpu(ib->tmodes[i].width) * + le32_to_cpu(ib->tmodes[i].height) * 4); + ib->boot_w = width; + ib->boot_h = height; + ib->boot_stride = stride; + for (int i = 0; i < ARRAY_SIZE(ib->scan); i++) { + ret = dcp_iboot_scan_alloc(ib, i, size); + if (ret) + return ret; + } + ib->front = 0; + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[0], width, height, stride); + dev_info(ib->dcp->dev, "boot surface %ux%u at %pad: %d\n", width, height, + &ib->scan_dva[0], ret); + return ret; +} + +/* Both mode lists of the current sink; a list is kept when its query fails. */ +int dcp_iboot_get_modes(struct dcp_iboot *ib) +{ + struct iboot_timing_mode *tmodes; + struct iboot_color_mode *cmodes; + unsigned int count; + int ret; + + ret = ibootep_get_timing_modes(ib->dcp, &tmodes, &count); + if (ret) + return ret; + kfree(ib->tmodes); + ib->tmodes = tmodes; + ib->nr_tmodes = count; + ret = ibootep_get_color_modes(ib->dcp, &cmodes, &count); + if (ret) + return ret; + kfree(ib->cmodes); + ib->cmodes = cmodes; + ib->nr_cmodes = count; + return 0; +} + +/* + * Wait until the firmware reports a sink with modes, as the bootloader does. + * Nothing on the iBoot interface announces the sink, so GET_HPD is asked + * every 100 ms; the J873g ports took 268 to 328 ms after power on. + */ +int dcp_iboot_wait_hpd(struct dcp_iboot *ib) +{ + unsigned long timeout = jiffies + msecs_to_jiffies(DCP_IBOOT_HPD_TIMEOUT_MS); + u32 timings = 0, colors = 0; + int hpd; + + do { + hpd = ibootep_get_hpd(ib->dcp, &timings, &colors); + if (hpd > 0 && timings && colors) { + dev_info(ib->dcp->dev, "sink: %u timing, %u color modes\n", + timings, colors); + return 0; + } + msleep(100); + } while (time_before(jiffies, timeout)); + + dev_err(ib->dcp->dev, "no sink (hpd %d, %u timing, %u color modes)\n", hpd, + timings, colors); + return hpd < 0 ? hpd : -ENODEV; +} + +static void dcp_iboot_av_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(to_delayed_work(work), struct dcp_iboot, + av_work); + + if (READ_ONCE(ib->ready)) + dcp_iboot_reset_mode(ib); +} + +/* + * The DPAV controller endpoint's services take no host commands, but the + * firmware expects all of them opened: its video interface powers the + * display on and starts its idle power off timer, so SET_MODE follows once + * that one is up. + */ +static void dcp_iboot_dpav_init(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + struct dcp_iboot *ib = READ_ONCE(service->ep->dcp->iboot); + + if (ib && name && strstr(name, "dcpav-video-interface")) + dcp_iboot_av_started(ib); +} + +static const struct apple_epic_service_ops dcp_iboot_dpav_ops = { + .name = "dcpav", + .reusable = true, + .init = dcp_iboot_dpav_init, +}; + +static unsigned int dcp_iboot_ep_services(struct apple_dcp_afkep *ep) +{ + unsigned int count = 0; + + for (unsigned int i = 0; i < AFK_MAX_CHANNEL; i++) + count += READ_ONCE(ep->services[i].enabled); + return count; +} + +/* + * The endpoint's services as it announces them, up to @expected within the + * AFK timeout; none is an error, fewer a warning. + */ +static int dcp_iboot_wait_services(struct apple_dcp *dcp, + struct apple_dcp_afkep *ep, unsigned int expected) +{ + unsigned int count; + + wait_event_timeout(ep->service_wq, dcp_iboot_ep_services(ep) >= expected, + msecs_to_jiffies(dcp->hw.afk_timeout_ms)); + count = dcp_iboot_ep_services(ep); + if (!count) { + dev_err(dcp->dev, "endpoint %#x announced no service\n", ep->endpoint); + return -ETIMEDOUT; + } + if (count < expected) + dev_warn(dcp->dev, "endpoint %#x: %u of %u services\n", ep->endpoint, + count, expected); + return 0; +} + +static int dcp_iboot_start_ep(struct apple_dcp *dcp, u32 endpoint, + struct apple_dcp_afkep **slot, + const struct apple_epic_service_ops *ops, + unsigned int expected) +{ + struct apple_dcp_afkep *ep = afk_init(dcp, endpoint, NULL); + int ret; + + if (IS_ERR(ep)) + return PTR_ERR(ep); + ep->unmatched_ops = ops; + WRITE_ONCE(*slot, ep); + ret = afk_start(ep); + if (ret) { + dev_err(dcp->dev, "endpoint %#x did not start: %d\n", endpoint, ret); + return ret; + } + return dcp_iboot_wait_services(dcp, ep, expected); +} + +/* The iBoot service is ready once its init callback has run. */ +static int dcp_iboot_start_iboot(struct apple_dcp *dcp) +{ + int ret; + + ret = ibootep_init(dcp); + if (ret) + return ret; + wait_event_timeout(dcp->ibootep->service_wq, ibootep_is_ready(dcp), + msecs_to_jiffies(dcp->hw.afk_timeout_ms)); + return ibootep_is_ready(dcp) ? 0 : -ENODEV; +} + +/* + * Once adopted, the DCP may still DMA into our buffers. Stop the host side: + * no more endpoint work or messages, no KMS work, and RTKit detached with + * its buffers retained. Firmware-visible storage stays allocated until + * reboot. + */ +static void dcp_iboot_detach(struct dcp_iboot *ib) +{ + struct apple_dcp *dcp = ib->dcp; + + WRITE_ONCE(ib->ready, false); + WRITE_ONCE(dcp->quiescing, true); + cancel_delayed_work_sync(&ib->av_work); + dcp_iboot_kms_stop(ib); + afk_quiesce(dcp->ibootep); + afk_quiesce(dcp->dptx_controller_ep); + afk_quiesce(dcp->dptxep); + if (!IS_ERR_OR_NULL(dcp->rtk)) + apple_rtkit_free_retaining_buffers(dcp->rtk); + WRITE_ONCE(dcp->rtk, NULL); +} + +static int dcp_iboot_start(struct dcp_iboot *ib) +{ + struct t8152_display *disp = &ib->disp; + struct apple_dcp *dcp = ib->dcp; + struct device *dev = dcp->dev; + bool sink = true; + int ret; + + ret = dcp_iboot_start_iboot(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 = ibootep_set_power(dcp, false); + if (ret) + return dev_err_probe(dev, ret, "display power off failed\n"); + ret = dcp_iboot_start_ep(dcp, DPTX_CONTROLLER_ENDPOINT, + &dcp->dptx_controller_ep, &dcp_iboot_dpav_ops, 4); + if (ret) + return dev_err_probe(dev, ret, "no DPAV controllers\n"); + ret = dcp_iboot_start_ep(dcp, DPTX_ENDPOINT, &dcp->dptxep, + &t8152_dptx_port_ops, 2); + if (ret) + return dev_err_probe(dev, ret, "no DPTX port service\n"); + if (disp->pd) { + ret = t8152_dptx_disconnect(disp, 0); + if (ret) + return dev_err_probe(dev, ret, "cannot release inherited DP link\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 (disp->pd) + sink = false; + if (sink) { + ret = t8152_dptx_connect(disp, 0); + if (ret) + return dev_err_probe(dev, ret, "DPTX connect failed\n"); + ret = t8152_dptx_set_hpd(disp, 0, true); + if (ret) + return dev_err_probe(dev, ret, "DPTX hotplug failed\n"); + ret = dcp_iboot_wait_hpd(ib); + if (ret) + return ret; + ret = dcp_iboot_get_modes(ib); + if (ret) + return dev_err_probe(dev, ret, "no modes\n"); + } + ret = dcp_iboot_boot_surface(ib); + 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; + } + disp->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. + */ + if (disp->phy->detect && disp->phy->set_orientation) { + bool flipped; + + if (disp->phy->detect(disp, &flipped) > 0) { + if (disp->phy->select) + disp->phy->select(disp); + disp->phy->set_orientation(disp, flipped); + } + } + ret = disp->phy->activate(disp); + if (ret) + return dev_err_probe(dev, ret, "PHY activation failed\n"); + /* While the display is still off and the firmware does no AUX. */ + dcp_iboot_update_edid(ib); + ret = ibootep_set_power(dcp, true); + if (ret) + return dev_err_probe(dev, ret, "set_power failed\n"); + ib->powered = true; + dev_info(dev, "%u timing modes, %u color modes\n", ib->nr_tmodes, + ib->nr_cmodes); + +register_kms: + ret = dcp_iboot_kms_init(ib); + if (ret) + return ret; + if (sink) { + ret = dcp_iboot_set_boot_mode(ib); + if (ret) + dev_warn(dev, "boot mode not set again: %d\n", ret); + } + ret = drm_dev_register(&ib->drm, 0); + if (ret) + return ret; + WRITE_ONCE(ib->ready, true); + if (disp->hpd_gpio || disp->pd) + drmm_kms_helper_poll_init(&ib->drm); + if (disp->pd) + queue_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(250)); + drm_client_setup(&ib->drm, NULL); + return 0; +} + +/* + * Without a USB-C display the bootloader drives HDMI from the main DCP + * (source 0) and never starts DCPEXT0. hdmi_np: DCPEXT0's node, which + * describes the HDMI PHY. + */ +int dcp_iboot_probe(struct apple_dcp *dcp) +{ + struct device *dev = dcp->dev; + struct device_node *hdmi_np __free(device_node) = t8152_hdmi_node(); + int source = hdmi_np ? t8152_hdmi_source(hdmi_np) : -ENODEV; + struct t8152_display *disp; + struct dcp_iboot *ib; + u32 live; + int ret; + + 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; + } + + /* + * The bootloader's AFK endpoint hand-off: without it there is no + * telling whether an endpoint is live, and an INIT on a live one + * asserts in the firmware. + */ + ret = of_property_read_u32(dev->of_node, "apple,afk-active-endpoints", &live); + if (ret || live & ~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; + + ib = dcp_iboot_alloc(dev); + if (IS_ERR(ib)) + return PTR_ERR(ib); + ib->dcp = dcp; + disp = &ib->disp; + disp->dcp = dcp; + disp->dev = dev; + disp->dp_source = dev->of_node == hdmi_np ? 1 : 0; + of_property_read_u32(dev->of_node, "apple,dp-source", &disp->dp_source); + if (disp->dp_source > 2) + return -EINVAL; + of_property_read_u32(dev->of_node, "apple,die", &disp->die); + dcp->afk_live_endpoints = live; + mutex_init(&ib->lock); + INIT_DELAYED_WORK(&ib->av_work, dcp_iboot_av_work); + + ret = dcp_iboot_scanout_init(ib); + if (ret) + return dev_err_probe(dev, ret, "no scanout DART stream\n"); + + disp->hdmi = source >= 0 && source == disp->dp_source; + if (disp->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. */ + disp->hpd_gpio = NULL; + if (disp->hdmi) + disp->hpd_gpio = devm_fwnode_gpiod_get(dev, of_fwnode_handle(hdmi_np), + "hpd", GPIOD_ASIS, "hpd"); + if (PTR_ERR(disp->hpd_gpio) == -ENOENT) + disp->hpd_gpio = NULL; + if (IS_ERR(disp->hpd_gpio)) + return dev_err_probe(dev, PTR_ERR(disp->hpd_gpio), "no HPD GPIO\n"); + disp->hpd = 0; + ret = disp->hdmi ? t8152_hdmi_init(disp, hdmi_np) : t8152_atc_init(disp); + 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 (!disp->hdmi && source < 0 && hdmi_np) { + ret = t8152_hdmi_port_init(disp, hdmi_np); + if (ret) + return dev_err_probe(dev, ret, "no shared HDMI port\n"); + } + + WRITE_ONCE(dcp->t8152, disp); + WRITE_ONCE(dcp->iboot, ib); + ret = dcp_iboot_boot(ib); + if (IS_ERR_OR_NULL(dcp->rtk)) { + dcp->rtk = NULL; + return dev_err_probe(dev, ret, "cannot adopt the DCP\n"); + } + /* + * From here on the DCP may DMA into what this driver gives it, and + * there is no safe way to stop it: retain the session until reboot. + */ + if (dcp_retain_live_session(dcp)) { + dev_warn(dev, "live session not recorded; its DMA stays allocated\n"); + WRITE_ONCE(dcp->retain_dma, true); + } + if (ret) + dev_err(dev, "cannot adopt the DCP: %d\n", ret); + else + ret = dcp_iboot_start(ib); + if (!ret) + return 0; + + /* + * Gate RX before draining endpoint work; keep RTKit available until + * every sender has stopped. Do not reclaim firmware-visible storage + * or let the driver core retry a partially started session. + */ + dcp_iboot_detach(ib); + dev_err(dev, "initialization failed (%d); live DMA resources retained until reboot\n", + ret); + return 0; +} + +/* An unbind: the DRM device goes, the firmware session and its DMA stay. */ +void dcp_iboot_remove(struct apple_dcp *dcp) +{ + struct dcp_iboot *ib = dcp->iboot; + bool registered; + + if (!ib) + return; + registered = READ_ONCE(ib->ready); + if (ib->drm.mode_config.poll_enabled) + drm_kms_helper_poll_disable(&ib->drm); + if (!READ_ONCE(dcp->quiescing)) + dcp_iboot_detach(ib); + if (registered) { + drm_dev_unplug(&ib->drm); + /* Drops the committed state's connector reference. */ + drm_atomic_helper_shutdown(&ib->drm); + } +} diff --git a/drivers/gpu/drm/apple/iomfb_iboot.h b/drivers/gpu/drm/apple/iomfb_iboot.h new file mode 100644 index 0000000000000..9c2268604b017 --- /dev/null +++ b/drivers/gpu/drm/apple/iomfb_iboot.h @@ -0,0 +1,139 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * DCP_FIRMWARE_IBOOT: a T8152 DCP driven through its firmware's iBoot + * interface alone, with a DRM device of its own (iomfb_iboot.c, iboot_drm.c). + */ +#ifndef __APPLE_IOMFB_IBOOT_H__ +#define __APPLE_IOMFB_IBOOT_H__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "ibootep.h" +#include "t8152_display.h" + +struct apple_dcp; +struct device; +struct drm_edid; +struct iommu_domain; +struct platform_device; + +struct dcp_iboot_dma { + void *cpu; + dma_addr_t iova; + size_t size; +}; + +/* + * Scanout buffers, 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 DCP_IBOOT_SCANOUT_BUFS 3 + +struct dcp_iboot { + struct drm_device drm; + struct apple_dcp *dcp; + struct t8152_display disp; + + /* The DRM device is registered and the session up. */ + bool ready; + bool kms_work_ready; + + /* The scanout DART's own device and domain (dcp_iboot_scanout_init()). */ + struct platform_device *scanout; + struct iommu_domain *scanout_dom; + struct dcp_iboot_dma scan[DCP_IBOOT_SCANOUT_BUFS]; + /* their pages write-combined: the pipe does not snoop the CPU caches */ + void *scan_wc[DCP_IBOOT_SCANOUT_BUFS]; + /* their addresses in the display pipe's DART */ + dma_addr_t scan_dva[DCP_IBOOT_SCANOUT_BUFS]; + /* scan[front] is on screen (or set as the surface at the next power on) */ + unsigned int front; + /* the part of the current picture scan[i] does not hold yet */ + struct drm_rect stale[DCP_IBOOT_SCANOUT_BUFS]; + /* when scan[i] stopped being the requested surface */ + ktime_t retired[DCP_IBOOT_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; + + /* the sink's EDID, read through the PHY (NULL if unavailable) */ + const struct drm_edid *edid; + + /* iBoot state below, under lock */ + struct mutex lock; + bool enabled; + bool powered; + struct iboot_timing_mode *tmodes; + unsigned int nr_tmodes; + struct iboot_color_mode *cmodes; + unsigned int nr_cmodes; + struct iboot_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; + /* + * The DPAV 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 delayed_work hpd_work; + + struct drm_plane plane; + struct drm_crtc crtc; + struct drm_encoder encoder; + struct drm_connector connector; +}; + +static inline struct dcp_iboot *to_dcp_iboot(struct drm_device *drm) +{ + return container_of(drm, struct dcp_iboot, drm); +} + +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) +/* iomfb_iboot.c */ +int dcp_iboot_probe(struct apple_dcp *dcp); +void dcp_iboot_remove(struct apple_dcp *dcp); +int dcp_iboot_wait_hpd(struct dcp_iboot *ib); +int dcp_iboot_get_modes(struct dcp_iboot *ib); + +/* iboot_drm.c */ +struct dcp_iboot *dcp_iboot_alloc(struct device *dev); +const char *dcp_iboot_driver_name(void); +int dcp_iboot_kms_init(struct dcp_iboot *ib); +void dcp_iboot_kms_stop(struct dcp_iboot *ib); +int dcp_iboot_set_boot_mode(struct dcp_iboot *ib); +void dcp_iboot_update_edid(struct dcp_iboot *ib); +void dcp_iboot_reset_mode(struct dcp_iboot *ib); +void dcp_iboot_av_started(struct dcp_iboot *ib); +#else +static inline int dcp_iboot_probe(struct apple_dcp *dcp) { return -ENODEV; } +static inline void dcp_iboot_remove(struct apple_dcp *dcp) { } +#endif + +#endif From 9528b6f22ad03001e6b261c145bac322d01d0c2b Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 10:07:11 +0100 Subject: [PATCH 084/121] 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 578e7730ef5f1..cab3001ab9086 100644 --- a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi @@ -123,17 +123,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"; @@ -148,17 +151,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 77e59b842a8f8da1c2f16e33ea509a45e5356cb9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 13 Nov 2026 10:08:50 +0100 Subject: [PATCH 085/121] 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 d6e5edf0790f2052f7386332f7a0497c285eac53 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 22:53:55 +0100 Subject: [PATCH 086/121] 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 bdf0e2c959c9c5da1bb5494d1d379c0ca85648b3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Wed, 18 Nov 2026 11:03:18 +0100 Subject: [PATCH 087/121] 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 the DCP driver 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 66408fe38790074dd49b19b9ad9c96fdd8602d0c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 22 Nov 2026 15:28:08 +0100 Subject: [PATCH 088/121] dt-bindings: display: apple,t8152-dcp-iboot: allow a power domain The display coprocessor has a power state of its own, which its DARTs follow. Allow the node to name it. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/display/apple,t8152-dcp-iboot.yaml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index 7c4e2b1db5ab9..6fbdaba2d17a4 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -188,6 +188,12 @@ properties: maxItems: 1 description: DCP DART stream + power-domains: + maxItems: 1 + description: + The coprocessor's power state, which its firmware runs; the DARTs + follow it. + scanout: type: object additionalProperties: false From 9ba42452969af56e2e6993c12b20215fe3fadc23 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 22 Nov 2026 15:28:08 +0100 Subject: [PATCH 089/121] arm64: dts: apple: t8152-j873g: power domains for the display DARTs Every enabled DART must name the power state of the engine it serves (scripts/dtc/apple-dart-pd-check.py). The six J873g display DARTs named none. Their engines are the display coprocessors, whose PMGR states are DISP_CPU (dcp), DISPEXT0_CPU (dcpext0) and DISPEXT1_CPU (dcpext1) in the 26A434 ADT. The AP does not switch those: a coprocessor is started through its PSD service (coproc-psd), and its firmware runs the state; Linux only reads DISPEXT0_CPU (coproc-ps). So they are described as firmware-owned: the OS keeps them on and never reads or writes them, which leaves the display hand-off and the HDMI cold start as they are. The coprocessor nodes name the same state as their DARTs. DISP_CPU sits at PMGR offset 0x14000 (it reads 0x0f0000ff on J873g, as DISPEXT0/1_CPU do), past the 0x14000 the PMGR node described, so the node now spans the ADT's 0x1c000 PMGR window. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 49 +++++++++++++++++++ .../arm64/boot/dts/apple/t8152-j873-qspi.dtsi | 3 +- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi index ebfae0dbbd1d0..8263f1c68634b 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -18,34 +18,80 @@ #include #include +/* + * The display coprocessors' PMGR power states (ADT pmgr devices DISP_CPU, + * DISPEXT0_CPU and DISPEXT1_CPU), which their DARTs follow. The PMGR does not + * switch them for the AP: the coprocessor is started through its PSD service + * (coproc-psd below) and its firmware runs the state, so Linux only reads + * DISPEXT0_CPU (coproc-ps). They are the firmware's: the OS keeps them on and + * never accesses them. + */ +&pmgr { + ps_dispext1_cpu: power-controller@aa0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xaa0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_cpu"; + apple,firmware-owned; + }; + + ps_dispext0_cpu: power-controller@e00 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xe00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_cpu"; + apple,firmware-owned; + }; + + ps_disp_cpu: power-controller@14000 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x14000 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_cpu"; + apple,firmware-owned; + }; +}; + &dcp_dart { apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_disp_cpu>; status = "okay"; }; &disp0_dart { apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_disp_cpu>; status = "okay"; }; &dcpext0_dart { apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext0_cpu>; status = "okay"; }; &dispext0_dart { apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext0_cpu>; status = "okay"; }; &dcpext1_dart { apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext1_cpu>; status = "okay"; }; &dispext1_dart { reg-names = "dart", "dapf"; apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext1_cpu>; status = "okay"; }; @@ -115,6 +161,7 @@ ranges; mboxes = <&dcp_mbox>; iommus = <&dcp_dart 23>; + power-domains = <&ps_disp_cpu>; /* * Cacheable DMA, as iBoot maps DCP buffers: the firmware * faults on entries with the DART's no-cache bit. @@ -472,6 +519,7 @@ "phy-ps", "coproc-ps", "coproc-psd", "phy-psd"; mboxes = <&dcpext_mbox>; iommus = <&dcpext0_dart 23>; + power-domains = <&ps_dispext0_cpu>; dma-coherent; apple,dp-source = <1>; apple,usb-c-ports = <&dcp_iboot>; @@ -534,6 +582,7 @@ reg-names = "coproc", "coproc-psd"; mboxes = <&dcpext1_mbox>; iommus = <&dcpext1_dart 23>; + power-domains = <&ps_dispext1_cpu>; dma-coherent; apple,dp-source = <2>; apple,usb-c-ports = <&dcp_iboot>; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi index c03fbf04b24e4..538511e3ffc17 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi @@ -25,7 +25,8 @@ "syscon", "simple-mfd"; #address-cells = <1>; #size-cells = <1>; - reg = <0x3 0x700000 0x0 0x14000>; + /* ADT pmgr reg[32]: power states up to DISP_CPU at 0x14000 */ + reg = <0x3 0x700000 0x0 0x1c000>; }; qspi: spi@331118000 { From 66094b3e7be6c1fdc28a29f2e21c55ddfcbd712b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 12 Nov 2026 18:09:54 -0600 Subject: [PATCH 090/121] spmi: apple: take interrupts on generation 4 controllers Generation 4 (t8142, t6050) had its interrupt refused at probe. macOS's trace (reported by Dj on the Aurora M5 Pro thread) acks peripheral sources 0..255 per bit in words from +0x600, with the controller fault source 263 at +0x620 bit 7. On K114c the PMIC RTC alarm sets +0x600 bit 2 (read-only probe, alarm armed 20 s out). Take the mask and ack bank offsets from the hw table (gen1 unchanged, shared with a host check in spmi-apple-irq.h). Generation 4 has no mask bank we could find (no word in 0x20..0x7f or 0x500..0x6ff toggles), so sources are masked in the cache only. Commands stay polled: the RX notification is not wired for gen 4. Tested: host check of the register math; compile only, not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 63 +++++++++++++++---------- drivers/spmi/spmi-apple-irq-host-test.c | 42 +++++++++++++++++ drivers/spmi/spmi-apple-irq.h | 37 +++++++++++++++ 3 files changed, 116 insertions(+), 26 deletions(-) create mode 100644 drivers/spmi/spmi-apple-irq-host-test.c create mode 100644 drivers/spmi/spmi-apple-irq.h diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index c5f8829cfeb45..7ecbf636dc16e 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -32,14 +32,14 @@ #include #include +#include "spmi-apple-irq.h" + /* SPMI Controller Registers */ #define SPMI_STATUS_REG 0 #define SPMI_CMD_REG 0x4 #define SPMI_RSP_REG 0x8 #define SPMI_ACT_REG 0xa4 -#define SPMI_IRQ_MASK_BASE 0x20 -#define SPMI_IRQ_ACK_BASE 0x60 /* * Peripheral interrupts come first. The RX FIFO notification sits right * after them, followed by the controller's own fault interrupts, so the @@ -61,8 +61,6 @@ * reply FIFO. macOS acks the controller's fault interrupt (source 263, after the 256 * peripheral sources; ack words from 0x600) and empties the queue when the controller starts. */ -#define SPMI_GEN4_IRQ_ACK_BASE 0x600 -#define SPMI_GEN4_FAULT_IRQ (SPMI_MAX_PERIPHERAL_IRQS + 7) #define SPMI_FAULT_QUEUE_MAX 64 /* More than the reply FIFO holds: the bound of a recovery's read-out. */ #define SPMI_GEN4_REPLY_DRAIN_MAX 64 @@ -77,6 +75,8 @@ struct apple_spmi_hw { u32 rx_empty; bool legacy_irqs; u32 num_irqs; + u32 irq_mask; + u32 irq_ack; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -86,6 +86,8 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ @@ -96,6 +98,8 @@ static const struct apple_spmi_hw apple_spmi_t6000 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 192, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; static const struct apple_spmi_hw apple_spmi_gen4 = { @@ -103,6 +107,9 @@ static const struct apple_spmi_hw apple_spmi_gen4 = { .command = 0x210, .reply = 0x220, .rx_empty = BIT(30), + .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN4_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN4_IRQ_ACK, }; struct apple_spmi { @@ -125,23 +132,26 @@ struct apple_spmi { static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_ack + (irq / 32) * 4; writel(BIT(irq % 32), reg); } static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - writel(readl(reg) & ~BIT(irq % 32), reg); + /* Generation 4 has no mask bank found: sources are masked in irq_mask_cache only. */ + if (spmi->hw->irq_mask) + writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - writel(readl(reg) | BIT(irq % 32), reg); + if (spmi->hw->irq_mask) + writel(readl(reg) | BIT(irq % 32), reg); } static void apple_spmi_irq_ack(struct irq_data *d) @@ -181,8 +191,8 @@ static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 param) /* Ack the fault interrupt, then pop and log every queued fault record */ static void apple_spmi_drain_faults(struct device *dev, struct apple_spmi *spmi) { - void __iomem *ack = spmi->regs + SPMI_GEN4_IRQ_ACK_BASE + (SPMI_GEN4_FAULT_IRQ / 32) * 4; - u32 bit = BIT(SPMI_GEN4_FAULT_IRQ % 32), fault; + void __iomem *ack = spmi->regs + APPLE_SPMI_GEN4_IRQ_ACK + (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * 4; + u32 bit = BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32), fault; int i; if (!spmi->faults) @@ -513,7 +523,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) unsigned long val, offset, bit; chained_irq_enter(chip, desc); - val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -522,14 +532,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ if (val & ~BIT(notify % 32)) { - writel(val & ~BIT(notify % 32), spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + writel(val & ~BIT(notify % 32), spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); handled = true; } for (offset = 0; offset < notify / 8; offset += sizeof(val)) { unsigned long stray; - val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset); + val = readq(spmi->regs + spmi->hw->irq_ack + offset); raw_pending |= !!val; /* * After a real sleep, sources no driver uses come up pending (on the Neo the @@ -540,8 +550,8 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; if (stray) { - writel(lower_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset); - writel(upper_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset + 4); + writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); + writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); handled = true; } if (val & spmi->irq_used[offset / sizeof(val)] & @@ -571,7 +581,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * unmasked, or it fires again for what was just cleared. */ if (handled) - readl(spmi->regs + SPMI_IRQ_ACK_BASE); + readl(spmi->regs + spmi->hw->irq_ack); chained_irq_exit(chip, desc); } @@ -580,7 +590,8 @@ static void apple_spmi_teardown_irq(void *data) struct apple_spmi *spmi = data; for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + if (spmi->hw->irq_mask) + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -600,8 +611,9 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); - writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); + if (spmi->hw->irq_mask) + writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); @@ -613,8 +625,10 @@ static int apple_spmi_init_irq(struct platform_device *pdev, return ret; irq_set_chained_handler_and_data(spmi->irq, apple_spmi_irq_handler, spmi); - apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); - spmi->notify_irq = true; + if (spmi->hw->legacy_irqs) { + apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); + spmi->notify_irq = true; + } return 0; } @@ -662,7 +676,7 @@ static int apple_spmi_resume_noirq(struct device *dev) if (pm_resume_via_firmware()) { bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); for (i = 0; i < spmi->hw->num_irqs / 32; i++) - writel(words[i], spmi->regs + SPMI_IRQ_MASK_BASE + i * 4); + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); } apple_spmi_irq_ack_raw(spmi, spmi->hw->num_irqs); apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); @@ -715,9 +729,6 @@ static int apple_spmi_probe(struct platform_device *pdev) if (spmi->irq < 0 && spmi->irq != -ENXIO) return spmi->irq; if (spmi->irq >= 0) { - if (!spmi->hw->legacy_irqs) - return dev_err_probe(&pdev->dev, -EOPNOTSUPP, - "Generation 4 interrupt layout is not supported\n"); ret = apple_spmi_init_irq(pdev, spmi, spmi->irq); if (ret) return ret; diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c new file mode 100644 index 0000000000000..89dbbacfedfb2 --- /dev/null +++ b/drivers/spmi/spmi-apple-irq-host-test.c @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Host check for the Apple SPMI interrupt register layout (not built by kbuild): + * cc -Wall -Werror -o /tmp/spmi-irq-test drivers/spmi/spmi-apple-irq-host-test.c && /tmp/spmi-irq-test + * + * The expected values are the layouts measured on hardware or traced from macOS: + * generation 1 (T8103/T6000): mask words from 0x20, ack/pending words from 0x60; + * generation 4 (T8142/T6050): ack/pending words from 0x600, source n in bit n % 32 + * of word n / 32, the controller's fault source 263 acked at 0x620 bit 7. + */ +#include +#include +#include + +typedef uint32_t u32; +#define BIT(n) (1U << (n)) + +#include "spmi-apple-irq.h" + +int main(void) +{ + /* generation 1 */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_MASK, 3) == 0x20); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 3) == 0x60); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 40) == 0x64); + assert(apple_spmi_irq_bit(40) == BIT(8)); + + /* generation 4: the PMU alarm source seen on K114c, the hpm2 wake bit macOS acks, the fault source */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 2) == 0x600); + assert(apple_spmi_irq_bit(2) == BIT(2)); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 19) == 0x600); + assert(apple_spmi_irq_bit(19) == BIT(19)); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); + assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); + /* no hardware mask bank for gen 4 */ + assert(APPLE_SPMI_GEN4_IRQ_MASK == 0); + /* the last peripheral source is in word 7 */ + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); + + puts("spmi-apple-irq host check: ok"); + return 0; +} diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h new file mode 100644 index 0000000000000..dce85d2d65ae2 --- /dev/null +++ b/drivers/spmi/spmi-apple-irq.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Apple SPMI controller interrupt register layout, shared with the host check + * (spmi-apple-irq-host-test.c). + * + * Peripheral sources 0..255 come first, then the RX FIFO notification (256) and + * the controller's own fault sources. Source n sits in bit n % 32 of word n / 32 + * of both the mask bank and the ack/pending bank. + */ +#ifndef _SPMI_APPLE_IRQ_H +#define _SPMI_APPLE_IRQ_H + +/* Generation 1 (T8103, T6000) */ +#define APPLE_SPMI_GEN1_IRQ_MASK 0x20 +#define APPLE_SPMI_GEN1_IRQ_ACK 0x60 + +/* + * Generation 4 (T8142, T6050): ack and pending words from 0x600, the fault source + * 263 acked at 0x620 bit 7 (traced from macOS under the hypervisor). The mask bank + * is not found; see APPLE_SPMI_GEN4_IRQ_MASK. + */ +#define APPLE_SPMI_GEN4_IRQ_ACK 0x600 +#define APPLE_SPMI_GEN4_FAULT_IRQ (256 + 7) +/* No mask bank found by toggling every word in 0x20..0x7f and 0x500..0x6ff (K114c): 0 = soft mask only */ +#define APPLE_SPMI_GEN4_IRQ_MASK 0 + +static inline u32 apple_spmi_irq_reg(u32 base, u32 irq) +{ + return base + (irq / 32) * 4; +} + +static inline u32 apple_spmi_irq_bit(u32 irq) +{ + return BIT(irq % 32); +} + +#endif /* _SPMI_APPLE_IRQ_H */ From 31dd41ec6fdc55967f0007f0e9f0aec31fe5303f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 13 Nov 2026 01:23:27 +0000 Subject: [PATCH 091/121] spmi: apple: use the generation 4 mask bank at +0x400 Probe on K114c: +0x400..0x41c toggle and restore (8 words), +0x420 does not, matching the +0x600 ack bank 0x200 above (Dj, seq 713, from write offsets in a macOS trace). The alarm latches +0x600 bit 2 once the PMIC alarm mask byte 0x200e is 0 (as rtc-macsmc writes it) and a write of 4 to +0x600 clears it (measured). Whether the +0x400 bit gates the AIC line is not measured. Drop the cache-only masking for gen 4. On a firmware resume re-apply the runtime mask, since a firmware sleep entry writes the mask bank itself. Host check extended; compile only, not booted. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 24 ++++++++++++++---------- drivers/spmi/spmi-apple-irq-host-test.c | 7 +++++-- drivers/spmi/spmi-apple-irq.h | 6 +++--- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 7ecbf636dc16e..a7f2e1b32d7ba 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -141,17 +141,14 @@ static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - /* Generation 4 has no mask bank found: sources are masked in irq_mask_cache only. */ - if (spmi->hw->irq_mask) - writel(readl(reg) & ~BIT(irq % 32), reg); + writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; - if (spmi->hw->irq_mask) - writel(readl(reg) | BIT(irq % 32), reg); + writel(readl(reg) | BIT(irq % 32), reg); } static void apple_spmi_irq_ack(struct irq_data *d) @@ -590,8 +587,7 @@ static void apple_spmi_teardown_irq(void *data) struct apple_spmi *spmi = data; for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - if (spmi->hw->irq_mask) - writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -611,8 +607,7 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - if (spmi->hw->irq_mask) - writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(0, spmi->regs + spmi->hw->irq_mask + offset); writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } @@ -667,8 +662,17 @@ static int apple_spmi_resume_noirq(struct device *dev) unsigned long flags; size_t i; - if (!spmi->notify_parked) + if (!spmi->notify_parked) { + /* Gen 4 never parks the notification, but a firmware sleep entry writes the mask bank itself. */ + if (spmi->hw->legacy_irqs || !spmi->irqd || !pm_resume_via_firmware()) + return 0; + raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); + bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); + for (i = 0; i < spmi->hw->num_irqs / 32; i++) + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags); return 0; + } guard(mutex)(&spmi->fifo_lock); raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c index 89dbbacfedfb2..5ab780d73bc05 100644 --- a/drivers/spmi/spmi-apple-irq-host-test.c +++ b/drivers/spmi/spmi-apple-irq-host-test.c @@ -32,8 +32,11 @@ int main(void) assert(apple_spmi_irq_bit(19) == BIT(19)); assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); - /* no hardware mask bank for gen 4 */ - assert(APPLE_SPMI_GEN4_IRQ_MASK == 0); + /* gen 4 mask bank (measured on K114c, Dj's HV trace writes +0x420), mirrors the ack bank */ + assert(APPLE_SPMI_GEN4_IRQ_MASK == 0x400); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 2) == 0x400); + assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 263) == 0x420); + assert(APPLE_SPMI_GEN4_IRQ_ACK - APPLE_SPMI_GEN4_IRQ_MASK == 0x200); /* the last peripheral source is in word 7 */ assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h index dce85d2d65ae2..d43dfa1c606cb 100644 --- a/drivers/spmi/spmi-apple-irq.h +++ b/drivers/spmi/spmi-apple-irq.h @@ -17,12 +17,12 @@ /* * Generation 4 (T8142, T6050): ack and pending words from 0x600, the fault source * 263 acked at 0x620 bit 7 (traced from macOS under the hypervisor). The mask bank - * is not found; see APPLE_SPMI_GEN4_IRQ_MASK. + * is at 0x400 (see APPLE_SPMI_GEN4_IRQ_MASK). */ #define APPLE_SPMI_GEN4_IRQ_ACK 0x600 #define APPLE_SPMI_GEN4_FAULT_IRQ (256 + 7) -/* No mask bank found by toggling every word in 0x20..0x7f and 0x500..0x6ff (K114c): 0 = soft mask only */ -#define APPLE_SPMI_GEN4_IRQ_MASK 0 +/* Mask bank mirrors the ack bank 0x200 below; +0x400..0x41c toggle on K114c, +0x420 does not. */ +#define APPLE_SPMI_GEN4_IRQ_MASK 0x400 static inline u32 apple_spmi_irq_reg(u32 base, u32 irq) { From ca24a4e63aafbfd07b3bc6b23427df3eaa2f2d6c Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 19 Nov 2026 12:07:56 -0600 Subject: [PATCH 092/121] spmi: apple: read the fault queue before the shared ack, limit gen4 mask writes Both open code points from review: The controller's fault source (263, word 0x620 bit 7 on gen4) shares its ack word with the notification word the handler reads first, and the stray-source path acked it directly: queued fault records were lost. Drain the queue before the bit is acked, in both the notification-word path and the readq stray path. gen4 has no notification source, and the word at +0x420 does not behave as a mask bank, so the init and teardown loops now write only the num_irqs / 32 mask words on gen4 (the legacy controllers keep the extra notification word). The host-test file is dropped: kbuild never built it and it checked constants against themselves. --- drivers/spmi/spmi-apple-controller.c | 27 +++++++++++++-- drivers/spmi/spmi-apple-irq-host-test.c | 45 ------------------------- drivers/spmi/spmi-apple-irq.h | 3 +- 3 files changed, 26 insertions(+), 49 deletions(-) delete mode 100644 drivers/spmi/spmi-apple-irq-host-test.c diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index a7f2e1b32d7ba..1237ac856ac55 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -116,6 +116,7 @@ struct apple_spmi { void __iomem *regs; void __iomem *faults; unsigned int nfaults; + struct device *dev; const struct apple_spmi_hw *hw; struct mutex fifo_lock; struct completion fifo_rx; @@ -521,6 +522,17 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) chained_irq_enter(chip, desc); val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); + /* + * On gen4 the controller's own fault source shares this last ack word + * (0x620, bit 7). Its queued records must be read before the source is + * acked, or drain_faults() never sees them. + */ + if (!spmi->hw->legacy_irqs && spmi->faults && + (val & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { + apple_spmi_drain_faults(spmi->dev, spmi); + val &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); + handled = true; + } raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -546,6 +558,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; + if (stray && !spmi->hw->legacy_irqs && spmi->faults && + offset == (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * sizeof(val) && + (stray & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { + /* Same rule as above: read the queued records first. */ + apple_spmi_drain_faults(spmi->dev, spmi); + stray &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); + handled = true; + } if (stray) { writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); @@ -586,7 +606,8 @@ static void apple_spmi_teardown_irq(void *data) { struct apple_spmi *spmi = data; - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); @@ -606,7 +627,8 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) { writel(0, spmi->regs + spmi->hw->irq_mask + offset); writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } @@ -705,6 +727,7 @@ static int apple_spmi_probe(struct platform_device *pdev) return -ENOMEM; spmi = spmi_controller_get_drvdata(ctrl); + spmi->dev = &pdev->dev; spmi->hw = device_get_match_data(&pdev->dev); if (!spmi->hw) return -EINVAL; diff --git a/drivers/spmi/spmi-apple-irq-host-test.c b/drivers/spmi/spmi-apple-irq-host-test.c deleted file mode 100644 index 5ab780d73bc05..0000000000000 --- a/drivers/spmi/spmi-apple-irq-host-test.c +++ /dev/null @@ -1,45 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Host check for the Apple SPMI interrupt register layout (not built by kbuild): - * cc -Wall -Werror -o /tmp/spmi-irq-test drivers/spmi/spmi-apple-irq-host-test.c && /tmp/spmi-irq-test - * - * The expected values are the layouts measured on hardware or traced from macOS: - * generation 1 (T8103/T6000): mask words from 0x20, ack/pending words from 0x60; - * generation 4 (T8142/T6050): ack/pending words from 0x600, source n in bit n % 32 - * of word n / 32, the controller's fault source 263 acked at 0x620 bit 7. - */ -#include -#include -#include - -typedef uint32_t u32; -#define BIT(n) (1U << (n)) - -#include "spmi-apple-irq.h" - -int main(void) -{ - /* generation 1 */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_MASK, 3) == 0x20); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 3) == 0x60); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN1_IRQ_ACK, 40) == 0x64); - assert(apple_spmi_irq_bit(40) == BIT(8)); - - /* generation 4: the PMU alarm source seen on K114c, the hpm2 wake bit macOS acks, the fault source */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 2) == 0x600); - assert(apple_spmi_irq_bit(2) == BIT(2)); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 19) == 0x600); - assert(apple_spmi_irq_bit(19) == BIT(19)); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, APPLE_SPMI_GEN4_FAULT_IRQ) == 0x620); - assert(apple_spmi_irq_bit(APPLE_SPMI_GEN4_FAULT_IRQ) == BIT(7)); - /* gen 4 mask bank (measured on K114c, Dj's HV trace writes +0x420), mirrors the ack bank */ - assert(APPLE_SPMI_GEN4_IRQ_MASK == 0x400); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 2) == 0x400); - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_MASK, 263) == 0x420); - assert(APPLE_SPMI_GEN4_IRQ_ACK - APPLE_SPMI_GEN4_IRQ_MASK == 0x200); - /* the last peripheral source is in word 7 */ - assert(apple_spmi_irq_reg(APPLE_SPMI_GEN4_IRQ_ACK, 255) == 0x61c); - - puts("spmi-apple-irq host check: ok"); - return 0; -} diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h index d43dfa1c606cb..4134ef37ff369 100644 --- a/drivers/spmi/spmi-apple-irq.h +++ b/drivers/spmi/spmi-apple-irq.h @@ -1,7 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ /* - * Apple SPMI controller interrupt register layout, shared with the host check - * (spmi-apple-irq-host-test.c). + * Apple SPMI controller interrupt register layout. * * Peripheral sources 0..255 come first, then the RX FIFO notification (256) and * the controller's own fault sources. Source n sits in bit n % 32 of word n / 32 From f853dec279f13324f3cf14e26c3f1d4c9958c56f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Thu, 19 Nov 2026 18:27:53 -0600 Subject: [PATCH 093/121] spmi: apple: drop the unreachable fault drain in the stray-queue loop The stray-queue loop visits ack words 0 to 3 (bytes 0 to 24), while the gen4 fault source lives in word 8 (0x620), which the chained handler already reads and drains before acking. The hunk also compared a word index against byte offsets. It could never fire; remove it. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/spmi/spmi-apple-controller.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 1237ac856ac55..bdabe697859b1 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -558,14 +558,6 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; - if (stray && !spmi->hw->legacy_irqs && spmi->faults && - offset == (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * sizeof(val) && - (stray & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { - /* Same rule as above: read the queued records first. */ - apple_spmi_drain_faults(spmi->dev, spmi); - stray &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); - handled = true; - } if (stray) { writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); From 918e9114d2ea10b84703f370bf3ad5b3f77fb030 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 23:50:54 +0100 Subject: [PATCH 094/121] dt-bindings: usb: apple,sn201202x: add the T8152 controllers The USB-C PD controllers behind the J873g's (T8152) SPMI controller at 0x308908000 answer as the T8132 ones do: no register-selection interrupt, so a selection is polled, and the payload length of the selected register is read from register 0x1f. Their event, sleep and wake sources are interrupts 11/17/19, 37/43/45 and 63/69/71 of that controller. Add apple,t8152-sn201202x with apple,t8132-sn201202x as fallback, so that the T8132 interrupt layout (irq, sleep, wake) applies. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/usb/apple,sn201202x.yaml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml index cc82767a25a51..84ae1f7bf0880 100644 --- a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml +++ b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml @@ -18,7 +18,9 @@ description: | The controller can be polled when interrupt resources are not supplied. T8132 omits the register-selection interrupt, so selection is polled while - event, standby and wakeup notifications use interrupts. + event, standby and wakeup notifications use interrupts. The T8152 + controllers work as the T8132 ones do: no register-selection interrupt, and + the payload length of a selected register in register 0x1f. properties: compatible: @@ -27,6 +29,10 @@ properties: - items: - const: apple,t8132-sn201202x - const: apple,sn201202x + - items: + - const: apple,t8152-sn201202x + - const: apple,t8132-sn201202x + - const: apple,sn201202x reg: maxItems: 1 From 2a360a0c95879d2700ecd06edd875c3efea93207 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 23:52:00 +0100 Subject: [PATCH 095/121] dt-bindings: display: apple,t8152-dcp-iboot: describe the USB-C ports as Type-C mode switches A T8152 DCP drives the rear USB-C port whose PD controller reports a DisplayPort sink. So far the DCP read the controllers itself, through apple,usb-pd. The controllers belong to the USB Type-C port driver instead, which passes the DisplayPort alt mode state of a port to the Type-C mode switches its connector's graph leads to. Describe one display switch per port, shared by the DCPs: the port's usb-c node in the shared ports node (the one apple,usb-c-ports refers to) is the mode switch, with an endpoint at the display port (port@3) of the port's usb-c-connector. The DCPs already share these nodes for the port's PHY registers and tunables, and each port has one owner at a time. One switch per DCP instead would fill the three mode switches a connector's port driver looks at (fwnode_typec_mux_get() collects the matches into a three-entry array and stops at the third endpoint without an error), and leave out the port's ATC PHY, which needs one for USB4. Drop apple,usb-pd, which nothing reads any more. Signed-off-by: Thomas Glanzmann --- .../display/apple,t8152-dcp-iboot.yaml | 32 ++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index 6fbdaba2d17a4..cc7ea1045a323 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -169,12 +169,6 @@ properties: The converter drives the HDMI hot-plug detect line only while it is powered. - 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: @@ -243,20 +237,30 @@ patternProperties: 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. + mode-switch: + type: boolean + description: + The port's display switch, one per port and shared by all DCPs + that can drive it. The port controller sets the port's + DisplayPort alt mode state, pin assignment and HPD on it; the plug + orientation is the Type-C port's. + port: + $ref: /schemas/graph.yaml#/properties/port + description: + Connects to the display port (port@3) of the port's + usb-c-connector. + dependencies: + mode-switch: [ port ] required: - reg - reg-names - apple,dfp-endpoint - - apple,usb-pd required: - compatible @@ -311,7 +315,13 @@ examples: <0x3 0x03a13a00 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <3>; - apple,usb-pd = <&hpm3>; + mode-switch; + + port { + endpoint { + remote-endpoint = <&typec3_display>; + }; + }; }; }; }; From b0935d55fd8b1b70c532f27ca59a9afa684daac2 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 23:56:10 +0100 Subject: [PATCH 096/121] drm/apple: take the T8152 USB-C display state from the Type-C ports The T8152 DCPs found a USB-C display by reading the rear ports' PD controllers over SPMI every 250 ms (t8152_pd.c): plug and orientation from STATUS (0x1a), DisplayPort connection, pin assignment and HPD from DATA_STATUS (0x5f), through the controllers' register window (select at 0x00, length at 0x1f, data from 0x20). With tipd bound to the same controllers, tipd failed to read its events while the display path polled. The controllers belong to tipd now. Take the state from the Type-C class instead: one Type-C mode switch per rear port, the port's usb-c node in the shared ports node, with an endpoint at the display port of the port's connector. tipd sets the port's mode on it. The switch records whether the port is in DisplayPort alt mode with HPD high, the lanes of the pin assignment (two for B, D and F, which share the cable with USB 3) and the plug orientation of the Type-C port, once, next to the port claims of t8152_atc.c, and tells every DCP that drives USB-C to look at the ports. The port claim and the PHY, crossbar and DPTX handling of t8152_atc.c and iboot_drm.c stay as they were. One switch per port, not one per DCP: a connector's port driver takes three mode switches at most (TYPEC_MUX_MAX_DEVS; fwnode_connection_find_matches() stops at the third endpoint and returns success). A switch per DCP would fill all three on every J873g rear connector, and the port's ATC PHY, which needs one for USB4, would never be called. A HPD pulse is not a new sink. Without a video stream, an EV2780 drops HPD for about 160 ms every 4.7 s; the PD controller reports it after the fact, and tipd passes it on as HPD low and then high. Connecting the sink anew on each pulse kept its link from coming up (link faults, one lane, then a standby link trained at RBR whose mode list lacked the enabled mode, so the next DPMS on failed atomic check). The 250 ms poll never saw these pulses. A switch event is looked at 100 ms later, which takes such a low and high together, and only a changed plug (orientation, lanes) or a sink that leaves DP alt mode with its partner is a new connection. dcp-fabric.c's route layer itself does not fit these DCPs: it switches a DP PHY and the display crossbar through their drivers and connects the sink through the DCP's IOMFB DPTX service, while the iBoot interface DCPs program the ATC PHY and the crossbar themselves and connect through their own DPTX port service. Their switches only record the state, in t8152_typec.c. The 250 ms work now only re-arms while a DCP can take the shared HDMI port, whose HPD line has no interrupt. The PD controller reset that made a sink which stopped answering AUX enter DP alt mode again (a cold reset, "Gaid", then system power state S0, "SSPS") is gone: the controller is tipd's, and tipd puts it into S0 whenever it sets the controller up. What remains is the DisplayPort side, at most once a minute: release the link and connect the port's sink again. HPD changes now reach the display path as they happen. The first DCP that probes registers the switches, ahead of everything else in its probe, and they stay until the driver is unloaded: tipd keeps the switch it found, and must not wait for a DCP that cannot start. A switch that cannot be registered is disabled in the live tree, so that tipd goes on without it. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/Kconfig | 5 +- drivers/gpu/drm/apple/Makefile | 2 +- drivers/gpu/drm/apple/dcp.c | 6 +- drivers/gpu/drm/apple/iboot_drm.c | 77 +++++---- drivers/gpu/drm/apple/iomfb_iboot.c | 11 +- drivers/gpu/drm/apple/iomfb_iboot.h | 13 +- drivers/gpu/drm/apple/t8152_atc.c | 15 +- drivers/gpu/drm/apple/t8152_display.h | 31 ++-- drivers/gpu/drm/apple/t8152_pd.c | 211 ------------------------ drivers/gpu/drm/apple/t8152_typec.c | 227 ++++++++++++++++++++++++++ 10 files changed, 322 insertions(+), 276 deletions(-) delete mode 100644 drivers/gpu/drm/apple/t8152_pd.c create mode 100644 drivers/gpu/drm/apple/t8152_typec.c diff --git a/drivers/gpu/drm/apple/Kconfig b/drivers/gpu/drm/apple/Kconfig index 876ebbd58605e..aae90f8de5825 100644 --- a/drivers/gpu/drm/apple/Kconfig +++ b/drivers/gpu/drm/apple/Kconfig @@ -78,7 +78,7 @@ config DRM_APPLE_DCP_T8132 config DRM_APPLE_DCP_T8152 bool "Mac mini M6 (J873g) displays" depends on DRM_APPLE - depends on SPMI=y || SPMI=DRM_APPLE + depends on TYPEC depends on MFD_MACSMC=y || MFD_MACSMC=DRM_APPLE select APERTURE_HELPERS help @@ -86,7 +86,8 @@ config DRM_APPLE_DCP_T8152 coprocessors of the T8152 Mac mini (J873g) through their firmware's iBoot interface: the HDMI port, whose DisplayPort-to-HDMI converter is powered through the SMC, and displays on the rear USB-C ports, - whose PD controllers are polled over SPMI. + whose DisplayPort alt mode the USB Type-C port driver of their PD + controllers reports (TYPEC_SN201202X). The boot loader hands each coprocessor over, running or quiesced, with the AFK endpoints it left running. The adopted sessions cannot diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index e6752d0f28516..c040f80df8e80 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -19,7 +19,7 @@ appledrm-y += iomfb_v26_6_desktop.o appledrm-y += iomfb_v14_7.o iomfb_v14_7_link.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8132) += iomfb_m4.o t8132_ext_drm.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_atc.o t8152_aux.o t8152_dptx.o -appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_pd.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_typec.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += iomfb_iboot.o iboot_drm.o appledrm-y += iomfb_h17p.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 396b62c988ecb..b0b1255045fd5 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7938,8 +7938,11 @@ static int dcp_platform_probe(struct platform_device *pdev) void *group; int ret; - if (hw->firmware_compat == DCP_FIRMWARE_IBOOT) + if (hw->firmware_compat == DCP_FIRMWARE_IBOOT) { + /* The port controllers wait for the USB-C display switches. */ + t8152_typec_register(dev); return dcp_platform_probe_iboot(pdev); + } /* t6041_dcpext=0: stay off the external processors' hardware. */ if (of_device_is_compatible(dev->of_node, "apple,t6041-dcpext") && @@ -10249,6 +10252,7 @@ int __init dcp_register(void) void dcp_unregister(void) { platform_driver_unregister(&apple_platform_driver); + t8152_typec_unregister(); } #if IS_ENABLED(CONFIG_DRM_APPLE_DISPLAY_KUNIT_TEST) diff --git a/drivers/gpu/drm/apple/iboot_drm.c b/drivers/gpu/drm/apple/iboot_drm.c index c0b3bd2311962..46b9fae499254 100644 --- a/drivers/gpu/drm/apple/iboot_drm.c +++ b/drivers/gpu/drm/apple/iboot_drm.c @@ -369,10 +369,10 @@ iboot_connector_detect(struct drm_connector *connector, bool force) dev_info(dcp->dev, "sink %s\n", hpd ? "plugged" : "unplugged"); disp->hpd = hpd; /* - * USB-C: the DPTX port's HPD follows the PD controller, and a - * new plug may come the other way round. + * USB-C: the DPTX port's HPD follows the port's Type-C state, + * and a new plug may come the other way round. */ - if (disp->pd) { + if (disp->usbc) { if (!hpd || ib->powered) { iboot_cancel_swap_locked(ib); if (t8152_dptx_disconnect(disp, 0)) @@ -408,11 +408,11 @@ iboot_connector_detect(struct drm_connector *connector, bool force) dev_err(dcp->dev, "no modes from the new sink\n"); ib->nr_tmodes = 0; ib->nr_cmodes = 0; - /* A sleeping EIZO may need a fresh DP alt mode entry. */ - if (disp->pd && !disp->on_hdmi && - time_after(jiffies, ib->pd_reset_time + 60 * HZ)) { - ib->pd_reset_time = jiffies; - schedule_work(&ib->pd_reset_work); + /* A sleeping EIZO may need its link started anew. */ + if (disp->usbc && !disp->on_hdmi && + time_after(jiffies, ib->relink_time + 60 * HZ)) { + ib->relink_time = jiffies; + schedule_work(&ib->relink_work); } } /* @@ -724,16 +724,17 @@ static int iboot_set_mode_locked(struct dcp_iboot *ib, dev_err(ib->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. + * monitor's deep sleep) is connected anew: its link is + * released, and the plug that follows starts the PHY cold + * and sets the mode again. At most once a minute, so a dead + * sink does not loop. */ - if (ib->disp.pd && !ib->disp.on_hdmi && - time_after(jiffies, ib->pd_reset_time + 60 * HZ)) { + if (ib->disp.usbc && !ib->disp.on_hdmi && + time_after(jiffies, ib->relink_time + 60 * HZ)) { ib->cur_mode = *t; ib->mode_failed = true; - ib->pd_reset_time = jiffies; - schedule_work(&ib->pd_reset_work); + ib->relink_time = jiffies; + schedule_work(&ib->relink_work); } return ret; } @@ -944,14 +945,18 @@ static const struct drm_mode_config_funcs iboot_mode_config_funcs = { .atomic_commit = drm_atomic_helper_commit, }; -static void iboot_pd_reset_work(struct work_struct *work) +/* + * Release the link of a USB-C sink that does not answer, and have the port's + * sink plugged again: the port's Type-C state still shows it, so the next + * look at the ports connects it as a new one. + */ +static void iboot_relink_work(struct work_struct *work) { - struct dcp_iboot *ib = container_of(work, struct dcp_iboot, pd_reset_work); + struct dcp_iboot *ib = container_of(work, struct dcp_iboot, relink_work); struct t8152_display *disp = &ib->disp; int ret; - dev_info(ib->dcp->dev, "USB-C sink does not answer, entering DP alt mode again\n"); - /* The reset may finish between polls. Release the old link explicitly. */ + dev_info(ib->dcp->dev, "USB-C sink does not answer, connecting it again\n"); mutex_lock(&ib->lock); iboot_cancel_swap_locked(ib); ret = t8152_dptx_disconnect(disp, 0); @@ -968,13 +973,9 @@ static void iboot_pd_reset_work(struct work_struct *work) return; } disp->hpd = 0; - ret = t8152_pd_reconnect(disp); mutex_unlock(&ib->lock); - if (ret) { - dev_err(ib->dcp->dev, "DP alt mode entry failed: %d\n", ret); - return; - } drm_kms_helper_hotplug_event(&ib->drm); + dcp_iboot_hpd_event(ib); } static void iboot_hpd_work(struct work_struct *work) @@ -985,11 +986,27 @@ static void iboot_hpd_work(struct work_struct *work) if (!READ_ONCE(ib->ready)) return; drm_helper_hpd_irq_event(&ib->drm); - if (READ_ONCE(ib->ready)) + /* + * USB-C changes come from the ports' display switches. The HDMI port's + * HPD line has no interrupt: poll it while this DCP can take the port. + */ + if (READ_ONCE(ib->ready) && ib->disp.hdmi_port) queue_delayed_work(system_freezable_wq, &ib->hpd_work, msecs_to_jiffies(250)); } +/* + * A USB-C port's Type-C state changed: look at the ports shortly. A HPD pulse + * the port driver learns of after the fact comes as HPD low and high at once; + * the delay takes both together. + */ +void dcp_iboot_hpd_event(struct dcp_iboot *ib) +{ + if (READ_ONCE(ib->ready)) + mod_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(100)); +} + void dcp_iboot_kms_stop(struct dcp_iboot *ib) { if (!ib->kms_work_ready) @@ -998,7 +1015,7 @@ void dcp_iboot_kms_stop(struct dcp_iboot *ib) cancel_delayed_work_sync(&ib->hpd_work); hrtimer_cancel(&ib->swap_timer); cancel_work_sync(&ib->swap_work); - cancel_work_sync(&ib->pd_reset_work); + cancel_work_sync(&ib->relink_work); } static void iboot_swap_stop(void *data) @@ -1014,7 +1031,7 @@ int dcp_iboot_kms_init(struct dcp_iboot *ib) ib->pending = -1; INIT_WORK(&ib->swap_work, iboot_swap_work); - INIT_WORK(&ib->pd_reset_work, iboot_pd_reset_work); + INIT_WORK(&ib->relink_work, iboot_relink_work); INIT_DELAYED_WORK(&ib->hpd_work, iboot_hpd_work); hrtimer_setup(&ib->swap_timer, iboot_swap_timer, CLOCK_MONOTONIC, HRTIMER_MODE_ABS); @@ -1031,7 +1048,7 @@ int dcp_iboot_kms_init(struct dcp_iboot *ib) ret = drmm_mode_config_init(drm); if (ret) return ret; - ib->pd_reset_time = jiffies - 61 * HZ; + ib->relink_time = jiffies - 61 * HZ; drm->mode_config.min_width = 320; drm->mode_config.min_height = 240; @@ -1067,10 +1084,10 @@ int dcp_iboot_kms_init(struct dcp_iboot *ib) if (ret) return ret; drm_connector_helper_add(&ib->connector, &iboot_connector_helper); - if (ib->disp.hpd_gpio || ib->disp.pd) + if (ib->disp.hpd_gpio || ib->disp.usbc) ib->connector.polled = DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT; - if (ib->disp.pd) + if (ib->disp.usbc) ib->connector.polled = DRM_CONNECTOR_POLL_HPD; ret = drm_connector_attach_encoder(&ib->connector, &ib->encoder); if (ret) diff --git a/drivers/gpu/drm/apple/iomfb_iboot.c b/drivers/gpu/drm/apple/iomfb_iboot.c index 757b122dc8e42..df308b133a39a 100644 --- a/drivers/gpu/drm/apple/iomfb_iboot.c +++ b/drivers/gpu/drm/apple/iomfb_iboot.c @@ -625,7 +625,7 @@ static int dcp_iboot_start(struct dcp_iboot *ib) &t8152_dptx_port_ops, 2); if (ret) return dev_err_probe(dev, ret, "no DPTX port service\n"); - if (disp->pd) { + if (disp->usbc) { ret = t8152_dptx_disconnect(disp, 0); if (ret) return dev_err_probe(dev, ret, "cannot release inherited DP link\n"); @@ -635,7 +635,7 @@ static int dcp_iboot_start(struct dcp_iboot *ib) * 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 (disp->pd) + if (disp->usbc) sink = false; if (sink) { ret = t8152_dptx_connect(disp, 0); @@ -698,9 +698,9 @@ static int dcp_iboot_start(struct dcp_iboot *ib) if (ret) return ret; WRITE_ONCE(ib->ready, true); - if (disp->hpd_gpio || disp->pd) + if (disp->hpd_gpio || disp->usbc) drmm_kms_helper_poll_init(&ib->drm); - if (disp->pd) + if (disp->usbc) queue_delayed_work(system_freezable_wq, &ib->hpd_work, msecs_to_jiffies(250)); drm_client_setup(&ib->drm, NULL); @@ -801,6 +801,9 @@ int dcp_iboot_probe(struct apple_dcp *dcp) dev_warn(dev, "live session not recorded; its DMA stays allocated\n"); WRITE_ONCE(dcp->retain_dma, true); } + /* The device stays bound from here on: follow the USB-C ports. */ + if (t8152_typec_init(disp)) + dev_err(dev, "USB-C ports not followed, no USB-C display\n"); if (ret) dev_err(dev, "cannot adopt the DCP: %d\n", ret); else diff --git a/drivers/gpu/drm/apple/iomfb_iboot.h b/drivers/gpu/drm/apple/iomfb_iboot.h index 9c2268604b017..bddeeedc198d5 100644 --- a/drivers/gpu/drm/apple/iomfb_iboot.h +++ b/drivers/gpu/drm/apple/iomfb_iboot.h @@ -94,9 +94,9 @@ struct dcp_iboot { 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; + /* USB-C: connect the sink anew when it stopped answering */ + struct work_struct relink_work; + unsigned long relink_time; /* * The DPAV video interface started: SET_MODE again, or the * firmware's idle power off timer takes the link down 30 s later. @@ -116,6 +116,10 @@ static inline struct dcp_iboot *to_dcp_iboot(struct drm_device *drm) } #if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) +/* t8152_typec.c */ +void t8152_typec_register(struct device *dev); +void t8152_typec_unregister(void); + /* iomfb_iboot.c */ int dcp_iboot_probe(struct apple_dcp *dcp); void dcp_iboot_remove(struct apple_dcp *dcp); @@ -131,7 +135,10 @@ int dcp_iboot_set_boot_mode(struct dcp_iboot *ib); void dcp_iboot_update_edid(struct dcp_iboot *ib); void dcp_iboot_reset_mode(struct dcp_iboot *ib); void dcp_iboot_av_started(struct dcp_iboot *ib); +void dcp_iboot_hpd_event(struct dcp_iboot *ib); #else +static inline void t8152_typec_register(struct device *dev) { } +static inline void t8152_typec_unregister(void) { } static inline int dcp_iboot_probe(struct apple_dcp *dcp) { return -ENODEV; } static inline void dcp_iboot_remove(struct apple_dcp *dcp) { } #endif diff --git a/drivers/gpu/drm/apple/t8152_atc.c b/drivers/gpu/drm/apple/t8152_atc.c index ce4b6a84602de..b2d018d4e636e 100644 --- a/drivers/gpu/drm/apple/t8152_atc.c +++ b/drivers/gpu/drm/apple/t8152_atc.c @@ -13,7 +13,7 @@ * set up the lanes again), drive settings, the DCP -> ATCn/DFP0 crossbar * route, and with the display off or unplugged a full power down and a cold * start. A DCP drives one USB-C port at a time: the one it claims from the - * shared ports while polling their PD controllers. + * shared ports once their Type-C state shows a sink (t8152_typec.c). */ #include @@ -53,7 +53,6 @@ struct t8152_atc_port { unsigned int index; /* ATC instance */ /* display crossbar DFP endpoint of this ATC */ u32 dfp; - struct spmi_device *pd; /* AP DisplayPort AUX controller aux0 (shared), for the EDID */ struct t8152_aux *aux; /* PMGR power states of the four ATC dependencies */ @@ -692,7 +691,9 @@ static int atc_detect(struct t8152_display *disp, bool *flipped) atc->next = atc->cur; /* Keep a monitor on its controller, including while userspace blanks it. */ if (atc_owner[atc->cur->index] == disp->dev) { - ret = t8152_pd_sink(atc->cur->pd, flipped, &atc->cur->next_lanes); + ret = t8152_typec_sink(disp, atc->cur->index, flipped, + &atc->cur->next_lanes); + /* The plug changed: a new sink */ if (ret > 0 && (atc->cur->swap != *flipped || atc->cur->lanes != atc->cur->next_lanes)) disp->hpd = 0; @@ -706,7 +707,7 @@ static int atc_detect(struct t8152_display *disp, bool *flipped) struct t8152_atc_port *port = &atc->port[i]; if (atc_owner[port->index] || - t8152_pd_sink(port->pd, flipped, &port->next_lanes) <= 0) + t8152_typec_sink(disp, port->index, flipped, &port->next_lanes) <= 0) continue; atc_owner[port->index] = disp->dev; atc->next = port; @@ -739,7 +740,6 @@ static void atc_select(struct t8152_display *disp) dev_info(disp->dev, "USB-C display on ATC%u now, was ATC%u\n", port->index, atc->cur->index); atc->cur = port; - disp->pd = port->pd; disp->dcp_output = port->dfp; } @@ -796,9 +796,6 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, port->psd = atc_map(disp, np, "atc-psd"); if (!port->base || !port->ps || !port->psd) return -ENOMEM; - port->pd = t8152_pd_get(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); @@ -916,7 +913,7 @@ int t8152_atc_init(struct t8152_display *disp) atc->next = atc->cur; disp->phy = &atc_ops; disp->phy_priv = atc; - disp->pd = atc->cur->pd; + disp->usbc = true; disp->dcp_output = atc->cur->dfp; dev_info(disp->dev, "USB-C display on ATC%u (%u ports)\n", atc->cur->index, atc->nports); diff --git a/drivers/gpu/drm/apple/t8152_display.h b/drivers/gpu/drm/apple/t8152_display.h index b26baf6b04924..f4aa562fb3810 100644 --- a/drivers/gpu/drm/apple/t8152_display.h +++ b/drivers/gpu/drm/apple/t8152_display.h @@ -4,15 +4,15 @@ * that no subsystem driver covers yet: the ATC PHYs' DisplayPort lanes and * their display crossbar route (t8152_atc.c), the HDMI port's dedicated * DisplayPort PHY and PS190 converter (t8152_hdmi.c), the AP's DisplayPort - * AUX controllers that read the sink's EDID (t8152_aux.c), the rear USB-C - * ports' ACE3 PD controllers (t8152_pd.c), and the DPTX port service the - * DCP firmware calls into for the PHY (t8152_dptx.c). + * AUX controllers that read the sink's EDID (t8152_aux.c), and the DPTX port + * service the DCP firmware calls into for the PHY (t8152_dptx.c). The rear + * USB-C ports' DisplayPort alt mode state comes from their Type-C port + * driver, through the ports' shared display switches (t8152_typec.c). * - * Interim: the ATC DisplayPort mode moves to drivers/phy/apple/atc.c, the - * ACE3 controllers to tipd, and the choice of port with DP alt mode to the - * Type-C route layer of dcp-fabric.c, each in its own change. Until then - * these files program the registers themselves, for the iBoot interface - * DCPs of iomfb_iboot.c alone. + * Interim: the ATC DisplayPort mode moves to drivers/phy/apple/atc.c and the + * choice of port with DP alt mode to the Type-C route layer of dcp-fabric.c, + * each in its own change. Until then these files program the registers + * themselves, for the iBoot interface DCPs of iomfb_iboot.c alone. */ #ifndef __APPLE_T8152_DISPLAY_H__ #define __APPLE_T8152_DISPLAY_H__ @@ -24,9 +24,9 @@ struct apple_epic_service_ops; struct device; struct device_node; struct gpio_desc; -struct spmi_device; struct t8152_display; struct t8152_hdmi; +struct t8152_typec; /* SET_DRIVE_SETTINGS and GET_DRIVE_SETTINGS records, one per lane */ struct t8152_drive_settings { @@ -90,8 +90,9 @@ struct t8152_display { /* optional sink HPD line (HDMI), polled; the last level seen */ struct gpio_desc *hpd_gpio; int hpd; - /* USB-C: the PD controller of the port in use */ - struct spmi_device *pd; + /* USB-C: plug and HPD come from the ports' display switches */ + bool usbc; + struct t8152_typec *typec; /* HDMI PHY: DCPEXT0's, or the main DCP's on an HDMI-only boot */ bool hdmi; /* @@ -126,10 +127,10 @@ int t8152_aux_init(struct t8152_display *disp, struct t8152_aux *aux); int t8152_aux_read_edid(struct t8152_display *disp, struct t8152_aux *aux, u8 *buf, size_t size); -/* t8152_pd.c */ -struct spmi_device *t8152_pd_get(struct device_node *np); -int t8152_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes); -int t8152_pd_reconnect(struct t8152_display *disp); +/* t8152_typec.c, see also iomfb_iboot.h */ +int t8152_typec_init(struct t8152_display *disp); +int t8152_typec_sink(struct t8152_display *disp, u32 index, bool *flipped, + u32 *lanes); /* t8152_dptx.c */ extern const struct apple_epic_service_ops t8152_dptx_port_ops; diff --git a/drivers/gpu/drm/apple/t8152_pd.c b/drivers/gpu/drm/apple/t8152_pd.c deleted file mode 100644 index 8c514d17d69d2..0000000000000 --- a/drivers/gpu/drm/apple/t8152_pd.c +++ /dev/null @@ -1,211 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0-only OR MIT -/* - * USB-C plug state from the rear ports' ACE3 PD controllers over SPMI, for - * the USB-C displays' hotplug: the DP alt mode connection, its pin - * assignment and the plug orientation. Logical registers are read through a - * window: select with a register-zero write, wait for the busy bit to - * clear, read the size at 0x1f and the data from 0x20. - * - * Interim, until tipd owns these controllers and reports DP alt mode to the - * Type-C route layer of dcp-fabric.c: tipd and this share the SPMI devices, - * serialized by the device lock. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include "t8152_display.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_POWER_STATE 0x20 -#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). A sink that stopped answering AUX after a - * monitor's deep sleep comes back this way. - */ -int t8152_pd_reconnect(struct t8152_display *disp) -{ - struct spmi_device *pd = disp->pd; - int ret; - - device_lock(&pd->dev); - /* Gaid resets the controller before it can report completion. */ - ret = spmi_command_wakeup(pd); - if (!ret) - ret = ace3_write(pd, ACE3_REG_CMD1, "Gaid", 4); - if (ret) - goto out; - /* - * The controller restarts: on the J873g ports its mode register read - * "BOOT" about 22 ms after Gaid, it acknowledged no SPMI command from - * about 215 ms on, and it read "APP " and took SSPS again after about - * 290 ms. Polling it through that gap only gets NACKs, which the SPMI - * controller logs as errors, and nothing signals the restart's end. - * So SSPS is first sent 500 ms after Gaid, and every 500 ms after that - * for a controller that takes longer. - */ - for (int i = 0; i < 60; i++) { - msleep(500); - ret = ace3_cmd(pd, "SSPS", 0); - if (!ret) - break; - } -out: - device_unlock(&pd->dev); - return ret; -} - -/* 1 with a DisplayPort sink in DP alt mode and HPD high, 0 without. */ -int t8152_pd_sink(struct spmi_device *pd, bool *flipped, u32 *lanes) -{ - 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) - 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) - 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. */ - 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. */ -struct spmi_device *t8152_pd_get(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 (retained) device. */ - pd = spmi_find_device_by_of_node(pd_np); - of_node_put(pd_np); - return pd ?: ERR_PTR(-EPROBE_DEFER); -} diff --git a/drivers/gpu/drm/apple/t8152_typec.c b/drivers/gpu/drm/apple/t8152_typec.c new file mode 100644 index 0000000000000..0084afc02dbc9 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_typec.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The rear USB-C ports' DisplayPort alt mode, from the USB Type-C port + * driver that owns their PD controllers. Each port has one Type-C mode + * switch for the display path, shared by all DCPs: the port's usb-c node in + * the shared ports node (apple,usb-c-ports), whose endpoint is at the display + * port of the port's connector. The Type-C class looks at three mode switches + * of a connector at most, and the port's PHY needs one as well, so there is + * no room for one per DCP. + * + * The first DCP that probes registers the switches, and they stay until the + * driver is unloaded: the port driver keeps using a switch it found, and + * must not wait for a DCP that cannot start. A switch records what the + * display path reads (DisplayPort alt mode with HPD high, the lanes of the + * pin assignment, the plug orientation) and has every DCP that drives USB-C + * look at its ports; t8152_atc.c claims a port for one of them. + * + * The switches are dcp-fabric.c's in the device tree only. Its route layer + * switches a DP PHY and the display crossbar through their own drivers and + * connects the sink through the DCP's IOMFB DPTX service; these DCPs program + * the ATC PHY and the crossbar themselves and connect through the iBoot + * interface's DPTX port service, so their switches record the state alone. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iomfb_iboot.h" +#include "t8152_display.h" + +/* The ATC instances, as the display crossbar's DFP endpoints number them */ +#define T8152_TYPEC_PORTS 4 + +struct t8152_typec_port { + struct typec_mux_dev *mux; + /* below under t8152_typec_lock */ + bool sink; + bool flipped; + u32 lanes; +}; + +/* A DCP that drives USB-C, told about the ports' changes */ +struct t8152_typec { + struct list_head node; + struct t8152_display *disp; +}; + +/* Registers the switches, once */ +static DEFINE_MUTEX(t8152_typec_register_lock); +/* The ports' state, written by the port driver, and the DCPs that read it */ +static DEFINE_SPINLOCK(t8152_typec_lock); +static struct t8152_typec_port t8152_typec_ports[T8152_TYPEC_PORTS]; +static LIST_HEAD(t8152_typec_displays); + +static int t8152_typec_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + struct t8152_typec_port *port = typec_mux_get_drvdata(mux); + struct typec_displayport_data *dp = NULL; + struct t8152_typec *typec; + bool flipped = false; + u32 lanes = 4; + + if (state->alt && state->alt->svid == USB_TYPEC_DP_SID && + state->mode >= TYPEC_DP_STATE_A && state->mode <= TYPEC_DP_STATE_F) { + dp = state->data; + flipped = typec_altmode_get_orientation(state->alt) == + TYPEC_ORIENTATION_REVERSE; + /* B, D and F share the cable with USB 3: two DisplayPort lanes */ + if (state->mode == TYPEC_DP_STATE_B || state->mode == TYPEC_DP_STATE_D || + state->mode == TYPEC_DP_STATE_F) + lanes = 2; + } + + guard(spinlock)(&t8152_typec_lock); + /* The sink answers AUX once it raised HPD, not at alt mode entry. */ + port->sink = dp && (dp->status & DP_STATUS_HPD_STATE); + port->flipped = flipped; + port->lanes = lanes; + list_for_each_entry(typec, &t8152_typec_displays, node) + dcp_iboot_hpd_event(container_of(typec->disp, struct dcp_iboot, disp)); + return 0; +} + +/* + * 1 with a DisplayPort sink on the port of ATC @index (DP alt mode, HPD + * high), 0 without. + * + * A HPD pulse that ends before the DCP looks is not a new sink: an EV2780 + * without a video stream drops HPD for about 160 ms every few seconds, and + * connecting it anew each time kept its link from coming up. A sink that is + * really unplugged leaves DP alt mode with its partner. + */ +int t8152_typec_sink(struct t8152_display *disp, u32 index, bool *flipped, + u32 *lanes) +{ + struct t8152_typec_port *port; + + if (!disp->typec || index >= T8152_TYPEC_PORTS) + return 0; + port = &t8152_typec_ports[index]; + guard(spinlock)(&t8152_typec_lock); + if (!port->mux || !port->sink) + return 0; + *flipped = port->flipped; + *lanes = port->lanes; + return 1; +} + +static int t8152_typec_port_register(struct device *dev, struct device_node *np) +{ + struct typec_mux_desc desc = {}; + struct t8152_typec_port *port; + struct typec_mux_dev *mux; + u32 index; + int ret; + + ret = of_property_read_u32(np, "apple,dfp-endpoint", &index); + if (ret || index >= T8152_TYPEC_PORTS) + return dev_err_probe(dev, ret ?: -EINVAL, "%pOF: invalid port\n", np); + port = &t8152_typec_ports[index]; + if (port->mux) + return 0; + desc.fwnode = of_fwnode_handle(np); + desc.set = t8152_typec_set; + desc.drvdata = port; + desc.name = kasprintf(GFP_KERNEL, "dcp-usb-c%u", index); + if (!desc.name) + return -ENOMEM; + port->lanes = 4; + /* Not a devres of @dev: the switch outlives this DCP's binding. */ + mux = typec_mux_register(dev, &desc); + kfree(desc.name); + if (IS_ERR(mux)) + return dev_err_probe(dev, PTR_ERR(mux), "%pOF: switch not registered\n", np); + scoped_guard(spinlock, &t8152_typec_lock) + port->mux = mux; + return 0; +} + +/* A switch that cannot be registered: the port driver goes on without it. */ +static void t8152_typec_port_disable(struct device *dev, struct device_node *np) +{ + struct of_changeset *cs = kzalloc(sizeof(*cs), GFP_KERNEL); + + if (!cs) + return; + of_changeset_init(cs); + if (!of_changeset_update_prop_string(cs, np, "status", "disabled") && + !of_changeset_apply(cs)) + return; /* applied, it stays: the live tree refers to it */ + dev_err(dev, "%pOF: could not disable the display switch\n", np); + of_changeset_destroy(cs); + kfree(cs); +} + +/* + * Register the display switches of the USB-C ports the DCP @dev can drive, + * unless another DCP did. Called first in the DCP's probe, so that the port + * driver, which waits for them, never waits for a DCP that cannot start. + */ +void t8152_typec_register(struct device *dev) +{ + struct device_node *ports __free(device_node) = + of_parse_phandle(dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: dev->of_node; + + guard(mutex)(&t8152_typec_register_lock); + for_each_available_child_of_node_scoped(np, child) { + if (of_property_present(child, "mode-switch") && + t8152_typec_port_register(dev, child)) + t8152_typec_port_disable(dev, child); + } +} + +/* At driver unload, once no DCP is bound */ +void t8152_typec_unregister(void) +{ + guard(mutex)(&t8152_typec_register_lock); + for (unsigned int i = 0; i < T8152_TYPEC_PORTS; i++) { + struct typec_mux_dev *mux = t8152_typec_ports[i].mux; + + if (!mux) + continue; + scoped_guard(spinlock, &t8152_typec_lock) + t8152_typec_ports[i].mux = NULL; + typec_mux_unregister(mux); + } +} + +static void t8152_typec_leave(void *data) +{ + struct t8152_typec *typec = data; + + scoped_guard(spinlock, &t8152_typec_lock) + list_del(&typec->node); +} + +/* + * Have the DCP see the USB-C ports' display state from now on: call this + * once the DCP stays bound. Without it, the DCP sees no USB-C sink. + */ +int t8152_typec_init(struct t8152_display *disp) +{ + struct t8152_typec *typec; + int ret; + + typec = devm_kzalloc(disp->dev, sizeof(*typec), GFP_KERNEL); + if (!typec) + return -ENOMEM; + typec->disp = disp; + scoped_guard(spinlock, &t8152_typec_lock) + list_add_tail(&typec->node, &t8152_typec_displays); + ret = devm_add_action_or_reset(disp->dev, t8152_typec_leave, typec); + if (ret) + return ret; + disp->typec = typec; + return 0; +} From f53d6de128080b63e1e90cb187912759f6b260bd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 23:57:58 +0100 Subject: [PATCH 097/121] arm64: dts: apple: t8152-j873g: hand the rear USB-C PD controllers to tipd The PD controllers of the three rear USB-C ports were described for the display path alone, which read them over SPMI itself. Describe them for tipd, which owns them from now on, and the display path takes their DisplayPort alt mode state from the Type-C class: - the controllers as apple,t8152-sn201202x, with the T8132 fallback: tipd's SPMI transport then polls the register selection and reads the payload length from register 0x1f, as these controllers need; - the SPMI controller (AIC 682) as the interrupt controller of their event, sleep and wake sources: 11/17/19 (back-middle), 37/43/45 (back-left) and 63/69/71 (back-right), rising edge, as in the ADT. In a test with the compatibles and interrupts alone, tipd bound all three, took its events by interrupt, and both display partners showed DisplayPort alt mode active; - a usb-c-connector per controller, whose display port (port@3) leads to the port's usb-c node in the main DCP's shared ports node, the port's one display switch for all three DCPs. The USB port (port@0) stays unlinked: the USB data path is not changed here. The DCP's usb-c nodes lose apple,usb-pd, which nothing reads any more. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 134 +++++++++++++++++- 1 file changed, 128 insertions(+), 6 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi index 8263f1c68634b..2cc188ea99d91 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -100,29 +100,124 @@ /* * 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. + * Their event, sleep and wake sources are interrupts of this + * controller (the ADT's), its own line is AIC 682. A connector's + * display port leads to the port's display switch, which all + * DCPs share. */ nub_spmi_a0: spmi@308908000 { compatible = "apple,t8152-spmi", "apple,t8142-spmi"; reg = <0x3 0x08908000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + interrupt-controller; + #interrupt-cells = <2>; #address-cells = <2>; #size-cells = <0>; /* back-middle */ hpm0: usb-pd@c { - compatible = "apple,sn201202x"; + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; reg = <0xc SPMI_USID>; + interrupts = <11 IRQ_TYPE_EDGE_RISING>, + <17 IRQ_TYPE_EDGE_RISING>, + <19 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec0: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-middle"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec0_display: endpoint { + remote-endpoint = <&display_typec0>; + }; + }; + }; + }; }; /* back-left */ hpm1: usb-pd@a { - compatible = "apple,sn201202x"; + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; reg = <0xa SPMI_USID>; + interrupts = <37 IRQ_TYPE_EDGE_RISING>, + <43 IRQ_TYPE_EDGE_RISING>, + <45 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec1: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-left"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec1_display: endpoint { + remote-endpoint = <&display_typec1>; + }; + }; + }; + }; }; /* back-right */ hpm3: usb-pd@8 { - compatible = "apple,sn201202x"; + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; reg = <0x8 SPMI_USID>; + interrupts = <63 IRQ_TYPE_EDGE_RISING>, + <69 IRQ_TYPE_EDGE_RISING>, + <71 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec3: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-right"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec3_display: endpoint { + remote-endpoint = <&display_typec3>; + }; + }; + }; + }; }; }; @@ -182,6 +277,7 @@ * 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. + * The node is also the port's display switch for all DCPs. */ usb-c@403000000 { reg = <0x4 0x03000000 0x0 0x84000>, @@ -189,7 +285,8 @@ <0x3 0x03a13700 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <0>; - apple,usb-pd = <&hpm0>; + /* The DCPs' display switch of the port */ + mode-switch; apple,tunable-pre = /* ACIOPHY_CMN_DFLT */ <0x00800 0x00fc0000 0x00fc0000>, @@ -279,12 +376,19 @@ <0x00ebc 0x0000007f 0x0000005a>, /* ASDC_AUX_SHM_DFLT */ <0x02308 0x000000fc 0x00000084>; + + port { + display_typec0: endpoint { + remote-endpoint = <&typec0_display>; + }; + }; }; /* * 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. + * The node is also the port's display switch for all DCPs. */ usb-c@40b000000 { reg = <0x4 0x0b000000 0x0 0x84000>, @@ -292,7 +396,8 @@ <0x3 0x03a13800 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <1>; - apple,usb-pd = <&hpm1>; + /* The DCPs' display switch of the port */ + mode-switch; apple,tunable-pre = /* ACIOPHY_CMN_DFLT */ <0x00800 0x00fc0000 0x00fc0000>, @@ -382,12 +487,19 @@ <0x00ebc 0x0000007f 0x0000005a>, /* ASDC_AUX_SHM_DFLT */ <0x02308 0x000000fc 0x00000084>; + + port { + display_typec1: endpoint { + remote-endpoint = <&typec1_display>; + }; + }; }; /* * 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. + * The node is also the port's display switch for all DCPs. */ usb-c@413000000 { reg = <0x4 0x13000000 0x0 0x84000>, @@ -395,7 +507,8 @@ <0x3 0x03a13a00 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <3>; - apple,usb-pd = <&hpm3>; + /* The DCPs' display switch of the port */ + mode-switch; apple,tunable-pre = /* ACIOPHY_CMN_DFLT */ <0x00800 0x00fc0000 0x00fc0000>, @@ -485,7 +598,14 @@ <0x00ebc 0x0000007f 0x0000005a>, /* ASDC_AUX_SHM_DFLT */ <0x02308 0x000000fc 0x00000084>; + + port { + display_typec3: endpoint { + remote-endpoint = <&typec3_display>; + }; + }; }; + }; /* @@ -563,6 +683,7 @@ iommus = <&dispext0_dart 0>; dma-coherent; }; + }; dcpext1_mbox: mailbox@316020700 { @@ -591,6 +712,7 @@ iommus = <&dispext1_dart 0>; dma-coherent; }; + }; }; From 143afdb3779a6f05f13609231ef6c44922477560 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 098/121] 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 934f9eb5ffd17384cffd3364c566667adb839fdf Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 20:54:59 +0100 Subject: [PATCH 099/121] 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. It has its own Kconfig symbol, APPLE_PMGR_PSD, on by default with ARCH_APPLE and built in by the shared asahi.config profile. Signed-off-by: Thomas Glanzmann --- arch/arm64/configs/asahi.config | 1 + drivers/pmdomain/apple/Kconfig | 12 +++ drivers/pmdomain/apple/Makefile | 1 + drivers/pmdomain/apple/pmgr-psd.c | 151 ++++++++++++++++++++++++++++++ 4 files changed, 165 insertions(+) create mode 100644 drivers/pmdomain/apple/pmgr-psd.c diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index ff74ba4c8dad6..f4e60efde4d42 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -157,6 +157,7 @@ CONFIG_SECURITY_LOCKDOWN_LSM=y CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y CONFIG_APPLE_PMGR_PWRSTATE=y +CONFIG_APPLE_PMGR_PSD=y CONFIG_APPLE_T6041_CIO_RECONFIG=y CONFIG_APPLE_PMC=y CONFIG_APPLE_CLUSTER_PWRGATE=y diff --git a/drivers/pmdomain/apple/Kconfig b/drivers/pmdomain/apple/Kconfig index 118bcd1736242..7c6469fabdc04 100644 --- a/drivers/pmdomain/apple/Kconfig +++ b/drivers/pmdomain/apple/Kconfig @@ -26,6 +26,18 @@ config APPLE_PMGR_PWRSTATE_KUNIT_TEST and need no Apple hardware. Also check the T6000 GFX missing-parent wait, its timeout, and the separate actual-state acknowledgment. +config APPLE_PMGR_PSD + bool "Apple T8152 PMGR service power domains" + depends on ARCH_APPLE || COMPILE_TEST + depends on PM && OF + select PM_GENERIC_DOMAINS + default ARCH_APPLE + help + The T8152 PMGR switches some blocks, among them the USB and USB4 + DARTs and controllers and the video decoder, through service + power states (PSD) rather than PMGR power state registers. This + driver offers each service as a generic power domain. + config APPLE_T6041_CIO_RECONFIG bool "Apple T6041 CIO cluster reconfiguration" depends on OF diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index 351773930cb84..34b8898eff911 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_FLOOR_KUNIT_TEST) += pmp-floor-gov-test.o +obj-$(CONFIG_APPLE_PMGR_PSD) += 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 c5b88996af52f1cc02c6b669fb7ffb24900c52fc Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:14:28 +0100 Subject: [PATCH 100/121] dt-bindings: phy: apple,atcphy: add the T8152 fixed-USB3 PHY The two front USB-C ports of the Mac mini (2026, J873g) sit behind an on-board USB3 hub. The hub's SuperSpeed lanes are wired to the Type-C PHY of the SoC's ATC2 directly, without a Type-C mux or port controller in between, so that PHY only ever runs one fixed USB3 configuration. Describe the T8152 variant in that role, with a boolean apple,fixed-usb3 that marks such a port: the PHY runs USB3 on lane 0 from probe on, ignores mux and orientation changes and provides only the USB3 PHY of its controller. The controller's USB2 side and reset stay with the bootloader, so the T8152 PHY has no #reset-cells and no Type-C switch properties. The PHY is described by its core and pipehandler banks. On T8152 the core bank also holds the USB controller's DARTs, and the PHY's power and reset block sits behind them. It needs four power domains, listed in the order they are powered up: the ATC's USB_AON power state, its common PSD service and its COMMON_DP_0 and COMMON_DP_1 power states. The other variants keep their single power domain and #reset-cells. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/phy/apple,atcphy.yaml | 142 ++++++++++++++---- 1 file changed, 114 insertions(+), 28 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml index 41ecaccc8a0ae..783f6732fae3a 100644 --- a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml @@ -40,6 +40,13 @@ description: > DisplayPort also requires separate bootloader-provided calibration lists for that bank and the common configuration in the lpdptx region. + The T8152 variant is supported as the USB3 PHY of a fixed-USB3 port only, + see apple,fixed-usb3. It is described by its core and pipehandler banks; the + core bank also holds the USB controller's DARTs. Its power domains are the + ATC's PMGR power states and PSD service the PHY needs, in the order they are + powered up. Lane 0 is powered up and the crossbar set between the common-a + tunables and the others. + allOf: - $ref: /schemas/usb/usb-switch.yaml# - if: @@ -122,32 +129,78 @@ allOf: required: - power-domains else: - properties: - reg: - minItems: 5 - items: - - description: Common controls for all PHYs (USB2/3/4, DisplayPort, TBT) - - description: DisplayPort Alternate Mode PHY specific controls - - description: Type-C PHY AXI to Apple Fabric interconnect controls - - description: USB2 PHY specific controls - - description: USB3 PIPE interface controls - - description: Secondary eUSB2 PHY register bank (T8140) - - description: - Power and hibernation control of the USB controller the PHY - serves (T8140). The PHY drives that controller's reset and - takes it through hibernation for a system sleep. - reg-names: - minItems: 5 - items: - - const: core - - const: lpdptx - - const: axi2af - - const: usb2phy - - const: pipehandler - - const: usb2phy-reg - - const: pwrctl - required: - - power-domains + if: + properties: + compatible: + contains: + const: apple,t8152-atcphy + then: + properties: + reg: + items: + - description: + PHY core with its power and reset block, which also holds + the USB controller's DARTs + - description: USB3 PIPE interface controls + reg-names: + items: + - const: core + - const: pipehandler + power-domains: + items: + - description: The ATC's USB_AON power state + - description: The ATC's common PSD service + - description: The ATC's COMMON_DP_0 power state + - description: The ATC's COMMON_DP_1 power state + required: + - power-domains + else: + properties: + reg: + minItems: 5 + items: + - description: Common controls for all PHYs (USB2/3/4, DisplayPort, TBT) + - description: DisplayPort Alternate Mode PHY specific controls + - description: Type-C PHY AXI to Apple Fabric interconnect controls + - description: USB2 PHY specific controls + - description: USB3 PIPE interface controls + - description: Secondary eUSB2 PHY register bank (T8140) + - description: + Power and hibernation control of the USB controller the PHY + serves (T8140). The PHY drives that controller's reset and + takes it through hibernation for a system sleep. + reg-names: + minItems: 5 + items: + - const: core + - const: lpdptx + - const: axi2af + - const: usb2phy + - const: pipehandler + - const: usb2phy-reg + - const: pwrctl + required: + - power-domains + - if: + properties: + compatible: + contains: + const: apple,t8152-atcphy + then: + properties: + "#reset-cells": false + mode-switch: false + orientation-switch: false + ports: false + required: + - apple,fixed-usb3 + else: + properties: + apple,fixed-usb3: false + power-domains: + maxItems: 1 + required: + - "#reset-cells" - if: properties: compatible: @@ -234,6 +287,7 @@ allOf: - apple,t8122-atcphy - apple,t6030-atcphy - apple,t6031-atcphy + - apple,t8152-atcphy then: required: - orientation-switch @@ -275,6 +329,7 @@ properties: - const: apple,t8132-atcphy - const: apple,t8140-atcphy - const: apple,t8142-atcphy + - const: apple,t8152-atcphy reg: minItems: 1 @@ -294,7 +349,8 @@ properties: orientation-switch: true power-domains: - maxItems: 1 + minItems: 1 + maxItems: 4 phys: maxItems: 1 @@ -323,6 +379,15 @@ properties: $ref: /schemas/graph.yaml#/properties/port description: Incoming endpoint from the USB4/Thunderbolt controller. + apple,fixed-usb3: + type: boolean + description: > + T8152 only, and required there. The port's SuperSpeed lanes go straight + to a USB3 device or hub, with no Type-C mux in between, so the PHY runs + USB3 on lane 0 from probe on and ignores mux and orientation changes. It + provides only the USB3 PHY of its USB controller, which is a host, and + leaves the controller's USB2 side and reset to the bootloader. + apple,dp-alt-mode: type: boolean description: > @@ -521,7 +586,6 @@ required: - reg - reg-names - "#phy-cells" - - "#reset-cells" additionalProperties: false @@ -622,3 +686,25 @@ examples: }; }; }; + + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x3 0x83000000 0x0 0x84000>, + <0x3 0x82414000 0x0 0x4000>; + reg-names = "core", "pipehandler"; + + #phy-cells = <1>; + apple,fixed-usb3; + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_common>, + <&ps_atc2_common_dp_0>, <&ps_atc2_common_dp_1>; + + apple,tunable-common-a = <0x00800 0x00fc0000 0x00fc0000>; + apple,tunable-common-b = <0x6c004 0x003f003f 0x00200020>; + apple,tunable-lane0-usb = <0x082d8 0xf0000000 0x70000000>; + }; + }; From 78e6e33e0a487a4eba542eec9456709f5dd800a5 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:14:45 +0100 Subject: [PATCH 101/121] phy: apple: atc: add T8152 for a fixed-USB3 port The J873g front ports reach their on-board USB3 hub through ATC2's Type-C PHY, wired to the hub without a Type-C mux. So far the hub ran at USB2 only: the bootloader leaves the PHY powered down and the PIPE on the controller's dummy PHY. Support the T8152 PHY in that role in the shared ATC driver. T8152 shares the T8142 generation's power and reset block, tunables and PIPE handler, with a different layout: the USB controller's DARTs sit at 0x20000 and 0x40000 of the ATC window, so the power and reset block follows at 0x60000, its lane swap is bit 1 there, and the reset the power-up releases first is a separate always-on sync reset at 0x60030. The crossbar is at 0x4c and the USB3 mode's existing setting, USB3+DP with single PMA 0x008, gives the value 0x110; there is no lane mode register to program. Describe this in the match data, with zero for the layout of the other SoCs, and leave the power-up and power-down, the tunables, the crossbar and the PIPE switch to the existing code. What remains T8152 code: - Lane 0 is powered up on its own after the common-a tunables (LFPS receivers, sleep, clamp, AHB reset) and down again with the PHY. Without it the lane registers stay in AHB reset, drop the lane tunables and the PHY never reports PIPE PhyStatus. The crossbar is set right after, before the remaining tunables, as in the T8152 sequence. - While the PIPE moves to the PHY, the BIST overrides hold lane 0's PIPE reset and power-down, stepping from P2 to P3, and the non-selected PHY override is released under them. The T8152 PIPE handler takes the lock request but does not acknowledge it: with the controller out of reset, no acknowledge came within 150 ms in either direction, while the PIPE moved to USB3 and back to the dummy PHY under the request. So T8152 changes the PIPE under the request without waiting for the acknowledge; otherwise every USB3 start fails. A fixed-USB3 port, apple,fixed-usb3, is a host by construction. Probe maps only the core and PIPE windows, the core without claiming it as it holds the DARTs, powers the PHY's power domains in the order they are listed and brings the PHY up in USB3. It registers only the USB3 PHY: no reset controller, Type-C mux or switch, as the controller's reset and USB2 side stay with the bootloader. The PIPE is routed when the controller powers the USB3 PHY on, after its core reset, which also sets the PHY up again after a power-off. If that fails the host starts with its PIPE parked, so the hub keeps USB2. The T8152 register sequence is the one of the earlier standalone driver, with which the hub enumerated at 10 Gb/s. The other SoCs keep their register accesses: the new layout fields are zero for them, and the new code runs for T8152 or a fixed-USB3 port only. KUnit cases check the T8152 crossbar, lane and power block accesses. Signed-off-by: Thomas Glanzmann --- drivers/phy/apple/atc-test.c | 113 +++++ drivers/phy/apple/atc.c | 455 ++++++++++++++++-- tools/asahi/atc-usb3-tests.py | 7 +- .../selftests/drivers/apple/atc-t8132-usb3.py | 9 +- .../selftests/drivers/gpu/apple-dcp/common.py | 12 + .../drivers/gpu/apple-dcp/dwc3/mocks.c | 8 +- .../drivers/gpu/apple-dcp/lifecycle.py | 4 +- .../selftests/drivers/gpu/apple-dcp/phy.py | 24 +- 8 files changed, 577 insertions(+), 55 deletions(-) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..a34e19b1ab432 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -1450,3 +1450,116 @@ static struct kunit_suite atcphy_t8132_pm_test_suite = { }; kunit_test_suite(atcphy_t8132_pm_test_suite); + +#define ATCPHY_TEST_T8152_LANE0_UP \ + (ACIOPHY_T8152_AON_LANE_SLEEP_SMALL | ACIOPHY_T8152_AON_LANE_SLEEP_BIG | \ + ACIOPHY_T8152_AON_LANE_AHB_RESET_N) + +/* + * A T8152 fixed-USB3 PHY over zeroed memory in place of its ATC window, up to + * the sync reset. Its USB controller's DARTs sit at the T8103 offsets of the + * power and reset block: mark those words to see that nothing writes them. + */ +static struct apple_atcphy *atcphy_test_alloc_t8152(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false); + void *core = kunit_kzalloc(test, ATCPHY_T8152_SYNC_RESET + 4, GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, core); + atcphy->regs.core = (__force void __iomem *)core; + atcphy->hw = &atcphy_hw_t8152; + atcphy->fixed_usb3 = true; + writel(0xdeadbeef, atcphy->regs.core + ATCPHY_POWER_CTRL); + writel(0xdeadbeef, atcphy->regs.core + ATCPHY_MISC); + + return atcphy; +} + +static void atcphy_test_t8152_untouched(struct kunit *test, struct apple_atcphy *atcphy) +{ + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.core + ATCPHY_POWER_CTRL), 0xdeadbeefU); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.core + ATCPHY_MISC), 0xdeadbeefU); +} + +/* USB3: lane 0 powered up, crossbar 0x110, no lane mode register, lane swap bit 1 */ +static void atcphy_test_t8152_lanes(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE0); + writel(ATCPHY_T8152_MISC_LANE_SWAP, core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC); + + atcphy_lanes_up_t8152(atcphy, APPLE_ATCPHY_MODE_USB3); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0 | + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), 0x110U); + + KUNIT_EXPECT_EQ(test, atcphy_configure_lanes(atcphy, APPLE_ATCPHY_MODE_USB3), 0); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), 0x110U); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_LANE_MODE_T8103), 0U); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC), 0U); + atcphy_test_t8152_untouched(test, atcphy); +} + +/* Power-up and power-down go to the block at 0x60000 and the sync reset at 0x60030 */ +static void atcphy_test_t8152_power(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 stat = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_STAT; + + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + writel(ATCPHY_POWER_SLEEP_SMALL | ATCPHY_POWER_SLEEP_BIG, core + stat); + KUNIT_EXPECT_EQ(test, atcphy_power_on(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(core + ctrl), ATCPHY_POWER_SLEEP_SMALL | + ATCPHY_POWER_SLEEP_BIG | ATCPHY_POWER_APB_RESET_N); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_SYNC_RESET), ATCPHY_MISC_RESET_N); + atcphy_test_t8152_untouched(test, atcphy); + + writel(ATCPHY_TEST_T8152_LANE0_UP, core + ACIOPHY_T8152_AON_LANE0); + writel(0, core + stat); + KUNIT_EXPECT_EQ(test, atcphy_power_off(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(core + ctrl), ATCPHY_POWER_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_SYNC_RESET), 0U); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + atcphy_test_t8152_untouched(test, atcphy); +} + +/* + * The T8152 PIPE handler does not acknowledge the lock: the request is made + * and the PIPE changes under it without waiting. Its release then finds the + * acknowledge clear at once. + */ +static void atcphy_test_t8152_pipe_lock(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void *pipehandler = kunit_kzalloc(test, PIPEHANDLER_NONSELECTED_OVERRIDE + 4, + GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, pipehandler); + atcphy->regs.pipehandler = (__force void __iomem *)pipehandler; + KUNIT_EXPECT_EQ(test, atcphy_pipehandler_lock(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ), + PIPEHANDLER_LOCK_EN); + KUNIT_EXPECT_EQ(test, atcphy_pipehandler_unlock(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ), 0U); +} + +static struct kunit_case atcphy_t8152_test_cases[] = { + KUNIT_CASE(atcphy_test_t8152_lanes), + KUNIT_CASE(atcphy_test_t8152_power), + KUNIT_CASE(atcphy_test_t8152_pipe_lock), + {} +}; + +static struct kunit_suite atcphy_t8152_test_suite = { + .name = "phy-apple-atc-t8152", + .test_cases = atcphy_t8152_test_cases, +}; + +kunit_test_suite(atcphy_t8152_test_suite); diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 34d3aa12b8f4c..347d2a4d6ec03 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -249,6 +249,44 @@ enum atcphy_lane_mode { #define ACIOPHY_BIST_MAC_USBPHY_CFG_OV2_LN0_RESET_N_OV 0x200 #define ACIOPHY_BIST_MAC_USBPHY_CFG_OV2_LN0_PWR_DOWN_OV 0x20 +/* T8152 BIST block (ACIOPHY_BIST_BLK) */ +#define ACIOPHY_T8152_BIST_CFG0 0x2400 +#define ACIOPHY_T8152_BIST_CFG0_CLOCK_EN BIT(0) +#define ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC BIT(6) + +#define ACIOPHY_T8152_BIST_CFG2 0x240c +#define ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE BIT(0) + +#define ACIOPHY_T8152_BIST_STATUS1 0x24a0 +#define ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS BIT(6) +#define ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2 BIT(7) + +#define ACIOPHY_T8152_BIST_OV1 0x24b0 +#define ACIOPHY_T8152_BIST_OV1_LN0_PIPE_RESET_N BIT(0) +#define ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN GENMASK(8, 5) + +#define ACIOPHY_T8152_BIST_OV2 0x24b8 +#define ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV BIT(5) +#define ACIOPHY_T8152_BIST_OV2_LN0_UNK6 BIT(6) +#define ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV BIT(9) +#define ACIOPHY_T8152_BIST_OV2_LN0_UNK10 BIT(10) +#define ACIOPHY_T8152_BIST_OV2_LN0 \ + (ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV | \ + ACIOPHY_T8152_BIST_OV2_LN0_UNK6 | \ + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV | \ + ACIOPHY_T8152_BIST_OV2_LN0_UNK10) + +/* T8152 lane power controls in the always-on top block (ACIOPHY_TOP_AON_BLK) */ +#define ACIOPHY_T8152_AON_LANE0 0x1e18 +#define ACIOPHY_T8152_AON_LANE_CLAMP_EN BIT(0) +#define ACIOPHY_T8152_AON_LANE_SLEEP_SMALL BIT(1) +#define ACIOPHY_T8152_AON_LANE_SLEEP_BIG BIT(2) +#define ACIOPHY_T8152_AON_LANE_AHB_RESET_N BIT(5) + +#define ACIOPHY_T8152_AON_SLEEP_CTRL2 0x1e24 +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0 BIT(12) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0 BIT(16) + #define ACIOPHY_SLEEP_CTRL 0x1b0 #define ACIOPHY_SLEEP_CTRL_TX_BIG GENMASK(1, 0) #define ACIOPHY_SLEEP_CTRL_TX_BIG_OV GENMASK(3, 2) @@ -274,6 +312,16 @@ enum atcphy_lane_mode { #define ATCPHY_MISC_RESET_N BIT(0) #define ATCPHY_MISC_LANE_SWAP BIT(2) +/* + * T8152 has the USB controller's DARTs at 0x20000 and 0x40000 of its ATC + * window, and the power and reset block (ATCPHY_CFG_BLK) follows at 0x60000. + * There the lane swap is bit 1 of 0x60008, and the reset the power-up releases + * first is bit 0 of the always-on sync reset at 0x60030. + */ +#define ATCPHY_T8152_CFG_OFFSET 0x40000 +#define ATCPHY_T8152_MISC_LANE_SWAP BIT(1) +#define ATCPHY_T8152_SYNC_RESET 0x60030 + #define ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0 0x7000 #define DP_PMA_BYTECLK_RESET BIT(0) #define DP_MAC_DIV20_CLK_SEL BIT(1) @@ -596,6 +644,7 @@ enum atcphy_generation { ATCPHY_GENERATION_T8103, ATCPHY_GENERATION_T8122, ATCPHY_GENERATION_T8132, + ATCPHY_GENERATION_T8152, }; enum atcphy_dp_link_rate { @@ -675,10 +724,18 @@ struct apple_atcphy; /** * struct atcphy_hw - SoC-specific PHY description - * @configure_post_tunable: Generation-specific setup after the tunables + * @configure_post_tunable: Generation-specific setup after the tunables, if any * @gen: Register programming generation - * @aciophy_lane_mode: Lane mode register offset + * @aciophy_lane_mode: Lane mode register offset, or zero to leave the lane + * mode alone (T8152 sets its lanes up through the crossbar) * @aciophy_crossbar: Crossbar register offset + * @cfg_offset: Offset of the power and reset block (ATCPHY_POWER_CTRL, + * ATCPHY_POWER_STAT, ATCPHY_MISC) from where those definitions + * place it + * @sync_reset: Register whose bit 0 is the reset the PHY's power-up releases + * first and its power-down asserts last, instead of + * ATCPHY_MISC_RESET_N, or zero + * @lane_swap: Lane swap bit in ATCPHY_MISC, or zero for ATCPHY_MISC_LANE_SWAP * @has_usb4: A USB4/Thunderbolt controller sits behind the PHY * @usb2_only: Uses the USB2 subset unless its banked SuperSpeed resources exist * @usb2phy_sig_host: Host role field mask, or zero for the original layout @@ -691,6 +748,9 @@ struct apple_atcphy; * still works without the latter * @park_pipe_unlocked: A stopped controller may park without a PIPE handshake * @clear_boot_hold: Release the boot PIPE hold before dummy backend selection + * @pipe_lock_unacked: The PIPE handler takes the lock request but never + * acknowledges it, so the PIPE changes under the request + * without waiting for the acknowledge * @dp_banked_tunables: DisplayPort requires separate LIOA/common calibration * @dp_t8122: DisplayPort runs the T8122 AUX, AUSPLL and lane sequences * @park_dummy_phy: Enable the dummy PIPE backend whenever the PIPE is parked on @@ -710,6 +770,9 @@ struct atcphy_hw { enum atcphy_generation gen; int aciophy_lane_mode; int aciophy_crossbar; + u32 cfg_offset; + u32 sync_reset; + u32 lane_swap; bool has_usb4; bool usb2_only; u32 usb2phy_sig_host; @@ -723,6 +786,7 @@ struct atcphy_hw { bool park_pipe_unlocked; bool park_dummy_phy; bool clear_boot_hold; + bool pipe_lock_unacked; bool restore_after_pd_off; bool idle_power_off; }; @@ -796,6 +860,11 @@ struct atcphy_cio_sleep { * behind the T6030 HDMI port; it maps only its core window * @fixed_usb2: The USB2 pairs go to a fixed hub on the USB controller, which * stays in host mode; the PHY provides USB2 from probe on + * @fixed_usb3: The SuperSpeed lanes go straight to a USB3 device or hub, with + * no Type-C mux in between (apple,fixed-usb3): the PHY runs USB3 + * on lane 0 from probe on and provides only the USB3 PHY of the + * controller, which is a host; its USB2 side and its reset are + * left to the bootloader * @typec_mode: Mode the Type-C mux last asked for; a fixed-hub port returns to * it when the PHY is brought back up after a power-off * @host_active: dwc3 has selected host mode on the USB3 PHY; a fixed-hub port @@ -910,6 +979,7 @@ struct apple_atcphy { bool dp_presets_valid[5]; bool dp_only; bool fixed_usb2; + bool fixed_usb3; enum atcphy_mode typec_mode; bool host_active; /* @@ -1276,6 +1346,65 @@ static inline u32 core_read32(struct apple_atcphy *atcphy, u32 reg) return readl(atcphy->regs.core + reg); } +/* A register of the power and reset block, see atcphy_hw.cfg_offset */ +static inline u32 atcphy_cfg(const struct apple_atcphy *atcphy, u32 reg) +{ + return reg + atcphy->hw->cfg_offset; +} + +static inline u32 atcphy_lane_swap(const struct apple_atcphy *atcphy) +{ + return atcphy->hw->lane_swap ?: ATCPHY_MISC_LANE_SWAP; +} + +/* + * T8152 keeps a lane's registers in AHB reset until the lane is powered up on + * its own, and they drop their tunables meanwhile. Power lane 0, the USB3 lane + * of a fixed-USB3 port, up after the common-a tunables: its LFPS receivers, + * then out of sleep, unclamped and out of AHB reset. Set the crossbar right + * after, before the remaining tunables, as the T8152 sequence does: 0x110 for + * USB3, i.e. USB3+DP with single PMA 0x008. atcphy_configure_lanes() writes the + * same value again later. + */ +static void atcphy_lanes_up_t8152(struct apple_atcphy *atcphy, enum atcphy_mode mode) +{ + const struct atcphy_mode_configuration *mode_cfg = atcphy_get_mode_config(atcphy, mode); + + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + + core_mask32(atcphy, atcphy->hw->aciophy_crossbar, + ACIOPHY_CROSSBAR_PROTOCOL | ACIOPHY_CROSSBAR_DP_SINGLE_PMA, + FIELD_PREP(ACIOPHY_CROSSBAR_PROTOCOL, mode_cfg->crossbar) | + FIELD_PREP(ACIOPHY_CROSSBAR_DP_SINGLE_PMA, + mode_cfg->crossbar_dp_single_pma)); +} + +/* T8152: power lane 0 down as the PHY powers down, the reverse of the above */ +static void atcphy_lanes_down_t8152(struct apple_atcphy *atcphy) +{ + core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); +} + /* Static configuration fields already read/modified by the public DP path. */ static void j700_dp_tunables(struct apple_atcphy *atcphy) { @@ -1305,6 +1434,8 @@ static void atcphy_apply_tunables(struct apple_atcphy *atcphy, enum atcphy_mode } apple_tunable_apply(atcphy->regs.core, atcphy->tunables.common[0]); + if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + atcphy_lanes_up_t8152(atcphy, mode); apple_tunable_apply(atcphy->regs.axi2af, atcphy->tunables.axi2af); apple_tunable_apply(atcphy->regs.core, atcphy->tunables.common[1]); @@ -1389,6 +1520,10 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy) if (IS_ENABLED(CONFIG_PHY_APPLE_ATC_KUNIT_TEST)) KUNIT_STATIC_STUB_REDIRECT(atcphy_pipehandler_lock, atcphy); + if (atcphy->hw->pipe_lock_unacked) { + set32(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ, PIPEHANDLER_LOCK_EN); + return 0; + } return atcphy_pipehandler_lock_timeout(atcphy, atcphy->hw->gen == ATCPHY_GENERATION_T8132 ? 6000 : PIPEHANDLER_LOCK_ACK_TIMEOUT_US); @@ -1631,6 +1766,77 @@ static int atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *atc return ret; } +/* T8152: latch the BIST override registers into the USB side of the PHY */ +static void atcphy_t8152_bist_sync(struct apple_atcphy *atcphy) +{ + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC); + core_read32(atcphy, ACIOPHY_T8152_BIST_CFG0); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC); +} + +static void atcphy_t8152_bist_ack(struct apple_atcphy *atcphy) +{ + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG2, ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG2, ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE); +} + +/* + * T8152: while the PIPE moves from the dummy PHY to this one, the BIST + * overrides hold lane 0's PIPE reset and power-down, the power-down stepping + * from P2 to P3, and the non-selected PHY override is released under them. + */ +static int atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *atcphy) +{ + void __iomem *status = atcphy->regs.core + ACIOPHY_T8152_BIST_STATUS1; + int ret, error = 0; + u32 reg; + + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_CLOCK_EN); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV1, ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, + ACIOPHY_T8152_BIST_OV1_LN0_PIPE_RESET_N | + FIELD_PREP(ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, 2)); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV2, ACIOPHY_T8152_BIST_OV2_LN0, + ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV | + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV); + atcphy_t8152_bist_sync(atcphy); + ret = readl_poll_timeout(status, reg, !(reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2), + 10, 20000); + if (ret) { + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: PHY status stuck in P2 (%#x)\n", reg); + } + atcphy_t8152_bist_ack(atcphy); + + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV1, ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, + FIELD_PREP(ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, 3)); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV2, + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV | ACIOPHY_T8152_BIST_OV2_LN0_UNK10, + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV); + atcphy_t8152_bist_sync(atcphy); + ret = readl_poll_timeout(status, reg, reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS, + 10, 130000); + if (ret) { + if (!error) + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: no PHY status in P3 (%#x)\n", reg); + } + ret = readl_poll_timeout(status, reg, !(reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2), + 10, 1000); + if (ret) { + if (!error) + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: PHY status stuck in P3 (%#x)\n", reg); + } + atcphy_t8152_bist_ack(atcphy); + + atcphy_clear_nonselected_phy_reset(atcphy); + + core_clear32(atcphy, ACIOPHY_T8152_BIST_OV2, ACIOPHY_T8152_BIST_OV2_LN0); + atcphy_t8152_bist_sync(atcphy); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_CLOCK_EN); + return error; +} + static int atcphy_configure_pipehandler_usb3_host_t8103(struct apple_atcphy *atcphy) { int ret, error = 0; @@ -1738,6 +1944,8 @@ static int atcphy_configure_pipehandler_usb3(struct apple_atcphy *atcphy, bool h ret = atcphy_configure_pipehandler_usb3_host_t8103(atcphy); else if (atcphy->hw->gen == ATCPHY_GENERATION_T8132) ret = atcphy_configure_pipehandler_usb3_host_t8132(atcphy); + else if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + ret = atcphy_configure_pipehandler_usb3_host_t8152(atcphy); else ret = atcphy_configure_pipehandler_usb3_host_t8122(atcphy); if (ret) { @@ -2147,21 +2355,23 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode mode == APPLE_ATCPHY_MODE_DP)) return j700_dp_route(atcphy, mode == APPLE_ATCPHY_MODE_DP); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX0, - FIELD_PREP(ACIOPHY_LANE_MODE_RX0, mode_cfg->lane_mode[0])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX0, - FIELD_PREP(ACIOPHY_LANE_MODE_TX0, mode_cfg->lane_mode[0])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX1, - FIELD_PREP(ACIOPHY_LANE_MODE_RX1, mode_cfg->lane_mode[1])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX1, - FIELD_PREP(ACIOPHY_LANE_MODE_TX1, mode_cfg->lane_mode[1])); + if (atcphy->hw->aciophy_lane_mode) { + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX0, + FIELD_PREP(ACIOPHY_LANE_MODE_RX0, mode_cfg->lane_mode[0])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX0, + FIELD_PREP(ACIOPHY_LANE_MODE_TX0, mode_cfg->lane_mode[0])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX1, + FIELD_PREP(ACIOPHY_LANE_MODE_RX1, mode_cfg->lane_mode[1])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX1, + FIELD_PREP(ACIOPHY_LANE_MODE_TX1, mode_cfg->lane_mode[1])); + } core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_PROTOCOL, FIELD_PREP(ACIOPHY_CROSSBAR_PROTOCOL, mode_cfg->crossbar)); if (mode_cfg->set_swap) - core_set32(atcphy, ATCPHY_MISC, ATCPHY_MISC_LANE_SWAP); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); else - core_clear32(atcphy, ATCPHY_MISC, ATCPHY_MISC_LANE_SWAP); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_DP_SINGLE_PMA, FIELD_PREP(ACIOPHY_CROSSBAR_DP_SINGLE_PMA, mode_cfg->crossbar_dp_single_pma)); @@ -2173,8 +2383,10 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode /* * The PMA FSM override below is for the T8103 generation. T8122 DP lanes * are started by the link rate sequence, see atcphy_dp_set_rate_t8122(). + * T8152 runs USB3 alone. */ - if (atcphy->hw->gen == ATCPHY_GENERATION_T8122) + if (atcphy->hw->gen == ATCPHY_GENERATION_T8122 || + atcphy->hw->gen == ATCPHY_GENERATION_T8152) return 0; if (mode_cfg->dp_lane[0]) { @@ -2707,34 +2919,43 @@ static int atcphy_power_off(struct apple_atcphy *atcphy) u32 reg; int ret; - if (atcphy->hw->gen != ATCPHY_GENERATION_T8132) { + /* A fixed-USB3 port has no DisplayPort side */ + if (atcphy->hw->gen != ATCPHY_GENERATION_T8132 && !atcphy->fixed_usb3) { ret = atcphy_disable_dp_aux(atcphy); if (ret) return ret; } /* Enable all reset lines */ - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); - core_clear32(atcphy, ATCPHY_MISC, ATCPHY_MISC_RESET_N | ATCPHY_MISC_LANE_SWAP); - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_APB_RESET_N); - - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_PHY_RESET_N); + if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + atcphy_lanes_down_t8152(atcphy); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_CLAMP_EN); + if (!atcphy->hw->sync_reset) + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), + ATCPHY_MISC_RESET_N | ATCPHY_MISC_LANE_SWAP); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_APB_RESET_N); + + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_BIG); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, !(reg & ATCPHY_POWER_SLEEP_BIG), 10, 1000); if (ret) { dev_err(atcphy->dev, "Failed to sleep atcphy \"big\"\n"); return ret; } - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_SMALL); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, !(reg & ATCPHY_POWER_SLEEP_SMALL), 10, 1000); if (ret) { dev_err(atcphy->dev, "Failed to sleep atcphy \"small\"\n"); return ret; } + /* A separate sync reset is asserted last, once the block sleeps */ + if (atcphy->hw->sync_reset) + core_clear32(atcphy, atcphy->hw->sync_reset, ATCPHY_MISC_RESET_N); + return 0; } @@ -2792,29 +3013,30 @@ static int atcphy_power_on(struct apple_atcphy *atcphy) u32 reg; int ret; - if (!atcphy->dp_only) + if (!atcphy->dp_only && !atcphy->fixed_usb3) atcphy_usb2_power_on(atcphy); - core_set32(atcphy, ATCPHY_MISC, ATCPHY_MISC_RESET_N); + core_set32(atcphy, atcphy->hw->sync_reset ?: atcphy_cfg(atcphy, ATCPHY_MISC), + ATCPHY_MISC_RESET_N); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_SMALL); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, reg & ATCPHY_POWER_SLEEP_SMALL, 100, 100000); if (ret) { dev_err(atcphy->dev, "failed to wakeup atcphy \"small\"\n"); return ret; } - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_BIG); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, reg & ATCPHY_POWER_SLEEP_BIG, 100, 100000); if (ret) { dev_err(atcphy->dev, "failed to wakeup atcphy \"big\"\n"); return ret; } - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_APB_RESET_N); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_CLAMP_EN); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_APB_RESET_N); return 0; } @@ -4265,7 +4487,8 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) apple_tunable_apply(atcphy->regs.lioa, atcphy->tunables.dp_lioa); apple_tunable_apply(atcphy->regs.lpdptx, atcphy->tunables.dp_common_config); } - atcphy->hw->configure_post_tunable(atcphy, mode); + if (atcphy->hw->configure_post_tunable) + atcphy->hw->configure_post_tunable(atcphy, mode); /* Setup AUX channel if DP altmode is requested */ if (atcphy_modes[mode].enable_dp_aux) { @@ -4284,7 +4507,7 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) return ret; /* Take the USB3 PHY out of reset */ - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_PHY_RESET_N); /* * NOTE: Not what macos does, it takes the phy out of reset right before * writing to ACIOPHY_CFG0_COMMON_SMALL, does lane configuration with phy @@ -4753,7 +4976,7 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode readl(atcphy->regs.pipehandler + PIPEHANDLER_MUX_CTRL), readl(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE), readl(atcphy->regs.pipehandler + PIPEHANDLER_T8132_USB2_CONFIG)); - if (!ret || !atcphy->fixed_usb2 || mode != PHY_MODE_USB_HOST) + if (!ret || !(atcphy->fixed_usb2 || atcphy->fixed_usb3) || mode != PHY_MODE_USB_HOST) return ret; /* @@ -4761,7 +4984,8 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode * fails, xHCI registers neither of its root hubs. Let it start, with * the PIPE parked if that works: the Type-C mux update that restores * the lanes or retries the handoff routes the PIPE, with the - * SuperSpeed port off. + * SuperSpeed port off. On a fixed-USB3 port the controller's next + * power-on of this PHY tries again. */ if (atcphy_park_pipehandler(atcphy, false)) dev_warn(atcphy->dev, "Host starts with its PIPE not parked\n"); @@ -4770,6 +4994,35 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode return 0; } +/* + * A fixed-USB3 port's controller is a host by construction. It powers this + * PHY on after its core reset, before the host starts: route the PIPE to the + * USB3 PHY then, bringing the PHY up in USB3 again first if a power-off took + * it down. A failure here would stop the controller altogether, and with it + * the USB2 side of the same device, so the host then starts with its PIPE + * parked instead. + */ +static int atcphy_usb3_power_on(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + int ret = 0; + + guard(mutex)(&atcphy->lock); + atcphy->host_active = true; + if (atcphy->mode != APPLE_ATCPHY_MODE_USB3 || atcphy->mode_dirty) + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB3); + if (!ret) + ret = atcphy_usb3_route(atcphy, true); + if (!ret) + return 0; + + if (atcphy_park_pipehandler(atcphy, false)) + dev_warn(atcphy->dev, "Host starts with its PIPE not parked\n"); + else + dev_warn(atcphy->dev, "Host starts without USB3: %d\n", ret); + return 0; +} + static int atcphy_usb3_exit(struct phy *phy) { struct apple_atcphy *atcphy = phy_get_drvdata(phy); @@ -4817,6 +5070,17 @@ static const struct phy_ops apple_atc_usb3_phy_ops = { .set_mode = atcphy_rpm_usb3_set_mode, }; +/* + * A fixed-USB3 port also routes its PIPE at power-on. Its PHY never + * runtime-suspends (see atcphy_rpm_get()), so it needs no runtime PM wrappers. + */ +static const struct phy_ops apple_atc_fixed_usb3_phy_ops = { + .owner = THIS_MODULE, + .power_on = atcphy_usb3_power_on, + .power_off = atcphy_usb3_power_off, + .set_mode = atcphy_usb3_set_mode, +}; + /* * The T8132 PHY has no DisplayPort alternate mode: its DP PHY only exists so * that a DisplayPort tunnel can get its pixel clock, see @@ -5206,7 +5470,7 @@ static struct phy *atcphy_xlate(struct device *dev, const struct of_phandle_args default: return ERR_PTR(-ENODEV); } - /* A DisplayPort-only or USB2-only instance omits the other PHYs. */ + /* A DisplayPort-, USB2- or USB3-only instance omits the other PHYs. */ return phy ?: ERR_PTR(-ENODEV); } @@ -5217,18 +5481,20 @@ static int atcphy_probe_phy(struct apple_atcphy *atcphy) const struct phy_ops *ops; } phys[] = { { &atcphy->phys.usb2, &apple_atc_usb2_phy_ops }, - { &atcphy->phys.usb3, &apple_atc_usb3_phy_ops }, + { &atcphy->phys.usb3, atcphy->fixed_usb3 ? &apple_atc_fixed_usb3_phy_ops : + &apple_atc_usb3_phy_ops }, { &atcphy->phys.dp, &apple_atc_dp_phy_ops }, }; /* * A T8132 PHY with its USB3/USB4 banks gets a DP PHY for DisplayPort * tunnels only (see atcphy_dpphy_set_mode_t8132()); creating it does - * not touch the hardware. + * not touch the hardware. A fixed-USB3 PHY gets its USB3 PHY only. */ for (int i = 0; i < ARRAY_SIZE(phys); i++) { if ((atcphy->dp_only && phys[i].phy != &atcphy->phys.dp) || - (atcphy_usb2_only(atcphy) && i != 0)) + (atcphy_usb2_only(atcphy) && i != 0) || + (atcphy->fixed_usb3 && phys[i].phy != &atcphy->phys.usb3)) continue; *phys[i].phy = devm_phy_create(atcphy->dev, NULL, phys[i].ops); if (IS_ERR(*phys[i].phy)) @@ -6412,6 +6678,14 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) bool lane_dp = tunables[i].tunable == &atcphy->tunables.lane_dp[0] || tunables[i].tunable == &atcphy->tunables.lane_dp[1]; + /* a fixed-USB3 port runs USB3 on lane 0 alone and has no axi2af window */ + if (atcphy->fixed_usb3 && + tunables[i].tunable != &atcphy->tunables.common[0] && + tunables[i].tunable != &atcphy->tunables.common[1] && + tunables[i].tunable != &atcphy->tunables.lane_usb3[0]) { + *tunables[i].tunable = NULL; + continue; + } if (!atcphy->hw->has_usb4 && (tunables[i].tunable == &atcphy->tunables.lane_usb4[0] || tunables[i].tunable == &atcphy->tunables.lane_usb4[1])) { @@ -6516,6 +6790,28 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph struct resource *res; void __iomem *addr; + /* + * A fixed-USB3 PHY has its core and PIPE windows only. On T8152 the + * core window also holds the USB controller's DARTs, so it is mapped + * without claiming it. + */ + if (atcphy->fixed_usb3) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!res) + return dev_err_probe(atcphy->dev, -EINVAL, "Missing core regs\n"); + atcphy->regs.core = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!atcphy->regs.core) + return -ENOMEM; + atcphy->res.core = res; + + addr = devm_platform_ioremap_resource_byname(pdev, "pipehandler"); + if (IS_ERR(addr)) + return dev_err_probe(atcphy->dev, PTR_ERR(addr), + "Unable to map pipehandler regs\n"); + atcphy->regs.pipehandler = addr; + return 0; + } + if (atcphy->hw->gen == ATCPHY_GENERATION_T8132 && platform_get_resource_byname(pdev, IORESOURCE_MEM, "common-config")) { static const char * const names[] = { @@ -6743,6 +7039,34 @@ static int atcphy_probe_finalize_dp_only(struct apple_atcphy *atcphy) return 0; } +/* + * A fixed-USB3 port: the bootloader hands its controller over running, with + * the controller's reset and its USB2 side its own, and no Type-C mux sits in + * front of the lanes, so there is no reset controller, mux or switch to + * register. Take the PHY from the state the bootloader left it in to USB3; the + * PIPE follows when the controller powers its USB3 PHY on, which also tries + * again if this fails, see atcphy_usb3_power_on(). + */ +static int atcphy_probe_finalize_fixed_usb3(struct apple_atcphy *atcphy) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + + atcphy_power_off(atcphy); + atcphy_setup_pipehandler(atcphy); + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB3); + if (ret) + dev_warn(atcphy->dev, "USB3 not up yet: %d\n", ret); + + ret = atcphy_probe_phy(atcphy); + if (ret) { + atcphy_configure(atcphy, APPLE_ATCPHY_MODE_OFF); + return dev_err_probe(atcphy->dev, ret, "Probing phy failed"); + } + return 0; +} + static int atcphy_probe_finalize(struct apple_atcphy *atcphy) { int ret; @@ -6751,6 +7075,8 @@ static int atcphy_probe_finalize(struct apple_atcphy *atcphy) if (atcphy->dp_only) return atcphy_probe_finalize_dp_only(atcphy); + if (atcphy->fixed_usb3) + return atcphy_probe_finalize_fixed_usb3(atcphy); /* Reset dwc3 on probe, let dwc3 (consumer) deassert it */ _atcphy_dwc3_reset_assert(atcphy); @@ -6882,6 +7208,25 @@ static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw, of_device_is_compatible(root, "apple,t8103"); } +/* + * The driver core attaches a single power domain. A fixed-USB3 PHY may list + * several, like T8152's ATC power states and PSD service: hold them all on + * while it is bound, powered up in the order they are listed. + */ +static int atcphy_probe_power_domains(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_attach_data pd_data = { .pd_flags = PD_FLAG_DEV_LINK_ON }; + struct dev_pm_domain_list *pd_list; + int ret; + + if (!atcphy->fixed_usb3 || atcphy->dev->pm_domain) + return 0; + ret = devm_pm_domain_attach_list(atcphy->dev, &pd_data, &pd_list); + if (ret < 0) + return dev_err_probe(atcphy->dev, ret, "Failed to attach power domains\n"); + return 0; +} + static void atcphy_sleep_finish_work(struct work_struct *work); static int atcphy_probe(struct platform_device *pdev) @@ -6904,6 +7249,10 @@ static int atcphy_probe(struct platform_device *pdev) atcphy->np = dev->of_node; atcphy->t8132_dp_alt = atcphy->hw->gen == ATCPHY_GENERATION_T8132 && of_property_read_bool(dev->of_node, "apple,dp-alt-mode"); + atcphy->fixed_usb3 = of_property_read_bool(dev->of_node, "apple,fixed-usb3"); + /* T8152 is supported on a fixed-USB3 port only */ + if (atcphy->hw->gen == ATCPHY_GENERATION_T8152 && !atcphy->fixed_usb3) + return dev_err_probe(dev, -ENODEV, "Only a fixed-USB3 port is supported\n"); apple_atc_tunnel_wiring(atcphy); mutex_init(&atcphy->lock); platform_set_drvdata(pdev, atcphy); @@ -6912,6 +7261,9 @@ static int atcphy_probe(struct platform_device *pdev) if (ret) return ret; ret = atcphy_load_tunables(atcphy); + if (ret) + return ret; + ret = atcphy_probe_power_domains(atcphy); if (ret) return ret; @@ -7983,12 +8335,37 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .clear_boot_hold = true, }; +/* + * T8152 as the USB3 PHY of a fixed-USB3 port: no USB4, DisplayPort or lane + * mode register and nothing to wake after the tunables. Its power domains are + * not followed: the controller's power-off and power-on of the PHY, as around + * a system sleep, take it down and up again. + */ +static const struct atcphy_hw atcphy_hw_t8152 = { + .gen = ATCPHY_GENERATION_T8152, + .aciophy_crossbar = ACIOPHY_CROSSBAR_T8103, + .cfg_offset = ATCPHY_T8152_CFG_OFFSET, + .sync_reset = ATCPHY_T8152_SYNC_RESET, + .lane_swap = ATCPHY_T8152_MISC_LANE_SWAP, + .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, + .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, + .park_dummy_phy = true, + .clear_boot_hold = true, + /* + * With the controller out of reset, the J873g front port's PIPE handler + * left the lock unacknowledged for 150 ms in both directions, while the + * PIPE moved to USB3 and back to the dummy PHY under the request. + */ + .pipe_lock_unacked = true, +}; + static const struct of_device_id atcphy_match[] = { { .compatible = "apple,t8103-atcphy", .data = &atcphy_hw_t8103 }, { .compatible = "apple,t8122-atcphy", .data = &atcphy_hw_t8122 }, { .compatible = "apple,t8132-atcphy", .data = &atcphy_hw_t8132 }, { .compatible = "apple,t8142-atcphy", .data = &atcphy_hw_t8142 }, { .compatible = "apple,t8140-atcphy", .data = &atcphy_hw_t8140 }, + { .compatible = "apple,t8152-atcphy", .data = &atcphy_hw_t8152 }, {}, }; MODULE_DEVICE_TABLE(of, atcphy_match); diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 3a7955197c9f9..d9f9aacb4d38f 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -78,7 +78,7 @@ def block(source, marker): STUBS = r''' struct atcphy_hw { enum atcphy_generation gen; bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; - bool clear_boot_hold, dp_banked_tunables; }; + bool clear_boot_hold, dp_banked_tunables, pipe_lock_unacked; }; struct device_node { const char *const *compatible; unsigned int count; }; static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { if (!root) return false; @@ -98,7 +98,7 @@ def block(source, marker): enum atcphy_pipehandler_state pipe_state; enum atcphy_mode typec_mode; bool pipe_pending, t8103_dummy_pending, t8103_usb3_retry, t8103_usb3_workaround, mode_dirty, usb_off_pending; - bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, t8140_dp_tunables, dp_tunables; + bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, fixed_usb3, t8140_dp_tunables, dp_tunables; /* T8132 ownership is tested without entering its lane-setup backend. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; struct { void *usb3_dp; } tunables; @@ -185,6 +185,9 @@ def block(source, marker): static int atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *a) { (void)a; assert(!"T8132 PIPE setup reached"); return -EINVAL; } +static int atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *a) { + (void)a; assert(!"T8152 PIPE setup reached"); return -EINVAL; +} static void atcphy_usb2_power_on(struct apple_atcphy *a) { (void)a; assert(!"USB2-only power restore reached"); } diff --git a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py index 7eeb90baf4385..ed02e7f33b562 100755 --- a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py +++ b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py @@ -92,7 +92,8 @@ def main(): ''' declarations = r''' struct apple_tunable { unsigned id; }; -struct atcphy_hw { int gen; bool usb2_only, has_usb2phy_reg, park_pipe_unlocked; u32 usb2phy_sig_host; }; +struct atcphy_hw { int gen; bool usb2_only, has_usb2phy_reg, park_pipe_unlocked; u32 usb2phy_sig_host; + u32 cfg_offset, sync_reset; }; enum suspend_state { PM_SUSPEND_TO_IDLE = 1, PM_SUSPEND_MEM = 3 }; static enum suspend_state pm_suspend_target_state; static bool rpm_suspended; @@ -106,7 +107,7 @@ def main(): bool t8132_ss, t8132_common_owned, t8132_suspended, t8132_failed, host_active; bool ss_tunables, mode_dirty, pipe_pending, swap_lanes; bool cio_tunables, t8132_dp_alt, fixed_usb2, hibernated, pd_was_off, idle_rpm; - bool t8103_dummy_pending, t8103_usb3_workaround; + bool t8103_dummy_pending, t8103_usb3_workaround, fixed_usb3; unsigned tunnel_users; struct { bool prepared, changed, restored; } cio_sleep; int mode, pipe_state, lock; @@ -122,6 +123,8 @@ def main(): struct device { struct apple_atcphy *atc; }; static struct apple_atcphy *dev_get_drvdata(struct device *d) { return d->atc; } static struct apple_atcphy *phy_get_drvdata(struct phy *p) { return p->atc; } +/* T8152 only: these rows run T8132, which never reaches it. */ +static void atcphy_lanes_down_t8152(struct apple_atcphy *a) { (void)a; assert(0); } static u32 core[0x24000/4], usb2[0x4000/4], pipe_regs[0x4000/4]; static unsigned tunes[16], tune_count, reset_releases, bist_phase, writes, core_reads; static unsigned stall_power, stall_bist, expected_tunes, stall_sleep; @@ -215,7 +218,7 @@ def main(): } ''' names = ["atcphy_mode_is_cio", "atcphy_usb2_sig_host", "atcphy_t8132_dp_on", - "atcphy_usb2_power_off", "atcphy_power_off", "atcphy_usb2_power_on", + "atcphy_cfg", "atcphy_usb2_power_off", "atcphy_power_off", "atcphy_usb2_power_on", "atcphy_t8132_cold", "atcphy_t8132_common_start", "atcphy_t8132_phy_stop", "atcphy_t8132_full_stop", "atcphy_configure_t8132", "atcphy_usb2_set_mode", "atcphy_t8132_bist_pulse", diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py index 980a7a8773b97..aee2f68cc7bed 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py @@ -194,6 +194,18 @@ def atc_cio_helpers(source): return result +def atc_cfg_helpers(source): + """Where the power and reset block sits and which bit swaps the lanes, both of + which T8152 moves; the power-up, power-down and lane functions call these. + + Marked unused, as a unit may extract only some of their callers. Older + sources have neither: ''. + """ + return ''.join(atc_function(source, name).replace( + 'static inline ', 'static inline __attribute__((unused)) ', 1) + for name in ('atcphy_cfg', 'atcphy_lane_swap')) + + def atc_restore_helpers(source): """What atcphy_restore_after_pd_off() needs beyond the parking helpers. diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index cc3197c1b738a..a2d8076ac8b3d 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -25,7 +25,7 @@ struct apple_atcphy { bool aux, pll; unsigned int pairs, rate; } dp_t8122; - bool fixed_usb2, host_active, mode_dirty, ss_tunables, dp_tunables, + bool fixed_usb2, fixed_usb3, host_active, mode_dirty, ss_tunables, dp_tunables, aux_power_requested; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; @@ -252,11 +252,15 @@ static void atcphy_restore_after_pd_off(struct apple_atcphy *p); static int atcphy_power_off(struct apple_atcphy *p); static int atcphy_configure(struct apple_atcphy *p, enum atcphy_mode mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } /* Model the USB2 power-on boundary's running state. */ diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index e41e10447eb22..2fc3385d1df6e 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -3,7 +3,7 @@ """Actual disconnect authority, DWC3 teardown and firmware resource admission.""" from pathlib import Path import re -from common import block, apple_function, internal_inline, atc_mux_without_pm, source_defines, ATC_POST_TUNABLE, tipd_pm_header, firmware_lineage, atc_restore_helpers, atc_cio_helpers +from common import block, apple_function, internal_inline, atc_mux_without_pm, source_defines, ATC_POST_TUNABLE, tipd_pm_header, firmware_lineage, atc_restore_helpers, atc_cio_helpers, atc_cfg_helpers def disconnect(root): # Copyright 2026 Ryan Murray @@ -1182,7 +1182,7 @@ def fn(n, name): names = {n: tuple(name for name in group if re.search(r'^(?:static [^\n]*\b|(?:int|void) )' + name + r'\(', files[n], re.M)) for n, group in names.items()} context = (fn('atc', 'core_read32') + '\n' + fn('atc', 'atcphy_get_mode_config') + '\n' + fn('atc', 'j700_field_update') + '\n' + files['dp'][files['dp'].index('/* Masks are the union'):files['dp'].index('/* Retry only the idle operations')]) - functions = atc_cio_helpers(files['atc']) + '\n\n'.join(fn(n, name) for n, group in names.items() for name in group) + functions = atc_cio_helpers(files['atc']) + atc_cfg_helpers(files['atc']) + '\n\n'.join(fn(n, name) for n, group in names.items() for name in group) definitions = [] lines = iter(files['atc'].splitlines()) for line in lines: diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 26c0f62dabb25..45c8275bf462e 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -5,7 +5,7 @@ import re from common import (block, source_defines, atc_mux_without_pm, ATC_POST_TUNABLE, atc_function, ATC_SPLIT, ATC_T8103_LIVE, atc_restore_helpers, atc_common_state_helpers, - atc_cio_helpers) + atc_cio_helpers, atc_cfg_helpers) def parking(root): @@ -46,7 +46,7 @@ def function(source, name): struct reset_controller_dev rcdev; void *dev; int lock, dp_link_rate; - bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; @@ -67,6 +67,7 @@ def function(source, name): start = atc.index('static const struct {\n\tconst struct atcphy_mode_configuration normal;') parts.append(atc[start:atc.index('\n};', start) + 3]) parts.append(atc_cio_helpers(atc)) + parts.append(atc_cfg_helpers(atc)) parts.append(r''' struct phy_configure_opts_dp { unsigned int link_rate, lanes, voltage[4], pre[4]; @@ -160,11 +161,15 @@ def function(source, name): static int atcphy_power_off(struct apple_atcphy *); static int atcphy_configure(struct apple_atcphy *, enum atcphy_mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } ''') @@ -1948,7 +1953,7 @@ def function(name): struct { unsigned char *core, *pipehandler; } regs; void *dev; int lock; - bool fixed_usb2, host_active, ss_tunables, dp_tunables, mode_dirty; + bool fixed_usb2, fixed_usb3, host_active, ss_tunables, dp_tunables, mode_dirty; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; u32 dp_usb_context[2][27]; @@ -1993,11 +1998,13 @@ def function(name): static void __attribute__((unused)) atcphy_restore_after_pd_off(struct apple_atcphy *p) { assert(!p->pd_was_off); } static int atcphy_configure(struct apple_atcphy *p, enum atcphy_mode mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } ''') for name in ('core_read32', 'atcphy_get_mode_config'): @@ -2348,7 +2355,7 @@ def function(source, name): struct { unsigned char *core, *lpdptx, *lioa; } regs; void *dev; int lock, dp_link_rate; - bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; @@ -2364,6 +2371,7 @@ def function(source, name): start = atc.index('static const struct {\n\tconst struct atcphy_mode_configuration normal;') parts.append(atc[start:atc.index('\n};', start) + 3]) parts.append(atc_cio_helpers(atc)) + parts.append(atc_cfg_helpers(atc)) parts.append(r''' struct phy_configure_opts_dp { unsigned int link_rate, lanes, voltage[4], pre[4]; @@ -2424,11 +2432,13 @@ def function(source, name): static int atcphy_power_off(struct apple_atcphy *); static int atcphy_configure(struct apple_atcphy *, enum atcphy_mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } static int atcphy_park_pipehandler(struct apple_atcphy *p, bool keep_dp) From 8fa030f644687ba5b2621da0f0424c1210565afd Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 22:14:52 +0100 Subject: [PATCH 102/121] arm64: dts: apple: j873: USB3 on the front ports The two front USB-C ports sit behind an on-board VL822 hub on usb-drd2. The hub's USB2 side is on the controller's eUSB2 PHY, which the loader sets up, and its USB3 side on ATC2's Type-C PHY, wired directly without a Type-C mux. So far the controller was limited to high speed and the hub ran at USB2 only. Describe ATC2's PHY as an apple,t8152-atcphy with apple,fixed-usb3, hand it to usb-drd2 as its USB3 PHY and drop the controller's high-speed limit. Nothing changes for usb-drd1 (the back-left port). The PHY's power domains are ATC2's USB_AON, COMMON_DP_0 and COMMON_DP_1 PMGR power states, in a new node for the ATCs' block of PMGR states at 0x308290000, and its common domain, PSD service 57 (ADT clock-gates 57). The T8152 USB3 bring-up runs the power states without automatic power management, so they are marked apple,no-auto-pm. The tunables are the groups of the ADT's atc-phy2 node (26A434) that apply to USB3 on lane 0, in the order they are applied: the common and PLL defaults as common-a, the fabric, PLL and USBC0 groups as common-b and the lane 0 groups as lane0-usb. Some of them differ between the four ATCs of the same machine, so they likely carry per-device calibration. There is no atcphy2 alias, as the loader's ATC tunable copy would replace them with values for another PHY layout. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 311 ++++++++++++++++-- 1 file changed, 275 insertions(+), 36 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index 924df52e3622b..2085434c423ff 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -1,15 +1,18 @@ // 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). + * J873g USB host bring-up: usb-drd1 (back-left port, USB2) and usb-drd2 + * (front ports via the on-board hub, USB2 and USB3). * 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 ATC PHY or Type-C + * PHYs for host mode before Linux starts (there is no T8152 USB2 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 on the Type-C port * the role switch, exist but are left to the loader. + * usb-drd2's hub is wired to ATC2's PHY without a Type-C mux, so Linux brings + * that PHY up in USB3 mode (atc2_phy). * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2 (on atc-phy1 and - * atc-phy2) and the pmgr devices ATC1_USB_AON/USB and ATC2_USB_AON/USB. + * atc-phy2), atc-phy2 and the pmgr devices ATC1_USB_AON/USB, ATC2_USB_AON/USB + * and ATC2_COMMON_DP_0/1. * * 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 @@ -19,6 +22,8 @@ * own window only, and describe instance 1 as a node of its own. */ +#include + &dwc3_1_dart { reg = <0x4 0x0b020000 0x0 0xc000>; power-domains = <&ps_atc1_usb>; @@ -33,15 +38,47 @@ / { soc { + dwc3_1_dart_1: iommu@40b040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_atc1_usb>; + }; + + usb1: usb@40a430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; + power-domains = <&ps_atc1_usb>; + 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>; + power-domains = <&ps_atc2_usb>; + }; + /* - * The ATCs' PMGR power states (ADT pmgr devices ATCn_USB_AON and - * ATCn_USB from 0x308290100, 0x40 apart per ATC). The ADT gives - * usb-drd1/2 service-gates 175/176, but those PSD service blocks - * (0x303a1af00, 0x303a1b000) take a bus error from the CPU. + * The ATCs' PMGR power states (ADT pmgr devices ATCn_COMMON_DP_0/1 + * from 0x308290000 and ATCn_USB_AON/USB from 0x308290100, 0x40 + * apart per ATC). The T8152 USB bring-up runs them without + * automatic power management. * - * The loader leaves them on; they hold the controllers' reset and - * the USB2 PHY setup it did, which Linux cannot redo yet. So they - * stay on, without automatic power management. + * ATCn_USB is the controller's state. The ADT also gives + * usb-drd1/2 service-gates 175/176, but those PSD service blocks + * (0x303a1af00, 0x303a1b000) take a bus error from the CPU. The + * loader leaves ATCn_USB and ATCn_USB_AON on; they hold the + * controllers' reset and the USB2 PHY setup it did, which Linux + * cannot redo yet, so they stay on. ATC2_COMMON_DP_0/1 are what + * ATC2's PHY needs besides. */ pmgr_atc: power-management@308290000 { compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", @@ -50,6 +87,26 @@ #size-cells = <1>; reg = <0x3 0x08290000 0x0 0x1000>; + ps_atc2_common_dp_0: power-controller@80 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x80 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc2_common_dp_1: power-controller@a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xa0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_1"; + apple,no-auto-pm; + }; + ps_atc1_usb_aon: power-controller@140 { compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; @@ -73,6 +130,11 @@ apple,always-on; }; + /* + * Kept on: it holds the USB controller's reset and the + * PIPE handler state the loader set up. Switched off, the + * controller stays in reset until the next boot. + */ ps_atc2_usb_aon: power-controller@180 { compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; @@ -97,32 +159,208 @@ }; }; - dwc3_1_dart_1: iommu@40b040000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x4 0x0b040000 0x0 0xc000>; - interrupts = ; - #iommu-cells = <1>; - power-domains = <&ps_atc1_usb>; - }; - - usb1: usb@40a430000 { - compatible = "apple,t8152-dwc3"; - reg = <0x4 0x0a430000 0x0 0xcd00>; - interrupts = ; - dr_mode = "host"; - maximum-speed = "high-speed"; - iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; - power-domains = <&ps_atc1_usb>; - snps,dis_u2_susphy_quirk; - snps,dis_u3_susphy_quirk; + /* ATC2's common domain: PSD service 57 (ADT atc-phy2 clock-gates). */ + ps_atc2_common: power-controller@303a13900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13900 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc2_common"; }; - dwc3_2_dart_1: iommu@383040000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x3 0x83040000 0x0 0xc000>; - interrupts = ; - #iommu-cells = <1>; - power-domains = <&ps_atc2_usb>; + /* + * ADT atc-phy2 as usb-drd2's USB3 PHY: the hub is wired to its + * lanes directly. The power domains are listed in the order the + * PHY needs them powered up. The tunables are the atc-phy2 + * tunable_* groups of the 26A434 ADT that apply to USB3 on lane + * 0, in the order they are applied: common-a before lane 0 is + * powered up and the crossbar set, then common-b and lane0-usb. + * Some of them differ between the four ATCs of the same machine, + * so they likely carry per-device calibration. There is no + * atcphy2 alias: the loader's ATC tunable copy would then replace + * these with values for another PHY layout. + */ + atc2_phy: phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x3 0x83000000 0x0 0x84000>, + <0x3 0x82414000 0x0 0x4000>; + reg-names = "core", "pipehandler"; + #phy-cells = <1>; + apple,fixed-usb3; + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_common>, + <&ps_atc2_common_dp_0>, <&ps_atc2_common_dp_1>; + apple,tunable-common-a = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc27>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + /* 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>, + /* CIOPLL_TOP_DFLT */ + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + /* ACIOPHY_USBC0_DFLT */ + <0x15c04 0x0f000000 0x00000000>, + <0x15c0c 0x0007c000 0x00020000>, + /* ACIOPHY_USBC0_USB */ + <0x15c50 0x60000000 0x00000000>; + apple,tunable-lane0-usb = + /* LN0_ARBITER_REGS_DFLT */ + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + /* LN0_RX_TOP_REGS_DFLT */ + <0x08cf4 0x00000020 0x00000020>, + /* LN0_RX_DFE_REGS_DFLT */ + <0x077c4 0x0003ff00 0x0000fa00>, + /* LN0_SMGR_REGS_DFLT */ + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + /* LN0_RXAEQ_TOP_REGS_DFLT */ + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + /* LN0_RX_SHM_REGS_DFLT */ + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + /* LN0_TXSEQ_REGS_DFLT */ + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + /* LN0_TX_SHM_AHB_DFLT */ + <0x04fd4 0x03800000 0x02800000>, + /* LN0_TX_TXSPL_CM_DFLT */ + <0x04e20 0x00fff000 0x00723000>, + /* LN0_ASDC_TXSPL_CM_DFLT */ + <0x08980 0x00fff000 0x00723000>, + /* LN0_DIV40_REGS_DFLT */ + <0x085e4 0x00000004 0x00000000>, + /* LN0_RX_PCTRL_REGS_DFLT */ + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + /* LN0_CTLE_EQ_REGS_DFLT */ + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + /* L0_RXCALACC_HALFUI_DFLT */ + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + /* L0_RXCALACC_EDSKEW_DFLT */ + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + /* LN0_TXSPL_TXDCC_DFLT */ + <0x04d84 0x001c0000 0x00000000>, + /* LN0_SMGR_REGS_USB */ + <0x07d88 0x000000f0 0x00000030>, + <0x07da8 0xff000000 0x44000000>, + <0x07dd8 0x00003000 0x00003000>, + /* LN0_DETECTOR_REGS_USB */ + <0x0848c 0x00008000 0x00000000>, + /* LN0_DIV40_REGS_USB */ + <0x08594 0x00000001 0x00000001>, + <0x085b0 0x0000ffff 0x00001010>, + <0x085b8 0x0000ffff 0x00001010>, + <0x085cc 0x68100000 0x00000000>, + <0x085d0 0x68100000 0x00000000>, + /* LN0_CTLE_EQ_REGS_USB */ + <0x07fdc 0x000001ff 0x000000b4>, + <0x07fe0 0x000001ff 0x000000aa>, + /* LN0_RXAEQ_TOP_REGS_USB */ + <0x07a1c 0x00000ff8 0x00000578>, + <0x07a2c 0x0003ffff 0x000154b4>, + <0x07bb8 0x00007000 0x00000000>, + /* LN0_TXSEQ_REGS_USB */ + <0x04ca0 0x00000002 0x00000000>; }; /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ @@ -131,7 +369,8 @@ reg = <0x3 0x82430000 0x0 0xcd00>; interrupts = ; dr_mode = "host"; - maximum-speed = "high-speed"; + phys = <&atc2_phy PHY_TYPE_USB3>; + phy-names = "usb3-phy"; iommus = <&dwc3_2_dart 0>, <&dwc3_2_dart_1 1>; power-domains = <&ps_atc2_usb>; snps,dis_u2_susphy_quirk; From 9dc9156afa51fdb33d417831743e10b6182e3aed Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 14:31:49 +0100 Subject: [PATCH 103/121] 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 c4fc0a9c05b84b5fa830189494152a4de0c44604 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 14:31:49 +0100 Subject: [PATCH 104/121] 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 3883ee10186f3..2a9f18f99c8eb 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[]; /** @@ -3393,8 +3409,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; @@ -3431,19 +3464,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; } @@ -3477,7 +3497,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)) { @@ -7563,6 +7583,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 7fb6b9465e2e38a045371eacf66eacf6cca65609 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:58:23 +0100 Subject: [PATCH 105/121] 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 afb1541e14112e3f4ebc9ddaab7eecbc9e176a40 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:08 +0100 Subject: [PATCH 106/121] 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 f2cc6a7c82bec5cd72077223c3f3c4aacb58c116 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 107/121] 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 d3107c22e9898713a6dc7282081abe1e0a294bc7 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 108/121] 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 like the display ones, but start unlocked with inactive streams. 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 | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index d7e8e332951ad..c3d2b8bd72bb1 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -33,6 +33,8 @@ properties: - apple,t8110-dart - apple,t6000-dart - apple,t8152-dart-gen3 + - apple,t8152-acio-dart + - apple,t8152-pciec-dart - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -369,7 +371,10 @@ allOf: properties: compatible: contains: - const: apple,t8152-dart-gen3 + enum: + - apple,t8152-dart-gen3 + - apple,t8152-acio-dart + - apple,t8152-pciec-dart then: description: The T8152 Gen3 DARTs in front of the display coprocessors and their @@ -377,7 +382,10 @@ 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 DARTs of the rear USB4 + routers (ACIO NHI streams) and of their PCIe-C tunnels use the same + invalidation aperture, each at its own slot, but start unlocked with + inactive streams and are initialized by the operating system. properties: reg: minItems: 2 @@ -395,6 +403,18 @@ allOf: - const: dart - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - if: + properties: + compatible: + contains: + enum: + - apple,t8152-acio-dart + - apple,t8152-pciec-dart + then: + required: + - apple,dma-range + - apple,tunable + additionalProperties: false examples: From 8b09e83ce106af60e683a4dc9e9713ab082874d3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 109/121] iommu: apple-dart: initialize the cold T8152 ACIO and PCIe-C DARTs The DARTs of the T8152 USB4 routers and their PCIe-C tunnels are Gen3 DARTs that, unlike the display ones, the bootloader leaves unlocked with inactive streams. Admit cold Gen3 setup for the instances their compatibles select, with version 0x300, their tunables and inactive streams, and initialize them before enabling translation: clear the streams, apply the tunables and invalidate through the Gen3 TLBI aperture, which is now mapped before the reset. Domains use two-level 16K tables inside a single 64 GiB DMA window, as iBoot's display streams do. - ACIO DART (apple,t8152-acio-dart): 32 streams, 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; it must be tunnelled and have its power domain. 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. The locked display DARTs and all other Gen3 instances stay as they were. Signed-off-by: Thomas Glanzmann --- drivers/iommu/apple-dart.c | 144 ++++++++++++++---- .../drivers/apple/bcm4377-radio-sids.py | 2 + 2 files changed, 118 insertions(+), 28 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 938e6f519efa6..3cd266e6cf7c4 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -361,6 +361,9 @@ struct apple_dart_fw_tree { #define APPLE_DART_GAPF_PROTECT BIT(4) struct apple_dart { + bool cold_gen3; + u32 cold_gen3_sids; + bool cold_gen3_pcie; struct device *dev; const struct apple_dart_hw *hw; @@ -2661,6 +2664,39 @@ 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); + 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, 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); + } + if (dart->isp_host) return apple_dart_isp_host_reset(dart); if (dart->managed_sids || dart->cold_ane) @@ -3393,6 +3429,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; @@ -4014,6 +4061,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) @@ -5548,6 +5598,15 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); dart->tunneled = tunneled; + 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)) @@ -5754,7 +5813,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); @@ -5770,7 +5829,15 @@ 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 = 42; + 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; @@ -5967,6 +6034,51 @@ static int apple_dart_probe(struct platform_device *pdev) ret = -EBUSY; goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* 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->tunables || + (dart->cold_gen3_pcie ? (!tunneled || !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) { + 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", @@ -6107,32 +6219,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); @@ -7394,6 +7480,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-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 }, diff --git a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py index e13025a6157c5..4fa142bdf5c25 100755 --- a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py +++ b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py @@ -106,6 +106,8 @@ def main(): bool four_level, per_stream, tunneled, fw_mirror, fw_handoff; bool pending, preserve_display; bool isp_host, cold_ane, live_mtp, display_dark, display_tlb_stale; + bool cold_gen3, cold_gen3_pcie; + u32 cold_gen3_sids; void *tunables; unsigned long static_bypass[4]; void *dcp, *frontend[2]; From c150eb3301ab238fd10cc67d17ee16dec9d2caf8 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 110/121] 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 f1aece361ba2cb8a01e756810618446edef186cb Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Thu, 19 Nov 2026 19:59:15 +0100 Subject: [PATCH 111/121] 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 2a9f18f99c8eb..2d59ba7c0191f 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[]; /** @@ -3409,7 +3425,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 @@ -3497,7 +3514,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)) { @@ -7584,6 +7602,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 cec1b6b93a2bb6c5992c2ef8792e0ddcbfd171ea Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 112/121] dt-bindings: thunderbolt: add the T8152 USB4 routers 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. Signed-off-by: Thomas Glanzmann --- .../thunderbolt/apple,t8103-usb4-acio.yaml | 30 +++++++++++++++++-- .../thunderbolt/apple,t8103-usb4-nhi.yaml | 3 ++ 2 files changed, 31 insertions(+), 2 deletions(-) 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: From 8b57c0308e721d3a9de6d573b6ddc7e2bbdd979c Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Tue, 17 Nov 2026 23:21:09 +0100 Subject: [PATCH 113/121] 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 e21cf99212eba..a22d8129a7b32 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 != @@ -3097,6 +3112,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", }, @@ -3307,6 +3323,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 @@ -3317,7 +3353,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) @@ -3342,12 +3378,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; @@ -3608,12 +3639,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; } @@ -4773,6 +4799,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 e9894bba4c9f4932baca9a838239c666286b4f32 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:21:48 +0100 Subject: [PATCH 114/121] dt-bindings: phy: apple,atcphy: add the T8152 Type-C ports in CIO mode The J873g's three rear USB-C ports have T8152 ATC PHYs behind a Type-C mux, with a USB4 router behind each. Linux runs them in CIO (USB4) mode only for now: their DisplayPort alt mode is still driven by the display controllers, and their USB2 side by the bootloader. Allow a T8152 PHY without apple,fixed-usb3 for such a port: its core bank alone (the power and reset block at 0x60000 is part of it, and the display controllers map the same bank), the orientation and mode switches with port@0 to the connector's SuperSpeed port, the ATC's four power domains in power-up order, and the common and lane CIO tunables. The display controller takes the PHY through its DisplayPort PHY. Signed-off-by: Thomas Glanzmann --- .../devicetree/bindings/phy/apple,atcphy.yaml | 89 +++++++++++++++---- 1 file changed, 72 insertions(+), 17 deletions(-) diff --git a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml index 783f6732fae3a..d3e7f3722d214 100644 --- a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml @@ -40,12 +40,17 @@ description: > DisplayPort also requires separate bootloader-provided calibration lists for that bank and the common configuration in the lpdptx region. - The T8152 variant is supported as the USB3 PHY of a fixed-USB3 port only, - see apple,fixed-usb3. It is described by its core and pipehandler banks; the - core bank also holds the USB controller's DARTs. Its power domains are the - ATC's PMGR power states and PSD service the PHY needs, in the order they are - powered up. Lane 0 is powered up and the crossbar set between the common-a - tunables and the others. + The T8152 variant is supported as the USB3 PHY of a fixed-USB3 port, see + apple,fixed-usb3, and as the PHY of a Type-C port in USB4/Thunderbolt + ("Converged IO", CIO) mode alone. Its core bank also holds the USB + controller's DARTs. Its power domains are the ATC's PMGR power states and + PSD service the PHY needs, in the order they are powered up. The lanes of + the mode are powered up and the crossbar set between the common-a tunables + and the others. A fixed-USB3 port is described by its core and pipehandler + banks. A Type-C port is described by its core bank alone: its DisplayPort + alternate mode is driven by the display controller, which takes the PHY + through its DisplayPort PHY (PHY_TYPE_DP) and has the PHY's power domains + powered while it drives it, and its USB2 side is left to the bootloader. allOf: - $ref: /schemas/usb/usb-switch.yaml# @@ -137,12 +142,14 @@ allOf: then: properties: reg: + minItems: 1 items: - description: PHY core with its power and reset block, which also holds the USB controller's DARTs - - description: USB3 PIPE interface controls + - description: USB3 PIPE interface controls (fixed-USB3 port) reg-names: + minItems: 1 items: - const: core - const: pipehandler @@ -189,11 +196,28 @@ allOf: then: properties: "#reset-cells": false - mode-switch: false - orientation-switch: false - ports: false - required: - - apple,fixed-usb3 + if: + required: + - apple,fixed-usb3 + then: + properties: + mode-switch: false + orientation-switch: false + ports: false + reg: + minItems: 2 + reg-names: + minItems: 2 + else: + properties: + reg: + maxItems: 1 + reg-names: + maxItems: 1 + required: + - mode-switch + - orientation-switch + - ports else: properties: apple,fixed-usb3: false @@ -382,11 +406,12 @@ properties: apple,fixed-usb3: type: boolean description: > - T8152 only, and required there. The port's SuperSpeed lanes go straight - to a USB3 device or hub, with no Type-C mux in between, so the PHY runs - USB3 on lane 0 from probe on and ignores mux and orientation changes. It - provides only the USB3 PHY of its USB controller, which is a host, and - leaves the controller's USB2 side and reset to the bootloader. + T8152 only. The port's SuperSpeed lanes go straight to a USB3 device or + hub, with no Type-C mux in between, so the PHY runs USB3 on lane 0 from + probe on and ignores mux and orientation changes. It provides only the + USB3 PHY of its USB controller, which is a host, and leaves the + controller's USB2 side and reset to the bootloader. Without it a T8152 + PHY is a Type-C port's, run in CIO mode alone. apple,dp-alt-mode: type: boolean @@ -707,4 +732,34 @@ examples: apple,tunable-common-b = <0x6c004 0x003f003f 0x00200020>; apple,tunable-lane0-usb = <0x082d8 0xf0000000 0x70000000>; }; + + phy@413000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x13000000 0x0 0x84000>; + reg-names = "core"; + + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_common>, + <&ps_atc3_common_dp_0>, <&ps_atc3_common_dp_1>; + + apple,tunable-common-a = <0x00800 0x00fc0000 0x00fc0000>; + apple,tunable-common-b = <0x6c004 0x003f003f 0x00200020>; + apple,tunable-lane0-cio = <0x082d8 0xf0000000 0x70000000>; + apple,tunable-lane1-cio = <0x112d8 0xf0000000 0x70000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + endpoint { + remote-endpoint = <&typec3_ss>; + }; + }; + }; + }; }; From e55caa0c1d62c2e7e8b44e471e90c314ad6b6afe Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:02 +0100 Subject: [PATCH 115/121] phy: apple: atc: run the T8152 Type-C ports in CIO mode The J873g's three rear USB-C ports have T8152 ATC PHYs with a USB4 router behind each. Their DisplayPort alt mode is still programmed by the display driver (drm/apple's T8152 code), and their USB2 side is the bootloader's. Run such a PHY in CIO mode for a USB4 partner and leave it to the display driver otherwise, as a Type-C port of its own kind (cio_only, selected by the T8152 match data for a PHY without apple,fixed-usb3). The Type-C port driver sets the mux before it starts the router and after it stops it, as on T8142. CIO mode uses the T8152 layout of the fixed-USB3 support: the power and reset block at 0x60000 with the sync reset at 0x60030, the crossbar at 0x4c (USB4 0, USB4 swapped 1), no lane mode register. It differs from USB3 in that both lanes are powered up, one after the other, between the common-a tunables and the others (LFPS receivers 0x1e24 bits 12/16 and 14/18, then the lane controls at 0x1e18 and 0x1e1c out of sleep, unclamped and out of AHB reset), and in that a reversed plug sets the lane swap (bit 1 of 0x60008) next to the swapped crossbar, where T8142 leaves it clear. On the way down AUX is clamped (0x1e24 bit 10, sleeps 6 and 8 cleared) and both lanes' LFPS receivers are dropped before the lanes, as the T8152 CIO shutdown does: these always-on controls keep their state while the common block is off. The lanes are only touched while the register bus (0x60000 bit 3) is out of reset. This is the sequence the earlier port monitor ran, with which a rear port trained USB4 at 2 x 20 Gb/s and carried an NVMe enclosure at 16 GT/s x4. The PHY's four power domains (USB_AON, the common PSD service, DP_0, DP_1) are attached without device links. They are held while the PHY runs CIO mode, and dropped synchronously after the CIO shutdown, so that the common block goes cold before the next partner: a training from a powered common block asserted in the router's firmware. The PHY and the display driver take turns, explicitly: - The display driver powers the PHY's DP PHY on before it touches the PHY and off when it has let go of it. The DP PHY holds the domains for it and keeps CIO mode out: a USB4 mode change fails with -ETIMEDOUT, and the mux declares its timeouts transient, so the port driver retries until the display is gone. A DP PHY power-on in CIO mode fails with -EBUSY. - Either takes the PHY only when its power and reset block is as its power-up leaves it (0x60000 = 0x4, no sleep acknowledged, sync reset 0); CIO mode is refused otherwise. - A display the bootloader started has all four domains on and a busy block at probe. Its domains are then held for the display driver, which takes the PHY over, until its DP PHY goes off. Once DisplayPort moves into this driver, the DP PHY programs it itself, both modes switch under the PHY's lock and this arbitration goes away. Thunderbolt alt mode is refused on these ports for now: the T8152 routers have only been run with USB4 partners. The other SoCs are unchanged: the new paths are taken for a cio_only PHY or the T8152 generation only, and T8152 now sets has_usb4, which a fixed-USB3 port's tunable list does not consult. KUnit cases check the CIO lanes, crossbar and swap in both orientations, the power-down, the idle test and which Type-C states ask for CIO. The DCP host-test fixtures that compile the power-up and power-down get the new field. Signed-off-by: Thomas Glanzmann --- drivers/phy/apple/atc-test.c | 129 ++++- drivers/phy/apple/atc.c | 462 ++++++++++++++++-- .../selftests/drivers/apple/atc-t8132-usb3.py | 2 +- .../drivers/gpu/apple-dcp/dwc3/mocks.c | 2 +- .../selftests/drivers/gpu/apple-dcp/phy.py | 6 +- 5 files changed, 541 insertions(+), 60 deletions(-) diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index a34e19b1ab432..000f8c28834da 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -1493,8 +1493,8 @@ static void atcphy_test_t8152_lanes(struct kunit *test) atcphy_lanes_up_t8152(atcphy, APPLE_ATCPHY_MODE_USB3); KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), ATCPHY_TEST_T8152_LANE0_UP); KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), - ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0 | - ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0); + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(0) | + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(0)); KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), 0x110U); KUNIT_EXPECT_EQ(test, atcphy_configure_lanes(atcphy, APPLE_ATCPHY_MODE_USB3), 0); @@ -1550,10 +1550,135 @@ static void atcphy_test_t8152_pipe_lock(struct kunit *test) KUNIT_EXPECT_EQ(test, readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ), 0U); } +/* Both LFPS receivers of a lane on */ +static u32 atcphy_test_t8152_lfps(unsigned int lane) +{ + return ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane) | + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane); +} + +/* + * CIO on a rear port: both lanes powered up one after the other, the USB4 + * crossbar by the orientation, the lane swap for a reversed plug too, and on + * the way down both lanes clamped, their LFPS receivers off and AUX clamped. + */ +static void atcphy_test_t8152_cio_lanes(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 misc = ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC; + + atcphy->fixed_usb3 = false; + atcphy->cio_only = true; + for (int reversed = 0; reversed < 2; reversed++) { + atcphy->swap_lanes = reversed; + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE(0)); + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE(1)); + writel(ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN, + core + ACIOPHY_T8152_AON_SLEEP_CTRL2); + writel(reversed ? 0 : ATCPHY_T8152_MISC_LANE_SWAP, core + misc); + writel(ACIOPHY_CROSSBAR_DP_SINGLE_PMA_UNK100 << 5 | ACIOPHY_CROSSBAR_DP_BOTH_PMA, + core + ACIOPHY_CROSSBAR_T8103); + + atcphy_lanes_up_t8152(atcphy, APPLE_ATCPHY_MODE_USB4); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(0)), + ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(1)), + ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN | + atcphy_test_t8152_lfps(0) | atcphy_test_t8152_lfps(1)); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), + (u32)ACIOPHY_CROSSBAR_DP_BOTH_PMA | reversed); + + KUNIT_EXPECT_EQ(test, atcphy_configure_lanes(atcphy, APPLE_ATCPHY_MODE_USB4), 0); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), (u32)reversed); + KUNIT_EXPECT_EQ(test, readl(core + misc), + reversed ? ATCPHY_T8152_MISC_LANE_SWAP : 0U); + + atcphy->mode = APPLE_ATCPHY_MODE_USB4; + writel(ATCPHY_POWER_APB_RESET_N, core + ctrl); + atcphy_lanes_down_t8152(atcphy); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(0)), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(1)), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN); + atcphy->mode = APPLE_ATCPHY_MODE_OFF; + atcphy_test_t8152_untouched(test, atcphy); + } +} + +/* A lane power-down with the register bus in reset leaves the lanes alone */ +static void atcphy_test_t8152_lanes_bus_reset(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + + writel(ATCPHY_TEST_T8152_LANE0_UP, core + ACIOPHY_T8152_AON_LANE0); + writel(ATCPHY_POWER_CLAMP_EN, core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL); + atcphy_lanes_down_t8152(atcphy); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), ATCPHY_TEST_T8152_LANE0_UP); +} + +/* Only USB4 in its own mode, and Thunderbolt, ask a CIO-only PHY for CIO */ +static void atcphy_test_cio_target_mode(struct kunit *test) +{ + struct typec_altmode dp = { .svid = USB_TYPEC_DP_SID }; + struct typec_altmode tbt = { .svid = USB_TYPEC_TBT_SID }; + struct enter_usb_data usb4 = { .eudo = FIELD_PREP(EUDO_USB_MODE_MASK, EUDO_USB_MODE_USB4) }; + struct enter_usb_data usb3 = { .eudo = FIELD_PREP(EUDO_USB_MODE_MASK, EUDO_USB_MODE_USB3) }; + struct typec_mux_state state = { .mode = TYPEC_MODE_USB4, .data = &usb4 }; + + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_USB4); + state.data = &usb3; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.data = NULL; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.alt = &tbt; + state.mode = TYPEC_TBT_MODE; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_TBT); + state.alt = &dp; + state.mode = TYPEC_DP_STATE_D; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.alt = NULL; + state.mode = TYPEC_STATE_USB; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.mode = TYPEC_STATE_SAFE; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); +} + +/* The PHY is idle only as its power-up leaves it */ +static void atcphy_test_t8152_cio_idle(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 stat = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_STAT; + + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + KUNIT_EXPECT_TRUE(test, atcphy_cio_idle(atcphy)); + /* the display driver's DisplayPort setup */ + writel(0x1b, core + ctrl); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + writel(ATCPHY_POWER_SLEEP_SMALL, core + stat); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); + writel(0, core + stat); + writel(ATCPHY_MISC_RESET_N, core + ATCPHY_T8152_SYNC_RESET); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); +} + static struct kunit_case atcphy_t8152_test_cases[] = { KUNIT_CASE(atcphy_test_t8152_lanes), KUNIT_CASE(atcphy_test_t8152_power), KUNIT_CASE(atcphy_test_t8152_pipe_lock), + KUNIT_CASE(atcphy_test_t8152_cio_lanes), + KUNIT_CASE(atcphy_test_t8152_lanes_bus_reset), + KUNIT_CASE(atcphy_test_cio_target_mode), + KUNIT_CASE(atcphy_test_t8152_cio_idle), {} }; diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 347d2a4d6ec03..e139ac328fbbe 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -277,15 +277,19 @@ enum atcphy_lane_mode { ACIOPHY_T8152_BIST_OV2_LN0_UNK10) /* T8152 lane power controls in the always-on top block (ACIOPHY_TOP_AON_BLK) */ -#define ACIOPHY_T8152_AON_LANE0 0x1e18 +#define ACIOPHY_T8152_AON_LANE(n) (0x1e18 + 4 * (n)) +#define ACIOPHY_T8152_AON_LANE0 ACIOPHY_T8152_AON_LANE(0) #define ACIOPHY_T8152_AON_LANE_CLAMP_EN BIT(0) #define ACIOPHY_T8152_AON_LANE_SLEEP_SMALL BIT(1) #define ACIOPHY_T8152_AON_LANE_SLEEP_BIG BIT(2) #define ACIOPHY_T8152_AON_LANE_AHB_RESET_N BIT(5) #define ACIOPHY_T8152_AON_SLEEP_CTRL2 0x1e24 -#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0 BIT(12) -#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0 BIT(16) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_BIG BIT(6) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_SMALL BIT(8) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN BIT(10) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(n) BIT(12 + 2 * (n)) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(n) BIT(16 + 2 * (n)) #define ACIOPHY_SLEEP_CTRL 0x1b0 #define ACIOPHY_SLEEP_CTRL_TX_BIG GENMASK(1, 0) @@ -736,6 +740,10 @@ struct apple_atcphy; * first and its power-down asserts last, instead of * ATCPHY_MISC_RESET_N, or zero * @lane_swap: Lane swap bit in ATCPHY_MISC, or zero for ATCPHY_MISC_LANE_SWAP + * @cio_lane_swap: CIO (USB4) mode sets @lane_swap for a reversed plug as well, + * next to the swapped crossbar + * @typec_cio_only: On a Type-C port the PHY runs only CIO (USB4) mode, see + * apple_atcphy.cio_only * @has_usb4: A USB4/Thunderbolt controller sits behind the PHY * @usb2_only: Uses the USB2 subset unless its banked SuperSpeed resources exist * @usb2phy_sig_host: Host role field mask, or zero for the original layout @@ -773,6 +781,8 @@ struct atcphy_hw { u32 cfg_offset; u32 sync_reset; u32 lane_swap; + bool cio_lane_swap; + bool typec_cio_only; bool has_usb4; bool usb2_only; u32 usb2phy_sig_host; @@ -865,6 +875,16 @@ struct atcphy_cio_sleep { * on lane 0 from probe on and provides only the USB3 PHY of the * controller, which is a host; its USB2 side and its reset are * left to the bootloader + * @cio_only: A Type-C port on which the PHY runs CIO (USB4) mode alone + * (atcphy_hw.typec_cio_only): its DisplayPort mode is the display + * driver's, which powers the DP PHY while it drives the PHY itself, + * and its USB2 side is left to the bootloader. See + * atcphy_cio_mux_set(). + * @cio_pds: The power domains of a @cio_only PHY, in power-up order + * @cio_powered: The PHY holds @cio_pds for CIO mode + * @display_owned: The display driver drives a @cio_only PHY and holds @cio_pds + * through the DP PHY, or the bootloader left it driving a + * display, which the display driver takes over * @typec_mode: Mode the Type-C mux last asked for; a fixed-hub port returns to * it when the PHY is brought back up after a power-off * @host_active: dwc3 has selected host mode on the USB3 PHY; a fixed-hub port @@ -980,6 +1000,10 @@ struct apple_atcphy { bool dp_only; bool fixed_usb2; bool fixed_usb3; + bool cio_only; + struct dev_pm_domain_list *cio_pds; + bool cio_powered; + bool display_owned; enum atcphy_mode typec_mode; bool host_active; /* @@ -1357,33 +1381,45 @@ static inline u32 atcphy_lane_swap(const struct apple_atcphy *atcphy) return atcphy->hw->lane_swap ?: ATCPHY_MISC_LANE_SWAP; } +/* T8152: the lanes a mode runs on, lane 0 for USB3, both for CIO (USB4) */ +static unsigned int atcphy_lanes_t8152(enum atcphy_mode mode) +{ + return mode == APPLE_ATCPHY_MODE_USB4 || mode == APPLE_ATCPHY_MODE_TBT ? 2 : 1; +} + /* * T8152 keeps a lane's registers in AHB reset until the lane is powered up on - * its own, and they drop their tunables meanwhile. Power lane 0, the USB3 lane - * of a fixed-USB3 port, up after the common-a tunables: its LFPS receivers, - * then out of sleep, unclamped and out of AHB reset. Set the crossbar right - * after, before the remaining tunables, as the T8152 sequence does: 0x110 for - * USB3, i.e. USB3+DP with single PMA 0x008. atcphy_configure_lanes() writes the - * same value again later. + * its own, and they drop their tunables meanwhile. Power the lanes of the mode + * up after the common-a tunables, one after the other: lane 0, the USB3 lane + * of a fixed-USB3 port, and in CIO mode lane 1 too. Each gets its LFPS + * receivers, then goes out of sleep, unclamped and out of AHB reset. Set the + * crossbar right after, before the remaining tunables, as the T8152 sequence + * does: 0x110 for USB3, i.e. USB3+DP with single PMA 0x008, and 0 or 1 for + * CIO by the plug orientation. atcphy_configure_lanes() writes the same value + * again later. */ static void atcphy_lanes_up_t8152(struct apple_atcphy *atcphy, enum atcphy_mode mode) { const struct atcphy_mode_configuration *mode_cfg = atcphy_get_mode_config(atcphy, mode); - core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, - ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL_LN0); - udelay(1); - core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, - ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG_LN0); - udelay(1); - core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); - udelay(1); - core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); - udelay(1); - core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_CLAMP_EN); - udelay(1); - core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); - udelay(1); + for (unsigned int lane = 0; lane < atcphy_lanes_t8152(mode); lane++) { + u32 ctrl = ACIOPHY_T8152_AON_LANE(lane); + + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane)); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane)); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + } core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_PROTOCOL | ACIOPHY_CROSSBAR_DP_SINGLE_PMA, @@ -1392,17 +1428,55 @@ static void atcphy_lanes_up_t8152(struct apple_atcphy *atcphy, enum atcphy_mode mode_cfg->crossbar_dp_single_pma)); } -/* T8152: power lane 0 down as the PHY powers down, the reverse of the above */ +/* + * T8152: power the lanes of the current mode down as the PHY powers down, the + * reverse of the above, while the register bus is still out of reset (a + * failed power-up may not have released it). A CIO-only PHY only ever runs + * CIO mode, so both of its lanes, also after a failed CIO power-up. Leaving + * CIO mode also clamps AUX and drops both lanes' LFPS receivers first, as the + * T8152 CIO shutdown does; the lanes' power controls are always-on and keep + * what they are left with across the common block's power-down. + */ static void atcphy_lanes_down_t8152(struct apple_atcphy *atcphy) { - core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); - udelay(1); - core_set32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_CLAMP_EN); - udelay(1); - core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); - udelay(1); - core_clear32(atcphy, ACIOPHY_T8152_AON_LANE0, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); - udelay(1); + unsigned int lanes = atcphy->cio_only ? 2 : atcphy_lanes_t8152(atcphy->mode); + + if (!(core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL)) & + ATCPHY_POWER_APB_RESET_N)) + return; + + if (lanes > 1) { + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_SMALL); + udelay(1); + for (unsigned int lane = 0; lane < lanes; lane++) { + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane)); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane)); + udelay(1); + } + } + + for (unsigned int lane = 0; lane < lanes; lane++) { + u32 ctrl = ACIOPHY_T8152_AON_LANE(lane); + + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); + } } /* Static configuration fields already read/modified by the public DP path. */ @@ -2368,7 +2442,8 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_PROTOCOL, FIELD_PREP(ACIOPHY_CROSSBAR_PROTOCOL, mode_cfg->crossbar)); - if (mode_cfg->set_swap) + if (mode_cfg->set_swap || + (atcphy->hw->cio_lane_swap && atcphy_mode_is_cio(mode) && atcphy->swap_lanes)) core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); else core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); @@ -2383,7 +2458,7 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode /* * The PMA FSM override below is for the T8103 generation. T8122 DP lanes * are started by the link rate sequence, see atcphy_dp_set_rate_t8122(). - * T8152 runs USB3 alone. + * T8152 runs USB3 or CIO alone. */ if (atcphy->hw->gen == ATCPHY_GENERATION_T8122 || atcphy->hw->gen == ATCPHY_GENERATION_T8152) @@ -2919,8 +2994,9 @@ static int atcphy_power_off(struct apple_atcphy *atcphy) u32 reg; int ret; - /* A fixed-USB3 port has no DisplayPort side */ - if (atcphy->hw->gen != ATCPHY_GENERATION_T8132 && !atcphy->fixed_usb3) { + /* A fixed-USB3 port has no DisplayPort side, a CIO-only port leaves it alone */ + if (atcphy->hw->gen != ATCPHY_GENERATION_T8132 && !atcphy->fixed_usb3 && + !atcphy->cio_only) { ret = atcphy_disable_dp_aux(atcphy); if (ret) return ret; @@ -3013,7 +3089,7 @@ static int atcphy_power_on(struct apple_atcphy *atcphy) u32 reg; int ret; - if (!atcphy->dp_only && !atcphy->fixed_usb3) + if (!atcphy->dp_only && !atcphy->fixed_usb3 && !atcphy->cio_only) atcphy_usb2_power_on(atcphy); core_set32(atcphy, atcphy->hw->sync_reset ?: atcphy_cfg(atcphy, ATCPHY_MISC), @@ -5452,6 +5528,192 @@ int apple_atc_dp_tunnel_open(struct phy *phy) } EXPORT_SYMBOL_GPL(apple_atc_dp_tunnel_open); +/* + * T8152's rear USB-C ports (atcphy_hw.typec_cio_only, apple_atcphy.cio_only): + * the PHY runs CIO mode for a USB4 partner and is left alone otherwise. + * + * Their DisplayPort alt mode is still driven by the display driver, which + * programs the PHY's power and reset block, lanes and display crossbar + * itself. The two take turns on the PHY: + * + * - The display driver powers the DP PHY on before it touches the PHY and + * off once it has let go of it. The DP PHY then holds the PHY's power + * domains for it, and keeps the PHY out of CIO mode: a USB4 mode change + * fails with -ETIMEDOUT, which the Type-C port driver retries (the mux + * declares its timeouts transient) until the display driver is done. + * - A DP PHY power-on is refused with -EBUSY while the PHY runs CIO mode. + * - Either takes the PHY only from its idle state: the power and reset block + * as the power-up leaves it, clamped and asleep, its sync reset asserted. + * Anything else means another user still has it, and CIO mode is refused. + * - A display the bootloader brought up keeps running for the display + * driver: such a PHY has all its domains on and is not idle at probe, and + * the domains are held for the display driver until its DP PHY goes off. + * + * Once the DisplayPort mode moves into this driver, the DP PHY programs it + * itself, both modes switch under the PHY's lock, and this arbitration goes. + */ +static int atcphy_cio_pds_on(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + int ret; + + for (unsigned int i = 0; i < pds->num_pds; i++) { + ret = pm_runtime_resume_and_get(pds->pd_devs[i]); + if (ret < 0) { + while (i--) + pm_runtime_put_sync(pds->pd_devs[i]); + return ret; + } + } + return 0; +} + +/* Synchronously: the next CIO mode or display must find them off. */ +static void atcphy_cio_pds_off(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + + for (unsigned int i = pds->num_pds; i > 0; i--) + pm_runtime_put_sync(pds->pd_devs[i - 1]); +} + +/* The power and reset block as its power-up leaves it, with its domains on */ +static bool atcphy_cio_idle(struct apple_atcphy *atcphy) +{ + return core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL)) == + ATCPHY_POWER_CLAMP_EN && + !(core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_STAT)) & + (ATCPHY_POWER_SLEEP_SMALL | ATCPHY_POWER_SLEEP_BIG)) && + !core_read32(atcphy, atcphy->hw->sync_reset); +} + +/* + * The CIO shutdown, then the power domains: the common block goes cold, so + * that the next partner, in either orientation, starts from a cold PHY. With + * the common block left powered, the next link training asserted in the + * router's firmware. A failed shutdown keeps the domains for the next try. + */ +static int atcphy_cio_stop(struct apple_atcphy *atcphy) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_OFF); + if (ret) { + dev_err(atcphy->dev, "CIO shutdown failed: %d\n", ret); + return ret; + } + atcphy_cio_pds_off(atcphy); + atcphy->cio_powered = false; + dev_dbg(atcphy->dev, "CIO mode off\n"); + return 0; +} + +static int atcphy_cio_start(struct apple_atcphy *atcphy, enum atcphy_mode mode) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + /* The router's Thunderbolt mode is not qualified on these ports. */ + if (mode != APPLE_ATCPHY_MODE_USB4) { + dev_info(atcphy->dev, "Thunderbolt alt mode is not supported on this port\n"); + return -ENODEV; + } + if (atcphy->display_owned) { + dev_dbg(atcphy->dev, "USB4 waits for the display driver to release the PHY\n"); + return -ETIMEDOUT; + } + ret = atcphy_cio_pds_on(atcphy); + if (ret) + return ret; + if (!atcphy_cio_idle(atcphy)) { + dev_warn(atcphy->dev, "PHY not idle (power control %#x), USB4 refused\n", + core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL))); + atcphy_cio_pds_off(atcphy); + return -EBUSY; + } + atcphy->cio_powered = true; + ret = atcphy_configure(atcphy, mode); + if (ret) { + dev_err(atcphy->dev, "CIO mode failed: %d\n", ret); + atcphy_cio_stop(atcphy); + return ret; + } + dev_dbg(atcphy->dev, "CIO mode on, %s\n", atcphy->swap_lanes ? "reversed" : "normal"); + return 0; +} + +/* USB4 asks for CIO mode; every other state leaves the PHY to its other users. */ +static enum atcphy_mode atcphy_cio_target_mode(const struct typec_mux_state *state) +{ + const struct enter_usb_data *data = state->data; + + if (state->alt && state->alt->svid == USB_TYPEC_TBT_SID) + return APPLE_ATCPHY_MODE_TBT; + if (!state->alt && state->mode == TYPEC_MODE_USB4 && data && + FIELD_GET(EUDO_USB_MODE_MASK, data->eudo) == EUDO_USB_MODE_USB4) + return APPLE_ATCPHY_MODE_USB4; + return APPLE_ATCPHY_MODE_OFF; +} + +/* + * The Type-C port driver sets the mux before it starts the USB4 router and + * after it stops it, so CIO mode comes up before the router starts and goes + * down after it stopped. + */ +static int atcphy_cio_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + struct apple_atcphy *atcphy = typec_mux_get_drvdata(mux); + enum atcphy_mode mode = atcphy_cio_target_mode(state); + int ret; + + guard(mutex)(&atcphy->lock); + if (atcphy->cio_powered) { + if (atcphy->mode == mode && !atcphy->mode_dirty) + return 0; + ret = atcphy_cio_stop(atcphy); + if (ret) + return ret; + } + if (mode == APPLE_ATCPHY_MODE_OFF) + return 0; + return atcphy_cio_start(atcphy, mode); +} + +/* The display driver takes the PHY of a CIO-only port, see above. */ +static int atcphy_cio_dp_power_on(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + int ret; + + guard(mutex)(&atcphy->lock); + if (atcphy->display_owned) + return 0; + if (atcphy->cio_powered) + return -EBUSY; + ret = atcphy_cio_pds_on(atcphy); + if (!ret) + atcphy->display_owned = true; + return ret; +} + +static int atcphy_cio_dp_power_off(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + + guard(mutex)(&atcphy->lock); + if (atcphy->display_owned) + atcphy_cio_pds_off(atcphy); + atcphy->display_owned = false; + return 0; +} + +static const struct phy_ops apple_atc_cio_dp_phy_ops = { + .owner = THIS_MODULE, + .power_on = atcphy_cio_dp_power_on, + .power_off = atcphy_cio_dp_power_off, +}; + static struct phy *atcphy_xlate(struct device *dev, const struct of_phandle_args *args) { struct apple_atcphy *atcphy = dev_get_drvdata(dev); @@ -5483,16 +5745,18 @@ static int atcphy_probe_phy(struct apple_atcphy *atcphy) { &atcphy->phys.usb2, &apple_atc_usb2_phy_ops }, { &atcphy->phys.usb3, atcphy->fixed_usb3 ? &apple_atc_fixed_usb3_phy_ops : &apple_atc_usb3_phy_ops }, - { &atcphy->phys.dp, &apple_atc_dp_phy_ops }, + { &atcphy->phys.dp, atcphy->cio_only ? &apple_atc_cio_dp_phy_ops : + &apple_atc_dp_phy_ops }, }; /* * A T8132 PHY with its USB3/USB4 banks gets a DP PHY for DisplayPort * tunnels only (see atcphy_dpphy_set_mode_t8132()); creating it does - * not touch the hardware. A fixed-USB3 PHY gets its USB3 PHY only. + * not touch the hardware. A fixed-USB3 PHY gets its USB3 PHY only, a + * CIO-only PHY the DP PHY through which the display driver takes it. */ for (int i = 0; i < ARRAY_SIZE(phys); i++) { - if ((atcphy->dp_only && phys[i].phy != &atcphy->phys.dp) || + if (((atcphy->dp_only || atcphy->cio_only) && phys[i].phy != &atcphy->phys.dp) || (atcphy_usb2_only(atcphy) && i != 0) || (atcphy->fixed_usb3 && phys[i].phy != &atcphy->phys.usb3)) continue; @@ -6460,9 +6724,10 @@ static int atcphy_probe_mux(struct apple_atcphy *atcphy) struct typec_mux_desc mux_desc = { .drvdata = atcphy, .fwnode = atcphy->dev->fwnode, - .set = atcphy_mux_set, + .set = atcphy->cio_only ? atcphy_cio_mux_set : atcphy_mux_set, .safe_after_role = !atcphy->fixed_usb2, - .transient_timeouts = atcphy_mux_transient_timeouts(atcphy), + /* A CIO-only PHY times out while the display driver has it. */ + .transient_timeouts = atcphy->cio_only || atcphy_mux_transient_timeouts(atcphy), }; mux = typec_mux_register(atcphy->dev, &mux_desc); @@ -6686,6 +6951,15 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) *tunables[i].tunable = NULL; continue; } + /* a CIO-only port has its common and CIO lane tunables alone */ + if (atcphy->cio_only && + tunables[i].tunable != &atcphy->tunables.common[0] && + tunables[i].tunable != &atcphy->tunables.common[1] && + tunables[i].tunable != &atcphy->tunables.lane_usb4[0] && + tunables[i].tunable != &atcphy->tunables.lane_usb4[1]) { + *tunables[i].tunable = NULL; + continue; + } if (!atcphy->hw->has_usb4 && (tunables[i].tunable == &atcphy->tunables.lane_usb4[0] || tunables[i].tunable == &atcphy->tunables.lane_usb4[1])) { @@ -6791,11 +7065,12 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph void __iomem *addr; /* - * A fixed-USB3 PHY has its core and PIPE windows only. On T8152 the - * core window also holds the USB controller's DARTs, so it is mapped - * without claiming it. + * A fixed-USB3 PHY has its core and PIPE windows only, a CIO-only PHY its + * core window. On T8152 the core window also holds the USB controller's + * DARTs, and the display driver maps it too, so it is mapped without + * claiming it. */ - if (atcphy->fixed_usb3) { + if (atcphy->fixed_usb3 || atcphy->cio_only) { res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); if (!res) return dev_err_probe(atcphy->dev, -EINVAL, "Missing core regs\n"); @@ -6803,6 +7078,8 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph if (!atcphy->regs.core) return -ENOMEM; atcphy->res.core = res; + if (atcphy->cio_only) + return 0; addr = devm_platform_ioremap_resource_byname(pdev, "pipehandler"); if (IS_ERR(addr)) @@ -7067,6 +7344,64 @@ static int atcphy_probe_finalize_fixed_usb3(struct apple_atcphy *atcphy) return 0; } +/* Let go of the PHY of a CIO-only port on unbind, see atcphy_cio_mux_set(). */ +static void atcphy_cio_release(void *data) +{ + struct apple_atcphy *atcphy = data; + + guard(mutex)(&atcphy->lock); + if (atcphy->cio_powered) + atcphy_cio_stop(atcphy); + if (atcphy->display_owned) + atcphy_cio_pds_off(atcphy); + atcphy->display_owned = false; +} + +/* + * A CIO-only port: probe leaves the hardware as it is. A display the + * bootloader brought up on the port has all of the PHY's power domains on, + * and the PHY is not idle: hold the domains for the display driver, which + * takes it over, until its DP PHY goes off. Otherwise the domains are left to + * their power domain driver. Then register the mux, the orientation switch + * and the DP PHY. + */ +static int atcphy_probe_finalize_cio_only(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + bool all_on = true; + int ret; + + lockdep_assert_held(&atcphy->lock); + + ret = devm_add_action(atcphy->dev, atcphy_cio_release, atcphy); + if (ret) + return ret; + for (unsigned int i = 0; i < pds->num_pds; i++) + all_on &= dev_pm_genpd_is_on(pds->pd_devs[i]); + if (all_on) { + ret = atcphy_cio_pds_on(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Failed to power the PHY\n"); + if (atcphy_cio_idle(atcphy)) { + atcphy_cio_pds_off(atcphy); + } else { + atcphy->display_owned = true; + dev_info(atcphy->dev, "PHY in use at boot, held for the display driver\n"); + } + } + + ret = atcphy_probe_mux(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing mux failed\n"); + ret = atcphy_probe_switch(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing switch failed\n"); + ret = atcphy_probe_phy(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing phy failed\n"); + return 0; +} + static int atcphy_probe_finalize(struct apple_atcphy *atcphy) { int ret; @@ -7077,6 +7412,8 @@ static int atcphy_probe_finalize(struct apple_atcphy *atcphy) return atcphy_probe_finalize_dp_only(atcphy); if (atcphy->fixed_usb3) return atcphy_probe_finalize_fixed_usb3(atcphy); + if (atcphy->cio_only) + return atcphy_probe_finalize_cio_only(atcphy); /* Reset dwc3 on probe, let dwc3 (consumer) deassert it */ _atcphy_dwc3_reset_assert(atcphy); @@ -7219,6 +7556,18 @@ static int atcphy_probe_power_domains(struct apple_atcphy *atcphy) struct dev_pm_domain_list *pd_list; int ret; + /* + * A CIO-only PHY powers its domains only while it runs CIO mode or the + * display driver has it, see atcphy_cio_mux_set(). + */ + if (atcphy->cio_only) { + pd_data.pd_flags = PD_FLAG_NO_DEV_LINK; + ret = devm_pm_domain_attach_list(atcphy->dev, &pd_data, &atcphy->cio_pds); + if (ret <= 0) + return dev_err_probe(atcphy->dev, ret ?: -EINVAL, + "Failed to attach power domains\n"); + return 0; + } if (!atcphy->fixed_usb3 || atcphy->dev->pm_domain) return 0; ret = devm_pm_domain_attach_list(atcphy->dev, &pd_data, &pd_list); @@ -7250,9 +7599,7 @@ static int atcphy_probe(struct platform_device *pdev) atcphy->t8132_dp_alt = atcphy->hw->gen == ATCPHY_GENERATION_T8132 && of_property_read_bool(dev->of_node, "apple,dp-alt-mode"); atcphy->fixed_usb3 = of_property_read_bool(dev->of_node, "apple,fixed-usb3"); - /* T8152 is supported on a fixed-USB3 port only */ - if (atcphy->hw->gen == ATCPHY_GENERATION_T8152 && !atcphy->fixed_usb3) - return dev_err_probe(dev, -ENODEV, "Only a fixed-USB3 port is supported\n"); + atcphy->cio_only = atcphy->hw->typec_cio_only && !atcphy->fixed_usb3; apple_atc_tunnel_wiring(atcphy); mutex_init(&atcphy->lock); platform_set_drvdata(pdev, atcphy); @@ -8336,10 +8683,11 @@ static const struct atcphy_hw atcphy_hw_t8142 = { }; /* - * T8152 as the USB3 PHY of a fixed-USB3 port: no USB4, DisplayPort or lane - * mode register and nothing to wake after the tunables. Its power domains are - * not followed: the controller's power-off and power-on of the PHY, as around - * a system sleep, take it down and up again. + * T8152 as the USB3 PHY of a fixed-USB3 port, or as a Type-C port's PHY in CIO + * mode alone (see atcphy_cio_mux_set()): no DisplayPort mode, no lane mode + * register and nothing to wake after the tunables. A fixed-USB3 port does not + * follow its power domains: the controller's power-off and power-on of the + * PHY, as around a system sleep, take it down and up again. */ static const struct atcphy_hw atcphy_hw_t8152 = { .gen = ATCPHY_GENERATION_T8152, @@ -8349,6 +8697,7 @@ static const struct atcphy_hw atcphy_hw_t8152 = { .lane_swap = ATCPHY_T8152_MISC_LANE_SWAP, .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, + .has_usb4 = true, .park_dummy_phy = true, .clear_boot_hold = true, /* @@ -8357,6 +8706,13 @@ static const struct atcphy_hw atcphy_hw_t8152 = { * PIPE moved to USB3 and back to the dummy PHY under the request. */ .pipe_lock_unacked = true, + /* + * Its Type-C ports run CIO mode alone; a reversed plug takes the + * swapped crossbar and the lane swap, with which the J873g's rear ports + * trained USB4 at 2 x 20 Gb/s. + */ + .typec_cio_only = true, + .cio_lane_swap = true, }; static const struct of_device_id atcphy_match[] = { diff --git a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py index ed02e7f33b562..dfa3d7aad45f5 100755 --- a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py +++ b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py @@ -107,7 +107,7 @@ def main(): bool t8132_ss, t8132_common_owned, t8132_suspended, t8132_failed, host_active; bool ss_tunables, mode_dirty, pipe_pending, swap_lanes; bool cio_tunables, t8132_dp_alt, fixed_usb2, hibernated, pd_was_off, idle_rpm; - bool t8103_dummy_pending, t8103_usb3_workaround, fixed_usb3; + bool t8103_dummy_pending, t8103_usb3_workaround, fixed_usb3, cio_only; unsigned tunnel_users; struct { bool prepared, changed, restored; } cio_sleep; int mode, pipe_state, lock; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index a2d8076ac8b3d..dd3cb7476f43b 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -25,7 +25,7 @@ struct apple_atcphy { bool aux, pll; unsigned int pairs, rate; } dp_t8122; - bool fixed_usb2, fixed_usb3, host_active, mode_dirty, ss_tunables, dp_tunables, + bool fixed_usb2, fixed_usb3, cio_only, host_active, mode_dirty, ss_tunables, dp_tunables, aux_power_requested; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 45c8275bf462e..544b698f70e8c 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -46,7 +46,7 @@ def function(source, name): struct reset_controller_dev rcdev; void *dev; int lock, dp_link_rate; - bool fixed_usb2, fixed_usb3, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, cio_only, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; @@ -1953,7 +1953,7 @@ def function(name): struct { unsigned char *core, *pipehandler; } regs; void *dev; int lock; - bool fixed_usb2, fixed_usb3, host_active, ss_tunables, dp_tunables, mode_dirty; + bool fixed_usb2, fixed_usb3, cio_only, host_active, ss_tunables, dp_tunables, mode_dirty; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; u32 dp_usb_context[2][27]; @@ -2355,7 +2355,7 @@ def function(source, name): struct { unsigned char *core, *lpdptx, *lioa; } regs; void *dev; int lock, dp_link_rate; - bool fixed_usb2, fixed_usb3, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, cio_only, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; From 83f5ead819ac89089247e6bee8dcb6da9083a7b4 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:26 +0100 Subject: [PATCH 116/121] dt-bindings: display: apple,t8152-dcp-iboot: add the USB-C ports' PHYs A rear USB-C port's ATC PHY is also its USB4 PHY, run by the ATC PHY driver, which powers the PHY. Give each usb-c port node the port's PHY in DisplayPort use (PHY_TYPE_DP): a DCP powers it while it drives the PHY, from before a cold start until the PHY is powered down, and the PHY driver keeps the PHY powered and out of USB4 meanwhile. Signed-off-by: Thomas Glanzmann --- .../bindings/display/apple,t8152-dcp-iboot.yaml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml index cc7ea1045a323..b25cd3a74cfa0 100644 --- a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -243,6 +243,14 @@ patternProperties: apple,tunable-post: $ref: /schemas/types.yaml#/definitions/uint32-matrix description: As the node's apple,tunable-post, for this port's PHY. + phys: + maxItems: 1 + description: + The port's ATC PHY in DisplayPort use (PHY_TYPE_DP). A DCP powers + it while it drives the PHY, from before its cold start until its + power-down, and keeps it powered for a display the bootloader + started; the PHY driver powers the PHY's domains meanwhile and + keeps it out of USB4. The PHY refuses this while it runs USB4. mode-switch: type: boolean description: @@ -315,6 +323,7 @@ examples: <0x3 0x03a13a00 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <3>; + phys = <&atc3_phy 6>; mode-switch; port { From 466388c3f56273f287b8c0bc1a5f36567241e21e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:26 +0100 Subject: [PATCH 117/121] drm/apple: power the T8152 ATC PHYs through their PHY driver The T8152 DCPs powered a rear USB-C port's ATC PHY themselves: before a cold start they set the port's USB_AON, DP_0 and DP_1 PMGR power states (PS +0x100, +0, +0x20) to 0xf and its common PSD service to 0, and after a power-down they set back those that had been off. The same PHY now runs CIO mode for USB4, through the ATC PHY driver, which powers it through the PMGR and PSD power domain drivers. With two writers of the same states, one would switch off what the other uses, or leave the power domain drivers believing a domain on that is off. Take the PHY through the port's DP PHY instead (the usb-c node's phys): power it on before the cold start's first PHY access and off once the PHY is powered down. The PHY driver then holds the PHY's power domains and keeps it out of USB4; while the PHY runs USB4 the power-on fails with -EBUSY and the cold start with it. A display the bootloader left running is kept powered by the PHY driver from its probe; the DCP that adopts it powers the DP PHY on at once and so takes that over. A port whose common block runs but whose DP PHY cannot be powered is in USB4, not a bootloader display: the power and reset block (CFG +0x60000) reads 0x1b in both. The PMGR and PSD state registers are still read to tell whether the PHY can be looked at. The DisplayPort programming itself is unchanged. Signed-off-by: Thomas Glanzmann --- drivers/gpu/drm/apple/t8152_atc.c | 102 +++++++++++------------------- 1 file changed, 36 insertions(+), 66 deletions(-) diff --git a/drivers/gpu/drm/apple/t8152_atc.c b/drivers/gpu/drm/apple/t8152_atc.c index b2d018d4e636e..b5bb17bab79f1 100644 --- a/drivers/gpu/drm/apple/t8152_atc.c +++ b/drivers/gpu/drm/apple/t8152_atc.c @@ -14,6 +14,11 @@ * route, and with the display off or unplugged a full power down and a cold * start. A DCP drives one USB-C port at a time: the one it claims from the * shared ports once their Type-C state shows a sink (t8152_typec.c). + * + * The ATC PHY driver powers the PHY: it holds the PHY's power domains while + * the port's DP PHY is on, and keeps the PHY out of USB4 meanwhile. So the DP + * PHY goes on before any PHY register access of a cold start, and off once + * the PHY is powered down, and a bootloader display's PHY stays on with it. */ #include @@ -24,6 +29,7 @@ #include #include #include +#include #include "dptxep.h" #include "t8152_display.h" @@ -55,11 +61,11 @@ struct t8152_atc_port { u32 dfp; /* AP DisplayPort AUX controller aux0 (shared), for the EDID */ struct t8152_aux *aux; - /* PMGR power states of the four ATC dependencies */ + /* PMGR power states of the ATC dependencies, read to tell if it runs */ void __iomem *ps; void __iomem *psd; - /* the dependencies this driver powered up, and may power down */ - u8 owned; + /* the port's DP PHY of the ATC PHY driver, which powers the PHY */ + struct phy *phy; /* {offset, mask, value} tunables, before and after the lane setup */ const __be32 *tunable[2]; int tunable_len[2]; @@ -382,50 +388,7 @@ static int atc_dp_start(struct t8152_display *disp, struct t8152_atc_port *atc, 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 t8152_atc_port *atc, u32 state) -{ - u32 reg; - - /* - * Only the state: the acknowledge bit 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 t8152_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 t8152_atc_port *atc, unsigned int which) { @@ -436,13 +399,13 @@ static void atc_apply_tunables(struct t8152_atc_port *atc, unsigned int which) be32_to_cpu(t[i + 2])); } -/* Cold start: the power dependencies, the common block and AUX, then the lanes at HBR. */ +/* Cold start: the PHY's power, the common block and AUX, then the lanes at HBR. */ static int atc_activate(struct t8152_display *disp) { struct t8152_atc_port *atc = atc_cur(disp); void __iomem *cfg = atc->base + ATC_CFG; - unsigned int gates = 0; u32 reg; + int ret; if (READ_ONCE(atc_owner[atc->index]) != disp->dev) return -EBUSY; @@ -450,9 +413,12 @@ static int atc_activate(struct t8152_display *disp) 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; + /* -EBUSY while the PHY runs USB4 */ + ret = phy_power_on(atc->phy); + if (ret) { + dev_err(disp->dev, "ATC%u: PHY not powered: %d\n", atc->index, ret); + return ret; + } if (readl(cfg) != 4 || (readl(cfg + 4) & 3) || readl(cfg + 0x30)) goto fail; writel(readl(cfg + 0x30) | BIT(0), cfg + 0x30); @@ -494,14 +460,13 @@ static int atc_activate(struct t8152_display *disp) */ return atc_dp_start(disp, atc, 1); fail: - dev_err(disp->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); + dev_err(disp->dev, "ATC%u: cold start failed (cfg %#x/%#x)\n", + atc->index, readl(cfg), readl(cfg + 4)); + phy_power_off(atc->phy); return -EIO; } -/* Power the PHY down, dependencies included. */ +/* Power the PHY down, its power included. */ static int atc_deactivate(struct t8152_display *disp) { struct t8152_atc_port *atc = atc_cur(disp); @@ -538,13 +503,9 @@ static int atc_deactivate(struct t8152_display *disp) } 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; + /* Then its power: the next activation starts it cold. */ + if (phy_power_off(atc->phy)) + ret = -ETIMEDOUT; dev_info(disp->dev, "ATC%u: powered down: %d\n", atc->index, ret); return ret; } @@ -796,6 +757,9 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, port->psd = atc_map(disp, np, "atc-psd"); if (!port->base || !port->ps || !port->psd) return -ENOMEM; + port->phy = devm_of_phy_optional_get(disp->dev, np, NULL); + if (IS_ERR(port->phy)) + return dev_err_probe(disp->dev, PTR_ERR(port->phy), "%pOF: no PHY\n", np); /* The node without ports is ATC3's (J873g back-right). */ port->dfp = 3; of_property_read_u32(np, "apple,dfp-endpoint", &port->dfp); @@ -831,6 +795,15 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, /* Common block out of reset and AUX up, as the bootloader leaves it. */ cfg = readl(port->base + ATC_CFG); port->active = (cfg & 0x1f) == 0x1b; + /* + * The bootloader's display keeps the PHY powered through its DP PHY. The + * common block runs the same way in USB4, whose PHY refuses the DP PHY. + */ + if (port->active && phy_power_on(port->phy)) { + dev_info(disp->dev, "ATC%u: runs USB4\n", port->index); + port->active = false; + return 0; + } if ((readl(port->base + 0x4c) & 0x1f) == 0x10 || (readl(port->base + 0x4c) & 0x1f) == 0x11) { port->lanes = 2; @@ -844,9 +817,6 @@ static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, 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(disp->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, From 789f1bdaa608e6ad8f8efb8fd0a0823b1d47d079 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:41 +0100 Subject: [PATCH 118/121] arm64: dts: apple: t8152-j873g: describe the rear ports' ATC PHYs The three rear USB-C ports' ATC PHYs (ADT atc-phy0, 1 and 3) were only known to the display controllers, as register windows they program and power themselves. Describe them as T8152 Type-C PHYs, which the ATC PHY driver runs in CIO mode for USB4: - their core windows (0x403000000, 0x40b000000, 0x413000000, 0x84000 each, also mapped by the display controllers); - the orientation and mode switches, linked to the SuperSpeed port (port@1) of the port's usb-c-connector; - their power domains, in power-up order: the ATC's USB_AON, its common PSD service (55, 56, 58) and its COMMON_DP_0/1 power states, new nodes next to ATC2's. The USB_AON states are kept on, as ATC2's: they hold the rear USB controllers' state the loader set up; - the CIO tunables of the ADT's atc-phyN groups, at the PHY blocks they apply to: the common defaults before the lanes are powered up, the fabric, PLL and remaining common groups after them, then each lane's groups. They are the lists the earlier port monitor applied, with which a rear port trained USB4. The display controllers' usb-c port nodes take the PHYs through their DP PHY, which powers them while a controller drives the port. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi | 51 +- arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi | 872 +++++++++++++++++- 2 files changed, 906 insertions(+), 17 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi index 2cc188ea99d91..0c7df8e3a55dd 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -138,6 +138,15 @@ reg = <0>; }; + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec0_ss: endpoint { + remote-endpoint = <&atc0_phy_typec>; + }; + }; + /* DisplayPort: the DCPs' display switch */ port@3 { reg = <3>; @@ -173,6 +182,15 @@ reg = <0>; }; + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec1_ss: endpoint { + remote-endpoint = <&atc1_phy_typec>; + }; + }; + /* DisplayPort: the DCPs' display switch */ port@3 { reg = <3>; @@ -208,6 +226,15 @@ reg = <0>; }; + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec3_ss: endpoint { + remote-endpoint = <&atc3_phy_typec>; + }; + }; + /* DisplayPort: the DCPs' display switch */ port@3 { reg = <3>; @@ -276,8 +303,10 @@ /* * 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. - * The node is also the port's display switch for all DCPs. + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. */ usb-c@403000000 { reg = <0x4 0x03000000 0x0 0x84000>, @@ -285,6 +314,8 @@ <0x3 0x03a13700 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <0>; + /* Powered while a DCP drives it */ + phys = <&atc0_phy PHY_TYPE_DP>; /* The DCPs' display switch of the port */ mode-switch; apple,tunable-pre = @@ -387,8 +418,10 @@ /* * 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. - * The node is also the port's display switch for all DCPs. + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. */ usb-c@40b000000 { reg = <0x4 0x0b000000 0x0 0x84000>, @@ -396,6 +429,8 @@ <0x3 0x03a13800 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <1>; + /* Powered while a DCP drives it */ + phys = <&atc1_phy PHY_TYPE_DP>; /* The DCPs' display switch of the port */ mode-switch; apple,tunable-pre = @@ -498,8 +533,10 @@ /* * 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. - * The node is also the port's display switch for all DCPs. + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. */ usb-c@413000000 { reg = <0x4 0x13000000 0x0 0x84000>, @@ -507,6 +544,8 @@ <0x3 0x03a13a00 0x0 0xc0>; reg-names = "atc", "atc-ps", "atc-psd"; apple,dfp-endpoint = <3>; + /* Powered while a DCP drives it */ + phys = <&atc3_phy PHY_TYPE_DP>; /* The DCPs' display switch of the port */ mode-switch; apple,tunable-pre = diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi index 2085434c423ff..83c99eced8749 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -10,9 +10,12 @@ * the role switch, exist but are left to the loader. * usb-drd2's hub is wired to ATC2's PHY without a Type-C mux, so Linux brings * that PHY up in USB3 mode (atc2_phy). + * The rear ports' ATC PHYs (atc0_phy, atc1_phy, atc3_phy) run CIO mode for + * USB4 alone: their DisplayPort alt mode is the display controllers', which + * take a PHY through its DP PHY, and their USB2 side stays with the loader. * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2 (on atc-phy1 and - * atc-phy2), atc-phy2 and the pmgr devices ATC1_USB_AON/USB, ATC2_USB_AON/USB - * and ATC2_COMMON_DP_0/1. + * atc-phy2), atc-phy0-3 and the pmgr devices ATCn_USB_AON, ATC1/2_USB and + * ATCn_COMMON_DP_0/1. * * 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 @@ -69,16 +72,16 @@ /* * The ATCs' PMGR power states (ADT pmgr devices ATCn_COMMON_DP_0/1 * from 0x308290000 and ATCn_USB_AON/USB from 0x308290100, 0x40 - * apart per ATC). The T8152 USB bring-up runs them without - * automatic power management. + * apart per ATC). Each ATC's three are those its PHY needs, and + * ATC1_USB and ATC2_USB are the USB controllers' states. The + * T8152 USB3 and CIO bring-ups run them without automatic power + * management. * - * ATCn_USB is the controller's state. The ADT also gives - * usb-drd1/2 service-gates 175/176, but those PSD service blocks - * (0x303a1af00, 0x303a1b000) take a bus error from the CPU. The - * loader leaves ATCn_USB and ATCn_USB_AON on; they hold the - * controllers' reset and the USB2 PHY setup it did, which Linux - * cannot redo yet, so they stay on. ATC2_COMMON_DP_0/1 are what - * ATC2's PHY needs besides. + * The ADT also gives usb-drd1/2 service-gates 175/176, but those + * PSD service blocks (0x303a1af00, 0x303a1b000) take a bus error + * from the CPU. The loader leaves ATC1/2_USB on; with USB_AON + * they hold the controllers' reset and the USB2 PHY setup it + * did, which Linux cannot redo yet, so they stay on. */ pmgr_atc: power-management@308290000 { compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", @@ -87,6 +90,46 @@ #size-cells = <1>; reg = <0x3 0x08290000 0x0 0x1000>; + ps_atc0_common_dp_0: power-controller@0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc0_common_dp_1: power-controller@20 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x20 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_1"; + apple,no-auto-pm; + }; + + ps_atc1_common_dp_0: power-controller@40 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc1_common_dp_1: power-controller@60 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_1"; + apple,no-auto-pm; + }; + ps_atc2_common_dp_0: power-controller@80 { compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; @@ -107,6 +150,42 @@ apple,no-auto-pm; }; + ps_atc3_common_dp_0: power-controller@c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xc0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc3_common_dp_1: power-controller@e0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xe0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_1"; + apple,no-auto-pm; + }; + + /* + * The USB_AON states are kept on: each holds its USB + * controller's reset and PIPE handler state, and the + * rear ports' controllers stay with the loader. + */ + ps_atc0_usb_aon: power-controller@100 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + ps_atc1_usb_aon: power-controller@140 { compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; @@ -157,6 +236,42 @@ apple,no-auto-pm; apple,always-on; }; + + ps_atc3_usb_aon: power-controller@1c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + }; + + /* + * The rear ports' ATCs' common domains: PSD services 55, 56 and 58 + * (ADT atc-phy0/1/3 clock-gates). + */ + ps_atc0_common: power-controller@303a13700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13700 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc0_common"; + }; + + ps_atc1_common: power-controller@303a13800 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13800 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc1_common"; + }; + + ps_atc3_common: power-controller@303a13a00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13a00 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc3_common"; }; /* ATC2's common domain: PSD service 57 (ADT atc-phy2 clock-gates). */ @@ -363,6 +478,741 @@ <0x04ca0 0x00000002 0x00000000>; }; + /* + * USB-C Back-middle: ADT atc-phy0 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy0 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc0_phy: phy@403000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x03000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_common>, + <&ps_atc0_common_dp_0>, <&ps_atc0_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bca4>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <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>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc0_phy_typec: endpoint { + remote-endpoint = <&typec0_ss>; + }; + }; + }; + }; + + /* + * USB-C Back-left: ADT atc-phy1 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy1 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc1_phy: phy@40b000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x0b000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_common>, + <&ps_atc1_common_dp_0>, <&ps_atc1_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <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>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc1_phy_typec: endpoint { + remote-endpoint = <&typec1_ss>; + }; + }; + }; + }; + + /* + * USB-C Back-right: ADT atc-phy3 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy3 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc3_phy: phy@413000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x13000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_common>, + <&ps_atc3_common_dp_0>, <&ps_atc3_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <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>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc3_phy_typec: endpoint { + remote-endpoint = <&typec3_ss>; + }; + }; + }; + }; + /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ usb2: usb@382430000 { compatible = "apple,t8152-dwc3"; From e7b569dfc2bfbdbdff8e565213cc9bc6dcc2e05e Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:41 +0100 Subject: [PATCH 119/121] thunderbolt: apple: stop the T8152 routers before a reboot A reboot or power-off shuts the PCIe-C host and the router's and the tunnel's DARTs down before the router, while a started router still runs over them. With the J873g's rear ports, the earlier port monitor stopped the routers from a reboot notifier for this. Without a port monitor, do that in the router driver: for routers whose match data asks for it (T8152), stop a started router from a reboot notifier, as the port driver does for an unplugged cable, and refuse a new start from then on. Signed-off-by: Thomas Glanzmann --- drivers/thunderbolt/apple.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index a22d8129a7b32..cdce656a28a5c 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -173,6 +174,8 @@ struct apple_cio_hw { bool host_tmu; /* Drain PSD runtime power-off before the PHY is reset or reused. */ bool psd_power_cycle; + /* Stop a started router before a reboot shuts its PCIe and DARTs down. */ + bool stop_at_reboot; const struct apple_dpin_policy *dp; }; @@ -211,6 +214,7 @@ static const struct apple_cio_hw apple_cio_t8132_hw = { /* MXWrap-v2p3 is started by reconfiguration, using its counted mailbox. */ static const struct apple_cio_hw apple_cio_t8152_hw = { .psd_power_cycle = true, + .stop_at_reboot = true, .type7 = true, .lstx_after_boot = true, .strict_fw_ready = true, @@ -513,6 +517,7 @@ struct apple_cio { u64 link_lost_cycle_activity; /* remote activity at the last cycle */ bool link_lost_restart; /* protected by lock: cycle requested */ struct notifier_block pm_notifier; + struct notifier_block reboot_notifier; /* * T6050: the displays behind this port go at the start of the sleep's entry, before any * port's power-off. @sleep_dp_paused: this entry closed the DP IN admission; @@ -4498,6 +4503,24 @@ static int apple_cio_pcie_notify(struct notifier_block *nb, return NOTIFY_OK; } +/* + * A reboot or power-off shuts the PCIe-C host and the router's and the + * tunnel's DARTs down before this device, with the router still running + * over them. Stop a started router first, as the port driver does for an + * unplugged cable, and refuse a new start from then on. + */ +static int apple_cio_reboot_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct apple_cio *acio = container_of(nb, struct apple_cio, reboot_notifier); + + guard(mutex)(&acio->lock); + acio->removing = true; + if (acio->current_cable_info) + apple_cio_stop(acio); + return NOTIFY_DONE; +} + static int apple_cio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -4759,6 +4782,10 @@ static int apple_cio_probe(struct platform_device *pdev) acio->pm_notifier_dp.notifier_call = apple_cio_dp_pm_notify; acio->pm_notifier_dp.priority = 20; register_pm_notifier(&acio->pm_notifier_dp); + if (acio->hw->stop_at_reboot) { + acio->reboot_notifier.notifier_call = apple_cio_reboot_notify; + register_reboot_notifier(&acio->reboot_notifier); + } return 0; } @@ -4766,6 +4793,8 @@ static void apple_cio_remove(struct platform_device *pdev) { struct apple_cio *acio = platform_get_drvdata(pdev); + if (acio->hw->stop_at_reboot) + unregister_reboot_notifier(&acio->reboot_notifier); /* Refuse new activation before draining callbacks and workers. */ scoped_guard(mutex, &acio->lock) acio->removing = true; From a35e6df2c67a381f74a3b3bb6ae3442f121880f9 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Fri, 20 Nov 2026 01:26:41 +0100 Subject: [PATCH 120/121] arm64: dts: apple: t8152-j873g: 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 and the LSTX pins. 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. 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. Each router's Thunderbolt switch (its port@1) is linked to the USB4 port (port@4) of its port's usb-c-connector, as on the J813: the PD controller driver sets the port's ATC PHY to CIO mode and then starts the router with the cable's EUDO and orientation, and stops the router before it takes the PHY out of CIO mode. Signed-off-by: Thomas Glanzmann --- .../arm64/boot/dts/apple/t8152-j873-usb4.dtsi | 1314 +++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 1315 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..ff1579e5d08f3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi @@ -0,0 +1,1314 @@ +// 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, and the T8152 PSD services they need. Each + * router's Thunderbolt switch is linked to the USB4 port (port@4) of its + * port's usb-c-connector, whose PD controller driver starts and stops it + * after it set the port's ATC PHY to CIO mode. + * + * Generated from the J873g ADT (27.2 iBoot): /arm-io/acio{0,1,3}, acio-cpuN, + * dart-acioN, apciecN and dart-apciecN. + * + * 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 = <&typec0_usb4>; + }; + }; + }; + }; + + 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 = <&typec1_usb4>; + }; + }; + }; + }; + + 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 = <&typec3_usb4>; + }; + }; + }; + }; + }; + + 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>; + }; +}; + +/* USB-C Back-middle: its router */ +&typec0 { + ports { + port@4 { + reg = <4>; + + typec0_usb4: endpoint { + remote-endpoint = <&usb4_0_sw>; + }; + }; + }; +}; + +/* USB-C Back-left: its router */ +&typec1 { + ports { + port@4 { + reg = <4>; + + typec1_usb4: endpoint { + remote-endpoint = <&usb4_1_sw>; + }; + }; + }; +}; + +/* USB-C Back-right: its router */ +&typec3 { + ports { + port@4 { + reg = <4>; + + typec3_usb4: endpoint { + remote-endpoint = <&usb4_3_sw>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 169298a6c9e6c..bc08534567499 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-usb4.dtsi" From 5f89281a4236f8f381516eba8db16b970ce71a18 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sun, 22 Nov 2026 15:30:42 +0100 Subject: [PATCH 121/121] arm64: dts: apple: t8152-j873g: power domains for the ACIO DARTs Every enabled DART must name the power state of the engine it serves (scripts/dtc/apple-dart-pd-check.py). The three rear routers' NHI DARTs named none. A DART sits inside its router, so it takes the router's first PSD service (59, 60 and 62: ADT acioN power-gates), the one the router powers up first and down last. The router populates the DART only once it is powered and its firmware is ready, and removes it before it powers down, so the DART's vote never holds the router on after a stop. Signed-off-by: Thomas Glanzmann --- arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi index ff1579e5d08f3..41083f7ebccaa 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi @@ -173,6 +173,7 @@ #iommu-cells = <1>; interrupt-parent = <&aic>; interrupts = ; + power-domains = <&cio_psd59>; apple,dma-range = <0x100 0x0 0x10 0x0>; apple,tunable = <0x20c 0x80000121 0x80000121>, @@ -442,6 +443,7 @@ #iommu-cells = <1>; interrupt-parent = <&aic>; interrupts = ; + power-domains = <&cio_psd60>; apple,dma-range = <0x100 0x0 0x10 0x0>; apple,tunable = <0x20c 0x80000121 0x80000121>, @@ -711,6 +713,7 @@ #iommu-cells = <1>; interrupt-parent = <&aic>; interrupts = ; + power-domains = <&cio_psd62>; apple,dma-range = <0x100 0x0 0x10 0x0>; apple,tunable = <0x20c 0x80000121 0x80000121>,