1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000, 2001
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 /* ------------------------------------------------------------------------- */
15 * This function is intended for SHORT delays only.
16 * It will overflow at around 10 seconds @ 400MHz,
17 * or 20 seconds @ 200MHz.
19 unsigned long usec2ticks(unsigned long usec)
24 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
26 ticks = ((usec / 10) * (get_tbclk() / 100000));
32 /* ------------------------------------------------------------------------- */
35 * We implement the delay by converting the delay (the number of
36 * microseconds to wait) into a number of time base ticks; then we
37 * watch the time base until it has incremented by that amount.
39 void __udelay(unsigned long usec)
41 ulong ticks = usec2ticks (usec);
45 /* ------------------------------------------------------------------------- */
46 #ifndef CONFIG_NAND_SPL
47 unsigned long ticks2usec(unsigned long ticks)
49 ulong tbclk = get_tbclk();
51 /* usec = ticks * 1000000 / tbclk
52 * Multiplication would overflow at ~4.2e3 ticks,
53 * so we break it up into
54 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
60 return ((ulong)ticks);
63 /* ------------------------------------------------------------------------- */
70 asm volatile("li %0,0 ; mttbl %0 ; mttbu %0;"
75 /* ------------------------------------------------------------------------- */