dsp_spos_scb_lib.c 48 KB

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