Lines Matching full:dpcm

72 	int (*open)(struct loopback_pcm *dpcm);
76 int (*start)(struct loopback_pcm *dpcm);
80 int (*stop)(struct loopback_pcm *dpcm);
82 int (*stop_sync)(struct loopback_pcm *dpcm);
84 int (*close_substream)(struct loopback_pcm *dpcm);
88 int (*close_cable)(struct loopback_pcm *dpcm);
94 void (*dpcm_info)(struct loopback_pcm *dpcm,
170 static inline unsigned int byte_pos(struct loopback_pcm *dpcm, unsigned int x) in byte_pos() argument
172 if (dpcm->pcm_rate_shift == NO_PITCH) { in byte_pos()
176 HZ * (unsigned long long)dpcm->pcm_rate_shift); in byte_pos()
178 return x - (x % dpcm->pcm_salign); in byte_pos()
181 static inline unsigned int frac_pos(struct loopback_pcm *dpcm, unsigned int x) in frac_pos() argument
183 if (dpcm->pcm_rate_shift == NO_PITCH) { /* no pitch */ in frac_pos()
186 x = div_u64(dpcm->pcm_rate_shift * (unsigned long long)x * HZ, in frac_pos()
192 static inline struct loopback_setup *get_setup(struct loopback_pcm *dpcm) in get_setup() argument
194 int device = dpcm->substream->pstr->pcm->device; in get_setup()
196 if (dpcm->substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in get_setup()
198 return &dpcm->loopback->setup[dpcm->substream->number][device]; in get_setup()
201 static inline unsigned int get_notify(struct loopback_pcm *dpcm) in get_notify() argument
203 return get_setup(dpcm)->notify; in get_notify()
206 static inline unsigned int get_rate_shift(struct loopback_pcm *dpcm) in get_rate_shift() argument
208 return get_setup(dpcm)->rate_shift; in get_rate_shift()
212 static int loopback_jiffies_timer_start(struct loopback_pcm *dpcm) in loopback_jiffies_timer_start() argument
215 unsigned int rate_shift = get_rate_shift(dpcm); in loopback_jiffies_timer_start()
217 if (rate_shift != dpcm->pcm_rate_shift) { in loopback_jiffies_timer_start()
218 dpcm->pcm_rate_shift = rate_shift; in loopback_jiffies_timer_start()
219 dpcm->period_size_frac = frac_pos(dpcm, dpcm->pcm_period_size); in loopback_jiffies_timer_start()
221 if (dpcm->period_size_frac <= dpcm->irq_pos) { in loopback_jiffies_timer_start()
222 dpcm->irq_pos %= dpcm->period_size_frac; in loopback_jiffies_timer_start()
223 dpcm->period_update_pending = 1; in loopback_jiffies_timer_start()
225 tick = dpcm->period_size_frac - dpcm->irq_pos; in loopback_jiffies_timer_start()
226 tick = DIV_ROUND_UP(tick, dpcm->pcm_bps); in loopback_jiffies_timer_start()
227 mod_timer(&dpcm->timer, jiffies + tick); in loopback_jiffies_timer_start()
233 static int loopback_snd_timer_start(struct loopback_pcm *dpcm) in loopback_snd_timer_start() argument
235 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_start()
250 pcm_err(dpcm->substream->pcm, in loopback_snd_timer_start()
262 static inline int loopback_jiffies_timer_stop(struct loopback_pcm *dpcm) in loopback_jiffies_timer_stop() argument
264 del_timer(&dpcm->timer); in loopback_jiffies_timer_stop()
265 dpcm->timer.expires = 0; in loopback_jiffies_timer_stop()
271 static int loopback_snd_timer_stop(struct loopback_pcm *dpcm) in loopback_snd_timer_stop() argument
273 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_stop()
282 pcm_err(dpcm->substream->pcm, in loopback_snd_timer_stop()
293 static inline int loopback_jiffies_timer_stop_sync(struct loopback_pcm *dpcm) in loopback_jiffies_timer_stop_sync() argument
295 del_timer_sync(&dpcm->timer); in loopback_jiffies_timer_stop_sync()
301 static int loopback_snd_timer_close_cable(struct loopback_pcm *dpcm) in loopback_snd_timer_close_cable() argument
303 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_close_cable()
394 static void loopback_active_notify(struct loopback_pcm *dpcm) in loopback_active_notify() argument
396 snd_ctl_notify(dpcm->loopback->card, in loopback_active_notify()
398 &get_setup(dpcm)->active_id); in loopback_active_notify()
404 struct loopback_pcm *dpcm = runtime->private_data; in loopback_trigger() local
405 struct loopback_cable *cable = dpcm->cable; in loopback_trigger()
413 dpcm->last_jiffies = jiffies; in loopback_trigger()
414 dpcm->pcm_rate_shift = 0; in loopback_trigger()
415 dpcm->last_drift = 0; in loopback_trigger()
419 err = cable->ops->start(dpcm); in loopback_trigger()
422 loopback_active_notify(dpcm); in loopback_trigger()
428 err = cable->ops->stop(dpcm); in loopback_trigger()
431 loopback_active_notify(dpcm); in loopback_trigger()
437 err = cable->ops->stop(dpcm); in loopback_trigger()
440 loopback_active_notify(dpcm); in loopback_trigger()
445 dpcm->last_jiffies = jiffies; in loopback_trigger()
447 err = cable->ops->start(dpcm); in loopback_trigger()
450 loopback_active_notify(dpcm); in loopback_trigger()
461 struct loopback_pcm *dpcm = runtime->private_data; in params_change() local
462 struct loopback_cable *cable = dpcm->cable; in params_change()
481 struct loopback_pcm *dpcm = runtime->private_data; in loopback_prepare() local
482 struct loopback_cable *cable = dpcm->cable; in loopback_prepare()
486 err = cable->ops->stop_sync(dpcm); in loopback_prepare()
497 dpcm->buf_pos = 0; in loopback_prepare()
498 dpcm->pcm_buffer_size = frames_to_bytes(runtime, runtime->buffer_size); in loopback_prepare()
499 dpcm->channel_buf_n = dpcm->pcm_buffer_size / runtime->channels; in loopback_prepare()
502 dpcm->silent_size = dpcm->pcm_buffer_size; in loopback_prepare()
507 dpcm->irq_pos = 0; in loopback_prepare()
508 dpcm->period_update_pending = 0; in loopback_prepare()
509 dpcm->pcm_bps = bps; in loopback_prepare()
510 dpcm->pcm_salign = salign; in loopback_prepare()
511 dpcm->pcm_period_size = frames_to_bytes(runtime, runtime->period_size); in loopback_prepare()
513 mutex_lock(&dpcm->loopback->cable_lock); in loopback_prepare()
515 (get_setup(dpcm)->notify && in loopback_prepare()
519 mutex_unlock(&dpcm->loopback->cable_lock); in loopback_prepare()
524 static void clear_capture_buf(struct loopback_pcm *dpcm, unsigned int bytes) in clear_capture_buf() argument
526 struct snd_pcm_runtime *runtime = dpcm->substream->runtime; in clear_capture_buf()
528 unsigned int dst_off = dpcm->buf_pos; in clear_capture_buf()
530 if (dpcm->silent_size >= dpcm->pcm_buffer_size) in clear_capture_buf()
532 if (dpcm->silent_size + bytes > dpcm->pcm_buffer_size) in clear_capture_buf()
533 bytes = dpcm->pcm_buffer_size - dpcm->silent_size; in clear_capture_buf()
537 if (dst_off + size > dpcm->pcm_buffer_size) in clear_capture_buf()
538 size = dpcm->pcm_buffer_size - dst_off; in clear_capture_buf()
542 dpcm->silent_size += size; in clear_capture_buf()
618 static inline unsigned int bytepos_delta(struct loopback_pcm *dpcm, in bytepos_delta() argument
624 last_pos = byte_pos(dpcm, dpcm->irq_pos); in bytepos_delta()
625 dpcm->irq_pos += jiffies_delta * dpcm->pcm_bps; in bytepos_delta()
626 delta = byte_pos(dpcm, dpcm->irq_pos) - last_pos; in bytepos_delta()
627 if (delta >= dpcm->last_drift) in bytepos_delta()
628 delta -= dpcm->last_drift; in bytepos_delta()
629 dpcm->last_drift = 0; in bytepos_delta()
630 if (dpcm->irq_pos >= dpcm->period_size_frac) { in bytepos_delta()
631 dpcm->irq_pos %= dpcm->period_size_frac; in bytepos_delta()
632 dpcm->period_update_pending = 1; in bytepos_delta()
637 static inline void bytepos_finish(struct loopback_pcm *dpcm, in bytepos_finish() argument
640 dpcm->buf_pos += delta; in bytepos_finish()
641 dpcm->buf_pos %= dpcm->pcm_buffer_size; in bytepos_finish()
702 struct loopback_pcm *dpcm = from_timer(dpcm, t, timer); in loopback_jiffies_timer_function() local
705 spin_lock_irqsave(&dpcm->cable->lock, flags); in loopback_jiffies_timer_function()
706 if (loopback_jiffies_timer_pos_update(dpcm->cable) & in loopback_jiffies_timer_function()
707 (1 << dpcm->substream->stream)) { in loopback_jiffies_timer_function()
708 loopback_jiffies_timer_start(dpcm); in loopback_jiffies_timer_function()
709 if (dpcm->period_update_pending) { in loopback_jiffies_timer_function()
710 dpcm->period_update_pending = 0; in loopback_jiffies_timer_function()
711 spin_unlock_irqrestore(&dpcm->cable->lock, flags); in loopback_jiffies_timer_function()
713 snd_pcm_period_elapsed(dpcm->substream); in loopback_jiffies_timer_function()
717 spin_unlock_irqrestore(&dpcm->cable->lock, flags); in loopback_jiffies_timer_function()
725 struct loopback_pcm *dpcm = runtime->private_data; in loopback_snd_timer_check_resolution() local
726 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_check_resolution()
742 pcm_err(dpcm->substream->pcm, in loopback_snd_timer_check_resolution()
881 static void loopback_jiffies_timer_dpcm_info(struct loopback_pcm *dpcm, in loopback_jiffies_timer_dpcm_info() argument
885 dpcm->period_update_pending); in loopback_jiffies_timer_dpcm_info()
886 snd_iprintf(buffer, " irq_pos:\t\t%u\n", dpcm->irq_pos); in loopback_jiffies_timer_dpcm_info()
887 snd_iprintf(buffer, " period_frac:\t%u\n", dpcm->period_size_frac); in loopback_jiffies_timer_dpcm_info()
889 dpcm->last_jiffies, jiffies); in loopback_jiffies_timer_dpcm_info()
890 snd_iprintf(buffer, " timer_expires:\t%lu\n", dpcm->timer.expires); in loopback_jiffies_timer_dpcm_info()
893 static void loopback_snd_timer_dpcm_info(struct loopback_pcm *dpcm, in loopback_snd_timer_dpcm_info() argument
896 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_dpcm_info()
909 struct loopback_pcm *dpcm = runtime->private_data; in loopback_pointer() local
912 spin_lock(&dpcm->cable->lock); in loopback_pointer()
913 if (dpcm->cable->ops->pos_update) in loopback_pointer()
914 dpcm->cable->ops->pos_update(dpcm->cable); in loopback_pointer()
915 pos = dpcm->buf_pos; in loopback_pointer()
916 spin_unlock(&dpcm->cable->lock); in loopback_pointer()
950 struct loopback_pcm *dpcm = runtime->private_data; in loopback_runtime_free() local
951 kfree(dpcm); in loopback_runtime_free()
957 struct loopback_pcm *dpcm = runtime->private_data; in loopback_hw_free() local
958 struct loopback_cable *cable = dpcm->cable; in loopback_hw_free()
960 mutex_lock(&dpcm->loopback->cable_lock); in loopback_hw_free()
962 mutex_unlock(&dpcm->loopback->cable_lock); in loopback_hw_free()
977 struct loopback_pcm *dpcm = rule->private; in rule_format() local
978 struct loopback_cable *cable = dpcm->cable; in rule_format()
982 mutex_lock(&dpcm->loopback->cable_lock); in rule_format()
985 mutex_unlock(&dpcm->loopback->cable_lock); in rule_format()
992 struct loopback_pcm *dpcm = rule->private; in rule_rate() local
993 struct loopback_cable *cable = dpcm->cable; in rule_rate()
996 mutex_lock(&dpcm->loopback->cable_lock); in rule_rate()
999 mutex_unlock(&dpcm->loopback->cable_lock); in rule_rate()
1008 struct loopback_pcm *dpcm = rule->private; in rule_channels() local
1009 struct loopback_cable *cable = dpcm->cable; in rule_channels()
1012 mutex_lock(&dpcm->loopback->cable_lock); in rule_channels()
1015 mutex_unlock(&dpcm->loopback->cable_lock); in rule_channels()
1024 struct loopback_pcm *dpcm = rule->private; in rule_period_bytes() local
1025 struct loopback_cable *cable = dpcm->cable; in rule_period_bytes()
1028 mutex_lock(&dpcm->loopback->cable_lock); in rule_period_bytes()
1031 mutex_unlock(&dpcm->loopback->cable_lock); in rule_period_bytes()
1053 struct loopback_pcm *dpcm = substream->runtime->private_data; in free_cable() local
1055 if (cable->ops && cable->ops->close_cable && dpcm) in free_cable()
1056 cable->ops->close_cable(dpcm); in free_cable()
1063 static int loopback_jiffies_timer_open(struct loopback_pcm *dpcm) in loopback_jiffies_timer_open() argument
1065 timer_setup(&dpcm->timer, loopback_jiffies_timer_function, 0); in loopback_jiffies_timer_open()
1143 static int loopback_snd_timer_open(struct loopback_pcm *dpcm) in loopback_snd_timer_open() argument
1151 struct loopback_cable *cable = dpcm->cable; in loopback_snd_timer_open()
1159 err = loopback_parse_timer_id(dpcm->loopback->timer_source, &tid); in loopback_snd_timer_open()
1161 pcm_err(dpcm->substream->pcm, in loopback_snd_timer_open()
1163 dpcm->loopback->timer_source, err); in loopback_snd_timer_open()
1167 cable->snd_timer.stream = dpcm->substream->stream; in loopback_snd_timer_open()
1170 timeri = snd_timer_instance_new(dpcm->loopback->card->id); in loopback_snd_timer_open()
1204 pcm_err(dpcm->substream->pcm, in loopback_snd_timer_open()
1235 struct loopback_pcm *dpcm; in loopback_open() local
1241 dpcm = kzalloc(sizeof(*dpcm), GFP_KERNEL); in loopback_open()
1242 if (!dpcm) { in loopback_open()
1246 dpcm->loopback = loopback; in loopback_open()
1247 dpcm->substream = substream; in loopback_open()
1264 dpcm->cable = cable; in loopback_open()
1265 runtime->private_data = dpcm; in loopback_open()
1268 err = cable->ops->open(dpcm); in loopback_open()
1280 rule_format, dpcm, in loopback_open()
1286 rule_rate, dpcm, in loopback_open()
1292 rule_channels, dpcm, in loopback_open()
1304 rule_period_bytes, dpcm, in loopback_open()
1310 /* loopback_runtime_free() has not to be called if kfree(dpcm) was in loopback_open()
1314 if (get_notify(dpcm)) in loopback_open()
1320 cable->streams[substream->stream] = dpcm; in loopback_open()
1326 kfree(dpcm); in loopback_open()
1335 struct loopback_pcm *dpcm = substream->runtime->private_data; in loopback_close() local
1338 if (dpcm->cable->ops->close_substream) in loopback_close()
1339 err = dpcm->cable->ops->close_substream(dpcm); in loopback_close()
1689 struct loopback_pcm *dpcm, in print_dpcm_info() argument
1693 if (dpcm == NULL) { in print_dpcm_info()
1697 snd_iprintf(buffer, " buffer_size:\t%u\n", dpcm->pcm_buffer_size); in print_dpcm_info()
1698 snd_iprintf(buffer, " buffer_pos:\t\t%u\n", dpcm->buf_pos); in print_dpcm_info()
1699 snd_iprintf(buffer, " silent_size:\t%u\n", dpcm->silent_size); in print_dpcm_info()
1700 snd_iprintf(buffer, " period_size:\t%u\n", dpcm->pcm_period_size); in print_dpcm_info()
1701 snd_iprintf(buffer, " bytes_per_sec:\t%u\n", dpcm->pcm_bps); in print_dpcm_info()
1702 snd_iprintf(buffer, " sample_align:\t%u\n", dpcm->pcm_salign); in print_dpcm_info()
1703 snd_iprintf(buffer, " rate_shift:\t\t%u\n", dpcm->pcm_rate_shift); in print_dpcm_info()
1704 if (dpcm->cable->ops->dpcm_info) in print_dpcm_info()
1705 dpcm->cable->ops->dpcm_info(dpcm, buffer); in print_dpcm_info()