2 * (C) Copyright 2000, 2001
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26 /* ------------------------------------------------------------------------- */
29 * This function is intended for SHORT delays only.
30 * It will overflow at around 10 seconds @ 400MHz,
31 * or 20 seconds @ 200MHz.
33 unsigned long usec2ticks(unsigned long usec)
38 ticks = ((usec * (get_tbclk()/1000)) + 500) / 1000;
40 ticks = ((usec / 10) * (get_tbclk() / 100000));
46 /* ------------------------------------------------------------------------- */
49 * We implement the delay by converting the delay (the number of
50 * microseconds to wait) into a number of time base ticks; then we
51 * watch the time base until it has incremented by that amount.
53 void __udelay(unsigned long usec)
55 ulong ticks = usec2ticks (usec);
59 /* ------------------------------------------------------------------------- */
60 #ifndef CONFIG_NAND_SPL
61 unsigned long ticks2usec(unsigned long ticks)
63 ulong tbclk = get_tbclk();
65 /* usec = ticks * 1000000 / tbclk
66 * Multiplication would overflow at ~4.2e3 ticks,
67 * so we break it up into
68 * usec = ( ( ticks * 1000) / tbclk ) * 1000;
74 return ((ulong)ticks);
77 /* ------------------------------------------------------------------------- */
79 int init_timebase (void)
81 #if defined(CONFIG_5xx) || defined(CONFIG_8xx)
82 volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
85 immap->im_sitk.sitk_tbk = KAPWR_KEY;
89 asm ("li 3,0 ; mttbu 3 ; mttbl 3 ;");
91 #if defined(CONFIG_5xx) || defined(CONFIG_8xx)
93 immap->im_sit.sit_tbscr |= TBSCR_TBE;
97 /* ------------------------------------------------------------------------- */