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
Cc: John Youn <John.Youn@synopsys.com>
Subject: [PATCH v5 09/12] usb: dwc3: gadget: Report sublink speed capability
Date: Thu, 24 Sep 2020 19:42:38 -0700	[thread overview]
Message-ID: <d7fe65c16eefc53fb7176947e69a902a73bd8c5a.1601001199.git.Thinh.Nguyen@synopsys.com> (raw)
In-Reply-To: <cover.1601001199.git.Thinh.Nguyen@synopsys.com>

Report the sublink speed attributes to the usb_gadget structure based on
the HW capability from the device maximum_speed property.

Only DWC_usb32 supports 2 sublink speeds if it can operate with 2 lanes.
(i.e. at SSP, it can operate as gen1x2)

Note: the SSID DWC3_SSP_SSID_GEN2 and DWC3_SSP_SSID_GEN1 are arbitrary.
There's no standard according to the USB 3.2 spec as long as they are
unique and within 0-15.

Signed-off-by: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
---
Changes in v5:
- Rebase on Felipe's testing/next branch
- Changed Signed-off-by email to match From: email header
Changes in v4:
- None
Changes in v3:
- Update commit with updated field name
- No longer use DWC3_LSM_5/10_GBPS macros
Changes in v2:
- Fix missing check for gen1x2 when writing to sublink speed attributes
- Minor fix in commit message (first commit sentence ended with comma)

 drivers/usb/dwc3/core.h   |  4 ++++
 drivers/usb/dwc3/gadget.c | 49 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 53 insertions(+)

diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 585a83ada270..c4a33545530d 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -40,6 +40,10 @@
 #define DWC3_XHCI_RESOURCES_NUM	2
 #define DWC3_ISOC_MAX_RETRIES	5
 
+/* Sublink Speed Attribute ID */
+#define DWC3_SSP_SSID_GEN2	2
+#define DWC3_SSP_SSID_GEN1	1
+
 #define DWC3_SCRATCHBUF_SIZE	4096	/* each buffer is assumed to be 4KiB */
 #define DWC3_EVENT_BUFFERS_SIZE	4096
 #define DWC3_EVENT_TYPE_MASK	0xfe
diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
index 82bc075ba97c..e60161205bf9 100644
--- a/drivers/usb/dwc3/gadget.c
+++ b/drivers/usb/dwc3/gadget.c
@@ -3779,6 +3779,55 @@ int dwc3_gadget_init(struct dwc3 *dwc)
 				dwc->revision);
 
 	dwc->gadget->max_speed		= dwc->maximum_speed;
+	dwc->gadget->max_num_lanes	= dwc->maximum_num_lanes;
+
+	if (dwc->maximum_speed == USB_SPEED_SUPER_PLUS) {
+		struct usb_sublink_speed *ssa;
+		int i;
+
+		/*
+		 * Multiple sublink speeds are only available to DWC_usb32
+		 * devices that can operate at gen2x2 max.
+		 */
+		if (dwc->maximum_phy_gen == USB_PHY_GEN_2 &&
+		    dwc->maximum_num_lanes == 2) {
+			dwc->gadget->ssac = 3;
+			dwc->gadget->min_speed_ssid = DWC3_SSP_SSID_GEN1;
+			dwc->gadget->max_speed_ssid = DWC3_SSP_SSID_GEN2;
+		} else if (dwc->maximum_phy_gen == USB_PHY_GEN_1 &&
+			   dwc->maximum_num_lanes == 2) {
+			dwc->gadget->ssac = 1;
+			dwc->gadget->min_speed_ssid = DWC3_SSP_SSID_GEN1;
+			dwc->gadget->max_speed_ssid = DWC3_SSP_SSID_GEN1;
+		} else {
+			dwc->gadget->ssac = 1;
+			dwc->gadget->min_speed_ssid = DWC3_SSP_SSID_GEN2;
+			dwc->gadget->max_speed_ssid = DWC3_SSP_SSID_GEN2;
+		}
+
+		for (i = 0; i < dwc->gadget->ssac + 1; i++) {
+			ssa = &dwc->gadget->sublink_speed[i];
+
+			if (dwc->gadget->ssac > 1 && i > 1)
+				ssa->id = dwc->gadget->max_speed_ssid;
+			else
+				ssa->id = dwc->gadget->min_speed_ssid;
+
+			if (ssa->id == DWC3_SSP_SSID_GEN1)
+				ssa->mantissa = 5;
+			else
+				ssa->mantissa = 10;
+
+			/* First attribute is RX followed by TX */
+			if (i % 2)
+				ssa->type = USB_ST_SYMMETRIC_TX;
+			else
+				ssa->type = USB_ST_SYMMETRIC_RX;
+
+			ssa->exponent = USB_LSE_GBPS;
+			ssa->protocol = USB_LP_SSP;
+		}
+	}
 
 	/*
 	 * REVISIT: Here we should clear all pending IRQs to be
-- 
2.28.0


  parent reply	other threads:[~2020-09-25  2:42 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-25  2:41 [PATCH v5 00/12] usb: Handle different sublink speeds Thinh Nguyen
2020-09-25  2:41 ` [PATCH v5 01/12] usb: ch9: Add sublink speed struct Thinh Nguyen
2020-09-25 15:08   ` Greg Kroah-Hartman
2020-09-25  2:41 ` [PATCH v5 02/12] usb: gadget: composite: Avoid using magic numbers Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 03/12] usb: gadget: Expose sublink speed attributes Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 04/12] usb: gadget: Set max speed for SSP devices Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 05/12] usb: composite: Properly report sublink speed Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 06/12] usb: devicetree: Include USB SSP Gen X x Y Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 07/12] usb: common: Add and update common functions for SSP speeds Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 08/12] usb: dwc3: Initialize lane count and sublink speed Thinh Nguyen
2020-09-25  2:42 ` Thinh Nguyen [this message]
2020-09-25  2:42 ` [PATCH v5 10/12] usb: dwc3: gadget: Implement setting of " Thinh Nguyen
2020-09-25  2:42 ` [PATCH v5 11/12] usb: dwc3: gadget: Track connected lane and " Thinh Nguyen
2020-09-25  2:44 ` [PATCH v5 12/12] usb: dwc3: gadget: Set speed only up to the max supported Thinh Nguyen
2020-09-29 18:13 ` [PATCH v5 00/12] usb: Handle different sublink speeds 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=d7fe65c16eefc53fb7176947e69a902a73bd8c5a.1601001199.git.Thinh.Nguyen@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-usb@vger.kernel.org \
    /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.