dsp_spos.c 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. */
  4. /*
  5. * 2002-07 Benny Sjostrand [email protected]
  6. */
  7. #include <linux/io.h>
  8. #include <linux/delay.h>
  9. #include <linux/pm.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/vmalloc.h>
  13. #include <linux/mutex.h>
  14. #include <sound/core.h>
  15. #include <sound/control.h>
  16. #include <sound/info.h>
  17. #include <sound/asoundef.h>
  18. #include "cs46xx.h"
  19. #include "cs46xx_lib.h"
  20. #include "dsp_spos.h"
  21. static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
  22. struct dsp_scb_descriptor * fg_entry);
  23. static const enum wide_opcode wide_opcodes[] = {
  24. WIDE_FOR_BEGIN_LOOP,
  25. WIDE_FOR_BEGIN_LOOP2,
  26. WIDE_COND_GOTO_ADDR,
  27. WIDE_COND_GOTO_CALL,
  28. WIDE_TBEQ_COND_GOTO_ADDR,
  29. WIDE_TBEQ_COND_CALL_ADDR,
  30. WIDE_TBEQ_NCOND_GOTO_ADDR,
  31. WIDE_TBEQ_NCOND_CALL_ADDR,
  32. WIDE_TBEQ_COND_GOTO1_ADDR,
  33. WIDE_TBEQ_COND_CALL1_ADDR,
  34. WIDE_TBEQ_NCOND_GOTOI_ADDR,
  35. WIDE_TBEQ_NCOND_CALL1_ADDR
  36. };
  37. static int shadow_and_reallocate_code (struct snd_cs46xx * chip, u32 * data, u32 size,
  38. u32 overlay_begin_address)
  39. {
  40. unsigned int i = 0, j, nreallocated = 0;
  41. u32 hival,loval,address;
  42. u32 mop_operands,mop_type,wide_op;
  43. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  44. if (snd_BUG_ON(size %2))
  45. return -EINVAL;
  46. while (i < size) {
  47. loval = data[i++];
  48. hival = data[i++];
  49. if (ins->code.offset > 0) {
  50. mop_operands = (hival >> 6) & 0x03fff;
  51. mop_type = mop_operands >> 10;
  52. /* check for wide type instruction */
  53. if (mop_type == 0 &&
  54. (mop_operands & WIDE_LADD_INSTR_MASK) == 0 &&
  55. (mop_operands & WIDE_INSTR_MASK) != 0) {
  56. wide_op = loval & 0x7f;
  57. for (j = 0;j < ARRAY_SIZE(wide_opcodes); ++j) {
  58. if (wide_opcodes[j] == wide_op) {
  59. /* need to reallocate instruction */
  60. address = (hival & 0x00FFF) << 5;
  61. address |= loval >> 15;
  62. dev_dbg(chip->card->dev,
  63. "handle_wideop[1]: %05x:%05x addr %04x\n",
  64. hival, loval, address);
  65. if ( !(address & 0x8000) ) {
  66. address += (ins->code.offset / 2) - overlay_begin_address;
  67. } else {
  68. dev_dbg(chip->card->dev,
  69. "handle_wideop[1]: ROM symbol not reallocated\n");
  70. }
  71. hival &= 0xFF000;
  72. loval &= 0x07FFF;
  73. hival |= ( (address >> 5) & 0x00FFF);
  74. loval |= ( (address << 15) & 0xF8000);
  75. address = (hival & 0x00FFF) << 5;
  76. address |= loval >> 15;
  77. dev_dbg(chip->card->dev,
  78. "handle_wideop:[2] %05x:%05x addr %04x\n",
  79. hival, loval, address);
  80. nreallocated++;
  81. } /* wide_opcodes[j] == wide_op */
  82. } /* for */
  83. } /* mod_type == 0 ... */
  84. } /* ins->code.offset > 0 */
  85. ins->code.data[ins->code.size++] = loval;
  86. ins->code.data[ins->code.size++] = hival;
  87. }
  88. dev_dbg(chip->card->dev,
  89. "dsp_spos: %d instructions reallocated\n", nreallocated);
  90. return nreallocated;
  91. }
  92. static struct dsp_segment_desc * get_segment_desc (struct dsp_module_desc * module, int seg_type)
  93. {
  94. int i;
  95. for (i = 0;i < module->nsegments; ++i) {
  96. if (module->segments[i].segment_type == seg_type) {
  97. return (module->segments + i);
  98. }
  99. }
  100. return NULL;
  101. };
  102. static int find_free_symbol_index (struct dsp_spos_instance * ins)
  103. {
  104. int index = ins->symbol_table.nsymbols,i;
  105. for (i = ins->symbol_table.highest_frag_index; i < ins->symbol_table.nsymbols; ++i) {
  106. if (ins->symbol_table.symbols[i].deleted) {
  107. index = i;
  108. break;
  109. }
  110. }
  111. return index;
  112. }
  113. static int add_symbols (struct snd_cs46xx * chip, struct dsp_module_desc * module)
  114. {
  115. int i;
  116. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  117. if (module->symbol_table.nsymbols > 0) {
  118. if (!strcmp(module->symbol_table.symbols[0].symbol_name, "OVERLAYBEGINADDRESS") &&
  119. module->symbol_table.symbols[0].symbol_type == SYMBOL_CONSTANT ) {
  120. module->overlay_begin_address = module->symbol_table.symbols[0].address;
  121. }
  122. }
  123. for (i = 0;i < module->symbol_table.nsymbols; ++i) {
  124. if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
  125. dev_err(chip->card->dev,
  126. "dsp_spos: symbol table is full\n");
  127. return -ENOMEM;
  128. }
  129. if (cs46xx_dsp_lookup_symbol(chip,
  130. module->symbol_table.symbols[i].symbol_name,
  131. module->symbol_table.symbols[i].symbol_type) == NULL) {
  132. ins->symbol_table.symbols[ins->symbol_table.nsymbols] = module->symbol_table.symbols[i];
  133. ins->symbol_table.symbols[ins->symbol_table.nsymbols].address += ((ins->code.offset / 2) - module->overlay_begin_address);
  134. ins->symbol_table.symbols[ins->symbol_table.nsymbols].module = module;
  135. ins->symbol_table.symbols[ins->symbol_table.nsymbols].deleted = 0;
  136. if (ins->symbol_table.nsymbols > ins->symbol_table.highest_frag_index)
  137. ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols;
  138. ins->symbol_table.nsymbols++;
  139. } else {
  140. #if 0
  141. dev_dbg(chip->card->dev,
  142. "dsp_spos: symbol <%s> duplicated, probably nothing wrong with that (Cirrus?)\n",
  143. module->symbol_table.symbols[i].symbol_name); */
  144. #endif
  145. }
  146. }
  147. return 0;
  148. }
  149. static struct dsp_symbol_entry *
  150. add_symbol (struct snd_cs46xx * chip, char * symbol_name, u32 address, int type)
  151. {
  152. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  153. struct dsp_symbol_entry * symbol = NULL;
  154. int index;
  155. if (ins->symbol_table.nsymbols == (DSP_MAX_SYMBOLS - 1)) {
  156. dev_err(chip->card->dev, "dsp_spos: symbol table is full\n");
  157. return NULL;
  158. }
  159. if (cs46xx_dsp_lookup_symbol(chip,
  160. symbol_name,
  161. type) != NULL) {
  162. dev_err(chip->card->dev,
  163. "dsp_spos: symbol <%s> duplicated\n", symbol_name);
  164. return NULL;
  165. }
  166. index = find_free_symbol_index (ins);
  167. strcpy (ins->symbol_table.symbols[index].symbol_name, symbol_name);
  168. ins->symbol_table.symbols[index].address = address;
  169. ins->symbol_table.symbols[index].symbol_type = type;
  170. ins->symbol_table.symbols[index].module = NULL;
  171. ins->symbol_table.symbols[index].deleted = 0;
  172. symbol = (ins->symbol_table.symbols + index);
  173. if (index > ins->symbol_table.highest_frag_index)
  174. ins->symbol_table.highest_frag_index = index;
  175. if (index == ins->symbol_table.nsymbols)
  176. ins->symbol_table.nsymbols++; /* no frag. in list */
  177. return symbol;
  178. }
  179. struct dsp_spos_instance *cs46xx_dsp_spos_create (struct snd_cs46xx * chip)
  180. {
  181. struct dsp_spos_instance * ins = kzalloc(sizeof(struct dsp_spos_instance), GFP_KERNEL);
  182. if (ins == NULL)
  183. return NULL;
  184. /* better to use vmalloc for this big table */
  185. ins->symbol_table.symbols =
  186. vmalloc(array_size(DSP_MAX_SYMBOLS,
  187. sizeof(struct dsp_symbol_entry)));
  188. ins->code.data = kmalloc(DSP_CODE_BYTE_SIZE, GFP_KERNEL);
  189. ins->modules = kmalloc_array(DSP_MAX_MODULES,
  190. sizeof(struct dsp_module_desc),
  191. GFP_KERNEL);
  192. if (!ins->symbol_table.symbols || !ins->code.data || !ins->modules) {
  193. cs46xx_dsp_spos_destroy(chip);
  194. goto error;
  195. }
  196. ins->symbol_table.nsymbols = 0;
  197. ins->symbol_table.highest_frag_index = 0;
  198. ins->code.offset = 0;
  199. ins->code.size = 0;
  200. ins->nscb = 0;
  201. ins->ntask = 0;
  202. ins->nmodules = 0;
  203. /* default SPDIF input sample rate
  204. to 48000 khz */
  205. ins->spdif_in_sample_rate = 48000;
  206. /* maximize volume */
  207. ins->dac_volume_right = 0x8000;
  208. ins->dac_volume_left = 0x8000;
  209. ins->spdif_input_volume_right = 0x8000;
  210. ins->spdif_input_volume_left = 0x8000;
  211. /* set left and right validity bits and
  212. default channel status */
  213. ins->spdif_csuv_default =
  214. ins->spdif_csuv_stream =
  215. /* byte 0 */ ((unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF & 0xff)) << 24) |
  216. /* byte 1 */ ((unsigned int)_wrap_all_bits( ((SNDRV_PCM_DEFAULT_CON_SPDIF >> 8) & 0xff)) << 16) |
  217. /* byte 3 */ (unsigned int)_wrap_all_bits( (SNDRV_PCM_DEFAULT_CON_SPDIF >> 24) & 0xff) |
  218. /* left and right validity bits */ (1 << 13) | (1 << 12);
  219. return ins;
  220. error:
  221. kfree(ins->modules);
  222. kfree(ins->code.data);
  223. vfree(ins->symbol_table.symbols);
  224. kfree(ins);
  225. return NULL;
  226. }
  227. void cs46xx_dsp_spos_destroy (struct snd_cs46xx * chip)
  228. {
  229. int i;
  230. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  231. if (snd_BUG_ON(!ins))
  232. return;
  233. mutex_lock(&chip->spos_mutex);
  234. for (i = 0; i < ins->nscb; ++i) {
  235. if (ins->scbs[i].deleted) continue;
  236. cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
  237. #ifdef CONFIG_PM_SLEEP
  238. kfree(ins->scbs[i].data);
  239. #endif
  240. }
  241. kfree(ins->code.data);
  242. vfree(ins->symbol_table.symbols);
  243. kfree(ins->modules);
  244. kfree(ins);
  245. mutex_unlock(&chip->spos_mutex);
  246. }
  247. static int dsp_load_parameter(struct snd_cs46xx *chip,
  248. struct dsp_segment_desc *parameter)
  249. {
  250. u32 doffset, dsize;
  251. if (!parameter) {
  252. dev_dbg(chip->card->dev,
  253. "dsp_spos: module got no parameter segment\n");
  254. return 0;
  255. }
  256. doffset = (parameter->offset * 4 + DSP_PARAMETER_BYTE_OFFSET);
  257. dsize = parameter->size * 4;
  258. dev_dbg(chip->card->dev,
  259. "dsp_spos: downloading parameter data to chip (%08x-%08x)\n",
  260. doffset,doffset + dsize);
  261. if (snd_cs46xx_download (chip, parameter->data, doffset, dsize)) {
  262. dev_err(chip->card->dev,
  263. "dsp_spos: failed to download parameter data to DSP\n");
  264. return -EINVAL;
  265. }
  266. return 0;
  267. }
  268. static int dsp_load_sample(struct snd_cs46xx *chip,
  269. struct dsp_segment_desc *sample)
  270. {
  271. u32 doffset, dsize;
  272. if (!sample) {
  273. dev_dbg(chip->card->dev,
  274. "dsp_spos: module got no sample segment\n");
  275. return 0;
  276. }
  277. doffset = (sample->offset * 4 + DSP_SAMPLE_BYTE_OFFSET);
  278. dsize = sample->size * 4;
  279. dev_dbg(chip->card->dev,
  280. "dsp_spos: downloading sample data to chip (%08x-%08x)\n",
  281. doffset,doffset + dsize);
  282. if (snd_cs46xx_download (chip,sample->data,doffset,dsize)) {
  283. dev_err(chip->card->dev,
  284. "dsp_spos: failed to sample data to DSP\n");
  285. return -EINVAL;
  286. }
  287. return 0;
  288. }
  289. int cs46xx_dsp_load_module (struct snd_cs46xx * chip, struct dsp_module_desc * module)
  290. {
  291. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  292. struct dsp_segment_desc * code = get_segment_desc (module,SEGTYPE_SP_PROGRAM);
  293. u32 doffset, dsize;
  294. int err;
  295. if (ins->nmodules == DSP_MAX_MODULES - 1) {
  296. dev_err(chip->card->dev,
  297. "dsp_spos: to many modules loaded into DSP\n");
  298. return -ENOMEM;
  299. }
  300. dev_dbg(chip->card->dev,
  301. "dsp_spos: loading module %s into DSP\n", module->module_name);
  302. if (ins->nmodules == 0) {
  303. dev_dbg(chip->card->dev, "dsp_spos: clearing parameter area\n");
  304. snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET, DSP_PARAMETER_BYTE_SIZE);
  305. }
  306. err = dsp_load_parameter(chip, get_segment_desc(module,
  307. SEGTYPE_SP_PARAMETER));
  308. if (err < 0)
  309. return err;
  310. if (ins->nmodules == 0) {
  311. dev_dbg(chip->card->dev, "dsp_spos: clearing sample area\n");
  312. snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET, DSP_SAMPLE_BYTE_SIZE);
  313. }
  314. err = dsp_load_sample(chip, get_segment_desc(module,
  315. SEGTYPE_SP_SAMPLE));
  316. if (err < 0)
  317. return err;
  318. if (ins->nmodules == 0) {
  319. dev_dbg(chip->card->dev, "dsp_spos: clearing code area\n");
  320. snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
  321. }
  322. if (code == NULL) {
  323. dev_dbg(chip->card->dev,
  324. "dsp_spos: module got no code segment\n");
  325. } else {
  326. if (ins->code.offset + code->size > DSP_CODE_BYTE_SIZE) {
  327. dev_err(chip->card->dev,
  328. "dsp_spos: no space available in DSP\n");
  329. return -ENOMEM;
  330. }
  331. module->load_address = ins->code.offset;
  332. module->overlay_begin_address = 0x000;
  333. /* if module has a code segment it must have
  334. symbol table */
  335. if (snd_BUG_ON(!module->symbol_table.symbols))
  336. return -ENOMEM;
  337. if (add_symbols(chip,module)) {
  338. dev_err(chip->card->dev,
  339. "dsp_spos: failed to load symbol table\n");
  340. return -ENOMEM;
  341. }
  342. doffset = (code->offset * 4 + ins->code.offset * 4 + DSP_CODE_BYTE_OFFSET);
  343. dsize = code->size * 4;
  344. dev_dbg(chip->card->dev,
  345. "dsp_spos: downloading code to chip (%08x-%08x)\n",
  346. doffset,doffset + dsize);
  347. module->nfixups = shadow_and_reallocate_code(chip,code->data,code->size,module->overlay_begin_address);
  348. if (snd_cs46xx_download (chip,(ins->code.data + ins->code.offset),doffset,dsize)) {
  349. dev_err(chip->card->dev,
  350. "dsp_spos: failed to download code to DSP\n");
  351. return -EINVAL;
  352. }
  353. ins->code.offset += code->size;
  354. }
  355. /* NOTE: module segments and symbol table must be
  356. statically allocated. Case that module data is
  357. not generated by the ospparser */
  358. ins->modules[ins->nmodules] = *module;
  359. ins->nmodules++;
  360. return 0;
  361. }
  362. struct dsp_symbol_entry *
  363. cs46xx_dsp_lookup_symbol (struct snd_cs46xx * chip, char * symbol_name, int symbol_type)
  364. {
  365. int i;
  366. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  367. for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
  368. if (ins->symbol_table.symbols[i].deleted)
  369. continue;
  370. if (!strcmp(ins->symbol_table.symbols[i].symbol_name,symbol_name) &&
  371. ins->symbol_table.symbols[i].symbol_type == symbol_type) {
  372. return (ins->symbol_table.symbols + i);
  373. }
  374. }
  375. #if 0
  376. dev_err(chip->card->dev, "dsp_spos: symbol <%s> type %02x not found\n",
  377. symbol_name,symbol_type);
  378. #endif
  379. return NULL;
  380. }
  381. #ifdef CONFIG_SND_PROC_FS
  382. static struct dsp_symbol_entry *
  383. cs46xx_dsp_lookup_symbol_addr (struct snd_cs46xx * chip, u32 address, int symbol_type)
  384. {
  385. int i;
  386. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  387. for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
  388. if (ins->symbol_table.symbols[i].deleted)
  389. continue;
  390. if (ins->symbol_table.symbols[i].address == address &&
  391. ins->symbol_table.symbols[i].symbol_type == symbol_type) {
  392. return (ins->symbol_table.symbols + i);
  393. }
  394. }
  395. return NULL;
  396. }
  397. static void cs46xx_dsp_proc_symbol_table_read (struct snd_info_entry *entry,
  398. struct snd_info_buffer *buffer)
  399. {
  400. struct snd_cs46xx *chip = entry->private_data;
  401. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  402. int i;
  403. snd_iprintf(buffer, "SYMBOLS:\n");
  404. for ( i = 0; i < ins->symbol_table.nsymbols; ++i ) {
  405. char *module_str = "system";
  406. if (ins->symbol_table.symbols[i].deleted)
  407. continue;
  408. if (ins->symbol_table.symbols[i].module != NULL) {
  409. module_str = ins->symbol_table.symbols[i].module->module_name;
  410. }
  411. snd_iprintf(buffer, "%04X <%02X> %s [%s]\n",
  412. ins->symbol_table.symbols[i].address,
  413. ins->symbol_table.symbols[i].symbol_type,
  414. ins->symbol_table.symbols[i].symbol_name,
  415. module_str);
  416. }
  417. }
  418. static void cs46xx_dsp_proc_modules_read (struct snd_info_entry *entry,
  419. struct snd_info_buffer *buffer)
  420. {
  421. struct snd_cs46xx *chip = entry->private_data;
  422. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  423. int i,j;
  424. mutex_lock(&chip->spos_mutex);
  425. snd_iprintf(buffer, "MODULES:\n");
  426. for ( i = 0; i < ins->nmodules; ++i ) {
  427. snd_iprintf(buffer, "\n%s:\n", ins->modules[i].module_name);
  428. snd_iprintf(buffer, " %d symbols\n", ins->modules[i].symbol_table.nsymbols);
  429. snd_iprintf(buffer, " %d fixups\n", ins->modules[i].nfixups);
  430. for (j = 0; j < ins->modules[i].nsegments; ++ j) {
  431. struct dsp_segment_desc * desc = (ins->modules[i].segments + j);
  432. snd_iprintf(buffer, " segment %02x offset %08x size %08x\n",
  433. desc->segment_type,desc->offset, desc->size);
  434. }
  435. }
  436. mutex_unlock(&chip->spos_mutex);
  437. }
  438. static void cs46xx_dsp_proc_task_tree_read (struct snd_info_entry *entry,
  439. struct snd_info_buffer *buffer)
  440. {
  441. struct snd_cs46xx *chip = entry->private_data;
  442. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  443. int i, j, col;
  444. void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
  445. mutex_lock(&chip->spos_mutex);
  446. snd_iprintf(buffer, "TASK TREES:\n");
  447. for ( i = 0; i < ins->ntask; ++i) {
  448. snd_iprintf(buffer,"\n%04x %s:\n",ins->tasks[i].address,ins->tasks[i].task_name);
  449. for (col = 0,j = 0;j < ins->tasks[i].size; j++,col++) {
  450. u32 val;
  451. if (col == 4) {
  452. snd_iprintf(buffer,"\n");
  453. col = 0;
  454. }
  455. val = readl(dst + (ins->tasks[i].address + j) * sizeof(u32));
  456. snd_iprintf(buffer,"%08x ",val);
  457. }
  458. }
  459. snd_iprintf(buffer,"\n");
  460. mutex_unlock(&chip->spos_mutex);
  461. }
  462. static void cs46xx_dsp_proc_scb_read (struct snd_info_entry *entry,
  463. struct snd_info_buffer *buffer)
  464. {
  465. struct snd_cs46xx *chip = entry->private_data;
  466. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  467. int i;
  468. mutex_lock(&chip->spos_mutex);
  469. snd_iprintf(buffer, "SCB's:\n");
  470. for ( i = 0; i < ins->nscb; ++i) {
  471. if (ins->scbs[i].deleted)
  472. continue;
  473. snd_iprintf(buffer,"\n%04x %s:\n\n",ins->scbs[i].address,ins->scbs[i].scb_name);
  474. if (ins->scbs[i].parent_scb_ptr != NULL) {
  475. snd_iprintf(buffer,"parent [%s:%04x] ",
  476. ins->scbs[i].parent_scb_ptr->scb_name,
  477. ins->scbs[i].parent_scb_ptr->address);
  478. } else snd_iprintf(buffer,"parent [none] ");
  479. snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n",
  480. ins->scbs[i].sub_list_ptr->scb_name,
  481. ins->scbs[i].sub_list_ptr->address,
  482. ins->scbs[i].next_scb_ptr->scb_name,
  483. ins->scbs[i].next_scb_ptr->address,
  484. ins->scbs[i].task_entry->symbol_name,
  485. ins->scbs[i].task_entry->address);
  486. }
  487. snd_iprintf(buffer,"\n");
  488. mutex_unlock(&chip->spos_mutex);
  489. }
  490. static void cs46xx_dsp_proc_parameter_dump_read (struct snd_info_entry *entry,
  491. struct snd_info_buffer *buffer)
  492. {
  493. struct snd_cs46xx *chip = entry->private_data;
  494. /*struct dsp_spos_instance * ins = chip->dsp_spos_instance; */
  495. unsigned int i, col = 0;
  496. void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
  497. struct dsp_symbol_entry * symbol;
  498. for (i = 0;i < DSP_PARAMETER_BYTE_SIZE; i += sizeof(u32),col ++) {
  499. if (col == 4) {
  500. snd_iprintf(buffer,"\n");
  501. col = 0;
  502. }
  503. symbol = cs46xx_dsp_lookup_symbol_addr(chip, i / sizeof(u32), SYMBOL_PARAMETER);
  504. if (symbol) {
  505. col = 0;
  506. snd_iprintf (buffer,"\n%s:\n",symbol->symbol_name);
  507. }
  508. if (col == 0) {
  509. snd_iprintf(buffer, "%04X ", i / (unsigned int)sizeof(u32));
  510. }
  511. snd_iprintf(buffer,"%08X ",readl(dst + i));
  512. }
  513. }
  514. static void cs46xx_dsp_proc_sample_dump_read (struct snd_info_entry *entry,
  515. struct snd_info_buffer *buffer)
  516. {
  517. struct snd_cs46xx *chip = entry->private_data;
  518. int i,col = 0;
  519. void __iomem *dst = chip->region.idx[2].remap_addr;
  520. snd_iprintf(buffer,"PCMREADER:\n");
  521. for (i = PCM_READER_BUF1;i < PCM_READER_BUF1 + 0x30; i += sizeof(u32),col ++) {
  522. if (col == 4) {
  523. snd_iprintf(buffer,"\n");
  524. col = 0;
  525. }
  526. if (col == 0) {
  527. snd_iprintf(buffer, "%04X ",i);
  528. }
  529. snd_iprintf(buffer,"%08X ",readl(dst + i));
  530. }
  531. snd_iprintf(buffer,"\nMIX_SAMPLE_BUF1:\n");
  532. col = 0;
  533. for (i = MIX_SAMPLE_BUF1;i < MIX_SAMPLE_BUF1 + 0x40; i += sizeof(u32),col ++) {
  534. if (col == 4) {
  535. snd_iprintf(buffer,"\n");
  536. col = 0;
  537. }
  538. if (col == 0) {
  539. snd_iprintf(buffer, "%04X ",i);
  540. }
  541. snd_iprintf(buffer,"%08X ",readl(dst + i));
  542. }
  543. snd_iprintf(buffer,"\nSRC_TASK_SCB1:\n");
  544. col = 0;
  545. for (i = 0x2480 ; i < 0x2480 + 0x40 ; i += sizeof(u32),col ++) {
  546. if (col == 4) {
  547. snd_iprintf(buffer,"\n");
  548. col = 0;
  549. }
  550. if (col == 0) {
  551. snd_iprintf(buffer, "%04X ",i);
  552. }
  553. snd_iprintf(buffer,"%08X ",readl(dst + i));
  554. }
  555. snd_iprintf(buffer,"\nSPDIFO_BUFFER:\n");
  556. col = 0;
  557. for (i = SPDIFO_IP_OUTPUT_BUFFER1;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x30; i += sizeof(u32),col ++) {
  558. if (col == 4) {
  559. snd_iprintf(buffer,"\n");
  560. col = 0;
  561. }
  562. if (col == 0) {
  563. snd_iprintf(buffer, "%04X ",i);
  564. }
  565. snd_iprintf(buffer,"%08X ",readl(dst + i));
  566. }
  567. snd_iprintf(buffer,"\n...\n");
  568. col = 0;
  569. for (i = SPDIFO_IP_OUTPUT_BUFFER1+0xD0;i < SPDIFO_IP_OUTPUT_BUFFER1 + 0x110; i += sizeof(u32),col ++) {
  570. if (col == 4) {
  571. snd_iprintf(buffer,"\n");
  572. col = 0;
  573. }
  574. if (col == 0) {
  575. snd_iprintf(buffer, "%04X ",i);
  576. }
  577. snd_iprintf(buffer,"%08X ",readl(dst + i));
  578. }
  579. snd_iprintf(buffer,"\nOUTPUT_SNOOP:\n");
  580. col = 0;
  581. for (i = OUTPUT_SNOOP_BUFFER;i < OUTPUT_SNOOP_BUFFER + 0x40; i += sizeof(u32),col ++) {
  582. if (col == 4) {
  583. snd_iprintf(buffer,"\n");
  584. col = 0;
  585. }
  586. if (col == 0) {
  587. snd_iprintf(buffer, "%04X ",i);
  588. }
  589. snd_iprintf(buffer,"%08X ",readl(dst + i));
  590. }
  591. snd_iprintf(buffer,"\nCODEC_INPUT_BUF1: \n");
  592. col = 0;
  593. for (i = CODEC_INPUT_BUF1;i < CODEC_INPUT_BUF1 + 0x40; i += sizeof(u32),col ++) {
  594. if (col == 4) {
  595. snd_iprintf(buffer,"\n");
  596. col = 0;
  597. }
  598. if (col == 0) {
  599. snd_iprintf(buffer, "%04X ",i);
  600. }
  601. snd_iprintf(buffer,"%08X ",readl(dst + i));
  602. }
  603. #if 0
  604. snd_iprintf(buffer,"\nWRITE_BACK_BUF1: \n");
  605. col = 0;
  606. for (i = WRITE_BACK_BUF1;i < WRITE_BACK_BUF1 + 0x40; i += sizeof(u32),col ++) {
  607. if (col == 4) {
  608. snd_iprintf(buffer,"\n");
  609. col = 0;
  610. }
  611. if (col == 0) {
  612. snd_iprintf(buffer, "%04X ",i);
  613. }
  614. snd_iprintf(buffer,"%08X ",readl(dst + i));
  615. }
  616. #endif
  617. snd_iprintf(buffer,"\nSPDIFI_IP_OUTPUT_BUFFER1: \n");
  618. col = 0;
  619. for (i = SPDIFI_IP_OUTPUT_BUFFER1;i < SPDIFI_IP_OUTPUT_BUFFER1 + 0x80; i += sizeof(u32),col ++) {
  620. if (col == 4) {
  621. snd_iprintf(buffer,"\n");
  622. col = 0;
  623. }
  624. if (col == 0) {
  625. snd_iprintf(buffer, "%04X ",i);
  626. }
  627. snd_iprintf(buffer,"%08X ",readl(dst + i));
  628. }
  629. snd_iprintf(buffer,"\n");
  630. }
  631. int cs46xx_dsp_proc_init (struct snd_card *card, struct snd_cs46xx *chip)
  632. {
  633. struct snd_info_entry *entry;
  634. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  635. int i;
  636. ins->snd_card = card;
  637. entry = snd_info_create_card_entry(card, "dsp", card->proc_root);
  638. if (entry)
  639. entry->mode = S_IFDIR | 0555;
  640. ins->proc_dsp_dir = entry;
  641. if (!ins->proc_dsp_dir)
  642. return -ENOMEM;
  643. entry = snd_info_create_card_entry(card, "spos_symbols",
  644. ins->proc_dsp_dir);
  645. if (entry)
  646. snd_info_set_text_ops(entry, chip,
  647. cs46xx_dsp_proc_symbol_table_read);
  648. entry = snd_info_create_card_entry(card, "spos_modules",
  649. ins->proc_dsp_dir);
  650. if (entry)
  651. snd_info_set_text_ops(entry, chip,
  652. cs46xx_dsp_proc_modules_read);
  653. entry = snd_info_create_card_entry(card, "parameter",
  654. ins->proc_dsp_dir);
  655. if (entry)
  656. snd_info_set_text_ops(entry, chip,
  657. cs46xx_dsp_proc_parameter_dump_read);
  658. entry = snd_info_create_card_entry(card, "sample",
  659. ins->proc_dsp_dir);
  660. if (entry)
  661. snd_info_set_text_ops(entry, chip,
  662. cs46xx_dsp_proc_sample_dump_read);
  663. entry = snd_info_create_card_entry(card, "task_tree",
  664. ins->proc_dsp_dir);
  665. if (entry)
  666. snd_info_set_text_ops(entry, chip,
  667. cs46xx_dsp_proc_task_tree_read);
  668. entry = snd_info_create_card_entry(card, "scb_info",
  669. ins->proc_dsp_dir);
  670. if (entry)
  671. snd_info_set_text_ops(entry, chip,
  672. cs46xx_dsp_proc_scb_read);
  673. mutex_lock(&chip->spos_mutex);
  674. /* register/update SCB's entries on proc */
  675. for (i = 0; i < ins->nscb; ++i) {
  676. if (ins->scbs[i].deleted) continue;
  677. cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i));
  678. }
  679. mutex_unlock(&chip->spos_mutex);
  680. return 0;
  681. }
  682. int cs46xx_dsp_proc_done (struct snd_cs46xx *chip)
  683. {
  684. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  685. int i;
  686. if (!ins)
  687. return 0;
  688. mutex_lock(&chip->spos_mutex);
  689. for (i = 0; i < ins->nscb; ++i) {
  690. if (ins->scbs[i].deleted) continue;
  691. cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
  692. }
  693. mutex_unlock(&chip->spos_mutex);
  694. snd_info_free_entry(ins->proc_dsp_dir);
  695. ins->proc_dsp_dir = NULL;
  696. return 0;
  697. }
  698. #endif /* CONFIG_SND_PROC_FS */
  699. static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
  700. u32 dest, int size)
  701. {
  702. void __iomem *spdst = chip->region.idx[1].remap_addr +
  703. DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
  704. int i;
  705. for (i = 0; i < size; ++i) {
  706. dev_dbg(chip->card->dev, "addr %p, val %08x\n",
  707. spdst, task_data[i]);
  708. writel(task_data[i],spdst);
  709. spdst += sizeof(u32);
  710. }
  711. }
  712. static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
  713. {
  714. void __iomem *spdst = chip->region.idx[1].remap_addr +
  715. DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
  716. int i;
  717. for (i = 0; i < 0x10; ++i) {
  718. dev_dbg(chip->card->dev, "addr %p, val %08x\n",
  719. spdst, scb_data[i]);
  720. writel(scb_data[i],spdst);
  721. spdst += sizeof(u32);
  722. }
  723. }
  724. static int find_free_scb_index (struct dsp_spos_instance * ins)
  725. {
  726. int index = ins->nscb, i;
  727. for (i = ins->scb_highest_frag_index; i < ins->nscb; ++i) {
  728. if (ins->scbs[i].deleted) {
  729. index = i;
  730. break;
  731. }
  732. }
  733. return index;
  734. }
  735. static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * name, u32 dest)
  736. {
  737. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  738. struct dsp_scb_descriptor * desc = NULL;
  739. int index;
  740. if (ins->nscb == DSP_MAX_SCB_DESC - 1) {
  741. dev_err(chip->card->dev,
  742. "dsp_spos: got no place for other SCB\n");
  743. return NULL;
  744. }
  745. index = find_free_scb_index (ins);
  746. memset(&ins->scbs[index], 0, sizeof(ins->scbs[index]));
  747. strcpy(ins->scbs[index].scb_name, name);
  748. ins->scbs[index].address = dest;
  749. ins->scbs[index].index = index;
  750. ins->scbs[index].ref_count = 1;
  751. desc = (ins->scbs + index);
  752. ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);
  753. if (index > ins->scb_highest_frag_index)
  754. ins->scb_highest_frag_index = index;
  755. if (index == ins->nscb)
  756. ins->nscb++;
  757. return desc;
  758. }
  759. static struct dsp_task_descriptor *
  760. _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
  761. {
  762. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  763. struct dsp_task_descriptor * desc = NULL;
  764. if (ins->ntask == DSP_MAX_TASK_DESC - 1) {
  765. dev_err(chip->card->dev,
  766. "dsp_spos: got no place for other TASK\n");
  767. return NULL;
  768. }
  769. if (name)
  770. strcpy(ins->tasks[ins->ntask].task_name, name);
  771. else
  772. strcpy(ins->tasks[ins->ntask].task_name, "(NULL)");
  773. ins->tasks[ins->ntask].address = dest;
  774. ins->tasks[ins->ntask].size = size;
  775. /* quick find in list */
  776. ins->tasks[ins->ntask].index = ins->ntask;
  777. desc = (ins->tasks + ins->ntask);
  778. ins->ntask++;
  779. if (name)
  780. add_symbol (chip,name,dest,SYMBOL_PARAMETER);
  781. return desc;
  782. }
  783. #define SCB_BYTES (0x10 * 4)
  784. struct dsp_scb_descriptor *
  785. cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
  786. {
  787. struct dsp_scb_descriptor * desc;
  788. #ifdef CONFIG_PM_SLEEP
  789. /* copy the data for resume */
  790. scb_data = kmemdup(scb_data, SCB_BYTES, GFP_KERNEL);
  791. if (!scb_data)
  792. return NULL;
  793. #endif
  794. desc = _map_scb (chip,name,dest);
  795. if (desc) {
  796. desc->data = scb_data;
  797. _dsp_create_scb(chip,scb_data,dest);
  798. } else {
  799. dev_err(chip->card->dev, "dsp_spos: failed to map SCB\n");
  800. #ifdef CONFIG_PM_SLEEP
  801. kfree(scb_data);
  802. #endif
  803. }
  804. return desc;
  805. }
  806. static struct dsp_task_descriptor *
  807. cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_data,
  808. u32 dest, int size)
  809. {
  810. struct dsp_task_descriptor * desc;
  811. desc = _map_task_tree (chip,name,dest,size);
  812. if (desc) {
  813. desc->data = task_data;
  814. _dsp_create_task_tree(chip,task_data,dest,size);
  815. } else {
  816. dev_err(chip->card->dev, "dsp_spos: failed to map TASK\n");
  817. }
  818. return desc;
  819. }
  820. int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
  821. {
  822. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  823. struct dsp_symbol_entry * fg_task_tree_header_code;
  824. struct dsp_symbol_entry * task_tree_header_code;
  825. struct dsp_symbol_entry * task_tree_thread;
  826. struct dsp_symbol_entry * null_algorithm;
  827. struct dsp_symbol_entry * magic_snoop_task;
  828. struct dsp_scb_descriptor * timing_master_scb;
  829. struct dsp_scb_descriptor * codec_out_scb;
  830. struct dsp_scb_descriptor * codec_in_scb;
  831. struct dsp_scb_descriptor * src_task_scb;
  832. struct dsp_scb_descriptor * master_mix_scb;
  833. struct dsp_scb_descriptor * rear_mix_scb;
  834. struct dsp_scb_descriptor * record_mix_scb;
  835. struct dsp_scb_descriptor * write_back_scb;
  836. struct dsp_scb_descriptor * vari_decimate_scb;
  837. struct dsp_scb_descriptor * rear_codec_out_scb;
  838. struct dsp_scb_descriptor * clfe_codec_out_scb;
  839. struct dsp_scb_descriptor * magic_snoop_scb;
  840. int fifo_addr, fifo_span, valid_slots;
  841. static const struct dsp_spos_control_block sposcb = {
  842. /* 0 */ HFG_TREE_SCB,HFG_STACK,
  843. /* 1 */ SPOSCB_ADDR,BG_TREE_SCB_ADDR,
  844. /* 2 */ DSP_SPOS_DC,0,
  845. /* 3 */ DSP_SPOS_DC,DSP_SPOS_DC,
  846. /* 4 */ 0,0,
  847. /* 5 */ DSP_SPOS_UU,0,
  848. /* 6 */ FG_TASK_HEADER_ADDR,0,
  849. /* 7 */ 0,0,
  850. /* 8 */ DSP_SPOS_UU,DSP_SPOS_DC,
  851. /* 9 */ 0,
  852. /* A */ 0,HFG_FIRST_EXECUTE_MODE,
  853. /* B */ DSP_SPOS_UU,DSP_SPOS_UU,
  854. /* C */ DSP_SPOS_DC_DC,
  855. /* D */ DSP_SPOS_DC_DC,
  856. /* E */ DSP_SPOS_DC_DC,
  857. /* F */ DSP_SPOS_DC_DC
  858. };
  859. cs46xx_dsp_create_task_tree(chip, "sposCB", (u32 *)&sposcb, SPOSCB_ADDR, 0x10);
  860. null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE);
  861. if (null_algorithm == NULL) {
  862. dev_err(chip->card->dev,
  863. "dsp_spos: symbol NULLALGORITHM not found\n");
  864. return -EIO;
  865. }
  866. fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE);
  867. if (fg_task_tree_header_code == NULL) {
  868. dev_err(chip->card->dev,
  869. "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
  870. return -EIO;
  871. }
  872. task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE);
  873. if (task_tree_header_code == NULL) {
  874. dev_err(chip->card->dev,
  875. "dsp_spos: symbol TASKTREEHEADERCODE not found\n");
  876. return -EIO;
  877. }
  878. task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE);
  879. if (task_tree_thread == NULL) {
  880. dev_err(chip->card->dev,
  881. "dsp_spos: symbol TASKTREETHREAD not found\n");
  882. return -EIO;
  883. }
  884. magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE);
  885. if (magic_snoop_task == NULL) {
  886. dev_err(chip->card->dev,
  887. "dsp_spos: symbol MAGICSNOOPTASK not found\n");
  888. return -EIO;
  889. }
  890. {
  891. /* create the null SCB */
  892. static struct dsp_generic_scb null_scb = {
  893. { 0, 0, 0, 0 },
  894. { 0, 0, 0, 0, 0 },
  895. NULL_SCB_ADDR, NULL_SCB_ADDR,
  896. 0, 0, 0, 0, 0,
  897. {
  898. 0,0,
  899. 0,0,
  900. }
  901. };
  902. null_scb.entry_point = null_algorithm->address;
  903. ins->the_null_scb = cs46xx_dsp_create_scb(chip, "nullSCB", (u32 *)&null_scb, NULL_SCB_ADDR);
  904. ins->the_null_scb->task_entry = null_algorithm;
  905. ins->the_null_scb->sub_list_ptr = ins->the_null_scb;
  906. ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
  907. ins->the_null_scb->parent_scb_ptr = NULL;
  908. cs46xx_dsp_proc_register_scb_desc (chip,ins->the_null_scb);
  909. }
  910. {
  911. /* setup foreground task tree */
  912. static struct dsp_task_tree_control_block fg_task_tree_hdr = {
  913. { FG_TASK_HEADER_ADDR | (DSP_SPOS_DC << 0x10),
  914. DSP_SPOS_DC_DC,
  915. DSP_SPOS_DC_DC,
  916. 0x0000,DSP_SPOS_DC,
  917. DSP_SPOS_DC, DSP_SPOS_DC,
  918. DSP_SPOS_DC_DC,
  919. DSP_SPOS_DC_DC,
  920. DSP_SPOS_DC_DC,
  921. DSP_SPOS_DC,DSP_SPOS_DC },
  922. {
  923. BG_TREE_SCB_ADDR,TIMINGMASTER_SCB_ADDR,
  924. 0,
  925. FG_TASK_HEADER_ADDR + TCBData,
  926. },
  927. {
  928. 4,0,
  929. 1,0,
  930. 2,SPOSCB_ADDR + HFGFlags,
  931. 0,0,
  932. FG_TASK_HEADER_ADDR + TCBContextBlk,FG_STACK
  933. },
  934. {
  935. DSP_SPOS_DC,0,
  936. DSP_SPOS_DC,DSP_SPOS_DC,
  937. DSP_SPOS_DC,DSP_SPOS_DC,
  938. DSP_SPOS_DC,DSP_SPOS_DC,
  939. DSP_SPOS_DC,DSP_SPOS_DC,
  940. DSP_SPOS_DCDC,
  941. DSP_SPOS_UU,1,
  942. DSP_SPOS_DCDC,
  943. DSP_SPOS_DCDC,
  944. DSP_SPOS_DCDC,
  945. DSP_SPOS_DCDC,
  946. DSP_SPOS_DCDC,
  947. DSP_SPOS_DCDC,
  948. DSP_SPOS_DCDC,
  949. DSP_SPOS_DCDC,
  950. DSP_SPOS_DCDC,
  951. DSP_SPOS_DCDC,
  952. DSP_SPOS_DCDC,
  953. DSP_SPOS_DCDC,
  954. DSP_SPOS_DCDC,
  955. DSP_SPOS_DCDC,
  956. DSP_SPOS_DCDC,
  957. DSP_SPOS_DCDC,
  958. DSP_SPOS_DCDC,
  959. DSP_SPOS_DCDC,
  960. DSP_SPOS_DCDC,
  961. DSP_SPOS_DCDC,
  962. DSP_SPOS_DCDC,
  963. DSP_SPOS_DCDC,
  964. DSP_SPOS_DCDC,
  965. DSP_SPOS_DCDC,
  966. DSP_SPOS_DCDC,
  967. DSP_SPOS_DCDC,
  968. DSP_SPOS_DCDC,
  969. DSP_SPOS_DCDC
  970. },
  971. {
  972. FG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
  973. 0,0
  974. }
  975. };
  976. fg_task_tree_hdr.links.entry_point = fg_task_tree_header_code->address;
  977. fg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
  978. cs46xx_dsp_create_task_tree(chip,"FGtaskTreeHdr",(u32 *)&fg_task_tree_hdr,FG_TASK_HEADER_ADDR,0x35);
  979. }
  980. {
  981. /* setup foreground task tree */
  982. static struct dsp_task_tree_control_block bg_task_tree_hdr = {
  983. { DSP_SPOS_DC_DC,
  984. DSP_SPOS_DC_DC,
  985. DSP_SPOS_DC_DC,
  986. DSP_SPOS_DC, DSP_SPOS_DC,
  987. DSP_SPOS_DC, DSP_SPOS_DC,
  988. DSP_SPOS_DC_DC,
  989. DSP_SPOS_DC_DC,
  990. DSP_SPOS_DC_DC,
  991. DSP_SPOS_DC,DSP_SPOS_DC },
  992. {
  993. NULL_SCB_ADDR,NULL_SCB_ADDR, /* Set up the background to do nothing */
  994. 0,
  995. BG_TREE_SCB_ADDR + TCBData,
  996. },
  997. {
  998. 9999,0,
  999. 0,1,
  1000. 0,SPOSCB_ADDR + HFGFlags,
  1001. 0,0,
  1002. BG_TREE_SCB_ADDR + TCBContextBlk,BG_STACK
  1003. },
  1004. {
  1005. DSP_SPOS_DC,0,
  1006. DSP_SPOS_DC,DSP_SPOS_DC,
  1007. DSP_SPOS_DC,DSP_SPOS_DC,
  1008. DSP_SPOS_DC,DSP_SPOS_DC,
  1009. DSP_SPOS_DC,DSP_SPOS_DC,
  1010. DSP_SPOS_DCDC,
  1011. DSP_SPOS_UU,1,
  1012. DSP_SPOS_DCDC,
  1013. DSP_SPOS_DCDC,
  1014. DSP_SPOS_DCDC,
  1015. DSP_SPOS_DCDC,
  1016. DSP_SPOS_DCDC,
  1017. DSP_SPOS_DCDC,
  1018. DSP_SPOS_DCDC,
  1019. DSP_SPOS_DCDC,
  1020. DSP_SPOS_DCDC,
  1021. DSP_SPOS_DCDC,
  1022. DSP_SPOS_DCDC,
  1023. DSP_SPOS_DCDC,
  1024. DSP_SPOS_DCDC,
  1025. DSP_SPOS_DCDC,
  1026. DSP_SPOS_DCDC,
  1027. DSP_SPOS_DCDC,
  1028. DSP_SPOS_DCDC,
  1029. DSP_SPOS_DCDC,
  1030. DSP_SPOS_DCDC,
  1031. DSP_SPOS_DCDC,
  1032. DSP_SPOS_DCDC,
  1033. DSP_SPOS_DCDC,
  1034. DSP_SPOS_DCDC,
  1035. DSP_SPOS_DCDC,
  1036. DSP_SPOS_DCDC,
  1037. DSP_SPOS_DCDC,
  1038. DSP_SPOS_DCDC,
  1039. DSP_SPOS_DCDC
  1040. },
  1041. {
  1042. BG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
  1043. 0,0
  1044. }
  1045. };
  1046. bg_task_tree_hdr.links.entry_point = task_tree_header_code->address;
  1047. bg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
  1048. cs46xx_dsp_create_task_tree(chip,"BGtaskTreeHdr",(u32 *)&bg_task_tree_hdr,BG_TREE_SCB_ADDR,0x35);
  1049. }
  1050. /* create timing master SCB */
  1051. timing_master_scb = cs46xx_dsp_create_timing_master_scb(chip);
  1052. /* create the CODEC output task */
  1053. codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_I",0x0010,0x0000,
  1054. MASTERMIX_SCB_ADDR,
  1055. CODECOUT_SCB_ADDR,timing_master_scb,
  1056. SCB_ON_PARENT_SUBLIST_SCB);
  1057. if (!codec_out_scb) goto _fail_end;
  1058. /* create the master mix SCB */
  1059. master_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"MasterMixSCB",
  1060. MIX_SAMPLE_BUF1,MASTERMIX_SCB_ADDR,
  1061. codec_out_scb,
  1062. SCB_ON_PARENT_SUBLIST_SCB);
  1063. ins->master_mix_scb = master_mix_scb;
  1064. if (!master_mix_scb) goto _fail_end;
  1065. /* create codec in */
  1066. codec_in_scb = cs46xx_dsp_create_codec_in_scb(chip,"CodecInSCB",0x0010,0x00A0,
  1067. CODEC_INPUT_BUF1,
  1068. CODECIN_SCB_ADDR,codec_out_scb,
  1069. SCB_ON_PARENT_NEXT_SCB);
  1070. if (!codec_in_scb) goto _fail_end;
  1071. ins->codec_in_scb = codec_in_scb;
  1072. /* create write back scb */
  1073. write_back_scb = cs46xx_dsp_create_mix_to_ostream_scb(chip,"WriteBackSCB",
  1074. WRITE_BACK_BUF1,WRITE_BACK_SPB,
  1075. WRITEBACK_SCB_ADDR,
  1076. timing_master_scb,
  1077. SCB_ON_PARENT_NEXT_SCB);
  1078. if (!write_back_scb) goto _fail_end;
  1079. {
  1080. static struct dsp_mix2_ostream_spb mix2_ostream_spb = {
  1081. 0x00020000,
  1082. 0x0000ffff
  1083. };
  1084. if (!cs46xx_dsp_create_task_tree(chip, NULL,
  1085. (u32 *)&mix2_ostream_spb,
  1086. WRITE_BACK_SPB, 2))
  1087. goto _fail_end;
  1088. }
  1089. /* input sample converter */
  1090. vari_decimate_scb = cs46xx_dsp_create_vari_decimate_scb(chip,"VariDecimateSCB",
  1091. VARI_DECIMATE_BUF0,
  1092. VARI_DECIMATE_BUF1,
  1093. VARIDECIMATE_SCB_ADDR,
  1094. write_back_scb,
  1095. SCB_ON_PARENT_SUBLIST_SCB);
  1096. if (!vari_decimate_scb) goto _fail_end;
  1097. /* create the record mixer SCB */
  1098. record_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RecordMixerSCB",
  1099. MIX_SAMPLE_BUF2,
  1100. RECORD_MIXER_SCB_ADDR,
  1101. vari_decimate_scb,
  1102. SCB_ON_PARENT_SUBLIST_SCB);
  1103. ins->record_mixer_scb = record_mix_scb;
  1104. if (!record_mix_scb) goto _fail_end;
  1105. valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);
  1106. if (snd_BUG_ON(chip->nr_ac97_codecs != 1 && chip->nr_ac97_codecs != 2))
  1107. goto _fail_end;
  1108. if (chip->nr_ac97_codecs == 1) {
  1109. /* output on slot 5 and 11
  1110. on primary CODEC */
  1111. fifo_addr = 0x20;
  1112. fifo_span = 0x60;
  1113. /* enable slot 5 and 11 */
  1114. valid_slots |= ACOSV_SLV5 | ACOSV_SLV11;
  1115. } else {
  1116. /* output on slot 7 and 8
  1117. on secondary CODEC */
  1118. fifo_addr = 0x40;
  1119. fifo_span = 0x10;
  1120. /* enable slot 7 and 8 */
  1121. valid_slots |= ACOSV_SLV7 | ACOSV_SLV8;
  1122. }
  1123. /* create CODEC tasklet for rear speakers output*/
  1124. rear_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_Rear",fifo_span,fifo_addr,
  1125. REAR_MIXER_SCB_ADDR,
  1126. REAR_CODECOUT_SCB_ADDR,codec_in_scb,
  1127. SCB_ON_PARENT_NEXT_SCB);
  1128. if (!rear_codec_out_scb) goto _fail_end;
  1129. /* create the rear PCM channel mixer SCB */
  1130. rear_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RearMixerSCB",
  1131. MIX_SAMPLE_BUF3,
  1132. REAR_MIXER_SCB_ADDR,
  1133. rear_codec_out_scb,
  1134. SCB_ON_PARENT_SUBLIST_SCB);
  1135. ins->rear_mix_scb = rear_mix_scb;
  1136. if (!rear_mix_scb) goto _fail_end;
  1137. if (chip->nr_ac97_codecs == 2) {
  1138. /* create CODEC tasklet for rear Center/LFE output
  1139. slot 6 and 9 on secondary CODEC */
  1140. clfe_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_CLFE",0x0030,0x0030,
  1141. CLFE_MIXER_SCB_ADDR,
  1142. CLFE_CODEC_SCB_ADDR,
  1143. rear_codec_out_scb,
  1144. SCB_ON_PARENT_NEXT_SCB);
  1145. if (!clfe_codec_out_scb) goto _fail_end;
  1146. /* create the rear PCM channel mixer SCB */
  1147. ins->center_lfe_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"CLFEMixerSCB",
  1148. MIX_SAMPLE_BUF4,
  1149. CLFE_MIXER_SCB_ADDR,
  1150. clfe_codec_out_scb,
  1151. SCB_ON_PARENT_SUBLIST_SCB);
  1152. if (!ins->center_lfe_mix_scb) goto _fail_end;
  1153. /* enable slot 6 and 9 */
  1154. valid_slots |= ACOSV_SLV6 | ACOSV_SLV9;
  1155. } else {
  1156. clfe_codec_out_scb = rear_codec_out_scb;
  1157. ins->center_lfe_mix_scb = rear_mix_scb;
  1158. }
  1159. /* enable slots depending on CODEC configuration */
  1160. snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots);
  1161. /* the magic snooper */
  1162. magic_snoop_scb = cs46xx_dsp_create_magic_snoop_scb (chip,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR,
  1163. OUTPUT_SNOOP_BUFFER,
  1164. codec_out_scb,
  1165. clfe_codec_out_scb,
  1166. SCB_ON_PARENT_NEXT_SCB);
  1167. if (!magic_snoop_scb) goto _fail_end;
  1168. ins->ref_snoop_scb = magic_snoop_scb;
  1169. /* SP IO access */
  1170. if (!cs46xx_dsp_create_spio_write_scb(chip,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR,
  1171. magic_snoop_scb,
  1172. SCB_ON_PARENT_NEXT_SCB))
  1173. goto _fail_end;
  1174. /* SPDIF input sampel rate converter */
  1175. src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI",
  1176. ins->spdif_in_sample_rate,
  1177. SRC_OUTPUT_BUF1,
  1178. SRC_DELAY_BUF1,SRCTASK_SCB_ADDR,
  1179. master_mix_scb,
  1180. SCB_ON_PARENT_SUBLIST_SCB,1);
  1181. if (!src_task_scb) goto _fail_end;
  1182. cs46xx_src_unlink(chip,src_task_scb);
  1183. /* NOTE: when we now how to detect the SPDIF input
  1184. sample rate we will use this SRC to adjust it */
  1185. ins->spdif_in_src = src_task_scb;
  1186. cs46xx_dsp_async_init(chip,timing_master_scb);
  1187. return 0;
  1188. _fail_end:
  1189. dev_err(chip->card->dev, "dsp_spos: failed to setup SCB's in DSP\n");
  1190. return -EINVAL;
  1191. }
  1192. static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
  1193. struct dsp_scb_descriptor * fg_entry)
  1194. {
  1195. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1196. struct dsp_symbol_entry * s16_async_codec_input_task;
  1197. struct dsp_symbol_entry * spdifo_task;
  1198. struct dsp_symbol_entry * spdifi_task;
  1199. struct dsp_scb_descriptor * spdifi_scb_desc, * spdifo_scb_desc, * async_codec_scb_desc;
  1200. s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE);
  1201. if (s16_async_codec_input_task == NULL) {
  1202. dev_err(chip->card->dev,
  1203. "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
  1204. return -EIO;
  1205. }
  1206. spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE);
  1207. if (spdifo_task == NULL) {
  1208. dev_err(chip->card->dev,
  1209. "dsp_spos: symbol SPDIFOTASK not found\n");
  1210. return -EIO;
  1211. }
  1212. spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE);
  1213. if (spdifi_task == NULL) {
  1214. dev_err(chip->card->dev,
  1215. "dsp_spos: symbol SPDIFITASK not found\n");
  1216. return -EIO;
  1217. }
  1218. {
  1219. /* 0xBC0 */
  1220. struct dsp_spdifoscb spdifo_scb = {
  1221. /* 0 */ DSP_SPOS_UUUU,
  1222. {
  1223. /* 1 */ 0xb0,
  1224. /* 2 */ 0,
  1225. /* 3 */ 0,
  1226. /* 4 */ 0,
  1227. },
  1228. /* NOTE: the SPDIF output task read samples in mono
  1229. format, the AsynchFGTxSCB task writes to buffer
  1230. in stereo format
  1231. */
  1232. /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_256,
  1233. /* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1 << 0x10 ) | 0xFFFC,
  1234. /* 7 */ 0,0,
  1235. /* 8 */ 0,
  1236. /* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR,
  1237. /* A */ spdifo_task->address,
  1238. SPDIFO_SCB_INST + SPDIFOFIFOPointer,
  1239. {
  1240. /* B */ 0x0040, /*DSP_SPOS_UUUU,*/
  1241. /* C */ 0x20ff, /*DSP_SPOS_UUUU,*/
  1242. },
  1243. /* D */ 0x804c,0, /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */
  1244. /* E */ 0x0108,0x0001, /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
  1245. /* F */ DSP_SPOS_UUUU /* SPDIFOFree; */
  1246. };
  1247. /* 0xBB0 */
  1248. struct dsp_spdifiscb spdifi_scb = {
  1249. /* 0 */ DSP_SPOS_UULO,DSP_SPOS_UUHI,
  1250. /* 1 */ 0,
  1251. /* 2 */ 0,
  1252. /* 3 */ 1,4000, /* SPDIFICountLimit SPDIFICount */
  1253. /* 4 */ DSP_SPOS_UUUU, /* SPDIFIStatusData */
  1254. /* 5 */ 0,DSP_SPOS_UUHI, /* StatusData, Free4 */
  1255. /* 6 */ DSP_SPOS_UUUU, /* Free3 */
  1256. /* 7 */ DSP_SPOS_UU,DSP_SPOS_DC, /* Free2 BitCount*/
  1257. /* 8 */ DSP_SPOS_UUUU, /* TempStatus */
  1258. /* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR,
  1259. /* A */ spdifi_task->address,
  1260. SPDIFI_SCB_INST + SPDIFIFIFOPointer,
  1261. /* NOTE: The SPDIF input task write the sample in mono
  1262. format from the HW FIFO, the AsynchFGRxSCB task reads
  1263. them in stereo
  1264. */
  1265. /* B */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_128,
  1266. /* C */ (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
  1267. /* D */ 0x8048,0,
  1268. /* E */ 0x01f0,0x0001,
  1269. /* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */
  1270. };
  1271. /* 0xBA0 */
  1272. struct dsp_async_codec_input_scb async_codec_input_scb = {
  1273. /* 0 */ DSP_SPOS_UUUU,
  1274. /* 1 */ 0,
  1275. /* 2 */ 0,
  1276. /* 3 */ 1,4000,
  1277. /* 4 */ 0x0118,0x0001,
  1278. /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_64,
  1279. /* 6 */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
  1280. /* 7 */ DSP_SPOS_UU,0x3,
  1281. /* 8 */ DSP_SPOS_UUUU,
  1282. /* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR,
  1283. /* A */ s16_async_codec_input_task->address,
  1284. HFG_TREE_SCB + AsyncCIOFIFOPointer,
  1285. /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
  1286. /* C */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10), /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/
  1287. #ifdef UseASER1Input
  1288. /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
  1289. Init. 0000:8042: for ASER1
  1290. 0000:8044: for ASER2 */
  1291. /* D */ 0x8042,0,
  1292. /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
  1293. Init 1 stero:8050 ASER1
  1294. Init 0 mono:8070 ASER2
  1295. Init 1 Stereo : 0100 ASER1 (Set by script) */
  1296. /* E */ 0x0100,0x0001,
  1297. #endif
  1298. #ifdef UseASER2Input
  1299. /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
  1300. Init. 0000:8042: for ASER1
  1301. 0000:8044: for ASER2 */
  1302. /* D */ 0x8044,0,
  1303. /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
  1304. Init 1 stero:8050 ASER1
  1305. Init 0 mono:8070 ASER2
  1306. Init 1 Stereo : 0100 ASER1 (Set by script) */
  1307. /* E */ 0x0110,0x0001,
  1308. #endif
  1309. /* short AsyncCIOutputBufModulo:AsyncCIFree;
  1310. AsyncCIOutputBufModulo: The modulo size for
  1311. the output buffer of this task */
  1312. /* F */ 0, /* DSP_SPOS_UUUU */
  1313. };
  1314. spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);
  1315. if (snd_BUG_ON(!spdifo_scb_desc))
  1316. return -EIO;
  1317. spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST);
  1318. if (snd_BUG_ON(!spdifi_scb_desc))
  1319. return -EIO;
  1320. async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB);
  1321. if (snd_BUG_ON(!async_codec_scb_desc))
  1322. return -EIO;
  1323. async_codec_scb_desc->parent_scb_ptr = NULL;
  1324. async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc;
  1325. async_codec_scb_desc->sub_list_ptr = ins->the_null_scb;
  1326. async_codec_scb_desc->task_entry = s16_async_codec_input_task;
  1327. spdifi_scb_desc->parent_scb_ptr = async_codec_scb_desc;
  1328. spdifi_scb_desc->next_scb_ptr = spdifo_scb_desc;
  1329. spdifi_scb_desc->sub_list_ptr = ins->the_null_scb;
  1330. spdifi_scb_desc->task_entry = spdifi_task;
  1331. spdifo_scb_desc->parent_scb_ptr = spdifi_scb_desc;
  1332. spdifo_scb_desc->next_scb_ptr = fg_entry;
  1333. spdifo_scb_desc->sub_list_ptr = ins->the_null_scb;
  1334. spdifo_scb_desc->task_entry = spdifo_task;
  1335. /* this one is faked, as the parnet of SPDIFO task
  1336. is the FG task tree */
  1337. fg_entry->parent_scb_ptr = spdifo_scb_desc;
  1338. /* for proc fs */
  1339. cs46xx_dsp_proc_register_scb_desc (chip,spdifo_scb_desc);
  1340. cs46xx_dsp_proc_register_scb_desc (chip,spdifi_scb_desc);
  1341. cs46xx_dsp_proc_register_scb_desc (chip,async_codec_scb_desc);
  1342. /* Async MASTER ENABLE, affects both SPDIF input and output */
  1343. snd_cs46xx_pokeBA0(chip, BA0_ASER_MASTER, 0x1 );
  1344. }
  1345. return 0;
  1346. }
  1347. static void cs46xx_dsp_disable_spdif_hw (struct snd_cs46xx *chip)
  1348. {
  1349. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1350. /* set SPDIF output FIFO slot */
  1351. snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, 0);
  1352. /* SPDIF output MASTER ENABLE */
  1353. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0);
  1354. /* right and left validate bit */
  1355. /*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/
  1356. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x0);
  1357. /* clear fifo pointer */
  1358. cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);
  1359. /* monitor state */
  1360. ins->spdif_status_out &= ~DSP_SPDIF_STATUS_HW_ENABLED;
  1361. }
  1362. int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip)
  1363. {
  1364. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1365. /* if hw-ctrl already enabled, turn off to reset logic ... */
  1366. cs46xx_dsp_disable_spdif_hw (chip);
  1367. udelay(50);
  1368. /* set SPDIF output FIFO slot */
  1369. snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, ( 0x8000 | ((SP_SPDOUT_FIFO >> 4) << 4) ));
  1370. /* SPDIF output MASTER ENABLE */
  1371. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000);
  1372. /* right and left validate bit */
  1373. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
  1374. /* monitor state */
  1375. ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED;
  1376. return 0;
  1377. }
  1378. int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)
  1379. {
  1380. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1381. /* turn on amplifier */
  1382. chip->active_ctrl(chip, 1);
  1383. chip->amplifier_ctrl(chip, 1);
  1384. if (snd_BUG_ON(ins->asynch_rx_scb))
  1385. return -EINVAL;
  1386. if (snd_BUG_ON(!ins->spdif_in_src))
  1387. return -EINVAL;
  1388. mutex_lock(&chip->spos_mutex);
  1389. if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) {
  1390. /* time countdown enable */
  1391. cs46xx_poke_via_dsp (chip,SP_ASER_COUNTDOWN, 0x80000005);
  1392. /* NOTE: 80000005 value is just magic. With all values
  1393. that I've tested this one seem to give the best result.
  1394. Got no explication why. (Benny) */
  1395. /* SPDIF input MASTER ENABLE */
  1396. cs46xx_poke_via_dsp (chip,SP_SPDIN_CONTROL, 0x800003ff);
  1397. ins->spdif_status_out |= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED;
  1398. }
  1399. /* create and start the asynchronous receiver SCB */
  1400. ins->asynch_rx_scb = cs46xx_dsp_create_asynch_fg_rx_scb(chip,"AsynchFGRxSCB",
  1401. ASYNCRX_SCB_ADDR,
  1402. SPDIFI_SCB_INST,
  1403. SPDIFI_IP_OUTPUT_BUFFER1,
  1404. ins->spdif_in_src,
  1405. SCB_ON_PARENT_SUBLIST_SCB);
  1406. spin_lock_irq(&chip->reg_lock);
  1407. /* reset SPDIF input sample buffer pointer */
  1408. /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
  1409. (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/
  1410. /* reset FIFO ptr */
  1411. /*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/
  1412. cs46xx_src_link(chip,ins->spdif_in_src);
  1413. /* unmute SRC volume */
  1414. cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff);
  1415. spin_unlock_irq(&chip->reg_lock);
  1416. /* set SPDIF input sample rate and unmute
  1417. NOTE: only 48khz support for SPDIF input this time */
  1418. /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
  1419. /* monitor state */
  1420. ins->spdif_status_in = 1;
  1421. mutex_unlock(&chip->spos_mutex);
  1422. return 0;
  1423. }
  1424. int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip)
  1425. {
  1426. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1427. if (snd_BUG_ON(!ins->asynch_rx_scb))
  1428. return -EINVAL;
  1429. if (snd_BUG_ON(!ins->spdif_in_src))
  1430. return -EINVAL;
  1431. mutex_lock(&chip->spos_mutex);
  1432. /* Remove the asynchronous receiver SCB */
  1433. cs46xx_dsp_remove_scb (chip,ins->asynch_rx_scb);
  1434. ins->asynch_rx_scb = NULL;
  1435. cs46xx_src_unlink(chip,ins->spdif_in_src);
  1436. /* monitor state */
  1437. ins->spdif_status_in = 0;
  1438. mutex_unlock(&chip->spos_mutex);
  1439. /* restore amplifier */
  1440. chip->active_ctrl(chip, -1);
  1441. chip->amplifier_ctrl(chip, -1);
  1442. return 0;
  1443. }
  1444. int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip)
  1445. {
  1446. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1447. if (snd_BUG_ON(ins->pcm_input))
  1448. return -EINVAL;
  1449. if (snd_BUG_ON(!ins->ref_snoop_scb))
  1450. return -EINVAL;
  1451. mutex_lock(&chip->spos_mutex);
  1452. ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
  1453. "PCMSerialInput_Wave");
  1454. mutex_unlock(&chip->spos_mutex);
  1455. return 0;
  1456. }
  1457. int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip)
  1458. {
  1459. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1460. if (snd_BUG_ON(!ins->pcm_input))
  1461. return -EINVAL;
  1462. mutex_lock(&chip->spos_mutex);
  1463. cs46xx_dsp_remove_scb (chip,ins->pcm_input);
  1464. ins->pcm_input = NULL;
  1465. mutex_unlock(&chip->spos_mutex);
  1466. return 0;
  1467. }
  1468. int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip)
  1469. {
  1470. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1471. if (snd_BUG_ON(ins->adc_input))
  1472. return -EINVAL;
  1473. if (snd_BUG_ON(!ins->codec_in_scb))
  1474. return -EINVAL;
  1475. mutex_lock(&chip->spos_mutex);
  1476. ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
  1477. "PCMSerialInput_ADC");
  1478. mutex_unlock(&chip->spos_mutex);
  1479. return 0;
  1480. }
  1481. int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip)
  1482. {
  1483. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1484. if (snd_BUG_ON(!ins->adc_input))
  1485. return -EINVAL;
  1486. mutex_lock(&chip->spos_mutex);
  1487. cs46xx_dsp_remove_scb (chip,ins->adc_input);
  1488. ins->adc_input = NULL;
  1489. mutex_unlock(&chip->spos_mutex);
  1490. return 0;
  1491. }
  1492. int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data)
  1493. {
  1494. u32 temp;
  1495. int i;
  1496. /* santiy check the parameters. (These numbers are not 100% correct. They are
  1497. a rough guess from looking at the controller spec.) */
  1498. if (address < 0x8000 || address >= 0x9000)
  1499. return -EINVAL;
  1500. /* initialize the SP_IO_WRITE SCB with the data. */
  1501. temp = ( address << 16 ) | ( address & 0x0000FFFF); /* offset 0 <-- address2 : address1 */
  1502. snd_cs46xx_poke(chip,( SPIOWRITE_SCB_ADDR << 2), temp);
  1503. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 1) << 2), data); /* offset 1 <-- data1 */
  1504. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 2) << 2), data); /* offset 1 <-- data2 */
  1505. /* Poke this location to tell the task to start */
  1506. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 6) << 2), SPIOWRITE_SCB_ADDR << 0x10);
  1507. /* Verify that the task ran */
  1508. for (i=0; i<25; i++) {
  1509. udelay(125);
  1510. temp = snd_cs46xx_peek(chip,((SPIOWRITE_SCB_ADDR + 6) << 2));
  1511. if (temp == 0x00000000)
  1512. break;
  1513. }
  1514. if (i == 25) {
  1515. dev_err(chip->card->dev,
  1516. "dsp_spos: SPIOWriteTask not responding\n");
  1517. return -EBUSY;
  1518. }
  1519. return 0;
  1520. }
  1521. int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right)
  1522. {
  1523. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1524. struct dsp_scb_descriptor * scb;
  1525. mutex_lock(&chip->spos_mutex);
  1526. /* main output */
  1527. scb = ins->master_mix_scb->sub_list_ptr;
  1528. while (scb != ins->the_null_scb) {
  1529. cs46xx_dsp_scb_set_volume (chip,scb,left,right);
  1530. scb = scb->next_scb_ptr;
  1531. }
  1532. /* rear output */
  1533. scb = ins->rear_mix_scb->sub_list_ptr;
  1534. while (scb != ins->the_null_scb) {
  1535. cs46xx_dsp_scb_set_volume (chip,scb,left,right);
  1536. scb = scb->next_scb_ptr;
  1537. }
  1538. ins->dac_volume_left = left;
  1539. ins->dac_volume_right = right;
  1540. mutex_unlock(&chip->spos_mutex);
  1541. return 0;
  1542. }
  1543. int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right)
  1544. {
  1545. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1546. mutex_lock(&chip->spos_mutex);
  1547. if (ins->asynch_rx_scb != NULL)
  1548. cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb,
  1549. left,right);
  1550. ins->spdif_input_volume_left = left;
  1551. ins->spdif_input_volume_right = right;
  1552. mutex_unlock(&chip->spos_mutex);
  1553. return 0;
  1554. }
  1555. #ifdef CONFIG_PM_SLEEP
  1556. int cs46xx_dsp_resume(struct snd_cs46xx * chip)
  1557. {
  1558. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1559. int i, err;
  1560. /* clear parameter, sample and code areas */
  1561. snd_cs46xx_clear_BA1(chip, DSP_PARAMETER_BYTE_OFFSET,
  1562. DSP_PARAMETER_BYTE_SIZE);
  1563. snd_cs46xx_clear_BA1(chip, DSP_SAMPLE_BYTE_OFFSET,
  1564. DSP_SAMPLE_BYTE_SIZE);
  1565. snd_cs46xx_clear_BA1(chip, DSP_CODE_BYTE_OFFSET, DSP_CODE_BYTE_SIZE);
  1566. for (i = 0; i < ins->nmodules; i++) {
  1567. struct dsp_module_desc *module = &ins->modules[i];
  1568. struct dsp_segment_desc *seg;
  1569. u32 doffset, dsize;
  1570. seg = get_segment_desc(module, SEGTYPE_SP_PARAMETER);
  1571. err = dsp_load_parameter(chip, seg);
  1572. if (err < 0)
  1573. return err;
  1574. seg = get_segment_desc(module, SEGTYPE_SP_SAMPLE);
  1575. err = dsp_load_sample(chip, seg);
  1576. if (err < 0)
  1577. return err;
  1578. seg = get_segment_desc(module, SEGTYPE_SP_PROGRAM);
  1579. if (!seg)
  1580. continue;
  1581. doffset = seg->offset * 4 + module->load_address * 4
  1582. + DSP_CODE_BYTE_OFFSET;
  1583. dsize = seg->size * 4;
  1584. err = snd_cs46xx_download(chip,
  1585. ins->code.data + module->load_address,
  1586. doffset, dsize);
  1587. if (err < 0)
  1588. return err;
  1589. }
  1590. for (i = 0; i < ins->ntask; i++) {
  1591. struct dsp_task_descriptor *t = &ins->tasks[i];
  1592. _dsp_create_task_tree(chip, t->data, t->address, t->size);
  1593. }
  1594. for (i = 0; i < ins->nscb; i++) {
  1595. struct dsp_scb_descriptor *s = &ins->scbs[i];
  1596. if (s->deleted)
  1597. continue;
  1598. _dsp_create_scb(chip, s->data, s->address);
  1599. }
  1600. for (i = 0; i < ins->nscb; i++) {
  1601. struct dsp_scb_descriptor *s = &ins->scbs[i];
  1602. if (s->deleted)
  1603. continue;
  1604. if (s->updated)
  1605. cs46xx_dsp_spos_update_scb(chip, s);
  1606. if (s->volume_set)
  1607. cs46xx_dsp_scb_set_volume(chip, s,
  1608. s->volume[0], s->volume[1]);
  1609. }
  1610. if (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) {
  1611. cs46xx_dsp_enable_spdif_hw(chip);
  1612. snd_cs46xx_poke(chip, (ins->ref_snoop_scb->address + 2) << 2,
  1613. (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10);
  1614. if (ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN)
  1615. cs46xx_poke_via_dsp(chip, SP_SPDOUT_CSUV,
  1616. ins->spdif_csuv_stream);
  1617. }
  1618. if (chip->dsp_spos_instance->spdif_status_in) {
  1619. cs46xx_poke_via_dsp(chip, SP_ASER_COUNTDOWN, 0x80000005);
  1620. cs46xx_poke_via_dsp(chip, SP_SPDIN_CONTROL, 0x800003ff);
  1621. }
  1622. return 0;
  1623. }
  1624. #endif