emu10k1_main.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046
  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. /* Tested by Thomas Zehetbauer 27th Aug 2005 */
  652. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
  653. .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
  654. .id = "Live",
  655. .emu10k1_chip = 1,
  656. .ac97_chip = 1,
  657. .sblive51 = 1} ,
  658. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  659. .driver = "EMU10K1", .name = "SB Live 5.1",
  660. .id = "Live",
  661. .emu10k1_chip = 1,
  662. .ac97_chip = 1,
  663. .sblive51 = 1} ,
  664. /* Tested by alsa bugtrack user "hus" 12th Sept 2005 */
  665. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  666. .driver = "EMU10K1", .name = "SBLive! Player 5.1 [SB0060]",
  667. .id = "Live",
  668. .emu10k1_chip = 1,
  669. .ac97_chip = 1,
  670. .sblive51 = 1} ,
  671. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  672. .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
  673. .id = "Live",
  674. .emu10k1_chip = 1,
  675. .ac97_chip = 1,
  676. .sblive51 = 1} ,
  677. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  678. .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
  679. .id = "Live",
  680. .emu10k1_chip = 1,
  681. .ac97_chip = 1} ,
  682. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  683. .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
  684. .id = "Live",
  685. .emu10k1_chip = 1,
  686. .ac97_chip = 1,
  687. .sblive51 = 1} ,
  688. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  689. .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
  690. .id = "Live",
  691. .emu10k1_chip = 1,
  692. .ac97_chip = 1,
  693. .sblive51 = 1} ,
  694. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  695. .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
  696. .id = "Live",
  697. .emu10k1_chip = 1,
  698. .ac97_chip = 1,
  699. .sblive51 = 1} ,
  700. /* Tested by James@superbug.co.uk 3rd July 2005 */
  701. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  702. .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
  703. .id = "Live",
  704. .emu10k1_chip = 1,
  705. .ac97_chip = 1,
  706. .sblive51 = 1} ,
  707. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  708. .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
  709. .id = "Live",
  710. .emu10k1_chip = 1,
  711. .ac97_chip = 1,
  712. .sblive51 = 1} ,
  713. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  714. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  715. .id = "Live",
  716. .emu10k1_chip = 1,
  717. .ac97_chip = 1,
  718. .sblive51 = 1} ,
  719. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  720. .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
  721. .id = "Live",
  722. .emu10k1_chip = 1,
  723. .ac97_chip = 1,
  724. .sblive51 = 1} ,
  725. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  726. .driver = "EMU10K1", .name = "E-mu APS [4001]",
  727. .id = "APS",
  728. .emu10k1_chip = 1,
  729. .ecard = 1} ,
  730. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  731. .driver = "EMU10K1", .name = "SBLive! [CT4620]",
  732. .id = "Live",
  733. .emu10k1_chip = 1,
  734. .ac97_chip = 1,
  735. .sblive51 = 1} ,
  736. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  737. .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
  738. .id = "Live",
  739. .emu10k1_chip = 1,
  740. .ac97_chip = 1,
  741. .sblive51 = 1} ,
  742. {.vendor = 0x1102, .device = 0x0002,
  743. .driver = "EMU10K1", .name = "SB Live [Unknown]",
  744. .id = "Live",
  745. .emu10k1_chip = 1,
  746. .ac97_chip = 1,
  747. .sblive51 = 1} ,
  748. { } /* terminator */
  749. };
  750. int __devinit snd_emu10k1_create(snd_card_t * card,
  751. struct pci_dev * pci,
  752. unsigned short extin_mask,
  753. unsigned short extout_mask,
  754. long max_cache_bytes,
  755. int enable_ir,
  756. uint subsystem,
  757. emu10k1_t ** remu)
  758. {
  759. emu10k1_t *emu;
  760. int err;
  761. int is_audigy;
  762. unsigned char revision;
  763. const emu_chip_details_t *c;
  764. static snd_device_ops_t ops = {
  765. .dev_free = snd_emu10k1_dev_free,
  766. };
  767. *remu = NULL;
  768. /* enable PCI device */
  769. if ((err = pci_enable_device(pci)) < 0)
  770. return err;
  771. emu = kcalloc(1, sizeof(*emu), GFP_KERNEL);
  772. if (emu == NULL) {
  773. pci_disable_device(pci);
  774. return -ENOMEM;
  775. }
  776. emu->card = card;
  777. spin_lock_init(&emu->reg_lock);
  778. spin_lock_init(&emu->emu_lock);
  779. spin_lock_init(&emu->voice_lock);
  780. spin_lock_init(&emu->synth_lock);
  781. spin_lock_init(&emu->memblk_lock);
  782. init_MUTEX(&emu->ptb_lock);
  783. init_MUTEX(&emu->fx8010.lock);
  784. INIT_LIST_HEAD(&emu->mapped_link_head);
  785. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  786. emu->pci = pci;
  787. emu->irq = -1;
  788. emu->synth = NULL;
  789. emu->get_synth_voice = NULL;
  790. /* read revision & serial */
  791. pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
  792. emu->revision = revision;
  793. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  794. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  795. 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);
  796. for (c = emu_chip_details; c->vendor; c++) {
  797. if (c->vendor == pci->vendor && c->device == pci->device) {
  798. if (subsystem) {
  799. if (c->subsystem && (c->subsystem == subsystem) ) {
  800. break;
  801. } else continue;
  802. } else {
  803. if (c->subsystem && (c->subsystem != emu->serial) )
  804. continue;
  805. if (c->revision && c->revision != emu->revision)
  806. continue;
  807. }
  808. break;
  809. }
  810. }
  811. if (c->vendor == 0) {
  812. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  813. kfree(emu);
  814. pci_disable_device(pci);
  815. return -ENOENT;
  816. }
  817. emu->card_capabilities = c;
  818. if (c->subsystem && !subsystem)
  819. snd_printdd("Sound card name=%s\n", c->name);
  820. else if (subsystem)
  821. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
  822. c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
  823. else
  824. snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
  825. c->name, pci->vendor, pci->device, emu->serial);
  826. if (!*card->id && c->id) {
  827. int i, n = 0;
  828. strlcpy(card->id, c->id, sizeof(card->id));
  829. for (;;) {
  830. for (i = 0; i < snd_ecards_limit; i++) {
  831. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  832. break;
  833. }
  834. if (i >= snd_ecards_limit)
  835. break;
  836. n++;
  837. if (n >= SNDRV_CARDS)
  838. break;
  839. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  840. }
  841. }
  842. is_audigy = emu->audigy = c->emu10k2_chip;
  843. /* set the DMA transfer mask */
  844. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  845. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  846. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  847. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  848. kfree(emu);
  849. pci_disable_device(pci);
  850. return -ENXIO;
  851. }
  852. if (is_audigy)
  853. emu->gpr_base = A_FXGPREGBASE;
  854. else
  855. emu->gpr_base = FXGPREGBASE;
  856. if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
  857. kfree(emu);
  858. pci_disable_device(pci);
  859. return err;
  860. }
  861. emu->port = pci_resource_start(pci, 0);
  862. if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) {
  863. snd_emu10k1_free(emu);
  864. return -EBUSY;
  865. }
  866. emu->irq = pci->irq;
  867. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  868. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  869. 32 * 1024, &emu->ptb_pages) < 0) {
  870. snd_emu10k1_free(emu);
  871. return -ENOMEM;
  872. }
  873. emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
  874. emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
  875. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  876. snd_emu10k1_free(emu);
  877. return -ENOMEM;
  878. }
  879. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  880. EMUPAGESIZE, &emu->silent_page) < 0) {
  881. snd_emu10k1_free(emu);
  882. return -ENOMEM;
  883. }
  884. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  885. if (emu->memhdr == NULL) {
  886. snd_emu10k1_free(emu);
  887. return -ENOMEM;
  888. }
  889. emu->memhdr->block_extra_size = sizeof(emu10k1_memblk_t) - sizeof(snd_util_memblk_t);
  890. pci_set_master(pci);
  891. emu->fx8010.fxbus_mask = 0x303f;
  892. if (extin_mask == 0)
  893. extin_mask = 0x3fcf;
  894. if (extout_mask == 0)
  895. extout_mask = 0x7fff;
  896. emu->fx8010.extin_mask = extin_mask;
  897. emu->fx8010.extout_mask = extout_mask;
  898. if (emu->card_capabilities->ecard) {
  899. if ((err = snd_emu10k1_ecard_init(emu)) < 0) {
  900. snd_emu10k1_free(emu);
  901. return err;
  902. }
  903. } else {
  904. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  905. does not support this, it shouldn't do any harm */
  906. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  907. }
  908. if ((err = snd_emu10k1_init(emu, enable_ir)) < 0) {
  909. snd_emu10k1_free(emu);
  910. return err;
  911. }
  912. if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0) {
  913. snd_emu10k1_free(emu);
  914. return err;
  915. }
  916. snd_emu10k1_proc_init(emu);
  917. snd_card_set_dev(card, &pci->dev);
  918. *remu = emu;
  919. return 0;
  920. }
  921. /* memory.c */
  922. EXPORT_SYMBOL(snd_emu10k1_synth_alloc);
  923. EXPORT_SYMBOL(snd_emu10k1_synth_free);
  924. EXPORT_SYMBOL(snd_emu10k1_synth_bzero);
  925. EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);
  926. EXPORT_SYMBOL(snd_emu10k1_memblk_map);
  927. /* voice.c */
  928. EXPORT_SYMBOL(snd_emu10k1_voice_alloc);
  929. EXPORT_SYMBOL(snd_emu10k1_voice_free);
  930. /* io.c */
  931. EXPORT_SYMBOL(snd_emu10k1_ptr_read);
  932. EXPORT_SYMBOL(snd_emu10k1_ptr_write);