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/io.h>
28 #include <asm/interrupt.h>
29 #include <asm/ic/sc520.h>
30 
sc520_timer_isr(void)31 void sc520_timer_isr(void)
32 {
33 	/* Ack the GP Timer Interrupt */
34 	writeb(0x02, &sc520_mmcr->gptmrsta);
35 }
36 
timer_init(void)37 int timer_init(void)
38 {
39 	/* Register the SC520 specific timer interrupt handler */
40 	register_timer_isr (sc520_timer_isr);
41 
42 	/* Install interrupt handler for GP Timer 1 */
43 	irq_install_handler (0, timer_isr, NULL);
44 
45 	/* Map GP Timer 1 to Master PIC IR0  */
46 	writeb(0x01, &sc520_mmcr->gp_tmr_int_map[1]);
47 
48 	/* Disable GP Timers 1 & 2 - Allow configuration writes */
49 	writew(0x4000, &sc520_mmcr->gptmr1ctl);
50 	writew(0x4000, &sc520_mmcr->gptmr2ctl);
51 
52 	/* Reset GP Timers 1 & 2 */
53 	writew(0x0000, &sc520_mmcr->gptmr1cnt);
54 	writew(0x0000, &sc520_mmcr->gptmr2cnt);
55 
56 	/* Setup GP Timer 2 as a 100kHz (10us) prescaler */
57 	writew(83, &sc520_mmcr->gptmr2maxcmpa);
58 	writew(0xc001, &sc520_mmcr->gptmr2ctl);
59 
60 	/* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
61 	writew(100, &sc520_mmcr->gptmr1maxcmpa);
62 	writew(0xe009, &sc520_mmcr->gptmr1ctl);
63 
64 	unmask_irq (0);
65 
66 	/* Clear the GP Timer 1 status register to get the show rolling*/
67 	writeb(0x02, &sc520_mmcr->gptmrsta);
68 
69 	return 0;
70 }
71 
72 /* Allow boards to override udelay implementation */
73 void __udelay(unsigned long usec)
74 	__attribute__((weak, alias("sc520_udelay")));
75 
sc520_udelay(unsigned long usec)76 void sc520_udelay(unsigned long usec)
77 {
78 	int m = 0;
79 	long u;
80 	long temp;
81 
82 	temp = readw(&sc520_mmcr->swtmrmilli);
83 	temp = readw(&sc520_mmcr->swtmrmicro);
84 
85 	do {
86 		m += readw(&sc520_mmcr->swtmrmilli);
87 		u = readw(&sc520_mmcr->swtmrmicro) + (m * 1000);
88 	} while (u < usec);
89 }
90