]> git.sur5r.net Git - u-boot/blob - cpu/i386/sc520/sc520_timer.c
Factor out SC520 sub-features
[u-boot] / cpu / i386 / sc520 / sc520_timer.c
1 /*
2  * (C) Copyright 2002
3  * Daniel Engström, Omicron Ceti AB <daniel@omicron.se>.
4  *
5  * See file CREDITS for list of people who contributed to this
6  * project.
7  *
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.
12  *
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.
17  *
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,
21  * MA 02111-1307 USA
22  */
23
24 /* stuff specific for the sc520, but independent of implementation */
25
26 #include <common.h>
27 #include <asm/interrupt.h>
28 #include <asm/ic/sc520.h>
29
30 void reset_timer(void)
31 {
32         write_mmcr_word(SC520_GPTMR0CNT, 0);
33         write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
34
35 }
36
37 ulong get_timer(ulong base)
38 {
39         /* fixme: 30 or 33 */
40         return  read_mmcr_word(SC520_GPTMR0CNT) / 33;
41 }
42
43 void set_timer(ulong t)
44 {
45         /* FixMe: use two cascade coupled timers */
46         write_mmcr_word(SC520_GPTMR0CTL, 0x4001);
47         write_mmcr_word(SC520_GPTMR0CNT, t*33);
48         write_mmcr_word(SC520_GPTMR0CTL, 0x6001);
49 }
50
51
52 void udelay(unsigned long usec)
53 {
54         int m=0;
55         long u;
56
57         read_mmcr_word(SC520_SWTMRMILLI);
58         read_mmcr_word(SC520_SWTMRMICRO);
59
60 #if 0
61         /* do not enable this line, udelay is used in the serial driver -> recursion */
62         printf("udelay: %ld m.u %d.%d  tm.tu %d.%d\n", usec, m, u, tm, tu);
63 #endif
64         while (1) {
65
66                 m += read_mmcr_word(SC520_SWTMRMILLI);
67                 u = read_mmcr_word(SC520_SWTMRMICRO) + (m * 1000);
68
69                 if (usec <= u) {
70                         break;
71                 }
72         }
73 }