xtensa: cleanup ccount frequency tracking
[linux-2.6-block.git] / arch / xtensa / kernel / time.c
CommitLineData
5a0015d6
CZ
1/*
2 * arch/xtensa/kernel/time.c
3 *
4 * Timer and clock support.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 *
10 * Copyright (C) 2005 Tensilica Inc.
11 *
12 * Chris Zankel <chris@zankel.net>
13 */
14
5a0015d6 15#include <linux/errno.h>
d43c36dc 16#include <linux/sched.h>
5a0015d6 17#include <linux/time.h>
fcc8f0f8 18#include <linux/clocksource.h>
5a0015d6
CZ
19#include <linux/interrupt.h>
20#include <linux/module.h>
21#include <linux/init.h>
22#include <linux/irq.h>
23#include <linux/profile.h>
24#include <linux/delay.h>
2206d5dd 25#include <linux/irqdomain.h>
5a0015d6
CZ
26
27#include <asm/timex.h>
28#include <asm/platform.h>
29
5a0015d6 30#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
e504c4b6 31unsigned long ccount_freq; /* ccount Hz */
5a0015d6
CZ
32#endif
33
09378d7c 34static cycle_t ccount_read(struct clocksource *cs)
fcc8f0f8
JW
35{
36 return (cycle_t)get_ccount();
37}
38
39static struct clocksource ccount_clocksource = {
40 .name = "ccount",
41 .rating = 200,
42 .read = ccount_read,
43 .mask = CLOCKSOURCE_MASK(32),
fcc8f0f8
JW
44};
45
fd43fe19 46static irqreturn_t timer_interrupt(int irq, void *dev_id);
5a0015d6
CZ
47static struct irqaction timer_irqaction = {
48 .handler = timer_interrupt,
85ac3ab2 49 .flags = IRQF_DISABLED,
5a0015d6
CZ
50 .name = "timer",
51};
52
53void __init time_init(void)
54{
2206d5dd 55 unsigned int irq;
288a60cf 56#ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
5a0015d6
CZ
57 printk("Calibrating CPU frequency ");
58 platform_calibrate_ccount();
e504c4b6
BS
59 printk("%d.%02d MHz\n", (int)ccount_freq/1000000,
60 (int)(ccount_freq/10000)%100);
5a0015d6 61#endif
a139723b 62 clocksource_register_hz(&ccount_clocksource, CCOUNT_PER_JIFFY * HZ);
5a0015d6
CZ
63
64 /* Initialize the linux timer interrupt. */
65
2206d5dd
MF
66 irq = irq_create_mapping(NULL, LINUX_TIMER_INT);
67 setup_irq(irq, &timer_irqaction);
5a0015d6
CZ
68 set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY);
69}
70
5a0015d6
CZ
71/*
72 * The timer interrupt is called HZ times per second.
73 */
74
fd43fe19 75irqreturn_t timer_interrupt (int irq, void *dev_id)
5a0015d6
CZ
76{
77
78 unsigned long next;
79
80 next = get_linux_timer();
81
82again:
83 while ((signed long)(get_ccount() - next) > 0) {
84
fd43fe19 85 profile_tick(CPU_PROFILING);
5a0015d6 86#ifndef CONFIG_SMP
fd43fe19 87 update_process_times(user_mode(get_irq_regs()));
5a0015d6
CZ
88#endif
89
d12b0e24 90 xtime_update(1); /* Linux handler in kernel/time/timekeeping */
2b8aea74
CZ
91
92 /* Note that writing CCOMPARE clears the interrupt. */
93
5a0015d6 94 next += CCOUNT_PER_JIFFY;
2b8aea74 95 set_linux_timer(next);
5a0015d6
CZ
96 }
97
2b8aea74 98 /* Allow platform to do something useful (Wdog). */
5a0015d6 99
2b8aea74 100 platform_heartbeat();
5a0015d6
CZ
101
102 /* Make sure we didn't miss any tick... */
103
104 if ((signed long)(get_ccount() - next) > 0)
105 goto again;
106
5a0015d6
CZ
107 return IRQ_HANDLED;
108}
109
110#ifndef CONFIG_GENERIC_CALIBRATE_DELAY
6c81c32f 111void __cpuinit calibrate_delay(void)
5a0015d6
CZ
112{
113 loops_per_jiffy = CCOUNT_PER_JIFFY;
114 printk("Calibrating delay loop (skipped)... "
115 "%lu.%02lu BogoMIPS preset\n",
116 loops_per_jiffy/(1000000/HZ),
117 (loops_per_jiffy/(10000/HZ)) % 100);
118}
119#endif