dsp_spos_scb_lib.c 48 KB

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