blob: 2cb8656ebd5886fdf666099adc0f01325bd8f079 [file] [log] [blame]
Graeme Russ6d7f6102009-02-24 21:14:32 +11001/*
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
Graeme Russ8c63d472009-02-24 21:14:45 +110030void sc520_timer_isr(void)
Graeme Russ6d7f6102009-02-24 21:14:32 +110031{
Graeme Russ8c63d472009-02-24 21:14:45 +110032 /* Ack the GP Timer Interrupt */
33 write_mmcr_byte (SC520_GPTMRSTA, 0x02);
Graeme Russ6d7f6102009-02-24 21:14:32 +110034}
35
Graeme Russ8c63d472009-02-24 21:14:45 +110036int timer_init(void)
Graeme Russ6d7f6102009-02-24 21:14:32 +110037{
Graeme Russ8c63d472009-02-24 21:14:45 +110038 /* Map GP Timer 1 to Master PIC IR0 */
39 write_mmcr_byte (SC520_GPTMR1MAP, 0x01);
Graeme Russ6d7f6102009-02-24 21:14:32 +110040
Graeme Russ8c63d472009-02-24 21:14:45 +110041 /* Disable GP Timers 1 & 2 - Allow configuration writes */
42 write_mmcr_word (SC520_GPTMR1CTL, 0x4000);
43 write_mmcr_word (SC520_GPTMR2CTL, 0x4000);
Graeme Russ6d7f6102009-02-24 21:14:32 +110044
Graeme Russ8c63d472009-02-24 21:14:45 +110045 /* Reset GP Timers 1 & 2 */
46 write_mmcr_word (SC520_GPTMR1CNT, 0x0000);
47 write_mmcr_word (SC520_GPTMR2CNT, 0x0000);
48
49 /* Setup GP Timer 2 as a 100kHz (10us) prescaler */
50 write_mmcr_word (SC520_GPTMR2MAXCMPA, 83);
51 write_mmcr_word (SC520_GPTMR2CTL, 0xc001);
52
53 /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
54 write_mmcr_word (SC520_GPTMR1MAXCMPA, 100);
55 write_mmcr_word (SC520_GPTMR1CTL, 0xe009);
56
57 /* Clear the GP Timers status register */
58 write_mmcr_byte (SC520_GPTMRSTA, 0x07);
59
60 /* Register the SC520 specific timer interrupt handler */
61 register_timer_isr (sc520_timer_isr);
62
63 /* Install interrupt handler for GP Timer 1 */
64 irq_install_handler (0, timer_isr, NULL);
65 unmask_irq (0);
66
67 return 0;
68}
Graeme Russ6d7f6102009-02-24 21:14:32 +110069
70void udelay(unsigned long usec)
71{
Graeme Russ8c63d472009-02-24 21:14:45 +110072 int m = 0;
Graeme Russ6d7f6102009-02-24 21:14:32 +110073 long u;
74
Graeme Russ8c63d472009-02-24 21:14:45 +110075 read_mmcr_word (SC520_SWTMRMILLI);
76 read_mmcr_word (SC520_SWTMRMICRO);
Graeme Russ6d7f6102009-02-24 21:14:32 +110077
Graeme Russ8c63d472009-02-24 21:14:45 +110078 do {
79 m += read_mmcr_word (SC520_SWTMRMILLI);
80 u = read_mmcr_word (SC520_SWTMRMICRO) + (m * 1000);
81 } while (u < usec);
Graeme Russ6d7f6102009-02-24 21:14:32 +110082}