1
2
3
4
5
6
7
8
9
10
11
12
13#include <linux/module.h>
14#include <linux/errno.h>
15#include <linux/sched.h>
16#include <linux/kernel.h>
17#include <linux/param.h>
18#include <linux/string.h>
19#include <linux/interrupt.h>
20#include <linux/profile.h>
21#include <linux/irq.h>
22#include <linux/mm.h>
23
24#include <asm/io.h>
25#include <asm/timer-regs.h>
26#include <asm/mb-regs.h>
27#include <asm/mb86943a.h>
28
29#include <linux/timex.h>
30
31#define TICK_SIZE (tick_nsec / 1000)
32
33unsigned long __nongprelbss __clkin_clock_speed_HZ;
34unsigned long __nongprelbss __ext_bus_clock_speed_HZ;
35unsigned long __nongprelbss __res_bus_clock_speed_HZ;
36unsigned long __nongprelbss __sdram_clock_speed_HZ;
37unsigned long __nongprelbss __core_bus_clock_speed_HZ;
38unsigned long __nongprelbss __core_clock_speed_HZ;
39unsigned long __nongprelbss __dsu_clock_speed_HZ;
40unsigned long __nongprelbss __serial_clock_speed_HZ;
41unsigned long __delay_loops_MHz;
42
43static irqreturn_t timer_interrupt(int irq, void *dummy);
44
45static struct irqaction timer_irq = {
46 .handler = timer_interrupt,
47 .flags = IRQF_DISABLED,
48 .name = "timer",
49};
50
51
52
53
54
55static irqreturn_t timer_interrupt(int irq, void *dummy)
56{
57 profile_tick(CPU_PROFILING);
58
59 xtime_update(1);
60
61#ifdef CONFIG_HEARTBEAT
62 static unsigned short n;
63 n++;
64 __set_LEDS(n);
65#endif
66
67 update_process_times(user_mode(get_irq_regs()));
68
69 return IRQ_HANDLED;
70}
71
72void time_divisor_init(void)
73{
74 unsigned short base, pre, prediv;
75
76
77 pre = 1;
78 prediv = 4;
79 base = __res_bus_clock_speed_HZ / pre / HZ / (1 << prediv);
80
81 __set_TPRV(pre);
82 __set_TxCKSL_DATA(0, prediv);
83 __set_TCTR(TCTR_SC_CTR0 | TCTR_RL_RW_LH8 | TCTR_MODE_2);
84 __set_TCSR_DATA(0, base & 0xff);
85 __set_TCSR_DATA(0, base >> 8);
86}
87
88
89void read_persistent_clock(struct timespec *ts)
90{
91 unsigned int year, mon, day, hour, min, sec;
92
93 extern void arch_gettod(int *year, int *mon, int *day, int *hour, int *min, int *sec);
94
95
96
97
98 year = 1980;
99 mon = day = 1;
100 hour = min = sec = 0;
101 arch_gettod (&year, &mon, &day, &hour, &min, &sec);
102
103 if ((year += 1900) < 1970)
104 year += 100;
105 ts->tv_sec = mktime(year, mon, day, hour, min, sec);
106 ts->tv_nsec = 0;
107}
108
109void time_init(void)
110{
111
112 setup_irq(IRQ_CPU_TIMER0, &timer_irq);
113
114 time_divisor_init();
115}
116
117
118
119
120unsigned long long sched_clock(void)
121{
122 return jiffies_64 * (1000000000 / HZ);
123}
124