emu10k1_main.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038
  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. /*
  493. * Create the EMU10K1 instance
  494. */
  495. static int snd_emu10k1_free(emu10k1_t *emu)
  496. {
  497. if (emu->port) { /* avoid access to already used hardware */
  498. snd_emu10k1_fx8010_tram_setup(emu, 0);
  499. snd_emu10k1_done(emu);
  500. }
  501. if (emu->memhdr)
  502. snd_util_memhdr_free(emu->memhdr);
  503. if (emu->silent_page.area)
  504. snd_dma_free_pages(&emu->silent_page);
  505. if (emu->ptb_pages.area)
  506. snd_dma_free_pages(&emu->ptb_pages);
  507. vfree(emu->page_ptr_table);
  508. vfree(emu->page_addr_table);
  509. if (emu->irq >= 0)
  510. free_irq(emu->irq, (void *)emu);
  511. if (emu->port)
  512. pci_release_regions(emu->pci);
  513. pci_disable_device(emu->pci);
  514. if (emu->card_capabilities->ca0151_chip) /* P16V */
  515. snd_p16v_free(emu);
  516. kfree(emu);
  517. return 0;
  518. }
  519. static int snd_emu10k1_dev_free(snd_device_t *device)
  520. {
  521. emu10k1_t *emu = device->device_data;
  522. return snd_emu10k1_free(emu);
  523. }
  524. static emu_chip_details_t emu_chip_details[] = {
  525. /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
  526. /* Tested by James@superbug.co.uk 3rd July 2005 */
  527. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
  528. .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
  529. .id = "Audigy2",
  530. .emu10k2_chip = 1,
  531. .ca0108_chip = 1,
  532. .spk71 = 1,
  533. .ac97_chip = 1} ,
  534. {.vendor = 0x1102, .device = 0x0008,
  535. .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
  536. .id = "Audigy2",
  537. .emu10k2_chip = 1,
  538. .ca0108_chip = 1,
  539. .ac97_chip = 1} ,
  540. /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
  541. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
  542. .driver = "Audigy2", .name = "E-mu 1212m [4001]",
  543. .id = "EMU1212m",
  544. .emu10k2_chip = 1,
  545. .ca0102_chip = 1,
  546. .ecard = 1} ,
  547. /* Tested by James@superbug.co.uk 3rd July 2005 */
  548. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
  549. .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
  550. .id = "Audigy2",
  551. .emu10k2_chip = 1,
  552. .ca0102_chip = 1,
  553. .ca0151_chip = 1,
  554. .spk71 = 1,
  555. .spdif_bug = 1,
  556. .ac97_chip = 1} ,
  557. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
  558. .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
  559. .id = "Audigy2",
  560. .emu10k2_chip = 1,
  561. .ca0102_chip = 1,
  562. .ca0151_chip = 1,
  563. .spk71 = 1,
  564. .spdif_bug = 1,
  565. .ac97_chip = 1} ,
  566. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
  567. .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
  568. .id = "Audigy2",
  569. .emu10k2_chip = 1,
  570. .ca0102_chip = 1,
  571. .ca0151_chip = 1,
  572. .spk71 = 1,
  573. .spdif_bug = 1,
  574. .ac97_chip = 1} ,
  575. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
  576. .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
  577. .id = "Audigy2",
  578. .emu10k2_chip = 1,
  579. .ca0102_chip = 1,
  580. .ca0151_chip = 1,
  581. .spk71 = 1,
  582. .spdif_bug = 1,
  583. .ac97_chip = 1} ,
  584. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
  585. .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
  586. .id = "Audigy2",
  587. .emu10k2_chip = 1,
  588. .ca0102_chip = 1,
  589. .ca0151_chip = 1,
  590. .spdif_bug = 1} ,
  591. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
  592. .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
  593. .id = "Audigy2",
  594. .emu10k2_chip = 1,
  595. .ca0102_chip = 1,
  596. .ca0151_chip = 1,
  597. .spk71 = 1,
  598. .spdif_bug = 1,
  599. .ac97_chip = 1} ,
  600. {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
  601. .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
  602. .id = "Audigy2",
  603. .emu10k2_chip = 1,
  604. .ca0102_chip = 1,
  605. .ca0151_chip = 1,
  606. .spdif_bug = 1,
  607. .ac97_chip = 1} ,
  608. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
  609. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  610. .id = "Audigy",
  611. .emu10k2_chip = 1,
  612. .ca0102_chip = 1,
  613. .ac97_chip = 1} ,
  614. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
  615. .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
  616. .id = "Audigy",
  617. .emu10k2_chip = 1,
  618. .ca0102_chip = 1,
  619. .spdif_bug = 1,
  620. .ac97_chip = 1} ,
  621. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
  622. .driver = "Audigy", .name = "Audigy 1 [SB0090]",
  623. .id = "Audigy",
  624. .emu10k2_chip = 1,
  625. .ca0102_chip = 1,
  626. .ac97_chip = 1} ,
  627. {.vendor = 0x1102, .device = 0x0004,
  628. .driver = "Audigy", .name = "Audigy 1 [Unknown]",
  629. .id = "Audigy",
  630. .emu10k2_chip = 1,
  631. .ca0102_chip = 1,
  632. .ac97_chip = 1} ,
  633. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
  634. .driver = "EMU10K1", .name = "SBLive! [SB0105]",
  635. .id = "Live",
  636. .emu10k1_chip = 1,
  637. .ac97_chip = 1,
  638. .sblive51 = 1} ,
  639. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
  640. .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
  641. .id = "Live",
  642. .emu10k1_chip = 1,
  643. .ac97_chip = 1,
  644. .sblive51 = 1} ,
  645. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
  646. .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
  647. .id = "Live",
  648. .emu10k1_chip = 1,
  649. .ac97_chip = 1,
  650. .sblive51 = 1} ,
  651. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  652. .driver = "EMU10K1", .name = "SB Live 5.1",
  653. .id = "Live",
  654. .emu10k1_chip = 1,
  655. .ac97_chip = 1,
  656. .sblive51 = 1} ,
  657. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  658. .driver = "EMU10K1", .name = "SBLive! Player 5.1 [SB0060]",
  659. .id = "Live",
  660. .emu10k1_chip = 1,
  661. .ac97_chip = 1,
  662. .sblive51 = 1} ,
  663. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  664. .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
  665. .id = "Live",
  666. .emu10k1_chip = 1,
  667. .ac97_chip = 1,
  668. .sblive51 = 1} ,
  669. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  670. .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
  671. .id = "Live",
  672. .emu10k1_chip = 1,
  673. .ac97_chip = 1} ,
  674. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  675. .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
  676. .id = "Live",
  677. .emu10k1_chip = 1,
  678. .ac97_chip = 1,
  679. .sblive51 = 1} ,
  680. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  681. .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
  682. .id = "Live",
  683. .emu10k1_chip = 1,
  684. .ac97_chip = 1,
  685. .sblive51 = 1} ,
  686. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  687. .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
  688. .id = "Live",
  689. .emu10k1_chip = 1,
  690. .ac97_chip = 1,
  691. .sblive51 = 1} ,
  692. /* Tested by James@superbug.co.uk 3rd July 2005 */
  693. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  694. .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
  695. .id = "Live",
  696. .emu10k1_chip = 1,
  697. .ac97_chip = 1,
  698. .sblive51 = 1} ,
  699. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  700. .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
  701. .id = "Live",
  702. .emu10k1_chip = 1,
  703. .ac97_chip = 1,
  704. .sblive51 = 1} ,
  705. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  706. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  707. .id = "Live",
  708. .emu10k1_chip = 1,
  709. .ac97_chip = 1,
  710. .sblive51 = 1} ,
  711. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  712. .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
  713. .id = "Live",
  714. .emu10k1_chip = 1,
  715. .ac97_chip = 1,
  716. .sblive51 = 1} ,
  717. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  718. .driver = "EMU10K1", .name = "E-mu APS [4001]",
  719. .id = "APS",
  720. .emu10k1_chip = 1,
  721. .ecard = 1} ,
  722. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  723. .driver = "EMU10K1", .name = "SBLive! [CT4620]",
  724. .id = "Live",
  725. .emu10k1_chip = 1,
  726. .ac97_chip = 1,
  727. .sblive51 = 1} ,
  728. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  729. .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
  730. .id = "Live",
  731. .emu10k1_chip = 1,
  732. .ac97_chip = 1,
  733. .sblive51 = 1} ,
  734. {.vendor = 0x1102, .device = 0x0002,
  735. .driver = "EMU10K1", .name = "SB Live [Unknown]",
  736. .id = "Live",
  737. .emu10k1_chip = 1,
  738. .ac97_chip = 1,
  739. .sblive51 = 1} ,
  740. { } /* terminator */
  741. };
  742. int __devinit snd_emu10k1_create(snd_card_t * card,
  743. struct pci_dev * pci,
  744. unsigned short extin_mask,
  745. unsigned short extout_mask,
  746. long max_cache_bytes,
  747. int enable_ir,
  748. uint subsystem,
  749. emu10k1_t ** remu)
  750. {
  751. emu10k1_t *emu;
  752. int err;
  753. int is_audigy;
  754. unsigned char revision;
  755. const emu_chip_details_t *c;
  756. static snd_device_ops_t ops = {
  757. .dev_free = snd_emu10k1_dev_free,
  758. };
  759. *remu = NULL;
  760. /* enable PCI device */
  761. if ((err = pci_enable_device(pci)) < 0)
  762. return err;
  763. emu = kcalloc(1, sizeof(*emu), GFP_KERNEL);
  764. if (emu == NULL) {
  765. pci_disable_device(pci);
  766. return -ENOMEM;
  767. }
  768. emu->card = card;
  769. spin_lock_init(&emu->reg_lock);
  770. spin_lock_init(&emu->emu_lock);
  771. spin_lock_init(&emu->voice_lock);
  772. spin_lock_init(&emu->synth_lock);
  773. spin_lock_init(&emu->memblk_lock);
  774. init_MUTEX(&emu->ptb_lock);
  775. init_MUTEX(&emu->fx8010.lock);
  776. INIT_LIST_HEAD(&emu->mapped_link_head);
  777. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  778. emu->pci = pci;
  779. emu->irq = -1;
  780. emu->synth = NULL;
  781. emu->get_synth_voice = NULL;
  782. /* read revision & serial */
  783. pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
  784. emu->revision = revision;
  785. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  786. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  787. 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);
  788. for (c = emu_chip_details; c->vendor; c++) {
  789. if (c->vendor == pci->vendor && c->device == pci->device) {
  790. if (subsystem) {
  791. if (c->subsystem && (c->subsystem == subsystem) ) {
  792. break;
  793. } else continue;
  794. } else {
  795. if (c->subsystem && (c->subsystem != emu->serial) )
  796. continue;
  797. if (c->revision && c->revision != emu->revision)
  798. continue;
  799. }
  800. break;
  801. }
  802. }
  803. if (c->vendor == 0) {
  804. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  805. kfree(emu);
  806. pci_disable_device(pci);
  807. return -ENOENT;
  808. }
  809. emu->card_capabilities = c;
  810. if (c->subsystem && !subsystem)
  811. snd_printdd("Sound card name=%s\n", c->name);
  812. else if (subsystem)
  813. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
  814. c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
  815. else
  816. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
  817. c->name, pci->vendor, pci->device, emu->serial);
  818. if (!*card->id && c->id) {
  819. int i, n = 0;
  820. strlcpy(card->id, c->id, sizeof(card->id));
  821. for (;;) {
  822. for (i = 0; i < snd_ecards_limit; i++) {
  823. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  824. break;
  825. }
  826. if (i >= snd_ecards_limit)
  827. break;
  828. n++;
  829. if (n >= SNDRV_CARDS)
  830. break;
  831. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  832. }
  833. }
  834. is_audigy = emu->audigy = c->emu10k2_chip;
  835. /* set the DMA transfer mask */
  836. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  837. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  838. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  839. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  840. kfree(emu);
  841. pci_disable_device(pci);
  842. return -ENXIO;
  843. }
  844. if (is_audigy)
  845. emu->gpr_base = A_FXGPREGBASE;
  846. else
  847. emu->gpr_base = FXGPREGBASE;
  848. if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
  849. kfree(emu);
  850. pci_disable_device(pci);
  851. return err;
  852. }
  853. emu->port = pci_resource_start(pci, 0);
  854. if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) {
  855. snd_emu10k1_free(emu);
  856. return -EBUSY;
  857. }
  858. emu->irq = pci->irq;
  859. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  860. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  861. 32 * 1024, &emu->ptb_pages) < 0) {
  862. snd_emu10k1_free(emu);
  863. return -ENOMEM;
  864. }
  865. emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
  866. emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
  867. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  868. snd_emu10k1_free(emu);
  869. return -ENOMEM;
  870. }
  871. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  872. EMUPAGESIZE, &emu->silent_page) < 0) {
  873. snd_emu10k1_free(emu);
  874. return -ENOMEM;
  875. }
  876. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  877. if (emu->memhdr == NULL) {
  878. snd_emu10k1_free(emu);
  879. return -ENOMEM;
  880. }
  881. emu->memhdr->block_extra_size = sizeof(emu10k1_memblk_t) - sizeof(snd_util_memblk_t);
  882. pci_set_master(pci);
  883. emu->fx8010.fxbus_mask = 0x303f;
  884. if (extin_mask == 0)
  885. extin_mask = 0x3fcf;
  886. if (extout_mask == 0)
  887. extout_mask = 0x7fff;
  888. emu->fx8010.extin_mask = extin_mask;
  889. emu->fx8010.extout_mask = extout_mask;
  890. if (emu->card_capabilities->ecard) {
  891. if ((err = snd_emu10k1_ecard_init(emu)) < 0) {
  892. snd_emu10k1_free(emu);
  893. return err;
  894. }
  895. } else {
  896. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  897. does not support this, it shouldn't do any harm */
  898. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  899. }
  900. if ((err = snd_emu10k1_init(emu, enable_ir)) < 0) {
  901. snd_emu10k1_free(emu);
  902. return err;
  903. }
  904. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) {
  905. snd_emu10k1_free(emu);
  906. return err;
  907. }
  908. snd_emu10k1_proc_init(emu);
  909. snd_card_set_dev(card, &pci->dev);
  910. *remu = emu;
  911. return 0;
  912. }
  913. /* memory.c */
  914. EXPORT_SYMBOL(snd_emu10k1_synth_alloc);
  915. EXPORT_SYMBOL(snd_emu10k1_synth_free);
  916. EXPORT_SYMBOL(snd_emu10k1_synth_bzero);
  917. EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);
  918. EXPORT_SYMBOL(snd_emu10k1_memblk_map);
  919. /* voice.c */
  920. EXPORT_SYMBOL(snd_emu10k1_voice_alloc);
  921. EXPORT_SYMBOL(snd_emu10k1_voice_free);
  922. /* io.c */
  923. EXPORT_SYMBOL(snd_emu10k1_ptr_read);
  924. EXPORT_SYMBOL(snd_emu10k1_ptr_write);