diff --git a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml index 4c048e4f5487d..a7bc6bf4885c9 100644 --- a/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml +++ b/Documentation/devicetree/bindings/reset/apple,t8103-cio-reset.yaml @@ -40,6 +40,7 @@ properties: - apple,t6020-cio-reset - apple,t6030-cio-reset - apple,t6031-cio-reset + - apple,t6041-cio-reset - apple,t8122-cio-reset - apple,t8132-cio-reset - const: apple,t6000-cio-reset diff --git a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml index c8b7fc98c1545..d9dd4cd1aa756 100644 --- a/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml +++ b/Documentation/devicetree/bindings/thunderbolt/apple,t8103-usb4-acio.yaml @@ -207,7 +207,9 @@ allOf: properties: compatible: contains: - const: apple,t8132-usb4-acio + enum: + - apple,t6040-usb4-acio + - apple,t8132-usb4-acio then: properties: reg: diff --git a/arch/arm64/boot/dts/apple/t6040-j616s.dts b/arch/arm64/boot/dts/apple/t6040-j616s.dts index c934110c69b95..0e29b6291ed9f 100644 --- a/arch/arm64/boot/dts/apple/t6040-j616s.dts +++ b/arch/arm64/boot/dts/apple/t6040-j616s.dts @@ -165,3 +165,47 @@ &scaler0 { status = "okay"; }; + +/* + * USB4/Thunderbolt on the left back port (typec0, ACIO0). The loader hands + * the router, adapter and NHI tuning and the DROM over. No PCIe tunnel yet: + * host-to-host (XDomain, thunderbolt-net) and USB4 links only. + */ +&pmgr_cio { + status = "okay"; +}; + +&ps_atc0_cio { + status = "okay"; +}; + +&ps_atc0_pcie { + status = "okay"; +}; + +&ps_atc0_cio_pcie { + status = "okay"; +}; + +&ps_atc0_cio_usb { + status = "okay"; +}; + +&usb4_0_mbox { + status = "okay"; +}; + +&usb4_0_acio { + /delete-property/ apple,pcie-tunnel; + status = "okay"; +}; + +&usb4_0_dart { + /* ADT dart-acio0 vm-base: the NHI addresses its rings below 1 TiB + 4 GiB. */ + apple,dma-range = <0x100 0x4000 0x0 0xffff0000>; + status = "okay"; +}; + +&usb4_0_nhi { + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi index 1313766fe8775..cb15a0516393c 100644 --- a/arch/arm64/boot/dts/apple/t6040-usb4.dtsi +++ b/arch/arm64/boot/dts/apple/t6040-usb4.dtsi @@ -2,21 +2,20 @@ /* * T6040 USB4/PCIe-C resource description. * - * Every node remains disabled until the Type-C PHY transition, bootloader - * tuning handoff, and dynamic PCIe RID-to-SID policy are qualified. + * Every node is disabled here; a board enables the routers it has qualified. */ / { aliases { - usb4-0-rc = &usb4_0_acio; + usb4-0-acio = &usb4_0_acio; usb4-0-nhi = &usb4_0_nhi; usb4-0-pcie = &usb4_0_pcie; usb4-0-pcie-adapter = &usb4_0_acio; - usb4-1-rc = &usb4_1_acio; + usb4-1-acio = &usb4_1_acio; usb4-1-nhi = &usb4_1_nhi; usb4-1-pcie = &usb4_1_pcie; usb4-1-pcie-adapter = &usb4_1_acio; - usb4-2-rc = &usb4_2_acio; + usb4-2-acio = &usb4_2_acio; usb4-2-nhi = &usb4_2_nhi; usb4-2-pcie = &usb4_2_pcie; usb4-2-pcie-adapter = &usb4_2_acio; @@ -33,7 +32,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_0_mbox>; - resets = <&ps_atc0_cio>; + resets = <&cio_reset 0>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_0_lstx_pins>; + lstx-gpios = <&pinctrl_aop 49 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc0_cio>, <&ps_atc0_cio_pcie>, <&ps_atc0_cio_usb>, <&ps_atc0_pcie>; thunderbolt-switch; @@ -50,7 +52,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_0_acio_tbt: endpoint { }; }; }; @@ -127,7 +129,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_1_mbox>; - resets = <&ps_atc1_cio>; + resets = <&cio_reset 1>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_1_lstx_pins>; + lstx-gpios = <&pinctrl_aop 51 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc1_cio>, <&ps_atc1_cio_pcie>, <&ps_atc1_cio_usb>, <&ps_atc1_pcie>; thunderbolt-switch; @@ -144,7 +149,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_1_acio_tbt: endpoint { }; }; }; @@ -221,7 +226,10 @@ interrupts = ; interrupt-names = "sram-parity"; mboxes = <&usb4_2_mbox>; - resets = <&ps_atc2_cio>; + resets = <&cio_reset 2>; + pinctrl-names = "lstx"; + pinctrl-0 = <&usb4_2_lstx_pins>; + lstx-gpios = <&pinctrl_aop 53 GPIO_ACTIVE_HIGH>; power-domains = <&ps_atc2_cio>, <&ps_atc2_cio_pcie>, <&ps_atc2_cio_usb>, <&ps_atc2_pcie>; thunderbolt-switch; @@ -238,7 +246,7 @@ port@1 { reg = <1>; - endpoint { }; + usb4_2_acio_tbt: endpoint { }; }; }; @@ -517,3 +525,36 @@ }; }; }; + +/ { + /* ADT pmgr reg[44]: AppleT6041PMGR::enableCioReconfig at +0x2024. */ + pmgr_cio: power-management@502820000 { + compatible = "apple,t6041-pmgr", "apple,t8103-pmgr", "syscon", "simple-mfd"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x5 0x02820000 0 0x4000>; + /* Enabled together with the routers. */ + status = "disabled"; + + cio_reset: reset-controller@2024 { + compatible = "apple,t6041-cio-reset", "apple,t6000-cio-reset"; + reg = <0x2024 0x4>; + #reset-cells = <1>; + }; + }; +}; + +&pinctrl_aop { + /* ADT acioN gpio-lstx. */ + usb4_0_lstx_pins: usb4-0-lstx-pins { + pinmux = ; + }; + + usb4_1_lstx_pins: usb4-1-lstx-pins { + pinmux = ; + }; + + usb4_2_lstx_pins: usb4-2-lstx-pins { + pinmux = ; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi new file mode 100644 index 0000000000000..ec32ca4bf9c03 --- /dev/null +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616-usb4.dtsi @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: GPL-2.0+ OR MIT +/* + * MacBook Pro (14-inch and 16-inch, M4 Pro) USB4/Thunderbolt: each Type-C + * port's connector is linked to the USB4 router behind the same ATC PHY + * (ADT acioN atc-phy-parent = atc-phyN): typec0 (left back) to ACIO0, + * typec1 (left front) to ACIO1, typec2 (right) to ACIO2. The routers stay + * disabled, and a port controller skips a link to a disabled router, so this + * changes nothing until a board enables them. + */ + +&usb4_0_acio_tbt { + remote-endpoint = <&typec0_con_tbt>; +}; + +&usb4_1_acio_tbt { + remote-endpoint = <&typec1_con_tbt>; +}; + +&usb4_2_acio_tbt { + remote-endpoint = <&typec2_con_tbt>; +}; + +&typec0 { + ports { + port@2 { + reg = <2>; + typec0_con_tbt: endpoint { + remote-endpoint = <&usb4_0_acio_tbt>; + }; + }; + }; +}; + +&typec1 { + ports { + port@2 { + reg = <2>; + typec1_con_tbt: endpoint { + remote-endpoint = <&usb4_1_acio_tbt>; + }; + }; + }; +}; + +&typec2 { + ports { + port@2 { + reg = <2>; + typec2_con_tbt: endpoint { + remote-endpoint = <&usb4_2_acio_tbt>; + }; + }; + }; +}; diff --git a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi index 368503f7f4884..864e87400bb87 100644 --- a/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi +++ b/arch/arm64/boot/dts/apple/t604x-j614-j616.dtsi @@ -3444,3 +3444,5 @@ power-domain-names = "sys", "cpu", "mpm", "td", "base", "perf"; status = "okay"; }; + +#include "t604x-j614-j616-usb4.dtsi" diff --git a/drivers/pci/controller/pcie-apple.c b/drivers/pci/controller/pcie-apple.c index 3173186c85209..6ad3376dcf75e 100644 --- a/drivers/pci/controller/pcie-apple.c +++ b/drivers/pci/controller/pcie-apple.c @@ -336,6 +336,21 @@ static const struct hw_info t8132_pciec_hw = { .s2idle_hold_domain = true, }; +static const struct hw_info t6040_pciec_hw = { + .port_msiaddr = PORT_MSIADDR, + .port_msiaddr_hi = PORT_MSIADDR + 4, + .port_perst = PORT_PERST, + .port_rid2sid = PORT_RID2SID, + .port_msimap = PORT_T602X_MSIMAP, + .port_tunctrl = 0x1088, + .max_rid2sid = 256, + .sid_indexed_rid2sid = true, + .tunneled = true, + .t8132_reset = true, + .msimap_by_vector = true, + .s2idle_hold_domain = true, +}; + static const struct of_device_id apple_pcie_of_match[]; /** @@ -2086,7 +2101,8 @@ static int apple_msi_init(struct apple_pcie *pcie) * 32-vector slice. Keep endpoint MSI data local, and route its table * entry to the corresponding shared-window vector. */ - if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw) { + if (pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || + pcie->hw == &t6040_pciec_hw) { struct resource ecam; u32 expected_base, aic_base; @@ -2108,6 +2124,21 @@ static int apple_msi_init(struct apple_pcie *pcie) default: goto invalid_slice; } + } else if (of_machine_is_compatible("apple,t6040")) { + aic_base = 2071; + switch (ecam.start) { + case 0x1c50000000ULL: + expected_base = 0x20; + break; + case 0x1c60000000ULL: + expected_base = 0x40; + break; + case 0x1c70000000ULL: + expected_base = 0x60; + break; + default: + goto invalid_slice; + } } else if (of_machine_is_compatible("apple,t8132")) { aic_base = 1506; switch (ecam.start) { @@ -2153,7 +2184,8 @@ static int apple_msi_init(struct apple_pcie *pcie) } /* Keep map targets within the supported 8-bit range. */ - if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw) && + if ((pcie->hw == &t8122_pciec_hw || pcie->hw == &t8132_pciec_hw || + pcie->hw == &t6040_pciec_hw) && (!pcie->nvecs || pcie->nvecs > 256 || pcie->msi_vector_base > FIELD_MAX(PORT_MSIMAP_TARGET) + 1 - pcie->nvecs)) { @@ -4052,6 +4084,7 @@ static const struct dev_pm_ops apple_pcie_pm_ops = { }; static const struct of_device_id apple_pcie_of_match[] = { + { .compatible = "apple,t6040-pciec", .data = &t6040_pciec_hw }, { .compatible = "apple,t8132-pciec", .data = &t8132_pciec_hw }, { .compatible = "apple,t8122-pciec", .data = &t8122_pciec_hw }, { .compatible = "apple,t8112-pciec", .data = &t8112_pciec_hw }, diff --git a/drivers/phy/apple/t6040-usb2.c b/drivers/phy/apple/t6040-usb2.c index cb4146d91faf1..73b687686294d 100644 --- a/drivers/phy/apple/t6040-usb2.c +++ b/drivers/phy/apple/t6040-usb2.c @@ -49,6 +49,8 @@ #include #include #include +#include +#include #define T6040_USB2_USBCTL 0x00 #define T6040_USB2_USBCTL_MODE GENMASK(2, 0) @@ -120,7 +122,10 @@ #define T6040_CORE_CMN_OVRD_SLEEP_B_BIG BIT(0) #define T6040_CORE_CMN_OVRD_SLEEP_B_SML BIT(2) #define T6040_CORE_CMN_OVRD_CLAMP BIT(4) +#define T6040_CORE_LANE_RX 0x10 /* CFG1_TOP */ #define T6040_CORE_SLP_CTRL 0x120 /* CFG_SLP_CTRL */ +#define T6040_CORE_LN0_RX_TOP_CIO 0x935c +#define T6040_CORE_LN1_RX_TOP_CIO 0x1935c #define T6040_CORE_CMN_BIAS 0xa00 /* AUS40CMN_SHM CMN_BIAS_REG */ #define T6040_CORE_CMN_BIAS_BGBIAS_EN_OV BIT(1) #define T6040_CORE_UC_CTRL 0x260 /* ACIOPHY_TOP_BLK_UC_CTRL_REG */ @@ -241,6 +246,7 @@ struct t6040_usb2_phy { bool usb3_pipe; /* dwc3 asked for the PIPE switch this power cycle */ bool usb3_lent; /* DP mode took the lanes of this Type-C port */ bool pipe_switched; /* the controller's PIPE runs on this PHY */ + bool cio_up; /* the lanes run USB4/Thunderbolt */ /* DisplayPort; dp_ok is false when the DT lacks a DP route */ struct phy *dp; @@ -598,14 +604,15 @@ static int t6040_usb3_cpu_start(struct t6040_usb2_phy *tphy) * every detach; each start makes the firmware tune the PHY. Then release the * PHY reset (D). */ -static int t6040_usb3_run_firmware(struct t6040_usb2_phy *tphy, bool swap) +static int t6040_usb3_run_firmware(struct t6040_usb2_phy *tphy, bool usb, bool swap) { void __iomem *cpu = t6040_cpu(tphy); u32 uc_before; int ret; - t6040_usb2_mask32(t6040_cfg(tphy) + T6040_CFG_SPARE0, T6040_CFG_SPARE0_USB_LN_SWAP, - swap ? T6040_CFG_SPARE0_USB_LN_SWAP : 0); + if (usb) + t6040_usb2_mask32(t6040_cfg(tphy) + T6040_CFG_SPARE0, T6040_CFG_SPARE0_USB_LN_SWAP, + swap ? T6040_CFG_SPARE0_USB_LN_SWAP : 0); fsleep(20); t6040_usb2_set32(cpu + T6040_CPU_IDLE_CTRL, T6040_CPU_IDLE_CTRL_EN); fsleep(10); @@ -750,24 +757,12 @@ static void t6040_usb3_bist_off(struct t6040_usb2_phy *tphy) * aciophy_phy_shutdown_partA: the PHY's USB link side down (the same BIST * handshake as the PIPE switch), both TX lanes, then the common block. */ -static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) +/* aciophy_tx_powerdown(0), (1), then aciophy_cmn_shutdown: USB and CIO alike. */ +static void t6040_phy_tx_cmn_down(struct t6040_usb2_phy *tphy) { - void __iomem *bist = t6040_bist(tphy); void __iomem *core = t6040_core(tphy); unsigned int lane; - t6040_usb2_set32(bist + T6040_BIST_CFG0, BIT(0)); - t6040_usb2_clear32(bist + T6040_BIST_OVRD0, 0x100000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x60, 0x20); - t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); - t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD0, ~0xe1ffffffu, 0x4000000); - t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x600, 0x200); - t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); - t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); - t6040_usb2_clear32(bist + T6040_BIST_CFG0, BIT(0)); - - /* aciophy_tx_powerdown(0), (1) */ for (lane = 0; lane < 2; lane++) { t6040_usb2_set32(core + T6040_CORE_SLP_CTRL, 0x100 << lane); udelay(1); @@ -786,6 +781,25 @@ static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) udelay(1); t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, T6040_CORE_CMN_OVRD_SLEEP_B_SML); udelay(1); +} + + +static void t6040_usb3_shutdown_lanes(struct t6040_usb2_phy *tphy) +{ + void __iomem *bist = t6040_bist(tphy); + + t6040_usb2_set32(bist + T6040_BIST_CFG0, BIT(0)); + t6040_usb2_clear32(bist + T6040_BIST_OVRD0, 0x100000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x60, 0x20); + t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); + t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD0, ~0xe1ffffffu, 0x4000000); + t6040_usb2_mask32(bist + T6040_BIST_OVRD1, 0x600, 0x200); + t6040_usb3_bist_pulse(tphy, T6040_BIST_CFG0, BIT(3)); + t6040_usb3_bist_wait(tphy, T6040_BIST_STATUS_PHY_2, true, 1000); + t6040_usb2_clear32(bist + T6040_BIST_CFG0, BIT(0)); + + t6040_phy_tx_cmn_down(tphy); fsleep(200); } @@ -896,8 +910,8 @@ static void t6040_usb3_up_locked(struct t6040_usb2_phy *tphy) lockdep_assert_held(&tphy->lock); if (!tphy->usb3_ok || tphy->usb3_up) return; - /* DP mode owns all four lanes; USB3 comes back in t6040_usb3_reclaim_locked(). */ - if (tphy->dp_up) { + /* DP and CIO own all four lanes; USB3 comes back in t6040_usb3_reclaim_locked(). */ + if (tphy->dp_up || tphy->cio_up) { dev_dbg(tphy->dev, "USB3: lanes held by DP, USB2 only for now\n"); return; } @@ -922,7 +936,7 @@ static void t6040_usb3_up_locked(struct t6040_usb2_phy *tphy) goto sleep; /* the coprocessor block may be unclocked: never touch it */ t6040_usb3_tunables(tphy); t6040_usb3_lanes(tphy, swap); - ret = t6040_usb3_run_firmware(tphy, swap); + ret = t6040_usb3_run_firmware(tphy, true, swap); if (ret) goto usb2_only; @@ -1409,7 +1423,7 @@ static void t6040_dp_drive(struct t6040_usb2_phy *tphy, unsigned int lane, u32 p static void t6040_usb3_reclaim_locked(struct t6040_usb2_phy *tphy) { lockdep_assert_held(&tphy->lock); - if (!tphy->usb3_lent || tphy->dp_up || tphy->dp_alt) + if (!tphy->usb3_lent || tphy->dp_up || tphy->dp_alt || tphy->cio_up) return; tphy->usb3_lent = false; if (!tphy->usb3_on || tphy->usb3_up) @@ -1422,6 +1436,156 @@ static void t6040_usb3_reclaim_locked(struct t6040_usb2_phy *tphy) dev_info(tphy->dev, "USB3 %s after DP\n", tphy->usb3_up ? "back" : "not restored"); } +/* ---- CIO: USB4 and Thunderbolt on both lanes ---- */ + +/* The ADT tables of the common set, then the CIO ones; no DPTX writes. */ +static void t6040_cio_tunables(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + size_t i; + + for (i = 0; i < T6040_USB3_NR_TUNABLES; i++) + apple_tunable_apply(tphy->regs[t6040_usb3_tunable_list[i].region], + tphy->tunables[i]); + /* tunable_LN0/1_RX_TOP_CIO_DFLT; UC_REGS_CIO and RX_EQ_CIO are empty. */ + t6040_usb2_clear32(core + T6040_CORE_LN0_RX_TOP_CIO, 0xe00); + t6040_usb2_clear32(core + T6040_CORE_LN1_RX_TOP_CIO, 0xe00); +} + +/* aciophy_xbar_config, mode 2: orientation is one crossbar bit. */ +static void t6040_cio_xbar(struct t6040_usb2_phy *tphy, bool flip) +{ + void __iomem *core = t6040_core(tphy); + + t6040_usb2_clear32(core + T6040_CORE_XBAR, 0xfc); + t6040_usb2_mask32(core + T6040_CORE_XBAR_LANES, 0x1f, flip ? 1 : 0); + t6040_usb2_mask32(core + T6040_CORE_XBAR, 0x3, 0x2); +} + +/* aciophy_slpctrl_init, mode 2: both lanes, whatever the orientation. */ +static void t6040_cio_lanes_on(struct t6040_usb2_phy *tphy) +{ + static const struct { u32 off, bit; bool set; } steps[] = { + { T6040_CORE_LANE_RX, 0x10, true }, { T6040_CORE_LANE_RX, 0x40, true }, + { T6040_CORE_LANE_RX, 0x1, true }, { T6040_CORE_LANE_RX, 0x4, true }, + { T6040_CORE_CMN_OVRD, 0x400, true }, { T6040_CORE_CMN_OVRD, 0x1000, true }, + { T6040_CORE_CMN_OVRD, 0x40, true }, { T6040_CORE_CMN_OVRD, 0x100, true }, + { T6040_CORE_CMN_OVRD, 0x4000, false }, { T6040_CORE_CMN_OVRD, 0x10000, true }, + { T6040_CORE_SLP_CTRL, 0x40, false }, { T6040_CORE_SLP_CTRL, 0x4, false }, + { T6040_CORE_SLP_CTRL, 0x400, false }, + }; + void __iomem *core = t6040_core(tphy); + unsigned int lane; + size_t i; + + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x2a); + udelay(1); + for (lane = 0; lane < 2; lane++) { + for (i = 0; i < ARRAY_SIZE(steps); i++) { + if (steps[i].set) + t6040_usb2_set32(core + steps[i].off, steps[i].bit << lane); + else + t6040_usb2_clear32(core + steps[i].off, steps[i].bit << lane); + udelay(1); + } + } +} + +/* aciophy_rx_powerdown(0), (1): CIO powers the receivers down, USB does not. */ +static void t6040_cio_rx_down(struct t6040_usb2_phy *tphy) +{ + void __iomem *core = t6040_core(tphy); + unsigned int lane; + + for (lane = 0; lane < 2; lane++) { + t6040_usb2_set32(core + T6040_CORE_CMN_OVRD, 0x4000 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x40 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_CMN_OVRD, 0x400 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_LANE_RX, 0x1 << lane); + udelay(1); + t6040_usb2_clear32(core + T6040_CORE_LANE_RX, 0x10 << lane); + udelay(1); + } +} + +/* The Type-C state that needs CIO: USB4 entered, or the Thunderbolt alt mode. */ +static bool t6040_cio_state(const struct typec_mux_state *state) +{ + if (state->alt) + return state->alt->svid == USB_TYPEC_TBT_SID; + if (state->mode != TYPEC_MODE_USB4 || !state->data) + return false; + return FIELD_GET(EUDO_USB_MODE_MASK, + ((const struct enter_usb_data *)state->data)->eudo) == EUDO_USB_MODE_USB4; +} + +static int t6040_cio_up_locked(struct t6040_usb2_phy *tphy) +{ + bool flip; + int ret; + + lockdep_assert_held(&tphy->lock); + if (!tphy->usb3_ok || tphy->dp_up) + return -EBUSY; + switch (tphy->orientation) { + case TYPEC_ORIENTATION_NORMAL: + flip = false; + break; + case TYPEC_ORIENTATION_REVERSE: + flip = true; + break; + default: + dev_warn(tphy->dev, "CIO: no plug orientation\n"); + return -EINVAL; + } + if (tphy->usb3_up || tphy->pipe_switched) + t6040_usb3_down_locked(tphy); + tphy->usb3_lent = tphy->usb3_on; + + ret = pm_runtime_resume_and_get(tphy->dev); + if (ret) + return ret; + ret = t6040_usb3_wake(tphy); + if (ret) + goto sleep; /* the coprocessor block may be unclocked: never touch it */ + t6040_cio_tunables(tphy); + t6040_cio_xbar(tphy, flip); + t6040_cio_lanes_on(tphy); + ret = t6040_usb3_run_firmware(tphy, false, flip); + if (ret) { + t6040_usb3_firmware_power_down(tphy); + goto sleep; + } + tphy->cio_up = true; + dev_info(tphy->dev, "CIO PHY up, %s orientation\n", flip ? "reverse" : "normal"); + return 0; + +sleep: + t6040_usb3_sleep(tphy); + pm_runtime_put(tphy->dev); + dev_warn(tphy->dev, "CIO PHY bring-up failed: %d\n", ret); + return ret; +} + +static void t6040_cio_down_locked(struct t6040_usb2_phy *tphy) +{ + lockdep_assert_held(&tphy->lock); + if (!tphy->cio_up) + return; + t6040_phy_tx_cmn_down(tphy); + t6040_cio_rx_down(tphy); + fsleep(200); + t6040_usb3_firmware_power_down(tphy); + t6040_usb3_sleep(tphy); + tphy->cio_up = false; + pm_runtime_put(tphy->dev); + dev_info(tphy->dev, "CIO PHY asleep\n"); + t6040_usb3_reclaim_locked(tphy); +} + /* ---- DP phy_ops ---- */ static int t6040_dp_power_on(struct phy *phy) @@ -1432,6 +1596,8 @@ static int t6040_dp_power_on(struct phy *phy) guard(mutex)(&tphy->lock); if (!tphy->dp_ok || tphy->dp_up) return 0; + if (tphy->cio_up) + return -EBUSY; /* Pin D shares the running PHY with USB3. Keep its PIPE and firmware. */ if (tphy->dp_two_lanes) { if (!tphy->usb3_ok || !tphy->dp_alt) @@ -1581,6 +1747,12 @@ static int t6040_dp_mux_set(struct typec_mux_dev *mux, struct typec_mux_state *s bool alt = false; guard(mutex)(&tphy->lock); + if (t6040_cio_state(state)) { + if (tphy->cio_up) + return 0; + return t6040_cio_up_locked(tphy); + } + t6040_cio_down_locked(tphy); tphy->dp_flip = (tphy->orientation == TYPEC_ORIENTATION_REVERSE); /* * Latch the DP alt mode state for the DCP's Type-C route. Pin diff --git a/drivers/thunderbolt/apple.c b/drivers/thunderbolt/apple.c index 61325859752d4..ba7ec0bc0296c 100644 --- a/drivers/thunderbolt/apple.c +++ b/drivers/thunderbolt/apple.c @@ -181,6 +181,16 @@ static const struct apple_cio_hw apple_cio_t8142_hw = { .dp = &apple_dpin_disabled, }; +static const struct apple_cio_hw apple_cio_t6040_hw = { + .mxwrap = true, + .lstx_explicit = true, + .skip_run = true, + .lstx_after_boot = true, + .strict_fw_ready = true, + .no_host_clx = true, + .dp = &apple_dpin_disabled, +}; + #define APPLE_CIO_NHI_HOP_COUNT 0x0 #define APPLE_CIO_NHI_HOP_COUNT_MASK GENMASK(9, 0) @@ -883,14 +893,20 @@ static void apple_cio_of_node_put(void *data) of_node_put(data); } +static bool apple_cio_pciec_eligible(const struct device_node *np) +{ + return of_device_is_compatible(np, "apple,t6040-pciec") || + of_device_is_compatible(np, "apple,t8103-pciec") || + of_device_is_compatible(np, "apple,t6000-pciec"); +} + static bool apple_cio_pcie_tunnel_is_preinitialized(struct device_node *parent) { for_each_available_child_of_node_scoped(parent, child) { u32 status; - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; if (!of_property_read_u32(child, "apple,pciec-preinit-status", @@ -919,8 +935,7 @@ static int apple_cio_get_pcie_reset(struct apple_cio *acio) struct reset_control *rst = NULL; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; if (!of_property_read_bool(child, "apple,pciec-kernel-init")) break; @@ -952,8 +967,7 @@ static int apple_cio_map_pcie_intr2axi(struct apple_cio *acio) int index, ret; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; index = of_property_match_string(child, "reg-names", "intr2axi"); @@ -2032,7 +2046,8 @@ static int apple_nhi_probe(struct platform_device *pdev) int ret = 0; if (acio->type7 != - of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi")) { + (of_device_is_compatible(pdev->dev.of_node, "apple,t8142-usb4-nhi") || + of_device_is_compatible(pdev->dev.of_node, "apple,t6040-usb4-nhi"))) { ret = dev_err_probe(&pdev->dev, -EINVAL, "ACIO/NHI generation mismatch\n"); goto err; } @@ -2458,6 +2473,9 @@ static const struct dev_pm_ops apple_nhi_pm_ops = { }; static const struct of_device_id apple_nhi_match[] = { + { + .compatible = "apple,t6040-usb4-nhi", + }, { .compatible = "apple,t8142-usb4-nhi", }, @@ -2486,8 +2504,7 @@ static struct platform_device *apple_cio_find_pcie_tunnel(struct apple_cio *acio return NULL; for_each_available_child_of_node_scoped(acio->pcie_tunnel_np, child) { - if (!of_device_is_compatible(child, "apple,t8103-pciec") && - !of_device_is_compatible(child, "apple,t6000-pciec")) + if (!apple_cio_pciec_eligible(child)) continue; pdev = of_find_device_by_node(child); @@ -3279,7 +3296,8 @@ static int apple_cio_probe(struct platform_device *pdev) init_completion(&acio->nhi_boot_completion); acio->dev = &pdev->dev; acio->np = dev->of_node; - acio->type7 = of_device_is_compatible(acio->np, "apple,t8142-usb4-acio"); + acio->type7 = of_device_is_compatible(acio->np, "apple,t8142-usb4-acio") || + of_device_is_compatible(acio->np, "apple,t6040-usb4-acio"); if (acio->type7 && of_property_count_u32_elems(acio->np, "apple,tunable-rc") <= 0) return dev_err_probe(dev, -EINVAL, "Missing bootloader RC tuning\n"); @@ -3487,6 +3505,10 @@ static void apple_cio_remove(struct platform_device *pdev) static const struct of_device_id apple_acio_match[] = { + { + .compatible = "apple,t6040-usb4-acio", + .data = &apple_cio_t6040_hw, + }, { .compatible = "apple,t8142-usb4-acio", .data = &apple_cio_t8142_hw, diff --git a/tools/asahi/pciec-policy-tests.py b/tools/asahi/pciec-policy-tests.py index 825caefac0912..a399c7ef6e023 100644 --- a/tools/asahi/pciec-policy-tests.py +++ b/tools/asahi/pciec-policy-tests.py @@ -38,7 +38,7 @@ def function(source, name): struct of_device_id { const char *compatible; const void *data; }; struct of_phandle_args { struct device_node *np; }; static int maps; -static bool of_device_is_compatible(struct device_node *np, const char *compat) +static bool of_device_is_compatible(const struct device_node *np, const char *compat) { for (int i = 0; np && i < 3 && np->compat[i]; i++) if (!strcmp(np->compat[i], compat)) @@ -149,6 +149,7 @@ def main(): matches = re.search(r'static const struct of_device_id apple_pcie_of_match\[\] = \{.*?\n\};', pci, re.S)[0] production = '\n'.join((defines, info, matches, function(pci, 'apple_pcie_tunnel_needs_cold_init'), + function(acio, 'apple_cio_pciec_eligible'), function(acio, 'apple_cio_pcie_tunnel_is_preinitialized'))) code = FIXTURE.replace('/* PRODUCTION */', production) with tempfile.TemporaryDirectory(prefix='pciec-policy-') as tmp: