emu10k1_main.c 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089
  1. /*
  2. * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  3. * Creative Labs, Inc.
  4. * Routines for control of EMU10K1 chips
  5. *
  6. * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
  7. * Added support for Audigy 2 Value.
  8. * Added EMU 1010 support.
  9. * General bug fixes and enhancements.
  10. *
  11. *
  12. * BUGS:
  13. * --
  14. *
  15. * TODO:
  16. * --
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  31. *
  32. */
  33. #include <linux/sched.h>
  34. #include <linux/kthread.h>
  35. #include <linux/delay.h>
  36. #include <linux/init.h>
  37. #include <linux/interrupt.h>
  38. #include <linux/pci.h>
  39. #include <linux/slab.h>
  40. #include <linux/vmalloc.h>
  41. #include <linux/mutex.h>
  42. #include <sound/core.h>
  43. #include <sound/emu10k1.h>
  44. #include <linux/firmware.h>
  45. #include "p16v.h"
  46. #include "tina2.h"
  47. #include "p17v.h"
  48. #define HANA_FILENAME "emu/hana.fw"
  49. #define DOCK_FILENAME "emu/audio_dock.fw"
  50. #define EMU1010B_FILENAME "emu/emu1010b.fw"
  51. #define MICRO_DOCK_FILENAME "emu/micro_dock.fw"
  52. #define EMU0404_FILENAME "emu/emu0404.fw"
  53. #define EMU1010_NOTEBOOK_FILENAME "emu/emu1010_notebook.fw"
  54. MODULE_FIRMWARE(HANA_FILENAME);
  55. MODULE_FIRMWARE(DOCK_FILENAME);
  56. MODULE_FIRMWARE(EMU1010B_FILENAME);
  57. MODULE_FIRMWARE(MICRO_DOCK_FILENAME);
  58. MODULE_FIRMWARE(EMU0404_FILENAME);
  59. MODULE_FIRMWARE(EMU1010_NOTEBOOK_FILENAME);
  60. /*************************************************************************
  61. * EMU10K1 init / done
  62. *************************************************************************/
  63. void snd_emu10k1_voice_init(struct snd_emu10k1 *emu, int ch)
  64. {
  65. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  66. snd_emu10k1_ptr_write(emu, IP, ch, 0);
  67. snd_emu10k1_ptr_write(emu, VTFT, ch, 0xffff);
  68. snd_emu10k1_ptr_write(emu, CVCF, ch, 0xffff);
  69. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  70. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  71. snd_emu10k1_ptr_write(emu, CCR, ch, 0);
  72. snd_emu10k1_ptr_write(emu, PSST, ch, 0);
  73. snd_emu10k1_ptr_write(emu, DSL, ch, 0x10);
  74. snd_emu10k1_ptr_write(emu, CCCA, ch, 0);
  75. snd_emu10k1_ptr_write(emu, Z1, ch, 0);
  76. snd_emu10k1_ptr_write(emu, Z2, ch, 0);
  77. snd_emu10k1_ptr_write(emu, FXRT, ch, 0x32100000);
  78. snd_emu10k1_ptr_write(emu, ATKHLDM, ch, 0);
  79. snd_emu10k1_ptr_write(emu, DCYSUSM, ch, 0);
  80. snd_emu10k1_ptr_write(emu, IFATN, ch, 0xffff);
  81. snd_emu10k1_ptr_write(emu, PEFE, ch, 0);
  82. snd_emu10k1_ptr_write(emu, FMMOD, ch, 0);
  83. snd_emu10k1_ptr_write(emu, TREMFRQ, ch, 24); /* 1 Hz */
  84. snd_emu10k1_ptr_write(emu, FM2FRQ2, ch, 24); /* 1 Hz */
  85. snd_emu10k1_ptr_write(emu, TEMPENV, ch, 0);
  86. /*** these are last so OFF prevents writing ***/
  87. snd_emu10k1_ptr_write(emu, LFOVAL2, ch, 0);
  88. snd_emu10k1_ptr_write(emu, LFOVAL1, ch, 0);
  89. snd_emu10k1_ptr_write(emu, ATKHLDV, ch, 0);
  90. snd_emu10k1_ptr_write(emu, ENVVOL, ch, 0);
  91. snd_emu10k1_ptr_write(emu, ENVVAL, ch, 0);
  92. /* Audigy extra stuffs */
  93. if (emu->audigy) {
  94. snd_emu10k1_ptr_write(emu, 0x4c, ch, 0); /* ?? */
  95. snd_emu10k1_ptr_write(emu, 0x4d, ch, 0); /* ?? */
  96. snd_emu10k1_ptr_write(emu, 0x4e, ch, 0); /* ?? */
  97. snd_emu10k1_ptr_write(emu, 0x4f, ch, 0); /* ?? */
  98. snd_emu10k1_ptr_write(emu, A_FXRT1, ch, 0x03020100);
  99. snd_emu10k1_ptr_write(emu, A_FXRT2, ch, 0x3f3f3f3f);
  100. snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, ch, 0);
  101. }
  102. }
  103. static unsigned int spi_dac_init[] = {
  104. 0x00ff,
  105. 0x02ff,
  106. 0x0400,
  107. 0x0520,
  108. 0x0600,
  109. 0x08ff,
  110. 0x0aff,
  111. 0x0cff,
  112. 0x0eff,
  113. 0x10ff,
  114. 0x1200,
  115. 0x1400,
  116. 0x1480,
  117. 0x1800,
  118. 0x1aff,
  119. 0x1cff,
  120. 0x1e00,
  121. 0x0530,
  122. 0x0602,
  123. 0x0622,
  124. 0x1400,
  125. };
  126. static unsigned int i2c_adc_init[][2] = {
  127. { 0x17, 0x00 }, /* Reset */
  128. { 0x07, 0x00 }, /* Timeout */
  129. { 0x0b, 0x22 }, /* Interface control */
  130. { 0x0c, 0x22 }, /* Master mode control */
  131. { 0x0d, 0x08 }, /* Powerdown control */
  132. { 0x0e, 0xcf }, /* Attenuation Left 0x01 = -103dB, 0xff = 24dB */
  133. { 0x0f, 0xcf }, /* Attenuation Right 0.5dB steps */
  134. { 0x10, 0x7b }, /* ALC Control 1 */
  135. { 0x11, 0x00 }, /* ALC Control 2 */
  136. { 0x12, 0x32 }, /* ALC Control 3 */
  137. { 0x13, 0x00 }, /* Noise gate control */
  138. { 0x14, 0xa6 }, /* Limiter control */
  139. { 0x15, ADC_MUX_2 }, /* ADC Mixer control. Mic for A2ZS Notebook */
  140. };
  141. static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
  142. {
  143. unsigned int silent_page;
  144. int ch;
  145. u32 tmp;
  146. /* disable audio and lock cache */
  147. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK |
  148. HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
  149. /* reset recording buffers */
  150. snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
  151. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  152. snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
  153. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  154. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  155. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  156. /* disable channel interrupt */
  157. outl(0, emu->port + INTE);
  158. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  159. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  160. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  161. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  162. if (emu->audigy) {
  163. /* set SPDIF bypass mode */
  164. snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
  165. /* enable rear left + rear right AC97 slots */
  166. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
  167. AC97SLOT_REAR_LEFT);
  168. }
  169. /* init envelope engine */
  170. for (ch = 0; ch < NUM_G; ch++)
  171. snd_emu10k1_voice_init(emu, ch);
  172. snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
  173. snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
  174. snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
  175. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  176. /* Hacks for Alice3 to work independent of haP16V driver */
  177. /* Setup SRCMulti_I2S SamplingRate */
  178. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  179. tmp &= 0xfffff1ff;
  180. tmp |= (0x2<<9);
  181. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  182. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  183. snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
  184. /* Setup SRCMulti Input Audio Enable */
  185. /* Use 0xFFFFFFFF to enable P16V sounds. */
  186. snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
  187. /* Enabled Phased (8-channel) P16V playback */
  188. outl(0x0201, emu->port + HCFG2);
  189. /* Set playback routing. */
  190. snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
  191. }
  192. if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
  193. /* Hacks for Alice3 to work independent of haP16V driver */
  194. snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
  195. /* Setup SRCMulti_I2S SamplingRate */
  196. tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
  197. tmp &= 0xfffff1ff;
  198. tmp |= (0x2<<9);
  199. snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
  200. /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
  201. outl(0x600000, emu->port + 0x20);
  202. outl(0x14, emu->port + 0x24);
  203. /* Setup SRCMulti Input Audio Enable */
  204. outl(0x7b0000, emu->port + 0x20);
  205. outl(0xFF000000, emu->port + 0x24);
  206. /* Setup SPDIF Out Audio Enable */
  207. /* The Audigy 2 Value has a separate SPDIF out,
  208. * so no need for a mixer switch
  209. */
  210. outl(0x7a0000, emu->port + 0x20);
  211. outl(0xFF000000, emu->port + 0x24);
  212. tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
  213. outl(tmp, emu->port + A_IOCFG);
  214. }
  215. if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
  216. int size, n;
  217. size = ARRAY_SIZE(spi_dac_init);
  218. for (n = 0; n < size; n++)
  219. snd_emu10k1_spi_write(emu, spi_dac_init[n]);
  220. snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
  221. /* Enable GPIOs
  222. * GPIO0: Unknown
  223. * GPIO1: Speakers-enabled.
  224. * GPIO2: Unknown
  225. * GPIO3: Unknown
  226. * GPIO4: IEC958 Output on.
  227. * GPIO5: Unknown
  228. * GPIO6: Unknown
  229. * GPIO7: Unknown
  230. */
  231. outl(0x76, emu->port + A_IOCFG); /* Windows uses 0x3f76 */
  232. }
  233. if (emu->card_capabilities->i2c_adc) { /* Audigy 2 ZS Notebook with ADC Wolfson WM8775 */
  234. int size, n;
  235. snd_emu10k1_ptr20_write(emu, P17V_I2S_SRC_SEL, 0, 0x2020205f);
  236. tmp = inl(emu->port + A_IOCFG);
  237. outl(tmp | 0x4, emu->port + A_IOCFG); /* Set bit 2 for mic input */
  238. tmp = inl(emu->port + A_IOCFG);
  239. size = ARRAY_SIZE(i2c_adc_init);
  240. for (n = 0; n < size; n++)
  241. snd_emu10k1_i2c_write(emu, i2c_adc_init[n][0], i2c_adc_init[n][1]);
  242. for (n = 0; n < 4; n++) {
  243. emu->i2c_capture_volume[n][0] = 0xcf;
  244. emu->i2c_capture_volume[n][1] = 0xcf;
  245. }
  246. }
  247. snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
  248. snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
  249. snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
  250. silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
  251. for (ch = 0; ch < NUM_G; ch++) {
  252. snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
  253. snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
  254. }
  255. if (emu->card_capabilities->emu_model) {
  256. outl(HCFG_AUTOMUTE_ASYNC |
  257. HCFG_EMU32_SLAVE |
  258. HCFG_AUDIOENABLE, emu->port + HCFG);
  259. /*
  260. * Hokay, setup HCFG
  261. * Mute Disable Audio = 0
  262. * Lock Tank Memory = 1
  263. * Lock Sound Memory = 0
  264. * Auto Mute = 1
  265. */
  266. } else if (emu->audigy) {
  267. if (emu->revision == 4) /* audigy2 */
  268. outl(HCFG_AUDIOENABLE |
  269. HCFG_AC3ENABLE_CDSPDIF |
  270. HCFG_AC3ENABLE_GPSPDIF |
  271. HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  272. else
  273. outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  274. /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
  275. * e.g. card_capabilities->joystick */
  276. } else if (emu->model == 0x20 ||
  277. emu->model == 0xc400 ||
  278. (emu->model == 0x21 && emu->revision < 6))
  279. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
  280. else
  281. /* With on-chip joystick */
  282. outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
  283. if (enable_ir) { /* enable IR for SB Live */
  284. if (emu->card_capabilities->emu_model) {
  285. ; /* Disable all access to A_IOCFG for the emu1010 */
  286. } else if (emu->card_capabilities->i2c_adc) {
  287. ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
  288. } else if (emu->audigy) {
  289. unsigned int reg = inl(emu->port + A_IOCFG);
  290. outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
  291. udelay(500);
  292. outl(reg | A_IOCFG_GPOUT1 | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
  293. udelay(100);
  294. outl(reg, emu->port + A_IOCFG);
  295. } else {
  296. unsigned int reg = inl(emu->port + HCFG);
  297. outl(reg | HCFG_GPOUT2, emu->port + HCFG);
  298. udelay(500);
  299. outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
  300. udelay(100);
  301. outl(reg, emu->port + HCFG);
  302. }
  303. }
  304. if (emu->card_capabilities->emu_model) {
  305. ; /* Disable all access to A_IOCFG for the emu1010 */
  306. } else if (emu->card_capabilities->i2c_adc) {
  307. ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
  308. } else if (emu->audigy) { /* enable analog output */
  309. unsigned int reg = inl(emu->port + A_IOCFG);
  310. outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
  311. }
  312. return 0;
  313. }
  314. static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
  315. {
  316. /*
  317. * Enable the audio bit
  318. */
  319. outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
  320. /* Enable analog/digital outs on audigy */
  321. if (emu->card_capabilities->emu_model) {
  322. ; /* Disable all access to A_IOCFG for the emu1010 */
  323. } else if (emu->card_capabilities->i2c_adc) {
  324. ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
  325. } else if (emu->audigy) {
  326. outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
  327. if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
  328. /* Unmute Analog now. Set GPO6 to 1 for Apollo.
  329. * This has to be done after init ALice3 I2SOut beyond 48KHz.
  330. * So, sequence is important. */
  331. outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
  332. } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
  333. /* Unmute Analog now. */
  334. outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
  335. } else {
  336. /* Disable routing from AC97 line out to Front speakers */
  337. outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
  338. }
  339. }
  340. #if 0
  341. {
  342. unsigned int tmp;
  343. /* FIXME: the following routine disables LiveDrive-II !! */
  344. /* TOSLink detection */
  345. emu->tos_link = 0;
  346. tmp = inl(emu->port + HCFG);
  347. if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
  348. outl(tmp|0x800, emu->port + HCFG);
  349. udelay(50);
  350. if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
  351. emu->tos_link = 1;
  352. outl(tmp, emu->port + HCFG);
  353. }
  354. }
  355. }
  356. #endif
  357. snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
  358. }
  359. int snd_emu10k1_done(struct snd_emu10k1 *emu)
  360. {
  361. int ch;
  362. outl(0, emu->port + INTE);
  363. /*
  364. * Shutdown the chip
  365. */
  366. for (ch = 0; ch < NUM_G; ch++)
  367. snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
  368. for (ch = 0; ch < NUM_G; ch++) {
  369. snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
  370. snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
  371. snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
  372. snd_emu10k1_ptr_write(emu, CPF, ch, 0);
  373. }
  374. /* reset recording buffers */
  375. snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
  376. snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
  377. snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
  378. snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
  379. snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
  380. snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
  381. snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
  382. snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
  383. snd_emu10k1_ptr_write(emu, TCB, 0, 0);
  384. if (emu->audigy)
  385. snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
  386. else
  387. snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
  388. /* disable channel interrupt */
  389. snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
  390. snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
  391. snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
  392. snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
  393. /* disable audio and lock cache */
  394. outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
  395. snd_emu10k1_ptr_write(emu, PTB, 0, 0);
  396. return 0;
  397. }
  398. /*************************************************************************
  399. * ECARD functional implementation
  400. *************************************************************************/
  401. /* In A1 Silicon, these bits are in the HC register */
  402. #define HOOKN_BIT (1L << 12)
  403. #define HANDN_BIT (1L << 11)
  404. #define PULSEN_BIT (1L << 10)
  405. #define EC_GDI1 (1 << 13)
  406. #define EC_GDI0 (1 << 14)
  407. #define EC_NUM_CONTROL_BITS 20
  408. #define EC_AC3_DATA_SELN 0x0001L
  409. #define EC_EE_DATA_SEL 0x0002L
  410. #define EC_EE_CNTRL_SELN 0x0004L
  411. #define EC_EECLK 0x0008L
  412. #define EC_EECS 0x0010L
  413. #define EC_EESDO 0x0020L
  414. #define EC_TRIM_CSN 0x0040L
  415. #define EC_TRIM_SCLK 0x0080L
  416. #define EC_TRIM_SDATA 0x0100L
  417. #define EC_TRIM_MUTEN 0x0200L
  418. #define EC_ADCCAL 0x0400L
  419. #define EC_ADCRSTN 0x0800L
  420. #define EC_DACCAL 0x1000L
  421. #define EC_DACMUTEN 0x2000L
  422. #define EC_LEDN 0x4000L
  423. #define EC_SPDIF0_SEL_SHIFT 15
  424. #define EC_SPDIF1_SEL_SHIFT 17
  425. #define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
  426. #define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
  427. #define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
  428. #define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
  429. #define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
  430. * be incremented any time the EEPROM's
  431. * format is changed. */
  432. #define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
  433. /* Addresses for special values stored in to EEPROM */
  434. #define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
  435. #define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
  436. #define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
  437. #define EC_LAST_PROMFILE_ADDR 0x2f
  438. #define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
  439. * can be up to 30 characters in length
  440. * and is stored as a NULL-terminated
  441. * ASCII string. Any unused bytes must be
  442. * filled with zeros */
  443. #define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
  444. /* Most of this stuff is pretty self-evident. According to the hardware
  445. * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
  446. * offset problem. Weird.
  447. */
  448. #define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
  449. EC_TRIM_CSN)
  450. #define EC_DEFAULT_ADC_GAIN 0xC4C4
  451. #define EC_DEFAULT_SPDIF0_SEL 0x0
  452. #define EC_DEFAULT_SPDIF1_SEL 0x4
  453. /**************************************************************************
  454. * @func Clock bits into the Ecard's control latch. The Ecard uses a
  455. * control latch will is loaded bit-serially by toggling the Modem control
  456. * lines from function 2 on the E8010. This function hides these details
  457. * and presents the illusion that we are actually writing to a distinct
  458. * register.
  459. */
  460. static void snd_emu10k1_ecard_write(struct snd_emu10k1 *emu, unsigned int value)
  461. {
  462. unsigned short count;
  463. unsigned int data;
  464. unsigned long hc_port;
  465. unsigned int hc_value;
  466. hc_port = emu->port + HCFG;
  467. hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
  468. outl(hc_value, hc_port);
  469. for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
  470. /* Set up the value */
  471. data = ((value & 0x1) ? PULSEN_BIT : 0);
  472. value >>= 1;
  473. outl(hc_value | data, hc_port);
  474. /* Clock the shift register */
  475. outl(hc_value | data | HANDN_BIT, hc_port);
  476. outl(hc_value | data, hc_port);
  477. }
  478. /* Latch the bits */
  479. outl(hc_value | HOOKN_BIT, hc_port);
  480. outl(hc_value, hc_port);
  481. }
  482. /**************************************************************************
  483. * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
  484. * trim value consists of a 16bit value which is composed of two
  485. * 8 bit gain/trim values, one for the left channel and one for the
  486. * right channel. The following table maps from the Gain/Attenuation
  487. * value in decibels into the corresponding bit pattern for a single
  488. * channel.
  489. */
  490. static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 *emu,
  491. unsigned short gain)
  492. {
  493. unsigned int bit;
  494. /* Enable writing to the TRIM registers */
  495. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  496. /* Do it again to insure that we meet hold time requirements */
  497. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
  498. for (bit = (1 << 15); bit; bit >>= 1) {
  499. unsigned int value;
  500. value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
  501. if (gain & bit)
  502. value |= EC_TRIM_SDATA;
  503. /* Clock the bit */
  504. snd_emu10k1_ecard_write(emu, value);
  505. snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
  506. snd_emu10k1_ecard_write(emu, value);
  507. }
  508. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  509. }
  510. static int snd_emu10k1_ecard_init(struct snd_emu10k1 *emu)
  511. {
  512. unsigned int hc_value;
  513. /* Set up the initial settings */
  514. emu->ecard_ctrl = EC_RAW_RUN_MODE |
  515. EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
  516. EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
  517. /* Step 0: Set the codec type in the hardware control register
  518. * and enable audio output */
  519. hc_value = inl(emu->port + HCFG);
  520. outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
  521. inl(emu->port + HCFG);
  522. /* Step 1: Turn off the led and deassert TRIM_CS */
  523. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  524. /* Step 2: Calibrate the ADC and DAC */
  525. snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
  526. /* Step 3: Wait for awhile; XXX We can't get away with this
  527. * under a real operating system; we'll need to block and wait that
  528. * way. */
  529. snd_emu10k1_wait(emu, 48000);
  530. /* Step 4: Switch off the DAC and ADC calibration. Note
  531. * That ADC_CAL is actually an inverted signal, so we assert
  532. * it here to stop calibration. */
  533. snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
  534. /* Step 4: Switch into run mode */
  535. snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
  536. /* Step 5: Set the analog input gain */
  537. snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
  538. return 0;
  539. }
  540. static int snd_emu10k1_cardbus_init(struct snd_emu10k1 *emu)
  541. {
  542. unsigned long special_port;
  543. unsigned int value;
  544. /* Special initialisation routine
  545. * before the rest of the IO-Ports become active.
  546. */
  547. special_port = emu->port + 0x38;
  548. value = inl(special_port);
  549. outl(0x00d00000, special_port);
  550. value = inl(special_port);
  551. outl(0x00d00001, special_port);
  552. value = inl(special_port);
  553. outl(0x00d0005f, special_port);
  554. value = inl(special_port);
  555. outl(0x00d0007f, special_port);
  556. value = inl(special_port);
  557. outl(0x0090007f, special_port);
  558. value = inl(special_port);
  559. snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
  560. /* Delay to give time for ADC chip to switch on. It needs 113ms */
  561. msleep(200);
  562. return 0;
  563. }
  564. static int snd_emu1010_load_firmware(struct snd_emu10k1 *emu, const char *filename)
  565. {
  566. int err;
  567. int n, i;
  568. int reg;
  569. int value;
  570. unsigned int write_post;
  571. unsigned long flags;
  572. const struct firmware *fw_entry;
  573. err = request_firmware(&fw_entry, filename, &emu->pci->dev);
  574. if (err != 0) {
  575. snd_printk(KERN_ERR "firmware: %s not found. Err = %d\n", filename, err);
  576. return err;
  577. }
  578. snd_printk(KERN_INFO "firmware size = 0x%zx\n", fw_entry->size);
  579. /* The FPGA is a Xilinx Spartan IIE XC2S50E */
  580. /* GPIO7 -> FPGA PGMN
  581. * GPIO6 -> FPGA CCLK
  582. * GPIO5 -> FPGA DIN
  583. * FPGA CONFIG OFF -> FPGA PGMN
  584. */
  585. spin_lock_irqsave(&emu->emu_lock, flags);
  586. outl(0x00, emu->port + A_IOCFG); /* Set PGMN low for 1uS. */
  587. write_post = inl(emu->port + A_IOCFG);
  588. udelay(100);
  589. outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */
  590. write_post = inl(emu->port + A_IOCFG);
  591. udelay(100); /* Allow FPGA memory to clean */
  592. for (n = 0; n < fw_entry->size; n++) {
  593. value = fw_entry->data[n];
  594. for (i = 0; i < 8; i++) {
  595. reg = 0x80;
  596. if (value & 0x1)
  597. reg = reg | 0x20;
  598. value = value >> 1;
  599. outl(reg, emu->port + A_IOCFG);
  600. write_post = inl(emu->port + A_IOCFG);
  601. outl(reg | 0x40, emu->port + A_IOCFG);
  602. write_post = inl(emu->port + A_IOCFG);
  603. }
  604. }
  605. /* After programming, set GPIO bit 4 high again. */
  606. outl(0x10, emu->port + A_IOCFG);
  607. write_post = inl(emu->port + A_IOCFG);
  608. spin_unlock_irqrestore(&emu->emu_lock, flags);
  609. release_firmware(fw_entry);
  610. return 0;
  611. }
  612. static int emu1010_firmware_thread(void *data)
  613. {
  614. struct snd_emu10k1 *emu = data;
  615. u32 tmp, tmp2, reg;
  616. int err;
  617. for (;;) {
  618. /* Delay to allow Audio Dock to settle */
  619. msleep_interruptible(1000);
  620. if (kthread_should_stop())
  621. break;
  622. snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp); /* IRQ Status */
  623. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg); /* OPTIONS: Which cards are attached to the EMU */
  624. if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
  625. /* Audio Dock attached */
  626. /* Return to Audio Dock programming mode */
  627. snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
  628. snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK);
  629. if (emu->card_capabilities->emu_model ==
  630. EMU_MODEL_EMU1010) {
  631. err = snd_emu1010_load_firmware(emu, DOCK_FILENAME);
  632. if (err != 0)
  633. continue;
  634. } else if (emu->card_capabilities->emu_model ==
  635. EMU_MODEL_EMU1010B) {
  636. err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
  637. if (err != 0)
  638. continue;
  639. } else if (emu->card_capabilities->emu_model ==
  640. EMU_MODEL_EMU1616) {
  641. err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME);
  642. if (err != 0)
  643. continue;
  644. }
  645. snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0);
  646. snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg);
  647. snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS = 0x%x\n", reg);
  648. /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
  649. snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
  650. snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID = 0x%x\n", reg);
  651. if ((reg & 0x1f) != 0x15) {
  652. /* FPGA failed to be programmed */
  653. snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg = 0x%x\n", reg);
  654. continue;
  655. }
  656. snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
  657. snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp);
  658. snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2);
  659. snd_printk(KERN_INFO "Audio Dock ver: %u.%u\n",
  660. tmp, tmp2);
  661. /* Sync clocking between 1010 and Dock */
  662. /* Allow DLL to settle */
  663. msleep(10);
  664. /* Unmute all. Default is muted after a firmware load */
  665. snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
  666. }
  667. }
  668. snd_printk(KERN_INFO "emu1010: firmware thread stopping\n");
  669. return 0;
  670. }
  671. /*
  672. * EMU-1010 - details found out from this driver, official MS Win drivers,
  673. * testing the card:
  674. *
  675. * Audigy2 (aka Alice2):
  676. * ---------------------
  677. * * communication over PCI
  678. * * conversion of 32-bit data coming over EMU32 links from HANA FPGA
  679. * to 2 x 16-bit, using internal DSP instructions
  680. * * slave mode, clock supplied by HANA
  681. * * linked to HANA using:
  682. * 32 x 32-bit serial EMU32 output channels
  683. * 16 x EMU32 input channels
  684. * (?) x I2S I/O channels (?)
  685. *
  686. * FPGA (aka HANA):
  687. * ---------------
  688. * * provides all (?) physical inputs and outputs of the card
  689. * (ADC, DAC, SPDIF I/O, ADAT I/O, etc.)
  690. * * provides clock signal for the card and Alice2
  691. * * two crystals - for 44.1kHz and 48kHz multiples
  692. * * provides internal routing of signal sources to signal destinations
  693. * * inputs/outputs to Alice2 - see above
  694. *
  695. * Current status of the driver:
  696. * ----------------------------
  697. * * only 44.1/48kHz supported (the MS Win driver supports up to 192 kHz)
  698. * * PCM device nb. 2:
  699. * 16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops
  700. * 16 x 32-bit capture - snd_emu10k1_capture_efx_ops
  701. */
  702. static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
  703. {
  704. unsigned int i;
  705. u32 tmp, tmp2, reg;
  706. int err;
  707. const char *filename = NULL;
  708. snd_printk(KERN_INFO "emu1010: Special config.\n");
  709. /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
  710. * Lock Sound Memory Cache, Lock Tank Memory Cache,
  711. * Mute all codecs.
  712. */
  713. outl(0x0005a00c, emu->port + HCFG);
  714. /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
  715. * Lock Tank Memory Cache,
  716. * Mute all codecs.
  717. */
  718. outl(0x0005a004, emu->port + HCFG);
  719. /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
  720. * Mute all codecs.
  721. */
  722. outl(0x0005a000, emu->port + HCFG);
  723. /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
  724. * Mute all codecs.
  725. */
  726. outl(0x0005a000, emu->port + HCFG);
  727. /* Disable 48Volt power to Audio Dock */
  728. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
  729. /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
  730. snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
  731. snd_printdd("reg1 = 0x%x\n", reg);
  732. if ((reg & 0x3f) == 0x15) {
  733. /* FPGA netlist already present so clear it */
  734. /* Return to programming mode */
  735. snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02);
  736. }
  737. snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
  738. snd_printdd("reg2 = 0x%x\n", reg);
  739. if ((reg & 0x3f) == 0x15) {
  740. /* FPGA failed to return to programming mode */
  741. snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n");
  742. return -ENODEV;
  743. }
  744. snd_printk(KERN_INFO "emu1010: EMU_HANA_ID = 0x%x\n", reg);
  745. switch (emu->card_capabilities->emu_model) {
  746. case EMU_MODEL_EMU1010:
  747. filename = HANA_FILENAME;
  748. break;
  749. case EMU_MODEL_EMU1010B:
  750. filename = EMU1010B_FILENAME;
  751. break;
  752. case EMU_MODEL_EMU1616:
  753. filename = EMU1010_NOTEBOOK_FILENAME;
  754. break;
  755. case EMU_MODEL_EMU0404:
  756. filename = EMU0404_FILENAME;
  757. break;
  758. default:
  759. filename = NULL;
  760. return -ENODEV;
  761. break;
  762. }
  763. snd_printk(KERN_INFO "emu1010: filename %s testing\n", filename);
  764. err = snd_emu1010_load_firmware(emu, filename);
  765. if (err != 0) {
  766. snd_printk(
  767. KERN_INFO "emu1010: Loading Firmware file %s failed\n",
  768. filename);
  769. return err;
  770. }
  771. /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
  772. snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg);
  773. if ((reg & 0x3f) != 0x15) {
  774. /* FPGA failed to be programmed */
  775. snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg = 0x%x\n", reg);
  776. return -ENODEV;
  777. }
  778. snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
  779. snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp);
  780. snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2);
  781. snd_printk(KERN_INFO "emu1010: Hana version: %u.%u\n", tmp, tmp2);
  782. /* Enable 48Volt power to Audio Dock */
  783. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON);
  784. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
  785. snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
  786. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
  787. snd_printk(KERN_INFO "emu1010: Card options = 0x%x\n", reg);
  788. snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp);
  789. /* Optical -> ADAT I/O */
  790. /* 0 : SPDIF
  791. * 1 : ADAT
  792. */
  793. emu->emu1010.optical_in = 1; /* IN_ADAT */
  794. emu->emu1010.optical_out = 1; /* IN_ADAT */
  795. tmp = 0;
  796. tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
  797. (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
  798. snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp);
  799. snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp);
  800. /* Set no attenuation on Audio Dock pads. */
  801. snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00);
  802. emu->emu1010.adc_pads = 0x00;
  803. snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp);
  804. /* Unmute Audio dock DACs, Headphone source DAC-4. */
  805. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30);
  806. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);
  807. snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp);
  808. /* DAC PADs. */
  809. snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f);
  810. emu->emu1010.dac_pads = 0x0f;
  811. snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp);
  812. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30);
  813. snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp);
  814. /* SPDIF Format. Set Consumer mode, 24bit, copy enable */
  815. snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10);
  816. /* MIDI routing */
  817. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19);
  818. /* Unknown. */
  819. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c);
  820. /* IRQ Enable: All on */
  821. /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); */
  822. /* IRQ Enable: All off */
  823. snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00);
  824. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg);
  825. snd_printk(KERN_INFO "emu1010: Card options3 = 0x%x\n", reg);
  826. /* Default WCLK set to 48kHz. */
  827. snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00);
  828. /* Word Clock source, Internal 48kHz x1 */
  829. snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K);
  830. /* snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X); */
  831. /* Audio Dock LEDs. */
  832. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);
  833. #if 0
  834. /* For 96kHz */
  835. snd_emu1010_fpga_link_dst_src_write(emu,
  836. EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
  837. snd_emu1010_fpga_link_dst_src_write(emu,
  838. EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
  839. snd_emu1010_fpga_link_dst_src_write(emu,
  840. EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT2);
  841. snd_emu1010_fpga_link_dst_src_write(emu,
  842. EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT2);
  843. #endif
  844. #if 0
  845. /* For 192kHz */
  846. snd_emu1010_fpga_link_dst_src_write(emu,
  847. EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
  848. snd_emu1010_fpga_link_dst_src_write(emu,
  849. EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
  850. snd_emu1010_fpga_link_dst_src_write(emu,
  851. EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
  852. snd_emu1010_fpga_link_dst_src_write(emu,
  853. EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_RIGHT2);
  854. snd_emu1010_fpga_link_dst_src_write(emu,
  855. EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT3);
  856. snd_emu1010_fpga_link_dst_src_write(emu,
  857. EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT3);
  858. snd_emu1010_fpga_link_dst_src_write(emu,
  859. EMU_DST_ALICE2_EMU32_6, EMU_SRC_HAMOA_ADC_LEFT4);
  860. snd_emu1010_fpga_link_dst_src_write(emu,
  861. EMU_DST_ALICE2_EMU32_7, EMU_SRC_HAMOA_ADC_RIGHT4);
  862. #endif
  863. #if 1
  864. /* For 48kHz */
  865. snd_emu1010_fpga_link_dst_src_write(emu,
  866. EMU_DST_ALICE2_EMU32_0, EMU_SRC_DOCK_MIC_A1);
  867. snd_emu1010_fpga_link_dst_src_write(emu,
  868. EMU_DST_ALICE2_EMU32_1, EMU_SRC_DOCK_MIC_B1);
  869. snd_emu1010_fpga_link_dst_src_write(emu,
  870. EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
  871. snd_emu1010_fpga_link_dst_src_write(emu,
  872. EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_LEFT2);
  873. snd_emu1010_fpga_link_dst_src_write(emu,
  874. EMU_DST_ALICE2_EMU32_4, EMU_SRC_DOCK_ADC1_LEFT1);
  875. snd_emu1010_fpga_link_dst_src_write(emu,
  876. EMU_DST_ALICE2_EMU32_5, EMU_SRC_DOCK_ADC1_RIGHT1);
  877. snd_emu1010_fpga_link_dst_src_write(emu,
  878. EMU_DST_ALICE2_EMU32_6, EMU_SRC_DOCK_ADC2_LEFT1);
  879. snd_emu1010_fpga_link_dst_src_write(emu,
  880. EMU_DST_ALICE2_EMU32_7, EMU_SRC_DOCK_ADC2_RIGHT1);
  881. /* Pavel Hofman - setting defaults for 8 more capture channels
  882. * Defaults only, users will set their own values anyways, let's
  883. * just copy/paste.
  884. */
  885. snd_emu1010_fpga_link_dst_src_write(emu,
  886. EMU_DST_ALICE2_EMU32_8, EMU_SRC_DOCK_MIC_A1);
  887. snd_emu1010_fpga_link_dst_src_write(emu,
  888. EMU_DST_ALICE2_EMU32_9, EMU_SRC_DOCK_MIC_B1);
  889. snd_emu1010_fpga_link_dst_src_write(emu,
  890. EMU_DST_ALICE2_EMU32_A, EMU_SRC_HAMOA_ADC_LEFT2);
  891. snd_emu1010_fpga_link_dst_src_write(emu,
  892. EMU_DST_ALICE2_EMU32_B, EMU_SRC_HAMOA_ADC_LEFT2);
  893. snd_emu1010_fpga_link_dst_src_write(emu,
  894. EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_ADC1_LEFT1);
  895. snd_emu1010_fpga_link_dst_src_write(emu,
  896. EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_ADC1_RIGHT1);
  897. snd_emu1010_fpga_link_dst_src_write(emu,
  898. EMU_DST_ALICE2_EMU32_E, EMU_SRC_DOCK_ADC2_LEFT1);
  899. snd_emu1010_fpga_link_dst_src_write(emu,
  900. EMU_DST_ALICE2_EMU32_F, EMU_SRC_DOCK_ADC2_RIGHT1);
  901. #endif
  902. #if 0
  903. /* Original */
  904. snd_emu1010_fpga_link_dst_src_write(emu,
  905. EMU_DST_ALICE2_EMU32_4, EMU_SRC_HANA_ADAT);
  906. snd_emu1010_fpga_link_dst_src_write(emu,
  907. EMU_DST_ALICE2_EMU32_5, EMU_SRC_HANA_ADAT + 1);
  908. snd_emu1010_fpga_link_dst_src_write(emu,
  909. EMU_DST_ALICE2_EMU32_6, EMU_SRC_HANA_ADAT + 2);
  910. snd_emu1010_fpga_link_dst_src_write(emu,
  911. EMU_DST_ALICE2_EMU32_7, EMU_SRC_HANA_ADAT + 3);
  912. snd_emu1010_fpga_link_dst_src_write(emu,
  913. EMU_DST_ALICE2_EMU32_8, EMU_SRC_HANA_ADAT + 4);
  914. snd_emu1010_fpga_link_dst_src_write(emu,
  915. EMU_DST_ALICE2_EMU32_9, EMU_SRC_HANA_ADAT + 5);
  916. snd_emu1010_fpga_link_dst_src_write(emu,
  917. EMU_DST_ALICE2_EMU32_A, EMU_SRC_HANA_ADAT + 6);
  918. snd_emu1010_fpga_link_dst_src_write(emu,
  919. EMU_DST_ALICE2_EMU32_B, EMU_SRC_HANA_ADAT + 7);
  920. snd_emu1010_fpga_link_dst_src_write(emu,
  921. EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_MIC_A1);
  922. snd_emu1010_fpga_link_dst_src_write(emu,
  923. EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_MIC_B1);
  924. snd_emu1010_fpga_link_dst_src_write(emu,
  925. EMU_DST_ALICE2_EMU32_E, EMU_SRC_HAMOA_ADC_LEFT2);
  926. snd_emu1010_fpga_link_dst_src_write(emu,
  927. EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2);
  928. #endif
  929. for (i = 0; i < 0x20; i++) {
  930. /* AudioDock Elink <- Silence */
  931. snd_emu1010_fpga_link_dst_src_write(emu, 0x0100 + i, EMU_SRC_SILENCE);
  932. }
  933. for (i = 0; i < 4; i++) {
  934. /* Hana SPDIF Out <- Silence */
  935. snd_emu1010_fpga_link_dst_src_write(emu, 0x0200 + i, EMU_SRC_SILENCE);
  936. }
  937. for (i = 0; i < 7; i++) {
  938. /* Hamoa DAC <- Silence */
  939. snd_emu1010_fpga_link_dst_src_write(emu, 0x0300 + i, EMU_SRC_SILENCE);
  940. }
  941. for (i = 0; i < 7; i++) {
  942. /* Hana ADAT Out <- Silence */
  943. snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE);
  944. }
  945. snd_emu1010_fpga_link_dst_src_write(emu,
  946. EMU_DST_ALICE_I2S0_LEFT, EMU_SRC_DOCK_ADC1_LEFT1);
  947. snd_emu1010_fpga_link_dst_src_write(emu,
  948. EMU_DST_ALICE_I2S0_RIGHT, EMU_SRC_DOCK_ADC1_RIGHT1);
  949. snd_emu1010_fpga_link_dst_src_write(emu,
  950. EMU_DST_ALICE_I2S1_LEFT, EMU_SRC_DOCK_ADC2_LEFT1);
  951. snd_emu1010_fpga_link_dst_src_write(emu,
  952. EMU_DST_ALICE_I2S1_RIGHT, EMU_SRC_DOCK_ADC2_RIGHT1);
  953. snd_emu1010_fpga_link_dst_src_write(emu,
  954. EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1);
  955. snd_emu1010_fpga_link_dst_src_write(emu,
  956. EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1);
  957. snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01); /* Unmute all */
  958. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp);
  959. /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
  960. * Lock Sound Memory Cache, Lock Tank Memory Cache,
  961. * Mute all codecs.
  962. */
  963. outl(0x0000a000, emu->port + HCFG);
  964. /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
  965. * Lock Sound Memory Cache, Lock Tank Memory Cache,
  966. * Un-Mute all codecs.
  967. */
  968. outl(0x0000a001, emu->port + HCFG);
  969. /* Initial boot complete. Now patches */
  970. snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp);
  971. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19); /* MIDI Route */
  972. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c); /* Unknown */
  973. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19); /* MIDI Route */
  974. snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c); /* Unknown */
  975. snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp);
  976. snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10); /* SPDIF Format spdif (or 0x11 for aes/ebu) */
  977. /* Start Micro/Audio Dock firmware loader thread */
  978. if (!emu->emu1010.firmware_thread) {
  979. emu->emu1010.firmware_thread =
  980. kthread_create(emu1010_firmware_thread, emu,
  981. "emu1010_firmware");
  982. wake_up_process(emu->emu1010.firmware_thread);
  983. }
  984. #if 0
  985. snd_emu1010_fpga_link_dst_src_write(emu,
  986. EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32B + 2); /* ALICE2 bus 0xa2 */
  987. snd_emu1010_fpga_link_dst_src_write(emu,
  988. EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32B + 3); /* ALICE2 bus 0xa3 */
  989. snd_emu1010_fpga_link_dst_src_write(emu,
  990. EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 2); /* ALICE2 bus 0xb2 */
  991. snd_emu1010_fpga_link_dst_src_write(emu,
  992. EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 3); /* ALICE2 bus 0xb3 */
  993. #endif
  994. /* Default outputs */
  995. if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1616) {
  996. /* 1616(M) cardbus default outputs */
  997. /* ALICE2 bus 0xa0 */
  998. snd_emu1010_fpga_link_dst_src_write(emu,
  999. EMU_DST_DOCK_DAC1_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1000. emu->emu1010.output_source[0] = 17;
  1001. snd_emu1010_fpga_link_dst_src_write(emu,
  1002. EMU_DST_DOCK_DAC1_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1003. emu->emu1010.output_source[1] = 18;
  1004. snd_emu1010_fpga_link_dst_src_write(emu,
  1005. EMU_DST_DOCK_DAC2_LEFT1, EMU_SRC_ALICE_EMU32A + 2);
  1006. emu->emu1010.output_source[2] = 19;
  1007. snd_emu1010_fpga_link_dst_src_write(emu,
  1008. EMU_DST_DOCK_DAC2_RIGHT1, EMU_SRC_ALICE_EMU32A + 3);
  1009. emu->emu1010.output_source[3] = 20;
  1010. snd_emu1010_fpga_link_dst_src_write(emu,
  1011. EMU_DST_DOCK_DAC3_LEFT1, EMU_SRC_ALICE_EMU32A + 4);
  1012. emu->emu1010.output_source[4] = 21;
  1013. snd_emu1010_fpga_link_dst_src_write(emu,
  1014. EMU_DST_DOCK_DAC3_RIGHT1, EMU_SRC_ALICE_EMU32A + 5);
  1015. emu->emu1010.output_source[5] = 22;
  1016. /* ALICE2 bus 0xa0 */
  1017. snd_emu1010_fpga_link_dst_src_write(emu,
  1018. EMU_DST_MANA_DAC_LEFT, EMU_SRC_ALICE_EMU32A + 0);
  1019. emu->emu1010.output_source[16] = 17;
  1020. snd_emu1010_fpga_link_dst_src_write(emu,
  1021. EMU_DST_MANA_DAC_RIGHT, EMU_SRC_ALICE_EMU32A + 1);
  1022. emu->emu1010.output_source[17] = 18;
  1023. } else {
  1024. /* ALICE2 bus 0xa0 */
  1025. snd_emu1010_fpga_link_dst_src_write(emu,
  1026. EMU_DST_DOCK_DAC1_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1027. emu->emu1010.output_source[0] = 21;
  1028. snd_emu1010_fpga_link_dst_src_write(emu,
  1029. EMU_DST_DOCK_DAC1_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1030. emu->emu1010.output_source[1] = 22;
  1031. snd_emu1010_fpga_link_dst_src_write(emu,
  1032. EMU_DST_DOCK_DAC2_LEFT1, EMU_SRC_ALICE_EMU32A + 2);
  1033. emu->emu1010.output_source[2] = 23;
  1034. snd_emu1010_fpga_link_dst_src_write(emu,
  1035. EMU_DST_DOCK_DAC2_RIGHT1, EMU_SRC_ALICE_EMU32A + 3);
  1036. emu->emu1010.output_source[3] = 24;
  1037. snd_emu1010_fpga_link_dst_src_write(emu,
  1038. EMU_DST_DOCK_DAC3_LEFT1, EMU_SRC_ALICE_EMU32A + 4);
  1039. emu->emu1010.output_source[4] = 25;
  1040. snd_emu1010_fpga_link_dst_src_write(emu,
  1041. EMU_DST_DOCK_DAC3_RIGHT1, EMU_SRC_ALICE_EMU32A + 5);
  1042. emu->emu1010.output_source[5] = 26;
  1043. snd_emu1010_fpga_link_dst_src_write(emu,
  1044. EMU_DST_DOCK_DAC4_LEFT1, EMU_SRC_ALICE_EMU32A + 6);
  1045. emu->emu1010.output_source[6] = 27;
  1046. snd_emu1010_fpga_link_dst_src_write(emu,
  1047. EMU_DST_DOCK_DAC4_RIGHT1, EMU_SRC_ALICE_EMU32A + 7);
  1048. emu->emu1010.output_source[7] = 28;
  1049. /* ALICE2 bus 0xa0 */
  1050. snd_emu1010_fpga_link_dst_src_write(emu,
  1051. EMU_DST_DOCK_PHONES_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1052. emu->emu1010.output_source[8] = 21;
  1053. snd_emu1010_fpga_link_dst_src_write(emu,
  1054. EMU_DST_DOCK_PHONES_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1055. emu->emu1010.output_source[9] = 22;
  1056. /* ALICE2 bus 0xa0 */
  1057. snd_emu1010_fpga_link_dst_src_write(emu,
  1058. EMU_DST_DOCK_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1059. emu->emu1010.output_source[10] = 21;
  1060. snd_emu1010_fpga_link_dst_src_write(emu,
  1061. EMU_DST_DOCK_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1062. emu->emu1010.output_source[11] = 22;
  1063. /* ALICE2 bus 0xa0 */
  1064. snd_emu1010_fpga_link_dst_src_write(emu,
  1065. EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1066. emu->emu1010.output_source[12] = 21;
  1067. snd_emu1010_fpga_link_dst_src_write(emu,
  1068. EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1069. emu->emu1010.output_source[13] = 22;
  1070. /* ALICE2 bus 0xa0 */
  1071. snd_emu1010_fpga_link_dst_src_write(emu,
  1072. EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32A + 0);
  1073. emu->emu1010.output_source[14] = 21;
  1074. snd_emu1010_fpga_link_dst_src_write(emu,
  1075. EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
  1076. emu->emu1010.output_source[15] = 22;
  1077. /* ALICE2 bus 0xa0 */
  1078. snd_emu1010_fpga_link_dst_src_write(emu,
  1079. EMU_DST_HANA_ADAT, EMU_SRC_ALICE_EMU32A + 0);
  1080. emu->emu1010.output_source[16] = 21;
  1081. snd_emu1010_fpga_link_dst_src_write(emu,
  1082. EMU_DST_HANA_ADAT + 1, EMU_SRC_ALICE_EMU32A + 1);
  1083. emu->emu1010.output_source[17] = 22;
  1084. snd_emu1010_fpga_link_dst_src_write(emu,
  1085. EMU_DST_HANA_ADAT + 2, EMU_SRC_ALICE_EMU32A + 2);
  1086. emu->emu1010.output_source[18] = 23;
  1087. snd_emu1010_fpga_link_dst_src_write(emu,
  1088. EMU_DST_HANA_ADAT + 3, EMU_SRC_ALICE_EMU32A + 3);
  1089. emu->emu1010.output_source[19] = 24;
  1090. snd_emu1010_fpga_link_dst_src_write(emu,
  1091. EMU_DST_HANA_ADAT + 4, EMU_SRC_ALICE_EMU32A + 4);
  1092. emu->emu1010.output_source[20] = 25;
  1093. snd_emu1010_fpga_link_dst_src_write(emu,
  1094. EMU_DST_HANA_ADAT + 5, EMU_SRC_ALICE_EMU32A + 5);
  1095. emu->emu1010.output_source[21] = 26;
  1096. snd_emu1010_fpga_link_dst_src_write(emu,
  1097. EMU_DST_HANA_ADAT + 6, EMU_SRC_ALICE_EMU32A + 6);
  1098. emu->emu1010.output_source[22] = 27;
  1099. snd_emu1010_fpga_link_dst_src_write(emu,
  1100. EMU_DST_HANA_ADAT + 7, EMU_SRC_ALICE_EMU32A + 7);
  1101. emu->emu1010.output_source[23] = 28;
  1102. }
  1103. /* TEMP: Select SPDIF in/out */
  1104. /* snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); */ /* Output spdif */
  1105. /* TEMP: Select 48kHz SPDIF out */
  1106. snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */
  1107. snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */
  1108. /* Word Clock source, Internal 48kHz x1 */
  1109. snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K);
  1110. /* snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X); */
  1111. emu->emu1010.internal_clock = 1; /* 48000 */
  1112. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12); /* Set LEDs on Audio Dock */
  1113. snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */
  1114. /* snd_emu1010_fpga_write(emu, 0x7, 0x0); */ /* Mute all */
  1115. /* snd_emu1010_fpga_write(emu, 0x7, 0x1); */ /* Unmute all */
  1116. /* snd_emu1010_fpga_write(emu, 0xe, 0x12); */ /* Set LEDs on Audio Dock */
  1117. return 0;
  1118. }
  1119. /*
  1120. * Create the EMU10K1 instance
  1121. */
  1122. #ifdef CONFIG_PM
  1123. static int alloc_pm_buffer(struct snd_emu10k1 *emu);
  1124. static void free_pm_buffer(struct snd_emu10k1 *emu);
  1125. #endif
  1126. static int snd_emu10k1_free(struct snd_emu10k1 *emu)
  1127. {
  1128. if (emu->port) { /* avoid access to already used hardware */
  1129. snd_emu10k1_fx8010_tram_setup(emu, 0);
  1130. snd_emu10k1_done(emu);
  1131. snd_emu10k1_free_efx(emu);
  1132. }
  1133. if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) {
  1134. /* Disable 48Volt power to Audio Dock */
  1135. snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0);
  1136. }
  1137. if (emu->emu1010.firmware_thread)
  1138. kthread_stop(emu->emu1010.firmware_thread);
  1139. if (emu->irq >= 0)
  1140. free_irq(emu->irq, emu);
  1141. /* remove reserved page */
  1142. if (emu->reserved_page) {
  1143. snd_emu10k1_synth_free(emu,
  1144. (struct snd_util_memblk *)emu->reserved_page);
  1145. emu->reserved_page = NULL;
  1146. }
  1147. if (emu->memhdr)
  1148. snd_util_memhdr_free(emu->memhdr);
  1149. if (emu->silent_page.area)
  1150. snd_dma_free_pages(&emu->silent_page);
  1151. if (emu->ptb_pages.area)
  1152. snd_dma_free_pages(&emu->ptb_pages);
  1153. vfree(emu->page_ptr_table);
  1154. vfree(emu->page_addr_table);
  1155. #ifdef CONFIG_PM
  1156. free_pm_buffer(emu);
  1157. #endif
  1158. if (emu->port)
  1159. pci_release_regions(emu->pci);
  1160. if (emu->card_capabilities->ca0151_chip) /* P16V */
  1161. snd_p16v_free(emu);
  1162. pci_disable_device(emu->pci);
  1163. kfree(emu);
  1164. return 0;
  1165. }
  1166. static int snd_emu10k1_dev_free(struct snd_device *device)
  1167. {
  1168. struct snd_emu10k1 *emu = device->device_data;
  1169. return snd_emu10k1_free(emu);
  1170. }
  1171. static struct snd_emu_chip_details emu_chip_details[] = {
  1172. /* Audigy4 (Not PRO) SB0610 */
  1173. /* Tested by James@superbug.co.uk 4th April 2006 */
  1174. /* A_IOCFG bits
  1175. * Output
  1176. * 0: ?
  1177. * 1: ?
  1178. * 2: ?
  1179. * 3: 0 - Digital Out, 1 - Line in
  1180. * 4: ?
  1181. * 5: ?
  1182. * 6: ?
  1183. * 7: ?
  1184. * Input
  1185. * 8: ?
  1186. * 9: ?
  1187. * A: Green jack sense (Front)
  1188. * B: ?
  1189. * C: Black jack sense (Rear/Side Right)
  1190. * D: Yellow jack sense (Center/LFE/Side Left)
  1191. * E: ?
  1192. * F: ?
  1193. *
  1194. * Digital Out/Line in switch using A_IOCFG bit 3 (0x08)
  1195. * 0 - Digital Out
  1196. * 1 - Line in
  1197. */
  1198. /* Mic input not tested.
  1199. * Analog CD input not tested
  1200. * Digital Out not tested.
  1201. * Line in working.
  1202. * Audio output 5.1 working. Side outputs not working.
  1203. */
  1204. /* DSP: CA10300-IAT LF
  1205. * DAC: Cirrus Logic CS4382-KQZ
  1206. * ADC: Philips 1361T
  1207. * AC97: Sigmatel STAC9750
  1208. * CA0151: None
  1209. */
  1210. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
  1211. .driver = "Audigy2", .name = "SB Audigy 4 [SB0610]",
  1212. .id = "Audigy2",
  1213. .emu10k2_chip = 1,
  1214. .ca0108_chip = 1,
  1215. .spk71 = 1,
  1216. .adc_1361t = 1, /* 24 bit capture instead of 16bit */
  1217. .ac97_chip = 1} ,
  1218. /* Audigy 2 Value AC3 out does not work yet.
  1219. * Need to find out how to turn off interpolators.
  1220. */
  1221. /* Tested by James@superbug.co.uk 3rd July 2005 */
  1222. /* DSP: CA0108-IAT
  1223. * DAC: CS4382-KQ
  1224. * ADC: Philips 1361T
  1225. * AC97: STAC9750
  1226. * CA0151: None
  1227. */
  1228. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
  1229. .driver = "Audigy2", .name = "SB Audigy 2 Value [SB0400]",
  1230. .id = "Audigy2",
  1231. .emu10k2_chip = 1,
  1232. .ca0108_chip = 1,
  1233. .spk71 = 1,
  1234. .ac97_chip = 1} ,
  1235. /* Audigy 2 ZS Notebook Cardbus card.*/
  1236. /* Tested by James@superbug.co.uk 6th November 2006 */
  1237. /* Audio output 7.1/Headphones working.
  1238. * Digital output working. (AC3 not checked, only PCM)
  1239. * Audio Mic/Line inputs working.
  1240. * Digital input not tested.
  1241. */
  1242. /* DSP: Tina2
  1243. * DAC: Wolfson WM8768/WM8568
  1244. * ADC: Wolfson WM8775
  1245. * AC97: None
  1246. * CA0151: None
  1247. */
  1248. /* Tested by James@superbug.co.uk 4th April 2006 */
  1249. /* A_IOCFG bits
  1250. * Output
  1251. * 0: Not Used
  1252. * 1: 0 = Mute all the 7.1 channel out. 1 = unmute.
  1253. * 2: Analog input 0 = line in, 1 = mic in
  1254. * 3: Not Used
  1255. * 4: Digital output 0 = off, 1 = on.
  1256. * 5: Not Used
  1257. * 6: Not Used
  1258. * 7: Not Used
  1259. * Input
  1260. * All bits 1 (0x3fxx) means nothing plugged in.
  1261. * 8-9: 0 = Line in/Mic, 2 = Optical in, 3 = Nothing.
  1262. * A-B: 0 = Headphones, 2 = Optical out, 3 = Nothing.
  1263. * C-D: 2 = Front/Rear/etc, 3 = nothing.
  1264. * E-F: Always 0
  1265. *
  1266. */
  1267. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
  1268. .driver = "Audigy2", .name = "SB Audigy 2 ZS Notebook [SB0530]",
  1269. .id = "Audigy2",
  1270. .emu10k2_chip = 1,
  1271. .ca0108_chip = 1,
  1272. .ca_cardbus_chip = 1,
  1273. .spi_dac = 1,
  1274. .i2c_adc = 1,
  1275. .spk71 = 1} ,
  1276. /* Tested by James@superbug.co.uk 4th Nov 2007. */
  1277. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x42011102,
  1278. .driver = "Audigy2", .name = "E-mu 1010 Notebook [MAEM8950]",
  1279. .id = "EMU1010",
  1280. .emu10k2_chip = 1,
  1281. .ca0108_chip = 1,
  1282. .ca_cardbus_chip = 1,
  1283. .spk71 = 1 ,
  1284. .emu_model = EMU_MODEL_EMU1616},
  1285. /* Tested by James@superbug.co.uk 4th Nov 2007. */
  1286. /* This is MAEM8960, 0202 is MAEM 8980 */
  1287. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40041102,
  1288. .driver = "Audigy2", .name = "E-mu 1010b PCI [MAEM8960]",
  1289. .id = "EMU1010",
  1290. .emu10k2_chip = 1,
  1291. .ca0108_chip = 1,
  1292. .spk71 = 1,
  1293. .emu_model = EMU_MODEL_EMU1010B}, /* EMU 1010 new revision */
  1294. /* Tested by James@superbug.co.uk 8th July 2005. */
  1295. /* This is MAEM8810, 0202 is MAEM8820 */
  1296. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
  1297. .driver = "Audigy2", .name = "E-mu 1010 [MAEM8810]",
  1298. .id = "EMU1010",
  1299. .emu10k2_chip = 1,
  1300. .ca0102_chip = 1,
  1301. .spk71 = 1,
  1302. .emu_model = EMU_MODEL_EMU1010}, /* EMU 1010 old revision */
  1303. /* EMU0404b */
  1304. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40021102,
  1305. .driver = "Audigy2", .name = "E-mu 0404b PCI [MAEM8852]",
  1306. .id = "EMU0404",
  1307. .emu10k2_chip = 1,
  1308. .ca0108_chip = 1,
  1309. .spk71 = 1,
  1310. .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 new revision */
  1311. /* Tested by James@superbug.co.uk 20-3-2007. */
  1312. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40021102,
  1313. .driver = "Audigy2", .name = "E-mu 0404 [MAEM8850]",
  1314. .id = "EMU0404",
  1315. .emu10k2_chip = 1,
  1316. .ca0102_chip = 1,
  1317. .spk71 = 1,
  1318. .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 */
  1319. /* EMU0404 PCIe */
  1320. {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40051102,
  1321. .driver = "Audigy2", .name = "E-mu 0404 PCIe [MAEM8984]",
  1322. .id = "EMU0404",
  1323. .emu10k2_chip = 1,
  1324. .ca0108_chip = 1,
  1325. .spk71 = 1,
  1326. .emu_model = EMU_MODEL_EMU0404}, /* EMU 0404 PCIe ver_03 */
  1327. /* Note that all E-mu cards require kernel 2.6 or newer. */
  1328. {.vendor = 0x1102, .device = 0x0008,
  1329. .driver = "Audigy2", .name = "SB Audigy 2 Value [Unknown]",
  1330. .id = "Audigy2",
  1331. .emu10k2_chip = 1,
  1332. .ca0108_chip = 1,
  1333. .ac97_chip = 1} ,
  1334. /* Tested by James@superbug.co.uk 3rd July 2005 */
  1335. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
  1336. .driver = "Audigy2", .name = "SB Audigy 4 PRO [SB0380]",
  1337. .id = "Audigy2",
  1338. .emu10k2_chip = 1,
  1339. .ca0102_chip = 1,
  1340. .ca0151_chip = 1,
  1341. .spk71 = 1,
  1342. .spdif_bug = 1,
  1343. .ac97_chip = 1} ,
  1344. /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
  1345. /* The 0x20061102 does have SB0350 written on it
  1346. * Just like 0x20021102
  1347. */
  1348. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
  1349. .driver = "Audigy2", .name = "SB Audigy 2 [SB0350b]",
  1350. .id = "Audigy2",
  1351. .emu10k2_chip = 1,
  1352. .ca0102_chip = 1,
  1353. .ca0151_chip = 1,
  1354. .spk71 = 1,
  1355. .spdif_bug = 1,
  1356. .invert_shared_spdif = 1, /* digital/analog switch swapped */
  1357. .ac97_chip = 1} ,
  1358. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
  1359. .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0350]",
  1360. .id = "Audigy2",
  1361. .emu10k2_chip = 1,
  1362. .ca0102_chip = 1,
  1363. .ca0151_chip = 1,
  1364. .spk71 = 1,
  1365. .spdif_bug = 1,
  1366. .invert_shared_spdif = 1, /* digital/analog switch swapped */
  1367. .ac97_chip = 1} ,
  1368. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
  1369. .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0360]",
  1370. .id = "Audigy2",
  1371. .emu10k2_chip = 1,
  1372. .ca0102_chip = 1,
  1373. .ca0151_chip = 1,
  1374. .spk71 = 1,
  1375. .spdif_bug = 1,
  1376. .invert_shared_spdif = 1, /* digital/analog switch swapped */
  1377. .ac97_chip = 1} ,
  1378. /* Audigy 2 */
  1379. /* Tested by James@superbug.co.uk 3rd July 2005 */
  1380. /* DSP: CA0102-IAT
  1381. * DAC: CS4382-KQ
  1382. * ADC: Philips 1361T
  1383. * AC97: STAC9721
  1384. * CA0151: Yes
  1385. */
  1386. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
  1387. .driver = "Audigy2", .name = "SB Audigy 2 [SB0240]",
  1388. .id = "Audigy2",
  1389. .emu10k2_chip = 1,
  1390. .ca0102_chip = 1,
  1391. .ca0151_chip = 1,
  1392. .spk71 = 1,
  1393. .spdif_bug = 1,
  1394. .adc_1361t = 1, /* 24 bit capture instead of 16bit */
  1395. .ac97_chip = 1} ,
  1396. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
  1397. .driver = "Audigy2", .name = "SB Audigy 2 Platinum EX [SB0280]",
  1398. .id = "Audigy2",
  1399. .emu10k2_chip = 1,
  1400. .ca0102_chip = 1,
  1401. .ca0151_chip = 1,
  1402. .spk71 = 1,
  1403. .spdif_bug = 1} ,
  1404. /* Dell OEM/Creative Labs Audigy 2 ZS */
  1405. /* See ALSA bug#1365 */
  1406. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
  1407. .driver = "Audigy2", .name = "SB Audigy 2 ZS [SB0353]",
  1408. .id = "Audigy2",
  1409. .emu10k2_chip = 1,
  1410. .ca0102_chip = 1,
  1411. .ca0151_chip = 1,
  1412. .spk71 = 1,
  1413. .spdif_bug = 1,
  1414. .invert_shared_spdif = 1, /* digital/analog switch swapped */
  1415. .ac97_chip = 1} ,
  1416. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
  1417. .driver = "Audigy2", .name = "SB Audigy 2 Platinum [SB0240P]",
  1418. .id = "Audigy2",
  1419. .emu10k2_chip = 1,
  1420. .ca0102_chip = 1,
  1421. .ca0151_chip = 1,
  1422. .spk71 = 1,
  1423. .spdif_bug = 1,
  1424. .invert_shared_spdif = 1, /* digital/analog switch swapped */
  1425. .adc_1361t = 1, /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */
  1426. .ac97_chip = 1} ,
  1427. {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
  1428. .driver = "Audigy2", .name = "SB Audigy 2 [Unknown]",
  1429. .id = "Audigy2",
  1430. .emu10k2_chip = 1,
  1431. .ca0102_chip = 1,
  1432. .ca0151_chip = 1,
  1433. .spdif_bug = 1,
  1434. .ac97_chip = 1} ,
  1435. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
  1436. .driver = "Audigy", .name = "SB Audigy 1 [SB0092]",
  1437. .id = "Audigy",
  1438. .emu10k2_chip = 1,
  1439. .ca0102_chip = 1,
  1440. .ac97_chip = 1} ,
  1441. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
  1442. .driver = "Audigy", .name = "SB Audigy 1 ES [SB0160]",
  1443. .id = "Audigy",
  1444. .emu10k2_chip = 1,
  1445. .ca0102_chip = 1,
  1446. .spdif_bug = 1,
  1447. .ac97_chip = 1} ,
  1448. {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
  1449. .driver = "Audigy", .name = "SB Audigy 1 [SB0090]",
  1450. .id = "Audigy",
  1451. .emu10k2_chip = 1,
  1452. .ca0102_chip = 1,
  1453. .ac97_chip = 1} ,
  1454. {.vendor = 0x1102, .device = 0x0004,
  1455. .driver = "Audigy", .name = "Audigy 1 [Unknown]",
  1456. .id = "Audigy",
  1457. .emu10k2_chip = 1,
  1458. .ca0102_chip = 1,
  1459. .ac97_chip = 1} ,
  1460. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
  1461. .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0220]",
  1462. .id = "Live",
  1463. .emu10k1_chip = 1,
  1464. .ac97_chip = 1,
  1465. .sblive51 = 1} ,
  1466. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806b1102,
  1467. .driver = "EMU10K1", .name = "SB Live! [SB0105]",
  1468. .id = "Live",
  1469. .emu10k1_chip = 1,
  1470. .ac97_chip = 1,
  1471. .sblive51 = 1} ,
  1472. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806a1102,
  1473. .driver = "EMU10K1", .name = "SB Live! Value [SB0103]",
  1474. .id = "Live",
  1475. .emu10k1_chip = 1,
  1476. .ac97_chip = 1,
  1477. .sblive51 = 1} ,
  1478. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
  1479. .driver = "EMU10K1", .name = "SB Live! Value [SB0101]",
  1480. .id = "Live",
  1481. .emu10k1_chip = 1,
  1482. .ac97_chip = 1,
  1483. .sblive51 = 1} ,
  1484. /* Tested by ALSA bug#1680 26th December 2005 */
  1485. /* note: It really has SB0220 written on the card, */
  1486. /* but it's SB0228 according to kx.inf */
  1487. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
  1488. .driver = "EMU10K1", .name = "SB Live! 5.1 Dell OEM [SB0228]",
  1489. .id = "Live",
  1490. .emu10k1_chip = 1,
  1491. .ac97_chip = 1,
  1492. .sblive51 = 1} ,
  1493. /* Tested by Thomas Zehetbauer 27th Aug 2005 */
  1494. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
  1495. .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0220]",
  1496. .id = "Live",
  1497. .emu10k1_chip = 1,
  1498. .ac97_chip = 1,
  1499. .sblive51 = 1} ,
  1500. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
  1501. .driver = "EMU10K1", .name = "SB Live! 5.1",
  1502. .id = "Live",
  1503. .emu10k1_chip = 1,
  1504. .ac97_chip = 1,
  1505. .sblive51 = 1} ,
  1506. /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
  1507. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
  1508. .driver = "EMU10K1", .name = "SB Live! 5.1 [SB0060]",
  1509. .id = "Live",
  1510. .emu10k1_chip = 1,
  1511. .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
  1512. * share the same IDs!
  1513. */
  1514. .sblive51 = 1} ,
  1515. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
  1516. .driver = "EMU10K1", .name = "SB Live! Value [CT4850]",
  1517. .id = "Live",
  1518. .emu10k1_chip = 1,
  1519. .ac97_chip = 1,
  1520. .sblive51 = 1} ,
  1521. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
  1522. .driver = "EMU10K1", .name = "SB Live! Platinum [CT4760P]",
  1523. .id = "Live",
  1524. .emu10k1_chip = 1,
  1525. .ac97_chip = 1} ,
  1526. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
  1527. .driver = "EMU10K1", .name = "SB Live! Value [CT4871]",
  1528. .id = "Live",
  1529. .emu10k1_chip = 1,
  1530. .ac97_chip = 1,
  1531. .sblive51 = 1} ,
  1532. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
  1533. .driver = "EMU10K1", .name = "SB Live! Value [CT4831]",
  1534. .id = "Live",
  1535. .emu10k1_chip = 1,
  1536. .ac97_chip = 1,
  1537. .sblive51 = 1} ,
  1538. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
  1539. .driver = "EMU10K1", .name = "SB Live! Value [CT4870]",
  1540. .id = "Live",
  1541. .emu10k1_chip = 1,
  1542. .ac97_chip = 1,
  1543. .sblive51 = 1} ,
  1544. /* Tested by James@superbug.co.uk 3rd July 2005 */
  1545. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
  1546. .driver = "EMU10K1", .name = "SB Live! Value [CT4832]",
  1547. .id = "Live",
  1548. .emu10k1_chip = 1,
  1549. .ac97_chip = 1,
  1550. .sblive51 = 1} ,
  1551. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
  1552. .driver = "EMU10K1", .name = "SB Live! Value [CT4830]",
  1553. .id = "Live",
  1554. .emu10k1_chip = 1,
  1555. .ac97_chip = 1,
  1556. .sblive51 = 1} ,
  1557. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
  1558. .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
  1559. .id = "Live",
  1560. .emu10k1_chip = 1,
  1561. .ac97_chip = 1,
  1562. .sblive51 = 1} ,
  1563. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
  1564. .driver = "EMU10K1", .name = "SB Live! Value [CT4780]",
  1565. .id = "Live",
  1566. .emu10k1_chip = 1,
  1567. .ac97_chip = 1,
  1568. .sblive51 = 1} ,
  1569. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
  1570. .driver = "EMU10K1", .name = "E-mu APS [PC545]",
  1571. .id = "APS",
  1572. .emu10k1_chip = 1,
  1573. .ecard = 1} ,
  1574. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
  1575. .driver = "EMU10K1", .name = "SB Live! [CT4620]",
  1576. .id = "Live",
  1577. .emu10k1_chip = 1,
  1578. .ac97_chip = 1,
  1579. .sblive51 = 1} ,
  1580. {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
  1581. .driver = "EMU10K1", .name = "SB Live! Value [CT4670]",
  1582. .id = "Live",
  1583. .emu10k1_chip = 1,
  1584. .ac97_chip = 1,
  1585. .sblive51 = 1} ,
  1586. {.vendor = 0x1102, .device = 0x0002,
  1587. .driver = "EMU10K1", .name = "SB Live! [Unknown]",
  1588. .id = "Live",
  1589. .emu10k1_chip = 1,
  1590. .ac97_chip = 1,
  1591. .sblive51 = 1} ,
  1592. { } /* terminator */
  1593. };
  1594. int __devinit snd_emu10k1_create(struct snd_card *card,
  1595. struct pci_dev *pci,
  1596. unsigned short extin_mask,
  1597. unsigned short extout_mask,
  1598. long max_cache_bytes,
  1599. int enable_ir,
  1600. uint subsystem,
  1601. struct snd_emu10k1 **remu)
  1602. {
  1603. struct snd_emu10k1 *emu;
  1604. int idx, err;
  1605. int is_audigy;
  1606. unsigned int silent_page;
  1607. const struct snd_emu_chip_details *c;
  1608. static struct snd_device_ops ops = {
  1609. .dev_free = snd_emu10k1_dev_free,
  1610. };
  1611. *remu = NULL;
  1612. /* enable PCI device */
  1613. err = pci_enable_device(pci);
  1614. if (err < 0)
  1615. return err;
  1616. emu = kzalloc(sizeof(*emu), GFP_KERNEL);
  1617. if (emu == NULL) {
  1618. pci_disable_device(pci);
  1619. return -ENOMEM;
  1620. }
  1621. emu->card = card;
  1622. spin_lock_init(&emu->reg_lock);
  1623. spin_lock_init(&emu->emu_lock);
  1624. spin_lock_init(&emu->spi_lock);
  1625. spin_lock_init(&emu->i2c_lock);
  1626. spin_lock_init(&emu->voice_lock);
  1627. spin_lock_init(&emu->synth_lock);
  1628. spin_lock_init(&emu->memblk_lock);
  1629. mutex_init(&emu->fx8010.lock);
  1630. INIT_LIST_HEAD(&emu->mapped_link_head);
  1631. INIT_LIST_HEAD(&emu->mapped_order_link_head);
  1632. emu->pci = pci;
  1633. emu->irq = -1;
  1634. emu->synth = NULL;
  1635. emu->get_synth_voice = NULL;
  1636. /* read revision & serial */
  1637. emu->revision = pci->revision;
  1638. pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
  1639. pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
  1640. 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);
  1641. for (c = emu_chip_details; c->vendor; c++) {
  1642. if (c->vendor == pci->vendor && c->device == pci->device) {
  1643. if (subsystem) {
  1644. if (c->subsystem && (c->subsystem == subsystem))
  1645. break;
  1646. else
  1647. continue;
  1648. } else {
  1649. if (c->subsystem && (c->subsystem != emu->serial))
  1650. continue;
  1651. if (c->revision && c->revision != emu->revision)
  1652. continue;
  1653. }
  1654. break;
  1655. }
  1656. }
  1657. if (c->vendor == 0) {
  1658. snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
  1659. kfree(emu);
  1660. pci_disable_device(pci);
  1661. return -ENOENT;
  1662. }
  1663. emu->card_capabilities = c;
  1664. if (c->subsystem && !subsystem)
  1665. snd_printdd("Sound card name = %s\n", c->name);
  1666. else if (subsystem)
  1667. snd_printdd("Sound card name = %s, "
  1668. "vendor = 0x%x, device = 0x%x, subsystem = 0x%x. "
  1669. "Forced to subsystem = 0x%x\n", c->name,
  1670. pci->vendor, pci->device, emu->serial, c->subsystem);
  1671. else
  1672. snd_printdd("Sound card name = %s, "
  1673. "vendor = 0x%x, device = 0x%x, subsystem = 0x%x.\n",
  1674. c->name, pci->vendor, pci->device,
  1675. emu->serial);
  1676. if (!*card->id && c->id) {
  1677. int i, n = 0;
  1678. strlcpy(card->id, c->id, sizeof(card->id));
  1679. for (;;) {
  1680. for (i = 0; i < snd_ecards_limit; i++) {
  1681. if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
  1682. break;
  1683. }
  1684. if (i >= snd_ecards_limit)
  1685. break;
  1686. n++;
  1687. if (n >= SNDRV_CARDS)
  1688. break;
  1689. snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
  1690. }
  1691. }
  1692. is_audigy = emu->audigy = c->emu10k2_chip;
  1693. /* set the DMA transfer mask */
  1694. emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
  1695. if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
  1696. pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
  1697. snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
  1698. kfree(emu);
  1699. pci_disable_device(pci);
  1700. return -ENXIO;
  1701. }
  1702. if (is_audigy)
  1703. emu->gpr_base = A_FXGPREGBASE;
  1704. else
  1705. emu->gpr_base = FXGPREGBASE;
  1706. err = pci_request_regions(pci, "EMU10K1");
  1707. if (err < 0) {
  1708. kfree(emu);
  1709. pci_disable_device(pci);
  1710. return err;
  1711. }
  1712. emu->port = pci_resource_start(pci, 0);
  1713. emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
  1714. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1715. 32 * 1024, &emu->ptb_pages) < 0) {
  1716. err = -ENOMEM;
  1717. goto error;
  1718. }
  1719. emu->page_ptr_table = vmalloc(emu->max_cache_pages * sizeof(void *));
  1720. emu->page_addr_table = vmalloc(emu->max_cache_pages *
  1721. sizeof(unsigned long));
  1722. if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
  1723. err = -ENOMEM;
  1724. goto error;
  1725. }
  1726. if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
  1727. EMUPAGESIZE, &emu->silent_page) < 0) {
  1728. err = -ENOMEM;
  1729. goto error;
  1730. }
  1731. emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
  1732. if (emu->memhdr == NULL) {
  1733. err = -ENOMEM;
  1734. goto error;
  1735. }
  1736. emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
  1737. sizeof(struct snd_util_memblk);
  1738. pci_set_master(pci);
  1739. emu->fx8010.fxbus_mask = 0x303f;
  1740. if (extin_mask == 0)
  1741. extin_mask = 0x3fcf;
  1742. if (extout_mask == 0)
  1743. extout_mask = 0x7fff;
  1744. emu->fx8010.extin_mask = extin_mask;
  1745. emu->fx8010.extout_mask = extout_mask;
  1746. emu->enable_ir = enable_ir;
  1747. if (emu->card_capabilities->ca_cardbus_chip) {
  1748. err = snd_emu10k1_cardbus_init(emu);
  1749. if (err < 0)
  1750. goto error;
  1751. }
  1752. if (emu->card_capabilities->ecard) {
  1753. err = snd_emu10k1_ecard_init(emu);
  1754. if (err < 0)
  1755. goto error;
  1756. } else if (emu->card_capabilities->emu_model) {
  1757. err = snd_emu10k1_emu1010_init(emu);
  1758. if (err < 0) {
  1759. snd_emu10k1_free(emu);
  1760. return err;
  1761. }
  1762. } else {
  1763. /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
  1764. does not support this, it shouldn't do any harm */
  1765. snd_emu10k1_ptr_write(emu, AC97SLOT, 0,
  1766. AC97SLOT_CNTR|AC97SLOT_LFE);
  1767. }
  1768. /* initialize TRAM setup */
  1769. emu->fx8010.itram_size = (16 * 1024)/2;
  1770. emu->fx8010.etram_pages.area = NULL;
  1771. emu->fx8010.etram_pages.bytes = 0;
  1772. /* irq handler must be registered after I/O ports are activated */
  1773. if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_SHARED,
  1774. "EMU10K1", emu)) {
  1775. err = -EBUSY;
  1776. goto error;
  1777. }
  1778. emu->irq = pci->irq;
  1779. /*
  1780. * Init to 0x02109204 :
  1781. * Clock accuracy = 0 (1000ppm)
  1782. * Sample Rate = 2 (48kHz)
  1783. * Audio Channel = 1 (Left of 2)
  1784. * Source Number = 0 (Unspecified)
  1785. * Generation Status = 1 (Original for Cat Code 12)
  1786. * Cat Code = 12 (Digital Signal Mixer)
  1787. * Mode = 0 (Mode 0)
  1788. * Emphasis = 0 (None)
  1789. * CP = 1 (Copyright unasserted)
  1790. * AN = 0 (Audio data)
  1791. * P = 0 (Consumer)
  1792. */
  1793. emu->spdif_bits[0] = emu->spdif_bits[1] =
  1794. emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
  1795. SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
  1796. SPCS_GENERATIONSTATUS | 0x00001200 |
  1797. 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
  1798. emu->reserved_page = (struct snd_emu10k1_memblk *)
  1799. snd_emu10k1_synth_alloc(emu, 4096);
  1800. if (emu->reserved_page)
  1801. emu->reserved_page->map_locked = 1;
  1802. /* Clear silent pages and set up pointers */
  1803. memset(emu->silent_page.area, 0, PAGE_SIZE);
  1804. silent_page = emu->silent_page.addr << 1;
  1805. for (idx = 0; idx < MAXPAGES; idx++)
  1806. ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
  1807. /* set up voice indices */
  1808. for (idx = 0; idx < NUM_G; idx++) {
  1809. emu->voices[idx].emu = emu;
  1810. emu->voices[idx].number = idx;
  1811. }
  1812. err = snd_emu10k1_init(emu, enable_ir, 0);
  1813. if (err < 0)
  1814. goto error;
  1815. #ifdef CONFIG_PM
  1816. err = alloc_pm_buffer(emu);
  1817. if (err < 0)
  1818. goto error;
  1819. #endif
  1820. /* Initialize the effect engine */
  1821. err = snd_emu10k1_init_efx(emu);
  1822. if (err < 0)
  1823. goto error;
  1824. snd_emu10k1_audio_enable(emu);
  1825. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops);
  1826. if (err < 0)
  1827. goto error;
  1828. #ifdef CONFIG_PROC_FS
  1829. snd_emu10k1_proc_init(emu);
  1830. #endif
  1831. snd_card_set_dev(card, &pci->dev);
  1832. *remu = emu;
  1833. return 0;
  1834. error:
  1835. snd_emu10k1_free(emu);
  1836. return err;
  1837. }
  1838. #ifdef CONFIG_PM
  1839. static unsigned char saved_regs[] = {
  1840. CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
  1841. FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
  1842. ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
  1843. TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
  1844. MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
  1845. SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
  1846. 0xff /* end */
  1847. };
  1848. static unsigned char saved_regs_audigy[] = {
  1849. A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
  1850. A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
  1851. 0xff /* end */
  1852. };
  1853. static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
  1854. {
  1855. int size;
  1856. size = ARRAY_SIZE(saved_regs);
  1857. if (emu->audigy)
  1858. size += ARRAY_SIZE(saved_regs_audigy);
  1859. emu->saved_ptr = vmalloc(4 * NUM_G * size);
  1860. if (!emu->saved_ptr)
  1861. return -ENOMEM;
  1862. if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
  1863. return -ENOMEM;
  1864. if (emu->card_capabilities->ca0151_chip &&
  1865. snd_p16v_alloc_pm_buffer(emu) < 0)
  1866. return -ENOMEM;
  1867. return 0;
  1868. }
  1869. static void free_pm_buffer(struct snd_emu10k1 *emu)
  1870. {
  1871. vfree(emu->saved_ptr);
  1872. snd_emu10k1_efx_free_pm_buffer(emu);
  1873. if (emu->card_capabilities->ca0151_chip)
  1874. snd_p16v_free_pm_buffer(emu);
  1875. }
  1876. void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
  1877. {
  1878. int i;
  1879. unsigned char *reg;
  1880. unsigned int *val;
  1881. val = emu->saved_ptr;
  1882. for (reg = saved_regs; *reg != 0xff; reg++)
  1883. for (i = 0; i < NUM_G; i++, val++)
  1884. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1885. if (emu->audigy) {
  1886. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1887. for (i = 0; i < NUM_G; i++, val++)
  1888. *val = snd_emu10k1_ptr_read(emu, *reg, i);
  1889. }
  1890. if (emu->audigy)
  1891. emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
  1892. emu->saved_hcfg = inl(emu->port + HCFG);
  1893. }
  1894. void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
  1895. {
  1896. if (emu->card_capabilities->ca_cardbus_chip)
  1897. snd_emu10k1_cardbus_init(emu);
  1898. if (emu->card_capabilities->ecard)
  1899. snd_emu10k1_ecard_init(emu);
  1900. else if (emu->card_capabilities->emu_model)
  1901. snd_emu10k1_emu1010_init(emu);
  1902. else
  1903. snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
  1904. snd_emu10k1_init(emu, emu->enable_ir, 1);
  1905. }
  1906. void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
  1907. {
  1908. int i;
  1909. unsigned char *reg;
  1910. unsigned int *val;
  1911. snd_emu10k1_audio_enable(emu);
  1912. /* resore for spdif */
  1913. if (emu->audigy)
  1914. outl(emu->saved_a_iocfg, emu->port + A_IOCFG);
  1915. outl(emu->saved_hcfg, emu->port + HCFG);
  1916. val = emu->saved_ptr;
  1917. for (reg = saved_regs; *reg != 0xff; reg++)
  1918. for (i = 0; i < NUM_G; i++, val++)
  1919. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1920. if (emu->audigy) {
  1921. for (reg = saved_regs_audigy; *reg != 0xff; reg++)
  1922. for (i = 0; i < NUM_G; i++, val++)
  1923. snd_emu10k1_ptr_write(emu, *reg, i, *val);
  1924. }
  1925. }
  1926. #endif