emu10k1_main.c 43 KB

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