14 #include <linux/string.h>
19 static volatile int initialized, opened, tmr_running;
20 static volatile time_t tmr_offs, tmr_ctr;
21 static volatile unsigned long ticks_offs;
22 static volatile int curr_tempo, curr_timebase;
23 static volatile unsigned long curr_ticks;
24 static volatile unsigned long next_event_time;
25 static unsigned long prev_event_time;
26 static volatile unsigned long usecs_per_tmr;
31 static unsigned long tmr2ticks(
int tmr_value)
40 tmp = tmr_value * usecs_per_tmr;
41 scale = (60 * 1000000) / (curr_tempo * curr_timebase);
42 return (tmp + (scale / 2)) / scale;
47 unsigned long usecs_per_tick;
57 usecs_per_tick = (60 * 1000000) / (curr_tempo * curr_timebase);
62 if (usecs_per_tick < 2000)
63 usecs_per_tick = 2000;
65 usecs_per_tmr = tmr->
tmr_start(tmr->
dev, usecs_per_tick);
75 ticks_offs += tmr2ticks(tmr_ctr);
77 usecs_per_tmr = new_usecs;
81 static void tmr_reset(
void)
89 next_event_time = (
unsigned long) -1;
92 spin_unlock_irqrestore(&lock,flags);
95 static int timer_open(
int dev,
int mode)
107 static void timer_close(
int dev)
109 opened = tmr_running = 0;
115 unsigned char cmd =
event[1];
116 unsigned long parm = *(
int *) &event[4];
121 parm += prev_event_time;
127 if (parm <= curr_ticks)
130 next_event_time = prev_event_time =
time;
158 ticks_offs += tmr2ticks(tmr_ctr);
174 static unsigned long timer_get_time(
int dev)
181 static int timer_ioctl(
int dev,
unsigned int cmd,
void __user *
arg)
229 ticks_offs += tmr2ticks(tmr_ctr);
242 val = ((curr_tempo * curr_timebase) + 30) / 60;
256 static void timer_arm(
int dev,
long time)
259 time = curr_ticks + 1;
260 else if (time <= curr_ticks)
263 next_event_time = prev_event_time =
time;
270 .info = {
"Sound Timer", 0},
274 .close = timer_close,
276 .get_time = timer_get_time,
277 .ioctl = timer_ioctl,
278 .arm_timer = timer_arm
295 curr_ticks = ticks_offs + tmr2ticks(tmr_ctr);
297 if (curr_ticks >= next_event_time)
299 next_event_time = (
unsigned long) -1;
302 spin_unlock_irqrestore(&
lock,flags);