blob: 6135fc99fa5e4d91a6947124e1a8cb9d5f3b4c13 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright (c) by Jaroslav Kysela <perex@suse.cz>
3 * Creative Labs, Inc.
4 * Routines for control of EMU10K1 chips
5 *
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01006 * Copyright (c) by James Courtier-Dutton <James@superbug.co.uk>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * Added support for Audigy 2 Value.
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01008 * Added EMU 1010 support.
9 * General bug fixes and enhancements.
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 *
12 * BUGS:
13 * --
14 *
15 * TODO:
16 * --
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 *
32 */
33
34#include <sound/driver.h>
35#include <linux/delay.h>
36#include <linux/init.h>
37#include <linux/interrupt.h>
38#include <linux/pci.h>
39#include <linux/slab.h>
40#include <linux/vmalloc.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010041#include <linux/mutex.h>
42
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44#include <sound/core.h>
45#include <sound/emu10k1.h>
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +010046#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#include "p16v.h"
James Courtier-Duttone2b15f82005-11-11 23:39:05 +010048#include "tina2.h"
James Courtier-Dutton184c1e22006-12-06 15:58:02 +000049#include "p17v.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +010051
Clemens Ladisch7e0af292007-05-03 17:59:54 +020052#define HANA_FILENAME "emu/hana.fw"
53#define DOCK_FILENAME "emu/audio_dock.fw"
James Courtier-Dutton3663d842007-07-14 02:18:26 +010054#define EMU1010B_FILENAME "emu/emu1010b.fw"
55#define MICRO_DOCK_FILENAME "emu/micro_dock.fw"
Clemens Ladisch7e0af292007-05-03 17:59:54 +020056
57MODULE_FIRMWARE(HANA_FILENAME);
58MODULE_FIRMWARE(DOCK_FILENAME);
James Courtier-Dutton3663d842007-07-14 02:18:26 +010059MODULE_FIRMWARE(EMU1010B_FILENAME);
60MODULE_FIRMWARE(MICRO_DOCK_FILENAME);
Clemens Ladisch7e0af292007-05-03 17:59:54 +020061
62
Linus Torvalds1da177e2005-04-16 15:20:36 -070063/*************************************************************************
64 * EMU10K1 init / done
65 *************************************************************************/
66
Takashi Iwaieb4698f2005-11-17 14:50:13 +010067void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068{
69 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
70 snd_emu10k1_ptr_write(emu, IP, ch, 0);
71 snd_emu10k1_ptr_write(emu, VTFT, ch, 0xffff);
72 snd_emu10k1_ptr_write(emu, CVCF, ch, 0xffff);
73 snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
74 snd_emu10k1_ptr_write(emu, CPF, ch, 0);
75 snd_emu10k1_ptr_write(emu, CCR, ch, 0);
76
77 snd_emu10k1_ptr_write(emu, PSST, ch, 0);
78 snd_emu10k1_ptr_write(emu, DSL, ch, 0x10);
79 snd_emu10k1_ptr_write(emu, CCCA, ch, 0);
80 snd_emu10k1_ptr_write(emu, Z1, ch, 0);
81 snd_emu10k1_ptr_write(emu, Z2, ch, 0);
82 snd_emu10k1_ptr_write(emu, FXRT, ch, 0x32100000);
83
84 snd_emu10k1_ptr_write(emu, ATKHLDM, ch, 0);
85 snd_emu10k1_ptr_write(emu, DCYSUSM, ch, 0);
86 snd_emu10k1_ptr_write(emu, IFATN, ch, 0xffff);
87 snd_emu10k1_ptr_write(emu, PEFE, ch, 0);
88 snd_emu10k1_ptr_write(emu, FMMOD, ch, 0);
89 snd_emu10k1_ptr_write(emu, TREMFRQ, ch, 24); /* 1 Hz */
90 snd_emu10k1_ptr_write(emu, FM2FRQ2, ch, 24); /* 1 Hz */
91 snd_emu10k1_ptr_write(emu, TEMPENV, ch, 0);
92
93 /*** these are last so OFF prevents writing ***/
94 snd_emu10k1_ptr_write(emu, LFOVAL2, ch, 0);
95 snd_emu10k1_ptr_write(emu, LFOVAL1, ch, 0);
96 snd_emu10k1_ptr_write(emu, ATKHLDV, ch, 0);
97 snd_emu10k1_ptr_write(emu, ENVVOL, ch, 0);
98 snd_emu10k1_ptr_write(emu, ENVVAL, ch, 0);
99
100 /* Audigy extra stuffs */
101 if (emu->audigy) {
102 snd_emu10k1_ptr_write(emu, 0x4c, ch, 0); /* ?? */
103 snd_emu10k1_ptr_write(emu, 0x4d, ch, 0); /* ?? */
104 snd_emu10k1_ptr_write(emu, 0x4e, ch, 0); /* ?? */
105 snd_emu10k1_ptr_write(emu, 0x4f, ch, 0); /* ?? */
106 snd_emu10k1_ptr_write(emu, A_FXRT1, ch, 0x03020100);
107 snd_emu10k1_ptr_write(emu, A_FXRT2, ch, 0x3f3f3f3f);
108 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, ch, 0);
109 }
110}
111
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100112static unsigned int spi_dac_init[] = {
113 0x00ff,
114 0x02ff,
115 0x0400,
116 0x0520,
117 0x0600,
118 0x08ff,
119 0x0aff,
120 0x0cff,
121 0x0eff,
122 0x10ff,
123 0x1200,
124 0x1400,
125 0x1480,
126 0x1800,
127 0x1aff,
128 0x1cff,
129 0x1e00,
130 0x0530,
131 0x0602,
132 0x0622,
133 0x1400,
134};
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000135
136static unsigned int i2c_adc_init[][2] = {
137 { 0x17, 0x00 }, /* Reset */
138 { 0x07, 0x00 }, /* Timeout */
139 { 0x0b, 0x22 }, /* Interface control */
140 { 0x0c, 0x22 }, /* Master mode control */
141 { 0x0d, 0x08 }, /* Powerdown control */
142 { 0x0e, 0xcf }, /* Attenuation Left 0x01 = -103dB, 0xff = 24dB */
143 { 0x0f, 0xcf }, /* Attenuation Right 0.5dB steps */
144 { 0x10, 0x7b }, /* ALC Control 1 */
145 { 0x11, 0x00 }, /* ALC Control 2 */
146 { 0x12, 0x32 }, /* ALC Control 3 */
147 { 0x13, 0x00 }, /* Noise gate control */
148 { 0x14, 0xa6 }, /* Limiter control */
149 { 0x15, ADC_MUX_2 }, /* ADC Mixer control. Mic for Audigy 2 ZS Notebook */
150};
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100151
Takashi Iwai09668b42005-11-17 16:14:10 +0100152static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 unsigned int silent_page;
Takashi Iwai09668b42005-11-17 16:14:10 +0100155 int ch;
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000156 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157
158 /* disable audio and lock cache */
Takashi Iwai09668b42005-11-17 16:14:10 +0100159 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
160 emu->port + HCFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 /* reset recording buffers */
163 snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
164 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
165 snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
166 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
167 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
168 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
169
170 /* disable channel interrupt */
171 outl(0, emu->port + INTE);
172 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
173 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
174 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
175 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
176
177 if (emu->audigy){
178 /* set SPDIF bypass mode */
179 snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
180 /* enable rear left + rear right AC97 slots */
Takashi Iwai09668b42005-11-17 16:14:10 +0100181 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
182 AC97SLOT_REAR_LEFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 }
184
185 /* init envelope engine */
Takashi Iwai09668b42005-11-17 16:14:10 +0100186 for (ch = 0; ch < NUM_G; ch++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 snd_emu10k1_voice_init(emu, ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188
Takashi Iwai09668b42005-11-17 16:14:10 +0100189 snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
190 snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
191 snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Lee Revell2b637da2005-03-30 13:51:18 +0200193 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 /* Hacks for Alice3 to work independent of haP16V driver */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 //Setup SRCMulti_I2S SamplingRate
196 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
197 tmp &= 0xfffff1ff;
198 tmp |= (0x2<<9);
199 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
200
201 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
202 snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
203 /* Setup SRCMulti Input Audio Enable */
204 /* Use 0xFFFFFFFF to enable P16V sounds. */
205 snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
206
207 /* Enabled Phased (8-channel) P16V playback */
208 outl(0x0201, emu->port + HCFG2);
209 /* Set playback routing. */
James Courtier-Duttonfd9a98e2005-04-10 15:43:35 +0200210 snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 }
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200212 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /* Hacks for Alice3 to work independent of haP16V driver */
Takashi Iwai09668b42005-11-17 16:14:10 +0100214 snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 //Setup SRCMulti_I2S SamplingRate
216 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
217 tmp &= 0xfffff1ff;
218 tmp |= (0x2<<9);
219 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
220
221 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
222 outl(0x600000, emu->port + 0x20);
223 outl(0x14, emu->port + 0x24);
224
225 /* Setup SRCMulti Input Audio Enable */
226 outl(0x7b0000, emu->port + 0x20);
227 outl(0xFF000000, emu->port + 0x24);
228
229 /* Setup SPDIF Out Audio Enable */
230 /* The Audigy 2 Value has a separate SPDIF out,
231 * so no need for a mixer switch
232 */
233 outl(0x7a0000, emu->port + 0x20);
234 outl(0xFF000000, emu->port + 0x24);
235 tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
236 outl(tmp, emu->port + A_IOCFG);
237 }
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100238 if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100239 int size, n;
240
241 size = ARRAY_SIZE(spi_dac_init);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100242 for (n = 0; n < size; n++)
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100243 snd_emu10k1_spi_write(emu, spi_dac_init[n]);
244
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100245 snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
James Courtier-Duttonccadc3e2005-12-21 15:31:02 +0100246 /* Enable GPIOs
247 * GPIO0: Unknown
248 * GPIO1: Speakers-enabled.
249 * GPIO2: Unknown
250 * GPIO3: Unknown
251 * GPIO4: IEC958 Output on.
252 * GPIO5: Unknown
253 * GPIO6: Unknown
254 * GPIO7: Unknown
255 */
256 outl(0x76, emu->port + A_IOCFG); /* Windows uses 0x3f76 */
257
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100258 }
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000259 if (emu->card_capabilities->i2c_adc) { /* Audigy 2 ZS Notebook with ADC Wolfson WM8775 */
260 int size, n;
261
262 snd_emu10k1_ptr20_write(emu, P17V_I2S_SRC_SEL, 0, 0x2020205f);
263 tmp = inl(emu->port + A_IOCFG);
264 outl(tmp | 0x4, emu->port + A_IOCFG); /* Set bit 2 for mic input */
265 tmp = inl(emu->port + A_IOCFG);
266 size = ARRAY_SIZE(i2c_adc_init);
267 for (n = 0; n < size; n++)
268 snd_emu10k1_i2c_write(emu, i2c_adc_init[n][0], i2c_adc_init[n][1]);
269 for (n=0; n < 4; n++) {
270 emu->i2c_capture_volume[n][0]= 0xcf;
271 emu->i2c_capture_volume[n][1]= 0xcf;
272 }
273
274 }
275
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
278 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
279 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
280
281 silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
282 for (ch = 0; ch < NUM_G; ch++) {
283 snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
284 snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
285 }
286
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100287 if (emu->card_capabilities->emu1010) {
288 outl(HCFG_AUTOMUTE_ASYNC |
289 HCFG_EMU32_SLAVE |
290 HCFG_AUDIOENABLE, emu->port + HCFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700291 /*
292 * Hokay, setup HCFG
293 * Mute Disable Audio = 0
294 * Lock Tank Memory = 1
295 * Lock Sound Memory = 0
296 * Auto Mute = 1
297 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100298 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 if (emu->revision == 4) /* audigy2 */
300 outl(HCFG_AUDIOENABLE |
301 HCFG_AC3ENABLE_CDSPDIF |
302 HCFG_AC3ENABLE_GPSPDIF |
303 HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
304 else
305 outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200306 /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
307 * e.g. card_capabilities->joystick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 } else if (emu->model == 0x20 ||
309 emu->model == 0xc400 ||
310 (emu->model == 0x21 && emu->revision < 6))
311 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
312 else
313 // With on-chip joystick
314 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
315
316 if (enable_ir) { /* enable IR for SB Live */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100317 if (emu->card_capabilities->emu1010) {
318 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000319 } else if (emu->card_capabilities->i2c_adc) {
320 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100321 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 unsigned int reg = inl(emu->port + A_IOCFG);
323 outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
324 udelay(500);
325 outl(reg | A_IOCFG_GPOUT1 | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
326 udelay(100);
327 outl(reg, emu->port + A_IOCFG);
328 } else {
329 unsigned int reg = inl(emu->port + HCFG);
330 outl(reg | HCFG_GPOUT2, emu->port + HCFG);
331 udelay(500);
332 outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
333 udelay(100);
334 outl(reg, emu->port + HCFG);
335 }
336 }
337
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100338 if (emu->card_capabilities->emu1010) {
339 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000340 } else if (emu->card_capabilities->i2c_adc) {
341 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100342 } else if (emu->audigy) { /* enable analog output */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343 unsigned int reg = inl(emu->port + A_IOCFG);
344 outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
345 }
346
Takashi Iwai09668b42005-11-17 16:14:10 +0100347 return 0;
348}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349
Takashi Iwai09668b42005-11-17 16:14:10 +0100350static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
351{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 /*
353 * Enable the audio bit
354 */
355 outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
356
357 /* Enable analog/digital outs on audigy */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100358 if (emu->card_capabilities->emu1010) {
359 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000360 } else if (emu->card_capabilities->i2c_adc) {
361 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100362 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
364
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200365 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
367 * This has to be done after init ALice3 I2SOut beyond 48KHz.
368 * So, sequence is important. */
369 outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200370 } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Unmute Analog now. */
372 outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
373 } else {
374 /* Disable routing from AC97 line out to Front speakers */
375 outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
376 }
377 }
378
379#if 0
380 {
381 unsigned int tmp;
382 /* FIXME: the following routine disables LiveDrive-II !! */
383 // TOSLink detection
384 emu->tos_link = 0;
385 tmp = inl(emu->port + HCFG);
386 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
387 outl(tmp|0x800, emu->port + HCFG);
388 udelay(50);
389 if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
390 emu->tos_link = 1;
391 outl(tmp, emu->port + HCFG);
392 }
393 }
394 }
395#endif
396
397 snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398}
399
Takashi Iwai09668b42005-11-17 16:14:10 +0100400int snd_emu10k1_done(struct snd_emu10k1 * emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401{
402 int ch;
403
404 outl(0, emu->port + INTE);
405
406 /*
407 * Shutdown the chip
408 */
409 for (ch = 0; ch < NUM_G; ch++)
410 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
411 for (ch = 0; ch < NUM_G; ch++) {
412 snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
413 snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
414 snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
415 snd_emu10k1_ptr_write(emu, CPF, ch, 0);
416 }
417
418 /* reset recording buffers */
419 snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
420 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
421 snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
422 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
423 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
424 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
425 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
426 snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
427 snd_emu10k1_ptr_write(emu, TCB, 0, 0);
428 if (emu->audigy)
429 snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
430 else
431 snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
432
433 /* disable channel interrupt */
434 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
435 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
436 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
437 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 /* disable audio and lock cache */
440 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
441 snd_emu10k1_ptr_write(emu, PTB, 0, 0);
442
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 return 0;
444}
445
446/*************************************************************************
447 * ECARD functional implementation
448 *************************************************************************/
449
450/* In A1 Silicon, these bits are in the HC register */
451#define HOOKN_BIT (1L << 12)
452#define HANDN_BIT (1L << 11)
453#define PULSEN_BIT (1L << 10)
454
455#define EC_GDI1 (1 << 13)
456#define EC_GDI0 (1 << 14)
457
458#define EC_NUM_CONTROL_BITS 20
459
460#define EC_AC3_DATA_SELN 0x0001L
461#define EC_EE_DATA_SEL 0x0002L
462#define EC_EE_CNTRL_SELN 0x0004L
463#define EC_EECLK 0x0008L
464#define EC_EECS 0x0010L
465#define EC_EESDO 0x0020L
466#define EC_TRIM_CSN 0x0040L
467#define EC_TRIM_SCLK 0x0080L
468#define EC_TRIM_SDATA 0x0100L
469#define EC_TRIM_MUTEN 0x0200L
470#define EC_ADCCAL 0x0400L
471#define EC_ADCRSTN 0x0800L
472#define EC_DACCAL 0x1000L
473#define EC_DACMUTEN 0x2000L
474#define EC_LEDN 0x4000L
475
476#define EC_SPDIF0_SEL_SHIFT 15
477#define EC_SPDIF1_SEL_SHIFT 17
478#define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
479#define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
480#define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
481#define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
482#define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
483 * be incremented any time the EEPROM's
484 * format is changed. */
485
486#define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
487
488/* Addresses for special values stored in to EEPROM */
489#define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
490#define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
491#define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
492
493#define EC_LAST_PROMFILE_ADDR 0x2f
494
495#define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
496 * can be up to 30 characters in length
497 * and is stored as a NULL-terminated
498 * ASCII string. Any unused bytes must be
499 * filled with zeros */
500#define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
501
502
503/* Most of this stuff is pretty self-evident. According to the hardware
504 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
505 * offset problem. Weird.
506 */
507#define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
508 EC_TRIM_CSN)
509
510
511#define EC_DEFAULT_ADC_GAIN 0xC4C4
512#define EC_DEFAULT_SPDIF0_SEL 0x0
513#define EC_DEFAULT_SPDIF1_SEL 0x4
514
515/**************************************************************************
516 * @func Clock bits into the Ecard's control latch. The Ecard uses a
517 * control latch will is loaded bit-serially by toggling the Modem control
518 * lines from function 2 on the E8010. This function hides these details
519 * and presents the illusion that we are actually writing to a distinct
520 * register.
521 */
522
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100523static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524{
525 unsigned short count;
526 unsigned int data;
527 unsigned long hc_port;
528 unsigned int hc_value;
529
530 hc_port = emu->port + HCFG;
531 hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
532 outl(hc_value, hc_port);
533
534 for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
535
536 /* Set up the value */
537 data = ((value & 0x1) ? PULSEN_BIT : 0);
538 value >>= 1;
539
540 outl(hc_value | data, hc_port);
541
542 /* Clock the shift register */
543 outl(hc_value | data | HANDN_BIT, hc_port);
544 outl(hc_value | data, hc_port);
545 }
546
547 /* Latch the bits */
548 outl(hc_value | HOOKN_BIT, hc_port);
549 outl(hc_value, hc_port);
550}
551
552/**************************************************************************
553 * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
554 * trim value consists of a 16bit value which is composed of two
555 * 8 bit gain/trim values, one for the left channel and one for the
556 * right channel. The following table maps from the Gain/Attenuation
557 * value in decibels into the corresponding bit pattern for a single
558 * channel.
559 */
560
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100561static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 unsigned short gain)
563{
564 unsigned int bit;
565
566 /* Enable writing to the TRIM registers */
567 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
568
569 /* Do it again to insure that we meet hold time requirements */
570 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
571
572 for (bit = (1 << 15); bit; bit >>= 1) {
573 unsigned int value;
574
575 value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
576
577 if (gain & bit)
578 value |= EC_TRIM_SDATA;
579
580 /* Clock the bit */
581 snd_emu10k1_ecard_write(emu, value);
582 snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
583 snd_emu10k1_ecard_write(emu, value);
584 }
585
586 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
587}
588
Takashi Iwaif40b6892006-07-05 16:51:05 +0200589static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
591 unsigned int hc_value;
592
593 /* Set up the initial settings */
594 emu->ecard_ctrl = EC_RAW_RUN_MODE |
595 EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
596 EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
597
598 /* Step 0: Set the codec type in the hardware control register
599 * and enable audio output */
600 hc_value = inl(emu->port + HCFG);
601 outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
602 inl(emu->port + HCFG);
603
604 /* Step 1: Turn off the led and deassert TRIM_CS */
605 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
606
607 /* Step 2: Calibrate the ADC and DAC */
608 snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
609
610 /* Step 3: Wait for awhile; XXX We can't get away with this
611 * under a real operating system; we'll need to block and wait that
612 * way. */
613 snd_emu10k1_wait(emu, 48000);
614
615 /* Step 4: Switch off the DAC and ADC calibration. Note
616 * That ADC_CAL is actually an inverted signal, so we assert
617 * it here to stop calibration. */
618 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
619
620 /* Step 4: Switch into run mode */
621 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
622
623 /* Step 5: Set the analog input gain */
624 snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
625
626 return 0;
627}
628
Takashi Iwaif40b6892006-07-05 16:51:05 +0200629static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
James Courtier-Duttond83c6712005-10-31 10:27:41 +0000630{
631 unsigned long special_port;
632 unsigned int value;
633
634 /* Special initialisation routine
635 * before the rest of the IO-Ports become active.
636 */
637 special_port = emu->port + 0x38;
638 value = inl(special_port);
639 outl(0x00d00000, special_port);
640 value = inl(special_port);
641 outl(0x00d00001, special_port);
642 value = inl(special_port);
643 outl(0x00d0005f, special_port);
644 value = inl(special_port);
645 outl(0x00d0007f, special_port);
646 value = inl(special_port);
647 outl(0x0090007f, special_port);
648 value = inl(special_port);
649
James Courtier-Duttone2b15f82005-11-11 23:39:05 +0100650 snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
James Courtier-Duttond83c6712005-10-31 10:27:41 +0000651 return 0;
652}
653
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100654static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * filename)
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100655{
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100656 int err;
657 int n, i;
658 int reg;
659 int value;
660 const struct firmware *fw_entry;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100661
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100662 if ((err = request_firmware(&fw_entry, filename, &emu->pci->dev)) != 0) {
663 snd_printk(KERN_ERR "firmware: %s not found. Err=%d\n",filename, err);
664 return err;
665 }
Takashi Iwaibbb53552006-10-05 16:21:19 +0200666 snd_printk(KERN_INFO "firmware size=0x%zx\n", fw_entry->size);
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100667#if 0
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100668 if (fw_entry->size != 0x133a4) {
669 snd_printk(KERN_ERR "firmware: %s wrong size.\n",filename);
670 return -EINVAL;
671 }
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100672#endif
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100673
674 /* The FPGA is a Xilinx Spartan IIE XC2S50E */
675 /* GPIO7 -> FPGA PGMN
676 * GPIO6 -> FPGA CCLK
677 * GPIO5 -> FPGA DIN
678 * FPGA CONFIG OFF -> FPGA PGMN
679 */
680 outl(0x00, emu->port + A_IOCFG); /* Set PGMN low for 1uS. */
681 udelay(1);
682 outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */
683 udelay(100); /* Allow FPGA memory to clean */
684 for(n = 0; n < fw_entry->size; n++) {
685 value=fw_entry->data[n];
686 for(i = 0; i < 8; i++) {
687 reg = 0x80;
688 if (value & 0x1)
689 reg = reg | 0x20;
690 value = value >> 1;
691 outl(reg, emu->port + A_IOCFG);
692 outl(reg | 0x40, emu->port + A_IOCFG);
693 }
694 }
695 /* After programming, set GPIO bit 4 high again. */
696 outl(0x10, emu->port + A_IOCFG);
697
698
699 release_firmware(fw_entry);
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100700 return 0;
701}
702
Pavel Hofman13d45702007-06-11 12:21:20 +0200703/*
704 * EMU-1010 - details found out from this driver, official MS Win drivers,
705 * testing the card:
706 *
707 * Audigy2 (aka Alice2):
708 * ---------------------
709 * * communication over PCI
710 * * conversion of 32-bit data coming over EMU32 links from HANA FPGA
711 * to 2 x 16-bit, using internal DSP instructions
712 * * slave mode, clock supplied by HANA
713 * * linked to HANA using:
714 * 32 x 32-bit serial EMU32 output channels
715 * 16 x EMU32 input channels
716 * (?) x I2S I/O channels (?)
717 *
718 * FPGA (aka HANA):
719 * ---------------
720 * * provides all (?) physical inputs and outputs of the card
721 * (ADC, DAC, SPDIF I/O, ADAT I/O, etc.)
722 * * provides clock signal for the card and Alice2
723 * * two crystals - for 44.1kHz and 48kHz multiples
724 * * provides internal routing of signal sources to signal destinations
725 * * inputs/outputs to Alice2 - see above
726 *
727 * Current status of the driver:
728 * ----------------------------
729 * * only 44.1/48kHz supported (the MS Win driver supports up to 192 kHz)
730 * * PCM device nb. 2:
731 * 16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops
732 * 16 x 32-bit capture - snd_emu10k1_capture_efx_ops
733 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100734static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100735{
736 unsigned int i;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100737 int tmp,tmp2;
738 int reg;
739 int err;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100740
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100741 snd_printk(KERN_INFO "emu1010: Special config.\n");
742 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
743 * Lock Sound Memory Cache, Lock Tank Memory Cache,
744 * Mute all codecs.
745 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100746 outl(0x0005a00c, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100747 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
748 * Lock Tank Memory Cache,
749 * Mute all codecs.
750 */
751 outl(0x0005a004, emu->port + HCFG);
752 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
753 * Mute all codecs.
754 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100755 outl(0x0005a000, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100756 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
757 * Mute all codecs.
758 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100759 outl(0x0005a000, emu->port + HCFG);
760
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100761 /* Disable 48Volt power to Audio Dock */
762 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 );
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100763
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100764 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
765 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
766 snd_printdd("reg1=0x%x\n",reg);
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100767 if ((reg & 0x1f) == 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100768 /* FPGA netlist already present so clear it */
769 /* Return to programming mode */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100770
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100771 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02 );
772 }
773 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
774 snd_printdd("reg2=0x%x\n",reg);
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100775 if ((reg & 0x1f) == 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100776 /* FPGA failed to return to programming mode */
777 return -ENODEV;
778 }
779 snd_printk(KERN_INFO "emu1010: EMU_HANA_ID=0x%x\n",reg);
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100780 if (emu->card_capabilities->emu1010 == 1) {
781 if ((err = snd_emu1010_load_firmware(emu, HANA_FILENAME)) != 0) {
782 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file %s failed\n", HANA_FILENAME);
783 return err;
784 }
785 } else if (emu->card_capabilities->emu1010 == 2) {
786 if ((err = snd_emu1010_load_firmware(emu, EMU1010B_FILENAME)) != 0) {
787 snd_printk(KERN_INFO "emu1010: Loading Firmware file %s failed\n", EMU1010B_FILENAME);
788 return err;
789 }
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100790 }
791
792 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
793 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
James Courtier-Dutton3663d842007-07-14 02:18:26 +0100794 if ((reg & 0x1f) != 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100795 /* FPGA failed to be programmed */
796 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg=0x%x\n", reg);
797 return -ENODEV;
798 }
799
800 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
801 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp );
802 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2 );
803 snd_printk("Hana ver:%d.%d\n",tmp ,tmp2);
804 /* Enable 48Volt power to Audio Dock */
805 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON );
806
807 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
808 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
809 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
810 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
811 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp );
812 /* ADAT input. */
813 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x01 );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100814 snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100815 /* Set no attenuation on Audio Dock pads. */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100816 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00 );
817 emu->emu1010.adc_pads = 0x00;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100818 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
819 /* Unmute Audio dock DACs, Headphone source DAC-4. */
820 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
821 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100822 snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp );
823 /* DAC PADs. */
824 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f );
825 emu->emu1010.dac_pads = 0x0f;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100826 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
827 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
828 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
829 /* SPDIF Format. Set Consumer mode, 24bit, copy enable */
830 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 );
831 /* MIDI routing */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100832 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100833 /* Unknown. */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100834 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100835 /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); // IRQ Enable: All on */
836 /* IRQ Enable: All off */
837 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00 );
838
839 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
840 snd_printk(KERN_INFO "emu1010: Card options3=0x%x\n",reg);
841 /* Default WCLK set to 48kHz. */
842 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00 );
843 /* Word Clock source, Internal 48kHz x1 */
844 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
845 //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X );
846 /* Audio Dock LEDs. */
847 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
848
849#if 0
850 /* For 96kHz */
851 snd_emu1010_fpga_link_dst_src_write(emu,
852 EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
853 snd_emu1010_fpga_link_dst_src_write(emu,
854 EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
855 snd_emu1010_fpga_link_dst_src_write(emu,
856 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT2);
857 snd_emu1010_fpga_link_dst_src_write(emu,
858 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT2);
859#endif
860#if 0
861 /* For 192kHz */
862 snd_emu1010_fpga_link_dst_src_write(emu,
863 EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
864 snd_emu1010_fpga_link_dst_src_write(emu,
865 EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
866 snd_emu1010_fpga_link_dst_src_write(emu,
867 EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
868 snd_emu1010_fpga_link_dst_src_write(emu,
869 EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_RIGHT2);
870 snd_emu1010_fpga_link_dst_src_write(emu,
871 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT3);
872 snd_emu1010_fpga_link_dst_src_write(emu,
873 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT3);
874 snd_emu1010_fpga_link_dst_src_write(emu,
875 EMU_DST_ALICE2_EMU32_6, EMU_SRC_HAMOA_ADC_LEFT4);
876 snd_emu1010_fpga_link_dst_src_write(emu,
877 EMU_DST_ALICE2_EMU32_7, EMU_SRC_HAMOA_ADC_RIGHT4);
878#endif
879#if 1
880 /* For 48kHz */
881 snd_emu1010_fpga_link_dst_src_write(emu,
882 EMU_DST_ALICE2_EMU32_0, EMU_SRC_DOCK_MIC_A1);
883 snd_emu1010_fpga_link_dst_src_write(emu,
884 EMU_DST_ALICE2_EMU32_1, EMU_SRC_DOCK_MIC_B1);
885 snd_emu1010_fpga_link_dst_src_write(emu,
886 EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
887 snd_emu1010_fpga_link_dst_src_write(emu,
888 EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_LEFT2);
889 snd_emu1010_fpga_link_dst_src_write(emu,
890 EMU_DST_ALICE2_EMU32_4, EMU_SRC_DOCK_ADC1_LEFT1);
891 snd_emu1010_fpga_link_dst_src_write(emu,
892 EMU_DST_ALICE2_EMU32_5, EMU_SRC_DOCK_ADC1_RIGHT1);
893 snd_emu1010_fpga_link_dst_src_write(emu,
894 EMU_DST_ALICE2_EMU32_6, EMU_SRC_DOCK_ADC2_LEFT1);
895 snd_emu1010_fpga_link_dst_src_write(emu,
896 EMU_DST_ALICE2_EMU32_7, EMU_SRC_DOCK_ADC2_RIGHT1);
Pavel Hofman13d45702007-06-11 12:21:20 +0200897 /* Pavel Hofman - setting defaults for 8 more capture channels
898 * Defaults only, users will set their own values anyways, let's
899 * just copy/paste.
900 */
901
902 snd_emu1010_fpga_link_dst_src_write(emu,
903 EMU_DST_ALICE2_EMU32_8, EMU_SRC_DOCK_MIC_A1);
904 snd_emu1010_fpga_link_dst_src_write(emu,
905 EMU_DST_ALICE2_EMU32_9, EMU_SRC_DOCK_MIC_B1);
906 snd_emu1010_fpga_link_dst_src_write(emu,
907 EMU_DST_ALICE2_EMU32_A, EMU_SRC_HAMOA_ADC_LEFT2);
908 snd_emu1010_fpga_link_dst_src_write(emu,
909 EMU_DST_ALICE2_EMU32_B, EMU_SRC_HAMOA_ADC_LEFT2);
910 snd_emu1010_fpga_link_dst_src_write(emu,
911 EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_ADC1_LEFT1);
912 snd_emu1010_fpga_link_dst_src_write(emu,
913 EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_ADC1_RIGHT1);
914 snd_emu1010_fpga_link_dst_src_write(emu,
915 EMU_DST_ALICE2_EMU32_E, EMU_SRC_DOCK_ADC2_LEFT1);
916 snd_emu1010_fpga_link_dst_src_write(emu,
917 EMU_DST_ALICE2_EMU32_F, EMU_SRC_DOCK_ADC2_RIGHT1);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100918#endif
919#if 0
920 /* Original */
921 snd_emu1010_fpga_link_dst_src_write(emu,
922 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HANA_ADAT);
923 snd_emu1010_fpga_link_dst_src_write(emu,
924 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HANA_ADAT + 1);
925 snd_emu1010_fpga_link_dst_src_write(emu,
926 EMU_DST_ALICE2_EMU32_6, EMU_SRC_HANA_ADAT + 2);
927 snd_emu1010_fpga_link_dst_src_write(emu,
928 EMU_DST_ALICE2_EMU32_7, EMU_SRC_HANA_ADAT + 3);
929 snd_emu1010_fpga_link_dst_src_write(emu,
930 EMU_DST_ALICE2_EMU32_8, EMU_SRC_HANA_ADAT + 4);
931 snd_emu1010_fpga_link_dst_src_write(emu,
932 EMU_DST_ALICE2_EMU32_9, EMU_SRC_HANA_ADAT + 5);
933 snd_emu1010_fpga_link_dst_src_write(emu,
934 EMU_DST_ALICE2_EMU32_A, EMU_SRC_HANA_ADAT + 6);
935 snd_emu1010_fpga_link_dst_src_write(emu,
936 EMU_DST_ALICE2_EMU32_B, EMU_SRC_HANA_ADAT + 7);
937 snd_emu1010_fpga_link_dst_src_write(emu,
938 EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_MIC_A1);
939 snd_emu1010_fpga_link_dst_src_write(emu,
940 EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_MIC_B1);
941 snd_emu1010_fpga_link_dst_src_write(emu,
942 EMU_DST_ALICE2_EMU32_E, EMU_SRC_HAMOA_ADC_LEFT2);
943 snd_emu1010_fpga_link_dst_src_write(emu,
944 EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2);
945#endif
946 for (i = 0;i < 0x20; i++ ) {
947 /* AudioDock Elink <- Silence */
948 snd_emu1010_fpga_link_dst_src_write(emu, 0x0100+i, EMU_SRC_SILENCE);
949 }
950 for (i = 0;i < 4; i++) {
951 /* Hana SPDIF Out <- Silence */
952 snd_emu1010_fpga_link_dst_src_write(emu, 0x0200+i, EMU_SRC_SILENCE);
953 }
954 for (i = 0;i < 7; i++) {
955 /* Hamoa DAC <- Silence */
956 snd_emu1010_fpga_link_dst_src_write(emu, 0x0300+i, EMU_SRC_SILENCE);
957 }
958 for (i = 0;i < 7; i++) {
959 /* Hana ADAT Out <- Silence */
960 snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE);
961 }
962 snd_emu1010_fpga_link_dst_src_write(emu,
963 EMU_DST_ALICE_I2S0_LEFT, EMU_SRC_DOCK_ADC1_LEFT1);
964 snd_emu1010_fpga_link_dst_src_write(emu,
965 EMU_DST_ALICE_I2S0_RIGHT, EMU_SRC_DOCK_ADC1_RIGHT1);
966 snd_emu1010_fpga_link_dst_src_write(emu,
967 EMU_DST_ALICE_I2S1_LEFT, EMU_SRC_DOCK_ADC2_LEFT1);
968 snd_emu1010_fpga_link_dst_src_write(emu,
969 EMU_DST_ALICE_I2S1_RIGHT, EMU_SRC_DOCK_ADC2_RIGHT1);
970 snd_emu1010_fpga_link_dst_src_write(emu,
971 EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1);
972 snd_emu1010_fpga_link_dst_src_write(emu,
973 EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1);
974 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01 ); // Unmute all
975
976 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
977
978 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
979 * Lock Sound Memory Cache, Lock Tank Memory Cache,
980 * Mute all codecs.
981 */
982 outl(0x0000a000, emu->port + HCFG);
983 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
984 * Lock Sound Memory Cache, Lock Tank Memory Cache,
985 * Un-Mute all codecs.
986 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100987 outl(0x0000a001, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100988
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100989 /* Initial boot complete. Now patches */
990
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100991 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100992 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
993 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
994 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
995 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100996 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
997 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 ); /* SPDIF Format spdif (or 0x11 for aes/ebu) */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100998
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100999 /* Delay to allow Audio Dock to settle */
1000 msleep(100);
1001 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp ); /* IRQ Status */
1002 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); /* OPTIONS: Which cards are attached to the EMU */
1003 /* FIXME: The loading of this should be able to happen any time,
1004 * as the user can plug/unplug it at any time
1005 */
1006 if (reg & (EMU_HANA_OPTION_DOCK_ONLINE | EMU_HANA_OPTION_DOCK_OFFLINE) ) {
1007 /* Audio Dock attached */
1008 /* Return to Audio Dock programming mode */
1009 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
1010 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK );
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001011 if (emu->card_capabilities->emu1010 == 1) {
1012 if ((err = snd_emu1010_load_firmware(emu, DOCK_FILENAME)) != 0) {
1013 return err;
1014 }
1015 } else if (emu->card_capabilities->emu1010 == 2) {
1016 if ((err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME)) != 0) {
1017 return err;
1018 }
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001019 }
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001020
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001021 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0 );
1022 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg );
1023 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS=0x%x\n",reg);
1024 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
1025 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
1026 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID=0x%x\n",reg);
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001027 if ((reg & 0x1f) != 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001028 /* FPGA failed to be programmed */
1029 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg=0x%x\n", reg);
1030 return 0;
1031 return -ENODEV;
1032 }
James Courtier-Dutton9148cc52006-10-09 23:08:00 +01001033 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
1034 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp );
1035 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2 );
1036 snd_printk("Audio Dock ver:%d.%d\n",tmp ,tmp2);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001037 }
1038#if 0
1039 snd_emu1010_fpga_link_dst_src_write(emu,
1040 EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32B + 2); /* ALICE2 bus 0xa2 */
1041 snd_emu1010_fpga_link_dst_src_write(emu,
1042 EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32B + 3); /* ALICE2 bus 0xa3 */
1043 snd_emu1010_fpga_link_dst_src_write(emu,
1044 EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 2); /* ALICE2 bus 0xb2 */
1045 snd_emu1010_fpga_link_dst_src_write(emu,
1046 EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 3); /* ALICE2 bus 0xb3 */
1047#endif
1048 /* Default outputs */
1049 snd_emu1010_fpga_link_dst_src_write(emu,
1050 EMU_DST_DOCK_DAC1_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1051 emu->emu1010.output_source[0] = 21;
1052 snd_emu1010_fpga_link_dst_src_write(emu,
1053 EMU_DST_DOCK_DAC1_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1054 emu->emu1010.output_source[1] = 22;
1055 snd_emu1010_fpga_link_dst_src_write(emu,
1056 EMU_DST_DOCK_DAC2_LEFT1, EMU_SRC_ALICE_EMU32A + 2);
1057 emu->emu1010.output_source[2] = 23;
1058 snd_emu1010_fpga_link_dst_src_write(emu,
1059 EMU_DST_DOCK_DAC2_RIGHT1, EMU_SRC_ALICE_EMU32A + 3);
1060 emu->emu1010.output_source[3] = 24;
1061 snd_emu1010_fpga_link_dst_src_write(emu,
1062 EMU_DST_DOCK_DAC3_LEFT1, EMU_SRC_ALICE_EMU32A + 4);
1063 emu->emu1010.output_source[4] = 25;
1064 snd_emu1010_fpga_link_dst_src_write(emu,
1065 EMU_DST_DOCK_DAC3_RIGHT1, EMU_SRC_ALICE_EMU32A + 5);
1066 emu->emu1010.output_source[5] = 26;
1067 snd_emu1010_fpga_link_dst_src_write(emu,
1068 EMU_DST_DOCK_DAC4_LEFT1, EMU_SRC_ALICE_EMU32A + 6);
1069 emu->emu1010.output_source[6] = 27;
1070 snd_emu1010_fpga_link_dst_src_write(emu,
1071 EMU_DST_DOCK_DAC4_RIGHT1, EMU_SRC_ALICE_EMU32A + 7);
1072 emu->emu1010.output_source[7] = 28;
1073 snd_emu1010_fpga_link_dst_src_write(emu,
1074 EMU_DST_DOCK_PHONES_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1075 emu->emu1010.output_source[8] = 21;
1076 snd_emu1010_fpga_link_dst_src_write(emu,
1077 EMU_DST_DOCK_PHONES_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1078 emu->emu1010.output_source[9] = 22;
1079 snd_emu1010_fpga_link_dst_src_write(emu,
1080 EMU_DST_DOCK_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1081 emu->emu1010.output_source[10] = 21;
1082 snd_emu1010_fpga_link_dst_src_write(emu,
1083 EMU_DST_DOCK_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1084 emu->emu1010.output_source[11] = 22;
1085 snd_emu1010_fpga_link_dst_src_write(emu,
1086 EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1087 emu->emu1010.output_source[12] = 21;
1088 snd_emu1010_fpga_link_dst_src_write(emu,
1089 EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1090 emu->emu1010.output_source[13] = 22;
1091 snd_emu1010_fpga_link_dst_src_write(emu,
1092 EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1093 emu->emu1010.output_source[14] = 21;
1094 snd_emu1010_fpga_link_dst_src_write(emu,
1095 EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1096 emu->emu1010.output_source[15] = 22;
1097 snd_emu1010_fpga_link_dst_src_write(emu,
1098 EMU_DST_HANA_ADAT, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1099 emu->emu1010.output_source[16] = 21;
1100 snd_emu1010_fpga_link_dst_src_write(emu,
1101 EMU_DST_HANA_ADAT + 1, EMU_SRC_ALICE_EMU32A + 1);
1102 emu->emu1010.output_source[17] = 22;
1103 snd_emu1010_fpga_link_dst_src_write(emu,
1104 EMU_DST_HANA_ADAT + 2, EMU_SRC_ALICE_EMU32A + 2);
1105 emu->emu1010.output_source[18] = 23;
1106 snd_emu1010_fpga_link_dst_src_write(emu,
1107 EMU_DST_HANA_ADAT + 3, EMU_SRC_ALICE_EMU32A + 3);
1108 emu->emu1010.output_source[19] = 24;
1109 snd_emu1010_fpga_link_dst_src_write(emu,
1110 EMU_DST_HANA_ADAT + 4, EMU_SRC_ALICE_EMU32A + 4);
1111 emu->emu1010.output_source[20] = 25;
1112 snd_emu1010_fpga_link_dst_src_write(emu,
1113 EMU_DST_HANA_ADAT + 5, EMU_SRC_ALICE_EMU32A + 5);
1114 emu->emu1010.output_source[21] = 26;
1115 snd_emu1010_fpga_link_dst_src_write(emu,
1116 EMU_DST_HANA_ADAT + 6, EMU_SRC_ALICE_EMU32A + 6);
1117 emu->emu1010.output_source[22] = 27;
1118 snd_emu1010_fpga_link_dst_src_write(emu,
1119 EMU_DST_HANA_ADAT + 7, EMU_SRC_ALICE_EMU32A + 7);
1120 emu->emu1010.output_source[23] = 28;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001121
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001122 /* TEMP: Select SPDIF in/out */
1123 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); /* Output spdif */
1124
1125 /* TEMP: Select 48kHz SPDIF out */
1126 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */
1127 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */
1128 /* Word Clock source, Internal 48kHz x1 */
1129 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
1130 //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X );
James Courtier-Duttonb0dbdae2006-10-10 18:08:45 +01001131 emu->emu1010.internal_clock = 1; /* 48000 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001132 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);/* Set LEDs on Audio Dock */
1133 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */
1134 //snd_emu1010_fpga_write(emu, 0x7, 0x0); /* Mute all */
1135 //snd_emu1010_fpga_write(emu, 0x7, 0x1); /* Unmute all */
1136 //snd_emu1010_fpga_write(emu, 0xe, 0x12); /* Set LEDs on Audio Dock */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001137
1138 return 0;
1139}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001140/*
1141 * Create the EMU10K1 instance
1142 */
1143
Takashi Iwai09668b42005-11-17 16:14:10 +01001144#ifdef CONFIG_PM
1145static int alloc_pm_buffer(struct snd_emu10k1 *emu);
1146static void free_pm_buffer(struct snd_emu10k1 *emu);
1147#endif
1148
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001149static int snd_emu10k1_free(struct snd_emu10k1 *emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150{
1151 if (emu->port) { /* avoid access to already used hardware */
1152 snd_emu10k1_fx8010_tram_setup(emu, 0);
1153 snd_emu10k1_done(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001154 /* remove reserved page */
1155 if (emu->reserved_page) {
1156 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
1157 emu->reserved_page = NULL;
1158 }
1159 snd_emu10k1_free_efx(emu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001160 }
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001161 if (emu->card_capabilities->emu1010) {
1162 /* Disable 48Volt power to Audio Dock */
1163 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 );
1164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 if (emu->memhdr)
1166 snd_util_memhdr_free(emu->memhdr);
1167 if (emu->silent_page.area)
1168 snd_dma_free_pages(&emu->silent_page);
1169 if (emu->ptb_pages.area)
1170 snd_dma_free_pages(&emu->ptb_pages);
1171 vfree(emu->page_ptr_table);
1172 vfree(emu->page_addr_table);
Takashi Iwai09668b42005-11-17 16:14:10 +01001173#ifdef CONFIG_PM
1174 free_pm_buffer(emu);
1175#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (emu->irq >= 0)
Takashi Iwai437a5a42006-11-21 12:14:23 +01001177 free_irq(emu->irq, emu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001178 if (emu->port)
1179 pci_release_regions(emu->pci);
Lee Revell2b637da2005-03-30 13:51:18 +02001180 if (emu->card_capabilities->ca0151_chip) /* P16V */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 snd_p16v_free(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001182 pci_disable_device(emu->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 kfree(emu);
1184 return 0;
1185}
1186
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001187static int snd_emu10k1_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188{
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001189 struct snd_emu10k1 *emu = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190 return snd_emu10k1_free(emu);
1191}
1192
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001193static struct snd_emu_chip_details emu_chip_details[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 /* Audigy 2 Value AC3 out does not work yet. Need to find out how to turn off interpolators.*/
James Courtier-Dutton88dc0e52005-07-03 12:54:29 +02001195 /* Tested by James@superbug.co.uk 3rd July 2005 */
James Courtier-Dutton54efc962005-12-22 12:58:41 +01001196 /* DSP: CA0108-IAT
1197 * DAC: CS4382-KQ
1198 * ADC: Philips 1361T
1199 * AC97: STAC9750
1200 * CA0151: None
1201 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
1203 .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001204 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205 .emu10k2_chip = 1,
1206 .ca0108_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001207 .spk71 = 1,
1208 .ac97_chip = 1} ,
James Courtier-Dutton21fddde2006-04-09 17:36:39 +01001209 /* Audigy4 (Not PRO) SB0610 */
1210 /* Tested by James@superbug.co.uk 4th April 2006 */
1211 /* A_IOCFG bits
1212 * Output
1213 * 0: ?
1214 * 1: ?
1215 * 2: ?
1216 * 3: 0 - Digital Out, 1 - Line in
1217 * 4: ?
1218 * 5: ?
1219 * 6: ?
1220 * 7: ?
1221 * Input
1222 * 8: ?
1223 * 9: ?
1224 * A: Green jack sense (Front)
1225 * B: ?
1226 * C: Black jack sense (Rear/Side Right)
1227 * D: Yellow jack sense (Center/LFE/Side Left)
1228 * E: ?
1229 * F: ?
1230 *
1231 * Digital Out/Line in switch using A_IOCFG bit 3 (0x08)
1232 * 0 - Digital Out
1233 * 1 - Line in
1234 */
1235 /* Mic input not tested.
1236 * Analog CD input not tested
1237 * Digital Out not tested.
1238 * Line in working.
1239 * Audio output 5.1 working. Side outputs not working.
1240 */
1241 /* DSP: CA10300-IAT LF
1242 * DAC: Cirrus Logic CS4382-KQZ
1243 * ADC: Philips 1361T
1244 * AC97: Sigmatel STAC9750
1245 * CA0151: None
1246 */
1247 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
1248 .driver = "Audigy2", .name = "Audigy 4 [SB0610]",
1249 .id = "Audigy2",
1250 .emu10k2_chip = 1,
1251 .ca0108_chip = 1,
1252 .spk71 = 1,
1253 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1254 .ac97_chip = 1} ,
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001255 /* Audigy 2 ZS Notebook Cardbus card.*/
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001256 /* Tested by James@superbug.co.uk 6th November 2006 */
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001257 /* Audio output 7.1/Headphones working.
1258 * Digital output working. (AC3 not checked, only PCM)
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001259 * Audio Mic/Line inputs working.
1260 * Digital input not tested.
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001261 */
James Courtier-Dutton21fddde2006-04-09 17:36:39 +01001262 /* DSP: Tina2
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001263 * DAC: Wolfson WM8768/WM8568
1264 * ADC: Wolfson WM8775
1265 * AC97: None
1266 * CA0151: None
1267 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001268 /* Tested by James@superbug.co.uk 4th April 2006 */
1269 /* A_IOCFG bits
1270 * Output
1271 * 0: Not Used
1272 * 1: 0 = Mute all the 7.1 channel out. 1 = unmute.
1273 * 2: Analog input 0 = line in, 1 = mic in
1274 * 3: Not Used
1275 * 4: Digital output 0 = off, 1 = on.
1276 * 5: Not Used
1277 * 6: Not Used
1278 * 7: Not Used
1279 * Input
1280 * All bits 1 (0x3fxx) means nothing plugged in.
1281 * 8-9: 0 = Line in/Mic, 2 = Optical in, 3 = Nothing.
1282 * A-B: 0 = Headphones, 2 = Optical out, 3 = Nothing.
1283 * C-D: 2 = Front/Rear/etc, 3 = nothing.
1284 * E-F: Always 0
1285 *
1286 */
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001287 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
1288 .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
1289 .id = "Audigy2",
1290 .emu10k2_chip = 1,
1291 .ca0108_chip = 1,
1292 .ca_cardbus_chip = 1,
James Courtier-Dutton27fe8642005-12-21 15:06:08 +01001293 .spi_dac = 1,
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001294 .i2c_adc = 1,
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001295 .spk71 = 1} ,
James Courtier-Dutton82c8c742007-04-19 11:14:41 +01001296 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x42011102,
1297 .driver = "Audigy2", .name = "E-mu 1010 Notebook [MAEM8950]",
1298 .id = "EMU1010",
1299 .emu10k2_chip = 1,
1300 .ca0108_chip = 1,
1301 .ca_cardbus_chip = 1,
1302 .spi_dac = 1,
1303 .i2c_adc = 1,
1304 .spk71 = 1} ,
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001305 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40041102,
1306 .driver = "Audigy2", .name = "E-mu 1010b PCI [MAEM????]",
1307 .id = "EMU1010",
1308 .emu10k2_chip = 1,
1309 .ca0108_chip = 1,
1310 .spk71 = 1 ,
1311 .emu1010 = 2} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 {.vendor = 0x1102, .device = 0x0008,
1313 .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001314 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315 .emu10k2_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001316 .ca0108_chip = 1,
1317 .ac97_chip = 1} ,
James Courtier-Dutton7c1d5492005-07-10 11:50:36 +02001318 /* Tested by James@superbug.co.uk 8th July 2005. No sound available yet. */
1319 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001320 .driver = "Audigy2", .name = "E-mu 1010 [4001]",
1321 .id = "EMU1010",
James Courtier-Dutton7c1d5492005-07-10 11:50:36 +02001322 .emu10k2_chip = 1,
1323 .ca0102_chip = 1,
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001324 .spk71 = 1,
1325 .emu1010 = 1} ,
James Courtier-Dutton88dc0e52005-07-03 12:54:29 +02001326 /* Tested by James@superbug.co.uk 3rd July 2005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
1328 .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001329 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 .emu10k2_chip = 1,
1331 .ca0102_chip = 1,
1332 .ca0151_chip = 1,
1333 .spk71 = 1,
1334 .spdif_bug = 1,
1335 .ac97_chip = 1} ,
Lee Revellf6f8bb62005-11-07 14:59:19 +01001336 /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
James Courtier-Dutton5b0e4982006-04-09 22:45:58 +02001337 /* The 0x20061102 does have SB0350 written on it
1338 * Just like 0x20021102
1339 */
Lee Revellf6f8bb62005-11-07 14:59:19 +01001340 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
James Courtier-Dutton5b0e4982006-04-09 22:45:58 +02001341 .driver = "Audigy2", .name = "Audigy 2 [SB0350b]",
Lee Revellf6f8bb62005-11-07 14:59:19 +01001342 .id = "Audigy2",
1343 .emu10k2_chip = 1,
1344 .ca0102_chip = 1,
1345 .ca0151_chip = 1,
1346 .spk71 = 1,
1347 .spdif_bug = 1,
1348 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
1350 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001351 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001352 .emu10k2_chip = 1,
1353 .ca0102_chip = 1,
1354 .ca0151_chip = 1,
1355 .spk71 = 1,
1356 .spdif_bug = 1,
1357 .ac97_chip = 1} ,
1358 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
1359 .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001360 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 .emu10k2_chip = 1,
1362 .ca0102_chip = 1,
1363 .ca0151_chip = 1,
1364 .spk71 = 1,
1365 .spdif_bug = 1,
1366 .ac97_chip = 1} ,
James Courtier-Dutton54efc962005-12-22 12:58:41 +01001367 /* Audigy 2 */
1368 /* Tested by James@superbug.co.uk 3rd July 2005 */
1369 /* DSP: CA0102-IAT
1370 * DAC: CS4382-KQ
1371 * ADC: Philips 1361T
1372 * AC97: STAC9721
1373 * CA0151: Yes
1374 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
1376 .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001377 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 .emu10k2_chip = 1,
1379 .ca0102_chip = 1,
1380 .ca0151_chip = 1,
1381 .spk71 = 1,
1382 .spdif_bug = 1,
James Courtier-Dutton11b3a752006-07-08 16:39:30 +01001383 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384 .ac97_chip = 1} ,
1385 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
1386 .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001387 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 .emu10k2_chip = 1,
1389 .ca0102_chip = 1,
1390 .ca0151_chip = 1,
Lee Revell2f020aa2005-11-07 14:54:24 +01001391 .spk71 = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .spdif_bug = 1} ,
James Courtier-Dutton264f9572006-07-30 17:17:59 +01001393 /* Dell OEM/Creative Labs Audigy 2 ZS */
1394 /* See ALSA bug#1365 */
1395 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
1396 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]",
1397 .id = "Audigy2",
1398 .emu10k2_chip = 1,
1399 .ca0102_chip = 1,
1400 .ca0151_chip = 1,
1401 .spk71 = 1,
1402 .spdif_bug = 1,
1403 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
1405 .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001406 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407 .emu10k2_chip = 1,
1408 .ca0102_chip = 1,
1409 .ca0151_chip = 1,
1410 .spk71 = 1,
1411 .spdif_bug = 1,
James Courtier-Dutton3271b7b2006-11-25 22:02:47 +00001412 .adc_1361t = 1, /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 .ac97_chip = 1} ,
Takashi Iwaibdaed502005-04-07 15:48:42 +02001414 {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
1415 .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
1416 .id = "Audigy2",
1417 .emu10k2_chip = 1,
1418 .ca0102_chip = 1,
1419 .ca0151_chip = 1,
1420 .spdif_bug = 1,
1421 .ac97_chip = 1} ,
Peter Zubaj26689072005-04-01 11:15:07 +02001422 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
1423 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
1424 .id = "Audigy",
1425 .emu10k2_chip = 1,
1426 .ca0102_chip = 1,
1427 .ac97_chip = 1} ,
James Courtier-Duttonae3a72d2005-07-06 22:36:18 +02001428 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
1429 .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
1430 .id = "Audigy",
1431 .emu10k2_chip = 1,
1432 .ca0102_chip = 1,
1433 .spdif_bug = 1,
1434 .ac97_chip = 1} ,
Arnaud Patarda6c17ec2005-05-27 12:31:34 +02001435 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
1436 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
1437 .id = "Audigy",
1438 .emu10k2_chip = 1,
1439 .ca0102_chip = 1,
1440 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441 {.vendor = 0x1102, .device = 0x0004,
Takashi Iwaibdaed502005-04-07 15:48:42 +02001442 .driver = "Audigy", .name = "Audigy 1 [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001443 .id = "Audigy",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 .emu10k2_chip = 1,
1445 .ca0102_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001446 .ac97_chip = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001447 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
1448 .driver = "EMU10K1", .name = "SBLive! [SB0105]",
James Courtier-Dutton2b6b22f2005-06-18 13:50:22 +02001449 .id = "Live",
1450 .emu10k1_chip = 1,
1451 .ac97_chip = 1,
1452 .sblive51 = 1} ,
1453 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
1454 .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
1455 .id = "Live",
1456 .emu10k1_chip = 1,
1457 .ac97_chip = 1,
1458 .sblive51 = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001459 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
1460 .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
1461 .id = "Live",
1462 .emu10k1_chip = 1,
1463 .ac97_chip = 1,
1464 .sblive51 = 1} ,
James Courtier-Dutton0ba656d2005-12-26 15:30:03 +01001465 /* Tested by ALSA bug#1680 26th December 2005 */
1466 /* note: It really has SB0220 written on the card. */
1467 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
1468 .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]",
1469 .id = "Live",
1470 .emu10k1_chip = 1,
1471 .ac97_chip = 1,
1472 .sblive51 = 1} ,
Lee Revellc6c0b842005-08-29 17:42:00 +02001473 /* Tested by Thomas Zehetbauer 27th Aug 2005 */
1474 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
1475 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
1476 .id = "Live",
1477 .emu10k1_chip = 1,
1478 .ac97_chip = 1,
1479 .sblive51 = 1} ,
Gergely Tamasa8ee7292005-12-06 14:10:57 +01001480 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
1481 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
1482 .id = "Live",
1483 .emu10k1_chip = 1,
1484 .ac97_chip = 1,
1485 .sblive51 = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001486 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
1487 .driver = "EMU10K1", .name = "SB Live 5.1",
1488 .id = "Live",
1489 .emu10k1_chip = 1,
1490 .ac97_chip = 1,
1491 .sblive51 = 1} ,
James Courtier-Duttonafe0f1f2005-09-10 10:24:10 +02001492 /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001493 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
Takashi Iwaif12aa402005-09-30 16:56:59 +02001494 .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001495 .id = "Live",
1496 .emu10k1_chip = 1,
Takashi Iwaif12aa402005-09-30 16:56:59 +02001497 .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
1498 * share the same IDs!
1499 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001500 .sblive51 = 1} ,
1501 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
1502 .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
1503 .id = "Live",
1504 .emu10k1_chip = 1,
1505 .ac97_chip = 1,
1506 .sblive51 = 1} ,
1507 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
1508 .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
1509 .id = "Live",
1510 .emu10k1_chip = 1,
1511 .ac97_chip = 1} ,
1512 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
1513 .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
1514 .id = "Live",
1515 .emu10k1_chip = 1,
1516 .ac97_chip = 1,
1517 .sblive51 = 1} ,
1518 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
1519 .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
1520 .id = "Live",
1521 .emu10k1_chip = 1,
1522 .ac97_chip = 1,
1523 .sblive51 = 1} ,
1524 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
1525 .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
1526 .id = "Live",
1527 .emu10k1_chip = 1,
1528 .ac97_chip = 1,
1529 .sblive51 = 1} ,
James Courtier-Dutton88dc0e52005-07-03 12:54:29 +02001530 /* Tested by James@superbug.co.uk 3rd July 2005 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001531 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
1532 .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
1533 .id = "Live",
1534 .emu10k1_chip = 1,
1535 .ac97_chip = 1,
1536 .sblive51 = 1} ,
1537 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
1538 .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
1539 .id = "Live",
1540 .emu10k1_chip = 1,
1541 .ac97_chip = 1,
1542 .sblive51 = 1} ,
1543 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
1544 .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
1545 .id = "Live",
1546 .emu10k1_chip = 1,
1547 .ac97_chip = 1,
1548 .sblive51 = 1} ,
1549 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
1550 .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
1551 .id = "Live",
1552 .emu10k1_chip = 1,
1553 .ac97_chip = 1,
1554 .sblive51 = 1} ,
1555 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
1556 .driver = "EMU10K1", .name = "E-mu APS [4001]",
1557 .id = "APS",
1558 .emu10k1_chip = 1,
1559 .ecard = 1} ,
1560 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
1561 .driver = "EMU10K1", .name = "SBLive! [CT4620]",
1562 .id = "Live",
1563 .emu10k1_chip = 1,
1564 .ac97_chip = 1,
1565 .sblive51 = 1} ,
1566 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
1567 .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
James Courtier-Dutton2b6b22f2005-06-18 13:50:22 +02001568 .id = "Live",
1569 .emu10k1_chip = 1,
1570 .ac97_chip = 1,
1571 .sblive51 = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 {.vendor = 0x1102, .device = 0x0002,
1573 .driver = "EMU10K1", .name = "SB Live [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001574 .id = "Live",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001575 .emu10k1_chip = 1,
Lee Revell2b637da2005-03-30 13:51:18 +02001576 .ac97_chip = 1,
1577 .sblive51 = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578 { } /* terminator */
1579};
1580
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001581int __devinit snd_emu10k1_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582 struct pci_dev * pci,
1583 unsigned short extin_mask,
1584 unsigned short extout_mask,
1585 long max_cache_bytes,
1586 int enable_ir,
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001587 uint subsystem,
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001588 struct snd_emu10k1 ** remu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001590 struct snd_emu10k1 *emu;
Takashi Iwai09668b42005-11-17 16:14:10 +01001591 int idx, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592 int is_audigy;
Takashi Iwai09668b42005-11-17 16:14:10 +01001593 unsigned int silent_page;
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001594 const struct snd_emu_chip_details *c;
1595 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 .dev_free = snd_emu10k1_dev_free,
1597 };
1598
1599 *remu = NULL;
1600
1601 /* enable PCI device */
1602 if ((err = pci_enable_device(pci)) < 0)
1603 return err;
1604
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001605 emu = kzalloc(sizeof(*emu), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606 if (emu == NULL) {
1607 pci_disable_device(pci);
1608 return -ENOMEM;
1609 }
1610 emu->card = card;
1611 spin_lock_init(&emu->reg_lock);
1612 spin_lock_init(&emu->emu_lock);
1613 spin_lock_init(&emu->voice_lock);
1614 spin_lock_init(&emu->synth_lock);
1615 spin_lock_init(&emu->memblk_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01001616 mutex_init(&emu->fx8010.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 INIT_LIST_HEAD(&emu->mapped_link_head);
1618 INIT_LIST_HEAD(&emu->mapped_order_link_head);
1619 emu->pci = pci;
1620 emu->irq = -1;
1621 emu->synth = NULL;
1622 emu->get_synth_voice = NULL;
1623 /* read revision & serial */
Auke Kok44c10132007-06-08 15:46:36 -07001624 emu->revision = pci->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001625 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
1626 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 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);
1628
1629 for (c = emu_chip_details; c->vendor; c++) {
1630 if (c->vendor == pci->vendor && c->device == pci->device) {
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001631 if (subsystem) {
1632 if (c->subsystem && (c->subsystem == subsystem) ) {
1633 break;
1634 } else continue;
1635 } else {
1636 if (c->subsystem && (c->subsystem != emu->serial) )
1637 continue;
1638 if (c->revision && c->revision != emu->revision)
1639 continue;
1640 }
Takashi Iwaibdaed502005-04-07 15:48:42 +02001641 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 }
1643 }
1644 if (c->vendor == 0) {
1645 snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
1646 kfree(emu);
1647 pci_disable_device(pci);
1648 return -ENOENT;
1649 }
1650 emu->card_capabilities = c;
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001651 if (c->subsystem && !subsystem)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652 snd_printdd("Sound card name=%s\n", c->name);
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001653 else if (subsystem)
1654 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
1655 c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
1656 else
1657 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
1658 c->name, pci->vendor, pci->device, emu->serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659
Takashi Iwai85a655d2005-03-30 14:40:25 +02001660 if (!*card->id && c->id) {
1661 int i, n = 0;
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001662 strlcpy(card->id, c->id, sizeof(card->id));
Takashi Iwai85a655d2005-03-30 14:40:25 +02001663 for (;;) {
1664 for (i = 0; i < snd_ecards_limit; i++) {
1665 if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
1666 break;
1667 }
1668 if (i >= snd_ecards_limit)
1669 break;
1670 n++;
1671 if (n >= SNDRV_CARDS)
1672 break;
1673 snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
1674 }
1675 }
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001676
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 is_audigy = emu->audigy = c->emu10k2_chip;
1678
1679 /* set the DMA transfer mask */
1680 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
1681 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
1682 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
1683 snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
1684 kfree(emu);
1685 pci_disable_device(pci);
1686 return -ENXIO;
1687 }
1688 if (is_audigy)
1689 emu->gpr_base = A_FXGPREGBASE;
1690 else
1691 emu->gpr_base = FXGPREGBASE;
1692
1693 if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
1694 kfree(emu);
1695 pci_disable_device(pci);
1696 return err;
1697 }
1698 emu->port = pci_resource_start(pci, 0);
1699
Takashi Iwai437a5a42006-11-21 12:14:23 +01001700 if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_SHARED,
1701 "EMU10K1", emu)) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001702 err = -EBUSY;
1703 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 }
1705 emu->irq = pci->irq;
1706
1707 emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
1708 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1709 32 * 1024, &emu->ptb_pages) < 0) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001710 err = -ENOMEM;
1711 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713
1714 emu->page_ptr_table = (void **)vmalloc(emu->max_cache_pages * sizeof(void*));
1715 emu->page_addr_table = (unsigned long*)vmalloc(emu->max_cache_pages * sizeof(unsigned long));
1716 if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001717 err = -ENOMEM;
1718 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 }
1720
1721 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1722 EMUPAGESIZE, &emu->silent_page) < 0) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001723 err = -ENOMEM;
1724 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725 }
1726 emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
1727 if (emu->memhdr == NULL) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001728 err = -ENOMEM;
1729 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730 }
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001731 emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
1732 sizeof(struct snd_util_memblk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733
1734 pci_set_master(pci);
1735
Linus Torvalds1da177e2005-04-16 15:20:36 -07001736 emu->fx8010.fxbus_mask = 0x303f;
1737 if (extin_mask == 0)
1738 extin_mask = 0x3fcf;
1739 if (extout_mask == 0)
1740 extout_mask = 0x7fff;
1741 emu->fx8010.extin_mask = extin_mask;
1742 emu->fx8010.extout_mask = extout_mask;
Takashi Iwai09668b42005-11-17 16:14:10 +01001743 emu->enable_ir = enable_ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744
Lee Revell2b637da2005-03-30 13:51:18 +02001745 if (emu->card_capabilities->ecard) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001746 if ((err = snd_emu10k1_ecard_init(emu)) < 0)
1747 goto error;
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001748 } else if (emu->card_capabilities->ca_cardbus_chip) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001749 if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
1750 goto error;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001751 } else if (emu->card_capabilities->emu1010) {
1752 if ((err = snd_emu10k1_emu1010_init(emu)) < 0) {
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001753 snd_emu10k1_free(emu);
1754 return err;
1755 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 } else {
1757 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
1758 does not support this, it shouldn't do any harm */
1759 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1760 }
1761
Takashi Iwai09668b42005-11-17 16:14:10 +01001762 /* initialize TRAM setup */
1763 emu->fx8010.itram_size = (16 * 1024)/2;
1764 emu->fx8010.etram_pages.area = NULL;
1765 emu->fx8010.etram_pages.bytes = 0;
1766
1767 /*
1768 * Init to 0x02109204 :
1769 * Clock accuracy = 0 (1000ppm)
1770 * Sample Rate = 2 (48kHz)
1771 * Audio Channel = 1 (Left of 2)
1772 * Source Number = 0 (Unspecified)
1773 * Generation Status = 1 (Original for Cat Code 12)
1774 * Cat Code = 12 (Digital Signal Mixer)
1775 * Mode = 0 (Mode 0)
1776 * Emphasis = 0 (None)
1777 * CP = 1 (Copyright unasserted)
1778 * AN = 0 (Audio data)
1779 * P = 0 (Consumer)
1780 */
1781 emu->spdif_bits[0] = emu->spdif_bits[1] =
1782 emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1783 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1784 SPCS_GENERATIONSTATUS | 0x00001200 |
1785 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
1786
1787 emu->reserved_page = (struct snd_emu10k1_memblk *)
1788 snd_emu10k1_synth_alloc(emu, 4096);
1789 if (emu->reserved_page)
1790 emu->reserved_page->map_locked = 1;
1791
1792 /* Clear silent pages and set up pointers */
1793 memset(emu->silent_page.area, 0, PAGE_SIZE);
1794 silent_page = emu->silent_page.addr << 1;
1795 for (idx = 0; idx < MAXPAGES; idx++)
1796 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
1797
1798 /* set up voice indices */
1799 for (idx = 0; idx < NUM_G; idx++) {
1800 emu->voices[idx].emu = emu;
1801 emu->voices[idx].number = idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 }
1803
Takashi Iwai09668b42005-11-17 16:14:10 +01001804 if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
1805 goto error;
1806#ifdef CONFIG_PM
1807 if ((err = alloc_pm_buffer(emu)) < 0)
1808 goto error;
1809#endif
1810
1811 /* Initialize the effect engine */
1812 if ((err = snd_emu10k1_init_efx(emu)) < 0)
1813 goto error;
1814 snd_emu10k1_audio_enable(emu);
1815
1816 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
1817 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +01001819#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 snd_emu10k1_proc_init(emu);
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +01001821#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
1823 snd_card_set_dev(card, &pci->dev);
1824 *remu = emu;
1825 return 0;
Takashi Iwai09668b42005-11-17 16:14:10 +01001826
1827 error:
1828 snd_emu10k1_free(emu);
1829 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830}
1831
Takashi Iwai09668b42005-11-17 16:14:10 +01001832#ifdef CONFIG_PM
1833static unsigned char saved_regs[] = {
1834 CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
1835 FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
1836 ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
1837 TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
1838 MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
1839 SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
1840 0xff /* end */
1841};
1842static unsigned char saved_regs_audigy[] = {
1843 A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
1844 A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
1845 0xff /* end */
1846};
1847
1848static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
1849{
1850 int size;
1851
1852 size = ARRAY_SIZE(saved_regs);
1853 if (emu->audigy)
1854 size += ARRAY_SIZE(saved_regs_audigy);
1855 emu->saved_ptr = vmalloc(4 * NUM_G * size);
1856 if (! emu->saved_ptr)
1857 return -ENOMEM;
1858 if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
1859 return -ENOMEM;
1860 if (emu->card_capabilities->ca0151_chip &&
1861 snd_p16v_alloc_pm_buffer(emu) < 0)
1862 return -ENOMEM;
1863 return 0;
1864}
1865
1866static void free_pm_buffer(struct snd_emu10k1 *emu)
1867{
1868 vfree(emu->saved_ptr);
1869 snd_emu10k1_efx_free_pm_buffer(emu);
1870 if (emu->card_capabilities->ca0151_chip)
1871 snd_p16v_free_pm_buffer(emu);
1872}
1873
1874void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
1875{
1876 int i;
1877 unsigned char *reg;
1878 unsigned int *val;
1879
1880 val = emu->saved_ptr;
1881 for (reg = saved_regs; *reg != 0xff; reg++)
1882 for (i = 0; i < NUM_G; i++, val++)
1883 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1884 if (emu->audigy) {
1885 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1886 for (i = 0; i < NUM_G; i++, val++)
1887 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1888 }
1889 if (emu->audigy)
1890 emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
1891 emu->saved_hcfg = inl(emu->port + HCFG);
1892}
1893
1894void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
1895{
1896 if (emu->card_capabilities->ecard)
1897 snd_emu10k1_ecard_init(emu);
Takashi Iwaif40b6892006-07-05 16:51:05 +02001898 else if (emu->card_capabilities->ca_cardbus_chip)
1899 snd_emu10k1_cardbus_init(emu);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001900 else if (emu->card_capabilities->emu1010)
1901 snd_emu10k1_emu1010_init(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001902 else
1903 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1904 snd_emu10k1_init(emu, emu->enable_ir, 1);
1905}
1906
1907void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
1908{
1909 int i;
1910 unsigned char *reg;
1911 unsigned int *val;
1912
1913 snd_emu10k1_audio_enable(emu);
1914
1915 /* resore for spdif */
1916 if (emu->audigy)
Arnaud Patard4130d592006-10-04 18:21:05 +02001917 outl(emu->saved_a_iocfg, emu->port + A_IOCFG);
1918 outl(emu->saved_hcfg, emu->port + HCFG);
Takashi Iwai09668b42005-11-17 16:14:10 +01001919
1920 val = emu->saved_ptr;
1921 for (reg = saved_regs; *reg != 0xff; reg++)
1922 for (i = 0; i < NUM_G; i++, val++)
1923 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1924 if (emu->audigy) {
1925 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1926 for (i = 0; i < NUM_G; i++, val++)
1927 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1928 }
1929}
1930#endif