diff --git a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml index c5fce7d78bfc62..253c1b78f235d0 100644 --- a/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml +++ b/Documentation/devicetree/bindings/arm/apple/apple,pmgr.yaml @@ -44,6 +44,7 @@ properties: - apple,t8132-pmgr - apple,t8140-pmgr - apple,t8142-pmgr + - apple,t8152-pmgr - const: apple,t8103-pmgr - const: syscon - const: simple-mfd diff --git a/Documentation/devicetree/bindings/iommu/apple,dart.yaml b/Documentation/devicetree/bindings/iommu/apple,dart.yaml index 44a0499ada2cbc..8996f8aef1e797 100644 --- a/Documentation/devicetree/bindings/iommu/apple,dart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,dart.yaml @@ -28,6 +28,7 @@ properties: - apple,t8103-usb4-dart - apple,t8110-dart - apple,t6000-dart + - apple,t8152-dart - items: - enum: - apple,t6000-dart @@ -42,11 +43,24 @@ properties: - const: apple,t8110-dart reg: - maxItems: 1 + minItems: 1 + maxItems: 2 interrupts: maxItems: 1 + apple,static-topology: + type: boolean + description: | + apple,t8152-dart only. Do not touch the DART registers at probe. Use a + fixed topology and defer the tunables, parameter read, lock check, reset + and fault handling to the first runtime resume (the first consumer). For + DARTs behind a power or availability gate that firmware controls. + + apple,num-streams: + $ref: /schemas/types.yaml#/definitions/uint32 + description: Stream count assumed by apple,static-topology (default 16). + clocks: description: Reference to the gate clock phandle if required for this IOMMU. @@ -115,6 +129,22 @@ properties: and filtering state without a separate page-table root. Source and destination must differ, and both must exist on the controller. +allOf: + # Only apple,t8152-dart has a second register region (the shared TLB invalidate doorbell). + - if: + properties: + compatible: + contains: + const: apple,t8152-dart + then: + properties: + reg: + minItems: 2 + else: + properties: + reg: + maxItems: 1 + required: - compatible - reg diff --git a/Documentation/devicetree/bindings/iommu/apple,sart.yaml b/Documentation/devicetree/bindings/iommu/apple,sart.yaml index 472454c3d24d67..10fd165d1903db 100644 --- a/Documentation/devicetree/bindings/iommu/apple,sart.yaml +++ b/Documentation/devicetree/bindings/iommu/apple,sart.yaml @@ -40,6 +40,7 @@ properties: - apple,t6000-sart - apple,t8015-sart - apple,t8103-sart + - apple,t8152-sart reg: maxItems: 1 diff --git a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml index 8d66dc77c0a54e..c1b17e089fbdd1 100644 --- a/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml +++ b/Documentation/devicetree/bindings/mailbox/apple,mailbox.yaml @@ -54,6 +54,14 @@ properties: - apple,t8112-ane-mailbox - const: apple,asc-mailbox-v4 + - description: + The T8152 ACIO (USB4/Thunderbolt) co-processor mailbox. Its status + word counts the receive occupancy and the free transmit slots, unlike + the full/empty flags of the ASC mailboxes, so it has no ASC + fallback. Only its recv-not-empty and send-empty interrupts are + known. + const: apple,t8152-acio-mailbox + - description: M3 GPU ASC mailboxes with no generic mailbox fallback. This keeps older kernels from binding before the GPU handoff is supported. @@ -145,6 +153,7 @@ allOf: enum: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox + - apple,t8152-acio-mailbox then: properties: interrupt-names: @@ -163,6 +172,7 @@ allOf: enum: - apple,t6021-ane-mailbox - apple,t8112-ane-mailbox + - apple,t8152-acio-mailbox - apple,t8140-aop-setup-mailbox then: properties: diff --git a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml index fc8a4afd5add47..d8a713e6726f60 100644 --- a/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml +++ b/Documentation/devicetree/bindings/nvme/apple,nvme-ans.yaml @@ -29,6 +29,7 @@ properties: - apple,t8112-nvme-ans2 - apple,t6000-nvme-ans2 - const: apple,nvme-ans2 + - const: apple,t8152-nvme-ans2 reg: minItems: 2 @@ -125,13 +126,24 @@ allOf: reg-names: maxItems: 2 + # T8152 has no reset line and no PMGR power domains for the ANS: the ANS is + # a virtual PMGR device there. + - if: + not: + properties: + compatible: + contains: + const: apple,t8152-nvme-ans2 + then: + required: + - resets + - power-domains + - power-domain-names + required: - compatible - reg - reg-names - - resets - - power-domains - - power-domain-names - mboxes - interrupts - apple,sart diff --git a/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml new file mode 100644 index 00000000000000..55c8b3b9a3d64c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/apple,t8152-usb2-phy.yaml @@ -0,0 +1,79 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/apple,t8152-usb2-phy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 USB2 PHY + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +description: | + The USB2 and eUSB2 register banks support a fixed host or fixed peripheral + connection independently of the ATC USB3 and USB4 lanes. Firmware supplies + device-specific calibration. Both independent USB power domains must stay + active while the PHY runs. + +$defs: + tunable: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + description: | + Register offset, clear mask, and set value triples for the usb2 bank. + The bootloader supplies these at boot; they are not part of the board file. + items: + items: + - description: Aligned byte offset within the usb2 register bank + - description: Bits to clear + - description: Bits to set + +properties: + compatible: + const: apple,t8152-usb2-phy + + reg: + items: + - description: USB2 PHY register bank + - description: eUSB2 PHY register bank + + reg-names: + items: + - const: usb2 + - const: eusb2 + + '#phy-cells': + const: 0 + + power-domains: + items: + - description: USB always-on domain + - description: USB controller domain + + power-domain-names: + items: + - const: usb-aon + - const: usb + + apple,tunable-usb2phy-dflt: + $ref: '#/$defs/tunable' + description: Default calibration, applied before the role calibration. + + apple,tunable-usb2phy-host: + $ref: '#/$defs/tunable' + description: Host calibration, applied before the PHY leaves reset. + + apple,tunable-usb2phy-dev: + $ref: '#/$defs/tunable' + description: | + Device-mode calibration, applied before the PHY leaves reset in peripheral + mode. + +required: + - compatible + - reg + - reg-names + - '#phy-cells' + - power-domains + - power-domain-names + +additionalProperties: false diff --git a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml index b8b4a24107cd1b..3a3015ddba3359 100644 --- a/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml +++ b/Documentation/devicetree/bindings/pinctrl/apple,pinctrl.yaml @@ -25,6 +25,7 @@ properties: - apple,t8122-pinctrl - apple,t8132-pinctrl - apple,t8140-pinctrl + - apple,t8152-pinctrl - const: apple,t8103-pinctrl - items: # Do not add additional SoC to this list. @@ -91,6 +92,11 @@ patternProperties: additionalProperties: false + '^.+-hog(-[0-9]+)?$': + type: object + required: + - gpio-hog + allOf: - $ref: pinctrl.yaml# diff --git a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml index 7800f0f106f2cd..1479bfea38c3bb 100644 --- a/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml +++ b/Documentation/devicetree/bindings/power/apple,pmgr-pwrstate.yaml @@ -51,6 +51,7 @@ properties: - apple,t8132-pmgr-pwrstate - apple,t8140-pmgr-pwrstate - apple,t8142-pmgr-pwrstate + - apple,t8152-pmgr-pwrstate - const: apple,t8103-pmgr-pwrstate reg: diff --git a/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml new file mode 100644 index 00000000000000..4cd4c43122c90a --- /dev/null +++ b/Documentation/devicetree/bindings/power/apple,t8152-psd.yaml @@ -0,0 +1,107 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/power/apple,t8152-psd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 PSD service slot power domain + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +allOf: + - $ref: power-domain.yaml# + +description: | + The T8152 (M6) power state director (PSD) gates some blocks, among them the + USB controllers and their DARTs, behind a per-port service slot. Each + slot has a 0x100 byte register window at the PSD base plus (slot << 8) with + the status (0x80), request (0x90), diagnostic (0xa0) and valid (0xbc) + registers. A consumer must power the parent PMGR domains of the block + first, then request state 0 (running) and wait for the acknowledge. This + node models that as a power domain: the PMGR domains are its parents + (power-domains), powering it on writes the request. Power-off requests + state 6 (off). + + A "apple,t8152-psd-group" node covers several slots that are brought up + together: one reg window per slot, requested in reg order with the active + state given by apple,psd-states, and put back to state 6 in reverse order. + +properties: + compatible: + enum: + - apple,t8152-psd + - apple,t8152-psd-group + + reg: + minItems: 1 + maxItems: 3 + + "#power-domain-cells": + const: 0 + + power-domains: + description: + Parent PMGR power domains, powered before the slot request. Absent when + the block has no PMGR power state. + minItems: 1 + maxItems: 4 + + label: + description: Name of the power domain. + + apple,psd-states: + $ref: /schemas/types.yaml#/definitions/uint32-array + minItems: 1 + maxItems: 3 + description: + Active PSD state requested for each reg window, in reg order (default + 0, running). Each value is 0 to 5. + + apple,psd-timeout-ms: + description: Acknowledge timeout in milliseconds (default 1000). + +required: + - compatible + - reg + - "#power-domain-cells" + +unevaluatedProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + ps_usb_aon: power-controller-aon { + #power-domain-cells = <0>; + }; + + ps_usb: power-controller-usb { + #power-domain-cells = <0>; + }; + + power-controller@1000 { + compatible = "apple,t8152-psd"; + reg = <0x0 0x1000 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_usb_aon>, <&ps_usb>; + label = "psd_example"; + }; + }; + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + power-controller@2000 { + compatible = "apple,t8152-psd-group"; + reg = <0x0 0x2000 0x0 0x100>, + <0x0 0x2100 0x0 0x100>, + <0x0 0x2200 0x0 0x100>; + apple,psd-states = <0 2 2>; + #power-domain-cells = <0>; + label = "psd_group_example"; + }; + }; diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index 33960878649c21..599624b02a6cc9 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -38,24 +38,42 @@ properties: - apple,t6031-usb4-acio - apple,t8112-usb4-acio - apple,t8122-usb4-acio + - apple,t8152-usb4-acio - const: apple,t8103-usb4-acio reg: minItems: 2 + maxItems: 4 items: - description: Root complex and co-processor control registers - description: SRAM used for communication with the co-processor - description: | 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. + can be configured before a PCIe-C link is brought up. On T8152, which + has no such range, this entry is the co-processor wrapper. + - description: | + Co-processor wrapper ("cpu"): run control at +0x28 and idle status at + +0x44. It starts the co-processor instead of the rc M3_CTRL start bit + on t6030 and T8152. reg-names: - minItems: 2 - items: - - const: rc - - const: sram - - const: pcie-adapter + oneOf: + - minItems: 2 + maxItems: 3 + items: + - const: rc + - const: sram + - const: pcie-adapter + - items: + - const: rc + - const: sram + - const: pcie-adapter + - const: cpu + - items: + - const: rc + - const: sram + - const: cpu mboxes: maxItems: 1 @@ -117,8 +135,12 @@ properties: const: 1 ranges: - maxItems: 1 - description: Single 16 MiB MMIO window containing all child registers + minItems: 1 + maxItems: 2 + description: | + The 16 MiB MMIO window containing all child registers. apple,t8152-usb4-acio + adds a second window that maps the TLB invalidate doorbell page shared by + the Gen3 DARTs, which the DART child lists as its second register region. nonposted-mmio: true @@ -167,7 +189,6 @@ required: - reg-names - mboxes - power-domains - - resets - thunderbolt-switch - '#address-cells' - '#size-cells' @@ -179,6 +200,35 @@ required: allOf: - $ref: /schemas/usb/usb-switch.yaml# + # The driver does not probe without the "cpu" region on these two, and only these use it. + - if: + properties: + compatible: + contains: + enum: + - apple,t6030-usb4-acio + - apple,t8152-usb4-acio + then: + properties: + reg-names: + contains: + const: cpu + else: + properties: + reg-names: + not: + contains: + const: cpu + # apple,t8152-usb4-acio: the reset is not described yet (its driver is separate work). + - if: + not: + properties: + compatible: + contains: + const: apple,t8152-usb4-acio + then: + required: + - resets 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 49b60aaa8deafb..b4d75f89f2eb06 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-nhi.yaml @@ -30,18 +30,21 @@ properties: - apple,t6031-usb4-nhi - apple,t8112-usb4-nhi - apple,t8122-usb4-nhi + - apple,t8152-usb4-nhi - const: apple,t8103-usb4-nhi reg: minItems: 1 + maxItems: 2 items: - description: NHI registers with the transmit and receive rings - description: Protocol Defined Field (PDF) bitmasks selecting which frames are - accepted by each receive ring + accepted by each receive ring; absent on T8152 reg-names: minItems: 1 + maxItems: 2 items: - const: nhi - const: pdf @@ -123,7 +126,9 @@ allOf: properties: compatible: contains: - const: apple,t8142-usb4-nhi + enum: + - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi then: properties: reg: @@ -145,6 +150,7 @@ allOf: - apple,t6031-usb4-nhi - apple,t8122-usb4-nhi - apple,t8142-usb4-nhi + - apple,t8152-usb4-nhi then: properties: iommus: diff --git a/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml new file mode 100644 index 00000000000000..38c1015446c9cd --- /dev/null +++ b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml @@ -0,0 +1,99 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/usb/apple,t8152-dwc3.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 USB2-only controller + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +description: | + This USB2-only profile starts a fixed role at probe, with or without a + physical hub child node: host mode, or — for a debug-cable port — fixed + peripheral (gadget) mode selected with dr_mode. The controller never + switches roles at runtime. + The dr_mode and maximum-speed properties must select host or peripheral and + high-speed. + Firmware supplies device-specific calibration records as offset, clear-mask, + set-value triples. Offsets are relative to each native register bank, not + the combined Linux window. The core window ends at 0xcd00. The Apple window + starts at 0xcd00 and covers the debug, configuration, and link banks through + 0x11800. These windows must not overlap. + +allOf: + - $ref: snps,dwc3-common.yaml# + +properties: + compatible: + const: apple,t8152-dwc3 + + reg: + items: + - description: DWC3 core, offsets 0 through 0xccff + - description: Apple registers, offsets 0xcd00 through 0x117ff + - description: PIPE handler (native register bank 3) + - description: Power control (native register bank 5) + - description: Bulk fabric (native register bank 6) + - description: AUSBC debug (native register bank 8) + + reg-names: + items: + - const: dwc3-core + - const: dwc3-apple + - const: pipe-handler + - const: pwr-ctrl + - const: bulk-fabric + - const: ausbc-debug + + interrupts: + maxItems: 1 + + iommus: + minItems: 4 + maxItems: 4 + + power-domains: + maxItems: 1 + + phys: + maxItems: 1 + + phy-names: + items: + - const: usb2-phy + + dr_mode: + enum: [ host, peripheral ] + + maximum-speed: + const: high-speed + + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + + +patternProperties: + '^hub@[1-9a-f][0-9a-f]?$': + $ref: /schemas/usb/usb-device.yaml# + '^apple,tunable-(bulk-fabric-default|pipe-handler-default|pipe-handler-host|pwr-ctrl-default|drd-usb31-gbl-default|drd-usb31-gbl-host|drd-cio-regs-default|drd-usb31-dbg-default|drd-usb31-cfg-host|link-regs-default|ausbc-debug-default)$': + $ref: /schemas/types.yaml#/definitions/uint32-array + description: Native bank-relative offset, clear-mask, set-value triples. + +required: + - compatible + - reg + - reg-names + - interrupts + - iommus + - power-domains + - phys + - phy-names + - dr_mode + - maximum-speed + +unevaluatedProperties: false diff --git a/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi new file mode 100644 index 00000000000000..6ba88f24035d4b --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-drd1.dtsi @@ -0,0 +1,87 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * usb-drd1 (ATC1, rear BACK-LEFT port, port-number 2, HPM hpm1 at SPMI 0xa) as a fixed USB2 host. + * Addresses, IRQs and TLBI aperture from the saved M6 ADT: usb-drd1 core 0x40a430000, atc-phy1 0x40a418000 / + * 0x40a448000, dart-usb1 0x40b020000 / 0x40b040000 (sid-count 16, tlbi-aperture-offset 384 = 0x180, irq 1679), + * drd irq 1692. Same node layout as the drd3/drd2 hosts (both DARTs, SIDs 0 and 1). + * + * The m1n1 loader must export the port-1 USB2 PHY and DRD tunables (aliases usb2phy1 / usbdrd1), otherwise the + * PHY fails probe with -ENOENT "Invalid default tunables", exactly as drd2 did before its exporter line. + */ +/ { + aliases { + usb2phy1 = &usb2phy1; + usbdrd1 = &usbdrd1; + }; + + soc { + usb1_dart0: iommu@40b020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x0b020000 0x0 0xc000>, + <0x2 0x00000180 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc1_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb1_dart1: iommu@40b040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x0b040000 0x0 0xc000>, + <0x2 0x00000180 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc1_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2phy1: phy@40a418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <0x4 0x0a418000 0x0 0x4000>, + <0x4 0x0a448000 0x0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc1_usb_aon>, <&psd_atc1_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd1: usb@40a430000 { + compatible = "apple,t8152-dwc3"; + reg = <0x4 0x0a430000 0x0 0xcd00>, + <0x4 0x0a43cd00 0x0 0x4b00>, + <0x4 0x0a414000 0x0 0x4000>, + <0x4 0x0a410000 0x0 0x4000>, + <0x4 0x0a444000 0x0 0x4000>, + <0x4 0x0a450000 0x0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb1_dart0 0>, <&usb1_dart0 1>, <&usb1_dart1 0>, <&usb1_dart1 1>; + power-domains = <&psd_atc1_usb>; + phys = <&usb2phy1>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi new file mode 100644 index 00000000000000..9b107ceea8f1b7 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-drd2.dtsi @@ -0,0 +1,73 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/ { + aliases { + usb2phy2 = &usb2phy2; + usbdrd2 = &usbdrd2; + }; + + soc { + usb2_dart0: iommu@383020000 { + compatible = "apple,t8152-dart"; + reg = <3 0x83020000 0 0xc000>, <2 0x200 0 0x10>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&psd_atc2_usb>; + apple,static-topology; + apple,num-streams = <16>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2_dart1: iommu@383040000 { + compatible = "apple,t8152-dart"; + reg = <3 0x83040000 0 0xc000>, <2 0x200 0 0x10>; + interrupts = ; + #iommu-cells = <1>; + power-domains = <&psd_atc2_usb>; + apple,static-topology; + apple,num-streams = <16>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb2phy2: phy@382418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <3 0x82418000 0 0x4000>, <3 0x82448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc2_usb_aon>, <&psd_atc2_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd2: usb@382430000 { + compatible = "apple,t8152-dwc3"; + reg = <3 0x82430000 0 0xcd00>, + <3 0x8243cd00 0 0x4b00>, + <3 0x82414000 0 0x4000>, + <3 0x82410000 0 0x4000>, + <3 0x82444000 0 0x4000>, + <3 0x82450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb2_dart0 0>, <&usb2_dart0 1>, <&usb2_dart1 0>, <&usb2_dart1 1>; + power-domains = <&psd_atc2_usb>; + phys = <&usb2phy2>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi new file mode 100644 index 00000000000000..95c91876fc25b0 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-pmgr.dtsi @@ -0,0 +1,374 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * PMGR power domains for the Apple T8152 (M6), generated from the device tree of the boot firmware + * (/arm-io/pmgr-child). Real (non-virtual) devices only; + * virtual ADT devices have no PS register of their own (ANS, DPTX_PHY, ATC*_CIO_USB, ...) + * and are managed by firmware. Every domain is apple,always-on: Linux only keeps them ACTIVE. + */ + +/ { + soc { + pmgr0: power-management@300700000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x700000 0 0xd0000>; + }; + pmgr1: power-management@308280000 { + compatible = "apple,t8152-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x3 0x8280000 0 0x80000>; + }; + }; +}; + +&pmgr0 { + ps_apcie_gp: power-controller@8c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x8c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp"; + apple,always-on; + }; + + ps_msg: power-controller@b40 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "msg"; + apple,always-on; + }; + + ps_gpio: power-controller@b60 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xb60 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "gpio"; + apple,always-on; + }; + + ps_postoffice: power-controller@be0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xbe0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "postoffice"; + apple,always-on; + }; + + ps_fpwm0: power-controller@c40 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xc40 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "fpwm0"; + apple,always-on; + }; + + ps_apcie_st0: power-controller@ea0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xea0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0"; + apple,always-on; + }; + + ps_apcie_sys_gp: power-controller@ec0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0xec0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_gp"; + power-domains = <&ps_apcie_gp>; + apple,always-on; + }; + + ps_apcie_sys_st0: power-controller@1280 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1280 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sys_st0"; + power-domains = <&ps_apcie_st0>; + apple,always-on; + }; + + ps_apcie_sysocla: power-controller@12a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x12a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_sysocla"; + power-domains = <&ps_apcie_sys_gp>; + apple,always-on; + }; + + ps_apcie_phy_sw: power-controller@15a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x15a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_phy_sw"; + power-domains = <&ps_apcie_sys_st0>, <&ps_apcie_sys_gp>; + apple,always-on; + }; + + ps_apcie_st0_ocla: power-controller@15c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x15c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0_ocla"; + power-domains = <&ps_apcie_sys_st0>; + apple,always-on; + }; + + ps_apcie_aon_aus5: power-controller@1620 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1620 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_aon_aus5"; + power-domains = <&ps_apcie_phy_sw>; + apple,always-on; + }; + + ps_apcie_aon_gp: power-controller@1640 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1640 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_aon_gp"; + power-domains = <&ps_apcie_phy_sw>; + apple,always-on; + }; + + ps_apcie_st0_aus5: power-controller@1660 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1660 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_st0_aus5"; + power-domains = <&ps_apcie_aon_aus5>; + apple,always-on; + }; + + ps_apcie_gp_aus5: power-controller@1680 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1680 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "apcie_gp_aus5"; + power-domains = <&ps_apcie_aon_gp>; + apple,always-on; + }; + +}; + +&pmgr1 { + ps_nub_spmi0: power-controller@180 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi0"; + apple,always-on; + }; + + ps_nub_spmi1: power-controller@1a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi1"; + apple,always-on; + }; + + ps_nub_spmi_a0: power-controller@1c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_a0"; + apple,always-on; + }; + + ps_nub_spmi_a1: power-controller@1e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x1e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "nub_spmi_a1"; + apple,always-on; + }; + + ps_atc0_common_dp_0: power-controller@10000 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10000 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_0"; + apple,always-on; + }; + + ps_atc0_common_dp_1: power-controller@10020 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10020 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_common_dp_1"; + apple,always-on; + }; + + ps_atc1_common_dp_0: power-controller@10040 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10040 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_0"; + apple,always-on; + }; + + ps_atc1_common_dp_1: power-controller@10060 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10060 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_common_dp_1"; + apple,always-on; + }; + + ps_atc2_common_dp_0: power-controller@10080 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10080 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_0"; + apple,always-on; + }; + + ps_atc2_common_dp_1: power-controller@100a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_common_dp_1"; + apple,always-on; + }; + + ps_atc3_common_dp_0: power-controller@100c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_0"; + apple,always-on; + }; + + ps_atc3_common_dp_1: power-controller@100e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x100e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_common_dp_1"; + apple,always-on; + }; + + ps_atc0_usb_aon: power-controller@10100 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10100 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb_aon"; + apple,always-on; + }; + + ps_atc0_usb: power-controller@10120 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10120 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc0_usb"; + apple,always-on; + }; + + ps_atc1_usb_aon: power-controller@10140 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10140 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb_aon"; + apple,always-on; + }; + + ps_atc1_usb: power-controller@10160 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10160 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc1_usb"; + apple,always-on; + }; + + ps_atc2_usb_aon: power-controller@10180 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x10180 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb_aon"; + apple,always-on; + }; + + ps_atc2_usb: power-controller@101a0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101a0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc2_usb"; + apple,always-on; + }; + + ps_atc3_usb_aon: power-controller@101c0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101c0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb_aon"; + apple,always-on; + }; + + ps_atc3_usb: power-controller@101e0 { + compatible = "apple,t8152-pmgr-pwrstate", "apple,t8103-pmgr-pwrstate"; + reg = <0x101e0 4>; + #power-domain-cells = <0>; + #reset-cells = <0>; + label = "atc3_usb"; + apple,always-on; + }; + +}; + +/* + * The PSD service slots of the four USB ports sit on top of the PMGR domains of + * their port: genpd powers the parents first, then the slot request is made. + */ +&psd_atc0_usb { + power-domains = <&ps_atc0_usb_aon>, <&ps_atc0_usb>; +}; + +&psd_atc1_usb { + power-domains = <&ps_atc1_usb_aon>, <&ps_atc1_usb>; +}; + +&psd_atc2_usb { + power-domains = <&ps_atc2_usb_aon>, <&ps_atc2_usb>; +}; + +&psd_atc3_usb { + power-domains = <&ps_atc3_usb_aon>, <&ps_atc3_usb>; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi new file mode 100644 index 00000000000000..afd610963b005f --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb0-dart.dtsi @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd0: two DARTBLK instances, SID 1, shared TLBI aperture offset 0x100. + * Windows, IRQ, tunables and dma-range are from the M6 ADT; + * port 3 is the fixed-host reference. */ + +/ { + soc { + usb0_dart0: iommu@403020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x03020000 0x0 0xc000>, + <0x2 0x00000100 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc0_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value) */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb0_dart1: iommu@403040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x03040000 0x0 0xc000>, + <0x2 0x00000100 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc0_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-1: byte-identical to instance 0 */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi new file mode 100644 index 00000000000000..bebc9ce1c948d8 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb0.dtsi @@ -0,0 +1,42 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd0 as a fixed high-speed peripheral: the debug cable port + * (receptacle 1, ATC0). Windows, IRQ and phy banks are from the M6 ADT; + * the layout mirrors the drd3 host node. */ + +/ { + aliases { + usb2phy0 = &usb2phy0; + usbdrd0 = &usbdrd0; + }; + + soc { + usb2phy0: phy@402418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <4 0x02418000 0 0x4000>, + <4 0x02448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc0_usb_aon>, <&psd_atc0_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd0: usb@402430000 { + compatible = "apple,t8152-dwc3"; + reg = <4 0x02430000 0 0xcd00>, + <4 0x0243cd00 0 0x4b00>, + <4 0x02414000 0 0x4000>, + <4 0x02410000 0 0x4000>, + <4 0x02444000 0 0x4000>, + <4 0x02450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb0_dart0 0>, <&usb0_dart0 1>, <&usb0_dart1 0>, <&usb0_dart1 1>; + power-domains = <&psd_atc0_usb>; + phys = <&usb2phy0>; + phy-names = "usb2-phy"; + dr_mode = "peripheral"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi new file mode 100644 index 00000000000000..46fa177b0acdab --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb2-dart.dtsi @@ -0,0 +1,50 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* usb-drd3: two DARTBLK instances, SID 1, shared TLBI aperture offset 0x280. */ + +/ { + soc { + usb3_dart0: iommu@413020000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x13020000 0x0 0xc000>, + <0x2 0x00000280 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc3_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value) */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + + usb3_dart1: iommu@413040000 { + compatible = "apple,t8152-dart"; + reg = <0x4 0x13040000 0x0 0xc000>, + <0x2 0x00000280 0x0 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + /* no DART MMIO at probe: ADT dart,gen3 manual-availability, see apple-dart.c */ + apple,static-topology; + apple,num-streams = <16>; + power-domains = <&psd_atc3_usb>; + apple,dma-range = /bits/ 64 <0x10000004000 0xffff0000>; + /* ADT dart-tunables-instance-1: byte-identical to instance 0 */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x4600 0x00000002 0x00000002>; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi new file mode 100644 index 00000000000000..8241b19d03adf3 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-usb2.dtsi @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/ { + aliases { + usb2phy3 = &usb2phy3; + usbdrd3 = &usbdrd3; + }; + + soc { + usb2phy3: phy@412418000 { + compatible = "apple,t8152-usb2-phy"; + reg = <4 0x12418000 0 0x4000>, + <4 0x12448000 0 0x4000>; + reg-names = "usb2", "eusb2"; + #phy-cells = <0>; + power-domains = <&ps_atc3_usb_aon>, <&psd_atc3_usb>; + power-domain-names = "usb-aon", "usb"; + }; + + usbdrd3: usb@412430000 { + compatible = "apple,t8152-dwc3"; + reg = <4 0x12430000 0 0xcd00>, + <4 0x1243cd00 0 0x4b00>, + <4 0x12414000 0 0x4000>, + <4 0x12410000 0 0x4000>, + <4 0x12444000 0 0x4000>, + <4 0x12450000 0 0x4000>; + reg-names = "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug"; + interrupts = ; + iommus = <&usb3_dart0 0>, <&usb3_dart0 1>, <&usb3_dart1 0>, <&usb3_dart1 1>; + power-domains = <&psd_atc3_usb>; + phys = <&usb2phy3>; + phy-names = "usb2-phy"; + dr_mode = "host"; + maximum-speed = "high-speed"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi new file mode 100644 index 00000000000000..1099f76d189cf2 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873g-peripherals.dtsi @@ -0,0 +1,71 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple Mac mini (M6), J873g: peripherals that have a driver in this tree. + * + * Only addresses, interrupt numbers and wiring are described here. The boot + * loader adds the register tunables that some of these blocks need. The + * power-management (PMGR) domains are not described yet, so nodes that need + * them are left out. + */ + +#include + +/ { + soc { + /* GPIO controller of the always-on block. Pin 39 releases the reset of the front-port USB hub. */ + nub_pinctrl: pinctrl@3081f0000 { + compatible = "apple,t8152-pinctrl", "apple,t8103-pinctrl"; + reg = <3 0x081f0000 0 0x4000>; + gpio-controller; + #gpio-cells = <2>; + gpio-ranges = <&nub_pinctrl 0 0 40>; + apple,npins = <40>; + interrupt-controller; + #interrupt-cells = <2>; + interrupt-parent = <&aic>; + interrupts = , + , + , + , + , + , + ; + + vl822-reset-n-hog { + gpio-hog; + gpios = <39 GPIO_ACTIVE_HIGH>; + output-high; + line-name = "vl822-reset-n"; + }; + }; + + /* Power state director: one service slot per USB port, 0x100 bytes each. */ + psd_atc0_usb: power-controller@303a14700 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14700 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc0_usb"; + }; + + psd_atc1_usb: power-controller@303a14800 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14800 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc1_usb"; + }; + + psd_atc2_usb: power-controller@303a14900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14900 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc2_usb"; + }; + + psd_atc3_usb: power-controller@303a14a00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14a00 0x0 0x100>; + #power-domain-cells = <0>; + label = "psd_atc3_usb"; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g-usb4.dtsi b/arch/arm64/boot/dts/apple/t8152-j873g-usb4.dtsi new file mode 100644 index 00000000000000..e5c4502746dadc --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873g-usb4.dtsi @@ -0,0 +1,232 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple T8152 (M6) J873: USB4/Thunderbolt host router, ACIO port 3 (ATC3, the free rear port). + * ACIO0 (the NCM tether) and ACIO1 (Studio Display cable) are not described; there is no ACIO2. + * + * Addresses are physical: ADT bus address + 0x200000000 for every ADT address below + * 0x400000000 (arm-io ranges[0]); config space 0x1c80000000 is above that and unchanged. + * The register ranges, interrupts and DART data come from the ADT nodes acio3, acio-cpu3, + * dart-acio3, apciec3 and dart-apciec3; the power-domain slots and the mailbox layout come + * from the macOS driver and its power-manager tables. + * + * The probe of the acio node maps registers and registers the Type-C switch; nothing powers + * ACIO until a cable event. The boot loader fills apple,tunable-rc, -pcie-adapter, -nhi, + * -debug and -fabric, the port tunable and apple,thunderbolt-drom through the aliases below + * (it accepts both spellings). Not described here: pinctrl (the ADT LSTX pin is an AOP + * GPIO), the Type-C graph link to the port controller, and the ATC3 PHY CIO mode. + */ + +/ { + aliases { + usb4-3-acio = &usb4_3_acio; + usb4-3-nhi = &usb4_3_nhi; + usb4-3-pcie-adapter = &usb4_3_acio; + }; + + soc { + /* + * PSD slots of ATC3 (macOS slot-name table): ATC3_CIO 70, ATC3_CIOPCIE 66, + * ATC3_CIOUSB 62, ATC3_PCIE 89. The parent power state of the three CIO slots is + * not known; ps_atc3_usb_aon is a guess. The slot active state is not decoded. + */ + psd_atc3_cio: power-controller@303a14600 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14600 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_usb_aon>; + label = "psd_atc3_cio"; + }; + + psd_atc3_cio_pcie: power-controller@303a14200 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a14200 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_usb_aon>; + label = "psd_atc3_cio_pcie"; + }; + + psd_atc3_cio_usb: power-controller@303a13e00 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a13e00 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_usb_aon>; + label = "psd_atc3_cio_usb"; + }; + + psd_atc3_pcie: power-controller@303a15900 { + compatible = "apple,t8152-psd"; + reg = <0x3 0x03a15900 0x0 0x100>; + #power-domain-cells = <0>; + power-domains = <&ps_atc3_usb_aon>; + label = "psd_atc3_pcie"; + }; + + /* + * ACIO coprocessor mailbox (IOP wrapper v2 layout): acio-cpu3 reg[0] 0x411178000 + + * 0x80, counted FIFO, RX +0, TX +0x10, STATUS +0x20, same layout as the SMC and ANS + * mailboxes. The ADT lists the interrupts as [1873, 1872]: 1873 is inbox empty and + * 1872 is outbox not empty. + */ + usb4_3_mbox: mailbox@411178080 { + compatible = "apple,t8152-acio-mailbox"; + reg = <0x4 0x11178080 0x0 0x80>; + interrupt-parent = <&aic>; + interrupts = , + ; + interrupt-names = "recv-not-empty", "send-empty"; + #mbox-cells = <0>; + }; + + usb4_3_acio: cio@411ac0000 { + compatible = "apple,t8152-usb4-acio", "apple,t8103-usb4-acio"; + /* + * rc = ADT acio3 reg[1..3] (three adjacent 0x4000 blocks). sram is at the + * same offset from the ACIO base as on t8112 (+0x80000) and lies inside + * acio-cpu3 reg[2]; the ADT does not name it. cpu = acio-cpu3 reg[1], the + * coprocessor wrapper: CPU run control +0x28, idle +0x44 bit 1. + */ + reg = <0x4 0x11ac0000 0x0 0xc000>, + <0x4 0x11080000 0x0 0x20000>, + <0x4 0x11100000 0x0 0x4000>; + reg-names = "rc", "sram", "cpu"; + + mboxes = <&usb4_3_mbox>; + power-domains = <&psd_atc3_cio>, + <&psd_atc3_cio_pcie>, + <&psd_atc3_cio_usb>, + <&psd_atc3_pcie>; + + thunderbolt-switch; + + #address-cells = <1>; + #size-cells = <1>; + /* + * child 0 = ACIO block; child 0x2000000 = the shared gen3 DART TLBI + * doorbell page (physical 0x200000000, ADT tlbi-aperture-offset 0x280) + */ + ranges = <0x0 0x4 0x11000000 0x1000000>, + <0x2000000 0x2 0x00000000 0x1000>; + nonposted-mmio; + + /* The Type-C graph link to the port controller is not wired yet. */ + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@1 { + reg = <1>; + usb4_3_acio_tbt: endpoint { + }; + }; + }; + + usb4_3_dart: iommu@a80000 { + compatible = "apple,t8152-dart"; + /* + * ADT dart-acio3 (dart,gen3, manual-availability): reg 0x411a80000, + * 28 SIDs, vm-base 0x10000000000 vm-size 0x30000000000 + */ + reg = <0xa80000 0xc000>, <0x2000280 0x10>; + interrupt-parent = <&aic>; + interrupts = ; + #iommu-cells = <1>; + apple,static-topology; + apple,num-streams = <28>; + apple,dma-range = /bits/ 64 <0x10000000000 0x30000000000>; + /* ADT dart-tunables-instance-0 as (offset, mask, value) */ + apple,tunable = <0x20c 0x80000121 0x80000121>, + <0x220 0x00000f0f 0x00000f0f>, + <0x224 0x0000ffff 0x00000909>, + <0x300 0x00001f31 0x00000001>, + <0x308 0x3ffffffc 0x10000000>, + <0x310 0x3ffffffc 0x3ffffffc>, + <0x800 0x000f003f 0x00010000>, + <0x804 0x000f003f 0x00010002>, + <0x808 0x000f003f 0x00010004>, + <0x80c 0x000f003f 0x00020006>, + <0x810 0x000f003f 0x0002000a>, + <0x814 0x000f003f 0x0002000e>, + <0x818 0x000f003f 0x00020012>, + <0x81c 0x000f003f 0x00020016>, + <0x820 0x000f003f 0x0002001a>, + <0x824 0x000f003f 0x0002001e>, + <0x828 0x000f003f 0x00020022>, + <0x82c 0x000f003f 0x00020026>, + <0x830 0x000f003f 0x0002002a>, + <0x834 0x000f003f 0x0002002e>, + <0x838 0x000f003f 0x00020032>, + <0x83c 0x000f003f 0x00010036>, + <0x4600 0x00000002 0x00000002>; + }; + + usb4_3_nhi: nhi@f00000 { + compatible = "apple,t8152-usb4-nhi", "apple,t8103-usb4-nhi"; + /* + * nhi = ADT acio3 reg[0]. There is no "pdf" range: the ACIO + + * 0xdb0000 block that M1/M2 device trees map for it takes a + * synchronous external abort on a read on T8152. + */ + reg = <0xf00000 0x100000>; + reg-names = "nhi"; + interrupt-parent = <&aic>; + /* + * tx = 1842..1853, rx = 1854..1865 (the ADT lists 1854.. first). + * The TX ring 0 completion raised 1842 and the RX ring 0 interrupt + * raised 1854; the other rings were not seen to fire. + */ + 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"; + /* + * ADT dart-acio3 mappers: mapper-acio3-tx-N reg N (SIDs 0-11), + * mapper-acio3-rx-N reg 16+N (SIDs 16-27). With only SID 1 bound + * the first ring read came from SID 16 and the DART rejected it, + * which ended in a system error; every ring SID is bound. + */ + 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>; + /* + * filled by the loader (alias usb4-3-nhi / usb4_3_nhi): + * apple,thunderbolt-drom, apple,tunable-nhi + */ + apple,thunderbolt-drom = [00]; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t8152-j873g.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 6b5e14036c98af..a2c3f9dd224107 100644 --- a/arch/arm64/boot/dts/apple/t8152-j873g.dts +++ b/arch/arm64/boot/dts/apple/t8152-j873g.dts @@ -247,3 +247,13 @@ }; }; }; + +#include "t8152-j873g-peripherals.dtsi" +#include "t8152-j873-pmgr.dtsi" +#include "t8152-j873-usb2-dart.dtsi" +#include "t8152-j873-usb2.dtsi" +#include "t8152-j873-usb0-dart.dtsi" +#include "t8152-j873-usb0.dtsi" +#include "t8152-j873-drd2.dtsi" +#include "t8152-j873-drd1.dtsi" +#include "t8152-j873g-usb4.dtsi" diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index 73af536772fc20..75682a5266a4fc 100644 --- a/drivers/iommu/apple-dart.c +++ b/drivers/iommu/apple-dart.c @@ -179,6 +179,11 @@ #define DART_T8110_DIAG_LOCK 0x210 #define DART_T8110_DIAG_LOCK_ON_ERR BIT(1) +/* T8152 Gen3: low nibble selects the TLBI route for this DART instance */ +#define DART_GEN3_ROUTE 0x4604 +/* AppleGen3DART _DART_ERR_SID_AXI_ID/_AXI_USER: 2 and 8 words per SID record */ +#define DART_GEN3_ERR_SID_AXI_ID(sid) (DART_T8110_ERR_SID(sid) + 0x18) +#define DART_GEN3_ERR_SID_AXI_USER(sid) (DART_T8110_ERR_SID(sid) + 0x20) #define DART_T8110_ENABLE_STREAMS 0xc00 #define DART_T8110_DISABLE_STREAMS 0xc20 @@ -216,6 +221,7 @@ struct apple_dart_hw { irqreturn_t (*irq_handler)(int irq, void *dev); int (*invalidate_tlb)(struct apple_dart_stream_map *stream_map); void (*enable_remap)(struct apple_dart *dart, int sid, int remap_to); + bool gen3; u32 oas; enum io_pgtable_fmt fmt; @@ -288,6 +294,7 @@ struct apple_dart { u32 supports_bypass : 1; u32 four_level : 1; u32 locked : 1; + u32 force_available : 1; u32 tunneled : 1; u32 per_stream : 1; u32 power_retained : 1; @@ -300,6 +307,18 @@ struct apple_dart { /* Resume restored the translations, but the last steps of its reset failed. */ bool reset_incomplete; struct apple_tunable *tunables; + /* + * Gen3 static topology: no DART MMIO at probe. Topology comes from fixed + * values; tunables, parameter read, lock check, reset and the fault IRQ + * wait for the first runtime resume (first consumer). + */ + u32 static_topo : 1; + u32 hw_ready : 1; + u32 irq_requested : 1; + /* Serialises the first-use init: resume, attach and the fault IRQ can all reach it. */ + spinlock_t late_lock; + /* Gen3 (T8152): shared TLBI doorbell and per-instance route register */ + void __iomem *tlbi; u16 version; DECLARE_BITMAP(remapped, DART_MAX_STREAMS); @@ -468,6 +487,8 @@ struct apple_dart_master_cfg { stream_map = &(base)->stream_maps[++i]) static struct platform_driver apple_dart_driver; +static int apple_dart_cfg_ensure_ready(struct apple_dart_master_cfg *cfg); +static int apple_dart_gen3_ensure_ready(struct apple_dart *dart); static const struct iommu_ops apple_dart_iommu_ops; static struct apple_dart_domain *to_dart_domain(struct iommu_domain *dom) @@ -1246,6 +1267,44 @@ apple_dart_t8110_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) stream_map, DART_T8110_TLB_CMD_OP_FLUSH_SID, false, 0, 0); } +/* + * Gen3 (T8152) DARTs do not take TLB invalidates through TLB_CMD. Apple's SPTM + * (gen3dart_write_tlbi_cmd_payload) stores a 128-bit payload to a TLBI + * aperture, then issues TLBI VALE1OS. Layout as used by m1n1 (accepted on + * DCP SID 23 without an exception): lo = BIT(60) | route << 56 | sid << 48. + * Writes one flush-SID doorbell per stream; no range invalidate. + */ +#ifdef CONFIG_ARM64 +static int apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + struct apple_dart *dart = stream_map->dart; + u64 route = readl(dart->regs + DART_GEN3_ROUTE) & 0xf; + unsigned long flags; + int sid; + + spin_lock_irqsave(&dart->lock, flags); + for_each_set_bit(sid, stream_map->sidmap, dart->num_streams) { + u64 lo = BIT_ULL(60) | route << 56 | (u64)sid << 48; + u64 hi = 0; + + dma_wmb(); + asm volatile("stp %0, %1, [%2]\n" + "dsb ish\n" + ".inst 0xd50881bf\n" /* tlbi vale1os, xzr */ + "dsb osh\n" + :: "r"(lo), "r"(hi), "r"(dart->tlbi) : "memory"); + } + spin_unlock_irqrestore(&dart->lock, flags); + return 0; +} +#else +/* The doorbell store and TLBI are arm64 instructions; other architectures build only for COMPILE_TEST. */ +static int apple_dart_gen3_hw_invalidate_tlb(struct apple_dart_stream_map *stream_map) +{ + return -EOPNOTSUPP; +} +#endif + static const char *apple_dart_t8110_v2_fault_name(u32 exception); static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) @@ -1295,7 +1354,8 @@ static void apple_dart_drain_stale_exceptions(struct apple_dart *dart) readl(dart->regs + DART_T8110_EXCEPTION(0)); } - if (dart->version >= 0x0203) + /* Gen3: 0x704 is not in AppleGen3DART's register capture list; do not touch it. */ + if (dart->version >= 0x0203 && !dart->hw->gen3) readl(dart->regs + DART_T8110_BLOCK_ERROR); if (drained) @@ -1313,6 +1373,13 @@ static int apple_dart_t8110_v2_unlock(struct apple_dart *dart) if (!(readl(dart->regs + DART_T8110_DIAG_LOCK) & DART_T8110_DIAG_LOCK_ON_ERR)) return 0; + /* Gen3 does not take commands through TLB_CMD, so the unlock command cannot be sent there. */ + if (dart->hw->gen3) { + dev_warn_once(dart->dev, + "Gen3 DART: unlock after a lock-on-error exception is not supported\n"); + return 0; + } + /* Unlock after acknowledging a lock-on-error exception. */ __set_bit(0, stream_map.sidmap); return apple_dart_t8110_hw_tlb_command_range(&stream_map, @@ -1407,7 +1474,8 @@ static int apple_dart_hw_finish_reset(struct apple_dart *dart) dart->hw->error); } - if (dart->hw->type == DART_T8110) + /* Gen3: 0x104 is not in AppleGen3DART's register capture list; leave it alone. */ + if (dart->hw->type == DART_T8110 && !dart->hw->gen3) apple_dart_writel(dart, 0, DART_T8110_ERROR_MASK); bitmap_set(stream_map.sidmap, 0, dart->num_streams); @@ -1480,7 +1548,8 @@ static int apple_dart_domain_flush_tlb_range(struct apple_dart_domain *domain, if (range && (stream.dart->fw_mirror || stream.dart->fw_handoff) && stream.dart->version >= 0x0202) ret = apple_dart_fw_invalidate(&stream, start, end); - else if (range && stream.dart->locked && stream.dart->version >= 0x0202) + else if (range && stream.dart->locked && !stream.dart->hw->gen3 && + stream.dart->version >= 0x0202) ret = apple_dart_t8110_hw_tlb_command_range(&stream, op, true, start, end); else @@ -1959,6 +2028,9 @@ static int apple_dart_attach_dev_paging(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + ret = apple_dart_cfg_ensure_ready(cfg); + if (ret) + goto err; ret = apple_dart_finalize_domain(dart_domain, cfg); if (ret) goto err; @@ -2000,6 +2072,12 @@ static int apple_dart_attach_dev_identity(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + if (apple_dart_cfg_ensure_ready(cfg)) { + for_each_stream_map(i, cfg, stream_map) + pm_runtime_put(stream_map->dart->dev); + return -ENODEV; + } + for_each_stream_map(i, cfg, stream_map) apple_dart_hw_enable_bypass(stream_map); @@ -2031,6 +2109,12 @@ static int apple_dart_attach_dev_blocked(struct iommu_domain *domain, for_each_stream_map(i, cfg, stream_map) WARN_ON(pm_runtime_get_sync(stream_map->dart->dev) < 0); + if (apple_dart_cfg_ensure_ready(cfg)) { + for_each_stream_map(i, cfg, stream_map) + pm_runtime_put(stream_map->dart->dev); + return -ENODEV; + } + for_each_stream_map(i, cfg, stream_map) apple_dart_hw_disable_dma(stream_map); @@ -2057,10 +2141,16 @@ static struct iommu_device *apple_dart_probe_device(struct device *dev) if (!dev_iommu_fwspec_get(dev) || !cfg) return ERR_PTR(-ENODEV); - for_each_stream_map(i, cfg, stream_map) + for_each_stream_map(i, cfg, stream_map) { device_link_add(dev, stream_map->dart->dev, DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_SUPPLIER | DL_FLAG_RPM_ACTIVE); + if (stream_map->dart->static_topo) + dev_dbg(dev, "uses static-topology DART %s, sids %*pbl, hw_ready %d, rpm status %d\n", + dev_name(stream_map->dart->dev), stream_map->dart->num_streams, + stream_map->sidmap, stream_map->dart->hw_ready, + stream_map->dart->dev->power.runtime_status); + } return &cfg->stream_maps[0].dart->iommu; } @@ -2707,7 +2797,7 @@ static bool apple_dart_t8110_v2_block_pending(u16 version, u32 block_error) (block_error & DART_T8110_BLOCK_ERROR_MASK); } -static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) +static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev, bool gen3) { struct apple_dart *dart = dev; irqreturn_t ret = IRQ_NONE; @@ -2751,6 +2841,16 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) "write" : "read", apple_dart_t8110_v2_fault_name(status), addr, status); + if (gen3) + dev_err_ratelimited(dart->dev, + " SID:%u AXI_ID %#x/%#x AXI_USER %#x/%#x raw+4 %#x raw+10 %#x\n", + sid, + readl(dart->regs + DART_GEN3_ERR_SID_AXI_ID(sid)), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_ID(sid) + 4), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_USER(sid)), + readl(dart->regs + DART_GEN3_ERR_SID_AXI_USER(sid) + 4), + readl(dart->regs + DART_T8110_ERR_SID(sid) + 0x4), + readl(dart->regs + DART_T8110_ERR_SID(sid) + 0x10)); } /* @@ -2767,7 +2867,8 @@ static irqreturn_t apple_dart_t8110_v2_irq(int irq, void *dev) readl(dart->regs + DART_T8110_EXCEPTION(0)); } - if (dart->version >= 0x0203) { + /* Gen3: 0x704 is not in AppleGen3DART's register capture list; do not touch it. */ + if (!gen3 && dart->version >= 0x0203) { block_error = readl(dart->regs + DART_T8110_BLOCK_ERROR); if (apple_dart_t8110_v2_block_pending(dart->version, block_error)) { dev_err_ratelimited(dart->dev, @@ -2789,11 +2890,16 @@ static irqreturn_t apple_dart_t8110_irq(int irq, void *dev) struct apple_dart *dart = dev; if (dart->version >= 0x0202) - return apple_dart_t8110_v2_irq(irq, dev); + return apple_dart_t8110_v2_irq(irq, dev, false); return apple_dart_t8110_legacy_irq(irq, dev); } +static irqreturn_t apple_dart_gen3_irq(int irq, void *dev) +{ + return apple_dart_t8110_v2_irq(irq, dev, true); +} + static irqreturn_t apple_dart_irq(int irq, void *dev) { irqreturn_t ret = IRQ_NONE; @@ -2801,6 +2907,17 @@ static irqreturn_t apple_dart_irq(int irq, void *dev) if (READ_ONCE(dart->commands_gated)) return IRQ_NONE; + /* + * Static topology: no MMIO before the first consumer. A powered (runtime-active) DART that + * still raises a fault was never initialised: do the first-use init here, which also + * clears the pending error, rather than leave a level IRQ nobody claims. + */ + if (dart->static_topo && !dart->hw_ready) { + if (!pm_runtime_active(dart->dev) || apple_dart_gen3_ensure_ready(dart)) + return IRQ_NONE; + dev_warn_ratelimited(dart->dev, "fault before first-use init; initialised from the IRQ path\n"); + return IRQ_HANDLED; + } if (pm_runtime_resume_and_get(dart->dev) < 0) return IRQ_NONE; if (!READ_ONCE(dart->commands_gated)) @@ -2850,10 +2967,141 @@ apple_dart_platform_ioremap_np_resource(struct platform_device *pdev, return regs; } -static int apple_dart_probe(struct platform_device *pdev) +static const struct apple_dart_hw apple_dart_hw_t8152; + +static void apple_dart_read_params(struct apple_dart *dart) { - int ret, sid; u32 dart_params[4]; + + dart_params[0] = apple_dart_readl(dart, DART_PARAMS1); + dart_params[1] = apple_dart_readl(dart, DART_PARAMS2); + dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]); + dart->supports_bypass = dart_params[1] & DART_PARAMS2_BYPASS_SUPPORT; + + switch (dart->hw->type) { + case DART_T8020: + case DART_T6000: + dart->ias = 32; + dart->oas = dart->hw->oas; + dart->num_streams = dart->hw->max_sid_count; + break; + + case DART_T8110: + dart_params[2] = apple_dart_readl(dart, DART_T8110_PARAMS3); + dart->ias = FIELD_GET(DART_T8110_PARAMS3_VA_WIDTH, dart_params[2]); + dart->oas = FIELD_GET(DART_T8110_PARAMS3_PA_WIDTH, dart_params[2]); + dart_params[3] = apple_dart_readl(dart, DART_T8110_PARAMS4); + dart->num_streams = FIELD_GET(DART_T8110_PARAMS4_NUM_SIDS, + dart_params[3]); + dart->four_level = dart->ias > 36; + dart->version = dart_params[2] & GENMASK(15, 0); + break; + } +} + +/* + * Gen3 static topology, no MMIO. ADT: page-size 16384 (m1n1 also expects page shift 14 + * and version 0x300), sid-count 16 for the USB DARTs (optional apple,num-streams). The + * address widths are placeholders wide enough for probe-time window checks; the + * first resume re-reads the real PARAMS and re-validates. + */ +static void apple_dart_set_static_params(struct apple_dart *dart) +{ + u32 n = 16; + + of_property_read_u32(dart->dev->of_node, "apple,num-streams", &n); + dart->pgsize = SZ_16K; + dart->supports_bypass = false; + dart->ias = 42; + dart->oas = 42; + dart->num_streams = n; + dart->four_level = true; + dart->version = 0x0300; +} + +/* + * First use of a static-topology Gen3 DART: everything probe skipped, in the safe order. + * Runs from the runtime-resume callback, which is irq-safe here: no sleeping calls. The + * fault IRQ is requested at probe (no MMIO) and ignored until hw_ready. + */ +static int apple_dart_gen3_late_init(struct apple_dart *dart) +{ + struct device *dev = dart->dev; + int ret; + u32 pgsize; + + pgsize = dart->pgsize; + apple_dart_read_params(dart); + if (dart->pgsize != pgsize) + return dev_err_probe(dev, -EINVAL, "page size %#x differs from the assumed %#x\n", + dart->pgsize, pgsize); + if (dart->num_streams > DART_MAX_STREAMS) + return dev_err_probe(dev, -EINVAL, "too many streams (%d)\n", dart->num_streams); + if (of_property_present(dev->of_node, "apple,dma-range")) { + if ((dart->dma_min ^ dart->dma_max) & ~DMA_BIT_MASK(dart->ias)) + return dev_err_probe(dev, -EINVAL, "DMA range does not fit ias=%d\n", dart->ias); + } else { + dart->dma_max = DMA_BIT_MASK(dart->ias); + } + + /* Read the lock before any write. A locked root needs the locked-TTBR path. */ + if (apple_dart_is_locked(dart)) + return dev_err_probe(dev, -EOPNOTSUPP, + "locked Gen3 DART is not supported in static-topology mode\n"); + + apple_dart_apply_tunables(dart); + + ret = apple_dart_hw_reset(dart); + if (ret) + return ret; + dart->hw_ready = true; + dev_info(dev, "Gen3 DART initialised on first use: pagesize %#x, %d streams, AS %d -> %d\n", + dart->pgsize, dart->num_streams, dart->ias, dart->oas); + return 0; +} + +/* + * Run the first-use init exactly once from whichever path gets there first: runtime + * resume, a consumer attach, or a fault IRQ on a powered but never initialised DART. + * The caller guarantees the DART is powered. Safe in atomic context. + */ +static int apple_dart_gen3_ensure_ready(struct apple_dart *dart) +{ + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&dart->late_lock, flags); + if (!dart->hw_ready) + ret = apple_dart_gen3_late_init(dart); + spin_unlock_irqrestore(&dart->late_lock, flags); + return ret; +} + +/* Every DART in a consumer's iommus list must be initialised before it is programmed. */ +static int apple_dart_cfg_ensure_ready(struct apple_dart_master_cfg *cfg) +{ + struct apple_dart_stream_map *stream_map; + int i, ret; + + for_each_stream_map(i, cfg, stream_map) { + struct apple_dart *dart = stream_map->dart; + + if (!dart->static_topo || dart->hw_ready) + continue; + dev_warn(dart->dev, + "first-use init was not run by runtime resume (rpm status %d); initialising from attach\n", + dart->dev->power.runtime_status); + ret = apple_dart_gen3_ensure_ready(dart); + if (ret) + return ret; + } + return 0; +} + +static int apple_dart_probe(struct platform_device *pdev) +{ + int ret; + u32 sid; struct device_node *pd_np; struct resource *res; struct apple_dart *dart; @@ -2869,6 +3117,8 @@ static int apple_dart_probe(struct platform_device *pdev) dart->dev = dev; dart->hw = of_device_get_match_data(dev); + dart->static_topo = dart->hw->gen3 && + of_property_read_bool(dev->of_node, "apple,static-topology"); dart->tunneled = tunneled; dart->per_stream = of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart"); @@ -2881,6 +3131,7 @@ static int apple_dart_probe(struct platform_device *pdev) } } spin_lock_init(&dart->lock); + spin_lock_init(&dart->late_lock); platform_set_drvdata(pdev, dart); /* @@ -2905,7 +3156,7 @@ static int apple_dart_probe(struct platform_device *pdev) dev_err(dev, "MMIO region too small (%pr)\n", res); return -EINVAL; } - if (tunneled) { + if (tunneled || dart->hw == &apple_dart_hw_t8152) { dart->tunables = devm_apple_tunable_parse(dev, dev->of_node, "apple,tunable", res); if (IS_ERR(dart->tunables)) { @@ -2921,10 +3172,26 @@ static int apple_dart_probe(struct platform_device *pdev) dart->tunables = NULL; } else { return dev_err_probe(dev, PTR_ERR(dart->tunables), - "failed to parse PCIe-C DART tunables\n"); + "failed to parse DART tunables\n"); } } } + if (dart->hw == &apple_dart_hw_t8152) { + /* TLBI doorbell: reg[1], shared by every Gen3 DART (no mem region claim) */ + struct resource *tr = platform_get_resource(pdev, IORESOURCE_MEM, 1); + + if (!tr || resource_size(tr) < 16) + return dev_err_probe(dev, -EINVAL, "Gen3 DART needs a 16-byte TLBI reg[1]\n"); + /* + * The doorbell uses the normal Device mapping, like the registers of the + * on-SoC DARTs; only the tunneled DARTs need ioremap_np(). Each doorbell + * store is followed by dsb ish, the TLBI and dsb osh (see the invalidate + * function), the vendor sequence. + */ + dart->tlbi = devm_ioremap(dev, tr->start, resource_size(tr)); + if (!dart->tlbi) + return -ENOMEM; + } dart->irq = platform_get_irq(pdev, 0); if (dart->irq < 0) @@ -2950,6 +3217,16 @@ static int apple_dart_probe(struct platform_device *pdev) dev_dbg(dev, "applying %zu PCIe-C DART tunables\n", dart->tunables->sz); apple_dart_apply_tunables(dart); + } else if (dart->hw == &apple_dart_hw_t8152 && !dart->static_topo) { + /* + * Firmware (SPTM) owns a locked Gen3 DART: its protection and tunables are + * already set and the 0x20c group sits in the write-protect block, so decide + * lock state with a read before any write. + */ + if (apple_dart_is_locked(dart)) + dev_info(dev, "Gen3 DART is locked: not applying tunables\n"); + else + apple_dart_apply_tunables(dart); } if (tunneled) { @@ -2983,30 +3260,10 @@ static int apple_dart_probe(struct platform_device *pdev) goto params_done; } - dart_params[0] = apple_dart_readl(dart, DART_PARAMS1); - dart_params[1] = apple_dart_readl(dart, DART_PARAMS2); - dart->pgsize = 1 << FIELD_GET(DART_PARAMS1_PAGE_SHIFT, dart_params[0]); - dart->supports_bypass = dart_params[1] & DART_PARAMS2_BYPASS_SUPPORT; - - switch (dart->hw->type) { - case DART_T8020: - case DART_T6000: - dart->ias = 32; - dart->oas = dart->hw->oas; - dart->num_streams = dart->hw->max_sid_count; - break; - - case DART_T8110: - dart_params[2] = apple_dart_readl(dart, DART_T8110_PARAMS3); - dart->ias = FIELD_GET(DART_T8110_PARAMS3_VA_WIDTH, dart_params[2]); - dart->oas = FIELD_GET(DART_T8110_PARAMS3_PA_WIDTH, dart_params[2]); - dart_params[3] = apple_dart_readl(dart, DART_T8110_PARAMS4); - dart->num_streams = FIELD_GET(DART_T8110_PARAMS4_NUM_SIDS, - dart_params[3]); - dart->four_level = dart->ias > 36; - dart->version = dart_params[2] & GENMASK(15, 0); - break; - } + if (dart->static_topo) + apple_dart_set_static_params(dart); + else + apple_dart_read_params(dart); params_done: dart->dma_min = 0; @@ -3092,30 +3349,43 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) goto err_clk_disable; - /* A hot-plug PCIe-C DART has no retained/locked translation context. */ + /* + * A hot-plug PCIe-C DART has no retained/locked translation context. + * A DART the bootloader leaves locked is one that hardware we do not drive + * still translates through (on T8152 Gen3 a display pipe scans out through + * the boot stream the whole time Linux is booting). Letting runtime PM + * suspend it drops the TTBRs underneath that traffic, and the engine then + * faults "TTBR invalid" forever. Hold the reference for the DART's lifetime. + */ if (tunneled) dart->locked = false; else - dart->locked = apple_dart_is_locked(dart); + dart->locked = !dart->static_topo && apple_dart_is_locked(dart); + if (dart->hw->gen3 && dart->locked && !dart->force_available) { + dev_info(dev, "locked DART: holding it available for its lifetime\n"); + dart->force_available = 1; + } /* Reserved table-page lifetime requires the matched three-level loader. */ dart->fw_handoff = apple_dart_fw_handoff_enabled(dart); /* Preserve our retained-root path when no reserved-table handoff exists. */ dart->fw_mirror = dart->locked && !dart->fw_handoff && (of_device_is_compatible(dev->of_node, "apple,t8140-dart") || of_device_is_compatible(dev->of_node, "apple,t8142-dart")); - if (!dart->locked) { + if (!dart->locked && !dart->static_topo) { ret = apple_dart_hw_reset(dart); if (ret) goto err_clk_disable; } + if (dart->static_topo) + dev_info(dev, "Gen3 DART static topology: no MMIO until first use\n"); if (dart->locked) apple_dart_drain_stale_exceptions(dart); - ret = request_irq(dart->irq, apple_dart_irq, IRQF_SHARED, "apple-dart fault handler", dart); if (ret) goto err_clk_disable; + dart->irq_requested = true; ret = iommu_device_sysfs_add(&dart->iommu, dev, NULL, "apple-dart.%s", dev_name(&pdev->dev)); @@ -3126,7 +3396,8 @@ static int apple_dart_probe(struct platform_device *pdev) if (ret) goto err_sysfs_remove; - pm_runtime_put(dev); + if (!dart->force_available) + pm_runtime_put(dev); dev_dbg( &pdev->dev, @@ -3138,7 +3409,8 @@ static int apple_dart_probe(struct platform_device *pdev) err_sysfs_remove: iommu_device_sysfs_remove(&dart->iommu); err_free_irq: - free_irq(dart->irq, dart); + if (dart->irq_requested) + free_irq(dart->irq, dart); err_clk_disable: pm_runtime_put(dev); clk_bulk_disable_unprepare(dart->num_clks, dart->clks); @@ -3253,13 +3525,17 @@ static void apple_dart_remove(struct platform_device *pdev) * A command issued then never completes. The next probe resets the * block after that clock is running again. */ - if (!dart->locked && !READ_ONCE(dart->commands_gated)) + if (!dart->locked && (!dart->static_topo || dart->hw_ready) && + !READ_ONCE(dart->commands_gated)) apple_dart_hw_reset(dart); - free_irq(dart->irq, dart); + if (dart->irq_requested) + free_irq(dart->irq, dart); iommu_device_unregister(&dart->iommu); iommu_device_sysfs_remove(&dart->iommu); + if (dart->force_available) + pm_runtime_put_noidle(dart->dev); clk_bulk_disable_unprepare(dart->num_clks, dart->clks); } @@ -3372,12 +3648,43 @@ static const struct apple_dart_hw apple_dart_hw_t8110 = { .ttbr_count = 1, }; +static const struct apple_dart_hw apple_dart_hw_t8152 = { + .type = DART_T8110, + .irq_handler = apple_dart_gen3_irq, + .invalidate_tlb = apple_dart_gen3_hw_invalidate_tlb, + .gen3 = true, + .fmt = APPLE_DART2, + .max_sid_count = 256, + + .enable_streams = DART_T8110_ENABLE_STREAMS, + .lock = DART_T8110_PROTECT, + .lock_bit = DART_T8110_PROTECT_TTBR_TCR, + + .error = DART_T8110_ERROR, + + .tcr = DART_T8110_TCR, + .tcr_enabled = DART_T8110_TCR_TRANSLATE_ENABLE, + .tcr_disabled = 0, + .tcr_bypass = DART_T8110_TCR_BYPASS_DAPF | DART_T8110_TCR_BYPASS_DART, + .tcr_4level = DART_T8110_TCR_FOUR_LEVEL, + + .ttbr = DART_T8110_TTBR, + .ttbr_valid = DART_T8110_TTBR_VALID, + .ttbr_addr_field_shift = DART_T8110_TTBR_ADDR_FIELD_SHIFT, + .ttbr_shift = DART_T8110_TTBR_SHIFT, + .ttbr_count = 1, +}; + static __maybe_unused int apple_dart_suspend(struct device *dev) { struct apple_dart *dart = dev_get_drvdata(dev); unsigned int sid, idx; dart->tunnel_state_restored = false; + /* A static-topology DART untouched so far has no state and must not be read. */ + if (dart->static_topo && !dart->hw_ready) + return 0; + if (READ_ONCE(dart->commands_gated)) return 0; /* The tunneled DART has no state to save when its domain stays on. */ @@ -3466,6 +3773,10 @@ static __maybe_unused int apple_dart_resume(struct device *dev) unsigned int sid, idx; int ret; + /* First resume of a static-topology DART: do everything probe skipped. */ + if (dart->static_topo && !dart->hw_ready) + return apple_dart_gen3_ensure_ready(dart); + /* PCIe-C restored these mappings before starting its downstream link. */ if (dart->tunnel_state_restored) { dart->tunnel_state_restored = false; @@ -3532,6 +3843,7 @@ static const struct of_device_id apple_dart_of_match[] = { { .compatible = "apple,t8103-dart", .data = &apple_dart_hw_t8103 }, { .compatible = "apple,t8103-usb4-dart", .data = &apple_dart_hw_t8103_usb4 }, { .compatible = "apple,t8110-dart", .data = &apple_dart_hw_t8110 }, + { .compatible = "apple,t8152-dart", .data = &apple_dart_hw_t8152 }, { .compatible = "apple,t6000-dart", .data = &apple_dart_hw_t6000 }, {}, }; diff --git a/drivers/nvme/host/apple.c b/drivers/nvme/host/apple.c index d3ef47fa840e49..815b298d3a430c 100644 --- a/drivers/nvme/host/apple.c +++ b/drivers/nvme/host/apple.c @@ -198,6 +198,12 @@ struct apple_nvme_hw { bool has_queue_count; bool has_separate_nvmmu; bool needs_ioq_registers; + /* T8152: LSQ_CTRL and IOQA accept writes but read back 0. */ + bool no_ioq_readback; + /* T8152: the queue setup registers live at different offsets. */ + bool t8152_reg_layout; + /* T8152: the ANS is a virtual PMGR device with no PS register, so there is no reset line. */ + bool no_reset_control; u32 max_queue_depth; unsigned long quirks; }; @@ -262,6 +268,27 @@ struct apple_nvme { struct blk_crypto_profile crypto_profile; }; +/* Map a legacy ANS register offset to the T8152 layout: admin queue +0x4000, IOQ registers +0x4000, + * LSQ_CTRL 0x24908 -> 0x2813c. */ +static u32 apple_nvme_reg(const struct apple_nvme *anv, u32 off) +{ + if (!anv->hw->t8152_reg_layout) + return off; + switch (off) { + case NVME_REG_AQA: + case NVME_REG_ASQ: + case NVME_REG_ACQ: + case APPLE_ANS_IOSQ_REGISTER: + case APPLE_ANS_IOCQ_REGISTER: + case APPLE_ANS_MAX_PEND_CMDS_CTRL: + return off + 0x4000; + case APPLE_ANS_LINEAR_SQ_CTRL: + return 0x2813c; + default: + return off; + } +} + /* Bit in recovery_flags: recovery_work owns the next controller stop. */ #define APPLE_NVME_RECOVERY_PENDING 0 @@ -1711,12 +1738,12 @@ static void apple_nvme_reset_work(struct work_struct *work) * since T6000. */ writel(APPLE_ANS_LINEAR_SQ_EN, - anv->mmio_nvme + APPLE_ANS_LINEAR_SQ_CTRL); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_LINEAR_SQ_CTRL)); if (anv->hw->needs_ioq_registers) { u32 lsq_ctrl = readl(anv->mmio_nvme + - APPLE_ANS_LINEAR_SQ_CTRL); + apple_nvme_reg(anv, APPLE_ANS_LINEAR_SQ_CTRL)); - if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN)) { + if (!(lsq_ctrl & APPLE_ANS_LINEAR_SQ_EN) && !anv->hw->no_ioq_readback) { dev_err(anv->dev, "failed to enable linear submission queues: LSQ_CTRL=0x%08x\n", lsq_ctrl); @@ -1736,9 +1763,9 @@ static void apple_nvme_reset_work(struct work_struct *work) if (anv->hw->needs_ioq_registers) ioqa_depth--; ioqa = ioqa_depth | (ioqa_depth << 16); - writel(ioqa, anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL); - if (anv->hw->needs_ioq_registers && - readl(anv->mmio_nvme + APPLE_ANS_MAX_PEND_CMDS_CTRL) != ioqa) { + writel(ioqa, anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)); + if (anv->hw->needs_ioq_registers && !anv->hw->no_ioq_readback && + readl(anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_MAX_PEND_CMDS_CTRL)) != ioqa) { dev_err(anv->dev, "failed to program I/O queue aperture\n"); ret = -EIO; goto out; @@ -1752,11 +1779,11 @@ static void apple_nvme_reset_work(struct work_struct *work) /* Setup the admin queue */ aqa = APPLE_NVME_AQ_DEPTH - 1; aqa |= aqa << 16; - writel(aqa, anv->mmio_nvme + NVME_REG_AQA); + writel(aqa, anv->mmio_nvme + apple_nvme_reg(anv, NVME_REG_AQA)); apple_nvme_writeq(anv, anv->adminq.sq_dma_addr, - anv->mmio_nvme + NVME_REG_ASQ); + anv->mmio_nvme + apple_nvme_reg(anv, NVME_REG_ASQ)); apple_nvme_writeq(anv, anv->adminq.cq_dma_addr, - anv->mmio_nvme + NVME_REG_ACQ); + anv->mmio_nvme + apple_nvme_reg(anv, NVME_REG_ACQ)); if (anv->hw->has_lsq_nvmmu) { /* Setup NVMMU for both queues */ @@ -1824,9 +1851,9 @@ static void apple_nvme_reset_work(struct work_struct *work) * reports null I/O SQ and CQ addresses. */ apple_nvme_writeq(anv, anv->ioq.cq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOCQ_REGISTER); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_IOCQ_REGISTER)); apple_nvme_writeq(anv, anv->ioq.sq_dma_addr, - anv->mmio_nvme + APPLE_ANS_IOSQ_REGISTER); + anv->mmio_nvme + apple_nvme_reg(anv, APPLE_ANS_IOSQ_REGISTER)); } nr_io_queues = 1; if (anv->hw->has_queue_count) { @@ -2309,7 +2336,11 @@ static struct apple_nvme *apple_nvme_alloc(struct platform_device *pdev) goto out_detach_genpd; } - anv->reset = devm_reset_control_array_get_exclusive(anv->dev); + /* T8152's ANS is a virtual PMGR device with no PS register, so the DT has no reset to give. */ + if (anv->hw->no_reset_control) + anv->reset = NULL; + else + anv->reset = devm_reset_control_array_get_exclusive(anv->dev); if (IS_ERR(anv->reset)) { ret = dev_err_probe(dev, PTR_ERR(anv->reset), "Failed to get reset control"); @@ -2642,11 +2673,27 @@ static const struct apple_nvme_hw apple_nvme_t8140_hw = { .quirks = NVME_QUIRK_BROKEN_FUA, }; +/* T8152: NVMMU registers sit in the 0x60000 NVMe window (no separate region; the T8140 + * alias window does not exist and faults). */ +static const struct apple_nvme_hw apple_nvme_t8152_hw = { + /* T8152 register layout, linear submission queue, 64 queue entries. */ + .has_lsq_nvmmu = true, + .has_queue_count = true, + .has_separate_nvmmu = false, + .no_ioq_readback = true, + .t8152_reg_layout = true, + .no_reset_control = true, + .needs_ioq_registers = true, + .max_queue_depth = 64, + .quirks = NVME_QUIRK_BROKEN_FUA, +}; + static const struct of_device_id apple_nvme_of_match[] = { { .compatible = "apple,t8015-nvme-ans2", .data = &apple_nvme_t8015_hw }, { .compatible = "apple,t8103-nvme-ans2", .data = &apple_nvme_t8103_hw }, { .compatible = "apple,t8132-nvme-ans2", .data = &apple_nvme_t8132_hw }, { .compatible = "apple,t8140-nvme-ans2", .data = &apple_nvme_t8140_hw }, + { .compatible = "apple,t8152-nvme-ans2", .data = &apple_nvme_t8152_hw }, { .compatible = "apple,nvme-ans2", .data = &apple_nvme_t8103_hw }, {}, }; diff --git a/drivers/phy/apple/Kconfig b/drivers/phy/apple/Kconfig index 66c71acb005156..95b31a796e4cf3 100644 --- a/drivers/phy/apple/Kconfig +++ b/drivers/phy/apple/Kconfig @@ -40,3 +40,14 @@ config PHY_APPLE_DPTX such as the M2. This driver provides support for DisplayPort and is used on the Mac mini (M2 and M2 Pro, 2023). + +config PHY_APPLE_T8152_USB2 + tristate "Apple T8152 fixed-host USB2 PHY" + default ARCH_APPLE + depends on ARCH_APPLE || COMPILE_TEST + depends on PM + select GENERIC_PHY + select APPLE_TUNABLE + help + Enable the USB2-only PHY for fixed host ports on Apple T8152. + This does not configure the USB3 or USB4 lanes. diff --git a/drivers/phy/apple/Makefile b/drivers/phy/apple/Makefile index b9e7bf3e4ac170..bc33678c64707a 100644 --- a/drivers/phy/apple/Makefile +++ b/drivers/phy/apple/Makefile @@ -5,3 +5,6 @@ phy-apple-atc-y := atc.o obj-$(CONFIG_PHY_APPLE_DPTX) += phy-apple-dptx.o phy-apple-dptx-y += dptx.o + +obj-$(CONFIG_PHY_APPLE_T8152_USB2) += phy-apple-t8152-usb2.o +phy-apple-t8152-usb2-y := usb2-t8152.o diff --git a/drivers/phy/apple/usb2-t8152.c b/drivers/phy/apple/usb2-t8152.c new file mode 100644 index 00000000000000..6bb54dfe301030 --- /dev/null +++ b/drivers/phy/apple/usb2-t8152.c @@ -0,0 +1,231 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define USB2_CONTROL 0x00 +#define USB2_RESET 0x04 +#define USB2_VBUS 0x08 +#define USB2_VBUS_FORCE GENMASK(3, 0) +#define USB2_HOST_MODE GENMASK(14, 12) +#define USB2_CLOCK 0x1c +#define USB2_MODE GENMASK(2, 0) +#define USB2_RUN 2 +#define USB2_STOP 4 +#define USB2_RESET_ASSERT BIT(0) +#define USB2_PORT_RESET BIT(1) +#define USB2_APB_RESET_N BIT(2) +#define USB2_SIDDQ BIT(3) +#define USB2_REFCLK_GATE BIT(29) +#define USB2_PHYCLOCK_GATE BIT(30) +/* + * Bits that the host path sets. Their function is not documented; they are + * named by position. + */ +#define USB2_VBUS_HOST_BIT2 BIT(2) +#define USB2_VBUS_HOST_BIT3 BIT(3) +#define EUSB2_HOST_ENABLE (BIT(0) | BIT(3)) +/* + * Device-mode value of the misc-tune register from m1n1 src/usb.c + * usb_phy_bringup(), the role-agnostic USB2 device console setup. The word + * leaves the same refclk/APB gate bits clear that the host path clears below. + */ +#define USB2_DEVICE_MISCTUNE 0x008c0813 + +struct apple_usb2 { + void __iomem *usb2; + void __iomem *eusb2; + struct apple_tunable *dflt; + struct apple_tunable *host; + struct apple_tunable *dev; + enum phy_mode mode; +}; + +static void apple_usb2_update(void __iomem *reg, u32 clear, u32 set) +{ + writel((readl(reg) & ~clear) | set, reg); +} + +static int apple_usb2_power_on(struct phy *phy) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + apple_tunable_apply(usb->usb2, usb->dflt); + if (usb->mode == PHY_MODE_USB_DEVICE) { + if (!usb->dev) + return -EINVAL; + apple_tunable_apply(usb->usb2, usb->dev); + } else { + if (!usb->host) + return -EINVAL; + apple_tunable_apply(usb->usb2, usb->host); + } + if (usb->mode == PHY_MODE_USB_DEVICE) { + apple_usb2_update(usb->usb2 + USB2_VBUS, USB2_HOST_MODE, USB2_VBUS_FORCE); + } else { + apple_usb2_update(usb->usb2 + USB2_VBUS, 0, USB2_VBUS_HOST_BIT2); + apple_usb2_update(usb->usb2 + USB2_VBUS, 0, USB2_VBUS_HOST_BIT3); + } + msleep(10); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_SIDDQ, 0); + udelay(10); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_RESET_ASSERT, 0); + apple_usb2_update(usb->usb2 + USB2_RESET, USB2_PORT_RESET, 0); + apple_usb2_update(usb->eusb2, 0, EUSB2_HOST_ENABLE); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_APB_RESET_N); + if (usb->mode == PHY_MODE_USB_DEVICE) + writel(USB2_DEVICE_MISCTUNE, usb->usb2 + USB2_CLOCK); + else { + apple_usb2_update(usb->usb2 + USB2_CLOCK, USB2_REFCLK_GATE, 0); + apple_usb2_update(usb->usb2 + USB2_CLOCK, USB2_PHYCLOCK_GATE, 0); + } + udelay(30); + msleep(5); + apple_usb2_update(usb->usb2 + USB2_CONTROL, USB2_MODE, USB2_RUN); + + return 0; +} + +static int apple_usb2_power_off(struct phy *phy) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + if (!(readl(usb->usb2 + USB2_RESET) & USB2_PORT_RESET)) { + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_PORT_RESET); + msleep(5); + } + apple_usb2_update(usb->usb2 + USB2_CONTROL, USB2_MODE, USB2_STOP); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_SIDDQ); + apple_usb2_update(usb->usb2 + USB2_RESET, 0, USB2_RESET_ASSERT); + apple_usb2_update(usb->usb2 + USB2_CLOCK, 0, USB2_REFCLK_GATE); + apple_usb2_update(usb->usb2 + USB2_CLOCK, 0, USB2_PHYCLOCK_GATE); + + return 0; +} + +static int apple_usb2_set_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct apple_usb2 *usb = phy_get_drvdata(phy); + + (void)submode; + if (mode != PHY_MODE_USB_HOST && mode != PHY_MODE_USB_DEVICE) + return -EINVAL; + if (mode == PHY_MODE_USB_DEVICE && !usb->dev) + return -EINVAL; + if (mode == PHY_MODE_USB_HOST && !usb->host) + return -EINVAL; + usb->mode = mode; + + return 0; +} + +static const struct phy_ops apple_usb2_ops = { + .power_on = apple_usb2_power_on, + .power_off = apple_usb2_power_off, + .set_mode = apple_usb2_set_mode, + .owner = THIS_MODULE, +}; + +static int apple_usb2_probe(struct platform_device *pdev) +{ + static const char * const pd_names[] = { "usb-aon", "usb" }; + const struct dev_pm_domain_attach_data pd_data = { + .pd_names = pd_names, + .num_pd_names = ARRAY_SIZE(pd_names), + }; + struct device *dev = &pdev->dev; + struct dev_pm_domain_list *domains; + struct phy_provider *provider; + struct resource *res; + struct apple_usb2 *usb; + struct phy *phy; + int ret; + + if (of_count_phandle_with_args(dev->of_node, "power-domains", + "#power-domain-cells") != ARRAY_SIZE(pd_names)) + return dev_err_probe(dev, -EINVAL, "Both USB2 power domains are required\n"); + + usb = devm_kzalloc(dev, sizeof(*usb), GFP_KERNEL); + if (!usb) + return -ENOMEM; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "usb2"); + usb->usb2 = devm_ioremap_resource(dev, res); + if (IS_ERR(usb->usb2)) + return PTR_ERR(usb->usb2); + if (resource_size(res) < USB2_CLOCK + sizeof(u32)) + return -EINVAL; + + usb->dflt = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-dflt", res); + if (IS_ERR(usb->dflt)) + return dev_err_probe(dev, PTR_ERR(usb->dflt), "Invalid default tunables\n"); + usb->host = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-host", res); + if (IS_ERR(usb->host)) { + if (PTR_ERR(usb->host) != -ENOENT) + return dev_err_probe(dev, PTR_ERR(usb->host), "Invalid host tunables\n"); + usb->host = NULL; + } + usb->dev = devm_apple_tunable_parse(dev, dev->of_node, + "apple,tunable-usb2phy-dev", res); + if (IS_ERR(usb->dev)) { + if (PTR_ERR(usb->dev) != -ENOENT) + return dev_err_probe(dev, PTR_ERR(usb->dev), "Invalid device tunables\n"); + usb->dev = NULL; + } + if (!usb->host && !usb->dev) + return dev_err_probe(dev, -EINVAL, "No USB2 role calibration\n"); + /* Default to the role whose calibration the board actually supplies. */ + usb->mode = usb->host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE; + + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "eusb2"); + usb->eusb2 = devm_ioremap_resource(dev, res); + if (IS_ERR(usb->eusb2)) + return PTR_ERR(usb->eusb2); + if (resource_size(res) < sizeof(u32)) + return -EINVAL; + + ret = devm_pm_domain_attach_list(dev, &pd_data, &domains); + if (ret < 0) + return dev_err_probe(dev, ret, "Failed to attach USB2 power domains\n"); + if (ret != ARRAY_SIZE(pd_names)) + return -ENODEV; + + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + + phy = devm_phy_create(dev, NULL, &apple_usb2_ops); + if (IS_ERR(phy)) + return PTR_ERR(phy); + phy_set_drvdata(phy, usb); + + provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate); + return PTR_ERR_OR_ZERO(provider); +} + +static const struct of_device_id apple_usb2_match[] = { + { .compatible = "apple,t8152-usb2-phy" }, + { } +}; +MODULE_DEVICE_TABLE(of, apple_usb2_match); + +static struct platform_driver apple_usb2_driver = { + .probe = apple_usb2_probe, + .driver = { + .name = "apple-t8152-usb2-phy", + .of_match_table = apple_usb2_match, + }, +}; +module_platform_driver(apple_usb2_driver); + +MODULE_DESCRIPTION("Apple T8152 USB2 PHY"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/pinctrl/pinctrl-apple-gpio.c b/drivers/pinctrl/pinctrl-apple-gpio.c index eee7f5014ecc18..620d0e57bb2ccb 100644 --- a/drivers/pinctrl/pinctrl-apple-gpio.c +++ b/drivers/pinctrl/pinctrl-apple-gpio.c @@ -597,6 +597,7 @@ static int apple_gpio_pinctrl_probe(struct platform_device *pdev) static const struct of_device_id apple_gpio_pinctrl_of_match[] = { { .compatible = "apple,t8140-pinctrl", .data = &apple_gpio_t8140_hw }, + { .compatible = "apple,t8152-pinctrl", .data = &apple_gpio_t8140_hw }, { .compatible = "apple,t8103-pinctrl", }, { .compatible = "apple,pinctrl", }, { } diff --git a/drivers/pmdomain/apple/Kconfig b/drivers/pmdomain/apple/Kconfig index 5f0a9d95c196c2..2e85b6d5031abe 100644 --- a/drivers/pmdomain/apple/Kconfig +++ b/drivers/pmdomain/apple/Kconfig @@ -25,6 +25,18 @@ config APPLE_PMGR_PWRSTATE_KUNIT_TEST driver's power callbacks against an emulated power state register and need no Apple hardware. +config APPLE_PMGR_PSD + bool "Apple T8152 PSD service slot power domains" + default ARCH_APPLE + depends on OF + depends on PM + select PM_GENERIC_DOMAINS + help + The M6 (T8152) power state director gates the ATC USB blocks behind a + per-port service slot request on top of the PMGR power states. This + driver exposes each slot as a power domain whose parents are the PMGR + domains, so consumers (the USB DARTs and controllers) power both in order. + config APPLE_PMP_REPORT bool "Apple PMP report control" depends on OF diff --git a/drivers/pmdomain/apple/Makefile b/drivers/pmdomain/apple/Makefile index ff7f9192b5e39f..c9f1e412f6ab93 100644 --- a/drivers/pmdomain/apple/Makefile +++ b/drivers/pmdomain/apple/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += pmgr-pwrstate.o +obj-$(CONFIG_APPLE_PMGR_PSD) += pmgr-psd.o obj-$(CONFIG_APPLE_PMGR_PWRSTATE) += gfx-tvm.o obj-$(CONFIG_APPLE_PMP_REPORT) += pmp-report.o obj-$(CONFIG_APPLE_PMP_REPORT_KUNIT_TEST) += pmp-report-test.o diff --git a/drivers/pmdomain/apple/pmgr-psd.c b/drivers/pmdomain/apple/pmgr-psd.c new file mode 100644 index 00000000000000..9be3506d9ed5a8 --- /dev/null +++ b/drivers/pmdomain/apple/pmgr-psd.c @@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 PSD (power state director) service slot power domains + * + * On the M6 the USB blocks are not usable (even their DART registers hang the bus) + * until two things have happened: the PMGR power states of the block are active, and the + * PSD service slot for the port has been requested to run (state 0) and has + * acknowledged. This driver models the second step as a genpd whose parents are the + * PMGR domains: genpd powers the parents first, then this domain's power_on writes the + * slot request and waits for the ack. + * + * Per-slot window (reg, 0x100 bytes at base + (slot << 8)): + * 0x80 status bits 2:0 = current PSD state + * 0x90 request (write a PSD state) + * 0xa0 diag + * 0xbc valid bit 0 = status is valid + * PSD states: this driver accepts states 0 (running) to 6 (off). + * + * Ack: the valid bit 0 is set and (status & 7) equals the requested state. + * + * Slot groups: a block that needs several slots (the GPU uses several) must bring them up + * together, in a fixed order, with possibly different active states. A node with compatible + * "apple,t8152-psd-group" lists one reg window per slot and apple,psd-states with each slot's + * active state; power_on requests the slots in reg order, power_off requests state 6 in reverse. + * + * Reading STATUS clears the acknowledge, so a request polls VALID first and reads + * STATUS only once VALID is set. + * + * Lifetime: this domain sleeps in power_on (usleep_range polling), so it is not IRQ-safe. + * The platform bus powers a consumer's single power domain on at attach time, before its + * probe runs, which issues the request in process context. A consumer that marks its + * runtime PM irq_safe (the Apple DART does) keeps this domain powered: genpd never powers off + * a sleepable domain holding an irq-safe device and skips the (atomic-context) power_on on + * its runtime resume (drivers/pmdomain/core.c irq_safe_dev_in_sleep_domain users). Other + * consumers may let it power off to state 6. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define APPLE_PSD_STATUS 0x80 +#define APPLE_PSD_REQUEST 0x90 +#define APPLE_PSD_DIAG 0xa0 +#define APPLE_PSD_VALID 0xbc +#define APPLE_PSD_STATE GENMASK(2, 0) +#define APPLE_PSD_VALID_BIT BIT(0) + +#define APPLE_PSD_STATE_RUNNING 0 +#define APPLE_PSD_STATE_OFF 6 + +#define APPLE_PSD_DEFAULT_TIMEOUT_MS 1000 /* default ack timeout, apple,psd-timeout-ms overrides it */ +#define APPLE_PSD_MAX_SLOTS 3 + +struct apple_psd { + struct device *dev; + void __iomem *regs[APPLE_PSD_MAX_SLOTS]; + u32 active[APPLE_PSD_MAX_SLOTS]; + unsigned int nslots; + struct generic_pm_domain genpd; + unsigned int timeout_ms; +}; + +#define to_apple_psd(d) container_of(d, struct apple_psd, genpd) + +static int apple_psd_request(struct apple_psd *psd, unsigned int slot, u32 state) +{ + void __iomem *regs = psd->regs[slot]; + unsigned long timeout = jiffies + msecs_to_jiffies(psd->timeout_ms); + u32 valid = 0, status = 0; + + writel(state, regs + APPLE_PSD_REQUEST); + + for (;;) { + valid = readl(regs + APPLE_PSD_VALID); + if (valid & APPLE_PSD_VALID_BIT) { + /* Reading STATUS clears the acknowledge, so only after VALID. */ + status = readl(regs + APPLE_PSD_STATUS); + if (FIELD_GET(APPLE_PSD_STATE, status) == state) + return 0; + } + if (time_after(jiffies, timeout)) + break; + usleep_range(50, 200); + } + + dev_err(psd->dev, + "PSD slot %u request %u not acknowledged: valid %#x status %#x diag %#x\n", slot, + state, valid, status, readl(regs + APPLE_PSD_DIAG)); + return -ETIMEDOUT; +} + +static int apple_psd_power_on(struct generic_pm_domain *genpd) +{ + struct apple_psd *psd = to_apple_psd(genpd); + int i, ret; + + for (i = 0; i < psd->nslots; i++) { + ret = apple_psd_request(psd, i, psd->active[i]); + if (ret) + goto undo; + } + return 0; + +undo: + /* + * Best effort: put the slots back to idle, newest first. The slot whose request timed + * out is included, because its acknowledge was not seen but it may still start. + */ + for (; i >= 0; i--) + apple_psd_request(psd, i, APPLE_PSD_STATE_OFF); + return ret; +} + +static int apple_psd_power_off(struct generic_pm_domain *genpd) +{ + struct apple_psd *psd = to_apple_psd(genpd); + int i, ret, first = 0; + + for (i = psd->nslots - 1; i >= 0; i--) { + ret = apple_psd_request(psd, i, APPLE_PSD_STATE_OFF); + if (ret && !first) + first = ret; + } + if (!first) + return 0; + + /* + * genpd keeps the domain marked on after a failed power-off, so the next resume does not + * call power_on. Put every slot back to its active state, best effort: the slots that + * did stop, and the one whose off request timed out and may still finish stopping. + */ + for (i = 0; i < psd->nslots; i++) + apple_psd_request(psd, i, psd->active[i]); + return first; +} + +static int apple_psd_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *node = dev->of_node; + struct apple_psd *psd; + const char *name; + u32 status, valid; + unsigned int i; + int ret; + + psd = devm_kzalloc(dev, sizeof(*psd), GFP_KERNEL); + if (!psd) + return -ENOMEM; + psd->dev = dev; + psd->timeout_ms = APPLE_PSD_DEFAULT_TIMEOUT_MS; + of_property_read_u32(node, "apple,psd-timeout-ms", &psd->timeout_ms); + + for (i = 0; i < APPLE_PSD_MAX_SLOTS; i++) { + struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, i); + + if (!res) + break; + psd->regs[i] = devm_ioremap_resource(dev, res); + if (IS_ERR(psd->regs[i])) + return PTR_ERR(psd->regs[i]); + psd->nslots++; + } + if (!psd->nslots) + return dev_err_probe(dev, -EINVAL, "no register window\n"); + + /* Per-slot active state, in reg order; default 0 (running). */ + if (of_property_present(node, "apple,psd-states")) { + ret = of_property_read_u32_array(node, "apple,psd-states", psd->active, + psd->nslots); + if (ret) + return dev_err_probe(dev, ret, "apple,psd-states needs one cell per reg\n"); + for (i = 0; i < psd->nslots; i++) + if (psd->active[i] >= APPLE_PSD_STATE_OFF) + return dev_err_probe(dev, -EINVAL, "bad PSD active state %u\n", + psd->active[i]); + } + + ret = of_property_read_string(node, "label", &name); + if (ret) + name = node->name; + psd->genpd.name = name; + psd->genpd.power_on = apple_psd_power_on; + psd->genpd.power_off = apple_psd_power_off; + + /* + * Always start OFF: an inherited status of state 0 without the valid bit is not an + * acknowledged P0, and the parents' state is not known here. The first consumer's + * power_on then issues the request (idempotent if the slot already runs P0). + * A status read is safe (proven on hardware); no write happens at probe. + */ + status = readl(psd->regs[0] + APPLE_PSD_STATUS); + valid = readl(psd->regs[0] + APPLE_PSD_VALID); + + ret = pm_genpd_init(&psd->genpd, NULL, true); + if (ret) + return dev_err_probe(dev, ret, "pm_genpd_init failed\n"); + + ret = of_genpd_add_provider_simple(node, &psd->genpd); + if (ret) { + dev_err(dev, "of_genpd_add_provider_simple failed: %d\n", ret); + goto err_remove; + } + + /* The PMGR parents are brought up before power_on runs. */ + for (i = 0; ; i++) { + struct of_phandle_args parent, child; + + ret = of_parse_phandle_with_args(node, "power-domains", "#power-domain-cells", i, + &parent); + if (ret == -ENOENT) + break; /* no (more) parents */ + if (ret) + goto err_unlink; + child.np = node; + child.args_count = 0; + ret = of_genpd_add_subdomain(&parent, &child); + if (ret < 0 && ret != -EPROBE_DEFER) + dev_err(dev, "failed to add parent domain %pOFn: %d\n", parent.np, ret); + of_node_put(parent.np); + if (ret < 0) + goto err_unlink; + } + ret = 0; + + /* Parent domains are handled through the genpd hierarchy, not as a device. */ + pm_genpd_remove_device(dev); + + dev_info(dev, "PSD slot domain %s, %u slot(s) (status %#x valid %#x at probe, starting off)\n", + name, psd->nslots, status, valid); + return 0; + +err_unlink: + /* pm_genpd_remove() drops any parent links added so far. */ + of_genpd_del_provider(node); +err_remove: + pm_genpd_remove(&psd->genpd); + return ret; +} + +static const struct of_device_id apple_psd_of_match[] = { + { .compatible = "apple,t8152-psd" }, + { .compatible = "apple,t8152-psd-group" }, + { } +}; +MODULE_DEVICE_TABLE(of, apple_psd_of_match); + +static struct platform_driver apple_psd_driver = { + .probe = apple_psd_probe, + .driver = { + .name = "apple-pmgr-psd", + .of_match_table = apple_psd_of_match, + .suppress_bind_attrs = true, + }, +}; +builtin_platform_driver(apple_psd_driver); + +MODULE_DESCRIPTION("Apple T8152 PSD service slot power domains"); +MODULE_LICENSE("Dual MIT/GPL"); diff --git a/drivers/soc/apple/mailbox.c b/drivers/soc/apple/mailbox.c index 5be648a40fe03c..5203cc52f2f79e 100644 --- a/drivers/soc/apple/mailbox.c +++ b/drivers/soc/apple/mailbox.c @@ -117,6 +117,8 @@ struct apple_mbox_hw { unsigned int reg_offset; bool is_ascwrap_v6; bool ap_initializes_mailboxes; + /* The status word counts RX occupancy and free TX slots; a message is one paired access. */ + bool counted_fifo; unsigned int control_full; unsigned int control_empty; @@ -266,6 +268,70 @@ int apple_mbox_ascwrap_v6_stop_cpu(struct apple_mbox *mbox) } EXPORT_SYMBOL_GPL(apple_mbox_ascwrap_v6_stop_cpu); +static bool apple_mbox_tx_full(struct apple_mbox *mbox, u32 status) +{ + if (mbox->hw->counted_fifo) + return !(status & mbox->hw->control_full); + return status & mbox->hw->control_full; +} + +static bool apple_mbox_rx_empty(struct apple_mbox *mbox, u32 status) +{ + if (mbox->hw->counted_fifo) + return !(status & mbox->hw->control_empty); + return status & mbox->hw->control_empty; +} + +static void apple_mbox_write_msg(struct apple_mbox *mbox, const struct apple_mbox_msg msg) +{ + u64 high = FIELD_PREP(APPLE_MBOX_MSG1_MSG, msg.msg1); + +#ifdef CONFIG_ARM64 + if (mbox->hw->counted_fifo) { + u64 low = (__force u64)cpu_to_le64(msg.msg0); + + high = (__force u64)cpu_to_le64(high); + /* Order the message words against the earlier writes to the shared buffers. */ + wmb(); + asm volatile("stp %0, %1, [%2]" + : : "r" (low), "r" (high), + "r" (mbox->regs + mbox->hw->a2i_send0) + : "memory"); + return; + } +#endif + writeq_relaxed(msg.msg0, mbox->regs + mbox->hw->a2i_send0); + writeq_relaxed(high, mbox->regs + mbox->hw->a2i_send1); +} + +static struct apple_mbox_msg apple_mbox_read_msg(struct apple_mbox *mbox) +{ + struct apple_mbox_msg msg; + bool paired = false; + u64 low, high; + +#ifdef CONFIG_ARM64 + if (mbox->hw->counted_fifo) { + asm volatile("ldp %0, %1, [%2]" + : "=&r" (low), "=&r" (high) + : "r" (mbox->regs + mbox->hw->i2a_recv0) + : "memory"); + /* The message words must be read before the buffers they describe. */ + rmb(); + low = le64_to_cpu((__force __le64)low); + high = le64_to_cpu((__force __le64)high); + paired = true; + } +#endif + if (!paired) { + low = readq_relaxed(mbox->regs + mbox->hw->i2a_recv0); + high = readq_relaxed(mbox->regs + mbox->hw->i2a_recv1); + } + msg.msg0 = low; + msg.msg1 = FIELD_GET(APPLE_MBOX_MSG1_MSG, high); + return msg; +} + int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, bool atomic) { @@ -281,11 +347,11 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, } mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); - while (mbox_ctrl & mbox->hw->control_full) { + while (apple_mbox_tx_full(mbox, mbox_ctrl)) { if (atomic || mbox->irq_send_empty < 0) { ret = readl_poll_timeout_atomic( mbox->regs + mbox->hw->a2i_control, mbox_ctrl, - !(mbox_ctrl & mbox->hw->control_full), 100, + !apple_mbox_tx_full(mbox, mbox_ctrl), 100, APPLE_MBOX_TX_TIMEOUT * 1000); if (ret) { @@ -337,9 +403,7 @@ int apple_mbox_send(struct apple_mbox *mbox, const struct apple_mbox_msg msg, mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->a2i_control); } - writeq_relaxed(msg.msg0, mbox->regs + mbox->hw->a2i_send0); - writeq_relaxed(FIELD_PREP(APPLE_MBOX_MSG1_MSG, msg.msg1), - mbox->regs + mbox->hw->a2i_send1); + apple_mbox_write_msg(mbox, msg); spin_unlock_irqrestore(&mbox->tx_lock, flags); @@ -380,11 +444,8 @@ static int apple_mbox_poll_locked(struct apple_mbox *mbox) return 0; mbox_ctrl = readl_relaxed(mbox->regs + mbox->hw->i2a_control); - while (!(mbox_ctrl & mbox->hw->control_empty)) { - msg.msg0 = readq_relaxed(mbox->regs + mbox->hw->i2a_recv0); - msg.msg1 = FIELD_GET( - APPLE_MBOX_MSG1_MSG, - readq_relaxed(mbox->regs + mbox->hw->i2a_recv1)); + while (!apple_mbox_rx_empty(mbox, mbox_ctrl)) { + msg = apple_mbox_read_msg(mbox); mbox->rx(mbox, msg, mbox->cookie); ret++; @@ -646,6 +707,8 @@ static int apple_mbox_probe(struct platform_device *pdev) mbox->hw = of_device_get_match_data(dev); if (!mbox->hw) return -EINVAL; + if (mbox->hw->counted_fifo && !IS_ENABLED(CONFIG_ARM64)) + return -EOPNOTSUPP; if (mbox->hw->is_ascwrap_v6) { /* @@ -795,6 +858,28 @@ static const struct apple_mbox_hw apple_mbox_t8015_hw = { .has_irq_controls = false, }; +/* + * T8152 ACIO (USB4) co-processor mailbox: RX at +0, TX at +0x10 and the status + * word at +0x20 of the 0x80-byte window. The status word holds the RX occupancy + * (bits 3:0) and the free TX slots (bits 11:8). The interrupts are not + * controlled per mailbox. + */ +static const struct apple_mbox_hw apple_mbox_t8152_acio_hw = { + .counted_fifo = true, + .control_full = GENMASK(11, 8), + .control_empty = GENMASK(3, 0), + + .a2i_control = 0x20, + .a2i_send0 = 0x10, + .a2i_send1 = 0x18, + + .i2a_control = 0x20, + .i2a_recv0 = 0x00, + .i2a_recv1 = 0x08, + + .has_irq_controls = false, +}; + static const struct apple_mbox_hw apple_mbox_asc_hw = { .control_full = APPLE_ASC_MBOX_CONTROL_FULL, .control_empty = APPLE_ASC_MBOX_CONTROL_EMPTY, @@ -890,6 +975,7 @@ static const struct of_device_id apple_mbox_of_match[] = { * kernels without M3 GPU support leave it unbound. */ { .compatible = "apple,t6030-agx-asc-mailbox", .data = &apple_mbox_asc_hw }, + { .compatible = "apple,t8152-acio-mailbox", .data = &apple_mbox_t8152_acio_hw }, { .compatible = "apple,asc-mailbox-v4", .data = &apple_mbox_asc_hw }, { .compatible = "apple,t8015-asc-mailbox", .data = &apple_mbox_t8015_hw }, { .compatible = "apple,m3-mailbox-v2", .data = &apple_mbox_m3_hw }, diff --git a/drivers/soc/apple/sart.c b/drivers/soc/apple/sart.c index b0b208c92741dc..e8777835d738a3 100644 --- a/drivers/soc/apple/sart.c +++ b/drivers/soc/apple/sart.c @@ -62,6 +62,18 @@ #define APPLE_SART3_FLAGS_ALLOW 0xff +/* SARTv4 (CoastGuard, T8152) registers; layout from m1n1 sart4 */ +#define APPLE_SART4_CONFIG(idx) (0x00 + 4 * (idx)) + +#define APPLE_SART4_PADDR(idx) (0x60 + 4 * (idx)) +#define APPLE_SART4_PADDR_SHIFT 12 + +#define APPLE_SART4_SIZE(idx) (0xc0 + 4 * (idx)) +#define APPLE_SART4_SIZE_SHIFT 12 +#define APPLE_SART4_SIZE_MAX GENMASK(29, 0) + +#define APPLE_SART4_FLAGS_ALLOW 0xff + struct apple_sart_ops { void (*get_entry)(struct apple_sart *sart, int index, u8 *flags, phys_addr_t *paddr, size_t *size); @@ -178,6 +190,35 @@ static struct apple_sart_ops sart_ops_v3 = { .size_max = APPLE_SART3_SIZE_MAX, }; + +static void sart4_get_entry(struct apple_sart *sart, int index, u8 *flags, + phys_addr_t *paddr, size_t *size) +{ + phys_addr_t paddr_ = readl(sart->regs + APPLE_SART4_PADDR(index)); + size_t size_ = readl(sart->regs + APPLE_SART4_SIZE(index)); + + *flags = readl(sart->regs + APPLE_SART4_CONFIG(index)); + *size = size_ << APPLE_SART4_SIZE_SHIFT; + *paddr = paddr_ << APPLE_SART4_PADDR_SHIFT; +} + +static void sart4_set_entry(struct apple_sart *sart, int index, u8 flags, + phys_addr_t paddr_shifted, size_t size_shifted) +{ + writel(paddr_shifted, sart->regs + APPLE_SART4_PADDR(index)); + writel(size_shifted, sart->regs + APPLE_SART4_SIZE(index)); + writel(flags, sart->regs + APPLE_SART4_CONFIG(index)); +} + +static struct apple_sart_ops sart_ops_v4 = { + .get_entry = sart4_get_entry, + .set_entry = sart4_set_entry, + .flags_allow = APPLE_SART4_FLAGS_ALLOW, + .size_shift = APPLE_SART4_SIZE_SHIFT, + .paddr_shift = APPLE_SART4_PADDR_SHIFT, + .size_max = APPLE_SART4_SIZE_MAX, +}; + static int apple_sart_probe(struct platform_device *pdev) { int i; @@ -376,6 +417,10 @@ static const struct of_device_id apple_sart_of_match[] = { .compatible = "apple,t6000-sart", .data = &sart_ops_v3, }, + { + .compatible = "apple,t8152-sart", + .data = &sart_ops_v4, + }, { .compatible = "apple,t8103-sart", .data = &sart_ops_v2, diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index c6625c5cbb5d3f..ced73a28032f2f 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -133,6 +133,8 @@ struct apple_cio_hw { bool mxwrap; bool lstx_explicit; bool strict_fw_ready; + /* M3_STAT never becomes ready; a poll timeout is not fatal. */ + bool m3_stat_optional; const struct apple_dpin_policy *dp; }; @@ -156,6 +158,19 @@ static const struct apple_cio_hw apple_cio_t8142_hw = { .dp = &apple_dpin_disabled, }; +/* + * T8152 starts the ACIO CPU through the same coprocessor wrapper block as + * t6030 (the "cpu" region: run control +0x28, idle status +0x44), and its + * rc M3_CTRL start bit is not decoded, so the wrapper drives the start. + * M3_STAT never becomes ready; the RTKit boot of the co-processor is the + * readiness check. + */ +static const struct apple_cio_hw apple_cio_t8152_hw = { + .mxwrap = true, + .m3_stat_optional = true, + .dp = &apple_dpin_disabled, +}; + #define APPLE_CIO_NHI_HOP_COUNT 0x0 #define APPLE_CIO_NHI_HOP_COUNT_MASK GENMASK(9, 0) @@ -1236,7 +1251,14 @@ static void apple_nhi_ring_configure(struct tb_ring *ring, u32 flags, u32 e2e_fl options += APPLE_CIO_NHI_RXRING_DESC_BASE; sof_eof_mask = ring->sof_mask << 16 | ring->eof_mask; - writel(sof_eof_mask, options + 4); + /* + * T8152 has no PDF range (the ACIO+0xdb0000 block of the M1/M2 DT + * aborts on a read) and macOS never writes RX options + 4 there: + * without a "pdf" range only the ring options are programmed. Type 7 + * keeps the masks in the receive ring registers. + */ + if (anhi->pdf_base || (anhi->acio && anhi->acio->type7)) + writel(sof_eof_mask, options + 4); if (anhi->pdf_base) writel(sof_eof_mask, anhi->pdf_base + ring->hop * APPLE_CIO_NHI_PDF_STRIDE); @@ -2037,9 +2059,13 @@ static int apple_nhi_probe(struct platform_device *pdev) } apple_tunable_apply(anhi->nhi_base, tunable); - /* Type 7 keeps the PDF masks in the receive ring registers only. */ - if (!acio->type7) { - res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pdf"); + /* + * The M1/M2 DTs carry a "pdf" range; type 7 keeps the PDF masks in the + * receive ring registers only, and T8152 has no "pdf" range at all + * (see apple_nhi_ring_configure). + */ + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "pdf"); + if (res && !acio->type7) { anhi->pdf_base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(anhi->pdf_base)) { ret = dev_err_probe(&pdev->dev, PTR_ERR(anhi->pdf_base), @@ -2622,7 +2648,7 @@ static int apple_cio_start(struct apple_cio *acio) if (acio->hw->lstx_explicit) { writel(APPLE_CIO_LSTX_CTRL_ENABLE | APPLE_CIO_LSTX_CTRL_LEVEL, acio->rc_base + APPLE_CIO_M3_CTRL); - } else { + } else if (!acio->hw->mxwrap) { val = readl(acio->rc_base + APPLE_CIO_M3_CTRL); writel(val | APPLE_CIO_M3_CTRL_START, acio->rc_base + APPLE_CIO_M3_CTRL); } @@ -2648,17 +2674,25 @@ static int apple_cio_start(struct apple_cio *acio) goto err_free_rtkit; } - if (acio->hw->strict_fw_ready) + state = 0; + if (acio->hw->m3_stat_optional) { + /* + * T8152: M3_STAT is not shown to exist, so do not wait for it; the + * RTKit boot above is the readiness check. + */ + ret = 0; + } else if (acio->hw->strict_fw_ready) { ret = readl_poll_timeout(acio->rc_base + APPLE_CIO_M3_STAT, state, (state & APPLE_CIO_M3_STAT_CODE_VALID) || FIELD_GET(APPLE_CIO_M3_STAT_STATE, state) == APPLE_CIO_M3_STAT_STATE_READY, 100, 500000); - else + } else { ret = readl_poll_timeout(acio->rc_base + APPLE_CIO_M3_STAT, state, acio->type7 ? (state & APPLE_CIO_M3_STAT_STATE) == BIT(24) : (state & APPLE_CIO_M3_STAT_STATE), 100, 500000); + } if (!ret && acio->hw->strict_fw_ready && (state & APPLE_CIO_M3_STAT_CODE_VALID)) { dev_err(acio->dev, "M3 firmware assert, code 0x%06lx (state 0x%08x)\n", FIELD_GET(APPLE_CIO_M3_STAT_CODE, state), state); @@ -3339,6 +3373,10 @@ static const struct of_device_id apple_acio_match[] = { .compatible = "apple,t6020-usb4-acio", .data = &apple_cio_t6020_hw, }, + { + .compatible = "apple,t8152-usb4-acio", + .data = &apple_cio_t8152_hw, + }, { .compatible = "apple,t8103-usb4-acio", .data = &apple_cio_t8103_hw, diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c index f2e6718c3dfc4e..12ee0f33976afe 100644 --- a/drivers/usb/core/hub.c +++ b/drivers/usb/core/hub.c @@ -55,6 +55,8 @@ #define USB_PRODUCT_TUSB8041_USB3 0x8140 #define USB_PRODUCT_TUSB8041_USB2 0x8142 #define USB_VENDOR_MICROCHIP 0x0424 +#define USB_VENDOR_APPLE 0x05ac +#define USB_PRODUCT_APPLE_HUB_800F 0x800f #define USB_PRODUCT_USB4913 0x4913 #define USB_PRODUCT_USB4914 0x4914 #define USB_PRODUCT_USB4915 0x4915 @@ -6251,6 +6253,11 @@ static const struct usb_device_id hub_id_table[] = { | USB_DEVICE_ID_MATCH_PRODUCT, .idVendor = USB_VENDOR_VIA_LABS, .idProduct = USB_PRODUCT_VL122, + .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, + { .match_flags = USB_DEVICE_ID_MATCH_VENDOR + | USB_DEVICE_ID_MATCH_PRODUCT, + .idVendor = USB_VENDOR_APPLE, + .idProduct = USB_PRODUCT_APPLE_HUB_800F, .driver_info = HUB_QUIRK_DISABLE_AUTOSUSPEND}, { .match_flags = USB_DEVICE_ID_MATCH_VENDOR | USB_DEVICE_ID_MATCH_PRODUCT, diff --git a/drivers/usb/dwc3/Kconfig b/drivers/usb/dwc3/Kconfig index c862e55ae3a373..4f5be5ecee5626 100644 --- a/drivers/usb/dwc3/Kconfig +++ b/drivers/usb/dwc3/Kconfig @@ -227,6 +227,7 @@ config USB_DWC3_APPLE depends on OF && ARCH_APPLE default USB_DWC3 select USB_ROLE_SWITCH + select APPLE_TUNABLE help Support Apple Silicon SoCs with DesignWare Core USB3 IP. The DesignWare Core USB3 IP has to be used in dual-role diff --git a/drivers/usb/dwc3/dwc3-apple.c b/drivers/usb/dwc3/dwc3-apple.c index 464e5d9e691fe3..55e9a49a4e23d7 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -13,12 +13,15 @@ #include #include #include +#include #include #include +#include #include #include "dwc3-apple-state.h" #include "glue.h" +#include "io.h" /* * This platform requires a very specific sequence of operations to bring up dwc3 and its USB3 PHY: @@ -86,6 +89,13 @@ * dwc3_apple_init(). In host mode xHCI then keeps running in suspend-to-idle when a USB device * may wake the system, as a halted xHC could not signal the wakeup. * + * The T8152 USB2-only profile starts a fixed host, without a physical hub, or — + * with dr_mode = "peripheral" on the debug-cable port — a fixed peripheral. A + * fixed peripheral programs the pipe handler with the m1n1 device-console + * sequence (mux to the dummy backend, DWC3 reset released, device non-selected + * override word) and applies only the default calibration lists plus the USB2 + * PHY device calibration; the host lists stay unused. + * * enum dwc3_apple_state is defined in dwc3-apple-state.h. */ @@ -100,7 +110,11 @@ * sets host mode * @usb3_phy: USB3 PHY, configured after the core is brought up * @role_sw: USB role switch - * @fixed_hub: A fixed hub sits on the controller's USB2 port, the controller stays in host mode + * @fixed_hub: A physical hub child node sits on the controller's USB2 port + * @t8152_usb2: T8152 fixed-role calibration and USB2-only PHY profile + * @fixed_peripheral: T8152 started as a fixed peripheral (dr_mode = "peripheral") + * @tunable_regs: Non-overlapping calibration windows, with the core mapped by dwc3 + * @tunables: Native host calibration lists in application order * @lock: Mutex for synchronizing access * @state: Current state of the controller, see enum dwc3_apple_state and the comment above * @core_active: Core still owns initialized PHYs @@ -121,6 +135,10 @@ struct dwc3_apple { struct phy *usb3_phy; struct usb_role_switch *role_sw; bool fixed_hub; + bool t8152_usb2; + bool fixed_peripheral; + void __iomem *tunable_regs[6]; + struct apple_tunable *tunables[11]; struct mutex lock; @@ -193,6 +211,120 @@ static void dwc3_apple_setup_cio(struct dwc3_apple *appledwc) APPLE_DWC3_CIO_PM_ENTRY_TIMER_VALUE)); } +static const struct { + const char *name; + u8 resource; + u32 offset; + bool optional; + bool host_only; +} t8152_host_tunables[] = { + { "apple,tunable-bulk-fabric-default", 4, 0 }, + { "apple,tunable-pipe-handler-default", 2, 0 }, + { "apple,tunable-pipe-handler-host", 2, 0, true, true }, + { "apple,tunable-pwr-ctrl-default", 3, 0, true }, + { "apple,tunable-drd-usb31-gbl-default", 0, 0xc100 }, + { "apple,tunable-drd-usb31-gbl-host", 0, 0xc100, false, true }, + { "apple,tunable-drd-cio-regs-default", 1, 0x20, true }, + { "apple,tunable-drd-usb31-dbg-default", 1, 0xb00 }, + { "apple,tunable-drd-usb31-cfg-host", 1, 0x3300, false, true }, + { "apple,tunable-link-regs-default", 1, 0x300 }, + { "apple,tunable-ausbc-debug-default", 5, 0 }, +}; + +static int dwc3_apple_t8152_parse_tunables(struct platform_device *pdev, + struct dwc3_apple *appledwc) +{ + static const char * const names[] = { + "dwc3-core", "dwc3-apple", "pipe-handler", + "pwr-ctrl", "bulk-fabric", "ausbc-debug", + }; + struct device *dev = &pdev->dev; + struct resource *resources[ARRAY_SIZE(names)]; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(names); i++) { + resources[i] = platform_get_resource_byname(pdev, IORESOURCE_MEM, names[i]); + if (!resources[i]) + return dev_err_probe(dev, -EINVAL, "Missing %s MMIO\n", names[i]); + if (i < 2) + continue; + appledwc->tunable_regs[i] = devm_ioremap_resource(dev, resources[i]); + if (IS_ERR(appledwc->tunable_regs[i])) + return PTR_ERR(appledwc->tunable_regs[i]); + } + if (resource_size(resources[0]) != 0xcd00 || + resource_size(resources[1]) < 0x4b00 || + resources[1]->start != resources[0]->start + 0xcd00 || + resource_size(resources[2]) < 0x24) + return dev_err_probe(dev, -EINVAL, "Invalid T8152 register windows\n"); + appledwc->tunable_regs[1] = appledwc->apple_regs; + + for (i = 0; i < ARRAY_SIZE(t8152_host_tunables); i++) { + struct resource window = *resources[t8152_host_tunables[i].resource]; + struct apple_tunable *tunable; + + /* A fixed peripheral never applies the host-only lists, so they may be absent. */ + if (appledwc->fixed_peripheral && t8152_host_tunables[i].host_only) + continue; + if (resource_size(&window) <= t8152_host_tunables[i].offset) + return -EINVAL; + window.start += t8152_host_tunables[i].offset; + tunable = devm_apple_tunable_parse(dev, dev->of_node, + t8152_host_tunables[i].name, &window); + if (IS_ERR(tunable)) { + if (PTR_ERR(tunable) == -ENOENT && t8152_host_tunables[i].optional) + continue; + return dev_err_probe(dev, PTR_ERR(tunable), "Invalid %s\n", + t8152_host_tunables[i].name); + } + appledwc->tunables[i] = tunable; + } + return 0; +} + +/* + * T8152 pipe handler registers programmed by m1n1 src/usb.c usb_phy_bringup() + * for the USB2 device console: route the mux to the dummy backend, release the + * DWC3 reset, and write the whole non-selected override word. + */ +#define T8152_PIPE_MUX_CTRL 0x0c +#define T8152_PIPE_AON_GEN 0x1c +#define T8152_PIPE_NONSELECTED_OVERRIDE 0x20 +#define T8152_PIPE_MUX_CTRL_DUMMY 0x22 +#define T8152_PIPE_AON_GEN_DWC3_RESET_N BIT(0) +#define T8152_PIPE_NONSELECTED_DEVICE 0x9332 + +static void dwc3_apple_t8152_apply_tunables(struct dwc3_apple *appledwc, + enum dwc3_apple_state state) +{ + bool device = state == DWC3_APPLE_DEVICE; + void __iomem *pipe = appledwc->tunable_regs[2]; + unsigned int i; + u32 value; + + for (i = 0; i < ARRAY_SIZE(t8152_host_tunables); i++) { + u8 resource = t8152_host_tunables[i].resource; + u32 offset = t8152_host_tunables[i].offset; + void __iomem *base = resource ? appledwc->tunable_regs[resource] : + appledwc->dwc.regs; + + if (device && t8152_host_tunables[i].host_only) + continue; + if (!resource) + offset -= DWC3_GLOBALS_REGS_START; + apple_tunable_apply(base + offset, appledwc->tunables[i]); + } + + if (device) + return; + + writel(readl(pipe + 0x20) | BIT(15), pipe + 0x20); + value = dwc3_readl(&appledwc->dwc, 0xc680); + dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); + value = dwc3_readl(&appledwc->dwc, 0xc680); + dwc3_writel(&appledwc->dwc, 0xc680, value & ~BIT(13)); +} + static void dwc3_apple_set_ptrcap(struct dwc3_apple *appledwc, u32 mode) { guard(spinlock_irqsave)(&appledwc->dwc.lock); @@ -374,7 +506,40 @@ static int dwc3_apple_core_start(struct dwc3_apple *appledwc, enum dwc3_apple_st appledwc->reset_pending = true; /* Keep register access powered until both PHY shutdown and reset finish. */ dev_pm_syscore_device(appledwc->dev, true); + + if (appledwc->t8152_usb2) { + void __iomem *pipe = appledwc->tunable_regs[2]; + + if (state == DWC3_APPLE_DEVICE) { + writel(T8152_PIPE_MUX_CTRL_DUMMY, pipe + T8152_PIPE_MUX_CTRL); + writel(T8152_PIPE_NONSELECTED_DEVICE, pipe + T8152_PIPE_NONSELECTED_OVERRIDE); + } + /* + * The AON block gates every DWC3 core register with its reset. + * dwc3_core_probe() reads GSNPSID/GHWPARAMS first, so the reset + * must be released here for the host role too, not only for the + * peripheral (verified on port 1; port 2 returned garbage on the + * first hardware run without this). + */ + writel(T8152_PIPE_AON_GEN_DWC3_RESET_N, pipe + T8152_PIPE_AON_GEN); + } + + if (appledwc->t8152_usb2) { + ret = phy_init(appledwc->usb2_phy); + if (ret) + goto err_stop; + ret = phy_power_on(appledwc->usb2_phy); + if (ret) { + phy_exit(appledwc->usb2_phy); + goto err_stop; + } + } + ret = dwc3_apple_core_init(appledwc); + if (appledwc->t8152_usb2) { + phy_power_off(appledwc->usb2_phy); + phy_exit(appledwc->usb2_phy); + } if (ret) { ret_reset = dwc3_apple_core_stop(appledwc); if (ret_reset) @@ -392,6 +557,12 @@ static int dwc3_apple_core_start(struct dwc3_apple *appledwc, enum dwc3_apple_st appledwc->usb3_power_off_pending = BIT(appledwc->dwc.num_usb3_ports) - 1; return 0; + +err_stop: + ret_reset = dwc3_apple_core_stop(appledwc); + if (ret_reset) + dev_warn(appledwc->dev, "Failed to finish core shutdown, err=%d\n", ret_reset); + return ret; } /* Select the role in the core and route the USB3 PHY, before xhci or the gadget is started */ @@ -414,6 +585,27 @@ static void dwc3_apple_set_role(struct dwc3_apple *appledwc, enum dwc3_apple_sta ret = phy_set_mode(appledwc->usb3_phy, host ? PHY_MODE_USB_HOST : PHY_MODE_USB_DEVICE); if (ret) dev_warn(appledwc->dev, "USB3 PHY setup failed, USB2 only, err=%d\n", ret); + if (appledwc->t8152_usb2) + dwc3_apple_t8152_apply_tunables(appledwc, state); +} + +/* + * A T8152 controller never switches roles: it starts as a fixed host (with or + * without a hub child) or — with dr_mode = "peripheral" — as a fixed + * peripheral. Returns false for the dynamic-role profiles. + */ +static bool dwc3_apple_fixed_state(const struct dwc3_apple *appledwc, + enum dwc3_apple_state *state) +{ + if (appledwc->fixed_peripheral) { + *state = DWC3_APPLE_DEVICE; + return true; + } + if (appledwc->fixed_hub || appledwc->t8152_usb2) { + *state = DWC3_APPLE_HOST; + return true; + } + return false; } static int dwc3_apple_init(struct dwc3_apple *appledwc, enum dwc3_apple_state state) @@ -505,6 +697,16 @@ static int dwc3_usb_role_switch_set(struct usb_role_switch *sw, enum usb_role ro if (appledwc->fixed_hub) return 0; + if (appledwc->t8152_usb2) { + enum usb_role fixed_role = appledwc->fixed_peripheral ? + USB_ROLE_DEVICE : USB_ROLE_HOST; + if (role != fixed_role) { + dev_err(appledwc->dev, "Invalid target role: %d\n", role); + return -EINVAL; + } + return 0; + } + /* * Skip role switches if appledwc is already in the desired state. The * USB-C port controller on M2 and M1/M2 Pro/Max/Ultra devices issues @@ -590,6 +792,7 @@ static bool dwc3_apple_has_fixed_hub(struct device *dev) static int dwc3_apple_probe(struct platform_device *pdev) { + enum dwc3_apple_state fixed_state; struct device *dev = &pdev->dev; struct dwc3_apple *appledwc; int ret; @@ -599,10 +802,24 @@ static int dwc3_apple_probe(struct platform_device *pdev) return -ENOMEM; appledwc->dev = &pdev->dev; + appledwc->t8152_usb2 = of_device_is_compatible(dev->of_node, "apple,t8152-dwc3"); appledwc->fixed_hub = dwc3_apple_has_fixed_hub(dev); + if (appledwc->t8152_usb2) { + enum usb_dr_mode dr_mode = usb_get_dr_mode(dev); + + if ((dr_mode != USB_DR_MODE_HOST && dr_mode != USB_DR_MODE_PERIPHERAL) || + usb_get_maximum_speed(dev) != USB_SPEED_HIGH) + return dev_err_probe(dev, -EINVAL, + "T8152 requires dr_mode = \"host\" or \"peripheral\" and maximum-speed = \"high-speed\"\n"); + appledwc->fixed_peripheral = dr_mode == USB_DR_MODE_PERIPHERAL; + if (appledwc->fixed_peripheral && appledwc->fixed_hub) + return dev_err_probe(dev, -EINVAL, + "A hub child node requires dr_mode = \"host\"\n"); + } mutex_init(&appledwc->lock); - appledwc->reset = devm_reset_control_get_exclusive(dev, NULL); + if (!appledwc->t8152_usb2) + appledwc->reset = devm_reset_control_get_exclusive(dev, NULL); if (IS_ERR(appledwc->reset)) return dev_err_probe(&pdev->dev, PTR_ERR(appledwc->reset), "Failed to get reset control\n"); @@ -612,7 +829,8 @@ static int dwc3_apple_probe(struct platform_device *pdev) return dev_err_probe(dev, PTR_ERR(appledwc->usb2_phy), "Failed to get the USB2 PHY\n"); - appledwc->usb3_phy = devm_phy_get(dev, "usb3-phy"); + if (!appledwc->t8152_usb2) + appledwc->usb3_phy = devm_phy_get(dev, "usb3-phy"); if (IS_ERR(appledwc->usb3_phy)) return dev_err_probe(dev, PTR_ERR(appledwc->usb3_phy), "Failed to get the USB3 PHY\n"); @@ -633,6 +851,11 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (IS_ERR(appledwc->apple_regs)) return dev_err_probe(dev, PTR_ERR(appledwc->apple_regs), "Failed to map Apple-specific MMIO\n"); + if (appledwc->t8152_usb2) { + ret = dwc3_apple_t8152_parse_tunables(pdev, appledwc); + if (ret) + return ret; + } /* * Like a PCI xHCI controller, allow USB devices to wake the system by default. This has @@ -654,16 +877,11 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (ret) return dev_err_probe(&pdev->dev, ret, "Failed to setup role switch\n"); - if (!appledwc->fixed_hub) + if (!dwc3_apple_fixed_state(appledwc, &fixed_state)) return 0; - /* - * The hub is the controller's permanent USB2 peer, and the PHY has kept - * its USB2 path up for it since its own probe, so there is nothing to - * wait for: bring the host up now. - */ scoped_guard(mutex, &appledwc->lock) - ret = dwc3_apple_init(appledwc, DWC3_APPLE_HOST); + ret = dwc3_apple_init(appledwc, fixed_state); if (ret) { /* A failed cleanup remains visible even when probe cannot be retried. */ if (appledwc->core_active || appledwc->reset_pending) @@ -671,7 +889,8 @@ static int dwc3_apple_probe(struct platform_device *pdev) if (appledwc->state != DWC3_APPLE_PROBE_PENDING) dwc3_core_remove_no_shutdown(&appledwc->dwc); usb_role_switch_unregister(appledwc->role_sw); - return dev_err_probe(dev, ret, "Failed to start host mode\n"); + return dev_err_probe(dev, ret, "Failed to start fixed %s mode\n", + fixed_state == DWC3_APPLE_DEVICE ? "peripheral" : "host"); } return 0; @@ -699,6 +918,7 @@ static void dwc3_apple_remove(struct platform_device *pdev) static const struct of_device_id dwc3_apple_of_match[] = { { .compatible = "apple,t8103-dwc3" }, + { .compatible = "apple,t8152-dwc3" }, {} }; MODULE_DEVICE_TABLE(of, dwc3_apple_of_match);