blob: 036ae57180ef2c42e762bc45db45cc509994920b [file] [log] [blame]
Thomas Gleixnerd2912cb2019-06-04 10:11:33 +02001// SPDX-License-Identifier: GPL-2.0-only
Jonas Bonn224cd122011-06-04 22:44:40 +03002/*
3 * OpenRISC Linux
4 *
5 * Linux architectural port borrowing liberally from similar works of
6 * others. All original copyrights apply as per the original source
7 * declaration.
8 *
9 * Modifications for the OpenRISC architecture:
10 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
11 *
Jonas Bonn224cd122011-06-04 22:44:40 +030012 * Precise Delay Loops
13 */
14
15#include <linux/kernel.h>
Stafford Horne19388522017-03-14 22:54:22 +090016#include <linux/export.h>
Jonas Bonn224cd122011-06-04 22:44:40 +030017#include <linux/init.h>
Stafford Horne19388522017-03-14 22:54:22 +090018#include <asm/param.h>
Jonas Bonn224cd122011-06-04 22:44:40 +030019#include <asm/delay.h>
20#include <asm/timex.h>
21#include <asm/processor.h>
22
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -080023int read_current_timer(unsigned long *timer_value)
Jonas Bonn224cd122011-06-04 22:44:40 +030024{
Stefan Kristiansson8e6d08e2014-05-11 21:49:34 +030025 *timer_value = get_cycles();
Jonas Bonn224cd122011-06-04 22:44:40 +030026 return 0;
27}
28
29void __delay(unsigned long cycles)
30{
Will Deacon807607f2012-08-07 17:59:54 +010031 cycles_t start = get_cycles();
Jonas Bonn224cd122011-06-04 22:44:40 +030032
Will Deacon807607f2012-08-07 17:59:54 +010033 while ((get_cycles() - start) < cycles)
Jonas Bonn224cd122011-06-04 22:44:40 +030034 cpu_relax();
35}
36EXPORT_SYMBOL(__delay);
37
38inline void __const_udelay(unsigned long xloops)
39{
40 unsigned long long loops;
41
Will Deacon43916462012-08-07 17:59:53 +010042 loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
Jonas Bonn224cd122011-06-04 22:44:40 +030043
44 __delay(loops >> 32);
45}
46EXPORT_SYMBOL(__const_udelay);
47
48void __udelay(unsigned long usecs)
49{
50 __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
51}
52EXPORT_SYMBOL(__udelay);
53
54void __ndelay(unsigned long nsecs)
55{
56 __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
57}
58EXPORT_SYMBOL(__ndelay);