dsp_spos.c 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918
  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. entry->c.text.read_size = 512;
  614. if (snd_info_register(entry) < 0) {
  615. snd_info_free_entry(entry);
  616. entry = NULL;
  617. }
  618. }
  619. ins->proc_dsp_dir = entry;
  620. if (!ins->proc_dsp_dir)
  621. return -ENOMEM;
  622. if ((entry = snd_info_create_card_entry(card, "spos_symbols", ins->proc_dsp_dir)) != NULL) {
  623. entry->content = SNDRV_INFO_CONTENT_TEXT;
  624. entry->private_data = chip;
  625. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  626. entry->c.text.read_size = 512;
  627. entry->c.text.read = cs46xx_dsp_proc_symbol_table_read;
  628. if (snd_info_register(entry) < 0) {
  629. snd_info_free_entry(entry);
  630. entry = NULL;
  631. }
  632. }
  633. ins->proc_sym_info_entry = entry;
  634. if ((entry = snd_info_create_card_entry(card, "spos_modules", ins->proc_dsp_dir)) != NULL) {
  635. entry->content = SNDRV_INFO_CONTENT_TEXT;
  636. entry->private_data = chip;
  637. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  638. entry->c.text.read_size = 512;
  639. entry->c.text.read = cs46xx_dsp_proc_modules_read;
  640. if (snd_info_register(entry) < 0) {
  641. snd_info_free_entry(entry);
  642. entry = NULL;
  643. }
  644. }
  645. ins->proc_modules_info_entry = entry;
  646. if ((entry = snd_info_create_card_entry(card, "parameter", ins->proc_dsp_dir)) != NULL) {
  647. entry->content = SNDRV_INFO_CONTENT_TEXT;
  648. entry->private_data = chip;
  649. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  650. entry->c.text.read_size = 512;
  651. entry->c.text.read = cs46xx_dsp_proc_parameter_dump_read;
  652. if (snd_info_register(entry) < 0) {
  653. snd_info_free_entry(entry);
  654. entry = NULL;
  655. }
  656. }
  657. ins->proc_parameter_dump_info_entry = entry;
  658. if ((entry = snd_info_create_card_entry(card, "sample", ins->proc_dsp_dir)) != NULL) {
  659. entry->content = SNDRV_INFO_CONTENT_TEXT;
  660. entry->private_data = chip;
  661. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  662. entry->c.text.read_size = 512;
  663. entry->c.text.read = cs46xx_dsp_proc_sample_dump_read;
  664. if (snd_info_register(entry) < 0) {
  665. snd_info_free_entry(entry);
  666. entry = NULL;
  667. }
  668. }
  669. ins->proc_sample_dump_info_entry = entry;
  670. if ((entry = snd_info_create_card_entry(card, "task_tree", ins->proc_dsp_dir)) != NULL) {
  671. entry->content = SNDRV_INFO_CONTENT_TEXT;
  672. entry->private_data = chip;
  673. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  674. entry->c.text.read_size = 512;
  675. entry->c.text.read = cs46xx_dsp_proc_task_tree_read;
  676. if (snd_info_register(entry) < 0) {
  677. snd_info_free_entry(entry);
  678. entry = NULL;
  679. }
  680. }
  681. ins->proc_task_info_entry = entry;
  682. if ((entry = snd_info_create_card_entry(card, "scb_info", ins->proc_dsp_dir)) != NULL) {
  683. entry->content = SNDRV_INFO_CONTENT_TEXT;
  684. entry->private_data = chip;
  685. entry->mode = S_IFREG | S_IRUGO | S_IWUSR;
  686. entry->c.text.read_size = 1024;
  687. entry->c.text.read = cs46xx_dsp_proc_scb_read;
  688. if (snd_info_register(entry) < 0) {
  689. snd_info_free_entry(entry);
  690. entry = NULL;
  691. }
  692. }
  693. ins->proc_scb_info_entry = entry;
  694. mutex_lock(&chip->spos_mutex);
  695. /* register/update SCB's entries on proc */
  696. for (i = 0; i < ins->nscb; ++i) {
  697. if (ins->scbs[i].deleted) continue;
  698. cs46xx_dsp_proc_register_scb_desc (chip, (ins->scbs + i));
  699. }
  700. mutex_unlock(&chip->spos_mutex);
  701. return 0;
  702. }
  703. int cs46xx_dsp_proc_done (struct snd_cs46xx *chip)
  704. {
  705. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  706. int i;
  707. if (ins->proc_sym_info_entry) {
  708. snd_info_unregister(ins->proc_sym_info_entry);
  709. ins->proc_sym_info_entry = NULL;
  710. }
  711. if (ins->proc_modules_info_entry) {
  712. snd_info_unregister(ins->proc_modules_info_entry);
  713. ins->proc_modules_info_entry = NULL;
  714. }
  715. if (ins->proc_parameter_dump_info_entry) {
  716. snd_info_unregister(ins->proc_parameter_dump_info_entry);
  717. ins->proc_parameter_dump_info_entry = NULL;
  718. }
  719. if (ins->proc_sample_dump_info_entry) {
  720. snd_info_unregister(ins->proc_sample_dump_info_entry);
  721. ins->proc_sample_dump_info_entry = NULL;
  722. }
  723. if (ins->proc_scb_info_entry) {
  724. snd_info_unregister(ins->proc_scb_info_entry);
  725. ins->proc_scb_info_entry = NULL;
  726. }
  727. if (ins->proc_task_info_entry) {
  728. snd_info_unregister(ins->proc_task_info_entry);
  729. ins->proc_task_info_entry = NULL;
  730. }
  731. mutex_lock(&chip->spos_mutex);
  732. for (i = 0; i < ins->nscb; ++i) {
  733. if (ins->scbs[i].deleted) continue;
  734. cs46xx_dsp_proc_free_scb_desc ( (ins->scbs + i) );
  735. }
  736. mutex_unlock(&chip->spos_mutex);
  737. if (ins->proc_dsp_dir) {
  738. snd_info_unregister (ins->proc_dsp_dir);
  739. ins->proc_dsp_dir = NULL;
  740. }
  741. return 0;
  742. }
  743. #endif /* CONFIG_PROC_FS */
  744. static int debug_tree;
  745. static void _dsp_create_task_tree (struct snd_cs46xx *chip, u32 * task_data,
  746. u32 dest, int size)
  747. {
  748. void __iomem *spdst = chip->region.idx[1].remap_addr +
  749. DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
  750. int i;
  751. for (i = 0; i < size; ++i) {
  752. if (debug_tree) printk ("addr %p, val %08x\n",spdst,task_data[i]);
  753. writel(task_data[i],spdst);
  754. spdst += sizeof(u32);
  755. }
  756. }
  757. static int debug_scb;
  758. static void _dsp_create_scb (struct snd_cs46xx *chip, u32 * scb_data, u32 dest)
  759. {
  760. void __iomem *spdst = chip->region.idx[1].remap_addr +
  761. DSP_PARAMETER_BYTE_OFFSET + dest * sizeof(u32);
  762. int i;
  763. for (i = 0; i < 0x10; ++i) {
  764. if (debug_scb) printk ("addr %p, val %08x\n",spdst,scb_data[i]);
  765. writel(scb_data[i],spdst);
  766. spdst += sizeof(u32);
  767. }
  768. }
  769. static int find_free_scb_index (struct dsp_spos_instance * ins)
  770. {
  771. int index = ins->nscb, i;
  772. for (i = ins->scb_highest_frag_index; i < ins->nscb; ++i) {
  773. if (ins->scbs[i].deleted) {
  774. index = i;
  775. break;
  776. }
  777. }
  778. return index;
  779. }
  780. static struct dsp_scb_descriptor * _map_scb (struct snd_cs46xx *chip, char * name, u32 dest)
  781. {
  782. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  783. struct dsp_scb_descriptor * desc = NULL;
  784. int index;
  785. if (ins->nscb == DSP_MAX_SCB_DESC - 1) {
  786. snd_printk(KERN_ERR "dsp_spos: got no place for other SCB\n");
  787. return NULL;
  788. }
  789. index = find_free_scb_index (ins);
  790. strcpy(ins->scbs[index].scb_name, name);
  791. ins->scbs[index].address = dest;
  792. ins->scbs[index].index = index;
  793. ins->scbs[index].proc_info = NULL;
  794. ins->scbs[index].ref_count = 1;
  795. ins->scbs[index].deleted = 0;
  796. spin_lock_init(&ins->scbs[index].lock);
  797. desc = (ins->scbs + index);
  798. ins->scbs[index].scb_symbol = add_symbol (chip, name, dest, SYMBOL_PARAMETER);
  799. if (index > ins->scb_highest_frag_index)
  800. ins->scb_highest_frag_index = index;
  801. if (index == ins->nscb)
  802. ins->nscb++;
  803. return desc;
  804. }
  805. static struct dsp_task_descriptor *
  806. _map_task_tree (struct snd_cs46xx *chip, char * name, u32 dest, u32 size)
  807. {
  808. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  809. struct dsp_task_descriptor * desc = NULL;
  810. if (ins->ntask == DSP_MAX_TASK_DESC - 1) {
  811. snd_printk(KERN_ERR "dsp_spos: got no place for other TASK\n");
  812. return NULL;
  813. }
  814. strcpy(ins->tasks[ins->ntask].task_name,name);
  815. ins->tasks[ins->ntask].address = dest;
  816. ins->tasks[ins->ntask].size = size;
  817. /* quick find in list */
  818. ins->tasks[ins->ntask].index = ins->ntask;
  819. desc = (ins->tasks + ins->ntask);
  820. ins->ntask++;
  821. add_symbol (chip,name,dest,SYMBOL_PARAMETER);
  822. return desc;
  823. }
  824. struct dsp_scb_descriptor *
  825. cs46xx_dsp_create_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest)
  826. {
  827. struct dsp_scb_descriptor * desc;
  828. desc = _map_scb (chip,name,dest);
  829. if (desc) {
  830. _dsp_create_scb(chip,scb_data,dest);
  831. } else {
  832. snd_printk(KERN_ERR "dsp_spos: failed to map SCB\n");
  833. }
  834. return desc;
  835. }
  836. static struct dsp_task_descriptor *
  837. cs46xx_dsp_create_task_tree (struct snd_cs46xx *chip, char * name, u32 * task_data,
  838. u32 dest, int size)
  839. {
  840. struct dsp_task_descriptor * desc;
  841. desc = _map_task_tree (chip,name,dest,size);
  842. if (desc) {
  843. _dsp_create_task_tree(chip,task_data,dest,size);
  844. } else {
  845. snd_printk(KERN_ERR "dsp_spos: failed to map TASK\n");
  846. }
  847. return desc;
  848. }
  849. int cs46xx_dsp_scb_and_task_init (struct snd_cs46xx *chip)
  850. {
  851. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  852. struct dsp_symbol_entry * fg_task_tree_header_code;
  853. struct dsp_symbol_entry * task_tree_header_code;
  854. struct dsp_symbol_entry * task_tree_thread;
  855. struct dsp_symbol_entry * null_algorithm;
  856. struct dsp_symbol_entry * magic_snoop_task;
  857. struct dsp_scb_descriptor * timing_master_scb;
  858. struct dsp_scb_descriptor * codec_out_scb;
  859. struct dsp_scb_descriptor * codec_in_scb;
  860. struct dsp_scb_descriptor * src_task_scb;
  861. struct dsp_scb_descriptor * master_mix_scb;
  862. struct dsp_scb_descriptor * rear_mix_scb;
  863. struct dsp_scb_descriptor * record_mix_scb;
  864. struct dsp_scb_descriptor * write_back_scb;
  865. struct dsp_scb_descriptor * vari_decimate_scb;
  866. struct dsp_scb_descriptor * rear_codec_out_scb;
  867. struct dsp_scb_descriptor * clfe_codec_out_scb;
  868. struct dsp_scb_descriptor * magic_snoop_scb;
  869. int fifo_addr, fifo_span, valid_slots;
  870. static struct dsp_spos_control_block sposcb = {
  871. /* 0 */ HFG_TREE_SCB,HFG_STACK,
  872. /* 1 */ SPOSCB_ADDR,BG_TREE_SCB_ADDR,
  873. /* 2 */ DSP_SPOS_DC,0,
  874. /* 3 */ DSP_SPOS_DC,DSP_SPOS_DC,
  875. /* 4 */ 0,0,
  876. /* 5 */ DSP_SPOS_UU,0,
  877. /* 6 */ FG_TASK_HEADER_ADDR,0,
  878. /* 7 */ 0,0,
  879. /* 8 */ DSP_SPOS_UU,DSP_SPOS_DC,
  880. /* 9 */ 0,
  881. /* A */ 0,HFG_FIRST_EXECUTE_MODE,
  882. /* B */ DSP_SPOS_UU,DSP_SPOS_UU,
  883. /* C */ DSP_SPOS_DC_DC,
  884. /* D */ DSP_SPOS_DC_DC,
  885. /* E */ DSP_SPOS_DC_DC,
  886. /* F */ DSP_SPOS_DC_DC
  887. };
  888. cs46xx_dsp_create_task_tree(chip, "sposCB", (u32 *)&sposcb, SPOSCB_ADDR, 0x10);
  889. null_algorithm = cs46xx_dsp_lookup_symbol(chip, "NULLALGORITHM", SYMBOL_CODE);
  890. if (null_algorithm == NULL) {
  891. snd_printk(KERN_ERR "dsp_spos: symbol NULLALGORITHM not found\n");
  892. return -EIO;
  893. }
  894. fg_task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "FGTASKTREEHEADERCODE", SYMBOL_CODE);
  895. if (fg_task_tree_header_code == NULL) {
  896. snd_printk(KERN_ERR "dsp_spos: symbol FGTASKTREEHEADERCODE not found\n");
  897. return -EIO;
  898. }
  899. task_tree_header_code = cs46xx_dsp_lookup_symbol(chip, "TASKTREEHEADERCODE", SYMBOL_CODE);
  900. if (task_tree_header_code == NULL) {
  901. snd_printk(KERN_ERR "dsp_spos: symbol TASKTREEHEADERCODE not found\n");
  902. return -EIO;
  903. }
  904. task_tree_thread = cs46xx_dsp_lookup_symbol(chip, "TASKTREETHREAD", SYMBOL_CODE);
  905. if (task_tree_thread == NULL) {
  906. snd_printk(KERN_ERR "dsp_spos: symbol TASKTREETHREAD not found\n");
  907. return -EIO;
  908. }
  909. magic_snoop_task = cs46xx_dsp_lookup_symbol(chip, "MAGICSNOOPTASK", SYMBOL_CODE);
  910. if (magic_snoop_task == NULL) {
  911. snd_printk(KERN_ERR "dsp_spos: symbol MAGICSNOOPTASK not found\n");
  912. return -EIO;
  913. }
  914. {
  915. /* create the null SCB */
  916. static struct dsp_generic_scb null_scb = {
  917. { 0, 0, 0, 0 },
  918. { 0, 0, 0, 0, 0 },
  919. NULL_SCB_ADDR, NULL_SCB_ADDR,
  920. 0, 0, 0, 0, 0,
  921. {
  922. 0,0,
  923. 0,0,
  924. }
  925. };
  926. null_scb.entry_point = null_algorithm->address;
  927. ins->the_null_scb = cs46xx_dsp_create_scb(chip, "nullSCB", (u32 *)&null_scb, NULL_SCB_ADDR);
  928. ins->the_null_scb->task_entry = null_algorithm;
  929. ins->the_null_scb->sub_list_ptr = ins->the_null_scb;
  930. ins->the_null_scb->next_scb_ptr = ins->the_null_scb;
  931. ins->the_null_scb->parent_scb_ptr = NULL;
  932. cs46xx_dsp_proc_register_scb_desc (chip,ins->the_null_scb);
  933. }
  934. {
  935. /* setup foreground task tree */
  936. static struct dsp_task_tree_control_block fg_task_tree_hdr = {
  937. { FG_TASK_HEADER_ADDR | (DSP_SPOS_DC << 0x10),
  938. DSP_SPOS_DC_DC,
  939. DSP_SPOS_DC_DC,
  940. 0x0000,DSP_SPOS_DC,
  941. DSP_SPOS_DC, DSP_SPOS_DC,
  942. DSP_SPOS_DC_DC,
  943. DSP_SPOS_DC_DC,
  944. DSP_SPOS_DC_DC,
  945. DSP_SPOS_DC,DSP_SPOS_DC },
  946. {
  947. BG_TREE_SCB_ADDR,TIMINGMASTER_SCB_ADDR,
  948. 0,
  949. FG_TASK_HEADER_ADDR + TCBData,
  950. },
  951. {
  952. 4,0,
  953. 1,0,
  954. 2,SPOSCB_ADDR + HFGFlags,
  955. 0,0,
  956. FG_TASK_HEADER_ADDR + TCBContextBlk,FG_STACK
  957. },
  958. {
  959. DSP_SPOS_DC,0,
  960. DSP_SPOS_DC,DSP_SPOS_DC,
  961. DSP_SPOS_DC,DSP_SPOS_DC,
  962. DSP_SPOS_DC,DSP_SPOS_DC,
  963. DSP_SPOS_DC,DSP_SPOS_DC,
  964. DSP_SPOS_DCDC,
  965. DSP_SPOS_UU,1,
  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. DSP_SPOS_DCDC,
  988. DSP_SPOS_DCDC,
  989. DSP_SPOS_DCDC,
  990. DSP_SPOS_DCDC,
  991. DSP_SPOS_DCDC,
  992. DSP_SPOS_DCDC,
  993. DSP_SPOS_DCDC
  994. },
  995. {
  996. FG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
  997. 0,0
  998. }
  999. };
  1000. fg_task_tree_hdr.links.entry_point = fg_task_tree_header_code->address;
  1001. fg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
  1002. cs46xx_dsp_create_task_tree(chip,"FGtaskTreeHdr",(u32 *)&fg_task_tree_hdr,FG_TASK_HEADER_ADDR,0x35);
  1003. }
  1004. {
  1005. /* setup foreground task tree */
  1006. static struct dsp_task_tree_control_block bg_task_tree_hdr = {
  1007. { DSP_SPOS_DC_DC,
  1008. DSP_SPOS_DC_DC,
  1009. DSP_SPOS_DC_DC,
  1010. DSP_SPOS_DC, DSP_SPOS_DC,
  1011. DSP_SPOS_DC, DSP_SPOS_DC,
  1012. DSP_SPOS_DC_DC,
  1013. DSP_SPOS_DC_DC,
  1014. DSP_SPOS_DC_DC,
  1015. DSP_SPOS_DC,DSP_SPOS_DC },
  1016. {
  1017. NULL_SCB_ADDR,NULL_SCB_ADDR, /* Set up the background to do nothing */
  1018. 0,
  1019. BG_TREE_SCB_ADDR + TCBData,
  1020. },
  1021. {
  1022. 9999,0,
  1023. 0,1,
  1024. 0,SPOSCB_ADDR + HFGFlags,
  1025. 0,0,
  1026. BG_TREE_SCB_ADDR + TCBContextBlk,BG_STACK
  1027. },
  1028. {
  1029. DSP_SPOS_DC,0,
  1030. DSP_SPOS_DC,DSP_SPOS_DC,
  1031. DSP_SPOS_DC,DSP_SPOS_DC,
  1032. DSP_SPOS_DC,DSP_SPOS_DC,
  1033. DSP_SPOS_DC,DSP_SPOS_DC,
  1034. DSP_SPOS_DCDC,
  1035. DSP_SPOS_UU,1,
  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. DSP_SPOS_DCDC,
  1058. DSP_SPOS_DCDC,
  1059. DSP_SPOS_DCDC,
  1060. DSP_SPOS_DCDC,
  1061. DSP_SPOS_DCDC,
  1062. DSP_SPOS_DCDC,
  1063. DSP_SPOS_DCDC
  1064. },
  1065. {
  1066. BG_INTERVAL_TIMER_PERIOD,DSP_SPOS_UU,
  1067. 0,0
  1068. }
  1069. };
  1070. bg_task_tree_hdr.links.entry_point = task_tree_header_code->address;
  1071. bg_task_tree_hdr.context_blk.stack0 = task_tree_thread->address;
  1072. cs46xx_dsp_create_task_tree(chip,"BGtaskTreeHdr",(u32 *)&bg_task_tree_hdr,BG_TREE_SCB_ADDR,0x35);
  1073. }
  1074. /* create timing master SCB */
  1075. timing_master_scb = cs46xx_dsp_create_timing_master_scb(chip);
  1076. /* create the CODEC output task */
  1077. codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_I",0x0010,0x0000,
  1078. MASTERMIX_SCB_ADDR,
  1079. CODECOUT_SCB_ADDR,timing_master_scb,
  1080. SCB_ON_PARENT_SUBLIST_SCB);
  1081. if (!codec_out_scb) goto _fail_end;
  1082. /* create the master mix SCB */
  1083. master_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"MasterMixSCB",
  1084. MIX_SAMPLE_BUF1,MASTERMIX_SCB_ADDR,
  1085. codec_out_scb,
  1086. SCB_ON_PARENT_SUBLIST_SCB);
  1087. ins->master_mix_scb = master_mix_scb;
  1088. if (!master_mix_scb) goto _fail_end;
  1089. /* create codec in */
  1090. codec_in_scb = cs46xx_dsp_create_codec_in_scb(chip,"CodecInSCB",0x0010,0x00A0,
  1091. CODEC_INPUT_BUF1,
  1092. CODECIN_SCB_ADDR,codec_out_scb,
  1093. SCB_ON_PARENT_NEXT_SCB);
  1094. if (!codec_in_scb) goto _fail_end;
  1095. ins->codec_in_scb = codec_in_scb;
  1096. /* create write back scb */
  1097. write_back_scb = cs46xx_dsp_create_mix_to_ostream_scb(chip,"WriteBackSCB",
  1098. WRITE_BACK_BUF1,WRITE_BACK_SPB,
  1099. WRITEBACK_SCB_ADDR,
  1100. timing_master_scb,
  1101. SCB_ON_PARENT_NEXT_SCB);
  1102. if (!write_back_scb) goto _fail_end;
  1103. {
  1104. static struct dsp_mix2_ostream_spb mix2_ostream_spb = {
  1105. 0x00020000,
  1106. 0x0000ffff
  1107. };
  1108. /* dirty hack ... */
  1109. _dsp_create_task_tree (chip,(u32 *)&mix2_ostream_spb,WRITE_BACK_SPB,2);
  1110. }
  1111. /* input sample converter */
  1112. vari_decimate_scb = cs46xx_dsp_create_vari_decimate_scb(chip,"VariDecimateSCB",
  1113. VARI_DECIMATE_BUF0,
  1114. VARI_DECIMATE_BUF1,
  1115. VARIDECIMATE_SCB_ADDR,
  1116. write_back_scb,
  1117. SCB_ON_PARENT_SUBLIST_SCB);
  1118. if (!vari_decimate_scb) goto _fail_end;
  1119. /* create the record mixer SCB */
  1120. record_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RecordMixerSCB",
  1121. MIX_SAMPLE_BUF2,
  1122. RECORD_MIXER_SCB_ADDR,
  1123. vari_decimate_scb,
  1124. SCB_ON_PARENT_SUBLIST_SCB);
  1125. ins->record_mixer_scb = record_mix_scb;
  1126. if (!record_mix_scb) goto _fail_end;
  1127. valid_slots = snd_cs46xx_peekBA0(chip, BA0_ACOSV);
  1128. snd_assert (chip->nr_ac97_codecs == 1 || chip->nr_ac97_codecs == 2);
  1129. if (chip->nr_ac97_codecs == 1) {
  1130. /* output on slot 5 and 11
  1131. on primary CODEC */
  1132. fifo_addr = 0x20;
  1133. fifo_span = 0x60;
  1134. /* enable slot 5 and 11 */
  1135. valid_slots |= ACOSV_SLV5 | ACOSV_SLV11;
  1136. } else {
  1137. /* output on slot 7 and 8
  1138. on secondary CODEC */
  1139. fifo_addr = 0x40;
  1140. fifo_span = 0x10;
  1141. /* enable slot 7 and 8 */
  1142. valid_slots |= ACOSV_SLV7 | ACOSV_SLV8;
  1143. }
  1144. /* create CODEC tasklet for rear speakers output*/
  1145. rear_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_Rear",fifo_span,fifo_addr,
  1146. REAR_MIXER_SCB_ADDR,
  1147. REAR_CODECOUT_SCB_ADDR,codec_in_scb,
  1148. SCB_ON_PARENT_NEXT_SCB);
  1149. if (!rear_codec_out_scb) goto _fail_end;
  1150. /* create the rear PCM channel mixer SCB */
  1151. rear_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"RearMixerSCB",
  1152. MIX_SAMPLE_BUF3,
  1153. REAR_MIXER_SCB_ADDR,
  1154. rear_codec_out_scb,
  1155. SCB_ON_PARENT_SUBLIST_SCB);
  1156. ins->rear_mix_scb = rear_mix_scb;
  1157. if (!rear_mix_scb) goto _fail_end;
  1158. if (chip->nr_ac97_codecs == 2) {
  1159. /* create CODEC tasklet for rear Center/LFE output
  1160. slot 6 and 9 on seconadry CODEC */
  1161. clfe_codec_out_scb = cs46xx_dsp_create_codec_out_scb(chip,"CodecOutSCB_CLFE",0x0030,0x0030,
  1162. CLFE_MIXER_SCB_ADDR,
  1163. CLFE_CODEC_SCB_ADDR,
  1164. rear_codec_out_scb,
  1165. SCB_ON_PARENT_NEXT_SCB);
  1166. if (!clfe_codec_out_scb) goto _fail_end;
  1167. /* create the rear PCM channel mixer SCB */
  1168. ins->center_lfe_mix_scb = cs46xx_dsp_create_mix_only_scb(chip,"CLFEMixerSCB",
  1169. MIX_SAMPLE_BUF4,
  1170. CLFE_MIXER_SCB_ADDR,
  1171. clfe_codec_out_scb,
  1172. SCB_ON_PARENT_SUBLIST_SCB);
  1173. if (!ins->center_lfe_mix_scb) goto _fail_end;
  1174. /* enable slot 6 and 9 */
  1175. valid_slots |= ACOSV_SLV6 | ACOSV_SLV9;
  1176. } else {
  1177. clfe_codec_out_scb = rear_codec_out_scb;
  1178. ins->center_lfe_mix_scb = rear_mix_scb;
  1179. }
  1180. /* enable slots depending on CODEC configuration */
  1181. snd_cs46xx_pokeBA0(chip, BA0_ACOSV, valid_slots);
  1182. /* the magic snooper */
  1183. magic_snoop_scb = cs46xx_dsp_create_magic_snoop_scb (chip,"MagicSnoopSCB_I",OUTPUTSNOOP_SCB_ADDR,
  1184. OUTPUT_SNOOP_BUFFER,
  1185. codec_out_scb,
  1186. clfe_codec_out_scb,
  1187. SCB_ON_PARENT_NEXT_SCB);
  1188. if (!magic_snoop_scb) goto _fail_end;
  1189. ins->ref_snoop_scb = magic_snoop_scb;
  1190. /* SP IO access */
  1191. if (!cs46xx_dsp_create_spio_write_scb(chip,"SPIOWriteSCB",SPIOWRITE_SCB_ADDR,
  1192. magic_snoop_scb,
  1193. SCB_ON_PARENT_NEXT_SCB))
  1194. goto _fail_end;
  1195. /* SPDIF input sampel rate converter */
  1196. src_task_scb = cs46xx_dsp_create_src_task_scb(chip,"SrcTaskSCB_SPDIFI",
  1197. ins->spdif_in_sample_rate,
  1198. SRC_OUTPUT_BUF1,
  1199. SRC_DELAY_BUF1,SRCTASK_SCB_ADDR,
  1200. master_mix_scb,
  1201. SCB_ON_PARENT_SUBLIST_SCB,1);
  1202. if (!src_task_scb) goto _fail_end;
  1203. cs46xx_src_unlink(chip,src_task_scb);
  1204. /* NOTE: when we now how to detect the SPDIF input
  1205. sample rate we will use this SRC to adjust it */
  1206. ins->spdif_in_src = src_task_scb;
  1207. cs46xx_dsp_async_init(chip,timing_master_scb);
  1208. return 0;
  1209. _fail_end:
  1210. snd_printk(KERN_ERR "dsp_spos: failed to setup SCB's in DSP\n");
  1211. return -EINVAL;
  1212. }
  1213. static int cs46xx_dsp_async_init (struct snd_cs46xx *chip,
  1214. struct dsp_scb_descriptor * fg_entry)
  1215. {
  1216. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1217. struct dsp_symbol_entry * s16_async_codec_input_task;
  1218. struct dsp_symbol_entry * spdifo_task;
  1219. struct dsp_symbol_entry * spdifi_task;
  1220. struct dsp_scb_descriptor * spdifi_scb_desc, * spdifo_scb_desc, * async_codec_scb_desc;
  1221. s16_async_codec_input_task = cs46xx_dsp_lookup_symbol(chip, "S16_ASYNCCODECINPUTTASK", SYMBOL_CODE);
  1222. if (s16_async_codec_input_task == NULL) {
  1223. snd_printk(KERN_ERR "dsp_spos: symbol S16_ASYNCCODECINPUTTASK not found\n");
  1224. return -EIO;
  1225. }
  1226. spdifo_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFOTASK", SYMBOL_CODE);
  1227. if (spdifo_task == NULL) {
  1228. snd_printk(KERN_ERR "dsp_spos: symbol SPDIFOTASK not found\n");
  1229. return -EIO;
  1230. }
  1231. spdifi_task = cs46xx_dsp_lookup_symbol(chip, "SPDIFITASK", SYMBOL_CODE);
  1232. if (spdifi_task == NULL) {
  1233. snd_printk(KERN_ERR "dsp_spos: symbol SPDIFITASK not found\n");
  1234. return -EIO;
  1235. }
  1236. {
  1237. /* 0xBC0 */
  1238. struct dsp_spdifoscb spdifo_scb = {
  1239. /* 0 */ DSP_SPOS_UUUU,
  1240. {
  1241. /* 1 */ 0xb0,
  1242. /* 2 */ 0,
  1243. /* 3 */ 0,
  1244. /* 4 */ 0,
  1245. },
  1246. /* NOTE: the SPDIF output task read samples in mono
  1247. format, the AsynchFGTxSCB task writes to buffer
  1248. in stereo format
  1249. */
  1250. /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_256,
  1251. /* 6 */ ( SPDIFO_IP_OUTPUT_BUFFER1 << 0x10 ) | 0xFFFC,
  1252. /* 7 */ 0,0,
  1253. /* 8 */ 0,
  1254. /* 9 */ FG_TASK_HEADER_ADDR, NULL_SCB_ADDR,
  1255. /* A */ spdifo_task->address,
  1256. SPDIFO_SCB_INST + SPDIFOFIFOPointer,
  1257. {
  1258. /* B */ 0x0040, /*DSP_SPOS_UUUU,*/
  1259. /* C */ 0x20ff, /*DSP_SPOS_UUUU,*/
  1260. },
  1261. /* D */ 0x804c,0, /* SPDIFOFIFOPointer:SPDIFOStatRegAddr; */
  1262. /* E */ 0x0108,0x0001, /* SPDIFOStMoFormat:SPDIFOFIFOBaseAddr; */
  1263. /* F */ DSP_SPOS_UUUU /* SPDIFOFree; */
  1264. };
  1265. /* 0xBB0 */
  1266. struct dsp_spdifiscb spdifi_scb = {
  1267. /* 0 */ DSP_SPOS_UULO,DSP_SPOS_UUHI,
  1268. /* 1 */ 0,
  1269. /* 2 */ 0,
  1270. /* 3 */ 1,4000, /* SPDIFICountLimit SPDIFICount */
  1271. /* 4 */ DSP_SPOS_UUUU, /* SPDIFIStatusData */
  1272. /* 5 */ 0,DSP_SPOS_UUHI, /* StatusData, Free4 */
  1273. /* 6 */ DSP_SPOS_UUUU, /* Free3 */
  1274. /* 7 */ DSP_SPOS_UU,DSP_SPOS_DC, /* Free2 BitCount*/
  1275. /* 8 */ DSP_SPOS_UUUU, /* TempStatus */
  1276. /* 9 */ SPDIFO_SCB_INST, NULL_SCB_ADDR,
  1277. /* A */ spdifi_task->address,
  1278. SPDIFI_SCB_INST + SPDIFIFIFOPointer,
  1279. /* NOTE: The SPDIF input task write the sample in mono
  1280. format from the HW FIFO, the AsynchFGRxSCB task reads
  1281. them in stereo
  1282. */
  1283. /* B */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_128,
  1284. /* C */ (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
  1285. /* D */ 0x8048,0,
  1286. /* E */ 0x01f0,0x0001,
  1287. /* F */ DSP_SPOS_UUUU /* SPDIN_STATUS monitor */
  1288. };
  1289. /* 0xBA0 */
  1290. struct dsp_async_codec_input_scb async_codec_input_scb = {
  1291. /* 0 */ DSP_SPOS_UUUU,
  1292. /* 1 */ 0,
  1293. /* 2 */ 0,
  1294. /* 3 */ 1,4000,
  1295. /* 4 */ 0x0118,0x0001,
  1296. /* 5 */ RSCONFIG_SAMPLE_16MONO + RSCONFIG_MODULO_64,
  1297. /* 6 */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,
  1298. /* 7 */ DSP_SPOS_UU,0x3,
  1299. /* 8 */ DSP_SPOS_UUUU,
  1300. /* 9 */ SPDIFI_SCB_INST,NULL_SCB_ADDR,
  1301. /* A */ s16_async_codec_input_task->address,
  1302. HFG_TREE_SCB + AsyncCIOFIFOPointer,
  1303. /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
  1304. /* C */ (ASYNC_IP_OUTPUT_BUFFER1 << 0x10), /*(ASYNC_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC,*/
  1305. #ifdef UseASER1Input
  1306. /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
  1307. Init. 0000:8042: for ASER1
  1308. 0000:8044: for ASER2 */
  1309. /* D */ 0x8042,0,
  1310. /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
  1311. Init 1 stero:8050 ASER1
  1312. Init 0 mono:8070 ASER2
  1313. Init 1 Stereo : 0100 ASER1 (Set by script) */
  1314. /* E */ 0x0100,0x0001,
  1315. #endif
  1316. #ifdef UseASER2Input
  1317. /* short AsyncCIFIFOPointer:AsyncCIStatRegAddr;
  1318. Init. 0000:8042: for ASER1
  1319. 0000:8044: for ASER2 */
  1320. /* D */ 0x8044,0,
  1321. /* short AsyncCIStMoFormat:AsyncCIFIFOBaseAddr;
  1322. Init 1 stero:8050 ASER1
  1323. Init 0 mono:8070 ASER2
  1324. Init 1 Stereo : 0100 ASER1 (Set by script) */
  1325. /* E */ 0x0110,0x0001,
  1326. #endif
  1327. /* short AsyncCIOutputBufModulo:AsyncCIFree;
  1328. AsyncCIOutputBufModulo: The modulo size for
  1329. the output buffer of this task */
  1330. /* F */ 0, /* DSP_SPOS_UUUU */
  1331. };
  1332. spdifo_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFOSCB",(u32 *)&spdifo_scb,SPDIFO_SCB_INST);
  1333. snd_assert(spdifo_scb_desc, return -EIO);
  1334. spdifi_scb_desc = cs46xx_dsp_create_scb(chip,"SPDIFISCB",(u32 *)&spdifi_scb,SPDIFI_SCB_INST);
  1335. snd_assert(spdifi_scb_desc, return -EIO);
  1336. async_codec_scb_desc = cs46xx_dsp_create_scb(chip,"AsynCodecInputSCB",(u32 *)&async_codec_input_scb, HFG_TREE_SCB);
  1337. snd_assert(async_codec_scb_desc, return -EIO);
  1338. async_codec_scb_desc->parent_scb_ptr = NULL;
  1339. async_codec_scb_desc->next_scb_ptr = spdifi_scb_desc;
  1340. async_codec_scb_desc->sub_list_ptr = ins->the_null_scb;
  1341. async_codec_scb_desc->task_entry = s16_async_codec_input_task;
  1342. spdifi_scb_desc->parent_scb_ptr = async_codec_scb_desc;
  1343. spdifi_scb_desc->next_scb_ptr = spdifo_scb_desc;
  1344. spdifi_scb_desc->sub_list_ptr = ins->the_null_scb;
  1345. spdifi_scb_desc->task_entry = spdifi_task;
  1346. spdifo_scb_desc->parent_scb_ptr = spdifi_scb_desc;
  1347. spdifo_scb_desc->next_scb_ptr = fg_entry;
  1348. spdifo_scb_desc->sub_list_ptr = ins->the_null_scb;
  1349. spdifo_scb_desc->task_entry = spdifo_task;
  1350. /* this one is faked, as the parnet of SPDIFO task
  1351. is the FG task tree */
  1352. fg_entry->parent_scb_ptr = spdifo_scb_desc;
  1353. /* for proc fs */
  1354. cs46xx_dsp_proc_register_scb_desc (chip,spdifo_scb_desc);
  1355. cs46xx_dsp_proc_register_scb_desc (chip,spdifi_scb_desc);
  1356. cs46xx_dsp_proc_register_scb_desc (chip,async_codec_scb_desc);
  1357. /* Async MASTER ENABLE, affects both SPDIF input and output */
  1358. snd_cs46xx_pokeBA0(chip, BA0_ASER_MASTER, 0x1 );
  1359. }
  1360. return 0;
  1361. }
  1362. static void cs46xx_dsp_disable_spdif_hw (struct snd_cs46xx *chip)
  1363. {
  1364. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1365. /* set SPDIF output FIFO slot */
  1366. snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, 0);
  1367. /* SPDIF output MASTER ENABLE */
  1368. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0);
  1369. /* right and left validate bit */
  1370. /*cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);*/
  1371. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, 0x0);
  1372. /* clear fifo pointer */
  1373. cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);
  1374. /* monitor state */
  1375. ins->spdif_status_out &= ~DSP_SPDIF_STATUS_HW_ENABLED;
  1376. }
  1377. int cs46xx_dsp_enable_spdif_hw (struct snd_cs46xx *chip)
  1378. {
  1379. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1380. /* if hw-ctrl already enabled, turn off to reset logic ... */
  1381. cs46xx_dsp_disable_spdif_hw (chip);
  1382. udelay(50);
  1383. /* set SPDIF output FIFO slot */
  1384. snd_cs46xx_pokeBA0(chip, BA0_ASER_FADDR, ( 0x8000 | ((SP_SPDOUT_FIFO >> 4) << 4) ));
  1385. /* SPDIF output MASTER ENABLE */
  1386. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CONTROL, 0x80000000);
  1387. /* right and left validate bit */
  1388. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
  1389. /* monitor state */
  1390. ins->spdif_status_out |= DSP_SPDIF_STATUS_HW_ENABLED;
  1391. return 0;
  1392. }
  1393. int cs46xx_dsp_enable_spdif_in (struct snd_cs46xx *chip)
  1394. {
  1395. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1396. /* turn on amplifier */
  1397. chip->active_ctrl(chip, 1);
  1398. chip->amplifier_ctrl(chip, 1);
  1399. snd_assert (ins->asynch_rx_scb == NULL,return -EINVAL);
  1400. snd_assert (ins->spdif_in_src != NULL,return -EINVAL);
  1401. mutex_lock(&chip->spos_mutex);
  1402. if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED) ) {
  1403. /* time countdown enable */
  1404. cs46xx_poke_via_dsp (chip,SP_ASER_COUNTDOWN, 0x80000005);
  1405. /* NOTE: 80000005 value is just magic. With all values
  1406. that I've tested this one seem to give the best result.
  1407. Got no explication why. (Benny) */
  1408. /* SPDIF input MASTER ENABLE */
  1409. cs46xx_poke_via_dsp (chip,SP_SPDIN_CONTROL, 0x800003ff);
  1410. ins->spdif_status_out |= DSP_SPDIF_STATUS_INPUT_CTRL_ENABLED;
  1411. }
  1412. /* create and start the asynchronous receiver SCB */
  1413. ins->asynch_rx_scb = cs46xx_dsp_create_asynch_fg_rx_scb(chip,"AsynchFGRxSCB",
  1414. ASYNCRX_SCB_ADDR,
  1415. SPDIFI_SCB_INST,
  1416. SPDIFI_IP_OUTPUT_BUFFER1,
  1417. ins->spdif_in_src,
  1418. SCB_ON_PARENT_SUBLIST_SCB);
  1419. spin_lock_irq(&chip->reg_lock);
  1420. /* reset SPDIF input sample buffer pointer */
  1421. /*snd_cs46xx_poke (chip, (SPDIFI_SCB_INST + 0x0c) << 2,
  1422. (SPDIFI_IP_OUTPUT_BUFFER1 << 0x10) | 0xFFFC);*/
  1423. /* reset FIFO ptr */
  1424. /*cs46xx_poke_via_dsp (chip,SP_SPDIN_FIFOPTR, 0x0);*/
  1425. cs46xx_src_link(chip,ins->spdif_in_src);
  1426. /* unmute SRC volume */
  1427. cs46xx_dsp_scb_set_volume (chip,ins->spdif_in_src,0x7fff,0x7fff);
  1428. spin_unlock_irq(&chip->reg_lock);
  1429. /* set SPDIF input sample rate and unmute
  1430. NOTE: only 48khz support for SPDIF input this time */
  1431. /* cs46xx_dsp_set_src_sample_rate(chip,ins->spdif_in_src,48000); */
  1432. /* monitor state */
  1433. ins->spdif_status_in = 1;
  1434. mutex_unlock(&chip->spos_mutex);
  1435. return 0;
  1436. }
  1437. int cs46xx_dsp_disable_spdif_in (struct snd_cs46xx *chip)
  1438. {
  1439. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1440. snd_assert (ins->asynch_rx_scb != NULL, return -EINVAL);
  1441. snd_assert (ins->spdif_in_src != NULL,return -EINVAL);
  1442. mutex_lock(&chip->spos_mutex);
  1443. /* Remove the asynchronous receiver SCB */
  1444. cs46xx_dsp_remove_scb (chip,ins->asynch_rx_scb);
  1445. ins->asynch_rx_scb = NULL;
  1446. cs46xx_src_unlink(chip,ins->spdif_in_src);
  1447. /* monitor state */
  1448. ins->spdif_status_in = 0;
  1449. mutex_unlock(&chip->spos_mutex);
  1450. /* restore amplifier */
  1451. chip->active_ctrl(chip, -1);
  1452. chip->amplifier_ctrl(chip, -1);
  1453. return 0;
  1454. }
  1455. int cs46xx_dsp_enable_pcm_capture (struct snd_cs46xx *chip)
  1456. {
  1457. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1458. snd_assert (ins->pcm_input == NULL,return -EINVAL);
  1459. snd_assert (ins->ref_snoop_scb != NULL,return -EINVAL);
  1460. mutex_lock(&chip->spos_mutex);
  1461. ins->pcm_input = cs46xx_add_record_source(chip,ins->ref_snoop_scb,PCMSERIALIN_PCM_SCB_ADDR,
  1462. "PCMSerialInput_Wave");
  1463. mutex_unlock(&chip->spos_mutex);
  1464. return 0;
  1465. }
  1466. int cs46xx_dsp_disable_pcm_capture (struct snd_cs46xx *chip)
  1467. {
  1468. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1469. snd_assert (ins->pcm_input != NULL,return -EINVAL);
  1470. mutex_lock(&chip->spos_mutex);
  1471. cs46xx_dsp_remove_scb (chip,ins->pcm_input);
  1472. ins->pcm_input = NULL;
  1473. mutex_unlock(&chip->spos_mutex);
  1474. return 0;
  1475. }
  1476. int cs46xx_dsp_enable_adc_capture (struct snd_cs46xx *chip)
  1477. {
  1478. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1479. snd_assert (ins->adc_input == NULL,return -EINVAL);
  1480. snd_assert (ins->codec_in_scb != NULL,return -EINVAL);
  1481. mutex_lock(&chip->spos_mutex);
  1482. ins->adc_input = cs46xx_add_record_source(chip,ins->codec_in_scb,PCMSERIALIN_SCB_ADDR,
  1483. "PCMSerialInput_ADC");
  1484. mutex_unlock(&chip->spos_mutex);
  1485. return 0;
  1486. }
  1487. int cs46xx_dsp_disable_adc_capture (struct snd_cs46xx *chip)
  1488. {
  1489. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1490. snd_assert (ins->adc_input != NULL,return -EINVAL);
  1491. mutex_lock(&chip->spos_mutex);
  1492. cs46xx_dsp_remove_scb (chip,ins->adc_input);
  1493. ins->adc_input = NULL;
  1494. mutex_unlock(&chip->spos_mutex);
  1495. return 0;
  1496. }
  1497. int cs46xx_poke_via_dsp (struct snd_cs46xx *chip, u32 address, u32 data)
  1498. {
  1499. u32 temp;
  1500. int i;
  1501. /* santiy check the parameters. (These numbers are not 100% correct. They are
  1502. a rough guess from looking at the controller spec.) */
  1503. if (address < 0x8000 || address >= 0x9000)
  1504. return -EINVAL;
  1505. /* initialize the SP_IO_WRITE SCB with the data. */
  1506. temp = ( address << 16 ) | ( address & 0x0000FFFF); /* offset 0 <-- address2 : address1 */
  1507. snd_cs46xx_poke(chip,( SPIOWRITE_SCB_ADDR << 2), temp);
  1508. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 1) << 2), data); /* offset 1 <-- data1 */
  1509. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 2) << 2), data); /* offset 1 <-- data2 */
  1510. /* Poke this location to tell the task to start */
  1511. snd_cs46xx_poke(chip,((SPIOWRITE_SCB_ADDR + 6) << 2), SPIOWRITE_SCB_ADDR << 0x10);
  1512. /* Verify that the task ran */
  1513. for (i=0; i<25; i++) {
  1514. udelay(125);
  1515. temp = snd_cs46xx_peek(chip,((SPIOWRITE_SCB_ADDR + 6) << 2));
  1516. if (temp == 0x00000000)
  1517. break;
  1518. }
  1519. if (i == 25) {
  1520. snd_printk(KERN_ERR "dsp_spos: SPIOWriteTask not responding\n");
  1521. return -EBUSY;
  1522. }
  1523. return 0;
  1524. }
  1525. int cs46xx_dsp_set_dac_volume (struct snd_cs46xx * chip, u16 left, u16 right)
  1526. {
  1527. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1528. struct dsp_scb_descriptor * scb;
  1529. mutex_lock(&chip->spos_mutex);
  1530. /* main output */
  1531. scb = ins->master_mix_scb->sub_list_ptr;
  1532. while (scb != ins->the_null_scb) {
  1533. cs46xx_dsp_scb_set_volume (chip,scb,left,right);
  1534. scb = scb->next_scb_ptr;
  1535. }
  1536. /* rear output */
  1537. scb = ins->rear_mix_scb->sub_list_ptr;
  1538. while (scb != ins->the_null_scb) {
  1539. cs46xx_dsp_scb_set_volume (chip,scb,left,right);
  1540. scb = scb->next_scb_ptr;
  1541. }
  1542. ins->dac_volume_left = left;
  1543. ins->dac_volume_right = right;
  1544. mutex_unlock(&chip->spos_mutex);
  1545. return 0;
  1546. }
  1547. int cs46xx_dsp_set_iec958_volume (struct snd_cs46xx * chip, u16 left, u16 right)
  1548. {
  1549. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1550. mutex_lock(&chip->spos_mutex);
  1551. if (ins->asynch_rx_scb != NULL)
  1552. cs46xx_dsp_scb_set_volume (chip,ins->asynch_rx_scb,
  1553. left,right);
  1554. ins->spdif_input_volume_left = left;
  1555. ins->spdif_input_volume_right = right;
  1556. mutex_unlock(&chip->spos_mutex);
  1557. return 0;
  1558. }