emu10k1_main.c 44 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  3. * Creative Labs, Inc.
  4. * Routines for control of EMU10K1 chips
  5. *
  6. * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
  7. * Added support for Audigy 2 Value.
  8. *
  9. *
  10. * BUGS:
  11. * --
  12. *
  13. * TODO:
  14. * --
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 2 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program; if not, write to the Free Software
  28. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  29. *
  30. */
  31. #include <sound/driver.h>
  32. #include <linux/delay.h>
  33. #include <linux/init.h>
  34. #include <linux/interrupt.h>
  35. #include <linux/pci.h>
  36. #include <linux/slab.h>
  37. #include <linux/vmalloc.h>
  38. #include <linux/mutex.h>
  39. #include <sound/core.h>
  40. #include <sound/emu10k1.h>
  41. #include "p16v.h"
  42. #include "tina2.h"
  43. /*************************************************************************
  44. * EMU10K1 init / done
  45. *************************************************************************/
  46. void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int ch)
  47. {
  48. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  49. snd_emu10k1_ptr_write(emu, IP, ch, 0);
  50. snd_emu10k1_ptr_write(emu, VTFT, ch, 0xffff);
  51. snd_emu10k1_ptr_write(emu, CVCF, ch, 0xffff);
  52. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  53. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  54. snd_emu10k1_ptr_write(emu, CCR, ch, 0);
  55. snd_emu10k1_ptr_write(emu, PSST, ch, 0);
  56. snd_emu10k1_ptr_write(emu, DSL, ch, 0x10);
  57. snd_emu10k1_ptr_write(emu, CCCA, ch, 0);
  58. snd_emu10k1_ptr_write(emu, Z1, ch, 0);
  59. snd_emu10k1_ptr_write(emu, Z2, ch, 0);
  60. snd_emu10k1_ptr_write(emu, FXRT, ch, 0x32100000);
  61. snd_emu10k1_ptr_write(emu, ATKHLDM, ch, 0);
  62. snd_emu10k1_ptr_write(emu, DCYSUSM, ch, 0);
  63. snd_emu10k1_ptr_write(emu, IFATN, ch, 0xffff);
  64. snd_emu10k1_ptr_write(emu, PEFE, ch, 0);
  65. snd_emu10k1_ptr_write(emu, FMMOD, ch, 0);
  66. snd_emu10k1_ptr_write(emu, TREMFRQ, ch, 24); /* 1 Hz */
  67. snd_emu10k1_ptr_write(emu, FM2FRQ2, ch, 24); /* 1 Hz */
  68. snd_emu10k1_ptr_write(emu, TEMPENV, ch, 0);
  69. /*** these are last so OFF prevents writing ***/
  70. snd_emu10k1_ptr_write(emu, LFOVAL2, ch, 0);
  71. snd_emu10k1_ptr_write(emu, LFOVAL1, ch, 0);
  72. snd_emu10k1_ptr_write(emu, ATKHLDV, ch, 0);
  73. snd_emu10k1_ptr_write(emu, ENVVOL, ch, 0);
  74. snd_emu10k1_ptr_write(emu, ENVVAL, ch, 0);
  75. /* Audigy extra stuffs */
  76. if (emu->audigy) {
  77. snd_emu10k1_ptr_write(emu, 0x4c, ch, 0); /* ?? */
  78. snd_emu10k1_ptr_write(emu, 0x4d, ch, 0); /* ?? */
  79. snd_emu10k1_ptr_write(emu, 0x4e, ch, 0); /* ?? */
  80. snd_emu10k1_ptr_write(emu, 0x4f, ch, 0); /* ?? */
  81. snd_emu10k1_ptr_write(emu, A_FXRT1, ch, 0x03020100);
  82. snd_emu10k1_ptr_write(emu, A_FXRT2, ch, 0x3f3f3f3f);
  83. snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, ch, 0);
  84. }
  85. }
  86. static unsigned int spi_dac_init[] = {
  87. 0x00ff,
  88. 0x02ff,
  89. 0x0400,
  90. 0x0520,
  91. 0x0600,
  92. 0x08ff,
  93. 0x0aff,
  94. 0x0cff,
  95. 0x0eff,
  96. 0x10ff,
  97. 0x1200,
  98. 0x1400,
  99. 0x1480,
  100. 0x1800,
  101. 0x1aff,
  102. 0x1cff,
  103. 0x1e00,
  104. 0x0530,
  105. 0x0602,
  106. 0x0622,
  107. 0x1400,
  108. };
  109. static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
  110. {
  111. unsigned int silent_page;
  112. int ch;
  113. /* disable audio and lock cache */
  114. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
  115. emu->port + HCFG);
  116. /* reset recording buffers */
  117. snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
  118. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  119. snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
  120. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  121. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  122. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  123. /* disable channel interrupt */
  124. outl(0, emu->port + INTE);
  125. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  126. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  127. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  128. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  129. if (emu->audigy){
  130. /* set SPDIF bypass mode */
  131. snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
  132. /* enable rear left + rear right AC97 slots */
  133. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
  134. AC97SLOT_REAR_LEFT);
  135. }
  136. /* init envelope engine */
  137. for (ch = 0; ch < NUM_G; ch++)
  138. snd_emu10k1_voice_init(emu, ch);
  139. snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
  140. snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
  141. snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
  142. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  143. /* Hacks for Alice3 to work independent of haP16V driver */
  144. u32 tmp;
  145. //Setup SRCMulti_I2S SamplingRate
  146. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  147. tmp &= 0xfffff1ff;
  148. tmp |= (0x2<<9);
  149. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  150. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  151. snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
  152. /* Setup SRCMulti Input Audio Enable */
  153. /* Use 0xFFFFFFFF to enable P16V sounds. */
  154. snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
  155. /* Enabled Phased (8-channel) P16V playback */
  156. outl(0x0201, emu->port + HCFG2);
  157. /* Set playback routing. */
  158. snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
  159. }
  160. if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
  161. /* Hacks for Alice3 to work independent of haP16V driver */
  162. u32 tmp;
  163. snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
  164. //Setup SRCMulti_I2S SamplingRate
  165. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  166. tmp &= 0xfffff1ff;
  167. tmp |= (0x2<<9);
  168. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  169. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  170. outl(0x600000, emu->port + 0x20);
  171. outl(0x14, emu->port + 0x24);
  172. /* Setup SRCMulti Input Audio Enable */
  173. outl(0x7b0000, emu->port + 0x20);
  174. outl(0xFF000000, emu->port + 0x24);
  175. /* Setup SPDIF Out Audio Enable */
  176. /* The Audigy 2 Value has a separate SPDIF out,
  177. * so no need for a mixer switch
  178. */
  179. outl(0x7a0000, emu->port + 0x20);
  180. outl(0xFF000000, emu->port + 0x24);
  181. tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
  182. outl(tmp, emu->port + A_IOCFG);
  183. }
  184. if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
  185. int size, n;
  186. size = ARRAY_SIZE(spi_dac_init);
  187. for (n=0; n < size; n++)
  188. snd_emu10k1_spi_write(emu, spi_dac_init[n]);
  189. snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
  190. /* Enable GPIOs
  191. * GPIO0: Unknown
  192. * GPIO1: Speakers-enabled.
  193. * GPIO2: Unknown
  194. * GPIO3: Unknown
  195. * GPIO4: IEC958 Output on.
  196. * GPIO5: Unknown
  197. * GPIO6: Unknown
  198. * GPIO7: Unknown
  199. */
  200. outl(0x76, emu->port + A_IOCFG); /* Windows uses 0x3f76 */
  201. }
  202. snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
  203. snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
  204. snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
  205. silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
  206. for (ch = 0; ch < NUM_G; ch++) {
  207. snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
  208. snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
  209. }
  210. /*
  211. * Hokay, setup HCFG
  212. * Mute Disable Audio = 0
  213. * Lock Tank Memory = 1
  214. * Lock Sound Memory = 0
  215. * Auto Mute = 1
  216. */
  217. if (emu->audigy) {
  218. if (emu->revision == 4) /* audigy2 */
  219. outl(HCFG_AUDIOENABLE |
  220. HCFG_AC3ENABLE_CDSPDIF |
  221. HCFG_AC3ENABLE_GPSPDIF |
  222. HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  223. else
  224. outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  225. /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
  226. * e.g. card_capabilities->joystick */
  227. } else if (emu->model == 0x20 ||
  228. emu->model == 0xc400 ||
  229. (emu->model == 0x21 && emu->revision < 6))
  230. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
  231. else
  232. // With on-chip joystick
  233. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  234. if (enable_ir) { /* enable IR for SB Live */
  235. if ( emu->card_capabilities->emu1212m) {
  236. ; /* Disable all access to A_IOCFG for the emu1212m */
  237. } else if (emu->audigy) {
  238. unsigned int reg = inl(emu->port + A_IOCFG);
  239. outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
  240. udelay(500);
  241. outl(reg | A_IOCFG_GPOUT1 | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
  242. udelay(100);
  243. outl(reg, emu->port + A_IOCFG);
  244. } else {
  245. unsigned int reg = inl(emu->port + HCFG);
  246. outl(reg | HCFG_GPOUT2, emu->port + HCFG);
  247. udelay(500);
  248. outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
  249. udelay(100);
  250. outl(reg, emu->port + HCFG);
  251. }
  252. }
  253. if ( emu->card_capabilities->emu1212m) {
  254. ; /* Disable all access to A_IOCFG for the emu1212m */
  255. } else if (emu->audigy) { /* enable analog output */
  256. unsigned int reg = inl(emu->port + A_IOCFG);
  257. outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
  258. }
  259. return 0;
  260. }
  261. static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
  262. {
  263. /*
  264. * Enable the audio bit
  265. */
  266. outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
  267. /* Enable analog/digital outs on audigy */
  268. if ( emu->card_capabilities->emu1212m) {
  269. ; /* Disable all access to A_IOCFG for the emu1212m */
  270. } else if (emu->audigy) {
  271. outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
  272. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  273. /* Unmute Analog now. Set GPO6 to 1 for Apollo.
  274. * This has to be done after init ALice3 I2SOut beyond 48KHz.
  275. * So, sequence is important. */
  276. outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
  277. } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
  278. /* Unmute Analog now. */
  279. outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
  280. } else {
  281. /* Disable routing from AC97 line out to Front speakers */
  282. outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
  283. }
  284. }
  285. #if 0
  286. {
  287. unsigned int tmp;
  288. /* FIXME: the following routine disables LiveDrive-II !! */
  289. // TOSLink detection
  290. emu->tos_link = 0;
  291. tmp = inl(emu->port + HCFG);
  292. if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
  293. outl(tmp|0x800, emu->port + HCFG);
  294. udelay(50);
  295. if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
  296. emu->tos_link = 1;
  297. outl(tmp, emu->port + HCFG);
  298. }
  299. }
  300. }
  301. #endif
  302. snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
  303. }
  304. int snd_emu10k1_done(struct snd_emu10k1 * emu)
  305. {
  306. int ch;
  307. outl(0, emu->port + INTE);
  308. /*
  309. * Shutdown the chip
  310. */
  311. for (ch = 0; ch < NUM_G; ch++)
  312. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  313. for (ch = 0; ch < NUM_G; ch++) {
  314. snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
  315. snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
  316. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  317. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  318. }
  319. /* reset recording buffers */
  320. snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
  321. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  322. snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
  323. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  324. snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
  325. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  326. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  327. snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
  328. snd_emu10k1_ptr_write(emu, TCB, 0, 0);
  329. if (emu->audigy)
  330. snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
  331. else
  332. snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
  333. /* disable channel interrupt */
  334. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  335. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  336. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  337. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  338. /* disable audio and lock cache */
  339. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
  340. snd_emu10k1_ptr_write(emu, PTB, 0, 0);
  341. return 0;
  342. }
  343. /*************************************************************************
  344. * ECARD functional implementation
  345. *************************************************************************/
  346. /* In A1 Silicon, these bits are in the HC register */
  347. #define HOOKN_BIT (1L << 12)
  348. #define HANDN_BIT (1L << 11)
  349. #define PULSEN_BIT (1L << 10)
  350. #define EC_GDI1 (1 << 13)
  351. #define EC_GDI0 (1 << 14)
  352. #define EC_NUM_CONTROL_BITS 20
  353. #define EC_AC3_DATA_SELN 0x0001L
  354. #define EC_EE_DATA_SEL 0x0002L
  355. #define EC_EE_CNTRL_SELN 0x0004L
  356. #define EC_EECLK 0x0008L
  357. #define EC_EECS 0x0010L
  358. #define EC_EESDO 0x0020L
  359. #define EC_TRIM_CSN 0x0040L
  360. #define EC_TRIM_SCLK 0x0080L
  361. #define EC_TRIM_SDATA 0x0100L
  362. #define EC_TRIM_MUTEN 0x0200L
  363. #define EC_ADCCAL 0x0400L
  364. #define EC_ADCRSTN 0x0800L
  365. #define EC_DACCAL 0x1000L
  366. #define EC_DACMUTEN 0x2000L
  367. #define EC_LEDN 0x4000L
  368. #define EC_SPDIF0_SEL_SHIFT 15
  369. #define EC_SPDIF1_SEL_SHIFT 17
  370. #define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
  371. #define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
  372. #define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
  373. #define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
  374. #define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
  375. * be incremented any time the EEPROM's
  376. * format is changed. */
  377. #define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
  378. /* Addresses for special values stored in to EEPROM */
  379. #define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
  380. #define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
  381. #define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
  382. #define EC_LAST_PROMFILE_ADDR 0x2f
  383. #define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
  384. * can be up to 30 characters in length
  385. * and is stored as a NULL-terminated
  386. * ASCII string. Any unused bytes must be
  387. * filled with zeros */
  388. #define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
  389. /* Most of this stuff is pretty self-evident. According to the hardware
  390. * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
  391. * offset problem. Weird.
  392. */
  393. #define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
  394. EC_TRIM_CSN)
  395. #define EC_DEFAULT_ADC_GAIN 0xC4C4
  396. #define EC_DEFAULT_SPDIF0_SEL 0x0
  397. #define EC_DEFAULT_SPDIF1_SEL 0x4
  398. /**************************************************************************
  399. * @func Clock bits into the Ecard's control latch. The Ecard uses a
  400. * control latch will is loaded bit-serially by toggling the Modem control
  401. * lines from function 2 on the E8010. This function hides these details
  402. * and presents the illusion that we are actually writing to a distinct
  403. * register.
  404. */
  405. static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value)
  406. {
  407. unsigned short count;
  408. unsigned int data;
  409. unsigned long hc_port;
  410. unsigned int hc_value;
  411. hc_port = emu->port + HCFG;
  412. hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
  413. outl(hc_value, hc_port);
  414. for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
  415. /* Set up the value */
  416. data = ((value & 0x1) ? PULSEN_BIT : 0);
  417. value >>= 1;
  418. outl(hc_value | data, hc_port);
  419. /* Clock the shift register */
  420. outl(hc_value | data | HANDN_BIT, hc_port);
  421. outl(hc_value | data, hc_port);
  422. }
  423. /* Latch the bits */
  424. outl(hc_value | HOOKN_BIT, hc_port);
  425. outl(hc_value, hc_port);
  426. }
  427. /**************************************************************************
  428. * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
  429. * trim value consists of a 16bit value which is composed of two
  430. * 8 bit gain/trim values, one for the left channel and one for the
  431. * right channel. The following table maps from the Gain/Attenuation
  432. * value in decibels into the corresponding bit pattern for a single
  433. * channel.
  434. */
  435. static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
  436. unsigned short gain)
  437. {
  438. unsigned int bit;
  439. /* Enable writing to the TRIM registers */
  440. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  441. /* Do it again to insure that we meet hold time requirements */
  442. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  443. for (bit = (1 << 15); bit; bit >>= 1) {
  444. unsigned int value;
  445. value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
  446. if (gain & bit)
  447. value |= EC_TRIM_SDATA;
  448. /* Clock the bit */
  449. snd_emu10k1_ecard_write(emu, value);
  450. snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
  451. snd_emu10k1_ecard_write(emu, value);
  452. }
  453. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  454. }
  455. static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
  456. {
  457. unsigned int hc_value;
  458. /* Set up the initial settings */
  459. emu->ecard_ctrl = EC_RAW_RUN_MODE |
  460. EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
  461. EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
  462. /* Step 0: Set the codec type in the hardware control register
  463. * and enable audio output */
  464. hc_value = inl(emu->port + HCFG);
  465. outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
  466. inl(emu->port + HCFG);
  467. /* Step 1: Turn off the led and deassert TRIM_CS */
  468. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  469. /* Step 2: Calibrate the ADC and DAC */
  470. snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
  471. /* Step 3: Wait for awhile; XXX We can't get away with this
  472. * under a real operating system; we'll need to block and wait that
  473. * way. */
  474. snd_emu10k1_wait(emu, 48000);
  475. /* Step 4: Switch off the DAC and ADC calibration. Note
  476. * That ADC_CAL is actually an inverted signal, so we assert
  477. * it here to stop calibration. */
  478. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  479. /* Step 4: Switch into run mode */
  480. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  481. /* Step 5: Set the analog input gain */
  482. snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
  483. return 0;
  484. }
  485. static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
  486. {
  487. unsigned long special_port;
  488. unsigned int value;
  489. /* Special initialisation routine
  490. * before the rest of the IO-Ports become active.
  491. */
  492. special_port = emu->port + 0x38;
  493. value = inl(special_port);
  494. outl(0x00d00000, special_port);
  495. value = inl(special_port);
  496. outl(0x00d00001, special_port);
  497. value = inl(special_port);
  498. outl(0x00d0005f, special_port);
  499. value = inl(special_port);
  500. outl(0x00d0007f, special_port);
  501. value = inl(special_port);
  502. outl(0x0090007f, special_port);
  503. value = inl(special_port);
  504. snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
  505. return 0;
  506. }
  507. static int snd_emu1212m_fpga_write(struct snd_emu10k1 * emu, int reg, int value)
  508. {
  509. if (reg<0 || reg>0x3f)
  510. return 1;
  511. reg+=0x40; /* 0x40 upwards are registers. */
  512. if (value<0 || value>0x3f) /* 0 to 0x3f are values */
  513. return 1;
  514. outl(reg, emu->port + A_IOCFG);
  515. outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
  516. outl(value, emu->port + A_IOCFG);
  517. outl(value | 0x80 , emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
  518. return 0;
  519. }
  520. static int snd_emu1212m_fpga_read(struct snd_emu10k1 * emu, int reg, int *value)
  521. {
  522. if (reg<0 || reg>0x3f)
  523. return 1;
  524. reg+=0x40; /* 0x40 upwards are registers. */
  525. outl(reg, emu->port + A_IOCFG);
  526. outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
  527. *value = inl(emu->port + A_IOCFG);
  528. return 0;
  529. }
  530. static int snd_emu1212m_fpga_netlist_write(struct snd_emu10k1 * emu, int reg, int value)
  531. {
  532. snd_emu1212m_fpga_write(emu, 0x00, ((reg >> 8) & 0x3f) );
  533. snd_emu1212m_fpga_write(emu, 0x01, (reg & 0x3f) );
  534. snd_emu1212m_fpga_write(emu, 0x02, ((value >> 8) & 0x3f) );
  535. snd_emu1212m_fpga_write(emu, 0x03, (value & 0x3f) );
  536. return 0;
  537. }
  538. static int snd_emu10k1_emu1212m_init(struct snd_emu10k1 * emu)
  539. {
  540. unsigned int i;
  541. int tmp;
  542. snd_printk(KERN_ERR "emu1212m: Special config.\n");
  543. outl(0x0005a00c, emu->port + HCFG);
  544. outl(0x0005a004, emu->port + HCFG);
  545. outl(0x0005a000, emu->port + HCFG);
  546. outl(0x0005a000, emu->port + HCFG);
  547. snd_emu1212m_fpga_read(emu, 0x22, &tmp );
  548. snd_emu1212m_fpga_read(emu, 0x23, &tmp );
  549. snd_emu1212m_fpga_read(emu, 0x24, &tmp );
  550. snd_emu1212m_fpga_write(emu, 0x04, 0x01 );
  551. snd_emu1212m_fpga_read(emu, 0x0b, &tmp );
  552. snd_emu1212m_fpga_write(emu, 0x0b, 0x01 );
  553. snd_emu1212m_fpga_read(emu, 0x10, &tmp );
  554. snd_emu1212m_fpga_write(emu, 0x10, 0x00 );
  555. snd_emu1212m_fpga_read(emu, 0x11, &tmp );
  556. snd_emu1212m_fpga_write(emu, 0x11, 0x30 );
  557. snd_emu1212m_fpga_read(emu, 0x13, &tmp );
  558. snd_emu1212m_fpga_write(emu, 0x13, 0x0f );
  559. snd_emu1212m_fpga_read(emu, 0x11, &tmp );
  560. snd_emu1212m_fpga_write(emu, 0x11, 0x30 );
  561. snd_emu1212m_fpga_read(emu, 0x0a, &tmp );
  562. snd_emu1212m_fpga_write(emu, 0x0a, 0x10 );
  563. snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
  564. snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
  565. snd_emu1212m_fpga_write(emu, 0x09, 0x0f );
  566. snd_emu1212m_fpga_write(emu, 0x06, 0x00 );
  567. snd_emu1212m_fpga_write(emu, 0x05, 0x00 );
  568. snd_emu1212m_fpga_write(emu, 0x0e, 0x12 );
  569. snd_emu1212m_fpga_netlist_write(emu, 0x0000, 0x0200);
  570. snd_emu1212m_fpga_netlist_write(emu, 0x0001, 0x0201);
  571. snd_emu1212m_fpga_netlist_write(emu, 0x0002, 0x0500);
  572. snd_emu1212m_fpga_netlist_write(emu, 0x0003, 0x0501);
  573. snd_emu1212m_fpga_netlist_write(emu, 0x0004, 0x0400);
  574. snd_emu1212m_fpga_netlist_write(emu, 0x0005, 0x0401);
  575. snd_emu1212m_fpga_netlist_write(emu, 0x0006, 0x0402);
  576. snd_emu1212m_fpga_netlist_write(emu, 0x0007, 0x0403);
  577. snd_emu1212m_fpga_netlist_write(emu, 0x0008, 0x0404);
  578. snd_emu1212m_fpga_netlist_write(emu, 0x0009, 0x0405);
  579. snd_emu1212m_fpga_netlist_write(emu, 0x000a, 0x0406);
  580. snd_emu1212m_fpga_netlist_write(emu, 0x000b, 0x0407);
  581. snd_emu1212m_fpga_netlist_write(emu, 0x000c, 0x0100);
  582. snd_emu1212m_fpga_netlist_write(emu, 0x000d, 0x0104);
  583. snd_emu1212m_fpga_netlist_write(emu, 0x000e, 0x0200);
  584. snd_emu1212m_fpga_netlist_write(emu, 0x000f, 0x0201);
  585. for (i=0;i < 0x20;i++) {
  586. snd_emu1212m_fpga_netlist_write(emu, 0x0100+i, 0x0000);
  587. }
  588. for (i=0;i < 4;i++) {
  589. snd_emu1212m_fpga_netlist_write(emu, 0x0200+i, 0x0000);
  590. }
  591. for (i=0;i < 7;i++) {
  592. snd_emu1212m_fpga_netlist_write(emu, 0x0300+i, 0x0000);
  593. }
  594. for (i=0;i < 7;i++) {
  595. snd_emu1212m_fpga_netlist_write(emu, 0x0400+i, 0x0000);
  596. }
  597. snd_emu1212m_fpga_netlist_write(emu, 0x0500, 0x0108);
  598. snd_emu1212m_fpga_netlist_write(emu, 0x0501, 0x010c);
  599. snd_emu1212m_fpga_netlist_write(emu, 0x0600, 0x0110);
  600. snd_emu1212m_fpga_netlist_write(emu, 0x0601, 0x0114);
  601. snd_emu1212m_fpga_netlist_write(emu, 0x0700, 0x0118);
  602. snd_emu1212m_fpga_netlist_write(emu, 0x0701, 0x011c);
  603. snd_emu1212m_fpga_write(emu, 0x07, 0x01 );
  604. snd_emu1212m_fpga_read(emu, 0x21, &tmp );
  605. outl(0x0000a000, emu->port + HCFG);
  606. outl(0x0000a001, emu->port + HCFG);
  607. /* Initial boot complete. Now patches */
  608. snd_emu1212m_fpga_read(emu, 0x21, &tmp );
  609. snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
  610. snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
  611. snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
  612. snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
  613. snd_emu1212m_fpga_read(emu, 0x0a, &tmp );
  614. snd_emu1212m_fpga_write(emu, 0x0a, 0x10 );
  615. snd_emu1212m_fpga_read(emu, 0x20, &tmp );
  616. snd_emu1212m_fpga_read(emu, 0x21, &tmp );
  617. snd_emu1212m_fpga_netlist_write(emu, 0x0300, 0x0312);
  618. snd_emu1212m_fpga_netlist_write(emu, 0x0301, 0x0313);
  619. snd_emu1212m_fpga_netlist_write(emu, 0x0200, 0x0302);
  620. snd_emu1212m_fpga_netlist_write(emu, 0x0201, 0x0303);
  621. return 0;
  622. }
  623. /*
  624. * Create the EMU10K1 instance
  625. */
  626. #ifdef CONFIG_PM
  627. static int alloc_pm_buffer(struct snd_emu10k1 *emu);
  628. static void free_pm_buffer(struct snd_emu10k1 *emu);
  629. #endif
  630. static int snd_emu10k1_free(struct snd_emu10k1 *emu)
  631. {
  632. if (emu->port) { /* avoid access to already used hardware */
  633. snd_emu10k1_fx8010_tram_setup(emu, 0);
  634. snd_emu10k1_done(emu);
  635. /* remove reserved page */
  636. if (emu->reserved_page) {
  637. snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
  638. emu->reserved_page = NULL;
  639. }
  640. snd_emu10k1_free_efx(emu);
  641. }
  642. if (emu->memhdr)
  643. snd_util_memhdr_free(emu->memhdr);
  644. if (emu->silent_page.area)
  645. snd_dma_free_pages(&emu->silent_page);
  646. if (emu->ptb_pages.area)
  647. snd_dma_free_pages(&emu->ptb_pages);
  648. vfree(emu->page_ptr_table);
  649. vfree(emu->page_addr_table);
  650. #ifdef CONFIG_PM
  651. free_pm_buffer(emu);
  652. #endif
  653. if (emu->irq >= 0)
  654. free_irq(emu->irq, (void *)emu);
  655. if (emu->port)
  656. pci_release_regions(emu->pci);
  657. if (emu->card_capabilities->ca0151_chip) /* P16V */
  658. snd_p16v_free(emu);
  659. pci_disable_device(emu->pci);
  660. kfree(emu);
  661. return 0;
  662. }
  663. static int snd_emu10k1_dev_free(struct snd_device *device)
  664. {
  665. struct snd_emu10k1 *emu = device->device_data;
  666. return snd_emu10k1_free(emu);
  667. }
  668. static struct snd_emu_chip_details emu_chip_details[] = {
  669. /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
  670. /* Tested by James@superbug.co.uk 3rd July 2005 */
  671. /* DSP: CA0108-IAT
  672. * DAC: CS4382-KQ
  673. * ADC: Philips 1361T
  674. * AC97: STAC9750
  675. * CA0151: None
  676. */
  677. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
  678. .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
  679. .id = "Audigy2",
  680. .emu10k2_chip = 1,
  681. .ca0108_chip = 1,
  682. .spk71 = 1,
  683. .ac97_chip = 1} ,
  684. /* Audigy4 (Not PRO) SB0610 */
  685. /* Tested by James@superbug.co.uk 4th April 2006 */
  686. /* A_IOCFG bits
  687. * Output
  688. * 0: ?
  689. * 1: ?
  690. * 2: ?
  691. * 3: 0 - Digital Out, 1 - Line in
  692. * 4: ?
  693. * 5: ?
  694. * 6: ?
  695. * 7: ?
  696. * Input
  697. * 8: ?
  698. * 9: ?
  699. * A: Green jack sense (Front)
  700. * B: ?
  701. * C: Black jack sense (Rear/Side Right)
  702. * D: Yellow jack sense (Center/LFE/Side Left)
  703. * E: ?
  704. * F: ?
  705. *
  706. * Digital Out/Line in switch using A_IOCFG bit 3 (0x08)
  707. * 0 - Digital Out
  708. * 1 - Line in
  709. */
  710. /* Mic input not tested.
  711. * Analog CD input not tested
  712. * Digital Out not tested.
  713. * Line in working.
  714. * Audio output 5.1 working. Side outputs not working.
  715. */
  716. /* DSP: CA10300-IAT LF
  717. * DAC: Cirrus Logic CS4382-KQZ
  718. * ADC: Philips 1361T
  719. * AC97: Sigmatel STAC9750
  720. * CA0151: None
  721. */
  722. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
  723. .driver = "Audigy2", .name = "Audigy 4 [SB0610]",
  724. .id = "Audigy2",
  725. .emu10k2_chip = 1,
  726. .ca0108_chip = 1,
  727. .spk71 = 1,
  728. .adc_1361t = 1, /* 24 bit capture instead of 16bit */
  729. .ac97_chip = 1} ,
  730. /* Audigy 2 ZS Notebook Cardbus card.*/
  731. /* Tested by James@superbug.co.uk 22th December 2005 */
  732. /* Audio output 7.1/Headphones working.
  733. * Digital output working. (AC3 not checked, only PCM)
  734. * Audio inputs not tested.
  735. */
  736. /* DSP: Tina2
  737. * DAC: Wolfson WM8768/WM8568
  738. * ADC: Wolfson WM8775
  739. * AC97: None
  740. * CA0151: None
  741. */
  742. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
  743. .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
  744. .id = "Audigy2",
  745. .emu10k2_chip = 1,
  746. .ca0108_chip = 1,
  747. .ca_cardbus_chip = 1,
  748. .spi_dac = 1,
  749. .spk71 = 1} ,
  750. {.vendor = 0x1102, .device = 0x0008,
  751. .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
  752. .id = "Audigy2",
  753. .emu10k2_chip = 1,
  754. .ca0108_chip = 1,
  755. .ac97_chip = 1} ,
  756. /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
  757. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
  758. .driver = "Audigy2", .name = "E-mu 1212m [4001]",
  759. .id = "EMU1212m",
  760. .emu10k2_chip = 1,
  761. .ca0102_chip = 1,
  762. .emu1212m = 1} ,
  763. /* Tested by James@superbug.co.uk 3rd July 2005 */
  764. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
  765. .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
  766. .id = "Audigy2",
  767. .emu10k2_chip = 1,
  768. .ca0102_chip = 1,
  769. .ca0151_chip = 1,
  770. .spk71 = 1,
  771. .spdif_bug = 1,
  772. .ac97_chip = 1} ,
  773. /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
  774. /* The 0x20061102 does have SB0350 written on it
  775. * Just like 0x20021102
  776. */
  777. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
  778. .driver = "Audigy2", .name = "Audigy 2 [SB0350b]",
  779. .id = "Audigy2",
  780. .emu10k2_chip = 1,
  781. .ca0102_chip = 1,
  782. .ca0151_chip = 1,
  783. .spk71 = 1,
  784. .spdif_bug = 1,
  785. .ac97_chip = 1} ,
  786. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
  787. .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
  788. .id = "Audigy2",
  789. .emu10k2_chip = 1,
  790. .ca0102_chip = 1,
  791. .ca0151_chip = 1,
  792. .spk71 = 1,
  793. .spdif_bug = 1,
  794. .ac97_chip = 1} ,
  795. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
  796. .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
  797. .id = "Audigy2",
  798. .emu10k2_chip = 1,
  799. .ca0102_chip = 1,
  800. .ca0151_chip = 1,
  801. .spk71 = 1,
  802. .spdif_bug = 1,
  803. .ac97_chip = 1} ,
  804. /* Audigy 2 */
  805. /* Tested by James@superbug.co.uk 3rd July 2005 */
  806. /* DSP: CA0102-IAT
  807. * DAC: CS4382-KQ
  808. * ADC: Philips 1361T
  809. * AC97: STAC9721
  810. * CA0151: Yes
  811. */
  812. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
  813. .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
  814. .id = "Audigy2",
  815. .emu10k2_chip = 1,
  816. .ca0102_chip = 1,
  817. .ca0151_chip = 1,
  818. .spk71 = 1,
  819. .spdif_bug = 1,
  820. .adc_1361t = 1, /* 24 bit capture instead of 16bit */
  821. .ac97_chip = 1} ,
  822. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
  823. .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
  824. .id = "Audigy2",
  825. .emu10k2_chip = 1,
  826. .ca0102_chip = 1,
  827. .ca0151_chip = 1,
  828. .spk71 = 1,
  829. .spdif_bug = 1} ,
  830. /* Dell OEM/Creative Labs Audigy 2 ZS */
  831. /* See ALSA bug#1365 */
  832. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
  833. .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]",
  834. .id = "Audigy2",
  835. .emu10k2_chip = 1,
  836. .ca0102_chip = 1,
  837. .ca0151_chip = 1,
  838. .spk71 = 1,
  839. .spdif_bug = 1,
  840. .ac97_chip = 1} ,
  841. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
  842. .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
  843. .id = "Audigy2",
  844. .emu10k2_chip = 1,
  845. .ca0102_chip = 1,
  846. .ca0151_chip = 1,
  847. .spk71 = 1,
  848. .spdif_bug = 1,
  849. .ac97_chip = 1} ,
  850. {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
  851. .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
  852. .id = "Audigy2",
  853. .emu10k2_chip = 1,
  854. .ca0102_chip = 1,
  855. .ca0151_chip = 1,
  856. .spdif_bug = 1,
  857. .ac97_chip = 1} ,
  858. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
  859. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  860. .id = "Audigy",
  861. .emu10k2_chip = 1,
  862. .ca0102_chip = 1,
  863. .ac97_chip = 1} ,
  864. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
  865. .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
  866. .id = "Audigy",
  867. .emu10k2_chip = 1,
  868. .ca0102_chip = 1,
  869. .spdif_bug = 1,
  870. .ac97_chip = 1} ,
  871. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
  872. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  873. .id = "Audigy",
  874. .emu10k2_chip = 1,
  875. .ca0102_chip = 1,
  876. .ac97_chip = 1} ,
  877. {.vendor = 0x1102, .device = 0x0004,
  878. .driver = "Audigy", .name = "Audigy 1 [Unknown]",
  879. .id = "Audigy",
  880. .emu10k2_chip = 1,
  881. .ca0102_chip = 1,
  882. .ac97_chip = 1} ,
  883. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
  884. .driver = "EMU10K1", .name = "SBLive! [SB0105]",
  885. .id = "Live",
  886. .emu10k1_chip = 1,
  887. .ac97_chip = 1,
  888. .sblive51 = 1} ,
  889. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
  890. .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
  891. .id = "Live",
  892. .emu10k1_chip = 1,
  893. .ac97_chip = 1,
  894. .sblive51 = 1} ,
  895. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
  896. .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
  897. .id = "Live",
  898. .emu10k1_chip = 1,
  899. .ac97_chip = 1,
  900. .sblive51 = 1} ,
  901. /* Tested by ALSA bug#1680 26th December 2005 */
  902. /* note: It really has SB0220 written on the card. */
  903. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
  904. .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]",
  905. .id = "Live",
  906. .emu10k1_chip = 1,
  907. .ac97_chip = 1,
  908. .sblive51 = 1} ,
  909. /* Tested by Thomas Zehetbauer 27th Aug 2005 */
  910. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
  911. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  912. .id = "Live",
  913. .emu10k1_chip = 1,
  914. .ac97_chip = 1,
  915. .sblive51 = 1} ,
  916. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
  917. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  918. .id = "Live",
  919. .emu10k1_chip = 1,
  920. .ac97_chip = 1,
  921. .sblive51 = 1} ,
  922. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  923. .driver = "EMU10K1", .name = "SB Live 5.1",
  924. .id = "Live",
  925. .emu10k1_chip = 1,
  926. .ac97_chip = 1,
  927. .sblive51 = 1} ,
  928. /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
  929. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  930. .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
  931. .id = "Live",
  932. .emu10k1_chip = 1,
  933. .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
  934. * share the same IDs!
  935. */
  936. .sblive51 = 1} ,
  937. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  938. .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
  939. .id = "Live",
  940. .emu10k1_chip = 1,
  941. .ac97_chip = 1,
  942. .sblive51 = 1} ,
  943. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  944. .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
  945. .id = "Live",
  946. .emu10k1_chip = 1,
  947. .ac97_chip = 1} ,
  948. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  949. .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
  950. .id = "Live",
  951. .emu10k1_chip = 1,
  952. .ac97_chip = 1,
  953. .sblive51 = 1} ,
  954. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  955. .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
  956. .id = "Live",
  957. .emu10k1_chip = 1,
  958. .ac97_chip = 1,
  959. .sblive51 = 1} ,
  960. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  961. .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
  962. .id = "Live",
  963. .emu10k1_chip = 1,
  964. .ac97_chip = 1,
  965. .sblive51 = 1} ,
  966. /* Tested by James@superbug.co.uk 3rd July 2005 */
  967. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  968. .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
  969. .id = "Live",
  970. .emu10k1_chip = 1,
  971. .ac97_chip = 1,
  972. .sblive51 = 1} ,
  973. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  974. .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
  975. .id = "Live",
  976. .emu10k1_chip = 1,
  977. .ac97_chip = 1,
  978. .sblive51 = 1} ,
  979. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  980. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  981. .id = "Live",
  982. .emu10k1_chip = 1,
  983. .ac97_chip = 1,
  984. .sblive51 = 1} ,
  985. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  986. .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
  987. .id = "Live",
  988. .emu10k1_chip = 1,
  989. .ac97_chip = 1,
  990. .sblive51 = 1} ,
  991. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  992. .driver = "EMU10K1", .name = "E-mu APS [4001]",
  993. .id = "APS",
  994. .emu10k1_chip = 1,
  995. .ecard = 1} ,
  996. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  997. .driver = "EMU10K1", .name = "SBLive! [CT4620]",
  998. .id = "Live",
  999. .emu10k1_chip = 1,
  1000. .ac97_chip = 1,
  1001. .sblive51 = 1} ,
  1002. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  1003. .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
  1004. .id = "Live",
  1005. .emu10k1_chip = 1,
  1006. .ac97_chip = 1,
  1007. .sblive51 = 1} ,
  1008. {.vendor = 0x1102, .device = 0x0002,
  1009. .driver = "EMU10K1", .name = "SB Live [Unknown]",
  1010. .id = "Live",
  1011. .emu10k1_chip = 1,
  1012. .ac97_chip = 1,
  1013. .sblive51 = 1} ,
  1014. { } /* terminator */
  1015. };
  1016. int __devinit snd_emu10k1_create(struct snd_card *card,
  1017. struct pci_dev * pci,
  1018. unsigned short extin_mask,
  1019. unsigned short extout_mask,
  1020. long max_cache_bytes,
  1021. int enable_ir,
  1022. uint subsystem,
  1023. struct snd_emu10k1 ** remu)
  1024. {
  1025. struct snd_emu10k1 *emu;
  1026. int idx, err;
  1027. int is_audigy;
  1028. unsigned char revision;
  1029. unsigned int silent_page;
  1030. const struct snd_emu_chip_details *c;
  1031. static struct snd_device_ops ops = {
  1032. .dev_free = snd_emu10k1_dev_free,
  1033. };
  1034. *remu = NULL;
  1035. /* enable PCI device */
  1036. if ((err = pci_enable_device(pci)) < 0)
  1037. return err;
  1038. emu = kzalloc(sizeof(*emu), GFP_KERNEL);
  1039. if (emu == NULL) {
  1040. pci_disable_device(pci);
  1041. return -ENOMEM;
  1042. }
  1043. emu->card = card;
  1044. spin_lock_init(&emu->reg_lock);
  1045. spin_lock_init(&emu->emu_lock);
  1046. spin_lock_init(&emu->voice_lock);
  1047. spin_lock_init(&emu->synth_lock);
  1048. spin_lock_init(&emu->memblk_lock);
  1049. mutex_init(&emu->fx8010.lock);
  1050. INIT_LIST_HEAD(&emu->mapped_link_head);
  1051. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  1052. emu->pci = pci;
  1053. emu->irq = -1;
  1054. emu->synth = NULL;
  1055. emu->get_synth_voice = NULL;
  1056. /* read revision & serial */
  1057. pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
  1058. emu->revision = revision;
  1059. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  1060. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  1061. snd_printdd("vendor=0x%x, device=0x%x, subsystem_vendor_id=0x%x, subsystem_id=0x%x\n",pci->vendor, pci->device, emu->serial, emu->model);
  1062. for (c = emu_chip_details; c->vendor; c++) {
  1063. if (c->vendor == pci->vendor && c->device == pci->device) {
  1064. if (subsystem) {
  1065. if (c->subsystem && (c->subsystem == subsystem) ) {
  1066. break;
  1067. } else continue;
  1068. } else {
  1069. if (c->subsystem && (c->subsystem != emu->serial) )
  1070. continue;
  1071. if (c->revision && c->revision != emu->revision)
  1072. continue;
  1073. }
  1074. break;
  1075. }
  1076. }
  1077. if (c->vendor == 0) {
  1078. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  1079. kfree(emu);
  1080. pci_disable_device(pci);
  1081. return -ENOENT;
  1082. }
  1083. emu->card_capabilities = c;
  1084. if (c->subsystem && !subsystem)
  1085. snd_printdd("Sound card name=%s\n", c->name);
  1086. else if (subsystem)
  1087. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
  1088. c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
  1089. else
  1090. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
  1091. c->name, pci->vendor, pci->device, emu->serial);
  1092. if (!*card->id && c->id) {
  1093. int i, n = 0;
  1094. strlcpy(card->id, c->id, sizeof(card->id));
  1095. for (;;) {
  1096. for (i = 0; i < snd_ecards_limit; i++) {
  1097. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  1098. break;
  1099. }
  1100. if (i >= snd_ecards_limit)
  1101. break;
  1102. n++;
  1103. if (n >= SNDRV_CARDS)
  1104. break;
  1105. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  1106. }
  1107. }
  1108. is_audigy = emu->audigy = c->emu10k2_chip;
  1109. /* set the DMA transfer mask */
  1110. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  1111. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  1112. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  1113. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  1114. kfree(emu);
  1115. pci_disable_device(pci);
  1116. return -ENXIO;
  1117. }
  1118. if (is_audigy)
  1119. emu->gpr_base = A_FXGPREGBASE;
  1120. else
  1121. emu->gpr_base = FXGPREGBASE;
  1122. if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
  1123. kfree(emu);
  1124. pci_disable_device(pci);
  1125. return err;
  1126. }
  1127. emu->port = pci_resource_start(pci, 0);
  1128. if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_DISABLED|IRQF_SHARED, "EMU10K1", (void *)emu)) {
  1129. err = -EBUSY;
  1130. goto error;
  1131. }
  1132. emu->irq = pci->irq;
  1133. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  1134. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1135. 32 * 1024, &emu->ptb_pages) < 0) {
  1136. err = -ENOMEM;
  1137. goto error;
  1138. }
  1139. emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
  1140. emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
  1141. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  1142. err = -ENOMEM;
  1143. goto error;
  1144. }
  1145. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1146. EMUPAGESIZE, &emu->silent_page) < 0) {
  1147. err = -ENOMEM;
  1148. goto error;
  1149. }
  1150. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  1151. if (emu->memhdr == NULL) {
  1152. err = -ENOMEM;
  1153. goto error;
  1154. }
  1155. emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
  1156. sizeof(struct snd_util_memblk);
  1157. pci_set_master(pci);
  1158. emu->fx8010.fxbus_mask = 0x303f;
  1159. if (extin_mask == 0)
  1160. extin_mask = 0x3fcf;
  1161. if (extout_mask == 0)
  1162. extout_mask = 0x7fff;
  1163. emu->fx8010.extin_mask = extin_mask;
  1164. emu->fx8010.extout_mask = extout_mask;
  1165. emu->enable_ir = enable_ir;
  1166. if (emu->card_capabilities->ecard) {
  1167. if ((err = snd_emu10k1_ecard_init(emu)) < 0)
  1168. goto error;
  1169. } else if (emu->card_capabilities->ca_cardbus_chip) {
  1170. if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
  1171. goto error;
  1172. } else if (emu->card_capabilities->emu1212m) {
  1173. if ((err = snd_emu10k1_emu1212m_init(emu)) < 0) {
  1174. snd_emu10k1_free(emu);
  1175. return err;
  1176. }
  1177. } else {
  1178. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  1179. does not support this, it shouldn't do any harm */
  1180. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  1181. }
  1182. /* initialize TRAM setup */
  1183. emu->fx8010.itram_size = (16 * 1024)/2;
  1184. emu->fx8010.etram_pages.area = NULL;
  1185. emu->fx8010.etram_pages.bytes = 0;
  1186. /*
  1187. * Init to 0x02109204 :
  1188. * Clock accuracy = 0 (1000ppm)
  1189. * Sample Rate = 2 (48kHz)
  1190. * Audio Channel = 1 (Left of 2)
  1191. * Source Number = 0 (Unspecified)
  1192. * Generation Status = 1 (Original for Cat Code 12)
  1193. * Cat Code = 12 (Digital Signal Mixer)
  1194. * Mode = 0 (Mode 0)
  1195. * Emphasis = 0 (None)
  1196. * CP = 1 (Copyright unasserted)
  1197. * AN = 0 (Audio data)
  1198. * P = 0 (Consumer)
  1199. */
  1200. emu->spdif_bits[0] = emu->spdif_bits[1] =
  1201. emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1202. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1203. SPCS_GENERATIONSTATUS | 0x00001200 |
  1204. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
  1205. emu->reserved_page = (struct snd_emu10k1_memblk *)
  1206. snd_emu10k1_synth_alloc(emu, 4096);
  1207. if (emu->reserved_page)
  1208. emu->reserved_page->map_locked = 1;
  1209. /* Clear silent pages and set up pointers */
  1210. memset(emu->silent_page.area, 0, PAGE_SIZE);
  1211. silent_page = emu->silent_page.addr << 1;
  1212. for (idx = 0; idx < MAXPAGES; idx++)
  1213. ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
  1214. /* set up voice indices */
  1215. for (idx = 0; idx < NUM_G; idx++) {
  1216. emu->voices[idx].emu = emu;
  1217. emu->voices[idx].number = idx;
  1218. }
  1219. if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
  1220. goto error;
  1221. #ifdef CONFIG_PM
  1222. if ((err = alloc_pm_buffer(emu)) < 0)
  1223. goto error;
  1224. #endif
  1225. /* Initialize the effect engine */
  1226. if ((err = snd_emu10k1_init_efx(emu)) < 0)
  1227. goto error;
  1228. snd_emu10k1_audio_enable(emu);
  1229. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
  1230. goto error;
  1231. #ifdef CONFIG_PROC_FS
  1232. snd_emu10k1_proc_init(emu);
  1233. #endif
  1234. snd_card_set_dev(card, &pci->dev);
  1235. *remu = emu;
  1236. return 0;
  1237. error:
  1238. snd_emu10k1_free(emu);
  1239. return err;
  1240. }
  1241. #ifdef CONFIG_PM
  1242. static unsigned char saved_regs[] = {
  1243. CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
  1244. FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
  1245. ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
  1246. TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
  1247. MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
  1248. SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
  1249. 0xff /* end */
  1250. };
  1251. static unsigned char saved_regs_audigy[] = {
  1252. A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
  1253. A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
  1254. 0xff /* end */
  1255. };
  1256. static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
  1257. {
  1258. int size;
  1259. size = ARRAY_SIZE(saved_regs);
  1260. if (emu->audigy)
  1261. size += ARRAY_SIZE(saved_regs_audigy);
  1262. emu->saved_ptr = vmalloc(4 * NUM_G * size);
  1263. if (! emu->saved_ptr)
  1264. return -ENOMEM;
  1265. if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
  1266. return -ENOMEM;
  1267. if (emu->card_capabilities->ca0151_chip &&
  1268. snd_p16v_alloc_pm_buffer(emu) < 0)
  1269. return -ENOMEM;
  1270. return 0;
  1271. }
  1272. static void free_pm_buffer(struct snd_emu10k1 *emu)
  1273. {
  1274. vfree(emu->saved_ptr);
  1275. snd_emu10k1_efx_free_pm_buffer(emu);
  1276. if (emu->card_capabilities->ca0151_chip)
  1277. snd_p16v_free_pm_buffer(emu);
  1278. }
  1279. void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
  1280. {
  1281. int i;
  1282. unsigned char *reg;
  1283. unsigned int *val;
  1284. val = emu->saved_ptr;
  1285. for (reg = saved_regs; *reg != 0xff; reg++)
  1286. for (i = 0; i < NUM_G; i++, val++)
  1287. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1288. if (emu->audigy) {
  1289. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1290. for (i = 0; i < NUM_G; i++, val++)
  1291. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1292. }
  1293. if (emu->audigy)
  1294. emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
  1295. emu->saved_hcfg = inl(emu->port + HCFG);
  1296. }
  1297. void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
  1298. {
  1299. if (emu->card_capabilities->ecard)
  1300. snd_emu10k1_ecard_init(emu);
  1301. else if (emu->card_capabilities->ca_cardbus_chip)
  1302. snd_emu10k1_cardbus_init(emu);
  1303. else if (emu->card_capabilities->emu1212m)
  1304. snd_emu10k1_emu1212m_init(emu);
  1305. else
  1306. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  1307. snd_emu10k1_init(emu, emu->enable_ir, 1);
  1308. }
  1309. void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
  1310. {
  1311. int i;
  1312. unsigned char *reg;
  1313. unsigned int *val;
  1314. snd_emu10k1_audio_enable(emu);
  1315. /* resore for spdif */
  1316. if (emu->audigy)
  1317. outl(emu->saved_a_iocfg, emu->port + A_IOCFG);
  1318. outl(emu->saved_hcfg, emu->port + HCFG);
  1319. val = emu->saved_ptr;
  1320. for (reg = saved_regs; *reg != 0xff; reg++)
  1321. for (i = 0; i < NUM_G; i++, val++)
  1322. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1323. if (emu->audigy) {
  1324. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1325. for (i = 0; i < NUM_G; i++, val++)
  1326. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1327. }
  1328. }
  1329. #endif