blob: da660676680e38d7540be8de6d552ce321c6df8e [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jaroslav Kyselac1017a42007-10-15 09:50:19 +02002 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 * 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
James Courtier-Dutton42f53222007-07-23 17:52:27 +010034#include <linux/sched.h>
35#include <linux/kthread.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <linux/delay.h>
37#include <linux/init.h>
38#include <linux/interrupt.h>
39#include <linux/pci.h>
40#include <linux/slab.h>
41#include <linux/vmalloc.h>
Ingo Molnar62932df2006-01-16 16:34:20 +010042#include <linux/mutex.h>
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
45#include <sound/core.h>
46#include <sound/emu10k1.h>
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +010047#include <linux/firmware.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#include "p16v.h"
James Courtier-Duttone2b15f82005-11-11 23:39:05 +010049#include "tina2.h"
James Courtier-Dutton184c1e22006-12-06 15:58:02 +000050#include "p17v.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +010052
Clemens Ladisch7e0af292007-05-03 17:59:54 +020053#define HANA_FILENAME "emu/hana.fw"
54#define DOCK_FILENAME "emu/audio_dock.fw"
James Courtier-Dutton3663d842007-07-14 02:18:26 +010055#define EMU1010B_FILENAME "emu/emu1010b.fw"
56#define MICRO_DOCK_FILENAME "emu/micro_dock.fw"
James Courtier-Dutton190d2c42007-11-04 14:08:26 +000057#define EMU0404_FILENAME "emu/emu0404.fw"
James Courtier-Duttond9e8a552007-07-14 10:24:49 +010058#define EMU1010_NOTEBOOK_FILENAME "emu/emu1010_notebook.fw"
Clemens Ladisch7e0af292007-05-03 17:59:54 +020059
60MODULE_FIRMWARE(HANA_FILENAME);
61MODULE_FIRMWARE(DOCK_FILENAME);
James Courtier-Dutton3663d842007-07-14 02:18:26 +010062MODULE_FIRMWARE(EMU1010B_FILENAME);
63MODULE_FIRMWARE(MICRO_DOCK_FILENAME);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +000064MODULE_FIRMWARE(EMU0404_FILENAME);
James Courtier-Duttond9e8a552007-07-14 10:24:49 +010065MODULE_FIRMWARE(EMU1010_NOTEBOOK_FILENAME);
Clemens Ladisch7e0af292007-05-03 17:59:54 +020066
67
Linus Torvalds1da177e2005-04-16 15:20:36 -070068/*************************************************************************
69 * EMU10K1 init / done
70 *************************************************************************/
71
Takashi Iwaieb4698f2005-11-17 14:50:13 +010072void snd_emu10k1_voice_init(struct snd_emu10k1 * emu, int ch)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
74 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
75 snd_emu10k1_ptr_write(emu, IP, ch, 0);
76 snd_emu10k1_ptr_write(emu, VTFT, ch, 0xffff);
77 snd_emu10k1_ptr_write(emu, CVCF, ch, 0xffff);
78 snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
79 snd_emu10k1_ptr_write(emu, CPF, ch, 0);
80 snd_emu10k1_ptr_write(emu, CCR, ch, 0);
81
82 snd_emu10k1_ptr_write(emu, PSST, ch, 0);
83 snd_emu10k1_ptr_write(emu, DSL, ch, 0x10);
84 snd_emu10k1_ptr_write(emu, CCCA, ch, 0);
85 snd_emu10k1_ptr_write(emu, Z1, ch, 0);
86 snd_emu10k1_ptr_write(emu, Z2, ch, 0);
87 snd_emu10k1_ptr_write(emu, FXRT, ch, 0x32100000);
88
89 snd_emu10k1_ptr_write(emu, ATKHLDM, ch, 0);
90 snd_emu10k1_ptr_write(emu, DCYSUSM, ch, 0);
91 snd_emu10k1_ptr_write(emu, IFATN, ch, 0xffff);
92 snd_emu10k1_ptr_write(emu, PEFE, ch, 0);
93 snd_emu10k1_ptr_write(emu, FMMOD, ch, 0);
94 snd_emu10k1_ptr_write(emu, TREMFRQ, ch, 24); /* 1 Hz */
95 snd_emu10k1_ptr_write(emu, FM2FRQ2, ch, 24); /* 1 Hz */
96 snd_emu10k1_ptr_write(emu, TEMPENV, ch, 0);
97
98 /*** these are last so OFF prevents writing ***/
99 snd_emu10k1_ptr_write(emu, LFOVAL2, ch, 0);
100 snd_emu10k1_ptr_write(emu, LFOVAL1, ch, 0);
101 snd_emu10k1_ptr_write(emu, ATKHLDV, ch, 0);
102 snd_emu10k1_ptr_write(emu, ENVVOL, ch, 0);
103 snd_emu10k1_ptr_write(emu, ENVVAL, ch, 0);
104
105 /* Audigy extra stuffs */
106 if (emu->audigy) {
107 snd_emu10k1_ptr_write(emu, 0x4c, ch, 0); /* ?? */
108 snd_emu10k1_ptr_write(emu, 0x4d, ch, 0); /* ?? */
109 snd_emu10k1_ptr_write(emu, 0x4e, ch, 0); /* ?? */
110 snd_emu10k1_ptr_write(emu, 0x4f, ch, 0); /* ?? */
111 snd_emu10k1_ptr_write(emu, A_FXRT1, ch, 0x03020100);
112 snd_emu10k1_ptr_write(emu, A_FXRT2, ch, 0x3f3f3f3f);
113 snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, ch, 0);
114 }
115}
116
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100117static unsigned int spi_dac_init[] = {
118 0x00ff,
119 0x02ff,
120 0x0400,
121 0x0520,
122 0x0600,
123 0x08ff,
124 0x0aff,
125 0x0cff,
126 0x0eff,
127 0x10ff,
128 0x1200,
129 0x1400,
130 0x1480,
131 0x1800,
132 0x1aff,
133 0x1cff,
134 0x1e00,
135 0x0530,
136 0x0602,
137 0x0622,
138 0x1400,
139};
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000140
141static unsigned int i2c_adc_init[][2] = {
142 { 0x17, 0x00 }, /* Reset */
143 { 0x07, 0x00 }, /* Timeout */
144 { 0x0b, 0x22 }, /* Interface control */
145 { 0x0c, 0x22 }, /* Master mode control */
146 { 0x0d, 0x08 }, /* Powerdown control */
147 { 0x0e, 0xcf }, /* Attenuation Left 0x01 = -103dB, 0xff = 24dB */
148 { 0x0f, 0xcf }, /* Attenuation Right 0.5dB steps */
149 { 0x10, 0x7b }, /* ALC Control 1 */
150 { 0x11, 0x00 }, /* ALC Control 2 */
151 { 0x12, 0x32 }, /* ALC Control 3 */
152 { 0x13, 0x00 }, /* Noise gate control */
153 { 0x14, 0xa6 }, /* Limiter control */
154 { 0x15, ADC_MUX_2 }, /* ADC Mixer control. Mic for Audigy 2 ZS Notebook */
155};
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100156
Takashi Iwai09668b42005-11-17 16:14:10 +0100157static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 unsigned int silent_page;
Takashi Iwai09668b42005-11-17 16:14:10 +0100160 int ch;
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000161 u32 tmp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
163 /* disable audio and lock cache */
Takashi Iwai09668b42005-11-17 16:14:10 +0100164 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE,
165 emu->port + HCFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 /* reset recording buffers */
168 snd_emu10k1_ptr_write(emu, MICBS, 0, ADCBS_BUFSIZE_NONE);
169 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
170 snd_emu10k1_ptr_write(emu, FXBS, 0, ADCBS_BUFSIZE_NONE);
171 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
172 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
173 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
174
175 /* disable channel interrupt */
176 outl(0, emu->port + INTE);
177 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
178 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
179 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
180 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
181
182 if (emu->audigy){
183 /* set SPDIF bypass mode */
184 snd_emu10k1_ptr_write(emu, SPBYPASS, 0, SPBYPASS_FORMAT);
185 /* enable rear left + rear right AC97 slots */
Takashi Iwai09668b42005-11-17 16:14:10 +0100186 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_REAR_RIGHT |
187 AC97SLOT_REAR_LEFT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 /* init envelope engine */
Takashi Iwai09668b42005-11-17 16:14:10 +0100191 for (ch = 0; ch < NUM_G; ch++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192 snd_emu10k1_voice_init(emu, ch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Takashi Iwai09668b42005-11-17 16:14:10 +0100194 snd_emu10k1_ptr_write(emu, SPCS0, 0, emu->spdif_bits[0]);
195 snd_emu10k1_ptr_write(emu, SPCS1, 0, emu->spdif_bits[1]);
196 snd_emu10k1_ptr_write(emu, SPCS2, 0, emu->spdif_bits[2]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Lee Revell2b637da2005-03-30 13:51:18 +0200198 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 /* Hacks for Alice3 to work independent of haP16V driver */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 //Setup SRCMulti_I2S SamplingRate
201 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
202 tmp &= 0xfffff1ff;
203 tmp |= (0x2<<9);
204 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
205
206 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
207 snd_emu10k1_ptr20_write(emu, SRCSel, 0, 0x14);
208 /* Setup SRCMulti Input Audio Enable */
209 /* Use 0xFFFFFFFF to enable P16V sounds. */
210 snd_emu10k1_ptr20_write(emu, SRCMULTI_ENABLE, 0, 0xFFFFFFFF);
211
212 /* Enabled Phased (8-channel) P16V playback */
213 outl(0x0201, emu->port + HCFG2);
214 /* Set playback routing. */
James Courtier-Duttonfd9a98e2005-04-10 15:43:35 +0200215 snd_emu10k1_ptr20_write(emu, CAPTURE_P16V_SOURCE, 0, 0x78e4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 }
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200217 if (emu->card_capabilities->ca0108_chip) { /* audigy2 Value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 /* Hacks for Alice3 to work independent of haP16V driver */
Takashi Iwai09668b42005-11-17 16:14:10 +0100219 snd_printk(KERN_INFO "Audigy2 value: Special config.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 //Setup SRCMulti_I2S SamplingRate
221 tmp = snd_emu10k1_ptr_read(emu, A_SPDIF_SAMPLERATE, 0);
222 tmp &= 0xfffff1ff;
223 tmp |= (0x2<<9);
224 snd_emu10k1_ptr_write(emu, A_SPDIF_SAMPLERATE, 0, tmp);
225
226 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
227 outl(0x600000, emu->port + 0x20);
228 outl(0x14, emu->port + 0x24);
229
230 /* Setup SRCMulti Input Audio Enable */
231 outl(0x7b0000, emu->port + 0x20);
232 outl(0xFF000000, emu->port + 0x24);
233
234 /* Setup SPDIF Out Audio Enable */
235 /* The Audigy 2 Value has a separate SPDIF out,
236 * so no need for a mixer switch
237 */
238 outl(0x7a0000, emu->port + 0x20);
239 outl(0xFF000000, emu->port + 0x24);
240 tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
241 outl(tmp, emu->port + A_IOCFG);
242 }
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100243 if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100244 int size, n;
245
246 size = ARRAY_SIZE(spi_dac_init);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100247 for (n = 0; n < size; n++)
James Courtier-Dutton18f3c592005-12-21 22:05:29 +0100248 snd_emu10k1_spi_write(emu, spi_dac_init[n]);
249
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100250 snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
James Courtier-Duttonccadc3e2005-12-21 15:31:02 +0100251 /* Enable GPIOs
252 * GPIO0: Unknown
253 * GPIO1: Speakers-enabled.
254 * GPIO2: Unknown
255 * GPIO3: Unknown
256 * GPIO4: IEC958 Output on.
257 * GPIO5: Unknown
258 * GPIO6: Unknown
259 * GPIO7: Unknown
260 */
261 outl(0x76, emu->port + A_IOCFG); /* Windows uses 0x3f76 */
262
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100263 }
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000264 if (emu->card_capabilities->i2c_adc) { /* Audigy 2 ZS Notebook with ADC Wolfson WM8775 */
265 int size, n;
266
267 snd_emu10k1_ptr20_write(emu, P17V_I2S_SRC_SEL, 0, 0x2020205f);
268 tmp = inl(emu->port + A_IOCFG);
269 outl(tmp | 0x4, emu->port + A_IOCFG); /* Set bit 2 for mic input */
270 tmp = inl(emu->port + A_IOCFG);
271 size = ARRAY_SIZE(i2c_adc_init);
272 for (n = 0; n < size; n++)
273 snd_emu10k1_i2c_write(emu, i2c_adc_init[n][0], i2c_adc_init[n][1]);
274 for (n=0; n < 4; n++) {
275 emu->i2c_capture_volume[n][0]= 0xcf;
276 emu->i2c_capture_volume[n][1]= 0xcf;
277 }
278
279 }
280
James Courtier-Dutton27fe8642005-12-21 15:06:08 +0100281
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
283 snd_emu10k1_ptr_write(emu, TCB, 0, 0); /* taken from original driver */
284 snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
285
286 silent_page = (emu->silent_page.addr << 1) | MAP_PTI_MASK;
287 for (ch = 0; ch < NUM_G; ch++) {
288 snd_emu10k1_ptr_write(emu, MAPA, ch, silent_page);
289 snd_emu10k1_ptr_write(emu, MAPB, ch, silent_page);
290 }
291
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000292 if (emu->card_capabilities->emu_model) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100293 outl(HCFG_AUTOMUTE_ASYNC |
294 HCFG_EMU32_SLAVE |
295 HCFG_AUDIOENABLE, emu->port + HCFG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 /*
297 * Hokay, setup HCFG
298 * Mute Disable Audio = 0
299 * Lock Tank Memory = 1
300 * Lock Sound Memory = 0
301 * Auto Mute = 1
302 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100303 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 if (emu->revision == 4) /* audigy2 */
305 outl(HCFG_AUDIOENABLE |
306 HCFG_AC3ENABLE_CDSPDIF |
307 HCFG_AC3ENABLE_GPSPDIF |
308 HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
309 else
310 outl(HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200311 /* FIXME: Remove all these emu->model and replace it with a card recognition parameter,
312 * e.g. card_capabilities->joystick */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313 } else if (emu->model == 0x20 ||
314 emu->model == 0xc400 ||
315 (emu->model == 0x21 && emu->revision < 6))
316 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE, emu->port + HCFG);
317 else
318 // With on-chip joystick
319 outl(HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE, emu->port + HCFG);
320
321 if (enable_ir) { /* enable IR for SB Live */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000322 if (emu->card_capabilities->emu_model) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100323 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000324 } else if (emu->card_capabilities->i2c_adc) {
325 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100326 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 unsigned int reg = inl(emu->port + A_IOCFG);
328 outl(reg | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
329 udelay(500);
330 outl(reg | A_IOCFG_GPOUT1 | A_IOCFG_GPOUT2, emu->port + A_IOCFG);
331 udelay(100);
332 outl(reg, emu->port + A_IOCFG);
333 } else {
334 unsigned int reg = inl(emu->port + HCFG);
335 outl(reg | HCFG_GPOUT2, emu->port + HCFG);
336 udelay(500);
337 outl(reg | HCFG_GPOUT1 | HCFG_GPOUT2, emu->port + HCFG);
338 udelay(100);
339 outl(reg, emu->port + HCFG);
340 }
341 }
342
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000343 if (emu->card_capabilities->emu_model) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100344 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000345 } else if (emu->card_capabilities->i2c_adc) {
346 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100347 } else if (emu->audigy) { /* enable analog output */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 unsigned int reg = inl(emu->port + A_IOCFG);
349 outl(reg | A_IOCFG_GPOUT0, emu->port + A_IOCFG);
350 }
351
Takashi Iwai09668b42005-11-17 16:14:10 +0100352 return 0;
353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Takashi Iwai09668b42005-11-17 16:14:10 +0100355static void snd_emu10k1_audio_enable(struct snd_emu10k1 *emu)
356{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 /*
358 * Enable the audio bit
359 */
360 outl(inl(emu->port + HCFG) | HCFG_AUDIOENABLE, emu->port + HCFG);
361
362 /* Enable analog/digital outs on audigy */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000363 if (emu->card_capabilities->emu_model) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100364 ; /* Disable all access to A_IOCFG for the emu1010 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +0000365 } else if (emu->card_capabilities->i2c_adc) {
366 ; /* Disable A_IOCFG for Audigy 2 ZS Notebook */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100367 } else if (emu->audigy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 outl(inl(emu->port + A_IOCFG) & ~0x44, emu->port + A_IOCFG);
369
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200370 if (emu->card_capabilities->ca0151_chip) { /* audigy2 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
372 * This has to be done after init ALice3 I2SOut beyond 48KHz.
373 * So, sequence is important. */
374 outl(inl(emu->port + A_IOCFG) | 0x0040, emu->port + A_IOCFG);
James Courtier-Duttone0474e52005-07-02 16:33:34 +0200375 } else if (emu->card_capabilities->ca0108_chip) { /* audigy2 value */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 /* Unmute Analog now. */
377 outl(inl(emu->port + A_IOCFG) | 0x0060, emu->port + A_IOCFG);
378 } else {
379 /* Disable routing from AC97 line out to Front speakers */
380 outl(inl(emu->port + A_IOCFG) | 0x0080, emu->port + A_IOCFG);
381 }
382 }
383
384#if 0
385 {
386 unsigned int tmp;
387 /* FIXME: the following routine disables LiveDrive-II !! */
388 // TOSLink detection
389 emu->tos_link = 0;
390 tmp = inl(emu->port + HCFG);
391 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
392 outl(tmp|0x800, emu->port + HCFG);
393 udelay(50);
394 if (tmp != (inl(emu->port + HCFG) & ~0x800)) {
395 emu->tos_link = 1;
396 outl(tmp, emu->port + HCFG);
397 }
398 }
399 }
400#endif
401
402 snd_emu10k1_intr_enable(emu, INTE_PCIERRORENABLE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403}
404
Takashi Iwai09668b42005-11-17 16:14:10 +0100405int snd_emu10k1_done(struct snd_emu10k1 * emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406{
407 int ch;
408
409 outl(0, emu->port + INTE);
410
411 /*
412 * Shutdown the chip
413 */
414 for (ch = 0; ch < NUM_G; ch++)
415 snd_emu10k1_ptr_write(emu, DCYSUSV, ch, 0);
416 for (ch = 0; ch < NUM_G; ch++) {
417 snd_emu10k1_ptr_write(emu, VTFT, ch, 0);
418 snd_emu10k1_ptr_write(emu, CVCF, ch, 0);
419 snd_emu10k1_ptr_write(emu, PTRX, ch, 0);
420 snd_emu10k1_ptr_write(emu, CPF, ch, 0);
421 }
422
423 /* reset recording buffers */
424 snd_emu10k1_ptr_write(emu, MICBS, 0, 0);
425 snd_emu10k1_ptr_write(emu, MICBA, 0, 0);
426 snd_emu10k1_ptr_write(emu, FXBS, 0, 0);
427 snd_emu10k1_ptr_write(emu, FXBA, 0, 0);
428 snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
429 snd_emu10k1_ptr_write(emu, ADCBS, 0, ADCBS_BUFSIZE_NONE);
430 snd_emu10k1_ptr_write(emu, ADCBA, 0, 0);
431 snd_emu10k1_ptr_write(emu, TCBS, 0, TCBS_BUFFSIZE_16K);
432 snd_emu10k1_ptr_write(emu, TCB, 0, 0);
433 if (emu->audigy)
434 snd_emu10k1_ptr_write(emu, A_DBG, 0, A_DBG_SINGLE_STEP);
435 else
436 snd_emu10k1_ptr_write(emu, DBG, 0, EMU10K1_DBG_SINGLE_STEP);
437
438 /* disable channel interrupt */
439 snd_emu10k1_ptr_write(emu, CLIEL, 0, 0);
440 snd_emu10k1_ptr_write(emu, CLIEH, 0, 0);
441 snd_emu10k1_ptr_write(emu, SOLEL, 0, 0);
442 snd_emu10k1_ptr_write(emu, SOLEH, 0, 0);
443
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444 /* disable audio and lock cache */
445 outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE, emu->port + HCFG);
446 snd_emu10k1_ptr_write(emu, PTB, 0, 0);
447
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448 return 0;
449}
450
451/*************************************************************************
452 * ECARD functional implementation
453 *************************************************************************/
454
455/* In A1 Silicon, these bits are in the HC register */
456#define HOOKN_BIT (1L << 12)
457#define HANDN_BIT (1L << 11)
458#define PULSEN_BIT (1L << 10)
459
460#define EC_GDI1 (1 << 13)
461#define EC_GDI0 (1 << 14)
462
463#define EC_NUM_CONTROL_BITS 20
464
465#define EC_AC3_DATA_SELN 0x0001L
466#define EC_EE_DATA_SEL 0x0002L
467#define EC_EE_CNTRL_SELN 0x0004L
468#define EC_EECLK 0x0008L
469#define EC_EECS 0x0010L
470#define EC_EESDO 0x0020L
471#define EC_TRIM_CSN 0x0040L
472#define EC_TRIM_SCLK 0x0080L
473#define EC_TRIM_SDATA 0x0100L
474#define EC_TRIM_MUTEN 0x0200L
475#define EC_ADCCAL 0x0400L
476#define EC_ADCRSTN 0x0800L
477#define EC_DACCAL 0x1000L
478#define EC_DACMUTEN 0x2000L
479#define EC_LEDN 0x4000L
480
481#define EC_SPDIF0_SEL_SHIFT 15
482#define EC_SPDIF1_SEL_SHIFT 17
483#define EC_SPDIF0_SEL_MASK (0x3L << EC_SPDIF0_SEL_SHIFT)
484#define EC_SPDIF1_SEL_MASK (0x7L << EC_SPDIF1_SEL_SHIFT)
485#define EC_SPDIF0_SELECT(_x) (((_x) << EC_SPDIF0_SEL_SHIFT) & EC_SPDIF0_SEL_MASK)
486#define EC_SPDIF1_SELECT(_x) (((_x) << EC_SPDIF1_SEL_SHIFT) & EC_SPDIF1_SEL_MASK)
487#define EC_CURRENT_PROM_VERSION 0x01 /* Self-explanatory. This should
488 * be incremented any time the EEPROM's
489 * format is changed. */
490
491#define EC_EEPROM_SIZE 0x40 /* ECARD EEPROM has 64 16-bit words */
492
493/* Addresses for special values stored in to EEPROM */
494#define EC_PROM_VERSION_ADDR 0x20 /* Address of the current prom version */
495#define EC_BOARDREV0_ADDR 0x21 /* LSW of board rev */
496#define EC_BOARDREV1_ADDR 0x22 /* MSW of board rev */
497
498#define EC_LAST_PROMFILE_ADDR 0x2f
499
500#define EC_SERIALNUM_ADDR 0x30 /* First word of serial number. The
501 * can be up to 30 characters in length
502 * and is stored as a NULL-terminated
503 * ASCII string. Any unused bytes must be
504 * filled with zeros */
505#define EC_CHECKSUM_ADDR 0x3f /* Location at which checksum is stored */
506
507
508/* Most of this stuff is pretty self-evident. According to the hardware
509 * dudes, we need to leave the ADCCAL bit low in order to avoid a DC
510 * offset problem. Weird.
511 */
512#define EC_RAW_RUN_MODE (EC_DACMUTEN | EC_ADCRSTN | EC_TRIM_MUTEN | \
513 EC_TRIM_CSN)
514
515
516#define EC_DEFAULT_ADC_GAIN 0xC4C4
517#define EC_DEFAULT_SPDIF0_SEL 0x0
518#define EC_DEFAULT_SPDIF1_SEL 0x4
519
520/**************************************************************************
521 * @func Clock bits into the Ecard's control latch. The Ecard uses a
522 * control latch will is loaded bit-serially by toggling the Modem control
523 * lines from function 2 on the E8010. This function hides these details
524 * and presents the illusion that we are actually writing to a distinct
525 * register.
526 */
527
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100528static void snd_emu10k1_ecard_write(struct snd_emu10k1 * emu, unsigned int value)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529{
530 unsigned short count;
531 unsigned int data;
532 unsigned long hc_port;
533 unsigned int hc_value;
534
535 hc_port = emu->port + HCFG;
536 hc_value = inl(hc_port) & ~(HOOKN_BIT | HANDN_BIT | PULSEN_BIT);
537 outl(hc_value, hc_port);
538
539 for (count = 0; count < EC_NUM_CONTROL_BITS; count++) {
540
541 /* Set up the value */
542 data = ((value & 0x1) ? PULSEN_BIT : 0);
543 value >>= 1;
544
545 outl(hc_value | data, hc_port);
546
547 /* Clock the shift register */
548 outl(hc_value | data | HANDN_BIT, hc_port);
549 outl(hc_value | data, hc_port);
550 }
551
552 /* Latch the bits */
553 outl(hc_value | HOOKN_BIT, hc_port);
554 outl(hc_value, hc_port);
555}
556
557/**************************************************************************
558 * @func Set the gain of the ECARD's CS3310 Trim/gain controller. The
559 * trim value consists of a 16bit value which is composed of two
560 * 8 bit gain/trim values, one for the left channel and one for the
561 * right channel. The following table maps from the Gain/Attenuation
562 * value in decibels into the corresponding bit pattern for a single
563 * channel.
564 */
565
Takashi Iwaieb4698f2005-11-17 14:50:13 +0100566static void snd_emu10k1_ecard_setadcgain(struct snd_emu10k1 * emu,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567 unsigned short gain)
568{
569 unsigned int bit;
570
571 /* Enable writing to the TRIM registers */
572 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
573
574 /* Do it again to insure that we meet hold time requirements */
575 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl & ~EC_TRIM_CSN);
576
577 for (bit = (1 << 15); bit; bit >>= 1) {
578 unsigned int value;
579
580 value = emu->ecard_ctrl & ~(EC_TRIM_CSN | EC_TRIM_SDATA);
581
582 if (gain & bit)
583 value |= EC_TRIM_SDATA;
584
585 /* Clock the bit */
586 snd_emu10k1_ecard_write(emu, value);
587 snd_emu10k1_ecard_write(emu, value | EC_TRIM_SCLK);
588 snd_emu10k1_ecard_write(emu, value);
589 }
590
591 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
592}
593
Takashi Iwaif40b6892006-07-05 16:51:05 +0200594static int snd_emu10k1_ecard_init(struct snd_emu10k1 * emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595{
596 unsigned int hc_value;
597
598 /* Set up the initial settings */
599 emu->ecard_ctrl = EC_RAW_RUN_MODE |
600 EC_SPDIF0_SELECT(EC_DEFAULT_SPDIF0_SEL) |
601 EC_SPDIF1_SELECT(EC_DEFAULT_SPDIF1_SEL);
602
603 /* Step 0: Set the codec type in the hardware control register
604 * and enable audio output */
605 hc_value = inl(emu->port + HCFG);
606 outl(hc_value | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S, emu->port + HCFG);
607 inl(emu->port + HCFG);
608
609 /* Step 1: Turn off the led and deassert TRIM_CS */
610 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
611
612 /* Step 2: Calibrate the ADC and DAC */
613 snd_emu10k1_ecard_write(emu, EC_DACCAL | EC_LEDN | EC_TRIM_CSN);
614
615 /* Step 3: Wait for awhile; XXX We can't get away with this
616 * under a real operating system; we'll need to block and wait that
617 * way. */
618 snd_emu10k1_wait(emu, 48000);
619
620 /* Step 4: Switch off the DAC and ADC calibration. Note
621 * That ADC_CAL is actually an inverted signal, so we assert
622 * it here to stop calibration. */
623 snd_emu10k1_ecard_write(emu, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
624
625 /* Step 4: Switch into run mode */
626 snd_emu10k1_ecard_write(emu, emu->ecard_ctrl);
627
628 /* Step 5: Set the analog input gain */
629 snd_emu10k1_ecard_setadcgain(emu, EC_DEFAULT_ADC_GAIN);
630
631 return 0;
632}
633
Takashi Iwaif40b6892006-07-05 16:51:05 +0200634static int snd_emu10k1_cardbus_init(struct snd_emu10k1 * emu)
James Courtier-Duttond83c6712005-10-31 10:27:41 +0000635{
636 unsigned long special_port;
637 unsigned int value;
638
639 /* Special initialisation routine
640 * before the rest of the IO-Ports become active.
641 */
642 special_port = emu->port + 0x38;
643 value = inl(special_port);
644 outl(0x00d00000, special_port);
645 value = inl(special_port);
646 outl(0x00d00001, special_port);
647 value = inl(special_port);
648 outl(0x00d0005f, special_port);
649 value = inl(special_port);
650 outl(0x00d0007f, special_port);
651 value = inl(special_port);
652 outl(0x0090007f, special_port);
653 value = inl(special_port);
654
James Courtier-Duttone2b15f82005-11-11 23:39:05 +0100655 snd_emu10k1_ptr20_write(emu, TINA2_VOLUME, 0, 0xfefefefe); /* Defaults to 0x30303030 */
James Courtier-Duttond83c6712005-10-31 10:27:41 +0000656 return 0;
657}
658
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100659static int snd_emu1010_load_firmware(struct snd_emu10k1 * emu, const char * filename)
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100660{
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100661 int err;
662 int n, i;
663 int reg;
664 int value;
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000665 unsigned int write_post;
666 unsigned long flags;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100667 const struct firmware *fw_entry;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100668
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100669 if ((err = request_firmware(&fw_entry, filename, &emu->pci->dev)) != 0) {
670 snd_printk(KERN_ERR "firmware: %s not found. Err=%d\n",filename, err);
671 return err;
672 }
Takashi Iwaibbb53552006-10-05 16:21:19 +0200673 snd_printk(KERN_INFO "firmware size=0x%zx\n", fw_entry->size);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100674
675 /* The FPGA is a Xilinx Spartan IIE XC2S50E */
676 /* GPIO7 -> FPGA PGMN
677 * GPIO6 -> FPGA CCLK
678 * GPIO5 -> FPGA DIN
679 * FPGA CONFIG OFF -> FPGA PGMN
680 */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000681 spin_lock_irqsave(&emu->emu_lock, flags);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100682 outl(0x00, emu->port + A_IOCFG); /* Set PGMN low for 1uS. */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000683 write_post = inl(emu->port + A_IOCFG);
684 udelay(100);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100685 outl(0x80, emu->port + A_IOCFG); /* Leave bit 7 set during netlist setup. */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000686 write_post = inl(emu->port + A_IOCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100687 udelay(100); /* Allow FPGA memory to clean */
688 for(n = 0; n < fw_entry->size; n++) {
689 value=fw_entry->data[n];
690 for(i = 0; i < 8; i++) {
691 reg = 0x80;
692 if (value & 0x1)
693 reg = reg | 0x20;
694 value = value >> 1;
695 outl(reg, emu->port + A_IOCFG);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000696 write_post = inl(emu->port + A_IOCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100697 outl(reg | 0x40, emu->port + A_IOCFG);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000698 write_post = inl(emu->port + A_IOCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100699 }
700 }
701 /* After programming, set GPIO bit 4 high again. */
702 outl(0x10, emu->port + A_IOCFG);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000703 write_post = inl(emu->port + A_IOCFG);
704 spin_unlock_irqrestore(&emu->emu_lock, flags);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100705
706 release_firmware(fw_entry);
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100707 return 0;
708}
709
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100710int emu1010_firmware_thread(void *data) {
711 struct snd_emu10k1 * emu = data;
712 int tmp,tmp2;
713 int reg;
714 int err;
715
716 for (;;) {
717 /* Delay to allow Audio Dock to settle */
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000718 msleep_interruptible(1000);
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100719 if (kthread_should_stop())
720 break;
721 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &tmp ); /* IRQ Status */
722 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg ); /* OPTIONS: Which cards are attached to the EMU */
723 if (reg & EMU_HANA_OPTION_DOCK_OFFLINE) {
724 /* Audio Dock attached */
725 /* Return to Audio Dock programming mode */
726 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware\n");
727 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, EMU_HANA_FPGA_CONFIG_AUDIODOCK );
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000728 if (emu->card_capabilities->emu_model == 1) {
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100729 if ((err = snd_emu1010_load_firmware(emu, DOCK_FILENAME)) != 0) {
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000730 continue;
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100731 }
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000732 } else if (emu->card_capabilities->emu_model == 2) {
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100733 if ((err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME)) != 0) {
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000734 continue;
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100735 }
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000736 } else if (emu->card_capabilities->emu_model == 3) {
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100737 if ((err = snd_emu1010_load_firmware(emu, MICRO_DOCK_FILENAME)) != 0) {
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000738 continue;
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100739 }
740 }
741
742 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0 );
743 snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &reg );
744 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_IRQ_STATUS=0x%x\n",reg);
745 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
746 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
747 snd_printk(KERN_INFO "emu1010: EMU_HANA+DOCK_ID=0x%x\n",reg);
748 if ((reg & 0x1f) != 0x15) {
749 /* FPGA failed to be programmed */
750 snd_printk(KERN_INFO "emu1010: Loading Audio Dock Firmware file failed, reg=0x%x\n", reg);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000751 continue;
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100752 }
753 snd_printk(KERN_INFO "emu1010: Audio Dock Firmware loaded\n");
754 snd_emu1010_fpga_read(emu, EMU_DOCK_MAJOR_REV, &tmp );
755 snd_emu1010_fpga_read(emu, EMU_DOCK_MINOR_REV, &tmp2 );
756 snd_printk("Audio Dock ver:%d.%d\n",tmp ,tmp2);
James Courtier-Duttonc93d1c22007-07-26 18:44:49 +0100757 /* Sync clocking between 1010 and Dock */
758 /* Allow DLL to settle */
759 msleep(10);
760 /* Unmute all. Default is muted after a firmware load */
761 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE );
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100762 }
763 }
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000764 snd_printk(KERN_INFO "emu1010: firmware thread stopping\n");
James Courtier-Dutton42f53222007-07-23 17:52:27 +0100765 return 0;
766}
767
Pavel Hofman13d45702007-06-11 12:21:20 +0200768/*
769 * EMU-1010 - details found out from this driver, official MS Win drivers,
770 * testing the card:
771 *
772 * Audigy2 (aka Alice2):
773 * ---------------------
774 * * communication over PCI
775 * * conversion of 32-bit data coming over EMU32 links from HANA FPGA
776 * to 2 x 16-bit, using internal DSP instructions
777 * * slave mode, clock supplied by HANA
778 * * linked to HANA using:
779 * 32 x 32-bit serial EMU32 output channels
780 * 16 x EMU32 input channels
781 * (?) x I2S I/O channels (?)
782 *
783 * FPGA (aka HANA):
784 * ---------------
785 * * provides all (?) physical inputs and outputs of the card
786 * (ADC, DAC, SPDIF I/O, ADAT I/O, etc.)
787 * * provides clock signal for the card and Alice2
788 * * two crystals - for 44.1kHz and 48kHz multiples
789 * * provides internal routing of signal sources to signal destinations
790 * * inputs/outputs to Alice2 - see above
791 *
792 * Current status of the driver:
793 * ----------------------------
794 * * only 44.1/48kHz supported (the MS Win driver supports up to 192 kHz)
795 * * PCM device nb. 2:
796 * 16 x 16-bit playback - snd_emu10k1_fx8010_playback_ops
797 * 16 x 32-bit capture - snd_emu10k1_capture_efx_ops
798 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100799static int snd_emu10k1_emu1010_init(struct snd_emu10k1 * emu)
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100800{
801 unsigned int i;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100802 int tmp,tmp2;
803 int reg;
804 int err;
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000805 const char *filename = NULL;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100806
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100807 snd_printk(KERN_INFO "emu1010: Special config.\n");
808 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
809 * Lock Sound Memory Cache, Lock Tank Memory Cache,
810 * Mute all codecs.
811 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100812 outl(0x0005a00c, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100813 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
814 * Lock Tank Memory Cache,
815 * Mute all codecs.
816 */
817 outl(0x0005a004, emu->port + HCFG);
818 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
819 * Mute all codecs.
820 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100821 outl(0x0005a000, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100822 /* AC97 2.1, Any 16Meg of 4Gig address, Auto-Mute, EMU32 Slave,
823 * Mute all codecs.
824 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100825 outl(0x0005a000, emu->port + HCFG);
826
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100827 /* Disable 48Volt power to Audio Dock */
828 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 );
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100829
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100830 /* ID, should read & 0x7f = 0x55. (Bit 7 is the IRQ bit) */
831 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
832 snd_printdd("reg1=0x%x\n",reg);
James Courtier-Duttond9e8a552007-07-14 10:24:49 +0100833 if ((reg & 0x3f) == 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100834 /* FPGA netlist already present so clear it */
835 /* Return to programming mode */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +0100836
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100837 snd_emu1010_fpga_write(emu, EMU_HANA_FPGA_CONFIG, 0x02 );
838 }
839 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
840 snd_printdd("reg2=0x%x\n",reg);
James Courtier-Duttond9e8a552007-07-14 10:24:49 +0100841 if ((reg & 0x3f) == 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100842 /* FPGA failed to return to programming mode */
James Courtier-Duttond9e8a552007-07-14 10:24:49 +0100843 snd_printk(KERN_INFO "emu1010: FPGA failed to return to programming mode\n");
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100844 return -ENODEV;
845 }
846 snd_printk(KERN_INFO "emu1010: EMU_HANA_ID=0x%x\n",reg);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +0000847 switch (emu->card_capabilities->emu_model) {
848 case 1:
849 filename = HANA_FILENAME;
850 break;
851 case 2:
852 filename = EMU1010B_FILENAME;
853 break;
854 case 3:
855 filename = EMU1010_NOTEBOOK_FILENAME;
856 break;
857 case 4:
858 filename = EMU0404_FILENAME;
859 break;
860 default:
861 filename = NULL;
862 return -ENODEV;
863 break;
864 }
865 snd_printk(KERN_INFO "emu1010: filename %s testing\n", filename);
866 err = snd_emu1010_load_firmware(emu, filename);
867 if (err != 0) {
868 snd_printk(
869 KERN_INFO "emu1010: Loading Firmware file %s failed\n",
870 filename);
871 return err;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100872 }
873
874 /* ID, should read & 0x7f = 0x55 when FPGA programmed. */
875 snd_emu1010_fpga_read(emu, EMU_HANA_ID, &reg );
James Courtier-Duttond9e8a552007-07-14 10:24:49 +0100876 if ((reg & 0x3f) != 0x15) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100877 /* FPGA failed to be programmed */
878 snd_printk(KERN_INFO "emu1010: Loading Hana Firmware file failed, reg=0x%x\n", reg);
879 return -ENODEV;
880 }
881
882 snd_printk(KERN_INFO "emu1010: Hana Firmware loaded\n");
883 snd_emu1010_fpga_read(emu, EMU_HANA_MAJOR_REV, &tmp );
884 snd_emu1010_fpga_read(emu, EMU_HANA_MINOR_REV, &tmp2 );
885 snd_printk("Hana ver:%d.%d\n",tmp ,tmp2);
886 /* Enable 48Volt power to Audio Dock */
887 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, EMU_HANA_DOCK_PWR_ON );
888
889 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
890 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
891 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
892 snd_printk(KERN_INFO "emu1010: Card options=0x%x\n",reg);
893 snd_emu1010_fpga_read(emu, EMU_HANA_OPTICAL_TYPE, &tmp );
James Courtier-Duttonedec7bb2007-07-23 20:30:22 +0100894 /* Optical -> ADAT I/O */
James Courtier-Duttonf93abe52007-07-26 18:31:39 +0100895 /* 0 : SPDIF
896 * 1 : ADAT
897 */
898 emu->emu1010.optical_in = 1; /* IN_ADAT */
899 emu->emu1010.optical_out = 1; /* IN_ADAT */
900 tmp = 0;
901 tmp = (emu->emu1010.optical_in ? EMU_HANA_OPTICAL_IN_ADAT : 0) |
902 (emu->emu1010.optical_out ? EMU_HANA_OPTICAL_OUT_ADAT : 0);
903 snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, tmp );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100904 snd_emu1010_fpga_read(emu, EMU_HANA_ADC_PADS, &tmp );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100905 /* Set no attenuation on Audio Dock pads. */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100906 snd_emu1010_fpga_write(emu, EMU_HANA_ADC_PADS, 0x00 );
907 emu->emu1010.adc_pads = 0x00;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100908 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
909 /* Unmute Audio dock DACs, Headphone source DAC-4. */
910 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
911 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100912 snd_emu1010_fpga_read(emu, EMU_HANA_DAC_PADS, &tmp );
913 /* DAC PADs. */
914 snd_emu1010_fpga_write(emu, EMU_HANA_DAC_PADS, 0x0f );
915 emu->emu1010.dac_pads = 0x0f;
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100916 snd_emu1010_fpga_read(emu, EMU_HANA_DOCK_MISC, &tmp );
917 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_MISC, 0x30 );
918 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
919 /* SPDIF Format. Set Consumer mode, 24bit, copy enable */
920 snd_emu1010_fpga_write(emu, EMU_HANA_SPDIF_MODE, 0x10 );
921 /* MIDI routing */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100922 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100923 /* Unknown. */
James Courtier-Dutton9148cc52006-10-09 23:08:00 +0100924 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c );
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +0100925 /* snd_emu1010_fpga_write(emu, 0x09, 0x0f ); // IRQ Enable: All on */
926 /* IRQ Enable: All off */
927 snd_emu1010_fpga_write(emu, EMU_HANA_IRQ_ENABLE, 0x00 );
928
929 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &reg );
930 snd_printk(KERN_INFO "emu1010: Card options3=0x%x\n",reg);
931 /* Default WCLK set to 48kHz. */
932 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x00 );
933 /* Word Clock source, Internal 48kHz x1 */
934 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
935 //snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K | EMU_HANA_WCLOCK_4X );
936 /* Audio Dock LEDs. */
937 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12 );
938
939#if 0
940 /* For 96kHz */
941 snd_emu1010_fpga_link_dst_src_write(emu,
942 EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
943 snd_emu1010_fpga_link_dst_src_write(emu,
944 EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
945 snd_emu1010_fpga_link_dst_src_write(emu,
946 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT2);
947 snd_emu1010_fpga_link_dst_src_write(emu,
948 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT2);
949#endif
950#if 0
951 /* For 192kHz */
952 snd_emu1010_fpga_link_dst_src_write(emu,
953 EMU_DST_ALICE2_EMU32_0, EMU_SRC_HAMOA_ADC_LEFT1);
954 snd_emu1010_fpga_link_dst_src_write(emu,
955 EMU_DST_ALICE2_EMU32_1, EMU_SRC_HAMOA_ADC_RIGHT1);
956 snd_emu1010_fpga_link_dst_src_write(emu,
957 EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
958 snd_emu1010_fpga_link_dst_src_write(emu,
959 EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_RIGHT2);
960 snd_emu1010_fpga_link_dst_src_write(emu,
961 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HAMOA_ADC_LEFT3);
962 snd_emu1010_fpga_link_dst_src_write(emu,
963 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HAMOA_ADC_RIGHT3);
964 snd_emu1010_fpga_link_dst_src_write(emu,
965 EMU_DST_ALICE2_EMU32_6, EMU_SRC_HAMOA_ADC_LEFT4);
966 snd_emu1010_fpga_link_dst_src_write(emu,
967 EMU_DST_ALICE2_EMU32_7, EMU_SRC_HAMOA_ADC_RIGHT4);
968#endif
969#if 1
970 /* For 48kHz */
971 snd_emu1010_fpga_link_dst_src_write(emu,
972 EMU_DST_ALICE2_EMU32_0, EMU_SRC_DOCK_MIC_A1);
973 snd_emu1010_fpga_link_dst_src_write(emu,
974 EMU_DST_ALICE2_EMU32_1, EMU_SRC_DOCK_MIC_B1);
975 snd_emu1010_fpga_link_dst_src_write(emu,
976 EMU_DST_ALICE2_EMU32_2, EMU_SRC_HAMOA_ADC_LEFT2);
977 snd_emu1010_fpga_link_dst_src_write(emu,
978 EMU_DST_ALICE2_EMU32_3, EMU_SRC_HAMOA_ADC_LEFT2);
979 snd_emu1010_fpga_link_dst_src_write(emu,
980 EMU_DST_ALICE2_EMU32_4, EMU_SRC_DOCK_ADC1_LEFT1);
981 snd_emu1010_fpga_link_dst_src_write(emu,
982 EMU_DST_ALICE2_EMU32_5, EMU_SRC_DOCK_ADC1_RIGHT1);
983 snd_emu1010_fpga_link_dst_src_write(emu,
984 EMU_DST_ALICE2_EMU32_6, EMU_SRC_DOCK_ADC2_LEFT1);
985 snd_emu1010_fpga_link_dst_src_write(emu,
986 EMU_DST_ALICE2_EMU32_7, EMU_SRC_DOCK_ADC2_RIGHT1);
Pavel Hofman13d45702007-06-11 12:21:20 +0200987 /* Pavel Hofman - setting defaults for 8 more capture channels
988 * Defaults only, users will set their own values anyways, let's
989 * just copy/paste.
990 */
991
992 snd_emu1010_fpga_link_dst_src_write(emu,
993 EMU_DST_ALICE2_EMU32_8, EMU_SRC_DOCK_MIC_A1);
994 snd_emu1010_fpga_link_dst_src_write(emu,
995 EMU_DST_ALICE2_EMU32_9, EMU_SRC_DOCK_MIC_B1);
996 snd_emu1010_fpga_link_dst_src_write(emu,
997 EMU_DST_ALICE2_EMU32_A, EMU_SRC_HAMOA_ADC_LEFT2);
998 snd_emu1010_fpga_link_dst_src_write(emu,
999 EMU_DST_ALICE2_EMU32_B, EMU_SRC_HAMOA_ADC_LEFT2);
1000 snd_emu1010_fpga_link_dst_src_write(emu,
1001 EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_ADC1_LEFT1);
1002 snd_emu1010_fpga_link_dst_src_write(emu,
1003 EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_ADC1_RIGHT1);
1004 snd_emu1010_fpga_link_dst_src_write(emu,
1005 EMU_DST_ALICE2_EMU32_E, EMU_SRC_DOCK_ADC2_LEFT1);
1006 snd_emu1010_fpga_link_dst_src_write(emu,
1007 EMU_DST_ALICE2_EMU32_F, EMU_SRC_DOCK_ADC2_RIGHT1);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001008#endif
1009#if 0
1010 /* Original */
1011 snd_emu1010_fpga_link_dst_src_write(emu,
1012 EMU_DST_ALICE2_EMU32_4, EMU_SRC_HANA_ADAT);
1013 snd_emu1010_fpga_link_dst_src_write(emu,
1014 EMU_DST_ALICE2_EMU32_5, EMU_SRC_HANA_ADAT + 1);
1015 snd_emu1010_fpga_link_dst_src_write(emu,
1016 EMU_DST_ALICE2_EMU32_6, EMU_SRC_HANA_ADAT + 2);
1017 snd_emu1010_fpga_link_dst_src_write(emu,
1018 EMU_DST_ALICE2_EMU32_7, EMU_SRC_HANA_ADAT + 3);
1019 snd_emu1010_fpga_link_dst_src_write(emu,
1020 EMU_DST_ALICE2_EMU32_8, EMU_SRC_HANA_ADAT + 4);
1021 snd_emu1010_fpga_link_dst_src_write(emu,
1022 EMU_DST_ALICE2_EMU32_9, EMU_SRC_HANA_ADAT + 5);
1023 snd_emu1010_fpga_link_dst_src_write(emu,
1024 EMU_DST_ALICE2_EMU32_A, EMU_SRC_HANA_ADAT + 6);
1025 snd_emu1010_fpga_link_dst_src_write(emu,
1026 EMU_DST_ALICE2_EMU32_B, EMU_SRC_HANA_ADAT + 7);
1027 snd_emu1010_fpga_link_dst_src_write(emu,
1028 EMU_DST_ALICE2_EMU32_C, EMU_SRC_DOCK_MIC_A1);
1029 snd_emu1010_fpga_link_dst_src_write(emu,
1030 EMU_DST_ALICE2_EMU32_D, EMU_SRC_DOCK_MIC_B1);
1031 snd_emu1010_fpga_link_dst_src_write(emu,
1032 EMU_DST_ALICE2_EMU32_E, EMU_SRC_HAMOA_ADC_LEFT2);
1033 snd_emu1010_fpga_link_dst_src_write(emu,
1034 EMU_DST_ALICE2_EMU32_F, EMU_SRC_HAMOA_ADC_LEFT2);
1035#endif
1036 for (i = 0;i < 0x20; i++ ) {
1037 /* AudioDock Elink <- Silence */
1038 snd_emu1010_fpga_link_dst_src_write(emu, 0x0100+i, EMU_SRC_SILENCE);
1039 }
1040 for (i = 0;i < 4; i++) {
1041 /* Hana SPDIF Out <- Silence */
1042 snd_emu1010_fpga_link_dst_src_write(emu, 0x0200+i, EMU_SRC_SILENCE);
1043 }
1044 for (i = 0;i < 7; i++) {
1045 /* Hamoa DAC <- Silence */
1046 snd_emu1010_fpga_link_dst_src_write(emu, 0x0300+i, EMU_SRC_SILENCE);
1047 }
1048 for (i = 0;i < 7; i++) {
1049 /* Hana ADAT Out <- Silence */
1050 snd_emu1010_fpga_link_dst_src_write(emu, EMU_DST_HANA_ADAT + i, EMU_SRC_SILENCE);
1051 }
1052 snd_emu1010_fpga_link_dst_src_write(emu,
1053 EMU_DST_ALICE_I2S0_LEFT, EMU_SRC_DOCK_ADC1_LEFT1);
1054 snd_emu1010_fpga_link_dst_src_write(emu,
1055 EMU_DST_ALICE_I2S0_RIGHT, EMU_SRC_DOCK_ADC1_RIGHT1);
1056 snd_emu1010_fpga_link_dst_src_write(emu,
1057 EMU_DST_ALICE_I2S1_LEFT, EMU_SRC_DOCK_ADC2_LEFT1);
1058 snd_emu1010_fpga_link_dst_src_write(emu,
1059 EMU_DST_ALICE_I2S1_RIGHT, EMU_SRC_DOCK_ADC2_RIGHT1);
1060 snd_emu1010_fpga_link_dst_src_write(emu,
1061 EMU_DST_ALICE_I2S2_LEFT, EMU_SRC_DOCK_ADC3_LEFT1);
1062 snd_emu1010_fpga_link_dst_src_write(emu,
1063 EMU_DST_ALICE_I2S2_RIGHT, EMU_SRC_DOCK_ADC3_RIGHT1);
1064 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x01 ); // Unmute all
1065
1066 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
1067
1068 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
1069 * Lock Sound Memory Cache, Lock Tank Memory Cache,
1070 * Mute all codecs.
1071 */
1072 outl(0x0000a000, emu->port + HCFG);
1073 /* AC97 1.03, Any 32Meg of 2Gig address, Auto-Mute, EMU32 Slave,
1074 * Lock Sound Memory Cache, Lock Tank Memory Cache,
1075 * Un-Mute all codecs.
1076 */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001077 outl(0x0000a001, emu->port + HCFG);
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001078
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001079 /* Initial boot complete. Now patches */
1080
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001081 snd_emu1010_fpga_read(emu, EMU_HANA_OPTION_CARDS, &tmp );
James Courtier-Dutton9148cc52006-10-09 23:08:00 +01001082 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
1083 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
1084 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_IN, 0x19 ); /* MIDI Route */
1085 snd_emu1010_fpga_write(emu, EMU_HANA_MIDI_OUT, 0x0c ); /* Unknown */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001086 snd_emu1010_fpga_read(emu, EMU_HANA_SPDIF_MODE, &tmp );
1087 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 +01001088
James Courtier-Dutton42f53222007-07-23 17:52:27 +01001089 /* Start Micro/Audio Dock firmware loader thread */
1090 emu->emu1010.firmware_thread = kthread_create(&emu1010_firmware_thread,
1091 emu,
1092 "emu1010_firmware");
1093 wake_up_process(emu->emu1010.firmware_thread);
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001094
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001095#if 0
1096 snd_emu1010_fpga_link_dst_src_write(emu,
1097 EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32B + 2); /* ALICE2 bus 0xa2 */
1098 snd_emu1010_fpga_link_dst_src_write(emu,
1099 EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32B + 3); /* ALICE2 bus 0xa3 */
1100 snd_emu1010_fpga_link_dst_src_write(emu,
1101 EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 2); /* ALICE2 bus 0xb2 */
1102 snd_emu1010_fpga_link_dst_src_write(emu,
1103 EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 3); /* ALICE2 bus 0xb3 */
1104#endif
1105 /* Default outputs */
1106 snd_emu1010_fpga_link_dst_src_write(emu,
1107 EMU_DST_DOCK_DAC1_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1108 emu->emu1010.output_source[0] = 21;
1109 snd_emu1010_fpga_link_dst_src_write(emu,
1110 EMU_DST_DOCK_DAC1_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1111 emu->emu1010.output_source[1] = 22;
1112 snd_emu1010_fpga_link_dst_src_write(emu,
1113 EMU_DST_DOCK_DAC2_LEFT1, EMU_SRC_ALICE_EMU32A + 2);
1114 emu->emu1010.output_source[2] = 23;
1115 snd_emu1010_fpga_link_dst_src_write(emu,
1116 EMU_DST_DOCK_DAC2_RIGHT1, EMU_SRC_ALICE_EMU32A + 3);
1117 emu->emu1010.output_source[3] = 24;
1118 snd_emu1010_fpga_link_dst_src_write(emu,
1119 EMU_DST_DOCK_DAC3_LEFT1, EMU_SRC_ALICE_EMU32A + 4);
1120 emu->emu1010.output_source[4] = 25;
1121 snd_emu1010_fpga_link_dst_src_write(emu,
1122 EMU_DST_DOCK_DAC3_RIGHT1, EMU_SRC_ALICE_EMU32A + 5);
1123 emu->emu1010.output_source[5] = 26;
1124 snd_emu1010_fpga_link_dst_src_write(emu,
1125 EMU_DST_DOCK_DAC4_LEFT1, EMU_SRC_ALICE_EMU32A + 6);
1126 emu->emu1010.output_source[6] = 27;
1127 snd_emu1010_fpga_link_dst_src_write(emu,
1128 EMU_DST_DOCK_DAC4_RIGHT1, EMU_SRC_ALICE_EMU32A + 7);
1129 emu->emu1010.output_source[7] = 28;
1130 snd_emu1010_fpga_link_dst_src_write(emu,
1131 EMU_DST_DOCK_PHONES_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1132 emu->emu1010.output_source[8] = 21;
1133 snd_emu1010_fpga_link_dst_src_write(emu,
1134 EMU_DST_DOCK_PHONES_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1135 emu->emu1010.output_source[9] = 22;
1136 snd_emu1010_fpga_link_dst_src_write(emu,
1137 EMU_DST_DOCK_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1138 emu->emu1010.output_source[10] = 21;
1139 snd_emu1010_fpga_link_dst_src_write(emu,
1140 EMU_DST_DOCK_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1141 emu->emu1010.output_source[11] = 22;
1142 snd_emu1010_fpga_link_dst_src_write(emu,
1143 EMU_DST_HANA_SPDIF_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1144 emu->emu1010.output_source[12] = 21;
1145 snd_emu1010_fpga_link_dst_src_write(emu,
1146 EMU_DST_HANA_SPDIF_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1147 emu->emu1010.output_source[13] = 22;
1148 snd_emu1010_fpga_link_dst_src_write(emu,
1149 EMU_DST_HAMOA_DAC_LEFT1, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1150 emu->emu1010.output_source[14] = 21;
1151 snd_emu1010_fpga_link_dst_src_write(emu,
1152 EMU_DST_HAMOA_DAC_RIGHT1, EMU_SRC_ALICE_EMU32A + 1);
1153 emu->emu1010.output_source[15] = 22;
1154 snd_emu1010_fpga_link_dst_src_write(emu,
1155 EMU_DST_HANA_ADAT, EMU_SRC_ALICE_EMU32A + 0); /* ALICE2 bus 0xa0 */
1156 emu->emu1010.output_source[16] = 21;
1157 snd_emu1010_fpga_link_dst_src_write(emu,
1158 EMU_DST_HANA_ADAT + 1, EMU_SRC_ALICE_EMU32A + 1);
1159 emu->emu1010.output_source[17] = 22;
1160 snd_emu1010_fpga_link_dst_src_write(emu,
1161 EMU_DST_HANA_ADAT + 2, EMU_SRC_ALICE_EMU32A + 2);
1162 emu->emu1010.output_source[18] = 23;
1163 snd_emu1010_fpga_link_dst_src_write(emu,
1164 EMU_DST_HANA_ADAT + 3, EMU_SRC_ALICE_EMU32A + 3);
1165 emu->emu1010.output_source[19] = 24;
1166 snd_emu1010_fpga_link_dst_src_write(emu,
1167 EMU_DST_HANA_ADAT + 4, EMU_SRC_ALICE_EMU32A + 4);
1168 emu->emu1010.output_source[20] = 25;
1169 snd_emu1010_fpga_link_dst_src_write(emu,
1170 EMU_DST_HANA_ADAT + 5, EMU_SRC_ALICE_EMU32A + 5);
1171 emu->emu1010.output_source[21] = 26;
1172 snd_emu1010_fpga_link_dst_src_write(emu,
1173 EMU_DST_HANA_ADAT + 6, EMU_SRC_ALICE_EMU32A + 6);
1174 emu->emu1010.output_source[22] = 27;
1175 snd_emu1010_fpga_link_dst_src_write(emu,
1176 EMU_DST_HANA_ADAT + 7, EMU_SRC_ALICE_EMU32A + 7);
1177 emu->emu1010.output_source[23] = 28;
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001178
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001179 /* TEMP: Select SPDIF in/out */
James Courtier-Duttonedec7bb2007-07-23 20:30:22 +01001180 //snd_emu1010_fpga_write(emu, EMU_HANA_OPTICAL_TYPE, 0x0); /* Output spdif */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001181
1182 /* TEMP: Select 48kHz SPDIF out */
1183 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x0); /* Mute all */
1184 snd_emu1010_fpga_write(emu, EMU_HANA_DEFCLOCK, 0x0); /* Default fallback clock 48kHz */
1185 /* Word Clock source, Internal 48kHz x1 */
1186 snd_emu1010_fpga_write(emu, EMU_HANA_WCLOCK, EMU_HANA_WCLOCK_INT_48K );
1187 //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 +01001188 emu->emu1010.internal_clock = 1; /* 48000 */
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001189 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_LEDS_2, 0x12);/* Set LEDs on Audio Dock */
1190 snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, 0x1); /* Unmute all */
1191 //snd_emu1010_fpga_write(emu, 0x7, 0x0); /* Mute all */
1192 //snd_emu1010_fpga_write(emu, 0x7, 0x1); /* Unmute all */
1193 //snd_emu1010_fpga_write(emu, 0xe, 0x12); /* Set LEDs on Audio Dock */
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001194
1195 return 0;
1196}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197/*
1198 * Create the EMU10K1 instance
1199 */
1200
Takashi Iwai09668b42005-11-17 16:14:10 +01001201#ifdef CONFIG_PM
1202static int alloc_pm_buffer(struct snd_emu10k1 *emu);
1203static void free_pm_buffer(struct snd_emu10k1 *emu);
1204#endif
1205
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001206static int snd_emu10k1_free(struct snd_emu10k1 *emu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207{
1208 if (emu->port) { /* avoid access to already used hardware */
1209 snd_emu10k1_fx8010_tram_setup(emu, 0);
1210 snd_emu10k1_done(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001211 /* remove reserved page */
1212 if (emu->reserved_page) {
1213 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
1214 emu->reserved_page = NULL;
1215 }
1216 snd_emu10k1_free_efx(emu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001217 }
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001218 if (emu->card_capabilities->emu_model == 1) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001219 /* Disable 48Volt power to Audio Dock */
1220 snd_emu1010_fpga_write(emu, EMU_HANA_DOCK_PWR, 0 );
1221 }
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001222 if (emu->card_capabilities->emu_model)
1223 kthread_stop(emu->emu1010.firmware_thread);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001224 if (emu->memhdr)
1225 snd_util_memhdr_free(emu->memhdr);
1226 if (emu->silent_page.area)
1227 snd_dma_free_pages(&emu->silent_page);
1228 if (emu->ptb_pages.area)
1229 snd_dma_free_pages(&emu->ptb_pages);
1230 vfree(emu->page_ptr_table);
1231 vfree(emu->page_addr_table);
Takashi Iwai09668b42005-11-17 16:14:10 +01001232#ifdef CONFIG_PM
1233 free_pm_buffer(emu);
1234#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001235 if (emu->irq >= 0)
Takashi Iwai437a5a42006-11-21 12:14:23 +01001236 free_irq(emu->irq, emu);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001237 if (emu->port)
1238 pci_release_regions(emu->pci);
Lee Revell2b637da2005-03-30 13:51:18 +02001239 if (emu->card_capabilities->ca0151_chip) /* P16V */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 snd_p16v_free(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001241 pci_disable_device(emu->pci);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 kfree(emu);
1243 return 0;
1244}
1245
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001246static int snd_emu10k1_dev_free(struct snd_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247{
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001248 struct snd_emu10k1 *emu = device->device_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 return snd_emu10k1_free(emu);
1250}
1251
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001252static struct snd_emu_chip_details emu_chip_details[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001253 /* 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 +02001254 /* Tested by James@superbug.co.uk 3rd July 2005 */
James Courtier-Dutton54efc962005-12-22 12:58:41 +01001255 /* DSP: CA0108-IAT
1256 * DAC: CS4382-KQ
1257 * ADC: Philips 1361T
1258 * AC97: STAC9750
1259 * CA0151: None
1260 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10011102,
1262 .driver = "Audigy2", .name = "Audigy 2 Value [SB0400]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001263 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264 .emu10k2_chip = 1,
1265 .ca0108_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001266 .spk71 = 1,
1267 .ac97_chip = 1} ,
James Courtier-Dutton21fddde2006-04-09 17:36:39 +01001268 /* Audigy4 (Not PRO) SB0610 */
1269 /* Tested by James@superbug.co.uk 4th April 2006 */
1270 /* A_IOCFG bits
1271 * Output
1272 * 0: ?
1273 * 1: ?
1274 * 2: ?
1275 * 3: 0 - Digital Out, 1 - Line in
1276 * 4: ?
1277 * 5: ?
1278 * 6: ?
1279 * 7: ?
1280 * Input
1281 * 8: ?
1282 * 9: ?
1283 * A: Green jack sense (Front)
1284 * B: ?
1285 * C: Black jack sense (Rear/Side Right)
1286 * D: Yellow jack sense (Center/LFE/Side Left)
1287 * E: ?
1288 * F: ?
1289 *
1290 * Digital Out/Line in switch using A_IOCFG bit 3 (0x08)
1291 * 0 - Digital Out
1292 * 1 - Line in
1293 */
1294 /* Mic input not tested.
1295 * Analog CD input not tested
1296 * Digital Out not tested.
1297 * Line in working.
1298 * Audio output 5.1 working. Side outputs not working.
1299 */
1300 /* DSP: CA10300-IAT LF
1301 * DAC: Cirrus Logic CS4382-KQZ
1302 * ADC: Philips 1361T
1303 * AC97: Sigmatel STAC9750
1304 * CA0151: None
1305 */
1306 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x10211102,
1307 .driver = "Audigy2", .name = "Audigy 4 [SB0610]",
1308 .id = "Audigy2",
1309 .emu10k2_chip = 1,
1310 .ca0108_chip = 1,
1311 .spk71 = 1,
1312 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
1313 .ac97_chip = 1} ,
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001314 /* Audigy 2 ZS Notebook Cardbus card.*/
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001315 /* Tested by James@superbug.co.uk 6th November 2006 */
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001316 /* Audio output 7.1/Headphones working.
1317 * Digital output working. (AC3 not checked, only PCM)
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001318 * Audio Mic/Line inputs working.
1319 * Digital input not tested.
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001320 */
James Courtier-Dutton21fddde2006-04-09 17:36:39 +01001321 /* DSP: Tina2
James Courtier-Duttonf951fd32005-12-22 13:05:23 +01001322 * DAC: Wolfson WM8768/WM8568
1323 * ADC: Wolfson WM8775
1324 * AC97: None
1325 * CA0151: None
1326 */
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001327 /* Tested by James@superbug.co.uk 4th April 2006 */
1328 /* A_IOCFG bits
1329 * Output
1330 * 0: Not Used
1331 * 1: 0 = Mute all the 7.1 channel out. 1 = unmute.
1332 * 2: Analog input 0 = line in, 1 = mic in
1333 * 3: Not Used
1334 * 4: Digital output 0 = off, 1 = on.
1335 * 5: Not Used
1336 * 6: Not Used
1337 * 7: Not Used
1338 * Input
1339 * All bits 1 (0x3fxx) means nothing plugged in.
1340 * 8-9: 0 = Line in/Mic, 2 = Optical in, 3 = Nothing.
1341 * A-B: 0 = Headphones, 2 = Optical out, 3 = Nothing.
1342 * C-D: 2 = Front/Rear/etc, 3 = nothing.
1343 * E-F: Always 0
1344 *
1345 */
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001346 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x20011102,
1347 .driver = "Audigy2", .name = "Audigy 2 ZS Notebook [SB0530]",
1348 .id = "Audigy2",
1349 .emu10k2_chip = 1,
1350 .ca0108_chip = 1,
1351 .ca_cardbus_chip = 1,
James Courtier-Dutton27fe8642005-12-21 15:06:08 +01001352 .spi_dac = 1,
James Courtier-Dutton184c1e22006-12-06 15:58:02 +00001353 .i2c_adc = 1,
James Courtier-Duttond83c6712005-10-31 10:27:41 +00001354 .spk71 = 1} ,
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001355 /* Tested by James@superbug.co.uk 20-3-2007. */
1356 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40021102,
1357 .driver = "Audigy2", .name = "E-mu 0404 [4002]",
1358 .id = "EMU0404",
1359 .emu10k2_chip = 1,
1360 .ca0102_chip = 1,
1361 .spk71 = 1,
1362 .emu_model = 4} , /* EMU 0404 */
1363 /* Tested by James@superbug.co.uk 4th Nov 2007. */
James Courtier-Dutton82c8c742007-04-19 11:14:41 +01001364 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x42011102,
1365 .driver = "Audigy2", .name = "E-mu 1010 Notebook [MAEM8950]",
1366 .id = "EMU1010",
1367 .emu10k2_chip = 1,
1368 .ca0108_chip = 1,
1369 .ca_cardbus_chip = 1,
James Courtier-Duttond9e8a552007-07-14 10:24:49 +01001370 .spk71 = 1 ,
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001371 .emu_model = 3} ,
1372 /* Tested by James@superbug.co.uk 4th Nov 2007. */
James Courtier-Dutton3663d842007-07-14 02:18:26 +01001373 {.vendor = 0x1102, .device = 0x0008, .subsystem = 0x40041102,
1374 .driver = "Audigy2", .name = "E-mu 1010b PCI [MAEM????]",
1375 .id = "EMU1010",
1376 .emu10k2_chip = 1,
1377 .ca0108_chip = 1,
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001378 .spk71 = 1,
1379 .emu_model = 2} ,
1380 /* Tested by James@superbug.co.uk 8th July 2005. */
1381 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x40011102,
1382 .driver = "Audigy2", .name = "E-mu 1010 [4001]",
1383 .id = "EMU1010",
1384 .emu10k2_chip = 1,
1385 .ca0102_chip = 1,
1386 .spk71 = 1,
1387 .emu_model = 1} , /* Emu 1010 */
1388 /* Audigy4 (Not PRO) SB0610 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001389 {.vendor = 0x1102, .device = 0x0008,
1390 .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001391 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 .emu10k2_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001393 .ca0108_chip = 1,
1394 .ac97_chip = 1} ,
James Courtier-Dutton88dc0e52005-07-03 12:54:29 +02001395 /* Tested by James@superbug.co.uk 3rd July 2005 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20071102,
1397 .driver = "Audigy2", .name = "Audigy 4 PRO [SB0380]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001398 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 .emu10k2_chip = 1,
1400 .ca0102_chip = 1,
1401 .ca0151_chip = 1,
1402 .spk71 = 1,
1403 .spdif_bug = 1,
1404 .ac97_chip = 1} ,
Lee Revellf6f8bb62005-11-07 14:59:19 +01001405 /* Tested by shane-alsa@cm.nu 5th Nov 2005 */
James Courtier-Dutton5b0e4982006-04-09 22:45:58 +02001406 /* The 0x20061102 does have SB0350 written on it
1407 * Just like 0x20021102
1408 */
Lee Revellf6f8bb62005-11-07 14:59:19 +01001409 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20061102,
James Courtier-Dutton5b0e4982006-04-09 22:45:58 +02001410 .driver = "Audigy2", .name = "Audigy 2 [SB0350b]",
Lee Revellf6f8bb62005-11-07 14:59:19 +01001411 .id = "Audigy2",
1412 .emu10k2_chip = 1,
1413 .ca0102_chip = 1,
1414 .ca0151_chip = 1,
1415 .spk71 = 1,
1416 .spdif_bug = 1,
1417 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20021102,
1419 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0350]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001420 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 .emu10k2_chip = 1,
1422 .ca0102_chip = 1,
1423 .ca0151_chip = 1,
1424 .spk71 = 1,
1425 .spdif_bug = 1,
1426 .ac97_chip = 1} ,
1427 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x20011102,
1428 .driver = "Audigy2", .name = "Audigy 2 ZS [2001]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001429 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 .emu10k2_chip = 1,
1431 .ca0102_chip = 1,
1432 .ca0151_chip = 1,
1433 .spk71 = 1,
1434 .spdif_bug = 1,
1435 .ac97_chip = 1} ,
James Courtier-Dutton54efc962005-12-22 12:58:41 +01001436 /* Audigy 2 */
1437 /* Tested by James@superbug.co.uk 3rd July 2005 */
1438 /* DSP: CA0102-IAT
1439 * DAC: CS4382-KQ
1440 * ADC: Philips 1361T
1441 * AC97: STAC9721
1442 * CA0151: Yes
1443 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001444 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10071102,
1445 .driver = "Audigy2", .name = "Audigy 2 [SB0240]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001446 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 .emu10k2_chip = 1,
1448 .ca0102_chip = 1,
1449 .ca0151_chip = 1,
1450 .spk71 = 1,
1451 .spdif_bug = 1,
James Courtier-Dutton11b3a752006-07-08 16:39:30 +01001452 .adc_1361t = 1, /* 24 bit capture instead of 16bit */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 .ac97_chip = 1} ,
1454 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10051102,
1455 .driver = "Audigy2", .name = "Audigy 2 EX [1005]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001456 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 .emu10k2_chip = 1,
1458 .ca0102_chip = 1,
1459 .ca0151_chip = 1,
Lee Revell2f020aa2005-11-07 14:54:24 +01001460 .spk71 = 1,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461 .spdif_bug = 1} ,
James Courtier-Dutton264f9572006-07-30 17:17:59 +01001462 /* Dell OEM/Creative Labs Audigy 2 ZS */
1463 /* See ALSA bug#1365 */
1464 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10031102,
1465 .driver = "Audigy2", .name = "Audigy 2 ZS [SB0353]",
1466 .id = "Audigy2",
1467 .emu10k2_chip = 1,
1468 .ca0102_chip = 1,
1469 .ca0151_chip = 1,
1470 .spk71 = 1,
1471 .spdif_bug = 1,
1472 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x10021102,
1474 .driver = "Audigy2", .name = "Audigy 2 Platinum [SB0240P]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001475 .id = "Audigy2",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 .emu10k2_chip = 1,
1477 .ca0102_chip = 1,
1478 .ca0151_chip = 1,
1479 .spk71 = 1,
1480 .spdif_bug = 1,
James Courtier-Dutton3271b7b2006-11-25 22:02:47 +00001481 .adc_1361t = 1, /* 24 bit capture instead of 16bit. Fixes ALSA bug#324 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 .ac97_chip = 1} ,
Takashi Iwaibdaed502005-04-07 15:48:42 +02001483 {.vendor = 0x1102, .device = 0x0004, .revision = 0x04,
1484 .driver = "Audigy2", .name = "Audigy 2 [Unknown]",
1485 .id = "Audigy2",
1486 .emu10k2_chip = 1,
1487 .ca0102_chip = 1,
1488 .ca0151_chip = 1,
1489 .spdif_bug = 1,
1490 .ac97_chip = 1} ,
Peter Zubaj26689072005-04-01 11:15:07 +02001491 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00531102,
1492 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
1493 .id = "Audigy",
1494 .emu10k2_chip = 1,
1495 .ca0102_chip = 1,
1496 .ac97_chip = 1} ,
James Courtier-Duttonae3a72d2005-07-06 22:36:18 +02001497 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00521102,
1498 .driver = "Audigy", .name = "Audigy 1 ES [SB0160]",
1499 .id = "Audigy",
1500 .emu10k2_chip = 1,
1501 .ca0102_chip = 1,
1502 .spdif_bug = 1,
1503 .ac97_chip = 1} ,
Arnaud Patarda6c17ec2005-05-27 12:31:34 +02001504 {.vendor = 0x1102, .device = 0x0004, .subsystem = 0x00511102,
1505 .driver = "Audigy", .name = "Audigy 1 [SB0090]",
1506 .id = "Audigy",
1507 .emu10k2_chip = 1,
1508 .ca0102_chip = 1,
1509 .ac97_chip = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 {.vendor = 0x1102, .device = 0x0004,
Takashi Iwaibdaed502005-04-07 15:48:42 +02001511 .driver = "Audigy", .name = "Audigy 1 [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001512 .id = "Audigy",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 .emu10k2_chip = 1,
1514 .ca0102_chip = 1,
Peter Zubaj26689072005-04-01 11:15:07 +02001515 .ac97_chip = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001516 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806B1102,
1517 .driver = "EMU10K1", .name = "SBLive! [SB0105]",
James Courtier-Dutton2b6b22f2005-06-18 13:50:22 +02001518 .id = "Live",
1519 .emu10k1_chip = 1,
1520 .ac97_chip = 1,
1521 .sblive51 = 1} ,
1522 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x806A1102,
1523 .driver = "EMU10K1", .name = "SBLive! Value [SB0103]",
1524 .id = "Live",
1525 .emu10k1_chip = 1,
1526 .ac97_chip = 1,
1527 .sblive51 = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001528 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80691102,
1529 .driver = "EMU10K1", .name = "SBLive! Value [SB0101]",
1530 .id = "Live",
1531 .emu10k1_chip = 1,
1532 .ac97_chip = 1,
1533 .sblive51 = 1} ,
James Courtier-Dutton0ba656d2005-12-26 15:30:03 +01001534 /* Tested by ALSA bug#1680 26th December 2005 */
1535 /* note: It really has SB0220 written on the card. */
1536 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80661102,
1537 .driver = "EMU10K1", .name = "SB Live 5.1 Dell OEM [SB0220]",
1538 .id = "Live",
1539 .emu10k1_chip = 1,
1540 .ac97_chip = 1,
1541 .sblive51 = 1} ,
Lee Revellc6c0b842005-08-29 17:42:00 +02001542 /* Tested by Thomas Zehetbauer 27th Aug 2005 */
1543 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80651102,
1544 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
1545 .id = "Live",
1546 .emu10k1_chip = 1,
1547 .ac97_chip = 1,
1548 .sblive51 = 1} ,
Gergely Tamasa8ee7292005-12-06 14:10:57 +01001549 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x100a1102,
1550 .driver = "EMU10K1", .name = "SB Live 5.1 [SB0220]",
1551 .id = "Live",
1552 .emu10k1_chip = 1,
1553 .ac97_chip = 1,
1554 .sblive51 = 1} ,
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001555 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80641102,
1556 .driver = "EMU10K1", .name = "SB Live 5.1",
1557 .id = "Live",
1558 .emu10k1_chip = 1,
1559 .ac97_chip = 1,
1560 .sblive51 = 1} ,
James Courtier-Duttonafe0f1f2005-09-10 10:24:10 +02001561 /* Tested by alsa bugtrack user "hus" bug #1297 12th Aug 2005 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001562 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80611102,
Takashi Iwaif12aa402005-09-30 16:56:59 +02001563 .driver = "EMU10K1", .name = "SBLive 5.1 [SB0060]",
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001564 .id = "Live",
1565 .emu10k1_chip = 1,
Takashi Iwaif12aa402005-09-30 16:56:59 +02001566 .ac97_chip = 2, /* ac97 is optional; both SBLive 5.1 and platinum
1567 * share the same IDs!
1568 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001569 .sblive51 = 1} ,
1570 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80511102,
1571 .driver = "EMU10K1", .name = "SBLive! Value [CT4850]",
1572 .id = "Live",
1573 .emu10k1_chip = 1,
1574 .ac97_chip = 1,
1575 .sblive51 = 1} ,
1576 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80401102,
1577 .driver = "EMU10K1", .name = "SBLive! Platinum [CT4760P]",
1578 .id = "Live",
1579 .emu10k1_chip = 1,
1580 .ac97_chip = 1} ,
1581 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80321102,
1582 .driver = "EMU10K1", .name = "SBLive! Value [CT4871]",
1583 .id = "Live",
1584 .emu10k1_chip = 1,
1585 .ac97_chip = 1,
1586 .sblive51 = 1} ,
1587 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80311102,
1588 .driver = "EMU10K1", .name = "SBLive! Value [CT4831]",
1589 .id = "Live",
1590 .emu10k1_chip = 1,
1591 .ac97_chip = 1,
1592 .sblive51 = 1} ,
1593 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80281102,
1594 .driver = "EMU10K1", .name = "SBLive! Value [CT4870]",
1595 .id = "Live",
1596 .emu10k1_chip = 1,
1597 .ac97_chip = 1,
1598 .sblive51 = 1} ,
James Courtier-Dutton88dc0e52005-07-03 12:54:29 +02001599 /* Tested by James@superbug.co.uk 3rd July 2005 */
James Courtier-Duttona6f61922005-07-03 12:32:40 +02001600 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80271102,
1601 .driver = "EMU10K1", .name = "SBLive! Value [CT4832]",
1602 .id = "Live",
1603 .emu10k1_chip = 1,
1604 .ac97_chip = 1,
1605 .sblive51 = 1} ,
1606 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80261102,
1607 .driver = "EMU10K1", .name = "SBLive! Value [CT4830]",
1608 .id = "Live",
1609 .emu10k1_chip = 1,
1610 .ac97_chip = 1,
1611 .sblive51 = 1} ,
1612 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80231102,
1613 .driver = "EMU10K1", .name = "SB PCI512 [CT4790]",
1614 .id = "Live",
1615 .emu10k1_chip = 1,
1616 .ac97_chip = 1,
1617 .sblive51 = 1} ,
1618 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x80221102,
1619 .driver = "EMU10K1", .name = "SBLive! Value [CT4780]",
1620 .id = "Live",
1621 .emu10k1_chip = 1,
1622 .ac97_chip = 1,
1623 .sblive51 = 1} ,
1624 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x40011102,
1625 .driver = "EMU10K1", .name = "E-mu APS [4001]",
1626 .id = "APS",
1627 .emu10k1_chip = 1,
1628 .ecard = 1} ,
1629 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00211102,
1630 .driver = "EMU10K1", .name = "SBLive! [CT4620]",
1631 .id = "Live",
1632 .emu10k1_chip = 1,
1633 .ac97_chip = 1,
1634 .sblive51 = 1} ,
1635 {.vendor = 0x1102, .device = 0x0002, .subsystem = 0x00201102,
1636 .driver = "EMU10K1", .name = "SBLive! Value [CT4670]",
James Courtier-Dutton2b6b22f2005-06-18 13:50:22 +02001637 .id = "Live",
1638 .emu10k1_chip = 1,
1639 .ac97_chip = 1,
1640 .sblive51 = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 {.vendor = 0x1102, .device = 0x0002,
1642 .driver = "EMU10K1", .name = "SB Live [Unknown]",
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001643 .id = "Live",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 .emu10k1_chip = 1,
Lee Revell2b637da2005-03-30 13:51:18 +02001645 .ac97_chip = 1,
1646 .sblive51 = 1} ,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647 { } /* terminator */
1648};
1649
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001650int __devinit snd_emu10k1_create(struct snd_card *card,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001651 struct pci_dev * pci,
1652 unsigned short extin_mask,
1653 unsigned short extout_mask,
1654 long max_cache_bytes,
1655 int enable_ir,
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001656 uint subsystem,
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001657 struct snd_emu10k1 ** remu)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658{
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001659 struct snd_emu10k1 *emu;
Takashi Iwai09668b42005-11-17 16:14:10 +01001660 int idx, err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 int is_audigy;
Takashi Iwai09668b42005-11-17 16:14:10 +01001662 unsigned int silent_page;
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001663 const struct snd_emu_chip_details *c;
1664 static struct snd_device_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001665 .dev_free = snd_emu10k1_dev_free,
1666 };
1667
1668 *remu = NULL;
1669
1670 /* enable PCI device */
1671 if ((err = pci_enable_device(pci)) < 0)
1672 return err;
1673
Takashi Iwaie560d8d2005-09-09 14:21:46 +02001674 emu = kzalloc(sizeof(*emu), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675 if (emu == NULL) {
1676 pci_disable_device(pci);
1677 return -ENOMEM;
1678 }
1679 emu->card = card;
1680 spin_lock_init(&emu->reg_lock);
1681 spin_lock_init(&emu->emu_lock);
1682 spin_lock_init(&emu->voice_lock);
1683 spin_lock_init(&emu->synth_lock);
1684 spin_lock_init(&emu->memblk_lock);
Ingo Molnar62932df2006-01-16 16:34:20 +01001685 mutex_init(&emu->fx8010.lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001686 INIT_LIST_HEAD(&emu->mapped_link_head);
1687 INIT_LIST_HEAD(&emu->mapped_order_link_head);
1688 emu->pci = pci;
1689 emu->irq = -1;
1690 emu->synth = NULL;
1691 emu->get_synth_voice = NULL;
1692 /* read revision & serial */
Auke Kok44c10132007-06-08 15:46:36 -07001693 emu->revision = pci->revision;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &emu->serial);
1695 pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &emu->model);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 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);
1697
1698 for (c = emu_chip_details; c->vendor; c++) {
1699 if (c->vendor == pci->vendor && c->device == pci->device) {
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001700 if (subsystem) {
1701 if (c->subsystem && (c->subsystem == subsystem) ) {
1702 break;
1703 } else continue;
1704 } else {
1705 if (c->subsystem && (c->subsystem != emu->serial) )
1706 continue;
1707 if (c->revision && c->revision != emu->revision)
1708 continue;
1709 }
Takashi Iwaibdaed502005-04-07 15:48:42 +02001710 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 }
1712 }
1713 if (c->vendor == 0) {
1714 snd_printk(KERN_ERR "emu10k1: Card not recognised\n");
1715 kfree(emu);
1716 pci_disable_device(pci);
1717 return -ENOENT;
1718 }
1719 emu->card_capabilities = c;
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001720 if (c->subsystem && !subsystem)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 snd_printdd("Sound card name=%s\n", c->name);
James Courtier-Duttone66bc8b2005-07-06 22:21:51 +02001722 else if (subsystem)
1723 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x. Forced to subsytem=0x%x\n",
1724 c->name, pci->vendor, pci->device, emu->serial, c->subsystem);
1725 else
1726 snd_printdd("Sound card name=%s, vendor=0x%x, device=0x%x, subsystem=0x%x.\n",
1727 c->name, pci->vendor, pci->device, emu->serial);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728
Takashi Iwai85a655d2005-03-30 14:40:25 +02001729 if (!*card->id && c->id) {
1730 int i, n = 0;
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001731 strlcpy(card->id, c->id, sizeof(card->id));
Takashi Iwai85a655d2005-03-30 14:40:25 +02001732 for (;;) {
1733 for (i = 0; i < snd_ecards_limit; i++) {
1734 if (snd_cards[i] && !strcmp(snd_cards[i]->id, card->id))
1735 break;
1736 }
1737 if (i >= snd_ecards_limit)
1738 break;
1739 n++;
1740 if (n >= SNDRV_CARDS)
1741 break;
1742 snprintf(card->id, sizeof(card->id), "%s_%d", c->id, n);
1743 }
1744 }
Takashi Iwaiaec72e02005-03-30 14:22:25 +02001745
Linus Torvalds1da177e2005-04-16 15:20:36 -07001746 is_audigy = emu->audigy = c->emu10k2_chip;
1747
1748 /* set the DMA transfer mask */
1749 emu->dma_mask = is_audigy ? AUDIGY_DMA_MASK : EMU10K1_DMA_MASK;
1750 if (pci_set_dma_mask(pci, emu->dma_mask) < 0 ||
1751 pci_set_consistent_dma_mask(pci, emu->dma_mask) < 0) {
1752 snd_printk(KERN_ERR "architecture does not support PCI busmaster DMA with mask 0x%lx\n", emu->dma_mask);
1753 kfree(emu);
1754 pci_disable_device(pci);
1755 return -ENXIO;
1756 }
1757 if (is_audigy)
1758 emu->gpr_base = A_FXGPREGBASE;
1759 else
1760 emu->gpr_base = FXGPREGBASE;
1761
1762 if ((err = pci_request_regions(pci, "EMU10K1")) < 0) {
1763 kfree(emu);
1764 pci_disable_device(pci);
1765 return err;
1766 }
1767 emu->port = pci_resource_start(pci, 0);
1768
Takashi Iwai437a5a42006-11-21 12:14:23 +01001769 if (request_irq(pci->irq, snd_emu10k1_interrupt, IRQF_SHARED,
1770 "EMU10K1", emu)) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001771 err = -EBUSY;
1772 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
1774 emu->irq = pci->irq;
1775
1776 emu->max_cache_pages = max_cache_bytes >> PAGE_SHIFT;
1777 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1778 32 * 1024, &emu->ptb_pages) < 0) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001779 err = -ENOMEM;
1780 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 }
1782
Jesper Juhl36726d92007-08-28 15:21:33 +02001783 emu->page_ptr_table = vmalloc(emu->max_cache_pages * sizeof(void *));
1784 emu->page_addr_table = vmalloc(emu->max_cache_pages *
1785 sizeof(unsigned long));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 if (emu->page_ptr_table == NULL || emu->page_addr_table == NULL) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001787 err = -ENOMEM;
1788 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 }
1790
1791 if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(pci),
1792 EMUPAGESIZE, &emu->silent_page) < 0) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001793 err = -ENOMEM;
1794 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 }
1796 emu->memhdr = snd_util_memhdr_new(emu->max_cache_pages * PAGE_SIZE);
1797 if (emu->memhdr == NULL) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001798 err = -ENOMEM;
1799 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 }
Takashi Iwaieb4698f2005-11-17 14:50:13 +01001801 emu->memhdr->block_extra_size = sizeof(struct snd_emu10k1_memblk) -
1802 sizeof(struct snd_util_memblk);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 pci_set_master(pci);
1805
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 emu->fx8010.fxbus_mask = 0x303f;
1807 if (extin_mask == 0)
1808 extin_mask = 0x3fcf;
1809 if (extout_mask == 0)
1810 extout_mask = 0x7fff;
1811 emu->fx8010.extin_mask = extin_mask;
1812 emu->fx8010.extout_mask = extout_mask;
Takashi Iwai09668b42005-11-17 16:14:10 +01001813 emu->enable_ir = enable_ir;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814
James Courtier-Duttond9e8a552007-07-14 10:24:49 +01001815 if (emu->card_capabilities->ca_cardbus_chip) {
1816 if ((err = snd_emu10k1_cardbus_init(emu)) < 0)
1817 goto error;
1818 }
Lee Revell2b637da2005-03-30 13:51:18 +02001819 if (emu->card_capabilities->ecard) {
Takashi Iwai09668b42005-11-17 16:14:10 +01001820 if ((err = snd_emu10k1_ecard_init(emu)) < 0)
1821 goto error;
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001822 } else if (emu->card_capabilities->emu_model) {
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001823 if ((err = snd_emu10k1_emu1010_init(emu)) < 0) {
James Courtier-Dutton19b99fb2005-12-04 18:03:03 +01001824 snd_emu10k1_free(emu);
1825 return err;
1826 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 } else {
1828 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
1829 does not support this, it shouldn't do any harm */
1830 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1831 }
1832
Takashi Iwai09668b42005-11-17 16:14:10 +01001833 /* initialize TRAM setup */
1834 emu->fx8010.itram_size = (16 * 1024)/2;
1835 emu->fx8010.etram_pages.area = NULL;
1836 emu->fx8010.etram_pages.bytes = 0;
1837
1838 /*
1839 * Init to 0x02109204 :
1840 * Clock accuracy = 0 (1000ppm)
1841 * Sample Rate = 2 (48kHz)
1842 * Audio Channel = 1 (Left of 2)
1843 * Source Number = 0 (Unspecified)
1844 * Generation Status = 1 (Original for Cat Code 12)
1845 * Cat Code = 12 (Digital Signal Mixer)
1846 * Mode = 0 (Mode 0)
1847 * Emphasis = 0 (None)
1848 * CP = 1 (Copyright unasserted)
1849 * AN = 0 (Audio data)
1850 * P = 0 (Consumer)
1851 */
1852 emu->spdif_bits[0] = emu->spdif_bits[1] =
1853 emu->spdif_bits[2] = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
1854 SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC |
1855 SPCS_GENERATIONSTATUS | 0x00001200 |
1856 0x00000000 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
1857
1858 emu->reserved_page = (struct snd_emu10k1_memblk *)
1859 snd_emu10k1_synth_alloc(emu, 4096);
1860 if (emu->reserved_page)
1861 emu->reserved_page->map_locked = 1;
1862
1863 /* Clear silent pages and set up pointers */
1864 memset(emu->silent_page.area, 0, PAGE_SIZE);
1865 silent_page = emu->silent_page.addr << 1;
1866 for (idx = 0; idx < MAXPAGES; idx++)
1867 ((u32 *)emu->ptb_pages.area)[idx] = cpu_to_le32(silent_page | idx);
1868
1869 /* set up voice indices */
1870 for (idx = 0; idx < NUM_G; idx++) {
1871 emu->voices[idx].emu = emu;
1872 emu->voices[idx].number = idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 }
1874
Takashi Iwai09668b42005-11-17 16:14:10 +01001875 if ((err = snd_emu10k1_init(emu, enable_ir, 0)) < 0)
1876 goto error;
1877#ifdef CONFIG_PM
1878 if ((err = alloc_pm_buffer(emu)) < 0)
1879 goto error;
1880#endif
1881
1882 /* Initialize the effect engine */
1883 if ((err = snd_emu10k1_init_efx(emu)) < 0)
1884 goto error;
1885 snd_emu10k1_audio_enable(emu);
1886
1887 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, emu, &ops)) < 0)
1888 goto error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +01001890#ifdef CONFIG_PROC_FS
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 snd_emu10k1_proc_init(emu);
Takashi Iwaiadf1b3d2005-12-01 10:49:58 +01001892#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
1894 snd_card_set_dev(card, &pci->dev);
1895 *remu = emu;
1896 return 0;
Takashi Iwai09668b42005-11-17 16:14:10 +01001897
1898 error:
1899 snd_emu10k1_free(emu);
1900 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
Takashi Iwai09668b42005-11-17 16:14:10 +01001903#ifdef CONFIG_PM
1904static unsigned char saved_regs[] = {
1905 CPF, PTRX, CVCF, VTFT, Z1, Z2, PSST, DSL, CCCA, CCR, CLP,
1906 FXRT, MAPA, MAPB, ENVVOL, ATKHLDV, DCYSUSV, LFOVAL1, ENVVAL,
1907 ATKHLDM, DCYSUSM, LFOVAL2, IP, IFATN, PEFE, FMMOD, TREMFRQ, FM2FRQ2,
1908 TEMPENV, ADCCR, FXWC, MICBA, ADCBA, FXBA,
1909 MICBS, ADCBS, FXBS, CDCS, GPSCS, SPCS0, SPCS1, SPCS2,
1910 SPBYPASS, AC97SLOT, CDSRCS, GPSRCS, ZVSRCS, MICIDX, ADCIDX, FXIDX,
1911 0xff /* end */
1912};
1913static unsigned char saved_regs_audigy[] = {
1914 A_ADCIDX, A_MICIDX, A_FXWC1, A_FXWC2, A_SAMPLE_RATE,
1915 A_FXRT2, A_SENDAMOUNTS, A_FXRT1,
1916 0xff /* end */
1917};
1918
1919static int __devinit alloc_pm_buffer(struct snd_emu10k1 *emu)
1920{
1921 int size;
1922
1923 size = ARRAY_SIZE(saved_regs);
1924 if (emu->audigy)
1925 size += ARRAY_SIZE(saved_regs_audigy);
1926 emu->saved_ptr = vmalloc(4 * NUM_G * size);
1927 if (! emu->saved_ptr)
1928 return -ENOMEM;
1929 if (snd_emu10k1_efx_alloc_pm_buffer(emu) < 0)
1930 return -ENOMEM;
1931 if (emu->card_capabilities->ca0151_chip &&
1932 snd_p16v_alloc_pm_buffer(emu) < 0)
1933 return -ENOMEM;
1934 return 0;
1935}
1936
1937static void free_pm_buffer(struct snd_emu10k1 *emu)
1938{
1939 vfree(emu->saved_ptr);
1940 snd_emu10k1_efx_free_pm_buffer(emu);
1941 if (emu->card_capabilities->ca0151_chip)
1942 snd_p16v_free_pm_buffer(emu);
1943}
1944
1945void snd_emu10k1_suspend_regs(struct snd_emu10k1 *emu)
1946{
1947 int i;
1948 unsigned char *reg;
1949 unsigned int *val;
1950
1951 val = emu->saved_ptr;
1952 for (reg = saved_regs; *reg != 0xff; reg++)
1953 for (i = 0; i < NUM_G; i++, val++)
1954 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1955 if (emu->audigy) {
1956 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1957 for (i = 0; i < NUM_G; i++, val++)
1958 *val = snd_emu10k1_ptr_read(emu, *reg, i);
1959 }
1960 if (emu->audigy)
1961 emu->saved_a_iocfg = inl(emu->port + A_IOCFG);
1962 emu->saved_hcfg = inl(emu->port + HCFG);
1963}
1964
1965void snd_emu10k1_resume_init(struct snd_emu10k1 *emu)
1966{
James Courtier-Duttond9e8a552007-07-14 10:24:49 +01001967 if (emu->card_capabilities->ca_cardbus_chip)
1968 snd_emu10k1_cardbus_init(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001969 if (emu->card_capabilities->ecard)
1970 snd_emu10k1_ecard_init(emu);
James Courtier-Dutton190d2c42007-11-04 14:08:26 +00001971 else if (emu->card_capabilities->emu_model)
James Courtier-Dutton9f4bd5d2006-10-01 10:48:04 +01001972 snd_emu10k1_emu1010_init(emu);
Takashi Iwai09668b42005-11-17 16:14:10 +01001973 else
1974 snd_emu10k1_ptr_write(emu, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
1975 snd_emu10k1_init(emu, emu->enable_ir, 1);
1976}
1977
1978void snd_emu10k1_resume_regs(struct snd_emu10k1 *emu)
1979{
1980 int i;
1981 unsigned char *reg;
1982 unsigned int *val;
1983
1984 snd_emu10k1_audio_enable(emu);
1985
1986 /* resore for spdif */
1987 if (emu->audigy)
Arnaud Patard4130d592006-10-04 18:21:05 +02001988 outl(emu->saved_a_iocfg, emu->port + A_IOCFG);
1989 outl(emu->saved_hcfg, emu->port + HCFG);
Takashi Iwai09668b42005-11-17 16:14:10 +01001990
1991 val = emu->saved_ptr;
1992 for (reg = saved_regs; *reg != 0xff; reg++)
1993 for (i = 0; i < NUM_G; i++, val++)
1994 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1995 if (emu->audigy) {
1996 for (reg = saved_regs_audigy; *reg != 0xff; reg++)
1997 for (i = 0; i < NUM_G; i++, val++)
1998 snd_emu10k1_ptr_write(emu, *reg, i, *val);
1999 }
2000}
2001#endif