|
|
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: *****************************************************************************/
1.1.1.2 ! root 12:
! 13: #include <stdint.h>
1.1 root 14:
15: //*******************************************************************
16: // variable "tb_freq" contains the frequency in Hz
17: // and is read from the device tree (setup by LLFW) in "init.c"
18: uint64_t tb_freq;
19:
20: //-------------------------------------------------------------------
21: // Read the current timebase
22: uint64_t get_time(void)
23: {
24: uint64_t act;
25:
26: __asm__ __volatile__(
27: "0: mftbu %0 ;\
28: mftbl %%r0 ; \
29: mftbu %%r4 ; \
30: cmpw %0,%%r4 ; \
31: bne 0b; \
32: sldi %0,%0,32; \
33: or %0,%0,%%r0"
34: : "=r"(act)
35: : /* no inputs */
36: : "r0", "r4");
37: return act;
38: }
39:
40: //-------------------------------------------------------------------
41: // wait for ticks/scale timebase ticks
42: void wait_ticks(uint64_t ticks)
43: {
44: uint64_t timeout = get_time() + ticks;
45: while (get_time() < timeout) {
46: unsigned int i;
47: for (i = 1000; i > 0; i--)
48: __asm__ __volatile__ ("" : : : "memory");
49: }
50: }
51:
52: //-------------------------------------------------------------------
53: // wait for (at least) usecs microseconds
54: void udelay(unsigned int usecs)
55: {
56: // first multiply the usec with timebase and then devide
57: // because 1.000.000 is relatively huge compared to usecs
58: wait_ticks((usecs*tb_freq)/1000000);
59: }
60:
61: //-------------------------------------------------------------------
62: // wait for (at least) msecs milliseconds
63: void mdelay(unsigned int msecs)
64: {
65: // first multiply the msec and timebase and then devide
66: // because 1.000 is relatively huge compared to msecs
67: wait_ticks((msecs*tb_freq)/1000);
68: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.