dsp_spos.c 55.5 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 *   This program is free software; you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation; either version 2 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program; if not, write to the Free Software
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 *
 */

/*
 * 2002-07 Benny Sjostrand benny@hostmobility.com
 */


23
#include <linux/io.h>
L
Linus Torvalds 已提交
24 25 26 27 28
#include <linux/delay.h>
#include <linux/pm.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/vmalloc.h>
29 30
#include <linux/mutex.h>

L
Linus Torvalds 已提交
31 32 33 34
#include <sound/core.h>
#include <sound/control.h>
#include <sound/info.h>
#include <sound/asoundef.h>
35
#include "cs46xx.h"
L
Linus Torvalds 已提交
36 37 38 39

#include "cs46xx_lib.h"
#include "dsp_spos.h"

40 41
static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
				  struct dsp_scb_descriptor * fg_entry);
L
Linus Torvalds 已提交
42

43
static enum wide_opcode wide_opcodes[] = { 
L
Linus Torvalds 已提交
44 45 46 47 48 49 50 51 52 53 54 55 56 57
	WIDE_FOR_BEGIN_LOOP,
	WIDE_FOR_BEGIN_LOOP2,
	WIDE_COND_GOTO_ADDR,
	WIDE_COND_GOTO_CALL,
	WIDE_TBEQ_COND_GOTO_ADDR,
	WIDE_TBEQ_COND_CALL_ADDR,
	WIDE_TBEQ_NCOND_GOTO_ADDR,
	WIDE_TBEQ_NCOND_CALL_ADDR,
	WIDE_TBEQ_COND_GOTO1_ADDR,
	WIDE_TBEQ_COND_CALL1_ADDR,
	WIDE_TBEQ_NCOND_GOTOI_ADDR,
	WIDE_TBEQ_NCOND_CALL1_ADDR
};

58 59
static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32 size,
				       u32 overlay_begin_address)
L
Linus Torvalds 已提交
60 61 62 63
{
	unsigned int i = 0, j, nreallocated = 0;
	u32 hival,loval,address;
	u32 mop_operands,mop_type,wide_op;
64
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
65

66 67
	if (snd_BUG_ON(size %2))
		return -EINVAL;
L
Linus Torvalds 已提交
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
  
	while (i < size) {
		loval = data[i++];
		hival = data[i++];

		if (ins->code.offset > 0) {
			mop_operands = (hival >> 6) & 0x03fff;
			mop_type = mop_operands >> 10;
      
			/* check for wide type instruction */
			if (mop_type == 0 &&
			    (mop_operands & WIDE_LADD_INSTR_MASK) == 0 &&
			    (mop_operands & WIDE_INSTR_MASK) != 0) {
				wide_op = loval & 0x7f;
				for (j = 0;j < ARRAY_SIZE(wide_opcodes); ++j) {
					if (wide_opcodes[j] == wide_op) {
						/* need to reallocate instruction */
						address  = (hival & 0x00FFF) << 5;
						address |=  loval >> 15;
            
88 89 90
						dev_dbg(chip->card->dev,
							"handle_wideop[1]: %05x:%05x addr %04x\n",
							hival, loval, address);
L
Linus Torvalds 已提交
91 92 93 94
            
						if ( !(address & 0x8000) ) {
							address += (ins->code.offset / 2) - overlay_begin_address;
						} else {
95 96
							dev_dbg(chip->card->dev,
								"handle_wideop[1]: ROM symbol not reallocated\n");
L
Linus Torvalds 已提交
97 98 99 100 101 102 103 104 105 106 107
						}
            
						hival &= 0xFF000;
						loval &= 0x07FFF;
            
						hival |= ( (address >> 5)  & 0x00FFF);
						loval |= ( (address << 15) & 0xF8000);
            
						address  = (hival & 0x00FFF) << 5;
						address |=  loval >> 15;
            
108 109
						dev_dbg(chip->card->dev,
							"handle_wideop:[2] %05x:%05x addr %04x\n",
D
Dan Carpenter 已提交
110 111
							hival, loval, address);
						nreallocated++;
L
Linus Torvalds 已提交
112 113 114 115 116 117 118 119 120
					} /* wide_opcodes[j] == wide_op */
				} /* for */
			} /* mod_type == 0 ... */
		} /* ins->code.offset > 0 */

		ins->code.data[ins->code.size++] = loval;
		ins->code.data[ins->code.size++] = hival;
	}

121 122
	dev_dbg(chip->card->dev,
		"dsp_spos: %d instructions reallocated\n", nreallocated);
L
Linus Torvalds 已提交
123 124 125
	return nreallocated;
}

126
static struct dsp_segment_desc * get_segment_desc (struct dsp_module_desc * module, int seg_type)
L
Linus Torvalds 已提交
127 128 129 130 131 132 133 134 135 136 137
{
	int i;
	for (i = 0;i < module->nsegments; ++i) {
		if (module->segments[i].segment_type == seg_type) {
			return (module->segments + i);
		}
	}

	return NULL;
};

138
static int find_free_symbol_index (struct dsp_spos_instance * ins)
L
Linus Torvalds 已提交
139 140 141 142 143 144 145 146 147 148 149 150 151
{
	int index = ins->symbol_table.nsymbols,i;

	for (i = ins->symbol_table.highest_frag_index; i < ins->symbol_table.nsymbols; ++i) {
		if (ins->symbol_table.symbols[i].deleted) {
			index = i;
			break;
		}
	}

	return index;
}

152
static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * module)
L
Linus Torvalds 已提交
153 154
{
	int i;
155
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
156 157 158 159 160 161 162 163 164 165

	if (module->symbol_table.nsymbols > 0) {
		if (!strcmp(module->symbol_table.symbols[0].symbol_name, "OVERLAYBEGINADDRESS") &&
		    module->symbol_table.symbols[0].symbol_type == SYMBOL_CONSTANT ) {
			module->overlay_begin_address = module->symbol_table.symbols[0].address;
		}
	}

	for (i = 0;i < module->symbol_table.nsymbols; ++i) {
		if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
166 167
			dev_err(chip->card->dev,
				"dsp_spos: symbol table is full\n");
L
Linus Torvalds 已提交
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
			return -ENOMEM;
		}


		if (cs46xx_dsp_lookup_symbol(chip,
					     module->symbol_table.symbols[i].symbol_name,
					     module->symbol_table.symbols[i].symbol_type) == NULL) {

			ins->symbol_table.symbols[ins->symbol_table.nsymbols] = module->symbol_table.symbols[i];
			ins->symbol_table.symbols[ins->symbol_table.nsymbols].address += ((ins->code.offset / 2) - module->overlay_begin_address);
			ins->symbol_table.symbols[ins->symbol_table.nsymbols].module = module;
			ins->symbol_table.symbols[ins->symbol_table.nsymbols].deleted = 0;

			if (ins->symbol_table.nsymbols > ins->symbol_table.highest_frag_index) 
				ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols;

			ins->symbol_table.nsymbols++;
		} else {
186 187 188 189 190
#if 0
			dev_dbg(chip->card->dev,
				"dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n",
				module->symbol_table.symbols[i].symbol_name); */
#endif
L
Linus Torvalds 已提交
191 192 193 194 195 196
		}
	}

	return 0;
}

197 198
static struct dsp_symbol_entry *
add_symbol (struct snd_cs46xx * chip, char * symbol_name, u32 address, int type)
L
Linus Torvalds 已提交
199
{
200 201
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_symbol_entry * symbol = NULL;
L
Linus Torvalds 已提交
202 203 204
	int index;

	if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
205
		dev_err(chip->card->dev, "dsp_spos: symbol table is full\n");
L
Linus Torvalds 已提交
206 207 208 209 210 211
		return NULL;
	}
  
	if (cs46xx_dsp_lookup_symbol(chip,
				     symbol_name,
				     type) != NULL) {
212 213
		dev_err(chip->card->dev,
			"dsp_spos: symbol <%s> duplicated\n", symbol_name);
L
Linus Torvalds 已提交
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234
		return NULL;
	}

	index = find_free_symbol_index (ins);

	strcpy (ins->symbol_table.symbols[index].symbol_name, symbol_name);
	ins->symbol_table.symbols[index].address = address;
	ins->symbol_table.symbols[index].symbol_type = type;
	ins->symbol_table.symbols[index].module = NULL;
	ins->symbol_table.symbols[index].deleted = 0;
	symbol = (ins->symbol_table.symbols + index);

	if (index > ins->symbol_table.highest_frag_index) 
		ins->symbol_table.highest_frag_index = index;

	if (index == ins->symbol_table.nsymbols)
		ins->symbol_table.nsymbols++; /* no frag. in list */

	return symbol;
}

235
struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
L
Linus Torvalds 已提交
236
{
237
	struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL);
L
Linus Torvalds 已提交
238

239
	if (ins == NULL)
L
Linus Torvalds 已提交
240 241 242
		return NULL;

	/* better to use vmalloc for this big table */
243 244
	ins->symbol_table.symbols = vmalloc(sizeof(struct dsp_symbol_entry) *
					    DSP_MAX_SYMBOLS);
245 246 247
	ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
	ins->modules = kmalloc(sizeof(struct dsp_module_desc) * DSP_MAX_MODULES, GFP_KERNEL);
	if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
L
Linus Torvalds 已提交
248
		cs46xx_dsp_spos_destroy(chip);
A
Adrian Bunk 已提交
249
		goto error;
L
Linus Torvalds 已提交
250
	}
251 252
	ins->symbol_table.nsymbols = 0;
	ins->symbol_table.highest_frag_index = 0;
L
Linus Torvalds 已提交
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
	ins->code.offset = 0;
	ins->code.size = 0;
	ins->nscb = 0;
	ins->ntask = 0;
	ins->nmodules = 0;

	/* default SPDIF input sample rate
	   to 48000 khz */
	ins->spdif_in_sample_rate = 48000;

	/* maximize volume */
	ins->dac_volume_right = 0x8000;
	ins->dac_volume_left = 0x8000;
	ins->spdif_input_volume_right = 0x8000;
	ins->spdif_input_volume_left = 0x8000;

	/* set left and right validity bits and
	   default channel status */
271 272
	ins->spdif_csuv_default =
		ins->spdif_csuv_stream =
L
Linus Torvalds 已提交
273 274 275 276 277 278
	 /* byte 0 */  ((unsigned int)_wrap_all_bits(  (SNDRV_PCM_DEFAULT_CON_SPDIF        & 0xff)) << 24) |
	 /* byte 1 */  ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) |
	 /* byte 3 */   (unsigned int)_wrap_all_bits(  (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
	 /* left and right validity bits */ (1 << 13) | (1 << 12);

	return ins;
A
Adrian Bunk 已提交
279 280

error:
281 282 283
	kfree(ins->modules);
	kfree(ins->code.data);
	vfree(ins->symbol_table.symbols);
A
Adrian Bunk 已提交
284 285
	kfree(ins);
	return NULL;
L
Linus Torvalds 已提交
286 287
}

288
void  cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
L
Linus Torvalds 已提交
289 290
{
	int i;
291
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
292

293 294
	if (snd_BUG_ON(!ins))
		return;
L
Linus Torvalds 已提交
295

296
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
297 298 299 300
	for (i = 0; i < ins->nscb; ++i) {
		if (ins->scbs[i].deleted) continue;

		cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
301
#ifdef CONFIG_PM_SLEEP
302 303
		kfree(ins->scbs[i].data);
#endif
L
Linus Torvalds 已提交
304 305 306 307 308 309
	}

	kfree(ins->code.data);
	vfree(ins->symbol_table.symbols);
	kfree(ins->modules);
	kfree(ins);
310
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
311 312
}

T
Takashi Iwai 已提交
313 314 315 316 317 318
static int dsp_load_parameter(struct snd_cs46xx *chip,
			      struct dsp_segment_desc *parameter)
{
	u32 doffset, dsize;

	if (!parameter) {
319 320
		dev_dbg(chip->card->dev,
			"dsp_spos: module got no parameter segment\n");
T
Takashi Iwai 已提交
321 322 323 324 325 326
		return 0;
	}

	doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET);
	dsize   = parameter->size * 4;

327 328
	dev_dbg(chip->card->dev,
		"dsp_spos: downloading parameter data to chip (%08x-%08x)\n",
T
Takashi Iwai 已提交
329 330
		    doffset,doffset + dsize);
	if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) {
331 332
		dev_err(chip->card->dev,
			"dsp_spos: failed to download parameter data to DSP\n");
T
Takashi Iwai 已提交
333 334 335 336 337 338 339 340 341 342 343
		return -EINVAL;
	}
	return 0;
}

static int dsp_load_sample(struct snd_cs46xx *chip,
			   struct dsp_segment_desc *sample)
{
	u32 doffset, dsize;

	if (!sample) {
344 345
		dev_dbg(chip->card->dev,
			"dsp_spos: module got no sample segment\n");
T
Takashi Iwai 已提交
346 347 348 349 350 351
		return 0;
	}

	doffset = (sample->offset * 4  + DSP_SAMPLE_BYTE_OFFSET);
	dsize   =  sample->size * 4;

352 353
	dev_dbg(chip->card->dev,
		"dsp_spos: downloading sample data to chip (%08x-%08x)\n",
T
Takashi Iwai 已提交
354 355 356
		    doffset,doffset + dsize);

	if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) {
357 358
		dev_err(chip->card->dev,
			"dsp_spos: failed to sample data to DSP\n");
T
Takashi Iwai 已提交
359 360 361 362 363
		return -EINVAL;
	}
	return 0;
}

364
int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module)
L
Linus Torvalds 已提交
365
{
366 367
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_segment_desc * code = get_segment_desc (module,SEGTYPE_SP_PROGRAM);
L
Linus Torvalds 已提交
368
	u32 doffset, dsize;
T
Takashi Iwai 已提交
369
	int err;
L
Linus Torvalds 已提交
370 371

	if (ins->nmodules == DSP_MAX_MODULES - 1) {
372 373
		dev_err(chip->card->dev,
			"dsp_spos: to many modules loaded into DSP\n");
L
Linus Torvalds 已提交
374 375 376
		return -ENOMEM;
	}

377 378
	dev_dbg(chip->card->dev,
		"dsp_spos: loading module %s into DSP\n", module->module_name);
L
Linus Torvalds 已提交
379 380
  
	if (ins->nmodules == 0) {
381
		dev_dbg(chip->card->dev, "dsp_spos: clearing parameter area\n");
L
Linus Torvalds 已提交
382 383 384
		snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE);
	}
  
T
Takashi Iwai 已提交
385 386 387 388
	err = dsp_load_parameter(chip, get_segment_desc(module,
							SEGTYPE_SP_PARAMETER));
	if (err < 0)
		return err;
L
Linus Torvalds 已提交
389 390

	if (ins->nmodules == 0) {
391
		dev_dbg(chip->card->dev, "dsp_spos: clearing sample area\n");
L
Linus Torvalds 已提交
392 393 394
		snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE);
	}

T
Takashi Iwai 已提交
395 396 397 398
	err = dsp_load_sample(chip, get_segment_desc(module,
						     SEGTYPE_SP_SAMPLE));
	if (err < 0)
		return err;
L
Linus Torvalds 已提交
399 400

	if (ins->nmodules == 0) {
401
		dev_dbg(chip->card->dev, "dsp_spos: clearing code area\n");
L
Linus Torvalds 已提交
402 403 404 405
		snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
	}

	if (code == NULL) {
406 407
		dev_dbg(chip->card->dev,
			"dsp_spos: module got no code segment\n");
L
Linus Torvalds 已提交
408 409
	} else {
		if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) {
410 411
			dev_err(chip->card->dev,
				"dsp_spos: no space available in DSP\n");
L
Linus Torvalds 已提交
412 413 414 415 416 417 418 419
			return -ENOMEM;
		}

		module->load_address = ins->code.offset;
		module->overlay_begin_address = 0x000;

		/* if module has a code segment it must have
		   symbol table */
420 421
		if (snd_BUG_ON(!module->symbol_table.symbols))
			return -ENOMEM;
L
Linus Torvalds 已提交
422
		if (add_symbols(chip,module)) {
423 424
			dev_err(chip->card->dev,
				"dsp_spos: failed to load symbol table\n");
L
Linus Torvalds 已提交
425 426 427 428 429
			return -ENOMEM;
		}
    
		doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET);
		dsize   = code->size * 4;
430 431
		dev_dbg(chip->card->dev,
			"dsp_spos: downloading code to chip (%08x-%08x)\n",
L
Linus Torvalds 已提交
432 433 434 435 436
			    doffset,doffset + dsize);   

		module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address);

		if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) {
437 438
			dev_err(chip->card->dev,
				"dsp_spos: failed to download code to DSP\n");
L
Linus Torvalds 已提交
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453
			return -EINVAL;
		}

		ins->code.offset += code->size;
	}

	/* NOTE: module segments and symbol table must be
	   statically allocated. Case that module data is
	   not generated by the ospparser */
	ins->modules[ins->nmodules] = *module;
	ins->nmodules++;

	return 0;
}

454 455
struct dsp_symbol_entry *
cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, int symbol_type)
L
Linus Torvalds 已提交
456 457
{
	int i;
458
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
459 460 461 462 463 464 465 466 467 468 469 470 471

	for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {

		if (ins->symbol_table.symbols[i].deleted)
			continue;

		if (!strcmp(ins->symbol_table.symbols[i].symbol_name,symbol_name) &&
		    ins->symbol_table.symbols[i].symbol_type == symbol_type) {
			return (ins->symbol_table.symbols + i);
		}
	}

#if 0
472
	dev_err(chip->card->dev, "dsp_spos: symbol <%s> type %02x not found\n",
L
Linus Torvalds 已提交
473 474 475 476 477 478 479
		symbol_name,symbol_type);
#endif

	return NULL;
}


480
#ifdef CONFIG_SND_PROC_FS
481 482
static struct dsp_symbol_entry *
cs46xx_dsp_lookup_symbol_addr (struct snd_cs46xx * chip, u32 address, int symbol_type)
L
Linus Torvalds 已提交
483 484
{
	int i;
485
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502

	for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {

		if (ins->symbol_table.symbols[i].deleted)
			continue;

		if (ins->symbol_table.symbols[i].address == address &&
		    ins->symbol_table.symbols[i].symbol_type == symbol_type) {
			return (ins->symbol_table.symbols + i);
		}
	}


	return NULL;
}


503 504
static void cs46xx_dsp_proc_symbol_table_read (struct snd_info_entry *entry,
					       struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
505
{
506 507
	struct snd_cs46xx *chip = entry->private_data;
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
	int i;

	snd_iprintf(buffer, "SYMBOLS:\n");
	for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
		char *module_str = "system";

		if (ins->symbol_table.symbols[i].deleted)
			continue;

		if (ins->symbol_table.symbols[i].module != NULL) {
			module_str = ins->symbol_table.symbols[i].module->module_name;
		}

    
		snd_iprintf(buffer, "%04X <%02X> %s [%s]\n",
			    ins->symbol_table.symbols[i].address,
			    ins->symbol_table.symbols[i].symbol_type,
			    ins->symbol_table.symbols[i].symbol_name,
			    module_str);    
	}
}


531 532
static void cs46xx_dsp_proc_modules_read (struct snd_info_entry *entry,
					  struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
533
{
534 535
	struct snd_cs46xx *chip = entry->private_data;
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
536 537
	int i,j;

538
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
539 540 541 542 543 544 545
	snd_iprintf(buffer, "MODULES:\n");
	for ( i = 0; i < ins->nmodules; ++i ) {
		snd_iprintf(buffer, "\n%s:\n", ins->modules[i].module_name);
		snd_iprintf(buffer, "   %d symbols\n", ins->modules[i].symbol_table.nsymbols);
		snd_iprintf(buffer, "   %d fixups\n", ins->modules[i].nfixups);

		for (j = 0; j < ins->modules[i].nsegments; ++ j) {
546
			struct dsp_segment_desc * desc = (ins->modules[i].segments + j);
L
Linus Torvalds 已提交
547 548 549 550
			snd_iprintf(buffer, "   segment %02x offset %08x size %08x\n",
				    desc->segment_type,desc->offset, desc->size);
		}
	}
551
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
552 553
}

554 555
static void cs46xx_dsp_proc_task_tree_read (struct snd_info_entry *entry,
					    struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
556
{
557 558 559
	struct snd_cs46xx *chip = entry->private_data;
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	int i, j, col;
L
Linus Torvalds 已提交
560 561
	void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;

562
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578
	snd_iprintf(buffer, "TASK TREES:\n");
	for ( i = 0; i < ins->ntask; ++i) {
		snd_iprintf(buffer,"\n%04x %s:\n",ins->tasks[i].address,ins->tasks[i].task_name);

		for (col = 0,j = 0;j < ins->tasks[i].size; j++,col++) {
			u32 val;
			if (col == 4) {
				snd_iprintf(buffer,"\n");
				col = 0;
			}
			val = readl(dst + (ins->tasks[i].address + j) * sizeof(u32));
			snd_iprintf(buffer,"%08x ",val);
		}
	}

	snd_iprintf(buffer,"\n");  
579
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
580 581
}

582 583
static void cs46xx_dsp_proc_scb_read (struct snd_info_entry *entry,
				      struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
584
{
585 586
	struct snd_cs46xx *chip = entry->private_data;
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
587 588
	int i;

589
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611
	snd_iprintf(buffer, "SCB's:\n");
	for ( i = 0; i < ins->nscb; ++i) {
		if (ins->scbs[i].deleted)
			continue;
		snd_iprintf(buffer,"\n%04x %s:\n\n",ins->scbs[i].address,ins->scbs[i].scb_name);

		if (ins->scbs[i].parent_scb_ptr != NULL) {
			snd_iprintf(buffer,"parent [%s:%04x] ", 
				    ins->scbs[i].parent_scb_ptr->scb_name,
				    ins->scbs[i].parent_scb_ptr->address);
		} else snd_iprintf(buffer,"parent [none] ");

		snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x]  task_entry [%s:%04x]\n",
			    ins->scbs[i].sub_list_ptr->scb_name,
			    ins->scbs[i].sub_list_ptr->address,
			    ins->scbs[i].next_scb_ptr->scb_name,
			    ins->scbs[i].next_scb_ptr->address,
			    ins->scbs[i].task_entry->symbol_name,
			    ins->scbs[i].task_entry->address);
	}

	snd_iprintf(buffer,"\n");
612
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
613 614
}

615 616
static void cs46xx_dsp_proc_parameter_dump_read (struct snd_info_entry *entry,
						 struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
617
{
618 619 620
	struct snd_cs46xx *chip = entry->private_data;
	/*struct dsp_spos_instance * ins = chip->dsp_spos_instance; */
	unsigned int i, col = 0;
L
Linus Torvalds 已提交
621
	void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
622
	struct dsp_symbol_entry * symbol; 
L
Linus Torvalds 已提交
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642

	for (i = 0;i < DSP_PARAMETER_BYTE_SIZE; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if ( (symbol = cs46xx_dsp_lookup_symbol_addr (chip,i / sizeof(u32), SYMBOL_PARAMETER)) != NULL) {
			col = 0;
			snd_iprintf (buffer,"\n%s:\n",symbol->symbol_name);
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ", i / (unsigned int)sizeof(u32));
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}
}

643 644
static void cs46xx_dsp_proc_sample_dump_read (struct snd_info_entry *entry,
					      struct snd_info_buffer *buffer)
L
Linus Torvalds 已提交
645
{
646
	struct snd_cs46xx *chip = entry->private_data;
L
Linus Torvalds 已提交
647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790
	int i,col = 0;
	void __iomem *dst = chip->region.idx[2].remap_addr;

	snd_iprintf(buffer,"PCMREADER:\n");
	for (i = PCM_READER_BUF1;i < PCM_READER_BUF1 + 0x30; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}

	snd_iprintf(buffer,"\nMIX_SAMPLE_BUF1:\n");

	col = 0;
	for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x40; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}

	snd_iprintf(buffer,"\nSRC_TASK_SCB1:\n");
	col = 0;
	for (i = 0x2480 ; i < 0x2480 + 0x40 ; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}
		
		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}


	snd_iprintf(buffer,"\nSPDIFO_BUFFER:\n");
	col = 0;
	for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x30; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}

	snd_iprintf(buffer,"\n...\n");
	col = 0;

	for (i = SPDIFO_IP_OUTPUT_BUFFER1+0xD0;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x110; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}


	snd_iprintf(buffer,"\nOUTPUT_SNOOP:\n");
	col = 0;
	for (i = OUTPUT_SNOOP_BUFFER;i < OUTPUT_SNOOP_BUFFER + 0x40; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}

	snd_iprintf(buffer,"\nCODEC_INPUT_BUF1: \n");
	col = 0;
	for (i = CODEC_INPUT_BUF1;i < CODEC_INPUT_BUF1 + 0x40; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}
#if 0
	snd_iprintf(buffer,"\nWRITE_BACK_BUF1: \n");
	col = 0;
	for (i = WRITE_BACK_BUF1;i < WRITE_BACK_BUF1 + 0x40; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}

		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}
#endif

	snd_iprintf(buffer,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n");
	col = 0;
	for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x80; i += sizeof(u32),col ++) {
		if (col == 4) {
			snd_iprintf(buffer,"\n");
			col = 0;
		}

		if (col == 0) {
			snd_iprintf(buffer, "%04X ",i);
		}
		
		snd_iprintf(buffer,"%08X ",readl(dst + i));
	}
	snd_iprintf(buffer,"\n");
}

791
int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
792
{
793 794
	struct snd_info_entry *entry;
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
795 796 797 798 799 800
	int i;

	ins->snd_card = card;

	if ((entry = snd_info_create_card_entry(card, "dsp", card->proc_root)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
801
		entry->mode = S_IFDIR | 0555;
L
Linus Torvalds 已提交
802 803 804 805 806 807 808 809 810 811 812 813 814 815 816
      
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}

	ins->proc_dsp_dir = entry;

	if (!ins->proc_dsp_dir)
		return -ENOMEM;

	if ((entry = snd_info_create_card_entry(card, "spos_symbols", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
817
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
818 819 820 821 822 823 824 825 826 827 828
		entry->c.text.read = cs46xx_dsp_proc_symbol_table_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_sym_info_entry = entry;
    
	if ((entry = snd_info_create_card_entry(card, "spos_modules", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
829
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
830 831 832 833 834 835 836 837 838 839 840
		entry->c.text.read = cs46xx_dsp_proc_modules_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_modules_info_entry = entry;

	if ((entry = snd_info_create_card_entry(card, "parameter", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
841
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
842 843 844 845 846 847 848 849 850 851 852
		entry->c.text.read = cs46xx_dsp_proc_parameter_dump_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_parameter_dump_info_entry = entry;

	if ((entry = snd_info_create_card_entry(card, "sample", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
853
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
854 855 856 857 858 859 860 861 862 863 864
		entry->c.text.read = cs46xx_dsp_proc_sample_dump_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_sample_dump_info_entry = entry;

	if ((entry = snd_info_create_card_entry(card, "task_tree", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
865
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
866 867 868 869 870 871 872 873 874 875 876
		entry->c.text.read = cs46xx_dsp_proc_task_tree_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_task_info_entry = entry;

	if ((entry = snd_info_create_card_entry(card, "scb_info", ins->proc_dsp_dir)) != NULL) {
		entry->content = SNDRV_INFO_CONTENT_TEXT;
		entry->private_data = chip;
877
		entry->mode = S_IFREG | 0644;
L
Linus Torvalds 已提交
878 879 880 881 882 883 884 885
		entry->c.text.read = cs46xx_dsp_proc_scb_read;
		if (snd_info_register(entry) < 0) {
			snd_info_free_entry(entry);
			entry = NULL;
		}
	}
	ins->proc_scb_info_entry = entry;

886
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
887 888 889 890 891 892
	/* register/update SCB's entries on proc */
	for (i = 0; i < ins->nscb; ++i) {
		if (ins->scbs[i].deleted) continue;

		cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i));
	}
893
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
894 895 896 897

	return 0;
}

898
int cs46xx_dsp_proc_done (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
899
{
900
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
901 902
	int i;

903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919
	snd_info_free_entry(ins->proc_sym_info_entry);
	ins->proc_sym_info_entry = NULL;

	snd_info_free_entry(ins->proc_modules_info_entry);
	ins->proc_modules_info_entry = NULL;

	snd_info_free_entry(ins->proc_parameter_dump_info_entry);
	ins->proc_parameter_dump_info_entry = NULL;

	snd_info_free_entry(ins->proc_sample_dump_info_entry);
	ins->proc_sample_dump_info_entry = NULL;

	snd_info_free_entry(ins->proc_scb_info_entry);
	ins->proc_scb_info_entry = NULL;

	snd_info_free_entry(ins->proc_task_info_entry);
	ins->proc_task_info_entry = NULL;
L
Linus Torvalds 已提交
920

921
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
922 923 924 925
	for (i = 0; i < ins->nscb; ++i) {
		if (ins->scbs[i].deleted) continue;
		cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
	}
926
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
927

928 929
	snd_info_free_entry(ins->proc_dsp_dir);
	ins->proc_dsp_dir = NULL;
L
Linus Torvalds 已提交
930 931 932

	return 0;
}
933
#endif /* CONFIG_SND_PROC_FS */
L
Linus Torvalds 已提交
934

935 936
static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
				   u32  dest, int size)
L
Linus Torvalds 已提交
937 938 939 940 941 942
{
	void __iomem *spdst = chip->region.idx[1].remap_addr + 
		DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
	int i;

	for (i = 0; i < size; ++i) {
943 944
		dev_dbg(chip->card->dev, "addr %p, val %08x\n",
			spdst, task_data[i]);
L
Linus Torvalds 已提交
945 946 947 948 949
		writel(task_data[i],spdst);
		spdst += sizeof(u32);
	}
}

950
static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
L
Linus Torvalds 已提交
951 952 953 954 955 956
{
	void __iomem *spdst = chip->region.idx[1].remap_addr + 
		DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
	int i;

	for (i = 0; i < 0x10; ++i) {
957 958
		dev_dbg(chip->card->dev, "addr %p, val %08x\n",
			spdst, scb_data[i]);
L
Linus Torvalds 已提交
959 960 961 962 963
		writel(scb_data[i],spdst);
		spdst += sizeof(u32);
	}
}

964
static int find_free_scb_index (struct dsp_spos_instance * ins)
L
Linus Torvalds 已提交
965 966 967 968 969 970 971 972 973 974 975 976 977
{
	int index = ins->nscb, i;

	for (i = ins->scb_highest_frag_index; i < ins->nscb; ++i) {
		if (ins->scbs[i].deleted) {
			index = i;
			break;
		}
	}

	return index;
}

978
static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * name, u32 dest)
L
Linus Torvalds 已提交
979
{
980 981
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_scb_descriptor * desc = NULL;
L
Linus Torvalds 已提交
982 983 984
	int index;

	if (ins->nscb == DSP_MAX_SCB_DESC - 1) {
985 986
		dev_err(chip->card->dev,
			"dsp_spos: got no place for other SCB\n");
L
Linus Torvalds 已提交
987 988 989 990 991
		return NULL;
	}

	index = find_free_scb_index (ins);

992
	memset(&ins->scbs[index], 0, sizeof(ins->scbs[index]));
L
Linus Torvalds 已提交
993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009
	strcpy(ins->scbs[index].scb_name, name);
	ins->scbs[index].address = dest;
	ins->scbs[index].index = index;
	ins->scbs[index].ref_count = 1;

	desc = (ins->scbs + index);
	ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);

	if (index > ins->scb_highest_frag_index)
		ins->scb_highest_frag_index = index;

	if (index == ins->nscb)
		ins->nscb++;

	return desc;
}

1010 1011
static struct dsp_task_descriptor *
_map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
L
Linus Torvalds 已提交
1012
{
1013 1014
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_task_descriptor * desc = NULL;
L
Linus Torvalds 已提交
1015 1016

	if (ins->ntask == DSP_MAX_TASK_DESC - 1) {
1017 1018
		dev_err(chip->card->dev,
			"dsp_spos: got no place for other TASK\n");
L
Linus Torvalds 已提交
1019 1020 1021
		return NULL;
	}

T
Takashi Iwai 已提交
1022 1023 1024 1025
	if (name)
		strcpy(ins->tasks[ins->ntask].task_name, name);
	else
		strcpy(ins->tasks[ins->ntask].task_name, "(NULL)");
L
Linus Torvalds 已提交
1026 1027 1028 1029 1030 1031 1032 1033
	ins->tasks[ins->ntask].address = dest;
	ins->tasks[ins->ntask].size = size;

	/* quick find in list */
	ins->tasks[ins->ntask].index = ins->ntask;
	desc = (ins->tasks + ins->ntask);
	ins->ntask++;

T
Takashi Iwai 已提交
1034 1035
	if (name)
		add_symbol (chip,name,dest,SYMBOL_PARAMETER);
L
Linus Torvalds 已提交
1036 1037 1038
	return desc;
}

1039 1040
#define SCB_BYTES	(0x10 * 4)

1041 1042
struct dsp_scb_descriptor *
cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
L
Linus Torvalds 已提交
1043
{
1044
	struct dsp_scb_descriptor * desc;
L
Linus Torvalds 已提交
1045

1046
#ifdef CONFIG_PM_SLEEP
1047 1048 1049 1050 1051 1052
	/* copy the data for resume */
	scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL);
	if (!scb_data)
		return NULL;
#endif

L
Linus Torvalds 已提交
1053 1054
	desc = _map_scb (chip,name,dest);
	if (desc) {
T
Takashi Iwai 已提交
1055
		desc->data = scb_data;
L
Linus Torvalds 已提交
1056 1057
		_dsp_create_scb(chip,scb_data,dest);
	} else {
1058
		dev_err(chip->card->dev, "dsp_spos: failed to map SCB\n");
1059
#ifdef CONFIG_PM_SLEEP
1060 1061
		kfree(scb_data);
#endif
L
Linus Torvalds 已提交
1062 1063 1064 1065 1066 1067
	}

	return desc;
}


1068 1069 1070
static struct dsp_task_descriptor *
cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_data,
			     u32 dest, int size)
L
Linus Torvalds 已提交
1071
{
1072
	struct dsp_task_descriptor * desc;
L
Linus Torvalds 已提交
1073 1074 1075

	desc = _map_task_tree (chip,name,dest,size);
	if (desc) {
T
Takashi Iwai 已提交
1076
		desc->data = task_data;
L
Linus Torvalds 已提交
1077 1078
		_dsp_create_task_tree(chip,task_data,dest,size);
	} else {
1079
		dev_err(chip->card->dev, "dsp_spos: failed to map TASK\n");
L
Linus Torvalds 已提交
1080 1081 1082 1083 1084
	}

	return desc;
}

1085
int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1086
{
1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_symbol_entry * fg_task_tree_header_code;
	struct dsp_symbol_entry * task_tree_header_code;
	struct dsp_symbol_entry * task_tree_thread;
	struct dsp_symbol_entry * null_algorithm;
	struct dsp_symbol_entry * magic_snoop_task;

	struct dsp_scb_descriptor * timing_master_scb;
	struct dsp_scb_descriptor * codec_out_scb;
	struct dsp_scb_descriptor * codec_in_scb;
	struct dsp_scb_descriptor * src_task_scb;
	struct dsp_scb_descriptor * master_mix_scb;
	struct dsp_scb_descriptor * rear_mix_scb;
	struct dsp_scb_descriptor * record_mix_scb;
	struct dsp_scb_descriptor * write_back_scb;
	struct dsp_scb_descriptor * vari_decimate_scb;
	struct dsp_scb_descriptor * rear_codec_out_scb;
	struct dsp_scb_descriptor * clfe_codec_out_scb;
	struct dsp_scb_descriptor * magic_snoop_scb;
L
Linus Torvalds 已提交
1106
	
1107
	int fifo_addr, fifo_span, valid_slots;
L
Linus Torvalds 已提交
1108

1109
	static struct dsp_spos_control_block sposcb = {
L
Linus Torvalds 已提交
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131
		/* 0 */ HFG_TREE_SCB,HFG_STACK,
		/* 1 */ SPOSCB_ADDR,BG_TREE_SCB_ADDR,
		/* 2 */ DSP_SPOS_DC,0,
		/* 3 */ DSP_SPOS_DC,DSP_SPOS_DC,
		/* 4 */ 0,0,
		/* 5 */ DSP_SPOS_UU,0,
		/* 6 */ FG_TASK_HEADER_ADDR,0,
		/* 7 */ 0,0,
		/* 8 */ DSP_SPOS_UU,DSP_SPOS_DC,
		/* 9 */ 0,
		/* A */ 0,HFG_FIRST_EXECUTE_MODE,
		/* B */ DSP_SPOS_UU,DSP_SPOS_UU,
		/* C */ DSP_SPOS_DC_DC,
		/* D */ DSP_SPOS_DC_DC,
		/* E */ DSP_SPOS_DC_DC,
		/* F */ DSP_SPOS_DC_DC
	};

	cs46xx_dsp_create_task_tree(chip, "sposCB", (u32 *)&sposcb, SPOSCB_ADDR, 0x10);

	null_algorithm  = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE);
	if (null_algorithm == NULL) {
1132 1133
		dev_err(chip->card->dev,
			"dsp_spos: symbol NULLALGORITHM not found\n");
L
Linus Torvalds 已提交
1134 1135 1136 1137 1138
		return -EIO;
	}

	fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE);  
	if (fg_task_tree_header_code == NULL) {
1139 1140
		dev_err(chip->card->dev,
			"dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
L
Linus Torvalds 已提交
1141 1142 1143 1144 1145
		return -EIO;
	}

	task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE);  
	if (task_tree_header_code == NULL) {
1146 1147
		dev_err(chip->card->dev,
			"dsp_spos: symbol TASKTREEHEADERCODE not found\n");
L
Linus Torvalds 已提交
1148 1149 1150 1151 1152
		return -EIO;
	}
  
	task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE);
	if (task_tree_thread == NULL) {
1153 1154
		dev_err(chip->card->dev,
			"dsp_spos: symbol TASKTREETHREAD not found\n");
L
Linus Torvalds 已提交
1155 1156 1157 1158 1159
		return -EIO;
	}

	magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE);
	if (magic_snoop_task == NULL) {
1160 1161
		dev_err(chip->card->dev,
			"dsp_spos: symbol MAGICSNOOPTASK not found\n");
L
Linus Torvalds 已提交
1162 1163 1164 1165 1166
		return -EIO;
	}
  
	{
		/* create the null SCB */
1167
		static struct dsp_generic_scb null_scb = {
L
Linus Torvalds 已提交
1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188
			{ 0, 0, 0, 0 },
			{ 0, 0, 0, 0, 0 },
			NULL_SCB_ADDR, NULL_SCB_ADDR,
			0, 0, 0, 0, 0,
			{
				0,0,
				0,0,
			}
		};

		null_scb.entry_point = null_algorithm->address;
		ins->the_null_scb = cs46xx_dsp_create_scb(chip, "nullSCB", (u32 *)&null_scb, NULL_SCB_ADDR);
		ins->the_null_scb->task_entry = null_algorithm;
		ins->the_null_scb->sub_list_ptr = ins->the_null_scb;
		ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
		ins->the_null_scb->parent_scb_ptr = NULL;
		cs46xx_dsp_proc_register_scb_desc (chip,ins->the_null_scb);
	}

	{
		/* setup foreground task tree */
1189
		static struct dsp_task_tree_control_block fg_task_tree_hdr =  {
L
Linus Torvalds 已提交
1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264
			{ FG_TASK_HEADER_ADDR | (DSP_SPOS_DC << 0x10),
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  0x0000,DSP_SPOS_DC,
			  DSP_SPOS_DC, DSP_SPOS_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC,DSP_SPOS_DC },
    
			{
				BG_TREE_SCB_ADDR,TIMINGMASTER_SCB_ADDR, 
				0,
				FG_TASK_HEADER_ADDR + TCBData,                  
			},

			{    
				4,0,
				1,0,
				2,SPOSCB_ADDR + HFGFlags,
				0,0,
				FG_TASK_HEADER_ADDR + TCBContextBlk,FG_STACK
			},

			{
				DSP_SPOS_DC,0,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DCDC,
				DSP_SPOS_UU,1,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC 
			},                                               
			{ 
				FG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
				0,0
			}
		};

		fg_task_tree_hdr.links.entry_point = fg_task_tree_header_code->address;
		fg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
		cs46xx_dsp_create_task_tree(chip,"FGtaskTreeHdr",(u32 *)&fg_task_tree_hdr,FG_TASK_HEADER_ADDR,0x35);
	}


	{
		/* setup foreground task tree */
1265
		static struct dsp_task_tree_control_block bg_task_tree_hdr =  {
L
Linus Torvalds 已提交
1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373
			{ DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC, DSP_SPOS_DC,
			  DSP_SPOS_DC, DSP_SPOS_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC_DC,
			  DSP_SPOS_DC,DSP_SPOS_DC },
    
			{
				NULL_SCB_ADDR,NULL_SCB_ADDR,  /* Set up the background to do nothing */
				0,
				BG_TREE_SCB_ADDR + TCBData,
			},

			{    
				9999,0,
				0,1,
				0,SPOSCB_ADDR + HFGFlags,
				0,0,
				BG_TREE_SCB_ADDR + TCBContextBlk,BG_STACK
			},

			{
				DSP_SPOS_DC,0,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DC,DSP_SPOS_DC,
				DSP_SPOS_DCDC,
				DSP_SPOS_UU,1,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC,
				DSP_SPOS_DCDC 
			},                                               
			{ 
				BG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
				0,0
			}
		};

		bg_task_tree_hdr.links.entry_point = task_tree_header_code->address;
		bg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
		cs46xx_dsp_create_task_tree(chip,"BGtaskTreeHdr",(u32 *)&bg_task_tree_hdr,BG_TREE_SCB_ADDR,0x35);
	}

	/* create timing master SCB */
	timing_master_scb = cs46xx_dsp_create_timing_master_scb(chip);

	/* create the CODEC output task */
	codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_I",0x0010,0x0000,
							MASTERMIX_SCB_ADDR,
							CODECOUT_SCB_ADDR,timing_master_scb,
							SCB_ON_PARENT_SUBLIST_SCB);

	if (!codec_out_scb) goto _fail_end;
	/* create the master mix SCB */
	master_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"MasterMixSCB",
							MIX_SAMPLE_BUF1,MASTERMIX_SCB_ADDR,
							codec_out_scb,
							SCB_ON_PARENT_SUBLIST_SCB);
	ins->master_mix_scb = master_mix_scb;

	if (!master_mix_scb) goto _fail_end;

	/* create codec in */
	codec_in_scb = cs46xx_dsp_create_codec_in_scb(chip,"CodecInSCB",0x0010,0x00A0,
						      CODEC_INPUT_BUF1,
						      CODECIN_SCB_ADDR,codec_out_scb,
						      SCB_ON_PARENT_NEXT_SCB);
	if (!codec_in_scb) goto _fail_end;
	ins->codec_in_scb = codec_in_scb;

	/* create write back scb */
	write_back_scb = cs46xx_dsp_create_mix_to_ostream_scb(chip,"WriteBackSCB",
							      WRITE_BACK_BUF1,WRITE_BACK_SPB,
							      WRITEBACK_SCB_ADDR,
							      timing_master_scb,
							      SCB_ON_PARENT_NEXT_SCB);
	if (!write_back_scb) goto _fail_end;

	{
1374
		static struct dsp_mix2_ostream_spb mix2_ostream_spb = {
L
Linus Torvalds 已提交
1375 1376 1377 1378
			0x00020000,
			0x0000ffff
		};
    
T
Takashi Iwai 已提交
1379 1380 1381 1382
		if (!cs46xx_dsp_create_task_tree(chip, NULL,
						 (u32 *)&mix2_ostream_spb,
						 WRITE_BACK_SPB, 2))
			goto _fail_end;
L
Linus Torvalds 已提交
1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405
	}

	/* input sample converter */
	vari_decimate_scb = cs46xx_dsp_create_vari_decimate_scb(chip,"VariDecimateSCB",
								VARI_DECIMATE_BUF0,
								VARI_DECIMATE_BUF1,
								VARIDECIMATE_SCB_ADDR,
								write_back_scb,
								SCB_ON_PARENT_SUBLIST_SCB);
	if (!vari_decimate_scb) goto _fail_end;

	/* create the record mixer SCB */
	record_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RecordMixerSCB",
							MIX_SAMPLE_BUF2,
							RECORD_MIXER_SCB_ADDR,
							vari_decimate_scb,
							SCB_ON_PARENT_SUBLIST_SCB);
	ins->record_mixer_scb = record_mix_scb;

	if (!record_mix_scb) goto _fail_end;

	valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);

1406 1407
	if (snd_BUG_ON(chip->nr_ac97_codecs != 1 && chip->nr_ac97_codecs != 2))
		goto _fail_end;
L
Linus Torvalds 已提交
1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444

	if (chip->nr_ac97_codecs == 1) {
		/* output on slot 5 and 11 
		   on primary CODEC */
		fifo_addr = 0x20;
		fifo_span = 0x60;

		/* enable slot 5 and 11 */
		valid_slots |= ACOSV_SLV5 | ACOSV_SLV11;
	} else {
		/* output on slot 7 and 8 
		   on secondary CODEC */
		fifo_addr = 0x40;
		fifo_span = 0x10;

		/* enable slot 7 and 8 */
		valid_slots |= ACOSV_SLV7 | ACOSV_SLV8;
	}
	/* create CODEC tasklet for rear speakers output*/
	rear_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_Rear",fifo_span,fifo_addr,
							     REAR_MIXER_SCB_ADDR,
							     REAR_CODECOUT_SCB_ADDR,codec_in_scb,
							     SCB_ON_PARENT_NEXT_SCB);
	if (!rear_codec_out_scb) goto _fail_end;
	
	
	/* create the rear PCM channel  mixer SCB */
	rear_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RearMixerSCB",
						      MIX_SAMPLE_BUF3,
						      REAR_MIXER_SCB_ADDR,
						      rear_codec_out_scb,
						      SCB_ON_PARENT_SUBLIST_SCB);
	ins->rear_mix_scb = rear_mix_scb;
	if (!rear_mix_scb) goto _fail_end;
	
	if (chip->nr_ac97_codecs == 2) {
		/* create CODEC tasklet for rear Center/LFE output 
1445
		   slot 6 and 9 on secondary CODEC */
L
Linus Torvalds 已提交
1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507
		clfe_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_CLFE",0x0030,0x0030,
								     CLFE_MIXER_SCB_ADDR,
								     CLFE_CODEC_SCB_ADDR,
								     rear_codec_out_scb,
								     SCB_ON_PARENT_NEXT_SCB);
		if (!clfe_codec_out_scb) goto _fail_end;
		
		
		/* create the rear PCM channel  mixer SCB */
		ins->center_lfe_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"CLFEMixerSCB",
									 MIX_SAMPLE_BUF4,
									 CLFE_MIXER_SCB_ADDR,
									 clfe_codec_out_scb,
									 SCB_ON_PARENT_SUBLIST_SCB);
		if (!ins->center_lfe_mix_scb) goto _fail_end;

		/* enable slot 6 and 9 */
		valid_slots |= ACOSV_SLV6 | ACOSV_SLV9;
	} else {
		clfe_codec_out_scb = rear_codec_out_scb;
		ins->center_lfe_mix_scb = rear_mix_scb;
	}

	/* enable slots depending on CODEC configuration */
	snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots);

	/* the magic snooper */
	magic_snoop_scb = cs46xx_dsp_create_magic_snoop_scb (chip,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR,
							     OUTPUT_SNOOP_BUFFER,
							     codec_out_scb,
							     clfe_codec_out_scb,
							     SCB_ON_PARENT_NEXT_SCB);

    
	if (!magic_snoop_scb) goto _fail_end;
	ins->ref_snoop_scb = magic_snoop_scb;

	/* SP IO access */
	if (!cs46xx_dsp_create_spio_write_scb(chip,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR,
					      magic_snoop_scb,
					      SCB_ON_PARENT_NEXT_SCB))
		goto _fail_end;

	/* SPDIF input sampel rate converter */
	src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI",
						      ins->spdif_in_sample_rate,
						      SRC_OUTPUT_BUF1,
						      SRC_DELAY_BUF1,SRCTASK_SCB_ADDR,
						      master_mix_scb,
						      SCB_ON_PARENT_SUBLIST_SCB,1);

	if (!src_task_scb) goto _fail_end;
	cs46xx_src_unlink(chip,src_task_scb);

	/* NOTE: when we now how to detect the SPDIF input
	   sample rate we will use this SRC to adjust it */
	ins->spdif_in_src = src_task_scb;

	cs46xx_dsp_async_init(chip,timing_master_scb);
	return 0;

 _fail_end:
1508
	dev_err(chip->card->dev, "dsp_spos: failed to setup SCB's in DSP\n");
L
Linus Torvalds 已提交
1509 1510 1511
	return -EINVAL;
}

1512 1513
static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
				  struct dsp_scb_descriptor * fg_entry)
L
Linus Torvalds 已提交
1514
{
1515 1516 1517 1518 1519
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_symbol_entry * s16_async_codec_input_task;
	struct dsp_symbol_entry * spdifo_task;
	struct dsp_symbol_entry * spdifi_task;
	struct dsp_scb_descriptor * spdifi_scb_desc, * spdifo_scb_desc, * async_codec_scb_desc;
L
Linus Torvalds 已提交
1520 1521 1522

	s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE);
	if (s16_async_codec_input_task == NULL) {
1523 1524
		dev_err(chip->card->dev,
			"dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
L
Linus Torvalds 已提交
1525 1526 1527 1528
		return -EIO;
	}
	spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE);
	if (spdifo_task == NULL) {
1529 1530
		dev_err(chip->card->dev,
			"dsp_spos: symbol SPDIFOTASK not found\n");
L
Linus Torvalds 已提交
1531 1532 1533 1534 1535
		return -EIO;
	}

	spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE);
	if (spdifi_task == NULL) {
1536 1537
		dev_err(chip->card->dev,
			"dsp_spos: symbol SPDIFITASK not found\n");
L
Linus Torvalds 已提交
1538 1539 1540 1541 1542
		return -EIO;
	}

	{
		/* 0xBC0 */
1543
		struct dsp_spdifoscb spdifo_scb = {
L
Linus Torvalds 已提交
1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571
			/* 0 */ DSP_SPOS_UUUU,
			{
				/* 1 */ 0xb0, 
				/* 2 */ 0, 
				/* 3 */ 0, 
				/* 4 */ 0, 
			},
			/* NOTE: the SPDIF output task read samples in mono
			   format, the AsynchFGTxSCB task writes to buffer
			   in stereo format
			*/
			/* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_256,
			/* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1 << 0x10 )  |  0xFFFC,
			/* 7 */ 0,0, 
			/* 8 */ 0, 
			/* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR, 
			/* A */ spdifo_task->address,
			SPDIFO_SCB_INST + SPDIFOFIFOPointer,
			{
				/* B */ 0x0040, /*DSP_SPOS_UUUU,*/
				/* C */ 0x20ff, /*DSP_SPOS_UUUU,*/
			},
			/* D */ 0x804c,0,							  /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */
			/* E */ 0x0108,0x0001,					  /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
			/* F */ DSP_SPOS_UUUU	  			          /* SPDIFOFree; */
		};

		/* 0xBB0 */
1572
		struct dsp_spdifiscb spdifi_scb = {
L
Linus Torvalds 已提交
1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596
			/* 0 */ DSP_SPOS_UULO,DSP_SPOS_UUHI,
			/* 1 */ 0,
			/* 2 */ 0,
			/* 3 */ 1,4000,        /* SPDIFICountLimit SPDIFICount */ 
			/* 4 */ DSP_SPOS_UUUU, /* SPDIFIStatusData */
			/* 5 */ 0,DSP_SPOS_UUHI, /* StatusData, Free4 */
			/* 6 */ DSP_SPOS_UUUU,  /* Free3 */
			/* 7 */ DSP_SPOS_UU,DSP_SPOS_DC,  /* Free2 BitCount*/
			/* 8 */ DSP_SPOS_UUUU,	/* TempStatus */
			/* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR,
			/* A */ spdifi_task->address,
			SPDIFI_SCB_INST + SPDIFIFIFOPointer,
			/* NOTE: The SPDIF input task write the sample in mono
			   format from the HW FIFO, the AsynchFGRxSCB task  reads 
			   them in stereo 
			*/
			/* B */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_128,
			/* C */ (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
			/* D */ 0x8048,0,
			/* E */ 0x01f0,0x0001,
			/* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */
		};

		/* 0xBA0 */
1597
		struct dsp_async_codec_input_scb async_codec_input_scb = {
L
Linus Torvalds 已提交
1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
			/* 0 */ DSP_SPOS_UUUU,
			/* 1 */ 0,
			/* 2 */ 0,
			/* 3 */ 1,4000,
			/* 4 */ 0x0118,0x0001,
			/* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_64,
			/* 6 */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
			/* 7 */ DSP_SPOS_UU,0x3,
			/* 8 */ DSP_SPOS_UUUU,
			/* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR,
			/* A */ s16_async_codec_input_task->address,
			HFG_TREE_SCB + AsyncCIOFIFOPointer,
              
			/* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
			/* C */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10),  /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/
      
#ifdef UseASER1Input
			/* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;	       
			   Init. 0000:8042: for ASER1
			   0000:8044: for ASER2 */
			/* D */ 0x8042,0,
      
			/* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
			   Init 1 stero:8050 ASER1
			   Init 0  mono:8070 ASER2
			   Init 1 Stereo : 0100 ASER1 (Set by script) */
			/* E */ 0x0100,0x0001,
      
#endif
      
#ifdef UseASER2Input
			/* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
			   Init. 0000:8042: for ASER1
			   0000:8044: for ASER2 */
			/* D */ 0x8044,0,
      
			/* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
			   Init 1 stero:8050 ASER1
			   Init 0  mono:8070 ASER2
			   Init 1 Stereo : 0100 ASER1 (Set by script) */
			/* E */ 0x0110,0x0001,
      
#endif
      
			/* short AsyncCIOutputBufModulo:AsyncCIFree;
			   AsyncCIOutputBufModulo: The modulo size for   
			   the output buffer of this task */
			/* F */ 0, /* DSP_SPOS_UUUU */
		};

		spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);

1650 1651
		if (snd_BUG_ON(!spdifo_scb_desc))
			return -EIO;
L
Linus Torvalds 已提交
1652
		spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST);
1653 1654
		if (snd_BUG_ON(!spdifi_scb_desc))
			return -EIO;
L
Linus Torvalds 已提交
1655
		async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB);
1656 1657
		if (snd_BUG_ON(!async_codec_scb_desc))
			return -EIO;
L
Linus Torvalds 已提交
1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689

		async_codec_scb_desc->parent_scb_ptr = NULL;
		async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc;
		async_codec_scb_desc->sub_list_ptr = ins->the_null_scb;
		async_codec_scb_desc->task_entry = s16_async_codec_input_task;

		spdifi_scb_desc->parent_scb_ptr = async_codec_scb_desc;
		spdifi_scb_desc->next_scb_ptr = spdifo_scb_desc;
		spdifi_scb_desc->sub_list_ptr = ins->the_null_scb;
		spdifi_scb_desc->task_entry = spdifi_task;

		spdifo_scb_desc->parent_scb_ptr = spdifi_scb_desc;
		spdifo_scb_desc->next_scb_ptr = fg_entry;
		spdifo_scb_desc->sub_list_ptr = ins->the_null_scb;
		spdifo_scb_desc->task_entry = spdifo_task;

		/* this one is faked, as the parnet of SPDIFO task
		   is the FG task tree */
		fg_entry->parent_scb_ptr = spdifo_scb_desc;

		/* for proc fs */
		cs46xx_dsp_proc_register_scb_desc (chip,spdifo_scb_desc);
		cs46xx_dsp_proc_register_scb_desc (chip,spdifi_scb_desc);
		cs46xx_dsp_proc_register_scb_desc (chip,async_codec_scb_desc);

		/* Async MASTER ENABLE, affects both SPDIF input and output */
		snd_cs46xx_pokeBA0(chip, BA0_ASER_MASTER, 0x1 );
	}

	return 0;
}

1690
static void cs46xx_dsp_disable_spdif_hw (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1691
{
1692
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710

	/* set SPDIF output FIFO slot */
	snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, 0);

	/* SPDIF output MASTER ENABLE */
	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0);

	/* right and left validate bit */
	/*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/
	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x0);

	/* clear fifo pointer */
	cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);

	/* monitor state */
	ins->spdif_status_out &= ~DSP_SPDIF_STATUS_HW_ENABLED;
}

1711
int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1712
{
1713
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733

	/* if hw-ctrl already enabled, turn off to reset logic ... */
	cs46xx_dsp_disable_spdif_hw (chip);
	udelay(50);

	/* set SPDIF output FIFO slot */
	snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, ( 0x8000 | ((SP_SPDOUT_FIFO >> 4) << 4) ));

	/* SPDIF output MASTER ENABLE */
	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000);

	/* right and left validate bit */
	cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);

	/* monitor state */
	ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED;

	return 0;
}

1734
int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1735
{
1736
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1737 1738 1739 1740 1741

	/* turn on amplifier */
	chip->active_ctrl(chip, 1);
	chip->amplifier_ctrl(chip, 1);

1742 1743 1744 1745
	if (snd_BUG_ON(ins->asynch_rx_scb))
		return -EINVAL;
	if (snd_BUG_ON(!ins->spdif_in_src))
		return -EINVAL;
L
Linus Torvalds 已提交
1746

1747
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790

	if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) {
		/* time countdown enable */
		cs46xx_poke_via_dsp (chip,SP_ASER_COUNTDOWN, 0x80000005);
		/* NOTE: 80000005 value is just magic. With all values
		   that I've tested this one seem to give the best result.
		   Got no explication why. (Benny) */

		/* SPDIF input MASTER ENABLE */
		cs46xx_poke_via_dsp (chip,SP_SPDIN_CONTROL, 0x800003ff);

		ins->spdif_status_out |= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED;
	}

	/* create and start the asynchronous receiver SCB */
	ins->asynch_rx_scb = cs46xx_dsp_create_asynch_fg_rx_scb(chip,"AsynchFGRxSCB",
								ASYNCRX_SCB_ADDR,
								SPDIFI_SCB_INST,
								SPDIFI_IP_OUTPUT_BUFFER1,
								ins->spdif_in_src,
								SCB_ON_PARENT_SUBLIST_SCB);

	spin_lock_irq(&chip->reg_lock);

	/* reset SPDIF input sample buffer pointer */
	/*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
	  (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/

	/* reset FIFO ptr */
	/*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/
	cs46xx_src_link(chip,ins->spdif_in_src);

	/* unmute SRC volume */
	cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff);

	spin_unlock_irq(&chip->reg_lock);

	/* set SPDIF input sample rate and unmute
	   NOTE: only 48khz support for SPDIF input this time */
	/* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */

	/* monitor state */
	ins->spdif_status_in = 1;
1791
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1792 1793 1794 1795

	return 0;
}

1796
int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1797
{
1798
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1799

1800 1801 1802 1803
	if (snd_BUG_ON(!ins->asynch_rx_scb))
		return -EINVAL;
	if (snd_BUG_ON(!ins->spdif_in_src))
		return -EINVAL;
L
Linus Torvalds 已提交
1804

1805
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1806 1807 1808 1809 1810 1811 1812 1813 1814

	/* Remove the asynchronous receiver SCB */
	cs46xx_dsp_remove_scb (chip,ins->asynch_rx_scb);
	ins->asynch_rx_scb = NULL;

	cs46xx_src_unlink(chip,ins->spdif_in_src);

	/* monitor state */
	ins->spdif_status_in = 0;
1815
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1816 1817 1818 1819 1820 1821 1822 1823

	/* restore amplifier */
	chip->active_ctrl(chip, -1);
	chip->amplifier_ctrl(chip, -1);

	return 0;
}

1824
int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1825
{
1826
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1827

1828 1829 1830 1831
	if (snd_BUG_ON(ins->pcm_input))
		return -EINVAL;
	if (snd_BUG_ON(!ins->ref_snoop_scb))
		return -EINVAL;
L
Linus Torvalds 已提交
1832

1833
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1834 1835
	ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
                                                  "PCMSerialInput_Wave");
1836
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1837 1838 1839 1840

	return 0;
}

1841
int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1842
{
1843
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1844

1845 1846
	if (snd_BUG_ON(!ins->pcm_input))
		return -EINVAL;
L
Linus Torvalds 已提交
1847

1848
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1849 1850
	cs46xx_dsp_remove_scb (chip,ins->pcm_input);
	ins->pcm_input = NULL;
1851
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1852 1853 1854 1855

	return 0;
}

1856
int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1857
{
1858
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1859

1860 1861 1862 1863
	if (snd_BUG_ON(ins->adc_input))
		return -EINVAL;
	if (snd_BUG_ON(!ins->codec_in_scb))
		return -EINVAL;
L
Linus Torvalds 已提交
1864

1865
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1866 1867
	ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
						  "PCMSerialInput_ADC");
1868
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1869 1870 1871 1872

	return 0;
}

1873
int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip)
L
Linus Torvalds 已提交
1874
{
1875
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1876

1877 1878
	if (snd_BUG_ON(!ins->adc_input))
		return -EINVAL;
L
Linus Torvalds 已提交
1879

1880
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1881 1882
	cs46xx_dsp_remove_scb (chip,ins->adc_input);
	ins->adc_input = NULL;
1883
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1884 1885 1886 1887

	return 0;
}

1888
int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data)
L
Linus Torvalds 已提交
1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917
{
	u32 temp;
	int  i;

	/* santiy check the parameters.  (These numbers are not 100% correct.  They are
	   a rough guess from looking at the controller spec.) */
	if (address < 0x8000 || address >= 0x9000)
		return -EINVAL;
        
	/* initialize the SP_IO_WRITE SCB with the data. */
	temp = ( address << 16 ) | ( address & 0x0000FFFF);   /* offset 0 <-- address2 : address1 */

	snd_cs46xx_poke(chip,( SPIOWRITE_SCB_ADDR      << 2), temp);
	snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 1) << 2), data); /* offset 1 <-- data1 */
	snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 2) << 2), data); /* offset 1 <-- data2 */
    
	/* Poke this location to tell the task to start */
	snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 6) << 2), SPIOWRITE_SCB_ADDR << 0x10);

	/* Verify that the task ran */
	for (i=0; i<25; i++) {
		udelay(125);

		temp =  snd_cs46xx_peek(chip,((SPIOWRITE_SCB_ADDR + 6) << 2));
		if (temp == 0x00000000)
			break;
	}

	if (i == 25) {
1918 1919
		dev_err(chip->card->dev,
			"dsp_spos: SPIOWriteTask not responding\n");
L
Linus Torvalds 已提交
1920 1921 1922 1923 1924 1925
		return -EBUSY;
	}

	return 0;
}

1926
int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right)
L
Linus Torvalds 已提交
1927
{
1928 1929
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	struct dsp_scb_descriptor * scb; 
L
Linus Torvalds 已提交
1930

1931
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949
	
	/* main output */
	scb = ins->master_mix_scb->sub_list_ptr;
	while (scb != ins->the_null_scb) {
		cs46xx_dsp_scb_set_volume (chip,scb,left,right);
		scb = scb->next_scb_ptr;
	}

	/* rear output */
	scb = ins->rear_mix_scb->sub_list_ptr;
	while (scb != ins->the_null_scb) {
		cs46xx_dsp_scb_set_volume (chip,scb,left,right);
		scb = scb->next_scb_ptr;
	}

	ins->dac_volume_left = left;
	ins->dac_volume_right = right;

1950
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1951 1952 1953 1954

	return 0;
}

1955 1956 1957
int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right)
{
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
L
Linus Torvalds 已提交
1958

1959
	mutex_lock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1960 1961 1962 1963 1964 1965 1966 1967

	if (ins->asynch_rx_scb != NULL)
		cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb,
					   left,right);

	ins->spdif_input_volume_left = left;
	ins->spdif_input_volume_right = right;

1968
	mutex_unlock(&chip->spos_mutex);
L
Linus Torvalds 已提交
1969 1970 1971

	return 0;
}
T
Takashi Iwai 已提交
1972

1973
#ifdef CONFIG_PM_SLEEP
T
Takashi Iwai 已提交
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025
int cs46xx_dsp_resume(struct snd_cs46xx * chip)
{
	struct dsp_spos_instance * ins = chip->dsp_spos_instance;
	int i, err;

	/* clear parameter, sample and code areas */
	snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET,
			     DSP_PARAMETER_BYTE_SIZE);
	snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET,
			     DSP_SAMPLE_BYTE_SIZE);
	snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);

	for (i = 0; i < ins->nmodules; i++) {
		struct dsp_module_desc *module = &ins->modules[i];
		struct dsp_segment_desc *seg;
		u32 doffset, dsize;

		seg = get_segment_desc(module, SEGTYPE_SP_PARAMETER);
		err = dsp_load_parameter(chip, seg);
		if (err < 0)
			return err;

		seg = get_segment_desc(module, SEGTYPE_SP_SAMPLE);
		err = dsp_load_sample(chip, seg);
		if (err < 0)
			return err;

		seg = get_segment_desc(module, SEGTYPE_SP_PROGRAM);
		if (!seg)
			continue;

		doffset = seg->offset * 4 + module->load_address * 4
			+ DSP_CODE_BYTE_OFFSET;
		dsize   = seg->size * 4;
		err = snd_cs46xx_download(chip,
					  ins->code.data + module->load_address,
					  doffset, dsize);
		if (err < 0)
			return err;
	}

	for (i = 0; i < ins->ntask; i++) {
		struct dsp_task_descriptor *t = &ins->tasks[i];
		_dsp_create_task_tree(chip, t->data, t->address, t->size);
	}

	for (i = 0; i < ins->nscb; i++) {
		struct dsp_scb_descriptor *s = &ins->scbs[i];
		if (s->deleted)
			continue;
		_dsp_create_scb(chip, s->data, s->address);
	}
2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047
	for (i = 0; i < ins->nscb; i++) {
		struct dsp_scb_descriptor *s = &ins->scbs[i];
		if (s->deleted)
			continue;
		if (s->updated)
			cs46xx_dsp_spos_update_scb(chip, s);
		if (s->volume_set)
			cs46xx_dsp_scb_set_volume(chip, s,
						  s->volume[0], s->volume[1]);
	}
	if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) {
		cs46xx_dsp_enable_spdif_hw(chip);
		snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2,
				(OUTPUT_SNOOP_BUFFER + 0x10) << 0x10);
		if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN)
			cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV,
					    ins->spdif_csuv_stream);
	}
	if (chip->dsp_spos_instance->spdif_status_in) {
		cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005);
		cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff);
	}
T
Takashi Iwai 已提交
2048 2049 2050
	return 0;
}
#endif