// SPDX-License-Identifier: GPL-2.01/*2* Copyright (C) 2020-2022 Loongson Technology Corporation Limited3*/4#include <linux/delay.h>5#include <linux/export.h>6#include <linux/smp.h>7#include <linux/timex.h>89#include <asm/processor.h>1011void __delay(unsigned long cycles)12{13u64 t0 = get_cycles();1415while ((unsigned long)(get_cycles() - t0) < cycles)16cpu_relax();17}18EXPORT_SYMBOL(__delay);1920/*21* Division by multiplication: you don't have to worry about22* loss of precision.23*24* Use only for very small delays ( < 1 msec). Should probably use a25* lookup table, really, as the multiplications take much too long with26* short delays. This is a "reasonable" implementation, though (and the27* first constant multiplications gets optimized away if the delay is28* a constant)29*/3031void __udelay(unsigned long us)32{33__delay((us * 0x000010c7ull * HZ * lpj_fine) >> 32);34}35EXPORT_SYMBOL(__udelay);3637void __ndelay(unsigned long ns)38{39__delay((ns * 0x00000005ull * HZ * lpj_fine) >> 32);40}41EXPORT_SYMBOL(__ndelay);424344