spi-topcliff-pch: Fix issue for transmitting over 4KByte
[zen-stable.git] / arch / xtensa / kernel / time.c
blobac62f9cf1e100518ce719d10beb7110385b149ba
1 /*
2 * arch/xtensa/kernel/time.c
4 * Timer and clock support.
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.
10 * Copyright (C) 2005 Tensilica Inc.
12 * Chris Zankel <chris@zankel.net>
15 #include <linux/errno.h>
16 #include <linux/sched.h>
17 #include <linux/time.h>
18 #include <linux/clocksource.h>
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>
26 #include <asm/timex.h>
27 #include <asm/platform.h>
29 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
30 unsigned long ccount_per_jiffy; /* per 1/HZ */
31 unsigned long nsec_per_ccount; /* nsec per ccount increment */
32 #endif
34 static cycle_t ccount_read(void)
36 return (cycle_t)get_ccount();
39 static struct clocksource ccount_clocksource = {
40 .name = "ccount",
41 .rating = 200,
42 .read = ccount_read,
43 .mask = CLOCKSOURCE_MASK(32),
46 static irqreturn_t timer_interrupt(int irq, void *dev_id);
47 static struct irqaction timer_irqaction = {
48 .handler = timer_interrupt,
49 .flags = IRQF_DISABLED,
50 .name = "timer",
53 void __init time_init(void)
55 #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT
56 printk("Calibrating CPU frequency ");
57 platform_calibrate_ccount();
58 printk("%d.%02d MHz\n", (int)ccount_per_jiffy/(1000000/HZ),
59 (int)(ccount_per_jiffy/(10000/HZ))%100);
60 #endif
61 clocksource_register_hz(&ccount_clocksource, CCOUNT_PER_JIFFY * HZ);
63 /* Initialize the linux timer interrupt. */
65 setup_irq(LINUX_TIMER_INT, &timer_irqaction);
66 set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY);
70 * The timer interrupt is called HZ times per second.
73 irqreturn_t timer_interrupt (int irq, void *dev_id)
76 unsigned long next;
78 next = get_linux_timer();
80 again:
81 while ((signed long)(get_ccount() - next) > 0) {
83 profile_tick(CPU_PROFILING);
84 #ifndef CONFIG_SMP
85 update_process_times(user_mode(get_irq_regs()));
86 #endif
88 xtime_update(1); /* Linux handler in kernel/time/timekeeping */
90 /* Note that writing CCOMPARE clears the interrupt. */
92 next += CCOUNT_PER_JIFFY;
93 set_linux_timer(next);
96 /* Allow platform to do something useful (Wdog). */
98 platform_heartbeat();
100 /* Make sure we didn't miss any tick... */
102 if ((signed long)(get_ccount() - next) > 0)
103 goto again;
105 return IRQ_HANDLED;
108 #ifndef CONFIG_GENERIC_CALIBRATE_DELAY
109 void __cpuinit calibrate_delay(void)
111 loops_per_jiffy = CCOUNT_PER_JIFFY;
112 printk("Calibrating delay loop (skipped)... "
113 "%lu.%02lu BogoMIPS preset\n",
114 loops_per_jiffy/(1000000/HZ),
115 (loops_per_jiffy/(10000/HZ)) % 100);
117 #endif