emu10k1_main.c 42 KB

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