xref: /kernel/linux/linux-5.10/arch/h8300/lib/delay.c (revision 8c2ecf20)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * delay loops
4 *
5 * Copyright (C) 2015 Yoshinori Sato
6 */
7
8#include <linux/module.h>
9#include <linux/delay.h>
10#include <asm/param.h>
11#include <asm/processor.h>
12#include <asm/timex.h>
13
14void __delay(unsigned long cycles)
15{
16	__asm__ volatile ("1: dec.l #1,%0\n\t"
17			  "bne 1b":"=r"(cycles):"0"(cycles));
18}
19EXPORT_SYMBOL(__delay);
20
21void __const_udelay(unsigned long xloops)
22{
23	u64 loops;
24
25	loops = (u64)xloops * loops_per_jiffy * HZ;
26
27	__delay(loops >> 32);
28}
29EXPORT_SYMBOL(__const_udelay);
30
31void __udelay(unsigned long usecs)
32{
33	__const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
34}
35EXPORT_SYMBOL(__udelay);
36
37void __ndelay(unsigned long nsecs)
38{
39	__const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
40}
41EXPORT_SYMBOL(__ndelay);
42