public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Frank Wunderlich <linux@fw-web.de>
To: u-boot@lists.denx.de
Subject: [RESEND PATCH v2 03/11] usb: xhci: add quirks flag to support MediaTek xHCI 0.96
Date: Wed,  2 Sep 2020 08:13:35 +0200	[thread overview]
Message-ID: <20200902061343.3185-3-linux@fw-web.de> (raw)
In-Reply-To: <20200902061343.3185-1-linux@fw-web.de>

From: Chunfeng Yun <chunfeng.yun@mediatek.com>

There some vendor quirks for MTK xHCI 0.96 host controller:
1. It defines some extra SW scheduling parameters for HW
   to minimize the scheduling effort for synchronous and
   interrupt endpoints. The parameters are put into reseved
   DWs of slot context and endpoint context.
2. Its TDS in  Normal TRB defines a number of packets that
   remains to be transferred for a TD after processing all
   Max packets in all previous TRBs.

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Tested-by: Frank Wunderlich <frank-w@public-files.de>
---
 drivers/usb/host/xhci-mtk.c  | 1 +
 drivers/usb/host/xhci-ring.c | 9 +++++++--
 drivers/usb/host/xhci.c      | 2 +-
 include/usb/xhci.h           | 2 ++
 4 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/host/xhci-mtk.c b/drivers/usb/host/xhci-mtk.c
index 8ff71854fc..f3f181dae0 100644
--- a/drivers/usb/host/xhci-mtk.c
+++ b/drivers/usb/host/xhci-mtk.c
@@ -258,6 +258,7 @@ static int xhci_mtk_probe(struct udevice *dev)
 	if (ret)
 		goto ssusb_init_err;
 
+	mtk->ctrl.quirks = XHCI_MTK_HOST;
 	hcor = (struct xhci_hcor *)((uintptr_t)mtk->hcd +
 			HC_LENGTH(xhci_readl(&mtk->hcd->cr_capbase)));
 
diff --git a/drivers/usb/host/xhci-ring.c b/drivers/usb/host/xhci-ring.c
index 0f86b011f3..cf8b9d2362 100644
--- a/drivers/usb/host/xhci-ring.c
+++ b/drivers/usb/host/xhci-ring.c
@@ -332,7 +332,8 @@ static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int transferred,
 {
 	u32 total_packet_count;
 
-	if (ctrl->hci_version < 0x100)
+	/* MTK xHCI 0.96 contains some features from 1.0 */
+	if (ctrl->hci_version < 0x100 && !(ctrl->quirks & XHCI_MTK_HOST))
 		return ((td_total_len - transferred) >> 10);
 
 	/* One TRB with a zero-length data packet. */
@@ -340,6 +341,10 @@ static u32 xhci_td_remainder(struct xhci_ctrl *ctrl, int transferred,
 	    trb_buff_len == td_total_len)
 		return 0;
 
+	/* for MTK xHCI 0.96, TD size include this TRB, but not in 1.x */
+	if ((ctrl->quirks & XHCI_MTK_HOST) && (ctrl->hci_version < 0x100))
+		trb_buff_len = 0;
+
 	total_packet_count = DIV_ROUND_UP(td_total_len, maxp);
 
 	/* Queueing functions don't count the current TRB into transferred */
@@ -823,7 +828,7 @@ int xhci_ctrl_tx(struct usb_device *udev, unsigned long pipe,
 		field |= 0x1;
 
 	/* xHCI 1.0 6.4.1.2.1: Transfer Type field */
-	if (ctrl->hci_version >= 0x100) {
+	if (ctrl->hci_version >= 0x100 || ctrl->quirks & XHCI_MTK_HOST) {
 		if (length > 0) {
 			if (req->requesttype & USB_DIR_IN)
 				field |= (TRB_DATA_IN << TRB_TX_TYPE_SHIFT);
diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index 4be1411243..51edeb22c1 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -650,7 +650,7 @@ static int xhci_set_configuration(struct usb_device *udev)
 		 * are put into reserved DWs in Slot and Endpoint Contexts
 		 * for synchronous endpoints.
 		 */
-		if (IS_ENABLED(CONFIG_USB_XHCI_MTK)) {
+		if (ctrl->quirks & XHCI_MTK_HOST) {
 			ep_ctx[ep_index]->reserved[0] =
 				cpu_to_le32(EP_BPKTS(1) | EP_BBM(1));
 		}
diff --git a/include/usb/xhci.h b/include/usb/xhci.h
index 15926eb9f4..3de46cd95e 100644
--- a/include/usb/xhci.h
+++ b/include/usb/xhci.h
@@ -1230,6 +1230,8 @@ struct xhci_ctrl {
 	struct xhci_virt_device *devs[MAX_HC_SLOTS];
 	int rootdev;
 	u16 hci_version;
+	u32 quirks;
+#define XHCI_MTK_HOST		BIT(0)
 };
 
 unsigned long trb_addr(struct xhci_segment *seg, union xhci_trb *trb);
-- 
2.25.1

  parent reply	other threads:[~2020-09-02  6:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-02  6:13 [RESEND PATCH v2 01/11] usb: xhci: add a member hci_version in xhci_ctrl struct Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 02/11] usb: xhci: create one unified function to calculate TRB TD remainder Frank Wunderlich
2020-09-02  6:13 ` Frank Wunderlich [this message]
2020-09-02  6:13 ` [RESEND PATCH v2 04/11] usb: xhci: convert to HCS_MAX_PORTS() Frank Wunderlich
2020-09-04  6:54   ` Bin Meng
2020-09-02  6:13 ` [RESEND PATCH v2 05/11] usb: xhci: convert to TRB_TYPE() Frank Wunderlich
2020-09-04  9:23   ` Bin Meng
2020-09-02  6:13 ` [RESEND PATCH v2 06/11] usb: xhci: convert to TRB_INTR_TARGET() Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 07/11] usb: xhci: convert to TRB_LEN() Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 08/11] usb: xhci: convert to TRB_TX_TYPE() Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 09/11] usb: xhci: convert to EP_TYPE() Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 10/11] usb: xhci: use macros with parameter to fill ep_info2 Frank Wunderlich
2020-09-02  6:13 ` [RESEND PATCH v2 11/11] usb: xhci: convert to readx_poll_sleep_timeout() Frank Wunderlich
2020-09-02 10:38 ` [RESEND PATCH v2 01/11] usb: xhci: add a member hci_version in xhci_ctrl struct Marek Vasut
2020-09-02 13:21   ` Bin Meng
2020-09-04  0:59 ` Bin Meng

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=20200902061343.3185-3-linux@fw-web.de \
    --to=linux@fw-web.de \
    --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