Import 2.3.9pre5
[davej-history.git] / arch / mips / baget / time.c
blob093b6c0ac26d7c1bd2bb76f41c5e9a847707e47e
1 /* $Id$
2 * time.c: Baget/MIPS specific time handling details
4 * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
5 */
7 #include <linux/errno.h>
8 #include <linux/init.h>
9 #include <linux/sched.h>
10 #include <linux/kernel.h>
11 #include <linux/param.h>
12 #include <linux/string.h>
13 #include <linux/mm.h>
14 #include <linux/interrupt.h>
15 #include <linux/timex.h>
16 #include <linux/kernel_stat.h>
18 #include <asm/bootinfo.h>
19 #include <asm/io.h>
20 #include <asm/irq.h>
21 #include <asm/ptrace.h>
22 #include <asm/system.h>
24 #include <asm/baget/baget.h>
26 /*
27 * To have precision clock, we need to fix available clock frequency
29 #define FREQ_NOM 79125 /* Baget frequency ratio */
30 #define FREQ_DEN 10000
31 static inline int timer_intr_valid(void)
33 static unsigned long long ticks, valid_ticks;
35 if (ticks++ * FREQ_DEN >= valid_ticks * FREQ_NOM) {
36 /*
37 * We need no overflow checks,
38 * due baget unable to work 3000 years...
39 * At least without reboot...
41 valid_ticks++;
42 return 1;
44 return 0;
47 void static timer_interrupt(int irq, void *dev_id, struct pt_regs * regs)
49 if (timer_intr_valid()) {
50 sti();
51 do_timer(regs);
55 __initfunc(static void timer_enable(void))
57 unsigned char ss0cr0 = vic_inb(VIC_SS0CR0);
58 ss0cr0 &= ~VIC_SS0CR0_TIMER_FREQ_MASK;
59 ss0cr0 |= VIC_SS0CR0_TIMER_FREQ_1000HZ;
60 vic_outb(ss0cr0, VIC_SS0CR0);
62 vic_outb(VIC_INT_IPL(6)|VIC_INT_NOAUTO|VIC_INT_EDGE|
63 VIC_INT_LOW|VIC_INT_ENABLE, VIC_LINT2);
66 __initfunc(void time_init(void))
68 if (request_irq(BAGET_VIC_TIMER_IRQ, timer_interrupt,
69 SA_INTERRUPT|SA_STATIC_ALLOC, "timer", NULL) < 0)
70 printk("time_init: unable request irq for system timer\n");
72 timer_enable();
74 /* We don't call sti() here, because it is too early for baget */
77 void do_gettimeofday(struct timeval *tv)
79 unsigned long flags;
81 save_and_cli(flags);
82 *tv = xtime;
83 restore_flags(flags);
86 void do_settimeofday(struct timeval *tv)
88 unsigned long flags;
90 save_and_cli(flags);
91 xtime = *tv;
92 time_state = TIME_BAD;
93 time_maxerror = MAXPHASE;
94 time_esterror = MAXPHASE;
95 restore_flags(flags);