From 4c8f9d3039410f64a9823e001aebce7839aa8ead Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Sun, 8 Nov 2026 19:49:04 -0500 Subject: [PATCH 1/3] phy: apple: Enable T6050 USB4 display clocks and port zero Provide the four USB4 DisplayPort tunnel pixel-clock gates and clock-source switches, unwind failed starts, and park idle clocks in USB4 mode. Accept port index zero when its controller has handed the port to the host. Keep the public tunnel-clock declaration with its PHY implementation. Consolidate the duplicate T6050 schema into the existing combo-PHY binding, which already describes these compatibles with matrix-typed tunables. Developed with Claude Code. Signed-off-by: Erik Bourget --- .../bindings/phy/apple,combo-phy.yaml | 23 +- .../bindings/phy/apple,t6050-dp-phy.yaml | 257 ------------------ drivers/phy/apple/atc-t6050-combo.h | 6 +- drivers/phy/apple/atc-t6050-dp.c | 206 +++++++++++++- .../apple/usb-t6050/apple_t6050_usb3_pipe.h | 2 +- include/linux/soc/apple/dp-tunnel.h | 8 + 6 files changed, 233 insertions(+), 269 deletions(-) delete mode 100644 Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml diff --git a/Documentation/devicetree/bindings/phy/apple,combo-phy.yaml b/Documentation/devicetree/bindings/phy/apple,combo-phy.yaml index 43b179b4dd879..90e5dbf812a0e 100644 --- a/Documentation/devicetree/bindings/phy/apple,combo-phy.yaml +++ b/Documentation/devicetree/bindings/phy/apple,combo-phy.yaml @@ -24,11 +24,11 @@ properties: reg: minItems: 6 - maxItems: 11 + maxItems: 12 reg-names: minItems: 6 - maxItems: 11 + maxItems: 12 '#phy-cells': enum: [0, 1] @@ -38,8 +38,8 @@ properties: apple,port-index: $ref: /schemas/types.yaml#/definitions/uint32 - enum: [1, 2, 3, 4, 5] - description: Type-C port; the debug port (0) is excluded + enum: [0, 1, 2, 3, 4, 5] + description: Type-C port, including port zero when handed over to the host apple,guest-port-reserved: type: boolean @@ -78,9 +78,11 @@ properties: description: A combo PHY may name the USB controller's domain fourth ("usb"). Its USB2 PHY and digital banks are in that domain, and the PHY then holds it - while it runs, also on a port with no USB controller bound. + while it runs, also on a port with no USB controller bound. USB4 + DisplayPort tunnel pixel clocks add four clock gates ("dp0" to "dp3"), + held while the corresponding clock runs. minItems: 3 - maxItems: 4 + maxItems: 8 power-domain-names: minItems: 3 @@ -89,6 +91,10 @@ properties: - const: common - const: wrapper - const: usb + - const: dp0 + - const: dp1 + - const: dp2 + - const: dp3 apple,tunable-axi2af: $ref: /schemas/types.yaml#/definitions/uint32-matrix @@ -174,8 +180,9 @@ allOf: const: 1 reg: minItems: 11 - maxItems: 11 + maxItems: 12 reg-names: + minItems: 11 items: - const: core - const: usb2phy @@ -188,6 +195,8 @@ allOf: - const: usb-control - const: firmware-data - const: pipehandler + - description: Source select words for the four USB4 DP pixel clocks + const: dp-clock-source required: - '#reset-cells' - apple,port-index diff --git a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml b/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml deleted file mode 100644 index 3b22c3f19ee9b..0000000000000 --- a/Documentation/devicetree/bindings/phy/apple,t6050-dp-phy.yaml +++ /dev/null @@ -1,257 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0-only -%YAML 1.2 ---- -$id: http://devicetree.org/schemas/phy/apple,t6050-dp-phy.yaml# -$schema: http://devicetree.org/meta-schemas/core.yaml# - -title: Apple T6050 DisplayPort and Type-C combo PHY - -maintainers: - - Dj - -description: | - Fixed four-lane DisplayPort PHY for HDMI bridges, or one shared owner of - Type-C USB2, USB3 and DisplayPort alternate mode. DisplayPort supports RBR - through HBR3 without spread-spectrum clocking. The combo provider serializes - controller shutdown, PIPE handoff, orientation and alternate-mode changes. - Register resources, power domains and board tunables come from the producer. - -properties: - compatible: - enum: - - apple,t6050-dp-phy - - apple,t6050-combo-phy - - reg: - minItems: 6 - maxItems: 11 - - reg-names: - minItems: 6 - maxItems: 11 - - '#phy-cells': - enum: [0, 1] - - '#reset-cells': - const: 1 - - apple,port-index: - $ref: /schemas/types.yaml#/definitions/uint32 - enum: [1, 2, 3, 4, 5] - description: Type-C port; the debug port (0) is excluded - - apple,guest-port-reserved: - type: boolean - description: The boot producer has excluded this port from host ownership - - mode-switch: true - orientation-switch: true - - mboxes: - maxItems: 1 - - port: - $ref: /schemas/graph.yaml#/properties/port - - apple,tunable-aus40cmn-shm: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the common analog bank - - apple,tunable-cio4pll: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the CIO PLL bank - - apple,tunable-usb2-default: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the USB2 PHY bank - - apple,tunable-usb2-host: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the USB2 host bank - - apple,tunable-pipe-default: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples for the PIPE handler - - power-domains: - description: - A combo PHY may name the USB controller's domain fourth ("usb"). Its - USB2 PHY and digital banks are in that domain, and the PHY then holds it - while it runs, also on a port with no USB controller bound. - minItems: 3 - maxItems: 4 - - power-domain-names: - minItems: 3 - items: - - const: usb-aon - - const: common - - const: wrapper - - const: usb - - apple,tunable-axi2af: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-fabric: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-common-cfg: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lioa: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane0-rx-clock: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane1-rx-clock: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane0-rx-eq: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-lane1-rx-eq: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-auspll: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: Offset, mask and value tuples within the named bank - - apple,tunable-uc-regs-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: - Offset, mask and value tuples for the PHY firmware's registers in CIO - (USB4/Thunderbolt) mode. Optional; an absent CIO tunable is skipped. - - apple,tunable-lane0-rx-top-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 0's receiver top bank - - apple,tunable-lane1-rx-top-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 1's receiver top bank - - apple,tunable-lane0-rx-eq-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 0's receiver equalizer - - apple,tunable-lane1-rx-eq-cio: - $ref: /schemas/types.yaml#/definitions/uint32-array - description: As apple,tunable-uc-regs-cio, for lane 1's receiver equalizer - -patternProperties: - '^apple,dp-training-table(-rbr|-hbr|-hbr2|-hbr3)?$': - $ref: /schemas/types.yaml#/definitions/uint32-array - minItems: 16 - maxItems: 16 - description: Drive presets indexed by voltage swing times four plus pre-emphasis - -required: - - compatible - - reg - - reg-names - - '#phy-cells' - - power-domains - - power-domain-names - - apple,tunable-axi2af - - apple,tunable-fabric - - apple,tunable-common-cfg - - apple,tunable-lioa - - apple,tunable-lane0-rx-clock - - apple,tunable-lane1-rx-clock - - apple,tunable-lane0-rx-eq - - apple,tunable-lane1-rx-eq - - apple,tunable-auspll - -allOf: - - if: - properties: - compatible: - const: apple,t6050-combo-phy - then: - properties: - '#phy-cells': - const: 1 - reg: - minItems: 11 - maxItems: 11 - reg-names: - items: - - const: core - - const: usb2phy - - const: usb2-digital - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - - const: usb-control - - const: firmware-data - - const: pipehandler - required: - - '#reset-cells' - - apple,port-index - - apple,guest-port-reserved - - mode-switch - - orientation-switch - - mboxes - - apple,tunable-aus40cmn-shm - - apple,tunable-cio4pll - - apple,tunable-usb2-default - - apple,tunable-usb2-host - - apple,tunable-pipe-default - else: - properties: - '#phy-cells': - const: 0 - power-domains: - maxItems: 3 - power-domain-names: - maxItems: 3 - if: - required: - - mode-switch - then: - properties: - reg: - minItems: 8 - maxItems: 8 - reg-names: - items: - - const: core - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - - const: usb-control - - const: firmware-data - required: - - orientation-switch - - mboxes - - apple,tunable-aus40cmn-shm - - apple,tunable-cio4pll - else: - properties: - reg: - minItems: 6 - maxItems: 6 - reg-names: - items: - - const: core - - const: reset - - const: fabric - - const: axi2af - - const: lioa - - const: common-cfg - -additionalProperties: false diff --git a/drivers/phy/apple/atc-t6050-combo.h b/drivers/phy/apple/atc-t6050-combo.h index 185f71cd6e138..f1e0ea6238ab9 100644 --- a/drivers/phy/apple/atc-t6050-combo.h +++ b/drivers/phy/apple/atc-t6050-combo.h @@ -122,6 +122,8 @@ static int combo_stop(struct t6050_dp *dp) lockdep_assert_held(&dp->lock); if (dp->faulted) return -EIO; + /* No tunnel clock outlives USB4 mode. */ + atc_dp_tunnels_stop(dp); if (dp->controller_active || dp->pipe_active) return -EBUSY; ret = combo_quiesce(dp); @@ -180,8 +182,10 @@ static int combo_start(struct t6050_dp *dp, enum combo_mode mode) ret = dp->reverse ? APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_cio_init_reverse) : APPLE_T6050_USB_RUN(&dp->usb_platform, apple_t6050_cio_init_normal); - if (!ret) + if (!ret) { dp->cio_prepared = true; + atc_dp_tunnels_park(dp); + } dev_info(dp->dev, "CIO mode %s (%d), %s orientation, %lld ms\n", ret ? "failed" : "up: UC_TNBL_DONE", ret, dp->reverse ? "reverse" : "normal", diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 3eadc358589ff..62d8ee9aae0f2 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -71,6 +71,22 @@ struct atc_domain { bool active; }; enum combo_mode { COMBO_SAFE, COMBO_USB, COMBO_DP4, COMBO_DP2, COMBO_CIO }; + +/* + * USB4 DisplayPort tunnel pixel clocks, k = 1..4. Each has a clock gate, a + * source select word in the power manager's clock block (the DP link rate's + * source, then a busy bit to wait out), and a switch in the PHY's CFG block + * (bank 39): +0x14 holds a 3-bit field per clock (k = on, 7 = parked) and a + * UHBR bit 11 + k, +0x18 an enable bit per clock, +0x1c its status. Switch k + * feeds the display crossbar's pixel clock k. + */ +#define ATC_DP_TUNNELS 4 +#define ATC_CFG_DP_SWITCH 0x14 +#define ATC_CFG_DP_ENABLE 0x18 +#define ATC_CFG_DP_STATUS 0x1c +#define ATC_DP_SWITCH_PARKED 7 +#define ATC_DP_SRC_SELECT GENMASK(27, 24) +#define ATC_DP_SRC_BUSY BIT(30) struct t6050_dp { bool combo, usb_prepared, usb2_active, pipe_active, controller_active, cio_prepared; bool pipe_tunnel; /* the active PIPE is a USB4 router's USB3 tunnel */ @@ -99,6 +115,11 @@ struct t6050_dp { void __iomem *fw_data; bool fw_running; void *fw_data_saved; /* the firmware data SRAM as the first start found it */ + /* USB4 DP tunnel pixel clocks: source words, gates, running link rates */ + void __iomem *dp_clk_src; + struct atc_domain dp_gate[ATC_DP_TUNNELS]; + bool dp_gates; + u8 tunnel_rate[ATC_DP_TUNNELS]; }; static int atc_domain_set(struct atc_domain *pd, bool active) @@ -413,6 +434,77 @@ static void atc_drive(struct t6050_dp *dp, unsigned int lane, u32 preset) atc_mask(base + (tx ? 0x100 : 0xa8), 0x7ffff, eq); } +static u32 atc_dp_switch_mask(unsigned int k) +{ + return GENMASK(3 * k - 1, 3 * k - 3) | BIT(11 + k); +} + +/* Enable (and status) bits 1, 8, 15 and 22 */ +static u32 atc_dp_enable_bit(unsigned int k) +{ + return BIT(7 * k - 6); +} + +/* The power manager's source code for a DP link rate */ +static int atc_dp_source(u8 rate) +{ + switch (rate) { + case 0x06: return 10; /* RBR */ + case 0x0a: return 9; /* HBR */ + case 0x14: return 8; /* HBR2 */ + case 0x1e: return 7; /* HBR3 */ + case 0x81: return 6; /* UHBR10 */ + case 0x82: return 5; /* UHBR20 */ + default: return -EINVAL; + } +} + +/* Switch tunnel clock @k off and park it; its gate stays as it is. */ +static void atc_dp_tunnel_switch_off(struct t6050_dp *dp, unsigned int k) +{ + void __iomem *cfg = dp->banks[39]; + u32 en = atc_dp_enable_bit(k), v; + + writel(readl(cfg + ATC_CFG_DP_ENABLE) & ~en, cfg + ATC_CFG_DP_ENABLE); + writel((readl(cfg + ATC_CFG_DP_SWITCH) & ~atc_dp_switch_mask(k)) | + (ATC_DP_SWITCH_PARKED << (3 * k - 3)), cfg + ATC_CFG_DP_SWITCH); + if (readl_poll_timeout(cfg + ATC_CFG_DP_STATUS, v, !(v & en), 10, 10000)) + dev_warn(dp->dev, "DP tunnel clock %u: switch status %08x still on\n", k, v); + dp->tunnel_rate[k - 1] = 0; +} + +/* + * Park every tunnel clock switch that runs no clock (field 7, enable off), + * once the PHY is in USB4 mode: an unparked switch selects the native DP + * clock for its crossbar pixel clock. + */ +static void atc_dp_tunnels_park(struct t6050_dp *dp) +{ + void __iomem *cfg = dp->banks[39]; + u32 sw = readl(cfg + ATC_CFG_DP_SWITCH), en = readl(cfg + ATC_CFG_DP_ENABLE); + + for (unsigned int k = 1; k <= ATC_DP_TUNNELS; k++) { + if (dp->tunnel_rate[k - 1]) + continue; + sw = (sw & ~atc_dp_switch_mask(k)) | (ATC_DP_SWITCH_PARKED << (3 * k - 3)); + en &= ~atc_dp_enable_bit(k); + } + writel(en, cfg + ATC_CFG_DP_ENABLE); + writel(sw, cfg + ATC_CFG_DP_SWITCH); +} + +/* Stop every tunnel clock, before the PHY leaves USB4 mode. */ +static void atc_dp_tunnels_stop(struct t6050_dp *dp) +{ + for (unsigned int k = 1; k <= ATC_DP_TUNNELS; k++) { + if (dp->tunnel_rate[k - 1]) + atc_dp_tunnel_switch_off(dp, k); + /* A failed start or gate suspend can leave a held domain at rate zero. */ + if (dp->dp_gates) + atc_domain_set(&dp->dp_gate[k - 1], false); + } +} + #include "atc-t6050-combo.h" static int t6050_dp_set_mode(struct phy *phy, enum phy_mode mode, int submode) @@ -520,6 +612,80 @@ int apple_dp_phy_link_config(struct phy *phy, unsigned int *pclk, bool *uhbr) } EXPORT_SYMBOL_GPL(apple_dp_phy_link_config); +int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate) +{ + struct t6050_dp *dp; + void __iomem *cfg, *word; + unsigned int i = clock - 1; + int src = 0, ret; + u32 en, v; + + if (!phy || phy->ops != &t6050_dp_ops) + return -EOPNOTSUPP; + if (clock < 1 || clock > ATC_DP_TUNNELS) + return -EINVAL; + if (rate) { + src = atc_dp_source(rate); + if (src < 0) + return src; + } + dp = phy_get_drvdata(phy); + guard(mutex)(&dp->lock); + if (!dp->combo || !dp->dp_clk_src) + return -EOPNOTSUPP; + if (rate && dp->tunnel_rate[i] == rate) + return 0; + /* A new rate takes the clock off its old source first. */ + if (dp->tunnel_rate[i]) + atc_dp_tunnel_switch_off(dp, clock); + if (!rate) { + ret = dp->dp_gates ? atc_domain_set(&dp->dp_gate[i], false) : 0; + if (!ret) + dev_info(dp->dev, "DP tunnel clock %u stopped\n", clock); + return ret; + } + if (dp->faulted) + return -EIO; + if (dp->combo_mode != COMBO_CIO) + return -ENOLINK; + if (dp->dp_gates) { + ret = atc_domain_set(&dp->dp_gate[i], true); + if (ret) + return ret; + } + word = dp->dp_clk_src + 4 * i; + writel((readl(word) & ~ATC_DP_SRC_SELECT) | FIELD_PREP(ATC_DP_SRC_SELECT, src), word); + ret = readl_poll_timeout(word, v, !(v & ATC_DP_SRC_BUSY), 10, 200000); + if (ret) { + dev_err(dp->dev, "DP tunnel clock %u: source %d not taken (%08x)\n", + clock, src, v); + if (dp->dp_gates) + atc_domain_set(&dp->dp_gate[i], false); + return ret; + } + cfg = dp->banks[39]; + en = atc_dp_enable_bit(clock); + writel((readl(cfg + ATC_CFG_DP_SWITCH) & ~atc_dp_switch_mask(clock)) | + (clock << (3 * clock - 3)) | + (rate == 0x81 || rate == 0x82 ? BIT(11 + clock) : 0), + cfg + ATC_CFG_DP_SWITCH); + writel(readl(cfg + ATC_CFG_DP_ENABLE) | en, cfg + ATC_CFG_DP_ENABLE); + ret = readl_poll_timeout(cfg + ATC_CFG_DP_STATUS, v, v & en, 10, 10000); + if (ret) { + dev_err(dp->dev, "DP tunnel clock %u: switch status %08x not on\n", clock, v); + /* Undo the partial start before leaving the rate uncached for retry. */ + atc_dp_tunnel_switch_off(dp, clock); + if (dp->dp_gates) + atc_domain_set(&dp->dp_gate[i], false); + return ret; + } + dp->tunnel_rate[i] = rate; + dev_info(dp->dev, "DP tunnel clock %u: link rate 0x%02x, source %d, switch status %08x\n", + clock, rate, src, v); + return 0; +} +EXPORT_SYMBOL_GPL(apple_t6050_dp_tunnel_clock); + /* The connector sets orientation before changing the alternate-mode mux. */ static int t6050_set_orientation(struct t6050_dp *dp, enum typec_orientation orientation) @@ -633,7 +799,7 @@ static int t6050_dp_probe(struct platform_device *pdev) struct phy *phy; struct resource *core; void __iomem *base; - int ndomains, ret; + int ndomains, gates, ret; dp = devm_kzalloc(dev, sizeof(*dp), GFP_KERNEL); if (!dp) @@ -642,9 +808,9 @@ static int t6050_dp_probe(struct platform_device *pdev) dp->combo = of_device_is_compatible(dev->of_node, "apple,t6050-combo-phy"); if (dp->combo) { u32 port; - /* Every Type-C port but 0, the debug port that carries the boot link. */ + /* Only ports explicitly handed over by the boot producer. */ if (of_property_read_u32(dev->of_node, "apple,port-index", &port) || - port < 1 || port > 5 || + port > 5 || !of_property_present(dev->of_node, "apple,guest-port-reserved") || !of_property_present(dev->of_node, "mode-switch")) return -EINVAL; @@ -769,6 +935,14 @@ static int t6050_dp_probe(struct platform_device *pdev) * are in (combo_start()). */ ndomains = of_count_phandle_with_args(dev->of_node, "power-domains", "#power-domain-cells"); + /* A combo's tunnel clock gates, "dp0".."dp3", follow its own domains. */ + gates = dp->combo ? + of_property_match_string(dev->of_node, "power-domain-names", "dp0") : -EINVAL; + if (gates > 0) { + if (ndomains != gates + ATC_DP_TUNNELS) + return -EINVAL; + ndomains = gates; + } if (ndomains != 3 && !(dp->combo && ndomains == 4)) return -EINVAL; dp->ndomains = ndomains; @@ -781,6 +955,32 @@ static int t6050_dp_probe(struct platform_device *pdev) if (ret) return ret; } + for (unsigned int i = 0; gates > 0 && i < ATC_DP_TUNNELS; i++) { + char name[4]; + + snprintf(name, sizeof(name), "dp%u", i); + dp->dp_gate[i].dev = dev_pm_domain_attach_by_name(dev, name); + if (IS_ERR_OR_NULL(dp->dp_gate[i].dev)) { + ret = dp->dp_gate[i].dev ? PTR_ERR(dp->dp_gate[i].dev) : -ENODEV; + return dev_err_probe(dev, ret, "cannot attach %s domain\n", name); + } + ret = devm_add_action_or_reset(dev, atc_domain_release, &dp->dp_gate[i]); + if (ret) + return ret; + dp->dp_gates = true; + } + if (dp->combo) { + struct resource *res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + "dp-clock-source"); + + if (res) { + if (resource_size(res) < 4 * ATC_DP_TUNNELS) + return -EINVAL; + dp->dp_clk_src = devm_ioremap_resource(dev, res); + if (IS_ERR(dp->dp_clk_src)) + return PTR_ERR(dp->dp_clk_src); + } + } if (dp->typec) { dp->fw_data = devm_platform_ioremap_resource_byname(pdev, "firmware-data"); if (IS_ERR(dp->fw_data)) diff --git a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h index 30e462e416580..2504c7db2ad8f 100644 --- a/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h +++ b/drivers/phy/apple/usb-t6050/apple_t6050_usb3_pipe.h @@ -3,7 +3,7 @@ * The caller owns the port, has powered the PHY/firmware for native USB3, * completed DWC3 core init and enabled SUSPHY, and has valid DART mappings. * Bank 35 is T6050's ADT PHY reg[35]. Bank 44 is usb-drdN reg[3]. - * The first left/debug port must never reach this backend. + * Only ports explicitly handed over to Linux may use this backend. */ #ifndef APPLE_T6050_USB3_PIPE_H #define APPLE_T6050_USB3_PIPE_H diff --git a/include/linux/soc/apple/dp-tunnel.h b/include/linux/soc/apple/dp-tunnel.h index 1597e338eca45..d3576207e5140 100644 --- a/include/linux/soc/apple/dp-tunnel.h +++ b/include/linux/soc/apple/dp-tunnel.h @@ -90,6 +90,14 @@ static inline int apple_dp_tunnel_t8132_rate_ok(u8 rate, u8 other) int apple_atc_dp_tunnel_rate_source(struct phy *phy, unsigned int source, unsigned int dpin, u8 rate); +/* + * T6050 ATC PHY in USB4/TBT mode: run tunnel pixel clock @clock (1-4, which + * feeds the display crossbar's pixel clock @clock) at DP link rate code @rate + * (0x06 RBR, 0x0a HBR, 0x14 HBR2, 0x1e HBR3, 0x81 UHBR10, 0x82 UHBR20), or + * stop it (@rate == 0). A running clock holds its clock gate. + */ +int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate); + /* * ATC PHY: wake the DP clock path of a PHY in Thunderbolt/USB4 mode ahead of * apple_atc_dp_tunnel_rate(), before DCP is told about the display. From 2935a2e72b74e1d6590c2f646b2b280c4976b75f Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 9 Nov 2026 20:22:14 -0500 Subject: [PATCH 2/3] phy: apple: atc-t6050-dp: keep a stopped tunnel clock while another runs Taking a running DP tunnel clock away disturbs the port's other tunnel clocks. With two displays on a dock, switching one off made the other's transmitter report a FIFO error within a millisecond of the first display's clock stopping; the second display's sink then sometimes lost its link. Leave a clock whose user stopped it running while another tunnel clock of the port is in use, and stop it with the last of them. A restart at the same rate then finds it running; a new rate re-sources it as before. On J716c with two 4K displays on one port, 24 of 24 stops disturbed the other display before. With this change, 8 of 8 off/on cycles of one display left the other undisturbed, and switching both off stops both clocks. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-dp.c | 48 ++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 62d8ee9aae0f2..0e84f9b72d4dd 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -120,6 +120,7 @@ struct t6050_dp { struct atc_domain dp_gate[ATC_DP_TUNNELS]; bool dp_gates; u8 tunnel_rate[ATC_DP_TUNNELS]; + u8 tunnel_idle; /* bit k - 1: clock k runs with no user, see below */ }; static int atc_domain_set(struct atc_domain *pd, bool active) @@ -471,6 +472,7 @@ static void atc_dp_tunnel_switch_off(struct t6050_dp *dp, unsigned int k) if (readl_poll_timeout(cfg + ATC_CFG_DP_STATUS, v, !(v & en), 10, 10000)) dev_warn(dp->dev, "DP tunnel clock %u: switch status %08x still on\n", k, v); dp->tunnel_rate[k - 1] = 0; + dp->tunnel_idle &= ~BIT(k - 1); } /* @@ -493,6 +495,28 @@ static void atc_dp_tunnels_park(struct t6050_dp *dp) writel(sw, cfg + ATC_CFG_DP_SWITCH); } +/* Stop tunnel clock @k and gate it. */ +static int atc_dp_tunnel_stop(struct t6050_dp *dp, unsigned int k) +{ + if (dp->tunnel_rate[k - 1]) + atc_dp_tunnel_switch_off(dp, k); + return dp->dp_gates ? atc_domain_set(&dp->dp_gate[k - 1], false) : 0; +} + +/* + * Taking a running tunnel clock away disturbs the port's other tunnel + * clocks: the display on one of them loses its stream for a moment, and can + * lose its link. A clock whose user stopped it therefore keeps running while + * another clock of the port is in use, and stops with the last of them. + */ +static bool atc_dp_tunnel_others_in_use(struct t6050_dp *dp, unsigned int k) +{ + for (unsigned int i = 0; i < ATC_DP_TUNNELS; i++) + if (i != k - 1 && dp->tunnel_rate[i] && !(dp->tunnel_idle & BIT(i))) + return true; + return false; +} + /* Stop every tunnel clock, before the PHY leaves USB4 mode. */ static void atc_dp_tunnels_stop(struct t6050_dp *dp) { @@ -633,17 +657,31 @@ int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate) guard(mutex)(&dp->lock); if (!dp->combo || !dp->dp_clk_src) return -EOPNOTSUPP; - if (rate && dp->tunnel_rate[i] == rate) + if (rate && dp->tunnel_rate[i] == rate) { + dp->tunnel_idle &= ~BIT(i); return 0; - /* A new rate takes the clock off its old source first. */ - if (dp->tunnel_rate[i]) - atc_dp_tunnel_switch_off(dp, clock); + } if (!rate) { - ret = dp->dp_gates ? atc_domain_set(&dp->dp_gate[i], false) : 0; + bool others = atc_dp_tunnel_others_in_use(dp, clock); + + if (dp->tunnel_rate[i] && others) { + dp->tunnel_idle |= BIT(i); + dev_dbg(dp->dev, "DP tunnel clock %u left running for the others\n", + clock); + return 0; + } + ret = atc_dp_tunnel_stop(dp, clock); + /* The last user went: the clocks kept for it go as well. */ + for (unsigned int k = 1; !others && k <= ATC_DP_TUNNELS; k++) + if (dp->tunnel_idle & BIT(k - 1)) + atc_dp_tunnel_stop(dp, k); if (!ret) dev_info(dp->dev, "DP tunnel clock %u stopped\n", clock); return ret; } + /* A new rate takes the clock off its old source first. */ + if (dp->tunnel_rate[i]) + atc_dp_tunnel_switch_off(dp, clock); if (dp->faulted) return -EIO; if (dp->combo_mode != COMBO_CIO) From 054c120dc3214227d03f75f1a7000236d80dc2e9 Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Mon, 9 Nov 2026 21:00:14 -0500 Subject: [PATCH 3/3] phy: apple: atc-t6050-dp: start a port's tunnel clocks together Starting a DP tunnel clock disturbs the port's running tunnel clocks as stopping one does: with one display running on a dock, the start of a second display's clock made the first display's transmitter report a FIFO error within a millisecond of the enable, in 4 of 4 tries. When a port's first tunnel clock starts, start the others with it, at its rate and with no user. A display that comes later at that rate finds its clock running; one at another rate re-sources its clock as before. The clocks stop together with the last user. Developed with Claude Code. Signed-off-by: Erik Bourget --- drivers/phy/apple/atc-t6050-dp.c | 95 ++++++++++++++++++++------------ 1 file changed, 61 insertions(+), 34 deletions(-) diff --git a/drivers/phy/apple/atc-t6050-dp.c b/drivers/phy/apple/atc-t6050-dp.c index 0e84f9b72d4dd..54a46cdc693c0 100644 --- a/drivers/phy/apple/atc-t6050-dp.c +++ b/drivers/phy/apple/atc-t6050-dp.c @@ -636,13 +636,56 @@ int apple_dp_phy_link_config(struct phy *phy, unsigned int *pclk, bool *uhbr) } EXPORT_SYMBOL_GPL(apple_dp_phy_link_config); +/* Start tunnel clock @clock at link rate @rate from PMGR source @src. */ +static int atc_dp_tunnel_start(struct t6050_dp *dp, unsigned int clock, u8 rate, + int src, u32 *status) +{ + void __iomem *cfg = dp->banks[39], *word; + unsigned int i = clock - 1; + u32 en = atc_dp_enable_bit(clock), v; + int ret; + + if (dp->dp_gates) { + ret = atc_domain_set(&dp->dp_gate[i], true); + if (ret) + return ret; + } + word = dp->dp_clk_src + 4 * i; + writel((readl(word) & ~ATC_DP_SRC_SELECT) | FIELD_PREP(ATC_DP_SRC_SELECT, src), word); + ret = readl_poll_timeout(word, v, !(v & ATC_DP_SRC_BUSY), 10, 200000); + if (ret) { + dev_err(dp->dev, "DP tunnel clock %u: source %d not taken (%08x)\n", + clock, src, v); + if (dp->dp_gates) + atc_domain_set(&dp->dp_gate[i], false); + return ret; + } + writel((readl(cfg + ATC_CFG_DP_SWITCH) & ~atc_dp_switch_mask(clock)) | + (clock << (3 * clock - 3)) | + (rate == 0x81 || rate == 0x82 ? BIT(11 + clock) : 0), + cfg + ATC_CFG_DP_SWITCH); + writel(readl(cfg + ATC_CFG_DP_ENABLE) | en, cfg + ATC_CFG_DP_ENABLE); + ret = readl_poll_timeout(cfg + ATC_CFG_DP_STATUS, v, v & en, 10, 10000); + if (ret) { + dev_err(dp->dev, "DP tunnel clock %u: switch status %08x not on\n", clock, v); + /* Undo the partial start before leaving the rate uncached for retry. */ + atc_dp_tunnel_switch_off(dp, clock); + if (dp->dp_gates) + atc_domain_set(&dp->dp_gate[i], false); + return ret; + } + dp->tunnel_rate[i] = rate; + *status = v; + return 0; +} + int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate) { struct t6050_dp *dp; - void __iomem *cfg, *word; unsigned int i = clock - 1; int src = 0, ret; - u32 en, v; + bool others; + u32 v; if (!phy || phy->ops != &t6050_dp_ops) return -EOPNOTSUPP; @@ -661,9 +704,8 @@ int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate) dp->tunnel_idle &= ~BIT(i); return 0; } + others = atc_dp_tunnel_others_in_use(dp, clock); if (!rate) { - bool others = atc_dp_tunnel_others_in_use(dp, clock); - if (dp->tunnel_rate[i] && others) { dp->tunnel_idle |= BIT(i); dev_dbg(dp->dev, "DP tunnel clock %u left running for the others\n", @@ -686,38 +728,23 @@ int apple_t6050_dp_tunnel_clock(struct phy *phy, unsigned int clock, u8 rate) return -EIO; if (dp->combo_mode != COMBO_CIO) return -ENOLINK; - if (dp->dp_gates) { - ret = atc_domain_set(&dp->dp_gate[i], true); - if (ret) - return ret; - } - word = dp->dp_clk_src + 4 * i; - writel((readl(word) & ~ATC_DP_SRC_SELECT) | FIELD_PREP(ATC_DP_SRC_SELECT, src), word); - ret = readl_poll_timeout(word, v, !(v & ATC_DP_SRC_BUSY), 10, 200000); - if (ret) { - dev_err(dp->dev, "DP tunnel clock %u: source %d not taken (%08x)\n", - clock, src, v); - if (dp->dp_gates) - atc_domain_set(&dp->dp_gate[i], false); - return ret; - } - cfg = dp->banks[39]; - en = atc_dp_enable_bit(clock); - writel((readl(cfg + ATC_CFG_DP_SWITCH) & ~atc_dp_switch_mask(clock)) | - (clock << (3 * clock - 3)) | - (rate == 0x81 || rate == 0x82 ? BIT(11 + clock) : 0), - cfg + ATC_CFG_DP_SWITCH); - writel(readl(cfg + ATC_CFG_DP_ENABLE) | en, cfg + ATC_CFG_DP_ENABLE); - ret = readl_poll_timeout(cfg + ATC_CFG_DP_STATUS, v, v & en, 10, 10000); - if (ret) { - dev_err(dp->dev, "DP tunnel clock %u: switch status %08x not on\n", clock, v); - /* Undo the partial start before leaving the rate uncached for retry. */ - atc_dp_tunnel_switch_off(dp, clock); - if (dp->dp_gates) - atc_domain_set(&dp->dp_gate[i], false); + ret = atc_dp_tunnel_start(dp, clock, rate, src, &v); + if (ret) return ret; + /* + * Starting a clock disturbs the running ones as stopping one does. The + * port's first clock therefore starts the others with it, at its rate + * and with no user: a display that comes later at that rate finds its + * clock running. + */ + for (unsigned int k = 1; !others && k <= ATC_DP_TUNNELS; k++) { + u32 unused; + + if (k == clock || dp->tunnel_rate[k - 1]) + continue; + if (!atc_dp_tunnel_start(dp, k, rate, src, &unused)) + dp->tunnel_idle |= BIT(k - 1); } - dp->tunnel_rate[i] = rate; dev_info(dp->dev, "DP tunnel clock %u: link rate 0x%02x, source %d, switch status %08x\n", clock, rate, src, v); return 0;