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
23 #include <sound/driver.h>
25 #include <linux/delay.h>
26 #include <linux/pci.h>
28 #include <linux/init.h>
29 #include <linux/slab.h>
30 #include <linux/vmalloc.h>
31 #include <sound/core.h>
32 #include <sound/control.h>
33 #include <sound/info.h>
34 #include <sound/asoundef.h>
35 #include <sound/cs46xx.h>
37 #include "cs46xx_lib.h"
40 static int cs46xx_dsp_async_init (cs46xx_t
*chip
, dsp_scb_descriptor_t
* fg_entry
);
42 static wide_opcode_t wide_opcodes
[] = {
47 WIDE_TBEQ_COND_GOTO_ADDR
,
48 WIDE_TBEQ_COND_CALL_ADDR
,
49 WIDE_TBEQ_NCOND_GOTO_ADDR
,
50 WIDE_TBEQ_NCOND_CALL_ADDR
,
51 WIDE_TBEQ_COND_GOTO1_ADDR
,
52 WIDE_TBEQ_COND_CALL1_ADDR
,
53 WIDE_TBEQ_NCOND_GOTOI_ADDR
,
54 WIDE_TBEQ_NCOND_CALL1_ADDR
57 static int shadow_and_reallocate_code (cs46xx_t
* chip
,u32
* data
,u32 size
, u32 overlay_begin_address
)
59 unsigned int i
= 0, j
, nreallocated
= 0;
60 u32 hival
,loval
,address
;
61 u32 mop_operands
,mop_type
,wide_op
;
62 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
64 snd_assert( ((size
% 2) == 0), return -EINVAL
);
70 if (ins
->code
.offset
> 0) {
71 mop_operands
= (hival
>> 6) & 0x03fff;
72 mop_type
= mop_operands
>> 10;
74 /* check for wide type instruction */
76 (mop_operands
& WIDE_LADD_INSTR_MASK
) == 0 &&
77 (mop_operands
& WIDE_INSTR_MASK
) != 0) {
78 wide_op
= loval
& 0x7f;
79 for (j
= 0;j
< ARRAY_SIZE(wide_opcodes
); ++j
) {
80 if (wide_opcodes
[j
] == wide_op
) {
81 /* need to reallocate instruction */
82 address
= (hival
& 0x00FFF) << 5;
83 address
|= loval
>> 15;
85 snd_printdd("handle_wideop[1]: %05x:%05x addr %04x\n",hival
,loval
,address
);
87 if ( !(address
& 0x8000) ) {
88 address
+= (ins
->code
.offset
/ 2) - overlay_begin_address
;
90 snd_printdd("handle_wideop[1]: ROM symbol not reallocated\n");
96 hival
|= ( (address
>> 5) & 0x00FFF);
97 loval
|= ( (address
<< 15) & 0xF8000);
99 address
= (hival
& 0x00FFF) << 5;
100 address
|= loval
>> 15;
102 snd_printdd("handle_wideop:[2] %05x:%05x addr %04x\n",hival
,loval
,address
);
104 } /* wide_opcodes[j] == wide_op */
106 } /* mod_type == 0 ... */
107 } /* ins->code.offset > 0 */
109 ins
->code
.data
[ins
->code
.size
++] = loval
;
110 ins
->code
.data
[ins
->code
.size
++] = hival
;
113 snd_printdd("dsp_spos: %d instructions reallocated\n",nreallocated
);
117 static segment_desc_t
* get_segment_desc (dsp_module_desc_t
* module
, int seg_type
)
120 for (i
= 0;i
< module
->nsegments
; ++i
) {
121 if (module
->segments
[i
].segment_type
== seg_type
) {
122 return (module
->segments
+ i
);
129 static int find_free_symbol_index (dsp_spos_instance_t
* ins
)
131 int index
= ins
->symbol_table
.nsymbols
,i
;
133 for (i
= ins
->symbol_table
.highest_frag_index
; i
< ins
->symbol_table
.nsymbols
; ++i
) {
134 if (ins
->symbol_table
.symbols
[i
].deleted
) {
143 static int add_symbols (cs46xx_t
* chip
, dsp_module_desc_t
* module
)
146 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
148 if (module
->symbol_table
.nsymbols
> 0) {
149 if (!strcmp(module
->symbol_table
.symbols
[0].symbol_name
, "OVERLAYBEGINADDRESS") &&
150 module
->symbol_table
.symbols
[0].symbol_type
== SYMBOL_CONSTANT
) {
151 module
->overlay_begin_address
= module
->symbol_table
.symbols
[0].address
;
155 for (i
= 0;i
< module
->symbol_table
.nsymbols
; ++i
) {
156 if (ins
->symbol_table
.nsymbols
== (DSP_MAX_SYMBOLS
- 1)) {
157 snd_printk(KERN_ERR
"dsp_spos: symbol table is full\n");
162 if (cs46xx_dsp_lookup_symbol(chip
,
163 module
->symbol_table
.symbols
[i
].symbol_name
,
164 module
->symbol_table
.symbols
[i
].symbol_type
) == NULL
) {
166 ins
->symbol_table
.symbols
[ins
->symbol_table
.nsymbols
] = module
->symbol_table
.symbols
[i
];
167 ins
->symbol_table
.symbols
[ins
->symbol_table
.nsymbols
].address
+= ((ins
->code
.offset
/ 2) - module
->overlay_begin_address
);
168 ins
->symbol_table
.symbols
[ins
->symbol_table
.nsymbols
].module
= module
;
169 ins
->symbol_table
.symbols
[ins
->symbol_table
.nsymbols
].deleted
= 0;
171 if (ins
->symbol_table
.nsymbols
> ins
->symbol_table
.highest_frag_index
)
172 ins
->symbol_table
.highest_frag_index
= ins
->symbol_table
.nsymbols
;
174 ins
->symbol_table
.nsymbols
++;
176 /* if (0) printk ("dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n",
177 module->symbol_table.symbols[i].symbol_name); */
184 static symbol_entry_t
* add_symbol (cs46xx_t
* chip
, char * symbol_name
, u32 address
, int type
)
186 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
187 symbol_entry_t
* symbol
= NULL
;
190 if (ins
->symbol_table
.nsymbols
== (DSP_MAX_SYMBOLS
- 1)) {
191 snd_printk(KERN_ERR
"dsp_spos: symbol table is full\n");
195 if (cs46xx_dsp_lookup_symbol(chip
,
198 snd_printk(KERN_ERR
"dsp_spos: symbol <%s> duplicated\n", symbol_name
);
202 index
= find_free_symbol_index (ins
);
204 strcpy (ins
->symbol_table
.symbols
[index
].symbol_name
, symbol_name
);
205 ins
->symbol_table
.symbols
[index
].address
= address
;
206 ins
->symbol_table
.symbols
[index
].symbol_type
= type
;
207 ins
->symbol_table
.symbols
[index
].module
= NULL
;
208 ins
->symbol_table
.symbols
[index
].deleted
= 0;
209 symbol
= (ins
->symbol_table
.symbols
+ index
);
211 if (index
> ins
->symbol_table
.highest_frag_index
)
212 ins
->symbol_table
.highest_frag_index
= index
;
214 if (index
== ins
->symbol_table
.nsymbols
)
215 ins
->symbol_table
.nsymbols
++; /* no frag. in list */
220 dsp_spos_instance_t
* cs46xx_dsp_spos_create (cs46xx_t
* chip
)
222 dsp_spos_instance_t
* ins
= kmalloc(sizeof(dsp_spos_instance_t
), GFP_KERNEL
);
226 memset(ins
, 0, sizeof(*ins
));
228 /* better to use vmalloc for this big table */
229 ins
->symbol_table
.nsymbols
= 0;
230 ins
->symbol_table
.symbols
= vmalloc(sizeof(symbol_entry_t
) * DSP_MAX_SYMBOLS
);
231 ins
->symbol_table
.highest_frag_index
= 0;
233 if (ins
->symbol_table
.symbols
== NULL
) {
234 cs46xx_dsp_spos_destroy(chip
);
238 ins
->code
.offset
= 0;
240 ins
->code
.data
= kmalloc(DSP_CODE_BYTE_SIZE
, GFP_KERNEL
);
242 if (ins
->code
.data
== NULL
) {
243 cs46xx_dsp_spos_destroy(chip
);
251 ins
->modules
= kmalloc(sizeof(dsp_module_desc_t
) * DSP_MAX_MODULES
, GFP_KERNEL
);
253 if (ins
->modules
== NULL
) {
254 cs46xx_dsp_spos_destroy(chip
);
258 /* default SPDIF input sample rate
260 ins
->spdif_in_sample_rate
= 48000;
262 /* maximize volume */
263 ins
->dac_volume_right
= 0x8000;
264 ins
->dac_volume_left
= 0x8000;
265 ins
->spdif_input_volume_right
= 0x8000;
266 ins
->spdif_input_volume_left
= 0x8000;
268 /* set left and right validity bits and
269 default channel status */
270 ins
->spdif_csuv_default
=
271 ins
->spdif_csuv_stream
=
272 /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF
& 0xff)) << 24) |
273 /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF
>> 8) & 0xff)) << 16) |
274 /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF
>> 24) & 0xff) |
275 /* left and right validity bits */ (1 << 13) | (1 << 12);
280 void cs46xx_dsp_spos_destroy (cs46xx_t
* chip
)
283 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
285 snd_assert(ins
!= NULL
, return);
287 down(&chip
->spos_mutex
);
288 for (i
= 0; i
< ins
->nscb
; ++i
) {
289 if (ins
->scbs
[i
].deleted
) continue;
291 cs46xx_dsp_proc_free_scb_desc ( (ins
->scbs
+ i
) );
294 kfree(ins
->code
.data
);
295 vfree(ins
->symbol_table
.symbols
);
298 up(&chip
->spos_mutex
);
301 int cs46xx_dsp_load_module (cs46xx_t
* chip
, dsp_module_desc_t
* module
)
303 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
304 segment_desc_t
* code
= get_segment_desc (module
,SEGTYPE_SP_PROGRAM
);
305 segment_desc_t
* parameter
= get_segment_desc (module
,SEGTYPE_SP_PARAMETER
);
306 segment_desc_t
* sample
= get_segment_desc (module
,SEGTYPE_SP_SAMPLE
);
309 if (ins
->nmodules
== DSP_MAX_MODULES
- 1) {
310 snd_printk(KERN_ERR
"dsp_spos: to many modules loaded into DSP\n");
314 snd_printdd("dsp_spos: loading module %s into DSP\n", module
->module_name
);
316 if (ins
->nmodules
== 0) {
317 snd_printdd("dsp_spos: clearing parameter area\n");
318 snd_cs46xx_clear_BA1(chip
, DSP_PARAMETER_BYTE_OFFSET
, DSP_PARAMETER_BYTE_SIZE
);
321 if (parameter
== NULL
) {
322 snd_printdd("dsp_spos: module got no parameter segment\n");
324 if (ins
->nmodules
> 0) {
325 snd_printk(KERN_WARNING
"dsp_spos: WARNING current parameter data may be overwriten!\n");
328 doffset
= (parameter
->offset
* 4 + DSP_PARAMETER_BYTE_OFFSET
);
329 dsize
= parameter
->size
* 4;
331 snd_printdd("dsp_spos: downloading parameter data to chip (%08x-%08x)\n",
332 doffset
,doffset
+ dsize
);
334 if (snd_cs46xx_download (chip
, parameter
->data
, doffset
, dsize
)) {
335 snd_printk(KERN_ERR
"dsp_spos: failed to download parameter data to DSP\n");
340 if (ins
->nmodules
== 0) {
341 snd_printdd("dsp_spos: clearing sample area\n");
342 snd_cs46xx_clear_BA1(chip
, DSP_SAMPLE_BYTE_OFFSET
, DSP_SAMPLE_BYTE_SIZE
);
345 if (sample
== NULL
) {
346 snd_printdd("dsp_spos: module got no sample segment\n");
348 if (ins
->nmodules
> 0) {
349 snd_printk(KERN_WARNING
"dsp_spos: WARNING current sample data may be overwriten\n");
352 doffset
= (sample
->offset
* 4 + DSP_SAMPLE_BYTE_OFFSET
);
353 dsize
= sample
->size
* 4;
355 snd_printdd("dsp_spos: downloading sample data to chip (%08x-%08x)\n",
356 doffset
,doffset
+ dsize
);
358 if (snd_cs46xx_download (chip
,sample
->data
,doffset
,dsize
)) {
359 snd_printk(KERN_ERR
"dsp_spos: failed to sample data to DSP\n");
365 if (ins
->nmodules
== 0) {
366 snd_printdd("dsp_spos: clearing code area\n");
367 snd_cs46xx_clear_BA1(chip
, DSP_CODE_BYTE_OFFSET
, DSP_CODE_BYTE_SIZE
);
371 snd_printdd("dsp_spos: module got no code segment\n");
373 if (ins
->code
.offset
+ code
->size
> DSP_CODE_BYTE_SIZE
) {
374 snd_printk(KERN_ERR
"dsp_spos: no space available in DSP\n");
378 module
->load_address
= ins
->code
.offset
;
379 module
->overlay_begin_address
= 0x000;
381 /* if module has a code segment it must have
383 snd_assert(module
->symbol_table
.symbols
!= NULL
,return -ENOMEM
);
384 if (add_symbols(chip
,module
)) {
385 snd_printk(KERN_ERR
"dsp_spos: failed to load symbol table\n");
389 doffset
= (code
->offset
* 4 + ins
->code
.offset
* 4 + DSP_CODE_BYTE_OFFSET
);
390 dsize
= code
->size
* 4;
391 snd_printdd("dsp_spos: downloading code to chip (%08x-%08x)\n",
392 doffset
,doffset
+ dsize
);
394 module
->nfixups
= shadow_and_reallocate_code(chip
,code
->data
,code
->size
,module
->overlay_begin_address
);
396 if (snd_cs46xx_download (chip
,(ins
->code
.data
+ ins
->code
.offset
),doffset
,dsize
)) {
397 snd_printk(KERN_ERR
"dsp_spos: failed to download code to DSP\n");
401 ins
->code
.offset
+= code
->size
;
404 /* NOTE: module segments and symbol table must be
405 statically allocated. Case that module data is
406 not generated by the ospparser */
407 ins
->modules
[ins
->nmodules
] = *module
;
413 symbol_entry_t
* cs46xx_dsp_lookup_symbol (cs46xx_t
* chip
, char * symbol_name
, int symbol_type
)
416 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
418 for ( i
= 0; i
< ins
->symbol_table
.nsymbols
; ++i
) {
420 if (ins
->symbol_table
.symbols
[i
].deleted
)
423 if (!strcmp(ins
->symbol_table
.symbols
[i
].symbol_name
,symbol_name
) &&
424 ins
->symbol_table
.symbols
[i
].symbol_type
== symbol_type
) {
425 return (ins
->symbol_table
.symbols
+ i
);
430 printk ("dsp_spos: symbol <%s> type %02x not found\n",
431 symbol_name
,symbol_type
);
438 static symbol_entry_t
* cs46xx_dsp_lookup_symbol_addr (cs46xx_t
* chip
, u32 address
, int symbol_type
)
441 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
443 for ( i
= 0; i
< ins
->symbol_table
.nsymbols
; ++i
) {
445 if (ins
->symbol_table
.symbols
[i
].deleted
)
448 if (ins
->symbol_table
.symbols
[i
].address
== address
&&
449 ins
->symbol_table
.symbols
[i
].symbol_type
== symbol_type
) {
450 return (ins
->symbol_table
.symbols
+ i
);
459 static void cs46xx_dsp_proc_symbol_table_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
461 cs46xx_t
*chip
= entry
->private_data
;
462 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
465 snd_iprintf(buffer
, "SYMBOLS:\n");
466 for ( i
= 0; i
< ins
->symbol_table
.nsymbols
; ++i
) {
467 char *module_str
= "system";
469 if (ins
->symbol_table
.symbols
[i
].deleted
)
472 if (ins
->symbol_table
.symbols
[i
].module
!= NULL
) {
473 module_str
= ins
->symbol_table
.symbols
[i
].module
->module_name
;
477 snd_iprintf(buffer
, "%04X <%02X> %s [%s]\n",
478 ins
->symbol_table
.symbols
[i
].address
,
479 ins
->symbol_table
.symbols
[i
].symbol_type
,
480 ins
->symbol_table
.symbols
[i
].symbol_name
,
486 static void cs46xx_dsp_proc_modules_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
488 cs46xx_t
*chip
= entry
->private_data
;
489 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
492 down(&chip
->spos_mutex
);
493 snd_iprintf(buffer
, "MODULES:\n");
494 for ( i
= 0; i
< ins
->nmodules
; ++i
) {
495 snd_iprintf(buffer
, "\n%s:\n", ins
->modules
[i
].module_name
);
496 snd_iprintf(buffer
, " %d symbols\n", ins
->modules
[i
].symbol_table
.nsymbols
);
497 snd_iprintf(buffer
, " %d fixups\n", ins
->modules
[i
].nfixups
);
499 for (j
= 0; j
< ins
->modules
[i
].nsegments
; ++ j
) {
500 segment_desc_t
* desc
= (ins
->modules
[i
].segments
+ j
);
501 snd_iprintf(buffer
, " segment %02x offset %08x size %08x\n",
502 desc
->segment_type
,desc
->offset
, desc
->size
);
505 up(&chip
->spos_mutex
);
508 static void cs46xx_dsp_proc_task_tree_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
510 cs46xx_t
*chip
= entry
->private_data
;
511 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
513 void __iomem
*dst
= chip
->region
.idx
[1].remap_addr
+ DSP_PARAMETER_BYTE_OFFSET
;
515 down(&chip
->spos_mutex
);
516 snd_iprintf(buffer
, "TASK TREES:\n");
517 for ( i
= 0; i
< ins
->ntask
; ++i
) {
518 snd_iprintf(buffer
,"\n%04x %s:\n",ins
->tasks
[i
].address
,ins
->tasks
[i
].task_name
);
520 for (col
= 0,j
= 0;j
< ins
->tasks
[i
].size
; j
++,col
++) {
523 snd_iprintf(buffer
,"\n");
526 val
= readl(dst
+ (ins
->tasks
[i
].address
+ j
) * sizeof(u32
));
527 snd_iprintf(buffer
,"%08x ",val
);
531 snd_iprintf(buffer
,"\n");
532 up(&chip
->spos_mutex
);
535 static void cs46xx_dsp_proc_scb_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
537 cs46xx_t
*chip
= entry
->private_data
;
538 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
541 down(&chip
->spos_mutex
);
542 snd_iprintf(buffer
, "SCB's:\n");
543 for ( i
= 0; i
< ins
->nscb
; ++i
) {
544 if (ins
->scbs
[i
].deleted
)
546 snd_iprintf(buffer
,"\n%04x %s:\n\n",ins
->scbs
[i
].address
,ins
->scbs
[i
].scb_name
);
548 if (ins
->scbs
[i
].parent_scb_ptr
!= NULL
) {
549 snd_iprintf(buffer
,"parent [%s:%04x] ",
550 ins
->scbs
[i
].parent_scb_ptr
->scb_name
,
551 ins
->scbs
[i
].parent_scb_ptr
->address
);
552 } else snd_iprintf(buffer
,"parent [none] ");
554 snd_iprintf(buffer
,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n",
555 ins
->scbs
[i
].sub_list_ptr
->scb_name
,
556 ins
->scbs
[i
].sub_list_ptr
->address
,
557 ins
->scbs
[i
].next_scb_ptr
->scb_name
,
558 ins
->scbs
[i
].next_scb_ptr
->address
,
559 ins
->scbs
[i
].task_entry
->symbol_name
,
560 ins
->scbs
[i
].task_entry
->address
);
563 snd_iprintf(buffer
,"\n");
564 up(&chip
->spos_mutex
);
567 static void cs46xx_dsp_proc_parameter_dump_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
569 cs46xx_t
*chip
= entry
->private_data
;
570 /*dsp_spos_instance_t * ins = chip->dsp_spos_instance; */
571 unsigned int i
,col
= 0;
572 void __iomem
*dst
= chip
->region
.idx
[1].remap_addr
+ DSP_PARAMETER_BYTE_OFFSET
;
573 symbol_entry_t
* symbol
;
575 for (i
= 0;i
< DSP_PARAMETER_BYTE_SIZE
; i
+= sizeof(u32
),col
++) {
577 snd_iprintf(buffer
,"\n");
581 if ( (symbol
= cs46xx_dsp_lookup_symbol_addr (chip
,i
/ sizeof(u32
), SYMBOL_PARAMETER
)) != NULL
) {
583 snd_iprintf (buffer
,"\n%s:\n",symbol
->symbol_name
);
587 snd_iprintf(buffer
, "%04X ", i
/ (unsigned int)sizeof(u32
));
590 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
594 static void cs46xx_dsp_proc_sample_dump_read (snd_info_entry_t
*entry
, snd_info_buffer_t
* buffer
)
596 cs46xx_t
*chip
= entry
->private_data
;
598 void __iomem
*dst
= chip
->region
.idx
[2].remap_addr
;
600 snd_iprintf(buffer
,"PCMREADER:\n");
601 for (i
= PCM_READER_BUF1
;i
< PCM_READER_BUF1
+ 0x30; i
+= sizeof(u32
),col
++) {
603 snd_iprintf(buffer
,"\n");
608 snd_iprintf(buffer
, "%04X ",i
);
611 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
614 snd_iprintf(buffer
,"\nMIX_SAMPLE_BUF1:\n");
617 for (i
= MIX_SAMPLE_BUF1
;i
< MIX_SAMPLE_BUF1
+ 0x40; i
+= sizeof(u32
),col
++) {
619 snd_iprintf(buffer
,"\n");
624 snd_iprintf(buffer
, "%04X ",i
);
627 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
630 snd_iprintf(buffer
,"\nSRC_TASK_SCB1:\n");
632 for (i
= 0x2480 ; i
< 0x2480 + 0x40 ; i
+= sizeof(u32
),col
++) {
634 snd_iprintf(buffer
,"\n");
639 snd_iprintf(buffer
, "%04X ",i
);
642 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
646 snd_iprintf(buffer
,"\nSPDIFO_BUFFER:\n");
648 for (i
= SPDIFO_IP_OUTPUT_BUFFER1
;i
< SPDIFO_IP_OUTPUT_BUFFER1
+ 0x30; i
+= sizeof(u32
),col
++) {
650 snd_iprintf(buffer
,"\n");
655 snd_iprintf(buffer
, "%04X ",i
);
658 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
661 snd_iprintf(buffer
,"\n...\n");
664 for (i
= SPDIFO_IP_OUTPUT_BUFFER1
+0xD0;i
< SPDIFO_IP_OUTPUT_BUFFER1
+ 0x110; i
+= sizeof(u32
),col
++) {
666 snd_iprintf(buffer
,"\n");
671 snd_iprintf(buffer
, "%04X ",i
);
674 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
678 snd_iprintf(buffer
,"\nOUTPUT_SNOOP:\n");
680 for (i
= OUTPUT_SNOOP_BUFFER
;i
< OUTPUT_SNOOP_BUFFER
+ 0x40; i
+= sizeof(u32
),col
++) {
682 snd_iprintf(buffer
,"\n");
687 snd_iprintf(buffer
, "%04X ",i
);
690 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
693 snd_iprintf(buffer
,"\nCODEC_INPUT_BUF1: \n");
695 for (i
= CODEC_INPUT_BUF1
;i
< CODEC_INPUT_BUF1
+ 0x40; i
+= sizeof(u32
),col
++) {
697 snd_iprintf(buffer
,"\n");
702 snd_iprintf(buffer
, "%04X ",i
);
705 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
708 snd_iprintf(buffer
,"\nWRITE_BACK_BUF1: \n");
710 for (i
= WRITE_BACK_BUF1
;i
< WRITE_BACK_BUF1
+ 0x40; i
+= sizeof(u32
),col
++) {
712 snd_iprintf(buffer
,"\n");
717 snd_iprintf(buffer
, "%04X ",i
);
720 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
724 snd_iprintf(buffer
,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n");
726 for (i
= SPDIFI_IP_OUTPUT_BUFFER1
;i
< SPDIFI_IP_OUTPUT_BUFFER1
+ 0x80; i
+= sizeof(u32
),col
++) {
728 snd_iprintf(buffer
,"\n");
733 snd_iprintf(buffer
, "%04X ",i
);
736 snd_iprintf(buffer
,"%08X ",readl(dst
+ i
));
738 snd_iprintf(buffer
,"\n");
741 int cs46xx_dsp_proc_init (snd_card_t
* card
, cs46xx_t
*chip
)
743 snd_info_entry_t
*entry
;
744 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
747 ins
->snd_card
= card
;
749 if ((entry
= snd_info_create_card_entry(card
, "dsp", card
->proc_root
)) != NULL
) {
750 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
751 entry
->mode
= S_IFDIR
| S_IRUGO
| S_IXUGO
;
752 entry
->c
.text
.read_size
= 512;
754 if (snd_info_register(entry
) < 0) {
755 snd_info_free_entry(entry
);
760 ins
->proc_dsp_dir
= entry
;
762 if (!ins
->proc_dsp_dir
)
765 if ((entry
= snd_info_create_card_entry(card
, "spos_symbols", ins
->proc_dsp_dir
)) != NULL
) {
766 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
767 entry
->private_data
= chip
;
768 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
769 entry
->c
.text
.read_size
= 512;
770 entry
->c
.text
.read
= cs46xx_dsp_proc_symbol_table_read
;
771 if (snd_info_register(entry
) < 0) {
772 snd_info_free_entry(entry
);
776 ins
->proc_sym_info_entry
= entry
;
778 if ((entry
= snd_info_create_card_entry(card
, "spos_modules", ins
->proc_dsp_dir
)) != NULL
) {
779 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
780 entry
->private_data
= chip
;
781 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
782 entry
->c
.text
.read_size
= 512;
783 entry
->c
.text
.read
= cs46xx_dsp_proc_modules_read
;
784 if (snd_info_register(entry
) < 0) {
785 snd_info_free_entry(entry
);
789 ins
->proc_modules_info_entry
= entry
;
791 if ((entry
= snd_info_create_card_entry(card
, "parameter", ins
->proc_dsp_dir
)) != NULL
) {
792 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
793 entry
->private_data
= chip
;
794 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
795 entry
->c
.text
.read_size
= 512;
796 entry
->c
.text
.read
= cs46xx_dsp_proc_parameter_dump_read
;
797 if (snd_info_register(entry
) < 0) {
798 snd_info_free_entry(entry
);
802 ins
->proc_parameter_dump_info_entry
= entry
;
804 if ((entry
= snd_info_create_card_entry(card
, "sample", ins
->proc_dsp_dir
)) != NULL
) {
805 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
806 entry
->private_data
= chip
;
807 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
808 entry
->c
.text
.read_size
= 512;
809 entry
->c
.text
.read
= cs46xx_dsp_proc_sample_dump_read
;
810 if (snd_info_register(entry
) < 0) {
811 snd_info_free_entry(entry
);
815 ins
->proc_sample_dump_info_entry
= entry
;
817 if ((entry
= snd_info_create_card_entry(card
, "task_tree", ins
->proc_dsp_dir
)) != NULL
) {
818 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
819 entry
->private_data
= chip
;
820 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
821 entry
->c
.text
.read_size
= 512;
822 entry
->c
.text
.read
= cs46xx_dsp_proc_task_tree_read
;
823 if (snd_info_register(entry
) < 0) {
824 snd_info_free_entry(entry
);
828 ins
->proc_task_info_entry
= entry
;
830 if ((entry
= snd_info_create_card_entry(card
, "scb_info", ins
->proc_dsp_dir
)) != NULL
) {
831 entry
->content
= SNDRV_INFO_CONTENT_TEXT
;
832 entry
->private_data
= chip
;
833 entry
->mode
= S_IFREG
| S_IRUGO
| S_IWUSR
;
834 entry
->c
.text
.read_size
= 1024;
835 entry
->c
.text
.read
= cs46xx_dsp_proc_scb_read
;
836 if (snd_info_register(entry
) < 0) {
837 snd_info_free_entry(entry
);
841 ins
->proc_scb_info_entry
= entry
;
843 down(&chip
->spos_mutex
);
844 /* register/update SCB's entries on proc */
845 for (i
= 0; i
< ins
->nscb
; ++i
) {
846 if (ins
->scbs
[i
].deleted
) continue;
848 cs46xx_dsp_proc_register_scb_desc (chip
, (ins
->scbs
+ i
));
850 up(&chip
->spos_mutex
);
855 int cs46xx_dsp_proc_done (cs46xx_t
*chip
)
857 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
860 if (ins
->proc_sym_info_entry
) {
861 snd_info_unregister(ins
->proc_sym_info_entry
);
862 ins
->proc_sym_info_entry
= NULL
;
865 if (ins
->proc_modules_info_entry
) {
866 snd_info_unregister(ins
->proc_modules_info_entry
);
867 ins
->proc_modules_info_entry
= NULL
;
870 if (ins
->proc_parameter_dump_info_entry
) {
871 snd_info_unregister(ins
->proc_parameter_dump_info_entry
);
872 ins
->proc_parameter_dump_info_entry
= NULL
;
875 if (ins
->proc_sample_dump_info_entry
) {
876 snd_info_unregister(ins
->proc_sample_dump_info_entry
);
877 ins
->proc_sample_dump_info_entry
= NULL
;
880 if (ins
->proc_scb_info_entry
) {
881 snd_info_unregister(ins
->proc_scb_info_entry
);
882 ins
->proc_scb_info_entry
= NULL
;
885 if (ins
->proc_task_info_entry
) {
886 snd_info_unregister(ins
->proc_task_info_entry
);
887 ins
->proc_task_info_entry
= NULL
;
890 down(&chip
->spos_mutex
);
891 for (i
= 0; i
< ins
->nscb
; ++i
) {
892 if (ins
->scbs
[i
].deleted
) continue;
893 cs46xx_dsp_proc_free_scb_desc ( (ins
->scbs
+ i
) );
895 up(&chip
->spos_mutex
);
897 if (ins
->proc_dsp_dir
) {
898 snd_info_unregister (ins
->proc_dsp_dir
);
899 ins
->proc_dsp_dir
= NULL
;
905 static int debug_tree
;
906 static void _dsp_create_task_tree (cs46xx_t
*chip
,u32
* task_data
, u32 dest
, int size
)
908 void __iomem
*spdst
= chip
->region
.idx
[1].remap_addr
+
909 DSP_PARAMETER_BYTE_OFFSET
+ dest
* sizeof(u32
);
912 for (i
= 0; i
< size
; ++i
) {
913 if (debug_tree
) printk ("addr %p, val %08x\n",spdst
,task_data
[i
]);
914 writel(task_data
[i
],spdst
);
915 spdst
+= sizeof(u32
);
919 static int debug_scb
;
920 static void _dsp_create_scb (cs46xx_t
*chip
,u32
* scb_data
, u32 dest
)
922 void __iomem
*spdst
= chip
->region
.idx
[1].remap_addr
+
923 DSP_PARAMETER_BYTE_OFFSET
+ dest
* sizeof(u32
);
926 for (i
= 0; i
< 0x10; ++i
) {
927 if (debug_scb
) printk ("addr %p, val %08x\n",spdst
,scb_data
[i
]);
928 writel(scb_data
[i
],spdst
);
929 spdst
+= sizeof(u32
);
933 static int find_free_scb_index (dsp_spos_instance_t
* ins
)
935 int index
= ins
->nscb
, i
;
937 for (i
= ins
->scb_highest_frag_index
; i
< ins
->nscb
; ++i
) {
938 if (ins
->scbs
[i
].deleted
) {
947 static dsp_scb_descriptor_t
* _map_scb (cs46xx_t
*chip
,char * name
,u32 dest
)
949 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
950 dsp_scb_descriptor_t
* desc
= NULL
;
953 if (ins
->nscb
== DSP_MAX_SCB_DESC
- 1) {
954 snd_printk(KERN_ERR
"dsp_spos: got no place for other SCB\n");
958 index
= find_free_scb_index (ins
);
960 strcpy(ins
->scbs
[index
].scb_name
, name
);
961 ins
->scbs
[index
].address
= dest
;
962 ins
->scbs
[index
].index
= index
;
963 ins
->scbs
[index
].proc_info
= NULL
;
964 ins
->scbs
[index
].ref_count
= 1;
965 ins
->scbs
[index
].deleted
= 0;
966 spin_lock_init(&ins
->scbs
[index
].lock
);
968 desc
= (ins
->scbs
+ index
);
969 ins
->scbs
[index
].scb_symbol
= add_symbol (chip
, name
, dest
, SYMBOL_PARAMETER
);
971 if (index
> ins
->scb_highest_frag_index
)
972 ins
->scb_highest_frag_index
= index
;
974 if (index
== ins
->nscb
)
980 static dsp_task_descriptor_t
* _map_task_tree (cs46xx_t
*chip
,char * name
,u32 dest
,u32 size
)
982 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
983 dsp_task_descriptor_t
* desc
= NULL
;
985 if (ins
->ntask
== DSP_MAX_TASK_DESC
- 1) {
986 snd_printk(KERN_ERR
"dsp_spos: got no place for other TASK\n");
990 strcpy(ins
->tasks
[ins
->ntask
].task_name
,name
);
991 ins
->tasks
[ins
->ntask
].address
= dest
;
992 ins
->tasks
[ins
->ntask
].size
= size
;
994 /* quick find in list */
995 ins
->tasks
[ins
->ntask
].index
= ins
->ntask
;
996 desc
= (ins
->tasks
+ ins
->ntask
);
999 add_symbol (chip
,name
,dest
,SYMBOL_PARAMETER
);
1003 dsp_scb_descriptor_t
* cs46xx_dsp_create_scb (cs46xx_t
*chip
,char * name
, u32
* scb_data
,u32 dest
)
1005 dsp_scb_descriptor_t
* desc
;
1007 desc
= _map_scb (chip
,name
,dest
);
1009 _dsp_create_scb(chip
,scb_data
,dest
);
1011 snd_printk(KERN_ERR
"dsp_spos: failed to map SCB\n");
1018 static dsp_task_descriptor_t
* cs46xx_dsp_create_task_tree (cs46xx_t
*chip
,char * name
, u32
* task_data
,u32 dest
,int size
)
1020 dsp_task_descriptor_t
* desc
;
1022 desc
= _map_task_tree (chip
,name
,dest
,size
);
1024 _dsp_create_task_tree(chip
,task_data
,dest
,size
);
1026 snd_printk(KERN_ERR
"dsp_spos: failed to map TASK\n");
1032 int cs46xx_dsp_scb_and_task_init (cs46xx_t
*chip
)
1034 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1035 symbol_entry_t
* fg_task_tree_header_code
;
1036 symbol_entry_t
* task_tree_header_code
;
1037 symbol_entry_t
* task_tree_thread
;
1038 symbol_entry_t
* null_algorithm
;
1039 symbol_entry_t
* magic_snoop_task
;
1041 dsp_scb_descriptor_t
* timing_master_scb
;
1042 dsp_scb_descriptor_t
* codec_out_scb
;
1043 dsp_scb_descriptor_t
* codec_in_scb
;
1044 dsp_scb_descriptor_t
* src_task_scb
;
1045 dsp_scb_descriptor_t
* master_mix_scb
;
1046 dsp_scb_descriptor_t
* rear_mix_scb
;
1047 dsp_scb_descriptor_t
* record_mix_scb
;
1048 dsp_scb_descriptor_t
* write_back_scb
;
1049 dsp_scb_descriptor_t
* vari_decimate_scb
;
1050 dsp_scb_descriptor_t
* rear_codec_out_scb
;
1051 dsp_scb_descriptor_t
* clfe_codec_out_scb
;
1052 dsp_scb_descriptor_t
* magic_snoop_scb
;
1054 int fifo_addr
,fifo_span
,valid_slots
;
1056 static spos_control_block_t sposcb
= {
1057 /* 0 */ HFG_TREE_SCB
,HFG_STACK
,
1058 /* 1 */ SPOSCB_ADDR
,BG_TREE_SCB_ADDR
,
1059 /* 2 */ DSP_SPOS_DC
,0,
1060 /* 3 */ DSP_SPOS_DC
,DSP_SPOS_DC
,
1062 /* 5 */ DSP_SPOS_UU
,0,
1063 /* 6 */ FG_TASK_HEADER_ADDR
,0,
1065 /* 8 */ DSP_SPOS_UU
,DSP_SPOS_DC
,
1067 /* A */ 0,HFG_FIRST_EXECUTE_MODE
,
1068 /* B */ DSP_SPOS_UU
,DSP_SPOS_UU
,
1069 /* C */ DSP_SPOS_DC_DC
,
1070 /* D */ DSP_SPOS_DC_DC
,
1071 /* E */ DSP_SPOS_DC_DC
,
1072 /* F */ DSP_SPOS_DC_DC
1075 cs46xx_dsp_create_task_tree(chip
, "sposCB", (u32
*)&sposcb
, SPOSCB_ADDR
, 0x10);
1077 null_algorithm
= cs46xx_dsp_lookup_symbol(chip
, "NULLALGORITHM", SYMBOL_CODE
);
1078 if (null_algorithm
== NULL
) {
1079 snd_printk(KERN_ERR
"dsp_spos: symbol NULLALGORITHM not found\n");
1083 fg_task_tree_header_code
= cs46xx_dsp_lookup_symbol(chip
, "FGTASKTREEHEADERCODE", SYMBOL_CODE
);
1084 if (fg_task_tree_header_code
== NULL
) {
1085 snd_printk(KERN_ERR
"dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
1089 task_tree_header_code
= cs46xx_dsp_lookup_symbol(chip
, "TASKTREEHEADERCODE", SYMBOL_CODE
);
1090 if (task_tree_header_code
== NULL
) {
1091 snd_printk(KERN_ERR
"dsp_spos: symbol TASKTREEHEADERCODE not found\n");
1095 task_tree_thread
= cs46xx_dsp_lookup_symbol(chip
, "TASKTREETHREAD", SYMBOL_CODE
);
1096 if (task_tree_thread
== NULL
) {
1097 snd_printk(KERN_ERR
"dsp_spos: symbol TASKTREETHREAD not found\n");
1101 magic_snoop_task
= cs46xx_dsp_lookup_symbol(chip
, "MAGICSNOOPTASK", SYMBOL_CODE
);
1102 if (magic_snoop_task
== NULL
) {
1103 snd_printk(KERN_ERR
"dsp_spos: symbol MAGICSNOOPTASK not found\n");
1108 /* create the null SCB */
1109 static generic_scb_t null_scb
= {
1112 NULL_SCB_ADDR
, NULL_SCB_ADDR
,
1120 null_scb
.entry_point
= null_algorithm
->address
;
1121 ins
->the_null_scb
= cs46xx_dsp_create_scb(chip
, "nullSCB", (u32
*)&null_scb
, NULL_SCB_ADDR
);
1122 ins
->the_null_scb
->task_entry
= null_algorithm
;
1123 ins
->the_null_scb
->sub_list_ptr
= ins
->the_null_scb
;
1124 ins
->the_null_scb
->next_scb_ptr
= ins
->the_null_scb
;
1125 ins
->the_null_scb
->parent_scb_ptr
= NULL
;
1126 cs46xx_dsp_proc_register_scb_desc (chip
,ins
->the_null_scb
);
1130 /* setup foreground task tree */
1131 static task_tree_control_block_t fg_task_tree_hdr
= {
1132 { FG_TASK_HEADER_ADDR
| (DSP_SPOS_DC
<< 0x10),
1136 DSP_SPOS_DC
, DSP_SPOS_DC
,
1140 DSP_SPOS_DC
,DSP_SPOS_DC
},
1143 BG_TREE_SCB_ADDR
,TIMINGMASTER_SCB_ADDR
,
1145 FG_TASK_HEADER_ADDR
+ TCBData
,
1151 2,SPOSCB_ADDR
+ HFGFlags
,
1153 FG_TASK_HEADER_ADDR
+ TCBContextBlk
,FG_STACK
1158 DSP_SPOS_DC
,DSP_SPOS_DC
,
1159 DSP_SPOS_DC
,DSP_SPOS_DC
,
1160 DSP_SPOS_DC
,DSP_SPOS_DC
,
1161 DSP_SPOS_DC
,DSP_SPOS_DC
,
1194 FG_INTERVAL_TIMER_PERIOD
,DSP_SPOS_UU
,
1199 fg_task_tree_hdr
.links
.entry_point
= fg_task_tree_header_code
->address
;
1200 fg_task_tree_hdr
.context_blk
.stack0
= task_tree_thread
->address
;
1201 cs46xx_dsp_create_task_tree(chip
,"FGtaskTreeHdr",(u32
*)&fg_task_tree_hdr
,FG_TASK_HEADER_ADDR
,0x35);
1206 /* setup foreground task tree */
1207 static task_tree_control_block_t bg_task_tree_hdr
= {
1211 DSP_SPOS_DC
, DSP_SPOS_DC
,
1212 DSP_SPOS_DC
, DSP_SPOS_DC
,
1216 DSP_SPOS_DC
,DSP_SPOS_DC
},
1219 NULL_SCB_ADDR
,NULL_SCB_ADDR
, /* Set up the background to do nothing */
1221 BG_TREE_SCB_ADDR
+ TCBData
,
1227 0,SPOSCB_ADDR
+ HFGFlags
,
1229 BG_TREE_SCB_ADDR
+ TCBContextBlk
,BG_STACK
1234 DSP_SPOS_DC
,DSP_SPOS_DC
,
1235 DSP_SPOS_DC
,DSP_SPOS_DC
,
1236 DSP_SPOS_DC
,DSP_SPOS_DC
,
1237 DSP_SPOS_DC
,DSP_SPOS_DC
,
1270 BG_INTERVAL_TIMER_PERIOD
,DSP_SPOS_UU
,
1275 bg_task_tree_hdr
.links
.entry_point
= task_tree_header_code
->address
;
1276 bg_task_tree_hdr
.context_blk
.stack0
= task_tree_thread
->address
;
1277 cs46xx_dsp_create_task_tree(chip
,"BGtaskTreeHdr",(u32
*)&bg_task_tree_hdr
,BG_TREE_SCB_ADDR
,0x35);
1280 /* create timing master SCB */
1281 timing_master_scb
= cs46xx_dsp_create_timing_master_scb(chip
);
1283 /* create the CODEC output task */
1284 codec_out_scb
= cs46xx_dsp_create_codec_out_scb(chip
,"CodecOutSCB_I",0x0010,0x0000,
1286 CODECOUT_SCB_ADDR
,timing_master_scb
,
1287 SCB_ON_PARENT_SUBLIST_SCB
);
1289 if (!codec_out_scb
) goto _fail_end
;
1290 /* create the master mix SCB */
1291 master_mix_scb
= cs46xx_dsp_create_mix_only_scb(chip
,"MasterMixSCB",
1292 MIX_SAMPLE_BUF1
,MASTERMIX_SCB_ADDR
,
1294 SCB_ON_PARENT_SUBLIST_SCB
);
1295 ins
->master_mix_scb
= master_mix_scb
;
1297 if (!master_mix_scb
) goto _fail_end
;
1299 /* create codec in */
1300 codec_in_scb
= cs46xx_dsp_create_codec_in_scb(chip
,"CodecInSCB",0x0010,0x00A0,
1302 CODECIN_SCB_ADDR
,codec_out_scb
,
1303 SCB_ON_PARENT_NEXT_SCB
);
1304 if (!codec_in_scb
) goto _fail_end
;
1305 ins
->codec_in_scb
= codec_in_scb
;
1307 /* create write back scb */
1308 write_back_scb
= cs46xx_dsp_create_mix_to_ostream_scb(chip
,"WriteBackSCB",
1309 WRITE_BACK_BUF1
,WRITE_BACK_SPB
,
1312 SCB_ON_PARENT_NEXT_SCB
);
1313 if (!write_back_scb
) goto _fail_end
;
1316 static mix2_ostream_spb_t mix2_ostream_spb
= {
1321 /* dirty hack ... */
1322 _dsp_create_task_tree (chip
,(u32
*)&mix2_ostream_spb
,WRITE_BACK_SPB
,2);
1325 /* input sample converter */
1326 vari_decimate_scb
= cs46xx_dsp_create_vari_decimate_scb(chip
,"VariDecimateSCB",
1329 VARIDECIMATE_SCB_ADDR
,
1331 SCB_ON_PARENT_SUBLIST_SCB
);
1332 if (!vari_decimate_scb
) goto _fail_end
;
1334 /* create the record mixer SCB */
1335 record_mix_scb
= cs46xx_dsp_create_mix_only_scb(chip
,"RecordMixerSCB",
1337 RECORD_MIXER_SCB_ADDR
,
1339 SCB_ON_PARENT_SUBLIST_SCB
);
1340 ins
->record_mixer_scb
= record_mix_scb
;
1342 if (!record_mix_scb
) goto _fail_end
;
1344 valid_slots
= snd_cs46xx_peekBA0(chip
, BA0_ACOSV
);
1346 snd_assert (chip
->nr_ac97_codecs
== 1 || chip
->nr_ac97_codecs
== 2);
1348 if (chip
->nr_ac97_codecs
== 1) {
1349 /* output on slot 5 and 11
1354 /* enable slot 5 and 11 */
1355 valid_slots
|= ACOSV_SLV5
| ACOSV_SLV11
;
1357 /* output on slot 7 and 8
1358 on secondary CODEC */
1362 /* enable slot 7 and 8 */
1363 valid_slots
|= ACOSV_SLV7
| ACOSV_SLV8
;
1365 /* create CODEC tasklet for rear speakers output*/
1366 rear_codec_out_scb
= cs46xx_dsp_create_codec_out_scb(chip
,"CodecOutSCB_Rear",fifo_span
,fifo_addr
,
1367 REAR_MIXER_SCB_ADDR
,
1368 REAR_CODECOUT_SCB_ADDR
,codec_in_scb
,
1369 SCB_ON_PARENT_NEXT_SCB
);
1370 if (!rear_codec_out_scb
) goto _fail_end
;
1373 /* create the rear PCM channel mixer SCB */
1374 rear_mix_scb
= cs46xx_dsp_create_mix_only_scb(chip
,"RearMixerSCB",
1376 REAR_MIXER_SCB_ADDR
,
1378 SCB_ON_PARENT_SUBLIST_SCB
);
1379 ins
->rear_mix_scb
= rear_mix_scb
;
1380 if (!rear_mix_scb
) goto _fail_end
;
1382 if (chip
->nr_ac97_codecs
== 2) {
1383 /* create CODEC tasklet for rear Center/LFE output
1384 slot 6 and 9 on seconadry CODEC */
1385 clfe_codec_out_scb
= cs46xx_dsp_create_codec_out_scb(chip
,"CodecOutSCB_CLFE",0x0030,0x0030,
1386 CLFE_MIXER_SCB_ADDR
,
1387 CLFE_CODEC_SCB_ADDR
,
1389 SCB_ON_PARENT_NEXT_SCB
);
1390 if (!clfe_codec_out_scb
) goto _fail_end
;
1393 /* create the rear PCM channel mixer SCB */
1394 ins
->center_lfe_mix_scb
= cs46xx_dsp_create_mix_only_scb(chip
,"CLFEMixerSCB",
1396 CLFE_MIXER_SCB_ADDR
,
1398 SCB_ON_PARENT_SUBLIST_SCB
);
1399 if (!ins
->center_lfe_mix_scb
) goto _fail_end
;
1401 /* enable slot 6 and 9 */
1402 valid_slots
|= ACOSV_SLV6
| ACOSV_SLV9
;
1404 clfe_codec_out_scb
= rear_codec_out_scb
;
1405 ins
->center_lfe_mix_scb
= rear_mix_scb
;
1408 /* enable slots depending on CODEC configuration */
1409 snd_cs46xx_pokeBA0(chip
, BA0_ACOSV
, valid_slots
);
1411 /* the magic snooper */
1412 magic_snoop_scb
= cs46xx_dsp_create_magic_snoop_scb (chip
,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR
,
1413 OUTPUT_SNOOP_BUFFER
,
1416 SCB_ON_PARENT_NEXT_SCB
);
1419 if (!magic_snoop_scb
) goto _fail_end
;
1420 ins
->ref_snoop_scb
= magic_snoop_scb
;
1423 if (!cs46xx_dsp_create_spio_write_scb(chip
,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR
,
1425 SCB_ON_PARENT_NEXT_SCB
))
1428 /* SPDIF input sampel rate converter */
1429 src_task_scb
= cs46xx_dsp_create_src_task_scb(chip
,"SrcTaskSCB_SPDIFI",
1430 ins
->spdif_in_sample_rate
,
1432 SRC_DELAY_BUF1
,SRCTASK_SCB_ADDR
,
1434 SCB_ON_PARENT_SUBLIST_SCB
,1);
1436 if (!src_task_scb
) goto _fail_end
;
1437 cs46xx_src_unlink(chip
,src_task_scb
);
1439 /* NOTE: when we now how to detect the SPDIF input
1440 sample rate we will use this SRC to adjust it */
1441 ins
->spdif_in_src
= src_task_scb
;
1443 cs46xx_dsp_async_init(chip
,timing_master_scb
);
1447 snd_printk(KERN_ERR
"dsp_spos: failed to setup SCB's in DSP\n");
1451 static int cs46xx_dsp_async_init (cs46xx_t
*chip
, dsp_scb_descriptor_t
* fg_entry
)
1453 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1454 symbol_entry_t
* s16_async_codec_input_task
;
1455 symbol_entry_t
* spdifo_task
;
1456 symbol_entry_t
* spdifi_task
;
1457 dsp_scb_descriptor_t
* spdifi_scb_desc
,* spdifo_scb_desc
,* async_codec_scb_desc
;
1459 s16_async_codec_input_task
= cs46xx_dsp_lookup_symbol(chip
, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE
);
1460 if (s16_async_codec_input_task
== NULL
) {
1461 snd_printk(KERN_ERR
"dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
1464 spdifo_task
= cs46xx_dsp_lookup_symbol(chip
, "SPDIFOTASK", SYMBOL_CODE
);
1465 if (spdifo_task
== NULL
) {
1466 snd_printk(KERN_ERR
"dsp_spos: symbol SPDIFOTASK not found\n");
1470 spdifi_task
= cs46xx_dsp_lookup_symbol(chip
, "SPDIFITASK", SYMBOL_CODE
);
1471 if (spdifi_task
== NULL
) {
1472 snd_printk(KERN_ERR
"dsp_spos: symbol SPDIFITASK not found\n");
1478 spdifoscb_t spdifo_scb
= {
1479 /* 0 */ DSP_SPOS_UUUU
,
1486 /* NOTE: the SPDIF output task read samples in mono
1487 format, the AsynchFGTxSCB task writes to buffer
1490 /* 5 */ RSCONFIG_SAMPLE_16MONO
+ RSCONFIG_MODULO_256
,
1491 /* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1
<< 0x10 ) | 0xFFFC,
1494 /* 9 */ FG_TASK_HEADER_ADDR
, NULL_SCB_ADDR
,
1495 /* A */ spdifo_task
->address
,
1496 SPDIFO_SCB_INST
+ SPDIFOFIFOPointer
,
1498 /* B */ 0x0040, /*DSP_SPOS_UUUU,*/
1499 /* C */ 0x20ff, /*DSP_SPOS_UUUU,*/
1501 /* D */ 0x804c,0, /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */
1502 /* E */ 0x0108,0x0001, /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
1503 /* F */ DSP_SPOS_UUUU
/* SPDIFOFree; */
1507 spdifiscb_t spdifi_scb
= {
1508 /* 0 */ DSP_SPOS_UULO
,DSP_SPOS_UUHI
,
1511 /* 3 */ 1,4000, /* SPDIFICountLimit SPDIFICount */
1512 /* 4 */ DSP_SPOS_UUUU
, /* SPDIFIStatusData */
1513 /* 5 */ 0,DSP_SPOS_UUHI
, /* StatusData, Free4 */
1514 /* 6 */ DSP_SPOS_UUUU
, /* Free3 */
1515 /* 7 */ DSP_SPOS_UU
,DSP_SPOS_DC
, /* Free2 BitCount*/
1516 /* 8 */ DSP_SPOS_UUUU
, /* TempStatus */
1517 /* 9 */ SPDIFO_SCB_INST
, NULL_SCB_ADDR
,
1518 /* A */ spdifi_task
->address
,
1519 SPDIFI_SCB_INST
+ SPDIFIFIFOPointer
,
1520 /* NOTE: The SPDIF input task write the sample in mono
1521 format from the HW FIFO, the AsynchFGRxSCB task reads
1524 /* B */ RSCONFIG_SAMPLE_16MONO
+ RSCONFIG_MODULO_128
,
1525 /* C */ (SPDIFI_IP_OUTPUT_BUFFER1
<< 0x10) | 0xFFFC,
1527 /* E */ 0x01f0,0x0001,
1528 /* F */ DSP_SPOS_UUUU
/* SPDIN_STATUS monitor */
1532 async_codec_input_scb_t async_codec_input_scb
= {
1533 /* 0 */ DSP_SPOS_UUUU
,
1537 /* 4 */ 0x0118,0x0001,
1538 /* 5 */ RSCONFIG_SAMPLE_16MONO
+ RSCONFIG_MODULO_64
,
1539 /* 6 */ (ASYNC_IP_OUTPUT_BUFFER1
<< 0x10) | 0xFFFC,
1540 /* 7 */ DSP_SPOS_UU
,0x3,
1541 /* 8 */ DSP_SPOS_UUUU
,
1542 /* 9 */ SPDIFI_SCB_INST
,NULL_SCB_ADDR
,
1543 /* A */ s16_async_codec_input_task
->address
,
1544 HFG_TREE_SCB
+ AsyncCIOFIFOPointer
,
1546 /* B */ RSCONFIG_SAMPLE_16STEREO
+ RSCONFIG_MODULO_64
,
1547 /* C */ (ASYNC_IP_OUTPUT_BUFFER1
<< 0x10), /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/
1549 #ifdef UseASER1Input
1550 /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
1551 Init. 0000:8042: for ASER1
1552 0000:8044: for ASER2 */
1555 /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
1556 Init 1 stero:8050 ASER1
1557 Init 0 mono:8070 ASER2
1558 Init 1 Stereo : 0100 ASER1 (Set by script) */
1559 /* E */ 0x0100,0x0001,
1563 #ifdef UseASER2Input
1564 /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
1565 Init. 0000:8042: for ASER1
1566 0000:8044: for ASER2 */
1569 /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
1570 Init 1 stero:8050 ASER1
1571 Init 0 mono:8070 ASER2
1572 Init 1 Stereo : 0100 ASER1 (Set by script) */
1573 /* E */ 0x0110,0x0001,
1577 /* short AsyncCIOutputBufModulo:AsyncCIFree;
1578 AsyncCIOutputBufModulo: The modulo size for
1579 the output buffer of this task */
1580 /* F */ 0, /* DSP_SPOS_UUUU */
1583 spdifo_scb_desc
= cs46xx_dsp_create_scb(chip
,"SPDIFOSCB",(u32
*)&spdifo_scb
,SPDIFO_SCB_INST
);
1585 snd_assert(spdifo_scb_desc
, return -EIO
);
1586 spdifi_scb_desc
= cs46xx_dsp_create_scb(chip
,"SPDIFISCB",(u32
*)&spdifi_scb
,SPDIFI_SCB_INST
);
1587 snd_assert(spdifi_scb_desc
, return -EIO
);
1588 async_codec_scb_desc
= cs46xx_dsp_create_scb(chip
,"AsynCodecInputSCB",(u32
*)&async_codec_input_scb
, HFG_TREE_SCB
);
1589 snd_assert(async_codec_scb_desc
, return -EIO
);
1591 async_codec_scb_desc
->parent_scb_ptr
= NULL
;
1592 async_codec_scb_desc
->next_scb_ptr
= spdifi_scb_desc
;
1593 async_codec_scb_desc
->sub_list_ptr
= ins
->the_null_scb
;
1594 async_codec_scb_desc
->task_entry
= s16_async_codec_input_task
;
1596 spdifi_scb_desc
->parent_scb_ptr
= async_codec_scb_desc
;
1597 spdifi_scb_desc
->next_scb_ptr
= spdifo_scb_desc
;
1598 spdifi_scb_desc
->sub_list_ptr
= ins
->the_null_scb
;
1599 spdifi_scb_desc
->task_entry
= spdifi_task
;
1601 spdifo_scb_desc
->parent_scb_ptr
= spdifi_scb_desc
;
1602 spdifo_scb_desc
->next_scb_ptr
= fg_entry
;
1603 spdifo_scb_desc
->sub_list_ptr
= ins
->the_null_scb
;
1604 spdifo_scb_desc
->task_entry
= spdifo_task
;
1606 /* this one is faked, as the parnet of SPDIFO task
1607 is the FG task tree */
1608 fg_entry
->parent_scb_ptr
= spdifo_scb_desc
;
1611 cs46xx_dsp_proc_register_scb_desc (chip
,spdifo_scb_desc
);
1612 cs46xx_dsp_proc_register_scb_desc (chip
,spdifi_scb_desc
);
1613 cs46xx_dsp_proc_register_scb_desc (chip
,async_codec_scb_desc
);
1615 /* Async MASTER ENABLE, affects both SPDIF input and output */
1616 snd_cs46xx_pokeBA0(chip
, BA0_ASER_MASTER
, 0x1 );
1623 static void cs46xx_dsp_disable_spdif_hw (cs46xx_t
*chip
)
1625 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1627 /* set SPDIF output FIFO slot */
1628 snd_cs46xx_pokeBA0(chip
, BA0_ASER_FADDR
, 0);
1630 /* SPDIF output MASTER ENABLE */
1631 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CONTROL
, 0);
1633 /* right and left validate bit */
1634 /*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/
1635 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CSUV
, 0x0);
1637 /* clear fifo pointer */
1638 cs46xx_poke_via_dsp (chip
,SP_SPDIN_FIFOPTR
, 0x0);
1641 ins
->spdif_status_out
&= ~DSP_SPDIF_STATUS_HW_ENABLED
;
1644 int cs46xx_dsp_enable_spdif_hw (cs46xx_t
*chip
)
1646 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1648 /* if hw-ctrl already enabled, turn off to reset logic ... */
1649 cs46xx_dsp_disable_spdif_hw (chip
);
1652 /* set SPDIF output FIFO slot */
1653 snd_cs46xx_pokeBA0(chip
, BA0_ASER_FADDR
, ( 0x8000 | ((SP_SPDOUT_FIFO
>> 4) << 4) ));
1655 /* SPDIF output MASTER ENABLE */
1656 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CONTROL
, 0x80000000);
1658 /* right and left validate bit */
1659 cs46xx_poke_via_dsp (chip
,SP_SPDOUT_CSUV
, ins
->spdif_csuv_default
);
1662 ins
->spdif_status_out
|= DSP_SPDIF_STATUS_HW_ENABLED
;
1667 int cs46xx_dsp_enable_spdif_in (cs46xx_t
*chip
)
1669 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1671 /* turn on amplifier */
1672 chip
->active_ctrl(chip
, 1);
1673 chip
->amplifier_ctrl(chip
, 1);
1675 snd_assert (ins
->asynch_rx_scb
== NULL
,return -EINVAL
);
1676 snd_assert (ins
->spdif_in_src
!= NULL
,return -EINVAL
);
1678 down(&chip
->spos_mutex
);
1680 if ( ! (ins
->spdif_status_out
& DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED
) ) {
1681 /* time countdown enable */
1682 cs46xx_poke_via_dsp (chip
,SP_ASER_COUNTDOWN
, 0x80000005);
1683 /* NOTE: 80000005 value is just magic. With all values
1684 that I've tested this one seem to give the best result.
1685 Got no explication why. (Benny) */
1687 /* SPDIF input MASTER ENABLE */
1688 cs46xx_poke_via_dsp (chip
,SP_SPDIN_CONTROL
, 0x800003ff);
1690 ins
->spdif_status_out
|= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED
;
1693 /* create and start the asynchronous receiver SCB */
1694 ins
->asynch_rx_scb
= cs46xx_dsp_create_asynch_fg_rx_scb(chip
,"AsynchFGRxSCB",
1697 SPDIFI_IP_OUTPUT_BUFFER1
,
1699 SCB_ON_PARENT_SUBLIST_SCB
);
1701 spin_lock_irq(&chip
->reg_lock
);
1703 /* reset SPDIF input sample buffer pointer */
1704 /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
1705 (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/
1707 /* reset FIFO ptr */
1708 /*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/
1709 cs46xx_src_link(chip
,ins
->spdif_in_src
);
1711 /* unmute SRC volume */
1712 cs46xx_dsp_scb_set_volume (chip
,ins
->spdif_in_src
,0x7fff,0x7fff);
1714 spin_unlock_irq(&chip
->reg_lock
);
1716 /* set SPDIF input sample rate and unmute
1717 NOTE: only 48khz support for SPDIF input this time */
1718 /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
1721 ins
->spdif_status_in
= 1;
1722 up(&chip
->spos_mutex
);
1727 int cs46xx_dsp_disable_spdif_in (cs46xx_t
*chip
)
1729 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1731 snd_assert (ins
->asynch_rx_scb
!= NULL
, return -EINVAL
);
1732 snd_assert (ins
->spdif_in_src
!= NULL
,return -EINVAL
);
1734 down(&chip
->spos_mutex
);
1736 /* Remove the asynchronous receiver SCB */
1737 cs46xx_dsp_remove_scb (chip
,ins
->asynch_rx_scb
);
1738 ins
->asynch_rx_scb
= NULL
;
1740 cs46xx_src_unlink(chip
,ins
->spdif_in_src
);
1743 ins
->spdif_status_in
= 0;
1744 up(&chip
->spos_mutex
);
1746 /* restore amplifier */
1747 chip
->active_ctrl(chip
, -1);
1748 chip
->amplifier_ctrl(chip
, -1);
1753 int cs46xx_dsp_enable_pcm_capture (cs46xx_t
*chip
)
1755 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1757 snd_assert (ins
->pcm_input
== NULL
,return -EINVAL
);
1758 snd_assert (ins
->ref_snoop_scb
!= NULL
,return -EINVAL
);
1760 down(&chip
->spos_mutex
);
1761 ins
->pcm_input
= cs46xx_add_record_source(chip
,ins
->ref_snoop_scb
,PCMSERIALIN_PCM_SCB_ADDR
,
1762 "PCMSerialInput_Wave");
1763 up(&chip
->spos_mutex
);
1768 int cs46xx_dsp_disable_pcm_capture (cs46xx_t
*chip
)
1770 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1772 snd_assert (ins
->pcm_input
!= NULL
,return -EINVAL
);
1774 down(&chip
->spos_mutex
);
1775 cs46xx_dsp_remove_scb (chip
,ins
->pcm_input
);
1776 ins
->pcm_input
= NULL
;
1777 up(&chip
->spos_mutex
);
1782 int cs46xx_dsp_enable_adc_capture (cs46xx_t
*chip
)
1784 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1786 snd_assert (ins
->adc_input
== NULL
,return -EINVAL
);
1787 snd_assert (ins
->codec_in_scb
!= NULL
,return -EINVAL
);
1789 down(&chip
->spos_mutex
);
1790 ins
->adc_input
= cs46xx_add_record_source(chip
,ins
->codec_in_scb
,PCMSERIALIN_SCB_ADDR
,
1791 "PCMSerialInput_ADC");
1792 up(&chip
->spos_mutex
);
1797 int cs46xx_dsp_disable_adc_capture (cs46xx_t
*chip
)
1799 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1801 snd_assert (ins
->adc_input
!= NULL
,return -EINVAL
);
1803 down(&chip
->spos_mutex
);
1804 cs46xx_dsp_remove_scb (chip
,ins
->adc_input
);
1805 ins
->adc_input
= NULL
;
1806 up(&chip
->spos_mutex
);
1811 int cs46xx_poke_via_dsp (cs46xx_t
*chip
,u32 address
,u32 data
)
1816 /* santiy check the parameters. (These numbers are not 100% correct. They are
1817 a rough guess from looking at the controller spec.) */
1818 if (address
< 0x8000 || address
>= 0x9000)
1821 /* initialize the SP_IO_WRITE SCB with the data. */
1822 temp
= ( address
<< 16 ) | ( address
& 0x0000FFFF); /* offset 0 <-- address2 : address1 */
1824 snd_cs46xx_poke(chip
,( SPIOWRITE_SCB_ADDR
<< 2), temp
);
1825 snd_cs46xx_poke(chip
,((SPIOWRITE_SCB_ADDR
+ 1) << 2), data
); /* offset 1 <-- data1 */
1826 snd_cs46xx_poke(chip
,((SPIOWRITE_SCB_ADDR
+ 2) << 2), data
); /* offset 1 <-- data2 */
1828 /* Poke this location to tell the task to start */
1829 snd_cs46xx_poke(chip
,((SPIOWRITE_SCB_ADDR
+ 6) << 2), SPIOWRITE_SCB_ADDR
<< 0x10);
1831 /* Verify that the task ran */
1832 for (i
=0; i
<25; i
++) {
1835 temp
= snd_cs46xx_peek(chip
,((SPIOWRITE_SCB_ADDR
+ 6) << 2));
1836 if (temp
== 0x00000000)
1841 snd_printk(KERN_ERR
"dsp_spos: SPIOWriteTask not responding\n");
1848 int cs46xx_dsp_set_dac_volume (cs46xx_t
* chip
,u16 left
,u16 right
)
1850 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1851 dsp_scb_descriptor_t
* scb
;
1853 down(&chip
->spos_mutex
);
1856 scb
= ins
->master_mix_scb
->sub_list_ptr
;
1857 while (scb
!= ins
->the_null_scb
) {
1858 cs46xx_dsp_scb_set_volume (chip
,scb
,left
,right
);
1859 scb
= scb
->next_scb_ptr
;
1863 scb
= ins
->rear_mix_scb
->sub_list_ptr
;
1864 while (scb
!= ins
->the_null_scb
) {
1865 cs46xx_dsp_scb_set_volume (chip
,scb
,left
,right
);
1866 scb
= scb
->next_scb_ptr
;
1869 ins
->dac_volume_left
= left
;
1870 ins
->dac_volume_right
= right
;
1872 up(&chip
->spos_mutex
);
1877 int cs46xx_dsp_set_iec958_volume (cs46xx_t
* chip
,u16 left
,u16 right
) {
1878 dsp_spos_instance_t
* ins
= chip
->dsp_spos_instance
;
1880 down(&chip
->spos_mutex
);
1882 if (ins
->asynch_rx_scb
!= NULL
)
1883 cs46xx_dsp_scb_set_volume (chip
,ins
->asynch_rx_scb
,
1886 ins
->spdif_input_volume_left
= left
;
1887 ins
->spdif_input_volume_right
= right
;
1889 up(&chip
->spos_mutex
);