Skip to contentSkip to conversation

phy: tegra: xusb: Default otg mode to peripheral

PATCH In review Aaron Kling 2 participants 5 messages May 6, 2025 – May 13, 2025

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

v2 cover phy: tegra: xusb: Default otg mode to peripheral

---
Changes in v2:
- Add new patch to document role-switch-default-mode in xusb padctl
- Simplify code change, per review
- Comment in code why device mode is default
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Aaron Kling (2):
dt-bindings: phy: tegra-xusb: Document role-switch-default-mode
phy: tegra: xusb: Default otg mode to peripheral

 .../bindings/phy/nvidia,tegra124-xusb-padctl.yaml  | 33 ++++++++++++++++++++
 .../bindings/phy/nvidia,tegra186-xusb-padctl.yaml  | 27 ++++++++++++++++
 .../bindings/phy/nvidia,tegra194-xusb-padctl.yaml  | 36 ++++++++++++++++++++++
 .../bindings/phy/nvidia,tegra210-xusb-padctl.yaml  | 36 ++++++++++++++++++++++
 drivers/phy/tegra/xusb.c                           | 11 +++----
 5 files changed, 136 insertions(+), 7 deletions(-)

---
base-commit: 91e5bfe317d8f8471fbaa3e70cf66cae1314a516
change-id: 20250404-xusb-peripheral-c45b1637f33b

Best regards,

Signature · 1 line
Aaron Kling <[email protected]>
#1 lore raw

PATCH v2 1/2 dt-bindings: phy: tegra-xusb: Document role-switch-default-mode

This property is used to default an otg port to host or peripheral.

---
 .../bindings/phy/nvidia,tegra124-xusb-padctl.yaml  | 33 ++++++++++++++++++++
 .../bindings/phy/nvidia,tegra186-xusb-padctl.yaml  | 27 ++++++++++++++++
 .../bindings/phy/nvidia,tegra194-xusb-padctl.yaml  | 36 ++++++++++++++++++++++
 .../bindings/phy/nvidia,tegra210-xusb-padctl.yaml  | 36 ++++++++++++++++++++++
 4 files changed, 132 insertions(+)
Documentation/devicetree/bindings/phy/nvidia,tegra124-xusb-padctl.yaml +33 -0
index 33b41b6b2fd539450f9ce72db8bba204e9c08eba..f383f25d932071bb4e4c86cb9f87f51e6a59aaac 100644
@@ -357,10 +357,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
+        dependencies:
+          role-switch-default-mode: [ usb-role-switch ]
+
       usb2-1:
         type: object
         additionalProperties: false
@@ -392,10 +403,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
+        dependencies:
+          role-switch-default-mode: [ usb-role-switch ]
+
       usb2-2:
         type: object
         additionalProperties: false
@@ -427,10 +449,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
+        dependencies:
+          role-switch-default-mode: [ usb-role-switch ]
+
       ulpi-0:
         type: object
         additionalProperties: false
Documentation/devicetree/bindings/phy/nvidia,tegra186-xusb-padctl.yaml +27 -0
index 8b1d5a8529e38a1956a60e402c40ebec089ff2e9..f38ed6d339f125df136bcf0e954efb9f5b46466a 100644
@@ -260,12 +260,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-1:
         type: object
@@ -298,12 +307,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-2:
         type: object
@@ -336,12 +354,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       hsic-0:
         type: object
Documentation/devicetree/bindings/phy/nvidia,tegra194-xusb-padctl.yaml +36 -0
index 6e3398399628766e820ff2a5da0ee644dcdee956..8253ff3ac5e8cffba16ddca3fbbc0fa32b58384f 100644
@@ -251,12 +251,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-1:
         type: object
@@ -289,12 +298,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-2:
         type: object
@@ -327,12 +345,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-3:
         type: object
@@ -365,12 +392,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb3-0:
         type: object
Documentation/devicetree/bindings/phy/nvidia,tegra210-xusb-padctl.yaml +36 -0
index e9237c58ce45df7fa25cac861891b3fe76efe83d..c14bb947d306912fb732ff219511c6d6fda80f7c 100644
@@ -379,12 +379,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-1:
         type: object
@@ -417,12 +426,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-2:
         type: object
@@ -455,12 +473,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       usb2-3:
         type: object
@@ -493,12 +520,21 @@ properties:
 
               See ../connector/usb-connector.yaml.
 
+          role-switch-default-mode:
+            description:
+              Indicates if usb-role-switch is enabled, the device default operation
+              mode of controller while usb role is USB_ROLE_NONE.
+            $ref: /schemas/types.yaml#/definitions/string
+            enum: [host, peripheral]
+            default: peripheral
+
           vbus-supply:
             description: A phandle to the regulator supplying the VBUS
               voltage.
 
         dependencies:
           usb-role-switch: [ connector ]
+          role-switch-default-mode: [ usb-role-switch ]
 
       hsic-0:
         type: object
Signature · 1 line
2.48.1
#2 lore raw

PATCH v2 2/2 phy: tegra: xusb: Default otg mode to peripheral

In reply to Aaron Kling

Currently, if usb-role-switch is set and role-switch-default-mode is not, a xusb port will be inoperable until that port is hotplugged, because the driver defaults to role none. Instead of requiring all devices to set the default mode, assume that the port is primarily intended for use in device mode.

---
 drivers/phy/tegra/xusb.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
drivers/phy/tegra/xusb.c +4 -7
index 79d4814d758d5e1f0e8200d61e131606adbb0e2d..22338f3f24a0794c22544a0e16e0fc706c4fb6d7 100644
@@ -726,18 +726,15 @@ static int tegra_xusb_setup_usb_role_switch(struct tegra_xusb_port *port)
 
 static void tegra_xusb_parse_usb_role_default_mode(struct tegra_xusb_port *port)
 {
-	enum usb_role role = USB_ROLE_NONE;
+	/* Most switchable usb ports are normally used in device mode */
+	enum usb_role role = USB_ROLE_DEVICE;
 	enum usb_dr_mode mode = usb_get_role_switch_default_mode(&port->dev);
 
 	if (mode == USB_DR_MODE_HOST)
 		role = USB_ROLE_HOST;
-	else if (mode == USB_DR_MODE_PERIPHERAL)
-		role = USB_ROLE_DEVICE;
 
-	if (role != USB_ROLE_NONE) {
-		usb_role_switch_set_role(port->usb_role_sw, role);
-		dev_dbg(&port->dev, "usb role default mode is %s", modes[mode]);
-	}
+	usb_role_switch_set_role(port->usb_role_sw, role);
+	dev_dbg(&port->dev, "usb role default mode is %s", modes[mode]);
 }
 
 static int tegra_xusb_usb2_port_parse_dt(struct tegra_xusb_usb2_port *usb2)
Signature · 1 line
2.48.1
maintainer
#3 lore raw
In reply to Aaron Kling
Quoted 7 lines · On 06/05/2025 18:09, Aaron Kling via B4 Relay wrote:

---
Changes in v2:
- Add new patch to document role-switch-default-mode in xusb padctl
- Simplify code change, per review
- Comment in code why device mode is default
- Link to v1: https://lore.kernel.org/r/[email protected]

I have been asking our team about this and this is the feedback I received ...

"By design, a port’s data role starts out as USB_ROLE_NONE.
It remains in that state until a dedicated role‐switch driver, such as the GPIO-based driver, usb-conn-gpio, or a Type-C controller driver, CCG, probes VBUS/ID or CC lines and tells the USB core whether to switch to host or device. The role-switch-default-mode DT property exists precisely for controlled use cases where a board truly only ever needs one role and doesn’t include any role-detection hardware.
In that scenario, you’re effectively opting out of dynamic role switching.
In the general OTG case, though, we shouldn’t assume the data role of an OTG port.

In his case, he should work out
1. If his platform has a role-switch component, then he should enable it rather than adding this change.
2. If his platform doesn’t have a role-switch controller, add role-switch-default-mode = "peripheral"; to the PHY node instead of changing the core driver."

So I guess the question is, does your platform have a role-switch controller?

The bottom line here is that we don't want to make this change by default for all Tegra platforms.

Thanks
Jon

Signature · 1 line
nvpublic
#4 lore raw
Quoted 34 lines · Jon Hunter
Quoted 7 lines · On 06/05/2025 18:09, Aaron Kling via B4 Relay wrote:

---
Changes in v2:
- Add new patch to document role-switch-default-mode in xusb padctl
- Simplify code change, per review
- Comment in code why device mode is default
- Link to v1: https://lore.kernel.org/r/[email protected]

I have been asking our team about this and this is the feedback I received ...

"By design, a port’s data role starts out as USB_ROLE_NONE.
It remains in that state until a dedicated role‐switch driver, such as the GPIO-based driver, usb-conn-gpio, or a Type-C controller driver, CCG, probes VBUS/ID or CC lines and tells the USB core whether to switch to host or device.
The role-switch-default-mode DT property exists precisely for controlled use cases where a board truly only ever needs one role and doesn’t include any role-detection hardware.
In that scenario, you’re effectively opting out of dynamic role switching. In the general OTG case, though, we shouldn’t assume the data role of an OTG port.

In his case, he should work out
1. If his platform has a role-switch component, then he should enable it rather than adding this change.
2. If his platform doesn’t have a role-switch controller, add role-switch-default-mode = "peripheral"; to the PHY node instead of changing the core driver."

Quoted 5 lines

So I guess the question is, does your platform have a role-switch controller?

The bottom line here is that we don't want to make this change by default for all Tegra platforms.

I wasn't familiar with role-switch controllers and that seems to have been my problem. I wasn't loading the usb-conn-gpio or ucsi_ccg modules which was why the current role wasn't being auto-detected. After loading those, the majority of the Jetson devkits and Shield devices I'm targeting worked as expected without this change. The only failure I've seen so far is p3509+p3636. And I've got a fix I'll push separately for that. So this series can be abandoned.

Sincerely,
Aaron