48 #include <linux/slab.h>
64 unsigned char *
buf = (
unsigned char *)(runtime->
dma_area + offset);
65 *buf++ =
vx_inb(chip, RXH);
68 buf = (
unsigned char *)runtime->
dma_area;
70 *buf++ =
vx_inb(chip, RXM);
73 buf = (
unsigned char *)runtime->
dma_area;
75 *buf++ =
vx_inb(chip, RXL);
78 buf = (
unsigned char *)runtime->
dma_area;
89 unsigned int *dsp_time)
105 static int vx_set_differed_time(
struct vx_core *chip,
struct vx_rmh *rmh,
116 vx_set_pcx_time(chip, &pipe->
pcx_time, &rmh->
Cmd[1]);
139 static int vx_set_stream_format(
struct vx_core *chip,
struct vx_pipe *pipe,
149 vx_set_differed_time(chip, &rmh, pipe);
151 rmh.
Cmd[rmh.
LgCmd] = (data & 0xFFFFFF00) >> 8;
152 rmh.
Cmd[rmh.
LgCmd + 1] = (data & 0xFF) << 16 ;
166 static int vx_set_format(
struct vx_core *chip,
struct vx_pipe *pipe,
175 if (runtime->
rate < 32000 && runtime->
rate > 11025)
177 else if (runtime->
rate <= 11025)
189 return vx_set_stream_format(chip, pipe, header);
201 rmh.
Cmd[0] |= info->
size & 0x03ffff;
234 *state = (rmh.
Stat[0] & (1 << pipe->
number)) ? 1 : 0;
250 static int vx_query_hbuffer_size(
struct vx_core *chip,
struct vx_pipe *pipe)
258 rmh.
Cmd[0] |= 0x00000001;
261 result = rmh.
Stat[0] & 0xffff;
274 static int vx_pipe_can_start(
struct vx_core *chip,
struct vx_pipe *pipe)
295 static int vx_conf_pipe(
struct vx_core *chip,
struct vx_pipe *pipe)
309 static int vx_send_irqa(
struct vx_core *chip)
318 #define MAX_WAIT_FOR_DSP 250
323 #define CAN_START_DELAY 2
324 #define WAIT_STATE_DELAY 2
334 static int vx_toggle_pipe(
struct vx_core *chip,
struct vx_pipe *pipe,
int state)
336 int err,
i, cur_state;
339 if (vx_get_pipe_state(chip, pipe, &cur_state) < 0)
341 if (state == cur_state)
350 err = vx_pipe_can_start(chip, pipe);
360 if ((err = vx_conf_pipe(chip, pipe)) < 0)
363 if ((err = vx_send_irqa(chip)) < 0)
371 err = vx_get_pipe_state(chip, pipe, &cur_state);
372 if (err < 0 || cur_state == state)
377 return err < 0 ? -
EIO : 0;
387 static int vx_stop_pipe(
struct vx_core *chip,
struct vx_pipe *pipe)
405 static int vx_alloc_pipe(
struct vx_core *chip,
int capture,
406 int audioid,
int num_audio,
416 vx_set_pipe_cmd_params(&rmh, capture, audioid, num_audio);
418 if (underrun_skip_sound)
422 if (! capture && data_mode)
433 vx_set_pipe_cmd_params(&rmh, capture, audioid, 0);
455 static int vx_free_pipe(
struct vx_core *chip,
struct vx_pipe *pipe)
473 static int vx_start_stream(
struct vx_core *chip,
struct vx_pipe *pipe)
479 vx_set_differed_time(chip, &rmh, pipe);
489 static int vx_stop_stream(
struct vx_core *chip,
struct vx_pipe *pipe)
514 .buffer_bytes_max = (128*1024),
523 static void vx_pcm_delayed_start(
unsigned long arg);
539 audio = subs->
pcm->device * 2;
547 err = vx_alloc_pipe(chip, 0, audio, 2, &pipe);
559 runtime->
hw = vx_pcm_playback_hw;
560 runtime->
hw.period_bytes_min = chip->
ibl.size;
578 if (! subs->
runtime->private_data)
581 pipe = subs->
runtime->private_data;
585 vx_free_pipe(chip, pipe);
599 static int vx_notify_end_of_buffer(
struct vx_core *chip,
struct vx_pipe *pipe)
607 vx_set_stream_cmd_params(&rmh, 0, pipe->
number);
627 static int vx_pcm_playback_transfer_chunk(
struct vx_core *chip,
633 space = vx_query_hbuffer_size(chip, pipe);
642 snd_printd(
"no enough hbuffer space %d\n", space);
649 spin_lock(&chip->
lock);
650 vx_pseudo_dma_write(chip, runtime, pipe, size);
651 err = vx_notify_end_of_buffer(chip, pipe);
654 spin_unlock(&chip->
lock);
665 static int vx_update_pipe_position(
struct vx_core *chip,
693 static void vx_pcm_playback_transfer(
struct vx_core *chip,
695 struct vx_pipe *pipe,
int nchunks)
702 for (i = 0; i < nchunks; i++) {
703 if ((err = vx_pcm_playback_transfer_chunk(chip, runtime, pipe,
704 chip->
ibl.size)) < 0)
713 static void vx_pcm_playback_update(
struct vx_core *chip,
721 if ((err = vx_update_pipe_position(chip, runtime, pipe)) < 0)
735 static void vx_pcm_delayed_start(
unsigned long arg)
738 struct vx_core *chip = subs->
pcm->private_data;
744 if ((err = vx_start_stream(chip, pipe)) < 0) {
748 if ((err = vx_toggle_pipe(chip, pipe, 1)) < 0) {
771 vx_pcm_playback_transfer(chip, subs, pipe, 2);
782 vx_toggle_pipe(chip, pipe, 0);
783 vx_stop_pipe(chip, pipe);
784 vx_stop_stream(chip, pipe);
789 if ((err = vx_toggle_pipe(chip, pipe, 0)) < 0)
793 if ((err = vx_toggle_pipe(chip, pipe, 1)) < 0)
851 vx_set_pipe_cmd_params(&rmh, 0, pipe->
number, 0);
865 "from the current %d\n", runtime->
rate, chip->
freq);
870 if ((err = vx_set_format(chip, pipe, runtime)) < 0)
884 vx_update_pipe_position(chip, runtime, pipe);
899 .open = vx_pcm_playback_open,
900 .close = vx_pcm_playback_close,
902 .hw_params = vx_pcm_hw_params,
903 .hw_free = vx_pcm_hw_free,
904 .prepare = vx_pcm_prepare,
905 .trigger = vx_pcm_trigger,
906 .pointer = vx_pcm_playback_pointer,
927 .buffer_bytes_max = (128*1024),
951 audio = subs->
pcm->device * 2;
954 err = vx_alloc_pipe(chip, 1, audio, 2, &pipe);
964 if (! pipe_out_monitoring) {
966 err = vx_alloc_pipe(chip, 0, audio, 2, &pipe_out_monitoring);
985 runtime->
hw = vx_pcm_capture_hw;
986 runtime->
hw.period_bytes_min = chip->
ibl.size;
1003 struct vx_pipe *pipe_out_monitoring;
1005 if (! subs->
runtime->private_data)
1007 pipe = subs->
runtime->private_data;
1016 if (pipe_out_monitoring) {
1017 if (--pipe_out_monitoring->
references == 0) {
1018 vx_free_pipe(chip, pipe_out_monitoring);
1024 vx_free_pipe(chip, pipe);
1030 #define DMA_READ_ALIGN 6
1044 size = runtime->
buffer_size - snd_pcm_capture_avail(runtime);
1047 size = frames_to_bytes(runtime, size);
1048 space = vx_query_hbuffer_size(chip, pipe);
1053 size = (size / 3) * 3;
1067 vx_pcm_read_per_bytes(chip, runtime, pipe);
1073 space = (count /
align) * align;
1074 vx_pseudo_dma_read(chip, runtime, pipe, space);
1081 vx_pcm_read_per_bytes(chip, runtime, pipe);
1089 vx_pcm_read_per_bytes(chip, runtime, pipe);
1113 return bytes_to_frames(runtime, pipe->
hw_ptr);
1120 .open = vx_pcm_capture_open,
1121 .close = vx_pcm_capture_close,
1123 .hw_params = vx_pcm_hw_params,
1124 .hw_free = vx_pcm_hw_free,
1125 .prepare = vx_pcm_prepare,
1126 .trigger = vx_pcm_trigger,
1127 .pointer = vx_pcm_capture_pointer,
1141 #define EVENT_MASK (END_OF_BUFFER_EVENTS_PENDING|ASYNC_EVENTS_PENDING)
1146 chip->
irq_rmh.Cmd[0] |= 0x00000001;
1148 chip->
irq_rmh.Cmd[0] |= 0x00000002;
1156 while (i < chip->irq_rmh.LgStat) {
1157 int p,
buf, capture, eob;
1159 capture = (chip->
irq_rmh.Stat[
i] & 0x400000) ? 1 : 0;
1160 eob = (chip->
irq_rmh.Stat[
i] & 0x800000) ? 1 : 0;
1162 if (events & ASYNC_EVENTS_PENDING)
1165 if (events & END_OF_BUFFER_EVENTS_PENDING) {
1176 vx_pcm_playback_update(chip, pipe->
substream, pipe);
1177 vx_pcm_playback_transfer(chip, pipe->
substream, pipe, buf);
1186 vx_pcm_capture_update(chip, pipe->
substream, pipe);
1194 static int vx_init_audio_io(
struct vx_core *chip)
1219 preferred = chip->
ibl.size;
1221 vx_set_ibl(chip, &chip->
ibl);
1222 if (preferred > 0) {
1223 chip->
ibl.size = ((preferred + chip->
ibl.granularity - 1) /
1224 chip->
ibl.granularity) * chip->
ibl.granularity;
1225 if (chip->
ibl.size > chip->
ibl.max_size)
1226 chip->
ibl.size = chip->
ibl.max_size;
1228 chip->
ibl.size = chip->
ibl.min_size;
1229 vx_set_ibl(chip, &chip->
ibl);
1238 static void snd_vx_pcm_free(
struct snd_pcm *pcm)
1257 if ((err = vx_init_audio_io(chip)) < 0)
1260 for (i = 0; i < chip->
hw->num_codecs; i++) {
1261 unsigned int outs,
ins;
1264 if (! outs && ! ins)