emu10k1_main.c 41 KB

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