• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  *	Precise Delay Loops for Meta
4  *
5  *	Copyright (C) 1993 Linus Torvalds
6  *	Copyright (C) 1997 Martin Mares <mj@atrey.karlin.mff.cuni.cz>
7  *	Copyright (C) 2007,2009 Imagination Technologies Ltd.
8  *
9  */
10 
11 #include <linux/export.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
14 
15 #include <asm/core_reg.h>
16 #include <asm/processor.h>
17 
18 /*
19  * TXTACTCYC is only 24 bits, so on chips with fast clocks it will wrap
20  * many times per-second. If it does wrap __delay will return prematurely,
21  * but this is only likely with large delay values.
22  *
23  * We also can't implement read_current_timer() with TXTACTCYC due to
24  * this wrapping behaviour.
25  */
26 #define rdtimer(t) t = __core_reg_get(TXTACTCYC)
27 
__delay(unsigned long loops)28 void __delay(unsigned long loops)
29 {
30 	unsigned long bclock, now;
31 
32 	rdtimer(bclock);
33 	do {
34 		asm("NOP");
35 		rdtimer(now);
36 	} while ((now-bclock) < loops);
37 }
38 EXPORT_SYMBOL(__delay);
39 
__const_udelay(unsigned long xloops)40 inline void __const_udelay(unsigned long xloops)
41 {
42 	u64 loops = (u64)xloops * (u64)loops_per_jiffy * HZ;
43 	__delay(loops >> 32);
44 }
45 EXPORT_SYMBOL(__const_udelay);
46 
__udelay(unsigned long usecs)47 void __udelay(unsigned long usecs)
48 {
49 	__const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
50 }
51 EXPORT_SYMBOL(__udelay);
52 
__ndelay(unsigned long nsecs)53 void __ndelay(unsigned long nsecs)
54 {
55 	__const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
56 }
57 EXPORT_SYMBOL(__ndelay);
58