emu10k1_main.c 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  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. .ac97_chip = 1} ,
  821. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
  822. .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
  823. .id = "Audigy2",
  824. .emu10k2_chip = 1,
  825. .ca0102_chip = 1,
  826. .ca0151_chip = 1,
  827. .spk71 = 1,
  828. .spdif_bug = 1} ,
  829. /* Dell OEM/Creative Labs Audigy 2 ZS */
  830. /* See ALSA bug#1365 */
  831. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
  832. .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]",
  833. .id = "Audigy2",
  834. .emu10k2_chip = 1,
  835. .ca0102_chip = 1,
  836. .ca0151_chip = 1,
  837. .spk71 = 1,
  838. .spdif_bug = 1,
  839. .ac97_chip = 1} ,
  840. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
  841. .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
  842. .id = "Audigy2",
  843. .emu10k2_chip = 1,
  844. .ca0102_chip = 1,
  845. .ca0151_chip = 1,
  846. .spk71 = 1,
  847. .spdif_bug = 1,
  848. .ac97_chip = 1} ,
  849. {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
  850. .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
  851. .id = "Audigy2",
  852. .emu10k2_chip = 1,
  853. .ca0102_chip = 1,
  854. .ca0151_chip = 1,
  855. .spdif_bug = 1,
  856. .ac97_chip = 1} ,
  857. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
  858. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  859. .id = "Audigy",
  860. .emu10k2_chip = 1,
  861. .ca0102_chip = 1,
  862. .ac97_chip = 1} ,
  863. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
  864. .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
  865. .id = "Audigy",
  866. .emu10k2_chip = 1,
  867. .ca0102_chip = 1,
  868. .spdif_bug = 1,
  869. .ac97_chip = 1} ,
  870. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
  871. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  872. .id = "Audigy",
  873. .emu10k2_chip = 1,
  874. .ca0102_chip = 1,
  875. .ac97_chip = 1} ,
  876. {.vendor = 0x1102, .device = 0x0004,
  877. .driver = "Audigy", .name = "Audigy 1 [Unknown]",
  878. .id = "Audigy",
  879. .emu10k2_chip = 1,
  880. .ca0102_chip = 1,
  881. .ac97_chip = 1} ,
  882. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
  883. .driver = "EMU10K1", .name = "SBLive! [SB0105]",
  884. .id = "Live",
  885. .emu10k1_chip = 1,
  886. .ac97_chip = 1,
  887. .sblive51 = 1} ,
  888. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
  889. .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
  890. .id = "Live",
  891. .emu10k1_chip = 1,
  892. .ac97_chip = 1,
  893. .sblive51 = 1} ,
  894. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
  895. .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
  896. .id = "Live",
  897. .emu10k1_chip = 1,
  898. .ac97_chip = 1,
  899. .sblive51 = 1} ,
  900. /* Tested by ALSA bug#1680 26th December 2005 */
  901. /* note: It really has SB0220 written on the card. */
  902. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
  903. .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]",
  904. .id = "Live",
  905. .emu10k1_chip = 1,
  906. .ac97_chip = 1,
  907. .sblive51 = 1} ,
  908. /* Tested by Thomas Zehetbauer 27th Aug 2005 */
  909. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
  910. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  911. .id = "Live",
  912. .emu10k1_chip = 1,
  913. .ac97_chip = 1,
  914. .sblive51 = 1} ,
  915. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
  916. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  917. .id = "Live",
  918. .emu10k1_chip = 1,
  919. .ac97_chip = 1,
  920. .sblive51 = 1} ,
  921. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  922. .driver = "EMU10K1", .name = "SB Live 5.1",
  923. .id = "Live",
  924. .emu10k1_chip = 1,
  925. .ac97_chip = 1,
  926. .sblive51 = 1} ,
  927. /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
  928. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  929. .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
  930. .id = "Live",
  931. .emu10k1_chip = 1,
  932. .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
  933. * share the same IDs!
  934. */
  935. .sblive51 = 1} ,
  936. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  937. .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
  938. .id = "Live",
  939. .emu10k1_chip = 1,
  940. .ac97_chip = 1,
  941. .sblive51 = 1} ,
  942. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  943. .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
  944. .id = "Live",
  945. .emu10k1_chip = 1,
  946. .ac97_chip = 1} ,
  947. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  948. .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
  949. .id = "Live",
  950. .emu10k1_chip = 1,
  951. .ac97_chip = 1,
  952. .sblive51 = 1} ,
  953. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  954. .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
  955. .id = "Live",
  956. .emu10k1_chip = 1,
  957. .ac97_chip = 1,
  958. .sblive51 = 1} ,
  959. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  960. .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
  961. .id = "Live",
  962. .emu10k1_chip = 1,
  963. .ac97_chip = 1,
  964. .sblive51 = 1} ,
  965. /* Tested by James@superbug.co.uk 3rd July 2005 */
  966. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  967. .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
  968. .id = "Live",
  969. .emu10k1_chip = 1,
  970. .ac97_chip = 1,
  971. .sblive51 = 1} ,
  972. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  973. .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
  974. .id = "Live",
  975. .emu10k1_chip = 1,
  976. .ac97_chip = 1,
  977. .sblive51 = 1} ,
  978. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  979. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  980. .id = "Live",
  981. .emu10k1_chip = 1,
  982. .ac97_chip = 1,
  983. .sblive51 = 1} ,
  984. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  985. .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
  986. .id = "Live",
  987. .emu10k1_chip = 1,
  988. .ac97_chip = 1,
  989. .sblive51 = 1} ,
  990. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  991. .driver = "EMU10K1", .name = "E-mu APS [4001]",
  992. .id = "APS",
  993. .emu10k1_chip = 1,
  994. .ecard = 1} ,
  995. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  996. .driver = "EMU10K1", .name = "SBLive! [CT4620]",
  997. .id = "Live",
  998. .emu10k1_chip = 1,
  999. .ac97_chip = 1,
  1000. .sblive51 = 1} ,
  1001. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  1002. .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
  1003. .id = "Live",
  1004. .emu10k1_chip = 1,
  1005. .ac97_chip = 1,
  1006. .sblive51 = 1} ,
  1007. {.vendor = 0x1102, .device = 0x0002,
  1008. .driver = "EMU10K1", .name = "SB Live [Unknown]",
  1009. .id = "Live",
  1010. .emu10k1_chip = 1,
  1011. .ac97_chip = 1,
  1012. .sblive51 = 1} ,
  1013. { } /* terminator */
  1014. };
  1015. int __devinit snd_emu10k1_create(struct snd_card *card,
  1016. struct pci_dev * pci,
  1017. unsigned short extin_mask,
  1018. unsigned short extout_mask,
  1019. long max_cache_bytes,
  1020. int enable_ir,
  1021. uint subsystem,
  1022. struct snd_emu10k1 ** remu)
  1023. {
  1024. struct snd_emu10k1 *emu;
  1025. int idx, err;
  1026. int is_audigy;
  1027. unsigned char revision;
  1028. unsigned int silent_page;
  1029. const struct snd_emu_chip_details *c;
  1030. static struct snd_device_ops ops = {
  1031. .dev_free = snd_emu10k1_dev_free,
  1032. };
  1033. *remu = NULL;
  1034. /* enable PCI device */
  1035. if ((err = pci_enable_device(pci)) < 0)
  1036. return err;
  1037. emu = kzalloc(sizeof(*emu), GFP_KERNEL);
  1038. if (emu == NULL) {
  1039. pci_disable_device(pci);
  1040. return -ENOMEM;
  1041. }
  1042. emu->card = card;
  1043. spin_lock_init(&emu->reg_lock);
  1044. spin_lock_init(&emu->emu_lock);
  1045. spin_lock_init(&emu->voice_lock);
  1046. spin_lock_init(&emu->synth_lock);
  1047. spin_lock_init(&emu->memblk_lock);
  1048. mutex_init(&emu->fx8010.lock);
  1049. INIT_LIST_HEAD(&emu->mapped_link_head);
  1050. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  1051. emu->pci = pci;
  1052. emu->irq = -1;
  1053. emu->synth = NULL;
  1054. emu->get_synth_voice = NULL;
  1055. /* read revision & serial */
  1056. pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
  1057. emu->revision = revision;
  1058. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  1059. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  1060. 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);
  1061. for (c = emu_chip_details; c->vendor; c++) {
  1062. if (c->vendor == pci->vendor && c->device == pci->device) {
  1063. if (subsystem) {
  1064. if (c->subsystem && (c->subsystem == subsystem) ) {
  1065. break;
  1066. } else continue;
  1067. } else {
  1068. if (c->subsystem && (c->subsystem != emu->serial) )
  1069. continue;
  1070. if (c->revision && c->revision != emu->revision)
  1071. continue;
  1072. }
  1073. break;
  1074. }
  1075. }
  1076. if (c->vendor == 0) {
  1077. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  1078. kfree(emu);
  1079. pci_disable_device(pci);
  1080. return -ENOENT;
  1081. }
  1082. emu->card_capabilities = c;
  1083. if (c->subsystem && !subsystem)
  1084. snd_printdd("Sound card name=%s\n", c->name);
  1085. else if (subsystem)
  1086. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
  1087. c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
  1088. else
  1089. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
  1090. c->name, pci->vendor, pci->device, emu->serial);
  1091. if (!*card->id && c->id) {
  1092. int i, n = 0;
  1093. strlcpy(card->id, c->id, sizeof(card->id));
  1094. for (;;) {
  1095. for (i = 0; i < snd_ecards_limit; i++) {
  1096. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  1097. break;
  1098. }
  1099. if (i >= snd_ecards_limit)
  1100. break;
  1101. n++;
  1102. if (n >= SNDRV_CARDS)
  1103. break;
  1104. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  1105. }
  1106. }
  1107. is_audigy = emu->audigy = c->emu10k2_chip;
  1108. /* set the DMA transfer mask */
  1109. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  1110. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  1111. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  1112. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  1113. kfree(emu);
  1114. pci_disable_device(pci);
  1115. return -ENXIO;
  1116. }
  1117. if (is_audigy)
  1118. emu->gpr_base = A_FXGPREGBASE;
  1119. else
  1120. emu->gpr_base = FXGPREGBASE;
  1121. if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
  1122. kfree(emu);
  1123. pci_disable_device(pci);
  1124. return err;
  1125. }
  1126. emu->port = pci_resource_start(pci, 0);
  1127. if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_DISABLED|IRQF_SHARED, "EMU10K1", (void *)emu)) {
  1128. err = -EBUSY;
  1129. goto error;
  1130. }
  1131. emu->irq = pci->irq;
  1132. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  1133. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1134. 32 * 1024, &emu->ptb_pages) < 0) {
  1135. err = -ENOMEM;
  1136. goto error;
  1137. }
  1138. emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
  1139. emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
  1140. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  1141. err = -ENOMEM;
  1142. goto error;
  1143. }
  1144. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1145. EMUPAGESIZE, &emu->silent_page) < 0) {
  1146. err = -ENOMEM;
  1147. goto error;
  1148. }
  1149. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  1150. if (emu->memhdr == NULL) {
  1151. err = -ENOMEM;
  1152. goto error;
  1153. }
  1154. emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
  1155. sizeof(struct snd_util_memblk);
  1156. pci_set_master(pci);
  1157. emu->fx8010.fxbus_mask = 0x303f;
  1158. if (extin_mask == 0)
  1159. extin_mask = 0x3fcf;
  1160. if (extout_mask == 0)
  1161. extout_mask = 0x7fff;
  1162. emu->fx8010.extin_mask = extin_mask;
  1163. emu->fx8010.extout_mask = extout_mask;
  1164. emu->enable_ir = enable_ir;
  1165. if (emu->card_capabilities->ecard) {
  1166. if ((err = snd_emu10k1_ecard_init(emu)) < 0)
  1167. goto error;
  1168. } else if (emu->card_capabilities->ca_cardbus_chip) {
  1169. if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
  1170. goto error;
  1171. } else if (emu->card_capabilities->emu1212m) {
  1172. if ((err = snd_emu10k1_emu1212m_init(emu)) < 0) {
  1173. snd_emu10k1_free(emu);
  1174. return err;
  1175. }
  1176. } else {
  1177. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  1178. does not support this, it shouldn't do any harm */
  1179. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  1180. }
  1181. /* initialize TRAM setup */
  1182. emu->fx8010.itram_size = (16 * 1024)/2;
  1183. emu->fx8010.etram_pages.area = NULL;
  1184. emu->fx8010.etram_pages.bytes = 0;
  1185. /*
  1186. * Init to 0x02109204 :
  1187. * Clock accuracy = 0 (1000ppm)
  1188. * Sample Rate = 2 (48kHz)
  1189. * Audio Channel = 1 (Left of 2)
  1190. * Source Number = 0 (Unspecified)
  1191. * Generation Status = 1 (Original for Cat Code 12)
  1192. * Cat Code = 12 (Digital Signal Mixer)
  1193. * Mode = 0 (Mode 0)
  1194. * Emphasis = 0 (None)
  1195. * CP = 1 (Copyright unasserted)
  1196. * AN = 0 (Audio data)
  1197. * P = 0 (Consumer)
  1198. */
  1199. emu->spdif_bits[0] = emu->spdif_bits[1] =
  1200. emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1201. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1202. SPCS_GENERATIONSTATUS | 0x00001200 |
  1203. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
  1204. emu->reserved_page = (struct snd_emu10k1_memblk *)
  1205. snd_emu10k1_synth_alloc(emu, 4096);
  1206. if (emu->reserved_page)
  1207. emu->reserved_page->map_locked = 1;
  1208. /* Clear silent pages and set up pointers */
  1209. memset(emu->silent_page.area, 0, PAGE_SIZE);
  1210. silent_page = emu->silent_page.addr << 1;
  1211. for (idx = 0; idx < MAXPAGES; idx++)
  1212. ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
  1213. /* set up voice indices */
  1214. for (idx = 0; idx < NUM_G; idx++) {
  1215. emu->voices[idx].emu = emu;
  1216. emu->voices[idx].number = idx;
  1217. }
  1218. if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
  1219. goto error;
  1220. #ifdef CONFIG_PM
  1221. if ((err = alloc_pm_buffer(emu)) < 0)
  1222. goto error;
  1223. #endif
  1224. /* Initialize the effect engine */
  1225. if ((err = snd_emu10k1_init_efx(emu)) < 0)
  1226. goto error;
  1227. snd_emu10k1_audio_enable(emu);
  1228. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
  1229. goto error;
  1230. #ifdef CONFIG_PROC_FS
  1231. snd_emu10k1_proc_init(emu);
  1232. #endif
  1233. snd_card_set_dev(card, &pci->dev);
  1234. *remu = emu;
  1235. return 0;
  1236. error:
  1237. snd_emu10k1_free(emu);
  1238. return err;
  1239. }
  1240. #ifdef CONFIG_PM
  1241. static unsigned char saved_regs[] = {
  1242. CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
  1243. FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
  1244. ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
  1245. TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
  1246. MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
  1247. SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
  1248. 0xff /* end */
  1249. };
  1250. static unsigned char saved_regs_audigy[] = {
  1251. A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
  1252. A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
  1253. 0xff /* end */
  1254. };
  1255. static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
  1256. {
  1257. int size;
  1258. size = ARRAY_SIZE(saved_regs);
  1259. if (emu->audigy)
  1260. size += ARRAY_SIZE(saved_regs_audigy);
  1261. emu->saved_ptr = vmalloc(4 * NUM_G * size);
  1262. if (! emu->saved_ptr)
  1263. return -ENOMEM;
  1264. if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
  1265. return -ENOMEM;
  1266. if (emu->card_capabilities->ca0151_chip &&
  1267. snd_p16v_alloc_pm_buffer(emu) < 0)
  1268. return -ENOMEM;
  1269. return 0;
  1270. }
  1271. static void free_pm_buffer(struct snd_emu10k1 *emu)
  1272. {
  1273. vfree(emu->saved_ptr);
  1274. snd_emu10k1_efx_free_pm_buffer(emu);
  1275. if (emu->card_capabilities->ca0151_chip)
  1276. snd_p16v_free_pm_buffer(emu);
  1277. }
  1278. void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
  1279. {
  1280. int i;
  1281. unsigned char *reg;
  1282. unsigned int *val;
  1283. val = emu->saved_ptr;
  1284. for (reg = saved_regs; *reg != 0xff; reg++)
  1285. for (i = 0; i < NUM_G; i++, val++)
  1286. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1287. if (emu->audigy) {
  1288. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1289. for (i = 0; i < NUM_G; i++, val++)
  1290. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1291. }
  1292. if (emu->audigy)
  1293. emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
  1294. emu->saved_hcfg = inl(emu->port + HCFG);
  1295. }
  1296. void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
  1297. {
  1298. if (emu->card_capabilities->ecard)
  1299. snd_emu10k1_ecard_init(emu);
  1300. else if (emu->card_capabilities->ca_cardbus_chip)
  1301. snd_emu10k1_cardbus_init(emu);
  1302. else if (emu->card_capabilities->emu1212m)
  1303. snd_emu10k1_emu1212m_init(emu);
  1304. else
  1305. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  1306. snd_emu10k1_init(emu, emu->enable_ir, 1);
  1307. }
  1308. void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
  1309. {
  1310. int i;
  1311. unsigned char *reg;
  1312. unsigned int *val;
  1313. snd_emu10k1_audio_enable(emu);
  1314. /* resore for spdif */
  1315. if (emu->audigy)
  1316. outl(emu->port + A_IOCFG, emu->saved_a_iocfg);
  1317. outl(emu->port + HCFG, emu->saved_hcfg);
  1318. val = emu->saved_ptr;
  1319. for (reg = saved_regs; *reg != 0xff; reg++)
  1320. for (i = 0; i < NUM_G; i++, val++)
  1321. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1322. if (emu->audigy) {
  1323. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1324. for (i = 0; i < NUM_G; i++, val++)
  1325. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1326. }
  1327. }
  1328. #endif