Lines Matching refs:cdev
30 #define MAKE_CHECKBYTE(cdev,stream,i) \ argument
31 (stream << 1) | (~(i / (cdev->n_streams * BYTES_PER_SAMPLE_USB)) & 1)
51 activate_substream(struct snd_usb_caiaqdev *cdev, in activate_substream() argument
54 spin_lock(&cdev->spinlock); in activate_substream()
57 cdev->sub_playback[sub->number] = sub; in activate_substream()
59 cdev->sub_capture[sub->number] = sub; in activate_substream()
61 spin_unlock(&cdev->spinlock); in activate_substream()
65 deactivate_substream(struct snd_usb_caiaqdev *cdev, in deactivate_substream() argument
69 spin_lock_irqsave(&cdev->spinlock, flags); in deactivate_substream()
72 cdev->sub_playback[sub->number] = NULL; in deactivate_substream()
74 cdev->sub_capture[sub->number] = NULL; in deactivate_substream()
76 spin_unlock_irqrestore(&cdev->spinlock, flags); in deactivate_substream()
89 static int stream_start(struct snd_usb_caiaqdev *cdev) in stream_start() argument
92 struct device *dev = caiaqdev_to_dev(cdev); in stream_start()
94 dev_dbg(dev, "%s(%p)\n", __func__, cdev); in stream_start()
96 if (cdev->streaming) in stream_start()
99 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback)); in stream_start()
100 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture)); in stream_start()
101 cdev->input_panic = 0; in stream_start()
102 cdev->output_panic = 0; in stream_start()
103 cdev->first_packet = 4; in stream_start()
104 cdev->streaming = 1; in stream_start()
105 cdev->warned = 0; in stream_start()
108 ret = usb_submit_urb(cdev->data_urbs_in[i], GFP_ATOMIC); in stream_start()
112 cdev->streaming = 0; in stream_start()
120 static void stream_stop(struct snd_usb_caiaqdev *cdev) in stream_stop() argument
123 struct device *dev = caiaqdev_to_dev(cdev); in stream_stop()
125 dev_dbg(dev, "%s(%p)\n", __func__, cdev); in stream_stop()
126 if (!cdev->streaming) in stream_stop()
129 cdev->streaming = 0; in stream_stop()
132 usb_kill_urb(cdev->data_urbs_in[i]); in stream_stop()
134 if (test_bit(i, &cdev->outurb_active_mask)) in stream_stop()
135 usb_kill_urb(cdev->data_urbs_out[i]); in stream_stop()
138 cdev->outurb_active_mask = 0; in stream_stop()
143 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream); in snd_usb_caiaq_substream_open() local
144 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_substream_open()
147 substream->runtime->hw = cdev->pcm_info; in snd_usb_caiaq_substream_open()
155 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream); in snd_usb_caiaq_substream_close() local
156 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_substream_close()
159 if (all_substreams_zero(cdev->sub_playback) && in snd_usb_caiaq_substream_close()
160 all_substreams_zero(cdev->sub_capture)) { in snd_usb_caiaq_substream_close()
163 stream_stop(cdev); in snd_usb_caiaq_substream_close()
164 cdev->pcm_info.rates = cdev->samplerates; in snd_usb_caiaq_substream_close()
172 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub); in snd_usb_caiaq_pcm_hw_free() local
173 deactivate_substream(cdev, sub); in snd_usb_caiaq_pcm_hw_free()
189 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(substream); in snd_usb_caiaq_pcm_prepare() local
191 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_pcm_prepare()
198 switch (cdev->spec.data_alignment) { in snd_usb_caiaq_pcm_prepare()
209 cdev->period_out_count[index] = out_pos; in snd_usb_caiaq_pcm_prepare()
210 cdev->audio_out_buf_pos[index] = out_pos; in snd_usb_caiaq_pcm_prepare()
214 switch (cdev->spec.data_alignment) { in snd_usb_caiaq_pcm_prepare()
227 cdev->period_in_count[index] = in_pos; in snd_usb_caiaq_pcm_prepare()
228 cdev->audio_in_buf_pos[index] = in_pos; in snd_usb_caiaq_pcm_prepare()
231 if (cdev->streaming) in snd_usb_caiaq_pcm_prepare()
238 cdev->pcm_info.rates = 1 << i; in snd_usb_caiaq_pcm_prepare()
243 if (cdev->spec.data_alignment >= 2) in snd_usb_caiaq_pcm_prepare()
247 * bytes_per_sample * CHANNELS_PER_STREAM * cdev->n_streams; in snd_usb_caiaq_pcm_prepare()
252 ret = snd_usb_caiaq_set_audio_params(cdev, runtime->rate, in snd_usb_caiaq_pcm_prepare()
257 ret = stream_start(cdev); in snd_usb_caiaq_pcm_prepare()
261 cdev->output_running = 0; in snd_usb_caiaq_pcm_prepare()
262 wait_event_timeout(cdev->prepare_wait_queue, cdev->output_running, HZ); in snd_usb_caiaq_pcm_prepare()
263 if (!cdev->output_running) { in snd_usb_caiaq_pcm_prepare()
264 stream_stop(cdev); in snd_usb_caiaq_pcm_prepare()
273 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub); in snd_usb_caiaq_pcm_trigger() local
274 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_pcm_trigger()
281 activate_substream(cdev, sub); in snd_usb_caiaq_pcm_trigger()
285 deactivate_substream(cdev, sub); in snd_usb_caiaq_pcm_trigger()
298 struct snd_usb_caiaqdev *cdev = snd_pcm_substream_chip(sub); in snd_usb_caiaq_pcm_pointer() local
301 spin_lock(&cdev->spinlock); in snd_usb_caiaq_pcm_pointer()
303 if (cdev->input_panic || cdev->output_panic) { in snd_usb_caiaq_pcm_pointer()
310 cdev->audio_out_buf_pos[index]); in snd_usb_caiaq_pcm_pointer()
313 cdev->audio_in_buf_pos[index]); in snd_usb_caiaq_pcm_pointer()
316 spin_unlock(&cdev->spinlock); in snd_usb_caiaq_pcm_pointer()
330 static void check_for_elapsed_periods(struct snd_usb_caiaqdev *cdev, in check_for_elapsed_periods() argument
336 for (stream = 0; stream < cdev->n_streams; stream++) { in check_for_elapsed_periods()
343 &cdev->period_out_count[stream] : in check_for_elapsed_periods()
344 &cdev->period_in_count[stream]; in check_for_elapsed_periods()
353 static void read_in_urb_mode0(struct snd_usb_caiaqdev *cdev, in read_in_urb_mode0() argument
361 if (all_substreams_zero(cdev->sub_capture)) in read_in_urb_mode0()
365 for (stream = 0; stream < cdev->n_streams; stream++, i++) { in read_in_urb_mode0()
366 sub = cdev->sub_capture[stream]; in read_in_urb_mode0()
371 audio_buf[cdev->audio_in_buf_pos[stream]++] in read_in_urb_mode0()
373 cdev->period_in_count[stream]++; in read_in_urb_mode0()
374 if (cdev->audio_in_buf_pos[stream] == sz) in read_in_urb_mode0()
375 cdev->audio_in_buf_pos[stream] = 0; in read_in_urb_mode0()
381 static void read_in_urb_mode2(struct snd_usb_caiaqdev *cdev, in read_in_urb_mode2() argument
391 if (i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { in read_in_urb_mode2()
393 stream < cdev->n_streams; in read_in_urb_mode2()
395 if (cdev->first_packet) in read_in_urb_mode2()
398 check_byte = MAKE_CHECKBYTE(cdev, stream, i); in read_in_urb_mode2()
401 cdev->input_panic = 1; in read_in_urb_mode2()
404 cdev->output_panic = 1; in read_in_urb_mode2()
407 cdev->first_packet = 0; in read_in_urb_mode2()
409 for (stream = 0; stream < cdev->n_streams; stream++, i++) { in read_in_urb_mode2()
410 sub = cdev->sub_capture[stream]; in read_in_urb_mode2()
411 if (cdev->input_panic) in read_in_urb_mode2()
418 audio_buf[cdev->audio_in_buf_pos[stream]++] = in read_in_urb_mode2()
420 cdev->period_in_count[stream]++; in read_in_urb_mode2()
421 if (cdev->audio_in_buf_pos[stream] == sz) in read_in_urb_mode2()
422 cdev->audio_in_buf_pos[stream] = 0; in read_in_urb_mode2()
428 static void read_in_urb_mode3(struct snd_usb_caiaqdev *cdev, in read_in_urb_mode3() argument
433 struct device *dev = caiaqdev_to_dev(cdev); in read_in_urb_mode3()
441 for (stream = 0; stream < cdev->n_streams; stream++) { in read_in_urb_mode3()
442 struct snd_pcm_substream *sub = cdev->sub_capture[stream]; in read_in_urb_mode3()
446 if (sub && !cdev->input_panic) { in read_in_urb_mode3()
456 audio_buf[cdev->audio_in_buf_pos[stream]++] = usb_buf[i+n]; in read_in_urb_mode3()
458 if (cdev->audio_in_buf_pos[stream] == sz) in read_in_urb_mode3()
459 cdev->audio_in_buf_pos[stream] = 0; in read_in_urb_mode3()
462 cdev->period_in_count[stream] += BYTES_PER_SAMPLE; in read_in_urb_mode3()
468 !cdev->first_packet) { in read_in_urb_mode3()
469 if (!cdev->input_panic) in read_in_urb_mode3()
472 cdev->input_panic = 1; in read_in_urb_mode3()
480 if (cdev->first_packet > 0) in read_in_urb_mode3()
481 cdev->first_packet--; in read_in_urb_mode3()
484 static void read_in_urb(struct snd_usb_caiaqdev *cdev, in read_in_urb() argument
488 struct device *dev = caiaqdev_to_dev(cdev); in read_in_urb()
490 if (!cdev->streaming) in read_in_urb()
493 if (iso->actual_length < cdev->bpp) in read_in_urb()
496 switch (cdev->spec.data_alignment) { in read_in_urb()
498 read_in_urb_mode0(cdev, urb, iso); in read_in_urb()
501 read_in_urb_mode2(cdev, urb, iso); in read_in_urb()
504 read_in_urb_mode3(cdev, urb, iso); in read_in_urb()
508 if ((cdev->input_panic || cdev->output_panic) && !cdev->warned) { in read_in_urb()
510 cdev->input_panic ? "(input)" : "", in read_in_urb()
511 cdev->output_panic ? "(output)" : ""); in read_in_urb()
512 cdev->warned = 1; in read_in_urb()
516 static void fill_out_urb_mode_0(struct snd_usb_caiaqdev *cdev, in fill_out_urb_mode_0() argument
525 for (stream = 0; stream < cdev->n_streams; stream++, i++) { in fill_out_urb_mode_0()
526 sub = cdev->sub_playback[stream]; in fill_out_urb_mode_0()
532 audio_buf[cdev->audio_out_buf_pos[stream]]; in fill_out_urb_mode_0()
533 cdev->period_out_count[stream]++; in fill_out_urb_mode_0()
534 cdev->audio_out_buf_pos[stream]++; in fill_out_urb_mode_0()
535 if (cdev->audio_out_buf_pos[stream] == sz) in fill_out_urb_mode_0()
536 cdev->audio_out_buf_pos[stream] = 0; in fill_out_urb_mode_0()
542 if (cdev->spec.data_alignment == 2 && in fill_out_urb_mode_0()
543 i % (cdev->n_streams * BYTES_PER_SAMPLE_USB) == in fill_out_urb_mode_0()
544 (cdev->n_streams * CHANNELS_PER_STREAM)) in fill_out_urb_mode_0()
545 for (stream = 0; stream < cdev->n_streams; stream++, i++) in fill_out_urb_mode_0()
546 usb_buf[i] = MAKE_CHECKBYTE(cdev, stream, i); in fill_out_urb_mode_0()
550 static void fill_out_urb_mode_3(struct snd_usb_caiaqdev *cdev, in fill_out_urb_mode_3() argument
558 for (stream = 0; stream < cdev->n_streams; stream++) { in fill_out_urb_mode_3()
559 struct snd_pcm_substream *sub = cdev->sub_playback[stream]; in fill_out_urb_mode_3()
572 usb_buf[i+n] = audio_buf[cdev->audio_out_buf_pos[stream]++]; in fill_out_urb_mode_3()
574 if (cdev->audio_out_buf_pos[stream] == sz) in fill_out_urb_mode_3()
575 cdev->audio_out_buf_pos[stream] = 0; in fill_out_urb_mode_3()
582 cdev->period_out_count[stream] += BYTES_PER_SAMPLE; in fill_out_urb_mode_3()
593 static inline void fill_out_urb(struct snd_usb_caiaqdev *cdev, in fill_out_urb() argument
597 switch (cdev->spec.data_alignment) { in fill_out_urb()
600 fill_out_urb_mode_0(cdev, urb, iso); in fill_out_urb()
603 fill_out_urb_mode_3(cdev, urb, iso); in fill_out_urb()
611 struct snd_usb_caiaqdev *cdev; in read_completed() local
621 cdev = info->cdev; in read_completed()
622 dev = caiaqdev_to_dev(cdev); in read_completed()
624 if (!cdev->streaming) in read_completed()
629 if (test_and_set_bit(i, &cdev->outurb_active_mask) == 0) { in read_completed()
630 out = cdev->data_urbs_out[i]; in read_completed()
652 spin_lock_irqsave(&cdev->spinlock, flags); in read_completed()
653 fill_out_urb(cdev, out, &out->iso_frame_desc[outframe]); in read_completed()
654 read_in_urb(cdev, urb, &urb->iso_frame_desc[frame]); in read_completed()
655 spin_unlock_irqrestore(&cdev->spinlock, flags); in read_completed()
656 check_for_elapsed_periods(cdev, cdev->sub_playback); in read_completed()
657 check_for_elapsed_periods(cdev, cdev->sub_capture); in read_completed()
669 clear_bit(oinfo->index, &cdev->outurb_active_mask); in read_completed()
687 struct snd_usb_caiaqdev *cdev = info->cdev; in write_completed() local
689 if (!cdev->output_running) { in write_completed()
690 cdev->output_running = 1; in write_completed()
691 wake_up(&cdev->prepare_wait_queue); in write_completed()
694 clear_bit(info->index, &cdev->outurb_active_mask); in write_completed()
697 static struct urb **alloc_urbs(struct snd_usb_caiaqdev *cdev, int dir, int *ret) in alloc_urbs() argument
701 struct usb_device *usb_dev = cdev->chip.dev; in alloc_urbs()
741 urbs[i]->context = &cdev->data_cb_info[i]; in alloc_urbs()
771 int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *cdev) in snd_usb_caiaq_audio_init() argument
774 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_audio_init()
776 cdev->n_audio_in = max(cdev->spec.num_analog_audio_in, in snd_usb_caiaq_audio_init()
777 cdev->spec.num_digital_audio_in) / in snd_usb_caiaq_audio_init()
779 cdev->n_audio_out = max(cdev->spec.num_analog_audio_out, in snd_usb_caiaq_audio_init()
780 cdev->spec.num_digital_audio_out) / in snd_usb_caiaq_audio_init()
782 cdev->n_streams = max(cdev->n_audio_in, cdev->n_audio_out); in snd_usb_caiaq_audio_init()
784 dev_dbg(dev, "cdev->n_audio_in = %d\n", cdev->n_audio_in); in snd_usb_caiaq_audio_init()
785 dev_dbg(dev, "cdev->n_audio_out = %d\n", cdev->n_audio_out); in snd_usb_caiaq_audio_init()
786 dev_dbg(dev, "cdev->n_streams = %d\n", cdev->n_streams); in snd_usb_caiaq_audio_init()
788 if (cdev->n_streams > MAX_STREAMS) { in snd_usb_caiaq_audio_init()
793 if (cdev->n_streams < 1) { in snd_usb_caiaq_audio_init()
794 dev_err(dev, "bogus number of streams: %d\n", cdev->n_streams); in snd_usb_caiaq_audio_init()
798 ret = snd_pcm_new(cdev->chip.card, cdev->product_name, 0, in snd_usb_caiaq_audio_init()
799 cdev->n_audio_out, cdev->n_audio_in, &cdev->pcm); in snd_usb_caiaq_audio_init()
806 cdev->pcm->private_data = cdev; in snd_usb_caiaq_audio_init()
807 strscpy(cdev->pcm->name, cdev->product_name, sizeof(cdev->pcm->name)); in snd_usb_caiaq_audio_init()
809 memset(cdev->sub_playback, 0, sizeof(cdev->sub_playback)); in snd_usb_caiaq_audio_init()
810 memset(cdev->sub_capture, 0, sizeof(cdev->sub_capture)); in snd_usb_caiaq_audio_init()
812 memcpy(&cdev->pcm_info, &snd_usb_caiaq_pcm_hardware, in snd_usb_caiaq_audio_init()
816 cdev->samplerates = cdev->pcm_info.rates; in snd_usb_caiaq_audio_init()
817 switch (cdev->chip.usb_id) { in snd_usb_caiaq_audio_init()
822 cdev->samplerates |= SNDRV_PCM_RATE_192000; in snd_usb_caiaq_audio_init()
828 cdev->samplerates |= SNDRV_PCM_RATE_88200; in snd_usb_caiaq_audio_init()
832 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_PLAYBACK, in snd_usb_caiaq_audio_init()
834 snd_pcm_set_ops(cdev->pcm, SNDRV_PCM_STREAM_CAPTURE, in snd_usb_caiaq_audio_init()
836 snd_pcm_set_managed_buffer_all(cdev->pcm, SNDRV_DMA_TYPE_VMALLOC, in snd_usb_caiaq_audio_init()
839 cdev->data_cb_info = in snd_usb_caiaq_audio_init()
843 if (!cdev->data_cb_info) in snd_usb_caiaq_audio_init()
846 cdev->outurb_active_mask = 0; in snd_usb_caiaq_audio_init()
847 BUILD_BUG_ON(N_URBS > (sizeof(cdev->outurb_active_mask) * 8)); in snd_usb_caiaq_audio_init()
850 cdev->data_cb_info[i].cdev = cdev; in snd_usb_caiaq_audio_init()
851 cdev->data_cb_info[i].index = i; in snd_usb_caiaq_audio_init()
854 cdev->data_urbs_in = alloc_urbs(cdev, SNDRV_PCM_STREAM_CAPTURE, &ret); in snd_usb_caiaq_audio_init()
856 kfree(cdev->data_cb_info); in snd_usb_caiaq_audio_init()
857 free_urbs(cdev->data_urbs_in); in snd_usb_caiaq_audio_init()
861 cdev->data_urbs_out = alloc_urbs(cdev, SNDRV_PCM_STREAM_PLAYBACK, &ret); in snd_usb_caiaq_audio_init()
863 kfree(cdev->data_cb_info); in snd_usb_caiaq_audio_init()
864 free_urbs(cdev->data_urbs_in); in snd_usb_caiaq_audio_init()
865 free_urbs(cdev->data_urbs_out); in snd_usb_caiaq_audio_init()
872 void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *cdev) in snd_usb_caiaq_audio_free() argument
874 struct device *dev = caiaqdev_to_dev(cdev); in snd_usb_caiaq_audio_free()
876 dev_dbg(dev, "%s(%p)\n", __func__, cdev); in snd_usb_caiaq_audio_free()
877 stream_stop(cdev); in snd_usb_caiaq_audio_free()
878 free_urbs(cdev->data_urbs_in); in snd_usb_caiaq_audio_free()
879 free_urbs(cdev->data_urbs_out); in snd_usb_caiaq_audio_free()
880 kfree(cdev->data_cb_info); in snd_usb_caiaq_audio_free()