2007-02-16 21:36:55 +07:00
|
|
|
/*
|
|
|
|
* arch/arm/mach-ns9xxx/time.c
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 by Digi International Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License version 2 as published by
|
|
|
|
* the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/irq.h>
|
2007-10-01 02:35:48 +07:00
|
|
|
#include <linux/stringify.h>
|
|
|
|
#include <linux/clocksource.h>
|
|
|
|
|
2007-02-16 21:36:55 +07:00
|
|
|
#include <asm/arch-ns9xxx/regs-sys.h>
|
|
|
|
#include <asm/arch-ns9xxx/clock.h>
|
|
|
|
#include <asm/arch-ns9xxx/irqs.h>
|
|
|
|
#include <asm/arch/system.h>
|
|
|
|
#include "generic.h"
|
|
|
|
|
|
|
|
#define TIMERCLOCKSELECT 64
|
2007-10-01 02:35:48 +07:00
|
|
|
#define TIMER_CLOCKSOURCE 1
|
2007-02-16 21:36:55 +07:00
|
|
|
|
|
|
|
static irqreturn_t
|
|
|
|
ns9xxx_timer_interrupt(int irq, void *dev_id)
|
|
|
|
{
|
2007-08-08 03:08:21 +07:00
|
|
|
int timerno = irq - IRQ_TIMER0;
|
|
|
|
u32 tc;
|
|
|
|
|
2007-02-16 21:36:55 +07:00
|
|
|
write_seqlock(&xtime_lock);
|
|
|
|
timer_tick();
|
|
|
|
write_sequnlock(&xtime_lock);
|
|
|
|
|
2007-08-08 03:08:21 +07:00
|
|
|
/* clear irq */
|
|
|
|
tc = SYS_TC(timerno);
|
|
|
|
if (REGGET(tc, SYS_TCx, REN) == SYS_TCx_REN_DIS) {
|
|
|
|
REGSET(tc, SYS_TCx, TEN, DIS);
|
|
|
|
SYS_TC(timerno) = tc;
|
|
|
|
}
|
|
|
|
REGSET(tc, SYS_TCx, INTC, SET);
|
|
|
|
SYS_TC(timerno) = tc;
|
|
|
|
REGSET(tc, SYS_TCx, INTC, UNSET);
|
|
|
|
SYS_TC(timerno) = tc;
|
|
|
|
|
2007-02-16 21:36:55 +07:00
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct irqaction ns9xxx_timer_irq = {
|
|
|
|
.name = "NS9xxx Timer Tick",
|
2007-05-08 14:35:39 +07:00
|
|
|
.flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
|
2007-02-16 21:36:55 +07:00
|
|
|
.handler = ns9xxx_timer_interrupt,
|
|
|
|
};
|
|
|
|
|
2007-10-01 02:35:48 +07:00
|
|
|
static cycle_t ns9xxx_clocksource_read(void)
|
|
|
|
{
|
|
|
|
return SYS_TR(TIMER_CLOCKSOURCE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct clocksource ns9xxx_clocksource = {
|
|
|
|
.name = "ns9xxx-timer" __stringify(TIMER_CLOCKSOURCE),
|
|
|
|
.rating = 300,
|
|
|
|
.read = ns9xxx_clocksource_read,
|
|
|
|
.mask = CLOCKSOURCE_MASK(32),
|
|
|
|
.shift = 20,
|
|
|
|
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
|
|
|
|
};
|
|
|
|
|
2007-02-16 21:36:55 +07:00
|
|
|
static void __init ns9xxx_timer_init(void)
|
|
|
|
{
|
|
|
|
int tc;
|
|
|
|
|
|
|
|
/* disable timer */
|
|
|
|
if ((tc = SYS_TC(0)) & SYS_TCx_TEN)
|
|
|
|
SYS_TC(0) = tc & ~SYS_TCx_TEN;
|
|
|
|
|
|
|
|
SYS_TRC(0) = SH_DIV(ns9xxx_cpuclock(), (TIMERCLOCKSELECT * HZ), 0);
|
|
|
|
|
|
|
|
REGSET(tc, SYS_TCx, TEN, EN);
|
|
|
|
REGSET(tc, SYS_TCx, TLCS, DIV64); /* This must match TIMERCLOCKSELECT */
|
|
|
|
REGSET(tc, SYS_TCx, INTS, EN);
|
|
|
|
REGSET(tc, SYS_TCx, UDS, DOWN);
|
|
|
|
REGSET(tc, SYS_TCx, TDBG, STOP);
|
|
|
|
REGSET(tc, SYS_TCx, TSZ, 32);
|
|
|
|
REGSET(tc, SYS_TCx, REN, EN);
|
|
|
|
SYS_TC(0) = tc;
|
|
|
|
|
|
|
|
setup_irq(IRQ_TIMER0, &ns9xxx_timer_irq);
|
2007-10-01 02:35:48 +07:00
|
|
|
|
|
|
|
tc = SYS_TC(TIMER_CLOCKSOURCE);
|
|
|
|
if (REGGET(tc, SYS_TCx, TEN)) {
|
|
|
|
REGSET(tc, SYS_TCx, TEN, DIS);
|
|
|
|
SYS_TC(TIMER_CLOCKSOURCE) = tc;
|
|
|
|
}
|
|
|
|
|
|
|
|
SYS_TRC(TIMER_CLOCKSOURCE) = 0;
|
|
|
|
|
|
|
|
REGSET(tc, SYS_TCx, TEN, EN);
|
|
|
|
REGSET(tc, SYS_TCx, TDBG, STOP);
|
|
|
|
REGSET(tc, SYS_TCx, TLCS, CPU);
|
|
|
|
REGSET(tc, SYS_TCx, TM, IEE);
|
|
|
|
REGSET(tc, SYS_TCx, INTS, DIS);
|
|
|
|
REGSET(tc, SYS_TCx, UDS, UP);
|
|
|
|
REGSET(tc, SYS_TCx, TSZ, 32);
|
|
|
|
REGSET(tc, SYS_TCx, REN, EN);
|
|
|
|
|
|
|
|
SYS_TC(TIMER_CLOCKSOURCE) = tc;
|
|
|
|
|
|
|
|
ns9xxx_clocksource.mult = clocksource_hz2mult(ns9xxx_cpuclock(),
|
|
|
|
ns9xxx_clocksource.shift);
|
|
|
|
|
|
|
|
clocksource_register(&ns9xxx_clocksource);
|
2007-02-16 21:36:55 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
struct sys_timer ns9xxx_timer = {
|
|
|
|
.init = ns9xxx_timer_init,
|
|
|
|
};
|