1 | /* $Id: main.c 142 2000-04-23 14:55:46Z ktk $ */
|
---|
2 |
|
---|
3 |
|
---|
4 | /*
|
---|
5 | **********************************************************************
|
---|
6 | * main.c - Creative EMU10K1 audio driver
|
---|
7 | * Copyright 1999, 2000 Creative Labs, Inc.
|
---|
8 | *
|
---|
9 | **********************************************************************
|
---|
10 | *
|
---|
11 | * Date Author Summary of changes
|
---|
12 | * ---- ------ ------------------
|
---|
13 | * October 20, 1999 Bertrand Lee base code release
|
---|
14 | * November 2, 1999 Alan Cox cleaned up stuff
|
---|
15 | *
|
---|
16 | **********************************************************************
|
---|
17 | *
|
---|
18 | * This program is free software; you can redistribute it and/or
|
---|
19 | * modify it under the terms of the GNU General Public License as
|
---|
20 | * published by the Free Software Foundation; either version 2 of
|
---|
21 | * the License, or (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
|
---|
29 | * License along with this program; if not, write to the Free
|
---|
30 | * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
|
---|
31 | * USA.
|
---|
32 | *
|
---|
33 | **********************************************************************
|
---|
34 | *
|
---|
35 | * Supported devices:
|
---|
36 | * /dev/dsp: Standard /dev/dsp device, OSS-compatible
|
---|
37 | * /dev/mixer: Standard /dev/mixer device, OSS-compatible
|
---|
38 | * /dev/midi: Raw MIDI UART device, mostly OSS-compatible
|
---|
39 | *
|
---|
40 | * Revision history:
|
---|
41 | * 0.1 beta Initial release
|
---|
42 | * 0.2 Lowered initial mixer vol. Improved on stuttering wave playback. Added MIDI UART support.
|
---|
43 | * 0.3 Fixed mixer routing bug, added APS, joystick support.
|
---|
44 | * 0.4 Added rear-channel, SPDIF support.
|
---|
45 | * 0.5 Source cleanup, SMP fixes, multiopen support, 64 bit arch fixes,
|
---|
46 | * moved bh's to tasklets, moved to the new PCI driver initialization style.
|
---|
47 | **********************************************************************
|
---|
48 | */
|
---|
49 |
|
---|
50 | /* These are only included once per module */
|
---|
51 | #include <linux/module.h>
|
---|
52 | #include <linux/init.h>
|
---|
53 |
|
---|
54 | #include "hwaccess.h"
|
---|
55 | #include "efxmgr.h"
|
---|
56 | #include "cardwo.h"
|
---|
57 | #include "cardwi.h"
|
---|
58 | #include "cardmo.h"
|
---|
59 | #include "cardmi.h"
|
---|
60 | #include "recmgr.h"
|
---|
61 |
|
---|
62 | #define DRIVER_VERSION "0.5"
|
---|
63 |
|
---|
64 | /* FIXME: is this right? */
|
---|
65 | #define EMU10K1_DMA_MASK 0xffffffff /* DMA buffer mask for pci_alloc_consist */
|
---|
66 |
|
---|
67 | #ifndef PCI_VENDOR_ID_CREATIVE
|
---|
68 | #define PCI_VENDOR_ID_CREATIVE 0x1102
|
---|
69 | #endif
|
---|
70 |
|
---|
71 | #ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
|
---|
72 | #define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002
|
---|
73 | #endif
|
---|
74 |
|
---|
75 | #define EMU10K1_EXTENT 0x20 /* 32 byte I/O space */
|
---|
76 |
|
---|
77 | enum {
|
---|
78 | EMU10K1 = 0,
|
---|
79 | };
|
---|
80 |
|
---|
81 | static char *card_names[] __devinitdata = {
|
---|
82 | "EMU10K1",
|
---|
83 | };
|
---|
84 |
|
---|
85 | static struct pci_device_id emu10k1_pci_tbl[] __initdata = {
|
---|
86 | {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_EMU10K1,
|
---|
87 | PCI_ANY_ID, PCI_ANY_ID, 0, 0, EMU10K1},
|
---|
88 | {0,}
|
---|
89 | };
|
---|
90 |
|
---|
91 | MODULE_DEVICE_TABLE(pci, emu10k1_pci_tbl);
|
---|
92 |
|
---|
93 | /* Global var instantiation */
|
---|
94 |
|
---|
95 | LIST_HEAD(emu10k1_devs);
|
---|
96 |
|
---|
97 | extern struct file_operations emu10k1_audio_fops;
|
---|
98 | extern struct file_operations emu10k1_mixer_fops;
|
---|
99 | extern struct file_operations emu10k1_midi_fops;
|
---|
100 |
|
---|
101 | extern void emu10k1_interrupt(int, void *, struct pt_regs *s);
|
---|
102 | extern int emu10k1_mixer_wrch(struct emu10k1_card *, unsigned int, int);
|
---|
103 |
|
---|
104 | static int __devinit audio_init(struct emu10k1_card *card)
|
---|
105 | {
|
---|
106 | if ((card->waveout = kmalloc(sizeof(struct emu10k1_waveout), GFP_KERNEL)) == NULL) {
|
---|
107 | printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_waveout: out of memory\n");
|
---|
108 | return CTSTATUS_ERROR;
|
---|
109 | }
|
---|
110 | memset(card->waveout, 0, sizeof(struct emu10k1_waveout));
|
---|
111 |
|
---|
112 | /* Assign default global volume, reverb, chorus */
|
---|
113 | card->waveout->globalvol = 0xffffffff;
|
---|
114 | card->waveout->left = 0xffff;
|
---|
115 | card->waveout->right = 0xffff;
|
---|
116 | card->waveout->mute = 0;
|
---|
117 | card->waveout->globalreverb = 0xffffffff;
|
---|
118 | card->waveout->globalchorus = 0xffffffff;
|
---|
119 |
|
---|
120 | if ((card->wavein = kmalloc(sizeof(struct emu10k1_wavein), GFP_KERNEL))
|
---|
121 | == NULL) {
|
---|
122 | printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_wavein: out of memory\n");
|
---|
123 | return CTSTATUS_ERROR;
|
---|
124 | }
|
---|
125 | memset(card->wavein, 0, sizeof(struct emu10k1_wavein));
|
---|
126 |
|
---|
127 | card->wavein->recsrc = WAVERECORD_AC97;
|
---|
128 |
|
---|
129 | return CTSTATUS_SUCCESS;
|
---|
130 | }
|
---|
131 |
|
---|
132 | static void __devinit mixer_init(struct emu10k1_card *card)
|
---|
133 | {
|
---|
134 | int count;
|
---|
135 | struct initvol {
|
---|
136 | int mixch;
|
---|
137 | int vol;
|
---|
138 | } initvol[] = {
|
---|
139 | {
|
---|
140 | SOUND_MIXER_VOLUME, 0x5050}, {
|
---|
141 | SOUND_MIXER_OGAIN, 0x3232}, {
|
---|
142 | SOUND_MIXER_SPEAKER, 0x3232}, {
|
---|
143 | SOUND_MIXER_PHONEIN, 0x3232}, {
|
---|
144 | SOUND_MIXER_MIC, 0x0000}, {
|
---|
145 | SOUND_MIXER_LINE, 0x0000}, {
|
---|
146 | SOUND_MIXER_CD, 0x3232}, {
|
---|
147 | SOUND_MIXER_LINE1, 0x3232}, {
|
---|
148 | SOUND_MIXER_LINE3, 0x3232}, {
|
---|
149 | SOUND_MIXER_DIGITAL1, 0x6464}, {
|
---|
150 | SOUND_MIXER_DIGITAL2, 0x6464}, {
|
---|
151 | SOUND_MIXER_PCM, 0x6464}, {
|
---|
152 | SOUND_MIXER_RECLEV, 0x3232}, {
|
---|
153 | SOUND_MIXER_TREBLE, 0x3232}, {
|
---|
154 | SOUND_MIXER_BASS, 0x3232}, {
|
---|
155 | SOUND_MIXER_LINE2, 0x4b4b}};
|
---|
156 |
|
---|
157 | int initdig[] = { 0, 1, 2, 3, 6, 7, 18, 19, 20, 21, 24, 25, 72, 73, 74, 75, 78, 79,
|
---|
158 | 94, 95
|
---|
159 | };
|
---|
160 |
|
---|
161 | /* Reset */
|
---|
162 | sblive_writeac97(card, AC97_RESET, 0);
|
---|
163 |
|
---|
164 |
|
---|
165 | #if 0
|
---|
166 | /* Check status word */
|
---|
167 | {
|
---|
168 | u16 reg;
|
---|
169 |
|
---|
170 | sblive_readac97(card, AC97_RESET, ®);
|
---|
171 | DPD(2, "RESET 0x%x\n", reg);
|
---|
172 | sblive_readac97(card, AC97_MASTERTONE, ®);
|
---|
173 | DPD(2, "MASTER_TONE 0x%x\n", reg);
|
---|
174 | }
|
---|
175 | #endif
|
---|
176 |
|
---|
177 | /* Set default recording source to mic in */
|
---|
178 | sblive_writeac97(card, AC97_RECORDSELECT, 0);
|
---|
179 |
|
---|
180 | /* Set default AC97 "PCM" volume to acceptable max */
|
---|
181 | //sblive_writeac97(card, AC97_PCMOUTVOLUME, 0);
|
---|
182 | //sblive_writeac97(card, AC97_LINE2, 0);
|
---|
183 |
|
---|
184 | /* Set default volumes for all mixer channels */
|
---|
185 |
|
---|
186 | for (count = 0; count < sizeof(card->digmix) / sizeof(card->digmix[0]); count++) {
|
---|
187 | card->digmix[count] = 0x80000000;
|
---|
188 | sblive_writeptr(card, FXGPREGBASE + 0x10 + count, 0, 0);
|
---|
189 | }
|
---|
190 |
|
---|
191 | for (count = 0; count < sizeof(initdig) / sizeof(initdig[0]); count++) {
|
---|
192 | card->digmix[initdig[count]] = 0x7fffffff;
|
---|
193 | sblive_writeptr(card, FXGPREGBASE + 0x10 + initdig[count], 0, 0x7fffffff);
|
---|
194 | }
|
---|
195 |
|
---|
196 | for (count = 0; count < sizeof(initvol) / sizeof(initvol[0]); count++) {
|
---|
197 | emu10k1_mixer_wrch(card, initvol[count].mixch, initvol[count].vol);
|
---|
198 | }
|
---|
199 |
|
---|
200 | card->modcnt = 0; // Should this be here or in open() ?
|
---|
201 |
|
---|
202 | return;
|
---|
203 | }
|
---|
204 |
|
---|
205 | static int __devinit midi_init(struct emu10k1_card *card)
|
---|
206 | {
|
---|
207 | if ((card->mpuout = kmalloc(sizeof(struct emu10k1_mpuout), GFP_KERNEL))
|
---|
208 | == NULL) {
|
---|
209 | printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n");
|
---|
210 | return CTSTATUS_ERROR;
|
---|
211 | }
|
---|
212 |
|
---|
213 | memset(card->mpuout, 0, sizeof(struct emu10k1_mpuout));
|
---|
214 |
|
---|
215 | card->mpuout->intr = 1;
|
---|
216 | card->mpuout->status = FLAGS_AVAILABLE;
|
---|
217 | card->mpuout->state = CARDMIDIOUT_STATE_DEFAULT;
|
---|
218 |
|
---|
219 | tasklet_init(&card->mpuout->tasklet, emu10k1_mpuout_bh, (unsigned long) card);
|
---|
220 |
|
---|
221 | spin_lock_init(&card->mpuout->lock);
|
---|
222 |
|
---|
223 | if ((card->mpuin = kmalloc(sizeof(struct emu10k1_mpuin), GFP_KERNEL)) == NULL) {
|
---|
224 | kfree(card->mpuout);
|
---|
225 | printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n");
|
---|
226 | return CTSTATUS_ERROR;
|
---|
227 | }
|
---|
228 |
|
---|
229 | memset(card->mpuin, 0, sizeof(struct emu10k1_mpuin));
|
---|
230 |
|
---|
231 | card->mpuin->status = FLAGS_AVAILABLE;
|
---|
232 |
|
---|
233 | tasklet_init(&card->mpuin->tasklet, emu10k1_mpuin_bh, (unsigned long) card->mpuin);
|
---|
234 |
|
---|
235 | spin_lock_init(&card->mpuin->lock);
|
---|
236 |
|
---|
237 | /* Reset the MPU port */
|
---|
238 | if (emu10k1_mpu_reset(card) != CTSTATUS_SUCCESS) {
|
---|
239 | ERROR();
|
---|
240 | return CTSTATUS_ERROR;
|
---|
241 | }
|
---|
242 |
|
---|
243 | return CTSTATUS_SUCCESS;
|
---|
244 | }
|
---|
245 |
|
---|
246 | static void __devinit voice_init(struct emu10k1_card *card)
|
---|
247 | {
|
---|
248 | struct voice_manager *voicemgr = &card->voicemgr;
|
---|
249 | struct emu_voice *voice;
|
---|
250 | int i;
|
---|
251 |
|
---|
252 | voicemgr->card = card;
|
---|
253 | voicemgr->lock = SPIN_LOCK_UNLOCKED;
|
---|
254 |
|
---|
255 | voice = voicemgr->voice;
|
---|
256 | for (i = 0; i < NUM_G; i++) {
|
---|
257 | voice->card = card;
|
---|
258 | voice->usage = VOICEMGR_USAGE_FREE;
|
---|
259 | voice->num = i;
|
---|
260 | voice->linked_voice = NULL;
|
---|
261 | voice++;
|
---|
262 | }
|
---|
263 |
|
---|
264 | return;
|
---|
265 | }
|
---|
266 |
|
---|
267 | static void __devinit timer_init(struct emu10k1_card *card)
|
---|
268 | {
|
---|
269 | INIT_LIST_HEAD(&card->timers);
|
---|
270 | card->timer_delay = TIMER_STOPPED;
|
---|
271 | card->timer_lock = SPIN_LOCK_UNLOCKED;
|
---|
272 |
|
---|
273 | return;
|
---|
274 | }
|
---|
275 |
|
---|
276 | static void __devinit addxmgr_init(struct emu10k1_card *card)
|
---|
277 | {
|
---|
278 | u32 count;
|
---|
279 |
|
---|
280 | for (count = 0; count < MAXPAGES; count++)
|
---|
281 | card->emupagetable[count] = 0;
|
---|
282 |
|
---|
283 | /* Mark first page as used */
|
---|
284 | /* This page is reserved by the driver */
|
---|
285 | card->emupagetable[0] = 0x8001;
|
---|
286 | card->emupagetable[1] = MAXPAGES - RESERVED - 1;
|
---|
287 |
|
---|
288 | return;
|
---|
289 | }
|
---|
290 |
|
---|
291 | static void __devinit fx_init(struct emu10k1_card *card)
|
---|
292 | {
|
---|
293 | int i, j, k, l;
|
---|
294 | u32 pc = 0;
|
---|
295 |
|
---|
296 | for (i = 0; i < 512; i++)
|
---|
297 | OP(6, 0x40, 0x40, 0x40, 0x40);
|
---|
298 |
|
---|
299 | for (i = 0; i < 256; i++)
|
---|
300 | sblive_writeptr(card, FXGPREGBASE + i, 0, 0);
|
---|
301 |
|
---|
302 | pc = 0;
|
---|
303 |
|
---|
304 | for (j = 0; j < 2; j++) {
|
---|
305 |
|
---|
306 | OP(4, 0x100, 0x40, j, 0x44);
|
---|
307 | OP(4, 0x101, 0x40, j + 2, 0x44);
|
---|
308 |
|
---|
309 | for (i = 0; i < 6; i++) {
|
---|
310 | k = i * 18 + j;
|
---|
311 | OP(0, 0x102, 0x40, 0x110 + k, 0x100);
|
---|
312 | OP(0, 0x102, 0x102, 0x112 + k, 0x101);
|
---|
313 | OP(0, 0x102, 0x102, 0x114 + k, 0x10 + j);
|
---|
314 | OP(0, 0x102, 0x102, 0x116 + k, 0x12 + j);
|
---|
315 | OP(0, 0x102, 0x102, 0x118 + k, 0x14 + j);
|
---|
316 | OP(0, 0x102, 0x102, 0x11a + k, 0x16 + j);
|
---|
317 | OP(0, 0x102, 0x102, 0x11c + k, 0x18 + j);
|
---|
318 | OP(0, 0x102, 0x102, 0x11e + k, 0x1a + j);
|
---|
319 | OP(0, 0x102, 0x102, 0x120 + k, 0x1c + j);
|
---|
320 |
|
---|
321 | k = 0x1a0 + i * 8 + j * 4;
|
---|
322 | OP(0, 0x40, 0x40, 0x102, 0x180 + j);
|
---|
323 | OP(7, k + 1, k, k + 1, 0x184 + j);
|
---|
324 | OP(7, k, 0x102, k, 0x182 + j);
|
---|
325 | OP(7, k + 3, k + 2, k + 3, 0x188 + j);
|
---|
326 | OP(0, k + 2, 0x56, k + 2, 0x186 + j);
|
---|
327 | OP(6, k + 2, k + 2, k + 2, 0x40);
|
---|
328 |
|
---|
329 | l = 0x1d0 + i * 8 + j * 4;
|
---|
330 | OP(0, 0x40, 0x40, k + 2, 0x190 + j);
|
---|
331 | OP(7, l + 1, l, l + 1, 0x194 + j);
|
---|
332 | OP(7, l, k + 2, l, 0x192 + j);
|
---|
333 | OP(7, l + 3, l + 2, l + 3, 0x198 + j);
|
---|
334 | OP(0, l + 2, 0x56, l + 2, 0x196 + j);
|
---|
335 | OP(4, l + 2, 0x40, l + 2, 0x46);
|
---|
336 |
|
---|
337 | OP(6, 0x20 + (i * 2) + j, l + 2, 0x40, 0x40);
|
---|
338 |
|
---|
339 | if (i == 0)
|
---|
340 | OP(0, 0x20 + (i * 2) + j, 0x40, l + 2, 0x4e); /* FIXME: Is this really needed? */
|
---|
341 | else
|
---|
342 | OP(6, 0x20 + (i * 2) + j, l + 2, 0x40, 0x40);
|
---|
343 | }
|
---|
344 | }
|
---|
345 | sblive_writeptr(card, DBG, 0, 0);
|
---|
346 |
|
---|
347 | return;
|
---|
348 | }
|
---|
349 |
|
---|
350 | static int __devinit hw_init(struct emu10k1_card *card)
|
---|
351 | {
|
---|
352 | int nCh;
|
---|
353 |
|
---|
354 | #ifdef TANKMEM
|
---|
355 | u32 size = 0;
|
---|
356 | #endif
|
---|
357 | u32 sizeIdx = 0;
|
---|
358 | u32 pagecount, tmp;
|
---|
359 |
|
---|
360 | /* Disable audio and lock cache */
|
---|
361 | sblive_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE | HCFG_MUTEBUTTONENABLE);
|
---|
362 |
|
---|
363 | /* Reset recording buffers */
|
---|
364 | sblive_writeptr(card, MICBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
365 | sblive_writeptr(card, MICBA, 0, 0);
|
---|
366 | sblive_writeptr(card, FXBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
367 | sblive_writeptr(card, FXBA, 0, 0);
|
---|
368 | sblive_writeptr(card, ADCBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
369 | sblive_writeptr(card, ADCBA, 0, 0);
|
---|
370 |
|
---|
371 | /* Disable channel interrupt */
|
---|
372 | sblive_writefn0(card, INTE, DISABLE);
|
---|
373 | sblive_writeptr(card, CLIEL, 0, 0);
|
---|
374 | sblive_writeptr(card, CLIEH, 0, 0);
|
---|
375 | sblive_writeptr(card, SOLEL, 0, 0);
|
---|
376 | sblive_writeptr(card, SOLEH, 0, 0);
|
---|
377 |
|
---|
378 | /* Init envelope engine */
|
---|
379 | for (nCh = 0; nCh < NUM_G; nCh++) {
|
---|
380 | sblive_writeptr(card, DCYSUSV, nCh, ENV_OFF);
|
---|
381 | sblive_writeptr(card, IP, nCh, 0);
|
---|
382 | sblive_writeptr(card, VTFT, nCh, 0xffff);
|
---|
383 | sblive_writeptr(card, CVCF, nCh, 0xffff);
|
---|
384 | sblive_writeptr(card, PTRX, nCh, 0);
|
---|
385 | sblive_writeptr(card, CPF, nCh, 0);
|
---|
386 | sblive_writeptr(card, CCR, nCh, 0);
|
---|
387 |
|
---|
388 | sblive_writeptr(card, PSST, nCh, 0);
|
---|
389 | sblive_writeptr(card, DSL, nCh, 0x10);
|
---|
390 | sblive_writeptr(card, CCCA, nCh, 0);
|
---|
391 | sblive_writeptr(card, Z1, nCh, 0);
|
---|
392 | sblive_writeptr(card, Z2, nCh, 0);
|
---|
393 | sblive_writeptr(card, FXRT, nCh, 0xd01c0000);
|
---|
394 |
|
---|
395 | sblive_writeptr(card, ATKHLDM, nCh, 0);
|
---|
396 | sblive_writeptr(card, DCYSUSM, nCh, 0);
|
---|
397 | sblive_writeptr(card, IFATN, nCh, 0xffff);
|
---|
398 | sblive_writeptr(card, PEFE, nCh, 0);
|
---|
399 | sblive_writeptr(card, FMMOD, nCh, 0);
|
---|
400 | sblive_writeptr(card, TREMFRQ, nCh, 24); /* 1 Hz */
|
---|
401 | sblive_writeptr(card, FM2FRQ2, nCh, 24); /* 1 Hz */
|
---|
402 | sblive_writeptr(card, TEMPENV, nCh, 0);
|
---|
403 |
|
---|
404 | /*** These are last so OFF prevents writing ***/
|
---|
405 | sblive_writeptr(card, LFOVAL2, nCh, 0);
|
---|
406 | sblive_writeptr(card, LFOVAL1, nCh, 0);
|
---|
407 | sblive_writeptr(card, ATKHLDV, nCh, 0);
|
---|
408 | sblive_writeptr(card, ENVVOL, nCh, 0);
|
---|
409 | sblive_writeptr(card, ENVVAL, nCh, 0);
|
---|
410 | }
|
---|
411 |
|
---|
412 | /*
|
---|
413 | ** Init to 0x02109204 :
|
---|
414 | ** Clock accuracy = 0 (1000ppm)
|
---|
415 | ** Sample Rate = 2 (48kHz)
|
---|
416 | ** Audio Channel = 1 (Left of 2)
|
---|
417 | ** Source Number = 0 (Unspecified)
|
---|
418 | ** Generation Status = 1 (Original for Cat Code 12)
|
---|
419 | ** Cat Code = 12 (Digital Signal Mixer)
|
---|
420 | ** Mode = 0 (Mode 0)
|
---|
421 | ** Emphasis = 0 (None)
|
---|
422 | ** CP = 1 (Copyright unasserted)
|
---|
423 | ** AN = 0 (Digital audio)
|
---|
424 | ** P = 0 (Consumer)
|
---|
425 | */
|
---|
426 |
|
---|
427 | /* SPDIF0 */
|
---|
428 | sblive_writeptr(card, SPCS0, 0, SPCS_CLKACCY_1000PPM | 0x002000000 |
|
---|
429 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
---|
430 |
|
---|
431 | /* SPDIF1 */
|
---|
432 | sblive_writeptr(card, SPCS1, 0, SPCS_CLKACCY_1000PPM | 0x002000000 |
|
---|
433 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
---|
434 |
|
---|
435 | /* SPDIF2 & SPDIF3 */
|
---|
436 | sblive_writeptr(card, SPCS2, 0, SPCS_CLKACCY_1000PPM | 0x002000000 |
|
---|
437 | SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT);
|
---|
438 |
|
---|
439 | fx_init(card); /* initialize effects engine */
|
---|
440 |
|
---|
441 | card->tankmem = NULL;
|
---|
442 |
|
---|
443 | #ifdef TANKMEM
|
---|
444 | size = TMEMSIZE;
|
---|
445 | sizeIdx = TMEMSIZEREG;
|
---|
446 | while (size > 16384) {
|
---|
447 | if ((card->tankmem = emu10k1_alloc_memphysical(size)) != NULL)
|
---|
448 | break;
|
---|
449 |
|
---|
450 | size /= 2;
|
---|
451 | sizeIdx -= 1;
|
---|
452 | }
|
---|
453 |
|
---|
454 | if (card->tankmem == NULL) {
|
---|
455 | card->tmemsize = 0;
|
---|
456 | return CTSTATUS_ERROR;
|
---|
457 | }
|
---|
458 |
|
---|
459 | card->tmemsize = size;
|
---|
460 | #else /* !TANKMEM */
|
---|
461 | card->tmemsize = 0;
|
---|
462 | #endif /* TANKMEM */
|
---|
463 |
|
---|
464 | if ((card->virtualpagetable = emu10k1_alloc_memphysical((MAXPAGES - RESERVED) * sizeof(u32))) == NULL) {
|
---|
465 | ERROR();
|
---|
466 | emu10k1_free_memphysical(card->tankmem);
|
---|
467 | return CTSTATUS_ERROR;
|
---|
468 | }
|
---|
469 |
|
---|
470 | if ((card->silentpage = emu10k1_alloc_memphysical(EMUPAGESIZE)) == NULL) {
|
---|
471 | ERROR();
|
---|
472 | emu10k1_free_memphysical(card->tankmem);
|
---|
473 | emu10k1_free_memphysical(card->virtualpagetable);
|
---|
474 | return CTSTATUS_ERROR;
|
---|
475 | } else
|
---|
476 | memset(card->silentpage->virtaddx, 0, EMUPAGESIZE);
|
---|
477 |
|
---|
478 | for (pagecount = 0; pagecount < (MAXPAGES - RESERVED); pagecount++)
|
---|
479 |
|
---|
480 | ((u32 *) card->virtualpagetable->virtaddx)[pagecount] = (card->silentpage->busaddx * 2) | pagecount;
|
---|
481 |
|
---|
482 | /* Init page table & tank memory base register */
|
---|
483 | sblive_writeptr(card, PTB, 0, card->virtualpagetable->busaddx);
|
---|
484 | #ifdef TANKMEM
|
---|
485 | sblive_writeptr(card, TCB, 0, card->tankmem->busaddx);
|
---|
486 | #else
|
---|
487 | sblive_writeptr(card, TCB, 0, 0);
|
---|
488 | #endif
|
---|
489 | sblive_writeptr(card, TCBS, 0, sizeIdx);
|
---|
490 |
|
---|
491 | for (nCh = 0; nCh < NUM_G; nCh++) {
|
---|
492 | sblive_writeptr(card, MAPA, nCh, MAP_PTI_MASK | (card->silentpage->busaddx * 2));
|
---|
493 | sblive_writeptr(card, MAPB, nCh, MAP_PTI_MASK | (card->silentpage->busaddx * 2));
|
---|
494 | }
|
---|
495 |
|
---|
496 | /* Hokay, now enable the AUD bit */
|
---|
497 | /* Enable Audio = 1 */
|
---|
498 | /* Mute Disable Audio = 0 */
|
---|
499 | /* Lock Tank Memory = 1 */
|
---|
500 | /* Lock Sound Memory = 0 */
|
---|
501 | /* Auto Mute = 1 */
|
---|
502 |
|
---|
503 | sblive_rmwac97(card, AC97_MASTERVOLUME, 0x8000, 0x8000);
|
---|
504 |
|
---|
505 | sblive_writeac97(card, AC97_MASTERVOLUME, 0);
|
---|
506 | sblive_writeac97(card, AC97_PCMOUTVOLUME, 0);
|
---|
507 |
|
---|
508 | sblive_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE | HCFG_AUTOMUTE | HCFG_JOYENABLE);
|
---|
509 |
|
---|
510 | /* TOSLink detection */
|
---|
511 | card->has_toslink = 0;
|
---|
512 |
|
---|
513 | tmp = sblive_readfn0(card, HCFG);
|
---|
514 | if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
|
---|
515 | sblive_writefn0(card, HCFG, tmp | 0x800);
|
---|
516 |
|
---|
517 | udelay(512);
|
---|
518 |
|
---|
519 | if (tmp != (sblive_readfn0(card, HCFG) & ~0x800)) {
|
---|
520 | card->has_toslink = 1;
|
---|
521 | sblive_writefn0(card, HCFG, tmp);
|
---|
522 | }
|
---|
523 | }
|
---|
524 |
|
---|
525 | return CTSTATUS_SUCCESS;
|
---|
526 | }
|
---|
527 |
|
---|
528 | static int __devinit emu10k1_init(struct emu10k1_card *card)
|
---|
529 | {
|
---|
530 | /* Init Card */
|
---|
531 | if (hw_init(card) != CTSTATUS_SUCCESS)
|
---|
532 | return CTSTATUS_ERROR;
|
---|
533 |
|
---|
534 |
|
---|
535 | voice_init(card);
|
---|
536 | timer_init(card);
|
---|
537 | addxmgr_init(card);
|
---|
538 |
|
---|
539 | DPD(2, " hw control register -> %x\n", sblive_readfn0(card, HCFG));
|
---|
540 |
|
---|
541 | return CTSTATUS_SUCCESS;
|
---|
542 | }
|
---|
543 |
|
---|
544 | static void __devexit audio_exit(struct emu10k1_card *card)
|
---|
545 | {
|
---|
546 | kfree(card->waveout);
|
---|
547 | kfree(card->wavein);
|
---|
548 | return;
|
---|
549 | }
|
---|
550 |
|
---|
551 | static void __devexit midi_exit(struct emu10k1_card *card)
|
---|
552 | {
|
---|
553 | tasklet_unlock_wait(&card->mpuout->tasklet);
|
---|
554 | kfree(card->mpuout);
|
---|
555 |
|
---|
556 | tasklet_unlock_wait(&card->mpuin->tasklet);
|
---|
557 | kfree(card->mpuin);
|
---|
558 |
|
---|
559 | return;
|
---|
560 | }
|
---|
561 |
|
---|
562 | static void __devexit emu10k1_exit(struct emu10k1_card *card)
|
---|
563 | {
|
---|
564 | int ch;
|
---|
565 |
|
---|
566 | sblive_writefn0(card, INTE, DISABLE);
|
---|
567 |
|
---|
568 | /** Shutdown the chip **/
|
---|
569 | for (ch = 0; ch < NUM_G; ch++)
|
---|
570 | sblive_writeptr(card, DCYSUSV, ch, ENV_OFF);
|
---|
571 |
|
---|
572 | for (ch = 0; ch < NUM_G; ch++) {
|
---|
573 | sblive_writeptr(card, VTFT, ch, 0);
|
---|
574 | sblive_writeptr(card, CVCF, ch, 0);
|
---|
575 | sblive_writeptr(card, PTRX, ch, 0);
|
---|
576 | sblive_writeptr(card, CPF, ch, 0);
|
---|
577 | }
|
---|
578 |
|
---|
579 | /* Reset recording buffers */
|
---|
580 | sblive_writeptr(card, MICBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
581 | sblive_writeptr(card, MICBA, 0, 0);
|
---|
582 | sblive_writeptr(card, FXBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
583 | sblive_writeptr(card, FXBA, 0, 0);
|
---|
584 | sblive_writeptr(card, FXWC, 0, 0);
|
---|
585 | sblive_writeptr(card, ADCBS, 0, ADCBS_BUFSIZE_NONE);
|
---|
586 | sblive_writeptr(card, ADCBA, 0, 0);
|
---|
587 | sblive_writeptr(card, TCBS, 0, TCBS_BUFFSIZE_16K);
|
---|
588 | sblive_writeptr(card, TCB, 0, 0);
|
---|
589 | sblive_writeptr(card, DBG, 0, 0x8000);
|
---|
590 |
|
---|
591 | /* Disable channel interrupt */
|
---|
592 | sblive_writeptr(card, CLIEL, 0, 0);
|
---|
593 | sblive_writeptr(card, CLIEH, 0, 0);
|
---|
594 | sblive_writeptr(card, SOLEL, 0, 0);
|
---|
595 | sblive_writeptr(card, SOLEH, 0, 0);
|
---|
596 |
|
---|
597 | /* Disable audio and lock cache */
|
---|
598 | sblive_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE | HCFG_MUTEBUTTONENABLE);
|
---|
599 | sblive_writeptr(card, PTB, 0, 0);
|
---|
600 |
|
---|
601 | emu10k1_free_memphysical(card->silentpage);
|
---|
602 | emu10k1_free_memphysical(card->virtualpagetable);
|
---|
603 | #ifdef TANKMEM
|
---|
604 | emu10k1_free_memphysical(card->tankmem);
|
---|
605 | #endif
|
---|
606 | return;
|
---|
607 | }
|
---|
608 |
|
---|
609 | /* Driver initialization routine */
|
---|
610 | static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
|
---|
611 | {
|
---|
612 | struct emu10k1_card *card;
|
---|
613 |
|
---|
614 | if ((card = kmalloc(sizeof(struct emu10k1_card), GFP_KERNEL)) == NULL) {
|
---|
615 | printk(KERN_ERR "emu10k1: out of memory\n");
|
---|
616 | return -ENOMEM;
|
---|
617 | }
|
---|
618 | memset(card, 0, sizeof(struct emu10k1_card));
|
---|
619 |
|
---|
620 | #if LINUX_VERSION_CODE > 0x020320
|
---|
621 | if (!pci_dma_supported(pci_dev, EMU10K1_DMA_MASK)) {
|
---|
622 | printk(KERN_ERR "emu10k1: architecture does not support 32bit PCI busmaster DMA\n");
|
---|
623 | kfree(card);
|
---|
624 | return -ENODEV;
|
---|
625 | }
|
---|
626 |
|
---|
627 | if (pci_enable_device(pci_dev)) {
|
---|
628 | printk(KERN_ERR "emu10k1: couldn't enable device\n");
|
---|
629 | kfree(card);
|
---|
630 | return -ENODEV;
|
---|
631 | }
|
---|
632 |
|
---|
633 | pci_set_master(pci_dev);
|
---|
634 |
|
---|
635 | card->iobase = pci_dev->resource[0].start;
|
---|
636 |
|
---|
637 | if (request_region(card->iobase, EMU10K1_EXTENT, card_names[pci_id->driver_data]) == NULL) {
|
---|
638 | printk(KERN_ERR "emu10k1: IO space in use\n");
|
---|
639 | kfree(card);
|
---|
640 | return -ENODEV;
|
---|
641 | }
|
---|
642 | pci_dev->driver_data = card;
|
---|
643 | pci_dev->dma_mask = EMU10K1_DMA_MASK;
|
---|
644 | #else
|
---|
645 | pci_set_master(pci_dev);
|
---|
646 |
|
---|
647 | card->iobase = pci_dev->base_address[0] & PCI_BASE_ADDRESS_IO_MASK;
|
---|
648 |
|
---|
649 | if (check_region(card->iobase, EMU10K1_EXTENT)) {
|
---|
650 | printk(KERN_ERR "emu10k1: IO space in use\n");
|
---|
651 | kfree(card);
|
---|
652 | return -ENODEV;
|
---|
653 | }
|
---|
654 |
|
---|
655 | request_region(card->iobase, EMU10K1_EXTENT, card_names[pci_id->driver_data]);
|
---|
656 | #endif
|
---|
657 | card->irq = pci_dev->irq;
|
---|
658 | card->pci_dev = pci_dev;
|
---|
659 |
|
---|
660 | /* Reserve IRQ Line */
|
---|
661 | if (request_irq(card->irq, emu10k1_interrupt, SA_SHIRQ, card_names[pci_id->driver_data], card)) {
|
---|
662 | printk(KERN_ERR "emu10k1: IRQ in use\n");
|
---|
663 | goto err_irq;
|
---|
664 | }
|
---|
665 |
|
---|
666 | pci_read_config_byte(pci_dev, PCI_REVISION_ID, &card->chiprev);
|
---|
667 |
|
---|
668 | printk(KERN_INFO "emu10k1: %s rev %d found at IO 0x%04lx, IRQ %d\n", card_names[pci_id->driver_data], card->chiprev, card->iobase, card->irq);
|
---|
669 |
|
---|
670 | spin_lock_init(&card->lock);
|
---|
671 | card->mixeraddx = card->iobase + AC97DATA;
|
---|
672 | init_MUTEX(&card->open_sem);
|
---|
673 | card->open_mode = 0;
|
---|
674 | init_waitqueue_head(&card->open_wait);
|
---|
675 |
|
---|
676 | /* Register devices */
|
---|
677 | if ((card->audio1_num = register_sound_dsp(&emu10k1_audio_fops, -1)) < 0) {
|
---|
678 | printk(KERN_ERR "emu10k1: cannot register first audio device!\n");
|
---|
679 | goto err_dev0;
|
---|
680 | }
|
---|
681 |
|
---|
682 | if ((card->audio2_num = register_sound_dsp(&emu10k1_audio_fops, -1)) < 0) {
|
---|
683 | printk(KERN_ERR "emu10k1: cannot register second audio device!\n");
|
---|
684 | goto err_dev1;
|
---|
685 | }
|
---|
686 |
|
---|
687 | if ((card->mixer_num = register_sound_mixer(&emu10k1_mixer_fops, -1)) < 0) {
|
---|
688 | printk(KERN_ERR "emu10k1: cannot register mixer device!\n");
|
---|
689 | goto err_dev2;
|
---|
690 | }
|
---|
691 |
|
---|
692 | if ((card->midi_num = register_sound_midi(&emu10k1_midi_fops, -1)) < 0) {
|
---|
693 | printk(KERN_ERR "emu10k1: cannot register midi device!\n");
|
---|
694 | goto err_dev3;
|
---|
695 | }
|
---|
696 |
|
---|
697 | if (emu10k1_init(card) != CTSTATUS_SUCCESS) {
|
---|
698 | printk(KERN_ERR "emu10k1: cannot initialize device!\n");
|
---|
699 | goto err_emu10k1_init;
|
---|
700 | }
|
---|
701 |
|
---|
702 | if (audio_init(card) != CTSTATUS_SUCCESS) {
|
---|
703 | printk(KERN_ERR "emu10k1: cannot initialize audio!\n");
|
---|
704 | goto err_audio_init;
|
---|
705 | }
|
---|
706 |
|
---|
707 | if (midi_init(card) != CTSTATUS_SUCCESS) {
|
---|
708 | printk(KERN_ERR "emu10k1: cannot initialize midi!\n");
|
---|
709 | goto err_midi_init;
|
---|
710 | }
|
---|
711 |
|
---|
712 | mixer_init(card);
|
---|
713 |
|
---|
714 | DPD(2, "Hardware initialized. TRAM allocated: %u bytes\n", (unsigned int) card->tmemsize);
|
---|
715 |
|
---|
716 | list_add(&card->list, &emu10k1_devs);
|
---|
717 |
|
---|
718 | return 0;
|
---|
719 |
|
---|
720 | err_midi_init:
|
---|
721 | audio_exit(card);
|
---|
722 |
|
---|
723 | err_audio_init:
|
---|
724 | emu10k1_exit(card);
|
---|
725 |
|
---|
726 | err_emu10k1_init:
|
---|
727 | unregister_sound_midi(card->midi_num);
|
---|
728 |
|
---|
729 | err_dev3:
|
---|
730 | unregister_sound_mixer(card->mixer_num);
|
---|
731 |
|
---|
732 | err_dev2:
|
---|
733 | unregister_sound_dsp(card->audio2_num);
|
---|
734 |
|
---|
735 | err_dev1:
|
---|
736 | unregister_sound_dsp(card->audio1_num);
|
---|
737 |
|
---|
738 | err_dev0:
|
---|
739 | free_irq(card->irq, card);
|
---|
740 |
|
---|
741 | err_irq:
|
---|
742 | release_region(card->iobase, EMU10K1_EXTENT);
|
---|
743 | kfree(card);
|
---|
744 |
|
---|
745 | return -ENODEV;
|
---|
746 | }
|
---|
747 |
|
---|
748 | static void __devexit emu10k1_remove(struct pci_dev *pci_dev)
|
---|
749 | {
|
---|
750 | #if LINUX_VERSION_CODE > 0x020320
|
---|
751 | struct emu10k1_card *card = pci_dev->driver_data;
|
---|
752 | #else
|
---|
753 | struct emu10k1_card *card = list_entry(emu10k1_devs.next, struct emu10k1_card, list);
|
---|
754 | #endif
|
---|
755 | midi_exit(card);
|
---|
756 | audio_exit(card);
|
---|
757 | emu10k1_exit(card);
|
---|
758 |
|
---|
759 | unregister_sound_midi(card->midi_num);
|
---|
760 | unregister_sound_mixer(card->mixer_num);
|
---|
761 | unregister_sound_dsp(card->audio2_num);
|
---|
762 | unregister_sound_dsp(card->audio1_num);
|
---|
763 |
|
---|
764 | free_irq(card->irq, card);
|
---|
765 | release_region(card->iobase, EMU10K1_EXTENT);
|
---|
766 |
|
---|
767 | list_del(&card->list);
|
---|
768 |
|
---|
769 | kfree(card);
|
---|
770 | return;
|
---|
771 | }
|
---|
772 |
|
---|
773 | MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@opensource.creative.com)");
|
---|
774 | MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION "\nCopyright (C) 1999 Creative Technology Ltd.");
|
---|
775 |
|
---|
776 | #ifdef TARGET_OS2
|
---|
777 | static struct pci_driver emu10k1_pci_driver = {
|
---|
778 | {0},
|
---|
779 | "emu10k1",
|
---|
780 | emu10k1_pci_tbl,
|
---|
781 | emu10k1_probe,
|
---|
782 | emu10k1_remove,
|
---|
783 | NULL,
|
---|
784 | NULL
|
---|
785 | };
|
---|
786 | #else
|
---|
787 | static struct pci_driver emu10k1_pci_driver __initdata = {
|
---|
788 | name:"emu10k1",
|
---|
789 | id_table:emu10k1_pci_tbl,
|
---|
790 | probe:emu10k1_probe,
|
---|
791 | remove:emu10k1_remove,
|
---|
792 | };
|
---|
793 | #endif //TARGET_OS2
|
---|
794 |
|
---|
795 | #if LINUX_VERSION_CODE > 0x020320
|
---|
796 | static int __init emu10k1_init_module(void)
|
---|
797 | {
|
---|
798 | printk(KERN_INFO "Creative EMU10K1 PCI Audio Driver, version " DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
|
---|
799 |
|
---|
800 | return pci_module_init(&emu10k1_pci_driver);
|
---|
801 | }
|
---|
802 |
|
---|
803 | static void __exit emu10k1_cleanup_module(void)
|
---|
804 | {
|
---|
805 | pci_unregister_driver(&emu10k1_pci_driver);
|
---|
806 | return;
|
---|
807 | }
|
---|
808 |
|
---|
809 | #else
|
---|
810 |
|
---|
811 | static int __init emu10k1_init_module(void)
|
---|
812 | {
|
---|
813 | struct pci_dev *dev = NULL;
|
---|
814 | const struct pci_device_id *pci_id = emu10k1_pci_driver.id_table;
|
---|
815 |
|
---|
816 | printk(KERN_INFO "Creative EMU10K1 PCI Audio Driver, version " DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
|
---|
817 |
|
---|
818 | if (!pci_present())
|
---|
819 | return -ENODEV;
|
---|
820 |
|
---|
821 | while (pci_id->vendor) {
|
---|
822 | while ((dev = pci_find_device(pci_id->vendor, pci_id->device, dev)))
|
---|
823 | emu10k1_probe(dev, pci_id);
|
---|
824 |
|
---|
825 | pci_id++;
|
---|
826 | }
|
---|
827 | return 0;
|
---|
828 | }
|
---|
829 |
|
---|
830 | static void __exit emu10k1_cleanup_module(void)
|
---|
831 | {
|
---|
832 | struct emu10k1_card *card;
|
---|
833 |
|
---|
834 | while (!list_empty(&emu10k1_devs)) {
|
---|
835 | card = list_entry(emu10k1_devs.next, struct emu10k1_card, list);
|
---|
836 |
|
---|
837 | emu10k1_remove(card->pci_dev);
|
---|
838 | }
|
---|
839 |
|
---|
840 | return;
|
---|
841 | }
|
---|
842 |
|
---|
843 | #endif
|
---|
844 |
|
---|
845 | module_init(emu10k1_init_module);
|
---|
846 | module_exit(emu10k1_cleanup_module);
|
---|