source: GPL/branches/uniaud-2.0/alsa-kernel/core/timer.c@ 319

Last change on this file since 319 was 319, checked in by Paul Smedley, 17 years ago

Cleanups + reinstante bt87x support

File size: 53.9 KB
Line 
1/*
2 * Timers abstract layer
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22#include <linux/delay.h>
23#include <linux/init.h>
24#include <linux/slab.h>
25#include <linux/time.h>
26#include <linux/mutex.h>
27#include <linux/moduleparam.h>
28#include <linux/string.h>
29#include <sound/core.h>
30#include <sound/timer.h>
31#include <sound/control.h>
32#include <sound/info.h>
33#include <sound/minors.h>
34#include <sound/initval.h>
35#include <linux/kmod.h>
36
37#if defined(CONFIG_SND_HPET) || defined(CONFIG_SND_HPET_MODULE)
38#define DEFAULT_TIMER_LIMIT 3
39#elif defined(CONFIG_SND_RTCTIMER) || defined(CONFIG_SND_RTCTIMER_MODULE)
40#define DEFAULT_TIMER_LIMIT 2
41#else
42#define DEFAULT_TIMER_LIMIT 1
43#endif
44
45static int timer_limit = DEFAULT_TIMER_LIMIT;
46static int timer_tstamp_monotonic = 1;
47MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>, Takashi Iwai <tiwai@suse.de>");
48MODULE_DESCRIPTION("ALSA timer interface");
49MODULE_LICENSE("GPL");
50module_param(timer_limit, int, 0444);
51MODULE_PARM_DESC(timer_limit, "Maximum global timers in system.");
52module_param(timer_tstamp_monotonic, int, 0444);
53MODULE_PARM_DESC(timer_tstamp_monotonic, "Use posix monotonic clock source for timestamps (default).");
54
55struct snd_timer_user {
56 struct snd_timer_instance *timeri;
57 int tread; /* enhanced read with timestamps and events */
58 unsigned long ticks;
59 unsigned long overrun;
60 int qhead;
61 int qtail;
62 int qused;
63 int queue_size;
64 struct snd_timer_read *queue;
65 struct snd_timer_tread *tqueue;
66 spinlock_t qlock;
67 unsigned long last_resolution;
68 unsigned int filter;
69 struct timespec tstamp; /* trigger tstamp */
70 wait_queue_head_t qchange_sleep;
71 struct fasync_struct *fasync;
72 struct mutex tread_sem;
73};
74
75/* list of timers */
76static LIST_HEAD(snd_timer_list);
77
78/* list of slave instances */
79static LIST_HEAD(snd_timer_slave_list);
80
81/* lock for slave active lists */
82#ifndef TARGET_OS2
83static DEFINE_SPINLOCK(slave_active_lock);
84#else
85static spinlock_t slave_active_lock = SPIN_LOCK_UNLOCKED;
86#endif
87
88static DEFINE_MUTEX(register_mutex);
89
90static int snd_timer_free(struct snd_timer *timer);
91static int snd_timer_dev_free(struct snd_device *device);
92static int snd_timer_dev_register(struct snd_device *device);
93static int snd_timer_dev_disconnect(struct snd_device *device);
94
95static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left);
96
97/*
98 * create a timer instance with the given owner string.
99 * when timer is not NULL, increments the module counter
100 */
101static struct snd_timer_instance *snd_timer_instance_new(char *owner,
102 struct snd_timer *timer)
103{
104 struct snd_timer_instance *timeri;
105 timeri = kzalloc(sizeof(*timeri), GFP_KERNEL);
106 if (timeri == NULL)
107 return NULL;
108 timeri->owner = kstrdup(owner, GFP_KERNEL);
109 if (! timeri->owner) {
110 kfree(timeri);
111 return NULL;
112 }
113 INIT_LIST_HEAD(&timeri->open_list);
114 INIT_LIST_HEAD(&timeri->active_list);
115 INIT_LIST_HEAD(&timeri->ack_list);
116 INIT_LIST_HEAD(&timeri->slave_list_head);
117 INIT_LIST_HEAD(&timeri->slave_active_head);
118
119 timeri->timer = timer;
120 if (timer && !try_module_get(timer->module)) {
121 kfree(timeri->owner);
122 kfree(timeri);
123 return NULL;
124 }
125
126 return timeri;
127}
128
129/*
130 * find a timer instance from the given timer id
131 */
132static struct snd_timer *snd_timer_find(struct snd_timer_id *tid)
133{
134 struct snd_timer *timer = NULL;
135
136 list_for_each_entry(timer, &snd_timer_list, device_list, struct snd_timer) {
137 if (timer->tmr_class != tid->dev_class)
138 continue;
139 if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD ||
140 timer->tmr_class == SNDRV_TIMER_CLASS_PCM) &&
141 (timer->card == NULL ||
142 timer->card->number != tid->card))
143 continue;
144 if (timer->tmr_device != tid->device)
145 continue;
146 if (timer->tmr_subdevice != tid->subdevice)
147 continue;
148 return timer;
149 }
150 return NULL;
151}
152
153#ifdef CONFIG_KMOD
154
155static void snd_timer_request(struct snd_timer_id *tid)
156{
157 if (! current->fs->root)
158 return;
159 switch (tid->dev_class) {
160 case SNDRV_TIMER_CLASS_GLOBAL:
161 if (tid->device < timer_limit)
162 request_module("snd-timer-%i", tid->device);
163 break;
164 case SNDRV_TIMER_CLASS_CARD:
165 case SNDRV_TIMER_CLASS_PCM:
166 if (tid->card < snd_ecards_limit)
167 request_module("snd-card-%i", tid->card);
168 break;
169 default:
170 break;
171 }
172}
173
174#endif
175
176/*
177 * look for a master instance matching with the slave id of the given slave.
178 * when found, relink the open_link of the slave.
179 *
180 * call this with register_mutex down.
181 */
182static void snd_timer_check_slave(struct snd_timer_instance *slave)
183{
184 struct snd_timer *timer;
185 struct snd_timer_instance *master;
186
187 /* FIXME: it's really dumb to look up all entries.. */
188 list_for_each_entry(timer, &snd_timer_list, device_list, struct snd_timer) {
189 list_for_each_entry(master, &timer->open_list_head, open_list, struct snd_timer_instance) {
190 if (slave->slave_class == master->slave_class &&
191 slave->slave_id == master->slave_id) {
192 list_del(&slave->open_list);
193 list_add_tail(&slave->open_list,
194 &master->slave_list_head);
195 spin_lock_irq(&slave_active_lock);
196 slave->master = master;
197 slave->timer = master->timer;
198 spin_unlock_irq(&slave_active_lock);
199 return;
200 }
201 }
202 }
203}
204
205/*
206 * look for slave instances matching with the slave id of the given master.
207 * when found, relink the open_link of slaves.
208 *
209 * call this with register_mutex down.
210 */
211static void snd_timer_check_master(struct snd_timer_instance *master)
212{
213 struct snd_timer_instance *slave, *tmp;
214
215 /* check all pending slaves */
216 list_for_each_entry_safe(slave, tmp, &snd_timer_slave_list, open_list, struct snd_timer_instance) {
217 if (slave->slave_class == master->slave_class &&
218 slave->slave_id == master->slave_id) {
219 list_move_tail(&slave->open_list, &master->slave_list_head);
220 spin_lock_irq(&slave_active_lock);
221 slave->master = master;
222 slave->timer = master->timer;
223 if (slave->flags & SNDRV_TIMER_IFLG_RUNNING)
224 list_add_tail(&slave->active_list,
225 &master->slave_active_head);
226 spin_unlock_irq(&slave_active_lock);
227 }
228 }
229}
230
231/*
232 * open a timer instance
233 * when opening a master, the slave id must be here given.
234 */
235int snd_timer_open(struct snd_timer_instance **ti,
236 char *owner, struct snd_timer_id *tid,
237 unsigned int slave_id)
238{
239 struct snd_timer *timer;
240 struct snd_timer_instance *timeri = NULL;
241
242 if (tid->dev_class == SNDRV_TIMER_CLASS_SLAVE) {
243 /* open a slave instance */
244 if (tid->dev_sclass <= SNDRV_TIMER_SCLASS_NONE ||
245 tid->dev_sclass > SNDRV_TIMER_SCLASS_OSS_SEQUENCER) {
246 snd_printd("invalid slave class %i\n", tid->dev_sclass);
247 return -EINVAL;
248 }
249 mutex_lock(&register_mutex);
250 timeri = snd_timer_instance_new(owner, NULL);
251 if (!timeri) {
252 mutex_unlock(&register_mutex);
253 return -ENOMEM;
254 }
255 timeri->slave_class = tid->dev_sclass;
256 timeri->slave_id = tid->device;
257 timeri->flags |= SNDRV_TIMER_IFLG_SLAVE;
258 list_add_tail(&timeri->open_list, &snd_timer_slave_list);
259 snd_timer_check_slave(timeri);
260 mutex_unlock(&register_mutex);
261 *ti = timeri;
262 return 0;
263 }
264
265 /* open a master instance */
266 mutex_lock(&register_mutex);
267 timer = snd_timer_find(tid);
268#ifdef CONFIG_KMOD
269 if (timer == NULL) {
270 mutex_unlock(&register_mutex);
271 snd_timer_request(tid);
272 mutex_lock(&register_mutex);
273 timer = snd_timer_find(tid);
274 }
275#endif
276 if (!timer) {
277 mutex_unlock(&register_mutex);
278 return -ENODEV;
279 }
280 if (!list_empty(&timer->open_list_head)) {
281 timeri = list_entry(timer->open_list_head.next,
282 struct snd_timer_instance, open_list);
283 if (timeri->flags & SNDRV_TIMER_IFLG_EXCLUSIVE) {
284 mutex_unlock(&register_mutex);
285 return -EBUSY;
286 }
287 }
288 timeri = snd_timer_instance_new(owner, timer);
289 if (!timeri) {
290 mutex_unlock(&register_mutex);
291 return -ENOMEM;
292 }
293 timeri->slave_class = tid->dev_sclass;
294 timeri->slave_id = slave_id;
295 if (list_empty(&timer->open_list_head) && timer->hw.open)
296 timer->hw.open(timer);
297 list_add_tail(&timeri->open_list, &timer->open_list_head);
298 snd_timer_check_master(timeri);
299 mutex_unlock(&register_mutex);
300 *ti = timeri;
301 return 0;
302}
303
304static int _snd_timer_stop(struct snd_timer_instance *timeri,
305 int keep_flag, int event);
306
307/*
308 * close a timer instance
309 */
310int snd_timer_close(struct snd_timer_instance *timeri)
311{
312 struct snd_timer *timer = NULL;
313 struct snd_timer_instance *slave, *tmp;
314
315 snd_assert(timeri != NULL, return -ENXIO);
316
317 /* force to stop the timer */
318 snd_timer_stop(timeri);
319
320 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
321 /* wait, until the active callback is finished */
322 spin_lock_irq(&slave_active_lock);
323 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
324 spin_unlock_irq(&slave_active_lock);
325 udelay(10);
326 spin_lock_irq(&slave_active_lock);
327 }
328 spin_unlock_irq(&slave_active_lock);
329 mutex_lock(&register_mutex);
330 list_del(&timeri->open_list);
331 mutex_unlock(&register_mutex);
332 } else {
333 timer = timeri->timer;
334 /* wait, until the active callback is finished */
335 spin_lock_irq(&timer->lock);
336 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
337 spin_unlock_irq(&timer->lock);
338 udelay(10);
339 spin_lock_irq(&timer->lock);
340 }
341 spin_unlock_irq(&timer->lock);
342 mutex_lock(&register_mutex);
343 list_del(&timeri->open_list);
344 if (timer && list_empty(&timer->open_list_head) &&
345 timer->hw.close)
346 timer->hw.close(timer);
347 /* remove slave links */
348 list_for_each_entry_safe(slave, tmp, &timeri->slave_list_head,
349 open_list, struct snd_timer_instance) {
350 spin_lock_irq(&slave_active_lock);
351 _snd_timer_stop(slave, 1, SNDRV_TIMER_EVENT_RESOLUTION);
352 list_move_tail(&slave->open_list, &snd_timer_slave_list);
353 slave->master = NULL;
354 slave->timer = NULL;
355 spin_unlock_irq(&slave_active_lock);
356 }
357 mutex_unlock(&register_mutex);
358 }
359 if (timeri->private_free)
360 timeri->private_free(timeri);
361 kfree(timeri->owner);
362 kfree(timeri);
363 if (timer)
364 module_put(timer->module);
365 return 0;
366}
367
368unsigned long snd_timer_resolution(struct snd_timer_instance *timeri)
369{
370 struct snd_timer * timer;
371
372 if (timeri == NULL)
373 return 0;
374 if ((timer = timeri->timer) != NULL) {
375 if (timer->hw.c_resolution)
376 return timer->hw.c_resolution(timer);
377 return timer->hw.resolution;
378 }
379 return 0;
380}
381
382static void snd_timer_notify1(struct snd_timer_instance *ti, int event)
383{
384 struct snd_timer *timer;
385 unsigned long flags;
386 unsigned long resolution = 0;
387 struct snd_timer_instance *ts;
388 struct timespec tstamp;
389
390 if (timer_tstamp_monotonic)
391 do_posix_clock_monotonic_gettime(&tstamp);
392 else
393 getnstimeofday(&tstamp);
394 snd_assert(event >= SNDRV_TIMER_EVENT_START &&
395 event <= SNDRV_TIMER_EVENT_PAUSE, return);
396 if (event == SNDRV_TIMER_EVENT_START ||
397 event == SNDRV_TIMER_EVENT_CONTINUE)
398 resolution = snd_timer_resolution(ti);
399 if (ti->ccallback)
400 ti->ccallback(ti, SNDRV_TIMER_EVENT_START, &tstamp, resolution);
401 if (ti->flags & SNDRV_TIMER_IFLG_SLAVE)
402 return;
403 timer = ti->timer;
404 if (timer == NULL)
405 return;
406 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
407 return;
408 spin_lock_irqsave(&timer->lock, flags);
409 list_for_each_entry(ts, &ti->slave_active_head, active_list, struct snd_timer_instance)
410 if (ts->ccallback)
411 ts->ccallback(ti, event + 100, &tstamp, resolution);
412 spin_unlock_irqrestore(&timer->lock, flags);
413}
414
415static int snd_timer_start1(struct snd_timer *timer, struct snd_timer_instance *timeri,
416 unsigned long sticks)
417{
418 list_del(&timeri->active_list);
419 list_add_tail(&timeri->active_list, &timer->active_list_head);
420 if (timer->running) {
421 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
422 goto __start_now;
423 timer->flags |= SNDRV_TIMER_FLG_RESCHED;
424 timeri->flags |= SNDRV_TIMER_IFLG_START;
425 return 1; /* delayed start */
426 } else {
427 timer->sticks = sticks;
428 timer->hw.start(timer);
429 __start_now:
430 timer->running++;
431 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
432 return 0;
433 }
434}
435
436static int snd_timer_start_slave(struct snd_timer_instance *timeri)
437{
438 unsigned long flags;
439
440 spin_lock_irqsave(&slave_active_lock, flags);
441 timeri->flags |= SNDRV_TIMER_IFLG_RUNNING;
442 if (timeri->master)
443 list_add_tail(&timeri->active_list,
444 &timeri->master->slave_active_head);
445 spin_unlock_irqrestore(&slave_active_lock, flags);
446 return 1; /* delayed start */
447}
448
449/*
450 * start the timer instance
451 */
452int snd_timer_start(struct snd_timer_instance *timeri, unsigned int ticks)
453{
454 struct snd_timer *timer;
455 int result = -EINVAL;
456 unsigned long flags;
457
458 if (timeri == NULL || ticks < 1)
459 return -EINVAL;
460 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
461 result = snd_timer_start_slave(timeri);
462 snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
463 return result;
464 }
465 timer = timeri->timer;
466 if (timer == NULL)
467 return -EINVAL;
468 spin_lock_irqsave(&timer->lock, flags);
469 timeri->ticks = timeri->cticks = ticks;
470 timeri->pticks = 0;
471 result = snd_timer_start1(timer, timeri, ticks);
472 spin_unlock_irqrestore(&timer->lock, flags);
473 snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_START);
474 return result;
475}
476
477static int _snd_timer_stop(struct snd_timer_instance * timeri,
478 int keep_flag, int event)
479{
480 struct snd_timer *timer;
481 unsigned long flags;
482
483 snd_assert(timeri != NULL, return -ENXIO);
484
485 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE) {
486 if (!keep_flag) {
487 spin_lock_irqsave(&slave_active_lock, flags);
488 timeri->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
489 spin_unlock_irqrestore(&slave_active_lock, flags);
490 }
491 goto __end;
492 }
493 timer = timeri->timer;
494 if (!timer)
495 return -EINVAL;
496 spin_lock_irqsave(&timer->lock, flags);
497 list_del_init(&timeri->ack_list);
498 list_del_init(&timeri->active_list);
499 if ((timeri->flags & SNDRV_TIMER_IFLG_RUNNING) &&
500 !(--timer->running)) {
501 timer->hw.stop(timer);
502 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) {
503 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED;
504 snd_timer_reschedule(timer, 0);
505 if (timer->flags & SNDRV_TIMER_FLG_CHANGE) {
506 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE;
507 timer->hw.start(timer);
508 }
509 }
510 }
511 if (!keep_flag)
512 timeri->flags &=
513 ~(SNDRV_TIMER_IFLG_RUNNING | SNDRV_TIMER_IFLG_START);
514 spin_unlock_irqrestore(&timer->lock, flags);
515 __end:
516 if (event != SNDRV_TIMER_EVENT_RESOLUTION)
517 snd_timer_notify1(timeri, event);
518 return 0;
519}
520
521/*
522 * stop the timer instance.
523 *
524 * do not call this from the timer callback!
525 */
526int snd_timer_stop(struct snd_timer_instance *timeri)
527{
528 struct snd_timer *timer;
529 unsigned long flags;
530 int err;
531
532 err = _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_STOP);
533 if (err < 0)
534 return err;
535 timer = timeri->timer;
536 spin_lock_irqsave(&timer->lock, flags);
537 timeri->cticks = timeri->ticks;
538 timeri->pticks = 0;
539 spin_unlock_irqrestore(&timer->lock, flags);
540 return 0;
541}
542
543/*
544 * start again.. the tick is kept.
545 */
546int snd_timer_continue(struct snd_timer_instance *timeri)
547{
548 struct snd_timer *timer;
549 int result = -EINVAL;
550 unsigned long flags;
551
552 if (timeri == NULL)
553 return result;
554 if (timeri->flags & SNDRV_TIMER_IFLG_SLAVE)
555 return snd_timer_start_slave(timeri);
556 timer = timeri->timer;
557 if (! timer)
558 return -EINVAL;
559 spin_lock_irqsave(&timer->lock, flags);
560 if (!timeri->cticks)
561 timeri->cticks = 1;
562 timeri->pticks = 0;
563 result = snd_timer_start1(timer, timeri, timer->sticks);
564 spin_unlock_irqrestore(&timer->lock, flags);
565 snd_timer_notify1(timeri, SNDRV_TIMER_EVENT_CONTINUE);
566 return result;
567}
568
569/*
570 * pause.. remember the ticks left
571 */
572int snd_timer_pause(struct snd_timer_instance * timeri)
573{
574 return _snd_timer_stop(timeri, 0, SNDRV_TIMER_EVENT_PAUSE);
575}
576
577/*
578 * reschedule the timer
579 *
580 * start pending instances and check the scheduling ticks.
581 * when the scheduling ticks is changed set CHANGE flag to reprogram the timer.
582 */
583static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left)
584{
585 struct snd_timer_instance *ti;
586 unsigned long ticks = ~0UL;
587
588 list_for_each_entry(ti, &timer->active_list_head, active_list, struct snd_timer_instance) {
589 if (ti->flags & SNDRV_TIMER_IFLG_START) {
590 ti->flags &= ~SNDRV_TIMER_IFLG_START;
591 ti->flags |= SNDRV_TIMER_IFLG_RUNNING;
592 timer->running++;
593 }
594 if (ti->flags & SNDRV_TIMER_IFLG_RUNNING) {
595 if (ticks > ti->cticks)
596 ticks = ti->cticks;
597 }
598 }
599 if (ticks == ~0UL) {
600 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED;
601 return;
602 }
603 if (ticks > timer->hw.ticks)
604 ticks = timer->hw.ticks;
605 if (ticks_left != ticks)
606 timer->flags |= SNDRV_TIMER_FLG_CHANGE;
607 timer->sticks = ticks;
608}
609
610/*
611 * timer tasklet
612 *
613 */
614static void snd_timer_tasklet(unsigned long arg)
615{
616 struct snd_timer *timer = (struct snd_timer *) arg;
617 struct snd_timer_instance *ti;
618 struct list_head *p;
619 unsigned long resolution, ticks;
620 unsigned long flags;
621
622 spin_lock_irqsave(&timer->lock, flags);
623 /* now process all callbacks */
624 while (!list_empty(&timer->sack_list_head)) {
625 p = timer->sack_list_head.next; /* get first item */
626 ti = list_entry(p, struct snd_timer_instance, ack_list);
627
628 /* remove from ack_list and make empty */
629 list_del_init(p);
630
631 ticks = ti->pticks;
632 ti->pticks = 0;
633 resolution = ti->resolution;
634
635 ti->flags |= SNDRV_TIMER_IFLG_CALLBACK;
636 spin_unlock(&timer->lock);
637 if (ti->callback)
638 ti->callback(ti, resolution, ticks);
639 spin_lock(&timer->lock);
640 ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK;
641 }
642 spin_unlock_irqrestore(&timer->lock, flags);
643}
644
645/*
646 * timer interrupt
647 *
648 * ticks_left is usually equal to timer->sticks.
649 *
650 */
651void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left)
652{
653 struct snd_timer_instance *ti, *ts, *tmp;
654 unsigned long resolution, ticks;
655 struct list_head *p, *ack_list_head;
656 unsigned long flags;
657 int use_tasklet = 0;
658
659 if (timer == NULL)
660 return;
661
662 spin_lock_irqsave(&timer->lock, flags);
663
664 /* remember the current resolution */
665 if (timer->hw.c_resolution)
666 resolution = timer->hw.c_resolution(timer);
667 else
668 resolution = timer->hw.resolution;
669
670 /* loop for all active instances
671 * Here we cannot use list_for_each_entry because the active_list of a
672 * processed instance is relinked to done_list_head before the callback
673 * is called.
674 */
675 list_for_each_entry_safe(ti, tmp, &timer->active_list_head,
676 active_list, struct snd_timer_instance) {
677 if (!(ti->flags & SNDRV_TIMER_IFLG_RUNNING))
678 continue;
679 ti->pticks += ticks_left;
680 ti->resolution = resolution;
681 if (ti->cticks < ticks_left)
682 ti->cticks = 0;
683 else
684 ti->cticks -= ticks_left;
685 if (ti->cticks) /* not expired */
686 continue;
687 if (ti->flags & SNDRV_TIMER_IFLG_AUTO) {
688 ti->cticks = ti->ticks;
689 } else {
690 ti->flags &= ~SNDRV_TIMER_IFLG_RUNNING;
691 if (--timer->running)
692 list_del(&ti->active_list);
693 }
694 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) ||
695 (ti->flags & SNDRV_TIMER_IFLG_FAST))
696 ack_list_head = &timer->ack_list_head;
697 else
698 ack_list_head = &timer->sack_list_head;
699 if (list_empty(&ti->ack_list))
700 list_add_tail(&ti->ack_list, ack_list_head);
701 list_for_each_entry(ts, &ti->slave_active_head, active_list, struct snd_timer_instance) {
702 ts->pticks = ti->pticks;
703 ts->resolution = resolution;
704 if (list_empty(&ts->ack_list))
705 list_add_tail(&ts->ack_list, ack_list_head);
706 }
707 }
708 if (timer->flags & SNDRV_TIMER_FLG_RESCHED)
709 snd_timer_reschedule(timer, timer->sticks);
710 if (timer->running) {
711 if (timer->hw.flags & SNDRV_TIMER_HW_STOP) {
712 timer->hw.stop(timer);
713 timer->flags |= SNDRV_TIMER_FLG_CHANGE;
714 }
715 if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) ||
716 (timer->flags & SNDRV_TIMER_FLG_CHANGE)) {
717 /* restart timer */
718 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE;
719 timer->hw.start(timer);
720 }
721 } else {
722 timer->hw.stop(timer);
723 }
724
725 /* now process all fast callbacks */
726 while (!list_empty(&timer->ack_list_head)) {
727 p = timer->ack_list_head.next; /* get first item */
728 ti = list_entry(p, struct snd_timer_instance, ack_list);
729
730 /* remove from ack_list and make empty */
731 list_del_init(p);
732
733 ticks = ti->pticks;
734 ti->pticks = 0;
735
736 ti->flags |= SNDRV_TIMER_IFLG_CALLBACK;
737 spin_unlock(&timer->lock);
738 if (ti->callback)
739 ti->callback(ti, resolution, ticks);
740 spin_lock(&timer->lock);
741 ti->flags &= ~SNDRV_TIMER_IFLG_CALLBACK;
742 }
743
744 /* do we have any slow callbacks? */
745 use_tasklet = !list_empty(&timer->sack_list_head);
746 spin_unlock_irqrestore(&timer->lock, flags);
747
748 if (use_tasklet)
749 tasklet_hi_schedule(&timer->task_queue);
750}
751
752/*
753
754 */
755
756int snd_timer_new(struct snd_card *card, char *id, struct snd_timer_id *tid,
757 struct snd_timer **rtimer)
758{
759 struct snd_timer *timer;
760 int err;
761 static struct snd_device_ops ops = {
762 .dev_free = snd_timer_dev_free,
763 .dev_register = snd_timer_dev_register,
764 .dev_disconnect = snd_timer_dev_disconnect,
765 };
766
767 snd_assert(tid != NULL, return -EINVAL);
768 snd_assert(rtimer != NULL, return -EINVAL);
769 *rtimer = NULL;
770 timer = kzalloc(sizeof(*timer), GFP_KERNEL);
771 if (timer == NULL) {
772 snd_printk(KERN_ERR "timer: cannot allocate\n");
773 return -ENOMEM;
774 }
775 timer->tmr_class = tid->dev_class;
776 timer->card = card;
777 timer->tmr_device = tid->device;
778 timer->tmr_subdevice = tid->subdevice;
779 if (id)
780 strlcpy(timer->id, id, sizeof(timer->id));
781 INIT_LIST_HEAD(&timer->device_list);
782 INIT_LIST_HEAD(&timer->open_list_head);
783 INIT_LIST_HEAD(&timer->active_list_head);
784 INIT_LIST_HEAD(&timer->ack_list_head);
785 INIT_LIST_HEAD(&timer->sack_list_head);
786 spin_lock_init(&timer->lock);
787 tasklet_init(&timer->task_queue, snd_timer_tasklet,
788 (unsigned long)timer);
789 if (card != NULL) {
790 timer->module = card->module;
791 err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops);
792 if (err < 0) {
793 snd_timer_free(timer);
794 return err;
795 }
796 }
797 *rtimer = timer;
798 return 0;
799}
800
801static int snd_timer_free(struct snd_timer *timer)
802{
803 snd_assert(timer != NULL, return -ENXIO);
804
805 mutex_lock(&register_mutex);
806 if (! list_empty(&timer->open_list_head)) {
807 struct list_head *p, *n;
808 struct snd_timer_instance *ti;
809 snd_printk(KERN_WARNING "timer %p is busy?\n", timer);
810 list_for_each_safe(p, n, &timer->open_list_head) {
811 list_del_init(p);
812 ti = list_entry(p, struct snd_timer_instance, open_list);
813 ti->timer = NULL;
814 }
815 }
816 list_del(&timer->device_list);
817 mutex_unlock(&register_mutex);
818
819 if (timer->private_free)
820 timer->private_free(timer);
821 kfree(timer);
822 return 0;
823}
824
825static int snd_timer_dev_free(struct snd_device *device)
826{
827 struct snd_timer *timer = device->device_data;
828 return snd_timer_free(timer);
829}
830
831static int snd_timer_dev_register(struct snd_device *dev)
832{
833 struct snd_timer *timer = dev->device_data;
834 struct snd_timer *timer1;
835
836 snd_assert(timer != NULL && timer->hw.start != NULL &&
837 timer->hw.stop != NULL, return -ENXIO);
838 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) &&
839 !timer->hw.resolution && timer->hw.c_resolution == NULL)
840 return -EINVAL;
841
842 mutex_lock(&register_mutex);
843 list_for_each_entry(timer1, &snd_timer_list, device_list, struct snd_timer) {
844 if (timer1->tmr_class > timer->tmr_class)
845 break;
846 if (timer1->tmr_class < timer->tmr_class)
847 continue;
848 if (timer1->card && timer->card) {
849 if (timer1->card->number > timer->card->number)
850 break;
851 if (timer1->card->number < timer->card->number)
852 continue;
853 }
854 if (timer1->tmr_device > timer->tmr_device)
855 break;
856 if (timer1->tmr_device < timer->tmr_device)
857 continue;
858 if (timer1->tmr_subdevice > timer->tmr_subdevice)
859 break;
860 if (timer1->tmr_subdevice < timer->tmr_subdevice)
861 continue;
862 /* conflicts.. */
863 mutex_unlock(&register_mutex);
864 return -EBUSY;
865 }
866 list_add_tail(&timer->device_list, &timer1->device_list);
867 mutex_unlock(&register_mutex);
868 return 0;
869}
870
871static int snd_timer_dev_disconnect(struct snd_device *device)
872{
873 struct snd_timer *timer = device->device_data;
874 mutex_lock(&register_mutex);
875 list_del_init(&timer->device_list);
876 mutex_unlock(&register_mutex);
877 return 0;
878}
879
880void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp)
881{
882 unsigned long flags;
883 unsigned long resolution = 0;
884 struct snd_timer_instance *ti, *ts;
885
886 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE))
887 return;
888 snd_assert(event >= SNDRV_TIMER_EVENT_MSTART &&
889 event <= SNDRV_TIMER_EVENT_MRESUME, return);
890 spin_lock_irqsave(&timer->lock, flags);
891 if (event == SNDRV_TIMER_EVENT_MSTART ||
892 event == SNDRV_TIMER_EVENT_MCONTINUE ||
893 event == SNDRV_TIMER_EVENT_MRESUME) {
894 if (timer->hw.c_resolution)
895 resolution = timer->hw.c_resolution(timer);
896 else
897 resolution = timer->hw.resolution;
898 }
899 list_for_each_entry(ti, &timer->active_list_head, active_list, struct snd_timer_instance) {
900 if (ti->ccallback)
901 ti->ccallback(ti, event, tstamp, resolution);
902 list_for_each_entry(ts, &ti->slave_active_head, active_list, struct snd_timer_instance)
903 if (ts->ccallback)
904 ts->ccallback(ts, event, tstamp, resolution);
905 }
906 spin_unlock_irqrestore(&timer->lock, flags);
907}
908
909/*
910 * exported functions for global timers
911 */
912int snd_timer_global_new(char *id, int device, struct snd_timer **rtimer)
913{
914 struct snd_timer_id tid;
915
916 tid.dev_class = SNDRV_TIMER_CLASS_GLOBAL;
917 tid.dev_sclass = SNDRV_TIMER_SCLASS_NONE;
918 tid.card = -1;
919 tid.device = device;
920 tid.subdevice = 0;
921 return snd_timer_new(NULL, id, &tid, rtimer);
922}
923
924int snd_timer_global_free(struct snd_timer *timer)
925{
926 return snd_timer_free(timer);
927}
928
929int snd_timer_global_register(struct snd_timer *timer)
930{
931 struct snd_device dev;
932
933 memset(&dev, 0, sizeof(dev));
934 dev.device_data = timer;
935 return snd_timer_dev_register(&dev);
936}
937
938/*
939 * System timer
940 */
941
942struct snd_timer_system_private {
943 struct timer_list tlist;
944 unsigned long last_expires;
945 unsigned long last_jiffies;
946 unsigned long correction;
947};
948
949static void snd_timer_s_function(unsigned long data)
950{
951 struct snd_timer *timer = (struct snd_timer *)data;
952 struct snd_timer_system_private *priv = timer->private_data;
953 unsigned long jiff = jiffies;
954 if (time_after(jiff, priv->last_expires))
955 priv->correction += (long)jiff - (long)priv->last_expires;
956 snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies);
957}
958
959static int snd_timer_s_start(struct snd_timer * timer)
960{
961 struct snd_timer_system_private *priv;
962 unsigned long njiff;
963
964 priv = (struct snd_timer_system_private *) timer->private_data;
965 njiff = (priv->last_jiffies = jiffies);
966 if (priv->correction > timer->sticks - 1) {
967 priv->correction -= timer->sticks - 1;
968 njiff++;
969 } else {
970 njiff += timer->sticks - priv->correction;
971 priv->correction = 0;
972 }
973 priv->last_expires = priv->tlist.expires = njiff;
974 add_timer(&priv->tlist);
975 return 0;
976}
977
978static int snd_timer_s_stop(struct snd_timer * timer)
979{
980 struct snd_timer_system_private *priv;
981 unsigned long jiff;
982
983 priv = (struct snd_timer_system_private *) timer->private_data;
984 del_timer(&priv->tlist);
985 jiff = jiffies;
986 if (time_before(jiff, priv->last_expires))
987 timer->sticks = priv->last_expires - jiff;
988 else
989 timer->sticks = 1;
990 priv->correction = 0;
991 return 0;
992}
993
994static struct snd_timer_hardware snd_timer_system =
995{
996 .flags = SNDRV_TIMER_HW_FIRST | SNDRV_TIMER_HW_TASKLET,
997 .resolution = 1000000000L / HZ,
998 .ticks = 10000000L,
999 .start = snd_timer_s_start,
1000 .stop = snd_timer_s_stop
1001};
1002
1003static void snd_timer_free_system(struct snd_timer *timer)
1004{
1005 kfree(timer->private_data);
1006}
1007
1008static int snd_timer_register_system(void)
1009{
1010 struct snd_timer *timer;
1011 struct snd_timer_system_private *priv;
1012 int err;
1013
1014 err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer);
1015 if (err < 0)
1016 return err;
1017 strcpy(timer->name, "system timer");
1018 timer->hw = snd_timer_system;
1019 priv = kzalloc(sizeof(*priv), GFP_KERNEL);
1020 if (priv == NULL) {
1021 snd_timer_free(timer);
1022 return -ENOMEM;
1023 }
1024 init_timer(&priv->tlist);
1025 priv->tlist.function = snd_timer_s_function;
1026 priv->tlist.data = (unsigned long) timer;
1027 timer->private_data = priv;
1028 timer->private_free = snd_timer_free_system;
1029 return snd_timer_global_register(timer);
1030}
1031
1032#ifdef CONFIG_PROC_FS
1033/*
1034 * Info interface
1035 */
1036
1037static void snd_timer_proc_read(struct snd_info_entry *entry,
1038 struct snd_info_buffer *buffer)
1039{
1040 struct snd_timer *timer;
1041 struct snd_timer_instance *ti;
1042
1043 mutex_lock(&register_mutex);
1044 list_for_each_entry(timer, &snd_timer_list, device_list, struct snd_timer) {
1045 switch (timer->tmr_class) {
1046 case SNDRV_TIMER_CLASS_GLOBAL:
1047 snd_iprintf(buffer, "G%i: ", timer->tmr_device);
1048 break;
1049 case SNDRV_TIMER_CLASS_CARD:
1050 snd_iprintf(buffer, "C%i-%i: ",
1051 timer->card->number, timer->tmr_device);
1052 break;
1053 case SNDRV_TIMER_CLASS_PCM:
1054 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number,
1055 timer->tmr_device, timer->tmr_subdevice);
1056 break;
1057 default:
1058 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class,
1059 timer->card ? timer->card->number : -1,
1060 timer->tmr_device, timer->tmr_subdevice);
1061 }
1062 snd_iprintf(buffer, "%s :", timer->name);
1063 if (timer->hw.resolution)
1064 snd_iprintf(buffer, " %lu.%03luus (%lu ticks)",
1065 timer->hw.resolution / 1000,
1066 timer->hw.resolution % 1000,
1067 timer->hw.ticks);
1068 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)
1069 snd_iprintf(buffer, " SLAVE");
1070 snd_iprintf(buffer, "\n");
1071 list_for_each_entry(ti, &timer->open_list_head, open_list, struct snd_timer_instance)
1072 snd_iprintf(buffer, " Client %s : %s\n",
1073 ti->owner ? ti->owner : "unknown",
1074 ti->flags & (SNDRV_TIMER_IFLG_START |
1075 SNDRV_TIMER_IFLG_RUNNING)
1076 ? "running" : "stopped");
1077 }
1078 mutex_unlock(&register_mutex);
1079}
1080
1081static struct snd_info_entry *snd_timer_proc_entry;
1082
1083static void __init snd_timer_proc_init(void)
1084{
1085 struct snd_info_entry *entry;
1086
1087 entry = snd_info_create_module_entry(THIS_MODULE, "timers", NULL);
1088 if (entry != NULL) {
1089 entry->c.text.read = snd_timer_proc_read;
1090 if (snd_info_register(entry) < 0) {
1091 snd_info_free_entry(entry);
1092 entry = NULL;
1093 }
1094 }
1095 snd_timer_proc_entry = entry;
1096}
1097
1098static void __exit snd_timer_proc_done(void)
1099{
1100 snd_info_free_entry(snd_timer_proc_entry);
1101}
1102#else /* !CONFIG_PROC_FS */
1103#define snd_timer_proc_init()
1104#define snd_timer_proc_done()
1105#endif
1106
1107/*
1108 * USER SPACE interface
1109 */
1110
1111static void snd_timer_user_interrupt(struct snd_timer_instance *timeri,
1112 unsigned long resolution,
1113 unsigned long ticks)
1114{
1115 struct snd_timer_user *tu = timeri->callback_data;
1116 struct snd_timer_read *r;
1117 int prev;
1118
1119 spin_lock(&tu->qlock);
1120 if (tu->qused > 0) {
1121 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
1122 r = &tu->queue[prev];
1123 if (r->resolution == resolution) {
1124 r->ticks += ticks;
1125 goto __wake;
1126 }
1127 }
1128 if (tu->qused >= tu->queue_size) {
1129 tu->overrun++;
1130 } else {
1131 r = &tu->queue[tu->qtail++];
1132 tu->qtail %= tu->queue_size;
1133 r->resolution = resolution;
1134 r->ticks = ticks;
1135 tu->qused++;
1136 }
1137 __wake:
1138 spin_unlock(&tu->qlock);
1139#ifndef TARGET_OS2
1140 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1141#else
1142 kill_fasync(tu->fasync, SIGIO, POLL_IN);
1143#endif
1144 wake_up(&tu->qchange_sleep);
1145}
1146
1147static void snd_timer_user_append_to_tqueue(struct snd_timer_user *tu,
1148 struct snd_timer_tread *tread)
1149{
1150 if (tu->qused >= tu->queue_size) {
1151 tu->overrun++;
1152 } else {
1153 memcpy(&tu->tqueue[tu->qtail++], tread, sizeof(*tread));
1154 tu->qtail %= tu->queue_size;
1155 tu->qused++;
1156 }
1157}
1158
1159static void snd_timer_user_ccallback(struct snd_timer_instance *timeri,
1160 int event,
1161 struct timespec *tstamp,
1162 unsigned long resolution)
1163{
1164 struct snd_timer_user *tu = timeri->callback_data;
1165 struct snd_timer_tread r1;
1166
1167 if (event >= SNDRV_TIMER_EVENT_START &&
1168 event <= SNDRV_TIMER_EVENT_PAUSE)
1169 tu->tstamp = *tstamp;
1170 if ((tu->filter & (1 << event)) == 0 || !tu->tread)
1171 return;
1172 r1.event = event;
1173 r1.tstamp = *tstamp;
1174 r1.val = resolution;
1175 spin_lock(&tu->qlock);
1176 snd_timer_user_append_to_tqueue(tu, &r1);
1177 spin_unlock(&tu->qlock);
1178#ifndef TARGET_OS2
1179 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1180#else
1181 kill_fasync(tu->fasync, SIGIO, POLL_IN);
1182#endif
1183 wake_up(&tu->qchange_sleep);
1184}
1185
1186static void snd_timer_user_tinterrupt(struct snd_timer_instance *timeri,
1187 unsigned long resolution,
1188 unsigned long ticks)
1189{
1190 struct snd_timer_user *tu = timeri->callback_data;
1191 struct snd_timer_tread *r, r1;
1192 struct timespec tstamp;
1193 int prev, append = 0;
1194
1195 memset(&tstamp, 0, sizeof(tstamp));
1196 spin_lock(&tu->qlock);
1197 if ((tu->filter & ((1 << SNDRV_TIMER_EVENT_RESOLUTION) |
1198 (1 << SNDRV_TIMER_EVENT_TICK))) == 0) {
1199 spin_unlock(&tu->qlock);
1200 return;
1201 }
1202 if (tu->last_resolution != resolution || ticks > 0) {
1203 if (timer_tstamp_monotonic)
1204 do_posix_clock_monotonic_gettime(&tstamp);
1205 else
1206 getnstimeofday(&tstamp);
1207 }
1208 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_RESOLUTION)) &&
1209 tu->last_resolution != resolution) {
1210 r1.event = SNDRV_TIMER_EVENT_RESOLUTION;
1211 r1.tstamp = tstamp;
1212 r1.val = resolution;
1213 snd_timer_user_append_to_tqueue(tu, &r1);
1214 tu->last_resolution = resolution;
1215 append++;
1216 }
1217 if ((tu->filter & (1 << SNDRV_TIMER_EVENT_TICK)) == 0)
1218 goto __wake;
1219 if (ticks == 0)
1220 goto __wake;
1221 if (tu->qused > 0) {
1222 prev = tu->qtail == 0 ? tu->queue_size - 1 : tu->qtail - 1;
1223 r = &tu->tqueue[prev];
1224 if (r->event == SNDRV_TIMER_EVENT_TICK) {
1225 r->tstamp = tstamp;
1226 r->val += ticks;
1227 append++;
1228 goto __wake;
1229 }
1230 }
1231 r1.event = SNDRV_TIMER_EVENT_TICK;
1232 r1.tstamp = tstamp;
1233 r1.val = ticks;
1234 snd_timer_user_append_to_tqueue(tu, &r1);
1235 append++;
1236 __wake:
1237 spin_unlock(&tu->qlock);
1238 if (append == 0)
1239 return;
1240#ifndef TARGET_OS2
1241 kill_fasync(&tu->fasync, SIGIO, POLL_IN);
1242#else
1243 kill_fasync(tu->fasync, SIGIO, POLL_IN);
1244#endif
1245 wake_up(&tu->qchange_sleep);
1246}
1247
1248static int snd_timer_user_open(struct inode *inode, struct file *file)
1249{
1250 struct snd_timer_user *tu;
1251
1252 tu = kzalloc(sizeof(*tu), GFP_KERNEL);
1253 if (tu == NULL)
1254 return -ENOMEM;
1255 spin_lock_init(&tu->qlock);
1256 init_waitqueue_head(&tu->qchange_sleep);
1257 mutex_init(&tu->tread_sem);
1258 tu->ticks = 1;
1259 tu->queue_size = 128;
1260 tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read),
1261 GFP_KERNEL);
1262 if (tu->queue == NULL) {
1263 kfree(tu);
1264 return -ENOMEM;
1265 }
1266 file->private_data = tu;
1267 return 0;
1268}
1269
1270static int snd_timer_user_release(struct inode *inode, struct file *file)
1271{
1272 struct snd_timer_user *tu;
1273
1274 if (file->private_data) {
1275 tu = file->private_data;
1276 file->private_data = NULL;
1277 fasync_helper(-1, file, 0, &tu->fasync);
1278 if (tu->timeri)
1279 snd_timer_close(tu->timeri);
1280 kfree(tu->queue);
1281 kfree(tu->tqueue);
1282 kfree(tu);
1283 }
1284 return 0;
1285}
1286
1287static void snd_timer_user_zero_id(struct snd_timer_id *id)
1288{
1289 id->dev_class = SNDRV_TIMER_CLASS_NONE;
1290 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1291 id->card = -1;
1292 id->device = -1;
1293 id->subdevice = -1;
1294}
1295
1296static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer)
1297{
1298 id->dev_class = timer->tmr_class;
1299 id->dev_sclass = SNDRV_TIMER_SCLASS_NONE;
1300 id->card = timer->card ? timer->card->number : -1;
1301 id->device = timer->tmr_device;
1302 id->subdevice = timer->tmr_subdevice;
1303}
1304
1305static int snd_timer_user_next_device(struct snd_timer_id __user *_tid)
1306{
1307 struct snd_timer_id id;
1308 struct snd_timer *timer;
1309 struct list_head *p;
1310
1311 if (copy_from_user(&id, _tid, sizeof(id)))
1312 return -EFAULT;
1313 mutex_lock(&register_mutex);
1314 if (id.dev_class < 0) { /* first item */
1315 if (list_empty(&snd_timer_list))
1316 snd_timer_user_zero_id(&id);
1317 else {
1318 timer = list_entry(snd_timer_list.next,
1319 struct snd_timer, device_list);
1320 snd_timer_user_copy_id(&id, timer);
1321 }
1322 } else {
1323 switch (id.dev_class) {
1324 case SNDRV_TIMER_CLASS_GLOBAL:
1325 id.device = id.device < 0 ? 0 : id.device + 1;
1326 list_for_each(p, &snd_timer_list) {
1327 timer = list_entry(p, struct snd_timer, device_list);
1328 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) {
1329 snd_timer_user_copy_id(&id, timer);
1330 break;
1331 }
1332 if (timer->tmr_device >= id.device) {
1333 snd_timer_user_copy_id(&id, timer);
1334 break;
1335 }
1336 }
1337 if (p == &snd_timer_list)
1338 snd_timer_user_zero_id(&id);
1339 break;
1340 case SNDRV_TIMER_CLASS_CARD:
1341 case SNDRV_TIMER_CLASS_PCM:
1342 if (id.card < 0) {
1343 id.card = 0;
1344 } else {
1345 if (id.card < 0) {
1346 id.card = 0;
1347 } else {
1348 if (id.device < 0) {
1349 id.device = 0;
1350 } else {
1351 if (id.subdevice < 0) {
1352 id.subdevice = 0;
1353 } else {
1354 id.subdevice++;
1355 }
1356 }
1357 }
1358 }
1359 list_for_each(p, &snd_timer_list) {
1360 timer = list_entry(p, struct snd_timer, device_list);
1361 if (timer->tmr_class > id.dev_class) {
1362 snd_timer_user_copy_id(&id, timer);
1363 break;
1364 }
1365 if (timer->tmr_class < id.dev_class)
1366 continue;
1367 if (timer->card->number > id.card) {
1368 snd_timer_user_copy_id(&id, timer);
1369 break;
1370 }
1371 if (timer->card->number < id.card)
1372 continue;
1373 if (timer->tmr_device > id.device) {
1374 snd_timer_user_copy_id(&id, timer);
1375 break;
1376 }
1377 if (timer->tmr_device < id.device)
1378 continue;
1379 if (timer->tmr_subdevice > id.subdevice) {
1380 snd_timer_user_copy_id(&id, timer);
1381 break;
1382 }
1383 if (timer->tmr_subdevice < id.subdevice)
1384 continue;
1385 snd_timer_user_copy_id(&id, timer);
1386 break;
1387 }
1388 if (p == &snd_timer_list)
1389 snd_timer_user_zero_id(&id);
1390 break;
1391 default:
1392 snd_timer_user_zero_id(&id);
1393 }
1394 }
1395 mutex_unlock(&register_mutex);
1396 if (copy_to_user(_tid, &id, sizeof(*_tid)))
1397 return -EFAULT;
1398 return 0;
1399}
1400
1401static int snd_timer_user_ginfo(struct file *file,
1402 struct snd_timer_ginfo __user *_ginfo)
1403{
1404 struct snd_timer_ginfo *ginfo;
1405 struct snd_timer_id tid;
1406 struct snd_timer *t;
1407 struct list_head *p;
1408 int err = 0;
1409
1410 ginfo = kmalloc(sizeof(*ginfo), GFP_KERNEL);
1411 if (! ginfo)
1412 return -ENOMEM;
1413 if (copy_from_user(ginfo, _ginfo, sizeof(*ginfo))) {
1414 kfree(ginfo);
1415 return -EFAULT;
1416 }
1417 tid = ginfo->tid;
1418 memset(ginfo, 0, sizeof(*ginfo));
1419 ginfo->tid = tid;
1420 mutex_lock(&register_mutex);
1421 t = snd_timer_find(&tid);
1422 if (t != NULL) {
1423 ginfo->card = t->card ? t->card->number : -1;
1424 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
1425 ginfo->flags |= SNDRV_TIMER_FLG_SLAVE;
1426 strlcpy(ginfo->id, t->id, sizeof(ginfo->id));
1427 strlcpy(ginfo->name, t->name, sizeof(ginfo->name));
1428 ginfo->resolution = t->hw.resolution;
1429 if (t->hw.resolution_min > 0) {
1430 ginfo->resolution_min = t->hw.resolution_min;
1431 ginfo->resolution_max = t->hw.resolution_max;
1432 }
1433 list_for_each(p, &t->open_list_head) {
1434 ginfo->clients++;
1435 }
1436 } else {
1437 err = -ENODEV;
1438 }
1439 mutex_unlock(&register_mutex);
1440 if (err >= 0 && copy_to_user(_ginfo, ginfo, sizeof(*ginfo)))
1441 err = -EFAULT;
1442 kfree(ginfo);
1443 return err;
1444}
1445
1446static int snd_timer_user_gparams(struct file *file,
1447 struct snd_timer_gparams __user *_gparams)
1448{
1449 struct snd_timer_gparams gparams;
1450 struct snd_timer *t;
1451 int err;
1452
1453 if (copy_from_user(&gparams, _gparams, sizeof(gparams)))
1454 return -EFAULT;
1455 mutex_lock(&register_mutex);
1456 t = snd_timer_find(&gparams.tid);
1457 if (!t) {
1458 err = -ENODEV;
1459 goto _error;
1460 }
1461 if (!list_empty(&t->open_list_head)) {
1462 err = -EBUSY;
1463 goto _error;
1464 }
1465 if (!t->hw.set_period) {
1466 err = -ENOSYS;
1467 goto _error;
1468 }
1469 err = t->hw.set_period(t, gparams.period_num, gparams.period_den);
1470_error:
1471 mutex_unlock(&register_mutex);
1472 return err;
1473}
1474
1475static int snd_timer_user_gstatus(struct file *file,
1476 struct snd_timer_gstatus __user *_gstatus)
1477{
1478 struct snd_timer_gstatus gstatus;
1479 struct snd_timer_id tid;
1480 struct snd_timer *t;
1481 int err = 0;
1482
1483 if (copy_from_user(&gstatus, _gstatus, sizeof(gstatus)))
1484 return -EFAULT;
1485 tid = gstatus.tid;
1486 memset(&gstatus, 0, sizeof(gstatus));
1487 gstatus.tid = tid;
1488 mutex_lock(&register_mutex);
1489 t = snd_timer_find(&tid);
1490 if (t != NULL) {
1491 if (t->hw.c_resolution)
1492 gstatus.resolution = t->hw.c_resolution(t);
1493 else
1494 gstatus.resolution = t->hw.resolution;
1495 if (t->hw.precise_resolution) {
1496 t->hw.precise_resolution(t, &gstatus.resolution_num,
1497 &gstatus.resolution_den);
1498 } else {
1499 gstatus.resolution_num = gstatus.resolution;
1500 gstatus.resolution_den = 1000000000uL;
1501 }
1502 } else {
1503 err = -ENODEV;
1504 }
1505 mutex_unlock(&register_mutex);
1506 if (err >= 0 && copy_to_user(_gstatus, &gstatus, sizeof(gstatus)))
1507 err = -EFAULT;
1508 return err;
1509}
1510
1511static int snd_timer_user_tselect(struct file *file,
1512 struct snd_timer_select __user *_tselect)
1513{
1514 struct snd_timer_user *tu;
1515 struct snd_timer_select tselect;
1516 char str[32];
1517 int err = 0;
1518
1519 tu = file->private_data;
1520 mutex_lock(&tu->tread_sem);
1521 if (tu->timeri) {
1522 snd_timer_close(tu->timeri);
1523 tu->timeri = NULL;
1524 }
1525 if (copy_from_user(&tselect, _tselect, sizeof(tselect))) {
1526 err = -EFAULT;
1527 goto __err;
1528 }
1529 sprintf(str, "application %i", current->pid);
1530 if (tselect.id.dev_class != SNDRV_TIMER_CLASS_SLAVE)
1531 tselect.id.dev_sclass = SNDRV_TIMER_SCLASS_APPLICATION;
1532 err = snd_timer_open(&tu->timeri, str, &tselect.id, current->pid);
1533 if (err < 0)
1534 goto __err;
1535
1536 kfree(tu->queue);
1537 tu->queue = NULL;
1538 kfree(tu->tqueue);
1539 tu->tqueue = NULL;
1540 if (tu->tread) {
1541 tu->tqueue = kmalloc(tu->queue_size * sizeof(struct snd_timer_tread),
1542 GFP_KERNEL);
1543 if (tu->tqueue == NULL)
1544 err = -ENOMEM;
1545 } else {
1546 tu->queue = kmalloc(tu->queue_size * sizeof(struct snd_timer_read),
1547 GFP_KERNEL);
1548 if (tu->queue == NULL)
1549 err = -ENOMEM;
1550 }
1551
1552 if (err < 0) {
1553 snd_timer_close(tu->timeri);
1554 tu->timeri = NULL;
1555 } else {
1556 tu->timeri->flags |= SNDRV_TIMER_IFLG_FAST;
1557 tu->timeri->callback = tu->tread
1558 ? snd_timer_user_tinterrupt : snd_timer_user_interrupt;
1559 tu->timeri->ccallback = snd_timer_user_ccallback;
1560 tu->timeri->callback_data = (void *)tu;
1561 }
1562
1563 __err:
1564 mutex_unlock(&tu->tread_sem);
1565 return err;
1566}
1567
1568static int snd_timer_user_info(struct file *file,
1569 struct snd_timer_info __user *_info)
1570{
1571 struct snd_timer_user *tu;
1572 struct snd_timer_info *info;
1573 struct snd_timer *t;
1574 int err = 0;
1575
1576 tu = file->private_data;
1577 if (!tu->timeri)
1578 return -EBADFD;
1579 t = tu->timeri->timer;
1580 if (!t)
1581 return -EBADFD;
1582
1583 info = kzalloc(sizeof(*info), GFP_KERNEL);
1584 if (! info)
1585 return -ENOMEM;
1586 info->card = t->card ? t->card->number : -1;
1587 if (t->hw.flags & SNDRV_TIMER_HW_SLAVE)
1588 info->flags |= SNDRV_TIMER_FLG_SLAVE;
1589 strlcpy(info->id, t->id, sizeof(info->id));
1590 strlcpy(info->name, t->name, sizeof(info->name));
1591 info->resolution = t->hw.resolution;
1592 if (copy_to_user(_info, info, sizeof(*_info)))
1593 err = -EFAULT;
1594 kfree(info);
1595 return err;
1596}
1597
1598static int snd_timer_user_params(struct file *file,
1599 struct snd_timer_params __user *_params)
1600{
1601 struct snd_timer_user *tu;
1602 struct snd_timer_params params;
1603 struct snd_timer *t;
1604 struct snd_timer_read *tr;
1605 struct snd_timer_tread *ttr;
1606 int err;
1607
1608 tu = file->private_data;
1609 if (!tu->timeri)
1610 return -EBADFD;
1611 t = tu->timeri->timer;
1612 if (!t)
1613 return -EBADFD;
1614 if (copy_from_user(&params, _params, sizeof(params)))
1615 return -EFAULT;
1616 if (!(t->hw.flags & SNDRV_TIMER_HW_SLAVE) && params.ticks < 1) {
1617 err = -EINVAL;
1618 goto _end;
1619 }
1620 if (params.queue_size > 0 &&
1621 (params.queue_size < 32 || params.queue_size > 1024)) {
1622 err = -EINVAL;
1623 goto _end;
1624 }
1625 if (params.filter & ~((1<<SNDRV_TIMER_EVENT_RESOLUTION)|
1626 (1<<SNDRV_TIMER_EVENT_TICK)|
1627 (1<<SNDRV_TIMER_EVENT_START)|
1628 (1<<SNDRV_TIMER_EVENT_STOP)|
1629 (1<<SNDRV_TIMER_EVENT_CONTINUE)|
1630 (1<<SNDRV_TIMER_EVENT_PAUSE)|
1631 (1<<SNDRV_TIMER_EVENT_SUSPEND)|
1632 (1<<SNDRV_TIMER_EVENT_RESUME)|
1633 (1<<SNDRV_TIMER_EVENT_MSTART)|
1634 (1<<SNDRV_TIMER_EVENT_MSTOP)|
1635 (1<<SNDRV_TIMER_EVENT_MCONTINUE)|
1636 (1<<SNDRV_TIMER_EVENT_MPAUSE)|
1637 (1<<SNDRV_TIMER_EVENT_MSUSPEND)|
1638 (1<<SNDRV_TIMER_EVENT_MRESUME))) {
1639 err = -EINVAL;
1640 goto _end;
1641 }
1642 snd_timer_stop(tu->timeri);
1643 spin_lock_irq(&t->lock);
1644 tu->timeri->flags &= ~(SNDRV_TIMER_IFLG_AUTO|
1645 SNDRV_TIMER_IFLG_EXCLUSIVE|
1646 SNDRV_TIMER_IFLG_EARLY_EVENT);
1647 if (params.flags & SNDRV_TIMER_PSFLG_AUTO)
1648 tu->timeri->flags |= SNDRV_TIMER_IFLG_AUTO;
1649 if (params.flags & SNDRV_TIMER_PSFLG_EXCLUSIVE)
1650 tu->timeri->flags |= SNDRV_TIMER_IFLG_EXCLUSIVE;
1651 if (params.flags & SNDRV_TIMER_PSFLG_EARLY_EVENT)
1652 tu->timeri->flags |= SNDRV_TIMER_IFLG_EARLY_EVENT;
1653 spin_unlock_irq(&t->lock);
1654 if (params.queue_size > 0 &&
1655 (unsigned int)tu->queue_size != params.queue_size) {
1656 if (tu->tread) {
1657 ttr = kmalloc(params.queue_size * sizeof(*ttr),
1658 GFP_KERNEL);
1659 if (ttr) {
1660 kfree(tu->tqueue);
1661 tu->queue_size = params.queue_size;
1662 tu->tqueue = ttr;
1663 }
1664 } else {
1665 tr = kmalloc(params.queue_size * sizeof(*tr),
1666 GFP_KERNEL);
1667 if (tr) {
1668 kfree(tu->queue);
1669 tu->queue_size = params.queue_size;
1670 tu->queue = tr;
1671 }
1672 }
1673 }
1674 tu->qhead = tu->qtail = tu->qused = 0;
1675 if (tu->timeri->flags & SNDRV_TIMER_IFLG_EARLY_EVENT) {
1676 if (tu->tread) {
1677 struct snd_timer_tread tread;
1678 tread.event = SNDRV_TIMER_EVENT_EARLY;
1679 tread.tstamp.tv_sec = 0;
1680 tread.tstamp.tv_nsec = 0;
1681 tread.val = 0;
1682 snd_timer_user_append_to_tqueue(tu, &tread);
1683 } else {
1684 struct snd_timer_read *r = &tu->queue[0];
1685 r->resolution = 0;
1686 r->ticks = 0;
1687 tu->qused++;
1688 tu->qtail++;
1689 }
1690 }
1691 tu->filter = params.filter;
1692 tu->ticks = params.ticks;
1693 err = 0;
1694 _end:
1695 if (copy_to_user(_params, &params, sizeof(params)))
1696 return -EFAULT;
1697 return err;
1698}
1699
1700static int snd_timer_user_status(struct file *file,
1701 struct snd_timer_status __user *_status)
1702{
1703 struct snd_timer_user *tu;
1704 struct snd_timer_status status;
1705
1706 tu = file->private_data;
1707 if (!tu->timeri)
1708 return -EBADFD;
1709 memset(&status, 0, sizeof(status));
1710 status.tstamp = tu->tstamp;
1711 status.resolution = snd_timer_resolution(tu->timeri);
1712 status.lost = tu->timeri->lost;
1713 status.overrun = tu->overrun;
1714 spin_lock_irq(&tu->qlock);
1715 status.queue = tu->qused;
1716 spin_unlock_irq(&tu->qlock);
1717 if (copy_to_user(_status, &status, sizeof(status)))
1718 return -EFAULT;
1719 return 0;
1720}
1721
1722static int snd_timer_user_start(struct file *file)
1723{
1724 int err;
1725 struct snd_timer_user *tu;
1726
1727 tu = file->private_data;
1728 if (!tu->timeri)
1729 return -EBADFD;
1730 snd_timer_stop(tu->timeri);
1731 tu->timeri->lost = 0;
1732 tu->last_resolution = 0;
1733 return (err = snd_timer_start(tu->timeri, tu->ticks)) < 0 ? err : 0;
1734}
1735
1736static int snd_timer_user_stop(struct file *file)
1737{
1738 int err;
1739 struct snd_timer_user *tu;
1740
1741 tu = file->private_data;
1742 if (!tu->timeri)
1743 return -EBADFD;
1744 return (err = snd_timer_stop(tu->timeri)) < 0 ? err : 0;
1745}
1746
1747static int snd_timer_user_continue(struct file *file)
1748{
1749 int err;
1750 struct snd_timer_user *tu;
1751
1752 tu = file->private_data;
1753 if (!tu->timeri)
1754 return -EBADFD;
1755 tu->timeri->lost = 0;
1756 return (err = snd_timer_continue(tu->timeri)) < 0 ? err : 0;
1757}
1758
1759static int snd_timer_user_pause(struct file *file)
1760{
1761 int err;
1762 struct snd_timer_user *tu;
1763
1764 tu = file->private_data;
1765 if (!tu->timeri)
1766 return -EBADFD;
1767 return (err = snd_timer_pause(tu->timeri)) < 0 ? err : 0;
1768}
1769
1770enum {
1771 SNDRV_TIMER_IOCTL_START_OLD = _IO('T', 0x20),
1772 SNDRV_TIMER_IOCTL_STOP_OLD = _IO('T', 0x21),
1773 SNDRV_TIMER_IOCTL_CONTINUE_OLD = _IO('T', 0x22),
1774 SNDRV_TIMER_IOCTL_PAUSE_OLD = _IO('T', 0x23),
1775};
1776
1777static long snd_timer_user_ioctl(struct file *file, unsigned int cmd,
1778 unsigned long arg)
1779{
1780 struct snd_timer_user *tu;
1781 void __user *argp = (void __user *)arg;
1782 int __user *p = argp;
1783
1784 tu = file->private_data;
1785 switch (cmd) {
1786 case SNDRV_TIMER_IOCTL_PVERSION:
1787 return put_user(SNDRV_TIMER_VERSION, p) ? -EFAULT : 0;
1788 case SNDRV_TIMER_IOCTL_NEXT_DEVICE:
1789 return snd_timer_user_next_device(argp);
1790 case SNDRV_TIMER_IOCTL_TREAD:
1791 {
1792 int xarg;
1793
1794 mutex_lock(&tu->tread_sem);
1795 if (tu->timeri) { /* too late */
1796 mutex_unlock(&tu->tread_sem);
1797 return -EBUSY;
1798 }
1799 if (get_user(xarg, p)) {
1800 mutex_unlock(&tu->tread_sem);
1801 return -EFAULT;
1802 }
1803 tu->tread = xarg ? 1 : 0;
1804 mutex_unlock(&tu->tread_sem);
1805 return 0;
1806 }
1807 case SNDRV_TIMER_IOCTL_GINFO:
1808 return snd_timer_user_ginfo(file, argp);
1809 case SNDRV_TIMER_IOCTL_GPARAMS:
1810 return snd_timer_user_gparams(file, argp);
1811 case SNDRV_TIMER_IOCTL_GSTATUS:
1812 return snd_timer_user_gstatus(file, argp);
1813 case SNDRV_TIMER_IOCTL_SELECT:
1814 return snd_timer_user_tselect(file, argp);
1815 case SNDRV_TIMER_IOCTL_INFO:
1816 return snd_timer_user_info(file, argp);
1817 case SNDRV_TIMER_IOCTL_PARAMS:
1818 return snd_timer_user_params(file, argp);
1819 case SNDRV_TIMER_IOCTL_STATUS:
1820 return snd_timer_user_status(file, argp);
1821 case SNDRV_TIMER_IOCTL_START:
1822 case SNDRV_TIMER_IOCTL_START_OLD:
1823 return snd_timer_user_start(file);
1824 case SNDRV_TIMER_IOCTL_STOP:
1825 case SNDRV_TIMER_IOCTL_STOP_OLD:
1826 return snd_timer_user_stop(file);
1827 case SNDRV_TIMER_IOCTL_CONTINUE:
1828 case SNDRV_TIMER_IOCTL_CONTINUE_OLD:
1829 return snd_timer_user_continue(file);
1830 case SNDRV_TIMER_IOCTL_PAUSE:
1831 case SNDRV_TIMER_IOCTL_PAUSE_OLD:
1832 return snd_timer_user_pause(file);
1833 }
1834 return -ENOTTY;
1835}
1836
1837static int snd_timer_user_fasync(int fd, struct file * file, int on)
1838{
1839 struct snd_timer_user *tu;
1840 int err;
1841
1842 tu = file->private_data;
1843 err = fasync_helper(fd, file, on, &tu->fasync);
1844 if (err < 0)
1845 return err;
1846 return 0;
1847}
1848
1849static ssize_t snd_timer_user_read(struct file *file, char __user *buffer,
1850 size_t count, loff_t *offset)
1851{
1852 struct snd_timer_user *tu;
1853 long result = 0, unit;
1854 int err = 0;
1855
1856 tu = file->private_data;
1857 unit = tu->tread ? sizeof(struct snd_timer_tread) : sizeof(struct snd_timer_read);
1858 spin_lock_irq(&tu->qlock);
1859 while ((long)count - result >= unit) {
1860 while (!tu->qused) {
1861 wait_queue_t wait;
1862
1863 if ((file->f_flags & O_NONBLOCK) != 0 || result > 0) {
1864 err = -EAGAIN;
1865 break;
1866 }
1867
1868 set_current_state(TASK_INTERRUPTIBLE);
1869 init_waitqueue_entry(&wait, current);
1870 add_wait_queue(&tu->qchange_sleep, &wait);
1871
1872 spin_unlock_irq(&tu->qlock);
1873 schedule();
1874 spin_lock_irq(&tu->qlock);
1875
1876 remove_wait_queue(&tu->qchange_sleep, &wait);
1877
1878 if (signal_pending(current)) {
1879 err = -ERESTARTSYS;
1880 break;
1881 }
1882 }
1883
1884 spin_unlock_irq(&tu->qlock);
1885 if (err < 0)
1886 goto _error;
1887
1888 if (tu->tread) {
1889 if (copy_to_user(buffer, &tu->tqueue[tu->qhead++],
1890 sizeof(struct snd_timer_tread))) {
1891 err = -EFAULT;
1892 goto _error;
1893 }
1894 } else {
1895 if (copy_to_user(buffer, &tu->queue[tu->qhead++],
1896 sizeof(struct snd_timer_read))) {
1897 err = -EFAULT;
1898 goto _error;
1899 }
1900 }
1901
1902 tu->qhead %= tu->queue_size;
1903
1904 result += unit;
1905 buffer += unit;
1906
1907 spin_lock_irq(&tu->qlock);
1908 tu->qused--;
1909 }
1910 spin_unlock_irq(&tu->qlock);
1911 _error:
1912 return result > 0 ? result : err;
1913}
1914
1915static unsigned int snd_timer_user_poll(struct file *file, poll_table * wait)
1916{
1917 unsigned int mask;
1918 struct snd_timer_user *tu;
1919
1920 tu = file->private_data;
1921
1922 poll_wait(file, &tu->qchange_sleep, wait);
1923
1924 mask = 0;
1925 if (tu->qused)
1926 mask |= POLLIN | POLLRDNORM;
1927
1928 return mask;
1929}
1930
1931#ifdef CONFIG_COMPAT
1932#include "timer_compat.c"
1933#else
1934#define snd_timer_user_ioctl_compat NULL
1935#endif
1936
1937#ifndef CONFIG_SND_HAVE_NEW_IOCTL
1938/* need to unlock BKL to allow preemption */
1939static int snd_timer_user_ioctl_old(struct inode *inode, struct file * file,
1940 unsigned int cmd, unsigned long arg)
1941{
1942 int err;
1943 err = snd_timer_user_ioctl(file, cmd, arg);
1944 return err;
1945}
1946#endif
1947
1948#ifndef TARGET_OS2
1949static const struct file_operations snd_timer_f_ops =
1950#else
1951static struct file_operations snd_timer_f_ops =
1952#endif
1953{
1954#ifndef TARGET_OS2
1955 .owner = THIS_MODULE,
1956#endif
1957 .read = snd_timer_user_read,
1958 .open = snd_timer_user_open,
1959 .release = snd_timer_user_release,
1960 .poll = snd_timer_user_poll,
1961#ifdef CONFIG_SND_HAVE_NEW_IOCTL
1962 .unlocked_ioctl = snd_timer_user_ioctl,
1963 .compat_ioctl = snd_timer_user_ioctl_compat,
1964#else
1965 .ioctl = snd_timer_user_ioctl_old,
1966#endif
1967 .fasync = snd_timer_user_fasync,
1968};
1969
1970/*
1971 * ENTRY functions
1972 */
1973
1974static int __init alsa_timer_init(void)
1975{
1976 int err;
1977
1978#ifdef SNDRV_OSS_INFO_DEV_TIMERS
1979 snd_oss_info_register(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1,
1980 "system timer");
1981#endif
1982
1983 if ((err = snd_timer_register_system()) < 0)
1984 snd_printk(KERN_ERR "unable to register system timer (%i)\n",
1985 err);
1986 if ((err = snd_register_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0,
1987 &snd_timer_f_ops, NULL, "timer")) < 0)
1988 snd_printk(KERN_ERR "unable to register timer device (%i)\n",
1989 err);
1990 snd_timer_proc_init();
1991 return 0;
1992}
1993
1994static void __exit alsa_timer_exit(void)
1995{
1996 struct list_head *p, *n;
1997
1998 snd_unregister_device(SNDRV_DEVICE_TYPE_TIMER, NULL, 0);
1999 /* unregister the system timer */
2000 list_for_each_safe(p, n, &snd_timer_list) {
2001 struct snd_timer *timer = list_entry(p, struct snd_timer, device_list);
2002 snd_timer_free(timer);
2003 }
2004 snd_timer_proc_done();
2005#ifdef SNDRV_OSS_INFO_DEV_TIMERS
2006 snd_oss_info_unregister(SNDRV_OSS_INFO_DEV_TIMERS, SNDRV_CARDS - 1);
2007#endif
2008}
2009
2010module_init(alsa_timer_init)
2011module_exit(alsa_timer_exit)
2012
2013EXPORT_SYMBOL(snd_timer_open);
2014EXPORT_SYMBOL(snd_timer_close);
2015EXPORT_SYMBOL(snd_timer_resolution);
2016EXPORT_SYMBOL(snd_timer_start);
2017EXPORT_SYMBOL(snd_timer_stop);
2018EXPORT_SYMBOL(snd_timer_continue);
2019EXPORT_SYMBOL(snd_timer_pause);
2020EXPORT_SYMBOL(snd_timer_new);
2021EXPORT_SYMBOL(snd_timer_notify);
2022EXPORT_SYMBOL(snd_timer_global_new);
2023EXPORT_SYMBOL(snd_timer_global_free);
2024EXPORT_SYMBOL(snd_timer_global_register);
2025EXPORT_SYMBOL(snd_timer_interrupt);
Note: See TracBrowser for help on using the repository browser.