All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Thinh.Nguyen@synopsys.com, linux-usb@vger.kernel.org,
	Peter Chen <peter.chen@nxp.com>, Lee Jones <lee.jones@linaro.org>,
	Alan Stern <stern@rowland.harvard.edu>,
	Dejin Zheng <zhengdejin5@gmail.com>,
	"Ahmed S. Darwish" <a.darwish@linutronix.de>,
	Marek Szyprowski <m.szyprowski@samsung.com>
Cc: John Youn <John.Youn@synopsys.com>
Subject: [PATCH v6 04/11] usb: gadget: Introduce udc_set_ssp_rate() for SSP
Date: Wed, 13 Jan 2021 18:53:07 -0800	[thread overview]
Message-ID: <9b85357cdadc02e3f0d653fd05f89eb46af836e1.1610592135.git.Thinh.Nguyen@synopsys.com> (raw)
In-Reply-To: <cover.1610592135.git.Thinh.Nguyen@synopsys.com>

A SuperSpeed Plus device may operate at different speed and lane count
(i.e. gen2x2, gen1x2, or gen2x1). Introduce gadget ops
udc_set_ssp_rate() to set the desire corresponding usb_ssp_rate for
SuperSpeed Plus capable devices.

If the USB device supports different speeds at SuperSpeed Plus, set the
device to operate with the maximum number of lanes and speed.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
Changes in v6:
- Rebase on Greg's usb-testing branch
- Rename udc_set_num_lanes_and_speed() to udc_set_ssp_rate()
- Use usb_ssp_rate enum as a parameter instead of SSID
- Update commit message
Changes in v5:
- Rebase on Felipe's testing/next branch
- Changed Signed-off-by email to match From: email header
Changes in v4:
- Add identifier name for usb_gadget in gadget ops
  (*udc_set_num_lanes_and_speed) to avoid checkpatch warning
Changes in v3:
- None
Changes in v2:
- None

 drivers/usb/gadget/udc/core.c | 16 +++++++++++-----
 include/linux/usb/gadget.h    |  2 ++
 2 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/gadget/udc/core.c b/drivers/usb/gadget/udc/core.c
index 98cf9216f3cb..4173acdcd35b 100644
--- a/drivers/usb/gadget/udc/core.c
+++ b/drivers/usb/gadget/udc/core.c
@@ -1133,12 +1133,18 @@ static inline void usb_gadget_udc_stop(struct usb_udc *udc)
 static inline void usb_gadget_udc_set_speed(struct usb_udc *udc,
 					    enum usb_device_speed speed)
 {
-	if (udc->gadget->ops->udc_set_speed) {
-		enum usb_device_speed s;
+	struct usb_gadget *gadget = udc->gadget;
+	enum usb_device_speed s;
 
-		s = min(speed, udc->gadget->max_speed);
-		udc->gadget->ops->udc_set_speed(udc->gadget, s);
-	}
+	if (speed == USB_SPEED_UNKNOWN)
+		s = gadget->max_speed;
+	else
+		s = min(speed, gadget->max_speed);
+
+	if (s == USB_SPEED_SUPER_PLUS && gadget->ops->udc_set_ssp_rate)
+		gadget->ops->udc_set_ssp_rate(gadget, gadget->max_ssp_rate);
+	else if (gadget->ops->udc_set_speed)
+		gadget->ops->udc_set_speed(gadget, s);
 }
 
 /**
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index 02483c862444..ee04ef214ce8 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -323,6 +323,8 @@ struct usb_gadget_ops {
 			struct usb_gadget_driver *);
 	int	(*udc_stop)(struct usb_gadget *);
 	void	(*udc_set_speed)(struct usb_gadget *, enum usb_device_speed);
+	void	(*udc_set_ssp_rate)(struct usb_gadget *gadget,
+			enum usb_ssp_rate rate);
 	struct usb_ep *(*match_ep)(struct usb_gadget *,
 			struct usb_endpoint_descriptor *,
 			struct usb_ss_ep_comp_descriptor *);
-- 
2.28.0


  parent reply	other threads:[~2021-01-14  2:54 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-14  2:52 [PATCH v6 00/11] usb: Support USB 3.2 multi-lanes Thinh Nguyen
2021-01-14  2:52 ` [PATCH v6 01/11] usb: ch9: Add USB 3.2 SSP attributes Thinh Nguyen
2021-01-14  9:58   ` Felipe Balbi
2021-01-14 18:58     ` Thinh Nguyen
2021-01-15 11:08       ` Felipe Balbi
2021-01-16  4:03         ` Thinh Nguyen
2021-01-18 11:32           ` Felipe Balbi
2021-01-14  2:52 ` [PATCH v6 02/11] usb: gadget: composite: Use SSP sublink speed macros Thinh Nguyen
2021-01-14  2:53 ` [PATCH v6 03/11] usb: gadget: Introduce SSP rates and lanes Thinh Nguyen
2021-01-14  2:53 ` Thinh Nguyen [this message]
2021-01-14  2:53 ` [PATCH v6 05/11] usb: gadget: composite: Report various SSP sublink speeds Thinh Nguyen
2021-01-14  5:47   ` Peter Chen
2021-01-14  6:16     ` Thinh Nguyen
2021-01-15  0:51       ` Peter Chen
2021-01-15  2:40         ` Thinh Nguyen
2021-01-15  2:56           ` Thinh Nguyen
2021-01-16 13:37             ` Peter Chen
2021-01-14  2:53 ` [PATCH v6 06/11] dt-binding: usb: Include USB SSP rates in GenXxY Thinh Nguyen
2021-01-14  2:53 ` [PATCH v6 07/11] usb: common: Parse for USB SSP genXxY Thinh Nguyen
2021-01-14  2:53 ` [PATCH v6 08/11] usb: dwc3: core: Check maximum_speed " Thinh Nguyen
2021-01-14  2:53 ` [PATCH v6 09/11] usb: dwc3: gadget: Implement setting of SSP rate Thinh Nguyen
2021-01-14 10:02   ` Felipe Balbi
2021-01-14 18:17     ` Thinh Nguyen
2021-01-15 11:13       ` Felipe Balbi
2021-01-14  2:53 ` [PATCH v6 10/11] usb: dwc3: gadget: Track connected SSP rate and lane count Thinh Nguyen
2021-01-14  2:53 ` [PATCH v6 11/11] usb: dwc3: gadget: Set speed only up to the max supported Thinh Nguyen
2021-01-18 17:42 ` [PATCH v6 00/11] usb: Support USB 3.2 multi-lanes Greg Kroah-Hartman
2021-01-20  1:38   ` Thinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9b85357cdadc02e3f0d653fd05f89eb46af836e1.1610592135.git.Thinh.Nguyen@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=a.darwish@linutronix.de \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=m.szyprowski@samsung.com \
    --cc=peter.chen@nxp.com \
    --cc=stern@rowland.harvard.edu \
    --cc=zhengdejin5@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.