linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc3: Allow usb role swich control from userspace
       [not found] <CGME20251020112840epcas5p28d8eded5200f096e7b80f71899371f2c@epcas5p2.samsung.com>
@ 2025-10-20 11:37 ` Pritam Manohar Sutar
  2025-10-21 22:09   ` Thinh Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Pritam Manohar Sutar @ 2025-10-20 11:37 UTC (permalink / raw)
  To: Thinh.Nguyen, gregkh
  Cc: linux-usb, linux-kernel, rosa.pila, dev.tailor, faraz.ata,
	muhammed.ali, selvarasu.g, Pritam Manohar Sutar

There is a possibility of user needs for USB mode switching on boards
that lack external hardware support for dynamic host/device role
detection.

Add an `allow_userspace_control` flag to handle such cases. When
enabled, it exposes a sysfs attribute that allows userspace to switch
the USB role manually between host and device. This provides flexibility
for platforms that cannot rely on hardware-based mode detection.

The role switch can be done as below
echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role

Signed-off-by: Pritam Manohar Sutar <pritam.sutar@samsung.com>
---
 drivers/usb/dwc3/drd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
index 4c91240eb429..589bbeb27454 100644
--- a/drivers/usb/dwc3/drd.c
+++ b/drivers/usb/dwc3/drd.c
@@ -515,6 +515,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc)
 	dwc3_role_switch.set = dwc3_usb_role_switch_set;
 	dwc3_role_switch.get = dwc3_usb_role_switch_get;
 	dwc3_role_switch.driver_data = dwc;
+	dwc3_role_switch.allow_userspace_control = true;
 	dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
 	if (IS_ERR(dwc->role_sw))
 		return PTR_ERR(dwc->role_sw);
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: Allow usb role swich control from userspace
  2025-10-20 11:37 ` [PATCH] usb: dwc3: Allow usb role swich control from userspace Pritam Manohar Sutar
@ 2025-10-21 22:09   ` Thinh Nguyen
  2025-10-23  9:55     ` Pritam Manohar Sutar
  0 siblings, 1 reply; 5+ messages in thread
From: Thinh Nguyen @ 2025-10-21 22:09 UTC (permalink / raw)
  To: Pritam Manohar Sutar
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	rosa.pila@samsung.com, dev.tailor@samsung.com,
	faraz.ata@samsung.com, muhammed.ali@samsung.com,
	selvarasu.g@samsung.com

On Mon, Oct 20, 2025, Pritam Manohar Sutar wrote:
> There is a possibility of user needs for USB mode switching on boards
> that lack external hardware support for dynamic host/device role
> detection.

It's fine to enable this. But base on this change log, it sounds like
there's no use case at the moment? If there is one, even if it's only
for debugging purpose, please note it so. I'm hesitant to accept changes
base on use case speculation only.

Thanks,
Thinh

> 
> Add an `allow_userspace_control` flag to handle such cases. When
> enabled, it exposes a sysfs attribute that allows userspace to switch
> the USB role manually between host and device. This provides flexibility
> for platforms that cannot rely on hardware-based mode detection.
> 
> The role switch can be done as below
> echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> 
> Signed-off-by: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> ---
>  drivers/usb/dwc3/drd.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c
> index 4c91240eb429..589bbeb27454 100644
> --- a/drivers/usb/dwc3/drd.c
> +++ b/drivers/usb/dwc3/drd.c
> @@ -515,6 +515,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc)
>  	dwc3_role_switch.set = dwc3_usb_role_switch_set;
>  	dwc3_role_switch.get = dwc3_usb_role_switch_get;
>  	dwc3_role_switch.driver_data = dwc;
> +	dwc3_role_switch.allow_userspace_control = true;
>  	dwc->role_sw = usb_role_switch_register(dwc->dev, &dwc3_role_switch);
>  	if (IS_ERR(dwc->role_sw))
>  		return PTR_ERR(dwc->role_sw);
> -- 
> 2.34.1
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] usb: dwc3: Allow usb role swich control from userspace
  2025-10-21 22:09   ` Thinh Nguyen
@ 2025-10-23  9:55     ` Pritam Manohar Sutar
  2025-10-23 22:45       ` Thinh Nguyen
  0 siblings, 1 reply; 5+ messages in thread
From: Pritam Manohar Sutar @ 2025-10-23  9:55 UTC (permalink / raw)
  To: 'Thinh Nguyen'
  Cc: gregkh, linux-usb, linux-kernel, rosa.pila, dev.tailor, faraz.ata,
	muhammed.ali, selvarasu.g

Hi Thinh,

> -----Original Message-----
> From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Sent: 22 October 2025 03:40 AM
> To: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>;
> gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; linux-
> kernel@vger.kernel.org; rosa.pila@samsung.com; dev.tailor@samsung.com;
> faraz.ata@samsung.com; muhammed.ali@samsung.com;
> selvarasu.g@samsung.com
> Subject: Re: [PATCH] usb: dwc3: Allow usb role swich control from userspace
> 
> On Mon, Oct 20, 2025, Pritam Manohar Sutar wrote:
> > There is a possibility of user needs for USB mode switching on boards
> > that lack external hardware support for dynamic host/device role
> > detection.
> 
> It's fine to enable this. But base on this change log, it sounds like there's no use
> case at the moment? If there is one, even if it's only for debugging purpose,
> please note it so. I'm hesitant to accept changes base on use case speculation
> only.
> 

Thank you for your comments. 

Yes, a use case exists, especially in automotive, where this feature
is needed to allow user-space applications to switch modes 
(host to device or vice-versa) at runtime during CarPlay or Android
Auto operations.

Can you please confirm updated commit message with usecase added as below? 

"
usb: dwc3: Allow usb role swich control from userspace

There is a possibility of user needs for USB mode switching on boards
that lack external hardware support for dynamic host/device role
detection. This is particularly relevant in automotive applications 
where userspace applications need to switch USB roles (host to device)
at runtime for CarPlay/Android Auto integration.

Add an `allow_userspace_control` flag to handle such cases. When
enabled, it exposes a sysfs attribute that allows userspace to switch
the USB role manually between host and device. This provides flexibility
for platforms that cannot rely on hardware-based mode detection.

The role switch can be done as below
echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role
"

> Thanks,
> Thinh
> 
> >
> > Add an `allow_userspace_control` flag to handle such cases. When
> > enabled, it exposes a sysfs attribute that allows userspace to switch
> > the USB role manually between host and device. This provides
> > flexibility for platforms that cannot rely on hardware-based mode detection.
> >
> > The role switch can be done as below
> > echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> > echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> >
> > Signed-off-by: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> > ---
> >  drivers/usb/dwc3/drd.c | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/drivers/usb/dwc3/drd.c b/drivers/usb/dwc3/drd.c index
> > 4c91240eb429..589bbeb27454 100644
> > --- a/drivers/usb/dwc3/drd.c
> > +++ b/drivers/usb/dwc3/drd.c
> > @@ -515,6 +515,7 @@ static int dwc3_setup_role_switch(struct dwc3 *dwc)
> >  	dwc3_role_switch.set = dwc3_usb_role_switch_set;
> >  	dwc3_role_switch.get = dwc3_usb_role_switch_get;
> >  	dwc3_role_switch.driver_data = dwc;
> > +	dwc3_role_switch.allow_userspace_control = true;
> >  	dwc->role_sw = usb_role_switch_register(dwc->dev,
> &dwc3_role_switch);
> >  	if (IS_ERR(dwc->role_sw))
> >  		return PTR_ERR(dwc->role_sw);
> > --
> > 2.34.1
> >

Thank you,

Regards,
Pritam


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] usb: dwc3: Allow usb role swich control from userspace
  2025-10-23  9:55     ` Pritam Manohar Sutar
@ 2025-10-23 22:45       ` Thinh Nguyen
  2025-10-24  8:32         ` Pritam Manohar Sutar
  0 siblings, 1 reply; 5+ messages in thread
From: Thinh Nguyen @ 2025-10-23 22:45 UTC (permalink / raw)
  To: Pritam Manohar Sutar
  Cc: Thinh Nguyen, gregkh@linuxfoundation.org,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	rosa.pila@samsung.com, dev.tailor@samsung.com,
	faraz.ata@samsung.com, muhammed.ali@samsung.com,
	selvarasu.g@samsung.com

On Thu, Oct 23, 2025, Pritam Manohar Sutar wrote:
> Hi Thinh,
> 
> > -----Original Message-----
> > From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> > Sent: 22 October 2025 03:40 AM
> > To: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> > Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>;
> > gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; linux-
> > kernel@vger.kernel.org; rosa.pila@samsung.com; dev.tailor@samsung.com;
> > faraz.ata@samsung.com; muhammed.ali@samsung.com;
> > selvarasu.g@samsung.com
> > Subject: Re: [PATCH] usb: dwc3: Allow usb role swich control from userspace
> > 
> > On Mon, Oct 20, 2025, Pritam Manohar Sutar wrote:
> > > There is a possibility of user needs for USB mode switching on boards
> > > that lack external hardware support for dynamic host/device role
> > > detection.
> > 
> > It's fine to enable this. But base on this change log, it sounds like there's no use
> > case at the moment? If there is one, even if it's only for debugging purpose,
> > please note it so. I'm hesitant to accept changes base on use case speculation
> > only.
> > 
> 
> Thank you for your comments. 
> 
> Yes, a use case exists, especially in automotive, where this feature
> is needed to allow user-space applications to switch modes 
> (host to device or vice-versa) at runtime during CarPlay or Android
> Auto operations.
> 
> Can you please confirm updated commit message with usecase added as below? 
> 
> "
> usb: dwc3: Allow usb role swich control from userspace
> 
> There is a possibility of user needs for USB mode switching on boards
> that lack external hardware support for dynamic host/device role
> detection. This is particularly relevant in automotive applications 
> where userspace applications need to switch USB roles (host to device)
> at runtime for CarPlay/Android Auto integration.
> 
> Add an `allow_userspace_control` flag to handle such cases. When
> enabled, it exposes a sysfs attribute that allows userspace to switch
> the USB role manually between host and device. This provides flexibility
> for platforms that cannot rely on hardware-based mode detection.
> 
> The role switch can be done as below
> echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> "
> 

Yes, can you update the patch with this new info? Thank you.

Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

BR,
Thinh

^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [PATCH] usb: dwc3: Allow usb role swich control from userspace
  2025-10-23 22:45       ` Thinh Nguyen
@ 2025-10-24  8:32         ` Pritam Manohar Sutar
  0 siblings, 0 replies; 5+ messages in thread
From: Pritam Manohar Sutar @ 2025-10-24  8:32 UTC (permalink / raw)
  To: 'Thinh Nguyen'
  Cc: gregkh, linux-usb, linux-kernel, rosa.pila, dev.tailor, faraz.ata,
	muhammed.ali, selvarasu.g

Hi Thinh,

> -----Original Message-----
> From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> Sent: 24 October 2025 04:15 AM
> To: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>;
> gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; linux-
> kernel@vger.kernel.org; rosa.pila@samsung.com; dev.tailor@samsung.com;
> faraz.ata@samsung.com; muhammed.ali@samsung.com;
> selvarasu.g@samsung.com
> Subject: Re: [PATCH] usb: dwc3: Allow usb role swich control from userspace
> 
> On Thu, Oct 23, 2025, Pritam Manohar Sutar wrote:
> > Hi Thinh,
> >
> > > -----Original Message-----
> > > From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
> > > Sent: 22 October 2025 03:40 AM
> > > To: Pritam Manohar Sutar <pritam.sutar@samsung.com>
> > > Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>;
> > > gregkh@linuxfoundation.org; linux-usb@vger.kernel.org; linux-
> > > kernel@vger.kernel.org; rosa.pila@samsung.com;
> > > dev.tailor@samsung.com; faraz.ata@samsung.com;
> > > muhammed.ali@samsung.com; selvarasu.g@samsung.com
> > > Subject: Re: [PATCH] usb: dwc3: Allow usb role swich control from
> > > userspace
> > >
> > > On Mon, Oct 20, 2025, Pritam Manohar Sutar wrote:
> > > > There is a possibility of user needs for USB mode switching on
> > > > boards that lack external hardware support for dynamic host/device
> > > > role detection.
> > >
> > > It's fine to enable this. But base on this change log, it sounds
> > > like there's no use case at the moment? If there is one, even if
> > > it's only for debugging purpose, please note it so. I'm hesitant to
> > > accept changes base on use case speculation only.
> > >
> >
> > Thank you for your comments.
> >
> > Yes, a use case exists, especially in automotive, where this feature
> > is needed to allow user-space applications to switch modes (host to
> > device or vice-versa) at runtime during CarPlay or Android Auto
> > operations.
> >
> > Can you please confirm updated commit message with usecase added as
> below?
> >
> > "
> > usb: dwc3: Allow usb role swich control from userspace
> >
> > There is a possibility of user needs for USB mode switching on boards
> > that lack external hardware support for dynamic host/device role
> > detection. This is particularly relevant in automotive applications
> > where userspace applications need to switch USB roles (host to device)
> > at runtime for CarPlay/Android Auto integration.
> >
> > Add an `allow_userspace_control` flag to handle such cases. When
> > enabled, it exposes a sysfs attribute that allows userspace to switch
> > the USB role manually between host and device. This provides
> > flexibility for platforms that cannot rely on hardware-based mode detection.
> >
> > The role switch can be done as below
> > echo host > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> > echo device > /sys/class/usb_role/<ADDR>.usb-role-switch/role
> > "
> >
> 
> Yes, can you update the patch with this new info? Thank you.
> 

Will update it and share v2 patch soon. 

> Acked-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>

Thank you.

> 
> BR,
> Thinh

Regards,
Pritam


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2025-10-24  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <CGME20251020112840epcas5p28d8eded5200f096e7b80f71899371f2c@epcas5p2.samsung.com>
2025-10-20 11:37 ` [PATCH] usb: dwc3: Allow usb role swich control from userspace Pritam Manohar Sutar
2025-10-21 22:09   ` Thinh Nguyen
2025-10-23  9:55     ` Pritam Manohar Sutar
2025-10-23 22:45       ` Thinh Nguyen
2025-10-24  8:32         ` Pritam Manohar Sutar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).