dsp_spos.c 55 KB

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