From 965e5b366b7efe602d5bbe50f81efcacd32a0e8d Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:12 -0500 Subject: [PATCH 01/19] dt-bindings: pci: apple,pcie: allow T6030 sleep PHY and clock register blocks Allow the optional phy-shared, phy-ip, clkgen, axi2af, cio3pll, phy-common, and port/phy/intr2axi register windows on Apple PCIe host nodes so the T6030 sleep provider can map them by name from DT. Signed-off-by: Diljit Singh --- .../devicetree/bindings/pci/apple,pcie.yaml | 70 ++++++++++++++----- 1 file changed, 51 insertions(+), 19 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 79bd0d648cd80..11f021c1383f1 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -740,12 +740,12 @@ allOf: properties: compatible: contains: - const: apple,t6041-pcie + const: apple,t6030-pcie then: properties: reg: minItems: 10 - maxItems: 15 + maxItems: 18 reg-names: minItems: 10 items: @@ -762,25 +762,57 @@ allOf: - const: axi2af - const: cio3pll - const: clkgen - - const: phy-block + - const: phy-common + - const: phy-shared - const: phy-ip + - const: intr2axi0 + - const: intr2axi1 else: - properties: - reg: - maxItems: 10 - reg-names: - minItems: 3 - items: - - const: config - - const: rc - - const: port0 - - const: port1 - - const: port2 - - const: port3 - - const: phy0 - - const: phy1 - - const: phy2 - - const: phy3 + if: + properties: + compatible: + contains: + const: apple,t6041-pcie + then: + properties: + reg: + minItems: 10 + maxItems: 15 + reg-names: + minItems: 10 + items: + - const: config + - const: rc + - const: port0 + - const: port1 + - const: port2 + - const: port3 + - const: phy0 + - const: phy1 + - const: phy2 + - const: phy3 + - const: axi2af + - const: cio3pll + - const: clkgen + - const: phy-block + - const: phy-ip + else: + properties: + reg: + maxItems: 10 + reg-names: + minItems: 3 + items: + - const: config + - const: rc + - const: port0 + - const: port1 + - const: port2 + - const: port3 + - const: phy0 + - const: phy1 + - const: phy2 + - const: phy3 patternProperties: "^pci@": properties: From 6ef9f5f938140163a4b06190683deb55e7af67b9 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:13 -0500 Subject: [PATCH 02/19] dt-bindings: soc: apple: add T6030 sleep controller binding Add the Devicetree schema for the Apple T6030 (M3 Pro) system suspend-to-RAM controller, including its 33 register windows, phandle links, wake sources, SMC sleep policy timing, and register sequence opcodes (including explicit slc-off and clear64-way opcodes). Signed-off-by: Diljit Singh --- .../bindings/soc/apple/apple,t6030-sleep.yaml | 207 ++++++++++++++++++ 1 file changed, 207 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml new file mode 100644 index 0000000000000..faa9a56a8be41 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml @@ -0,0 +1,207 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/apple/apple,t6030-sleep.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T6030 firmware suspend controller + +maintainers: + - Diljit Singh + +description: + Power manager, memory controller, CPU and wake register windows used for + firmware suspend on the Apple T6030 SoC. + +properties: + compatible: + const: apple,t6030-sleep + + reg: + minItems: 33 + maxItems: 34 + + reg-names: + minItems: 33 + items: + - const: ps + - const: pwrgate + - const: cpu-start + - const: cllt + - const: cluster + - const: commit + - const: wdt + - const: wake + - const: spmi + - const: ps-aon + - const: spmi-a0 + - const: clk-mux + - const: clk-perf + - const: ps-gpu + - const: amcc0 + - const: amcc1 + - const: dcs0 + - const: ptd + - const: cpm-e + - const: cpm-p + - const: amcc0-mc + - const: amcc1-mc + - const: dcs0-ch1 + - const: dcs0-ch2 + - const: dcs0-ch3 + - const: dcs0-ch4 + - const: dcs0-ch5 + - const: dcs1-ch0 + - const: dcs1-ch1 + - const: dcs1-ch2 + - const: dcs1-ch3 + - const: dcs1-ch4 + - const: dcs1-ch5 + - const: pmp-mbox + + apple,display-coprocessors: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + maxItems: 1 + maxItems: 3 + description: Internal and external display coprocessors in display order. + + apple,display-darts: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + maxItems: 1 + maxItems: 3 + description: Display IOMMU instances quiesced at display power-down. + + apple,pcie-host: + $ref: /schemas/types.yaml#/definitions/phandle + description: General-purpose PCIe host parked and restored across sleep. + + apple,pcie-darts: + $ref: /schemas/types.yaml#/definitions/phandle-array + items: + maxItems: 1 + maxItems: 4 + description: General-purpose PCIe port IOMMU instances quiesced before sleep. + + apple,pinctrl: + $ref: /schemas/types.yaml#/definitions/phandle + description: AP pin controller whose state is lost in firmware sleep. + + apple,sep-dart: + $ref: /schemas/types.yaml#/definitions/phandle + description: SEP IOMMU quiesced before requesting SEP sleep. + + apple,mtp-dart: + $ref: /schemas/types.yaml#/definitions/phandle + description: MTP IOMMU quiesced after SMC AP idle acknowledgment. + + apple,debug-port: + $ref: /schemas/types.yaml#/definitions/phandle + description: USB-PD controller connected to the sleep debug port. + + apple,wake-enable: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 32 + description: AP wake-source indices enabled by the board description. + + apple,smc-sleep-policy: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 6 + maxItems: 6 + description: + The SMC pmVC value, followed by the delays in microseconds from the + sleep warning to pmVC, pmVC to SLPA, SLPA to AP idle, AP idle to the + sleep timer, and the wake notice to pmVC. + +patternProperties: + "^apple,seq-(prepare|notice|commit|wake-early|wake)$": + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + minItems: 4 + maxItems: 4 + description: | + Ordered register operations. Each four-cell entry is + : + - opcode bits 7:0: operation kind (0 write32, 1 read32, 2 set32, + 3 clear32, 4 rewrite32, 5 wait-set32, 6 wait-clear32, 7 write16, + 8 write64-hi, 9 clear64, 10 set64, 11 read64, 12 restore32, + 13 restore64, 14 if-saved32, 15 if-saved64, 16 slc-off, + 17 clear64-way). slc-off takes zero block, offset, and operand + and disables the system-level cache via multicast registers. + clear64-way clears one bit of a 64-bit AMCC way-mask register + and reads the matching way status register at offset + 0x1000 + + 8 * bit before and after. + - opcode bit 8: optional flag (for wait operations, ignore timeout). + - opcode bits 15:9: reserved, must be zero. + - opcode bits 31:16: timeout in milliseconds for wait operations + (0 defaults to 10 ms), or number of following entries guarded by + if-saved32/if-saved64. + - block: zero-based index into reg/reg-names. + - offset: naturally aligned byte offset within the register window. + - operand: write value, bitmask, or 0 for read/restore operations. + +required: + - compatible + - reg + - reg-names + - apple,wake-enable + - apple,smc-sleep-policy + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + sleep-controller@350700000 { + compatible = "apple,t6030-sleep"; + reg = <0x3 0x50700000 0x0 0x18000>, + <0x3 0x50724000 0x0 0x4000>, + <0x3 0x50734000 0x0 0x10>, + <0x3 0x50768000 0x0 0x40>, + <0x3 0x50780000 0x0 0x8>, + <0x3 0x642d4000 0x0 0x4>, + <0x3 0x642b0000 0x0 0x30>, + <0x3 0x64004000 0x0 0x48>, + <0x3 0x64714000 0x0 0x100>, + <0x3 0x64280000 0x0 0x4000>, + <0x3 0x64908000 0x0 0x100>, + <0x3 0x50040000 0x0 0x60>, + <0x3 0x5005c000 0x0 0x4>, + <0x2 0x90e80000 0x0 0x18000>, + <0x2 0x20000000 0x0 0xc0000>, + <0x2 0x22000000 0x0 0xc0000>, + <0x2 0x20400000 0x0 0x4000>, + <0x3 0x503c0000 0x0 0x20000>, + <0x2 0x10e40000 0x0 0xc000>, + <0x2 0x11e40000 0x0 0xc000>, + <0x2 0x201c1c00 0x0 0x4>, + <0x2 0x221c1c00 0x0 0x4>, + <0x2 0x20600000 0x0 0x1000>, + <0x2 0x20800000 0x0 0x1000>, + <0x2 0x20a00000 0x0 0x1000>, + <0x2 0x20c00000 0x0 0x1000>, + <0x2 0x20e00000 0x0 0x1000>, + <0x2 0x22400000 0x0 0x1000>, + <0x2 0x22600000 0x0 0x1000>, + <0x2 0x22800000 0x0 0x1000>, + <0x2 0x22a00000 0x0 0x1000>, + <0x2 0x22c00000 0x0 0x1000>, + <0x2 0x22e00000 0x0 0x1000>, + <0x3 0x50c08000 0x0 0x4000>; + reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", + "commit", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", + "clk-mux", "clk-perf", "ps-gpu", "amcc0", "amcc1", + "dcs0", "ptd", "cpm-e", "cpm-p", "amcc0-mc", "amcc1-mc", + "dcs0-ch1", "dcs0-ch2", "dcs0-ch3", "dcs0-ch4", + "dcs0-ch5", "dcs1-ch0", "dcs1-ch1", "dcs1-ch2", + "dcs1-ch3", "dcs1-ch4", "dcs1-ch5", "pmp-mbox"; + apple,wake-enable = <3 51 132 190 214>; + apple,smc-sleep-policy = <0x100 286300 4446000 560 9510 0>; + apple,seq-prepare = <8 17 0x10900 0x20000000>; + }; + }; From b1bb53942bd7134aa0a85422ad5f4871753fb7f3 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:14 -0500 Subject: [PATCH 03/19] spmi: apple: preserve masked pending interrupts on T6030 Add T6030 match data enabling keep_pending so masked SPMI sources owned by the T6030 firmware sleep path are not acknowledged away at probe or during unrelated IRQ handling. Bound consecutive unhandled held interrupts across all IRQ words including the notification word to prevent an interrupt storm if a masked bit ever asserts the parent line. Signed-off-by: Diljit Singh --- drivers/spmi/spmi-apple-controller.c | 65 ++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 4 deletions(-) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 0db33aa91ae61..40cf126117f0e 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -77,6 +77,7 @@ struct apple_spmi_hw { u32 num_irqs; u32 irq_mask; u32 irq_ack; + bool keep_pending; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -90,6 +91,19 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; +/* M3 Pro (T6030): preserve masked pending sources owned by firmware sleep */ +static const struct apple_spmi_hw apple_spmi_t6030 = { + .status = SPMI_STATUS_REG, + .command = SPMI_CMD_REG, + .reply = SPMI_RSP_REG, + .rx_empty = SPMI_RX_FIFO_EMPTY, + .legacy_irqs = true, + .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, + .keep_pending = true, +}; + /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ static const struct apple_spmi_hw apple_spmi_t6000 = { .status = SPMI_STATUS_REG, @@ -130,6 +144,7 @@ struct apple_spmi { bool notify_irq; bool notify_parked; bool prev_fail; + unsigned int held_spurious; }; static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) @@ -531,8 +546,16 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) handled = true; } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ - if (val & ~BIT(notify % 32)) { - writel(val & ~BIT(notify % 32), spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); + val &= ~BIT(notify % 32); + if (val && spmi->hw->keep_pending) { + u32 enabled = readl(spmi->regs + spmi->hw->irq_mask + (notify / 32) * 4); + + /* The sleep driver can enable controller sources outside this driver. */ + held |= !!(val & ~enabled); + val &= enabled; + } + if (val) { + writel(val, spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); handled = true; } @@ -549,6 +572,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; + if (stray && spmi->hw->keep_pending) { + void __iomem *mask = spmi->regs + spmi->hw->irq_mask + offset; + u64 enabled = readl(mask); + + enabled |= (u64)readl(mask + 4) << 32; + held |= !!(stray & ~enabled); + stray &= enabled; + } if (stray) { writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); @@ -574,8 +605,30 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * Keep the diagnostic for unclassified nonempty samples, including a * mask transition; an empty parent needs no invented controller ACK. */ - if (!handled && !held && raw_pending) + if (handled) { + spmi->held_spurious = 0; + } else if (held && spmi->hw->keep_pending) { + /* + * Masked pending bits should not re-assert the parent IRQ; if they + * ever do, bound retries and ack stuck masked bits to prevent a storm. + */ + if (++spmi->held_spurious >= 8) { + dev_warn_once(spmi->dev, + "stuck masked pending SPMI interrupt; acknowledging\n"); + for (offset = 0; offset <= (notify / 32) * 4; offset += 4) { + u32 pend = readl(spmi->regs + spmi->hw->irq_ack + offset); + u32 mask = readl(spmi->regs + spmi->hw->irq_mask + offset); + u32 stuck = pend & ~mask; + + if (stuck) + writel(stuck, spmi->regs + spmi->hw->irq_ack + offset); + } + spmi->held_spurious = 0; + handled = true; + } + } else if (!held && raw_pending) { handle_bad_irq(desc); + } /* * The acks are posted writes: let them reach the controller before the parent is * unmasked, or it fires again for what was just cleared. @@ -613,8 +666,11 @@ static int apple_spmi_init_irq(struct platform_device *pdev, for (size_t offset = 0; offset < spmi->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); offset += 4) { writel(0, spmi->regs + spmi->hw->irq_mask + offset); - writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); + if (!spmi->hw->keep_pending) + writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } + if (spmi->hw->keep_pending) + apple_spmi_irq_ack_raw(spmi, spmi->num_irqs); spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); if (IS_ERR(spmi->irqd)) @@ -795,6 +851,7 @@ static int apple_spmi_probe(struct platform_device *pdev) static const struct of_device_id apple_spmi_match_table[] = { { .compatible = "apple,t8142-spmi", .data = &apple_spmi_gen4 }, + { .compatible = "apple,t6030-spmi", .data = &apple_spmi_t6030 }, { .compatible = "apple,t8103-spmi", .data = &apple_spmi_gen1 }, { .compatible = "apple,t6000-spmi", .data = &apple_spmi_t6000 }, { .compatible = "apple,spmi", .data = &apple_spmi_gen1 }, From a1b0a90f09e8cbbecc3055b06d451dc990e9bb62 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:15 -0500 Subject: [PATCH 04/19] phy: apple: atc: mark T6030 common power domain dropped across deep sleep T6030 powers down ATC common domains during deep sleep, so set common_pd_dropped in the T6030 PHY match data so the PHY driver reinitializes its common block on wake. Signed-off-by: Diljit Singh --- drivers/phy/apple/atc.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 769317ba9d9c6..a094c426810b6 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -9620,6 +9620,21 @@ static const struct atcphy_hw atcphy_hw_t8122 = { .restore_after_pd_off = true, }; +static const struct atcphy_hw atcphy_hw_t6030 = { + .gen = ATCPHY_GENERATION_T8122, + .aciophy_lane_mode = ACIOPHY_LANE_MODE_T8122, + .aciophy_crossbar = ACIOPHY_CROSSBAR_T8122, + .configure_post_tunable = atcphy_configure_post_tunable_t8122, + .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8103, + .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8103, + .has_usb4 = true, + .dp_t8122 = true, + .park_pipe_unlocked = true, + .park_dummy_phy = true, + .restore_after_pd_off = true, + .sleep_drops_common = true, +}; + static const struct atcphy_hw atcphy_hw_t8132 = { .gen = ATCPHY_GENERATION_T8132, .usb2_only = true, @@ -9701,6 +9716,7 @@ static const struct atcphy_hw atcphy_hw_t8152 = { static const struct of_device_id atcphy_match[] = { { .compatible = "apple,t8103-atcphy", .data = &atcphy_hw_t8103 }, + { .compatible = "apple,t6030-atcphy", .data = &atcphy_hw_t6030 }, { .compatible = "apple,t8122-atcphy", .data = &atcphy_hw_t8122 }, { .compatible = "apple,t8132-atcphy", .data = &atcphy_hw_t8132 }, { .compatible = "apple,t8142-atcphy", .data = &atcphy_hw_t8142 }, From be5ed7bcbc45d67d2a536da6fd3010e4bf9b21a5 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:15 -0500 Subject: [PATCH 05/19] mfd: macsmc: support generic SMC sleep policy and pre-SLPA pacing Allow sleep providers that supply apple,smc-sleep-policy in DT to drive the generic macsmc sleep sequence (pmVC, SLPA, AP idle, and wake notices) and expose until_before_slpa() so providers can pace hardware votes ahead of the SLPA deadline without duplicating SMC state. Signed-off-by: Diljit Singh --- drivers/mfd/macsmc.c | 20 ++++++++++++++++++-- include/linux/mfd/macsmc.h | 1 + include/linux/soc/apple/sleep.h | 24 ++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 2 deletions(-) diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index b3a36436d834e..41ed7286fa337 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -761,8 +761,9 @@ static int apple_smc_probe(struct platform_device *pdev) apple_smc_init_state(smc); smc->dev = &pdev->dev; smc->bind_gen = atomic64_inc_return(&apple_smc_bind_gen); - smc->saved_enabled = apple_t6050_sleep_described() && - of_device_is_compatible(dev->of_node, "apple,t6050-smc"); + smc->saved_enabled = (apple_t6050_sleep_described() && + of_device_is_compatible(dev->of_node, "apple,t6050-smc")) || + apple_sleep_smc_policy_described(); if (smc->saved_enabled) smc->dark_wake_mask = apple_smc_dt_dark_wakes(smc); /* @@ -1797,6 +1798,19 @@ static int apple_smc_sleep_saved_pmvc(void *data) return 0; } +static void apple_smc_sleep_until_before_slpa(void *data, u32 us) +{ + struct apple_smc *smc = data; + const struct apple_sleep_smc_policy *p = smc->sleep_policy; + u64 answered; + + if (!p || !smc->sleep_warned) + return; + answered = smc->saved_pmvc_sent ? smc->saved_pmvc_at : smc->sleep_pmvc_at; + if (p->pmvc_to_slpa_us > us) + apple_smc_sleep_wait(answered, p->pmvc_to_slpa_us - us); +} + static const struct apple_sleep_smc_saved_ops apple_smc_saved_ops = { .begin = apple_smc_sleep_saved_begin, .check = apple_smc_sleep_saved_check, @@ -1805,6 +1819,7 @@ static const struct apple_sleep_smc_saved_ops apple_smc_saved_ops = { .end = apple_smc_sleep_saved_end, .woken = apple_smc_sleep_saved_woken, .pmvc = apple_smc_sleep_saved_pmvc, + .until_before_slpa = apple_smc_sleep_until_before_slpa, }; /* @@ -1884,6 +1899,7 @@ static int apple_smc_prepare_policy(struct apple_smc *smc) ret = apple_smc_write_u32(smc, SMC_KEY(pmVC), p->pmvc); if (ret) return ret; + smc->sleep_pmvc_at = __arch_counter_get_cntpct(); return apple_sleep_smc_register_saved(smc->dev, &apple_smc_saved_ops, smc); } diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h index 654f208de6e38..a6d07b2a7b6bc 100644 --- a/include/linux/mfd/macsmc.h +++ b/include/linux/mfd/macsmc.h @@ -123,6 +123,7 @@ struct apple_smc { bool sleep_warned; const struct apple_sleep_smc_policy *sleep_policy; u64 sleep_warn_ack; + u64 sleep_pmvc_at; bool sleep_pmvc_info; /* WKTP (1-byte writable) supported: notify SMC on full wake. */ bool has_wktp; diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index b61473131dcf9..303f54e373700 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -37,6 +37,24 @@ static inline bool apple_t6050_sleep_described(void) return apple_t6050_sleep_property(NULL); } +/* + * A sleep controller in the device tree that takes the SMC through its saved-context policy + * (apple,smc-sleep-policy): the SMC's last notices go out with interrupts off, on the + * transport that runs without them. + */ +static inline bool apple_sleep_smc_policy_described(void) +{ + struct device_node *np; + + for_each_node_with_property(np, "apple,smc-sleep-policy") { + if (of_device_is_available(np)) { + of_node_put(np); + return true; + } + } + return false; +} + /* The SMC's sleep messages: the pmVC value and the spacings between them, used as floors */ struct apple_sleep_smc_policy { u32 pmvc; @@ -62,6 +80,12 @@ struct apple_sleep_smc_saved_ops { void (*woken)(void *data); /* Optional, after the irreversible stops: pmVC alone, before late_notice (which then skips it). */ int (*pmvc)(void *data); + /* + * Optional: busy-wait until @us before the earliest slpa the policy allows (its pmVC to + * slpa spacing from the last pmVC's answer), so steps a SoC takes just before slpa can + * be taken there too. + */ + void (*until_before_slpa)(void *data, u32 us); }; #if IS_ENABLED(CONFIG_APPLE_SOC_SLEEP) From 1b0cf437881c95f4812893c404276b00ba52d974 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:16 -0500 Subject: [PATCH 06/19] iommu/apple-dart: gate PMP DART across failed wakes Export apple_dart_set_pmp_sleep() (guarded with IS_REACHABLE) so the PMP driver can mark its DART as sleep-managed. Keep TLB and PM suspend/ resume callbacks gated if the PMP DART fails to come back on wake so subsequent operations do not fault on an unpowered DART. Signed-off-by: Diljit Singh --- drivers/iommu/apple-dart.c | 70 ++++++++++++++++++++++++++++------ include/linux/soc/apple/dart.h | 6 +++ 2 files changed, 65 insertions(+), 11 deletions(-) diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 7e1ff6401057c..f980df9320aed 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -481,6 +481,8 @@ struct apple_dart { /* Powered down by its DCP across a real sleep: see apple_dart_host_power_on(). */ u32 host_off_slept : 1; bool commands_gated; + bool pmp_sleep_managed; + bool pmp_wake_gated; /* TLB commands written, counted under the lock: see apple_dart_t8110_tlb_wait(). */ unsigned long tlb_commands; /* A locked DART a display subsystem scans out through: apple_dart_display_scanout(). */ @@ -1764,7 +1766,7 @@ apple_dart_t8020_hw_stream_command(struct apple_dart_stream_map *stream_map, u32 command_reg; spin_lock_irqsave(&dart->lock, flags); - if (dart->commands_gated) { + if (dart->commands_gated || dart->pmp_wake_gated) { spin_unlock_irqrestore(&dart->lock, flags); return -EHOSTDOWN; } @@ -1862,7 +1864,7 @@ static int apple_dart_t8110_tlb_wait(struct apple_dart *dart, unsigned long *fla if (issued) return 0; /* Not yet written: another command may have gone in meanwhile. */ - if (dart->commands_gated) + if (dart->commands_gated || dart->pmp_wake_gated) return -EHOSTDOWN; return read_poll_timeout_atomic(apple_dart_readl, *status, !(*status & DART_T8110_TLB_CMD_BUSY), 1, @@ -1881,7 +1883,7 @@ apple_dart_t8110_hw_tlb_command_range(struct apple_dart_stream_map *stream_map, int sid, ret = 0; spin_lock_irqsave(&dart->lock, flags); - if (dart->commands_gated) { + if (dart->commands_gated || dart->pmp_wake_gated) { spin_unlock_irqrestore(&dart->lock, flags); return -EHOSTDOWN; } @@ -5712,13 +5714,13 @@ static irqreturn_t apple_dart_irq(int irq, void *dev) * faulting. Its line can be shared or still pending, so leave it alone; * apple_dart_host_power_off() waits for a handler already past this. */ - if (READ_ONCE(dart->commands_gated) || READ_ONCE(dart->host_off) || - READ_ONCE(dart->display_dark)) + if (READ_ONCE(dart->commands_gated) || READ_ONCE(dart->pmp_wake_gated) || + READ_ONCE(dart->host_off) || READ_ONCE(dart->display_dark)) return IRQ_NONE; if (pm_runtime_resume_and_get(dart->dev) < 0) return IRQ_NONE; - if (!READ_ONCE(dart->commands_gated) && !READ_ONCE(dart->host_off) && - !READ_ONCE(dart->display_dark)) + if (!READ_ONCE(dart->commands_gated) && !READ_ONCE(dart->pmp_wake_gated) && + !READ_ONCE(dart->host_off) && !READ_ONCE(dart->display_dark)) ret = dart->hw->irq_handler(irq, dev); pm_runtime_put(dart->dev); return ret; @@ -7423,7 +7425,7 @@ static void apple_dart_remove(struct platform_device *pdev) * block after that clock is running again. */ if (!dart->locked && !dart->retained_mtp && !dart->live_mtp && - !READ_ONCE(dart->commands_gated)) { + !READ_ONCE(dart->commands_gated) && !READ_ONCE(dart->pmp_wake_gated)) { if (pm_runtime_resume_and_get(&pdev->dev) >= 0) { apple_dart_hw_reset(dart); pm_runtime_put_sync(&pdev->dev); @@ -7818,7 +7820,7 @@ static __maybe_unused int apple_dart_suspend(struct device *dev) /* Its consumer saved this already and restores it: see apple_dart_sleep_prepare(). */ if (dart->sleep_saved) return 0; - if (READ_ONCE(dart->commands_gated)) + if (READ_ONCE(dart->commands_gated) || READ_ONCE(dart->pmp_wake_gated)) return 0; /* * The cold ANE DARTs belong to the ANE backend: it deactivates them @@ -8257,7 +8259,8 @@ static __maybe_unused int apple_dart_resume(struct device *dev) * state. Resetting one here is unnecessary; DART access must remain * ordered after PCIe-C port resume. */ - if (dart->power_retained || dart->retained_mtp || READ_ONCE(dart->commands_gated)) + if (dart->power_retained || dart->retained_mtp || + READ_ONCE(dart->commands_gated) || READ_ONCE(dart->pmp_wake_gated)) return 0; /* Locked DARTs can't be restored, and they should not need it */ @@ -8485,6 +8488,31 @@ int apple_dart_state_restore(struct device *dev) } EXPORT_SYMBOL_GPL(apple_dart_state_restore); +int apple_dart_set_pmp_sleep(struct device_node *np) +{ + struct platform_device *pdev; + struct apple_dart *dart; + + if (!np) + return -EINVAL; + pdev = of_find_device_by_node(np); + if (!pdev) + return -EPROBE_DEFER; + if (pdev->dev.driver != &apple_dart_driver.driver) { + put_device(&pdev->dev); + return -EPROBE_DEFER; + } + dart = platform_get_drvdata(pdev); + if (!dart) { + put_device(&pdev->dev); + return -EPROBE_DEFER; + } + dart->pmp_sleep_managed = true; + put_device(&pdev->dev); + return 0; +} +EXPORT_SYMBOL_GPL(apple_dart_set_pmp_sleep); + /* * A firmware-driven sleep takes the DARTs in the noirq phase, which every device finishes * before any early resume: coprocessors such as the PMP and SIO restart their firmware in @@ -8497,6 +8525,8 @@ static int apple_dart_system_suspend(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); + if (dart->pmp_sleep_managed && READ_ONCE(dart->pmp_wake_gated)) + return 0; if (!dart->live_mtp) return pm_suspend_via_firmware() ? 0 : pm_runtime_force_suspend(dev); /* @@ -8519,6 +8549,8 @@ static int apple_dart_system_resume(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); + if (dart->pmp_sleep_managed && READ_ONCE(dart->pmp_wake_gated)) + return 0; if (!dart->live_mtp) return pm_suspend_via_firmware() ? 0 : pm_runtime_force_resume(dev); if (!dart->live_mtp_sleep) @@ -8541,7 +8573,8 @@ static __maybe_unused int apple_dart_sys_suspend_noirq(struct device *dev) return 0; } /* Kept running by .suspend above: no runtime suspend, which refuses a live MTP. */ - if (dart->live_mtp_sleep) + if (dart->live_mtp_sleep || + (dart->pmp_sleep_managed && READ_ONCE(dart->pmp_wake_gated))) return 0; return pm_suspend_via_firmware() ? pm_runtime_force_suspend(dev) : 0; @@ -8557,6 +8590,21 @@ static __maybe_unused int apple_dart_sys_resume_noirq(struct device *dev) } if (dart->live_mtp_sleep) return 0; + if (dart->pmp_sleep_managed) { + int ret = apple_sleep_pmp_wake_error(); + + /* + * Keep the original suspend snapshot and runtime PM reference + * until a later firmware wake restores the PMP power words. + */ + if (ret) { + scoped_guard(spinlock_irqsave, &dart->lock) + WRITE_ONCE(dart->pmp_wake_gated, true); + return pm_resume_via_firmware() ? ret : 0; + } + scoped_guard(spinlock_irqsave, &dart->lock) + WRITE_ONCE(dart->pmp_wake_gated, false); + } return pm_suspend_via_firmware() ? apple_dart_resume_noirq(dev) : 0; } diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 04b3429931e0b..e110f462228c6 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -323,4 +323,10 @@ void apple_dart_make_available(struct device_node *np); static inline void apple_dart_make_available(struct device_node *np) { } #endif +#if IS_REACHABLE(CONFIG_APPLE_DART) +int apple_dart_set_pmp_sleep(struct device_node *np); +#else +static inline int apple_dart_set_pmp_sleep(struct device_node *np) { return -EOPNOTSUPP; } +#endif + #endif From 90f1d7103656f41520b4b47b3d59804a34a7f4fe Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:17 -0500 Subject: [PATCH 07/19] soc: apple: pmp-export: mark PMP DART sleep-managed on T6030 Register the T6030 PMP DART with apple_dart_set_pmp_sleep() when apple_pmp_commit_available() binds the commit callback on the first apple_pmp_suspend_late() (with apple,t6030-pmp-v2 instantiated on J516s via the runtime overlay t6030-j516s-pmp.dtso), so apple-dart coordinates its suspend/resume gating across deep sleep. Also move the wake_err check in apple_pmp_resume_early() ahead of clearing pmp_commit_used and apple_sleep_coproc_set_ready() so the coprocessor stays stopped and its RX mailbox held until a real wake restores power. Signed-off-by: Diljit Singh --- drivers/soc/apple/pmp-export.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/drivers/soc/apple/pmp-export.c b/drivers/soc/apple/pmp-export.c index 73a65697a640a..7f96058cc36f8 100644 --- a/drivers/soc/apple/pmp-export.c +++ b/drivers/soc/apple/pmp-export.c @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -207,6 +208,18 @@ static bool apple_pmp_commit_available(struct device *dev) iounmap(asc); return false; } + if (of_device_is_compatible(dev->of_node, "apple,t6030-pmp-v2")) { + struct device_node *dart_np = of_parse_phandle(dev->of_node, "iommus", 0); + + if (dart_np) { + int ret = apple_dart_set_pmp_sleep(dart_np); + + of_node_put(dart_np); + if (ret) + dev_warn(dev, "could not mark PMP DART for sleep gating: %d\n", + ret); + } + } pmp_commit_registered = true; return true; @@ -274,11 +287,12 @@ static int apple_pmp_resume_early(struct device *dev) bool stopped = apple_sleep_coproc_stopped(dev); int wake_err = apple_sleep_coproc_wake_error(dev); + /* Keep the coprocessor stopped and RX held until a real wake restores power. */ + if (wake_err) + return pm_resume_via_firmware() ? wake_err : 0; + pmp_commit_used = false; apple_sleep_coproc_set_ready(dev, false); - /* The PMP registers are inaccessible until its power words are on. */ - if (pm_resume_via_firmware() && wake_err) - return wake_err; if (!pm_resume_via_firmware() && !stopped) { if (pmp_rx_held) { pmp_rx_held = false; From 3e472125e87ef8a7223ed38133a6a5aaef68439f Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:17 -0500 Subject: [PATCH 08/19] soc: apple: sleep: add T6030 provider hooks Add the generic sleep-core hooks needed by the T6030 provider: - apple_sleep_domain_kept() via soc->ops->domain_kept, checked in pmgr-pwrstate suspend so wake resync still restores genpd-OFF domains; - after_early, wfi_again, and before_enclave hooks (marking regs_staged before before_enclave so refusal cleanup always runs undo_regs); - gate_fail_closed, cpu_start_every_cluster, gp_host_apart, and failed_stop_ends_sleep profile flags; - split sleep_ps_rewake() into staged helpers for multi-stage wake ordering. Signed-off-by: Diljit Singh --- drivers/soc/apple/sleep.c | 180 +++++++++++++++++++++++++------- include/linux/soc/apple/sleep.h | 6 ++ 2 files changed, 146 insertions(+), 40 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index fa73bd073761a..f87a3659e8d33 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -618,6 +618,12 @@ struct apple_sleep_ops { void (*cpu_down)(struct apple_sleep *s, u64 mpidr); /* Optional: past the point of no return, between ANS's stop and SIO's */ void (*after_ans)(struct apple_sleep *s); + /* Optional: past the point of no return, between SIO's stop and the PMP's */ + void (*after_early)(struct apple_sleep *s); + /* Optional: if the boot core's last WFI returns, re-issue the commit sequence */ + void (*wfi_again)(struct apple_sleep *s); + /* Optional: power domain kept across sleep by the SoC provider */ + bool (*domain_kept)(struct apple_sleep *s, int off); /* Pure bounded planning only; no register read/write or entry authorization. */ int (*plan_complex_request)(u32 observed, u32 *request); @@ -690,6 +696,17 @@ struct apple_sleep_soc { */ bool display_no_restart; bool strict_gate_inventory; + /* Fail closed if a gate_coprocs DT entry is missing or an unbound must_stop runs. */ + bool gate_fail_closed; + /* Write all CPU cluster start words (BIT(core) to target, 0 to others). */ + bool cpu_start_every_cluster; + /* APCIE_SYS_GP is the GP PCIe host's own domain, separate from ANS (APCIE_SYS_ST). */ + bool gp_host_apart; + /* + * A failed commit-time coprocessor stop leaves its run bit alone for the profile to + * halt on. + */ + bool failed_stop_ends_sleep; /* * No PMP runs and its report is disabled: the PTD entries the commit drops have no * report driver to take them from. A board whose report is enabled still takes them. @@ -1966,17 +1983,20 @@ static void apple_sleep_coproc_stop(struct apple_sleep *s, struct apple_sleep_co c->stop_ret = c->last_stop ? c->last_stop(c->data) : 0; if (s->soc->regions && c->pcie_ans && c->stop_ret) s->ans_m5_wake_error = -EIO; + if (c->stop_ret && s->soc->failed_stop_ends_sleep) { + c->stopped = true; + return; + } apple_sleep_coproc_run_off(c); } static void apple_sleep_coprocs_stop(struct apple_sleep *s, bool first) { /* - * Slot order, except that T6050's second pass stops ANS before the rest, as macOS - * does on the M5. - * The ANS owner registers at its .suspend, after the PMP's probe-time slot. + * Slot order, except that the second pass of T6050, or of a SoC with an after_early + * step, stops ANS, then the early ones (SIO), then the rest (PMP), as macOS does. */ - bool ans_first = s->soc->regions && !first; + bool ans_first = (s->soc->regions || s->soc->ops->after_early) && !first; int pass, i; if (first) @@ -1985,6 +2005,8 @@ static void apple_sleep_coprocs_stop(struct apple_sleep *s, bool first) for (pass = ans_first ? 0 : 2; pass < 3; pass++) { if (ans_first && pass == 1 && s->soc->ops->after_ans) s->soc->ops->after_ans(s); + if (ans_first && pass == 2 && s->soc->ops->after_early) + s->soc->ops->after_early(s); for (i = 0; i < SLEEP_COPROCS; i++) { struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; @@ -2991,7 +3013,14 @@ static int sleep_cpu_on(u64 mpidr) } writel(sleep_cpu_start_bit(s, mpidr), s->cpu_start + CPU_START_SYS); - writel(BIT(core), s->cpu_start + CPU_START_CLUSTER(cluster)); + if (s->soc->cpu_start_every_cluster) { + unsigned int c; + + for (c = 0; c < s->soc->cpu_clusters; c++) + writel(c == cluster ? BIT(core) : 0, s->cpu_start + CPU_START_CLUSTER(c)); + } else { + writel(BIT(core), s->cpu_start + CPU_START_CLUSTER(cluster)); + } if (!trace) return 0; @@ -3246,6 +3275,20 @@ bool apple_sleep_domain_is_down(struct device_node *pd) } EXPORT_SYMBOL_GPL(apple_sleep_domain_is_down); +bool apple_sleep_domain_kept(struct device_node *pd) +{ + struct apple_sleep *s = apple_sleep; + int off; + + if (!s || !s->soc->ops->domain_kept) + return false; + off = sleep_ps_offset(s, pd); + if (off < 0) + return false; + return s->soc->ops->domain_kept(s, off); +} +EXPORT_SYMBOL_GPL(apple_sleep_domain_kept); + /* * After a refused sleep, the sleep engine's own restart of a firmware's CPU whose domain shares * a power switch and can't gate alone, as SIO's: each of the device's own domains reset through @@ -3606,9 +3649,9 @@ static void apple_sleep_gate_prepare(struct apple_sleep *s) if (!c) { dev_warn(s->dev, "%s isn't in this tree\n", coprocs[i].path ?: coprocs[i].compatible); - if (s->soc->strict_gate_inventory) { + if (s->soc->strict_gate_inventory || s->soc->gate_fail_closed) { g = &s->gate[s->gate_count++]; - g->name = coprocs[i].compatible; + g->name = coprocs[i].path ?: coprocs[i].compatible; g->bound = false; g->strict_unbound = true; } @@ -3689,6 +3732,11 @@ static bool apple_sleep_gate_failed(struct apple_sleep *s, bool sep_prepared) readl(g->asc + ASC_CPU_CONTROL), readl(g->asc + ASC_CPU_STATUS)); running++; + } else if (g->must_stop && s->soc->gate_fail_closed && + (!g->asc || !g->ps)) { + dev_err(s->dev, "%s unbound and run state cannot be read\n", + g->name); + running++; } if (g->strict_unbound) running++; @@ -3879,17 +3927,33 @@ static int apple_sleep_refuse(struct apple_sleep *s) } sleep_note(s, 0x22); - /* ANS's link needs these after a real power loss. */ - if (idled && !s->soc->regions && !s->apcie_phy_tunable) { - dev_err(s->dev, "refused: no tunables to bring ANS's PCIe block back\n"); - refused = true; - } + if (s->soc->gp_host_apart) { + dev_dbg(s->dev, "ANS %#x, APCIE_SYS_GP %#x\n", + readl(sleep_power_reg(s, d->ans)), + readl(sleep_power_reg(s, d->apcie_sys_gp))); + if (!idled) { + if (d->ans && sleep_ps_on(s, d->ans)) { + dev_err(s->dev, "refused: ANS is on with no driver to stop it\n"); + refused = true; + } + } else if (d->ans && !sleep_ps_on(s, d->ans) && !s->apcie_phy_tunable) { + dev_err(s->dev, + "refused: ANS's link has no verified restore after a real sleep\n"); + refused = true; + } + } else { + /* ANS's link needs these after a real power loss. */ + if (idled && !s->soc->regions && !s->apcie_phy_tunable) { + dev_err(s->dev, "refused: no tunables to bring ANS's PCIe block back\n"); + refused = true; + } - /* Only ANS's driver can stop it, and it doesn't come back without a real sleep. */ - if (!idled && ((d->ans && sleep_ps_on(s, d->ans)) || - (d->apcie_sys_gp && sleep_ps_on(s, d->apcie_sys_gp)))) { - dev_err(s->dev, "refused: ANS or PCIe is on with no driver to stop it\n"); - refused = true; + /* Only ANS's driver can stop it, and it doesn't come back without a real sleep. */ + if (!idled && ((d->ans && sleep_ps_on(s, d->ans)) || + (d->apcie_sys_gp && sleep_ps_on(s, d->apcie_sys_gp)))) { + dev_err(s->dev, "refused: ANS or PCIe is on with no driver to stop it\n"); + refused = true; + } } sleep_note(s, 0x23); @@ -5260,17 +5324,18 @@ static bool sleep_ps_dropped(u32 saved, u32 woke) * macOS's wake words first, in its order, whatever they read, if Linux had them on. Then * any other domain the wake left otherwise, a second time for one whose parent came later. */ -static void sleep_ps_rewake(struct apple_sleep *s) +/* In a wake order: a word of "ps-aon"; the others are of "ps" */ +#define SLEEP_PS_WAKE_AON BIT(31) + +static void sleep_ps_rewake_begin(struct apple_sleep *s) { const struct apple_sleep_soc *soc = s->soc; const u32 *all = soc->ps_all.offset, *aon = soc->ps_aon_all.offset; unsigned int n = soc->ps_all.count, naon = soc->ps_aon_all.count; - bool *redo = s->ps_late, *redo_aon = s->ps_aon_late; - bool *done = s->ps_done, *done_aon = s->ps_aon_done; - int i, j, pass; + int i; - memset(done, 0, n * sizeof(*done)); - memset(done_aon, 0, naon * sizeof(*done_aon)); + memset(s->ps_done, 0, n * sizeof(*s->ps_done)); + memset(s->ps_aon_done, 0, naon * sizeof(*s->ps_aon_done)); memset(s->ps_late, 0, n * sizeof(*s->ps_late)); memset(s->ps_aon_late, 0, naon * sizeof(*s->ps_aon_late)); s->ps_rewoken = 0; @@ -5279,25 +5344,46 @@ static void sleep_ps_rewake(struct apple_sleep *s) s->ps_woke[i] = readl(sleep_power_reg(s, all[i])); for (i = 0; i < naon; i++) s->ps_aon_woke[i] = readl(s->ps_aon + aon[i]); +} - for (j = 0; j < soc->ps_wake_order.count; j++) { - i = sleep_ps_find(all, n, soc->ps_wake_order.offset[j]); - if (i < 0 || !FIELD_GET(PS_TARGET, s->ps_commit[i])) - continue; - done[i] = true; - s->ps_rewoken++; - if (sleep_ps_restore(sleep_power_reg(s, all[i]), s->ps_commit[i])) - redo[i] = true; - } - for (j = 0; j < soc->ps_aon_wake_order.count; j++) { - i = sleep_ps_find(aon, naon, soc->ps_aon_wake_order.offset[j]); - if (i < 0 || !FIELD_GET(PS_TARGET, s->ps_aon_commit[i])) - continue; - done_aon[i] = true; - s->ps_rewoken++; - if (sleep_ps_restore(s->ps_aon + aon[i], s->ps_aon_commit[i])) - redo_aon[i] = true; +static void sleep_ps_rewake_words(struct apple_sleep *s, const struct apple_sleep_words *order, + bool aon) +{ + const struct apple_sleep_soc *soc = s->soc; + int i, j; + + for (j = 0; j < order->count; j++) { + u32 offset = order->offset[j] & ~SLEEP_PS_WAKE_AON; + + if (aon || (order->offset[j] & SLEEP_PS_WAKE_AON)) { + i = sleep_ps_find(soc->ps_aon_all.offset, soc->ps_aon_all.count, offset); + if (i < 0 || s->ps_aon_done[i] || + !FIELD_GET(PS_TARGET, s->ps_aon_commit[i])) + continue; + s->ps_aon_done[i] = true; + s->ps_rewoken++; + if (sleep_ps_restore(s->ps_aon + offset, s->ps_aon_commit[i])) + s->ps_aon_late[i] = true; + } else { + i = sleep_ps_find(soc->ps_all.offset, soc->ps_all.count, offset); + if (i < 0 || s->ps_done[i] || !FIELD_GET(PS_TARGET, s->ps_commit[i])) + continue; + s->ps_done[i] = true; + s->ps_rewoken++; + if (sleep_ps_restore(sleep_power_reg(s, offset), s->ps_commit[i])) + s->ps_late[i] = true; + } } +} + +static void sleep_ps_rewake_rest(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + const u32 *all = soc->ps_all.offset, *aon = soc->ps_aon_all.offset; + unsigned int n = soc->ps_all.count, naon = soc->ps_aon_all.count; + bool *redo = s->ps_late, *redo_aon = s->ps_aon_late; + bool *done = s->ps_done, *done_aon = s->ps_aon_done; + int i, pass; for (pass = 0; pass < PS_REWAKE_PASSES; pass++) { for (i = 0; i < n; i++) { @@ -5329,6 +5415,14 @@ static void sleep_ps_rewake(struct apple_sleep *s) s->ps_rewake_timeouts += redo_aon[i]; } +static void sleep_ps_rewake(struct apple_sleep *s) +{ + sleep_ps_rewake_begin(s); + sleep_ps_rewake_words(s, &s->soc->ps_wake_order, false); + sleep_ps_rewake_words(s, &s->soc->ps_aon_wake_order, true); + sleep_ps_rewake_rest(s); +} + /* * Which blocks lost their power across this sleep: a coprocessor whose word is listed lost its * firmware as well, whatever the wake wrote back, and a driver that talks to it after the wake @@ -6056,6 +6150,8 @@ static void __noreturn sleep_boot_wfi(struct apple_sleep *s) t8142_wfi_returned(s, t0, ¬ed); s->soc->ops->aic_ack(); write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); + if (s->soc->ops->wfi_again) + s->soc->ops->wfi_again(s); } } @@ -6721,6 +6817,10 @@ static int apple_sleep_enter_prepare(struct apple_sleep *s) if (ret) panic("Apple SEP refused after the always-on GPU stop: %d", ret); } else if (!ret) { + if (s->soc->ops->before_enclave) { + s->regs_staged = true; + s->soc->ops->before_enclave(s); + } ret = apple_sleep_enclave_stop(s); } if (ret) { diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 303f54e373700..9fd456077ff3d 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -244,6 +244,7 @@ int apple_sleep_domain_check(struct device_node *pd); /* For the PMGR's driver at the wake: a driver took @pd down and brings it up itself. */ bool apple_sleep_domain_is_down(struct device_node *pd); +bool apple_sleep_domain_kept(struct device_node *pd); /* For the port controller wired to the fixed hub's @port, as it arms USB wake. */ bool apple_sleep_usb_port_can_wake(unsigned int port); @@ -532,6 +533,11 @@ static inline bool apple_sleep_domain_is_down(struct device_node *pd) return false; } +static inline bool apple_sleep_domain_kept(struct device_node *pd) +{ + return false; +} + static inline bool apple_sleep_usb_port_can_wake(unsigned int port) { return false; From 53742efc1604c029f1cbbae8ea9342b8f1075bf3 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:18 -0500 Subject: [PATCH 09/19] pmdomain: apple: pmgr-pwrstate: keep provider-owned domains across sleep Consult apple_sleep_domain_kept() during system sleep power-off so power domains managed directly by the SoC sleep provider are not gated early by genpd suspend while wake resync still restores genpd-OFF domains. Signed-off-by: Diljit Singh --- drivers/pmdomain/apple/pmgr-pwrstate.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 14367dfb58550..2d20cbbf7f2cb 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -469,7 +469,9 @@ static int apple_pmgr_ps_power_off(struct generic_pm_domain *genpd) * Its driver took it down for the sleep and raises it in its own order. Gating it * here would take its parents too, and genpd would raise them all first at the wake. */ - if (ps->system_sleep && apple_sleep_domain_is_down(ps->dev->of_node)) + if (ps->system_sleep && + (apple_sleep_domain_is_down(ps->dev->of_node) || + apple_sleep_domain_kept(ps->dev->of_node))) return -EBUSY; ret = apple_pmgr_ps_set(genpd, APPLE_PMGR_PS_PWRGATE, false); From 4d410bca78c502ac714fc561cfa320c6ef80ac47 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:19 -0500 Subject: [PATCH 10/19] soc: apple: sleep: add T6030 firmware sleep provider Add the Apple T6030 (M3 Pro) deep suspend-to-RAM provider for apple-sleep with full SEP stop, DT-driven entry/wake register sequences (with explicit slc-off and clear64-way opcodes), PTD/CPM/SLC handshakes, GP PCIe PHY/clock park and wake recovery, PMU RTC alarm re-arming and sleep/wake stage byte updates (writing 0xfe to PMU register 0xf801 on wake, matching the 0x50 stage byte written at sleep entry), and KUnit coverage. Signed-off-by: Diljit Singh --- drivers/soc/apple/Kconfig | 2 +- drivers/soc/apple/sleep-t6030-pcie-wake.h | 472 +++ drivers/soc/apple/sleep-t6030-ps.h | 182 ++ drivers/soc/apple/sleep-t6030-quiesce.h | 272 ++ drivers/soc/apple/sleep-t6030.h | 3237 +++++++++++++++++++++ drivers/soc/apple/sleep-test.c | 6 +- drivers/soc/apple/sleep.c | 40 + tools/asahi/run-host-tests.py | 2 + tools/asahi/t6030-sleep-qblk-tests.py | 141 + 9 files changed, 4351 insertions(+), 3 deletions(-) create mode 100644 drivers/soc/apple/sleep-t6030-pcie-wake.h create mode 100644 drivers/soc/apple/sleep-t6030-ps.h create mode 100644 drivers/soc/apple/sleep-t6030-quiesce.h create mode 100644 drivers/soc/apple/sleep-t6030.h create mode 100755 tools/asahi/t6030-sleep-qblk-tests.py diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index 7e5277f07d702..160baf3824ffe 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -181,7 +181,7 @@ config APPLE_SOC_SLEEP /chosen/aurora,s2r-mailbox. Only SoCs whose sleep has been measured and tested are supported, - each by its match data: today T8140, T8132, T6050 and T8103. On every other + each by its match data: today T8140, T8132, T6030, T6050 and T8103. On every other SoC the driver doesn't bind, and s2idle stays the only system sleep. T6041 (M4 Max) has a driver of its own, t6041-sleep, which binds diff --git a/drivers/soc/apple/sleep-t6030-pcie-wake.h b/drivers/soc/apple/sleep-t6030-pcie-wake.h new file mode 100644 index 0000000000000..d3bc3226cccac --- /dev/null +++ b/drivers/soc/apple/sleep-t6030-pcie-wake.h @@ -0,0 +1,472 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple T6030 general-purpose PCIe root complex and PHY wake-up sequence. + * Register blocks are mapped from the apple,pcie-host DT phandle. + */ + +enum { + T6030_GPW_RC, + T6030_GPW_PHY_COMMON, + T6030_GPW_PHY_SHARED, + T6030_GPW_PHY_IP, + T6030_GPW_BLOCKS, +}; + +enum { T6030_GPW_READ, T6030_GPW_WRITE, T6030_GPW_POLL }; + +struct t6030_gpw { + u8 blk; + u8 op; + u32 off; + u32 val; +}; + +static const struct t6030_gpw t6030_gp_wake[] = { + { T6030_GPW_RC, T6030_GPW_WRITE, 0x4, 0x0 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0xc, 0x3010030 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x10, 0x400c030 }, + { T6030_GPW_PHY_COMMON, T6030_GPW_READ, 0x0, 0x80300000 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x0, 0x1f0c080 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x0, 0x1f0c081 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x0, 0x1f0c085 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x0, 0x1f0c087 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x0, 0x1f0c08f }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x0, 0x1f0c00f }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x4, 0x0 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x4, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x28, 0xa00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x28, 0x800800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x6c, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x6c, 0x4c }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x80, 0x80010000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x80, 0x80010001 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x94, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x94, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1000, 0x2a2083c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1000, 0x2a2383c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x102c, 0x5133113 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x102c, 0x4454447 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1204, 0x40 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1204, 0x48 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x501c, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5080, 0x298d8190 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5080, 0x294d8190 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5088, 0x550800 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5088, 0x560800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x508c, 0x298d8190 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x508c, 0x294d8190 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5094, 0x50800 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5094, 0x60800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x50a0, 0x544800 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x50a0, 0x554800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x50ac, 0x544800 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x50ac, 0x554800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x50b8, 0x544800 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x50b8, 0x554800 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5200, 0x81554 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5200, 0x8155e }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5224, 0x18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5224, 0x818 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5230, 0x1d008 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x5240, 0x4010f30 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x5240, 0x4010f49 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x52b0, 0x18300811 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x52b0, 0x10300811 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x52e4, 0x1044201 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x52fc, 0x30f00f0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x52fc, 0x3078078 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x531c, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x531c, 0x2 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x608c, 0x66120280 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x608c, 0x65918280 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x6204, 0x800000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x6204, 0x80003c }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x6224, 0x18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x6224, 0x818 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x6228, 0x18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x6228, 0xb18 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x6230, 0x1e814 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x6230, 0x1e80f }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x624c, 0x1f800080 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x624c, 0x1f80009b }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x62b0, 0x18300811 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x62e4, 0x1044201 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa000, 0x80001ac }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa000, 0x80001aa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa008, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa008, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa00c, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa00c, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa010, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa010, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa014, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa014, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa038, 0x4e2 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa038, 0x271 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa040, 0x8c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa040, 0xc8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa04c, 0x18c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa04c, 0xbff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa050, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa050, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa068, 0xc42 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa068, 0xc41 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa070, 0x49e01040 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa070, 0x55b00820 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa084, 0x1402710 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa084, 0x3e8f4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa088, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa088, 0xfff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa09c, 0x1a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa09c, 0x541a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0b8, 0xff03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0b8, 0xaa03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0bc, 0x52b1cff }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0bc, 0x52d1faa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0c0, 0xae051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0c0, 0x145051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0c4, 0x7777 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0e0, 0x5045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0e0, 0xd045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa0e8, 0x8041 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa0e8, 0x2041 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa10c, 0x1388 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa10c, 0xf4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa11c, 0xb30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa11c, 0xf30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa178, 0xa00000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa178, 0x300000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1b4, 0x1d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1b4, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1bc, 0x2d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1bc, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1c4, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1cc, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1cc, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1e8, 0x100003 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1e8, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1b0, 0x82243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1b0, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xa1b8, 0x582243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xa1b8, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12000, 0x80001ac }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12000, 0x80001aa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12008, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12008, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1200c, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1200c, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12010, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12010, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12014, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12014, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12038, 0x4e2 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12038, 0x271 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12040, 0x8c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12040, 0xc8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1204c, 0x18c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1204c, 0xbff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12050, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12050, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12068, 0xc42 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12068, 0xc41 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12070, 0x49e01040 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12070, 0x55b00820 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12084, 0x1402710 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12084, 0x3e8f4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12088, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12088, 0xfff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1209c, 0x1a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1209c, 0x541a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120b8, 0xff03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120b8, 0xaa03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120bc, 0x52b1cff }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120bc, 0x52d1faa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120c0, 0xae051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120c0, 0x145051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120c4, 0x7777 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120e0, 0x5045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120e0, 0xd045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x120e8, 0x8041 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x120e8, 0x2041 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1210c, 0x1388 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1210c, 0xf4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1211c, 0xb30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1211c, 0xf30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x12178, 0xa00000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x12178, 0x300000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121b0, 0x82243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121b0, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121b4, 0x1d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121b4, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121b8, 0x582243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121b8, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121bc, 0x2d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121bc, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121c4, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121cc, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121cc, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x121e8, 0x100003 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x121e8, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a000, 0x80001ac }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a000, 0x80001aa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a008, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a008, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a00c, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a00c, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a010, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a010, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a014, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a014, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a038, 0x4e2 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a038, 0x271 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a040, 0x8c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a040, 0xc8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a04c, 0x18c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a04c, 0xbff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a050, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a050, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a068, 0xc42 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a068, 0xc41 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a070, 0x49e01040 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a070, 0x55b00820 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a084, 0x1402710 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a084, 0x3e8f4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a088, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a088, 0xfff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a09c, 0x1a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a09c, 0x541a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0b8, 0xff03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0b8, 0xaa03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0bc, 0x52b1cff }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0bc, 0x52d1faa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0c0, 0xae051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0c0, 0x145051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0c4, 0x7777 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0e0, 0x5045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0e0, 0xd045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a0e8, 0x8041 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a0e8, 0x2041 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a10c, 0x1388 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a10c, 0xf4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a11c, 0xb30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a11c, 0xf30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a178, 0xa00000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a178, 0x300000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1b0, 0x82243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1b0, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1b4, 0x1d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1b4, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1b8, 0x582243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1b8, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1bc, 0x2d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1bc, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1c4, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1cc, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1cc, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1a1e8, 0x100003 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1a1e8, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22000, 0x80001ac }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22000, 0x80001aa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22008, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22008, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2200c, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2200c, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22010, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22010, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22014, 0x9 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22014, 0xa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22038, 0x4e2 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22038, 0x271 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22040, 0x8c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22040, 0xc8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2204c, 0x18c8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2204c, 0xbff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22050, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22050, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22068, 0xc42 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22068, 0xc41 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22070, 0x49e01040 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22070, 0x55b00820 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22084, 0x1402710 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22084, 0x3e8f4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22088, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22088, 0xfff }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2209c, 0x1a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2209c, 0x541a81a }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220b8, 0xff03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220b8, 0xaa03f1f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220bc, 0x52b1cff }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220bc, 0x52d1faa }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220c0, 0xae051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220c0, 0x145051f8 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220c4, 0x7777 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220e0, 0x5045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220e0, 0xd045000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x220e8, 0x8041 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x220e8, 0x2041 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2210c, 0x1388 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2210c, 0xf4240 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2211c, 0xb30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2211c, 0xf30dc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x22178, 0xa00000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x22178, 0x300000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221b0, 0x82243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221b0, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221b4, 0x1d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221b4, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221b8, 0x582243 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221b8, 0x98924 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221bc, 0x2d00 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221bc, 0x1500 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221c4, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221c4, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221cc, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221cc, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x221e8, 0x100003 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x221e8, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xb02c, 0x1880062 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xb02c, 0x1980062 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xb098, 0x5000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xb098, 0x5028000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1302c, 0x1880062 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1302c, 0x1980062 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x13098, 0x5000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x13098, 0x5028000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1b02c, 0x1880062 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1b02c, 0x1980062 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1b098, 0x5000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1b098, 0x5028000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2302c, 0x1880062 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2302c, 0x1980062 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x23098, 0x5000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x23098, 0x5028000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x9000, 0x5e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x9000, 0x1e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x9008, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x903c, 0xc3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x903c, 0x18c3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x90d8, 0x1021c38 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x90d8, 0x102068d }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x90dc, 0x12004c18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x90dc, 0x12004408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x91e0, 0x2000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x91e0, 0x2008 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x9280, 0xcc8ccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x9280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x9280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x9280, 0xccc8ccc1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x11000, 0x5e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x11000, 0x1e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x11008, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1103c, 0xc3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1103c, 0x18c3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x110d8, 0x1021c38 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x110d8, 0x102068d }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x110dc, 0x12004c18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x110dc, 0x12004408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x111e0, 0x2000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x111e0, 0x2008 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x11280, 0xcc8ccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x11280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x11280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x11280, 0xccc8cccc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x19000, 0x5e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x19000, 0x1e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x19008, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1903c, 0xc3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1903c, 0x18c3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x190d8, 0x1021c38 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x190d8, 0x102068d }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x190dc, 0x12004c18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x190dc, 0x12004408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x191e0, 0x2000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x191e0, 0x2008 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x19280, 0xcc8ccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x19280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x21000, 0x5e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x21000, 0x1e000000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x21008, 0x100000 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2103c, 0xc3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2103c, 0x18c3509 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x210d8, 0x1021c38 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x210d8, 0x102068d }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x210dc, 0x12004c18 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x210dc, 0x12004408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x211e0, 0x2000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x211e0, 0x2008 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x21280, 0xcc8ccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x21280, 0xcccccccc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xd008, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xd008, 0xc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xd014, 0x4840000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xd014, 0x4840408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x15008, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x15008, 0xc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x15014, 0x4840000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x15014, 0x4840408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1d008, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1d008, 0xc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1d014, 0x4840000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1d014, 0x4840408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x25008, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x25008, 0xc }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x25014, 0x4840000 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x25014, 0x4840408 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xc01c, 0x641 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xc01c, 0x6a1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xc080, 0x140c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xc080, 0x540c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xc08c, 0x10bc0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xc08c, 0x10be0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xc0a0, 0x2021780 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xc0a0, 0x21a1780 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0xc0ec, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0xc0ec, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1401c, 0x641 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1401c, 0x6a1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x14080, 0x140c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x14080, 0x540c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1408c, 0x10bc0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1408c, 0x10be0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x140a0, 0x2021780 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x140a0, 0x21a1780 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x140ec, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x140ec, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1c01c, 0x641 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1c01c, 0x6a1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1c080, 0x140c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1c080, 0x540c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1c08c, 0x10bc0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1c08c, 0x10be0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1c0a0, 0x2021780 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1c0a0, 0x21a1780 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x1c0ec, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x1c0ec, 0x0 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2401c, 0x641 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2401c, 0x6a1 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x24080, 0x140c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x24080, 0x540c6831 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x2408c, 0x10bc0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x2408c, 0x10be0c1f }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x240a0, 0x2021780 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x240a0, 0x21a1780 }, + { T6030_GPW_PHY_IP, T6030_GPW_READ, 0x240ec, 0x1 }, + { T6030_GPW_PHY_IP, T6030_GPW_WRITE, 0x240ec, 0x0 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x4, 0x1 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x4, 0x11 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_POLL, 0x8, 0x1 }, + { T6030_GPW_PHY_COMMON, T6030_GPW_READ, 0x0, 0x80300000 }, + { T6030_GPW_PHY_COMMON, T6030_GPW_WRITE, 0x0, 0x80300001 }, + { T6030_GPW_PHY_SHARED, T6030_GPW_READ, 0x0, 0x1f0c00f }, + { T6030_GPW_PHY_SHARED, T6030_GPW_WRITE, 0x0, 0x1f0c20f }, + { T6030_GPW_RC, T6030_GPW_WRITE, 0x54, 0x140 }, + { T6030_GPW_RC, T6030_GPW_WRITE, 0x50, 0x1 }, + { T6030_GPW_RC, T6030_GPW_READ, 0x58, 0x1 }, +}; diff --git a/drivers/soc/apple/sleep-t6030-ps.h b/drivers/soc/apple/sleep-t6030-ps.h new file mode 100644 index 0000000000000..117d6627ceae0 --- /dev/null +++ b/drivers/soc/apple/sleep-t6030-ps.h @@ -0,0 +1,182 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple T6030 power-state domain inventory and entry ordering tables. + * Offsets are relative to the PMGR ps (aon = false) or ps-aon (aon = true) block. + */ + +struct t6030_ps_entry { + u32 off; + bool aon; + u32 target; + u8 group; +}; + +/* Group: 1 = staged ON, 2 = AUTO_PM enabled, 3/4 = lowered at commit, 0 = other. */ +static const struct t6030_ps_entry t6030_ps_entries[] = { + { 0x108, false, 0x200, 3 }, /* 0 MSG */ + { 0x110, false, 0x100000ff, 2 }, /* 1 AIC */ + { 0x118, false, 0x1000000f, 1 }, /* 2 DWI */ + { 0x120, false, 0x100000ff, 1 }, /* 3 GPIO */ + { 0x138, false, 0x200, 4 }, /* 4 PMS_FPWM0 */ + { 0x140, false, 0x200, 4 }, /* 5 PMS_FPWM1 */ + { 0x148, false, 0x200, 4 }, /* 6 PMS_FPWM2 */ + { 0x150, false, 0x200, 4 }, /* 7 PMS_FPWM3 */ + { 0x158, false, 0x200, 4 }, /* 8 PMS_FPWM4 */ + { 0x160, false, 0x200, 0 }, /* 9 PMS_C1PPT */ + { 0x168, false, 0x200, 0 }, /* 10 SOC_RC */ + { 0x170, false, 0x100000ff, 2 }, /* 11 SOC_DPE */ + { 0x178, false, 0x200, 4 }, /* 12 PMGR_SOC_OCLA */ + { 0x180, false, 0x4000200, 0 }, /* 13 ISPSENS0 */ + { 0x190, false, 0x200, 4 }, /* 14 AFT0 */ + { 0x1a8, false, 0x300, 0 }, /* 15 AP_TMM */ + { 0x1b8, false, 0xf0000ff, 0 }, /* 16 SIO */ + { 0x1c0, false, 0x2300, 0 }, /* 17 DISP_SYS */ + { 0x1c8, false, 0xf000100, 0 }, /* 18 JPG */ + { 0x1d0, false, 0xf000200, 0 }, /* 19 SIO_CPU */ + { 0x1d8, false, 0x200, 0 }, /* 20 FPWM0 */ + { 0x1e0, false, 0x200, 4 }, /* 21 FPWM1 */ + { 0x1e8, false, 0x200, 4 }, /* 22 FPWM2 */ + { 0x1f0, false, 0x100000ff, 1 }, /* 23 I2C0 */ + { 0x1f8, false, 0x200, 0 }, /* 24 I2C1 */ + { 0x200, false, 0x200, 0 }, /* 25 I2C2 */ + { 0x208, false, 0x200, 0 }, /* 26 I2C3 */ + { 0x210, false, 0x100000ff, 1 }, /* 27 I2C4 */ + { 0x218, false, 0x200, 4 }, /* 28 I2C5 */ + { 0x220, false, 0x200, 0 }, /* 29 I2C6 */ + { 0x228, false, 0x100000ff, 1 }, /* 30 I2C7 */ + { 0x230, false, 0x100000ff, 1 }, /* 31 I2C8 */ + { 0x238, false, 0x100000ff, 2 }, /* 32 SPI_P */ + { 0x240, false, 0x100000ff, 2 }, /* 33 UART_P */ + { 0x248, false, 0x100000ff, 2 }, /* 34 AUDIO_P */ + { 0x250, false, 0x100, 0 }, /* 35 AES */ + { 0x258, false, 0x2200, 0 }, /* 36 DISP_FE */ + { 0x260, false, 0x100000ff, 1 }, /* 37 SPI0 */ + { 0x268, false, 0x200, 0 }, /* 38 SPI1 */ + { 0x270, false, 0x200, 0 }, /* 39 SPI2 */ + { 0x278, false, 0x200, 0 }, /* 40 SPI3 */ + { 0x280, false, 0x200, 0 }, /* 41 SPI4 */ + { 0x288, false, 0x200, 0 }, /* 42 SPI5 */ + { 0x290, false, 0x200, 0 }, /* 43 QSPI */ + { 0x298, false, 0x200, 0 }, /* 44 UART_N */ + { 0x2a0, false, 0x100000ff, 2 }, /* 45 UART0 */ + { 0x2a8, false, 0x100000ff, 1 }, /* 46 UART1 */ + { 0x2b0, false, 0x100000ff, 1 }, /* 47 UART2 */ + { 0x2b8, false, 0x100000ff, 1 }, /* 48 UART3 */ + { 0x2c0, false, 0x100000ff, 1 }, /* 49 UART4 */ + { 0x2c8, false, 0x100000ff, 1 }, /* 50 UART5 */ + { 0x2d0, false, 0x100000ff, 1 }, /* 51 UART6 */ + { 0x2d8, false, 0x200, 0 }, /* 52 SIO_ADMA */ + { 0x2e0, false, 0x100000ff, 2 }, /* 53 DPA0 */ + { 0x2e8, false, 0x200, 3 }, /* 54 DPA1 */ + { 0x2f0, false, 0x200, 3 }, /* 55 DPA2 */ + { 0x2f8, false, 0x200, 3 }, /* 56 DPA3 */ + { 0x300, false, 0x200, 3 }, /* 57 DPA4 */ + { 0x308, false, 0x200, 0 }, /* 58 MCA0 */ + { 0x388, false, 0x200, 0 }, /* 59 MCA1 */ + { 0x390, false, 0x200, 4 }, /* 60 MCA2 */ + { 0x398, false, 0x200, 4 }, /* 61 MCA3 */ + { 0x3a0, false, 0x1f0000ff, 0 }, /* 62 IOA1 */ + { 0x3a8, false, 0x1f0000ff, 0 }, /* 63 LS1 */ + { 0x3b0, false, 0x1f0000ff, 0 }, /* 64 LW10 */ + { 0x3b8, false, 0x2300, 0 }, /* 65 DISPEXT0_SYS */ + { 0x3c0, false, 0x2100, 0 }, /* 66 DISPEXT1_SYS */ + { 0x3c8, false, 0x2300, 0 }, /* 67 ISP_SYS */ + { 0x3d0, false, 0xf002100, 0 }, /* 68 VENC_SYS */ + { 0x3d8, false, 0x2200, 0 }, /* 69 DISPEXT0_FE */ + { 0x3e0, false, 0xf040300, 0 }, /* 70 DISPEXT0_CPU */ + { 0x3e8, false, 0x300, 0 }, /* 71 TRACE_FAB */ + { 0x3f0, false, 0x2200, 0 }, /* 72 DISPEXT1_FE */ + { 0x3f8, false, 0xf040300, 0 }, /* 73 DISPEXT1_CPU */ + { 0x408, false, 0x100000ff, 1 }, /* 74 DPTX_PHY */ + { 0x490, false, 0xf002100, 0 }, /* 75 AVD_SYS */ + { 0x498, false, 0xf002300, 0 }, /* 76 ANE_SYS */ + { 0x4a0, false, 0x2100, 0 }, /* 77 SCODEC */ + { 0x4a8, false, 0x300, 0 }, /* 78 SCODEC_STREAM */ + { 0x4b0, false, 0x1f0000ff, 0 }, /* 79 IOA3 */ + { 0x4b8, false, 0x1f0000ff, 0 }, /* 80 LS3 */ + { 0x4c0, false, 0x1f0000ff, 0 }, /* 81 LW30 */ + { 0x4c8, false, 0xf0f0300, 0 }, /* 82 PMP */ + { 0x4d0, false, 0xf000300, 0 }, /* 83 PMS_SRAM */ + { 0x4d8, false, 0x1f0000ff, 0 }, /* 84 LW31 */ + { 0x4e0, false, 0x2300, 3 }, /* 85 ATC0_COMMON */ + { 0x4e8, false, 0x2300, 3 }, /* 86 ATC1_COMMON */ + { 0x4f0, false, 0x2300, 3 }, /* 87 ATC2_COMMON */ + { 0x4f8, false, 0x2300, 3 }, /* 88 ATC3_COMMON */ + { 0x500, false, 0x100000ff, 2 }, /* 89 APCIE_GP */ + { 0x508, false, 0xf002300, 0 }, /* 90 MSR */ + { 0x510, false, 0x1f0020ff, 0 }, /* 91 ANS */ + { 0x518, false, 0x300, 0 }, /* 92 ATC0_PCIE */ + { 0x520, false, 0x300, 0 }, /* 93 ATC0_CIO */ + { 0x528, false, 0x300, 0 }, /* 94 ATC1_PCIE */ + { 0x530, false, 0x300, 0 }, /* 95 ATC1_CIO */ + { 0x538, false, 0x300, 0 }, /* 96 ATC2_PCIE */ + { 0x540, false, 0x300, 0 }, /* 97 ATC2_CIO */ + { 0x548, false, 0x300, 0 }, /* 98 ATC3_PCIE */ + { 0x550, false, 0x300, 0 }, /* 99 ATC3_CIO */ + { 0x558, false, 0x1000230f, 0 }, /* 100 APCIE_SYS_GP */ + { 0x560, false, 0x300, 0 }, /* 101 MSR_ASE_CORE */ + { 0x568, false, 0x100000ff, 2 }, /* 102 APCIE_ST */ + { 0x570, false, 0x300, 0 }, /* 103 ATC0_CIO_PCIE */ + { 0x578, false, 0x300, 0 }, /* 104 ATC0_CIO_USB */ + { 0x580, false, 0x300, 0 }, /* 105 ATC1_CIO_PCIE */ + { 0x588, false, 0x300, 0 }, /* 106 ATC1_CIO_USB */ + { 0x590, false, 0x300, 0 }, /* 107 ATC2_CIO_PCIE */ + { 0x598, false, 0x300, 0 }, /* 108 ATC2_CIO_USB */ + { 0x5a0, false, 0x300, 0 }, /* 109 ATC3_CIO_PCIE */ + { 0x5a8, false, 0x300, 0 }, /* 110 ATC3_CIO_USB */ + { 0x5b0, false, 0x1000030f, 0 }, /* 111 APCIE_SYS_ST */ + { 0x5b8, false, 0xf000200, 0 }, /* 112 APCIE_PHY_SW */ + { 0xc00, false, 0x1000270f, 0 }, /* 113 SEP */ + { 0x4000, false, 0x100, 0 }, /* 114 ISP_CPU */ + { 0x4008, false, 0x300, 0 }, /* 115 ISP_FE */ + { 0x4010, false, 0x200, 0 }, /* 116 DPRX */ + { 0x4018, false, 0x300, 0 }, /* 117 ISP_SECURE */ + { 0x4020, false, 0x300, 0 }, /* 118 ISP_BE */ + { 0x4028, false, 0x300, 0 }, /* 119 ISP_CLR */ + { 0x8000, false, 0x300, 0 }, /* 120 VENC_DMA */ + { 0x8008, false, 0x300, 0 }, /* 121 VENC_PIPE4 */ + { 0x8010, false, 0x300, 0 }, /* 122 VENC_PIPE5 */ + { 0x8018, false, 0x300, 0 }, /* 123 VENC_ME0 */ + { 0x8020, false, 0x300, 0 }, /* 124 VENC_ME1 */ + { 0xc000, false, 0x300, 0 }, /* 125 ANE_MPM */ + { 0xc008, false, 0xf000300, 0 }, /* 126 ANE_CPU */ + { 0xc010, false, 0x300, 0 }, /* 127 ANE_TD */ + { 0xc018, false, 0x300, 0 }, /* 128 ANE_BASE */ + { 0x10000, false, 0xf000300, 0 }, /* 129 DISP_CPU */ + { 0x0, true, 0x1f0000ff, 0 }, /* 130 DEBUG_GATED */ + { 0x58, true, 0x1f0000ff, 0 }, /* 131 NUB_SPMI0 */ + { 0x60, true, 0x1f0000ff, 0 }, /* 132 NUB_SPMI1 */ + { 0x68, true, 0x1f0000ff, 0 }, /* 133 NUB_SPMI2 */ + { 0x70, true, 0x1f0000ff, 0 }, /* 134 NUB_SPMI_A0 */ + { 0x78, true, 0x1f0000ff, 0 }, /* 135 NUB_SPMI_A1 */ + { 0x88, true, 0x200, 3 }, /* 136 NUB_SPI0 */ + { 0x90, true, 0x200, 3 }, /* 137 NUB_OCLA */ + { 0x98, true, 0x100000ff, 2 }, /* 138 NUB_GPIO */ + { 0xa0, true, 0x1f0000ff, 2 }, /* 139 NUB_FABRIC */ + { 0xa8, true, 0x1f0000ff, 0 }, /* 140 NUB_SRAM */ + { 0xb0, true, 0x1f0000ff, 0 }, /* 141 DEBUG_SWITCH */ + { 0xb8, true, 0x300, 3 }, /* 142 ATC0_USB_AON */ + { 0xc0, true, 0x300, 0 }, /* 143 ATC1_USB_AON */ + { 0xc8, true, 0x300, 0 }, /* 144 ATC2_USB_AON */ + { 0xd0, true, 0x300, 0 }, /* 145 ATC3_USB_AON */ + { 0xd8, true, 0x300, 3 }, /* 146 ATC0_USB */ + { 0xe0, true, 0x100, 0 }, /* 147 ATC1_USB */ + { 0xe8, true, 0x100, 0 }, /* 148 ATC2_USB */ + { 0xf0, true, 0x300, 0 }, /* 149 ATC3_USB */ +}; + +/* Domains kept active across display power-down for firmware entry. */ +static const u8 t6030_ps_on_order[] = { + 2, 3, 23, 27, 30, 31, 37, 46, 47, 48, 49, 50, 51, 74, +}; + +/* Domains with AUTO_PM enabled before sleep commit. */ +static const u8 t6030_ps_auto_order[] = { + 1, 11, 45, 53, 89, 102, 138, 139, 32, 33, 34, +}; + +/* Domains lowered in child-before-parent order immediately before commit. */ +static const u8 t6030_ps_lower_order[] = { + 146, 142, 4, 5, 6, 7, 8, 12, 14, 21, 22, 28, 54, 55, + 56, 57, 60, 61, 85, 86, 87, 88, 136, 137, 0, +}; diff --git a/drivers/soc/apple/sleep-t6030-quiesce.h b/drivers/soc/apple/sleep-t6030-quiesce.h new file mode 100644 index 0000000000000..e2db6268852c8 --- /dev/null +++ b/drivers/soc/apple/sleep-t6030-quiesce.h @@ -0,0 +1,272 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple T6030 peripheral quiesce register sequences run at display power-down + * before firmware sleep entry. Register blocks are mapped from DT phandles. + */ + +enum t6030_qblk { + T6030_QBLK_PCIE_DART0, + T6030_QBLK_PCIE_PORT0, + T6030_QBLK_PCIE_INTR0, + T6030_QBLK_PCIE_DART1, + T6030_QBLK_PCIE_PORT1, + T6030_QBLK_PCIE_INTR1, + T6030_QBLK_PCIE_PHY0, + T6030_QBLK_PCIE_PHY1, + T6030_QBLK_PINCTRL, + T6030_QBLK_DISP_DART0, + T6030_QBLK_DISP_DART1, + T6030_QBLK_DISP_DART2, + T6030_QBLK_PWRGATE, + T6030_QBLK_COUNT, +}; + +struct t6030_quiesce_write { + u8 blk; + u16 off; + u32 val; + u32 delay_us; +}; + +static const struct t6030_quiesce_write t6030_quiesce_sd[] = { + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00066f, 0 }, + { T6030_QBLK_PCIE_INTR1, 0x20, 0x7, 434 }, + { T6030_QBLK_PCIE_PORT1, 0x104, 0xff5527f0, 33 }, + { T6030_QBLK_PCIE_PORT1, 0x100, 0xf0, 2 }, + { T6030_QBLK_PCIE_PORT1, 0x800, 0x100101, 9 }, + { T6030_QBLK_PCIE_PORT1, 0x88, 0x11, 2 }, + { T6030_QBLK_PINCTRL, 0x2a0, 0x76a02, 2559 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00066f, 5 }, + { T6030_QBLK_PCIE_DART1, 0x104, 0xffffffff, 29 }, + { T6030_QBLK_PCIE_DART1, 0x100, 0xe00000, 4 }, + { T6030_QBLK_PCIE_DART1, 0x704, 0xffffffff, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x2, 4 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x4, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x8, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x10, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x20, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x40, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x80, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x100, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x200, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x400, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x800, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x1000, 2 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x2000, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x4000, 3 }, + { T6030_QBLK_PCIE_DART1, 0xc20, 0x8000, 2 }, + { T6030_QBLK_PCIE_DART1, 0x80, 0x2000, 4 }, + { T6030_QBLK_PCIE_PORT1, 0x13c, 0x110, 13 }, + { T6030_QBLK_PCIE_PORT1, 0x82c, 0x0, 5 }, + { T6030_QBLK_PCIE_PORT1, 0x13c, 0x10, 3 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00066f, 3 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00026f, 3 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00006f, 4 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00007f, 3 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00007e, 3 }, + { T6030_QBLK_PCIE_PHY1, 0x0, 0xc000070, 5 }, + { T6030_QBLK_PCIE_PORT1, 0x800, 0x100100, 2 }, + { T6030_QBLK_PCIE_PORT1, 0x100, 0x30004200, 8 }, +}; + +static const struct t6030_quiesce_write t6030_quiesce_wifi[] = { + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 0 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 30 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 25 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 27 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 70 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 6 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 19 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 2 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 2 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 20 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 22 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 41 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 24 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 22 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 59 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 11 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 2 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 3 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 15 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 22 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 38 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 22 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 62 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 10 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 2 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 3 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 15 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 21 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 35 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 22 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 59 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 11 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 6 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 3 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 15 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 21 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 31 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 24 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 22 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 58 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 11 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 3 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 3 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 13 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 22 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 29 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 22 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 58 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 10 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 2 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 3 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 15 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 22 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 3000 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 54 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 46 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 36 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 10 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 141 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 19 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 40 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 30 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 2 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 37 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 57 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 42 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 40 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 30 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 8 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 71 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 11 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 20 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 10 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 9 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 24 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 36 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 3000 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 24 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 30 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 60 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 14 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 0 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 7 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 16 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 25 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 37 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 26 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 26 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 27 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 62 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 7 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 28 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 2 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100001, 2 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 20 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 24 }, + { T6030_QBLK_PCIE_INTR0, 0x20, 0x7, 3000 }, + { T6030_QBLK_PCIE_PORT0, 0x104, 0xff5527f0, 71 }, + { T6030_QBLK_PCIE_PORT0, 0x100, 0xf0, 5 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 23 }, + { T6030_QBLK_PCIE_PORT0, 0x88, 0x11, 2 }, + { T6030_QBLK_PINCTRL, 0x29c, 0x76a02, 2438 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00066f, 37 }, + { T6030_QBLK_PCIE_DART0, 0x104, 0xffffffff, 16 }, + { T6030_QBLK_PCIE_DART0, 0x100, 0xe00000, 7 }, + { T6030_QBLK_PCIE_DART0, 0x704, 0xffffffff, 2 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x2, 7 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x4, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x8, 4 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x10, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x20, 4 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x40, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x80, 4 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x100, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x200, 4 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x400, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x800, 11 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x1000, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x2000, 4 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x4000, 5 }, + { T6030_QBLK_PCIE_DART0, 0xc20, 0x8000, 4 }, + { T6030_QBLK_PCIE_DART0, 0x80, 0x2000, 7 }, + { T6030_QBLK_PCIE_PORT0, 0x13c, 0x110, 15 }, + { T6030_QBLK_PCIE_PORT0, 0x82c, 0x0, 6 }, + { T6030_QBLK_PCIE_PORT0, 0x13c, 0x10, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00066f, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00026f, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00006f, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00007f, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00007e, 5 }, + { T6030_QBLK_PCIE_PHY0, 0x0, 0xc000070, 6 }, + { T6030_QBLK_PCIE_PORT0, 0x800, 0x100100, 4 }, +}; + +static const struct t6030_quiesce_write t6030_quiesce_disp[] = { + { T6030_QBLK_PWRGATE, 0xe6c, 0x0, 0 }, + { T6030_QBLK_PWRGATE, 0xe90, 0x1, 20 }, + { T6030_QBLK_DISP_DART0, 0x210, 0x0, 192 }, + { T6030_QBLK_DISP_DART0, 0x80, 0x0, 79 }, + { T6030_QBLK_DISP_DART0, 0x104, 0x0, 13 }, + { T6030_QBLK_DISP_DART0, 0xc00, 0x20, 6 }, + { T6030_QBLK_PWRGATE, 0x16ec, 0x0, 4 }, + { T6030_QBLK_DISP_DART2, 0x210, 0x0, 124 }, + { T6030_QBLK_PWRGATE, 0x136c, 0x0, 64 }, + { T6030_QBLK_DISP_DART2, 0x80, 0x0, 54 }, + { T6030_QBLK_DISP_DART2, 0x104, 0x0, 19 }, + { T6030_QBLK_DISP_DART2, 0xc00, 0x20, 9 }, + { T6030_QBLK_DISP_DART1, 0x210, 0x0, 74 }, + { T6030_QBLK_DISP_DART1, 0x80, 0x0, 78 }, + { T6030_QBLK_DISP_DART1, 0x104, 0x0, 13 }, + { T6030_QBLK_DISP_DART1, 0xc00, 0x20, 6 }, + { T6030_QBLK_DISP_DART2, 0x104, 0xffffffff, 3000 }, + { T6030_QBLK_DISP_DART2, 0x100, 0x10b00000, 7 }, + { T6030_QBLK_DISP_DART2, 0x704, 0xffffffff, 2 }, + { T6030_QBLK_DISP_DART1, 0x104, 0xffffffff, 17 }, + { T6030_QBLK_DISP_DART1, 0x100, 0x10100000, 7 }, + { T6030_QBLK_DISP_DART1, 0x704, 0xffffffff, 2 }, + { T6030_QBLK_DISP_DART0, 0x104, 0xffffffff, 49 }, + { T6030_QBLK_DISP_DART0, 0x100, 0x10900000, 7 }, + { T6030_QBLK_DISP_DART0, 0x704, 0xffffffff, 2 }, + { T6030_QBLK_PWRGATE, 0x16ec, 0x3, 19 }, + { T6030_QBLK_PWRGATE, 0x136c, 0x3, 449 }, + { T6030_QBLK_PWRGATE, 0xe6c, 0x3, 219 }, + { T6030_QBLK_PWRGATE, 0xe90, 0x0, 21 }, +}; + +static const struct t6030_quiesce_write t6030_quiesce_pins[] = { + { T6030_QBLK_PINCTRL, 0x90, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0x94, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xa0, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xa4, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xa8, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xac, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xb8, 0x76a21, 0 }, + { T6030_QBLK_PINCTRL, 0xbc, 0x76a21, 0 }, +}; diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h new file mode 100644 index 0000000000000..d7dacb3347f6e --- /dev/null +++ b/drivers/soc/apple/sleep-t6030.h @@ -0,0 +1,3237 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple T6030 (M3 Pro) system suspend-to-RAM provider. Included by sleep.c. + */ + +#include "sleep-t6030-quiesce.h" +#include "sleep-t6030-ps.h" +#include "sleep-t6030-pcie-wake.h" + +/* + * Register block indices matching the reg-names order in apple,t6030-sleep.yaml. + */ +enum t6030_reg_blk { + T6030_BLK_PS = 0, + T6030_BLK_PWRGATE = 1, + T6030_BLK_CPU_START = 2, + T6030_BLK_CLLT = 3, + T6030_BLK_CLUSTER = 4, + T6030_BLK_COMMIT = 5, + T6030_BLK_WDT = 6, + T6030_BLK_WAKE = 7, + T6030_BLK_SPMI = 8, + T6030_BLK_PS_AON = 9, + T6030_BLK_SPMI_A0 = 10, + T6030_BLK_CLK_MUX = 11, + T6030_BLK_CLK_PERF = 12, + T6030_BLK_PS_GPU = 13, + T6030_BLK_AMCC0 = 14, + T6030_BLK_AMCC1 = 15, + T6030_BLK_DCS0 = 16, + T6030_BLK_PTD = 17, + T6030_BLK_CPM_E = 18, + T6030_BLK_CPM_P = 19, + T6030_BLK_AMCC0_MC = 20, + T6030_BLK_AMCC1_MC = 21, + T6030_BLK_DCS0_CH1 = 22, + T6030_BLK_DCS0_CH2 = 23, + T6030_BLK_DCS0_CH3 = 24, + T6030_BLK_DCS0_CH4 = 25, + T6030_BLK_DCS0_CH5 = 26, + T6030_BLK_DCS1_CH0 = 27, + T6030_BLK_DCS1_CH1 = 28, + T6030_BLK_DCS1_CH2 = 29, + T6030_BLK_DCS1_CH3 = 30, + T6030_BLK_DCS1_CH4 = 31, + T6030_BLK_DCS1_CH5 = 32, + T6030_BLOCKS = 33, +}; + +/* Power-state register offsets */ +#define T6030_PS_DWI 0x118 +#define T6030_PS_GPIO 0x120 +#define T6030_PS_AP_TMM 0x1a8 +#define T6030_PS_SIO 0x1b8 +#define T6030_PS_DISP_SYS 0x1c0 +#define T6030_PS_SIO_CPU 0x1d0 +#define T6030_PS_I2C6 0x220 +#define T6030_PS_DISP_FE 0x258 +#define T6030_PS_SPI2 0x270 +#define T6030_PS_DISPEXT0_SYS 0x3b8 +#define T6030_PS_DISPEXT1_SYS 0x3c0 +#define T6030_PS_DISPEXT0_FE 0x3d8 +#define T6030_PS_DISPEXT0_CPU 0x3e0 +#define T6030_PS_DISPEXT1_FE 0x3f0 +#define T6030_PS_DISPEXT1_CPU 0x3f8 +#define T6030_PS_PMP 0x4c8 +#define T6030_PS_PMS_SRAM 0x4d0 +#define T6030_PS_ATC0_COMMON 0x4e0 +#define T6030_PS_APCIE_GP 0x500 +#define T6030_PS_ANS 0x510 +#define T6030_PS_ATC1_PCIE 0x528 +#define T6030_PS_ATC2_PCIE 0x538 +#define T6030_PS_APCIE_SYS_GP 0x558 +#define T6030_PS_APCIE_ST 0x568 +#define T6030_PS_APCIE_SYS_ST 0x5b0 +#define T6030_PS_APCIE_PHY_SW 0x5b8 +#define T6030_PS_SEP 0xc00 +#define T6030_PS_DISP_CPU 0x10000 + +#define T6030_AON_NUB_GPIO 0x098 +#define T6030_AON_NUB_FABRIC 0x0a0 +#define T6030_AON_ATC0_USB_AON 0x0b8 +#define T6030_AON_ATC0_USB 0x0d8 +#define T6030_ATC_WORDS 12 + +#define T6030_PS_STAGE_BITS (PS_TARGET | PS_AUTO_ENABLE) + +#define T6030_CLUSTER_E 0x0 +#define T6030_CLUSTER_P 0x4 +#define T6030_CLLT_SLEEP 0x24 +#define T6030_RECOMMIT_US 157 + +#define T6030_PWRGATE_E_CLUSTER 0x0 +#define T6030_PWRGATE_P_CLUSTER 0x60 +#define T6030_PWRGATE_ENABLE BIT(31) +#define T6030_PWRGATE_DISPEXT1 0x16ec +#define T6030_PWRGATE_DISPEXT1_OFF 3 + +#define T6030_PS_GPU_AFR 0x100 +#define T6030_PS_GPU_AFR_ON 0x0f00000f +#define T6030_PS_GPU_AFR_AUTO 0x1f00000f + +/* SPMI / PMU registers (USID 0xb) */ +#define T6030_SPMI_EXT_WRITEL 0x30 +#define T6030_SPMI_EXT_READL 0x38 +#define T6030_SPMI_RX_EMPTY BIT(24) +#define T6030_SPMI_DONE BIT(0) +#define T6030_SPMI_MASK(n) (0x20 + 4 * (n)) +#define T6030_SPMI_ACK(n) (0x60 + 4 * (n)) +#define T6030_SPMI_POLL_US 1000 +#define T6030_SPMI_A0_ENTRY_ACK3 BIT(1) +#define T6030_SPMI_WAKE_ACK0 BIT(2) +#define T6030_SPMI_WAKE_MASK0 BIT(12) +#define T6030_SPMI_A0_WAKE_ACK2 BIT(25) +#define T6030_SPMI_A0_WAKE_MASK2 BIT(31) + +#define T6030_RTC_CTL 0x2000 +#define T6030_RTC_CTL_ARMED BIT(6) +#define T6030_RTC_CTL_FIRED BIT(1) +#define T6030_RTC_COUNTER 0x2002 +#define T6030_RTC_COMPARE 0x2008 +#define T6030_RTC_MASK 0x200e + +#define T6030_WAKE_MASK 0x08 +#define T6030_WAKE_STATUS 0x24 +#define T6030_WAKE_WORDS 7 +#define T6030_WAKE_LAST_BITS GENMASK(24, 0) +#define T6030_LAST_I2C6 0x3f0 + +/* PTD sub-window offsets within T6030_BLK_PTD (0x20000 bytes) */ +#define T6030_PTD_READ_OFF 0x1000 +#define T6030_PTD_UPDATE_OFF 0x10000 +#define T6030_PTD_CTRL_OFF 0x18000 +#define T6030_PTD_MIN_SIZE 0x20000 +#define T6030_PTD_TGT_READ 0x180 +#define T6030_PTD_ACTUAL 0x1c0 +#define T6030_PTD_REQUEST 0x8c0 +#define T6030_PTD_DVFS0 0x900 +#define T6030_PTD_DVFS0_VOTE (BIT_ULL(61) | 1) +#define T6030_PTD_SLEEP_CTRL 0x328 +#define T6030_PTD_SLEEP_CTRL_ENTRY 0x80000 +#define T6030_MASK_AT_PMVC 0x10040ULL +#define T6030_MASK_LATE 0x10000ULL +#define T6030_PTD_ACK_US 50000 +#define T6030_MASK_LATE_TO_SLPA_US 1036600 +#define T6030_LAST_DVFS0_TO_SLPA_US (15200 + 4200) +#define T6030_LATE_TO_SLPA_US 15200 + +/* PMP mailbox and DART quiesce registers */ +#define T6030_MBOX_A2I_CONTROL 0x110 +#define T6030_MBOX_I2A_CONTROL 0x114 +#define T6030_MBOX_CONTROL_FULL BIT(16) +#define T6030_MBOX_CONTROL_EMPTY BIT(17) +#define T6030_MBOX_I2A_IRQ BIT(0) +#define T6030_MBOX_A2I_SEND0 0x800 +#define T6030_MBOX_A2I_SEND1 0x808 +#define T6030_MBOX_I2A_RECV0 0x830 +#define T6030_MBOX_I2A_RECV1 0x838 +#define T6030_RTKIT_MGMT_TYPE GENMASK_ULL(59, 52) +#define T6030_RTKIT_SET_IOP_PWR 0x6 +#define T6030_RTKIT_SET_IOP_PWR_ACK 0x7 +#define T6030_RTKIT_SET_AP_PWR 0xb +#define T6030_RTKIT_PWR_IDLE 0x201 +#define T6030_PMP_ACK_US 10000 +#define T6030_PMP_DRAIN 32 +#define T6030_PMP_TO_SRAM_US 10680 + +#define T6030_DART_ERROR 0x100 +#define T6030_DART_ERROR_MASK 0x104 +#define T6030_DART_704 0x704 +#define T6030_DART_SEP_ERROR_CLEAR 0x10000000 +#define T6030_DART_MTP_ERROR_CLEAR 0x10100000 + +/* GP PCIe PHY park and clock registers */ +#define T6030_GP_PHY_CTRL 0x0 +#define T6030_GP_PHY_CFG 0x4 +#define T6030_GP_PHYIP_6C 0x6c +#define T6030_GP_PHYIP_7C 0x7c +#define T6030_GP_AXI2AF_600 0x600 +#define T6030_GP_CLK_CTRL 0x0 +#define T6030_GP_CLK_BUSY BIT(31) +#define T6030_GP_POLL_US 1000 +#define T6030_GP_PERST_PORTS 2 + +/* Cluster power manager (CPM) registers */ +#define T6030_CPM_CNT0 0x8000 +#define T6030_CPM_CNT1 0x8008 +#define T6030_CPM_CTL 0x8080 +#define T6030_CPM_ENA 0x40f8 +#define T6030_CPM_B63_0 0x8400 +#define T6030_CPM_B63_1 0x8408 +#define T6030_CPM_B63_2 0x0270 +#define T6030_CPM_B63_3 0x0250 +#define T6030_CPM_TABLE 0x4018 +#define T6030_CPM_TABLE_STRIDE 0x10 +#define T6030_CPM_CFG 0x4180 +#define T6030_CPM_CFG_ON 3 +#define T6030_CPM_B63 BIT_ULL(63) + +/* SLC plane status registers */ +#define T6030_SLC_PLANE_STATUS 0x1c04 +#define T6030_SLC_STATUS_ON 0x2100 +#define T6030_SLC_PLANES 6 + +/* CPU cache and WFI sysregs (M3 generation) */ +#define T6030_HID4 sys_reg(3, 0, 15, 4, 0) +#define T6030_EHID4 sys_reg(3, 0, 15, 4, 1) +#define T6030_HID4_DISABLE_DC_MVA BIT_ULL(11) +#define T6030_HID4_DISABLE_DC_SW_L2 BIT_ULL(44) +#define T6030_HID4_DC_MASK (T6030_HID4_DISABLE_DC_MVA | T6030_HID4_DISABLE_DC_SW_L2) +#define T6030_MPIDR_PCORE BIT_ULL(16) +#define T6030_CYC_OVRD sys_reg(3, 5, 15, 5, 0) +#define T6030_CYC_OVRD_WFI_MODE GENMASK_ULL(25, 24) +#define T6030_CYC_OVRD_DISABLE_WFI_RET BIT_ULL(0) + +static int t6030_slc_off(void); +static void t6030_slc_on(struct apple_sleep *s); + +/* + * DT register-sequence engine (apple,seq-prepare/notice/commit/wake-early/wake) + */ +enum { + T6030_OP_WRITE, T6030_OP_READ, T6030_OP_SET, T6030_OP_CLEAR, T6030_OP_REWRITE, + T6030_OP_WAIT_SET, T6030_OP_WAIT_CLEAR, T6030_OP_WRITE16, T6030_OP_WRITE64_HI, + T6030_OP_CLEAR64, T6030_OP_SET64, T6030_OP_READ64, T6030_OP_RESTORE, T6030_OP_RESTORE64, + T6030_OP_IF_SAVED, T6030_OP_IF_SAVED64, T6030_OP_SLC_OFF, T6030_OP_CLEAR64_WAY, +}; + +#define T6030_OP_KIND GENMASK(7, 0) +#define T6030_OP_OPTIONAL BIT(8) +#define T6030_OP_RESERVED GENMASK(15, 9) +#define T6030_OP_TIMEOUT GENMASK(31, 16) +#define T6030_OP_SPAN T6030_OP_TIMEOUT + +struct t6030_seq { + const u32 *op; + unsigned int n; + u64 *saved; + bool have_saved; +}; + +static unsigned int t6030_op_width(u32 kind) +{ + switch (kind) { + case T6030_OP_WRITE16: + return 2; + case T6030_OP_WRITE ... T6030_OP_WAIT_CLEAR: + case T6030_OP_RESTORE: + case T6030_OP_IF_SAVED: + return 4; + case T6030_OP_WRITE64_HI ... T6030_OP_READ64: + case T6030_OP_RESTORE64: + case T6030_OP_IF_SAVED64: + case T6030_OP_CLEAR64_WAY: + return 8; + default: + return 0; + } +} + +static bool t6030_op_saved(u32 kind) +{ + return kind >= T6030_OP_RESTORE && kind <= T6030_OP_IF_SAVED64; +} + +static int t6030_op_check(const u32 *op, unsigned int i, unsigned int n, u32 size, bool saves) +{ + const u32 *e = &op[4 * i]; + u32 kind = FIELD_GET(T6030_OP_KIND, e[0]), span = FIELD_GET(T6030_OP_SPAN, e[0]); + unsigned int width = t6030_op_width(kind); + bool wait = kind == T6030_OP_WAIT_SET || kind == T6030_OP_WAIT_CLEAR; + bool guard = kind == T6030_OP_IF_SAVED || kind == T6030_OP_IF_SAVED64; + + if (kind == T6030_OP_SLC_OFF) + return ((e[0] & ~T6030_OP_KIND) || e[1] || e[2] || e[3]) ? -ERANGE : 0; + if (!width || size < width || e[2] > size - width || (e[2] % width) || + (e[0] & T6030_OP_RESERVED)) + return -ERANGE; + if (((e[0] & T6030_OP_OPTIONAL) && !wait) || (span && !wait && !guard)) + return -ERANGE; + if (t6030_op_saved(kind) && !saves) + return -ERANGE; + if ((kind == T6030_OP_RESTORE || kind == T6030_OP_RESTORE64) && e[3]) + return -ERANGE; + if (kind == T6030_OP_CLEAR64_WAY) { + u64 way_off; + + if (hweight32(e[3]) != 1) + return -ERANGE; + way_off = (u64)e[2] + 0x1000 + 8ULL * __ffs(e[3]); + if (way_off > size - 8) + return -ERANGE; + } + if (guard && (!span || span >= n - i)) + return -ERANGE; + return 0; +} + +static int t6030_seq_check_spans(const u32 *op, unsigned int n) +{ + unsigned int i, j; + + for (i = 0; i < n; i++) { + u32 kind = FIELD_GET(T6030_OP_KIND, op[4 * i]); + u32 end = i + FIELD_GET(T6030_OP_SPAN, op[4 * i]); + + if (kind != T6030_OP_IF_SAVED && kind != T6030_OP_IF_SAVED64) + continue; + for (j = i + 1; j <= end && j < n; j++) { + u32 inner = FIELD_GET(T6030_OP_KIND, op[4 * j]); + + if ((inner == T6030_OP_IF_SAVED || inner == T6030_OP_IF_SAVED64) && + j + FIELD_GET(T6030_OP_SPAN, op[4 * j]) > end) + return -ERANGE; + } + } + return 0; +} + +static int t6030_seq_get(struct apple_sleep *s, const char *name, struct t6030_seq *seq, + u32 (*block_size)(struct apple_sleep *s, u32 b), bool saves) +{ + int len = of_property_count_u32_elems(s->dev->of_node, name); + bool saved = false; + unsigned int i; + u32 *op; + + seq->n = 0; + seq->saved = NULL; + seq->have_saved = false; + if (len <= 0) + return 0; + if (len % 4) + return dev_err_probe(s->dev, -EINVAL, "%s: not in fours\n", name); + op = devm_kcalloc(s->dev, len, sizeof(*op), GFP_KERNEL); + if (!op) + return -ENOMEM; + if (of_property_read_u32_array(s->dev->of_node, name, op, len)) + return -EINVAL; + for (i = 0; i < len / 4; i++) { + u32 kind = FIELD_GET(T6030_OP_KIND, op[4 * i]); + u32 size = t6030_op_width(kind) ? block_size(s, op[4 * i + 1]) : 0; + + if (t6030_op_check(op, i, len / 4, size, saves)) { + devm_kfree(s->dev, op); + return dev_err_probe(s->dev, -ERANGE, + "%s: entry %u malformed or out of bounds\n", name, i); + } + saved |= t6030_op_saved(kind); + } + if (t6030_seq_check_spans(op, len / 4)) { + devm_kfree(s->dev, op); + return dev_err_probe(s->dev, -ERANGE, "%s: guard spans cross\n", name); + } + if (saved) { + seq->saved = devm_kcalloc(s->dev, len / 4, sizeof(*seq->saved), GFP_KERNEL); + if (!seq->saved) + return -ENOMEM; + } + seq->op = op; + seq->n = len / 4; + return 0; +} + +static void t6030_seq_save(void __iomem *const *blk, struct t6030_seq *seq) +{ + unsigned int i; + + for (i = 0; i < seq->n; i++) { + const u32 *op = &seq->op[4 * i]; + u32 kind = FIELD_GET(T6030_OP_KIND, op[0]); + + if (!t6030_op_saved(kind)) + continue; + if (t6030_op_width(kind) == 8) + seq->saved[i] = readq(blk[op[1]] + op[2]); + else + seq->saved[i] = readl(blk[op[1]] + op[2]); + } + seq->have_saved = true; +} + +static int t6030_seq_run_strict(void __iomem *const *blk, const struct t6030_seq *seq) +{ + unsigned int i; + u32 v; + + for (i = 0; i < seq->n; i++) { + const u32 *op = &seq->op[4 * i]; + u32 kind = FIELD_GET(T6030_OP_KIND, op[0]); + void __iomem *reg = (kind == T6030_OP_SLC_OFF) ? NULL : blk[op[1]] + op[2]; + u32 ms = FIELD_GET(T6030_OP_TIMEOUT, op[0]) ?: 10; + u32 span = FIELD_GET(T6030_OP_SPAN, op[0]); + int ret = 0; + + switch (kind) { + case T6030_OP_WRITE: + writel(op[3], reg); + break; + case T6030_OP_READ: + readl(reg); + break; + case T6030_OP_SET: + writel(readl(reg) | op[3], reg); + break; + case T6030_OP_CLEAR: + writel(readl(reg) & ~op[3], reg); + break; + case T6030_OP_REWRITE: + writel(readl(reg), reg); + break; + case T6030_OP_WAIT_SET: + ret = readl_poll_timeout_atomic(reg, v, (v & op[3]) == op[3], 1, ms * 1000); + break; + case T6030_OP_WAIT_CLEAR: + ret = readl_poll_timeout_atomic(reg, v, !(v & op[3]), 1, ms * 1000); + break; + case T6030_OP_WRITE16: + writew(op[3], reg); + break; + case T6030_OP_WRITE64_HI: + writeq((u64)op[3] << 32, reg); + break; + case T6030_OP_CLEAR64: + writeq(readq(reg) & ~(u64)op[3], reg); + break; + case T6030_OP_SLC_OFF: + ret = t6030_slc_off(); + break; + case T6030_OP_CLEAR64_WAY: { + void __iomem *way = reg + 0x1000 + 8 * __ffs(op[3]); + + readq(way); + writeq(readq(reg) & ~(u64)op[3], reg); + readq(way); + break; + } + case T6030_OP_SET64: + writeq(readq(reg) | op[3], reg); + break; + case T6030_OP_READ64: + readq(reg); + break; + case T6030_OP_RESTORE: + if (seq->have_saved) + writel(seq->saved[i], reg); + else + ret = -ENODATA; + break; + case T6030_OP_RESTORE64: + if (seq->have_saved) + writeq(seq->saved[i], reg); + else + ret = -ENODATA; + break; + case T6030_OP_IF_SAVED: + case T6030_OP_IF_SAVED64: + if (!seq->have_saved) + ret = -ENODATA; + if (ret || !(seq->saved[i] & op[3])) + i += span; + break; + } + if (ret && !(op[0] & T6030_OP_OPTIONAL)) + return ret; + } + return 0; +} + +/* + * Power-domain inventory and wake ordering tables + */ +static const u32 t6030_ps_all[] = { + 0x0, 0x8, 0x10, 0x18, 0x20, 0x28, 0x30, 0x38, 0x40, 0x48, + 0x50, 0x58, 0x60, 0x68, 0x108, 0x110, 0x118, 0x120, 0x138, 0x140, + 0x148, 0x150, 0x158, 0x160, 0x168, 0x170, 0x178, 0x180, 0x190, 0x1a8, + 0x1b8, 0x1c0, 0x1c8, 0x1d0, 0x1d8, 0x1e0, 0x1e8, 0x1f0, 0x1f8, 0x200, + 0x208, 0x210, 0x218, 0x220, 0x228, 0x230, 0x238, 0x240, 0x248, 0x250, + 0x258, 0x260, 0x268, 0x270, 0x278, 0x280, 0x288, 0x290, 0x298, 0x2a0, + 0x2a8, 0x2b0, 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2d8, 0x2e0, 0x2e8, 0x2f0, + 0x2f8, 0x300, 0x308, 0x388, 0x390, 0x398, 0x3a0, 0x3a8, 0x3b0, 0x3b8, + 0x3c0, 0x3c8, 0x3d0, 0x3d8, 0x3e0, 0x3e8, 0x3f0, 0x3f8, 0x408, 0x490, + 0x498, 0x4a0, 0x4a8, 0x4b0, 0x4b8, 0x4c0, 0x4c8, 0x4d0, 0x4d8, 0x4e0, + 0x4e8, 0x4f0, 0x4f8, 0x500, 0x508, 0x510, 0x518, 0x520, 0x528, 0x530, + 0x538, 0x540, 0x548, 0x550, 0x558, 0x560, 0x568, 0x570, 0x578, 0x580, + 0x588, 0x590, 0x598, 0x5a0, 0x5a8, 0x5b0, 0x5b8, 0xc00, 0x4000, 0x4008, + 0x4010, 0x4018, 0x4020, 0x4028, 0x8000, 0x8008, 0x8010, 0x8018, 0x8020, 0xc000, + 0xc008, 0xc010, 0xc018, 0x10000, +}; + +static const u32 t6030_ps_aon_all[] = { + 0x0, 0x58, 0x60, 0x68, 0x70, 0x78, 0x88, 0x90, 0x98, 0xa0, + 0xa8, 0xb0, 0xb8, 0xc0, 0xc8, 0xd0, 0xd8, 0xe0, 0xe8, 0xf0, +}; + +/* + * 14 domains staged ON with AUTO_ENABLE across firmware sleep entry. + */ +static const u32 t6030_ps_macos_on[] = { + 0x120, /* GPIO */ + 0x1f0, 0x210, 0x228, 0x230, /* I2C0/4/7/8 */ + 0x260, /* SPI0 */ + 0x2a8, 0x2b0, 0x2b8, 0x2c0, 0x2c8, 0x2d0, /* UART1-6 */ + 0x408, /* DPTX_PHY */ + 0x118, /* DWI */ +}; + +/* + * 11 ON domains requiring AUTO_ENABLE before sleep commit (9 in ps, 2 in ps-aon). + */ +static const u32 t6030_ps_boot_auto[] = { + 0x110, /* AIC */ + 0x170, /* SOC_DPE */ + 0x238, /* SPI_P */ + 0x240, /* UART_P */ + 0x248, /* AUDIO_P */ + 0x2a0, /* UART0 */ + 0x2e0, /* DPA0 */ + 0x500, /* APCIE_GP */ + 0x568, /* APCIE_ST */ +}; + +static const u32 t6030_ps_aon_boot_auto[] = { + T6030_AON_NUB_GPIO, /* NUB_GPIO */ + T6030_AON_NUB_FABRIC, /* NUB_FABRIC */ +}; + +/* + * 25 domains lowered off at commit in child-before-parent order. + * Always-on CPU and fabric domains are intentionally excluded. + * + * In ps-aon, ATC0_USB (0xd8) and ATC0_USB_AON (0xb8) lower before their + * parent ATC0_COMMON (ps 0x4e0). + */ +static const u32 t6030_ps_aon_macos_off[] = { + T6030_AON_ATC0_USB, /* ATC0_USB */ + T6030_AON_ATC0_USB_AON, /* ATC0_USB_AON */ + 0x090, /* NUB_OCLA */ + 0x088, /* NUB_SPI0 */ +}; + +static const u32 t6030_ps_macos_off[] = { + 0x4f8, /* ATC3_COMMON */ + 0x4e0, /* ATC0_COMMON */ + 0x300, 0x2f8, 0x2f0, 0x2e8, /* DPA4..1 */ + 0x218, 0x1e8, 0x1e0, 0x190, 0x178, /* I2C5, FPWM2/1, AFT0, PMGR_SOC_OCLA */ + 0x158, 0x150, 0x148, 0x140, 0x138, /* PMS_FPWM4..0 */ + 0x108, /* MSG */ + 0x398, 0x390, /* MCA3, MCA2 */ + 0x4e8, 0x4f0, /* ATC1/2_COMMON */ +}; + +/* + * Coprocessor/PHY power words lowered in macOS's two-write form: + * SIO_CPU, PMP, PMS_SRAM, and APCIE_PHY_SW. + */ +enum { T6030_LOWER_SIO_CPU, T6030_LOWER_PMP, T6030_LOWER_PMS_SRAM, T6030_LOWER_PHY }; + +static const u32 t6030_lowered[] = { + T6030_PS_SIO_CPU, T6030_PS_PMP, T6030_PS_PMS_SRAM, T6030_PS_APCIE_PHY_SW, +}; + +static const u32 t6030_lowered_macos[][2] = { + { 0x0400004f, 0x04000340 }, /* SIO_CPU */ + { 0x0f0f00ff, 0x0f0f03f0 }, /* PMP */ + { 0x0000000f, 0x00000300 }, /* PMS_SRAM */ + { 0x0400004f, 0x04000340 }, /* APCIE_PHY_SW */ +}; + +/* SIO and SIO_CPU: apple,seq-commit clears AUTO_ENABLE */ +static const u32 t6030_auto_off[] = { T6030_PS_SIO, T6030_PS_SIO_CPU }; + +/* + * Wake PS restore order, + * split around seq-wake and the SPMI notify mask restore. + */ +#define T6030_AON(offset) (SLEEP_PS_WAKE_AON | (offset)) + +static const u32 t6030_ps_wake_early[] = { + 0xc00, T6030_AON(0x98), 0x110, 0x118, 0x120, 0x170, 0x1b8, 0x1f0, 0x210, 0x228, 0x230, + 0x238, 0x240, 0x248, 0x260, 0x2a0, 0x2a8, 0x2b0, 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2e0, + 0x408, 0x500, 0x510, 0x558, 0x568, 0x5b0, +}; + +static const u32 t6030_ps_wake_mid[] = { + 0x5b8, 0x2d8, 0x308, 0x388, 0x390, 0x398, T6030_PS_PMS_SRAM, T6030_PS_PMP, 0x1d0, +}; + +static const u32 t6030_ps_wake_late[] = { + 0x3b8, 0x3d8, 0x3e0, 0x3c0, 0x3f0, 0x3f8, 0x1c0, 0x258, 0x10000, 0x1f8, 0x208, 0x200, + 0x270, +}; + +static const u32 t6030_ps_wake_order[] = { + 0xc00, 0x110, 0x118, 0x120, 0x170, 0x1b8, 0x1f0, 0x210, 0x228, 0x230, 0x238, 0x240, + 0x248, 0x260, 0x2a0, 0x2a8, 0x2b0, 0x2b8, 0x2c0, 0x2c8, 0x2d0, 0x2e0, 0x408, 0x500, + 0x510, 0x558, 0x568, 0x5b0, + 0x5b8, 0x2d8, 0x308, 0x388, 0x390, 0x398, 0x4d0, 0x4c8, 0x1d0, + 0x3b8, 0x3d8, 0x3e0, 0x3c0, 0x3f0, 0x3f8, 0x1c0, 0x258, 0x10000, 0x1f8, 0x208, 0x200, + 0x270, +}; + +static const u32 t6030_ps_aon_wake_order[] = { T6030_AON_NUB_GPIO }; + +static const struct apple_sleep_words t6030_wake_early_words = SLEEP_WORDS(t6030_ps_wake_early); +static const struct apple_sleep_words t6030_wake_mid_words = SLEEP_WORDS(t6030_ps_wake_mid); +static const struct apple_sleep_words t6030_wake_late_words = SLEEP_WORDS(t6030_ps_wake_late); +static const u32 t6030_i2c6_regs[] = { 0x38, 0x30, 0x2c }; + +struct t6030_ps_wake_sample { + u32 before, saved, active, after; + u32 us; +}; + +/* Singleton T6030 sleep provider state */ +static struct t6030_sleep { + void __iomem *blk[T6030_BLOCKS]; + u32 blk_size[T6030_BLOCKS]; + struct t6030_seq prepare, notice, commit, wake_early, wake; + + void __iomem *gp_phy, *gp_phy_ip, *gp_clkgen, *gp_axi2af; + void __iomem *gp_cio3pll, *gp_rc, *gp_phy_common; + u32 perst_pin[T6030_GP_PERST_PORTS]; + bool perst_valid[T6030_GP_PERST_PORTS]; + int gp_park_ret; + + void __iomem *ptd_read, *ptd_update, *ptd_ctrl; + void __iomem *pmp_mbox, *mtp_dart, *dart_sep, *i2c6; + void __iomem *cpm[2]; + void __iomem *slc_multicast[2]; + void __iomem *qblk[T6030_QBLK_COUNT]; + + bool mem_configured; + bool slc_disabled; + u32 atc_saved[T6030_ATC_WORDS]; + u32 atc_lowered; + u32 i2c6_ps_saved; + u32 i2c6_regs_saved[ARRAY_SIZE(t6030_i2c6_regs)]; + bool i2c6_ps_staged; + bool i2c6_saved; + + u32 notify_saved[2]; + bool notify_staged; + u32 wake_saved[T6030_WAKE_WORDS]; + bool wake_masks_staged; + u32 wake_pending[T6030_WAKE_WORDS]; + u32 wake_status[T6030_WAKE_WORDS]; + + u8 alarm_compare[4]; + bool alarm_valid; + bool pmu_wake_pending; + + u32 gate_dispext1_saved; + bool gate_dispext1_staged; + u32 ptd_sleep_ctrl_saved; + bool ptd_sleep_ctrl_staged; + + u32 lowered_saved[ARRAY_SIZE(t6030_lowered)]; + unsigned int nlowered; + struct t6030_ps_wake_sample pms_sram_wake, pmp_wake; + u32 pmp_wake_timeout; + bool pmp_wake_sampled; + u32 auto_off_saved[ARRAY_SIZE(t6030_auto_off)]; + bool auto_staged; + + /* Pre-sleep PS save/restore state for display-off staging and commit lowering */ + u32 ps_on_saved[ARRAY_SIZE(t6030_ps_on_order)]; + u32 ps_auto_saved[ARRAY_SIZE(t6030_ps_auto_order)]; + bool ps_display_staged; + u32 ps_lower_saved[ARRAY_SIZE(t6030_ps_lower_order)]; + DECLARE_BITMAP(ps_lowered, ARRAY_SIZE(t6030_ps_lower_order)); + u32 dart_sep_err_mask_saved, dart_sep_704_saved; + bool dart_sep_staged; + u32 ps_extra_saved[ARRAY_SIZE(t6030_ps_entries)]; + DECLARE_BITMAP(ps_extra_lowered, ARRAY_SIZE(t6030_ps_entries)); +} t6030; + +static struct apple_sleep_smc_policy t6030_smc_policy; + +/* + * Cache maintenance (HID4/EHID4 unblocked PoP/PoC) + */ +static __always_inline u64 t6030_dc_unblock(void) +{ + bool pcore = read_cpuid_mpidr() & T6030_MPIDR_PCORE; + u64 hid4 = pcore ? read_sysreg_s(T6030_HID4) : read_sysreg_s(T6030_EHID4); + + if (hid4 & T6030_HID4_DC_MASK) { + if (pcore) + write_sysreg_s(hid4 & ~T6030_HID4_DC_MASK, T6030_HID4); + else + write_sysreg_s(hid4 & ~T6030_HID4_DC_MASK, T6030_EHID4); + isb(); + } + return hid4; +} + +static __always_inline void t6030_dc_reblock(u64 hid4) +{ + if (!(hid4 & T6030_HID4_DC_MASK)) + return; + if (read_cpuid_mpidr() & T6030_MPIDR_PCORE) + write_sysreg_s(hid4, T6030_HID4); + else + write_sysreg_s(hid4, T6030_EHID4); + isb(); +} + +static void t6030_clean_range(unsigned long start, unsigned long end) +{ + unsigned long line = 4UL << ((read_cpuid_cachetype() >> CTR_EL0_DminLine_SHIFT) & 0xf); + unsigned int dpb = cpuid_feature_extract_unsigned_field(read_sysreg(id_aa64isar1_el1), + ID_AA64ISAR1_EL1_DPB_SHIFT); + unsigned long addr = start & ~(line - 1); + + if (dpb >= 2) { + for (; addr < end; addr += line) + asm volatile("sys #3, c7, c13, #1, %0" : : "r"(addr) : "memory"); + } else if (dpb >= 1) { + for (; addr < end; addr += line) + asm volatile("sys #3, c7, c12, #1, %0" : : "r"(addr) : "memory"); + } else { + for (; addr < end; addr += line) + asm volatile("dc civac, %0" : : "r"(addr) : "memory"); + } + dsb(sy); +} + +static __always_inline void t6030_clean_all_levels(void) +{ + u64 clidr, ccidx, lvl, ctype, ccsidr, lshift, way, mset, wshift, set, tmp; + + asm volatile( + "dsb sy\n\t" + "mrs %[clidr], clidr_el1\n\t" + "mrs %[ccidx], id_aa64mmfr2_el1\n\t" + "ubfx %[ccidx], %[ccidx], #20, #4\n\t" + "mov %[lvl], #0\n\t" + "1:\n\t" + "cmp %[lvl], #7\n\t" + "b.hs 5f\n\t" + "add %[tmp], %[lvl], %[lvl], lsl #1\n\t" + "lsr %[ctype], %[clidr], %[tmp]\n\t" + "and %[ctype], %[ctype], #7\n\t" + "cbz %[ctype], 5f\n\t" + "cmp %[ctype], #2\n\t" + "b.lo 4f\n\t" + "cmp %[ctype], #4\n\t" + "b.hi 4f\n\t" + "lsl %[tmp], %[lvl], #1\n\t" + "msr csselr_el1, %[tmp]\n\t" + "isb\n\t" + "mrs %[ccsidr], ccsidr_el1\n\t" + "and %[lshift], %[ccsidr], #7\n\t" + "add %[lshift], %[lshift], #4\n\t" + "cbnz %[ccidx], 20f\n\t" + "ubfx %[way], %[ccsidr], #3, #10\n\t" + "ubfx %[mset], %[ccsidr], #13, #15\n\t" + "b 21f\n\t" + "20:\n\t" + "ubfx %[way], %[ccsidr], #3, #21\n\t" + "ubfx %[mset], %[ccsidr], #32, #24\n\t" + "21:\n\t" + "clz %w[wshift], %w[way]\n\t" + "2:\n\t" + "mov %[set], %[mset]\n\t" + "lsl %[ctype], %[way], %[wshift]\n\t" + "orr %[ctype], %[ctype], %[lvl], lsl #1\n\t" + "3:\n\t" + "lsl %[tmp], %[set], %[lshift]\n\t" + "orr %[tmp], %[ctype], %[tmp]\n\t" + "dc csw, %[tmp]\n\t" + "subs %[set], %[set], #1\n\t" + "b.ge 3b\n\t" + "subs %[way], %[way], #1\n\t" + "b.ge 2b\n\t" + "dsb sy\n\t" + "4:\n\t" + "add %[lvl], %[lvl], #1\n\t" + "b 1b\n\t" + "5:\n\t" + "msr csselr_el1, xzr\n\t" + "dsb sy\n\t" + "isb\n\t" + : [clidr] "=&r"(clidr), [ccidx] "=&r"(ccidx), [lvl] "=&r"(lvl), + [ctype] "=&r"(ctype), [ccsidr] "=&r"(ccsidr), [lshift] "=&r"(lshift), + [way] "=&r"(way), [mset] "=&r"(mset), [wshift] "=&r"(wshift), + [set] "=&r"(set), [tmp] "=&r"(tmp) + : + : "cc", "memory"); +} + +static bool t6030_va_mapped(unsigned long addr) +{ + pgd_t *pgdp = pgd_offset_k(addr); + p4d_t *p4dp; + pud_t *pudp, pud; + pmd_t *pmdp, pmd; + + if (pgd_none(READ_ONCE(*pgdp)) || pgd_bad(READ_ONCE(*pgdp))) + return false; + p4dp = p4d_offset(pgdp, addr); + if (p4d_none(READ_ONCE(*p4dp)) || p4d_bad(READ_ONCE(*p4dp))) + return false; + pudp = pud_offset(p4dp, addr); + pud = READ_ONCE(*pudp); + if (pud_none(pud)) + return false; + if (pud_leaf(pud)) + return pud_valid(pud); + if (pud_bad(pud)) + return false; + pmdp = pmd_offset(pudp, addr); + pmd = READ_ONCE(*pmdp); + if (pmd_none(pmd)) + return false; + if (pmd_leaf(pmd)) + return pmd_valid(pmd); + if (pmd_bad(pmd)) + return false; + return pte_valid(READ_ONCE(*pte_offset_kernel(pmdp, addr))); +} + +struct t6030_run { + unsigned long start, end; +}; + +static void t6030_run_add(struct t6030_run *r, unsigned long va) +{ + if (r->start && va == r->end) { + r->end += PAGE_SIZE; + return; + } + if (r->start) + t6030_clean_range(r->start, r->end); + r->start = va; + r->end = va + PAGE_SIZE; +} + +static void t6030_run_end(struct t6030_run *r) +{ + if (r->start) + t6030_clean_range(r->start, r->end); + r->start = 0; +} + +static void t6030_clean_obj(const void *p, size_t size) +{ + if (p && size) + t6030_clean_range((unsigned long)p, (unsigned long)p + size); +} + +static void t6030_sleep_clean_ram(void) +{ + struct t6030_run run = {}; + struct memblock_region *reg; + unsigned long va; + u64 hid4 = t6030_dc_unblock(); + + for_each_mem_region(reg) { + unsigned long pfn = PFN_UP(reg->base), end = PFN_DOWN(reg->base + reg->size); + + if (memblock_is_nomap(reg)) + continue; + while (pfn < end) { + struct page *page; + unsigned long nr = 1; + + if (!pfn_valid(pfn)) { + t6030_run_end(&run); + pfn++; + continue; + } + page = pfn_to_page(pfn); + if (PageBuddy(page)) { + unsigned long order = page_private(page); + + if (order <= MAX_PAGE_ORDER && IS_ALIGNED(pfn, 1UL << order)) + nr = min(1UL << order, end - pfn); + t6030_run_end(&run); + pfn += nr; + continue; + } + va = (unsigned long)page_address(page); + if (!PageOffline(page) && va && t6030_va_mapped(va)) + t6030_run_add(&run, va); + else + t6030_run_end(&run); + pfn++; + } + t6030_run_end(&run); + } + for (va = (unsigned long)_text & PAGE_MASK; va < PAGE_ALIGN((unsigned long)_end); + va += PAGE_SIZE) { + if (t6030_va_mapped(va)) + t6030_run_add(&run, va); + else + t6030_run_end(&run); + } + t6030_run_end(&run); + t6030_dc_reblock(hid4); +} + +static void t6030_sleep_clean(struct apple_sleep *s) +{ + const struct apple_sleep_soc *soc = s->soc; + unsigned int i, stash_n = mpidr_hash_size(); + size_t pcpu = __per_cpu_end - __per_cpu_start; + u64 hid4 = t6030_dc_unblock(); + + t6030_clean_range((unsigned long)_sdata, (unsigned long)_end); + for_each_possible_cpu(i) + t6030_clean_obj(__per_cpu_start + per_cpu_offset(i), pcpu); + t6030_clean_obj(task_stack_page(current), THREAD_SIZE); + t6030_clean_obj(current, sizeof(*current)); + t6030_clean_obj(s, sizeof(*s)); + t6030_clean_obj(s->ps_commit, soc->ps_all.count * sizeof(*s->ps_commit)); + t6030_clean_obj(s->ps_aon_commit, soc->ps_aon_all.count * sizeof(*s->ps_aon_commit)); + if (s->pins_saved && s->npins) + t6030_clean_obj(s->pins_saved, s->npins * sizeof(*s->pins_saved)); + if (s->pins_skip && s->npins) + t6030_clean_obj(s->pins_skip, + BITS_TO_LONGS(s->npins) * sizeof(*s->pins_skip)); + for (i = 0; i < 2; i++) { + const struct t6030_seq *seq = i ? &t6030.wake : &t6030.wake_early; + + t6030_clean_obj(seq->op, 4 * seq->n * sizeof(*seq->op)); + if (seq->saved) + t6030_clean_obj(seq->saved, seq->n * sizeof(*seq->saved)); + } + t6030_clean_obj(&t6030, sizeof(t6030)); + if (sleep_save_stash) { + t6030_clean_obj(sleep_save_stash, stash_n * sizeof(*sleep_save_stash)); + for (i = 0; i < stash_n; i++) + t6030_clean_obj((void *)READ_ONCE(sleep_save_stash[i]), + sizeof(struct sleep_stack_data)); + } + t6030_clean_obj(&sleep_save_stash, sizeof(sleep_save_stash)); + t6030_clean_obj(&mpidr_hash, sizeof(mpidr_hash)); + t6030_clean_obj(s->mbox, sizeof(*s->mbox)); + t6030_clean_all_levels(); + t6030_dc_reblock(hid4); +} + +/* + * SPMI / PMU helpers (USID 0xb) + */ +static int t6030_spmi_xfer(void __iomem *spmi, u8 usid, u32 mask, u8 opcode, u16 address, + const u8 *wr, u8 *rd, unsigned int len) +{ + u8 command = opcode | (len - 1); + unsigned int i, n; + u32 value, data; + int ret = 0; + + if (!len || len > 8 || !!wr == !!rd) + return -EINVAL; + readl(spmi + SPMI_STATUS); + writel(mask, spmi + SPMI_NOTIFY_ENABLE); + writel((u32)address << 16 | SPMI_CMD_ACTIVE | (u32)usid << 8 | command, + spmi + SPMI_CMD); + for (i = 0; wr && i < len; i += 4) { + data = 0; + for (n = 0; n < min(4U, len - i); n++) + data |= (u32)wr[i + n] << (8 * n); + writel(data, spmi + SPMI_CMD); + } + if (!readl_poll_timeout_atomic(spmi + SPMI_NOTIFY_ACK, value, + value & T6030_SPMI_DONE, 1, T6030_SPMI_POLL_US)) + writel(T6030_SPMI_DONE, spmi + SPMI_NOTIFY_ACK); + if (readl_poll_timeout_atomic(spmi + SPMI_STATUS, value, + !(value & T6030_SPMI_RX_EMPTY), 1, T6030_SPMI_POLL_US)) + return -ETIMEDOUT; + value = readl(spmi + SPMI_REPLY); + if ((value & 0xff) != command || ((value >> 8) & 0x7f) != usid || + (wr && !(value & SPMI_CMD_ACTIVE))) + ret = -EIO; + for (i = 0; !ret && rd && i < len; i += 4) { + if (readl(spmi + SPMI_STATUS) & T6030_SPMI_RX_EMPTY) { + ret = -EIO; + break; + } + data = readl(spmi + SPMI_REPLY); + for (n = 0; n < min(4U, len - i); n++) + rd[i + n] = data >> (8 * n); + } + for (i = 0; i < SPMI_DRAIN_MAX && !(readl(spmi + SPMI_STATUS) & T6030_SPMI_RX_EMPTY); i++) + readl(spmi + SPMI_REPLY); + return ret; +} + +static int t6030_pmu_xfer(struct apple_sleep *s, u32 mask, u8 opcode, u16 address, + const u8 *wr, u8 *rd, unsigned int len) +{ + return t6030_spmi_xfer(s->spmi, s->soc->pmu_usid, mask, opcode, address, wr, rd, len); +} + +/* Read and clear boot PMU stage/status latches at probe */ +static void t6030_last_pmu_boot(struct apple_sleep *s) +{ + u32 runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); + u8 stage = 0, v = 0, stat[4] = {}, zero[4] = {}; + + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_READL, 0xf801, NULL, &stage, 1); + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_READL, 0xf803, NULL, &v, 1); + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_READL, 0xf808, NULL, stat, 4); + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_WRITEL, 0xf803, zero, NULL, 1); + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_WRITEL, 0xf808, zero, NULL, 4); + writel(runtime, s->spmi + SPMI_NOTIFY_ENABLE); + dev_info(s->dev, "T6030: PMU boot stage 0xf801=%#x 0xf803=%#x 0xf808=%*phN\n", + stage, v, (int)sizeof(stat), stat); +} + +/* Drain PMU status registers before arming sleep entry */ +static void t6030_last_pmu_reads(struct apple_sleep *s) +{ + static const struct { u16 reg; u8 len; } reads[] = { + { 0xf801, 1 }, { 0xf808, 4 }, { 0xf802, 1 }, { 0xf818, 1 }, + { 0xf819, 2 }, { 0xf800, 1 }, { 0xf81f, 1 }, + }; + u32 runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); + u32 mask = runtime & ~T6030_SPMI_DONE; + u8 buf[4]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(reads); i++) + t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, reads[i].reg, NULL, buf, + reads[i].len); + writel(runtime, s->spmi + SPMI_NOTIFY_ENABLE); +} + +static void t6030_alarm_snapshot(struct apple_sleep *s, u32 runtime_mask) +{ + u32 mask = runtime_mask & ~T6030_SPMI_DONE; + u8 ctl = 0, rmask = 0, ticks[6] = {}; + u32 compare, now; + + t6030.alarm_valid = false; + if (t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, T6030_RTC_CTL, NULL, &ctl, 1) || + t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, T6030_RTC_MASK, NULL, &rmask, 1) || + t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, T6030_RTC_COMPARE, NULL, + t6030.alarm_compare, 4) || + t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, T6030_RTC_COUNTER, NULL, ticks, 6)) + goto out; + compare = get_unaligned_le32(t6030.alarm_compare); + now = get_unaligned_le32(ticks + 2); + t6030.alarm_valid = (ctl & T6030_RTC_CTL_ARMED) && !(rmask & BIT(0)) && + (s32)(compare - now) > 0; +out: + writel(runtime_mask, s->spmi + SPMI_NOTIFY_ENABLE); +} + +static void t6030_last_alarm_disarm(struct apple_sleep *s) +{ + u32 runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); + u8 v = 0x01; + + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_WRITEL, T6030_RTC_CTL, + &v, NULL, 1); + writel(runtime, s->spmi + SPMI_NOTIFY_ENABLE); +} + +/* + * CPM, cluster power-gate, and AMCC/DCS memory configuration + */ +static const u16 t6030_cpm_table[] = { + 0x8a0f, 0x800f, 0x8c0f, 0x9c0f, 0x9e0f, 0x810f, 0xb90f, 0xbe0f, 0xbf0f, 0xd40f, 0x980f, +}; + +static const u32 t6030_cpm_cfg[] = { 0, 0, 0xffffffff, 0, 0, 0, 0x6665, 0 }; + +static void t6030_cpm_b63(unsigned int c, u16 off, bool on) +{ + u64 v = readq(t6030.cpm[c] + off); + + writeq(on ? v | T6030_CPM_B63 : v & ~T6030_CPM_B63, t6030.cpm[c] + off); +} + +static void __iomem *t6030_ioremap(struct device *dev, const struct resource *res) +{ + void __iomem *base; + + if (res->flags & IORESOURCE_MEM_NONPOSTED) { + base = ioremap_np(res->start, resource_size(res)); + if (!base || + devm_add_action_or_reset(dev, apple_sleep_iounmap, (void __force *)base)) + return NULL; + return base; + } + return devm_ioremap(dev, res->start, resource_size(res)); +} + +static void t6030_cpm_init(void) +{ + unsigned int c, i; + + if (!t6030.cpm[0] || !t6030.cpm[1]) + return; + for (c = 0; c < 2; c++) { + writeq(0, t6030.cpm[c] + T6030_CPM_CNT0); + writeq(0, t6030.cpm[c] + T6030_CPM_CNT1); + writeq(readq(t6030.cpm[c] + T6030_CPM_CTL), t6030.cpm[c] + T6030_CPM_CTL); + writeq(1, t6030.cpm[c] + T6030_CPM_ENA); + } + for (c = 0; c < 2; c++) { + t6030_cpm_b63(c, T6030_CPM_B63_0, true); + t6030_cpm_b63(c, T6030_CPM_B63_1, true); + } + for (c = 0; c < 2; c++) + t6030_cpm_b63(c, T6030_CPM_B63_2, true); + for (c = 0; c < 2; c++) + t6030_cpm_b63(c, T6030_CPM_B63_3, true); + for (c = 0; c < 2; c++) { + writeq(1, t6030.cpm[c] + T6030_CPM_ENA); + for (i = 0; i < ARRAY_SIZE(t6030_cpm_table); i++) + writeq(t6030_cpm_table[i], + t6030.cpm[c] + T6030_CPM_TABLE + T6030_CPM_TABLE_STRIDE * i); + } + for (c = 0; c < 2; c++) { + for (i = 0; i < ARRAY_SIZE(t6030_cpm_cfg); i++) + writeq(t6030_cpm_cfg[i], t6030.cpm[c] + T6030_CPM_CFG + 8 * i); + writeq(T6030_CPM_CFG_ON, t6030.cpm[c] + T6030_CPM_CFG); + } +} + +static void t6030_cpm_entry(void) +{ + unsigned int c; + + if (!t6030.cpm[0] || !t6030.cpm[1]) + return; + for (c = 0; c < 2; c++) + writeq(0, t6030.cpm[c] + T6030_CPM_CTL); + for (c = 0; c < 2; c++) + t6030_cpm_b63(c, T6030_CPM_B63_3, false); + for (c = 0; c < 2; c++) + t6030_cpm_b63(c, T6030_CPM_B63_2, false); + for (c = 0; c < 2; c++) { + t6030_cpm_b63(c, T6030_CPM_B63_0, false); + t6030_cpm_b63(c, T6030_CPM_B63_1, false); + } +} + +static void t6030_pwrgate_init(struct apple_sleep *s) +{ + writel(T6030_PWRGATE_ENABLE, s->pwrgate + T6030_PWRGATE_E_CLUSTER); + writel(T6030_PWRGATE_ENABLE, s->pwrgate + T6030_PWRGATE_P_CLUSTER); + readl(s->pwrgate + T6030_PWRGATE_P_CLUSTER); +} + +struct t6030_mem_write { + u8 blk; + u32 off; + u8 width; + u64 val; +}; + +static const struct t6030_mem_write t6030_mem_config[] = { + { T6030_BLK_AMCC0, 0x24010, 64, 0x110000100501000ULL }, + { T6030_BLK_AMCC0, 0x24018, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0x24020, 64, 0x210000100501000ULL }, + { T6030_BLK_AMCC0, 0x24028, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x3ULL }, + { T6030_BLK_AMCC0, 0x24030, 64, 0x110000000500000ULL }, + { T6030_BLK_AMCC0, 0x24038, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x7ULL }, + { T6030_BLK_AMCC0, 0x24040, 64, 0x210000000500000ULL }, + { T6030_BLK_AMCC0, 0x24048, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0xfULL }, + { T6030_BLK_AMCC0, 0x24050, 64, 0x11000311492a100ULL }, + { T6030_BLK_AMCC0, 0x24058, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x1fULL }, + { T6030_BLK_AMCC0, 0x24060, 64, 0x21000311492a100ULL }, + { T6030_BLK_AMCC0, 0x24068, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x3fULL }, + { T6030_BLK_AMCC0, 0x24070, 64, 0x11000121c4121c0ULL }, + { T6030_BLK_AMCC0, 0x24078, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x7fULL }, + { T6030_BLK_AMCC0, 0x24080, 64, 0x21000121c4121c0ULL }, + { T6030_BLK_AMCC0, 0x24088, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0xffULL }, + { T6030_BLK_AMCC0, 0x24090, 64, 0x110001129b11280ULL }, + { T6030_BLK_AMCC0, 0x24098, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x1ffULL }, + { T6030_BLK_AMCC0, 0x240a0, 64, 0x210001129b11280ULL }, + { T6030_BLK_AMCC0, 0x240a8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x3ffULL }, + { T6030_BLK_AMCC0, 0x240b0, 64, 0x110001048310480ULL }, + { T6030_BLK_AMCC0, 0x240b8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x7ffULL }, + { T6030_BLK_AMCC0, 0x240c0, 64, 0x210001048310480ULL }, + { T6030_BLK_AMCC0, 0x240c8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0xfffULL }, + { T6030_BLK_AMCC0, 0x240d0, 64, 0x110001263c12600ULL }, + { T6030_BLK_AMCC0, 0x240d8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x1fffULL }, + { T6030_BLK_AMCC0, 0x240e0, 64, 0x210001263c12600ULL }, + { T6030_BLK_AMCC0, 0x240e8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x3fffULL }, + { T6030_BLK_AMCC0, 0x240f0, 64, 0x11000104c5104c0ULL }, + { T6030_BLK_AMCC0, 0x240f8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0x7fffULL }, + { T6030_BLK_AMCC0, 0x24100, 64, 0x21000104c5104c0ULL }, + { T6030_BLK_AMCC0, 0x24108, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24000, 64, 0xffffULL }, + { T6030_BLK_AMCC0, 0x64010, 64, 0x11000106c9106c0ULL }, + { T6030_BLK_AMCC0, 0x64018, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0x64020, 64, 0x21000106c9106c0ULL }, + { T6030_BLK_AMCC0, 0x64028, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x3ULL }, + { T6030_BLK_AMCC0, 0x64030, 64, 0x110001018410180ULL }, + { T6030_BLK_AMCC0, 0x64038, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x7ULL }, + { T6030_BLK_AMCC0, 0x64040, 64, 0x210001018410180ULL }, + { T6030_BLK_AMCC0, 0x64048, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0xfULL }, + { T6030_BLK_AMCC0, 0x64050, 64, 0x110001131411300ULL }, + { T6030_BLK_AMCC0, 0x64058, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x1fULL }, + { T6030_BLK_AMCC0, 0x64060, 64, 0x210001131411300ULL }, + { T6030_BLK_AMCC0, 0x64068, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x3fULL }, + { T6030_BLK_AMCC0, 0x64070, 64, 0x110001135411340ULL }, + { T6030_BLK_AMCC0, 0x64078, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x7fULL }, + { T6030_BLK_AMCC0, 0x64080, 64, 0x210001135411340ULL }, + { T6030_BLK_AMCC0, 0x64088, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0xffULL }, + { T6030_BLK_AMCC0, 0x64090, 64, 0x110001371e13700ULL }, + { T6030_BLK_AMCC0, 0x64098, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x1ffULL }, + { T6030_BLK_AMCC0, 0x640a0, 64, 0x210001371e13700ULL }, + { T6030_BLK_AMCC0, 0x640a8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x3ffULL }, + { T6030_BLK_AMCC0, 0x640b0, 64, 0x110001375e13740ULL }, + { T6030_BLK_AMCC0, 0x640b8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x7ffULL }, + { T6030_BLK_AMCC0, 0x640c0, 64, 0x210001375e13740ULL }, + { T6030_BLK_AMCC0, 0x640c8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0xfffULL }, + { T6030_BLK_AMCC0, 0x640d0, 64, 0x110001379e13780ULL }, + { T6030_BLK_AMCC0, 0x640d8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x1fffULL }, + { T6030_BLK_AMCC0, 0x640e0, 64, 0x210001379e13780ULL }, + { T6030_BLK_AMCC0, 0x640e8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x3fffULL }, + { T6030_BLK_AMCC0, 0x640f0, 64, 0x11000137de137c0ULL }, + { T6030_BLK_AMCC0, 0x640f8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0x7fffULL }, + { T6030_BLK_AMCC0, 0x64100, 64, 0x21000137de137c0ULL }, + { T6030_BLK_AMCC0, 0x64108, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64000, 64, 0xffffULL }, + { T6030_BLK_AMCC0, 0xa4010, 64, 0x110001359713580ULL }, + { T6030_BLK_AMCC0, 0xa4018, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0xa4020, 64, 0x210001359713580ULL }, + { T6030_BLK_AMCC0, 0xa4028, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x3ULL }, + { T6030_BLK_AMCC0, 0xa4030, 64, 0x110001364713640ULL }, + { T6030_BLK_AMCC0, 0xa4038, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x7ULL }, + { T6030_BLK_AMCC0, 0xa4040, 64, 0x210001364713640ULL }, + { T6030_BLK_AMCC0, 0xa4048, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0xfULL }, + { T6030_BLK_AMCC0, 0xa4050, 64, 0x11000102e9102c0ULL }, + { T6030_BLK_AMCC0, 0xa4058, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x1fULL }, + { T6030_BLK_AMCC0, 0xa4060, 64, 0x21000102e9102c0ULL }, + { T6030_BLK_AMCC0, 0xa4068, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x3fULL }, + { T6030_BLK_AMCC0, 0xa4070, 64, 0x110001340413400ULL }, + { T6030_BLK_AMCC0, 0xa4078, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x7fULL }, + { T6030_BLK_AMCC0, 0xa4080, 64, 0x210001340413400ULL }, + { T6030_BLK_AMCC0, 0xa4088, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0xffULL }, + { T6030_BLK_AMCC0, 0xa4090, 64, 0x110001251012500ULL }, + { T6030_BLK_AMCC0, 0xa4098, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x1ffULL }, + { T6030_BLK_AMCC0, 0xa40a0, 64, 0x210001251012500ULL }, + { T6030_BLK_AMCC0, 0xa40a8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x3ffULL }, + { T6030_BLK_AMCC0, 0xa40b0, 64, 0x110001120811200ULL }, + { T6030_BLK_AMCC0, 0xa40b8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x7ffULL }, + { T6030_BLK_AMCC0, 0xa40c0, 64, 0x210001120811200ULL }, + { T6030_BLK_AMCC0, 0xa40c8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0xfffULL }, + { T6030_BLK_AMCC0, 0xa40d0, 64, 0x11000126bf12680ULL }, + { T6030_BLK_AMCC0, 0xa40d8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x1fffULL }, + { T6030_BLK_AMCC0, 0xa40e0, 64, 0x21000126bf12680ULL }, + { T6030_BLK_AMCC0, 0xa40e8, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4000, 64, 0x3fffULL }, + { T6030_BLK_AMCC0, 0x24858, 64, 0x100000000500000ULL }, + { T6030_BLK_AMCC0, 0x24810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC0, 0x24860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24800, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0x24868, 64, 0x200000000500000ULL }, + { T6030_BLK_AMCC0, 0x24870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x24800, 64, 0x3ULL }, + { T6030_BLK_AMCC0, 0x64858, 64, 0x10000311492a100ULL }, + { T6030_BLK_AMCC0, 0x64810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC0, 0x64860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64800, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0x64868, 64, 0x20000311492a100ULL }, + { T6030_BLK_AMCC0, 0x64870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0x64800, 64, 0x3ULL }, + { T6030_BLK_AMCC0, 0xa4858, 64, 0x100003ffff00000ULL }, + { T6030_BLK_AMCC0, 0xa4810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC0, 0xa4860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4800, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0xa4868, 64, 0x200003ffff00000ULL }, + { T6030_BLK_AMCC0, 0xa4870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC0, 0xa4800, 64, 0x3ULL }, + { T6030_BLK_AMCC1, 0x24858, 64, 0x100001129b11280ULL }, + { T6030_BLK_AMCC1, 0x24810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC1, 0x24860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0x24800, 64, 0x1ULL }, + { T6030_BLK_AMCC1, 0x24868, 64, 0x200001129b11280ULL }, + { T6030_BLK_AMCC1, 0x24870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0x24800, 64, 0x3ULL }, + { T6030_BLK_AMCC1, 0x64858, 64, 0x100001251012500ULL }, + { T6030_BLK_AMCC1, 0x64810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC1, 0x64860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0x64800, 64, 0x1ULL }, + { T6030_BLK_AMCC1, 0x64868, 64, 0x200001251012500ULL }, + { T6030_BLK_AMCC1, 0x64870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0x64800, 64, 0x3ULL }, + { T6030_BLK_AMCC1, 0xa4858, 64, 0x100001120811200ULL }, + { T6030_BLK_AMCC1, 0xa4810, 64, 0x103fff00000000ULL }, + { T6030_BLK_AMCC1, 0xa4860, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0xa4800, 64, 0x1ULL }, + { T6030_BLK_AMCC1, 0xa4868, 64, 0x200001120811200ULL }, + { T6030_BLK_AMCC1, 0xa4870, 64, 0xff000000000ULL }, + { T6030_BLK_AMCC1, 0xa4800, 64, 0x3ULL }, + { T6030_BLK_DCS0, 0x58c, 32, 0x3ff001aULL }, + { T6030_BLK_DCS0, 0x590, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x594, 32, 0x33ULL }, + { T6030_BLK_DCS0, 0x598, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x59c, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x1ULL }, + { T6030_BLK_DCS0, 0x5a0, 32, 0x3ff0039ULL }, + { T6030_BLK_DCS0, 0x5a4, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5a8, 32, 0x33ULL }, + { T6030_BLK_DCS0, 0x5ac, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5b0, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x3ULL }, + { T6030_BLK_DCS0, 0x5b4, 32, 0x3ff003aULL }, + { T6030_BLK_DCS0, 0x5b8, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5bc, 32, 0x33ULL }, + { T6030_BLK_DCS0, 0x5c0, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5c4, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x7ULL }, + { T6030_BLK_DCS0, 0x5c8, 32, 0x3ff0013ULL }, + { T6030_BLK_DCS0, 0x5cc, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5d0, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5d4, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5d8, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0xfULL }, + { T6030_BLK_DCS0, 0x5dc, 32, 0x3ff0016ULL }, + { T6030_BLK_DCS0, 0x5e0, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5e4, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5e8, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5ec, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x1fULL }, + { T6030_BLK_DCS0, 0x5f0, 32, 0x3ff001aULL }, + { T6030_BLK_DCS0, 0x5f4, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x5f8, 32, 0x31ULL }, + { T6030_BLK_DCS0, 0x5fc, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x600, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x3fULL }, + { T6030_BLK_DCS0, 0x604, 32, 0x3ff001aULL }, + { T6030_BLK_DCS0, 0x608, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x60c, 32, 0x32ULL }, + { T6030_BLK_DCS0, 0x610, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x614, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x7fULL }, + { T6030_BLK_DCS0, 0x618, 32, 0x3ff0012ULL }, + { T6030_BLK_DCS0, 0x61c, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x620, 32, 0x33ULL }, + { T6030_BLK_DCS0, 0x624, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x628, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0xffULL }, + { T6030_BLK_DCS0, 0x62c, 32, 0x3ff0014ULL }, + { T6030_BLK_DCS0, 0x630, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x634, 32, 0x33ULL }, + { T6030_BLK_DCS0, 0x638, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x63c, 32, 0x0ULL }, + { T6030_BLK_DCS0, 0x580, 32, 0x71ULL }, + { T6030_BLK_DCS0, 0x584, 32, 0x1ffULL }, + { T6030_BLK_DCS0, 0x588, 32, 0x100ULL }, + { T6030_BLK_DCS0, 0x588, 32, 0x1ULL }, + { T6030_BLK_DCS0, 0x588, 32, 0x1001ULL }, + { T6030_BLK_DCS0, 0x588, 32, 0x11ULL }, + { T6030_BLK_AMCC0, 0x27018, 64, 0x10000000ULL }, + { T6030_BLK_AMCC0, 0x27008, 64, 0x700ULL }, + { T6030_BLK_AMCC0, 0x27000, 64, 0x11ULL }, + { T6030_BLK_AMCC0, 0x67008, 64, 0x708ULL }, + { T6030_BLK_AMCC0, 0x67000, 64, 0x1ULL }, + { T6030_BLK_AMCC0, 0xa7008, 64, 0x710ULL }, + { T6030_BLK_AMCC0, 0xa7000, 64, 0x1ULL }, + { T6030_BLK_AMCC1, 0x27008, 64, 0x718ULL }, + { T6030_BLK_AMCC1, 0x27000, 64, 0x1ULL }, + { T6030_BLK_DCS0, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS0_CH1, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS0_CH2, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS0_CH3, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS0_CH4, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS0_CH5, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH0, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH1, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH2, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH3, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH4, 0x18, 32, 0x70a1100ULL }, + { T6030_BLK_DCS1_CH5, 0x18, 32, 0x70a1100ULL }, +}; + +#define T6030_MEM_CONFIG_TAIL 247 +#define T6030_PERF_SOC_HI GENMASK(15, 12) +#define T6030_PERF_SOC_HI_SLEEP 4 + +static void t6030_mem_config_run(unsigned int from, unsigned int to) +{ + unsigned int i; + + for (i = from; i < to; i++) { + const struct t6030_mem_write *w = &t6030_mem_config[i]; + void __iomem *base = t6030.blk[w->blk]; + + if (!base) + continue; + if (w->width == 64) + writeq(w->val, base + w->off); + else + writel(w->val, base + w->off); + } +} + +static void t6030_mem_perf(struct apple_sleep *s) +{ + u32 v = readl(s->clk_perf + CLK_PERF_SOC); + + writel((v & ~T6030_PERF_SOC_HI) | FIELD_PREP(T6030_PERF_SOC_HI, T6030_PERF_SOC_HI_SLEEP), + s->clk_perf + CLK_PERF_SOC); + readl(s->clk_perf + CLK_PERF_SOC); +} + +static void t6030_mem_config_apply(struct apple_sleep *s) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(t6030_mem_config); i++) + if (!t6030.blk[t6030_mem_config[i].blk]) + return; + t6030_mem_config_run(0, ARRAY_SIZE(t6030_mem_config)); + t6030_mem_perf(s); + t6030.mem_configured = true; +} + +/* + * Peripheral quiesce sequences run at display power-down + */ +static void t6030_quiesce_run(const struct t6030_quiesce_write *w, unsigned int n, + const bool skip_disp[3]) +{ + unsigned int i, d; + + for (i = 0; i < n; i++) { + void __iomem *base = t6030.qblk[w[i].blk]; + + if (!base) + continue; + static_assert(T6030_QBLK_DISP_DART1 - T6030_QBLK_DISP_DART0 == 1); + static_assert(T6030_QBLK_DISP_DART2 - T6030_QBLK_DISP_DART0 == 2); + if (skip_disp && w[i].blk >= T6030_QBLK_DISP_DART0 && + w[i].blk <= T6030_QBLK_DISP_DART2 && + skip_disp[w[i].blk - T6030_QBLK_DISP_DART0]) + continue; + for (d = w[i].delay_us; d; d -= min(d, 1000U)) + udelay(min(d, 1000U)); + writel(w[i].val, base + w[i].off); + readl(base + w[i].off); + } +} + +static void t6030_quiesce_at_display_off(struct apple_sleep *s) +{ + bool pcie_on = sleep_ps_on(s, T6030_PS_APCIE_GP) && + sleep_ps_on(s, T6030_PS_APCIE_PHY_SW); + bool skip_disp[3] = { + !sleep_ps_on(s, T6030_PS_DISP_SYS), + !sleep_ps_on(s, T6030_PS_DISPEXT0_SYS), + !sleep_ps_on(s, T6030_PS_DISPEXT1_SYS), + }; + + if (pcie_on) { + t6030_quiesce_run(t6030_quiesce_sd, ARRAY_SIZE(t6030_quiesce_sd), NULL); + t6030_quiesce_run(t6030_quiesce_wifi, ARRAY_SIZE(t6030_quiesce_wifi), NULL); + } + t6030_quiesce_run(t6030_quiesce_disp, ARRAY_SIZE(t6030_quiesce_disp), skip_disp); + t6030_quiesce_run(t6030_quiesce_pins, ARRAY_SIZE(t6030_quiesce_pins), NULL); +} + +/* + * Power-state domain staging and commit-time lowering + */ +static void __iomem *t6030_ps_reg(struct apple_sleep *s, const struct t6030_ps_entry *e) +{ + return (e->aon ? s->ps_aon : s->ps) + e->off; +} + +static bool t6030_ps_domain_kept(struct apple_sleep *s, int off) +{ + unsigned int i; + + if (!s || off < 0) + return false; + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + + if (!e->aon && e->off == (u32)off) + return true; + } + return false; +} + +static bool t6030_ps_write_bits(void __iomem *r, u32 want) +{ + u32 v = readl(r); + + writel((v & ~T6030_PS_STAGE_BITS) | (want & T6030_PS_STAGE_BITS), r); + return !readl_poll_timeout_atomic(r, v, (v & PS_TARGET) == (want & PS_TARGET), 1, 1000); +} + +static void t6030_ps_restore_word(void __iomem *r, u32 saved) +{ + u32 v = readl(r); + + writel((v & ~T6030_PS_STAGE_BITS) | (saved & T6030_PS_STAGE_BITS), r); + readl_poll_timeout_atomic(r, v, FIELD_GET(PS_ACTUAL, v) == FIELD_GET(PS_TARGET, saved), + 1, 1000); +} + +static void t6030_ps_at_display_off(struct apple_sleep *s) +{ + unsigned int i, on_bad = 0, auto_bad = 0; + + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + void __iomem *r = t6030_ps_reg(s, e); + + t6030.ps_on_saved[i] = readl(r); + on_bad += !t6030_ps_write_bits(r, e->target); + } + for (i = 0; i < ARRAY_SIZE(t6030_ps_auto_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_auto_order[i]]; + void __iomem *r = t6030_ps_reg(s, e); + + t6030.ps_auto_saved[i] = readl(r); + auto_bad += !t6030_ps_write_bits(r, e->target); + } + t6030.ps_display_staged = true; + s->regs_staged = true; + if (on_bad || auto_bad) + dev_warn(s->dev, "T6030 display power: %u ON and %u AUTO words failed readback\n", + on_bad, auto_bad); +} + +static void t6030_ps_undo_display_off(struct apple_sleep *s) +{ + int i; + + if (!t6030.ps_display_staged) + return; + t6030.ps_display_staged = false; + for (i = ARRAY_SIZE(t6030_ps_auto_order) - 1; i >= 0; i--) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_auto_order[i]]; + + t6030_ps_restore_word(t6030_ps_reg(s, e), t6030.ps_auto_saved[i]); + } + for (i = ARRAY_SIZE(t6030_ps_on_order) - 1; i >= 0; i--) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + + t6030_ps_restore_word(t6030_ps_reg(s, e), t6030.ps_on_saved[i]); + } +} + +static bool t6030_usb_aon_kept_port(unsigned int port) +{ + return port < 4 && + (READ_ONCE(sleep_usb_asleep) || (READ_ONCE(sleep_usb_aon_kept) & BIT(port))); +} + +static bool t6030_usb_aon_kept(const struct t6030_ps_entry *e) +{ + u32 rel; + + if (!e->aon || e->off < T6030_AON_ATC0_USB_AON || + e->off >= T6030_AON_ATC0_USB_AON + 4 * 8) + return false; + rel = e->off - T6030_AON_ATC0_USB_AON; + if (rel & 7) + return false; + return t6030_usb_aon_kept_port(rel / 8); +} + +/* + * Lower remaining active OFF-target domains in child-before-parent order, then + * apply t6030_ps_lower_order. Keep any ATCn_USB_AON domain powered when USB + * wake or in-place hibernation requested retention for that port. + */ +static void t6030_ps_at_commit(struct apple_sleep *s) +{ + unsigned int i; + int j; + + bitmap_zero(t6030.ps_extra_lowered, ARRAY_SIZE(t6030_ps_entries)); + bitmap_zero(t6030.ps_lowered, ARRAY_SIZE(t6030_ps_lower_order)); + for (j = ARRAY_SIZE(t6030_ps_entries) - 1; j >= 0; j--) { + const struct t6030_ps_entry *e = &t6030_ps_entries[j]; + void __iomem *r = t6030_ps_reg(s, e); + u32 v; + + if (e->group || (e->target & PS_TARGET) || t6030_usb_aon_kept(e)) + continue; + v = readl(r); + if (!(v & PS_TARGET) && !FIELD_GET(PS_ACTUAL, v)) + continue; + t6030.ps_extra_saved[j] = v; + __set_bit(j, t6030.ps_extra_lowered); + t6030_ps_write_bits(r, e->target); + readl_poll_timeout_atomic(r, v, !FIELD_GET(PS_ACTUAL, v), 1, 1000); + } + for (i = 0; i < ARRAY_SIZE(t6030_ps_lower_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_lower_order[i]]; + void __iomem *r = t6030_ps_reg(s, e); + u32 v; + + if (t6030_usb_aon_kept(e)) + continue; + if ((e->aon && (e->off == T6030_AON_ATC0_USB || e->off == T6030_AON_ATC0_USB_AON)) || + (!e->aon && e->off == T6030_PS_ATC0_COMMON)) + continue; + t6030.ps_lower_saved[i] = readl(r); + __set_bit(i, t6030.ps_lowered); + t6030_ps_write_bits(r, e->target); + readl_poll_timeout_atomic(r, v, + FIELD_GET(PS_ACTUAL, v) == + FIELD_GET(PS_TARGET, e->target), + 1, 1000); + } +} + +/* + * System-level cache (SLC) multicast disable/enable across commit and wake + */ +static void __iomem *t6030_slc_plane(unsigned int p) +{ + void __iomem *amcc = t6030.blk[p < 3 ? T6030_BLK_AMCC0 : T6030_BLK_AMCC1]; + + return amcc ? amcc + (p % 3) * 0x40000 : NULL; +} + +static bool t6030_slc_set(bool enable) +{ + unsigned int p; + u32 v, target = enable ? T6030_SLC_STATUS_ON : 0; + bool ok = true; + + writel(enable, t6030.slc_multicast[0]); + writel(enable, t6030.slc_multicast[1]); + /* Complete both multicast writes before polling plane status. */ + mb(); + for (p = 0; p < T6030_SLC_PLANES; p++) { + void __iomem *pl = t6030_slc_plane(p); + + if (readl_poll_timeout_atomic(pl + T6030_SLC_PLANE_STATUS, v, v == target, + 1, 10000)) + ok = false; + } + return ok; +} + +static int t6030_slc_off(void) +{ + if (!t6030.slc_multicast[0] || !t6030.slc_multicast[1]) + return -ENODEV; + t6030.slc_disabled = true; + return t6030_slc_set(false) ? 0 : -ETIMEDOUT; +} + +static void t6030_slc_on(struct apple_sleep *s) +{ + if (t6030.slc_disabled) { + if (!t6030_slc_set(true)) + dev_err(s->dev, "SLC did not return on wake\n"); + t6030.slc_disabled = false; + } +} + +/* + * DT resource mapping (probe performs no hardware writes) + */ +static u32 t6030_block(struct apple_sleep *s, u32 b) +{ + struct resource res; + + if (b >= T6030_BLOCKS) + return 0; + if (t6030.blk[b]) + return t6030.blk_size[b]; + if (of_address_to_resource(s->dev->of_node, b, &res)) + return 0; + t6030.blk[b] = t6030_ioremap(s->dev, &res); + if (!t6030.blk[b]) + return 0; + t6030.blk_size[b] = min_t(resource_size_t, resource_size(&res), U32_MAX); + return t6030.blk_size[b]; +} + +static void __iomem *t6030_map_node_reg(struct apple_sleep *s, struct device_node *np, + int index) +{ + struct resource res; + + if (!np || index < 0 || of_address_to_resource(np, index, &res)) + return NULL; + return t6030_ioremap(s->dev, &res); +} + +static void __iomem *t6030_map_node_name(struct apple_sleep *s, struct device_node *np, + const char *name) +{ + return t6030_map_node_reg(s, np, of_property_match_string(np, "reg-names", name)); +} + +static void __iomem *t6030_map_phandle(struct apple_sleep *s, const char *prop, int index) +{ + struct device_node *np = of_parse_phandle(s->dev->of_node, prop, index); + void __iomem *base; + + if (!np) + return NULL; + base = t6030_map_node_reg(s, np, 0); + of_node_put(np); + return base; +} + +static void t6030_gp_map(struct apple_sleep *s) +{ + struct device_node *host = of_parse_phandle(s->dev->of_node, "apple,pcie-host", 0); + struct device_node *port; + unsigned int idx = 0; + + if (!host) + return; + t6030.gp_phy = t6030_map_node_name(s, host, "phy-shared"); + t6030.gp_phy_ip = t6030_map_node_name(s, host, "phy-ip"); + t6030.gp_clkgen = t6030_map_node_name(s, host, "clkgen"); + t6030.gp_axi2af = t6030_map_node_name(s, host, "axi2af"); + t6030.gp_cio3pll = t6030_map_node_name(s, host, "cio3pll"); + t6030.gp_rc = t6030_map_node_name(s, host, "rc"); + t6030.gp_phy_common = t6030_map_node_name(s, host, "phy-common"); + + t6030.qblk[T6030_QBLK_PCIE_PORT0] = t6030_map_node_name(s, host, "port0"); + t6030.qblk[T6030_QBLK_PCIE_INTR0] = t6030_map_node_name(s, host, "intr2axi0"); + t6030.qblk[T6030_QBLK_PCIE_PORT1] = t6030_map_node_name(s, host, "port1"); + t6030.qblk[T6030_QBLK_PCIE_INTR1] = t6030_map_node_name(s, host, "intr2axi1"); + t6030.qblk[T6030_QBLK_PCIE_PHY0] = t6030_map_node_name(s, host, "phy0"); + t6030.qblk[T6030_QBLK_PCIE_PHY1] = t6030_map_node_name(s, host, "phy1"); + + struct device_node *pinctrl_np = of_parse_phandle(s->dev->of_node, "apple,pinctrl", 0); + + for_each_child_of_node(host, port) { + struct of_phandle_args args; + + if (idx >= T6030_GP_PERST_PORTS) { + of_node_put(port); + break; + } + if (!of_parse_phandle_with_args(port, "reset-gpios", "#gpio-cells", 0, &args)) { + if (pinctrl_np && args.np == pinctrl_np && args.args_count >= 1) { + t6030.perst_pin[idx] = args.args[0]; + t6030.perst_valid[idx] = true; + } + of_node_put(args.np); + } + idx++; + } + of_node_put(pinctrl_np); + + of_node_put(host); + if (!t6030.gp_phy || !t6030.gp_phy_ip || !t6030.gp_clkgen || !t6030.gp_axi2af) { + dev_warn(s->dev, "T6030: GP PCIe PHY/clock blocks incomplete, park disabled\n"); + t6030.gp_phy = NULL; + } +} + +static bool t6030_replay_actual(void __iomem *va, u32 actual, unsigned int us) +{ + u32 v; + + return !readl_poll_timeout(va, v, FIELD_GET(PS_ACTUAL, v) == actual, 20, us); +} + +static void t6030_replay_pulse(struct device *dev, void __iomem *ps, u32 off, + const char *name, unsigned int hold_us) +{ + void __iomem *va = ps + off; + + writel(0xf, va); + if (!t6030_replay_actual(va, 0xf, 10000)) + dev_warn(dev, "T6030 boot replay: %s not on: %#x\n", name, readl(va)); + writel(0x1000000f, va); + readl(va); + fsleep(hold_us); + writel(0x3f0, va); + if (!t6030_replay_actual(va, 0, 10000)) + dev_warn(dev, "T6030 boot replay: %s not off: %#x\n", name, readl(va)); +} + +static void t6030_boot_replay(struct apple_sleep *s) +{ + static bool done; + void __iomem *mca; + unsigned int i; + + if (done) + return; + done = true; + + /* DWI boot pulse */ + writel(0x340, s->ps + T6030_PS_DWI); + readl(s->ps + T6030_PS_DWI); + fsleep(8500); + writel(0xf, s->ps + T6030_PS_DWI); + if (!t6030_replay_actual(s->ps + T6030_PS_DWI, 0xf, 10000)) + dev_warn(s->dev, "T6030 boot replay: DWI not on: %#x\n", + readl(s->ps + T6030_PS_DWI)); + writel(0x1000000f, s->ps + T6030_PS_DWI); + readl(s->ps + T6030_PS_DWI); + + /* MCA audio-clock switches */ + mca = ioremap_np(0x350040000ULL, 0x1000); + if (mca) { + for (i = 0; i < 4; i++) { + writel(0, mca + 0xc0 + 4 * i); + readl(mca + 0xc0 + 4 * i); + } + iounmap(mca); + } + + /* ATC2_PCIE, then ATC1_PCIE */ + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, "ATC2_PCIE", 15200); + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, "ATC1_PCIE", 8400); +} + +static void t6030_ps_auto_set(void __iomem *reg) +{ + u32 v = readl(reg); + + if (FIELD_GET(PS_ACTUAL, v) == 0xf && !(v & PS_AUTO_ENABLE)) { + writel(v & ~PS_FLAGS, reg); + readl(reg); + writel((v & ~PS_FLAGS) | PS_AUTO_ENABLE, reg); + } +} + +static void t6030_boot_auto_probe(struct apple_sleep *s) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(t6030_ps_boot_auto); i++) + t6030_ps_auto_set(s->ps + t6030_ps_boot_auto[i]); + for (i = 0; i < ARRAY_SIZE(t6030_ps_aon_boot_auto); i++) { + u32 off = t6030_ps_aon_boot_auto[i]; + + if (off == T6030_AON_NUB_FABRIC) + continue; + t6030_ps_auto_set(s->ps_aon + off); + } +} + +static int t6030_sleep_map_regs(struct apple_sleep *s) +{ + static const struct { + const char *name; + size_t offset; + } regs[] = { + { "ps", offsetof(struct apple_sleep, ps) }, + { "pwrgate", offsetof(struct apple_sleep, pwrgate) }, + { "cpu-start", offsetof(struct apple_sleep, cpu_start) }, + { "cllt", offsetof(struct apple_sleep, cllt) }, + { "cluster", offsetof(struct apple_sleep, cluster) }, + { "commit", offsetof(struct apple_sleep, commit) }, + { "wdt", offsetof(struct apple_sleep, wdt) }, + { "wake", offsetof(struct apple_sleep, wake) }, + { "spmi", offsetof(struct apple_sleep, spmi) }, + { "ps-aon", offsetof(struct apple_sleep, ps_aon) }, + { "spmi-a0", offsetof(struct apple_sleep, spmi_a0) }, + { "clk-mux", offsetof(struct apple_sleep, clk_mux) }, + { "clk-perf", offsetof(struct apple_sleep, clk_perf) }, + }; + struct device_node *np = s->dev->of_node, *i2c_np; + u32 v[6]; + unsigned int i; + int ret; + + memset(&t6030, 0, sizeof(t6030)); + for (i = 0; i < ARRAY_SIZE(regs); i++) { + void __iomem **field = (void __iomem **)((u8 *)s + regs[i].offset); + + *field = apple_sleep_map(s->dev, regs[i].name); + if (IS_ERR(*field)) + return dev_err_probe(s->dev, PTR_ERR(*field), "no %s registers\n", + regs[i].name); + } + ret = of_address_to_resource(np, of_property_match_string(np, "reg-names", "ps"), + &s->ps_res); + if (ret) + return ret; + s->driver_down = devm_bitmap_zalloc(s->dev, resource_size(&s->ps_res) / 4, GFP_KERNEL); + if (!s->driver_down) + return -ENOMEM; + ret = apple_sleep_alloc_books(s); + if (ret) + return ret; + + if (of_property_read_u32_array(np, "apple,smc-sleep-policy", v, ARRAY_SIZE(v))) + return dev_err_probe(s->dev, -ENODATA, "no apple,smc-sleep-policy in DT\n"); + t6030_smc_policy = (struct apple_sleep_smc_policy) { + .pmvc = v[0], .warn_to_pmvc_us = v[1], .pmvc_to_slpa_us = v[2], + .slpa_to_idle_us = v[3], .idle_to_timer_us = v[4], .waka_to_pmvc_us = v[5], + }; + + ret = t6030_seq_get(s, "apple,seq-prepare", &t6030.prepare, t6030_block, false) ?: + t6030_seq_get(s, "apple,seq-notice", &t6030.notice, t6030_block, false) ?: + t6030_seq_get(s, "apple,seq-commit", &t6030.commit, t6030_block, false) ?: + t6030_seq_get(s, "apple,seq-wake-early", &t6030.wake_early, t6030_block, true) ?: + t6030_seq_get(s, "apple,seq-wake", &t6030.wake, t6030_block, true); + if (ret) + return ret; + + /* Map remaining DT register windows (PTD, CPM, AMCC multicast, DCS channels, GPU PMGR). */ + for (i = T6030_BLK_PS_GPU; i < T6030_BLOCKS; i++) { + if (!t6030_block(s, i)) + return dev_err_probe(s->dev, -ENOMEM, "cannot map reg block %u\n", i); + } + if (t6030.blk_size[T6030_BLK_PTD] < T6030_PTD_MIN_SIZE) + return dev_err_probe(s->dev, -EINVAL, "PTD window too small\n"); + + t6030.ptd_read = t6030.blk[T6030_BLK_PTD] + T6030_PTD_READ_OFF; + t6030.ptd_update = t6030.blk[T6030_BLK_PTD] + T6030_PTD_UPDATE_OFF; + t6030.ptd_ctrl = t6030.blk[T6030_BLK_PTD] + T6030_PTD_CTRL_OFF; + t6030.cpm[0] = t6030.blk[T6030_BLK_CPM_E]; + t6030.cpm[1] = t6030.blk[T6030_BLK_CPM_P]; + t6030.slc_multicast[0] = t6030.blk[T6030_BLK_AMCC0_MC]; + t6030.slc_multicast[1] = t6030.blk[T6030_BLK_AMCC1_MC]; + + t6030_gp_map(s); + t6030.pmp_mbox = t6030_map_node_name(s, np, "pmp-mbox"); + t6030.dart_sep = t6030_map_phandle(s, "apple,sep-dart", 0); + t6030.mtp_dart = t6030_map_phandle(s, "apple,mtp-dart", 0); + i2c_np = of_find_node_by_path("/soc/i2c@289028000"); + if (i2c_np) { + t6030.i2c6 = t6030_map_node_reg(s, i2c_np, 0); + of_node_put(i2c_np); + } + t6030.qblk[T6030_QBLK_PINCTRL] = t6030_map_phandle(s, "apple,pinctrl", 0); + t6030.qblk[T6030_QBLK_PWRGATE] = s->pwrgate; + static_assert(T6030_QBLK_DISP_DART1 - T6030_QBLK_DISP_DART0 == 1); + static_assert(T6030_QBLK_DISP_DART2 - T6030_QBLK_DISP_DART0 == 2); + for (i = 0; i < 3; i++) + t6030.qblk[T6030_QBLK_DISP_DART0 + i] = + t6030_map_phandle(s, "apple,display-darts", i); + t6030.qblk[T6030_QBLK_PCIE_DART0] = t6030_map_phandle(s, "apple,pcie-darts", 0); + t6030.qblk[T6030_QBLK_PCIE_DART1] = t6030_map_phandle(s, "apple,pcie-darts", 1); + + { + u64 hid4 = t6030_dc_unblock(); + + t6030_clean_range((unsigned long)t8142_el1_wfi_stub, + (unsigned long)t8142_el1_wfi_stub_end); + t6030_dc_reblock(hid4); + } + + t6030_boot_replay(s); + t6030_pwrgate_init(s); + t6030_cpm_init(); + t6030_boot_auto_probe(s); + t6030_mem_config_apply(s); + t6030_last_pmu_boot(s); + + return apple_sleep_read_wake_sources(s); +} + +/* + * Entry callbacks + */ +static void t6030_sleep_failed(const char *what) +{ + panic("T6030 sleep: %s failed, not committing", what); +} + +static void t6030_sleep_check_stops(void) +{ + struct apple_sleep_coproc *c = apple_sleep_coprocs_stop_failed(); + + if (!c) + return; + sleep_note_at(apple_sleep, 4, min(-c->stop_ret, 0xff)); + panic("T6030 sleep: %s's stop failed (%d), not committing", dev_name(c->dev), c->stop_ret); +} + +static int t6030_sleep_final_check(struct apple_sleep *s) +{ + int ret; + + if (!s->smc.held || !s->smc.saved_ops || !s->smc.saved_ops->check) { + dev_dbg(s->dev, "final check: SMC scope held %d\n", s->smc.held); + return -EBUSY; + } + ret = s->smc.saved_ops->check(s->smc.data); + if (ret) { + dev_dbg(s->dev, "final check: SMC check %d\n", ret); + return ret; + } + return 0; +} + +static int t6030_sleep_display_off(struct apple_sleep *s) +{ + s->regs_staged = true; + t6030_ps_at_display_off(s); + return 0; +} + +static void t6030_sleep_before_enclave(struct apple_sleep *s) +{ + void __iomem *d = t6030.dart_sep; + + if (!d) + return; + t6030.dart_sep_err_mask_saved = readl(d + T6030_DART_ERROR_MASK); + t6030.dart_sep_704_saved = readl(d + T6030_DART_704); + t6030.dart_sep_staged = true; + writel(0xffffffff, d + T6030_DART_ERROR_MASK); + readl(d + T6030_DART_ERROR_MASK); + readl(d + T6030_DART_ERROR); + writel(T6030_DART_SEP_ERROR_CLEAR, d + T6030_DART_ERROR); + readl(d + T6030_DART_ERROR); + writel(0xffffffff, d + T6030_DART_704); + readl(d + T6030_DART_704); +} + +static void t6030_wake_masks_set(struct apple_sleep *s) +{ + u32 val[T6030_WAKE_WORDS]; + unsigned int i; + + if (t6030.wake_masks_staged) + return; + for (i = 0; i < T6030_WAKE_WORDS; i++) { + t6030.wake_saved[i] = readl(s->wake + T6030_WAKE_MASK + 4 * i); + val[i] = (i == T6030_WAKE_WORDS - 1) ? T6030_WAKE_LAST_BITS : U32_MAX; + } + for (i = 0; i < s->wake_enable_count; i++) { + u32 src = s->wake_enable[i]; + + if (src < T6030_WAKE_WORDS * 32) + val[src / 32] &= ~BIT(src % 32); + } + t6030.wake_masks_staged = true; + for (i = 0; i < T6030_WAKE_WORDS; i++) { + if (i < ARRAY_SIZE(s->wake_armed)) + s->wake_armed[i] = ~val[i]; + writel(val[i], s->wake + T6030_WAKE_MASK + 4 * i); + } + for (i = 0; i < T6030_WAKE_WORDS; i++) + t6030.wake_pending[i] = readl(s->wake + T6030_WAKE_STATUS + 4 * i); +} + +static void t6030_wake_masks_restore(struct apple_sleep *s) +{ + unsigned int i; + + if (!t6030.wake_masks_staged) + return; + for (i = 0; i < T6030_WAKE_WORDS; i++) + writel(t6030.wake_saved[i], s->wake + T6030_WAKE_MASK + 4 * i); + t6030.wake_masks_staged = false; +} + +static void t6030_sleep_prepare_regs(struct apple_sleep *s) +{ + t6030_quiesce_at_display_off(s); + if (t6030.ptd_ctrl) { + t6030.ptd_sleep_ctrl_saved = readl(t6030.ptd_ctrl + T6030_PTD_SLEEP_CTRL); + t6030.ptd_sleep_ctrl_staged = true; + writel(T6030_PTD_SLEEP_CTRL_ENTRY, t6030.ptd_ctrl + T6030_PTD_SLEEP_CTRL); + } + writel(T6030_SPMI_A0_ENTRY_ACK3, s->spmi_a0 + T6030_SPMI_ACK(3)); + t6030.gate_dispext1_saved = readl(s->pwrgate + T6030_PWRGATE_DISPEXT1); + t6030.gate_dispext1_staged = true; + writel(T6030_PWRGATE_DISPEXT1_OFF, s->pwrgate + T6030_PWRGATE_DISPEXT1); + sleep_ps_lower(s, T6030_PS_SPI2); + t6030_sleep_clean_ram(); +} + +static void t6030_sleep_undo_regs(struct apple_sleep *s) +{ + t6030_wake_masks_restore(s); + if (t6030.notify_staged) { + writel(t6030.notify_saved[1], s->spmi + SPMI_NOTIFY_ENABLE); + writel(t6030.notify_saved[0], s->spmi_a0 + SPMI_NOTIFY_ENABLE); + t6030.notify_staged = false; + } + if (t6030.gate_dispext1_staged) { + writel(t6030.gate_dispext1_saved, s->pwrgate + T6030_PWRGATE_DISPEXT1); + t6030.gate_dispext1_staged = false; + } + if (t6030.ptd_sleep_ctrl_staged && t6030.ptd_ctrl) { + writel(t6030.ptd_sleep_ctrl_saved, t6030.ptd_ctrl + T6030_PTD_SLEEP_CTRL); + t6030.ptd_sleep_ctrl_staged = false; + } + if (t6030.dart_sep_staged && t6030.dart_sep) { + writel(t6030.dart_sep_err_mask_saved, t6030.dart_sep + T6030_DART_ERROR_MASK); + writel(t6030.dart_sep_704_saved, t6030.dart_sep + T6030_DART_704); + t6030.dart_sep_staged = false; + } + t6030_ps_undo_display_off(s); +} + +static void t6030_sleep_after_ans(struct apple_sleep *s) +{ + unsigned int i; + u64 ack = 0; + + t6030_sleep_check_stops(); + if (t6030.ptd_update) { + writeq(T6030_MASK_AT_PMVC, t6030.ptd_update + T6030_PTD_REQUEST); + if (t6030.ptd_read) + readq_poll_timeout_atomic(t6030.ptd_read + T6030_PTD_ACTUAL, ack, + ack == T6030_MASK_AT_PMVC, 100, T6030_PTD_ACK_US); + apple_sleep_smc_until_before_slpa(s, T6030_MASK_LATE_TO_SLPA_US); + writeq(T6030_MASK_LATE, t6030.ptd_update + T6030_PTD_REQUEST); + apple_sleep_smc_until_before_slpa(s, T6030_LAST_DVFS0_TO_SLPA_US); + writeq(T6030_PTD_DVFS0_VOTE, t6030.ptd_update + T6030_PTD_DVFS0); + } + apple_sleep_smc_until_before_slpa(s, T6030_LATE_TO_SLPA_US); + if (t6030_seq_run_strict(t6030.blk, &t6030.prepare)) + t6030_sleep_failed("apple,seq-prepare"); + t6030_alarm_snapshot(s, readl(s->spmi + SPMI_NOTIFY_ENABLE)); + if (t6030.alarm_valid) + t6030_last_alarm_disarm(s); + writel(0, s->wdt + WDT_WD0_COUNT); + writel(0, s->wdt + WDT_WD1_COUNT); + sleep_pmu_write(s, s->soc->pmu_sleep_reg, s->soc->pmu_sleep_val); + t6030_last_pmu_reads(s); + t6030.i2c6_ps_saved = readl(s->ps + T6030_PS_I2C6); + t6030.i2c6_ps_staged = FIELD_GET(PS_ACTUAL, t6030.i2c6_ps_saved) == 0xf; + t6030.i2c6_saved = false; + if (t6030.i2c6 && t6030.i2c6_ps_staged) { + for (i = 0; i < ARRAY_SIZE(t6030_i2c6_regs); i++) + t6030.i2c6_regs_saved[i] = readl(t6030.i2c6 + t6030_i2c6_regs[i]); + t6030.i2c6_saved = true; + } + writel(T6030_LAST_I2C6, s->ps + T6030_PS_I2C6); + readl(s->ps + T6030_PS_I2C6); + t6030.notify_saved[0] = readl(s->spmi_a0 + SPMI_NOTIFY_ENABLE); + t6030.notify_saved[1] = readl(s->spmi + SPMI_NOTIFY_ENABLE); + t6030.notify_staged = true; + t6030_wake_masks_set(s); + writel(s->soc->spmi_notify_sleep, s->spmi_a0 + SPMI_NOTIFY_ENABLE); + writel(s->soc->spmi_notify_sleep, s->spmi + SPMI_NOTIFY_ENABLE); +} + +static int t6030_sleep_lower(struct apple_sleep *s, unsigned int from, unsigned int to) +{ + unsigned int i; + + for (i = from; i < to; i++) { + t6030.lowered_saved[i] = readl(s->ps + t6030_lowered[i]); + t6030.nlowered = i + 1; + writel(t6030_lowered_macos[i][0], s->ps + t6030_lowered[i]); + writel(t6030_lowered_macos[i][1], s->ps + t6030_lowered[i]); + if (sleep_ps_wait_off(s, t6030_lowered[i])) { + dev_err(s->dev, "power word %#x not off: %#x\n", t6030_lowered[i], + readl(s->ps + t6030_lowered[i])); + return -ETIMEDOUT; + } + } + return 0; +} + +static void t6030_sleep_after_early(struct apple_sleep *s) +{ + t6030_sleep_check_stops(); + + if (t6030_sleep_lower(s, T6030_LOWER_SIO_CPU, T6030_LOWER_PMP)) + t6030_sleep_failed("SIO CPU power word"); + if (t6030_seq_run_strict(t6030.blk, &t6030.notice)) + t6030_sleep_failed("apple,seq-notice"); +} + +static int t6030_pmp_mgmt(void __iomem *mb, u64 type, u64 ack) +{ + unsigned int us, n = 0; + u64 m0, m1; + + if (readl(mb + T6030_MBOX_A2I_CONTROL) & T6030_MBOX_CONTROL_FULL) + return -EBUSY; + writeq(FIELD_PREP(T6030_RTKIT_MGMT_TYPE, type) | T6030_RTKIT_PWR_IDLE, + mb + T6030_MBOX_A2I_SEND0); + writeq(0, mb + T6030_MBOX_A2I_SEND1); + readl(mb + T6030_MBOX_A2I_CONTROL); + for (us = 0; us < T6030_PMP_ACK_US; us++) { + if (readl(mb + T6030_MBOX_I2A_CONTROL) & T6030_MBOX_CONTROL_EMPTY) { + udelay(1); + continue; + } + m0 = readq(mb + T6030_MBOX_I2A_RECV0); + m1 = readq(mb + T6030_MBOX_I2A_RECV1); + if (!(m1 & 0xff) && FIELD_GET(T6030_RTKIT_MGMT_TYPE, m0) == ack) + return 0; + if (++n >= T6030_PMP_DRAIN) + return -EPROTO; + } + return -ETIMEDOUT; +} + +static struct apple_sleep_coproc *t6030_pmp_coproc(void) +{ + int i; + + for (i = 0; i < SLEEP_COPROCS; i++) { + struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; + + if (c->dev && c->ready && + of_device_is_compatible(c->dev->of_node, "apple,t6030-pmp-v2")) + return c; + } + return NULL; +} + +static void t6030_pmp_idle(struct apple_sleep *s) +{ + void __iomem *mb = t6030.pmp_mbox; + + if (t6030_pmp_coproc() || !mb || !sleep_ps_on(s, T6030_PS_PMP)) + return; + if (!t6030_pmp_mgmt(mb, T6030_RTKIT_SET_AP_PWR, T6030_RTKIT_SET_AP_PWR)) + t6030_pmp_mgmt(mb, T6030_RTKIT_SET_IOP_PWR, T6030_RTKIT_SET_IOP_PWR_ACK); + writel(readl(mb + T6030_MBOX_I2A_CONTROL) & ~T6030_MBOX_I2A_IRQ, + mb + T6030_MBOX_I2A_CONTROL); + readl(mb); +} + +static void t6030_mtp_dart_quiet(void) +{ + void __iomem *d = t6030.mtp_dart; + + if (!d) + return; + writel(0xffffffff, d + T6030_DART_ERROR_MASK); + readl(d + T6030_DART_ERROR_MASK); + readl(d + T6030_DART_ERROR); + writel(T6030_DART_MTP_ERROR_CLEAR, d + T6030_DART_ERROR); + writel(0xffffffff, d + T6030_DART_704); + readl(d + T6030_DART_704); +} + +static int t6030_sleep_commit_notice(struct apple_sleep *s) +{ + int ret; + + t6030_sleep_check_stops(); + t6030_pmp_idle(s); + + ret = t6030_sleep_lower(s, T6030_LOWER_PMP, T6030_LOWER_PMS_SRAM); + if (ret) + return ret; + udelay(T6030_PMP_TO_SRAM_US); + ret = t6030_sleep_lower(s, T6030_LOWER_PMS_SRAM, T6030_LOWER_PHY); + if (ret) + return ret; + ret = apple_sleep_smc_commit_notice(s); + if (ret) + return ret; + if (!s->smc_idle_sent || s->smc_idle_ack < s->smc_idle_sent) + return -EPROTO; + t6030_mtp_dart_quiet(); + return 0; +} + +static void t6030_gp_phy_park(struct apple_sleep *s) +{ + void __iomem *phy = t6030.gp_phy; + int ret = 0; + u32 v; + + t6030.gp_park_ret = -ENODEV; + if (!phy || !sleep_ps_on(s, T6030_PS_APCIE_SYS_GP) || + !sleep_ps_on(s, T6030_PS_APCIE_PHY_SW)) + return; + writel(readl(phy + T6030_GP_PHY_CTRL), phy + T6030_GP_PHY_CTRL); + writel(readl(t6030.gp_phy_ip + T6030_GP_PHYIP_6C) & ~GENMASK(3, 2), + t6030.gp_phy_ip + T6030_GP_PHYIP_6C); + readl(t6030.gp_phy_ip + T6030_GP_PHYIP_7C); + writel(0x0f000000, t6030.gp_phy_ip + T6030_GP_PHYIP_7C); + writel(readl(phy + T6030_GP_PHY_CTRL) | BIT(7), phy + T6030_GP_PHY_CTRL); + writel(readl(phy + T6030_GP_PHY_CTRL) & ~BIT(1), phy + T6030_GP_PHY_CTRL); + ret |= readl_poll_timeout_atomic(phy + T6030_GP_PHY_CTRL, v, !(v & BIT(3)), 1, + T6030_GP_POLL_US); + writel(readl(phy + T6030_GP_PHY_CTRL) & ~BIT(0), phy + T6030_GP_PHY_CTRL); + ret |= readl_poll_timeout_atomic(phy + T6030_GP_PHY_CTRL, v, !(v & BIT(2)), 1, + T6030_GP_POLL_US); + writel(readl(phy + T6030_GP_PHY_CTRL) & ~BIT(9), phy + T6030_GP_PHY_CTRL); + writel(readl(phy + T6030_GP_PHY_CFG) & ~BIT(4), phy + T6030_GP_PHY_CFG); + writel(readl(phy + T6030_GP_PHY_CFG) & ~BIT(0), phy + T6030_GP_PHY_CFG); + t6030.gp_park_ret = ret ? -ETIMEDOUT : 0; +} + +static void t6030_gp_clk_off(void) +{ + void __iomem *clk = t6030.gp_clkgen; + u32 v; + + if (t6030.gp_park_ret == -ENODEV) + return; + writel(readl(t6030.gp_axi2af + T6030_GP_AXI2AF_600) & ~BIT(16), + t6030.gp_axi2af + T6030_GP_AXI2AF_600); + writel(readl(clk + T6030_GP_CLK_CTRL) & ~BIT(5), clk + T6030_GP_CLK_CTRL); + writel(readl(clk + T6030_GP_CLK_CTRL) | BIT(1), clk + T6030_GP_CLK_CTRL); + readl_poll_timeout_atomic(clk + T6030_GP_CLK_CTRL, v, v & T6030_GP_CLK_BUSY, 1, + T6030_GP_POLL_US); + writel(readl(clk + T6030_GP_CLK_CTRL) & ~BIT(0), clk + T6030_GP_CLK_CTRL); + if (readl_poll_timeout_atomic(clk + T6030_GP_CLK_CTRL, v, !(v & T6030_GP_CLK_BUSY), 1, + T6030_GP_POLL_US)) + t6030.gp_park_ret = -ETIMEDOUT; + writel(readl(clk + T6030_GP_CLK_CTRL) | BIT(2), clk + T6030_GP_CLK_CTRL); +} + +static void __iomem *t6030_atc_reg(struct apple_sleep *s, unsigned int i) +{ + unsigned int port = i / 3; + + switch (i % 3) { + case 0: + return s->ps_aon + T6030_AON_ATC0_USB + 8 * port; + case 1: + return s->ps_aon + T6030_AON_ATC0_USB_AON + 8 * port; + default: + return s->ps + T6030_PS_ATC0_COMMON + 8 * port; + } +} + +static bool t6030_ps_lower_off(void __iomem *reg) +{ + u32 v = readl(reg), now; + + if (!FIELD_GET(PS_ACTUAL, v) && !FIELD_GET(PS_TARGET, v)) + return true; + writel(v & ~(PS_AUTO_ENABLE | PS_TARGET), reg); + return !readl_poll_timeout_atomic(reg, now, !FIELD_GET(PS_ACTUAL, now), + 1, PS_OFF_TIMEOUT_US); +} + +static void t6030_atc_after_commit(struct apple_sleep *s) +{ + unsigned int i; + + t6030.atc_lowered = 0; + for (i = 0; i < T6030_ATC_WORDS; i++) { + void __iomem *reg = t6030_atc_reg(s, i); + u32 v = readl(reg); + + t6030.atc_saved[i] = v; + if (i >= 3 || !FIELD_GET(PS_ACTUAL, v)) + continue; + if (i % 3 == 1 && t6030_usb_aon_kept_port(i / 3)) + continue; + t6030.atc_lowered |= BIT(i); + if (!t6030_ps_lower_off(reg)) + t6030_sleep_failed("ATC0 power word failed to turn off"); + } +} + +static void t6030_ps_aon_back(struct apple_sleep *s) +{ + int i; + u32 now; + + for (i = T6030_ATC_WORDS - 1; i >= 0; i--) { + void __iomem *reg = t6030_atc_reg(s, i); + + if (!(t6030.atc_lowered & BIT(i))) + continue; + writel(t6030.atc_saved[i] & ~PS_FLAGS, reg); + if (readl_poll_timeout_atomic(reg, now, FIELD_GET(PS_ACTUAL, now), 1, + PS_OFF_TIMEOUT_US) && i < 3) + t6030_sleep_failed("ATC0 power word failed to return"); + } + t6030.atc_lowered = 0; +} + +static void t6030_sleep_commit_regs(struct apple_sleep *s) +{ + unsigned int i; + + if (s->cpus_stop_ret) + t6030_sleep_failed("the other cores' stop"); + + t6030_gp_phy_park(s); + if (t6030_sleep_lower(s, T6030_LOWER_PHY, ARRAY_SIZE(t6030_lowered))) + t6030_sleep_failed("storage PHY power word"); + t6030_gp_clk_off(); + + for (i = 0; i < ARRAY_SIZE(t6030_auto_off); i++) + t6030.auto_off_saved[i] = readl(s->ps + t6030_auto_off[i]); + t6030.auto_staged = true; + t6030_seq_save(t6030.blk, &t6030.wake_early); + t6030_seq_save(t6030.blk, &t6030.wake); + + t6030_cpm_entry(); + + if (t6030_seq_run_strict(t6030.blk, &t6030.commit)) + t6030_sleep_failed("apple,seq-commit"); + + t6030_atc_after_commit(s); + sleep_ps_save(s); +} + +static void t6030_sleep_pre_commit(struct apple_sleep *s) +{ + u64 at = s->smc_idle_sent + (u64)arch_timer_get_cntfrq() * + s->soc->smc_policy->idle_to_timer_us / USEC_PER_SEC; + + t6030_sleep_clean(s); + while (__arch_counter_get_cntpct() < at) + cpu_relax(); + + t6030_ps_at_commit(s); +} + +static void t6030_sleep_post_timer(struct apple_sleep *s) +{ + u32 mask = s->soc->spmi_notify_sleep & ~T6030_SPMI_DONE; + u8 ctl = 0, v; + int ret; + + if (!t6030.alarm_valid) + goto recommit; + ret = t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_READL, T6030_RTC_CTL, NULL, &ctl, 1); + if (!ret && (ctl & T6030_RTC_CTL_FIRED)) { + v = 0x43; + ret = t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_WRITEL, T6030_RTC_CTL, &v, NULL, 1); + } + if (!ret) + ret = t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_WRITEL, T6030_RTC_COMPARE, + t6030.alarm_compare, NULL, 4); + if (!ret) { + v = 0; + ret = t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_WRITEL, T6030_RTC_MASK, &v, NULL, 1); + } + if (!ret) { + v = 0x41; + t6030_pmu_xfer(s, mask, T6030_SPMI_EXT_WRITEL, T6030_RTC_CTL, &v, NULL, 1); + } + writel(mask, s->spmi + SPMI_NOTIFY_ENABLE); +recommit: + writel(readl(s->cllt + T6030_CLLT_SLEEP), s->cllt + T6030_CLLT_SLEEP); + writel(1, s->commit); + udelay(T6030_RECOMMIT_US); + writel(readl(s->cllt + T6030_CLLT_SLEEP), s->cllt + T6030_CLLT_SLEEP); + writel(1, s->commit); +} + +static void t6030_sleep_wfi_again(struct apple_sleep *s) +{ + writel(readl(s->cllt + T6030_CLLT_SLEEP), s->cllt + T6030_CLLT_SLEEP); + writel(1, s->commit); +} + +/* + * Wake callbacks and GP PCIe restore + */ +struct t6030_wake_write { + u32 offset; + u32 val; +}; + +static void t6030_wake_afr_on(struct apple_sleep *s) +{ + void __iomem *gpu = t6030.blk[T6030_BLK_PS_GPU]; + u32 val; + + if (!gpu) + return; + writel(T6030_PS_GPU_AFR_ON, gpu + T6030_PS_GPU_AFR); + if (readl_poll_timeout_atomic(gpu + T6030_PS_GPU_AFR, val, + FIELD_GET(PS_ACTUAL, val) == 0xf, 1, 2000)) + dev_warn(s->dev, "T6030 wake: AFR power word not on: %#x\n", val); + writel(T6030_PS_GPU_AFR_AUTO, gpu + T6030_PS_GPU_AFR); + readl(gpu + T6030_PS_GPU_AFR); +} + +static const struct t6030_wake_write t6030_wake_lowered[] = { + { 0x5b8, 0x0f000340 }, { 0x4c8, 0x0f0003f0 }, + { 0x398, 0x340 }, { 0x390, 0x340 }, { 0x388, 0x340 }, { 0x308, 0x340 }, + { 0x2d8, 0x340 }, { 0x298, 0x340 }, { 0x290, 0x340 }, { 0x288, 0x340 }, + { 0x280, 0x340 }, { 0x278, 0x340 }, { 0x270, 0x340 }, { 0x268, 0x340 }, + { 0x250, 0x340 }, { 0x220, 0x340 }, { 0x208, 0x340 }, { 0x200, 0x340 }, + { 0x1f8, 0x340 }, { 0x1d8, 0x340 }, { 0x1d0, 0x0f0003f0 }, + { 0x180, 0x04000340 }, { 0x168, 0x3f0 }, { 0x160, 0x3f0 }, + { T6030_AON(0xc0), 0x3f0 }, { T6030_AON(0xb8), 0x3f0 }, +}; + +static const struct t6030_wake_write t6030_wake_gpu[] = { + { 0x10834, 0x0 }, { 0x10820, 0x4 }, { 0x10874, 0x1 }, { 0x10860, 0x4 }, + { 0x10854, 0x1 }, { 0x10840, 0x4 }, { 0x10110, 0x0 }, { 0x10114, 0x0 }, + { 0x10100, 0x4 }, { 0x10130, 0x0 }, { 0x10134, 0x0 }, { 0x10120, 0x4 }, + { 0x10154, 0x1 }, { 0x10140, 0x4 }, { 0x10170, 0x0 }, { 0x10174, 0x0 }, + { 0x10160, 0x4 }, { 0x10190, 0x0 }, { 0x10194, 0x0 }, { 0x10180, 0x4 }, + { 0x101b0, 0x0 }, { 0x101b4, 0x0 }, { 0x101a0, 0x4 }, { 0x101d0, 0x0 }, + { 0x101d4, 0x0 }, { 0x101c0, 0x4 }, { 0x106f4, 0x0 }, { 0x106e0, 0x4 }, + { 0x10714, 0x0 }, { 0x10700, 0x4 }, { 0x10734, 0x0 }, { 0x10720, 0x4 }, + { 0x10754, 0x0 }, { 0x10740, 0x4 }, { 0x10774, 0x1 }, { 0x10760, 0x4 }, + { 0x10794, 0x0 }, { 0x10780, 0x4 }, { 0x107b4, 0x0 }, { 0x107a0, 0x4 }, + { 0x107d4, 0x1 }, { 0x107c0, 0x4 }, { 0x107f4, 0x0 }, { 0x107e0, 0x4 }, + { 0x10814, 0x0 }, { 0x10800, 0x4 }, { 0x101f4, 0x1 }, { 0x101e0, 0x4 }, + { 0x10214, 0x0 }, { 0x10200, 0x4 }, { 0x10234, 0x0 }, { 0x10220, 0x4 }, + { 0x10274, 0x1 }, { 0x10250, 0x0 }, { 0x10254, 0x0 }, { 0x10260, 0x4 }, + { 0x10240, 0x5 }, { 0x102b0, 0x0 }, { 0x102b4, 0x0 }, { 0x10290, 0x0 }, + { 0x10294, 0x0 }, { 0x102a0, 0x4 }, { 0x10280, 0x5 }, { 0x102f0, 0x0 }, + { 0x102f4, 0x0 }, { 0x102d0, 0x0 }, { 0x102d4, 0x0 }, { 0x102e0, 0x4 }, + { 0x102c0, 0x5 }, { 0x10330, 0x0 }, { 0x10334, 0x0 }, { 0x10310, 0x0 }, + { 0x10314, 0x0 }, { 0x10320, 0x4 }, { 0x10300, 0x5 }, { 0x10370, 0x0 }, + { 0x10374, 0x0 }, { 0x10350, 0x0 }, { 0x10354, 0x0 }, { 0x10360, 0x4 }, + { 0x10340, 0x5 }, { 0x103b0, 0x0 }, { 0x103b4, 0x0 }, { 0x10390, 0x0 }, + { 0x10394, 0x0 }, { 0x103a0, 0x4 }, { 0x10380, 0x5 }, { 0x103f0, 0x0 }, + { 0x103f4, 0x0 }, { 0x103d0, 0x0 }, { 0x103d4, 0x0 }, { 0x103e0, 0x4 }, + { 0x103c0, 0x5 }, { 0x10430, 0x0 }, { 0x10434, 0x0 }, { 0x10410, 0x0 }, + { 0x10414, 0x0 }, { 0x10420, 0x4 }, { 0x10400, 0x5 }, { 0x10450, 0x0 }, + { 0x10454, 0x0 }, { 0x10440, 0x4 }, { 0x10470, 0x0 }, { 0x10474, 0x0 }, + { 0x10460, 0x4 }, { 0x10490, 0x0 }, { 0x10494, 0x0 }, { 0x10480, 0x4 }, + { 0x104b0, 0x0 }, { 0x104b4, 0x0 }, { 0x104a0, 0x4 }, { 0x104d0, 0x0 }, + { 0x104d4, 0x0 }, { 0x104c0, 0x4 }, { 0x104f0, 0x0 }, { 0x104f4, 0x0 }, + { 0x104e0, 0x4 }, { 0x10510, 0x0 }, { 0x10514, 0x0 }, { 0x10500, 0x4 }, + { 0x10530, 0x0 }, { 0x10534, 0x0 }, { 0x10520, 0x4 }, { 0x10550, 0x0 }, + { 0x10554, 0x0 }, { 0x10540, 0x4 }, { 0x10570, 0x0 }, { 0x10574, 0x0 }, + { 0x10560, 0x4 }, { 0x10590, 0x0 }, { 0x10594, 0x0 }, { 0x10580, 0x4 }, + { 0x105b0, 0x0 }, { 0x105b4, 0x0 }, { 0x105a0, 0x4 }, { 0x105d0, 0x0 }, + { 0x105d4, 0x0 }, { 0x105c0, 0x4 }, { 0x105f0, 0x0 }, { 0x105f4, 0x0 }, + { 0x105e0, 0x4 }, { 0x10610, 0x0 }, { 0x10614, 0x0 }, { 0x10600, 0x4 }, + { 0x10630, 0x0 }, { 0x10634, 0x0 }, { 0x10620, 0x4 }, { 0x10650, 0x0 }, + { 0x10654, 0x0 }, { 0x10640, 0x4 }, { 0x10670, 0x0 }, { 0x10674, 0x0 }, + { 0x10660, 0x4 }, { 0x10694, 0x1 }, { 0x10680, 0x4 }, { 0x106b0, 0x0 }, + { 0x106b4, 0x0 }, { 0x106a0, 0x4 }, { 0x106d4, 0x1 }, { 0x106c0, 0x4 }, + { 0x10890, 0x0 }, { 0x10894, 0x0 }, { 0x10880, 0x4 }, { 0x108b4, 0x1 }, + { 0x108a0, 0x4 }, { 0x108d4, 0x1 }, { 0x108c0, 0x4 }, { 0x108f4, 0x1 }, + { 0x108e0, 0x4 }, { 0x10910, 0x0 }, { 0x10914, 0x0 }, { 0x10900, 0x4 }, + { 0x10000, 0x30001 }, + { 0x14000, 0x1 }, { 0x14400, 0x1 }, { 0x14800, 0x1 }, { 0x14c00, 0x1 }, { 0x15000, 0x1 }, +}; + +static void t6030_sleep_unstage(struct apple_sleep *s, u32 offset, u32 before) +{ + const struct apple_sleep_words *all = &s->soc->ps_all; + int i = sleep_ps_find(all->offset, all->count, offset); + + if (i >= 0) + s->ps_commit[i] = before; +} + +static void t6030_sleep_wake_seq(struct t6030_seq *seq, const char *name) +{ + int ret = t6030_seq_run_strict(t6030.blk, seq); + + seq->have_saved = false; + if (ret) + panic("T6030 wake: %s failed: %d", name, ret); +} + +static void t6030_sleep_wake_check_ps(struct apple_sleep *s, const char *step) +{ + const u32 *all = s->soc->ps_all.offset; + const u32 *aon = s->soc->ps_aon_all.offset; + int i; + + for (i = 0; i < s->soc->ps_all.count; i++) + if (s->ps_late[i]) + dev_err(s->dev, "wake, %s: power word %#x not on: %#x\n", + step, all[i], readl(s->ps + all[i])); + for (i = 0; i < s->soc->ps_aon_all.count; i++) + if (s->ps_aon_late[i]) + dev_err(s->dev, "wake, %s: always-on word %#x not on: %#x\n", + step, aon[i], readl(s->ps_aon + aon[i])); +} + +static void t6030_sleep_unstage_aon(struct apple_sleep *s, u32 offset, u32 before) +{ + int i = sleep_ps_find(s->soc->ps_aon_all.offset, s->soc->ps_aon_all.count, offset); + + if (i >= 0) + s->ps_aon_commit[i] = before; +} + +static void t6030_ps_unstage_display_off(struct apple_sleep *s) +{ + unsigned int i; + + if (!t6030.ps_display_staged) + return; + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + + if (e->aon) + t6030_sleep_unstage_aon(s, e->off, t6030.ps_on_saved[i]); + else + t6030_sleep_unstage(s, e->off, t6030.ps_on_saved[i]); + } + for (i = 0; i < ARRAY_SIZE(t6030_ps_auto_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_auto_order[i]]; + + if (e->aon) + t6030_sleep_unstage_aon(s, e->off, t6030.ps_auto_saved[i]); + else + t6030_sleep_unstage(s, e->off, t6030.ps_auto_saved[i]); + } +} + +static void t6030_ps_finish_display_off(struct apple_sleep *s) +{ + unsigned int i; + + if (!t6030.ps_display_staged) + return; + t6030.ps_display_staged = false; + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + void __iomem *r = t6030_ps_reg(s, e); + u32 saved = t6030.ps_on_saved[i]; + + if ((readl(r) & T6030_PS_STAGE_BITS) != (saved & T6030_PS_STAGE_BITS)) + t6030_ps_restore_word(r, saved); + } + for (i = 0; i < ARRAY_SIZE(t6030_ps_auto_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_auto_order[i]]; + void __iomem *r = t6030_ps_reg(s, e); + u32 saved = t6030.ps_auto_saved[i]; + + if ((readl(r) & T6030_PS_STAGE_BITS) != (saved & T6030_PS_STAGE_BITS)) + t6030_ps_restore_word(r, saved); + } +} + +static bool t6030_apcie_ps_step(struct apple_sleep *s, u32 off, u32 first, u32 then, u32 actual) +{ + void __iomem *r = s->ps + off; + u32 v = 0; + int ret; + + writel(first, r); + ret = readl_poll_timeout_atomic(r, v, FIELD_GET(PS_ACTUAL, v) == actual, 1, 1000); + if (then) + writel(then, r); + if (ret) + dev_warn(s->dev, "T6030 wake: PCIe PS %#x stayed %#x (want %#x)\n", + off, v, actual); + return !ret; +} + +static void t6030_gp_rw(void __iomem *base, u32 off, u32 val) +{ + readl(base + off); + writel(val, base + off); +} + +static void t6030_gp_clocks_wake(void) +{ + void __iomem *a = t6030.gp_axi2af; + void __iomem *c = t6030.gp_cio3pll; + void __iomem *k = t6030.gp_clkgen; + + if (!a || !c || !k) + return; + readl(a + 0x34); + readl(a + 0x38); + t6030_gp_rw(a, 0x0, 0x211); + readl(a + 0xc); + readl(a + 0x10); + t6030_gp_rw(a, 0x108, 0x100031); + readl(a + 0x10c); + readl(a + 0x110); + t6030_gp_rw(a, 0x600, 0xc0110001); + t6030_gp_rw(a, 0xc00, 0x1ffffff); + readl(a + 0xd48); + readl(a + 0xe58); + t6030_gp_rw(a, 0x1000, 0x101); + t6030_gp_rw(c, 0x0, 0x81f55); + t6030_gp_rw(c, 0x24, 0x818); + t6030_gp_rw(c, 0x28, 0xb18); + readl(c + 0x38); + t6030_gp_rw(c, 0x4c, 0x1f800095); + t6030_gp_rw(c, 0xe4, 0x1024201); + t6030_gp_rw(c, 0xfc, 0x30b40b4); + t6030_gp_rw(k, 0x0, 0x23d); + t6030_gp_rw(k, 0x4, 0x80000030); + t6030_gp_rw(k, 0x0, 0x239); + readl(k + 0x0); + readl(k + 0x0); + writel(0x239, k + 0x0); +} + +static void __iomem *t6030_gpw_blk(u8 b) +{ + switch (b) { + case T6030_GPW_RC: + return t6030.gp_rc; + case T6030_GPW_PHY_COMMON: + return t6030.gp_phy_common; + case T6030_GPW_PHY_SHARED: + return t6030.gp_phy; + case T6030_GPW_PHY_IP: + return t6030.gp_phy_ip; + } + return NULL; +} + +static void t6030_gp_common_wake(struct apple_sleep *s) +{ + unsigned int i, misses = 0; + u8 b; + + for (b = 0; b < T6030_GPW_BLOCKS; b++) + if (!t6030_gpw_blk(b)) + return; + for (i = 0; i < ARRAY_SIZE(t6030_gp_wake); i++) { + const struct t6030_gpw *g = &t6030_gp_wake[i]; + void __iomem *r = t6030_gpw_blk(g->blk) + g->off; + u32 v = 0; + + if (g->op == T6030_GPW_WRITE) { + writel(g->val, r); + } else if (readl_poll_timeout_atomic(r, v, v == g->val, 1, 1000)) { + if (!misses++) + dev_warn(s->dev, + "T6030 wake: GP PCIe step %u read %#x (want %#x)\n", + i, v, g->val); + } + } +} + +static void t6030_apcie_wake(struct apple_sleep *s) +{ + void __iomem *pinctrl = t6030.qblk[T6030_QBLK_PINCTRL]; + bool gpio_on = sleep_ps_on(s, T6030_PS_GPIO); + unsigned int i; + bool phy_ok; + + t6030_apcie_ps_step(s, T6030_PS_APCIE_GP, 0x4f, 0x1000004f, 0xf); + t6030_apcie_ps_step(s, T6030_PS_ANS, 0xf00200f, 0x1f00200f, 0xf); + t6030_apcie_ps_step(s, T6030_PS_APCIE_SYS_GP, 0xf00200f, 0x1f00200f, 0xf); + t6030_apcie_ps_step(s, T6030_PS_APCIE_ST, 0xf, 0x1000000f, 0xf); + t6030_apcie_ps_step(s, T6030_PS_APCIE_SYS_ST, 0xf00000f, 0x1f00000f, 0xf); + t6030_apcie_ps_step(s, T6030_PS_APCIE_PHY_SW, 0xf000340, 0, 0); + /* + * Hold PHY_SW low for 10.7 ms, then drive PERST# low (0x76802) and + * release it high (0x76a02) on each GP PCIe port. + */ + mdelay(10); + udelay(700); + if (pinctrl && gpio_on) { + for (i = 0; i < T6030_GP_PERST_PORTS; i++) { + void __iomem *pin; + + if (!t6030.perst_valid[i]) + continue; + pin = pinctrl + 4 * t6030.perst_pin[i]; + readl(pin); + writel(0x76802, pin); + writel(0x76a02, pin); + } + } + /* Wait 1.6 ms after PERST# before bringing GP clocks and PHY_SW back up. */ + udelay(1600); + t6030_gp_clocks_wake(); + phy_ok = t6030_apcie_ps_step(s, T6030_PS_APCIE_PHY_SW, 0xf00000f, 0x1f00000f, 0xf); + if (phy_ok) + t6030_gp_common_wake(s); +} + +static void t6030_ps_restore_early(struct apple_sleep *s) +{ + unsigned long bit; + int i; + + for (i = ARRAY_SIZE(t6030_ps_lower_order) - 1; i >= 0; i--) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_lower_order[i]]; + + if (!test_bit(i, t6030.ps_lowered)) + continue; + t6030_ps_restore_word(t6030_ps_reg(s, e), t6030.ps_lower_saved[i]); + } + bitmap_zero(t6030.ps_lowered, ARRAY_SIZE(t6030_ps_lower_order)); + + for_each_set_bit(bit, t6030.ps_extra_lowered, ARRAY_SIZE(t6030_ps_entries)) { + const struct t6030_ps_entry *e = &t6030_ps_entries[bit]; + + t6030_ps_restore_word(t6030_ps_reg(s, e), t6030.ps_extra_saved[bit]); + } + bitmap_zero(t6030.ps_extra_lowered, ARRAY_SIZE(t6030_ps_entries)); + + /* + * Re-power only staged domains that were actually active before sleep (such as GPIO) + * without leaking domains that genpd had powered off. + */ + if (t6030.ps_display_staged) { + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = &t6030_ps_entries[t6030_ps_on_order[i]]; + + if (!FIELD_GET(PS_TARGET, t6030.ps_on_saved[i])) + continue; + t6030_ps_restore_word(t6030_ps_reg(s, e), t6030.ps_on_saved[i]); + } + } + t6030_apcie_wake(s); +} + +static int t6030_ps_force_active_restore(void __iomem *reg, struct t6030_ps_wake_sample *sample) +{ + u64 start = __arch_counter_get_cntpct(); + u32 keep; + int ret; + + /* Keep the live AUTO state and omit status bits, as in sleep_ps_restore(). */ + keep = sample->saved & ~(PS_AUTO_ENABLE | PS_AUTO_STATE | PS_PARENT_MISSING | + PS_DEV_DISABLE | PS_FLAGS | PS_ACTUAL | PS_TARGET); + keep |= (sample->before & PS_AUTO_STATE) | PS_TARGET; + writel(keep, reg); + ret = readl_poll_timeout_atomic(reg, sample->active, + (sample->active & PS_ACTUAL) == PS_ACTUAL, + 1, PS_OFF_TIMEOUT_US); + if (!ret && (sample->saved & PS_AUTO_ENABLE)) + writel(keep | PS_AUTO_ENABLE, reg); + sample->after = readl(reg); + sample->us = div_u64((__arch_counter_get_cntpct() - start) * USEC_PER_SEC, + arch_timer_get_cntfrq()); + + return ret; +} + +static void t6030_ps_rewake_pmp(struct apple_sleep *s, int sram_idx, int pmp_idx) +{ + struct t6030_ps_wake_sample *sram = &t6030.pms_sram_wake, *pmp = &t6030.pmp_wake; + struct apple_sleep_coproc *c; + void __iomem *sram_reg = s->ps + T6030_PS_PMS_SRAM, *pmp_reg = s->ps + T6030_PS_PMP; + bool retry = apple_sleep_pmp_wake_error(); + int ret; + + /* Own both words even on timeout so the generic passes cannot retry them. */ + s->ps_done[sram_idx] = true; + s->ps_done[pmp_idx] = true; + t6030.pmp_wake_sampled = true; + t6030.pmp_wake_timeout = 0; + /* A failed wake can leave the live target off. Keep the original AUTO policy. */ + if (!retry) + sram->saved = s->ps_commit[sram_idx]; + sram->before = readl(sram_reg); + s->ps_rewoken++; + ret = t6030_ps_force_active_restore(sram_reg, sram); + + *pmp = (struct t6030_ps_wake_sample) { + .before = readl(pmp_reg), + .saved = retry ? pmp->saved : s->ps_commit[pmp_idx], + }; + if (ret) { + t6030.pmp_wake_timeout = T6030_PS_PMS_SRAM; + pmp->after = pmp->before; + } else { + s->ps_rewoken++; + ret = t6030_ps_force_active_restore(pmp_reg, pmp); + if (ret) + t6030.pmp_wake_timeout = T6030_PS_PMP; + } + WRITE_ONCE(pmp_sram_failed, t6030.pmp_wake_timeout == T6030_PS_PMS_SRAM); + WRITE_ONCE(pmp_wake_error, ret); + c = t6030_pmp_coproc(); + if (c) + c->wake_err = ret; +} + +static void t6030_ps_rewake_mid(struct apple_sleep *s) +{ + const struct apple_sleep_words *all = &s->soc->ps_all; + struct apple_sleep_words word = { .count = 1 }; + int sram_idx, pmp_idx; + unsigned int i; + + sram_idx = sleep_ps_find(all->offset, all->count, T6030_PS_PMS_SRAM); + pmp_idx = sleep_ps_find(all->offset, all->count, T6030_PS_PMP); + if (sram_idx < 0 || pmp_idx < 0 || + (!(s->ps_commit[pmp_idx] & PS_TARGET) && !apple_sleep_pmp_wake_error())) { + sleep_ps_rewake_words(s, &t6030_wake_mid_words, false); + return; + } + + for (i = 0; i < ARRAY_SIZE(t6030_ps_wake_mid); i++) { + word.offset = &t6030_ps_wake_mid[i]; + if (*word.offset == T6030_PS_PMS_SRAM) + t6030_ps_rewake_pmp(s, sram_idx, pmp_idx); + else if (*word.offset != T6030_PS_PMP) + sleep_ps_rewake_words(s, &word, false); + } +} + +static void t6030_sleep_wake(struct apple_sleep *s) +{ + void __iomem *gpu = t6030.blk[T6030_BLK_PS_GPU]; + unsigned int i; + + t6030_slc_on(s); + s->pins_lost = s->pins_saved_valid; + t6030_ps_restore_early(s); + + sleep_note(s, 0x70); + for (i = 0; i < T6030_WAKE_WORDS; i++) { + t6030.wake_status[i] = readl(s->wake + T6030_WAKE_STATUS + 4 * i); + if (i < ARRAY_SIZE(s->wake_status)) + s->wake_status[i] = t6030.wake_status[i]; + } + t6030_sleep_wake_seq(&t6030.wake_early, "apple,seq-wake-early"); + sleep_note(s, 0x71); + + /* Restore pre-entry commit table so sleep_ps_rewake brings only pre-sleep domains back. */ + if (t6030.auto_staged) + for (i = 0; i < ARRAY_SIZE(t6030_auto_off); i++) + t6030_sleep_unstage(s, t6030_auto_off[i], t6030.auto_off_saved[i]); + for (i = 0; i < t6030.nlowered; i++) + t6030_sleep_unstage(s, t6030_lowered[i], t6030.lowered_saved[i]); + if (t6030.i2c6_ps_staged) { + t6030_sleep_unstage(s, T6030_PS_I2C6, t6030.i2c6_ps_saved); + t6030.i2c6_ps_staged = false; + } + t6030_ps_unstage_display_off(s); + t6030.auto_staged = false; + t6030.nlowered = 0; + + sleep_ps_rewake_begin(s); + sleep_ps_rewake_words(s, &t6030_wake_early_words, false); + sleep_ps_rewake_settle(s); + apple_sleep_restore_pins(); + + t6030_wake_afr_on(s); + for (i = 0; i < ARRAY_SIZE(t6030_wake_lowered); i++) { + u32 off = t6030_wake_lowered[i].offset; + void __iomem *r = (off & SLEEP_PS_WAKE_AON) ? + s->ps_aon + (off & ~SLEEP_PS_WAKE_AON) : s->ps + off; + + writel(t6030_wake_lowered[i].val, r); + readl(r); + } + for (i = 0; gpu && i < ARRAY_SIZE(t6030_wake_gpu); i++) { + writel(t6030_wake_gpu[i].val, gpu + t6030_wake_gpu[i].offset); + readl(gpu + t6030_wake_gpu[i].offset); + } + if (t6030.ptd_update) { + if (t6030.ptd_read) + readq(t6030.ptd_read + T6030_PTD_TGT_READ); + writeq(T6030_MASK_LATE, t6030.ptd_update + T6030_PTD_REQUEST); + } + t6030_sleep_wake_check_ps(s, "before the memory side"); + sleep_note(s, 0x72); + + t6030_sleep_wake_seq(&t6030.wake, "apple,seq-wake"); + if (t6030.mem_configured) { + t6030_mem_config_run(T6030_MEM_CONFIG_TAIL, ARRAY_SIZE(t6030_mem_config)); + t6030_mem_perf(s); + } + sleep_note(s, 0x73); + + t6030_ps_rewake_mid(s); + writel(T6030_SPMI_WAKE_ACK0, s->spmi + T6030_SPMI_ACK(0)); + writel(T6030_SPMI_WAKE_MASK0, s->spmi + T6030_SPMI_MASK(0)); + writel(T6030_SPMI_A0_WAKE_ACK2, s->spmi_a0 + T6030_SPMI_ACK(2)); + writel(T6030_SPMI_A0_WAKE_MASK2, s->spmi_a0 + T6030_SPMI_MASK(2)); + t6030_wake_masks_restore(s); + if (t6030.notify_staged) { + writel(t6030.notify_saved[1], s->spmi + SPMI_NOTIFY_ENABLE); + writel(t6030.notify_saved[0], s->spmi_a0 + SPMI_NOTIFY_ENABLE); + t6030.notify_staged = false; + } + sleep_note(s, 0x74); + + sleep_ps_rewake_words(s, &t6030_wake_late_words, false); + sleep_ps_rewake_rest(s); + if (t6030.i2c6_saved) { + t6030.i2c6_saved = false; + if (t6030.i2c6 && FIELD_GET(PS_ACTUAL, readl(s->ps + T6030_PS_I2C6)) == 0xf) { + for (i = 0; i < ARRAY_SIZE(t6030_i2c6_regs); i++) { + writel(t6030.i2c6_regs_saved[i], + t6030.i2c6 + t6030_i2c6_regs[i]); + readl(t6030.i2c6 + t6030_i2c6_regs[i]); + } + } + } + t6030_ps_aon_back(s); + t6030_ps_finish_display_off(s); + if (t6030.gate_dispext1_staged) { + writel(t6030.gate_dispext1_saved, s->pwrgate + T6030_PWRGATE_DISPEXT1); + t6030.gate_dispext1_staged = false; + } + t6030.ptd_sleep_ctrl_staged = false; + t6030.dart_sep_staged = false; + + apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); + t6030_sleep_wake_check_ps(s, "at the end"); + t6030.pmu_wake_pending = true; + sleep_note(s, 0x75); +} + +static void t6030_sleep_pmu_wake(struct apple_sleep *s) +{ + u32 runtime; + u8 ctl = 0, stage = 0xfe; + int ret; + + if (t6030.pmp_wake_sampled) { + const struct t6030_ps_wake_sample *sram = &t6030.pms_sram_wake; + const struct t6030_ps_wake_sample *pmp = &t6030.pmp_wake; + u32 timeout = t6030.pmp_wake_timeout; + + t6030.pmp_wake_sampled = false; + if (timeout) + dev_err(s->dev, + "PMP wake timeout at %#x (SRAM %08x->%08x %uus, PMP %08x->%08x %uus)\n", + timeout, sram->before, sram->after, sram->us, + pmp->before, pmp->after, pmp->us); + else + dev_dbg(s->dev, + "PMP wake: SRAM %08x->%08x (%uus), PMP %08x->%08x (%uus)\n", + sram->before, sram->after, sram->us, + pmp->before, pmp->after, pmp->us); + } + + if (!t6030.pmu_wake_pending) + return; + t6030.pmu_wake_pending = false; + runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); + ret = t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_READL, + T6030_RTC_CTL, NULL, &ctl, 1); + t6030_pmu_xfer(s, runtime & ~T6030_SPMI_DONE, T6030_SPMI_EXT_WRITEL, 0xf801, + &stage, NULL, 1); + writel(runtime, s->spmi + SPMI_NOTIFY_ENABLE); + t6030_last_pmu_reads(s); + if (ret) + dev_warn(s->dev, "T6030: PMU wake RTC control read failed (%d)\n", ret); + else + dev_dbg(s->dev, "T6030: PMU wake RTC control %#x\n", ctl); +} + +/* + * Per-core WFI arming + */ +static int t6030_sleep_cpu_prepare(u64 mpidr) +{ + return 0; +} + +static void t6030_sleep_cpu_restore(u64 mpidr) +{ +} + +static void t6030_deep_wfi_arm(void) +{ + sysreg_clear_set_s(T6030_CYC_OVRD, + T6030_CYC_OVRD_WFI_MODE | T6030_CYC_OVRD_DISABLE_WFI_RET, + FIELD_PREP(T6030_CYC_OVRD_WFI_MODE, 3)); + sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_ENABLE); + isb(); + if (is_kernel_in_hyp_mode()) { + dsb(sy); + t8142_el1_wfi(); + } +} + +/* + * Coprocessor gates and profile descriptor + */ +static bool t6030_macos_off_at_commit(u32 offset) +{ + return sleep_ps_find(t6030_ps_macos_off, ARRAY_SIZE(t6030_ps_macos_off), offset) >= 0; +} + +static const struct apple_sleep_gate_coproc t6030_gate_coprocs[] = { + { .path = "/soc/dcp@28ec00000", .must_stop = true, .ps = T6030_PS_DISP_CPU }, + { .path = "/soc/dcp@2d2c00000", .must_stop = true, .ps = T6030_PS_DISPEXT0_CPU }, + { .path = "/soc/dcp@2d6c00000", .must_stop = true, .ps = T6030_PS_DISPEXT1_CPU }, + { .path = "/soc/dma-controller@289c00000", .must_stop = true, .ps = T6030_PS_SIO_CPU, + .explicit_run_index = true, .run_index = 0 }, + { .path = "/soc/nvme@38dcc0000", .must_stop = true, .ps = T6030_PS_ANS, + .explicit_run_index = true, .run_index = 1 }, + { .path = "/soc/sep@29e400000" }, + { .path = "/soc/mtp@37a400000" }, + { .path = "/soc/aop@374c00000" }, + { .path = "/soc/smc@36c400000" }, + { .path = "/soc/gpu@292400000" }, +}; + +static const struct apple_sleep_word t6030_gate_off[] = { + { "ATC0_PCIE", 0x518 }, { "ATC0_CIO", 0x520 }, + { "ATC1_PCIE", 0x528 }, { "ATC1_CIO", 0x530 }, + { "ATC2_PCIE", 0x538 }, { "ATC2_CIO", 0x540 }, + { "ATC3_PCIE", 0x548 }, { "ATC3_CIO", 0x550 }, + { "ATC0_CIO_PCIE", 0x570 }, { "ATC0_CIO_USB", 0x578 }, + { "ATC1_CIO_PCIE", 0x580 }, { "ATC1_CIO_USB", 0x588 }, + { "ATC2_CIO_PCIE", 0x590 }, { "ATC2_CIO_USB", 0x598 }, + { "ATC3_CIO_PCIE", 0x5a0 }, { "ATC3_CIO_USB", 0x5a8 }, +}; + +static const struct apple_sleep_wake_name t6030_wake_names[] = { + { 3, "AOP.CPUWakeupAP" }, { 51, "AOP.OutboxNotEmpty" }, + { 74, "AOP.SPMI0.SW3" }, { 83, "AOP.SPMI1.SW3" }, + { 87, "ATC0.CIOWakeup" }, { 88, "ATC0.USBWakeup" }, + { 89, "ATC1.CIOWakeup" }, { 90, "ATC1.USBWakeup" }, + { 91, "ATC2.CIOWakeup" }, { 92, "ATC2.USBWakeup" }, + { 93, "ATC3.CIOWakeup" }, { 94, "ATC3.USBWakeup" }, + { 104, "MTP.DOCK.CHANNELS.AP0.IRQ" }, { 111, "MTP.GPIO.IRQ4" }, + { 113, "MTP.GPIO.IRQ6" }, { 132, "NUB.APWakeupTime" }, + { 133, "NUB.APWatchdog" }, { 147, "NUB.GPIO.IRQ6" }, + { 159, "NUB.SPMI0.SW3" }, { 169, "NUB.SPMI1.SW3" }, + { 185, "NUB.WakeupAP" }, { 190, "SMC.CPUWakeupAP" }, + { 214, "SMC.OutboxNotEmpty" }, +}; + +static const struct apple_sleep_ops t6030_sleep_ops = { + .deep_wfi_arm = t6030_deep_wfi_arm, + .resume = cpu_resume, + .aic_mask_all = aic_sleep_mask_all, + .aic_ack = aic_sleep_ack, + .aic_restore = aic_sleep_restore, + .map_regs = t6030_sleep_map_regs, + .display_off = t6030_sleep_display_off, + .before_enclave = t6030_sleep_before_enclave, + .final_check = t6030_sleep_final_check, + .prepare_regs = t6030_sleep_prepare_regs, + .undo_regs = t6030_sleep_undo_regs, + .after_ans = t6030_sleep_after_ans, + .after_early = t6030_sleep_after_early, + .commit_notice = t6030_sleep_commit_notice, + .commit_regs = t6030_sleep_commit_regs, + .pre_commit = t6030_sleep_pre_commit, + .post_timer = t6030_sleep_post_timer, + .wfi_again = t6030_sleep_wfi_again, + .wake = t6030_sleep_wake, + .pmu_wake = t6030_sleep_pmu_wake, + .cpu_prepare = t6030_sleep_cpu_prepare, + .cpu_restore = t6030_sleep_cpu_restore, + .domain_kept = t6030_ps_domain_kept, + .macos_off_at_commit = t6030_macos_off_at_commit, +}; + +static const struct apple_sleep_soc t6030_sleep_soc = { + .ops = &t6030_sleep_ops, + .smc_policy = &t6030_smc_policy, + .early_context = true, + .own_wake = true, + .pen_deep = true, + .el1_wfi = true, + .wdt_wd1 = true, + .gp_host_apart = true, + .failed_stop_ends_sleep = true, + .no_pmu_notes = true, + .ps_aon_debug_switch = 0xb0, + .wake_mask = T6030_WAKE_MASK, + .wake_status = T6030_WAKE_STATUS, + .wake_words = T6030_WAKE_WORDS, + .wake_last_word = T6030_WAKE_LAST_BITS, + .wake_names = t6030_wake_names, + .nwake_names = ARRAY_SIZE(t6030_wake_names), + .pmu_usid = 0xb, + .pmu_sleep_reg = 0xf801, + .pmu_sleep_val = 0x50, + .spmi_notify_sleep = 0x2000001, + .cpu_cluster_affinity = 1, + .cpu_clusters = 2, + .cpu_cores_per_cluster = 6, + .cpu_start_stride = 6, + .cpu_start_every_cluster = true, + .cluster_cpu = { T6030_CLUSTER_E, T6030_CLUSTER_P }, + .ncluster_cpu = 2, + .ndisp = 3, + .display_order = { 0, 2, 1 }, + .ps = { + .disp = { + { T6030_PS_DISP_CPU, T6030_PS_DISP_FE, T6030_PS_DISP_SYS }, + { T6030_PS_DISPEXT0_CPU, T6030_PS_DISPEXT0_FE, T6030_PS_DISPEXT0_SYS }, + { T6030_PS_DISPEXT1_CPU, T6030_PS_DISPEXT1_FE, T6030_PS_DISPEXT1_SYS }, + }, + .sio_cpu = T6030_PS_SIO_CPU, + .sep = T6030_PS_SEP, + .ap_tmm = T6030_PS_AP_TMM, + .gpio = T6030_PS_GPIO, + .ans = T6030_PS_ANS, + .apcie_gp = T6030_PS_APCIE_GP, + .apcie_sys_gp = T6030_PS_APCIE_SYS_GP, + .apcie_st = T6030_PS_APCIE_ST, + .apcie_sys_st = T6030_PS_APCIE_SYS_ST, + .apcie_phy_sw = T6030_PS_APCIE_PHY_SW, + }, + .gate_coprocs = t6030_gate_coprocs, + .ngate_coprocs = ARRAY_SIZE(t6030_gate_coprocs), + .gate_off = t6030_gate_off, + .ngate_off = ARRAY_SIZE(t6030_gate_off), + .gate_fail_closed = true, + .ps_all = SLEEP_WORDS(t6030_ps_all), + .ps_aon_all = SLEEP_WORDS(t6030_ps_aon_all), + .ps_macos_on = SLEEP_WORDS(t6030_ps_macos_on), + .ps_macos_off = SLEEP_WORDS(t6030_ps_macos_off), + .ps_aon_macos_off = SLEEP_WORDS(t6030_ps_aon_macos_off), + .ps_boot_auto = SLEEP_WORDS(t6030_ps_boot_auto), + .ps_aon_boot_auto = SLEEP_WORDS(t6030_ps_aon_boot_auto), + .ps_wake_order = SLEEP_WORDS(t6030_ps_wake_order), + .ps_aon_wake_order = SLEEP_WORDS(t6030_ps_aon_wake_order), +}; diff --git a/drivers/soc/apple/sleep-test.c b/drivers/soc/apple/sleep-test.c index 5a697a8de5174..150ddbc88e5f2 100644 --- a/drivers/soc/apple/sleep-test.c +++ b/drivers/soc/apple/sleep-test.c @@ -16,6 +16,7 @@ static const char *const apple_sleep_test_profiles[] = { "apple,t8103-sleep", "apple,t8112-sleep", "apple,t8122-sleep", + "apple,t6030-sleep", }; /* @@ -231,8 +232,9 @@ static void apple_sleep_test_layout(struct kunit *test) KUNIT_EXPECT_GT(test, soc->cpu_start_stride, 0); KUNIT_EXPECT_LE(test, soc->nclk_mux_parked, SLEEP_CLK_MUX_MAX); KUNIT_EXPECT_LE(test, soc->ncllt, SLEEP_CLLT_MAX); - /* Every SoC steps its memory controller down (T8142: from the J813 trace). */ - KUNIT_EXPECT_GE(test, soc->nmcc, 1); + /* Providers without own_wake step their memory controller via the shared MCC list. */ + if (!soc->own_wake) + KUNIT_EXPECT_GE(test, soc->nmcc, 1); KUNIT_EXPECT_LE(test, soc->nmcc, MCC_CHANNELS); KUNIT_EXPECT_LE(test, soc->namcc, SLEEP_AMCC_MAX); /* Each SoC NI table is mapped 0x80 bytes long (the T8142 sleep node). */ diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index f87a3659e8d33..e19ab1148c4da 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1990,6 +1990,20 @@ static void apple_sleep_coproc_stop(struct apple_sleep *s, struct apple_sleep_co apple_sleep_coproc_run_off(c); } +/* After commit-time stops: a coprocessor whose last stop failed in this sleep, or NULL */ +static struct apple_sleep_coproc *apple_sleep_coprocs_stop_failed(void) +{ + int i; + + for (i = 0; i < SLEEP_COPROCS; i++) { + struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; + + if (c->dev && c->ready && c->stopped && c->stop_ret) + return c; + } + return NULL; +} + static void apple_sleep_coprocs_stop(struct apple_sleep *s, bool first) { /* @@ -5376,6 +5390,23 @@ static void sleep_ps_rewake_words(struct apple_sleep *s, const struct apple_slee } } +static void sleep_ps_rewake_settle(struct apple_sleep *s) +{ + const u32 *all = s->soc->ps_all.offset, *aon = s->soc->ps_aon_all.offset; + int i, pass; + + for (pass = 0; pass < PS_REWAKE_PASSES; pass++) { + for (i = 0; i < s->soc->ps_all.count; i++) + if (s->ps_late[i]) + s->ps_late[i] = sleep_ps_restore(sleep_power_reg(s, all[i]), + s->ps_commit[i]); + for (i = 0; i < s->soc->ps_aon_all.count; i++) + if (s->ps_aon_late[i]) + s->ps_aon_late[i] = sleep_ps_restore(s->ps_aon + aon[i], + s->ps_aon_commit[i]); + } +} + static void sleep_ps_rewake_rest(struct apple_sleep *s) { const struct apple_sleep_soc *soc = s->soc; @@ -6691,6 +6722,13 @@ static int apple_sleep_smc_commit_notice(struct apple_sleep *s) &s->smc_idle_sent, &s->smc_idle_ack); } +static void apple_sleep_smc_until_before_slpa(struct apple_sleep *s, u32 us) +{ + if (s->smc.dev && s->smc.held && s->smc.saved_ops && + s->smc.saved_ops->until_before_slpa) + s->smc.saved_ops->until_before_slpa(s->smc.data, us); +} + static void apple_sleep_enter_cleanup(struct apple_sleep *s) { if (s->regs_staged) @@ -10643,6 +10681,7 @@ static const struct apple_sleep_soc t8142_sleep_soc = { #include "sleep-t8103.h" #include "sleep-t8122.h" #include "sleep-t8112.h" +#include "sleep-t6030.h" /* * Qualified profiles expose system sleep. Inventory-only profiles match for a @@ -10659,6 +10698,7 @@ static const struct of_device_id apple_sleep_of_match[] = { { .compatible = "apple,t8103-sleep", .data = &t8103_sleep_soc }, { .compatible = "apple,t8112-sleep", .data = &t8112_sleep_soc }, { .compatible = "apple,t8122-sleep", .data = &t8122_sleep_soc }, + { .compatible = "apple,t6030-sleep", .data = &t6030_sleep_soc }, { } }; diff --git a/tools/asahi/run-host-tests.py b/tools/asahi/run-host-tests.py index ab96117cd7086..ce292b888eb73 100644 --- a/tools/asahi/run-host-tests.py +++ b/tools/asahi/run-host-tests.py @@ -626,6 +626,8 @@ def mutations(flag, names, base, expect=KILL): 't6030-pmp-dt-tests.py': [(out('--output') + ['--dtc', '{dtc}'], PASS)], 't6030-pmp-graph-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], 't6030-pmp-supplier-tests.py': [(out('--output'), PASS), (out('--output') + ['--mutations'], PASS)], + 't6030-sleep-qblk-tests.py': [([], PASS)] + + mutations('--mutation', ('pcie-dart-offset',), []), 't6030-wiring-tests.py': [(out(), PASS), (out() + ['--old-classifier', 'tb'], PASS), (out() + ['--old-classifier', 'dcp'], PASS)], 't6040-calibration-tests.py': [([], PASS)], diff --git a/tools/asahi/t6030-sleep-qblk-tests.py b/tools/asahi/t6030-sleep-qblk-tests.py new file mode 100755 index 0000000000000..41f2a9aaa657e --- /dev/null +++ b/tools/asahi/t6030-sleep-qblk-tests.py @@ -0,0 +1,141 @@ +#!/usr/bin/env python3 +# SPDX-License-Identifier: GPL-2.0-only OR MIT +"""Host tests verifying T6030 sleep quiesce register block enum mapping.""" + +import argparse +from collections import Counter +from pathlib import Path +import re +import sys + +MUTATIONS = { + "pcie-dart-offset": ( + '\tt6030.qblk[T6030_QBLK_PCIE_DART0] = t6030_map_phandle(s, "apple,pcie-darts", 0);\n' + '\tt6030.qblk[T6030_QBLK_PCIE_DART1] = t6030_map_phandle(s, "apple,pcie-darts", 1);', + '\tfor (i = 0; i < 2; i++)\n' + '\t\tt6030.qblk[T6030_QBLK_PCIE_DART0 + i] =\n' + '\t\t\tt6030_map_phandle(s, "apple,pcie-darts", i);', + ), +} + + +def parse_qblk_enum(quiesce_text: str) -> list[str]: + m = re.search(r"enum\s+t6030_qblk\s*\{(.*?)\};", quiesce_text, re.S) + if not m: + raise AssertionError("enum t6030_qblk not found in sleep-t6030-quiesce.h") + names = [] + for raw in m.group(1).splitlines(): + line = raw.split("//", 1)[0].strip() + if not line or line.startswith("/*") or line.startswith("*"): + continue + tok = line.rstrip(",").strip() + if tok == "T6030_QBLK_COUNT": + break + if "=" in tok: + raise AssertionError(f"unexpected explicit enumerator value: {tok}") + names.append(tok) + if not names: + raise AssertionError("empty enum t6030_qblk") + return names + + +def check_qblk_mapping(quiesce_text: str, sleep_text: str) -> list[str]: + errors: list[str] = [] + enum_names = parse_qblk_enum(quiesce_text) + enum_index = {name: idx for idx, name in enumerate(enum_names)} + count = len(enum_names) + + writes: Counter[int] = Counter() + + # Check indexed loop assignments: for (i = 0; i < N; i++) t6030.qblk[BASE + i] = ... + loop_re = re.compile( + r"for\s*\(\s*i\s*=\s*0\s*;\s*i\s*<\s*(\d+)\s*;\s*i\+\+\s*\)\s*" + r"t6030\.qblk\[\s*(T6030_QBLK_[A-Z0-9_]+)\s*\+\s*i\s*\]\s*=", + re.S, + ) + matched_spans = [] + for m in loop_re.finditer(sleep_text): + matched_spans.append(m.span()) + bound = int(m.group(1)) + base = m.group(2) + if base not in enum_index: + errors.append(f"unknown qblk enum base in loop: {base}") + continue + start = enum_index[base] + prefix = re.sub(r"0$", "", base) + for offset in range(bound): + slot = start + offset + if slot >= count: + errors.append(f"{base} + {offset} exceeds T6030_QBLK_COUNT ({count})") + continue + writes[slot] += 1 + expected = f"{prefix}{offset}" + actual = enum_names[slot] + if actual != expected: + errors.append( + f"non-contiguous qblk loop {base} + {offset}: " + f"indexed {actual} (slot {slot}) instead of {expected}" + ) + + # Mask matched loop regions before scanning direct assignments + masked = list(sleep_text) + for lo, hi in matched_spans: + for pos in range(lo, hi): + masked[pos] = " " + direct_text = "".join(masked) + + # Reject any remaining arithmetic inside t6030.qblk[...] writes + for m in re.finditer(r"t6030\.qblk\[([^\]]+)\]\s*=", direct_text): + expr = m.group(1).strip() + if expr in enum_index: + writes[enum_index[expr]] += 1 + else: + errors.append(f"unsupported qblk write index expression: t6030.qblk[{expr}]") + + for idx, name in enumerate(enum_names): + n = writes[idx] + if n == 0: + errors.append(f"unmapped qblk enum slot: {name} (index {idx})") + elif n > 1: + errors.append(f"qblk enum slot overwritten ({n} writes): {name} (index {idx})") + + # Verify every table entry in sleep-t6030-quiesce.h references a known mapped slot + for ref in sorted(set(re.findall(r"\b(T6030_QBLK_[A-Z0-9_]+)\b", quiesce_text))): + if ref == "T6030_QBLK_COUNT": + continue + if ref not in enum_index: + errors.append(f"quiesce table references unknown qblk: {ref}") + elif writes[enum_index[ref]] != 1: + errors.append(f"quiesce table uses improperly mapped qblk: {ref}") + + return errors + + +def main() -> int: + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--mutation", choices=sorted(MUTATIONS), help="run one negative control") + args = parser.parse_args() + + repo = Path(__file__).resolve().parents[2] + quiesce_text = (repo / "drivers/soc/apple/sleep-t6030-quiesce.h").read_text() + sleep_text = (repo / "drivers/soc/apple/sleep-t6030.h").read_text() + + if args.mutation: + target, replacement = MUTATIONS[args.mutation] + if sleep_text.count(target) != 1: + print(f"FAIL: mutation target {args.mutation} not found", file=sys.stderr) + return 2 + sleep_text = sleep_text.replace(target, replacement, 1) + + errors = check_qblk_mapping(quiesce_text, sleep_text) + if errors: + for err in errors: + print(f"AssertionError: {err}", file=sys.stderr) + return 1 + + print("PASS: all 13 T6030 qblk enum slots mapped uniquely and contiguously where indexed") + return 0 + + +if __name__ == "__main__": + raise SystemExit(main()) From f0273427aecef0642219f33355dde7da4f39b73b Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Wed, 2 Dec 2026 12:56:19 -0500 Subject: [PATCH 11/19] arm64: dts: apple: add T6030 sleep controller and enable on J516s Add the apple,t6030-sleep controller node with its register windows, phandle links, wake sources, SMC policy, and explicit entry/wake register sequences in t6030.dtsi, add the PCIe sleep register windows, and enable deep sleep on J516s. Signed-off-by: Diljit Singh --- arch/arm64/boot/dts/apple/t6030-j516s.dts | 53 +++ arch/arm64/boot/dts/apple/t6030.dtsi | 437 +++++++++++++++++++++- 2 files changed, 488 insertions(+), 2 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6030-j516s.dts b/arch/arm64/boot/dts/apple/t6030-j516s.dts index 516301e47298e..2b4e90f6fe172 100644 --- a/arch/arm64/boot/dts/apple/t6030-j516s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j516s.dts @@ -40,6 +40,7 @@ &wifi0 { brcm,board-type = "apple,jura"; + wakeup-source; }; &bluetooth0 { @@ -114,6 +115,9 @@ &hpm0 { apple,irq-status-update; + apple,cable-change-ssps; + apple,sleep-ssps; + apple,sleep-ssps-rules; }; &hpm1 { @@ -195,3 +199,52 @@ &sep { status = "okay"; }; + +&t6030_sleep { + apple,debug-port = <&hpm0>; + status = "okay"; +}; + +&smc { + apple,sleep-wake-type; + apple,wake-reasons = <0 8 9 11 13 35 40 41 42 43 44 45 48>; + apple,wake-reason-names = "pwrbtn", "lid", "sdconn", "charger", "wifibt", + "trackpadkeyboard", "acattach", "acdetach", "USB-C_plug", + "USB2_plug", "USB2_wake", "aupo", "rtc"; + apple,dark-wake-reasons = "USB-C_plug", "wifibt"; +}; + +&smc_gpio { + apple,output-templates = <19 0x00800000>; +}; + +&ps_spi2 { + apple,always-on; + apple,no-auto-pm; +}; + +&spi2 { + status = "okay"; +}; + +&mesa { + spi-cs-setup-delay-ns = <20>; + spi-cs-hold-delay-ns = <20>; + enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; + status = "okay"; +}; + +&ps_atc0_usb { + apple,sleep-retained; +}; + +&ps_i2c6 { + apple,always-on; + apple,no-auto-pm; +}; + +&mtp_hid { + actuator { + apple,sleep-report = /bits/ 8 <0x21 0x00>; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6030.dtsi b/arch/arm64/boot/dts/apple/t6030.dtsi index 1908ac36daba3..3746d8839c28a 100644 --- a/arch/arm64/boot/dts/apple/t6030.dtsi +++ b/arch/arm64/boot/dts/apple/t6030.dtsi @@ -1098,6 +1098,428 @@ interrupts = ; }; + /* System sleep controller; enabled by qualified boards. */ + t6030_sleep: sleep-controller@350700000 { + compatible = "apple,t6030-sleep"; + reg = <0x3 0x50700000 0x0 0x18000>, + <0x3 0x50724000 0x0 0x4000>, + <0x3 0x50734000 0x0 0x10>, + <0x3 0x50768000 0x0 0x40>, + <0x3 0x50780000 0x0 0x8>, + <0x3 0x642d4000 0x0 0x4>, + <0x3 0x642b0000 0x0 0x30>, + <0x3 0x64004000 0x0 0x48>, + <0x3 0x64714000 0x0 0x100>, + <0x3 0x64280000 0x0 0x4000>, + <0x3 0x64908000 0x0 0x100>, + <0x3 0x50040000 0x0 0x60>, + <0x3 0x5005c000 0x0 0x4>, + <0x2 0x90e80000 0x0 0x18000>, + <0x2 0x20000000 0x0 0xc0000>, + <0x2 0x22000000 0x0 0xc0000>, + <0x2 0x20400000 0x0 0x4000>, + <0x3 0x503c0000 0x0 0x20000>, + <0x2 0x10e40000 0x0 0xc000>, + <0x2 0x11e40000 0x0 0xc000>, + <0x2 0x201c1c00 0x0 0x4>, + <0x2 0x221c1c00 0x0 0x4>, + <0x2 0x20600000 0x0 0x1000>, + <0x2 0x20800000 0x0 0x1000>, + <0x2 0x20a00000 0x0 0x1000>, + <0x2 0x20c00000 0x0 0x1000>, + <0x2 0x20e00000 0x0 0x1000>, + <0x2 0x22400000 0x0 0x1000>, + <0x2 0x22600000 0x0 0x1000>, + <0x2 0x22800000 0x0 0x1000>, + <0x2 0x22a00000 0x0 0x1000>, + <0x2 0x22c00000 0x0 0x1000>, + <0x2 0x22e00000 0x0 0x1000>, + <0x3 0x50c08000 0x0 0x4000>; + reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", + "commit", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", + "clk-mux", "clk-perf", "ps-gpu", "amcc0", "amcc1", + "dcs0", "ptd", "cpm-e", "cpm-p", "amcc0-mc", "amcc1-mc", + "dcs0-ch1", "dcs0-ch2", "dcs0-ch3", "dcs0-ch4", "dcs0-ch5", + "dcs1-ch0", "dcs1-ch1", "dcs1-ch2", "dcs1-ch3", "dcs1-ch4", + "dcs1-ch5", "pmp-mbox"; + apple,display-coprocessors = <&dcp>, <&dcpext>, <&dcpext1>; + apple,display-darts = <&dcp_dart>, <&dcpext_dart>, <&dcpext1_dart>; + apple,pcie-host = <&pcie0>; + apple,pcie-darts = <&pcie0_dart_0>, <&pcie0_dart_1>; + apple,pinctrl = <&pinctrl_ap>; + apple,sep-dart = <&sep_dart>; + apple,mtp-dart = <&mtp_dart>; + /* The ADT's pmgr ap-wake-sources */ + apple,wake-enable = <3 51 74 83 87 88 89 90 91 92 93 94 104 111 + 113 132 133 147 159 169 185 190 214>; + /* + * SMC pmVC value followed by minimum spacings in us: sleep warning + * to pmVC, pmVC to SLPA, SLPA to AP idle, AP idle to commit, and + * wake notice to pmVC (0 on T6030). + */ + apple,smc-sleep-policy = <0x100 286300 4446000 560 9510 0>; + /* + * macOS 27.2's entry sequences on J516s: PTD no-demand votes (64-bit), + * then WD0 off, AMCC ways/planes, DCS, GPU PMGR, CPU power gates, + * perf word, AFR=0, clusters, SIO, clock muxes, CLLT. + */ + apple,seq-prepare = + <8 17 0x10900 0x20000000>, + <8 17 0x10900 0x20000000>, + <8 17 0x10908 0x20000000>, + <8 17 0x10918 0x20000000>, + <8 17 0x10900 0x20000000>, + <8 17 0x10908 0x20000000>, + <8 17 0x10918 0x20000000>, + <0 17 0x18328 0x20000>; + apple,seq-notice = + <8 17 0x10900 0x20000000>, + <8 17 0x10908 0x20000000>, + <8 17 0x10918 0x20000000>; + apple,seq-commit = + /* WD0 off, then SLC off */ + <0 6 0xc 0x0>, + <16 0 0x0 0x0>, + /* AMCC0's planes' ways, a bit at a time, in 64-bit accesses */ + <17 14 0x24000 0x1>, + <17 14 0x24000 0x2>, + <17 14 0x24000 0x4>, + <17 14 0x24000 0x8>, + <17 14 0x24000 0x10>, + <17 14 0x24000 0x20>, + <17 14 0x24000 0x40>, + <17 14 0x24000 0x80>, + <17 14 0x24000 0x100>, + <17 14 0x24000 0x200>, + <17 14 0x24000 0x400>, + <17 14 0x24000 0x800>, + <17 14 0x24000 0x1000>, + <17 14 0x24000 0x2000>, + <17 14 0x24000 0x4000>, + <17 14 0x24000 0x8000>, + <17 14 0x64000 0x1>, + <17 14 0x64000 0x2>, + <17 14 0x64000 0x4>, + <17 14 0x64000 0x8>, + <17 14 0x64000 0x10>, + <17 14 0x64000 0x20>, + <17 14 0x64000 0x40>, + <17 14 0x64000 0x80>, + <17 14 0x64000 0x100>, + <17 14 0x64000 0x200>, + <17 14 0x64000 0x400>, + <17 14 0x64000 0x800>, + <17 14 0x64000 0x1000>, + <17 14 0x64000 0x2000>, + <17 14 0x64000 0x4000>, + <17 14 0x64000 0x8000>, + <17 14 0xa4000 0x1>, + <17 14 0xa4000 0x2>, + <17 14 0xa4000 0x4>, + <17 14 0xa4000 0x8>, + <17 14 0xa4000 0x10>, + <17 14 0xa4000 0x20>, + <17 14 0xa4000 0x40>, + <17 14 0xa4000 0x80>, + <17 14 0xa4000 0x100>, + <17 14 0xa4000 0x200>, + <17 14 0xa4000 0x400>, + <17 14 0xa4000 0x800>, + <17 14 0xa4000 0x1000>, + <17 14 0xa4000 0x2000>, + /* Each AMCC plane stage word, 3 to 2 to 0 */ + <9 14 0x24800 0x1>, + <9 14 0x24800 0x2>, + <9 14 0x64800 0x1>, + <9 14 0x64800 0x2>, + <9 14 0xa4800 0x1>, + <9 14 0xa4800 0x2>, + <9 15 0x24800 0x1>, + <9 15 0x24800 0x2>, + <9 15 0x64800 0x1>, + <9 15 0x64800 0x2>, + <9 15 0xa4800 0x1>, + <9 15 0xa4800 0x2>, + /* DCS */ + <3 16 0x584 0x1>, + <3 16 0x584 0x2>, + <3 16 0x584 0x4>, + <3 16 0x584 0x8>, + <3 16 0x584 0x10>, + <3 16 0x584 0x20>, + <3 16 0x584 0x40>, + <3 16 0x584 0x80>, + <3 16 0x584 0x100>, + <3 16 0x588 0x1>, + <3 16 0x588 0x10>, + /* Read both AMCC0 status words twice after the final DCS step */ + <11 14 0x27068 0x0>, + <11 14 0x27068 0x0>, + <11 14 0x27070 0x0>, + <11 14 0x27070 0x0>, + /* + * GPU PMGR, CPU power gates, perf, AFR=0, clusters, SIO, clk- + * mux, CLLT + */ + <3 13 0x10000 0x1>, + <0 1 0xc0 0x80000000>, + <0 1 0xc8 0x80000000>, + <0 1 0xc0 0x80000000>, + <0 1 0xc8 0x80000000>, + <0 13 0x15000 0x0>, + <1 13 0x153e0 0x0>, + <0 13 0x14000 0x0>, + <1 13 0x143e0 0x0>, + <0 13 0x14400 0x0>, + <1 13 0x147e0 0x0>, + <0 13 0x14800 0x0>, + <1 13 0x14be0 0x0>, + <0 13 0x14c00 0x0>, + <1 13 0x14fe0 0x0>, + <4 12 0x0 0x0>, + <0 13 0x100 0x0>, + <0 4 0x0 0x0>, + <0 4 0x4 0x0>, + <3 0 0x1b8 0x10000000>, + <3 0 0x1d0 0x10000000>, + <0 11 0x48 0x80100000>, + <0 11 0x50 0x80100000>, + <0 11 0x4c 0x80100000>, + <0 11 0x40 0x80100000>, + <0 11 0x3c 0x80100000>, + <3 3 0x24 0x30000>; + /* + * macOS 27.2's wake on J516s: each complex's word, waited on, and two CPU + * power gates; after the power words, the other two gates, then + * the AMCCs' ways and planes and the DCS back. + */ + apple,seq-wake-early = + /* Each complex on, waited on, and read again */ + <1 4 0x0 0>, <0 4 0x0 0xf>, <6 4 0x0 0x10>, <1 4 0x0 0>, + <1 4 0x4 0>, <0 4 0x4 0xf>, <6 4 0x4 0x10>, <1 4 0x4 0>, + <2 1 0x0 0x80000000>, <2 1 0x60 0x80000000>; + apple,seq-wake = + <2 1 0xc0 0x80000000>, <2 1 0xc8 0x80000000>, + /* AMCC0's ways that were on, a bit at a time, after their words */ + <0x4000f 14 0x24000 0x1>, + <13 14 0x24010 0>, <13 14 0x24018 0>, + <11 14 0x25000 0>, <10 14 0x24000 0x1>, + <0x4000f 14 0x24000 0x2>, + <13 14 0x24020 0>, <13 14 0x24028 0>, + <11 14 0x25008 0>, <10 14 0x24000 0x2>, + <0x4000f 14 0x24000 0x4>, + <13 14 0x24030 0>, <13 14 0x24038 0>, + <11 14 0x25010 0>, <10 14 0x24000 0x4>, + <0x4000f 14 0x24000 0x8>, + <13 14 0x24040 0>, <13 14 0x24048 0>, + <11 14 0x25018 0>, <10 14 0x24000 0x8>, + <0x4000f 14 0x24000 0x10>, + <13 14 0x24050 0>, <13 14 0x24058 0>, + <11 14 0x25020 0>, <10 14 0x24000 0x10>, + <0x4000f 14 0x24000 0x20>, + <13 14 0x24060 0>, <13 14 0x24068 0>, + <11 14 0x25028 0>, <10 14 0x24000 0x20>, + <0x4000f 14 0x24000 0x40>, + <13 14 0x24070 0>, <13 14 0x24078 0>, + <11 14 0x25030 0>, <10 14 0x24000 0x40>, + <0x4000f 14 0x24000 0x80>, + <13 14 0x24080 0>, <13 14 0x24088 0>, + <11 14 0x25038 0>, <10 14 0x24000 0x80>, + <0x4000f 14 0x24000 0x100>, + <13 14 0x24090 0>, <13 14 0x24098 0>, + <11 14 0x25040 0>, <10 14 0x24000 0x100>, + <0x4000f 14 0x24000 0x200>, + <13 14 0x240a0 0>, <13 14 0x240a8 0>, + <11 14 0x25048 0>, <10 14 0x24000 0x200>, + <0x4000f 14 0x24000 0x400>, + <13 14 0x240b0 0>, <13 14 0x240b8 0>, + <11 14 0x25050 0>, <10 14 0x24000 0x400>, + <0x4000f 14 0x24000 0x800>, + <13 14 0x240c0 0>, <13 14 0x240c8 0>, + <11 14 0x25058 0>, <10 14 0x24000 0x800>, + <0x4000f 14 0x24000 0x1000>, + <13 14 0x240d0 0>, <13 14 0x240d8 0>, + <11 14 0x25060 0>, <10 14 0x24000 0x1000>, + <0x4000f 14 0x24000 0x2000>, + <13 14 0x240e0 0>, <13 14 0x240e8 0>, + <11 14 0x25068 0>, <10 14 0x24000 0x2000>, + <0x4000f 14 0x24000 0x4000>, + <13 14 0x240f0 0>, <13 14 0x240f8 0>, + <11 14 0x25070 0>, <10 14 0x24000 0x4000>, + <0x4000f 14 0x24000 0x8000>, + <13 14 0x24100 0>, <13 14 0x24108 0>, + <11 14 0x25078 0>, <10 14 0x24000 0x8000>, + <0x4000f 14 0x64000 0x1>, + <13 14 0x64010 0>, <13 14 0x64018 0>, + <11 14 0x65000 0>, <10 14 0x64000 0x1>, + <0x4000f 14 0x64000 0x2>, + <13 14 0x64020 0>, <13 14 0x64028 0>, + <11 14 0x65008 0>, <10 14 0x64000 0x2>, + <0x4000f 14 0x64000 0x4>, + <13 14 0x64030 0>, <13 14 0x64038 0>, + <11 14 0x65010 0>, <10 14 0x64000 0x4>, + <0x4000f 14 0x64000 0x8>, + <13 14 0x64040 0>, <13 14 0x64048 0>, + <11 14 0x65018 0>, <10 14 0x64000 0x8>, + <0x4000f 14 0x64000 0x10>, + <13 14 0x64050 0>, <13 14 0x64058 0>, + <11 14 0x65020 0>, <10 14 0x64000 0x10>, + <0x4000f 14 0x64000 0x20>, + <13 14 0x64060 0>, <13 14 0x64068 0>, + <11 14 0x65028 0>, <10 14 0x64000 0x20>, + <0x4000f 14 0x64000 0x40>, + <13 14 0x64070 0>, <13 14 0x64078 0>, + <11 14 0x65030 0>, <10 14 0x64000 0x40>, + <0x4000f 14 0x64000 0x80>, + <13 14 0x64080 0>, <13 14 0x64088 0>, + <11 14 0x65038 0>, <10 14 0x64000 0x80>, + <0x4000f 14 0x64000 0x100>, + <13 14 0x64090 0>, <13 14 0x64098 0>, + <11 14 0x65040 0>, <10 14 0x64000 0x100>, + <0x4000f 14 0x64000 0x200>, + <13 14 0x640a0 0>, <13 14 0x640a8 0>, + <11 14 0x65048 0>, <10 14 0x64000 0x200>, + <0x4000f 14 0x64000 0x400>, + <13 14 0x640b0 0>, <13 14 0x640b8 0>, + <11 14 0x65050 0>, <10 14 0x64000 0x400>, + <0x4000f 14 0x64000 0x800>, + <13 14 0x640c0 0>, <13 14 0x640c8 0>, + <11 14 0x65058 0>, <10 14 0x64000 0x800>, + <0x4000f 14 0x64000 0x1000>, + <13 14 0x640d0 0>, <13 14 0x640d8 0>, + <11 14 0x65060 0>, <10 14 0x64000 0x1000>, + <0x4000f 14 0x64000 0x2000>, + <13 14 0x640e0 0>, <13 14 0x640e8 0>, + <11 14 0x65068 0>, <10 14 0x64000 0x2000>, + <0x4000f 14 0x64000 0x4000>, + <13 14 0x640f0 0>, <13 14 0x640f8 0>, + <11 14 0x65070 0>, <10 14 0x64000 0x4000>, + <0x4000f 14 0x64000 0x8000>, + <13 14 0x64100 0>, <13 14 0x64108 0>, + <11 14 0x65078 0>, <10 14 0x64000 0x8000>, + <0x4000f 14 0xa4000 0x1>, + <13 14 0xa4010 0>, <13 14 0xa4018 0>, + <11 14 0xa5000 0>, <10 14 0xa4000 0x1>, + <0x4000f 14 0xa4000 0x2>, + <13 14 0xa4020 0>, <13 14 0xa4028 0>, + <11 14 0xa5008 0>, <10 14 0xa4000 0x2>, + <0x4000f 14 0xa4000 0x4>, + <13 14 0xa4030 0>, <13 14 0xa4038 0>, + <11 14 0xa5010 0>, <10 14 0xa4000 0x4>, + <0x4000f 14 0xa4000 0x8>, + <13 14 0xa4040 0>, <13 14 0xa4048 0>, + <11 14 0xa5018 0>, <10 14 0xa4000 0x8>, + <0x4000f 14 0xa4000 0x10>, + <13 14 0xa4050 0>, <13 14 0xa4058 0>, + <11 14 0xa5020 0>, <10 14 0xa4000 0x10>, + <0x4000f 14 0xa4000 0x20>, + <13 14 0xa4060 0>, <13 14 0xa4068 0>, + <11 14 0xa5028 0>, <10 14 0xa4000 0x20>, + <0x4000f 14 0xa4000 0x40>, + <13 14 0xa4070 0>, <13 14 0xa4078 0>, + <11 14 0xa5030 0>, <10 14 0xa4000 0x40>, + <0x4000f 14 0xa4000 0x80>, + <13 14 0xa4080 0>, <13 14 0xa4088 0>, + <11 14 0xa5038 0>, <10 14 0xa4000 0x80>, + <0x4000f 14 0xa4000 0x100>, + <13 14 0xa4090 0>, <13 14 0xa4098 0>, + <11 14 0xa5040 0>, <10 14 0xa4000 0x100>, + <0x4000f 14 0xa4000 0x200>, + <13 14 0xa40a0 0>, <13 14 0xa40a8 0>, + <11 14 0xa5048 0>, <10 14 0xa4000 0x200>, + <0x4000f 14 0xa4000 0x400>, + <13 14 0xa40b0 0>, <13 14 0xa40b8 0>, + <11 14 0xa5050 0>, <10 14 0xa4000 0x400>, + <0x4000f 14 0xa4000 0x800>, + <13 14 0xa40c0 0>, <13 14 0xa40c8 0>, + <11 14 0xa5058 0>, <10 14 0xa4000 0x800>, + <0x4000f 14 0xa4000 0x1000>, + <13 14 0xa40d0 0>, <13 14 0xa40d8 0>, + <11 14 0xa5060 0>, <10 14 0xa4000 0x1000>, + <0x4000f 14 0xa4000 0x2000>, + <13 14 0xa40e0 0>, <13 14 0xa40e8 0>, + <11 14 0xa5068 0>, <10 14 0xa4000 0x2000>, + /* Stage bits that were on, 0 to 1 to 3, after their words */ + <0x4000f 14 0x24800 0x1>, + <13 14 0x24858 0>, <13 14 0x24810 0>, <13 14 0x24860 0>, + <10 14 0x24800 0x1>, + <0x3000f 14 0x24800 0x2>, + <13 14 0x24868 0>, <13 14 0x24870 0>, + <10 14 0x24800 0x2>, + <0x4000f 14 0x64800 0x1>, + <13 14 0x64858 0>, <13 14 0x64810 0>, <13 14 0x64860 0>, + <10 14 0x64800 0x1>, + <0x3000f 14 0x64800 0x2>, + <13 14 0x64868 0>, <13 14 0x64870 0>, + <10 14 0x64800 0x2>, + <0x4000f 14 0xa4800 0x1>, + <13 14 0xa4858 0>, <13 14 0xa4810 0>, <13 14 0xa4860 0>, + <10 14 0xa4800 0x1>, + <0x3000f 14 0xa4800 0x2>, + <13 14 0xa4868 0>, <13 14 0xa4870 0>, + <10 14 0xa4800 0x2>, + <0x4000f 15 0x24800 0x1>, + <13 15 0x24858 0>, <13 15 0x24810 0>, <13 15 0x24860 0>, + <10 15 0x24800 0x1>, + <0x3000f 15 0x24800 0x2>, + <13 15 0x24868 0>, <13 15 0x24870 0>, + <10 15 0x24800 0x2>, + <0x4000f 15 0x64800 0x1>, + <13 15 0x64858 0>, <13 15 0x64810 0>, <13 15 0x64860 0>, + <10 15 0x64800 0x1>, + <0x3000f 15 0x64800 0x2>, + <13 15 0x64868 0>, <13 15 0x64870 0>, + <10 15 0x64800 0x2>, + <0x4000f 15 0xa4800 0x1>, + <13 15 0xa4858 0>, <13 15 0xa4810 0>, <13 15 0xa4860 0>, + <10 15 0xa4800 0x1>, + <0x3000f 15 0xa4800 0x2>, + <13 15 0xa4868 0>, <13 15 0xa4870 0>, + <10 15 0xa4800 0x2>, + /* The DCS's bits that were on, one at a time, after their words */ + <0x7000e 16 0x584 0x1>, + <12 16 0x58c 0>, <12 16 0x590 0>, <12 16 0x594 0>, + <12 16 0x598 0>, <12 16 0x59c 0>, + <12 16 0x580 0>, <2 16 0x584 0x1>, + <0x7000e 16 0x584 0x2>, + <12 16 0x5a0 0>, <12 16 0x5a4 0>, <12 16 0x5a8 0>, + <12 16 0x5ac 0>, <12 16 0x5b0 0>, + <12 16 0x580 0>, <2 16 0x584 0x2>, + <0x7000e 16 0x584 0x4>, + <12 16 0x5b4 0>, <12 16 0x5b8 0>, <12 16 0x5bc 0>, + <12 16 0x5c0 0>, <12 16 0x5c4 0>, + <12 16 0x580 0>, <2 16 0x584 0x4>, + <0x7000e 16 0x584 0x8>, + <12 16 0x5c8 0>, <12 16 0x5cc 0>, <12 16 0x5d0 0>, + <12 16 0x5d4 0>, <12 16 0x5d8 0>, + <12 16 0x580 0>, <2 16 0x584 0x8>, + <0x7000e 16 0x584 0x10>, + <12 16 0x5dc 0>, <12 16 0x5e0 0>, <12 16 0x5e4 0>, + <12 16 0x5e8 0>, <12 16 0x5ec 0>, + <12 16 0x580 0>, <2 16 0x584 0x10>, + <0x7000e 16 0x584 0x20>, + <12 16 0x5f0 0>, <12 16 0x5f4 0>, <12 16 0x5f8 0>, + <12 16 0x5fc 0>, <12 16 0x600 0>, + <12 16 0x580 0>, <2 16 0x584 0x20>, + <0x7000e 16 0x584 0x40>, + <12 16 0x604 0>, <12 16 0x608 0>, <12 16 0x60c 0>, + <12 16 0x610 0>, <12 16 0x614 0>, + <12 16 0x580 0>, <2 16 0x584 0x40>, + <0x7000e 16 0x584 0x80>, + <12 16 0x618 0>, <12 16 0x61c 0>, <12 16 0x620 0>, + <12 16 0x624 0>, <12 16 0x628 0>, + <12 16 0x580 0>, <2 16 0x584 0x80>, + <0x7000e 16 0x584 0x100>, + <12 16 0x62c 0>, <12 16 0x630 0>, <12 16 0x634 0>, + <12 16 0x638 0>, <12 16 0x63c 0>, + <12 16 0x580 0>, <2 16 0x584 0x100>, + <0x2000e 16 0x588 0x1>, + <2 16 0x588 0x100>, <2 16 0x588 0x1>, + <0x2000e 16 0x588 0x10>, + <2 16 0x588 0x1000>, <2 16 0x588 0x10>; + status = "disabled"; + }; + nub_spmi: spmi@364714000 { compatible = "apple,t6030-spmi", "apple,t8103-spmi"; reg = <0x3 0x64714000 0x0 0x100>; @@ -1511,10 +1933,21 @@ <0x5 0x9e020000 0x0 0x4000>, /* phy0 */ <0x5 0x9e024000 0x0 0x4000>, /* phy1 */ <0x5 0x9e028000 0x0 0x4000>, /* phy2 */ - <0x5 0x9e02c000 0x0 0x4000>; /* phy3 */ + <0x5 0x9e02c000 0x0 0x4000>, /* phy3 */ + <0x5 0x9c000000 0x0 0x8000>, /* axi2af */ + <0x5 0x9e08a200 0x0 0x4000>, /* cio3pll */ + <0x5 0x9e088000 0x0 0x4000>, /* clkgen */ + <0x5 0x9e008000 0x0 0x4000>, /* phy-common */ + <0x5 0x9e00c000 0x0 0x4000>, /* phy-shared */ + <0x5 0x9e040000 0x0 0x40000>, /* phy-ip */ + <0x5 0x9400c000 0x0 0x4000>, /* intr2axi0 */ + <0x5 0x9500c000 0x0 0x4000>; /* intr2axi1 */ reg-names = "config", "rc", "port0", "port1", "port2", "port3", - "phy0", "phy1", "phy2", "phy3"; + "phy0", "phy1", "phy2", "phy3", + "axi2af", "cio3pll", "clkgen", + "phy-common", "phy-shared", "phy-ip", + "intr2axi0", "intr2axi1"; interrupt-parent = <&aic>; interrupts = , From 6473a6c040b9939999eba0d92d5907ce316527ed Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 02:17:38 -0500 Subject: [PATCH 12/19] arm64: dts: apple: t6030-j516s: name the Touch ID calibration The sensor's binding requires firmware-name: the per-device calibration blob apple_sep loads, and the file the Touch ID setup helper writes. J516s has J514s's SoC, sensor part and enclave profile, which need the calibration alone and no signed root key. Signed-off-by: DjDeveloperr --- arch/arm64/boot/dts/apple/t6030-j516s.dts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/arch/arm64/boot/dts/apple/t6030-j516s.dts b/arch/arm64/boot/dts/apple/t6030-j516s.dts index 2b4e90f6fe172..2831cdb876e6c 100644 --- a/arch/arm64/boot/dts/apple/t6030-j516s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j516s.dts @@ -231,6 +231,8 @@ spi-cs-setup-delay-ns = <20>; spi-cs-hold-delay-ns = <20>; enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; + /* Per-device factory data from this Mac's own iBoot system container. */ + firmware-name = "apple/mesacal-j516s.bin"; status = "okay"; }; From b023a0ebbaadeabc0681676154ed88209de04399 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 02:17:59 -0500 Subject: [PATCH 13/19] selftests: apple: cover the T6030 sleep hooks in host tests The DART's PMP wake gate, the PMGR's kept domains and the PMP bridge's DART call are new to four harnesses that compile those functions. Give the stand-in DARTs the new fields and check them, run the real apple_sleep_domain_kept() with a negative control, and compile the bridge against the real DART header. Signed-off-by: DjDeveloperr --- tools/asahi/apple-dart-tlb-stall-tests.py | 20 +++++++-- tools/asahi/display26-tests.py | 5 +++ tools/asahi/j613-mtp-s2idle-tests.py | 8 +++- .../selftests/drivers/apple/pmgr-inherited.py | 44 ++++++++++++++++--- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/tools/asahi/apple-dart-tlb-stall-tests.py b/tools/asahi/apple-dart-tlb-stall-tests.py index 706ad2ab7e83d..7a20eb52ec342 100644 --- a/tools/asahi/apple-dart-tlb-stall-tests.py +++ b/tools/asahi/apple-dart-tlb-stall-tests.py @@ -35,7 +35,8 @@ 'DART_T8110_TLB_CMD_STREAM', 'DART_T8110_CTC_FLUSH') OPTIONAL_DEFINES = {'DART_T8110_FLUSH_STALL_TIMEOUT', 'DART_T8110_FLUSH_STALL_POLL'} CASES = ('fast', 'stall-after', 'stall-before', 'stuck', 'no-handoff', 'not-scanout', - 'not-range', 'ctc-flush', 'sleep-listed', 'superseded', 'gated', 'two-streams') + 'not-range', 'ctc-flush', 'sleep-listed', 'superseded', 'gated', 'pmp-gated', + 'two-streams') J700 = 'arch/arm64/boot/dts/apple/t8140-j700.dts' # What the J700 display subsystem scans out through: disp0 and dispext0. SCANOUT = {'/soc/iommu@412300000', '/soc/iommu@416300000'} @@ -70,7 +71,7 @@ int num_streams; unsigned int version; unsigned long pgsize; - bool commands_gated, fw_handoff, display_scanout, ctc_flush; + bool commands_gated, pmp_wake_gated, fw_handoff, display_scanout, ctc_flush; struct { unsigned int count; } sleep_restore; unsigned long tlb_commands; void *dev; @@ -302,6 +303,13 @@ dart.lock = 0; } +static void pmp_wake_fails(void) +{ + dart.lock = 1; + dart.pmp_wake_gated = true; + dart.lock = 0; +} + int main(int argc, char **argv) { const char *c = argc > 1 ? argv[1] : ""; @@ -429,14 +437,18 @@ assert(ret == 0 && !errors_logged); assert(commands == 2); assert(now < 31000); - } else if (!strcmp(c, "gated")) { + } else if (!strcmp(c, "gated") || !strcmp(c, "pmp-gated")) { /* Gated while waiting to write: nothing is written. */ busy_until = 30000; other_at = 10000; - other = other_gates; + other = !strcmp(c, "gated") ? other_gates : pmp_wake_fails; ret = range(); assert(ret == -EHOSTDOWN && commands == 0 && !errors_logged); assert(!dart.lock); + /* Already gated: nothing is written either. */ + busy_until = 0; + other = NULL; + assert(range() == -EHOSTDOWN && commands == 0 && !dart.lock); } else if (!strcmp(c, "two-streams")) { /* Each stream of the map, in order, each after the last finished. */ stream.sidmap[0] = BIT(0) | BIT(16); diff --git a/tools/asahi/display26-tests.py b/tools/asahi/display26-tests.py index dc50c2dd4a497..538d0a64f9bfa 100644 --- a/tools/asahi/display26-tests.py +++ b/tools/asahi/display26-tests.py @@ -30,6 +30,7 @@ def main(): #include #include typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; typedef uint64_t u64; +typedef u64 dma_addr_t; typedef u64 phys_addr_t; ''') write(tmp, 'linux/string.h', '#include \n') write(tmp, 'linux/bitops.h', '#pragma once\n#define BIT(x) (1U << (x))\nstatic int fls(unsigned x){return x?32-__builtin_clz(x):0;}\n') @@ -90,6 +91,9 @@ def main(): for name in ('device', 'export', 'mutex', 'of'): write(tmp, 'linux/'+name+'.h', '#include "mock.h"\n') write(tmp, 'linux/errno.h', '#define EPROBE_DEFER 517\n#define ENODEV 19\n#define EINVAL 22\n#define EBUSY 16\n#define EIO 5\n#define ETIMEDOUT 110\n#define EAGAIN 11\n') + # The bridge takes the real DART header; only a T6030 PMP marks its DART for a system sleep. + write(tmp, 'linux/bits.h', '#define BIT(n) (1UL << (n))\n') + write(tmp, 'linux/err.h', '#pragma once\n#define ERR_PTR(e) ((void *)(long)(e))\n') write(tmp, 'linux/kconfig.h', '#define IS_REACHABLE(x) 1\n#define IS_ENABLED(x) 1\n') # The PMP's system-sleep callbacks live in the bridge; this harness never suspends. write(tmp, 'linux/pm.h', '#include "mock.h"\n' @@ -169,6 +173,7 @@ def main(): int apple_pmp_report_check_t6030_gfx(struct device*d){assert(!"unexpected T6030 report on J613");return -EIO;} int apple_pmp_report_set_t6030_gfx(struct device*d,bool enabled){assert(!"unexpected T6030 report on J613");return -EIO;} bool apple_pmp_display_retained_board(void){return false;} +int apple_dart_set_pmp_sleep(struct device_node*n){assert(!"unexpected T6030 sleep on J613");return -EIO;} void apple_pmp_report_sleep(struct device*d,bool at_commit){assert(!"no system sleep here");} void apple_pmp_report_wake(struct device*d,bool real){assert(!"no system sleep here");} int apple_pmp_sleep(const void*data){assert(!"no system sleep here");return -EIO;} diff --git a/tools/asahi/j613-mtp-s2idle-tests.py b/tools/asahi/j613-mtp-s2idle-tests.py index fbf39ce280e26..6e4d79af2cba8 100644 --- a/tools/asahi/j613-mtp-s2idle-tests.py +++ b/tools/asahi/j613-mtp-s2idle-tests.py @@ -19,10 +19,11 @@ def fn(s,n): #define APPLE_ASC_CPU_CONTROL 0x44 #define APPLE_ASC_CPU_CONTROL_RUN 16 #define PM_SUSPEND_TO_IDLE 1 +#define READ_ONCE(x) (*(volatile __typeof__(x) *)&(x)) static int pm_suspend_target_state=1; struct device {void *data;bool awake;}; struct hw {unsigned tcr_bypass;}; -struct apple_dart {bool live_mtp,live_mtp_sleep;struct hw *hw;unsigned tcr;}; +struct apple_dart {bool live_mtp,live_mtp_sleep,pmp_sleep_managed,pmp_wake_gated;struct hw *hw;unsigned tcr;}; struct apple_rtkit_helper {bool adopted;unsigned char *asc_base;}; static void *dev_get_drvdata(struct device *d){return d->data;} static unsigned apple_dart_readl(struct apple_dart *d,unsigned sid){assert(sid==1);return d->tcr;} @@ -51,6 +52,11 @@ def fn(s,n): a.tcr=0;assert(apple_dart_system_suspend(&d)==-EIO);a.tcr=3; assert(!apple_dart_system_suspend(&d));a.tcr=0;assert(apple_dart_system_resume(&d)==-EIO&&a.tcr==0); a.live_mtp=false;assert(apple_dart_system_suspend(&d)==7&&apple_dart_system_resume(&d)==8); + // A PMP DART left off by a failed wake keeps its runtime PM state; any other DART, or this one after a good wake, does not. + a.pmp_sleep_managed=a.pmp_wake_gated=true;assert(!apple_dart_system_suspend(&d)&&!apple_dart_system_resume(&d)&&forced_suspend==1&&forced_resume==1); + a.pmp_wake_gated=false;assert(apple_dart_system_suspend(&d)==7&&apple_dart_system_resume(&d)==8); + a.pmp_sleep_managed=false;a.pmp_wake_gated=true;assert(apple_dart_system_suspend(&d)==7&&apple_dart_system_resume(&d)==8); + a.pmp_wake_gated=false; unsigned regs[32]={0};struct apple_rtkit_helper h={.adopted=true,.asc_base=(void *)regs};d.data=&h;d.awake=false; regs[0x44/4]=16;assert(!apple_rtkit_helper_suspend(&d)&&d.awake);assert(!apple_rtkit_helper_resume(&d)); regs[0x44/4]=0;assert(apple_rtkit_helper_resume(&d)==-EHOSTDOWN&&!regs[0x44/4]); diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index 32c252cffcfc4..dc3ae3f00de62 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -10,8 +10,8 @@ import tempfile -def function(source, name): - match = re.search(r"^static [^\n]*\b" + name + r"\(", source, re.M) +def function(source, name, linkage="static "): + match = re.search(r"^" + linkage + r"[^\n]*\b" + name + r"\(", source, re.M) assert match, name start = source.index("{", match.start()) depth, end = 1, start + 1 @@ -28,6 +28,7 @@ def main(): print("# SKIP: requires the matching kernel source tree") return 4 source = path.read_text() + sleep = (root / "drivers/soc/apple/sleep.c").read_text() start = source.index("#define APPLE_PMGR_RESET") end = source.index("\n", source.index("#define rcdev_to_apple_pmgr_ps", start)) definitions = source[start:end] + "\n" @@ -107,6 +108,14 @@ def main(): #define IS_ENABLED(option) (option) static bool apple_t8132_firmware_path(void) { return firmware_path; } static bool apple_sleep_domain_is_down(struct device_node *n) { (void)n; return false; } +struct apple_sleep; +struct sleep_ops { bool (*domain_kept)(struct apple_sleep *s, int off); }; +struct sleep_soc { const struct sleep_ops *ops; }; +struct apple_sleep { const struct sleep_soc *soc; }; +static struct apple_sleep *apple_sleep; +static int sleep_offset; +static int sleep_ps_offset(struct apple_sleep *s, struct device_node *pd) +{ (void)s; (void)pd; return sleep_offset; } static struct device_node *of_parse_phandle(struct device_node *n, const char *p, int i) { (void)n; (void)p; (void)i; return NULL; } static bool of_device_is_compatible(struct device_node *n, const char *p) @@ -186,6 +195,8 @@ def main(): "apple_pmgr_ps_always_on", "apple_pmgr_ps_probe_auto_enable", "apple_pmgr_ps_probe"] tests = r''' +static bool keeps_428(struct apple_sleep *s, int off) +{ assert(s==apple_sleep && off>=0); return off==0x428; } static void clean(u32 value, int error) { map=(struct regmap){ .value=value, .error=error }; init_count=provider_count=reset_count=0; initialized_off=true; free(driver_data); driver_data=NULL; } @@ -246,6 +257,24 @@ def main(): ps->system_sleep=true; assert(apple_pmgr_ps_power_off(&ps->genpd)==-EBUSY && !map.writes); puts("ok 3 - read errors and lost inherited activity never request a transition"); + /* Only while the system sleeps, and only a domain the sleep provider itself keeps. */ + const struct sleep_ops no_hook={0}, hook={ .domain_kept=keeps_428 }; + struct sleep_soc soc={ .ops=&no_hook }; + struct apple_sleep s={ .soc=&soc }; + ps->inherited_on=false; map.error=0; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==1); + apple_sleep=&s; sleep_offset=0x428; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==2); + soc.ops=&hook; + assert(apple_pmgr_ps_power_off(&ps->genpd)==-EBUSY && map.writes==2); + sleep_offset=-ENODEV; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==3); + sleep_offset=0x430; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==4); + sleep_offset=0x428; ps->system_sleep=false; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==5); + apple_sleep=NULL; + puts("ok 4 - a domain the sleep provider keeps stays on through a system sleep only"); const char *conflicts[]={"apple,firmware-owned","apple,sleep-retained","apple,always-on","apple,min-state", "apple,force-disable","apple,force-reset","apple,externally-clocked","apple,auto-managed", "apple,auto-pm"}; @@ -260,12 +289,13 @@ def main(): assert(!apple_pmgr_ps_power_on(&ps->genpd) && !apple_pmgr_ps_power_off(&ps->genpd)); assert(!map.reads && !map.writes); free(driver_data); driver_data=NULL; - puts("ok 4 - contradictory policy fails before MMIO; firmware policy remains unchanged"); + puts("ok 5 - contradictory policy fails before MMIO; firmware policy remains unchanged"); return 0; } ''' - program = preamble + definitions + fake_set + "\n".join(function(source,n) for n in names) + tests - print("TAP version 13\n1..5", flush=True) + kept = function(sleep, "apple_sleep_domain_kept", "") + program = preamble + definitions + fake_set + kept + "\n".join(function(source,n) for n in names) + tests + print("TAP version 13\n1..6", flush=True) resource.setrlimit(resource.RLIMIT_CORE, (0, 0)) with tempfile.TemporaryDirectory(prefix="apple-pmgr-inherited-") as temporary: tmp=Path(temporary) @@ -279,6 +309,8 @@ def main(): "unchecked-active-state": program.replace("return -EBUSY;", "return 0;", 1), "reset-without-ownership": program.replace( "ps->firmware_owned || ps->inherited_on", "ps->firmware_owned", 1), + "kept-domain-gated": program.replace( + " ||\n\t apple_sleep_domain_kept(ps->dev->of_node)", "", 1), } for name, negative in controls.items(): assert negative != program @@ -288,7 +320,7 @@ def main(): result = subprocess.run([str(tmp/"test")],capture_output=True) if result.returncode == 0: raise RuntimeError(f"negative control passed: {name}") - print("ok 5 - unchecked admission and unowned reset negative controls are rejected") + print("ok 6 - unchecked admission, unowned reset and kept-domain negative controls are rejected") return 0 From 8671481c11e1f14e47febe6211eab603689bc743 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 03:57:31 -0500 Subject: [PATCH 14/19] soc: apple: sleep: t6030: address review feedback on sleep provider and DT Address the review comments on the T6030 deep-sleep provider, SPMI interrupt handling, and device tree: - Gate deep-sleep entry in t6030_sleep_begin() and t6030_sleep_final_check() on pcie-apple being bound and every available GP PCIe DART being host-resumed via apple_dart_is_host_resumed(), now backed by the merged #3809 takeover path. - Keep t6030_sleep_map_regs() read-only at probe; defer the one-time hardware setup (boot replay, pwrgate, CPM, auto-pm, AMCC/DCS memory config, PMU boot latch clear) to the first deep-sleep entry in t6030_sleep_display_off(). - Make t6030_boot_replay() atomic-safe with pre-mapped DT reg "mca-switch" (no ioremap_np/fsleep), skip ATC1/ATC2_PCIE pulses when the domain is already active or its parent ATCn_COMMON is off, and preserve the pre-replay DWI power-state word for refusal/wake restoration. - Derive PERST# pin numbers by PCI slot from port reg properties and replace the hardcoded pinctrl offsets in the quiesce tables with t6030_perst_assert(). - Rename the T6030 sleep node to sleep-controller@3642d4000 with reg index 0 = "commit" and index 5 = "ps" (eliminating the W=1 duplicate unit-address warning with power-management@350700000), add the "mca-switch" reg entry and "apple,i2c6" phandle, and drop the unrelated Touch ID / SPI2 / I2C6 edits from t6030-j516s.dts. - Replace the apple,t6030-spmi compatible with DT boolean "apple,keep-pending-irqs" on J516s nub_spmi/nub_spmi_a0 and keep the stuck-IRQ valve from clearing driver-owned or RX-notify bits. - Guard apple_sleep_domain_kept() with pm_suspend_via_firmware() so s2idle does not keep firmware-sleep domains on, with host selftest coverage; narrow the sleep-test.c nmcc check exception to t6030_sleep_ops; drop the unused .cpu_count = 12 field; and document provenance for the macOS 27.2 (26B123) J516s tables. Signed-off-by: DjDeveloperr --- .../bindings/soc/apple/apple,t6030-sleep.yaml | 27 +- .../devicetree/bindings/spmi/apple,spmi.yaml | 7 + arch/arm64/boot/dts/apple/t6030-j516s.dts | 23 +- arch/arm64/boot/dts/apple/t6030.dtsi | 20 +- drivers/iommu/apple-dart.c | 8 + drivers/soc/apple/sleep-t6030-pcie-wake.h | 5 + drivers/soc/apple/sleep-t6030-quiesce.h | 14 +- drivers/soc/apple/sleep-t6030.h | 243 ++++++++++++++---- drivers/soc/apple/sleep-test.c | 4 +- drivers/soc/apple/sleep.c | 2 +- drivers/spmi/spmi-apple-controller.c | 40 ++- include/linux/soc/apple/dart.h | 2 + .../selftests/drivers/apple/pmgr-inherited.py | 15 +- 13 files changed, 292 insertions(+), 118 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml index faa9a56a8be41..1750f6efd0348 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml @@ -19,17 +19,17 @@ properties: reg: minItems: 33 - maxItems: 34 + maxItems: 35 reg-names: minItems: 33 items: - - const: ps + - const: commit - const: pwrgate - const: cpu-start - const: cllt - const: cluster - - const: commit + - const: ps - const: wdt - const: wake - const: spmi @@ -58,6 +58,7 @@ properties: - const: dcs1-ch4 - const: dcs1-ch5 - const: pmp-mbox + - const: mca-switch apple,display-coprocessors: $ref: /schemas/types.yaml#/definitions/phandle-array @@ -96,6 +97,10 @@ properties: $ref: /schemas/types.yaml#/definitions/phandle description: MTP IOMMU quiesced after SMC AP idle acknowledgment. + apple,i2c6: + $ref: /schemas/types.yaml#/definitions/phandle + description: I2C controller saved and restored across sleep. + apple,debug-port: $ref: /schemas/types.yaml#/definitions/phandle description: USB-PD controller connected to the sleep debug port. @@ -157,14 +162,14 @@ examples: #address-cells = <2>; #size-cells = <2>; - sleep-controller@350700000 { + sleep-controller@3642d4000 { compatible = "apple,t6030-sleep"; - reg = <0x3 0x50700000 0x0 0x18000>, + reg = <0x3 0x642d4000 0x0 0x4>, <0x3 0x50724000 0x0 0x4000>, <0x3 0x50734000 0x0 0x10>, <0x3 0x50768000 0x0 0x40>, <0x3 0x50780000 0x0 0x8>, - <0x3 0x642d4000 0x0 0x4>, + <0x3 0x50700000 0x0 0x18000>, <0x3 0x642b0000 0x0 0x30>, <0x3 0x64004000 0x0 0x48>, <0x3 0x64714000 0x0 0x100>, @@ -192,14 +197,16 @@ examples: <0x2 0x22a00000 0x0 0x1000>, <0x2 0x22c00000 0x0 0x1000>, <0x2 0x22e00000 0x0 0x1000>, - <0x3 0x50c08000 0x0 0x4000>; - reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", - "commit", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", + <0x3 0x50c08000 0x0 0x4000>, + <0x3 0x500400c0 0x0 0x10>; + reg-names = "commit", "pwrgate", "cpu-start", "cllt", "cluster", + "ps", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", "clk-mux", "clk-perf", "ps-gpu", "amcc0", "amcc1", "dcs0", "ptd", "cpm-e", "cpm-p", "amcc0-mc", "amcc1-mc", "dcs0-ch1", "dcs0-ch2", "dcs0-ch3", "dcs0-ch4", "dcs0-ch5", "dcs1-ch0", "dcs1-ch1", "dcs1-ch2", - "dcs1-ch3", "dcs1-ch4", "dcs1-ch5", "pmp-mbox"; + "dcs1-ch3", "dcs1-ch4", "dcs1-ch5", "pmp-mbox", + "mca-switch"; apple,wake-enable = <3 51 132 190 214>; apple,smc-sleep-policy = <0x100 286300 4446000 560 9510 0>; apple,seq-prepare = <8 17 0x10900 0x20000000>; diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml index 9f00cf99cf3bb..7c4808f996501 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -89,6 +89,13 @@ properties: controllers). Not applicable to generation 4 controllers ("apple,t8142-spmi"). + apple,keep-pending-irqs: + type: boolean + description: + Preserve masked pending peripheral interrupt bits at probe and across + dispatches on buses where the firmware sleep path owns peripheral + interrupt status bits. + power-domains: maxItems: 1 diff --git a/arch/arm64/boot/dts/apple/t6030-j516s.dts b/arch/arm64/boot/dts/apple/t6030-j516s.dts index 2831cdb876e6c..dea6cdd02485d 100644 --- a/arch/arm64/boot/dts/apple/t6030-j516s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j516s.dts @@ -218,33 +218,18 @@ apple,output-templates = <19 0x00800000>; }; -&ps_spi2 { - apple,always-on; - apple,no-auto-pm; +&nub_spmi { + apple,keep-pending-irqs; }; -&spi2 { - status = "okay"; -}; - -&mesa { - spi-cs-setup-delay-ns = <20>; - spi-cs-hold-delay-ns = <20>; - enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; - /* Per-device factory data from this Mac's own iBoot system container. */ - firmware-name = "apple/mesacal-j516s.bin"; - status = "okay"; +&nub_spmi_a0 { + apple,keep-pending-irqs; }; &ps_atc0_usb { apple,sleep-retained; }; -&ps_i2c6 { - apple,always-on; - apple,no-auto-pm; -}; - &mtp_hid { actuator { apple,sleep-report = /bits/ 8 <0x21 0x00>; diff --git a/arch/arm64/boot/dts/apple/t6030.dtsi b/arch/arm64/boot/dts/apple/t6030.dtsi index 3746d8839c28a..def7cdfab985d 100644 --- a/arch/arm64/boot/dts/apple/t6030.dtsi +++ b/arch/arm64/boot/dts/apple/t6030.dtsi @@ -1099,14 +1099,14 @@ }; /* System sleep controller; enabled by qualified boards. */ - t6030_sleep: sleep-controller@350700000 { + t6030_sleep: sleep-controller@3642d4000 { compatible = "apple,t6030-sleep"; - reg = <0x3 0x50700000 0x0 0x18000>, + reg = <0x3 0x642d4000 0x0 0x4>, <0x3 0x50724000 0x0 0x4000>, <0x3 0x50734000 0x0 0x10>, <0x3 0x50768000 0x0 0x40>, <0x3 0x50780000 0x0 0x8>, - <0x3 0x642d4000 0x0 0x4>, + <0x3 0x50700000 0x0 0x18000>, <0x3 0x642b0000 0x0 0x30>, <0x3 0x64004000 0x0 0x48>, <0x3 0x64714000 0x0 0x100>, @@ -1134,14 +1134,15 @@ <0x2 0x22a00000 0x0 0x1000>, <0x2 0x22c00000 0x0 0x1000>, <0x2 0x22e00000 0x0 0x1000>, - <0x3 0x50c08000 0x0 0x4000>; - reg-names = "ps", "pwrgate", "cpu-start", "cllt", "cluster", - "commit", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", + <0x3 0x50c08000 0x0 0x4000>, + <0x3 0x500400c0 0x0 0x10>; + reg-names = "commit", "pwrgate", "cpu-start", "cllt", "cluster", + "ps", "wdt", "wake", "spmi", "ps-aon", "spmi-a0", "clk-mux", "clk-perf", "ps-gpu", "amcc0", "amcc1", "dcs0", "ptd", "cpm-e", "cpm-p", "amcc0-mc", "amcc1-mc", "dcs0-ch1", "dcs0-ch2", "dcs0-ch3", "dcs0-ch4", "dcs0-ch5", "dcs1-ch0", "dcs1-ch1", "dcs1-ch2", "dcs1-ch3", "dcs1-ch4", - "dcs1-ch5", "pmp-mbox"; + "dcs1-ch5", "pmp-mbox", "mca-switch"; apple,display-coprocessors = <&dcp>, <&dcpext>, <&dcpext1>; apple,display-darts = <&dcp_dart>, <&dcpext_dart>, <&dcpext1_dart>; apple,pcie-host = <&pcie0>; @@ -1149,6 +1150,7 @@ apple,pinctrl = <&pinctrl_ap>; apple,sep-dart = <&sep_dart>; apple,mtp-dart = <&mtp_dart>; + apple,i2c6 = <&i2c6>; /* The ADT's pmgr ap-wake-sources */ apple,wake-enable = <3 51 74 83 87 88 89 90 91 92 93 94 104 111 113 132 133 147 159 169 185 190 214>; @@ -1280,8 +1282,8 @@ <0 13 0x100 0x0>, <0 4 0x0 0x0>, <0 4 0x4 0x0>, - <3 0 0x1b8 0x10000000>, - <3 0 0x1d0 0x10000000>, + <3 5 0x1b8 0x10000000>, + <3 5 0x1d0 0x10000000>, <0 11 0x48 0x80100000>, <0 11 0x50 0x80100000>, <0 11 0x4c 0x80100000>, diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 2ee5a9f5b301b..3f83942d6e6de 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -8438,6 +8438,14 @@ void apple_dart_clear_host_resumes(struct device *dev) } EXPORT_SYMBOL_GPL(apple_dart_clear_host_resumes); +bool apple_dart_is_host_resumed(struct device *dev) +{ + struct apple_dart *dart = dev_get_drvdata(dev); + + return dart && dart->host_resumes; +} +EXPORT_SYMBOL_GPL(apple_dart_is_host_resumed); + /* The host's port is up again: ungate the DART and restore what it saved. */ int apple_dart_host_resume(struct device *dev) { diff --git a/drivers/soc/apple/sleep-t6030-pcie-wake.h b/drivers/soc/apple/sleep-t6030-pcie-wake.h index d3bc3226cccac..ae0c83ea72a97 100644 --- a/drivers/soc/apple/sleep-t6030-pcie-wake.h +++ b/drivers/soc/apple/sleep-t6030-pcie-wake.h @@ -2,6 +2,11 @@ /* * Apple T6030 general-purpose PCIe root complex and PHY wake-up sequence. * Register blocks are mapped from the apple,pcie-host DT phandle. + * + * Captured from the macOS 27.2 (26B123) deep-sleep wake sequence on J516s + * (T6030). Kept here because the boot loader's pcie_apcie_tables_fdt() + * currently exports apple,tunable-* properties only for Post-M4 ANS + * controllers, not T6030 general-purpose PCIe. */ enum { diff --git a/drivers/soc/apple/sleep-t6030-quiesce.h b/drivers/soc/apple/sleep-t6030-quiesce.h index e2db6268852c8..97c2c04344365 100644 --- a/drivers/soc/apple/sleep-t6030-quiesce.h +++ b/drivers/soc/apple/sleep-t6030-quiesce.h @@ -2,6 +2,8 @@ /* * Apple T6030 peripheral quiesce register sequences run at display power-down * before firmware sleep entry. Register blocks are mapped from DT phandles. + * Values are captured from the macOS 27.2 (26B123) J516s sleep entry sequence; + * PCIe PERST# pins are resolved from DT reset-gpios rather than hardcoded here. */ enum t6030_qblk { @@ -28,14 +30,16 @@ struct t6030_quiesce_write { u32 delay_us; }; -static const struct t6030_quiesce_write t6030_quiesce_sd[] = { +static const struct t6030_quiesce_write t6030_quiesce_sd_pre[] = { { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00066f, 0 }, { T6030_QBLK_PCIE_INTR1, 0x20, 0x7, 434 }, { T6030_QBLK_PCIE_PORT1, 0x104, 0xff5527f0, 33 }, { T6030_QBLK_PCIE_PORT1, 0x100, 0xf0, 2 }, { T6030_QBLK_PCIE_PORT1, 0x800, 0x100101, 9 }, { T6030_QBLK_PCIE_PORT1, 0x88, 0x11, 2 }, - { T6030_QBLK_PINCTRL, 0x2a0, 0x76a02, 2559 }, +}; + +static const struct t6030_quiesce_write t6030_quiesce_sd_post[] = { { T6030_QBLK_PCIE_PHY1, 0x0, 0xc00066f, 5 }, { T6030_QBLK_PCIE_DART1, 0x104, 0xffffffff, 29 }, { T6030_QBLK_PCIE_DART1, 0x100, 0xe00000, 4 }, @@ -69,7 +73,7 @@ static const struct t6030_quiesce_write t6030_quiesce_sd[] = { { T6030_QBLK_PCIE_PORT1, 0x100, 0x30004200, 8 }, }; -static const struct t6030_quiesce_write t6030_quiesce_wifi[] = { +static const struct t6030_quiesce_write t6030_quiesce_wifi_pre[] = { { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 0 }, { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 30 }, { T6030_QBLK_PCIE_DART0, 0x80, 0x10f, 25 }, @@ -195,7 +199,9 @@ static const struct t6030_quiesce_write t6030_quiesce_wifi[] = { { T6030_QBLK_PCIE_PORT0, 0x100, 0xf0, 5 }, { T6030_QBLK_PCIE_PORT0, 0x800, 0x100101, 23 }, { T6030_QBLK_PCIE_PORT0, 0x88, 0x11, 2 }, - { T6030_QBLK_PINCTRL, 0x29c, 0x76a02, 2438 }, +}; + +static const struct t6030_quiesce_write t6030_quiesce_wifi_post[] = { { T6030_QBLK_PCIE_PHY0, 0x0, 0xc00066f, 37 }, { T6030_QBLK_PCIE_DART0, 0x104, 0xffffffff, 16 }, { T6030_QBLK_PCIE_DART0, 0x100, 0xe00000, 7 }, diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h index d7dacb3347f6e..e078bf27aad07 100644 --- a/drivers/soc/apple/sleep-t6030.h +++ b/drivers/soc/apple/sleep-t6030.h @@ -11,12 +11,12 @@ * Register block indices matching the reg-names order in apple,t6030-sleep.yaml. */ enum t6030_reg_blk { - T6030_BLK_PS = 0, + T6030_BLK_COMMIT = 0, T6030_BLK_PWRGATE = 1, T6030_BLK_CPU_START = 2, T6030_BLK_CLLT = 3, T6030_BLK_CLUSTER = 4, - T6030_BLK_COMMIT = 5, + T6030_BLK_PS = 5, T6030_BLK_WDT = 6, T6030_BLK_WAKE = 7, T6030_BLK_SPMI = 8, @@ -625,11 +625,13 @@ static struct t6030_sleep { int gp_park_ret; void __iomem *ptd_read, *ptd_update, *ptd_ctrl; - void __iomem *pmp_mbox, *mtp_dart, *dart_sep, *i2c6; + void __iomem *pmp_mbox, *mtp_dart, *dart_sep, *i2c6, *mca_switch; void __iomem *cpm[2]; void __iomem *slc_multicast[2]; void __iomem *qblk[T6030_QBLK_COUNT]; + bool first_entry_done; + bool pcie_host_owned; bool mem_configured; bool slc_disabled; u32 atc_saved[T6030_ATC_WORDS]; @@ -995,7 +997,7 @@ static int t6030_pmu_xfer(struct apple_sleep *s, u32 mask, u8 opcode, u16 addres return t6030_spmi_xfer(s->spmi, s->soc->pmu_usid, mask, opcode, address, wr, rd, len); } -/* Read and clear boot PMU stage/status latches at probe */ +/* Read and clear boot PMU stage/status latches on the first deep-sleep entry */ static void t6030_last_pmu_boot(struct apple_sleep *s) { u32 runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); @@ -1061,7 +1063,9 @@ static void t6030_last_alarm_disarm(struct apple_sleep *s) } /* - * CPM, cluster power-gate, and AMCC/DCS memory configuration + * CPM, cluster power-gate, and AMCC/DCS memory configuration. + * Table values are captured from the macOS 27.2 (26B123) J516s (T6030) + * boot and deep-sleep reference traces. */ static const u16 t6030_cpm_table[] = { 0x8a0f, 0x800f, 0x8c0f, 0x9c0f, 0x9e0f, 0x810f, 0xb90f, 0xbe0f, 0xbf0f, 0xd40f, 0x980f, @@ -1155,6 +1159,10 @@ struct t6030_mem_write { u64 val; }; +/* + * AMCC/DCS memory controller sleep-config register writes captured from the + * macOS 27.2 (26B123) J516s (T6030) boot and deep-sleep wake traces. + */ static const struct t6030_mem_write t6030_mem_config[] = { { T6030_BLK_AMCC0, 0x24010, 64, 0x110000100501000ULL }, { T6030_BLK_AMCC0, 0x24018, 64, 0xff000000000ULL }, @@ -1468,13 +1476,23 @@ static void t6030_mem_config_apply(struct apple_sleep *s) t6030.mem_configured = true; } +static void t6030_delay_us(unsigned int us) +{ + while (us) { + unsigned int chunk = min(us, 1000U); + + udelay(chunk); + us -= chunk; + } +} + /* * Peripheral quiesce sequences run at display power-down */ static void t6030_quiesce_run(const struct t6030_quiesce_write *w, unsigned int n, const bool skip_disp[3]) { - unsigned int i, d; + unsigned int i; for (i = 0; i < n; i++) { void __iomem *base = t6030.qblk[w[i].blk]; @@ -1487,13 +1505,25 @@ static void t6030_quiesce_run(const struct t6030_quiesce_write *w, unsigned int w[i].blk <= T6030_QBLK_DISP_DART2 && skip_disp[w[i].blk - T6030_QBLK_DISP_DART0]) continue; - for (d = w[i].delay_us; d; d -= min(d, 1000U)) - udelay(min(d, 1000U)); + t6030_delay_us(w[i].delay_us); writel(w[i].val, base + w[i].off); readl(base + w[i].off); } } +static void t6030_perst_assert(struct apple_sleep *s, unsigned int port, unsigned int delay_us) +{ + void __iomem *pinctrl = t6030.qblk[T6030_QBLK_PINCTRL]; + + if (!pinctrl || port >= T6030_GP_PERST_PORTS || !t6030.perst_valid[port] || + !sleep_ps_on(s, T6030_PS_GPIO)) + return; + t6030_delay_us(delay_us); + /* Keep PERST# asserted (DATA=0, OUTPUT=1) while quiescing the port PHY/DART. */ + writel(0x76a02, pinctrl + 4 * t6030.perst_pin[port]); + readl(pinctrl + 4 * t6030.perst_pin[port]); +} + static void t6030_quiesce_at_display_off(struct apple_sleep *s) { bool pcie_on = sleep_ps_on(s, T6030_PS_APCIE_GP) && @@ -1505,8 +1535,14 @@ static void t6030_quiesce_at_display_off(struct apple_sleep *s) }; if (pcie_on) { - t6030_quiesce_run(t6030_quiesce_sd, ARRAY_SIZE(t6030_quiesce_sd), NULL); - t6030_quiesce_run(t6030_quiesce_wifi, ARRAY_SIZE(t6030_quiesce_wifi), NULL); + t6030_quiesce_run(t6030_quiesce_sd_pre, ARRAY_SIZE(t6030_quiesce_sd_pre), NULL); + t6030_perst_assert(s, 1, 2559); + t6030_quiesce_run(t6030_quiesce_sd_post, ARRAY_SIZE(t6030_quiesce_sd_post), NULL); + t6030_quiesce_run(t6030_quiesce_wifi_pre, ARRAY_SIZE(t6030_quiesce_wifi_pre), + NULL); + t6030_perst_assert(s, 0, 2438); + t6030_quiesce_run(t6030_quiesce_wifi_post, ARRAY_SIZE(t6030_quiesce_wifi_post), + NULL); } t6030_quiesce_run(t6030_quiesce_disp, ARRAY_SIZE(t6030_quiesce_disp), skip_disp); t6030_quiesce_run(t6030_quiesce_pins, ARRAY_SIZE(t6030_quiesce_pins), NULL); @@ -1760,8 +1796,7 @@ static void __iomem *t6030_map_phandle(struct apple_sleep *s, const char *prop, static void t6030_gp_map(struct apple_sleep *s) { struct device_node *host = of_parse_phandle(s->dev->of_node, "apple,pcie-host", 0); - struct device_node *port; - unsigned int idx = 0; + struct device_node *pinctrl_np, *port; if (!host) return; @@ -1780,23 +1815,25 @@ static void t6030_gp_map(struct apple_sleep *s) t6030.qblk[T6030_QBLK_PCIE_PHY0] = t6030_map_node_name(s, host, "phy0"); t6030.qblk[T6030_QBLK_PCIE_PHY1] = t6030_map_node_name(s, host, "phy1"); - struct device_node *pinctrl_np = of_parse_phandle(s->dev->of_node, "apple,pinctrl", 0); + pinctrl_np = of_parse_phandle(s->dev->of_node, "apple,pinctrl", 0); for_each_child_of_node(host, port) { struct of_phandle_args args; + unsigned int slot; + u32 reg0; - if (idx >= T6030_GP_PERST_PORTS) { - of_node_put(port); - break; - } + if (of_property_read_u32_index(port, "reg", 0, ®0)) + continue; + slot = (reg0 >> 11) & 0x1f; + if (slot >= T6030_GP_PERST_PORTS) + continue; if (!of_parse_phandle_with_args(port, "reset-gpios", "#gpio-cells", 0, &args)) { if (pinctrl_np && args.np == pinctrl_np && args.args_count >= 1) { - t6030.perst_pin[idx] = args.args[0]; - t6030.perst_valid[idx] = true; + t6030.perst_pin[slot] = args.args[0]; + t6030.perst_valid[slot] = true; } of_node_put(args.np); } - idx++; } of_node_put(pinctrl_np); @@ -1811,20 +1848,31 @@ static bool t6030_replay_actual(void __iomem *va, u32 actual, unsigned int us) { u32 v; - return !readl_poll_timeout(va, v, FIELD_GET(PS_ACTUAL, v) == actual, 20, us); + return !readl_poll_timeout_atomic(va, v, FIELD_GET(PS_ACTUAL, v) == actual, 20, us); } static void t6030_replay_pulse(struct device *dev, void __iomem *ps, u32 off, - const char *name, unsigned int hold_us) + u32 parent_off, const char *name, unsigned int hold_us) { void __iomem *va = ps + off; + u32 v = readl(va); + u32 pv = readl(ps + parent_off); + + /* + * Skip if a tunnel/driver already has this domain active, or if genpd + * has already gated its parent ATCn_COMMON domain off. + */ + if (FIELD_GET(PS_ACTUAL, v) || FIELD_GET(PS_TARGET, v)) + return; + if (FIELD_GET(PS_ACTUAL, pv) != 0xf) + return; writel(0xf, va); if (!t6030_replay_actual(va, 0xf, 10000)) dev_warn(dev, "T6030 boot replay: %s not on: %#x\n", name, readl(va)); writel(0x1000000f, va); readl(va); - fsleep(hold_us); + t6030_delay_us(hold_us); writel(0x3f0, va); if (!t6030_replay_actual(va, 0, 10000)) dev_warn(dev, "T6030 boot replay: %s not off: %#x\n", name, readl(va)); @@ -1832,18 +1880,12 @@ static void t6030_replay_pulse(struct device *dev, void __iomem *ps, u32 off, static void t6030_boot_replay(struct apple_sleep *s) { - static bool done; - void __iomem *mca; unsigned int i; - if (done) - return; - done = true; - /* DWI boot pulse */ writel(0x340, s->ps + T6030_PS_DWI); readl(s->ps + T6030_PS_DWI); - fsleep(8500); + t6030_delay_us(8500); writel(0xf, s->ps + T6030_PS_DWI); if (!t6030_replay_actual(s->ps + T6030_PS_DWI, 0xf, 10000)) dev_warn(s->dev, "T6030 boot replay: DWI not on: %#x\n", @@ -1852,18 +1894,18 @@ static void t6030_boot_replay(struct apple_sleep *s) readl(s->ps + T6030_PS_DWI); /* MCA audio-clock switches */ - mca = ioremap_np(0x350040000ULL, 0x1000); - if (mca) { + if (t6030.mca_switch) { for (i = 0; i < 4; i++) { - writel(0, mca + 0xc0 + 4 * i); - readl(mca + 0xc0 + 4 * i); + writel(0, t6030.mca_switch + 4 * i); + readl(t6030.mca_switch + 4 * i); } - iounmap(mca); } /* ATC2_PCIE, then ATC1_PCIE */ - t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, "ATC2_PCIE", 15200); - t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, "ATC1_PCIE", 8400); + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, + T6030_PS_ATC0_COMMON + 2 * 8, "ATC2_PCIE", 15200); + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, + T6030_PS_ATC0_COMMON + 1 * 8, "ATC1_PCIE", 8400); } static void t6030_ps_auto_set(void __iomem *reg) @@ -1912,7 +1954,7 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) { "clk-mux", offsetof(struct apple_sleep, clk_mux) }, { "clk-perf", offsetof(struct apple_sleep, clk_perf) }, }; - struct device_node *np = s->dev->of_node, *i2c_np; + struct device_node *np = s->dev->of_node; u32 v[6]; unsigned int i; int ret; @@ -1970,13 +2012,10 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) t6030_gp_map(s); t6030.pmp_mbox = t6030_map_node_name(s, np, "pmp-mbox"); + t6030.mca_switch = t6030_map_node_name(s, np, "mca-switch"); t6030.dart_sep = t6030_map_phandle(s, "apple,sep-dart", 0); t6030.mtp_dart = t6030_map_phandle(s, "apple,mtp-dart", 0); - i2c_np = of_find_node_by_path("/soc/i2c@289028000"); - if (i2c_np) { - t6030.i2c6 = t6030_map_node_reg(s, i2c_np, 0); - of_node_put(i2c_np); - } + t6030.i2c6 = t6030_map_phandle(s, "apple,i2c6", 0); t6030.qblk[T6030_QBLK_PINCTRL] = t6030_map_phandle(s, "apple,pinctrl", 0); t6030.qblk[T6030_QBLK_PWRGATE] = s->pwrgate; static_assert(T6030_QBLK_DISP_DART1 - T6030_QBLK_DISP_DART0 == 1); @@ -1995,14 +2034,92 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) t6030_dc_reblock(hid4); } + return apple_sleep_read_wake_sources(s); +} + +static void t6030_first_deep_init(struct apple_sleep *s) +{ + if (t6030.first_entry_done) + return; + t6030.first_entry_done = true; + t6030_boot_replay(s); t6030_pwrgate_init(s); t6030_cpm_init(); t6030_boot_auto_probe(s); t6030_mem_config_apply(s); t6030_last_pmu_boot(s); +} - return apple_sleep_read_wake_sources(s); +/* + * Deep sleep resets the GP PCIe complex and its DARTs. Refuse deep sleep + * unless pcie-apple is bound and has claimed host-resumed ownership of every + * available GP PCIe DART (otherwise apple-dart noirq resume touches unclocked + * DART MMIO and triggers an SError). + */ +static bool t6030_pcie_darts_host_owned(struct apple_sleep *s) +{ + struct device_node *np = s->dev->of_node; + struct device_node *host_np, *dart_np; + struct platform_device *pdev; + bool bound; + int i; + + host_np = of_parse_phandle(np, "apple,pcie-host", 0); + if (host_np) { + if (of_device_is_available(host_np)) { + pdev = of_find_device_by_node(host_np); + if (!pdev) { + of_node_put(host_np); + dev_err(s->dev, + "T6030 sleep: refusing deep sleep without PCIe host device\n"); + return false; + } + device_lock(&pdev->dev); + bound = pdev->dev.driver != NULL; + device_unlock(&pdev->dev); + put_device(&pdev->dev); + if (!bound) { + of_node_put(host_np); + dev_err(s->dev, + "T6030 sleep: refusing deep sleep without PCIe host driver bound\n"); + return false; + } + } + of_node_put(host_np); + } + + for (i = 0; (dart_np = of_parse_phandle(np, "apple,pcie-darts", i)); i++) { + bool resumed = false; + + if (!of_device_is_available(dart_np)) { + of_node_put(dart_np); + continue; + } + pdev = of_find_device_by_node(dart_np); + if (pdev) { + resumed = apple_dart_is_host_resumed(&pdev->dev); + put_device(&pdev->dev); + } + if (!resumed) { + dev_err(s->dev, + "T6030 sleep: refusing deep sleep while %pOF is not host-resumed\n", + dart_np); + of_node_put(dart_np); + return false; + } + of_node_put(dart_np); + } + + return true; +} + +static int t6030_sleep_begin(struct apple_sleep *s) +{ + t6030.pcie_host_owned = t6030_pcie_darts_host_owned(s); + if (!t6030.pcie_host_owned) + return -EBUSY; + return 0; } /* @@ -2027,6 +2144,10 @@ static int t6030_sleep_final_check(struct apple_sleep *s) { int ret; + if (!t6030.pcie_host_owned) { + dev_dbg(s->dev, "final check: PCIe DARTs not host-resumed\n"); + return -EBUSY; + } if (!s->smc.held || !s->smc.saved_ops || !s->smc.saved_ops->check) { dev_dbg(s->dev, "final check: SMC scope held %d\n", s->smc.held); return -EBUSY; @@ -2041,8 +2162,25 @@ static int t6030_sleep_final_check(struct apple_sleep *s) static int t6030_sleep_display_off(struct apple_sleep *s) { + bool first = !t6030.first_entry_done; + u32 dwi_before = first ? readl(s->ps + T6030_PS_DWI) : 0; + + t6030_first_deep_init(s); s->regs_staged = true; t6030_ps_at_display_off(s); + if (first) { + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { + const struct t6030_ps_entry *e = + &t6030_ps_entries[t6030_ps_on_order[i]]; + + if (!e->aon && e->off == T6030_PS_DWI) { + t6030.ps_on_saved[i] = dwi_before; + break; + } + } + } return 0; } @@ -2140,6 +2278,7 @@ static void t6030_sleep_undo_regs(struct apple_sleep *s) t6030.dart_sep_staged = false; } t6030_ps_undo_display_off(s); + t6030.pcie_host_owned = false; } static void t6030_sleep_after_ans(struct apple_sleep *s) @@ -2527,6 +2666,10 @@ static const struct t6030_wake_write t6030_wake_lowered[] = { { T6030_AON(0xc0), 0x3f0 }, { T6030_AON(0xb8), 0x3f0 }, }; +/* + * GPU PMGR wake restore writes captured from the macOS 27.2 (26B123) J516s + * (T6030) deep-sleep wake trace. + */ static const struct t6030_wake_write t6030_wake_gpu[] = { { 0x10834, 0x0 }, { 0x10820, 0x4 }, { 0x10874, 0x1 }, { 0x10860, 0x4 }, { 0x10854, 0x1 }, { 0x10840, 0x4 }, { 0x10110, 0x0 }, { 0x10114, 0x0 }, @@ -2688,6 +2831,10 @@ static void t6030_gp_rw(void __iomem *base, u32 off, u32 val) writel(val, base + off); } +/* + * GP PCIe AXI2AF / CIO3PLL / CLKGEN wake restore sequence captured from the + * macOS 27.2 (26B123) J516s (T6030) deep-sleep wake trace. + */ static void t6030_gp_clocks_wake(void) { void __iomem *a = t6030.gp_axi2af; @@ -2777,8 +2924,10 @@ static void t6030_apcie_wake(struct apple_sleep *s) t6030_apcie_ps_step(s, T6030_PS_APCIE_SYS_ST, 0xf00000f, 0x1f00000f, 0xf); t6030_apcie_ps_step(s, T6030_PS_APCIE_PHY_SW, 0xf000340, 0, 0); /* - * Hold PHY_SW low for 10.7 ms, then drive PERST# low (0x76802) and - * release it high (0x76a02) on each GP PCIe port. + * Hold PHY_SW low for 10.7 ms, then re-program the GP PCIe PERST# + * pins while keeping PERST# asserted low (DATA=0, OUTPUT=1; bit 9 + * matches the macOS 27.2 wake trace) until pcie-apple deasserts + * reset-gpios during host resume. */ mdelay(10); udelay(700); @@ -3024,6 +3173,7 @@ static void t6030_sleep_wake(struct apple_sleep *s) } t6030.ptd_sleep_ctrl_staged = false; t6030.dart_sep_staged = false; + t6030.pcie_host_owned = false; apple_sleep_set_wd2(s, WDT_SUSPEND_SECS); t6030_sleep_wake_check_ps(s, "at the end"); @@ -3152,6 +3302,7 @@ static const struct apple_sleep_ops t6030_sleep_ops = { .aic_ack = aic_sleep_ack, .aic_restore = aic_sleep_restore, .map_regs = t6030_sleep_map_regs, + .begin = t6030_sleep_begin, .display_off = t6030_sleep_display_off, .before_enclave = t6030_sleep_before_enclave, .final_check = t6030_sleep_final_check, diff --git a/drivers/soc/apple/sleep-test.c b/drivers/soc/apple/sleep-test.c index 150ddbc88e5f2..c260bce566ba9 100644 --- a/drivers/soc/apple/sleep-test.c +++ b/drivers/soc/apple/sleep-test.c @@ -232,8 +232,8 @@ static void apple_sleep_test_layout(struct kunit *test) KUNIT_EXPECT_GT(test, soc->cpu_start_stride, 0); KUNIT_EXPECT_LE(test, soc->nclk_mux_parked, SLEEP_CLK_MUX_MAX); KUNIT_EXPECT_LE(test, soc->ncllt, SLEEP_CLLT_MAX); - /* Providers without own_wake step their memory controller via the shared MCC list. */ - if (!soc->own_wake) + /* T6030 steps its memory controller via DT sequences rather than the shared MCC list. */ + if (soc->ops != &t6030_sleep_ops) KUNIT_EXPECT_GE(test, soc->nmcc, 1); KUNIT_EXPECT_LE(test, soc->nmcc, MCC_CHANNELS); KUNIT_EXPECT_LE(test, soc->namcc, SLEEP_AMCC_MAX); diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index e19ab1148c4da..cfe6751fc08a7 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -3294,7 +3294,7 @@ bool apple_sleep_domain_kept(struct device_node *pd) struct apple_sleep *s = apple_sleep; int off; - if (!s || !s->soc->ops->domain_kept) + if (!s || !s->soc->ops->domain_kept || !pm_suspend_via_firmware()) return false; off = sleep_ps_offset(s, pd); if (off < 0) diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index 40cf126117f0e..46d6f70c763f2 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -77,7 +77,6 @@ struct apple_spmi_hw { u32 num_irqs; u32 irq_mask; u32 irq_ack; - bool keep_pending; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -91,19 +90,6 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; -/* M3 Pro (T6030): preserve masked pending sources owned by firmware sleep */ -static const struct apple_spmi_hw apple_spmi_t6030 = { - .status = SPMI_STATUS_REG, - .command = SPMI_CMD_REG, - .reply = SPMI_RSP_REG, - .rx_empty = SPMI_RX_FIFO_EMPTY, - .legacy_irqs = true, - .num_irqs = 256, - .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, - .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, - .keep_pending = true, -}; - /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ static const struct apple_spmi_hw apple_spmi_t6000 = { .status = SPMI_STATUS_REG, @@ -141,6 +127,7 @@ struct apple_spmi { /* The sources a driver uses, enabled or not. */ DECLARE_BITMAP(irq_used, SPMI_MAX_PERIPHERAL_IRQS); int irq; + bool keep_pending; bool notify_irq; bool notify_parked; bool prev_fail; @@ -547,7 +534,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ val &= ~BIT(notify % 32); - if (val && spmi->hw->keep_pending) { + if (val && spmi->keep_pending) { u32 enabled = readl(spmi->regs + spmi->hw->irq_mask + (notify / 32) * 4); /* The sleep driver can enable controller sources outside this driver. */ @@ -572,7 +559,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * pending for its unmask: it isn't a bad interrupt either. */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; - if (stray && spmi->hw->keep_pending) { + if (stray && spmi->keep_pending) { void __iomem *mask = spmi->regs + spmi->hw->irq_mask + offset; u64 enabled = readl(mask); @@ -607,18 +594,24 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) */ if (handled) { spmi->held_spurious = 0; - } else if (held && spmi->hw->keep_pending) { + } else if (held && spmi->keep_pending) { /* * Masked pending bits should not re-assert the parent IRQ; if they - * ever do, bound retries and ack stuck masked bits to prevent a storm. + * ever do, bound retries and ack stuck unowned masked bits without + * dropping driver-requested interrupts or the RX notify vector. */ if (++spmi->held_spurious >= 8) { + u32 used_words[SPMI_MAX_PERIPHERAL_IRQS / 32]; + dev_warn_once(spmi->dev, - "stuck masked pending SPMI interrupt; acknowledging\n"); + "stuck masked pending SPMI interrupt; acknowledging unowned bits\n"); + bitmap_to_arr32(used_words, spmi->irq_used, notify); for (offset = 0; offset <= (notify / 32) * 4; offset += 4) { u32 pend = readl(spmi->regs + spmi->hw->irq_ack + offset); u32 mask = readl(spmi->regs + spmi->hw->irq_mask + offset); - u32 stuck = pend & ~mask; + u32 owned = (offset < (notify / 32) * 4) ? + used_words[offset / 4] : BIT(notify % 32); + u32 stuck = pend & ~mask & ~owned; if (stuck) writel(stuck, spmi->regs + spmi->hw->irq_ack + offset); @@ -666,10 +659,10 @@ static int apple_spmi_init_irq(struct platform_device *pdev, for (size_t offset = 0; offset < spmi->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); offset += 4) { writel(0, spmi->regs + spmi->hw->irq_mask + offset); - if (!spmi->hw->keep_pending) + if (!spmi->keep_pending) writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } - if (spmi->hw->keep_pending) + if (spmi->keep_pending) apple_spmi_irq_ack_raw(spmi, spmi->num_irqs); spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); @@ -787,6 +780,8 @@ static int apple_spmi_probe(struct platform_device *pdev) spmi->hw = device_get_match_data(&pdev->dev); if (!spmi->hw) return -EINVAL; + spmi->keep_pending = of_property_read_bool(pdev->dev.of_node, + "apple,keep-pending-irqs"); spmi->num_irqs = spmi->hw->num_irqs; if (spmi->hw->legacy_irqs) { u32 response_vector; @@ -851,7 +846,6 @@ static int apple_spmi_probe(struct platform_device *pdev) static const struct of_device_id apple_spmi_match_table[] = { { .compatible = "apple,t8142-spmi", .data = &apple_spmi_gen4 }, - { .compatible = "apple,t6030-spmi", .data = &apple_spmi_t6030 }, { .compatible = "apple,t8103-spmi", .data = &apple_spmi_gen1 }, { .compatible = "apple,t6000-spmi", .data = &apple_spmi_t6000 }, { .compatible = "apple,spmi", .data = &apple_spmi_gen1 }, diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 794bc12d98f45..dbf59afd6d6d8 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -180,6 +180,7 @@ int apple_dart_fw_remote(struct device *dev, dma_addr_t iova, bool write, phys_a */ int apple_dart_set_host_resumes(struct device *dev); void apple_dart_clear_host_resumes(struct device *dev); +bool apple_dart_is_host_resumed(struct device *dev); int apple_dart_host_resume(struct device *dev); /* The same after a sleep entry that stopped its streams: always the whole reset and restore. */ int apple_dart_host_restart(struct device *dev); @@ -196,6 +197,7 @@ static inline int apple_dart_fw_remote(struct device *dev, dma_addr_t iova, bool } static inline int apple_dart_set_host_resumes(struct device *dev) { return -EOPNOTSUPP; } static inline void apple_dart_clear_host_resumes(struct device *dev) {} +static inline bool apple_dart_is_host_resumed(struct device *dev) { return false; } static inline int apple_dart_host_resume(struct device *dev) { return -EOPNOTSUPP; } static inline int apple_dart_host_restart(struct device *dev) { return -EOPNOTSUPP; } #endif diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index dc3ae3f00de62..b4c3dd8c2bd1c 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -114,6 +114,8 @@ def main(): struct apple_sleep { const struct sleep_soc *soc; }; static struct apple_sleep *apple_sleep; static int sleep_offset; +static bool suspend_via_firmware = true; +static bool pm_suspend_via_firmware(void) { return suspend_via_firmware; } static int sleep_ps_offset(struct apple_sleep *s, struct device_node *pd) { (void)s; (void)pd; return sleep_offset; } static struct device_node *of_parse_phandle(struct device_node *n, const char *p, int i) @@ -267,14 +269,17 @@ def main(): assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==2); soc.ops=&hook; assert(apple_pmgr_ps_power_off(&ps->genpd)==-EBUSY && map.writes==2); - sleep_offset=-ENODEV; + suspend_via_firmware=false; assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==3); - sleep_offset=0x430; + suspend_via_firmware=true; + sleep_offset=-ENODEV; assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==4); - sleep_offset=0x428; ps->system_sleep=false; + sleep_offset=0x430; assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==5); + sleep_offset=0x428; ps->system_sleep=false; + assert(!apple_pmgr_ps_power_off(&ps->genpd) && map.writes==6); apple_sleep=NULL; - puts("ok 4 - a domain the sleep provider keeps stays on through a system sleep only"); + puts("ok 4 - a domain the sleep provider keeps stays on through firmware sleep only"); const char *conflicts[]={"apple,firmware-owned","apple,sleep-retained","apple,always-on","apple,min-state", "apple,force-disable","apple,force-reset","apple,externally-clocked","apple,auto-managed", "apple,auto-pm"}; @@ -311,6 +316,8 @@ def main(): "ps->firmware_owned || ps->inherited_on", "ps->firmware_owned", 1), "kept-domain-gated": program.replace( " ||\n\t apple_sleep_domain_kept(ps->dev->of_node)", "", 1), + "s2idle-keeps-domain": program.replace( + " || !pm_suspend_via_firmware()", "", 1), } for name, negative in controls.items(): assert negative != program From 51a51d39045318b94e1a0b4f2f0767b1e3c81a00 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 04:09:27 -0500 Subject: [PATCH 15/19] arm64: dts: apple: t6030: match ADT gpio0 skip pins and J516s SMC wake reasons Update the T6030 sleep and J516s SMC properties to match the J516s ADT: - Add apple,pinctrl-skip-pins = <5 6 17> (from ADT gpio0 no-restore-gpio-pins) to t6030_sleep and document the property in apple,t6030-sleep.yaml so sleep_pins_save/restore leaves those pins untouched. - Update J516s &smc apple,wake-reasons and apple,wake-reason-names to match the J516s ADT smc-pmu event_name-bitN table (codec at bit 10, trackpadkeyboard at bit 12 instead of 35). Signed-off-by: DjDeveloperr --- .../devicetree/bindings/soc/apple/apple,t6030-sleep.yaml | 8 ++++++++ arch/arm64/boot/dts/apple/t6030-j516s.dts | 9 +++++---- arch/arm64/boot/dts/apple/t6030.dtsi | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml index 1750f6efd0348..6b3883b054216 100644 --- a/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6030-sleep.yaml @@ -89,6 +89,14 @@ properties: $ref: /schemas/types.yaml#/definitions/phandle description: AP pin controller whose state is lost in firmware sleep. + apple,pinctrl-skip-pins: + oneOf: + - $ref: /schemas/types.yaml#/definitions/uint32-array + - type: boolean + description: | + AP pins neither saved nor restored across sleep (from ADT gpio0 + no-restore-gpio-pins). Empty where every pin is saved. + apple,sep-dart: $ref: /schemas/types.yaml#/definitions/phandle description: SEP IOMMU quiesced before requesting SEP sleep. diff --git a/arch/arm64/boot/dts/apple/t6030-j516s.dts b/arch/arm64/boot/dts/apple/t6030-j516s.dts index dea6cdd02485d..71ea2d1a8ae82 100644 --- a/arch/arm64/boot/dts/apple/t6030-j516s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j516s.dts @@ -207,10 +207,11 @@ &smc { apple,sleep-wake-type; - apple,wake-reasons = <0 8 9 11 13 35 40 41 42 43 44 45 48>; - apple,wake-reason-names = "pwrbtn", "lid", "sdconn", "charger", "wifibt", - "trackpadkeyboard", "acattach", "acdetach", "USB-C_plug", - "USB2_plug", "USB2_wake", "aupo", "rtc"; + /* The SMC PMU's event names (J516s ADT, smc-pmu event_name-bitN) */ + apple,wake-reasons = <0 8 9 10 11 12 13 40 41 42 43 44 45 48>; + apple,wake-reason-names = "pwrbtn", "lid", "sdconn", "codec", "charger", + "trackpadkeyboard", "wifibt", "acattach", "acdetach", + "USB-C_plug", "USB2_plug", "USB2_wake", "aupo", "rtc"; apple,dark-wake-reasons = "USB-C_plug", "wifibt"; }; diff --git a/arch/arm64/boot/dts/apple/t6030.dtsi b/arch/arm64/boot/dts/apple/t6030.dtsi index def7cdfab985d..6c3a62ac525c7 100644 --- a/arch/arm64/boot/dts/apple/t6030.dtsi +++ b/arch/arm64/boot/dts/apple/t6030.dtsi @@ -1148,6 +1148,8 @@ apple,pcie-host = <&pcie0>; apple,pcie-darts = <&pcie0_dart_0>, <&pcie0_dart_1>; apple,pinctrl = <&pinctrl_ap>; + /* From the T6030 ADT gpio0 no-restore-gpio-pins */ + apple,pinctrl-skip-pins = <5 6 17>; apple,sep-dart = <&sep_dart>; apple,mtp-dart = <&mtp_dart>; apple,i2c6 = <&i2c6>; From 64ba2fb531861d73cd6cf50d8975093366b8c5b2 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 04:31:47 -0500 Subject: [PATCH 16/19] soc: apple: sleep: t6030: run first-entry init in sleep_begin Move t6030_first_deep_init() from t6030_sleep_display_off() (noirq, after secondary CPUs are parked and genpd has gated runtime domains off) to t6030_sleep_begin() (process context, after the PCIe DART host-resumed gate succeeds and before device suspend or CPU offlining). Running boot replay, cluster pwrgate/CPM setup, and boot-auto PS setup in t6030_sleep_begin() preserves zero hardware writes at probe and on s2idle, while ensuring all CPUs are online and active domains are on when t6030_boot_auto_probe() and t6030_boot_replay() run. It also removes the DWI save override in t6030_sleep_display_off() that undid the one-time DWI boot pulse on a refused first entry while leaving first_entry_done set. Signed-off-by: Diljit Singh --- drivers/soc/apple/sleep-t6030.h | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h index e078bf27aad07..3ceef5b921a3b 100644 --- a/drivers/soc/apple/sleep-t6030.h +++ b/drivers/soc/apple/sleep-t6030.h @@ -2119,6 +2119,7 @@ static int t6030_sleep_begin(struct apple_sleep *s) t6030.pcie_host_owned = t6030_pcie_darts_host_owned(s); if (!t6030.pcie_host_owned) return -EBUSY; + t6030_first_deep_init(s); return 0; } @@ -2162,25 +2163,8 @@ static int t6030_sleep_final_check(struct apple_sleep *s) static int t6030_sleep_display_off(struct apple_sleep *s) { - bool first = !t6030.first_entry_done; - u32 dwi_before = first ? readl(s->ps + T6030_PS_DWI) : 0; - - t6030_first_deep_init(s); s->regs_staged = true; t6030_ps_at_display_off(s); - if (first) { - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(t6030_ps_on_order); i++) { - const struct t6030_ps_entry *e = - &t6030_ps_entries[t6030_ps_on_order[i]]; - - if (!e->aon && e->off == T6030_PS_DWI) { - t6030.ps_on_saved[i] = dwi_before; - break; - } - } - } return 0; } From 4d76e17159c584e61cac5b5129b56495c87a70ec Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 05:41:14 -0500 Subject: [PATCH 17/19] soc: apple: sleep: t6030: restore J516s S2R DT invariants and probe-time boot init Fix three regressions introduced in 8671481c11e1 ("soc: apple: sleep: t6030: address review feedback on sleep provider and DT") that caused committed deep sleep on J516s to cold-reset after ~73 s via the Chapel watchdog: 1. Restore &ps_spi2, &ps_i2c6 (apple,always-on; apple,no-auto-pm), &spi2, and &mesa (CS delays, enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>, firmware-name = "apple/mesacal-j516s.bin") in t6030-j516s.dts. Without them, apple_sep enables spi2/mesa at boot and apple-mesa fails with -ENODEV (leaving nub-gpio 33 unconfigured), while ps_spi2 and ps_i2c6 are gated off instead of held on before sleep entry where sleep-t6030.h lowers T6030_PS_SPI2 and saves/writes T6030_PS_I2C6. 2. Add apple,keep-pending-irqs to &nub_spmi_a1 in t6030-j516s.dts. t6030.dtsi defines three apple,t6030-spmi buses (nub_spmi, nub_spmi_a0, and nub_spmi_a1 hosting hpm2); 8671481c11e1 only tagged nub_spmi and nub_spmi_a0, leaving nub_spmi_a1 to clear pending IRQs with U32_MAX at probe. 3. Move the one-time T6030 boot-state setup (t6030_boot_replay, t6030_pwrgate_init, t6030_cpm_init, t6030_boot_auto_probe, t6030_mem_config_apply, t6030_last_pmu_boot) back to t6030_sleep_map_regs() after DT validation succeeds, and remove the deferred skip guards in t6030_replay_pulse(). Running these in t6030_sleep_begin() after late_initcall_sync/driver probe skipped both ATC1_PCIE (active on CIO) and ATC2_PCIE (ATC2_COMMON already gated off by genpd_power_off_unused), missed runtime-suspended domains in t6030_boot_auto_probe(), and issued unlocked raw SPMI PMU latch clears right after rtcwake programmed the wake alarm. Signed-off-by: DjDeveloperr --- arch/arm64/boot/dts/apple/t6030-j516s.dts | 27 ++++++++++++++ drivers/soc/apple/sleep-t6030.h | 44 +++++++---------------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/arch/arm64/boot/dts/apple/t6030-j516s.dts b/arch/arm64/boot/dts/apple/t6030-j516s.dts index 71ea2d1a8ae82..c8e821e1fc585 100644 --- a/arch/arm64/boot/dts/apple/t6030-j516s.dts +++ b/arch/arm64/boot/dts/apple/t6030-j516s.dts @@ -219,6 +219,24 @@ apple,output-templates = <19 0x00800000>; }; +&ps_spi2 { + apple,always-on; + apple,no-auto-pm; +}; + +&spi2 { + status = "okay"; +}; + +&mesa { + spi-cs-setup-delay-ns = <20>; + spi-cs-hold-delay-ns = <20>; + enable-gpios = <&pinctrl_nub 33 GPIO_ACTIVE_HIGH>; + /* Per-device factory data from this Mac's own iBoot system container. */ + firmware-name = "apple/mesacal-j516s.bin"; + status = "okay"; +}; + &nub_spmi { apple,keep-pending-irqs; }; @@ -227,10 +245,19 @@ apple,keep-pending-irqs; }; +&nub_spmi_a1 { + apple,keep-pending-irqs; +}; + &ps_atc0_usb { apple,sleep-retained; }; +&ps_i2c6 { + apple,always-on; + apple,no-auto-pm; +}; + &mtp_hid { actuator { apple,sleep-report = /bits/ 8 <0x21 0x00>; diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h index 3ceef5b921a3b..6e7e4cb2ce79e 100644 --- a/drivers/soc/apple/sleep-t6030.h +++ b/drivers/soc/apple/sleep-t6030.h @@ -630,7 +630,6 @@ static struct t6030_sleep { void __iomem *slc_multicast[2]; void __iomem *qblk[T6030_QBLK_COUNT]; - bool first_entry_done; bool pcie_host_owned; bool mem_configured; bool slc_disabled; @@ -997,7 +996,7 @@ static int t6030_pmu_xfer(struct apple_sleep *s, u32 mask, u8 opcode, u16 addres return t6030_spmi_xfer(s->spmi, s->soc->pmu_usid, mask, opcode, address, wr, rd, len); } -/* Read and clear boot PMU stage/status latches on the first deep-sleep entry */ +/* Read and clear boot PMU stage/status latches at probe */ static void t6030_last_pmu_boot(struct apple_sleep *s) { u32 runtime = readl(s->spmi + SPMI_NOTIFY_ENABLE); @@ -1746,7 +1745,7 @@ static void t6030_slc_on(struct apple_sleep *s) } /* - * DT resource mapping (probe performs no hardware writes) + * DT resource mapping and one-time boot hardware setup */ static u32 t6030_block(struct apple_sleep *s, u32 b) { @@ -1848,31 +1847,20 @@ static bool t6030_replay_actual(void __iomem *va, u32 actual, unsigned int us) { u32 v; - return !readl_poll_timeout_atomic(va, v, FIELD_GET(PS_ACTUAL, v) == actual, 20, us); + return !readl_poll_timeout(va, v, FIELD_GET(PS_ACTUAL, v) == actual, 20, us); } static void t6030_replay_pulse(struct device *dev, void __iomem *ps, u32 off, - u32 parent_off, const char *name, unsigned int hold_us) + const char *name, unsigned int hold_us) { void __iomem *va = ps + off; - u32 v = readl(va); - u32 pv = readl(ps + parent_off); - - /* - * Skip if a tunnel/driver already has this domain active, or if genpd - * has already gated its parent ATCn_COMMON domain off. - */ - if (FIELD_GET(PS_ACTUAL, v) || FIELD_GET(PS_TARGET, v)) - return; - if (FIELD_GET(PS_ACTUAL, pv) != 0xf) - return; writel(0xf, va); if (!t6030_replay_actual(va, 0xf, 10000)) dev_warn(dev, "T6030 boot replay: %s not on: %#x\n", name, readl(va)); writel(0x1000000f, va); readl(va); - t6030_delay_us(hold_us); + fsleep(hold_us); writel(0x3f0, va); if (!t6030_replay_actual(va, 0, 10000)) dev_warn(dev, "T6030 boot replay: %s not off: %#x\n", name, readl(va)); @@ -1885,7 +1873,7 @@ static void t6030_boot_replay(struct apple_sleep *s) /* DWI boot pulse */ writel(0x340, s->ps + T6030_PS_DWI); readl(s->ps + T6030_PS_DWI); - t6030_delay_us(8500); + fsleep(8500); writel(0xf, s->ps + T6030_PS_DWI); if (!t6030_replay_actual(s->ps + T6030_PS_DWI, 0xf, 10000)) dev_warn(s->dev, "T6030 boot replay: DWI not on: %#x\n", @@ -1902,10 +1890,8 @@ static void t6030_boot_replay(struct apple_sleep *s) } /* ATC2_PCIE, then ATC1_PCIE */ - t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, - T6030_PS_ATC0_COMMON + 2 * 8, "ATC2_PCIE", 15200); - t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, - T6030_PS_ATC0_COMMON + 1 * 8, "ATC1_PCIE", 8400); + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, "ATC2_PCIE", 15200); + t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, "ATC1_PCIE", 8400); } static void t6030_ps_auto_set(void __iomem *reg) @@ -2034,14 +2020,9 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) t6030_dc_reblock(hid4); } - return apple_sleep_read_wake_sources(s); -} - -static void t6030_first_deep_init(struct apple_sleep *s) -{ - if (t6030.first_entry_done) - return; - t6030.first_entry_done = true; + ret = apple_sleep_read_wake_sources(s); + if (ret) + return ret; t6030_boot_replay(s); t6030_pwrgate_init(s); @@ -2049,6 +2030,8 @@ static void t6030_first_deep_init(struct apple_sleep *s) t6030_boot_auto_probe(s); t6030_mem_config_apply(s); t6030_last_pmu_boot(s); + + return 0; } /* @@ -2119,7 +2102,6 @@ static int t6030_sleep_begin(struct apple_sleep *s) t6030.pcie_host_owned = t6030_pcie_darts_host_owned(s); if (!t6030.pcie_host_owned) return -EBUSY; - t6030_first_deep_init(s); return 0; } From f66d67e3a24254f87c84104442be6558507725b2 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 06:15:26 -0500 Subject: [PATCH 18/19] soc: apple: sleep: t6030: gate probe on OS firmware 27.2 t6030_sleep_map_regs() runs one-time AMCC/DCS, CPM, SoC perf, and PMGR setup measured on OS firmware 27.2 (26B123). Since T6030 also supports 14.x firmware, return -ENODEV before mapping or writing any registers unless /chosen/asahi,os-fw-version is exact "27.2", leaving s2idle available on other firmwares. Log the SoC perf word before and after t6030_mem_perf() during the 27.2 probe, and document that probe-time ATC1/2 PCIe replay relies on drivers/Makefile link order (drivers/soc/ before pmdomain/, spmi/, and loadable thunderbolt_apple). Signed-off-by: DjDeveloperr --- drivers/soc/apple/sleep-t6030.h | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/soc/apple/sleep-t6030.h b/drivers/soc/apple/sleep-t6030.h index 6e7e4cb2ce79e..3e0ce1d3d2bc7 100644 --- a/drivers/soc/apple/sleep-t6030.h +++ b/drivers/soc/apple/sleep-t6030.h @@ -1465,13 +1465,18 @@ static void t6030_mem_perf(struct apple_sleep *s) static void t6030_mem_config_apply(struct apple_sleep *s) { + u32 perf_before, perf_after; unsigned int i; for (i = 0; i < ARRAY_SIZE(t6030_mem_config); i++) if (!t6030.blk[t6030_mem_config[i].blk]) return; t6030_mem_config_run(0, ARRAY_SIZE(t6030_mem_config)); + perf_before = readl(s->clk_perf + CLK_PERF_SOC); t6030_mem_perf(s); + perf_after = readl(s->clk_perf + CLK_PERF_SOC); + dev_info(s->dev, "T6030: OS firmware 27.2 SoC perf %#x -> %#x\n", + perf_before, perf_after); t6030.mem_configured = true; } @@ -1889,7 +1894,12 @@ static void t6030_boot_replay(struct apple_sleep *s) } } - /* ATC2_PCIE, then ATC1_PCIE */ + /* + * ATC2_PCIE, then ATC1_PCIE. Built-in apple-sleep relies on drivers/Makefile + * link order (drivers/soc/ before drivers/pmdomain/, drivers/spmi/, and + * loadable thunderbolt_apple) so no power domain, ATC PHY, or USB4 tunnel + * is active yet, except a tunnel left up by a kexec'd kernel. + */ t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC2_PCIE, "ATC2_PCIE", 15200); t6030_replay_pulse(s->dev, s->ps, T6030_PS_ATC1_PCIE, "ATC1_PCIE", 8400); } @@ -1920,6 +1930,18 @@ static void t6030_boot_auto_probe(struct apple_sleep *s) } } +/* The boot writes and the sleep tables were measured on this OS firmware only. */ +static bool t6030_firmware_ok(struct apple_sleep *s) +{ + const char *fw = NULL; + + if (!of_property_read_string(of_chosen, "asahi,os-fw-version", &fw) && + !strcmp(fw, "27.2")) + return true; + dev_info(s->dev, "OS firmware %s is not 27.2: no deep sleep\n", fw ?: "unknown"); + return false; +} + static int t6030_sleep_map_regs(struct apple_sleep *s) { static const struct { @@ -1945,6 +1967,9 @@ static int t6030_sleep_map_regs(struct apple_sleep *s) unsigned int i; int ret; + if (!t6030_firmware_ok(s)) + return -ENODEV; + memset(&t6030, 0, sizeof(t6030)); for (i = 0; i < ARRAY_SIZE(regs); i++) { void __iomem **field = (void __iomem **)((u8 *)s + regs[i].offset); From 731c7e36276370bdbf4bb6fbf400ac9ee37a6351 Mon Sep 17 00:00:00 2001 From: DjDeveloperr Date: Thu, 3 Dec 2026 08:52:05 -0500 Subject: [PATCH 19/19] soc: apple: sleep: don't count T6030's ANS tables as missing apple_sleep_undescribed() came to main while the T6030 provider was in review. It makes s2idle the default when a SoC with no regions has an ANS and no PCIe tables for it, as every deep sleep would be refused there. T6030 has no such tables and apple_sleep_refuse() asks for them only when ANS is off (gp_host_apart), so its deep sleep would go through and still not be the default. Ask for the tables with the same condition. Other SoCs don't set gp_host_apart. Signed-off-by: DjDeveloperr --- drivers/soc/apple/sleep.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index 530a4ff8bc592..e7c0c6f08ffa1 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -8520,8 +8520,12 @@ static unsigned int apple_sleep_undescribed(struct apple_sleep *s) missing++; } - /* Only the region-based SoCs bring ANS's PCIe block back without them. */ - if (!s->soc->regions && s->soc->ps.ans && !s->apcie_phy_tunable) { + /* + * Only the region-based SoCs bring ANS's PCIe block back without them. One with its GP + * PCIe host apart needs them for an ANS that is off, which apple_sleep_refuse() checks. + */ + if (!s->soc->regions && !s->soc->gp_host_apart && s->soc->ps.ans && + !s->apcie_phy_tunable) { dev_warn(s->dev, "deep sleep: no PCIe tunables for ANS, its PCIe block can't come back\n"); missing++; }