2 * time.c: Baget/MIPS specific time handling details
4 * Copyright (C) 1998 Gleb Raiko & Vladimir Roganov
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>
14 #include <linux/interrupt.h>
15 #include <linux/timex.h>
16 #include <linux/kernel_stat.h>
18 #include <asm/bootinfo.h>
21 #include <asm/ptrace.h>
22 #include <asm/system.h>
24 #include <asm/baget/baget.h>
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
) {
37 * We need no overflow checks,
38 * due baget unable to work 3000 years...
39 * At least without reboot...
47 void static timer_interrupt(int irq
, void *dev_id
, struct pt_regs
* regs
)
49 if (timer_intr_valid()) {
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");
74 /* We don't call sti() here, because it is too early for baget */
77 void do_gettimeofday(struct timeval
*tv
)
86 void do_settimeofday(struct timeval
*tv
)
92 time_state
= TIME_BAD
;
93 time_maxerror
= MAXPHASE
;
94 time_esterror
= MAXPHASE
;