sc520_timer.c 2.3 KB
Newer Older
G
Graeme Russ 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
/*
 * (C) Copyright 2002
 * Daniel Engstrm, Omicron Ceti AB <daniel@omicron.se>.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 */

/* stuff specific for the sc520, but independent of implementation */

#include <common.h>
#include <asm/interrupt.h>
#include <asm/ic/sc520.h>

G
Graeme Russ 已提交
30
void sc520_timer_isr(void)
G
Graeme Russ 已提交
31
{
G
Graeme Russ 已提交
32 33
	/* Ack the GP Timer Interrupt */
	write_mmcr_byte (SC520_GPTMRSTA, 0x02);
G
Graeme Russ 已提交
34 35
}

G
Graeme Russ 已提交
36
int timer_init(void)
G
Graeme Russ 已提交
37
{
G
Graeme Russ 已提交
38 39
	/* Map GP Timer 1 to Master PIC IR0  */
	write_mmcr_byte (SC520_GPTMR1MAP, 0x01);
G
Graeme Russ 已提交
40

G
Graeme Russ 已提交
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
	/* Disable GP Timers 1 & 2 - Allow configuration writes */
	write_mmcr_word (SC520_GPTMR1CTL, 0x4000);
	write_mmcr_word (SC520_GPTMR2CTL, 0x4000);

	/* Reset GP Timers 1 & 2 */
	write_mmcr_word (SC520_GPTMR1CNT, 0x0000);
	write_mmcr_word (SC520_GPTMR2CNT, 0x0000);

	/* Setup GP Timer 2 as a 100kHz (10us) prescaler */
	write_mmcr_word (SC520_GPTMR2MAXCMPA, 83);
	write_mmcr_word (SC520_GPTMR2CTL, 0xc001);

	/* Setup GP Timer 1 as a 1000 Hz (1ms) interrupt generator */
	write_mmcr_word (SC520_GPTMR1MAXCMPA, 100);
	write_mmcr_word (SC520_GPTMR1CTL, 0xe009);
G
Graeme Russ 已提交
56

G
Graeme Russ 已提交
57 58 59 60 61 62 63
	/* Register the SC520 specific timer interrupt handler */
	register_timer_isr (sc520_timer_isr);

	/* Install interrupt handler for GP Timer 1 */
	irq_install_handler (0, timer_isr, NULL);
	unmask_irq (0);

64 65 66
	/* Clear the GP Timer 1 status register to get the show rolling*/
	write_mmcr_byte (SC520_GPTMRSTA, 0x02);

G
Graeme Russ 已提交
67 68
	return 0;
}
G
Graeme Russ 已提交
69 70 71

void udelay(unsigned long usec)
{
G
Graeme Russ 已提交
72
	int m = 0;
G
Graeme Russ 已提交
73 74
	long u;

G
Graeme Russ 已提交
75 76
	read_mmcr_word (SC520_SWTMRMILLI);
	read_mmcr_word (SC520_SWTMRMICRO);
G
Graeme Russ 已提交
77

G
Graeme Russ 已提交
78 79 80 81
	do {
		m += read_mmcr_word (SC520_SWTMRMILLI);
		u = read_mmcr_word (SC520_SWTMRMICRO) + (m * 1000);
	} while (u < usec);
G
Graeme Russ 已提交
82
}