linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] usb: dwc2: gadget: implement udc_set_speed()
@ 2021-08-10 10:42 Argishti Aleksanyan
  2021-08-10 10:52 ` Minas Harutyunyan
  0 siblings, 1 reply; 2+ messages in thread
From: Argishti Aleksanyan @ 2021-08-10 10:42 UTC (permalink / raw)
  To: Felipe Balbi, Greg Kroah-Hartman, Minas Harutyunyan, linux-usb
  Cc: John Youn, Argishti Aleksanyan

Implemented udc_set_speed() gadget ops to allow the udc to select
the gadget speed on initialization.

Signed-off-by: Argishti Aleksanyan <aleksan@synopsys.com>
---
 drivers/usb/dwc2/gadget.c | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
index 985b272f53d5..837237e4bc96 100644
--- a/drivers/usb/dwc2/gadget.c
+++ b/drivers/usb/dwc2/gadget.c
@@ -4709,12 +4709,35 @@ static int dwc2_hsotg_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
 	return usb_phy_set_power(hsotg->uphy, mA);
 }
 
+static void dwc2_gadget_set_speed(struct usb_gadget *g, enum usb_device_speed speed)
+{
+	struct dwc2_hsotg *hsotg = to_hsotg(g);
+	unsigned long		flags;
+
+	spin_lock_irqsave(&hsotg->lock, flags);
+	switch (speed) {
+	case USB_SPEED_HIGH:
+		hsotg->params.speed = DWC2_SPEED_PARAM_HIGH;
+		break;
+	case USB_SPEED_FULL:
+		hsotg->params.speed = DWC2_SPEED_PARAM_FULL;
+		break;
+	case USB_SPEED_LOW:
+		hsotg->params.speed = DWC2_SPEED_PARAM_LOW;
+		break;
+	default:
+		dev_err(hsotg->dev, "invalid speed (%d)\n", speed);
+	}
+	spin_unlock_irqrestore(&hsotg->lock, flags);
+}
+
 static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
 	.get_frame	= dwc2_hsotg_gadget_getframe,
 	.set_selfpowered	= dwc2_hsotg_set_selfpowered,
 	.udc_start		= dwc2_hsotg_udc_start,
 	.udc_stop		= dwc2_hsotg_udc_stop,
 	.pullup                 = dwc2_hsotg_pullup,
+	.udc_set_speed		= dwc2_gadget_set_speed,
 	.vbus_session		= dwc2_hsotg_vbus_session,
 	.vbus_draw		= dwc2_hsotg_vbus_draw,
 };

base-commit: 73e19de7b79a2f26f0b370cc071728cede1ab3a0
-- 
2.30.2


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

* Re: [PATCH] usb: dwc2: gadget: implement udc_set_speed()
  2021-08-10 10:42 [PATCH] usb: dwc2: gadget: implement udc_set_speed() Argishti Aleksanyan
@ 2021-08-10 10:52 ` Minas Harutyunyan
  0 siblings, 0 replies; 2+ messages in thread
From: Minas Harutyunyan @ 2021-08-10 10:52 UTC (permalink / raw)
  To: Argishti Aleksanyan, Felipe Balbi, Greg Kroah-Hartman, linux-usb
  Cc: John Youn

On 8/10/2021 2:42 PM, Argishti Aleksanyan wrote:
> Implemented udc_set_speed() gadget ops to allow the udc to select
> the gadget speed on initialization.
> 
> Signed-off-by: Argishti Aleksanyan <aleksan@synopsys.com>

Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>


> ---
>   drivers/usb/dwc2/gadget.c | 23 +++++++++++++++++++++++
>   1 file changed, 23 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/gadget.c b/drivers/usb/dwc2/gadget.c
> index 985b272f53d5..837237e4bc96 100644
> --- a/drivers/usb/dwc2/gadget.c
> +++ b/drivers/usb/dwc2/gadget.c
> @@ -4709,12 +4709,35 @@ static int dwc2_hsotg_vbus_draw(struct usb_gadget *gadget, unsigned int mA)
>   	return usb_phy_set_power(hsotg->uphy, mA);
>   }
>   
> +static void dwc2_gadget_set_speed(struct usb_gadget *g, enum usb_device_speed speed)
> +{
> +	struct dwc2_hsotg *hsotg = to_hsotg(g);
> +	unsigned long		flags;
> +
> +	spin_lock_irqsave(&hsotg->lock, flags);
> +	switch (speed) {
> +	case USB_SPEED_HIGH:
> +		hsotg->params.speed = DWC2_SPEED_PARAM_HIGH;
> +		break;
> +	case USB_SPEED_FULL:
> +		hsotg->params.speed = DWC2_SPEED_PARAM_FULL;
> +		break;
> +	case USB_SPEED_LOW:
> +		hsotg->params.speed = DWC2_SPEED_PARAM_LOW;
> +		break;
> +	default:
> +		dev_err(hsotg->dev, "invalid speed (%d)\n", speed);
> +	}
> +	spin_unlock_irqrestore(&hsotg->lock, flags);
> +}
> +
>   static const struct usb_gadget_ops dwc2_hsotg_gadget_ops = {
>   	.get_frame	= dwc2_hsotg_gadget_getframe,
>   	.set_selfpowered	= dwc2_hsotg_set_selfpowered,
>   	.udc_start		= dwc2_hsotg_udc_start,
>   	.udc_stop		= dwc2_hsotg_udc_stop,
>   	.pullup                 = dwc2_hsotg_pullup,
> +	.udc_set_speed		= dwc2_gadget_set_speed,
>   	.vbus_session		= dwc2_hsotg_vbus_session,
>   	.vbus_draw		= dwc2_hsotg_vbus_draw,
>   };
> 
> base-commit: 73e19de7b79a2f26f0b370cc071728cede1ab3a0
> 


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

end of thread, other threads:[~2021-08-10 10:52 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-10 10:42 [PATCH] usb: dwc2: gadget: implement udc_set_speed() Argishti Aleksanyan
2021-08-10 10:52 ` Minas Harutyunyan

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).