blob: d5617e91f6e154a1360f2a6a850e022a8df0aa66 [file] [log] [blame]
Graeme Russ85cc39f2009-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>
Graeme Russ0c5ced72010-04-24 00:05:37 +100027#include <asm/io.h>
Graeme Russ85cc39f2009-02-24 21:14:32 +110028#include <asm/interrupt.h>
29#include <asm/ic/sc520.h>
30
Graeme Russ7679d1f2009-02-24 21:14:45 +110031void sc520_timer_isr(void)
Graeme Russ85cc39f2009-02-24 21:14:32 +110032{
Graeme Russ7679d1f2009-02-24 21:14:45 +110033 /* Ack the GP Timer Interrupt */
Graeme Russ0c5ced72010-04-24 00:05:37 +100034 writeb(0x02, &sc520_mmcr->gptmrsta);
Graeme Russ85cc39f2009-02-24 21:14:32 +110035}
36
Graeme Russ7679d1f2009-02-24 21:14:45 +110037int timer_init(void)
Graeme Russ85cc39f2009-02-24 21:14:32 +110038{
Graeme Russcc272eb2009-11-24 20:04:17 +110039 /* 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
Graeme Russ7679d1f2009-02-24 21:14:45 +110045 /* Map GP Timer 1 to Master PIC IR0 */
Graeme Russ0c5ced72010-04-24 00:05:37 +100046 writeb(0x01, &sc520_mmcr->gp_tmr_int_map[1]);
Graeme Russ85cc39f2009-02-24 21:14:32 +110047
Graeme Russ7679d1f2009-02-24 21:14:45 +110048 /* Disable GP Timers 1 & 2 - Allow configuration writes */
Graeme Russ0c5ced72010-04-24 00:05:37 +100049 writew(0x4000, &sc520_mmcr->gptmr1ctl);
50 writew(0x4000, &sc520_mmcr->gptmr2ctl);
Graeme Russ85cc39f2009-02-24 21:14:32 +110051
Graeme Russ7679d1f2009-02-24 21:14:45 +110052 /* Reset GP Timers 1 & 2 */
Graeme Russ0c5ced72010-04-24 00:05:37 +100053 writew(0x0000, &sc520_mmcr->gptmr1cnt);
54 writew(0x0000, &sc520_mmcr->gptmr2cnt);
Graeme Russ7679d1f2009-02-24 21:14:45 +110055
56 /* Setup GP Timer 2 as a 100kHz (10us) prescaler */
Graeme Russ0c5ced72010-04-24 00:05:37 +100057 writew(83, &sc520_mmcr->gptmr2maxcmpa);
58 writew(0xc001, &sc520_mmcr->gptmr2ctl);
Graeme Russ7679d1f2009-02-24 21:14:45 +110059
60 /* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
Graeme Russ0c5ced72010-04-24 00:05:37 +100061 writew(100, &sc520_mmcr->gptmr1maxcmpa);
62 writew(0xe009, &sc520_mmcr->gptmr1ctl);
Graeme Russ7679d1f2009-02-24 21:14:45 +110063
Graeme Russ7679d1f2009-02-24 21:14:45 +110064 unmask_irq (0);
65
Graeme Russcf2fb0c2009-08-23 12:59:49 +100066 /* Clear the GP Timer 1 status register to get the show rolling*/
Graeme Russ0c5ced72010-04-24 00:05:37 +100067 writeb(0x02, &sc520_mmcr->gptmrsta);
Graeme Russcf2fb0c2009-08-23 12:59:49 +100068
Graeme Russ7679d1f2009-02-24 21:14:45 +110069 return 0;
70}
Graeme Russ85cc39f2009-02-24 21:14:32 +110071
Graeme Russf5f18282010-04-24 00:05:50 +100072/* Allow boards to override udelay implementation */
Ingo van Lilf0f778a2009-11-24 14:09:21 +010073void __udelay(unsigned long usec)
Graeme Russf5f18282010-04-24 00:05:50 +100074 __attribute__((weak, alias("sc520_udelay")));
75
76void sc520_udelay(unsigned long usec)
Graeme Russ85cc39f2009-02-24 21:14:32 +110077{
Graeme Russ7679d1f2009-02-24 21:14:45 +110078 int m = 0;
Graeme Russ85cc39f2009-02-24 21:14:32 +110079 long u;
Graeme Russ1d977dc2009-08-23 12:59:56 +100080 long temp;
Graeme Russ85cc39f2009-02-24 21:14:32 +110081
Graeme Russ0c5ced72010-04-24 00:05:37 +100082 temp = readw(&sc520_mmcr->swtmrmilli);
83 temp = readw(&sc520_mmcr->swtmrmicro);
Graeme Russ85cc39f2009-02-24 21:14:32 +110084
Graeme Russ7679d1f2009-02-24 21:14:45 +110085 do {
Graeme Russ0c5ced72010-04-24 00:05:37 +100086 m += readw(&sc520_mmcr->swtmrmilli);
87 u = readw(&sc520_mmcr->swtmrmicro) + (m * 1000);
Graeme Russ7679d1f2009-02-24 21:14:45 +110088 } while (u < usec);
Graeme Russ85cc39f2009-02-24 21:14:32 +110089}