Lines Matching +full:chip +full:- +full:to +full:- +full:chip

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 * IBL size, typically 126 samples. at each end of chunk, the end-of-buffer
15 * pipe->transferred is the counter of data which has been already transferred.
16 * if this counter reaches to the period size, snd_pcm_period_elapsed() will
20 * to get a low latency response, we'll check the capture streams at each
22 * data is accumulated to the period size, snd_pcm_period_elapsed() is
25 * the current point of read buffer is kept in pipe->hw_ptr. note that
29 * - linked trigger for full-duplex mode.
30 * - scheduled action on the stream.
45 static void vx_pcm_read_per_bytes(struct vx_core *chip, struct snd_pcm_runtime *runtime, in vx_pcm_read_per_bytes() argument
48 int offset = pipe->hw_ptr; in vx_pcm_read_per_bytes()
49 unsigned char *buf = (unsigned char *)(runtime->dma_area + offset); in vx_pcm_read_per_bytes()
50 *buf++ = vx_inb(chip, RXH); in vx_pcm_read_per_bytes()
51 if (++offset >= pipe->buffer_bytes) { in vx_pcm_read_per_bytes()
53 buf = (unsigned char *)runtime->dma_area; in vx_pcm_read_per_bytes()
55 *buf++ = vx_inb(chip, RXM); in vx_pcm_read_per_bytes()
56 if (++offset >= pipe->buffer_bytes) { in vx_pcm_read_per_bytes()
58 buf = (unsigned char *)runtime->dma_area; in vx_pcm_read_per_bytes()
60 *buf++ = vx_inb(chip, RXL); in vx_pcm_read_per_bytes()
61 if (++offset >= pipe->buffer_bytes) { in vx_pcm_read_per_bytes()
64 pipe->hw_ptr = offset; in vx_pcm_read_per_bytes()
68 * vx_set_pcx_time - convert from the PC time to the RMH status time.
69 * @pc_time: the pointer for the PC-time to set
72 static void vx_set_pcx_time(struct vx_core *chip, pcx_time_t *pc_time, in vx_set_pcx_time() argument
80 * vx_set_differed_time - set the differed time if specified
81 * @rmh: the rmh record to modify
82 * @pipe: the pipe to be checked
89 static int vx_set_differed_time(struct vx_core *chip, struct vx_rmh *rmh, in vx_set_differed_time() argument
92 /* Update The length added to the RMH command by the timestamp */ in vx_set_differed_time()
93 if (! (pipe->differed_type & DC_DIFFERED_DELAY)) in vx_set_differed_time()
97 rmh->Cmd[0] |= DSP_DIFFERED_COMMAND_MASK; in vx_set_differed_time()
100 vx_set_pcx_time(chip, &pipe->pcx_time, &rmh->Cmd[1]); in vx_set_differed_time()
102 /* Add the flags to a notified differed command */ in vx_set_differed_time()
103 if (pipe->differed_type & DC_NOTIFY_DELAY) in vx_set_differed_time()
104 rmh->Cmd[1] |= NOTIFY_MASK_TIME_HIGH ; in vx_set_differed_time()
106 /* Add the flags to a multiple differed command */ in vx_set_differed_time()
107 if (pipe->differed_type & DC_MULTIPLE_DELAY) in vx_set_differed_time()
108 rmh->Cmd[1] |= MULTIPLE_MASK_TIME_HIGH; in vx_set_differed_time()
110 /* Add the flags to a stream-time differed command */ in vx_set_differed_time()
111 if (pipe->differed_type & DC_STREAM_TIME_DELAY) in vx_set_differed_time()
112 rmh->Cmd[1] |= STREAM_MASK_TIME_HIGH; in vx_set_differed_time()
114 rmh->LgCmd += 2; in vx_set_differed_time()
119 * vx_set_stream_format - send the stream format command
123 static int vx_set_stream_format(struct vx_core *chip, struct vx_pipe *pipe, in vx_set_stream_format() argument
128 vx_init_rmh(&rmh, pipe->is_capture ? in vx_set_stream_format()
130 rmh.Cmd[0] |= pipe->number << FIELD_SIZE; in vx_set_stream_format()
132 /* Command might be longer since we may have to add a timestamp */ in vx_set_stream_format()
133 vx_set_differed_time(chip, &rmh, pipe); in vx_set_stream_format()
139 return vx_send_msg(chip, &rmh); in vx_set_stream_format()
144 * vx_set_format - set the format of a pipe
146 * @runtime: pcm runtime instance to be referred
150 static int vx_set_format(struct vx_core *chip, struct vx_pipe *pipe, in vx_set_format() argument
155 if (runtime->channels == 1) in vx_set_format()
157 if (snd_pcm_format_little_endian(runtime->format)) in vx_set_format()
159 if (runtime->rate < 32000 && runtime->rate > 11025) in vx_set_format()
161 else if (runtime->rate <= 11025) in vx_set_format()
164 switch (snd_pcm_format_physical_width(runtime->format)) { in vx_set_format()
170 return -EINVAL; in vx_set_format()
173 return vx_set_stream_format(chip, pipe, header); in vx_set_format()
179 static int vx_set_ibl(struct vx_core *chip, struct vx_ibl_info *info) in vx_set_ibl() argument
185 rmh.Cmd[0] |= info->size & 0x03ffff; in vx_set_ibl()
186 err = vx_send_msg(chip, &rmh); in vx_set_ibl()
189 info->size = rmh.Stat[0]; in vx_set_ibl()
190 info->max_size = rmh.Stat[1]; in vx_set_ibl()
191 info->min_size = rmh.Stat[2]; in vx_set_ibl()
192 info->granularity = rmh.Stat[3]; in vx_set_ibl()
194 info->size, info->max_size, info->min_size, info->granularity); in vx_set_ibl()
200 * vx_get_pipe_state - get the state of a pipe
201 * @pipe: the pipe to be checked
209 static int vx_get_pipe_state(struct vx_core *chip, struct vx_pipe *pipe, int *state) in vx_get_pipe_state() argument
215 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_get_pipe_state()
216 err = vx_send_msg(chip, &rmh); in vx_get_pipe_state()
218 *state = (rmh.Stat[0] & (1 << pipe->number)) ? 1 : 0; in vx_get_pipe_state()
224 * vx_query_hbuffer_size - query available h-buffer size in bytes
225 * @pipe: the pipe to be checked
227 * return the available size on h-buffer in bytes,
230 * NOTE: calling this function always switches to the stream mode.
231 * you'll need to disconnect the host to get back to the
234 static int vx_query_hbuffer_size(struct vx_core *chip, struct vx_pipe *pipe) in vx_query_hbuffer_size() argument
240 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_query_hbuffer_size()
241 if (pipe->is_capture) in vx_query_hbuffer_size()
243 result = vx_send_msg(chip, &rmh); in vx_query_hbuffer_size()
251 * vx_pipe_can_start - query whether a pipe is ready for start
252 * @pipe: the pipe to be checked
258 static int vx_pipe_can_start(struct vx_core *chip, struct vx_pipe *pipe) in vx_pipe_can_start() argument
264 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_pipe_can_start()
267 err = vx_send_msg(chip, &rmh); in vx_pipe_can_start()
276 * vx_conf_pipe - tell the pipe to stand by and wait for IRQA.
277 * @pipe: the pipe to be configured
279 static int vx_conf_pipe(struct vx_core *chip, struct vx_pipe *pipe) in vx_conf_pipe() argument
284 if (pipe->is_capture) in vx_conf_pipe()
286 rmh.Cmd[1] = 1 << pipe->number; in vx_conf_pipe()
287 return vx_send_msg(chip, &rmh); in vx_conf_pipe()
291 * vx_send_irqa - trigger IRQA
293 static int vx_send_irqa(struct vx_core *chip) in vx_send_irqa() argument
298 return vx_send_msg(chip, &rmh); in vx_send_irqa()
304 * vx boards do not support inter-card sync, besides
305 * only 126 samples require to be prepared before a pipe can start
311 * vx_toggle_pipe - start / pause a pipe
312 * @pipe: the pipe to be triggered
318 static int vx_toggle_pipe(struct vx_core *chip, struct vx_pipe *pipe, int state) in vx_toggle_pipe() argument
323 if (vx_get_pipe_state(chip, pipe, &cur_state) < 0) in vx_toggle_pipe()
324 return -EBADFD; in vx_toggle_pipe()
328 /* If a start is requested, ask the DSP to get prepared in vx_toggle_pipe()
334 err = vx_pipe_can_start(chip, pipe); in vx_toggle_pipe()
338 * to avoid flooding the DSP with our requests in vx_toggle_pipe()
344 err = vx_conf_pipe(chip, pipe); in vx_toggle_pipe()
348 err = vx_send_irqa(chip); in vx_toggle_pipe()
357 err = vx_get_pipe_state(chip, pipe, &cur_state); in vx_toggle_pipe()
360 err = -EIO; in vx_toggle_pipe()
363 return err < 0 ? -EIO : 0; in vx_toggle_pipe()
368 * vx_stop_pipe - stop a pipe
369 * @pipe: the pipe to be stopped
373 static int vx_stop_pipe(struct vx_core *chip, struct vx_pipe *pipe) in vx_stop_pipe() argument
377 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_stop_pipe()
378 return vx_send_msg(chip, &rmh); in vx_stop_pipe()
383 * vx_alloc_pipe - allocate a pipe and initialize the pipe instance
385 * @audioid: the audio id to be assigned
391 static int vx_alloc_pipe(struct vx_core *chip, int capture, in vx_alloc_pipe() argument
407 data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0; in vx_alloc_pipe()
410 err = vx_send_msg(chip, &rmh); in vx_alloc_pipe()
420 vx_send_msg(chip, &rmh); in vx_alloc_pipe()
421 return -ENOMEM; in vx_alloc_pipe()
425 pipe->number = audioid; in vx_alloc_pipe()
426 pipe->is_capture = capture; in vx_alloc_pipe()
427 pipe->channels = num_audio; in vx_alloc_pipe()
428 pipe->differed_type = 0; in vx_alloc_pipe()
429 pipe->pcx_time = 0; in vx_alloc_pipe()
430 pipe->data_mode = data_mode; in vx_alloc_pipe()
438 * vx_free_pipe - release a pipe
439 * @pipe: pipe to be released
441 static int vx_free_pipe(struct vx_core *chip, struct vx_pipe *pipe) in vx_free_pipe() argument
446 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_free_pipe()
447 vx_send_msg(chip, &rmh); in vx_free_pipe()
455 * vx_start_stream - start the stream
459 static int vx_start_stream(struct vx_core *chip, struct vx_pipe *pipe) in vx_start_stream() argument
464 vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number); in vx_start_stream()
465 vx_set_differed_time(chip, &rmh, pipe); in vx_start_stream()
466 return vx_send_msg(chip, &rmh); in vx_start_stream()
471 * vx_stop_stream - stop the stream
475 static int vx_stop_stream(struct vx_core *chip, struct vx_pipe *pipe) in vx_stop_stream() argument
480 vx_set_stream_cmd_params(&rmh, pipe->is_capture, pipe->number); in vx_stop_stream()
481 return vx_send_msg(chip, &rmh); in vx_stop_stream()
510 * vx_pcm_playback_open - open callback for playback
514 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_playback_open()
515 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_playback_open() local
520 if (chip->chip_status & VX_STAT_IS_STALE) in vx_pcm_playback_open()
521 return -EBUSY; in vx_pcm_playback_open()
523 audio = subs->pcm->device * 2; in vx_pcm_playback_open()
524 if (snd_BUG_ON(audio >= chip->audio_outs)) in vx_pcm_playback_open()
525 return -EINVAL; in vx_pcm_playback_open()
528 pipe = chip->playback_pipes[audio]; in vx_pcm_playback_open()
531 err = vx_alloc_pipe(chip, 0, audio, 2, &pipe); /* stereo playback */ in vx_pcm_playback_open()
536 pipe->references++; in vx_pcm_playback_open()
538 pipe->substream = subs; in vx_pcm_playback_open()
539 chip->playback_pipes[audio] = pipe; in vx_pcm_playback_open()
541 runtime->hw = vx_pcm_playback_hw; in vx_pcm_playback_open()
542 runtime->hw.period_bytes_min = chip->ibl.size; in vx_pcm_playback_open()
543 runtime->private_data = pipe; in vx_pcm_playback_open()
545 /* align to 4 bytes (otherwise will be problematic when 24bit is used) */ in vx_pcm_playback_open()
553 * vx_pcm_playback_close - close callback for playback
557 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_playback_close() local
560 if (! subs->runtime->private_data) in vx_pcm_playback_close()
561 return -EINVAL; in vx_pcm_playback_close()
563 pipe = subs->runtime->private_data; in vx_pcm_playback_close()
565 if (--pipe->references == 0) { in vx_pcm_playback_close()
566 chip->playback_pipes[pipe->number] = NULL; in vx_pcm_playback_close()
567 vx_free_pipe(chip, pipe); in vx_pcm_playback_close()
576 * vx_notify_end_of_buffer - send "end-of-buffer" notifier at the given pipe
577 * @pipe: the pipe to notify
581 static int vx_notify_end_of_buffer(struct vx_core *chip, struct vx_pipe *pipe) in vx_notify_end_of_buffer() argument
587 vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT); in vx_notify_end_of_buffer()
589 vx_set_stream_cmd_params(&rmh, 0, pipe->number); in vx_notify_end_of_buffer()
590 err = vx_send_msg_nolock(chip, &rmh); in vx_notify_end_of_buffer()
593 /* Toggle Dsp Host Interface back to sound transfer mode */ in vx_notify_end_of_buffer()
594 vx_send_rih_nolock(chip, IRQ_PAUSE_START_CONNECT); in vx_notify_end_of_buffer()
599 * vx_pcm_playback_transfer_chunk - transfer a single chunk
601 * @pipe: the pipe to transfer
609 static int vx_pcm_playback_transfer_chunk(struct vx_core *chip, in vx_pcm_playback_transfer_chunk() argument
615 space = vx_query_hbuffer_size(chip, pipe); in vx_pcm_playback_transfer_chunk()
617 /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ in vx_pcm_playback_transfer_chunk()
618 vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); in vx_pcm_playback_transfer_chunk()
623 vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); in vx_pcm_playback_transfer_chunk()
625 return -EIO; /* XRUN */ in vx_pcm_playback_transfer_chunk()
631 mutex_lock(&chip->lock); in vx_pcm_playback_transfer_chunk()
632 vx_pseudo_dma_write(chip, runtime, pipe, size); in vx_pcm_playback_transfer_chunk()
633 err = vx_notify_end_of_buffer(chip, pipe); in vx_pcm_playback_transfer_chunk()
634 /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ in vx_pcm_playback_transfer_chunk()
635 vx_send_rih_nolock(chip, IRQ_CONNECT_STREAM_NEXT); in vx_pcm_playback_transfer_chunk()
636 mutex_unlock(&chip->lock); in vx_pcm_playback_transfer_chunk()
642 * pipe->position is updated and wrapped within the buffer size.
643 * pipe->transferred is updated, too, but the size is not wrapped,
645 * (to call snd_pcm_period_elapsed).
647 static int vx_update_pipe_position(struct vx_core *chip, in vx_update_pipe_position() argument
656 vx_set_pipe_cmd_params(&rmh, pipe->is_capture, pipe->number, 0); in vx_update_pipe_position()
657 err = vx_send_msg(chip, &rmh); in vx_update_pipe_position()
662 update = (int)(count - pipe->cur_count); in vx_update_pipe_position()
663 pipe->cur_count = count; in vx_update_pipe_position()
664 pipe->position += update; in vx_update_pipe_position()
665 if (pipe->position >= (int)runtime->buffer_size) in vx_update_pipe_position()
666 pipe->position %= runtime->buffer_size; in vx_update_pipe_position()
667 pipe->transferred += update; in vx_update_pipe_position()
672 * transfer the pending playback buffer data to DSP
675 static void vx_pcm_playback_transfer(struct vx_core *chip, in vx_pcm_playback_transfer() argument
680 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_playback_transfer()
682 if (! pipe->prepared || (chip->chip_status & VX_STAT_IS_STALE)) in vx_pcm_playback_transfer()
685 err = vx_pcm_playback_transfer_chunk(chip, runtime, pipe, in vx_pcm_playback_transfer()
686 chip->ibl.size); in vx_pcm_playback_transfer()
696 static void vx_pcm_playback_update(struct vx_core *chip, in vx_pcm_playback_update() argument
701 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_playback_update()
703 if (pipe->running && ! (chip->chip_status & VX_STAT_IS_STALE)) { in vx_pcm_playback_update()
704 err = vx_update_pipe_position(chip, runtime, pipe); in vx_pcm_playback_update()
707 if (pipe->transferred >= (int)runtime->period_size) { in vx_pcm_playback_update()
708 pipe->transferred %= runtime->period_size; in vx_pcm_playback_update()
715 * vx_pcm_playback_trigger - trigger callback for playback
719 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_trigger() local
720 struct vx_pipe *pipe = subs->runtime->private_data; in vx_pcm_trigger()
723 if (chip->chip_status & VX_STAT_IS_STALE) in vx_pcm_trigger()
724 return -EBUSY; in vx_pcm_trigger()
729 if (! pipe->is_capture) in vx_pcm_trigger()
730 vx_pcm_playback_transfer(chip, subs, pipe, 2); in vx_pcm_trigger()
731 err = vx_start_stream(chip, pipe); in vx_pcm_trigger()
736 err = vx_toggle_pipe(chip, pipe, 1); in vx_pcm_trigger()
739 vx_stop_stream(chip, pipe); in vx_pcm_trigger()
742 chip->pcm_running++; in vx_pcm_trigger()
743 pipe->running = 1; in vx_pcm_trigger()
747 vx_toggle_pipe(chip, pipe, 0); in vx_pcm_trigger()
748 vx_stop_pipe(chip, pipe); in vx_pcm_trigger()
749 vx_stop_stream(chip, pipe); in vx_pcm_trigger()
750 chip->pcm_running--; in vx_pcm_trigger()
751 pipe->running = 0; in vx_pcm_trigger()
754 err = vx_toggle_pipe(chip, pipe, 0); in vx_pcm_trigger()
759 err = vx_toggle_pipe(chip, pipe, 1); in vx_pcm_trigger()
764 return -EINVAL; in vx_pcm_trigger()
770 * vx_pcm_playback_pointer - pointer callback for playback
774 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_playback_pointer()
775 struct vx_pipe *pipe = runtime->private_data; in vx_pcm_playback_pointer()
776 return pipe->position; in vx_pcm_playback_pointer()
780 * vx_pcm_prepare - prepare callback for playback and capture
784 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_prepare() local
785 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_prepare()
786 struct vx_pipe *pipe = runtime->private_data; in vx_pcm_prepare()
790 if (chip->chip_status & VX_STAT_IS_STALE) in vx_pcm_prepare()
791 return -EBUSY; in vx_pcm_prepare()
793 data_mode = (chip->uer_bits & IEC958_AES0_NONAUDIO) != 0; in vx_pcm_prepare()
794 if (data_mode != pipe->data_mode && ! pipe->is_capture) { in vx_pcm_prepare()
795 /* IEC958 status (raw-mode) was changed */ in vx_pcm_prepare()
800 vx_set_pipe_cmd_params(&rmh, 0, pipe->number, 0); in vx_pcm_prepare()
801 err = vx_send_msg(chip, &rmh); in vx_pcm_prepare()
805 vx_set_pipe_cmd_params(&rmh, 0, pipe->number, pipe->channels); in vx_pcm_prepare()
808 err = vx_send_msg(chip, &rmh); in vx_pcm_prepare()
811 pipe->data_mode = data_mode; in vx_pcm_prepare()
814 if (chip->pcm_running && chip->freq != runtime->rate) { in vx_pcm_prepare()
816 "from the current %d\n", runtime->rate, chip->freq); in vx_pcm_prepare()
817 return -EINVAL; in vx_pcm_prepare()
819 vx_set_clock(chip, runtime->rate); in vx_pcm_prepare()
821 err = vx_set_format(chip, pipe, runtime); in vx_pcm_prepare()
825 if (vx_is_pcmcia(chip)) { in vx_pcm_prepare()
826 pipe->align = 2; /* 16bit word */ in vx_pcm_prepare()
828 pipe->align = 4; /* 32bit word */ in vx_pcm_prepare()
831 pipe->buffer_bytes = frames_to_bytes(runtime, runtime->buffer_size); in vx_pcm_prepare()
832 pipe->period_bytes = frames_to_bytes(runtime, runtime->period_size); in vx_pcm_prepare()
833 pipe->hw_ptr = 0; in vx_pcm_prepare()
836 vx_update_pipe_position(chip, runtime, pipe); in vx_pcm_prepare()
838 pipe->transferred = 0; in vx_pcm_prepare()
839 pipe->position = 0; in vx_pcm_prepare()
841 pipe->prepared = 1; in vx_pcm_prepare()
884 * vx_pcm_capture_open - open callback for capture
888 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_capture_open()
889 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_capture_open() local
895 if (chip->chip_status & VX_STAT_IS_STALE) in vx_pcm_capture_open()
896 return -EBUSY; in vx_pcm_capture_open()
898 audio = subs->pcm->device * 2; in vx_pcm_capture_open()
899 if (snd_BUG_ON(audio >= chip->audio_ins)) in vx_pcm_capture_open()
900 return -EINVAL; in vx_pcm_capture_open()
901 err = vx_alloc_pipe(chip, 1, audio, 2, &pipe); in vx_pcm_capture_open()
904 pipe->substream = subs; in vx_pcm_capture_open()
905 chip->capture_pipes[audio] = pipe; in vx_pcm_capture_open()
908 if (chip->audio_monitor_active[audio]) { in vx_pcm_capture_open()
909 pipe_out_monitoring = chip->playback_pipes[audio]; in vx_pcm_capture_open()
912 err = vx_alloc_pipe(chip, 0, audio, 2, &pipe_out_monitoring); in vx_pcm_capture_open()
915 chip->playback_pipes[audio] = pipe_out_monitoring; in vx_pcm_capture_open()
917 pipe_out_monitoring->references++; in vx_pcm_capture_open()
919 if an output pipe is available, it's audios still may need to be in vx_pcm_capture_open()
920 unmuted. hence we'll have to call a mixer entry point. in vx_pcm_capture_open()
922 vx_set_monitor_level(chip, audio, chip->audio_monitor[audio], in vx_pcm_capture_open()
923 chip->audio_monitor_active[audio]); in vx_pcm_capture_open()
925 vx_set_monitor_level(chip, audio+1, chip->audio_monitor[audio+1], in vx_pcm_capture_open()
926 chip->audio_monitor_active[audio+1]); in vx_pcm_capture_open()
929 pipe->monitoring_pipe = pipe_out_monitoring; /* default value NULL */ in vx_pcm_capture_open()
931 runtime->hw = vx_pcm_capture_hw; in vx_pcm_capture_open()
932 runtime->hw.period_bytes_min = chip->ibl.size; in vx_pcm_capture_open()
933 runtime->private_data = pipe; in vx_pcm_capture_open()
935 /* align to 4 bytes (otherwise will be problematic when 24bit is used) */ in vx_pcm_capture_open()
943 * vx_pcm_capture_close - close callback for capture
947 struct vx_core *chip = snd_pcm_substream_chip(subs); in vx_pcm_capture_close() local
951 if (! subs->runtime->private_data) in vx_pcm_capture_close()
952 return -EINVAL; in vx_pcm_capture_close()
953 pipe = subs->runtime->private_data; in vx_pcm_capture_close()
954 chip->capture_pipes[pipe->number] = NULL; in vx_pcm_capture_close()
956 pipe_out_monitoring = pipe->monitoring_pipe; in vx_pcm_capture_close()
959 if an output pipe is attached to this input, in vx_pcm_capture_close()
960 check if it needs to be released. in vx_pcm_capture_close()
963 if (--pipe_out_monitoring->references == 0) { in vx_pcm_capture_close()
964 vx_free_pipe(chip, pipe_out_monitoring); in vx_pcm_capture_close()
965 chip->playback_pipes[pipe->number] = NULL; in vx_pcm_capture_close()
966 pipe->monitoring_pipe = NULL; in vx_pcm_capture_close()
970 vx_free_pipe(chip, pipe); in vx_pcm_capture_close()
979 * vx_pcm_capture_update - update the capture buffer
981 static void vx_pcm_capture_update(struct vx_core *chip, struct snd_pcm_substream *subs, in vx_pcm_capture_update() argument
985 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_capture_update()
987 if (!pipe->running || (chip->chip_status & VX_STAT_IS_STALE)) in vx_pcm_capture_update()
990 size = runtime->buffer_size - snd_pcm_capture_avail(runtime); in vx_pcm_capture_update()
994 space = vx_query_hbuffer_size(chip, pipe); in vx_pcm_capture_update()
999 size = (size / 3) * 3; /* align to 3 bytes */ in vx_pcm_capture_update()
1004 count = size - DMA_READ_ALIGN; in vx_pcm_capture_update()
1005 /* read bytes until the current pointer reaches to the aligned position in vx_pcm_capture_update()
1006 * for word-transfer in vx_pcm_capture_update()
1009 if ((pipe->hw_ptr % pipe->align) == 0) in vx_pcm_capture_update()
1011 if (vx_wait_for_rx_full(chip) < 0) in vx_pcm_capture_update()
1013 vx_pcm_read_per_bytes(chip, runtime, pipe); in vx_pcm_capture_update()
1014 count -= 3; in vx_pcm_capture_update()
1018 int align = pipe->align * 3; in vx_pcm_capture_update()
1021 vx_pseudo_dma_read(chip, runtime, pipe, space); in vx_pcm_capture_update()
1022 count -= space; in vx_pcm_capture_update()
1027 if (vx_wait_for_rx_full(chip) < 0) in vx_pcm_capture_update()
1029 vx_pcm_read_per_bytes(chip, runtime, pipe); in vx_pcm_capture_update()
1030 count -= 3; in vx_pcm_capture_update()
1032 /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ in vx_pcm_capture_update()
1033 vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); in vx_pcm_capture_update()
1037 vx_pcm_read_per_bytes(chip, runtime, pipe); in vx_pcm_capture_update()
1038 count -= 3; in vx_pcm_capture_update()
1041 pipe->transferred += size; in vx_pcm_capture_update()
1042 if (pipe->transferred >= pipe->period_bytes) { in vx_pcm_capture_update()
1043 pipe->transferred %= pipe->period_bytes; in vx_pcm_capture_update()
1049 /* disconnect the host, SIZE_HBUF command always switches to the stream mode */ in vx_pcm_capture_update()
1050 vx_send_rih(chip, IRQ_CONNECT_STREAM_NEXT); in vx_pcm_capture_update()
1055 * vx_pcm_capture_pointer - pointer callback for capture
1059 struct snd_pcm_runtime *runtime = subs->runtime; in vx_pcm_capture_pointer()
1060 struct vx_pipe *pipe = runtime->private_data; in vx_pcm_capture_pointer()
1061 return bytes_to_frames(runtime, pipe->hw_ptr); in vx_pcm_capture_pointer()
1079 void vx_pcm_update_intr(struct vx_core *chip, unsigned int events) in vx_pcm_update_intr() argument
1087 vx_init_rmh(&chip->irq_rmh, CMD_ASYNC); in vx_pcm_update_intr()
1089 chip->irq_rmh.Cmd[0] |= 0x00000001; /* SEL_ASYNC_EVENTS */ in vx_pcm_update_intr()
1091 chip->irq_rmh.Cmd[0] |= 0x00000002; /* SEL_END_OF_BUF_EVENTS */ in vx_pcm_update_intr()
1093 if (vx_send_msg(chip, &chip->irq_rmh) < 0) { in vx_pcm_update_intr()
1099 while (i < chip->irq_rmh.LgStat) { in vx_pcm_update_intr()
1101 p = chip->irq_rmh.Stat[i] & MASK_FIRST_FIELD; in vx_pcm_update_intr()
1102 capture = (chip->irq_rmh.Stat[i] & 0x400000) ? 1 : 0; in vx_pcm_update_intr()
1103 eob = (chip->irq_rmh.Stat[i] & 0x800000) ? 1 : 0; in vx_pcm_update_intr()
1107 buf = 1; /* force to transfer */ in vx_pcm_update_intr()
1110 buf = chip->irq_rmh.Stat[i]; in vx_pcm_update_intr()
1115 if (snd_BUG_ON(p < 0 || p >= chip->audio_outs)) in vx_pcm_update_intr()
1117 pipe = chip->playback_pipes[p]; in vx_pcm_update_intr()
1118 if (pipe && pipe->substream) { in vx_pcm_update_intr()
1119 vx_pcm_playback_update(chip, pipe->substream, pipe); in vx_pcm_update_intr()
1120 vx_pcm_playback_transfer(chip, pipe->substream, pipe, buf); in vx_pcm_update_intr()
1126 for (i = 0; i < chip->audio_ins; i++) { in vx_pcm_update_intr()
1127 pipe = chip->capture_pipes[i]; in vx_pcm_update_intr()
1128 if (pipe && pipe->substream) in vx_pcm_update_intr()
1129 vx_pcm_capture_update(chip, pipe->substream, pipe); in vx_pcm_update_intr()
1135 * vx_init_audio_io - check the available audio i/o and allocate pipe arrays
1137 static int vx_init_audio_io(struct vx_core *chip) in vx_init_audio_io() argument
1143 if (vx_send_msg(chip, &rmh) < 0) { in vx_init_audio_io()
1145 return -ENXIO; in vx_init_audio_io()
1148 chip->audio_outs = rmh.Stat[0] & MASK_FIRST_FIELD; in vx_init_audio_io()
1149 chip->audio_ins = (rmh.Stat[0] >> (FIELD_SIZE*2)) & MASK_FIRST_FIELD; in vx_init_audio_io()
1150 chip->audio_info = rmh.Stat[1]; in vx_init_audio_io()
1153 chip->playback_pipes = kcalloc(chip->audio_outs, sizeof(struct vx_pipe *), GFP_KERNEL); in vx_init_audio_io()
1154 if (!chip->playback_pipes) in vx_init_audio_io()
1155 return -ENOMEM; in vx_init_audio_io()
1156 chip->capture_pipes = kcalloc(chip->audio_ins, sizeof(struct vx_pipe *), GFP_KERNEL); in vx_init_audio_io()
1157 if (!chip->capture_pipes) { in vx_init_audio_io()
1158 kfree(chip->playback_pipes); in vx_init_audio_io()
1159 return -ENOMEM; in vx_init_audio_io()
1162 preferred = chip->ibl.size; in vx_init_audio_io()
1163 chip->ibl.size = 0; in vx_init_audio_io()
1164 vx_set_ibl(chip, &chip->ibl); /* query the info */ in vx_init_audio_io()
1166 chip->ibl.size = roundup(preferred, chip->ibl.granularity); in vx_init_audio_io()
1167 if (chip->ibl.size > chip->ibl.max_size) in vx_init_audio_io()
1168 chip->ibl.size = chip->ibl.max_size; in vx_init_audio_io()
1170 chip->ibl.size = chip->ibl.min_size; /* set to the minimum */ in vx_init_audio_io()
1171 vx_set_ibl(chip, &chip->ibl); in vx_init_audio_io()
1182 struct vx_core *chip = pcm->private_data; in snd_vx_pcm_free() local
1183 chip->pcm[pcm->device] = NULL; in snd_vx_pcm_free()
1184 kfree(chip->playback_pipes); in snd_vx_pcm_free()
1185 chip->playback_pipes = NULL; in snd_vx_pcm_free()
1186 kfree(chip->capture_pipes); in snd_vx_pcm_free()
1187 chip->capture_pipes = NULL; in snd_vx_pcm_free()
1191 * snd_vx_pcm_new - create and initialize a pcm
1193 int snd_vx_pcm_new(struct vx_core *chip) in snd_vx_pcm_new() argument
1199 err = vx_init_audio_io(chip); in snd_vx_pcm_new()
1203 for (i = 0; i < chip->hw->num_codecs; i++) { in snd_vx_pcm_new()
1205 outs = chip->audio_outs > i * 2 ? 1 : 0; in snd_vx_pcm_new()
1206 ins = chip->audio_ins > i * 2 ? 1 : 0; in snd_vx_pcm_new()
1209 err = snd_pcm_new(chip->card, "VX PCM", i, in snd_vx_pcm_new()
1220 pcm->private_data = chip; in snd_vx_pcm_new()
1221 pcm->private_free = snd_vx_pcm_free; in snd_vx_pcm_new()
1222 pcm->info_flags = 0; in snd_vx_pcm_new()
1223 pcm->nonatomic = true; in snd_vx_pcm_new()
1224 strcpy(pcm->name, chip->card->shortname); in snd_vx_pcm_new()
1225 chip->pcm[i] = pcm; in snd_vx_pcm_new()