aboutsummaryrefslogtreecommitdiffstats
path: root/arch/blackfin/kernel/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/blackfin/kernel/time.c')
-rw-r--r--arch/blackfin/kernel/time.c162
1 files changed, 91 insertions, 71 deletions
diff --git a/arch/blackfin/kernel/time.c b/arch/blackfin/kernel/time.c
index eb2352320454..172b4c588467 100644
--- a/arch/blackfin/kernel/time.c
+++ b/arch/blackfin/kernel/time.c
@@ -1,32 +1,11 @@
1/* 1/*
2 * File: arch/blackfin/kernel/time.c 2 * arch/blackfin/kernel/time.c
3 * Based on: none - original work
4 * Author:
5 * 3 *
6 * Created: 4 * This file contains the Blackfin-specific time handling details.
7 * Description: This file contains the bfin-specific time handling details. 5 * Most of the stuff is located in the machine specific files.
8 * Most of the stuff is located in the machine specific files.
9 * FIXME: (This file is subject for removal)
10 * 6 *
11 * Modified: 7 * Copyright 2004-2008 Analog Devices Inc.
12 * Copyright 2004-2008 Analog Devices Inc. 8 * Licensed under the GPL-2 or later.
13 *
14 * Bugs: Enter bugs at http://blackfin.uclinux.org/
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 2 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, see the file COPYING, or write
28 * to the Free Software Foundation, Inc.,
29 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30 */ 9 */
31 10
32#include <linux/module.h> 11#include <linux/module.h>
@@ -34,23 +13,43 @@
34#include <linux/interrupt.h> 13#include <linux/interrupt.h>
35#include <linux/time.h> 14#include <linux/time.h>
36#include <linux/irq.h> 15#include <linux/irq.h>
16#include <linux/delay.h>
37 17
38#include <asm/blackfin.h> 18#include <asm/blackfin.h>
39#include <asm/time.h> 19#include <asm/time.h>
20#include <asm/gptimers.h>
40 21
41/* This is an NTP setting */ 22/* This is an NTP setting */
42#define TICK_SIZE (tick_nsec / 1000) 23#define TICK_SIZE (tick_nsec / 1000)
43 24
44static void time_sched_init(irq_handler_t timer_routine);
45static unsigned long gettimeoffset(void);
46
47static struct irqaction bfin_timer_irq = { 25static struct irqaction bfin_timer_irq = {
48 .name = "BFIN Timer Tick", 26 .name = "Blackfin Timer Tick",
27#ifdef CONFIG_IRQ_PER_CPU
28 .flags = IRQF_DISABLED | IRQF_PERCPU,
29#else
49 .flags = IRQF_DISABLED 30 .flags = IRQF_DISABLED
31#endif
50}; 32};
51 33
52static void 34#if defined(CONFIG_TICK_SOURCE_SYSTMR0) || defined(CONFIG_IPIPE)
53time_sched_init(irq_handler_t timer_routine) 35void __init setup_system_timer0(void)
36{
37 /* Power down the core timer, just to play safe. */
38 bfin_write_TCNTL(0);
39
40 disable_gptimers(TIMER0bit);
41 set_gptimer_status(0, TIMER_STATUS_TRUN0);
42 while (get_gptimer_status(0) & TIMER_STATUS_TRUN0)
43 udelay(10);
44
45 set_gptimer_config(0, 0x59); /* IRQ enable, periodic, PWM_OUT, SCLKed, OUT PAD disabled */
46 set_gptimer_period(TIMER0_id, get_sclk() / HZ);
47 set_gptimer_pwidth(TIMER0_id, 1);
48 SSYNC();
49 enable_gptimers(TIMER0bit);
50}
51#else
52void __init setup_core_timer(void)
54{ 53{
55 u32 tcount; 54 u32 tcount;
56 55
@@ -58,10 +57,8 @@ time_sched_init(irq_handler_t timer_routine)
58 bfin_write_TCNTL(1); 57 bfin_write_TCNTL(1);
59 CSYNC(); 58 CSYNC();
60 59
61 /* 60 /* the TSCALE prescaler counter */
62 * the TSCALE prescaler counter. 61 bfin_write_TSCALE(TIME_SCALE - 1);
63 */
64 bfin_write_TSCALE((TIME_SCALE - 1));
65 62
66 tcount = ((get_cclk() / (HZ * TIME_SCALE)) - 1); 63 tcount = ((get_cclk() / (HZ * TIME_SCALE)) - 1);
67 bfin_write_TPERIOD(tcount); 64 bfin_write_TPERIOD(tcount);
@@ -71,35 +68,52 @@ time_sched_init(irq_handler_t timer_routine)
71 CSYNC(); 68 CSYNC();
72 69
73 bfin_write_TCNTL(7); 70 bfin_write_TCNTL(7);
71}
72#endif
74 73
75 bfin_timer_irq.handler = (irq_handler_t)timer_routine; 74static void __init
76 /* call setup_irq instead of request_irq because request_irq calls 75time_sched_init(irqreturn_t(*timer_routine) (int, void *))
77 * kmalloc which has not been initialized yet 76{
78 */ 77#if defined(CONFIG_TICK_SOURCE_SYSTMR0) || defined(CONFIG_IPIPE)
78 setup_system_timer0();
79 bfin_timer_irq.handler = timer_routine;
80 setup_irq(IRQ_TIMER0, &bfin_timer_irq);
81#else
82 setup_core_timer();
83 bfin_timer_irq.handler = timer_routine;
79 setup_irq(IRQ_CORETMR, &bfin_timer_irq); 84 setup_irq(IRQ_CORETMR, &bfin_timer_irq);
85#endif
80} 86}
81 87
82/* 88/*
83 * Should return useconds since last timer tick 89 * Should return useconds since last timer tick
84 */ 90 */
91#ifndef CONFIG_GENERIC_TIME
85static unsigned long gettimeoffset(void) 92static unsigned long gettimeoffset(void)
86{ 93{
87 unsigned long offset; 94 unsigned long offset;
88 unsigned long clocks_per_jiffy; 95 unsigned long clocks_per_jiffy;
89 96
97#if defined(CONFIG_TICK_SOURCE_SYSTMR0) || defined(CONFIG_IPIPE)
98 clocks_per_jiffy = bfin_read_TIMER0_PERIOD();
99 offset = bfin_read_TIMER0_COUNTER() / \
100 (((clocks_per_jiffy + 1) * HZ) / USEC_PER_SEC);
101
102 if ((get_gptimer_status(0) & TIMER_STATUS_TIMIL0) && offset < (100000 / HZ / 2))
103 offset += (USEC_PER_SEC / HZ);
104#else
90 clocks_per_jiffy = bfin_read_TPERIOD(); 105 clocks_per_jiffy = bfin_read_TPERIOD();
91 offset = 106 offset = (clocks_per_jiffy - bfin_read_TCOUNT()) / \
92 (clocks_per_jiffy - 107 (((clocks_per_jiffy + 1) * HZ) / USEC_PER_SEC);
93 bfin_read_TCOUNT()) / (((clocks_per_jiffy + 1) * HZ) /
94 USEC_PER_SEC);
95 108
96 /* Check if we just wrapped the counters and maybe missed a tick */ 109 /* Check if we just wrapped the counters and maybe missed a tick */
97 if ((bfin_read_ILAT() & (1 << IRQ_CORETMR)) 110 if ((bfin_read_ILAT() & (1 << IRQ_CORETMR))
98 && (offset < (100000 / HZ / 2))) 111 && (offset < (100000 / HZ / 2)))
99 offset += (USEC_PER_SEC / HZ); 112 offset += (USEC_PER_SEC / HZ);
100 113#endif
101 return offset; 114 return offset;
102} 115}
116#endif
103 117
104static inline int set_rtc_mmss(unsigned long nowtime) 118static inline int set_rtc_mmss(unsigned long nowtime)
105{ 119{
@@ -111,43 +125,49 @@ static inline int set_rtc_mmss(unsigned long nowtime)
111 * as well as call the "do_timer()" routine every clocktick 125 * as well as call the "do_timer()" routine every clocktick
112 */ 126 */
113#ifdef CONFIG_CORE_TIMER_IRQ_L1 127#ifdef CONFIG_CORE_TIMER_IRQ_L1
114irqreturn_t timer_interrupt(int irq, void *dummy)__attribute__((l1_text)); 128__attribute__((l1_text))
115#endif 129#endif
116
117irqreturn_t timer_interrupt(int irq, void *dummy) 130irqreturn_t timer_interrupt(int irq, void *dummy)
118{ 131{
119 /* last time the cmos clock got updated */ 132 /* last time the cmos clock got updated */
120 static long last_rtc_update; 133 static long last_rtc_update;
121 134
122 write_seqlock(&xtime_lock); 135 write_seqlock(&xtime_lock);
123 136#if defined(CONFIG_TICK_SOURCE_SYSTMR0) && !defined(CONFIG_IPIPE)
124 do_timer(1); 137/* FIXME: Here TIMIL0 is not set when IPIPE enabled, why? */
125 138 if (get_gptimer_status(0) & TIMER_STATUS_TIMIL0) {
126 profile_tick(CPU_PROFILING); 139#endif
127 140 do_timer(1);
128 /* 141
129 * If we have an externally synchronized Linux clock, then update 142 /*
130 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be 143 * If we have an externally synchronized Linux clock, then update
131 * called as close as possible to 500 ms before the new second starts. 144 * CMOS clock accordingly every ~11 minutes. Set_rtc_mmss() has to be
132 */ 145 * called as close as possible to 500 ms before the new second starts.
133 146 */
134 if (ntp_synced() && 147 if (ntp_synced() &&
135 xtime.tv_sec > last_rtc_update + 660 && 148 xtime.tv_sec > last_rtc_update + 660 &&
136 (xtime.tv_nsec / NSEC_PER_USEC) >= 149 (xtime.tv_nsec / NSEC_PER_USEC) >=
137 500000 - ((unsigned)TICK_SIZE) / 2 150 500000 - ((unsigned)TICK_SIZE) / 2
138 && (xtime.tv_nsec / NSEC_PER_USEC) <= 151 && (xtime.tv_nsec / NSEC_PER_USEC) <=
139 500000 + ((unsigned)TICK_SIZE) / 2) { 152 500000 + ((unsigned)TICK_SIZE) / 2) {
140 if (set_rtc_mmss(xtime.tv_sec) == 0) 153 if (set_rtc_mmss(xtime.tv_sec) == 0)
141 last_rtc_update = xtime.tv_sec; 154 last_rtc_update = xtime.tv_sec;
142 else 155 else
143 /* Do it again in 60s. */ 156 /* Do it again in 60s. */
144 last_rtc_update = xtime.tv_sec - 600; 157 last_rtc_update = xtime.tv_sec - 600;
158 }
159#if defined(CONFIG_TICK_SOURCE_SYSTMR0) && !defined(CONFIG_IPIPE)
160 set_gptimer_status(0, TIMER_STATUS_TIMIL0);
145 } 161 }
162#endif
146 write_sequnlock(&xtime_lock); 163 write_sequnlock(&xtime_lock);
147 164
148#ifndef CONFIG_SMP 165#ifdef CONFIG_IPIPE
166 update_root_process_times(get_irq_regs());
167#else
149 update_process_times(user_mode(get_irq_regs())); 168 update_process_times(user_mode(get_irq_regs()));
150#endif 169#endif
170 profile_tick(CPU_PROFILING);
151 171
152 return IRQ_HANDLED; 172 return IRQ_HANDLED;
153} 173}