diff --git a/Documentation/devicetree/bindings/display/apple,dcp.yaml b/Documentation/devicetree/bindings/display/apple,dcp.yaml index ca938411a566a..849ee20abe322 100644 --- a/Documentation/devicetree/bindings/display/apple,dcp.yaml +++ b/Documentation/devicetree/bindings/display/apple,dcp.yaml @@ -173,9 +173,10 @@ properties: apple,display-power: $ref: /schemas/types.yaml#/definitions/phandle description: - A node whose ps, pwrgate and pmc-dcp registers hold the display power - words this coprocessor's driver writes around a firmware restart, such - as an apple,t8140-display-power node. + A node describing the display power-state words (or PMGR power-domain + chains), power-gate retention words and pmc-dcp counter that this + coprocessor's driver writes around a firmware restart, such as an + apple,t8140-display-power or apple,t6041-display-power node. apple,bw-scratch: $ref: /schemas/types.yaml#/definitions/phandle-array @@ -381,6 +382,14 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32 description: Display coprocessor index on multi-DCP systems. + apple,sleep-host-stop: + type: boolean + description: + The SoC's suspend-to-RAM needs this display coprocessor and the external + ones stopped, and their power domains lowered, by the operating system + before the sleep commit, and the internal one restarted after the wake. + The firmware doesn't take the display down for the sleep itself. + apple,typec-hybrid-first: type: boolean description: diff --git a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml index 7d15745134267..755f0c21e2d5d 100644 --- a/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml +++ b/Documentation/devicetree/bindings/display/apple,t8140-display-power.yaml @@ -4,30 +4,100 @@ $id: http://devicetree.org/schemas/display/apple,t8140-display-power.yaml# $schema: http://devicetree.org/meta-schemas/core.yaml# -title: Apple T8140 and T8142 display power words +title: Apple T6041, T8140 and T8142 display power words maintainers: - Diljit Singh description: - The words a display coprocessor's driver writes to power its domains off - and on around a restart of its firmware, as macOS does. A display - coprocessor names this node in its apple,display-power property. The words - belong to the power manager and the display block, so no driver binds it. + The words and PMGR power-state chains a display coprocessor's driver writes + to power its domains off and on around a restart of its firmware, as macOS + does. A display coprocessor names this node in its apple,display-power + property. The words belong to the power manager and the display block, so no + driver binds it. properties: compatible: enum: + - apple,t6041-display-power - apple,t8140-display-power - apple,t8142-display-power reg: minItems: 2 - maxItems: 3 + maxItems: 5 reg-names: minItems: 2 - maxItems: 3 + maxItems: 5 + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + '^chain@[0-9]+$': + type: object + description: | + One ordered display power-domain chain for apple,t6041-display-power, + powered down in reg order during suspend-to-RAM. + properties: + reg: + maxItems: 1 + + label: + description: Short name of the display chain (e.g. main, ext0..ext3). + + apple,main-chain: + type: boolean + description: + Marks the internal display chain, which clears the display AXI2AF + bridge and PMC voter on stop and is restarted warm on wake. + + apple,pwrgate-aux: + type: boolean + description: + Selects the pwrgate-aux register window instead of pwrgate for this + chain's power-gate retention words. + + apple,gapf-offset: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Byte offset of this chain's clock-protection slice within the gapf + register window. + + apple,pwrgate-offsets: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 2 + maxItems: 2 + description: + Byte offsets of the pair of power-gate retention words (A, then B) + within the selected pwrgate window. + + apple,fabric-domain: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Parent fabric PMGR power-state node held manually on while this chain + powers down, then returned to its previous auto-enable state. + + power-domains: + minItems: 3 + maxItems: 16 + description: | + Ordered PMGR power-state nodes for this chain: SYS, FE, CPU, followed + by the chain's child sub-domains in parent-before-child order + (powered off in reverse). + + required: + - reg + - label + - apple,gapf-offset + - apple,pwrgate-offsets + - power-domains + + additionalProperties: false required: - compatible @@ -35,6 +105,35 @@ required: - reg-names allOf: + - if: + properties: + compatible: + const: apple,t6041-display-power + then: + properties: + reg: + items: + - description: the display PMC voter counter pair + - description: the internal display power gate retention words + - description: the external display power gate retention words + - description: the clock-protection slices for all display chains + - description: the internal display AXI2AF bridge registers + reg-names: + items: + - const: pmc-dcp + - const: pwrgate + - const: pwrgate-aux + - const: gapf + - const: axi2af + required: + - '#address-cells' + - '#size-cells' + else: + properties: + '#address-cells': false + '#size-cells': false + patternProperties: + '^chain@[0-9]+$': false - if: properties: compatible: @@ -70,6 +169,51 @@ allOf: additionalProperties: false examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display-power@5048a9c14 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x048a9c14 0x0 0x8>, + <0x5 0x022a1000 0x0 0x100>, + <0x5 0x0282d000 0x0 0x1000>, + <0x5 0x00578000 0x0 0x1000>, + <0x4 0x03000100 0x0 0x10>; + reg-names = "pmc-dcp", "pwrgate", "pwrgate-aux", "gapf", "axi2af"; + #address-cells = <1>; + #size-cells = <0>; + + chain@0 { + reg = <0>; + label = "ext3"; + apple,pwrgate-aux; + apple,gapf-offset = <0x740>; + apple,pwrgate-offsets = <0xfb4 0xfd8>; + power-domains = <&ps_dispext3_sys>, <&ps_dispext3_fe>, + <&ps_dispext3_cpu>, <&ps_dispext3_dbe>, + <&ps_dpext3>, <&ps_dispext3_gp0>, + <&ps_dispext3_gp1>, <&ps_dispext3_gpl>, + <&ps_dispext3_ppp>, <&ps_dispext3_dsc>; + }; + + chain@4 { + reg = <4>; + label = "main"; + apple,main-chain; + apple,gapf-offset = <0x540>; + apple,pwrgate-offsets = <0x1c 0x60>; + apple,fabric-domain = <&ps_fab6_soc>; + power-domains = <&ps_disp_sys>, <&ps_disp_fe>, <&ps_disp_cpu>, + <&ps_disp_spi>, <&ps_disp_spmi>, <&ps_disp_dbe>, + <&ps_disp_dp>, <&ps_disp_gp0>, <&ps_disp_gp1>, + <&ps_disp_gpl>, <&ps_disp_cmb>, <&ps_disp_ppp>, + <&ps_disp_brc>, <&ps_disp_blc>; + }; + }; + }; + - | soc { #address-cells = <2>; diff --git a/Documentation/devicetree/bindings/mfd/apple,smc.yaml b/Documentation/devicetree/bindings/mfd/apple,smc.yaml index 34416179acfa0..255209498bd59 100644 --- a/Documentation/devicetree/bindings/mfd/apple,smc.yaml +++ b/Documentation/devicetree/bindings/mfd/apple,smc.yaml @@ -51,6 +51,24 @@ properties: mboxes: maxItems: 1 + apple,sleep-wake-type: + type: boolean + description: + The SMC firmware expects the wake type key (WKTP) set to its sleep value + at the sleep commit, and cleared after a full wake. Left at the sleep + value, the SMC treats the time awake as a power nap. + + apple,sleep-pmvc: + $ref: /schemas/types.yaml#/definitions/uint32 + minimum: 0x100 + maximum: 0x1ff + description: + The value written to the SMC's VDD_CIO rail key (pmVC) at the sleep + commit, before the sleep notice. Bit 8 is set, and bit n keeps port n's + CIO rail powered across the sleep. Which rails must stay up depends on + what the SoC's sleep sequence powers on itself. Without the property + pmVC is not written. + gpio: oneOf: - $ref: /schemas/gpio/apple,smc-gpio.yaml diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index 70700cb86b839..90e0abb33c3c6 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -694,22 +694,51 @@ allOf: interrupts: maxItems: 3 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: diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index bc7a15af64b29..999c31c461f2c 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -25,11 +25,30 @@ allOf: apple,sleep-retained: false apple,sleep-driver-owned: false apple,always-on: false + apple,auto-managed: false apple,min-state: false apple,force-disable: false apple,force-reset: false apple,externally-clocked: false apple,consumer-switched: false + - if: + properties: + compatible: + contains: + const: apple,t8132-pmgr-pwrstate + required: + - compatible + then: + properties: + apple,auto-managed: false + - if: + required: + - apple,auto-managed + then: + properties: + apple,no-auto-pm: false + apple,firmware-owned: false + apple,inherited-on: false - if: required: - apple,consumer-switched @@ -136,6 +155,18 @@ properties: coprocessors' CPU domains. type: boolean + apple,auto-managed: + description: | + Hardware-managed power domain (such as a DRAM channel slice or memory + fabric) that the boot loader may leave forced on and that must be + switched to hardware automatic power management (auto-enable) early + at boot, before the PMP firmware starts. + + Once switched, the hardware gates the domain by itself and it has no + software-controlled power transitions. On parts where an instance is + fused off, its power-state register reads as off. + type: boolean + apple,sleep-retained: description: A coprocessor keeps running in this domain across system sleep with no diff --git a/Documentation/devicetree/bindings/soc/apple/apple,t6041-sleep.yaml b/Documentation/devicetree/bindings/soc/apple/apple,t6041-sleep.yaml new file mode 100644 index 0000000000000..08629278a4872 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/apple/apple,t6041-sleep.yaml @@ -0,0 +1,437 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/apple/apple,t6041-sleep.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T6041 system sleep controls + +maintainers: + - AxxzyWasTaken + +description: | + The registers and PMGR power-state domains a kernel running directly at EL2 + on the M4 Max (T6041) writes to enter and return from suspend-to-RAM and to + power its secondary CPUs off. They belong to several hardware blocks, some of + which other drivers also use, so this node overlaps those drivers' register + ranges and the driver does not claim them. The way back from a sleep is the + boot loader's S2R mailbox, which the boot loader names in /chosen; without it + the driver offers no deep sleep. + +properties: + compatible: + const: apple,t6041-sleep + + reg: + minItems: 40 + maxItems: 40 + + reg-names: + items: + - const: ps-aop + - const: cluster + - const: pwrgate + - const: cpu-start + - const: wdt + - const: aon-misc + - const: commit + - const: clk-mux + - const: ka-pmgr + - const: ka-east + - const: pmc + - const: ptd + - const: perf + - const: wake + - const: amcc0 + - const: amcc1 + - const: amcc2 + - const: amcc3 + - const: amcc4 + - const: amcc5 + - const: amcc6 + - const: amcc7 + - const: dcs0 + - const: dcs1 + - const: dcs2 + - const: dcs3 + - const: dcs4 + - const: dcs5 + - const: dcs6 + - const: dcs7 + - const: axi2af-disp + - const: axi2af-dispext0 + - const: axi2af-dispext1 + - const: axi2af-dispext2 + - const: axi2af-dispext3 + - const: axi2af-ans + - const: axi2af-avd + - const: axi2af-venc0 + - const: axi2af-venc1 + - const: axi2af-jpg + + apple,pinctrl: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The AP pin controller whose pins a deep sleep resets. Its pins are saved + before a sleep and restored on wake. + + apple,pinctrl-skip-pins: + $ref: /schemas/types.yaml#/definitions/uint32-array + description: + Pins of that controller to leave alone across a sleep, neither saved nor + restored. + + apple,apcie: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The PCIe host whose shared registers and tunables the storage + controller's link depends on, and whose GP ports need clock restoration + after deep sleep. Without it or its tunables, deep sleep is refused. + + apple,spmi-buses: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 2 + maxItems: 2 + items: + maxItems: 1 + description: | + The SPMI buses driven around a sleep: nub-spmi0 first (PMU boot stage + and notify mask), then nub-spmi-a0 (notify mask when powered). + + apple,atc-phys: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 4 + maxItems: 4 + items: + maxItems: 1 + description: + The four ATC PHY nodes (atcphy0 through atcphy3) whose axi2af fabric + bridges are disarmed at sleep entry and re-armed on wake. + + apple,wake-enable: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 64 + description: + The AP wake source IDs left unmasked across suspend-to-RAM (ADT + ap-wake-sources). Every other wake source is masked. + + apple,sleep-off-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 256 + items: + maxItems: 1 + description: + PMGR power-state nodes powered off before the sleep commit (sorted + child-before-parent from their DT power-domains edges) and restored to + their pre-commit states on wake. + + apple,atc-off-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 64 + items: + maxItems: 1 + description: + USB-C / ATC PMGR power-state nodes lowered in hardware order after PS + matching and PMC/PTD quiesce, and restored to their pre-commit states on + wake. + + apple,sleep-auto-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 128 + items: + maxItems: 1 + description: + PMGR power-state nodes placed into hardware automatic power management + with auto-state 0 (power gated) before the sleep commit, skipping fused-off + words, and restored on wake. + + apple,sleep-auto-clkgate-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 128 + items: + maxItems: 1 + description: + PMGR power-state nodes placed into hardware automatic power management + with auto-state 4 (clock gated) before the sleep commit, skipping fused-off + words, and restored on wake. + + apple,sleep-auto-active-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 64 + items: + maxItems: 1 + description: + PMGR power-state nodes placed into hardware automatic power management + with auto-state 15 (active) before the sleep commit and restored on wake. + + apple,sleep-keep-on-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 1 + maxItems: 64 + items: + maxItems: 1 + description: + PMGR power-state nodes held manually on (target 15, auto-enable clear) + before the sleep commit and restored on wake. + + apple,cpu-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 16 + maxItems: 16 + items: + maxItems: 1 + description: + PMGR power-state nodes for the 16 CPU cores in ADT CPU ID order + (ecpu_0..3, pcpu0_0..5, pcpu1_0..5), matched before commit and polled off + as secondary CPUs enter deep WFI. + + apple,cpm-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 3 + maxItems: 3 + items: + maxItems: 1 + description: + PMGR power-state nodes for the three cluster power managers in order + (ecpm, pcpm0, pcpm1). + + apple,sep-domain: + $ref: /schemas/types.yaml#/definitions/phandle + description: + PMGR power-state node for SEP, whose DEV_DISABLE bit is set before the + sleep commit and cleared with BUSY polled clear on wake. + + apple,spmi-a0-domain: + $ref: /schemas/types.yaml#/definitions/phandle + description: + PMGR power-state node for nub-spmi-a0, tested before accessing the second + SPMI bus's notify mask register. + + apple,atc-common-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 4 + maxItems: 4 + items: + maxItems: 1 + description: + PMGR power-state nodes for the four ATC common domains (atc0_common + through atc3_common), raised right before the sleep commit. + + apple,atc-fabric-domain: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Parent fabric PMGR power-state node (fab2_soc) raised manually while + bringing up the ATC common domains and returned to auto-enable. + + apple,atc-afi-domain: + $ref: /schemas/types.yaml#/definitions/phandle + description: + AFI fabric PMGR power-state node left in hardware auto-enable after + lowering the ATC power domains. + + apple,apcie-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 8 + maxItems: 8 + items: + maxItems: 1 + description: | + The eight storage and GP PCIe PMGR power-state nodes in order: + ans, apcie_gp, apcie_sys_gp, apcie_st0, apcie_sys_st0, apcie_st1, + apcie_sys_st1, apcie_phy_sw. + + apple,commit-sio-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 2 + maxItems: 2 + items: + maxItems: 1 + description: | + The two SIO PMGR power-state nodes written in the final commit sequence, + in order: sio, sio_cpu. + + apple,commit-periph-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 5 + maxItems: 5 + items: + maxItems: 1 + description: | + The five peripheral PMGR power-state nodes lowered after the PMU boot + stage write in the final commit sequence, in order: i2c6, i2c3, i2c2, + i2c1, spi2. + + apple,axi2af-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 15 + maxItems: 15 + items: + maxItems: 1 + description: | + PMGR power-state nodes paired 1:1 with the 15 AXI2AF fabric bridges in + order: atc0..3_common (0..3), disp_sys (4), dispext0..3_sys (5..8), + ans (9), avd_sys (10), venc0_sys (11), venc1_sys (12), jpg (13), + apcie_sys_gp (14). + + apple,full-part-detect-domains: + $ref: /schemas/types.yaml#/definitions/phandle-array + minItems: 2 + maxItems: 2 + items: + maxItems: 1 + description: | + The two AMCC PMGR power-state nodes (amcc24, amcc28) probed at driver + init to distinguish 24-channel binned parts from 32-channel full parts. + +required: + - compatible + - reg + - reg-names + - apple,pinctrl + - apple,spmi-buses + - apple,wake-enable + - apple,sleep-off-domains + - apple,atc-off-domains + - apple,sleep-auto-domains + - apple,sleep-auto-clkgate-domains + - apple,sleep-auto-active-domains + - apple,sleep-keep-on-domains + - apple,cpu-domains + - apple,cpm-domains + - apple,sep-domain + - apple,spmi-a0-domain + - apple,atc-common-domains + - apple,atc-fabric-domain + - apple,atc-afi-domain + - apple,apcie-domains + - apple,commit-sio-domains + - apple,commit-periph-domains + - apple,axi2af-domains + - apple,full-part-detect-domains + +allOf: + - if: + not: + properties: + status: + const: disabled + required: + - status + then: + required: + - apple,atc-phys + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + sleep-controller@508304000 { + compatible = "apple,t6041-sleep"; + reg = <0x5 0x08304000 0x0 0x4000>, + <0x5 0x02820000 0x0 0x4000>, + <0x5 0x0282c000 0x0 0x4000>, + <0x5 0x02888000 0x0 0x4000>, + <0x5 0x0836c000 0x0 0x4000>, + <0x5 0x08330000 0x0 0x4000>, + <0x5 0x08904000 0x0 0x4>, + <0x5 0x00038000 0x0 0x4000>, + <0x5 0x029dc000 0x0 0x880>, + <0x5 0x022d0000 0x0 0x880>, + <0x5 0x04800000 0x0 0xb0000>, + <0x5 0x003c0000 0x0 0x20000>, + <0x5 0x0020c000 0x0 0x800>, + <0x5 0x08004000 0x0 0x58>, + <0x2 0x20000000 0x0 0x200000>, + <0x2 0x22000000 0x0 0x200000>, + <0x2 0x24000000 0x0 0x200000>, + <0x2 0x26000000 0x0 0x200000>, + <0x2 0x28000000 0x0 0x200000>, + <0x2 0x2a000000 0x0 0x200000>, + <0x2 0x2c000000 0x0 0x200000>, + <0x2 0x2e000000 0x0 0x200000>, + <0x2 0x20200000 0x0 0x601000>, + <0x2 0x22200000 0x0 0x601000>, + <0x2 0x24200000 0x0 0x601000>, + <0x2 0x26200000 0x0 0x601000>, + <0x2 0x28200000 0x0 0x601000>, + <0x2 0x2a200000 0x0 0x601000>, + <0x2 0x2c200000 0x0 0x601000>, + <0x2 0x2e200000 0x0 0x601000>, + <0x4 0x03000100 0x0 0x10>, + <0x3 0xa3000100 0x0 0x10>, + <0x6 0x03000100 0x0 0x10>, + <0x6 0x07000100 0x0 0x10>, + <0x3 0x07000100 0x0 0x10>, + <0x4 0x0b000100 0x0 0x10>, + <0x2 0x80000100 0x0 0x10>, + <0x2 0x82000100 0x0 0x10>, + <0x2 0x84000100 0x0 0x10>, + <0x4 0x86000100 0x0 0x10>; + reg-names = "ps-aop", + "cluster", "pwrgate", "cpu-start", "wdt", + "aon-misc", "commit", "clk-mux", "ka-pmgr", + "ka-east", "pmc", "ptd", "perf", "wake", + "amcc0", "amcc1", "amcc2", "amcc3", + "amcc4", "amcc5", "amcc6", "amcc7", + "dcs0", "dcs1", "dcs2", "dcs3", + "dcs4", "dcs5", "dcs6", "dcs7", + "axi2af-disp", "axi2af-dispext0", + "axi2af-dispext1", "axi2af-dispext2", + "axi2af-dispext3", "axi2af-ans", + "axi2af-avd", "axi2af-venc0", + "axi2af-venc1", "axi2af-jpg"; + apple,pinctrl = <&pinctrl>; + apple,pinctrl-skip-pins = <190 191 192>; + apple,apcie = <&pcie0>; + apple,spmi-buses = <&nub_spmi0>, <&nub_spmi_a0>; + apple,atc-phys = <&atcphy0>, <&atcphy1>, <&atcphy2>, <&atcphy3>; + apple,wake-enable = <13 15 25 27 28 41 44 48 50 51 52 53 55 + 101 106 126 127 128 129 130 131 132 133 + 155 167>; + apple,sleep-off-domains = <&ps_gfx>, <&ps_afr>; + apple,atc-off-domains = <&ps_atc0_phymxwrap>, <&ps_atc0_common>; + apple,sleep-auto-domains = <&ps_fab0_soc>, <&ps_amcc0>; + apple,sleep-auto-clkgate-domains = <&ps_fab3_soc>, <&ps_dcs_00>; + apple,sleep-auto-active-domains = <&ps_fab2_soc>, <&ps_afi>; + apple,sleep-keep-on-domains = <&ps_sio>, <&ps_sio_cpu>; + apple,cpu-domains = <&ps_ecpu_0>, <&ps_ecpu_1>, <&ps_ecpu_2>, + <&ps_ecpu_3>, <&ps_pcpu0_0>, <&ps_pcpu0_1>, + <&ps_pcpu0_2>, <&ps_pcpu0_3>, <&ps_pcpu0_4>, + <&ps_pcpu0_5>, <&ps_pcpu1_0>, <&ps_pcpu1_1>, + <&ps_pcpu1_2>, <&ps_pcpu1_3>, <&ps_pcpu1_4>, + <&ps_pcpu1_5>; + apple,cpm-domains = <&ps_ecpm>, <&ps_pcpm0>, <&ps_pcpm1>; + apple,sep-domain = <&ps_sep>; + apple,spmi-a0-domain = <&ps_nub_spmi_a0>; + apple,atc-common-domains = <&ps_atc0_common>, <&ps_atc1_common>, + <&ps_atc2_common>, <&ps_atc3_common>; + apple,atc-fabric-domain = <&ps_fab2_soc>; + apple,atc-afi-domain = <&ps_afi>; + apple,apcie-domains = <&ps_ans>, <&ps_apcie_gp>, + <&ps_apcie_sys_gp>, <&ps_apcie_st0>, + <&ps_apcie_sys_st0>, <&ps_apcie_st1>, + <&ps_apcie_sys_st1>, <&ps_apcie_phy_sw>; + apple,commit-sio-domains = <&ps_sio>, <&ps_sio_cpu>; + apple,commit-periph-domains = <&ps_i2c6>, <&ps_i2c3>, <&ps_i2c2>, + <&ps_i2c1>, <&ps_spi2>; + apple,axi2af-domains = <&ps_atc0_common>, <&ps_atc1_common>, + <&ps_atc2_common>, <&ps_atc3_common>, + <&ps_disp_sys>, <&ps_dispext0_sys>, + <&ps_dispext1_sys>, <&ps_dispext2_sys>, + <&ps_dispext3_sys>, <&ps_ans>, + <&ps_avd_sys>, <&ps_venc0_sys>, + <&ps_venc1_sys>, <&ps_jpg>, + <&ps_apcie_sys_gp>; + apple,full-part-detect-domains = <&ps_amcc24>, <&ps_amcc28>; + }; + }; diff --git a/arch/arm64/boot/dts/apple/t6041-j614-j616-j575-scaler.dtsi b/arch/arm64/boot/dts/apple/t6041-j614-j616-j575-scaler.dtsi index 34ecb3b560df9..6140cc718d11c 100644 --- a/arch/arm64/boot/dts/apple/t6041-j614-j616-j575-scaler.dtsi +++ b/arch/arm64/boot/dts/apple/t6041-j614-j616-j575-scaler.dtsi @@ -26,19 +26,6 @@ }; }; -&pmgr_aux { - ps_fab5_soc: power-controller@440 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x440 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "fab5_soc"; - power-domains = <&ps_afi>; - apple,always-on; - status = "disabled"; - }; -}; - /* PMGR group 1 resolves via ps-groups to the main bank at 0x502280000. */ &pmgr { ps_msr1: ps_msr1_dart: power-controller@3b0 { diff --git a/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi b/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi index 6c88428a48ba5..f48c73e04176f 100644 --- a/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi +++ b/arch/arm64/boot/dts/apple/t6041-j614c-j616c.dtsi @@ -33,6 +33,85 @@ sep = &sep; }; + /* + * Display power words and PMGR chains the DCP driver writes around + * suspend-to-RAM. The windows belong to PMC, PMGR, GAPF and AXI2AF; + * no driver binds this. + */ + dcp_power: display-power@5048a9c14 { + compatible = "apple,t6041-display-power"; + reg = <0x5 0x048a9c14 0x0 0x8>, + <0x5 0x022a1000 0x0 0x100>, + <0x5 0x0282d000 0x0 0x1000>, + <0x5 0x00578000 0x0 0x1000>, + <0x4 0x03000100 0x0 0x10>; + reg-names = "pmc-dcp", "pwrgate", "pwrgate-aux", "gapf", "axi2af"; + #address-cells = <1>; + #size-cells = <0>; + + chain@0 { + reg = <0>; + label = "ext3"; + apple,pwrgate-aux; + apple,gapf-offset = <0x740>; + apple,pwrgate-offsets = <0xfb4 0xfd8>; + power-domains = <&ps_dispext3_sys>, <&ps_dispext3_fe>, <&ps_dispext3_cpu>, + <&ps_dispext3_dbe>, <&ps_dpext3>, <&ps_dispext3_gp0>, + <&ps_dispext3_gp1>, <&ps_dispext3_gpl>, <&ps_dispext3_ppp>, + <&ps_dispext3_dsc>; + }; + + chain@1 { + reg = <1>; + label = "ext2"; + apple,pwrgate-aux; + apple,gapf-offset = <0xd80>; + apple,pwrgate-offsets = <0xb34 0xb58>; + power-domains = <&ps_dispext2_sys>, <&ps_dispext2_fe>, <&ps_dispext2_cpu>, + <&ps_dispext2_dbe>, <&ps_dpext2>, <&ps_dispext2_gp0>, + <&ps_dispext2_gp1>, <&ps_dispext2_gpl>, <&ps_dispext2_ppp>, + <&ps_dispext2_dsc>; + }; + + chain@2 { + reg = <2>; + label = "ext1"; + apple,pwrgate-aux; + apple,gapf-offset = <0xd00>; + apple,pwrgate-offsets = <0x6b4 0x6d8>; + power-domains = <&ps_dispext1_sys>, <&ps_dispext1_fe>, <&ps_dispext1_cpu>, + <&ps_dispext1_dbe>, <&ps_dpext1>, <&ps_dispext1_gp0>, + <&ps_dispext1_gp1>, <&ps_dispext1_gpl>, <&ps_dispext1_ppp>, + <&ps_dispext1_dsc>; + }; + + chain@3 { + reg = <3>; + label = "ext0"; + apple,pwrgate-aux; + apple,gapf-offset = <0x840>; + apple,pwrgate-offsets = <0x234 0x258>; + power-domains = <&ps_dispext0_sys>, <&ps_dispext0_fe>, <&ps_dispext0_cpu>, + <&ps_dispext0_dbe>, <&ps_dpext0>, <&ps_dispext0_gp0>, + <&ps_dispext0_gp1>, <&ps_dispext0_gpl>, <&ps_dispext0_ppp>, + <&ps_dispext0_dsc>; + }; + + chain@4 { + reg = <4>; + label = "main"; + apple,main-chain; + apple,gapf-offset = <0x540>; + apple,pwrgate-offsets = <0x1c 0x60>; + apple,fabric-domain = <&ps_fab6_soc>; + power-domains = <&ps_disp_sys>, <&ps_disp_fe>, <&ps_disp_cpu>, + <&ps_disp_spi>, <&ps_disp_spmi>, <&ps_disp_dbe>, + <&ps_disp_dp>, <&ps_disp_gp0>, <&ps_disp_gp1>, + <&ps_disp_gpl>, <&ps_disp_cmb>, <&ps_disp_ppp>, + <&ps_disp_brc>, <&ps_disp_blc>; + }; + }; + chosen { #address-cells = <2>; #size-cells = <2>; @@ -1197,6 +1276,9 @@ }; &smc { + apple,sleep-wake-type; + /* VDD_CIO mask: bit 8 + bit 0 keeps port 0 powered for atc0_common at commit. */ + apple,sleep-pmvc = <0x101>; status = "okay"; smc_gpio_low: gpio-low { @@ -1652,10 +1734,17 @@ <0x4 0x17020000 0x0 0x4000>, <0x4 0x17024000 0x0 0x4000>, <0x4 0x17028000 0x0 0x4000>, - <0x4 0x1702c000 0x0 0x4000>; + <0x4 0x1702c000 0x0 0x4000>, + <0x4 0x16000000 0x0 0x1000000>, + <0x4 0x15046200 0x0 0x4000>, + <0x4 0x15044000 0x0 0x4000>, + <0x4 0x17000000 0x0 0x40000>, + <0x4 0x17040000 0x0 0x28000>; reg-names = "config", "rc", "port0", "port1", "port2", "port3", - "phy0", "phy1", "phy2", "phy3"; + "phy0", "phy1", "phy2", "phy3", + "axi2af", "cio3pll", "clkgen", + "phy-block", "phy-ip"; ranges = <0x43000000 0xb 0xc0000000 0xb 0xc0000000 0x0 0x20000000>, <0x02000000 0x0 0x80000000 0xb 0x80000000 0x0 0x40000000>; pinctrl-names = "default"; @@ -1756,7 +1845,15 @@ phandle = <&display>; }; +&t6041_sleep { + apple,apcie = <&pcie0>; + apple,atc-phys = <&atcphy0>, <&atcphy1>, <&atcphy2>, <&atcphy3>; + status = "okay"; +}; + &dcp { + apple,sleep-host-stop; + apple,display-power = <&dcp_power>; clocks = <&clk_disp0>; phandle = <&dcp>; @@ -2754,43 +2851,20 @@ * under DPA_P. The SIO stays disabled here: the loader enables it once it has * reserved the firmware iBoot loaded (it finds it by the alias). */ -&pmgr { - ps_uart_p: power-controller@1a0 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x1a0 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "uart_p"; - power-domains = <&ps_sio>; - }; - - ps_dpa_p: power-controller@1a8 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x1a8 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "dpa_p"; - power-domains = <&ps_sio>; - apple,always-on; - }; - - ps_dpa1: power-controller@238 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x238 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "dpa1"; - power-domains = <&ps_dpa_p>; - }; - - ps_dpa2: power-controller@240 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x240 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "dpa2"; - power-domains = <&ps_dpa_p>; - }; +&ps_uart_p { + status = "okay"; +}; + +&ps_dpa_p { + status = "okay"; +}; + +&ps_dpa1 { + status = "okay"; +}; + +&ps_dpa2 { + status = "okay"; }; / { diff --git a/arch/arm64/boot/dts/apple/t6041-pmgr.dtsi b/arch/arm64/boot/dts/apple/t6041-pmgr.dtsi new file mode 100644 index 0000000000000..2f7a2f483b3ec --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6041-pmgr.dtsi @@ -0,0 +1,424 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * T6041-specific PMGR power domains for hardware auto-managed DCS channels + * and memory/SoC fabrics. + * + * Offsets and parent links verified against the J616c ADT (/arm-io/pmgr + * devices and ps-groups). The DCS nodes omit their ADT parents, the AMCC + * power states, which are not described in this device tree. All 32 DCS + * channels (24 present on binned parts, 32 on full parts) and 12 fabrics + * are hardware auto-managed: the boot loader may leave them forced on, and + * they must be switched to hardware AUTO_ENABLE early at boot, before the + * PMP starts. On binned parts dcs_24-31 are fused off and read as off. + * + * Copyright The Asahi Linux Contributors + */ + +&pmgr_aux { + ps_fab0_soc: power-controller@168 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x168 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab0_soc"; + power-domains = <&ps_afi>; + apple,always-on; + apple,auto-managed; + }; + + ps_dcs_00: power-controller@188 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x188 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_00"; + apple,auto-managed; + }; + + ps_dcs_01: power-controller@1a0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_01"; + apple,auto-managed; + }; + + ps_dcs_02: power-controller@1b0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1b0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_02"; + apple,auto-managed; + }; + + ps_dcs_03: power-controller@1c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_03"; + apple,auto-managed; + }; + + ps_dcs_08: power-controller@1d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_08"; + apple,auto-managed; + }; + + ps_dcs_09: power-controller@1e0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_09"; + apple,auto-managed; + }; + + ps_dcs_10: power-controller@1f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_10"; + apple,auto-managed; + }; + + ps_dcs_11: power-controller@200 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x200 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_11"; + apple,auto-managed; + }; + + ps_dcs_16: power-controller@210 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x210 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_16"; + apple,auto-managed; + }; + + ps_dcs_17: power-controller@220 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x220 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_17"; + apple,auto-managed; + }; + + ps_dcs_18: power-controller@230 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x230 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_18"; + apple,auto-managed; + }; + + ps_dcs_19: power-controller@240 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x240 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_19"; + apple,auto-managed; + }; + + ps_dcs_24: power-controller@250 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x250 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_24"; + apple,auto-managed; + }; + + ps_dcs_25: power-controller@260 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x260 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_25"; + apple,auto-managed; + }; + + ps_dcs_26: power-controller@270 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x270 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_26"; + apple,auto-managed; + }; + + ps_fab_gw_0: power-controller@288 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x288 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab_gw_0"; + apple,always-on; + apple,auto-managed; + }; + + ps_fab_gw_1: power-controller@290 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x290 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab_gw_1"; + apple,always-on; + apple,auto-managed; + }; + + ps_fab_afr: power-controller@298 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x298 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab_afr"; + apple,always-on; + apple,auto-managed; + }; + + ps_fab1_soc: power-controller@2d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab1_soc"; + power-domains = <&ps_afi>; + apple,always-on; + apple,auto-managed; + }; + + ps_fab2_soc: power-controller@338 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x338 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab2_soc"; + power-domains = <&ps_afi>; + apple,always-on; + apple,auto-managed; + }; + + ps_fab5_soc: power-controller@440 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x440 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab5_soc"; + power-domains = <&ps_afi>; + apple,always-on; + apple,auto-managed; + }; + + ps_fab7_soc: power-controller@488 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x488 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab7_soc"; + power-domains = <&ps_afi>; + apple,always-on; + apple,auto-managed; + }; + + /* dcs_27 sits at +0x530 rather than adjacent to dcs_26 (+0x280 is amcc27). */ + ps_dcs_27: power-controller@530 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x530 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_27"; + apple,auto-managed; + }; +}; + +&ps_fab6_soc { + apple,auto-managed; +}; + +&pmgr { + ps_fab4_soc: power-controller@128 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fab4_soc"; + power-domains = <&ps_afc>; + apple,always-on; + apple,auto-managed; + }; + + ps_dcs_04: power-controller@2e0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_04"; + apple,auto-managed; + }; + + ps_dcs_05: power-controller@2e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_05"; + apple,auto-managed; + }; + + ps_dcs_06: power-controller@2f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_06"; + apple,auto-managed; + }; + + ps_dcs_07: power-controller@2f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_07"; + apple,auto-managed; + }; + + ps_dcs_12: power-controller@300 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x300 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_12"; + apple,auto-managed; + }; + + ps_dcs_13: power-controller@308 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x308 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_13"; + apple,auto-managed; + }; + + ps_dcs_14: power-controller@310 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x310 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_14"; + apple,auto-managed; + }; + + ps_dcs_15: power-controller@318 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x318 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_15"; + apple,auto-managed; + }; + + ps_dcs_20: power-controller@320 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x320 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_20"; + apple,auto-managed; + }; + + ps_dcs_21: power-controller@328 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x328 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_21"; + apple,auto-managed; + }; + + ps_dcs_22: power-controller@330 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x330 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_22"; + apple,auto-managed; + }; + + ps_dcs_23: power-controller@338 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x338 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_23"; + apple,auto-managed; + }; + + ps_dcs_28: power-controller@340 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x340 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_28"; + apple,auto-managed; + }; + + ps_dcs_29: power-controller@348 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x348 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_29"; + apple,auto-managed; + }; + + ps_dcs_30: power-controller@350 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x350 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_30"; + apple,auto-managed; + }; + + ps_dcs_31: power-controller@358 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x358 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dcs_31"; + apple,auto-managed; + }; +}; + +&ps_fab3_soc { + apple,auto-managed; +}; + +&pmgr_mini { + ps_nub_fabric: power-controller@100 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_fabric"; + apple,always-on; + apple,auto-managed; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t6041-sleep-pmgr.dtsi b/arch/arm64/boot/dts/apple/t6041-sleep-pmgr.dtsi new file mode 100644 index 0000000000000..82d293e918fd8 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t6041-sleep-pmgr.dtsi @@ -0,0 +1,1850 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Additional Apple T6041 ("M4 Max") PMGR power states used by suspend-to-RAM + * and display power-domain chains, beyond the nodes already described in + * t6041.dtsi, t604x-pmgr.dtsi, t6041-pmgr.dtsi (hardware auto-managed + * DCS/fabrics) and t6041-j614-j616-j575-scaler.dtsi. + * + * Offsets and parent links are verified against the J616c ADT (/arm-io/pmgr + * devices and ps-groups). Every newly added node stays disabled so + * apple-pmgr-pwrstate never probes or powers down firmware-owned blocks; + * boards enable nodes that have Linux consumers (such as ps_uart_p, ps_dpa_p, + * ps_dpa1 and ps_dpa2 on J614c/J616c). + * + * Copyright The Asahi Linux Contributors + */ + +&pmgr { + ps_apcie_gp: power-controller@100 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp"; + status = "disabled"; + }; + + ps_fpwm1: power-controller@140 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fpwm1"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_fpwm2: power-controller@148 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fpwm2"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_i2c0: power-controller@150 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x150 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c0"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_i2c5: power-controller@178 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x178 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c5"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_i2c7: power-controller@188 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x188 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c7"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_uart_p: power-controller@1a0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart_p"; + power-domains = <&ps_sio>; + status = "disabled"; + }; + + ps_dpa_p: power-controller@1a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa_p"; + power-domains = <&ps_sio>; + apple,always-on; + status = "disabled"; + }; + + ps_spi0: power-controller@1b8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1b8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi0"; + power-domains = <&ps_spi_p>; + status = "disabled"; + }; + + ps_spi1: power-controller@1c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi1"; + power-domains = <&ps_spi_p>; + status = "disabled"; + }; + + ps_spi3: power-controller@1d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi3"; + power-domains = <&ps_spi_p>; + status = "disabled"; + }; + + ps_spi4: power-controller@1d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi4"; + power-domains = <&ps_spi_p>; + status = "disabled"; + }; + + ps_spi5: power-controller@1e0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "spi5"; + power-domains = <&ps_spi_p>; + status = "disabled"; + }; + + ps_uart_n: power-controller@1f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart_n"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart0: power-controller@1f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart0"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart1: power-controller@200 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x200 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart1"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart2: power-controller@208 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x208 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart2"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart3: power-controller@210 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x210 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart3"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart4: power-controller@218 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x218 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart4"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart5: power-controller@220 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x220 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart5"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_uart6: power-controller@228 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x228 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "uart6"; + power-domains = <&ps_uart_p>; + status = "disabled"; + }; + + ps_dpa0: power-controller@230 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x230 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa0"; + power-domains = <&ps_dpa_p>; + status = "disabled"; + }; + + ps_dpa1: power-controller@238 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x238 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa1"; + power-domains = <&ps_dpa_p>; + status = "disabled"; + }; + + ps_dpa2: power-controller@240 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x240 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa2"; + power-domains = <&ps_dpa_p>; + status = "disabled"; + }; + + ps_dpa3: power-controller@248 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x248 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa3"; + power-domains = <&ps_dpa_p>; + status = "disabled"; + }; + + ps_dpa4: power-controller@250 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x250 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpa4"; + power-domains = <&ps_dpa_p>; + status = "disabled"; + }; + + ps_disp_sys: power-controller@258 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x258 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_sys"; + power-domains = <&ps_fab6_soc>; + status = "disabled"; + }; + + ps_amcc4: power-controller@260 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x260 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc4"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc5: power-controller@268 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x268 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc5"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc6: power-controller@270 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x270 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc6"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc7: power-controller@278 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x278 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc7"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc12: power-controller@280 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x280 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc12"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc13: power-controller@288 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x288 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc13"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc14: power-controller@290 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x290 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc14"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc15: power-controller@298 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x298 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc15"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc20: power-controller@2a0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc20"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc21: power-controller@2a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc21"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc22: power-controller@2b0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc22"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc23: power-controller@2b8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2b8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc23"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc28: power-controller@2c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc28"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc29: power-controller@2c8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2c8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc29"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc30: power-controller@2d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc30"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc31: power-controller@2d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc31"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_disp_fe: power-controller@368 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x368 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_fe"; + power-domains = <&ps_disp_sys>; + status = "disabled"; + }; + + ps_apcie_sys_gp: power-controller@390 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x390 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_gp"; + power-domains = <&ps_fab3_soc>, <&ps_apcie_gp>; + status = "disabled"; + }; + + ps_apcie_phy_sw: power-controller@398 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x398 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_phy_sw"; + power-domains = <&ps_apcie_sys_st0>, <&ps_apcie_sys_st1>, + <&ps_apcie_sys_gp>; + status = "disabled"; + }; + + ps_prores: power-controller@3a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "prores"; + power-domains = <&ps_fab6_soc>; + status = "disabled"; + }; +}; + +&pmgr_disp { + ps_disp_cpu: power-controller@0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_cpu"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_spi: power-controller@8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_spi"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_spmi: power-controller@10 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_spmi"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_dbe: power-controller@18 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x18 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_dbe"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_dp: power-controller@20 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x20 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dp"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_gp0: power-controller@28 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x28 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_gp0"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_gp1: power-controller@30 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x30 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_gp1"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_gpl: power-controller@38 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x38 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_gpl"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_cmb: power-controller@40 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_cmb"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_ppp: power-controller@48 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x48 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_ppp"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_brc: power-controller@50 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x50 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_brc"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; + + ps_disp_blc: power-controller@58 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x58 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_blc"; + power-domains = <&ps_disp_fe>; + status = "disabled"; + }; +}; + +&pmgr_aux { + ps_ecpu_0: power-controller@0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ecpu_0"; + status = "disabled"; + }; + + ps_ecpu_1: power-controller@8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ecpu_1"; + status = "disabled"; + }; + + ps_ecpu_2: power-controller@10 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ecpu_2"; + status = "disabled"; + }; + + ps_ecpu_3: power-controller@18 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x18 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ecpu_3"; + status = "disabled"; + }; + + ps_pcpu0_0: power-controller@20 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x20 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_0"; + status = "disabled"; + }; + + ps_pcpu0_1: power-controller@28 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x28 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_1"; + status = "disabled"; + }; + + ps_pcpu0_2: power-controller@30 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x30 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_2"; + status = "disabled"; + }; + + ps_pcpu0_3: power-controller@38 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x38 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_3"; + status = "disabled"; + }; + + ps_pcpu0_4: power-controller@40 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_4"; + status = "disabled"; + }; + + ps_pcpu0_5: power-controller@48 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x48 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu0_5"; + status = "disabled"; + }; + + ps_pcpu1_0: power-controller@50 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x50 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_0"; + status = "disabled"; + }; + + ps_pcpu1_1: power-controller@58 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x58 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_1"; + status = "disabled"; + }; + + ps_pcpu1_2: power-controller@60 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_2"; + status = "disabled"; + }; + + ps_pcpu1_3: power-controller@68 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x68 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_3"; + status = "disabled"; + }; + + ps_pcpu1_4: power-controller@70 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x70 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_4"; + status = "disabled"; + }; + + ps_pcpu1_5: power-controller@78 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x78 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpu1_5"; + status = "disabled"; + }; + + ps_ecpm: power-controller@80 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x80 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ecpm"; + status = "disabled"; + }; + + ps_pcpm0: power-controller@88 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x88 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpm0"; + status = "disabled"; + }; + + ps_pcpm1: power-controller@90 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x90 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pcpm1"; + status = "disabled"; + }; + + ps_dwi: power-controller@108 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dwi"; + status = "disabled"; + }; + + ps_aic: power-controller@118 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x118 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "aic"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pmc: power-controller@120 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x120 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pmc"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pms_c1ppt: power-controller@128 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x128 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_c1ppt"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_soc_dpe: power-controller@130 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x130 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "soc_dpe"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pmgr_soc_ocla: power-controller@138 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x138 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pmgr_soc_ocla"; + status = "disabled"; + }; + + ps_pms_fpwm0: power-controller@140 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_fpwm0"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pms_fpwm1: power-controller@148 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x148 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_fpwm1"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pms_fpwm2: power-controller@150 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x150 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_fpwm2"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pms_fpwm3: power-controller@158 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x158 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_fpwm3"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_pms_fpwm4: power-controller@160 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "pms_fpwm4"; + power-domains = <&ps_pms>; + status = "disabled"; + }; + + ps_amcc0: power-controller@180 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc0"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_rom: power-controller@190 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x190 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "rom"; + power-domains = <&ps_amcc0>; + status = "disabled"; + }; + + ps_amcc1: power-controller@198 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x198 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc1"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc2: power-controller@1a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc2"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc3: power-controller@1b8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1b8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc3"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc8: power-controller@1c8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc8"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc9: power-controller@1d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc9"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc10: power-controller@1e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc10"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc11: power-controller@1f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc11"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc16: power-controller@208 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x208 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc16"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc17: power-controller@218 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x218 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc17"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc18: power-controller@228 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x228 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc18"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc19: power-controller@238 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x238 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc19"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc24: power-controller@248 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x248 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc24"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc25: power-controller@258 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x258 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc25"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc26: power-controller@268 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x268 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc26"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_amcc27: power-controller@280 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x280 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "amcc27"; + power-domains = <&ps_afc>; + status = "disabled"; + }; + + ps_dispext3_sys: power-controller@2d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_sys"; + power-domains = <&ps_fab1_soc>; + status = "disabled"; + }; + + ps_dispext3_fe: power-controller@2e0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_fe"; + power-domains = <&ps_dispext3_sys>; + status = "disabled"; + }; + + ps_dispext3_cpu: power-controller@2e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_cpu"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_dbe: power-controller@2f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_dbe"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dpext3: power-controller@2f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x2f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpext3"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_gp0: power-controller@300 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x300 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_gp0"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_gp1: power-controller@308 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x308 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_gp1"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_gpl: power-controller@310 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x310 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_gpl"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_ppp: power-controller@318 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x318 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_ppp"; + power-domains = <&ps_dispext3_fe>; + status = "disabled"; + }; + + ps_dispext3_dsc: power-controller@320 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x320 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext3_dsc"; + power-domains = <&ps_dispext3_dbe>; + status = "disabled"; + }; + + ps_dispext0_sys: power-controller@340 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x340 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_sys"; + power-domains = <&ps_fab2_soc>; + status = "disabled"; + }; + + ps_dispext0_fe: power-controller@348 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x348 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_fe"; + power-domains = <&ps_dispext0_sys>; + status = "disabled"; + }; + + ps_dispext0_cpu: power-controller@350 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x350 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_cpu"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_dbe: power-controller@358 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x358 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_dbe"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dpext0: power-controller@360 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x360 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpext0"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_gp0: power-controller@368 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x368 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_gp0"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_gp1: power-controller@370 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x370 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_gp1"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_gpl: power-controller@378 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x378 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_gpl"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_ppp: power-controller@380 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x380 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_ppp"; + power-domains = <&ps_dispext0_fe>; + status = "disabled"; + }; + + ps_dispext0_dsc: power-controller@388 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x388 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_dsc"; + power-domains = <&ps_dispext0_dbe>; + status = "disabled"; + }; + + ps_atc0_cio: power-controller@398 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x398 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_cio"; + power-domains = <&ps_atc0_common>; + status = "disabled"; + }; + + ps_atc0_pcie: power-controller@3a0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_pcie"; + power-domains = <&ps_atc0_common>; + status = "disabled"; + }; + + ps_atc0_cio_pcie: power-controller@3a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_cio_pcie"; + power-domains = <&ps_atc0_cio>; + status = "disabled"; + }; + + ps_atc0_cio_usb: power-controller@3b0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3b0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_cio_usb"; + power-domains = <&ps_atc0_cio>; + status = "disabled"; + }; + + ps_atc1_cio: power-controller@3c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_cio"; + power-domains = <&ps_atc1_common>; + status = "disabled"; + }; + + ps_atc1_pcie: power-controller@3c8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3c8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_pcie"; + power-domains = <&ps_atc1_common>; + status = "disabled"; + }; + + ps_atc1_cio_pcie: power-controller@3d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_cio_pcie"; + power-domains = <&ps_atc1_cio>; + status = "disabled"; + }; + + ps_atc1_cio_usb: power-controller@3d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_cio_usb"; + power-domains = <&ps_atc1_cio>; + status = "disabled"; + }; + + ps_atc2_cio: power-controller@3e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_cio"; + power-domains = <&ps_atc2_common>; + status = "disabled"; + }; + + ps_atc2_pcie: power-controller@3f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_pcie"; + power-domains = <&ps_atc2_common>; + status = "disabled"; + }; + + ps_atc2_cio_pcie: power-controller@3f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x3f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_cio_pcie"; + power-domains = <&ps_atc2_cio>; + status = "disabled"; + }; + + ps_atc2_cio_usb: power-controller@400 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x400 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_cio_usb"; + power-domains = <&ps_atc2_cio>; + status = "disabled"; + }; + + ps_atc3_cio: power-controller@420 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x420 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_cio"; + power-domains = <&ps_atc3_common>; + status = "disabled"; + }; + + ps_atc3_pcie: power-controller@428 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x428 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_pcie"; + power-domains = <&ps_atc3_common>; + status = "disabled"; + }; + + ps_atc3_cio_pcie: power-controller@430 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x430 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_cio_pcie"; + power-domains = <&ps_atc3_cio>; + status = "disabled"; + }; + + ps_atc3_cio_usb: power-controller@438 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x438 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_cio_usb"; + power-domains = <&ps_atc3_cio>; + status = "disabled"; + }; + + ps_sbr: power-controller@448 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x448 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "sbr"; + power-domains = <&ps_fab5_soc>; + status = "disabled"; + }; + + ps_gpio: power-controller@450 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x450 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpio"; + power-domains = <&ps_sbr>; + status = "disabled"; + }; + + ps_msg: power-controller@458 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x458 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "msg"; + power-domains = <&ps_sbr>; + status = "disabled"; + }; + + ps_ap_tmm: power-controller@468 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x468 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "ap_tmm"; + power-domains = <&ps_sbr>; + status = "disabled"; + }; + + ps_dispext1_sys: power-controller@490 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x490 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_sys"; + power-domains = <&ps_fab7_soc>; + status = "disabled"; + }; + + ps_dispext1_fe: power-controller@498 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x498 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_fe"; + power-domains = <&ps_dispext1_sys>; + status = "disabled"; + }; + + ps_dispext1_cpu: power-controller@4a0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_cpu"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_dbe: power-controller@4a8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4a8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_dbe"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dpext1: power-controller@4b0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4b0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpext1"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_gp0: power-controller@4b8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4b8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_gp0"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_gp1: power-controller@4c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_gp1"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_gpl: power-controller@4c8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4c8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_gpl"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_ppp: power-controller@4d0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4d0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_ppp"; + power-domains = <&ps_dispext1_fe>; + status = "disabled"; + }; + + ps_dispext1_dsc: power-controller@4d8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4d8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_dsc"; + power-domains = <&ps_dispext1_dbe>; + status = "disabled"; + }; + + ps_dispext2_sys: power-controller@4e0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_sys"; + power-domains = <&ps_fab7_soc>; + status = "disabled"; + }; + + ps_dispext2_fe: power-controller@4e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4e8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_fe"; + power-domains = <&ps_dispext2_sys>; + status = "disabled"; + }; + + ps_dispext2_cpu: power-controller@4f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4f0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_cpu"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_dbe: power-controller@4f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x4f8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_dbe"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dpext2: power-controller@500 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x500 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dpext2"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_gp0: power-controller@508 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x508 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_gp0"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_gp1: power-controller@510 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x510 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_gp1"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_gpl: power-controller@518 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x518 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_gpl"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_ppp: power-controller@520 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x520 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_ppp"; + power-domains = <&ps_dispext2_fe>; + status = "disabled"; + }; + + ps_dispext2_dsc: power-controller@528 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x528 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext2_dsc"; + power-domains = <&ps_dispext2_dbe>; + status = "disabled"; + }; +}; + +&pmgr_mini { + ps_debug_gated: power-controller@0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "debug_gated"; + status = "disabled"; + }; + + ps_nub_spmi_ahb: power-controller@58 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x58 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_ahb"; + status = "disabled"; + }; + + ps_nub_spmi0: power-controller@60 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi0"; + power-domains = <&ps_nub_spmi_ahb>; + status = "disabled"; + }; + + ps_nub_spmi_a2: power-controller@78 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x78 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_a2"; + status = "disabled"; + }; + + ps_nub_spi0: power-controller@80 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x80 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spi0"; + status = "disabled"; + }; + + ps_nub_aon: power-controller@88 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x88 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_aon"; + status = "disabled"; + }; + + ps_nub_ocla: power-controller@98 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x98 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_ocla"; + status = "disabled"; + }; + + ps_nub_spmi1: power-controller@c0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi1"; + power-domains = <&ps_nub_spmi_ahb>; + status = "disabled"; + }; + + ps_nub_spmi2: power-controller@e8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xe8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi2"; + power-domains = <&ps_nub_spmi_ahb>; + status = "disabled"; + }; + + ps_nub_spmi3: power-controller@f0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xf0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi3"; + power-domains = <&ps_nub_spmi_ahb>; + status = "disabled"; + }; + + ps_nub_spmi4: power-controller@f8 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xf8 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi4"; + power-domains = <&ps_nub_spmi_ahb>; + status = "disabled"; + }; + + ps_nub_sram: power-controller@108 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x108 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_sram"; + power-domains = <&ps_nub_fabric>; + status = "disabled"; + }; + + ps_debug_switch: power-controller@110 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x110 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "debug_switch"; + status = "disabled"; + }; +}; + +&pmgr_gfx { + ps_gpx: power-controller@0 { + compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpx"; + status = "disabled"; + }; +}; + +/* + * Parent-domain links absent from t604x-pmgr.dtsi (matching t6040-pmgr.dtsi, + * plus ps_atc3_common_dp -> ps_atc3_phymxwrap matching ps_atc0..2_common_dp). + * Every parent referenced here is enabled whenever its child is enabled. + */ +&ps_avd_sys { + power-domains = <&ps_fab0_soc>; +}; + +&ps_atc0_common { + power-domains = <&ps_fab2_soc>; +}; + +&ps_atc1_common { + power-domains = <&ps_fab2_soc>; +}; + +&ps_atc2_common { + power-domains = <&ps_fab2_soc>; +}; + +&ps_atc3_common { + power-domains = <&ps_fab2_soc>; +}; + +&ps_atc3_common_dp { + power-domains = <&ps_atc3_phymxwrap>; +}; + +&ps_ane_sys { + power-domains = <&ps_fab5_soc>, <&ps_fab4_soc>; +}; + +&ps_pmp { + power-domains = <&ps_pms>; +}; + +&ps_pms_sram { + power-domains = <&ps_pms>; +}; + +&ps_jpg { + power-domains = <&ps_fab4_soc>; +}; + +&ps_venc0_sys { + power-domains = <&ps_fab0_soc>; +}; + +&ps_venc1_sys { + power-domains = <&ps_fab0_soc>; +}; diff --git a/arch/arm64/boot/dts/apple/t6041.dtsi b/arch/arm64/boot/dts/apple/t6041.dtsi index 36e3db2718a98..a4dfb2d600c9f 100644 --- a/arch/arm64/boot/dts/apple/t6041.dtsi +++ b/arch/arm64/boot/dts/apple/t6041.dtsi @@ -486,6 +486,185 @@ #address-cells = <0>; status = "disabled"; }; + + pmgr_disp: power-management@502290000 { + compatible = "apple,t6041-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + reg = <0x5 0x02290000 0x0 0x4000>; + #address-cells = <1>; + #size-cells = <1>; + }; + + /* + * Suspend-to-RAM at EL2 through aura's S2R mailbox; without the mailbox + * it stays out. Stays disabled at the SoC level so boards without + * qualified deep sleep (such as J575c) remain on s2idle; qualified board + * trees wire apple,apcie and apple,atc-phys and enable it. + */ + t6041_sleep: sleep-controller@508304000 { + compatible = "apple,t6041-sleep"; + reg = <0x5 0x08304000 0x0 0x4000>, + <0x5 0x02820000 0x0 0x4000>, + <0x5 0x0282c000 0x0 0x4000>, + <0x5 0x02888000 0x0 0x4000>, + <0x5 0x0836c000 0x0 0x4000>, + <0x5 0x08330000 0x0 0x4000>, + <0x5 0x08904000 0x0 0x4>, + <0x5 0x00038000 0x0 0x4000>, + <0x5 0x029dc000 0x0 0x880>, + <0x5 0x022d0000 0x0 0x880>, + <0x5 0x04800000 0x0 0xb0000>, + <0x5 0x003c0000 0x0 0x20000>, + <0x5 0x0020c000 0x0 0x800>, + <0x5 0x08004000 0x0 0x58>, + <0x2 0x20000000 0x0 0x200000>, + <0x2 0x22000000 0x0 0x200000>, + <0x2 0x24000000 0x0 0x200000>, + <0x2 0x26000000 0x0 0x200000>, + <0x2 0x28000000 0x0 0x200000>, + <0x2 0x2a000000 0x0 0x200000>, + <0x2 0x2c000000 0x0 0x200000>, + <0x2 0x2e000000 0x0 0x200000>, + <0x2 0x20200000 0x0 0x601000>, + <0x2 0x22200000 0x0 0x601000>, + <0x2 0x24200000 0x0 0x601000>, + <0x2 0x26200000 0x0 0x601000>, + <0x2 0x28200000 0x0 0x601000>, + <0x2 0x2a200000 0x0 0x601000>, + <0x2 0x2c200000 0x0 0x601000>, + <0x2 0x2e200000 0x0 0x601000>, + <0x4 0x03000100 0x0 0x10>, + <0x3 0xa3000100 0x0 0x10>, + <0x6 0x03000100 0x0 0x10>, + <0x6 0x07000100 0x0 0x10>, + <0x3 0x07000100 0x0 0x10>, + <0x4 0x0b000100 0x0 0x10>, + <0x2 0x80000100 0x0 0x10>, + <0x2 0x82000100 0x0 0x10>, + <0x2 0x84000100 0x0 0x10>, + <0x4 0x86000100 0x0 0x10>; + reg-names = "ps-aop", + "cluster", "pwrgate", "cpu-start", "wdt", + "aon-misc", "commit", "clk-mux", "ka-pmgr", + "ka-east", "pmc", "ptd", "perf", "wake", + "amcc0", "amcc1", "amcc2", "amcc3", + "amcc4", "amcc5", "amcc6", "amcc7", + "dcs0", "dcs1", "dcs2", "dcs3", + "dcs4", "dcs5", "dcs6", "dcs7", + "axi2af-disp", "axi2af-dispext0", + "axi2af-dispext1", "axi2af-dispext2", + "axi2af-dispext3", "axi2af-ans", + "axi2af-avd", "axi2af-venc0", + "axi2af-venc1", "axi2af-jpg"; + apple,pinctrl = <&pinctrl>; + apple,pinctrl-skip-pins = <190 191 192>; + apple,spmi-buses = <&nub_spmi0>, <&nub_spmi_a0>; + /* ADT ap-wake-sources unmasked across S2R */ + apple,wake-enable = <13 15 25 27 28 41 44 48 50 51 52 53 55 + 101 106 126 127 128 129 130 131 132 133 + 155 167>; + apple,sleep-off-domains = <&ps_venc1_me1>, <&ps_venc0_me1>, <&ps_venc1_pipe5>, + <&ps_venc1_pipe4>, <&ps_venc1_me0>, <&ps_venc0_pipe5>, + <&ps_venc0_pipe4>, <&ps_venc0_me0>, <&ps_apcie_phy_sw>, + <&ps_ane_base>, <&ps_venc1_dma>, <&ps_venc0_dma>, + <&ps_scodec_streaming>, <&ps_msr1_ase_core>, + <&ps_msr0_ase_core>, <&ps_apcie_sys_st1>, + <&ps_apcie_sys_st0>, <&ps_apcie_sys_gp>, <&ps_ane_td>, + <&ps_ane_mpm>, <&ps_ane_cpu>, <&ps_gfx>, <&ps_venc1_sys>, + <&ps_venc0_sys>, <&ps_spi5>, <&ps_spi4>, <&ps_spi3>, + <&ps_spi2>, <&ps_spi1>, <&ps_spi0>, <&ps_scodec>, + <&ps_rom>, <&ps_qspi>, <&ps_prores>, <&ps_pms_fpwm4>, + <&ps_pms_fpwm3>, <&ps_pms_fpwm2>, <&ps_pms_fpwm1>, + <&ps_pms_fpwm0>, <&ps_pmgr_soc_ocla>, <&ps_nub_spi0>, + <&ps_nub_ocla>, <&ps_msr1>, <&ps_msr0>, <&ps_msg>, + <&ps_jpg>, <&ps_ispsens0>, <&ps_isp_sys>, <&ps_i2c8>, + <&ps_i2c7>, <&ps_i2c6>, <&ps_i2c5>, <&ps_i2c4>, + <&ps_i2c3>, <&ps_i2c2>, <&ps_i2c1>, <&ps_i2c0>, + <&ps_fpwm2>, <&ps_fpwm1>, <&ps_fpwm0>, <&ps_dpa4>, + <&ps_dpa3>, <&ps_dpa2>, <&ps_dpa1>, <&ps_dpa0>, + <&ps_avd_sys>, <&ps_ans>, <&ps_apcie_st1>, + <&ps_apcie_st0>, <&ps_apcie_gp>, <&ps_ap_tmm>, + <&ps_ane_sys>, <&ps_afr>; + apple,atc-off-domains = <&ps_atc0_phymxwrap>, <&ps_atc1_phymxwrap>, + <&ps_atc2_phymxwrap>, <&ps_atc3_phymxwrap>, + <&ps_atc0_usb>, <&ps_atc1_usb>, + <&ps_atc2_usb>, <&ps_atc3_usb>, + <&ps_atc0_usb_aon>, <&ps_atc1_usb_aon>, + <&ps_atc2_usb_aon>, <&ps_atc3_usb_aon>, + <&ps_atc0_common_dp>, <&ps_atc1_common_dp>, + <&ps_atc2_common_dp>, <&ps_atc3_common_dp>, + <&ps_atc0_cio_usb>, <&ps_atc0_cio_pcie>, + <&ps_atc0_pcie>, <&ps_atc0_cio>, + <&ps_atc1_cio_usb>, <&ps_atc1_cio_pcie>, + <&ps_atc1_pcie>, <&ps_atc1_cio>, + <&ps_atc2_cio_usb>, <&ps_atc2_cio_pcie>, + <&ps_atc2_pcie>, <&ps_atc2_cio>, + <&ps_atc3_cio_usb>, <&ps_atc3_cio_pcie>, + <&ps_atc3_pcie>, <&ps_atc3_cio>, + <&ps_atc0_common>, <&ps_atc1_common>, + <&ps_atc2_common>, <&ps_atc3_common>; + apple,sleep-auto-domains = <&ps_fab_gw_1>, <&ps_fab_afr>, <&ps_fab4_soc>, + <&ps_amcc4>, <&ps_amcc5>, <&ps_amcc6>, <&ps_amcc7>, + <&ps_amcc12>, <&ps_amcc13>, <&ps_amcc14>, <&ps_amcc15>, + <&ps_amcc20>, <&ps_amcc21>, <&ps_amcc22>, <&ps_amcc23>, + <&ps_fab0_soc>, <&ps_amcc0>, <&ps_amcc1>, <&ps_amcc2>, + <&ps_amcc3>, <&ps_amcc8>, <&ps_amcc9>, <&ps_amcc10>, + <&ps_amcc11>, <&ps_amcc16>, <&ps_amcc17>, <&ps_amcc18>, + <&ps_amcc19>, <&ps_fab1_soc>, <&ps_fab6_soc>, + <&ps_fab7_soc>, <&ps_nub_sram>, <&ps_dcs_23>, <&ps_sep>, + <&ps_dcs_19>, <&ps_amcc24>, <&ps_amcc25>, <&ps_amcc26>, + <&ps_amcc27>, <&ps_amcc28>, <&ps_amcc29>, <&ps_amcc30>, + <&ps_amcc31>; + apple,sleep-auto-clkgate-domains = <&ps_nub_spmi_a0>, <&ps_nub_spmi_a1>, + <&ps_nub_spmi_a2>, <&ps_fab3_soc>, <&ps_pmc>, + <&ps_nub_spmi0>, <&ps_nub_spmi1>, + <&ps_nub_spmi2>, <&ps_nub_spmi3>, + <&ps_nub_spmi4>, <&ps_dcs_04>, <&ps_dcs_06>, + <&ps_dcs_07>, <&ps_dcs_12>, <&ps_dcs_13>, + <&ps_dcs_14>, <&ps_dcs_15>, <&ps_dcs_20>, + <&ps_dcs_21>, <&ps_dcs_22>, <&ps_dcs_00>, + <&ps_dcs_01>, <&ps_dcs_02>, <&ps_dcs_03>, + <&ps_dcs_08>, <&ps_dcs_09>, <&ps_dcs_10>, + <&ps_dcs_16>, <&ps_dcs_17>, <&ps_dcs_18>, + <&ps_dcs_24>, <&ps_dcs_25>, <&ps_dcs_26>, + <&ps_dcs_27>, <&ps_dcs_28>, <&ps_dcs_29>, + <&ps_dcs_30>, <&ps_dcs_31>; + apple,sleep-auto-active-domains = <&ps_gpx>, <&ps_pms>, <&ps_afi>, <&ps_afc>, + <&ps_fab_gw_0>, <&ps_debug_gated>, <&ps_nub_aon>, + <&ps_nub_fabric>, <&ps_debug_switch>, + <&ps_fab2_soc>, <&ps_pmp>, <&ps_pms_sram>, + <&ps_fab5_soc>, <&ps_dcs_05>, <&ps_dcs_11>, + <&ps_sbr>; + apple,sleep-keep-on-domains = <&ps_dwi>, <&ps_nub_spmi_ahb>, <&ps_nub_gpio>, + <&ps_aic>, <&ps_pms_c1ppt>, <&ps_soc_dpe>, <&ps_sio>, + <&ps_sio_cpu>, <&ps_spi_p>, <&ps_uart_p>, <&ps_dpa_p>, + <&ps_aes>, <&ps_gpio>, <&ps_uart_n>, <&ps_uart0>, + <&ps_uart1>, <&ps_uart2>, <&ps_uart3>, <&ps_uart4>, + <&ps_uart5>, <&ps_uart6>; + apple,cpu-domains = <&ps_ecpu_0>, <&ps_ecpu_1>, <&ps_ecpu_2>, <&ps_ecpu_3>, + <&ps_pcpu0_0>, <&ps_pcpu0_1>, <&ps_pcpu0_2>, <&ps_pcpu0_3>, + <&ps_pcpu0_4>, <&ps_pcpu0_5>, <&ps_pcpu1_0>, <&ps_pcpu1_1>, + <&ps_pcpu1_2>, <&ps_pcpu1_3>, <&ps_pcpu1_4>, <&ps_pcpu1_5>; + apple,cpm-domains = <&ps_ecpm>, <&ps_pcpm0>, <&ps_pcpm1>; + apple,sep-domain = <&ps_sep>; + apple,spmi-a0-domain = <&ps_nub_spmi_a0>; + apple,atc-common-domains = <&ps_atc0_common>, <&ps_atc1_common>, <&ps_atc2_common>, + <&ps_atc3_common>; + apple,atc-fabric-domain = <&ps_fab2_soc>; + apple,atc-afi-domain = <&ps_afi>; + apple,apcie-domains = <&ps_ans>, <&ps_apcie_gp>, <&ps_apcie_sys_gp>, + <&ps_apcie_st0>, <&ps_apcie_sys_st0>, <&ps_apcie_st1>, + <&ps_apcie_sys_st1>, <&ps_apcie_phy_sw>; + apple,commit-sio-domains = <&ps_sio>, <&ps_sio_cpu>; + apple,commit-periph-domains = <&ps_i2c6>, <&ps_i2c3>, <&ps_i2c2>, <&ps_i2c1>, + <&ps_spi2>; + apple,axi2af-domains = <&ps_atc0_common>, <&ps_atc1_common>, <&ps_atc2_common>, + <&ps_atc3_common>, <&ps_disp_sys>, <&ps_dispext0_sys>, + <&ps_dispext1_sys>, <&ps_dispext2_sys>, <&ps_dispext3_sys>, + <&ps_ans>, <&ps_avd_sys>, <&ps_venc0_sys>, <&ps_venc1_sys>, + <&ps_jpg>, <&ps_apcie_sys_gp>; + apple,full-part-detect-domains = <&ps_amcc24>, <&ps_amcc28>; + status = "disabled"; + }; }; &pmgr { @@ -578,6 +757,20 @@ opp-microwatt = <531000>; }; +/* + * What the SEP's DART gets around a sleep, as offset and value: the writes T8140's has + * (t8140.dtsi), which the J616C has slept with. The SEP driver saves the DART with them + * before it tells the enclave to sleep at suspend. + */ +&sep_dart { + apple,sleep-prepare = <0x80 0xa102>, <0x704 0xffffffff>; + apple,sleep-restore = <0x210 0x0>, <0x20c 0x800005f5>, + <0x220 0xf0f0f>, <0x224 0x80808>, + <0x300 0x1>, <0x318 0x1>; + apple,sleep-restore-late = <0x80 0x8000>, <0x228 0x3f3f3f3f>, + <0x22c 0x1010101>; +}; + /* * The ISP DART's address filter, from the full-die J616c ADT's dart-isp0 * dapf-instance-0 (its sixth reg window), in the ADT's order: the @@ -622,6 +815,7 @@ #power-domain-cells = <0>; #reset-cells = <0>; label = "venc1_sys"; + power-domains = <&ps_fab0_soc>; status = "disabled"; }; @@ -721,21 +915,11 @@ /* * First ProRes engine (ADT /arm-io/apr0) and its DART, from the J616c ADT. - * apr0 sits in the SCODEC block (PMGR bank 0 / pmgr_aux: FAB1_SOC 0x2d0, - * SCODEC 0x328, SCODEC_STREAMING 0x330) with core, wrapper and aux windows. + * apr0 sits in the SCODEC block (PMGR bank 0 / pmgr_aux: FAB1_SOC 0x2d0 in + * t6041-pmgr.dtsi, SCODEC 0x328, SCODEC_STREAMING 0x330) with core, wrapper + * and aux windows. */ &pmgr_aux { - ps_fab1_soc: power-controller@2d0 { - compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; - reg = <0x2d0 4>; - #power-domain-cells = <0>; - #reset-cells = <0>; - label = "fab1_soc"; - power-domains = <&ps_afi>; - apple,always-on; - status = "disabled"; - }; - ps_scodec: power-controller@328 { compatible = "apple,t6041-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; reg = <0x328 4>; @@ -826,3 +1010,6 @@ &ave { status = "okay"; }; + +#include "t6041-pmgr.dtsi" +#include "t6041-sleep-pmgr.dtsi" diff --git a/drivers/bluetooth/hci_bcm4377.c b/drivers/bluetooth/hci_bcm4377.c index 7bafff5d5aedb..97fb480ed995c 100644 --- a/drivers/bluetooth/hci_bcm4377.c +++ b/drivers/bluetooth/hci_bcm4377.c @@ -5,6 +5,7 @@ * Copyright (C) The Asahi Linux Contributors */ +#include #include #include #include @@ -3218,6 +3219,19 @@ static int bcm4377_resume(struct device *dev) bcm4377->wake_armed = false; } + /* + * A real sleep took the function's power: the firmware is gone, and every resume command + * would only time out (two times 2 s inside the system resume, then the rebind anyway). + * Skip them and rebind from the work queue; probe boots the firmware from scratch. + */ + if (pm_resume_via_firmware() && !bcm4377->dma_window_base) { + bcm4377->quiesced = false; + bcm4377->resume_powered = false; + WRITE_ONCE(bcm4377->setup_retry_blocked, false); + bcm4377_queue_rebind(bcm4377, "power lost in the sleep"); + return 0; + } + if (bcm4377->quiesced) { iowrite32(BCM4377_BAR0_SLEEP_CONTROL_UNQUIESCE, bcm4377->bar0 + BCM4377_BAR0_SLEEP_CONTROL); diff --git a/drivers/dma/apple-sio-t6041-test.c b/drivers/dma/apple-sio-t6041-test.c index d5d13f609d7b0..12adc5349637c 100644 --- a/drivers/dma/apple-sio-t6041-test.c +++ b/drivers/dma/apple-sio-t6041-test.c @@ -265,6 +265,7 @@ static void sio_t6041_match_test(struct kunit *test) KUNIT_EXPECT_PTR_EQ(test, sio_hw_t8140.arrays, &sio_t6041_arrays); KUNIT_EXPECT_TRUE(test, sio_hw_t8140.check_boot_tables == sio_t6041_check_boot_tables); KUNIT_EXPECT_EQ(test, sio_hw_t6041.protocol, 10U); + KUNIT_EXPECT_TRUE(test, sio_hw_t6041.stop_at_commit); KUNIT_EXPECT_TRUE(test, sio_hw_t6041.clear_period_desc); KUNIT_EXPECT_PTR_EQ(test, sio_hw_t6041.arrays, &sio_t6041_arrays); /* Protocol 10 alone is T6030's too, which keeps its own contract. */ diff --git a/drivers/dma/apple-sio.c b/drivers/dma/apple-sio.c index c953e60293b8c..0f54aad81b97c 100644 --- a/drivers/dma/apple-sio.c +++ b/drivers/dma/apple-sio.c @@ -656,6 +656,7 @@ static const struct sio_hw_data sio_hw_t6030 = { * the 5 of the host's mailbox call timeout is not part of the record. */ static const struct sio_hw_data sio_hw_t6041 = { + .stop_at_commit = true, .protocol = 10, .fifo_threshold = 0x600, .cfg_word4 = 0x800, diff --git a/drivers/gpu/drm/apple/apple_drv.c b/drivers/gpu/drm/apple/apple_drv.c index 17d1416d636d2..58957e679b392 100644 --- a/drivers/gpu/drm/apple/apple_drv.c +++ b/drivers/gpu/drm/apple/apple_drv.c @@ -2282,10 +2282,23 @@ static int apple_platform_suspend(struct device *dev) if (apple && apple->dark_held) return 0; + if (pm_suspend_via_firmware()) { + int ret = dcp_t6041_s2r_all(false); + + if (ret) + return ret; + } + if (apple && !apple->aborted) { apple->s2r_skipped = apple_drm_firmware_stopped(apple); - if (!apple->s2r_skipped) - return drm_mode_config_helper_suspend(&apple->drm); + if (!apple->s2r_skipped) { + int ret = drm_mode_config_helper_suspend(&apple->drm); + + if (ret) { + dcp_t6041_s2r_all(true); + return ret; + } + } } return 0; @@ -2333,6 +2346,10 @@ static int apple_platform_resume(struct device *dev) { struct apple_drm_private *apple = dev_get_drvdata(dev); + /* Nothing if this suspend never took the display down. */ + if (dcp_t6041_s2r_all(true)) + dev_err(dev, "T6041 S2R display resume failed\n"); + if (!apple || apple->aborted || apple->s2r_skipped) return 0; diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 8d18fa7694944..cb77aa8eabd5a 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -253,6 +253,43 @@ struct dcp_s2r_layout { bool pmc_dcp; }; +/* + * One display power chain parsed from a child node of + * apple,t6041-display-power. domains[] is ordered sys, fe, cpu, then child + * sub-domains (parent-before-child; powered off in reverse). + */ +struct dcp_t6041_chain { + const char *name; + u32 reg; + bool is_main; + void __iomem *gapf; + void __iomem *pg_a; + void __iomem *pg_b; + void __iomem *fabric; + void __iomem **domains; + u32 *child_saved; + unsigned int num_domains; +}; + +/* + * Mapped register windows and display power chains from apple,display-power + * (apple,t6041-display-power) for host-driven T6041 suspend-to-RAM; mapped + * once at probe. + */ +struct dcp_t6041_power { + void __iomem *pmc_dcp; + void __iomem *pwrgate; + void __iomem *pwrgate_aux; + void __iomem *gapf; + void __iomem *axi2af; + struct dcp_t6041_chain *chains; + unsigned int num_chains; + struct dcp_t6041_chain *main_chain; + bool child_valid; + u32 boot_ps[3]; + bool boot_ps_valid; +}; + /* * Identity of a fixed internal panel, for the EDID published on its * connector. Any processor with an internal panel allocates it; the boot @@ -606,6 +643,8 @@ struct apple_dcp { */ bool ext_failsafe; bool ext_dead; + /* T6041 S2R: this external DCP's firmware stop ran in a sleep of this boot */ + bool t6041_ext_seen; /* * A T6030 external processor in the main DRM device: the kernel starts * its firmware on first use, its modes come from the attached display. @@ -747,6 +786,8 @@ struct apple_dcp { struct dcp_channel ch_cmd, ch_oobcmd; struct dcp_channel ch_cb, ch_oobcb, ch_async, ch_oobasync; + /* In-flight dcp_ack() mailbox sends not yet queued to RTKit. */ + atomic_t pending_acks; /* iomfb EP callback handlers */ const iomfb_cb_handler *cb_handlers; @@ -931,6 +972,9 @@ struct apple_dcp { bool s2r_power_oob; u8 s2r_step; struct completion s2r_dart_done; + struct completion s2r_hpd_done; + bool sleep_host_stop; + struct dcp_t6041_power t6041_power; struct device *s2r_disp_dart; struct device *s2r_dcp_dart; diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index 6f3a8604278dd..4e48c4574624f 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -7469,6 +7470,347 @@ static void dcp_t8132_ext_routes(struct apple_dcp *dcp) static int dcp_s2r_pm_register(struct apple_dcp *dcp); +/* A DCP node with apple,sleep-host-stop: the SoC's sleep needs the display stopped from here. */ +static bool dcp_sleep_host_stop; +static bool dcp_sleep_host_stop_missing; +static struct apple_dcp *dcp_t6041_host; + +static void dcp_t6041_host_release(void *data) +{ + struct apple_dcp *dcp = data; + + if (READ_ONCE(dcp_t6041_host) == dcp) { + WRITE_ONCE(dcp_sleep_host_stop, false); + WRITE_ONCE(dcp_t6041_host, NULL); + } +} + +#define DCP_T6041_MAX_PMGR_MAPS 16 + +struct dcp_t6041_pmgr_map { + struct device_node *np; + void __iomem *base; + resource_size_t size; +}; + +struct dcp_t6041_pmgr_cache { + struct dcp_t6041_pmgr_map maps[DCP_T6041_MAX_PMGR_MAPS]; + unsigned int count; +}; + +static void dcp_t6041_iounmap(void *base) +{ + iounmap((__force void __iomem *)base); +} + +static void dcp_t6041_pmgr_cache_put(struct dcp_t6041_pmgr_cache *cache) +{ + unsigned int i; + + for (i = 0; i < cache->count; i++) + of_node_put(cache->maps[i].np); +} + +static void __iomem *dcp_t6041_map_reg(struct device *dev, struct device_node *np, + const char *name, resource_size_t min_size, + resource_size_t *out_size) +{ + struct resource res; + resource_size_t size; + void __iomem *base; + int index; + + index = of_property_match_string(np, "reg-names", name); + if (index < 0) + return IOMEM_ERR_PTR(index); + if (of_address_to_resource(np, index, &res)) + return IOMEM_ERR_PTR(-EINVAL); + size = resource_size(&res); + if (size < min_size) { + dev_err(dev, "%pOF reg '%s' too small (%pa < %pa)\n", + np, name, &size, &min_size); + return IOMEM_ERR_PTR(-EINVAL); + } + + /* Shared with the PMGR, PMC and fabric drivers, so not claimed. */ + base = devm_ioremap(dev, res.start, size); + if (!base) + return IOMEM_ERR_PTR(-ENOMEM); + if (out_size) + *out_size = size; + + return base; +} + +static void __iomem *dcp_t6041_map_ps_node(struct device *dev, + struct dcp_t6041_pmgr_cache *cache, + struct device_node *ps_np) +{ + struct device_node *pmgr_np __free(device_node) = of_get_parent(ps_np); + struct dcp_t6041_pmgr_map *map = NULL; + struct resource res; + resource_size_t size; + void __iomem *base; + unsigned int i; + u32 off; + int ret; + + if (!pmgr_np) { + dev_err(dev, "%pOF has no parent pmgr node\n", ps_np); + return IOMEM_ERR_PTR(-EINVAL); + } + if (of_property_read_u32_index(ps_np, "reg", 0, &off)) { + dev_err(dev, "%pOF missing reg offset\n", ps_np); + return IOMEM_ERR_PTR(-EINVAL); + } + + for (i = 0; i < cache->count; i++) { + if (cache->maps[i].np == pmgr_np) { + map = &cache->maps[i]; + break; + } + } + + if (!map) { + if (cache->count >= ARRAY_SIZE(cache->maps)) { + dev_err(dev, "too many distinct pmgr parents for %pOF\n", ps_np); + return IOMEM_ERR_PTR(-ENOSPC); + } + if (of_address_to_resource(pmgr_np, 0, &res)) { + dev_err(dev, "%pOF missing parent pmgr reg\n", pmgr_np); + return IOMEM_ERR_PTR(-EINVAL); + } + size = resource_size(&res); + /* Shared with the PMGR driver, so mapped via of_iomap without claiming. */ + base = of_iomap(pmgr_np, 0); + if (!base) + return IOMEM_ERR_PTR(-ENOMEM); + ret = devm_add_action_or_reset(dev, dcp_t6041_iounmap, (__force void *)base); + if (ret) + return IOMEM_ERR_PTR(ret); + + map = &cache->maps[cache->count++]; + map->np = of_node_get(pmgr_np); + map->base = base; + map->size = size; + } + + if ((off & 3) || off > map->size || map->size - off < sizeof(u32)) { + dev_err(dev, "%pOF reg offset %#x out of bounds for %pOF (%pa)\n", + ps_np, off, pmgr_np, &map->size); + return IOMEM_ERR_PTR(-EINVAL); + } + + return map->base + off; +} + +static int dcp_t6041_parse_chain(struct device *dev, struct dcp_t6041_power *pwr, + struct dcp_t6041_pmgr_cache *cache, + struct device_node *child, + resource_size_t gapf_size, + resource_size_t pg_size, + resource_size_t pg_aux_size, + struct dcp_t6041_chain *chain) +{ + struct of_phandle_args args; + resource_size_t pg_lim; + void __iomem *pg_base; + u32 gapf_off, pg_off[2]; + bool pg_aux; + int count, i; + + if (of_property_read_u32(child, "reg", &chain->reg)) { + dev_err(dev, "%pOF missing reg\n", child); + return -EINVAL; + } + if (of_property_read_string(child, "label", &chain->name)) + chain->name = child->name; + + chain->is_main = of_property_read_bool(child, "apple,main-chain"); + pg_aux = of_property_read_bool(child, "apple,pwrgate-aux"); + + if (of_property_read_u32(child, "apple,gapf-offset", &gapf_off) || + (gapf_off & 3) || gapf_off > gapf_size || gapf_size - gapf_off < sizeof(u32)) { + dev_err(dev, "%pOF invalid apple,gapf-offset\n", child); + return -EINVAL; + } + chain->gapf = pwr->gapf + gapf_off; + + pg_base = pg_aux ? pwr->pwrgate_aux : pwr->pwrgate; + pg_lim = pg_aux ? pg_aux_size : pg_size; + if (of_property_read_u32_array(child, "apple,pwrgate-offsets", pg_off, 2) || + (pg_off[0] & 3) || pg_off[0] > pg_lim || pg_lim - pg_off[0] < sizeof(u32) || + (pg_off[1] & 3) || pg_off[1] > pg_lim || pg_lim - pg_off[1] < sizeof(u32)) { + dev_err(dev, "%pOF invalid apple,pwrgate-offsets\n", child); + return -EINVAL; + } + chain->pg_a = pg_base + pg_off[0]; + chain->pg_b = pg_base + pg_off[1]; + + if (of_property_present(child, "apple,fabric-domain")) { + struct device_node *fab_np __free(device_node) = + of_parse_phandle(child, "apple,fabric-domain", 0); + + if (!fab_np) { + dev_err(dev, "%pOF invalid apple,fabric-domain\n", child); + return -EINVAL; + } + chain->fabric = dcp_t6041_map_ps_node(dev, cache, fab_np); + if (IS_ERR(chain->fabric)) + return PTR_ERR(chain->fabric); + } else if (chain->is_main) { + dev_err(dev, "%pOF main chain missing apple,fabric-domain\n", child); + return -EINVAL; + } + + count = of_count_phandle_with_args(child, "power-domains", "#power-domain-cells"); + if (count < 3) { + dev_err(dev, "%pOF needs at least 3 power-domains (got %d)\n", child, count); + return -EINVAL; + } + + chain->domains = devm_kcalloc(dev, count, sizeof(*chain->domains), GFP_KERNEL); + if (!chain->domains) + return -ENOMEM; + chain->num_domains = count; + + for (i = 0; i < count; i++) { + int ret = of_parse_phandle_with_args(child, "power-domains", + "#power-domain-cells", i, &args); + void __iomem *reg; + + if (ret) { + dev_err(dev, "%pOF power-domains[%d] parse failed: %d\n", child, i, ret); + return ret; + } + reg = dcp_t6041_map_ps_node(dev, cache, args.np); + of_node_put(args.np); + if (IS_ERR(reg)) + return PTR_ERR(reg); + chain->domains[i] = reg; + } + + if (chain->is_main && count > 3) { + chain->child_saved = devm_kcalloc(dev, count - 3, sizeof(*chain->child_saved), + GFP_KERNEL); + if (!chain->child_saved) + return -ENOMEM; + } + + return 0; +} + +static int dcp_t6041_map_power(struct apple_dcp *dcp) +{ + struct device *dev = dcp->dev; + struct device_node *np __free(device_node) = + of_parse_phandle(dev->of_node, "apple,display-power", 0); + struct dcp_t6041_power *pwr = &dcp->t6041_power; + struct dcp_t6041_pmgr_cache cache = {}; + resource_size_t pg_size = 0, pg_aux_size = 0, gapf_size = 0; + const struct { + const char *name; + void __iomem **dst; + resource_size_t min_size; + resource_size_t *out_size; + } regs[] = { + { "pmc-dcp", &pwr->pmc_dcp, 0x8, NULL }, + { "pwrgate", &pwr->pwrgate, 0x4, &pg_size }, + { "pwrgate-aux", &pwr->pwrgate_aux, 0x4, &pg_aux_size }, + { "gapf", &pwr->gapf, 0x4, &gapf_size }, + { "axi2af", &pwr->axi2af, 0xc, NULL }, + }; + unsigned int nchains = 0, idx = 0, main_count = 0, i, j; + int ret; + + if (!np) + return -ENODEV; + if (!of_device_is_compatible(np, "apple,t6041-display-power")) + return -EINVAL; + + for (i = 0; i < ARRAY_SIZE(regs); i++) { + void __iomem *base = dcp_t6041_map_reg(dev, np, regs[i].name, + regs[i].min_size, regs[i].out_size); + + if (IS_ERR(base)) { + dev_err(dev, "apple,display-power reg '%s' failed: %ld\n", + regs[i].name, PTR_ERR(base)); + ret = PTR_ERR(base); + goto err; + } + *regs[i].dst = base; + } + + for_each_available_child_of_node_scoped(np, child) { + if (!of_node_name_eq(child, "chain")) + continue; + nchains++; + } + if (!nchains) { + dev_err(dev, "%pOF has no chain child nodes\n", np); + ret = -EINVAL; + goto err; + } + + pwr->chains = devm_kcalloc(dev, nchains, sizeof(*pwr->chains), GFP_KERNEL); + if (!pwr->chains) { + ret = -ENOMEM; + goto err; + } + pwr->num_chains = nchains; + + for_each_available_child_of_node_scoped(np, child) { + if (!of_node_name_eq(child, "chain")) + continue; + ret = dcp_t6041_parse_chain(dev, pwr, &cache, child, + gapf_size, pg_size, pg_aux_size, + &pwr->chains[idx]); + if (ret) + goto err; + if (pwr->chains[idx].is_main) + main_count++; + idx++; + } + + if (main_count != 1) { + dev_err(dev, "%pOF expected exactly 1 apple,main-chain, got %u\n", + np, main_count); + ret = -EINVAL; + goto err; + } + + /* Order chains by ascending reg address so lowering order matches DT. */ + for (i = 1; i < nchains; i++) { + struct dcp_t6041_chain key = pwr->chains[i]; + + for (j = i; j > 0 && pwr->chains[j - 1].reg > key.reg; j--) + pwr->chains[j] = pwr->chains[j - 1]; + pwr->chains[j] = key; + } + for (i = 1; i < nchains; i++) { + if (pwr->chains[i].reg == pwr->chains[i - 1].reg) { + dev_err(dev, "%pOF duplicate chain reg %u\n", + np, pwr->chains[i].reg); + ret = -EINVAL; + goto err; + } + } + for (i = 0; i < nchains; i++) { + if (pwr->chains[i].is_main) { + pwr->main_chain = &pwr->chains[i]; + break; + } + } + + dcp_t6041_pmgr_cache_put(&cache); + return 0; + +err: + dcp_t6041_pmgr_cache_put(&cache); + memset(pwr, 0, sizeof(*pwr)); + return ret; +} + static int dcp_platform_probe_pipe(struct platform_device *pdev) { const struct apple_dcp_hw_data *hw = of_device_get_match_data(&pdev->dev); @@ -7754,9 +8096,27 @@ static int dcp_platform_probe_pipe(struct platform_device *pdev) of_property_read_u32(dev->of_node, "apple,dcp-endpoint", &dcp->peer_endpoint); if (of_property_read_bool(dev->of_node, "apple,typec-hybrid-first")) dcp_typec_hybrid_first_dt(); + if (of_property_read_bool(dev->of_node, "apple,sleep-host-stop")) { + ret = dcp_t6041_map_power(dcp); + if (ret) { + dev_err(dev, + "apple,display-power unusable (%d): host-driven sleep disabled\n", + ret); + WRITE_ONCE(dcp_sleep_host_stop_missing, true); + } else { + dcp->sleep_host_stop = true; + WRITE_ONCE(dcp_t6041_host, dcp); + WRITE_ONCE(dcp_sleep_host_stop, true); + ret = devm_add_action_or_reset(dev, dcp_t6041_host_release, dcp); + if (ret) + return ret; + } + } of_property_read_u32(dev->of_node, "apple,dptx-phy", &dcp->dptx_phy); of_property_read_u32(dev->of_node, "apple,dptx-die", &dcp->dptx_die); dcp->fixed_dptx_phy = dcp->dptx_phy; + init_completion(&dcp->s2r_dart_done); + init_completion(&dcp->s2r_hpd_done); init_completion(&dcp->typec_iomfb_hpd_ready); INIT_DELAYED_WORK(&dcp->typec_reconnect_wq, dcp_typec_reconnect_work); @@ -8733,6 +9093,10 @@ static const struct dcp_s2r_layout *dcp_s2r_layout(struct apple_dcp *dcp) return &dcp_s2r_t8142_ext[dcp->index - 1]; return dcp->hw.s2r_layout ?: &dcp_s2r_t8140; } + +/* T6041's display stop and restart for its own sleep driver, below: T8140's DART streams. */ +#define DCP_S2R_DISP_STREAMS (dcp_s2r_t8140.disp_streams) +#define DCP_S2R_DCP_STREAMS (dcp_s2r_t8140.dcp_streams) #define DCP_PS_MIN GENMASK(19, 16) static struct device *dcp_s2r_find_dart(struct device_node *np) @@ -8775,13 +9139,18 @@ static void dcp_s2r_find_darts(struct apple_dcp *dcp) void dcp_s2r_dart_power(struct apple_dcp *dcp, u32 on) { + if (dcp->fw_compat == DCP_FIRMWARE_V_26_6_DESKTOP) + dev_dbg(dcp->dev, "D572(%u) s2r_active=%u\n", + on, READ_ONCE(dcp->s2r_active)); + if (!READ_ONCE(dcp->s2r_active)) return; if (dcp->s2r_disp_dart) apple_dart_display_streams(dcp->s2r_disp_dart, dcp_s2r_layout(dcp)->disp_streams, on, false); - complete(&dcp->s2r_dart_done); + if (dcp->fw_compat != DCP_FIRMWARE_V_26_6_DESKTOP || !on) + complete(&dcp->s2r_dart_done); } static bool dcp_s2r_capable(struct apple_dcp *dcp) @@ -10650,6 +11019,741 @@ static struct platform_driver apple_platform_driver = { }, }; +/* + * T6041 suspend-to-RAM: each display firmware is stopped from Linux before the sleep, from the + * display subsystem's own suspend, and the internal one is restarted warm after the wake. + */ +static int dcp_stop_poller(void *data) +{ + while (!kthread_should_stop()) { + apple_rtkit_poll(data); + usleep_range(500, 1000); + } + return 0; +} + +static int dcp_t6041_recommit(struct apple_dcp *dcp); + +static int dcp_t6041_stop_one(struct device *dev, void *data) +{ + struct apple_dcp *dcp = dev_get_drvdata(dev); + bool external = *(bool *)data; + struct task_struct *poller; + bool keep_set = false; + bool powered_off = false; + bool idle_attempted = false; + bool idle; + u32 ctrl, status; + int ret; + + /* dcp->external is only set on T6030. */ + if (!dcp || IS_ERR_OR_NULL(dcp->rtk) || dcp->sleep_host_stop == external) + return 0; + /* + * An external DCP stopped for an earlier sleep stays down, with its domains forced off by + * the power word step: reading its registers again hung the second sleep of a boot (11 Nov). + */ + if (external) { + /* Also one that was never running: the power word step took its domains down too. */ + if (READ_ONCE(dcp->ext_dead) || dcp->t6041_ext_seen) + return 0; + } + if (!apple_rtkit_is_running(dcp->rtk)) { + if (external) { + dcp_s2r_find_darts(dcp); + if (dcp->s2r_disp_dart) + apple_dart_display_streams(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, false, true); + dcp->t6041_ext_seen = true; + } + dcp_s2r_put_darts(dcp); + return 0; + } + dcp_drain_for_sleep(dcp); + cancel_delayed_work_sync(&dcp->swap_watchdog_wq); + iomfb_pause_presentation(dcp, true); + iomfb_queue_settle(dcp, msecs_to_jiffies(500)); + dcp_s2r_find_darts(dcp); + if (!external) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true); + keep_set = true; + /* + * As linux#1477 dcp_t6041_s2r_stop: the pipe off through the firmware, then wait for + * its calls to settle. No av_service_disconnect: the firmware answered it with an + * unplug (HPD removed), and after the warm restart it refused every mode set with + * "HPD is 0 link_status is 0" (10 Nov). No display sleep transition after the + * power-off either. + */ + /* + * The firmware's D572(0) after the power-off says it is done with the display, and + * dcp_s2r_dart_power() turns the display DART's streams off right there, as macOS + * does. Turned off while the pipe still scanned out, they crashed the firmware + * (axi_rd_err, 11 Nov). Without D572(0) abort sleep instead of tearing down domains + * while scanning out. + */ + reinit_completion(&dcp->s2r_dart_done); + WRITE_ONCE(dcp->s2r_active, true); + _dcp_poweroff(dcp); + powered_off = true; + if (!wait_for_completion_timeout(&dcp->s2r_dart_done, + msecs_to_jiffies(DCP_S2R_D572_TIMEOUT_MS))) { + WRITE_ONCE(dcp->s2r_active, false); + dev_err(dev, "no D572 after the power-off\n"); + ret = -ETIMEDOUT; + goto err_unwind; + } + WRITE_ONCE(dcp->s2r_active, false); + if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 200000, false, dcp)) { + dev_err(dev, "display calls still in flight after the power-off\n"); + ret = -ETIMEDOUT; + goto err_unwind; + } + } + ret = iomfb_s2r_500_v26_6_desktop(dcp); + if (ret) { + dev_err(dev, "no reply to A500: %d\n", ret); + goto err_unwind; + } + if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 100000, false, dcp)) { + dev_err(dev, "display calls still in flight after A500\n"); + ret = -ETIMEDOUT; + goto err_unwind; + } + idle_attempted = true; + ret = apple_rtkit_idle(dcp->rtk); + if (ret) { + poller = kthread_run(dcp_stop_poller, dcp->rtk, "dcpstop"); + ret = apple_rtkit_idle(dcp->rtk); + if (!IS_ERR(poller)) + kthread_stop(poller); + } + if (ret) { + dev_err(dev, "the firmware didn't go idle for the sleep: %d\n", ret); + goto err_unwind; + } + apple_rtkit_poll(dcp->rtk); + /* + * T6041 desktop firmware reaches status 0x6d (IDLE set, STOPPED clear) on + * apple_rtkit_idle(). Both AP and IOP have already acknowledged IDLE here, + * so proceed even if IDLE is late, matching apple_rtkit_sleep_idle(). + */ + ret = readl_poll_timeout(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_STATUS, status, + status & APPLE_DCP_COPROC_CPU_STATUS_IDLE, 100, 50000); + if (ret) + dev_warn(dev, "coprocessor did not set IDLE after RTKit idle: status %#x\n", + status); + /* + * QUIESCED and SLEEP after idle: T23 reached STOPPED (0x6e) only this way. Not for the + * internal DCP: linux#1477 stops it at the idle (A500, idle, mailbox off, run bit, bit 5) + * and its warm restart then works; after a shutdown ours crashed in the restart (10 Nov, + * data abort at 0xffffffff00000040 right after the first shmem_setup). + */ + if (external) { + dcp->t6041_ext_seen = true; + ret = apple_rtkit_shutdown(dcp->rtk); + if (ret) + dev_warn(dev, "external coprocessor shutdown failed: %d\n", ret); + if (readl_poll_timeout(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_STATUS, status, + (status & (APPLE_DCP_COPROC_CPU_STATUS_IDLE | + APPLE_DCP_COPROC_CPU_STATUS_STOPPED)) == + (APPLE_DCP_COPROC_CPU_STATUS_IDLE | + APPLE_DCP_COPROC_CPU_STATUS_STOPPED), 100, 50000)) + dev_warn(dev, "external coprocessor did not reach stopped: status %#x\n", + status); + } + WRITE_ONCE(dcp->crashed, true); + WRITE_ONCE(dcp->ext_dead, true); + WRITE_ONCE(dcp->s2r_fw_down, true); + apple_rtkit_mailbox_off(dcp->rtk); + dcp_s2r_cpu_stop(dcp); + ret = readl_poll_timeout(dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL, ctrl, + !(ctrl & APPLE_DCP_COPROC_CPU_CONTROL_RUN), 100, 10000); + if (ret) { + dev_err(dev, "coprocessor RUN bit did not clear: control %#x\n", ctrl); + dcp_s2r_put_darts(dcp); + return ret; + } + /* + * External display DARTs go dark for good while their block is still on: + * the power word step forces the external display domains off and nothing raises + * them, but the framebuffers are mapped through all display DARTs, so every + * later unmap would flush a DART behind a dead block (11 Nov). + * Marked dark, the flush only publishes to memory. + */ + if (external && dcp->s2r_disp_dart) + apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, + false, true); + ret = dcp_s2r_stop_streams(dcp); + dcp_s2r_put_darts(dcp); + if (ret) { + dev_err(dev, "failed to stop DCP DART streams: %d\n", ret); + return ret; + } + + return 0; + +err_unwind: + if (!external) { + if (keep_set) { + if (dcp->s2r_disp_dart) + apple_dart_display_keep(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, false); + if (dcp->s2r_dcp_dart) + apple_dart_display_keep(dcp->s2r_dcp_dart, + DCP_S2R_DCP_STREAMS, false); + } + if (powered_off && dcp->s2r_disp_dart) + apple_dart_display_streams(dcp->s2r_disp_dart, + DCP_S2R_DISP_STREAMS, true, false); + } + dcp_s2r_put_darts(dcp); + iomfb_pause_presentation(dcp, false); + if (idle_attempted) { + int ap_ret = apple_rtkit_ap_power(dcp->rtk, true); + + if (ap_ret) + dev_warn(dev, "AP on after failed stop: %d\n", ap_ret); + } + if (!external && powered_off) { + if (dcp_t6041_recommit(dcp)) + dev_err(dev, "display recovery after failed stop failed\n"); + else + dcp_backlight_s2r_restore(dcp); + } + return ret; +} + +/* + * The power words of each display CPU down, after its firmware stopped. The fabric rejects + * writes to a DCP's CPU word until bit 4 of its GAPF slice is clear: ADT + * clock-protection-slice-index, 0x100 + 0x40 * index. Then macOS's order on the Neo. + */ +static int dcp_t6041_word_try(struct device *dev, struct dcp_t6041_power *pwr, + struct dcp_t6041_chain *chain) +{ + void __iomem *gapf = chain->gapf; + void __iomem *rsys = chain->domains[0]; + void __iomem *rfe = chain->domains[1]; + void __iomem *rcpu = chain->domains[2]; + void __iomem *ra = chain->pg_a; + void __iomem *rb = chain->pg_b; + void __iomem *rfab = NULL; + unsigned int i; + u32 val, fab = 0, cur; + int ret = 0; + + val = readl(gapf); + writel(val & ~BIT(4), gapf); + if (readl_poll_timeout(gapf, cur, !(cur & BIT(4)), 10, 5000)) { + dev_err(dev, "dcp %s: GAPF write protection stayed set: %#x\n", + chain->name, cur); + return -ETIMEDOUT; + } + val = readl(rcpu); + writel(val & ~(BIT(28) | GENMASK(9, 8)), rcpu); + if (readl_poll_timeout(rcpu, cur, !(cur & BIT(28)), 10, 5000)) { + dev_err(dev, "dcp %s: CPU auto-enable did not clear: %#x\n", + chain->name, cur); + return -ETIMEDOUT; + } + val = cur; + /* + * Everything macOS's sleep check wants off under this CPU, last first: DSC, PPP, GPL, + * GP1, GP0, DPEXT, DBE. iBoot leaves them on over a DCP Linux never started. + */ + if (chain->is_main && chain->child_saved) { + for (i = 3; i < chain->num_domains; i++) + chain->child_saved[i - 3] = readl(chain->domains[i]); + pwr->child_valid = true; + } + for (i = chain->num_domains; i-- > 3; ) { + void __iomem *sub = chain->domains[i]; + + val = readl(sub); + if (val & BIT(28)) { + val &= ~(BIT(28) | GENMASK(9, 8)); + writel(val, sub); + } + writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), sub); + if (readl_poll_timeout(sub, cur, !FIELD_GET(GENMASK(7, 4), cur), + 50, 20000)) { + dev_err(dev, "dcp %s: child %u did not power off: %#x\n", + chain->name, i - 2, cur); + return -ETIMEDOUT; + } + } + val = readl(rcpu); + /* + * Two things the restart sets that boot did not have, undone before the lowering: bit 0 of + * both words of bridge 4 (boot 0x10000 / 0x101330, after a restart 0x10001 / 0x101331) and the + * display voter count at pmc-dcp (boot 0, after a restart 1). With them left, the + * second lowering of a boot ends with FE 0x200 and SYS 0x800 (bit 11) instead of 0x300 / 0x300. + */ + if (chain->is_main) { + writel(readl(pwr->axi2af + 0x4) & ~1U, pwr->axi2af + 0x4); + writel(readl(pwr->axi2af + 0x8) & ~1U, pwr->axi2af + 0x8); + writel(0, pwr->pmc_dcp); + } + if (chain->fabric) { + /* + * The internal display's SYS hangs off fab6_soc, which gates itself as soon as + * nothing under it is on. Lowered while the fabric is already going (second stop + * of a boot, the external pipes long off), SYS latches PARENT_OFF (reads 0x800, + * FE 0x200), the sleep engine waits on that bit and the chip resets. So: the + * fabric on by hand until SYS is down. + */ + rfab = chain->fabric; + fab = readl(rfab); + writel((fab & ~(BIT(28) | GENMASK(9, 8) | GENMASK(3, 0))) | 0xf, rfab); + if (readl_poll_timeout(rfab, cur, FIELD_GET(GENMASK(7, 4), cur) == 0xf, + 50, 20000)) { + dev_err(dev, "dcp %s: fabric domain not on: %#x\n", chain->name, cur); + ret = -ETIMEDOUT; + goto restore_fab; + } + } + writel(3, ra); + writel(0, rb); + writel((val & ~GENMASK(3, 0)) | GENMASK(9, 8), rcpu); + val = readl(rfe); + if (val & BIT(28)) + writel(val & ~(BIT(28) | GENMASK(9, 8)), rfe); + writel((readl(rfe) & ~GENMASK(3, 0)) | GENMASK(9, 8), rfe); + val = readl(rsys); + if (val & BIT(28)) + writel(val & ~(BIT(28) | GENMASK(9, 8)), rsys); + writel((readl(rsys) & ~GENMASK(3, 0)) | GENMASK(9, 8), rsys); + /* + * Verify CPU, FE and SYS all reach off; macOS polls up to 50 ms here. The internal + * chain must also not have latched PARENT_OFF (bit 11), see above. + */ + if (readl_poll_timeout(rcpu, cur, + !FIELD_GET(GENMASK(7, 4), cur) && + (!chain->is_main || !(cur & BIT(11))), + 50, 100000)) { + dev_err(dev, "dcp %s: cpu still %#x\n", chain->name, cur); + ret = -ETIMEDOUT; + goto restore_fab; + } + if (readl_poll_timeout(rfe, cur, + !FIELD_GET(GENMASK(7, 4), cur) && + (!chain->is_main || !(cur & BIT(11))), + 50, 100000)) { + dev_err(dev, "dcp %s: fe still %#x\n", chain->name, cur); + ret = -ETIMEDOUT; + goto restore_fab; + } + if (readl_poll_timeout(rsys, cur, + !FIELD_GET(GENMASK(7, 4), cur) && + (!chain->is_main || !(cur & BIT(11))), + 50, 100000)) { + dev_err(dev, "dcp %s: sys still %#x\n", chain->name, cur); + ret = -ETIMEDOUT; + goto restore_fab; + } +restore_fab: + if (rfab) { + /* Back to automatic, as it was; the flag bits are write-one-to-clear, left alone. */ + writel((readl(rfab) & ~(GENMASK(9, 8) | BIT(28))) | (fab & BIT(28)), rfab); + if (readl_poll_timeout(rfab, cur, (cur & BIT(28)) == (fab & BIT(28)), 10, 5000)) { + dev_err(dev, "dcp %s: fabric auto-enable did not restore: %#x\n", + chain->name, cur); + if (!ret) + ret = -ETIMEDOUT; + } + } + + return ret; +} + +/* + * After a real wake: the internal DCP back, as linux#1477 does it for the M4 Pro + * (t6040_disp_back, dcp_t6041_s2r_domains_on, dcp_t6041_s2r_resume, the warm restart and the + * mode set of dcp_hib_recommit): DISP_SYS on, the retention pair (A := 0, B := 1), DISP_FE on, + * the GAPF protection off, DISP_CPU on, its child domains as the stop found them, the PMC voter, + * both DARTs' streams, the idled firmware restarted, the pipe powered and the mode set again. + */ +static int dcp_t6041_recommit(struct apple_dcp *dcp) +{ + struct apple_crtc *acrtc = READ_ONCE(dcp->crtc); + struct drm_modeset_acquire_ctx ctx; + struct drm_atomic_commit *state; + struct drm_crtc_state *cs; + struct drm_crtc *crtc; + ktime_t start = ktime_get(); + bool idle; + int ret; + + reinit_completion(&dcp->s2r_hpd_done); + iomfb_poweron_v26_6_desktop(dcp); + if (dcp->desktop && dcp->desktop->poweron_result) { + dev_err(dcp->dev, "display power-on after the sleep failed (%u)\n", + dcp->desktop->poweron_result); + return dcp->desktop->poweron_result == 1 ? -ETIMEDOUT : -EIO; + } + if (!wait_for_completion_timeout(&dcp->s2r_hpd_done, msecs_to_jiffies(1000))) { + dev_err(dcp->dev, "no D575 hotplug %lld ms after power-on\n", + ktime_ms_delta(ktime_get(), start)); + return -ETIMEDOUT; + } + dev_dbg(dcp->dev, "D575 hotplug ready %lld ms after power-on\n", + ktime_ms_delta(ktime_get(), start)); + if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 200000, false, dcp)) { + dev_err(dcp->dev, "display calls still in flight after D575\n"); + return -ETIMEDOUT; + } + if (!acrtc) + return 0; + crtc = &acrtc->base; + DRM_MODESET_LOCK_ALL_BEGIN(crtc->dev, ctx, 0, ret); + if (!crtc->state->active) { + ret = 0; + goto unlock; + } + state = drm_atomic_commit_alloc(crtc->dev); + if (!state) { + ret = -ENOMEM; + goto unlock; + } + state->acquire_ctx = &ctx; + cs = drm_atomic_get_crtc_state(state, crtc); + if (IS_ERR(cs)) { + ret = PTR_ERR(cs); + goto put; + } + cs->mode_changed = true; + ret = drm_atomic_add_affected_connectors(state, crtc); + if (!ret) + ret = drm_atomic_add_affected_planes(state, crtc); + if (!ret) + ret = drm_atomic_commit(state); +put: + drm_atomic_commit_put(state); +unlock: + DRM_MODESET_LOCK_ALL_END(crtc->dev, ctx, ret); + return ret; +} + +/* + * The internal display's SYS, FE and CPU power words as they were before the first stop (from + * boot: SYS and FE with no flags, the CPU word 0x1000030f, automatic). The restart leaves the CPU + * word manual (0x0f0003ff) and SYS/FE with both flags, and the first display power-off after such + * a wake hung the machine (11 Nov, run 6). Captured once and put back once the display runs again. + */ +static int dcp_t6041_boot_ps_io(struct apple_dcp *dcp, bool restore) +{ + static const char *const names[3] = { "sys", "fe", "cpu" }; + struct dcp_t6041_power *pwr = &dcp->t6041_power; + const struct dcp_t6041_chain *main = pwr->main_chain; + bool idle; + u32 cur; + int i; + + if (!main || main->num_domains < 3) + return -EINVAL; + + if (!restore) { + if (pwr->boot_ps_valid) + return 0; + for (i = 0; i < 3; i++) + pwr->boot_ps[i] = readl(main->domains[i]); + pwr->boot_ps_valid = true; + return 0; + } + + if (!pwr->boot_ps_valid) + return 0; + + if (read_poll_timeout(iomfb_channels_idle, idle, idle, 1000, 200000, false, dcp)) { + dev_err(dcp->dev, "display calls still in flight before restoring boot power words\n"); + return -ETIMEDOUT; + } + for (i = 0; i < 3; i++) { + if (!pwr->boot_ps[i]) + continue; + if (readl_poll_timeout(main->domains[i], cur, + FIELD_GET(GENMASK(7, 4), cur) == 0xf && !(cur & BIT(11)), + 50, 10000)) { + dev_err(dcp->dev, "display %s power word not on before restore: %#x\n", + names[i], cur); + return -ETIMEDOUT; + } + } + for (i = 0; i < 3; i++) { + u32 want = pwr->boot_ps[i] & ~0xf0U; + + if (!pwr->boot_ps[i]) + continue; + writel(want, main->domains[i]); + if (want & BIT(28)) { + /* + * AUTO_ENABLE lets hardware drop PS_ACTUAL to 0 while the DCP CPU sits + * idle in WFI, so poll target + AUTO_ENABLE + !PARENT_OFF instead. + */ + if (readl_poll_timeout(main->domains[i], cur, + (cur & (BIT(28) | GENMASK(3, 0))) == + (want & (BIT(28) | GENMASK(3, 0))) && + !(cur & BIT(11)), 50, 10000)) { + dev_err(dcp->dev, + "display %s power word did not restore auto-enable: %#x\n", + names[i], cur); + return -ETIMEDOUT; + } + } else { + if (readl_poll_timeout(main->domains[i], cur, + FIELD_GET(GENMASK(7, 4), cur) == 0xf && + !(cur & BIT(11)), 50, 10000)) { + dev_err(dcp->dev, + "display %s power word did not stay on after restore: %#x\n", + names[i], cur); + return -ETIMEDOUT; + } + } + } + + return 0; +} + +static int dcp_t6041_start_one(struct device *dev, void *data) +{ + struct apple_dcp *dcp = dev_get_drvdata(dev); + struct dcp_t6041_power *pwr; + const struct dcp_t6041_chain *main; + void __iomem *rsys, *rfe, *rcpu, *gapf, *pmc; + unsigned int i; + u32 v, cur, to = 0; + int ret, ps_ret; + + if (!dcp || IS_ERR_OR_NULL(dcp->rtk) || !dcp->sleep_host_stop) + return 0; + pwr = &dcp->t6041_power; + main = pwr->main_chain; + if (!main || main->num_domains < 3) + return -EINVAL; + rsys = main->domains[0]; + rfe = main->domains[1]; + rcpu = main->domains[2]; + gapf = main->gapf; + pmc = pwr->pmc_dcp; + + v = readl(rsys) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + /* + * As macOS's wake writes them: target on with both flag bits clear (0xf). Raised with the + * flags kept (0x30f) the word reads 0x3ff, a later write can't clear them, and the next + * lowering then latches bit 11 on SYS (0x800) and leaves FE at 0x200: the sleep engine waits + * on that bit and the chip resets (second sleep of a boot, 11 Nov). + */ + writel((v & ~0x30fU) | 0xf, rsys); + if (readl_poll_timeout(rsys, cur, + FIELD_GET(GENMASK(7, 4), cur) == 0xf && !(cur & BIT(11)), + 50, 10000)) + to |= BIT(0); + writel(0, main->pg_a); + writel(1, main->pg_b); + /* + * Bridge 4 stays as boot has it (bit 0 of both words clear, 0x10000 / 0x101330), unlike + * macOS's wake: with it set, the driver's own display power-off after a wake froze the whole + * machine right after "dcp_poweroff() done" (login after a wake, sddm restart; 11 Nov). + */ + v = readl(rfe) & ~(GENMASK(9, 8) | GENMASK(3, 0) | BIT(28)); + writel((v & ~0x30fU) | 0xf, rfe); + if (readl_poll_timeout(rfe, cur, + FIELD_GET(GENMASK(7, 4), cur) == 0xf && !(cur & BIT(11)), + 50, 10000)) + to |= BIT(1); + writel(readl(gapf) & ~BIT(4), gapf); + if (readl_poll_timeout(gapf, cur, !(cur & BIT(4)), 10, 5000)) + to |= BIT(3); + v = readl(rcpu); + writel((v & ~(0x30fU | BIT(28))) | 0xf, rcpu); + mb(); + if (readl_poll_timeout(rcpu, cur, + FIELD_GET(GENMASK(7, 4), cur) == 0xf && !(cur & BIT(11)), + 50, 10000)) + to |= BIT(2); + for (i = 3; i < main->num_domains && pwr->child_valid && main->child_saved; i++) { + void __iomem *cw = main->domains[i]; + u32 want = main->child_saved[i - 3]; + + if (!(want & 0xf) || (readl(cw) & 0xf0)) + continue; + writel(want, cw); + if (readl_poll_timeout(cw, cur, cur & 0xf0, 50, 2000)) + to |= (i - 3 < 24) ? BIT(8 + (i - 3)) : BIT(31); + } + dcp_pmc_set(dcp, pmc, true); + if (to & 0xf) { + dev_err(dev, "display domains not on after the sleep: %#x\n", to); + return -ETIMEDOUT; + } + if (to) + dev_warn(dev, "display child domains not on after the sleep: %#x\n", to); + + dcp_s2r_find_darts(dcp); + if (dcp->s2r_disp_dart) { + apple_dart_display_keep(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, false); + apple_dart_display_streams(dcp->s2r_disp_dart, DCP_S2R_DISP_STREAMS, true, false); + } + if (dcp->s2r_dcp_dart) { + apple_dart_display_keep(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, false); + apple_dart_display_streams(dcp->s2r_dcp_dart, DCP_S2R_DCP_STREAMS, true, false); + } + dcp_s2r_put_darts(dcp); + + WRITE_ONCE(dcp->crashed, false); + WRITE_ONCE(dcp->ext_dead, false); + ret = apple_rtkit_power_cycled_return(dcp->rtk, + dcp->coproc_reg + APPLE_DCP_COPROC_CPU_CONTROL); + if (ret) { + dev_err(dev, "the firmware's warm restart after the sleep failed: %d\n", ret); + WRITE_ONCE(dcp->crashed, true); + return ret; + } + WRITE_ONCE(dcp->s2r_fw_down, false); + /* + * Before the mode set, not after it: the commit's swap is what hands the firmware the + * console's framebuffer, and fbcon draws into that memory without committing again. With + * presentation still paused the swap was dropped and the panel stayed black with everything + * else up (10 Nov). + */ + iomfb_pause_presentation(dcp, false); + ret = dcp_t6041_recommit(dcp); + if (ret) + dev_err(dev, "mode set after the sleep failed: %d\n", ret); + /* + * Always restore backlight and boot power words once domains and RTKit warm restart + * succeeded, even if recommit timed out (e.g., wake with lid closed): leaving disp_cpu + * manual hangs the next display power-off. + */ + dcp_backlight_s2r_restore(dcp); + ps_ret = dcp_t6041_boot_ps_io(dcp, true); + return ret ?: ps_ret; +} + +static bool dcp_t6041_down, dcp_t6041_words; + +/* @np's first DART, dark if its driver is bound. */ +static void dcp_t6041_dart_dark(struct device_node *np) +{ + struct device_node *dart = np ? of_parse_phandle(np, "iommus", 0) : NULL; + struct platform_device *pdev = dart ? of_find_device_by_node(dart) : NULL; + + of_node_put(dart); + if (!pdev) + return; + if (device_is_bound(&pdev->dev)) + apple_dart_power_dark(&pdev->dev, true); + put_device(&pdev->dev); +} + +/* + * Every external chain's DARTs, dark before their domains go off. The display subsystem maps + * every framebuffer through the display DARTs, and an unmap after the wake (an sddm restart, a + * logout) flushed one behind a dead block and stopped the machine (12 Nov). By node, so a chain + * whose DCP never bound, which the display subsystem skips as unusable, is covered too, and so + * is every chain a board enables, not only the first two. + */ +static void dcp_t6041_ext_darts_dark(void) +{ + struct device_node *np, *piodma; + + for_each_compatible_node(np, NULL, "apple,t6041-dcpext") { + if (!of_device_is_available(np)) + continue; + piodma = of_get_child_by_name(np, "piodma"); + dcp_t6041_dart_dark(piodma); + of_node_put(piodma); + dcp_t6041_dart_dark(np); + } +} + +enum dcp_t6041_step { DCP_S2R_FW_STOP, DCP_S2R_WORDS_DOWN, DCP_S2R_START }; + +/* Each step once per sleep. */ +static int dcp_t6041_s2r_step(enum dcp_t6041_step step) +{ + struct apple_dcp *host = READ_ONCE(dcp_t6041_host); + bool external = true; + unsigned int i; + int ret; + + if (!host) + return -ENODEV; + + if (step == DCP_S2R_START) { + if (!dcp_t6041_down) + return 0; + dcp_t6041_down = false; + dcp_t6041_words = false; + return driver_for_each_device(&apple_platform_driver.driver, NULL, NULL, + dcp_t6041_start_one); + } + if (step == DCP_S2R_WORDS_DOWN) { + if (dcp_t6041_words || !dcp_t6041_down) + return 0; + dcp_t6041_words = true; + dcp_t6041_ext_darts_dark(); + for (i = 0; i < host->t6041_power.num_chains; i++) { + ret = dcp_t6041_word_try(host->dev, &host->t6041_power, + &host->t6041_power.chains[i]); + if (ret) + return ret; + } + return 0; + } + if (dcp_t6041_down) + return 0; + dcp_t6041_boot_ps_io(host, false); + ret = driver_for_each_device(&apple_platform_driver.driver, NULL, &external, + dcp_t6041_stop_one); + if (ret) + return ret; + external = false; + ret = driver_for_each_device(&apple_platform_driver.driver, NULL, &external, + dcp_t6041_stop_one); + if (ret) { + if (READ_ONCE(host->s2r_fw_down)) + dcp_t6041_down = true; + return ret; + } + dcp_t6041_down = true; + return 0; +} + +/* T6041: the display down for a real sleep and back after it. */ +int dcp_t6041_s2r_all(bool start) +{ + int ret; + + if (!READ_ONCE(dcp_sleep_host_stop)) { + if (!start && READ_ONCE(dcp_sleep_host_stop_missing)) { + pr_err("apple-dcp: host-driven sleep required but apple,display-power unavailable\n"); + return -ENODEV; + } + return 0; + } + if (start) + return dcp_t6041_s2r_step(DCP_S2R_START); + if (dcp_t6041_down) + return 0; + ret = dcp_t6041_s2r_step(DCP_S2R_FW_STOP); + if (ret) { + if (dcp_t6041_down && dcp_t6041_s2r_step(DCP_S2R_START)) + pr_err("apple-dcp: T6041 S2R display unwind failed\n"); + return ret; + } + ret = dcp_t6041_s2r_step(DCP_S2R_WORDS_DOWN); + if (ret) { + if (dcp_t6041_s2r_step(DCP_S2R_START)) + pr_err("apple-dcp: T6041 S2R display unwind failed\n"); + return ret; + } + return 0; +} + int __init dcp_register(void) { return platform_driver_register(&apple_platform_driver); diff --git a/drivers/gpu/drm/apple/dcp.h b/drivers/gpu/drm/apple/dcp.h index 0989d8d6a2437..6c1c258c3c54e 100644 --- a/drivers/gpu/drm/apple/dcp.h +++ b/drivers/gpu/drm/apple/dcp.h @@ -156,6 +156,7 @@ int dcp_dptx_park(struct apple_dcp *dcp); int dcp_dptx_disconnect_oob(struct platform_device *pdev, u32 port); bool dcp_hold_resume_event(struct platform_device *pdev); bool dcp_s2r_firmware_stopped(struct platform_device *pdev); +int dcp_t6041_s2r_all(bool start); int iomfb_start_rtkit(struct apple_dcp *dcp); void iomfb_ext26_start(struct apple_dcp *dcp); diff --git a/drivers/gpu/drm/apple/dcp_backlight.c b/drivers/gpu/drm/apple/dcp_backlight.c index a487e9b770aab..1019180517bed 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.c +++ b/drivers/gpu/drm/apple/dcp_backlight.c @@ -431,6 +431,34 @@ void dcp_backlight_finish_fade(struct apple_dcp *dcp) dcp_backlight_kick(dcp); } +/* + * After the S2R display restart: ask for the user's level again and send it, whatever the + * backlight core's flags say at that moment. The class device resumes on its own schedule: + * when it runs after the restart the panel stays dark until then (suspended and core_blank + * still set at the mode set, 11 Nov), and when it runs before, its request goes to a firmware + * that isn't up yet and nothing sends it again (the dark lid wakes). + */ +void dcp_backlight_s2r_restore(struct apple_dcp *dcp) +{ + struct backlight_device *bd = READ_ONCE(dcp->brightness.bl_dev); + unsigned long flags; + + if (!dcp_backlight_desktop(dcp) || !bd) + return; + spin_lock_irqsave(&dcp->backlight.lock, flags); + /* + * A level sent to the firmware that the stop then took down never gets its answer: the + * state stayed in_flight for good and nothing was sent again (dark lid wake of 20:30, + * "sent 0 ... dirty 1 in_flight 1"). The restarted firmware knows nothing of it. + */ + dcp->backlight.state.in_flight = false; + dcp->backlight.state.retries = 0; + dcp_bl_request(&dcp->backlight.state, bd->props.brightness, false, false); + dcp->backlight.state.dirty = true; + spin_unlock_irqrestore(&dcp->backlight.lock, flags); + dcp_backlight_kick(dcp); +} + int dcp_backlight_dpms(struct apple_dcp *dcp, bool on) { unsigned long flags; diff --git a/drivers/gpu/drm/apple/dcp_backlight.h b/drivers/gpu/drm/apple/dcp_backlight.h index 0045e995885d7..bb200ace90258 100644 --- a/drivers/gpu/drm/apple/dcp_backlight.h +++ b/drivers/gpu/drm/apple/dcp_backlight.h @@ -407,6 +407,7 @@ bool dcp_backlight_desktop_prepare(struct apple_dcp *dcp, u32 id, bool have_surface, u32 *nits); void dcp_backlight_desktop_finish(struct apple_dcp *dcp, u32 id, bool reply, bool accepted); +void dcp_backlight_s2r_restore(struct apple_dcp *dcp); /* * kick only queues work; it must not submit a top-level RPC from the caller. diff --git a/drivers/gpu/drm/apple/iomfb.c b/drivers/gpu/drm/apple/iomfb.c index a431791daf9f9..45b53f5e9bbd9 100644 --- a/drivers/gpu/drm/apple/iomfb.c +++ b/drivers/gpu/drm/apple/iomfb.c @@ -349,17 +349,22 @@ static u16 dcp_packet_start(struct dcp_channel *ch, u8 depth) /* Pushes and pops the depth of the call stack with safety checks */ static u8 dcp_push_depth(u8 *depth) { - u8 ret = (*depth)++; + u8 ret = *depth; WARN_ON(ret >= DCP_MAX_CALL_DEPTH); + WRITE_ONCE(*depth, ret + 1); return ret; } static u8 dcp_pop_depth(u8 *depth) { - WARN_ON((*depth) == 0); + u8 val = *depth; - return --(*depth); + WARN_ON(val == 0); + val--; + /* Pair with iomfb_channels_idle() so callers observe prior ACK sends. */ + smp_store_release(depth, val); + return val; } /* Older firmware and the H17G method profile retain their existing transport. */ @@ -373,9 +378,14 @@ static bool iomfb_uses_queue(struct apple_dcp *dcp) bool iomfb_channels_idle(struct apple_dcp *dcp) { - return !dcp->ch_cmd.depth && !dcp->ch_cb.depth && - !dcp->ch_oobcmd.depth && !dcp->ch_oobcb.depth && - !dcp->ch_async.depth && !dcp->ch_oobasync.depth; + /* Pair with dcp_pop_depth() / dcp_ack() pending_acks ordering. */ + return !smp_load_acquire(&dcp->ch_cmd.depth) && + !smp_load_acquire(&dcp->ch_cb.depth) && + !smp_load_acquire(&dcp->ch_oobcmd.depth) && + !smp_load_acquire(&dcp->ch_oobcb.depth) && + !smp_load_acquire(&dcp->ch_async.depth) && + !smp_load_acquire(&dcp->ch_oobasync.depth) && + !atomic_read_acquire(&dcp->pending_acks); } enum iomfb_opaque_x_state { @@ -1441,11 +1451,21 @@ void dcp_ack(struct apple_dcp *dcp, enum dcp_context_id context) { struct dcp_channel *ch = dcp_get_channel(dcp, context); + /* + * Track the in-flight ACK before popping ch->depth so a concurrent + * iomfb_channels_idle() poll cannot see idle before the ACK is queued + * to RTKit, while popping ch->depth before sending so DCP's next + * callback cannot race ch->depth. + */ + atomic_inc(&dcp->pending_acks); dcp_pop_depth(&ch->depth); if (dcp_is_ext26(dcp)) dma_wmb(); dcp_send_message(dcp, IOMFB_ENDPOINT, dcpep_ack(context)); + /* Order dcp_send_message() before publishing pending_acks == 0. */ + smp_mb__before_atomic(); + atomic_dec(&dcp->pending_acks); } /* diff --git a/drivers/gpu/drm/apple/iomfb_template.c b/drivers/gpu/drm/apple/iomfb_template.c index faa4f69624bec..88c303630aae0 100644 --- a/drivers/gpu/drm/apple/iomfb_template.c +++ b/drivers/gpu/drm/apple/iomfb_template.c @@ -2785,6 +2785,40 @@ int DCP_FW_NAME(iomfb_s2r_power)(struct apple_dcp *dcp, bool on, bool named_call } #endif +#if DCP_FW_DESKTOP_26(DCP_FW_VER) +DCP_THUNK_IN(dcp_unnamed_500, dcpep_unnamed_500, u32); + +static void dcp_s2r_500_done(struct apple_dcp *dcp, void *out, void *cookie) +{ + struct dcp_wait_cookie *wait = cookie; + + complete(&wait->done); + kref_put(&wait->refcount, release_wait_cookie); +} + +/* Sleep test: H17P's A500, same number and bytes as this firmware's neighbours. */ +int DCP_FW_NAME(iomfb_s2r_500)(struct apple_dcp *dcp) +{ + struct dcp_wait_cookie *cookie; + unsigned long left; + u32 val = 0xaaaa0000; + + cookie = kzalloc_obj(*cookie); + if (!cookie) + return -ENOMEM; + init_completion(&cookie->done); + kref_init(&cookie->refcount); + kref_get(&cookie->refcount); + + dcp_unnamed_500(dcp, false, &val, dcp_s2r_500_done, cookie); + + left = wait_for_completion_timeout(&cookie->done, msecs_to_jiffies(1000)); + kref_put(&cookie->refcount, release_wait_cookie); + + return left ? 0 : -ETIMEDOUT; +} +#endif + static bool dcp_power_stop_confirmed(struct dcp_wait_cookie *cookie) { /* H17P does not confirm that scanout has stopped. */ @@ -3225,6 +3259,12 @@ dcpep_cb_hotplug_v26_6(struct apple_dcp *dcp, struct dcp_hotplug_req_v26_6 *req) if (!dcp->main_display && !connected) dcp->desktop->ext_pipe_off = true; + /* Signal T6041 S2R resume before dcpep_cb_hotplug() skips main_display. */ + if (connected) { + dev_dbg(dcp->dev, "D575 hotplug connected=1\n"); + complete(&dcp->s2r_hpd_done); + } + dcpep_cb_hotplug(dcp, &connected); if (paired && tiled_valid) diff --git a/drivers/gpu/drm/apple/iomfb_template.h b/drivers/gpu/drm/apple/iomfb_template.h index 5820f624350d7..f4c47eba0406f 100644 --- a/drivers/gpu/drm/apple/iomfb_template.h +++ b/drivers/gpu/drm/apple/iomfb_template.h @@ -394,6 +394,9 @@ void DCP_FW_NAME(iomfb_poweroff)(struct apple_dcp *dcp); void DCP_FW_NAME(iomfb_sleep)(struct apple_dcp *dcp); void DCP_FW_NAME(iomfb_start)(struct apple_dcp *dcp); void DCP_FW_NAME(iomfb_shutdown)(struct apple_dcp *dcp); +#if DCP_FW_DESKTOP_26(DCP_FW_VER) +int DCP_FW_NAME(iomfb_s2r_500)(struct apple_dcp *dcp); +#endif #if DCP_FW_H17(DCP_FW_VER) int DCP_FW_NAME(iomfb_s2r_500)(struct apple_dcp *dcp); int DCP_FW_NAME(iomfb_s2r_power)(struct apple_dcp *dcp, bool on, bool named_calls, bool oob); diff --git a/drivers/gpu/drm/apple/iomfb_v26_6_desktop.c b/drivers/gpu/drm/apple/iomfb_v26_6_desktop.c index 3a9436c29355f..e3585174b0fd1 100644 --- a/drivers/gpu/drm/apple/iomfb_v26_6_desktop.c +++ b/drivers/gpu/drm/apple/iomfb_v26_6_desktop.c @@ -51,6 +51,7 @@ static const struct dcp_method_entry dcp_methods[dcpep_num_methods] = { IOMFB_METHOD("A469", iomfbep_abort_swaps_dcp), IOMFB_METHOD("A473", dcpep_set_power_state), IOMFB_METHOD("A474", dcpep_pipe_query_474), + IOMFB_METHOD("A500", dcpep_unnamed_500), /* A364 get_mode_info and A420/A421 gamma: see iomfb_template.c */ }; @@ -59,6 +60,22 @@ static const struct dcp_method_entry dcp_methods[dcpep_num_methods] = { #include "iomfb_template.c" +/* + * D572: 0 when the firmware is done with the display, 1 when it wants it back. Only a + * sleep path waiting for it (s2r_active) acts on it; the firmware takes a zero status. + */ +static bool trampoline_dart_power_v26_6_desktop(struct apple_dcp *dcp, int tag, void *out, + void *in) +{ + const struct dcp_packet_header *header = in - sizeof(*header); + + /* A bool in a 4-byte slot: its upper padding bytes are not cleared. */ + if (header->in_len >= sizeof(u32)) + dcp_s2r_dart_power(dcp, !!*(const u8 *)in); + + return trampoline_zero(dcp, tag, out, in); +} + /* * D114 periodically publishes dictionary-valued statistics: the analytics * event, answered by dcp_dict_passthrough_reply(). @@ -236,14 +253,16 @@ static const iomfb_cb_handler cb_handlers[IOMFB_MAX_CB] = { [565] = trampoline_true, /* set_property_bool */ [567] = trampoline_true, /* set_property_str */ /* a zero status for both its start and stop events */ - [572] = trampoline_zero, + [572] = trampoline_dart_power_v26_6_desktop, [575] = trampoline_hotplug, [576] = trampoline_nop, [581] = trampoline_nop, [582] = trampoline_true, /* create_default_fb_surface */ + [583] = trampoline_nop, /* clear_default_surface */ [588] = trampoline_nop, /* resize_default_fb_surface_gated */ [590] = trampoline_swap_complete, [592] = trampoline_swap_complete_intent_gated, + [597] = trampoline_zero, /* sleep test: (0, 4), purpose unknown */ [593] = trampoline_abort_swap_ap_gated, /* a four-byte padded notification; only its first byte is read */ [594] = trampoline_enable_backlight_message_ap_gated, @@ -330,9 +349,11 @@ static const struct dcp_cb_min_v26_6_desktop cb_min[IOMFB_MAX_CB] = { [576] = CB_MIN(0, 0), [581] = CB_MIN(0, 0), [582] = CB_MIN(0, sizeof(u8)), + [583] = CB_MIN(0, 0), [588] = CB_MIN(0, 0), [590] = CB_MIN(sizeof(struct DCP_FW_NAME(dc_swap_complete_resp)), 0), [592] = CB_MIN(sizeof(dcp_swap_intent_t), 0), + [597] = CB_MIN(0, sizeof(u32)), [593] = CB_MIN(sizeof(u32), 0), [594] = CB_MIN(sizeof(u8), 0), [595] = CB_MIN(0, 0), diff --git a/drivers/gpu/drm/asahi/g17/sleep.c b/drivers/gpu/drm/asahi/g17/sleep.c index 0131ace971222..e62315b1eb2b5 100644 --- a/drivers/gpu/drm/asahi/g17/sleep.c +++ b/drivers/gpu/drm/asahi/g17/sleep.c @@ -193,6 +193,24 @@ int asahi_g17_pmp_request(struct device *dev, bool enable) return ret; } +/* + * The node of the GPU's power state word. Where the GPU's first power domain is its PMP + * report entry (a small index for a reg, under the PMP), as in the J616C device tree the + * bring-up runs, the word is that entry's own domain. + */ +static struct device_node *asahi_g17_ps_node(struct device *dev) +{ + struct device_node *np, *next; + + np = of_parse_phandle(dev->of_node, "power-domains", 0); + if (np && of_device_is_compatible(np, "apple,t6000-pmp-v2-report-entry")) { + next = of_parse_phandle(np, "power-domains", 0); + of_node_put(np); + np = next; + } + return np; +} + static int asahi_g17_ps(struct device *dev, struct regmap **regmap, u32 *offset) { struct device_node *np; @@ -212,7 +230,7 @@ static int asahi_g17_ps(struct device *dev, struct regmap **regmap, u32 *offset) of_node_put(np); return ret; } - np = of_parse_phandle(dev->of_node, "power-domains", 0); + np = asahi_g17_ps_node(dev); if (!np) return -EINVAL; ret = of_property_read_u32(np, "reg", offset); @@ -622,7 +640,7 @@ struct asahi_g17_commit *asahi_g17_commit_prepare(struct device *dev, of_node_put(parent); of_node_put(np); } else { - np = of_parse_phandle(dev->of_node, "power-domains", 0); + np = asahi_g17_ps_node(dev); if (!np) goto err; if (!of_property_read_u32(np, "reg", &offset) && np->parent) diff --git a/drivers/gpu/drm/asahi/hw/t6041.rs b/drivers/gpu/drm/asahi/hw/t6041.rs index f2b4a464089da..4cce54372a3f8 100644 --- a/drivers/gpu/drm/asahi/hw/t6041.rs +++ b/drivers/gpu/drm/asahi/hw/t6041.rs @@ -241,6 +241,8 @@ const CONFIG_25G83: Config = Config { reserved_slots: &[], chip: Some(&CHIP_25G83), firmware: fw::variant::Firmware::Identified(&[BUILD_25G83]), + // The GPU is restarted after a real sleep, as on the 32-core part. + sleep_restart: true, ..BASE }; diff --git a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs index 6ccd27f2ddc11..4afc2179f5632 100644 --- a/drivers/gpu/drm/asahi/hw/t6041_25g83.rs +++ b/drivers/gpu/drm/asahi/hw/t6041_25g83.rs @@ -60,6 +60,8 @@ pub(super) const CONFIG: Config = Config { // hang this GPU's firmware on grids of more than ten workgroups. compute_blocks: 96, }, + // The GPU is restarted after a real sleep, as on T8140. + sleep_restart: true, ..t6041::BASE }; diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 2834878283a52..59060014f224a 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -8121,6 +8121,56 @@ EXPORT_SYMBOL_GPL(apple_dart_gapf_ready); * Stopping again after a sleep that never reached the commit does nothing: the * domains may be off by then. */ +/* + * T6041: a display DART is locked, so the driver neither saves nor restores its TCR / TTBR, and + * after a real sleep the panel stayed black with everything else up. Keep the words of @streams + * before the sleep (save), and after it write back what differs (!save). Returns how many words + * were written back. + */ +int apple_dart_display_keep(struct device *dev, u32 streams, bool save) +{ + static struct { struct apple_dart *dart; u32 tcr[32]; u32 ttbr[32][4]; } keep[2]; + struct apple_dart *dart = dev_get_drvdata(dev); + unsigned long bits = streams; + unsigned int sid, idx, k, n = 0; + + if (!dart) + return -ENODEV; + for (k = 0; k < 2 && keep[k].dart && keep[k].dart != dart; k++) + ; + if (k == 2) + return -ENOSPC; + if (!save && keep[k].dart != dart) + return -ENOENT; + keep[k].dart = dart; + for_each_set_bit(sid, &bits, 32) { + u32 tcr = readl(dart->regs + DART_TCR(dart, sid)); + + if (sid >= dart->num_streams) + break; + if (save) + keep[k].tcr[sid] = tcr; + for (idx = 0; idx < dart->hw->ttbr_count && idx < 4; idx++) { + u32 ttbr = readl(dart->regs + DART_TTBR(dart, sid, idx)); + + if (save) { + keep[k].ttbr[sid][idx] = ttbr; + continue; + } + if (ttbr != keep[k].ttbr[sid][idx]) { + writel(keep[k].ttbr[sid][idx], dart->regs + DART_TTBR(dart, sid, idx)); + n++; + } + } + if (!save && tcr != keep[k].tcr[sid]) { + writel(keep[k].tcr[sid], dart->regs + DART_TCR(dart, sid)); + n++; + } + } + return n; +} +EXPORT_SYMBOL_GPL(apple_dart_display_keep); + int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush) { struct apple_dart *dart = dev_get_drvdata(dev); diff --git a/drivers/irqchip/irq-apple-aic.c b/drivers/irqchip/irq-apple-aic.c index b3ea9b614475d..8e7866a865e49 100644 --- a/drivers/irqchip/irq-apple-aic.c +++ b/drivers/irqchip/irq-apple-aic.c @@ -350,6 +350,18 @@ static const struct aic_info aic3_t8140_info __initconst = { .fw_suspend = true, }; +/* + * T6041 (M4 Max): the AICv3 of T8122, with the state its sleep driver's firmware + * suspend loses saved and restored around it. + */ +static const struct aic_info aic3_t6041_info __initconst = { + .version = 3, + .irq_cfg = AIC3_IRQ_CFG, + .fast_ipi = true, + .local_fast_ipi = true, + .fw_suspend = true, +}; + static const struct aic_info aic3_t8132_info __initconst = { .version = 3, .irq_cfg = AIC3_IRQ_CFG, @@ -382,6 +394,10 @@ static const struct of_device_id aic_info_match[] = { .compatible = "apple,t8142-aic3", .data = &aic3_t8142_info, }, + { + .compatible = "apple,t6041-aic3", + .data = &aic3_t6041_info, + }, { .compatible = "apple,t8103-aic", .data = &aic1_local_fipi_info, diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index 0ef475e5be02b..35f86f9fe0027 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -686,6 +686,20 @@ static void apple_smc_probe_wktp(struct apple_smc *smc) apple_smc_write_full_wake(smc); } +/* pmVC as the boot left it, next to what apple,sleep-pmvc has the sleep commit write. */ +static void apple_smc_sleep_pmvc_report(struct apple_smc *smc) +{ + u32 cur; + int ret = apple_smc_read_u32(smc, SMC_KEY(pmVC), &cur); + + if (ret) + dev_dbg(smc->dev, "pmVC unreadable (%d); the sleep commit writes %#x\n", ret, + smc->sleep_pmvc); + else + dev_dbg(smc->dev, "pmVC %#x at boot; the sleep commit writes %#x\n", cur, + smc->sleep_pmvc); +} + static int apple_smc_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -703,6 +717,9 @@ static int apple_smc_probe(struct platform_device *pdev) if (!smc->wake_reasons) smc->wake_reasons = of_device_is_compatible(dev->of_node, "apple,t8132-smc") ? apple_smc_t8132_wake_reasons : apple_smc_t8140_wake_reasons; + smc->sleep_wake_type = of_property_read_bool(dev->of_node, "apple,sleep-wake-type"); + smc->sleep_pmvc_set = !of_property_read_u32(dev->of_node, "apple,sleep-pmvc", + &smc->sleep_pmvc); mutex_init(&smc->mutex); spin_lock_init(&smc->lock); @@ -770,6 +787,9 @@ static int apple_smc_probe(struct platform_device *pdev) return dev_err_probe(smc->dev, ret, "Failed to get key count"); smc->key_count = be32_to_cpu(count); + if (smc->sleep_pmvc_set) + apple_smc_sleep_pmvc_report(smc); + /* T8152: key reads and writes are qualified; notifications and GPIO are not. */ if (of_device_is_compatible(dev->of_node, "apple,t8152-smc")) return devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, @@ -932,10 +952,56 @@ static int apple_smc_notice_idle(struct apple_smc *smc) return ret; } +/* + * WKTP, one byte: 2 at the sleep commit, 0 again once a wake is a full one. With the + * key left at 2 the SMC treats all the time awake as a power nap: it keeps its own fan + * policy against a fan request (the write times out and the fans stay at its idle + * speed), and under thermal load it requests a sleep once a second. #1910 does the same + * on the M4 Pro. + */ +#define SMC_WKTP_SLEEP 2 +#define SMC_WKTP_AWAKE 0 + +/* WKTP back to 0 after a full wake, or after a sleep that ended in a refusal. */ +static void apple_smc_wake_full(struct apple_smc *smc) +{ + int ret; + + if (!smc->wake_silent) + return; + smc->wake_silent = false; + ret = apple_smc_write_u8(smc, SMC_KEY(WKTP), SMC_WKTP_AWAKE); + if (ret) + dev_err(smc->dev, "Failed to write WKTP = %u: %d\n", SMC_WKTP_AWAKE, ret); +} + static int apple_smc_sleep_commit(struct apple_smc *smc) { int ret; + /* + * apple,sleep-wake-type and apple,sleep-pmvc (T6041): macOS writes WKTP = 2, going to + * sleep, and pmVC, the VDD_CIO rail mask (bit 8 set, bit n keeping port n's CIO rail + * powered across sleep so rails the sleep engine polls active remain up), before its + * sleep notice. Either failing refuses the sleep before slpa; .complete then tells the + * SMC the sleep is off and writes WKTP back. + */ + if (smc->sleep_wake_type) { + /* Whatever came of the write, the SMC may run silent until it is told. */ + smc->wake_silent = true; + ret = apple_smc_write_u8(smc, SMC_KEY(WKTP), SMC_WKTP_SLEEP); + if (ret) { + dev_err(smc->dev, "Failed to write WKTP = %u: %d\n", SMC_WKTP_SLEEP, ret); + return ret; + } + } + if (smc->sleep_pmvc_set) { + ret = apple_smc_write_u32(smc, SMC_KEY(pmVC), smc->sleep_pmvc); + if (ret) { + dev_err(smc->dev, "Failed to write pmVC = %#x: %d\n", smc->sleep_pmvc, ret); + return ret; + } + } apple_smc_write_mbse(smc, SMC_KEY(slpa)); /* Device interrupts are off here. */ mdelay(SMC_SLEEP_ARM_MS); @@ -1188,6 +1254,9 @@ static void apple_smc_sleep_wake(struct apple_smc *smc, bool woken) } if (apple_smc_port_reasons_only(smc, smc->wake_record)) apple_sleep_debug_link_cut_wake(); + /* A dark wake sleeps again, and its commit writes the key anyway. */ + if (!pm_dark_wake()) + apple_smc_wake_full(smc); /* A dark wake isn't one: with wakeup_count in use, it would abort the sleep after it. */ if (smc->wake_record && !pm_dark_wake()) pm_wakeup_event(smc->dev, 0); @@ -1780,9 +1849,12 @@ static void apple_smc_complete(struct device *dev) smc->sleep_warned = false; } smc->sleep_policy = NULL; - - if (smc->has_wktp && !pm_dark_wake()) + if (smc->has_wktp && !pm_dark_wake()) { + smc->wake_silent = false; apple_smc_write_full_wake(smc); + } + /* A commit the SMC refused, or dark wakes that ended in a refusal. */ + apple_smc_wake_full(smc); } /* @@ -1836,6 +1908,9 @@ static int apple_smc_suspend_noirq(struct device *dev) struct apple_smc *smc = dev_get_drvdata(dev); int ret; + if (!pm_suspend_via_firmware()) + return 0; + /* For the time asleep a dark wake logs: boot time counts the sleep, monotonic doesn't. */ smc->sleep_entry_boot = ktime_get_boottime(); smc->sleep_entry_mono = ktime_get(); @@ -1854,7 +1929,12 @@ static int apple_smc_suspend_noirq(struct device *dev) static int apple_smc_resume_noirq(struct device *dev) { struct apple_smc *smc = dev_get_drvdata(dev); - bool woken = smc->woken_done; + bool woken; + + if (!pm_suspend_via_firmware()) + return 0; + + woken = smc->woken_done; /* This wake's own: never left for another attempt's resume */ smc->woken_done = false; diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index 508930d3937aa..b33e64ae38bd8 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -2719,6 +2719,8 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) return ERR_PTR(ret); anv->adminq.is_adminq = true; platform_set_drvdata(pdev, anv); + /* Its resume waits on the coprocessor (0.2 to 0.9 s after a real sleep): not in the others' way. */ + device_enable_async_suspend(&pdev->dev); anv->hw = of_device_get_match_data(&pdev->dev); if (!anv->hw) { @@ -3480,6 +3482,10 @@ static const struct apple_nvme_hw apple_nvme_t6040_hw = { .needs_ioq_registers = true, .lsq_in_nvmmu = true, .max_queue_depth = 64, + /* ANS takes part in a firmware sleep, whole endpoint map echoed. */ + .sleep_traced = true, + .sleep_flush_max_nsid = 1, + .sleep_shn = NVME_CC_SHN_MASK, .quirks = NVME_QUIRK_NO_APST, }; diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index deb2c6214202d..824b94d04caa7 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -99,7 +99,6 @@ static int t6050_sd_port_wake = 2; module_param(t6050_sd_port_wake, int, 0644); MODULE_PARM_DESC(t6050_sd_port_wake, "T6050: the SD card reader's port after a firmware sleep: back once the resume is over (2, default), back in the early resume (1), or parked until a restart (0)"); - /* T8103 (original M1) and related SoCs */ #define CORE_RC_PHYIF_CTL 0x00024 #define CORE_RC_PHYIF_CTL_RUN BIT(0) @@ -659,6 +658,7 @@ struct apple_pcie { const struct hw_info *hw; unsigned long *bitmap; struct list_head ports; + struct list_head hib_fns; struct completion event; struct irq_fwspec fwspec; struct irq_domain *msi_domain; @@ -689,6 +689,9 @@ struct apple_pcie_port { struct gpio_desc *perst_gpio; struct gpio_desc *pwren_gpio; int idx; + /* Conventional port: link up when the sleep began, and found down after it */ + bool hib_link_up; + bool hib_cold; bool started; bool needs_stop; bool link_failed; @@ -5923,6 +5926,9 @@ static int apple_pcie_probe(struct platform_device *pdev) struct device *piodma_supplier = NULL; int ret; + /* Setting the ports up again after a real sleep takes ~0.75 s: resume in parallel. */ + device_enable_async_suspend(&pdev->dev); + hw = of_device_get_match_data(dev); if (!hw) return -ENODEV; @@ -6046,6 +6052,7 @@ static int apple_pcie_probe(struct platform_device *pdev) mutex_init(&pcie->lock); INIT_LIST_HEAD(&pcie->ports); + INIT_LIST_HEAD(&pcie->hib_fns); /* Resolve PM dependencies before publishing the PCI hierarchy. */ if (pcie->hw->tunneled) { @@ -6966,6 +6973,9 @@ static void apple_pcie_stop_for_sleep(struct device *dev) static void apple_pcie_neo_save_functions(struct apple_pcie *pcie); +static bool apple_pcie_s2r_reinit(struct apple_pcie *pcie); +static void apple_pcie_hib_save(struct apple_pcie *pcie); +static void apple_pcie_hib_restore_noirq(struct apple_pcie *pcie, const char *what); /* * The J716c radio drivers save PCI state without entering D3. The PCI core * keeps the root port in D0 as well. Its host and DART have no switchable @@ -7130,6 +7140,8 @@ static int apple_pcie_suspend_noirq(struct device *dev) return ret; } if (!pcie->hw->tunneled) { + if (apple_pcie_s2r_reinit(pcie) && pm_suspend_via_firmware()) + apple_pcie_hib_save(pcie); if (pm_suspend_no_platform() && pcie->num_pds) return apple_pcie_hold_domains(pcie); return 0; @@ -7661,8 +7673,11 @@ static int apple_pcie_resume_noirq(struct device *dev) } return ret; } - if (!pcie->hw->tunneled) + if (!pcie->hw->tunneled) { + if (apple_pcie_s2r_reinit(pcie) && pm_resume_via_firmware()) + apple_pcie_hib_restore_noirq(pcie, "S2R"); return 0; + } if (pcie->resume_failed) return -EIO; /* @@ -7729,6 +7744,191 @@ static int apple_pcie_resume_noirq(struct device *dev) return ret; } +/* + * A conventional host (the internal ports with the radio and the SD reader) loses its power + * in a real sleep: the endpoints sit unpowered or in reset behind a link that is down. The + * resume then does what probe did. From aurora-silicon/linux#1477 (0ab1a6603). + */ +struct apple_pcie_hib_fn { + struct list_head entry; + struct pci_dev *pdev; + struct pci_saved_state *state; +}; + +/* A real sleep takes a conventional host's power: its ports are set up again as at probe. */ +static bool apple_pcie_s2r_reinit(struct apple_pcie *pcie) +{ + return !pcie->hw->tunneled && !pcie->managed_sids && !pcie->piodma_supplier && + !pcie->hw->root_bus_only; +} + +/* What only the port registers hold. */ +static void apple_pcie_hib_save(struct apple_pcie *pcie) +{ + struct apple_pcie_port *port; + int i; + + mutex_lock(&pcie->lock); + list_for_each_entry(port, &pcie->ports, entry) { + port->hib_link_up = apple_pcie_port_readl(port, PORT_LINKSTS) & PORT_LINKSTS_UP; + port->hib_cold = false; + port->saved_intmask = apple_pcie_port_readl(port, PORT_INTMSK); + for_each_set_bit(i, port->sid_map, port->sid_map_sz) + port->saved_rid2sid[i] = + apple_pcie_port_readl(port, port_rid2sid_offset(port, i)); + } + mutex_unlock(&pcie->lock); +} + +static void apple_pcie_hib_free_fns(struct apple_pcie *pcie) +{ + struct apple_pcie_hib_fn *fn, *tmp; + + list_for_each_entry_safe(fn, tmp, &pcie->hib_fns, entry) { + list_del(&fn->entry); + kfree(fn->state); + pci_dev_put(fn->pdev); + kfree(fn); + } +} + +/* + * The PCI core's noirq resume spends the functions' saved state on a link that is down + * ("device inaccessible"). A copy taken first goes back once the link is. + */ +static int apple_pcie_hib_keep_fn(struct pci_dev *pdev, void *data) +{ + struct apple_pcie *pcie = data; + struct apple_pcie_port *port; + struct apple_pcie_hib_fn *fn; + + if (pci_is_root_bus(pdev->bus) || !pdev->state_saved) + return 0; + port = apple_pcie_get_port(pdev); + if (!port || !port->hib_cold) + return 0; + fn = kzalloc(sizeof(*fn), GFP_ATOMIC); + if (!fn) + return 0; + fn->state = pci_store_saved_state(pdev); + if (!fn->state) { + kfree(fn); + return 0; + } + fn->pdev = pci_dev_get(pdev); + list_add_tail(&fn->entry, &pcie->hib_fns); + return 0; +} + +/* Before the PCI core restores the functions; nothing is written to a port in this phase. */ +static void apple_pcie_hib_restore_noirq(struct apple_pcie *pcie, const char *what) +{ + struct pci_host_bridge *bridge = pci_host_bridge_from_priv(pcie); + struct apple_pcie_port *port; + bool cold = false; + + apple_pcie_hib_free_fns(pcie); + list_for_each_entry(port, &pcie->ports, entry) { + if (!port->hib_link_up) + continue; + if (apple_pcie_port_readl(port, PORT_LINKSTS) & PORT_LINKSTS_UP) + continue; + port->hib_cold = true; + cold = true; + dev_info(pcie->dev, "%s: %pOF lost its link, setting it up again\n", + what, port->np); + } + if (cold && bridge->bus) + pci_walk_bus(bridge->bus, apple_pcie_hib_keep_fn, pcie); +} + +static void apple_pcie_hib_rid2sid(struct apple_pcie *pcie, struct apple_pcie_port *port) +{ + int i; + + mutex_lock(&pcie->lock); + for (i = 0; i < port->sid_map_sz; i++) + apple_pcie_rid2sid_write(port, i, test_bit(i, port->sid_map) ? + port->saved_rid2sid[i] : 0); + mutex_unlock(&pcie->lock); +} + +/* Probe's bring-up of a conventional port, with the state this kernel had programmed. */ +static int apple_pcie_hib_port_up(struct apple_pcie *pcie, struct apple_pcie_port *port) +{ + u32 stat; + int ret; + + ret = apple_pcie_setup_link(pcie, port, port->np); + if (ret) + return ret; + if (!pcie->hw->retain_clocks) { + if (pcie->hw->port_refclk) + rmw_clear(PORT_REFCLK_CGDIS, port->base + pcie->hw->port_refclk); + else if (port->phy) + rmw_set(PHY_LANE_CFG_REFCLKCGEN, port->phy + PHY_LANE_CFG); + rmw_clear(PORT_APPCLK_CGDIS, port->base + PORT_APPCLK); + } + /* All port interrupts masked and cleared, MSI routing as at probe. */ + apple_pcie_tunnel_restore_irq_hw(port); + apple_pcie_hib_rid2sid(pcie, port); + apple_pcie_port_writel(port, PORT_LTSSMCTL_START, PORT_LTSSMCTL); + ret = readl_relaxed_poll_timeout(port->base + PORT_LINKSTS, stat, + stat & PORT_LINKSTS_UP, 100, link_up_timeout * 1000); + if (ret) { + dev_err(pcie->dev, "S2R: %pOF status %#x link %#x after training\n", port->np, + apple_pcie_port_readl(port, PORT_STATUS), stat); + return ret; + } + apple_pcie_port_writel(port, BIT(PORT_INT_LINK_UP), PORT_INTSTAT); + apple_pcie_port_writel(port, port->saved_intmask, PORT_INTMSK); + /* 100 ms after the link before configuration requests (PCIe r5.0, 6.6.1). */ + msleep(100); + return 0; +} + +/* The normal phase, after the SMC (the PWREN GPIOs are its) and before the functions. */ +static int apple_pcie_resume(struct device *dev) +{ + struct apple_pcie *pcie = apple_pcie_lookup(dev); + struct apple_pcie_port *port; + struct apple_pcie_hib_fn *fn; + int ret; + + if (!apple_pcie_s2r_reinit(pcie) || !pm_resume_via_firmware()) + return 0; + list_for_each_entry(port, &pcie->ports, entry) { + if (!port->hib_link_up) + continue; + if (!port->hib_cold) { + apple_pcie_hib_rid2sid(pcie, port); + continue; + } + ret = apple_pcie_hib_port_up(pcie, port); + if (ret) { + dev_err(dev, "S2R: %pOF link not back (%d), its functions stay unreachable\n", + port->np, ret); + port->hib_cold = false; + continue; + } + dev_info(dev, "S2R: %pOF link back, PWREN and PERST# cycled as at probe\n", + port->np); + } + list_for_each_entry(fn, &pcie->hib_fns, entry) { + port = apple_pcie_get_port(fn->pdev); + if (!port || !port->hib_cold) + continue; + if (pci_load_saved_state(fn->pdev, fn->state)) + pci_warn(fn->pdev, "S2R: saved configuration not taken back\n"); + else + pci_restore_state(fn->pdev); + } + apple_pcie_hib_free_fns(pcie); + list_for_each_entry(port, &pcie->ports, entry) + port->hib_cold = false; + return 0; +} + static int apple_pcie_prepare(struct device *dev) { struct apple_pcie *pcie = apple_pcie_lookup(dev); @@ -7775,6 +7975,7 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { .complete = apple_radio_complete, .suspend_noirq = apple_pcie_suspend_noirq, .resume_noirq = apple_pcie_resume_noirq, + .resume = apple_pcie_resume, .resume_early = apple_pcie_resume_early, }; diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index 6b96948767a80..7089aac3bbe2e 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -341,6 +341,15 @@ static void apple_gpio_irq_unmask(struct irq_data *data) gpiochip_enable_irq(gc, data->hwirq); apple_gpio_set_reg(pctl, data->hwirq, apple_gpio_mode_mask(), FIELD_PREP(REG_GPIOx_MODE, irqtype)); + /* + * On T6041 a level interrupt fired again at once every time it was unmasked although its + * line was inactive (J616c speaker amps, pin 55: mode 3, data 1, ~140 interrupts a second + * from boot until the core disabled the line as unhandled). Switching the mode back from + * "off" leaves the status bit set. Clear it once more: a level that really is active sets + * it again. + */ + if (irqd_get_trigger_type(data) & IRQ_TYPE_LEVEL_MASK) + apple_gpio_irq_ack(data); } static unsigned int apple_gpio_irq_startup(struct irq_data *data) diff --git a/drivers/pmdomain/apple/pmgr-pwrstate-test.c b/drivers/pmdomain/apple/pmgr-pwrstate-test.c index 3eaa22999e87f..e7449c1dbee8a 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate-test.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate-test.c @@ -752,6 +752,80 @@ static void pmgr_ps_reset_busy_no_idle_wait_test(struct kunit *test) KUNIT_EXPECT_FALSE(test, r->val & (APPLE_PMGR_DEV_DISABLE | APPLE_PMGR_RESET)); } +/* Forced-on auto-managed words write target 0xf, wait for actual 0xf, then AUTO_ENABLE. */ +static void pmgr_ps_auto_enable_test(struct kunit *test) +{ + static const u32 seq[][2] = { + { 0, 0x0f0000ff }, + { 0, 0x1f0000ff }, + }; + struct pmgr_ps_test_bank *b; + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_consumer(test, 0x0f0003ff, &b); + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_auto_enable(ps->regmap, 0), 1); + pmgr_ps_test_expect_log(test, b, seq, ARRAY_SIZE(seq)); + KUNIT_EXPECT_TRUE(test, b->word[0] & APPLE_PMGR_AUTO_ENABLE); + + /* Delayed actual-state ACK completes before AUTO_ENABLE is written. */ + ps = pmgr_ps_test_domain(test, APPLE_PMGR_PS_CLKGATE, false, &r); + r->val = FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_ACTIVE) | + FIELD_PREP(APPLE_PMGR_PS_ACTUAL, APPLE_PMGR_PS_CLKGATE) | + APPLE_PMGR_FLAGS; + r->active_reads = 3; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_auto_enable(ps->regmap, 0), 1); + KUNIT_EXPECT_EQ(test, r->active_reads, 0U); + KUNIT_EXPECT_EQ(test, FIELD_GET(APPLE_PMGR_PS_ACTUAL, r->val), APPLE_PMGR_PS_ACTIVE); + KUNIT_EXPECT_TRUE(test, r->val & APPLE_PMGR_AUTO_ENABLE); + KUNIT_EXPECT_EQ(test, r->auto_writes, 1U); + KUNIT_EXPECT_EQ(test, r->busy_writes, 0U); +} + +/* Fused-off, already-AUTO, and reset/disabled words are left completely untouched. */ +static void pmgr_ps_auto_enable_skip_test(struct kunit *test) +{ + static const u32 skipped[] = { + 0x0f000300, /* fused off (J616c dcs_24-31) */ + 0x1f0000ff, /* already on AUTO_ENABLE */ + 0x0f0000ff | APPLE_PMGR_RESET, /* held in reset */ + 0x0f0000ff | APPLE_PMGR_PS_RESET, /* PS reset set */ + 0x0f0000ff | APPLE_PMGR_DEV_DISABLE, /* device disabled */ + }; + struct pmgr_ps_test_bank *b; + struct apple_pmgr_ps *ps; + + for (unsigned int i = 0; i < ARRAY_SIZE(skipped); i++) { + ps = pmgr_ps_test_consumer(test, skipped[i], &b); + KUNIT_EXPECT_EQ_MSG(test, apple_pmgr_ps_auto_enable(ps->regmap, 0), 0, + "word %#x", skipped[i]); + KUNIT_EXPECT_EQ_MSG(test, b->nr_log, 0U, "word %#x", skipped[i]); + KUNIT_EXPECT_EQ_MSG(test, b->word[0], skipped[i], "word %#x", skipped[i]); + } +} + +/* Stuck actual state times out without setting AUTO_ENABLE; read errors propagate. */ +static void pmgr_ps_auto_enable_fail_test(struct kunit *test) +{ + struct pmgr_ps_test_reg *r; + struct apple_pmgr_ps *ps; + + ps = pmgr_ps_test_named_domain(test, "apple-pmgr-ps-auto-stuck", + APPLE_PMGR_PS_CLKGATE, false, &r); + r->val = FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_ACTIVE) | + FIELD_PREP(APPLE_PMGR_PS_ACTUAL, APPLE_PMGR_PS_CLKGATE); + r->stuck = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_auto_enable(ps->regmap, 0), -ETIMEDOUT); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); + KUNIT_EXPECT_FALSE(test, r->val & APPLE_PMGR_AUTO_ENABLE); + + ps = pmgr_ps_test_named_domain(test, "apple-pmgr-ps-auto-err", + APPLE_PMGR_PS_ACTIVE, false, &r); + r->parent_read_error = true; + KUNIT_EXPECT_EQ(test, apple_pmgr_ps_auto_enable(ps->regmap, 0), -EIO); + KUNIT_EXPECT_EQ(test, r->auto_writes, 0U); +} + static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_power_on_test), KUNIT_CASE(pmgr_ps_power_off_undo_test), @@ -776,6 +850,9 @@ static struct kunit_case pmgr_ps_test_cases[] = { KUNIT_CASE(pmgr_ps_reset_refused_test), KUNIT_CASE(pmgr_ps_reset_idle_wait_test), KUNIT_CASE(pmgr_ps_reset_busy_no_idle_wait_test), + KUNIT_CASE(pmgr_ps_auto_enable_test), + KUNIT_CASE(pmgr_ps_auto_enable_skip_test), + KUNIT_CASE(pmgr_ps_auto_enable_fail_test), {} }; diff --git a/drivers/pmdomain/apple/pmgr-pwrstate.c b/drivers/pmdomain/apple/pmgr-pwrstate.c index 6745b4916365b..709037c9b2787 100644 --- a/drivers/pmdomain/apple/pmgr-pwrstate.c +++ b/drivers/pmdomain/apple/pmgr-pwrstate.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -79,6 +80,8 @@ struct apple_pmgr_ps { bool sleep_wakeup_path; /* Never enable automatic power management (apple,no-auto-pm). */ bool no_auto_pm; + /* Hardware auto-managed domain armed early at boot (apple,auto-managed). */ + bool auto_managed; bool inherited_on; bool no_auto_enable; bool needs_reset_idle_wait; @@ -437,7 +440,7 @@ static int apple_pmgr_ps_power_off(struct generic_pm_domain *genpd) if (ps->firmware_owned) return 0; - if (ps->inherited_on) + if (ps->inherited_on || ps->auto_managed) return -EBUSY; /* A live coprocessor keeps this domain through system sleep. */ if (ps->sleep_retained && ps->system_sleep) @@ -478,7 +481,7 @@ int apple_pmgr_ps_verify_state(struct device *domain_dev, bool on) !(genpd->flags & GENPD_FLAG_IRQ_SAFE)) return -EOPNOTSUPP; ps = genpd_to_apple_pmgr_ps(genpd); - if (ps->firmware_owned || ps->inherited_on) + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) return -EPERM; if (!on) mask |= APPLE_PMGR_AUTO_ENABLE; @@ -516,7 +519,7 @@ int apple_pmgr_ps_cycle(struct device_node *np) ret = -EPROBE_DEFER; goto out; } - if (ps->firmware_owned || ps->inherited_on) { + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) { ret = -EPERM; goto out; } @@ -591,7 +594,7 @@ static int apple_pmgr_ps_suspend_noirq(struct device *dev) u32 reg; ps->sleep_raised_by_other = false; - if (ps->firmware_owned || ps->inherited_on) + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) return 0; spin_lock_irqsave(&ps->genpd.slock, flags); @@ -640,7 +643,8 @@ static int apple_pmgr_ps_resume_noirq(struct device *dev) int ret; if (!pm_resume_via_firmware() || ps->firmware_owned || ps->inherited_on || - ps->sleep_driver_owned || apple_sleep_domain_is_down(dev->of_node)) + ps->auto_managed || ps->sleep_driver_owned || + apple_sleep_domain_is_down(dev->of_node)) return 0; spin_lock_irqsave(&ps->genpd.slock, flags); @@ -680,7 +684,7 @@ static int apple_pmgr_reset_assert(struct reset_controller_dev *rcdev, unsigned int ret; u32 reg; - if (ps->firmware_owned || ps->inherited_on) + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) return -EPERM; spin_lock_irqsave(&ps->genpd.slock, flags); @@ -718,7 +722,7 @@ static int apple_pmgr_reset_deassert(struct reset_controller_dev *rcdev, unsigne struct apple_pmgr_ps *ps = rcdev_to_apple_pmgr_ps(rcdev); unsigned long flags; - if (ps->firmware_owned || ps->inherited_on) + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) return -EPERM; if (ps->reset_time_us == APPLE_PMGR_T8132_RESET_TIME) @@ -760,7 +764,7 @@ static int apple_pmgr_reset_status(struct reset_controller_dev *rcdev, unsigned struct apple_pmgr_ps *ps = rcdev_to_apple_pmgr_ps(rcdev); u32 reg = 0; - if (ps->firmware_owned || ps->inherited_on) + if (ps->firmware_owned || ps->inherited_on || ps->auto_managed) return -EPERM; regmap_read(ps->regmap, ps->offset, ®); @@ -951,6 +955,9 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) ps->sleep_retained = of_property_read_bool(node, "apple,sleep-retained"); ps->sleep_driver_owned = of_property_read_bool(node, "apple,sleep-driver-owned"); ps->sleep_wakeup_path = of_property_read_bool(node, "apple,sleep-wakeup-path"); + /* A cold-started coprocessor CPU must not be gated behind its firmware. */ + ps->no_auto_pm = of_property_read_bool(node, "apple,no-auto-pm"); + ps->auto_managed = of_property_read_bool(node, "apple,auto-managed"); /* * Only T8132 hands over inherited-on domains with this contract. Older * M3 device trees carry the property with another meaning; keep them @@ -958,7 +965,7 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) */ ps->inherited_on = t8132 && of_property_read_bool(node, "apple,inherited-on"); if (ps->inherited_on && - (ps->firmware_owned || ps->sleep_retained || + (ps->firmware_owned || ps->sleep_retained || ps->auto_managed || of_property_present(node, "apple,min-state") || of_property_present(node, "apple,always-on") || of_property_present(node, "apple,force-disable") || @@ -966,8 +973,13 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) of_property_present(node, "apple,externally-clocked"))) return dev_err_probe(dev, -EINVAL, "conflicting inherited power policy\n"); + if (ps->auto_managed && + (ps->firmware_owned || ps->no_auto_pm || ps->no_auto_enable || t8132)) + return dev_err_probe(dev, -EINVAL, "conflicting auto-managed power policy\n"); + ret = of_property_read_u32(node, "apple,min-state", &ps->min_state); - if (ret == 0 && ps->min_state <= APPLE_PMGR_PS_ACTIVE && !ps->firmware_owned) + if (ret == 0 && ps->min_state <= APPLE_PMGR_PS_ACTIVE && + !ps->firmware_owned && !ps->auto_managed) regmap_update_bits(regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_PS_MIN, FIELD_PREP(APPLE_PMGR_PS_MIN, ps->min_state)); @@ -980,9 +992,6 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) if (of_property_read_bool(node, "apple,externally-clocked")) ps->externally_clocked = true; - /* A cold-started coprocessor CPU must not be gated behind its firmware. */ - ps->no_auto_pm = of_property_read_bool(node, "apple,no-auto-pm"); - /* * An inherited-on domain has readable state but no transition ownership. * A firmware-owned domain need not have a CPU-accessible state register; @@ -1003,9 +1012,19 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) return dev_err_probe(dev, ret, "cannot read power state\n"); active = ret; } - /* Legacy handoff DTs must also keep the throttle controller powered. */ - if (!ps->firmware_owned && !ps->inherited_on && - apple_pmgr_ps_always_on(node, ps->offset, name)) { + if (ps->auto_managed) { + if (!active) { + if (apple_pmgr_ps_always_on(node, ps->offset, name)) + return dev_err_probe(dev, -EIO, + "always-on auto-managed domain %s is off at boot\n", + name); + dev_dbg(dev, "auto-managed domain %s is off at boot, skipping\n", name); + return -ENODEV; + } + ps->genpd.flags |= GENPD_FLAG_ALWAYS_ON; + } else if (!ps->firmware_owned && !ps->inherited_on && + apple_pmgr_ps_always_on(node, ps->offset, name)) { + /* Legacy handoff DTs must also keep the throttle controller powered. */ ps->genpd.flags |= GENPD_FLAG_ALWAYS_ON; if (!active) { /* @@ -1035,7 +1054,8 @@ static int apple_pmgr_ps_probe(struct platform_device *pdev) } /* Turn on auto-PM if the domain is already on, unless it must stay off */ - if (active && !ps->firmware_owned && !ps->inherited_on && !ps->no_auto_enable) + if (active && !ps->firmware_owned && !ps->inherited_on && + !ps->no_auto_enable && !ps->auto_managed) regmap_update_bits(regmap, ps->offset, APPLE_PMGR_FLAGS | APPLE_PMGR_AUTO_ENABLE, ps->no_auto_pm ? 0 : APPLE_PMGR_AUTO_ENABLE); @@ -1390,6 +1410,124 @@ static const struct of_device_id apple_pmgr_ps_of_match[] = { MODULE_DEVICE_TABLE(of, apple_pmgr_ps_of_match); +/* + * Switch a power-state word left forced on by the boot loader (target 0xf, + * AUTO_ENABLE clear) to hardware automatic power management, early at boot, + * before the PMP starts: write target 0xf, wait for actual 0xf, then set + * AUTO_ENABLE. Words that are fused off, not forced on, held in reset, or + * already on AUTO_ENABLE are left untouched (returns 0). Returns 1 if + * switched, or a negative errno on read/write error or timeout. + */ +static int apple_pmgr_ps_auto_enable(struct regmap *regmap, u32 offset) +{ + u32 v; + int ret; + + ret = regmap_read(regmap, offset, &v); + if (ret) + return ret; + + if (FIELD_GET(APPLE_PMGR_PS_TARGET, v) != APPLE_PMGR_PS_ACTIVE || + (v & (APPLE_PMGR_AUTO_ENABLE | APPLE_PMGR_RESET | + APPLE_PMGR_PS_RESET | APPLE_PMGR_DEV_DISABLE))) + return 0; + + ret = regmap_write(regmap, offset, + (v & ~(APPLE_PMGR_FLAGS | APPLE_PMGR_BUSY | + APPLE_PMGR_PS_TARGET)) | + FIELD_PREP(APPLE_PMGR_PS_TARGET, APPLE_PMGR_PS_ACTIVE)); + if (ret) + return ret; + + ret = regmap_read_poll_timeout_atomic(regmap, offset, v, + FIELD_GET(APPLE_PMGR_PS_ACTUAL, v) == + APPLE_PMGR_PS_ACTIVE, + 1, APPLE_PMGR_PS_PARENT_TIMEOUT); + if (ret) + return ret; + + ret = regmap_write(regmap, offset, + (v & ~(APPLE_PMGR_FLAGS | APPLE_PMGR_BUSY)) | + APPLE_PMGR_AUTO_ENABLE); + return ret ?: 1; +} + +static const struct of_device_id apple_pmgr_of_match[] __initconst = { + { .compatible = "apple,t8103-pmgr" }, + { .compatible = "apple,pmgr" }, + {} +}; + +static bool __init apple_pmgr_ps_node_is_auto_managed(struct device_node *np) +{ + return of_match_node(apple_pmgr_ps_of_match, np) && + of_property_read_bool(np, "apple,auto-managed") && + !of_property_read_bool(np, "apple,no-auto-pm") && + !of_property_read_bool(np, "apple,firmware-owned") && + !of_property_read_bool(np, "apple,inherited-on") && + !of_device_is_compatible(np, "apple,t8132-pmgr-pwrstate"); +} + +/* + * Arm hardware automatic power management for DT-marked domains early at + * boot, before platform drivers (in particular the PMP) start: enabling + * AUTO_ENABLE on memory and fabric domains after the PMP is running freezes + * the SoC. + */ +static int __init apple_pmgr_ps_auto_init(void) +{ + struct device_node *pmgr_np; + unsigned int done = 0, failed = 0; + + for_each_matching_node(pmgr_np, apple_pmgr_of_match) { + struct regmap *regmap = NULL; + struct device_node *child; + + if (!of_device_is_available(pmgr_np)) + continue; + + for_each_available_child_of_node(pmgr_np, child) { + u32 offset; + int ret; + + if (!apple_pmgr_ps_node_is_auto_managed(child)) + continue; + + if (of_property_read_u32(child, "reg", &offset)) { + pr_warn("apple-pmgr-pwrstate: %pOF: missing reg property\n", + child); + continue; + } + + if (!regmap) { + regmap = syscon_node_to_regmap(pmgr_np); + if (IS_ERR(regmap)) { + pr_warn("apple-pmgr-pwrstate: %pOF: cannot map PMGR: %ld\n", + pmgr_np, PTR_ERR(regmap)); + of_node_put(child); + break; + } + } + + ret = apple_pmgr_ps_auto_enable(regmap, offset); + if (ret > 0) { + done++; + } else if (ret < 0) { + failed++; + pr_warn("apple-pmgr-pwrstate: %pOF: auto-enable failed: %d\n", + child, ret); + } + } + } + + if (done || failed) + pr_info("apple-pmgr-pwrstate: %u auto-managed domains enabled, %u failed\n", + done, failed); + + return 0; +} +arch_initcall(apple_pmgr_ps_auto_init); + static const struct dev_pm_ops apple_pmgr_ps_pm_ops = { LATE_SYSTEM_SLEEP_PM_OPS(apple_pmgr_ps_suspend_late, apple_pmgr_ps_resume_early) NOIRQ_SYSTEM_SLEEP_PM_OPS(apple_pmgr_ps_suspend_noirq, apple_pmgr_ps_resume_noirq) diff --git a/drivers/soc/apple/Kconfig b/drivers/soc/apple/Kconfig index d1f15e2ceca73..e83837cb404fb 100644 --- a/drivers/soc/apple/Kconfig +++ b/drivers/soc/apple/Kconfig @@ -162,6 +162,10 @@ config APPLE_SOC_SLEEP each by its match data: today T8140, T8132 and T6050. 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 + to an "apple,t6041-sleep" node and uses this driver's coprocessor + stop. + config APPLE_SOC_SLEEP_KUNIT_TEST bool "KUnit tests for the Apple SoC sleep match data" if !KUNIT_ALL_TESTS depends on APPLE_SOC_SLEEP && KUNIT=y diff --git a/drivers/soc/apple/Makefile b/drivers/soc/apple/Makefile index 6e82a01e4cd9f..be98f2a35d7ff 100644 --- a/drivers/soc/apple/Makefile +++ b/drivers/soc/apple/Makefile @@ -21,6 +21,7 @@ obj-$(CONFIG_APPLE_CLUSTER_PWRGATE) += apple-cluster-pwrgate.o obj-$(CONFIG_APPLE_SOC_SLEEP) += apple-sleep.o obj-$(CONFIG_APPLE_SOC_SLEEP) += t6050-aop.o apple-sleep-y = sleep.o +obj-$(CONFIG_APPLE_SOC_SLEEP) += t6041-sleep.o obj-$(CONFIG_APPLE_RTKIT) += apple-rtkit.o apple-rtkit-y = rtkit.o rtkit-crashlog.o diff --git a/drivers/soc/apple/aop.rs b/drivers/soc/apple/aop.rs index 7fb2939e239a4..89849f775d5c7 100644 --- a/drivers/soc/apple/aop.rs +++ b/drivers/soc/apple/aop.rs @@ -3185,6 +3185,13 @@ const HW_CFG_T6040: AopHwConfig = AopHwConfig { halt_on_failed_start: true, without_fw_regions: None, }; +/// T6041 (J616C): as T6040, with the AFK sleep and wake order macOS 26.6.2 uses on the J616C +/// (trace, 8 Nov 2026: sleep to these endpoints in this order, then the AP idle notice). +const HW_CFG_T6041: AopHwConfig = AopHwConfig { + sleep_endpoints: &[0x2b, 0x2a, 0x24, 0x20, 0x27, 0x26, 0x28, 0x25, 0x21, 0x29, 0x23, 0x22], + wake_endpoints: &[0x22, 0x23, 0x29, 0x21, 0x25, 0x28, 0x26, 0x27, 0x20, 0x24, 0x2a, 0x2b], + ..HW_CFG_T6040 +}; /// T8132 (J713): as T6040. The bootloader hands the AOP over the same way, with /// the DART's DAPF programmed and its windows reserved alongside the firmware /// segments. @@ -3329,7 +3336,7 @@ kernel::of_device_table!( (of::DeviceId::new(c_str!("apple,t8122-aop")), &HW_CFG_T8122), (of::DeviceId::new(c_str!("apple,t6020-aop")), &HW_CFG_T6020), (of::DeviceId::new(c_str!("apple,t8140-aop")), &HW_CFG_T8140), - (of::DeviceId::new(c_str!("apple,t6041-aop")), &HW_CFG_T6040), + (of::DeviceId::new(c_str!("apple,t6041-aop")), &HW_CFG_T6041), (of::DeviceId::new(c_str!("apple,t8132-aop")), &HW_CFG_T8132), (of::DeviceId::new(c_str!("apple,t6050-aop")), &HW_CFG_T6050), (of::DeviceId::new(c_str!("apple,t8142-aop")), &HW_CFG_T8142), diff --git a/drivers/soc/apple/display-gate.c b/drivers/soc/apple/display-gate.c index 7778598dc3f2b..dc57af0dd1651 100644 --- a/drivers/soc/apple/display-gate.c +++ b/drivers/soc/apple/display-gate.c @@ -3300,7 +3300,39 @@ static const struct gate_staged *t6041_max_stage(unsigned int i) /* Applied, they stay: the live tree refers to them. Only the KUnit test reverts them. */ static struct of_changeset t6041_max_cs[ARRAY_SIZE(t6041_max_stages)]; -/* Enable every node of stage @i and put its display DART into the display subsystem's iommus. */ +/* + * Whether @np needs a power domain that stays disabled: neither enabled nor one of the nodes + * stage @st enables. + */ +static bool __init t6041_max_needs_off_domain(const struct gate_staged *st, struct device_node *np) +{ + struct of_phandle_args args; + bool off = false; + unsigned int n; + int i; + + for (i = 0; !off && !of_parse_phandle_with_args(np, "power-domains", "#power-domain-cells", + i, &args); i++) { + off = !of_device_is_available(args.np); + for (n = 0; off && n < st->nr; n++) { + struct device_node *dn = of_find_node_by_path(st->nodes[n]); + + off = dn != args.np; + of_node_put(dn); + } + of_node_put(args.np); + } + return off; +} + +/* + * Enable every node of stage @i and put its display DART into the display subsystem's iommus. + * The in-tree trees give the chains no DISPEXT power domain: they are on as iBoot left them. A + * tree that does describe them (the J616c's bring-up EL2 tree: dispextN_fe, and PMP report + * entries above them, all disabled) loses the property on the chain's nodes here, or each + * device would wait for a domain provider that never comes and give up at the deferred probe + * timeout, and the display subsystem with them. + */ static int __init t6041_max_apply(unsigned int i, struct device_node *display) { const struct gate_staged *st = t6041_max_stage(i); @@ -3316,6 +3348,9 @@ static int __init t6041_max_apply(unsigned int i, struct device_node *display) for (n = 0; !ret && n < st->nr; n++) { np = of_find_node_by_path(st->nodes[n]); ret = np ? of_changeset_update_prop_string(cs, np, "status", "okay") : -ENODEV; + if (!ret && t6041_max_needs_off_domain(st, np)) + ret = of_changeset_remove_property(cs, np, + of_find_property(np, "power-domains", NULL)); of_node_put(np); } if (!ret) diff --git a/drivers/soc/apple/pm.rs b/drivers/soc/apple/pm.rs index e18e84bb1986a..d479bf866ae4c 100644 --- a/drivers/soc/apple/pm.rs +++ b/drivers/soc/apple/pm.rs @@ -38,6 +38,9 @@ extern "C" { fn sep_pm_keep_domains(dev: *mut c_void) -> c_int; fn sep_pm_clear_dev_disable(dev: *mut c_void) -> c_int; fn sep_pm_dart_restore(dev: *mut c_void); + fn sep_pm_dart_prepare(dev: *mut c_void) -> c_int; + fn sep_pm_wait_gated(dev: *mut c_void, timeout_ms: c_uint) -> c_int; + fn sep_pm_platform_commit() -> bool; fn sep_pm_commit_prepare( dev: *mut c_void, mbox: *mut c_void, @@ -128,6 +131,31 @@ pub(crate) fn commit_finish(dev: &kernel::device::Device) -> Option { } /// Puts the enclave's DART back if it lost its state, before the doorbell. +/// How long the enclave gets to gate its domain once it has answered (told at suspend). +const GATE_TIMEOUT_MS: u32 = 5000; + +/// Whether a sleep core commit sends the staged SLEEP; if not, it is sent at device suspend. +pub(crate) fn platform_commit() -> bool { + // SAFETY: only reads the sleep core's state. + unsafe { sep_pm_platform_commit() } +} + +/// Whether the enclave gated itself within the bound. +pub(crate) fn wait_gated(dev: &kernel::device::Device) -> bool { + // SAFETY: `dev` is the bound SEP device. + unsafe { sep_pm_wait_gated(dev.as_raw().cast(), GATE_TIMEOUT_MS) == 0 } +} + +/// Saves the enclave's DART while it can be read, before the enclave is told. +pub(crate) fn dart_prepare(dev: &kernel::device::Device) -> Result<()> { + // SAFETY: `dev` is the bound SEP device. + let rc = unsafe { sep_pm_dart_prepare(dev.as_raw().cast()) }; + if rc != 0 { + return Err(Error::from_errno(rc)); + } + Ok(()) +} + pub(crate) fn dart_restore(dev: &kernel::device::Device) { // SAFETY: `dev` is the bound SEP device. unsafe { sep_pm_dart_restore(dev.as_raw().cast()) }; diff --git a/drivers/soc/apple/pm_shim.c b/drivers/soc/apple/pm_shim.c index c1d415c0bd744..5f5ee20bd7db1 100644 --- a/drivers/soc/apple/pm_shim.c +++ b/drivers/soc/apple/pm_shim.c @@ -155,6 +155,39 @@ static struct device *sep_pm_dart(struct device *dev) return pdev ? &pdev->dev : NULL; } +/* + * Saves the enclave's DART while it can be read, before the enclave is told at suspend. Only + * a DART with apple,sleep-restore in its node is saved here and then left alone by its own + * callbacks. Without it, the DART's noirq suspend would read its registers after the enclave + * slept and its power domain went off, which hangs the suspend: refuse instead. + */ +int sep_pm_dart_prepare(void *ptr) +{ + struct device *dart = sep_pm_dart(ptr); + int ret; + + if (!dart) + return -ENODEV; + if (!apple_dart_sleep_listed(dart)) { + dev_err(dart, "no apple,sleep-restore list: the enclave can't sleep at suspend\n"); + put_device(dart); + return -EOPNOTSUPP; + } + ret = apple_dart_sleep_prepare(dart); + put_device(dart); + + return ret; +} + +/* + * Whether a sleep core commit sends the staged SLEEP (T8140). Without one, a firmware suspend + * (T6041's own sleep driver) tells the enclave at device suspend instead. + */ +bool sep_pm_platform_commit(void) +{ + return apple_sleep_commit_stops_coprocs(); +} + void sep_pm_dart_restore(void *ptr) { struct device *dart = sep_pm_dart(ptr); diff --git a/drivers/soc/apple/pmp.rs b/drivers/soc/apple/pmp.rs index fc492fa428d70..c8b9219e51c01 100644 --- a/drivers/soc/apple/pmp.rs +++ b/drivers/soc/apple/pmp.rs @@ -986,7 +986,9 @@ const HW_CFG_T6041: PmpHwConfig = PmpHwConfig { dma_mask: Some(DmaMask::new::<42>()), check_bootargs_uuid: true, coreanalytics: Ep7::Always, - sram_backup: None, + // 26.6.2 firmware (J616C): __DATA at 0x500761000, 0x7d000 bytes; the 27.2 firmware has it at + // 0x62000. Kept across a real sleep. + sram_backup: Some((0x61000, 0x7d000)), sram_backup_data: false, self_ack_start: false, confirm_ioreg_len: false, diff --git a/drivers/soc/apple/sep.rs b/drivers/soc/apple/sep.rs index a71d3ff0be3fb..fc5302b33bdac 100644 --- a/drivers/soc/apple/sep.rs +++ b/drivers/soc/apple/sep.rs @@ -231,6 +231,8 @@ const RNG_MAX_WORDS_PER_READ: usize = 16; // already being written can still go out once the sleep has begun; see // `send_entropy_request()`. const RNG_SLEEP_DRAIN_MS: u32 = proto::CONTROL_TIMEOUT_MS + 1000; +/// How long a full mailbox may take to drain before a sleep is refused. +const MAILBOX_DRAIN_MS: u32 = 100; extern "C" { fn sep_cancel_work_sync(work: *mut c_void); @@ -681,6 +683,11 @@ struct SepData { // The mailbox's receive interrupt is held off for the enclave's sleep. sleep_rx_held: Atomic, + /// Told at device suspend (no sleep core commit, T6041) rather than staged for the commit. + sleep_at_suspend: Atomic, + /// The enclave didn't answer a sleep request or a wake this boot: no deep sleep until a + /// reboot, as a commit over a running enclave resets the SoC. + sleep_unanswered: Atomic, #[pin] ool_xarm: Mutex>, @@ -1226,6 +1233,8 @@ impl SepData { phase: Atomic::new(PHASE_ATTACH), sleep_gate: Atomic::new(pm::SleepGate::Open as u32), sleep_rx_held: Atomic::new(false), + sleep_at_suspend: Atomic::new(false), + sleep_unanswered: Atomic::new(false), ool_xarm <- new_mutex!(Some(ool_xarm)), ool_sbio <- new_mutex!(Some(ool_sbio)), ool_sks <- new_mutex!(Some(ool_sks)), @@ -1543,6 +1552,10 @@ impl SepData { /// Prepare a firmware-driven suspend without sending SLEEP. The platform /// owns the irreversible request, after every returnable refusal. pub(crate) fn sleep_enter(&self) -> Result<()> { + // T6041: its sleep driver has no sleep core commit, so the enclave is told now. + if !pm::platform_commit() { + return self.sleep_enter_at_suspend(); + } match self.sleep_gate() { // A failed earlier wake is not repaired by another precommit attempt. pm::SleepGate::Lost => return Err(EIO), @@ -1557,6 +1570,14 @@ impl SepData { ); return Err(EBUSY); } + // Refused here, at once, rather than at the commit after its send wait. + if !self.mailbox_drains() { + dev_err_ratelimited!( + self.dev, + "deep sleep refused: the enclave isn't taking messages (its mailbox stays full)\n" + ); + return Err(EBUSY); + } self.set_sleep_gate(pm::SleepGate::Draining); let idle = control::wait_idle( @@ -1586,6 +1607,195 @@ impl SepData { Ok(()) } + /// Without a sleep core commit (T6041): tell the enclave at device suspend, seconds before + /// the platform's commit, which answers, saves its state and gates its own domain (waited + /// for in suspend_noirq). A deep sleep commits only over an enclave that is asleep. + fn sleep_enter_at_suspend(&self) -> Result<()> { + if self.sleep_unanswered.load(Relaxed) { + dev_err_ratelimited!( + self.dev, + "deep sleep refused: the enclave did not answer a sleep request or wake earlier this boot\n" + ); + return Err(EBUSY); + } + match self.sleep_gate() { + // Gated already at an earlier, refused sleep: it stays asleep until a real wake. + pm::SleepGate::Lost if self.sleep_at_suspend.load(Relaxed) => return Ok(()), + pm::SleepGate::Lost => { + dev_err_ratelimited!( + self.dev, + "deep sleep refused: the enclave did not come back from a sleep earlier this boot\n" + ); + return Err(EBUSY); + } + pm::SleepGate::Open => {} + _ => return Err(EBUSY), + } + // One that didn't come up still runs: a commit over it resets the SoC. + if self.phase.load(Relaxed) != PHASE_READY || !self.endpoint_present(proto::EP_CONTROL) { + dev_err_ratelimited!( + self.dev, + "deep sleep refused: the enclave did not finish coming up, so it can't be put to sleep\n" + ); + return Err(EBUSY); + } + if !self.mailbox_drains() { + dev_err_ratelimited!( + self.dev, + "deep sleep refused: the enclave isn't taking messages (its mailbox stays full)\n" + ); + return Err(EBUSY); + } + + self.set_sleep_gate(pm::SleepGate::Draining); + let idle = control::wait_idle( + proto::CONTROL_TIMEOUT_MS, + 10, + || self.control.lock().requests_in_flight(), + |ms| kernel::time::delay::fsleep(kernel::time::Delta::from_millis(i64::from(ms))), + ); + if !idle { + dev_err_ratelimited!( + self.dev, + "sleep refused: a request is still waiting for its reply\n" + ); + self.set_sleep_gate(pm::SleepGate::Open); + return Err(EBUSY); + } + + if let Err(e) = pm::dart_prepare(&self.dev) { + dev_err_ratelimited!( + self.dev, + "sleep refused: its DART could not be saved ({:?})\n", + e + ); + self.set_sleep_gate(pm::SleepGate::Open); + return Err(e); + } + + self.sleep_at_suspend.store(true, Relaxed); + match self.sleep_request() { + Ok(()) => { + if let Some(mbox) = self.mbox.lock().as_ref() { + mbox.set_recv_enabled(false); + } + self.sleep_hold_rx(); + self.set_sleep_gate(pm::SleepGate::Told); + dev_dbg!(self.dev, "the enclave answered the sleep request\n"); + Ok(()) + } + Err(e) => { + dev_err_ratelimited!( + self.dev, + "sleep refused: no answer to the sleep request ({:?})\n", + e + ); + self.sleep_unanswered.store(true, Relaxed); + // A request that timed out may still have been taken. + self.set_sleep_gate(pm::SleepGate::Told); + self.sleep_exit(); + Err(e) + } + } + } + + /// Asks the enclave to go to sleep (told at suspend). The request is sent past the gate. + fn sleep_request(&self) -> Result<()> { + let op = proto::op_sleep(); + let tag = proto::TAG_SLEEP; + let idx = self.control.lock().alloc_sleep()?; + let msg = proto::encode_control(&op, tag); + + let sent = match self.mbox.lock().as_ref() { + Some(mbox) => Self::ring(mbox, msg), + None => Err(ENODEV), + }; + if let Err(e) = sent { + self.control.lock().abandon(idx); + return Err(e); + } + match self.control_wait(&op, idx, tag)? { + Some(_) => Ok(()), + None => Err(ETIMEDOUT), + } + } + + /// The wake of an enclave told at suspend: a real wake starts it, a refused sleep finds + /// it gated (it stays asleep until the next real sleep) or asks whether it still answers. + fn sleep_exit_at_suspend(&self) -> bool { + let gate = self.sleep_gate(); + if gate == pm::SleepGate::Draining { + self.set_sleep_gate(pm::SleepGate::Open); + return false; + } + if !gate.needs_wake() { + return false; + } + // SAFETY: only reads a flag. + let real = unsafe { bindings::pm_resume_via_firmware() }; + if !real && gate == pm::SleepGate::Lost { + return false; + } + let answered = if real { + self.sleep_kick() + } else if pm::wait_gated(&self.dev) { + self.sleep_hold_rx(); + self.set_sleep_gate(pm::SleepGate::Lost); + dev_warn_ratelimited!( + self.dev, + "the enclave stays asleep until the next real sleep or a reboot\n" + ); + return false; + } else { + dev_warn_ratelimited!(self.dev, "the enclave never gated its power domain\n"); + self.sleep_probe() + }; + match answered { + Ok(()) => { + self.sleep_at_suspend.store(false, Relaxed); + self.set_sleep_gate(pm::SleepGate::Open); + // One line per sleep it was told of: nothing else says it came back. + dev_info_ratelimited!(self.dev, "the enclave is back from its sleep request\n"); + true + } + Err(e) => { + dev_err_ratelimited!( + self.dev, + "the enclave did not come back ({:?}); it stays unused\n", + e + ); + self.sleep_unanswered.store(true, Relaxed); + self.sleep_hold_rx(); + self.set_sleep_gate(pm::SleepGate::Lost); + false + } + } + } + + /// Whether an enclave that was told and never gated still answers. + fn sleep_probe(&self) -> Result<()> { + pm::dart_restore(&self.dev); + self.sleep_release_rx(); + let op = proto::op_nop(0); + let (idx, tag) = self.control.lock().alloc()?; + let msg = proto::encode_control(&op, tag); + let sent = match self.mbox.lock().as_ref() { + Some(mbox) => { + mbox.set_recv_enabled(true); + Self::ring(mbox, msg) + } + None => Err(ENODEV), + }; + if let Err(e) = sent { + self.control.lock().abandon(idx); + return Err(e); + } + match self.control_wait(&op, idx, tag)? { + Some(_) => Ok(()), + None => Err(ETIMEDOUT), + } + } + /// Stage without sending; the platform's commit owns SLEEP with IRQs off. fn sleep_leave_for_commit(&self) -> Result<()> { let request = proto::encode_control(&proto::op_sleep(), proto::TAG_SLEEP); @@ -1604,6 +1814,20 @@ impl SepData { Ok(()) } + /// Whether the enclave takes messages: its receive FIFO drains within `MAILBOX_DRAIN_MS`. A + /// FIFO that stays full means it stopped reading, and a sleep request would only time out. + fn mailbox_drains(&self) -> bool { + for _ in 0..MAILBOX_DRAIN_MS / 5 { + match self.mbox.lock().as_ref() { + Some(mbox) if mbox.send_ready() => return true, + Some(_) => {} + None => return false, + } + kernel::time::delay::fsleep(kernel::time::Delta::from_millis(5)); + } + false + } + /// Holds off the receive interrupt, whose handler reads the mailbox. fn sleep_hold_rx(&self) { if !self.sleep_rx_held.xchg(true, Relaxed) { @@ -1625,6 +1849,9 @@ impl SepData { /// A sent request can be restarted only after actual physical sleep/wake. /// Returns whether the enclave came back from a sleep it was told of. pub(crate) fn sleep_exit(&self) -> bool { + if self.sleep_at_suspend.load(Relaxed) { + return self.sleep_exit_at_suspend(); + } // Staged only: an unsent refusal releases RX without a restart. match pm::commit_finish(&self.dev) { Some(true) => self.set_sleep_gate(pm::SleepGate::Told), diff --git a/drivers/soc/apple/shim.h b/drivers/soc/apple/shim.h index 1ca60f1b338a8..4a691f2b62a40 100644 --- a/drivers/soc/apple/shim.h +++ b/drivers/soc/apple/shim.h @@ -33,6 +33,8 @@ int sep_pm_keep_domains(void *dev); int sep_pm_wait_gated(void *dev, unsigned int timeout_ms); int sep_pm_clear_dev_disable(void *dev); void sep_pm_dart_restore(void *dev); +int sep_pm_dart_prepare(void *dev); +bool sep_pm_platform_commit(void); int sep_pm_commit_prepare(void *dev, void *mbox, u64 msg0, u32 msg1, u64 reply, u64 mask); int sep_pm_commit_finish(void *dev); extern const struct dev_pm_ops sep_pm_ops; diff --git a/drivers/soc/apple/sleep.c b/drivers/soc/apple/sleep.c index da88e301a3cb4..7f93efef9ec5a 100644 --- a/drivers/soc/apple/sleep.c +++ b/drivers/soc/apple/sleep.c @@ -1653,9 +1653,18 @@ bool apple_sleep_coproc_stopped(struct device *dev) } EXPORT_SYMBOL_GPL(apple_sleep_coproc_stopped); +static bool apple_sleep_external_commit; + +void apple_sleep_set_commit_stops_coprocs(bool enable) +{ + WRITE_ONCE(apple_sleep_external_commit, enable); +} +EXPORT_SYMBOL_GPL(apple_sleep_set_commit_stops_coprocs); + bool apple_sleep_commit_stops_coprocs(void) { - return READ_ONCE(apple_sleep) && pm_suspend_via_firmware(); + return (READ_ONCE(apple_sleep) || READ_ONCE(apple_sleep_external_commit)) && + pm_suspend_via_firmware(); } EXPORT_SYMBOL_GPL(apple_sleep_commit_stops_coprocs); @@ -1673,7 +1682,8 @@ static void apple_sleep_coproc_run_off(struct apple_sleep_coproc *c) c->stopped = true; return; } - if (!apple_sleep->soc->regions) + /* T6041's own sleep driver runs this without the sleep core. */ + if (!apple_sleep || !apple_sleep->soc->regions) c->status = readl(c->asc + ASC_CPU_STATUS); writel(readl(c->asc + ASC_CPU_CONTROL) & ~ASC_CPU_CONTROL_RUN, c->asc + ASC_CPU_CONTROL); writel(readl(c->asc + ASC_CPU_CONTROL) & ~ASC_CPU_CONTROL_RUN, c->asc + ASC_CPU_CONTROL); @@ -1792,6 +1802,87 @@ static void apple_sleep_coprocs_stop(struct apple_sleep *s, bool first) dsb(sy); } +/* + * For a SoC whose sleep has its own driver at EL2 (T6041): last refusal checks + * before any irreversible enclave or coprocessor stop. + */ +int apple_sleep_coprocs_check_all(void) +{ + int i, ret; + + for (i = 0; i < SLEEP_COPROCS; i++) { + struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; + + if (!c->dev || !c->ready || c->stopped || !c->last_check) + continue; + ret = c->last_check(c->data); + if (ret) { + dev_err(c->dev, "refused at sleep commit: %d\n", ret); + return ret; + } + } + + return 0; +} + +/* + * For a SoC whose sleep has its own driver at EL2 (T6041): run the enclave's + * irreversible sleep request with interrupts off. A nonzero return guarantees + * no SLEEP request was sent. + */ +int apple_sleep_enclave_stop_all(void) +{ + int ret; + + if (!apple_sleep_enclave.stop) + return 0; + ret = apple_sleep_enclave.stop(apple_sleep_enclave.data); + if (ret && apple_sleep_enclave.dev) + dev_err(apple_sleep_enclave.dev, + "refused before SEP SLEEP was sent: %d\n", ret); + + return ret; +} + +/* + * For a SoC whose sleep has its own driver at EL2 (T6041): both passes of the stop above, + * the coprocessors registered first, then the rest. Past the refusal boundary every ready + * coprocessor is still halted even if one @last_stop reports a negative error. + */ +int apple_sleep_coprocs_stop_all(void) +{ + int pass, i, ret, first_err = 0; + + for (pass = 1; pass >= 0; pass--) { + for (i = 0; i < SLEEP_COPROCS; i++) { + struct apple_sleep_coproc *c = &apple_sleep_coprocs[i]; + + if (!c->dev || !c->ready || c->first != pass || c->stopped) + continue; + if (c->last_stop) { + ret = c->last_stop(c->data); + if (ret < 0 && !first_err) + first_err = ret; + } + apple_sleep_coproc_run_off(c); + } + } + dsb(sy); + return first_err; +} + +/* For T6041: whether the coprocessor behind the storage PCIe link (ANS) was stopped. */ +bool apple_sleep_coprocs_ans_stopped(void) +{ + int i; + + for (i = 0; i < SLEEP_COPROCS; i++) + if (apple_sleep_coprocs[i].dev && apple_sleep_coprocs[i].pcie_ans && + apple_sleep_coprocs[i].stopped) + return true; + return false; +} + const struct apple_sleep_smc_policy *apple_sleep_smc_policy(void) { return apple_sleep && pm_suspend_via_firmware() ? apple_sleep->soc->smc_policy : NULL; diff --git a/drivers/soc/apple/t6041-sleep.c b/drivers/soc/apple/t6041-sleep.c new file mode 100644 index 0000000000000..35259580fc6f0 --- /dev/null +++ b/drivers/soc/apple/t6041-sleep.c @@ -0,0 +1,2296 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T6041 (M4 Max) system sleep, at EL2 with no monitor below. + * + * It runs macOS 26.6.2's last steps before the S2R commit, in macOS's order and + * with its values, as traced from macOS sleeping under aura's hypervisor, and + * commits; aura's S2R mailbox brings the boot core back to cpu_resume on the + * wake, and the driver restores what the sleep took. + * + * Needs the kernel at EL2 (CTXR window) and the "aurora,rvbar-spin-table" CPU + * enable method, so the other cores can leave the kernel. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define SYS_APL_IPI_SR_EL1 sys_reg(3, 5, 15, 1, 1) +#define IPI_SR_PENDING BIT(0) +#define SYS_APL_SIQ_CFG_EL1 sys_reg(3, 4, 15, 10, 4) +#define SYS_APL_DEEP_SLEEP sys_reg(3, 5, 15, 6, 2) +#define DEEP_SLEEP_BITS (BIT(0) | BIT(63)) + +#define KA_WORDS 32 +#define KA_STRIDE 0x44 + +#define PS_AUTO_ENABLE BIT(28) +#define PS_AUTO_STATE GENMASK(27, 24) +#define PS_FLAGS GENMASK(9, 8) +#define PS_ACTUAL GENMASK(7, 4) +#define PS_TARGET GENMASK(3, 0) + +#define SPMI_STATUS 0x00 +#define SPMI_CMD 0x04 +#define SPMI_REPLY 0x08 +#define SPMI_RX_EMPTY BIT(24) +#define SPMI_TX_EMPTY BIT(8) +#define SPMI_IDLE (SPMI_RX_EMPTY | SPMI_TX_EMPTY) +#define SPMI_DRAIN_MAX 16 +#define SPMI_NOTIFY_MASK 0x40 +#define SPMI_IRQ_ACK 0x80 +#define PMU_SID 0xb + +#define PERF_BUSY BIT(31) +#define PERF_ACTUAL GENMASK(11, 8) + +#define AMCC_MAX_GROUPS 8 +#define AMCC_ERR_OFF 0x25000 +#define AMCC_PLANE_STRIDE 0x40000 +#define AMCC_MIN_SIZE 0x1c2848 + +#define DCS_CH_STRIDE 0x200000UL +#define DCS_CH_SIZE 0x40 + +#define PTD_SOC_DEV_REQ_READ 0x01e00 +#define PTD_SOC_DEV_REQ_WRITE 0x10f00 +#define PTD_CLUSTER_WRITE_0 0x10f80 +#define PTD_CLUSTER_WRITE_1 0x10f88 +#define PTD_CLUSTER_WRITE_2 0x10f90 +#define PTD_CLUSTER_WRITE_3 0x10fa0 +#define PTD_MIN_SIZE 0x10fa8 + +#define AOP_PS_WORDS 44 + +#define WAKE_WORDS 9 +#define WAKE_LAST_MASK 0x00003fffU +#define WAKE_MAX_ID (32 * (WAKE_WORDS - 1) + 14) +#define WAKE_SOURCES_MAX 64 + +#define AXI2AF_ATC_COUNT 4 +#define AXI2AF_DISP_FIRST 4 +#define AXI2AF_DISP_COUNT 5 +#define AXI2AF_REG_COUNT 10 +#define AXI2AF_COUNT 15 +#define AXI2AF_ANS 9 +#define AXI2AF_APCIE 14 + +#define T6041_CPU_COUNT 16 +#define T6041_CPM_COUNT 3 +#define T6041_COMMIT_SIO_COUNT 2 +#define T6041_COMMIT_PERIPH_COUNT 5 +#define T6041_FULL_DETECT_COUNT 2 +#define T6041_MAX_PMGR_BANKS 16 +#define T6041_PS_MAX_DEPTH 16 + +enum t6041_apcie_ps { + T6041_APCIE_ANS, + T6041_APCIE_GP, + T6041_APCIE_SYS_GP, + T6041_APCIE_ST0, + T6041_APCIE_SYS_ST0, + T6041_APCIE_ST1, + T6041_APCIE_SYS_ST1, + T6041_APCIE_PHY_SW, + T6041_APCIE_PS_COUNT, +}; + +/* aura's struct aura_s2r_mailbox (aura PR 117). */ +#define T6041_S2R_MAGIC 0x3152325341525541ULL /* "AURAS2R1" */ +struct t6041_s2r_mailbox { + u64 magic; + u64 boot_mpidr; + u64 resume_pa; + u64 resumes; +}; + +struct t6041_sleep { + struct device *dev; + struct t6041_s2r_mailbox *mbox; + /* PMGR power-state words resolved from DT phandles. */ + void __iomem **ps_off; + unsigned int n_off; + void __iomem **ps_atc_off; + unsigned int n_atc_off; + void __iomem **ps_auto; + unsigned long *ps_auto_mem; + unsigned int n_auto; + void __iomem **ps_auto_clkgate; + unsigned long *ps_auto_clkgate_mem; + unsigned int n_auto_clkgate; + void __iomem **ps_auto_active; + unsigned int n_auto_active; + void __iomem **ps_keep_on; + unsigned int n_keep_on; + void __iomem **ps_restore; + unsigned int n_restore; + void __iomem *ps_cpu[T6041_CPU_COUNT]; + void __iomem *ps_cpm[T6041_CPM_COUNT]; + void __iomem *ps_sep; + void __iomem *ps_spmi_a0; + void __iomem *ps_atc_common[AXI2AF_ATC_COUNT]; + void __iomem *ps_atc_fabric; + void __iomem *ps_atc_afi; + void __iomem *ps_apcie[T6041_APCIE_PS_COUNT]; + void __iomem *ps_commit_sio[T6041_COMMIT_SIO_COUNT]; + void __iomem *ps_commit_periph[T6041_COMMIT_PERIPH_COUNT]; + void __iomem *ps_axi2af[AXI2AF_COUNT]; + void __iomem *ps_full_detect[T6041_FULL_DETECT_COUNT]; + void __iomem *cluster; + void __iomem *pwrgate; + void __iomem *misc; + void __iomem *wdt; + void __iomem *aon; + void __iomem *commit; + void __iomem *clkgen; + void __iomem *spmi; + void __iomem *spmi_a0; + void __iomem *pmc; + void __iomem *ka[2]; /* keep-alive tables, 1 from iBoot, 0 at macOS's commit */ + unsigned int ngroups; /* AMCCs of four planes: 8 on full T6041, 6 on binned */ + void __iomem *dcs[4 * AMCC_MAX_GROUPS]; + void __iomem *amccb[AMCC_MAX_GROUPS]; + void __iomem *wake; /* SLP_DDR +0, wake masks +0x0c..+0x2c */ + void __iomem *perf; /* SoC perf +0, DCS perf +0x400 */ + void __iomem *axi2af[AXI2AF_COUNT]; + void __iomem *ptd; /* PTD read (+0x0) and write (+0x10000) pages */ + u32 wake_masks[WAKE_WORDS]; + int stop_ret; + int coproc_ret; + int apcie_ret; + unsigned int atc_late; + unsigned int off_late; + unsigned int dcs_late; + u32 cpu_off_late; + u32 cpm_off_late; + unsigned int spmi_late; + unsigned int ps_late; + unsigned int gp_late; + /* Saved as the commit starts, put back by t6041_sleep_return(). */ + u64 cntkctl; + u64 siq_cfg; + u32 *ps_pre; + u32 pre_perf[2]; + u32 pre_pmc[5]; + u32 pre_clk[4]; + u32 pre_mask[2]; + u32 pre_wake[WAKE_WORDS]; + u32 pre_votes[5]; + /* Each AMCC plane's cache ways (+0x2800) and status (+0x2804). */ + u32 pre_ways[4 * AMCC_MAX_GROUPS]; + u32 pre_cache[4 * AMCC_MAX_GROUPS]; + bool pre_a0; + /* GP PCIe ports 0/1: port block, PHY word, and saved state. */ + void __iomem *gp_port[2]; + void __iomem *gp_phy[2]; + u32 gp_phy_pre[2]; + u32 gp_app_pre[2]; + u32 gp_perst_pre[2]; + bool gp_saved; + /* ANS's storage PCIe block and bootloader-supplied tunables (apple,apcie). */ + void __iomem *ap_rc; + void __iomem *ap_phy; + void __iomem *ap_phy_ip; + void __iomem *ap_axi; + void __iomem *ap_cio3pll; + void __iomem *ap_clkgen; + struct apple_tunable *tun_axi2af; + struct apple_tunable *tun_cio3pll; + struct apple_tunable *tun_clkgen; + struct apple_tunable *tun_phy; + struct apple_tunable *tun_phy_ip_pll; + struct apple_tunable *tun_phy_ip_lanes; + bool apcie_ready; + bool ans_stopped; + /* The AOP island's 44 MiniPMGR power words (ps-aop). */ + void __iomem *aop_ps; + u32 aop_pre[AOP_PS_WORDS]; + /* AP GPIO block (apple,pinctrl), saved/restored across deep sleep. */ + void __iomem *gpio; + u32 npins; + u32 *gpio_pre; + unsigned long *gpio_skip; +}; + +static struct t6041_sleep *t6041_sleep; + +/* ADT cpu number: E 0-3, P0 4-9, P1 10-15. */ +static unsigned int t6041_cpu_id(u64 mpidr) +{ + unsigned int cl = MPIDR_AFFINITY_LEVEL(mpidr, 1); + unsigned int core = MPIDR_AFFINITY_LEVEL(mpidr, 0); + + return cl == 0 ? core : cl == 1 ? 4 + core : 10 + core; +} + +/* + * Pure counter + cpu_relax() busy-spin helpers for the sleep commit path. + * Never call udelay()/mdelay()/readl_poll_timeout_atomic() once CPU/CPM + * PS_TARGET = 0 or cluster power-down is armed: arm64's delay_loop uses + * WFIT/WFET, which lets the sleep hardware power-gate the boot core early. + */ +static void t6041_spin_us(u64 us) +{ + u64 t0 = arch_timer_read_counter(); + u64 ticks = DIV_ROUND_UP_ULL(us * arch_timer_get_cntfrq(), USEC_PER_SEC); + + while (arch_timer_read_counter() - t0 < ticks) + cpu_relax(); +} + +#define t6041_poll_until_us(addr, val, cond, timeout_us) ({ \ + u64 __t0 = arch_timer_read_counter(); \ + u64 __ticks = DIV_ROUND_UP_ULL((u64)(timeout_us) * \ + arch_timer_get_cntfrq(), USEC_PER_SEC); \ + bool __timed_out = false; \ + int __ret = 0; \ + \ + for (;;) { \ + (val) = readl(addr); \ + if (cond) \ + break; \ + if (__timed_out) { \ + __ret = -ETIMEDOUT; \ + break; \ + } \ + if (arch_timer_read_counter() - __t0 >= __ticks) \ + __timed_out = true; \ + else \ + cpu_relax(); \ + } \ + __ret; \ +}) + +/* + * A core's last WFI, as the Neo's and the Air's t8140_deep_wfi() and macOS's + * last-WFI routine with x0 = 1: timers masked, the deep-sleep bits (C6_2 bit 0 + * and 63) set, then WFI for good. (Not the runtime offline branch, which leaves + * C6_2 clear.) + */ +static void __noreturn t6041_offline_wfi(void) +{ + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntp_ctl_el0); + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntv_ctl_el0); + sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_BITS); + isb(); + while (true) { + dsb(sy); + isb(); + wfi(); + aic_sleep_ack(); + write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); + } +} + +static void t6041_cpu_stop(u64 mpidr) +{ + writel(BIT(t6041_cpu_id(mpidr)), t6041_sleep->misc + 0x0); + dsb(sy); +} + +static int t6041_cpu_on(u64 mpidr) +{ + void __iomem *misc = t6041_sleep->misc; + unsigned int cl = MPIDR_AFFINITY_LEVEL(mpidr, 1); + + writel(BIT(t6041_cpu_id(mpidr)), misc + 0x4); + writel(BIT(MPIDR_AFFINITY_LEVEL(mpidr, 0)), misc + 0x8 + 4 * cl); + return 0; +} + +static void t6041_ps_lower(void __iomem *reg) +{ + u32 val = readl(reg); + + if (val & PS_AUTO_ENABLE) { + val &= ~(PS_AUTO_ENABLE | PS_FLAGS); + writel(val, reg); + } + writel((val & ~PS_TARGET) | PS_FLAGS, reg); +} + +/* One byte to a PMU register over nub-spmi0: command, then data. */ +static void t6041_pmu_write(struct t6041_sleep *s, u16 reg, u8 val) +{ + unsigned int i; + u32 status; + + /* Drain any stale reply before issuing our command. */ + for (i = 0; i < SPMI_DRAIN_MAX && !(readl(s->spmi + SPMI_STATUS) & SPMI_RX_EMPTY); i++) + readl(s->spmi + SPMI_REPLY); + writel((u32)reg << 16 | BIT(15) | PMU_SID << 8 | 0x30, s->spmi + SPMI_CMD); + writel(val, s->spmi + SPMI_CMD); + if (t6041_poll_until_us(s->spmi + SPMI_STATUS, status, + !(status & SPMI_RX_EMPTY), 1000)) + s->spmi_late++; + for (i = 0; i < SPMI_DRAIN_MAX && !(readl(s->spmi + SPMI_STATUS) & SPMI_RX_EMPTY); i++) + readl(s->spmi + SPMI_REPLY); + writel(1, s->spmi + SPMI_IRQ_ACK); +} + +static void cpm_gates(struct t6041_sleep *s) +{ + writel(0x80000000, s->pwrgate + 0x100); + writel(0x80000000, s->pwrgate + 0x108); + writel(0x80000000, s->pwrgate + 0x110); +} + +static void t6041_ps_match_list(void __iomem *const *regs, + const unsigned long *may_be_fused, + unsigned int count, u32 mask, u32 want) +{ + unsigned int i; + + for (i = 0; i < count; i++) { + u32 now = readl(regs[i]); + + if (may_be_fused && test_bit(i, may_be_fused) && + !(now & (PS_TARGET | PS_ACTUAL))) + continue; + if ((now & mask) != want) + writel((now & ~mask) | want, regs[i]); + } +} + +/* + * Put every matched PS word into its macOS commit mode: hardware AUTO (off, + * clock-gated, or active) or manual active. Only fused-off AMCC/DCS channel + * slices on 24-channel binned parts (reading 0 for both target and actual) + * are skipped; idle non-channel domains such as fab6_soc must still enter + * hardware AUTO. + */ +static void t6041_ps_match_all(struct t6041_sleep *s) +{ + const u32 auto_mask = PS_TARGET | PS_AUTO_ENABLE | PS_AUTO_STATE; + + t6041_ps_match_list(s->ps_auto, s->ps_auto_mem, s->n_auto, auto_mask, + PS_TARGET | PS_AUTO_ENABLE | FIELD_PREP(PS_AUTO_STATE, 0)); + t6041_ps_match_list(s->ps_auto_clkgate, s->ps_auto_clkgate_mem, + s->n_auto_clkgate, auto_mask, + PS_TARGET | PS_AUTO_ENABLE | FIELD_PREP(PS_AUTO_STATE, 4)); + t6041_ps_match_list(s->ps_auto_active, NULL, s->n_auto_active, auto_mask, + PS_TARGET | PS_AUTO_ENABLE | FIELD_PREP(PS_AUTO_STATE, 0xf)); + t6041_ps_match_list(s->ps_keep_on, NULL, s->n_keep_on, + PS_TARGET | PS_AUTO_ENABLE, PS_TARGET); +} + +static void t6041_cpu_off(u64 mpidr) +{ + t6041_offline_wfi(); +} + +static const struct spin_table_power_ops t6041_cpu_power_ops = { + .cpu_stop = t6041_cpu_stop, + .cpu_off = t6041_cpu_off, + .cpu_on = t6041_cpu_on, +}; + +static void __noreturn t6041_boot_wfi(struct t6041_sleep *s) +{ + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntp_ctl_el0); + write_sysreg(ARCH_TIMER_CTRL_IT_MASK, cntv_ctl_el0); + sysreg_clear_set_s(SYS_APL_DEEP_SLEEP, 0, DEEP_SLEEP_BITS); + while (aic_sleep_ack()) + ; + while (true) { + dsb(sy); + isb(); + wfi(); + aic_sleep_ack(); + write_sysreg_s(IPI_SR_PENDING, SYS_APL_IPI_SR_EL1); + } +} + +/* + * Raise each present core and all three CPM PS words to on, then drop their + * targets to 0 so the hardware drops PS_ACTUAL when each core and cluster + * enters deep WFI. Clear any stray target/auto bits on absent/fused-off cores + * (e.g. pcpu0_5 / pcpu1_5 on 14-core binned parts) without raising them. + */ +static void t6041_cpu_ps_match(struct t6041_sleep *s) +{ + const u32 cpu_clear = PS_TARGET | PS_AUTO_ENABLE | PS_AUTO_STATE; + DECLARE_BITMAP(present, T6041_CPU_COUNT); + unsigned int cpu, i; + u32 v; + + bitmap_zero(present, T6041_CPU_COUNT); + for_each_present_cpu(cpu) { + unsigned int id = t6041_cpu_id(cpu_logical_map(cpu)); + void __iomem *reg = s->ps_cpu[id]; + + __set_bit(id, present); + v = readl(reg); + writel((v & ~cpu_clear) | PS_TARGET, reg); + t6041_poll_until_us(reg, v, FIELD_GET(PS_ACTUAL, v) == 0xf, 2000); + } + for (i = 0; i < T6041_CPM_COUNT; i++) { + void __iomem *reg = s->ps_cpm[i]; + + v = readl(reg); + writel((v & ~cpu_clear) | PS_TARGET, reg); + t6041_poll_until_us(reg, v, FIELD_GET(PS_ACTUAL, v) == 0xf, 2000); + } + for (i = 0; i < T6041_CPU_COUNT; i++) { + void __iomem *reg = s->ps_cpu[i]; + + if (test_bit(i, present)) { + writel(readl(reg) & ~PS_TARGET, reg); + } else { + v = readl(reg); + if (v & cpu_clear) + writel(v & ~cpu_clear, reg); + } + } + for (i = 0; i < T6041_CPM_COUNT; i++) { + void __iomem *reg = s->ps_cpm[i]; + + writel(readl(reg) & ~PS_TARGET, reg); + } +} + +/* + * Lower every USB-C port's power domains in macOS's deepest-first order + * (phymxwrap -> usb -> usb_aon -> common_dp, then cio/pcie -> common) and + * wait for each domain to reach PS_ACTUAL == 0, then hand fab2_soc and afi + * to hardware AUTO (forcing them off hangs T6041). + */ +static void t6041_atc_down(struct t6041_sleep *s) +{ + unsigned int i; + u32 v; + + for (i = 0; i < s->n_atc_off; i++) + t6041_ps_lower(s->ps_atc_off[i]); + for (i = 0; i < s->n_atc_off; i++) { + if (t6041_poll_until_us(s->ps_atc_off[i], v, + !FIELD_GET(PS_ACTUAL, v), 10000)) + s->atc_late++; + } + writel(readl(s->ps_atc_fabric) | PS_AUTO_ENABLE, s->ps_atc_fabric); + writel(readl(s->ps_atc_afi) | PS_AUTO_ENABLE, s->ps_atc_afi); +} + +/* + * Raise fab2_soc manually, raise all four atcN_common domains, then re-enable + * AUTO on fab2_soc so the sleep engine's ATC step never stalls on a gated + * parent fabric. + */ +static int t6041_ps_raise_start(void __iomem *reg) +{ + u32 v; + + writel((readl(reg) & ~(PS_AUTO_ENABLE | GENMASK(11, 0))) | PS_TARGET, reg); + return t6041_poll_until_us(reg, v, (v & PS_ACTUAL) == PS_ACTUAL, 5000); +} + +static void t6041_atc_commons_on(struct t6041_sleep *s) +{ + void __iomem *fab2 = s->ps_atc_fabric; + unsigned int i; + + t6041_ps_raise_start(fab2); + for (i = 0; i < AXI2AF_ATC_COUNT; i++) + t6041_ps_raise_start(s->ps_atc_common[i]); + writel((readl(fab2) & ~(PS_AUTO_ENABLE | GENMASK(11, 0))) | PS_TARGET | PS_AUTO_ENABLE, + fab2); +} + +/* + * Disable DSID age-out (word 0 bit 25) and unexpected RT hit (word 1 bit 8) + * error enables on every AMCC plane and clear any latched error status words. + */ +static void t6041_amcc_quiesce(struct t6041_sleep *s) +{ + unsigned int g, p, w; + + for (g = 0; g < s->ngroups; g++) { + for (p = 0; p < 4; p++) { + void __iomem *a = s->amccb[g] + AMCC_ERR_OFF + AMCC_PLANE_STRIDE * p; + + writel(readl(a + 0x0) & ~BIT(25), a + 0x0); + writel(readl(a + 0x8) & ~BIT(8), a + 0x8); + for (w = 0; w < 7; w++) { + u32 v = readl(a + 4 + 8 * w); + + if (v) + writel(v, a + 4 + 8 * w); + } + } + } + dsb(sy); +} + +/* + * Flush AMCC caches and enable DCS dynamic power gating on every enabled + * channel while the AMCC slices are still forced on. + */ +static void t6041_mcc_macos(struct t6041_sleep *s) +{ + unsigned int i, p; + u32 v; + + for (i = 0; i < s->ngroups; i++) { + /* +0x1c0000 is the AMCC all-planes write window; poll per plane. */ + writel(1, s->amccb[i] + 0x1c082c); + writel(1, s->amccb[i] + 0x1c2844); + for (p = 0; p < 4; p++) + t6041_poll_until_us(s->amccb[i] + AMCC_PLANE_STRIDE * p + 0x2844, + v, !(v & BIT(0)), 100000); + } + dsb(sy); + for (i = 0; i < 4 * s->ngroups; i++) + writel(readl(s->dcs[i] + 0x20) | 0x1100, s->dcs[i] + 0x20); + dsb(sy); +} + +static const char *const t6041_axi2af_names[AXI2AF_REG_COUNT] = { + "axi2af-disp", + "axi2af-dispext0", + "axi2af-dispext1", + "axi2af-dispext2", + "axi2af-dispext3", + "axi2af-ans", + "axi2af-avd", + "axi2af-venc0", + "axi2af-venc1", + "axi2af-jpg", +}; + +static void t6041_wake_sep(struct t6041_sleep *s) +{ + unsigned int i; + u32 v; + + if (readl(s->wake + 0x0)) + writel(0, s->wake + 0x0); + for (i = 0; i < WAKE_WORDS; i++) + writel(s->wake_masks[i], s->wake + 0xc + 4 * i); + + v = readl(s->ps_sep); + if (!(v & BIT(10))) + writel(v | BIT(10), s->ps_sep); + dsb(sy); +} + +/* A perf word: the low nibble asks, [11:8] is the state reached, bit 31 busy. */ +static bool t6041_perf_set(void __iomem *reg, u32 state) +{ + u32 v; + + if (FIELD_GET(PERF_ACTUAL, readl(reg)) == state) + return true; + writel((readl(reg) & ~0xf) | state, reg); + return !t6041_poll_until_us(reg, v, + !(v & PERF_BUSY) && FIELD_GET(PERF_ACTUAL, v) == state, + 5000); +} + +/* SoC to 3, voters 0, DCS to 6: macOS commits at DCS 6 (0x7666); the engine takes it to 4. */ +static void t6041_mem_down(struct t6041_sleep *s) +{ + unsigned int i; + + t6041_perf_set(s->perf + 0x0, 3); + for (i = 0; i < 4; i++) + writel(0, s->pmc + i * 0x4000); + t6041_perf_set(s->perf + 0x400, 6); +} + +/* + * Cluster power-control words: +0 E, +4 P0, +8 P1, +0xc and +0x10 the two AVE + * complexes. Clear bit 5 (CLUSTER_UP_DONE) and take both AVE complexes to 0. + */ +static void t6041_ave_off(struct t6041_sleep *s) +{ + static const u16 ave[] = { 0xc, 0x10 }; + unsigned int i; + u32 v; + + for (i = 0; i < ARRAY_SIZE(ave); i++) { + writel(BIT(5), s->cluster + ave[i]); + t6041_poll_until_us(s->cluster + ave[i], v, !v, 5000); + } + v = readl(s->cluster + 0x8); + if (v & BIT(5)) + writel((v & 0xf) | BIT(5), s->cluster + 0x8); +} + +static void t6041_save(struct t6041_sleep *s); + +/* + * Lower a domain with two writes (AUTO off with target still f, then + * target 0), only when it is currently on so bit 11 does not latch. + */ +static void t6041_ps_lower_pair(void __iomem *reg, u32 first, u32 second) +{ + u32 v = readl(reg); + + if (!FIELD_GET(PS_TARGET, v) && !FIELD_GET(PS_ACTUAL, v)) + return; + writel(first, reg); + writel(second, reg); +} + +/* + * Pulse bit 33 of SOC-DEV-PS-REQ (PTD write +0x10f00) after ANS lowers and + * before arming WD2, matching macOS's traced -10 ms to -4 ms pulse (~6 ms). + * PMP is already halted by apple_sleep_coprocs_stop_all() before commit, so + * its PTD report page provides no completion/ACK bit to poll; read back + * SOC-DEV-PS-REQ (+0x1e00) to post the write before holding the 5 ms pulse. + */ +static void t6041_ptd_soc_dev_pulse(struct t6041_sleep *s) +{ + writeq(0x200000800ULL, s->ptd + PTD_SOC_DEV_REQ_WRITE); + readq(s->ptd + PTD_SOC_DEV_REQ_READ); + t6041_spin_us(5000); + writeq(0x800ULL, s->ptd + PTD_SOC_DEV_REQ_WRITE); +} + +static int t6041_sleep_commit(unsigned long unused) +{ + struct t6041_sleep *s = t6041_sleep; + unsigned int i, cpu; + u32 v; + + t6041_save(s); + s->stop_ret = spin_table_stop_parked(); + t6041_ave_off(s); + /* While every AMCC slice is still on: a clock-gated plane faults. */ + t6041_amcc_quiesce(s); + t6041_mcc_macos(s); + /* + * Disarm AXI2AF bridges on powered blocks before lowering them so the + * power domain does not latch bit 11 on subsequent sleeps. + */ + for (i = 0; i < AXI2AF_COUNT; i++) { + if (!s->axi2af[i]) + continue; + if (FIELD_GET(PS_ACTUAL, readl(s->ps_axi2af[i])) != 0xf) + continue; + v = readl(s->axi2af[i] + 0x4); + if (!(v & 1) && !(readl(s->axi2af[i] + 0x8) & 1)) + continue; + writel(v & ~1U, s->axi2af[i] + 0x4); + writel(readl(s->axi2af[i] + 0x8) & ~1U, s->axi2af[i] + 0x8); + } + t6041_cpu_ps_match(s); + t6041_mem_down(s); + + /* + * Lower child-before-parent sorted domains and wait for each domain to + * reach PS_ACTUAL == 0 before moving on so no parent is ever lowered + * while a child is still powering off (which latches bit 11). + */ + for (i = 0; i < s->n_off; i++) { + t6041_ps_lower(s->ps_off[i]); + if (t6041_poll_until_us(s->ps_off[i], v, + !FIELD_GET(PS_ACTUAL, v), 5000)) + s->off_late++; + } + + t6041_ps_match_all(s); + /* Every PMC voter at 0, and the PMS word macOS holds at 0. */ + for (i = 0; i < 4; i++) + writel(0, s->pmc + i * 0x4000); + writel(0, s->pmc + 0xa9c18); + readl(s->pmc + 0xa9c18); + if (t6041_poll_until_us(s->perf + 0x400, v, + !(v & PERF_BUSY) && FIELD_GET(PERF_ACTUAL, v) <= 6, 20000) || + t6041_poll_until_us(s->perf + 0x0, v, + !(v & PERF_BUSY) && FIELD_GET(PERF_ACTUAL, v) <= 3, 20000)) + s->dcs_late++; + /* Cluster PTD votes, no demand. */ + writeq(0x2000000000000000ULL, s->ptd + PTD_CLUSTER_WRITE_0); + writeq(0x2000000000000000ULL, s->ptd + PTD_CLUSTER_WRITE_1); + writeq(0x2000000000000000ULL, s->ptd + PTD_CLUSTER_WRITE_2); + writeq(0x2000000000000000ULL, s->ptd + PTD_CLUSTER_WRITE_3); + t6041_atc_down(s); + t6041_wake_sep(s); + + writel(0xffef, s->misc + 0x0); + /* + * Mask AIC before releasing parked secondary cores into their final + * deep WFI, then poll each non-boot core and secondary CPM PS word + * until hardware drops PS_ACTUAL to 0. + */ + aic_sleep_mask_all(); + spin_table_release_stopped(); + for_each_present_cpu(cpu) { + unsigned int id; + + if (cpu == smp_processor_id()) + continue; + id = t6041_cpu_id(cpu_logical_map(cpu)); + if (t6041_poll_until_us(s->ps_cpu[id], v, + !FIELD_GET(PS_ACTUAL, v), 50000)) + s->cpu_off_late |= BIT(id); + } + for (i = 0; i < T6041_CPM_COUNT; i++) { + if (i == MPIDR_AFFINITY_LEVEL(cpu_logical_map(smp_processor_id()), 1)) + continue; + if (t6041_poll_until_us(s->ps_cpm[i], v, + !FIELD_GET(PS_ACTUAL, v), 50000)) + s->cpm_off_late |= BIT(i); + } + + writel(0x3f833ff1, s->spmi + SPMI_NOTIFY_MASK); + /* PMU boot stage to 0x50 (asleep). */ + t6041_pmu_write(s, 0xf801, 0x50); + writel(0x3f0, s->ps_commit_periph[0]); + writel(0x3f0, s->ps_commit_periph[1]); + writel(0x3f0, s->ps_commit_periph[2]); + writel(0x3f0, s->ps_commit_periph[3]); + writel(0x2000001, s->spmi + SPMI_NOTIFY_MASK); + if (FIELD_GET(PS_ACTUAL, readl(s->ps_spmi_a0))) + writel(0x2000001, s->spmi_a0 + SPMI_NOTIFY_MASK); + writel(0x3f0, s->ps_commit_periph[4]); + cpm_gates(s); + writel(0, s->cluster + 0x0); + cpm_gates(s); + writel(0, s->cluster + 0x8); + t6041_ps_lower_pair(s->ps_apcie[T6041_APCIE_PHY_SW], 0x400004f, 0x4000340); + t6041_ps_lower_pair(s->ps_apcie[T6041_APCIE_SYS_ST1], 0xf, 0x300); + writel(0x3f0, s->ps_apcie[T6041_APCIE_ST1]); + t6041_ps_lower_pair(s->ps_apcie[T6041_APCIE_SYS_ST0], 0xf0000ff, 0xf0003f0); + writel(0x3f0, s->ps_apcie[T6041_APCIE_ST0]); + t6041_ps_lower_pair(s->ps_apcie[T6041_APCIE_SYS_GP], 0xf, 0x300); + writel(0x3f0, s->ps_apcie[T6041_APCIE_GP]); + t6041_ps_lower_pair(s->ps_apcie[T6041_APCIE_ANS], 0xf0000ff, 0xf0003f0); + /* macOS -10 ms to -4 ms before arming WD2: pulse PTD SOC-DEV-PS-REQ bit 33. */ + t6041_ptd_soc_dev_pulse(s); + writel(0, s->wdt + 0x0c); + writel(0, s->wdt + 0x2c); + writel(0, s->wdt + 0x20); + writel(0x7270e00, s->wdt + 0x28); + writel(1, s->wdt + 0x2c); + writel(0, s->aon + 0x8); + cpm_gates(s); + cpm_gates(s); + cpm_gates(s); + writel(0x10, s->cluster + 0x00); + writel(0, s->cluster + 0x04); + writel(0x10, s->cluster + 0x08); + writel(0x20, s->cluster + 0x0c); + writel(0, s->cluster + 0x10); + writel(0x400024f, s->ps_commit_sio[0]); + writel(0x400024f, s->ps_commit_sio[1]); + writel(0xa0100000, s->clkgen + 0x60); + writel(0xa0100000, s->clkgen + 0x64); + writel(0xa0100000, s->clkgen + 0x54); + writel(0xa0100000, s->clkgen + 0x50); + /* aura reads this with the MMU off on the way back. */ + WRITE_ONCE(s->mbox->resume_pa, __pa_symbol(cpu_resume)); + dcache_clean_poc((unsigned long)s->mbox, (unsigned long)(s->mbox + 1)); + t6041_atc_commons_on(s); + /* + * Confirm the SPMI controller's TX and RX FIFOs are idle after the + * PMU boot-stage write before the sleep engine takes over SPMI. + */ + if (t6041_poll_until_us(s->spmi + SPMI_STATUS, v, + (v & SPMI_IDLE) == SPMI_IDLE, 5000)) + s->spmi_late++; + /* + * Keep SPMI quiet before clearing keep-alive tables and committing + * sleep, matching macOS and the sleep engine's bus handoff window. + */ + t6041_spin_us(20000); + /* Keep-alive tables off right before commit. */ + for (i = 0; i < KA_WORDS; i++) { + writel(0, s->ka[0] + i * KA_STRIDE); + writel(0, s->ka[1] + i * KA_STRIDE); + } + dsb(sy); + writel(1, s->commit); + dsb(sy); + /* + * Secondary cores and non-boot CPMs are already polled off in deep WFI. + * Mask AIC again and hold the 3 ms commit-to-boot-WFI gap (matching + * sleep.c's boot_wfi_delay_ms = 3 on T8132/T8142; no hardware status + * bit reports commit-armed, and pure counter spin avoids WFET early + * gating) before entering the boot core's final deep WFI. + */ + aic_sleep_mask_all(); + t6041_spin_us(3000); + t6041_boot_wfi(s); +} + +/* + * Display pipe PMC votes saved before commit and restored on wake (offsets into + * the PMC register block). + */ +static const u32 t6041_pmc_vote_off[5] = { 0xac028, 0xa4000, 0xac020, 0xa9c10, 0xa9c20 }; + +/* + * Restore AMCC cache mode after wake: write way count through the all-planes + * window, then poll each plane's status word. + */ +static void t6041_mcc_active(struct t6041_sleep *s) +{ + unsigned int i, p; + u32 v; + + for (i = 0; i < s->ngroups; i++) { + writel(s->pre_ways[4 * i], s->amccb[i] + 0x1c2800); + for (p = 0; p < 4; p++) + readl_poll_timeout_atomic(s->amccb[i] + AMCC_PLANE_STRIDE * p + 0x2804, v, + v == s->pre_cache[4 * i + p], 10, 100000); + } +} + +/* Restore display PMC votes; wait for the DVMR ack (+0x20). */ +static void t6041_pmc_votes(struct t6041_sleep *s) +{ + unsigned int i; + u32 v; + + for (i = 0; i < ARRAY_SIZE(t6041_pmc_vote_off); i++) { + void __iomem *reg = s->pmc + t6041_pmc_vote_off[i]; + + if (readl(reg) != s->pre_votes[i]) + writel(s->pre_votes[i], reg); + if (t6041_pmc_vote_off[i] == 0xa4000 && s->pre_votes[i]) + readl_poll_timeout_atomic(reg + 0x20, v, v & BIT(0), 1, 8000); + } +} + +static const u16 t6041_clk_mux[4] = { 0x50, 0x54, 0x64, 0x60 }; + +static void t6041_save(struct t6041_sleep *s) +{ + unsigned int i; + + for (i = 0; i < 4 * s->ngroups; i++) { + void __iomem *plane = s->amccb[i / 4] + AMCC_PLANE_STRIDE * (i % 4); + + s->pre_ways[i] = readl(plane + 0x2800); + s->pre_cache[i] = readl(plane + 0x2804); + } + for (i = 0; i < ARRAY_SIZE(t6041_pmc_vote_off); i++) + s->pre_votes[i] = readl(s->pmc + t6041_pmc_vote_off[i]); + s->cntkctl = read_sysreg(cntkctl_el1); + s->siq_cfg = read_sysreg_s(SYS_APL_SIQ_CFG_EL1); + for (i = 0; i < s->n_restore; i++) + s->ps_pre[i] = readl(s->ps_restore[i]); + s->pre_perf[0] = readl(s->perf + 0x0); + s->pre_perf[1] = readl(s->perf + 0x400); + for (i = 0; i < 4; i++) + s->pre_pmc[i] = readl(s->pmc + i * 0x4000); + s->pre_pmc[4] = readl(s->pmc + 0xa9c18); + for (i = 0; i < 4; i++) + s->pre_clk[i] = readl(s->clkgen + t6041_clk_mux[i]); + s->pre_mask[0] = readl(s->spmi + SPMI_NOTIFY_MASK); + s->pre_a0 = FIELD_GET(PS_ACTUAL, readl(s->ps_spmi_a0)) != 0; + if (s->pre_a0) + s->pre_mask[1] = readl(s->spmi_a0 + SPMI_NOTIFY_MASK); + for (i = 0; i < WAKE_WORDS; i++) + s->pre_wake[i] = readl(s->wake + 0xc + 4 * i); + for (i = 0; i < AOP_PS_WORDS; i++) + s->aop_pre[i] = readl(s->aop_ps + 8 * i); + for (i = 0; i < s->npins; i++) { + if (test_bit(i, s->gpio_skip)) + continue; + s->gpio_pre[i] = readl(s->gpio + 4 * i); + } + /* Only with the GP PCIe block on: apcie_gp and apcie_sys_gp. */ + s->gp_saved = s->gp_port[0] && s->gp_port[1] && s->gp_phy[0] && s->gp_phy[1] && + FIELD_GET(PS_ACTUAL, readl(s->ps_apcie[T6041_APCIE_GP])) == 0xf && + FIELD_GET(PS_ACTUAL, readl(s->ps_apcie[T6041_APCIE_SYS_GP])) == 0xf; + for (i = 0; i < 2 && s->gp_saved; i++) { + s->gp_phy_pre[i] = readl(s->gp_phy[i]); + s->gp_app_pre[i] = readl(s->gp_port[i] + 0x800); + s->gp_perst_pre[i] = readl(s->gp_port[i] + 0x82c); + } +} + +/* + * Restore all AP GPIO pin configurations lost across deep sleep, skipping pins + * listed in apple,pinctrl-skip-pins. + */ +static void t6041_gpio_restore(struct t6041_sleep *s) +{ + unsigned int i; + + for (i = 0; i < s->npins; i++) { + if (test_bit(i, s->gpio_skip)) + continue; + if (readl(s->gpio + 4 * i) != s->gpio_pre[i]) + writel(s->gpio_pre[i], s->gpio + 4 * i); + } +} + +/* + * AOP island MiniPMGR power words (ps-aop). Walked backwards (parents first) + * on wake so every previously-on domain returns to manual target f. + */ +static const u16 t6041_aop_ps_order[] = { + 0x0b0, 0x128, 0x120, 0x158, 0x150, 0x148, 0x140, 0x138, 0x130, 0x0c0, 0x0c8, + 0x0e8, 0x0f0, 0x0f8, 0x100, 0x108, 0x110, 0x118, 0x0e0, 0x0d8, 0x0d0, 0x0b8, 0x090, + 0x020, 0x098, 0x0a0, 0x0a8, 0x028, 0x030, 0x068, 0x070, 0x078, 0x080, 0x038, 0x040, + 0x048, 0x058, 0x060, 0x088, 0x050, 0x010, 0x018, 0x008, 0x000, +}; + +static_assert(ARRAY_SIZE(t6041_aop_ps_order) == AOP_PS_WORDS); + +static void t6041_aop_wake(struct t6041_sleep *s) +{ + int k; + u32 v; + + for (k = ARRAY_SIZE(t6041_aop_ps_order) - 1; k >= 0; k--) { + u16 off = t6041_aop_ps_order[k]; + void __iomem *r = s->aop_ps + off; + u32 now = readl(r); + + if (!FIELD_GET(PS_ACTUAL, s->aop_pre[off / 8])) + continue; + if (FIELD_GET(PS_ACTUAL, now) == 0xf && !(now & PS_AUTO_ENABLE)) + continue; + writel((now & ~(PS_AUTO_ENABLE | PS_TARGET)) | PS_TARGET, r); + readl_poll_timeout_atomic(r, v, FIELD_GET(PS_ACTUAL, v), 1, 2000); + } +} + +static int t6041_ps_raise(void __iomem *reg) +{ + int ret = t6041_ps_raise_start(reg); + + writel((readl(reg) & ~(PS_AUTO_ENABLE | GENMASK(11, 0))) | PS_TARGET | PS_AUTO_ENABLE, reg); + return ret; +} + +/* + * Bring ANS's storage PCIe link back from power-off using the DT-supplied + * apple,tunable-* tables from apple,apcie. Returns 0, or the step (1-8) that + * timed out. Runs only when the NVMe driver stopped ANS for this sleep. + */ +static int t6041_apcie_raise(struct t6041_sleep *s) +{ + void __iomem *ctrl = s->ap_phy + 0x8000; + void __iomem *run = s->ap_phy + 0x8004; + u32 v; + int ret; + + ret = t6041_ps_raise(s->ps_apcie[T6041_APCIE_ANS]); + if (!ret) { + writel(readl(s->axi2af[AXI2AF_ANS] + 0x4) | 1, s->axi2af[AXI2AF_ANS] + 0x4); + writel(readl(s->axi2af[AXI2AF_ANS] + 0x8) | 1, s->axi2af[AXI2AF_ANS] + 0x8); + } + ret |= t6041_ps_raise(s->ps_apcie[T6041_APCIE_GP]); + if (!ret) + ret = t6041_ps_raise_start(s->ps_apcie[T6041_APCIE_SYS_GP]); + if (!ret) { + writel(readl(s->ap_axi + 0x104) | 1, s->ap_axi + 0x104); + writel(readl(s->ap_axi + 0x108) | 1, s->ap_axi + 0x108); + } + ret |= t6041_ps_raise(s->ps_apcie[T6041_APCIE_ST0]); + ret |= t6041_ps_raise(s->ps_apcie[T6041_APCIE_SYS_ST0]); + ret |= t6041_ps_raise(s->ps_apcie[T6041_APCIE_ST1]); + ret |= t6041_ps_raise(s->ps_apcie[T6041_APCIE_SYS_ST1]); + if (ret) + return 1; + + apple_tunable_apply(s->ap_axi, s->tun_axi2af); + apple_tunable_apply(s->ap_cio3pll, s->tun_cio3pll); + apple_tunable_apply(s->ap_clkgen, s->tun_clkgen); + writel(readl(s->ap_clkgen + 0x4) | BIT(31), s->ap_clkgen + 0x4); + writel(readl(s->ap_clkgen + 0x0) & ~(BIT(2) | BIT(1)), s->ap_clkgen + 0x0); + if (readl_poll_timeout_atomic(s->ap_clkgen + 0x0, v, !(v & BIT(31)), 1, 50000)) + return 2; + if (t6041_ps_raise(s->ps_apcie[T6041_APCIE_PHY_SW])) + return 3; + apple_tunable_apply(s->ap_phy, s->tun_phy); + if (readl_poll_timeout_atomic(s->ap_phy + 0x4000, v, v & BIT(31), 1, 50000)) + return 4; + writel(readl(ctrl) | BIT(0), ctrl); + if (readl_poll_timeout_atomic(ctrl, v, v & BIT(2), 1, 50000)) + return 5; + writel(readl(ctrl) | BIT(1), ctrl); + if (readl_poll_timeout_atomic(ctrl, v, v & BIT(3), 1, 50000)) + return 6; + writel(readl(ctrl) & ~BIT(4), ctrl); + + writel(readl(run) | BIT(0), run); + apple_tunable_apply(s->ap_phy_ip, s->tun_phy_ip_pll); + apple_tunable_apply(s->ap_phy_ip, s->tun_phy_ip_lanes); + writel(readl(s->ap_phy_ip + 0x90) & ~BIT(16), s->ap_phy_ip + 0x90); + writel(readl(run) | BIT(4), run); + if (readl_poll_timeout_atomic(s->ap_phy + 0x8008, v, v & BIT(0), 1, 50000)) + return 7; + writel(readl(s->ap_phy + 0x4000) | BIT(0), s->ap_phy + 0x4000); + writel(readl(ctrl) | BIT(27), ctrl); + + writel(0, s->ap_rc + 0x04); + writel(0x140, s->ap_rc + 0x54); + writel(1, s->ap_rc + 0x50); + if (readl_poll_timeout_atomic(s->ap_rc + 0x58, v, v & BIT(0), 1, 50000)) + return 8; + return 0; +} + +/* + * Restore GP PCIe port 0/1 reference and app clocks after deep sleep so their + * DART blocks do not raise SErrors on resume. Returns a mask of late ports. + */ +static unsigned int t6041_gp_pcie_clk(struct t6041_sleep *s) +{ + unsigned int i, late = 0; + u32 v; + + for (i = 0; i < 2; i++) { + void __iomem *phy = s->gp_phy[i]; + void __iomem *port = s->gp_port[i]; + u32 cfg = s->gp_phy_pre[i]; + u32 app = s->gp_app_pre[i]; + + if (!s->gp_saved || + FIELD_GET(PS_ACTUAL, readl(s->ps_apcie[T6041_APCIE_GP])) != 0xf || + FIELD_GET(PS_ACTUAL, readl(s->ps_apcie[T6041_APCIE_SYS_GP])) != 0xf) + continue; + writel(readl(phy) | BIT(0), phy); + if (readl_poll_timeout_atomic(phy, v, v & BIT(2), 1, 50000)) + late |= BIT(i); + writel(readl(phy) | BIT(1), phy); + if (readl_poll_timeout_atomic(phy, v, v & BIT(3), 1, 50000)) + late |= BIT(i); + if (!(cfg & BIT(4))) { + writel(readl(phy) & ~BIT(4), phy); + /* T6020+ PHY refclk buffer settle before REFCLKEN (as in pcie-apple.c). */ + udelay(1); + } + writel(readl(phy) | (cfg & (BIT(9) | BIT(10))), phy); + writel(readl(phy) | (cfg & BIT(31)), phy); + writel((readl(port + 0x800) & ~(BIT(0) | BIT(8))) | (app & (BIT(0) | BIT(8))), + port + 0x800); + writel(readl(port + 0x13c) | BIT(8), port + 0x13c); + writel(s->gp_perst_pre[i], port + 0x82c); + writel(readl(port + 0x13c) & ~BIT(8), port + 0x13c); + if (readl_poll_timeout_atomic(port + 0x804, v, v & BIT(0), 1, 50000)) + late |= BIT(i); + } + return late; +} + +/* + * Restore every non-CPU/CPM PS word to its pre-commit target and AUTO state: + * raises parents first (0..n_restore-1), then lowers children first. + */ +static unsigned int t6041_ps_restore(struct t6041_sleep *s) +{ + const u32 keep = ~(u32)(PS_AUTO_ENABLE | PS_FLAGS | PS_TARGET); + unsigned int i, late = 0; + u32 v; + + for (i = 0; i < s->n_restore; i++) { + void __iomem *reg = s->ps_restore[i]; + u32 pre = s->ps_pre[i]; + u32 cur = readl(reg); + u32 pt = pre & PS_TARGET; + + if (!(pre & (PS_TARGET | PS_ACTUAL)) && !(cur & (PS_TARGET | PS_ACTUAL))) + continue; + if (pt > (cur & PS_TARGET)) { + writel((cur & keep) | pt, reg); + if (readl_poll_timeout_atomic(reg, v, FIELD_GET(PS_ACTUAL, v) == pt, + 1, 3000)) + late++; + cur = readl(reg); + } + if (pt == (cur & PS_TARGET) && ((pre ^ cur) & PS_AUTO_ENABLE)) + writel((cur & ~(PS_AUTO_ENABLE | PS_FLAGS)) | (pre & PS_AUTO_ENABLE), reg); + } + for (i = s->n_restore; i-- > 0;) { + void __iomem *reg = s->ps_restore[i]; + u32 pre = s->ps_pre[i]; + u32 cur = readl(reg); + u32 pt = pre & PS_TARGET; + + if (pt >= (cur & PS_TARGET)) + continue; + if (cur & PS_AUTO_ENABLE) { + cur &= ~(PS_AUTO_ENABLE | PS_FLAGS); + writel(cur, reg); + } + writel((cur & keep) | pt | PS_FLAGS, reg); + if (readl_poll_timeout_atomic(reg, v, FIELD_GET(PS_ACTUAL, v) == pt, 1, 3000)) + late++; + if (pre & PS_AUTO_ENABLE) + writel((readl(reg) & ~PS_FLAGS) | PS_AUTO_ENABLE, reg); + } + return late; +} + +static u64 t6041_ret_t0, t6041_ret_t1; + +/* + * Back on the boot core through aura's mailbox: clusters on, masks back, WD2 off. + * Hardware wake reset restores the boot CPU power state before return, so + * udelay()/readl_poll_timeout_atomic() are safe here and in its helpers. + */ +static void t6041_sleep_return(struct t6041_sleep *s) +{ + unsigned int i; + u32 v; + + t6041_ret_t0 = read_sysreg(cntpct_el0); + /* The reset left the timer control and the AIC's IRQ routing at their EL2 defaults. */ + write_sysreg(s->cntkctl, cntkctl_el1); + isb(); + write_sysreg_s(s->siq_cfg, SYS_APL_SIQ_CFG_EL1); + writel(0, s->wdt + 0x2c); + /* Keep-alive back on, as macOS on its way back and as iBoot leaves it. */ + for (i = 0; i < KA_WORDS; i++) { + writel(1, s->ka[0] + i * KA_STRIDE); + writel(1, s->ka[1] + i * KA_STRIDE); + } + spin_table_stop_finished(); + aic_sleep_restore(); + writel(0xf, s->cluster + 0x0); + writel(0xf, s->cluster + 0x4); + writel(0xf, s->cluster + 0x8); + /* The two wake gates, then the CPM voters. */ + writel(readl(s->pwrgate + 0x000) | BIT(31), s->pwrgate + 0x000); + writel(readl(s->pwrgate + 0x040) | BIT(31), s->pwrgate + 0x040); + cpm_gates(s); + /* SEP DEV_DISABLE off again, bit 11 polled clear; S2R request word; wake masks. */ + v = readl(s->ps_sep); + if (v & BIT(10)) + writel(v & ~BIT(10), s->ps_sep); + readl_poll_timeout_atomic(s->ps_sep, v, !(v & BIT(11)), 1, 5000); + writel(0, s->wake + 0x0); + for (i = 0; i < WAKE_WORDS; i++) + writel(s->pre_wake[i], s->wake + 0xc + 4 * i); + /* Before t6041_mcc_active() touches the AMCC/DCS planes. */ + s->ps_late = t6041_ps_restore(s); + t6041_mcc_active(s); + t6041_aop_wake(s); + t6041_gpio_restore(s); + /* Re-arm AXI2AF bridges whose blocks are back on. */ + for (i = 0; i < AXI2AF_COUNT; i++) { + if (!s->axi2af[i]) + continue; + v = readl(s->ps_axi2af[i]); + if ((v & PS_TARGET) != PS_TARGET || FIELD_GET(PS_ACTUAL, v) != 0xf) + continue; + writel(readl(s->axi2af[i] + 0x4) | 1, s->axi2af[i] + 0x4); + writel(readl(s->axi2af[i] + 0x8) | 1, s->axi2af[i] + 0x8); + } + s->apcie_ret = s->ans_stopped ? t6041_apcie_raise(s) : 0; + s->gp_late = t6041_gp_pcie_clk(s); + /* Restore parked clock muxes (last parked first), perf states, and PMC voters. */ + for (i = 4; i-- > 0;) + writel(s->pre_clk[i], s->clkgen + t6041_clk_mux[i]); + t6041_perf_set(s->perf + 0x400, s->pre_perf[1] & 0xf); + t6041_perf_set(s->perf + 0x0, s->pre_perf[0] & 0xf); + for (i = 0; i < 4; i++) + writel(s->pre_pmc[i], s->pmc + i * 0x4000); + writel(s->pre_pmc[4], s->pmc + 0xa9c18); + t6041_pmc_votes(s); + writel(s->pre_mask[0], s->spmi + SPMI_NOTIFY_MASK); + if (s->pre_a0 && FIELD_GET(PS_ACTUAL, readl(s->ps_spmi_a0))) + writel(s->pre_mask[1], s->spmi_a0 + SPMI_NOTIFY_MASK); + writel(0, s->wdt + 0x2c); + /* PMU boot stage back from 0x50 (asleep) to 0x30 (OS running). */ + t6041_pmu_write(s, 0xf801, 0x30); + t6041_ret_t1 = read_sysreg(cntpct_el0); +} + +static int t6041_sleep_enter(suspend_state_t state) +{ + struct t6041_sleep *s = t6041_sleep; + unsigned int i; + int ret; + + /* With no way back, a sleep would end in aura's boot flow over this kernel. */ + if (!s->mbox) + return -EOPNOTSUPP; + if (WARN_ON_ONCE(!s->apcie_ready)) + return -EOPNOTSUPP; + /* + * Display power chains require GAPF unprotect, child-first lowering, and + * fab6_soc hold (handled by apple-dcp); refuse sleep if any display block + * is still active (e.g., apple-drm unbound or nomodeset). + */ + for (i = 0; i < AXI2AF_DISP_COUNT; i++) { + u32 v = readl(s->ps_axi2af[AXI2AF_DISP_FIRST + i]); + + if (v & (PS_TARGET | PS_ACTUAL)) { + dev_err(s->dev, "refused: display domain %u still active (%#x)\n", i, v); + return -EBUSY; + } + } + /* + * Every parked CPU answers the hold while a refusal is still possible: at the commit + * only a held CPU stops, and one left awake there keeps the engine waiting until the + * watchdog resets the SoC. + */ + ret = spin_table_hold_parked(); + if (ret) { + dev_err(s->dev, "refused: a parked CPU didn't answer the hold: %d\n", ret); + return ret; + } + ret = apple_sleep_coprocs_check_all(); + if (ret) { + spin_table_unhold_parked(); + return ret; + } + if (pm_wakeup_pending()) { + spin_table_unhold_parked(); + return -EBUSY; + } + /* + * Send SEP SLEEP only after every refusal check has passed: a nonzero + * return here guarantees nothing was sent, while success gates the + * enclave and commits this sleep through physical wake. + */ + ret = apple_sleep_enclave_stop_all(); + if (ret) { + spin_table_unhold_parked(); + return ret; + } + s->stop_ret = 0; + s->apcie_ret = 0; + s->atc_late = 0; + s->off_late = 0; + s->dcs_late = 0; + s->cpu_off_late = 0; + s->cpm_off_late = 0; + s->spmi_late = 0; + s->ps_late = 0; + s->gp_late = 0; + /* macOS stops the PMP before its last steps; past this a refusal can't go back. */ + ret = apple_sleep_coprocs_stop_all(); + s->coproc_ret = ret; + s->ans_stopped = apple_sleep_coprocs_ans_stopped(); + pm_set_resume_via_firmware(); + ret = cpu_suspend(0, t6041_sleep_commit); + if (!ret) + t6041_sleep_return(s); + return ret; +} + +static void t6041_sleep_end(void) +{ + struct t6041_sleep *s = t6041_sleep; + + if (!s || !t6041_ret_t1) + return; + dev_dbg(s->dev, "back from deep sleep, return path %llu ms\n", + div64_u64((t6041_ret_t1 - t6041_ret_t0) * 1000, arch_timer_get_cntfrq())); + t6041_ret_t1 = 0; + if (s->coproc_ret < 0) + dev_warn(s->dev, "a coprocessor didn't stop for the sleep: %d\n", s->coproc_ret); + if (s->stop_ret) + dev_warn(s->dev, "the parked CPUs didn't all stop: %d\n", s->stop_ret); + if (s->atc_late) + dev_warn(s->dev, "%u ATC power domains did not reach off before commit\n", + s->atc_late); + if (s->off_late) + dev_warn(s->dev, "%u power domains did not reach off before commit\n", + s->off_late); + if (s->dcs_late) + dev_warn(s->dev, "DCS/SoC perf did not settle after clearing PMC voters\n"); + if (s->cpu_off_late) + dev_warn(s->dev, "secondary CPUs %#x did not reach off before commit\n", + s->cpu_off_late); + if (s->cpm_off_late) + dev_warn(s->dev, "secondary CPMs %#x did not reach off before commit\n", + s->cpm_off_late); + if (s->spmi_late) + dev_warn(s->dev, "%u SPMI waits timed out around sleep\n", s->spmi_late); + if (s->ps_late) + dev_dbg(s->dev, "%u power domains took more than 3 ms to come back\n", s->ps_late); + if (s->apcie_ret) + dev_warn(s->dev, "storage link raise timed out at step %d\n", s->apcie_ret); + if (s->gp_late) + dev_warn(s->dev, "GP PCIe ports %#x didn't come back\n", s->gp_late); +} + +static int t6041_sleep_begin(suspend_state_t state) +{ + /* The PM core also calls .begin for s2idle when no s2idle ops are installed. */ + if (state != PM_SUSPEND_MEM) + return 0; + pm_set_suspend_via_firmware(); + return 0; +} + +static const struct platform_suspend_ops t6041_sleep_ops = { + .valid = suspend_valid_only_mem, + .begin = t6041_sleep_begin, + .end = t6041_sleep_end, + .enter = t6041_sleep_enter, +}; + +static void t6041_iounmap(void *base) +{ + iounmap((void __iomem *)base); +} + +static void __iomem *t6041_map_idx(struct device *dev, struct device_node *np, + int idx, resource_size_t min_size, + resource_size_t *out_size) +{ + struct resource res; + void __iomem *base; + int ret; + + if (idx < 0 || of_address_to_resource(np, idx, &res)) + return IOMEM_ERR_PTR(-EINVAL); + if (resource_size(&res) < min_size) + return IOMEM_ERR_PTR(-EINVAL); + /* Shared with other drivers, so map without claiming the region. */ + base = of_iomap(np, idx); + if (!base) + return IOMEM_ERR_PTR(-ENOMEM); + ret = devm_add_action_or_reset(dev, t6041_iounmap, (void __force *)base); + if (ret) + return IOMEM_ERR_PTR(ret); + if (out_size) + *out_size = resource_size(&res); + return base; +} + +static void __iomem *t6041_map_name(struct device *dev, struct device_node *np, + const char *name, resource_size_t min_size, + resource_size_t *out_size) +{ + int idx = of_property_match_string(np, "reg-names", name); + + if (idx < 0) + return IOMEM_ERR_PTR(idx); + return t6041_map_idx(dev, np, idx, min_size, out_size); +} + +struct t6041_pmgr_bank { + struct device_node *np; + void __iomem *base; + resource_size_t size; +}; + +struct t6041_ps_resolver { + struct device *dev; + struct t6041_pmgr_bank banks[T6041_MAX_PMGR_BANKS]; + unsigned int nbanks; +}; + +static void t6041_ps_resolver_cleanup(struct t6041_ps_resolver *r) +{ + unsigned int i; + + for (i = 0; i < r->nbanks; i++) + of_node_put(r->banks[i].np); +} + +static void __iomem *t6041_resolve_ps_node(struct t6041_ps_resolver *r, + struct device_node *ps_np) +{ + struct t6041_pmgr_bank *bank = NULL; + struct device_node *parent; + unsigned int i; + u32 off; + + if (of_property_read_u32(ps_np, "reg", &off) || (off & 3)) { + dev_err(r->dev, "%pOF: invalid PMGR PS reg offset\n", ps_np); + return IOMEM_ERR_PTR(-EINVAL); + } + + parent = of_get_parent(ps_np); + if (!parent) + return IOMEM_ERR_PTR(-EINVAL); + + for (i = 0; i < r->nbanks; i++) { + if (r->banks[i].np == parent) { + bank = &r->banks[i]; + break; + } + } + + if (!bank) { + resource_size_t size; + void __iomem *base; + + if (r->nbanks >= T6041_MAX_PMGR_BANKS) { + of_node_put(parent); + return IOMEM_ERR_PTR(-ENOSPC); + } + base = t6041_map_idx(r->dev, parent, 0, 4, &size); + if (IS_ERR(base)) { + of_node_put(parent); + return base; + } + bank = &r->banks[r->nbanks++]; + bank->np = of_node_get(parent); + bank->base = base; + bank->size = size; + } + of_node_put(parent); + + if (off > bank->size || bank->size - off < 4) { + dev_err(r->dev, "%pOF: offset %#x exceeds parent size %pa\n", + ps_np, off, &bank->size); + return IOMEM_ERR_PTR(-EINVAL); + } + + return bank->base + off; +} + +static int t6041_parse_ps_fixed(struct t6041_ps_resolver *r, const char *prop, + void __iomem **out_regs, + struct device_node **out_nodes, + unsigned int expected) +{ + struct device_node *np = r->dev->of_node; + unsigned int i; + int count; + + count = of_count_phandle_with_args(np, prop, NULL); + if (count != expected) + return dev_err_probe(r->dev, -EINVAL, + "%s: expected %u phandles, got %d\n", + prop, expected, count); + + for (i = 0; i < expected; i++) { + struct device_node *ps_np; + void __iomem *reg; + + ps_np = of_parse_phandle(np, prop, i); + if (!ps_np) + return dev_err_probe(r->dev, -EINVAL, + "%s[%u]: unresolved phandle\n", + prop, i); + reg = t6041_resolve_ps_node(r, ps_np); + if (IS_ERR(reg)) { + of_node_put(ps_np); + return dev_err_probe(r->dev, PTR_ERR(reg), + "%s[%u]: cannot map PS register\n", + prop, i); + } + out_regs[i] = reg; + if (out_nodes) + out_nodes[i] = ps_np; + else + of_node_put(ps_np); + } + return 0; +} + +struct t6041_topo_ctx { + struct device *dev; + struct device_node *const *nodes; + unsigned int n; + unsigned int stride; + unsigned long *adj; + unsigned int *indeg; +}; + +static int t6041_topo_find(const struct t6041_topo_ctx *ctx, + const struct device_node *np) +{ + unsigned int i; + + for (i = 0; i < ctx->n; i++) + if (ctx->nodes[i] == np) + return i; + return -1; +} + +static int t6041_ps_parent(struct device_node *np, int index, + struct device_node **out) +{ + struct of_phandle_args args; + int ret; + + ret = of_parse_phandle_with_args(np, "power-domains", + "#power-domain-cells", index, &args); + if (ret) { + *out = NULL; + return ret; + } + *out = args.np; + return 0; +} + +static int t6041_topo_add_ancestors(struct t6041_topo_ctx *ctx, unsigned int src, + struct device_node *np, unsigned int depth) +{ + struct device_node *parent; + int k, ret; + + if (depth >= T6041_PS_MAX_DEPTH) { + dev_err(ctx->dev, "PMGR power-domain hierarchy too deep or cyclic at %pOF\n", np); + return -EINVAL; + } + + for (k = 0; ; k++) { + int idx; + + ret = t6041_ps_parent(np, k, &parent); + if (ret == -ENOENT) + break; + if (ret) + return ret; + + idx = t6041_topo_find(ctx, parent); + if (idx == (int)src) { + dev_err(ctx->dev, "PMGR power-domain cycle involving %pOF\n", parent); + of_node_put(parent); + return -EINVAL; + } + if (idx >= 0) { + if (!__test_and_set_bit(idx, ctx->adj + (size_t)src * ctx->stride)) + ctx->indeg[idx]++; + } else { + ret = t6041_topo_add_ancestors(ctx, src, parent, depth + 1); + if (ret) { + of_node_put(parent); + return ret; + } + } + of_node_put(parent); + } + return 0; +} + +/* + * Stable (input-order-preserving) Kahn's topological sort on DT power-domains + * edges (child -> parent). For child-first (shutdown), pick the lowest-index + * ready node forward; for parent-first (restore), run the same child-first + * pass in reverse index order and reverse the output so edge-free nodes later + * in the list (such as auto-managed DCS domains after AMCCs) stay after + * earlier nodes whose ancestors are resolved later. + */ +static int t6041_topo_sort(struct device *dev, struct device_node *const *nodes, + unsigned int n, unsigned int *order, bool child_first) +{ + struct t6041_topo_ctx ctx = { + .dev = dev, + .nodes = nodes, + .n = n, + .stride = BITS_TO_LONGS(n), + }; + unsigned long *emitted = NULL; + unsigned int i, step; + int ret = 0; + + if (!n) + return 0; + + ctx.adj = kcalloc((size_t)n * ctx.stride, sizeof(*ctx.adj), GFP_KERNEL); + ctx.indeg = kcalloc(n, sizeof(*ctx.indeg), GFP_KERNEL); + emitted = bitmap_zalloc(n, GFP_KERNEL); + if (!ctx.adj || !ctx.indeg || !emitted) { + ret = -ENOMEM; + goto out; + } + + for (i = 0; i < n; i++) { + ret = t6041_topo_add_ancestors(&ctx, i, nodes[i], 0); + if (ret) + goto out; + } + + for (step = 0; step < n; step++) { + unsigned int pick, next; + bool found = false; + + if (child_first) { + for (pick = 0; pick < n; pick++) { + if (!test_bit(pick, emitted) && !ctx.indeg[pick]) { + found = true; + break; + } + } + } else { + for (pick = n; pick-- > 0; ) { + if (!test_bit(pick, emitted) && !ctx.indeg[pick]) { + found = true; + break; + } + } + } + if (!found) { + dev_err(dev, "PMGR power-domain cycle detected\n"); + ret = -EINVAL; + goto out; + } + __set_bit(pick, emitted); + order[child_first ? step : n - 1 - step] = pick; + for_each_set_bit(next, ctx.adj + (size_t)pick * ctx.stride, n) + ctx.indeg[next]--; + } + +out: + bitmap_free(emitted); + kfree(ctx.indeg); + kfree(ctx.adj); + return ret; +} + +static bool t6041_node_in_list(struct device_node *const *list, unsigned int n, + const struct device_node *np) +{ + unsigned int i; + + for (i = 0; i < n; i++) + if (list[i] == np) + return true; + return false; +} + +struct t6041_restore_acc { + struct device_node **nodes; + void __iomem **regs; + unsigned int count; + struct device_node *const *exclude; + unsigned int n_exclude; +}; + +static bool t6041_ps_is_mem_channel(const struct device_node *np) +{ + const char *label; + + if (of_property_read_string(np, "label", &label)) + return false; + return str_has_prefix(label, "amcc") || str_has_prefix(label, "dcs_"); +} + +static int t6041_parse_ps_list(struct t6041_ps_resolver *r, const char *prop, + bool topo_child_first, + void __iomem ***out_regs, + unsigned int *out_count, + unsigned long **out_mem_mask, + struct t6041_restore_acc *acc) +{ + struct device *dev = r->dev; + struct device_node *np = dev->of_node; + struct device_node **nodes; + void __iomem **regs; + void __iomem **dst; + unsigned long *mem_mask = NULL; + unsigned int *order = NULL; + unsigned int i, uniq = 0; + int count, ret = 0; + + count = of_count_phandle_with_args(np, prop, NULL); + if (count <= 0) + return dev_err_probe(dev, -EINVAL, "%s: missing or empty phandle list\n", prop); + + nodes = kcalloc(count, sizeof(*nodes), GFP_KERNEL); + regs = kcalloc(count, sizeof(*regs), GFP_KERNEL); + if (!nodes || !regs) { + ret = -ENOMEM; + goto out_free; + } + + for (i = 0; i < count; i++) { + struct device_node *ps_np; + void __iomem *reg; + + ps_np = of_parse_phandle(np, prop, i); + if (!ps_np) { + ret = dev_err_probe(dev, -EINVAL, "%s[%u]: unresolved phandle\n", + prop, i); + goto out_put; + } + if (t6041_node_in_list(nodes, uniq, ps_np)) { + of_node_put(ps_np); + continue; + } + reg = t6041_resolve_ps_node(r, ps_np); + if (IS_ERR(reg)) { + of_node_put(ps_np); + ret = dev_err_probe(dev, PTR_ERR(reg), + "%s[%u]: cannot map PS register\n", prop, i); + goto out_put; + } + nodes[uniq] = ps_np; + regs[uniq] = reg; + uniq++; + } + + dst = devm_kcalloc(dev, uniq, sizeof(*dst), GFP_KERNEL); + if (!dst) { + ret = -ENOMEM; + goto out_put; + } + + if (topo_child_first) { + order = kcalloc(uniq, sizeof(*order), GFP_KERNEL); + if (!order) { + ret = -ENOMEM; + goto out_put; + } + ret = t6041_topo_sort(dev, nodes, uniq, order, true); + if (ret) + goto out_put; + for (i = 0; i < uniq; i++) + dst[i] = regs[order[i]]; + } else { + memcpy(dst, regs, uniq * sizeof(*dst)); + } + + if (out_mem_mask) { + mem_mask = devm_bitmap_zalloc(dev, uniq, GFP_KERNEL); + if (!mem_mask) { + ret = -ENOMEM; + goto out_put; + } + for (i = 0; i < uniq; i++) { + struct device_node *entry = topo_child_first ? nodes[order[i]] : nodes[i]; + + if (t6041_ps_is_mem_channel(entry)) + __set_bit(i, mem_mask); + } + } + + for (i = 0; i < uniq; i++) { + if (t6041_node_in_list(acc->exclude, acc->n_exclude, nodes[i])) + continue; + if (t6041_node_in_list(acc->nodes, acc->count, nodes[i])) + continue; + acc->nodes[acc->count] = of_node_get(nodes[i]); + acc->regs[acc->count] = regs[i]; + acc->count++; + } + + *out_regs = dst; + *out_count = uniq; + if (out_mem_mask) + *out_mem_mask = mem_mask; + +out_put: + kfree(order); + for (i = 0; i < uniq; i++) + of_node_put(nodes[i]); +out_free: + kfree(regs); + kfree(nodes); + return ret; +} + +static int t6041_map_ps_domains(struct t6041_sleep *s) +{ + static const char *const sleep_props[] = { + "apple,sleep-off-domains", + "apple,atc-off-domains", + "apple,sleep-auto-domains", + "apple,sleep-auto-clkgate-domains", + "apple,sleep-auto-active-domains", + "apple,sleep-keep-on-domains", + }; + struct device_node *cpu_cpm_nodes[T6041_CPU_COUNT + T6041_CPM_COUNT] = {}; + struct t6041_ps_resolver r = { .dev = s->dev }; + struct t6041_restore_acc acc = { + .exclude = cpu_cpm_nodes, + .n_exclude = ARRAY_SIZE(cpu_cpm_nodes), + }; + struct device *dev = s->dev; + struct device_node *np = dev->of_node; + unsigned int *order = NULL; + unsigned int max_restore = 0; + unsigned int i, cpu; + int ret; + + ret = t6041_parse_ps_fixed(&r, "apple,cpu-domains", s->ps_cpu, + cpu_cpm_nodes, T6041_CPU_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,cpm-domains", s->ps_cpm, + cpu_cpm_nodes + T6041_CPU_COUNT, T6041_CPM_COUNT); + if (ret) + goto out; + + for_each_present_cpu(cpu) { + if (t6041_cpu_id(cpu_logical_map(cpu)) >= T6041_CPU_COUNT) { + ret = dev_err_probe(dev, -EINVAL, "CPU %u ID out of range\n", cpu); + goto out; + } + } + + ret = t6041_parse_ps_fixed(&r, "apple,sep-domain", &s->ps_sep, NULL, 1); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,spmi-a0-domain", &s->ps_spmi_a0, NULL, 1); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,atc-common-domains", s->ps_atc_common, + NULL, AXI2AF_ATC_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,atc-fabric-domain", &s->ps_atc_fabric, NULL, 1); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,atc-afi-domain", &s->ps_atc_afi, NULL, 1); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,apcie-domains", s->ps_apcie, + NULL, T6041_APCIE_PS_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,commit-sio-domains", s->ps_commit_sio, + NULL, T6041_COMMIT_SIO_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,commit-periph-domains", s->ps_commit_periph, + NULL, T6041_COMMIT_PERIPH_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,axi2af-domains", s->ps_axi2af, + NULL, AXI2AF_COUNT); + if (ret) + goto out; + ret = t6041_parse_ps_fixed(&r, "apple,full-part-detect-domains", s->ps_full_detect, + NULL, T6041_FULL_DETECT_COUNT); + if (ret) + goto out; + + for (i = 0; i < ARRAY_SIZE(sleep_props); i++) { + int n = of_count_phandle_with_args(np, sleep_props[i], NULL); + + if (n <= 0) { + ret = dev_err_probe(dev, -EINVAL, + "%s: missing or empty phandle list\n", + sleep_props[i]); + goto out; + } + max_restore += n; + } + + acc.nodes = kcalloc(max_restore, sizeof(*acc.nodes), GFP_KERNEL); + acc.regs = kcalloc(max_restore, sizeof(*acc.regs), GFP_KERNEL); + if (!acc.nodes || !acc.regs) { + ret = -ENOMEM; + goto out; + } + + /* + * Accumulate restore domains fabric- and controller-first before leaf + * and peripheral lists so hardware parents without DT power-domains + * edges (e.g. disabled AMCCs above auto-managed DCS nodes, or fab* + * fabrics above ATC/media blocks) are still ordered parent-first in + * ps_restore. + */ + ret = t6041_parse_ps_list(&r, "apple,sleep-auto-domains", false, + &s->ps_auto, &s->n_auto, &s->ps_auto_mem, &acc); + if (ret) + goto out; + ret = t6041_parse_ps_list(&r, "apple,sleep-auto-active-domains", false, + &s->ps_auto_active, &s->n_auto_active, NULL, &acc); + if (ret) + goto out; + ret = t6041_parse_ps_list(&r, "apple,sleep-auto-clkgate-domains", false, + &s->ps_auto_clkgate, &s->n_auto_clkgate, + &s->ps_auto_clkgate_mem, &acc); + if (ret) + goto out; + ret = t6041_parse_ps_list(&r, "apple,sleep-keep-on-domains", false, + &s->ps_keep_on, &s->n_keep_on, NULL, &acc); + if (ret) + goto out; + ret = t6041_parse_ps_list(&r, "apple,atc-off-domains", false, + &s->ps_atc_off, &s->n_atc_off, NULL, &acc); + if (ret) + goto out; + ret = t6041_parse_ps_list(&r, "apple,sleep-off-domains", true, + &s->ps_off, &s->n_off, NULL, &acc); + if (ret) + goto out; + + order = kcalloc(acc.count, sizeof(*order), GFP_KERNEL); + s->ps_restore = devm_kcalloc(dev, acc.count, sizeof(*s->ps_restore), GFP_KERNEL); + s->ps_pre = devm_kcalloc(dev, acc.count, sizeof(*s->ps_pre), GFP_KERNEL); + if (!order || !s->ps_restore || !s->ps_pre) { + ret = -ENOMEM; + goto out; + } + + ret = t6041_topo_sort(dev, acc.nodes, acc.count, order, false); + if (ret) + goto out; + + for (i = 0; i < acc.count; i++) + s->ps_restore[i] = acc.regs[order[i]]; + s->n_restore = acc.count; + +out: + kfree(order); + for (i = 0; i < acc.count; i++) + of_node_put(acc.nodes[i]); + kfree(acc.regs); + kfree(acc.nodes); + for (i = 0; i < ARRAY_SIZE(cpu_cpm_nodes); i++) + of_node_put(cpu_cpm_nodes[i]); + t6041_ps_resolver_cleanup(&r); + return ret; +} + +static struct apple_tunable *t6041_apcie_tunable(struct device *dev, + struct device_node *np, + const char *reg_name, + const char *prop) +{ + int idx = of_property_match_string(np, "reg-names", reg_name); + struct apple_tunable *t; + struct resource res; + + if (idx < 0 || of_address_to_resource(np, idx, &res)) + return NULL; + t = devm_apple_tunable_parse(dev, np, prop, &res); + return IS_ERR(t) ? NULL : t; +} + +static void __iomem *t6041_apcie_block(struct device *dev, struct device_node *np, + const char *reg_name, resource_size_t min_size, + const char *prop, struct apple_tunable **tunable) +{ + void __iomem *base; + + if (prop) { + *tunable = t6041_apcie_tunable(dev, np, reg_name, prop); + if (!*tunable) + return NULL; + } + base = t6041_map_name(dev, np, reg_name, min_size, NULL); + return IS_ERR(base) ? NULL : base; +} + +static void t6041_map_apcie(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + struct device_node *np; + + np = of_parse_phandle(dev->of_node, "apple,apcie", 0); + if (!np) + return; + + s->ap_rc = t6041_apcie_block(dev, np, "rc", 0x5c, NULL, NULL); + s->ap_axi = t6041_apcie_block(dev, np, "axi2af", 0x110, + "apple,tunable-axi2af", &s->tun_axi2af); + s->ap_cio3pll = t6041_apcie_block(dev, np, "cio3pll", 0x4, + "apple,tunable-cio3pll", &s->tun_cio3pll); + s->ap_clkgen = t6041_apcie_block(dev, np, "clkgen", 0x8, + "apple,tunable-clkgen", &s->tun_clkgen); + s->ap_phy = t6041_apcie_block(dev, np, "phy-block", 0x800c, + "apple,tunable-phy", &s->tun_phy); + s->ap_phy_ip = t6041_apcie_block(dev, np, "phy-ip", 0x94, + "apple,tunable-phy-ip-pll", &s->tun_phy_ip_pll); + s->tun_phy_ip_lanes = t6041_apcie_tunable(dev, np, "phy-ip", + "apple,tunable-phy-ip-auspma"); + s->gp_port[0] = t6041_apcie_block(dev, np, "port0", 0x830, NULL, NULL); + s->gp_port[1] = t6041_apcie_block(dev, np, "port1", 0x830, NULL, NULL); + s->gp_phy[0] = t6041_apcie_block(dev, np, "phy0", 0x4, NULL, NULL); + s->gp_phy[1] = t6041_apcie_block(dev, np, "phy1", 0x4, NULL, NULL); + of_node_put(np); + + if (s->ap_axi) + s->axi2af[AXI2AF_APCIE] = s->ap_axi + 0x100; + + if (s->ap_rc && s->ap_axi && s->ap_cio3pll && s->ap_clkgen && + s->ap_phy && s->ap_phy_ip && s->tun_phy_ip_lanes && + s->gp_port[0] && s->gp_port[1] && s->gp_phy[0] && s->gp_phy[1]) + s->apcie_ready = true; +} + +static int t6041_map_pinctrl(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + struct device_node *np = dev->of_node; + struct device_node *pin_np; + void __iomem *base; + u32 npins, pin; + int i, n; + + pin_np = of_parse_phandle(np, "apple,pinctrl", 0); + if (!pin_np) + return dev_err_probe(dev, -EINVAL, "missing apple,pinctrl\n"); + if (of_property_read_u32(pin_np, "apple,npins", &npins) || !npins || npins > 512) { + of_node_put(pin_np); + return dev_err_probe(dev, -EINVAL, "invalid apple,npins on pinctrl\n"); + } + base = t6041_map_idx(dev, pin_np, 0, (resource_size_t)npins * 4, NULL); + of_node_put(pin_np); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map apple,pinctrl\n"); + + s->gpio_pre = devm_kcalloc(dev, npins, sizeof(*s->gpio_pre), GFP_KERNEL); + s->gpio_skip = devm_bitmap_zalloc(dev, npins, GFP_KERNEL); + if (!s->gpio_pre || !s->gpio_skip) + return -ENOMEM; + + n = of_property_count_u32_elems(np, "apple,pinctrl-skip-pins"); + for (i = 0; i < n; i++) + if (!of_property_read_u32_index(np, "apple,pinctrl-skip-pins", i, &pin) && + pin < npins) + set_bit(pin, s->gpio_skip); + + s->gpio = base; + s->npins = npins; + return 0; +} + +static int t6041_map_spmi(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + struct device_node *np = dev->of_node; + struct device_node *bus_np; + void __iomem *base; + + bus_np = of_parse_phandle(np, "apple,spmi-buses", 0); + if (!bus_np) + return dev_err_probe(dev, -EINVAL, "missing apple,spmi-buses[0]\n"); + base = t6041_map_idx(dev, bus_np, 0, 0x84, NULL); + of_node_put(bus_np); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map apple,spmi-buses[0]\n"); + s->spmi = base; + + bus_np = of_parse_phandle(np, "apple,spmi-buses", 1); + if (!bus_np) + return dev_err_probe(dev, -EINVAL, "missing apple,spmi-buses[1]\n"); + base = t6041_map_idx(dev, bus_np, 0, 0x84, NULL); + of_node_put(bus_np); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map apple,spmi-buses[1]\n"); + s->spmi_a0 = base; + return 0; +} + +static int t6041_map_axi2af(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + struct device_node *np = dev->of_node; + unsigned int i; + + for (i = 0; i < AXI2AF_ATC_COUNT; i++) { + struct device_node *phy_np; + void __iomem *base; + + phy_np = of_parse_phandle(np, "apple,atc-phys", i); + if (!phy_np) + return dev_err_probe(dev, -EINVAL, "missing apple,atc-phys[%u]\n", i); + base = t6041_map_name(dev, phy_np, "axi2af", 0x110, NULL); + of_node_put(phy_np); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), + "cannot map axi2af on apple,atc-phys[%u]\n", i); + s->axi2af[i] = base + 0x100; + } + + for (i = 0; i < AXI2AF_REG_COUNT; i++) { + void __iomem *base = t6041_map_name(dev, np, t6041_axi2af_names[i], 0xc, NULL); + + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map %s\n", + t6041_axi2af_names[i]); + s->axi2af[AXI2AF_ATC_COUNT + i] = base; + } + return 0; +} + +static int t6041_map_mcc(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + struct device_node *np = dev->of_node; + unsigned int g, p; + + for (g = 0; g < s->ngroups; g++) { + char name[16]; + struct resource res; + void __iomem *base; + int idx; + + snprintf(name, sizeof(name), "amcc%u", g); + base = t6041_map_name(dev, np, name, AMCC_MIN_SIZE, NULL); + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map %s\n", name); + s->amccb[g] = base; + + snprintf(name, sizeof(name), "dcs%u", g); + idx = of_property_match_string(np, "reg-names", name); + if (idx < 0 || of_address_to_resource(np, idx, &res)) + return dev_err_probe(dev, -EINVAL, "missing %s\n", name); + for (p = 0; p < 4; p++) { + resource_size_t off = (resource_size_t)p * DCS_CH_STRIDE; + + if (off + DCS_CH_SIZE > resource_size(&res)) + return dev_err_probe(dev, -EINVAL, "%s too small\n", name); + s->dcs[4 * g + p] = devm_ioremap(dev, res.start + off, DCS_CH_SIZE); + if (!s->dcs[4 * g + p]) + return -ENOMEM; + } + } + return 0; +} + +static int t6041_parse_wake_sources(struct t6041_sleep *s) +{ + struct device *dev = s->dev; + u32 ids[WAKE_SOURCES_MAX]; + int i, n; + + n = of_property_read_variable_u32_array(dev->of_node, "apple,wake-enable", + ids, 1, WAKE_SOURCES_MAX); + if (n < 0) + return dev_err_probe(dev, n, "missing apple,wake-enable\n"); + + for (i = 0; i < WAKE_WORDS - 1; i++) + s->wake_masks[i] = U32_MAX; + s->wake_masks[WAKE_WORDS - 1] = WAKE_LAST_MASK; + + for (i = 0; i < n; i++) { + if (ids[i] >= WAKE_MAX_ID) + return dev_err_probe(dev, -EINVAL, + "wake source %u out of range\n", ids[i]); + s->wake_masks[ids[i] / 32] &= ~BIT(ids[i] % 32); + } + return 0; +} + +static const struct { + const char *name; + size_t field; + resource_size_t min_size; +} t6041_core_regs[] = { + { "ps-aop", offsetof(struct t6041_sleep, aop_ps), 8 * AOP_PS_WORDS }, + { "cluster", offsetof(struct t6041_sleep, cluster), 0x14 }, + { "pwrgate", offsetof(struct t6041_sleep, pwrgate), 0x114 }, + { "cpu-start", offsetof(struct t6041_sleep, misc), 0x14 }, + { "wdt", offsetof(struct t6041_sleep, wdt), 0x30 }, + { "aon-misc", offsetof(struct t6041_sleep, aon), 0xc }, + { "commit", offsetof(struct t6041_sleep, commit), 0x4 }, + { "clk-mux", offsetof(struct t6041_sleep, clkgen), 0x68 }, + { "ka-pmgr", offsetof(struct t6041_sleep, ka[0]), KA_WORDS * KA_STRIDE }, + { "ka-east", offsetof(struct t6041_sleep, ka[1]), KA_WORDS * KA_STRIDE }, + { "pmc", offsetof(struct t6041_sleep, pmc), 0xac02c }, + { "ptd", offsetof(struct t6041_sleep, ptd), PTD_MIN_SIZE }, + { "perf", offsetof(struct t6041_sleep, perf), 0x404 }, + { "wake", offsetof(struct t6041_sleep, wake), 0xc + 4 * WAKE_WORDS }, +}; + +static int t6041_sleep_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct t6041_sleep *s; + unsigned int i; + u64 pa; + int ret; + + if (!is_kernel_in_hyp_mode()) + return -ENODEV; + + s = devm_kzalloc(dev, sizeof(*s), GFP_KERNEL); + if (!s) + return -ENOMEM; + s->dev = dev; + + if (!of_property_read_u64(of_chosen, "aurora,s2r-mailbox", &pa)) { + s->mbox = devm_memremap(dev, pa, sizeof(*s->mbox), MEMREMAP_WB); + if (IS_ERR(s->mbox) || READ_ONCE(s->mbox->magic) != T6041_S2R_MAGIC) + s->mbox = NULL; + } + /* With no way back, a sleep would end in aura's boot flow over this kernel. */ + if (!s->mbox) { + dev_info(dev, "no aura S2R mailbox: no deep sleep\n"); + return -ENODEV; + } + + for (i = 0; i < ARRAY_SIZE(t6041_core_regs); i++) { + void __iomem *base = t6041_map_name(dev, np, t6041_core_regs[i].name, + t6041_core_regs[i].min_size, NULL); + + if (IS_ERR(base)) + return dev_err_probe(dev, PTR_ERR(base), "cannot map %s\n", + t6041_core_regs[i].name); + *(void __iomem **)((char *)s + t6041_core_regs[i].field) = base; + } + + ret = t6041_map_ps_domains(s); + if (ret) + return ret; + ret = t6041_parse_wake_sources(s); + if (ret) + return ret; + ret = t6041_map_spmi(s); + if (ret) + return ret; + ret = t6041_map_axi2af(s); + if (ret) + return ret; + ret = t6041_map_pinctrl(s); + if (ret) + return ret; + + /* + * The full part: the two full-part detect words (amcc24, amcc28) are + * not both target and actual 0 as on the binned part, where those + * channels are fused off. + */ + s->ngroups = (readl(s->ps_full_detect[0]) & (PS_TARGET | PS_ACTUAL)) && + (readl(s->ps_full_detect[1]) & (PS_TARGET | PS_ACTUAL)) ? 8 : 6; + dev_info(dev, "%u memory channels\n", 4 * s->ngroups); + + ret = t6041_map_mcc(s); + if (ret) + return ret; + + t6041_map_apcie(s); + if (!s->apcie_ready) { + dev_info(dev, "no PCIe tunables for ANS: no deep sleep\n"); + return -ENODEV; + } + + t6041_sleep = s; + ret = spin_table_set_power_ops(&t6041_cpu_power_ops); + if (ret) { + t6041_sleep = NULL; + return dev_err_probe(dev, ret, "cannot control CPU power\n"); + } + apple_sleep_set_commit_stops_coprocs(true); + suspend_set_ops(&t6041_sleep_ops); + dev_info(dev, "T6041 deep sleep at EL2 through aura's S2R mailbox\n"); + return 0; +} + +static const struct of_device_id t6041_sleep_of_match[] = { + { .compatible = "apple,t6041-sleep" }, + { } +}; + +static struct platform_driver t6041_sleep_driver = { + .driver = { + .name = "t6041-sleep", + .of_match_table = t6041_sleep_of_match, + .suppress_bind_attrs = true, + }, + .probe = t6041_sleep_probe, +}; +builtin_platform_driver(t6041_sleep_driver); diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index eaab8552de963..1182e2e2daae3 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -680,6 +680,23 @@ static int apple_spmi_resume_noirq(struct device *dev) } guard(mutex)(&spmi->fifo_lock); + /* + * Firmware and the platform's sleep code use this queue while Linux is + * away. Every command of ours was answered before the suspend, so any + * reply waiting now is someone else's, and would be read as the reply + * to our next command. + */ + if (pm_resume_via_firmware()) { + unsigned int stale = 0; + + while (!(readl(spmi->regs + spmi->hw->status) & spmi->hw->rx_empty) && + stale < 64) { + readl(spmi->regs + spmi->hw->reply); + stale++; + } + if (stale) + dev_info(dev, "dropped %u stale reply words after the wake\n", stale); + } raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); /* Whether the enables survive a real sleep has not been measured. */ if (pm_resume_via_firmware()) { diff --git a/include/linux/mfd/macsmc.h b/include/linux/mfd/macsmc.h index 8ebd1d059e1d1..5afcf707a7c31 100644 --- a/include/linux/mfd/macsmc.h +++ b/include/linux/mfd/macsmc.h @@ -147,6 +147,13 @@ struct apple_smc { u8 wake_lid; int wake_lid_ret; u64 saved_unexpected; + /* WKTP left at its sleep value: written back once a wake is a full one. */ + bool wake_silent; + /* apple,sleep-wake-type: WKTP written at the sleep commit. */ + bool sleep_wake_type; + /* apple,sleep-pmvc: when set, the pmVC value written at the sleep commit. */ + bool sleep_pmvc_set; + u32 sleep_pmvc; /* To be told at the noirq suspend, after the debug link's cut. */ bool sleep_warn_late; /* In a noirq phase: replies are polled for. */ diff --git a/include/linux/soc/apple/dart.h b/include/linux/soc/apple/dart.h index 0a7925025e628..5c0fbf5688a3b 100644 --- a/include/linux/soc/apple/dart.h +++ b/include/linux/soc/apple/dart.h @@ -187,6 +187,8 @@ int apple_dart_sleep_prepare(struct device *dev); void apple_dart_sleep_restore(struct device *dev); /* A display DART's streams around a display power cycle, see the DART driver. */ int apple_dart_display_streams(struct device *dev, u32 streams, bool on, bool flush); +/* A locked display DART's TCR and TTBR words kept across a real sleep (T6041). */ +int apple_dart_display_keep(struct device *dev, u32 streams, bool save); /* A GAPF slice released before its coprocessor's CPU domain comes up after a wake. */ int apple_dart_gapf_ready(struct device *dev); /* A display DART whose domain goes off at runtime while others still map into it. */ @@ -221,6 +223,11 @@ static inline int apple_dart_display_streams(struct device *dev, u32 streams, bo return -ENODEV; } +static inline int apple_dart_display_keep(struct device *dev, u32 streams, bool save) +{ + return -ENODEV; +} + static inline int apple_dart_gapf_ready(struct device *dev) { return 0; diff --git a/include/linux/soc/apple/sleep.h b/include/linux/soc/apple/sleep.h index 86760fa77b602..d2642a9c8ffb4 100644 --- a/include/linux/soc/apple/sleep.h +++ b/include/linux/soc/apple/sleep.h @@ -95,6 +95,17 @@ int apple_sleep_m5_dispext_power(struct device *dev, bool on); int apple_sleep_coproc_register(struct device *dev, void __iomem *asc, bool pcie_ans, int (*last_stop)(void *data), void *data); +/* + * For a SoC sleep driver of its own (T6041): advertise commit-time stop + * support and run the refusal checks, enclave stop, and coprocessor stops + * with interrupts off. + */ +void apple_sleep_set_commit_stops_coprocs(bool enable); +int apple_sleep_coprocs_check_all(void); +int apple_sleep_enclave_stop_all(void); +int apple_sleep_coprocs_stop_all(void); +bool apple_sleep_coprocs_ans_stopped(void); + /* * The same with no ASC to clear: @last_stop clears its own run bits and lowers its own power * domain, and runs before every other coprocessor's. The refusal checks leave that domain on. @@ -362,6 +373,30 @@ static inline bool apple_sleep_coproc_stopped(struct device *dev) static inline void apple_sleep_note_sub(u8 step) {} +static inline void apple_sleep_set_commit_stops_coprocs(bool enable) +{ +} + +static inline int apple_sleep_coprocs_check_all(void) +{ + return 0; +} + +static inline int apple_sleep_enclave_stop_all(void) +{ + return 0; +} + +static inline int apple_sleep_coprocs_stop_all(void) +{ + return 0; +} + +static inline bool apple_sleep_coprocs_ans_stopped(void) +{ + return false; +} + static inline bool apple_sleep_commit_stops_coprocs(void) { return false; diff --git a/rust/kernel/soc/apple/mailbox.rs b/rust/kernel/soc/apple/mailbox.rs index e0c4be586801d..9d39fc8726294 100644 --- a/rust/kernel/soc/apple/mailbox.rs +++ b/rust/kernel/soc/apple/mailbox.rs @@ -102,6 +102,12 @@ impl Mailbox { to_result(unsafe { bindings::apple_mbox_send(self.mbox, msg, atomic) }) } + /// Whether the firmware has room for another message (its receive FIFO isn't full). + pub fn send_ready(&self) -> bool { + // SAFETY: Calling the c function, `mbox` is a valid pointer + unsafe { bindings::apple_mbox_send_ready(self.mbox) } + } + /// Sets bit 0 of the receive control word, for firmware that powers itself down. pub fn set_recv_enabled(&self, enabled: bool) { // SAFETY: Calling the c function, `mbox` is a valid pointer diff --git a/tools/asahi/bcm4377-resume/fixture.h b/tools/asahi/bcm4377-resume/fixture.h index 5eece3476e65f..cb47a5d7ae3b7 100644 --- a/tools/asahi/bcm4377-resume/fixture.h +++ b/tools/asahi/bcm4377-resume/fixture.h @@ -63,6 +63,8 @@ struct bcm4377_data { pthread_mutex_t resume_lock; uint64_t resume_epoch, resume_pending; bool resume_armed, resume_blocked, resume_powered; + /* T6041 S2R: zero, so a real sleep's power loss rebinds (not modelled: see below). */ + uint64_t dma_window_base; bool resume_guarded, resume_recovering; struct work_struct resume_work; struct ring acl_d2h_ring,acl_h2d_ring,sco_d2h_ring,sco_h2d_ring,hci_d2h_ring,hci_h2d_ring,sco_event_ring,sco_ack_ring,hci_acl_event_ring,hci_acl_ack_ring; @@ -107,6 +109,14 @@ static pthread_t producer_thread; static void hci_cmd_timeout(struct work_struct *work); static struct bcm4377_data *active; static bool hdev_is_powered(struct hci_dev *h) {return (h->flags&HCI_UP) && !(h->flags&HCI_AUTO_OFF);} +/* The controls model resumes after s2idle; a real sleep's rebind path is not taken. */ +static bool pm_resume_via_firmware(void) { return false; } +struct bcm4377_data; +static void bcm4377_queue_rebind(struct bcm4377_data *b, const char *why) +{ + (void)b; (void)why; + assert(0); +} static bool of_machine_is_compatible(const char *s) {assert(!strcmp(s,"apple,j493"));return board_j493;} static void *kmalloc(size_t n,int flags) {return allocation_error?NULL:malloc(n);} static void kfree(void *p) {free(p);} diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index 98b984e597554..c896fb3715666 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -222,6 +222,11 @@ def run(name,code,reject=False): #define current ((void *)1) #define dma_wmb() ((void)0) #define dma_rmb() ((void)0) +#define smp_store_release(p,v) (*(p)=(v)) +#define smp_mb__before_atomic() ((void)0) +typedef int atomic_t; +#define atomic_inc(v) ((*(v))++) +#define atomic_dec(v) ((*(v))--) #define trace_iomfb_push(...) #define IOMFB_METHOD(t,n) [n]={#n,{t[0],t[1],t[2],t[3]},{0},{0}} #define IOMFB_METHOD_H17(t,h,n) [n]={#n,{t[0],t[1],t[2],t[3]},{h[0],h[1],h[2],h[3]},{0}} @@ -230,7 +235,7 @@ def run(name,code,reject=False): struct dcp_method_entry {const char *name;char tag[4],tag_h17g[4],tag_ext26[4];}; ''' transport+=block(ih,'enum dcp_context_id {')+'\n'+block(ih,'struct dcp_packet_header {')+'\n'+block(internal,'struct dcp_channel {')+'\n'+block(ih,'enum dcpep_method {')+r''' -struct apple_dcp {const void *push_out_prefill;void *dev;u8 *shmem;int fw_compat;bool native,crashed,quiescing,ext26_blocked,ext26_power_sent;u64 ext26_power_ns;struct {int iomfb_method_profile;}hw;struct {void *owner;} iomfb;struct dcp_channel ch_cb,ch_cmd,ch_oobcb,ch_oobcmd,ch_async,ch_oobasync;}; +struct apple_dcp {const void *push_out_prefill;void *dev;u8 *shmem;int fw_compat;bool native,crashed,quiescing,ext26_blocked,ext26_power_sent;u64 ext26_power_ns;struct {int iomfb_method_profile;}hw;struct {void *owner;} iomfb;struct dcp_channel ch_cb,ch_cmd,ch_oobcb,ch_oobcmd,ch_async,ch_oobasync;atomic_t pending_acks;}; static bool iomfb_uses_queue(struct apple_dcp *d){return true;} static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} diff --git a/tools/asahi/sep-suspend-errors-tests.py b/tools/asahi/sep-suspend-errors-tests.py index 2ae69ec2c32fc..b8cc7a76a7f00 100644 --- a/tools/asahi/sep-suspend-errors-tests.py +++ b/tools/asahi/sep-suspend-errors-tests.py @@ -139,6 +139,7 @@ def replace_once(source, before, after): static struct apple_mbox mbox; static int apple_sleep_coprocs_lock; static void *apple_sleep; +static bool apple_sleep_external_commit; static struct { struct device *dev; int (*stop)(void *); void *data; } apple_sleep_enclave; @@ -251,7 +252,7 @@ def replace_once(source, before, after): memset(&hw, 0, sizeof(hw)); mbox = (struct apple_mbox){ .regs = &hw, .hw = &hw, .rx = foreign_rx, .cookie = &device }; config_enabled = hyp = sep_pm_suspending = dart_present = dart_ready = map_ok = true; - firmware = tx_ready = true; apple_sleep = &device; + firmware = tx_ready = true; apple_sleep = &device; apple_sleep_external_commit = false; real_wake = pending_wake = late_wake = sleep_refuse_before_send = false; domain_error = property_error = address_error = read_error = gate_after = reads = 0; put_refs = maps = unmaps = lookups = prepares = restores = sends = closes = 0; @@ -276,6 +277,7 @@ def replace_once(source, before, after): case 19: apple_sleep_enclave.dev = value ? &device : NULL; break; case 20: sep_pm_commit.sent = value; break; case 21: firmware = value; break; case 22: sep_pm_told = value ? yes : NULL; break; + case 23: apple_sleep_external_commit = value; break; } } int counter(int which) { @@ -343,6 +345,14 @@ def replace_once(source, before, after): assert(sep_pm_commit.registered); assert(sep_pm_commit_finish(&device) == 0); assert(put_refs == 1 && unmaps == 1 && !apple_sleep_enclave.dev); assert(sep_pm_commit_finish(&device) == -ENOENT); + // An external EL2 sleep driver (T6041) advertises commit-stop without apple_sleep. + fixture(); apple_sleep = NULL; apple_sleep_external_commit = true; + assert(apple_sleep_commit_stops_coprocs()); + assert(stage() == 0); + assert(sep_pm_commit_finish(&device) == 0); + assert(put_refs == 1 && unmaps == 1 && !apple_sleep_enclave.dev); + firmware = false; + assert(!apple_sleep_commit_stops_coprocs()); } static void test_unsent(void) { for (int scenario = 0; scenario < 7; ++scenario) { @@ -446,7 +456,7 @@ def replace_once(source, before, after): #![allow(dead_code, unused_imports, unused_variables)] use std::cell::{Cell, RefCell, RefMut}; use std::ffi::{c_int, c_void}; -use std::sync::atomic::{AtomicU32, Ordering, Ordering::Relaxed}; +use std::sync::atomic::{AtomicBool, AtomicU32, Ordering, Ordering::Relaxed}; #[derive(Clone, Copy, Debug, PartialEq, Eq)] struct Error(i32); impl Error { fn from_errno(n: i32) -> Self { assert!(n < 0); Self(n) } } type Result = std::result::Result; @@ -529,17 +539,25 @@ def replace_once(source, before, after): struct SepData { dev: kernel::device::Device, phase: AtomicU32, control: Lock, mbox: Lock>, gate: Cell, sleep_rx_held: Flag, endpoint: Cell, control_wq: Wq, + // T6041's suspend-time path (no sleep core commit); never taken here. + sleep_at_suspend: AtomicBool, } impl SepData { fn new() -> Self { Self { dev: kernel::device::Device, phase: AtomicU32::new(PHASE_READY), control: Lock(RefCell::new(Control { busy: false, wake_ok: true })), mbox: Lock(RefCell::new(Some(Mbox))), gate: Cell::new(pm::SleepGate::Open), - sleep_rx_held: Flag(Cell::new(false)), endpoint: Cell::new(true), control_wq: Wq } + sleep_rx_held: Flag(Cell::new(false)), endpoint: Cell::new(true), control_wq: Wq, + sleep_at_suspend: AtomicBool::new(false) } } fn endpoint_present(&self, _: u32) -> bool { self.endpoint.get() } fn sleep_gate(&self) -> pm::SleepGate { self.gate.get() } fn set_sleep_gate(&self, g: pm::SleepGate) { self.gate.set(g); } + // T6041's suspend-time path and its mailbox check: the platform commits here, so the + // first is never reached, and the mailbox always drains. + fn sleep_enter_at_suspend(&self) -> Result<()> { unreachable!() } + fn sleep_exit_at_suspend(&self) -> bool { unreachable!() } + fn mailbox_drains(&self) -> bool { true } fn ring(_: &Mbox, msg: kernel::soc::apple::mailbox::Message) -> Result<()> { assert_eq!(msg.msg0, proto::WAKE_KICK.msg0); event(4); RING.with(|v|v.get()) } @@ -700,7 +718,9 @@ def sources(source, contracts, mutation): } ''' rust += pm[gate_start:gate_end] - rust += '\n'.join(bodies[n] for n in names['pm']) + '\n}\nimpl SepData {\n' + rust += '\n'.join(bodies[n] for n in names['pm']) + # T6041 has no sleep core commit; every platform modelled here has one. + rust += '\npub(crate) fn platform_commit() -> bool { true }\n}\nimpl SepData {\n' rust += '\n'.join(bodies[n] for n in names['sep']) + '\n}\n' + RUST_TESTS return c, rust diff --git a/tools/testing/selftests/drivers/apple/pmgr-inherited.py b/tools/testing/selftests/drivers/apple/pmgr-inherited.py index affc0312450b1..ac2538d2364ac 100755 --- a/tools/testing/selftests/drivers/apple/pmgr-inherited.py +++ b/tools/testing/selftests/drivers/apple/pmgr-inherited.py @@ -223,7 +223,7 @@ def main(): assert(apple_pmgr_ps_power_off(&ps->genpd)==-EBUSY && !map.writes); puts("ok 3 - read errors and lost inherited activity never request a transition"); 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,force-disable","apple,force-reset","apple,externally-clocked","apple,auto-managed"}; for(unsigned i=0;i