blob: a92bd621aa1f6e5e64a7ade5ad392c5d5c46e918 [file] [log] [blame]
Jonas Bonn224cd122011-06-04 22:44:40 +03001/*
2 * OpenRISC Linux
3 *
4 * Linux architectural port borrowing liberally from similar works of
5 * others. All original copyrights apply as per the original source
6 * declaration.
7 *
8 * Modifications for the OpenRISC architecture:
9 * Copyright (C) 2010-2011 Jonas Bonn <jonas@southpole.se>
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * version 2 as published by the Free Software Foundation
14 *
15 * Precise Delay Loops
16 */
17
18#include <linux/kernel.h>
Stafford Horne19388522017-03-14 22:54:22 +090019#include <linux/export.h>
Jonas Bonn224cd122011-06-04 22:44:40 +030020#include <linux/init.h>
Stafford Horne19388522017-03-14 22:54:22 +090021#include <asm/param.h>
Jonas Bonn224cd122011-06-04 22:44:40 +030022#include <asm/delay.h>
23#include <asm/timex.h>
24#include <asm/processor.h>
25
Greg Kroah-Hartmanb881bc42012-12-21 14:06:37 -080026int read_current_timer(unsigned long *timer_value)
Jonas Bonn224cd122011-06-04 22:44:40 +030027{
Stefan Kristiansson8e6d08e2014-05-11 21:49:34 +030028 *timer_value = get_cycles();
Jonas Bonn224cd122011-06-04 22:44:40 +030029 return 0;
30}
31
32void __delay(unsigned long cycles)
33{
Will Deacon807607f2012-08-07 17:59:54 +010034 cycles_t start = get_cycles();
Jonas Bonn224cd122011-06-04 22:44:40 +030035
Will Deacon807607f2012-08-07 17:59:54 +010036 while ((get_cycles() - start) < cycles)
Jonas Bonn224cd122011-06-04 22:44:40 +030037 cpu_relax();
38}
39EXPORT_SYMBOL(__delay);
40
41inline void __const_udelay(unsigned long xloops)
42{
43 unsigned long long loops;
44
Will Deacon43916462012-08-07 17:59:53 +010045 loops = (unsigned long long)xloops * loops_per_jiffy * HZ;
Jonas Bonn224cd122011-06-04 22:44:40 +030046
47 __delay(loops >> 32);
48}
49EXPORT_SYMBOL(__const_udelay);
50
51void __udelay(unsigned long usecs)
52{
53 __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
54}
55EXPORT_SYMBOL(__udelay);
56
57void __ndelay(unsigned long nsecs)
58{
59 __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
60}
61EXPORT_SYMBOL(__ndelay);