Lines Matching refs:timer

91 static int snd_timer_free(struct snd_timer *timer);
96 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left);
103 struct snd_timer *timer) in snd_timer_instance_new() argument
120 timeri->timer = timer; in snd_timer_instance_new()
121 if (timer && !try_module_get(timer->module)) { in snd_timer_instance_new()
135 struct snd_timer *timer = NULL; in snd_timer_find() local
137 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_find()
138 if (timer->tmr_class != tid->dev_class) in snd_timer_find()
140 if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD || in snd_timer_find()
141 timer->tmr_class == SNDRV_TIMER_CLASS_PCM) && in snd_timer_find()
142 (timer->card == NULL || in snd_timer_find()
143 timer->card->number != tid->card)) in snd_timer_find()
145 if (timer->tmr_device != tid->device) in snd_timer_find()
147 if (timer->tmr_subdevice != tid->subdevice) in snd_timer_find()
149 return timer; in snd_timer_find()
183 struct snd_timer *timer; in snd_timer_check_slave() local
187 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_check_slave()
188 list_for_each_entry(master, &timer->open_list_head, open_list) { in snd_timer_check_slave()
195 slave->timer = master->timer; in snd_timer_check_slave()
219 spin_lock(&master->timer->lock); in snd_timer_check_master()
221 slave->timer = master->timer; in snd_timer_check_master()
225 spin_unlock(&master->timer->lock); in snd_timer_check_master()
239 struct snd_timer *timer; in snd_timer_open() local
268 timer = snd_timer_find(tid); in snd_timer_open()
270 if (!timer) { in snd_timer_open()
274 timer = snd_timer_find(tid); in snd_timer_open()
277 if (!timer) { in snd_timer_open()
281 if (!list_empty(&timer->open_list_head)) { in snd_timer_open()
282 timeri = list_entry(timer->open_list_head.next, in snd_timer_open()
289 timeri = snd_timer_instance_new(owner, timer); in snd_timer_open()
295 if (timer->card) in snd_timer_open()
296 get_device(&timer->card->card_dev); in snd_timer_open()
299 if (list_empty(&timer->open_list_head) && timer->hw.open) in snd_timer_open()
300 timer->hw.open(timer); in snd_timer_open()
301 list_add_tail(&timeri->open_list, &timer->open_list_head); in snd_timer_open()
315 struct snd_timer *timer = NULL; in snd_timer_close() local
337 timer = timeri->timer; in snd_timer_close()
338 if (snd_BUG_ON(!timer)) in snd_timer_close()
341 spin_lock_irq(&timer->lock); in snd_timer_close()
343 spin_unlock_irq(&timer->lock); in snd_timer_close()
345 spin_lock_irq(&timer->lock); in snd_timer_close()
347 spin_unlock_irq(&timer->lock); in snd_timer_close()
350 if (list_empty(&timer->open_list_head) && in snd_timer_close()
351 timer->hw.close) in snd_timer_close()
352 timer->hw.close(timer); in snd_timer_close()
355 spin_lock(&timer->lock); in snd_timer_close()
360 slave->timer = NULL; in snd_timer_close()
364 spin_unlock(&timer->lock); in snd_timer_close()
367 if (timer->card) in snd_timer_close()
368 put_device(&timer->card->card_dev); in snd_timer_close()
376 if (timer) in snd_timer_close()
377 module_put(timer->module); in snd_timer_close()
383 struct snd_timer * timer; in snd_timer_resolution() local
387 if ((timer = timeri->timer) != NULL) { in snd_timer_resolution()
388 if (timer->hw.c_resolution) in snd_timer_resolution()
389 return timer->hw.c_resolution(timer); in snd_timer_resolution()
390 return timer->hw.resolution; in snd_timer_resolution()
397 struct snd_timer *timer; in snd_timer_notify1() local
417 timer = ti->timer; in snd_timer_notify1()
418 if (timer == NULL) in snd_timer_notify1()
420 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_notify1()
422 spin_lock_irqsave(&timer->lock, flags); in snd_timer_notify1()
426 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_notify1()
429 static int snd_timer_start1(struct snd_timer *timer, struct snd_timer_instance *timeri, in snd_timer_start1() argument
432 list_move_tail(&timeri->active_list, &timer->active_list_head); in snd_timer_start1()
433 if (timer->running) { in snd_timer_start1()
434 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_start1()
436 timer->flags |= SNDRV_TIMER_FLG_RESCHED; in snd_timer_start1()
440 timer->sticks = sticks; in snd_timer_start1()
441 timer->hw.start(timer); in snd_timer_start1()
443 timer->running++; in snd_timer_start1()
459 if (timeri->master && timeri->timer) { in snd_timer_start_slave()
460 spin_lock(&timeri->timer->lock); in snd_timer_start_slave()
463 spin_unlock(&timeri->timer->lock); in snd_timer_start_slave()
474 struct snd_timer *timer; in snd_timer_start() local
486 timer = timeri->timer; in snd_timer_start()
487 if (timer == NULL) in snd_timer_start()
489 if (timer->card && timer->card->shutdown) in snd_timer_start()
491 spin_lock_irqsave(&timer->lock, flags); in snd_timer_start()
499 result = snd_timer_start1(timer, timeri, ticks); in snd_timer_start()
501 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_start()
509 struct snd_timer *timer; in _snd_timer_stop() local
521 if (timeri->timer) in _snd_timer_stop()
522 spin_lock(&timeri->timer->lock); in _snd_timer_stop()
526 if (timeri->timer) in _snd_timer_stop()
527 spin_unlock(&timeri->timer->lock); in _snd_timer_stop()
531 timer = timeri->timer; in _snd_timer_stop()
532 if (!timer) in _snd_timer_stop()
534 spin_lock_irqsave(&timer->lock, flags); in _snd_timer_stop()
537 spin_unlock_irqrestore(&timer->lock, flags); in _snd_timer_stop()
542 if (timer->card && timer->card->shutdown) { in _snd_timer_stop()
543 spin_unlock_irqrestore(&timer->lock, flags); in _snd_timer_stop()
547 !(--timer->running)) { in _snd_timer_stop()
548 timer->hw.stop(timer); in _snd_timer_stop()
549 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { in _snd_timer_stop()
550 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in _snd_timer_stop()
551 snd_timer_reschedule(timer, 0); in _snd_timer_stop()
552 if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { in _snd_timer_stop()
553 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in _snd_timer_stop()
554 timer->hw.start(timer); in _snd_timer_stop()
559 spin_unlock_irqrestore(&timer->lock, flags); in _snd_timer_stop()
573 struct snd_timer *timer; in snd_timer_stop() local
580 timer = timeri->timer; in snd_timer_stop()
581 if (!timer) in snd_timer_stop()
583 spin_lock_irqsave(&timer->lock, flags); in snd_timer_stop()
586 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_stop()
595 struct snd_timer *timer; in snd_timer_continue() local
603 timer = timeri->timer; in snd_timer_continue()
604 if (! timer) in snd_timer_continue()
606 if (timer->card && timer->card->shutdown) in snd_timer_continue()
608 spin_lock_irqsave(&timer->lock, flags); in snd_timer_continue()
616 result = snd_timer_start1(timer, timeri, timer->sticks); in snd_timer_continue()
618 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_continue()
637 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left) in snd_timer_reschedule() argument
642 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_reschedule()
646 timer->running++; in snd_timer_reschedule()
654 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in snd_timer_reschedule()
657 if (ticks > timer->hw.ticks) in snd_timer_reschedule()
658 ticks = timer->hw.ticks; in snd_timer_reschedule()
660 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_reschedule()
661 timer->sticks = ticks; in snd_timer_reschedule()
670 struct snd_timer *timer = (struct snd_timer *) arg; in snd_timer_tasklet() local
676 if (timer->card && timer->card->shutdown) in snd_timer_tasklet()
679 spin_lock_irqsave(&timer->lock, flags); in snd_timer_tasklet()
681 while (!list_empty(&timer->sack_list_head)) { in snd_timer_tasklet()
682 p = timer->sack_list_head.next; /* get first item */ in snd_timer_tasklet()
693 spin_unlock(&timer->lock); in snd_timer_tasklet()
696 spin_lock(&timer->lock); in snd_timer_tasklet()
699 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_tasklet()
708 void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) in snd_timer_interrupt() argument
716 if (timer == NULL) in snd_timer_interrupt()
719 if (timer->card && timer->card->shutdown) in snd_timer_interrupt()
722 spin_lock_irqsave(&timer->lock, flags); in snd_timer_interrupt()
725 if (timer->hw.c_resolution) in snd_timer_interrupt()
726 resolution = timer->hw.c_resolution(timer); in snd_timer_interrupt()
728 resolution = timer->hw.resolution; in snd_timer_interrupt()
735 list_for_each_entry_safe(ti, tmp, &timer->active_list_head, in snd_timer_interrupt()
751 --timer->running; in snd_timer_interrupt()
754 if ((timer->hw.flags & SNDRV_TIMER_HW_TASKLET) || in snd_timer_interrupt()
756 ack_list_head = &timer->ack_list_head; in snd_timer_interrupt()
758 ack_list_head = &timer->sack_list_head; in snd_timer_interrupt()
768 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) in snd_timer_interrupt()
769 snd_timer_reschedule(timer, timer->sticks); in snd_timer_interrupt()
770 if (timer->running) { in snd_timer_interrupt()
771 if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { in snd_timer_interrupt()
772 timer->hw.stop(timer); in snd_timer_interrupt()
773 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
775 if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || in snd_timer_interrupt()
776 (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { in snd_timer_interrupt()
778 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
779 timer->hw.start(timer); in snd_timer_interrupt()
782 timer->hw.stop(timer); in snd_timer_interrupt()
786 while (!list_empty(&timer->ack_list_head)) { in snd_timer_interrupt()
787 p = timer->ack_list_head.next; /* get first item */ in snd_timer_interrupt()
797 spin_unlock(&timer->lock); in snd_timer_interrupt()
800 spin_lock(&timer->lock); in snd_timer_interrupt()
805 use_tasklet = !list_empty(&timer->sack_list_head); in snd_timer_interrupt()
806 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_interrupt()
809 tasklet_schedule(&timer->task_queue); in snd_timer_interrupt()
819 struct snd_timer *timer; in snd_timer_new() local
831 timer = kzalloc(sizeof(*timer), GFP_KERNEL); in snd_timer_new()
832 if (!timer) in snd_timer_new()
834 timer->tmr_class = tid->dev_class; in snd_timer_new()
835 timer->card = card; in snd_timer_new()
836 timer->tmr_device = tid->device; in snd_timer_new()
837 timer->tmr_subdevice = tid->subdevice; in snd_timer_new()
839 strlcpy(timer->id, id, sizeof(timer->id)); in snd_timer_new()
840 INIT_LIST_HEAD(&timer->device_list); in snd_timer_new()
841 INIT_LIST_HEAD(&timer->open_list_head); in snd_timer_new()
842 INIT_LIST_HEAD(&timer->active_list_head); in snd_timer_new()
843 INIT_LIST_HEAD(&timer->ack_list_head); in snd_timer_new()
844 INIT_LIST_HEAD(&timer->sack_list_head); in snd_timer_new()
845 spin_lock_init(&timer->lock); in snd_timer_new()
846 tasklet_init(&timer->task_queue, snd_timer_tasklet, in snd_timer_new()
847 (unsigned long)timer); in snd_timer_new()
849 timer->module = card->module; in snd_timer_new()
850 err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops); in snd_timer_new()
852 snd_timer_free(timer); in snd_timer_new()
857 *rtimer = timer; in snd_timer_new()
861 static int snd_timer_free(struct snd_timer *timer) in snd_timer_free() argument
863 if (!timer) in snd_timer_free()
867 if (! list_empty(&timer->open_list_head)) { in snd_timer_free()
870 pr_warn("ALSA: timer %p is busy?\n", timer); in snd_timer_free()
871 list_for_each_safe(p, n, &timer->open_list_head) { in snd_timer_free()
874 ti->timer = NULL; in snd_timer_free()
877 list_del(&timer->device_list); in snd_timer_free()
880 if (timer->private_free) in snd_timer_free()
881 timer->private_free(timer); in snd_timer_free()
882 kfree(timer); in snd_timer_free()
888 struct snd_timer *timer = device->device_data; in snd_timer_dev_free() local
889 return snd_timer_free(timer); in snd_timer_dev_free()
894 struct snd_timer *timer = dev->device_data; in snd_timer_dev_register() local
897 if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop)) in snd_timer_dev_register()
899 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && in snd_timer_dev_register()
900 !timer->hw.resolution && timer->hw.c_resolution == NULL) in snd_timer_dev_register()
905 if (timer1->tmr_class > timer->tmr_class) in snd_timer_dev_register()
907 if (timer1->tmr_class < timer->tmr_class) in snd_timer_dev_register()
909 if (timer1->card && timer->card) { in snd_timer_dev_register()
910 if (timer1->card->number > timer->card->number) in snd_timer_dev_register()
912 if (timer1->card->number < timer->card->number) in snd_timer_dev_register()
915 if (timer1->tmr_device > timer->tmr_device) in snd_timer_dev_register()
917 if (timer1->tmr_device < timer->tmr_device) in snd_timer_dev_register()
919 if (timer1->tmr_subdevice > timer->tmr_subdevice) in snd_timer_dev_register()
921 if (timer1->tmr_subdevice < timer->tmr_subdevice) in snd_timer_dev_register()
927 list_add_tail(&timer->device_list, &timer1->device_list); in snd_timer_dev_register()
939 struct snd_timer *timer = device->device_data; in snd_timer_dev_disconnect() local
943 list_del_init(&timer->device_list); in snd_timer_dev_disconnect()
945 list_for_each_entry(ti, &timer->open_list_head, open_list) { in snd_timer_dev_disconnect()
958 void snd_timer_notify(struct snd_timer *timer, int event, struct timespec *tstamp) in snd_timer_notify() argument
964 if (timer->card && timer->card->shutdown) in snd_timer_notify()
966 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) in snd_timer_notify()
971 spin_lock_irqsave(&timer->lock, flags); in snd_timer_notify()
975 if (timer->hw.c_resolution) in snd_timer_notify()
976 resolution = timer->hw.c_resolution(timer); in snd_timer_notify()
978 resolution = timer->hw.resolution; in snd_timer_notify()
980 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_notify()
987 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_notify()
1005 int snd_timer_global_free(struct snd_timer *timer) in snd_timer_global_free() argument
1007 return snd_timer_free(timer); in snd_timer_global_free()
1010 int snd_timer_global_register(struct snd_timer *timer) in snd_timer_global_register() argument
1015 dev.device_data = timer; in snd_timer_global_register()
1032 struct snd_timer *timer = (struct snd_timer *)data; in snd_timer_s_function() local
1033 struct snd_timer_system_private *priv = timer->private_data; in snd_timer_s_function()
1037 snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies); in snd_timer_s_function()
1040 static int snd_timer_s_start(struct snd_timer * timer) in snd_timer_s_start() argument
1045 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_start()
1047 if (priv->correction > timer->sticks - 1) { in snd_timer_s_start()
1048 priv->correction -= timer->sticks - 1; in snd_timer_s_start()
1051 njiff += timer->sticks - priv->correction; in snd_timer_s_start()
1059 static int snd_timer_s_stop(struct snd_timer * timer) in snd_timer_s_stop() argument
1064 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_stop()
1068 timer->sticks = priv->last_expires - jiff; in snd_timer_s_stop()
1070 timer->sticks = 1; in snd_timer_s_stop()
1084 static void snd_timer_free_system(struct snd_timer *timer) in snd_timer_free_system() argument
1086 kfree(timer->private_data); in snd_timer_free_system()
1091 struct snd_timer *timer; in snd_timer_register_system() local
1095 err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer); in snd_timer_register_system()
1098 strcpy(timer->name, "system timer"); in snd_timer_register_system()
1099 timer->hw = snd_timer_system; in snd_timer_register_system()
1102 snd_timer_free(timer); in snd_timer_register_system()
1105 setup_timer(&priv->tlist, snd_timer_s_function, (unsigned long) timer); in snd_timer_register_system()
1106 timer->private_data = priv; in snd_timer_register_system()
1107 timer->private_free = snd_timer_free_system; in snd_timer_register_system()
1108 return snd_timer_global_register(timer); in snd_timer_register_system()
1119 struct snd_timer *timer; in snd_timer_proc_read() local
1123 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_proc_read()
1124 if (timer->card && timer->card->shutdown) in snd_timer_proc_read()
1126 switch (timer->tmr_class) { in snd_timer_proc_read()
1128 snd_iprintf(buffer, "G%i: ", timer->tmr_device); in snd_timer_proc_read()
1132 timer->card->number, timer->tmr_device); in snd_timer_proc_read()
1135 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, in snd_timer_proc_read()
1136 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1139 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, in snd_timer_proc_read()
1140 timer->card ? timer->card->number : -1, in snd_timer_proc_read()
1141 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1143 snd_iprintf(buffer, "%s :", timer->name); in snd_timer_proc_read()
1144 if (timer->hw.resolution) in snd_timer_proc_read()
1146 timer->hw.resolution / 1000, in snd_timer_proc_read()
1147 timer->hw.resolution % 1000, in snd_timer_proc_read()
1148 timer->hw.ticks); in snd_timer_proc_read()
1149 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_proc_read()
1152 list_for_each_entry(ti, &timer->open_list_head, open_list) in snd_timer_proc_read()
1372 static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer) in snd_timer_user_copy_id() argument
1374 id->dev_class = timer->tmr_class; in snd_timer_user_copy_id()
1376 id->card = timer->card ? timer->card->number : -1; in snd_timer_user_copy_id()
1377 id->device = timer->tmr_device; in snd_timer_user_copy_id()
1378 id->subdevice = timer->tmr_subdevice; in snd_timer_user_copy_id()
1384 struct snd_timer *timer; in snd_timer_user_next_device() local
1394 timer = list_entry(snd_timer_list.next, in snd_timer_user_next_device()
1396 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1403 timer = list_entry(p, struct snd_timer, device_list); in snd_timer_user_next_device()
1404 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { in snd_timer_user_next_device()
1405 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1408 if (timer->tmr_device >= id.device) { in snd_timer_user_next_device()
1409 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1436 timer = list_entry(p, struct snd_timer, device_list); in snd_timer_user_next_device()
1437 if (timer->tmr_class > id.dev_class) { in snd_timer_user_next_device()
1438 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1441 if (timer->tmr_class < id.dev_class) in snd_timer_user_next_device()
1443 if (timer->card->number > id.card) { in snd_timer_user_next_device()
1444 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1447 if (timer->card->number < id.card) in snd_timer_user_next_device()
1449 if (timer->tmr_device > id.device) { in snd_timer_user_next_device()
1450 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1453 if (timer->tmr_device < id.device) in snd_timer_user_next_device()
1455 if (timer->tmr_subdevice > id.subdevice) { in snd_timer_user_next_device()
1456 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1459 if (timer->tmr_subdevice < id.subdevice) in snd_timer_user_next_device()
1461 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1650 t = tu->timeri->timer; in snd_timer_user_info()
1682 t = tu->timeri->timer; in snd_timer_user_params()
2028 struct snd_timer *timer, *n; in snd_timer_free_all() local
2030 list_for_each_entry_safe(timer, n, &snd_timer_list, device_list) in snd_timer_free_all()
2031 snd_timer_free(timer); in snd_timer_free_all()