Lines Matching refs:timer

128 static int snd_timer_free(struct snd_timer *timer);
133 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left);
176 struct snd_timer *timer; in snd_timer_find() local
178 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_find()
179 if (timer->tmr_class != tid->dev_class) in snd_timer_find()
181 if ((timer->tmr_class == SNDRV_TIMER_CLASS_CARD || in snd_timer_find()
182 timer->tmr_class == SNDRV_TIMER_CLASS_PCM) && in snd_timer_find()
183 (timer->card == NULL || in snd_timer_find()
184 timer->card->number != tid->card)) in snd_timer_find()
186 if (timer->tmr_device != tid->device) in snd_timer_find()
188 if (timer->tmr_subdevice != tid->subdevice) in snd_timer_find()
190 return timer; in snd_timer_find()
223 if (master->timer->num_instances >= master->timer->max_instances) in check_matching_master_slave()
226 master->timer->num_instances++; in check_matching_master_slave()
228 spin_lock(&master->timer->lock); in check_matching_master_slave()
230 slave->timer = master->timer; in check_matching_master_slave()
233 spin_unlock(&master->timer->lock); in check_matching_master_slave()
246 struct snd_timer *timer; in snd_timer_check_slave() local
251 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_check_slave()
252 list_for_each_entry(master, &timer->open_list_head, open_list) { in snd_timer_check_slave()
293 struct snd_timer *timer; in snd_timer_open() local
321 timer = snd_timer_find(tid); in snd_timer_open()
323 if (!timer) { in snd_timer_open()
327 timer = snd_timer_find(tid); in snd_timer_open()
330 if (!timer) { in snd_timer_open()
334 if (!list_empty(&timer->open_list_head)) { in snd_timer_open()
336 list_entry(timer->open_list_head.next, in snd_timer_open()
343 if (timer->num_instances >= timer->max_instances) { in snd_timer_open()
347 if (!try_module_get(timer->module)) { in snd_timer_open()
352 if (timer->card) { in snd_timer_open()
353 get_device(&timer->card->card_dev); in snd_timer_open()
354 card_dev_to_put = &timer->card->card_dev; in snd_timer_open()
357 if (list_empty(&timer->open_list_head) && timer->hw.open) { in snd_timer_open()
358 err = timer->hw.open(timer); in snd_timer_open()
360 module_put(timer->module); in snd_timer_open()
365 timeri->timer = timer; in snd_timer_open()
369 list_add_tail(&timeri->open_list, &timer->open_list_head); in snd_timer_open()
370 timer->num_instances++; in snd_timer_open()
392 struct snd_timer *timer = timeri->timer; in snd_timer_close_locked() local
395 if (timer) { in snd_timer_close_locked()
396 spin_lock_irq(&timer->lock); in snd_timer_close_locked()
398 spin_unlock_irq(&timer->lock); in snd_timer_close_locked()
410 if (timer) { in snd_timer_close_locked()
411 timer->num_instances--; in snd_timer_close_locked()
413 spin_lock_irq(&timer->lock); in snd_timer_close_locked()
415 spin_unlock_irq(&timer->lock); in snd_timer_close_locked()
417 spin_lock_irq(&timer->lock); in snd_timer_close_locked()
419 spin_unlock_irq(&timer->lock); in snd_timer_close_locked()
423 spin_lock(&timer->lock); in snd_timer_close_locked()
424 timeri->timer = NULL; in snd_timer_close_locked()
428 timer->num_instances--; in snd_timer_close_locked()
430 slave->timer = NULL; in snd_timer_close_locked()
434 spin_unlock(&timer->lock); in snd_timer_close_locked()
439 timer = NULL; in snd_timer_close_locked()
442 if (timer) { in snd_timer_close_locked()
443 if (list_empty(&timer->open_list_head) && timer->hw.close) in snd_timer_close_locked()
444 timer->hw.close(timer); in snd_timer_close_locked()
446 if (timer->card) in snd_timer_close_locked()
447 *card_devp_to_put = &timer->card->card_dev; in snd_timer_close_locked()
448 module_put(timer->module); in snd_timer_close_locked()
471 static unsigned long snd_timer_hw_resolution(struct snd_timer *timer) in snd_timer_hw_resolution() argument
473 if (timer->hw.c_resolution) in snd_timer_hw_resolution()
474 return timer->hw.c_resolution(timer); in snd_timer_hw_resolution()
476 return timer->hw.resolution; in snd_timer_hw_resolution()
481 struct snd_timer * timer; in snd_timer_resolution() local
487 timer = timeri->timer; in snd_timer_resolution()
488 if (timer) { in snd_timer_resolution()
489 spin_lock_irqsave(&timer->lock, flags); in snd_timer_resolution()
490 ret = snd_timer_hw_resolution(timer); in snd_timer_resolution()
491 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_resolution()
499 struct snd_timer *timer = ti->timer; in snd_timer_notify1() local
511 if (timer && in snd_timer_notify1()
514 resolution = snd_timer_hw_resolution(timer); in snd_timer_notify1()
519 if (timer == NULL) in snd_timer_notify1()
521 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_notify1()
533 struct snd_timer *timer; in snd_timer_start1() local
537 timer = timeri->timer; in snd_timer_start1()
538 if (!timer) in snd_timer_start1()
541 spin_lock_irqsave(&timer->lock, flags); in snd_timer_start1()
546 if (timer->card && timer->card->shutdown) { in snd_timer_start1()
559 if (start && !(timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) { in snd_timer_start1()
560 if ((u64)snd_timer_hw_resolution(timer) * ticks < 100000) { in snd_timer_start1()
572 list_move_tail(&timeri->active_list, &timer->active_list_head); in snd_timer_start1()
573 if (timer->running) { in snd_timer_start1()
574 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_start1()
576 timer->flags |= SNDRV_TIMER_FLG_RESCHED; in snd_timer_start1()
581 timer->sticks = ticks; in snd_timer_start1()
582 timer->hw.start(timer); in snd_timer_start1()
584 timer->running++; in snd_timer_start1()
591 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_start1()
612 if (timeri->master && timeri->timer) { in snd_timer_start_slave()
613 spin_lock(&timeri->timer->lock); in snd_timer_start_slave()
618 spin_unlock(&timeri->timer->lock); in snd_timer_start_slave()
629 struct snd_timer *timer; in snd_timer_stop1() local
633 timer = timeri->timer; in snd_timer_stop1()
634 if (!timer) in snd_timer_stop1()
636 spin_lock_irqsave(&timer->lock, flags); in snd_timer_stop1()
644 if (timer->card && timer->card->shutdown) in snd_timer_stop1()
651 !(--timer->running)) { in snd_timer_stop1()
652 timer->hw.stop(timer); in snd_timer_stop1()
653 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) { in snd_timer_stop1()
654 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in snd_timer_stop1()
655 snd_timer_reschedule(timer, 0); in snd_timer_stop1()
656 if (timer->flags & SNDRV_TIMER_FLG_CHANGE) { in snd_timer_stop1()
657 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in snd_timer_stop1()
658 timer->hw.start(timer); in snd_timer_stop1()
670 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_stop1()
683 if (timeri->timer) { in snd_timer_stop_slave()
684 spin_lock(&timeri->timer->lock); in snd_timer_stop_slave()
690 spin_unlock(&timeri->timer->lock); in snd_timer_stop_slave()
758 static void snd_timer_reschedule(struct snd_timer * timer, unsigned long ticks_left) in snd_timer_reschedule() argument
763 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_reschedule()
767 timer->running++; in snd_timer_reschedule()
775 timer->flags &= ~SNDRV_TIMER_FLG_RESCHED; in snd_timer_reschedule()
778 if (ticks > timer->hw.ticks) in snd_timer_reschedule()
779 ticks = timer->hw.ticks; in snd_timer_reschedule()
781 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_reschedule()
782 timer->sticks = ticks; in snd_timer_reschedule()
786 static void snd_timer_process_callbacks(struct snd_timer *timer, in snd_timer_process_callbacks() argument
804 spin_unlock(&timer->lock); in snd_timer_process_callbacks()
807 spin_lock(&timer->lock); in snd_timer_process_callbacks()
814 static void snd_timer_clear_callbacks(struct snd_timer *timer, in snd_timer_clear_callbacks() argument
819 spin_lock_irqsave(&timer->lock, flags); in snd_timer_clear_callbacks()
822 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_clear_callbacks()
831 struct snd_timer *timer = container_of(work, struct snd_timer, task_work); in snd_timer_work() local
834 if (timer->card && timer->card->shutdown) { in snd_timer_work()
835 snd_timer_clear_callbacks(timer, &timer->sack_list_head); in snd_timer_work()
839 spin_lock_irqsave(&timer->lock, flags); in snd_timer_work()
840 snd_timer_process_callbacks(timer, &timer->sack_list_head); in snd_timer_work()
841 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_work()
850 void snd_timer_interrupt(struct snd_timer * timer, unsigned long ticks_left) in snd_timer_interrupt() argument
858 if (timer == NULL) in snd_timer_interrupt()
861 if (timer->card && timer->card->shutdown) { in snd_timer_interrupt()
862 snd_timer_clear_callbacks(timer, &timer->ack_list_head); in snd_timer_interrupt()
866 spin_lock_irqsave(&timer->lock, flags); in snd_timer_interrupt()
869 resolution = snd_timer_hw_resolution(timer); in snd_timer_interrupt()
876 list_for_each_entry_safe(ti, tmp, &timer->active_list_head, in snd_timer_interrupt()
894 --timer->running; in snd_timer_interrupt()
897 if ((timer->hw.flags & SNDRV_TIMER_HW_WORK) || in snd_timer_interrupt()
899 ack_list_head = &timer->ack_list_head; in snd_timer_interrupt()
901 ack_list_head = &timer->sack_list_head; in snd_timer_interrupt()
911 if (timer->flags & SNDRV_TIMER_FLG_RESCHED) in snd_timer_interrupt()
912 snd_timer_reschedule(timer, timer->sticks); in snd_timer_interrupt()
913 if (timer->running) { in snd_timer_interrupt()
914 if (timer->hw.flags & SNDRV_TIMER_HW_STOP) { in snd_timer_interrupt()
915 timer->hw.stop(timer); in snd_timer_interrupt()
916 timer->flags |= SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
918 if (!(timer->hw.flags & SNDRV_TIMER_HW_AUTO) || in snd_timer_interrupt()
919 (timer->flags & SNDRV_TIMER_FLG_CHANGE)) { in snd_timer_interrupt()
921 timer->flags &= ~SNDRV_TIMER_FLG_CHANGE; in snd_timer_interrupt()
922 timer->hw.start(timer); in snd_timer_interrupt()
925 timer->hw.stop(timer); in snd_timer_interrupt()
929 snd_timer_process_callbacks(timer, &timer->ack_list_head); in snd_timer_interrupt()
932 use_work = !list_empty(&timer->sack_list_head); in snd_timer_interrupt()
933 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_interrupt()
936 queue_work(system_highpri_wq, &timer->task_work); in snd_timer_interrupt()
947 struct snd_timer *timer; in snd_timer_new() local
964 timer = kzalloc(sizeof(*timer), GFP_KERNEL); in snd_timer_new()
965 if (!timer) in snd_timer_new()
967 timer->tmr_class = tid->dev_class; in snd_timer_new()
968 timer->card = card; in snd_timer_new()
969 timer->tmr_device = tid->device; in snd_timer_new()
970 timer->tmr_subdevice = tid->subdevice; in snd_timer_new()
972 strscpy(timer->id, id, sizeof(timer->id)); in snd_timer_new()
973 timer->sticks = 1; in snd_timer_new()
974 INIT_LIST_HEAD(&timer->device_list); in snd_timer_new()
975 INIT_LIST_HEAD(&timer->open_list_head); in snd_timer_new()
976 INIT_LIST_HEAD(&timer->active_list_head); in snd_timer_new()
977 INIT_LIST_HEAD(&timer->ack_list_head); in snd_timer_new()
978 INIT_LIST_HEAD(&timer->sack_list_head); in snd_timer_new()
979 spin_lock_init(&timer->lock); in snd_timer_new()
980 INIT_WORK(&timer->task_work, snd_timer_work); in snd_timer_new()
981 timer->max_instances = 1000; /* default limit per timer */ in snd_timer_new()
983 timer->module = card->module; in snd_timer_new()
984 err = snd_device_new(card, SNDRV_DEV_TIMER, timer, &ops); in snd_timer_new()
986 snd_timer_free(timer); in snd_timer_new()
991 *rtimer = timer; in snd_timer_new()
996 static int snd_timer_free(struct snd_timer *timer) in snd_timer_free() argument
998 if (!timer) in snd_timer_free()
1002 if (! list_empty(&timer->open_list_head)) { in snd_timer_free()
1005 pr_warn("ALSA: timer %p is busy?\n", timer); in snd_timer_free()
1006 list_for_each_safe(p, n, &timer->open_list_head) { in snd_timer_free()
1009 ti->timer = NULL; in snd_timer_free()
1012 list_del(&timer->device_list); in snd_timer_free()
1015 if (timer->private_free) in snd_timer_free()
1016 timer->private_free(timer); in snd_timer_free()
1017 kfree(timer); in snd_timer_free()
1023 struct snd_timer *timer = device->device_data; in snd_timer_dev_free() local
1024 return snd_timer_free(timer); in snd_timer_dev_free()
1029 struct snd_timer *timer = dev->device_data; in snd_timer_dev_register() local
1032 if (snd_BUG_ON(!timer || !timer->hw.start || !timer->hw.stop)) in snd_timer_dev_register()
1034 if (!(timer->hw.flags & SNDRV_TIMER_HW_SLAVE) && in snd_timer_dev_register()
1035 !timer->hw.resolution && timer->hw.c_resolution == NULL) in snd_timer_dev_register()
1040 if (timer1->tmr_class > timer->tmr_class) in snd_timer_dev_register()
1042 if (timer1->tmr_class < timer->tmr_class) in snd_timer_dev_register()
1044 if (timer1->card && timer->card) { in snd_timer_dev_register()
1045 if (timer1->card->number > timer->card->number) in snd_timer_dev_register()
1047 if (timer1->card->number < timer->card->number) in snd_timer_dev_register()
1050 if (timer1->tmr_device > timer->tmr_device) in snd_timer_dev_register()
1052 if (timer1->tmr_device < timer->tmr_device) in snd_timer_dev_register()
1054 if (timer1->tmr_subdevice > timer->tmr_subdevice) in snd_timer_dev_register()
1056 if (timer1->tmr_subdevice < timer->tmr_subdevice) in snd_timer_dev_register()
1062 list_add_tail(&timer->device_list, &timer1->device_list); in snd_timer_dev_register()
1069 struct snd_timer *timer = device->device_data; in snd_timer_dev_disconnect() local
1073 list_del_init(&timer->device_list); in snd_timer_dev_disconnect()
1075 list_for_each_entry(ti, &timer->open_list_head, open_list) { in snd_timer_dev_disconnect()
1083 void snd_timer_notify(struct snd_timer *timer, int event, struct timespec64 *tstamp) in snd_timer_notify() argument
1089 if (timer->card && timer->card->shutdown) in snd_timer_notify()
1091 if (! (timer->hw.flags & SNDRV_TIMER_HW_SLAVE)) in snd_timer_notify()
1096 spin_lock_irqsave(&timer->lock, flags); in snd_timer_notify()
1100 resolution = snd_timer_hw_resolution(timer); in snd_timer_notify()
1101 list_for_each_entry(ti, &timer->active_list_head, active_list) { in snd_timer_notify()
1108 spin_unlock_irqrestore(&timer->lock, flags); in snd_timer_notify()
1128 int snd_timer_global_free(struct snd_timer *timer) in snd_timer_global_free() argument
1130 return snd_timer_free(timer); in snd_timer_global_free()
1134 int snd_timer_global_register(struct snd_timer *timer) in snd_timer_global_register() argument
1139 dev.device_data = timer; in snd_timer_global_register()
1160 struct snd_timer *timer = priv->snd_timer; in snd_timer_s_function() local
1164 snd_timer_interrupt(timer, (long)jiff - (long)priv->last_jiffies); in snd_timer_s_function()
1167 static int snd_timer_s_start(struct snd_timer * timer) in snd_timer_s_start() argument
1172 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_start()
1174 if (priv->correction > timer->sticks - 1) { in snd_timer_s_start()
1175 priv->correction -= timer->sticks - 1; in snd_timer_s_start()
1178 njiff += timer->sticks - priv->correction; in snd_timer_s_start()
1186 static int snd_timer_s_stop(struct snd_timer * timer) in snd_timer_s_stop() argument
1191 priv = (struct snd_timer_system_private *) timer->private_data; in snd_timer_s_stop()
1195 timer->sticks = priv->last_expires - jiff; in snd_timer_s_stop()
1197 timer->sticks = 1; in snd_timer_s_stop()
1202 static int snd_timer_s_close(struct snd_timer *timer) in snd_timer_s_close() argument
1206 priv = (struct snd_timer_system_private *)timer->private_data; in snd_timer_s_close()
1221 static void snd_timer_free_system(struct snd_timer *timer) in snd_timer_free_system() argument
1223 kfree(timer->private_data); in snd_timer_free_system()
1228 struct snd_timer *timer; in snd_timer_register_system() local
1232 err = snd_timer_global_new("system", SNDRV_TIMER_GLOBAL_SYSTEM, &timer); in snd_timer_register_system()
1235 strcpy(timer->name, "system timer"); in snd_timer_register_system()
1236 timer->hw = snd_timer_system; in snd_timer_register_system()
1239 snd_timer_free(timer); in snd_timer_register_system()
1242 priv->snd_timer = timer; in snd_timer_register_system()
1244 timer->private_data = priv; in snd_timer_register_system()
1245 timer->private_free = snd_timer_free_system; in snd_timer_register_system()
1246 return snd_timer_global_register(timer); in snd_timer_register_system()
1257 struct snd_timer *timer; in snd_timer_proc_read() local
1262 list_for_each_entry(timer, &snd_timer_list, device_list) { in snd_timer_proc_read()
1263 if (timer->card && timer->card->shutdown) in snd_timer_proc_read()
1265 switch (timer->tmr_class) { in snd_timer_proc_read()
1267 snd_iprintf(buffer, "G%i: ", timer->tmr_device); in snd_timer_proc_read()
1271 timer->card->number, timer->tmr_device); in snd_timer_proc_read()
1274 snd_iprintf(buffer, "P%i-%i-%i: ", timer->card->number, in snd_timer_proc_read()
1275 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1278 snd_iprintf(buffer, "?%i-%i-%i-%i: ", timer->tmr_class, in snd_timer_proc_read()
1279 timer->card ? timer->card->number : -1, in snd_timer_proc_read()
1280 timer->tmr_device, timer->tmr_subdevice); in snd_timer_proc_read()
1282 snd_iprintf(buffer, "%s :", timer->name); in snd_timer_proc_read()
1283 spin_lock_irq(&timer->lock); in snd_timer_proc_read()
1284 resolution = snd_timer_hw_resolution(timer); in snd_timer_proc_read()
1285 spin_unlock_irq(&timer->lock); in snd_timer_proc_read()
1290 timer->hw.ticks); in snd_timer_proc_read()
1291 if (timer->hw.flags & SNDRV_TIMER_HW_SLAVE) in snd_timer_proc_read()
1294 list_for_each_entry(ti, &timer->open_list_head, open_list) in snd_timer_proc_read()
1555 static void snd_timer_user_copy_id(struct snd_timer_id *id, struct snd_timer *timer) in snd_timer_user_copy_id() argument
1557 id->dev_class = timer->tmr_class; in snd_timer_user_copy_id()
1559 id->card = timer->card ? timer->card->number : -1; in snd_timer_user_copy_id()
1560 id->device = timer->tmr_device; in snd_timer_user_copy_id()
1561 id->subdevice = timer->tmr_subdevice; in snd_timer_user_copy_id()
1567 struct snd_timer *timer; in snd_timer_user_next_device() local
1577 timer = list_entry(snd_timer_list.next, in snd_timer_user_next_device()
1579 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1586 timer = list_entry(p, struct snd_timer, device_list); in snd_timer_user_next_device()
1587 if (timer->tmr_class > SNDRV_TIMER_CLASS_GLOBAL) { in snd_timer_user_next_device()
1588 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1591 if (timer->tmr_device >= id.device) { in snd_timer_user_next_device()
1592 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1614 timer = list_entry(p, struct snd_timer, device_list); in snd_timer_user_next_device()
1615 if (timer->tmr_class > id.dev_class) { in snd_timer_user_next_device()
1616 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1619 if (timer->tmr_class < id.dev_class) in snd_timer_user_next_device()
1621 if (timer->card->number > id.card) { in snd_timer_user_next_device()
1622 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1625 if (timer->card->number < id.card) in snd_timer_user_next_device()
1627 if (timer->tmr_device > id.device) { in snd_timer_user_next_device()
1628 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1631 if (timer->tmr_device < id.device) in snd_timer_user_next_device()
1633 if (timer->tmr_subdevice > id.subdevice) { in snd_timer_user_next_device()
1634 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1637 if (timer->tmr_subdevice < id.subdevice) in snd_timer_user_next_device()
1639 snd_timer_user_copy_id(&id, timer); in snd_timer_user_next_device()
1824 t = tu->timeri->timer; in snd_timer_user_info()
1856 t = tu->timeri->timer; in snd_timer_user_params()
2308 struct snd_timer *timer, *n; in snd_timer_free_all() local
2310 list_for_each_entry_safe(timer, n, &snd_timer_list, device_list) in snd_timer_free_all()
2311 snd_timer_free(timer); in snd_timer_free_all()