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/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-atcphy.yaml b/Documentation/devicetree/bindings/phy/apple,t8152-atcphy.yaml new file mode 100644 index 00000000000000..5de8026179381c --- /dev/null +++ b/Documentation/devicetree/bindings/phy/apple,t8152-atcphy.yaml @@ -0,0 +1,129 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/phy/apple,t8152-atcphy.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Apple T8152 Type-C PHY (SuperSpeed and USB4 lanes) + +maintainers: + - Joshua Warren <816217+joshuaswarren@users.noreply.github.com> + +description: | + The SuperSpeed / USB4 side of one ATC port of the Apple M6 (T8152). The USB2 + side of the same port is apple,t8152-usb2-phy. The PHY serves one transport + at a time: USB3 for the dwc3 controller of the port, or CIO (USB4 / + Thunderbolt) for the ACIO controller. Changing the transport shuts the PHY + down and brings it up again. + + Firmware supplies the calibration. Every native tunable list of the ADT atc-phy + node that the bring-up applies is passed as apple,tunable-, where + is the ADT list name without the "tunable_" prefix, lower case, with "_" + replaced by "-" (for example tunable_LN0_SMGR_REGS_CIO becomes + apple,tunable-ln0-smgr-regs-cio). Offsets are relative to the register block + the list belongs to (the driver knows the blocks). A list the ADT does not + carry is left out. The two efuse lists apple,tunable-aciophy-cmn-dflt and + apple,tunable-ciopll-core-dflt carry the factory calibration; a PHY without + them is not calibrated. + +$defs: + tunable: + $ref: /schemas/types.yaml#/definitions/uint32-matrix + items: + items: + - description: Aligned byte offset within the register block of the list + - description: Bits to clear + - description: Bits to set + +properties: + compatible: + const: apple,t8152-atcphy + + reg: + items: + - description: PHY core window (ADT atc-phy reg[2], 0x84000 bytes) + + reg-names: + items: + - const: core + + apple,dwc3: + $ref: /schemas/types.yaml#/definitions/phandle + description: | + The dwc3 node of the port. The PHY uses its "pipe-handler" window (usb-drd + reg[3], the PIPE mux it routes) and the PIPE_PHY_READY word (usb-drd reg[1], + 0x10000 above the "dwc3-core" window, inside the node's "dwc3-apple" + window). They are not resources of this node because the dwc3 node already + owns those ranges and the platform bus rejects equal or partly overlapping + ranges. + + '#phy-cells': + const: 1 + description: | + 0 selects the USB3 PHY (dwc3-apple, set_mode(HOST) routes the PIPE and + brings the PHY up), 1 the CIO PHY (thunderbolt_apple, power_on/power_off). + + power-domains: + minItems: 2 + maxItems: 2 + description: + The USB AON domain (ps_atc*_usb_aon) and the ATC USB domain + (psd_atc*_usb) of the port, in this order. + + power-domain-names: + items: + - const: usb-aon + - const: usb + + orientation-switch: + type: boolean + description: Register a Type-C orientation switch (the connector node points at it). + + apple,cio-lanes: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [1, 2, 3] + default: 3 + description: Lane mask of the CIO bring-up, bit 0 lane 0 and bit 1 lane 1. + +patternProperties: + '^apple,tunable-[a-z0-9-]+$': + $ref: '#/$defs/tunable' + +required: + - compatible + - reg + - reg-names + - apple,dwc3 + - '#phy-cells' + +additionalProperties: false + +examples: + - | + soc { + #address-cells = <2>; + #size-cells = <2>; + + ps_atc2_usb_aon: power-controller-aon { + #power-domain-cells = <0>; + }; + + psd_atc2_usb: power-controller-usb { + #power-domain-cells = <0>; + }; + + usbdrd2: usb@382430000 { + reg = <0x3 0x82430000 0x0 0xcd00>; + }; + + phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <0x3 0x83000000 0x0 0x84000>; + reg-names = "core"; + apple,dwc3 = <&usbdrd2>; + #phy-cells = <1>; + power-domains = <&ps_atc2_usb_aon>, <&psd_atc2_usb>; + power-domain-names = "usb-aon", "usb"; + orientation-switch; + }; + }; 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/usb/apple,t8152-dwc3.yaml b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml new file mode 100644 index 00000000000000..b3790d818de301 --- /dev/null +++ b/Documentation/devicetree/bindings/usb/apple,t8152-dwc3.yaml @@ -0,0 +1,105 @@ +# 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. + A port is USB2-only unless the board also describes the SuperSpeed PHY of + the port (apple,t8152-atcphy) as a second entry, named usb3-phy; without + that entry the controller ignores the USB3 side of the port. + 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: + minItems: 1 + maxItems: 2 + + phy-names: + minItems: 1 + items: + - const: usb2-phy + - const: usb3-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-atcphy.dtsi b/arch/arm64/boot/dts/apple/t8152-j873-atcphy.dtsi new file mode 100644 index 00000000000000..a019791fba3f1e --- /dev/null +++ b/arch/arm64/boot/dts/apple/t8152-j873-atcphy.dtsi @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * Apple T8152 (M6) Mac mini J873: SuperSpeed / USB4 PHYs of the ATC ports + * (apple,t8152-atcphy). + * + * Source: the firmware device tree, nodes atc-phy2 / usb-drd2 and atc-phy3 / + * usb-drd3. Addresses are the firmware regs plus 0x200000000: + * atc-phy reg[2] = PHY core window (xbar, CMN, CIOPLL, lane AON, PIPE/BIST, + * PCS, power block, ATC fabric; the USB DART banks sit + * inside it) + * The dwc3 PIPE handler (usb-drd reg[3]) and the PIPE_PHY_READY word + * (usb-drd reg[1]) are found through apple,dwc3: the dwc3 node owns those + * ranges. + * No tunables here: the boot loader passes every apple,tunable- list of + * the ADT atc-phy node (see the binding). + * + * Both nodes are disabled: the SuperSpeed link of the front port (atcphy2) is + * not verified yet, and atcphy3 serves the ACIO controller (USB4 tunnel nodes + * are not part of this file). Enable per port together with a "usb3-phy" + * reference in the dwc3 node and/or a phys reference in the ACIO node. + * + * Needs: ps_atc2_usb_aon / ps_atc3_usb_aon from t8152-j873-pmgr.dtsi and + * psd_atc2_usb / psd_atc3_usb from t8152-j873g-peripherals.dtsi. + */ + +/ { + soc { + atcphy2: phy@383000000 { + compatible = "apple,t8152-atcphy"; + reg = <3 0x83000000 0 0x84000>; + reg-names = "core"; + apple,dwc3 = <&usbdrd2>; + #phy-cells = <1>; + power-domains = <&ps_atc2_usb_aon>, <&psd_atc2_usb>; + power-domain-names = "usb-aon", "usb"; + status = "disabled"; + }; + + atcphy3: phy@413000000 { + compatible = "apple,t8152-atcphy"; + reg = <4 0x13000000 0 0x84000>; + reg-names = "core"; + apple,dwc3 = <&usbdrd3>; + #phy-cells = <1>; + orientation-switch; + power-domains = <&ps_atc3_usb_aon>, <&psd_atc3_usb>; + power-domain-names = "usb-aon", "usb"; + status = "disabled"; + }; + }; +}; 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.dts b/arch/arm64/boot/dts/apple/t8152-j873g.dts index 6b5e14036c98af..d226b7dacbf291 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-j873-atcphy.dtsi" diff --git a/drivers/iommu/apple-dart.c b/drivers/iommu/apple-dart.c index f2e7aee54e5978..3774cf0866977d 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); @@ -477,6 +496,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) @@ -1311,6 +1332,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) @@ -1360,7 +1419,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) @@ -1378,6 +1438,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, @@ -1472,7 +1539,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); @@ -1545,7 +1613,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 @@ -2035,6 +2104,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; @@ -2076,6 +2148,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); @@ -2107,6 +2185,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); @@ -2133,10 +2217,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; } @@ -2808,7 +2898,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; @@ -2852,6 +2942,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)); } /* @@ -2868,7 +2968,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, @@ -2890,11 +2991,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; @@ -2902,6 +3008,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)) @@ -2951,10 +3068,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; @@ -2970,6 +3218,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"); @@ -2982,6 +3232,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); /* @@ -3006,7 +3257,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)) { @@ -3022,10 +3273,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) @@ -3051,6 +3318,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) { @@ -3084,30 +3361,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; @@ -3193,30 +3450,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)); @@ -3227,7 +3497,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, @@ -3239,7 +3510,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); @@ -3354,13 +3626,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); } @@ -3473,12 +3749,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. */ @@ -3567,6 +3874,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; @@ -3633,6 +3944,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..efbcc3323cb2f9 100644 --- a/drivers/phy/apple/Kconfig +++ b/drivers/phy/apple/Kconfig @@ -40,3 +40,26 @@ 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. + +config PHY_APPLE_T8152_ATC + tristate "Apple T8152 Type-C PHY (SuperSpeed and USB4 lanes)" + depends on (ARCH_APPLE || COMPILE_TEST) && OF + depends on TYPEC + select GENERIC_PHY + select APPLE_TUNABLE + help + Enable the SuperSpeed and USB4 (CIO) side of the ATC ports of the + Apple M6 (T8152). It brings the PHY up for USB3 or CIO, routes the + dwc3 PIPE to it and follows the cable orientation from the Type-C + switch. The USB2 side is PHY_APPLE_T8152_USB2. diff --git a/drivers/phy/apple/Makefile b/drivers/phy/apple/Makefile index b9e7bf3e4ac170..0dd4f3fe25b691 100644 --- a/drivers/phy/apple/Makefile +++ b/drivers/phy/apple/Makefile @@ -5,3 +5,9 @@ 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 + +obj-$(CONFIG_PHY_APPLE_T8152_ATC) += phy-apple-t8152-atc.o +phy-apple-t8152-atc-y := atc-t8152.o diff --git a/drivers/phy/apple/atc-t8152-seq.h b/drivers/phy/apple/atc-t8152-seq.h new file mode 100644 index 00000000000000..e598f88a0f9951 --- /dev/null +++ b/drivers/phy/apple/atc-t8152-seq.h @@ -0,0 +1,370 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* + * Apple T8152 (M6) ATC PHY: register sequences, in the order the vendor driver runs them. + * Kept free of driver glue so the same code can be run against a fake memory. + * + * All offsets are relative to the 'core' window (ADT atc-phy reg[2], 0x84000 bytes) unless a + * function takes the pipe handler or config window. + * Block layout: XBAR 0x0, ACIOPHY_CMN 0x800, CIOPLL core 0x1600, lane AON 0x1e00, + * PIPE/BIST 0x2400, USB PCS 0x15c00, POWER 0x60000, ATC_FABRIC 0x6c000. + */ +#ifndef _ATC_T8152_SEQ_H +#define _ATC_T8152_SEQ_H + +#include +#include +#include +#include +#include + +#include "atc-t8152-tables.h" + +#define T8152_XBAR 0x0 +#define T8152_XBAR_PROTO 0x4c +#define T8152_LANE 0x1e00 +#define T8152_LANE0_CTRL 0x18 +#define T8152_LANE1_CTRL 0x1c +#define T8152_LANE_FINAL 0x24 +#define T8152_PIPE 0x2400 +#define T8152_POWER 0x60000 +#define T8152_PWR0 0x00 +#define T8152_PWR1 0x04 +#define T8152_PWR_SPARE 0x08 +#define T8152_PWR_S2R_SYNC 0x30 + +#define T8152_PWR0_SML_IN BIT(0) +#define T8152_PWR0_BIG_IN BIT(1) +#define T8152_PWR0_BIT2 BIT(2) +#define T8152_PWR0_CLAMP_EN BIT(3) +#define T8152_PWR0_RESET_N BIT(4) +#define T8152_PWR1_SML_OUT BIT(0) +#define T8152_PWR1_BIG_OUT BIT(1) + +#define T8152_PIPE_CTRL 0x00 +#define T8152_PIPE_STROBE 0x0c +#define T8152_PIPE_STATUS 0xa0 +#define T8152_PIPE_OV1 0xb0 +#define T8152_PIPE_OV2 0xb8 + +#define T8152_PH_OVERRIDE 0x00 +#define T8152_PH_OVERRIDE_VALUES 0x04 +#define T8152_PH_MUX 0x0c +#define T8152_PH_LOCK_REQ 0x10 +#define T8152_PH_LOCK_ACK 0x14 +#define T8152_PH_NONSELECTED 0x20 +/* the T8152 live boot value is 0x42: clock field bits 6:4, data bits 2:0 */ +#define T8152_PH_MUX_CLK_SHIFT 4 + +#define T8152_CFG_OFFSET 0x10000 /* usb-drd reg[1] = dwc3 core + 0x10000 */ +#define T8152_CFG_PHY_READY_REG 0x2c +#define T8152_CFG_PHY_READY BIT(30) + +/* Lanes of a CIO bring-up (partB x3): bit 0 lane 0, bit 1 lane 1. */ +#define T8152_LANES_BOTH 3 + +struct t8152_regs { + void __iomem *core; + void __iomem *pipeh; + void __iomem *cfg; /* optional: dwc3 config window (PIPE_PHY_READY) */ +}; + +static inline void t8152_wr(void __iomem *base, u32 off, u32 clear, u32 set) +{ + writel((readl(base + off) & ~clear) | set, base + off); +} + +/* The vendor driver rewrites every record even when the value is unchanged, so this does not use + * apple_tunable_apply(), which skips equal values. + */ +static inline void t8152_apply(const struct t8152_regs *r, + struct apple_tunable *const *tun, unsigned int i) +{ + void __iomem *blk = r->core + t8152_tunables[i].off; + size_t n; + + if (!tun[i]) + return; + for (n = 0; n < tun[i]->sz; n++) + t8152_wr(blk, tun[i]->values[n].offset, + tun[i]->values[n].mask, tun[i]->values[n].value); +} + +static inline void t8152_apply_seq(const struct t8152_regs *r, + struct apple_tunable *const *tun, + const u8 *seq, unsigned int n) +{ + unsigned int i; + + for (i = 0; i < n; i++) + t8152_apply(r, tun, seq[i]); +} + +/* Sleeps between reads: every caller runs under atc->lock, so only for process context. */ +static inline int t8152_poll_us(void __iomem *base, u32 off, u32 bit, + bool want_set, unsigned int timeout_us, unsigned int step_us) +{ + u32 val; + + return read_poll_timeout(readl, val, !!(val & bit) == want_set, + step_us, timeout_us, false, base + off); +} + +/* Stage A: wake the PHY power block. */ +static inline int t8152_powerup_rst(const struct t8152_regs *r) +{ + void __iomem *p = r->core + T8152_POWER; + int ret; + + t8152_wr(p, T8152_PWR_S2R_SYNC, 0, BIT(0)); + usleep_range(1000, 2000); + t8152_wr(p, T8152_PWR0, 0, T8152_PWR0_SML_IN); + ret = t8152_poll_us(p, T8152_PWR1, T8152_PWR1_SML_OUT, true, 1000000, 1); + if (ret) + return ret; + t8152_wr(p, T8152_PWR0, 0, T8152_PWR0_BIG_IN); + ret = t8152_poll_us(p, T8152_PWR1, T8152_PWR1_BIG_OUT, true, 1000000, 1); + if (ret) + return ret; + t8152_wr(p, T8152_PWR0, T8152_PWR0_BIT2, 0); + usleep_range(1000, 2000); + t8152_wr(p, T8152_PWR0, 0, T8152_PWR0_CLAMP_EN); + return 0; +} + +/* Stage C: power up one lane (bit 5 of the lane control register is the AHB reset). */ +static inline void t8152_lane_up(const struct t8152_regs *r, unsigned int lane) +{ + void __iomem *a = r->core + T8152_LANE; + u32 ctrl = lane ? T8152_LANE1_CTRL : T8152_LANE0_CTRL; + + t8152_wr(a, T8152_LANE_FINAL, 0, lane ? 0x4000 : 0x1000); + t8152_wr(a, T8152_LANE_FINAL, 0, lane ? 0x40000 : 0x10000); + t8152_wr(a, ctrl, 0, 0x2); + t8152_wr(a, ctrl, 0, 0x4); + t8152_wr(a, ctrl, 0x1, 0); + t8152_wr(a, ctrl, 0, BIT(5)); +} + +/* SPARE_REGISTERS_0 bit 1 follows the orientation flag; then ACIOPHY_RESET_N is deasserted. */ +static inline void t8152_release_reset(const struct t8152_regs *r, bool flag) +{ + void __iomem *p = r->core + T8152_POWER; + + t8152_wr(p, T8152_PWR_SPARE, 0x2, flag ? 0x2 : 0); + t8152_wr(p, T8152_PWR0, 0, T8152_PWR0_RESET_N); + usleep_range(1000, 2000); +} + +/* USB3 transport (4): one lane, crossbar 0x110 (normal) or 0x111 (swapped), USB tunable lists. */ +static inline int t8152_up_usb3(const struct t8152_regs *r, + struct apple_tunable *const *tun, bool swap) +{ + int ret; + + ret = t8152_powerup_rst(r); + if (ret) + return ret; + t8152_apply_seq(r, tun, t8152_seq_efuse, ARRAY_SIZE(t8152_seq_efuse)); + t8152_lane_up(r, swap); + usleep_range(1000, 2000); + t8152_wr(r->core + T8152_XBAR, T8152_XBAR_PROTO, 0x1ffff, swap ? 0x111 : 0x110); + t8152_apply_seq(r, tun, t8152_seq_usb3, ARRAY_SIZE(t8152_seq_usb3)); + t8152_release_reset(r, swap); + return 0; +} + +/* CIO / USB4 transport (2): lanes from the bit mask, crossbar low 5 bits = orientation, CIO + * tunable lists. + */ +static inline int t8152_up_cio(const struct t8152_regs *r, + struct apple_tunable *const *tun, bool flag, unsigned int lanes) +{ + int ret; + + ret = t8152_powerup_rst(r); + if (ret) + return ret; + t8152_apply_seq(r, tun, t8152_seq_efuse, ARRAY_SIZE(t8152_seq_efuse)); + if (lanes & BIT(0)) + t8152_lane_up(r, 0); + if (lanes & BIT(1)) + t8152_lane_up(r, 1); + usleep_range(1000, 2000); + t8152_wr(r->core + T8152_XBAR, T8152_XBAR_PROTO, 0x1f, flag ? 1 : 0); + t8152_apply_seq(r, tun, t8152_seq_cio, ARRAY_SIZE(t8152_seq_cio)); + t8152_release_reset(r, flag); + return 0; +} + +/* + * Stage H, PIPE/BIST override enable: the PIPE overrides the USB3 link needs, held for the whole + * attach (the vendor driver only releases them on power-down). Returns -ETIMEDOUT if the PHY + * never reports ready (STATUS bit 6). The two waits on STATUS bit 7 are best effort: a timeout + * there does not stop the bring-up. + */ +static inline int t8152_pipe_override_enable(const struct t8152_regs *r) +{ + void __iomem *q = r->core + T8152_PIPE; + int ret; + + t8152_wr(q, T8152_PIPE_CTRL, 0, 0x1); + t8152_wr(q, T8152_PIPE_OV1, 0x1a0, 0x41); + t8152_wr(q, T8152_PIPE_OV2, 0x440, 0x220); + t8152_wr(q, T8152_PIPE_CTRL, 0, 0x40); + t8152_wr(q, T8152_PIPE_CTRL, 0x40, 0); + t8152_poll_us(q, T8152_PIPE_STATUS, BIT(7), false, 20000, 50); + t8152_wr(q, T8152_PIPE_STROBE, 0, 0x1); + t8152_wr(q, T8152_PIPE_STROBE, 0x1, 0); + t8152_wr(q, T8152_PIPE_OV1, 0, 0x60); + t8152_wr(q, T8152_PIPE_OV2, 0, 0x200); + t8152_wr(q, T8152_PIPE_CTRL, 0, 0x40); + t8152_wr(q, T8152_PIPE_CTRL, 0x40, 0); + ret = t8152_poll_us(q, T8152_PIPE_STATUS, BIT(6), true, 130000, 50); + t8152_poll_us(q, T8152_PIPE_STATUS, BIT(7), false, 1000, 50); + t8152_wr(q, T8152_PIPE_STROBE, 0, 0x1); + t8152_wr(q, T8152_PIPE_STROBE, 0x1, 0); + return ret; +} + +/* Stage 5: route the dwc3 PIPE from the dummy backend to the USB3 PHY, like + * atcphy_configure_pipehandler_usb3(host) in atc.c. *routed is set as soon as the mux points at + * the PHY, before the waits: their failure leaves the route in place, so the caller must park it + * at shutdown. + */ +static inline int t8152_pipehandler_usb3_host(const struct t8152_regs *r, bool *routed) +{ + void __iomem *h = r->pipeh; + int ret; + + *routed = false; + if (readl(h + T8152_PH_LOCK_ACK) & 1) { + t8152_wr(h, T8152_PH_LOCK_REQ, 0x1, 0); + ret = t8152_poll_us(h, T8152_PH_LOCK_ACK, BIT(0), false, 1000, 50); + if (ret) + return ret; + } + t8152_wr(h, T8152_PH_OVERRIDE_VALUES, BIT(1) | BIT(2), 0); + t8152_wr(h, T8152_PH_OVERRIDE, 0, BIT(0)); + t8152_wr(h, T8152_PH_OVERRIDE, 0, BIT(2)); + t8152_wr(h, T8152_PH_LOCK_REQ, 0, 0x1); + ret = t8152_poll_us(h, T8152_PH_LOCK_ACK, BIT(0), true, 1000, 50); + if (ret) { + t8152_wr(h, T8152_PH_LOCK_REQ, 0x1, 0); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(0) | BIT(2), 0); + return ret; + } + t8152_wr(h, T8152_PH_NONSELECTED, 0xf, 0x3); + t8152_wr(h, T8152_PH_NONSELECTED, BIT(12), 0); + t8152_wr(h, T8152_PH_MUX, 0x7 << T8152_PH_MUX_CLK_SHIFT, 0); + udelay(10); + t8152_wr(h, T8152_PH_MUX, GENMASK(2, 0), 0); + udelay(10); + t8152_wr(h, T8152_PH_MUX, 0x7 << T8152_PH_MUX_CLK_SHIFT, 1 << T8152_PH_MUX_CLK_SHIFT); + *routed = true; + udelay(10); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(0), 0); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(2), 0); + t8152_wr(h, T8152_PH_LOCK_REQ, 0x1, 0); + return t8152_poll_us(h, T8152_PH_LOCK_ACK, BIT(0), false, 1000, 50); +} + +/* The vendor driver waits for PIPE_PHY_READY whenever the mux is not on the dummy backend. Safe + * to repeat while the route stands: a second set_mode(HOST) after a failed wait re-runs it. + */ +static inline int t8152_pipehandler_usb3_ready(const struct t8152_regs *r) +{ + if (!r->cfg) + return 0; + return t8152_poll_us(r->cfg, T8152_CFG_PHY_READY_REG, T8152_CFG_PHY_READY, + true, 100000, 50); +} + +/* + * Power-down, in the order of the vendor driver (it shuts the PHY down before every transport + * change and then re-runs the whole bring-up, so a mode switch is shutdown + up): + * aux shutdown: lane AON +0x24 |= 0x400, &= ~0x40, &= ~0x100 (1 us after each) + * lane AON +0x24 &= ~0x1000, ~0x10000, ~0x4000, ~0x40000 (the LFPS FINAL bits of lane_pwrup) + * lane power-down for lane 0, then lane 1: AHB_RESET_N bit 5 clear, ctrl |= 1, &= ~4, &= ~2 + * (1 us after each) + * POWER +0x0 &= ~0x10 (RESET_N), 1 us, &= ~0x8, |= 0x4, &= ~0x2, wait +0x4 bit 1 clear, + * &= ~0x1, wait +0x4 bit 0 clear, POWER +0x30 &= ~0x1 + * The xbar value is left as it is, like the vendor driver. The PIPE overrides are not released + * here, the vendor driver does not release them either. + */ +static inline int t8152_shutdown(const struct t8152_regs *r) +{ + void __iomem *a = r->core + T8152_LANE; + void __iomem *p = r->core + T8152_POWER; + int ret, ret2; + + t8152_wr(a, T8152_LANE_FINAL, 0, 0x400); + udelay(1); + t8152_wr(a, T8152_LANE_FINAL, 0x40, 0); + udelay(1); + t8152_wr(a, T8152_LANE_FINAL, 0x100, 0); + udelay(1); + t8152_wr(a, T8152_LANE_FINAL, 0x1000, 0); + t8152_wr(a, T8152_LANE_FINAL, 0x10000, 0); + t8152_wr(a, T8152_LANE_FINAL, 0x4000, 0); + t8152_wr(a, T8152_LANE_FINAL, 0x40000, 0); + udelay(1); + for (unsigned int lane = 0; lane < 2; lane++) { + u32 ctrl = lane ? T8152_LANE1_CTRL : T8152_LANE0_CTRL; + + t8152_wr(a, ctrl, BIT(5), 0); + udelay(1); + t8152_wr(a, ctrl, 0, 0x1); + udelay(1); + t8152_wr(a, ctrl, 0x4, 0); + udelay(1); + t8152_wr(a, ctrl, 0x2, 0); + udelay(1); + } + t8152_wr(p, T8152_PWR0, T8152_PWR0_RESET_N, 0); + udelay(1); + t8152_wr(p, T8152_PWR0, T8152_PWR0_CLAMP_EN, 0); + t8152_wr(p, T8152_PWR0, 0, T8152_PWR0_BIT2); + t8152_wr(p, T8152_PWR0, T8152_PWR0_BIG_IN, 0); + ret = t8152_poll_us(p, T8152_PWR1, T8152_PWR1_BIG_OUT, false, 1000000, 1); + t8152_wr(p, T8152_PWR0, T8152_PWR0_SML_IN, 0); + ret2 = t8152_poll_us(p, T8152_PWR1, T8152_PWR1_SML_OUT, false, 1000000, 1); + t8152_wr(p, T8152_PWR_S2R_SYNC, 0x1, 0); + return ret ? ret : ret2; +} + +/* + * Route the dwc3 PIPE back to the dummy backend (USB2 only): the mirror of + * t8152_pipehandler_usb3_host() and the order of atcphy_configure_pipehandler_dummy() in atc.c + * with the T8152 mux layout. + */ +static inline int t8152_pipehandler_park(const struct t8152_regs *r) +{ + void __iomem *h = r->pipeh; + int ret; + + t8152_wr(h, T8152_PH_OVERRIDE_VALUES, BIT(1) | BIT(2), 0); + t8152_wr(h, T8152_PH_OVERRIDE, 0, BIT(0)); + t8152_wr(h, T8152_PH_OVERRIDE, 0, BIT(2)); + t8152_wr(h, T8152_PH_LOCK_REQ, 0, 0x1); + ret = t8152_poll_us(h, T8152_PH_LOCK_ACK, BIT(0), true, 1000, 50); + if (ret) { + t8152_wr(h, T8152_PH_LOCK_REQ, 0x1, 0); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(0) | BIT(2), 0); + return ret; + } + t8152_wr(h, T8152_PH_MUX, 0x7 << T8152_PH_MUX_CLK_SHIFT, 0); + udelay(10); + t8152_wr(h, T8152_PH_MUX, GENMASK(2, 0), 2); + udelay(10); + t8152_wr(h, T8152_PH_MUX, 0x7 << T8152_PH_MUX_CLK_SHIFT, 4 << T8152_PH_MUX_CLK_SHIFT); + udelay(10); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(0), 0); + t8152_wr(h, T8152_PH_OVERRIDE, BIT(2), 0); + t8152_wr(h, T8152_PH_LOCK_REQ, 0x1, 0); + ret = t8152_poll_us(h, T8152_PH_LOCK_ACK, BIT(0), false, 1000, 50); + t8152_wr(h, T8152_PH_NONSELECTED, 0xf, 0x2); + t8152_wr(h, T8152_PH_NONSELECTED, 0, BIT(12)); + return ret; +} + +#endif diff --git a/drivers/phy/apple/atc-t8152-tables.h b/drivers/phy/apple/atc-t8152-tables.h new file mode 100644 index 00000000000000..3abd82ca53a433 --- /dev/null +++ b/drivers/phy/apple/atc-t8152-tables.h @@ -0,0 +1,103 @@ +/* SPDX-License-Identifier: GPL-2.0-only OR MIT */ +/* Layout of the T8152 ATC PHY: block offsets and tunable list order. No tunable values: they come from the device tree. */ +#ifndef _ATC_T8152_TABLES_H +#define _ATC_T8152_TABLES_H + +struct t8152_tunable_blk { + const char *prop; /* device tree property holding {offset, mask, value} triples relative to the block */ + u32 off; /* block offset inside the core window */ + u32 len; /* block length, bound for the offsets */ +}; + +#define T8152_NUM_TUNABLES 63 + +static const struct t8152_tunable_blk t8152_tunables[T8152_NUM_TUNABLES] = { + [0] = { "apple,tunable-aciophy-cmn-dflt", 0x800, 0x6c }, /* tunable_ACIOPHY_CMN_DFLT */ + [1] = { "apple,tunable-ciopll-core-dflt", 0x1600, 0x280 }, /* tunable_CIOPLL_CORE_DFLT */ + [2] = { "apple,tunable-atc-fabric", 0x6c000, 0x198 }, /* tunable_ATC_FABRIC */ + [3] = { "apple,tunable-dppll-core-dflt", 0x1000, 0x280 }, /* tunable_DPPLL_CORE_DFLT */ + [4] = { "apple,tunable-dppll-top-dflt", 0xe00, 0x200 }, /* tunable_DPPLL_TOP_DFLT */ + [5] = { "apple,tunable-ciopll-top-dflt", 0x1400, 0x200 }, /* tunable_CIOPLL_TOP_DFLT */ + [6] = { "apple,tunable-aciophy-usbc0-dflt", 0x15c00, 0x98 }, /* tunable_ACIOPHY_USBC0_DFLT */ + [7] = { "apple,tunable-aciophy-usbc0-usb", 0x15c00, 0x98 }, /* tunable_ACIOPHY_USBC0_USB */ + [8] = { "apple,tunable-ln0-arbiter-regs-dflt", 0x8280, 0xfc }, /* tunable_LN0_ARBITER_REGS_DFLT */ + [9] = { "apple,tunable-ln1-arbiter-regs-dflt", 0x11280, 0xfc }, /* tunable_LN1_ARBITER_REGS_DFLT */ + [10] = { "apple,tunable-ln0-rx-top-regs-dflt", 0x8cf0, 0x18 }, /* tunable_LN0_RX_TOP_REGS_DFLT */ + [11] = { "apple,tunable-ln1-rx-top-regs-dflt", 0x11cf0, 0x18 }, /* tunable_LN1_RX_TOP_REGS_DFLT */ + [12] = { "apple,tunable-ln0-rx-dfe-regs-dflt", 0x77c0, 0xe8 }, /* tunable_LN0_RX_DFE_REGS_DFLT */ + [13] = { "apple,tunable-ln1-rx-dfe-regs-dflt", 0x107c0, 0xe8 }, /* tunable_LN1_RX_DFE_REGS_DFLT */ + [14] = { "apple,tunable-ln0-smgr-regs-dflt", 0x7d80, 0x80 }, /* tunable_LN0_SMGR_REGS_DFLT */ + [15] = { "apple,tunable-ln1-smgr-regs-dflt", 0x10d80, 0x80 }, /* tunable_LN1_SMGR_REGS_DFLT */ + [16] = { "apple,tunable-ln0-rxaeq-top-regs-dflt", 0x79c0, 0x23c }, /* tunable_LN0_RXAEQ_TOP_REGS_DFLT */ + [17] = { "apple,tunable-ln1-rxaeq-top-regs-dflt", 0x109c0, 0x23c }, /* tunable_LN1_RXAEQ_TOP_REGS_DFLT */ + [18] = { "apple,tunable-ln0-rx-shm-regs-dflt", 0x8700, 0x194 }, /* tunable_LN0_RX_SHM_REGS_DFLT */ + [19] = { "apple,tunable-ln1-rx-shm-regs-dflt", 0x11700, 0x194 }, /* tunable_LN1_RX_SHM_REGS_DFLT */ + [20] = { "apple,tunable-ln0-txseq-regs-dflt", 0x4c80, 0x84 }, /* tunable_LN0_TXSEQ_REGS_DFLT */ + [21] = { "apple,tunable-ln1-txseq-regs-dflt", 0xdc80, 0x84 }, /* tunable_LN1_TXSEQ_REGS_DFLT */ + [22] = { "apple,tunable-ln0-tx-shm-ahb-dflt", 0x4f90, 0x94 }, /* tunable_LN0_TX_SHM_AHB_DFLT */ + [23] = { "apple,tunable-ln1-tx-shm-ahb-dflt", 0xdf90, 0x94 }, /* tunable_LN1_TX_SHM_AHB_DFLT */ + [24] = { "apple,tunable-ln0-tx-txspl-cm-dflt", 0x4e20, 0x14 }, /* tunable_LN0_TX_TXSPL_CM_DFLT */ + [25] = { "apple,tunable-ln1-tx-txspl-cm-dflt", 0xde20, 0x14 }, /* tunable_LN1_TX_TXSPL_CM_DFLT */ + [26] = { "apple,tunable-ln0-asdc-txspl-cm-dflt", 0x8980, 0x14 }, /* tunable_LN0_ASDC_TXSPL_CM_DFLT */ + [27] = { "apple,tunable-ln1-asdc-txspl-cm-dflt", 0x11980, 0x14 }, /* tunable_LN1_ASDC_TXSPL_CM_DFLT */ + [28] = { "apple,tunable-ln0-div40-regs-dflt", 0x8580, 0x80 }, /* tunable_LN0_DIV40_REGS_DFLT */ + [29] = { "apple,tunable-ln1-div40-regs-dflt", 0x11580, 0x80 }, /* tunable_LN1_DIV40_REGS_DFLT */ + [30] = { "apple,tunable-ln0-rx-pctrl-regs-dflt", 0x8600, 0xec }, /* tunable_LN0_RX_PCTRL_REGS_DFLT */ + [31] = { "apple,tunable-ln1-rx-pctrl-regs-dflt", 0x11600, 0xec }, /* tunable_LN1_RX_PCTRL_REGS_DFLT */ + [32] = { "apple,tunable-ln0-ctle-eq-regs-dflt", 0x7f80, 0x100 }, /* tunable_LN0_CTLE_EQ_REGS_DFLT */ + [33] = { "apple,tunable-ln1-ctle-eq-regs-dflt", 0x10f80, 0x100 }, /* tunable_LN1_CTLE_EQ_REGS_DFLT */ + [34] = { "apple,tunable-l0-rxcalacc-halfui-dflt", 0x7300, 0x80 }, /* tunable_L0_RXCALACC_HALFUI_DFLT */ + [35] = { "apple,tunable-l1-rxcalacc-halfui-dflt", 0x10300, 0x80 }, /* tunable_L1_RXCALACC_HALFUI_DFLT */ + [36] = { "apple,tunable-l0-rxcalacc-edskew-dflt", 0x7280, 0x80 }, /* tunable_L0_RXCALACC_EDSKEW_DFLT */ + [37] = { "apple,tunable-l1-rxcalacc-edskew-dflt", 0x10280, 0x80 }, /* tunable_L1_RXCALACC_EDSKEW_DFLT */ + [38] = { "apple,tunable-ln0-txspl-txdcc-dflt", 0x4d80, 0x40 }, /* tunable_LN0_TXSPL_TXDCC_DFLT */ + [39] = { "apple,tunable-ln1-txspl-txdcc-dflt", 0xdd80, 0x40 }, /* tunable_LN1_TXSPL_TXDCC_DFLT */ + [40] = { "apple,tunable-ln0-smgr-regs-usb", 0x7d80, 0x80 }, /* tunable_LN0_SMGR_REGS_USB */ + [41] = { "apple,tunable-ln1-smgr-regs-usb", 0x10d80, 0x80 }, /* tunable_LN1_SMGR_REGS_USB */ + [42] = { "apple,tunable-ln0-detector-regs-usb", 0x8480, 0x30 }, /* tunable_LN0_DETECTOR_REGS_USB */ + [43] = { "apple,tunable-ln1-detector-regs-usb", 0x11480, 0x30 }, /* tunable_LN1_DETECTOR_REGS_USB */ + [44] = { "apple,tunable-ln0-div40-regs-usb", 0x8580, 0x80 }, /* tunable_LN0_DIV40_REGS_USB */ + [45] = { "apple,tunable-ln1-div40-regs-usb", 0x11580, 0x80 }, /* tunable_LN1_DIV40_REGS_USB */ + [46] = { "apple,tunable-ln0-ctle-eq-regs-usb", 0x7f80, 0x100 }, /* tunable_LN0_CTLE_EQ_REGS_USB */ + [47] = { "apple,tunable-ln1-ctle-eq-regs-usb", 0x10f80, 0x100 }, /* tunable_LN1_CTLE_EQ_REGS_USB */ + [48] = { "apple,tunable-ln0-rxaeq-top-regs-usb", 0x79c0, 0x23c }, /* tunable_LN0_RXAEQ_TOP_REGS_USB */ + [49] = { "apple,tunable-ln1-rxaeq-top-regs-usb", 0x109c0, 0x23c }, /* tunable_LN1_RXAEQ_TOP_REGS_USB */ + [50] = { "apple,tunable-ln0-txseq-regs-usb", 0x4c80, 0x84 }, /* tunable_LN0_TXSEQ_REGS_USB */ + [51] = { "apple,tunable-ln1-txseq-regs-usb", 0xdc80, 0x84 }, /* tunable_LN1_TXSEQ_REGS_USB */ + [52] = { "apple,tunable-cio-shim-cio", 0x1a00, 0x68 }, /* tunable_CIO_SHIM_CIO */ + [53] = { "apple,tunable-ln0-ctle-eq-regs-cio", 0x7f80, 0x100 }, /* tunable_LN0_CTLE_EQ_REGS_CIO */ + [54] = { "apple,tunable-ln0-smgr-regs-cio", 0x7d80, 0x80 }, /* tunable_LN0_SMGR_REGS_CIO */ + [55] = { "apple,tunable-ln0-rxaeq-top-regs-cio", 0x79c0, 0x23c }, /* tunable_LN0_RXAEQ_TOP_REGS_CIO */ + [56] = { "apple,tunable-ln0-rxtx-txd-cfg-cio", 0x8af0, 0x44 }, /* tunable_LN0_RXTX_TXD_CFG_CIO */ + [57] = { "apple,tunable-ln0-tx-txd-cfg-cio", 0x4e90, 0x44 }, /* tunable_LN0_TX_TXD_CFG_CIO */ + [58] = { "apple,tunable-ln1-ctle-eq-regs-cio", 0x10f80, 0x100 }, /* tunable_LN1_CTLE_EQ_REGS_CIO */ + [59] = { "apple,tunable-ln1-smgr-regs-cio", 0x10d80, 0x80 }, /* tunable_LN1_SMGR_REGS_CIO */ + [60] = { "apple,tunable-ln1-rxaeq-top-regs-cio", 0x109c0, 0x23c }, /* tunable_LN1_RXAEQ_TOP_REGS_CIO */ + [61] = { "apple,tunable-ln1-rxtx-txd-cfg-cio", 0x11af0, 0x44 }, /* tunable_LN1_RXTX_TXD_CFG_CIO */ + [62] = { "apple,tunable-ln1-tx-txd-cfg-cio", 0xde90, 0x44 }, /* tunable_LN1_TX_TXD_CFG_CIO */ +}; + +static const u8 t8152_seq_efuse[] = { + 0, 1, +}; + +static const u8 t8152_seq_usb3[] = { + 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 28, 29, 30, 31, 32, 33, + 34, 35, 36, 37, 38, 39, 40, 41, + 42, 43, 44, 45, 46, 47, 48, 49, + 50, 51, +}; + +static const u8 t8152_seq_cio[] = { + 2, 3, 4, 5, 52, 8, 10, 12, + 14, 16, 18, 20, 22, 24, 26, 28, + 30, 32, 34, 36, 38, 53, 54, 55, + 56, 57, 9, 11, 13, 15, 17, 19, + 21, 23, 25, 27, 29, 31, 33, 35, + 37, 39, 58, 59, 60, 61, 62, +}; + +#endif diff --git a/drivers/phy/apple/atc-t8152.c b/drivers/phy/apple/atc-t8152.c new file mode 100644 index 00000000000000..e3450d14f7c533 --- /dev/null +++ b/drivers/phy/apple/atc-t8152.c @@ -0,0 +1,458 @@ +// SPDX-License-Identifier: GPL-2.0-only OR MIT +/* + * Apple T8152 (M6) Type-C PHY: the SuperSpeed / USB4 side of an ATC port. + * + * The USB2 side of the same port is apple,t8152-usb2-phy (usb2-t8152.c), the DisplayPort side dptx-t8152.c. This driver brings the PHY block + * (ADT atc-phy reg[2]) up for one transport at a time and routes the dwc3 PIPE (usb-drd reg[3], the "pipehandler") to it: + * + * PHY index 0, "usb3": USB3 transport. set_mode(HOST) powers the PHY if needed and routes the PIPE to it, which is the only call the dwc3-apple glue makes + * (like atc.c there is no power_on: dwc3 would call it before its core reset; power_off shuts the PHY down). + * PHY index 1, "cio": CIO / USB4 transport for the thunderbolt_apple driver (phy_power_on / phy_power_off). + * + * A transport change is shutdown + full bring-up, as in the vendor driver (it has no incremental path). The cable orientation comes from the Type-C + * switch; it takes effect at the next bring-up, or immediately (re-run) while the PHY is up. + * + * The register sequences are in atc-t8152-seq.h; the tunable lists are not part of the driver, the boot loader passes them as + * apple,tunable- properties (see Documentation/devicetree/bindings/phy/apple,t8152-atcphy.yaml). + */ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "atc-t8152-seq.h" + +#define ATC_CORE_MIN_SIZE (T8152_POWER + 0x40) +#define ATC_PIPEH_MIN_SIZE 0x30 + +enum atc_mode { + ATC_OFF, + ATC_USB3, + ATC_CIO, +}; + +struct apple_t8152_atc { + struct device *dev; + struct t8152_regs r; + struct apple_tunable *tun[T8152_NUM_TUNABLES]; + struct phy *usb3; + struct phy *cio; + struct typec_switch_dev *sw; + struct mutex lock; /* serialises mode changes, bring-up, shutdown and the PIPE route */ + enum atc_mode mode; + enum atc_mode want_mode; /* transport the consumers last asked for; ATC_OFF after a deliberate power_off */ + bool swap; /* cable orientation is reversed */ + bool restart; /* an orientation restart did not complete; retried on the next orientation event */ + bool pipe_usb3; /* the dwc3 PIPE is routed to the PHY */ + bool route_locked; /* the route sequence finished with the handler lock released */ + bool route_ready; /* the routed PIPE reported PIPE_PHY_READY */ + unsigned int cio_lanes; /* lane mask of the CIO bring-up */ +}; + +static int atc_up(struct apple_t8152_atc *atc, enum atc_mode mode) +{ + int ret; + + /* The efuse calibration lists are the minimum without which the PHY would run uncalibrated. */ + if (!atc->tun[t8152_seq_efuse[0]] || !atc->tun[t8152_seq_efuse[1]]) { + dev_err(atc->dev, "no PHY calibration tunables passed by the boot loader\n"); + return -ENODEV; + } + + if (mode == ATC_USB3) { + ret = t8152_up_usb3(&atc->r, atc->tun, atc->swap); + if (!ret) + ret = t8152_pipe_override_enable(&atc->r); + } else { + ret = t8152_up_cio(&atc->r, atc->tun, atc->swap, atc->cio_lanes); + } + if (ret) { + dev_err(atc->dev, "%s bring-up failed: %d\n", mode == ATC_USB3 ? "USB3" : "CIO", ret); + t8152_shutdown(&atc->r); + return ret; + } + atc->mode = mode; + atc->restart = false; + return 0; +} + +static int atc_down(struct apple_t8152_atc *atc) +{ + int ret; + + if (atc->mode == ATC_OFF) + return 0; + if (atc->pipe_usb3) { + /* a failed park leaves the controller routed to the PHY: keep the route + * recorded and the mode set, so a later down retries the park + */ + ret = t8152_pipehandler_park(&atc->r); + if (ret) { + dev_err(atc->dev, "failed to park the PIPE: %d\n", ret); + atc->route_ready = false; + return ret; + } + atc->pipe_usb3 = false; + } + atc->route_locked = false; + atc->route_ready = false; + ret = t8152_shutdown(&atc->r); + if (ret) + dev_warn(atc->dev, "PHY power-down did not settle: %d\n", ret); + atc->mode = ATC_OFF; + return ret; +} + +static int atc_route_usb3(struct apple_t8152_atc *atc) +{ + int ret = 0; + bool routed = false; + + /* the route stands, the handler lock is released and the PIPE is confirmed ready */ + if (atc->pipe_usb3 && atc->route_locked && atc->route_ready) + return 0; + if (!atc->pipe_usb3 || !atc->route_locked) { + ret = t8152_pipehandler_usb3_host(&atc->r, &routed); + /* a failed retry never un-records a standing route */ + if (routed) + atc->pipe_usb3 = true; + if (!atc->pipe_usb3) { + atc->route_locked = false; + return ret; /* the mux never moved and no route stands */ + } + atc->route_locked = !ret; + /* a lock-release timeout leaves the route standing; route_locked stays false, so a + * retry re-runs the host sequence, whose entry re-checks the lock ack + */ + if (ret) + return ret; + } + /* the PIPE points at the PHY: confirm it; a retry repeats only this wait */ + ret = t8152_pipehandler_usb3_ready(&atc->r); + atc->route_ready = !ret; + return ret; +} + +static int atc_usb3_power_off(struct phy *phy) +{ + struct apple_t8152_atc *atc = phy_get_drvdata(phy); + + guard(mutex)(&atc->lock); + + /* a deliberate power_off withdraws this transport's request only */ + if (atc->want_mode == ATC_USB3) + atc->want_mode = ATC_OFF; + if (atc->mode != ATC_USB3) + return 0; + return atc_down(atc); +} + +/* dwc3-apple only calls set_mode() on its USB3 PHY (after the core reset), so this brings the PHY up as well when nothing else has. */ +static int atc_usb3_set_mode(struct phy *phy, enum phy_mode mode, int submode) +{ + struct apple_t8152_atc *atc = phy_get_drvdata(phy); + int ret; + + if (mode != PHY_MODE_USB_HOST) + return -EOPNOTSUPP; + + guard(mutex)(&atc->lock); + + if (atc->mode == ATC_CIO) + return -EBUSY; + atc->want_mode = ATC_USB3; + if (atc->mode == ATC_OFF) { + ret = atc_up(atc, ATC_USB3); + if (ret) + return ret; + } + return atc_route_usb3(atc); +} + +static const struct phy_ops atc_usb3_ops = { + .power_off = atc_usb3_power_off, + .set_mode = atc_usb3_set_mode, + .owner = THIS_MODULE, +}; + +static int atc_cio_power_on(struct phy *phy) +{ + struct apple_t8152_atc *atc = phy_get_drvdata(phy); + + guard(mutex)(&atc->lock); + + if (atc->mode == ATC_CIO) + return 0; + if (atc->mode == ATC_USB3) + return -EBUSY; + atc->want_mode = ATC_CIO; + return atc_up(atc, ATC_CIO); +} + +static int atc_cio_power_off(struct phy *phy) +{ + struct apple_t8152_atc *atc = phy_get_drvdata(phy); + + guard(mutex)(&atc->lock); + + /* a deliberate power_off withdraws this transport's request only */ + if (atc->want_mode == ATC_CIO) + atc->want_mode = ATC_OFF; + if (atc->mode != ATC_CIO) + return 0; + return atc_down(atc); +} + +static const struct phy_ops atc_cio_ops = { + .power_on = atc_cio_power_on, + .power_off = atc_cio_power_off, + .owner = THIS_MODULE, +}; + +static struct phy *atc_xlate(struct device *dev, const struct of_phandle_args *args) +{ + struct apple_t8152_atc *atc = dev_get_drvdata(dev); + + if (args->args_count != 1 || args->args[0] > 1) + return ERR_PTR(-EINVAL); + return args->args[0] ? atc->cio : atc->usb3; +} + +static int atc_sw_set(struct typec_switch_dev *sw, enum typec_orientation orientation) +{ + struct apple_t8152_atc *atc = typec_switch_get_drvdata(sw); + enum atc_mode mode; + bool routed, swap; + int ret = 0; + + if (orientation == TYPEC_ORIENTATION_NONE) + return 0; + swap = orientation == TYPEC_ORIENTATION_REVERSE; + + guard(mutex)(&atc->lock); + + /* a pending restart retries here even when the orientation did not change */ + if (swap == atc->swap && !atc->restart) + return 0; + atc->swap = swap; + if (atc->mode == ATC_OFF) { + /* a failed orientation restart: bring the PHY back for the remembered transport + * (the fixed-role dwc3 calls phy_set_mode only once, at core start) + */ + if (!atc->restart || atc->want_mode == ATC_OFF) + return 0; + ret = atc_up(atc, atc->want_mode); + if (ret) + return ret; /* the restart stays pending */ + if (atc->want_mode == ATC_USB3) + ret = atc_route_usb3(atc); + if (ret) + atc->restart = true; + return ret; + } + + /* The vendor driver re-runs shutdown + bring-up when the orientation changes + * with the PHY up. + */ + mode = atc->mode; + routed = atc->pipe_usb3; + ret = atc_down(atc); + if (ret) { + /* the PHY is still up and routed; the next orientation event retries */ + atc->restart = true; + return ret; + } + ret = atc_up(atc, mode); + /* route for the USB3 transport even when the previous route attempt never moved the + * mux: otherwise the PHY comes back up with the PIPE still on the dummy backend + */ + if (!ret && (routed || atc->mode == ATC_USB3)) + ret = atc_route_usb3(atc); + /* the PHY is down again or half-routed; the next orientation event retries */ + if (ret) + atc->restart = true; + return ret; +} + +static void atc_pm_put(void *data) +{ + pm_runtime_put_sync(data); +} + +static void atc_sw_unregister(void *data) +{ + typec_switch_unregister(data); +} + +static int atc_dwc3_window(struct device_node *dwc3, const char *name, struct resource *res) +{ + int idx = of_property_match_string(dwc3, "reg-names", name); + + return idx < 0 ? idx : of_address_to_resource(dwc3, idx, res); +} + +static int atc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct resource *core, pipeh, dcore, dapple, blk; + resource_size_t cfg_phys; + struct device_node *dwc3; + struct apple_t8152_atc *atc; + struct typec_switch_desc sw_desc = { }; + struct phy_provider *provider; + unsigned int i; + int ret; + + atc = devm_kzalloc(dev, sizeof(*atc), GFP_KERNEL); + if (!atc) + return -ENOMEM; + atc->dev = dev; + atc->cio_lanes = T8152_LANES_BOTH; + mutex_init(&atc->lock); + platform_set_drvdata(pdev, atc); + + /* + * The windows are mapped without reserving them. The PHY core window of the ADT also contains the USB DART banks (+0x20000, +0x40000), which the + * platform bus nests inside it. The pipe handler and the PIPE_PHY_READY word are already resources of the dwc3 node (a second node with the same or + * a partly overlapping range cannot be added), so both are found through the dwc3 node. + */ + core = platform_get_resource_byname(pdev, IORESOURCE_MEM, "core"); + if (!core) + return dev_err_probe(dev, -EINVAL, "core window is required\n"); + if (resource_size(core) < ATC_CORE_MIN_SIZE) + return dev_err_probe(dev, -EINVAL, "core window too small\n"); + atc->r.core = devm_ioremap(dev, core->start, resource_size(core)); + if (!atc->r.core) + return -ENOMEM; + + dwc3 = of_parse_phandle(dev->of_node, "apple,dwc3", 0); + if (!dwc3) + return dev_err_probe(dev, -EINVAL, "apple,dwc3 is required\n"); + ret = atc_dwc3_window(dwc3, "pipe-handler", &pipeh); + if (!ret) + ret = atc_dwc3_window(dwc3, "dwc3-core", &dcore); + if (!ret) + ret = atc_dwc3_window(dwc3, "dwc3-apple", &dapple); + of_node_put(dwc3); + if (ret) + return dev_err_probe(dev, ret, "the dwc3 node lacks pipe-handler, dwc3-core or dwc3-apple\n"); + if (resource_size(&pipeh) < ATC_PIPEH_MIN_SIZE) + return dev_err_probe(dev, -EINVAL, "pipehandler window too small\n"); + atc->r.pipeh = devm_ioremap(dev, pipeh.start, resource_size(&pipeh)); + if (!atc->r.pipeh) + return -ENOMEM; + + /* usb-drd reg[1] of the ADT, 0x10000 above the dwc3 core, holds PIPE_PHY_READY; the dwc3 node maps it as the tail of its "dwc3-apple" window */ + cfg_phys = dcore.start + T8152_CFG_OFFSET; + if (cfg_phys < dapple.start || cfg_phys + T8152_CFG_PHY_READY_REG + sizeof(u32) - 1 > dapple.end) + return dev_err_probe(dev, -EINVAL, "the PIPE_PHY_READY word is outside the dwc3-apple window\n"); + atc->r.cfg = devm_ioremap(dev, cfg_phys, T8152_CFG_PHY_READY_REG + sizeof(u32)); + if (!atc->r.cfg) + return -ENOMEM; + + of_property_read_u32(dev->of_node, "apple,cio-lanes", &atc->cio_lanes); + if (!atc->cio_lanes || atc->cio_lanes > T8152_LANES_BOTH) + return dev_err_probe(dev, -EINVAL, "apple,cio-lanes must be 1, 2 or 3\n"); + + for (i = 0; i < T8152_NUM_TUNABLES; i++) { + blk = DEFINE_RES_MEM(core->start + t8152_tunables[i].off, t8152_tunables[i].len); + if (t8152_tunables[i].off + t8152_tunables[i].len > resource_size(core)) + return dev_err_probe(dev, -EINVAL, "%s lies outside the core window\n", t8152_tunables[i].prop); + atc->tun[i] = devm_apple_tunable_parse(dev, dev->of_node, t8152_tunables[i].prop, &blk); + if (IS_ERR(atc->tun[i])) { + if (PTR_ERR(atc->tun[i]) != -ENOENT) + return dev_err_probe(dev, PTR_ERR(atc->tun[i]), "invalid %s\n", t8152_tunables[i].prop); + atc->tun[i] = NULL; /* like the vendor driver, a list the firmware does not carry is skipped */ + } + } + + if (of_property_present(dev->of_node, "power-domains")) { + struct dev_pm_domain_list *domains; + + /* one domain is attached by the platform bus, several by index (the PHY, AON and ATC domains of the port) */ + if (of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells") > 1) { + ret = devm_pm_domain_attach_list(dev, NULL, &domains); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to attach the PHY power domains\n"); + } + ret = devm_pm_runtime_enable(dev); + if (ret) + return ret; + /* + * The domains stay on for the whole driver lifetime: the core, pipe + * handler and PIPE_PHY_READY windows are touched from the phy ops and + * the Type-C switch, which hold no runtime-PM reference of their own, + * and the ATC USB domain (psd_atc*_usb) is shared with the dwc3 node, + * whose runtime PM may gate it on its own. A get/put in + * atc_up/atc_down would gate the banks between transports and under + * an idle dwc3 (e.g. while the CIO PHY serves the ACIO controller). + */ + ret = pm_runtime_resume_and_get(dev); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to power the PHY domains\n"); + ret = devm_add_action_or_reset(dev, atc_pm_put, dev); + if (ret) + return ret; + } + + atc->usb3 = devm_phy_create(dev, NULL, &atc_usb3_ops); + if (IS_ERR(atc->usb3)) + return PTR_ERR(atc->usb3); + phy_set_drvdata(atc->usb3, atc); + atc->cio = devm_phy_create(dev, NULL, &atc_cio_ops); + if (IS_ERR(atc->cio)) + return PTR_ERR(atc->cio); + phy_set_drvdata(atc->cio, atc); + + if (of_property_read_bool(dev->of_node, "orientation-switch")) { + sw_desc.drvdata = atc; + sw_desc.fwnode = dev->fwnode; + sw_desc.set = atc_sw_set; + atc->sw = typec_switch_register(dev, &sw_desc); + if (IS_ERR(atc->sw)) + return dev_err_probe(dev, PTR_ERR(atc->sw), "failed to register the Type-C switch\n"); + ret = devm_add_action_or_reset(dev, atc_sw_unregister, atc->sw); + if (ret) + return ret; + } + + provider = devm_of_phy_provider_register(dev, atc_xlate); + return PTR_ERR_OR_ZERO(provider); +} + +static void atc_remove(struct platform_device *pdev) +{ + struct apple_t8152_atc *atc = platform_get_drvdata(pdev); + + guard(mutex)(&atc->lock); + /* a failed park leaves the route standing and the PHY powered: shutting the PHY + * down under a controller that still points at it is worse, so the failure is + * only logged (the driver is going away, nothing retries the park) + */ + if (atc_down(atc)) + dev_err(atc->dev, "the PIPE did not park; the PHY is left up and routed\n"); +} + +static const struct of_device_id atc_match[] = { + { .compatible = "apple,t8152-atcphy" }, + { } +}; +MODULE_DEVICE_TABLE(of, atc_match); + +static struct platform_driver atc_driver = { + .probe = atc_probe, + .remove = atc_remove, + .driver = { + .name = "apple-t8152-atcphy", + .of_match_table = atc_match, + }, +}; +module_platform_driver(atc_driver); + +MODULE_DESCRIPTION("Apple T8152 Type-C PHY (SuperSpeed and USB4 lanes)"); +MODULE_LICENSE("Dual MIT/GPL"); 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/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/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..6f3d2694455205 100644 --- a/drivers/usb/dwc3/dwc3-apple.c +++ b/drivers/usb/dwc3/dwc3-apple.c @@ -13,8 +13,10 @@ #include #include #include +#include #include #include +#include #include #include "dwc3-apple-state.h" @@ -86,6 +88,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 +109,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 +134,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 +210,138 @@ 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 + +/* + * GCTL.PWRDNSCALE specifies how many suspend_clk periods fit into a 16 kHz clock period (see + * dwc3_set_power_down_clk_scale()). The boot value is 1560 and the vendor driver writes 13 on + * T8152. With 1560 the SuperSpeed port waits about 1.6 s between RxDetect and Polling; with 13 + * that step takes under 90 ms. + */ +#define T8152_GCTL_PWRDNSCALE 13 + +static void dwc3_apple_t8152_set_pwrdnscale(struct dwc3_apple *appledwc) +{ + void __iomem *gctl_reg = appledwc->dwc.regs + DWC3_GCTL - DWC3_GLOBALS_REGS_START; + u32 gctl = readl(gctl_reg); + + gctl &= ~DWC3_GCTL_PWRDNSCALE_MASK; + gctl |= DWC3_GCTL_PWRDNSCALE(T8152_GCTL_PWRDNSCALE); + writel(gctl, gctl_reg); +} + +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 = readl(appledwc->dwc.regs + 0xc680 - DWC3_GLOBALS_REGS_START); + writel(value & ~BIT(13), appledwc->dwc.regs + 0xc680 - DWC3_GLOBALS_REGS_START); + value = readl(appledwc->dwc.regs + 0xc680 - DWC3_GLOBALS_REGS_START); + writel(value & ~BIT(13), appledwc->dwc.regs + 0xc680 - DWC3_GLOBALS_REGS_START); +} + static void dwc3_apple_set_ptrcap(struct dwc3_apple *appledwc, u32 mode) { guard(spinlock_irqsave)(&appledwc->dwc.lock); @@ -374,7 +523,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) @@ -386,12 +568,20 @@ static int dwc3_apple_core_start(struct dwc3_apple *appledwc, enum dwc3_apple_st * Now that the core is initialized and already went through dwc3_core_soft_reset we can * configure some unknown Apple-specific settings and then bring up xhci or gadget mode. */ + if (appledwc->t8152_usb2) + dwc3_apple_t8152_set_pwrdnscale(appledwc); dwc3_apple_setup_cio(appledwc); appledwc->core_active = true; appledwc->usb2_power_off_pending = BIT(appledwc->dwc.num_usb2_ports) - 1; 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 +604,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 +716,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 +811,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 +821,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 +848,16 @@ 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"); + /* + * A T8152 port runs USB2-only unless the board describes the SuperSpeed PHY + * (apple,t8152-atcphy): set_mode() on it brings the PHY up and routes the PIPE, + * see dwc3_apple_set_role(). Without one the PHY is NULL and every call on it + * succeeds. + */ + if (appledwc->t8152_usb2) + appledwc->usb3_phy = devm_phy_optional_get(dev, "usb3-phy"); + else + 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 +878,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 +904,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 +916,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 +945,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); diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c index 10d238b9220a49..48b0ace2a08e2d 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/dwc3/mocks.c @@ -77,6 +77,8 @@ struct dwc3_apple { void *dev; struct phy *usb2_phy, *usb3_phy; bool fixed_hub, core_active, core_exit_pending, reset_pending; + bool t8152_usb2, fixed_peripheral; + void *tunable_regs[6]; unsigned long usb2_power_off_pending, usb3_power_off_pending; }; static unsigned int polls, fail_poll, reset_calls, reset_writes, core_writes; @@ -292,6 +294,10 @@ static void dwc3_apple_setup_cio(struct dwc3_apple *a) (void)a; setup_cio++; } +static void dwc3_apple_t8152_set_pwrdnscale(struct dwc3_apple *a) +{ + (void)a; +} static int dwc3_apple_usb2_mode_before_reset(enum dwc3_apple_state s, enum phy_mode *m) { diff --git a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py index 96fd0b5dcea014..0781648d9bc2fd 100644 --- a/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py +++ b/tools/testing/selftests/drivers/gpu/apple-dcp/lifecycle.py @@ -1059,7 +1059,7 @@ def fn(n, name): while definition[-1].endswith('\\'): definition.append(next(lines)) definitions.append('\n'.join(definition)) - definitions = '\n'.join(definitions) + definitions = '\n'.join(definitions + [l for l in files['apple'].splitlines() if l.startswith('#define T8152_PIPE_')]) here = Path(__file__).resolve().parent fallback = '' if 'dwc3_core_remove_no_shutdown' in names['core'] else '#define dwc3_core_remove_no_shutdown dwc3_core_remove\n' unit = ((here / 'dwc3/prefix.c').read_text() + '\n' + definitions + '\n' +