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 2/6] usb: dwc3: Enable undefined length INCR burst type
Date: Wed, 21 Oct 2020 18:02:25 +0800	[thread overview]
Message-ID: <20201021100229.18366-3-ran.wang_1@nxp.com> (raw)
In-Reply-To: <20201021100229.18366-1-ran.wang_1@nxp.com>

Enable the undefined length INCR burst type and set INCRx. Different
platforms may has the different burst size type. In order to get best
performance, we need to tune the burst size to one special value,
instead of the default value.

Refer to Linux commit (?usb: dwc3: Enable undefined length INCR burst type?)

Signed-off-by: Ran Wang <ran.wang_1@nxp.com>
---
Change in v2:
 - None, only context changed to fit removal of [v1 2/7] usb: dwc3: add
   disable receiver detection in P3 quirk

 drivers/usb/dwc3/core.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++++
 drivers/usb/dwc3/core.h | 13 +++++++
 2 files changed, 109 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index b3d4751..6dc9781 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -310,6 +310,99 @@ static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
 	kfree(dwc->scratchbuf);
 }
 
+#if CONFIG_IS_ENABLED(DM_USB)
+/* set global incr burst type configuration registers */
+static void dwc3_set_incr_burst_type(struct dwc3 *dwc)
+{
+	struct udevice *dev = dwc->dev;
+	bool incrx_mode;
+	u32 incrx_size;
+	u32 *vals;
+	u32 cfg;
+	int ntype;
+	int ret;
+	int i;
+
+	cfg = dwc3_readl(dwc->regs, DWC3_GSBUSCFG0);
+
+	/*
+	 * Handle property "snps,incr-burst-type-adjustment".
+	 * Get the number of value from this property:
+	 * result <= 0, means this property is not supported.
+	 * result = 1, means INCRx burst mode supported.
+	 * result > 1, means undefined length burst mode supported.
+	 */
+	ntype = dev_read_size(dev, "snps,incr-burst-type-adjustment") / sizeof(u32);
+	if (ntype <= 0)
+		return;
+
+	vals = memalign(CONFIG_SYS_CACHELINE_SIZE, ntype * sizeof(u32));
+	if (!vals) {
+		dev_err(dev, "Error to get memory\n");
+		return;
+	}
+
+	/* Get INCR burst type, and parse it */
+	ret = dev_read_u32_array(dev, "snps,incr-burst-type-adjustment", vals, ntype);
+	if (ret) {
+		kfree(vals);
+		dev_err(dev, "Error to get property\n");
+		return;
+	}
+
+	incrx_size = *vals;
+
+	if (ntype > 1) {
+		/* INCRX (undefined length) burst mode */
+		incrx_mode = INCRX_UNDEF_LENGTH_BURST_MODE;
+		for (i = 1; i < ntype; i++) {
+			if (vals[i] > incrx_size)
+				incrx_size = vals[i];
+		}
+	} else {
+		/* INCRX burst mode */
+		incrx_mode = INCRX_BURST_MODE;
+	}
+
+	kfree(vals);
+
+	/* Enable Undefined Length INCR Burst and Enable INCRx Burst */
+	cfg &= ~DWC3_GSBUSCFG0_INCRBRST_MASK;
+	if (incrx_mode)
+		cfg |= DWC3_GSBUSCFG0_INCRBRSTENA;
+	switch (incrx_size) {
+	case 256:
+		cfg |= DWC3_GSBUSCFG0_INCR256BRSTENA;
+		break;
+	case 128:
+		cfg |= DWC3_GSBUSCFG0_INCR128BRSTENA;
+		break;
+	case 64:
+		cfg |= DWC3_GSBUSCFG0_INCR64BRSTENA;
+		break;
+	case 32:
+		cfg |= DWC3_GSBUSCFG0_INCR32BRSTENA;
+		break;
+	case 16:
+		cfg |= DWC3_GSBUSCFG0_INCR16BRSTENA;
+		break;
+	case 8:
+		cfg |= DWC3_GSBUSCFG0_INCR8BRSTENA;
+		break;
+	case 4:
+		cfg |= DWC3_GSBUSCFG0_INCR4BRSTENA;
+		break;
+	case 1:
+		break;
+	default:
+		dev_err(dev, "Invalid property\n");
+		break;
+	}
+
+	dwc3_writel(dwc->regs, DWC3_GSBUSCFG0, cfg);
+}
+#endif
+
 /*
  * dwc3_frame_length_adjustment - Adjusts frame length if required
  * @dwc3: Pointer to our controller context structure
@@ -591,6 +684,9 @@ static int dwc3_core_init(struct dwc3 *dwc)
 	if (dwc->fladj_quirk && dwc->revision >= DWC3_REVISION_250A)
 		dwc3_frame_length_adjustment(dwc, dwc->fladj);
 
+#if CONFIG_IS_ENABLED(OF_CONTROL)
+	dwc3_set_incr_burst_type(dwc);
+#endif
 	return 0;
 
 err1:
diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h
index 4650216..3f9b8e5 100644
--- a/drivers/usb/dwc3/core.h
+++ b/drivers/usb/dwc3/core.h
@@ -139,6 +139,17 @@
 
 /* Bit fields */
 
+/* Global SoC Bus Configuration INCRx Register 0 */
+#define DWC3_GSBUSCFG0_INCR256BRSTENA	BIT(7) /* INCR256 burst */
+#define DWC3_GSBUSCFG0_INCR128BRSTENA	BIT(6) /* INCR128 burst */
+#define DWC3_GSBUSCFG0_INCR64BRSTENA	BIT(5) /* INCR64 burst */
+#define DWC3_GSBUSCFG0_INCR32BRSTENA	BIT(4) /* INCR32 burst */
+#define DWC3_GSBUSCFG0_INCR16BRSTENA	BIT(3) /* INCR16 burst */
+#define DWC3_GSBUSCFG0_INCR8BRSTENA	BIT(2) /* INCR8 burst */
+#define DWC3_GSBUSCFG0_INCR4BRSTENA	BIT(1) /* INCR4 burst */
+#define DWC3_GSBUSCFG0_INCRBRSTENA	BIT(0) /* undefined length enable */
+#define DWC3_GSBUSCFG0_INCRBRST_MASK	0xff
+
 /* Global Configuration Register */
 #define DWC3_GCTL_PWRDNSCALE(n)	((n) << 19)
 #define DWC3_GCTL_U2RSTECN	(1 << 16)
@@ -856,6 +867,8 @@ struct dwc3 {
 	struct list_head        list;
 };
 
+#define INCRX_BURST_MODE 0
+#define INCRX_UNDEF_LENGTH_BURST_MODE 1
 /* -------------------------------------------------------------------------- */
 
 /* -------------------------------------------------------------------------- */
-- 
2.7.4

  parent 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 ` [PATCH v2 1/6] usb: dwc3: Add frame length adjustment quirk Ran Wang
2020-11-30  1:45   ` Ran Wang
2020-10-21 10:02 ` Ran Wang [this message]
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-3-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