2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4 * Routines for control of EMU10K1 chips
6 * Copyright (c) by James Courtier-Dutton <James@superbug.demon.co.uk>
7 * Added support for Audigy 2 Value.
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.
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.
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
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>
40 #include <sound/core.h>
41 #include <sound/emu10k1.h>
46 /*************************************************************************
48 *************************************************************************/
50 void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int ch)
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);
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);
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);
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);
83 /* Audigy extra stuffs */
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);
95 static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
97 unsigned int silent_page;
100 /* disable audio and lock cache */
101 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
104 /* reset recording buffers */
105 snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
106 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
107 snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
108 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
109 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
110 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
112 /* disable channel interrupt */
113 outl(0, emu->port + INTE);
114 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
115 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
116 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
117 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
120 /* set SPDIF bypass mode */
121 snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
122 /* enable rear left + rear right AC97 slots */
123 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
127 /* init envelope engine */
128 for (ch = 0; ch < NUM_G; ch++)
129 snd_emu10k1_voice_init(emu, ch);
131 snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
132 snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
133 snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
135 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
136 /* Hacks for Alice3 to work independent of haP16V driver */
139 //Setup SRCMulti_I2S SamplingRate
140 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
143 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
145 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
146 snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
147 /* Setup SRCMulti Input Audio Enable */
148 /* Use 0xFFFFFFFF to enable P16V sounds. */
149 snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
151 /* Enabled Phased (8-channel) P16V playback */
152 outl(0x0201, emu->port + HCFG2);
153 /* Set playback routing. */
154 snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
156 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
157 /* Hacks for Alice3 to work independent of haP16V driver */
160 snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
161 //Setup SRCMulti_I2S SamplingRate
162 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
165 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
167 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
168 outl(0x600000, emu->port + 0x20);
169 outl(0x14, emu->port + 0x24);
171 /* Setup SRCMulti Input Audio Enable */
172 outl(0x7b0000, emu->port + 0x20);
173 outl(0xFF000000, emu->port + 0x24);
175 /* Setup SPDIF Out Audio Enable */
176 /* The Audigy 2 Value has a separate SPDIF out,
177 * so no need for a mixer switch
179 outl(0x7a0000, emu->port + 0x20);
180 outl(0xFF000000, emu->port + 0x24);
181 tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
182 outl(tmp, emu->port + A_IOCFG);
184 if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
186 tmp = snd_emu10k1_spi_write(emu, 0x00ff);
187 tmp = snd_emu10k1_spi_write(emu, 0x02ff);
188 tmp = snd_emu10k1_spi_write(emu, 0x0400);
189 tmp = snd_emu10k1_spi_write(emu, 0x0520);
190 tmp = snd_emu10k1_spi_write(emu, 0x0600);
191 tmp = snd_emu10k1_spi_write(emu, 0x08ff);
192 tmp = snd_emu10k1_spi_write(emu, 0x0aff);
193 tmp = snd_emu10k1_spi_write(emu, 0x0cff);
194 tmp = snd_emu10k1_spi_write(emu, 0x0eff);
195 tmp = snd_emu10k1_spi_write(emu, 0x10ff);
196 tmp = snd_emu10k1_spi_write(emu, 0x1200);
197 tmp = snd_emu10k1_spi_write(emu, 0x1400);
198 tmp = snd_emu10k1_spi_write(emu, 0x1480);
199 tmp = snd_emu10k1_spi_write(emu, 0x1800);
200 tmp = snd_emu10k1_spi_write(emu, 0x1aff);
201 tmp = snd_emu10k1_spi_write(emu, 0x1cff);
202 tmp = snd_emu10k1_spi_write(emu, 0x1e00);
203 tmp = snd_emu10k1_spi_write(emu, 0x0530);
204 tmp = snd_emu10k1_spi_write(emu, 0x0602);
205 tmp = snd_emu10k1_spi_write(emu, 0x0622);
206 tmp = snd_emu10k1_spi_write(emu, 0x1400);
207 snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
210 snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
211 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
212 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
214 silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
215 for (ch = 0; ch < NUM_G; ch++) {
216 snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
217 snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
222 * Mute Disable Audio = 0
223 * Lock Tank Memory = 1
224 * Lock Sound Memory = 0
228 if (emu->revision == 4) /* audigy2 */
229 outl(HCFG_AUDIOENABLE |
230 HCFG_AC3ENABLE_CDSPDIF |
231 HCFG_AC3ENABLE_GPSPDIF |
232 HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
234 outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
235 /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
236 * e.g. card_capabilities->joystick */
237 } else if (emu->model == 0x20 ||
238 emu->model == 0xc400 ||
239 (emu->model == 0x21 && emu->revision < 6))
240 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
242 // With on-chip joystick
243 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
245 if (enable_ir) { /* enable IR for SB Live */
246 if ( emu->card_capabilities->emu1212m) {
247 ; /* Disable all access to A_IOCFG for the emu1212m */
248 } else if (emu->audigy) {
249 unsigned int reg = inl(emu->port + A_IOCFG);
250 outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
252 outl(reg | A_IOCFG_GPOUT1 | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
254 outl(reg, emu->port + A_IOCFG);
256 unsigned int reg = inl(emu->port + HCFG);
257 outl(reg | HCFG_GPOUT2, emu->port + HCFG);
259 outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
261 outl(reg, emu->port + HCFG);
265 if ( emu->card_capabilities->emu1212m) {
266 ; /* Disable all access to A_IOCFG for the emu1212m */
267 } else if (emu->audigy) { /* enable analog output */
268 unsigned int reg = inl(emu->port + A_IOCFG);
269 outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
275 static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
278 * Enable the audio bit
280 outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
282 /* Enable analog/digital outs on audigy */
283 if ( emu->card_capabilities->emu1212m) {
284 ; /* Disable all access to A_IOCFG for the emu1212m */
285 } else if (emu->audigy) {
286 outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
288 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
289 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
290 * This has to be done after init ALice3 I2SOut beyond 48KHz.
291 * So, sequence is important. */
292 outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
293 } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
294 /* Unmute Analog now. */
295 outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
297 /* Disable routing from AC97 line out to Front speakers */
298 outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
305 /* FIXME: the following routine disables LiveDrive-II !! */
308 tmp = inl(emu->port + HCFG);
309 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
310 outl(tmp|0x800, emu->port + HCFG);
312 if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
314 outl(tmp, emu->port + HCFG);
320 snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
323 int snd_emu10k1_done(struct snd_emu10k1 * emu)
327 outl(0, emu->port + INTE);
332 for (ch = 0; ch < NUM_G; ch++)
333 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
334 for (ch = 0; ch < NUM_G; ch++) {
335 snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
336 snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
337 snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
338 snd_emu10k1_ptr_write(emu, CPF, ch, 0);
341 /* reset recording buffers */
342 snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
343 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
344 snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
345 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
346 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
347 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
348 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
349 snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
350 snd_emu10k1_ptr_write(emu, TCB, 0, 0);
352 snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
354 snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
356 /* disable channel interrupt */
357 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
358 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
359 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
360 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
362 /* disable audio and lock cache */
363 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
364 snd_emu10k1_ptr_write(emu, PTB, 0, 0);
369 /*************************************************************************
370 * ECARD functional implementation
371 *************************************************************************/
373 /* In A1 Silicon, these bits are in the HC register */
374 #define HOOKN_BIT (1L << 12)
375 #define HANDN_BIT (1L << 11)
376 #define PULSEN_BIT (1L << 10)
378 #define EC_GDI1 (1 << 13)
379 #define EC_GDI0 (1 << 14)
381 #define EC_NUM_CONTROL_BITS 20
383 #define EC_AC3_DATA_SELN 0x0001L
384 #define EC_EE_DATA_SEL 0x0002L
385 #define EC_EE_CNTRL_SELN 0x0004L
386 #define EC_EECLK 0x0008L
387 #define EC_EECS 0x0010L
388 #define EC_EESDO 0x0020L
389 #define EC_TRIM_CSN 0x0040L
390 #define EC_TRIM_SCLK 0x0080L
391 #define EC_TRIM_SDATA 0x0100L
392 #define EC_TRIM_MUTEN 0x0200L
393 #define EC_ADCCAL 0x0400L
394 #define EC_ADCRSTN 0x0800L
395 #define EC_DACCAL 0x1000L
396 #define EC_DACMUTEN 0x2000L
397 #define EC_LEDN 0x4000L
399 #define EC_SPDIF0_SEL_SHIFT 15
400 #define EC_SPDIF1_SEL_SHIFT 17
401 #define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
402 #define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
403 #define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
404 #define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
405 #define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
406 * be incremented any time the EEPROM's
407 * format is changed. */
409 #define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
411 /* Addresses for special values stored in to EEPROM */
412 #define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
413 #define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
414 #define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
416 #define EC_LAST_PROMFILE_ADDR 0x2f
418 #define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
419 * can be up to 30 characters in length
420 * and is stored as a NULL-terminated
421 * ASCII string. Any unused bytes must be
422 * filled with zeros */
423 #define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
426 /* Most of this stuff is pretty self-evident. According to the hardware
427 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
428 * offset problem. Weird.
430 #define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
434 #define EC_DEFAULT_ADC_GAIN 0xC4C4
435 #define EC_DEFAULT_SPDIF0_SEL 0x0
436 #define EC_DEFAULT_SPDIF1_SEL 0x4
438 /**************************************************************************
439 * @func Clock bits into the Ecard's control latch. The Ecard uses a
440 * control latch will is loaded bit-serially by toggling the Modem control
441 * lines from function 2 on the E8010. This function hides these details
442 * and presents the illusion that we are actually writing to a distinct
446 static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value)
448 unsigned short count;
450 unsigned long hc_port;
451 unsigned int hc_value;
453 hc_port = emu->port + HCFG;
454 hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
455 outl(hc_value, hc_port);
457 for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
459 /* Set up the value */
460 data = ((value & 0x1) ? PULSEN_BIT : 0);
463 outl(hc_value | data, hc_port);
465 /* Clock the shift register */
466 outl(hc_value | data | HANDN_BIT, hc_port);
467 outl(hc_value | data, hc_port);
471 outl(hc_value | HOOKN_BIT, hc_port);
472 outl(hc_value, hc_port);
475 /**************************************************************************
476 * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
477 * trim value consists of a 16bit value which is composed of two
478 * 8 bit gain/trim values, one for the left channel and one for the
479 * right channel. The following table maps from the Gain/Attenuation
480 * value in decibels into the corresponding bit pattern for a single
484 static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
489 /* Enable writing to the TRIM registers */
490 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
492 /* Do it again to insure that we meet hold time requirements */
493 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
495 for (bit = (1 << 15); bit; bit >>= 1) {
498 value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
501 value |= EC_TRIM_SDATA;
504 snd_emu10k1_ecard_write(emu, value);
505 snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
506 snd_emu10k1_ecard_write(emu, value);
509 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
512 static int __devinit snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
514 unsigned int hc_value;
516 /* Set up the initial settings */
517 emu->ecard_ctrl = EC_RAW_RUN_MODE |
518 EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
519 EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
521 /* Step 0: Set the codec type in the hardware control register
522 * and enable audio output */
523 hc_value = inl(emu->port + HCFG);
524 outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
525 inl(emu->port + HCFG);
527 /* Step 1: Turn off the led and deassert TRIM_CS */
528 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
530 /* Step 2: Calibrate the ADC and DAC */
531 snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
533 /* Step 3: Wait for awhile; XXX We can't get away with this
534 * under a real operating system; we'll need to block and wait that
536 snd_emu10k1_wait(emu, 48000);
538 /* Step 4: Switch off the DAC and ADC calibration. Note
539 * That ADC_CAL is actually an inverted signal, so we assert
540 * it here to stop calibration. */
541 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
543 /* Step 4: Switch into run mode */
544 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
546 /* Step 5: Set the analog input gain */
547 snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
552 static int __devinit snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
554 unsigned long special_port;
557 /* Special initialisation routine
558 * before the rest of the IO-Ports become active.
560 special_port = emu->port + 0x38;
561 value = inl(special_port);
562 outl(0x00d00000, special_port);
563 value = inl(special_port);
564 outl(0x00d00001, special_port);
565 value = inl(special_port);
566 outl(0x00d0005f, special_port);
567 value = inl(special_port);
568 outl(0x00d0007f, special_port);
569 value = inl(special_port);
570 outl(0x0090007f, special_port);
571 value = inl(special_port);
573 snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
577 static int snd_emu1212m_fpga_write(struct snd_emu10k1 * emu, int reg, int value)
579 if (reg<0 || reg>0x3f)
581 reg+=0x40; /* 0x40 upwards are registers. */
582 if (value<0 || value>0x3f) /* 0 to 0x3f are values */
584 outl(reg, emu->port + A_IOCFG);
585 outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
586 outl(value, emu->port + A_IOCFG);
587 outl(value | 0x80 , emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
592 static int snd_emu1212m_fpga_read(struct snd_emu10k1 * emu, int reg, int *value)
594 if (reg<0 || reg>0x3f)
596 reg+=0x40; /* 0x40 upwards are registers. */
597 outl(reg, emu->port + A_IOCFG);
598 outl(reg | 0x80, emu->port + A_IOCFG); /* High bit clocks the value into the fpga. */
599 *value = inl(emu->port + A_IOCFG);
604 static int snd_emu1212m_fpga_netlist_write(struct snd_emu10k1 * emu, int reg, int value)
606 snd_emu1212m_fpga_write(emu, 0x00, ((reg >> 8) & 0x3f) );
607 snd_emu1212m_fpga_write(emu, 0x01, (reg & 0x3f) );
608 snd_emu1212m_fpga_write(emu, 0x02, ((value >> 8) & 0x3f) );
609 snd_emu1212m_fpga_write(emu, 0x03, (value & 0x3f) );
614 static int __devinit snd_emu10k1_emu1212m_init(struct snd_emu10k1 * emu)
619 snd_printk(KERN_ERR "emu1212m: Special config.\n");
620 outl(0x0005a00c, emu->port + HCFG);
621 outl(0x0005a004, emu->port + HCFG);
622 outl(0x0005a000, emu->port + HCFG);
623 outl(0x0005a000, emu->port + HCFG);
625 snd_emu1212m_fpga_read(emu, 0x22, &tmp );
626 snd_emu1212m_fpga_read(emu, 0x23, &tmp );
627 snd_emu1212m_fpga_read(emu, 0x24, &tmp );
628 snd_emu1212m_fpga_write(emu, 0x04, 0x01 );
629 snd_emu1212m_fpga_read(emu, 0x0b, &tmp );
630 snd_emu1212m_fpga_write(emu, 0x0b, 0x01 );
631 snd_emu1212m_fpga_read(emu, 0x10, &tmp );
632 snd_emu1212m_fpga_write(emu, 0x10, 0x00 );
633 snd_emu1212m_fpga_read(emu, 0x11, &tmp );
634 snd_emu1212m_fpga_write(emu, 0x11, 0x30 );
635 snd_emu1212m_fpga_read(emu, 0x13, &tmp );
636 snd_emu1212m_fpga_write(emu, 0x13, 0x0f );
637 snd_emu1212m_fpga_read(emu, 0x11, &tmp );
638 snd_emu1212m_fpga_write(emu, 0x11, 0x30 );
639 snd_emu1212m_fpga_read(emu, 0x0a, &tmp );
640 snd_emu1212m_fpga_write(emu, 0x0a, 0x10 );
641 snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
642 snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
643 snd_emu1212m_fpga_write(emu, 0x09, 0x0f );
644 snd_emu1212m_fpga_write(emu, 0x06, 0x00 );
645 snd_emu1212m_fpga_write(emu, 0x05, 0x00 );
646 snd_emu1212m_fpga_write(emu, 0x0e, 0x12 );
647 snd_emu1212m_fpga_netlist_write(emu, 0x0000, 0x0200);
648 snd_emu1212m_fpga_netlist_write(emu, 0x0001, 0x0201);
649 snd_emu1212m_fpga_netlist_write(emu, 0x0002, 0x0500);
650 snd_emu1212m_fpga_netlist_write(emu, 0x0003, 0x0501);
651 snd_emu1212m_fpga_netlist_write(emu, 0x0004, 0x0400);
652 snd_emu1212m_fpga_netlist_write(emu, 0x0005, 0x0401);
653 snd_emu1212m_fpga_netlist_write(emu, 0x0006, 0x0402);
654 snd_emu1212m_fpga_netlist_write(emu, 0x0007, 0x0403);
655 snd_emu1212m_fpga_netlist_write(emu, 0x0008, 0x0404);
656 snd_emu1212m_fpga_netlist_write(emu, 0x0009, 0x0405);
657 snd_emu1212m_fpga_netlist_write(emu, 0x000a, 0x0406);
658 snd_emu1212m_fpga_netlist_write(emu, 0x000b, 0x0407);
659 snd_emu1212m_fpga_netlist_write(emu, 0x000c, 0x0100);
660 snd_emu1212m_fpga_netlist_write(emu, 0x000d, 0x0104);
661 snd_emu1212m_fpga_netlist_write(emu, 0x000e, 0x0200);
662 snd_emu1212m_fpga_netlist_write(emu, 0x000f, 0x0201);
663 for (i=0;i < 0x20;i++) {
664 snd_emu1212m_fpga_netlist_write(emu, 0x0100+i, 0x0000);
666 for (i=0;i < 4;i++) {
667 snd_emu1212m_fpga_netlist_write(emu, 0x0200+i, 0x0000);
669 for (i=0;i < 7;i++) {
670 snd_emu1212m_fpga_netlist_write(emu, 0x0300+i, 0x0000);
672 for (i=0;i < 7;i++) {
673 snd_emu1212m_fpga_netlist_write(emu, 0x0400+i, 0x0000);
675 snd_emu1212m_fpga_netlist_write(emu, 0x0500, 0x0108);
676 snd_emu1212m_fpga_netlist_write(emu, 0x0501, 0x010c);
677 snd_emu1212m_fpga_netlist_write(emu, 0x0600, 0x0110);
678 snd_emu1212m_fpga_netlist_write(emu, 0x0601, 0x0114);
679 snd_emu1212m_fpga_netlist_write(emu, 0x0700, 0x0118);
680 snd_emu1212m_fpga_netlist_write(emu, 0x0701, 0x011c);
681 snd_emu1212m_fpga_write(emu, 0x07, 0x01 );
683 snd_emu1212m_fpga_read(emu, 0x21, &tmp );
685 outl(0x0000a000, emu->port + HCFG);
686 outl(0x0000a001, emu->port + HCFG);
687 /* Initial boot complete. Now patches */
689 snd_emu1212m_fpga_read(emu, 0x21, &tmp );
690 snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
691 snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
692 snd_emu1212m_fpga_write(emu, 0x0c, 0x19 );
693 snd_emu1212m_fpga_write(emu, 0x12, 0x0c );
694 snd_emu1212m_fpga_read(emu, 0x0a, &tmp );
695 snd_emu1212m_fpga_write(emu, 0x0a, 0x10 );
697 snd_emu1212m_fpga_read(emu, 0x20, &tmp );
698 snd_emu1212m_fpga_read(emu, 0x21, &tmp );
700 snd_emu1212m_fpga_netlist_write(emu, 0x0300, 0x0312);
701 snd_emu1212m_fpga_netlist_write(emu, 0x0301, 0x0313);
702 snd_emu1212m_fpga_netlist_write(emu, 0x0200, 0x0302);
703 snd_emu1212m_fpga_netlist_write(emu, 0x0201, 0x0303);
708 * Create the EMU10K1 instance
712 static int alloc_pm_buffer(struct snd_emu10k1 *emu);
713 static void free_pm_buffer(struct snd_emu10k1 *emu);
716 static int snd_emu10k1_free(struct snd_emu10k1 *emu)
718 if (emu->port) { /* avoid access to already used hardware */
719 snd_emu10k1_fx8010_tram_setup(emu, 0);
720 snd_emu10k1_done(emu);
721 /* remove reserved page */
722 if (emu->reserved_page) {
723 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
724 emu->reserved_page = NULL;
726 snd_emu10k1_free_efx(emu);
729 snd_util_memhdr_free(emu->memhdr);
730 if (emu->silent_page.area)
731 snd_dma_free_pages(&emu->silent_page);
732 if (emu->ptb_pages.area)
733 snd_dma_free_pages(&emu->ptb_pages);
734 vfree(emu->page_ptr_table);
735 vfree(emu->page_addr_table);
740 free_irq(emu->irq, (void *)emu);
742 pci_release_regions(emu->pci);
743 if (emu->card_capabilities->ca0151_chip) /* P16V */
745 pci_disable_device(emu->pci);
750 static int snd_emu10k1_dev_free(struct snd_device *device)
752 struct snd_emu10k1 *emu = device->device_data;
753 return snd_emu10k1_free(emu);
756 static struct snd_emu_chip_details emu_chip_details[] = {
757 /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
758 /* Tested by James@superbug.co.uk 3rd July 2005 */
759 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
760 .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
766 /* Audigy 2 ZS Notebook Cardbus card.*/
767 /* Tested by James@superbug.co.uk 30th October 2005 */
768 /* Not working yet, but progressing. */
769 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
770 .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
774 .ca_cardbus_chip = 1,
777 {.vendor = 0x1102, .device = 0x0008,
778 .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
783 /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
784 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
785 .driver = "Audigy2", .name = "E-mu 1212m [4001]",
790 /* Tested by James@superbug.co.uk 3rd July 2005 */
791 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
792 .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
800 /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
801 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
802 .driver = "Audigy2", .name = "Audigy 2 [2006]",
810 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
811 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
819 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
820 .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
828 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
829 .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
837 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
838 .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
845 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
846 .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
854 {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
855 .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
862 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
863 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
868 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
869 .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
875 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
876 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
881 {.vendor = 0x1102, .device = 0x0004,
882 .driver = "Audigy", .name = "Audigy 1 [Unknown]",
887 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
888 .driver = "EMU10K1", .name = "SBLive! [SB0105]",
893 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
894 .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
899 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
900 .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
905 /* Tested by Thomas Zehetbauer 27th Aug 2005 */
906 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
907 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
912 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
913 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
918 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
919 .driver = "EMU10K1", .name = "SB Live 5.1",
924 /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
925 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
926 .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
929 .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
930 * share the same IDs!
933 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
934 .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
939 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
940 .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
944 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
945 .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
950 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
951 .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
956 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
957 .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
962 /* Tested by James@superbug.co.uk 3rd July 2005 */
963 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
964 .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
969 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
970 .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
975 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
976 .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
981 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
982 .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
987 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
988 .driver = "EMU10K1", .name = "E-mu APS [4001]",
992 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
993 .driver = "EMU10K1", .name = "SBLive! [CT4620]",
998 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
999 .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
1004 {.vendor = 0x1102, .device = 0x0002,
1005 .driver = "EMU10K1", .name = "SB Live [Unknown]",
1010 { } /* terminator */
1013 int __devinit snd_emu10k1_create(struct snd_card *card,
1014 struct pci_dev * pci,
1015 unsigned short extin_mask,
1016 unsigned short extout_mask,
1017 long max_cache_bytes,
1020 struct snd_emu10k1 ** remu)
1022 struct snd_emu10k1 *emu;
1025 unsigned char revision;
1026 unsigned int silent_page;
1027 const struct snd_emu_chip_details *c;
1028 static struct snd_device_ops ops = {
1029 .dev_free = snd_emu10k1_dev_free,
1034 /* enable PCI device */
1035 if ((err = pci_enable_device(pci)) < 0)
1038 emu = kzalloc(sizeof(*emu), GFP_KERNEL);
1040 pci_disable_device(pci);
1044 spin_lock_init(&emu->reg_lock);
1045 spin_lock_init(&emu->emu_lock);
1046 spin_lock_init(&emu->voice_lock);
1047 spin_lock_init(&emu->synth_lock);
1048 spin_lock_init(&emu->memblk_lock);
1049 init_MUTEX(&emu->ptb_lock);
1050 init_MUTEX(&emu->fx8010.lock);
1051 INIT_LIST_HEAD(&emu->mapped_link_head);
1052 INIT_LIST_HEAD(&emu->mapped_order_link_head);
1056 emu->get_synth_voice = NULL;
1057 /* read revision & serial */
1058 pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
1059 emu->revision = revision;
1060 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
1061 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
1062 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);
1064 for (c = emu_chip_details; c->vendor; c++) {
1065 if (c->vendor == pci->vendor && c->device == pci->device) {
1067 if (c->subsystem && (c->subsystem == subsystem) ) {
1071 if (c->subsystem && (c->subsystem != emu->serial) )
1073 if (c->revision && c->revision != emu->revision)
1079 if (c->vendor == 0) {
1080 snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
1082 pci_disable_device(pci);
1085 emu->card_capabilities = c;
1086 if (c->subsystem && !subsystem)
1087 snd_printdd("Sound card name=%s\n", c->name);
1089 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
1090 c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
1092 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
1093 c->name, pci->vendor, pci->device, emu->serial);
1095 if (!*card->id && c->id) {
1097 strlcpy(card->id, c->id, sizeof(card->id));
1099 for (i = 0; i < snd_ecards_limit; i++) {
1100 if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
1103 if (i >= snd_ecards_limit)
1106 if (n >= SNDRV_CARDS)
1108 snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
1112 is_audigy = emu->audigy = c->emu10k2_chip;
1114 /* set the DMA transfer mask */
1115 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
1116 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
1117 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
1118 snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
1120 pci_disable_device(pci);
1124 emu->gpr_base = A_FXGPREGBASE;
1126 emu->gpr_base = FXGPREGBASE;
1128 if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
1130 pci_disable_device(pci);
1133 emu->port = pci_resource_start(pci, 0);
1135 if (request_irq(pci->irq, snd_emu10k1_interrupt, SA_INTERRUPT|SA_SHIRQ, "EMU10K1", (void *)emu)) {
1139 emu->irq = pci->irq;
1141 emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
1142 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1143 32 * 1024, &emu->ptb_pages) < 0) {
1148 emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
1149 emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
1150 if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
1155 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1156 EMUPAGESIZE, &emu->silent_page) < 0) {
1160 emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
1161 if (emu->memhdr == NULL) {
1165 emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
1166 sizeof(struct snd_util_memblk);
1168 pci_set_master(pci);
1170 emu->fx8010.fxbus_mask = 0x303f;
1171 if (extin_mask == 0)
1172 extin_mask = 0x3fcf;
1173 if (extout_mask == 0)
1174 extout_mask = 0x7fff;
1175 emu->fx8010.extin_mask = extin_mask;
1176 emu->fx8010.extout_mask = extout_mask;
1177 emu->enable_ir = enable_ir;
1179 if (emu->card_capabilities->ecard) {
1180 if ((err = snd_emu10k1_ecard_init(emu)) < 0)
1182 } else if (emu->card_capabilities->ca_cardbus_chip) {
1183 if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
1185 } else if (emu->card_capabilities->emu1212m) {
1186 if ((err = snd_emu10k1_emu1212m_init(emu)) < 0) {
1187 snd_emu10k1_free(emu);
1191 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
1192 does not support this, it shouldn't do any harm */
1193 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1196 /* initialize TRAM setup */
1197 emu->fx8010.itram_size = (16 * 1024)/2;
1198 emu->fx8010.etram_pages.area = NULL;
1199 emu->fx8010.etram_pages.bytes = 0;
1202 * Init to 0x02109204 :
1203 * Clock accuracy = 0 (1000ppm)
1204 * Sample Rate = 2 (48kHz)
1205 * Audio Channel = 1 (Left of 2)
1206 * Source Number = 0 (Unspecified)
1207 * Generation Status = 1 (Original for Cat Code 12)
1208 * Cat Code = 12 (Digital Signal Mixer)
1210 * Emphasis = 0 (None)
1211 * CP = 1 (Copyright unasserted)
1212 * AN = 0 (Audio data)
1215 emu->spdif_bits[0] = emu->spdif_bits[1] =
1216 emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1217 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1218 SPCS_GENERATIONSTATUS | 0x00001200 |
1219 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
1221 emu->reserved_page = (struct snd_emu10k1_memblk *)
1222 snd_emu10k1_synth_alloc(emu, 4096);
1223 if (emu->reserved_page)
1224 emu->reserved_page->map_locked = 1;
1226 /* Clear silent pages and set up pointers */
1227 memset(emu->silent_page.area, 0, PAGE_SIZE);
1228 silent_page = emu->silent_page.addr << 1;
1229 for (idx = 0; idx < MAXPAGES; idx++)
1230 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
1232 /* set up voice indices */
1233 for (idx = 0; idx < NUM_G; idx++) {
1234 emu->voices[idx].emu = emu;
1235 emu->voices[idx].number = idx;
1238 if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
1241 if ((err = alloc_pm_buffer(emu)) < 0)
1245 /* Initialize the effect engine */
1246 if ((err = snd_emu10k1_init_efx(emu)) < 0)
1248 snd_emu10k1_audio_enable(emu);
1250 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
1253 #ifdef CONFIG_PROC_FS
1254 snd_emu10k1_proc_init(emu);
1257 snd_card_set_dev(card, &pci->dev);
1262 snd_emu10k1_free(emu);
1267 static unsigned char saved_regs[] = {
1268 CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
1269 FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
1270 ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
1271 TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
1272 MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
1273 SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
1276 static unsigned char saved_regs_audigy[] = {
1277 A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
1278 A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
1282 static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
1286 size = ARRAY_SIZE(saved_regs);
1288 size += ARRAY_SIZE(saved_regs_audigy);
1289 emu->saved_ptr = vmalloc(4 * NUM_G * size);
1290 if (! emu->saved_ptr)
1292 if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
1294 if (emu->card_capabilities->ca0151_chip &&
1295 snd_p16v_alloc_pm_buffer(emu) < 0)
1300 static void free_pm_buffer(struct snd_emu10k1 *emu)
1302 vfree(emu->saved_ptr);
1303 snd_emu10k1_efx_free_pm_buffer(emu);
1304 if (emu->card_capabilities->ca0151_chip)
1305 snd_p16v_free_pm_buffer(emu);
1308 void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
1314 val = emu->saved_ptr;
1315 for (reg = saved_regs; *reg != 0xff; reg++)
1316 for (i = 0; i < NUM_G; i++, val++)
1317 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1319 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1320 for (i = 0; i < NUM_G; i++, val++)
1321 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1324 emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
1325 emu->saved_hcfg = inl(emu->port + HCFG);
1328 void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
1330 if (emu->card_capabilities->ecard)
1331 snd_emu10k1_ecard_init(emu);
1333 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1334 snd_emu10k1_init(emu, emu->enable_ir, 1);
1337 void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
1343 snd_emu10k1_audio_enable(emu);
1345 /* resore for spdif */
1347 outl(emu->port + A_IOCFG, emu->saved_a_iocfg);
1348 outl(emu->port + HCFG, emu->saved_hcfg);
1350 val = emu->saved_ptr;
1351 for (reg = saved_regs; *reg != 0xff; reg++)
1352 for (i = 0; i < NUM_G; i++, val++)
1353 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1355 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1356 for (i = 0; i < NUM_G; i++, val++)
1357 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1363 EXPORT_SYMBOL(snd_emu10k1_synth_alloc);
1364 EXPORT_SYMBOL(snd_emu10k1_synth_free);
1365 EXPORT_SYMBOL(snd_emu10k1_synth_bzero);
1366 EXPORT_SYMBOL(snd_emu10k1_synth_copy_from_user);
1367 EXPORT_SYMBOL(snd_emu10k1_memblk_map);
1369 EXPORT_SYMBOL(snd_emu10k1_voice_alloc);
1370 EXPORT_SYMBOL(snd_emu10k1_voice_free);
1372 EXPORT_SYMBOL(snd_emu10k1_ptr_read);
1373 EXPORT_SYMBOL(snd_emu10k1_ptr_write);