Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / arch / metag / lib / delay.c
blob6754012a261ffa71105d6c45ce7d42b85d9bdd73
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Precise Delay Loops for Meta
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.
9 */
11 #include <linux/export.h>
12 #include <linux/sched.h>
13 #include <linux/delay.h>
15 #include <asm/core_reg.h>
16 #include <asm/processor.h>
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.
23 * We also can't implement read_current_timer() with TXTACTCYC due to
24 * this wrapping behaviour.
26 #define rdtimer(t) t = __core_reg_get(TXTACTCYC)
28 void __delay(unsigned long loops)
30 unsigned long bclock, now;
32 rdtimer(bclock);
33 do {
34 asm("NOP");
35 rdtimer(now);
36 } while ((now-bclock) < loops);
38 EXPORT_SYMBOL(__delay);
40 inline void __const_udelay(unsigned long xloops)
42 u64 loops = (u64)xloops * (u64)loops_per_jiffy * HZ;
43 __delay(loops >> 32);
45 EXPORT_SYMBOL(__const_udelay);
47 void __udelay(unsigned long usecs)
49 __const_udelay(usecs * 0x000010c7); /* 2**32 / 1000000 (rounded up) */
51 EXPORT_SYMBOL(__udelay);
53 void __ndelay(unsigned long nsecs)
55 __const_udelay(nsecs * 0x00005); /* 2**32 / 1000000000 (rounded up) */
57 EXPORT_SYMBOL(__ndelay);