xref: /kernel/linux/linux-5.10/arch/h8300/lib/delay.c (revision 8c2ecf20)
18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * delay loops
48c2ecf20Sopenharmony_ci *
58c2ecf20Sopenharmony_ci * Copyright (C) 2015 Yoshinori Sato
68c2ecf20Sopenharmony_ci */
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <linux/module.h>
98c2ecf20Sopenharmony_ci#include <linux/delay.h>
108c2ecf20Sopenharmony_ci#include <asm/param.h>
118c2ecf20Sopenharmony_ci#include <asm/processor.h>
128c2ecf20Sopenharmony_ci#include <asm/timex.h>
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_civoid __delay(unsigned long cycles)
158c2ecf20Sopenharmony_ci{
168c2ecf20Sopenharmony_ci	__asm__ volatile ("1: dec.l #1,%0\n\t"
178c2ecf20Sopenharmony_ci			  "bne 1b":"=r"(cycles):"0"(cycles));
188c2ecf20Sopenharmony_ci}
198c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__delay);
208c2ecf20Sopenharmony_ci
218c2ecf20Sopenharmony_civoid __const_udelay(unsigned long xloops)
228c2ecf20Sopenharmony_ci{
238c2ecf20Sopenharmony_ci	u64 loops;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ci	loops = (u64)xloops * loops_per_jiffy * HZ;
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci	__delay(loops >> 32);
288c2ecf20Sopenharmony_ci}
298c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__const_udelay);
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_civoid __udelay(unsigned long usecs)
328c2ecf20Sopenharmony_ci{
338c2ecf20Sopenharmony_ci	__const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */
348c2ecf20Sopenharmony_ci}
358c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__udelay);
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_civoid __ndelay(unsigned long nsecs)
388c2ecf20Sopenharmony_ci{
398c2ecf20Sopenharmony_ci	__const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */
408c2ecf20Sopenharmony_ci}
418c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__ndelay);
42