dsp_spos_scb_lib.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. */
  4. /*
  5. * 2002-07 Benny Sjostrand benny@hostmobility.com
  6. */
  7. #include <linux/io.h>
  8. #include <linux/delay.h>
  9. #include <linux/pm.h>
  10. #include <linux/init.h>
  11. #include <linux/slab.h>
  12. #include <linux/mutex.h>
  13. #include <sound/core.h>
  14. #include <sound/control.h>
  15. #include <sound/info.h>
  16. #include "cs46xx.h"
  17. #include "cs46xx_lib.h"
  18. #include "dsp_spos.h"
  19. struct proc_scb_info {
  20. struct dsp_scb_descriptor * scb_desc;
  21. struct snd_cs46xx *chip;
  22. };
  23. static void remove_symbol (struct snd_cs46xx * chip, struct dsp_symbol_entry * symbol)
  24. {
  25. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  26. int symbol_index = (int)(symbol - ins->symbol_table.symbols);
  27. if (snd_BUG_ON(ins->symbol_table.nsymbols <= 0))
  28. return;
  29. if (snd_BUG_ON(symbol_index < 0 ||
  30. symbol_index >= ins->symbol_table.nsymbols))
  31. return;
  32. ins->symbol_table.symbols[symbol_index].deleted = 1;
  33. if (symbol_index < ins->symbol_table.highest_frag_index) {
  34. ins->symbol_table.highest_frag_index = symbol_index;
  35. }
  36. if (symbol_index == ins->symbol_table.nsymbols - 1)
  37. ins->symbol_table.nsymbols --;
  38. if (ins->symbol_table.highest_frag_index > ins->symbol_table.nsymbols) {
  39. ins->symbol_table.highest_frag_index = ins->symbol_table.nsymbols;
  40. }
  41. }
  42. #ifdef CONFIG_SND_PROC_FS
  43. static void cs46xx_dsp_proc_scb_info_read (struct snd_info_entry *entry,
  44. struct snd_info_buffer *buffer)
  45. {
  46. struct proc_scb_info * scb_info = entry->private_data;
  47. struct dsp_scb_descriptor * scb = scb_info->scb_desc;
  48. struct snd_cs46xx *chip = scb_info->chip;
  49. int j,col;
  50. void __iomem *dst = chip->region.idx[1].remap_addr + DSP_PARAMETER_BYTE_OFFSET;
  51. mutex_lock(&chip->spos_mutex);
  52. snd_iprintf(buffer,"%04x %s:\n",scb->address,scb->scb_name);
  53. for (col = 0,j = 0;j < 0x10; j++,col++) {
  54. if (col == 4) {
  55. snd_iprintf(buffer,"\n");
  56. col = 0;
  57. }
  58. snd_iprintf(buffer,"%08x ",readl(dst + (scb->address + j) * sizeof(u32)));
  59. }
  60. snd_iprintf(buffer,"\n");
  61. if (scb->parent_scb_ptr != NULL) {
  62. snd_iprintf(buffer,"parent [%s:%04x] ",
  63. scb->parent_scb_ptr->scb_name,
  64. scb->parent_scb_ptr->address);
  65. } else snd_iprintf(buffer,"parent [none] ");
  66. snd_iprintf(buffer,"sub_list_ptr [%s:%04x]\nnext_scb_ptr [%s:%04x] task_entry [%s:%04x]\n",
  67. scb->sub_list_ptr->scb_name,
  68. scb->sub_list_ptr->address,
  69. scb->next_scb_ptr->scb_name,
  70. scb->next_scb_ptr->address,
  71. scb->task_entry->symbol_name,
  72. scb->task_entry->address);
  73. snd_iprintf(buffer,"index [%d] ref_count [%d]\n",scb->index,scb->ref_count);
  74. mutex_unlock(&chip->spos_mutex);
  75. }
  76. #endif
  77. static void _dsp_unlink_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
  78. {
  79. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  80. if ( scb->parent_scb_ptr ) {
  81. /* unlink parent SCB */
  82. if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr != scb &&
  83. scb->parent_scb_ptr->next_scb_ptr != scb))
  84. return;
  85. if (scb->parent_scb_ptr->sub_list_ptr == scb) {
  86. if (scb->next_scb_ptr == ins->the_null_scb) {
  87. /* last and only node in parent sublist */
  88. scb->parent_scb_ptr->sub_list_ptr = scb->sub_list_ptr;
  89. if (scb->sub_list_ptr != ins->the_null_scb) {
  90. scb->sub_list_ptr->parent_scb_ptr = scb->parent_scb_ptr;
  91. }
  92. scb->sub_list_ptr = ins->the_null_scb;
  93. } else {
  94. /* first node in parent sublist */
  95. scb->parent_scb_ptr->sub_list_ptr = scb->next_scb_ptr;
  96. if (scb->next_scb_ptr != ins->the_null_scb) {
  97. /* update next node parent ptr. */
  98. scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr;
  99. }
  100. scb->next_scb_ptr = ins->the_null_scb;
  101. }
  102. } else {
  103. scb->parent_scb_ptr->next_scb_ptr = scb->next_scb_ptr;
  104. if (scb->next_scb_ptr != ins->the_null_scb) {
  105. /* update next node parent ptr. */
  106. scb->next_scb_ptr->parent_scb_ptr = scb->parent_scb_ptr;
  107. }
  108. scb->next_scb_ptr = ins->the_null_scb;
  109. }
  110. /* update parent first entry in DSP RAM */
  111. cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
  112. /* then update entry in DSP RAM */
  113. cs46xx_dsp_spos_update_scb(chip,scb);
  114. scb->parent_scb_ptr = NULL;
  115. }
  116. }
  117. static void _dsp_clear_sample_buffer (struct snd_cs46xx *chip, u32 sample_buffer_addr,
  118. int dword_count)
  119. {
  120. void __iomem *dst = chip->region.idx[2].remap_addr + sample_buffer_addr;
  121. int i;
  122. for (i = 0; i < dword_count ; ++i ) {
  123. writel(0, dst);
  124. dst += 4;
  125. }
  126. }
  127. void cs46xx_dsp_remove_scb (struct snd_cs46xx *chip, struct dsp_scb_descriptor * scb)
  128. {
  129. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  130. unsigned long flags;
  131. /* check integrety */
  132. if (snd_BUG_ON(scb->index < 0 ||
  133. scb->index >= ins->nscb ||
  134. (ins->scbs + scb->index) != scb))
  135. return;
  136. #if 0
  137. /* can't remove a SCB with childs before
  138. removing childs first */
  139. if (snd_BUG_ON(scb->sub_list_ptr != ins->the_null_scb ||
  140. scb->next_scb_ptr != ins->the_null_scb))
  141. goto _end;
  142. #endif
  143. spin_lock_irqsave(&chip->reg_lock, flags);
  144. _dsp_unlink_scb (chip,scb);
  145. spin_unlock_irqrestore(&chip->reg_lock, flags);
  146. cs46xx_dsp_proc_free_scb_desc(scb);
  147. if (snd_BUG_ON(!scb->scb_symbol))
  148. return;
  149. remove_symbol (chip,scb->scb_symbol);
  150. ins->scbs[scb->index].deleted = 1;
  151. #ifdef CONFIG_PM_SLEEP
  152. kfree(ins->scbs[scb->index].data);
  153. ins->scbs[scb->index].data = NULL;
  154. #endif
  155. if (scb->index < ins->scb_highest_frag_index)
  156. ins->scb_highest_frag_index = scb->index;
  157. if (scb->index == ins->nscb - 1) {
  158. ins->nscb --;
  159. }
  160. if (ins->scb_highest_frag_index > ins->nscb) {
  161. ins->scb_highest_frag_index = ins->nscb;
  162. }
  163. #if 0
  164. /* !!!! THIS IS A PIECE OF SHIT MADE BY ME !!! */
  165. for(i = scb->index + 1;i < ins->nscb; ++i) {
  166. ins->scbs[i - 1].index = i - 1;
  167. }
  168. #endif
  169. }
  170. #ifdef CONFIG_SND_PROC_FS
  171. void cs46xx_dsp_proc_free_scb_desc (struct dsp_scb_descriptor * scb)
  172. {
  173. if (scb->proc_info) {
  174. struct proc_scb_info * scb_info = scb->proc_info->private_data;
  175. struct snd_cs46xx *chip = scb_info->chip;
  176. dev_dbg(chip->card->dev,
  177. "cs46xx_dsp_proc_free_scb_desc: freeing %s\n",
  178. scb->scb_name);
  179. snd_info_free_entry(scb->proc_info);
  180. scb->proc_info = NULL;
  181. kfree (scb_info);
  182. }
  183. }
  184. void cs46xx_dsp_proc_register_scb_desc (struct snd_cs46xx *chip,
  185. struct dsp_scb_descriptor * scb)
  186. {
  187. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  188. struct snd_info_entry * entry;
  189. struct proc_scb_info * scb_info;
  190. /* register to proc */
  191. if (ins->snd_card != NULL && ins->proc_dsp_dir != NULL &&
  192. scb->proc_info == NULL) {
  193. entry = snd_info_create_card_entry(ins->snd_card, scb->scb_name,
  194. ins->proc_dsp_dir);
  195. if (entry) {
  196. scb_info = kmalloc(sizeof(struct proc_scb_info), GFP_KERNEL);
  197. if (!scb_info) {
  198. snd_info_free_entry(entry);
  199. entry = NULL;
  200. goto out;
  201. }
  202. scb_info->chip = chip;
  203. scb_info->scb_desc = scb;
  204. snd_info_set_text_ops(entry, scb_info,
  205. cs46xx_dsp_proc_scb_info_read);
  206. }
  207. out:
  208. scb->proc_info = entry;
  209. }
  210. }
  211. #endif /* CONFIG_SND_PROC_FS */
  212. static struct dsp_scb_descriptor *
  213. _dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data, u32 dest,
  214. struct dsp_symbol_entry * task_entry,
  215. struct dsp_scb_descriptor * parent_scb,
  216. int scb_child_type)
  217. {
  218. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  219. struct dsp_scb_descriptor * scb;
  220. unsigned long flags;
  221. if (snd_BUG_ON(!ins->the_null_scb))
  222. return NULL;
  223. /* fill the data that will be wroten to DSP */
  224. scb_data[SCBsubListPtr] =
  225. (ins->the_null_scb->address << 0x10) | ins->the_null_scb->address;
  226. scb_data[SCBfuncEntryPtr] &= 0xFFFF0000;
  227. scb_data[SCBfuncEntryPtr] |= task_entry->address;
  228. dev_dbg(chip->card->dev, "dsp_spos: creating SCB <%s>\n", name);
  229. scb = cs46xx_dsp_create_scb(chip,name,scb_data,dest);
  230. scb->sub_list_ptr = ins->the_null_scb;
  231. scb->next_scb_ptr = ins->the_null_scb;
  232. scb->parent_scb_ptr = parent_scb;
  233. scb->task_entry = task_entry;
  234. /* update parent SCB */
  235. if (scb->parent_scb_ptr) {
  236. #if 0
  237. dev_dbg(chip->card->dev,
  238. "scb->parent_scb_ptr = %s\n",
  239. scb->parent_scb_ptr->scb_name);
  240. dev_dbg(chip->card->dev,
  241. "scb->parent_scb_ptr->next_scb_ptr = %s\n",
  242. scb->parent_scb_ptr->next_scb_ptr->scb_name);
  243. dev_dbg(chip->card->dev,
  244. "scb->parent_scb_ptr->sub_list_ptr = %s\n",
  245. scb->parent_scb_ptr->sub_list_ptr->scb_name);
  246. #endif
  247. /* link to parent SCB */
  248. if (scb_child_type == SCB_ON_PARENT_NEXT_SCB) {
  249. if (snd_BUG_ON(scb->parent_scb_ptr->next_scb_ptr !=
  250. ins->the_null_scb))
  251. return NULL;
  252. scb->parent_scb_ptr->next_scb_ptr = scb;
  253. } else if (scb_child_type == SCB_ON_PARENT_SUBLIST_SCB) {
  254. if (snd_BUG_ON(scb->parent_scb_ptr->sub_list_ptr !=
  255. ins->the_null_scb))
  256. return NULL;
  257. scb->parent_scb_ptr->sub_list_ptr = scb;
  258. } else {
  259. snd_BUG();
  260. }
  261. spin_lock_irqsave(&chip->reg_lock, flags);
  262. /* update entry in DSP RAM */
  263. cs46xx_dsp_spos_update_scb(chip,scb->parent_scb_ptr);
  264. spin_unlock_irqrestore(&chip->reg_lock, flags);
  265. }
  266. cs46xx_dsp_proc_register_scb_desc (chip,scb);
  267. return scb;
  268. }
  269. static struct dsp_scb_descriptor *
  270. cs46xx_dsp_create_generic_scb (struct snd_cs46xx *chip, char * name, u32 * scb_data,
  271. u32 dest, char * task_entry_name,
  272. struct dsp_scb_descriptor * parent_scb,
  273. int scb_child_type)
  274. {
  275. struct dsp_symbol_entry * task_entry;
  276. task_entry = cs46xx_dsp_lookup_symbol (chip,task_entry_name,
  277. SYMBOL_CODE);
  278. if (task_entry == NULL) {
  279. dev_err(chip->card->dev,
  280. "dsp_spos: symbol %s not found\n", task_entry_name);
  281. return NULL;
  282. }
  283. return _dsp_create_generic_scb (chip,name,scb_data,dest,task_entry,
  284. parent_scb,scb_child_type);
  285. }
  286. struct dsp_scb_descriptor *
  287. cs46xx_dsp_create_timing_master_scb (struct snd_cs46xx *chip)
  288. {
  289. struct dsp_scb_descriptor * scb;
  290. struct dsp_timing_master_scb timing_master_scb = {
  291. { 0,
  292. 0,
  293. 0,
  294. 0
  295. },
  296. { 0,
  297. 0,
  298. 0,
  299. 0,
  300. 0
  301. },
  302. 0,0,
  303. 0,NULL_SCB_ADDR,
  304. 0,0, /* extraSampleAccum:TMreserved */
  305. 0,0, /* codecFIFOptr:codecFIFOsyncd */
  306. 0x0001,0x8000, /* fracSampAccumQm1:TMfrmsLeftInGroup */
  307. 0x0001,0x0000, /* fracSampCorrectionQm1:TMfrmGroupLength */
  308. 0x00060000 /* nSampPerFrmQ15 */
  309. };
  310. scb = cs46xx_dsp_create_generic_scb(chip,"TimingMasterSCBInst",(u32 *)&timing_master_scb,
  311. TIMINGMASTER_SCB_ADDR,
  312. "TIMINGMASTER",NULL,SCB_NO_PARENT);
  313. return scb;
  314. }
  315. struct dsp_scb_descriptor *
  316. cs46xx_dsp_create_codec_out_scb(struct snd_cs46xx * chip, char * codec_name,
  317. u16 channel_disp, u16 fifo_addr, u16 child_scb_addr,
  318. u32 dest, struct dsp_scb_descriptor * parent_scb,
  319. int scb_child_type)
  320. {
  321. struct dsp_scb_descriptor * scb;
  322. struct dsp_codec_output_scb codec_out_scb = {
  323. { 0,
  324. 0,
  325. 0,
  326. 0
  327. },
  328. {
  329. 0,
  330. 0,
  331. 0,
  332. 0,
  333. 0
  334. },
  335. 0,0,
  336. 0,NULL_SCB_ADDR,
  337. 0, /* COstrmRsConfig */
  338. 0, /* COstrmBufPtr */
  339. channel_disp,fifo_addr, /* leftChanBaseIOaddr:rightChanIOdisp */
  340. 0x0000,0x0080, /* (!AC97!) COexpVolChangeRate:COscaleShiftCount */
  341. 0,child_scb_addr /* COreserved - need child scb to work with rom code */
  342. };
  343. scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_out_scb,
  344. dest,"S16_CODECOUTPUTTASK",parent_scb,
  345. scb_child_type);
  346. return scb;
  347. }
  348. struct dsp_scb_descriptor *
  349. cs46xx_dsp_create_codec_in_scb(struct snd_cs46xx * chip, char * codec_name,
  350. u16 channel_disp, u16 fifo_addr, u16 sample_buffer_addr,
  351. u32 dest, struct dsp_scb_descriptor * parent_scb,
  352. int scb_child_type)
  353. {
  354. struct dsp_scb_descriptor * scb;
  355. struct dsp_codec_input_scb codec_input_scb = {
  356. { 0,
  357. 0,
  358. 0,
  359. 0
  360. },
  361. {
  362. 0,
  363. 0,
  364. 0,
  365. 0,
  366. 0
  367. },
  368. #if 0 /* cs4620 */
  369. SyncIOSCB,NULL_SCB_ADDR
  370. #else
  371. 0 , 0,
  372. #endif
  373. 0,0,
  374. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64, /* strmRsConfig */
  375. sample_buffer_addr << 0x10, /* strmBufPtr; defined as a dword ptr, used as a byte ptr */
  376. channel_disp,fifo_addr, /* (!AC97!) leftChanBaseINaddr=AC97primary
  377. link input slot 3 :rightChanINdisp=""slot 4 */
  378. 0x0000,0x0000, /* (!AC97!) ????:scaleShiftCount; no shift needed
  379. because AC97 is already 20 bits */
  380. 0x80008000 /* ??clw cwcgame.scb has 0 */
  381. };
  382. scb = cs46xx_dsp_create_generic_scb(chip,codec_name,(u32 *)&codec_input_scb,
  383. dest,"S16_CODECINPUTTASK",parent_scb,
  384. scb_child_type);
  385. return scb;
  386. }
  387. static struct dsp_scb_descriptor *
  388. cs46xx_dsp_create_pcm_reader_scb(struct snd_cs46xx * chip, char * scb_name,
  389. u16 sample_buffer_addr, u32 dest,
  390. int virtual_channel, u32 playback_hw_addr,
  391. struct dsp_scb_descriptor * parent_scb,
  392. int scb_child_type)
  393. {
  394. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  395. struct dsp_scb_descriptor * scb;
  396. struct dsp_generic_scb pcm_reader_scb = {
  397. /*
  398. Play DMA Task xfers data from host buffer to SP buffer
  399. init/runtime variables:
  400. PlayAC: Play Audio Data Conversion - SCB loc: 2nd dword, mask: 0x0000F000L
  401. DATA_FMT_16BIT_ST_LTLEND(0x00000000L) from 16-bit stereo, little-endian
  402. DATA_FMT_8_BIT_ST_SIGNED(0x00001000L) from 8-bit stereo, signed
  403. DATA_FMT_16BIT_MN_LTLEND(0x00002000L) from 16-bit mono, little-endian
  404. DATA_FMT_8_BIT_MN_SIGNED(0x00003000L) from 8-bit mono, signed
  405. DATA_FMT_16BIT_ST_BIGEND(0x00004000L) from 16-bit stereo, big-endian
  406. DATA_FMT_16BIT_MN_BIGEND(0x00006000L) from 16-bit mono, big-endian
  407. DATA_FMT_8_BIT_ST_UNSIGNED(0x00009000L) from 8-bit stereo, unsigned
  408. DATA_FMT_8_BIT_MN_UNSIGNED(0x0000b000L) from 8-bit mono, unsigned
  409. ? Other combinations possible from:
  410. DMA_RQ_C2_AUDIO_CONVERT_MASK 0x0000F000L
  411. DMA_RQ_C2_AC_NONE 0x00000000L
  412. DMA_RQ_C2_AC_8_TO_16_BIT 0x00001000L
  413. DMA_RQ_C2_AC_MONO_TO_STEREO 0x00002000L
  414. DMA_RQ_C2_AC_ENDIAN_CONVERT 0x00004000L
  415. DMA_RQ_C2_AC_SIGNED_CONVERT 0x00008000L
  416. HostBuffAddr: Host Buffer Physical Byte Address - SCB loc:3rd dword, Mask: 0xFFFFFFFFL
  417. aligned to dword boundary
  418. */
  419. /* Basic (non scatter/gather) DMA requestor (4 ints) */
  420. { DMA_RQ_C1_SOURCE_ON_HOST + /* source buffer is on the host */
  421. DMA_RQ_C1_SOURCE_MOD1024 + /* source buffer is 1024 dwords (4096 bytes) */
  422. DMA_RQ_C1_DEST_MOD32 + /* dest buffer(PCMreaderBuf) is 32 dwords*/
  423. DMA_RQ_C1_WRITEBACK_SRC_FLAG + /* ?? */
  424. DMA_RQ_C1_WRITEBACK_DEST_FLAG + /* ?? */
  425. 15, /* DwordCount-1: picked 16 for DwordCount because Jim */
  426. /* Barnette said that is what we should use since */
  427. /* we are not running in optimized mode? */
  428. DMA_RQ_C2_AC_NONE +
  429. DMA_RQ_C2_SIGNAL_SOURCE_PINGPONG + /* set play interrupt (bit0) in HISR when source */
  430. /* buffer (on host) crosses half-way point */
  431. virtual_channel, /* Play DMA channel arbitrarily set to 0 */
  432. playback_hw_addr, /* HostBuffAddr (source) */
  433. DMA_RQ_SD_SP_SAMPLE_ADDR + /* destination buffer is in SP Sample Memory */
  434. sample_buffer_addr /* SP Buffer Address (destination) */
  435. },
  436. /* Scatter/gather DMA requestor extension (5 ints) */
  437. {
  438. 0,
  439. 0,
  440. 0,
  441. 0,
  442. 0
  443. },
  444. /* Sublist pointer & next stream control block (SCB) link. */
  445. NULL_SCB_ADDR,NULL_SCB_ADDR,
  446. /* Pointer to this tasks parameter block & stream function pointer */
  447. 0,NULL_SCB_ADDR,
  448. /* rsConfig register for stream buffer (rsDMA reg. is loaded from basicReq.daw */
  449. /* for incoming streams, or basicReq.saw, for outgoing streams) */
  450. RSCONFIG_DMA_ENABLE + /* enable DMA */
  451. (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) + /* MAX_DMA_SIZE picked to be 19 since SPUD */
  452. /* uses it for some reason */
  453. ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) + /* stream number = SCBaddr/16 */
  454. RSCONFIG_SAMPLE_16STEREO +
  455. RSCONFIG_MODULO_32, /* dest buffer(PCMreaderBuf) is 32 dwords (256 bytes) */
  456. /* Stream sample pointer & MAC-unit mode for this stream */
  457. (sample_buffer_addr << 0x10),
  458. /* Fractional increment per output sample in the input sample buffer */
  459. 0,
  460. {
  461. /* Standard stereo volume control
  462. default muted */
  463. 0xffff,0xffff,
  464. 0xffff,0xffff
  465. }
  466. };
  467. if (ins->null_algorithm == NULL) {
  468. ins->null_algorithm = cs46xx_dsp_lookup_symbol (chip,"NULLALGORITHM",
  469. SYMBOL_CODE);
  470. if (ins->null_algorithm == NULL) {
  471. dev_err(chip->card->dev,
  472. "dsp_spos: symbol NULLALGORITHM not found\n");
  473. return NULL;
  474. }
  475. }
  476. scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_reader_scb,
  477. dest,ins->null_algorithm,parent_scb,
  478. scb_child_type);
  479. return scb;
  480. }
  481. #define GOF_PER_SEC 200
  482. struct dsp_scb_descriptor *
  483. cs46xx_dsp_create_src_task_scb(struct snd_cs46xx * chip, char * scb_name,
  484. int rate,
  485. u16 src_buffer_addr,
  486. u16 src_delay_buffer_addr, u32 dest,
  487. struct dsp_scb_descriptor * parent_scb,
  488. int scb_child_type,
  489. int pass_through)
  490. {
  491. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  492. struct dsp_scb_descriptor * scb;
  493. unsigned int tmp1, tmp2;
  494. unsigned int phiIncr;
  495. unsigned int correctionPerGOF, correctionPerSec;
  496. dev_dbg(chip->card->dev, "dsp_spos: setting %s rate to %u\n",
  497. scb_name, rate);
  498. /*
  499. * Compute the values used to drive the actual sample rate conversion.
  500. * The following formulas are being computed, using inline assembly
  501. * since we need to use 64 bit arithmetic to compute the values:
  502. *
  503. * phiIncr = floor((Fs,in * 2^26) / Fs,out)
  504. * correctionPerGOF = floor((Fs,in * 2^26 - Fs,out * phiIncr) /
  505. * GOF_PER_SEC)
  506. * ulCorrectionPerSec = Fs,in * 2^26 - Fs,out * phiIncr -M
  507. * GOF_PER_SEC * correctionPerGOF
  508. *
  509. * i.e.
  510. *
  511. * phiIncr:other = dividend:remainder((Fs,in * 2^26) / Fs,out)
  512. * correctionPerGOF:correctionPerSec =
  513. * dividend:remainder(ulOther / GOF_PER_SEC)
  514. */
  515. tmp1 = rate << 16;
  516. phiIncr = tmp1 / 48000;
  517. tmp1 -= phiIncr * 48000;
  518. tmp1 <<= 10;
  519. phiIncr <<= 10;
  520. tmp2 = tmp1 / 48000;
  521. phiIncr += tmp2;
  522. tmp1 -= tmp2 * 48000;
  523. correctionPerGOF = tmp1 / GOF_PER_SEC;
  524. tmp1 -= correctionPerGOF * GOF_PER_SEC;
  525. correctionPerSec = tmp1;
  526. {
  527. struct dsp_src_task_scb src_task_scb = {
  528. 0x0028,0x00c8,
  529. 0x5555,0x0000,
  530. 0x0000,0x0000,
  531. src_buffer_addr,1,
  532. correctionPerGOF,correctionPerSec,
  533. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,
  534. 0x0000,src_delay_buffer_addr,
  535. 0x0,
  536. 0x080,(src_delay_buffer_addr + (24 * 4)),
  537. 0,0, /* next_scb, sub_list_ptr */
  538. 0,0, /* entry, this_spb */
  539. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
  540. src_buffer_addr << 0x10,
  541. phiIncr,
  542. {
  543. 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left,
  544. 0xffff - ins->dac_volume_right,0xffff - ins->dac_volume_left
  545. }
  546. };
  547. if (ins->s16_up == NULL) {
  548. ins->s16_up = cs46xx_dsp_lookup_symbol (chip,"S16_UPSRC",
  549. SYMBOL_CODE);
  550. if (ins->s16_up == NULL) {
  551. dev_err(chip->card->dev,
  552. "dsp_spos: symbol S16_UPSRC not found\n");
  553. return NULL;
  554. }
  555. }
  556. /* clear buffers */
  557. _dsp_clear_sample_buffer (chip,src_buffer_addr,8);
  558. _dsp_clear_sample_buffer (chip,src_delay_buffer_addr,32);
  559. if (pass_through) {
  560. /* wont work with any other rate than
  561. the native DSP rate */
  562. snd_BUG_ON(rate != 48000);
  563. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
  564. dest,"DMAREADER",parent_scb,
  565. scb_child_type);
  566. } else {
  567. scb = _dsp_create_generic_scb(chip,scb_name,(u32 *)&src_task_scb,
  568. dest,ins->s16_up,parent_scb,
  569. scb_child_type);
  570. }
  571. }
  572. return scb;
  573. }
  574. #if 0 /* not used */
  575. struct dsp_scb_descriptor *
  576. cs46xx_dsp_create_filter_scb(struct snd_cs46xx * chip, char * scb_name,
  577. u16 buffer_addr, u32 dest,
  578. struct dsp_scb_descriptor * parent_scb,
  579. int scb_child_type) {
  580. struct dsp_scb_descriptor * scb;
  581. struct dsp_filter_scb filter_scb = {
  582. .a0_right = 0x41a9,
  583. .a0_left = 0x41a9,
  584. .a1_right = 0xb8e4,
  585. .a1_left = 0xb8e4,
  586. .a2_right = 0x3e55,
  587. .a2_left = 0x3e55,
  588. .filter_unused3 = 0x0000,
  589. .filter_unused2 = 0x0000,
  590. .output_buf_ptr = buffer_addr,
  591. .init = 0x000,
  592. .prev_sample_output1 = 0x00000000,
  593. .prev_sample_output2 = 0x00000000,
  594. .prev_sample_input1 = 0x00000000,
  595. .prev_sample_input2 = 0x00000000,
  596. .next_scb_ptr = 0x0000,
  597. .sub_list_ptr = 0x0000,
  598. .entry_point = 0x0000,
  599. .spb_ptr = 0x0000,
  600. .b0_right = 0x0e38,
  601. .b0_left = 0x0e38,
  602. .b1_right = 0x1c71,
  603. .b1_left = 0x1c71,
  604. .b2_right = 0x0e38,
  605. .b2_left = 0x0e38,
  606. };
  607. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&filter_scb,
  608. dest,"FILTERTASK",parent_scb,
  609. scb_child_type);
  610. return scb;
  611. }
  612. #endif /* not used */
  613. struct dsp_scb_descriptor *
  614. cs46xx_dsp_create_mix_only_scb(struct snd_cs46xx * chip, char * scb_name,
  615. u16 mix_buffer_addr, u32 dest,
  616. struct dsp_scb_descriptor * parent_scb,
  617. int scb_child_type)
  618. {
  619. struct dsp_scb_descriptor * scb;
  620. struct dsp_mix_only_scb master_mix_scb = {
  621. /* 0 */ { 0,
  622. /* 1 */ 0,
  623. /* 2 */ mix_buffer_addr,
  624. /* 3 */ 0
  625. /* */ },
  626. {
  627. /* 4 */ 0,
  628. /* 5 */ 0,
  629. /* 6 */ 0,
  630. /* 7 */ 0,
  631. /* 8 */ 0x00000080
  632. },
  633. /* 9 */ 0,0,
  634. /* A */ 0,0,
  635. /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_32,
  636. /* C */ (mix_buffer_addr + (16 * 4)) << 0x10,
  637. /* D */ 0,
  638. {
  639. /* E */ 0x8000,0x8000,
  640. /* F */ 0x8000,0x8000
  641. }
  642. };
  643. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&master_mix_scb,
  644. dest,"S16_MIX",parent_scb,
  645. scb_child_type);
  646. return scb;
  647. }
  648. struct dsp_scb_descriptor *
  649. cs46xx_dsp_create_mix_to_ostream_scb(struct snd_cs46xx * chip, char * scb_name,
  650. u16 mix_buffer_addr, u16 writeback_spb, u32 dest,
  651. struct dsp_scb_descriptor * parent_scb,
  652. int scb_child_type)
  653. {
  654. struct dsp_scb_descriptor * scb;
  655. struct dsp_mix2_ostream_scb mix2_ostream_scb = {
  656. /* Basic (non scatter/gather) DMA requestor (4 ints) */
  657. {
  658. DMA_RQ_C1_SOURCE_MOD64 +
  659. DMA_RQ_C1_DEST_ON_HOST +
  660. DMA_RQ_C1_DEST_MOD1024 +
  661. DMA_RQ_C1_WRITEBACK_SRC_FLAG +
  662. DMA_RQ_C1_WRITEBACK_DEST_FLAG +
  663. 15,
  664. DMA_RQ_C2_AC_NONE +
  665. DMA_RQ_C2_SIGNAL_DEST_PINGPONG +
  666. CS46XX_DSP_CAPTURE_CHANNEL,
  667. DMA_RQ_SD_SP_SAMPLE_ADDR +
  668. mix_buffer_addr,
  669. 0x0
  670. },
  671. { 0, 0, 0, 0, 0, },
  672. 0,0,
  673. 0,writeback_spb,
  674. RSCONFIG_DMA_ENABLE +
  675. (19 << RSCONFIG_MAX_DMA_SIZE_SHIFT) +
  676. ((dest >> 4) << RSCONFIG_STREAM_NUM_SHIFT) +
  677. RSCONFIG_DMA_TO_HOST +
  678. RSCONFIG_SAMPLE_16STEREO +
  679. RSCONFIG_MODULO_64,
  680. (mix_buffer_addr + (32 * 4)) << 0x10,
  681. 1,0,
  682. 0x0001,0x0080,
  683. 0xFFFF,0
  684. };
  685. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&mix2_ostream_scb,
  686. dest,"S16_MIX_TO_OSTREAM",parent_scb,
  687. scb_child_type);
  688. return scb;
  689. }
  690. struct dsp_scb_descriptor *
  691. cs46xx_dsp_create_vari_decimate_scb(struct snd_cs46xx * chip,char * scb_name,
  692. u16 vari_buffer_addr0,
  693. u16 vari_buffer_addr1,
  694. u32 dest,
  695. struct dsp_scb_descriptor * parent_scb,
  696. int scb_child_type)
  697. {
  698. struct dsp_scb_descriptor * scb;
  699. struct dsp_vari_decimate_scb vari_decimate_scb = {
  700. 0x0028,0x00c8,
  701. 0x5555,0x0000,
  702. 0x0000,0x0000,
  703. vari_buffer_addr0,vari_buffer_addr1,
  704. 0x0028,0x00c8,
  705. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256,
  706. 0xFF800000,
  707. 0,
  708. 0x0080,vari_buffer_addr1 + (25 * 4),
  709. 0,0,
  710. 0,0,
  711. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_8,
  712. vari_buffer_addr0 << 0x10,
  713. 0x04000000,
  714. {
  715. 0x8000,0x8000,
  716. 0xFFFF,0xFFFF
  717. }
  718. };
  719. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&vari_decimate_scb,
  720. dest,"VARIDECIMATE",parent_scb,
  721. scb_child_type);
  722. return scb;
  723. }
  724. static struct dsp_scb_descriptor *
  725. cs46xx_dsp_create_pcm_serial_input_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  726. struct dsp_scb_descriptor * input_scb,
  727. struct dsp_scb_descriptor * parent_scb,
  728. int scb_child_type)
  729. {
  730. struct dsp_scb_descriptor * scb;
  731. struct dsp_pcm_serial_input_scb pcm_serial_input_scb = {
  732. { 0,
  733. 0,
  734. 0,
  735. 0
  736. },
  737. {
  738. 0,
  739. 0,
  740. 0,
  741. 0,
  742. 0
  743. },
  744. 0,0,
  745. 0,0,
  746. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_16,
  747. 0,
  748. /* 0xD */ 0,input_scb->address,
  749. {
  750. /* 0xE */ 0x8000,0x8000,
  751. /* 0xF */ 0x8000,0x8000
  752. }
  753. };
  754. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&pcm_serial_input_scb,
  755. dest,"PCMSERIALINPUTTASK",parent_scb,
  756. scb_child_type);
  757. return scb;
  758. }
  759. static struct dsp_scb_descriptor *
  760. cs46xx_dsp_create_asynch_fg_tx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  761. u16 hfg_scb_address,
  762. u16 asynch_buffer_address,
  763. struct dsp_scb_descriptor * parent_scb,
  764. int scb_child_type)
  765. {
  766. struct dsp_scb_descriptor * scb;
  767. struct dsp_asynch_fg_tx_scb asynch_fg_tx_scb = {
  768. 0xfc00,0x03ff, /* Prototype sample buffer size of 256 dwords */
  769. 0x0058,0x0028, /* Min Delta 7 dwords == 28 bytes */
  770. /* : Max delta 25 dwords == 100 bytes */
  771. 0,hfg_scb_address, /* Point to HFG task SCB */
  772. 0,0, /* Initialize current Delta and Consumer ptr adjustment count */
  773. 0, /* Initialize accumulated Phi to 0 */
  774. 0,0x2aab, /* Const 1/3 */
  775. {
  776. 0, /* Define the unused elements */
  777. 0,
  778. 0
  779. },
  780. 0,0,
  781. 0,dest + AFGTxAccumPhi,
  782. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_256, /* Stereo, 256 dword */
  783. (asynch_buffer_address) << 0x10, /* This should be automagically synchronized
  784. to the producer pointer */
  785. /* There is no correct initial value, it will depend upon the detected
  786. rate etc */
  787. 0x18000000, /* Phi increment for approx 32k operation */
  788. 0x8000,0x8000, /* Volume controls are unused at this time */
  789. 0x8000,0x8000
  790. };
  791. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_tx_scb,
  792. dest,"ASYNCHFGTXCODE",parent_scb,
  793. scb_child_type);
  794. return scb;
  795. }
  796. struct dsp_scb_descriptor *
  797. cs46xx_dsp_create_asynch_fg_rx_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  798. u16 hfg_scb_address,
  799. u16 asynch_buffer_address,
  800. struct dsp_scb_descriptor * parent_scb,
  801. int scb_child_type)
  802. {
  803. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  804. struct dsp_scb_descriptor * scb;
  805. struct dsp_asynch_fg_rx_scb asynch_fg_rx_scb = {
  806. 0xfe00,0x01ff, /* Prototype sample buffer size of 128 dwords */
  807. 0x0064,0x001c, /* Min Delta 7 dwords == 28 bytes */
  808. /* : Max delta 25 dwords == 100 bytes */
  809. 0,hfg_scb_address, /* Point to HFG task SCB */
  810. 0,0, /* Initialize current Delta and Consumer ptr adjustment count */
  811. {
  812. 0, /* Define the unused elements */
  813. 0,
  814. 0,
  815. 0,
  816. 0
  817. },
  818. 0,0,
  819. 0,dest,
  820. RSCONFIG_MODULO_128 |
  821. RSCONFIG_SAMPLE_16STEREO, /* Stereo, 128 dword */
  822. ( (asynch_buffer_address + (16 * 4)) << 0x10), /* This should be automagically
  823. synchrinized to the producer pointer */
  824. /* There is no correct initial value, it will depend upon the detected
  825. rate etc */
  826. 0x18000000,
  827. /* Set IEC958 input volume */
  828. 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
  829. 0xffff - ins->spdif_input_volume_right,0xffff - ins->spdif_input_volume_left,
  830. };
  831. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&asynch_fg_rx_scb,
  832. dest,"ASYNCHFGRXCODE",parent_scb,
  833. scb_child_type);
  834. return scb;
  835. }
  836. #if 0 /* not used */
  837. struct dsp_scb_descriptor *
  838. cs46xx_dsp_create_output_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  839. u16 snoop_buffer_address,
  840. struct dsp_scb_descriptor * snoop_scb,
  841. struct dsp_scb_descriptor * parent_scb,
  842. int scb_child_type)
  843. {
  844. struct dsp_scb_descriptor * scb;
  845. struct dsp_output_snoop_scb output_snoop_scb = {
  846. { 0, /* not used. Zero */
  847. 0,
  848. 0,
  849. 0,
  850. },
  851. {
  852. 0, /* not used. Zero */
  853. 0,
  854. 0,
  855. 0,
  856. 0
  857. },
  858. 0,0,
  859. 0,0,
  860. RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
  861. snoop_buffer_address << 0x10,
  862. 0,0,
  863. 0,
  864. 0,snoop_scb->address
  865. };
  866. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&output_snoop_scb,
  867. dest,"OUTPUTSNOOP",parent_scb,
  868. scb_child_type);
  869. return scb;
  870. }
  871. #endif /* not used */
  872. struct dsp_scb_descriptor *
  873. cs46xx_dsp_create_spio_write_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  874. struct dsp_scb_descriptor * parent_scb,
  875. int scb_child_type)
  876. {
  877. struct dsp_scb_descriptor * scb;
  878. struct dsp_spio_write_scb spio_write_scb = {
  879. 0,0, /* SPIOWAddress2:SPIOWAddress1; */
  880. 0, /* SPIOWData1; */
  881. 0, /* SPIOWData2; */
  882. 0,0, /* SPIOWAddress4:SPIOWAddress3; */
  883. 0, /* SPIOWData3; */
  884. 0, /* SPIOWData4; */
  885. 0,0, /* SPIOWDataPtr:Unused1; */
  886. { 0,0 }, /* Unused2[2]; */
  887. 0,0, /* SPIOWChildPtr:SPIOWSiblingPtr; */
  888. 0,0, /* SPIOWThisPtr:SPIOWEntryPoint; */
  889. {
  890. 0,
  891. 0,
  892. 0,
  893. 0,
  894. 0 /* Unused3[5]; */
  895. }
  896. };
  897. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&spio_write_scb,
  898. dest,"SPIOWRITE",parent_scb,
  899. scb_child_type);
  900. return scb;
  901. }
  902. struct dsp_scb_descriptor *
  903. cs46xx_dsp_create_magic_snoop_scb(struct snd_cs46xx * chip, char * scb_name, u32 dest,
  904. u16 snoop_buffer_address,
  905. struct dsp_scb_descriptor * snoop_scb,
  906. struct dsp_scb_descriptor * parent_scb,
  907. int scb_child_type)
  908. {
  909. struct dsp_scb_descriptor * scb;
  910. struct dsp_magic_snoop_task magic_snoop_scb = {
  911. /* 0 */ 0, /* i0 */
  912. /* 1 */ 0, /* i1 */
  913. /* 2 */ snoop_buffer_address << 0x10,
  914. /* 3 */ 0,snoop_scb->address,
  915. /* 4 */ 0, /* i3 */
  916. /* 5 */ 0, /* i4 */
  917. /* 6 */ 0, /* i5 */
  918. /* 7 */ 0, /* i6 */
  919. /* 8 */ 0, /* i7 */
  920. /* 9 */ 0,0, /* next_scb, sub_list_ptr */
  921. /* A */ 0,0, /* entry_point, this_ptr */
  922. /* B */ RSCONFIG_SAMPLE_16STEREO + RSCONFIG_MODULO_64,
  923. /* C */ snoop_buffer_address << 0x10,
  924. /* D */ 0,
  925. /* E */ { 0x8000,0x8000,
  926. /* F */ 0xffff,0xffff
  927. }
  928. };
  929. scb = cs46xx_dsp_create_generic_scb(chip,scb_name,(u32 *)&magic_snoop_scb,
  930. dest,"MAGICSNOOPTASK",parent_scb,
  931. scb_child_type);
  932. return scb;
  933. }
  934. static struct dsp_scb_descriptor *
  935. find_next_free_scb (struct snd_cs46xx * chip, struct dsp_scb_descriptor * from)
  936. {
  937. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  938. struct dsp_scb_descriptor * scb = from;
  939. while (scb->next_scb_ptr != ins->the_null_scb) {
  940. if (snd_BUG_ON(!scb->next_scb_ptr))
  941. return NULL;
  942. scb = scb->next_scb_ptr;
  943. }
  944. return scb;
  945. }
  946. static const u32 pcm_reader_buffer_addr[DSP_MAX_PCM_CHANNELS] = {
  947. 0x0600, /* 1 */
  948. 0x1500, /* 2 */
  949. 0x1580, /* 3 */
  950. 0x1600, /* 4 */
  951. 0x1680, /* 5 */
  952. 0x1700, /* 6 */
  953. 0x1780, /* 7 */
  954. 0x1800, /* 8 */
  955. 0x1880, /* 9 */
  956. 0x1900, /* 10 */
  957. 0x1980, /* 11 */
  958. 0x1A00, /* 12 */
  959. 0x1A80, /* 13 */
  960. 0x1B00, /* 14 */
  961. 0x1B80, /* 15 */
  962. 0x1C00, /* 16 */
  963. 0x1C80, /* 17 */
  964. 0x1D00, /* 18 */
  965. 0x1D80, /* 19 */
  966. 0x1E00, /* 20 */
  967. 0x1E80, /* 21 */
  968. 0x1F00, /* 22 */
  969. 0x1F80, /* 23 */
  970. 0x2000, /* 24 */
  971. 0x2080, /* 25 */
  972. 0x2100, /* 26 */
  973. 0x2180, /* 27 */
  974. 0x2200, /* 28 */
  975. 0x2280, /* 29 */
  976. 0x2300, /* 30 */
  977. 0x2380, /* 31 */
  978. 0x2400, /* 32 */
  979. };
  980. static const u32 src_output_buffer_addr[DSP_MAX_SRC_NR] = {
  981. 0x2B80,
  982. 0x2BA0,
  983. 0x2BC0,
  984. 0x2BE0,
  985. 0x2D00,
  986. 0x2D20,
  987. 0x2D40,
  988. 0x2D60,
  989. 0x2D80,
  990. 0x2DA0,
  991. 0x2DC0,
  992. 0x2DE0,
  993. 0x2E00,
  994. 0x2E20
  995. };
  996. static const u32 src_delay_buffer_addr[DSP_MAX_SRC_NR] = {
  997. 0x2480,
  998. 0x2500,
  999. 0x2580,
  1000. 0x2600,
  1001. 0x2680,
  1002. 0x2700,
  1003. 0x2780,
  1004. 0x2800,
  1005. 0x2880,
  1006. 0x2900,
  1007. 0x2980,
  1008. 0x2A00,
  1009. 0x2A80,
  1010. 0x2B00
  1011. };
  1012. struct dsp_pcm_channel_descriptor *
  1013. cs46xx_dsp_create_pcm_channel (struct snd_cs46xx * chip,
  1014. u32 sample_rate, void * private_data,
  1015. u32 hw_dma_addr,
  1016. int pcm_channel_id)
  1017. {
  1018. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1019. struct dsp_scb_descriptor * src_scb = NULL, * pcm_scb, * mixer_scb = NULL;
  1020. struct dsp_scb_descriptor * src_parent_scb = NULL;
  1021. /* struct dsp_scb_descriptor * pcm_parent_scb; */
  1022. char scb_name[DSP_MAX_SCB_NAME];
  1023. int i, pcm_index = -1, insert_point, src_index = -1, pass_through = 0;
  1024. unsigned long flags;
  1025. switch (pcm_channel_id) {
  1026. case DSP_PCM_MAIN_CHANNEL:
  1027. mixer_scb = ins->master_mix_scb;
  1028. break;
  1029. case DSP_PCM_REAR_CHANNEL:
  1030. mixer_scb = ins->rear_mix_scb;
  1031. break;
  1032. case DSP_PCM_CENTER_LFE_CHANNEL:
  1033. mixer_scb = ins->center_lfe_mix_scb;
  1034. break;
  1035. case DSP_PCM_S71_CHANNEL:
  1036. /* TODO */
  1037. snd_BUG();
  1038. break;
  1039. case DSP_IEC958_CHANNEL:
  1040. if (snd_BUG_ON(!ins->asynch_tx_scb))
  1041. return NULL;
  1042. mixer_scb = ins->asynch_tx_scb;
  1043. /* if sample rate is set to 48khz we pass
  1044. the Sample Rate Converted (which could
  1045. alter the raw data stream ...) */
  1046. if (sample_rate == 48000) {
  1047. dev_dbg(chip->card->dev, "IEC958 pass through\n");
  1048. /* Hack to bypass creating a new SRC */
  1049. pass_through = 1;
  1050. }
  1051. break;
  1052. default:
  1053. snd_BUG();
  1054. return NULL;
  1055. }
  1056. /* default sample rate is 44100 */
  1057. if (!sample_rate) sample_rate = 44100;
  1058. /* search for a already created SRC SCB with the same sample rate */
  1059. for (i = 0; i < DSP_MAX_PCM_CHANNELS &&
  1060. (pcm_index == -1 || src_scb == NULL); ++i) {
  1061. /* virtual channel reserved
  1062. for capture */
  1063. if (i == CS46XX_DSP_CAPTURE_CHANNEL) continue;
  1064. if (ins->pcm_channels[i].active) {
  1065. if (!src_scb &&
  1066. ins->pcm_channels[i].sample_rate == sample_rate &&
  1067. ins->pcm_channels[i].mixer_scb == mixer_scb) {
  1068. src_scb = ins->pcm_channels[i].src_scb;
  1069. ins->pcm_channels[i].src_scb->ref_count ++;
  1070. src_index = ins->pcm_channels[i].src_slot;
  1071. }
  1072. } else if (pcm_index == -1) {
  1073. pcm_index = i;
  1074. }
  1075. }
  1076. if (pcm_index == -1) {
  1077. dev_err(chip->card->dev, "dsp_spos: no free PCM channel\n");
  1078. return NULL;
  1079. }
  1080. if (src_scb == NULL) {
  1081. if (ins->nsrc_scb >= DSP_MAX_SRC_NR) {
  1082. dev_err(chip->card->dev,
  1083. "dsp_spos: too many SRC instances\n!");
  1084. return NULL;
  1085. }
  1086. /* find a free slot */
  1087. for (i = 0; i < DSP_MAX_SRC_NR; ++i) {
  1088. if (ins->src_scb_slots[i] == 0) {
  1089. src_index = i;
  1090. ins->src_scb_slots[i] = 1;
  1091. break;
  1092. }
  1093. }
  1094. if (snd_BUG_ON(src_index == -1))
  1095. return NULL;
  1096. /* we need to create a new SRC SCB */
  1097. if (mixer_scb->sub_list_ptr == ins->the_null_scb) {
  1098. src_parent_scb = mixer_scb;
  1099. insert_point = SCB_ON_PARENT_SUBLIST_SCB;
  1100. } else {
  1101. src_parent_scb = find_next_free_scb(chip,mixer_scb->sub_list_ptr);
  1102. insert_point = SCB_ON_PARENT_NEXT_SCB;
  1103. }
  1104. snprintf (scb_name,DSP_MAX_SCB_NAME,"SrcTask_SCB%d",src_index);
  1105. dev_dbg(chip->card->dev,
  1106. "dsp_spos: creating SRC \"%s\"\n", scb_name);
  1107. src_scb = cs46xx_dsp_create_src_task_scb(chip,scb_name,
  1108. sample_rate,
  1109. src_output_buffer_addr[src_index],
  1110. src_delay_buffer_addr[src_index],
  1111. /* 0x400 - 0x600 source SCBs */
  1112. 0x400 + (src_index * 0x10) ,
  1113. src_parent_scb,
  1114. insert_point,
  1115. pass_through);
  1116. if (!src_scb) {
  1117. dev_err(chip->card->dev,
  1118. "dsp_spos: failed to create SRCtaskSCB\n");
  1119. return NULL;
  1120. }
  1121. /* cs46xx_dsp_set_src_sample_rate(chip,src_scb,sample_rate); */
  1122. ins->nsrc_scb ++;
  1123. }
  1124. snprintf (scb_name,DSP_MAX_SCB_NAME,"PCMReader_SCB%d",pcm_index);
  1125. dev_dbg(chip->card->dev, "dsp_spos: creating PCM \"%s\" (%d)\n",
  1126. scb_name, pcm_channel_id);
  1127. pcm_scb = cs46xx_dsp_create_pcm_reader_scb(chip,scb_name,
  1128. pcm_reader_buffer_addr[pcm_index],
  1129. /* 0x200 - 400 PCMreader SCBs */
  1130. (pcm_index * 0x10) + 0x200,
  1131. pcm_index, /* virtual channel 0-31 */
  1132. hw_dma_addr, /* pcm hw addr */
  1133. NULL, /* parent SCB ptr */
  1134. 0 /* insert point */
  1135. );
  1136. if (!pcm_scb) {
  1137. dev_err(chip->card->dev,
  1138. "dsp_spos: failed to create PCMreaderSCB\n");
  1139. return NULL;
  1140. }
  1141. spin_lock_irqsave(&chip->reg_lock, flags);
  1142. ins->pcm_channels[pcm_index].sample_rate = sample_rate;
  1143. ins->pcm_channels[pcm_index].pcm_reader_scb = pcm_scb;
  1144. ins->pcm_channels[pcm_index].src_scb = src_scb;
  1145. ins->pcm_channels[pcm_index].unlinked = 1;
  1146. ins->pcm_channels[pcm_index].private_data = private_data;
  1147. ins->pcm_channels[pcm_index].src_slot = src_index;
  1148. ins->pcm_channels[pcm_index].active = 1;
  1149. ins->pcm_channels[pcm_index].pcm_slot = pcm_index;
  1150. ins->pcm_channels[pcm_index].mixer_scb = mixer_scb;
  1151. ins->npcm_channels ++;
  1152. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1153. return (ins->pcm_channels + pcm_index);
  1154. }
  1155. int cs46xx_dsp_pcm_channel_set_period (struct snd_cs46xx * chip,
  1156. struct dsp_pcm_channel_descriptor * pcm_channel,
  1157. int period_size)
  1158. {
  1159. u32 temp = snd_cs46xx_peek (chip,pcm_channel->pcm_reader_scb->address << 2);
  1160. temp &= ~DMA_RQ_C1_SOURCE_SIZE_MASK;
  1161. switch (period_size) {
  1162. case 2048:
  1163. temp |= DMA_RQ_C1_SOURCE_MOD1024;
  1164. break;
  1165. case 1024:
  1166. temp |= DMA_RQ_C1_SOURCE_MOD512;
  1167. break;
  1168. case 512:
  1169. temp |= DMA_RQ_C1_SOURCE_MOD256;
  1170. break;
  1171. case 256:
  1172. temp |= DMA_RQ_C1_SOURCE_MOD128;
  1173. break;
  1174. case 128:
  1175. temp |= DMA_RQ_C1_SOURCE_MOD64;
  1176. break;
  1177. case 64:
  1178. temp |= DMA_RQ_C1_SOURCE_MOD32;
  1179. break;
  1180. case 32:
  1181. temp |= DMA_RQ_C1_SOURCE_MOD16;
  1182. break;
  1183. default:
  1184. dev_dbg(chip->card->dev,
  1185. "period size (%d) not supported by HW\n", period_size);
  1186. return -EINVAL;
  1187. }
  1188. snd_cs46xx_poke (chip,pcm_channel->pcm_reader_scb->address << 2,temp);
  1189. return 0;
  1190. }
  1191. int cs46xx_dsp_pcm_ostream_set_period (struct snd_cs46xx * chip,
  1192. int period_size)
  1193. {
  1194. u32 temp = snd_cs46xx_peek (chip,WRITEBACK_SCB_ADDR << 2);
  1195. temp &= ~DMA_RQ_C1_DEST_SIZE_MASK;
  1196. switch (period_size) {
  1197. case 2048:
  1198. temp |= DMA_RQ_C1_DEST_MOD1024;
  1199. break;
  1200. case 1024:
  1201. temp |= DMA_RQ_C1_DEST_MOD512;
  1202. break;
  1203. case 512:
  1204. temp |= DMA_RQ_C1_DEST_MOD256;
  1205. break;
  1206. case 256:
  1207. temp |= DMA_RQ_C1_DEST_MOD128;
  1208. break;
  1209. case 128:
  1210. temp |= DMA_RQ_C1_DEST_MOD64;
  1211. break;
  1212. case 64:
  1213. temp |= DMA_RQ_C1_DEST_MOD32;
  1214. break;
  1215. case 32:
  1216. temp |= DMA_RQ_C1_DEST_MOD16;
  1217. break;
  1218. default:
  1219. dev_dbg(chip->card->dev,
  1220. "period size (%d) not supported by HW\n", period_size);
  1221. return -EINVAL;
  1222. }
  1223. snd_cs46xx_poke (chip,WRITEBACK_SCB_ADDR << 2,temp);
  1224. return 0;
  1225. }
  1226. void cs46xx_dsp_destroy_pcm_channel (struct snd_cs46xx * chip,
  1227. struct dsp_pcm_channel_descriptor * pcm_channel)
  1228. {
  1229. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1230. unsigned long flags;
  1231. if (snd_BUG_ON(!pcm_channel->active ||
  1232. ins->npcm_channels <= 0 ||
  1233. pcm_channel->src_scb->ref_count <= 0))
  1234. return;
  1235. spin_lock_irqsave(&chip->reg_lock, flags);
  1236. pcm_channel->unlinked = 1;
  1237. pcm_channel->active = 0;
  1238. pcm_channel->private_data = NULL;
  1239. pcm_channel->src_scb->ref_count --;
  1240. ins->npcm_channels --;
  1241. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1242. cs46xx_dsp_remove_scb(chip,pcm_channel->pcm_reader_scb);
  1243. if (!pcm_channel->src_scb->ref_count) {
  1244. cs46xx_dsp_remove_scb(chip,pcm_channel->src_scb);
  1245. if (snd_BUG_ON(pcm_channel->src_slot < 0 ||
  1246. pcm_channel->src_slot >= DSP_MAX_SRC_NR))
  1247. return;
  1248. ins->src_scb_slots[pcm_channel->src_slot] = 0;
  1249. ins->nsrc_scb --;
  1250. }
  1251. }
  1252. int cs46xx_dsp_pcm_unlink (struct snd_cs46xx * chip,
  1253. struct dsp_pcm_channel_descriptor * pcm_channel)
  1254. {
  1255. unsigned long flags;
  1256. if (snd_BUG_ON(!pcm_channel->active ||
  1257. chip->dsp_spos_instance->npcm_channels <= 0))
  1258. return -EIO;
  1259. spin_lock_irqsave(&chip->reg_lock, flags);
  1260. if (pcm_channel->unlinked) {
  1261. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1262. return -EIO;
  1263. }
  1264. pcm_channel->unlinked = 1;
  1265. _dsp_unlink_scb (chip,pcm_channel->pcm_reader_scb);
  1266. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1267. return 0;
  1268. }
  1269. int cs46xx_dsp_pcm_link (struct snd_cs46xx * chip,
  1270. struct dsp_pcm_channel_descriptor * pcm_channel)
  1271. {
  1272. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1273. struct dsp_scb_descriptor * parent_scb;
  1274. struct dsp_scb_descriptor * src_scb = pcm_channel->src_scb;
  1275. unsigned long flags;
  1276. spin_lock_irqsave(&chip->reg_lock, flags);
  1277. if (pcm_channel->unlinked == 0) {
  1278. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1279. return -EIO;
  1280. }
  1281. parent_scb = src_scb;
  1282. if (src_scb->sub_list_ptr != ins->the_null_scb) {
  1283. src_scb->sub_list_ptr->parent_scb_ptr = pcm_channel->pcm_reader_scb;
  1284. pcm_channel->pcm_reader_scb->next_scb_ptr = src_scb->sub_list_ptr;
  1285. }
  1286. src_scb->sub_list_ptr = pcm_channel->pcm_reader_scb;
  1287. snd_BUG_ON(pcm_channel->pcm_reader_scb->parent_scb_ptr);
  1288. pcm_channel->pcm_reader_scb->parent_scb_ptr = parent_scb;
  1289. /* update SCB entry in DSP RAM */
  1290. cs46xx_dsp_spos_update_scb(chip,pcm_channel->pcm_reader_scb);
  1291. /* update parent SCB entry */
  1292. cs46xx_dsp_spos_update_scb(chip,parent_scb);
  1293. pcm_channel->unlinked = 0;
  1294. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1295. return 0;
  1296. }
  1297. struct dsp_scb_descriptor *
  1298. cs46xx_add_record_source (struct snd_cs46xx *chip, struct dsp_scb_descriptor * source,
  1299. u16 addr, char * scb_name)
  1300. {
  1301. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1302. struct dsp_scb_descriptor * parent;
  1303. struct dsp_scb_descriptor * pcm_input;
  1304. int insert_point;
  1305. if (snd_BUG_ON(!ins->record_mixer_scb))
  1306. return NULL;
  1307. if (ins->record_mixer_scb->sub_list_ptr != ins->the_null_scb) {
  1308. parent = find_next_free_scb (chip,ins->record_mixer_scb->sub_list_ptr);
  1309. insert_point = SCB_ON_PARENT_NEXT_SCB;
  1310. } else {
  1311. parent = ins->record_mixer_scb;
  1312. insert_point = SCB_ON_PARENT_SUBLIST_SCB;
  1313. }
  1314. pcm_input = cs46xx_dsp_create_pcm_serial_input_scb(chip,scb_name,addr,
  1315. source, parent,
  1316. insert_point);
  1317. return pcm_input;
  1318. }
  1319. int cs46xx_src_unlink(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
  1320. {
  1321. unsigned long flags;
  1322. if (snd_BUG_ON(!src->parent_scb_ptr))
  1323. return -EINVAL;
  1324. /* mute SCB */
  1325. cs46xx_dsp_scb_set_volume (chip,src,0,0);
  1326. spin_lock_irqsave(&chip->reg_lock, flags);
  1327. _dsp_unlink_scb (chip,src);
  1328. spin_unlock_irqrestore(&chip->reg_lock, flags);
  1329. return 0;
  1330. }
  1331. int cs46xx_src_link(struct snd_cs46xx *chip, struct dsp_scb_descriptor * src)
  1332. {
  1333. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1334. struct dsp_scb_descriptor * parent_scb;
  1335. if (snd_BUG_ON(src->parent_scb_ptr))
  1336. return -EINVAL;
  1337. if (snd_BUG_ON(!ins->master_mix_scb))
  1338. return -EINVAL;
  1339. if (ins->master_mix_scb->sub_list_ptr != ins->the_null_scb) {
  1340. parent_scb = find_next_free_scb (chip,ins->master_mix_scb->sub_list_ptr);
  1341. parent_scb->next_scb_ptr = src;
  1342. } else {
  1343. parent_scb = ins->master_mix_scb;
  1344. parent_scb->sub_list_ptr = src;
  1345. }
  1346. src->parent_scb_ptr = parent_scb;
  1347. /* update entry in DSP RAM */
  1348. cs46xx_dsp_spos_update_scb(chip,parent_scb);
  1349. return 0;
  1350. }
  1351. int cs46xx_dsp_enable_spdif_out (struct snd_cs46xx *chip)
  1352. {
  1353. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1354. if ( ! (ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) {
  1355. cs46xx_dsp_enable_spdif_hw (chip);
  1356. }
  1357. /* dont touch anything if SPDIF is open */
  1358. if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) {
  1359. /* when cs46xx_iec958_post_close(...) is called it
  1360. will call this function if necessary depending on
  1361. this bit */
  1362. ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
  1363. return -EBUSY;
  1364. }
  1365. if (snd_BUG_ON(ins->asynch_tx_scb))
  1366. return -EINVAL;
  1367. if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr !=
  1368. ins->the_null_scb))
  1369. return -EINVAL;
  1370. /* reset output snooper sample buffer pointer */
  1371. snd_cs46xx_poke (chip, (ins->ref_snoop_scb->address + 2) << 2,
  1372. (OUTPUT_SNOOP_BUFFER + 0x10) << 0x10 );
  1373. /* The asynch. transfer task */
  1374. ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR,
  1375. SPDIFO_SCB_INST,
  1376. SPDIFO_IP_OUTPUT_BUFFER1,
  1377. ins->master_mix_scb,
  1378. SCB_ON_PARENT_NEXT_SCB);
  1379. if (!ins->asynch_tx_scb) return -ENOMEM;
  1380. ins->spdif_pcm_input_scb = cs46xx_dsp_create_pcm_serial_input_scb(chip,"PCMSerialInput_II",
  1381. PCMSERIALINII_SCB_ADDR,
  1382. ins->ref_snoop_scb,
  1383. ins->asynch_tx_scb,
  1384. SCB_ON_PARENT_SUBLIST_SCB);
  1385. if (!ins->spdif_pcm_input_scb) return -ENOMEM;
  1386. /* monitor state */
  1387. ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
  1388. return 0;
  1389. }
  1390. int cs46xx_dsp_disable_spdif_out (struct snd_cs46xx *chip)
  1391. {
  1392. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1393. /* dont touch anything if SPDIF is open */
  1394. if ( ins->spdif_status_out & DSP_SPDIF_STATUS_PLAYBACK_OPEN) {
  1395. ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED;
  1396. return -EBUSY;
  1397. }
  1398. /* check integrety */
  1399. if (snd_BUG_ON(!ins->asynch_tx_scb))
  1400. return -EINVAL;
  1401. if (snd_BUG_ON(!ins->spdif_pcm_input_scb))
  1402. return -EINVAL;
  1403. if (snd_BUG_ON(ins->master_mix_scb->next_scb_ptr != ins->asynch_tx_scb))
  1404. return -EINVAL;
  1405. if (snd_BUG_ON(ins->asynch_tx_scb->parent_scb_ptr !=
  1406. ins->master_mix_scb))
  1407. return -EINVAL;
  1408. cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
  1409. cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
  1410. ins->spdif_pcm_input_scb = NULL;
  1411. ins->asynch_tx_scb = NULL;
  1412. /* clear buffer to prevent any undesired noise */
  1413. _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256);
  1414. /* monitor state */
  1415. ins->spdif_status_out &= ~DSP_SPDIF_STATUS_OUTPUT_ENABLED;
  1416. return 0;
  1417. }
  1418. int cs46xx_iec958_pre_open (struct snd_cs46xx *chip)
  1419. {
  1420. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1421. if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) {
  1422. /* remove AsynchFGTxSCB and PCMSerialInput_II */
  1423. cs46xx_dsp_disable_spdif_out (chip);
  1424. /* save state */
  1425. ins->spdif_status_out |= DSP_SPDIF_STATUS_OUTPUT_ENABLED;
  1426. }
  1427. /* if not enabled already */
  1428. if ( !(ins->spdif_status_out & DSP_SPDIF_STATUS_HW_ENABLED) ) {
  1429. cs46xx_dsp_enable_spdif_hw (chip);
  1430. }
  1431. /* Create the asynch. transfer task for playback */
  1432. ins->asynch_tx_scb = cs46xx_dsp_create_asynch_fg_tx_scb(chip,"AsynchFGTxSCB",ASYNCTX_SCB_ADDR,
  1433. SPDIFO_SCB_INST,
  1434. SPDIFO_IP_OUTPUT_BUFFER1,
  1435. ins->master_mix_scb,
  1436. SCB_ON_PARENT_NEXT_SCB);
  1437. /* set spdif channel status value for streaming */
  1438. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_stream);
  1439. ins->spdif_status_out |= DSP_SPDIF_STATUS_PLAYBACK_OPEN;
  1440. return 0;
  1441. }
  1442. int cs46xx_iec958_post_close (struct snd_cs46xx *chip)
  1443. {
  1444. struct dsp_spos_instance * ins = chip->dsp_spos_instance;
  1445. if (snd_BUG_ON(!ins->asynch_tx_scb))
  1446. return -EINVAL;
  1447. ins->spdif_status_out &= ~DSP_SPDIF_STATUS_PLAYBACK_OPEN;
  1448. /* restore settings */
  1449. cs46xx_poke_via_dsp (chip,SP_SPDOUT_CSUV, ins->spdif_csuv_default);
  1450. /* deallocate stuff */
  1451. if (ins->spdif_pcm_input_scb != NULL) {
  1452. cs46xx_dsp_remove_scb (chip,ins->spdif_pcm_input_scb);
  1453. ins->spdif_pcm_input_scb = NULL;
  1454. }
  1455. cs46xx_dsp_remove_scb (chip,ins->asynch_tx_scb);
  1456. ins->asynch_tx_scb = NULL;
  1457. /* clear buffer to prevent any undesired noise */
  1458. _dsp_clear_sample_buffer(chip,SPDIFO_IP_OUTPUT_BUFFER1,256);
  1459. /* restore state */
  1460. if ( ins->spdif_status_out & DSP_SPDIF_STATUS_OUTPUT_ENABLED ) {
  1461. cs46xx_dsp_enable_spdif_out (chip);
  1462. }
  1463. return 0;
  1464. }