emu10k1_main.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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 <sound/core.h>
  39. #include <sound/emu10k1.h>
  40. #include "p16v.h"
  41. #if 0
  42. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, Creative Labs, Inc.");
  43. MODULE_DESCRIPTION("Routines for control of EMU10K1 chips");
  44. MODULE_LICENSE("GPL");
  45. #endif
  46. /*************************************************************************
  47. * EMU10K1 init / done
  48. *************************************************************************/
  49. void snd_emu10k1_voice_init(emu10k1_t * emu, int ch)
  50. {
  51. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  52. snd_emu10k1_ptr_write(emu, IP, ch, 0);
  53. snd_emu10k1_ptr_write(emu, VTFT, ch, 0xffff);
  54. snd_emu10k1_ptr_write(emu, CVCF, ch, 0xffff);
  55. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  56. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  57. snd_emu10k1_ptr_write(emu, CCR, ch, 0);
  58. snd_emu10k1_ptr_write(emu, PSST, ch, 0);
  59. snd_emu10k1_ptr_write(emu, DSL, ch, 0x10);
  60. snd_emu10k1_ptr_write(emu, CCCA, ch, 0);
  61. snd_emu10k1_ptr_write(emu, Z1, ch, 0);
  62. snd_emu10k1_ptr_write(emu, Z2, ch, 0);
  63. snd_emu10k1_ptr_write(emu, FXRT, ch, 0x32100000);
  64. snd_emu10k1_ptr_write(emu, ATKHLDM, ch, 0);
  65. snd_emu10k1_ptr_write(emu, DCYSUSM, ch, 0);
  66. snd_emu10k1_ptr_write(emu, IFATN, ch, 0xffff);
  67. snd_emu10k1_ptr_write(emu, PEFE, ch, 0);
  68. snd_emu10k1_ptr_write(emu, FMMOD, ch, 0);
  69. snd_emu10k1_ptr_write(emu, TREMFRQ, ch, 24); /* 1 Hz */
  70. snd_emu10k1_ptr_write(emu, FM2FRQ2, ch, 24); /* 1 Hz */
  71. snd_emu10k1_ptr_write(emu, TEMPENV, ch, 0);
  72. /*** these are last so OFF prevents writing ***/
  73. snd_emu10k1_ptr_write(emu, LFOVAL2, ch, 0);
  74. snd_emu10k1_ptr_write(emu, LFOVAL1, ch, 0);
  75. snd_emu10k1_ptr_write(emu, ATKHLDV, ch, 0);
  76. snd_emu10k1_ptr_write(emu, ENVVOL, ch, 0);
  77. snd_emu10k1_ptr_write(emu, ENVVAL, ch, 0);
  78. /* Audigy extra stuffs */
  79. if (emu->audigy) {
  80. snd_emu10k1_ptr_write(emu, 0x4c, ch, 0); /* ?? */
  81. snd_emu10k1_ptr_write(emu, 0x4d, ch, 0); /* ?? */
  82. snd_emu10k1_ptr_write(emu, 0x4e, ch, 0); /* ?? */
  83. snd_emu10k1_ptr_write(emu, 0x4f, ch, 0); /* ?? */
  84. snd_emu10k1_ptr_write(emu, A_FXRT1, ch, 0x03020100);
  85. snd_emu10k1_ptr_write(emu, A_FXRT2, ch, 0x3f3f3f3f);
  86. snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, ch, 0);
  87. }
  88. }
  89. static int __devinit snd_emu10k1_init(emu10k1_t * emu, int enable_ir)
  90. {
  91. int ch, idx, err;
  92. unsigned int silent_page;
  93. emu->fx8010.itram_size = (16 * 1024)/2;
  94. emu->fx8010.etram_pages.area = NULL;
  95. emu->fx8010.etram_pages.bytes = 0;
  96. /* disable audio and lock cache */
  97. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
  98. /* reset recording buffers */
  99. snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
  100. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  101. snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
  102. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  103. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  104. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  105. /* disable channel interrupt */
  106. outl(0, emu->port + INTE);
  107. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  108. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  109. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  110. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  111. if (emu->audigy){
  112. /* set SPDIF bypass mode */
  113. snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
  114. /* enable rear left + rear right AC97 slots */
  115. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT | AC97SLOT_REAR_LEFT);
  116. }
  117. /* init envelope engine */
  118. for (ch = 0; ch < NUM_G; ch++) {
  119. emu->voices[ch].emu = emu;
  120. emu->voices[ch].number = ch;
  121. snd_emu10k1_voice_init(emu, ch);
  122. }
  123. /*
  124. * Init to 0x02109204 :
  125. * Clock accuracy = 0 (1000ppm)
  126. * Sample Rate = 2 (48kHz)
  127. * Audio Channel = 1 (Left of 2)
  128. * Source Number = 0 (Unspecified)
  129. * Generation Status = 1 (Original for Cat Code 12)
  130. * Cat Code = 12 (Digital Signal Mixer)
  131. * Mode = 0 (Mode 0)
  132. * Emphasis = 0 (None)
  133. * CP = 1 (Copyright unasserted)
  134. * AN = 0 (Audio data)
  135. * P = 0 (Consumer)
  136. */
  137. snd_emu10k1_ptr_write(emu, SPCS0, 0,
  138. emu->spdif_bits[0] =
  139. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  140. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  141. SPCS_GENERATIONSTATUS | 0x00001200 |
  142. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  143. snd_emu10k1_ptr_write(emu, SPCS1, 0,
  144. emu->spdif_bits[1] =
  145. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  146. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  147. SPCS_GENERATIONSTATUS | 0x00001200 |
  148. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  149. snd_emu10k1_ptr_write(emu, SPCS2, 0,
  150. emu->spdif_bits[2] =
  151. SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  152. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  153. SPCS_GENERATIONSTATUS | 0x00001200 |
  154. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
  155. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  156. /* Hacks for Alice3 to work independent of haP16V driver */
  157. u32 tmp;
  158. //Setup SRCMulti_I2S SamplingRate
  159. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  160. tmp &= 0xfffff1ff;
  161. tmp |= (0x2<<9);
  162. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  163. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  164. snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
  165. /* Setup SRCMulti Input Audio Enable */
  166. /* Use 0xFFFFFFFF to enable P16V sounds. */
  167. snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
  168. /* Enabled Phased (8-channel) P16V playback */
  169. outl(0x0201, emu->port + HCFG2);
  170. /* Set playback routing. */
  171. snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
  172. }
  173. if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
  174. /* Hacks for Alice3 to work independent of haP16V driver */
  175. u32 tmp;
  176. snd_printk(KERN_ERR "Audigy2 value:Special config.\n");
  177. //Setup SRCMulti_I2S SamplingRate
  178. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  179. tmp &= 0xfffff1ff;
  180. tmp |= (0x2<<9);
  181. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  182. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  183. outl(0x600000, emu->port + 0x20);
  184. outl(0x14, emu->port + 0x24);
  185. /* Setup SRCMulti Input Audio Enable */
  186. outl(0x7b0000, emu->port + 0x20);
  187. outl(0xFF000000, emu->port + 0x24);
  188. /* Setup SPDIF Out Audio Enable */
  189. /* The Audigy 2 Value has a separate SPDIF out,
  190. * so no need for a mixer switch
  191. */
  192. outl(0x7a0000, emu->port + 0x20);
  193. outl(0xFF000000, emu->port + 0x24);
  194. tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
  195. outl(tmp, emu->port + A_IOCFG);
  196. }
  197. /*
  198. * Clear page with silence & setup all pointers to this page
  199. */
  200. memset(emu->silent_page.area, 0, PAGE_SIZE);
  201. silent_page = emu->silent_page.addr << 1;
  202. for (idx = 0; idx < MAXPAGES; idx++)
  203. ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
  204. snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
  205. snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
  206. snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
  207. silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
  208. for (ch = 0; ch < NUM_G; ch++) {
  209. snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
  210. snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
  211. }
  212. /*
  213. * Hokay, setup HCFG
  214. * Mute Disable Audio = 0
  215. * Lock Tank Memory = 1
  216. * Lock Sound Memory = 0
  217. * Auto Mute = 1
  218. */
  219. if (emu->audigy) {
  220. if (emu->revision == 4) /* audigy2 */
  221. outl(HCFG_AUDIOENABLE |
  222. HCFG_AC3ENABLE_CDSPDIF |
  223. HCFG_AC3ENABLE_GPSPDIF |
  224. HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  225. else
  226. outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  227. /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
  228. * e.g. card_capabilities->joystick */
  229. } else if (emu->model == 0x20 ||
  230. emu->model == 0xc400 ||
  231. (emu->model == 0x21 && emu->revision < 6))
  232. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
  233. else
  234. // With on-chip joystick
  235. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  236. if (enable_ir) { /* enable IR for SB Live */
  237. 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->audigy) { /* enable analog output */
  254. unsigned int reg = inl(emu->port + A_IOCFG);
  255. outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
  256. }
  257. /*
  258. * Initialize the effect engine
  259. */
  260. if ((err = snd_emu10k1_init_efx(emu)) < 0)
  261. return err;
  262. /*
  263. * Enable the audio bit
  264. */
  265. outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
  266. /* Enable analog/digital outs on audigy */
  267. if (emu->audigy) {
  268. outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
  269. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  270. /* Unmute Analog now. Set GPO6 to 1 for Apollo.
  271. * This has to be done after init ALice3 I2SOut beyond 48KHz.
  272. * So, sequence is important. */
  273. outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
  274. } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
  275. /* Unmute Analog now. */
  276. outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
  277. } else {
  278. /* Disable routing from AC97 line out to Front speakers */
  279. outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
  280. }
  281. }
  282. #if 0
  283. {
  284. unsigned int tmp;
  285. /* FIXME: the following routine disables LiveDrive-II !! */
  286. // TOSLink detection
  287. emu->tos_link = 0;
  288. tmp = inl(emu->port + HCFG);
  289. if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
  290. outl(tmp|0x800, emu->port + HCFG);
  291. udelay(50);
  292. if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
  293. emu->tos_link = 1;
  294. outl(tmp, emu->port + HCFG);
  295. }
  296. }
  297. }
  298. #endif
  299. snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
  300. emu->reserved_page = (emu10k1_memblk_t *)snd_emu10k1_synth_alloc(emu, 4096);
  301. if (emu->reserved_page)
  302. emu->reserved_page->map_locked = 1;
  303. return 0;
  304. }
  305. static int snd_emu10k1_done(emu10k1_t * emu)
  306. {
  307. int ch;
  308. outl(0, emu->port + INTE);
  309. /*
  310. * Shutdown the chip
  311. */
  312. for (ch = 0; ch < NUM_G; ch++)
  313. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  314. for (ch = 0; ch < NUM_G; ch++) {
  315. snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
  316. snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
  317. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  318. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  319. }
  320. /* reset recording buffers */
  321. snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
  322. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  323. snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
  324. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  325. snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
  326. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  327. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  328. snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
  329. snd_emu10k1_ptr_write(emu, TCB, 0, 0);
  330. if (emu->audigy)
  331. snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
  332. else
  333. snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
  334. /* disable channel interrupt */
  335. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  336. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  337. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  338. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  339. /* remove reserved page */
  340. if (emu->reserved_page != NULL) {
  341. snd_emu10k1_synth_free(emu, (snd_util_memblk_t *)emu->reserved_page);
  342. emu->reserved_page = NULL;
  343. }
  344. /* disable audio and lock cache */
  345. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
  346. snd_emu10k1_ptr_write(emu, PTB, 0, 0);
  347. snd_emu10k1_free_efx(emu);
  348. return 0;
  349. }
  350. /*************************************************************************
  351. * ECARD functional implementation
  352. *************************************************************************/
  353. /* In A1 Silicon, these bits are in the HC register */
  354. #define HOOKN_BIT (1L << 12)
  355. #define HANDN_BIT (1L << 11)
  356. #define PULSEN_BIT (1L << 10)
  357. #define EC_GDI1 (1 << 13)
  358. #define EC_GDI0 (1 << 14)
  359. #define EC_NUM_CONTROL_BITS 20
  360. #define EC_AC3_DATA_SELN 0x0001L
  361. #define EC_EE_DATA_SEL 0x0002L
  362. #define EC_EE_CNTRL_SELN 0x0004L
  363. #define EC_EECLK 0x0008L
  364. #define EC_EECS 0x0010L
  365. #define EC_EESDO 0x0020L
  366. #define EC_TRIM_CSN 0x0040L
  367. #define EC_TRIM_SCLK 0x0080L
  368. #define EC_TRIM_SDATA 0x0100L
  369. #define EC_TRIM_MUTEN 0x0200L
  370. #define EC_ADCCAL 0x0400L
  371. #define EC_ADCRSTN 0x0800L
  372. #define EC_DACCAL 0x1000L
  373. #define EC_DACMUTEN 0x2000L
  374. #define EC_LEDN 0x4000L
  375. #define EC_SPDIF0_SEL_SHIFT 15
  376. #define EC_SPDIF1_SEL_SHIFT 17
  377. #define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
  378. #define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
  379. #define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
  380. #define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
  381. #define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
  382. * be incremented any time the EEPROM's
  383. * format is changed. */
  384. #define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
  385. /* Addresses for special values stored in to EEPROM */
  386. #define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
  387. #define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
  388. #define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
  389. #define EC_LAST_PROMFILE_ADDR 0x2f
  390. #define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
  391. * can be up to 30 characters in length
  392. * and is stored as a NULL-terminated
  393. * ASCII string. Any unused bytes must be
  394. * filled with zeros */
  395. #define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
  396. /* Most of this stuff is pretty self-evident. According to the hardware
  397. * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
  398. * offset problem. Weird.
  399. */
  400. #define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
  401. EC_TRIM_CSN)
  402. #define EC_DEFAULT_ADC_GAIN 0xC4C4
  403. #define EC_DEFAULT_SPDIF0_SEL 0x0
  404. #define EC_DEFAULT_SPDIF1_SEL 0x4
  405. /**************************************************************************
  406. * @func Clock bits into the Ecard's control latch. The Ecard uses a
  407. * control latch will is loaded bit-serially by toggling the Modem control
  408. * lines from function 2 on the E8010. This function hides these details
  409. * and presents the illusion that we are actually writing to a distinct
  410. * register.
  411. */
  412. static void snd_emu10k1_ecard_write(emu10k1_t * emu, unsigned int value)
  413. {
  414. unsigned short count;
  415. unsigned int data;
  416. unsigned long hc_port;
  417. unsigned int hc_value;
  418. hc_port = emu->port + HCFG;
  419. hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
  420. outl(hc_value, hc_port);
  421. for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
  422. /* Set up the value */
  423. data = ((value & 0x1) ? PULSEN_BIT : 0);
  424. value >>= 1;
  425. outl(hc_value | data, hc_port);
  426. /* Clock the shift register */
  427. outl(hc_value | data | HANDN_BIT, hc_port);
  428. outl(hc_value | data, hc_port);
  429. }
  430. /* Latch the bits */
  431. outl(hc_value | HOOKN_BIT, hc_port);
  432. outl(hc_value, hc_port);
  433. }
  434. /**************************************************************************
  435. * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
  436. * trim value consists of a 16bit value which is composed of two
  437. * 8 bit gain/trim values, one for the left channel and one for the
  438. * right channel. The following table maps from the Gain/Attenuation
  439. * value in decibels into the corresponding bit pattern for a single
  440. * channel.
  441. */
  442. static void snd_emu10k1_ecard_setadcgain(emu10k1_t * emu,
  443. unsigned short gain)
  444. {
  445. unsigned int bit;
  446. /* Enable writing to the TRIM registers */
  447. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  448. /* Do it again to insure that we meet hold time requirements */
  449. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  450. for (bit = (1 << 15); bit; bit >>= 1) {
  451. unsigned int value;
  452. value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
  453. if (gain & bit)
  454. value |= EC_TRIM_SDATA;
  455. /* Clock the bit */
  456. snd_emu10k1_ecard_write(emu, value);
  457. snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
  458. snd_emu10k1_ecard_write(emu, value);
  459. }
  460. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  461. }
  462. static int __devinit snd_emu10k1_ecard_init(emu10k1_t * emu)
  463. {
  464. unsigned int hc_value;
  465. /* Set up the initial settings */
  466. emu->ecard_ctrl = EC_RAW_RUN_MODE |
  467. EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
  468. EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
  469. /* Step 0: Set the codec type in the hardware control register
  470. * and enable audio output */
  471. hc_value = inl(emu->port + HCFG);
  472. outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
  473. inl(emu->port + HCFG);
  474. /* Step 1: Turn off the led and deassert TRIM_CS */
  475. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  476. /* Step 2: Calibrate the ADC and DAC */
  477. snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
  478. /* Step 3: Wait for awhile; XXX We can't get away with this
  479. * under a real operating system; we'll need to block and wait that
  480. * way. */
  481. snd_emu10k1_wait(emu, 48000);
  482. /* Step 4: Switch off the DAC and ADC calibration. Note
  483. * That ADC_CAL is actually an inverted signal, so we assert
  484. * it here to stop calibration. */
  485. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  486. /* Step 4: Switch into run mode */
  487. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  488. /* Step 5: Set the analog input gain */
  489. snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
  490. return 0;
  491. }
  492. static int __devinit snd_emu10k1_cardbus_init(emu10k1_t * emu)
  493. {
  494. unsigned long special_port;
  495. unsigned int value;
  496. /* Special initialisation routine
  497. * before the rest of the IO-Ports become active.
  498. */
  499. special_port = emu->port + 0x38;
  500. value = inl(special_port);
  501. outl(0x00d00000, special_port);
  502. value = inl(special_port);
  503. outl(0x00d00001, special_port);
  504. value = inl(special_port);
  505. outl(0x00d0005f, special_port);
  506. value = inl(special_port);
  507. outl(0x00d0007f, special_port);
  508. value = inl(special_port);
  509. outl(0x0090007f, special_port);
  510. value = inl(special_port);
  511. return 0;
  512. }
  513. /*
  514. * Create the EMU10K1 instance
  515. */
  516. static int snd_emu10k1_free(emu10k1_t *emu)
  517. {
  518. if (emu->port) { /* avoid access to already used hardware */
  519. snd_emu10k1_fx8010_tram_setup(emu, 0);
  520. snd_emu10k1_done(emu);
  521. }
  522. if (emu->memhdr)
  523. snd_util_memhdr_free(emu->memhdr);
  524. if (emu->silent_page.area)
  525. snd_dma_free_pages(&emu->silent_page);
  526. if (emu->ptb_pages.area)
  527. snd_dma_free_pages(&emu->ptb_pages);
  528. vfree(emu->page_ptr_table);
  529. vfree(emu->page_addr_table);
  530. if (emu->irq >= 0)
  531. free_irq(emu->irq, (void *)emu);
  532. if (emu->port)
  533. pci_release_regions(emu->pci);
  534. pci_disable_device(emu->pci);
  535. if (emu->card_capabilities->ca0151_chip) /* P16V */
  536. snd_p16v_free(emu);
  537. kfree(emu);
  538. return 0;
  539. }
  540. static int snd_emu10k1_dev_free(snd_device_t *device)
  541. {
  542. emu10k1_t *emu = device->device_data;
  543. return snd_emu10k1_free(emu);
  544. }
  545. static emu_chip_details_t emu_chip_details[] = {
  546. /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
  547. /* Tested by James@superbug.co.uk 3rd July 2005 */
  548. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
  549. .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
  550. .id = "Audigy2",
  551. .emu10k2_chip = 1,
  552. .ca0108_chip = 1,
  553. .spk71 = 1,
  554. .ac97_chip = 1} ,
  555. /* Audigy 2 ZS Notebook Cardbus card.*/
  556. /* Tested by James@superbug.co.uk 30th October 2005 */
  557. /* Not working yet, but progressing. */
  558. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
  559. .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
  560. .id = "Audigy2",
  561. .emu10k2_chip = 1,
  562. .ca0108_chip = 1,
  563. .ca_cardbus_chip = 1,
  564. .spk71 = 1} ,
  565. {.vendor = 0x1102, .device = 0x0008,
  566. .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
  567. .id = "Audigy2",
  568. .emu10k2_chip = 1,
  569. .ca0108_chip = 1,
  570. .ac97_chip = 1} ,
  571. /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
  572. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
  573. .driver = "Audigy2", .name = "E-mu 1212m [4001]",
  574. .id = "EMU1212m",
  575. .emu10k2_chip = 1,
  576. .ca0102_chip = 1,
  577. .ecard = 1} ,
  578. /* Tested by James@superbug.co.uk 3rd July 2005 */
  579. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
  580. .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
  581. .id = "Audigy2",
  582. .emu10k2_chip = 1,
  583. .ca0102_chip = 1,
  584. .ca0151_chip = 1,
  585. .spk71 = 1,
  586. .spdif_bug = 1,
  587. .ac97_chip = 1} ,
  588. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
  589. .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
  590. .id = "Audigy2",
  591. .emu10k2_chip = 1,
  592. .ca0102_chip = 1,
  593. .ca0151_chip = 1,
  594. .spk71 = 1,
  595. .spdif_bug = 1,
  596. .ac97_chip = 1} ,
  597. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
  598. .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
  599. .id = "Audigy2",
  600. .emu10k2_chip = 1,
  601. .ca0102_chip = 1,
  602. .ca0151_chip = 1,
  603. .spk71 = 1,
  604. .spdif_bug = 1,
  605. .ac97_chip = 1} ,
  606. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
  607. .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
  608. .id = "Audigy2",
  609. .emu10k2_chip = 1,
  610. .ca0102_chip = 1,
  611. .ca0151_chip = 1,
  612. .spk71 = 1,
  613. .spdif_bug = 1,
  614. .ac97_chip = 1} ,
  615. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
  616. .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
  617. .id = "Audigy2",
  618. .emu10k2_chip = 1,
  619. .ca0102_chip = 1,
  620. .ca0151_chip = 1,
  621. .spdif_bug = 1} ,
  622. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
  623. .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
  624. .id = "Audigy2",
  625. .emu10k2_chip = 1,
  626. .ca0102_chip = 1,
  627. .ca0151_chip = 1,
  628. .spk71 = 1,
  629. .spdif_bug = 1,
  630. .ac97_chip = 1} ,
  631. {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
  632. .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
  633. .id = "Audigy2",
  634. .emu10k2_chip = 1,
  635. .ca0102_chip = 1,
  636. .ca0151_chip = 1,
  637. .spdif_bug = 1,
  638. .ac97_chip = 1} ,
  639. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
  640. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  641. .id = "Audigy",
  642. .emu10k2_chip = 1,
  643. .ca0102_chip = 1,
  644. .ac97_chip = 1} ,
  645. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
  646. .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
  647. .id = "Audigy",
  648. .emu10k2_chip = 1,
  649. .ca0102_chip = 1,
  650. .spdif_bug = 1,
  651. .ac97_chip = 1} ,
  652. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
  653. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  654. .id = "Audigy",
  655. .emu10k2_chip = 1,
  656. .ca0102_chip = 1,
  657. .ac97_chip = 1} ,
  658. {.vendor = 0x1102, .device = 0x0004,
  659. .driver = "Audigy", .name = "Audigy 1 [Unknown]",
  660. .id = "Audigy",
  661. .emu10k2_chip = 1,
  662. .ca0102_chip = 1,
  663. .ac97_chip = 1} ,
  664. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
  665. .driver = "EMU10K1", .name = "SBLive! [SB0105]",
  666. .id = "Live",
  667. .emu10k1_chip = 1,
  668. .ac97_chip = 1,
  669. .sblive51 = 1} ,
  670. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
  671. .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
  672. .id = "Live",
  673. .emu10k1_chip = 1,
  674. .ac97_chip = 1,
  675. .sblive51 = 1} ,
  676. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
  677. .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
  678. .id = "Live",
  679. .emu10k1_chip = 1,
  680. .ac97_chip = 1,
  681. .sblive51 = 1} ,
  682. /* Tested by Thomas Zehetbauer 27th Aug 2005 */
  683. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
  684. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  685. .id = "Live",
  686. .emu10k1_chip = 1,
  687. .ac97_chip = 1,
  688. .sblive51 = 1} ,
  689. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  690. .driver = "EMU10K1", .name = "SB Live 5.1",
  691. .id = "Live",
  692. .emu10k1_chip = 1,
  693. .ac97_chip = 1,
  694. .sblive51 = 1} ,
  695. /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
  696. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  697. .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
  698. .id = "Live",
  699. .emu10k1_chip = 1,
  700. .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
  701. * share the same IDs!
  702. */
  703. .sblive51 = 1} ,
  704. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  705. .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
  706. .id = "Live",
  707. .emu10k1_chip = 1,
  708. .ac97_chip = 1,
  709. .sblive51 = 1} ,
  710. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  711. .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
  712. .id = "Live",
  713. .emu10k1_chip = 1,
  714. .ac97_chip = 1} ,
  715. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  716. .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
  717. .id = "Live",
  718. .emu10k1_chip = 1,
  719. .ac97_chip = 1,
  720. .sblive51 = 1} ,
  721. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  722. .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
  723. .id = "Live",
  724. .emu10k1_chip = 1,
  725. .ac97_chip = 1,
  726. .sblive51 = 1} ,
  727. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  728. .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
  729. .id = "Live",
  730. .emu10k1_chip = 1,
  731. .ac97_chip = 1,
  732. .sblive51 = 1} ,
  733. /* Tested by James@superbug.co.uk 3rd July 2005 */
  734. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  735. .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
  736. .id = "Live",
  737. .emu10k1_chip = 1,
  738. .ac97_chip = 1,
  739. .sblive51 = 1} ,
  740. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  741. .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
  742. .id = "Live",
  743. .emu10k1_chip = 1,
  744. .ac97_chip = 1,
  745. .sblive51 = 1} ,
  746. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  747. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  748. .id = "Live",
  749. .emu10k1_chip = 1,
  750. .ac97_chip = 1,
  751. .sblive51 = 1} ,
  752. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  753. .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
  754. .id = "Live",
  755. .emu10k1_chip = 1,
  756. .ac97_chip = 1,
  757. .sblive51 = 1} ,
  758. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  759. .driver = "EMU10K1", .name = "E-mu APS [4001]",
  760. .id = "APS",
  761. .emu10k1_chip = 1,
  762. .ecard = 1} ,
  763. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  764. .driver = "EMU10K1", .name = "SBLive! [CT4620]",
  765. .id = "Live",
  766. .emu10k1_chip = 1,
  767. .ac97_chip = 1,
  768. .sblive51 = 1} ,
  769. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  770. .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
  771. .id = "Live",
  772. .emu10k1_chip = 1,
  773. .ac97_chip = 1,
  774. .sblive51 = 1} ,
  775. {.vendor = 0x1102, .device = 0x0002,
  776. .driver = "EMU10K1", .name = "SB Live [Unknown]",
  777. .id = "Live",
  778. .emu10k1_chip = 1,
  779. .ac97_chip = 1,
  780. .sblive51 = 1} ,
  781. { } /* terminator */
  782. };
  783. int __devinit snd_emu10k1_create(snd_card_t * card,
  784. struct pci_dev * pci,
  785. unsigned short extin_mask,
  786. unsigned short extout_mask,
  787. long max_cache_bytes,
  788. int enable_ir,
  789. uint subsystem,
  790. emu10k1_t ** remu)
  791. {
  792. emu10k1_t *emu;
  793. int err;
  794. int is_audigy;
  795. unsigned char revision;
  796. const emu_chip_details_t *c;
  797. static snd_device_ops_t ops = {
  798. .dev_free = snd_emu10k1_dev_free,
  799. };
  800. *remu = NULL;
  801. /* enable PCI device */
  802. if ((err = pci_enable_device(pci)) < 0)
  803. return err;
  804. emu = kzalloc(sizeof(*emu), GFP_KERNEL);
  805. if (emu == NULL) {
  806. pci_disable_device(pci);
  807. return -ENOMEM;
  808. }
  809. emu->card = card;
  810. spin_lock_init(&emu->reg_lock);
  811. spin_lock_init(&emu->emu_lock);
  812. spin_lock_init(&emu->voice_lock);
  813. spin_lock_init(&emu->synth_lock);
  814. spin_lock_init(&emu->memblk_lock);
  815. init_MUTEX(&emu->ptb_lock);
  816. init_MUTEX(&emu->fx8010.lock);
  817. INIT_LIST_HEAD(&emu->mapped_link_head);
  818. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  819. emu->pci = pci;
  820. emu->irq = -1;
  821. emu->synth = NULL;
  822. emu->get_synth_voice = NULL;
  823. /* read revision & serial */
  824. pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
  825. emu->revision = revision;
  826. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  827. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  828. 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);
  829. for (c = emu_chip_details; c->vendor; c++) {
  830. if (c->vendor == pci->vendor && c->device == pci->device) {
  831. if (subsystem) {
  832. if (c->subsystem && (c->subsystem == subsystem) ) {
  833. break;
  834. } else continue;
  835. } else {
  836. if (c->subsystem && (c->subsystem != emu->serial) )
  837. continue;
  838. if (c->revision && c->revision != emu->revision)
  839. continue;
  840. }
  841. break;
  842. }
  843. }
  844. if (c->vendor == 0) {
  845. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  846. kfree(emu);
  847. pci_disable_device(pci);
  848. return -ENOENT;
  849. }
  850. emu->card_capabilities = c;
  851. if (c->subsystem && !subsystem)
  852. snd_printdd("Sound card name=%s\n", c->name);
  853. else if (subsystem)
  854. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
  855. c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
  856. else
  857. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
  858. c->name, pci->vendor, pci->device, emu->serial);
  859. if (!*card->id && c->id) {
  860. int i, n = 0;
  861. strlcpy(card->id, c->id, sizeof(card->id));
  862. for (;;) {
  863. for (i = 0; i < snd_ecards_limit; i++) {
  864. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  865. break;
  866. }
  867. if (i >= snd_ecards_limit)
  868. break;
  869. n++;
  870. if (n >= SNDRV_CARDS)
  871. break;
  872. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  873. }
  874. }
  875. is_audigy = emu->audigy = c->emu10k2_chip;
  876. /* set the DMA transfer mask */
  877. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  878. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  879. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  880. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  881. kfree(emu);
  882. pci_disable_device(pci);
  883. return -ENXIO;
  884. }
  885. if (is_audigy)
  886. emu->gpr_base = A_FXGPREGBASE;
  887. else
  888. emu->gpr_base = FXGPREGBASE;
  889. if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
  890. kfree(emu);
  891. pci_disable_device(pci);
  892. return err;
  893. }
  894. emu->port = pci_resource_start(pci, 0);
  895. if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) {
  896. snd_emu10k1_free(emu);
  897. return -EBUSY;
  898. }
  899. emu->irq = pci->irq;
  900. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  901. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  902. 32 * 1024, &emu->ptb_pages) < 0) {
  903. snd_emu10k1_free(emu);
  904. return -ENOMEM;
  905. }
  906. emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
  907. emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
  908. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  909. snd_emu10k1_free(emu);
  910. return -ENOMEM;
  911. }
  912. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  913. EMUPAGESIZE, &emu->silent_page) < 0) {
  914. snd_emu10k1_free(emu);
  915. return -ENOMEM;
  916. }
  917. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  918. if (emu->memhdr == NULL) {
  919. snd_emu10k1_free(emu);
  920. return -ENOMEM;
  921. }
  922. emu->memhdr->block_extra_size = sizeof(emu10k1_memblk_t) - sizeof(snd_util_memblk_t);
  923. pci_set_master(pci);
  924. emu->fx8010.fxbus_mask = 0x303f;
  925. if (extin_mask == 0)
  926. extin_mask = 0x3fcf;
  927. if (extout_mask == 0)
  928. extout_mask = 0x7fff;
  929. emu->fx8010.extin_mask = extin_mask;
  930. emu->fx8010.extout_mask = extout_mask;
  931. if (emu->card_capabilities->ecard) {
  932. if ((err = snd_emu10k1_ecard_init(emu)) < 0) {
  933. snd_emu10k1_free(emu);
  934. return err;
  935. }
  936. } else if (emu->card_capabilities->ca_cardbus_chip) {
  937. if ((err = snd_emu10k1_cardbus_init(emu)) < 0) {
  938. snd_emu10k1_free(emu);
  939. return err;
  940. }
  941. } else {
  942. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  943. does not support this, it shouldn't do any harm */
  944. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  945. }
  946. if ((err = snd_emu10k1_init(emu, enable_ir)) < 0) {
  947. snd_emu10k1_free(emu);
  948. return err;
  949. }
  950. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) {
  951. snd_emu10k1_free(emu);
  952. return err;
  953. }
  954. snd_emu10k1_proc_init(emu);
  955. snd_card_set_dev(card, &pci->dev);
  956. *remu = emu;
  957. return 0;
  958. }
  959. /* memory.c */
  960. EXPORT_SYMBOL(snd_emu10k1_synth_alloc);
  961. EXPORT_SYMBOL(snd_emu10k1_synth_free);
  962. EXPORT_SYMBOL(snd_emu10k1_synth_bzero);
  963. EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);
  964. EXPORT_SYMBOL(snd_emu10k1_memblk_map);
  965. /* voice.c */
  966. EXPORT_SYMBOL(snd_emu10k1_voice_alloc);
  967. EXPORT_SYMBOL(snd_emu10k1_voice_free);
  968. /* io.c */
  969. EXPORT_SYMBOL(snd_emu10k1_ptr_read);
  970. EXPORT_SYMBOL(snd_emu10k1_ptr_write);