dsp_spos.c 56 KB

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