18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/* Copyright Altera Corporation (C) 2014. All rights reserved. 38c2ecf20Sopenharmony_ci */ 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <linux/module.h> 68c2ecf20Sopenharmony_ci#include <asm/delay.h> 78c2ecf20Sopenharmony_ci#include <asm/param.h> 88c2ecf20Sopenharmony_ci#include <asm/processor.h> 98c2ecf20Sopenharmony_ci#include <asm/timex.h> 108c2ecf20Sopenharmony_ci 118c2ecf20Sopenharmony_civoid __delay(unsigned long cycles) 128c2ecf20Sopenharmony_ci{ 138c2ecf20Sopenharmony_ci cycles_t start = get_cycles(); 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_ci while ((get_cycles() - start) < cycles) 168c2ecf20Sopenharmony_ci cpu_relax(); 178c2ecf20Sopenharmony_ci} 188c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__delay); 198c2ecf20Sopenharmony_ci 208c2ecf20Sopenharmony_civoid __const_udelay(unsigned long xloops) 218c2ecf20Sopenharmony_ci{ 228c2ecf20Sopenharmony_ci u64 loops; 238c2ecf20Sopenharmony_ci 248c2ecf20Sopenharmony_ci loops = (u64)xloops * loops_per_jiffy * HZ; 258c2ecf20Sopenharmony_ci 268c2ecf20Sopenharmony_ci __delay(loops >> 32); 278c2ecf20Sopenharmony_ci} 288c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__const_udelay); 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_civoid __udelay(unsigned long usecs) 318c2ecf20Sopenharmony_ci{ 328c2ecf20Sopenharmony_ci __const_udelay(usecs * 0x10C7UL); /* 2**32 / 1000000 (rounded up) */ 338c2ecf20Sopenharmony_ci} 348c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__udelay); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_civoid __ndelay(unsigned long nsecs) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci __const_udelay(nsecs * 0x5UL); /* 2**32 / 1000000000 (rounded up) */ 398c2ecf20Sopenharmony_ci} 408c2ecf20Sopenharmony_ciEXPORT_SYMBOL(__ndelay); 41