From 1780386d74e48dbb1847e0fc720ae775764d4abf Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:19 -0500 Subject: [PATCH 01/32] pinctrl: apple: Add the T8152 compatible The T8152 GPIO block has the same layout as the T8140 one. Match "apple,t8152-pinctrl" with the T8140 hardware data. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../devicetree/bindings/pinctrl/apple,pinctrl.yaml | 6 ++++++ drivers/pinctrl/pinctrl-apple-gpio.c | 1 + 2 files changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml index b8b4a24107cd1b..3a3015ddba3359 100644 --- a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml @@ -25,6 +25,7 @@ properties: - apple,t8122-pinctrl - apple,t8132-pinctrl - apple,t8140-pinctrl + - apple,t8152-pinctrl - const: apple,t8103-pinctrl - items: # Do not add additional SoC to this list. @@ -91,6 +92,11 @@ patternProperties: additionalProperties: false + '^.+-hog(-[0-9]+)?$': + type: object + required: + - gpio-hog + allOf: - $ref: pinctrl.yaml# diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index eee7f5014ecc18..620d0e57bb2ccb 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -597,6 +597,7 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) static const struct of_device_id apple_gpio_pinctrl_of_match[] = { { .compatible = "apple,t8140-pinctrl", .data = &apple_gpio_t8140_hw }, + { .compatible = "apple,t8152-pinctrl", .data = &apple_gpio_t8140_hw }, { .compatible = "apple,t8103-pinctrl", }, { .compatible = "apple,pinctrl", }, { } From 4f833b21bce201145c69d36db037a746e4760626 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:19 -0500 Subject: [PATCH 02/32] soc: apple: sart: Add the SARTv4 register layout T8152 has a SART with a new register layout: the per-entry config, physical address and size registers sit at 0x00, 0x60 and 0xc0. Add the operations for it and match "apple,t8152-sart". The binding lists the new compatible as a stand-alone entry. Measured on an M6 Mac mini with an earlier form of this change: the machine boots and runs its root file system from NVMe, which uses this SART. This version is compile-checked only. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../devicetree/bindings/iommu/apple,sart.yaml | 1 + drivers/soc/apple/sart.c | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index 472454c3d24d67..10fd165d1903db 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -40,6 +40,7 @@ properties: - apple,t6000-sart - apple,t8015-sart - apple,t8103-sart + - apple,t8152-sart reg: maxItems: 1 diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index b0b208c92741dc..e8777835d738a3 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -62,6 +62,18 @@ #define APPLE_SART3_FLAGS_ALLOW 0xff +/* SARTv4 (CoastGuard, T8152) registers; layout from m1n1 sart4 */ +#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 + struct apple_sart_ops { void (*get_entry)(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size); @@ -178,6 +190,35 @@ static struct apple_sart_ops sart_ops_v3 = { .size_max = APPLE_SART3_SIZE_MAX, }; + +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 int apple_sart_probe(struct platform_device *pdev) { int i; @@ -376,6 +417,10 @@ static const struct of_device_id apple_sart_of_match[] = { .compatible = "apple,t6000-sart", .data = &sart_ops_v3, }, + { + .compatible = "apple,t8152-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t8103-sart", .data = &sart_ops_v2, From 8024caf822f9ba64db8cf5f81555bc867c13ed3f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:19 -0500 Subject: [PATCH 03/32] nvme: apple: Add T8152 ANS support On T8152 the queue setup registers (admin queue, IO queues, the linear submission queue control) live at different offsets, and a few of them accept writes but read back zero. Add a register translation for that layout, skip the read-back checks that cannot work, and describe the controller with a new hardware data block matched by "apple,t8152-nvme-ans2". The ANS is a virtual PMGR device on this SoC and has no reset line, so the hardware data block carries a no_reset_control flag. Only T8152 skips the reset lookup. Every other SoC still requires a reset control and fails the probe without one, as before. The binding gets the new compatible. On T8152 the resets, power-domains and power-domain-names properties are not required, and the controller has two register regions (the NVMMU registers live in the first one). Measured on an M6 Mac mini with an earlier form of this change: the machine boots and runs its root file system from NVMe. This version is compile-checked only. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/nvme/apple,nvme-ans.yaml | 18 ++++- drivers/nvme/host/apple.c | 71 +++++++++++++++---- 2 files changed, 74 insertions(+), 15 deletions(-) diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index fc8a4afd5add47..d8a713e6726f60 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -29,6 +29,7 @@ properties: - apple,t8112-nvme-ans2 - apple,t6000-nvme-ans2 - const: apple,nvme-ans2 + - const: apple,t8152-nvme-ans2 reg: minItems: 2 @@ -125,13 +126,24 @@ allOf: reg-names: maxItems: 2 + # T8152 has no reset line and no PMGR power domains for the ANS: the ANS is + # a virtual PMGR device there. + - if: + not: + properties: + compatible: + contains: + const: apple,t8152-nvme-ans2 + then: + required: + - resets + - power-domains + - power-domain-names + required: - compatible - reg - reg-names - - resets - - power-domains - - power-domain-names - mboxes - interrupts - apple,sart diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index d3ef47fa840e49..815b298d3a430c 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -198,6 +198,12 @@ struct apple_nvme_hw { bool has_queue_count; bool has_separate_nvmmu; bool needs_ioq_registers; + /* T8152: LSQ_CTRL and IOQA accept writes but read back 0. */ + bool no_ioq_readback; + /* T8152: the queue setup registers live at different offsets. */ + bool t8152_reg_layout; + /* T8152: the ANS is a virtual PMGR device with no PS register, so there is no reset line. */ + bool no_reset_control; u32 max_queue_depth; unsigned long quirks; }; @@ -262,6 +268,27 @@ struct apple_nvme { struct blk_crypto_profile crypto_profile; }; +/* Map a legacy ANS register offset to the T8152 layout: admin queue +0x4000, IOQ registers +0x4000, + * LSQ_CTRL 0x24908 -> 0x2813c. */ +static u32 apple_nvme_reg(const struct apple_nvme *anv, u32 off) +{ + if (!anv->hw->t8152_reg_layout) + return off; + switch (off) { + case NVME_REG_AQA: + case NVME_REG_ASQ: + case NVME_REG_ACQ: + case APPLE_ANS_IOSQ_REGISTER: + case APPLE_ANS_IOCQ_REGISTER: + case APPLE_ANS_MAX_PEND_CMDS_CTRL: + return off + 0x4000; + case APPLE_ANS_LINEAR_SQ_CTRL: + return 0x2813c; + default: + return off; + } +} + /* Bit in recovery_flags: recovery_work owns the next controller stop. */ #define APPLE_NVME_RECOVERY_PENDING 0 @@ -1711,12 +1738,12 @@ static void apple_nvme_reset_work(struct work_struct *work) * since T6000. */ writel(APPLE_ANS_LINEAR_SQ_EN, - anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_LINEAR_SQ_CTRL)); if (anv->hw->needs_ioq_registers) { u32 lsq_ctrl = readl(anv->mmio_nvme + - APPLE_ANS_LINEAR_SQ_CTRL); + apple_nvme_reg(anv, APPLE_ANS_LINEAR_SQ_CTRL)); - if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN)) { + if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN) && !anv->hw->no_ioq_readback) { dev_err(anv->dev, "failed to enable linear submission queues: LSQ_CTRL=0x%08x\n", lsq_ctrl); @@ -1736,9 +1763,9 @@ 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); - if (anv->hw->needs_ioq_registers && - readl(anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL) != ioqa) { + writel(ioqa, anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)); + if (anv->hw->needs_ioq_registers && !anv->hw->no_ioq_readback && + readl(anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)) != ioqa) { dev_err(anv->dev, "failed to program I/O queue aperture\n"); ret = -EIO; goto out; @@ -1752,11 +1779,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_reg(anv, NVME_REG_AQA)); apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, - anv->mmio_nvme + NVME_REG_ASQ); + anv->mmio_nvme + apple_nvme_reg(anv, NVME_REG_ASQ)); apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, - anv->mmio_nvme + NVME_REG_ACQ); + anv->mmio_nvme + apple_nvme_reg(anv, NVME_REG_ACQ)); if (anv->hw->has_lsq_nvmmu) { /* Setup NVMMU for both queues */ @@ -1824,9 +1851,9 @@ static void apple_nvme_reset_work(struct work_struct *work) * reports null I/O SQ and CQ addresses. */ apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOCQ_REGISTER); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_IOCQ_REGISTER)); apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOSQ_REGISTER); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_IOSQ_REGISTER)); } nr_io_queues = 1; if (anv->hw->has_queue_count) { @@ -2309,7 +2336,11 @@ 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); + /* T8152's ANS is a virtual PMGR device with no PS register, so the DT has no reset to give. */ + if (anv->hw->no_reset_control) + anv->reset = NULL; + 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"); @@ -2642,11 +2673,27 @@ static const struct apple_nvme_hw apple_nvme_t8140_hw = { .quirks = NVME_QUIRK_BROKEN_FUA, }; +/* T8152: NVMMU registers sit in the 0x60000 NVMe window (no separate region; the T8140 + * alias window does not exist and faults). */ +static const struct apple_nvme_hw apple_nvme_t8152_hw = { + /* T8152 register layout, linear submission queue, 64 queue entries. */ + .has_lsq_nvmmu = true, + .has_queue_count = true, + .has_separate_nvmmu = false, + .no_ioq_readback = true, + .t8152_reg_layout = true, + .no_reset_control = true, + .needs_ioq_registers = true, + .max_queue_depth = 64, + .quirks = NVME_QUIRK_BROKEN_FUA, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t8015-nvme-ans2", .data = &apple_nvme_t8015_hw }, { .compatible = "apple,t8103-nvme-ans2", .data = &apple_nvme_t8103_hw }, { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, { .compatible = "apple,t8140-nvme-ans2", .data = &apple_nvme_t8140_hw }, + { .compatible = "apple,t8152-nvme-ans2", .data = &apple_nvme_t8152_hw }, { .compatible = "apple,nvme-ans2", .data = &apple_nvme_t8103_hw }, {}, }; From 24d1bb150e52d7ec5b1eaced2a3c12fbbf4554a7 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:20 -0500 Subject: [PATCH 04/32] pmdomain: apple: Add T8152 PSD service slot power domains On T8152 the ATC USB blocks (and the GPU) are behind a per-slot service request in the power state director, on top of the normal PMGR power states. Expose each slot, or a group of slots that must come up together, as a generic power domain. Power-on writes the slot request and waits for the acknowledge; power-off requests state 6 in reverse order. Add the devicetree binding. When a power-on request times out, the slot that timed out is put back to idle with the slots before it, because its acknowledge was not seen but it may still start. When a group power-off fails, every slot is put back to its active state, including a slot whose off request timed out and may still finish stopping, because genpd keeps the domain marked on after a failed power-off and would skip power_on at the next resume. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/power/apple,t8152-psd.yaml | 107 +++++++ drivers/pmdomain/apple/Kconfig | 12 + drivers/pmdomain/apple/Makefile | 1 + drivers/pmdomain/apple/pmgr-psd.c | 266 ++++++++++++++++++ 4 files changed, 386 insertions(+) create mode 100644 Documentation/devicetree/bindings/power/apple,t8152-psd.yaml create mode 100644 drivers/pmdomain/apple/pmgr-psd.c 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 00000000000000..4cd4c43122c90a --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml @@ -0,0 +1,107 @@ +# 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 PSD service slot power domain + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +allOf: + - $ref: power-domain.yaml# + +description: | + The T8152 (M6) power state director (PSD) gates some blocks, among them the + USB controllers and their DARTs, behind a per-port service slot. Each + slot has a 0x100 byte register window at the PSD base plus (slot << 8) with + the status (0x80), request (0x90), diagnostic (0xa0) and valid (0xbc) + registers. A consumer must power the parent PMGR domains of the block + first, then request state 0 (running) and wait for the acknowledge. This + node models that as a power domain: the PMGR domains are its parents + (power-domains), powering it on writes the request. Power-off requests + state 6 (off). + + A "apple,t8152-psd-group" node covers several slots that are brought up + together: one reg window per slot, requested in reg order with the active + state given by apple,psd-states, and put back to state 6 in reverse order. + +properties: + compatible: + enum: + - apple,t8152-psd + - apple,t8152-psd-group + + reg: + minItems: 1 + maxItems: 3 + + "#power-domain-cells": + const: 0 + + power-domains: + description: + Parent PMGR power domains, powered before the slot request. Absent when + the block has no PMGR power state. + minItems: 1 + maxItems: 4 + + label: + description: Name of the power domain. + + apple,psd-states: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 3 + description: + Active PSD state requested for each reg window, in reg order (default + 0, running). Each value is 0 to 5. + + apple,psd-timeout-ms: + description: Acknowledge timeout in milliseconds (default 1000). + +required: + - compatible + - reg + - "#power-domain-cells" + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + ps_usb_aon: power-controller-aon { + #power-domain-cells = <0>; + }; + + ps_usb: power-controller-usb { + #power-domain-cells = <0>; + }; + + power-controller@1000 { + compatible = "apple,t8152-psd"; + reg = <0x0 0x1000 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_usb_aon>, <&ps_usb>; + label = "psd_example"; + }; + }; + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + power-controller@2000 { + compatible = "apple,t8152-psd-group"; + reg = <0x0 0x2000 0x0 0x100>, + <0x0 0x2100 0x0 0x100>, + <0x0 0x2200 0x0 0x100>; + apple,psd-states = <0 2 2>; + #power-domain-cells = <0>; + label = "psd_group_example"; + }; + }; diff --git a/drivers/pmdomain/apple/Kconfig b/drivers/pmdomain/apple/Kconfig index 5f0a9d95c196c2..2e85b6d5031abe 100644 --- a/drivers/pmdomain/apple/Kconfig +++ b/drivers/pmdomain/apple/Kconfig @@ -25,6 +25,18 @@ config APPLE_PMGR_PWRSTATE_KUNIT_TEST driver's power callbacks against an emulated power state register and need no Apple hardware. +config APPLE_PMGR_PSD + bool "Apple T8152 PSD service slot power domains" + default ARCH_APPLE + depends on OF + depends on PM + select PM_GENERIC_DOMAINS + help + The M6 (T8152) power state director gates the ATC USB blocks behind a + per-port service slot request on top of the PMGR power states. This + driver exposes each slot as a power domain whose parents are the PMGR + domains, so consumers (the USB DARTs and controllers) power both in order. + config APPLE_PMP_REPORT bool "Apple PMP report control" depends on OF diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index ff7f9192b5e39f..c9f1e412f6ab93 100644 --- a/drivers/pmdomain/apple/Makefile +++ b/drivers/pmdomain/apple/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += pmgr-pwrstate.o +obj-$(CONFIG_APPLE_PMGR_PSD) += pmgr-psd.o obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += gfx-tvm.o obj-$(CONFIG_APPLE_PMP_REPORT) += pmp-report.o obj-$(CONFIG_APPLE_PMP_REPORT_KUNIT_TEST) += pmp-report-test.o diff --git a/drivers/pmdomain/apple/pmgr-psd.c b/drivers/pmdomain/apple/pmgr-psd.c new file mode 100644 index 00000000000000..9be3506d9ed5a8 --- /dev/null +++ b/drivers/pmdomain/apple/pmgr-psd.c @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 PSD (power state director) service slot power domains + * + * On the M6 the USB blocks are not usable (even their DART registers hang the bus) + * until two things have happened: the PMGR power states of the block are active, and the + * PSD service slot for the port has been requested to run (state 0) and has + * acknowledged. This driver models the second step as a genpd whose parents are the + * PMGR domains: genpd powers the parents first, then this domain's power_on writes the + * slot request and waits for the ack. + * + * Per-slot window (reg, 0x100 bytes at base + (slot << 8)): + * 0x80 status bits 2:0 = current PSD state + * 0x90 request (write a PSD state) + * 0xa0 diag + * 0xbc valid bit 0 = status is valid + * PSD states: this driver accepts states 0 (running) to 6 (off). + * + * Ack: the valid bit 0 is set and (status & 7) equals the requested state. + * + * Slot groups: a block that needs several slots (the GPU uses several) must bring them up + * together, in a fixed order, with possibly different active states. A node with compatible + * "apple,t8152-psd-group" lists one reg window per slot and apple,psd-states with each slot's + * active state; power_on requests the slots in reg order, power_off requests state 6 in reverse. + * + * Reading STATUS clears the acknowledge, so a request polls VALID first and reads + * STATUS only once VALID is set. + * + * Lifetime: this domain sleeps in power_on (usleep_range polling), so it is not IRQ-safe. + * The platform bus powers a consumer's single power domain on at attach time, before its + * probe runs, which issues the request in process context. A consumer that marks its + * runtime PM irq_safe (the Apple DART does) keeps this domain powered: genpd never powers off + * a sleepable domain holding an irq-safe device and skips the (atomic-context) power_on on + * its runtime resume (drivers/pmdomain/core.c irq_safe_dev_in_sleep_domain users). Other + * consumers may let it power off to state 6. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PSD_STATUS 0x80 +#define APPLE_PSD_REQUEST 0x90 +#define APPLE_PSD_DIAG 0xa0 +#define APPLE_PSD_VALID 0xbc +#define APPLE_PSD_STATE GENMASK(2, 0) +#define APPLE_PSD_VALID_BIT BIT(0) + +#define APPLE_PSD_STATE_RUNNING 0 +#define APPLE_PSD_STATE_OFF 6 + +#define APPLE_PSD_DEFAULT_TIMEOUT_MS 1000 /* default ack timeout, apple,psd-timeout-ms overrides it */ +#define APPLE_PSD_MAX_SLOTS 3 + +struct apple_psd { + struct device *dev; + void __iomem *regs[APPLE_PSD_MAX_SLOTS]; + u32 active[APPLE_PSD_MAX_SLOTS]; + unsigned int nslots; + struct generic_pm_domain genpd; + unsigned int timeout_ms; +}; + +#define to_apple_psd(d) container_of(d, struct apple_psd, genpd) + +static int apple_psd_request(struct apple_psd *psd, unsigned int slot, u32 state) +{ + void __iomem *regs = psd->regs[slot]; + unsigned long timeout = jiffies + msecs_to_jiffies(psd->timeout_ms); + u32 valid = 0, status = 0; + + writel(state, regs + APPLE_PSD_REQUEST); + + for (;;) { + valid = readl(regs + APPLE_PSD_VALID); + if (valid & APPLE_PSD_VALID_BIT) { + /* Reading STATUS clears the acknowledge, so only after VALID. */ + status = readl(regs + APPLE_PSD_STATUS); + if (FIELD_GET(APPLE_PSD_STATE, status) == state) + return 0; + } + if (time_after(jiffies, timeout)) + break; + usleep_range(50, 200); + } + + dev_err(psd->dev, + "PSD slot %u request %u not acknowledged: valid %#x status %#x diag %#x\n", slot, + state, valid, status, readl(regs + APPLE_PSD_DIAG)); + return -ETIMEDOUT; +} + +static int apple_psd_power_on(struct generic_pm_domain *genpd) +{ + struct apple_psd *psd = to_apple_psd(genpd); + int i, ret; + + for (i = 0; i < psd->nslots; i++) { + ret = apple_psd_request(psd, i, psd->active[i]); + if (ret) + goto undo; + } + return 0; + +undo: + /* + * Best effort: put the slots back to idle, newest first. The slot whose request timed + * out is included, because its acknowledge was not seen but it may still start. + */ + for (; i >= 0; i--) + apple_psd_request(psd, i, APPLE_PSD_STATE_OFF); + return ret; +} + +static int apple_psd_power_off(struct generic_pm_domain *genpd) +{ + struct apple_psd *psd = to_apple_psd(genpd); + int i, ret, first = 0; + + for (i = psd->nslots - 1; i >= 0; i--) { + ret = apple_psd_request(psd, i, APPLE_PSD_STATE_OFF); + if (ret && !first) + first = ret; + } + if (!first) + return 0; + + /* + * genpd keeps the domain marked on after a failed power-off, so the next resume does not + * call power_on. Put every slot back to its active state, best effort: the slots that + * did stop, and the one whose off request timed out and may still finish stopping. + */ + for (i = 0; i < psd->nslots; i++) + apple_psd_request(psd, i, psd->active[i]); + return first; +} + +static int apple_psd_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; + struct apple_psd *psd; + const char *name; + u32 status, valid; + unsigned int i; + int ret; + + psd = devm_kzalloc(dev, sizeof(*psd), GFP_KERNEL); + if (!psd) + return -ENOMEM; + psd->dev = dev; + psd->timeout_ms = APPLE_PSD_DEFAULT_TIMEOUT_MS; + of_property_read_u32(node, "apple,psd-timeout-ms", &psd->timeout_ms); + + for (i = 0; i < APPLE_PSD_MAX_SLOTS; i++) { + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, i); + + if (!res) + break; + psd->regs[i] = devm_ioremap_resource(dev, res); + if (IS_ERR(psd->regs[i])) + return PTR_ERR(psd->regs[i]); + psd->nslots++; + } + if (!psd->nslots) + return dev_err_probe(dev, -EINVAL, "no register window\n"); + + /* Per-slot active state, in reg order; default 0 (running). */ + if (of_property_present(node, "apple,psd-states")) { + ret = of_property_read_u32_array(node, "apple,psd-states", psd->active, + psd->nslots); + if (ret) + return dev_err_probe(dev, ret, "apple,psd-states needs one cell per reg\n"); + for (i = 0; i < psd->nslots; i++) + if (psd->active[i] >= APPLE_PSD_STATE_OFF) + return dev_err_probe(dev, -EINVAL, "bad PSD active state %u\n", + psd->active[i]); + } + + ret = of_property_read_string(node, "label", &name); + if (ret) + name = node->name; + psd->genpd.name = name; + psd->genpd.power_on = apple_psd_power_on; + psd->genpd.power_off = apple_psd_power_off; + + /* + * Always start OFF: an inherited status of state 0 without the valid bit is not an + * acknowledged P0, and the parents' state is not known here. The first consumer's + * power_on then issues the request (idempotent if the slot already runs P0). + * A status read is safe (proven on hardware); no write happens at probe. + */ + status = readl(psd->regs[0] + APPLE_PSD_STATUS); + valid = readl(psd->regs[0] + APPLE_PSD_VALID); + + ret = pm_genpd_init(&psd->genpd, NULL, true); + if (ret) + return dev_err_probe(dev, ret, "pm_genpd_init failed\n"); + + ret = of_genpd_add_provider_simple(node, &psd->genpd); + if (ret) { + dev_err(dev, "of_genpd_add_provider_simple failed: %d\n", ret); + goto err_remove; + } + + /* The PMGR parents are brought up before power_on runs. */ + for (i = 0; ; i++) { + struct of_phandle_args parent, child; + + ret = of_parse_phandle_with_args(node, "power-domains", "#power-domain-cells", i, + &parent); + if (ret == -ENOENT) + break; /* no (more) parents */ + if (ret) + goto err_unlink; + child.np = node; + child.args_count = 0; + ret = of_genpd_add_subdomain(&parent, &child); + if (ret < 0 && ret != -EPROBE_DEFER) + dev_err(dev, "failed to add parent domain %pOFn: %d\n", parent.np, ret); + of_node_put(parent.np); + if (ret < 0) + goto err_unlink; + } + ret = 0; + + /* Parent domains are handled through the genpd hierarchy, not as a device. */ + pm_genpd_remove_device(dev); + + dev_info(dev, "PSD slot domain %s, %u slot(s) (status %#x valid %#x at probe, starting off)\n", + name, psd->nslots, status, valid); + return 0; + +err_unlink: + /* pm_genpd_remove() drops any parent links added so far. */ + of_genpd_del_provider(node); +err_remove: + pm_genpd_remove(&psd->genpd); + return ret; +} + +static const struct of_device_id apple_psd_of_match[] = { + { .compatible = "apple,t8152-psd" }, + { .compatible = "apple,t8152-psd-group" }, + { } +}; +MODULE_DEVICE_TABLE(of, apple_psd_of_match); + +static struct platform_driver apple_psd_driver = { + .probe = apple_psd_probe, + .driver = { + .name = "apple-pmgr-psd", + .of_match_table = apple_psd_of_match, + .suppress_bind_attrs = true, + }, +}; +builtin_platform_driver(apple_psd_driver); + +MODULE_DESCRIPTION("Apple T8152 PSD service slot power domains"); +MODULE_LICENSE("Dual MIT/GPL"); From e123886f0215c2238a0700ee699f9064a8094ec1 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:20 -0500 Subject: [PATCH 05/32] phy: apple: Add a T8152 fixed-host USB2 PHY driver The fixed host ports on T8152 need only the USB2 part of the PHY. Add a driver that applies the bootloader-supplied calibration, handles host and device mode, and leaves the USB3 and USB4 lanes alone. Add the devicetree binding. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/phy/apple,t8152-usb2-phy.yaml | 79 ++++++ drivers/phy/apple/Kconfig | 11 + drivers/phy/apple/Makefile | 3 + drivers/phy/apple/usb2-t8152.c | 231 ++++++++++++++++++ 4 files changed, 324 insertions(+) create mode 100644 Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml create mode 100644 drivers/phy/apple/usb2-t8152.c diff --git a/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml new file mode 100644 index 00000000000000..55c8b3b9a3d64c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/apple,t8152-usb2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 USB2 PHY + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +description: | + The USB2 and eUSB2 register banks support a fixed host or fixed peripheral + connection independently of the ATC USB3 and USB4 lanes. Firmware supplies + device-specific calibration. Both independent USB power domains must stay + active while the PHY runs. + +$defs: + tunable: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: | + Register offset, clear mask, and set value triples for the usb2 bank. + The bootloader supplies these at boot; they are not part of the board file. + items: + items: + - description: Aligned byte offset within the usb2 register bank + - description: Bits to clear + - description: Bits to set + +properties: + compatible: + const: apple,t8152-usb2-phy + + reg: + items: + - description: USB2 PHY register bank + - description: eUSB2 PHY register bank + + reg-names: + items: + - const: usb2 + - const: eusb2 + + '#phy-cells': + const: 0 + + power-domains: + items: + - description: USB always-on domain + - description: USB controller domain + + power-domain-names: + items: + - const: usb-aon + - const: usb + + apple,tunable-usb2phy-dflt: + $ref: '#/$defs/tunable' + description: Default calibration, applied before the role calibration. + + apple,tunable-usb2phy-host: + $ref: '#/$defs/tunable' + description: Host calibration, applied before the PHY leaves reset. + + apple,tunable-usb2phy-dev: + $ref: '#/$defs/tunable' + description: | + Device-mode calibration, applied before the PHY leaves reset in peripheral + mode. + +required: + - compatible + - reg + - reg-names + - '#phy-cells' + - power-domains + - power-domain-names + +additionalProperties: false diff --git a/drivers/phy/apple/Kconfig b/drivers/phy/apple/Kconfig index 66c71acb005156..95b31a796e4cf3 100644 --- a/drivers/phy/apple/Kconfig +++ b/drivers/phy/apple/Kconfig @@ -40,3 +40,14 @@ config PHY_APPLE_DPTX such as the M2. This driver provides support for DisplayPort and is used on the Mac mini (M2 and M2 Pro, 2023). + +config PHY_APPLE_T8152_USB2 + tristate "Apple T8152 fixed-host USB2 PHY" + default ARCH_APPLE + depends on ARCH_APPLE || COMPILE_TEST + depends on PM + select GENERIC_PHY + select APPLE_TUNABLE + help + Enable the USB2-only PHY for fixed host ports on Apple T8152. + This does not configure the USB3 or USB4 lanes. diff --git a/drivers/phy/apple/Makefile b/drivers/phy/apple/Makefile index b9e7bf3e4ac170..bc33678c64707a 100644 --- a/drivers/phy/apple/Makefile +++ b/drivers/phy/apple/Makefile @@ -5,3 +5,6 @@ phy-apple-atc-y := atc.o obj-$(CONFIG_PHY_APPLE_DPTX) += phy-apple-dptx.o phy-apple-dptx-y += dptx.o + +obj-$(CONFIG_PHY_APPLE_T8152_USB2) += phy-apple-t8152-usb2.o +phy-apple-t8152-usb2-y := usb2-t8152.o diff --git a/drivers/phy/apple/usb2-t8152.c b/drivers/phy/apple/usb2-t8152.c new file mode 100644 index 00000000000000..6bb54dfe301030 --- /dev/null +++ b/drivers/phy/apple/usb2-t8152.c @@ -0,0 +1,231 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB2_CONTROL 0x00 +#define USB2_RESET 0x04 +#define USB2_VBUS 0x08 +#define USB2_VBUS_FORCE GENMASK(3, 0) +#define USB2_HOST_MODE GENMASK(14, 12) +#define USB2_CLOCK 0x1c +#define USB2_MODE GENMASK(2, 0) +#define USB2_RUN 2 +#define USB2_STOP 4 +#define USB2_RESET_ASSERT BIT(0) +#define USB2_PORT_RESET BIT(1) +#define USB2_APB_RESET_N BIT(2) +#define USB2_SIDDQ BIT(3) +#define USB2_REFCLK_GATE BIT(29) +#define USB2_PHYCLOCK_GATE BIT(30) +/* + * Bits that the host path sets. Their function is not documented; they are + * named by position. + */ +#define USB2_VBUS_HOST_BIT2 BIT(2) +#define USB2_VBUS_HOST_BIT3 BIT(3) +#define EUSB2_HOST_ENABLE (BIT(0) | BIT(3)) +/* + * Device-mode value of the misc-tune register from m1n1 src/usb.c + * usb_phy_bringup(), the role-agnostic USB2 device console setup. The word + * leaves the same refclk/APB gate bits clear that the host path clears below. + */ +#define USB2_DEVICE_MISCTUNE 0x008c0813 + +struct apple_usb2 { + void __iomem *usb2; + void __iomem *eusb2; + struct apple_tunable *dflt; + struct apple_tunable *host; + struct apple_tunable *dev; + enum phy_mode mode; +}; + +static void apple_usb2_update(void __iomem *reg, u32 clear, u32 set) +{ + writel((readl(reg) & ~clear) | set, reg); +} + +static int apple_usb2_power_on(struct phy *phy) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + apple_tunable_apply(usb->usb2, usb->dflt); + if (usb->mode == PHY_MODE_USB_DEVICE) { + if (!usb->dev) + return -EINVAL; + apple_tunable_apply(usb->usb2, usb->dev); + } else { + if (!usb->host) + return -EINVAL; + apple_tunable_apply(usb->usb2, usb->host); + } + if (usb->mode == PHY_MODE_USB_DEVICE) { + apple_usb2_update(usb->usb2 + USB2_VBUS, USB2_HOST_MODE, USB2_VBUS_FORCE); + } else { + apple_usb2_update(usb->usb2 + USB2_VBUS, 0, USB2_VBUS_HOST_BIT2); + apple_usb2_update(usb->usb2 + USB2_VBUS, 0, USB2_VBUS_HOST_BIT3); + } + msleep(10); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_SIDDQ, 0); + udelay(10); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_RESET_ASSERT, 0); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_PORT_RESET, 0); + apple_usb2_update(usb->eusb2, 0, EUSB2_HOST_ENABLE); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_APB_RESET_N); + if (usb->mode == PHY_MODE_USB_DEVICE) + writel(USB2_DEVICE_MISCTUNE, usb->usb2 + USB2_CLOCK); + else { + apple_usb2_update(usb->usb2 + USB2_CLOCK, USB2_REFCLK_GATE, 0); + apple_usb2_update(usb->usb2 + USB2_CLOCK, USB2_PHYCLOCK_GATE, 0); + } + udelay(30); + msleep(5); + apple_usb2_update(usb->usb2 + USB2_CONTROL, USB2_MODE, USB2_RUN); + + return 0; +} + +static int apple_usb2_power_off(struct phy *phy) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + if (!(readl(usb->usb2 + USB2_RESET) & USB2_PORT_RESET)) { + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_PORT_RESET); + msleep(5); + } + apple_usb2_update(usb->usb2 + USB2_CONTROL, USB2_MODE, USB2_STOP); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_SIDDQ); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_RESET_ASSERT); + apple_usb2_update(usb->usb2 + USB2_CLOCK, 0, USB2_REFCLK_GATE); + apple_usb2_update(usb->usb2 + USB2_CLOCK, 0, USB2_PHYCLOCK_GATE); + + return 0; +} + +static int apple_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + (void)submode; + if (mode != PHY_MODE_USB_HOST && mode != PHY_MODE_USB_DEVICE) + return -EINVAL; + if (mode == PHY_MODE_USB_DEVICE && !usb->dev) + return -EINVAL; + if (mode == PHY_MODE_USB_HOST && !usb->host) + return -EINVAL; + usb->mode = mode; + + return 0; +} + +static const struct phy_ops apple_usb2_ops = { + .power_on = apple_usb2_power_on, + .power_off = apple_usb2_power_off, + .set_mode = apple_usb2_set_mode, + .owner = THIS_MODULE, +}; + +static int apple_usb2_probe(struct platform_device *pdev) +{ + static const char * const pd_names[] = { "usb-aon", "usb" }; + const struct dev_pm_domain_attach_data pd_data = { + .pd_names = pd_names, + .num_pd_names = ARRAY_SIZE(pd_names), + }; + struct device *dev = &pdev->dev; + struct dev_pm_domain_list *domains; + struct phy_provider *provider; + struct resource *res; + struct apple_usb2 *usb; + struct phy *phy; + int ret; + + if (of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells") != ARRAY_SIZE(pd_names)) + return dev_err_probe(dev, -EINVAL, "Both USB2 power domains are required\n"); + + usb = devm_kzalloc(dev, sizeof(*usb), GFP_KERNEL); + if (!usb) + return -ENOMEM; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2"); + usb->usb2 = devm_ioremap_resource(dev, res); + if (IS_ERR(usb->usb2)) + return PTR_ERR(usb->usb2); + if (resource_size(res) < USB2_CLOCK + sizeof(u32)) + return -EINVAL; + + usb->dflt = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-dflt", res); + if (IS_ERR(usb->dflt)) + return dev_err_probe(dev, PTR_ERR(usb->dflt), "Invalid default tunables\n"); + usb->host = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-host", res); + if (IS_ERR(usb->host)) { + if (PTR_ERR(usb->host) != -ENOENT) + return dev_err_probe(dev, PTR_ERR(usb->host), "Invalid host tunables\n"); + usb->host = NULL; + } + usb->dev = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-dev", res); + if (IS_ERR(usb->dev)) { + if (PTR_ERR(usb->dev) != -ENOENT) + return dev_err_probe(dev, PTR_ERR(usb->dev), "Invalid device tunables\n"); + usb->dev = NULL; + } + if (!usb->host && !usb->dev) + return dev_err_probe(dev, -EINVAL, "No USB2 role calibration\n"); + /* Default to the role whose calibration the board actually supplies. */ + usb->mode = usb->host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "eusb2"); + usb->eusb2 = devm_ioremap_resource(dev, res); + if (IS_ERR(usb->eusb2)) + return PTR_ERR(usb->eusb2); + if (resource_size(res) < sizeof(u32)) + return -EINVAL; + + ret = devm_pm_domain_attach_list(dev, &pd_data, &domains); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to attach USB2 power domains\n"); + if (ret != ARRAY_SIZE(pd_names)) + return -ENODEV; + + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + phy = devm_phy_create(dev, NULL, &apple_usb2_ops); + if (IS_ERR(phy)) + return PTR_ERR(phy); + phy_set_drvdata(phy, usb); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id apple_usb2_match[] = { + { .compatible = "apple,t8152-usb2-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, apple_usb2_match); + +static struct platform_driver apple_usb2_driver = { + .probe = apple_usb2_probe, + .driver = { + .name = "apple-t8152-usb2-phy", + .of_match_table = apple_usb2_match, + }, +}; +module_platform_driver(apple_usb2_driver); + +MODULE_DESCRIPTION("Apple T8152 USB2 PHY"); +MODULE_LICENSE("Dual MIT/GPL"); From 57630388edcc181573e70c5933ae9da0bb38093e Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 20:25:20 -0500 Subject: [PATCH 06/32] usb: core: hub: Disable autosuspend for the 05ac:800f hub A hub with the Apple ID 05ac:800f sits behind the front ports of the M6 Mac mini. Add that ID to the hub quirk table with HUB_QUIRK_DISABLE_AUTOSUSPEND so the kernel keeps it powered. The match is on the vendor and product ID alone. Every hub with this ID loses autosuspend, not only the one on this machine. The constant is named after the ID, USB_PRODUCT_APPLE_HUB_800F, because the ID is Apple's and the part behind it was not identified from the descriptor. This quirk was not measured on its own: it only keeps the hub awake. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/usb/core/hub.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index f2e6718c3dfc4e..12ee0f33976afe 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -55,6 +55,8 @@ #define USB_PRODUCT_TUSB8041_USB3 0x8140 #define USB_PRODUCT_TUSB8041_USB2 0x8142 #define USB_VENDOR_MICROCHIP 0x0424 +#define USB_VENDOR_APPLE 0x05ac +#define USB_PRODUCT_APPLE_HUB_800F 0x800f #define USB_PRODUCT_USB4913 0x4913 #define USB_PRODUCT_USB4914 0x4914 #define USB_PRODUCT_USB4915 0x4915 @@ -6251,6 +6253,11 @@ static const struct usb_device_id hub_id_table[] = { | USB_DEVICE_ID_MATCH_PRODUCT, .idVendor = USB_VENDOR_VIA_LABS, .idProduct = USB_PRODUCT_VL122, + .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, + { .match_flags = USB_DEVICE_ID_MATCH_VENDOR + | USB_DEVICE_ID_MATCH_PRODUCT, + .idVendor = USB_VENDOR_APPLE, + .idProduct = USB_PRODUCT_APPLE_HUB_800F, .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, { .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT, From b871c3a7c3ed11910f6d69298058a87740eb9e7f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 21 Oct 2026 21:17:59 -0500 Subject: [PATCH 07/32] arm64: dts: apple: t8152-j873g: Add the peripherals that have drivers Add a peripherals fragment to the M6 Mac mini board file: the always-on GPIO controller with the reset hog for the front-port USB hub, and the four PSD service slots for the USB ports. The NVMe controller, its mailbox and its address filter are not described here. The NVMe node needs a mailbox driver change that is not in this tree yet. The fragment holds only addresses, interrupt numbers and wiring. The boot loader adds the register tunables that some blocks need. The PMGR power domains are not described yet, so nodes that need them are left out. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../dts/apple/t8152-j873g-peripherals.dtsi | 71 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 2 + 2 files changed, 73 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi new file mode 100644 index 00000000000000..1099f76d189cf2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple Mac mini (M6), J873g: peripherals that have a driver in this tree. + * + * Only addresses, interrupt numbers and wiring are described here. The boot + * loader adds the register tunables that some of these blocks need. The + * power-management (PMGR) domains are not described yet, so nodes that need + * them are left out. + */ + +#include + +/ { + soc { + /* GPIO controller of the always-on block. Pin 39 releases the reset of the front-port USB hub. */ + nub_pinctrl: pinctrl@3081f0000 { + compatible = "apple,t8152-pinctrl", "apple,t8103-pinctrl"; + reg = <3 0x081f0000 0 0x4000>; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&nub_pinctrl 0 0 40>; + apple,npins = <40>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + ; + + vl822-reset-n-hog { + gpio-hog; + gpios = <39 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "vl822-reset-n"; + }; + }; + + /* Power state director: one service slot per USB port, 0x100 bytes each. */ + psd_atc0_usb: power-controller@303a14700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14700 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc0_usb"; + }; + + psd_atc1_usb: power-controller@303a14800 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14800 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc1_usb"; + }; + + psd_atc2_usb: power-controller@303a14900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14900 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc2_usb"; + }; + + psd_atc3_usb: power-controller@303a14a00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14a00 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc3_usb"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 6b5e14036c98af..05f723a7d36176 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -247,3 +247,5 @@ }; }; }; + +#include "t8152-j873g-peripherals.dtsi" From 781ef18af827d23c257b608f840cedd53e6cad3f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 08:05:49 -0500 Subject: [PATCH 08/32] iommu/apple-dart: Add the T8152 Gen3 DART Add the DART of the Apple M6 (T8152), a third-generation DART whose topology is fixed by the hardware. Its streams are described by static parameters instead of being probed, and it takes no MMIO access until the first use, because the block can be power gated behind the ATC USB domains. The binding requires a second register region (the TLB invalidate doorbell) for the T8152 compatible only. The change adds: - the apple,t8152-dart compatible and its hardware description; - static topology and "first use" initialisation of every DART; - the Gen3 TLB invalidate and the fault handler; - the reset path for DARTs that the boot loader leaves locked. A DART that the boot loader leaves locked is held powered for its lifetime. That applies to Gen3 hardware only. The other generations keep their behaviour. The first-use initialisation re-reads the parameters and fails if the page size differs from the one assumed at probe. It runs under a spinlock, and every function it calls is non-sleeping (register accesses and an atomic poll). Measured on an M6 Mac mini with the earlier form of this change: the display controller DART attaches locked on every boot. This version is rebased on current integration/aurora and was compile-checked only. The USB DART paths need the T8152 PSD power domains and were not run on their own. The doorbell store and the TLBI of the Gen3 invalidate are arm64 instructions: they are built only with CONFIG_ARM64, and other architectures (COMPILE_TEST) get a stub that returns -EOPNOTSUPP. A locked Gen3 DART no longer takes the range flush through TLB_CMD, which Gen3 does not accept; it uses the full-stream Gen3 callback. Gen3 does not take commands through TLB_CMD, so the unlock after a lock-on-error exception is not sent there: the DART logs once that this is not supported. The stale-exception drain of a reset does not read 0x704 on Gen3, like the fault handler. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../devicetree/bindings/iommu/apple,dart.yaml | 32 +- drivers/iommu/apple-dart.c | 398 ++++++++++++++++-- 2 files changed, 386 insertions(+), 44 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 44a0499ada2cbc..8996f8aef1e797 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -28,6 +28,7 @@ properties: - apple,t8103-usb4-dart - apple,t8110-dart - apple,t6000-dart + - apple,t8152-dart - items: - enum: - apple,t6000-dart @@ -42,11 +43,24 @@ properties: - const: apple,t8110-dart reg: - maxItems: 1 + minItems: 1 + maxItems: 2 interrupts: maxItems: 1 + apple,static-topology: + type: boolean + description: | + apple,t8152-dart only. Do not touch the DART registers at probe. Use a + fixed topology and defer the tunables, parameter read, lock check, reset + and fault handling to the first runtime resume (the first consumer). For + DARTs behind a power or availability gate that firmware controls. + + apple,num-streams: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Stream count assumed by apple,static-topology (default 16). + clocks: description: Reference to the gate clock phandle if required for this IOMMU. @@ -115,6 +129,22 @@ properties: and filtering state without a separate page-table root. Source and destination must differ, and both must exist on the controller. +allOf: + # Only apple,t8152-dart has a second register region (the shared TLB invalidate doorbell). + - if: + properties: + compatible: + contains: + const: apple,t8152-dart + then: + properties: + reg: + minItems: 2 + else: + properties: + reg: + maxItems: 1 + required: - compatible - reg diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 73af536772fc20..75682a5266a4fc 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -179,6 +179,11 @@ #define DART_T8110_DIAG_LOCK 0x210 #define DART_T8110_DIAG_LOCK_ON_ERR BIT(1) +/* T8152 Gen3: low nibble selects the TLBI route for this DART instance */ +#define DART_GEN3_ROUTE 0x4604 +/* AppleGen3DART _DART_ERR_SID_AXI_ID/_AXI_USER: 2 and 8 words per SID record */ +#define DART_GEN3_ERR_SID_AXI_ID(sid) (DART_T8110_ERR_SID(sid) + 0x18) +#define DART_GEN3_ERR_SID_AXI_USER(sid) (DART_T8110_ERR_SID(sid) + 0x20) #define DART_T8110_ENABLE_STREAMS 0xc00 #define DART_T8110_DISABLE_STREAMS 0xc20 @@ -216,6 +221,7 @@ struct apple_dart_hw { 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); + bool gen3; u32 oas; enum io_pgtable_fmt fmt; @@ -288,6 +294,7 @@ struct apple_dart { u32 supports_bypass : 1; u32 four_level : 1; u32 locked : 1; + u32 force_available : 1; u32 tunneled : 1; u32 per_stream : 1; u32 power_retained : 1; @@ -300,6 +307,18 @@ struct apple_dart { /* Resume restored the translations, but the last steps of its reset failed. */ bool reset_incomplete; struct apple_tunable *tunables; + /* + * Gen3 static topology: no DART MMIO at probe. Topology comes from fixed + * values; tunables, parameter read, lock check, reset and the fault IRQ + * wait for the first runtime resume (first consumer). + */ + u32 static_topo : 1; + u32 hw_ready : 1; + u32 irq_requested : 1; + /* Serialises the first-use init: resume, attach and the fault IRQ can all reach it. */ + spinlock_t late_lock; + /* Gen3 (T8152): shared TLBI doorbell and per-instance route register */ + void __iomem *tlbi; u16 version; DECLARE_BITMAP(remapped, DART_MAX_STREAMS); @@ -468,6 +487,8 @@ struct apple_dart_master_cfg { stream_map = &(base)->stream_maps[++i]) static struct platform_driver apple_dart_driver; +static int apple_dart_cfg_ensure_ready(struct apple_dart_master_cfg *cfg); +static int apple_dart_gen3_ensure_ready(struct apple_dart *dart); static const struct iommu_ops apple_dart_iommu_ops; static struct apple_dart_domain *to_dart_domain(struct iommu_domain *dom) @@ -1246,6 +1267,44 @@ apple_dart_t8110_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) stream_map, DART_T8110_TLB_CMD_OP_FLUSH_SID, false, 0, 0); } +/* + * Gen3 (T8152) DARTs do not take TLB invalidates through TLB_CMD. Apple's SPTM + * (gen3dart_write_tlbi_cmd_payload) stores a 128-bit payload to a TLBI + * aperture, then issues TLBI VALE1OS. Layout as used by m1n1 (accepted on + * DCP SID 23 without an exception): lo = BIT(60) | route << 56 | sid << 48. + * Writes one flush-SID doorbell per stream; no range invalidate. + */ +#ifdef CONFIG_ARM64 +static int apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + struct apple_dart *dart = stream_map->dart; + u64 route = readl(dart->regs + DART_GEN3_ROUTE) & 0xf; + unsigned long flags; + int sid; + + spin_lock_irqsave(&dart->lock, flags); + for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { + u64 lo = BIT_ULL(60) | route << 56 | (u64)sid << 48; + u64 hi = 0; + + dma_wmb(); + asm volatile("stp %0, %1, [%2]\n" + "dsb ish\n" + ".inst 0xd50881bf\n" /* tlbi vale1os, xzr */ + "dsb osh\n" + :: "r"(lo), "r"(hi), "r"(dart->tlbi) : "memory"); + } + spin_unlock_irqrestore(&dart->lock, flags); + return 0; +} +#else +/* The doorbell store and TLBI are arm64 instructions; other architectures build only for COMPILE_TEST. */ +static int apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + return -EOPNOTSUPP; +} +#endif + static const char *apple_dart_t8110_v2_fault_name(u32 exception); static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) @@ -1295,7 +1354,8 @@ static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) readl(dart->regs + DART_T8110_EXCEPTION(0)); } - if (dart->version >= 0x0203) + /* Gen3: 0x704 is not in AppleGen3DART's register capture list; do not touch it. */ + if (dart->version >= 0x0203 && !dart->hw->gen3) readl(dart->regs + DART_T8110_BLOCK_ERROR); if (drained) @@ -1313,6 +1373,13 @@ static int apple_dart_t8110_v2_unlock(struct apple_dart *dart) if (!(readl(dart->regs + DART_T8110_DIAG_LOCK) & DART_T8110_DIAG_LOCK_ON_ERR)) return 0; + /* Gen3 does not take commands through TLB_CMD, so the unlock command cannot be sent there. */ + if (dart->hw->gen3) { + dev_warn_once(dart->dev, + "Gen3 DART: unlock after a lock-on-error exception is not supported\n"); + return 0; + } + /* Unlock after acknowledging a lock-on-error exception. */ __set_bit(0, stream_map.sidmap); return apple_dart_t8110_hw_tlb_command_range(&stream_map, @@ -1407,7 +1474,8 @@ static int apple_dart_hw_finish_reset(struct apple_dart *dart) dart->hw->error); } - if (dart->hw->type == DART_T8110) + /* Gen3: 0x104 is not in AppleGen3DART's register capture list; leave it alone. */ + if (dart->hw->type == DART_T8110 && !dart->hw->gen3) apple_dart_writel(dart, 0, DART_T8110_ERROR_MASK); bitmap_set(stream_map.sidmap, 0, dart->num_streams); @@ -1480,7 +1548,8 @@ static int apple_dart_domain_flush_tlb_range(struct apple_dart_domain *domain, 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) + else if (range && stream.dart->locked && !stream.dart->hw->gen3 && + stream.dart->version >= 0x0202) ret = apple_dart_t8110_hw_tlb_command_range(&stream, op, true, start, end); else @@ -1959,6 +2028,9 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + ret = apple_dart_cfg_ensure_ready(cfg); + if (ret) + goto err; ret = apple_dart_finalize_domain(dart_domain, cfg); if (ret) goto err; @@ -2000,6 +2072,12 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + if (apple_dart_cfg_ensure_ready(cfg)) { + for_each_stream_map(i, cfg, stream_map) + pm_runtime_put(stream_map->dart->dev); + return -ENODEV; + } + for_each_stream_map(i, cfg, stream_map) apple_dart_hw_enable_bypass(stream_map); @@ -2031,6 +2109,12 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + if (apple_dart_cfg_ensure_ready(cfg)) { + for_each_stream_map(i, cfg, stream_map) + pm_runtime_put(stream_map->dart->dev); + return -ENODEV; + } + for_each_stream_map(i, cfg, stream_map) apple_dart_hw_disable_dma(stream_map); @@ -2057,10 +2141,16 @@ static struct iommu_device *apple_dart_probe_device(struct device *dev) if (!dev_iommu_fwspec_get(dev) || !cfg) return ERR_PTR(-ENODEV); - for_each_stream_map(i, cfg, stream_map) + for_each_stream_map(i, cfg, stream_map) { device_link_add(dev, stream_map->dart->dev, DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER | DL_FLAG_RPM_ACTIVE); + if (stream_map->dart->static_topo) + dev_dbg(dev, "uses static-topology DART %s, sids %*pbl, hw_ready %d, rpm status %d\n", + dev_name(stream_map->dart->dev), stream_map->dart->num_streams, + stream_map->sidmap, stream_map->dart->hw_ready, + stream_map->dart->dev->power.runtime_status); + } return &cfg->stream_maps[0].dart->iommu; } @@ -2707,7 +2797,7 @@ static bool apple_dart_t8110_v2_block_pending(u16 version, u32 block_error) (block_error & DART_T8110_BLOCK_ERROR_MASK); } -static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) +static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev, bool gen3) { struct apple_dart *dart = dev; irqreturn_t ret = IRQ_NONE; @@ -2751,6 +2841,16 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) "write" : "read", apple_dart_t8110_v2_fault_name(status), addr, status); + if (gen3) + dev_err_ratelimited(dart->dev, + " SID:%u AXI_ID %#x/%#x AXI_USER %#x/%#x raw+4 %#x raw+10 %#x\n", + sid, + readl(dart->regs + DART_GEN3_ERR_SID_AXI_ID(sid)), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_ID(sid) + 4), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_USER(sid)), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_USER(sid) + 4), + readl(dart->regs + DART_T8110_ERR_SID(sid) + 0x4), + readl(dart->regs + DART_T8110_ERR_SID(sid) + 0x10)); } /* @@ -2767,7 +2867,8 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) readl(dart->regs + DART_T8110_EXCEPTION(0)); } - if (dart->version >= 0x0203) { + /* Gen3: 0x704 is not in AppleGen3DART's register capture list; do not touch it. */ + if (!gen3 && dart->version >= 0x0203) { block_error = readl(dart->regs + DART_T8110_BLOCK_ERROR); if (apple_dart_t8110_v2_block_pending(dart->version, block_error)) { dev_err_ratelimited(dart->dev, @@ -2789,11 +2890,16 @@ static irqreturn_t apple_dart_t8110_irq(int irq, void *dev) struct apple_dart *dart = dev; if (dart->version >= 0x0202) - return apple_dart_t8110_v2_irq(irq, dev); + return apple_dart_t8110_v2_irq(irq, dev, false); return apple_dart_t8110_legacy_irq(irq, dev); } +static irqreturn_t apple_dart_gen3_irq(int irq, void *dev) +{ + return apple_dart_t8110_v2_irq(irq, dev, true); +} + static irqreturn_t apple_dart_irq(int irq, void *dev) { irqreturn_t ret = IRQ_NONE; @@ -2801,6 +2907,17 @@ static irqreturn_t apple_dart_irq(int irq, void *dev) if (READ_ONCE(dart->commands_gated)) return IRQ_NONE; + /* + * Static topology: no MMIO before the first consumer. A powered (runtime-active) DART that + * still raises a fault was never initialised: do the first-use init here, which also + * clears the pending error, rather than leave a level IRQ nobody claims. + */ + if (dart->static_topo && !dart->hw_ready) { + if (!pm_runtime_active(dart->dev) || apple_dart_gen3_ensure_ready(dart)) + return IRQ_NONE; + dev_warn_ratelimited(dart->dev, "fault before first-use init; initialised from the IRQ path\n"); + return IRQ_HANDLED; + } if (pm_runtime_resume_and_get(dart->dev) < 0) return IRQ_NONE; if (!READ_ONCE(dart->commands_gated)) @@ -2850,10 +2967,141 @@ apple_dart_platform_ioremap_np_resource(struct platform_device *pdev, return regs; } -static int apple_dart_probe(struct platform_device *pdev) +static const struct apple_dart_hw apple_dart_hw_t8152; + +static void apple_dart_read_params(struct apple_dart *dart) { - int ret, sid; u32 dart_params[4]; + + dart_params[0] = apple_dart_readl(dart, DART_PARAMS1); + dart_params[1] = apple_dart_readl(dart, DART_PARAMS2); + dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]); + dart->supports_bypass = dart_params[1] & DART_PARAMS2_BYPASS_SUPPORT; + + switch (dart->hw->type) { + case DART_T8020: + case DART_T6000: + dart->ias = 32; + dart->oas = dart->hw->oas; + dart->num_streams = dart->hw->max_sid_count; + break; + + case DART_T8110: + dart_params[2] = apple_dart_readl(dart, DART_T8110_PARAMS3); + dart->ias = FIELD_GET(DART_T8110_PARAMS3_VA_WIDTH, dart_params[2]); + dart->oas = FIELD_GET(DART_T8110_PARAMS3_PA_WIDTH, dart_params[2]); + dart_params[3] = apple_dart_readl(dart, DART_T8110_PARAMS4); + dart->num_streams = FIELD_GET(DART_T8110_PARAMS4_NUM_SIDS, + dart_params[3]); + dart->four_level = dart->ias > 36; + dart->version = dart_params[2] & GENMASK(15, 0); + break; + } +} + +/* + * Gen3 static topology, no MMIO. ADT: page-size 16384 (m1n1 also expects page shift 14 + * and version 0x300), sid-count 16 for the USB DARTs (optional apple,num-streams). The + * address widths are placeholders wide enough for probe-time window checks; the + * first resume re-reads the real PARAMS and re-validates. + */ +static void apple_dart_set_static_params(struct apple_dart *dart) +{ + u32 n = 16; + + of_property_read_u32(dart->dev->of_node, "apple,num-streams", &n); + dart->pgsize = SZ_16K; + dart->supports_bypass = false; + dart->ias = 42; + dart->oas = 42; + dart->num_streams = n; + dart->four_level = true; + dart->version = 0x0300; +} + +/* + * First use of a static-topology Gen3 DART: everything probe skipped, in the safe order. + * Runs from the runtime-resume callback, which is irq-safe here: no sleeping calls. The + * fault IRQ is requested at probe (no MMIO) and ignored until hw_ready. + */ +static int apple_dart_gen3_late_init(struct apple_dart *dart) +{ + struct device *dev = dart->dev; + int ret; + u32 pgsize; + + pgsize = dart->pgsize; + apple_dart_read_params(dart); + if (dart->pgsize != pgsize) + return dev_err_probe(dev, -EINVAL, "page size %#x differs from the assumed %#x\n", + dart->pgsize, pgsize); + if (dart->num_streams > DART_MAX_STREAMS) + return dev_err_probe(dev, -EINVAL, "too many streams (%d)\n", dart->num_streams); + if (of_property_present(dev->of_node, "apple,dma-range")) { + if ((dart->dma_min ^ dart->dma_max) & ~DMA_BIT_MASK(dart->ias)) + return dev_err_probe(dev, -EINVAL, "DMA range does not fit ias=%d\n", dart->ias); + } else { + dart->dma_max = DMA_BIT_MASK(dart->ias); + } + + /* Read the lock before any write. A locked root needs the locked-TTBR path. */ + if (apple_dart_is_locked(dart)) + return dev_err_probe(dev, -EOPNOTSUPP, + "locked Gen3 DART is not supported in static-topology mode\n"); + + apple_dart_apply_tunables(dart); + + ret = apple_dart_hw_reset(dart); + if (ret) + return ret; + dart->hw_ready = true; + dev_info(dev, "Gen3 DART initialised on first use: pagesize %#x, %d streams, AS %d -> %d\n", + dart->pgsize, dart->num_streams, dart->ias, dart->oas); + return 0; +} + +/* + * Run the first-use init exactly once from whichever path gets there first: runtime + * resume, a consumer attach, or a fault IRQ on a powered but never initialised DART. + * The caller guarantees the DART is powered. Safe in atomic context. + */ +static int apple_dart_gen3_ensure_ready(struct apple_dart *dart) +{ + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&dart->late_lock, flags); + if (!dart->hw_ready) + ret = apple_dart_gen3_late_init(dart); + spin_unlock_irqrestore(&dart->late_lock, flags); + return ret; +} + +/* Every DART in a consumer's iommus list must be initialised before it is programmed. */ +static int apple_dart_cfg_ensure_ready(struct apple_dart_master_cfg *cfg) +{ + struct apple_dart_stream_map *stream_map; + int i, ret; + + for_each_stream_map(i, cfg, stream_map) { + struct apple_dart *dart = stream_map->dart; + + if (!dart->static_topo || dart->hw_ready) + continue; + dev_warn(dart->dev, + "first-use init was not run by runtime resume (rpm status %d); initialising from attach\n", + dart->dev->power.runtime_status); + ret = apple_dart_gen3_ensure_ready(dart); + if (ret) + return ret; + } + return 0; +} + +static int apple_dart_probe(struct platform_device *pdev) +{ + int ret; + u32 sid; struct device_node *pd_np; struct resource *res; struct apple_dart *dart; @@ -2869,6 +3117,8 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); + dart->static_topo = dart->hw->gen3 && + of_property_read_bool(dev->of_node, "apple,static-topology"); dart->tunneled = tunneled; dart->per_stream = of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart"); @@ -2881,6 +3131,7 @@ static int apple_dart_probe(struct platform_device *pdev) } } spin_lock_init(&dart->lock); + spin_lock_init(&dart->late_lock); platform_set_drvdata(pdev, dart); /* @@ -2905,7 +3156,7 @@ static int apple_dart_probe(struct platform_device *pdev) dev_err(dev, "MMIO region too small (%pr)\n", res); return -EINVAL; } - if (tunneled) { + if (tunneled || dart->hw == &apple_dart_hw_t8152) { dart->tunables = devm_apple_tunable_parse(dev, dev->of_node, "apple,tunable", res); if (IS_ERR(dart->tunables)) { @@ -2921,10 +3172,26 @@ static int apple_dart_probe(struct platform_device *pdev) dart->tunables = NULL; } else { return dev_err_probe(dev, PTR_ERR(dart->tunables), - "failed to parse PCIe-C DART tunables\n"); + "failed to parse DART tunables\n"); } } } + if (dart->hw == &apple_dart_hw_t8152) { + /* TLBI doorbell: reg[1], shared by every Gen3 DART (no mem region claim) */ + struct resource *tr = platform_get_resource(pdev, IORESOURCE_MEM, 1); + + if (!tr || resource_size(tr) < 16) + return dev_err_probe(dev, -EINVAL, "Gen3 DART needs a 16-byte TLBI reg[1]\n"); + /* + * The doorbell uses the normal Device mapping, like the registers of the + * on-SoC DARTs; only the tunneled DARTs need ioremap_np(). Each doorbell + * store is followed by dsb ish, the TLBI and dsb osh (see the invalidate + * function), the vendor sequence. + */ + dart->tlbi = devm_ioremap(dev, tr->start, resource_size(tr)); + if (!dart->tlbi) + return -ENOMEM; + } dart->irq = platform_get_irq(pdev, 0); if (dart->irq < 0) @@ -2950,6 +3217,16 @@ static int apple_dart_probe(struct platform_device *pdev) dev_dbg(dev, "applying %zu PCIe-C DART tunables\n", dart->tunables->sz); apple_dart_apply_tunables(dart); + } else if (dart->hw == &apple_dart_hw_t8152 && !dart->static_topo) { + /* + * Firmware (SPTM) owns a locked Gen3 DART: its protection and tunables are + * already set and the 0x20c group sits in the write-protect block, so decide + * lock state with a read before any write. + */ + if (apple_dart_is_locked(dart)) + dev_info(dev, "Gen3 DART is locked: not applying tunables\n"); + else + apple_dart_apply_tunables(dart); } if (tunneled) { @@ -2983,30 +3260,10 @@ static int apple_dart_probe(struct platform_device *pdev) goto params_done; } - dart_params[0] = apple_dart_readl(dart, DART_PARAMS1); - dart_params[1] = apple_dart_readl(dart, DART_PARAMS2); - dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]); - dart->supports_bypass = dart_params[1] & DART_PARAMS2_BYPASS_SUPPORT; - - switch (dart->hw->type) { - case DART_T8020: - case DART_T6000: - dart->ias = 32; - dart->oas = dart->hw->oas; - dart->num_streams = dart->hw->max_sid_count; - break; - - case DART_T8110: - dart_params[2] = apple_dart_readl(dart, DART_T8110_PARAMS3); - dart->ias = FIELD_GET(DART_T8110_PARAMS3_VA_WIDTH, dart_params[2]); - dart->oas = FIELD_GET(DART_T8110_PARAMS3_PA_WIDTH, dart_params[2]); - dart_params[3] = apple_dart_readl(dart, DART_T8110_PARAMS4); - dart->num_streams = FIELD_GET(DART_T8110_PARAMS4_NUM_SIDS, - dart_params[3]); - dart->four_level = dart->ias > 36; - dart->version = dart_params[2] & GENMASK(15, 0); - break; - } + if (dart->static_topo) + apple_dart_set_static_params(dart); + else + apple_dart_read_params(dart); params_done: dart->dma_min = 0; @@ -3092,30 +3349,43 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) goto err_clk_disable; - /* A hot-plug PCIe-C DART has no retained/locked translation context. */ + /* + * A hot-plug PCIe-C DART has no retained/locked translation context. + * A DART the bootloader leaves locked is one that hardware we do not drive + * still translates through (on T8152 Gen3 a display pipe scans out through + * the boot stream the whole time Linux is booting). Letting runtime PM + * suspend it drops the TTBRs underneath that traffic, and the engine then + * faults "TTBR invalid" forever. Hold the reference for the DART's lifetime. + */ if (tunneled) dart->locked = false; else - dart->locked = apple_dart_is_locked(dart); + dart->locked = !dart->static_topo && apple_dart_is_locked(dart); + if (dart->hw->gen3 && dart->locked && !dart->force_available) { + dev_info(dev, "locked DART: holding it available for its lifetime\n"); + dart->force_available = 1; + } /* Reserved table-page lifetime requires the matched three-level loader. */ dart->fw_handoff = apple_dart_fw_handoff_enabled(dart); /* Preserve our retained-root path when no reserved-table handoff exists. */ dart->fw_mirror = dart->locked && !dart->fw_handoff && (of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart")); - if (!dart->locked) { + if (!dart->locked && !dart->static_topo) { ret = apple_dart_hw_reset(dart); if (ret) goto err_clk_disable; } + if (dart->static_topo) + dev_info(dev, "Gen3 DART static topology: no MMIO until first use\n"); if (dart->locked) apple_dart_drain_stale_exceptions(dart); - ret = request_irq(dart->irq, apple_dart_irq, IRQF_SHARED, "apple-dart fault handler", dart); if (ret) goto err_clk_disable; + dart->irq_requested = true; ret = iommu_device_sysfs_add(&dart->iommu, dev, NULL, "apple-dart.%s", dev_name(&pdev->dev)); @@ -3126,7 +3396,8 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) goto err_sysfs_remove; - pm_runtime_put(dev); + if (!dart->force_available) + pm_runtime_put(dev); dev_dbg( &pdev->dev, @@ -3138,7 +3409,8 @@ static int apple_dart_probe(struct platform_device *pdev) err_sysfs_remove: iommu_device_sysfs_remove(&dart->iommu); err_free_irq: - free_irq(dart->irq, dart); + if (dart->irq_requested) + free_irq(dart->irq, dart); err_clk_disable: pm_runtime_put(dev); clk_bulk_disable_unprepare(dart->num_clks, dart->clks); @@ -3253,13 +3525,17 @@ static void apple_dart_remove(struct platform_device *pdev) * A command issued then never completes. The next probe resets the * block after that clock is running again. */ - if (!dart->locked && !READ_ONCE(dart->commands_gated)) + if (!dart->locked && (!dart->static_topo || dart->hw_ready) && + !READ_ONCE(dart->commands_gated)) apple_dart_hw_reset(dart); - free_irq(dart->irq, dart); + if (dart->irq_requested) + free_irq(dart->irq, dart); iommu_device_unregister(&dart->iommu); iommu_device_sysfs_remove(&dart->iommu); + if (dart->force_available) + pm_runtime_put_noidle(dart->dev); clk_bulk_disable_unprepare(dart->num_clks, dart->clks); } @@ -3372,12 +3648,43 @@ static const struct apple_dart_hw apple_dart_hw_t8110 = { .ttbr_count = 1, }; +static const struct apple_dart_hw apple_dart_hw_t8152 = { + .type = DART_T8110, + .irq_handler = apple_dart_gen3_irq, + .invalidate_tlb = apple_dart_gen3_hw_invalidate_tlb, + .gen3 = true, + .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 __maybe_unused int apple_dart_suspend(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); unsigned int sid, idx; dart->tunnel_state_restored = false; + /* A static-topology DART untouched so far has no state and must not be read. */ + if (dart->static_topo && !dart->hw_ready) + return 0; + if (READ_ONCE(dart->commands_gated)) return 0; /* The tunneled DART has no state to save when its domain stays on. */ @@ -3466,6 +3773,10 @@ static __maybe_unused int apple_dart_resume(struct device *dev) unsigned int sid, idx; int ret; + /* First resume of a static-topology DART: do everything probe skipped. */ + if (dart->static_topo && !dart->hw_ready) + return apple_dart_gen3_ensure_ready(dart); + /* PCIe-C restored these mappings before starting its downstream link. */ if (dart->tunnel_state_restored) { dart->tunnel_state_restored = false; @@ -3532,6 +3843,7 @@ static const struct of_device_id apple_dart_of_match[] = { { .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 }, + { .compatible = "apple,t8152-dart", .data = &apple_dart_hw_t8152 }, { .compatible = "apple,t6000-dart", .data = &apple_dart_hw_t6000 }, {}, }; From 48cbf4a36a6fb0f2c0caff884e0cc860ab24d893 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 08:05:55 -0500 Subject: [PATCH 09/32] usb: dwc3: apple: Add the T8152 fixed-role USB2 controller Add the apple,t8152-dwc3 compatible to the Apple dwc3 glue. The ATC ports of the M6 (T8152) controller never switch roles through the Type-C controller. The glue starts the controller as a fixed host, with or without a hub child, or as a fixed peripheral when the node sets dr_mode = "peripheral". The T8152 profile is USB2 only: it needs maximum-speed = "high-speed", takes no reset line, and its USB3 PHY is optional. The calibration lists come from the device tree (apple,tunable-* properties that the boot loader fills in at runtime; the binding does not require them in the board file) and are applied to the register windows in a fixed order after the core is reset. The pipe handler is set up for the selected role. The apple,t8103-dwc3 paths keep their behaviour. The controller stays a syscore device while it runs, as before: no separate suspend or resume path is added for T8152. The earlier form of this change ran on an M6 Mac mini USB2 front port. This version is rebased on current integration/aurora and was compile-checked only. SuperSpeed does not train yet and is not part of this change. A fixed peripheral does not require the host-only calibration lists at probe, since it never applies them. The binding lists exactly four iommus entries, two stream IDs on each of two DARTs. If the T8152 USB2 PHY fails to initialise or power on during core start, the failure goes through the same shutdown as a failed core init, so the reset and syscore flags set earlier are cleared again. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/usb/apple,t8152-dwc3.yaml | 99 +++++++ drivers/usb/dwc3/Kconfig | 1 + drivers/usb/dwc3/dwc3-apple.c | 242 +++++++++++++++++- 3 files changed, 331 insertions(+), 11 deletions(-) create mode 100644 Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml diff --git a/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml new file mode 100644 index 00000000000000..38c1015446c9cd --- /dev/null +++ b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml @@ -0,0 +1,99 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/apple,t8152-dwc3.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 USB2-only controller + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +description: | + This USB2-only profile starts a fixed role at probe, with or without a + physical hub child node: host mode, or — for a debug-cable port — fixed + peripheral (gadget) mode selected with dr_mode. The controller never + switches roles at runtime. + The dr_mode and maximum-speed properties must select host or peripheral and + high-speed. + Firmware supplies device-specific calibration records as offset, clear-mask, + set-value triples. Offsets are relative to each native register bank, not + the combined Linux window. The core window ends at 0xcd00. The Apple window + starts at 0xcd00 and covers the debug, configuration, and link banks through + 0x11800. These windows must not overlap. + +allOf: + - $ref: snps,dwc3-common.yaml# + +properties: + compatible: + const: apple,t8152-dwc3 + + reg: + items: + - description: DWC3 core, offsets 0 through 0xccff + - description: Apple registers, offsets 0xcd00 through 0x117ff + - description: PIPE handler (native register bank 3) + - description: Power control (native register bank 5) + - description: Bulk fabric (native register bank 6) + - description: AUSBC debug (native register bank 8) + + reg-names: + items: + - const: dwc3-core + - const: dwc3-apple + - const: pipe-handler + - const: pwr-ctrl + - const: bulk-fabric + - const: ausbc-debug + + interrupts: + maxItems: 1 + + iommus: + minItems: 4 + maxItems: 4 + + power-domains: + maxItems: 1 + + phys: + maxItems: 1 + + phy-names: + items: + - const: usb2-phy + + dr_mode: + enum: [ host, peripheral ] + + maximum-speed: + const: high-speed + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + +patternProperties: + '^hub@[1-9a-f][0-9a-f]?$': + $ref: /schemas/usb/usb-device.yaml# + '^apple,tunable-(bulk-fabric-default|pipe-handler-default|pipe-handler-host|pwr-ctrl-default|drd-usb31-gbl-default|drd-usb31-gbl-host|drd-cio-regs-default|drd-usb31-dbg-default|drd-usb31-cfg-host|link-regs-default|ausbc-debug-default)$': + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Native bank-relative offset, clear-mask, set-value triples. + +required: + - compatible + - reg + - reg-names + - interrupts + - iommus + - power-domains + - phys + - phy-names + - dr_mode + - maximum-speed + +unevaluatedProperties: false diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index c862e55ae3a373..4f5be5ecee5626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -227,6 +227,7 @@ config USB_DWC3_APPLE depends on OF && ARCH_APPLE default USB_DWC3 select USB_ROLE_SWITCH + select APPLE_TUNABLE help Support Apple Silicon SoCs with DesignWare Core USB3 IP. The DesignWare Core USB3 IP has to be used in dual-role diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 464e5d9e691fe3..55e9a49a4e23d7 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -13,12 +13,15 @@ #include #include #include +#include #include #include +#include #include #include "dwc3-apple-state.h" #include "glue.h" +#include "io.h" /* * This platform requires a very specific sequence of operations to bring up dwc3 and its USB3 PHY: @@ -86,6 +89,13 @@ * dwc3_apple_init(). In host mode xHCI then keeps running in suspend-to-idle when a USB device * may wake the system, as a halted xHC could not signal the wakeup. * + * The T8152 USB2-only profile starts a fixed host, without a physical hub, or — + * with dr_mode = "peripheral" on the debug-cable port — a fixed peripheral. A + * fixed peripheral programs the pipe handler with the m1n1 device-console + * sequence (mux to the dummy backend, DWC3 reset released, device non-selected + * override word) and applies only the default calibration lists plus the USB2 + * PHY device calibration; the host lists stay unused. + * * enum dwc3_apple_state is defined in dwc3-apple-state.h. */ @@ -100,7 +110,11 @@ * sets host mode * @usb3_phy: USB3 PHY, configured after the core is brought up * @role_sw: USB role switch - * @fixed_hub: A fixed hub sits on the controller's USB2 port, the controller stays in host mode + * @fixed_hub: A physical hub child node sits on the controller's USB2 port + * @t8152_usb2: T8152 fixed-role calibration and USB2-only PHY profile + * @fixed_peripheral: T8152 started as a fixed peripheral (dr_mode = "peripheral") + * @tunable_regs: Non-overlapping calibration windows, with the core mapped by dwc3 + * @tunables: Native host calibration lists in application order * @lock: Mutex for synchronizing access * @state: Current state of the controller, see enum dwc3_apple_state and the comment above * @core_active: Core still owns initialized PHYs @@ -121,6 +135,10 @@ struct dwc3_apple { struct phy *usb3_phy; struct usb_role_switch *role_sw; bool fixed_hub; + bool t8152_usb2; + bool fixed_peripheral; + void __iomem *tunable_regs[6]; + struct apple_tunable *tunables[11]; struct mutex lock; @@ -193,6 +211,120 @@ static void dwc3_apple_setup_cio(struct dwc3_apple *appledwc) APPLE_DWC3_CIO_PM_ENTRY_TIMER_VALUE)); } +static const struct { + const char *name; + u8 resource; + u32 offset; + bool optional; + bool host_only; +} t8152_host_tunables[] = { + { "apple,tunable-bulk-fabric-default", 4, 0 }, + { "apple,tunable-pipe-handler-default", 2, 0 }, + { "apple,tunable-pipe-handler-host", 2, 0, true, true }, + { "apple,tunable-pwr-ctrl-default", 3, 0, true }, + { "apple,tunable-drd-usb31-gbl-default", 0, 0xc100 }, + { "apple,tunable-drd-usb31-gbl-host", 0, 0xc100, false, true }, + { "apple,tunable-drd-cio-regs-default", 1, 0x20, true }, + { "apple,tunable-drd-usb31-dbg-default", 1, 0xb00 }, + { "apple,tunable-drd-usb31-cfg-host", 1, 0x3300, false, true }, + { "apple,tunable-link-regs-default", 1, 0x300 }, + { "apple,tunable-ausbc-debug-default", 5, 0 }, +}; + +static int dwc3_apple_t8152_parse_tunables(struct platform_device *pdev, + struct dwc3_apple *appledwc) +{ + static const char * const names[] = { + "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug", + }; + struct device *dev = &pdev->dev; + struct resource *resources[ARRAY_SIZE(names)]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(names); i++) { + resources[i] = platform_get_resource_byname(pdev, IORESOURCE_MEM, names[i]); + if (!resources[i]) + return dev_err_probe(dev, -EINVAL, "Missing %s MMIO\n", names[i]); + if (i < 2) + continue; + appledwc->tunable_regs[i] = devm_ioremap_resource(dev, resources[i]); + if (IS_ERR(appledwc->tunable_regs[i])) + return PTR_ERR(appledwc->tunable_regs[i]); + } + if (resource_size(resources[0]) != 0xcd00 || + resource_size(resources[1]) < 0x4b00 || + resources[1]->start != resources[0]->start + 0xcd00 || + resource_size(resources[2]) < 0x24) + return dev_err_probe(dev, -EINVAL, "Invalid T8152 register windows\n"); + appledwc->tunable_regs[1] = appledwc->apple_regs; + + for (i = 0; i < ARRAY_SIZE(t8152_host_tunables); i++) { + struct resource window = *resources[t8152_host_tunables[i].resource]; + struct apple_tunable *tunable; + + /* A fixed peripheral never applies the host-only lists, so they may be absent. */ + if (appledwc->fixed_peripheral && t8152_host_tunables[i].host_only) + continue; + if (resource_size(&window) <= t8152_host_tunables[i].offset) + return -EINVAL; + window.start += t8152_host_tunables[i].offset; + tunable = devm_apple_tunable_parse(dev, dev->of_node, + t8152_host_tunables[i].name, &window); + if (IS_ERR(tunable)) { + if (PTR_ERR(tunable) == -ENOENT && t8152_host_tunables[i].optional) + continue; + return dev_err_probe(dev, PTR_ERR(tunable), "Invalid %s\n", + t8152_host_tunables[i].name); + } + appledwc->tunables[i] = tunable; + } + return 0; +} + +/* + * T8152 pipe handler registers programmed by m1n1 src/usb.c usb_phy_bringup() + * for the USB2 device console: route the mux to the dummy backend, release the + * DWC3 reset, and write the whole non-selected override word. + */ +#define T8152_PIPE_MUX_CTRL 0x0c +#define T8152_PIPE_AON_GEN 0x1c +#define T8152_PIPE_NONSELECTED_OVERRIDE 0x20 +#define T8152_PIPE_MUX_CTRL_DUMMY 0x22 +#define T8152_PIPE_AON_GEN_DWC3_RESET_N BIT(0) +#define T8152_PIPE_NONSELECTED_DEVICE 0x9332 + +static void dwc3_apple_t8152_apply_tunables(struct dwc3_apple *appledwc, + enum dwc3_apple_state state) +{ + bool device = state == DWC3_APPLE_DEVICE; + void __iomem *pipe = appledwc->tunable_regs[2]; + unsigned int i; + u32 value; + + for (i = 0; i < ARRAY_SIZE(t8152_host_tunables); i++) { + u8 resource = t8152_host_tunables[i].resource; + u32 offset = t8152_host_tunables[i].offset; + void __iomem *base = resource ? appledwc->tunable_regs[resource] : + appledwc->dwc.regs; + + if (device && t8152_host_tunables[i].host_only) + continue; + if (!resource) + offset -= DWC3_GLOBALS_REGS_START; + apple_tunable_apply(base + offset, appledwc->tunables[i]); + } + + if (device) + return; + + writel(readl(pipe + 0x20) | BIT(15), pipe + 0x20); + value = dwc3_readl(&appledwc->dwc, 0xc680); + dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); + value = dwc3_readl(&appledwc->dwc, 0xc680); + dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); +} + static void dwc3_apple_set_ptrcap(struct dwc3_apple *appledwc, u32 mode) { guard(spinlock_irqsave)(&appledwc->dwc.lock); @@ -374,7 +506,40 @@ static int dwc3_apple_core_start(struct dwc3_apple *appledwc, enum dwc3_apple_st appledwc->reset_pending = true; /* Keep register access powered until both PHY shutdown and reset finish. */ dev_pm_syscore_device(appledwc->dev, true); + + if (appledwc->t8152_usb2) { + void __iomem *pipe = appledwc->tunable_regs[2]; + + if (state == DWC3_APPLE_DEVICE) { + writel(T8152_PIPE_MUX_CTRL_DUMMY, pipe + T8152_PIPE_MUX_CTRL); + writel(T8152_PIPE_NONSELECTED_DEVICE, pipe + T8152_PIPE_NONSELECTED_OVERRIDE); + } + /* + * The AON block gates every DWC3 core register with its reset. + * dwc3_core_probe() reads GSNPSID/GHWPARAMS first, so the reset + * must be released here for the host role too, not only for the + * peripheral (verified on port 1; port 2 returned garbage on the + * first hardware run without this). + */ + writel(T8152_PIPE_AON_GEN_DWC3_RESET_N, pipe + T8152_PIPE_AON_GEN); + } + + if (appledwc->t8152_usb2) { + ret = phy_init(appledwc->usb2_phy); + if (ret) + goto err_stop; + ret = phy_power_on(appledwc->usb2_phy); + if (ret) { + phy_exit(appledwc->usb2_phy); + goto err_stop; + } + } + ret = dwc3_apple_core_init(appledwc); + if (appledwc->t8152_usb2) { + phy_power_off(appledwc->usb2_phy); + phy_exit(appledwc->usb2_phy); + } if (ret) { ret_reset = dwc3_apple_core_stop(appledwc); if (ret_reset) @@ -392,6 +557,12 @@ static int dwc3_apple_core_start(struct dwc3_apple *appledwc, enum dwc3_apple_st appledwc->usb3_power_off_pending = BIT(appledwc->dwc.num_usb3_ports) - 1; return 0; + +err_stop: + ret_reset = dwc3_apple_core_stop(appledwc); + if (ret_reset) + dev_warn(appledwc->dev, "Failed to finish core shutdown, err=%d\n", ret_reset); + return ret; } /* Select the role in the core and route the USB3 PHY, before xhci or the gadget is started */ @@ -414,6 +585,27 @@ static void dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_sta ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); if (ret) dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); + if (appledwc->t8152_usb2) + dwc3_apple_t8152_apply_tunables(appledwc, state); +} + +/* + * A T8152 controller never switches roles: it starts as a fixed host (with or + * without a hub child) or — with dr_mode = "peripheral" — as a fixed + * peripheral. Returns false for the dynamic-role profiles. + */ +static bool dwc3_apple_fixed_state(const struct dwc3_apple *appledwc, + enum dwc3_apple_state *state) +{ + if (appledwc->fixed_peripheral) { + *state = DWC3_APPLE_DEVICE; + return true; + } + if (appledwc->fixed_hub || appledwc->t8152_usb2) { + *state = DWC3_APPLE_HOST; + return true; + } + return false; } static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state state) @@ -505,6 +697,16 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role ro if (appledwc->fixed_hub) return 0; + if (appledwc->t8152_usb2) { + enum usb_role fixed_role = appledwc->fixed_peripheral ? + USB_ROLE_DEVICE : USB_ROLE_HOST; + if (role != fixed_role) { + dev_err(appledwc->dev, "Invalid target role: %d\n", role); + return -EINVAL; + } + return 0; + } + /* * Skip role switches if appledwc is already in the desired state. The * USB-C port controller on M2 and M1/M2 Pro/Max/Ultra devices issues @@ -590,6 +792,7 @@ static bool dwc3_apple_has_fixed_hub(struct device *dev) static int dwc3_apple_probe(struct platform_device *pdev) { + enum dwc3_apple_state fixed_state; struct device *dev = &pdev->dev; struct dwc3_apple *appledwc; int ret; @@ -599,10 +802,24 @@ static int dwc3_apple_probe(struct platform_device *pdev) return -ENOMEM; appledwc->dev = &pdev->dev; + appledwc->t8152_usb2 = of_device_is_compatible(dev->of_node, "apple,t8152-dwc3"); appledwc->fixed_hub = dwc3_apple_has_fixed_hub(dev); + if (appledwc->t8152_usb2) { + enum usb_dr_mode dr_mode = usb_get_dr_mode(dev); + + if ((dr_mode != USB_DR_MODE_HOST && dr_mode != USB_DR_MODE_PERIPHERAL) || + usb_get_maximum_speed(dev) != USB_SPEED_HIGH) + return dev_err_probe(dev, -EINVAL, + "T8152 requires dr_mode = \"host\" or \"peripheral\" and maximum-speed = \"high-speed\"\n"); + appledwc->fixed_peripheral = dr_mode == USB_DR_MODE_PERIPHERAL; + if (appledwc->fixed_peripheral && appledwc->fixed_hub) + return dev_err_probe(dev, -EINVAL, + "A hub child node requires dr_mode = \"host\"\n"); + } mutex_init(&appledwc->lock); - appledwc->reset = devm_reset_control_get_exclusive(dev, NULL); + if (!appledwc->t8152_usb2) + appledwc->reset = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(appledwc->reset)) return dev_err_probe(&pdev->dev, PTR_ERR(appledwc->reset), "Failed to get reset control\n"); @@ -612,7 +829,8 @@ static int dwc3_apple_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(appledwc->usb2_phy), "Failed to get the USB2 PHY\n"); - appledwc->usb3_phy = devm_phy_get(dev, "usb3-phy"); + if (!appledwc->t8152_usb2) + appledwc->usb3_phy = devm_phy_get(dev, "usb3-phy"); if (IS_ERR(appledwc->usb3_phy)) return dev_err_probe(dev, PTR_ERR(appledwc->usb3_phy), "Failed to get the USB3 PHY\n"); @@ -633,6 +851,11 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (IS_ERR(appledwc->apple_regs)) return dev_err_probe(dev, PTR_ERR(appledwc->apple_regs), "Failed to map Apple-specific MMIO\n"); + if (appledwc->t8152_usb2) { + ret = dwc3_apple_t8152_parse_tunables(pdev, appledwc); + if (ret) + return ret; + } /* * Like a PCI xHCI controller, allow USB devices to wake the system by default. This has @@ -654,16 +877,11 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "Failed to setup role switch\n"); - if (!appledwc->fixed_hub) + if (!dwc3_apple_fixed_state(appledwc, &fixed_state)) return 0; - /* - * The hub is the controller's permanent USB2 peer, and the PHY has kept - * its USB2 path up for it since its own probe, so there is nothing to - * wait for: bring the host up now. - */ scoped_guard(mutex, &appledwc->lock) - ret = dwc3_apple_init(appledwc, DWC3_APPLE_HOST); + ret = dwc3_apple_init(appledwc, fixed_state); if (ret) { /* A failed cleanup remains visible even when probe cannot be retried. */ if (appledwc->core_active || appledwc->reset_pending) @@ -671,7 +889,8 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (appledwc->state != DWC3_APPLE_PROBE_PENDING) dwc3_core_remove_no_shutdown(&appledwc->dwc); usb_role_switch_unregister(appledwc->role_sw); - return dev_err_probe(dev, ret, "Failed to start host mode\n"); + return dev_err_probe(dev, ret, "Failed to start fixed %s mode\n", + fixed_state == DWC3_APPLE_DEVICE ? "peripheral" : "host"); } return 0; @@ -699,6 +918,7 @@ static void dwc3_apple_remove(struct platform_device *pdev) static const struct of_device_id dwc3_apple_of_match[] = { { .compatible = "apple,t8103-dwc3" }, + { .compatible = "apple,t8152-dwc3" }, {} }; MODULE_DEVICE_TABLE(of, dwc3_apple_of_match); From 9fbb35688e4c737bf1818d5cd6f9890292e06c5b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 08:09:02 -0500 Subject: [PATCH 10/32] arm64: dts: apple: t8152-j873g: Add the PMGR domains and the USB nodes Describe the power management blocks and the USB controllers of the Mac mini (M6, J873) next to the peripherals fragment: - the two PMGR blocks and their power domains, in t8152-j873-pmgr.dtsi; - for each of the four USB ports (usb0, usb1, usb2 and usb3 of the SoC): two DART instances, the USB2 PHY and the dwc3 controller. The register windows, interrupts and DART tunables are the values of the Apple device tree of the machine. The boot loader adds the apple,tunable-* lists of the USB2 PHY and the controller at runtime. The bindings list the apple,t8152-pmgr and apple,t8152-pmgr-pwrstate compatibles, and the dwc3 and USB2 PHY bindings take the tunable lists as optional, because the boot loader adds them. The fragment is a plain description of the hardware. The ports that the change describes run USB2 only: SuperSpeed and USB4 are not part of it. This commit compiles to a device tree blob with dtc without warnings. It was not booted. The bring-up it comes from enumerated the front-port USB2 hub and a USB disk at 480 Mb/s. The four PSD service slots get their PMGR domains (the aon and the port domain of their port) as parents, so genpd powers them before the slot request. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/arm/apple/apple,pmgr.yaml | 1 + .../bindings/power/apple,pmgr-pwrstate.yaml | 1 + .../arm64/boot/dts/apple/t8152-j873-drd1.dtsi | 87 ++++ .../arm64/boot/dts/apple/t8152-j873-drd2.dtsi | 73 ++++ .../arm64/boot/dts/apple/t8152-j873-pmgr.dtsi | 374 ++++++++++++++++++ .../boot/dts/apple/t8152-j873-usb0-dart.dtsi | 52 +++ .../arm64/boot/dts/apple/t8152-j873-usb0.dtsi | 42 ++ .../boot/dts/apple/t8152-j873-usb2-dart.dtsi | 50 +++ .../arm64/boot/dts/apple/t8152-j873-usb2.dtsi | 38 ++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 7 + 10 files changed, 725 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index c5fce7d78bfc62..253c1b78f235d0 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -44,6 +44,7 @@ properties: - apple,t8132-pmgr - apple,t8140-pmgr - apple,t8142-pmgr + - apple,t8152-pmgr - const: apple,t8103-pmgr - const: syscon - const: simple-mfd diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index 7800f0f106f2cd..1479bfea38c3bb 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -51,6 +51,7 @@ properties: - apple,t8132-pmgr-pwrstate - apple,t8140-pmgr-pwrstate - apple,t8142-pmgr-pwrstate + - apple,t8152-pmgr-pwrstate - const: apple,t8103-pmgr-pwrstate reg: diff --git a/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi new file mode 100644 index 00000000000000..6ba88f24035d4b --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * usb-drd1 (ATC1, rear BACK-LEFT port, port-number 2, HPM hpm1 at SPMI 0xa) as a fixed USB2 host. + * Addresses, IRQs and TLBI aperture from the saved M6 ADT: usb-drd1 core 0x40a430000, atc-phy1 0x40a418000 / + * 0x40a448000, dart-usb1 0x40b020000 / 0x40b040000 (sid-count 16, tlbi-aperture-offset 384 = 0x180, irq 1679), + * drd irq 1692. Same node layout as the drd3/drd2 hosts (both DARTs, SIDs 0 and 1). + * + * The m1n1 loader must export the port-1 USB2 PHY and DRD tunables (aliases usb2phy1 / usbdrd1), otherwise the + * PHY fails probe with -ENOENT "Invalid default tunables", exactly as drd2 did before its exporter line. + */ +/ { + aliases { + usb2phy1 = &usb2phy1; + usbdrd1 = &usbdrd1; + }; + + soc { + usb1_dart0: iommu@40b020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x0b020000 0x0 0xc000>, + <0x2 0x00000180 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc1_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb1_dart1: iommu@40b040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>, + <0x2 0x00000180 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc1_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2phy1: phy@40a418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <0x4 0x0a418000 0x0 0x4000>, + <0x4 0x0a448000 0x0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc1_usb_aon>, <&psd_atc1_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd1: usb@40a430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>, + <0x4 0x0a43cd00 0x0 0x4b00>, + <0x4 0x0a414000 0x0 0x4000>, + <0x4 0x0a410000 0x0 0x4000>, + <0x4 0x0a444000 0x0 0x4000>, + <0x4 0x0a450000 0x0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb1_dart0 0>, <&usb1_dart0 1>, <&usb1_dart1 0>, <&usb1_dart1 1>; + power-domains = <&psd_atc1_usb>; + phys = <&usb2phy1>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi new file mode 100644 index 00000000000000..9b107ceea8f1b7 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/ { + aliases { + usb2phy2 = &usb2phy2; + usbdrd2 = &usbdrd2; + }; + + soc { + usb2_dart0: iommu@383020000 { + compatible = "apple,t8152-dart"; + reg = <3 0x83020000 0 0xc000>, <2 0x200 0 0x10>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&psd_atc2_usb>; + apple,static-topology; + apple,num-streams = <16>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2_dart1: iommu@383040000 { + compatible = "apple,t8152-dart"; + reg = <3 0x83040000 0 0xc000>, <2 0x200 0 0x10>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&psd_atc2_usb>; + apple,static-topology; + apple,num-streams = <16>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2phy2: phy@382418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <3 0x82418000 0 0x4000>, <3 0x82448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc2_usb_aon>, <&psd_atc2_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd2: usb@382430000 { + compatible = "apple,t8152-dwc3"; + reg = <3 0x82430000 0 0xcd00>, + <3 0x8243cd00 0 0x4b00>, + <3 0x82414000 0 0x4000>, + <3 0x82410000 0 0x4000>, + <3 0x82444000 0 0x4000>, + <3 0x82450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb2_dart0 0>, <&usb2_dart0 1>, <&usb2_dart1 0>, <&usb2_dart1 1>; + power-domains = <&psd_atc2_usb>; + phys = <&usb2phy2>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi new file mode 100644 index 00000000000000..95c91876fc25b0 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi @@ -0,0 +1,374 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * PMGR power domains for the Apple T8152 (M6), generated from the device tree of the boot firmware + * (/arm-io/pmgr-child). Real (non-virtual) devices only; + * virtual ADT devices have no PS register of their own (ANS, DPTX_PHY, ATC*_CIO_USB, ...) + * and are managed by firmware. Every domain is apple,always-on: Linux only keeps them ACTIVE. + */ + +/ { + soc { + pmgr0: power-management@300700000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x700000 0 0xd0000>; + }; + pmgr1: power-management@308280000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x8280000 0 0x80000>; + }; + }; +}; + +&pmgr0 { + 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,always-on; + }; + + ps_msg: power-controller@b40 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "msg"; + apple,always-on; + }; + + ps_gpio: power-controller@b60 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpio"; + apple,always-on; + }; + + ps_postoffice: power-controller@be0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xbe0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "postoffice"; + apple,always-on; + }; + + ps_fpwm0: power-controller@c40 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fpwm0"; + apple,always-on; + }; + + ps_apcie_st0: power-controller@ea0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xea0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0"; + 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,always-on; + }; + + ps_apcie_sys_st0: power-controller@1280 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1280 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_st0"; + power-domains = <&ps_apcie_st0>; + apple,always-on; + }; + + ps_apcie_sysocla: power-controller@12a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x12a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sysocla"; + power-domains = <&ps_apcie_sys_gp>; + apple,always-on; + }; + + ps_apcie_phy_sw: power-controller@15a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x15a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_phy_sw"; + power-domains = <&ps_apcie_sys_st0>, <&ps_apcie_sys_gp>; + apple,always-on; + }; + + ps_apcie_st0_ocla: power-controller@15c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x15c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0_ocla"; + power-domains = <&ps_apcie_sys_st0>; + apple,always-on; + }; + + ps_apcie_aon_aus5: power-controller@1620 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1620 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_aon_aus5"; + power-domains = <&ps_apcie_phy_sw>; + apple,always-on; + }; + + ps_apcie_aon_gp: power-controller@1640 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1640 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_aon_gp"; + power-domains = <&ps_apcie_phy_sw>; + apple,always-on; + }; + + ps_apcie_st0_aus5: power-controller@1660 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1660 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0_aus5"; + power-domains = <&ps_apcie_aon_aus5>; + apple,always-on; + }; + + ps_apcie_gp_aus5: power-controller@1680 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1680 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp_aus5"; + power-domains = <&ps_apcie_aon_gp>; + apple,always-on; + }; + +}; + +&pmgr1 { + ps_nub_spmi0: power-controller@180 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi0"; + apple,always-on; + }; + + ps_nub_spmi1: power-controller@1a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi1"; + apple,always-on; + }; + + ps_nub_spmi_a0: power-controller@1c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_a0"; + apple,always-on; + }; + + ps_nub_spmi_a1: power-controller@1e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_a1"; + apple,always-on; + }; + + ps_atc0_common_dp_0: power-controller@10000 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10000 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_0"; + apple,always-on; + }; + + ps_atc0_common_dp_1: power-controller@10020 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10020 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_1"; + apple,always-on; + }; + + ps_atc1_common_dp_0: power-controller@10040 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10040 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_0"; + apple,always-on; + }; + + ps_atc1_common_dp_1: power-controller@10060 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10060 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_1"; + apple,always-on; + }; + + ps_atc2_common_dp_0: power-controller@10080 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10080 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_0"; + apple,always-on; + }; + + ps_atc2_common_dp_1: power-controller@100a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_1"; + apple,always-on; + }; + + ps_atc3_common_dp_0: power-controller@100c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_0"; + apple,always-on; + }; + + ps_atc3_common_dp_1: power-controller@100e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_1"; + apple,always-on; + }; + + ps_atc0_usb_aon: power-controller@10100 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb_aon"; + apple,always-on; + }; + + ps_atc0_usb: power-controller@10120 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10120 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb"; + apple,always-on; + }; + + ps_atc1_usb_aon: power-controller@10140 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb_aon"; + apple,always-on; + }; + + ps_atc1_usb: power-controller@10160 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10160 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb"; + apple,always-on; + }; + + ps_atc2_usb_aon: power-controller@10180 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb_aon"; + apple,always-on; + }; + + ps_atc2_usb: power-controller@101a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb"; + apple,always-on; + }; + + ps_atc3_usb_aon: power-controller@101c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb_aon"; + apple,always-on; + }; + + ps_atc3_usb: power-controller@101e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb"; + apple,always-on; + }; + +}; + +/* + * The PSD service slots of the four USB ports sit on top of the PMGR domains of + * their port: genpd powers the parents first, then the slot request is made. + */ +&psd_atc0_usb { + power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_usb>; +}; + +&psd_atc1_usb { + power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_usb>; +}; + +&psd_atc2_usb { + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_usb>; +}; + +&psd_atc3_usb { + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_usb>; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi new file mode 100644 index 00000000000000..afd610963b005f --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd0: two DARTBLK instances, SID 1, shared TLBI aperture offset 0x100. + * Windows, IRQ, tunables and dma-range are from the M6 ADT; + * port 3 is the fixed-host reference. */ + +/ { + soc { + usb0_dart0: iommu@403020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x03020000 0x0 0xc000>, + <0x2 0x00000100 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc0_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value) */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb0_dart1: iommu@403040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x03040000 0x0 0xc000>, + <0x2 0x00000100 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc0_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-1: byte-identical to instance 0 */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi new file mode 100644 index 00000000000000..bebc9ce1c948d8 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd0 as a fixed high-speed peripheral: the debug cable port + * (receptacle 1, ATC0). Windows, IRQ and phy banks are from the M6 ADT; + * the layout mirrors the drd3 host node. */ + +/ { + aliases { + usb2phy0 = &usb2phy0; + usbdrd0 = &usbdrd0; + }; + + soc { + usb2phy0: phy@402418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <4 0x02418000 0 0x4000>, + <4 0x02448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc0_usb_aon>, <&psd_atc0_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd0: usb@402430000 { + compatible = "apple,t8152-dwc3"; + reg = <4 0x02430000 0 0xcd00>, + <4 0x0243cd00 0 0x4b00>, + <4 0x02414000 0 0x4000>, + <4 0x02410000 0 0x4000>, + <4 0x02444000 0 0x4000>, + <4 0x02450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb0_dart0 0>, <&usb0_dart0 1>, <&usb0_dart1 0>, <&usb0_dart1 1>; + power-domains = <&psd_atc0_usb>; + phys = <&usb2phy0>; + phy-names = "usb2-phy"; + dr_mode = "peripheral"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi new file mode 100644 index 00000000000000..46fa177b0acdab --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd3: two DARTBLK instances, SID 1, shared TLBI aperture offset 0x280. */ + +/ { + soc { + usb3_dart0: iommu@413020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x13020000 0x0 0xc000>, + <0x2 0x00000280 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc3_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value) */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb3_dart1: iommu@413040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x13040000 0x0 0xc000>, + <0x2 0x00000280 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc3_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-1: byte-identical to instance 0 */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi new file mode 100644 index 00000000000000..8241b19d03adf3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/ { + aliases { + usb2phy3 = &usb2phy3; + usbdrd3 = &usbdrd3; + }; + + soc { + usb2phy3: phy@412418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <4 0x12418000 0 0x4000>, + <4 0x12448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc3_usb_aon>, <&psd_atc3_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd3: usb@412430000 { + compatible = "apple,t8152-dwc3"; + reg = <4 0x12430000 0 0xcd00>, + <4 0x1243cd00 0 0x4b00>, + <4 0x12414000 0 0x4000>, + <4 0x12410000 0 0x4000>, + <4 0x12444000 0 0x4000>, + <4 0x12450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb3_dart0 0>, <&usb3_dart0 1>, <&usb3_dart1 0>, <&usb3_dart1 1>; + power-domains = <&psd_atc3_usb>; + phys = <&usb2phy3>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 05f723a7d36176..1515d472cd24ba 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -249,3 +249,10 @@ }; #include "t8152-j873g-peripherals.dtsi" +#include "t8152-j873-pmgr.dtsi" +#include "t8152-j873-usb2-dart.dtsi" +#include "t8152-j873-usb2.dtsi" +#include "t8152-j873-usb0-dart.dtsi" +#include "t8152-j873-usb0.dtsi" +#include "t8152-j873-drd2.dtsi" +#include "t8152-j873-drd1.dtsi" From 1045b8dba089db0ae097a70ae4d6cd0dfc5d3dbe Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:22:59 -0500 Subject: [PATCH 11/32] dma: apple-admac: add T8152 (admac-evolution) support The T8152 audio ADMAC is the same evolved family as the T8140 one: the vendor driver for it matches the evolved register map at every register we compared and never writes the global 0x28/0x2c pair, so the new variant sets evolved_layout and clears set_unk28. On an M6 Mac mini the base-ns ADMAC binds and probes ("Audio DMA Controller"). No data transfer is tested; the channel registers did not answer a read-only probe made after boot. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- Documentation/devicetree/bindings/dma/apple,admac.yaml | 1 + drivers/dma/apple-admac.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/dma/apple,admac.yaml b/Documentation/devicetree/bindings/dma/apple,admac.yaml index adc94ff3a3b69a..d171827c5fba32 100644 --- a/Documentation/devicetree/bindings/dma/apple,admac.yaml +++ b/Documentation/devicetree/bindings/dma/apple,admac.yaml @@ -40,6 +40,7 @@ properties: - const: apple,t8122-admac - const: apple,t8122-admac - const: apple,t8140-admac + - const: apple,t8152-admac reg: maxItems: 1 diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index dfaeeba9d8e83e..213d83d68808d3 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -1034,8 +1034,15 @@ static const struct admac_hw admac_t8140_hw = { .evolved_layout = true, }; +static const struct admac_hw admac_t8152_hw = { + /* macOS writes no global 0x28/0x2c value on this SoC */ + .set_unk28 = false, + .evolved_layout = true, +}; + static const struct of_device_id admac_of_match[] = { { .compatible = "apple,t8140-admac", .data = &admac_t8140_hw }, + { .compatible = "apple,t8152-admac", .data = &admac_t8152_hw }, { .compatible = "apple,t8122-admac", .data = &admac_t8122_hw }, { .compatible = "apple,t8103-admac", .data = &admac_t8013_hw }, { .compatible = "apple,admac", .data = &admac_t8013_hw }, From 7d52ab5f72b2b2cc9b369fdb355c13f823135884 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 10:23:53 -0500 Subject: [PATCH 12/32] soc: apple: aop: add the T8152 (Mac mini) hardware config Add apple,t8152-aop. Unlike T8140 it has no setup port: the CPU is started through the wrapper and RTKit boots on the primary mailbox, with three AFK endpoints (0x20 SPUApp, 0x21 wakehint, 0x22 aop-audio) announced with EPIC sub-header version 2. The binding requires two mailboxes for T8140 and allows exactly one for T8152. MEASURED on an M6 Mac mini, with an out-of-tree probe module: RTKit v12 boots on the primary mailbox without the setup port; all three services start; 25 of 25 EPIC calls with the version 2 header were answered; the speaker, codec-out and codec-in devices attach and report power state idle. NOT measured: audio data transfer, the hpai/lpai/tap devices (they return an error on this machine). BLOCKED: this patch alone does not play audio, see the audio driver patch. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/soc/apple/apple,t8140-aop.yaml | 33 ++++++++++++++++--- drivers/soc/apple/aop.rs | 20 +++++++++++ 2 files changed, 48 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml index deeef58299f6d1..5b2861c1e7c4bc 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml @@ -11,13 +11,16 @@ maintainers: description: The Always-On Processor provides audio and sensor services through firmware - loaded by the bootloader. The application processor uses a primary mailbox - and a separate setup-port mailbox. Each mailbox consumer has its own DMA - allocation window in the inherited AOP DART mappings. + loaded by the bootloader. On T8140 the application processor uses a primary + mailbox and a separate setup-port mailbox; on T8152 the setup port belongs to + the secure world and only the primary mailbox exists. Each mailbox consumer + has its own DMA allocation window in the inherited AOP DART mappings. properties: compatible: - const: apple,t8140-aop + enum: + - apple,t8140-aop + - apple,t8152-aop reg: items: @@ -30,11 +33,13 @@ properties: - const: asc mboxes: + minItems: 1 items: - description: Primary firmware transport - - description: Firmware setup-port transport + - description: Firmware setup-port transport (T8140 only) mbox-names: + minItems: 1 items: - const: mbox - const: setup @@ -61,6 +66,24 @@ properties: type: object $ref: /schemas/sound/apple,t8140-aop-audio.yaml# +allOf: + - if: + properties: + compatible: + const: apple,t8140-aop + then: + properties: + mboxes: + minItems: 2 + mbox-names: + minItems: 2 + else: + properties: + mboxes: + maxItems: 1 + mbox-names: + maxItems: 1 + required: - compatible - reg diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 6641e1d5013622..689b5462e3f82c 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -2309,6 +2309,25 @@ const HW_CFG_T8140: AopHwConfig = AopHwConfig { required_endpoints: &[0x20, 0x21, 0x22, 0x23, 0x2b], }; +/// T8152 (Mac mini): the firmware is preloaded by the bootloader and the setup +/// mailbox belongs to the secure world, so there is no setup port: the CPU is +/// started through the wrapper and RTKit boots on the primary mailbox. It +/// advertises three AFK endpoints, 0x20 SPUApp, 0x21 wakehint and 0x22 +/// aop-audio, all announced with EPIC sub-header version 2. The firmware only +/// brings its AFK endpoints up once all of them are started, which start_afk +/// does back to back. Calls with the version 2 header on the aop-audio +/// endpoint were all answered, with the tag echoed at the version 2 offset. +const HW_CFG_T8152: AopHwConfig = AopHwConfig { + ec0p: 0, + aopt: 0, + alig: 0, + patch_bootargs: false, + epic_v4: false, + setup_port: false, + quiesce_on_unbind: true, + required_endpoints: &[0x20, 0x21, 0x22], +}; + kernel::of_device_table!( OF_TABLE, MODULE_OF_TABLE, @@ -2319,6 +2338,7 @@ kernel::of_device_table!( (of::DeviceId::new(c_str!("apple,t6000-aop")), &HW_CFG_T6000), (of::DeviceId::new(c_str!("apple,t6020-aop")), &HW_CFG_T6020), (of::DeviceId::new(c_str!("apple,t8140-aop")), &HW_CFG_T8140), + (of::DeviceId::new(c_str!("apple,t8152-aop")), &HW_CFG_T8152), ] ); From 92c67d41f89b4d8d9c244e01af02319c05d8fab6 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:17:22 -0500 Subject: [PATCH 13/32] iommu/apple-dart: add owned-streams and inherited-roots for T8152 The T8152 SBR DART serves the audio DMA controllers together with firmware and coprocessor streams (AOP, MTP) in one instance, and the bootloader leaves its streams translating with page-table roots that hold firmware mappings although its lock bit is clear. Resetting it as a whole would break the firmware streams. apple,inherited-roots makes the driver treat such a DART as locked: it is never reset, TCR and TTBR are never written, and consumers publish into the vacant slots of the inherited roots, the path already used for locked DARTs. apple,owned-streams lists the streams that belong to Linux: consumer iommus entries naming another stream are refused, latched exceptions of other streams are not acknowledged, and the DART tunables are left as firmware set them. The interrupt handler applies the same filter as the probe-time drain: the pending word is masked with the owned streams before the faults are reported and before it is written back, so the exceptions of the streams firmware owns are neither logged as faults nor acknowledged. If such a stream raises an exception that stays latched, the shared interrupt line stays asserted; no foreign exception was seen on the M6 (the error registers were zero in every run). MEASURED on an M6 Mac mini with an earlier form of this change (separate compatibles instead of properties, on an older base): the shared DART probes without a reset, the AOP firmware boots, the audio DMA channels move data through it (the jack stream in real time at 48 kHz, the speaker stream in real time as mono at 48 kHz) and the error registers stay zero. NOT measured: this exact form on the current base, an exception raised by a firmware-owned stream. BLOCKED: nothing for the DART itself; the SBR DART device-tree node comes with the audio layer. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../devicetree/bindings/iommu/apple,dart.yaml | 18 +++++ drivers/iommu/apple-dart.c | 67 +++++++++++++++++-- 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 8996f8aef1e797..ef040278db4270 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -61,6 +61,24 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 description: Stream count assumed by apple,static-topology (default 16). + apple,inherited-roots: + type: boolean + description: | + apple,t8152-dart only. Treat the DART as locked even though its PROTECT + lock bit is clear: the bootloader left the listed streams translating + with page-table roots that hold firmware mappings, so the DART is never + reset, TCR/TTBR are never written, and consumers publish into the vacant + slots of the inherited roots (the path used for locked DARTs). + + apple,owned-streams: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: | + apple,t8152-dart only. The DART is shared with firmware and + coprocessors (the T8152 SBR DART): only these stream ids belong to the + OS. Consumer iommus entries never reference another stream, latched + exceptions of other streams are not acknowledged, and the DART tunables + are left as firmware set them. + clocks: description: Reference to the gate clock phandle if required for this IOMMU. diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 75682a5266a4fc..babed7248c04db 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -295,6 +295,13 @@ struct apple_dart { u32 four_level : 1; u32 locked : 1; u32 force_available : 1; + /* + * A DART shared with firmware (the T8152 SBR DART): only the owned + * streams belong to Linux; the others still translate for firmware and + * coprocessors and are never acknowledged or referenced. + */ + u32 has_owned : 1; + DECLARE_BITMAP(owned, DART_MAX_STREAMS); u32 tunneled : 1; u32 per_stream : 1; u32 power_retained : 1; @@ -1307,6 +1314,22 @@ static int apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *strea static const char *apple_dart_t8110_v2_fault_name(u32 exception); +/* The bits of exception word @word that belong to streams Linux owns. */ +static u32 apple_dart_owned_mask(struct apple_dart *dart, unsigned int word) +{ + unsigned int bit; + u32 own = 0; + + if (!dart->has_owned) + return U32_MAX; + + for (bit = 0; bit < 32; bit++) + if (test_bit(word * 32 + bit, dart->owned)) + own |= BIT(bit); + + return own; +} + static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) { unsigned int i, drained = 0; @@ -1316,9 +1339,13 @@ static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) for (i = 0; i < DIV_ROUND_UP(dart->num_streams, 32) && i < 8; i++) { u32 pending = readl(dart->regs + DART_T8110_EXCEPTION(i)); - unsigned long bits = pending; + unsigned long bits; unsigned int bit; + /* Shared DART: the latched exceptions of other streams are not ours. */ + pending &= apple_dart_owned_mask(dart, i); + bits = pending; + if (!pending) continue; @@ -2321,6 +2348,8 @@ static int apple_dart_of_xlate(struct device *dev, return i; sid = args->args[0]; + if (dart->has_owned && !test_bit(sid, dart->owned)) + return -EINVAL; if (!cfg) { cfg = kzalloc_obj(*cfg); @@ -2813,9 +2842,16 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev, bool gen3) */ for (i = 0; i < words && i < 8; i++) { u32 pending = readl(dart->regs + DART_T8110_EXCEPTION(i)); - unsigned long bits = pending; + unsigned long bits; unsigned int bit; + /* + * Shared DART: neither report nor acknowledge the exceptions of + * streams that belong to firmware. + */ + pending &= apple_dart_owned_mask(dart, i); + bits = pending; + if (!pending) continue; @@ -3100,7 +3136,7 @@ static int apple_dart_cfg_ensure_ready(struct apple_dart_master_cfg *cfg) static int apple_dart_probe(struct platform_device *pdev) { - int ret; + int ret, count; u32 sid; struct device_node *pd_np; struct resource *res; @@ -3225,6 +3261,9 @@ static int apple_dart_probe(struct platform_device *pdev) */ if (apple_dart_is_locked(dart)) dev_info(dev, "Gen3 DART is locked: not applying tunables\n"); + else if (of_property_read_bool(dev->of_node, "apple,inherited-roots") || + of_property_present(dev->of_node, "apple,owned-streams")) + dev_info(dev, "shared Gen3 DART: tunables left as firmware set them\n"); else apple_dart_apply_tunables(dart); } @@ -3349,6 +3388,24 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) goto err_clk_disable; + count = of_property_count_u32_elems(dev->of_node, "apple,owned-streams"); + if (count > 0) { + for (int i = 0; i < count; i++) { + ret = of_property_read_u32_index(dev->of_node, + "apple,owned-streams", + i, &sid); + if (ret || sid >= dart->num_streams) { + ret = ret ?: -ERANGE; + goto err_clk_disable; + } + set_bit(sid, dart->owned); + } + dart->has_owned = true; + } else if (count != -EINVAL) { + ret = count; + goto err_clk_disable; + } + /* * A hot-plug PCIe-C DART has no retained/locked translation context. * A DART the bootloader leaves locked is one that hardware we do not drive @@ -3360,7 +3417,9 @@ static int apple_dart_probe(struct platform_device *pdev) if (tunneled) dart->locked = false; else - dart->locked = !dart->static_topo && apple_dart_is_locked(dart); + dart->locked = !dart->static_topo && + (apple_dart_is_locked(dart) || + of_property_read_bool(dev->of_node, "apple,inherited-roots")); if (dart->hw->gen3 && dart->locked && !dart->force_available) { dev_info(dev, "locked DART: holding it available for its lifetime\n"); dart->force_available = 1; From 65356f51253304c2a880b5bb55e23f4a198c5ee1 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:23:06 -0500 Subject: [PATCH 14/32] dma: apple-admac: T8152 channels have per-channel 16 KiB apertures The T8152 audio DMA controller has no channel control blocks at 0x8000 and 0xc000 as the t8140 one does: a read there ends in a synchronous external abort, and the first write to such a block hangs the machine with an asynchronous SError. Instead every channel has its own 16 KiB aperture, the TX channels from 0x40000 and the RX channels from 0x80000, at a 0x4000 stride. Add a per-variant flag for that layout and use it for the T8152 variant; the descriptor FIFO ports (0x10000 for TX, 0x14000 for RX) and the global registers stay where they are. MEASURED on an M6 Mac mini with /dev/mem reads after the first power request to an AOP audio service: the global registers (+0x0, +0x94), the FIFO port pages (0x10000, 0x14000) and 13 apertures each at 0x40000 and 0x80000 (stride 0x4000, 13 being the channel count of the instance) answer; 0x8000, 0xc000 and 0x74000 abort. Writes of the bus width, SRAM carveout, FIFO control and interrupt mask registers at the start of an aperture read back correctly. The TX/RX assignment of the two halves comes from the vendor driver's descriptor and aperture code (TX channel n at 0x40000 + n * 0x4000); with the opposite assignment the channel starts but never takes a descriptor (ring register stays empty, no transfer). MEASURED with this layout: TX channel 5 (headphone jack) and TX channel 1 (speaker) accept their descriptors, the ring registers and residue move, a report with a 24 MHz timestamp arrives for every completed descriptor and the interrupt fires; the jack stream consumes data in real time at 48 kHz. NOT measured: that the samples reach the codec (nothing was listened to). BLOCKED: audio output also needs the AOP audio driver changes. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/dma/apple-admac.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index 213d83d68808d3..b02e2f525bb32d 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -67,7 +67,15 @@ */ #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 has no channel blocks at 0x8000/0xc000: every channel owns a 16 KiB + * aperture, the TX ones from 0x40000 and the RX ones from 0x80000, with the + * per-channel register layout of the other variants inside. The FIFO ports + * stay at 0x10000. + */ +#define REG_CHAN_BASE_APERTURE(ch) (((ch) & 1 ? 0x80000 : 0x40000) + ((ch) / 2) * 0x4000) +#define REG_CHAN_BASE(ad, ch) ((ad)->chan_aperture ? REG_CHAN_BASE_APERTURE(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) @@ -152,6 +160,7 @@ struct admac_data { bool set_unk28; bool evolved_layout; + bool chan_aperture; int irq; int irq_index; int nchannels; @@ -175,6 +184,7 @@ struct admac_tx { struct admac_hw { bool set_unk28; bool evolved_layout; + bool chan_aperture; }; static int admac_alloc_sram_carveout(struct admac_data *ad, @@ -907,6 +917,7 @@ static int admac_probe(struct platform_device *pdev) ad->nchannels = nchannels; ad->set_unk28 = hw->set_unk28; ad->evolved_layout = hw->evolved_layout; + ad->chan_aperture = hw->chan_aperture; mutex_init(&ad->cache_alloc_lock); /* @@ -1038,6 +1049,7 @@ static const struct admac_hw admac_t8152_hw = { /* macOS writes no global 0x28/0x2c value on this SoC */ .set_unk28 = false, .evolved_layout = true, + .chan_aperture = true, }; static const struct of_device_id admac_of_match[] = { From 9fbf2d14b6601c8ce2b4a44daa3e92f988a8d32f Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 11:36:43 -0500 Subject: [PATCH 15/32] reset: apple-cio: add apple,t8152-cio-reset The M6 (T8152) CIO reconfigure is a request/done register pair in the PMGR block: BIT(cluster) is written to the request register, BIT(cluster) is polled in the done register (the vendor driver allows 10 s), and the done bit is cleared by writing it back. The node is a sub-node of the PMGR syscon whose reg is the offset of the request register; the reset id is the CIO cluster (0..3, the cio-cluster property of the PMGR child). The sequence follows the vendor power-management driver for this SoC. NOT measured: no M6 boot has exercised this driver yet. Compile status: see the pull request. BLOCKED: the controller node and the reset consumers (ACIO) live in the Thunderbolt/USB4 device-tree layers. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/reset/apple,t8103-cio-reset.yaml | 7 ++- drivers/reset/reset-apple-cio.c | 52 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index 83f307d3fc178b..8ecad084c866a9 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -22,7 +22,11 @@ description: | On t8142, a standalone register page contains a shared request register with alternating request and busy bits for four ports. - In all cases the reset id is the CIO port index on the die. + On t8152 the request and done registers are two adjacent words in the PMGR + region and, as on t600x, are a sub-node of the PMGR syscon; reg is the offset + of the request register and the reset id is the CIO cluster index. + + On the other SoCs the reset id is the CIO port index on the die. properties: compatible: @@ -31,6 +35,7 @@ properties: - apple,t8103-cio-reset - apple,t8142-cio-reset - apple,t6000-cio-reset + - apple,t8152-cio-reset - items: - const: apple,t8112-cio-reset - const: apple,t8103-cio-reset diff --git a/drivers/reset/reset-apple-cio.c b/drivers/reset/reset-apple-cio.c index af299473a6c876..ea77c3d8b6438f 100644 --- a/drivers/reset/reset-apple-cio.c +++ b/drivers/reset/reset-apple-cio.c @@ -40,6 +40,14 @@ * On t8142, RegMap 0x62 is a separate MMIO region at 0x380780000. * The t8132 layout has not been decoded. * + * On t8152 (M6) the request and done registers are separate words in the PMGR + * block at 0x300780000: BIT(cluster) is written to the request register at + * +0x68, BIT(cluster) is then polled in the done register at +0x6c (the vendor + * driver allows 10 s), and the done bit is cleared by writing it back. There + * is one cluster per port (the pmgr-child cio-cluster property: devices + * 320..323, CIOn_RECONFIG-V, clusters 0..3), and the node's reg is the offset + * of the request register in the PMGR syscon (0x80068). + * * Reference firmware polls the busy bits, stores the request, then polls * again, with a 192 ms budget. It discards the first poll's result. The * t8142 implementation below instead refuses to issue a request while busy. @@ -62,6 +70,12 @@ #define T8103_CIO_CTRL_INIT_BUSY BIT(1) #define T8103_CIO_CTRL_INIT_DONE BIT(2) +/* The node's reg is the request register; the done register follows it. */ +#define T8152_CIO_REQ 0x0 +#define T8152_CIO_DONE 0x4 +/* The vendor driver waits up to 10 s for a cluster to come online. */ +#define T8152_CIO_TIMEOUT_US 10000000 + #define T6000_CIO_CTRL_INIT_REQ(port) BIT(port) #define T6000_CIO_CTRL_INIT_BUSY(port) BIT(16 + (port)) @@ -197,6 +211,34 @@ static const struct apple_cio_reset_variant apple_t8142_cio_reset = { .deassert = t8142_cio_deassert, }; +static int t8152_cio_deassert(struct apple_cio_reset *priv, unsigned long id) +{ + u32 val; + int ret; + + guard(mutex)(&priv->lock); + + /* A request for this cluster may still be pending; advisory, as on the other SoCs. */ + ret = regmap_read_poll_timeout(priv->regmap, priv->offset + T8152_CIO_REQ, val, + !(val & BIT(id)), APPLE_CIO_RESET_POLL_US, + APPLE_CIO_RESET_TIMEOUT_US); + if (ret) + dev_warn(priv->dev, "CIO %lu still busy before reconfigure request\n", id); + + ret = regmap_write(priv->regmap, priv->offset + T8152_CIO_REQ, BIT(id)); + if (ret) + return ret; + + ret = regmap_read_poll_timeout(priv->regmap, priv->offset + T8152_CIO_DONE, val, + val & BIT(id), APPLE_CIO_RESET_POLL_US, + T8152_CIO_TIMEOUT_US); + if (ret) + return ret; + + /* The done bit is write-one-to-clear. */ + return regmap_write(priv->regmap, priv->offset + T8152_CIO_DONE, BIT(id)); +} + static const struct apple_cio_reset_variant apple_t8103_cio_reset = { .nr_resets = 2, .deassert = t8103_cio_deassert, @@ -208,6 +250,12 @@ static const struct apple_cio_reset_variant apple_t6000_cio_reset = { .deassert = t6000_cio_deassert, }; +static const struct apple_cio_reset_variant apple_t8152_cio_reset = { + .nr_resets = 4, + .pmgr_child = true, + .deassert = t8152_cio_deassert, +}; + static int apple_cio_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { struct apple_cio_reset *priv = @@ -293,6 +341,10 @@ static const struct of_device_id apple_cio_reset_match[] = { .compatible = "apple,t6030-cio-reset", .data = &apple_t6000_cio_reset, }, + { + .compatible = "apple,t8152-cio-reset", + .data = &apple_t8152_cio_reset, + }, {}, }; MODULE_DEVICE_TABLE(of, apple_cio_reset_match); From 358333834045b976331b7d6dc2edc6a35c87095d Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:02:02 -0500 Subject: [PATCH 16/32] ASoC: apple: t8140-aop-audio: add the T8152 variant On T8152 (J873) the AOP audio service has only the speaker, jack output and jack input devices: lpai, hpai and the speaker tap answer kIOReturnNoDevice. There is no lpai microphone to raise the gated audio fabric with, no source ring, and no AP-powered serializer leaves (the audio PMGR leaves are virtual; the firmware powers them). Match data now says whether the machine has lpai: apple,t8140-aop-audio keeps everything as it was, apple,t8152-aop-audio skips the lpai/hpai attach, the source ring, the raw sound card with its two capture PCMs, the power-domain attach and the fabric raise, and treats the tap service as absent. The speaker mute property is not requested (the firmware answers every property above 302 with 0xe00002f0, unsupported; the amplifier is muted through its own codec), the speaker front-end and back-end accept one or two channels, and the properties 200/300/301/302 of a service are logged at debug level after pw0 and pwrd, so that the stream format can be read from the log. MEASURED on an M6 Mac mini: the AOP boots, the audio service has speaker, jack output and jack input devices and no lpai/hpai/tap (kIOReturnNoDevice); the audio fabric answers after the first power request of any service; with the T8152 ADMAC apertures the jack stream (S24, 48 kHz stereo) is consumed in real time (a DMA report every 125.00 ms for 48000-byte periods); the speaker stream drains at half the frame rate in stereo and at 48 kHz in mono (24000-byte periods, one report per 124.67 ms), no hang, no DART fault; the speaker amplifier logs 'bad TDM clock' once at stream start and not again while streaming. NOT measured: sound reaching the jack codec/headset or the speaker (the speaker volume stays locked at the lowest step and no speaker-safety profile exists), capture paths, suspend/resume. BLOCKED: the amplifier unlock needs a speaker-safety profile. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/sound/apple,t8140-aop-audio.yaml | 53 ++- sound/soc/apple/t8140_aop_audio.rs | 332 ++++++++++++------ 2 files changed, 274 insertions(+), 111 deletions(-) diff --git a/Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml b/Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml index b023080e48c7fc..7eb36c3b929fd1 100644 --- a/Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,t8140-aop-audio.yaml @@ -4,7 +4,7 @@ $id: http://devicetree.org/schemas/sound/apple,t8140-aop-audio.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8140 AOP audio +title: Apple T8140 and T8152 AOP audio maintainers: - Ryan Murray @@ -20,22 +20,29 @@ description: | The remaining audio data moves over the named ADMAC channels while its AOP service is active. The parent AOP binding describes the firmware transport. -allOf: - - $ref: dai-common.yaml# + On T8152 (Mac mini, J873) the AOP offers only the speaker, jack output and + jack input services; the low-power and array microphones and the speaker tap + answer with kIOReturnNoDevice. The serializers and the audio fabric are + powered by the firmware, so the node has no power domains and no DART stream + of its own, and the sound card is described by a separate machine node. properties: compatible: - const: apple,t8140-aop-audio + enum: + - apple,t8140-aop-audio + - apple,t8152-aop-audio dmas: + minItems: 4 items: - description: Internal speaker output - description: Headset jack output - description: Headset microphone input - description: Speaker output monitor input - - description: High-quality microphone array input + - description: High-quality microphone array input (T8140 only) dma-names: + minItems: 4 items: - const: spkr - const: cout @@ -91,13 +98,37 @@ required: - compatible - dmas - dma-names - - power-domains - - power-domain-names - - iommus - - apple,dma-range - "#sound-dai-cells" - - apple,chassis-name - - apple,machine-kind + +allOf: + - $ref: dai-common.yaml# + - if: + properties: + compatible: + const: apple,t8140-aop-audio + then: + properties: + dmas: + minItems: 5 + dma-names: + minItems: 5 + required: + - power-domains + - power-domain-names + - iommus + - apple,dma-range + - apple,chassis-name + - apple,machine-kind + else: + properties: + dmas: + maxItems: 4 + dma-names: + maxItems: 4 + power-domains: false + power-domain-names: false + iommus: false + apple,dma-range: false unevaluatedProperties: false diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index f077ff4df6e6c0..8ad9390dd1530d 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -556,7 +556,14 @@ struct SndSocT8140AopData { dev: ARef, adata: Arc, service: EPICService, - ring: Arc, + /// The low-power microphone's source ring; `None` on machines without lpai. + ring: Option>, + /// The machine has the lpai microphone, whose run state also raises the + /// gated audio fabric, and PMGR serializer leaves the AP must power + /// (T8140). On T8152 neither exists: the firmware powers its own fabric + /// and the serializers, and lpai, hpai and tap attach with + /// kIOReturnNoDevice. + has_lpai: bool, ring_bytes: Atomic, sequence: Atomic, /// The low-power microphone PCM holds a reference on `lpai_run`. @@ -903,6 +910,9 @@ impl SndSocT8140AopData { /// power up fails the stream; recovering a domain from that state is the /// power-domain driver's business, not a consumer's. fn power_up(&self, name: &str, pds: &[&Option], attempts: u32) -> Result<()> { + if !self.has_lpai { + return Ok(()); + } for (i, slot) in pds.iter().enumerate() { let Some(pd) = slot else { dev_err!(self.dev, "{}: power domain not attached\n", name); @@ -944,11 +954,57 @@ impl SndSocT8140AopData { fn service_startup(&self, svc: &Service, pds: &[&Option]) -> Result<()> { self.attach_device(svc.dev_id, svc.name)?; self.service_set_power(svc, SPKR_POWER_STATE_PW0)?; + if !self.has_lpai { + self.log_service_props(svc, "pw0"); + } self.power_up_raising(svc.name, pds)?; svc.running.store(false, Relaxed); Ok(()) } + /// T8152 bring-up diagnostics: log what the firmware reports for a + /// service (properties 200, 300, 301 and 302) so that the stream format + /// and the serializer state can be read from the log. Read-only. + fn log_service_props(&self, svc: &Service, when: &str) { + for modifier in [ + PROP_POWER_STATE, + PROP_CHANNEL_CONTROL, + PROP_STREAM_FORMAT, + PROP_RING_GEOMETRY, + ] { + let msg = AudioGetDeviceProp::new(svc.dev_id, modifier); + // SAFETY: the message is a plain packed firmware record. + let bytes = unsafe { + slice::from_raw_parts( + ptr::from_ref(&msg).cast::(), + mem::size_of::(), + ) + }; + match self + .adata + .epic_call_ret(&self.service, EPIC_SUBTYPE_WRAPPED_CALL, bytes, 64) + { + Ok((ret, data)) => dev_dbg!( + self.dev, + "{} {}: property {} retcode {:#x} data {:02x?}\n", + svc.name, + when, + modifier, + ret, + &data[..] + ), + Err(e) => dev_dbg!( + self.dev, + "{} {}: property {} call failed: {:?}\n", + svc.name, + when, + modifier, + e + ), + } + } + } + /// [`Self::power_up`] with the fabric raised first. /// /// The fabric may be gated at any open (a low-power capture is enough, @@ -967,6 +1023,9 @@ impl SndSocT8140AopData { /// microphone is attached for the firmware's lifetime, so hold it in /// `runn` around `f`, once its first report has arrived. fn with_fabric_raised(&self, f: impl FnOnce() -> Result) -> Result { + if !self.has_lpai { + return f(); + } self.lpai_run_get()?; let mut polls = 0; while !self.reported.load(Relaxed) && polls < FABRIC_RAISE_POLLS { @@ -994,6 +1053,9 @@ impl SndSocT8140AopData { } self.service_set_power(svc, SPKR_POWER_STATE_PWRD)?; svc.running.store(true, Relaxed); + if !self.has_lpai { + self.log_service_props(svc, "pwrd"); + } Ok(()) } @@ -1039,14 +1101,23 @@ impl SndSocT8140AopData { // data after the copy-time gain, it senses no current or voltage. ---- fn sense_startup(&self) -> Result<()> { + if !self.has_lpai { + return Ok(()); + } self.service_startup(&self.tap, &[&self.pd_mca0]) } fn sense_prepare(&self) -> Result<()> { + if !self.has_lpai { + return Ok(()); + } self.service_run(&self.tap) } fn sense_shutdown(&self) { + if !self.has_lpai { + return; + } self.service_shutdown(&self.tap, &[&self.pd_mca0]) } @@ -1138,6 +1209,17 @@ impl SndSocT8140AopData { /// Output mute (property 700) is independent of the amplifier's SD_MODE; /// the amplifier stays off across a failure here. fn spkr_set_mute(&self, muted: bool) -> Result<()> { + if !self.has_lpai { + // T8152: the firmware answers every property above 302 with + // 0xe00002f0 (unsupported), the mute request included (measured on + // an M6 Mac mini); the amplifier is muted through its own codec. + dev_dbg!( + self.dev, + "speaker mute {} not requested on this firmware\n", + muted + ); + return Ok(()); + } let ret = self.epic_wrapped_call(&AudioSetDeviceProp::new( AUDIO_DEV_SPKR, PROP_OUTPUT_MUTE, @@ -1340,7 +1422,7 @@ impl ReportListener for SndSocT8140AopData { let dma_area = unsafe { (*(*st.substream).runtime).dma_area }; let buffer_bytes = st.buffer_bytes; let new_ptr = copy_span( - &self.ring, + self.ring.as_ref().ok_or(ENODEV)?, dma_area, buffer_bytes, ring_bytes, @@ -2725,6 +2807,24 @@ fn pcm_stream( } } +fn pcm_stream_range( + name: &'static core::ffi::CStr, + formats: u64, + channels_min: u32, + channels_max: u32, +) -> bindings::snd_soc_pcm_stream { + bindings::snd_soc_pcm_stream { + stream_name: name.as_char_ptr(), + formats, + rates: bindings::SNDRV_PCM_RATE_48000, + rate_min: 48000, + rate_max: 48000, + channels_min, + channels_max, + ..Default::default() + } +} + /// The AOP-configured serializers take 24-bit samples from the low bits /// of each 32-bit DMA word: S24_LE. const OUT_FORMATS: u64 = bindings::BINDINGS_SNDRV_PCM_FMTBIT_S24_LE; @@ -2737,7 +2837,10 @@ const S32_FORMATS: u64 = bindings::BINDINGS_SNDRV_PCM_FMTBIT_S32_LE; /// renumbers every DAI after it and silently repoints the existing links. const DAI_COUNT: usize = 2 + FE_COUNT; -fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { +// `mono_speaker`: T8152, whose speaker serializer takes one 32-bit word per +// 48 kHz frame (measured: the DMA drains 192000 bytes per second whatever the +// stream), so the speaker front-end must also accept one channel. +fn dai_drivers(ops: &DaiOps, mono_speaker: bool) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { [ bindings::snd_soc_dai_driver { name: c"cout".as_char_ptr(), @@ -2762,7 +2865,12 @@ fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { id: FE_DAI_ID_BASE + 1, ops: &ops.fe, // the speaker front-end: S32 in, converted through the ceiling - playback: pcm_stream(c"PCM1 TX", S32_FORMATS, 2), + playback: pcm_stream_range( + c"PCM1 TX", + S32_FORMATS, + if mono_speaker { 1 } else { 2 }, + 2, + ), ..Default::default() }, bindings::snd_soc_dai_driver { @@ -2780,7 +2888,12 @@ fn dai_drivers(ops: &DaiOps) -> [bindings::snd_soc_dai_driver; DAI_COUNT] { name: c"spkr".as_char_ptr(), id: BE_DAI_ID_SPKR, ops: &ops.spkr, - playback: pcm_stream(c"SPKR TX", S32_FORMATS, 2), + playback: pcm_stream_range( + c"SPKR TX", + S32_FORMATS, + if mono_speaker { 1 } else { 2 }, + 2, + ), capture: pcm_stream(c"SPKR RX", S32_FORMATS, 2), ..Default::default() }, @@ -2806,7 +2919,7 @@ const _: () = assert!(mem::offset_of!(AsocContext, component) == 0); 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.has_lpai)), GFP_KERNEL)?; let volume = KBox::new( Opaque::new(bindings::soc_mixer_control { min: 0, @@ -2931,89 +3044,91 @@ impl SndSocT8140AopDriver { closed: AtomicFlag::new(false), }; - // The low-power microphone: its ring is reported to us by the - // firmware for the AOP's lifetime. - data.attach_device(AUDIO_DEV_LPAI, "lpai")?; - data.set_channel_control()?; - data.read_geometry()?; - let listener: Arc = data.clone(); - data.adata - .add_report_listener(data.service, EPIC_SUBTYPE_PRODUCER_REPORT, listener)?; - - // SAFETY: FFI call with the live device and the module; `this.card` receives the new card. - let ret = unsafe { - bindings::snd_card_new( - data.dev.as_raw(), - -1, - ptr::null(), - THIS_MODULE.as_ptr(), - 0, - &mut this.card, - ) - }; - if ret < 0 { - dev_err!(data.dev, "unable to allocate the sound card\n"); - return Err(Error::from_errno(ret)); - } - // Named like the other AOP audio cards: Apple. - let chassis = fwnode - .property_read::(c_str!("apple,chassis-name")) - .required_by(&data.dev)?; - let machine_kind = fwnode - .property_read::(c_str!("apple,machine-kind")) - .required_by(&data.dev)?; - let id_str = CString::try_from_fmt(fmt!("Apple{}AOP", *chassis))?; - let shortname = CString::try_from_fmt(fmt!("{} {} AOP", *machine_kind, *chassis))?; - let longname = CString::try_from_fmt(fmt!("{} {} AOP Audio", *machine_kind, *chassis))?; - // SAFETY: `card` was created by `snd_card_new` above and is not - // registered yet, so nothing else accesses it. - let card = unsafe { &mut *this.card }; - let named = copy_str(&mut card.driver, c"t8140-aop-audio".to_bytes_with_nul()) - .and_then(|()| copy_str(&mut card.id, id_str.to_bytes_with_nul())) - .and_then(|()| copy_str(&mut card.shortname, shortname.to_bytes_with_nul())) - .and_then(|()| copy_str(&mut card.longname, longname.to_bytes_with_nul())); - if let Err(e) = named { - dev_err!( - data.dev, - "apple,chassis-name or apple,machine-kind too long for the card names\n" - ); - return Err(e); - } - - this.new_pcm(0, c"lpai", c"Low-Power Microphone", &Self::LPAI_OPS)?; - this.new_pcm(1, c"hpai", c"High-Quality Microphone", &Self::HPAI_OPS)?; - - // Both microphones' jack: unplugged while a lid is closed. - let mut jack = ptr::null_mut(); - // SAFETY: `card` was created by `snd_card_new` above and is not registered yet; the jack - // becomes one of its devices and is freed with it. - let ret = unsafe { - bindings::snd_jack_new( - this.card, - c"Internal Mic".as_char_ptr(), - bindings::snd_jack_types_SND_JACK_MICROPHONE as i32, - &mut jack, - true, - // No input device of its own: the lid it follows already - // is one, and the control is what userspace reads. - true, - ) - }; - if ret < 0 { - dev_err!(data.dev, "unable to create the microphone jack\n"); - return Err(Error::from_errno(ret)); - } - data.mic_jack.store(jack, Relaxed); - this.register_lid_handler()?; - // The state as the card is registered, from the only reporter. - data.as_arc_borrow().queue_jack_report(); - data.flush_jack_report(); + if data.has_lpai { + // The low-power microphone: its ring is reported to us by the + // firmware for the AOP's lifetime. + data.attach_device(AUDIO_DEV_LPAI, "lpai")?; + data.set_channel_control()?; + data.read_geometry()?; + let listener: Arc = data.clone(); + data.adata + .add_report_listener(data.service, EPIC_SUBTYPE_PRODUCER_REPORT, listener)?; + + // SAFETY: FFI call with the live device and the module; `this.card` receives the new card. + let ret = unsafe { + bindings::snd_card_new( + data.dev.as_raw(), + -1, + ptr::null(), + THIS_MODULE.as_ptr(), + 0, + &mut this.card, + ) + }; + if ret < 0 { + dev_err!(data.dev, "unable to allocate the sound card\n"); + return Err(Error::from_errno(ret)); + } + // Named like the other AOP audio cards: Apple. + let chassis = fwnode + .property_read::(c_str!("apple,chassis-name")) + .required_by(&data.dev)?; + let machine_kind = fwnode + .property_read::(c_str!("apple,machine-kind")) + .required_by(&data.dev)?; + let id_str = CString::try_from_fmt(fmt!("Apple{}AOP", *chassis))?; + let shortname = CString::try_from_fmt(fmt!("{} {} AOP", *machine_kind, *chassis))?; + let longname = CString::try_from_fmt(fmt!("{} {} AOP Audio", *machine_kind, *chassis))?; + // SAFETY: `card` was created by `snd_card_new` above and is not + // registered yet, so nothing else accesses it. + let card = unsafe { &mut *this.card }; + let named = copy_str(&mut card.driver, c"t8140-aop-audio".to_bytes_with_nul()) + .and_then(|()| copy_str(&mut card.id, id_str.to_bytes_with_nul())) + .and_then(|()| copy_str(&mut card.shortname, shortname.to_bytes_with_nul())) + .and_then(|()| copy_str(&mut card.longname, longname.to_bytes_with_nul())); + if let Err(e) = named { + dev_err!( + data.dev, + "apple,chassis-name or apple,machine-kind too long for the card names\n" + ); + return Err(e); + } - // SAFETY: `card` was created by `snd_card_new` above and is not registered yet. - let ret = unsafe { bindings::snd_card_register(this.card) }; - if ret < 0 { - dev_err!(data.dev, "unable to register the sound card\n"); - return Err(Error::from_errno(ret)); + this.new_pcm(0, c"lpai", c"Low-Power Microphone", &Self::LPAI_OPS)?; + this.new_pcm(1, c"hpai", c"High-Quality Microphone", &Self::HPAI_OPS)?; + + // Both microphones' jack: unplugged while a lid is closed. + let mut jack = ptr::null_mut(); + // SAFETY: `card` was created by `snd_card_new` above and is not registered yet; the jack + // becomes one of its devices and is freed with it. + let ret = unsafe { + bindings::snd_jack_new( + this.card, + c"Internal Mic".as_char_ptr(), + bindings::snd_jack_types_SND_JACK_MICROPHONE as i32, + &mut jack, + true, + // No input device of its own: the lid it follows already + // is one, and the control is what userspace reads. + true, + ) + }; + if ret < 0 { + dev_err!(data.dev, "unable to create the microphone jack\n"); + return Err(Error::from_errno(ret)); + } + data.mic_jack.store(jack, Relaxed); + this.register_lid_handler()?; + // The state as the card is registered, from the only reporter. + data.as_arc_borrow().queue_jack_report(); + data.flush_jack_report(); + + // SAFETY: `card` was created by `snd_card_new` above and is not registered yet. + let ret = unsafe { bindings::snd_card_register(this.card) }; + if ret < 0 { + dev_err!(data.dev, "unable to register the sound card\n"); + return Err(Error::from_errno(ret)); + } } // The ASoC side: the jack (cout) and speaker back-ends, the @@ -3195,23 +3310,29 @@ unsafe extern "C" fn hpai_pcm_hw_params( } } +// The match data says whether the machine has the lpai microphone, its source +// ring and the AP-powered serializer leaves (T8140), or not (T8152). kernel::of_device_table!( OF_TABLE, MODULE_OF_TABLE, ::IdInfo, - [(of::DeviceId::new(c_str!("apple,t8140-aop-audio")), ())] + [ + (of::DeviceId::new(c_str!("apple,t8140-aop-audio")), true), + (of::DeviceId::new(c_str!("apple,t8152-aop-audio")), false), + ] ); impl platform::Driver for SndSocT8140AopDriver { - type IdInfo = (); + type IdInfo = bool; type Data<'bound> = SndSocT8140AopDriver; 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 has_lpai = *info.ok_or(ENODEV)?; let dev = ARef::::from(pdev.as_ref()); // SAFETY: this is a service device the AOP core registered, being // probed here; the lookup defers the probe until the core has @@ -3230,18 +3351,28 @@ impl platform::Driver for SndSocT8140AopDriver { // owned by the AOP driver because the firmware binds it once per boot. // SAFETY: no DMA is in flight on this device yet. unsafe { pdev.dma_set_mask_and_coherent(DmaMask::new::<42>())? }; - let ring = adata.source_ring(pdev.as_ref(), RING_BYTES)?; + let ring = if has_lpai { + Some(adata.source_ring(pdev.as_ref(), RING_BYTES)?) + } else { + None + }; // The serializer leaves. A missing one only disables the paths that - // need it; those fail to open with ENODEV. + // need it; those fail to open with ENODEV. T8152 has none: the + // firmware powers its own serializers. let mut pds: [Option; 5] = [None, None, None, None, None]; - for (slot, (name, dt_name)) in pds.iter_mut().zip([ - ("mca1", c"mca1"), - ("mca0", c"mca0"), - ("tx0", c"tx0"), - ("leap mca", c"mca"), - ("rx0", c"rx0"), - ]) { + let leaves: &[(&'static str, &'static core::ffi::CStr)] = if has_lpai { + &[ + ("mca1", c"mca1"), + ("mca0", c"mca0"), + ("tx0", c"tx0"), + ("leap mca", c"mca"), + ("rx0", c"rx0"), + ] + } else { + &[] + }; + for (slot, (name, dt_name)) in pds.iter_mut().zip(leaves.iter().copied()) { match PowerDomain::attach(&dev, name, dt_name) { Ok(Some(pd)) => *slot = Some(pd), Ok(None) => dev_warn!(dev, "no {} power domain\n", name), @@ -3257,6 +3388,7 @@ impl platform::Driver for SndSocT8140AopDriver { adata, service: svc, ring, + has_lpai, ring_bytes: Atomic::new(0), sequence: Atomic::new(0), powered: AtomicFlag::new(false), From 3c45a71a6628f4ab8ebc2a72a03e128f01973dae Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:02:03 -0500 Subject: [PATCH 17/32] ASoC: apple: macaudio: add apple,j873-macaudio AOP-fed like the J700, with the J873's SN012776 speaker amplifier; the speakers stay disabled until the speaker path is verified on hardware, the jack comes first. The front-end DAI names are those of the AOP audio component. In the single-woofer control fixup, the J873's amplifier controls are looked up with the amp node's sound-name-prefix ("Speaker ") instead of the empty prefix: with the empty prefix the lookup of 'Amp Gain Volume' fails with -EINVAL, and "* " would match the cs42l84 jack codec instead. No other model's prefix changes. MEASURED on an M6 Mac mini: the AOP boots, the audio service has speaker, jack output and jack input devices and no lpai/hpai/tap (kIOReturnNoDevice); the audio fabric answers after the first power request of any service; with the T8152 ADMAC apertures the jack stream (S24, 48 kHz stereo) is consumed in real time (a DMA report every 125.00 ms for 48000-byte periods); the speaker stream drains at half the frame rate in stereo and at 48 kHz in mono (24000-byte periods, one report per 124.67 ms), no hang, no DART fault; the speaker amplifier logs 'bad TDM clock' once at stream start and not again while streaming. NOT measured: sound reaching the jack codec/headset or the speaker (the speaker volume stays locked at the lowest step and no speaker-safety profile exists), capture paths, suspend/resume. BLOCKED: the amplifier unlock needs a speaker-safety profile. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/sound/apple,macaudio.yaml | 1 + sound/soc/apple/macaudio.c | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml index 8e986cca62594a..6a6e911eed5ac0 100644 --- a/Documentation/devicetree/bindings/sound/apple,macaudio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,macaudio.yaml @@ -21,6 +21,7 @@ properties: - apple,j293-macaudio - apple,j314-macaudio - apple,j700-macaudio + - apple,j873-macaudio - const: apple,macaudio "#address-cells": diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index 095a0391ea411c..6cca60354c5f7b 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -1498,6 +1498,25 @@ static int macaudio_set_speaker(struct snd_soc_card *card, const char *prefix, b return 0; } +/* + * J873 (Mac mini, T8152): AOP-fed like the J700, but the speaker amplifier is + * an SN012776 on the AP's I2C bus and needs no software gain. The speakers + * stay disabled until the speaker path is verified on hardware (the amplifier + * model and the speaker count are not confirmed); the jack works first. The + * front-end DAIs are those of the AOP audio component, which keeps the + * T8140 names. The serial link format is the macaudio default until the + * firmware's stream-format property has been read on this machine. + */ +struct macaudio_platform_cfg macaudio_j873_cfg = { + .enable_speakers = false, + .amp = AMP_SN012776, + .speakers = SPKR_1W, + .stereo = false, + .amp_gain = 15, + .safe_vol = -20, + .fe_dai_names = { "j700-pcm-0", "j700-pcm-1", "j700-pcm-2" }, +}; + static int macaudio_fixup_controls(struct snd_soc_card *card) { struct macaudio_snd_data *ma = snd_soc_card_get_drvdata(card); @@ -1525,6 +1544,15 @@ static int macaudio_fixup_controls(struct snd_soc_card *card) /* only 1W stereo system (J313) is uses cs42l83 */ if (ma->cfg->stereo) { CHECK(macaudio_set_speaker, "* ", false, 0); + } else if (ma->cfg == &macaudio_j873_cfg) { + /* + * The J873's SN012776 amp node carries the + * sound-name-prefix "Speaker": with the empty prefix + * the lookup of "Amp Gain Volume" fails with -EINVAL, + * and "* " would match the cs42l84 jack codec's + * "Jack HPF Corner Frequency" instead. + */ + CHECK(macaudio_set_speaker, "Speaker ", false, 0); } else { CHECK(macaudio_set_speaker, "", false, 0); } @@ -1898,6 +1926,8 @@ static const struct of_device_id macaudio_snd_device_id[] = { /* j615 AID21 sn012776 15 2x 2W+1T Compat: apple,j415-macaudio */ /* j700 AID44 max98360a - 2x 1W (AOP-fed, software gain) */ { .compatible = "apple,j700-macaudio", .data = &macaudio_j700_cfg }, + /* j873 AID? sn012776 15 1x 1W (AOP-fed, speakers disabled) */ + { .compatible = "apple,j873-macaudio", .data = &macaudio_j873_cfg }, /* Fallback, jack only */ { .compatible = "apple,macaudio"}, { } From 8fad78cf5c86d537c756b12f77b4f4b9905fbdd2 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 18:51:06 -0500 Subject: [PATCH 18/32] soc: apple: mailbox: add the T8152 ACIO counted-FIFO mailbox apple,t8152-acio-mailbox has a different register interface than the ASC mailboxes: the status word at +0x20 holds the receive occupancy in bits 3:0 and the number of free transmit slots in bits 11:8, the receive FIFO is at +0, the transmit FIFO at +0x10, and each 128-bit message is moved with one paired 64-bit access. Reading or writing the classic ASC offsets (control at +0x110, send at +0x800, receive at +0x830) from this window would touch unrelated registers of the wrapper block. Add a counted_fifo flag to the hardware table, test "transmit full" and "receive empty" through two helpers that honour it, and move the message read and write into helpers that use one load or store pair for the counted layout (arm64 only; the entry is refused elsewhere). Every other hardware table keeps its flags unchanged and its two separate 64-bit accesses. Measured here: arm64 compile. Run on hardware in an older tree: this layout and the paired access carried the RTKit boot of the ACIO co-processor. Not measured: this patch on this base, the send-empty interrupt path of this mailbox. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- drivers/soc/apple/mailbox.c | 106 ++++++++++++++++++++++++++++++++---- 1 file changed, 96 insertions(+), 10 deletions(-) diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 5be648a40fe03c..5203cc52f2f79e 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -117,6 +117,8 @@ struct apple_mbox_hw { unsigned int reg_offset; bool is_ascwrap_v6; bool ap_initializes_mailboxes; + /* The status word counts RX occupancy and free TX slots; a message is one paired access. */ + bool counted_fifo; unsigned int control_full; unsigned int control_empty; @@ -266,6 +268,70 @@ int apple_mbox_ascwrap_v6_stop_cpu(struct apple_mbox *mbox) } EXPORT_SYMBOL_GPL(apple_mbox_ascwrap_v6_stop_cpu); +static bool apple_mbox_tx_full(struct apple_mbox *mbox, u32 status) +{ + if (mbox->hw->counted_fifo) + return !(status & mbox->hw->control_full); + return status & mbox->hw->control_full; +} + +static bool apple_mbox_rx_empty(struct apple_mbox *mbox, u32 status) +{ + if (mbox->hw->counted_fifo) + return !(status & mbox->hw->control_empty); + return status & mbox->hw->control_empty; +} + +static void apple_mbox_write_msg(struct apple_mbox *mbox, const struct apple_mbox_msg msg) +{ + u64 high = FIELD_PREP(APPLE_MBOX_MSG1_MSG, msg.msg1); + +#ifdef CONFIG_ARM64 + if (mbox->hw->counted_fifo) { + u64 low = (__force u64)cpu_to_le64(msg.msg0); + + high = (__force u64)cpu_to_le64(high); + /* Order the message words against the earlier writes to the shared buffers. */ + wmb(); + asm volatile("stp %0, %1, [%2]" + : : "r" (low), "r" (high), + "r" (mbox->regs + mbox->hw->a2i_send0) + : "memory"); + return; + } +#endif + writeq_relaxed(msg.msg0, mbox->regs + mbox->hw->a2i_send0); + writeq_relaxed(high, mbox->regs + mbox->hw->a2i_send1); +} + +static struct apple_mbox_msg apple_mbox_read_msg(struct apple_mbox *mbox) +{ + struct apple_mbox_msg msg; + bool paired = false; + u64 low, high; + +#ifdef CONFIG_ARM64 + if (mbox->hw->counted_fifo) { + asm volatile("ldp %0, %1, [%2]" + : "=&r" (low), "=&r" (high) + : "r" (mbox->regs + mbox->hw->i2a_recv0) + : "memory"); + /* The message words must be read before the buffers they describe. */ + rmb(); + low = le64_to_cpu((__force __le64)low); + high = le64_to_cpu((__force __le64)high); + paired = true; + } +#endif + if (!paired) { + low = readq_relaxed(mbox->regs + mbox->hw->i2a_recv0); + high = readq_relaxed(mbox->regs + mbox->hw->i2a_recv1); + } + msg.msg0 = low; + msg.msg1 = FIELD_GET(APPLE_MBOX_MSG1_MSG, high); + return msg; +} + int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, bool atomic) { @@ -281,11 +347,11 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, } mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); - while (mbox_ctrl & mbox->hw->control_full) { + while (apple_mbox_tx_full(mbox, mbox_ctrl)) { if (atomic || mbox->irq_send_empty < 0) { ret = readl_poll_timeout_atomic( mbox->regs + mbox->hw->a2i_control, mbox_ctrl, - !(mbox_ctrl & mbox->hw->control_full), 100, + !apple_mbox_tx_full(mbox, mbox_ctrl), 100, APPLE_MBOX_TX_TIMEOUT * 1000); if (ret) { @@ -337,9 +403,7 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); } - writeq_relaxed(msg.msg0, mbox->regs + mbox->hw->a2i_send0); - writeq_relaxed(FIELD_PREP(APPLE_MBOX_MSG1_MSG, msg.msg1), - mbox->regs + mbox->hw->a2i_send1); + apple_mbox_write_msg(mbox, msg); spin_unlock_irqrestore(&mbox->tx_lock, flags); @@ -380,11 +444,8 @@ static int apple_mbox_poll_locked(struct apple_mbox *mbox) return 0; mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->i2a_control); - while (!(mbox_ctrl & mbox->hw->control_empty)) { - msg.msg0 = readq_relaxed(mbox->regs + mbox->hw->i2a_recv0); - msg.msg1 = FIELD_GET( - APPLE_MBOX_MSG1_MSG, - readq_relaxed(mbox->regs + mbox->hw->i2a_recv1)); + while (!apple_mbox_rx_empty(mbox, mbox_ctrl)) { + msg = apple_mbox_read_msg(mbox); mbox->rx(mbox, msg, mbox->cookie); ret++; @@ -646,6 +707,8 @@ static int apple_mbox_probe(struct platform_device *pdev) mbox->hw = of_device_get_match_data(dev); if (!mbox->hw) return -EINVAL; + if (mbox->hw->counted_fifo && !IS_ENABLED(CONFIG_ARM64)) + return -EOPNOTSUPP; if (mbox->hw->is_ascwrap_v6) { /* @@ -795,6 +858,28 @@ static const struct apple_mbox_hw apple_mbox_t8015_hw = { .has_irq_controls = false, }; +/* + * T8152 ACIO (USB4) co-processor mailbox: RX at +0, TX at +0x10 and the status + * word at +0x20 of the 0x80-byte window. The status word holds the RX occupancy + * (bits 3:0) and the free TX slots (bits 11:8). The interrupts are not + * controlled per mailbox. + */ +static const struct apple_mbox_hw apple_mbox_t8152_acio_hw = { + .counted_fifo = true, + .control_full = GENMASK(11, 8), + .control_empty = GENMASK(3, 0), + + .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 apple_mbox_hw apple_mbox_asc_hw = { .control_full = APPLE_ASC_MBOX_CONTROL_FULL, .control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY, @@ -890,6 +975,7 @@ static const struct of_device_id apple_mbox_of_match[] = { * kernels without M3 GPU support leave it unbound. */ { .compatible = "apple,t6030-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, + { .compatible = "apple,t8152-acio-mailbox", .data = &apple_mbox_t8152_acio_hw }, { .compatible = "apple,asc-mailbox-v4", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8015-asc-mailbox", .data = &apple_mbox_t8015_hw }, { .compatible = "apple,m3-mailbox-v2", .data = &apple_mbox_m3_hw }, From 94ff26c4c39b3553c839dfb909bf7089f8449623 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:43:27 -0500 Subject: [PATCH 19/32] soc: apple: mailbox: add the T8152 ASCWrap v8 AOP mailbox compatible The always-on processor of the T8152 uses the same counted-FIFO post office window as the ACIO co-processor (receive at +0, transmit at +0x10, status at +0x20 with the receive occupancy and the free transmit slots), as a plain 0x80-byte window without wrapper registers. Match it with the existing hardware description under its own compatible and describe it in the binding: two interrupts, send-empty and recv-not-empty, no IOMMU and no DMA range of its own. MEASURED on an M6 Mac mini: the AOP firmware boots through this mailbox (RTKit protocol version 12 handshake, endpoints discovered, 25 of 25 EPIC calls answered, hours of audio-service use without a message error). NOT measured: sleep. BLOCKED: needs the counted-FIFO mailbox commit it builds on. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../bindings/mailbox/apple,mailbox.yaml | 23 +++++++++++++++++++ drivers/soc/apple/mailbox.c | 1 + 2 files changed, 24 insertions(+) diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8d66dc77c0a54e..d3338461b93a43 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -65,6 +65,11 @@ properties: AOP setup-port mailbox with a separate register layout. const: apple,t8140-aop-setup-mailbox + - description: + T8152 ASCWrap v8 counted-FIFO mailbox, a plain 0x80-byte + post-office window without wrapper registers. + const: apple,t8152-ascwrap-v8-mailbox + - description: An older ASC mailbox interface found on T2 and A11 that is also used for the NVMe coprocessor and the system management @@ -155,6 +160,23 @@ allOf: - const: send-not-empty - const: recv-empty + - if: + properties: + compatible: + contains: + const: apple,t8152-ascwrap-v8-mailbox + then: + properties: + interrupts: + minItems: 2 + maxItems: 2 + interrupt-names: + items: + - const: send-empty + - const: recv-not-empty + iommus: false + apple,dma-range: false + - if: properties: compatible: @@ -164,6 +186,7 @@ allOf: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox - apple,t8140-aop-setup-mailbox + - apple,t8152-ascwrap-v8-mailbox then: properties: interrupts: diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 5203cc52f2f79e..f6a15157cde955 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -976,6 +976,7 @@ static const struct of_device_id apple_mbox_of_match[] = { */ { .compatible = "apple,t6030-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8152-acio-mailbox", .data = &apple_mbox_t8152_acio_hw }, + { .compatible = "apple,t8152-ascwrap-v8-mailbox", .data = &apple_mbox_t8152_acio_hw }, { .compatible = "apple,asc-mailbox-v4", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8015-asc-mailbox", .data = &apple_mbox_t8015_hw }, { .compatible = "apple,m3-mailbox-v2", .data = &apple_mbox_m3_hw }, From 327a8f60d837c0a7895785306797d49351f9e011 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:56:48 -0500 Subject: [PATCH 20/32] dt-bindings: sound: cirrus,cs42l84: add the DAI common properties The codec is a DAI provider and sits on a machine driver's sound card where its controls are named with a prefix (sound-name-prefix), as for the speaker amplifier binding. Reference dai-common.yaml and evaluate the remaining properties through it. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml b/Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml index 7f8338e8ae369b..6cc58569bf9dc1 100644 --- a/Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml +++ b/Documentation/devicetree/bindings/sound/cirrus,cs42l84.yaml @@ -15,6 +15,9 @@ description: | Pro models. It has stereo DAC for playback, mono ADC for capture, and is somewhat similar to CS42L42 but with a different regmap. +allOf: + - $ref: dai-common.yaml# + properties: compatible: enum: @@ -36,7 +39,7 @@ required: - compatible - reg -additionalProperties: false +unevaluatedProperties: false examples: - | From cce84c9fad9901452e77750eaaede0fabdb0f8f0 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:40:48 -0500 Subject: [PATCH 21/32] arm64: dts: apple: t8152-j873g: add the audio I2C codecs Add the two audio codecs of the Mac mini on their I2C buses: the cs42l84 jack codec at 0x4b on i2c1 and the SN012776 speaker amplifier at 0x38 on i2c3, with the controllers' power slots, the 24 MHz reference clock and the SIO pinctrl the codecs' reset and interrupt lines need. This is probe wiring only: the codecs' audio path is the AOP, described by a separate change. MEASURED on an M6 Mac mini with this device tree: i2c1 0x4b binds cs42l84 and i2c3 0x38 binds the SN012776 amplifier (tas2764 driver), both through the I2C controller behind its power slot. NOT measured: the polarity encoding of the reset GPIO flags (taken from the ADT, not verified electrically) and sound. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../boot/dts/apple/t8152-j873g-audio.dtsi | 106 ++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 107 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi new file mode 100644 index 00000000000000..b857e50709b470 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi @@ -0,0 +1,106 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g audio: the 24 MHz reference clock, the SIO pinctrl, the two I2C + * audio codecs and the sound card. + * + * ADT facts: + * i2c1 is at 0x331014000 (AIC 1414, service gate 15) with the child + * audio-codec-output (cs42l84, reg 0x4b, interrupt gpio 203, + * reset gpio 204). + * i2c3 is at 0x33101c000 (AIC 1416, service gate 17) with the child + * audio-speaker (sn012776, reg 0x38, interrupt gpio 193, reset + * gpio 202; speaker-config: one channel, amp gain 15, voltage + * sense slot 0, current sense slot 2). + * Service gates below 170 index the PSD slots: slot 15 = SIO_I2C1, + * slot 17 = SIO_I2C3, window 0x303a10000 + (slot << 8). The I2C PMGR + * devices have no power state register, so the PSD slot is the only + * power step. + */ +#include + +/ { + clkref: clock-ref { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + }; + + soc { + pinctrl_ap: pinctrl@31a000000 { + compatible = "apple,t8152-pinctrl", "apple,t8103-pinctrl"; + reg = <0x3 0x1a000000 0x0 0x100000>; + + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&pinctrl_ap 0 0 224>; + apple,npins = <224>; + + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + ; + }; + + psd_sio_i2c1: power-controller@303a10f00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a10f00 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_sio_i2c1"; + }; + + psd_sio_i2c3: power-controller@303a11100 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a11100 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_sio_i2c3"; + }; + + i2c1: i2c@331014000 { + compatible = "apple,t8103-i2c", "apple,i2c"; + reg = <0x3 0x31014000 0x0 0x4000>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&psd_sio_i2c1>; + #address-cells = <1>; + #size-cells = <0>; + + 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"; + }; + }; + + i2c3: i2c@33101c000 { + compatible = "apple,t8103-i2c", "apple,i2c"; + reg = <0x3 0x3101c000 0x0 0x4000>; + clocks = <&clkref>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&psd_sio_i2c3>; + #address-cells = <1>; + #size-cells = <0>; + + speaker_codec: codec@38 { + compatible = "ti,sn012776"; + reg = <0x38>; + shutdown-gpios = <&pinctrl_ap 202 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 193 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Speaker"; + ti,imon-slot-no = <2>; + ti,vmon-slot-no = <0>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 1515d472cd24ba..2c3efa025e68e4 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -256,3 +256,4 @@ #include "t8152-j873-usb0.dtsi" #include "t8152-j873-drd2.dtsi" #include "t8152-j873-drd1.dtsi" +#include "t8152-j873g-audio.dtsi" From d86085ca5dcaea027611fe40e2ac51fa5c493494 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:56:49 -0500 Subject: [PATCH 22/32] dt-bindings: soc: apple: aop: no power domain on T8152 The T8152 always-on processor is not behind a power domain: every PMGR device of the AOP block and of the audio block is firmware-managed and has no power state register of its own. Require power-domains only for the T8140 and forbid it for the T8152. MEASURED on an M6 Mac mini: the AOP firmware boots and serves audio with an AOP node that has no power domain. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../devicetree/bindings/soc/apple/apple,t8140-aop.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml index 5b2861c1e7c4bc..176a816547fc48 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t8140-aop.yaml @@ -77,12 +77,15 @@ allOf: minItems: 2 mbox-names: minItems: 2 + required: + - power-domains else: properties: mboxes: maxItems: 1 mbox-names: maxItems: 1 + power-domains: false required: - compatible @@ -92,6 +95,5 @@ required: - mbox-names - iommus - apple,dma-range - - power-domains additionalProperties: false From 4b2beadf5d49b05a6d2ef8b704d4f1c4bf12815e Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 22:40:48 -0500 Subject: [PATCH 23/32] arm64: dts: apple: t8152-j873g: add the AOP audio chain Describe the audio path of the Mac mini: the SBR DART shared with firmware (inherited roots, owned streams 0, 1, 40 and 42), the two non-secure audio DMA controllers, the AOP mailbox, the AOP with its audio service (speaker, jack output and jack input, no power domains since all audio PMGR devices are firmware-managed) and the sound card with the headphone jack and speaker links. The card driver keeps the speaker disabled until a speaker-safety profile exists. MEASURED on an M6 Mac mini with this device tree (the DART described by separate compatibles and driver changes of an earlier form of the series): the AOP boots and its audio service attaches the speaker, jack output and jack input devices, the SBR DART is used without a reset, the audio DMA channels run (the jack stream in real time at 48 kHz, the speaker stream in real time as mono at 48 kHz), the jack codec and the speaker amplifier probe on their I2C buses. NOT measured: this exact form with the DART properties, sound at the headset or speaker, capture, suspend. BLOCKED: needs the T8152 DART, ADMAC, mailbox, AOP, audio component and macaudio driver changes of the same series. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- arch/arm64/boot/dts/apple/t8152-j873-aop.dtsi | 45 +++++++++++++ .../boot/dts/apple/t8152-j873-audio-dart.dtsi | 66 +++++++++++++++++++ .../boot/dts/apple/t8152-j873g-audio.dtsi | 37 +++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 2 + 4 files changed, 150 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-aop.dtsi create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-audio-dart.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-aop.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-aop.dtsi new file mode 100644 index 00000000000000..403fa5567f2d18 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-aop.dtsi @@ -0,0 +1,45 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Always-on processor and its audio service. + * + * The AOP firmware is loaded by the bootloader; the CPU is started through + * the ASC wrapper and RTKit boots on the primary mailbox (there is no setup + * port on this SoC). The audio service has three devices: the speaker, the + * 3.5 mm jack output and the jack input. The audio PMGR devices are all + * firmware-managed, so none of these nodes has a power domain. Windows, + * IRQs and stream ids are from the M6 ADT. + */ + +/ { + soc { + aop_mbox: mailbox@310740080 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x10740080 0x0 0x80>; + interrupt-parent = <&aic>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + aop: aop@310c00000 { + compatible = "apple,t8152-aop"; + reg = <0x3 0x10c00000 0x0 0x300000>, + <0x3 0x10600000 0x0 0x4000>; + reg-names = "mmio", "asc"; + mboxes = <&aop_mbox>; + mbox-names = "mbox"; + iommus = <&dart_sbr 0>; + apple,dma-range = /bits/ 64 <0x11000000000 0x1000000000>; + + aop_audio: audio { + compatible = "apple,t8152-aop-audio"; + /* base-ns channels: TX 1 = speaker, TX 5 = jack out, RX 5 = jack in, RX 1 = speaker sense */ + dmas = <&admac_base_ns 2>, <&admac_base_ns 10>, + <&admac_base_ns 11>, <&admac_base_ns 3>; + dma-names = "spkr", "cout", "cin", "spkr-tap"; + #sound-dai-cells = <1>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-audio-dart.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-audio-dart.dtsi new file mode 100644 index 00000000000000..c43ad3cb9debf3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-audio-dart.dtsi @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Audio DMA: the SBR DART and the two non-secure audio DMA controllers. + * + * The SBR DART is shared with firmware: the bootloader leaves its AOP and + * audio-DMA streams translating with page-table roots that hold firmware + * mappings, so it must not be reset (apple,inherited-roots) and only the + * streams Linux uses are ours (apple,owned-streams: 0 = AOP, 1 = the AOP's + * second stream, 40 = leap-ns ADMAC, 42 = base-ns ADMAC). Windows, IRQs, + * tunables and dma-ranges are from the M6 ADT. + */ + +/ { + soc { + dart_sbr: iommu@318100000 { + compatible = "apple,t8152-dart"; + reg = <0x3 0x18100000 0x0 0xc000>, + <0x2 0x00000780 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,inherited-roots; + apple,owned-streams = <0 1 40 42>; + apple,dma-range = /bits/ 64 <0x11000000000 0x2000000000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value); left as firmware set them */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x240 0x01000000 0x00000000>, + <0x244 0x01000000 0x01000000>, + <0x248 0x01000000 0x00000000>, + <0x250 0x01000000 0x00000000>, + <0x254 0x01000000 0x01000000>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + /* base-ns: 13 TX and 13 RX channels (Linux channel 2n = TX n, 2n + 1 = RX n) */ + admac_base_ns: dma-controller@313900000 { + compatible = "apple,t8152-admac"; + reg = <0x3 0x13900000 0x0 0xb4000>; + dma-channels = <26>; + #dma-cells = <1>; + /* four IRQ outputs, only the first is connected */ + interrupts-extended = <&aic AIC_IRQ 640 IRQ_TYPE_LEVEL_HIGH>, + <0>, <0>, <0>; + iommus = <&dart_sbr 42>; + apple,dma-range = /bits/ 64 <0x11000000000 0x1000000000>; + }; + + /* leap-ns: 9 TX and 9 RX channels; no ADT user, kept off */ + admac_leap_ns: dma-controller@313300000 { + compatible = "apple,t8152-admac"; + reg = <0x3 0x13300000 0x0 0xa4000>; + dma-channels = <18>; + #dma-cells = <1>; + interrupts-extended = <&aic AIC_IRQ 643 IRQ_TYPE_LEVEL_HIGH>, + <0>, <0>, <0>; + iommus = <&dart_sbr 40>; + apple,dma-range = /bits/ 64 <0x11000000000 0x1000000000>; + status = "disabled"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi index b857e50709b470..0454e77da37ff5 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi @@ -103,4 +103,41 @@ }; }; }; + + 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>; + }; + }; + + /* + * The speaker stays disabled by the card driver until a + * speaker-safety profile exists for this machine. + */ + dai-link@1 { + reg = <1>; + link-name = "Speaker"; + + cpu { + sound-dai = <&aop_audio 4>; + }; + + codec { + sound-dai = <&speaker_codec>; + }; + }; + }; }; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 2c3efa025e68e4..aec3f54cd27153 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -256,4 +256,6 @@ #include "t8152-j873-usb0.dtsi" #include "t8152-j873-drd2.dtsi" #include "t8152-j873-drd1.dtsi" +#include "t8152-j873-audio-dart.dtsi" +#include "t8152-j873-aop.dtsi" #include "t8152-j873g-audio.dtsi" From 43f266453804e1843362c697c2dc4cec5ee09e5b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sat, 24 Oct 2026 00:29:52 -0500 Subject: [PATCH 24/32] ASoC: apple: t8140-aop-audio: limit the T8152 speaker with a thermal model The T8152 AOP offers no speaker tap, so the speaker-protection daemon that reads the amplifier's current and voltage sense cannot run on the Mac mini. The vendor protects this speaker with a thermal model driven by the signal alone; do the same in the speaker copy path, where no stream can bypass it. Every word, after the playback volume, goes through a fixed-point version of the vendor's model: the power (x * 11.9 V)^2 / 4.6 ohm heats the magnet (60 C/W, 210 s) towards ambient (50 C) and the coil (40 C/W, 3.4 s) towards the magnet, the two filters of the daemon's own model. The gain falls over the last 20 C below the 140 C limit to the level at which a full-scale square wave dissipates 98 % of the sustainable (140 - 50) / (40 + 60) = 0.9 W, which is -15.43 dB. The attack is immediate (one block of 128 words) and the release takes 20 s; the model assumes the amplifier at the vendor's 11.9 V per full scale whatever its gain setting. The speaker cools by the idle time between streams. A hard amplitude ceiling 20 dB below the sustained level (about 9 mW worst case) is built in for the first audible tests and is removed by a rebuild only. MEASURED on the host: the integer model against the closed-form step response of the two filters, a full-scale sine, square, noise and DC step from four starting temperatures stay below 140 C, ten minutes of a full-scale square wave settle at the sustained level with an equilibrium temperature of 139.9 C, the release and the idle cooling follow the model, and the kernel arithmetic (as a plain Rust test crate with overflow checks) reproduces the host model bit for bit. NOT measured: the real speaker (the vendor's resistance, thermal resistances and time constants are used as they are, the amplifier output voltage per full scale is not measured), anything audible on the machine, and the kernel build of this change. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/t8140_aop_audio.rs | 299 ++++++++++++++++++++++++++++- 1 file changed, 294 insertions(+), 5 deletions(-) diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index 8ad9390dd1530d..7c29245cfa1927 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -620,6 +620,9 @@ struct SndSocT8140AopData { /// [`SndSocT8140AopData::lpai_run_get`]. #[pin] lpai_run: Mutex, + /// The T8152 speaker's thermal limiter, see [`spk_thermal`]. + #[pin] + spkr_thermal: SpinLock, } const SPKR_START_WORK: u64 = 0; @@ -2320,7 +2323,7 @@ unsafe extern "C" fn asoc_pcm_hw_params( /// Called by ASoC on this driver's registered component, with live /// arguments belonging to one of its links. unsafe extern "C" fn asoc_pcm_prepare( - _component: *mut bindings::snd_soc_component, + component: *mut bindings::snd_soc_component, substream: *mut bindings::snd_pcm_substream, ) -> i32 { // SAFETY: ASoC hands its ops a live substream whose private data is the @@ -2341,6 +2344,12 @@ unsafe extern "C" fn asoc_pcm_prepare( // trigger START. unsafe { ptr::write_bytes(area, 0, bytes) }; } + // SAFETY: ASoC calls this op on a component whose descriptor/context stays live. + let data = unsafe { component_data(component) }; + if !data.has_lpai { + // The speaker cooled while no stream ran. + data.spkr_thermal.lock().cool_idle(); + } 0 } @@ -2370,6 +2379,177 @@ fn spkr_f32_bits(sample: i32, gain_q31: u32) -> u32 { f32_bits_of_q31(scaled as i32) } +/// Feed-forward thermal limiter of the T8152 speaker. +/// +/// The J873 has no speaker tap: the AOP offers no sense stream, so there is +/// nothing a daemon could measure. The vendor protects this speaker with a +/// thermal model driven by the signal itself, and so does this limiter, in the +/// copy path where no stream can bypass it. The vendor's numbers for the +/// speaker (one type-A speaker for all channels): amplifier sensitivity +/// 11.9 V per full scale, voice-coil resistance 4.6 ohm, coil 40 C/W with a +/// time constant of 3.4 s, magnet 60 C/W with 210 s, ambient 50 C, limit +/// 140 C. The thermal part is the two-filter model of the Linux speaker +/// daemon: the power of every word (x * 11.9 V)^2 / 4.6 ohm, with x the word +/// after the limiter gain in units of the I2S full scale, heats the magnet +/// towards ambient + 60 C/W * P and the coil towards the magnet + 40 C/W * P; +/// the gain falls from 0 dB to the sustained level (a full-scale square wave +/// at 98 % of (140 - 50) / (40 + 60) = 0.9 W, -15.43 dB) over the last 20 C +/// below the limit. Beyond the vendor, the attack is immediate (one block of +/// 128 words) and the release follows the vendor's 20 s, and the amplifier is +/// assumed at the voltage of the full 11.9 V per full scale. All of it is +/// fixed point: no floating point exists in the kernel. `CEILING` is a hard +/// amplitude ceiling in the first audible tests (-20 dB below the sustained +/// level), taken out only by a rebuild. +mod spk_thermal { + // Temperatures are Q40 degrees C, gains Q30, the power in units of + // (I2S full scale)^2 * 2^32. + const KCQ: i64 = 315236; + const KMQ: i64 = 472854; + const AC: i64 = 26317; + const AM: i64 = 426; + const T_AMB_Q: i64 = 54975581388800; + const LO_Q: i64 = 131941395333120; + const WIN_Q: i64 = 21990232555520; + const HYST_Q: i64 = 5497558138880; + const REL: i64 = 572586; + /// 10^(-15.43 dB * k / 64 / 20) in Q30, rounded down. + const GTAB: [i64; 65] = [ + 1073741824, 1044350352, 1015763411, 987958979, 960915636, 934612548, 909029454, 884146644, + 859944950, 836405728, 813510843, 791242658, 769584020, 748518241, 728029096, 708100798, + 688717996, 669865759, 651529563, 633695283, 616349179, 599477889, 583068416, 567108119, + 551584701, 536486206, 521801000, 507517772, 493625518, 480113536, 466971416, 454189035, + 441756545, 429664369, 417903192, 406463952, 395337838, 384516279, 373990937, 363753705, + 353796697, 344112240, 334692876, 325531348, 316620597, 307953760, 299524160, 291325303, + 283350873, 275594726, 268050888, 260713546, 253577050, 246635900, 239884750, 233318399, + 226931788, 220719998, 214678242, 208801867, 203086346, 197527275, 192120373, 186861473, + 181746525, + ]; + /// Start state: the coil just below the start of the limiting window (the + /// driver cannot know how warm the speaker is). + const T_START_COIL_Q: i64 = 130841883705344; + const T_START_MAGNET_Q: i64 = 100495362778726; + /// The hard amplitude ceiling of the first audible tests: -20 dB below the + /// sustained level (a worst-case power of about 9 mW). + pub(super) const CEILING_M20_Q30: i64 = 18174652; + /// No ceiling (unit tests, later steps). + #[allow(dead_code)] + pub(super) const CEILING_0DB_Q30: i64 = 1073741824; + /// 10 ms steps of the idle cooling: 1 - exp(-0.01 s / tau) in Q32. + const AC10: i64 = 12613698; + const AM10: i64 = 204517; + const ONE: i64 = 1 << 30; + + fn gain_for_reduction(r16: i64) -> i64 { + let k = (r16 >> 10) as usize; + let f = r16 & 1023; + if k >= 64 { + return GTAB[64]; + } + GTAB[k] + (((GTAB[k + 1] - GTAB[k]) * f) >> 10) + } + + pub(super) struct SpkThermal { + t_coil: i64, + t_magnet: i64, + hyst_coil: i64, + hyst_magnet: i64, + gain: i64, + ceiling: i64, + last: Option>, + } + + impl SpkThermal { + pub(super) fn new(ceiling: i64) -> Self { + Self { + t_coil: T_START_COIL_Q, + t_magnet: T_START_MAGNET_Q, + hyst_coil: T_START_COIL_Q, + hyst_magnet: T_START_MAGNET_Q, + gain: ONE, + ceiling, + last: None, + } + } + + /// Limit one block of words (the I2S full scale is 2^30), in place, and + /// advance the model by the block. + pub(super) fn block(&mut self, words: &mut [i32]) { + let g = (self.gain * self.ceiling) >> 30; + let (mut tc, mut tm) = (self.t_coil, self.t_magnet); + for w in words.iter_mut() { + let y = (i64::from(*w) * g) >> 30; + let yq = y >> 14; + let pfs = yq * yq; + let tgt_c = tm + pfs * KCQ; + let tgt_m = T_AMB_Q + pfs * KMQ; + tc += (((tgt_c - tc) >> 12) * AC) >> 20; + tm += (((tgt_m - tm) >> 12) * AM) >> 20; + *w = y as i32; + } + self.t_coil = tc; + self.t_magnet = tm; + self.hyst_coil = self.hyst_coil.max(tc).min(tc + HYST_Q); + self.hyst_magnet = self.hyst_magnet.max(tm).min(tm + HYST_Q); + let temp = self.hyst_coil.max(self.hyst_magnet); + let r16 = if temp <= LO_Q { + 0 + } else { + core::cmp::min(65536, ((temp - LO_Q) >> 20) * 65536 / (WIN_Q >> 20)) + }; + let target = gain_for_reduction(r16); + if target < self.gain { + self.gain = target; + } else { + self.gain += ((target - self.gain) * REL) >> 32; + } + self.last = Some(kernel::time::Instant::now()); + } + + /// Let the speaker cool for the time since the last block: the same + /// filters with no power, in steps of 10 ms (at most 20 minutes). + pub(super) fn cool_idle(&mut self) { + let Some(last) = self.last.take() else { + return; + }; + let ms = core::cmp::min(last.elapsed().as_millis(), 20 * 60 * 1000); + self.cool(ms as u64); + } + + pub(super) fn cool(&mut self, ms: u64) { + let (mut tc, mut tm) = (self.t_coil, self.t_magnet); + for _ in 0..ms / 10 { + tc += (((tm - tc) >> 12) * AC10) >> 20; + tm += (((T_AMB_Q - tm) >> 12) * AM10) >> 20; + } + self.t_coil = tc; + self.t_magnet = tm; + self.hyst_coil = tc; + self.hyst_magnet = tm; + } + + /// Unit tests: start from a given state. + #[allow(dead_code)] + pub(super) fn cool_from(&mut self, coil: i64, magnet: i64, ms: u64) { + self.t_coil = coil; + self.t_magnet = magnet; + self.cool(ms); + } + + #[allow(dead_code)] + pub(super) fn state(&self) -> (i64, i64, i64, i64, i64) { + ( + self.t_coil, + self.t_magnet, + self.hyst_coil, + self.hyst_magnet, + self.gain, + ) + } + } +} + +use spk_thermal::SpkThermal; + /// Copy between userspace and the front-end buffers. The speaker front-end /// converts and limits; the jack front-ends copy verbatim (their buffers are /// also mmap-able, this path serves read()/write()). @@ -2442,10 +2622,26 @@ unsafe extern "C" fn asoc_pcm_copy( if iov.copy_from_iter(&mut chunk[..n]) != n { return EFAULT.to_errno(); } - for (i, word) in chunk[..n].chunks_exact(4).enumerate() { - let sample = i32::from_le_bytes([word[0], word[1], word[2], word[3]]); - let bits = spkr_f32_bits(sample, gain); - dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&bits.to_le_bytes()); + if data.has_lpai { + for (i, word) in chunk[..n].chunks_exact(4).enumerate() { + let sample = i32::from_le_bytes([word[0], word[1], word[2], word[3]]); + let bits = spkr_f32_bits(sample, gain); + dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&bits.to_le_bytes()); + } + } else { + // T8152: every word goes through the thermal limiter, the one + // protection this speaker has. + let mut words = [0i32; 128]; + let count = n / 4; + for (w, word) in words.iter_mut().zip(chunk[..n].chunks_exact(4)) { + let sample = i32::from_le_bytes([word[0], word[1], word[2], word[3]]); + *w = ((i64::from(sample) * i64::from(gain)) >> 31) as i32; + } + data.spkr_thermal.lock().block(&mut words[..count]); + for (i, w) in words[..count].iter().enumerate() { + let bits = f32_bits_of_q31(*w); + dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&bits.to_le_bytes()); + } } off += n; } @@ -3426,6 +3622,7 @@ impl platform::Driver for SndSocT8140AopDriver { users: 0, running: false, }), + spkr_thermal <- new_spinlock!(SpkThermal::new(spk_thermal::CEILING_M20_Q30)), }), GFP_KERNEL, )?; @@ -3769,3 +3966,95 @@ mod lid_tests { assert!(lid.mic_cut()); } } + +#[kunit_tests(snd_soc_t8140_aop_audio_thermal)] +mod thermal_tests { + use super::spk_thermal::{SpkThermal, CEILING_0DB_Q30, CEILING_M20_Q30}; + + /// The 100 Hz square wave at the I2S full scale, 240 words per half period. + fn square(i: usize) -> i32 { + if (i / 240) % 2 == 0 { + 0x4000_0000 + } else { + -0x4000_0000 + } + } + + fn run_square(l: &mut SpkThermal, blocks: usize) -> i32 { + let mut words = [0i32; 128]; + let mut peak = 0i32; + for b in 0..blocks { + for (k, w) in words.iter_mut().enumerate() { + *w = square(b * 128 + k); + } + l.block(&mut words); + for w in words.iter() { + peak = peak.max(w.abs()); + } + } + peak + } + + /// The same numbers as the host model of the J873 speaker limiter (ten + /// seconds of a full-scale square wave, then two seconds of silence). + #[test] + fn ten_seconds_of_full_scale_square_match_the_host_model() { + let mut l = SpkThermal::new(CEILING_0DB_Q30); + let peak = run_square(&mut l, 3750); + assert_eq!(peak, 1_073_741_824); + assert_eq!( + l.state(), + ( + 152358436004836, + 102381555896261, + 152358436004836, + 102381555896261, + 206396213 + ) + ); + let silence = [0i32; 128]; + for _ in 0..750 { + let mut w = silence; + l.block(&mut w); + } + assert_eq!( + l.state(), + ( + 130024328395229, + 101932305864922, + 135521886534109, + 102381555896261, + 226457860 + ) + ); + } + + #[test] + fn the_coil_stays_below_the_limit_with_a_full_scale_square() { + let mut l = SpkThermal::new(CEILING_0DB_Q30); + run_square(&mut l, 3750 * 6); + // 140 C in Q40 + assert!(l.state().0 < 140i64 << 40); + } + + #[test] + fn idle_cooling_matches_the_host_model() { + let mut l = SpkThermal::new(CEILING_0DB_Q30); + l.cool_from( + 139i64 << 40, + (50i64 << 40) + (((139i64 - 50) * 60 << 40) / 100), + 60_000, + ); + assert_eq!(l.state().0, 99824966751432); + assert_eq!(l.state().1, 99097783336276); + } + + #[test] + fn the_first_audible_ceiling_is_20_db_below_the_sustained_level() { + let mut l = SpkThermal::new(CEILING_M20_Q30); + let mut w = [0x4000_0000i32; 128]; + l.block(&mut w); + assert_eq!(w[0], 18174652); + assert_eq!(w[127], 18174652); + } +} From 68c6401203afb55e7a60706fbca7c55f57350422 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sat, 24 Oct 2026 20:50:41 -0500 Subject: [PATCH 25/32] ASoC: apple: t8140-aop-audio: give the T8152 speaker plain PCM The speaker copy path converts every sample to a float32 bit pattern, the word format the T8140 speaker DSP consumes. The T8152 has no LPAI: the AOP link hands the words to the amplifier unchanged, so the amplifier played float bit patterns as 32-bit integers. On the T8152, write the limited sample as a signed 32-bit integer instead. The T8140 path is unchanged. MEASURED: with the float words, a 440 Hz tone gave a steady 2.6 s sound whose strongest component was 880 Hz, at the same level for two volume steps 10 dB apart (room microphone, 12 to 18 inches). NOT measured: the sound with this change, and the amplifier output voltage per full scale. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/t8140_aop_audio.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index 7c29245cfa1927..04948fe1107a95 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -2638,9 +2638,10 @@ unsafe extern "C" fn asoc_pcm_copy( *w = ((i64::from(sample) * i64::from(gain)) >> 31) as i32; } data.spkr_thermal.lock().block(&mut words[..count]); + // The amplifier takes plain 32-bit PCM from the AOP link (there is + // no LEAP on this machine to consume float32 words). for (i, w) in words[..count].iter().enumerate() { - let bits = f32_bits_of_q31(*w); - dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&bits.to_le_bytes()); + dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&w.to_le_bytes()); } } off += n; From 444f88a8eff09c01aa345b41654005b57f48307e Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sat, 24 Oct 2026 23:48:30 -0500 Subject: [PATCH 26/32] ASoC: apple: macaudio: give the J873 speaker link a rising RX edge The default serial link format of this card is I2S with an inverted bit clock, which makes the tas2764 driver program its receiver to sample on the falling edge. The SN012776 amplifier on the J873 does not take the AOP's speaker stream that way: it reports a bad TDM clock and stays in software shutdown. Add a platform configuration field for the DAI format of the speaker amplifier's link only and set it for the J873 to the default format with the clock polarity changed (rising RX edge, frame polarity as before). The headphone link and every other machine keep the default format. MEASURED: with the falling edge the amplifier status stays at software shutdown for a 440 Hz tone, and the room microphone (12 to 18 inches) hears nothing. Writing only the receiver edge bit of the amplifier's first TDM register to the rising value, and nothing else, puts it in the active state and the tone is heard 49 dB above the room at 440 Hz; the other four registers tried alone do not. With this change and no register writes from user space, the quietest volume step is 39 dB above the room with harmonics below -29 dB relative to the fundamental, and the step 10 dB up is 7 dB louder with harmonics below -21 dB. NOT measured: the absolute sound level, the amplifier output voltage, the loudest volume step (distorted, unexplained), the "bad TDM clock" report that still appears once when a stream starts. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/macaudio.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index 6cca60354c5f7b..d637c25a02bb53 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -108,6 +108,8 @@ struct macaudio_platform_cfg { const char *fe_dai_names[MACAUDIO_NUM_FE_LINKS]; unsigned int dai_fmt; unsigned int primary_bclk_ratio; + /* DAI format of the speaker amplifier's link only (0: as the others). */ + unsigned int spk_dai_fmt; }; static const char *volume_control_names[] = { @@ -830,6 +832,8 @@ static int macaudio_parse_of(struct macaudio_snd_data *ma) goto err_free; link_props->is_speakers = speakers; + if (speakers && ma->cfg->spk_dai_fmt) + link->dai_fmt = ma->cfg->spk_dai_fmt; link_props->is_headphones = !speakers; link_props->codecs = devm_kcalloc(dev, ncodecs_per_cpu, @@ -1515,6 +1519,12 @@ struct macaudio_platform_cfg macaudio_j873_cfg = { .amp_gain = 15, .safe_vol = -20, .fe_dai_names = { "j700-pcm-0", "j700-pcm-1", "j700-pcm-2" }, + /* + * The amplifier must sample on the rising bit-clock edge here: with + * the default format (falling edge) it stays in software shutdown. + */ + .spk_dai_fmt = SND_SOC_DAIFMT_I2S | SND_SOC_DAIFMT_CBC_CFC | + SND_SOC_DAIFMT_GATED | SND_SOC_DAIFMT_NB_IF, }; static int macaudio_fixup_controls(struct snd_soc_card *card) From 394a04038e948418497e53a628cf3441bd90cd82 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 25 Oct 2026 06:46:55 -0500 Subject: [PATCH 27/32] ASoC: apple: t8140-aop-audio: scale the T8152 speaker words to 24 bits The amplifier on the T8152 takes the samples in the low 24 bits of each 32-bit word of the AOP link: a word beyond 2^23 wraps. The thermal limiter works in units of a 2^30 full scale and the copy path wrote its words unscaled, so the amplifier saw every word 128 times (42 dB) larger than the limiter's model, and a word at the limiter's ceiling was already past the amplifier's full scale. Write the limited word shifted down by seven bits, so that the limiter's full scale is the amplifier's. MEASURED: with the unscaled words, a 440 Hz tone followed the word peak for peaks of 3.0e6, 5.0e6, 7.0e6 and 8.0e6 (30.9, 35.3, 38.3 and 39.7 dB above the room, third harmonic below -38 dB relative to the tone), and at 8.8e6, 9.6e6 and 1.1e7 the tone fell by 10 dB and more with the third harmonic at -4, +6 and -6 dB, the signature of a wrap at 2^23 = 8388608 (room microphone, 12 to 18 inches). NOT measured: the sound with this change, the absolute level, the amplifier output voltage. This does not enable the speaker: it stays disabled in the J873 configuration. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/t8140_aop_audio.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index 04948fe1107a95..b0e6429e05f2d8 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -2638,10 +2638,13 @@ unsafe extern "C" fn asoc_pcm_copy( *w = ((i64::from(sample) * i64::from(gain)) >> 31) as i32; } data.spkr_thermal.lock().block(&mut words[..count]); - // The amplifier takes plain 32-bit PCM from the AOP link (there is - // no LEAP on this machine to consume float32 words). + // The amplifier takes plain PCM from the AOP link (there is no + // LEAP on this machine to consume float32 words), but only the + // low 24 bits of each word: measured, a word beyond 2^23 wraps. + // The limiter's full scale, 2^30, is therefore 2^23 on the wire. for (i, w) in words[..count].iter().enumerate() { - dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&w.to_le_bytes()); + let w24 = *w >> 7; + dst[off + i * 4..off + i * 4 + 4].copy_from_slice(&w24.to_le_bytes()); } } off += n; From 8108707e64f8ba333759e6562cfb573d2fa10832 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:54:55 -0500 Subject: [PATCH 28/32] ASoC: apple: t8140-aop-audio: high-pass the T8152 speaker at 100 Hz The speaker limiter models the power of the speaker, not its cone excursion, which for the same voltage is largest at low frequencies, where the speaker radiates least. Filter the words of the T8152 speaker path with a fixed second-order Butterworth high-pass at 100 Hz (integer, direct form I, Q28 coefficients, 64-bit state), before the limiter, and hold its output to the input's full scale (a step through a high-pass overshoots by up to twice its size), so that the ceiling stays a peak ceiling. The unit tests of the module run the filter on integer sines: the gain at 50, 100, 200 and 440 Hz is 0.2425, 0.7071, 0.9701 and 0.9987 (the ideal Butterworth values, within 0.01), and a constant input is blocked. MEASURED (room microphone, 12 to 18 inches): with the filter in the path and the speaker ceiling of the next commit, a 440 Hz tone is within 1.2 dB of its level without the filter (the repeatability of the setup is 1.9 dB) with its second to fourth harmonics at -33 dB or lower relative to the tone, a 200 Hz tone is within 0.4 dB, and the limiter's gain is unchanged. NOT measured: the attenuation of the filter on the machine (100 and 60 Hz were not played, the speaker's cone excursion is not measured), the absolute level. This does not enable the speaker: it stays disabled in the J873 configuration. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/t8140_aop_audio.rs | 143 ++++++++++++++++++++++++++++- 1 file changed, 140 insertions(+), 3 deletions(-) diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index b0e6429e05f2d8..df5d2858903ec1 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -2348,7 +2348,9 @@ unsafe extern "C" fn asoc_pcm_prepare( let data = unsafe { component_data(component) }; if !data.has_lpai { // The speaker cooled while no stream ran. - data.spkr_thermal.lock().cool_idle(); + let mut thermal = data.spkr_thermal.lock(); + thermal.cool_idle(); + thermal.reset_highpass(); } 0 } @@ -2448,6 +2450,49 @@ mod spk_thermal { GTAB[k] + (((GTAB[k + 1] - GTAB[k]) * f) >> 10) } + // Fixed high-pass of the speaker path: 2nd-order Butterworth, 100 Hz at + // 48 kHz, direct form I, Q28 coefficients, 64-bit state. The speaker + // cone moves far more at low frequencies for the same voltage and the + // power model of the limiter has no excursion term; below 100 Hz the + // speaker radiates almost nothing anyway. The output is held to the + // input's full scale (a step through a high-pass overshoots by up to + // 2x), so the ceiling stays a true peak ceiling. |x| <= 2^31 and the + // coefficients are below 2^29: the sum of five products stays below + // 2^63 (the state, below 2.5 full scales, keeps it under 2^61). + const HP_B0: i64 = 265_962_279; + const HP_B1: i64 = -531_924_558; + const HP_B2: i64 = 265_962_279; + const HP_A1: i64 = -531_901_772; + const HP_A2: i64 = 263_511_889; + const HP_SHIFT: u32 = 28; + const HP_LIMIT: i64 = 1 << 30; + + #[derive(Default)] + pub(super) struct Highpass { + x1: i64, + x2: i64, + y1: i64, + y2: i64, + } + + impl Highpass { + pub(super) fn step(&mut self, x: i32) -> i32 { + let x = i64::from(x); + let acc = HP_B0 * x + HP_B1 * self.x1 + HP_B2 * self.x2 + - HP_A1 * self.y1 + - HP_A2 * self.y2; + // The feedback keeps the unclamped value: feeding the clamped one + // back would latch a nearly full-scale sine into sustained + // clipping. The state stays below 2.5 full scales. + let y = (acc + (1 << (HP_SHIFT - 1))) >> HP_SHIFT; + self.x2 = self.x1; + self.x1 = x; + self.y2 = self.y1; + self.y1 = y; + y.clamp(-HP_LIMIT, HP_LIMIT) as i32 + } + } + pub(super) struct SpkThermal { t_coil: i64, t_magnet: i64, @@ -2455,6 +2500,7 @@ mod spk_thermal { hyst_magnet: i64, gain: i64, ceiling: i64, + hp: Highpass, last: Option>, } @@ -2467,6 +2513,7 @@ mod spk_thermal { hyst_magnet: T_START_MAGNET_Q, gain: ONE, ceiling, + hp: Highpass::default(), last: None, } } @@ -2505,6 +2552,19 @@ mod spk_thermal { self.last = Some(kernel::time::Instant::now()); } + /// Filter one block of words in place with the speaker path's high-pass + /// (before `block`; the filter state carries over from block to block). + pub(super) fn highpass(&mut self, words: &mut [i32]) { + for w in words.iter_mut() { + *w = self.hp.step(*w); + } + } + + /// Start the high-pass from rest (a new stream). + pub(super) fn reset_highpass(&mut self) { + self.hp = Highpass::default(); + } + /// Let the speaker cool for the time since the last block: the same /// filters with no power, in steps of 10 ms (at most 20 minutes). pub(super) fn cool_idle(&mut self) { @@ -2637,7 +2697,11 @@ unsafe extern "C" fn asoc_pcm_copy( let sample = i32::from_le_bytes([word[0], word[1], word[2], word[3]]); *w = ((i64::from(sample) * i64::from(gain)) >> 31) as i32; } - data.spkr_thermal.lock().block(&mut words[..count]); + { + let mut thermal = data.spkr_thermal.lock(); + thermal.highpass(&mut words[..count]); + thermal.block(&mut words[..count]); + } // The amplifier takes plain PCM from the AOP link (there is no // LEAP on this machine to consume float32 words), but only the // low 24 bits of each word: measured, a word beyond 2^23 wraps. @@ -3973,7 +4037,7 @@ mod lid_tests { #[kunit_tests(snd_soc_t8140_aop_audio_thermal)] mod thermal_tests { - use super::spk_thermal::{SpkThermal, CEILING_0DB_Q30, CEILING_M20_Q30}; + use super::spk_thermal::{Highpass, SpkThermal, CEILING_0DB_Q30, CEILING_M20_Q30}; /// The 100 Hz square wave at the I2S full scale, 240 words per half period. fn square(i: usize) -> i32 { @@ -4033,6 +4097,79 @@ mod thermal_tests { ); } + /// Peak of the high-pass output for a sine of peak 2^28 made by an integer + /// oscillator (`next = 2 cos(w) cur - prev`, Q30): `c2` is 2 cos(w) and + /// `s1` the first sample; the peak is taken over the last two periods + /// after the start-up has died out. + fn highpass_peak(c2: i64, s1: i64, period: usize) -> i64 { + let mut hp = Highpass::default(); + let (mut prev, mut cur) = (0i64, s1); + let mut peak = 0i64; + for n in 0..8000usize { + let y = i64::from(hp.step(prev as i32)); + if n >= 8000 - 2 * period { + peak = peak.max(y.abs()); + } + let next = ((c2 * cur) >> 30) - prev; + prev = cur; + cur = next; + } + peak + } + + /// Amplitude relative to the input peak 2^28, in 1/10000: the ideal + /// Butterworth magnitudes are 0.2425, 0.7071, 0.9701 and 0.9987. + fn highpass_gain(c2: i64, s1: i64, period: usize) -> i64 { + highpass_peak(c2, s1, period) * 10_000 / (1 << 28) + } + + #[test] + fn the_highpass_follows_a_100_hz_butterworth() { + // 50, 100, 200 and 440 Hz at 48 kHz + assert!((highpass_gain(2_147_437_652, 1_756_893, 960) - 2_425).abs() <= 100); + assert!((highpass_gain(2_147_299_668, 3_513_712, 480) - 7_071).abs() <= 100); + assert!((highpass_gain(2_146_747_759, 7_026_821, 240) - 9_701).abs() <= 100); + assert!((highpass_gain(2_143_922_726, 15_452_226, 109) - 9_987).abs() <= 100); + } + + #[test] + fn the_highpass_blocks_a_constant_and_holds_full_scale() { + let mut hp = Highpass::default(); + let mut last = 0i32; + for _ in 0..300_000 { + last = hp.step(1 << 20); + } + assert!(i64::from(last).abs() < 1 << 15); + // a full-scale square wave at 120 Hz: the overshoot is held to full scale + let mut hp = Highpass::default(); + let mut peak = 0i32; + for i in 0..40_000usize { + let x = if (i / 200) % 2 == 0 { 1 << 30 } else { -(1 << 30) }; + peak = peak.max(hp.step(x).abs()); + } + assert_eq!(peak, 1 << 30); + } + + /// A full-scale 440 Hz sine (peak 2^30, integer oscillator) through the + /// high-pass: its linear peak is 0.9987 of full scale, so no sample may + /// sit on the clamp (a clamped feedback latched it into clipping). + #[test] + fn a_full_scale_sine_does_not_latch_the_highpass_into_clipping() { + let mut hp = Highpass::default(); + let (mut prev, mut cur) = (0i64, 61_808_904i64); + let mut clamped = 0; + for n in 0..48_000usize { + let y = hp.step(prev as i32); + if n >= 48_000 - 3_000 && y.abs() == 1 << 30 { + clamped += 1; + } + let next = ((2_143_922_726i64 * cur) >> 30) - prev; + prev = cur; + cur = next; + } + assert_eq!(clamped, 0); + } + #[test] fn the_coil_stays_below_the_limit_with_a_full_scale_square() { let mut l = SpkThermal::new(CEILING_0DB_Q30); From df7f942094136b3097a44a8904893a21d1f88046 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:05:28 -0500 Subject: [PATCH 29/32] ASoC: apple: t8140-aop-audio: set the T8152 speaker ceiling The first audible tests ran with the ceiling 20 dB below the speaker's sustained level (4 mW at the amplifier, by the limiter's model). Raise it to 0.078 of full scale: 0.93 V peak and about 94 mW for a sine at an amplifier gain of 15, by the model. A full-scale square wave at this ceiling is 0.19 W against the model's sustained 0.9 W, so the thermal gain never moves and the ceiling is a pure peak limit; a unit test checks that. The level is set from a measurement, not from the model: 6 dB below the level at which the vendor's own driver plays a 440 Hz tone at its maximum volume, settled over 20 s, measured with one microphone at one place. MEASURED (room microphone, 12 to 18 inches, a 440 Hz tone): the vendor's driver at maximum volume is 5.4 dB louder in power than this ceiling (its tone file was 1 dB lower in level than ours; two measurements of the vendor's maximum, taken hours apart, differ by 1.9 dB). 20 s of the tone at this ceiling are steady to 0.1 dB after the first 2 s. Tones of 440, 1000, 2000 and 4000 Hz at the ceiling have their second to fourth harmonics at -34 dB or lower relative to the tone; a 200 Hz tone is detected but its harmonics are below the room noise. NOT measured: the absolute level, the amplifier output voltage, the speaker's cone excursion, content other than tones and one noise burst (the noise burst is 11.9 dB quieter than the vendor's driver at maximum volume). This does not enable the speaker: it stays disabled in the J873 configuration. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- sound/soc/apple/t8140_aop_audio.rs | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/sound/soc/apple/t8140_aop_audio.rs b/sound/soc/apple/t8140_aop_audio.rs index df5d2858903ec1..6a68f04e8094ec 100644 --- a/sound/soc/apple/t8140_aop_audio.rs +++ b/sound/soc/apple/t8140_aop_audio.rs @@ -2431,8 +2431,15 @@ mod spk_thermal { const T_START_COIL_Q: i64 = 130841883705344; const T_START_MAGNET_Q: i64 = 100495362778726; /// The hard amplitude ceiling of the first audible tests: -20 dB below the - /// sustained level (a worst-case power of about 9 mW). + /// sustained level (a worst-case power of about 9 mW); kept for the unit + /// tests of the model. + #[allow(dead_code)] pub(super) const CEILING_M20_Q30: i64 = 18174652; + /// The ceiling of the speaker path: 0.078 of full scale (0.93 V peak and + /// about 94 mW for a sine at an amplifier gain of 15, by this model), 6 dB + /// below the level at which the vendor's own driver plays a 440 Hz tone at + /// its maximum volume, measured with one microphone at one place. + pub(super) const CEILING_Q30: i64 = 83_800_000; /// No ceiling (unit tests, later steps). #[allow(dead_code)] pub(super) const CEILING_0DB_Q30: i64 = 1073741824; @@ -3690,7 +3697,7 @@ impl platform::Driver for SndSocT8140AopDriver { users: 0, running: false, }), - spkr_thermal <- new_spinlock!(SpkThermal::new(spk_thermal::CEILING_M20_Q30)), + spkr_thermal <- new_spinlock!(SpkThermal::new(spk_thermal::CEILING_Q30)), }), GFP_KERNEL, )?; @@ -4037,7 +4044,7 @@ mod lid_tests { #[kunit_tests(snd_soc_t8140_aop_audio_thermal)] mod thermal_tests { - use super::spk_thermal::{Highpass, SpkThermal, CEILING_0DB_Q30, CEILING_M20_Q30}; + use super::spk_thermal::{Highpass, SpkThermal, CEILING_0DB_Q30, CEILING_M20_Q30, CEILING_Q30}; /// The 100 Hz square wave at the I2S full scale, 240 words per half period. fn square(i: usize) -> i32 { @@ -4178,6 +4185,17 @@ mod thermal_tests { assert!(l.state().0 < 140i64 << 40); } + /// At the speaker ceiling a full-scale square wave stays far below the + /// sustained power (0.19 W against 0.9 W at 11.9 V per full scale): the + /// thermal gain never moves, the ceiling is a pure peak limit. + #[test] + fn the_speaker_ceiling_is_a_peak_limit_below_the_sustained_level() { + let mut l = SpkThermal::new(CEILING_Q30); + let peak = run_square(&mut l, 3750 * 3); + assert_eq!(i64::from(peak), CEILING_Q30); + assert_eq!(l.state().4, 1 << 30); + } + #[test] fn idle_cooling_matches_the_host_model() { let mut l = SpkThermal::new(CEILING_0DB_Q30); From e9d9aa02db43eb86445be8bfa77cf348c182010b Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Sun, 25 Oct 2026 11:54:56 -0500 Subject: [PATCH 30/32] ASoC: apple: macaudio: enable the J873 speaker The speaker of the J873 was left disabled until its path was verified on hardware. It now plays: the amplifier takes the serial data on the rising bit-clock edge, the words are scaled to its 24 bits, and the speaker path has a ceiling set against the vendor's own maximum volume, a fixed 100 Hz high-pass and a thermal model of the speaker. The speaker is protected by that limiter, not by a user-space daemon (the machine offers no sense stream for one): set safe_vol to 0, so the volume lock for such a daemon is not created and the amplifier's volume is not held at its lowest step. MEASURED (room microphone, 12 to 18 inches): tones of 200 Hz and of 440 to 4000 Hz play at the ceiling with the second to fourth harmonics of the 440 to 4000 Hz tones at -33 dB or lower relative to the tone; a 20 s tone at the ceiling is steady to 0.1 dB; the ceiling is 5.4 dB below the vendor's own driver at its maximum volume for a 440 Hz tone and 11.9 dB below it for a noise burst. NOT measured: the absolute level, the amplifier output voltage, the speaker's cone excursion at low frequencies (nothing below 200 Hz was played at the ceiling), music. The amplifier reports a bad TDM clock once at the start of each stream and plays on; that is not understood further. Not needed for the release candidate. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../boot/dts/apple/t8152-j873g-audio.dtsi | 5 +++-- sound/soc/apple/macaudio.c | 18 ++++++++++-------- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi index 0454e77da37ff5..0e1eb741d362cb 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873g-audio.dtsi @@ -124,8 +124,9 @@ }; /* - * The speaker stays disabled by the card driver until a - * speaker-safety profile exists for this machine. + * The speaker is protected by the limiter of the AOP audio + * component (ceiling, high-pass and a thermal model), not by a + * user-space daemon: the machine has no sense stream for one. */ dai-link@1 { reg = <1>; diff --git a/sound/soc/apple/macaudio.c b/sound/soc/apple/macaudio.c index d637c25a02bb53..5ff40333e03f30 100644 --- a/sound/soc/apple/macaudio.c +++ b/sound/soc/apple/macaudio.c @@ -1504,20 +1504,22 @@ static int macaudio_set_speaker(struct snd_soc_card *card, const char *prefix, b /* * J873 (Mac mini, T8152): AOP-fed like the J700, but the speaker amplifier is - * an SN012776 on the AP's I2C bus and needs no software gain. The speakers - * stay disabled until the speaker path is verified on hardware (the amplifier - * model and the speaker count are not confirmed); the jack works first. The - * front-end DAIs are those of the AOP audio component, which keeps the - * T8140 names. The serial link format is the macaudio default until the - * firmware's stream-format property has been read on this machine. + * an SN012776 on the AP's I2C bus and needs no software gain. The speaker + * is protected by the limiter in the AOP audio component (a ceiling, a + * fixed high-pass and a thermal model of the speaker in the copy path), + * not by a user-space daemon: the machine has no sense stream for one, so + * there is no volume lock to hand over (safe_vol = 0). The front-end DAIs + * are those of the AOP audio component, which keeps the T8140 names. The + * serial link format of the speaker is set below; the jack keeps the + * default. */ struct macaudio_platform_cfg macaudio_j873_cfg = { - .enable_speakers = false, + .enable_speakers = true, .amp = AMP_SN012776, .speakers = SPKR_1W, .stereo = false, .amp_gain = 15, - .safe_vol = -20, + .safe_vol = 0, .fe_dai_names = { "j700-pcm-0", "j700-pcm-1", "j700-pcm-2" }, /* * The amplifier must sample on the rising bit-clock edge here: with From c4fb78e1cb08e77421d8fb68106941831abfeb20 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:52:58 -0600 Subject: [PATCH 31/32] usb: dwc3: apple: use raw core register access for the T8152 sequence The io.h dwc3_readl()/dwc3_writel() helpers reference the dwc3 tracepoints, which the dwc3 core module never exports, so dwc3-apple.ko failed MODPOST in the omarchy-pkgs package build: ERROR: modpost: "__tracepoint_dwc3_readl" [drivers/usb/dwc3/dwc3-apple.ko] undefined! Read and write the 0xc680 window with plain readl()/writel() on the core mapping, like the raw pipe-handler access in the same function. --- drivers/usb/dwc3/dwc3-apple.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 55e9a49a4e23d7..e10436a84e742e 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -21,7 +21,6 @@ #include "dwc3-apple-state.h" #include "glue.h" -#include "io.h" /* * This platform requires a very specific sequence of operations to bring up dwc3 and its USB3 PHY: @@ -319,10 +318,11 @@ static void dwc3_apple_t8152_apply_tunables(struct dwc3_apple *appledwc, return; writel(readl(pipe + 0x20) | BIT(15), pipe + 0x20); - value = dwc3_readl(&appledwc->dwc, 0xc680); - dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); - value = dwc3_readl(&appledwc->dwc, 0xc680); - dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); + /* Raw core access; io.h helpers drag unexported dwc3 tracepoints into this module. */ + value = readl(appledwc->dwc.regs - DWC3_GLOBALS_REGS_START + 0xc680); + writel(value & ~BIT(13), appledwc->dwc.regs - DWC3_GLOBALS_REGS_START + 0xc680); + value = readl(appledwc->dwc.regs - DWC3_GLOBALS_REGS_START + 0xc680); + writel(value & ~BIT(13), appledwc->dwc.regs - DWC3_GLOBALS_REGS_START + 0xc680); } static void dwc3_apple_set_ptrcap(struct dwc3_apple *appledwc, u32 mode) From 03944898ed6b3b21a10a66da32ffe990e25a5164 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Wed, 4 Nov 2026 15:53:02 -0600 Subject: [PATCH 32/32] selftests: apple-dcp: track the T8152 fixed role in the dwc3 fixture dwc3_apple_core_start() and dwc3_usb_role_switch_set() now reference the T8152_PIPE_* defines and the t8152_usb2, fixed_peripheral and tunable_regs members, so the dwc3-teardown host unit stopped compiling (TAP case 31, 'not ok 31 - dwc3-teardown' in CI). Mirror the defines and extend the fixture struct; the new fields stay false, leaving fixture behavior unchanged. The dwc3-teardown unit compiles and passes with cc -fsanitize=address,undefined on the host. --- .../selftests/drivers/gpu/apple-dcp/dwc3/mocks.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 10d238b9220a49..02f4294408a761 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -63,6 +63,13 @@ static void regulator_disable(int p) { assert(!p); } +/* Mirrors the pipe-handler window defines in dwc3-apple.c for the fixed T8152 role. */ +#define T8152_PIPE_MUX_CTRL 0x0c +#define T8152_PIPE_AON_GEN 0x1c +#define T8152_PIPE_NONSELECTED_OVERRIDE 0x20 +#define T8152_PIPE_MUX_CTRL_DUMMY 0x22 +#define T8152_PIPE_AON_GEN_DWC3_RESET_N BIT(0) +#define T8152_PIPE_NONSELECTED_DEVICE 0x9332 struct dwc3 { struct phy *usb2_generic_phy[3], *usb3_generic_phy[3]; int num_usb2_ports, num_usb3_ports, usb2_phy, usb3_phy; @@ -76,8 +83,10 @@ struct dwc3_apple { int lock; void *dev; struct phy *usb2_phy, *usb3_phy; - bool fixed_hub, core_active, core_exit_pending, reset_pending; + bool fixed_hub, t8152_usb2, fixed_peripheral; + bool core_active, core_exit_pending, reset_pending; unsigned long usb2_power_off_pending, usb3_power_off_pending; + void __iomem *tunable_regs[6]; }; static unsigned int polls, fail_poll, reset_calls, reset_writes, core_writes; static unsigned int host_exits, clocks_disabled, callback_calls;