From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
linux-usb@vger.kernel.org,
Mathias Nyman <mathias.nyman@intel.com>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCH v2 6/8] usb: early: xhci-dbc: use readl_poll_timeout() to simplify code
Date: Mon, 17 Aug 2020 21:46:57 +0300 [thread overview]
Message-ID: <20200817184659.58419-6-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20200817184659.58419-1-andriy.shevchenko@linux.intel.com>
Use readl_poll_timeout() to poll the status of the registers.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
v2: no change
drivers/usb/early/xhci-dbc.c | 56 +++++++++++++++++-------------------
1 file changed, 27 insertions(+), 29 deletions(-)
diff --git a/drivers/usb/early/xhci-dbc.c b/drivers/usb/early/xhci-dbc.c
index c0507767a8e3..77c2e8301971 100644
--- a/drivers/usb/early/xhci-dbc.c
+++ b/drivers/usb/early/xhci-dbc.c
@@ -14,6 +14,7 @@
#include <linux/pci_ids.h>
#include <linux/memblock.h>
#include <linux/io.h>
+#include <linux/iopoll.h>
#include <asm/pci-direct.h>
#include <asm/fixmap.h>
#include <linux/bcd.h>
@@ -131,38 +132,23 @@ static u32 __init xdbc_find_dbgp(int xdbc_num, u32 *b, u32 *d, u32 *f)
return -1;
}
-static int handshake(void __iomem *ptr, u32 mask, u32 done, int wait, int delay)
-{
- u32 result;
-
- do {
- result = readl(ptr);
- result &= mask;
- if (result == done)
- return 0;
- udelay(delay);
- wait -= delay;
- } while (wait > 0);
-
- return -ETIMEDOUT;
-}
-
static void __init xdbc_bios_handoff(void)
{
int offset, timeout;
u32 val;
offset = xhci_find_next_ext_cap(xdbc.xhci_base, 0, XHCI_EXT_CAPS_LEGACY);
- val = readl(xdbc.xhci_base + offset);
- if (val & XHCI_HC_BIOS_OWNED) {
+ val = readl(xdbc.xhci_base + offset);
+ if (val & XHCI_HC_BIOS_OWNED)
writel(val | XHCI_HC_OS_OWNED, xdbc.xhci_base + offset);
- timeout = handshake(xdbc.xhci_base + offset, XHCI_HC_BIOS_OWNED, 0, 5000, 10);
- if (timeout) {
- pr_notice("failed to hand over xHCI control from BIOS\n");
- writel(val & ~XHCI_HC_BIOS_OWNED, xdbc.xhci_base + offset);
- }
+ timeout = readl_poll_timeout_atomic(xdbc.xhci_base + offset, val,
+ !(val & XHCI_HC_BIOS_OWNED),
+ 10, 5000);
+ if (timeout) {
+ pr_notice("failed to hand over xHCI control from BIOS\n");
+ writel(val & ~XHCI_HC_BIOS_OWNED, xdbc.xhci_base + offset);
}
/* Disable BIOS SMIs and clear all SMI events: */
@@ -421,7 +407,9 @@ static int xdbc_start(void)
ctrl = readl(&xdbc.xdbc_reg->control);
writel(ctrl | CTRL_DBC_ENABLE | CTRL_PORT_ENABLE, &xdbc.xdbc_reg->control);
- ret = handshake(&xdbc.xdbc_reg->control, CTRL_DBC_ENABLE, CTRL_DBC_ENABLE, 100000, 100);
+ ret = readl_poll_timeout_atomic(&xdbc.xdbc_reg->control, ctrl,
+ (ctrl & CTRL_DBC_ENABLE) == CTRL_DBC_ENABLE,
+ 100, 100000);
if (ret) {
xdbc_trace("failed to initialize hardware\n");
return ret;
@@ -432,14 +420,18 @@ static int xdbc_start(void)
xdbc_reset_debug_port();
/* Wait for port connection: */
- ret = handshake(&xdbc.xdbc_reg->portsc, PORTSC_CONN_STATUS, PORTSC_CONN_STATUS, 5000000, 100);
+ ret = readl_poll_timeout_atomic(&xdbc.xdbc_reg->portsc, status,
+ (status & PORTSC_CONN_STATUS) == PORTSC_CONN_STATUS,
+ 100, 5000000);
if (ret) {
xdbc_trace("waiting for connection timed out\n");
return ret;
}
/* Wait for debug device to be configured: */
- ret = handshake(&xdbc.xdbc_reg->control, CTRL_DBC_RUN, CTRL_DBC_RUN, 5000000, 100);
+ ret = readl_poll_timeout_atomic(&xdbc.xdbc_reg->control, status,
+ (status & CTRL_DBC_RUN) == CTRL_DBC_RUN,
+ 100, 5000000);
if (ret) {
xdbc_trace("waiting for device configuration timed out\n");
return ret;
@@ -523,11 +515,14 @@ static int xdbc_bulk_transfer(void *data, int size, bool read)
static int xdbc_handle_external_reset(void)
{
- int ret = 0;
+ u32 result;
+ int ret;
xdbc.flags = 0;
writel(0, &xdbc.xdbc_reg->control);
- ret = handshake(&xdbc.xdbc_reg->control, CTRL_DBC_ENABLE, 0, 100000, 10);
+ ret = readl_poll_timeout_atomic(&xdbc.xdbc_reg->control, result,
+ !(result & CTRL_DBC_ENABLE),
+ 10, 100000);
if (ret)
goto reset_out;
@@ -552,10 +547,13 @@ static int xdbc_handle_external_reset(void)
static int __init xdbc_early_setup(void)
{
+ u32 result;
int ret;
writel(0, &xdbc.xdbc_reg->control);
- ret = handshake(&xdbc.xdbc_reg->control, CTRL_DBC_ENABLE, 0, 100000, 100);
+ ret = readl_poll_timeout_atomic(&xdbc.xdbc_reg->control, result,
+ !(result & CTRL_DBC_ENABLE),
+ 100, 100000);
if (ret)
return ret;
--
2.28.0
next prev parent reply other threads:[~2020-08-17 18:47 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-17 18:46 [PATCH v2 1/8] byteorder: Introduce cpu_to_le16_array() and le16_to_cpu_array() Andy Shevchenko
2020-08-17 18:46 ` [PATCH v2 2/8] media: solo6x10: Make use of cpu_to_le16_array() Andy Shevchenko
2020-08-17 22:18 ` Ismael Luceno
2020-08-17 18:46 ` [PATCH v2 3/8] rndis_wlan: " Andy Shevchenko
2020-08-17 22:02 ` kernel test robot
2020-08-18 5:36 ` Kalle Valo
2020-08-18 5:36 ` Jussi Kivilinna
2020-08-17 18:46 ` [PATCH v2 4/8] i40e: Make use of le16_to_cpu_array() Andy Shevchenko
2020-08-17 18:46 ` [PATCH v2 5/8] ice: " Andy Shevchenko
2020-08-17 18:46 ` Andy Shevchenko [this message]
2020-08-17 18:46 ` [PATCH v2 7/8] usb: early: xhci-dbc: Make use of cpu_to_le16_array() Andy Shevchenko
2020-08-17 21:23 ` kernel test robot
2020-08-17 18:46 ` [PATCH v2 8/8] usb: early: xhci-dbc: Move asm/* headers after linux/* Andy Shevchenko
2020-08-18 8:01 ` [PATCH v2 1/8] byteorder: Introduce cpu_to_le16_array() and le16_to_cpu_array() Andy Shevchenko
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=20200817184659.58419-6-andriy.shevchenko@linux.intel.com \
--to=andriy.shevchenko@linux.intel.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-usb@vger.kernel.org \
--cc=mathias.nyman@intel.com \
/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;
as well as URLs for NNTP newsgroup(s).