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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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/12] 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 27da41f2bbb7fd294dc99c33cf4f4b34c499e0e0 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 09:24:39 -0500 Subject: [PATCH 11/12] dt-bindings: spi: apple,qspi: Allow the T8152 compatible The T8152 boot NOR controller is the same QSPIMC block as the T8140 one. Add apple,t8152-qspi as a more specific compatible that falls back to apple,t8140-qspi, so a T8152 device tree describes the controller without the driver needing a new match entry. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- Documentation/devicetree/bindings/spi/apple,qspi.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/spi/apple,qspi.yaml b/Documentation/devicetree/bindings/spi/apple,qspi.yaml index 4d33549e7bf396..e5db9ecd172752 100644 --- a/Documentation/devicetree/bindings/spi/apple,qspi.yaml +++ b/Documentation/devicetree/bindings/spi/apple,qspi.yaml @@ -19,7 +19,11 @@ allOf: properties: compatible: - const: apple,t8140-qspi + oneOf: + - const: apple,t8140-qspi + - items: + - const: apple,t8152-qspi + - const: apple,t8140-qspi reg: maxItems: 1 From ecad670dc3a3f2279e6c5cc8a6e6b1c0d1e23143 Mon Sep 17 00:00:00 2001 From: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> Date: Fri, 23 Oct 2026 09:24:40 -0500 Subject: [PATCH 12/12] arm64: dts: apple: t8152-j873g: Add the boot NOR controller Describe the QSPIMC controller that serves the boot NOR of the Mac mini, with the nvram partition that the driver lets programs and erases through, and the sio -> spi_p -> qspi chain of power domains that it needs. The register address is the CPU physical address (the boot firmware lists it relative to /arm-io, which is mapped at 0x200000000). Power state at boot, read from the PMGR registers: sio (0x840) is on, spi_p (0xd40) and qspi (0x1140) are off. sio is marked always-on like the other domains of this board, so gating it cannot take down other peripherals. spi_p and qspi are not always-on: attaching the controller to its power domain powers the chain before the driver probes (the driver has no runtime PM call of its own). The nvram partition is [0x24000, 0xf4000). A read of the NOR through the controller at 0x24000 returns the boot variables from the first byte, and the last used byte of the store lies inside the 0xd0000 bytes of the window. The fallback compatible lets the driver program and erase inside this window, so the node limits what a write can reach. Signed-off-by: Joshua Warren <816217+joshuaswarren@users.noreply.github.com> --- .../arm64/boot/dts/apple/t8152-j873-qspi.dtsi | 84 +++++++++++++++++++ arch/arm64/boot/dts/apple/t8152-j873g.dts | 1 + 2 files changed, 85 insertions(+) create mode 100644 arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi diff --git a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi new file mode 100644 index 00000000000000..36aa464f9c7398 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Boot NOR of the Apple Mac mini (M6), J873g, behind the QSPIMC controller. + * + * The register address is the CPU physical address: the device tree of the boot firmware lists the controller + * at 0x131118000 relative to /arm-io, and /arm-io is mapped at 0x200000000. The only part of the NOR the driver + * lets programs and erases through is the "nvram" partition (the boot variables). A read of the NOR through + * the controller at its offset (0x24000) returns the boot variables from the first byte, and the last used + * byte of the store lies inside its size (0xd0000). + * + * The controller sits behind a chain of power domains: qspi needs spi_p, and spi_p needs sio. At boot the + * firmware leaves sio on and spi_p and qspi off (power state registers 0xd40 and 0x1140 read target 0, actual + * 0). sio is therefore always-on, like the other domains in t8152-j873-pmgr.dtsi, so that gating it cannot take + * down anything else. spi_p and qspi are not always-on: attaching the controller to its power domain powers + * the chain before the driver probes. The driver makes no runtime PM call of its own. + */ + +/ { + clk_200m: clock-200m { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <200000000>; + clock-output-names = "clk_200m"; + }; + + soc { + qspi: spi@331118000 { + compatible = "apple,t8152-qspi", "apple,t8140-qspi"; + reg = <0x3 0x31118000 0x0 0x4800>; + clocks = <&clk_200m>; + power-domains = <&ps_qspi>; + interrupt-parent = <&aic>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + spi-max-frequency = <25000000>; + + partitions { + compatible = "fixed-partitions"; + #address-cells = <1>; + #size-cells = <1>; + + partition@24000 { + label = "nvram"; + reg = <0x24000 0xd0000>; + }; + }; + }; + }; + }; +}; + +&pmgr0 { + ps_sio: power-controller@840 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x840 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "sio"; + apple,always-on; + }; + + ps_spi_p: power-controller@d40 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xd40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi_p"; + power-domains = <&ps_sio>; + }; + + ps_qspi: power-controller@1140 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "qspi"; + power-domains = <&ps_spi_p>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 1515d472cd24ba..c14c93f2a5b3c6 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -250,6 +250,7 @@ #include "t8152-j873g-peripherals.dtsi" #include "t8152-j873-pmgr.dtsi" +#include "t8152-j873-qspi.dtsi" #include "t8152-j873-usb2-dart.dtsi" #include "t8152-j873-usb2.dtsi" #include "t8152-j873-usb0-dart.dtsi"