dsp_spos.c 56 KB

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