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