public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Ran Wang <ran.wang_1@nxp.com>
To: u-boot@lists.denx.de
Subject: [PATCH v2 1/6] usb: dwc3: Add frame length adjustment quirk
Date: Wed, 21 Oct 2020 18:02:24 +0800	[thread overview]
Message-ID: <20201021100229.18366-2-ran.wang_1@nxp.com> (raw)
In-Reply-To: <20201021100229.18366-1-ran.wang_1@nxp.com>

Register Global frame length adjustment is used to do frame length
adjustment for SOF/ITP counter which is running on the ref_clk. Allow
updating it could help on avoiding potential USB 2.0 devices time-out over
a longer run.

Refer to Linux commit db2be4e9e30c (?usb: dwc3: Add frame length adjustment quirk?)

Signed-off-by: Ran Wang <ran.wang_1@nxp.com>
---
Change in v2:
 - None

 drivers/usb/dwc3/core.c | 34 ++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/core.h |  7 +++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 2e00353..b3d4751 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -310,6 +310,25 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
 	kfree(dwc->scratchbuf);
 }
 
+/*
+ * dwc3_frame_length_adjustment - Adjusts frame length if required
+ * @dwc3: Pointer to our controller context structure
+ * @val: Value of frame length
+ */
+static void dwc3_frame_length_adjustment(struct dwc3 *dwc, u32 val)
+{
+	u32 reg;
+	u32 dft;
+
+	reg = dwc3_readl(dwc->regs, DWC3_GFLADJ);
+	dft = reg & DWC3_GFLADJ_30MHZ_MASK;
+	if (dft != val) {
+		reg &= ~DWC3_GFLADJ_30MHZ_MASK;
+		reg |= DWC3_GFLADJ_30MHZ_SDBND_SEL | val;
+		dwc3_writel(dwc->regs, DWC3_GFLADJ, reg);
+	}
+}
+
 static void dwc3_core_num_eps(struct dwc3 *dwc)
 {
 	struct dwc3_hwparams	*parms = &dwc->hwparams;
@@ -569,6 +588,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
 	if (ret)
 		goto err1;
 
+	if (dwc->fladj_quirk && dwc->revision >= DWC3_REVISION_250A)
+		dwc3_frame_length_adjustment(dwc, dwc->fladj);
+
 	return 0;
 
 err1:
@@ -958,6 +980,18 @@ void dwc3_of_parse(struct dwc3 *dwc)
 
 	dwc->hird_threshold = hird_threshold
 		| (dwc->is_utmi_l1_suspend << 4);
+
+	dwc->fladj_quirk = false;
+	if (!dev_read_u32(dev,
+			  "snps,quirk-frame-length-adjustment",
+			  &dwc->fladj)) {
+		if (dwc->fladj <=  DWC3_GFLADJ_30MHZ_MASK)
+			dwc->fladj_quirk = true;
+		else
+			dev_err(dev,
+				"snps,quirk-frame-length-adjustment invalid: 0x%x\n",
+				dwc->fladj);
+	}
 }
 
 int dwc3_init(struct dwc3 *dwc)
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 44533fd..4650216 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -115,6 +115,7 @@
 #define DWC3_GEVNTCOUNT(n)	(0xc40c + (n * 0x10))
 
 #define DWC3_GHWPARAMS8		0xc600
+#define DWC3_GFLADJ		0xc630
 
 /* Device Registers */
 #define DWC3_DCFG		0xc700
@@ -291,6 +292,10 @@
 #define DWC3_DCTL_ULSTCHNG_COMPLIANCE	(DWC3_DCTL_ULSTCHNGREQ(10))
 #define DWC3_DCTL_ULSTCHNG_LOOPBACK	(DWC3_DCTL_ULSTCHNGREQ(11))
 
+/* Global Frame Length Adjustment Register */
+#define DWC3_GFLADJ_30MHZ_SDBND_SEL	BIT(7)
+#define DWC3_GFLADJ_30MHZ_MASK		0x3f
+
 /* Device Event Enable Register */
 #define DWC3_DEVTEN_VNDRDEVTSTRCVEDEN	(1 << 12)
 #define DWC3_DEVTEN_EVNTOVERFLOWEN	(1 << 11)
@@ -764,6 +769,7 @@ struct dwc3 {
 	u32			num_event_buffers;
 	u32			u1u2;
 	u32			maximum_speed;
+	u32			fladj;
 	u32			revision;
 
 #define DWC3_REVISION_173A	0x5533173a
@@ -845,6 +851,7 @@ struct dwc3 {
 
 	unsigned		tx_de_emphasis_quirk:1;
 	unsigned		tx_de_emphasis:2;
+	unsigned		fladj_quirk:1;
 	int			index;
 	struct list_head        list;
 };
-- 
2.7.4

  reply	other threads:[~2020-10-21 10:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-21 10:02 [PATCH v2 0/6] dwc3-generic: Add Layerscape support Ran Wang
2020-10-21 10:02 ` Ran Wang [this message]
2020-11-30  1:45   ` [PATCH v2 1/6] usb: dwc3: Add frame length adjustment quirk Ran Wang
2020-10-21 10:02 ` [PATCH v2 2/6] usb: dwc3: Enable undefined length INCR burst type Ran Wang
2020-10-21 10:02 ` [PATCH v2 3/6] usb: dwc3-generic: fix dwc3_setup_phy() return -ENOTSUPP causing init failure Ran Wang
2020-10-21 10:02 ` [PATCH v2 4/6] usb: dwc3-generic: Add support for the layerscape Ran Wang
2020-10-21 10:02 ` [PATCH v2 5/6] configs: ls1088a: add usb mass storage (device mode) support Ran Wang
2020-10-21 10:02 ` [PATCH v2 6/6] arm: dts: ls1088a: change dwc3 compatible to match dwc3-generic driver Ran Wang
2021-10-03 17:23   ` Michael Walle

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=20201021100229.18366-2-ran.wang_1@nxp.com \
    --to=ran.wang_1@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox