|
|
1.1 root 1: /******************************************************************************
2: * Copyright (c) 2004, 2008 IBM Corporation
3: * All rights reserved.
4: * This program and the accompanying materials
5: * are made available under the terms of the BSD License
6: * which accompanies this distribution, and is available at
7: * http://www.opensource.org/licenses/bsd-license.php
8: *
9: * Contributors:
10: * IBM Corporation - initial implementation
11: *****************************************************************************/
12: #include <types.h>
13:
14: //*******************************************************************
15: // variable "tb_freq" contains the frequency in Hz
16: // and is read from the device tree (setup by LLFW) in "init.c"
17: uint64_t tb_freq;
18:
19: //-------------------------------------------------------------------
20: // Read the current timebase
21: uint64_t get_time(void)
22: {
23: uint64_t act;
24:
25: __asm__ __volatile__(
26: "0: mftbu %0 ;\
27: mftbl %%r0 ; \
28: mftbu %%r4 ; \
29: cmpw %0,%%r4 ; \
30: bne 0b; \
31: sldi %0,%0,32; \
32: or %0,%0,%%r0"
33: : "=r"(act)
34: : /* no inputs */
35: : "r0", "r4");
36: return act;
37: }
38:
39: //-------------------------------------------------------------------
40: // wait for ticks/scale timebase ticks
41: void wait_ticks(uint64_t ticks)
42: {
43: uint64_t timeout = get_time() + ticks;
44: while (get_time() < timeout) {
45: unsigned int i;
46: for (i = 1000; i > 0; i--)
47: __asm__ __volatile__ ("" : : : "memory");
48: }
49: }
50:
51: //-------------------------------------------------------------------
52: // wait for (at least) usecs microseconds
53: void udelay(unsigned int usecs)
54: {
55: // first multiply the usec with timebase and then devide
56: // because 1.000.000 is relatively huge compared to usecs
57: wait_ticks((usecs*tb_freq)/1000000);
58: }
59:
60: //-------------------------------------------------------------------
61: // wait for (at least) msecs milliseconds
62: void mdelay(unsigned int msecs)
63: {
64: // first multiply the msec and timebase and then devide
65: // because 1.000 is relatively huge compared to msecs
66: wait_ticks((msecs*tb_freq)/1000);
67: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.