Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 79 additions & 9 deletions arch/arm64/boot/dts/apple/t6040-j773s-usb-front.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
/*
* The J773s's two front USB-C ports: an on-board USB2/USB3 hub behind ATC3,
* whose controller (ADT usb-drd3) is a fixed host with no PD controller.
* The hub's firmware is on its own flash (ADT spi3 usb3hub-flash).
* The hub's firmware is on its own flash (ADT spi3 usb3hub-flash): the same
* hub as on the M4 Mac mini (J773g), with the same firmware id, on raw USB2
* root port 1 and SuperSpeed root port 2 (ADT usb-drd3-port-hs/-ss).
*
* Disabled until the T6040 PHY driver has a fixed-host mode: it brings USB3
* up only for a Type-C plug orientation. Enabling this also takes the ATC3
* power domains. Tunables are this ADT's atc-phy3 and usb-drd3 tables
* The hub child tells dwc3-apple the controller is a host from probe on, and
* the graph link from the PHY's USB3 port to the controller's SuperSpeed port
* is how the PHY finds that fixed hub: it then runs USB3 on the lanes of a
* normal plug orientation, as the ADT gives for atc-phy3, with no orientation
* switch. The hub's reset and SPI-flash output-enable lines (ADT
* usb3hub_rst, usb3hub_flash_oe) are AP GPIOs; the boot loader leaves both
* high, as macOS does. Tunables are this ADT's atc-phy3 and usb-drd3 tables
* (macOS 26.6.2); DRD_USB31_GBL_DEFAULT is followed by the GCTL.PWRDNSCALE
* entry the other ports use.
*/
Expand Down Expand Up @@ -211,7 +217,18 @@
<0x44 0x00000004 0x00000004>;
apple,tunable-usb2-host =
<0x8 0x00007003 0x00000003>;
status = "disabled";

ports {
#address-cells = <1>;
#size-cells = <0>;

port@1 {
reg = <1>;
atcphy3_usb3: endpoint {
remote-endpoint = <&dwc3_3_ss>;
};
};
};
};

atcphy3_mbox: mailbox@39b148000 {
Expand All @@ -226,7 +243,6 @@
"recv-empty", "recv-not-empty";
#mbox-cells = <0>;
power-domains = <&ps_atc3_phymxwrap>;
status = "disabled";
};

dwc3_3_dart_0: iommu@39af00000 {
Expand All @@ -237,7 +253,6 @@
power-domains = <&ps_atc3_usb>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x4000 0x0 0xffff0000>;
status = "disabled";
};

dwc3_3_dart_1: iommu@39af80000 {
Expand All @@ -248,7 +263,6 @@
power-domains = <&ps_atc3_usb>;
#iommu-cells = <1>;
apple,dma-range = <0x100 0x4000 0x0 0xffff0000>;
status = "disabled";
};

dwc3_3: usb@39a280000 {
Expand All @@ -260,6 +274,8 @@
interrupt-parent = <&aic>;
interrupts = <AIC_IRQ 1715 IRQ_TYPE_LEVEL_HIGH>;
dr_mode = "host";
#address-cells = <1>;
#size-cells = <0>;
iommus = <&dwc3_3_dart_0 0>, <&dwc3_3_dart_1 1>;
power-domains = <&ps_atc3_usb>;
resets = <&atcphy3>;
Expand Down Expand Up @@ -288,6 +304,60 @@
apple,tunable-gbl-default =
<0x64 0x00000002 0x00000000>,
<0x10 0xfff80000 0x00680000>;
status = "disabled";

hub@1 {
compatible = "usb5ac,800b";
reg = <1>;
};

ports {
#address-cells = <1>;
#size-cells = <0>;

/* Raw xHCI port 1 is USB2; raw port 2 is SuperSpeed. */
port@2 {
reg = <2>;
dwc3_3_ss: endpoint {
remote-endpoint = <&atcphy3_usb3>;
};
};
};
};
};

&pinctrl {
usb3hub-flash-oe-hog {
gpio-hog;
gpios = <130 GPIO_ACTIVE_HIGH>;
output-high;
line-name = "usb3hub-flash-oe";
};

usb3hub-reset-hog {
gpio-hog;
gpios = <127 GPIO_ACTIVE_HIGH>;
output-high;
line-name = "usb3hub-reset";
};
};

/* The ATC3 domains, which t604x-pmgr.dtsi leaves disabled. */
&ps_atc3_common {
status = "okay";
};

&ps_atc3_usb_aon {
status = "okay";
};

&ps_atc3_usb {
status = "okay";
};

&ps_atc3_phymxwrap {
status = "okay";
};

&ps_atc3_common_dp {
status = "okay";
};
55 changes: 42 additions & 13 deletions drivers/phy/apple/t6040-usb2.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
* stops the coprocessor and resets its RTKit state, and puts the PHY to
* sleep, as macOS does on every detach: every attach boots the firmware again.
* Without a plug orientation, or when the coprocessor does not come up, the
* PIPE stays on the dummy PHY and the port keeps working at USB2.
* PIPE stays on the dummy PHY and the port keeps working at USB2. A PHY wired
* to an on-board hub instead of a connector has no orientation switch: its
* lanes have the fixed orientation of t6040_usb3_fixed_hub().
*
* The driver performs no ATC-register writes during probe. The power
* sequences only cover the PHY: the host controller must be stopped before
Expand All @@ -40,6 +42,7 @@
#include <linux/module.h>
#include <linux/mutex.h>
#include <linux/of.h>
#include <linux/of_graph.h>
#include <linux/of_platform.h>
#include <linux/phy/phy.h>
#include <linux/platform_device.h>
Expand Down Expand Up @@ -2209,6 +2212,28 @@ static bool t6040_map_regions(struct t6040_usb2_phy *tphy, struct platform_devic
return tphy->regs[T6040_USB3_CORE] && tphy->regs[T6040_USB3_CFG];
}

/*
* Whether the PHY is wired to an on-board hub instead of a Type-C connector,
* as on the Mac mini's front ports: the board describes the hub as a child of
* the controller the PHY's USB3 port (graph port 1) is linked to, as it does
* for dwc3-apple. There is no port controller, so no orientation switch and
* no cable event, and the hub's SuperSpeed pair sits on the lanes of a plug
* in normal orientation: the ADT gives every such fixed ATC PHY plug
* orientation 1, as it does the laptops' HDMI converter PHYs, which run
* unflipped.
*/
static bool t6040_usb3_fixed_hub(struct device *dev)
{
struct device_node *ep __free(device_node) =
of_graph_get_endpoint_by_regs(dev->of_node, 1, -1);
struct device_node *ctrl __free(device_node) =
ep ? of_graph_get_remote_port_parent(ep) : NULL;
struct device_node *hub __free(device_node) =
ctrl ? of_get_available_child_by_name(ctrl, "hub") : NULL;

return hub;
}

/*
* Everything USB3 needs from the device tree. A missing piece leaves the
* port at USB2; only a mailbox that has not probed yet defers.
Expand All @@ -2232,19 +2257,23 @@ static int t6040_usb3_probe(struct t6040_usb2_phy *tphy, struct platform_device
phy_set_drvdata(tphy->usb3, tphy);
init_completion(&tphy->app_reply);

if (!of_property_present(dev->of_node, "orientation-switch"))
if (of_property_present(dev->of_node, "orientation-switch")) {
/*
* Registered first: tipd waits for the switch the DT names, so the
* port keeps USB2, roles and PD even if a USB3 piece below is missing.
*/
sw = typec_switch_register(dev, &sw_desc);
if (IS_ERR(sw))
return PTR_ERR(sw);
ret = devm_add_action_or_reset(dev, t6040_usb3_switch_unregister, sw);
if (ret)
return ret;
} else if (t6040_usb3_fixed_hub(dev)) {
/* Nothing ever sets it again: the lanes stay where the hub is. */
tphy->orientation = TYPEC_ORIENTATION_NORMAL;
} else {
return 0;

/*
* Registered first: tipd waits for the switch the DT names, so the port
* keeps USB2, roles and PD even if a USB3 piece below is missing.
*/
sw = typec_switch_register(dev, &sw_desc);
if (IS_ERR(sw))
return PTR_ERR(sw);
ret = devm_add_action_or_reset(dev, t6040_usb3_switch_unregister, sw);
if (ret)
return ret;
}

for (i = 0; i < T6040_USB3_NR_REGIONS; i++) {
if (!tphy->regs[i]) {
Expand Down
Loading