All of lore.kernel.org
 help / color / mirror / Atom feed
From: Frank Wunderlich <linux@fw-web.de>
To: u-boot@lists.denx.de
Subject: [PATCH RESEND v4 9/9] usb: xhci: convert to readx_poll_sleep_timeout()
Date: Tue,  8 Sep 2020 19:00:03 +0200	[thread overview]
Message-ID: <20200908170003.4002-9-linux@fw-web.de> (raw)
In-Reply-To: <20200908170003.4002-1-linux@fw-web.de>

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

Use readx_poll_sleep_timeout() to poll the register status

Signed-off-by: Chunfeng Yun <chunfeng.yun@mediatek.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---
 drivers/usb/host/xhci.c | 25 +++++++++++--------------
 1 file changed, 11 insertions(+), 14 deletions(-)

diff --git a/drivers/usb/host/xhci.c b/drivers/usb/host/xhci.c
index fe30101d93..3547a9bad1 100644
--- a/drivers/usb/host/xhci.c
+++ b/drivers/usb/host/xhci.c
@@ -33,6 +33,7 @@
 #include <linux/bug.h>
 #include <linux/delay.h>
 #include <linux/errno.h>
+#include <linux/iopoll.h>
 #include <usb/xhci.h>
 
 #ifndef CONFIG_USB_MAX_CONTROLLER_COUNT
@@ -143,23 +144,19 @@ struct xhci_ctrl *xhci_get_ctrl(struct usb_device *udev)
  * @param usec	time to wait till
  * @return 0 if handshake is success else < 0 on failure
  */
-static int handshake(uint32_t volatile *ptr, uint32_t mask,
-					uint32_t done, int usec)
+static int
+handshake(uint32_t volatile *ptr, uint32_t mask, uint32_t done, int usec)
 {
 	uint32_t result;
+	int ret;
+
+	ret = readx_poll_sleep_timeout(xhci_readl, ptr, result,
+				 (result & mask) == done || result == U32_MAX,
+				 1, usec);
+	if (result == U32_MAX)		/* card removed */
+		return -ENODEV;
 
-	do {
-		result = xhci_readl(ptr);
-		if (result == ~(uint32_t)0)
-			return -ENODEV;
-		result &= mask;
-		if (result == done)
-			return 0;
-		usec--;
-		udelay(1);
-	} while (usec > 0);
-
-	return -ETIMEDOUT;
+	return ret;
 }
 
 /**
-- 
2.25.1

      parent reply	other threads:[~2020-09-08 17:00 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-08 16:59 [PATCH RESEND v4 1/9] usb: xhci: add a member hci_version in xhci_ctrl struct Frank Wunderlich
2020-09-08 16:59 ` [PATCH RESEND v4 2/9] usb: xhci: create one unified function to calculate TRB TD remainder Frank Wunderlich
2020-09-09 13:26   ` Marek Vasut
2020-09-08 16:59 ` [PATCH RESEND v4 3/9] usb: xhci: add quirks flag to support MediaTek xHCI 0.96 Frank Wunderlich
2020-09-08 16:59 ` [PATCH RESEND v4 4/9] usb: xhci: convert to HCS_MAX_PORTS() Frank Wunderlich
2020-09-08 16:59 ` [PATCH RESEND v4 5/9] usb: xhci: convert to TRB_TYPE() Frank Wunderlich
2020-09-08 17:00 ` [PATCH RESEND v4 6/9] usb: xhci: convert to TRB_LEN() and TRB_INTR_TARGET() Frank Wunderlich
2020-09-08 17:00 ` [PATCH RESEND v4 7/9] usb: xhci: convert to TRB_TX_TYPE() Frank Wunderlich
2020-09-08 17:00 ` [PATCH RESEND v4 8/9] usb: xhci: use macros with parameter to fill ep_info2 Frank Wunderlich
2020-09-08 17:00 ` Frank Wunderlich [this message]

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=20200908170003.4002-9-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 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.