All of lore.kernel.org
 help / color / mirror / Atom feed
From: sherry sun <sherry.sun@nxp.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 3/3] USB: gadget: core: introduce ->udc_set_speed() method
Date: Tue, 16 Jul 2019 20:08:14 +0800	[thread overview]
Message-ID: <1563278895-10635-4-git-send-email-sherry.sun@nxp.com> (raw)
In-Reply-To: <1563278895-10635-1-git-send-email-sherry.sun@nxp.com>

From: Sherry Sun <sherry.sun@nxp.com>

This patch was copied from kernel commit: 67fdfda4a99ed.

Sometimes, the gadget driver we want to run has max_speed lower than
what the UDC supports. In such situations, UDC might want to make sure
we don't try to connect on speeds not supported by the gadget
driver because that will just fail.

So here introduce a new optional ->udc_set_speed() method which can be
implemented by interested UDC drivers to achieve this purpose.

Signed-off-by: Sherry Sun <sherry.sun@nxp.com>
---
 drivers/usb/gadget/udc/udc-core.c | 23 +++++++++++++++++++++++
 include/linux/usb/gadget.h        |  2 ++
 2 files changed, 25 insertions(+)

diff --git a/drivers/usb/gadget/udc/udc-core.c b/drivers/usb/gadget/udc/udc-core.c
index 62b47781dd..8d1d90e3e3 100644
--- a/drivers/usb/gadget/udc/udc-core.c
+++ b/drivers/usb/gadget/udc/udc-core.c
@@ -267,6 +267,27 @@ EXPORT_SYMBOL_GPL(usb_del_gadget_udc);
 
 /* ------------------------------------------------------------------------- */
 
+/**
+ * usb_gadget_udc_set_speed - tells usb device controller speed supported by
+ *    current driver
+ * @udc: The device we want to set maximum speed
+ * @speed: The maximum speed to allowed to run
+ *
+ * This call is issued by the UDC Class driver before calling
+ * usb_gadget_udc_start() in order to make sure that we don't try to
+ * connect on speeds the gadget driver doesn't support.
+ */
+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;
+
+		s = min(speed, udc->gadget->max_speed);
+		udc->gadget->ops->udc_set_speed(udc->gadget, s);
+	}
+}
+
 static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *driver)
 {
 	int ret;
@@ -276,6 +297,8 @@ static int udc_bind_to_driver(struct usb_udc *udc, struct usb_gadget_driver *dri
 
 	udc->driver = driver;
 
+	usb_gadget_udc_set_speed(udc, driver->speed);
+
 	ret = driver->bind(udc->gadget);
 	if (ret)
 		goto err1;
diff --git a/include/linux/usb/gadget.h b/include/linux/usb/gadget.h
index a34f3478f3..78e245a1b5 100644
--- a/include/linux/usb/gadget.h
+++ b/include/linux/usb/gadget.h
@@ -450,6 +450,8 @@ struct usb_gadget_ops {
 	int   (*match_ep)(struct usb_gadget *gadget,
 			  struct usb_ep *ep,
 			  struct usb_endpoint_descriptor *desc);
+	void	(*udc_set_speed)(struct usb_gadget *gadget,
+				 enum usb_device_speed);
 };
 
 /**
-- 
2.17.1

  parent reply	other threads:[~2019-07-16 12:08 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-07-16 12:08 [U-Boot] [PATCH 0/3] USB: Add cadence USB3 gadget driver and host driver sherry sun
2019-07-16 12:08 ` [U-Boot] [PATCH 1/3] USB: gadget: Add the cadence USB3 gadget driver sherry sun
2019-07-16 12:08 ` [U-Boot] [PATCH 2/3] USB: host: Add the USB3 host driver sherry sun
2019-07-21 10:44   ` Marek Vasut
2019-08-01  7:07     ` [U-Boot] 答复: " Sherry Sun
2019-07-16 12:08 ` sherry sun [this message]
2019-08-01 12:09 ` [U-Boot] [PATCH 0/3] USB: Add cadence USB3 gadget driver and " Igor Opaniuk
2019-08-02  1:04   ` Peng Fan
2019-08-08  9:03     ` [U-Boot] 答复: " Sherry Sun

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=1563278895-10635-4-git-send-email-sherry.sun@nxp.com \
    --to=sherry.sun@nxp.com \
    --cc=u-boot@lists.denx.de \
    /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.