aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorTimur Tabi <timur@freescale.com>2009-05-26 01:21:41 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2009-06-16 00:15:44 -0400
commit9317726de42a157c377f7fe9110a63260800582f (patch)
tree14641c8adc6a56b289bdef8acc8b2cf18dbf90f7 /arch
parent79290e4b692af8a76273bab38e41a3a385dedc7b (diff)
powerpc: Introduce macro spin_event_timeout()
The macro spin_event_timeout() takes a condition and timeout value (in microseconds) as parameters. It spins until either the condition is true or the timeout expires. It returns the result of the condition when the loop was terminated. This primary purpose of this macro is to poll on a hardware register until a status bit changes. The timeout ensures that the loop still terminates if the bit doesn't change as expected. This macro makes it easier for driver developers to perform this kind of operation properly. Signed-off-by: Timur Tabi <timur@freescale.com> Acked-by: Geoff Thorpe <Geoff.Thorpe@freescale.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/powerpc/include/asm/delay.h36
1 files changed, 36 insertions, 0 deletions
diff --git a/arch/powerpc/include/asm/delay.h b/arch/powerpc/include/asm/delay.h
index f9200a65c632..1e2eb41fa057 100644
--- a/arch/powerpc/include/asm/delay.h
+++ b/arch/powerpc/include/asm/delay.h
@@ -2,8 +2,11 @@
2#define _ASM_POWERPC_DELAY_H 2#define _ASM_POWERPC_DELAY_H
3#ifdef __KERNEL__ 3#ifdef __KERNEL__
4 4
5#include <asm/time.h>
6
5/* 7/*
6 * Copyright 1996, Paul Mackerras. 8 * Copyright 1996, Paul Mackerras.
9 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
7 * 10 *
8 * This program is free software; you can redistribute it and/or 11 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License 12 * modify it under the terms of the GNU General Public License
@@ -30,5 +33,38 @@ extern void udelay(unsigned long usecs);
30#define mdelay(n) udelay((n) * 1000) 33#define mdelay(n) udelay((n) * 1000)
31#endif 34#endif
32 35
36/**
37 * spin_event_timeout - spin until a condition gets true or a timeout elapses
38 * @condition: a C expression to evalate
39 * @timeout: timeout, in microseconds
40 * @delay: the number of microseconds to delay between each evaluation of
41 * @condition
42 *
43 * The process spins until the condition evaluates to true (non-zero) or the
44 * timeout elapses. The return value of this macro is the value of
45 * @condition when the loop terminates. This allows you to determine the cause
46 * of the loop terminates. If the return value is zero, then you know a
47 * timeout has occurred.
48 *
49 * This primary purpose of this macro is to poll on a hardware register
50 * until a status bit changes. The timeout ensures that the loop still
51 * terminates even if the bit never changes. The delay is for devices that
52 * need a delay in between successive reads.
53 *
54 * gcc will optimize out the if-statement if @delay is a constant.
55 */
56#define spin_event_timeout(condition, timeout, delay) \
57({ \
58 typeof(condition) __ret; \
59 unsigned long __loops = tb_ticks_per_usec * timeout; \
60 unsigned long __start = get_tbl(); \
61 while (!(__ret = (condition)) && (tb_ticks_since(__start) <= __loops)) \
62 if (delay) \
63 udelay(delay); \
64 else \
65 cpu_relax(); \
66 __ret; \
67})
68
33#endif /* __KERNEL__ */ 69#endif /* __KERNEL__ */
34#endif /* _ASM_POWERPC_DELAY_H */ 70#endif /* _ASM_POWERPC_DELAY_H */