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