Improve Qualcomm EUD driver and platform support
Subsystems (5)
v10 cover Improve Qualcomm EUD driver and platform support
The Embedded USB Debugger (EUD) is a High-Speed USB on-chip hub that provides debug and trace capabilities on Qualcomm platforms. The current EUD driver, however, lacks essential hardware resources such as PHY references and support for multi-port configurations. This series addresses those gaps and introduces the necessary changes to enable EUD support on Qualcomm targets.
Below is a high-level block diagram showing the EUD and its connections.
EUD Block
+------------------------------+ | | [Conn-0]-->[USB2PHY-0]---->|-------- Path 0 --------------|-->[USBCtrl-0] | | [Conn-1]-->[USB2PHY-1]---->|-------- Path 1 --------------|-->[USBCtrl-1] | | | +------------------+ | | | EUD Debug Hub | | | +------------------+ | +------------------------------+
The series has been validated on the Qualcomm Dragonwing Q6 platform (RB3 Gen2 board), confirming successful OpenOCD connectivity to the EUD interface. For detailed usage instructions, refer to Qualcomm’s Linux kernel debugging guide:
https://docs.qualcomm.com/bundle/publicresource/topics/80-70020-12/debugging_linux_kernel.html#debug-using-openocd
Testing feedback:
- Konrad Dybcio reported running a slightly modified version of this series on Agatti with no obvious issues:
https://lore.kernel.org/all/[email protected]/
Regards,
Elson
---
Changes in v10:
- Separated the DT patch from the v9 series. This version contains
patches 1-7 only. Patch 8 (the DT patch) will be sent separately.
- Link to v9: https://lore.kernel.org/all/[email protected]/
Changes in v9:
- [Patch 0002] Initialize port_idx from the hardware EUD_REG_PORT_SEL
register in probe(sashiko bot).
- [Patch 0003] Fall back to primary if the hardware-selected port has no
matching devicetree path.
- [Patch 0004] Add missing of_node_get()/of_node_put() to keep the fwnode
valid for the lifetime of the registered role switch (sashiko bot).
- [Patch 0006] Avoid mixing goto with guard(mutex) per convention (sashiko bot)
- [Patch 0008] Reorder eud_con label references alphabetically(Konrad)
and extend this routing to newly added sm7325-xiaomi-lisa board file.
- Link to v8: https://lore.kernel.org/all/[email protected]/
Changes in v8:
- [Patch 0001] Require '#address-cells' and '#size-cells' for eud-path
nodes to address Sashiko bot feedback.
- [Patch 0004] Set path->curr_role before forwarding the role request to
the controller, as it reflects EUD's view of the role rather than the controller's outcome. This also addresses Sashiko feedback regarding
EUD hardware potentially remaining enabled when the controller fails
to complete the role switch.
- [Patch 0006] Acquire the lock in different execution paths to avoid
potential races.
- Link to v7: https://lore.kernel.org/all/[email protected]/
Changes in v7:
- [Patch 0001] Explicitly disallow the legacy ports representation for
SM8350, as pointed out by sashiko bot.
- [Patch 0004] Simplify fixed-role handling by relying on dr_mode directly instead of an indirect USB_ROLE_NONE check (Konrad).
- [Patch 0008] Squash the Kodiak EUD board endpoint remap into this patch,
as applying it separately leaves the OF graph bidirectionality broken.
- Link to v6: https://lore.kernel.org/all/[email protected]/
Changes in v6:
- [Patch 0001] Fix oneOf schema to properly enforce mutual exclusivity
between 'ports' and 'eud-path@N' (sashiko-bot).
- [Patch 0009] Extend the eud_con remote-endpoint fix to sm7325-motorola-dubai-common.dtsi and sm7325-xiaomi-taoyao.dts to fix
"not bidirectional" DT graph warning.
- Link to v5: https://lore.kernel.org/all/[email protected]/
Changes in v5:
- [Patch 0001] Add a compatible for a SoC that supports EUD over two
ports, restrict paths based on SoC hardware, and improve the commit
message [Krzysztof/Dmitry]
- [Patch 0002/0003] Document error codes in ABI doc.
- [Patch 0004] Zero-initialize the USB role switch descriptor [Peter].
Add a dr_mode check to handle cases where the USB controller
operates in a fixed role without role-switch support (based on
internal testing).
- [Patch 0006] Drop eud_disabled_for_host flag and control EUD based on
device role entry/exit [Peter]. Allow EUD to be powered on only in
device role and defer enablement in other roles until the port
switches to device role.
- Link to v4: https://lore.kernel.org/all/[email protected]/
Changes in v4:
- [Patch 0001] Restructure the flattened ports representation to a child-node based model.
- Preserve the top-level 'ports' property and add per-path child nodes, so that each role-switch path is described using its own OF graph. (Dmitry).
- Link to the discussion leading to this design decision:
https://lore.kernel.org/all/[email protected]/
- [Patch 0002] Use explicit port names when selecting the active EUD
port (Greg)
- [Patch 0003] Use a scoped iterator when looping over child nodes and
drop redundant EUD path validation checks (Konrad). Preserve support
for the legacy top-level ports description.
- [Patch 0004] Register role switch per path and forward the role switch notifications to the USB controller.
- [Patch 0006] Add host mode co-ordination based on the role changes as
per the new design and drop the custom API that was used to get role notifications.
- [Patch 0008] Described the UTMI path as a child node with role switch capability.
- Link to v3: https://lore.kernel.org/all/[email protected]/
Changes in RFC v3:
- Replaced the per-path (eud-path@N) model with a flattened ports
representation based on the feedback.
- Added port@2 and port@3 to support dual-port configurations.
- Removed the EUD-local 'phys' and 'usb-role-switch' properties since PHY
and role-switch information is obtained from walking the OF graph.
- Updated PHY discovery logic by fetching the PHY from the controller node/fwnode, and exported a new API for the controller to report role
changes. The dwc3-qcom driver now uses this API to notify EUD on role transitions.
- Updated the DTS structure by moving the EUD-to-controller port mapping
into the base SoC DTSI, enabling EUD by default, and adjusting all board
DTS files accordingly, including adding the usb-role-switch provider
link on connector nodes.
- Link to v2: https://lore.kernel.org/all/[email protected]/
Changes in v2:
- Improved commit message of patch 0001 and 0003 with historical context
on why EUD worked without PHY references on single-path systems.
Expanded the usb-role-switch property description in the bindings file.
- Link to v1: https://lore.kernel.org/all/[email protected]/
---
Elson Serrao (7):
dt-bindings: soc: qcom: eud: Add per-path child nodes for UTMI routing
usb: misc: qcom_eud: add sysfs attribute for port selection
usb: misc: qcom_eud: add per-path High-Speed PHY control
usb: misc: qcom_eud: add per-path role switch support
usb: misc: qcom_eud: improve enable_store API
usb: misc: qcom_eud: add role-based EUD control
usb: misc: qcom_eud: fix virtual attach/detach event handling
Documentation/ABI/testing/sysfs-driver-eud | 19 + .../bindings/soc/qcom/qcom,eud.yaml | 138 ++++++- drivers/usb/misc/qcom_eud.c | 369 ++++++++++++++++-- 3 files changed, 499 insertions(+), 27 deletions(-)
Signature · 1 line
2.34.1
PATCH v10 1/7 dt-bindings: soc: qcom: eud: Add per-path child nodes for UTMI routing
The Qualcomm Embedded USB Debugger (EUD) can intercept one or two High-Speed UTMI paths depending on the SoC. For example, SC7280 supports EUD on the primary UTMI path only, while SM8350 supports EUD on both primary and secondary UTMI paths.
Each UTMI path connects an independent USB controller/connector pair and forms its own role-switch domain. EUD routes traffic based on USB role. In device role the debug hub is inserted, while in host role it is bypassed.
The existing binding models EUD using a flattened ports representation. While sufficient for fixed device-role configurations, it cannot naturally associate a controller, connector, and role switch with a specific EUD-routable path. This is problematic for role-switch capable ports and becomes more pronounced on SoCs with multiple paths. In such cases, each path forms an independent role-switch domain and requires per-path role awareness.
Model each UTMI path as a separate child node with its own OF graph. This representation is used for role-aware EUD routing regardless of whether a SoC exposes one or two UTMI paths. Add an SM8350 compatible for dual-path EUD topologies. Retain support for the legacy flat ports representation on SC7280 for backward compatibility.
--- .../bindings/soc/qcom/qcom,eud.yaml | 138 +++++++++++++++++- 1 file changed, 137 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/soc/qcom/qcom,eud.yaml +137 -1
@@ -18,6 +18,7 @@ properties: items: - enum: - qcom,sc7280-eud + - qcom,sm8350-eud - const: qcom,eud reg:
@@ -45,10 +46,92 @@ properties: $ref: /schemas/graph.yaml#/properties/port description: This port is to be attached to the type C connector. + '#address-cells': + const: 1 + + '#size-cells': + const: 0 + +patternProperties: + "^eud-path@[0-1]$": + type: object + description: + Represents one High-Speed UTMI path that EUD intercepts. Use eud-path nodes + to associate role-switching behavior with specific port connections, allowing + EUD to manage role transitions independently for each UTMI path. + + properties: + reg: + maxItems: 1 + description: Path number + + usb-role-switch: + type: boolean + description: + Indicates that EUD relays USB role-switch events for this path and + performs role-dependent UTMI routing accordingly. In device role, + the EUD hub is inserted into this path to enable debug + functionality. In host role, the EUD hub is bypassed and UTMI + traffic flows directly between the PHY and the USB controller. + + ports: + $ref: /schemas/graph.yaml#/properties/ports + description: + These ports are to be attached to the endpoint of the USB controller node + and USB connector node. + + properties: + port@0: + $ref: /schemas/graph.yaml#/properties/port + description: This port is to be attached to the USB controller. + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: This port is to be attached to the USB connector. + + required: + - reg + - ports + + additionalProperties: false + required: - compatible - reg - - ports + +allOf: + - if: + properties: + compatible: + contains: + const: qcom,sc7280-eud + then: + oneOf: + - required: + - ports + properties: + eud-path@0: false + eud-path@1: false + - required: + - eud-path@0 + - '#address-cells' + - '#size-cells' + properties: + ports: false + eud-path@1: false + - if: + properties: + compatible: + contains: + const: qcom,sm8350-eud + then: + required: + - eud-path@0 + - eud-path@1 + - '#address-cells' + - '#size-cells' + properties: + ports: false additionalProperties: false
@@ -77,3 +160,56 @@ examples: }; }; }; + - | + eud@88e0000 { + compatible = "qcom,sm8350-eud", "qcom,eud"; + reg = <0x88e0000 0x2000>, + <0x88e2000 0x1000>; + #address-cells = <1>; + #size-cells = <0>; + + eud-path@0 { + reg = <0>; + usb-role-switch; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + eud_usb0: endpoint { + remote-endpoint = <&usb_1_dwc3_hs>; + }; + }; + + port@1 { + reg = <1>; + eud_con0: endpoint { + remote-endpoint = <&pmic_glink_hs_in>; + }; + }; + }; + }; + + eud-path@1 { + reg = <1>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + reg = <0>; + eud_usb1: endpoint { + remote-endpoint = <&usb_2_dwc3_hs>; + }; + }; + + port@1 { + reg = <1>; + eud_con1: endpoint { + remote-endpoint = <&conn_2_hs_in>; + }; + }; + }; + }; + };
Signature · 1 line
2.34.1
PATCH v10 2/7 usb: misc: qcom_eud: add sysfs attribute for port selection
In reply to Elson SerraoEUD can be mapped to either the primary USB port or the secondary USB port depending on the value of the EUD_PORT_SEL register. Add a 'port' sysfs attribute to allow userspace to select which port EUD should operate on and update the ABI documentation. This is needed for systems with dual USB ports where EUD needs to be accessible on either port depending on the system configuration and use case.
--- Documentation/ABI/testing/sysfs-driver-eud | 18 ++++++++++ drivers/usb/misc/qcom_eud.c | 42 ++++++++++++++++++++++ 2 files changed, 60 insertions(+)
Documentation/ABI/testing/sysfs-driver-eud +18 -0
@@ -7,3 +7,21 @@ Description: EUD based on a 1 or a 0 value. By enabling EUD, the user is able to activate the mini-usb hub of EUD for debug and trace capabilities. + +What: /sys/bus/platform/drivers/qcom_eud/.../port +Date: January 2026 +Contact: Elson Serrao <[email protected]> +Description: + Selects which USB port the Embedded USB Debugger (EUD) + is mapped to on platforms providing multiple High-Speed + USB ports. + + Valid values: + primary - Primary USB port + secondary - Secondary USB port + + Writing any other value returns -EINVAL. + + The attribute is writable only while EUD is disabled. + Writing it while EUD is enabled returns -EBUSY. Reading + the attribute returns the currently selected USB port.
drivers/usb/misc/qcom_eud.c +42 -0
75 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v10 3/7 usb: misc: qcom_eud: add per-path High-Speed PHY control
In reply to Elson SerraoEUD hardware can support multiple High-Speed USB paths, each routed through its own PHY. The active path is selected in hardware via the EUD_PORT_SEL register. As a High-Speed hub, EUD requires access to the High-Speed PHY associated with the active path. To support this multi-path capability, the driver must manage PHY resources on a per-path basis, ensuring that the PHY for the currently selected path is properly initialized and powered.
This patch restructures the driver to implement per-path PHY management. The driver now powers the appropriate PHY based on the selected and enabled UTMI path, ensuring correct operation when EUD is enabled.
Historically, EUD appeared to work on single-path systems because the USB controller kept the PHY initialized. However, EUD is designed to operate independently of the USB controller and therefore requires explicit PHY control for proper operation.
--- Documentation/ABI/testing/sysfs-driver-eud | 3 +- drivers/usb/misc/qcom_eud.c | 129 ++++++++++++++++++++- 2 files changed, 130 insertions(+), 2 deletions(-)
Documentation/ABI/testing/sysfs-driver-eud +2 -1
@@ -20,7 +20,8 @@ Description: primary - Primary USB port secondary - Secondary USB port - Writing any other value returns -EINVAL. + Writing any other value returns -EINVAL. Writing a port + not supported on the current platform returns -EOPNOTSUPP. The attribute is writable only while EUD is disabled. Writing it while EUD is enabled returns -EBUSY. Reading
drivers/usb/misc/qcom_eud.c +128 -1
187 lines not on this page · raw message
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 3/7] usb: misc: qcom_eud: add per-path High-Speed PHY control
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Medium] usb: misc: qcom_eud: eud_probe() fails when secondary path is disabled in DT --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] usb: misc: qcom_eud: eud_probe() fails when secondary path is disabled in DT
--
commit e2fd91a7c0ed5f3452a494a0a91ef1ddd34b1c26
Author: Elson Serrao <[email protected]>
usb: misc: qcom_eud: add per-path High-Speed PHY control
This commit adds per-path High-Speed PHY management to the Qualcomm EUD driver so that the PHY associated with the selected UTMI path is initialized and powered when EUD is enabled.
Quoted 4 lines
drivers/usb/misc/qcom_eud.c +0
-0
[ ... ]
Quoted 58 lines
drivers/usb/misc/qcom_eud.c +46
-0@@ -228,8 +294,54 @@ static void eud_role_switch_release(void *data)usb_role_switch_put (chip->role_sw); } +static int eud_init_path (struct eud_chip *chip,struct device_node *np) +{ +struct device_node *controller_node; +struct eud_path *path; +u32 path_num; +int ret; + + ret =of_property_read_u32 (np,"reg" , &path_num); +if (ret) { +/* Legacy DT uses 'ports' node without 'reg' property; treat as path 0 */ +if (of_node_name_eq (np,"ports" )) + path_num =0 ; +else +return dev_err_probe (chip->dev, ret,"unexpected child node '%s'\n" , + np->name); + } + +if (path_num >=EUD_MAX_PORTS ) +return dev_err_probe (chip->dev, -EINVAL ,"invalid path number: %u (max %d)\n" , + path_num,EUD_MAX_PORTS -1 ); + + path =devm_kzalloc (chip->dev,sizeof (*path),GFP_KERNEL ); +if (!path) +return -ENOMEM ; + + path->chip = chip; + path->num = path_num; + + controller_node =of_graph_get_remote_node (np,0 ,-1 ); +if (!controller_node) +return dev_err_probe (chip->dev, -ENODEV , +"failed to get controller node for path %u\n" , path_num); + + path->phy =devm_of_phy_get_by_index (chip->dev, controller_node,0 ); +of_node_put (controller_node); + +if (IS_ERR (path->phy)) +return dev_err_probe (chip->dev,PTR_ERR (path->phy), +"failed to get PHY for path %d\n" , path_num); + + chip->paths[path_num] = path; + +return 0 ; +} +static int eud_probe (struct platform_device *pdev) { +struct device_node *np = pdev->dev.of_node;struct eud_chip *chip;struct resource *res;int ret;@@ -258,7 +370,22 @@ static int eud_probe(struct platform_device *pdev)return -ENODEV ; chip->mode_mgr = res->start;
drivers/usb/misc/qcom_eud.c static int eud_probe(struct platform_device *pdev) · line 381
Quoted 10 lines
drivers/usb/misc/qcom_eud.c +9
-0+for_each_child_of_node_scoped (np, child) { + ret =eud_init_path (chip, child); +if (ret) +return ret; + } + +/* Primary path is mandatory. Secondary is optional */ +if (!chip->paths[0 ]) +return dev_err_probe (chip->dev, -ENODEV ,"primary path not found\n" );
[Severity: Medium]
Does eud_probe() fail on dual-path SoCs when a board disables the secondary path or its USB controller/PHY in Devicetree?
for_each_child_of_node_scoped() visits child nodes even when they are marked status = "disabled" (unlike for_each_available_child_of_node_scoped()). In Addition, on dual-path SoCs where the SoC dtsi defines both eud-path@0 and eud-path@1, if a board leaves the secondary USB controller disabled then of_graph_get_remote_node() returns NULL (failing probe with -ENODEV), and if the secondary High-Speed PHY is disabled then devm_of_phy_get_by_index() returns -EPROBE_DEFER indefinitely, preventing EUD from probing even for the primary port.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=3
Re: [PATCH v10 3/7] usb: misc: qcom_eud: add per-path High-Speed PHY control
Quoted 16 lines · On 11/23/2026 10:48 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Medium] usb: misc:qcom_eud:eud_probe()fails when secondary path is disabled in DT
--commit
e2fd91a7c0ed5f3452a494a0a91ef1ddd34b1c26
Author: Elson Serrao <[email protected]>usb: misc:
qcom_eud: add per-path High-Speed PHY controlThis commit adds per-path High-Speed PHY management to the Qualcomm EUD driver so that the PHY associated with the selected UTMI path is initialized and powered when EUD is enabled.
Quoted 1 line
drivers/usb/misc/qcom_eud.c +0
-0
[...]
Quoted 15 lines
drivers/usb/misc/qcom_eud.c static int eud_probe(struct platform_device *pdev) · line 381
Quoted 10 lines
drivers/usb/misc/qcom_eud.c +9
-0+for_each_child_of_node_scoped (np, child) { + ret =eud_init_path (chip, child); +if (ret) +return ret; + } + +/* Primary path is mandatory. Secondary is optional */ +if (!chip->paths[0 ]) +return dev_err_probe (chip->dev, -ENODEV ,"primary path not found\n" );[Severity: Medium]
Doeseud_probe()fail on dual-path SoCs when a board disables the secondary path or its USB controller/PHY in Devicetree?
Quoted 9 lines
for_each_child_of_node_scoped()visits child nodes even when they are marked status = "disabled" (unlikefor_each_available_child_of_node_scoped()). In Addition, on dual-path SoCs where the SoC dtsi defines both eud-path@0 and eud-path@1, if a board leaves the secondary USB controller disabled thenof_graph_get_remote_node()returns NULL (failing probe with-ENODEV), and if the secondary High-Speed PHY is disabled thendevm_of_phy_get_by_index()returns -EPROBE_DEFER indefinitely, preventing EUD from probing even for the primary port.
The binding defines both paths as required for dual-path SoCs (e.g. SM8350). The eud-path nodes represent the UTMI topology between the connector and the corresponding USB controller, not independently optional hardware resources. Therefore, disabling an eud-path node or the resources required by it is not a valid configuration for a dual-path topology. Probe failure or probe deferral is the expected outcome in such cases.
Thanks,
Elson
PATCH v10 4/7 usb: misc: qcom_eud: add per-path role switch support
In reply to Elson SerraoThe EUD hardware can support multiple High-Speed USB paths, each connected to different USB controllers. The current implementation uses a single chip-level role switch, which cannot properly handle multi-path configurations where each path needs independent role management. Since EUD is physically present between the USB connector and the controller, it should also relay the role change requests from the connector.
Restructure the driver to support per-path role switches and remove the chip-level role switch. Additionally, as EUD need not modify the USB role upon enabling, remove the unnecessary role switch call from enable_eud().
--- drivers/usb/misc/qcom_eud.c | 107 +++++++++++++++++++++++++++++------- 1 file changed, 88 insertions(+), 19 deletions(-)
drivers/usb/misc/qcom_eud.c +88 -19
@@ -45,12 +45,16 @@ static const char * const eud_port_names[] = {struct eud_path {struct eud_chip *chip;struct phy *phy; +struct usb_role_switch *controller_sw; +struct usb_role_switch *eud_sw; +struct device_node *np; +enum usb_role curr_role; +char name[16 ];u8 num; };struct eud_chip {struct device *dev; -struct usb_role_switch *role_sw;void __iomem *base;struct eud_path *paths[EUD_MAX_PORTS ];phys_addr_t mode_mgr;
@@ -124,7 +128,7 @@ static int enable_eud(struct eud_chip *priv)writel (EUD_INT_VBUS |EUD_INT_SAFE_MODE , priv->base +EUD_REG_INT1_EN_MASK ); -return usb_role_switch_set_role (priv->role_sw,USB_ROLE_DEVICE ); +return 0 ; }static int disable_eud (struct eud_chip *priv)
@@ -271,12 +275,15 @@ static irqreturn_t handle_eud_irq(int irq, void *data)static irqreturn_t handle_eud_irq_thread (int irq,void *data) {struct eud_chip *chip = data; +struct eud_path *path;int ret; + path = chip->paths[chip->port_idx]; +if (chip->usb_attached) - ret =usb_role_switch_set_role (chip->role_sw,USB_ROLE_DEVICE ); + ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_DEVICE );else - ret =usb_role_switch_set_role (chip->role_sw,USB_ROLE_HOST ); + ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_HOST );if (ret)dev_err (chip->dev,"failed to set role switch\n" );
@@ -287,17 +294,41 @@ static irqreturn_t handle_eud_irq_thread(int irq, void *data)return IRQ_HANDLED ; } -static void eud_role_switch_release (void *data) +static int eud_role_switch_set (struct usb_role_switch *sw,enum usb_role role) { -struct eud_chip *chip = data; +struct eud_path *path =usb_role_switch_get_drvdata (sw); +int ret; + +/* curr_role tracks the role from EUD's point of view */ + path->curr_role = role; + +/* Forward the role request to the USB controller */ + ret =usb_role_switch_set_role (path->controller_sw, role); +if (ret) { +dev_err (path->chip->dev,"failed to set role %s for port %u: %d\n" , +usb_role_string (role), path->num, ret); +return ret; + } -usb_role_switch_put (chip->role_sw); +return 0 ; +} + +static void eud_path_role_switch_release (void *data) +{ +struct eud_path *path = data; + +usb_role_switch_unregister (path->eud_sw); +usb_role_switch_put (path->controller_sw); +of_node_put (path->np); }static int eud_init_path (struct eud_chip *chip,struct device_node *np) { +struct usb_role_switch_desc role_sw_desc = {NULL }; +struct usb_role_switch *sw;struct device_node *controller_node;struct eud_path *path; +const char *dr_mode ="" ;u32 path_num;int ret;
@@ -328,14 +359,61 @@ static int eud_init_path(struct eud_chip *chip, struct device_node *np) "failed to get controller node for path %u\n", path_num); path->phy =devm_of_phy_get_by_index (chip->dev, controller_node,0 ); -of_node_put (controller_node); - -if (IS_ERR (path->phy)) +if (IS_ERR (path->phy)) { +of_node_put (controller_node);return dev_err_probe (chip->dev,PTR_ERR (path->phy),"failed to get PHY for path %d\n" , path_num); + } chip->paths[path_num] = path; +of_property_read_string (controller_node,"dr_mode" , &dr_mode); + +/* No role switch needed for fixed role controllers */ +if (!strcmp (dr_mode,"host" )) { + path->curr_role =USB_ROLE_HOST ; +of_node_put (controller_node); +return 0 ; + } + +if (!strcmp (dr_mode,"peripheral" )) { + path->curr_role =USB_ROLE_DEVICE ; +of_node_put (controller_node); +return 0 ; + } + + path->curr_role =USB_ROLE_NONE ; + + sw =usb_role_switch_find_by_fwnode (of_fwnode_handle (controller_node)); +if (!sw) { +of_node_put (controller_node); +return dev_err_probe (chip->dev, -EPROBE_DEFER , +"Failed to get controller role switch for path %d\n" , + path_num); + } + path->controller_sw = sw; + +of_node_put (controller_node); + + path->np =of_node_get (np); + role_sw_desc.fwnode =of_fwnode_handle (path->np); + role_sw_desc.set = eud_role_switch_set; + role_sw_desc.driver_data = path; +snprintf (path->name,sizeof (path->name),"eud-path%u" , path_num); + role_sw_desc.name = path->name; + + path->eud_sw =usb_role_switch_register (chip->dev, &role_sw_desc); +if (IS_ERR (path->eud_sw)) { +usb_role_switch_put (path->controller_sw); +of_node_put (path->np); +return dev_err_probe (chip->dev,PTR_ERR (path->eud_sw), +"Failed to register EUD role switch for path %d\n" , path_num); + } + + ret =devm_add_action_or_reset (chip->dev, eud_path_role_switch_release, path); +if (ret) +return ret; +return 0 ; }
@@ -352,15 +430,6 @@ static int eud_probe(struct platform_device *pdev) chip->dev = &pdev->dev; - chip->role_sw =usb_role_switch_get (&pdev->dev); -if (IS_ERR (chip->role_sw)) -return dev_err_probe (chip->dev,PTR_ERR (chip->role_sw), -"failed to get role switch\n" ); - - ret =devm_add_action_or_reset (chip->dev, eud_role_switch_release, chip); -if (ret) -return ret; - chip->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (chip->base))return PTR_ERR (chip->base);
Signature · 1 line
2.34.1
[email protected]
AI reviewRe: [PATCH v10 4/7] usb: misc: qcom_eud: add per-path role switch support
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [High] usb: misc: qcom_eud: infinite probe deferral and wrong fwnode in eud_init_path() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] usb: misc: qcom_eud: infinite probe deferral and wrong fwnode in eud_init_path()
--
commit 9854aac37e71428a22eccd3000ca7589c021cc4d
Author: Elson Serrao <[email protected]>
usb: misc: qcom_eud: add per-path role switch support
This commit replaces the chip-level USB role switch with per-path role switches that relay role changes from each USB connector to its corresponding USB controller.
Quoted 4 lines
drivers/usb/misc/qcom_eud.c +0
-0
[ ... ]
Quoted 41 lines
drivers/usb/misc/qcom_eud.c +29
-3@@ -328,14 +359,61 @@ static int eud_init_path(struct eud_chip *chip, struct device_node *np) "failed to get controller node for path %u\n", path_num); path->phy =devm_of_phy_get_by_index (chip->dev, controller_node,0 ); -of_node_put (controller_node); - -if (IS_ERR (path->phy)) +if (IS_ERR (path->phy)) { +of_node_put (controller_node);return dev_err_probe (chip->dev,PTR_ERR (path->phy),"failed to get PHY for path %d\n" , path_num); + } chip->paths[path_num] = path; +of_property_read_string (controller_node,"dr_mode" , &dr_mode); + +/* No role switch needed for fixed role controllers */ +if (!strcmp (dr_mode,"host" )) { + path->curr_role =USB_ROLE_HOST ; +of_node_put (controller_node); +return 0 ; + } + +if (!strcmp (dr_mode,"peripheral" )) { + path->curr_role =USB_ROLE_DEVICE ; +of_node_put (controller_node); +return 0 ; + } + + path->curr_role =USB_ROLE_NONE ; + + sw =usb_role_switch_find_by_fwnode (of_fwnode_handle (controller_node)); +if (!sw) { +of_node_put (controller_node); +return dev_err_probe (chip->dev, -EPROBE_DEFER , +"Failed to get controller role switch for path %d\n" , + path_num); + } + path->controller_sw = sw; +
drivers/usb/misc/qcom_eud.c static int eud_init_path(struct eud_chip *chip, struct device_node *np) · line 405
Quoted 10 lines
drivers/usb/misc/qcom_eud.c +10
-0+of_node_put (controller_node); + + path->np =of_node_get (np); + role_sw_desc.fwnode =of_fwnode_handle (path->np); + role_sw_desc.set = eud_role_switch_set; + role_sw_desc.driver_data = path; +snprintf (path->name,sizeof (path->name),"eud-path%u" , path_num); + role_sw_desc.name = path->name; + + path->eud_sw =usb_role_switch_register (chip->dev, &role_sw_desc);
[Severity: High]
As reported by Konrad Dybcio on v9 [1], will eud_init_path() defer probe forever when a controller omits dr_mode (or sets it to "otg") without a usb-role-switch property?
When a DWC3 node omits both dr_mode and usb-role-switch (such as usb_2_dwc3 on SM8350), dwc3_get_dr_mode() falls back to USB_DR_MODE_PERIPHERAL at runtime and dwc3_drd_init() never registers a usb_role_switch:
drivers/usb/dwc3/core.c:dwc3_get_dr_mode() {
...
if (mode == USB_DR_MODE_OTG && !dwc->edev &&
(!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
!device_property_read_bool(dwc->dev, "usb-role-switch")) &&
!DWC3_VER_IS_PRIOR(DWC3, 330A))
mode = USB_DR_MODE_PERIPHERAL;
...
}Because eud_init_path() only checks for explicit "host" and "peripheral" strings before calling usb_role_switch_find_by_fwnode(), eud_probe() will fail permanently with -EPROBE_DEFER on any board with such a path.
Also, when np is the legacy "ports" child node (handled earlier in eud_init_path()), setting role_sw_desc.fwnode to of_fwnode_handle(path->np) registers path->eud_sw on the "ports" node, which of_fwnode_graph_get_port_parent() skips in favor of the parent EUD device node during usb_role_switch_get() lookup, so the connector can never resolve path->eud_sw.
[1] https://lore.kernel.org/r/[email protected]
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=4
Re: [PATCH v10 4/7] usb: misc: qcom_eud: add per-path role switch support
Quoted 20 lines · On 11/23/2026 10:56 AM, [email protected] wrote:
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [High] usb: misc:qcom_eud: infinite probe deferral and wrong fwnode ineud_init_path()
--commit
9854aac37e71428a22eccd3000ca7589c021cc4d
Author: Elson Serrao <[email protected]>usb: misc:
qcom_eud: add per-path role switch supportThis commit replaces the chip-level USB role switch with per-path role switches that relay role changes from each USB connector to its corresponding USB controller.
Quoted 4 lines
drivers/usb/misc/qcom_eud.c +0
-0[ ... ]
[...]
Quoted 28 lines
drivers/usb/misc/qcom_eud.c static int eud_init_path(struct eud_chip *chip, struct device_node *np) · line 405
Quoted 7 lines
drivers/usb/misc/qcom_eud.c +7
-0+ role_sw_desc.fwnode =of_fwnode_handle (path->np); + role_sw_desc.set = eud_role_switch_set; + role_sw_desc.driver_data = path; +snprintf (path->name,sizeof (path->name),"eud-path%u" , path_num); + role_sw_desc.name = path->name; + + path->eud_sw =usb_role_switch_register (chip->dev, &role_sw_desc);[Severity: High]
As reported by Konrad Dybcio on v9 [1], willeud_init_path()defer probe forever when a controller omitsdr_mode(or sets it to "otg") without a usb-role-switch property?When a DWC3 node omits both
dr_modeand usb-role-switch (such asusb_2_dwc3on SM8350),dwc3_get_dr_mode()falls back toUSB_DR_MODE_PERIPHERALat runtime anddwc3_drd_init()never registers ausb_role_switch:drivers/usb/dwc3/core.c:dwc3_get_dr_mode() { ... if (mode == USB_DR_MODE_OTG && !dwc->edev && (!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) || !device_property_read_bool(dwc->dev, "usb-role-switch")) && !DWC3_VER_IS_PRIOR(DWC3, 330A)) mode = USB_DR_MODE_PERIPHERAL; ... }
Quoted 4 lines
Because
eud_init_path()only checks for explicit "host" and "peripheral" strings before callingusb_role_switch_find_by_fwnode(),eud_probe()will fail permanently with -EPROBE_DEFER on any board with such a path.
This corner case was discussed during the v9 review. The consensus was
that EUD is expected to be used with dual-role capable controllers,
while support for controllers that resolve to a fixed role at runtime
can be addressed as a follow-up improvement.
Link to this discussion: https://lore.kernel.org/all/[email protected]/
Quoted 7 lines
Also, when np is the legacy "ports" child node (handled earlier in
eud_init_path()), setting role_sw_desc.fwnode toof_fwnode_handle(path->np)registerspath->eud_swon the "ports" node, whichof_fwnode_graph_get_port_parent()skips in favor of the parent EUD device node duringusb_role_switch_get()lookup, so the connector can never resolvepath->eud_sw.
The legacy ports binding does not describe EUD as a connector-facing role switch. It does not define a usb-role-switch property on either the EUD node or its ports container. As EUD is not marked as role-switch capable, the connector never attempts to resolve a role switch [1]. Therefore, the described lookup scenario does not apply to the legacy binding.
Thanks
Elson
PATCH v10 5/7 usb: misc: qcom_eud: improve enable_store API
In reply to Elson SerraoCurrently enable_store() allows operations irrespective of the EUD state, which can result in redundant operations. Avoid this by adding duplicate state checks to skip requests when EUD is already in the desired state. Additionally, improve error handling with explicit logging to provide better feedback.
--- drivers/usb/misc/qcom_eud.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-)
drivers/usb/misc/qcom_eud.c +15 -6
@@ -164,18 +164,27 @@ static ssize_t enable_store(struct device *dev,if (kstrtobool (buf, &enable))return -EINVAL ; +/* Skip operation if already in desired state */ +if (chip->enabled == enable) +return count; +if (enable) { ret =enable_eud (chip); -if (!ret) - chip->enabled = enable; -else -disable_eud (chip); - +if (ret) { +dev_err (chip->dev,"failed to enable eud\n" ); +return ret; + } }else { ret =disable_eud (chip); +if (ret) { +dev_err (chip->dev,"failed to disable eud\n" ); +return ret; + } } -return ret <0 ? ret : count; + chip->enabled = enable; + +return count; }static DEVICE_ATTR_RW (enable);
Signature · 1 line
2.34.1
PATCH v10 6/7 usb: misc: qcom_eud: add role-based EUD control
In reply to Elson SerraoEUD functions by presenting itself as a USB device to the host PC and is therefore only applicable when the port operates in device role. Keeping EUD enabled in other roles provides no benefit and unnecessarily keeps the associated PHY resources enabled. Furthermore, enabling EUD in host role can cause the USB controller to misbehave because the EUD hub supports only a single upstream-facing port.
Address this by treating EUD as usable only in device role. The role-switch callback enables or disables EUD as the port enters or leaves device role. A sysfs enable request made outside device role is recorded and honored when the port subsequently switches to device role. Additionally, synchronize EUD state management across different paths to avoid races and maintain consistent hardware state.
--- drivers/usb/misc/qcom_eud.c | 70 ++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 8 deletions(-)
drivers/usb/misc/qcom_eud.c +62 -8
@@ -15,6 +15,7 @@#include <linux/phy/phy.h> #include <linux/platform_device.h> #include <linux/slab.h> +#include <linux/string_choices.h> #include <linux/sysfs.h> #include <linux/usb/role.h> #include <linux/firmware/qcom/qcom_scm.h>
@@ -57,6 +58,8 @@ struct eud_chip {struct device *dev;void __iomem *base;struct eud_path *paths[EUD_MAX_PORTS ]; +/* serializes EUD control operations */ +struct mutex state_lock;phys_addr_t mode_mgr;unsigned int int_status;int irq;
@@ -158,17 +161,33 @@ static ssize_t enable_store(struct device *dev, const char *buf, size_t count) {struct eud_chip *chip =dev_get_drvdata (dev); +struct eud_path *path;bool enable;int ret;if (kstrtobool (buf, &enable))return -EINVAL ; +guard (mutex)(&chip->state_lock); +/* Skip operation if already in desired state */ if (chip->enabled == enable)return count;if (enable) { + path = chip->paths[chip->port_idx]; + +/* +* If not yet in device role, honor the userspace request and defer +* EUD enablement until the port transitions to device role in the +* set_role callback. +*/ +if (path->curr_role !=USB_ROLE_DEVICE ) { +dev_info (chip->dev,"Deferring EUD enable until port enters device mode\n" ); + chip->enabled = enable; +return count; + } + ret =enable_eud (chip);if (ret) {dev_err (chip->dev,"failed to enable eud\n" );
@@ -206,6 +225,8 @@ static ssize_t port_store(struct device *dev, struct device_attribute *attr,if (port <0 )return port; +guard (mutex)(&chip->state_lock); +/* Check if the corresponding path is available */ if (!chip->paths[port])return -EOPNOTSUPP ;
@@ -287,14 +308,18 @@ static irqreturn_t handle_eud_irq_thread(int irq, void *data)struct eud_path *path;int ret; +guard (mutex)(&chip->state_lock); + path = chip->paths[chip->port_idx]; -if (chip->usb_attached) - ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_DEVICE ); -else - ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_HOST ); -if (ret) -dev_err (chip->dev,"failed to set role switch\n" ); +if (chip->enabled && path->curr_role ==USB_ROLE_DEVICE ) { +if (chip->usb_attached) + ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_DEVICE ); +else + ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_HOST ); +if (ret) +dev_err (chip->dev,"failed to set role switch\n" ); + }/* set and clear vbus_int_clr[0] to clear interrupt */ writel (BIT (0 ), chip->base +EUD_REG_VBUS_INT_CLR );
@@ -306,7 +331,30 @@ static irqreturn_t handle_eud_irq_thread(int irq, void *data)static int eud_role_switch_set (struct usb_role_switch *sw,enum usb_role role) {struct eud_path *path =usb_role_switch_get_drvdata (sw); -int ret; +struct eud_chip *chip = path->chip; +int ret =0 ; + +guard (mutex)(&chip->state_lock); + +/* +* EUD is usable only in device role. Power it down for every other +* role to avoid keeping an unusable module 'ON'. chip->enabled +* preserves user's sysfs configuration and is not modified across +* role transitions. +*/ +if (chip->enabled && path->num == chip->port_idx && role != path->curr_role) { +if (role ==USB_ROLE_DEVICE ) + ret =enable_eud (chip); +else if (path->curr_role ==USB_ROLE_DEVICE ) + ret =disable_eud (chip); + +if (ret) { +dev_err (chip->dev,"failed to %s EUD for role %s: %d\n" , +str_enable_disable (role ==USB_ROLE_DEVICE ), +usb_role_string (role), ret); +return ret; + } + }/* curr_role tracks the role from EUD's point of view */ path->curr_role = role;
@@ -439,6 +487,8 @@ static int eud_probe(struct platform_device *pdev) chip->dev = &pdev->dev; +mutex_init (&chip->state_lock); + chip->base =devm_platform_ioremap_resource (pdev,0 );if (IS_ERR (chip->base))return PTR_ERR (chip->base);
@@ -485,8 +535,12 @@ static void eud_remove(struct platform_device *pdev) {struct eud_chip *chip =platform_get_drvdata (pdev); -if (chip->enabled) +mutex_lock (&chip->state_lock); +if (chip->enabled) {disable_eud (chip); + chip->enabled = false; + } +mutex_unlock (&chip->state_lock);device_init_wakeup (&pdev->dev, false);disable_irq_wake (chip->irq);
Signature · 1 line
2.34.1
PATCH v10 7/7 usb: misc: qcom_eud: fix virtual attach/detach event handling
In reply to Elson SerraoEUD provides virtual USB attach/detach events to simulate cable plug/unplug while maintaining the physical debug connection. However, the current implementation incorrectly sets the USB role to HOST on virtual detach, which doesn't represent the disconnected state.
Fix the virtual detach handling by setting the USB role to NONE instead of HOST, correctly representing the disconnected state.
--- drivers/usb/misc/qcom_eud.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
drivers/usb/misc/qcom_eud.c +17 -1
@@ -313,10 +313,26 @@ static irqreturn_t handle_eud_irq_thread(int irq, void *data) path = chip->paths[chip->port_idx];if (chip->enabled && path->curr_role ==USB_ROLE_DEVICE ) { +/* +* EUD virtual attach/detach event handling for low power debugging: +* +* When EUD is enabled in debug mode, the device remains physically +* connected to the PC throughout the debug session, keeping the USB +* controller active. This prevents testing of low power scenarios that +* require USB disconnection. +* +* EUD solves this by providing virtual USB attach/detach events while +* maintaining the physical connection. These events are triggered from +* the Host PC via the enumerated EUD control interface and delivered +* to the EUD driver as interrupts. +* +* These notifications are forwarded to the USB controller through role +* switch framework. +*/ if (chip->usb_attached) ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_DEVICE );else - ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_HOST ); + ret =usb_role_switch_set_role (path->controller_sw,USB_ROLE_NONE );if (ret)dev_err (chip->dev,"failed to set role switch\n" ); }
Signature · 1 line
2.34.1
[email protected]
AI reviewSashiko has finished reviewing this 7-patch series:
Sashiko has finished reviewing this 7-patch series:
- Patches 1, 2, and 5-7: no issues found.
- Patch 3 ("usb: misc: qcom_eud: add per-path High-Speed PHY con..."): 1 potential issue (1 Medium)
- Patch 4 ("usb: misc: qcom_eud: add per-path role switch support"): 1 potential issue (1 High)
Detailed reviews have been sent as separate replies to patches 3 and 4.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]