2 * Copyright (C) 2000 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
3 * Licensed under the GPL
6 #include <linux/clockchips.h>
7 #include <linux/init.h>
8 #include <linux/interrupt.h>
9 #include <linux/jiffies.h>
10 #include <linux/threads.h>
12 #include <asm/param.h>
13 #include "kern_util.h"
16 void timer_handler(int sig
, struct uml_pt_regs
*regs
)
20 local_irq_save(flags
);
21 do_IRQ(TIMER_IRQ
, regs
);
22 local_irq_restore(flags
);
25 static void itimer_set_mode(enum clock_event_mode mode
,
26 struct clock_event_device
*evt
)
29 case CLOCK_EVT_MODE_PERIODIC
:
33 case CLOCK_EVT_MODE_SHUTDOWN
:
34 case CLOCK_EVT_MODE_UNUSED
:
35 case CLOCK_EVT_MODE_ONESHOT
:
39 case CLOCK_EVT_MODE_RESUME
:
44 static int itimer_next_event(unsigned long delta
,
45 struct clock_event_device
*evt
)
47 return timer_one_shot(delta
+ 1);
50 static struct clock_event_device itimer_clockevent
= {
53 .cpumask
= cpu_all_mask
,
54 .features
= CLOCK_EVT_FEAT_PERIODIC
| CLOCK_EVT_FEAT_ONESHOT
,
55 .set_mode
= itimer_set_mode
,
56 .set_next_event
= itimer_next_event
,
61 static irqreturn_t
um_timer(int irq
, void *dev
)
63 (*itimer_clockevent
.event_handler
)(&itimer_clockevent
);
68 static cycle_t
itimer_read(struct clocksource
*cs
)
70 return os_nsecs() / 1000;
73 static struct clocksource itimer_clocksource
= {
77 .mask
= CLOCKSOURCE_MASK(64),
78 .flags
= CLOCK_SOURCE_IS_CONTINUOUS
,
81 static void __init
setup_itimer(void)
85 err
= request_irq(TIMER_IRQ
, um_timer
, IRQF_DISABLED
, "timer", NULL
);
87 printk(KERN_ERR
"register_timer : request_irq failed - "
88 "errno = %d\n", -err
);
90 itimer_clockevent
.mult
= div_sc(HZ
, NSEC_PER_SEC
, 32);
91 itimer_clockevent
.max_delta_ns
=
92 clockevent_delta2ns(60 * HZ
, &itimer_clockevent
);
93 itimer_clockevent
.min_delta_ns
=
94 clockevent_delta2ns(1, &itimer_clockevent
);
95 err
= clocksource_register_hz(&itimer_clocksource
, USEC_PER_SEC
);
97 printk(KERN_ERR
"clocksource_register_hz returned %d\n", err
);
100 clockevents_register_device(&itimer_clockevent
);
103 void read_persistent_clock(struct timespec
*ts
)
105 long long nsecs
= os_nsecs();
107 set_normalized_timespec(ts
, nsecs
/ NSEC_PER_SEC
,
108 nsecs
% NSEC_PER_SEC
);
111 void __init
time_init(void)
114 late_time_init
= setup_itimer
;