Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris...
[linux/fpc-iii.git] / arch / c6x / include / asm / delay.h
blobf314c2e9eb540fe444e8c84e038fda183e8bd8ab
1 /*
2 * Port on Texas Instruments TMS320C6x architecture
4 * Copyright (C) 2004, 2009, 2010, 2011 Texas Instruments Incorporated
5 * Author: Aurelien Jacquiot (aurelien.jacquiot@jaluna.com)
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
11 #ifndef _ASM_C6X_DELAY_H
12 #define _ASM_C6X_DELAY_H
14 #include <linux/kernel.h>
16 extern unsigned int ticks_per_ns_scaled;
18 static inline void __delay(unsigned long loops)
20 uint32_t tmp;
22 /* 6 cycles per loop */
23 asm volatile (" mv .s1 %0,%1\n"
24 "0: [%1] b .s1 0b\n"
25 " add .l1 -6,%0,%0\n"
26 " cmplt .l1 1,%0,%1\n"
27 " nop 3\n"
28 : "+a"(loops), "=A"(tmp));
31 static inline void _c6x_tickdelay(unsigned int x)
33 uint32_t cnt, endcnt;
35 asm volatile (" mvc .s2 TSCL,%0\n"
36 " add .s2x %0,%1,%2\n"
37 " || mvk .l2 1,B0\n"
38 "0: [B0] b .s2 0b\n"
39 " mvc .s2 TSCL,%0\n"
40 " sub .s2 %0,%2,%0\n"
41 " cmpgt .l2 0,%0,B0\n"
42 " nop 2\n"
43 : "=b"(cnt), "+a"(x), "=b"(endcnt) : : "B0");
46 /* use scaled math to avoid slow division */
47 #define C6X_NDELAY_SCALE 10
49 static inline void _ndelay(unsigned int n)
51 _c6x_tickdelay((ticks_per_ns_scaled * n) >> C6X_NDELAY_SCALE);
54 static inline void _udelay(unsigned int n)
56 while (n >= 10) {
57 _ndelay(10000);
58 n -= 10;
60 while (n-- > 0)
61 _ndelay(1000);
64 #define udelay(x) _udelay((unsigned int)(x))
65 #define ndelay(x) _ndelay((unsigned int)(x))
67 #endif /* _ASM_C6X_DELAY_H */