1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000, 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
11 #include <linux/delay.h>
13 /* ------------------------------------------------------------------------- */
16 * This function is intended for SHORT delays only.
17 * It will overflow at around 10 seconds @ 400MHz,
18 * or 20 seconds @ 200MHz.
20 unsigned long usec2ticks(unsigned long usec)
25 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
27 ticks = ((usec / 10) * (get_tbclk() / 100000));
33 /* ------------------------------------------------------------------------- */
36 * We implement the delay by converting the delay (the number of
37 * microseconds to wait) into a number of time base ticks; then we
38 * watch the time base until it has incremented by that amount.
40 void __udelay(unsigned long usec)
42 ulong ticks = usec2ticks (usec);
46 /* ------------------------------------------------------------------------- */
47 #ifndef CONFIG_NAND_SPL
48 unsigned long ticks2usec(unsigned long ticks)
50 ulong tbclk = get_tbclk();
52 /* usec = ticks * 1000000 / tbclk
53 * Multiplication would overflow at ~4.2e3 ticks,
54 * so we break it up into
55 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
61 return ((ulong)ticks);
64 /* ------------------------------------------------------------------------- */
71 asm volatile("li %0,0 ; mttbl %0 ; mttbu %0;"
76 /* ------------------------------------------------------------------------- */