blob: 47f98c5067b5e6fffc202d7235274e51f4242900 [file] [log] [blame]
Mike Frysinger9e83b982007-11-21 16:08:58 +08001/*
2 * delay.h - delay functions
3 *
4 * Copyright (c) 2004-2007 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef __ASM_DELAY_H__
10#define __ASM_DELAY_H__
11
Bryan Wu639f6572008-08-27 10:51:02 +080012#include <mach/anomaly.h>
Bryan Wu1394f032007-05-06 14:50:22 -070013
14static inline void __delay(unsigned long loops)
15{
Mike Frysinger9e83b982007-11-21 16:08:58 +080016 if (ANOMALY_05000312) {
17 /* Interrupted loads to loop registers -> bad */
18 unsigned long tmp;
19 __asm__ __volatile__(
20 "[--SP] = LC0;"
21 "[--SP] = LT0;"
22 "[--SP] = LB0;"
23 "LSETUP (1f,1f) LC0 = %1;"
24 "1: NOP;"
25 /* We take advantage of the fact that LC0 is 0 at
26 * the end of the loop. Otherwise we'd need some
27 * NOPs after the CLI here.
28 */
29 "CLI %0;"
30 "LB0 = [SP++];"
31 "LT0 = [SP++];"
32 "LC0 = [SP++];"
33 "STI %0;"
34 : "=d" (tmp)
35 : "a" (loops)
36 );
37 } else
38 __asm__ __volatile__ (
39 "LSETUP(1f, 1f) LC0 = %0;"
40 "1: NOP;"
41 :
42 : "a" (loops)
43 : "LT0", "LB0", "LC0"
44 );
Bryan Wu1394f032007-05-06 14:50:22 -070045}
46
47#include <linux/param.h> /* needed for HZ */
48
49/*
Michael Hennerich4e653e02009-02-04 16:49:45 +080050 * close approximation borrowed from m68knommu to avoid 64-bit math
Bryan Wu1394f032007-05-06 14:50:22 -070051 */
Michael Hennerich4e653e02009-02-04 16:49:45 +080052
53#define HZSCALE (268435456 / (1000000/HZ))
54
Bryan Wu1394f032007-05-06 14:50:22 -070055static inline void udelay(unsigned long usecs)
56{
57 extern unsigned long loops_per_jiffy;
Michael Hennerich4e653e02009-02-04 16:49:45 +080058 __delay((((usecs * HZSCALE) >> 11) * (loops_per_jiffy >> 11)) >> 6);
Bryan Wu1394f032007-05-06 14:50:22 -070059}
60
Mike Frysinger9e83b982007-11-21 16:08:58 +080061#endif