diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index 91ae5a3ce1bca..e2e75a8c29f13 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -46,6 +46,7 @@ properties: - apple,t8132-pmgr - apple,t8140-pmgr - apple,t8142-pmgr + - apple,t8152-pmgr - const: apple,t8103-pmgr - const: syscon - const: simple-mfd diff --git a/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml b/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml new file mode 100644 index 0000000000000..38a4dcb4044a5 --- /dev/null +++ b/Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml @@ -0,0 +1,37 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/chosen/apple,dcp-rtkit-running.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple DCP RTKit state at the loader hand-off + +maintainers: + - Thomas Glanzmann + +description: + The loader records whether the internal display coprocessor's RTKit was + running when it handed over to the kernel, or whether the loader quiesced + it after a failed display setup. The loader omits this property when it + never started the coprocessor. + +select: + properties: + $nodename: + const: chosen + required: + - $nodename + +properties: + $nodename: + const: chosen + + apple,dcp-rtkit-running: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + description: + One if the internal DCP's RTKit was running at the hand-off, zero if + the loader quiesced it. + +additionalProperties: true +... diff --git a/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml new file mode 100644 index 0000000000000..b25cd3a74cfa0 --- /dev/null +++ b/Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml @@ -0,0 +1,336 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/display/apple,t8152-dcp-iboot.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 DCP on the iBoot display interface + +maintainers: + - Thomas Glanzmann + +description: | + The Display Coprocessor (DCP) of the Apple T8152 SoC runs RTKit firmware + that offers a small iBoot display interface (disp0-service) next to the + full IOMobileFramebuffer protocol. This binding describes the DCP driven + through that interface, together with the DisplayPort PHY its DPTX port + is routed to. The DCP fetches through its own DART, the display pipe + scans out through another one, which sees each scanout buffer at the same + address. + +properties: + compatible: + const: apple,t8152-dcp-iboot + + apple,afk-active-endpoints: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 65535 + description: + Runtime handoff from the bootloader. Bit N records that AFK endpoint + 0x20 + N is running and must acknowledge shutdown before a new session + starts. A zero bit means stopped. The bootloader inserts this only + for controllers whose complete endpoint state it owns, and reserves + the old session's buffers. The driver refuses takeover if absent. + This property must not be hard-coded in a board device tree. + + apple,dp-source: + $ref: /schemas/types.yaml#/definitions/uint32 + maximum: 2 + description: + Display-crossbar UFP endpoint, 0 for DCP, 1 for DCPEXT0, 2 for DCPEXT1. + The driver uses DPTX port zero, whose ATC mux selector is twice this. + + apple,usb-c-ports: + $ref: /schemas/types.yaml#/definitions/phandle + description: + Controller node containing the shared USB-C port children, dp-clock, + aux and aux-ps resources. Each connected port has one controller owner. + + apple,rtkit-wake: + type: boolean + description: + Runtime handoff for an unused DCPEXT whose firmware is loaded, powered, + and awaiting RTKit wake. The loader must reserve its firmware mappings + and buffers and supply apple,afk-active-endpoints. This property must + not be hard-coded in a board tree. An adopted HDMI session is already + running and takes precedence over this unused-controller indication. + + reg: + minItems: 2 + maxItems: 9 + + reg-names: + oneOf: + - items: + - const: coproc + - const: atc + - const: dp-clock + - const: atc-ps + - const: atc-psd + - const: aux + - const: aux-ps + minItems: 5 + description: + DCP coprocessor, ATC DisplayPort PHY (USB-C), the PMGR clock + control of its DisplayPort link, the PMGR power states the PHY + depends on, and optionally the AP DisplayPort AUX controller that + reads the sink's EDID with its PMGR power state + - items: + - const: coproc + - const: phy-core + - const: phy-apb + - const: aux + - const: aux-ps + - const: phy-ps + - const: coproc-ps + - const: coproc-psd + - const: phy-psd + minItems: 7 + description: + DCP coprocessor, the HDMI dptx-phy blocks, the AP + DisplayPort AUX controller that reads the sink's EDID with its + PMGR power state, the PMGR power state of the HDMI PHY, the read + only power state of the DCPEXT CPU, and the PMGR2 PSD service of + the HDMI PHY. The PHY is accessed only once its power states read + powered; with phy-psd it is powered up for a cold HDMI start. + - items: + - const: coproc + - const: coproc-psd + description: + Additional display controller and its PMGR2 PSD admission state; + PHY resources are shared through apple,usb-c-ports. + - items: + - const: coproc + - const: dp-clock + - const: aux + - const: aux-ps + minItems: 2 + description: + DCP coprocessor, the PMGR clock control of the ATC DisplayPort + links (one divider every eight bytes, starting with ATC0), and + optionally the AP DisplayPort AUX controller with its PMGR power + state; the USB-C ports follow as usb-c child nodes + + apple,tunable-pre: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the ATC PHY block + - description: mask + - description: value + description: + ATC PHY tunables (ADT ACIOPHY_CMN and CIOPLL_CORE defaults), applied + before the lane crossbar setup when the PHY starts from cold. + + apple,tunable-post: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the ATC PHY block + - description: mask + - description: value + description: + ATC PHY tunables (ADT ATC_FABRIC, DPPLL and AUX defaults), applied + after the lane crossbar setup. + + apple,hdmi: + type: boolean + description: + The DCP drives the HDMI port through the dedicated dptx-phy and an + on-board DisplayPort-to-HDMI converter. With apple,usb-c-ports it can + instead claim a USB-C port when the bootloader has not assigned HDMI. + + apple,tunable-phy: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: register offset in the HDMI dptx-phy core block + - description: mask + - description: value + description: + HDMI dptx-phy tunables (ADT dptx-phy asdc and lane-shm-regs groups), + applied when the PHY starts from cold. + + apple,smc: + $ref: /schemas/types.yaml#/definitions/phandle + description: + The SMC that switches the power of the DisplayPort-to-HDMI converter. + + apple,pcon-power: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: SMC key + - description: value, bits 63:32 + - description: value, bits 31:0 + description: + SMC writes, in order, that power the DisplayPort-to-HDMI converter + (ADT dp2hdmi-gpio0 function-dp2hdmi_pwr_en and function-hdmi_pwr_en). + The converter drives the HDMI hot-plug detect line only while it is + powered. + + hpd-gpios: + maxItems: 1 + description: + Hot plug detect line of the connector, if the AP can read it (J873g + HDMI); without it the sink is assumed to stay connected. + + mboxes: + maxItems: 1 + + iommus: + maxItems: 1 + description: DCP DART stream + + power-domains: + maxItems: 1 + description: + The coprocessor's power state, which its firmware runs; the DARTs + follow it. + + scanout: + type: object + additionalProperties: false + description: + The display pipe's scanout stream. Its DART is locked with its own + root, so it is a separate device that sees each scanout buffer at the + DCP's address. + properties: + iommus: + maxItems: 1 + dma-coherent: true + required: + - iommus + + dma-coherent: true + + apple,die: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Die of the DPTX connection target, 0 if absent. + + "#address-cells": + const: 2 + + "#size-cells": + const: 2 + + ranges: true + +patternProperties: + "^usb-c@[0-9a-f]+$": + type: object + additionalProperties: false + description: + A USB-C port whose ATC PHY the DCP can drive. The DCP drives one port + at a time, the one a DisplayPort sink is plugged into. + properties: + reg: + maxItems: 3 + reg-names: + items: + - const: atc + - const: atc-ps + - const: atc-psd + description: + ATC DisplayPort PHY, the PMGR power states it depends on (DP_0, + DP_1 and USB_AON) and its common power domain (PSD) + apple,dfp-endpoint: + $ref: /schemas/types.yaml#/definitions/uint32 + description: The ATC's display-crossbar0 DFP endpoint (ATC instance). + apple,tunable-pre: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: As the node's apple,tunable-pre, for this port's PHY. + apple,tunable-post: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: As the node's apple,tunable-post, for this port's PHY. + phys: + maxItems: 1 + description: + The port's ATC PHY in DisplayPort use (PHY_TYPE_DP). A DCP powers + it while it drives the PHY, from before its cold start until its + power-down, and keeps it powered for a display the bootloader + started; the PHY driver powers the PHY's domains meanwhile and + keeps it out of USB4. The PHY refuses this while it runs USB4. + mode-switch: + type: boolean + description: + The port's display switch, one per port and shared by all DCPs + that can drive it. The port controller sets the port's + DisplayPort alt mode state, pin assignment and HPD on it; the plug + orientation is the Type-C port's. + port: + $ref: /schemas/graph.yaml#/properties/port + description: + Connects to the display port (port@3) of the port's + usb-c-connector. + dependencies: + mode-switch: [ port ] + required: + - reg + - reg-names + - apple,dfp-endpoint + +required: + - compatible + - reg + - reg-names + - mboxes + - iommus + - scanout + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + display@286e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x86e00000 0x0 0x74000>, + <0x4 0x13000000 0x0 0x84000>, + <0x3 0x00020044 0x0 0x1c>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "coproc", "atc", "dp-clock", "atc-ps", "atc-psd"; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + + scanout { + iommus = <&disp0_dart 0>; + }; + }; + + display@296e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x96e00000 0x0 0x74000>, + <0x3 0x00020044 0x0 0x1c>; + reg-names = "coproc", "dp-clock"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + + scanout { + iommus = <&disp0_dart 0>; + }; + + usb-c@413000000 { + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <3>; + phys = <&atc3_phy 6>; + mode-switch; + + port { + endpoint { + remote-endpoint = <&typec3_display>; + }; + }; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/dma/apple,admac.yaml b/Documentation/devicetree/bindings/dma/apple,admac.yaml index d445faceda863..e472332dc97e7 100644 --- a/Documentation/devicetree/bindings/dma/apple,admac.yaml +++ b/Documentation/devicetree/bindings/dma/apple,admac.yaml @@ -53,6 +53,7 @@ properties: - items: - const: apple,t6041-admac - const: apple,t8132-admac + - const: apple,t8152-admac - items: - const: apple,t6050-admac - const: apple,t8140-admac diff --git a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml index 6c649719118af..779a9b14c6325 100644 --- a/Documentation/devicetree/bindings/i2c/apple,i2c.yaml +++ b/Documentation/devicetree/bindings/i2c/apple,i2c.yaml @@ -32,6 +32,7 @@ properties: - apple,t8132-i2c - apple,t8140-i2c - apple,t8142-i2c + - apple,t8152-i2c - const: apple,t8103-i2c - items: - enum: diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 6e7fdf9af5fdd..c3d2b8bd72bb1 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -32,6 +32,9 @@ properties: - apple,t8103-usb4-dart - apple,t8110-dart - apple,t6000-dart + - apple,t8152-dart-gen3 + - apple,t8152-acio-dart + - apple,t8152-pciec-dart - items: - const: apple,t8140-ane-dart - const: apple,t8140-dart @@ -87,13 +90,16 @@ properties: fabric filter (GAPF) that protects the power state of the coprocessor CPU behind this DART, cleared to power that CPU down, or the shared PS write-disable register that holds this DART's - bit for the same purpose (T8142) + bit for the same purpose (T8142), or on a T8152 Gen3 DART its + window in the SoC's TLB invalidation aperture (ADT + dart-tlbi-aperture plus tlbi-aperture-offset), which the Gen3 + DARTs share reg-names: minItems: 1 items: - const: dart - - enum: [dapf, gapf, ps-wr-dis, auxiliary] + - enum: [dapf, gapf, ps-wr-dis, auxiliary, tlbi] interrupts: maxItems: 1 @@ -320,6 +326,17 @@ properties: and filtering state without a separate page-table root. Source and destination must differ, and both must exist on the controller. + apple,retain-translation: + type: boolean + description: > + The bootloader hands this DART over translating, with stream page + tables that a co-processor's firmware keeps using, but without setting + the hardware lock. The operating system then treats the DART as locked: + it does not reset it or replace the inherited stream roots, adds its + own mappings only in root entries that are empty at handoff, and on + detach clears only the entries it added. The entries present at handoff + stay owned by the firmware, which may keep using them at any time. + required: - compatible - reg @@ -350,6 +367,53 @@ allOf: then: required: - reg-names + - if: + properties: + compatible: + contains: + enum: + - apple,t8152-dart-gen3 + - apple,t8152-acio-dart + - apple,t8152-pciec-dart + then: + description: + The T8152 Gen3 DARTs in front of the display coprocessors and their + display pipes belong to the SPTM. The bootloader hands them over + locked, and the operating system only adds page table entries in + root slots that are empty at handoff. Their TLB command register + answers translation queries; a stream is invalidated through the + TLB invalidation aperture instead. The DARTs of the rear USB4 + routers (ACIO NHI streams) and of their PCIe-C tunnels use the same + invalidation aperture, each at its own slot, but start unlocked with + inactive streams and are initialized by the operating system. + properties: + reg: + minItems: 2 + reg-names: + items: + - const: dart + - const: tlbi + required: + - reg-names + else: + properties: + reg-names: + minItems: 1 + items: + - const: dart + - enum: [dapf, gapf, ps-wr-dis, auxiliary] + + - if: + properties: + compatible: + contains: + enum: + - apple,t8152-acio-dart + - apple,t8152-pciec-dart + then: + required: + - apple,dma-range + - apple,tunable additionalProperties: false diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index 19ffe1bf167f7..a545bddf78d80 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -26,8 +26,8 @@ description: SART3, first seen in M1 Pro/Max, extends both the address space and filter entry size to 42 bit. - SART4, seen on M5 Ultra (T6050), keeps SART3's entries but moves the - address and size arrays, so it has no SART3 fallback. + SART4, seen on M5 Ultra (T6050) and M6 (T8152), keeps SART3's entries but + moves the address and size arrays, so it has no SART3 fallback. properties: compatible: @@ -49,6 +49,7 @@ properties: - apple,t6050-sart - apple,t8015-sart - apple,t8103-sart + - apple,t8152-sart reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8afd38261fe30..caa9e431a4a10 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -27,6 +27,31 @@ properties: masking provided by the interrupt controller. const: apple,t8152-smc-mailbox + - description: + The other T8152 post-office mailboxes. Each coprocessor has its own + window of the same counted-FIFO block as the SMC's. + items: + - enum: + - apple,t8152-ans-mailbox + - apple,t8152-dcp-mailbox + - apple,t8152-mtp-mailbox + - apple,t8152-sep-mailbox + - const: apple,t8152-smc-mailbox + + - description: + T8152 ASC wrapper (v8) mailbox of the AOP, with the counted + FIFOs of the SMC mailbox, described with its send-empty and + recv-not-empty interrupts. + const: apple,t8152-ascwrap-v8-mailbox + + - description: + T8152 ACIO mailbox of a USB4 router's coprocessor, a 0x80 window + with the counted FIFOs of the SMC mailbox, described with its + send-empty and recv-not-empty interrupts. + items: + - const: apple,t8152-cio-mailbox + - const: apple,t8152-smc-mailbox + - description: ASC mailboxes are the most common variant found on the M1 used for example for the display controller, the system management @@ -164,7 +189,9 @@ allOf: properties: compatible: contains: - const: apple,t8152-smc-mailbox + enum: + - apple,t8152-ascwrap-v8-mailbox + - apple,t8152-smc-mailbox then: properties: interrupts: @@ -223,6 +250,7 @@ allOf: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox - apple,t8140-aop-setup-mailbox + - apple,t8152-ascwrap-v8-mailbox - apple,t8152-smc-mailbox then: properties: @@ -243,6 +271,20 @@ required: additionalProperties: false examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + mailbox@316020300 { + compatible = "apple,t8152-ans-mailbox", "apple,t8152-smc-mailbox"; + reg = <0x3 0x16020300 0x0 0x80>; + interrupts = <1 302 4>, <1 262 4>; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + }; + - | mailbox@77408000 { compatible = "apple,t8103-asc-mailbox", "apple,asc-mailbox-v4"; diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index e983d8baf3837..13c643012a557 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -23,6 +23,7 @@ properties: - apple,t8122-nvme-ans2 - const: apple,t8103-nvme-ans2 - const: apple,t8132-nvme-ans2 + - const: apple,t8152-nvme-ans2 - items: - const: apple,t8132-nvme-ans2 - const: apple,t8103-nvme-ans2 @@ -117,6 +118,20 @@ properties: Without it the controller refuses the deep sleep. allOf: + - if: + properties: + compatible: + not: + contains: + enum: + - apple,t6050-nvme-ans2 + - apple,t8152-nvme-ans2 + then: + required: + - resets + - power-domains + - power-domain-names + - if: properties: compatible: @@ -192,10 +207,6 @@ allOf: else: properties: apple,sleep-wake-delay-ms: false - required: - - resets - - power-domains - - power-domain-names required: - compatible diff --git a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml index fe8b2001f4fa5..4a2ba5158b0f6 100644 --- a/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml +++ b/Documentation/devicetree/bindings/nvmem/apple,spmi-nvmem.yaml @@ -28,6 +28,7 @@ properties: - apple,simetra-pmic - apple,stowe-pmic - apple,vale-pmic + - apple,woodcote-pmic - const: apple,spmi-nvmem reg: diff --git a/Documentation/devicetree/bindings/pci/apple,pcie.yaml b/Documentation/devicetree/bindings/pci/apple,pcie.yaml index a9fd4822fd127..70700cb86b839 100644 --- a/Documentation/devicetree/bindings/pci/apple,pcie.yaml +++ b/Documentation/devicetree/bindings/pci/apple,pcie.yaml @@ -101,6 +101,8 @@ properties: - const: apple,t8103-pciec - const: apple,t6000-pciec - const: apple,t6050-pciec + - const: apple,t8142-pciec + - const: apple,t8152-pciec - items: - const: apple,t8132-pciec - const: apple,t8122-pciec @@ -374,6 +376,8 @@ allOf: contains: enum: - apple,t8132-pciec + - apple,t8142-pciec + - apple,t8152-pciec - apple,t6040-pciec then: required: @@ -501,6 +505,8 @@ allOf: - apple,t6000-pciec - apple,t6040-pciec - apple,t6050-pciec + - apple,t8142-pciec + - apple,t8152-pciec then: properties: reg: diff --git a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml index 41ecaccc8a0ae..d3e7f3722d214 100644 --- a/Documentation/devicetree/bindings/phy/apple,atcphy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,atcphy.yaml @@ -40,6 +40,18 @@ description: > DisplayPort also requires separate bootloader-provided calibration lists for that bank and the common configuration in the lpdptx region. + The T8152 variant is supported as the USB3 PHY of a fixed-USB3 port, see + apple,fixed-usb3, and as the PHY of a Type-C port in USB4/Thunderbolt + ("Converged IO", CIO) mode alone. Its core bank also holds the USB + controller's DARTs. Its power domains are the ATC's PMGR power states and + PSD service the PHY needs, in the order they are powered up. The lanes of + the mode are powered up and the crossbar set between the common-a tunables + and the others. A fixed-USB3 port is described by its core and pipehandler + banks. A Type-C port is described by its core bank alone: its DisplayPort + alternate mode is driven by the display controller, which takes the PHY + through its DisplayPort PHY (PHY_TYPE_DP) and has the PHY's power domains + powered while it drives it, and its USB2 side is left to the bootloader. + allOf: - $ref: /schemas/usb/usb-switch.yaml# - if: @@ -122,32 +134,97 @@ allOf: required: - power-domains else: + if: + properties: + compatible: + contains: + const: apple,t8152-atcphy + then: + properties: + reg: + minItems: 1 + items: + - description: + PHY core with its power and reset block, which also holds + the USB controller's DARTs + - description: USB3 PIPE interface controls (fixed-USB3 port) + reg-names: + minItems: 1 + items: + - const: core + - const: pipehandler + power-domains: + items: + - description: The ATC's USB_AON power state + - description: The ATC's common PSD service + - description: The ATC's COMMON_DP_0 power state + - description: The ATC's COMMON_DP_1 power state + required: + - power-domains + else: + properties: + reg: + minItems: 5 + items: + - description: Common controls for all PHYs (USB2/3/4, DisplayPort, TBT) + - description: DisplayPort Alternate Mode PHY specific controls + - description: Type-C PHY AXI to Apple Fabric interconnect controls + - description: USB2 PHY specific controls + - description: USB3 PIPE interface controls + - description: Secondary eUSB2 PHY register bank (T8140) + - description: + Power and hibernation control of the USB controller the PHY + serves (T8140). The PHY drives that controller's reset and + takes it through hibernation for a system sleep. + reg-names: + minItems: 5 + items: + - const: core + - const: lpdptx + - const: axi2af + - const: usb2phy + - const: pipehandler + - const: usb2phy-reg + - const: pwrctl + required: + - power-domains + - if: + properties: + compatible: + contains: + const: apple,t8152-atcphy + then: + properties: + "#reset-cells": false + if: + required: + - apple,fixed-usb3 + then: properties: + mode-switch: false + orientation-switch: false + ports: false reg: - minItems: 5 - items: - - description: Common controls for all PHYs (USB2/3/4, DisplayPort, TBT) - - description: DisplayPort Alternate Mode PHY specific controls - - description: Type-C PHY AXI to Apple Fabric interconnect controls - - description: USB2 PHY specific controls - - description: USB3 PIPE interface controls - - description: Secondary eUSB2 PHY register bank (T8140) - - description: - Power and hibernation control of the USB controller the PHY - serves (T8140). The PHY drives that controller's reset and - takes it through hibernation for a system sleep. + minItems: 2 reg-names: - minItems: 5 - items: - - const: core - - const: lpdptx - - const: axi2af - - const: usb2phy - - const: pipehandler - - const: usb2phy-reg - - const: pwrctl + minItems: 2 + else: + properties: + reg: + maxItems: 1 + reg-names: + maxItems: 1 required: - - power-domains + - mode-switch + - orientation-switch + - ports + else: + properties: + apple,fixed-usb3: false + power-domains: + maxItems: 1 + required: + - "#reset-cells" - if: properties: compatible: @@ -234,6 +311,7 @@ allOf: - apple,t8122-atcphy - apple,t6030-atcphy - apple,t6031-atcphy + - apple,t8152-atcphy then: required: - orientation-switch @@ -275,6 +353,7 @@ properties: - const: apple,t8132-atcphy - const: apple,t8140-atcphy - const: apple,t8142-atcphy + - const: apple,t8152-atcphy reg: minItems: 1 @@ -294,7 +373,8 @@ properties: orientation-switch: true power-domains: - maxItems: 1 + minItems: 1 + maxItems: 4 phys: maxItems: 1 @@ -323,6 +403,16 @@ properties: $ref: /schemas/graph.yaml#/properties/port description: Incoming endpoint from the USB4/Thunderbolt controller. + apple,fixed-usb3: + type: boolean + description: > + T8152 only. The port's SuperSpeed lanes go straight to a USB3 device or + hub, with no Type-C mux in between, so the PHY runs USB3 on lane 0 from + probe on and ignores mux and orientation changes. It provides only the + USB3 PHY of its USB controller, which is a host, and leaves the + controller's USB2 side and reset to the bootloader. Without it a T8152 + PHY is a Type-C port's, run in CIO mode alone. + apple,dp-alt-mode: type: boolean description: > @@ -521,7 +611,6 @@ required: - reg - reg-names - "#phy-cells" - - "#reset-cells" additionalProperties: false @@ -622,3 +711,55 @@ examples: }; }; }; + + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x3 0x83000000 0x0 0x84000>, + <0x3 0x82414000 0x0 0x4000>; + reg-names = "core", "pipehandler"; + + #phy-cells = <1>; + apple,fixed-usb3; + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_common>, + <&ps_atc2_common_dp_0>, <&ps_atc2_common_dp_1>; + + apple,tunable-common-a = <0x00800 0x00fc0000 0x00fc0000>; + apple,tunable-common-b = <0x6c004 0x003f003f 0x00200020>; + apple,tunable-lane0-usb = <0x082d8 0xf0000000 0x70000000>; + }; + + phy@413000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x13000000 0x0 0x84000>; + reg-names = "core"; + + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_common>, + <&ps_atc3_common_dp_0>, <&ps_atc3_common_dp_1>; + + apple,tunable-common-a = <0x00800 0x00fc0000 0x00fc0000>; + apple,tunable-common-b = <0x6c004 0x003f003f 0x00200020>; + apple,tunable-lane0-cio = <0x082d8 0xf0000000 0x70000000>; + apple,tunable-lane1-cio = <0x112d8 0xf0000000 0x70000000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + endpoint { + remote-endpoint = <&typec3_ss>; + }; + }; + }; + }; + }; diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index d8c03b0a12702..63520609e327c 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -90,6 +90,7 @@ properties: - apple,t8132-pmgr-pwrstate - apple,t8140-pmgr-pwrstate - apple,t8142-pmgr-pwrstate + - apple,t8152-pmgr-pwrstate - const: apple,t8103-pmgr-pwrstate reg: diff --git a/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml new file mode 100644 index 0000000000000..fa61de7d3d7e7 --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml @@ -0,0 +1,63 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/apple,t8152-psd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 PMGR2 PSD service + +maintainers: + - Thomas Glanzmann + +description: + On T8152 several blocks (the video decoder, the USB4 routers and their + PHYs, the USB controllers) are powered through PMGR2 PSD services rather + than through PMGR power-state registers. Each service has its own 0x100 + byte register block at the PSD base plus 0x100 times the service number, + with a target-state request, an acknowledge bit and the current state + (0 powered, 6 cold). Reading the state consumes the acknowledge. One node + describes one service as a power domain. + +allOf: + - $ref: power-domain.yaml# + +properties: + compatible: + const: apple,t8152-psd + + reg: + maxItems: 1 + + '#power-domain-cells': + const: 0 + + label: + description: The service's name, for the power domain. + + apple,always-on: + type: boolean + description: + Keep the service powered. For a service whose consumers cannot yet + restore the state another agent set up in its blocks, such as a PHY + configured by the bootloader. + +required: + - compatible + - reg + - '#power-domain-cells' + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + power-controller@303a13200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13200 0x0 0x100>; + #power-domain-cells = <0>; + label = "avd"; + }; + }; diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index 3b05fab7e7af1..f72d6e97577cc 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -38,6 +38,7 @@ properties: - enum: - apple,t8103-cio-reset - apple,t8142-cio-reset + - apple,t8152-cio-reset - apple,t6050-cio-reset - apple,t6000-cio-reset - apple,t6041-cio-reset diff --git a/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml index 9c14c3fff2e41..b23e734de9206 100644 --- a/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml +++ b/Documentation/devicetree/bindings/sound/apple,t8152-aop-audio.yaml @@ -26,6 +26,7 @@ properties: - const: apple,t8142-aop-audio - const: apple,t8152-aop-audio - const: apple,t6050-aop-audio + - const: apple,t8152-aop-audio dmas: minItems: 4 diff --git a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml index 48706095da208..14d037a00aedd 100644 --- a/Documentation/devicetree/bindings/spmi/apple,spmi.yaml +++ b/Documentation/devicetree/bindings/spmi/apple,spmi.yaml @@ -41,6 +41,11 @@ properties: - apple,t8132-spmi - apple,t8140-spmi - const: apple,t8103-spmi + - description: + The gen-4 controller of T8152, with its FIFO registers at 0x200. + items: + - const: apple,t8152-spmi + - const: apple,t8142-spmi reg: minItems: 1 diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index 01592811223d2..70a883b4696fe 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -30,6 +30,7 @@ properties: oneOf: - const: apple,t8103-usb4-acio - const: apple,t8142-usb4-acio + - const: apple,t8152-usb4-acio - const: apple,t6040-usb4-acio - const: apple,t6050-usb4-acio - items: @@ -52,8 +53,8 @@ properties: PCIe adapter configuration space of the USB4 router. Present where the root complex exposes the adapter separately, so that the tunnel can be configured before a PCIe-C link is brought up. - - description: MxWrap co-processor control registers, on T8132 and T6050 - - description: PCIe router AP firmware registers, on T6050 + - description: MxWrap co-processor control registers, on T8132, T8142 and T6050 + - description: PCIe router AP firmware registers, on T8142 and T6050 reg-names: oneOf: @@ -69,6 +70,14 @@ properties: - const: rc - const: sram - const: cpu + - description: + T8152, whose router CPU is started by a reconfiguration request + through its mailbox and has no window of its own + items: + - const: rc + - const: sram + - const: pcie-adapter + - const: router-ap-fw mboxes: maxItems: 1 @@ -185,8 +194,12 @@ properties: const: 1 ranges: - maxItems: 1 - description: Single 16 MiB MMIO window containing all child registers + minItems: 1 + maxItems: 2 + description: + 16 MiB MMIO window containing the child registers. On T8152 a second + range maps the shared Gen3 DART TLB invalidation aperture for the + router's DART. nonposted-mmio: true @@ -253,12 +266,24 @@ allOf: enum: - apple,t6040-usb4-acio - apple,t8132-usb4-acio + - apple,t8142-usb4-acio + - apple,t8152-usb4-acio then: properties: reg: minItems: 4 reg-names: minItems: 4 + - if: + properties: + compatible: + not: + contains: + const: apple,t8152-usb4-acio + then: + properties: + ranges: + maxItems: 1 - if: properties: compatible: @@ -267,6 +292,8 @@ allOf: - apple,t6040-usb4-acio - apple,t6050-usb4-acio - apple,t8132-usb4-acio + - apple,t8142-usb4-acio + - apple,t8152-usb4-acio then: properties: pinctrl-names: @@ -309,7 +336,29 @@ allOf: properties: power-domains: maxItems: 4 + - if: + properties: + compatible: + not: + contains: + enum: + - apple,t6050-usb4-acio + - apple,t8142-usb4-acio + - apple,t8152-usb4-acio + then: + properties: apple,tunable-router-ap-fw: false + - if: + properties: + compatible: + contains: + const: apple,t8142-usb4-acio + then: + properties: + reg: + minItems: 5 + reg-names: + minItems: 5 additionalProperties: false diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml index 28718fed167c5..c68f883b10d0f 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml @@ -22,6 +22,7 @@ properties: oneOf: - const: apple,t8103-usb4-nhi - const: apple,t8142-usb4-nhi + - const: apple,t8152-usb4-nhi - const: apple,t6040-usb4-nhi - const: apple,t6050-usb4-nhi - items: @@ -131,6 +132,7 @@ allOf: contains: enum: - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi - apple,t6040-usb4-nhi - apple,t6050-usb4-nhi then: @@ -155,6 +157,7 @@ allOf: - apple,t8122-usb4-nhi - apple,t8132-usb4-nhi - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi - apple,t6040-usb4-nhi - apple,t6050-usb4-nhi then: diff --git a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml index 6612a5370ee36..6bc0c202dceec 100644 --- a/Documentation/devicetree/bindings/usb/apple,dwc3.yaml +++ b/Documentation/devicetree/bindings/usb/apple,dwc3.yaml @@ -13,6 +13,12 @@ description: Apple Silicon SoCs use a Synopsys DesignWare DWC3 based controller for each of their Type-C ports. + On T8152 the bootloader can hand a controller over already running, powered + and with the USB2 side of its ATC PHY set up for host mode. Such a controller + is described by its DWC3 core region, as a host. Its PHY reset and power + domain, and on a Type-C port its USB role switch, exist but are left to the + bootloader, so they are optional. + allOf: - $ref: snps,dwc3-common.yaml# - if: @@ -20,11 +26,37 @@ allOf: compatible: not: contains: - const: apple,t8132-dwc3 + enum: + - apple,t8132-dwc3 + - apple,t8152-dwc3 then: required: - power-domains - if: + properties: + compatible: + contains: + const: apple,t8152-dwc3 + then: + properties: + dr_mode: + const: host + required: + - dr_mode + else: + properties: + reg: + minItems: 2 + reg-names: + minItems: 2 + required: + - reg-names + - if: + properties: + compatible: + not: + contains: + const: apple,t8152-dwc3 not: properties: status: @@ -85,9 +117,10 @@ properties: - const: apple,t8103-dwc3 - const: apple,t8103-dwc3 - const: apple,t8132-dwc3 + - const: apple,t8152-dwc3 reg: - minItems: 2 + minItems: 1 items: - description: Core DWC3 region - description: Apple-specific DWC3 region @@ -96,7 +129,7 @@ properties: - description: AUSBC debug block (T6050) reg-names: - minItems: 2 + minItems: 1 items: - const: dwc3-core - const: dwc3-apple @@ -160,7 +193,6 @@ properties: required: - compatible - reg - - reg-names - interrupts - iommus @@ -183,3 +215,18 @@ examples: usb-role-switch; }; + + - | + #include + #include + + usb@82430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x82430000 0xcd00>; + interrupts = ; + iommus = <&dwc3_2_dart_0 0>, <&dwc3_2_dart_1 1>; + dr_mode = "host"; + maximum-speed = "high-speed"; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; diff --git a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml index cc82767a25a51..84ae1f7bf0880 100644 --- a/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml +++ b/Documentation/devicetree/bindings/usb/apple,sn201202x.yaml @@ -18,7 +18,9 @@ description: | The controller can be polled when interrupt resources are not supplied. T8132 omits the register-selection interrupt, so selection is polled while - event, standby and wakeup notifications use interrupts. + event, standby and wakeup notifications use interrupts. The T8152 + controllers work as the T8132 ones do: no register-selection interrupt, and + the payload length of a selected register in register 0x1f. properties: compatible: @@ -27,6 +29,10 @@ properties: - items: - const: apple,t8132-sn201202x - const: apple,sn201202x + - items: + - const: apple,t8152-sn201202x + - const: apple,t8132-sn201202x + - const: apple,sn201202x reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml index e321ee28733d1..9a6634e146d75 100644 --- a/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml +++ b/Documentation/devicetree/bindings/watchdog/apple,wdt.yaml @@ -26,6 +26,7 @@ properties: - apple,t8132-wdt - apple,t8140-wdt - apple,t8142-wdt + - apple,t8152-wdt - const: apple,t8103-wdt - items: - enum: diff --git a/MAINTAINERS b/MAINTAINERS index 5c8fc89e51d00..8bd740eea9930 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2093,6 +2093,7 @@ F: drivers/soc/apple/pmp.rs F: include/linux/mt7932.h F: include/linux/soc/apple/pmp-report.h F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-quiesced.yaml +F: Documentation/devicetree/bindings/chosen/apple,dcp-rtkit-running.yaml F: Documentation/devicetree/bindings/chosen/aurora,ctxr-exec-window.yaml F: Documentation/devicetree/bindings/display/apple,dcp.yaml F: Documentation/devicetree/bindings/display/apple,display-subsystem.yaml @@ -2150,6 +2151,15 @@ F: tools/testing/kunit/configs/mt7932.config F: tools/testing/selftests/drivers/apple/aop-las.py F: tools/testing/selftests/drivers/gpu/apple-dcp/ +APPLE T8152 DCP DISPLAY DRIVER (IBOOT INTERFACE) +M: Thomas Glanzmann +L: dri-devel@lists.freedesktop.org +S: Maintained +F: Documentation/devicetree/bindings/display/apple,t8152-dcp-iboot.yaml +F: drivers/gpu/drm/apple/iboot_drm.c +F: drivers/gpu/drm/apple/iomfb_iboot.* +F: drivers/gpu/drm/apple/t8152_* + APPLETALK NETWORK LAYER L: netdev@vger.kernel.org S: Obsolete diff --git a/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi new file mode 100644 index 0000000000000..72bfb845022b8 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-audio.dtsi @@ -0,0 +1,258 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g audio: the AOP (always-on processor) owns the audio fabric, as + * on T8140. iBoot loads the AOP firmware (j873gaop) and leaves the CPU + * stopped; Linux starts it. The jack codec (CS42L84) and the speaker amp + * (SN012776) are on AP I2C buses; their data goes through AOP services on + * the base-ns ADMAC. Resources are from the 26A434 ADT: aop, dart-sbr, + * admac-base-ns, iop-audio-controller, i2c1, i2c3, pmgr. + */ +#include + +/* + * ADT dart-sbr (sbr_dart in t8152-peripherals.dtsi), shared with the PMP: + * mapper-aop 0, mapper-admac-base-ns 42. iBoot leaves streams 0, 1 and 42 + * translating (root slot 16 owned by the firmware) without setting the + * lock bit. + */ +&sbr_dart { + apple,retain-translation; + status = "okay"; +}; + +/ { + soc { + /* + * ADT aop: iop,ascwrap-v8, msgbox-mailbox-num 0, using-alias, + * not post-office: mailbox 0, aperture 1 of the bank at reg[2] + * (0x310740000) = 0x310740080. ADT interrupts [627, 626, 628]; + * the first two in the SMC order (send-empty, recv-not-empty). + */ + aop_mbox: mailbox@310740080 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x10740080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* + * ADT admac-base-ns (admac-evolution,t8152): 13 TX and 13 RX + * channels, interrupt destination 0, dart-sbr stream 42. + */ + admac_base_ns: dma-controller@313900000 { + compatible = "apple,t8152-admac"; + reg = <0x3 0x13900000 0x0 0xb4000>; + dma-channels = <26>; + interrupts-extended = <&aic AIC_IRQ 640 IRQ_TYPE_LEVEL_HIGH>, + <0>, <0>, <0>; + #dma-cells = <1>; + iommus = <&sbr_dart 42>; + /* slot 17: slot 16 of stream 42 belongs to the firmware */ + apple,dma-range = <0x110 0x0 0x0 0x10000000>; + }; + + /* + * The AOP's PMGR (ADT pmgr devices AUDIO_MCA0_M..AUDIO_MCA5_M at + * 0x308284400 + 0x20 * N). Their parent audio_p is the + * firmware's: it is up while a service is in pw0 or pwrd. + */ + pmgr_aop: power-management@308284000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", + "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x08284000 0x0 0x1000>; + + ps_audio_mca0_m: power-controller@400 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x400 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca0_m"; + }; + + ps_audio_mca1_m: power-controller@420 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x420 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca1_m"; + }; + + ps_audio_mca2_m: power-controller@440 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x440 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca2_m"; + }; + + ps_audio_mca3_m: power-controller@460 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x460 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca3_m"; + }; + + ps_audio_mca4_m: power-controller@480 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x480 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca4_m"; + }; + + ps_audio_mca5_m: power-controller@4a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x4a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "audio_mca5_m"; + }; + }; + + /* ADT i2c1: the CS42L84 jack codec (and the aqc NIC's EEPROM). */ + i2c1: i2c@331014000 { + compatible = "apple,t8152-i2c", "apple,t8103-i2c"; + reg = <0x3 0x31014000 0x0 0x4000>; + clocks = <&clkref>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + power-domains = <&ps_i2c1>; + + /* + * ADT audio-codec-output: function-reset GPIO 0xcc, + * interrupt on gpio0 pin 203. + */ + jack_codec: codec@4b { + compatible = "cirrus,cs42l84"; + reg = <0x4b>; + reset-gpios = <&pinctrl_ap 204 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 203 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + sound-name-prefix = "Jack"; + }; + }; + + /* ADT i2c3: the SN012776 speaker amplifier. */ + i2c3: i2c@33101c000 { + compatible = "apple,t8152-i2c", "apple,t8103-i2c"; + reg = <0x3 0x3101c000 0x0 0x4000>; + clocks = <&clkref>; + interrupts = ; + #address-cells = <1>; + #size-cells = <0>; + power-domains = <&ps_i2c3>; + + /* + * ADT audio-speaker: function-reset GPIO 0xca, interrupt + * on gpio0 pin 193, speaker-config rx_slot 0, + * vsense_slot 0, isense_slot 2. + */ + speaker_amp: codec@38 { + compatible = "ti,sn012776", "ti,tas2764"; + reg = <0x38>; + shutdown-gpios = <&pinctrl_ap 202 GPIO_ACTIVE_HIGH>; + interrupts-extended = <&pinctrl_ap 193 IRQ_TYPE_LEVEL_LOW>; + #sound-dai-cells = <0>; + ti,imon-slot-no = <2>; + ti,vmon-slot-no = <0>; + /* the AOP's speaker frame: 250 BCLKs at 12 MHz */ + ti,bclk-ratio = <250>; + }; + }; + + aop: aop@310c00000 { + compatible = "apple,t8152-aop"; + reg = <0x3 0x10c00000 0x0 0x1e0000>, + <0x3 0x10600000 0x0 0x4000>; + reg-names = "mmio", "asc"; + mboxes = <&aop_mbox>; + mbox-names = "mbox"; + iommus = <&sbr_dart 0>; + /* slot 17: slot 16 belongs to the firmware */ + apple,dma-range = <0x110 0x0 0x10 0x0>; + + /* + * Bound by name to the firmware's "audio" EPIC service. + * ADT iop-audio-controller: cout/cin on base-ns TX5/RX5, + * spkr on TX1 with its sense data on RX1; Linux ADMAC + * channel = 2 * N for TX N, 2 * N + 1 for RX N. + */ + aop_audio: audio { + compatible = "apple,t8152-aop-audio"; + dmas = <&admac_base_ns 10>, <&admac_base_ns 11>, + <&admac_base_ns 2>, <&admac_base_ns 3>; + dma-names = "cout", "cin", "spkr", "sense"; + power-domains = <&ps_audio_mca0_m>, <&ps_audio_mca1_m>, + <&ps_audio_mca2_m>, <&ps_audio_mca3_m>, + <&ps_audio_mca4_m>, <&ps_audio_mca5_m>; + power-domain-names = "mca0", "mca1", "mca2", + "mca3", "mca4", "mca5"; + #sound-dai-cells = <1>; + }; + }; + }; + + sound { + compatible = "apple,j873-macaudio", "apple,macaudio"; + model = "Mac mini J873"; + #address-cells = <1>; + #size-cells = <0>; + + dai-link@0 { + reg = <0>; + link-name = "Headphone Jack"; + + cpu { + sound-dai = <&aop_audio 0>; + }; + codec { + sound-dai = <&jack_codec>; + }; + }; + + dai-link@1 { + reg = <1>; + link-name = "Speaker"; + + cpu { + sound-dai = <&aop_audio 3>; + }; + codec { + sound-dai = <&speaker_amp>; + }; + }; + }; +}; + +/* The I2C power states (PMGR, parent SIO_CPU is always on). */ +&pmgr { + ps_i2c1: power-controller@cc0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xcc0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c1"; + }; + + ps_i2c3: power-controller@d00 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xd00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "i2c3"; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi new file mode 100644 index 0000000000000..0c7df8e3a55dd --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-dcp.dtsi @@ -0,0 +1,758 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g displays: three controllers for the rear USB-C and HDMI ports, + * driven through + * the DCP firmware's iBoot interface (apple,t8152-dcp-iboot). The + * bootloader hands over running or quiesced RTKit sessions. Unused + * controllers can claim another USB-C monitor through the shared crossbar. + * + * Resources are from the 26A434 ADT: dcp (iop,ascwrap-v8, post-office + * mailbox 5 with alias: 0x316020000 + 2 * 5 * 0x80), dart-dcp (SID 23), + * dart-disp0 (scanout SID 0), and the atc-phyN PHY windows. The Gen3 + * display DARTs stay locked by iBoot, each with its own live root, so the + * scanout stream is a child device with its own domain. Linux tables are + * published into vacant root slots, so the DMA window is the upper half of + * the 64 GiB vm-base window, above the firmware's and the bootloader's + * mappings. + */ +#include +#include + +/* + * The display coprocessors' PMGR power states (ADT pmgr devices DISP_CPU, + * DISPEXT0_CPU and DISPEXT1_CPU), which their DARTs follow. The PMGR does not + * switch them for the AP: the coprocessor is started through its PSD service + * (coproc-psd below) and its firmware runs the state, so Linux only reads + * DISPEXT0_CPU (coproc-ps). They are the firmware's: the OS keeps them on and + * never accesses them. + */ +&pmgr { + ps_dispext1_cpu: power-controller@aa0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xaa0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext1_cpu"; + apple,firmware-owned; + }; + + ps_dispext0_cpu: power-controller@e00 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xe00 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "dispext0_cpu"; + apple,firmware-owned; + }; + + ps_disp_cpu: power-controller@14000 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x14000 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "disp_cpu"; + apple,firmware-owned; + }; +}; + +&dcp_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_disp_cpu>; + status = "okay"; +}; + +&disp0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_disp_cpu>; + status = "okay"; +}; + +&dcpext0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext0_cpu>; + status = "okay"; +}; + +&dispext0_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext0_cpu>; + status = "okay"; +}; + +&dcpext1_dart { + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext1_cpu>; + status = "okay"; +}; + +&dispext1_dart { + reg-names = "dart", "dapf"; + apple,dma-range = <0x108 0x0 0x8 0x0>; + power-domains = <&ps_dispext1_cpu>; + status = "okay"; +}; + +/ { + soc { + /* + * ADT /arm-io/nub-spmi-a0 (gen 4): the USB-C PD controllers of + * the three rear ports, each of which can carry the USB-C display. + * Their event, sleep and wake sources are interrupts of this + * controller (the ADT's), its own line is AIC 682. A connector's + * display port leads to the port's display switch, which all + * DCPs share. + */ + nub_spmi_a0: spmi@308908000 { + compatible = "apple,t8152-spmi", "apple,t8142-spmi"; + reg = <0x3 0x08908000 0x0 0x4000>; + interrupt-parent = <&aic>; + interrupts = ; + interrupt-controller; + #interrupt-cells = <2>; + #address-cells = <2>; + #size-cells = <0>; + + /* back-middle */ + hpm0: usb-pd@c { + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; + reg = <0xc SPMI_USID>; + interrupts = <11 IRQ_TYPE_EDGE_RISING>, + <17 IRQ_TYPE_EDGE_RISING>, + <19 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec0: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-middle"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec0_ss: endpoint { + remote-endpoint = <&atc0_phy_typec>; + }; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec0_display: endpoint { + remote-endpoint = <&display_typec0>; + }; + }; + }; + }; + }; + + /* back-left */ + hpm1: usb-pd@a { + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; + reg = <0xa SPMI_USID>; + interrupts = <37 IRQ_TYPE_EDGE_RISING>, + <43 IRQ_TYPE_EDGE_RISING>, + <45 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec1: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-left"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec1_ss: endpoint { + remote-endpoint = <&atc1_phy_typec>; + }; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec1_display: endpoint { + remote-endpoint = <&display_typec1>; + }; + }; + }; + }; + }; + + /* back-right */ + hpm3: usb-pd@8 { + compatible = "apple,t8152-sn201202x", "apple,t8132-sn201202x", + "apple,sn201202x"; + reg = <0x8 SPMI_USID>; + interrupts = <63 IRQ_TYPE_EDGE_RISING>, + <69 IRQ_TYPE_EDGE_RISING>, + <71 IRQ_TYPE_EDGE_RISING>; + interrupt-names = "irq", "sleep", "wake"; + + typec3: connector { + compatible = "usb-c-connector"; + label = "USB-C Back-right"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + /* USB: not linked to its controller yet */ + port@0 { + reg = <0>; + }; + + /* SuperSpeed: the ATC PHY */ + port@1 { + reg = <1>; + + typec3_ss: endpoint { + remote-endpoint = <&atc3_phy_typec>; + }; + }; + + /* DisplayPort: the DCPs' display switch */ + port@3 { + reg = <3>; + + typec3_display: endpoint { + remote-endpoint = <&display_typec3>; + }; + }; + }; + }; + }; + }; + + /* + * ADT aop-gpio. Its interrupts are the AOP's, so it has no + * interrupt controller here; the HDMI HPD line is polled. + */ + pinctrl_aop: pinctrl@310824000 { + compatible = "apple,t8152-pinctrl", "apple,t8103-pinctrl"; + reg = <0x3 0x10824000 0x0 0x4000>; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&pinctrl_aop 0 0 77>; + apple,npins = <77>; + }; + + dcp_mbox: mailbox@316020500 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020500 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + dcp_iboot: display@286e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x2 0x86e00000 0x0 0x74000>, + <0x3 0x00020044 0x0 0x1c>, + <0x3 0x1a760000 0x0 0x4000>, + <0x3 0x00700460 0x0 0x4>; + /* aux: ADT dptx0-aux, aux-ps: PMGR GLOBAL_AUX_CTRL0 */ + reg-names = "coproc", "dp-clock", "aux", "aux-ps"; + #address-cells = <2>; + #size-cells = <2>; + ranges; + mboxes = <&dcp_mbox>; + iommus = <&dcp_dart 23>; + power-domains = <&ps_disp_cpu>; + /* + * Cacheable DMA, as iBoot maps DCP buffers: the firmware + * faults on entries with the DART's no-cache bit. + */ + dma-coherent; + apple,dp-source = <0>; + + /* + * The display pipe's own stream: a separate device, so + * its domain imports dart-disp0's root, not dart-dcp's. + */ + scanout { + iommus = <&disp0_dart 0>; + dma-coherent; + }; + + /* + * USB-C back-middle: ADT atc-phy0. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. + */ + usb-c@403000000 { + reg = <0x4 0x03000000 0x0 0x84000>, + <0x3 0x08290000 0x0 0x104>, + <0x3 0x03a13700 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <0>; + /* Powered while a DCP drives it */ + phys = <&atc0_phy PHY_TYPE_DP>; + /* The DCPs' display switch of the port */ + mode-switch; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bca4>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + + port { + display_typec0: endpoint { + remote-endpoint = <&typec0_display>; + }; + }; + }; + + /* + * USB-C back-left: ADT atc-phy1. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. + */ + usb-c@40b000000 { + reg = <0x4 0x0b000000 0x0 0x84000>, + <0x3 0x08290040 0x0 0x104>, + <0x3 0x03a13800 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <1>; + /* Powered while a DCP drives it */ + phys = <&atc1_phy PHY_TYPE_DP>; + /* The DCPs' display switch of the port */ + mode-switch; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + + port { + display_typec1: endpoint { + remote-endpoint = <&typec1_display>; + }; + }; + }; + + /* + * USB-C back-right: ADT atc-phy3. PS: the ATC's DP_0, DP_1 and + * USB_AON power states (+0, +0x20, +0x100), PSD: its common + * domain, read to tell whether the PHY runs; the ATC PHY + * driver powers them while the DP PHY is on. Tunables before + * and after the lane crossbar setup. The node is also the + * port's display switch for all DCPs. + */ + usb-c@413000000 { + reg = <0x4 0x13000000 0x0 0x84000>, + <0x3 0x082900c0 0x0 0x104>, + <0x3 0x03a13a00 0x0 0xc0>; + reg-names = "atc", "atc-ps", "atc-psd"; + apple,dfp-endpoint = <3>; + /* Powered while a DCP drives it */ + phys = <&atc3_phy PHY_TYPE_DP>; + /* The DCPs' display switch of the port */ + mode-switch; + apple,tunable-pre = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-post = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* ASDC_AUX_SHM_DFLT */ + <0x02308 0x000000fc 0x00000084>; + + port { + display_typec3: endpoint { + remote-endpoint = <&typec3_display>; + }; + }; + }; + + }; + + /* + * DCPEXT0 (post-office mailbox 6) can drive USB-C, or the dedicated + * dptx-phy through the PS190 converter. ADT dcpext0, + * dart-dcpext0 and dart-dispext0. + */ + dcpext_mbox: mailbox@316020600 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020600 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + dcpext_iboot: display@32ae00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x3 0x2ae00000 0x0 0x74000>, + <0x3 0x1a740000 0x0 0x10000>, + <0x3 0x1a700000 0x0 0x4000>, + <0x3 0x1a764000 0x0 0x4000>, + <0x3 0x00700480 0x0 0x4>, + <0x3 0x007016c0 0x0 0x4>, + <0x3 0x00700e00 0x0 0x4>, + <0x3 0x03a12c00 0x0 0xc0>, + <0x3 0x03a10500 0x0 0xc0>; + /* aux: ADT dptx1-aux, aux-ps: PMGR GLOBAL_AUX_CTRL1 */ + /* PMGR DPTX_PHY, read-only DISPEXT0_CPU, PSD service 5 (dptx-phy) */ + reg-names = "coproc", "phy-core", "phy-apb", "aux", "aux-ps", + "phy-ps", "coproc-ps", "coproc-psd", "phy-psd"; + mboxes = <&dcpext_mbox>; + iommus = <&dcpext0_dart 23>; + power-domains = <&ps_dispext0_cpu>; + dma-coherent; + apple,dp-source = <1>; + apple,usb-c-ports = <&dcp_iboot>; + apple,hdmi; + /* ADT dp2hdmi-gpio0 function-hdmi_hpd */ + hpd-gpios = <&pinctrl_aop 41 GPIO_ACTIVE_HIGH>; + /* function-dp2hdmi_pwr_en, function-hdmi_pwr_en (SMC pcIO) */ + apple,smc = <&smc>; + apple,pcon-power = <0x7063494f 0x00140000 0x00000001>, + <0x7063494f 0x000f0000 0x00800001>; + /* ADT dptx-phy tunables, in AppleT8152DPTXPort::handleSetTunables order */ + apple,tunable-phy = <0x5180 0x1fff000 0x723000>, + <0x5184 0xffffffff 0x2bc>, + <0x7980 0x1fff000 0x723000>, + <0x7984 0xffffffff 0x2bc>, + <0xa180 0x1fff000 0x723000>, + <0xa184 0xffffffff 0x2bc>, + <0xc980 0x1fff000 0x723000>, + <0xc984 0xffffffff 0x2bc>, + <0x4524 0x3800000 0x2800000>, + <0x6d24 0x3800000 0x2800000>, + <0x9524 0x3800000 0x2800000>, + <0xbd24 0x3800000 0x2800000>, + <0x840 0xc 0x8>, + <0x860 0x1c000 0xc000>, + <0x898 0xf00 0x800>, + <0x89c 0xfe000 0xfe000>, + <0x908 0x7c00000 0x4000000>, + <0x90c 0x7c 0x10>, + <0x68c 0x7f 0x3c>, + <0x69c 0x7f 0x32>, + <0x6ac 0x7f 0x32>, + <0x6bc 0x7f 0x5a>, + <0x1408 0xfc 0x84>, + <0x1c4c 0xff800 0xff800>, + <0x1c5c 0xff 0x80>, + <0x1c60 0x7fffff 0x52bba7>, + <0x1c64 0x2c00000 0x800000>; + + scanout { + iommus = <&dispext0_dart 0>; + dma-coherent; + }; + + }; + + dcpext1_mbox: mailbox@316020700 { + compatible = "apple,t8152-ascwrap-v8-mailbox"; + reg = <0x3 0x16020700 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* ADT dcpext1: crossbar UFP2, firmware SID23, scanout SID0. */ + dcpext1_iboot: display@502e00000 { + compatible = "apple,t8152-dcp-iboot"; + reg = <0x5 0x02e00000 0x0 0x74000>, + <0x3 0x03a12d00 0x0 0xc0>; + reg-names = "coproc", "coproc-psd"; + mboxes = <&dcpext1_mbox>; + iommus = <&dcpext1_dart 23>; + power-domains = <&ps_dispext1_cpu>; + dma-coherent; + apple,dp-source = <2>; + apple,usb-c-ports = <&dcp_iboot>; + + scanout { + iommus = <&dispext1_dart 0>; + dma-coherent; + }; + + }; + + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi new file mode 100644 index 0000000000000..b40923e9fec9e --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-ethernet.dtsi @@ -0,0 +1,105 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g internal PCIe (apcie) port 2: the on-board 10GbE NIC (ADT + * /arm-io/apcie/pci-bridge2/lan0; the ADT names an aqc107, the device has + * PCI ID 10ec:8127 and identifies as a Realtek RTL8125CP, XID 0x708). + * iBoot leaves the APCIE power domains on and + * the root complex enabled, but the AUS5 PHY gated and the lanes assigned + * to port 0; the loader ungates the PHY, writes the ADT lane-cfg and applies + * the dart-apcie2 tunables first. Port setup follows the T602x/T8122 + * register layout. Port 0 (N1) is bus 1, port 2 is bus 2. + * Resources are from the 26A434 ADT: apcie, dart-apcie2, gpio0. + */ +#include + +/ { + aliases { + ethernet0 = ðernet0; + }; +}; + +/* + * The internal PCIe power states (ADT pmgr devices APCIE_GP and APCIE_SYS_GP, + * the latter's parent the former). iBoot leaves both on, and Linux cannot redo + * the PHY and lane setup the loader does on them, so they stay on, without + * automatic power management: APCIE_GP has no automatic state set and would + * be power gated by it. dart-apcie2 takes APCIE_SYS_GP, as on T8142. + */ +&pmgr { + ps_apcie_gp: power-controller@8c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x8c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_apcie_sys_gp: power-controller@ec0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xec0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_gp"; + power-domains = <&ps_apcie_gp>; + apple,no-auto-pm; + apple,always-on; + }; +}; + +/* + * dart-apcie2, described in t8152-peripherals.dtsi. The ADT window is + * 0x20000; keep the 0xc000 this port was brought up with, the size that + * pcie0_dart has in t8152-j873-n1.dtsi. + */ +&pcie2_dart { + reg = <0x3 0x8a000000 0x0 0xc000>; + power-domains = <&ps_apcie_sys_gp>; + status = "okay"; +}; + +&pcie { + reg = <0x1c 0xb0000000 0x0 0x1000000>, /* config */ + <0x3 0x8c000000 0x0 0x4000>, /* rc */ + <0x3 0x88028000 0x0 0x4000>, /* port0 */ + <0x3 0x8f010000 0x0 0x4000>, /* phy0 */ + <0x3 0x8a028000 0x0 0x4000>, /* port2 */ + <0x3 0x8f018000 0x0 0x4000>; /* phy2 */ + reg-names = "config", "rc", "port0", "phy0", "port2", "phy2"; + /* One per root port, indexed by the port number. */ + interrupts = , + , + ; + iommu-map = <0x100 &pcie0_dart 1 1>, + <0x101 &pcie0_dart 2 1>, + <0x102 &pcie0_dart 3 1>, + <0x200 &pcie2_dart 1 1>; + bus-range = <0 7>; + + port02: pci@2,0 { + device_type = "pci"; + reg = <0x1000 0x0 0x0 0x0 0x0>; + reset-gpios = <&pinctrl_ap 5 GPIO_ACTIVE_LOW>; + bus-range = <2 2>; + #address-cells = <3>; + #size-cells = <2>; + ranges; + + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &port02 0 0 0 0>, + <0 0 0 2 &port02 0 0 0 1>, + <0 0 0 3 &port02 0 0 0 2>, + <0 0 0 4 &port02 0 0 0 3>; + + ethernet0: ethernet@0,0 { + reg = <0x20000 0x0 0x0 0x0 0x0>; + /* Filled in by the loader from the ADT. */ + local-mac-address = [00 00 00 00 00 00]; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi new file mode 100644 index 0000000000000..741162fe483ff --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-nvme.dtsi @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g ANS2 NVMe. + * iBoot leaves the ANS firmware running with the NVMe controller disabled; + * the driver wakes it with a fresh RTKit handshake (as m1n1 does). NVMe + * registers and NVMMU share the 0x325cc0000 window. The mailbox is the ANS + * post-office window (msgbox-mailbox-num 3, no alias: 0x316000000 + + * 0x10300), the SMC mailbox's counted FIFO. Its interrupts are the first two + * of the ADT's ans list, in the order the SMC and DCP mailboxes' ADT lists + * give theirs: send-empty, recv-not-empty. No PMGR power or reset yet. + * Resources are from the 26A434 ADT: ans, sart-ans. + */ + +/ { + soc { + ans_mbox: mailbox@316010300 { + compatible = "apple,t8152-ans-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x3 0x16010300 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + sart: iommu@325c50000 { + compatible = "apple,t8152-sart"; + reg = <0x3 0x25c50000 0x0 0xc000>; + }; + + nvme: nvme@325cc0000 { + compatible = "apple,t8152-nvme-ans2"; + reg = <0x3 0x25cc0000 0x0 0x60000>, + <0x3 0x21600000 0x0 0x4000>; + reg-names = "nvme", "ans"; + interrupts = ; + mboxes = <&ans_mbox>; + apple,sart = <&sart>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi index c03fbf04b24e4..538511e3ffc17 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-j873-qspi.dtsi @@ -25,7 +25,8 @@ "syscon", "simple-mfd"; #address-cells = <1>; #size-cells = <1>; - reg = <0x3 0x700000 0x0 0x14000>; + /* ADT pmgr reg[32]: power states up to DISP_CPU at 0x14000 */ + reg = <0x3 0x700000 0x0 0x1c000>; }; qspi: spi@331118000 { diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi new file mode 100644 index 0000000000000..83c99eced8749 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb.dtsi @@ -0,0 +1,1230 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g USB host bring-up: usb-drd1 (back-left port, USB2) and usb-drd2 + * (front ports via the on-board hub, USB2 and USB3). + * The loader powers the controllers and sets up the USB2 side of their ATC + * PHYs for host mode before Linux starts (there is no T8152 USB2 PHY or Type-C + * support yet). + * The controllers are described by their DWC3 core region, as hosts behind + * their two DARTs (apple,t8152-dwc3); their PHY reset, and on the Type-C port + * the role switch, exist but are left to the loader. + * usb-drd2's hub is wired to ATC2's PHY without a Type-C mux, so Linux brings + * that PHY up in USB3 mode (atc2_phy). + * The rear ports' ATC PHYs (atc0_phy, atc1_phy, atc3_phy) run CIO mode for + * USB4 alone: their DisplayPort alt mode is the display controllers', which + * take a PHY through its DP PHY, and their USB2 side stays with the loader. + * Resources are from the 26A434 ADT: dart-usb1/2, usb-drd1/2 (on atc-phy1 and + * atc-phy2), atc-phy0-3 and the pmgr devices ATCn_USB_AON, ATC1/2_USB and + * ATCn_COMMON_DP_0/1. + * + * dart-usb1 and dart-usb2 each have two DART instances (ADT reg[0] and + * reg[1], 0xc000 each, sharing one interrupt). t8152-peripherals.dtsi lists + * both windows on one node (dwc3_1_dart, dwc3_2_dart), but the DART driver + * drives one instance per node and the binding reads a second reg entry as + * DAPF or auxiliary registers. Keep instance 0 on the shared node, with its + * own window only, and describe instance 1 as a node of its own. + */ + +#include + +&dwc3_1_dart { + reg = <0x4 0x0b020000 0x0 0xc000>; + power-domains = <&ps_atc1_usb>; + status = "okay"; +}; + +&dwc3_2_dart { + reg = <0x3 0x83020000 0x0 0xc000>; + power-domains = <&ps_atc2_usb>; + status = "okay"; +}; + +/ { + soc { + dwc3_1_dart_1: iommu@40b040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_atc1_usb>; + }; + + usb1: usb@40a430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + maximum-speed = "high-speed"; + iommus = <&dwc3_1_dart 0>, <&dwc3_1_dart_1 1>; + power-domains = <&ps_atc1_usb>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + + dwc3_2_dart_1: iommu@383040000 { + compatible = "apple,t8152-dart", "apple,t8110-dart"; + reg = <0x3 0x83040000 0x0 0xc000>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&ps_atc2_usb>; + }; + + /* + * The ATCs' PMGR power states (ADT pmgr devices ATCn_COMMON_DP_0/1 + * from 0x308290000 and ATCn_USB_AON/USB from 0x308290100, 0x40 + * apart per ATC). Each ATC's three are those its PHY needs, and + * ATC1_USB and ATC2_USB are the USB controllers' states. The + * T8152 USB3 and CIO bring-ups run them without automatic power + * management. + * + * The ADT also gives usb-drd1/2 service-gates 175/176, but those + * PSD service blocks (0x303a1af00, 0x303a1b000) take a bus error + * from the CPU. The loader leaves ATC1/2_USB on; with USB_AON + * they hold the controllers' reset and the USB2 PHY setup it + * did, which Linux cannot redo yet, so they stay on. + */ + pmgr_atc: power-management@308290000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", + "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x08290000 0x0 0x1000>; + + ps_atc0_common_dp_0: power-controller@0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc0_common_dp_1: power-controller@20 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x20 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_1"; + apple,no-auto-pm; + }; + + ps_atc1_common_dp_0: power-controller@40 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc1_common_dp_1: power-controller@60 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_1"; + apple,no-auto-pm; + }; + + ps_atc2_common_dp_0: power-controller@80 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x80 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc2_common_dp_1: power-controller@a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xa0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_1"; + apple,no-auto-pm; + }; + + ps_atc3_common_dp_0: power-controller@c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xc0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_0"; + apple,no-auto-pm; + }; + + ps_atc3_common_dp_1: power-controller@e0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0xe0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_1"; + apple,no-auto-pm; + }; + + /* + * The USB_AON states are kept on: each holds its USB + * controller's reset and PIPE handler state, and the + * rear ports' controllers stay with the loader. + */ + ps_atc0_usb_aon: power-controller@100 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc1_usb_aon: power-controller@140 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc1_usb: power-controller@160 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x160 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb"; + power-domains = <&ps_atc1_usb_aon>; + apple,no-auto-pm; + apple,always-on; + }; + + /* + * Kept on: it holds the USB controller's reset and the + * PIPE handler state the loader set up. Switched off, the + * controller stays in reset until the next boot. + */ + ps_atc2_usb_aon: power-controller@180 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc2_usb: power-controller@1a0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb"; + power-domains = <&ps_atc2_usb_aon>; + apple,no-auto-pm; + apple,always-on; + }; + + ps_atc3_usb_aon: power-controller@1c0 { + compatible = "apple,t8152-pmgr-pwrstate", + "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb_aon"; + apple,no-auto-pm; + apple,always-on; + }; + }; + + /* + * The rear ports' ATCs' common domains: PSD services 55, 56 and 58 + * (ADT atc-phy0/1/3 clock-gates). + */ + ps_atc0_common: power-controller@303a13700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13700 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc0_common"; + }; + + ps_atc1_common: power-controller@303a13800 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13800 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc1_common"; + }; + + ps_atc3_common: power-controller@303a13a00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13a00 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc3_common"; + }; + + /* ATC2's common domain: PSD service 57 (ADT atc-phy2 clock-gates). */ + ps_atc2_common: power-controller@303a13900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13900 0x0 0x100>; + #power-domain-cells = <0>; + label = "atc2_common"; + }; + + /* + * ADT atc-phy2 as usb-drd2's USB3 PHY: the hub is wired to its + * lanes directly. The power domains are listed in the order the + * PHY needs them powered up. The tunables are the atc-phy2 + * tunable_* groups of the 26A434 ADT that apply to USB3 on lane + * 0, in the order they are applied: common-a before lane 0 is + * powered up and the crossbar set, then common-b and lane0-usb. + * Some of them differ between the four ATCs of the same machine, + * so they likely carry per-device calibration. There is no + * atcphy2 alias: the loader's ATC tunable copy would then replace + * these with values for another PHY layout. + */ + atc2_phy: phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x3 0x83000000 0x0 0x84000>, + <0x3 0x82414000 0x0 0x4000>; + reg-names = "core", "pipehandler"; + #phy-cells = <1>; + apple,fixed-usb3; + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_common>, + <&ps_atc2_common_dp_0>, <&ps_atc2_common_dp_1>; + apple,tunable-common-a = + /* ACIOPHY_CMN_DFLT */ + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc27>, + <0x00864 0x02c00000 0x00800000>, + /* CIOPLL_CORE_DFLT */ + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + /* ATC_FABRIC */ + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + /* DPPLL_CORE_DFLT */ + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + /* DPPLL_TOP_DFLT */ + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + /* CIOPLL_TOP_DFLT */ + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + /* ACIOPHY_USBC0_DFLT */ + <0x15c04 0x0f000000 0x00000000>, + <0x15c0c 0x0007c000 0x00020000>, + /* ACIOPHY_USBC0_USB */ + <0x15c50 0x60000000 0x00000000>; + apple,tunable-lane0-usb = + /* LN0_ARBITER_REGS_DFLT */ + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + /* LN0_RX_TOP_REGS_DFLT */ + <0x08cf4 0x00000020 0x00000020>, + /* LN0_RX_DFE_REGS_DFLT */ + <0x077c4 0x0003ff00 0x0000fa00>, + /* LN0_SMGR_REGS_DFLT */ + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + /* LN0_RXAEQ_TOP_REGS_DFLT */ + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + /* LN0_RX_SHM_REGS_DFLT */ + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + /* LN0_TXSEQ_REGS_DFLT */ + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + /* LN0_TX_SHM_AHB_DFLT */ + <0x04fd4 0x03800000 0x02800000>, + /* LN0_TX_TXSPL_CM_DFLT */ + <0x04e20 0x00fff000 0x00723000>, + /* LN0_ASDC_TXSPL_CM_DFLT */ + <0x08980 0x00fff000 0x00723000>, + /* LN0_DIV40_REGS_DFLT */ + <0x085e4 0x00000004 0x00000000>, + /* LN0_RX_PCTRL_REGS_DFLT */ + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + /* LN0_CTLE_EQ_REGS_DFLT */ + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + /* L0_RXCALACC_HALFUI_DFLT */ + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + /* L0_RXCALACC_EDSKEW_DFLT */ + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + /* LN0_TXSPL_TXDCC_DFLT */ + <0x04d84 0x001c0000 0x00000000>, + /* LN0_SMGR_REGS_USB */ + <0x07d88 0x000000f0 0x00000030>, + <0x07da8 0xff000000 0x44000000>, + <0x07dd8 0x00003000 0x00003000>, + /* LN0_DETECTOR_REGS_USB */ + <0x0848c 0x00008000 0x00000000>, + /* LN0_DIV40_REGS_USB */ + <0x08594 0x00000001 0x00000001>, + <0x085b0 0x0000ffff 0x00001010>, + <0x085b8 0x0000ffff 0x00001010>, + <0x085cc 0x68100000 0x00000000>, + <0x085d0 0x68100000 0x00000000>, + /* LN0_CTLE_EQ_REGS_USB */ + <0x07fdc 0x000001ff 0x000000b4>, + <0x07fe0 0x000001ff 0x000000aa>, + /* LN0_RXAEQ_TOP_REGS_USB */ + <0x07a1c 0x00000ff8 0x00000578>, + <0x07a2c 0x0003ffff 0x000154b4>, + <0x07bb8 0x00007000 0x00000000>, + /* LN0_TXSEQ_REGS_USB */ + <0x04ca0 0x00000002 0x00000000>; + }; + + /* + * USB-C Back-middle: ADT atc-phy0 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy0 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc0_phy: phy@403000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x03000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_common>, + <&ps_atc0_common_dp_0>, <&ps_atc0_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bca4>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc0_phy_typec: endpoint { + remote-endpoint = <&typec0_ss>; + }; + }; + }; + }; + + /* + * USB-C Back-left: ADT atc-phy1 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy1 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc1_phy: phy@40b000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x0b000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_common>, + <&ps_atc1_common_dp_0>, <&ps_atc1_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc1_phy_typec: endpoint { + remote-endpoint = <&typec1_ss>; + }; + }; + }; + }; + + /* + * USB-C Back-right: ADT atc-phy3 in CIO mode, see atc2_phy for the + * layout. The tunables are the atc-phy3 groups the CIO mode + * applies, in that order: the common and PLL defaults as + * common-a, the fabric, PLL and the other common groups as + * common-b, and each lane's groups. + */ + atc3_phy: phy@413000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x4 0x13000000 0x0 0x84000>; + reg-names = "core"; + #phy-cells = <1>; + orientation-switch; + mode-switch; + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_common>, + <&ps_atc3_common_dp_0>, <&ps_atc3_common_dp_1>; + apple,tunable-common-a = + <0x00800 0x00fc0000 0x00fc0000>, + <0x0084c 0x000ff800 0x000ff800>, + <0x0085c 0x000000ff 0x00000080>, + <0x00860 0x007fffff 0x0052bc26>, + <0x00864 0x02c00000 0x00800000>, + <0x01614 0x0003ffc0 0x0001e5c0>, + <0x01640 0x00000007 0x00000003>, + <0x01668 0x00000ffc 0x000005f0>; + apple,tunable-common-b = + <0x6c004 0x003f003f 0x00200020>, + <0x6c00c 0x000000f1 0x000000a1>, + <0x6c010 0x0000801f 0x00000004>, + <0x6c018 0x003f003f 0x00200020>, + <0x6c020 0x000000f1 0x000000a1>, + <0x6c024 0x0000801f 0x00000004>, + <0x6c02c 0x007f007f 0x00410041>, + <0x6c034 0x000000f1 0x00000071>, + <0x6c038 0x0000801f 0x00000004>, + <0x6c040 0x0000001f 0x00000010>, + <0x6c048 0x0000801f 0x00000004>, + <0x6c050 0x007f007f 0x00450045>, + <0x6c058 0x000000f1 0x00000051>, + <0x6c05c 0x0000801f 0x00000004>, + <0x6c064 0x0000003f 0x00000020>, + <0x6c06c 0x0000801f 0x00000004>, + <0x6c074 0x00000001 0x00000001>, + <0x6c078 0x0000801f 0x00000004>, + <0x6c080 0x001f001f 0x00100010>, + <0x6c084 0x000000f1 0x00000011>, + <0x6c088 0x00000001 0x00000001>, + <0x6c08c 0x00000001 0x00000001>, + <0x6c090 0x0000801f 0x00000004>, + <0x6c098 0x001f001f 0x00100010>, + <0x6c09c 0x000000f1 0x00000011>, + <0x6c0a0 0x0000801f 0x00000004>, + <0x6c0a8 0x000000ff 0x000000a0>, + <0x6c0ac 0x0000801f 0x00000004>, + <0x6c0b4 0x0000003f 0x00000020>, + <0x6c0bc 0x0000801f 0x00000004>, + <0x6c0c4 0x0000003f 0x00000020>, + <0x6c0cc 0x0000801f 0x00000004>, + <0x6c0d4 0x0000000f 0x00000008>, + <0x6c0d8 0x0000801f 0x00000004>, + <0x6c0e0 0x001f001f 0x00180018>, + <0x6c0e4 0x0000801f 0x00000004>, + <0x6c0ec 0x001f001f 0x00180018>, + <0x6c0f0 0x0000801f 0x00000004>, + <0x6c0f8 0x001f001f 0x00180018>, + <0x6c0fc 0x0000801f 0x00000004>, + <0x6c104 0x001f001f 0x00180018>, + <0x6c108 0x0000801f 0x00000004>, + <0x6c110 0x00000001 0x00000001>, + <0x6c114 0x0000801f 0x00000004>, + <0x6c11c 0x0000801f 0x00000004>, + <0x6c124 0x0000801f 0x00000004>, + <0x6c12c 0x0000801f 0x00000004>, + <0x6c134 0x0000801f 0x00000004>, + <0x6c13c 0xffffffff 0x01010101>, + <0x6c140 0x0000801f 0x00000004>, + <0x6c148 0x0000801f 0x00000004>, + <0x6c150 0xffffffff 0x01010101>, + <0x6c154 0x0000ffff 0x00000101>, + <0x6c158 0x0000801f 0x00000004>, + <0x6c160 0x0000801f 0x00000004>, + <0x6c168 0x0000801f 0x00000004>, + <0x6c170 0x0000801f 0x00000004>, + <0x6c178 0x0000801f 0x00000004>, + <0x6c180 0xffffffff 0x01010101>, + <0x6c184 0x0000801f 0x00000004>, + <0x6c18c 0x0000801f 0x00000004>, + <0x6c194 0x0000801f 0x00000004>, + <0x01040 0x0000000c 0x00000008>, + <0x01060 0x0001c000 0x0000c000>, + <0x01098 0x00000f00 0x00000800>, + <0x0109c 0x000fe000 0x000fe000>, + <0x01108 0x07c00000 0x04000000>, + <0x0110c 0x0000007c 0x00000010>, + <0x00e8c 0x0000007f 0x0000003c>, + <0x00e9c 0x0000007f 0x00000032>, + <0x00eac 0x0000007f 0x00000032>, + <0x00ebc 0x0000007f 0x0000005a>, + <0x01488 0x000001ff 0x00000128>, + <0x01494 0x00000100 0x00000100>, + <0x01a44 0x0000040f 0x0000040f>, + <0x01a48 0x0000040f 0x0000040f>; + apple,tunable-lane0-cio = + <0x082d8 0xf0000000 0x70000000>, + <0x082dc 0x0000000f 0x00000007>, + <0x08cf4 0x00000020 0x00000020>, + <0x077c4 0x0003ff00 0x0000fa00>, + <0x07dbc 0x00000078 0x00000030>, + <0x07dd8 0x000003f0 0x00000000>, + <0x07de8 0x00000003 0x00000003>, + <0x07dec 0x00000002 0x00000002>, + <0x07a00 0x000000f0 0x00000010>, + <0x07a08 0x00000fff 0x00000001>, + <0x07a28 0x0ff00000 0x0cf00000>, + <0x07a40 0x07ffffff 0x028154a5>, + <0x07a7c 0x20000000 0x00000000>, + <0x07a80 0x0000001f 0x00000002>, + <0x07b98 0x3f00003f 0x31000014>, + <0x07b9c 0x0003ffff 0x0000ef4b>, + <0x07ba8 0x0fc1f800 0x05005000>, + <0x07bac 0x07ffffe0 0x013f0e40>, + <0x07bbc 0x000001c7 0x00000145>, + <0x07bc8 0x000007f8 0x00000018>, + <0x08728 0x0000010f 0x0000010f>, + <0x0878c 0xfc000000 0xfc000000>, + <0x08790 0x00000001 0x00000001>, + <0x087b4 0x0e018000 0x06008000>, + <0x08708 0x40000000 0x40000000>, + <0x04c80 0x3f800000 0x00000000>, + <0x04c88 0x001fffff 0x00000000>, + <0x04fd4 0x03800000 0x02800000>, + <0x04e20 0x00fff000 0x00723000>, + <0x08980 0x00fff000 0x00723000>, + <0x085e4 0x00000004 0x00000000>, + <0x08628 0x00000ff0 0x00000660>, + <0x0862c 0x00000ff0 0x00000ea0>, + <0x08000 0x0000000a 0x00000000>, + <0x08014 0x000003ff 0x00000042>, + <0x07304 0x0000000f 0x00000006>, + <0x07334 0x01ffffff 0x001004ea>, + <0x07284 0x0000000f 0x00000006>, + <0x072cc 0x0003ffff 0x000004ea>, + <0x04d84 0x001c0000 0x00000000>, + <0x07f80 0xffffffff 0x00000148>, + <0x07f90 0x0003ff00 0x0002f700>, + <0x07fd0 0x00000100 0x00000000>, + <0x07d88 0x000000ff 0x00000041>, + <0x07da8 0xffff0000 0x22110000>, + <0x07dac 0x000000ff 0x00000044>, + <0x07dd8 0x0000c000 0x00000000>, + <0x07ddc 0x00000003 0x00000000>, + <0x07a1c 0x00000ff8 0x00000528>, + <0x07a2c 0x0003ffff 0x000140aa>, + <0x07a30 0x00001e00 0x00001000>, + <0x07a34 0x00ff0000 0x000a0000>, + <0x07b84 0x000000ff 0x00000028>, + <0x07b88 0x0000f00f 0x00007008>, + <0x07b8c 0x0000f00f 0x00006007>, + <0x07b90 0x0000f00f 0x00004005>, + <0x07bb4 0x0000703f 0x0000502d>, + <0x07bb8 0x0000703f 0x00002013>, + <0x07bbc 0x00000e00 0x00000600>, + <0x08af4 0x01fe0000 0x01540000>, + <0x08af8 0x003fc000 0x002a8000>, + <0x04e94 0x01fe0000 0x01540000>, + <0x04e98 0x003fc000 0x002a8000>; + apple,tunable-lane1-cio = + <0x112d8 0xf0000000 0x70000000>, + <0x112dc 0x0000000f 0x00000007>, + <0x11cf4 0x00000020 0x00000020>, + <0x107c4 0x0003ff00 0x0000fa00>, + <0x10dbc 0x00000078 0x00000030>, + <0x10dd8 0x000003f0 0x00000000>, + <0x10de8 0x00000003 0x00000003>, + <0x10dec 0x00000002 0x00000002>, + <0x10a00 0x000000f0 0x00000010>, + <0x10a08 0x00000fff 0x00000001>, + <0x10a28 0x0ff00000 0x0cf00000>, + <0x10a40 0x07ffffff 0x028154a5>, + <0x10a7c 0x20000000 0x00000000>, + <0x10a80 0x0000001f 0x00000002>, + <0x10b98 0x3f00003f 0x31000014>, + <0x10b9c 0x0003ffff 0x0000ef4b>, + <0x10ba8 0x0fc1f800 0x05005000>, + <0x10bac 0x07ffffe0 0x013f0e40>, + <0x10bbc 0x000001c7 0x00000145>, + <0x10bc8 0x000007f8 0x00000018>, + <0x11728 0x0000010f 0x0000010f>, + <0x1178c 0xfc000000 0xfc000000>, + <0x11790 0x00000001 0x00000001>, + <0x117b4 0x0e018000 0x06008000>, + <0x11708 0x40000000 0x40000000>, + <0x0dc80 0x3f800000 0x00000000>, + <0x0dc88 0x001fffff 0x00000000>, + <0x0dfd4 0x03800000 0x02800000>, + <0x0de20 0x00fff000 0x00723000>, + <0x11980 0x00fff000 0x00723000>, + <0x115e4 0x00000004 0x00000000>, + <0x11628 0x00000ff0 0x00000660>, + <0x1162c 0x00000ff0 0x00000ea0>, + <0x11000 0x0000000a 0x00000000>, + <0x11014 0x000003ff 0x00000042>, + <0x10304 0x0000000f 0x00000006>, + <0x10334 0x01ffffff 0x001004ea>, + <0x10284 0x0000000f 0x00000006>, + <0x102cc 0x0003ffff 0x000004ea>, + <0x0dd84 0x001c0000 0x00000000>, + <0x10f80 0xffffffff 0x00000148>, + <0x10f90 0x0003ff00 0x0002f700>, + <0x10fd0 0x00000100 0x00000000>, + <0x10d88 0x000000ff 0x00000041>, + <0x10da8 0xffff0000 0x22110000>, + <0x10dac 0x000000ff 0x00000044>, + <0x10dd8 0x0000c000 0x00000000>, + <0x10ddc 0x00000003 0x00000000>, + <0x10a1c 0x00000ff8 0x00000528>, + <0x10a2c 0x0003ffff 0x000140aa>, + <0x10a30 0x00001e00 0x00001000>, + <0x10a34 0x00ff0000 0x000a0000>, + <0x10b84 0x000000ff 0x00000028>, + <0x10b88 0x0000f00f 0x00007008>, + <0x10b8c 0x0000f00f 0x00006007>, + <0x10b90 0x0000f00f 0x00004005>, + <0x10bb4 0x0000703f 0x0000502d>, + <0x10bb8 0x0000703f 0x00002013>, + <0x10bbc 0x00000e00 0x00000600>, + <0x11af4 0x01fe0000 0x01540000>, + <0x11af8 0x003fc000 0x002a8000>, + <0x0de94 0x01fe0000 0x01540000>, + <0x0de98 0x003fc000 0x002a8000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + atc3_phy_typec: endpoint { + remote-endpoint = <&typec3_ss>; + }; + }; + }; + }; + + /* usb-drd2: on-board VL822 hub behind the two front USB-C ports. */ + usb2: usb@382430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x3 0x82430000 0x0 0xcd00>; + interrupts = ; + dr_mode = "host"; + phys = <&atc2_phy PHY_TYPE_USB3>; + phy-names = "usb3-phy"; + iommus = <&dwc3_2_dart 0>, <&dwc3_2_dart_1 1>; + power-domains = <&ps_atc2_usb>; + snps,dis_u2_susphy_quirk; + snps,dis_u3_susphy_quirk; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi new file mode 100644 index 0000000000000..41083f7ebccaa --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb4.dtsi @@ -0,0 +1,1317 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * J873g rear USB-C ports in USB4 mode: three ACIO host routers with their + * NHI, PCIe-C tunnel and DARTs, and the T8152 PSD services they need. Each + * router's Thunderbolt switch is linked to the USB4 port (port@4) of its + * port's usb-c-connector, whose PD controller driver starts and stops it + * after it set the port's ATC PHY to CIO mode. + * + * Generated from the J873g ADT (27.2 iBoot): /arm-io/acio{0,1,3}, acio-cpuN, + * dart-acioN, apciecN and dart-apciecN. + * + * Each router coprocessor's mailbox is the 0x80 window at +0x80 of its + * acio-cpuN register block, with the SMC mailbox's counted FIFOs. Its + * interrupts are acio-cpuN's two, in the order the SMC mailbox's ADT list + * gives its own: send-empty, recv-not-empty. + */ + +#include + +/ { + soc { + cio_reset: reset-controller@300780000 { + compatible = "apple,t8152-cio-reset"; + reg = <0x3 0x00780000 0x0 0x4000>; + #reset-cells = <1>; + }; + + cio_psd59: power-controller@303a13b00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13b00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd60: power-controller@303a13c00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13c00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd62: power-controller@303a13e00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13e00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd63: power-controller@303a13f00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a13f00 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd64: power-controller@303a14000 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14000 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd66: power-controller@303a14200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14200 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd67: power-controller@303a14300 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14300 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd68: power-controller@303a14400 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14400 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd70: power-controller@303a14600 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a14600 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd86: power-controller@303a15600 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15600 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd87: power-controller@303a15700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15700 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio_psd89: power-controller@303a15900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x3a15900 0x0 0x100>; + #power-domain-cells = <0>; + }; + + cio0_mbox: mailbox@401178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x1178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_0: acio@401ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x1ac0000 0x0 0xc000>, + <0x4 0x1080000 0x0 0x26000>, + <0x4 0x1e44000 0x0 0x4000>, + <0x4 0x1c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x1000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio0_mbox>; + resets = <&cio_reset 0>; + power-domains = <&cio_psd59>, <&cio_psd63>, <&cio_psd67>, <&cio_psd86>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_0_lstx_pins>; + lstx-gpios = <&pinctrl_aop 19 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_0_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_0_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000100 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd59>; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_0_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_0_dart 0>, <&usb4_0_dart 1>, <&usb4_0_dart 2>, + <&usb4_0_dart 3>, <&usb4_0_dart 4>, <&usb4_0_dart 5>, + <&usb4_0_dart 6>, <&usb4_0_dart 7>, <&usb4_0_dart 8>, + <&usb4_0_dart 9>, <&usb4_0_dart 10>, <&usb4_0_dart 11>, + <&usb4_0_dart 16>, <&usb4_0_dart 17>, <&usb4_0_dart 18>, + <&usb4_0_dart 19>, <&usb4_0_dart 20>, <&usb4_0_dart 21>, + <&usb4_0_dart 22>, <&usb4_0_dart 23>, <&usb4_0_dart 24>, + <&usb4_0_dart 25>, <&usb4_0_dart 26>, <&usb4_0_dart 27>; + apple,thunderbolt-drom = + [db 00 00 00 00 00 00 00 00 5d 2d 12 e9 01 42 00 + 01 00 0f 00 01 00 08 81 80 02 80 00 00 00 08 82 + 90 01 80 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 05 88 09 01 00 0d 01 41 70 + 70 6c 65 20 49 6e 63 2e 00 06 02 69 4f 53 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_0_sw: endpoint { + remote-endpoint = <&typec0_usb4>; + }; + }; + }; + }; + + cio1_mbox: mailbox@409178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x9178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_1: acio@409ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x9ac0000 0x0 0xc000>, + <0x4 0x9080000 0x0 0x26000>, + <0x4 0x9e44000 0x0 0x4000>, + <0x4 0x9c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x9000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio1_mbox>; + resets = <&cio_reset 1>; + power-domains = <&cio_psd60>, <&cio_psd64>, <&cio_psd68>, <&cio_psd87>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_1_lstx_pins>; + lstx-gpios = <&pinctrl_aop 21 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_1_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_1_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000180 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd60>; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_1_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_1_dart 0>, <&usb4_1_dart 1>, <&usb4_1_dart 2>, + <&usb4_1_dart 3>, <&usb4_1_dart 4>, <&usb4_1_dart 5>, + <&usb4_1_dart 6>, <&usb4_1_dart 7>, <&usb4_1_dart 8>, + <&usb4_1_dart 9>, <&usb4_1_dart 10>, <&usb4_1_dart 11>, + <&usb4_1_dart 16>, <&usb4_1_dart 17>, <&usb4_1_dart 18>, + <&usb4_1_dart 19>, <&usb4_1_dart 20>, <&usb4_1_dart 21>, + <&usb4_1_dart 22>, <&usb4_1_dart 23>, <&usb4_1_dart 24>, + <&usb4_1_dart 25>, <&usb4_1_dart 26>, <&usb4_1_dart 27>; + apple,thunderbolt-drom = + [c8 01 00 00 00 00 00 00 00 06 7e 74 db 01 42 00 + 01 00 0f 00 01 00 08 81 81 02 81 00 00 00 08 82 + 91 01 81 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 05 88 09 01 00 0d 01 41 70 + 70 6c 65 20 49 6e 63 2e 00 06 02 69 4f 53 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_1_sw: endpoint { + remote-endpoint = <&typec1_usb4>; + }; + }; + }; + }; + + cio3_mbox: mailbox@411178080 { + compatible = "apple,t8152-cio-mailbox", + "apple,t8152-smc-mailbox"; + reg = <0x4 0x11178080 0x0 0x80>; + interrupts = , + ; + interrupt-names = "send-empty", "recv-not-empty"; + #mbox-cells = <0>; + }; + + /* acio@ avoids the bootloader's legacy cio@ register-index fixup. */ + usb4_3: acio@411ac0000 { + compatible = "apple,t8152-usb4-acio"; + reg = <0x4 0x11ac0000 0x0 0xc000>, + <0x4 0x11080000 0x0 0x26000>, + <0x4 0x11e44000 0x0 0x4000>, + <0x4 0x11c80000 0x0 0x4000>; + reg-names = "rc", "sram", "pcie-adapter", "router-ap-fw"; + #address-cells = <1>; + #size-cells = <1>; + /* The router window and the shared Gen3 TLB invalidation aperture. */ + ranges = <0x0 0x4 0x11000000 0x1000000>, + <0x1000000 0x2 0x0 0x1000>; + nonposted-mmio; + mboxes = <&cio3_mbox>; + resets = <&cio_reset 3>; + power-domains = <&cio_psd62>, <&cio_psd66>, <&cio_psd70>, <&cio_psd89>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_3_lstx_pins>; + lstx-gpios = <&pinctrl_aop 25 GPIO_ACTIVE_HIGH>; + thunderbolt-switch; + apple,pcie-tunnel = <&usb4_3_tunnel>; + apple,tunable-rc = + <0x0 0xfff0 0x5010>, + <0x2c 0x4 0x0>, + <0xac 0xffffffff 0x84638463>, + <0x4004 0x1ff01ff 0x1000100>, + <0x4008 0x801f 0x4>, + <0x4010 0x7f 0x40>, + <0x4014 0x801f 0x4>, + <0x401c 0x7f 0x40>, + <0x4024 0x801f 0x4>, + <0x402c 0x7f 0x40>, + <0x4030 0x801f 0x4>, + <0x4038 0xffffffff 0x1010101>, + <0x403c 0xffff 0x101>, + <0x4040 0x1 0x1>, + <0x4044 0xffffffff 0x1010101>, + <0x4048 0x1 0x1>, + <0x404c 0x801f 0x4>, + <0x8004 0x70007 0x40004>, + <0x8008 0x801f 0x4>, + <0x8010 0xf000f 0x80008>, + <0x8018 0x801f 0x4>, + <0x8020 0x70007 0x40004>, + <0x8028 0x801f 0x4>, + <0x8030 0x801f 0x4>, + <0x8038 0x801f 0x4>, + <0x8040 0x801f 0x4>, + <0x8048 0x801f 0x4>, + <0x8050 0x801f 0x4>, + <0x8058 0x801f 0x4>, + <0x8060 0x801f 0x4>; + apple,tunable-pcie-adapter = + <0x1008 0x6 0x6>; + apple,tunable-router-ap-fw = + <0x8 0xff2 0x482>; + + usb4_3_dart: iommu@a80000 { + compatible = "apple,t8152-acio-dart"; + reg = <0xa80000 0xc000>, + <0x1000280 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd62>; + apple,dma-range = <0x100 0x0 0x10 0x0>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0xf003f 0x10000>, + <0x804 0xf003f 0x10002>, + <0x808 0xf003f 0x10004>, + <0x80c 0xf003f 0x20006>, + <0x810 0xf003f 0x2000a>, + <0x814 0xf003f 0x2000e>, + <0x818 0xf003f 0x20012>, + <0x81c 0xf003f 0x20016>, + <0x820 0xf003f 0x2001a>, + <0x824 0xf003f 0x2001e>, + <0x828 0xf003f 0x20022>, + <0x82c 0xf003f 0x20026>, + <0x830 0xf003f 0x2002a>, + <0x834 0xf003f 0x2002e>, + <0x838 0xf003f 0x20032>, + <0x83c 0xf003f 0x10036>, + <0x4600 0x2 0x2>; + }; + + usb4_3_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi"; + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + , + ; + interrupt-names = "txring0", "txring1", "txring2", + "txring3", "txring4", "txring5", + "txring6", "txring7", "txring8", + "txring9", "txring10", "txring11", + "rxring0", "rxring1", "rxring2", + "rxring3", "rxring4", "rxring5", + "rxring6", "rxring7", "rxring8", + "rxring9", "rxring10", "rxring11"; + iommus = <&usb4_3_dart 0>, <&usb4_3_dart 1>, <&usb4_3_dart 2>, + <&usb4_3_dart 3>, <&usb4_3_dart 4>, <&usb4_3_dart 5>, + <&usb4_3_dart 6>, <&usb4_3_dart 7>, <&usb4_3_dart 8>, + <&usb4_3_dart 9>, <&usb4_3_dart 10>, <&usb4_3_dart 11>, + <&usb4_3_dart 16>, <&usb4_3_dart 17>, <&usb4_3_dart 18>, + <&usb4_3_dart 19>, <&usb4_3_dart 20>, <&usb4_3_dart 21>, + <&usb4_3_dart 22>, <&usb4_3_dart 23>, <&usb4_3_dart 24>, + <&usb4_3_dart 25>, <&usb4_3_dart 26>, <&usb4_3_dart 27>; + apple,thunderbolt-drom = + [ee 03 00 00 00 00 00 00 00 4e bc d0 4b 01 3d 00 + 01 00 0f 00 01 00 08 81 83 02 83 00 00 00 08 82 + 93 01 83 00 00 00 03 83 20 02 84 05 85 09 01 00 + 05 86 09 01 00 02 87 0d 01 41 70 70 6c 65 20 49 + 6e 63 2e 00 06 02 69 4f 53 00 00 00]; + apple,tunable-nhi = + <0xf8004 0xff 0x80>, + <0xf8008 0x801f 0x4>, + <0xf8010 0x3f 0x20>, + <0xf8014 0x801f 0x4>, + <0xf801c 0x1f 0x10>, + <0xf8020 0x801f 0x4>, + <0xf8028 0xff 0x80>, + <0xf802c 0x801f 0x4>, + <0xf8034 0xff 0x80>, + <0xf8038 0x801f 0x4>, + <0xf8040 0x3f 0x20>, + <0xf8044 0x801f 0x4>, + <0xf804c 0x8007 0x1>, + <0xfc004 0x7 0x4>, + <0xfc008 0x801f 0x4>, + <0xfc010 0x7 0x4>, + <0xfc014 0x801f 0x4>, + <0xfc01c 0x7 0x4>, + <0xfc020 0x801f 0x4>, + <0xfc028 0x7 0x4>, + <0xfc02c 0x801f 0x4>, + <0xfc034 0x7 0x4>, + <0xfc038 0x801f 0x4>, + <0xfc040 0x7 0x4>, + <0xfc044 0x801f 0x4>, + <0xfc04c 0x8007 0x1>, + <0x4000 0x1000000f 0x10000002>, + <0x4004 0x1000000f 0x10000002>, + <0x4008 0x1000000f 0x10000002>, + <0x400c 0x1000000f 0x10000002>, + <0x4010 0x1000000f 0x10000002>, + <0x4014 0x1000000f 0x10000002>, + <0x4018 0x1000000f 0x10000002>, + <0x401c 0x1000000f 0x10000002>, + <0x4020 0x1000000f 0x10000002>, + <0x4024 0x1000000f 0x10000002>, + <0x4028 0x1000000f 0x10000002>, + <0x402c 0x1000000f 0x10000002>, + <0x4040 0x1000000f 0x10000002>, + <0x4044 0x1000000f 0x10000002>, + <0x4048 0x1000000f 0x10000002>, + <0x404c 0x1000000f 0x10000002>, + <0x4050 0x1000000f 0x10000002>, + <0x4054 0x1000000f 0x10000002>, + <0x4058 0x1000000f 0x10000002>, + <0x405c 0x1000000f 0x10000002>, + <0x4060 0x1000000f 0x10000002>, + <0x4064 0x1000000f 0x10000002>, + <0x4068 0x1000000f 0x10000002>, + <0x406c 0x1000000f 0x10000002>, + <0x4080 0x1000000f 0x10000002>, + <0x4084 0x1000000f 0x10000002>, + <0x4088 0x1000000f 0x10000002>, + <0x408c 0x1000000f 0x10000002>, + <0x4090 0x1000000f 0x10000002>, + <0x4094 0x1000000f 0x10000002>, + <0x4098 0x1000000f 0x10000002>, + <0x409c 0x1000000f 0x10000002>, + <0x40a0 0x1000000f 0x10000002>, + <0x40a4 0x1000000f 0x10000002>, + <0x40a8 0x1000000f 0x10000002>, + <0x40ac 0x1000000f 0x10000002>, + <0x40c0 0x1000000f 0x10000002>, + <0x40c4 0x1000000f 0x10000002>, + <0x40c8 0x1000000f 0x10000002>, + <0x40cc 0x1000000f 0x10000002>, + <0x40d0 0x1000000f 0x10000002>, + <0x40d4 0x1000000f 0x10000002>, + <0x40d8 0x1000000f 0x10000002>, + <0x40dc 0x1000000f 0x10000002>, + <0x40e0 0x1000000f 0x10000002>, + <0x40e4 0x1000000f 0x10000002>, + <0x40e8 0x1000000f 0x10000002>, + <0x40ec 0x1000000f 0x10000002>, + <0x4100 0x1000000f 0x10000002>, + <0x4104 0x1000000f 0x10000002>, + <0x4108 0x1000000f 0x10000002>, + <0x410c 0x1000000f 0x10000002>, + <0x4110 0x1000000f 0x10000002>, + <0x4114 0x1000000f 0x10000002>, + <0x4118 0x1000000f 0x10000002>, + <0x411c 0x1000000f 0x10000002>, + <0x4120 0x1000000f 0x10000002>, + <0x4124 0x1000000f 0x10000002>, + <0x4128 0x1000000f 0x10000002>, + <0x412c 0x1000000f 0x10000002>, + <0x4140 0x1000000f 0x10000002>, + <0x4144 0x1000000f 0x10000002>, + <0x4148 0x1000000f 0x10000002>, + <0x414c 0x1000000f 0x10000002>, + <0x4150 0x1000000f 0x10000002>, + <0x4154 0x1000000f 0x10000002>, + <0x4158 0x1000000f 0x10000002>, + <0x415c 0x1000000f 0x10000002>, + <0x4160 0x1000000f 0x10000002>, + <0x4164 0x1000000f 0x10000002>, + <0x4168 0x1000000f 0x10000002>, + <0x416c 0x1000000f 0x10000002>, + <0x43e4 0x7 0x7>; + }; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_3_sw: endpoint { + remote-endpoint = <&typec3_usb4>; + }; + }; + }; + }; + }; + + usb4_0_tunnel: usb4-pcie-tunnel-0 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_0_pcie_dart: iommu@404000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0x4000000 0x0 0xc000>, + <0x2 0x100 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd86>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_0_pcie: pcie@1c50000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x50000000 0x0 0x10000000>, + <0x4 0x4034000 0x0 0x4000>, + <0x4 0x4020000 0x0 0x8000>, + <0x4 0x4038000 0x0 0x4000>, + <0x4 0x4060000 0x0 0x4000>, + <0x4 0x402c000 0x0 0x4000>, + <0x4 0x4028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd86>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_0_pcie>; + msi-ranges = <&aic AIC_IRQ 1975 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <96>; + iommu-map = <0 &usb4_0_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <1>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x8 0x0 0x8 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0xa 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0xa 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_0_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_0_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_0_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_0_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_0_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; + + usb4_1_tunnel: usb4-pcie-tunnel-1 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_1_pcie_dart: iommu@40c000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0xc000000 0x0 0xc000>, + <0x2 0x180 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd87>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_1_pcie: pcie@1c60000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x60000000 0x0 0x10000000>, + <0x4 0xc034000 0x0 0x4000>, + <0x4 0xc020000 0x0 0x8000>, + <0x4 0xc038000 0x0 0x4000>, + <0x4 0xc060000 0x0 0x4000>, + <0x4 0xc02c000 0x0 0x4000>, + <0x4 0xc028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd87>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_1_pcie>; + msi-ranges = <&aic AIC_IRQ 2007 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <128>; + iommu-map = <0 &usb4_1_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <2>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0xc 0x0 0xc 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0xe 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0xe 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_1_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_1_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_1_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_1_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_1_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; + + usb4_3_tunnel: usb4-pcie-tunnel-3 { + #address-cells = <2>; + #size-cells = <2>; + ranges; + nonposted-mmio; + + usb4_3_pcie_dart: iommu@414000000 { + compatible = "apple,t8152-pciec-dart"; + reg = <0x4 0x14000000 0x0 0xc000>, + <0x2 0x280 0x0 0x10>; + reg-names = "dart", "tlbi"; + #iommu-cells = <1>; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd89>; + apple,dma-range = <0x100 0x80000000 0x0 0x7ff00000>; + apple,tunable = + <0x20c 0x80000121 0x80000121>, + <0x220 0xf0f 0xf0f>, + <0x224 0xffff 0x909>, + <0x300 0x1f31 0x1>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x2 0x2>; + }; + + usb4_3_pcie: pcie@1c80000000 { + compatible = "apple,t8152-pciec"; + device_type = "pci"; + reg = <0x1c 0x80000000 0x0 0x10000000>, + <0x4 0x14034000 0x0 0x4000>, + <0x4 0x14020000 0x0 0x8000>, + <0x4 0x14038000 0x0 0x4000>, + <0x4 0x14060000 0x0 0x4000>, + <0x4 0x1402c000 0x0 0x4000>, + <0x4 0x14028000 0x0 0x4000>; + reg-names = "config", "rc", "port0", "fabric", "debug", "ltssm", "intr2axi"; + interrupt-parent = <&aic>; + interrupts = ; + power-domains = <&cio_psd89>; + apple,pciec-kernel-init; + msi-controller; + msi-parent = <&usb4_3_pcie>; + msi-ranges = <&aic AIC_IRQ 2071 IRQ_TYPE_EDGE_RISING 32>; + apple,msi-vector-base = <192>; + iommu-map = <0 &usb4_3_pcie_dart 0 0x40>; + iommu-map-mask = <0x3f>; + linux,pci-domain = <4>; + bus-range = <0 0x7f>; + #address-cells = <3>; + #size-cells = <2>; + ranges = <0x43000000 0x14 0x0 0x14 0x0 0x2 0x0>, + <0x2000000 0x0 0x100000 0x16 0x100000 0x0 0x3ff00000>, + <0x42000000 0x0 0x40000000 0x16 0x40000000 0x0 0x40000000>; + apple,tunable-debug = + <0x1000 0x1 0x0>; + apple,tunable-fabric = + <0x4 0x3f003f 0x200020>, + <0x8 0x1 0x1>, + <0xc 0x1 0x1>, + <0x10 0x801f 0x4>, + <0x18 0x1ff 0x100>, + <0x1c 0x1 0x1>, + <0x20 0x801f 0x4>, + <0x28 0x1f 0x10>, + <0x2c 0x801f 0x4>, + <0x34 0x3f 0x20>, + <0x38 0x801f 0x4>, + <0x40 0x3f 0x20>, + <0x44 0x801f 0x4>, + <0x4c 0x10001 0x10001>, + <0x50 0x1 0x1>, + <0x54 0x1 0x1>, + <0x58 0x801f 0x4>, + <0x60 0x7f007f 0x450045>, + <0x64 0x801f 0x4>, + <0x6c 0x1f001f 0x100010>, + <0x70 0x801f 0x4>, + <0x78 0x801f 0x4>, + <0x80 0x1 0x1>, + <0x84 0x1 0x1>, + <0x88 0x801f 0x4>, + <0x90 0x1 0x1>, + <0x94 0x801f 0x4>, + <0x9c 0x1 0x1>, + <0xa0 0x801f 0x4>, + <0xa8 0x1 0x1>, + <0xac 0x1 0x1>, + <0xb0 0x801f 0x4>, + <0xb8 0x801f 0x4>, + <0xc0 0x801f 0x4>; + apple,tunable-rc = + <0x78 0x7000 0x0>, + <0x718 0x7c000 0x0>, + <0x814 0xffffffff 0x2000f060>, + <0x8bc 0x1 0x0>; + + usb4_3_pcie_port: pci@0,0 { + device_type = "pci"; + reg = <0x0 0x0 0x0 0x0 0x0>; + external-facing; + #address-cells = <3>; + #size-cells = <2>; + ranges; + interrupt-controller; + #interrupt-cells = <1>; + interrupt-map-mask = <0 0 0 7>; + interrupt-map = <0 0 0 1 &usb4_3_pcie_port 0 0 0 0>, + <0 0 0 2 &usb4_3_pcie_port 0 0 0 1>, + <0 0 0 3 &usb4_3_pcie_port 0 0 0 2>, + <0 0 0 4 &usb4_3_pcie_port 0 0 0 3>; + apple,tunable = + <0x140 0x1 0x1>, + <0x2a0 0x7e 0xa>; + }; + }; + }; +}; + +&pinctrl_aop { + usb4_0_lstx_pins: usb4-0-lstx-pins { + pinmux = <0x10013>; + }; + + usb4_1_lstx_pins: usb4-1-lstx-pins { + pinmux = <0x10015>; + }; + + usb4_3_lstx_pins: usb4-3-lstx-pins { + pinmux = <0x10019>; + }; +}; + +/* USB-C Back-middle: its router */ +&typec0 { + ports { + port@4 { + reg = <4>; + + typec0_usb4: endpoint { + remote-endpoint = <&usb4_0_sw>; + }; + }; + }; +}; + +/* USB-C Back-left: its router */ +&typec1 { + ports { + port@4 { + reg = <4>; + + typec1_usb4: endpoint { + remote-endpoint = <&usb4_1_sw>; + }; + }; + }; +}; + +/* USB-C Back-right: its router */ +&typec3 { + ports { + port@4 { + reg = <4>; + + typec3_usb4: endpoint { + remote-endpoint = <&usb4_3_sw>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 00fe5207a1956..bc08534567499 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -10,6 +10,7 @@ #include #include +#include / { compatible = "apple,j873g", "apple,t8152", "apple,arm-platform"; @@ -205,6 +206,15 @@ opp-level = <3>; }; }; + + /* The 24 MHz timebase (ADT timebase-frequency), as on T8103. */ + clkref: clock-ref { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <24000000>; + clock-output-names = "clkref"; + }; + timer { compatible = "arm,armv8-timer"; interrupts = , @@ -241,6 +251,62 @@ #performance-domain-cells = <0>; }; + /* + * ADT /arm-io/nub-spmi0 (gen 4) and its primary PMU, pmu-main + * ("woodcote", slave 0xe). The boot flags live in the legacy + * scratchpad (info-leg_scrpad = 0xf800), laid out as on T8103 + * and T8140; boot_stage read 0x30 (kernel started) here. + */ + nub_spmi0: spmi@308714000 { + /* + * Gen 4: FIFO registers at 0x200 (the block is 0x4000 + * long); polled, so no interrupts are described yet. + */ + compatible = "apple,t8152-spmi", "apple,t8142-spmi"; + reg = <0x3 0x08714000 0x0 0x4000>; + #address-cells = <2>; + #size-cells = <0>; + + pmic@e { + compatible = "apple,woodcote-pmic", "apple,spmi-nvmem"; + reg = <0xe SPMI_USID>; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + boot_stage: boot-stage@f801 { + reg = <0xf801 0x1>; + }; + + boot_error_count: boot-error-count@f802,0 { + reg = <0xf802 0x1>; + bits = <0 4>; + }; + + panic_count: panic-count@f802,4 { + reg = <0xf802 0x1>; + bits = <4 4>; + }; + + /* Set before off1, or the machine powers back on. */ + shutdown_flag: shutdown-flag@f80f,3 { + reg = <0xf80f 0x1>; + bits = <3 1>; + }; + }; + }; + }; + + /* ADT /arm-io/wdt (wdt,t8152): restart fallback and /dev/watchdog. */ + wdt: watchdog@3082b0000 { + compatible = "apple,t8152-wdt", "apple,t8103-wdt"; + reg = <3 0x082b0000 0 0x4000>; + clocks = <&clkref>; + interrupts = ; + }; + smc_mbox: mailbox@30c710080 { compatible = "apple,t8152-smc-mailbox"; reg = <3 0x0c710080 0 0x80>; @@ -257,6 +323,15 @@ reg-names = "smc", "sram"; mboxes = <&smc_mbox>; + /* Power off (MBSE = off1) and restart (MBSE = phra). */ + smc_reboot: reboot { + compatible = "apple,smc-reboot"; + nvmem-cells = <&shutdown_flag>, <&boot_stage>, + <&boot_error_count>, <&panic_count>; + nvmem-cell-names = "shutdown_flag", "boot_stage", + "boot_error_count", "panic_count"; + }; + hwmon { compatible = "apple,smc-hwmon"; apple,discover-temperatures; @@ -265,6 +340,8 @@ apple,key-id = "F0Ac"; apple,fan-minimum = "F0Mn"; apple,fan-maximum = "F0Mx"; + apple,fan-target = "F0Tg"; + apple,fan-mode = "F0md"; label = "Fan"; }; }; @@ -295,12 +372,6 @@ <0x4 0x3040000 0x0 0xc000>; }; -/* Retain the register view published by this board's live hardware capture. */ -&dwc3_1_dart { - reg = <0x4 0xb020000 0x0 0xc000>, - <0x4 0xb040000 0x0 0xc000>; -}; - /* Retain the register view published by this board's live hardware capture. */ &dwc3_3_dart { reg = <0x4 0x13020000 0x0 0xc000>, @@ -423,10 +494,13 @@ <0x3 0xa0000000 0x0 0x8000>; }; -/* Unexposed chassis port instances remain described and disabled. */ - -/* Retain the register view published by this board's live hardware capture. */ -&dwc3_2_dart { - reg = <0x3 0x83020000 0x0 0xc000>, - <0x3 0x83040000 0x0 0xc000>; -}; +/* + * The J873g fragments enable and refine nodes of t8152-peripherals.dtsi + * (the USB, apcie port 2 and dart-sbr DARTs), so they come after it. + */ +#include "t8152-j873-nvme.dtsi" +#include "t8152-j873-usb.dtsi" +#include "t8152-j873-ethernet.dtsi" +#include "t8152-j873-audio.dtsi" +#include "t8152-j873-dcp.dtsi" +#include "t8152-j873-usb4.dtsi" diff --git a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi index 578e7730ef5f1..cab3001ab9086 100644 --- a/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi +++ b/arch/arm64/boot/dts/apple/t8152-peripherals.dtsi @@ -123,17 +123,20 @@ }; dcp_dart: iommu@286340000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x2 0x86340000 0x0 0x20000>; + compatible = "apple,t8152-dart-gen3"; + reg = <0x2 0x86340000 0x0 0x20000>, + <0x2 0x00000400 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; }; disp0_dart: iommu@286300000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; + compatible = "apple,t8152-dart-gen3"; reg = <0x2 0x86300000 0x0 0xc000>, - <0x2 0x86314000 0x0 0x4000>; + <0x2 0x00000400 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; @@ -148,17 +151,20 @@ }; dcpext0_dart: iommu@32a340000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; - reg = <0x3 0x2a340000 0x0 0x20000>; + compatible = "apple,t8152-dart-gen3"; + reg = <0x3 0x2a340000 0x0 0x20000>, + <0x2 0x00000480 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; }; dispext0_dart: iommu@32a300000 { - compatible = "apple,t8152-dart", "apple,t8110-dart"; + compatible = "apple,t8152-dart-gen3"; reg = <0x3 0x2a300000 0x0 0xc000>, - <0x3 0x2a314000 0x0 0x4000>; + <0x2 0x00000480 0x0 0x10>; + reg-names = "dart", "tlbi"; interrupts = ; #iommu-cells = <1>; status = "disabled"; diff --git a/arch/arm64/configs/asahi.config b/arch/arm64/configs/asahi.config index 3173021d4f19d..f4e60efde4d42 100644 --- a/arch/arm64/configs/asahi.config +++ b/arch/arm64/configs/asahi.config @@ -88,6 +88,7 @@ CONFIG_DRM_ASAHI_M3_T8122=y CONFIG_DRM_ADP=m CONFIG_DRM_APPLE=m CONFIG_DRM_APPLE_DCP_T8132=y +CONFIG_DRM_APPLE_DCP_T8152=y CONFIG_DRM_APPLE_CEC=y CONFIG_DRM_APPLE_AUDIO=y CONFIG_DRM_APPLE_DCP_T6030_AUDIO=y @@ -156,6 +157,7 @@ CONFIG_SECURITY_LOCKDOWN_LSM=y CONFIG_SECURITY_LOCKDOWN_LSM_EARLY=y CONFIG_LOCK_DOWN_KERNEL_FORCE_NONE=y CONFIG_APPLE_PMGR_PWRSTATE=y +CONFIG_APPLE_PMGR_PSD=y CONFIG_APPLE_T6041_CIO_RECONFIG=y CONFIG_APPLE_PMC=y CONFIG_APPLE_CLUSTER_PWRGATE=y diff --git a/drivers/dma/apple-admac.c b/drivers/dma/apple-admac.c index e330bb9300975..cc57d9c76847e 100644 --- a/drivers/dma/apple-admac.c +++ b/drivers/dma/apple-admac.c @@ -78,13 +78,29 @@ */ #define REG_CHAN_BASE_LEGACY(ch) (0x8000 + (ch) * 0x200) #define REG_CHAN_BASE_EVOLVED(ch) (((ch) & 1 ? 0xc000 : 0x8000) + ((ch) / 2) * 0x200) -#define REG_CHAN_BASE(ad, ch) ((ad)->evolved_layout ? \ +/* + * T8152 (ADT admac-evolution,t8152; the macOS AudioDMAController-T8152 + * driver): the same per-channel block, 0x4000 apart, TX at 0x40000 and RX + * at 0x80000, and a channel has to be put in state 2 (+0x30 bits 3:0) + * before it is started. The descriptor and report FIFO ports are the legacy + * ones (the RX descriptor port answers at 0x14000 + 4n, not at the ADT's + * 0x10040 + 4n). + */ +#define REG_CHAN_BASE_T8152(ch) (((ch) & 1 ? 0x80000 : 0x40000) + ((ch) / 2) * 0x4000) +#define REG_CHAN_BASE(ad, ch) ((ad)->t8152_layout ? REG_CHAN_BASE_T8152(ch) : \ + (ad)->evolved_layout ? \ REG_CHAN_BASE_EVOLVED(ch) : REG_CHAN_BASE_LEGACY(ch)) #define REG_CHAN_CTL(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x00) #define REG_CHAN_CTL_RST_RINGS BIT(0) #define REG_CHAN_CONFIG(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x04) +/* macOS writes this for the T8152 base-ns channels before every start */ +#define CHAN_CONFIG_T8152 0x029b0000 #define REG_CHAN_BURST(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x30) +/* T8152: the low nibble of the same register is the channel state */ +#define REG_CHAN_STATE(ad, ch) REG_CHAN_BURST(ad, ch) +#define CHAN_STATE_MASK GENMASK(3, 0) +#define CHAN_STATE_READY 2 #define REG_DESC_RING(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x70) #define REG_REPORT_RING(ad, ch) (REG_CHAN_BASE(ad, ch) + 0x74) @@ -112,6 +128,11 @@ #define REG_DESC_WRITE(ch) (0x10000 + ((ch) / 2) * 0x4 + ((ch) & 1) * 0x4000) #define REG_REPORT_READ(ch) (0x10100 + ((ch) / 2) * 0x4 + ((ch) & 1) * 0x4000) +/* T8152: the AP's share of each SRAM pool starts above the firmware's. */ +#define T8152_SRAM_BASE 0x1000 +#define T8152_SRAM_BLOCK 1024 +#define SRAM_SIZE_MASK GENMASK(15, 0) + #define REG_TX_INTSTATE(idx) (0x0030 + (idx) * 4) #define REG_RX_INTSTATE(idx) (0x0040 + (idx) * 4) #define REG_GLOBAL_INTSTATE(idx) (0x0050 + (idx) * 4) @@ -163,6 +184,8 @@ struct admac_chan { struct tasklet_struct tasklet; u32 carveout; + /* T8152: transfer descriptor id, 1..255 */ + u8 desc_id; spinlock_t lock; struct admac_tx *current_tx; @@ -214,6 +237,7 @@ struct admac_data { bool evolved_layout; bool split_channels; bool display; + bool t8152_layout; bool ctl_programmed; /* Display ADMAC: its control block's two windows and their tunables */ void __iomem *control[2]; @@ -247,6 +271,7 @@ struct admac_hw { bool evolved_layout; bool split_channels; bool display; + bool t8152_layout; }; static int admac_alloc_sram_carveout(struct admac_data *ad, @@ -255,6 +280,8 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, { struct admac_sram *sram; int i, ret = 0, nblocks; + u32 first = 0, block = SRAM_BLOCK; + ad->txcache.size = readl_relaxed(ad->base + REG_TX_SRAM_SIZE); ad->rxcache.size = readl_relaxed(ad->base + REG_RX_SRAM_SIZE); /* T8132 reports channel metadata in the upper half of these words. */ @@ -262,6 +289,13 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, ad->txcache.size &= GENMASK(15, 0); ad->rxcache.size &= GENMASK(15, 0); } + if (ad->t8152_layout) { + /* bits 31:24 are the channel count */ + ad->txcache.size &= SRAM_SIZE_MASK; + ad->rxcache.size &= SRAM_SIZE_MASK; + first = T8152_SRAM_BASE; + block = T8152_SRAM_BLOCK; + } if (dir == DMA_MEM_TO_DEV) sram = &ad->txcache; @@ -270,14 +304,14 @@ static int admac_alloc_sram_carveout(struct admac_data *ad, mutex_lock(&ad->cache_alloc_lock); - nblocks = sram->size / SRAM_BLOCK; + nblocks = sram->size > first ? (sram->size - first) / block : 0; for (i = ad->split_channels ? 1 : 0; i < nblocks; i++) if (!(sram->allocated & BIT(i))) break; if (i < nblocks) { - *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, i * SRAM_BLOCK) | - FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, SRAM_BLOCK); + *out = FIELD_PREP(CHAN_SRAM_CARVEOUT_BASE, first + i * block) | + FIELD_PREP(CHAN_SRAM_CARVEOUT_SIZE, block); sram->allocated |= BIT(i); } else { ret = -EBUSY; @@ -294,18 +328,24 @@ static void admac_free_sram_carveout(struct admac_data *ad, { struct admac_sram *sram; u32 base = FIELD_GET(CHAN_SRAM_CARVEOUT_BASE, carveout); + u32 first = 0, block = SRAM_BLOCK; int i; + if (ad->t8152_layout) { + first = T8152_SRAM_BASE; + block = T8152_SRAM_BLOCK; + } + if (dir == DMA_MEM_TO_DEV) sram = &ad->txcache; else sram = &ad->rxcache; - if (WARN_ON(base >= sram->size)) + if (WARN_ON(base < first || base >= sram->size)) return; mutex_lock(&ad->cache_alloc_lock); - i = base / SRAM_BLOCK; + i = (base - first) / block; sram->allocated &= ~BIT(i); mutex_unlock(&ad->cache_alloc_lock); } @@ -409,6 +449,15 @@ static void admac_write_hw_desc(struct admac_data *ad, int channo, adchan->seq = adchan->seq == 0xff ? 1 : adchan->seq + 1; flags = DISPLAY_FLAG_DESC_REPORT | adchan->seq; + } else if (ad->t8152_layout) { + /* + * T8152: the low byte of the last word is a descriptor id, + * which macOS counts 1..255 and never leaves at 0. + */ + struct admac_chan *adchan = &ad->channels[channo]; + + adchan->desc_id = adchan->desc_id == 255 ? 1 : adchan->desc_id + 1; + flags = FLAG_DESC_NOTIFY | adchan->desc_id; } dev_dbg(ad->dev, "ch%d descriptor: addr=0x%pad len=0x%zx flags=0x%x\n", @@ -671,6 +720,11 @@ static void admac_start_chan(struct admac_chan *adchan) writel_relaxed(STATUS_DESC_DONE | STATUS_ERR, ad->base + REG_CHAN_INTMASK(ad, adchan->no, ad->irq_index)); } + if (ad->t8152_layout) { + writel_relaxed(CHAN_CONFIG_T8152, ad->base + REG_CHAN_CONFIG(ad, adchan->no)); + admac_modify(ad, REG_CHAN_STATE(ad, adchan->no), CHAN_STATE_MASK, + CHAN_STATE_READY); + } switch (admac_chan_direction(adchan->no)) { case DMA_MEM_TO_DEV: @@ -1445,7 +1499,8 @@ static int admac_device_config(struct dma_chan *chan, * of words position in a frame. That's where the importance of this control * comes from. */ - switch (is_tx ? config->dst_port_window_size : config->src_port_window_size) { + switch (ad->t8152_layout ? 0 : + is_tx ? config->dst_port_window_size : config->src_port_window_size) { case 0 ... 1: break; case 2: @@ -1467,6 +1522,15 @@ static int admac_device_config(struct dma_chan *chan, adchan->realign_bytes = admac_config_realign_bytes(config); + /* + * Optional: a u32 frame size in bytes, which a paused capture is + * restarted aligned to on resume (see admac_cyclic_realign()). + */ + if (config->peripheral_config && config->peripheral_size == sizeof(u32)) + adchan->realign_bytes = *(u32 *)config->peripheral_config; + else + adchan->realign_bytes = 0; + /* * By FIFOCTL_LIMIT we seem to set the maximal number of bytes allowed to be * held in controller's per-channel FIFO. Transfers seem to be triggered @@ -1588,6 +1652,7 @@ static int admac_probe(struct platform_device *pdev) ad->evolved_layout = hw->evolved_layout; ad->split_channels = hw->split_channels; ad->display = hw->display; + ad->t8152_layout = hw->t8152_layout; mutex_init(&ad->cache_alloc_lock); if (ad->display) { @@ -1751,8 +1816,13 @@ static const struct admac_hw admac_t6050_display_hw = { .display = true, }; +static const struct admac_hw admac_t8152_hw = { + .t8152_layout = true, +}; + static const struct of_device_id admac_of_match[] = { { .compatible = "apple,t6050-display-admac", .data = &admac_t6050_display_hw }, + { .compatible = "apple,t8152-admac", .data = &admac_t8152_hw }, { .compatible = "apple,t8140-admac", .data = &admac_t8140_hw }, { .compatible = "apple,t8132-admac", .data = &admac_t8132_hw }, { .compatible = "apple,t8122-admac", .data = &admac_t8122_hw }, diff --git a/drivers/gpu/drm/apple/Kconfig b/drivers/gpu/drm/apple/Kconfig index 99632ffe1535c..aae90f8de5825 100644 --- a/drivers/gpu/drm/apple/Kconfig +++ b/drivers/gpu/drm/apple/Kconfig @@ -75,6 +75,24 @@ config DRM_APPLE_DCP_T8132 Load appledrm explicitly before the GPU, with its alias autoload disabled, after guarded admission of the inherited display DARTs. +config DRM_APPLE_DCP_T8152 + bool "Mac mini M6 (J873g) displays" + depends on DRM_APPLE + depends on TYPEC + depends on MFD_MACSMC=y || MFD_MACSMC=DRM_APPLE + select APERTURE_HELPERS + help + Lets the common Apple display driver drive the three display + coprocessors of the T8152 Mac mini (J873g) through their firmware's + iBoot interface: the HDMI port, whose DisplayPort-to-HDMI converter + is powered through the SMC, and displays on the rear USB-C ports, + whose DisplayPort alt mode the USB Type-C port driver of their PD + controllers reports (TYPEC_SN201202X). + + The boot loader hands each coprocessor over, running or quiesced, + with the AFK endpoints it left running. The adopted sessions cannot + be stopped; their DMA stays retained until reboot. + config DRM_APPLE_DEBUG bool "Enable additional driver debugging" depends on DRM_APPLE diff --git a/drivers/gpu/drm/apple/Makefile b/drivers/gpu/drm/apple/Makefile index a6687d7cccd65..c040f80df8e80 100644 --- a/drivers/gpu/drm/apple/Makefile +++ b/drivers/gpu/drm/apple/Makefile @@ -18,6 +18,9 @@ appledrm-y += iomfb_v14_7_tpl.o appledrm-y += iomfb_v26_6_desktop.o appledrm-y += iomfb_v14_7.o iomfb_v14_7_link.o appledrm-$(CONFIG_DRM_APPLE_DCP_T8132) += iomfb_m4.o t8132_ext_drm.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_atc.o t8152_aux.o t8152_dptx.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += t8152_hdmi.o t8152_typec.o +appledrm-$(CONFIG_DRM_APPLE_DCP_T8152) += iomfb_iboot.o iboot_drm.o appledrm-y += iomfb_h17p.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_h17p_test.o parser_test.o appledrm-$(CONFIG_DRM_APPLE_KUNIT_TEST) += iomfb_external_hdr_hints_test.o diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 3c5eaf725d02a..75152de0a85dd 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -83,6 +83,18 @@ void afk_service_retry(struct apple_dcp_afkep *ep) } EXPORT_SYMBOL_IF_KUNIT(afk_service_retry); +/* How long the host waits for the firmware: the processor's own, or one second. */ +static unsigned int afk_timeout_ms(struct apple_dcp_afkep *ep) +{ + return ep->dcp->hw.afk_timeout_ms ?: MSEC_PER_SEC; +} + +/* The same for a service the caller may not have; the call fails without one. */ +static unsigned int afk_service_timeout_ms(struct apple_epic_service *service) +{ + return service ? afk_timeout_ms(service->ep) : MSEC_PER_SEC; +} + static void afk_send(struct apple_dcp_afkep *ep, u64 message) { dcp_send_message(ep->dcp, ep->endpoint, message); @@ -115,7 +127,8 @@ struct apple_dcp_afkep *afk_init(struct apple_dcp *dcp, u32 endpoint, afkep->ops = ops; afkep->dcp = dcp; - afkep->wire_v2 = dcp->fw_compat == DCP_FIRMWARE_V_27_0 || dcp_is_ext26(dcp); + afkep->wire_v2 = dcp->fw_compat == DCP_FIRMWARE_V_27_0 || dcp_is_ext26(dcp) || + dcp->hw.afk_v2; afkep->endpoint = endpoint; afkep->wq = alloc_ordered_workqueue("apple-dcp-afkep%02x", WQ_MEM_RECLAIM, endpoint); @@ -184,7 +197,8 @@ void afk_shutdown(struct apple_dcp_afkep *afkep) afk_send(afkep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); int ret; - ret = wait_for_completion_timeout(&afkep->stopped, msecs_to_jiffies(1000)); + ret = wait_for_completion_timeout(&afkep->stopped, + msecs_to_jiffies(afk_timeout_ms(afkep))); if (ret <= 0) { dev_err(afkep->dcp->dev, "Timed out shutting down AFK endpoint %02x", afkep->endpoint); } @@ -235,6 +249,36 @@ static int afk_start_polled(struct apple_dcp_afkep *ep) return -ETIMEDOUT; } +/* + * An endpoint the bootloader left running (afk_live_endpoints): an INIT + * on a live endpoint asserts in the firmware. Stop it and wait for the + * acknowledgment first. Its old ring stays with the bootloader, which + * keeps it reserved. + */ +static int afk_stop_live(struct apple_dcp_afkep *ep) +{ + u32 bit; + + if (ep->endpoint < 0x20 || ep->endpoint >= 0x40) + return 0; + bit = BIT(ep->endpoint - 0x20); + if (!(ep->dcp->afk_live_endpoints & bit)) + return 0; + reinit_completion(&ep->stopped); + afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_SHUTDOWN)); + if (!wait_for_completion_timeout(&ep->stopped, + msecs_to_jiffies(afk_timeout_ms(ep)))) { + dev_err(ep->dcp->dev, "AFK[ep:%02x]: inherited endpoint did not stop\n", + ep->endpoint); + return -ETIMEDOUT; + } + reinit_completion(&ep->stopped); + ep->dcp->afk_live_endpoints &= ~bit; + dev_info(ep->dcp->dev, "AFK[ep:%02x]: inherited endpoint stopped\n", + ep->endpoint); + return 0; +} + int afk_start(struct apple_dcp_afkep *ep) { int ret; @@ -248,6 +292,16 @@ int afk_start(struct apple_dcp_afkep *ep) } reinit_completion(&ep->started); + /* + * An adopted session's endpoint map went to the bootloader, and RTKit + * starts only endpoints it knows. Registered before anything is sent, + * the endpoint's replies are not reported as an unknown endpoint's. + */ + if (ep->dcp->hw.afk_adopt_endpoints) + apple_rtkit_adopt_ep(ep->dcp->rtk, ep->endpoint); + ret = afk_stop_live(ep); + if (ret) + return ret; ret = apple_rtkit_start_ep(ep->dcp->rtk, ep->endpoint); if (ret) return ret; @@ -256,7 +310,8 @@ int afk_start(struct apple_dcp_afkep *ep) return afk_start_polled(ep); afk_send(ep, FIELD_PREP(RBEP_TYPE, RBEP_INIT)); - ret = wait_for_completion_timeout(&ep->started, msecs_to_jiffies(1000)); + ret = wait_for_completion_timeout(&ep->started, + msecs_to_jiffies(afk_timeout_ms(ep))); if (ret <= 0 && ep->dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) dev_warn(ep->dcp->dev, @@ -969,6 +1024,7 @@ static void afk_recv_handle_compact_init(struct apple_dcp_afkep *ep, if (ops->init) ops->init(service, service_name, service_name, unit); + wake_up_all(&ep->service_wq); dev_info(ep->dcp->dev, "AFK[ep:%02x]: new compact service %s on interface %u%s\n", @@ -1658,6 +1714,7 @@ static void afk_retry_service_init(struct apple_dcp_afkep *ep) if (ops->init) ops->init(service, service->pending_name, service->pending_class, service->pending_unit); + wake_up_all(&ep->service_wq); if (service->enabled) afk_populate_service_debugfs(service); kfree(service->pending_name); @@ -1739,7 +1796,7 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, * EPICProviderClass was used. If the init call has props parse them and * use EPICProviderClass to match the service. */ - if (props_size > 36) { + if (props_size > 36 && !ep->dcp->hw.afk_announced_names) { int ret = parse(props, props_size, &ctx); if (ret) { dev_err(ep->dcp->dev, @@ -1784,8 +1841,17 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, service_name = epic_class; } } else { - service_name = name; - } + service_name = name; + /* + * hw.afk_announced_names: the announced name is the service's + * identity, and its handler gets it as the EPIC name. + */ + if (ep->dcp->hw.afk_announced_names) { + epic_name = kstrdup(name, GFP_KERNEL); + if (!epic_name) + return; + } + } if (ep->match_epic_name) ops = afk_match_service(ep, epic_name); @@ -1808,6 +1874,8 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, if (!ops && dcp_is_ext26(ep->dcp) && ep->ops && !strcmp(ep->ops->name, "native26-observer")) ops = ep->ops; + if (!ops) + ops = ep->unmatched_ops; if (!ops) { dev_err(ep->dcp->dev, "AFK[ep:%02x]: unable to match service %s on channel %d\n", @@ -1885,6 +1953,7 @@ static void afk_recv_handle_init(struct apple_dcp_afkep *ep, u32 channel, ops->init_props(service, epic_unit, props, props_size); if (ops->init) ops->init(service, epic_name, epic_class, epic_unit); + wake_up_all(&ep->service_wq); dev_info(ep->dcp->dev, "AFK[ep:%02x]: new service %s on channel %d\n", ep->endpoint, service_name, channel); @@ -3136,7 +3205,7 @@ int afk_send_command(struct apple_epic_service *service, u8 type, { return afk_send_command_timeout(service, type, payload, payload_len, output, output_len, retcode, - MSEC_PER_SEC); + afk_service_timeout_ms(service)); } static u16 afk_command_tag(struct apple_epic_service *service, u8 slot) @@ -3181,6 +3250,15 @@ int afk_send_command_timeout(struct apple_epic_service *service, u8 type, output, output_len, retcode, timeout_ms, NULL); } +int afk_send_command_len(struct apple_epic_service *service, u8 type, + const void *payload, size_t payload_len, void *output, + size_t output_len, u32 *retcode, size_t *received) +{ + return afk_send_command_timeout_len(service, type, payload, payload_len, + output, output_len, retcode, + afk_service_timeout_ms(service), received); +} + /* * @reply_len (legacy EPIC only): return just the bytes the firmware reported * in its reply instead of the whole allocated output. @@ -3268,11 +3346,20 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, goto err_put_service; } - rxbuf = dma_alloc_coherent(ep->dcp->dev, output_len, &rxbuf_dma, - GFP_KERNEL); - if (!rxbuf) { - ret = -ENOMEM; - goto err_put_service; + /* + * A command without output carries no reply buffer: firmware that + * answers some commands with a status alone asserts when it is given + * one, since it then copies an empty reply. + */ + rxbuf = NULL; + rxbuf_dma = 0; + if (output_len) { + rxbuf = dma_alloc_coherent(ep->dcp->dev, output_len, &rxbuf_dma, + GFP_KERNEL); + if (!rxbuf) { + ret = -ENOMEM; + goto err_put_service; + } } txbuf = dma_alloc_coherent(ep->dcp->dev, payload_len, &txbuf_dma, GFP_KERNEL); @@ -3430,7 +3517,7 @@ static int afk_send_command_common(struct apple_epic_service *service, u8 type, if (!dcp_is_ext26(ep->dcp)) dma_free_coherent(ep->dcp->dev, payload_len, txbuf, txbuf_dma); err_free_rxbuf: - if (!dcp_is_ext26(ep->dcp)) + if (rxbuf && !dcp_is_ext26(ep->dcp)) dma_free_coherent(ep->dcp->dev, output_len, rxbuf, rxbuf_dma); err_put_service: afk_service_put(service); @@ -3443,7 +3530,7 @@ int afk_service_call(struct apple_epic_service *service, u16 group, u32 command, { return afk_service_call_timeout(service, group, command, data, data_len, data_pad, output, output_len, - output_pad, MSEC_PER_SEC); + output_pad, afk_service_timeout_ms(service)); } int afk_service_call_len(struct apple_epic_service *service, u16 group, @@ -3453,7 +3540,7 @@ int afk_service_call_len(struct apple_epic_service *service, u16 group, { return afk_service_call_timeout_len(service, group, command, data, data_len, data_pad, output, output_len, output_pad, - MSEC_PER_SEC, received); + afk_service_timeout_ms(service), received); } int afk_service_call_timeout(struct apple_epic_service *service, u16 group, diff --git a/drivers/gpu/drm/apple/afk.h b/drivers/gpu/drm/apple/afk.h index b2c7c5deddb29..cf214e1eb1b68 100644 --- a/drivers/gpu/drm/apple/afk.h +++ b/drivers/gpu/drm/apple/afk.h @@ -580,8 +580,15 @@ struct apple_dcp_afkep { void *compact_rx_data; const struct apple_epic_service_ops *ops; + /* + * Bound to an announced service no entry of @ops names, which is then + * opened like a matched one. NULL leaves such a service unopened. + */ + const struct apple_epic_service_ops *unmatched_ops; struct apple_epic_service services[AFK_MAX_CHANNEL]; u32 num_channels; + /* Woken once a service has opened and its init callback has run. */ + wait_queue_head_t service_wq; struct dentry *debugfs_entry; @@ -601,6 +608,7 @@ static inline void afk_ep_init_state(struct apple_dcp_afkep *ep) spin_lock_init(&ep->lock); INIT_LIST_HEAD(&ep->compact_cmds); init_waitqueue_head(&ep->compact_orphan_wq); + init_waitqueue_head(&ep->service_wq); mutex_init(&ep->compact_tx_lock); init_completion(&ep->started); init_completion(&ep->stopped); @@ -641,6 +649,13 @@ int afk_send_command_timeout(struct apple_epic_service *service, u8 type, const void *payload, size_t payload_len, void *output, size_t output_len, u32 *retcode, unsigned int timeout_ms); +/* + * As afk_send_command(), and @received is set to the number of bytes of + * @output the reply filled: an AFKv2 reply may be shorter than @output_len. + */ +int afk_send_command_len(struct apple_epic_service *service, u8 type, + const void *payload, size_t payload_len, void *output, + size_t output_len, u32 *retcode, size_t *received); int afk_service_call(struct apple_epic_service *service, u16 group, u32 command, const void *data, size_t data_len, size_t data_pad, void *output, size_t output_len, size_t output_pad); diff --git a/drivers/gpu/drm/apple/dcp-internal.h b/drivers/gpu/drm/apple/dcp-internal.h index 515e6bf065f09..f55c05d9f1793 100644 --- a/drivers/gpu/drm/apple/dcp-internal.h +++ b/drivers/gpu/drm/apple/dcp-internal.h @@ -345,6 +345,29 @@ struct apple_dcp_hw_data { * firmware 27.0 and 27.2.1), so there is no secure port to idle before the IOP. */ bool s2r_no_secure_port; + /* + * Every AFK endpoint speaks AFKv2 (see afk_init()), whatever the + * firmware interface: for a firmware that does so on all of them + * without an IOMFB interface version that implies it. + */ + bool afk_v2; + /* + * The RTKit session is taken over without its endpoint map (see + * apple_rtkit_init_adopted()): afk_start() registers each endpoint + * with RTKit before starting it. + */ + bool afk_adopt_endpoints; + /* + * AFK services are matched by the name in their announcement; the + * properties after it are not parsed (afk_recv_handle_init()). + */ + bool afk_announced_names; + /* + * How long AFK waits for the firmware to start or stop an endpoint + * and to answer a command or service call (afk_timeout_ms()); zero + * for one second. + */ + unsigned int afk_timeout_ms; }; enum dcp_test_point { @@ -439,6 +462,8 @@ struct dcp_desktop_state { /* TODO: move IOMFB members to its own struct */ struct dcpext_scanout; +struct t8152_display; +struct dcp_iboot; struct dcp_hdmi; struct dcp_cec; @@ -561,8 +586,18 @@ struct apple_dcp { /* firmware version and compatible firmware version */ enum dcp_firmware_version fw_compat; + /* T8152: the DisplayPort hardware behind the DPTX port (t8152_display.h) */ + struct t8152_display *t8152; + /* DCP_FIRMWARE_IBOOT: the display driven through it (iomfb_iboot.h) */ + struct dcp_iboot *iboot; /* Bumped by every iomfb poweron; see afk_compact_slot(). */ u32 afk_power_gen; + /* + * AFK endpoints the bootloader left running, bit N for endpoint + * 0x20 + N, from its hand-off: afk_start() stops each before its + * INIT. Zero for a processor without such a hand-off. + */ + u32 afk_live_endpoints; /* Firmware 27.x: the method IDs of this build (iomfb_v27_methods()). */ const struct dcp_method_entry *v27_methods; bool external; @@ -1182,6 +1217,19 @@ struct apple_dcp { struct dcp_cec *cec; }; +/* A DCP driven through the firmware's iBoot interface alone. */ +static inline bool dcp_is_iboot(const struct apple_dcp *dcp) +{ + return dcp->fw_compat == DCP_FIRMWARE_IBOOT; +} + +struct apple_rtkit_shmem; +/* The common RTKit shared memory hooks, for a processor with its own RTKit ops. */ +int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr); +void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr); +/* Keep a session that cannot be stopped, its DMA and this driver until reboot. */ +int dcp_retain_live_session(struct apple_dcp *dcp); + /* T8132 firmware uses its own wire codec, with the common DRM/KMS owner. */ static inline bool iomfb_is_m4(const struct apple_dcp *dcp) { diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b16995083020d..b0b1255045fd5 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -77,6 +77,7 @@ #include "dptx-service.h" #include "iomfb.h" #include "iomfb_internal.h" +#include "iomfb_iboot.h" #include "iomfb_m4.h" #include "ibootep.h" #include "iomfb_internal.h" @@ -114,15 +115,15 @@ static bool dcp_session_retained(struct device *dev) return retained; } -static int dcp_pin_live_session(struct apple_dcp *dcp) +/* + * Keep a live session's DMA device, domain use and this driver until reboot, + * and refuse a new probe of its device after an unbind. + */ +int dcp_retain_live_session(struct apple_dcp *dcp) { struct dcp_session_ref *session; - if ((!dcp->hw.adopt_live_session && - dcp->hw.iomfb_method_profile != - DCP_IOMFB_METHODS_H17P_EXTERNAL) || - !dcp_fail_stop(dcp) || - dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || dcp->retain_dma) + if (dcp->retain_dma) return 0; session = kzalloc_obj(*session); if (!session) @@ -143,6 +144,17 @@ static int dcp_pin_live_session(struct apple_dcp *dcp) return 0; } +static int dcp_pin_live_session(struct apple_dcp *dcp) +{ + if ((!dcp->hw.adopt_live_session && + dcp->hw.iomfb_method_profile != + DCP_IOMFB_METHODS_H17P_EXTERNAL) || + !dcp_fail_stop(dcp) || + dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17G || dcp->retain_dma) + return 0; + return dcp_retain_live_session(dcp); +} + static void dcp_release_dma_domain(void *data) { struct apple_dcp *dcp = data; @@ -1843,7 +1855,7 @@ static int dcp_check_iova_contiguous(struct iommu_domain *domain, return 0; } -static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) +int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; int ret; @@ -1904,7 +1916,7 @@ static int dcp_rtk_shmem_setup(void *cookie, struct apple_rtkit_shmem *bfr) return 0; } -static void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +void dcp_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) { struct apple_dcp *dcp = cookie; @@ -7884,13 +7896,54 @@ static int dcp_platform_probe_t8132_ext(struct platform_device *pdev) * bind's, may still appear (bounded by the deferred probe timeout); on any * other failure join as an unusable pipe. */ +/* + * A DCP driven through the iBoot interface alone (DCP_FIRMWARE_IBOOT, + * iomfb_iboot.c): no component of a display subsystem, with a DRM device of + * its own. Its adopted session cannot be stopped: once the firmware is + * touched, its DMA and this driver stay until reboot, and a failed start + * leaves the device bound without a display. + */ +static int dcp_platform_probe_iboot(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct apple_dcp *dcp; + int ret; + + if (dcp_session_retained(dev)) + return dev_err_probe(dev, -EBUSY, "Previous live DCP session requires a reboot\n"); + dcp = kzalloc_obj(*dcp); + if (!dcp) + return -ENOMEM; + ret = devm_add_action_or_reset(dev, dcp_release_context, dcp); + if (ret) + return ret; + dcp->dev = dev; + dcp->hw = *(struct apple_dcp_hw_data *)of_device_get_match_data(dev); + dcp->fw_compat = dcp->hw.firmware_compat; + ret = iommu_device_use_default_domain(dev); + if (ret) + return ret; + ret = devm_add_action_or_reset(dev, dcp_release_dma_domain, dcp); + if (ret) + return ret; + platform_set_drvdata(pdev, dcp); + return dcp_iboot_probe(dcp); +} + static int dcp_platform_probe(struct platform_device *pdev) { + const struct apple_dcp_hw_data *hw = of_device_get_match_data(&pdev->dev); struct device *dev = &pdev->dev; struct apple_dcp *dcp; void *group; int ret; + if (hw->firmware_compat == DCP_FIRMWARE_IBOOT) { + /* The port controllers wait for the USB-C display switches. */ + t8152_typec_register(dev); + return dcp_platform_probe_iboot(pdev); + } + /* t6041_dcpext=0: stay off the external processors' hardware. */ if (of_device_is_compatible(dev->of_node, "apple,t6041-dcpext") && !t6041_dcpext) { @@ -7949,6 +8002,11 @@ static void dcp_platform_remove(struct platform_device *pdev) { struct apple_dcp *dcp = platform_get_drvdata(pdev); + /* No component and none of the works below; see dcp_iboot_remove(). */ + if (dcp && dcp_is_iboot(dcp)) { + dcp_iboot_remove(dcp); + return; + } if (dcp) { cancel_work_sync(&dcp->s2r_prewarm_work); cancel_delayed_work_sync(&dcp->s2r_prewarm_off_wq); @@ -8008,6 +8066,9 @@ VISIBLE_IF_KUNIT void dcp_platform_shutdown(struct platform_device *pdev) if (dcp_takeover_was_aborted(dcp)) return; + /* The iBoot interface's display stays as it is: no component to remove. */ + if (dcp && dcp_is_iboot(dcp)) + return; if (dcp && iomfb_is_m4(dcp)) { dcp_comp_unbind(&pdev->dev, NULL, NULL); @@ -8239,6 +8300,9 @@ static void dcp_platform_complete(struct device *dev) { struct apple_dcp *dcp = dev_get_drvdata(dev); + /* The iBoot interface's display stays powered across system sleep. */ + if (dcp_is_iboot(dcp)) + return; if (dcp_is_ext26(dcp)) { WRITE_ONCE(dcp->ext26_pm_preparing, false); if (dcp->ext26_pm_work_off && !READ_ONCE(dcp->ext26_blocked) && @@ -9724,6 +9788,9 @@ static int dcp_platform_suspend(struct device *dev) /* Its power sequences may crash the DCP and blank the panel. */ if (dcp_takeover_was_aborted(dcp)) return -EBUSY; + /* The iBoot interface's display stays powered across system sleep. */ + if (dcp_is_iboot(dcp)) + return 0; /* * An external DCP given up at probe may never have set up the works @@ -9877,6 +9944,8 @@ static int dcp_platform_resume(struct device *dev) if (dcp_takeover_was_aborted(dcp)) return 0; + if (dcp_is_iboot(dcp)) + return 0; if (dcp_v27_sleep_selected(dcp) && READ_ONCE(dcp->sleep_v27_closed)) return dcp_v27_sleep_resume(dcp); @@ -10113,8 +10182,29 @@ static const struct apple_dcp_hw_data apple_dcp_hw_t8142_dcpext = { .s2r_layout = &dcp_s2r_t8142_ext[0], }; +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) +/* + * T8152 (J873g): the DCP and both DCPEXTs, driven through the firmware's + * iBoot interface (disp0-service, dispext-service) over AFKv2, with the + * DPAV controller and DPTX port endpoints opened as the firmware expects + * them. The bootloader leaves each session running or quiesced; a running + * one is taken without the RTKit handshake. + */ +static const struct apple_dcp_hw_data apple_dcp_hw_t8152_iboot = { + .num_dptx_ports = 2, + .firmware_compat = DCP_FIRMWARE_IBOOT, + .afk_v2 = true, + .afk_adopt_endpoints = true, + .afk_announced_names = true, + .afk_timeout_ms = 3000, +}; +#endif + static const struct of_device_id of_match[] = { { .compatible = "apple,t8142-dcpext", .data = &apple_dcp_hw_t8142_dcpext }, +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) + { .compatible = "apple,t8152-dcp-iboot", .data = &apple_dcp_hw_t8152_iboot }, +#endif { .compatible = "apple,t6041-dcp", .data = &apple_dcp_hw_t6041, }, { .compatible = "apple,t6041-dcpext", .data = &apple_dcp_hw_t6041_dcpext, }, { .compatible = "apple,t6050-dcp", .data = &apple_dcp_hw_t6050 }, @@ -10162,6 +10252,7 @@ int __init dcp_register(void) void dcp_unregister(void) { platform_driver_unregister(&apple_platform_driver); + t8152_typec_unregister(); } #if IS_ENABLED(CONFIG_DRM_APPLE_DISPLAY_KUNIT_TEST) diff --git a/drivers/gpu/drm/apple/iboot_drm.c b/drivers/gpu/drm/apple/iboot_drm.c new file mode 100644 index 0000000000000..46b9fae499254 --- /dev/null +++ b/drivers/gpu/drm/apple/iboot_drm.c @@ -0,0 +1,1098 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * KMS of a DCP driven through the iBoot interface (DCP_FIRMWARE_IBOOT): a DRM + * device of its own per DCP with one primary plane, CRTC, encoder and + * connector. The firmware only takes width, height and refresh rate for a + * mode and picks the timing itself; the modes come from the sink's EDID, or + * from the firmware's list built with CVT. + * + * Framebuffers are shadow buffers copied by the CPU into the scanout + * buffers, and a modeset only changes their geometry, as the bootloader + * does. Changing the surface address between Linux buffers made later + * modesets crash the firmware (IOMFB axi_rd_err), so the scanout buffers + * are the only surfaces the firmware gets. There is no vblank interrupt. + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dcp-internal.h" +#include "ibootep.h" +#include "iomfb_iboot.h" +#include "t8152_display.h" + +/* + * Swap between the scanout buffers per frame. Off: frames are copied into + * the buffer on screen, which tears during motion. + */ +static bool buffered = true; +module_param_named(iboot_buffered, buffered, bool, 0444); +MODULE_PARM_DESC(iboot_buffered, "iBoot interface displays: copy each frame into a scanout buffer that is not on screen (default: on)"); + +DEFINE_DRM_GEM_DMA_FOPS(dcp_iboot_fops); + +/* + * Not the display subsystem's "apple": these DCPs take no direct scanout, + * every frame is copied, so userspace must not treat them as that one. + */ +static const struct drm_driver dcp_iboot_drm_driver = { + /* + * Frames are copied by the CPU, imported ones too: a compositor + * driving both displays imports one device's buffers into the other. + */ + DRM_GEM_DMA_DRIVER_OPS_VMAP, + DRM_FBDEV_DMA_DRIVER_OPS, + .name = "apple-dcpib", + .desc = "Apple DCP (iBoot interface)", + .major = 1, + .minor = 0, + .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_ATOMIC, + .fops = &dcp_iboot_fops, +}; + +struct dcp_iboot *dcp_iboot_alloc(struct device *dev) +{ + return devm_drm_dev_alloc(dev, &dcp_iboot_drm_driver, struct dcp_iboot, drm); +} + +const char *dcp_iboot_driver_name(void) +{ + return dcp_iboot_drm_driver.name; +} + +static const u32 dcp_iboot_formats[] = { + DRM_FORMAT_XRGB8888, + DRM_FORMAT_ARGB8888, +}; + +static int iboot_refresh(const struct iboot_timing_mode *t) +{ + return (le32_to_cpu(t->fps) + 0x8000) >> 16; +} + +/* + * Whether @t works: the link at the PHY's highest rate must carry it (24 bpp + * plus about 12% blanking against rate x lanes x 0.8 for 8b/10b); a mode + * beyond that only blanks the display. + */ +static bool iboot_mode_fits(struct dcp_iboot *ib, const struct iboot_timing_mode *t) +{ + const struct t8152_phy_ops *phy = ib->disp.phy; + /* + * The lanes the firmware may train, as GET_MAX_LANE_COUNT reports them: + * the USB-C route's. Not the last training's: a sink that replugs while + * the display is off is trained with a single lane. + */ + u32 lanes = (phy->max_lane_count ? phy->max_lane_count(&ib->disp) : 4) ?: 2; + u64 link = (u64)phy->max_link_rate * 270000000ULL * lanes * 8 / 10; + u64 pixels = (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) * + iboot_refresh(t); + + /* Hotplug may return modes larger than the buffers allocated at probe. */ + if ((u64)ALIGN(le32_to_cpu(t->width) * 4, 64) * le32_to_cpu(t->height) > + ib->scan[0].size) + return false; + return pixels * 24 * 112 / 100 <= link; +} + +/* @mode's refresh rate in 16.16, as drm_mode_vrefresh() computes it. */ +static u32 iboot_mode_fps(const struct drm_display_mode *mode) +{ + u64 num = mul_u32_u32(mode->clock, 1000) << 16; + u64 den = mul_u32_u32(mode->htotal, mode->vtotal); + + if (mode->flags & DRM_MODE_FLAG_INTERLACE) + num *= 2; + if (mode->flags & DRM_MODE_FLAG_DBLSCAN) + den *= 2; + if (mode->vscan > 1) + den *= mode->vscan; + return den ? DIV64_U64_ROUND_CLOSEST(num, den) : 0; +} + +/* + * The firmware mode for @mode: same size, refresh rate within 1 Hz (EDID's + * 59.94 against the firmware's 60.00), the nearest one by the exact rate. + * The firmware picks the timing from the rate, and next to the sink's + * 2560x1440@59.951 (241.5 MHz) it lists a 60.000 standard mode that it + * drives with CVT at 312.25 MHz, which the J873g's USB-C EV2780 rejects. + */ +static const struct iboot_timing_mode * +iboot_find_mode(struct dcp_iboot *ib, const struct drm_display_mode *mode) +{ + const struct iboot_timing_mode *best = NULL; + u32 fps = iboot_mode_fps(mode); + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != mode->hdisplay || + le32_to_cpu(t->height) != mode->vdisplay || + abs_diff(le32_to_cpu(t->fps), fps) > 0x10000 || + !iboot_mode_fits(ib, t)) + continue; + if (!best || abs_diff(le32_to_cpu(t->fps), fps) < + abs_diff(le32_to_cpu(best->fps), fps)) + best = t; + } + return best; +} + +/* + * Valid, at most 32 bpp, the highest depth, then the lowest colorimetry, + * encoding and EOTF, as the bootloader chooses. Deeper modes the HDMI + * converter offers are refused by SET_MODE. + */ +static bool iboot_color_better(const struct iboot_color_mode *a, + const struct iboot_color_mode *b) +{ + u32 abpp = le32_to_cpu(a->bpp), bbpp = le32_to_cpu(b->bpp); + bool afits = abpp <= 32, bfits = bbpp <= 32; + + if (!!a->valid != !!b->valid) + return a->valid; + if (afits != bfits) + return afits; + if (abpp != bbpp) + return abpp > bbpp; + if (a->colorimetry != b->colorimetry) + return le32_to_cpu(a->colorimetry) < le32_to_cpu(b->colorimetry); + if (a->encoding != b->encoding) + return le32_to_cpu(a->encoding) < le32_to_cpu(b->encoding); + return le32_to_cpu(a->eotf) < le32_to_cpu(b->eotf); +} + +static const struct iboot_color_mode *iboot_find_color(struct dcp_iboot *ib) +{ + const struct iboot_color_mode *best = NULL; + + for (unsigned int i = 0; i < ib->nr_cmodes; i++) + if (!best || iboot_color_better(&ib->cmodes[i], best)) + best = &ib->cmodes[i]; + return best && best->valid ? best : NULL; +} + +/* + * A conservative console mode from 50 to 60 Hz, up to 1920x1080 on + * USB-C. Userspace can select the larger modes, including 2560x1440@60, + * after the sink's EDID is available. + */ +static const struct iboot_timing_mode *iboot_preferred(struct dcp_iboot *ib) +{ + const struct iboot_timing_mode *best = NULL; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + /* + * Byte 0 bit 6 marks standard modes a converter adds on its own + * (the J873g PS190 lists 3840x2160 for a 2560x1440 monitor); + * the bootloader's largest mode skips them too. + */ + if (!t->valid || iboot_refresh(t) > 60 || iboot_refresh(t) < 50 || + (t->flags[0] & 0x40) || + (!ib->disp.hdmi && (le32_to_cpu(t->width) > 1920 || + le32_to_cpu(t->height) > 1080)) || + !iboot_mode_fits(ib, t)) + continue; + if (!best || (u64)le32_to_cpu(t->width) * le32_to_cpu(t->height) > + (u64)le32_to_cpu(best->width) * le32_to_cpu(best->height) || + (t->width == best->width && t->height == best->height && + le32_to_cpu(t->fps) > le32_to_cpu(best->fps))) + best = t; + } + return best; +} + +/* + * The sink's EDID modes the firmware also has (mode_valid drops the rest), + * the largest of them preferred: firmware modes the sink does not list, + * such as 1400x1050 on the J873g EV2780, stay black. + */ +static int iboot_edid_get_modes(struct drm_connector *connector) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + struct drm_display_mode *mode, *best = NULL; + int count = drm_edid_connector_add_modes(connector); + + mutex_lock(&ib->lock); + list_for_each_entry(mode, &connector->probed_modes, head) { + mode->type &= ~DRM_MODE_TYPE_PREFERRED; + if (!iboot_find_mode(ib, mode)) + continue; + if (!best || mode->hdisplay * mode->vdisplay > + best->hdisplay * best->vdisplay || + (mode->hdisplay * mode->vdisplay == + best->hdisplay * best->vdisplay && + drm_mode_vrefresh(mode) > drm_mode_vrefresh(best))) + best = mode; + } + if (best) + best->type |= DRM_MODE_TYPE_PREFERRED; + mutex_unlock(&ib->lock); + return count; +} + +static int iboot_connector_get_modes(struct drm_connector *connector) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + const struct iboot_timing_mode *preferred; + int count = 0; + + drm_edid_connector_update(connector, ib->edid); + if (ib->edid) + return iboot_edid_get_modes(connector); + + /* Without an EDID, the firmware's list. */ + mutex_lock(&ib->lock); + preferred = iboot_preferred(ib); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + struct drm_display_mode *mode; + + if (!t->valid || !iboot_mode_fits(ib, t)) + continue; + mode = drm_cvt_mode(connector->dev, le32_to_cpu(t->width), + le32_to_cpu(t->height), iboot_refresh(t), + false, false, false); + if (!mode) + continue; + if (t == preferred) + mode->type |= DRM_MODE_TYPE_PREFERRED; + drm_mode_probed_add(connector, mode); + count++; + } + mutex_unlock(&ib->lock); + return count; +} + +static enum drm_mode_status +iboot_connector_mode_valid(struct drm_connector *connector, + const struct drm_display_mode *mode) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + + return iboot_find_mode(ib, mode) ? MODE_OK : MODE_NOMODE; +} + +static const struct drm_connector_helper_funcs iboot_connector_helper = { + .get_modes = iboot_connector_get_modes, + .mode_valid = iboot_connector_mode_valid, +}; + +static int iboot_set_mode_locked(struct dcp_iboot *ib, + const struct iboot_timing_mode *t, + const struct iboot_color_mode *c); + +/* With ib->lock held; queued work will observe the cleared pending slot. */ +static void iboot_cancel_swap_locked(struct dcp_iboot *ib) +{ + hrtimer_cancel(&ib->swap_timer); + ib->pending = -1; +} + +/* Read the sink's EDID through the PHY, if it can, and keep it. */ +void dcp_iboot_update_edid(struct dcp_iboot *ib) +{ + const struct drm_edid *edid = NULL; + u8 *buf; + int len; + + if (!ib->disp.phy->read_edid) + return; + buf = kzalloc(4 * EDID_LENGTH, GFP_KERNEL); + if (!buf) + return; + len = ib->disp.phy->read_edid(&ib->disp, buf, 4 * EDID_LENGTH); + if (len >= EDID_LENGTH) { + edid = drm_edid_alloc(buf, len); + if (edid && !drm_edid_valid(edid)) { + drm_edid_free(edid); + edid = NULL; + } + } + if (!edid) + dev_warn(ib->dcp->dev, "no EDID: %d\n", len); + else + dev_info(ib->dcp->dev, "EDID: %d bytes\n", len); + drm_edid_free(ib->edid); + ib->edid = edid; + kfree(buf); +} + +static enum drm_connector_status +iboot_connector_detect(struct drm_connector *connector, bool force) +{ + struct dcp_iboot *ib = to_dcp_iboot(connector->dev); + struct t8152_display *disp = &ib->disp; + struct apple_dcp *dcp = ib->dcp; + enum drm_connector_status status; + bool flipped = false; + int hpd; + + mutex_lock(&ib->lock); + t8152_hdmi_port_poll(disp); + if (disp->hpd_gpio) { + hpd = gpiod_get_value_cansleep(disp->hpd_gpio); + } else if (disp->phy->detect) { + hpd = disp->phy->detect(disp, &flipped); + } else { + status = ib->nr_tmodes ? connector_status_connected : + connector_status_disconnected; + goto out; + } + if (hpd < 0) { + status = connector_status_unknown; + goto out; + } + if (hpd != disp->hpd) { + dev_info(dcp->dev, "sink %s\n", hpd ? "plugged" : "unplugged"); + disp->hpd = hpd; + /* + * USB-C: the DPTX port's HPD follows the port's Type-C state, + * and a new plug may come the other way round. + */ + if (disp->usbc) { + if (!hpd || ib->powered) { + iboot_cancel_swap_locked(ib); + if (t8152_dptx_disconnect(disp, 0)) + dev_err(dcp->dev, "DPTX release failed\n"); + if (!ibootep_set_power(dcp, false)) { + ib->powered = false; + ib->mode_set = false; + disp->phy->deactivate(disp); + } + } + /* + * A plug while the display stayed on (unplug and plug + * between two polls): start the PHY cold again, the + * new plug may come the other way round. + */ + if (hpd) + disp->phy->deactivate(disp); + /* The sink may be on another port now. */ + if (hpd && disp->phy->select) + disp->phy->select(disp); + if (hpd && disp->phy->set_orientation) + disp->phy->set_orientation(disp, flipped); + /* The firmware talks AUX as soon as it sees HPD. */ + if (hpd && disp->phy->activate(disp)) + dev_err(dcp->dev, "PHY activation failed\n"); + if (hpd && t8152_dptx_connect(disp, 0)) + dev_err(dcp->dev, "DPTX connect failed\n"); + if (hpd && t8152_dptx_set_hpd(disp, 0, true)) + dev_err(dcp->dev, "DPTX HPD update failed\n"); + } + /* A new sink: the firmware reads its EDID, take the new lists. */ + if (hpd && (dcp_iboot_wait_hpd(ib) || dcp_iboot_get_modes(ib))) { + dev_err(dcp->dev, "no modes from the new sink\n"); + ib->nr_tmodes = 0; + ib->nr_cmodes = 0; + /* A sleeping EIZO may need its link started anew. */ + if (disp->usbc && !disp->on_hdmi && + time_after(jiffies, ib->relink_time + 60 * HZ)) { + ib->relink_time = jiffies; + schedule_work(&ib->relink_work); + } + } + /* + * The EDID once the firmware has read it, so the sink's DDC + * answers, and before SET_MODE: reading it borrows the AUX path + * while the firmware does no AUX. + */ + if (hpd && ib->nr_tmodes) + dcp_iboot_update_edid(ib); + /* + * A fast reconnect can finish before userspace disables the CRTC. + * Restore its requested state even though unplug powered it off. + */ + if (hpd && ib->enabled && ib->cur_mode.valid) { + const struct iboot_timing_mode *t = NULL; + const struct iboot_color_mode *c = iboot_find_color(ib); + int ret = 0; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *candidate = &ib->tmodes[i]; + + if (candidate->valid && candidate->width == ib->cur_mode.width && + candidate->height == ib->cur_mode.height && + candidate->fps == ib->cur_mode.fps) { + t = candidate; + break; + } + } + if (t && c && !ib->powered) { + ret = ibootep_set_surface(dcp, ib->scan_dva[ib->front], + le32_to_cpu(t->width), + le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (!ret) + ret = ibootep_set_power(dcp, true); + ib->powered = !ret; + } + if (t && c && !ret) + iboot_set_mode_locked(ib, t, c); + } + } + status = hpd && ib->nr_tmodes ? connector_status_connected : + connector_status_disconnected; +out: + mutex_unlock(&ib->lock); + return status; +} + +static const struct drm_connector_funcs iboot_connector_funcs = { + .detect = iboot_connector_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = drm_connector_cleanup, + .reset = drm_atomic_helper_connector_reset, + .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, +}; + +static int iboot_plane_atomic_check(struct drm_plane *plane, + struct drm_atomic_commit *state) +{ + struct drm_plane_state *new = drm_atomic_get_new_plane_state(state, plane); + struct dcp_iboot *ib = to_dcp_iboot(plane->dev); + struct drm_crtc_state *crtc_state = NULL; + u32 width, height; + int ret; + + if (new->crtc) + crtc_state = drm_atomic_get_new_crtc_state(state, new->crtc); + /* The surface fills the whole mode; no scaling or positioning. */ + ret = drm_atomic_helper_check_plane_state(new, crtc_state, + DRM_PLANE_NO_SCALING, + DRM_PLANE_NO_SCALING, + false, false); + if (ret || !new->visible) + return ret; + /* The helper clips src/dst; raw src_w/src_h may exceed the CRTC. */ + if ((new->src.x1 | new->src.y1 | new->src.x2 | new->src.y2) & 0xffff) + return -EINVAL; + width = drm_rect_width(&new->src) >> 16; + height = drm_rect_height(&new->src) >> 16; + return (u64)ALIGN(width * 4, 64) * height <= ib->scan[0].size ? 0 : -EINVAL; +} + +static void iboot_rect_grow(struct drm_rect *r, const struct drm_rect *add) +{ + if (!drm_rect_visible(r)) { + *r = *add; + return; + } + r->x1 = min(r->x1, add->x1); + r->y1 = min(r->y1, add->y1); + r->x2 = max(r->x2, add->x2); + r->y2 = max(r->y2, add->y2); +} + +/* The current mode's refresh period, from its exact 16.16 rate. */ +static s64 iboot_period_ns(struct dcp_iboot *ib) +{ + u32 fps = le32_to_cpu(ib->cur_mode.fps); + + if (fps < (24 << 16)) + fps = 60 << 16; + return div64_u64((u64)NSEC_PER_SEC << 16, fps); +} + +/* Whether a frame may be shown: the display is on, set up and alive. */ +static bool iboot_scanning_locked(struct dcp_iboot *ib) +{ + struct apple_rtkit *rtk = READ_ONCE(ib->dcp->rtk); + + return ib->powered && ib->mode_set && ib->disp.hpd && rtk && + !apple_rtkit_is_crashed(rtk); +} + +/* Show scan[buf]. Called with ib->lock held. */ +static void iboot_swap_locked(struct dcp_iboot *ib, unsigned int buf, u32 w, + u32 h, u32 pitch) +{ + int ret; + + if (!iboot_scanning_locked(ib)) + return; + + /* The pipe must see the whole frame before it is swapped in. */ + wmb(); + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[buf], w, h, pitch); + if (ret) { + /* Still on the old buffer, which misses this frame. */ + dev_err_ratelimited(ib->dcp->dev, "swap failed: %d\n", ret); + ib->stale[ib->front] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + return; + } + ib->last_swap = ktime_get(); + ib->retired[ib->front] = ib->last_swap; + ib->front = buf; +} + +static void iboot_swap_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(work, struct dcp_iboot, swap_work); + + mutex_lock(&ib->lock); + if (ib->pending >= 0) { + iboot_swap_locked(ib, ib->pending, ib->pending_w, + ib->pending_h, ib->pending_pitch); + ib->pending = -1; + } + mutex_unlock(&ib->lock); +} + +static enum hrtimer_restart iboot_swap_timer(struct hrtimer *t) +{ + struct dcp_iboot *ib = container_of(t, struct dcp_iboot, swap_timer); + + queue_work(system_highpri_wq, &ib->swap_work); + return HRTIMER_NORESTART; +} + +/* + * Copy the frame into a scanout buffer that is not on screen and show it. + * That buffer already holds an older frame: copy this frame's damage and + * what changed since that buffer was last written. + * + * SET_SURFACE returns before the pipe takes the buffer at its next frame + * start, and there is no vblank interrupt. Several swaps within one refresh + * let an older frame stay on screen (a cursor that jumps back), so swaps are + * spaced one refresh apart: a frame that comes sooner waits in a pending + * buffer, which a newer frame overwrites, and a timer swaps it in. The + * commit itself never waits, so a client's next frame is not held up. + */ +static void iboot_plane_atomic_update(struct drm_plane *plane, + struct drm_atomic_commit *state) +{ + struct drm_plane_state *old = drm_atomic_get_old_plane_state(state, plane); + struct drm_plane_state *new = drm_atomic_get_new_plane_state(state, plane); + struct drm_shadow_plane_state *shadow = to_drm_shadow_plane_state(new); + struct dcp_iboot *ib = to_dcp_iboot(plane->dev); + struct drm_framebuffer *fb = new->fb; + struct drm_atomic_helper_damage_iter iter; + struct drm_rect clip, source_clip, src, full, damage = { 0, 0, 0, 0 }; + unsigned int pitch, back; + struct iosys_map dst; + s64 period, since; + + if (!fb || !new->visible) + return; + src = DRM_RECT_INIT(new->src.x1 >> 16, new->src.y1 >> 16, + drm_rect_width(&new->src) >> 16, + drm_rect_height(&new->src) >> 16); + full = DRM_RECT_INIT(0, 0, drm_rect_width(&src), drm_rect_height(&src)); + pitch = ALIGN(drm_rect_width(&full) * 4, 64); + drm_atomic_helper_damage_iter_init(&iter, old, new); + drm_atomic_for_each_plane_damage(&iter, &clip) { + if (!drm_rect_intersect(&clip, &src)) + continue; + drm_rect_translate(&clip, -src.x1, -src.y1); + iboot_rect_grow(&damage, &clip); + } + if (!drm_rect_visible(&damage)) + return; + + mutex_lock(&ib->lock); + if (!iboot_scanning_locked(ib)) + goto out; + period = iboot_period_ns(ib); + if (!READ_ONCE(buffered)) { + /* Into the buffer on screen (tears during motion). */ + back = ib->front; + } else if (ib->pending >= 0) { + back = ib->pending; + } else { + /* The other buffer that left the screen first. */ + unsigned int a = (ib->front + 1) % DCP_IBOOT_SCANOUT_BUFS; + unsigned int b = (ib->front + 2) % DCP_IBOOT_SCANOUT_BUFS; + s64 wait; + + back = ktime_before(ib->retired[a], ib->retired[b]) ? a : b; + /* Off screen for a full refresh: only after a mode change. */ + wait = period - ktime_to_ns(ktime_sub(ktime_get(), ib->retired[back])); + if (ib->mode_set && wait > 0) + usleep_range(div_s64(wait, NSEC_PER_USEC), + div_s64(wait, NSEC_PER_USEC) + 100); + } + clip = ib->stale[back]; + iboot_rect_grow(&clip, &damage); + if (drm_rect_intersect(&clip, &full)) { + iosys_map_set_vaddr(&dst, ib->scan_wc[back]); + iosys_map_incr(&dst, drm_fb_clip_offset(pitch, fb->format, &clip)); + source_clip = clip; + drm_rect_translate(&source_clip, src.x1, src.y1); + drm_fb_memcpy(&dst, &pitch, shadow->data, fb, &source_clip); + } + ib->stale[back] = (struct drm_rect){ 0, 0, 0, 0 }; + for (unsigned int i = 0; i < DCP_IBOOT_SCANOUT_BUFS; i++) + if (i != back) + iboot_rect_grow(&ib->stale[i], &damage); + if (back == ib->front) + goto out; + + since = ktime_to_ns(ktime_sub(ktime_get(), ib->last_swap)); + if (ib->pending < 0 && (!ib->mode_set || since >= period)) { + iboot_swap_locked(ib, back, drm_rect_width(&full), + drm_rect_height(&full), pitch); + goto out; + } + ib->pending_w = drm_rect_width(&full); + ib->pending_h = drm_rect_height(&full); + ib->pending_pitch = pitch; + if (ib->pending < 0) { + ib->pending = back; + hrtimer_start(&ib->swap_timer, ktime_add_ns(ib->last_swap, period), + HRTIMER_MODE_ABS); + } +out: + mutex_unlock(&ib->lock); +} + +static const struct drm_plane_helper_funcs iboot_plane_helper = { + DRM_GEM_SHADOW_PLANE_HELPER_FUNCS, + .atomic_check = iboot_plane_atomic_check, + .atomic_update = iboot_plane_atomic_update, +}; + +static const struct drm_plane_funcs iboot_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + DRM_GEM_SHADOW_PLANE_FUNCS, +}; + +static int iboot_crtc_atomic_check(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcp_iboot *ib = to_dcp_iboot(crtc->dev); + + /* No vblank interrupt: the helpers complete events after the flush. */ + new->no_vblank = true; + if (new->enable && !iboot_find_mode(ib, &new->mode)) + return -EINVAL; + return 0; +} + +/* SET_MODE, then the scanout buffer with the new mode's geometry. */ +static int iboot_set_mode_locked(struct dcp_iboot *ib, + const struct iboot_timing_mode *t, + const struct iboot_color_mode *c) +{ + int ret; + + /* + * Right after power on the firmware may still train the link, and it + * fails SET_MODE with an error status until the link is up. It sends + * no message once it is: the DPTX calls it makes while training (link + * configuration, rate, lane count) have no last one, and a sink can + * be trained twice in a row. So SET_MODE is retried. In the traced + * J873g modesets the link was up 76 to 229 ms after power on; one + * failed SET_MODE takes about 200 ms itself, so 200 ms between tries + * cover a second training, and five tries give up after about two + * seconds. On USB-C the DP alt mode reentry below takes over then. + */ + for (int i = 0; i < 5; i++) { + ret = ibootep_set_mode(ib->dcp, t, c); + if (ret != -EIO) + break; + msleep(200); + } + if (ret) { + dev_err(ib->dcp->dev, "set_mode failed: %d\n", ret); + /* + * USB-C: a sink that no longer answers AUX (seen after the + * monitor's deep sleep) is connected anew: its link is + * released, and the plug that follows starts the PHY cold + * and sets the mode again. At most once a minute, so a dead + * sink does not loop. + */ + if (ib->disp.usbc && !ib->disp.on_hdmi && + time_after(jiffies, ib->relink_time + 60 * HZ)) { + ib->cur_mode = *t; + ib->mode_failed = true; + ib->relink_time = jiffies; + schedule_work(&ib->relink_work); + } + return ret; + } + ib->cur_mode = *t; + ib->mode_set = true; + ib->mode_failed = false; + /* The buffers hold the old geometry: the next frame is copied whole. */ + for (unsigned int i = 0; i < DCP_IBOOT_SCANOUT_BUFS; i++) + ib->stale[i] = DRM_RECT_INIT(0, 0, INT_MAX / 2, INT_MAX / 2); + /* A pending frame has the old geometry. */ + iboot_cancel_swap_locked(ib); + /* As the bootloader swaps after a modeset. */ + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[ib->front], + le32_to_cpu(t->width), le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (ret) + dev_err(ib->dcp->dev, "set_surface failed: %d\n", ret); + return ret; +} + +/* + * The boot mode again: a display powered on without SET_MODE counts as idle + * to the firmware's AV stack, which powers the link off after 30 s. + */ +int dcp_iboot_set_boot_mode(struct dcp_iboot *ib) +{ + const struct iboot_timing_mode *best = NULL; + const struct iboot_color_mode *c; + int ret = -ENOENT; + + mutex_lock(&ib->lock); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + const struct iboot_timing_mode *t = &ib->tmodes[i]; + + if (!t->valid || le32_to_cpu(t->width) != ib->boot_w || + le32_to_cpu(t->height) != ib->boot_h || + iboot_refresh(t) > 60) + continue; + if (!best || le32_to_cpu(t->fps) > le32_to_cpu(best->fps)) + best = t; + } + c = iboot_find_color(ib); + if (best && c) + ret = iboot_set_mode_locked(ib, best, c); + mutex_unlock(&ib->lock); + return ret; +} + +/* + * The DCPAV service starts the firmware's idle power off timer when its video + * interface comes up: until a SET_MODE follows, it counts the powered-on + * display as idle and takes the link down 30 s later. The probe's SET_MODE + * comes before the interface starts, so one follows it here. + */ +void dcp_iboot_reset_mode(struct dcp_iboot *ib) +{ + const struct iboot_color_mode *c; + + mutex_lock(&ib->lock); + c = iboot_find_color(ib); + if (c && ib->powered && ib->mode_set) + iboot_set_mode_locked(ib, &ib->cur_mode, c); + mutex_unlock(&ib->lock); +} + +/* + * From the AFK receive work of the DPAV endpoint: let the firmware finish + * opening the interface before the SET_MODE, which waits for a reply that + * another endpoint's receive work completes. + */ +void dcp_iboot_av_started(struct dcp_iboot *ib) +{ + queue_delayed_work(system_percpu_wq, &ib->av_work, msecs_to_jiffies(1000)); +} + +static void iboot_crtc_atomic_enable(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcp_iboot *ib = to_dcp_iboot(crtc->dev); + struct apple_dcp *dcp = ib->dcp; + const struct iboot_timing_mode *t; + const struct iboot_color_mode *c; + int ret; + + mutex_lock(&ib->lock); + t = iboot_find_mode(ib, &new->mode); + c = iboot_find_color(ib); + if (!t || !c) + goto out; + ib->enabled = true; + if (!ib->powered) { + /* The PHY starts cold first; the firmware then trains. */ + ret = ib->disp.phy->activate(&ib->disp); + if (ret) { + dev_err(dcp->dev, "PHY activation failed: %d\n", ret); + goto out; + } + /* A pipe powered on without a surface fetches from a null base. */ + ret = ibootep_set_surface(dcp, ib->scan_dva[ib->front], + le32_to_cpu(t->width), le32_to_cpu(t->height), + ALIGN(le32_to_cpu(t->width) * 4, 64)); + if (ret) { + dev_err(dcp->dev, "set_surface failed: %d\n", ret); + goto out; + } + ret = ibootep_set_power(dcp, true); + if (ret) { + dev_err(dcp->dev, "set_power failed: %d\n", ret); + goto out; + } + ib->powered = true; + } + if (ib->mode_set && !memcmp(t, &ib->cur_mode, sizeof(*t))) + goto out; + dev_info(dcp->dev, "modeset %ux%u@%d\n", le32_to_cpu(t->width), + le32_to_cpu(t->height), iboot_refresh(t)); + /* + * As the bootloader configures a display: query the sink and both mode + * lists again before SET_MODE, and look the mode up in the fresh list. + * The DPTX port stays connected; reconnecting it here drops the link + * and the HDMI firmware then fails SET_MODE. + */ + ret = ibootep_set_power(dcp, true); + if (!ret) + ret = ibootep_get_hpd(dcp, NULL, NULL) < 0; + if (!ret) + ret = dcp_iboot_get_modes(ib); + if (ret) + dev_err(dcp->dev, "refreshing the modes failed: %d\n", ret); + t = iboot_find_mode(ib, &new->mode); + c = iboot_find_color(ib); + if (!t || !c) + goto out; + iboot_set_mode_locked(ib, t, c); +out: + mutex_unlock(&ib->lock); +} + +static void iboot_crtc_atomic_disable(struct drm_crtc *crtc, + struct drm_atomic_commit *state) +{ + struct drm_crtc_state *new = drm_atomic_get_new_crtc_state(state, crtc); + struct dcp_iboot *ib = to_dcp_iboot(crtc->dev); + int ret, idx; + + /* A mode change: SET_MODE alone switches, as before. */ + if (new->active) + return; + /* + * After an unbind the firmware session is retained as it is, and the + * shutdown commit only releases the state. + */ + if (!drm_dev_enter(crtc->dev, &idx)) + return; + /* + * Display off (DPMS, blanking): the firmware stops the pipe and the + * monitor goes to sleep. The next enable sets the mode again. + */ + mutex_lock(&ib->lock); + ib->enabled = false; + iboot_cancel_swap_locked(ib); + if (ib->powered) { + ret = ibootep_set_power(ib->dcp, false); + if (ret) { + dev_err(ib->dcp->dev, "set_power off failed: %d\n", ret); + } else { + dev_info(ib->dcp->dev, "display off\n"); + /* Nothing scans out: power the PHY down as well. */ + if (!ib->disp.phy->deactivate(&ib->disp)) + ib->disp.port[0].link_rate = 0; + } + ib->powered = !!ret; + ib->mode_set = false; + } + mutex_unlock(&ib->lock); + drm_dev_exit(idx); +} + +static const struct drm_crtc_helper_funcs iboot_crtc_helper = { + .atomic_check = iboot_crtc_atomic_check, + .atomic_enable = iboot_crtc_atomic_enable, + .atomic_disable = iboot_crtc_atomic_disable, +}; + +static const struct drm_crtc_funcs iboot_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static const struct drm_encoder_funcs iboot_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + +/* Modeset before the plane update, which copies at the new geometry. */ +static const struct drm_mode_config_helper_funcs iboot_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +}; + +static const struct drm_mode_config_funcs iboot_mode_config_funcs = { + /* fbdev writes reach the scanout buffer through the dirty damage */ + .fb_create = drm_gem_fb_create_with_dirty, + .atomic_check = drm_atomic_helper_check, + .atomic_commit = drm_atomic_helper_commit, +}; + +/* + * Release the link of a USB-C sink that does not answer, and have the port's + * sink plugged again: the port's Type-C state still shows it, so the next + * look at the ports connects it as a new one. + */ +static void iboot_relink_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(work, struct dcp_iboot, relink_work); + struct t8152_display *disp = &ib->disp; + int ret; + + dev_info(ib->dcp->dev, "USB-C sink does not answer, connecting it again\n"); + mutex_lock(&ib->lock); + iboot_cancel_swap_locked(ib); + ret = t8152_dptx_disconnect(disp, 0); + if (!ret) + ret = ibootep_set_power(ib->dcp, false); + if (!ret) { + ib->powered = false; + ib->mode_set = false; + ret = disp->phy->deactivate(disp); + } + if (ret) { + mutex_unlock(&ib->lock); + dev_err(ib->dcp->dev, "cannot release old DP link: %d\n", ret); + return; + } + disp->hpd = 0; + mutex_unlock(&ib->lock); + drm_kms_helper_hotplug_event(&ib->drm); + dcp_iboot_hpd_event(ib); +} + +static void iboot_hpd_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(to_delayed_work(work), struct dcp_iboot, + hpd_work); + + if (!READ_ONCE(ib->ready)) + return; + drm_helper_hpd_irq_event(&ib->drm); + /* + * USB-C changes come from the ports' display switches. The HDMI port's + * HPD line has no interrupt: poll it while this DCP can take the port. + */ + if (READ_ONCE(ib->ready) && ib->disp.hdmi_port) + queue_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(250)); +} + +/* + * A USB-C port's Type-C state changed: look at the ports shortly. A HPD pulse + * the port driver learns of after the fact comes as HPD low and high at once; + * the delay takes both together. + */ +void dcp_iboot_hpd_event(struct dcp_iboot *ib) +{ + if (READ_ONCE(ib->ready)) + mod_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(100)); +} + +void dcp_iboot_kms_stop(struct dcp_iboot *ib) +{ + if (!ib->kms_work_ready) + return; + + cancel_delayed_work_sync(&ib->hpd_work); + hrtimer_cancel(&ib->swap_timer); + cancel_work_sync(&ib->swap_work); + cancel_work_sync(&ib->relink_work); +} + +static void iboot_swap_stop(void *data) +{ + dcp_iboot_kms_stop(data); +} + +int dcp_iboot_kms_init(struct dcp_iboot *ib) +{ + struct drm_device *drm = &ib->drm; + u32 max_w = 3840, max_h = 2160; + int ret; + + ib->pending = -1; + INIT_WORK(&ib->swap_work, iboot_swap_work); + INIT_WORK(&ib->relink_work, iboot_relink_work); + INIT_DELAYED_WORK(&ib->hpd_work, iboot_hpd_work); + hrtimer_setup(&ib->swap_timer, iboot_swap_timer, CLOCK_MONOTONIC, + HRTIMER_MODE_ABS); + ib->kms_work_ready = true; + ret = devm_add_action_or_reset(ib->dcp->dev, iboot_swap_stop, ib); + if (ret) + return ret; + + for (unsigned int i = 0; i < ib->nr_tmodes; i++) { + max_w = max(max_w, le32_to_cpu(ib->tmodes[i].width)); + max_h = max(max_h, le32_to_cpu(ib->tmodes[i].height)); + } + + ret = drmm_mode_config_init(drm); + if (ret) + return ret; + ib->relink_time = jiffies - 61 * HZ; + + drm->mode_config.min_width = 320; + drm->mode_config.min_height = 240; + drm->mode_config.max_width = max_w; + drm->mode_config.max_height = max_h; + drm->mode_config.preferred_depth = 24; + drm->mode_config.funcs = &iboot_mode_config_funcs; + drm->mode_config.helper_private = &iboot_mode_config_helpers; + + ret = drm_universal_plane_init(drm, &ib->plane, 0, &iboot_plane_funcs, + dcp_iboot_formats, ARRAY_SIZE(dcp_iboot_formats), + NULL, DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ret; + drm_plane_helper_add(&ib->plane, &iboot_plane_helper); + drm_plane_enable_fb_damage_clips(&ib->plane); + + ret = drm_crtc_init_with_planes(drm, &ib->crtc, &ib->plane, NULL, + &iboot_crtc_funcs, NULL); + if (ret) + return ret; + drm_crtc_helper_add(&ib->crtc, &iboot_crtc_helper); + + ret = drm_encoder_init(drm, &ib->encoder, &iboot_encoder_funcs, + DRM_MODE_ENCODER_TMDS, NULL); + if (ret) + return ret; + ib->encoder.possible_crtcs = drm_crtc_mask(&ib->crtc); + + ret = drm_connector_init(drm, &ib->connector, &iboot_connector_funcs, + ib->disp.hdmi ? DRM_MODE_CONNECTOR_HDMIA : + DRM_MODE_CONNECTOR_DisplayPort); + if (ret) + return ret; + drm_connector_helper_add(&ib->connector, &iboot_connector_helper); + if (ib->disp.hpd_gpio || ib->disp.usbc) + ib->connector.polled = DRM_CONNECTOR_POLL_CONNECT | + DRM_CONNECTOR_POLL_DISCONNECT; + if (ib->disp.usbc) + ib->connector.polled = DRM_CONNECTOR_POLL_HPD; + ret = drm_connector_attach_encoder(&ib->connector, &ib->encoder); + if (ret) + return ret; + + drm_mode_config_reset(drm); + return 0; +} diff --git a/drivers/gpu/drm/apple/ibootep.c b/drivers/gpu/drm/apple/ibootep.c index 7f90f68bf26f6..1a12fb947d2cc 100644 --- a/drivers/gpu/drm/apple/ibootep.c +++ b/drivers/gpu/drm/apple/ibootep.c @@ -22,9 +22,12 @@ #define IBOOT_PATTERN_STRIDE DCPEXT_STRIDE enum iboot_query_op { + IBOOT_SET_SURFACE = 1, + IBOOT_SET_POWER = 2, IBOOT_GET_HPD = 3, IBOOT_GET_TIMING_MODES = 4, IBOOT_GET_COLOR_MODES = 5, + IBOOT_SET_MODE = 6, }; /* Packed layouts from m1n1 src/dcp_iboot.h and swap_set_layer_cmd_v13_3. */ @@ -148,15 +151,25 @@ static int iboot_parse_swap_begin(const u8 *reply, size_t received, u32 *id) return 0; } -static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) +/* A mode list: a count, then as many 24-byte records. */ +static int iboot_parse_mode_count(const u8 *payload, size_t size, u32 *count) { - u32 i; - if (size < 4) return -EPROTO; *count = get_unaligned_le32(payload); if (*count > (size - 4) / IBOOT_MODE_SIZE) return -EPROTO; + return 0; +} + +static int iboot_parse_modes(const u8 *payload, size_t size, u32 *count) +{ + u32 i; + int ret; + + ret = iboot_parse_mode_count(payload, size, count); + if (ret) + return ret; for (i = 0; i < *count; i++) if (get_unaligned_le32(payload + 4 + i * IBOOT_MODE_SIZE) > 1) return -EPROTO; @@ -234,7 +247,13 @@ static int iboot_build_pattern_request(u32 op, const void *data, size_t data_siz size_t expected; switch (op) { + case 1: /* SetSurface */ + expected = sizeof(struct iboot_layer); + break; case 2: expected = 1; break; /* SetPower */ + case 3 ... 5: /* GetHPD, GetTimingModes, GetColorModes */ + expected = 0; + break; case 6: expected = 2 * IBOOT_MODE_SIZE; break; /* SetMode */ case 15: expected = 0; break; /* SwapBegin */ case 16: expected = sizeof(struct iboot_swap_layer_v13_3); break; @@ -401,7 +420,7 @@ static struct iboot_query *iboot_find_query(struct apple_dcp *dcp) struct apple_dcp_afkep *ep = READ_ONCE(dcp->ibootep); u32 i; - if (!dcp->external || !ep) + if ((!dcp->external && !dcp_is_iboot(dcp)) || !ep) return ERR_PTR(-ENODEV); for (i = 0; i < AFK_MAX_CHANNEL; i++) { struct iboot_query *query = smp_load_acquire(&ep->services[i].cookie); @@ -668,6 +687,157 @@ int ibootep_present_pattern(struct apple_dcp *dcp, u64 iova, size_t size, u32 st return ret; } +/* + * One display command of the iBoot interface, with its reply payload copied + * to @out (at least @min_size bytes of it; returns the bytes copied), or a + * setter if @out is NULL. On AFKv2 the setters answer with a transport + * status alone: given a reply buffer, the firmware copies an empty reply + * into it and asserts, so they go out without one. Only the reply's own + * length is checked, not that its first word repeats @op. + */ +static int iboot_command(struct apple_dcp *dcp, u32 op, const void *data, + size_t size, void *out, size_t out_size, size_t min_size) +{ + struct iboot_query *query = iboot_find_query(dcp); + u8 request[16 + sizeof(struct iboot_swap_layer_v13_3)]; + size_t len, received = 0; + u32 retcode = 0, reply_len; + u8 *reply = NULL; + int ret; + + if (IS_ERR(query)) + return PTR_ERR(query); + ret = iboot_build_pattern_request(op, data, size, request, + sizeof(request), &len); + if (ret) + return ret; + if (out || !query->service->ep->wire_v2) { + reply = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); + if (!reply) + return -ENOMEM; + } + ret = afk_send_command_len(query->service, EPIC_SUBTYPE_STD_SERVICE, + request, len, reply, + reply ? IBOOT_QUERY_RX_SIZE : 0, &retcode, + &received); + if (!ret && retcode) { + dev_dbg(dcp->dev, "iBoot command %u returned %#x\n", op, retcode); + ret = -EIO; + } + if (ret || !out) + goto out; + reply_len = received >= 8 ? get_unaligned_le32(reply + 4) : 0; + if (reply_len < 8 || reply_len > received || reply_len - 8 < min_size) { + dev_err(dcp->dev, "iBoot: bad response length for command %u\n", op); + ret = -EPROTO; + goto out; + } + ret = min_t(size_t, reply_len - 8, out_size); + memcpy(out, reply + 8, ret); +out: + kfree(reply); + return ret; +} + +int ibootep_set_power(struct apple_dcp *dcp, bool on) +{ + u8 power = on; + + return iboot_command(dcp, IBOOT_SET_POWER, &power, sizeof(power), NULL, + 0, 0); +} + +int ibootep_get_hpd(struct apple_dcp *dcp, u32 *timings, u32 *colors) +{ + u8 payload[12]; + u32 timing_count, color_count; + bool hpd; + int ret; + + ret = iboot_command(dcp, IBOOT_GET_HPD, NULL, 0, payload, sizeof(payload), + sizeof(payload)); + if (ret >= 0) + ret = iboot_parse_hpd(payload, ret, &hpd, &timing_count, + &color_count); + if (ret) + return ret; + if (timings) + *timings = timing_count; + if (colors) + *colors = color_count; + return hpd; +} + +static int iboot_get_modes(struct apple_dcp *dcp, u32 op, void **modes, + unsigned int *count) +{ + u32 n; + u8 *buf; + int ret; + + buf = kzalloc(IBOOT_QUERY_RX_SIZE, GFP_KERNEL); + if (!buf) + return -ENOMEM; + ret = iboot_command(dcp, op, NULL, 0, buf, IBOOT_QUERY_RX_SIZE, 4); + if (ret >= 0) + ret = iboot_parse_mode_count(buf, ret, &n); + if (!ret) { + *modes = kmemdup(buf + 4, n * IBOOT_MODE_SIZE, GFP_KERNEL); + if (*modes) + *count = n; + else + ret = -ENOMEM; + } + kfree(buf); + return ret; +} + +int ibootep_get_timing_modes(struct apple_dcp *dcp, + struct iboot_timing_mode **modes, + unsigned int *count) +{ + return iboot_get_modes(dcp, IBOOT_GET_TIMING_MODES, (void **)modes, count); +} + +int ibootep_get_color_modes(struct apple_dcp *dcp, + struct iboot_color_mode **modes, unsigned int *count) +{ + return iboot_get_modes(dcp, IBOOT_GET_COLOR_MODES, (void **)modes, count); +} + +int ibootep_set_mode(struct apple_dcp *dcp, const struct iboot_timing_mode *timing, + const struct iboot_color_mode *color) +{ + struct { + struct iboot_timing_mode timing; + struct iboot_color_mode color; + } __packed mode = { *timing, *color }; + + return iboot_command(dcp, IBOOT_SET_MODE, &mode, sizeof(mode), NULL, 0, 0); +} + +int ibootep_set_surface(struct apple_dcp *dcp, u64 iova, u32 width, u32 height, + u32 stride) +{ + /* One linear BGRA plane, SDR, in colour space 2 as the bootloader sets. */ + struct iboot_layer layer = { + .planes = { { + .addr = cpu_to_le64(iova), + .stride = cpu_to_le32(stride), + .addr_format = cpu_to_le32(1), + } }, + .plane_count = cpu_to_le32(1), + .width = cpu_to_le32(width), + .height = cpu_to_le32(height), + .surface_format = cpu_to_le32(1), + .colorspace = cpu_to_le32(2), + .eotf = cpu_to_le32(1), + }; + + return iboot_command(dcp, IBOOT_SET_SURFACE, &layer, sizeof(layer), NULL, + 0, 0); +} + static ssize_t dcpext_modes_query_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) @@ -699,7 +869,7 @@ static void disp_service_init(struct apple_epic_service *service, const char *na struct iboot_query *query; int ret; - if (!dcp->external) + if (!dcp->external && !dcp_is_iboot(dcp)) return; query = devm_kzalloc(dcp->dev, sizeof(*query), GFP_KERNEL); if (!query) @@ -710,6 +880,16 @@ static void disp_service_init(struct apple_epic_service *service, const char *na ret = devm_add_action_or_reset(dcp->dev, iboot_query_cancel, query); if (ret) return; + /* + * A DCP driven through this interface alone has a display driver that + * sends every command (the exported ibootep_* calls); it takes no + * manual queries next to them. + */ + if (dcp_is_iboot(dcp)) { + /* Published for iboot_find_query()'s acquire. */ + smp_store_release(&service->cookie, query); + return; + } /* Remove the sysfs entry before cancelling work during device cleanup. */ ret = devm_device_add_group(dcp->dev, &iboot_query_group); if (ret) { @@ -741,6 +921,19 @@ static const struct apple_epic_service_ops external_ibootep_ops[] = { {} }; +/* DCP_FIRMWARE_IBOOT: the main DCP's service, or an external one's. */ +static const struct apple_epic_service_ops iboot_variant_ops[] = { + { + .name = "disp0-service", + .init = disp_service_init, + }, + { + .name = "dispext-service", + .init = disp_service_init, + }, + {} +}; + int ibootep_init(struct apple_dcp *dcp) { const struct apple_epic_service_ops *ops = ibootep_ops; @@ -751,6 +944,8 @@ int ibootep_init(struct apple_dcp *dcp) return -EBUSY; if (dcp->hw.iomfb_method_profile == DCP_IOMFB_METHODS_H17P_EXTERNAL) ops = external_ibootep_ops; + if (dcp_is_iboot(dcp)) + ops = iboot_variant_ops; dcp->ibootep = afk_init(dcp, DISP0_ENDPOINT, ops); if (IS_ERR(dcp->ibootep)) { ret = PTR_ERR(dcp->ibootep); diff --git a/drivers/gpu/drm/apple/ibootep.h b/drivers/gpu/drm/apple/ibootep.h index aa44c2f8754e4..aa6ad17a61be1 100644 --- a/drivers/gpu/drm/apple/ibootep.h +++ b/drivers/gpu/drm/apple/ibootep.h @@ -27,4 +27,42 @@ int ibootep_rearm_pattern(struct apple_dcp *dcp); */ int ibootep_present_frame(struct apple_dcp *dcp, u64 iova, size_t size, u32 stride); +/* + * The iBoot interface's display commands, for a DCP driven through it + * (DCP_FIRMWARE_IBOOT) and for the T6030 external role. Sleepable callers + * outside the AFK receive queue; the caller serializes them. + */ +struct iboot_timing_mode { + __le32 valid; + __le32 width; + __le32 height; + __le32 fps; /* 16.16 */ + /* byte 0 bit 6: a standard mode the firmware adds on its own */ + u8 flags[8]; +} __packed; + +struct iboot_color_mode { + __le32 valid; + __le32 colorimetry; + __le32 eotf; + __le32 encoding; + __le32 bpp; + u8 pad[4]; +} __packed; + +int ibootep_set_power(struct apple_dcp *dcp, bool on); +/* 1 with a sink, 0 without; the counts of its timing and colour modes. */ +int ibootep_get_hpd(struct apple_dcp *dcp, u32 *timings, u32 *colors); +/* The sink's mode lists, newly allocated; the caller frees them. */ +int ibootep_get_timing_modes(struct apple_dcp *dcp, + struct iboot_timing_mode **modes, + unsigned int *count); +int ibootep_get_color_modes(struct apple_dcp *dcp, + struct iboot_color_mode **modes, unsigned int *count); +int ibootep_set_mode(struct apple_dcp *dcp, const struct iboot_timing_mode *timing, + const struct iboot_color_mode *color); +/* SET_SURFACE: scan out one linear BGRA plane at @iova. */ +int ibootep_set_surface(struct apple_dcp *dcp, u64 iova, u32 width, u32 height, + u32 stride); + #endif diff --git a/drivers/gpu/drm/apple/iomfb_iboot.c b/drivers/gpu/drm/apple/iomfb_iboot.c new file mode 100644 index 0000000000000..df308b133a39a --- /dev/null +++ b/drivers/gpu/drm/apple/iomfb_iboot.c @@ -0,0 +1,843 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * DCP_FIRMWARE_IBOOT: the T8152 DCPs, driven through their firmware's + * iBoot interface alone. + * + * The bootloader leaves a successful display's RTKit session running, or + * quiesces it after a failed setup, and leaves an unused DCPEXT's firmware + * loaded and waiting for an RTKit wake (apple,rtkit-wake). This adopts or + * wakes that session, stops the AFK endpoints the bootloader left running + * and starts the iBoot (disp0-service or dispext-service), DPAV and DPTX + * port endpoints, reconnects the DPTX port and asserts HPD, then registers + * a DRM device whose flips are iBoot SET_SURFACE calls (iboot_drm.c), in + * the order the bootloader brings the display up. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include "afk.h" +#include "dcp.h" +#include "dcp-internal.h" +#include "ibootep.h" +#include "iomfb_iboot.h" +#include "t8152_display.h" + +#define DCP_IBOOT_HPD_TIMEOUT_MS 10000 +/* RTKit's oslog system endpoint */ +#define DCP_IBOOT_RTKIT_EP_OSLOG 8 +/* The coprocessor's CPU control (bit 4: run) and status registers */ +#define DCP_IBOOT_CPU_CONTROL 0x44 +#define DCP_IBOOT_CPU_CONTROL_RUN BIT(4) +#define DCP_IBOOT_CPU_STATUS 0x48 + +static void dcp_iboot_rtk_crashed(void *cookie, const void *crashlog, size_t size) +{ + struct apple_dcp *dcp = cookie; + + WRITE_ONCE(dcp->crashed, true); + dev_err(dcp->dev, "DCP firmware crashed\n"); +} + +static void dcp_iboot_rtk_recv(void *cookie, u8 endpoint, u64 message) +{ + struct apple_dcp *dcp = cookie; + struct apple_dcp_afkep *ep = NULL; + + if (READ_ONCE(dcp->quiescing)) + return; + switch (endpoint) { + case DISP0_ENDPOINT: + ep = READ_ONCE(dcp->ibootep); + break; + case DPTX_CONTROLLER_ENDPOINT: + ep = READ_ONCE(dcp->dptx_controller_ep); + break; + case DPTX_ENDPOINT: + ep = READ_ONCE(dcp->dptxep); + break; + } + if (IS_ERR_OR_NULL(ep)) { + dev_dbg(dcp->dev, "message %#llx for idle endpoint %#x\n", + message, endpoint); + return; + } + afk_receive_message(ep, message); +} + +/* + * Buffers the firmware placed in its own DART mappings, or new ones, as for + * every DCP; and a woken DCPEXT's oslog ring. + */ +static int dcp_iboot_rtk_shmem_setup(void *cookie, u8 endpoint, + struct apple_rtkit_shmem *bfr) +{ + struct apple_dcp *dcp = cookie; + + /* + * A woken DCPEXT offers the oslog ring in its own firmware segment, at + * an address only the firmware's retained DART tables map. Linux never + * reads that ring and only acknowledges its write counters: take it as + * the firmware's, without a CPU mapping. The request needs no reply; + * the bootloader sends none either. + */ + if (bfr->iova && endpoint == DCP_IBOOT_RTKIT_EP_OSLOG) { + struct iommu_domain *domain = iommu_get_domain_for_dev(dcp->dev); + + if (domain && !iommu_iova_to_phys(domain, bfr->iova)) { + bfr->is_mapped = true; + return 0; + } + } + return dcp_rtk_shmem_setup(cookie, bfr); +} + +static void dcp_iboot_rtk_shmem_destroy(void *cookie, struct apple_rtkit_shmem *bfr) +{ + /* The firmware's oslog ring, taken without a mapping */ + if (bfr->is_mapped && !bfr->buffer) + return; + dcp_rtk_shmem_destroy(cookie, bfr); +} + +static bool dcp_iboot_rtk_syslog_debug(void *cookie, const char *context, + const char *message) +{ + /* Surface logging through fbcon would itself submit another surface. */ + return strstr(message, "setSurfaceRequest") || + strstr(message, "swap_submit_dcp") || + strstr(message, "validateRequest: inSize"); +} + +static const struct apple_rtkit_ops dcp_iboot_rtkit_ops = { + .crashed = dcp_iboot_rtk_crashed, + .recv_message = dcp_iboot_rtk_recv, + .shmem_setup_ep = dcp_iboot_rtk_shmem_setup, + .shmem_destroy = dcp_iboot_rtk_shmem_destroy, + .syslog_is_debug = dcp_iboot_rtk_syslog_debug, +}; + +static bool dcp_iboot_handoff_quiesced(struct dcp_iboot *ib) +{ + struct device_node *chosen __free(device_node) = of_find_node_by_path("/chosen"); + const char *version; + u32 running; + + if (ib->disp.hdmi || !chosen) + return false; + if (!of_property_read_u32(chosen, "apple,dcp-rtkit-running", &running)) + return running == 0; + /* + * This older J873 loader predates the state property. Its failed + * display setup quiesces DCP and keeps iBoot's placeholder framebuffer; + * a successful setup hands over ON. Restrict this fallback to the + * verified loader build, rather than guessing for other handoffs. + */ + if (of_property_read_string(chosen, "asahi,m1n1-stage2-version", &version) || + strcmp(version, "v0.1.0-259-ga30a589a")) + return false; + for_each_child_of_node_scoped(chosen, np) { + u32 width, height; + + if (of_device_is_compatible(np, "simple-framebuffer") && + !of_property_read_u32(np, "width", &width) && + !of_property_read_u32(np, "height", &height)) + return width == 640 && height == 1136; + } + return false; +} + +/* The unused DCPEXT firmware is loaded and powered by iBoot. */ +static int dcp_iboot_check_wake(struct apple_dcp *dcp) +{ + struct platform_device *pdev = to_platform_device(dcp->dev); + struct resource *res; + void __iomem *psd, *coproc; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "coproc-psd"); + if (!res) + return -EINVAL; + psd = devm_ioremap(dcp->dev, res->start, resource_size(res)); + if (!psd) + return -ENOMEM; + /* A read from the coprocessor while gated hangs the machine. */ + if (readl(psd + 0x80) & 7) + return -ENODEV; + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "coproc"); + if (!res) + return -EINVAL; + coproc = devm_ioremap(dcp->dev, res->start, resource_size(res)); + if (!coproc) + return -ENOMEM; + dev_info(dcp->dev, "firmware handoff: CPU control %#x status %#x\n", + readl(coproc + DCP_IBOOT_CPU_CONTROL), + readl(coproc + DCP_IBOOT_CPU_STATUS)); + return (readl(coproc + DCP_IBOOT_CPU_CONTROL) & + DCP_IBOOT_CPU_CONTROL_RUN) ? 0 : -ENODEV; +} + +/* + * Wake only a quiesced session: IOP INIT on a running DCP can panic it. A + * running one is taken as it runs, without the HELLO/EPMAP handshake; + * its AFK endpoints are then registered as they start (hw.afk_adopt_endpoints). + */ +static int dcp_iboot_boot(struct dcp_iboot *ib) +{ + struct apple_dcp *dcp = ib->dcp; + bool wake = of_property_read_bool(dcp->dev->of_node, "apple,rtkit-wake"); + struct apple_rtkit *rtk; + int ret; + + if ((!ib->disp.hdmi && wake) || dcp_iboot_handoff_quiesced(ib)) { + if (wake) { + ret = dcp_iboot_check_wake(dcp); + if (ret) + return ret; + } + rtk = apple_rtkit_init(dcp->dev, dcp, NULL, 0, &dcp_iboot_rtkit_ops); + if (IS_ERR(rtk)) + return PTR_ERR(rtk); + dcp->rtk = rtk; + ret = apple_rtkit_wake(rtk); + dev_info(dcp->dev, "quiesced DCP wake: %d\n", ret); + return ret; + } + rtk = apple_rtkit_init_adopted(dcp->dev, dcp, NULL, 0, &dcp_iboot_rtkit_ops); + if (IS_ERR(rtk)) + return PTR_ERR(rtk); + dcp->rtk = rtk; + return apple_rtkit_adopt_running(rtk); +} + +/* + * The display pipe scans out through dart-disp0, the DCP fetches through + * dart-dcp. Both are locked with their own live root, so each needs its own + * device and domain: one domain spanning both would publish dart-dcp's root + * into dart-disp0 and drop the scanout mappings the bootloader left there + * (the pipe then faults, IOMFB axi_rd_err). Scanout buffers are allocated on + * the DCP device and mapped into the scanout domain at the same address. + */ +static int dcp_iboot_scanout_init(struct dcp_iboot *ib) +{ + struct device *dev = ib->dcp->dev; + struct device_node *np __free(device_node) = + of_get_child_by_name(dev->of_node, "scanout"); + int ret; + + if (!np) + return -ENODEV; + ib->scanout = of_platform_device_create(np, NULL, dev); + if (!ib->scanout) + ib->scanout = of_find_device_by_node(np); + if (!ib->scanout) + return -ENODEV; + ret = dma_set_mask_and_coherent(&ib->scanout->dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + ret = of_dma_configure(&ib->scanout->dev, np, true); + if (ret) + return ret; + ib->scanout_dom = iommu_get_domain_for_dev(&ib->scanout->dev); + return ib->scanout_dom ? 0 : -ENODEV; +} + +/* Firmware-visible memory: never freed, the firmware may still use it. */ +static int dcp_iboot_dma_alloc(struct dcp_iboot *ib, struct dcp_iboot_dma *dma, + size_t size) +{ + dma->size = PAGE_ALIGN(size); + dma->cpu = dma_alloc_coherent(ib->dcp->dev, dma->size, &dma->iova, + GFP_KERNEL); + return dma->cpu ? 0 : -ENOMEM; +} + +static void *dcp_iboot_vmap_wc(struct sg_table *sgt) +{ + unsigned int n = 0, count = 0; + struct sg_page_iter iter; + struct page **pages; + void *vaddr; + + for_each_sgtable_page(sgt, &iter, 0) + count++; + pages = kvmalloc_array(count, sizeof(*pages), GFP_KERNEL); + if (!pages) + return NULL; + for_each_sgtable_page(sgt, &iter, 0) + pages[n++] = sg_page_iter_page(&iter); + vaddr = vmap(pages, count, VM_MAP, pgprot_writecombine(PAGE_KERNEL)); + kvfree(pages); + return vaddr; +} + +/* + * The display pipe's DART is locked and comes with the firmware's own + * mappings. The address the coprocessor's allocator handed out for a scanout + * buffer can be one of them, and mapping over it corrupts what the pipe + * fetches every frame (the picture flickers). Start at @dva and go down until + * a range with no mapping is found. + */ +static dma_addr_t dcp_iboot_scan_free_dva(struct dcp_iboot *ib, dma_addr_t dva, + size_t size) +{ + const size_t step = SZ_16K; + + size = ALIGN(size, step); + for (int tries = 0; tries < 64 && dva >= size; tries++) { + size_t off; + + for (off = 0; off < size; off += step) + if (iommu_iova_to_phys(ib->scanout_dom, dva + off)) + break; + if (off == size) + return dva; + dev_info(ib->dcp->dev, "scanout DART: %pad+%#zx is in use, moving down\n", + &dva, off); + dva -= size; + } + return 0; +} + +/* One scanout buffer: allocated, cleared, mapped for the CPU and the pipe. */ +static int dcp_iboot_scan_alloc(struct dcp_iboot *ib, int i, size_t size) +{ + struct dcp_iboot_dma *fb = &ib->scan[i]; + struct sg_table sgt; + ssize_t mapped; + dma_addr_t dva; + int ret; + + ret = dcp_iboot_dma_alloc(ib, fb, size); + if (ret) + return ret; + ret = dma_get_sgtable(ib->dcp->dev, &sgt, fb->cpu, fb->iova, fb->size); + if (ret) + return ret; + /* + * The DCP is coherent, the display pipe is not: it reads memory past + * the CPU caches, and frames written through the cacheable mapping + * show only once evicted. Write through a write-combined mapping of + * the same pages, with the zeroing of the allocation cleaned out first. + */ + arch_wb_cache_pmem(fb->cpu, fb->size); + ib->scan_wc[i] = dcp_iboot_vmap_wc(&sgt); + if (!ib->scan_wc[i]) { + sg_free_table(&sgt); + return -ENOMEM; + } + memset(ib->scan_wc[i], 0, fb->size); + /* + * Cacheable, as the bootloader maps scanout buffers: the pipe faults on + * entries with the DART's no-cache bit (IOMFB axi_rd_err). + */ + dva = dcp_iboot_scan_free_dva(ib, fb->iova, fb->size); + if (!dva) { + sg_free_table(&sgt); + return -ENOSPC; + } + mapped = iommu_map_sgtable(ib->scanout_dom, dva, &sgt, + IOMMU_READ | IOMMU_WRITE | IOMMU_CACHE); + sg_free_table(&sgt); + if (mapped < (ssize_t)fb->size) + return mapped < 0 ? mapped : -ENOMEM; + ib->scan_dva[i] = dva; + dev_info(ib->dcp->dev, "scanout buffer %d: %zu bytes at %pad\n", i, + fb->size, &dva); + return 0; +} + +/* + * A fresh iBoot session has no surface. Whenever the pipe runs without one + * (the link retrains when the DPTX services restart, SET_MODE turns it on), + * it fetches from a null base and the firmware takes an NMI (IOMFB + * axi_rd_err). Hand it a black buffer of the boot mode at once, sized from + * the bootloader's simple-framebuffer. + */ +static int dcp_iboot_boot_surface(struct dcp_iboot *ib) +{ + /* + * The boot display's framebuffer is /chosen's; the bootloader adds the + * second display's (HDMI) at the root. + */ + struct device_node *chosen __free(device_node) = + of_find_node_by_path("/chosen"); + struct device_node *parent __free(device_node) = + ib->disp.dp_source ? + of_find_node_by_path("/") : of_node_get(chosen); + u32 width = 1280, height = 720, stride = 1280 * 4; + size_t size; + int ret; + + for_each_child_of_node_scoped(parent, np) { + struct resource res; + + if (!of_device_is_compatible(np, "simple-framebuffer")) + continue; + of_property_read_u32(np, "width", &width); + of_property_read_u32(np, "height", &height); + of_property_read_u32(np, "stride", &stride); + /* + * Take the display over from simpledrm on the bootloader's + * framebuffer, so it does not shadow this driver's output + * (fbcon on a framebuffer nothing scans out). + */ + if (!of_address_to_resource(np, 0, &res)) { + ret = aperture_remove_conflicting_devices(res.start, + resource_size(&res), + dcp_iboot_driver_name()); + if (ret) + dev_warn(ib->dcp->dev, "simpledrm stays: %d\n", ret); + } + break; + } + /* + * Large enough for the largest mode: while a SET_MODE switches, the + * pipe briefly scans the current surface with the new mode's size. + * A monitor may first appear after probe, with a larger mode list. + */ + size = max_t(size_t, (size_t)stride * height, 3840 * 2160 * 4); + for (unsigned int i = 0; i < ib->nr_tmodes; i++) + size = max_t(size_t, size, (size_t)le32_to_cpu(ib->tmodes[i].width) * + le32_to_cpu(ib->tmodes[i].height) * 4); + ib->boot_w = width; + ib->boot_h = height; + ib->boot_stride = stride; + for (int i = 0; i < ARRAY_SIZE(ib->scan); i++) { + ret = dcp_iboot_scan_alloc(ib, i, size); + if (ret) + return ret; + } + ib->front = 0; + ret = ibootep_set_surface(ib->dcp, ib->scan_dva[0], width, height, stride); + dev_info(ib->dcp->dev, "boot surface %ux%u at %pad: %d\n", width, height, + &ib->scan_dva[0], ret); + return ret; +} + +/* Both mode lists of the current sink; a list is kept when its query fails. */ +int dcp_iboot_get_modes(struct dcp_iboot *ib) +{ + struct iboot_timing_mode *tmodes; + struct iboot_color_mode *cmodes; + unsigned int count; + int ret; + + ret = ibootep_get_timing_modes(ib->dcp, &tmodes, &count); + if (ret) + return ret; + kfree(ib->tmodes); + ib->tmodes = tmodes; + ib->nr_tmodes = count; + ret = ibootep_get_color_modes(ib->dcp, &cmodes, &count); + if (ret) + return ret; + kfree(ib->cmodes); + ib->cmodes = cmodes; + ib->nr_cmodes = count; + return 0; +} + +/* + * Wait until the firmware reports a sink with modes, as the bootloader does. + * Nothing on the iBoot interface announces the sink, so GET_HPD is asked + * every 100 ms; the J873g ports took 268 to 328 ms after power on. + */ +int dcp_iboot_wait_hpd(struct dcp_iboot *ib) +{ + unsigned long timeout = jiffies + msecs_to_jiffies(DCP_IBOOT_HPD_TIMEOUT_MS); + u32 timings = 0, colors = 0; + int hpd; + + do { + hpd = ibootep_get_hpd(ib->dcp, &timings, &colors); + if (hpd > 0 && timings && colors) { + dev_info(ib->dcp->dev, "sink: %u timing, %u color modes\n", + timings, colors); + return 0; + } + msleep(100); + } while (time_before(jiffies, timeout)); + + dev_err(ib->dcp->dev, "no sink (hpd %d, %u timing, %u color modes)\n", hpd, + timings, colors); + return hpd < 0 ? hpd : -ENODEV; +} + +static void dcp_iboot_av_work(struct work_struct *work) +{ + struct dcp_iboot *ib = container_of(to_delayed_work(work), struct dcp_iboot, + av_work); + + if (READ_ONCE(ib->ready)) + dcp_iboot_reset_mode(ib); +} + +/* + * The DPAV controller endpoint's services take no host commands, but the + * firmware expects all of them opened: its video interface powers the + * display on and starts its idle power off timer, so SET_MODE follows once + * that one is up. + */ +static void dcp_iboot_dpav_init(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + struct dcp_iboot *ib = READ_ONCE(service->ep->dcp->iboot); + + if (ib && name && strstr(name, "dcpav-video-interface")) + dcp_iboot_av_started(ib); +} + +static const struct apple_epic_service_ops dcp_iboot_dpav_ops = { + .name = "dcpav", + .reusable = true, + .init = dcp_iboot_dpav_init, +}; + +static unsigned int dcp_iboot_ep_services(struct apple_dcp_afkep *ep) +{ + unsigned int count = 0; + + for (unsigned int i = 0; i < AFK_MAX_CHANNEL; i++) + count += READ_ONCE(ep->services[i].enabled); + return count; +} + +/* + * The endpoint's services as it announces them, up to @expected within the + * AFK timeout; none is an error, fewer a warning. + */ +static int dcp_iboot_wait_services(struct apple_dcp *dcp, + struct apple_dcp_afkep *ep, unsigned int expected) +{ + unsigned int count; + + wait_event_timeout(ep->service_wq, dcp_iboot_ep_services(ep) >= expected, + msecs_to_jiffies(dcp->hw.afk_timeout_ms)); + count = dcp_iboot_ep_services(ep); + if (!count) { + dev_err(dcp->dev, "endpoint %#x announced no service\n", ep->endpoint); + return -ETIMEDOUT; + } + if (count < expected) + dev_warn(dcp->dev, "endpoint %#x: %u of %u services\n", ep->endpoint, + count, expected); + return 0; +} + +static int dcp_iboot_start_ep(struct apple_dcp *dcp, u32 endpoint, + struct apple_dcp_afkep **slot, + const struct apple_epic_service_ops *ops, + unsigned int expected) +{ + struct apple_dcp_afkep *ep = afk_init(dcp, endpoint, NULL); + int ret; + + if (IS_ERR(ep)) + return PTR_ERR(ep); + ep->unmatched_ops = ops; + WRITE_ONCE(*slot, ep); + ret = afk_start(ep); + if (ret) { + dev_err(dcp->dev, "endpoint %#x did not start: %d\n", endpoint, ret); + return ret; + } + return dcp_iboot_wait_services(dcp, ep, expected); +} + +/* The iBoot service is ready once its init callback has run. */ +static int dcp_iboot_start_iboot(struct apple_dcp *dcp) +{ + int ret; + + ret = ibootep_init(dcp); + if (ret) + return ret; + wait_event_timeout(dcp->ibootep->service_wq, ibootep_is_ready(dcp), + msecs_to_jiffies(dcp->hw.afk_timeout_ms)); + return ibootep_is_ready(dcp) ? 0 : -ENODEV; +} + +/* + * Once adopted, the DCP may still DMA into our buffers. Stop the host side: + * no more endpoint work or messages, no KMS work, and RTKit detached with + * its buffers retained. Firmware-visible storage stays allocated until + * reboot. + */ +static void dcp_iboot_detach(struct dcp_iboot *ib) +{ + struct apple_dcp *dcp = ib->dcp; + + WRITE_ONCE(ib->ready, false); + WRITE_ONCE(dcp->quiescing, true); + cancel_delayed_work_sync(&ib->av_work); + dcp_iboot_kms_stop(ib); + afk_quiesce(dcp->ibootep); + afk_quiesce(dcp->dptx_controller_ep); + afk_quiesce(dcp->dptxep); + if (!IS_ERR_OR_NULL(dcp->rtk)) + apple_rtkit_free_retaining_buffers(dcp->rtk); + WRITE_ONCE(dcp->rtk, NULL); +} + +static int dcp_iboot_start(struct dcp_iboot *ib) +{ + struct t8152_display *disp = &ib->disp; + struct apple_dcp *dcp = ib->dcp; + struct device *dev = dcp->dev; + bool sink = true; + int ret; + + ret = dcp_iboot_start_iboot(dcp); + if (ret) + return dev_err_probe(dev, ret, "no disp0-service\n"); + /* + * The new iBoot session has dropped the surface while the pipe still + * runs: it fetches from a null base (IOMFB axi_rd_err, firmware NMI) + * unless it is powered off at once. It comes back on below, after a + * surface is set. + */ + ret = ibootep_set_power(dcp, false); + if (ret) + return dev_err_probe(dev, ret, "display power off failed\n"); + ret = dcp_iboot_start_ep(dcp, DPTX_CONTROLLER_ENDPOINT, + &dcp->dptx_controller_ep, &dcp_iboot_dpav_ops, 4); + if (ret) + return dev_err_probe(dev, ret, "no DPAV controllers\n"); + ret = dcp_iboot_start_ep(dcp, DPTX_ENDPOINT, &dcp->dptxep, + &t8152_dptx_port_ops, 2); + if (ret) + return dev_err_probe(dev, ret, "no DPTX port service\n"); + if (disp->usbc) { + ret = t8152_dptx_disconnect(disp, 0); + if (ret) + return dev_err_probe(dev, ret, "cannot release inherited DP link\n"); + } + + /* + * USB-C negotiation can outlive probe or fail while a monitor sleeps. + * Register the connector first; the hotplug path owns all USB-C links. + */ + if (disp->usbc) + sink = false; + if (sink) { + ret = t8152_dptx_connect(disp, 0); + if (ret) + return dev_err_probe(dev, ret, "DPTX connect failed\n"); + ret = t8152_dptx_set_hpd(disp, 0, true); + if (ret) + return dev_err_probe(dev, ret, "DPTX hotplug failed\n"); + ret = dcp_iboot_wait_hpd(ib); + if (ret) + return ret; + ret = dcp_iboot_get_modes(ib); + if (ret) + return dev_err_probe(dev, ret, "no modes\n"); + } + ret = dcp_iboot_boot_surface(ib); + if (ret) + return dev_err_probe(dev, ret, "no boot surface\n"); + /* Keep an idle connector registered while the PD controller negotiates. */ + if (!sink) { + dev_info(dev, "waiting for a USB-C display\n"); + goto register_kms; + } + disp->hpd = 1; + /* + * Without the bootloader's link (no display on the port at boot) the + * PHY starts cold, the right way round for the plug. + */ + if (disp->phy->detect && disp->phy->set_orientation) { + bool flipped; + + if (disp->phy->detect(disp, &flipped) > 0) { + if (disp->phy->select) + disp->phy->select(disp); + disp->phy->set_orientation(disp, flipped); + } + } + ret = disp->phy->activate(disp); + if (ret) + return dev_err_probe(dev, ret, "PHY activation failed\n"); + /* While the display is still off and the firmware does no AUX. */ + dcp_iboot_update_edid(ib); + ret = ibootep_set_power(dcp, true); + if (ret) + return dev_err_probe(dev, ret, "set_power failed\n"); + ib->powered = true; + dev_info(dev, "%u timing modes, %u color modes\n", ib->nr_tmodes, + ib->nr_cmodes); + +register_kms: + ret = dcp_iboot_kms_init(ib); + if (ret) + return ret; + if (sink) { + ret = dcp_iboot_set_boot_mode(ib); + if (ret) + dev_warn(dev, "boot mode not set again: %d\n", ret); + } + ret = drm_dev_register(&ib->drm, 0); + if (ret) + return ret; + WRITE_ONCE(ib->ready, true); + if (disp->hpd_gpio || disp->usbc) + drmm_kms_helper_poll_init(&ib->drm); + if (disp->usbc) + queue_delayed_work(system_freezable_wq, &ib->hpd_work, + msecs_to_jiffies(250)); + drm_client_setup(&ib->drm, NULL); + return 0; +} + +/* + * Without a USB-C display the bootloader drives HDMI from the main DCP + * (source 0) and never starts DCPEXT0. hdmi_np: DCPEXT0's node, which + * describes the HDMI PHY. + */ +int dcp_iboot_probe(struct apple_dcp *dcp) +{ + struct device *dev = dcp->dev; + struct device_node *hdmi_np __free(device_node) = t8152_hdmi_node(); + int source = hdmi_np ? t8152_hdmi_source(hdmi_np) : -ENODEV; + struct t8152_display *disp; + struct dcp_iboot *ib; + u32 live; + int ret; + + if (dev->of_node == hdmi_np && source != 1 && + !of_property_present(dev->of_node, "apple,usb-c-ports")) { + dev_info(dev, "%s\n", source == 0 ? "HDMI is on the main DCP" : + "no bootloader HDMI link to adopt"); + return -ENODEV; + } + + /* + * The bootloader's AFK endpoint hand-off: without it there is no + * telling whether an endpoint is live, and an INIT on a live one + * asserts in the firmware. + */ + ret = of_property_read_u32(dev->of_node, "apple,afk-active-endpoints", &live); + if (ret || live & ~GENMASK(15, 0)) + return dev_err_probe(dev, -EINVAL, + "bootloader AFK endpoint handoff required\n"); + + ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64)); + if (ret) + return ret; + + ib = dcp_iboot_alloc(dev); + if (IS_ERR(ib)) + return PTR_ERR(ib); + ib->dcp = dcp; + disp = &ib->disp; + disp->dcp = dcp; + disp->dev = dev; + disp->dp_source = dev->of_node == hdmi_np ? 1 : 0; + of_property_read_u32(dev->of_node, "apple,dp-source", &disp->dp_source); + if (disp->dp_source > 2) + return -EINVAL; + of_property_read_u32(dev->of_node, "apple,die", &disp->die); + dcp->afk_live_endpoints = live; + mutex_init(&ib->lock); + INIT_DELAYED_WORK(&ib->av_work, dcp_iboot_av_work); + + ret = dcp_iboot_scanout_init(ib); + if (ret) + return dev_err_probe(dev, ret, "no scanout DART stream\n"); + + disp->hdmi = source >= 0 && source == disp->dp_source; + if (disp->hdmi && dev->of_node != hdmi_np) + dev_info(dev, "HDMI from the main DCP (no USB-C display at boot)\n"); + /* Read only: the pin belongs to a controller the AOP runs. */ + disp->hpd_gpio = NULL; + if (disp->hdmi) + disp->hpd_gpio = devm_fwnode_gpiod_get(dev, of_fwnode_handle(hdmi_np), + "hpd", GPIOD_ASIS, "hpd"); + if (PTR_ERR(disp->hpd_gpio) == -ENOENT) + disp->hpd_gpio = NULL; + if (IS_ERR(disp->hpd_gpio)) + return dev_err_probe(dev, PTR_ERR(disp->hpd_gpio), "no HPD GPIO\n"); + disp->hpd = 0; + ret = disp->hdmi ? t8152_hdmi_init(disp, hdmi_np) : t8152_atc_init(disp); + if (ret) + return dev_err_probe(dev, ret, "no DisplayPort PHY\n"); + /* Nobody has HDMI from the bootloader: it is one of the shared ports. */ + if (!disp->hdmi && source < 0 && hdmi_np) { + ret = t8152_hdmi_port_init(disp, hdmi_np); + if (ret) + return dev_err_probe(dev, ret, "no shared HDMI port\n"); + } + + WRITE_ONCE(dcp->t8152, disp); + WRITE_ONCE(dcp->iboot, ib); + ret = dcp_iboot_boot(ib); + if (IS_ERR_OR_NULL(dcp->rtk)) { + dcp->rtk = NULL; + return dev_err_probe(dev, ret, "cannot adopt the DCP\n"); + } + /* + * From here on the DCP may DMA into what this driver gives it, and + * there is no safe way to stop it: retain the session until reboot. + */ + if (dcp_retain_live_session(dcp)) { + dev_warn(dev, "live session not recorded; its DMA stays allocated\n"); + WRITE_ONCE(dcp->retain_dma, true); + } + /* The device stays bound from here on: follow the USB-C ports. */ + if (t8152_typec_init(disp)) + dev_err(dev, "USB-C ports not followed, no USB-C display\n"); + if (ret) + dev_err(dev, "cannot adopt the DCP: %d\n", ret); + else + ret = dcp_iboot_start(ib); + if (!ret) + return 0; + + /* + * Gate RX before draining endpoint work; keep RTKit available until + * every sender has stopped. Do not reclaim firmware-visible storage + * or let the driver core retry a partially started session. + */ + dcp_iboot_detach(ib); + dev_err(dev, "initialization failed (%d); live DMA resources retained until reboot\n", + ret); + return 0; +} + +/* An unbind: the DRM device goes, the firmware session and its DMA stay. */ +void dcp_iboot_remove(struct apple_dcp *dcp) +{ + struct dcp_iboot *ib = dcp->iboot; + bool registered; + + if (!ib) + return; + registered = READ_ONCE(ib->ready); + if (ib->drm.mode_config.poll_enabled) + drm_kms_helper_poll_disable(&ib->drm); + if (!READ_ONCE(dcp->quiescing)) + dcp_iboot_detach(ib); + if (registered) { + drm_dev_unplug(&ib->drm); + /* Drops the committed state's connector reference. */ + drm_atomic_helper_shutdown(&ib->drm); + } +} diff --git a/drivers/gpu/drm/apple/iomfb_iboot.h b/drivers/gpu/drm/apple/iomfb_iboot.h new file mode 100644 index 0000000000000..bddeeedc198d5 --- /dev/null +++ b/drivers/gpu/drm/apple/iomfb_iboot.h @@ -0,0 +1,146 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * DCP_FIRMWARE_IBOOT: a T8152 DCP driven through its firmware's iBoot + * interface alone, with a DRM device of its own (iomfb_iboot.c, iboot_drm.c). + */ +#ifndef __APPLE_IOMFB_IBOOT_H__ +#define __APPLE_IOMFB_IBOOT_H__ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "ibootep.h" +#include "t8152_display.h" + +struct apple_dcp; +struct device; +struct drm_edid; +struct iommu_domain; +struct platform_device; + +struct dcp_iboot_dma { + void *cpu; + dma_addr_t iova; + size_t size; +}; + +/* + * Scanout buffers, each for the largest mode: a frame is copied into one not + * on screen, which SET_SURFACE then shows. Copying into the buffer being + * scanned out tore every frame. Three, so the one written next left the + * screen a frame ago. + */ +#define DCP_IBOOT_SCANOUT_BUFS 3 + +struct dcp_iboot { + struct drm_device drm; + struct apple_dcp *dcp; + struct t8152_display disp; + + /* The DRM device is registered and the session up. */ + bool ready; + bool kms_work_ready; + + /* The scanout DART's own device and domain (dcp_iboot_scanout_init()). */ + struct platform_device *scanout; + struct iommu_domain *scanout_dom; + struct dcp_iboot_dma scan[DCP_IBOOT_SCANOUT_BUFS]; + /* their pages write-combined: the pipe does not snoop the CPU caches */ + void *scan_wc[DCP_IBOOT_SCANOUT_BUFS]; + /* their addresses in the display pipe's DART */ + dma_addr_t scan_dva[DCP_IBOOT_SCANOUT_BUFS]; + /* scan[front] is on screen (or set as the surface at the next power on) */ + unsigned int front; + /* the part of the current picture scan[i] does not hold yet */ + struct drm_rect stale[DCP_IBOOT_SCANOUT_BUFS]; + /* when scan[i] stopped being the requested surface */ + ktime_t retired[DCP_IBOOT_SCANOUT_BUFS]; + /* the last SET_SURFACE of a new buffer */ + ktime_t last_swap; + /* + * A frame written within one refresh of the last swap waits in + * scan[pending] (-1: none) for swap_timer, at most one swap per + * refresh; a newer frame overwrites it. + */ + int pending; + u32 pending_w, pending_h, pending_pitch; + struct hrtimer swap_timer; + struct work_struct swap_work; + u32 boot_w, boot_h, boot_stride; + + /* the sink's EDID, read through the PHY (NULL if unavailable) */ + const struct drm_edid *edid; + + /* iBoot state below, under lock */ + struct mutex lock; + bool enabled; + bool powered; + struct iboot_timing_mode *tmodes; + unsigned int nr_tmodes; + struct iboot_color_mode *cmodes; + unsigned int nr_cmodes; + struct iboot_timing_mode cur_mode; + bool mode_set; + /* SET_MODE of cur_mode failed; the next plug sets it again */ + bool mode_failed; + /* USB-C: connect the sink anew when it stopped answering */ + struct work_struct relink_work; + unsigned long relink_time; + /* + * The DPAV video interface started: SET_MODE again, or the + * firmware's idle power off timer takes the link down 30 s later. + */ + struct delayed_work av_work; + struct delayed_work hpd_work; + + struct drm_plane plane; + struct drm_crtc crtc; + struct drm_encoder encoder; + struct drm_connector connector; +}; + +static inline struct dcp_iboot *to_dcp_iboot(struct drm_device *drm) +{ + return container_of(drm, struct dcp_iboot, drm); +} + +#if IS_ENABLED(CONFIG_DRM_APPLE_DCP_T8152) +/* t8152_typec.c */ +void t8152_typec_register(struct device *dev); +void t8152_typec_unregister(void); + +/* iomfb_iboot.c */ +int dcp_iboot_probe(struct apple_dcp *dcp); +void dcp_iboot_remove(struct apple_dcp *dcp); +int dcp_iboot_wait_hpd(struct dcp_iboot *ib); +int dcp_iboot_get_modes(struct dcp_iboot *ib); + +/* iboot_drm.c */ +struct dcp_iboot *dcp_iboot_alloc(struct device *dev); +const char *dcp_iboot_driver_name(void); +int dcp_iboot_kms_init(struct dcp_iboot *ib); +void dcp_iboot_kms_stop(struct dcp_iboot *ib); +int dcp_iboot_set_boot_mode(struct dcp_iboot *ib); +void dcp_iboot_update_edid(struct dcp_iboot *ib); +void dcp_iboot_reset_mode(struct dcp_iboot *ib); +void dcp_iboot_av_started(struct dcp_iboot *ib); +void dcp_iboot_hpd_event(struct dcp_iboot *ib); +#else +static inline void t8152_typec_register(struct device *dev) { } +static inline void t8152_typec_unregister(void) { } +static inline int dcp_iboot_probe(struct apple_dcp *dcp) { return -ENODEV; } +static inline void dcp_iboot_remove(struct apple_dcp *dcp) { } +#endif + +#endif diff --git a/drivers/gpu/drm/apple/t8152_atc.c b/drivers/gpu/drm/apple/t8152_atc.c new file mode 100644 index 0000000000000..b5bb17bab79f1 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_atc.c @@ -0,0 +1,891 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * T8152 (J873g) ATC PHYs as DisplayPort outputs of the DCPs' DPTX ports. + * + * Interim, until drivers/phy/apple/atc.c has a DisplayPort mode for T8152 + * and the display crossbar driver and the Type-C route layer of + * dcp-fabric.c take over the route and the choice of port: this programs + * the PHY's DisplayPort lanes, its pixel clock and the crossbar route + * itself. + * + * The bootloader trains a USB-C display before Linux starts; this takes + * that link over and then follows the firmware: link rate changes (stop and + * set up the lanes again), drive settings, the DCP -> ATCn/DFP0 crossbar + * route, and with the display off or unplugged a full power down and a cold + * start. A DCP drives one USB-C port at a time: the one it claims from the + * shared ports once their Type-C state shows a sink (t8152_typec.c). + * + * The ATC PHY driver powers the PHY: it holds the PHY's power domains while + * the port's DP PHY is on, and keeps the PHY out of USB4 meanwhile. So the DP + * PHY goes on before any PHY register access of a cold start, and off once + * the PHY is powered down, and a bootloader display's PHY stays on with it. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dptxep.h" +#include "t8152_display.h" + +#define ATC_AON 0x1e00 +#define ATC_CFG 0x60000 +#define ATC_XBAR 0x74000 +/* + * The DP clock switch at CFG + 0x14 (select), + 0x18 (enable) and + 0x1c + * (status). DP pixel clock n (1..4) runs from switch n: select field n is n + * for PMGR DP clock n - 1, 7 for none, and enable/status bit 1 + 7 * (n - 1) + * gates that PMGR clock. PCLK1 is used here, from PMGR DP0, whose divider + * atc_clock_write() sets for the link rate. + */ +#define ATC_CLKSW_SELECT (ATC_CFG + 0x14) +#define ATC_CLKSW_ENABLE (ATC_CFG + 0x18) +#define ATC_CLKSW_STATUS (ATC_CFG + 0x1c) +#define ATC_CLKSW_PCLK1_SEL GENMASK(2, 0) +#define ATC_CLKSW_PCLK1_MODE BIT(12) +#define ATC_CLKSW_PCLK1_OFF 7 +#define ATC_CLKSW_PCLK1_DP0 1 +#define ATC_CLKSW_PCLK1_EN BIT(1) +#define ATC_TIMEOUT_US 10000 + +struct t8152_atc_port { + void __iomem *base; + unsigned int index; /* ATC instance */ + /* display crossbar DFP endpoint of this ATC */ + u32 dfp; + /* AP DisplayPort AUX controller aux0 (shared), for the EDID */ + struct t8152_aux *aux; + /* PMGR power states of the ATC dependencies, read to tell if it runs */ + void __iomem *ps; + void __iomem *psd; + /* the port's DP PHY of the ATC PHY driver, which powers the PHY */ + struct phy *phy; + /* {offset, mask, value} tunables, before and after the lane setup */ + const __be32 *tunable[2]; + int tunable_len[2]; + /* This ATC's PMGR DP clock divider selects the link rate. */ + void __iomem *dp_clock; + bool swap; + bool active; + bool route_started; + u32 link_rate; + u32 lanes, next_lanes; +}; + +struct t8152_atc { + struct t8152_aux aux; + struct t8152_atc_port port[4]; + unsigned int nports; + /* the port the DCP drives, and the one a sink was found on */ + struct t8152_atc_port *cur, *next; +}; + +/* J873 has one display crossbar. Claims outlive firmware PHY power cycles. */ +static DEFINE_MUTEX(atc_owner_lock); +static struct device *atc_owner[4]; +/* All three DCPs borrow the same AP AUX controller for EDID reads. */ +static DEFINE_MUTEX(atc_aux_lock); + +static struct t8152_atc_port *atc_cur(struct t8152_display *disp) +{ + return ((struct t8152_atc *)disp->phy_priv)->cur; +} + +static const u32 atc_rates[] = { + LINK_RATE_RBR, LINK_RATE_HBR, LINK_RATE_HBR2, LINK_RATE_HBR3, +}; + +static bool atc_dp_pma(struct t8152_atc_port *atc, u32 pma) +{ + return atc->lanes == 4 || pma == !atc->swap; +} + +static bool atc_dp_register(struct t8152_atc_port *atc, u32 offset) +{ + if (offset >= 0x3000 && offset < 0xc000) + return atc_dp_pma(atc, 0); + if (offset >= 0xc000 && offset < 0x15000) + return atc_dp_pma(atc, 1); + return true; +} + +static void atc_update(struct t8152_atc_port *atc, u32 offset, u32 mask, u32 value) +{ + u32 reg = readl(atc->base + offset); + + writel((reg & ~mask) | value, atc->base + offset); +} + +static int atc_poll(struct t8152_atc_port *atc, u32 offset, u32 mask, u32 value) +{ + u32 reg; + + return readl_poll_timeout(atc->base + offset, reg, + (reg & mask) == value, 1, ATC_TIMEOUT_US); +} + +static int atc_route_stop(struct t8152_display *disp, struct t8152_atc_port *atc) +{ + u32 ufp = disp->dp_source * 2; + u32 mask = BIT(ufp); + + if (!atc->route_started) + return 0; + atc_update(atc, ATC_XBAR + 0x3c, mask, 0); + atc_update(atc, ATC_XBAR, mask, 0); + atc_update(atc, ATC_XBAR + 0xc, mask, 0); + atc_update(atc, ATC_XBAR + 0x24, 0x100, 0); + udelay(1); + /* + * With the pipe powered off (the bootloader hands the display over + * that way) nothing acknowledges the stop; the route is idle then, so + * finish it anyway. + */ + if (atc_poll(atc, ATC_XBAR + 0x800, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x808, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x81c, 0x100, 0)) + dev_info(disp->dev, "ATC%u: no crossbar stop acknowledgment\n", atc->index); + atc_update(atc, ATC_XBAR + 8, mask, 0); + atc_update(atc, ATC_XBAR + 0x20, 7 << (3 * ufp), 0); + atc_update(atc, ATC_XBAR + 0x38, 0x700, 0); + atc_update(atc, ATC_XBAR + 4, mask, mask); + atc_update(atc, ATC_XBAR + 0x1c, mask, mask); + atc_update(atc, ATC_XBAR + 0x34, 0x100, 0x100); + atc->route_started = false; + dev_dbg(disp->dev, "ATC%u: display route disabled\n", atc->index); + return 0; +} + +/* + * A source -> ATCn/DFP0 route, PCLK1: both DFP0 mux fields (0x44 bits 23:20 + * and 11:8) select the source. The upstream reset, clock and enable fields + * are indexed by DCP endpoint * 2 + DPTX port, independently of the + * downstream DFP0 fields. AUX borrowing keeps that DCP's clock path. + */ +#define ATC_SEL_AUX0 9 /* UFP endpoint 5 (aux0) + 4 */ + +static int atc_route_start_sel(struct t8152_display *disp, + struct t8152_atc_port *atc, u32 sel) +{ + u32 ufp = disp->dp_source * 2; + u32 mask = BIT(ufp); + + if (atc->route_started) + return 0; + atc_update(atc, ATC_XBAR + 0x44, 0x00f00000, sel << 20); + atc_update(atc, ATC_XBAR + 0x44, 0x00000f00, sel << 8); + atc_update(atc, ATC_XBAR + 4, mask, 0); + atc_update(atc, ATC_XBAR + 0x1c, mask, 0); + atc_update(atc, ATC_XBAR + 0x34, 0x100, 0); + udelay(1); + if (atc_poll(atc, ATC_XBAR + 0x804, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x818, mask, 0) || + atc_poll(atc, ATC_XBAR + 0x82c, 0x100, 0)) { + dev_err(disp->dev, "ATC%u: crossbar reset acknowledgment timeout\n", + atc->index); + return -ETIMEDOUT; + } + atc_update(atc, ATC_XBAR + 8, mask, mask); + atc_update(atc, ATC_XBAR + 0x20, 7 << (3 * ufp), 1 << (3 * ufp)); + atc_update(atc, ATC_XBAR + 0x38, 0x700, 0x100); + atc_update(atc, ATC_XBAR + 0x48, 1, 0); + atc_update(atc, ATC_XBAR, mask, mask); + atc_update(atc, ATC_XBAR + 0xc, mask, mask); + atc_update(atc, ATC_XBAR + 0x24, 0x100, 0x100); + atc_update(atc, ATC_XBAR + 0x4c, 0x100, 0x100); + atc_update(atc, ATC_XBAR + 0x3c, mask, mask); + atc->route_started = true; + dev_dbg(disp->dev, "ATC%u: source %u to local DFP0 route configured\n", + atc->index, sel); + return 0; +} + +static int atc_route_start(struct t8152_display *disp, struct t8152_atc_port *atc) +{ + return atc_route_start_sel(disp, atc, disp->dp_source * 2); +} + +/* Common four-lane setup; the rate-dependent fields follow in atc_dp_start. */ +static const struct { + u32 offset, mask, value; +} atc_dp_setup[] = { + { 0x2044, 0xffff, 0x4b0 }, + { 0x4c, 0x3c0000, 0x3c0000 }, + { 0x4c80, 0x40, 0x40 }, + { 0xdc80, 0x40, 0x40 }, + { 0x4fd4, 0x2000000, 0x2000000 }, + { 0x4fd4, 0x1800000, 0x800000 }, + { 0xdfd4, 0x2000000, 0x2000000 }, + { 0xdfd4, 0x1800000, 0x800000 }, + { 0x4d84, 0x1c0000, 0 }, + { 0x4fd4, 1, 0 }, + { 0x4fd4, 8, 0 }, + { 0x4fd4, 2, 2 }, + { 0x4fd4, 0x10, 0x10 }, + { 0x8904, 0x1c0000, 0 }, + { 0x8800, 0x10000000, 0 }, + { 0x8800, 0x80000000, 0 }, + { 0x8800, 0x20000000, 0x20000000 }, + { 0x8804, 1, 1 }, + { 0xdd84, 0x1c0000, 0 }, + { 0xdfd4, 1, 0 }, + { 0xdfd4, 8, 0 }, + { 0xdfd4, 2, 2 }, + { 0xdfd4, 0x10, 0x10 }, + { 0x11904, 0x1c0000, 0 }, + { 0x11800, 0x10000000, 0 }, + { 0x11800, 0x80000000, 0 }, + { 0x11800, 0x20000000, 0x20000000 }, + { 0x11804, 1, 1 }, + { 0x3c04, 2, 2 }, + { 0x3c04, 1, 1 }, + { 0xcc04, 2, 2 }, + { 0xcc04, 1, 1 }, +}; + +/* Program the PMGR DP clock divider and wait for the change to settle. */ +static int atc_clock_write(struct t8152_atc_port *atc, u32 divider) +{ + u32 reg = readl(atc->dp_clock); + + writel((reg & ~0x0f000000) | (divider << 24), atc->dp_clock); + return readl_poll_timeout(atc->dp_clock, reg, !(reg & BIT(30)), 1, + ATC_TIMEOUT_US); +} + +/* Stop the DP lanes: route, pixel clock, then both PMAs. */ +static int atc_dp_stop(struct t8152_display *disp, struct t8152_atc_port *atc) +{ + u32 reg; + + atc_route_stop(disp, atc); + atc_update(atc, ATC_CLKSW_SELECT, ATC_CLKSW_PCLK1_SEL | ATC_CLKSW_PCLK1_MODE, + ATC_CLKSW_PCLK1_OFF); + atc_update(atc, ATC_CLKSW_ENABLE, ATC_CLKSW_PCLK1_EN, 0); + if (readl_poll_timeout(atc->base + ATC_CLKSW_STATUS, reg, + !(reg & ATC_CLKSW_PCLK1_EN), 1, ATC_TIMEOUT_US)) { + dev_err(disp->dev, "ATC%u: DPTX clock stop failed\n", atc->index); + return -ETIMEDOUT; + } + atc_update(atc, 0x2040, BIT(16), 0); + udelay(5); + atc_update(atc, 0x2000, BIT(15), 0); + atc_update(atc, 0x2000, BIT(13), 0); + atc_update(atc, 0x2000, BIT(14), 0); + atc_update(atc, 0x2000, BIT(2), 0); + atc_update(atc, 0x2000, BIT(3), BIT(3)); + atc_update(atc, 0xe10, BIT(2), BIT(2)); + atc_update(atc, 0xe08, BIT(29), BIT(29)); + /* Remove both PMA clock requests, then clamp and power down both lanes. */ + for (u32 offset = 0x1e18; offset <= 0x1e1c; offset += 4) { + u32 pma = (offset - 0x1e18) / 4; + + if (!atc_dp_pma(atc, pma)) + continue; + atc_update(atc, ATC_AON + 0x24, + BIT(12 + 2 * pma) | BIT(16 + 2 * pma), 0); + udelay(1); + atc_update(atc, offset, BIT(5), 0); + udelay(1); + atc_update(atc, offset, BIT(0), BIT(0)); + udelay(1); + atc_update(atc, offset, BIT(2), 0); + udelay(1); + atc_update(atc, offset, BIT(1), 0); + udelay(1); + } + atc->link_rate = 0; + return 0; +} + +/* DP lane setup at rate index r. */ +static int atc_dp_start(struct t8152_display *disp, struct t8152_atc_port *atc, u32 r) +{ + static const u32 tx_ctrl[] = { 0x4eb0, 0x8b10, 0xdeb0, 0x11b10 }; + static const u32 wake_count[] = { 0xbb5, 0xbb7, 0xbb8, 0xbb9 }; + u32 reg; + int ret; + + if (readl(atc->dp_clock) & BIT(30)) + return -EBUSY; + if (!r) { + atc_update(atc, 0xe10, BIT(2), BIT(2)); + atc_update(atc, 0xe08, BIT(29), BIT(29)); + } + for (u32 i = 0; i < 2; i++) { + u32 offset = 0x1e18 + 4 * i; + + if (!atc_dp_pma(atc, i)) + continue; + atc_update(atc, ATC_AON + 0x24, BIT(12 + 2 * i), BIT(12 + 2 * i)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(16 + 2 * i), BIT(16 + 2 * i)); + udelay(1); + atc_update(atc, offset, BIT(1), BIT(1)); + udelay(1); + atc_update(atc, offset, BIT(2), BIT(2)); + udelay(1); + atc_update(atc, offset, BIT(0), 0); + udelay(1); + atc_update(atc, offset, BIT(5), BIT(5)); + udelay(2); + } + atc_update(atc, 0x2000, 0x380000, r << 19); + for (unsigned int i = 0; i < ARRAY_SIZE(atc_dp_setup); i++) + if (atc_dp_register(atc, atc_dp_setup[i].offset)) + atc_update(atc, atc_dp_setup[i].offset, atc_dp_setup[i].mask, + atc_dp_setup[i].value); + for (u32 i = 0; i < 2; i++) { + if (!atc_dp_pma(atc, i)) + continue; + atc_update(atc, 0x8684 + i * 0x9000, 3, r ? 0 : 1); + atc_update(atc, 0x4c80 + i * 0x9000, 0x30, r ? 0 : 0x10); + } + for (unsigned int i = 0; i < ARRAY_SIZE(tx_ctrl); i++) { + if (!atc_dp_register(atc, tx_ctrl[i])) + continue; + atc_update(atc, tx_ctrl[i], 0x7e07ff, 1); + atc_update(atc, tx_ctrl[i] - 0x14, 0x7f, r < 2 ? 0x65 : 0x40); + } + atc_update(atc, 0x2000, 0x70, 0x10); + atc_update(atc, 0x2000, BIT(13), BIT(13)); + atc_update(atc, 0x2044, 0xffff0000, wake_count[r] << 16); + atc_update(atc, atc->swap ? 0x89f0 : 0x119f0, BIT(14), BIT(14)); + atc_update(atc, 0x2000, BIT(2), BIT(2)); + atc_update(atc, 0x2000, BIT(3), BIT(3)); + atc_update(atc, 0x2040, BIT(16), BIT(16)); + + ret = atc_clock_write(atc, 10 - r); + if (ret) { + dev_err(disp->dev, "ATC%u: DP clock change timeout\n", atc->index); + return ret; + } + /* + * Clock the stream from PMGR DP0 at the link-rate divider just set. + * With source 0 selected instead, the pixel clock does not follow the + * divider, and every mode above about 165 MHz stays black. + */ + atc_update(atc, ATC_CLKSW_SELECT, ATC_CLKSW_PCLK1_SEL | ATC_CLKSW_PCLK1_MODE, + ATC_CLKSW_PCLK1_DP0); + atc_update(atc, ATC_CLKSW_ENABLE, ATC_CLKSW_PCLK1_EN, ATC_CLKSW_PCLK1_EN); + if (readl_poll_timeout(atc->base + ATC_CLKSW_STATUS, reg, + reg & ATC_CLKSW_PCLK1_EN, 1, ATC_TIMEOUT_US)) { + dev_err(disp->dev, "ATC%u: DP pixel clock does not start\n", atc->index); + return -ETIMEDOUT; + } + ret = atc_route_start(disp, atc); + if (ret) + return ret; + atc->link_rate = atc_rates[r]; + dev_info(disp->dev, "ATC%u: %u-lane DPTX setup at rate %#x\n", atc->index, + atc->lanes, atc->link_rate); + return 0; +} + +#define ATC_PSD_STATE 0x80 + +static void atc_apply_tunables(struct t8152_atc_port *atc, unsigned int which) +{ + const __be32 *t = atc->tunable[which]; + + for (int i = 0; i + 3 <= atc->tunable_len[which]; i += 3) + atc_update(atc, be32_to_cpu(t[i]), be32_to_cpu(t[i + 1]), + be32_to_cpu(t[i + 2])); +} + +/* Cold start: the PHY's power, the common block and AUX, then the lanes at HBR. */ +static int atc_activate(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + void __iomem *cfg = atc->base + ATC_CFG; + u32 reg; + int ret; + + if (READ_ONCE(atc_owner[atc->index]) != disp->dev) + return -EBUSY; + if (atc->active) + return 0; + if (!atc->tunable[0] || !atc->tunable[1]) + return -EOPNOTSUPP; + /* -EBUSY while the PHY runs USB4 */ + ret = phy_power_on(atc->phy); + if (ret) { + dev_err(disp->dev, "ATC%u: PHY not powered: %d\n", atc->index, ret); + return ret; + } + if (readl(cfg) != 4 || (readl(cfg + 4) & 3) || readl(cfg + 0x30)) + goto fail; + writel(readl(cfg + 0x30) | BIT(0), cfg + 0x30); + udelay(1); + writel(readl(cfg) | BIT(0), cfg); + if (readl_poll_timeout(cfg + 4, reg, reg & BIT(0), 1, ATC_TIMEOUT_US)) + goto fail; + writel(readl(cfg) | BIT(1), cfg); + if (readl_poll_timeout(cfg + 4, reg, reg & BIT(1), 1, ATC_TIMEOUT_US)) + goto fail; + writel(readl(cfg) & ~BIT(2), cfg); + udelay(1); + writel(readl(cfg) | BIT(3), cfg); + + atc_apply_tunables(atc, 0); + /* Pin D/F keeps the other PMA out of the DP path. */ + atc_update(atc, 0x4c, 0x1f, + atc->lanes == 2 ? (atc->swap ? 0x11 : 0x10) : 0x14); + atc_update(atc, 0x4c, 0x3ffe0, + atc->lanes == 2 || atc->swap ? 0x100 : 0x22000); + atc_apply_tunables(atc, 1); + atc_update(atc, ATC_CFG + 8, BIT(1), atc->swap ? BIT(1) : 0); + writel(readl(cfg) | BIT(4), cfg); + if ((readl(cfg) & 0x1f) != 0x1b) + goto fail; + /* AUX: release small and big sleep, then the AUX clamp. */ + atc_update(atc, ATC_AON + 0x24, BIT(8), BIT(8)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(6), BIT(6)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(10), 0); + udelay(1); + atc->active = true; + dev_info(disp->dev, "ATC%u: common PHY and AUX up from cold\n", atc->index); + /* + * The lanes start at HBR right away. From cold, AUX only works with + * the DP PLL and PMAs running (without them the firmware reports + * DEVICE_NOT_RESPONDING); the firmware switches to its rate afterwards. + */ + return atc_dp_start(disp, atc, 1); +fail: + dev_err(disp->dev, "ATC%u: cold start failed (cfg %#x/%#x)\n", + atc->index, readl(cfg), readl(cfg + 4)); + phy_power_off(atc->phy); + return -EIO; +} + +/* Power the PHY down, its power included. */ +static int atc_deactivate(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + void __iomem *cfg = atc->base + ATC_CFG; + int ret = 0; + u32 reg; + + if (!atc->active) + return 0; + if (atc->link_rate && atc_dp_stop(disp, atc)) { + dev_err(disp->dev, "ATC%u: DP stop failed\n", atc->index); + return -EIO; + } + atc_route_stop(disp, atc); + atc_update(atc, ATC_AON + 0x24, BIT(10), BIT(10)); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(6), 0); + udelay(1); + atc_update(atc, ATC_AON + 0x24, BIT(8), 0); + udelay(1); + writel(readl(cfg) & ~BIT(4), cfg); + udelay(1); + writel(readl(cfg) & ~BIT(3), cfg); + writel(readl(cfg) | BIT(2), cfg); + writel(readl(cfg) & ~BIT(1), cfg); + if (readl_poll_timeout(cfg + 4, reg, !(reg & BIT(1)), 1, ATC_TIMEOUT_US)) { + dev_err(disp->dev, "ATC%u: big-sleep entry timeout\n", atc->index); + ret = -ETIMEDOUT; + } + writel(readl(cfg) & ~BIT(0), cfg); + if (readl_poll_timeout(cfg + 4, reg, !(reg & BIT(0)), 1, ATC_TIMEOUT_US)) { + dev_err(disp->dev, "ATC%u: small-sleep entry timeout\n", atc->index); + ret = -ETIMEDOUT; + } + writel(readl(cfg + 0x30) & ~BIT(0), cfg + 0x30); + atc->active = false; + /* Then its power: the next activation starts it cold. */ + if (phy_power_off(atc->phy)) + ret = -ETIMEDOUT; + dev_info(disp->dev, "ATC%u: powered down: %d\n", atc->index, ret); + return ret; +} + +static int atc_set_link_rate(struct t8152_display *disp, u32 rate) +{ + struct t8152_atc_port *atc = atc_cur(disp); + u32 r; + int ret; + + /* The firmware drops the link (rate 0) before it retrains. */ + if (!rate || rate == atc->link_rate) + return 0; + for (r = 0; r < ARRAY_SIZE(atc_rates); r++) + if (atc_rates[r] == rate) + break; + if (r == ARRAY_SIZE(atc_rates) || !atc->active) + return -EINVAL; + dev_info(disp->dev, "ATC%u: link rate %#x, was %#x\n", atc->index, rate, + atc->link_rate); + if (atc->link_rate) { + ret = atc_dp_stop(disp, atc); + if (ret) + return ret; + } + return atc_dp_start(disp, atc, r); +} + +static int atc_set_route(struct t8152_display *disp, bool enable) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + if (!enable) + return atc_route_stop(disp, atc); + if (!atc->active) + return -ENODEV; + if (atc_route_start(disp, atc)) + return -EIO; + mdelay(5); + return 0; +} + +/* + * Lane drive presets, indexed by voltage * 4 + pre-emphasis; they serve + * every link rate. + */ +static const u32 atc_drive_presets[16] = { + 0x025, 0x420, 0x717, 0x90f, 0x019, 0x397, 0x78f, 0x025, + 0x011, 0x38f, 0x025, 0x025, 0x000, 0x025, 0x025, 0x025, +}; + +static int atc_set_drive(struct t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count) +{ + struct t8152_atc_port *atc = atc_cur(disp); + u32 presets[4]; + + if (!count) + return 0; + if (count > atc->lanes || !atc->active || !atc->link_rate) + return -EINVAL; + /* Validate the entire request before changing any lane. */ + for (u32 i = 0; i < count; i++) { + u32 v = le32_to_cpu(settings[i].voltage); + u32 e = le32_to_cpu(settings[i].pre_emphasis); + + if (settings[i].format || v > 3 || e > 3 || v + e > 3) + return -EINVAL; + presets[i] = atc_drive_presets[v * 4 + e]; + } + for (u32 i = 0; i < count; i++) { + u32 pma = (i / 2) ^ !atc->swap; + /* Even DP lanes use the PMA RX pair, odd lanes its TX pair. */ + u32 offset = ((i & 1) ? 0x4eb0 : 0x8b10) + pma * 0x9000; + u32 preset = presets[i]; + u32 control = 1 | (((preset >> 13) & 0x3f) << 17) | + (((preset >> 7) & 0x3f) << 5); + + atc_update(atc, offset, 0x7e07ff, control); + atc_update(atc, offset - 0x14, 0x7f, (preset & 0x3f) | 0x40); + } + return 0; +} + +static void atc_set_orientation(struct t8152_display *disp, bool flipped) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + /* Applied by the next cold start; a running PHY keeps its own. */ + if (atc->active && atc->swap != flipped) + dev_warn(disp->dev, "ATC%u: orientation changed while active\n", + atc->index); + atc->swap = flipped; + atc->lanes = atc->next_lanes; +} + +static u32 atc_max_lane_count(struct t8152_display *disp) +{ + return atc_cur(disp)->lanes; +} + +/* + * The sink's EDID through the AP AUX controller aux0, which reaches the ATC + * through crossbar UFP aux0 like the DCP: the DCP's route comes down for + * the read, so this runs while the firmware does no AUX itself (display + * off, HPD not asserted yet). + */ +static int atc_read_edid(struct t8152_display *disp, u8 *buf, size_t size) +{ + struct t8152_atc_port *atc = atc_cur(disp); + bool was_started = atc->route_started; + int ret; + + if (!atc->active || !atc->aux->regs) + return -ENODEV; + mutex_lock(&atc_aux_lock); + /* The AUX output select of an ATC port: ATC instance * 3 + local DFP. */ + atc->aux->sel = atc->index * 3; + ret = t8152_aux_init(disp, atc->aux); + if (ret) + goto out; + atc_route_stop(disp, atc); + ret = atc_route_start_sel(disp, atc, ATC_SEL_AUX0); + if (!ret) + ret = t8152_aux_read_edid(disp, atc->aux, buf, size); + atc_route_stop(disp, atc); + if (was_started) + atc_route_start(disp, atc); +out: + mutex_unlock(&atc_aux_lock); + return ret; +} + +/* + * 1 with a sink on one of the ports: the current one first, then the + * others; select() switches to a port found that way. + */ +static int atc_detect(struct t8152_display *disp, bool *flipped) +{ + struct t8152_atc *atc = disp->phy_priv; + int ret = 0; + + mutex_lock(&atc_owner_lock); + atc->next = atc->cur; + /* Keep a monitor on its controller, including while userspace blanks it. */ + if (atc_owner[atc->cur->index] == disp->dev) { + ret = t8152_typec_sink(disp, atc->cur->index, flipped, + &atc->cur->next_lanes); + /* The plug changed: a new sink */ + if (ret > 0 && (atc->cur->swap != *flipped || + atc->cur->lanes != atc->cur->next_lanes)) + disp->hpd = 0; + if (ret) + goto out; + /* Unplug powers down in KMS; release on the next poll. */ + if (!atc->cur->active) + atc_owner[atc->cur->index] = NULL; + } + for (unsigned int i = 0; i < atc->nports; i++) { + struct t8152_atc_port *port = &atc->port[i]; + + if (atc_owner[port->index] || + t8152_typec_sink(disp, port->index, flipped, &port->next_lanes) <= 0) + continue; + atc_owner[port->index] = disp->dev; + atc->next = port; + disp->hpd = 0; + ret = 1; + break; + } +out: + mutex_unlock(&atc_owner_lock); + return ret; +} + +/* + * Drive the port a sink was found on: power the old one down and connect + * the DPTX port to the new one's display crossbar endpoint. + */ +static void atc_select(struct t8152_display *disp) +{ + struct t8152_atc *atc = disp->phy_priv; + struct t8152_atc_port *port = atc->next; + + if (!port || port == atc->cur) + return; + if (atc->cur->active && atc_deactivate(disp)) + return; + mutex_lock(&atc_owner_lock); + if (atc_owner[atc->cur->index] == disp->dev) + atc_owner[atc->cur->index] = NULL; + mutex_unlock(&atc_owner_lock); + dev_info(disp->dev, "USB-C display on ATC%u now, was ATC%u\n", + port->index, atc->cur->index); + atc->cur = port; + disp->dcp_output = port->dfp; +} + +/* + * Before the DCP drives another PHY (the HDMI port): give up the claim on a + * port that is powered down. False while the current port is still up. + */ +bool t8152_atc_release(struct t8152_display *disp) +{ + struct t8152_atc_port *atc = atc_cur(disp); + + if (atc->active) + return false; + guard(mutex)(&atc_owner_lock); + if (atc_owner[atc->index] == disp->dev) + atc_owner[atc->index] = NULL; + return true; +} + +static const struct t8152_phy_ops atc_ops = { + .activate = atc_activate, + .deactivate = atc_deactivate, + .set_link_rate = atc_set_link_rate, + .max_lane_count = atc_max_lane_count, + .set_drive = atc_set_drive, + .set_route = atc_set_route, + .set_orientation = atc_set_orientation, + .read_edid = atc_read_edid, + .detect = atc_detect, + .select = atc_select, + .max_link_rate = LINK_RATE_HBR2, +}; + +/* PMGR registers, inside blocks their power domain driver has claimed. */ +static void __iomem *atc_map(struct t8152_display *disp, struct device_node *np, + const char *name) +{ + int i = of_property_match_string(np, "reg-names", name); + struct resource res; + + if (i < 0 || of_address_to_resource(np, i, &res)) + return NULL; + return devm_ioremap(disp->dev, res.start, resource_size(&res)); +} + +static int atc_port_init(struct t8152_display *disp, struct t8152_atc *atc, + struct device_node *np, void __iomem *dp_clock) +{ + struct t8152_atc_port *port = &atc->port[atc->nports]; + u32 cfg, r; + + port->base = atc_map(disp, np, "atc"); + port->ps = atc_map(disp, np, "atc-ps"); + port->psd = atc_map(disp, np, "atc-psd"); + if (!port->base || !port->ps || !port->psd) + return -ENOMEM; + port->phy = devm_of_phy_optional_get(disp->dev, np, NULL); + if (IS_ERR(port->phy)) + return dev_err_probe(disp->dev, PTR_ERR(port->phy), "%pOF: no PHY\n", np); + /* The node without ports is ATC3's (J873g back-right). */ + port->dfp = 3; + of_property_read_u32(np, "apple,dfp-endpoint", &port->dfp); + port->index = port->dfp; + port->lanes = 4; + port->next_lanes = 4; + if (port->index >= 4) + return -EINVAL; + port->dp_clock = dp_clock + port->index * 8; + port->aux = &atc->aux; + port->tunable[0] = of_get_property(np, "apple,tunable-pre", + &port->tunable_len[0]); + port->tunable[1] = of_get_property(np, "apple,tunable-post", + &port->tunable_len[1]); + port->tunable_len[0] /= sizeof(__be32); + port->tunable_len[1] /= sizeof(__be32); + atc->nports++; + + /* + * The PHY block hangs the bus while it is power-gated: look at it only + * with its DP dependencies and the common PSD up. + */ + if ((readl(port->ps) & 0xf0) != 0xf0 || + (readl(port->psd + ATC_PSD_STATE) & 7)) { + dev_info(disp->dev, "ATC%u: powered down\n", port->index); + return 0; + } + /* A different DCP may already be driving this port. */ + if (atc_owner[port->index] || + ((readl(port->base + ATC_XBAR + 0x44) >> 20) & 0xf) != + disp->dp_source * 2) + return 0; + /* Common block out of reset and AUX up, as the bootloader leaves it. */ + cfg = readl(port->base + ATC_CFG); + port->active = (cfg & 0x1f) == 0x1b; + /* + * The bootloader's display keeps the PHY powered through its DP PHY. The + * common block runs the same way in USB4, whose PHY refuses the DP PHY. + */ + if (port->active && phy_power_on(port->phy)) { + dev_info(disp->dev, "ATC%u: runs USB4\n", port->index); + port->active = false; + return 0; + } + if ((readl(port->base + 0x4c) & 0x1f) == 0x10 || + (readl(port->base + 0x4c) & 0x1f) == 0x11) { + port->lanes = 2; + port->next_lanes = 2; + } + port->swap = !!(readl(port->base + ATC_CFG + 8) & BIT(1)); + port->route_started = + (readl(port->base + ATC_XBAR) & BIT(disp->dp_source * 2)) && + (readl(port->base + ATC_XBAR + 0x3c) & BIT(disp->dp_source * 2)); + r = (readl(port->base + 0x2000) >> 19) & 7; + if (port->active && (readl(port->base + 0x2040) & BIT(16)) && + r < ARRAY_SIZE(atc_rates)) + port->link_rate = atc_rates[r]; + dev_info(disp->dev, + "ATC%u: inherited state: active %d, rate %#x, route %d, reversed %d (cfg %#x)\n", + port->index, port->active, port->link_rate, port->route_started, + port->swap, cfg); + return 0; +} + +int t8152_atc_init(struct t8152_display *disp) +{ + struct device_node *ports __free(device_node) = + of_parse_phandle(disp->dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: disp->dev->of_node; + struct resource clock_res; + void __iomem *dp_clock; + struct t8152_atc *atc; + int ret; + + atc = devm_kzalloc(disp->dev, sizeof(*atc), GFP_KERNEL); + if (!atc) + return -ENOMEM; + ret = of_property_match_string(np, "reg-names", "dp-clock"); + if (ret < 0 || of_address_to_resource(np, ret, &clock_res)) + return -EINVAL; + /* Older J873 DTs describe ATC3's divider alone; each ATC has its own. */ + if (resource_size(&clock_res) == 4 && clock_res.start == 0x30002005cULL) + clock_res.start -= 3 * 8; + if (resource_size(&clock_res) < 28) + return -EINVAL; + dp_clock = devm_ioremap(disp->dev, clock_res.start, resource_size(&clock_res)); + if (!dp_clock) + return -ENOMEM; + /* Shared AUX0 is serialized by atc_aux_lock. */ + atc->aux.regs = atc_map(disp, np, "aux"); + atc->aux.ps = atc_map(disp, np, "aux-ps"); + if (!atc->aux.ps) + atc->aux.regs = NULL; + + guard(mutex)(&atc_owner_lock); + /* One child per USB-C port, or the node itself for ATC3 alone. */ + for_each_child_of_node_scoped(np, child) { + if (!of_property_present(child, "apple,dfp-endpoint")) + continue; + if (atc->nports == ARRAY_SIZE(atc->port)) + break; + ret = atc_port_init(disp, atc, child, dp_clock); + if (ret) + return ret; + } + if (!atc->nports) { + ret = atc_port_init(disp, atc, np, dp_clock); + if (ret) + return ret; + } + + /* Only adopt a bootloader route belonging to this DCP. */ + atc->cur = &atc->port[0]; + for (unsigned int i = 0; i < atc->nports; i++) { + if (atc->port[i].active) { + atc->cur = &atc->port[i]; + atc_owner[atc->cur->index] = disp->dev; + break; + } + } + atc->next = atc->cur; + disp->phy = &atc_ops; + disp->phy_priv = atc; + disp->usbc = true; + disp->dcp_output = atc->cur->dfp; + dev_info(disp->dev, "USB-C display on ATC%u (%u ports)\n", atc->cur->index, + atc->nports); + return 0; +} diff --git a/drivers/gpu/drm/apple/t8152_aux.c b/drivers/gpu/drm/apple/t8152_aux.c new file mode 100644 index 0000000000000..8e2dbd2d2bd0c --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_aux.c @@ -0,0 +1,200 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The T8152 AP's DisplayPort AUX controllers aux0 and aux1: Analogix-derived + * DPTX cores with their own request framing. They attach to the display + * crossbar as UFP endpoints 5 and 6; the PHY code routes one to its port + * for the time of a read. Used for the sink's EDID, which the DCP firmware + * does not hand out on its iBoot interface. + * + * Interim, until the DCP's DPAV service or a DRM DP AUX channel provides the + * EDID on T8152. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "t8152_display.h" + +#define AUX_TIMEOUT_US 10000 +#define AUX_SEL 0x000 /* output: 9 crossbar UFP aux0, 0x10 lpdptx PHY */ +#define AUX_FUNC_EN_2 0x01c +#define AUX_FUNC_EN_N BIT(2) +#define AUX_HW_RETRY 0x390 +#define AUX_INT_STA 0x3dc +#define AUX_REPLY BIT(1) +#define AUX_ERROR BIT(0) +#define AUX_CH_STA 0x780 +#define AUX_DEFER_CTL 0x788 +#define AUX_RX_COMM 0x78c +#define AUX_BUF_CTL 0x790 +#define AUX_BUF_CLR BIT(9) +#define AUX_BUF_COUNT GENMASK(8, 0) +#define AUX_LEN 0x794 +#define AUX_ADDR_7_0 0x798 +#define AUX_ADDR_15_8 0x79c +#define AUX_CMD_ADDR 0x7a0 /* request in [7:4], address [19:16] */ +#define AUX_CTL 0x7a4 +#define AUX_GO BIT(0) +#define AUX_ADDR_ONLY BIT(1) +#define AUX_DATA 0xc00 /* one byte per word */ +#define AUX_MAX 16 + +#define AUX_NATIVE_WRITE 0x80 +#define AUX_I2C_WRITE 0x00 +#define AUX_I2C_READ 0x10 +#define AUX_I2C_MOT 0x40 +#define DDC_ADDR 0x50 +#define DPCD_SET_POWER 0x600 +#define DP_SET_POWER_D0 1 + +static void aux_update(void __iomem *reg, u32 mask, u32 value) +{ + writel((readl(reg) & ~mask) | value, reg); +} + +int t8152_aux_init(struct t8152_display *disp, struct t8152_aux *aux) +{ + u32 reg; + + /* PMGR power state of the controller */ + aux_update(aux->ps, 0xf, 0xf); + if (readl_poll_timeout(aux->ps, reg, ((reg >> 4) & 0xf) == 0xf, 1, + AUX_TIMEOUT_US)) { + dev_err(disp->dev, "AUX: controller does not power up\n"); + return -ETIMEDOUT; + } + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, AUX_FUNC_EN_N); + usleep_range(10, 20); + aux_update(aux->regs + AUX_FUNC_EN_2, AUX_FUNC_EN_N, 0); + /* + * Bits 21:8 of AUX_HW_RETRY are a 14-bit reply timeout, not Analogix's + * three-bit expected-delay field: the value 3 let native reads pass + * but timed out the EDID through a USB-C to HDMI adapter. 3200, with + * a retry interval of 3. + */ + writel((3200 << 8) | (3 << 3), aux->regs + AUX_HW_RETRY); + writel(BIT(7) | 1, aux->regs + AUX_DEFER_CTL); + aux_update(aux->regs + AUX_SEL, 0x3f, aux->sel); + return 0; +} + +/* One AUX request of up to 16 bytes; returns the bytes transferred. */ +static int aux_xfer(struct t8152_aux *aux, u32 cmd, u32 addr, u8 *buf, + u32 len, bool write) +{ + u32 sta, n; + int i; + + for (int tries = 0; tries < 7; tries++) { + writel(AUX_BUF_CLR, aux->regs + AUX_BUF_CTL); + writel(len ? len - 1 : 0, aux->regs + AUX_LEN); + writel(addr & 0xff, aux->regs + AUX_ADDR_7_0); + writel((addr >> 8) & 0xff, aux->regs + AUX_ADDR_15_8); + writel((cmd & 0xf0) | ((addr >> 16) & 0xf), aux->regs + AUX_CMD_ADDR); + aux_update(aux->regs + AUX_CTL, AUX_ADDR_ONLY, len ? 0 : AUX_ADDR_ONLY); + for (i = 0; write && i < len; i++) + writel(buf[i], aux->regs + AUX_DATA + 4 * i); + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + aux_update(aux->regs + AUX_CTL, AUX_GO, AUX_GO); + if (readl_poll_timeout(aux->regs + AUX_INT_STA, sta, + sta & (AUX_REPLY | AUX_ERROR), 10, 20000)) + return -ETIMEDOUT; + writel(AUX_REPLY | AUX_ERROR, aux->regs + AUX_INT_STA); + if ((sta & AUX_ERROR) || (readl(aux->regs + AUX_CH_STA) & 0xf)) + return -EIO; + /* [3:2] I2C and [1:0] AUX reply: 0 ACK, 1 NACK, 2 DEFER */ + sta = readl(aux->regs + AUX_RX_COMM); + if (sta & 0x5) + return -ENXIO; + if (sta & 0xa) { + usleep_range(500, 1000); + continue; + } + if (write) + return len; + n = min(readl(aux->regs + AUX_BUF_CTL) & AUX_BUF_COUNT, len); + for (i = 0; i < n; i++) + buf[i] = readl(aux->regs + AUX_DATA + 4 * i); + return n; + } + return -EBUSY; +} + +/* DDC over I2C-over-AUX: offset 0, then 16-byte reads up to @size. */ +static int aux_ddc_read(struct t8152_aux *aux, u8 *buf, size_t size) +{ + u8 offset = 0; + size_t done = 0; + int ret; + + ret = aux_xfer(aux, AUX_I2C_WRITE | AUX_I2C_MOT, DDC_ADDR, &offset, 1, true); + while (ret >= 0 && done < size) { + ret = aux_xfer(aux, AUX_I2C_READ | AUX_I2C_MOT, DDC_ADDR, + buf + done, min_t(size_t, size - done, AUX_MAX), + false); + if (ret > 0) + done += ret; + else if (!ret) + ret = -EIO; + } + /* End the I2C transaction with an address-only read without MOT. */ + aux_xfer(aux, AUX_I2C_READ, DDC_ADDR, NULL, 0, false); + return ret < 0 ? ret : done; +} + +/* + * The EDID over DDC, the base block and its extensions; the sink answers + * AUX only some time after the path is up, and a sink just plugged in a + * little later still. + */ +int t8152_aux_read_edid(struct t8152_display *disp, struct t8152_aux *aux, + u8 *buf, size_t size) +{ + u8 d0 = DP_SET_POWER_D0; + int ret = -EIO, ext; + + for (int i = 0; i < 30 && (ret == -EIO || ret == -ETIMEDOUT); i++) { + msleep(i ? 100 : 20); + /* + * A sink left in D3 (after an unplug) NACKs DDC: wake it + * first, as the DP spec asks before AUX use. + */ + ret = aux_xfer(aux, AUX_NATIVE_WRITE, DPCD_SET_POWER, &d0, 1, true); + if (ret < 0) + continue; + usleep_range(1000, 2000); + ret = aux_ddc_read(aux, buf, min_t(size_t, size, EDID_LENGTH)); + } + if (ret != EDID_LENGTH) + return ret < 0 ? ret : -EIO; + ext = min_t(size_t, buf[0x7e], size / EDID_LENGTH - 1); + return ext ? aux_ddc_read(aux, buf, (1 + ext) * EDID_LENGTH) : ret; +} + +/* + * The controller named by np's "aux" and "aux-ps" regs (np need not be the + * DCP's own node); the PMGR register is mapped without claiming it. + */ +void t8152_aux_probe(struct t8152_display *disp, struct t8152_aux *aux, + u32 sel, struct device_node *np) +{ + int ps = of_property_match_string(np, "reg-names", "aux-ps"); + int regs = of_property_match_string(np, "reg-names", "aux"); + struct resource res; + + aux->sel = sel; + if (ps < 0 || regs < 0 || of_address_to_resource(np, ps, &res)) + return; + aux->ps = devm_ioremap(disp->dev, res.start, resource_size(&res)); + aux->regs = devm_of_iomap(disp->dev, np, regs, NULL); + if (IS_ERR(aux->regs) || !aux->ps) + aux->regs = NULL; +} diff --git a/drivers/gpu/drm/apple/t8152_display.h b/drivers/gpu/drm/apple/t8152_display.h new file mode 100644 index 0000000000000..f4aa562fb3810 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_display.h @@ -0,0 +1,141 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * The T8152 (Mac mini J873g) DisplayPort hardware behind a DCP's DPTX port + * that no subsystem driver covers yet: the ATC PHYs' DisplayPort lanes and + * their display crossbar route (t8152_atc.c), the HDMI port's dedicated + * DisplayPort PHY and PS190 converter (t8152_hdmi.c), the AP's DisplayPort + * AUX controllers that read the sink's EDID (t8152_aux.c), and the DPTX port + * service the DCP firmware calls into for the PHY (t8152_dptx.c). The rear + * USB-C ports' DisplayPort alt mode state comes from their Type-C port + * driver, through the ports' shared display switches (t8152_typec.c). + * + * Interim: the ATC DisplayPort mode moves to drivers/phy/apple/atc.c and the + * choice of port with DP alt mode to the Type-C route layer of dcp-fabric.c, + * each in its own change. Until then these files program the registers + * themselves, for the iBoot interface DCPs of iomfb_iboot.c alone. + */ +#ifndef __APPLE_T8152_DISPLAY_H__ +#define __APPLE_T8152_DISPLAY_H__ + +#include + +struct apple_dcp; +struct apple_epic_service_ops; +struct device; +struct device_node; +struct gpio_desc; +struct t8152_display; +struct t8152_hdmi; +struct t8152_typec; + +/* SET_DRIVE_SETTINGS and GET_DRIVE_SETTINGS records, one per lane */ +struct t8152_drive_settings { + __le32 format; + __le32 voltage; + __le32 pre_emphasis; +} __packed; + +/* The PHY behind the DCP's DPTX port; link rates in DPCD units. */ +struct t8152_phy_ops { + int (*activate)(struct t8152_display *disp); + int (*deactivate)(struct t8152_display *disp); + int (*set_link_rate)(struct t8152_display *disp, u32 rate); + /* optional */ + int (*set_lane_count)(struct t8152_display *disp, u32 lanes); + u32 (*max_lane_count)(struct t8152_display *disp); + int (*set_drive)(struct t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count); + int (*set_route)(struct t8152_display *disp, bool enable); + /* optional: plug orientation for the next activation */ + void (*set_orientation)(struct t8152_display *disp, bool flipped); + /* optional: the sink's EDID, returns its length */ + int (*read_edid)(struct t8152_display *disp, u8 *buf, size_t size); + /* + * optional: 1 with a sink on one of the PHY's ports, 0 without; the + * port it found is taken by select() in the plug path + */ + int (*detect)(struct t8152_display *disp, bool *flipped); + void (*select)(struct t8152_display *disp); + u32 max_link_rate; +}; + +/* The DPTX port state the firmware's calls set and read back. */ +struct t8152_port { + u32 link_rate; + u32 lanes; + /* the drive settings the firmware set last, for GET_DRIVE_SETTINGS */ + struct t8152_drive_settings drive[4]; + u32 drive_count; +}; + +/* An AP DisplayPort AUX controller, and its output select */ +struct t8152_aux { + void __iomem *regs; + void __iomem *ps; + u32 sel; +}; + +/* The DisplayPort side of one DCP */ +struct t8152_display { + struct apple_dcp *dcp; + struct device *dev; + /* display crossbar UFP endpoint of the DCP; DPTX port 0 */ + u32 dp_source; + /* display crossbar DFP endpoint the DCP drives */ + u32 dcp_output; + u32 die; + + const struct t8152_phy_ops *phy; + void *phy_priv; + /* optional sink HPD line (HDMI), polled; the last level seen */ + struct gpio_desc *hpd_gpio; + int hpd; + /* USB-C: plug and HPD come from the ports' display switches */ + bool usbc; + struct t8152_typec *typec; + /* HDMI PHY: DCPEXT0's, or the main DCP's on an HDMI-only boot */ + bool hdmi; + /* + * The HDMI port of the shared ports when the bootloader brought HDMI + * up on no DCP: taken while this DCP drives no USB-C display, with + * the USB-C PHY kept to switch back. + */ + struct t8152_hdmi *hdmi_port; + bool on_hdmi; + const struct t8152_phy_ops *usbc_phy; + void *usbc_phy_priv; + u32 usbc_output; + + struct t8152_port port[2]; +}; + +/* t8152_atc.c */ +int t8152_atc_init(struct t8152_display *disp); +bool t8152_atc_release(struct t8152_display *disp); + +/* t8152_hdmi.c */ +struct device_node *t8152_hdmi_node(void); +int t8152_hdmi_source(struct device_node *np); +int t8152_hdmi_init(struct t8152_display *disp, struct device_node *np); +int t8152_hdmi_port_init(struct t8152_display *disp, struct device_node *np); +void t8152_hdmi_port_poll(struct t8152_display *disp); + +/* t8152_aux.c */ +void t8152_aux_probe(struct t8152_display *disp, struct t8152_aux *aux, + u32 sel, struct device_node *np); +int t8152_aux_init(struct t8152_display *disp, struct t8152_aux *aux); +int t8152_aux_read_edid(struct t8152_display *disp, struct t8152_aux *aux, + u8 *buf, size_t size); + +/* t8152_typec.c, see also iomfb_iboot.h */ +int t8152_typec_init(struct t8152_display *disp); +int t8152_typec_sink(struct t8152_display *disp, u32 index, bool *flipped, + u32 *lanes); + +/* t8152_dptx.c */ +extern const struct apple_epic_service_ops t8152_dptx_port_ops; +int t8152_dptx_connect(struct t8152_display *disp, unsigned int port); +int t8152_dptx_disconnect(struct t8152_display *disp, unsigned int port); +int t8152_dptx_set_hpd(struct t8152_display *disp, unsigned int port, bool hpd); + +#endif diff --git a/drivers/gpu/drm/apple/t8152_dptx.c b/drivers/gpu/drm/apple/t8152_dptx.c new file mode 100644 index 0000000000000..14da33f3c7c3e --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_dptx.c @@ -0,0 +1,315 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The DPTX port service of a T8152 iBoot interface DCP: the calls the + * firmware makes into the AP for the PHY behind its DPTX port, and the + * port's release and HPD calls. + * + * dptxep.c serves the same calls for the PHYs of the PHY framework, the + * display crossbar mux and Thunderbolt tunnels. The T8152 PHYs are + * programmed by t8152_atc.c and t8152_hdmi.c instead: their link rate, + * lanes and drive settings are applied here, and the drive settings are + * read back as they were set. The port's connect and display request are + * dptxep.c's. Interim, until the T8152 PHYs are PHY framework providers + * and dptxep.c can host this service. + */ + +#include +#include +#include + +#include "afk.h" +#include "dcp-internal.h" +#include "dptx-service.h" +#include "dptxep.h" +#include "t8152_display.h" + +/* IOReturn values the firmware takes as call status */ +#define KIO_RETURN_ERROR 0xe00002bcU +#define KIO_RETURN_BAD_ARG 0xe00002c2U +#define KIO_RETURN_UNSUPPORTED 0xe00002c7U +#define KIO_RETURN_NOT_READY 0xe00002d8U + +static bool dptx_needs_port(u32 command) +{ + switch (command) { + case DPTX_APCALL_ACTIVATE: + case DPTX_APCALL_DEACTIVATE: + case DPTX_APCALL_WILL_CHANGE_LINKG_CONFIG: + case DPTX_APCALL_DID_CHANGE_LINK_CONFIG: + case DPTX_APCALL_SET_LINK_RATE: + case DPTX_APCALL_SET_DOWN_SPREAD: + case DPTX_APCALL_SET_ACTIVE_LANE_COUNT: + case DPTX_APCALL_SET_DRIVE_SETTINGS: + case DPTX_APCALL_GET_LINK_RATE: + case DPTX_APCALL_GET_ACTIVE_LANE_COUNT: + case DPTX_APCALL_GET_DRIVE_SETTINGS: + return true; + default: + return false; + } +} + +/* + * One call; the IOReturn status. Requests carry their argument, replies + * their value, at offset 16. @reply holds a copy of the request. + */ +static u32 dptx_apcall(struct t8152_display *disp, struct t8152_port *port, + u16 group, u32 command, const void *data, size_t data_size, + void *reply, size_t reply_size) +{ + const struct t8152_phy_ops *phy = disp->phy; + u64 value; + u32 arg; + + if (group && !(group == 1 && (command == DPTX_APCALL_SET_DRIVE_SETTINGS || + command == DPTX_APCALL_GET_DRIVE_SETTINGS))) + return KIO_RETURN_UNSUPPORTED; + + if ((!port || !phy) && dptx_needs_port(command)) + return KIO_RETURN_NOT_READY; + + switch (command) { + case DPTX_APCALL_ACTIVATE: + if (phy->activate(disp)) + return KIO_RETURN_ERROR; + port->link_rate = LINK_RATE_HBR; + return 0; + case DPTX_APCALL_DEACTIVATE: + if (phy->deactivate(disp)) + return KIO_RETURN_ERROR; + port->link_rate = 0; + return 0; + case DPTX_APCALL_WILL_CHANGE_LINKG_CONFIG: + case DPTX_APCALL_DID_CHANGE_LINK_CONFIG: + return phy->set_route(disp, command == + DPTX_APCALL_DID_CHANGE_LINK_CONFIG) ? + KIO_RETURN_ERROR : 0; + case DPTX_APCALL_GET_MAX_LINK_RATE: + value = phy ? phy->max_link_rate : LINK_RATE_HBR; + break; + case DPTX_APCALL_GET_LINK_RATE: + value = port->link_rate; + break; + case DPTX_APCALL_SET_LINK_RATE: + if (data_size < 17) + return KIO_RETURN_BAD_ARG; + arg = ((const u8 *)data)[16]; + if (arg > phy->max_link_rate) + return KIO_RETURN_UNSUPPORTED; + if (phy->set_link_rate(disp, arg)) + return KIO_RETURN_ERROR; + port->link_rate = arg; + return 0; + case DPTX_APCALL_GET_MAX_LANE_COUNT: + value = phy && phy->max_lane_count ? phy->max_lane_count(disp) : 4; + break; + case DPTX_APCALL_GET_ACTIVE_LANE_COUNT: + value = port->lanes; + break; + case DPTX_APCALL_SET_ACTIVE_LANE_COUNT: + if (data_size < 20) + return KIO_RETURN_BAD_ARG; + arg = get_unaligned_le32(data + 16); + if (arg == 3 || arg > 4) + return KIO_RETURN_BAD_ARG; + dev_info(disp->dev, "DPTX: %u active lanes\n", arg); + if (phy->set_lane_count && phy->set_lane_count(disp, arg)) + return KIO_RETURN_ERROR; + port->lanes = arg; + return 0; + case DPTX_APCALL_GET_MAX_DRIVE_SETTINGS: { + const struct t8152_drive_settings maximum = { + 0, cpu_to_le32(3), cpu_to_le32(3) + }; + + if (reply_size < 16 + sizeof(maximum)) + return KIO_RETURN_BAD_ARG; + memcpy(reply + 16, &maximum, sizeof(maximum)); + return 0; + } + case DPTX_APCALL_SET_DRIVE_SETTINGS: { + struct t8152_drive_settings settings[4]; + + if (group != 1) + return KIO_RETURN_UNSUPPORTED; + if (data_size < 32) + return KIO_RETURN_BAD_ARG; + arg = get_unaligned_le32(data + 16); + if (arg > 4 || data_size < 32 + arg * sizeof(settings[0])) + return KIO_RETURN_BAD_ARG; + memcpy(settings, data + 32, arg * sizeof(settings[0])); + if (phy->set_drive(disp, settings, arg)) + return KIO_RETURN_ERROR; + memcpy(port->drive, settings, arg * sizeof(settings[0])); + port->drive_count = arg; + return 0; + } + case DPTX_APCALL_GET_DRIVE_SETTINGS: + /* + * The firmware reads back what it set during link training; an + * unsupported reply here was followed by a firmware crash. + * Same layout as SET: count at 16, settings from 32. + */ + if (group != 1) + return KIO_RETURN_UNSUPPORTED; + if (reply_size < 32 + port->drive_count * sizeof(port->drive[0])) + return KIO_RETURN_BAD_ARG; + put_unaligned_le32(port->drive_count, reply + 16); + memcpy(reply + 32, port->drive, + port->drive_count * sizeof(port->drive[0])); + return 0; + case DPTX_APCALL_SET_DOWN_SPREAD: + if (data_size < 17) + return KIO_RETURN_BAD_ARG; + /* The link is set up with downspread disabled. */ + return ((const u8 *)data)[16] ? KIO_RETURN_UNSUPPORTED : 0; + case DPTX_APCALL_GET_SUPPORTS_DOWN_SPREAD: + case DPTX_APCALL_GET_DOWN_SPREAD: + case DPTX_APCALL_GET_SUPPORTS_LANE_MAPPING: + case DPTX_APCALL_GET_VIRTUAL_DEVICE_MODE: + value = 0; + break; + case DPTX_APCALL_GET_SUPPORTS_HPD: + value = 1; + break; + case DPTX_APCALL_INACTIVE_SINK_DETECTED: + case DPTX_APCALL_DEVICE_NOT_RESPONDING: + case DPTX_APCALL_DEVICE_BUSY_TIMEOUT: + case DPTX_APCALL_DEVICE_NOT_STARTED: + /* Link fault reports: acknowledged with a zero status. */ + dev_info(disp->dev, "DPTX: firmware reports link fault %u\n", + command); + return 0; + case DPTX_APCALL_SET_TILED_DISPLAY_HINTS: + /* Acknowledged, the hints unused. */ + return 0; + default: + dev_info(disp->dev, "DPTX: unsupported call %u\n", command); + return KIO_RETURN_UNSUPPORTED; + } + + if (reply_size < 16 + sizeof(value)) + return KIO_RETURN_BAD_ARG; + put_unaligned_le64(value, reply + 16); + return 0; +} + +/* + * The reply starts as a copy of the request and carries the call's status + * in its first word; the transport status is always success. + */ +static int t8152_dptx_call(struct apple_epic_service *service, u16 group, + u32 command, const void *data, size_t size, + void *reply, size_t room) +{ + struct apple_dcp *dcp = service->ep->dcp; + struct dptx_port *dptx = service->cookie; + struct t8152_display *disp = READ_ONCE(dcp->t8152); + u32 status; + + dev_dbg(dcp->dev, "DPTX: port %d group %u command %u size %zu\n", + dptx ? (int)dptx->unit : -1, group, command, size); + memcpy(reply, data, min(room, size)); + if (disp) + status = dptx_apcall(disp, dptx ? &disp->port[dptx->unit] : NULL, + group, command, data, size, reply, room); + else + status = KIO_RETURN_NOT_READY; + if (status) + dev_dbg(dcp->dev, "DPTX: group %u command %u -> %#x\n", group, + command, status); + put_unaligned_le32(status, reply); + return 0; +} + +/* + * The ports in the order the firmware announces them. A further service is + * opened as well, without a port. + */ +static int t8152_dptx_prepare(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + struct apple_dcp *dcp = service->ep->dcp; + + for (unsigned int i = 0; i < ARRAY_SIZE(dcp->dptxport); i++) + if (!dcp->dptxport[i].service) + return dptx_service_bind(service, &dcp->dptxport[i], i); + return 0; +} + +static void t8152_dptx_init(struct apple_epic_service *service, + const char *name, const char *class, s64 unit) +{ + if (service->cookie) + dptx_service_publish(service); +} + +/* Bound to every service of the DPTX endpoint (afk unmatched_ops). */ +const struct apple_epic_service_ops t8152_dptx_port_ops = { + .name = "dcpdptx-port", + .prepare = t8152_dptx_prepare, + .init = t8152_dptx_init, + .call_v2 = t8152_dptx_call, +}; + +static struct apple_epic_service *t8152_dptx_service(struct t8152_display *disp, + unsigned int port) +{ + struct dptx_port *dptx = &disp->dcp->dptxport[port]; + + return dptx_service_available(dptx) ? dptx->service : NULL; +} + +/* Connect the port to the PHY the DCP drives and request the display. */ +int t8152_dptx_connect(struct t8152_display *disp, unsigned int port) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + int ret; + + if (!service) + return -ENODEV; + ret = dptxport_connect(service, 0, disp->dcp_output, disp->die, true); + if (!ret) + ret = dptxport_request_display(service); + return ret; +} + +/* + * HPD as the port reports it to the firmware (group 8, command 8): the + * reply's first word is the call's status. + */ +int t8152_dptx_set_hpd(struct t8152_display *disp, unsigned int port, bool hpd) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + struct { + u8 pad[16]; + __le32 hpd; + } __packed cmd = { .hpd = cpu_to_le32(hpd) }, resp = {}; + size_t received; + int ret; + + if (!service) + return -ENODEV; + ret = afk_service_call_len(service, 8, 8, &cmd, sizeof(cmd), 12, &resp, + sizeof(resp), 12, &received); + if (ret) + return ret; + return get_unaligned_le32(resp.pad) ? -EIO : 0; +} + +/* Release the display (group 8, command 7), then HPD low. */ +int t8152_dptx_disconnect(struct t8152_display *disp, unsigned int port) +{ + struct apple_epic_service *service = t8152_dptx_service(disp, port); + __le32 status = 0; + size_t received; + int ret; + + if (!service) + return -ENODEV; + ret = afk_service_call_len(service, 8, 7, NULL, 0, 16, &status, + sizeof(status), 12, &received); + if (ret || status) + return ret ?: -EIO; + return t8152_dptx_set_hpd(disp, port, false); +} diff --git a/drivers/gpu/drm/apple/t8152_hdmi.c b/drivers/gpu/drm/apple/t8152_hdmi.c new file mode 100644 index 0000000000000..5b11879b1724b --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_hdmi.c @@ -0,0 +1,669 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The J873g HDMI port: the T8152's dedicated DisplayPort PHY in display + * crossbar 0's lpdptx slot, converted by a PS190. + * + * Interim, until drivers/phy/apple/dptx.c has a T8152 type (its lanes are + * 0x2800 apart from 0x4500) and the PS190's power through the SMC is + * described as a supply: this programs the PHY and powers the converter + * itself. + * + * When the bootloader brought HDMI up, this keeps its setup and reprograms + * what a link training changes: the PLL for a new link rate and the active + * lanes. Drive settings are only recorded, and there is no per-link route. + * When it did not (no HDMI monitor at boot, or a USB-C display on the main + * DCP), the HDMI port joins the shared USB-C ports: a DCP without a USB-C + * display takes it on a plug and starts the PHY and the PS190 from cold. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "dptxep.h" +#include "t8152_display.h" + +#define HDMI_LANES 4 +#define HDMI_LANE0 0x4500 +#define HDMI_LANE_STRIDE 0x2800 + +struct t8152_hdmi { + void __iomem *core; + void __iomem *apb; + /* AP DisplayPort AUX controller aux1, for the EDID */ + struct t8152_aux aux; + /* The cold start of the HDMI port taken from the shared ports: */ + void __iomem *ps; /* PMGR power state of the PHY */ + void __iomem *psd; /* PMGR PSD service of the PHY */ + struct gpio_desc *hpd; + struct device_node *smc_np; + const __be32 *pcon, *tunable; + int pcon_len, tunable_len; + bool active; +}; + +/* + * The DCP driving the HDMI port taken from the shared ports, if any, and its + * HPD line, requested once for all the DCPs that may take the port. + */ +static DEFINE_MUTEX(hdmi_port_lock); +static struct device *hdmi_port_owner; +static struct gpio_desc *hdmi_port_hpd; +static unsigned int hdmi_port_users; + +#define HDMI_PS_TARGET GENMASK(3, 0) +#define HDMI_PS_ACTUAL GENMASK(7, 4) +#define HDMI_PS_FLAGS GENMASK(9, 8) /* write-one-to-clear */ +#define HDMI_PSD_STATE 0x80 +#define HDMI_PSD_TARGET 0x90 +#define HDMI_POWER_TIMEOUT_US 100000 + +/* APB 0x10 bits 3:0: the crossbar UFP feeding the PHY */ +#define HDMI_SOURCE_SELECT 0x10 +#define HDMI_SOURCE_AUX1 6 /* UFP endpoint of the aux1 controller */ + +static void hdmi_set_bits(struct t8152_hdmi *hdmi, u32 offset, u32 shift, + u32 mask, u32 value) +{ + u32 reg = readl(hdmi->core + offset); + + writel((reg & ~mask) | (value << shift), hdmi->core + offset); +} + +static void hdmi_apb_update(struct t8152_hdmi *hdmi, u32 offset, u32 mask, + u32 value) +{ + u32 reg = readl(hdmi->apb + offset); + + writel((reg & ~mask) | value, hdmi->apb + offset); +} + +/* The PLL configuration words for each link rate (DPCD units). */ +static const struct { + u32 rate; + u32 w[22]; +} hdmi_pll_configs[] = { + { LINK_RATE_RBR, + { 1, 0x21c, 0, 0, 1, 0x13, 1, 0, 0, 0x1a, 1, 0x3c, 2, 1, 0, 0, 1, 0, + 0, 0, 1, 3 } }, + { LINK_RATE_HBR, + { 1, 0x1c2, 0x1fff, 0x3ffe, 1, 0x13, 1, 0, 0, 0x1a, 1, 0x32, 2, 1, 0, + 0, 1, 0, 0, 0, 1, 3 } }, + { LINK_RATE_HBR2, + { 0, 0x1c2, 0x1fff, 0x3ffe, 1, 9, 1, 0, 0, 0x1a, 1, 0x32, 1, 0, 0, 1, + 0, 0, 0, 1, 1, 3 } }, + { LINK_RATE_HBR3, + { 0, 0x2a3, 0x2ffd, 0x3ffc, 1, 9, 1, 0, 0, 0x1a, 1, 0x5a, 1, 0, 0, 1, + 0, 0, 0, 1, 1, 3 } }, +}; + +/* A PLL command: command in 0x408[2:0], request bit 3, acknowledge bit 19. */ +static int hdmi_pll_command(struct t8152_display *disp, struct t8152_hdmi *hdmi, + u32 command) +{ + int i; + + hdmi_set_bits(hdmi, 0x408, 6, 0x40, 1); + hdmi_set_bits(hdmi, 0x408, 0, 0x7, command); + hdmi_set_bits(hdmi, 0x408, 3, 0x8, 1); + for (i = 0; i < 10; i++) { + usleep_range(16, 32); + if (readl(hdmi->core + 0x408) & BIT(19)) + break; + } + hdmi_set_bits(hdmi, 0x408, 3, 0x8, 0); + hdmi_set_bits(hdmi, 0x408, 6, 0x40, 0); + if (i == 10) { + dev_err(disp->dev, "HDMI: no ACK to PLL command %u\n", command); + return -ETIMEDOUT; + } + return 0; +} + +/* The lane-disable bits of each lane; 0x2420 holds the mask of unused lanes. */ +static void hdmi_set_lanes(struct t8152_hdmi *hdmi, u32 lanes) +{ + static const u32 offsets[] = { 0x64, 0x24, 0x24, 0x48, 0x48, 0x5c, 0x5c, 0x48 }; + static const u32 shifts[] = { 4, 4, 1, 0, 1, 2, 3, 4 }; + static const u32 masks[] = { 0x10, 0x10, 0x2, 0x1, 0x2, 0x4, 0x8, 0x10 }; + u32 lane, i; + + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 0); + for (lane = 0; lane < HDMI_LANES; lane++) { + u32 base = HDMI_LANE0 + lane * HDMI_LANE_STRIDE; + + for (i = 0; i < ARRAY_SIZE(offsets); i++) + hdmi_set_bits(hdmi, base + offsets[i], shifts[i], + masks[i], lane >= lanes); + } + hdmi_set_bits(hdmi, 0x2420, 0, 0xf, 0xf & ~((1 << lanes) - 1)); + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 1); +} + +static int hdmi_activate(struct t8152_display *disp) +{ + return 0; +} + +static int hdmi_deactivate(struct t8152_display *disp) +{ + dev_info(disp->dev, "HDMI: keeping the link up on deactivate\n"); + return 0; +} + +/* + * A new link rate: lanes off, PLL down, the PLL frequency, half link rate, + * PLL up again. + */ +static int hdmi_set_link_rate(struct t8152_display *disp, u32 rate) +{ + struct t8152_hdmi *hdmi = disp->phy_priv; + const u32 *w = NULL; + bool half; + size_t i; + int ret; + + for (i = 0; i < ARRAY_SIZE(hdmi_pll_configs); i++) + if (hdmi_pll_configs[i].rate == rate) + w = hdmi_pll_configs[i].w; + if (!w) + return -EINVAL; + + dev_info(disp->dev, "HDMI: link rate %#x\n", rate); + hdmi_set_bits(hdmi, 0x2400, 0, 0x1, 0); + ret = hdmi_pll_command(disp, hdmi, 0); + if (ret) + return ret; + + /* The PLL frequency, downspread off */ + hdmi_set_bits(hdmi, 0x6c0, 0, 0x7ff, w[1]); + hdmi_set_bits(hdmi, 0x6c0, 11, 0x800, w[6]); + hdmi_set_bits(hdmi, 0x6c0, 13, 0x2000, w[10]); + hdmi_set_bits(hdmi, 0x6c0, 18, 0x3c0000, w[21]); + hdmi_set_bits(hdmi, 0x6c4, 14, 0xfffc000, w[2]); + hdmi_set_bits(hdmi, 0x6c4, 0, 0x3fff, + (!(w[7] & 1) && w[2] < 2) ? 0 : w[3]); + hdmi_set_bits(hdmi, 0x6c8, 14, 0xc000, w[0]); + hdmi_set_bits(hdmi, 0x6c8, 8, 0x100, 0); + hdmi_set_bits(hdmi, 0x6c8, 0, 0xff, w[8]); + hdmi_set_bits(hdmi, 0x6c8, 9, 0x3e00, w[5]); + hdmi_set_bits(hdmi, 0x6c8, 16, 0x10000, w[17]); + hdmi_set_bits(hdmi, 0x6c8, 26, 0xfc000000, w[9]); + hdmi_set_bits(hdmi, 0x6cc, 0, 0x7f, w[11]); + hdmi_set_bits(hdmi, 0x6cc, 9, 0x600, w[13]); + hdmi_set_bits(hdmi, 0x6cc, 11, 0x7800, w[14]); + hdmi_set_bits(hdmi, 0x6cc, 15, 0x38000, w[15]); + hdmi_set_bits(hdmi, 0x6cc, 20, 0x100000, w[16]); + hdmi_set_bits(hdmi, 0x6cc, 21, 0x200000, w[18]); + hdmi_set_bits(hdmi, 0x6cc, 22, 0xc00000, w[19]); + hdmi_set_bits(hdmi, 0x6cc, 24, 0x3000000, w[4]); + hdmi_set_bits(hdmi, 0x6cc, 26, 0xc000000, w[20]); + + /* Latch the link rate dependent shadow registers (APB 0xa0). */ + hdmi_apb_update(hdmi, 0xa0, BIT(3), BIT(3)); + hdmi_apb_update(hdmi, 0xa0, BIT(2), BIT(2)); + hdmi_apb_update(hdmi, 0xa0, BIT(18), BIT(18)); + hdmi_apb_update(hdmi, 0xa0, BIT(18), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(19), BIT(19)); + hdmi_apb_update(hdmi, 0xa0, BIT(19), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(2), 0); + hdmi_apb_update(hdmi, 0xa0, BIT(3), 0); + + /* No UHBR rates; half link rate from HBR up. */ + half = rate >= LINK_RATE_HBR; + hdmi_set_bits(hdmi, 0x2400, 2, 0x4, 0); + hdmi_set_bits(hdmi, 0x2400, 3, 0x8, !half); + hdmi_set_bits(hdmi, 0x0000, 17, 0x20000, !half); + + ret = hdmi_pll_command(disp, hdmi, 7); + if (ret) + return ret; + if (!(readl(hdmi->core + 0x438) & BIT(30))) { + dev_err(disp->dev, "HDMI: PLL failed to lock at rate %#x\n", rate); + return -EIO; + } + return 0; +} + +static int hdmi_set_lane_count(struct t8152_display *disp, u32 lanes) +{ + /* The PHY takes no zero lane count. */ + if (lanes) + hdmi_set_lanes(disp->phy_priv, lanes); + return 0; +} + +static int hdmi_set_drive(struct t8152_display *disp, + const struct t8152_drive_settings *settings, u32 count) +{ + return 0; +} + +static int hdmi_set_route(struct t8152_display *disp, bool enable) +{ + return 0; +} + +/* + * The sink's EDID through the AP AUX controller aux1: the PHY takes its + * source from aux1 for the read (its AUX reaches the PS190, which reads the + * monitor's DDC), then from the DCP again. The display is off meanwhile. + */ +static int hdmi_read_edid(struct t8152_display *disp, u8 *buf, size_t size) +{ + struct t8152_hdmi *hdmi = disp->phy_priv; + u32 src; + int ret; + + if (!hdmi->aux.regs) + return -ENODEV; + ret = t8152_aux_init(disp, &hdmi->aux); + if (ret) + return ret; + src = readl(hdmi->apb + HDMI_SOURCE_SELECT); + writel((src & ~0xf) | HDMI_SOURCE_AUX1, hdmi->apb + HDMI_SOURCE_SELECT); + ret = t8152_aux_read_edid(disp, &hdmi->aux, buf, size); + writel(src, hdmi->apb + HDMI_SOURCE_SELECT); + return ret; +} + +static const struct t8152_phy_ops hdmi_ops = { + .activate = hdmi_activate, + .deactivate = hdmi_deactivate, + .set_link_rate = hdmi_set_link_rate, + .set_lane_count = hdmi_set_lane_count, + .set_drive = hdmi_set_drive, + .set_route = hdmi_set_route, + .read_edid = hdmi_read_edid, + .max_link_rate = LINK_RATE_HBR3, +}; + +/* + * The PS190's power through the SMC: the {key, value} writes of + * apple,pcon-power. The PS190 drives the HDMI HPD line only while it is + * powered, and the AP AUX controller that reads the USB-C monitors' EDID + * gets no reply from any USB-C port while it is off. Nothing here waits + * for it to come up: a DCP takes the port only once it sees HPD + * (t8152_hdmi_port_poll()), and an EDID read retries until the AUX + * replies (t8152_aux_read_edid()). On a port taken over, these writes find + * the PS190 powered since probe. + */ +static int hdmi_pcon_power(struct t8152_display *disp, struct t8152_hdmi *hdmi) +{ + struct platform_device *smc_pdev = of_find_device_by_node(hdmi->smc_np); + struct apple_smc *smc = smc_pdev ? platform_get_drvdata(smc_pdev) : NULL; + int ret = 0; + + if (!smc) { + ret = -EPROBE_DEFER; + goto out; + } + for (int i = 0; i + 3 <= hdmi->pcon_len; i += 3) { + u64 value = (u64)be32_to_cpu(hdmi->pcon[i + 1]) << 32 | + be32_to_cpu(hdmi->pcon[i + 2]); + + ret = apple_smc_write(smc, be32_to_cpu(hdmi->pcon[i]), &value, + sizeof(value)); + if (ret) { + dev_err(disp->dev, "HDMI: PS190 power failed: %d\n", ret); + goto out; + } + } +out: + if (smc_pdev) + put_device(&smc_pdev->dev); + return ret; +} + +/* The PHY's PMGR and PSD power, then the PS190's. */ +static int hdmi_power_up(struct t8152_display *disp, struct t8152_hdmi *hdmi) +{ + int ret; + u32 val; + + if ((readl(hdmi->ps) & HDMI_PS_ACTUAL) != HDMI_PS_ACTUAL) { + val = readl(hdmi->ps) & ~(HDMI_PS_TARGET | HDMI_PS_FLAGS); + writel(val | HDMI_PS_TARGET, hdmi->ps); + ret = readl_poll_timeout(hdmi->ps, val, + (val & HDMI_PS_ACTUAL) == HDMI_PS_ACTUAL, + 10, HDMI_POWER_TIMEOUT_US); + if (ret) { + dev_err(disp->dev, "HDMI: PHY power state stays %#x\n", val); + return ret; + } + } + if (readl(hdmi->psd + HDMI_PSD_STATE) & 7) { + writel(0, hdmi->psd + HDMI_PSD_TARGET); + ret = readl_poll_timeout(hdmi->psd + HDMI_PSD_STATE, val, !(val & 7), + 10, HDMI_POWER_TIMEOUT_US); + if (ret) { + dev_err(disp->dev, "HDMI: PHY PSD state stays %#x\n", val); + return ret; + } + } + return hdmi_pcon_power(disp, hdmi); +} + +/* The impedance calibration: wait for 0x1c04 bit 0, take 0x1c24 bits 12:6. */ +static void hdmi_impedance_calibration(struct t8152_display *disp, + struct t8152_hdmi *hdmi) +{ + u32 val; + + if (readl_poll_timeout(hdmi->core + 0x1c04, val, val & 1, 10, 1000000)) + dev_warn(disp->dev, "HDMI: impedance calibration timed out\n"); + hdmi_set_bits(hdmi, 0x1c00, 4, 0x3f0, 0x3f); + val = readl(hdmi->core + 0x1c24); + hdmi_set_bits(hdmi, 0x1c18, 15, 0x3f8000, (val >> 6) & 0x7f); + hdmi_set_bits(hdmi, 0x1c18, 14, 0x4000, 1); +} + +/* + * The cold start, as the bootloader does it: power, source select, PLL, AUX + * and PHY power, the tunables, the PLL and PHY activation, four lanes and + * the impedance calibration. Once up, the link is kept on deactivate, as + * for the bootloader's HDMI. + */ +static int hdmi_port_activate(struct t8152_display *disp) +{ + struct t8152_hdmi *hdmi = disp->phy_priv; + int ret; + + if (hdmi->active) + return 0; + ret = hdmi_power_up(disp, hdmi); + if (ret) + return ret; + /* The source select: only the low nibble */ + hdmi_apb_update(hdmi, HDMI_SOURCE_SELECT, 0xf, disp->dp_source); + /* PLL, AUX and PHY power enables */ + hdmi_apb_update(hdmi, 0x48, 0x010, 0x010); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x020, 0x020); + hdmi_apb_update(hdmi, 0x48, 0x040, 0); + hdmi_apb_update(hdmi, 0x48, 0x100, 0x100); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x200, 0x200); + hdmi_apb_update(hdmi, 0x48, 0x400, 0); + hdmi_apb_update(hdmi, 0x48, 0x001, 0x001); + usleep_range(1000, 2000); + hdmi_apb_update(hdmi, 0x48, 0x002, 0x002); + hdmi_apb_update(hdmi, 0x48, 0x004, 0); + + for (int i = 0; i + 3 <= hdmi->tunable_len; i += 3) { + void __iomem *reg = hdmi->core + be32_to_cpu(hdmi->tunable[i]); + + writel((readl(reg) & ~be32_to_cpu(hdmi->tunable[i + 1])) | + be32_to_cpu(hdmi->tunable[i + 2]), reg); + } + + hdmi_set_bits(hdmi, 0x08d0, 4, 0x10, 1); /* single-ended PLL clock */ + hdmi_set_bits(hdmi, 0x0000, 1, 0x02, 1); /* PLL on */ + hdmi_set_bits(hdmi, 0x1400, 0, 0x01, 0); /* AUX common control */ + hdmi_set_bits(hdmi, 0x1c00, 4, 0x3f0, 0x3c); /* PHY on */ + hdmi_set_bits(hdmi, 0x0000, 0, 0x01, 1); + usleep_range(1000, 2000); + hdmi_set_lanes(hdmi, HDMI_LANES); + hdmi_impedance_calibration(disp, hdmi); + hdmi->active = true; + dev_info(disp->dev, "HDMI: PHY up from cold, source %u\n", disp->dp_source); + return 0; +} + +static const struct t8152_phy_ops hdmi_port_ops = { + .activate = hdmi_port_activate, + .deactivate = hdmi_deactivate, + .set_link_rate = hdmi_set_link_rate, + .set_lane_count = hdmi_set_lane_count, + .set_drive = hdmi_set_drive, + .set_route = hdmi_set_route, + .read_edid = hdmi_read_edid, + .max_link_rate = LINK_RATE_HBR3, +}; + +/* Registers shared with the other DCPs that may take the HDMI port. */ +static void __iomem *hdmi_ioremap(struct t8152_display *disp, + struct device_node *np, const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + struct resource res; + + if (index < 0 || of_address_to_resource(np, index, &res)) + return NULL; + return devm_ioremap(disp->dev, res.start, resource_size(&res)); +} + +static void hdmi_put_smc(void *data) +{ + of_node_put(data); +} + +static void hdmi_port_put(void *data) +{ + guard(mutex)(&hdmi_port_lock); + if (!--hdmi_port_users) { + gpiod_put(hdmi_port_hpd); + hdmi_port_hpd = NULL; + } +} + +static struct gpio_desc *hdmi_port_get(struct t8152_display *disp, + struct device_node *np) +{ + struct gpio_desc *hpd; + int ret; + + scoped_guard(mutex, &hdmi_port_lock) { + if (!hdmi_port_users) { + hpd = fwnode_gpiod_get_index(of_fwnode_handle(np), "hpd", 0, + GPIOD_ASIS, "hdmi-hpd"); + if (IS_ERR(hpd)) + return hpd; + hdmi_port_hpd = hpd; + } + hdmi_port_users++; + hpd = hdmi_port_hpd; + } + ret = devm_add_action_or_reset(disp->dev, hdmi_port_put, NULL); + return ret ? ERR_PTR(ret) : hpd; +} + +/* + * The HDMI port of the shared ports, for every DCP: the PHY's source select + * takes each one's crossbar endpoint. Without the cold start description in + * np, HDMI stays the bootloader's. + */ +int t8152_hdmi_port_init(struct t8152_display *disp, struct device_node *np) +{ + struct t8152_hdmi *hdmi; + int ret; + + if (!of_property_present(np, "apple,pcon-power")) + return 0; + hdmi = devm_kzalloc(disp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_ioremap(disp, np, "phy-core"); + hdmi->apb = hdmi_ioremap(disp, np, "phy-apb"); + hdmi->ps = hdmi_ioremap(disp, np, "phy-ps"); + hdmi->psd = hdmi_ioremap(disp, np, "phy-psd"); + hdmi->aux.regs = hdmi_ioremap(disp, np, "aux"); + hdmi->aux.ps = hdmi_ioremap(disp, np, "aux-ps"); + /* AUX output select 0x10: the lpdptx PHY */ + hdmi->aux.sel = 0x10; + if (!hdmi->core || !hdmi->apb || !hdmi->ps || !hdmi->psd) + return -ENOMEM; + if (!hdmi->aux.ps) + hdmi->aux.regs = NULL; + hdmi->pcon = of_get_property(np, "apple,pcon-power", &hdmi->pcon_len); + hdmi->pcon_len /= sizeof(__be32); + hdmi->tunable = of_get_property(np, "apple,tunable-phy", + &hdmi->tunable_len); + hdmi->tunable_len /= sizeof(__be32); + hdmi->smc_np = of_parse_phandle(np, "apple,smc", 0); + if (!hdmi->smc_np) + return -EINVAL; + ret = devm_add_action_or_reset(disp->dev, hdmi_put_smc, hdmi->smc_np); + if (ret) + return ret; + /* Without the bootloader's HDMI nothing else powers the PS190. */ + ret = hdmi_pcon_power(disp, hdmi); + if (ret) + return ret; + /* Every DCP that may take the port watches the same line. */ + hdmi->hpd = hdmi_port_get(disp, np); + if (IS_ERR(hdmi->hpd)) + return PTR_ERR(hdmi->hpd); + disp->hdmi_port = hdmi; + dev_info(disp->dev, "HDMI: port shared, taken without a USB-C display\n"); + return 0; +} + +/* + * Take the HDMI port when a sink is plugged in and this DCP drives no USB-C + * display; give it back once the sink is gone and the plug path has + * released the link. Called from the connector's detect with the display + * lock held. + */ +void t8152_hdmi_port_poll(struct t8152_display *disp) +{ + struct t8152_hdmi *hdmi = disp->hdmi_port; + int hpd; + + if (!hdmi) + return; + hpd = gpiod_get_value_cansleep(hdmi->hpd); + if (hpd < 0) + return; + guard(mutex)(&hdmi_port_lock); + if (disp->on_hdmi) { + if (hpd || disp->hpd) + return; + disp->phy = disp->usbc_phy; + disp->phy_priv = disp->usbc_phy_priv; + disp->dcp_output = disp->usbc_output; + disp->hpd_gpio = NULL; + disp->on_hdmi = false; + hdmi_port_owner = NULL; + dev_info(disp->dev, "HDMI: port given back\n"); + return; + } + if (!hpd || disp->hpd || hdmi_port_owner || !t8152_atc_release(disp)) + return; + hdmi_port_owner = disp->dev; + disp->usbc_phy = disp->phy; + disp->usbc_phy_priv = disp->phy_priv; + disp->usbc_output = disp->dcp_output; + disp->phy = &hdmi_port_ops; + disp->phy_priv = hdmi; + /* display crossbar DFP endpoint lpdptx */ + disp->dcp_output = 4; + disp->hpd_gpio = hdmi->hpd; + disp->on_hdmi = true; + dev_info(disp->dev, "HDMI: sink plugged, taking the HDMI port\n"); +} + +/* The DCP node that describes the HDMI PHY (DCPEXT0's). */ +struct device_node *t8152_hdmi_node(void) +{ + struct device_node *np; + + for_each_compatible_node(np, NULL, "apple,t8152-dcp-iboot") + if (of_property_read_bool(np, "apple,hdmi")) + return np; + return NULL; +} + +static void __iomem *hdmi_map(struct device *dev, struct device_node *np, + const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + + if (index < 0) + return IOMEM_ERR_PTR(index); + return devm_of_iomap(dev, np, index, NULL); +} + +static bool hdmi_power_active(struct device_node *np, const char *name) +{ + int index = of_property_match_string(np, "reg-names", name); + void __iomem *regs; + u32 state; + + if (index < 0) + return false; + regs = of_iomap(np, index); + if (!regs) + return false; + state = readl(regs); + iounmap(regs); + /* Both the requested and actual PMGR states must be active. */ + return (state & GENMASK(7, 0)) == GENMASK(7, 0); +} + +/* + * The DCP the bootloader wired to the PHY (its source select: 0 for the main + * DCP on the HDMI-only route, 1 for DCPEXT0 next to a USB-C display), or + * -ENODEV if it left the PHY off or the PLL unlocked. + */ +int t8152_hdmi_source(struct device_node *np) +{ + int core = of_property_match_string(np, "reg-names", "phy-core"); + int apb = of_property_match_string(np, "reg-names", "phy-apb"); + void __iomem *core_regs, *apb_regs; + int ret = -ENODEV; + + /* The PHY aperture aborts while gated, including on a USB-C-only boot. */ + if (core < 0 || apb < 0 || !hdmi_power_active(np, "phy-ps")) + return -ENODEV; + core_regs = of_iomap(np, core); + apb_regs = of_iomap(np, apb); + if (core_regs && apb_regs && readl(core_regs + 0x438) & BIT(30)) + ret = readl(apb_regs + HDMI_SOURCE_SELECT) & 0xf; + if (apb_regs) + iounmap(apb_regs); + if (core_regs) + iounmap(core_regs); + if (ret == 1 && !hdmi_power_active(np, "coproc-ps")) + return -ENODEV; + if (ret != 0 && ret != 1) + return -ENODEV; + return ret; +} + +/* The PHY, its AUX controller and its HPD line come from np. */ +int t8152_hdmi_init(struct t8152_display *disp, struct device_node *np) +{ + struct t8152_hdmi *hdmi; + + hdmi = devm_kzalloc(disp->dev, sizeof(*hdmi), GFP_KERNEL); + if (!hdmi) + return -ENOMEM; + hdmi->core = hdmi_map(disp->dev, np, "phy-core"); + if (IS_ERR(hdmi->core)) + return PTR_ERR(hdmi->core); + hdmi->apb = hdmi_map(disp->dev, np, "phy-apb"); + if (IS_ERR(hdmi->apb)) + return PTR_ERR(hdmi->apb); + + /* AUX output select 0x10: the lpdptx PHY */ + t8152_aux_probe(disp, &hdmi->aux, 0x10, np); + + dev_info(disp->dev, "HDMI: inherited source select %u, PLL %slocked\n", + readl(hdmi->apb + HDMI_SOURCE_SELECT) & 0xf, + readl(hdmi->core + 0x438) & BIT(30) ? "" : "not "); + + disp->phy = &hdmi_ops; + disp->phy_priv = hdmi; + /* display crossbar DFP endpoint lpdptx */ + disp->dcp_output = 4; + return 0; +} diff --git a/drivers/gpu/drm/apple/t8152_typec.c b/drivers/gpu/drm/apple/t8152_typec.c new file mode 100644 index 0000000000000..0084afc02dbc9 --- /dev/null +++ b/drivers/gpu/drm/apple/t8152_typec.c @@ -0,0 +1,227 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * The rear USB-C ports' DisplayPort alt mode, from the USB Type-C port + * driver that owns their PD controllers. Each port has one Type-C mode + * switch for the display path, shared by all DCPs: the port's usb-c node in + * the shared ports node (apple,usb-c-ports), whose endpoint is at the display + * port of the port's connector. The Type-C class looks at three mode switches + * of a connector at most, and the port's PHY needs one as well, so there is + * no room for one per DCP. + * + * The first DCP that probes registers the switches, and they stay until the + * driver is unloaded: the port driver keeps using a switch it found, and + * must not wait for a DCP that cannot start. A switch records what the + * display path reads (DisplayPort alt mode with HPD high, the lanes of the + * pin assignment, the plug orientation) and has every DCP that drives USB-C + * look at its ports; t8152_atc.c claims a port for one of them. + * + * The switches are dcp-fabric.c's in the device tree only. Its route layer + * switches a DP PHY and the display crossbar through their own drivers and + * connects the sink through the DCP's IOMFB DPTX service; these DCPs program + * the ATC PHY and the crossbar themselves and connect through the iBoot + * interface's DPTX port service, so their switches record the state alone. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "iomfb_iboot.h" +#include "t8152_display.h" + +/* The ATC instances, as the display crossbar's DFP endpoints number them */ +#define T8152_TYPEC_PORTS 4 + +struct t8152_typec_port { + struct typec_mux_dev *mux; + /* below under t8152_typec_lock */ + bool sink; + bool flipped; + u32 lanes; +}; + +/* A DCP that drives USB-C, told about the ports' changes */ +struct t8152_typec { + struct list_head node; + struct t8152_display *disp; +}; + +/* Registers the switches, once */ +static DEFINE_MUTEX(t8152_typec_register_lock); +/* The ports' state, written by the port driver, and the DCPs that read it */ +static DEFINE_SPINLOCK(t8152_typec_lock); +static struct t8152_typec_port t8152_typec_ports[T8152_TYPEC_PORTS]; +static LIST_HEAD(t8152_typec_displays); + +static int t8152_typec_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + struct t8152_typec_port *port = typec_mux_get_drvdata(mux); + struct typec_displayport_data *dp = NULL; + struct t8152_typec *typec; + bool flipped = false; + u32 lanes = 4; + + if (state->alt && state->alt->svid == USB_TYPEC_DP_SID && + state->mode >= TYPEC_DP_STATE_A && state->mode <= TYPEC_DP_STATE_F) { + dp = state->data; + flipped = typec_altmode_get_orientation(state->alt) == + TYPEC_ORIENTATION_REVERSE; + /* B, D and F share the cable with USB 3: two DisplayPort lanes */ + if (state->mode == TYPEC_DP_STATE_B || state->mode == TYPEC_DP_STATE_D || + state->mode == TYPEC_DP_STATE_F) + lanes = 2; + } + + guard(spinlock)(&t8152_typec_lock); + /* The sink answers AUX once it raised HPD, not at alt mode entry. */ + port->sink = dp && (dp->status & DP_STATUS_HPD_STATE); + port->flipped = flipped; + port->lanes = lanes; + list_for_each_entry(typec, &t8152_typec_displays, node) + dcp_iboot_hpd_event(container_of(typec->disp, struct dcp_iboot, disp)); + return 0; +} + +/* + * 1 with a DisplayPort sink on the port of ATC @index (DP alt mode, HPD + * high), 0 without. + * + * A HPD pulse that ends before the DCP looks is not a new sink: an EV2780 + * without a video stream drops HPD for about 160 ms every few seconds, and + * connecting it anew each time kept its link from coming up. A sink that is + * really unplugged leaves DP alt mode with its partner. + */ +int t8152_typec_sink(struct t8152_display *disp, u32 index, bool *flipped, + u32 *lanes) +{ + struct t8152_typec_port *port; + + if (!disp->typec || index >= T8152_TYPEC_PORTS) + return 0; + port = &t8152_typec_ports[index]; + guard(spinlock)(&t8152_typec_lock); + if (!port->mux || !port->sink) + return 0; + *flipped = port->flipped; + *lanes = port->lanes; + return 1; +} + +static int t8152_typec_port_register(struct device *dev, struct device_node *np) +{ + struct typec_mux_desc desc = {}; + struct t8152_typec_port *port; + struct typec_mux_dev *mux; + u32 index; + int ret; + + ret = of_property_read_u32(np, "apple,dfp-endpoint", &index); + if (ret || index >= T8152_TYPEC_PORTS) + return dev_err_probe(dev, ret ?: -EINVAL, "%pOF: invalid port\n", np); + port = &t8152_typec_ports[index]; + if (port->mux) + return 0; + desc.fwnode = of_fwnode_handle(np); + desc.set = t8152_typec_set; + desc.drvdata = port; + desc.name = kasprintf(GFP_KERNEL, "dcp-usb-c%u", index); + if (!desc.name) + return -ENOMEM; + port->lanes = 4; + /* Not a devres of @dev: the switch outlives this DCP's binding. */ + mux = typec_mux_register(dev, &desc); + kfree(desc.name); + if (IS_ERR(mux)) + return dev_err_probe(dev, PTR_ERR(mux), "%pOF: switch not registered\n", np); + scoped_guard(spinlock, &t8152_typec_lock) + port->mux = mux; + return 0; +} + +/* A switch that cannot be registered: the port driver goes on without it. */ +static void t8152_typec_port_disable(struct device *dev, struct device_node *np) +{ + struct of_changeset *cs = kzalloc(sizeof(*cs), GFP_KERNEL); + + if (!cs) + return; + of_changeset_init(cs); + if (!of_changeset_update_prop_string(cs, np, "status", "disabled") && + !of_changeset_apply(cs)) + return; /* applied, it stays: the live tree refers to it */ + dev_err(dev, "%pOF: could not disable the display switch\n", np); + of_changeset_destroy(cs); + kfree(cs); +} + +/* + * Register the display switches of the USB-C ports the DCP @dev can drive, + * unless another DCP did. Called first in the DCP's probe, so that the port + * driver, which waits for them, never waits for a DCP that cannot start. + */ +void t8152_typec_register(struct device *dev) +{ + struct device_node *ports __free(device_node) = + of_parse_phandle(dev->of_node, "apple,usb-c-ports", 0); + struct device_node *np = ports ?: dev->of_node; + + guard(mutex)(&t8152_typec_register_lock); + for_each_available_child_of_node_scoped(np, child) { + if (of_property_present(child, "mode-switch") && + t8152_typec_port_register(dev, child)) + t8152_typec_port_disable(dev, child); + } +} + +/* At driver unload, once no DCP is bound */ +void t8152_typec_unregister(void) +{ + guard(mutex)(&t8152_typec_register_lock); + for (unsigned int i = 0; i < T8152_TYPEC_PORTS; i++) { + struct typec_mux_dev *mux = t8152_typec_ports[i].mux; + + if (!mux) + continue; + scoped_guard(spinlock, &t8152_typec_lock) + t8152_typec_ports[i].mux = NULL; + typec_mux_unregister(mux); + } +} + +static void t8152_typec_leave(void *data) +{ + struct t8152_typec *typec = data; + + scoped_guard(spinlock, &t8152_typec_lock) + list_del(&typec->node); +} + +/* + * Have the DCP see the USB-C ports' display state from now on: call this + * once the DCP stays bound. Without it, the DCP sees no USB-C sink. + */ +int t8152_typec_init(struct t8152_display *disp) +{ + struct t8152_typec *typec; + int ret; + + typec = devm_kzalloc(disp->dev, sizeof(*typec), GFP_KERNEL); + if (!typec) + return -ENOMEM; + typec->disp = disp; + scoped_guard(spinlock, &t8152_typec_lock) + list_add_tail(&typec->node, &t8152_typec_displays); + ret = devm_add_action_or_reset(disp->dev, t8152_typec_leave, typec); + if (ret) + return ret; + disp->typec = typec; + return 0; +} diff --git a/drivers/gpu/drm/apple/version_utils.h b/drivers/gpu/drm/apple/version_utils.h index 8cf36e39d3f24..fe19968ee5f1e 100644 --- a/drivers/gpu/drm/apple/version_utils.h +++ b/drivers/gpu/drm/apple/version_utils.h @@ -62,6 +62,12 @@ enum dcp_firmware_version { */ DCP_FIRMWARE_V_26_6_DESKTOP, DCP_FIRMWARE_V_27_0, + /* + * A DCP driven through its firmware's iBoot interface alone + * (disp0-service, dispext-service; see ibootep.c), not through + * IOMFB: the T8152 one. + */ + DCP_FIRMWARE_IBOOT, }; #endif /*__APPLE_VERSION_UTILS_H__*/ diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 33a29ce9beb04..3cd266e6cf7c4 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -57,6 +57,9 @@ #include #include +#include +#include + #include "dma-iommu.h" #if IS_ENABLED(CONFIG_APPLE_DART_KUNIT_TEST) @@ -277,6 +280,8 @@ struct apple_dart; struct apple_dart_hw { enum dart_type type; + /* T8110 register layout, SPTM-owned TLB invalidation (T8152) */ + bool gen3; irqreturn_t (*irq_handler)(int irq, void *dev); int (*invalidate_tlb)(struct apple_dart_stream_map *stream_map); void (*enable_remap)(struct apple_dart *dart, int sid, int remap_to); @@ -356,6 +361,9 @@ struct apple_dart_fw_tree { #define APPLE_DART_GAPF_PROTECT BIT(4) struct apple_dart { + bool cold_gen3; + u32 cold_gen3_sids; + bool cold_gen3_pcie; struct device *dev; const struct apple_dart_hw *hw; @@ -540,6 +548,10 @@ struct apple_dart { unsigned int sleep_writers; bool sleep_closed; + /* Gen3: shared TLBI aperture and this DART's route in it */ + void __iomem *tlbi; + u8 tlbi_route; + DECLARE_BITMAP(remapped, DART_MAX_STREAMS); u8 remap_target[DART_MAX_STREAMS]; @@ -1998,6 +2010,59 @@ static int apple_dart_fw_invalidate(struct apple_dart_stream_map *stream_map, return 0; } +#define DART_GEN3_TLBI_ROUTE 0x4604 +#define DART_GEN3_TLBI_VALID BIT_ULL(60) +#define DART_GEN3_TLBI_ROUTE_FIELD GENMASK_ULL(59, 56) +#define DART_GEN3_TLBI_SID GENMASK_ULL(55, 48) + +/* + * Gen3 DARTs (T8152) are owned by the SPTM, and their TLB command register at + * 0x80 answers translation queries instead of flushing. A stream is + * invalidated the way iBoot does it: write a 128-bit payload (valid, route, + * SID) to the shared TLBI aperture, then broadcast a TLBI, which the DART + * snoops and applies to that stream. + */ +static int +apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + struct apple_dart *dart = stream_map->dart; + unsigned long flags; + u64 hcr = 0; + int sid; + + spin_lock_irqsave(&dart->lock, flags); + /* + * The DART snoops an EL1&0 TLBI, as iBoot and aura (EL2 without VHE) + * issue it. A VHE kernel's TLBI VALE1OS targets EL2&0 while + * HCR_EL2.TGE is set, so clear TGE around it, as KVM does to reach + * the EL1&0 regime. + */ + if (is_kernel_in_hyp_mode()) { + hcr = read_sysreg(hcr_el2); + write_sysreg(hcr & ~HCR_TGE, hcr_el2); + isb(); + } + for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { + u64 lo = DART_GEN3_TLBI_VALID | + FIELD_PREP(DART_GEN3_TLBI_ROUTE_FIELD, dart->tlbi_route) | + FIELD_PREP(DART_GEN3_TLBI_SID, sid); + + dma_wmb(); + asm volatile("stp %0, xzr, [%1]\n" + "dsb ish\n" + ".inst 0xd50881bf\n" /* tlbi vale1os, xzr */ + "dsb osh\n" + : : "r"(lo), "r"(dart->tlbi) : "memory"); + } + if (is_kernel_in_hyp_mode()) { + write_sysreg(hcr, hcr_el2); + isb(); + } + spin_unlock_irqrestore(&dart->lock, flags); + + return 0; +} + static int apple_dart_t8020_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) { @@ -2168,6 +2233,15 @@ static int apple_dart_t8110_v2_unlock(struct apple_dart *dart) return -EPERM; if (!(readl(dart->regs + DART_T8110_DIAG_LOCK) & DART_T8110_DIAG_LOCK_ON_ERR)) return 0; + /* + * A Gen3 DART's TLB command register serves translation queries and + * cannot unlock it. Its streams stay stopped until the DART is reset. + */ + if (dart->hw->gen3) { + dev_err_ratelimited(dart->dev, + "locked on error; a Gen3 DART is not unlocked\n"); + return -EOPNOTSUPP; + } /* Unlock after acknowledging a lock-on-error exception. */ __set_bit(0, stream_map.sidmap); @@ -2590,6 +2664,39 @@ static int apple_dart_hw_reset(struct apple_dart *dart) struct apple_dart_stream_map stream_map; int i; + if (dart->cold_gen3) { + stream_map.dart = dart; + bitmap_zero(stream_map.sidmap, DART_MAX_STREAMS); + for (i = 0; i < 32; i++) + if (dart->cold_gen3_sids & BIT(i)) + __set_bit(i, stream_map.sidmap); + if (dart->cold_gen3_pcie) + bitmap_set(stream_map.sidmap, 0, 253); + apple_dart_hw_disable_dma(&stream_map); + apple_dart_hw_clear_all_ttbrs(&stream_map); + apple_dart_apply_own_tunables(dart); + apple_dart_writel(dart, apple_dart_readl(dart, dart->hw->enable_streams) | + dart->cold_gen3_sids, dart->hw->enable_streams); + if (dart->cold_gen3_pcie) { + /* ADT reserves 253/255 for host transactions, including MSI + * writes to AIC. Stream 254 belongs to firmware; preserve it. + */ + for (i = 253; i <= 255; i += 2) { + apple_dart_writel(dart, DART_T8110_TCR_BYPASS_DART, + DART_TCR(dart, i)); + __set_bit(i, stream_map.sidmap); + } + for (i = 0; i < 8; i++) { + u32 reg = dart->hw->enable_streams + i * 4; + u32 enabled = apple_dart_readl(dart, reg); + + enabled |= i == 7 ? (U32_MAX & ~BIT(30)) : U32_MAX; + apple_dart_writel(dart, enabled, reg); + } + } + return dart->hw->invalidate_tlb(&stream_map); + } + if (dart->isp_host) return apple_dart_isp_host_reset(dart); if (dart->managed_sids || dart->cold_ane) @@ -2736,8 +2843,11 @@ static int apple_dart_domain_flush_tlb_range(struct apple_dart_domain *domain, /* The range registers take the DVA the device issues. */ start = first + domain->dma_offset; end = last + domain->dma_offset; - if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && - stream.dart->version >= 0x0202) + /* Gen3 has no range command; invalidate the complete stream. */ + if (stream.dart->hw->gen3) + ret = stream.dart->hw->invalidate_tlb(&stream); + else if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && + stream.dart->version >= 0x0202) ret = apple_dart_fw_invalidate(&stream, start, end); else if (range && stream.dart->locked && stream.dart->version >= 0x0202) ret = apple_dart_t8110_hw_tlb_command_range(&stream, op, true, @@ -3319,6 +3429,17 @@ static int __apple_dart_finalize_domain(struct apple_dart_domain *dart_domain, .iommu_dev = dart->dev, }; + if (dart->cold_gen3) { + if ((dma_min ^ dma_max) & ~DMA_BIT_MASK(36)) { + ret = -ERANGE; + goto done; + } + /* Gen3 selects the high DMA window separately from its two-level + * 16K page-table indices, as with iBoot's display streams. + */ + pgtbl_cfg.ias = 36; + } + if (dart->locked) { unsigned long *sidmap; int sid; @@ -3940,6 +4061,9 @@ static int apple_dart_of_xlate(struct device *dev, return i; sid = args->args[0]; + if (dart->cold_gen3 && (dart->cold_gen3_pcie ? (sid < 0 || sid >= 253) : + (sid < 0 || sid >= 32 || !(dart->cold_gen3_sids & BIT(sid))))) + return -EPERM; if (dart->isp_host && sid != 0 && sid != 12) return -EINVAL; if (dart->cold_ane && sid != 0) @@ -4958,6 +5082,14 @@ static irqreturn_t apple_dart_irq(int irq, void *dev) static bool apple_dart_is_locked(struct apple_dart *dart) { + /* + * apple,retain-translation: the bootloader left live stream tables + * that a co-processor's firmware depends on, but did not set the lock + * bit (T8152 dart-sbr: AOP and audio ADMAC streams). Treat it as + * locked so the tables are inherited rather than reset. + */ + if (of_property_read_bool(dart->dev->of_node, "apple,retain-translation")) + return true; return !!(apple_dart_readl(dart, dart->hw->lock) & dart->hw->lock_bit); } @@ -5466,6 +5598,15 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); dart->tunneled = tunneled; + if (of_device_is_compatible(dev->of_node, "apple,t8152-acio-dart")) { + dart->cold_gen3 = true; + dart->cold_gen3_sids = 0x0fff0fff; + } + if (of_device_is_compatible(dev->of_node, "apple,t8152-pciec-dart")) { + dart->cold_gen3 = true; + dart->cold_gen3_pcie = true; + dart->cold_gen3_sids = U32_MAX; + } dart->cold_ane = of_device_is_compatible(dev->of_node, "apple,t8140-ane-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-ane-dart"); if (dart->cold_ane && !IS_BUILTIN(CONFIG_APPLE_DART)) @@ -5624,6 +5765,18 @@ static int apple_dart_probe(struct platform_device *pdev) * not admitted: never enable that level IRQ for one block alone. */ dart->irq = -1; + } else if (dart->hw->gen3) { + /* + * Gen3 reports a fault like a v2 DART: the per-SID exception + * bitmap and records, acknowledged by writing the bitmap back + * (apple_dart_t8110_v2_irq()). Only the unlock after a + * lock-on-error exception differs: see apple_dart_t8110_v2_unlock(). + */ + dart->irq = platform_get_irq_optional(pdev, 0); + if (dart->irq == -ENXIO) + dart->irq = -1; + else if (dart->irq < 0) + return dart->irq; } else if (dart->preserve_display || j713_radio) { dart->irq = platform_get_irq_optional(pdev, 0); if (dart->irq == -ENXIO) @@ -5660,7 +5813,7 @@ static int apple_dart_probe(struct platform_device *pdev) ret = devm_pm_runtime_enable(dev); if (ret) goto err_clk_disable; - if (tunneled && dart->tunables) { + if (tunneled && dart->tunables && !dart->cold_gen3) { dev_dbg(dev, "applying %zu PCIe-C DART tunables\n", dart->tunables->sz); apple_dart_apply_tunables(dart, dart->tunables); @@ -5676,7 +5829,15 @@ static int apple_dart_probe(struct platform_device *pdev) * pages, a 32-bit IOVA, a 36-bit PA and as many streams as its * register block describes. */ - if (dart->hw->type == DART_T8110) { + if (dart->cold_gen3_pcie) { + dart->pgsize = SZ_16K; + dart->supports_bypass = true; + dart->ias = 42; + dart->oas = 42; + dart->num_streams = 256; + dart->four_level = false; + dart->version = 0x300; + } else if (dart->hw->type == DART_T8110) { dart->pgsize = 1 << DART_PCIEC_PAGE_SHIFT; dart->supports_bypass = true; dart->ias = DART_PCIEC_ADDR_WIDTH; @@ -5873,6 +6034,51 @@ static int apple_dart_probe(struct platform_device *pdev) ret = -EBUSY; goto err_clk_disable; } + if (dart->hw->gen3) { + struct resource *tlbi; + + /* Cold setup only for the instances a T8152 compatible selects. */ + if (!dart->locked && !dart->cold_gen3) { + dev_err(dev, "Gen3 DART is not locked; cold setup is not supported\n"); + ret = -ENODEV; + goto err_clk_disable; + } + if (dart->cold_gen3 && + (dart->locked || dart->version != 0x300 || !dart->tunables || + (dart->cold_gen3_pcie ? (!tunneled || !dev->pm_domain) : + dart->num_streams != 32) || + (apple_dart_readl(dart, dart->hw->enable_streams) & dart->cold_gen3_sids))) { + ret = -EINVAL; + goto err_clk_disable; + } + if (dart->cold_gen3_pcie) { + for (sid = 0; sid < 8; sid++) { + u32 mask = sid == 7 ? GENMASK(28, 0) : U32_MAX; + u32 reg = dart->hw->enable_streams + sid * 4; + + if (apple_dart_readl(dart, reg) & mask) { + ret = -EBUSY; + goto err_clk_disable; + } + } + } + /* The aperture is shared by every Gen3 DART: map, do not claim. */ + tlbi = platform_get_resource_byname(pdev, IORESOURCE_MEM, "tlbi"); + if (!tlbi || resource_size(tlbi) < 16) { + dev_err(dev, "Gen3 DART needs its TLBI aperture\n"); + ret = -EINVAL; + goto err_clk_disable; + } + dart->tlbi = devm_ioremap(dev, tlbi->start, resource_size(tlbi)); + if (!dart->tlbi) { + ret = -ENOMEM; + goto err_clk_disable; + } + dart->tlbi_route = apple_dart_readl(dart, DART_GEN3_TLBI_ROUTE) & 0xf; + dev_info(dev, "Gen3 DART, version %#x, TLBI route %u\n", + dart->version, dart->tlbi_route); + } + apple_dart_parse_sleep_list(dart, res, "apple,sleep-prepare", &dart->sleep_prepare); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore", &dart->sleep_restore); apple_dart_parse_sleep_list(dart, res, "apple,sleep-restore-late", @@ -6014,7 +6220,7 @@ static int apple_dart_probe(struct platform_device *pdev) } /* Borrowed display state: never acknowledge someone else's fault. */ - if (dart->locked && !dart->preserve_display) + if (dart->locked && !dart->preserve_display && !dart->hw->gen3) apple_dart_drain_stale_exceptions(dart); /* Refuse an already pending inherited fault before joining the shared IRQ. */ @@ -6369,6 +6575,33 @@ static const struct apple_dart_hw apple_dart_hw_t6000 = { .ttbr_count = 4, }; +static const struct apple_dart_hw apple_dart_hw_gen3 = { + .type = DART_T8110, + .gen3 = true, + .irq_handler = apple_dart_t8110_irq, + .invalidate_tlb = apple_dart_gen3_hw_invalidate_tlb, + .fmt = APPLE_DART2, + .max_sid_count = 256, + + .enable_streams = DART_T8110_ENABLE_STREAMS, + .lock = DART_T8110_PROTECT, + .lock_bit = DART_T8110_PROTECT_TTBR_TCR, + + .error = DART_T8110_ERROR, + + .tcr = DART_T8110_TCR, + .tcr_enabled = DART_T8110_TCR_TRANSLATE_ENABLE, + .tcr_disabled = 0, + .tcr_bypass = DART_T8110_TCR_BYPASS_DAPF | DART_T8110_TCR_BYPASS_DART, + .tcr_4level = DART_T8110_TCR_FOUR_LEVEL, + + .ttbr = DART_T8110_TTBR, + .ttbr_valid = DART_T8110_TTBR_VALID, + .ttbr_addr_field_shift = DART_T8110_TTBR_ADDR_FIELD_SHIFT, + .ttbr_shift = DART_T8110_TTBR_SHIFT, + .ttbr_count = 1, +}; + static const struct apple_dart_hw apple_dart_hw_t8110 = { .type = DART_T8110, .irq_handler = apple_dart_t8110_irq, @@ -7246,6 +7479,9 @@ static const struct dev_pm_ops apple_dart_pm_ops = { }; static const struct of_device_id apple_dart_of_match[] = { + { .compatible = "apple,t8152-dart-gen3", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-acio-dart", .data = &apple_dart_hw_gen3 }, + { .compatible = "apple,t8152-pciec-dart", .data = &apple_dart_hw_gen3 }, { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, diff --git a/drivers/mfd/macsmc.c b/drivers/mfd/macsmc.c index ad4d84f9c3dd2..cb32577a3bf66 100644 --- a/drivers/mfd/macsmc.c +++ b/drivers/mfd/macsmc.c @@ -113,9 +113,15 @@ static int apple_smc_add_described_devices(struct apple_smc *smc, const struct m return 0; } -/* T8152 currently exposes read-only telemetry; firmware owns fan control. */ +/* + * T8152: temperatures and fans (hwmon; the fan keys are read-only unless the + * unsafe fan_control parameter is set) and power off/restart (reboot, which + * only writes the MBSE key). Notifications, GPIO and the power supply are not + * qualified there yet. + */ static const struct mfd_cell apple_smc_telemetry_devs[] = { MFD_CELL_OF("macsmc-hwmon", NULL, NULL, 0, 0, "apple,smc-hwmon"), + MFD_CELL_OF("macsmc-reboot", NULL, NULL, 0, 0, "apple,smc-reboot"), }; static void apple_smc_read_sram(struct apple_smc *smc, void *buf, size_t size) @@ -709,7 +715,7 @@ static int apple_smc_probe(struct platform_device *pdev) return dev_err_probe(smc->dev, ret, "Failed to get key count"); smc->key_count = be32_to_cpu(count); - /* Notifications, GPIO and power management are not qualified on T8152. */ + /* T8152: key reads and writes are qualified; notifications and GPIO are not. */ if (of_device_is_compatible(dev->of_node, "apple,t8152-smc")) return devm_mfd_add_devices(smc->dev, PLATFORM_DEVID_NONE, apple_smc_telemetry_devs, diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index e4522195f9a23..435ef9b7ae082 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -75,6 +75,15 @@ #define APPLE_ANS_LINEAR_ASQ_DB 0x2490c #define APPLE_ANS_LINEAR_IOSQ_DB 0x24910 +/* + * ADT nvme-secure-reg-layout (T8152, macOS AppleANS2NVMeController with its + * 0x92a flag set): AQA/ASQ/ACQ and the I/O queue registers move up by + * 0x4000 and LINEAR_SQ_CTRL moves into the NVMMU block. CC/CSTS, the + * doorbells and the NVMMU TCB registers stay where they are. + */ +#define APPLE_ANS_SECURE_QREG_SHIFT 0x4000 +#define APPLE_ANS_SECURE_LINEAR_SQ_CTRL 0x2813c + #define APPLE_NVMMU_NUM_TCBS 0x28100 #define APPLE_NVMMU_ASQ_TCB_BASE 0x28108 #define APPLE_NVMMU_IOSQ_TCB_BASE 0x28110 @@ -231,6 +240,9 @@ struct apple_nvme_hw { u32 sleep_shn; /* The ANS is never reset through PMGR here, so no reset is named. */ bool reset_optional; + bool secure_reg_layout; + /* Also send the NVMe shutdown notification (CC.SHN) on removal. */ + bool shutdown_notify; u32 max_queue_depth; unsigned long quirks; }; @@ -439,6 +451,17 @@ static int apple_nvme_read_handoff(struct apple_nvme *anv) return apple_nvme_can_adopt_rtkit(anv) ? 0 : -EIO; } +static u32 apple_nvme_qreg(const struct apple_nvme *anv, u32 reg) +{ + return anv->hw->secure_reg_layout ? reg + APPLE_ANS_SECURE_QREG_SHIFT : reg; +} + +static u32 apple_nvme_lsq_ctrl(const struct apple_nvme *anv) +{ + return anv->hw->secure_reg_layout ? APPLE_ANS_SECURE_LINEAR_SQ_CTRL : + APPLE_ANS_LINEAR_SQ_CTRL; +} + static inline struct apple_nvme *queue_to_apple_nvme(struct apple_nvme_queue *q) { if (q->is_adminq) @@ -1429,10 +1452,13 @@ static int apple_nvme_disable_locked(struct apple_nvme *anv, bool shutdown) * The final system shutdown is the exception for SHN: without it the * controller counts every Linux shutdown as unsafe (SMART * unsafe_shutdowns) and recovers on the next start, which slows the - * loader and the first seconds of I/O. A failed SHN changes nothing: - * the CC.EN clear below still runs. + * loader and the first seconds of I/O. Where the firmware handles it, + * removal sends it too. A failed SHN changes nothing: the CC.EN clear + * below still runs. */ - if (READ_ONCE(anv->final_shutdown) && !apple_rtkit_is_crashed(anv->rtk)) { + if ((READ_ONCE(anv->final_shutdown) || + (shutdown && anv->hw->shutdown_notify && READ_ONCE(anv->removing))) && + !apple_rtkit_is_crashed(anv->rtk)) { ret = nvme_disable_ctrl(&anv->ctrl, true); if (ret) dev_warn(anv->dev, "shutdown notification failed: %d\n", ret); @@ -1976,10 +2002,10 @@ static void apple_nvme_reset_work_impl(struct work_struct *work) */ if (!anv->lsq_in_nvmmu) { writel(APPLE_ANS_LINEAR_SQ_EN, - anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + anv->mmio_nvme + apple_nvme_lsq_ctrl(anv)); if (anv->hw->needs_ioq_registers) { u32 lsq_ctrl = readl(anv->mmio_nvme + - APPLE_ANS_LINEAR_SQ_CTRL); + apple_nvme_lsq_ctrl(anv)); if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN)) { dev_err(anv->dev, @@ -2002,9 +2028,11 @@ static void apple_nvme_reset_work_impl(struct work_struct *work) if (anv->hw->needs_ioq_registers) ioqa_depth--; ioqa = ioqa_depth | (ioqa_depth << 16); - writel(ioqa, anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL); + writel(ioqa, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)); if (anv->hw->needs_ioq_registers && - readl(anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL) != ioqa) { + readl(anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)) != ioqa) { dev_err(anv->dev, "failed to program I/O queue aperture\n"); ret = -EIO; goto out; @@ -2018,11 +2046,11 @@ static void apple_nvme_reset_work_impl(struct work_struct *work) /* Setup the admin queue */ aqa = APPLE_NVME_AQ_DEPTH - 1; aqa |= aqa << 16; - writel(aqa, anv->mmio_nvme + NVME_REG_AQA); + writel(aqa, anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_AQA)); apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, - anv->mmio_nvme + NVME_REG_ASQ); + anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_ASQ)); apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, - anv->mmio_nvme + NVME_REG_ACQ); + anv->mmio_nvme + apple_nvme_qreg(anv, NVME_REG_ACQ)); if (anv->hw->has_lsq_nvmmu) { /* Setup NVMMU for both queues */ @@ -2094,10 +2122,10 @@ static void apple_nvme_reset_work_impl(struct work_struct *work) * dedicated registers. Without them it crashes and its crash log * reports null I/O SQ and CQ addresses. */ - apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOCQ_REGISTER); - apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOSQ_REGISTER); + apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_IOCQ_REGISTER)); + apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, anv->mmio_nvme + + apple_nvme_qreg(anv, APPLE_ANS_IOSQ_REGISTER)); } nr_io_queues = 1; if (anv->hw->has_queue_count) { @@ -3354,6 +3382,22 @@ static const struct apple_nvme_hw apple_nvme_t6050_hw = { .quirks = NVME_QUIRK_NO_APST | NVME_QUIRK_BROKEN_FUA, }; +/* + * T8152 uses the post-M4 queue setup, but its NVMe registers and NVMMU share + * one window (0x325cc0000 on J873) like T8103, with the secure register + * layout. There is no T8152 PMGR driver yet, so the controller has no reset + * line in the DT. + */ +static const struct apple_nvme_hw apple_nvme_t8152_hw = { + .has_lsq_nvmmu = true, + .needs_ioq_registers = true, + .reset_optional = true, + .secure_reg_layout = true, + .shutdown_notify = true, + .max_queue_depth = 64, + .quirks = NVME_QUIRK_BROKEN_FUA, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t6041-nvme-ans2", .data = &apple_nvme_t6040_hw }, { .compatible = "apple,t6050-nvme-ans2", .data = &apple_nvme_t6050_hw }, @@ -3362,6 +3406,7 @@ static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, { .compatible = "apple,t8140-nvme-ans2", .data = &apple_nvme_t8140_hw }, { .compatible = "apple,t8142-nvme-ans2", .data = &apple_nvme_t8142_hw }, + { .compatible = "apple,t8152-nvme-ans2", .data = &apple_nvme_t8152_hw }, { .compatible = "apple,nvme-ans2", .data = &apple_nvme_t8103_hw }, {}, }; diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index dcff27ac6b268..2d59ba7c0191f 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -302,6 +302,12 @@ struct hw_info { bool pipe_rst; bool no_port_reset; bool mps_timers; + /* + * Keep endpoints at their reset Max_Read_Request_Size (512 bytes). + * On T8152 an RTL8127 at MRRS 4096 (what r8169 asks for) transmits + * 9000-byte frames at 7.0 Gbit/s; at 512 it reaches 9.93. + */ + bool no_inc_mrrs; }; static const struct hw_info t8103_hw = { @@ -357,6 +363,7 @@ static const struct hw_info t8152_hw = { .max_rid2sid = 512, .refbuf_off = true, .pipe_rst = true, + .no_inc_mrrs = true, }; /* @@ -473,6 +480,38 @@ static const struct hw_info t6050_pciec_hw = { .mps_timers = true, }; +/* T8142 shares this register layout, with its own three-cell AIC MSI slice. */ +static const struct hw_info t8142_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = PORT_T6050_TUNCTRL, + .max_rid2sid = 256, + .tunneled = true, + .tunnel_intr2axi = true, + .no_port_reset = true, + .msimap_by_vector = true, + .mps_timers = true, +}; + +/* T8152 PCIe-C: the T8142 layout, with a third PCIe-C bridge (CIO3). */ +static const struct hw_info t8152_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = PORT_T6050_TUNCTRL, + .max_rid2sid = 256, + .tunneled = true, + .tunnel_intr2axi = true, + .no_port_reset = true, + .msimap_by_vector = true, + .mps_timers = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -3386,8 +3425,26 @@ static int apple_msi_init(struct apple_pcie *pcie) * 32-vector slice. Keep endpoint MSI data local, and route its table * entry to the corresponding shared-window vector. */ - if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || - pcie->hw == &t6040_pciec_hw) { + if (pcie->hw == &t8132_pciec_hw || pcie->hw == &t8142_pciec_hw || + pcie->hw == &t8152_pciec_hw) { + /* + * msi-ranges names the AIC input of global vector + * apple,msi-vector-base in a linear window, so the slice is + * checked by its shape only: an edge-rising SPI, 32 vectors, + * 32-aligned, above the internal port's vectors and inside the + * 8-bit map target. + */ + if (args.args_count != 3 || args.args[0] != 0 || + args.args[2] != IRQ_TYPE_EDGE_RISING || + of_property_read_u32(to_of_node(fwnode), + "apple,msi-vector-base", + &pcie->msi_vector_base) || + args.args[1] < pcie->msi_vector_base || + !apple_t6030_msi_slice_valid(pcie->msi_vector_base, + pcie->nvecs, args.args[1], + args.args[1] - pcie->msi_vector_base)) + goto invalid_slice; + } else if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t6040_pciec_hw) { struct resource ecam; u32 expected_base, aic_base; @@ -3424,19 +3481,6 @@ static int apple_msi_init(struct apple_pcie *pcie) default: goto invalid_slice; } - } else if (of_machine_is_compatible("apple,t8132")) { - aic_base = 1506; - switch (ecam.start) { - /* The internal port's bridges own vectors 0..95. */ - case 0x1c50000000ULL: - expected_base = 0x60; - break; - case 0x1c60000000ULL: - expected_base = 0x80; - break; - default: - goto invalid_slice; - } } else { goto invalid_slice; } @@ -3470,7 +3514,8 @@ static int apple_msi_init(struct apple_pcie *pcie) /* Keep map targets within the supported 8-bit range. */ if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || - pcie->hw == &t6040_pciec_hw) && + pcie->hw == &t6040_pciec_hw || pcie->hw == &t8142_pciec_hw || + pcie->hw == &t8152_pciec_hw) && (!pcie->nvecs || pcie->nvecs > 256 || pcie->msi_vector_base > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 - pcie->nvecs)) { @@ -5811,6 +5856,7 @@ static int apple_pcie_probe(struct platform_device *pdev) if (ret) return dev_err_probe(dev, ret, "Failed to attach power domains\n"); + bridge->no_inc_mrrs = hw->no_inc_mrrs; if (of_property_present(dev->of_node, "apple,managed-sids")) { u32 ids[15]; int count = of_property_count_u32_elems(dev->of_node, "apple,managed-sids"); @@ -7555,6 +7601,8 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { static const struct of_device_id apple_pcie_of_match[] = { { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, { .compatible = "apple,t6050-pciec", .data = &t6050_pciec_hw }, + { .compatible = "apple,t8142-pciec", .data = &t8142_pciec_hw }, + { .compatible = "apple,t8152-pciec", .data = &t8152_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, diff --git a/drivers/phy/apple/atc-test.c b/drivers/phy/apple/atc-test.c index 09eec7f9d6185..000f8c28834da 100644 --- a/drivers/phy/apple/atc-test.c +++ b/drivers/phy/apple/atc-test.c @@ -1450,3 +1450,241 @@ static struct kunit_suite atcphy_t8132_pm_test_suite = { }; kunit_test_suite(atcphy_t8132_pm_test_suite); + +#define ATCPHY_TEST_T8152_LANE0_UP \ + (ACIOPHY_T8152_AON_LANE_SLEEP_SMALL | ACIOPHY_T8152_AON_LANE_SLEEP_BIG | \ + ACIOPHY_T8152_AON_LANE_AHB_RESET_N) + +/* + * A T8152 fixed-USB3 PHY over zeroed memory in place of its ATC window, up to + * the sync reset. Its USB controller's DARTs sit at the T8103 offsets of the + * power and reset block: mark those words to see that nothing writes them. + */ +static struct apple_atcphy *atcphy_test_alloc_t8152(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_dev(test, false); + void *core = kunit_kzalloc(test, ATCPHY_T8152_SYNC_RESET + 4, GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, core); + atcphy->regs.core = (__force void __iomem *)core; + atcphy->hw = &atcphy_hw_t8152; + atcphy->fixed_usb3 = true; + writel(0xdeadbeef, atcphy->regs.core + ATCPHY_POWER_CTRL); + writel(0xdeadbeef, atcphy->regs.core + ATCPHY_MISC); + + return atcphy; +} + +static void atcphy_test_t8152_untouched(struct kunit *test, struct apple_atcphy *atcphy) +{ + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.core + ATCPHY_POWER_CTRL), 0xdeadbeefU); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.core + ATCPHY_MISC), 0xdeadbeefU); +} + +/* USB3: lane 0 powered up, crossbar 0x110, no lane mode register, lane swap bit 1 */ +static void atcphy_test_t8152_lanes(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE0); + writel(ATCPHY_T8152_MISC_LANE_SWAP, core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC); + + atcphy_lanes_up_t8152(atcphy, APPLE_ATCPHY_MODE_USB3); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(0) | + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(0)); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), 0x110U); + + KUNIT_EXPECT_EQ(test, atcphy_configure_lanes(atcphy, APPLE_ATCPHY_MODE_USB3), 0); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), 0x110U); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_LANE_MODE_T8103), 0U); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC), 0U); + atcphy_test_t8152_untouched(test, atcphy); +} + +/* Power-up and power-down go to the block at 0x60000 and the sync reset at 0x60030 */ +static void atcphy_test_t8152_power(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 stat = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_STAT; + + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + writel(ATCPHY_POWER_SLEEP_SMALL | ATCPHY_POWER_SLEEP_BIG, core + stat); + KUNIT_EXPECT_EQ(test, atcphy_power_on(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(core + ctrl), ATCPHY_POWER_SLEEP_SMALL | + ATCPHY_POWER_SLEEP_BIG | ATCPHY_POWER_APB_RESET_N); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_SYNC_RESET), ATCPHY_MISC_RESET_N); + atcphy_test_t8152_untouched(test, atcphy); + + writel(ATCPHY_TEST_T8152_LANE0_UP, core + ACIOPHY_T8152_AON_LANE0); + writel(0, core + stat); + KUNIT_EXPECT_EQ(test, atcphy_power_off(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(core + ctrl), ATCPHY_POWER_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ATCPHY_T8152_SYNC_RESET), 0U); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + atcphy_test_t8152_untouched(test, atcphy); +} + +/* + * The T8152 PIPE handler does not acknowledge the lock: the request is made + * and the PIPE changes under it without waiting. Its release then finds the + * acknowledge clear at once. + */ +static void atcphy_test_t8152_pipe_lock(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void *pipehandler = kunit_kzalloc(test, PIPEHANDLER_NONSELECTED_OVERRIDE + 4, + GFP_KERNEL); + + KUNIT_ASSERT_NOT_NULL(test, pipehandler); + atcphy->regs.pipehandler = (__force void __iomem *)pipehandler; + KUNIT_EXPECT_EQ(test, atcphy_pipehandler_lock(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ), + PIPEHANDLER_LOCK_EN); + KUNIT_EXPECT_EQ(test, atcphy_pipehandler_unlock(atcphy), 0); + KUNIT_EXPECT_EQ(test, readl(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ), 0U); +} + +/* Both LFPS receivers of a lane on */ +static u32 atcphy_test_t8152_lfps(unsigned int lane) +{ + return ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane) | + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane); +} + +/* + * CIO on a rear port: both lanes powered up one after the other, the USB4 + * crossbar by the orientation, the lane swap for a reversed plug too, and on + * the way down both lanes clamped, their LFPS receivers off and AUX clamped. + */ +static void atcphy_test_t8152_cio_lanes(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 misc = ATCPHY_T8152_CFG_OFFSET + ATCPHY_MISC; + + atcphy->fixed_usb3 = false; + atcphy->cio_only = true; + for (int reversed = 0; reversed < 2; reversed++) { + atcphy->swap_lanes = reversed; + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE(0)); + writel(ACIOPHY_T8152_AON_LANE_CLAMP_EN, core + ACIOPHY_T8152_AON_LANE(1)); + writel(ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN, + core + ACIOPHY_T8152_AON_SLEEP_CTRL2); + writel(reversed ? 0 : ATCPHY_T8152_MISC_LANE_SWAP, core + misc); + writel(ACIOPHY_CROSSBAR_DP_SINGLE_PMA_UNK100 << 5 | ACIOPHY_CROSSBAR_DP_BOTH_PMA, + core + ACIOPHY_CROSSBAR_T8103); + + atcphy_lanes_up_t8152(atcphy, APPLE_ATCPHY_MODE_USB4); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(0)), + ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(1)), + ATCPHY_TEST_T8152_LANE0_UP); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN | + atcphy_test_t8152_lfps(0) | atcphy_test_t8152_lfps(1)); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), + (u32)ACIOPHY_CROSSBAR_DP_BOTH_PMA | reversed); + + KUNIT_EXPECT_EQ(test, atcphy_configure_lanes(atcphy, APPLE_ATCPHY_MODE_USB4), 0); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_CROSSBAR_T8103), (u32)reversed); + KUNIT_EXPECT_EQ(test, readl(core + misc), + reversed ? ATCPHY_T8152_MISC_LANE_SWAP : 0U); + + atcphy->mode = APPLE_ATCPHY_MODE_USB4; + writel(ATCPHY_POWER_APB_RESET_N, core + ctrl); + atcphy_lanes_down_t8152(atcphy); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(0)), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE(1)), + ACIOPHY_T8152_AON_LANE_CLAMP_EN); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_SLEEP_CTRL2), + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN); + atcphy->mode = APPLE_ATCPHY_MODE_OFF; + atcphy_test_t8152_untouched(test, atcphy); + } +} + +/* A lane power-down with the register bus in reset leaves the lanes alone */ +static void atcphy_test_t8152_lanes_bus_reset(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + + writel(ATCPHY_TEST_T8152_LANE0_UP, core + ACIOPHY_T8152_AON_LANE0); + writel(ATCPHY_POWER_CLAMP_EN, core + ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL); + atcphy_lanes_down_t8152(atcphy); + KUNIT_EXPECT_EQ(test, readl(core + ACIOPHY_T8152_AON_LANE0), ATCPHY_TEST_T8152_LANE0_UP); +} + +/* Only USB4 in its own mode, and Thunderbolt, ask a CIO-only PHY for CIO */ +static void atcphy_test_cio_target_mode(struct kunit *test) +{ + struct typec_altmode dp = { .svid = USB_TYPEC_DP_SID }; + struct typec_altmode tbt = { .svid = USB_TYPEC_TBT_SID }; + struct enter_usb_data usb4 = { .eudo = FIELD_PREP(EUDO_USB_MODE_MASK, EUDO_USB_MODE_USB4) }; + struct enter_usb_data usb3 = { .eudo = FIELD_PREP(EUDO_USB_MODE_MASK, EUDO_USB_MODE_USB3) }; + struct typec_mux_state state = { .mode = TYPEC_MODE_USB4, .data = &usb4 }; + + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_USB4); + state.data = &usb3; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.data = NULL; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.alt = &tbt; + state.mode = TYPEC_TBT_MODE; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_TBT); + state.alt = &dp; + state.mode = TYPEC_DP_STATE_D; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.alt = NULL; + state.mode = TYPEC_STATE_USB; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); + state.mode = TYPEC_STATE_SAFE; + KUNIT_EXPECT_EQ(test, atcphy_cio_target_mode(&state), APPLE_ATCPHY_MODE_OFF); +} + +/* The PHY is idle only as its power-up leaves it */ +static void atcphy_test_t8152_cio_idle(struct kunit *test) +{ + struct apple_atcphy *atcphy = atcphy_test_alloc_t8152(test); + void __iomem *core = atcphy->regs.core; + u32 ctrl = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_CTRL; + u32 stat = ATCPHY_T8152_CFG_OFFSET + ATCPHY_POWER_STAT; + + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + KUNIT_EXPECT_TRUE(test, atcphy_cio_idle(atcphy)); + /* the display driver's DisplayPort setup */ + writel(0x1b, core + ctrl); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); + writel(ATCPHY_POWER_CLAMP_EN, core + ctrl); + writel(ATCPHY_POWER_SLEEP_SMALL, core + stat); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); + writel(0, core + stat); + writel(ATCPHY_MISC_RESET_N, core + ATCPHY_T8152_SYNC_RESET); + KUNIT_EXPECT_FALSE(test, atcphy_cio_idle(atcphy)); +} + +static struct kunit_case atcphy_t8152_test_cases[] = { + KUNIT_CASE(atcphy_test_t8152_lanes), + KUNIT_CASE(atcphy_test_t8152_power), + KUNIT_CASE(atcphy_test_t8152_pipe_lock), + KUNIT_CASE(atcphy_test_t8152_cio_lanes), + KUNIT_CASE(atcphy_test_t8152_lanes_bus_reset), + KUNIT_CASE(atcphy_test_cio_target_mode), + KUNIT_CASE(atcphy_test_t8152_cio_idle), + {} +}; + +static struct kunit_suite atcphy_t8152_test_suite = { + .name = "phy-apple-atc-t8152", + .test_cases = atcphy_t8152_test_cases, +}; + +kunit_test_suite(atcphy_t8152_test_suite); diff --git a/drivers/phy/apple/atc.c b/drivers/phy/apple/atc.c index 34d3aa12b8f4c..e139ac328fbbe 100644 --- a/drivers/phy/apple/atc.c +++ b/drivers/phy/apple/atc.c @@ -249,6 +249,48 @@ enum atcphy_lane_mode { #define ACIOPHY_BIST_MAC_USBPHY_CFG_OV2_LN0_RESET_N_OV 0x200 #define ACIOPHY_BIST_MAC_USBPHY_CFG_OV2_LN0_PWR_DOWN_OV 0x20 +/* T8152 BIST block (ACIOPHY_BIST_BLK) */ +#define ACIOPHY_T8152_BIST_CFG0 0x2400 +#define ACIOPHY_T8152_BIST_CFG0_CLOCK_EN BIT(0) +#define ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC BIT(6) + +#define ACIOPHY_T8152_BIST_CFG2 0x240c +#define ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE BIT(0) + +#define ACIOPHY_T8152_BIST_STATUS1 0x24a0 +#define ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS BIT(6) +#define ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2 BIT(7) + +#define ACIOPHY_T8152_BIST_OV1 0x24b0 +#define ACIOPHY_T8152_BIST_OV1_LN0_PIPE_RESET_N BIT(0) +#define ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN GENMASK(8, 5) + +#define ACIOPHY_T8152_BIST_OV2 0x24b8 +#define ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV BIT(5) +#define ACIOPHY_T8152_BIST_OV2_LN0_UNK6 BIT(6) +#define ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV BIT(9) +#define ACIOPHY_T8152_BIST_OV2_LN0_UNK10 BIT(10) +#define ACIOPHY_T8152_BIST_OV2_LN0 \ + (ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV | \ + ACIOPHY_T8152_BIST_OV2_LN0_UNK6 | \ + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV | \ + ACIOPHY_T8152_BIST_OV2_LN0_UNK10) + +/* T8152 lane power controls in the always-on top block (ACIOPHY_TOP_AON_BLK) */ +#define ACIOPHY_T8152_AON_LANE(n) (0x1e18 + 4 * (n)) +#define ACIOPHY_T8152_AON_LANE0 ACIOPHY_T8152_AON_LANE(0) +#define ACIOPHY_T8152_AON_LANE_CLAMP_EN BIT(0) +#define ACIOPHY_T8152_AON_LANE_SLEEP_SMALL BIT(1) +#define ACIOPHY_T8152_AON_LANE_SLEEP_BIG BIT(2) +#define ACIOPHY_T8152_AON_LANE_AHB_RESET_N BIT(5) + +#define ACIOPHY_T8152_AON_SLEEP_CTRL2 0x1e24 +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_BIG BIT(6) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_SMALL BIT(8) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN BIT(10) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(n) BIT(12 + 2 * (n)) +#define ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(n) BIT(16 + 2 * (n)) + #define ACIOPHY_SLEEP_CTRL 0x1b0 #define ACIOPHY_SLEEP_CTRL_TX_BIG GENMASK(1, 0) #define ACIOPHY_SLEEP_CTRL_TX_BIG_OV GENMASK(3, 2) @@ -274,6 +316,16 @@ enum atcphy_lane_mode { #define ATCPHY_MISC_RESET_N BIT(0) #define ATCPHY_MISC_LANE_SWAP BIT(2) +/* + * T8152 has the USB controller's DARTs at 0x20000 and 0x40000 of its ATC + * window, and the power and reset block (ATCPHY_CFG_BLK) follows at 0x60000. + * There the lane swap is bit 1 of 0x60008, and the reset the power-up releases + * first is bit 0 of the always-on sync reset at 0x60030. + */ +#define ATCPHY_T8152_CFG_OFFSET 0x40000 +#define ATCPHY_T8152_MISC_LANE_SWAP BIT(1) +#define ATCPHY_T8152_SYNC_RESET 0x60030 + #define ACIOPHY_LANE_DP_CFG_BLK_TX_DP_CTRL0 0x7000 #define DP_PMA_BYTECLK_RESET BIT(0) #define DP_MAC_DIV20_CLK_SEL BIT(1) @@ -596,6 +648,7 @@ enum atcphy_generation { ATCPHY_GENERATION_T8103, ATCPHY_GENERATION_T8122, ATCPHY_GENERATION_T8132, + ATCPHY_GENERATION_T8152, }; enum atcphy_dp_link_rate { @@ -675,10 +728,22 @@ struct apple_atcphy; /** * struct atcphy_hw - SoC-specific PHY description - * @configure_post_tunable: Generation-specific setup after the tunables + * @configure_post_tunable: Generation-specific setup after the tunables, if any * @gen: Register programming generation - * @aciophy_lane_mode: Lane mode register offset + * @aciophy_lane_mode: Lane mode register offset, or zero to leave the lane + * mode alone (T8152 sets its lanes up through the crossbar) * @aciophy_crossbar: Crossbar register offset + * @cfg_offset: Offset of the power and reset block (ATCPHY_POWER_CTRL, + * ATCPHY_POWER_STAT, ATCPHY_MISC) from where those definitions + * place it + * @sync_reset: Register whose bit 0 is the reset the PHY's power-up releases + * first and its power-down asserts last, instead of + * ATCPHY_MISC_RESET_N, or zero + * @lane_swap: Lane swap bit in ATCPHY_MISC, or zero for ATCPHY_MISC_LANE_SWAP + * @cio_lane_swap: CIO (USB4) mode sets @lane_swap for a reversed plug as well, + * next to the swapped crossbar + * @typec_cio_only: On a Type-C port the PHY runs only CIO (USB4) mode, see + * apple_atcphy.cio_only * @has_usb4: A USB4/Thunderbolt controller sits behind the PHY * @usb2_only: Uses the USB2 subset unless its banked SuperSpeed resources exist * @usb2phy_sig_host: Host role field mask, or zero for the original layout @@ -691,6 +756,9 @@ struct apple_atcphy; * still works without the latter * @park_pipe_unlocked: A stopped controller may park without a PIPE handshake * @clear_boot_hold: Release the boot PIPE hold before dummy backend selection + * @pipe_lock_unacked: The PIPE handler takes the lock request but never + * acknowledges it, so the PIPE changes under the request + * without waiting for the acknowledge * @dp_banked_tunables: DisplayPort requires separate LIOA/common calibration * @dp_t8122: DisplayPort runs the T8122 AUX, AUSPLL and lane sequences * @park_dummy_phy: Enable the dummy PIPE backend whenever the PIPE is parked on @@ -710,6 +778,11 @@ struct atcphy_hw { enum atcphy_generation gen; int aciophy_lane_mode; int aciophy_crossbar; + u32 cfg_offset; + u32 sync_reset; + u32 lane_swap; + bool cio_lane_swap; + bool typec_cio_only; bool has_usb4; bool usb2_only; u32 usb2phy_sig_host; @@ -723,6 +796,7 @@ struct atcphy_hw { bool park_pipe_unlocked; bool park_dummy_phy; bool clear_boot_hold; + bool pipe_lock_unacked; bool restore_after_pd_off; bool idle_power_off; }; @@ -796,6 +870,21 @@ struct atcphy_cio_sleep { * behind the T6030 HDMI port; it maps only its core window * @fixed_usb2: The USB2 pairs go to a fixed hub on the USB controller, which * stays in host mode; the PHY provides USB2 from probe on + * @fixed_usb3: The SuperSpeed lanes go straight to a USB3 device or hub, with + * no Type-C mux in between (apple,fixed-usb3): the PHY runs USB3 + * on lane 0 from probe on and provides only the USB3 PHY of the + * controller, which is a host; its USB2 side and its reset are + * left to the bootloader + * @cio_only: A Type-C port on which the PHY runs CIO (USB4) mode alone + * (atcphy_hw.typec_cio_only): its DisplayPort mode is the display + * driver's, which powers the DP PHY while it drives the PHY itself, + * and its USB2 side is left to the bootloader. See + * atcphy_cio_mux_set(). + * @cio_pds: The power domains of a @cio_only PHY, in power-up order + * @cio_powered: The PHY holds @cio_pds for CIO mode + * @display_owned: The display driver drives a @cio_only PHY and holds @cio_pds + * through the DP PHY, or the bootloader left it driving a + * display, which the display driver takes over * @typec_mode: Mode the Type-C mux last asked for; a fixed-hub port returns to * it when the PHY is brought back up after a power-off * @host_active: dwc3 has selected host mode on the USB3 PHY; a fixed-hub port @@ -910,6 +999,11 @@ struct apple_atcphy { bool dp_presets_valid[5]; bool dp_only; bool fixed_usb2; + bool fixed_usb3; + bool cio_only; + struct dev_pm_domain_list *cio_pds; + bool cio_powered; + bool display_owned; enum atcphy_mode typec_mode; bool host_active; /* @@ -1276,6 +1370,115 @@ static inline u32 core_read32(struct apple_atcphy *atcphy, u32 reg) return readl(atcphy->regs.core + reg); } +/* A register of the power and reset block, see atcphy_hw.cfg_offset */ +static inline u32 atcphy_cfg(const struct apple_atcphy *atcphy, u32 reg) +{ + return reg + atcphy->hw->cfg_offset; +} + +static inline u32 atcphy_lane_swap(const struct apple_atcphy *atcphy) +{ + return atcphy->hw->lane_swap ?: ATCPHY_MISC_LANE_SWAP; +} + +/* T8152: the lanes a mode runs on, lane 0 for USB3, both for CIO (USB4) */ +static unsigned int atcphy_lanes_t8152(enum atcphy_mode mode) +{ + return mode == APPLE_ATCPHY_MODE_USB4 || mode == APPLE_ATCPHY_MODE_TBT ? 2 : 1; +} + +/* + * T8152 keeps a lane's registers in AHB reset until the lane is powered up on + * its own, and they drop their tunables meanwhile. Power the lanes of the mode + * up after the common-a tunables, one after the other: lane 0, the USB3 lane + * of a fixed-USB3 port, and in CIO mode lane 1 too. Each gets its LFPS + * receivers, then goes out of sleep, unclamped and out of AHB reset. Set the + * crossbar right after, before the remaining tunables, as the T8152 sequence + * does: 0x110 for USB3, i.e. USB3+DP with single PMA 0x008, and 0 or 1 for + * CIO by the plug orientation. atcphy_configure_lanes() writes the same value + * again later. + */ +static void atcphy_lanes_up_t8152(struct apple_atcphy *atcphy, enum atcphy_mode mode) +{ + const struct atcphy_mode_configuration *mode_cfg = atcphy_get_mode_config(atcphy, mode); + + for (unsigned int lane = 0; lane < atcphy_lanes_t8152(mode); lane++) { + u32 ctrl = ACIOPHY_T8152_AON_LANE(lane); + + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane)); + udelay(1); + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane)); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + } + + core_mask32(atcphy, atcphy->hw->aciophy_crossbar, + ACIOPHY_CROSSBAR_PROTOCOL | ACIOPHY_CROSSBAR_DP_SINGLE_PMA, + FIELD_PREP(ACIOPHY_CROSSBAR_PROTOCOL, mode_cfg->crossbar) | + FIELD_PREP(ACIOPHY_CROSSBAR_DP_SINGLE_PMA, + mode_cfg->crossbar_dp_single_pma)); +} + +/* + * T8152: power the lanes of the current mode down as the PHY powers down, the + * reverse of the above, while the register bus is still out of reset (a + * failed power-up may not have released it). A CIO-only PHY only ever runs + * CIO mode, so both of its lanes, also after a failed CIO power-up. Leaving + * CIO mode also clamps AUX and drops both lanes' LFPS receivers first, as the + * T8152 CIO shutdown does; the lanes' power controls are always-on and keep + * what they are left with across the common block's power-down. + */ +static void atcphy_lanes_down_t8152(struct apple_atcphy *atcphy) +{ + unsigned int lanes = atcphy->cio_only ? 2 : atcphy_lanes_t8152(atcphy->mode); + + if (!(core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL)) & + ATCPHY_POWER_APB_RESET_N)) + return; + + if (lanes > 1) { + core_set32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_CLAMP_EN); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_AUX_SLEEP_SMALL); + udelay(1); + for (unsigned int lane = 0; lane < lanes; lane++) { + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_SMALL(lane)); + udelay(1); + core_clear32(atcphy, ACIOPHY_T8152_AON_SLEEP_CTRL2, + ACIOPHY_T8152_AON_SLEEP_CTRL2_RXA_LFPS_BIG(lane)); + udelay(1); + } + } + + for (unsigned int lane = 0; lane < lanes; lane++) { + u32 ctrl = ACIOPHY_T8152_AON_LANE(lane); + + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_AHB_RESET_N); + udelay(1); + core_set32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_CLAMP_EN); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_BIG); + udelay(1); + core_clear32(atcphy, ctrl, ACIOPHY_T8152_AON_LANE_SLEEP_SMALL); + udelay(1); + } +} + /* Static configuration fields already read/modified by the public DP path. */ static void j700_dp_tunables(struct apple_atcphy *atcphy) { @@ -1305,6 +1508,8 @@ static void atcphy_apply_tunables(struct apple_atcphy *atcphy, enum atcphy_mode } apple_tunable_apply(atcphy->regs.core, atcphy->tunables.common[0]); + if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + atcphy_lanes_up_t8152(atcphy, mode); apple_tunable_apply(atcphy->regs.axi2af, atcphy->tunables.axi2af); apple_tunable_apply(atcphy->regs.core, atcphy->tunables.common[1]); @@ -1389,6 +1594,10 @@ static int atcphy_pipehandler_lock(struct apple_atcphy *atcphy) if (IS_ENABLED(CONFIG_PHY_APPLE_ATC_KUNIT_TEST)) KUNIT_STATIC_STUB_REDIRECT(atcphy_pipehandler_lock, atcphy); + if (atcphy->hw->pipe_lock_unacked) { + set32(atcphy->regs.pipehandler + PIPEHANDLER_LOCK_REQ, PIPEHANDLER_LOCK_EN); + return 0; + } return atcphy_pipehandler_lock_timeout(atcphy, atcphy->hw->gen == ATCPHY_GENERATION_T8132 ? 6000 : PIPEHANDLER_LOCK_ACK_TIMEOUT_US); @@ -1631,6 +1840,77 @@ static int atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *atc return ret; } +/* T8152: latch the BIST override registers into the USB side of the PHY */ +static void atcphy_t8152_bist_sync(struct apple_atcphy *atcphy) +{ + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC); + core_read32(atcphy, ACIOPHY_T8152_BIST_CFG0); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_USB_REGSYNC); +} + +static void atcphy_t8152_bist_ack(struct apple_atcphy *atcphy) +{ + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG2, ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG2, ACIOPHY_T8152_BIST_CFG2_LN0_PHY_STATUS_RE); +} + +/* + * T8152: while the PIPE moves from the dummy PHY to this one, the BIST + * overrides hold lane 0's PIPE reset and power-down, the power-down stepping + * from P2 to P3, and the non-selected PHY override is released under them. + */ +static int atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *atcphy) +{ + void __iomem *status = atcphy->regs.core + ACIOPHY_T8152_BIST_STATUS1; + int ret, error = 0; + u32 reg; + + core_set32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_CLOCK_EN); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV1, ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, + ACIOPHY_T8152_BIST_OV1_LN0_PIPE_RESET_N | + FIELD_PREP(ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, 2)); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV2, ACIOPHY_T8152_BIST_OV2_LN0, + ACIOPHY_T8152_BIST_OV2_LN0_PIPE_RESET_N_OV | + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV); + atcphy_t8152_bist_sync(atcphy); + ret = readl_poll_timeout(status, reg, !(reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2), + 10, 20000); + if (ret) { + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: PHY status stuck in P2 (%#x)\n", reg); + } + atcphy_t8152_bist_ack(atcphy); + + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV1, ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, + FIELD_PREP(ACIOPHY_T8152_BIST_OV1_LN0_PWR_DOWN, 3)); + core_mask32(atcphy, ACIOPHY_T8152_BIST_OV2, + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV | ACIOPHY_T8152_BIST_OV2_LN0_UNK10, + ACIOPHY_T8152_BIST_OV2_LN0_PWR_DOWN_OV); + atcphy_t8152_bist_sync(atcphy); + ret = readl_poll_timeout(status, reg, reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS, + 10, 130000); + if (ret) { + if (!error) + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: no PHY status in P3 (%#x)\n", reg); + } + ret = readl_poll_timeout(status, reg, !(reg & ACIOPHY_T8152_BIST_STATUS1_LN0_PHY_STATUS2), + 10, 1000); + if (ret) { + if (!error) + error = ret; + dev_warn(atcphy->dev, "T8152 USB3 BIST: PHY status stuck in P3 (%#x)\n", reg); + } + atcphy_t8152_bist_ack(atcphy); + + atcphy_clear_nonselected_phy_reset(atcphy); + + core_clear32(atcphy, ACIOPHY_T8152_BIST_OV2, ACIOPHY_T8152_BIST_OV2_LN0); + atcphy_t8152_bist_sync(atcphy); + core_clear32(atcphy, ACIOPHY_T8152_BIST_CFG0, ACIOPHY_T8152_BIST_CFG0_CLOCK_EN); + return error; +} + static int atcphy_configure_pipehandler_usb3_host_t8103(struct apple_atcphy *atcphy) { int ret, error = 0; @@ -1738,6 +2018,8 @@ static int atcphy_configure_pipehandler_usb3(struct apple_atcphy *atcphy, bool h ret = atcphy_configure_pipehandler_usb3_host_t8103(atcphy); else if (atcphy->hw->gen == ATCPHY_GENERATION_T8132) ret = atcphy_configure_pipehandler_usb3_host_t8132(atcphy); + else if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + ret = atcphy_configure_pipehandler_usb3_host_t8152(atcphy); else ret = atcphy_configure_pipehandler_usb3_host_t8122(atcphy); if (ret) { @@ -2147,21 +2429,24 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode mode == APPLE_ATCPHY_MODE_DP)) return j700_dp_route(atcphy, mode == APPLE_ATCPHY_MODE_DP); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX0, - FIELD_PREP(ACIOPHY_LANE_MODE_RX0, mode_cfg->lane_mode[0])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX0, - FIELD_PREP(ACIOPHY_LANE_MODE_TX0, mode_cfg->lane_mode[0])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX1, - FIELD_PREP(ACIOPHY_LANE_MODE_RX1, mode_cfg->lane_mode[1])); - core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX1, - FIELD_PREP(ACIOPHY_LANE_MODE_TX1, mode_cfg->lane_mode[1])); + if (atcphy->hw->aciophy_lane_mode) { + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX0, + FIELD_PREP(ACIOPHY_LANE_MODE_RX0, mode_cfg->lane_mode[0])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX0, + FIELD_PREP(ACIOPHY_LANE_MODE_TX0, mode_cfg->lane_mode[0])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_RX1, + FIELD_PREP(ACIOPHY_LANE_MODE_RX1, mode_cfg->lane_mode[1])); + core_mask32(atcphy, atcphy->hw->aciophy_lane_mode, ACIOPHY_LANE_MODE_TX1, + FIELD_PREP(ACIOPHY_LANE_MODE_TX1, mode_cfg->lane_mode[1])); + } core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_PROTOCOL, FIELD_PREP(ACIOPHY_CROSSBAR_PROTOCOL, mode_cfg->crossbar)); - if (mode_cfg->set_swap) - core_set32(atcphy, ATCPHY_MISC, ATCPHY_MISC_LANE_SWAP); + if (mode_cfg->set_swap || + (atcphy->hw->cio_lane_swap && atcphy_mode_is_cio(mode) && atcphy->swap_lanes)) + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); else - core_clear32(atcphy, ATCPHY_MISC, ATCPHY_MISC_LANE_SWAP); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), atcphy_lane_swap(atcphy)); core_mask32(atcphy, atcphy->hw->aciophy_crossbar, ACIOPHY_CROSSBAR_DP_SINGLE_PMA, FIELD_PREP(ACIOPHY_CROSSBAR_DP_SINGLE_PMA, mode_cfg->crossbar_dp_single_pma)); @@ -2173,8 +2458,10 @@ static int atcphy_configure_lanes(struct apple_atcphy *atcphy, enum atcphy_mode /* * The PMA FSM override below is for the T8103 generation. T8122 DP lanes * are started by the link rate sequence, see atcphy_dp_set_rate_t8122(). + * T8152 runs USB3 or CIO alone. */ - if (atcphy->hw->gen == ATCPHY_GENERATION_T8122) + if (atcphy->hw->gen == ATCPHY_GENERATION_T8122 || + atcphy->hw->gen == ATCPHY_GENERATION_T8152) return 0; if (mode_cfg->dp_lane[0]) { @@ -2707,34 +2994,44 @@ static int atcphy_power_off(struct apple_atcphy *atcphy) u32 reg; int ret; - if (atcphy->hw->gen != ATCPHY_GENERATION_T8132) { + /* A fixed-USB3 port has no DisplayPort side, a CIO-only port leaves it alone */ + if (atcphy->hw->gen != ATCPHY_GENERATION_T8132 && !atcphy->fixed_usb3 && + !atcphy->cio_only) { ret = atcphy_disable_dp_aux(atcphy); if (ret) return ret; } /* Enable all reset lines */ - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); - core_clear32(atcphy, ATCPHY_MISC, ATCPHY_MISC_RESET_N | ATCPHY_MISC_LANE_SWAP); - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_APB_RESET_N); - - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_PHY_RESET_N); + if (atcphy->hw->gen == ATCPHY_GENERATION_T8152) + atcphy_lanes_down_t8152(atcphy); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_CLAMP_EN); + if (!atcphy->hw->sync_reset) + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_MISC), + ATCPHY_MISC_RESET_N | ATCPHY_MISC_LANE_SWAP); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_APB_RESET_N); + + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_BIG); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, !(reg & ATCPHY_POWER_SLEEP_BIG), 10, 1000); if (ret) { dev_err(atcphy->dev, "Failed to sleep atcphy \"big\"\n"); return ret; } - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_SMALL); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, !(reg & ATCPHY_POWER_SLEEP_SMALL), 10, 1000); if (ret) { dev_err(atcphy->dev, "Failed to sleep atcphy \"small\"\n"); return ret; } + /* A separate sync reset is asserted last, once the block sleeps */ + if (atcphy->hw->sync_reset) + core_clear32(atcphy, atcphy->hw->sync_reset, ATCPHY_MISC_RESET_N); + return 0; } @@ -2792,29 +3089,30 @@ static int atcphy_power_on(struct apple_atcphy *atcphy) u32 reg; int ret; - if (!atcphy->dp_only) + if (!atcphy->dp_only && !atcphy->fixed_usb3 && !atcphy->cio_only) atcphy_usb2_power_on(atcphy); - core_set32(atcphy, ATCPHY_MISC, ATCPHY_MISC_RESET_N); + core_set32(atcphy, atcphy->hw->sync_reset ?: atcphy_cfg(atcphy, ATCPHY_MISC), + ATCPHY_MISC_RESET_N); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_SMALL); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_SMALL); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, reg & ATCPHY_POWER_SLEEP_SMALL, 100, 100000); if (ret) { dev_err(atcphy->dev, "failed to wakeup atcphy \"small\"\n"); return ret; } - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_SLEEP_BIG); - ret = readl_poll_timeout(atcphy->regs.core + ATCPHY_POWER_STAT, reg, + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_SLEEP_BIG); + ret = readl_poll_timeout(atcphy->regs.core + atcphy_cfg(atcphy, ATCPHY_POWER_STAT), reg, reg & ATCPHY_POWER_SLEEP_BIG, 100, 100000); if (ret) { dev_err(atcphy->dev, "failed to wakeup atcphy \"big\"\n"); return ret; } - core_clear32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_CLAMP_EN); - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_APB_RESET_N); + core_clear32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_CLAMP_EN); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_APB_RESET_N); return 0; } @@ -4265,7 +4563,8 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) apple_tunable_apply(atcphy->regs.lioa, atcphy->tunables.dp_lioa); apple_tunable_apply(atcphy->regs.lpdptx, atcphy->tunables.dp_common_config); } - atcphy->hw->configure_post_tunable(atcphy, mode); + if (atcphy->hw->configure_post_tunable) + atcphy->hw->configure_post_tunable(atcphy, mode); /* Setup AUX channel if DP altmode is requested */ if (atcphy_modes[mode].enable_dp_aux) { @@ -4284,7 +4583,7 @@ static int atcphy_configure(struct apple_atcphy *atcphy, enum atcphy_mode mode) return ret; /* Take the USB3 PHY out of reset */ - core_set32(atcphy, ATCPHY_POWER_CTRL, ATCPHY_POWER_PHY_RESET_N); + core_set32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL), ATCPHY_POWER_PHY_RESET_N); /* * NOTE: Not what macos does, it takes the phy out of reset right before * writing to ACIOPHY_CFG0_COMMON_SMALL, does lane configuration with phy @@ -4753,7 +5052,7 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode readl(atcphy->regs.pipehandler + PIPEHANDLER_MUX_CTRL), readl(atcphy->regs.pipehandler + PIPEHANDLER_NONSELECTED_OVERRIDE), readl(atcphy->regs.pipehandler + PIPEHANDLER_T8132_USB2_CONFIG)); - if (!ret || !atcphy->fixed_usb2 || mode != PHY_MODE_USB_HOST) + if (!ret || !(atcphy->fixed_usb2 || atcphy->fixed_usb3) || mode != PHY_MODE_USB_HOST) return ret; /* @@ -4761,7 +5060,8 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode * fails, xHCI registers neither of its root hubs. Let it start, with * the PIPE parked if that works: the Type-C mux update that restores * the lanes or retries the handoff routes the PIPE, with the - * SuperSpeed port off. + * SuperSpeed port off. On a fixed-USB3 port the controller's next + * power-on of this PHY tries again. */ if (atcphy_park_pipehandler(atcphy, false)) dev_warn(atcphy->dev, "Host starts with its PIPE not parked\n"); @@ -4770,6 +5070,35 @@ static int atcphy_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode return 0; } +/* + * A fixed-USB3 port's controller is a host by construction. It powers this + * PHY on after its core reset, before the host starts: route the PIPE to the + * USB3 PHY then, bringing the PHY up in USB3 again first if a power-off took + * it down. A failure here would stop the controller altogether, and with it + * the USB2 side of the same device, so the host then starts with its PIPE + * parked instead. + */ +static int atcphy_usb3_power_on(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + int ret = 0; + + guard(mutex)(&atcphy->lock); + atcphy->host_active = true; + if (atcphy->mode != APPLE_ATCPHY_MODE_USB3 || atcphy->mode_dirty) + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB3); + if (!ret) + ret = atcphy_usb3_route(atcphy, true); + if (!ret) + return 0; + + if (atcphy_park_pipehandler(atcphy, false)) + dev_warn(atcphy->dev, "Host starts with its PIPE not parked\n"); + else + dev_warn(atcphy->dev, "Host starts without USB3: %d\n", ret); + return 0; +} + static int atcphy_usb3_exit(struct phy *phy) { struct apple_atcphy *atcphy = phy_get_drvdata(phy); @@ -4817,6 +5146,17 @@ static const struct phy_ops apple_atc_usb3_phy_ops = { .set_mode = atcphy_rpm_usb3_set_mode, }; +/* + * A fixed-USB3 port also routes its PIPE at power-on. Its PHY never + * runtime-suspends (see atcphy_rpm_get()), so it needs no runtime PM wrappers. + */ +static const struct phy_ops apple_atc_fixed_usb3_phy_ops = { + .owner = THIS_MODULE, + .power_on = atcphy_usb3_power_on, + .power_off = atcphy_usb3_power_off, + .set_mode = atcphy_usb3_set_mode, +}; + /* * The T8132 PHY has no DisplayPort alternate mode: its DP PHY only exists so * that a DisplayPort tunnel can get its pixel clock, see @@ -5188,6 +5528,192 @@ int apple_atc_dp_tunnel_open(struct phy *phy) } EXPORT_SYMBOL_GPL(apple_atc_dp_tunnel_open); +/* + * T8152's rear USB-C ports (atcphy_hw.typec_cio_only, apple_atcphy.cio_only): + * the PHY runs CIO mode for a USB4 partner and is left alone otherwise. + * + * Their DisplayPort alt mode is still driven by the display driver, which + * programs the PHY's power and reset block, lanes and display crossbar + * itself. The two take turns on the PHY: + * + * - The display driver powers the DP PHY on before it touches the PHY and + * off once it has let go of it. The DP PHY then holds the PHY's power + * domains for it, and keeps the PHY out of CIO mode: a USB4 mode change + * fails with -ETIMEDOUT, which the Type-C port driver retries (the mux + * declares its timeouts transient) until the display driver is done. + * - A DP PHY power-on is refused with -EBUSY while the PHY runs CIO mode. + * - Either takes the PHY only from its idle state: the power and reset block + * as the power-up leaves it, clamped and asleep, its sync reset asserted. + * Anything else means another user still has it, and CIO mode is refused. + * - A display the bootloader brought up keeps running for the display + * driver: such a PHY has all its domains on and is not idle at probe, and + * the domains are held for the display driver until its DP PHY goes off. + * + * Once the DisplayPort mode moves into this driver, the DP PHY programs it + * itself, both modes switch under the PHY's lock, and this arbitration goes. + */ +static int atcphy_cio_pds_on(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + int ret; + + for (unsigned int i = 0; i < pds->num_pds; i++) { + ret = pm_runtime_resume_and_get(pds->pd_devs[i]); + if (ret < 0) { + while (i--) + pm_runtime_put_sync(pds->pd_devs[i]); + return ret; + } + } + return 0; +} + +/* Synchronously: the next CIO mode or display must find them off. */ +static void atcphy_cio_pds_off(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + + for (unsigned int i = pds->num_pds; i > 0; i--) + pm_runtime_put_sync(pds->pd_devs[i - 1]); +} + +/* The power and reset block as its power-up leaves it, with its domains on */ +static bool atcphy_cio_idle(struct apple_atcphy *atcphy) +{ + return core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL)) == + ATCPHY_POWER_CLAMP_EN && + !(core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_STAT)) & + (ATCPHY_POWER_SLEEP_SMALL | ATCPHY_POWER_SLEEP_BIG)) && + !core_read32(atcphy, atcphy->hw->sync_reset); +} + +/* + * The CIO shutdown, then the power domains: the common block goes cold, so + * that the next partner, in either orientation, starts from a cold PHY. With + * the common block left powered, the next link training asserted in the + * router's firmware. A failed shutdown keeps the domains for the next try. + */ +static int atcphy_cio_stop(struct apple_atcphy *atcphy) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_OFF); + if (ret) { + dev_err(atcphy->dev, "CIO shutdown failed: %d\n", ret); + return ret; + } + atcphy_cio_pds_off(atcphy); + atcphy->cio_powered = false; + dev_dbg(atcphy->dev, "CIO mode off\n"); + return 0; +} + +static int atcphy_cio_start(struct apple_atcphy *atcphy, enum atcphy_mode mode) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + /* The router's Thunderbolt mode is not qualified on these ports. */ + if (mode != APPLE_ATCPHY_MODE_USB4) { + dev_info(atcphy->dev, "Thunderbolt alt mode is not supported on this port\n"); + return -ENODEV; + } + if (atcphy->display_owned) { + dev_dbg(atcphy->dev, "USB4 waits for the display driver to release the PHY\n"); + return -ETIMEDOUT; + } + ret = atcphy_cio_pds_on(atcphy); + if (ret) + return ret; + if (!atcphy_cio_idle(atcphy)) { + dev_warn(atcphy->dev, "PHY not idle (power control %#x), USB4 refused\n", + core_read32(atcphy, atcphy_cfg(atcphy, ATCPHY_POWER_CTRL))); + atcphy_cio_pds_off(atcphy); + return -EBUSY; + } + atcphy->cio_powered = true; + ret = atcphy_configure(atcphy, mode); + if (ret) { + dev_err(atcphy->dev, "CIO mode failed: %d\n", ret); + atcphy_cio_stop(atcphy); + return ret; + } + dev_dbg(atcphy->dev, "CIO mode on, %s\n", atcphy->swap_lanes ? "reversed" : "normal"); + return 0; +} + +/* USB4 asks for CIO mode; every other state leaves the PHY to its other users. */ +static enum atcphy_mode atcphy_cio_target_mode(const struct typec_mux_state *state) +{ + const struct enter_usb_data *data = state->data; + + if (state->alt && state->alt->svid == USB_TYPEC_TBT_SID) + return APPLE_ATCPHY_MODE_TBT; + if (!state->alt && state->mode == TYPEC_MODE_USB4 && data && + FIELD_GET(EUDO_USB_MODE_MASK, data->eudo) == EUDO_USB_MODE_USB4) + return APPLE_ATCPHY_MODE_USB4; + return APPLE_ATCPHY_MODE_OFF; +} + +/* + * The Type-C port driver sets the mux before it starts the USB4 router and + * after it stops it, so CIO mode comes up before the router starts and goes + * down after it stopped. + */ +static int atcphy_cio_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *state) +{ + struct apple_atcphy *atcphy = typec_mux_get_drvdata(mux); + enum atcphy_mode mode = atcphy_cio_target_mode(state); + int ret; + + guard(mutex)(&atcphy->lock); + if (atcphy->cio_powered) { + if (atcphy->mode == mode && !atcphy->mode_dirty) + return 0; + ret = atcphy_cio_stop(atcphy); + if (ret) + return ret; + } + if (mode == APPLE_ATCPHY_MODE_OFF) + return 0; + return atcphy_cio_start(atcphy, mode); +} + +/* The display driver takes the PHY of a CIO-only port, see above. */ +static int atcphy_cio_dp_power_on(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + int ret; + + guard(mutex)(&atcphy->lock); + if (atcphy->display_owned) + return 0; + if (atcphy->cio_powered) + return -EBUSY; + ret = atcphy_cio_pds_on(atcphy); + if (!ret) + atcphy->display_owned = true; + return ret; +} + +static int atcphy_cio_dp_power_off(struct phy *phy) +{ + struct apple_atcphy *atcphy = phy_get_drvdata(phy); + + guard(mutex)(&atcphy->lock); + if (atcphy->display_owned) + atcphy_cio_pds_off(atcphy); + atcphy->display_owned = false; + return 0; +} + +static const struct phy_ops apple_atc_cio_dp_phy_ops = { + .owner = THIS_MODULE, + .power_on = atcphy_cio_dp_power_on, + .power_off = atcphy_cio_dp_power_off, +}; + static struct phy *atcphy_xlate(struct device *dev, const struct of_phandle_args *args) { struct apple_atcphy *atcphy = dev_get_drvdata(dev); @@ -5206,7 +5732,7 @@ static struct phy *atcphy_xlate(struct device *dev, const struct of_phandle_args default: return ERR_PTR(-ENODEV); } - /* A DisplayPort-only or USB2-only instance omits the other PHYs. */ + /* A DisplayPort-, USB2- or USB3-only instance omits the other PHYs. */ return phy ?: ERR_PTR(-ENODEV); } @@ -5217,18 +5743,22 @@ static int atcphy_probe_phy(struct apple_atcphy *atcphy) const struct phy_ops *ops; } phys[] = { { &atcphy->phys.usb2, &apple_atc_usb2_phy_ops }, - { &atcphy->phys.usb3, &apple_atc_usb3_phy_ops }, - { &atcphy->phys.dp, &apple_atc_dp_phy_ops }, + { &atcphy->phys.usb3, atcphy->fixed_usb3 ? &apple_atc_fixed_usb3_phy_ops : + &apple_atc_usb3_phy_ops }, + { &atcphy->phys.dp, atcphy->cio_only ? &apple_atc_cio_dp_phy_ops : + &apple_atc_dp_phy_ops }, }; /* * A T8132 PHY with its USB3/USB4 banks gets a DP PHY for DisplayPort * tunnels only (see atcphy_dpphy_set_mode_t8132()); creating it does - * not touch the hardware. + * not touch the hardware. A fixed-USB3 PHY gets its USB3 PHY only, a + * CIO-only PHY the DP PHY through which the display driver takes it. */ for (int i = 0; i < ARRAY_SIZE(phys); i++) { - if ((atcphy->dp_only && phys[i].phy != &atcphy->phys.dp) || - (atcphy_usb2_only(atcphy) && i != 0)) + if (((atcphy->dp_only || atcphy->cio_only) && phys[i].phy != &atcphy->phys.dp) || + (atcphy_usb2_only(atcphy) && i != 0) || + (atcphy->fixed_usb3 && phys[i].phy != &atcphy->phys.usb3)) continue; *phys[i].phy = devm_phy_create(atcphy->dev, NULL, phys[i].ops); if (IS_ERR(*phys[i].phy)) @@ -6194,9 +6724,10 @@ static int atcphy_probe_mux(struct apple_atcphy *atcphy) struct typec_mux_desc mux_desc = { .drvdata = atcphy, .fwnode = atcphy->dev->fwnode, - .set = atcphy_mux_set, + .set = atcphy->cio_only ? atcphy_cio_mux_set : atcphy_mux_set, .safe_after_role = !atcphy->fixed_usb2, - .transient_timeouts = atcphy_mux_transient_timeouts(atcphy), + /* A CIO-only PHY times out while the display driver has it. */ + .transient_timeouts = atcphy->cio_only || atcphy_mux_transient_timeouts(atcphy), }; mux = typec_mux_register(atcphy->dev, &mux_desc); @@ -6412,6 +6943,23 @@ static int atcphy_load_tunables(struct apple_atcphy *atcphy) bool lane_dp = tunables[i].tunable == &atcphy->tunables.lane_dp[0] || tunables[i].tunable == &atcphy->tunables.lane_dp[1]; + /* a fixed-USB3 port runs USB3 on lane 0 alone and has no axi2af window */ + if (atcphy->fixed_usb3 && + tunables[i].tunable != &atcphy->tunables.common[0] && + tunables[i].tunable != &atcphy->tunables.common[1] && + tunables[i].tunable != &atcphy->tunables.lane_usb3[0]) { + *tunables[i].tunable = NULL; + continue; + } + /* a CIO-only port has its common and CIO lane tunables alone */ + if (atcphy->cio_only && + tunables[i].tunable != &atcphy->tunables.common[0] && + tunables[i].tunable != &atcphy->tunables.common[1] && + tunables[i].tunable != &atcphy->tunables.lane_usb4[0] && + tunables[i].tunable != &atcphy->tunables.lane_usb4[1]) { + *tunables[i].tunable = NULL; + continue; + } if (!atcphy->hw->has_usb4 && (tunables[i].tunable == &atcphy->tunables.lane_usb4[0] || tunables[i].tunable == &atcphy->tunables.lane_usb4[1])) { @@ -6516,6 +7064,31 @@ static int atcphy_map_resources(struct platform_device *pdev, struct apple_atcph struct resource *res; void __iomem *addr; + /* + * A fixed-USB3 PHY has its core and PIPE windows only, a CIO-only PHY its + * core window. On T8152 the core window also holds the USB controller's + * DARTs, and the display driver maps it too, so it is mapped without + * claiming it. + */ + if (atcphy->fixed_usb3 || atcphy->cio_only) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!res) + return dev_err_probe(atcphy->dev, -EINVAL, "Missing core regs\n"); + atcphy->regs.core = devm_ioremap(&pdev->dev, res->start, resource_size(res)); + if (!atcphy->regs.core) + return -ENOMEM; + atcphy->res.core = res; + if (atcphy->cio_only) + return 0; + + addr = devm_platform_ioremap_resource_byname(pdev, "pipehandler"); + if (IS_ERR(addr)) + return dev_err_probe(atcphy->dev, PTR_ERR(addr), + "Unable to map pipehandler regs\n"); + atcphy->regs.pipehandler = addr; + return 0; + } + if (atcphy->hw->gen == ATCPHY_GENERATION_T8132 && platform_get_resource_byname(pdev, IORESOURCE_MEM, "common-config")) { static const char * const names[] = { @@ -6743,6 +7316,92 @@ static int atcphy_probe_finalize_dp_only(struct apple_atcphy *atcphy) return 0; } +/* + * A fixed-USB3 port: the bootloader hands its controller over running, with + * the controller's reset and its USB2 side its own, and no Type-C mux sits in + * front of the lanes, so there is no reset controller, mux or switch to + * register. Take the PHY from the state the bootloader left it in to USB3; the + * PIPE follows when the controller powers its USB3 PHY on, which also tries + * again if this fails, see atcphy_usb3_power_on(). + */ +static int atcphy_probe_finalize_fixed_usb3(struct apple_atcphy *atcphy) +{ + int ret; + + lockdep_assert_held(&atcphy->lock); + + atcphy_power_off(atcphy); + atcphy_setup_pipehandler(atcphy); + ret = atcphy_configure(atcphy, APPLE_ATCPHY_MODE_USB3); + if (ret) + dev_warn(atcphy->dev, "USB3 not up yet: %d\n", ret); + + ret = atcphy_probe_phy(atcphy); + if (ret) { + atcphy_configure(atcphy, APPLE_ATCPHY_MODE_OFF); + return dev_err_probe(atcphy->dev, ret, "Probing phy failed"); + } + return 0; +} + +/* Let go of the PHY of a CIO-only port on unbind, see atcphy_cio_mux_set(). */ +static void atcphy_cio_release(void *data) +{ + struct apple_atcphy *atcphy = data; + + guard(mutex)(&atcphy->lock); + if (atcphy->cio_powered) + atcphy_cio_stop(atcphy); + if (atcphy->display_owned) + atcphy_cio_pds_off(atcphy); + atcphy->display_owned = false; +} + +/* + * A CIO-only port: probe leaves the hardware as it is. A display the + * bootloader brought up on the port has all of the PHY's power domains on, + * and the PHY is not idle: hold the domains for the display driver, which + * takes it over, until its DP PHY goes off. Otherwise the domains are left to + * their power domain driver. Then register the mux, the orientation switch + * and the DP PHY. + */ +static int atcphy_probe_finalize_cio_only(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_list *pds = atcphy->cio_pds; + bool all_on = true; + int ret; + + lockdep_assert_held(&atcphy->lock); + + ret = devm_add_action(atcphy->dev, atcphy_cio_release, atcphy); + if (ret) + return ret; + for (unsigned int i = 0; i < pds->num_pds; i++) + all_on &= dev_pm_genpd_is_on(pds->pd_devs[i]); + if (all_on) { + ret = atcphy_cio_pds_on(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Failed to power the PHY\n"); + if (atcphy_cio_idle(atcphy)) { + atcphy_cio_pds_off(atcphy); + } else { + atcphy->display_owned = true; + dev_info(atcphy->dev, "PHY in use at boot, held for the display driver\n"); + } + } + + ret = atcphy_probe_mux(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing mux failed\n"); + ret = atcphy_probe_switch(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing switch failed\n"); + ret = atcphy_probe_phy(atcphy); + if (ret) + return dev_err_probe(atcphy->dev, ret, "Probing phy failed\n"); + return 0; +} + static int atcphy_probe_finalize(struct apple_atcphy *atcphy) { int ret; @@ -6751,6 +7410,10 @@ static int atcphy_probe_finalize(struct apple_atcphy *atcphy) if (atcphy->dp_only) return atcphy_probe_finalize_dp_only(atcphy); + if (atcphy->fixed_usb3) + return atcphy_probe_finalize_fixed_usb3(atcphy); + if (atcphy->cio_only) + return atcphy_probe_finalize_cio_only(atcphy); /* Reset dwc3 on probe, let dwc3 (consumer) deassert it */ _atcphy_dwc3_reset_assert(atcphy); @@ -6882,6 +7545,37 @@ static bool atcphy_has_t8103_usb3_workaround(const struct atcphy_hw *hw, of_device_is_compatible(root, "apple,t8103"); } +/* + * The driver core attaches a single power domain. A fixed-USB3 PHY may list + * several, like T8152's ATC power states and PSD service: hold them all on + * while it is bound, powered up in the order they are listed. + */ +static int atcphy_probe_power_domains(struct apple_atcphy *atcphy) +{ + struct dev_pm_domain_attach_data pd_data = { .pd_flags = PD_FLAG_DEV_LINK_ON }; + struct dev_pm_domain_list *pd_list; + int ret; + + /* + * A CIO-only PHY powers its domains only while it runs CIO mode or the + * display driver has it, see atcphy_cio_mux_set(). + */ + if (atcphy->cio_only) { + pd_data.pd_flags = PD_FLAG_NO_DEV_LINK; + ret = devm_pm_domain_attach_list(atcphy->dev, &pd_data, &atcphy->cio_pds); + if (ret <= 0) + return dev_err_probe(atcphy->dev, ret ?: -EINVAL, + "Failed to attach power domains\n"); + return 0; + } + if (!atcphy->fixed_usb3 || atcphy->dev->pm_domain) + return 0; + ret = devm_pm_domain_attach_list(atcphy->dev, &pd_data, &pd_list); + if (ret < 0) + return dev_err_probe(atcphy->dev, ret, "Failed to attach power domains\n"); + return 0; +} + static void atcphy_sleep_finish_work(struct work_struct *work); static int atcphy_probe(struct platform_device *pdev) @@ -6904,6 +7598,8 @@ static int atcphy_probe(struct platform_device *pdev) atcphy->np = dev->of_node; atcphy->t8132_dp_alt = atcphy->hw->gen == ATCPHY_GENERATION_T8132 && of_property_read_bool(dev->of_node, "apple,dp-alt-mode"); + atcphy->fixed_usb3 = of_property_read_bool(dev->of_node, "apple,fixed-usb3"); + atcphy->cio_only = atcphy->hw->typec_cio_only && !atcphy->fixed_usb3; apple_atc_tunnel_wiring(atcphy); mutex_init(&atcphy->lock); platform_set_drvdata(pdev, atcphy); @@ -6912,6 +7608,9 @@ static int atcphy_probe(struct platform_device *pdev) if (ret) return ret; ret = atcphy_load_tunables(atcphy); + if (ret) + return ret; + ret = atcphy_probe_power_domains(atcphy); if (ret) return ret; @@ -7983,12 +8682,46 @@ static const struct atcphy_hw atcphy_hw_t8142 = { .clear_boot_hold = true, }; +/* + * T8152 as the USB3 PHY of a fixed-USB3 port, or as a Type-C port's PHY in CIO + * mode alone (see atcphy_cio_mux_set()): no DisplayPort mode, no lane mode + * register and nothing to wake after the tunables. A fixed-USB3 port does not + * follow its power domains: the controller's power-off and power-on of the + * PHY, as around a system sleep, take it down and up again. + */ +static const struct atcphy_hw atcphy_hw_t8152 = { + .gen = ATCPHY_GENERATION_T8152, + .aciophy_crossbar = ACIOPHY_CROSSBAR_T8103, + .cfg_offset = ATCPHY_T8152_CFG_OFFSET, + .sync_reset = ATCPHY_T8152_SYNC_RESET, + .lane_swap = ATCPHY_T8152_MISC_LANE_SWAP, + .pipe_mux_clk = PIPEHANDLER_MUX_CTRL_CLK_T8142, + .pipe_mux_data = PIPEHANDLER_MUX_CTRL_DATA_T8142, + .has_usb4 = true, + .park_dummy_phy = true, + .clear_boot_hold = true, + /* + * With the controller out of reset, the J873g front port's PIPE handler + * left the lock unacknowledged for 150 ms in both directions, while the + * PIPE moved to USB3 and back to the dummy PHY under the request. + */ + .pipe_lock_unacked = true, + /* + * Its Type-C ports run CIO mode alone; a reversed plug takes the + * swapped crossbar and the lane swap, with which the J873g's rear ports + * trained USB4 at 2 x 20 Gb/s. + */ + .typec_cio_only = true, + .cio_lane_swap = true, +}; + static const struct of_device_id atcphy_match[] = { { .compatible = "apple,t8103-atcphy", .data = &atcphy_hw_t8103 }, { .compatible = "apple,t8122-atcphy", .data = &atcphy_hw_t8122 }, { .compatible = "apple,t8132-atcphy", .data = &atcphy_hw_t8132 }, { .compatible = "apple,t8142-atcphy", .data = &atcphy_hw_t8142 }, { .compatible = "apple,t8140-atcphy", .data = &atcphy_hw_t8140 }, + { .compatible = "apple,t8152-atcphy", .data = &atcphy_hw_t8152 }, {}, }; MODULE_DEVICE_TABLE(of, atcphy_match); diff --git a/drivers/pmdomain/apple/Kconfig b/drivers/pmdomain/apple/Kconfig index 118bcd1736242..7c6469fabdc04 100644 --- a/drivers/pmdomain/apple/Kconfig +++ b/drivers/pmdomain/apple/Kconfig @@ -26,6 +26,18 @@ config APPLE_PMGR_PWRSTATE_KUNIT_TEST and need no Apple hardware. Also check the T6000 GFX missing-parent wait, its timeout, and the separate actual-state acknowledgment. +config APPLE_PMGR_PSD + bool "Apple T8152 PMGR service power domains" + depends on ARCH_APPLE || COMPILE_TEST + depends on PM && OF + select PM_GENERIC_DOMAINS + default ARCH_APPLE + help + The T8152 PMGR switches some blocks, among them the USB and USB4 + DARTs and controllers and the video decoder, through service + power states (PSD) rather than PMGR power state registers. This + driver offers each service as a generic power domain. + config APPLE_T6041_CIO_RECONFIG bool "Apple T6041 CIO cluster reconfiguration" depends on OF diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index 351773930cb84..34b8898eff911 100644 --- a/drivers/pmdomain/apple/Makefile +++ b/drivers/pmdomain/apple/Makefile @@ -8,3 +8,4 @@ obj-$(CONFIG_APPLE_PMP_DRAM_KUNIT_TEST) += pmp-dram-test.o obj-$(CONFIG_APPLE_PMC) += pmc.o obj-$(CONFIG_APPLE_PMP_ANE_KUNIT_TEST) += pmp-ane-test.o obj-$(CONFIG_APPLE_PMP_FLOOR_KUNIT_TEST) += pmp-floor-gov-test.o +obj-$(CONFIG_APPLE_PMGR_PSD) += pmgr-psd.o diff --git a/drivers/pmdomain/apple/pmgr-psd.c b/drivers/pmdomain/apple/pmgr-psd.c new file mode 100644 index 0000000000000..04bbf0d35e948 --- /dev/null +++ b/drivers/pmdomain/apple/pmgr-psd.c @@ -0,0 +1,151 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 PMGR2 PSD services as power domains. + * + * Each service has a 0x100 byte register block: the target state at +0x90, + * the acknowledge in bit 0 of +0xbc, and the current state in bits 2:0 of + * +0x80 (0 powered, 6 cold). Reading the state consumes the acknowledge, so + * the state is read only once the acknowledge is set. + * + * The consumers include IRQ-safe devices (DARTs), so the domains are IRQ-safe + * and a transition is polled atomically, as for the PMGR power states. + */ +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PSD_STATE 0x80 +#define APPLE_PSD_STATE_CUR GENMASK(2, 0) +#define APPLE_PSD_TARGET 0x90 +#define APPLE_PSD_ACK 0xbc +#define APPLE_PSD_ACK_DONE BIT(0) + +#define APPLE_PSD_ON 0 +#define APPLE_PSD_COLD 6 + +#define APPLE_PSD_TIMEOUT_US 10000 + +struct apple_psd { + struct generic_pm_domain genpd; + struct device *dev; + void __iomem *regs; +}; + +static u32 apple_psd_state(struct apple_psd *psd) +{ + return readl(psd->regs + APPLE_PSD_STATE) & APPLE_PSD_STATE_CUR; +} + +static bool apple_psd_reached(struct apple_psd *psd, u32 target, u32 *ack, + u32 *state) +{ + *ack = readl(psd->regs + APPLE_PSD_ACK); + if (!(*ack & APPLE_PSD_ACK_DONE)) + return false; + *state = apple_psd_state(psd); + return *state == target; +} + +static int apple_psd_set_state(struct generic_pm_domain *genpd, u32 target) +{ + struct apple_psd *psd = container_of(genpd, struct apple_psd, genpd); + u32 ack = 0, state; + bool done; + int ret; + + state = apple_psd_state(psd); + if (state == target) + return 0; + writel(target, psd->regs + APPLE_PSD_TARGET); + ret = read_poll_timeout_atomic(apple_psd_reached, done, done, 1, + APPLE_PSD_TIMEOUT_US, false, psd, target, + &ack, &state); + if (ret) { + dev_err(psd->dev, "%s: state %u not reached: ack %#x, state %u\n", + genpd->name, target, ack, state); + return ret; + } + return 0; +} + +static int apple_psd_power_on(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_ON); +} + +static int apple_psd_power_off(struct generic_pm_domain *genpd) +{ + return apple_psd_set_state(genpd, APPLE_PSD_COLD); +} + +static void apple_psd_remove_provider(void *data) +{ + struct apple_psd *psd = data; + + of_genpd_del_provider(psd->dev->of_node); + pm_genpd_remove(&psd->genpd); +} + +static int apple_psd_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct apple_psd *psd; + bool is_off; + int ret; + + psd = devm_kzalloc(dev, sizeof(*psd), GFP_KERNEL); + if (!psd) + return -ENOMEM; + psd->dev = dev; + psd->regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(psd->regs)) + return PTR_ERR(psd->regs); + + if (of_property_read_string(np, "label", &psd->genpd.name)) + psd->genpd.name = dev_name(dev); + psd->genpd.power_on = apple_psd_power_on; + psd->genpd.power_off = apple_psd_power_off; + psd->genpd.flags = GENPD_FLAG_IRQ_SAFE; + + if (of_property_read_bool(np, "apple,always-on")) { + psd->genpd.flags |= GENPD_FLAG_ALWAYS_ON; + ret = apple_psd_power_on(&psd->genpd); + if (ret) + return ret; + } + is_off = apple_psd_state(psd) != APPLE_PSD_ON; + + ret = pm_genpd_init(&psd->genpd, NULL, is_off); + if (ret) + return ret; + ret = of_genpd_add_provider_simple(np, &psd->genpd); + if (ret) { + pm_genpd_remove(&psd->genpd); + return ret; + } + return devm_add_action_or_reset(dev, apple_psd_remove_provider, psd); +} + +static const struct of_device_id apple_psd_match[] = { + { .compatible = "apple,t8152-psd" }, + {} +}; +MODULE_DEVICE_TABLE(of, apple_psd_match); + +static struct platform_driver apple_psd_driver = { + .probe = apple_psd_probe, + .driver = { + .name = "apple-pmgr-psd", + .of_match_table = apple_psd_match, + .suppress_bind_attrs = true, + }, +}; +module_platform_driver(apple_psd_driver); + +MODULE_LICENSE("Dual MIT/GPL"); +MODULE_DESCRIPTION("Apple T8152 PMGR2 PSD power domains"); diff --git a/drivers/reset/reset-apple-cio.c b/drivers/reset/reset-apple-cio.c index e5755ebb39aff..b2dd69f30fde3 100644 --- a/drivers/reset/reset-apple-cio.c +++ b/drivers/reset/reset-apple-cio.c @@ -200,6 +200,31 @@ static int t8142_cio_deassert(struct apple_cio_reset *priv, unsigned long id) APPLE_CIO_RESET_TIMEOUT_US); } +static int t8152_cio_deassert(struct apple_cio_reset *priv, unsigned long id) +{ + u32 val, busy = id < 2 ? 3 : 12; + int ret; + + guard(mutex)(&priv->lock); + ret = regmap_read_poll_timeout(priv->regmap, 0x68, val, + !(val & busy), 10, 192000); + if (ret) + return ret; + ret = regmap_write(priv->regmap, 0x68, BIT(id)); + if (ret) + return ret; + ret = regmap_read_poll_timeout(priv->regmap, 0x6c, val, + val & BIT(id), 10, 192000); + if (ret) + return ret; + return regmap_write(priv->regmap, 0x6c, BIT(id)); +} + +static const struct apple_cio_reset_variant apple_t8152_cio_reset = { + .nr_resets = 4, + .deassert = t8152_cio_deassert, +}; + static const struct apple_cio_reset_variant apple_t8142_cio_reset = { .nr_resets = 4, .ctrl = T8142_CIO_CTRL, @@ -330,6 +355,7 @@ static int apple_cio_reset_probe(struct platform_device *pdev) } static const struct of_device_id apple_cio_reset_match[] = { + { .compatible = "apple,t8152-cio-reset", .data = &apple_t8152_cio_reset }, { .compatible = "apple,t6050-cio-reset", .data = &apple_t6050_cio_reset, diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 689d79858ab2b..5b5b69500db34 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -1953,6 +1953,8 @@ static const struct apple_mbox_hw apple_mbox_t8152_smc_hw = { static const struct of_device_id apple_mbox_of_match[] = { { .compatible = "apple,t8152-smc-mailbox", .data = &apple_mbox_t8152_smc_hw }, + /* The AOP's ASC wrapper mailbox has the SMC mailbox's counted FIFOs. */ + { .compatible = "apple,t8152-ascwrap-v8-mailbox", .data = &apple_mbox_t8152_smc_hw }, { .compatible = "apple,t6031-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8122-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8152-gfx-ascwrap-v8", .data = &apple_mbox_t8152_gfx_ascwrap_v8_hw }, diff --git a/drivers/soc/apple/rtkit.c b/drivers/soc/apple/rtkit.c index e529b4d4dd4c6..e516f9d6cb6a9 100644 --- a/drivers/soc/apple/rtkit.c +++ b/drivers/soc/apple/rtkit.c @@ -2125,6 +2125,18 @@ bool apple_rtkit_v27_rx_drained(struct apple_rtkit *rtk) } EXPORT_SYMBOL_GPL(apple_rtkit_v27_rx_drained); +/* + * A co-processor adopted from the bootloader has already sent its endpoint + * map. A client that starts one of its application endpoints by hand + * registers it here, so its messages are not reported as undiscovered. + */ +void apple_rtkit_adopt_ep(struct apple_rtkit *rtk, u8 ep) +{ + if (ep >= APPLE_RTKIT_APP_ENDPOINT_START) + set_bit(ep, rtk->endpoints); +} +EXPORT_SYMBOL_GPL(apple_rtkit_adopt_ep); + int apple_rtkit_start_ep(struct apple_rtkit *rtk, u8 endpoint) { u64 msg; diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index 34ce3ac0e2bb2..c6436bd645eaa 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -575,6 +575,10 @@ static const struct of_device_id apple_sart_of_match[] = { .compatible = "apple,t6050-sart", .data = &sart_ops_v4, }, + { + .compatible = "apple,t8152-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t6000-sart", .data = &sart_ops_v3, diff --git a/drivers/spmi/spmi-apple-controller.c b/drivers/spmi/spmi-apple-controller.c index c5f8829cfeb45..bdabe697859b1 100644 --- a/drivers/spmi/spmi-apple-controller.c +++ b/drivers/spmi/spmi-apple-controller.c @@ -32,14 +32,14 @@ #include #include +#include "spmi-apple-irq.h" + /* SPMI Controller Registers */ #define SPMI_STATUS_REG 0 #define SPMI_CMD_REG 0x4 #define SPMI_RSP_REG 0x8 #define SPMI_ACT_REG 0xa4 -#define SPMI_IRQ_MASK_BASE 0x20 -#define SPMI_IRQ_ACK_BASE 0x60 /* * Peripheral interrupts come first. The RX FIFO notification sits right * after them, followed by the controller's own fault interrupts, so the @@ -61,8 +61,6 @@ * reply FIFO. macOS acks the controller's fault interrupt (source 263, after the 256 * peripheral sources; ack words from 0x600) and empties the queue when the controller starts. */ -#define SPMI_GEN4_IRQ_ACK_BASE 0x600 -#define SPMI_GEN4_FAULT_IRQ (SPMI_MAX_PERIPHERAL_IRQS + 7) #define SPMI_FAULT_QUEUE_MAX 64 /* More than the reply FIFO holds: the bound of a recovery's read-out. */ #define SPMI_GEN4_REPLY_DRAIN_MAX 64 @@ -77,6 +75,8 @@ struct apple_spmi_hw { u32 rx_empty; bool legacy_irqs; u32 num_irqs; + u32 irq_mask; + u32 irq_ack; }; static const struct apple_spmi_hw apple_spmi_gen1 = { @@ -86,6 +86,8 @@ static const struct apple_spmi_hw apple_spmi_gen1 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; /* M1 Pro, Max and Ultra: 192 peripheral interrupts, notification at 192 */ @@ -96,6 +98,8 @@ static const struct apple_spmi_hw apple_spmi_t6000 = { .rx_empty = SPMI_RX_FIFO_EMPTY, .legacy_irqs = true, .num_irqs = 192, + .irq_mask = APPLE_SPMI_GEN1_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN1_IRQ_ACK, }; static const struct apple_spmi_hw apple_spmi_gen4 = { @@ -103,12 +107,16 @@ static const struct apple_spmi_hw apple_spmi_gen4 = { .command = 0x210, .reply = 0x220, .rx_empty = BIT(30), + .num_irqs = 256, + .irq_mask = APPLE_SPMI_GEN4_IRQ_MASK, + .irq_ack = APPLE_SPMI_GEN4_IRQ_ACK, }; struct apple_spmi { void __iomem *regs; void __iomem *faults; unsigned int nfaults; + struct device *dev; const struct apple_spmi_hw *hw; struct mutex fifo_lock; struct completion fifo_rx; @@ -125,21 +133,21 @@ struct apple_spmi { static void apple_spmi_irq_ack_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_ACK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_ack + (irq / 32) * 4; writel(BIT(irq % 32), reg); } static void apple_spmi_irq_mask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; writel(readl(reg) & ~BIT(irq % 32), reg); } static void apple_spmi_irq_unmask_raw(struct apple_spmi *spmi, u32 irq) { - u32 __iomem *reg = spmi->regs + SPMI_IRQ_MASK_BASE + (irq / 32) * 4; + u32 __iomem *reg = spmi->regs + spmi->hw->irq_mask + (irq / 32) * 4; writel(readl(reg) | BIT(irq % 32), reg); } @@ -181,8 +189,8 @@ static inline u32 apple_spmi_pack_cmd(u8 opc, u8 sid, u16 param) /* Ack the fault interrupt, then pop and log every queued fault record */ static void apple_spmi_drain_faults(struct device *dev, struct apple_spmi *spmi) { - void __iomem *ack = spmi->regs + SPMI_GEN4_IRQ_ACK_BASE + (SPMI_GEN4_FAULT_IRQ / 32) * 4; - u32 bit = BIT(SPMI_GEN4_FAULT_IRQ % 32), fault; + void __iomem *ack = spmi->regs + APPLE_SPMI_GEN4_IRQ_ACK + (APPLE_SPMI_GEN4_FAULT_IRQ / 32) * 4; + u32 bit = BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32), fault; int i; if (!spmi->faults) @@ -513,7 +521,18 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) unsigned long val, offset, bit; chained_irq_enter(chip, desc); - val = readl(spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + val = readl(spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); + /* + * On gen4 the controller's own fault source shares this last ack word + * (0x620, bit 7). Its queued records must be read before the source is + * acked, or drain_faults() never sees them. + */ + if (!spmi->hw->legacy_irqs && spmi->faults && + (val & BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32))) { + apple_spmi_drain_faults(spmi->dev, spmi); + val &= ~BIT(APPLE_SPMI_GEN4_FAULT_IRQ % 32); + handled = true; + } raw_pending |= !!val; if (val & BIT(notify % 32)) { apple_spmi_irq_ack_raw(spmi, notify); @@ -522,14 +541,14 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) } /* Other queues' responses, such as the sleep's own commands at the debug link's cut. */ if (val & ~BIT(notify % 32)) { - writel(val & ~BIT(notify % 32), spmi->regs + SPMI_IRQ_ACK_BASE + (notify / 32) * 4); + writel(val & ~BIT(notify % 32), spmi->regs + spmi->hw->irq_ack + (notify / 32) * 4); handled = true; } for (offset = 0; offset < notify / 8; offset += sizeof(val)) { unsigned long stray; - val = readq(spmi->regs + SPMI_IRQ_ACK_BASE + offset); + val = readq(spmi->regs + spmi->hw->irq_ack + offset); raw_pending |= !!val; /* * After a real sleep, sources no driver uses come up pending (on the Neo the @@ -540,8 +559,8 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) */ stray = val & ~spmi->irq_used[offset / sizeof(val)]; if (stray) { - writel(lower_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset); - writel(upper_32_bits(stray), spmi->regs + SPMI_IRQ_ACK_BASE + offset + 4); + writel(lower_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset); + writel(upper_32_bits(stray), spmi->regs + spmi->hw->irq_ack + offset + 4); handled = true; } if (val & spmi->irq_used[offset / sizeof(val)] & @@ -571,7 +590,7 @@ static void apple_spmi_irq_handler(struct irq_desc *desc) * unmasked, or it fires again for what was just cleared. */ if (handled) - readl(spmi->regs + SPMI_IRQ_ACK_BASE); + readl(spmi->regs + spmi->hw->irq_ack); chained_irq_exit(chip, desc); } @@ -579,8 +598,9 @@ static void apple_spmi_teardown_irq(void *data) { struct apple_spmi *spmi = data; - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) + writel(0, spmi->regs + spmi->hw->irq_mask + offset); synchronize_irq(spmi->irq); irq_set_chained_handler_and_data(spmi->irq, NULL, NULL); @@ -599,9 +619,10 @@ static int apple_spmi_init_irq(struct platform_device *pdev, raw_spin_lock_init(&spmi->irq_mask_lock); - for (size_t offset = 0; offset < (spmi->hw->num_irqs + 32) / 8; offset += 4) { - writel(0, spmi->regs + SPMI_IRQ_MASK_BASE + offset); - writel(U32_MAX, spmi->regs + SPMI_IRQ_ACK_BASE + offset); + for (size_t offset = 0; offset < spmi->hw->num_irqs / 8 + (spmi->hw->legacy_irqs ? 4 : 0); + offset += 4) { + writel(0, spmi->regs + spmi->hw->irq_mask + offset); + writel(U32_MAX, spmi->regs + spmi->hw->irq_ack + offset); } spmi->irqd = devm_irq_domain_instantiate(&pdev->dev, &info); @@ -613,8 +634,10 @@ static int apple_spmi_init_irq(struct platform_device *pdev, return ret; irq_set_chained_handler_and_data(spmi->irq, apple_spmi_irq_handler, spmi); - apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); - spmi->notify_irq = true; + if (spmi->hw->legacy_irqs) { + apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); + spmi->notify_irq = true; + } return 0; } @@ -653,8 +676,17 @@ static int apple_spmi_resume_noirq(struct device *dev) unsigned long flags; size_t i; - if (!spmi->notify_parked) + if (!spmi->notify_parked) { + /* Gen 4 never parks the notification, but a firmware sleep entry writes the mask bank itself. */ + if (spmi->hw->legacy_irqs || !spmi->irqd || !pm_resume_via_firmware()) + return 0; + raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); + bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); + for (i = 0; i < spmi->hw->num_irqs / 32; i++) + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); + raw_spin_unlock_irqrestore(&spmi->irq_mask_lock, flags); return 0; + } guard(mutex)(&spmi->fifo_lock); raw_spin_lock_irqsave(&spmi->irq_mask_lock, flags); @@ -662,7 +694,7 @@ static int apple_spmi_resume_noirq(struct device *dev) if (pm_resume_via_firmware()) { bitmap_to_arr32(words, spmi->irq_mask_cache, spmi->hw->num_irqs); for (i = 0; i < spmi->hw->num_irqs / 32; i++) - writel(words[i], spmi->regs + SPMI_IRQ_MASK_BASE + i * 4); + writel(words[i], spmi->regs + spmi->hw->irq_mask + i * 4); } apple_spmi_irq_ack_raw(spmi, spmi->hw->num_irqs); apple_spmi_irq_unmask_raw(spmi, spmi->hw->num_irqs); @@ -687,6 +719,7 @@ static int apple_spmi_probe(struct platform_device *pdev) return -ENOMEM; spmi = spmi_controller_get_drvdata(ctrl); + spmi->dev = &pdev->dev; spmi->hw = device_get_match_data(&pdev->dev); if (!spmi->hw) return -EINVAL; @@ -715,9 +748,6 @@ static int apple_spmi_probe(struct platform_device *pdev) if (spmi->irq < 0 && spmi->irq != -ENXIO) return spmi->irq; if (spmi->irq >= 0) { - if (!spmi->hw->legacy_irqs) - return dev_err_probe(&pdev->dev, -EOPNOTSUPP, - "Generation 4 interrupt layout is not supported\n"); ret = apple_spmi_init_irq(pdev, spmi, spmi->irq); if (ret) return ret; diff --git a/drivers/spmi/spmi-apple-irq.h b/drivers/spmi/spmi-apple-irq.h new file mode 100644 index 0000000000000..4134ef37ff369 --- /dev/null +++ b/drivers/spmi/spmi-apple-irq.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Apple SPMI controller interrupt register layout. + * + * Peripheral sources 0..255 come first, then the RX FIFO notification (256) and + * the controller's own fault sources. Source n sits in bit n % 32 of word n / 32 + * of both the mask bank and the ack/pending bank. + */ +#ifndef _SPMI_APPLE_IRQ_H +#define _SPMI_APPLE_IRQ_H + +/* Generation 1 (T8103, T6000) */ +#define APPLE_SPMI_GEN1_IRQ_MASK 0x20 +#define APPLE_SPMI_GEN1_IRQ_ACK 0x60 + +/* + * Generation 4 (T8142, T6050): ack and pending words from 0x600, the fault source + * 263 acked at 0x620 bit 7 (traced from macOS under the hypervisor). The mask bank + * is at 0x400 (see APPLE_SPMI_GEN4_IRQ_MASK). + */ +#define APPLE_SPMI_GEN4_IRQ_ACK 0x600 +#define APPLE_SPMI_GEN4_FAULT_IRQ (256 + 7) +/* Mask bank mirrors the ack bank 0x200 below; +0x400..0x41c toggle on K114c, +0x420 does not. */ +#define APPLE_SPMI_GEN4_IRQ_MASK 0x400 + +static inline u32 apple_spmi_irq_reg(u32 base, u32 irq) +{ + return base + (irq / 32) * 4; +} + +static inline u32 apple_spmi_irq_bit(u32 irq) +{ + return BIT(irq % 32); +} + +#endif /* _SPMI_APPLE_IRQ_H */ diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index e21cf99212eba..cdce656a28a5c 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -95,6 +95,7 @@ #include #include #include +#include #include #include #include @@ -171,6 +172,10 @@ struct apple_cio_hw { bool gen4_link_recovery; /* Leave the host router's TMU to its firmware; host TMU constants. */ bool host_tmu; + /* Drain PSD runtime power-off before the PHY is reset or reused. */ + bool psd_power_cycle; + /* Stop a started router before a reboot shuts its PCIe and DARTs down. */ + bool stop_at_reboot; const struct apple_dpin_policy *dp; }; @@ -206,6 +211,18 @@ static const struct apple_cio_hw apple_cio_t8132_hw = { .dp = &apple_dpin_m4, }; +/* MXWrap-v2p3 is started by reconfiguration, using its counted mailbox. */ +static const struct apple_cio_hw apple_cio_t8152_hw = { + .psd_power_cycle = true, + .stop_at_reboot = true, + .type7 = true, + .lstx_after_boot = true, + .strict_fw_ready = true, + .no_host_clx = true, + .no_asym = true, + .dp = &apple_dpin_disabled, +}; + /* Type 7 uses its existing ready-state check and has no qualified DP route. */ static const struct apple_cio_hw apple_cio_t8142_hw = { .type7 = true, @@ -500,6 +517,7 @@ struct apple_cio { u64 link_lost_cycle_activity; /* remote activity at the last cycle */ bool link_lost_restart; /* protected by lock: cycle requested */ struct notifier_block pm_notifier; + struct notifier_block reboot_notifier; /* * T6050: the displays behind this port go at the start of the sleep's entry, before any * port's power-off. @sleep_dp_paused: this entry closed the DP IN admission; @@ -1305,7 +1323,8 @@ static void apple_cio_of_node_put(void *data) static bool apple_cio_pciec_eligible(const struct device_node *np) { - return of_device_is_compatible(np, "apple,t6040-pciec") || + return of_device_is_compatible(np, "apple,t8152-pciec") || + of_device_is_compatible(np, "apple,t6040-pciec") || of_device_is_compatible(np, "apple,t8103-pciec") || of_device_is_compatible(np, "apple,t6000-pciec") || of_device_is_compatible(np, "apple,t6050-pciec"); @@ -2591,7 +2610,8 @@ static int apple_nhi_probe(struct platform_device *pdev) /* The T6050 router is the Type 7 one released by a RUN store. */ if (acio->type7 != - (of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || + (of_device_is_compatible(pdev->dev.of_node, "apple,t8152-usb4-nhi") || + of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi") || of_device_is_compatible(pdev->dev.of_node, "apple,t6050-usb4-nhi")) || acio->hw->run_store != @@ -3097,6 +3117,7 @@ static const struct of_device_id apple_nhi_match[] = { { .compatible = "apple,t6050-usb4-nhi", }, + { .compatible = "apple,t8152-usb4-nhi" }, { .compatible = "apple,t8142-usb4-nhi", }, @@ -3307,6 +3328,26 @@ static void apple_cio_test_log_guards(struct apple_cio *acio) dev_info(acio->dev, "TEST sv6t7: ACIO stop, its domain links go next: PS_PROT%s\n", buf); } +static void apple_cio_release_domains(struct apple_cio *acio) +{ + int n, i, ret; + + for (n = 0; n < acio->pd_list->num_pds; n++) { + i = acio->hw->psd_power_cycle ? acio->pd_list->num_pds - 1 - n : n; + dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); + if (!acio->pd_list->pd_links[i]) + continue; + device_link_del(acio->pd_list->pd_links[i]); + acio->pd_list->pd_links[i] = NULL; + if (!acio->hw->psd_power_cycle) + continue; + /* Link removal only queues idle; finish it before returning. */ + ret = pm_runtime_suspend(acio->pd_list->pd_devs[i]); + if (ret < 0) + dev_warn(acio->dev, "PSD domain %d failed to suspend: %d\n", i, ret); + } +} + /** * apple_cio_stop - Stop and power down the ACIO complex * @acio: ACIO complex to stop @@ -3317,7 +3358,7 @@ static void apple_cio_test_log_guards(struct apple_cio *acio) */ static void apple_cio_stop(struct apple_cio *acio) { - int ret, i; + int ret; lockdep_assert_held(&acio->lock); if (!acio->current_cable_info) @@ -3342,12 +3383,7 @@ static void apple_cio_stop(struct apple_cio *acio) apple_cio_test_log_guards(acio); /* Finally, remove the links to the PD domains to power everything off */ - for (i = 0; i < acio->pd_list->num_pds; i++) { - if (acio->pd_list->pd_links[i]) - device_link_del(acio->pd_list->pd_links[i]); - acio->pd_list->pd_links[i] = NULL; - dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); - } + apple_cio_release_domains(acio); acio->current_cable_info = 0; acio->resume_link_failed = false; @@ -3608,12 +3644,7 @@ static int apple_cio_start(struct apple_cio *acio) acio->rtk = NULL; apple_cio_cpu_halt(acio); /* Cut power to reset the entire block */ - for (i = 0; i < acio->pd_list->num_pds; i++) { - if (acio->pd_list->pd_links[i]) - device_link_del(acio->pd_list->pd_links[i]); - acio->pd_list->pd_links[i] = NULL; - dev_pm_syscore_device(acio->pd_list->pd_devs[i], false); - } + apple_cio_release_domains(acio); return ret; } @@ -4472,6 +4503,24 @@ static int apple_cio_pcie_notify(struct notifier_block *nb, return NOTIFY_OK; } +/* + * A reboot or power-off shuts the PCIe-C host and the router's and the + * tunnel's DARTs down before this device, with the router still running + * over them. Stop a started router first, as the port driver does for an + * unplugged cable, and refuse a new start from then on. + */ +static int apple_cio_reboot_notify(struct notifier_block *nb, unsigned long action, + void *data) +{ + struct apple_cio *acio = container_of(nb, struct apple_cio, reboot_notifier); + + guard(mutex)(&acio->lock); + acio->removing = true; + if (acio->current_cable_info) + apple_cio_stop(acio); + return NOTIFY_DONE; +} + static int apple_cio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -4733,6 +4782,10 @@ static int apple_cio_probe(struct platform_device *pdev) acio->pm_notifier_dp.notifier_call = apple_cio_dp_pm_notify; acio->pm_notifier_dp.priority = 20; register_pm_notifier(&acio->pm_notifier_dp); + if (acio->hw->stop_at_reboot) { + acio->reboot_notifier.notifier_call = apple_cio_reboot_notify; + register_reboot_notifier(&acio->reboot_notifier); + } return 0; } @@ -4740,6 +4793,8 @@ static void apple_cio_remove(struct platform_device *pdev) { struct apple_cio *acio = platform_get_drvdata(pdev); + if (acio->hw->stop_at_reboot) + unregister_reboot_notifier(&acio->reboot_notifier); /* Refuse new activation before draining callbacks and workers. */ scoped_guard(mutex, &acio->lock) acio->removing = true; @@ -4773,6 +4828,7 @@ static const struct of_device_id apple_acio_match[] = { .compatible = "apple,t6050-usb4-acio", .data = &apple_cio_t6050_hw, }, + { .compatible = "apple,t8152-usb4-acio", .data = &apple_cio_t8152_hw }, { .compatible = "apple,t8142-usb4-acio", .data = &apple_cio_t8142_hw, diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 7f68eba95e1f1..3566533dda5a2 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -2962,6 +2962,10 @@ static const struct of_device_id of_dwc3_match[] = { { .compatible = "synopsys,dwc3" }, + { + /* Handed over in host mode by the bootloader, see apple,dwc3.yaml */ + .compatible = "apple,t8152-dwc3" + }, { }, }; MODULE_DEVICE_TABLE(of, of_dwc3_match); diff --git a/include/linux/soc/apple/rtkit.h b/include/linux/soc/apple/rtkit.h index 4db916bb89f09..c76e50bd67d59 100644 --- a/include/linux/soc/apple/rtkit.h +++ b/include/linux/soc/apple/rtkit.h @@ -512,4 +512,14 @@ struct apple_rtkit *devm_apple_rtkit_init_m5_saved(struct device *dev, void *coo const char *mbox_name, int mbox_idx, const struct apple_rtkit_ops *ops); +/* + * Registers an application endpoint the client started itself on a + * co-processor whose endpoint map the bootloader consumed, so that its + * messages are not reported as undiscovered + * + * @rtk: RTKit reference + * @ep: endpoint to register + */ +void apple_rtkit_adopt_ep(struct apple_rtkit *rtk, u8 ep); + #endif /* _LINUX_APPLE_RTKIT_H_ */ diff --git a/tools/asahi/apple-dart-range-tests.py b/tools/asahi/apple-dart-range-tests.py index edebda6eb6a9d..8939de0a74e85 100644 --- a/tools/asahi/apple-dart-range-tests.py +++ b/tools/asahi/apple-dart-range-tests.py @@ -44,7 +44,7 @@ def main(): #define io_pgtable_ops_to_pgtable(x) ((struct io_pgtable *)(x)) struct apple_dart; struct apple_dart_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; -struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); }; +struct apple_dart_hw { int (*invalidate_tlb)(struct apple_dart_stream_map *); bool gen3; }; struct apple_dart { int num_streams, locked, version; bool fw_mirror, fw_handoff, managed_sids, display_dark, display_tlb_stale; void *dev; struct apple_dart_hw *hw; }; struct apple_dart_atomic_stream_map { struct apple_dart *dart; unsigned long sidmap[1]; }; struct apple_dart_domain { diff --git a/tools/asahi/atc-usb3-tests.py b/tools/asahi/atc-usb3-tests.py index 3a7955197c9f9..d9f9aacb4d38f 100644 --- a/tools/asahi/atc-usb3-tests.py +++ b/tools/asahi/atc-usb3-tests.py @@ -78,7 +78,7 @@ def block(source, marker): STUBS = r''' struct atcphy_hw { enum atcphy_generation gen; bool has_t8140_dp, dp_t8122, has_usb4, park_pipe_unlocked, park_dummy_phy, usb2_only; - bool clear_boot_hold, dp_banked_tunables; }; + bool clear_boot_hold, dp_banked_tunables, pipe_lock_unacked; }; struct device_node { const char *const *compatible; unsigned int count; }; static bool of_device_is_compatible(const struct device_node *root, const char *compatible) { if (!root) return false; @@ -98,7 +98,7 @@ def block(source, marker): enum atcphy_pipehandler_state pipe_state; enum atcphy_mode typec_mode; bool pipe_pending, t8103_dummy_pending, t8103_usb3_retry, t8103_usb3_workaround, mode_dirty, usb_off_pending; - bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, t8140_dp_tunables, dp_tunables; + bool host_active, usb3_port_off, dp_only, ss_tunables, fixed_usb2, fixed_usb3, t8140_dp_tunables, dp_tunables; /* T8132 ownership is tested without entering its lane-setup backend. */ bool t8132_ss, t8132_common_owned, t8132_failed, cio_tunables, t8132_dp_alt; struct { void *usb3_dp; } tunables; @@ -185,6 +185,9 @@ def block(source, marker): static int atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *a) { (void)a; assert(!"T8132 PIPE setup reached"); return -EINVAL; } +static int atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *a) { + (void)a; assert(!"T8152 PIPE setup reached"); return -EINVAL; +} static void atcphy_usb2_power_on(struct apple_atcphy *a) { (void)a; assert(!"USB2-only power restore reached"); } diff --git a/tools/asahi/dcpext26-parity-tests.py b/tools/asahi/dcpext26-parity-tests.py index 08e8fddb71e0f..bbdff169ae2e9 100644 --- a/tools/asahi/dcpext26-parity-tests.py +++ b/tools/asahi/dcpext26-parity-tests.py @@ -158,7 +158,8 @@ def run(name,code): struct apple_epic_service {bool pending_open,enabled;const struct apple_epic_service_ops *ops;const char *pending_name,*pending_class;int pending_unit;u32 channel;}; struct apple_dcp {bool ext26_services_open;struct apple_dcp_afkep *dptxep;}; static bool dptx_native_controllers_ready(struct apple_dcp *d){return true;} -struct apple_dcp_afkep {struct apple_dcp *dcp;unsigned num_channels;struct apple_epic_service services[2];}; +struct apple_dcp_afkep {struct apple_dcp *dcp;unsigned num_channels;struct apple_epic_service services[2];int service_wq;}; +#define wake_up_all(q) ((void)(q)) static bool dcp_is_ext26(struct apple_dcp *d){return true;} static unsigned sent,published,discarded,initialized;static int fault; static void afk_discard_pending_open(struct apple_epic_service *s){discarded++;s->pending_open=false;} diff --git a/tools/asahi/dcpext26-startup-tests.py b/tools/asahi/dcpext26-startup-tests.py index 0811ada7ce526..98b984e597554 100644 --- a/tools/asahi/dcpext26-startup-tests.py +++ b/tools/asahi/dcpext26-startup-tests.py @@ -59,6 +59,7 @@ def run(name,code,reject=False): #define kmalloc(n,f) malloc(n) #define kzalloc_obj(v) calloc(1,sizeof(v)) #define kfree(p) free((void *)(p)) +#define kstrdup(s,f) strdup(s) #define max(a,b) ((a)>(b)?(a):(b)) #define dev_info(...) ((void)0) #define dev_err(...) ((void)0) @@ -93,8 +94,9 @@ def run(name,code,reject=False): struct apple_epic_service_ops {const char *name;bool reusable,optional,open_later;int (*prepare)(struct apple_epic_service *,const char *,const char *,s64);int (*revalidate)(struct apple_epic_service *,const char *,const char *,s64);void (*init)(struct apple_epic_service *,const char *,const char *,s64);void (*teardown)(struct apple_epic_service *);void (*init_props)(struct apple_epic_service *,s64,const void *,size_t);}; struct apple_epic_service {struct apple_dcp_afkep *ep;const struct apple_epic_service_ops *ops;bool enabled,torndown,pending_open,defer_start;unsigned users;int lock;u32 channel;void *cookie;const char *pending_name,*pending_class;s64 pending_unit;int cmd_map[1];}; struct dptx_port {struct apple_epic_service *service;s64 unit;bool enabled,connected;int enable_completion;}; -struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; -struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops;struct apple_epic_service services[AFK_MAX_CHANNEL];}; +struct apple_dcp {const void *push_out_prefill;bool native,ext26_services_open,v27_j714s,v27_sleep_transport,dcpext;int fw_compat,index,dptx_controller_ready;struct {unsigned num_dptx_ports;int iomfb_method_profile,firmware_compat;bool afk_announced_names;} hw;struct dptx_port dptxport[2];void *dev;struct apple_dcp_afkep *systemep,*ibootep,*dptx_controller_ep,*dcpavservep,*dptxep,*ext26_aux[3];}; +struct apple_dcp_afkep {struct apple_dcp *dcp;u32 endpoint,num_channels;bool wire_v2,stopping,match_epic_name,compact;int lock;void *wq,*service_work;const struct apple_epic_service_ops *ops,*unmatched_ops;struct apple_epic_service services[AFK_MAX_CHANNEL];int service_wq;}; +#define wake_up_all(q) ((void)(q)) static bool dcp_is_ext26(struct apple_dcp *d){return d->native;} static bool dcp_fail_stop(struct apple_dcp *d){return d->native;} static bool dcp_is_v14_7_external(struct apple_dcp *d){return false;} diff --git a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py index 7eeb90baf4385..dfa3d7aad45f5 100755 --- a/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py +++ b/tools/testing/selftests/drivers/apple/atc-t8132-usb3.py @@ -92,7 +92,8 @@ def main(): ''' declarations = r''' struct apple_tunable { unsigned id; }; -struct atcphy_hw { int gen; bool usb2_only, has_usb2phy_reg, park_pipe_unlocked; u32 usb2phy_sig_host; }; +struct atcphy_hw { int gen; bool usb2_only, has_usb2phy_reg, park_pipe_unlocked; u32 usb2phy_sig_host; + u32 cfg_offset, sync_reset; }; enum suspend_state { PM_SUSPEND_TO_IDLE = 1, PM_SUSPEND_MEM = 3 }; static enum suspend_state pm_suspend_target_state; static bool rpm_suspended; @@ -106,7 +107,7 @@ def main(): bool t8132_ss, t8132_common_owned, t8132_suspended, t8132_failed, host_active; bool ss_tunables, mode_dirty, pipe_pending, swap_lanes; bool cio_tunables, t8132_dp_alt, fixed_usb2, hibernated, pd_was_off, idle_rpm; - bool t8103_dummy_pending, t8103_usb3_workaround; + bool t8103_dummy_pending, t8103_usb3_workaround, fixed_usb3, cio_only; unsigned tunnel_users; struct { bool prepared, changed, restored; } cio_sleep; int mode, pipe_state, lock; @@ -122,6 +123,8 @@ def main(): struct device { struct apple_atcphy *atc; }; static struct apple_atcphy *dev_get_drvdata(struct device *d) { return d->atc; } static struct apple_atcphy *phy_get_drvdata(struct phy *p) { return p->atc; } +/* T8152 only: these rows run T8132, which never reaches it. */ +static void atcphy_lanes_down_t8152(struct apple_atcphy *a) { (void)a; assert(0); } static u32 core[0x24000/4], usb2[0x4000/4], pipe_regs[0x4000/4]; static unsigned tunes[16], tune_count, reset_releases, bist_phase, writes, core_reads; static unsigned stall_power, stall_bist, expected_tunes, stall_sleep; @@ -215,7 +218,7 @@ def main(): } ''' names = ["atcphy_mode_is_cio", "atcphy_usb2_sig_host", "atcphy_t8132_dp_on", - "atcphy_usb2_power_off", "atcphy_power_off", "atcphy_usb2_power_on", + "atcphy_cfg", "atcphy_usb2_power_off", "atcphy_power_off", "atcphy_usb2_power_on", "atcphy_t8132_cold", "atcphy_t8132_common_start", "atcphy_t8132_phy_stop", "atcphy_t8132_full_stop", "atcphy_configure_t8132", "atcphy_usb2_set_mode", "atcphy_t8132_bist_pulse", diff --git a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py index 3d1026008cbd9..4fa142bdf5c25 100755 --- a/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py +++ b/tools/testing/selftests/drivers/apple/bcm4377-radio-sids.py @@ -97,6 +97,7 @@ def main(): u32 tcr_enabled, tcr_4level, ttbr_shift, ttbr_addr_field_shift; void (*enable_remap)(struct apple_dart *, int, int); int (*invalidate_tlb)(struct apple_dart_stream_map *); + bool gen3; }; struct apple_dart { const struct apple_dart_hw *hw; @@ -105,6 +106,8 @@ def main(): bool four_level, per_stream, tunneled, fw_mirror, fw_handoff; bool pending, preserve_display; bool isp_host, cold_ane, live_mtp, display_dark, display_tlb_stale; + bool cold_gen3, cold_gen3_pcie; + u32 cold_gen3_sids; void *tunables; unsigned long static_bypass[4]; void *dcp, *frontend[2]; diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py index 980a7a8773b97..aee2f68cc7bed 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/common.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/common.py @@ -194,6 +194,18 @@ def atc_cio_helpers(source): return result +def atc_cfg_helpers(source): + """Where the power and reset block sits and which bit swaps the lanes, both of + which T8152 moves; the power-up, power-down and lane functions call these. + + Marked unused, as a unit may extract only some of their callers. Older + sources have neither: ''. + """ + return ''.join(atc_function(source, name).replace( + 'static inline ', 'static inline __attribute__((unused)) ', 1) + for name in ('atcphy_cfg', 'atcphy_lane_swap')) + + def atc_restore_helpers(source): """What atcphy_restore_after_pd_off() needs beyond the parking helpers. diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index cc3197c1b738a..dd3cb7476f43b 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -25,7 +25,7 @@ struct apple_atcphy { bool aux, pll; unsigned int pairs, rate; } dp_t8122; - bool fixed_usb2, host_active, mode_dirty, ss_tunables, dp_tunables, + bool fixed_usb2, fixed_usb3, cio_only, host_active, mode_dirty, ss_tunables, dp_tunables, aux_power_requested; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; @@ -252,11 +252,15 @@ static void atcphy_restore_after_pd_off(struct apple_atcphy *p); static int atcphy_power_off(struct apple_atcphy *p); static int atcphy_configure(struct apple_atcphy *p, enum atcphy_mode mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } /* Model the USB2 power-on boundary's running state. */ diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py index fe2e56e1f46ea..6898b7b368801 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/edid.py @@ -95,12 +95,13 @@ def function(file,signature): bool pending_open;const char *pending_name,*pending_class;s64 pending_unit; }; /* v27_closed_teardown: set only by a J714s firmware 27 sleep. */ -struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; +struct apple_dcp_afkep { u8 *command_tags;bool lock,stopping;void *wq;struct work_struct service_work;struct apple_dcp *dcp;const struct apple_epic_service_ops *ops,*unmatched_ops;bool wire_v2,inline_v2,match_epic_name,v27_closed_teardown;u32 endpoint;unsigned int num_channels;int service_wq;struct apple_epic_service services[AFK_MAX_CHANNEL]; }; +#define wake_up_all(q) ((void)(q)) struct apple_connector { void *dcp;bool connected,edid_invalidation_pending;struct { int registration_state; } base;unsigned int hotplug_wq; }; struct apple_dcp { void *dev;int fw_compat;struct apple_dcp_afkep *dcpavservep;struct apple_connector *connector; bool external_physically_absent,hpd_mutex,quiescing,typec_cable_connected;u64 typec_generation;unsigned int nr_modes; - struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; + struct { int iomfb_method_profile,firmware_compat; bool fw_14_7_endpoints,afk_announced_names; unsigned int num_dptx_ports; } hw; bool ext_dead,external_native; struct { bool lock,enabled;u64 epoch;int enable_completion;struct apple_epic_service *service,*opened; u64 opened_epoch,close_gen,terminated_epoch,close_epoch;bool opening;struct work_struct close_wq; } dcpavserv; /* A J714s firmware 27 processor's: this one is not. */ @@ -146,6 +147,8 @@ def function(file,signature): struct dcp_parse_ctx { struct item *items;unsigned int count,index;bool key; }; struct iterator { struct dcp_parse_ctx *handle;unsigned int idx,len; }; #define kfree(p) free((void *)(p)) +#define GFP_KERNEL 0 +#define kstrdup(s,f) strdup(s) #define PTR_ERR(p) ((int)(intptr_t)(p)) static struct item announcement_items[3]; static int parse(u8 *p,size_t n,struct dcp_parse_ctx *ctx) @@ -574,7 +577,7 @@ def function(file, signature): av = (base / 'epic/dpavservep.c').read_text() af = (base / 'afk.c').read_text() - announce = af[af.index('static void afk_recv_handle_init('):af.index('static void afk_recv_handle_init(') + 6500] + announce = af[af.index('static void afk_recv_handle_init('):af.index('static void afk_recv_handle_init(') + 7000] assert announce.index('ops->prepare(service,') < announce.index('EPIC_CAT_REPORT, AFKV2_OPEN') assert '.prepare = dcpavserv_prepare,' in av and '.prepare = dcpdpserv_prepare,' in av prefix = r''' diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index e41e10447eb22..2fc3385d1df6e 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -3,7 +3,7 @@ """Actual disconnect authority, DWC3 teardown and firmware resource admission.""" from pathlib import Path import re -from common import block, apple_function, internal_inline, atc_mux_without_pm, source_defines, ATC_POST_TUNABLE, tipd_pm_header, firmware_lineage, atc_restore_helpers, atc_cio_helpers +from common import block, apple_function, internal_inline, atc_mux_without_pm, source_defines, ATC_POST_TUNABLE, tipd_pm_header, firmware_lineage, atc_restore_helpers, atc_cio_helpers, atc_cfg_helpers def disconnect(root): # Copyright 2026 Ryan Murray @@ -1182,7 +1182,7 @@ def fn(n, name): names = {n: tuple(name for name in group if re.search(r'^(?:static [^\n]*\b|(?:int|void) )' + name + r'\(', files[n], re.M)) for n, group in names.items()} context = (fn('atc', 'core_read32') + '\n' + fn('atc', 'atcphy_get_mode_config') + '\n' + fn('atc', 'j700_field_update') + '\n' + files['dp'][files['dp'].index('/* Masks are the union'):files['dp'].index('/* Retry only the idle operations')]) - functions = atc_cio_helpers(files['atc']) + '\n\n'.join(fn(n, name) for n, group in names.items() for name in group) + functions = atc_cio_helpers(files['atc']) + atc_cfg_helpers(files['atc']) + '\n\n'.join(fn(n, name) for n, group in names.items() for name in group) definitions = [] lines = iter(files['atc'].splitlines()) for line in lines: diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py index 26c0f62dabb25..544b698f70e8c 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/phy.py @@ -5,7 +5,7 @@ import re from common import (block, source_defines, atc_mux_without_pm, ATC_POST_TUNABLE, atc_function, ATC_SPLIT, ATC_T8103_LIVE, atc_restore_helpers, atc_common_state_helpers, - atc_cio_helpers) + atc_cio_helpers, atc_cfg_helpers) def parking(root): @@ -46,7 +46,7 @@ def function(source, name): struct reset_controller_dev rcdev; void *dev; int lock, dp_link_rate; - bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, cio_only, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; @@ -67,6 +67,7 @@ def function(source, name): start = atc.index('static const struct {\n\tconst struct atcphy_mode_configuration normal;') parts.append(atc[start:atc.index('\n};', start) + 3]) parts.append(atc_cio_helpers(atc)) + parts.append(atc_cfg_helpers(atc)) parts.append(r''' struct phy_configure_opts_dp { unsigned int link_rate, lanes, voltage[4], pre[4]; @@ -160,11 +161,15 @@ def function(source, name): static int atcphy_power_off(struct apple_atcphy *); static int atcphy_configure(struct apple_atcphy *, enum atcphy_mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } ''') @@ -1948,7 +1953,7 @@ def function(name): struct { unsigned char *core, *pipehandler; } regs; void *dev; int lock; - bool fixed_usb2, host_active, ss_tunables, dp_tunables, mode_dirty; + bool fixed_usb2, fixed_usb3, cio_only, host_active, ss_tunables, dp_tunables, mode_dirty; unsigned int dp_owned_pmas, dp_idle_pmas; unsigned int dp_usb_context_valid, dp_usb_context_dirty; u32 dp_usb_context[2][27]; @@ -1993,11 +1998,13 @@ def function(name): static void __attribute__((unused)) atcphy_restore_after_pd_off(struct apple_atcphy *p) { assert(!p->pd_was_off); } static int atcphy_configure(struct apple_atcphy *p, enum atcphy_mode mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); return -EOPNOTSUPP; } ''') for name in ('core_read32', 'atcphy_get_mode_config'): @@ -2348,7 +2355,7 @@ def function(source, name): struct { unsigned char *core, *lpdptx, *lioa; } regs; void *dev; int lock, dp_link_rate; - bool fixed_usb2, host_active, swap_lanes, ss_tunables, dp_tunables; + bool fixed_usb2, fixed_usb3, cio_only, host_active, swap_lanes, ss_tunables, dp_tunables; bool aux_power_requested, mode_dirty, dp_spread_spectrum, dp_presets_valid[5]; u32 dp_presets[5][16]; unsigned int dp_idle_pmas, dp_owned_pmas; @@ -2364,6 +2371,7 @@ def function(source, name): start = atc.index('static const struct {\n\tconst struct atcphy_mode_configuration normal;') parts.append(atc[start:atc.index('\n};', start) + 3]) parts.append(atc_cio_helpers(atc)) + parts.append(atc_cfg_helpers(atc)) parts.append(r''' struct phy_configure_opts_dp { unsigned int link_rate, lanes, voltage[4], pre[4]; @@ -2424,11 +2432,13 @@ def function(source, name): static int atcphy_power_off(struct apple_atcphy *); static int atcphy_configure(struct apple_atcphy *, enum atcphy_mode); -/* These units exercise older PHY generations. Never accept a T8132 dispatch. */ +/* These units exercise older PHY generations. Never accept a T8132 or T8152 dispatch. */ static int __attribute__((unused)) atcphy_configure_t8132(struct apple_atcphy *p, enum atcphy_mode mode) { (void)p; (void)mode; assert(false); return -EOPNOTSUPP; } static int __attribute__((unused)) atcphy_configure_pipehandler_usb3_host_t8132(struct apple_atcphy *p) { (void)p; assert(false); return -EOPNOTSUPP; } +static void __attribute__((unused)) atcphy_lanes_down_t8152(struct apple_atcphy *p) +{ (void)p; assert(false); } static int atcphy_park_pipehandler(struct apple_atcphy *p, bool keep_dp)