3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 * 2002-07 Benny Sjostrand benny@hostmobility.com
24 #include <sound/driver.h>
26 #include <linux/delay.h>
27 #include <linux/pci.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
31 #include <sound/core.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
34 #include <sound/cs46xx.h>
36 #include "cs46xx_lib.h"
39 struct proc_scb_info {
40 struct dsp_scb_descriptor * scb_desc;
41 struct snd_cs46xx *chip;
44 static void remove_symbol (struct snd_cs46xx * chip, struct dsp_symbol_entry * symbol)
46 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
47 int symbol_index = (int)(symbol - ins->symbol_table.symbols);
49 snd_assert(ins->symbol_table.nsymbols > 0,return);
50 snd_assert(symbol_index >= 0 && symbol_index < ins->symbol_table.nsymbols, return);
52 ins->symbol_table.symbols[symbol_index].deleted = 1;
54 if (symbol_index < ins->symbol_table.highest_frag_index) {
55 ins->symbol_table.highest_frag_index = symbol_index;
58 if (symbol_index == ins->symbol_table.nsymbols - 1)
59 ins->symbol_table.nsymbols --;
61 if (ins->symbol_table.highest_frag_index > ins->symbol_table.nsymbols) {
62 ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols;
67 static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,
68 struct snd_info_buffer *buffer)
70 struct proc_scb_info * scb_info = entry->private_data;
71 struct dsp_scb_descriptor * scb = scb_info->scb_desc;
72 struct dsp_spos_instance * ins;
73 struct snd_cs46xx *chip = scb_info->chip;
75 void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
77 ins = chip->dsp_spos_instance;
79 down(&chip->spos_mutex);
80 snd_iprintf(buffer,"%04x %s:\n",scb->address,scb->scb_name);
82 for (col = 0,j = 0;j < 0x10; j++,col++) {
84 snd_iprintf(buffer,"\n");
87 snd_iprintf(buffer,"%08x ",readl(dst + (scb->address + j) * sizeof(u32)));
90 snd_iprintf(buffer,"\n");
92 if (scb->parent_scb_ptr != NULL) {
93 snd_iprintf(buffer,"parent [%s:%04x] ",
94 scb->parent_scb_ptr->scb_name,
95 scb->parent_scb_ptr->address);
96 } else snd_iprintf(buffer,"parent [none] ");
98 snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n",
99 scb->sub_list_ptr->scb_name,
100 scb->sub_list_ptr->address,
101 scb->next_scb_ptr->scb_name,
102 scb->next_scb_ptr->address,
103 scb->task_entry->symbol_name,
104 scb->task_entry->address);
106 snd_iprintf(buffer,"index [%d] ref_count [%d]\n",scb->index,scb->ref_count);
107 up(&chip->spos_mutex);
110 static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
112 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
115 if ( scb->parent_scb_ptr ) {
116 /* unlink parent SCB */
117 snd_assert ((scb->parent_scb_ptr->sub_list_ptr == scb ||
118 scb->parent_scb_ptr->next_scb_ptr == scb),return);
120 if (scb->parent_scb_ptr->sub_list_ptr == scb) {
122 if (scb->next_scb_ptr == ins->the_null_scb) {
123 /* last and only node in parent sublist */
124 scb->parent_scb_ptr->sub_list_ptr = scb->sub_list_ptr;
126 if (scb->sub_list_ptr != ins->the_null_scb) {
127 scb->sub_list_ptr->parent_scb_ptr = scb->parent_scb_ptr;
129 scb->sub_list_ptr = ins->the_null_scb;
131 /* first node in parent sublist */
132 scb->parent_scb_ptr->sub_list_ptr = scb->next_scb_ptr;
134 if (scb->next_scb_ptr != ins->the_null_scb) {
135 /* update next node parent ptr. */
136 scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr;
138 scb->next_scb_ptr = ins->the_null_scb;
141 /* snd_assert ( (scb->sub_list_ptr == ins->the_null_scb), return); */
142 scb->parent_scb_ptr->next_scb_ptr = scb->next_scb_ptr;
144 if (scb->next_scb_ptr != ins->the_null_scb) {
145 /* update next node parent ptr. */
146 scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr;
148 scb->next_scb_ptr = ins->the_null_scb;
151 spin_lock_irqsave(&chip->reg_lock, flags);
153 /* update parent first entry in DSP RAM */
154 cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
156 /* then update entry in DSP RAM */
157 cs46xx_dsp_spos_update_scb(chip,scb);
159 scb->parent_scb_ptr = NULL;
160 spin_unlock_irqrestore(&chip->reg_lock, flags);
164 static void _dsp_clear_sample_buffer (struct snd_cs46xx *chip, u32 sample_buffer_addr,
167 void __iomem *dst = chip->region.idx[2].remap_addr + sample_buffer_addr;
170 for (i = 0; i < dword_count ; ++i ) {
176 void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
178 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
180 /* check integrety */
181 snd_assert ( (scb->index >= 0 &&
182 scb->index < ins->nscb &&
183 (ins->scbs + scb->index) == scb), return );
186 /* can't remove a SCB with childs before
187 removing childs first */
188 snd_assert ( (scb->sub_list_ptr == ins->the_null_scb &&
189 scb->next_scb_ptr == ins->the_null_scb),
193 spin_lock(&scb->lock);
194 _dsp_unlink_scb (chip,scb);
195 spin_unlock(&scb->lock);
197 cs46xx_dsp_proc_free_scb_desc(scb);
198 snd_assert (scb->scb_symbol != NULL, return );
199 remove_symbol (chip,scb->scb_symbol);
201 ins->scbs[scb->index].deleted = 1;
203 if (scb->index < ins->scb_highest_frag_index)
204 ins->scb_highest_frag_index = scb->index;
206 if (scb->index == ins->nscb - 1) {
210 if (ins->scb_highest_frag_index > ins->nscb) {
211 ins->scb_highest_frag_index = ins->nscb;
215 /* !!!! THIS IS A PIECE OF SHIT MADE BY ME !!! */
216 for(i = scb->index + 1;i < ins->nscb; ++i) {
217 ins->scbs[i - 1].index = i - 1;
223 void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb)
225 if (scb->proc_info) {
226 struct proc_scb_info * scb_info = scb->proc_info->private_data;
228 snd_printdd("cs46xx_dsp_proc_free_scb_desc: freeing %s\n",scb->scb_name);
230 snd_info_unregister(scb->proc_info);
231 scb->proc_info = NULL;
233 snd_assert (scb_info != NULL, return);
238 void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,
239 struct dsp_scb_descriptor * scb)
241 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
242 struct snd_info_entry * entry;
243 struct proc_scb_info * scb_info;
245 /* register to proc */
246 if (ins->snd_card != NULL && ins->proc_dsp_dir != NULL &&
247 scb->proc_info == NULL) {
249 if ((entry = snd_info_create_card_entry(ins->snd_card, scb->scb_name,
250 ins->proc_dsp_dir)) != NULL) {
251 scb_info = kmalloc(sizeof(struct proc_scb_info), GFP_KERNEL);
253 snd_info_free_entry(entry);
258 scb_info->chip = chip;
259 scb_info->scb_desc = scb;
261 entry->content = SNDRV_INFO_CONTENT_TEXT;
262 entry->private_data = scb_info;
263 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
265 entry->c.text.read_size = 512;
266 entry->c.text.read = cs46xx_dsp_proc_scb_info_read;
268 if (snd_info_register(entry) < 0) {
269 snd_info_free_entry(entry);
275 scb->proc_info = entry;
279 static struct dsp_scb_descriptor *
280 _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest,
281 struct dsp_symbol_entry * task_entry,
282 struct dsp_scb_descriptor * parent_scb,
285 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
286 struct dsp_scb_descriptor * scb;
290 snd_assert (ins->the_null_scb != NULL,return NULL);
292 /* fill the data that will be wroten to DSP */
293 scb_data[SCBsubListPtr] =
294 (ins->the_null_scb->address << 0x10) | ins->the_null_scb->address;
296 scb_data[SCBfuncEntryPtr] &= 0xFFFF0000;
297 scb_data[SCBfuncEntryPtr] |= task_entry->address;
299 snd_printdd("dsp_spos: creating SCB <%s>\n",name);
301 scb = cs46xx_dsp_create_scb(chip,name,scb_data,dest);
304 scb->sub_list_ptr = ins->the_null_scb;
305 scb->next_scb_ptr = ins->the_null_scb;
307 scb->parent_scb_ptr = parent_scb;
308 scb->task_entry = task_entry;
311 /* update parent SCB */
312 if (scb->parent_scb_ptr) {
314 printk ("scb->parent_scb_ptr = %s\n",scb->parent_scb_ptr->scb_name);
315 printk ("scb->parent_scb_ptr->next_scb_ptr = %s\n",scb->parent_scb_ptr->next_scb_ptr->scb_name);
316 printk ("scb->parent_scb_ptr->sub_list_ptr = %s\n",scb->parent_scb_ptr->sub_list_ptr->scb_name);
318 /* link to parent SCB */
319 if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) {
320 snd_assert ( (scb->parent_scb_ptr->next_scb_ptr == ins->the_null_scb),
323 scb->parent_scb_ptr->next_scb_ptr = scb;
325 } else if (scb_child_type == SCB_ON_PARENT_SUBLIST_SCB) {
326 snd_assert ( (scb->parent_scb_ptr->sub_list_ptr == ins->the_null_scb),
329 scb->parent_scb_ptr->sub_list_ptr = scb;
331 snd_assert (0,return NULL);
334 spin_lock_irqsave(&chip->reg_lock, flags);
336 /* update entry in DSP RAM */
337 cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
339 spin_unlock_irqrestore(&chip->reg_lock, flags);
343 cs46xx_dsp_proc_register_scb_desc (chip,scb);
348 static struct dsp_scb_descriptor *
349 cs46xx_dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data,
350 u32 dest, char * task_entry_name,
351 struct dsp_scb_descriptor * parent_scb,
354 struct dsp_symbol_entry * task_entry;
356 task_entry = cs46xx_dsp_lookup_symbol (chip,task_entry_name,
359 if (task_entry == NULL) {
360 snd_printk (KERN_ERR "dsp_spos: symbol %s not found\n",task_entry_name);
364 return _dsp_create_generic_scb (chip,name,scb_data,dest,task_entry,
365 parent_scb,scb_child_type);
368 struct dsp_scb_descriptor *
369 cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip)
371 struct dsp_scb_descriptor * scb;
373 struct dsp_timing_master_scb timing_master_scb = {
387 0,0, /* extraSampleAccum:TMreserved */
388 0,0, /* codecFIFOptr:codecFIFOsyncd */
389 0x0001,0x8000, /* fracSampAccumQm1:TMfrmsLeftInGroup */
390 0x0001,0x0000, /* fracSampCorrectionQm1:TMfrmGroupLength */
391 0x00060000 /* nSampPerFrmQ15 */
394 scb = cs46xx_dsp_create_generic_scb(chip,"TimingMasterSCBInst",(u32 *)&timing_master_scb,
395 TIMINGMASTER_SCB_ADDR,
396 "TIMINGMASTER",NULL,SCB_NO_PARENT);
402 struct dsp_scb_descriptor *
403 cs46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip, char * codec_name,
404 u16 channel_disp, u16 fifo_addr, u16 child_scb_addr,
405 u32 dest, struct dsp_scb_descriptor * parent_scb,
408 struct dsp_scb_descriptor * scb;
410 struct dsp_codec_output_scb codec_out_scb = {
425 0, /* COstrmRsConfig */
426 0, /* COstrmBufPtr */
427 channel_disp,fifo_addr, /* leftChanBaseIOaddr:rightChanIOdisp */
428 0x0000,0x0080, /* (!AC97!) COexpVolChangeRate:COscaleShiftCount */
429 0,child_scb_addr /* COreserved - need child scb to work with rom code */
433 scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_out_scb,
434 dest,"S16_CODECOUTPUTTASK",parent_scb,
440 struct dsp_scb_descriptor *
441 cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
442 u16 channel_disp, u16 fifo_addr, u16 sample_buffer_addr,
443 u32 dest, struct dsp_scb_descriptor * parent_scb,
447 struct dsp_scb_descriptor * scb;
448 struct dsp_codec_input_scb codec_input_scb = {
463 SyncIOSCB,NULL_SCB_ADDR
469 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, /* strmRsConfig */
470 sample_buffer_addr << 0x10, /* strmBufPtr; defined as a dword ptr, used as a byte ptr */
471 channel_disp,fifo_addr, /* (!AC97!) leftChanBaseINaddr=AC97primary
472 link input slot 3 :rightChanINdisp=""slot 4 */
473 0x0000,0x0000, /* (!AC97!) ????:scaleShiftCount; no shift needed
474 because AC97 is already 20 bits */
475 0x80008000 /* ??clw cwcgame.scb has 0 */
478 scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_input_scb,
479 dest,"S16_CODECINPUTTASK",parent_scb,
485 static struct dsp_scb_descriptor *
486 cs46xx_dsp_create_pcm_reader_scb(struct snd_cs46xx * chip, char * scb_name,
487 u16 sample_buffer_addr, u32 dest,
488 int virtual_channel, u32 playback_hw_addr,
489 struct dsp_scb_descriptor * parent_scb,
492 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
493 struct dsp_scb_descriptor * scb;
495 struct dsp_generic_scb pcm_reader_scb = {
498 Play DMA Task xfers data from host buffer to SP buffer
499 init/runtime variables:
500 PlayAC: Play Audio Data Conversion - SCB loc: 2nd dword, mask: 0x0000F000L
501 DATA_FMT_16BIT_ST_LTLEND(0x00000000L) from 16-bit stereo, little-endian
502 DATA_FMT_8_BIT_ST_SIGNED(0x00001000L) from 8-bit stereo, signed
503 DATA_FMT_16BIT_MN_LTLEND(0x00002000L) from 16-bit mono, little-endian
504 DATA_FMT_8_BIT_MN_SIGNED(0x00003000L) from 8-bit mono, signed
505 DATA_FMT_16BIT_ST_BIGEND(0x00004000L) from 16-bit stereo, big-endian
506 DATA_FMT_16BIT_MN_BIGEND(0x00006000L) from 16-bit mono, big-endian
507 DATA_FMT_8_BIT_ST_UNSIGNED(0x00009000L) from 8-bit stereo, unsigned
508 DATA_FMT_8_BIT_MN_UNSIGNED(0x0000b000L) from 8-bit mono, unsigned
509 ? Other combinations possible from:
510 DMA_RQ_C2_AUDIO_CONVERT_MASK 0x0000F000L
511 DMA_RQ_C2_AC_NONE 0x00000000L
512 DMA_RQ_C2_AC_8_TO_16_BIT 0x00001000L
513 DMA_RQ_C2_AC_MONO_TO_STEREO 0x00002000L
514 DMA_RQ_C2_AC_ENDIAN_CONVERT 0x00004000L
515 DMA_RQ_C2_AC_SIGNED_CONVERT 0x00008000L
517 HostBuffAddr: Host Buffer Physical Byte Address - SCB loc:3rd dword, Mask: 0xFFFFFFFFL
518 aligned to dword boundary
520 /* Basic (non scatter/gather) DMA requestor (4 ints) */
521 { DMA_RQ_C1_SOURCE_ON_HOST + /* source buffer is on the host */
522 DMA_RQ_C1_SOURCE_MOD1024 + /* source buffer is 1024 dwords (4096 bytes) */
523 DMA_RQ_C1_DEST_MOD32 + /* dest buffer(PCMreaderBuf) is 32 dwords*/
524 DMA_RQ_C1_WRITEBACK_SRC_FLAG + /* ?? */
525 DMA_RQ_C1_WRITEBACK_DEST_FLAG + /* ?? */
526 15, /* DwordCount-1: picked 16 for DwordCount because Jim */
527 /* Barnette said that is what we should use since */
528 /* we are not running in optimized mode? */
530 DMA_RQ_C2_SIGNAL_SOURCE_PINGPONG + /* set play interrupt (bit0) in HISR when source */
531 /* buffer (on host) crosses half-way point */
532 virtual_channel, /* Play DMA channel arbitrarily set to 0 */
533 playback_hw_addr, /* HostBuffAddr (source) */
534 DMA_RQ_SD_SP_SAMPLE_ADDR + /* destination buffer is in SP Sample Memory */
535 sample_buffer_addr /* SP Buffer Address (destination) */
537 /* Scatter/gather DMA requestor extension (5 ints) */
545 /* Sublist pointer & next stream control block (SCB) link. */
546 NULL_SCB_ADDR,NULL_SCB_ADDR,
547 /* Pointer to this tasks parameter block & stream function pointer */
549 /* rsConfig register for stream buffer (rsDMA reg. is loaded from basicReq.daw */
550 /* for incoming streams, or basicReq.saw, for outgoing streams) */
551 RSCONFIG_DMA_ENABLE + /* enable DMA */
552 (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) + /* MAX_DMA_SIZE picked to be 19 since SPUD */
553 /* uses it for some reason */
554 ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) + /* stream number = SCBaddr/16 */
555 RSCONFIG_SAMPLE_16STEREO +
556 RSCONFIG_MODULO_32, /* dest buffer(PCMreaderBuf) is 32 dwords (256 bytes) */
557 /* Stream sample pointer & MAC-unit mode for this stream */
558 (sample_buffer_addr << 0x10),
559 /* Fractional increment per output sample in the input sample buffer */
562 /* Standard stereo volume control
569 if (ins->null_algorithm == NULL) {
570 ins->null_algorithm = cs46xx_dsp_lookup_symbol (chip,"NULLALGORITHM",
573 if (ins->null_algorithm == NULL) {
574 snd_printk (KERN_ERR "dsp_spos: symbol NULLALGORITHM not found\n");
579 scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_reader_scb,
580 dest,ins->null_algorithm,parent_scb,
586 #define GOF_PER_SEC 200
588 struct dsp_scb_descriptor *
589 cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
592 u16 src_delay_buffer_addr, u32 dest,
593 struct dsp_scb_descriptor * parent_scb,
598 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
599 struct dsp_scb_descriptor * scb;
600 unsigned int tmp1, tmp2;
601 unsigned int phiIncr;
602 unsigned int correctionPerGOF, correctionPerSec;
604 snd_printdd( "dsp_spos: setting %s rate to %u\n",scb_name,rate);
607 * Compute the values used to drive the actual sample rate conversion.
608 * The following formulas are being computed, using inline assembly
609 * since we need to use 64 bit arithmetic to compute the values:
611 * phiIncr = floor((Fs,in * 2^26) / Fs,out)
612 * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
614 * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
615 * GOF_PER_SEC * correctionPerGOF
619 * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
620 * correctionPerGOF:correctionPerSec =
621 * dividend:remainder(ulOther / GOF_PER_SEC)
624 phiIncr = tmp1 / 48000;
625 tmp1 -= phiIncr * 48000;
630 tmp1 -= tmp2 * 48000;
631 correctionPerGOF = tmp1 / GOF_PER_SEC;
632 tmp1 -= correctionPerGOF * GOF_PER_SEC;
633 correctionPerSec = tmp1;
636 struct dsp_src_task_scb src_task_scb = {
641 correctionPerGOF,correctionPerSec,
642 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,
643 0x0000,src_delay_buffer_addr,
645 0x080,(src_delay_buffer_addr + (24 * 4)),
646 0,0, /* next_scb, sub_list_ptr */
647 0,0, /* entry, this_spb */
648 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
649 src_buffer_addr << 0x10,
652 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left,
653 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left
657 if (ins->s16_up == NULL) {
658 ins->s16_up = cs46xx_dsp_lookup_symbol (chip,"S16_UPSRC",
661 if (ins->s16_up == NULL) {
662 snd_printk (KERN_ERR "dsp_spos: symbol S16_UPSRC not found\n");
668 _dsp_clear_sample_buffer (chip,src_buffer_addr,8);
669 _dsp_clear_sample_buffer (chip,src_delay_buffer_addr,32);
672 /* wont work with any other rate than
673 the native DSP rate */
674 snd_assert (rate = 48000);
676 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
677 dest,"DMAREADER",parent_scb,
680 scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
681 dest,ins->s16_up,parent_scb,
692 struct dsp_scb_descriptor *
693 cs46xx_dsp_create_filter_scb(struct snd_cs46xx * chip, char * scb_name,
694 u16 buffer_addr, u32 dest,
695 struct dsp_scb_descriptor * parent_scb,
696 int scb_child_type) {
697 struct dsp_scb_descriptor * scb;
699 struct dsp_filter_scb filter_scb = {
707 .filter_unused3 = 0x0000,
708 .filter_unused2 = 0x0000,
710 .output_buf_ptr = buffer_addr,
713 .prev_sample_output1 = 0x00000000,
714 .prev_sample_output2 = 0x00000000,
716 .prev_sample_input1 = 0x00000000,
717 .prev_sample_input2 = 0x00000000,
719 .next_scb_ptr = 0x0000,
720 .sub_list_ptr = 0x0000,
722 .entry_point = 0x0000,
734 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&filter_scb,
735 dest,"FILTERTASK",parent_scb,
740 #endif /* not used */
742 struct dsp_scb_descriptor *
743 cs46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name,
744 u16 mix_buffer_addr, u32 dest,
745 struct dsp_scb_descriptor * parent_scb,
748 struct dsp_scb_descriptor * scb;
750 struct dsp_mix_only_scb master_mix_scb = {
753 /* 2 */ mix_buffer_addr,
765 /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,
766 /* C */ (mix_buffer_addr + (16 * 4)) << 0x10,
769 /* E */ 0x8000,0x8000,
770 /* F */ 0x8000,0x8000
775 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&master_mix_scb,
776 dest,"S16_MIX",parent_scb,
782 struct dsp_scb_descriptor *
783 cs46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name,
784 u16 mix_buffer_addr, u16 writeback_spb, u32 dest,
785 struct dsp_scb_descriptor * parent_scb,
788 struct dsp_scb_descriptor * scb;
790 struct dsp_mix2_ostream_scb mix2_ostream_scb = {
791 /* Basic (non scatter/gather) DMA requestor (4 ints) */
793 DMA_RQ_C1_SOURCE_MOD64 +
794 DMA_RQ_C1_DEST_ON_HOST +
795 DMA_RQ_C1_DEST_MOD1024 +
796 DMA_RQ_C1_WRITEBACK_SRC_FLAG +
797 DMA_RQ_C1_WRITEBACK_DEST_FLAG +
801 DMA_RQ_C2_SIGNAL_DEST_PINGPONG +
803 CS46XX_DSP_CAPTURE_CHANNEL,
804 DMA_RQ_SD_SP_SAMPLE_ADDR +
813 RSCONFIG_DMA_ENABLE +
814 (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) +
816 ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) +
817 RSCONFIG_DMA_TO_HOST +
818 RSCONFIG_SAMPLE_16STEREO +
820 (mix_buffer_addr + (32 * 4)) << 0x10,
827 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&mix2_ostream_scb,
829 dest,"S16_MIX_TO_OSTREAM",parent_scb,
836 struct dsp_scb_descriptor *
837 cs46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip,char * scb_name,
838 u16 vari_buffer_addr0,
839 u16 vari_buffer_addr1,
841 struct dsp_scb_descriptor * parent_scb,
845 struct dsp_scb_descriptor * scb;
847 struct dsp_vari_decimate_scb vari_decimate_scb = {
851 vari_buffer_addr0,vari_buffer_addr1,
854 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256,
858 0x0080,vari_buffer_addr1 + (25 * 4),
863 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
864 vari_buffer_addr0 << 0x10,
872 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&vari_decimate_scb,
873 dest,"VARIDECIMATE",parent_scb,
880 static struct dsp_scb_descriptor *
881 cs46xx_dsp_create_pcm_serial_input_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
882 struct dsp_scb_descriptor * input_scb,
883 struct dsp_scb_descriptor * parent_scb,
887 struct dsp_scb_descriptor * scb;
890 struct dsp_pcm_serial_input_scb pcm_serial_input_scb = {
907 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_16,
909 /* 0xD */ 0,input_scb->address,
911 /* 0xE */ 0x8000,0x8000,
912 /* 0xF */ 0x8000,0x8000
916 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_serial_input_scb,
917 dest,"PCMSERIALINPUTTASK",parent_scb,
923 static struct dsp_scb_descriptor *
924 cs46xx_dsp_create_asynch_fg_tx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
926 u16 asynch_buffer_address,
927 struct dsp_scb_descriptor * parent_scb,
931 struct dsp_scb_descriptor * scb;
933 struct dsp_asynch_fg_tx_scb asynch_fg_tx_scb = {
934 0xfc00,0x03ff, /* Prototype sample buffer size of 256 dwords */
935 0x0058,0x0028, /* Min Delta 7 dwords == 28 bytes */
936 /* : Max delta 25 dwords == 100 bytes */
937 0,hfg_scb_address, /* Point to HFG task SCB */
938 0,0, /* Initialize current Delta and Consumer ptr adjustment count */
939 0, /* Initialize accumulated Phi to 0 */
940 0,0x2aab, /* Const 1/3 */
943 0, /* Define the unused elements */
949 0,dest + AFGTxAccumPhi,
951 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256, /* Stereo, 256 dword */
952 (asynch_buffer_address) << 0x10, /* This should be automagically synchronized
953 to the producer pointer */
955 /* There is no correct initial value, it will depend upon the detected
957 0x18000000, /* Phi increment for approx 32k operation */
958 0x8000,0x8000, /* Volume controls are unused at this time */
962 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_tx_scb,
963 dest,"ASYNCHFGTXCODE",parent_scb,
970 struct dsp_scb_descriptor *
971 cs46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
973 u16 asynch_buffer_address,
974 struct dsp_scb_descriptor * parent_scb,
977 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
978 struct dsp_scb_descriptor * scb;
980 struct dsp_asynch_fg_rx_scb asynch_fg_rx_scb = {
981 0xfe00,0x01ff, /* Prototype sample buffer size of 128 dwords */
982 0x0064,0x001c, /* Min Delta 7 dwords == 28 bytes */
983 /* : Max delta 25 dwords == 100 bytes */
984 0,hfg_scb_address, /* Point to HFG task SCB */
985 0,0, /* Initialize current Delta and Consumer ptr adjustment count */
987 0, /* Define the unused elements */
997 RSCONFIG_MODULO_128 |
998 RSCONFIG_SAMPLE_16STEREO, /* Stereo, 128 dword */
999 ( (asynch_buffer_address + (16 * 4)) << 0x10), /* This should be automagically
1000 synchrinized to the producer pointer */
1002 /* There is no correct initial value, it will depend upon the detected
1006 /* Set IEC958 input volume */
1007 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
1008 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
1011 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_rx_scb,
1012 dest,"ASYNCHFGRXCODE",parent_scb,
1019 #if 0 /* not used */
1020 struct dsp_scb_descriptor *
1021 cs46xx_dsp_create_output_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
1022 u16 snoop_buffer_address,
1023 struct dsp_scb_descriptor * snoop_scb,
1024 struct dsp_scb_descriptor * parent_scb,
1028 struct dsp_scb_descriptor * scb;
1030 struct dsp_output_snoop_scb output_snoop_scb = {
1031 { 0, /* not used. Zero */
1037 0, /* not used. Zero */
1047 RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
1048 snoop_buffer_address << 0x10,
1051 0,snoop_scb->address
1054 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&output_snoop_scb,
1055 dest,"OUTPUTSNOOP",parent_scb,
1059 #endif /* not used */
1062 struct dsp_scb_descriptor *
1063 cs46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
1064 struct dsp_scb_descriptor * parent_scb,
1067 struct dsp_scb_descriptor * scb;
1069 struct dsp_spio_write_scb spio_write_scb = {
1070 0,0, /* SPIOWAddress2:SPIOWAddress1; */
1071 0, /* SPIOWData1; */
1072 0, /* SPIOWData2; */
1073 0,0, /* SPIOWAddress4:SPIOWAddress3; */
1074 0, /* SPIOWData3; */
1075 0, /* SPIOWData4; */
1076 0,0, /* SPIOWDataPtr:Unused1; */
1077 { 0,0 }, /* Unused2[2]; */
1079 0,0, /* SPIOWChildPtr:SPIOWSiblingPtr; */
1080 0,0, /* SPIOWThisPtr:SPIOWEntryPoint; */
1091 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&spio_write_scb,
1092 dest,"SPIOWRITE",parent_scb,
1098 struct dsp_scb_descriptor *
1099 cs46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
1100 u16 snoop_buffer_address,
1101 struct dsp_scb_descriptor * snoop_scb,
1102 struct dsp_scb_descriptor * parent_scb,
1105 struct dsp_scb_descriptor * scb;
1107 struct dsp_magic_snoop_task magic_snoop_scb = {
1110 /* 2 */ snoop_buffer_address << 0x10,
1111 /* 3 */ 0,snoop_scb->address,
1117 /* 9 */ 0,0, /* next_scb, sub_list_ptr */
1118 /* A */ 0,0, /* entry_point, this_ptr */
1119 /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
1120 /* C */ snoop_buffer_address << 0x10,
1122 /* E */ { 0x8000,0x8000,
1123 /* F */ 0xffff,0xffff
1127 scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&magic_snoop_scb,
1128 dest,"MAGICSNOOPTASK",parent_scb,
1134 static struct dsp_scb_descriptor *
1135 find_next_free_scb (struct snd_cs46xx * chip, struct dsp_scb_descriptor * from)
1137 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1138 struct dsp_scb_descriptor * scb = from;
1140 while (scb->next_scb_ptr != ins->the_null_scb) {
1141 snd_assert (scb->next_scb_ptr != NULL, return NULL);
1143 scb = scb->next_scb_ptr;
1149 static u32 pcm_reader_buffer_addr[DSP_MAX_PCM_CHANNELS] = {
1184 static u32 src_output_buffer_addr[DSP_MAX_SRC_NR] = {
1201 static u32 src_delay_buffer_addr[DSP_MAX_SRC_NR] = {
1218 struct dsp_pcm_channel_descriptor *
1219 cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
1220 u32 sample_rate, void * private_data,
1224 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1225 struct dsp_scb_descriptor * src_scb = NULL, * pcm_scb, * mixer_scb = NULL;
1226 struct dsp_scb_descriptor * src_parent_scb = NULL;
1228 /* struct dsp_scb_descriptor * pcm_parent_scb; */
1229 char scb_name[DSP_MAX_SCB_NAME];
1230 int i, pcm_index = -1, insert_point, src_index = -1, pass_through = 0;
1231 unsigned long flags;
1233 switch (pcm_channel_id) {
1234 case DSP_PCM_MAIN_CHANNEL:
1235 mixer_scb = ins->master_mix_scb;
1237 case DSP_PCM_REAR_CHANNEL:
1238 mixer_scb = ins->rear_mix_scb;
1240 case DSP_PCM_CENTER_LFE_CHANNEL:
1241 mixer_scb = ins->center_lfe_mix_scb;
1243 case DSP_PCM_S71_CHANNEL:
1247 case DSP_IEC958_CHANNEL:
1248 snd_assert (ins->asynch_tx_scb != NULL, return NULL);
1249 mixer_scb = ins->asynch_tx_scb;
1251 /* if sample rate is set to 48khz we pass
1252 the Sample Rate Converted (which could
1253 alter the raw data stream ...) */
1254 if (sample_rate == 48000) {
1255 snd_printdd ("IEC958 pass through\n");
1256 /* Hack to bypass creating a new SRC */
1264 /* default sample rate is 44100 */
1265 if (!sample_rate) sample_rate = 44100;
1267 /* search for a already created SRC SCB with the same sample rate */
1268 for (i = 0; i < DSP_MAX_PCM_CHANNELS &&
1269 (pcm_index == -1 || src_scb == NULL); ++i) {
1271 /* virtual channel reserved
1273 if (i == CS46XX_DSP_CAPTURE_CHANNEL) continue;
1275 if (ins->pcm_channels[i].active) {
1277 ins->pcm_channels[i].sample_rate == sample_rate &&
1278 ins->pcm_channels[i].mixer_scb == mixer_scb) {
1279 src_scb = ins->pcm_channels[i].src_scb;
1280 ins->pcm_channels[i].src_scb->ref_count ++;
1281 src_index = ins->pcm_channels[i].src_slot;
1283 } else if (pcm_index == -1) {
1288 if (pcm_index == -1) {
1289 snd_printk (KERN_ERR "dsp_spos: no free PCM channel\n");
1293 if (src_scb == NULL) {
1294 if (ins->nsrc_scb >= DSP_MAX_SRC_NR) {
1295 snd_printk(KERN_ERR "dsp_spos: to many SRC instances\n!");
1299 /* find a free slot */
1300 for (i = 0; i < DSP_MAX_SRC_NR; ++i) {
1301 if (ins->src_scb_slots[i] == 0) {
1303 ins->src_scb_slots[i] = 1;
1307 snd_assert (src_index != -1,return NULL);
1309 /* we need to create a new SRC SCB */
1310 if (mixer_scb->sub_list_ptr == ins->the_null_scb) {
1311 src_parent_scb = mixer_scb;
1312 insert_point = SCB_ON_PARENT_SUBLIST_SCB;
1314 src_parent_scb = find_next_free_scb(chip,mixer_scb->sub_list_ptr);
1315 insert_point = SCB_ON_PARENT_NEXT_SCB;
1318 snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index);
1320 snd_printdd( "dsp_spos: creating SRC \"%s\"\n",scb_name);
1321 src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name,
1323 src_output_buffer_addr[src_index],
1324 src_delay_buffer_addr[src_index],
1325 /* 0x400 - 0x600 source SCBs */
1326 0x400 + (src_index * 0x10) ,
1332 snd_printk (KERN_ERR "dsp_spos: failed to create SRCtaskSCB\n");
1336 /* cs46xx_dsp_set_src_sample_rate(chip,src_scb,sample_rate); */
1342 snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index);
1344 snd_printdd( "dsp_spos: creating PCM \"%s\" (%d)\n",scb_name,
1347 pcm_scb = cs46xx_dsp_create_pcm_reader_scb(chip,scb_name,
1348 pcm_reader_buffer_addr[pcm_index],
1349 /* 0x200 - 400 PCMreader SCBs */
1350 (pcm_index * 0x10) + 0x200,
1351 pcm_index, /* virtual channel 0-31 */
1352 hw_dma_addr, /* pcm hw addr */
1353 NULL, /* parent SCB ptr */
1354 0 /* insert point */
1358 snd_printk (KERN_ERR "dsp_spos: failed to create PCMreaderSCB\n");
1362 spin_lock_irqsave(&chip->reg_lock, flags);
1363 ins->pcm_channels[pcm_index].sample_rate = sample_rate;
1364 ins->pcm_channels[pcm_index].pcm_reader_scb = pcm_scb;
1365 ins->pcm_channels[pcm_index].src_scb = src_scb;
1366 ins->pcm_channels[pcm_index].unlinked = 1;
1367 ins->pcm_channels[pcm_index].private_data = private_data;
1368 ins->pcm_channels[pcm_index].src_slot = src_index;
1369 ins->pcm_channels[pcm_index].active = 1;
1370 ins->pcm_channels[pcm_index].pcm_slot = pcm_index;
1371 ins->pcm_channels[pcm_index].mixer_scb = mixer_scb;
1372 ins->npcm_channels ++;
1373 spin_unlock_irqrestore(&chip->reg_lock, flags);
1375 return (ins->pcm_channels + pcm_index);
1378 int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip,
1379 struct dsp_pcm_channel_descriptor * pcm_channel,
1382 u32 temp = snd_cs46xx_peek (chip,pcm_channel->pcm_reader_scb->address << 2);
1383 temp &= ~DMA_RQ_C1_SOURCE_SIZE_MASK;
1385 switch (period_size) {
1387 temp |= DMA_RQ_C1_SOURCE_MOD1024;
1390 temp |= DMA_RQ_C1_SOURCE_MOD512;
1393 temp |= DMA_RQ_C1_SOURCE_MOD256;
1396 temp |= DMA_RQ_C1_SOURCE_MOD128;
1399 temp |= DMA_RQ_C1_SOURCE_MOD64;
1402 temp |= DMA_RQ_C1_SOURCE_MOD32;
1405 temp |= DMA_RQ_C1_SOURCE_MOD16;
1408 snd_printdd ("period size (%d) not supported by HW\n", period_size);
1412 snd_cs46xx_poke (chip,pcm_channel->pcm_reader_scb->address << 2,temp);
1417 int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip,
1420 u32 temp = snd_cs46xx_peek (chip,WRITEBACK_SCB_ADDR << 2);
1421 temp &= ~DMA_RQ_C1_DEST_SIZE_MASK;
1423 switch (period_size) {
1425 temp |= DMA_RQ_C1_DEST_MOD1024;
1428 temp |= DMA_RQ_C1_DEST_MOD512;
1431 temp |= DMA_RQ_C1_DEST_MOD256;
1434 temp |= DMA_RQ_C1_DEST_MOD128;
1437 temp |= DMA_RQ_C1_DEST_MOD64;
1440 temp |= DMA_RQ_C1_DEST_MOD32;
1443 temp |= DMA_RQ_C1_DEST_MOD16;
1446 snd_printdd ("period size (%d) not supported by HW\n", period_size);
1450 snd_cs46xx_poke (chip,WRITEBACK_SCB_ADDR << 2,temp);
1455 void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
1456 struct dsp_pcm_channel_descriptor * pcm_channel)
1458 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1459 unsigned long flags;
1461 snd_assert(pcm_channel->active, return );
1462 snd_assert(ins->npcm_channels > 0, return );
1463 snd_assert(pcm_channel->src_scb->ref_count > 0, return );
1465 spin_lock_irqsave(&chip->reg_lock, flags);
1466 pcm_channel->unlinked = 1;
1467 pcm_channel->active = 0;
1468 pcm_channel->private_data = NULL;
1469 pcm_channel->src_scb->ref_count --;
1470 ins->npcm_channels --;
1471 spin_unlock_irqrestore(&chip->reg_lock, flags);
1473 cs46xx_dsp_remove_scb(chip,pcm_channel->pcm_reader_scb);
1475 if (!pcm_channel->src_scb->ref_count) {
1476 cs46xx_dsp_remove_scb(chip,pcm_channel->src_scb);
1478 snd_assert (pcm_channel->src_slot >= 0 && pcm_channel->src_slot <= DSP_MAX_SRC_NR,
1481 ins->src_scb_slots[pcm_channel->src_slot] = 0;
1486 int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
1487 struct dsp_pcm_channel_descriptor * pcm_channel)
1489 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1490 unsigned long flags;
1492 snd_assert(pcm_channel->active,return -EIO);
1493 snd_assert(ins->npcm_channels > 0,return -EIO);
1495 spin_lock(&pcm_channel->src_scb->lock);
1497 if (pcm_channel->unlinked) {
1498 spin_unlock(&pcm_channel->src_scb->lock);
1502 spin_lock_irqsave(&chip->reg_lock, flags);
1503 pcm_channel->unlinked = 1;
1504 spin_unlock_irqrestore(&chip->reg_lock, flags);
1506 _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb);
1508 spin_unlock(&pcm_channel->src_scb->lock);
1512 int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
1513 struct dsp_pcm_channel_descriptor * pcm_channel)
1515 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1516 struct dsp_scb_descriptor * parent_scb;
1517 struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb;
1518 unsigned long flags;
1520 spin_lock(&pcm_channel->src_scb->lock);
1522 if (pcm_channel->unlinked == 0) {
1523 spin_unlock(&pcm_channel->src_scb->lock);
1527 parent_scb = src_scb;
1529 if (src_scb->sub_list_ptr != ins->the_null_scb) {
1530 src_scb->sub_list_ptr->parent_scb_ptr = pcm_channel->pcm_reader_scb;
1531 pcm_channel->pcm_reader_scb->next_scb_ptr = src_scb->sub_list_ptr;
1534 src_scb->sub_list_ptr = pcm_channel->pcm_reader_scb;
1536 snd_assert (pcm_channel->pcm_reader_scb->parent_scb_ptr == NULL, ; );
1537 pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb;
1539 spin_lock_irqsave(&chip->reg_lock, flags);
1541 /* update SCB entry in DSP RAM */
1542 cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb);
1544 /* update parent SCB entry */
1545 cs46xx_dsp_spos_update_scb(chip,parent_scb);
1547 pcm_channel->unlinked = 0;
1548 spin_unlock_irqrestore(&chip->reg_lock, flags);
1550 spin_unlock(&pcm_channel->src_scb->lock);
1554 struct dsp_scb_descriptor *
1555 cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source,
1556 u16 addr, char * scb_name)
1558 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1559 struct dsp_scb_descriptor * parent;
1560 struct dsp_scb_descriptor * pcm_input;
1563 snd_assert (ins->record_mixer_scb != NULL,return NULL);
1565 if (ins->record_mixer_scb->sub_list_ptr != ins->the_null_scb) {
1566 parent = find_next_free_scb (chip,ins->record_mixer_scb->sub_list_ptr);
1567 insert_point = SCB_ON_PARENT_NEXT_SCB;
1569 parent = ins->record_mixer_scb;
1570 insert_point = SCB_ON_PARENT_SUBLIST_SCB;
1573 pcm_input = cs46xx_dsp_create_pcm_serial_input_scb(chip,scb_name,addr,
1580 int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
1582 snd_assert (src->parent_scb_ptr != NULL, return -EINVAL );
1585 cs46xx_dsp_scb_set_volume (chip,src,0,0);
1587 _dsp_unlink_scb (chip,src);
1592 int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
1594 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1595 struct dsp_scb_descriptor * parent_scb;
1597 snd_assert (src->parent_scb_ptr == NULL, return -EINVAL );
1598 snd_assert(ins->master_mix_scb !=NULL, return -EINVAL );
1600 if (ins->master_mix_scb->sub_list_ptr != ins->the_null_scb) {
1601 parent_scb = find_next_free_scb (chip,ins->master_mix_scb->sub_list_ptr);
1602 parent_scb->next_scb_ptr = src;
1604 parent_scb = ins->master_mix_scb;
1605 parent_scb->sub_list_ptr = src;
1608 src->parent_scb_ptr = parent_scb;
1610 /* update entry in DSP RAM */
1611 cs46xx_dsp_spos_update_scb(chip,parent_scb);
1616 int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip)
1618 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1620 if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) {
1621 cs46xx_dsp_enable_spdif_hw (chip);
1624 /* dont touch anything if SPDIF is open */
1625 if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) {
1626 /* when cs46xx_iec958_post_close(...) is called it
1627 will call this function if necessary depending on
1629 ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
1634 snd_assert (ins->asynch_tx_scb == NULL, return -EINVAL);
1635 snd_assert (ins->master_mix_scb->next_scb_ptr == ins->the_null_scb, return -EINVAL);
1637 /* reset output snooper sample buffer pointer */
1638 snd_cs46xx_poke (chip, (ins->ref_snoop_scb->address + 2) << 2,
1639 (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10 );
1641 /* The asynch. transfer task */
1642 ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR,
1644 SPDIFO_IP_OUTPUT_BUFFER1,
1645 ins->master_mix_scb,
1646 SCB_ON_PARENT_NEXT_SCB);
1647 if (!ins->asynch_tx_scb) return -ENOMEM;
1649 ins->spdif_pcm_input_scb = cs46xx_dsp_create_pcm_serial_input_scb(chip,"PCMSerialInput_II",
1650 PCMSERIALINII_SCB_ADDR,
1653 SCB_ON_PARENT_SUBLIST_SCB);
1656 if (!ins->spdif_pcm_input_scb) return -ENOMEM;
1659 ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
1664 int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip)
1666 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1668 /* dont touch anything if SPDIF is open */
1669 if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) {
1670 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED;
1674 /* check integrety */
1675 snd_assert (ins->asynch_tx_scb != NULL, return -EINVAL);
1676 snd_assert (ins->spdif_pcm_input_scb != NULL,return -EINVAL);
1677 snd_assert (ins->master_mix_scb->next_scb_ptr == ins->asynch_tx_scb, return -EINVAL);
1678 snd_assert (ins->asynch_tx_scb->parent_scb_ptr == ins->master_mix_scb, return -EINVAL);
1680 cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
1681 cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
1683 ins->spdif_pcm_input_scb = NULL;
1684 ins->asynch_tx_scb = NULL;
1686 /* clear buffer to prevent any undesired noise */
1687 _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256);
1690 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED;
1696 int cs46xx_iec958_pre_open (struct snd_cs46xx *chip)
1698 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1700 if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) {
1701 /* remove AsynchFGTxSCB and and PCMSerialInput_II */
1702 cs46xx_dsp_disable_spdif_out (chip);
1705 ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
1708 /* if not enabled already */
1709 if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) {
1710 cs46xx_dsp_enable_spdif_hw (chip);
1713 /* Create the asynch. transfer task for playback */
1714 ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR,
1716 SPDIFO_IP_OUTPUT_BUFFER1,
1717 ins->master_mix_scb,
1718 SCB_ON_PARENT_NEXT_SCB);
1721 /* set spdif channel status value for streaming */
1722 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_stream);
1724 ins->spdif_status_out |= DSP_SPDIF_STATUS_PLAYBACK_OPEN;
1729 int cs46xx_iec958_post_close (struct snd_cs46xx *chip)
1731 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1733 snd_assert (ins->asynch_tx_scb != NULL, return -EINVAL);
1735 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN;
1737 /* restore settings */
1738 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
1740 /* deallocate stuff */
1741 if (ins->spdif_pcm_input_scb != NULL) {
1742 cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
1743 ins->spdif_pcm_input_scb = NULL;
1746 cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
1747 ins->asynch_tx_scb = NULL;
1749 /* clear buffer to prevent any undesired noise */
1750 _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256);
1753 if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) {
1754 cs46xx_dsp_enable_spdif_out (chip);