[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20230330141413.25569-2-andriy.shevchenko@linux.intel.com>
Date: Thu, 30 Mar 2023 17:14:13 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Mika Westerberg <mika.westerberg@...ux.intel.com>,
Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Olliver Schinagl <oliver@...inagl.nl>,
linux-usb@...r.kernel.org, linux-kernel@...r.kernel.org
Cc: Andreas Noever <andreas.noever@...il.com>,
Michael Jamet <michael.jamet@...el.com>,
Yehezkel Bernat <YehezkelShB@...il.com>
Subject: [PATCH v1 2/2] thunderbolt: Make use of ioread32_poll_timeout()
Instead of open coding the same routine switch the code to use
ioread32_poll_timeout().
Signed-off-by: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
---
drivers/thunderbolt/nhi.c | 20 ++++++++------------
1 file changed, 8 insertions(+), 12 deletions(-)
diff --git a/drivers/thunderbolt/nhi.c b/drivers/thunderbolt/nhi.c
index d76e923fbc6a..d0bf11b40131 100644
--- a/drivers/thunderbolt/nhi.c
+++ b/drivers/thunderbolt/nhi.c
@@ -16,8 +16,8 @@
#include <linux/dma-mapping.h>
#include <linux/interrupt.h>
#include <linux/iommu.h>
+#include <linux/iopoll.h>
#include <linux/module.h>
-#include <linux/delay.h>
#include <linux/property.h>
#include <linux/string_helpers.h>
@@ -40,7 +40,7 @@
#define MSIX_MIN_VECS 6
#define MSIX_MAX_VECS 16
-#define NHI_MAILBOX_TIMEOUT 500 /* ms */
+#define NHI_MAILBOX_TIMEOUT_US 500000
/* Host interface quirks */
#define QUIRK_AUTO_CLEAR_INT BIT(0)
@@ -830,8 +830,8 @@ EXPORT_SYMBOL_GPL(tb_ring_free);
*/
int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
{
- ktime_t timeout;
u32 val;
+ int ret;
iowrite32(data, nhi->iobase + REG_INMAIL_DATA);
@@ -840,16 +840,12 @@ int nhi_mailbox_cmd(struct tb_nhi *nhi, enum nhi_mailbox_cmd cmd, u32 data)
val |= REG_INMAIL_OP_REQUEST | cmd;
iowrite32(val, nhi->iobase + REG_INMAIL_CMD);
- timeout = ktime_add_ms(ktime_get(), NHI_MAILBOX_TIMEOUT);
- do {
- val = ioread32(nhi->iobase + REG_INMAIL_CMD);
- if (!(val & REG_INMAIL_OP_REQUEST))
- break;
- usleep_range(10, 20);
- } while (ktime_before(ktime_get(), timeout));
+ ret = ioread32_poll_timeout(nhi->iobase + REG_INMAIL_CMD,
+ val, !(val & REG_INMAIL_OP_REQUEST),
+ 40, NHI_MAILBOX_TIMEOUT_US);
+ if (ret)
+ return ret;
- if (val & REG_INMAIL_OP_REQUEST)
- return -ETIMEDOUT;
if (val & REG_INMAIL_ERROR)
return -EIO;
--
2.40.0.1.gaa8946217a0b
Powered by blists - more mailing lists