diff mbox series

[v2,1/8] iopoll: Add dealy to read poll

Message ID 20200430070412.12499-2-jagan@amarulasolutions.com
State New
Headers show
Series rockchip: Add PCIe host support | expand

Commit Message

Jagan Teki April 30, 2020, 7:04 a.m. UTC
Some drivers and other bsp code not only poll the
register with timeout but also required to delay
on each transaction.

This patch add that requirement by adding sleep_us
variable so-that read_poll_timeout now support
delay as well.

Cc: Tom Rini <trini at konsulko.com>
Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
---
Changes for v2:
- none

 include/linux/iopoll.h | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

Comments

Tom Rini April 30, 2020, 2:46 p.m. UTC | #1
On Thu, Apr 30, 2020 at 12:34:05PM +0530, Jagan Teki wrote:

> Some drivers and other bsp code not only poll the
> register with timeout but also required to delay
> on each transaction.
> 
> This patch add that requirement by adding sleep_us
> variable so-that read_poll_timeout now support
> delay as well.
> 
> Cc: Tom Rini <trini at konsulko.com>
> Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>

This (and 2/8) need to say what kernel commit you're taking this from,
thanks.
Jagan Teki April 30, 2020, 9:03 p.m. UTC | #2
On Thu, Apr 30, 2020 at 8:16 PM Tom Rini <trini at konsulko.com> wrote:
>
> On Thu, Apr 30, 2020 at 12:34:05PM +0530, Jagan Teki wrote:
>
> > Some drivers and other bsp code not only poll the
> > register with timeout but also required to delay
> > on each transaction.
> >
> > This patch add that requirement by adding sleep_us
> > variable so-that read_poll_timeout now support
> > delay as well.
> >
> > Cc: Tom Rini <trini at konsulko.com>
> > Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
>
> This (and 2/8) need to say what kernel commit you're taking this from,
> thanks.

Linux supports sleep_us at the beginning where read_poll_timeout
supports, i.e. the reason I didn't add the sha1. If that works, I will
add the same sha1 and apply via my tree (since it has some SPI changes
dependency patch)?

Jagan.
Tom Rini April 30, 2020, 10:06 p.m. UTC | #3
On Fri, May 01, 2020 at 02:33:17AM +0530, Jagan Teki wrote:
> On Thu, Apr 30, 2020 at 8:16 PM Tom Rini <trini at konsulko.com> wrote:
> >
> > On Thu, Apr 30, 2020 at 12:34:05PM +0530, Jagan Teki wrote:
> >
> > > Some drivers and other bsp code not only poll the
> > > register with timeout but also required to delay
> > > on each transaction.
> > >
> > > This patch add that requirement by adding sleep_us
> > > variable so-that read_poll_timeout now support
> > > delay as well.
> > >
> > > Cc: Tom Rini <trini at konsulko.com>
> > > Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
> >
> > This (and 2/8) need to say what kernel commit you're taking this from,
> > thanks.
> 
> Linux supports sleep_us at the beginning where read_poll_timeout
> supports, i.e. the reason I didn't add the sha1. If that works, I will
> add the same sha1 and apply via my tree (since it has some SPI changes
> dependency patch)?

Yes, I think that sounds right, thanks!
Jagan Teki May 1, 2020, 2:52 p.m. UTC | #4
On Fri, May 1, 2020 at 3:36 AM Tom Rini <trini at konsulko.com> wrote:
>
> On Fri, May 01, 2020 at 02:33:17AM +0530, Jagan Teki wrote:
> > On Thu, Apr 30, 2020 at 8:16 PM Tom Rini <trini at konsulko.com> wrote:
> > >
> > > On Thu, Apr 30, 2020 at 12:34:05PM +0530, Jagan Teki wrote:
> > >
> > > > Some drivers and other bsp code not only poll the
> > > > register with timeout but also required to delay
> > > > on each transaction.
> > > >
> > > > This patch add that requirement by adding sleep_us
> > > > variable so-that read_poll_timeout now support
> > > > delay as well.
> > > >
> > > > Cc: Tom Rini <trini at konsulko.com>
> > > > Signed-off-by: Jagan Teki <jagan at amarulasolutions.com>
> > >
> > > This (and 2/8) need to say what kernel commit you're taking this from,
> > > thanks.
> >
> > Linux supports sleep_us at the beginning where read_poll_timeout
> > supports, i.e. the reason I didn't add the sha1. If that works, I will
> > add the same sha1 and apply via my tree (since it has some SPI changes
> > dependency patch)?
>
> Yes, I think that sounds right, thanks!

Applied 1/8 and 2/8 to u-boot-spi/master
diff mbox series

Patch

diff --git a/include/linux/iopoll.h b/include/linux/iopoll.h
index ab0ae1969a..0bbd757939 100644
--- a/include/linux/iopoll.h
+++ b/include/linux/iopoll.h
@@ -16,6 +16,7 @@ 
  * @addr: Address to poll
  * @val: Variable to read the value into
  * @cond: Break condition (usually involving @val)
+ * @sleep_us: Maximum time to sleep in us
  * @timeout_us: Timeout in us, 0 means never timeout
  *
  * Returns 0 on success and -ETIMEDOUT upon a timeout. In either
@@ -24,7 +25,7 @@ 
  * When available, you'll probably want to use one of the specialized
  * macros defined below rather than this macro directly.
  */
-#define readx_poll_timeout(op, addr, val, cond, timeout_us)	\
+#define readx_poll_timeout(op, addr, val, cond, sleep_us, timeout_us)	\
 ({ \
 	unsigned long timeout = timer_get_us() + timeout_us; \
 	for (;;) { \
@@ -35,33 +36,34 @@ 
 			(val) = op(addr); \
 			break; \
 		} \
+		if (sleep_us) \
+			udelay(sleep_us); \
 	} \
 	(cond) ? 0 : -ETIMEDOUT; \
 })
 
-
 #define readb_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readb, addr, val, cond, timeout_us)
+	readx_poll_timeout(readb, addr, val, cond, false, timeout_us)
 
 #define readw_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readw, addr, val, cond, timeout_us)
+	readx_poll_timeout(readw, addr, val, cond, false, timeout_us)
 
 #define readl_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readl, addr, val, cond, timeout_us)
+	readx_poll_timeout(readl, addr, val, cond, false, timeout_us)
 
 #define readq_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readq, addr, val, cond, timeout_us)
+	readx_poll_timeout(readq, addr, val, cond, false, timeout_us)
 
 #define readb_relaxed_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readb_relaxed, addr, val, cond, timeout_us)
+	readx_poll_timeout(readb_relaxed, addr, val, cond, false, timeout_us)
 
 #define readw_relaxed_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readw_relaxed, addr, val, cond, timeout_us)
+	readx_poll_timeout(readw_relaxed, addr, val, cond, false, timeout_us)
 
 #define readl_relaxed_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readl_relaxed, addr, val, cond, timeout_us)
+	readx_poll_timeout(readl_relaxed, addr, val, cond, false, timeout_us)
 
 #define readq_relaxed_poll_timeout(addr, val, cond, timeout_us) \
-	readx_poll_timeout(readq_relaxed, addr, val, cond, timeout_us)
+	readx_poll_timeout(readq_relaxed, addr, val, cond, false, timeout_us)
 
 #endif /* _LINUX_IOPOLL_H */