blob: 52e4d54da2a9845d16db0773ca81310178707723 [file] [log] [blame]
Paul Mackerrasc55377e2005-11-14 17:22:01 +11001#ifndef _ASM_POWERPC_DELAY_H
2#define _ASM_POWERPC_DELAY_H
Arnd Bergmann88ced032005-12-16 22:43:46 +01003#ifdef __KERNEL__
Linus Torvalds1da177e2005-04-16 15:20:36 -07004
Timur Tabi93177262009-05-26 05:21:41 +00005#include <asm/time.h>
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/*
8 * Copyright 1996, Paul Mackerras.
Timur Tabi93177262009-05-26 05:21:41 +00009 * Copyright (C) 2009 Freescale Semiconductor, Inc. All rights reserved.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
15 *
16 * PPC64 Support added by Dave Engebretsen, Todd Inglett, Mike Corrigan,
17 * Anton Blanchard.
18 */
19
Paul Mackerras6defa382005-11-18 13:44:17 +110020extern void __delay(unsigned long loops);
21extern void udelay(unsigned long usecs);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022
Anton Blanchard1e92a552006-06-15 14:11:22 +100023/*
24 * On shared processor machines the generic implementation of mdelay can
25 * result in large errors. While each iteration of the loop inside mdelay
26 * is supposed to take 1ms, the hypervisor could sleep our partition for
27 * longer (eg 10ms). With the right timing these errors can add up.
28 *
29 * Since there is no 32bit overflow issue on 64bit kernels, just call
30 * udelay directly.
31 */
32#ifdef CONFIG_PPC64
33#define mdelay(n) udelay((n) * 1000)
34#endif
35
Timur Tabi93177262009-05-26 05:21:41 +000036/**
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(); \
Grant Likelyad9064d2009-06-29 13:40:51 +000066 if (!__ret) \
67 __ret = (condition); \
Timur Tabi93177262009-05-26 05:21:41 +000068 __ret; \
69})
70
Arnd Bergmann88ced032005-12-16 22:43:46 +010071#endif /* __KERNEL__ */
Paul Mackerrasc55377e2005-11-14 17:22:01 +110072#endif /* _ASM_POWERPC_DELAY_H */