Ok. I didn't make 2.4.0 in 2000. Tough. I tried, but we had some
[davej-history.git] / arch / mips / baget / time.c
blobd56fa6a23a9bdd5306147a7f94a256aab41b89d9
1 /* $Id: time.c,v 1.3 1999/08/17 22:18:37 ralf Exp $
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 static void __init 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 static struct irqaction timer_irq =
67 { timer_interrupt, SA_INTERRUPT, 0, "timer", NULL, NULL};
69 void __init time_init(void)
71 if (setup_baget_irq(BAGET_VIC_TIMER_IRQ, &timer_irq) < 0)
72 printk("time_init: unable request irq for system timer\n");
73 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);