dsp_spos.c 53 KB

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