2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * 2002-07 Benny Sjostrand benny@hostmobility.com
24 #include <linux/delay.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/vmalloc.h>
29 #include <linux/mutex.h>
31 #include <sound/core.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
34 #include <sound/asoundef.h>
37 #include "cs46xx_lib.h"
40 static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
41 struct dsp_scb_descriptor * fg_entry);
43 static enum wide_opcode wide_opcodes[] = {
48 WIDE_TBEQ_COND_GOTO_ADDR,
49 WIDE_TBEQ_COND_CALL_ADDR,
50 WIDE_TBEQ_NCOND_GOTO_ADDR,
51 WIDE_TBEQ_NCOND_CALL_ADDR,
52 WIDE_TBEQ_COND_GOTO1_ADDR,
53 WIDE_TBEQ_COND_CALL1_ADDR,
54 WIDE_TBEQ_NCOND_GOTOI_ADDR,
55 WIDE_TBEQ_NCOND_CALL1_ADDR
58 static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32 size,
59 u32 overlay_begin_address)
61 unsigned int i = 0, j, nreallocated = 0;
62 u32 hival,loval,address;
63 u32 mop_operands,mop_type,wide_op;
64 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
66 if (snd_BUG_ON(size %2))
73 if (ins->code.offset > 0) {
74 mop_operands = (hival >> 6) & 0x03fff;
75 mop_type = mop_operands >> 10;
77 /* check for wide type instruction */
79 (mop_operands & WIDE_LADD_INSTR_MASK) == 0 &&
80 (mop_operands & WIDE_INSTR_MASK) != 0) {
81 wide_op = loval & 0x7f;
82 for (j = 0;j < ARRAY_SIZE(wide_opcodes); ++j) {
83 if (wide_opcodes[j] == wide_op) {
84 /* need to reallocate instruction */
85 address = (hival & 0x00FFF) << 5;
86 address |= loval >> 15;
88 dev_dbg(chip->card->dev,
89 "handle_wideop[1]: %05x:%05x addr %04x\n",
90 hival, loval, address);
92 if ( !(address & 0x8000) ) {
93 address += (ins->code.offset / 2) - overlay_begin_address;
95 dev_dbg(chip->card->dev,
96 "handle_wideop[1]: ROM symbol not reallocated\n");
102 hival |= ( (address >> 5) & 0x00FFF);
103 loval |= ( (address << 15) & 0xF8000);
105 address = (hival & 0x00FFF) << 5;
106 address |= loval >> 15;
108 dev_dbg(chip->card->dev,
109 "handle_wideop:[2] %05x:%05x addr %04x\n",
110 hival, loval, address);
112 } /* wide_opcodes[j] == wide_op */
114 } /* mod_type == 0 ... */
115 } /* ins->code.offset > 0 */
117 ins->code.data[ins->code.size++] = loval;
118 ins->code.data[ins->code.size++] = hival;
121 dev_dbg(chip->card->dev,
122 "dsp_spos: %d instructions reallocated\n", nreallocated);
126 static struct dsp_segment_desc * get_segment_desc (struct dsp_module_desc * module, int seg_type)
129 for (i = 0;i < module->nsegments; ++i) {
130 if (module->segments[i].segment_type == seg_type) {
131 return (module->segments + i);
138 static int find_free_symbol_index (struct dsp_spos_instance * ins)
140 int index = ins->symbol_table.nsymbols,i;
142 for (i = ins->symbol_table.highest_frag_index; i < ins->symbol_table.nsymbols; ++i) {
143 if (ins->symbol_table.symbols[i].deleted) {
152 static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * module)
155 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
157 if (module->symbol_table.nsymbols > 0) {
158 if (!strcmp(module->symbol_table.symbols[0].symbol_name, "OVERLAYBEGINADDRESS") &&
159 module->symbol_table.symbols[0].symbol_type == SYMBOL_CONSTANT ) {
160 module->overlay_begin_address = module->symbol_table.symbols[0].address;
164 for (i = 0;i < module->symbol_table.nsymbols; ++i) {
165 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
166 dev_err(chip->card->dev,
167 "dsp_spos: symbol table is full\n");
172 if (cs46xx_dsp_lookup_symbol(chip,
173 module->symbol_table.symbols[i].symbol_name,
174 module->symbol_table.symbols[i].symbol_type) == NULL) {
176 ins->symbol_table.symbols[ins->symbol_table.nsymbols] = module->symbol_table.symbols[i];
177 ins->symbol_table.symbols[ins->symbol_table.nsymbols].address += ((ins->code.offset / 2) - module->overlay_begin_address);
178 ins->symbol_table.symbols[ins->symbol_table.nsymbols].module = module;
179 ins->symbol_table.symbols[ins->symbol_table.nsymbols].deleted = 0;
181 if (ins->symbol_table.nsymbols > ins->symbol_table.highest_frag_index)
182 ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols;
184 ins->symbol_table.nsymbols++;
187 dev_dbg(chip->card->dev,
188 "dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n",
189 module->symbol_table.symbols[i].symbol_name); */
197 static struct dsp_symbol_entry *
198 add_symbol (struct snd_cs46xx * chip, char * symbol_name, u32 address, int type)
200 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
201 struct dsp_symbol_entry * symbol = NULL;
204 if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
205 dev_err(chip->card->dev, "dsp_spos: symbol table is full\n");
209 if (cs46xx_dsp_lookup_symbol(chip,
212 dev_err(chip->card->dev,
213 "dsp_spos: symbol <%s> duplicated\n", symbol_name);
217 index = find_free_symbol_index (ins);
219 strcpy (ins->symbol_table.symbols[index].symbol_name, symbol_name);
220 ins->symbol_table.symbols[index].address = address;
221 ins->symbol_table.symbols[index].symbol_type = type;
222 ins->symbol_table.symbols[index].module = NULL;
223 ins->symbol_table.symbols[index].deleted = 0;
224 symbol = (ins->symbol_table.symbols + index);
226 if (index > ins->symbol_table.highest_frag_index)
227 ins->symbol_table.highest_frag_index = index;
229 if (index == ins->symbol_table.nsymbols)
230 ins->symbol_table.nsymbols++; /* no frag. in list */
235 struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
237 struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL);
242 /* better to use vmalloc for this big table */
243 ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) *
245 ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
246 ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
247 if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
248 cs46xx_dsp_spos_destroy(chip);
251 ins->symbol_table.nsymbols = 0;
252 ins->symbol_table.highest_frag_index = 0;
253 ins->code.offset = 0;
259 /* default SPDIF input sample rate
261 ins->spdif_in_sample_rate = 48000;
263 /* maximize volume */
264 ins->dac_volume_right = 0x8000;
265 ins->dac_volume_left = 0x8000;
266 ins->spdif_input_volume_right = 0x8000;
267 ins->spdif_input_volume_left = 0x8000;
269 /* set left and right validity bits and
270 default channel status */
271 ins->spdif_csuv_default =
272 ins->spdif_csuv_stream =
273 /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) |
274 /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) |
275 /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
276 /* left and right validity bits */ (1 << 13) | (1 << 12);
282 kfree(ins->code.data);
283 vfree(ins->symbol_table.symbols);
288 void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
291 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
293 if (snd_BUG_ON(!ins))
296 mutex_lock(&chip->spos_mutex);
297 for (i = 0; i < ins->nscb; ++i) {
298 if (ins->scbs[i].deleted) continue;
300 cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
301 #ifdef CONFIG_PM_SLEEP
302 kfree(ins->scbs[i].data);
306 kfree(ins->code.data);
307 vfree(ins->symbol_table.symbols);
310 mutex_unlock(&chip->spos_mutex);
313 static int dsp_load_parameter(struct snd_cs46xx *chip,
314 struct dsp_segment_desc *parameter)
319 dev_dbg(chip->card->dev,
320 "dsp_spos: module got no parameter segment\n");
324 doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET);
325 dsize = parameter->size * 4;
327 dev_dbg(chip->card->dev,
328 "dsp_spos: downloading parameter data to chip (%08x-%08x)\n",
329 doffset,doffset + dsize);
330 if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) {
331 dev_err(chip->card->dev,
332 "dsp_spos: failed to download parameter data to DSP\n");
338 static int dsp_load_sample(struct snd_cs46xx *chip,
339 struct dsp_segment_desc *sample)
344 dev_dbg(chip->card->dev,
345 "dsp_spos: module got no sample segment\n");
349 doffset = (sample->offset * 4 + DSP_SAMPLE_BYTE_OFFSET);
350 dsize = sample->size * 4;
352 dev_dbg(chip->card->dev,
353 "dsp_spos: downloading sample data to chip (%08x-%08x)\n",
354 doffset,doffset + dsize);
356 if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) {
357 dev_err(chip->card->dev,
358 "dsp_spos: failed to sample data to DSP\n");
364 int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module)
366 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
367 struct dsp_segment_desc * code = get_segment_desc (module,SEGTYPE_SP_PROGRAM);
371 if (ins->nmodules == DSP_MAX_MODULES - 1) {
372 dev_err(chip->card->dev,
373 "dsp_spos: to many modules loaded into DSP\n");
377 dev_dbg(chip->card->dev,
378 "dsp_spos: loading module %s into DSP\n", module->module_name);
380 if (ins->nmodules == 0) {
381 dev_dbg(chip->card->dev, "dsp_spos: clearing parameter area\n");
382 snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE);
385 err = dsp_load_parameter(chip, get_segment_desc(module,
386 SEGTYPE_SP_PARAMETER));
390 if (ins->nmodules == 0) {
391 dev_dbg(chip->card->dev, "dsp_spos: clearing sample area\n");
392 snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE);
395 err = dsp_load_sample(chip, get_segment_desc(module,
400 if (ins->nmodules == 0) {
401 dev_dbg(chip->card->dev, "dsp_spos: clearing code area\n");
402 snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
406 dev_dbg(chip->card->dev,
407 "dsp_spos: module got no code segment\n");
409 if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) {
410 dev_err(chip->card->dev,
411 "dsp_spos: no space available in DSP\n");
415 module->load_address = ins->code.offset;
416 module->overlay_begin_address = 0x000;
418 /* if module has a code segment it must have
420 if (snd_BUG_ON(!module->symbol_table.symbols))
422 if (add_symbols(chip,module)) {
423 dev_err(chip->card->dev,
424 "dsp_spos: failed to load symbol table\n");
428 doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET);
429 dsize = code->size * 4;
430 dev_dbg(chip->card->dev,
431 "dsp_spos: downloading code to chip (%08x-%08x)\n",
432 doffset,doffset + dsize);
434 module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address);
436 if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) {
437 dev_err(chip->card->dev,
438 "dsp_spos: failed to download code to DSP\n");
442 ins->code.offset += code->size;
445 /* NOTE: module segments and symbol table must be
446 statically allocated. Case that module data is
447 not generated by the ospparser */
448 ins->modules[ins->nmodules] = *module;
454 struct dsp_symbol_entry *
455 cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, int symbol_type)
458 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
460 for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
462 if (ins->symbol_table.symbols[i].deleted)
465 if (!strcmp(ins->symbol_table.symbols[i].symbol_name,symbol_name) &&
466 ins->symbol_table.symbols[i].symbol_type == symbol_type) {
467 return (ins->symbol_table.symbols + i);
472 dev_err(chip->card->dev, "dsp_spos: symbol <%s> type %02x not found\n",
473 symbol_name,symbol_type);
480 #ifdef CONFIG_SND_PROC_FS
481 static struct dsp_symbol_entry *
482 cs46xx_dsp_lookup_symbol_addr (struct snd_cs46xx * chip, u32 address, int symbol_type)
485 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
487 for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
489 if (ins->symbol_table.symbols[i].deleted)
492 if (ins->symbol_table.symbols[i].address == address &&
493 ins->symbol_table.symbols[i].symbol_type == symbol_type) {
494 return (ins->symbol_table.symbols + i);
503 static void cs46xx_dsp_proc_symbol_table_read (struct snd_info_entry *entry,
504 struct snd_info_buffer *buffer)
506 struct snd_cs46xx *chip = entry->private_data;
507 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
510 snd_iprintf(buffer, "SYMBOLS:\n");
511 for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
512 char *module_str = "system";
514 if (ins->symbol_table.symbols[i].deleted)
517 if (ins->symbol_table.symbols[i].module != NULL) {
518 module_str = ins->symbol_table.symbols[i].module->module_name;
522 snd_iprintf(buffer, "%04X <%02X> %s [%s]\n",
523 ins->symbol_table.symbols[i].address,
524 ins->symbol_table.symbols[i].symbol_type,
525 ins->symbol_table.symbols[i].symbol_name,
531 static void cs46xx_dsp_proc_modules_read (struct snd_info_entry *entry,
532 struct snd_info_buffer *buffer)
534 struct snd_cs46xx *chip = entry->private_data;
535 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
538 mutex_lock(&chip->spos_mutex);
539 snd_iprintf(buffer, "MODULES:\n");
540 for ( i = 0; i < ins->nmodules; ++i ) {
541 snd_iprintf(buffer, "\n%s:\n", ins->modules[i].module_name);
542 snd_iprintf(buffer, " %d symbols\n", ins->modules[i].symbol_table.nsymbols);
543 snd_iprintf(buffer, " %d fixups\n", ins->modules[i].nfixups);
545 for (j = 0; j < ins->modules[i].nsegments; ++ j) {
546 struct dsp_segment_desc * desc = (ins->modules[i].segments + j);
547 snd_iprintf(buffer, " segment %02x offset %08x size %08x\n",
548 desc->segment_type,desc->offset, desc->size);
551 mutex_unlock(&chip->spos_mutex);
554 static void cs46xx_dsp_proc_task_tree_read (struct snd_info_entry *entry,
555 struct snd_info_buffer *buffer)
557 struct snd_cs46xx *chip = entry->private_data;
558 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
560 void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
562 mutex_lock(&chip->spos_mutex);
563 snd_iprintf(buffer, "TASK TREES:\n");
564 for ( i = 0; i < ins->ntask; ++i) {
565 snd_iprintf(buffer,"\n%04x %s:\n",ins->tasks[i].address,ins->tasks[i].task_name);
567 for (col = 0,j = 0;j < ins->tasks[i].size; j++,col++) {
570 snd_iprintf(buffer,"\n");
573 val = readl(dst + (ins->tasks[i].address + j) * sizeof(u32));
574 snd_iprintf(buffer,"%08x ",val);
578 snd_iprintf(buffer,"\n");
579 mutex_unlock(&chip->spos_mutex);
582 static void cs46xx_dsp_proc_scb_read (struct snd_info_entry *entry,
583 struct snd_info_buffer *buffer)
585 struct snd_cs46xx *chip = entry->private_data;
586 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
589 mutex_lock(&chip->spos_mutex);
590 snd_iprintf(buffer, "SCB's:\n");
591 for ( i = 0; i < ins->nscb; ++i) {
592 if (ins->scbs[i].deleted)
594 snd_iprintf(buffer,"\n%04x %s:\n\n",ins->scbs[i].address,ins->scbs[i].scb_name);
596 if (ins->scbs[i].parent_scb_ptr != NULL) {
597 snd_iprintf(buffer,"parent [%s:%04x] ",
598 ins->scbs[i].parent_scb_ptr->scb_name,
599 ins->scbs[i].parent_scb_ptr->address);
600 } else snd_iprintf(buffer,"parent [none] ");
602 snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n",
603 ins->scbs[i].sub_list_ptr->scb_name,
604 ins->scbs[i].sub_list_ptr->address,
605 ins->scbs[i].next_scb_ptr->scb_name,
606 ins->scbs[i].next_scb_ptr->address,
607 ins->scbs[i].task_entry->symbol_name,
608 ins->scbs[i].task_entry->address);
611 snd_iprintf(buffer,"\n");
612 mutex_unlock(&chip->spos_mutex);
615 static void cs46xx_dsp_proc_parameter_dump_read (struct snd_info_entry *entry,
616 struct snd_info_buffer *buffer)
618 struct snd_cs46xx *chip = entry->private_data;
619 /*struct dsp_spos_instance * ins = chip->dsp_spos_instance; */
620 unsigned int i, col = 0;
621 void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
622 struct dsp_symbol_entry * symbol;
624 for (i = 0;i < DSP_PARAMETER_BYTE_SIZE; i += sizeof(u32),col ++) {
626 snd_iprintf(buffer,"\n");
630 if ( (symbol = cs46xx_dsp_lookup_symbol_addr (chip,i / sizeof(u32), SYMBOL_PARAMETER)) != NULL) {
632 snd_iprintf (buffer,"\n%s:\n",symbol->symbol_name);
636 snd_iprintf(buffer, "%04X ", i / (unsigned int)sizeof(u32));
639 snd_iprintf(buffer,"%08X ",readl(dst + i));
643 static void cs46xx_dsp_proc_sample_dump_read (struct snd_info_entry *entry,
644 struct snd_info_buffer *buffer)
646 struct snd_cs46xx *chip = entry->private_data;
648 void __iomem *dst = chip->region.idx[2].remap_addr;
650 snd_iprintf(buffer,"PCMREADER:\n");
651 for (i = PCM_READER_BUF1;i < PCM_READER_BUF1 + 0x30; i += sizeof(u32),col ++) {
653 snd_iprintf(buffer,"\n");
658 snd_iprintf(buffer, "%04X ",i);
661 snd_iprintf(buffer,"%08X ",readl(dst + i));
664 snd_iprintf(buffer,"\nMIX_SAMPLE_BUF1:\n");
667 for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x40; i += sizeof(u32),col ++) {
669 snd_iprintf(buffer,"\n");
674 snd_iprintf(buffer, "%04X ",i);
677 snd_iprintf(buffer,"%08X ",readl(dst + i));
680 snd_iprintf(buffer,"\nSRC_TASK_SCB1:\n");
682 for (i = 0x2480 ; i < 0x2480 + 0x40 ; i += sizeof(u32),col ++) {
684 snd_iprintf(buffer,"\n");
689 snd_iprintf(buffer, "%04X ",i);
692 snd_iprintf(buffer,"%08X ",readl(dst + i));
696 snd_iprintf(buffer,"\nSPDIFO_BUFFER:\n");
698 for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x30; i += sizeof(u32),col ++) {
700 snd_iprintf(buffer,"\n");
705 snd_iprintf(buffer, "%04X ",i);
708 snd_iprintf(buffer,"%08X ",readl(dst + i));
711 snd_iprintf(buffer,"\n...\n");
714 for (i = SPDIFO_IP_OUTPUT_BUFFER1+0xD0;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x110; i += sizeof(u32),col ++) {
716 snd_iprintf(buffer,"\n");
721 snd_iprintf(buffer, "%04X ",i);
724 snd_iprintf(buffer,"%08X ",readl(dst + i));
728 snd_iprintf(buffer,"\nOUTPUT_SNOOP:\n");
730 for (i = OUTPUT_SNOOP_BUFFER;i < OUTPUT_SNOOP_BUFFER + 0x40; i += sizeof(u32),col ++) {
732 snd_iprintf(buffer,"\n");
737 snd_iprintf(buffer, "%04X ",i);
740 snd_iprintf(buffer,"%08X ",readl(dst + i));
743 snd_iprintf(buffer,"\nCODEC_INPUT_BUF1: \n");
745 for (i = CODEC_INPUT_BUF1;i < CODEC_INPUT_BUF1 + 0x40; i += sizeof(u32),col ++) {
747 snd_iprintf(buffer,"\n");
752 snd_iprintf(buffer, "%04X ",i);
755 snd_iprintf(buffer,"%08X ",readl(dst + i));
758 snd_iprintf(buffer,"\nWRITE_BACK_BUF1: \n");
760 for (i = WRITE_BACK_BUF1;i < WRITE_BACK_BUF1 + 0x40; i += sizeof(u32),col ++) {
762 snd_iprintf(buffer,"\n");
767 snd_iprintf(buffer, "%04X ",i);
770 snd_iprintf(buffer,"%08X ",readl(dst + i));
774 snd_iprintf(buffer,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n");
776 for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x80; i += sizeof(u32),col ++) {
778 snd_iprintf(buffer,"\n");
783 snd_iprintf(buffer, "%04X ",i);
786 snd_iprintf(buffer,"%08X ",readl(dst + i));
788 snd_iprintf(buffer,"\n");
791 int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip)
793 struct snd_info_entry *entry;
794 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
797 ins->snd_card = card;
799 if ((entry = snd_info_create_card_entry(card, "dsp", card->proc_root)) != NULL) {
800 entry->content = SNDRV_INFO_CONTENT_TEXT;
801 entry->mode = S_IFDIR | S_IRUGO | S_IXUGO;
803 if (snd_info_register(entry) < 0) {
804 snd_info_free_entry(entry);
809 ins->proc_dsp_dir = entry;
811 if (!ins->proc_dsp_dir)
814 if ((entry = snd_info_create_card_entry(card, "spos_symbols", ins->proc_dsp_dir)) != NULL) {
815 entry->content = SNDRV_INFO_CONTENT_TEXT;
816 entry->private_data = chip;
817 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
818 entry->c.text.read = cs46xx_dsp_proc_symbol_table_read;
819 if (snd_info_register(entry) < 0) {
820 snd_info_free_entry(entry);
824 ins->proc_sym_info_entry = entry;
826 if ((entry = snd_info_create_card_entry(card, "spos_modules", ins->proc_dsp_dir)) != NULL) {
827 entry->content = SNDRV_INFO_CONTENT_TEXT;
828 entry->private_data = chip;
829 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
830 entry->c.text.read = cs46xx_dsp_proc_modules_read;
831 if (snd_info_register(entry) < 0) {
832 snd_info_free_entry(entry);
836 ins->proc_modules_info_entry = entry;
838 if ((entry = snd_info_create_card_entry(card, "parameter", ins->proc_dsp_dir)) != NULL) {
839 entry->content = SNDRV_INFO_CONTENT_TEXT;
840 entry->private_data = chip;
841 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
842 entry->c.text.read = cs46xx_dsp_proc_parameter_dump_read;
843 if (snd_info_register(entry) < 0) {
844 snd_info_free_entry(entry);
848 ins->proc_parameter_dump_info_entry = entry;
850 if ((entry = snd_info_create_card_entry(card, "sample", ins->proc_dsp_dir)) != NULL) {
851 entry->content = SNDRV_INFO_CONTENT_TEXT;
852 entry->private_data = chip;
853 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
854 entry->c.text.read = cs46xx_dsp_proc_sample_dump_read;
855 if (snd_info_register(entry) < 0) {
856 snd_info_free_entry(entry);
860 ins->proc_sample_dump_info_entry = entry;
862 if ((entry = snd_info_create_card_entry(card, "task_tree", ins->proc_dsp_dir)) != NULL) {
863 entry->content = SNDRV_INFO_CONTENT_TEXT;
864 entry->private_data = chip;
865 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
866 entry->c.text.read = cs46xx_dsp_proc_task_tree_read;
867 if (snd_info_register(entry) < 0) {
868 snd_info_free_entry(entry);
872 ins->proc_task_info_entry = entry;
874 if ((entry = snd_info_create_card_entry(card, "scb_info", ins->proc_dsp_dir)) != NULL) {
875 entry->content = SNDRV_INFO_CONTENT_TEXT;
876 entry->private_data = chip;
877 entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
878 entry->c.text.read = cs46xx_dsp_proc_scb_read;
879 if (snd_info_register(entry) < 0) {
880 snd_info_free_entry(entry);
884 ins->proc_scb_info_entry = entry;
886 mutex_lock(&chip->spos_mutex);
887 /* register/update SCB's entries on proc */
888 for (i = 0; i < ins->nscb; ++i) {
889 if (ins->scbs[i].deleted) continue;
891 cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i));
893 mutex_unlock(&chip->spos_mutex);
898 int cs46xx_dsp_proc_done (struct snd_cs46xx *chip)
900 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
903 snd_info_free_entry(ins->proc_sym_info_entry);
904 ins->proc_sym_info_entry = NULL;
906 snd_info_free_entry(ins->proc_modules_info_entry);
907 ins->proc_modules_info_entry = NULL;
909 snd_info_free_entry(ins->proc_parameter_dump_info_entry);
910 ins->proc_parameter_dump_info_entry = NULL;
912 snd_info_free_entry(ins->proc_sample_dump_info_entry);
913 ins->proc_sample_dump_info_entry = NULL;
915 snd_info_free_entry(ins->proc_scb_info_entry);
916 ins->proc_scb_info_entry = NULL;
918 snd_info_free_entry(ins->proc_task_info_entry);
919 ins->proc_task_info_entry = NULL;
921 mutex_lock(&chip->spos_mutex);
922 for (i = 0; i < ins->nscb; ++i) {
923 if (ins->scbs[i].deleted) continue;
924 cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
926 mutex_unlock(&chip->spos_mutex);
928 snd_info_free_entry(ins->proc_dsp_dir);
929 ins->proc_dsp_dir = NULL;
933 #endif /* CONFIG_SND_PROC_FS */
935 static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
938 void __iomem *spdst = chip->region.idx[1].remap_addr +
939 DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
942 for (i = 0; i < size; ++i) {
943 dev_dbg(chip->card->dev, "addr %p, val %08x\n",
944 spdst, task_data[i]);
945 writel(task_data[i],spdst);
946 spdst += sizeof(u32);
950 static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
952 void __iomem *spdst = chip->region.idx[1].remap_addr +
953 DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
956 for (i = 0; i < 0x10; ++i) {
957 dev_dbg(chip->card->dev, "addr %p, val %08x\n",
959 writel(scb_data[i],spdst);
960 spdst += sizeof(u32);
964 static int find_free_scb_index (struct dsp_spos_instance * ins)
966 int index = ins->nscb, i;
968 for (i = ins->scb_highest_frag_index; i < ins->nscb; ++i) {
969 if (ins->scbs[i].deleted) {
978 static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * name, u32 dest)
980 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
981 struct dsp_scb_descriptor * desc = NULL;
984 if (ins->nscb == DSP_MAX_SCB_DESC - 1) {
985 dev_err(chip->card->dev,
986 "dsp_spos: got no place for other SCB\n");
990 index = find_free_scb_index (ins);
992 memset(&ins->scbs[index], 0, sizeof(ins->scbs[index]));
993 strcpy(ins->scbs[index].scb_name, name);
994 ins->scbs[index].address = dest;
995 ins->scbs[index].index = index;
996 ins->scbs[index].ref_count = 1;
998 desc = (ins->scbs + index);
999 ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);
1001 if (index > ins->scb_highest_frag_index)
1002 ins->scb_highest_frag_index = index;
1004 if (index == ins->nscb)
1010 static struct dsp_task_descriptor *
1011 _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
1013 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1014 struct dsp_task_descriptor * desc = NULL;
1016 if (ins->ntask == DSP_MAX_TASK_DESC - 1) {
1017 dev_err(chip->card->dev,
1018 "dsp_spos: got no place for other TASK\n");
1023 strcpy(ins->tasks[ins->ntask].task_name, name);
1025 strcpy(ins->tasks[ins->ntask].task_name, "(NULL)");
1026 ins->tasks[ins->ntask].address = dest;
1027 ins->tasks[ins->ntask].size = size;
1029 /* quick find in list */
1030 ins->tasks[ins->ntask].index = ins->ntask;
1031 desc = (ins->tasks + ins->ntask);
1035 add_symbol (chip,name,dest,SYMBOL_PARAMETER);
1039 #define SCB_BYTES (0x10 * 4)
1041 struct dsp_scb_descriptor *
1042 cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
1044 struct dsp_scb_descriptor * desc;
1046 #ifdef CONFIG_PM_SLEEP
1047 /* copy the data for resume */
1048 scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL);
1053 desc = _map_scb (chip,name,dest);
1055 desc->data = scb_data;
1056 _dsp_create_scb(chip,scb_data,dest);
1058 dev_err(chip->card->dev, "dsp_spos: failed to map SCB\n");
1059 #ifdef CONFIG_PM_SLEEP
1068 static struct dsp_task_descriptor *
1069 cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_data,
1072 struct dsp_task_descriptor * desc;
1074 desc = _map_task_tree (chip,name,dest,size);
1076 desc->data = task_data;
1077 _dsp_create_task_tree(chip,task_data,dest,size);
1079 dev_err(chip->card->dev, "dsp_spos: failed to map TASK\n");
1085 int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
1087 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1088 struct dsp_symbol_entry * fg_task_tree_header_code;
1089 struct dsp_symbol_entry * task_tree_header_code;
1090 struct dsp_symbol_entry * task_tree_thread;
1091 struct dsp_symbol_entry * null_algorithm;
1092 struct dsp_symbol_entry * magic_snoop_task;
1094 struct dsp_scb_descriptor * timing_master_scb;
1095 struct dsp_scb_descriptor * codec_out_scb;
1096 struct dsp_scb_descriptor * codec_in_scb;
1097 struct dsp_scb_descriptor * src_task_scb;
1098 struct dsp_scb_descriptor * master_mix_scb;
1099 struct dsp_scb_descriptor * rear_mix_scb;
1100 struct dsp_scb_descriptor * record_mix_scb;
1101 struct dsp_scb_descriptor * write_back_scb;
1102 struct dsp_scb_descriptor * vari_decimate_scb;
1103 struct dsp_scb_descriptor * rear_codec_out_scb;
1104 struct dsp_scb_descriptor * clfe_codec_out_scb;
1105 struct dsp_scb_descriptor * magic_snoop_scb;
1107 int fifo_addr, fifo_span, valid_slots;
1109 static struct dsp_spos_control_block sposcb = {
1110 /* 0 */ HFG_TREE_SCB,HFG_STACK,
1111 /* 1 */ SPOSCB_ADDR,BG_TREE_SCB_ADDR,
1112 /* 2 */ DSP_SPOS_DC,0,
1113 /* 3 */ DSP_SPOS_DC,DSP_SPOS_DC,
1115 /* 5 */ DSP_SPOS_UU,0,
1116 /* 6 */ FG_TASK_HEADER_ADDR,0,
1118 /* 8 */ DSP_SPOS_UU,DSP_SPOS_DC,
1120 /* A */ 0,HFG_FIRST_EXECUTE_MODE,
1121 /* B */ DSP_SPOS_UU,DSP_SPOS_UU,
1122 /* C */ DSP_SPOS_DC_DC,
1123 /* D */ DSP_SPOS_DC_DC,
1124 /* E */ DSP_SPOS_DC_DC,
1125 /* F */ DSP_SPOS_DC_DC
1128 cs46xx_dsp_create_task_tree(chip, "sposCB", (u32 *)&sposcb, SPOSCB_ADDR, 0x10);
1130 null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE);
1131 if (null_algorithm == NULL) {
1132 dev_err(chip->card->dev,
1133 "dsp_spos: symbol NULLALGORITHM not found\n");
1137 fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE);
1138 if (fg_task_tree_header_code == NULL) {
1139 dev_err(chip->card->dev,
1140 "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
1144 task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE);
1145 if (task_tree_header_code == NULL) {
1146 dev_err(chip->card->dev,
1147 "dsp_spos: symbol TASKTREEHEADERCODE not found\n");
1151 task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE);
1152 if (task_tree_thread == NULL) {
1153 dev_err(chip->card->dev,
1154 "dsp_spos: symbol TASKTREETHREAD not found\n");
1158 magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE);
1159 if (magic_snoop_task == NULL) {
1160 dev_err(chip->card->dev,
1161 "dsp_spos: symbol MAGICSNOOPTASK not found\n");
1166 /* create the null SCB */
1167 static struct dsp_generic_scb null_scb = {
1170 NULL_SCB_ADDR, NULL_SCB_ADDR,
1178 null_scb.entry_point = null_algorithm->address;
1179 ins->the_null_scb = cs46xx_dsp_create_scb(chip, "nullSCB", (u32 *)&null_scb, NULL_SCB_ADDR);
1180 ins->the_null_scb->task_entry = null_algorithm;
1181 ins->the_null_scb->sub_list_ptr = ins->the_null_scb;
1182 ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
1183 ins->the_null_scb->parent_scb_ptr = NULL;
1184 cs46xx_dsp_proc_register_scb_desc (chip,ins->the_null_scb);
1188 /* setup foreground task tree */
1189 static struct dsp_task_tree_control_block fg_task_tree_hdr = {
1190 { FG_TASK_HEADER_ADDR | (DSP_SPOS_DC << 0x10),
1194 DSP_SPOS_DC, DSP_SPOS_DC,
1198 DSP_SPOS_DC,DSP_SPOS_DC },
1201 BG_TREE_SCB_ADDR,TIMINGMASTER_SCB_ADDR,
1203 FG_TASK_HEADER_ADDR + TCBData,
1209 2,SPOSCB_ADDR + HFGFlags,
1211 FG_TASK_HEADER_ADDR + TCBContextBlk,FG_STACK
1216 DSP_SPOS_DC,DSP_SPOS_DC,
1217 DSP_SPOS_DC,DSP_SPOS_DC,
1218 DSP_SPOS_DC,DSP_SPOS_DC,
1219 DSP_SPOS_DC,DSP_SPOS_DC,
1252 FG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
1257 fg_task_tree_hdr.links.entry_point = fg_task_tree_header_code->address;
1258 fg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
1259 cs46xx_dsp_create_task_tree(chip,"FGtaskTreeHdr",(u32 *)&fg_task_tree_hdr,FG_TASK_HEADER_ADDR,0x35);
1264 /* setup foreground task tree */
1265 static struct dsp_task_tree_control_block bg_task_tree_hdr = {
1269 DSP_SPOS_DC, DSP_SPOS_DC,
1270 DSP_SPOS_DC, DSP_SPOS_DC,
1274 DSP_SPOS_DC,DSP_SPOS_DC },
1277 NULL_SCB_ADDR,NULL_SCB_ADDR, /* Set up the background to do nothing */
1279 BG_TREE_SCB_ADDR + TCBData,
1285 0,SPOSCB_ADDR + HFGFlags,
1287 BG_TREE_SCB_ADDR + TCBContextBlk,BG_STACK
1292 DSP_SPOS_DC,DSP_SPOS_DC,
1293 DSP_SPOS_DC,DSP_SPOS_DC,
1294 DSP_SPOS_DC,DSP_SPOS_DC,
1295 DSP_SPOS_DC,DSP_SPOS_DC,
1328 BG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
1333 bg_task_tree_hdr.links.entry_point = task_tree_header_code->address;
1334 bg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
1335 cs46xx_dsp_create_task_tree(chip,"BGtaskTreeHdr",(u32 *)&bg_task_tree_hdr,BG_TREE_SCB_ADDR,0x35);
1338 /* create timing master SCB */
1339 timing_master_scb = cs46xx_dsp_create_timing_master_scb(chip);
1341 /* create the CODEC output task */
1342 codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_I",0x0010,0x0000,
1344 CODECOUT_SCB_ADDR,timing_master_scb,
1345 SCB_ON_PARENT_SUBLIST_SCB);
1347 if (!codec_out_scb) goto _fail_end;
1348 /* create the master mix SCB */
1349 master_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"MasterMixSCB",
1350 MIX_SAMPLE_BUF1,MASTERMIX_SCB_ADDR,
1352 SCB_ON_PARENT_SUBLIST_SCB);
1353 ins->master_mix_scb = master_mix_scb;
1355 if (!master_mix_scb) goto _fail_end;
1357 /* create codec in */
1358 codec_in_scb = cs46xx_dsp_create_codec_in_scb(chip,"CodecInSCB",0x0010,0x00A0,
1360 CODECIN_SCB_ADDR,codec_out_scb,
1361 SCB_ON_PARENT_NEXT_SCB);
1362 if (!codec_in_scb) goto _fail_end;
1363 ins->codec_in_scb = codec_in_scb;
1365 /* create write back scb */
1366 write_back_scb = cs46xx_dsp_create_mix_to_ostream_scb(chip,"WriteBackSCB",
1367 WRITE_BACK_BUF1,WRITE_BACK_SPB,
1370 SCB_ON_PARENT_NEXT_SCB);
1371 if (!write_back_scb) goto _fail_end;
1374 static struct dsp_mix2_ostream_spb mix2_ostream_spb = {
1379 if (!cs46xx_dsp_create_task_tree(chip, NULL,
1380 (u32 *)&mix2_ostream_spb,
1385 /* input sample converter */
1386 vari_decimate_scb = cs46xx_dsp_create_vari_decimate_scb(chip,"VariDecimateSCB",
1389 VARIDECIMATE_SCB_ADDR,
1391 SCB_ON_PARENT_SUBLIST_SCB);
1392 if (!vari_decimate_scb) goto _fail_end;
1394 /* create the record mixer SCB */
1395 record_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RecordMixerSCB",
1397 RECORD_MIXER_SCB_ADDR,
1399 SCB_ON_PARENT_SUBLIST_SCB);
1400 ins->record_mixer_scb = record_mix_scb;
1402 if (!record_mix_scb) goto _fail_end;
1404 valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);
1406 if (snd_BUG_ON(chip->nr_ac97_codecs != 1 && chip->nr_ac97_codecs != 2))
1409 if (chip->nr_ac97_codecs == 1) {
1410 /* output on slot 5 and 11
1415 /* enable slot 5 and 11 */
1416 valid_slots |= ACOSV_SLV5 | ACOSV_SLV11;
1418 /* output on slot 7 and 8
1419 on secondary CODEC */
1423 /* enable slot 7 and 8 */
1424 valid_slots |= ACOSV_SLV7 | ACOSV_SLV8;
1426 /* create CODEC tasklet for rear speakers output*/
1427 rear_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_Rear",fifo_span,fifo_addr,
1428 REAR_MIXER_SCB_ADDR,
1429 REAR_CODECOUT_SCB_ADDR,codec_in_scb,
1430 SCB_ON_PARENT_NEXT_SCB);
1431 if (!rear_codec_out_scb) goto _fail_end;
1434 /* create the rear PCM channel mixer SCB */
1435 rear_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RearMixerSCB",
1437 REAR_MIXER_SCB_ADDR,
1439 SCB_ON_PARENT_SUBLIST_SCB);
1440 ins->rear_mix_scb = rear_mix_scb;
1441 if (!rear_mix_scb) goto _fail_end;
1443 if (chip->nr_ac97_codecs == 2) {
1444 /* create CODEC tasklet for rear Center/LFE output
1445 slot 6 and 9 on secondary CODEC */
1446 clfe_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_CLFE",0x0030,0x0030,
1447 CLFE_MIXER_SCB_ADDR,
1448 CLFE_CODEC_SCB_ADDR,
1450 SCB_ON_PARENT_NEXT_SCB);
1451 if (!clfe_codec_out_scb) goto _fail_end;
1454 /* create the rear PCM channel mixer SCB */
1455 ins->center_lfe_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"CLFEMixerSCB",
1457 CLFE_MIXER_SCB_ADDR,
1459 SCB_ON_PARENT_SUBLIST_SCB);
1460 if (!ins->center_lfe_mix_scb) goto _fail_end;
1462 /* enable slot 6 and 9 */
1463 valid_slots |= ACOSV_SLV6 | ACOSV_SLV9;
1465 clfe_codec_out_scb = rear_codec_out_scb;
1466 ins->center_lfe_mix_scb = rear_mix_scb;
1469 /* enable slots depending on CODEC configuration */
1470 snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots);
1472 /* the magic snooper */
1473 magic_snoop_scb = cs46xx_dsp_create_magic_snoop_scb (chip,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR,
1474 OUTPUT_SNOOP_BUFFER,
1477 SCB_ON_PARENT_NEXT_SCB);
1480 if (!magic_snoop_scb) goto _fail_end;
1481 ins->ref_snoop_scb = magic_snoop_scb;
1484 if (!cs46xx_dsp_create_spio_write_scb(chip,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR,
1486 SCB_ON_PARENT_NEXT_SCB))
1489 /* SPDIF input sampel rate converter */
1490 src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI",
1491 ins->spdif_in_sample_rate,
1493 SRC_DELAY_BUF1,SRCTASK_SCB_ADDR,
1495 SCB_ON_PARENT_SUBLIST_SCB,1);
1497 if (!src_task_scb) goto _fail_end;
1498 cs46xx_src_unlink(chip,src_task_scb);
1500 /* NOTE: when we now how to detect the SPDIF input
1501 sample rate we will use this SRC to adjust it */
1502 ins->spdif_in_src = src_task_scb;
1504 cs46xx_dsp_async_init(chip,timing_master_scb);
1508 dev_err(chip->card->dev, "dsp_spos: failed to setup SCB's in DSP\n");
1512 static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
1513 struct dsp_scb_descriptor * fg_entry)
1515 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1516 struct dsp_symbol_entry * s16_async_codec_input_task;
1517 struct dsp_symbol_entry * spdifo_task;
1518 struct dsp_symbol_entry * spdifi_task;
1519 struct dsp_scb_descriptor * spdifi_scb_desc, * spdifo_scb_desc, * async_codec_scb_desc;
1521 s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE);
1522 if (s16_async_codec_input_task == NULL) {
1523 dev_err(chip->card->dev,
1524 "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
1527 spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE);
1528 if (spdifo_task == NULL) {
1529 dev_err(chip->card->dev,
1530 "dsp_spos: symbol SPDIFOTASK not found\n");
1534 spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE);
1535 if (spdifi_task == NULL) {
1536 dev_err(chip->card->dev,
1537 "dsp_spos: symbol SPDIFITASK not found\n");
1543 struct dsp_spdifoscb spdifo_scb = {
1544 /* 0 */ DSP_SPOS_UUUU,
1551 /* NOTE: the SPDIF output task read samples in mono
1552 format, the AsynchFGTxSCB task writes to buffer
1555 /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_256,
1556 /* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1 << 0x10 ) | 0xFFFC,
1559 /* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR,
1560 /* A */ spdifo_task->address,
1561 SPDIFO_SCB_INST + SPDIFOFIFOPointer,
1563 /* B */ 0x0040, /*DSP_SPOS_UUUU,*/
1564 /* C */ 0x20ff, /*DSP_SPOS_UUUU,*/
1566 /* D */ 0x804c,0, /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */
1567 /* E */ 0x0108,0x0001, /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
1568 /* F */ DSP_SPOS_UUUU /* SPDIFOFree; */
1572 struct dsp_spdifiscb spdifi_scb = {
1573 /* 0 */ DSP_SPOS_UULO,DSP_SPOS_UUHI,
1576 /* 3 */ 1,4000, /* SPDIFICountLimit SPDIFICount */
1577 /* 4 */ DSP_SPOS_UUUU, /* SPDIFIStatusData */
1578 /* 5 */ 0,DSP_SPOS_UUHI, /* StatusData, Free4 */
1579 /* 6 */ DSP_SPOS_UUUU, /* Free3 */
1580 /* 7 */ DSP_SPOS_UU,DSP_SPOS_DC, /* Free2 BitCount*/
1581 /* 8 */ DSP_SPOS_UUUU, /* TempStatus */
1582 /* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR,
1583 /* A */ spdifi_task->address,
1584 SPDIFI_SCB_INST + SPDIFIFIFOPointer,
1585 /* NOTE: The SPDIF input task write the sample in mono
1586 format from the HW FIFO, the AsynchFGRxSCB task reads
1589 /* B */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_128,
1590 /* C */ (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
1592 /* E */ 0x01f0,0x0001,
1593 /* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */
1597 struct dsp_async_codec_input_scb async_codec_input_scb = {
1598 /* 0 */ DSP_SPOS_UUUU,
1602 /* 4 */ 0x0118,0x0001,
1603 /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_64,
1604 /* 6 */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
1605 /* 7 */ DSP_SPOS_UU,0x3,
1606 /* 8 */ DSP_SPOS_UUUU,
1607 /* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR,
1608 /* A */ s16_async_codec_input_task->address,
1609 HFG_TREE_SCB + AsyncCIOFIFOPointer,
1611 /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
1612 /* C */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10), /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/
1614 #ifdef UseASER1Input
1615 /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
1616 Init. 0000:8042: for ASER1
1617 0000:8044: for ASER2 */
1620 /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
1621 Init 1 stero:8050 ASER1
1622 Init 0 mono:8070 ASER2
1623 Init 1 Stereo : 0100 ASER1 (Set by script) */
1624 /* E */ 0x0100,0x0001,
1628 #ifdef UseASER2Input
1629 /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
1630 Init. 0000:8042: for ASER1
1631 0000:8044: for ASER2 */
1634 /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
1635 Init 1 stero:8050 ASER1
1636 Init 0 mono:8070 ASER2
1637 Init 1 Stereo : 0100 ASER1 (Set by script) */
1638 /* E */ 0x0110,0x0001,
1642 /* short AsyncCIOutputBufModulo:AsyncCIFree;
1643 AsyncCIOutputBufModulo: The modulo size for
1644 the output buffer of this task */
1645 /* F */ 0, /* DSP_SPOS_UUUU */
1648 spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);
1650 if (snd_BUG_ON(!spdifo_scb_desc))
1652 spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST);
1653 if (snd_BUG_ON(!spdifi_scb_desc))
1655 async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB);
1656 if (snd_BUG_ON(!async_codec_scb_desc))
1659 async_codec_scb_desc->parent_scb_ptr = NULL;
1660 async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc;
1661 async_codec_scb_desc->sub_list_ptr = ins->the_null_scb;
1662 async_codec_scb_desc->task_entry = s16_async_codec_input_task;
1664 spdifi_scb_desc->parent_scb_ptr = async_codec_scb_desc;
1665 spdifi_scb_desc->next_scb_ptr = spdifo_scb_desc;
1666 spdifi_scb_desc->sub_list_ptr = ins->the_null_scb;
1667 spdifi_scb_desc->task_entry = spdifi_task;
1669 spdifo_scb_desc->parent_scb_ptr = spdifi_scb_desc;
1670 spdifo_scb_desc->next_scb_ptr = fg_entry;
1671 spdifo_scb_desc->sub_list_ptr = ins->the_null_scb;
1672 spdifo_scb_desc->task_entry = spdifo_task;
1674 /* this one is faked, as the parnet of SPDIFO task
1675 is the FG task tree */
1676 fg_entry->parent_scb_ptr = spdifo_scb_desc;
1679 cs46xx_dsp_proc_register_scb_desc (chip,spdifo_scb_desc);
1680 cs46xx_dsp_proc_register_scb_desc (chip,spdifi_scb_desc);
1681 cs46xx_dsp_proc_register_scb_desc (chip,async_codec_scb_desc);
1683 /* Async MASTER ENABLE, affects both SPDIF input and output */
1684 snd_cs46xx_pokeBA0(chip, BA0_ASER_MASTER, 0x1 );
1690 static void cs46xx_dsp_disable_spdif_hw (struct snd_cs46xx *chip)
1692 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1694 /* set SPDIF output FIFO slot */
1695 snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, 0);
1697 /* SPDIF output MASTER ENABLE */
1698 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0);
1700 /* right and left validate bit */
1701 /*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/
1702 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x0);
1704 /* clear fifo pointer */
1705 cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);
1708 ins->spdif_status_out &= ~DSP_SPDIF_STATUS_HW_ENABLED;
1711 int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip)
1713 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1715 /* if hw-ctrl already enabled, turn off to reset logic ... */
1716 cs46xx_dsp_disable_spdif_hw (chip);
1719 /* set SPDIF output FIFO slot */
1720 snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, ( 0x8000 | ((SP_SPDOUT_FIFO >> 4) << 4) ));
1722 /* SPDIF output MASTER ENABLE */
1723 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000);
1725 /* right and left validate bit */
1726 cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
1729 ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED;
1734 int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)
1736 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1738 /* turn on amplifier */
1739 chip->active_ctrl(chip, 1);
1740 chip->amplifier_ctrl(chip, 1);
1742 if (snd_BUG_ON(ins->asynch_rx_scb))
1744 if (snd_BUG_ON(!ins->spdif_in_src))
1747 mutex_lock(&chip->spos_mutex);
1749 if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) {
1750 /* time countdown enable */
1751 cs46xx_poke_via_dsp (chip,SP_ASER_COUNTDOWN, 0x80000005);
1752 /* NOTE: 80000005 value is just magic. With all values
1753 that I've tested this one seem to give the best result.
1754 Got no explication why. (Benny) */
1756 /* SPDIF input MASTER ENABLE */
1757 cs46xx_poke_via_dsp (chip,SP_SPDIN_CONTROL, 0x800003ff);
1759 ins->spdif_status_out |= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED;
1762 /* create and start the asynchronous receiver SCB */
1763 ins->asynch_rx_scb = cs46xx_dsp_create_asynch_fg_rx_scb(chip,"AsynchFGRxSCB",
1766 SPDIFI_IP_OUTPUT_BUFFER1,
1768 SCB_ON_PARENT_SUBLIST_SCB);
1770 spin_lock_irq(&chip->reg_lock);
1772 /* reset SPDIF input sample buffer pointer */
1773 /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
1774 (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/
1776 /* reset FIFO ptr */
1777 /*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/
1778 cs46xx_src_link(chip,ins->spdif_in_src);
1780 /* unmute SRC volume */
1781 cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff);
1783 spin_unlock_irq(&chip->reg_lock);
1785 /* set SPDIF input sample rate and unmute
1786 NOTE: only 48khz support for SPDIF input this time */
1787 /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
1790 ins->spdif_status_in = 1;
1791 mutex_unlock(&chip->spos_mutex);
1796 int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip)
1798 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1800 if (snd_BUG_ON(!ins->asynch_rx_scb))
1802 if (snd_BUG_ON(!ins->spdif_in_src))
1805 mutex_lock(&chip->spos_mutex);
1807 /* Remove the asynchronous receiver SCB */
1808 cs46xx_dsp_remove_scb (chip,ins->asynch_rx_scb);
1809 ins->asynch_rx_scb = NULL;
1811 cs46xx_src_unlink(chip,ins->spdif_in_src);
1814 ins->spdif_status_in = 0;
1815 mutex_unlock(&chip->spos_mutex);
1817 /* restore amplifier */
1818 chip->active_ctrl(chip, -1);
1819 chip->amplifier_ctrl(chip, -1);
1824 int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip)
1826 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1828 if (snd_BUG_ON(ins->pcm_input))
1830 if (snd_BUG_ON(!ins->ref_snoop_scb))
1833 mutex_lock(&chip->spos_mutex);
1834 ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
1835 "PCMSerialInput_Wave");
1836 mutex_unlock(&chip->spos_mutex);
1841 int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip)
1843 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1845 if (snd_BUG_ON(!ins->pcm_input))
1848 mutex_lock(&chip->spos_mutex);
1849 cs46xx_dsp_remove_scb (chip,ins->pcm_input);
1850 ins->pcm_input = NULL;
1851 mutex_unlock(&chip->spos_mutex);
1856 int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip)
1858 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1860 if (snd_BUG_ON(ins->adc_input))
1862 if (snd_BUG_ON(!ins->codec_in_scb))
1865 mutex_lock(&chip->spos_mutex);
1866 ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
1867 "PCMSerialInput_ADC");
1868 mutex_unlock(&chip->spos_mutex);
1873 int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip)
1875 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1877 if (snd_BUG_ON(!ins->adc_input))
1880 mutex_lock(&chip->spos_mutex);
1881 cs46xx_dsp_remove_scb (chip,ins->adc_input);
1882 ins->adc_input = NULL;
1883 mutex_unlock(&chip->spos_mutex);
1888 int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data)
1893 /* santiy check the parameters. (These numbers are not 100% correct. They are
1894 a rough guess from looking at the controller spec.) */
1895 if (address < 0x8000 || address >= 0x9000)
1898 /* initialize the SP_IO_WRITE SCB with the data. */
1899 temp = ( address << 16 ) | ( address & 0x0000FFFF); /* offset 0 <-- address2 : address1 */
1901 snd_cs46xx_poke(chip,( SPIOWRITE_SCB_ADDR << 2), temp);
1902 snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 1) << 2), data); /* offset 1 <-- data1 */
1903 snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 2) << 2), data); /* offset 1 <-- data2 */
1905 /* Poke this location to tell the task to start */
1906 snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 6) << 2), SPIOWRITE_SCB_ADDR << 0x10);
1908 /* Verify that the task ran */
1909 for (i=0; i<25; i++) {
1912 temp = snd_cs46xx_peek(chip,((SPIOWRITE_SCB_ADDR + 6) << 2));
1913 if (temp == 0x00000000)
1918 dev_err(chip->card->dev,
1919 "dsp_spos: SPIOWriteTask not responding\n");
1926 int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right)
1928 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1929 struct dsp_scb_descriptor * scb;
1931 mutex_lock(&chip->spos_mutex);
1934 scb = ins->master_mix_scb->sub_list_ptr;
1935 while (scb != ins->the_null_scb) {
1936 cs46xx_dsp_scb_set_volume (chip,scb,left,right);
1937 scb = scb->next_scb_ptr;
1941 scb = ins->rear_mix_scb->sub_list_ptr;
1942 while (scb != ins->the_null_scb) {
1943 cs46xx_dsp_scb_set_volume (chip,scb,left,right);
1944 scb = scb->next_scb_ptr;
1947 ins->dac_volume_left = left;
1948 ins->dac_volume_right = right;
1950 mutex_unlock(&chip->spos_mutex);
1955 int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right)
1957 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1959 mutex_lock(&chip->spos_mutex);
1961 if (ins->asynch_rx_scb != NULL)
1962 cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb,
1965 ins->spdif_input_volume_left = left;
1966 ins->spdif_input_volume_right = right;
1968 mutex_unlock(&chip->spos_mutex);
1973 #ifdef CONFIG_PM_SLEEP
1974 int cs46xx_dsp_resume(struct snd_cs46xx * chip)
1976 struct dsp_spos_instance * ins = chip->dsp_spos_instance;
1979 /* clear parameter, sample and code areas */
1980 snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET,
1981 DSP_PARAMETER_BYTE_SIZE);
1982 snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET,
1983 DSP_SAMPLE_BYTE_SIZE);
1984 snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
1986 for (i = 0; i < ins->nmodules; i++) {
1987 struct dsp_module_desc *module = &ins->modules[i];
1988 struct dsp_segment_desc *seg;
1991 seg = get_segment_desc(module, SEGTYPE_SP_PARAMETER);
1992 err = dsp_load_parameter(chip, seg);
1996 seg = get_segment_desc(module, SEGTYPE_SP_SAMPLE);
1997 err = dsp_load_sample(chip, seg);
2001 seg = get_segment_desc(module, SEGTYPE_SP_PROGRAM);
2005 doffset = seg->offset * 4 + module->load_address * 4
2006 + DSP_CODE_BYTE_OFFSET;
2007 dsize = seg->size * 4;
2008 err = snd_cs46xx_download(chip,
2009 ins->code.data + module->load_address,
2015 for (i = 0; i < ins->ntask; i++) {
2016 struct dsp_task_descriptor *t = &ins->tasks[i];
2017 _dsp_create_task_tree(chip, t->data, t->address, t->size);
2020 for (i = 0; i < ins->nscb; i++) {
2021 struct dsp_scb_descriptor *s = &ins->scbs[i];
2024 _dsp_create_scb(chip, s->data, s->address);
2026 for (i = 0; i < ins->nscb; i++) {
2027 struct dsp_scb_descriptor *s = &ins->scbs[i];
2031 cs46xx_dsp_spos_update_scb(chip, s);
2033 cs46xx_dsp_scb_set_volume(chip, s,
2034 s->volume[0], s->volume[1]);
2036 if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) {
2037 cs46xx_dsp_enable_spdif_hw(chip);
2038 snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2,
2039 (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10);
2040 if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN)
2041 cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV,
2042 ins->spdif_csuv_stream);
2044 if (chip->dsp_spos_instance->spdif_status_in) {
2045 cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005);
2046 cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff);