2 **********************************************************************
3 * main.c - Creative EMU10K1 audio driver
4 * Copyright 1999, 2000 Creative Labs, Inc.
6 **********************************************************************
8 * Date Author Summary of changes
9 * ---- ------ ------------------
10 * October 20, 1999 Bertrand Lee base code release
11 * November 2, 1999 Alan Cox cleaned up stuff
13 **********************************************************************
15 * This program is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU General Public License as
17 * published by the Free Software Foundation; either version 2 of
18 * the License, or (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public
26 * License along with this program; if not, write to the Free
27 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
30 **********************************************************************
33 * /dev/dsp: Standard /dev/dsp device, OSS-compatible
34 * /dev/dsp1: Routes to rear speakers only
35 * /dev/mixer: Standard /dev/mixer device, OSS-compatible
36 * /dev/midi: Raw MIDI UART device, mostly OSS-compatible
37 * /dev/sequencer: Sequencer Interface (requires sound.o)
40 * 0.1 beta Initial release
41 * 0.2 Lowered initial mixer vol. Improved on stuttering wave playback. Added MIDI UART support.
42 * 0.3 Fixed mixer routing bug, added APS, joystick support.
43 * 0.4 Added rear-channel, SPDIF support.
44 * 0.5 Source cleanup, SMP fixes, multiopen support, 64 bit arch fixes,
45 * moved bh's to tasklets, moved to the new PCI driver initialization style.
46 * 0.6 Make use of pci_alloc_consistent, improve compatibility layer for 2.2 kernels,
47 * code reorganization and cleanup.
48 * 0.7 Support for the Emu-APS. Bug fixes for voice cache setup, mmaped sound + poll().
49 * Support for setting external TRAM size.
50 * 0.8 Make use of the kernel ac97 interface. Support for a dsp patch manager.
51 * 0.9 Re-enables rear speakers volume controls
52 * 0.10 Initializes rear speaker volume.
53 * Dynamic patch storage allocation.
54 * New private ioctls to change control gpr values.
55 * Enable volume control interrupts.
56 * By default enable dsp routes to digital out.
57 * 0.11 Fixed fx / 4 problem.
58 * 0.12 Implemented mmaped for recording.
59 * Fixed bug: not unreserving mmaped buffer pages.
60 * IRQ handler cleanup.
61 * 0.13 Fixed problem with dsp1
62 * Simplified dsp patch writing (inside the driver)
63 * Fixed several bugs found by the Stanford tools
64 * 0.14 New control gpr to oss mixer mapping feature (Chris Purnell)
65 * Added AC3 Passthrough Support (Juha Yrjola)
66 * Added Support for 5.1 cards (digital out and the third analog out)
67 * 0.15 Added Sequencer Support (Daniel Mack)
68 * Support for multichannel pcm playback (Eduard Hasenleithner)
69 * 0.16 Mixer improvements, added old treble/bass support (Daniel Bertrand)
70 * Small code format cleanup.
71 * Deadlock bug fix for emu10k1_volxxx_irqhandler().
72 * 0.17 Fix for mixer SOUND_MIXER_INFO ioctl.
73 * Fix for HIGHMEM machines (emu10k1 can only do 31 bit bus master)
74 * midi poll initial implementation.
75 * Small mixer fixes/cleanups.
76 * Improved support for 5.1 cards.
77 * 0.18 Fix for possible leak in pci_alloc_consistent()
78 * Cleaned up poll() functions (audio and midi). Don't start input.
79 * Restrict DMA pages used to 512Mib range.
80 * New AC97_BOOST mixer ioctl.
81 * 0.19a Added Support for Audigy Cards
82 * Real fix for kernel with highmem support (cast dma_handle to u32).
83 * Fix recording buffering parameters calculation.
84 * Use unsigned long for variables in bit ops.
85 * 0.20a Fixed recording startup
86 * Fixed timer rate setting (it's a 16-bit register)
87 * 0.21 Converted code to use pci_name() instead of accessing slot_name
88 * directly (Eugene Teo)
89 *********************************************************************/
91 /* These are only included once per module */
92 #include <linux/module.h>
93 #include <linux/slab.h>
94 #include <linux/init.h>
95 #include <linux/delay.h>
96 #include <linux/proc_fs.h>
97 #include <linux/dma-mapping.h>
110 #ifdef EMU10K1_SEQUENCER
111 #define MIDI_SYNTH_NAME "EMU10K1 MIDI"
112 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
114 #include "../sound_config.h"
115 #include "../midi_synth.h"
117 /* this should be in dev_table.h */
118 #define SNDCARD_EMU10K1 46
122 /* the emu10k1 _seems_ to only supports 29 bit (512MiB) bit bus master */
123 #define EMU10K1_DMA_MASK DMA_29BIT_MASK /* DMA buffer mask for pci_alloc_consist */
125 #ifndef PCI_VENDOR_ID_CREATIVE
126 #define PCI_VENDOR_ID_CREATIVE 0x1102
129 #ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
130 #define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002
132 #ifndef PCI_DEVICE_ID_CREATIVE_AUDIGY
133 #define PCI_DEVICE_ID_CREATIVE_AUDIGY 0x0004
136 #define EMU_APS_SUBID 0x40011102
143 static char *card_names
[] __devinitdata
= {
148 static struct pci_device_id emu10k1_pci_tbl
[] = {
149 {PCI_VENDOR_ID_CREATIVE
, PCI_DEVICE_ID_CREATIVE_EMU10K1
,
150 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, EMU10K1
},
151 {PCI_VENDOR_ID_CREATIVE
, PCI_DEVICE_ID_CREATIVE_AUDIGY
,
152 PCI_ANY_ID
, PCI_ANY_ID
, 0, 0, AUDIGY
},
156 MODULE_DEVICE_TABLE(pci
, emu10k1_pci_tbl
);
158 /* Global var instantiation */
160 LIST_HEAD(emu10k1_devs
);
162 extern struct file_operations emu10k1_audio_fops
;
163 extern struct file_operations emu10k1_mixer_fops
;
164 extern struct file_operations emu10k1_midi_fops
;
166 #ifdef EMU10K1_SEQUENCER
167 static struct midi_operations emu10k1_midi_operations
;
170 extern irqreturn_t
emu10k1_interrupt(int, void *);
172 static int __devinit
emu10k1_audio_init(struct emu10k1_card
*card
)
174 /* Assign default playback voice parameters */
176 card
->mchannel_fx
= 0;
178 card
->mchannel_fx
= 8;
181 if (card
->is_audigy
) {
183 card
->waveout
.send_dcba
[SEND_MONO
] = 0xffffffff;
184 card
->waveout
.send_hgfe
[SEND_MONO
] = 0x0000ffff;
188 card
->waveout
.send_dcba
[SEND_LEFT
] = 0x00ff00ff;
189 card
->waveout
.send_hgfe
[SEND_LEFT
] = 0x00007f7f;
191 card
->waveout
.send_dcba
[SEND_RIGHT
] = 0xff00ff00;
192 card
->waveout
.send_hgfe
[SEND_RIGHT
] = 0x00007f7f;
194 card
->waveout
.send_routing
[ROUTE_PCM
] = 0x03020100; // Regular pcm
195 card
->waveout
.send_routing2
[ROUTE_PCM
] = 0x07060504;
197 card
->waveout
.send_routing
[ROUTE_PT
] = 0x3f3f3d3c; // Passthrough
198 card
->waveout
.send_routing2
[ROUTE_PT
] = 0x3f3f3f3f;
200 card
->waveout
.send_routing
[ROUTE_PCM1
] = 0x03020100; // Spare
201 card
->waveout
.send_routing2
[ROUTE_PCM1
] = 0x07060404;
205 card
->waveout
.send_dcba
[SEND_MONO
] = 0x0000ffff;
209 card
->waveout
.send_dcba
[SEND_LEFT
] = 0x000000ff;
211 card
->waveout
.send_dcba
[SEND_RIGHT
] = 0x0000ff00;
213 card
->waveout
.send_routing
[ROUTE_PCM
] = 0x3210; // pcm
214 card
->waveout
.send_routing
[ROUTE_PT
] = 0x3210; // passthrough
215 card
->waveout
.send_routing
[ROUTE_PCM1
] = 0x7654; // /dev/dsp1
218 /* Assign default recording parameters */
221 card
->wavein
.recsrc
= WAVERECORD_FX
;
223 card
->wavein
.recsrc
= WAVERECORD_AC97
;
225 card
->wavein
.fxwc
= 0x0003;
229 static void emu10k1_audio_cleanup(struct emu10k1_card
*card
)
233 static int __devinit
emu10k1_register_devices(struct emu10k1_card
*card
)
235 card
->audio_dev
= register_sound_dsp(&emu10k1_audio_fops
, -1);
236 if (card
->audio_dev
< 0) {
237 printk(KERN_ERR
"emu10k1: cannot register first audio device!\n");
241 card
->audio_dev1
= register_sound_dsp(&emu10k1_audio_fops
, -1);
242 if (card
->audio_dev1
< 0) {
243 printk(KERN_ERR
"emu10k1: cannot register second audio device!\n");
247 card
->ac97
->dev_mixer
= register_sound_mixer(&emu10k1_mixer_fops
, -1);
248 if (card
->ac97
->dev_mixer
< 0) {
249 printk(KERN_ERR
"emu10k1: cannot register mixer device\n");
253 card
->midi_dev
= register_sound_midi(&emu10k1_midi_fops
, -1);
254 if (card
->midi_dev
< 0) {
255 printk(KERN_ERR
"emu10k1: cannot register midi device!\n");
259 #ifdef EMU10K1_SEQUENCER
260 card
->seq_dev
= sound_alloc_mididev();
261 if (card
->seq_dev
== -1)
262 printk(KERN_WARNING
"emu10k1: unable to register sequencer device!");
264 std_midi_synth
.midi_dev
= card
->seq_dev
;
265 midi_devs
[card
->seq_dev
] =
266 (struct midi_operations
*)
267 kmalloc(sizeof(struct midi_operations
), GFP_KERNEL
);
269 if (midi_devs
[card
->seq_dev
] == NULL
) {
270 printk(KERN_ERR
"emu10k1: unable to allocate memory!");
271 sound_unload_mididev(card
->seq_dev
);
273 /* return without error */
275 memcpy((char *)midi_devs
[card
->seq_dev
],
276 (char *)&emu10k1_midi_operations
,
277 sizeof(struct midi_operations
));
278 midi_devs
[card
->seq_dev
]->devc
= card
;
280 card
->seq_mididev
= NULL
;
287 unregister_sound_mixer(card
->ac97
->dev_mixer
);
289 unregister_sound_dsp(card
->audio_dev
);
291 unregister_sound_dsp(card
->audio_dev
);
296 static void emu10k1_unregister_devices(struct emu10k1_card
*card
)
298 #ifdef EMU10K1_SEQUENCER
299 if (card
->seq_dev
> -1) {
300 kfree(midi_devs
[card
->seq_dev
]);
301 midi_devs
[card
->seq_dev
] = NULL
;
302 sound_unload_mididev(card
->seq_dev
);
307 unregister_sound_midi(card
->midi_dev
);
308 unregister_sound_mixer(card
->ac97
->dev_mixer
);
309 unregister_sound_dsp(card
->audio_dev1
);
310 unregister_sound_dsp(card
->audio_dev
);
313 static int emu10k1_info_proc (char *page
, char **start
, off_t off
,
314 int count
, int *eof
, void *data
)
316 struct emu10k1_card
*card
= data
;
322 len
+= sprintf (page
+ len
, "Driver Version : %s\n", DRIVER_VERSION
);
323 len
+= sprintf (page
+ len
, "Card type : %s\n", card
->is_aps
? "Aps" : (card
->is_audigy
? "Audigy" : "Emu10k1"));
324 len
+= sprintf (page
+ len
, "Revision : %d\n", card
->chiprev
);
325 len
+= sprintf (page
+ len
, "Model : %#06x\n", card
->model
);
326 len
+= sprintf (page
+ len
, "IO : %#06lx-%#06lx\n", card
->iobase
, card
->iobase
+ card
->length
- 1);
327 len
+= sprintf (page
+ len
, "IRQ : %d\n\n", card
->irq
);
329 len
+= sprintf (page
+ len
, "Registered /dev Entries:\n");
330 len
+= sprintf (page
+ len
, "/dev/dsp%d\n", card
->audio_dev
/ 16);
331 len
+= sprintf (page
+ len
, "/dev/dsp%d\n", card
->audio_dev1
/ 16);
332 len
+= sprintf (page
+ len
, "/dev/mixer%d\n", card
->ac97
->dev_mixer
/ 16);
333 len
+= sprintf (page
+ len
, "/dev/midi%d\n", card
->midi_dev
/ 16);
335 #ifdef EMU10K1_SEQUENCER
336 len
+= sprintf (page
+ len
, "/dev/sequencer\n");
342 static int __devinit
emu10k1_proc_init(struct emu10k1_card
*card
)
346 if (!proc_mkdir ("driver/emu10k1", NULL
)) {
347 printk(KERN_ERR
"emu10k1: unable to create proc directory driver/emu10k1\n");
351 sprintf(s
, "driver/emu10k1/%s", pci_name(card
->pci_dev
));
352 if (!proc_mkdir (s
, NULL
)) {
353 printk(KERN_ERR
"emu10k1: unable to create proc directory %s\n", s
);
354 goto err_emu10k1_proc
;
357 sprintf(s
, "driver/emu10k1/%s/info", pci_name(card
->pci_dev
));
358 if (!create_proc_read_entry (s
, 0, NULL
, emu10k1_info_proc
, card
)) {
359 printk(KERN_ERR
"emu10k1: unable to create proc entry %s\n", s
);
364 sprintf(s
, "driver/emu10k1/%s/ac97", pci_name(card
->pci_dev
));
365 if (!create_proc_read_entry (s
, 0, NULL
, ac97_read_proc
, card
->ac97
)) {
366 printk(KERN_ERR
"emu10k1: unable to create proc entry %s\n", s
);
374 sprintf(s
, "driver/emu10k1/%s/info", pci_name(card
->pci_dev
));
375 remove_proc_entry(s
, NULL
);
378 sprintf(s
, "driver/emu10k1/%s", pci_name(card
->pci_dev
));
379 remove_proc_entry(s
, NULL
);
382 remove_proc_entry("driver/emu10k1", NULL
);
388 static void emu10k1_proc_cleanup(struct emu10k1_card
*card
)
393 sprintf(s
, "driver/emu10k1/%s/ac97", pci_name(card
->pci_dev
));
394 remove_proc_entry(s
, NULL
);
397 sprintf(s
, "driver/emu10k1/%s/info", pci_name(card
->pci_dev
));
398 remove_proc_entry(s
, NULL
);
400 sprintf(s
, "driver/emu10k1/%s", pci_name(card
->pci_dev
));
401 remove_proc_entry(s
, NULL
);
403 remove_proc_entry("driver/emu10k1", NULL
);
406 static int __devinit
emu10k1_mixer_init(struct emu10k1_card
*card
)
408 struct ac97_codec
*codec
= ac97_alloc_codec();
412 printk(KERN_ERR
"emu10k1: cannot allocate mixer\n");
416 card
->ac97
->private_data
= card
;
420 card
->ac97
->codec_read
= emu10k1_ac97_read
;
421 card
->ac97
->codec_write
= emu10k1_ac97_write
;
423 if (ac97_probe_codec (card
->ac97
) == 0) {
424 printk(KERN_ERR
"emu10k1: unable to probe AC97 codec\n");
427 /* 5.1: Enable the additional AC97 Slots and unmute extra channels on AC97 codec */
428 if (codec
->codec_read(codec
, AC97_EXTENDED_ID
) & 0x0080){
429 printk(KERN_INFO
"emu10k1: SBLive! 5.1 card detected\n");
430 sblive_writeptr(card
, AC97SLOT
, 0, AC97SLOT_CNTR
| AC97SLOT_LFE
);
431 codec
->codec_write(codec
, AC97_SURROUND_MASTER
, 0x0);
435 //card->ac97->bit_resolution=5;
437 /* these will store the original values and never be modified */
438 card
->ac97_supported_mixers
= card
->ac97
->supported_mixers
;
439 card
->ac97_stereo_mixers
= card
->ac97
->stereo_mixers
;
445 ac97_release_codec(card
->ac97
);
449 static void emu10k1_mixer_cleanup(struct emu10k1_card
*card
)
451 ac97_release_codec(card
->ac97
);
454 static int __devinit
emu10k1_midi_init(struct emu10k1_card
*card
)
458 card
->mpuout
= kzalloc(sizeof(struct emu10k1_mpuout
), GFP_KERNEL
);
459 if (card
->mpuout
== NULL
) {
460 printk(KERN_WARNING
"emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n");
465 card
->mpuout
->intr
= 1;
466 card
->mpuout
->status
= FLAGS_AVAILABLE
;
467 card
->mpuout
->state
= CARDMIDIOUT_STATE_DEFAULT
;
469 tasklet_init(&card
->mpuout
->tasklet
, emu10k1_mpuout_bh
, (unsigned long) card
);
471 spin_lock_init(&card
->mpuout
->lock
);
473 card
->mpuin
= kzalloc(sizeof(struct emu10k1_mpuin
), GFP_KERNEL
);
474 if (card
->mpuin
== NULL
) {
475 printk(KERN_WARNING
"emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n");
480 card
->mpuin
->status
= FLAGS_AVAILABLE
;
482 tasklet_init(&card
->mpuin
->tasklet
, emu10k1_mpuin_bh
, (unsigned long) card
->mpuin
);
484 spin_lock_init(&card
->mpuin
->lock
);
486 /* Reset the MPU port */
487 if (emu10k1_mpu_reset(card
) < 0) {
503 static void emu10k1_midi_cleanup(struct emu10k1_card
*card
)
505 tasklet_kill(&card
->mpuout
->tasklet
);
508 tasklet_kill(&card
->mpuin
->tasklet
);
512 static void __devinit
voice_init(struct emu10k1_card
*card
)
516 for (i
= 0; i
< NUM_G
; i
++)
517 card
->voicetable
[i
] = VOICE_USAGE_FREE
;
520 static void __devinit
timer_init(struct emu10k1_card
*card
)
522 INIT_LIST_HEAD(&card
->timers
);
523 card
->timer_delay
= TIMER_STOPPED
;
524 spin_lock_init(&card
->timer_lock
);
527 static void __devinit
addxmgr_init(struct emu10k1_card
*card
)
531 for (count
= 0; count
< MAXPAGES
; count
++)
532 card
->emupagetable
[count
] = 0;
534 /* Mark first page as used */
535 /* This page is reserved by the driver */
536 card
->emupagetable
[0] = 0x8001;
537 card
->emupagetable
[1] = MAXPAGES
- 1;
540 static void fx_cleanup(struct patch_manager
*mgr
)
543 for(i
= 0; i
< mgr
->current_pages
; i
++)
544 free_page((unsigned long) mgr
->patch
[i
]);
547 static int __devinit
fx_init(struct emu10k1_card
*card
)
549 struct patch_manager
*mgr
= &card
->mgr
;
550 struct dsp_patch
*patch
;
551 struct dsp_rpatch
*rpatch
;
556 struct emu_efx_info_t emu_efx_info
[2]=
557 {{ 20, 10, 0x400, 0x100, 0x20 },
558 { 24, 12, 0x600, 0x400, 0x60 },
562 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
563 mgr
->ctrl_gpr
[i
][0] = -1;
564 mgr
->ctrl_gpr
[i
][1] = -1;
569 mgr
->current_pages
= (2 + PATCHES_PER_PAGE
- 1) / PATCHES_PER_PAGE
;
571 /* !! The number below must equal the number of patches, currently 11 !! */
572 mgr
->current_pages
= (11 + PATCHES_PER_PAGE
- 1) / PATCHES_PER_PAGE
;
574 for (i
= 0; i
< mgr
->current_pages
; i
++) {
575 mgr
->patch
[i
] = (void *)__get_free_page(GFP_KERNEL
);
576 if (mgr
->patch
[i
] == NULL
) {
577 mgr
->current_pages
= i
;
581 memset(mgr
->patch
[i
], 0, PAGE_SIZE
);
584 if (card
->is_audigy
) {
585 for (i
= 0; i
< 1024; i
++)
586 OP(0xf, 0x0c0, 0x0c0, 0x0cf, 0x0c0);
588 for (i
= 0; i
< 512 ; i
++)
589 sblive_writeptr(card
, A_GPR_BASE
+i
,0,0);
594 OP(0, 0x402, 0x0c0, 0x406, 0x000);
595 OP(0, 0x403, 0x0c0, 0x407, 0x001);
597 //CD-Digital input Volume
598 OP(0, 0x404, 0x0c0, 0x40d, 0x42);
599 OP(0, 0x405, 0x0c0, 0x40f, 0x43);
602 OP(6, 0x400, 0x0c0, 0x402, 0x404);
603 OP(6, 0x401, 0x0c0, 0x403, 0x405);
605 // Front Output + Master Volume
606 OP(0, 0x68, 0x0c0, 0x408, 0x400);
607 OP(0, 0x69, 0x0c0, 0x409, 0x401);
609 // Add-in analog inputs for other speakers
610 OP(6, 0x400, 0x40, 0x400, 0xc0);
611 OP(6, 0x401, 0x41, 0x401, 0xc0);
613 // Digital Front + Master Volume
614 OP(0, 0x60, 0x0c0, 0x408, 0x400);
615 OP(0, 0x61, 0x0c0, 0x409, 0x401);
617 // Rear Output + Rear Volume
618 OP(0, 0x06e, 0x0c0, 0x419, 0x400);
619 OP(0, 0x06f, 0x0c0, 0x41a, 0x401);
621 // Digital Rear Output + Rear Volume
622 OP(0, 0x066, 0x0c0, 0x419, 0x400);
623 OP(0, 0x067, 0x0c0, 0x41a, 0x401);
625 // Audigy Drive, Headphone out
626 OP(6, 0x64, 0x0c0, 0x0c0, 0x400);
627 OP(6, 0x65, 0x0c0, 0x0c0, 0x401);
630 OP(6, 0x76, 0x0c0, 0x0c0, 0x40);
631 OP(6, 0x77, 0x0c0, 0x0c0, 0x41);
633 // Center = sub = Left/2 + Right/2
634 OP(0xe, 0x400, 0x401, 0xcd, 0x400);
636 // center/sub Volume (master)
637 OP(0, 0x06a, 0x0c0, 0x408, 0x400);
638 OP(0, 0x06b, 0x0c0, 0x409, 0x400);
640 // Digital center/sub Volume (master)
641 OP(0, 0x062, 0x0c0, 0x408, 0x400);
642 OP(0, 0x063, 0x0c0, 0x409, 0x400);
644 ROUTING_PATCH_START(rpatch
, "Routing");
645 ROUTING_PATCH_END(rpatch
);
647 /* delimiter patch */
648 patch
= PATCH(mgr
, patch_n
);
649 patch
->code_size
= 0;
652 sblive_writeptr(card
, 0x53, 0, 0);
654 for (i
= 0; i
< 512 ; i
++)
655 OP(6, 0x40, 0x40, 0x40, 0x40);
657 for (i
= 0; i
< 256; i
++)
658 sblive_writeptr_tag(card
, 0,
660 TANKMEMADDRREGBASE
+ i
, 0,
666 //first free GPR = 0x11b
669 /* FX volume correction and Volume control*/
670 INPUT_PATCH_START(patch
, "Pcm L vol", 0x0, 0);
671 GET_OUTPUT_GPR(patch
, 0x100, 0x0);
672 GET_CONTROL_GPR(patch
, 0x106, "Vol", 0, 0x7fffffff);
673 GET_DYNAMIC_GPR(patch
, 0x112);
675 OP(4, 0x112, 0x40, PCM_IN_L
, 0x44); //*4
676 OP(0, 0x100, 0x040, 0x112, 0x106); //*vol
677 INPUT_PATCH_END(patch
);
680 INPUT_PATCH_START(patch
, "Pcm R vol", 0x1, 0);
681 GET_OUTPUT_GPR(patch
, 0x101, 0x1);
682 GET_CONTROL_GPR(patch
, 0x107, "Vol", 0, 0x7fffffff);
683 GET_DYNAMIC_GPR(patch
, 0x112);
685 OP(4, 0x112, 0x40, PCM_IN_R
, 0x44);
686 OP(0, 0x101, 0x040, 0x112, 0x107);
688 INPUT_PATCH_END(patch
);
691 // CD-Digital In Volume control
692 INPUT_PATCH_START(patch
, "CD-Digital Vol L", 0x12, 0);
693 GET_OUTPUT_GPR(patch
, 0x10c, 0x12);
694 GET_CONTROL_GPR(patch
, 0x10d, "Vol", 0, 0x7fffffff);
696 OP(0, 0x10c, 0x040, SPDIF_CD_L
, 0x10d);
697 INPUT_PATCH_END(patch
);
699 INPUT_PATCH_START(patch
, "CD-Digital Vol R", 0x13, 0);
700 GET_OUTPUT_GPR(patch
, 0x10e, 0x13);
701 GET_CONTROL_GPR(patch
, 0x10f, "Vol", 0, 0x7fffffff);
703 OP(0, 0x10e, 0x040, SPDIF_CD_R
, 0x10f);
704 INPUT_PATCH_END(patch
);
706 //Volume Correction for Multi-channel Inputs
707 INPUT_PATCH_START(patch
, "Multi-Channel Gain", 0x08, 0);
708 patch
->input
=patch
->output
=0x3F00;
710 GET_OUTPUT_GPR(patch
, 0x113, MULTI_FRONT_L
);
711 GET_OUTPUT_GPR(patch
, 0x114, MULTI_FRONT_R
);
712 GET_OUTPUT_GPR(patch
, 0x115, MULTI_REAR_L
);
713 GET_OUTPUT_GPR(patch
, 0x116, MULTI_REAR_R
);
714 GET_OUTPUT_GPR(patch
, 0x117, MULTI_CENTER
);
715 GET_OUTPUT_GPR(patch
, 0x118, MULTI_LFE
);
717 OP(4, 0x113, 0x40, MULTI_FRONT_L
, 0x44);
718 OP(4, 0x114, 0x40, MULTI_FRONT_R
, 0x44);
719 OP(4, 0x115, 0x40, MULTI_REAR_L
, 0x44);
720 OP(4, 0x116, 0x40, MULTI_REAR_R
, 0x44);
721 OP(4, 0x117, 0x40, MULTI_CENTER
, 0x44);
722 OP(4, 0x118, 0x40, MULTI_LFE
, 0x44);
724 INPUT_PATCH_END(patch
);
727 //Routing patch start
728 ROUTING_PATCH_START(rpatch
, "Routing");
729 GET_INPUT_GPR(rpatch
, 0x100, 0x0);
730 GET_INPUT_GPR(rpatch
, 0x101, 0x1);
731 GET_INPUT_GPR(rpatch
, 0x10c, 0x12);
732 GET_INPUT_GPR(rpatch
, 0x10e, 0x13);
733 GET_INPUT_GPR(rpatch
, 0x113, MULTI_FRONT_L
);
734 GET_INPUT_GPR(rpatch
, 0x114, MULTI_FRONT_R
);
735 GET_INPUT_GPR(rpatch
, 0x115, MULTI_REAR_L
);
736 GET_INPUT_GPR(rpatch
, 0x116, MULTI_REAR_R
);
737 GET_INPUT_GPR(rpatch
, 0x117, MULTI_CENTER
);
738 GET_INPUT_GPR(rpatch
, 0x118, MULTI_LFE
);
740 GET_DYNAMIC_GPR(rpatch
, 0x102);
741 GET_DYNAMIC_GPR(rpatch
, 0x103);
743 GET_OUTPUT_GPR(rpatch
, 0x104, 0x8);
744 GET_OUTPUT_GPR(rpatch
, 0x105, 0x9);
745 GET_OUTPUT_GPR(rpatch
, 0x10a, 0x2);
746 GET_OUTPUT_GPR(rpatch
, 0x10b, 0x3);
750 OP(6, 0x102, AC97_IN_L
, 0x40, 0x40);
751 OP(6, 0x103, AC97_IN_R
, 0x40, 0x40);
754 /* Digital In + PCM + MULTI_FRONT-> AC97 out (front speakers)*/
755 OP(6, AC97_FRONT_L
, 0x100, 0x10c, 0x113);
757 CONNECT(MULTI_FRONT_L
, AC97_FRONT_L
);
758 CONNECT(PCM_IN_L
, AC97_FRONT_L
);
759 CONNECT(SPDIF_CD_L
, AC97_FRONT_L
);
761 OP(6, AC97_FRONT_R
, 0x101, 0x10e, 0x114);
763 CONNECT(MULTI_FRONT_R
, AC97_FRONT_R
);
764 CONNECT(PCM_IN_R
, AC97_FRONT_R
);
765 CONNECT(SPDIF_CD_R
, AC97_FRONT_R
);
767 /* Digital In + PCM + AC97 In + PCM1 + MULTI_REAR --> Rear Channel */
768 OP(6, 0x104, PCM1_IN_L
, 0x100, 0x115);
769 OP(6, 0x104, 0x104, 0x10c, 0x102);
771 CONNECT(MULTI_REAR_L
, ANALOG_REAR_L
);
772 CONNECT(AC97_IN_L
, ANALOG_REAR_L
);
773 CONNECT(PCM_IN_L
, ANALOG_REAR_L
);
774 CONNECT(SPDIF_CD_L
, ANALOG_REAR_L
);
775 CONNECT(PCM1_IN_L
, ANALOG_REAR_L
);
777 OP(6, 0x105, PCM1_IN_R
, 0x101, 0x116);
778 OP(6, 0x105, 0x105, 0x10e, 0x103);
780 CONNECT(MULTI_REAR_R
, ANALOG_REAR_R
);
781 CONNECT(AC97_IN_R
, ANALOG_REAR_R
);
782 CONNECT(PCM_IN_R
, ANALOG_REAR_R
);
783 CONNECT(SPDIF_CD_R
, ANALOG_REAR_R
);
784 CONNECT(PCM1_IN_R
, ANALOG_REAR_R
);
786 /* Digital In + PCM + AC97 In + MULTI_FRONT --> Digital out */
787 OP(6, 0x10b, 0x100, 0x102, 0x10c);
788 OP(6, 0x10b, 0x10b, 0x113, 0x40);
790 CONNECT(MULTI_FRONT_L
, DIGITAL_OUT_L
);
791 CONNECT(PCM_IN_L
, DIGITAL_OUT_L
);
792 CONNECT(AC97_IN_L
, DIGITAL_OUT_L
);
793 CONNECT(SPDIF_CD_L
, DIGITAL_OUT_L
);
795 OP(6, 0x10a, 0x101, 0x103, 0x10e);
796 OP(6, 0x10b, 0x10b, 0x114, 0x40);
798 CONNECT(MULTI_FRONT_R
, DIGITAL_OUT_R
);
799 CONNECT(PCM_IN_R
, DIGITAL_OUT_R
);
800 CONNECT(AC97_IN_R
, DIGITAL_OUT_R
);
801 CONNECT(SPDIF_CD_R
, DIGITAL_OUT_R
);
803 /* AC97 In --> ADC Recording Buffer */
804 OP(6, ADC_REC_L
, 0x102, 0x40, 0x40);
806 CONNECT(AC97_IN_L
, ADC_REC_L
);
808 OP(6, ADC_REC_R
, 0x103, 0x40, 0x40);
810 CONNECT(AC97_IN_R
, ADC_REC_R
);
813 /* fx12:Analog-Center */
814 OP(6, ANALOG_CENTER
, 0x117, 0x40, 0x40);
815 CONNECT(MULTI_CENTER
, ANALOG_CENTER
);
817 /* fx11:Analog-LFE */
818 OP(6, ANALOG_LFE
, 0x118, 0x40, 0x40);
819 CONNECT(MULTI_LFE
, ANALOG_LFE
);
821 /* fx12:Digital-Center */
822 OP(6, DIGITAL_CENTER
, 0x117, 0x40, 0x40);
823 CONNECT(MULTI_CENTER
, DIGITAL_CENTER
);
825 /* fx11:Analog-LFE */
826 OP(6, DIGITAL_LFE
, 0x118, 0x40, 0x40);
827 CONNECT(MULTI_LFE
, DIGITAL_LFE
);
829 ROUTING_PATCH_END(rpatch
);
832 // Rear volume control
833 OUTPUT_PATCH_START(patch
, "Vol Rear L", 0x8, 0);
834 GET_INPUT_GPR(patch
, 0x104, 0x8);
835 GET_CONTROL_GPR(patch
, 0x119, "Vol", 0, 0x7fffffff);
837 OP(0, ANALOG_REAR_L
, 0x040, 0x104, 0x119);
838 OUTPUT_PATCH_END(patch
);
840 OUTPUT_PATCH_START(patch
, "Vol Rear R", 0x9, 0);
841 GET_INPUT_GPR(patch
, 0x105, 0x9);
842 GET_CONTROL_GPR(patch
, 0x11a, "Vol", 0, 0x7fffffff);
844 OP(0, ANALOG_REAR_R
, 0x040, 0x105, 0x11a);
845 OUTPUT_PATCH_END(patch
);
848 //Master volume control on front-digital
849 OUTPUT_PATCH_START(patch
, "Vol Master L", 0x2, 1);
850 GET_INPUT_GPR(patch
, 0x10a, 0x2);
851 GET_CONTROL_GPR(patch
, 0x108, "Vol", 0, 0x7fffffff);
853 OP(0, DIGITAL_OUT_L
, 0x040, 0x10a, 0x108);
854 OUTPUT_PATCH_END(patch
);
857 OUTPUT_PATCH_START(patch
, "Vol Master R", 0x3, 1);
858 GET_INPUT_GPR(patch
, 0x10b, 0x3);
859 GET_CONTROL_GPR(patch
, 0x109, "Vol", 0, 0x7fffffff);
861 OP(0, DIGITAL_OUT_R
, 0x040, 0x10b, 0x109);
862 OUTPUT_PATCH_END(patch
);
865 /* delimiter patch */
866 patch
= PATCH(mgr
, patch_n
);
867 patch
->code_size
= 0;
870 sblive_writeptr(card
, DBG
, 0, 0);
873 spin_lock_init(&mgr
->lock
);
875 // Set up Volume controls, try to keep this the same for both Audigy and Live
878 mgr
->ctrl_gpr
[SOUND_MIXER_VOLUME
][0] = 8;
879 mgr
->ctrl_gpr
[SOUND_MIXER_VOLUME
][1] = 9;
881 left
= card
->ac97
->mixer_state
[SOUND_MIXER_VOLUME
] & 0xff;
882 right
= (card
->ac97
->mixer_state
[SOUND_MIXER_VOLUME
] >> 8) & 0xff;
884 emu10k1_set_volume_gpr(card
, 8, left
, 1 << card
->ac97
->bit_resolution
);
885 emu10k1_set_volume_gpr(card
, 9, right
, 1 << card
->ac97
->bit_resolution
);
888 mgr
->ctrl_gpr
[ SOUND_MIXER_OGAIN
][0] = 0x19;
889 mgr
->ctrl_gpr
[ SOUND_MIXER_OGAIN
][1] = 0x1a;
892 card
->ac97
->mixer_state
[SOUND_MIXER_OGAIN
] = (right
<< 8) | left
;
894 card
->ac97
->supported_mixers
|= SOUND_MASK_OGAIN
;
895 card
->ac97
->stereo_mixers
|= SOUND_MASK_OGAIN
;
897 emu10k1_set_volume_gpr(card
, 0x19, left
, VOL_5BIT
);
898 emu10k1_set_volume_gpr(card
, 0x1a, right
, VOL_5BIT
);
901 mgr
->ctrl_gpr
[SOUND_MIXER_PCM
][0] = 6;
902 mgr
->ctrl_gpr
[SOUND_MIXER_PCM
][1] = 7;
904 left
= card
->ac97
->mixer_state
[SOUND_MIXER_PCM
] & 0xff;
905 right
= (card
->ac97
->mixer_state
[SOUND_MIXER_PCM
] >> 8) & 0xff;
907 emu10k1_set_volume_gpr(card
, 6, left
, VOL_5BIT
);
908 emu10k1_set_volume_gpr(card
, 7, right
, VOL_5BIT
);
911 mgr
->ctrl_gpr
[SOUND_MIXER_DIGITAL1
][0] = 0xd;
912 mgr
->ctrl_gpr
[SOUND_MIXER_DIGITAL1
][1] = 0xf;
915 card
->ac97
->mixer_state
[SOUND_MIXER_DIGITAL1
] = (right
<< 8) | left
;
917 card
->ac97
->supported_mixers
|= SOUND_MASK_DIGITAL1
;
918 card
->ac97
->stereo_mixers
|= SOUND_MASK_DIGITAL1
;
920 emu10k1_set_volume_gpr(card
, 0xd, left
, VOL_5BIT
);
921 emu10k1_set_volume_gpr(card
, 0xf, right
, VOL_5BIT
);
924 //hard wire the ac97's pcm, pcm volume is done above using dsp code.
926 //for Audigy, we mute it and use the philips 6 channel DAC instead
927 emu10k1_ac97_write(card
->ac97
, 0x18, 0x8000);
929 //For the Live we hardwire it to full volume
930 emu10k1_ac97_write(card
->ac97
, 0x18, 0x0);
932 //remove it from the ac97_codec's control
933 card
->ac97_supported_mixers
&= ~SOUND_MASK_PCM
;
934 card
->ac97_stereo_mixers
&= ~SOUND_MASK_PCM
;
936 //set Igain to 0dB by default, maybe consider hardwiring it here.
937 emu10k1_ac97_write(card
->ac97
, AC97_RECORD_GAIN
, 0x0000);
938 card
->ac97
->mixer_state
[SOUND_MIXER_IGAIN
] = 0x101;
943 static int __devinit
hw_init(struct emu10k1_card
*card
)
946 u32 pagecount
; /* tmp */
949 /* Disable audio and lock cache */
950 emu10k1_writefn0(card
, HCFG
, HCFG_LOCKSOUNDCACHE
| HCFG_LOCKTANKCACHE_MASK
| HCFG_MUTEBUTTONENABLE
);
952 /* Reset recording buffers */
953 sblive_writeptr_tag(card
, 0,
954 MICBS
, ADCBS_BUFSIZE_NONE
,
956 FXBS
, ADCBS_BUFSIZE_NONE
,
958 ADCBS
, ADCBS_BUFSIZE_NONE
,
962 /* Disable channel interrupt */
963 emu10k1_writefn0(card
, INTE
, 0);
964 sblive_writeptr_tag(card
, 0,
971 if (card
->is_audigy
) {
972 sblive_writeptr_tag(card
,0,
978 /* Init envelope engine */
979 for (nCh
= 0; nCh
< NUM_G
; nCh
++) {
980 sblive_writeptr_tag(card
, nCh
,
1001 TREMFRQ
, 24, /* 1 Hz */
1002 FM2FRQ2
, 24, /* 1 Hz */
1005 /*** These are last so OFF prevents writing ***/
1012 sblive_writeptr(card
, CPF
, nCh
, 0);
1014 Audigy FXRT initialization
1015 reversed eng'd, may not be accurate.
1017 if (card
->is_audigy
) {
1018 sblive_writeptr_tag(card
,nCh
,
1023 A_FXRT1
, 0x3f3f3f3f,
1024 A_FXRT2
, 0x3f3f3f3f,
1032 ** Init to 0x02109204 :
1033 ** Clock accuracy = 0 (1000ppm)
1034 ** Sample Rate = 2 (48kHz)
1035 ** Audio Channel = 1 (Left of 2)
1036 ** Source Number = 0 (Unspecified)
1037 ** Generation Status = 1 (Original for Cat Code 12)
1038 ** Cat Code = 12 (Digital Signal Mixer)
1039 ** Mode = 0 (Mode 0)
1040 ** Emphasis = 0 (None)
1041 ** CP = 1 (Copyright unasserted)
1042 ** AN = 0 (Digital audio)
1046 sblive_writeptr_tag(card
, 0,
1049 SPCS0
, (SPCS_CLKACCY_1000PPM
| 0x002000000 |
1050 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
| 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
),
1053 SPCS1
, (SPCS_CLKACCY_1000PPM
| 0x002000000 |
1054 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
| 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
),
1056 /* SPDIF2 & SPDIF3 */
1057 SPCS2
, (SPCS_CLKACCY_1000PPM
| 0x002000000 |
1058 SPCS_CHANNELNUM_LEFT
| SPCS_SOURCENUM_UNSPEC
| SPCS_GENERATIONSTATUS
| 0x00001200 | SPCS_EMPHASIS_NONE
| SPCS_COPYRIGHT
),
1062 if (card
->is_audigy
&& (card
->chiprev
== 4)) {
1063 /* Hacks for Alice3 to work independent of haP16V driver */
1066 //Setup SRCMulti_I2S SamplingRate
1067 tmp
= sblive_readptr(card
, A_SPDIF_SAMPLERATE
, 0);
1070 sblive_writeptr(card
, A_SPDIF_SAMPLERATE
, 0, tmp
);
1072 /* Setup SRCSel (Enable Spdif,I2S SRCMulti) */
1073 emu10k1_writefn0(card
, 0x20, 0x600000);
1074 emu10k1_writefn0(card
, 0x24, 0x14);
1076 /* Setup SRCMulti Input Audio Enable */
1077 emu10k1_writefn0(card
, 0x20, 0x6E0000);
1078 emu10k1_writefn0(card
, 0x24, 0xFF00FF00);
1081 ret
= fx_init(card
); /* initialize effects engine */
1085 card
->tankmem
.size
= 0;
1087 card
->virtualpagetable
.size
= MAXPAGES
* sizeof(u32
);
1089 card
->virtualpagetable
.addr
= pci_alloc_consistent(card
->pci_dev
, card
->virtualpagetable
.size
, &card
->virtualpagetable
.dma_handle
);
1090 if (card
->virtualpagetable
.addr
== NULL
) {
1096 card
->silentpage
.size
= EMUPAGESIZE
;
1098 card
->silentpage
.addr
= pci_alloc_consistent(card
->pci_dev
, card
->silentpage
.size
, &card
->silentpage
.dma_handle
);
1099 if (card
->silentpage
.addr
== NULL
) {
1105 for (pagecount
= 0; pagecount
< MAXPAGES
; pagecount
++)
1106 ((u32
*) card
->virtualpagetable
.addr
)[pagecount
] = cpu_to_le32(((u32
) card
->silentpage
.dma_handle
* 2) | pagecount
);
1108 /* Init page table & tank memory base register */
1109 sblive_writeptr_tag(card
, 0,
1110 PTB
, (u32
) card
->virtualpagetable
.dma_handle
,
1115 for (nCh
= 0; nCh
< NUM_G
; nCh
++) {
1116 sblive_writeptr_tag(card
, nCh
,
1117 MAPA
, MAP_PTI_MASK
| ((u32
) card
->silentpage
.dma_handle
* 2),
1118 MAPB
, MAP_PTI_MASK
| ((u32
) card
->silentpage
.dma_handle
* 2),
1122 /* Hokay, now enable the AUD bit */
1123 /* Enable Audio = 1 */
1124 /* Mute Disable Audio = 0 */
1125 /* Lock Tank Memory = 1 */
1126 /* Lock Sound Memory = 0 */
1128 if (card
->is_audigy
) {
1129 if (card
->chiprev
== 4)
1130 emu10k1_writefn0(card
, HCFG
, HCFG_AUDIOENABLE
| HCFG_AC3ENABLE_CDSPDIF
| HCFG_AC3ENABLE_GPSPDIF
| HCFG_AUTOMUTE
| HCFG_JOYENABLE
);
1132 emu10k1_writefn0(card
, HCFG
, HCFG_AUDIOENABLE
| HCFG_AUTOMUTE
| HCFG_JOYENABLE
);
1134 if (card
->model
== 0x20 || card
->model
== 0xc400 ||
1135 (card
->model
== 0x21 && card
->chiprev
< 6))
1136 emu10k1_writefn0(card
, HCFG
, HCFG_AUDIOENABLE
| HCFG_LOCKTANKCACHE_MASK
| HCFG_AUTOMUTE
);
1138 emu10k1_writefn0(card
, HCFG
, HCFG_AUDIOENABLE
| HCFG_LOCKTANKCACHE_MASK
| HCFG_AUTOMUTE
| HCFG_JOYENABLE
);
1140 /* Enable Vol_Ctrl irqs */
1141 emu10k1_irq_enable(card
, INTE_VOLINCRENABLE
| INTE_VOLDECRENABLE
| INTE_MUTEENABLE
| INTE_FXDSPENABLE
);
1143 if (card
->is_audigy
&& (card
->chiprev
== 4)) {
1144 /* Unmute Analog now. Set GPO6 to 1 for Apollo.
1145 * This has to be done after init ALice3 I2SOut beyond 48KHz.
1146 * So, sequence is important. */
1147 u32 tmp
= emu10k1_readfn0(card
, A_IOCFG
);
1149 emu10k1_writefn0(card
, A_IOCFG
, tmp
);
1152 /* FIXME: TOSLink detection */
1153 card
->has_toslink
= 0;
1155 /* Initialize digital passthrough variables */
1156 card
->pt
.pos_gpr
= card
->pt
.intr_gpr
= card
->pt
.enable_gpr
= -1;
1157 card
->pt
.selected
= 0;
1158 card
->pt
.state
= PT_STATE_INACTIVE
;
1159 card
->pt
.spcs_to_use
= 0x01;
1160 card
->pt
.patch_name
= "AC3pass";
1161 card
->pt
.intr_gpr_name
= "count";
1162 card
->pt
.enable_gpr_name
= "enable";
1163 card
->pt
.pos_gpr_name
= "ptr";
1164 spin_lock_init(&card
->pt
.lock
);
1165 init_waitqueue_head(&card
->pt
.wait
);
1167 /* tmp = sblive_readfn0(card, HCFG);
1168 if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
1169 sblive_writefn0(card, HCFG, tmp | 0x800);
1173 if (tmp != (sblive_readfn0(card, HCFG) & ~0x800)) {
1174 card->has_toslink = 1;
1175 sblive_writefn0(card, HCFG, tmp);
1182 pci_free_consistent(card
->pci_dev
, card
->virtualpagetable
.size
, card
->virtualpagetable
.addr
, card
->virtualpagetable
.dma_handle
);
1184 fx_cleanup(&card
->mgr
);
1189 static int __devinit
emu10k1_init(struct emu10k1_card
*card
)
1192 if (hw_init(card
) < 0)
1199 DPD(2, " hw control register -> %#x\n", emu10k1_readfn0(card
, HCFG
));
1204 static void emu10k1_cleanup(struct emu10k1_card
*card
)
1208 emu10k1_writefn0(card
, INTE
, 0);
1210 /** Shutdown the chip **/
1211 for (ch
= 0; ch
< NUM_G
; ch
++)
1212 sblive_writeptr(card
, DCYSUSV
, ch
, 0);
1214 for (ch
= 0; ch
< NUM_G
; ch
++) {
1215 sblive_writeptr_tag(card
, ch
,
1221 sblive_writeptr(card
, CPF
, ch
, 0);
1224 /* Disable audio and lock cache */
1225 emu10k1_writefn0(card
, HCFG
, HCFG_LOCKSOUNDCACHE
| HCFG_LOCKTANKCACHE_MASK
| HCFG_MUTEBUTTONENABLE
);
1227 sblive_writeptr_tag(card
, 0,
1230 /* Reset recording buffers */
1231 MICBS
, ADCBS_BUFSIZE_NONE
,
1233 FXBS
, ADCBS_BUFSIZE_NONE
,
1236 ADCBS
, ADCBS_BUFSIZE_NONE
,
1242 /* Disable channel interrupt */
1249 if (card
->is_audigy
)
1250 sblive_writeptr(card
, 0, A_DBG
, A_DBG_SINGLE_STEP
);
1252 pci_free_consistent(card
->pci_dev
, card
->virtualpagetable
.size
, card
->virtualpagetable
.addr
, card
->virtualpagetable
.dma_handle
);
1253 pci_free_consistent(card
->pci_dev
, card
->silentpage
.size
, card
->silentpage
.addr
, card
->silentpage
.dma_handle
);
1255 if(card
->tankmem
.size
!= 0)
1256 pci_free_consistent(card
->pci_dev
, card
->tankmem
.size
, card
->tankmem
.addr
, card
->tankmem
.dma_handle
);
1258 /* release patch storage memory */
1259 fx_cleanup(&card
->mgr
);
1262 /* Driver initialization routine */
1263 static int __devinit
emu10k1_probe(struct pci_dev
*pci_dev
, const struct pci_device_id
*pci_id
)
1265 struct emu10k1_card
*card
;
1269 if (pci_set_dma_mask(pci_dev
, EMU10K1_DMA_MASK
)) {
1270 printk(KERN_ERR
"emu10k1: architecture does not support 29bit PCI busmaster DMA\n");
1274 if (pci_enable_device(pci_dev
))
1277 pci_set_master(pci_dev
);
1279 if ((card
= kzalloc(sizeof(struct emu10k1_card
), GFP_KERNEL
)) == NULL
) {
1280 printk(KERN_ERR
"emu10k1: out of memory\n");
1284 card
->iobase
= pci_resource_start(pci_dev
, 0);
1285 card
->length
= pci_resource_len(pci_dev
, 0);
1287 if (request_region(card
->iobase
, card
->length
, card_names
[pci_id
->driver_data
]) == NULL
) {
1288 printk(KERN_ERR
"emu10k1: IO space in use\n");
1293 pci_set_drvdata(pci_dev
, card
);
1295 card
->irq
= pci_dev
->irq
;
1296 card
->pci_dev
= pci_dev
;
1298 /* Reserve IRQ Line */
1299 if (request_irq(card
->irq
, emu10k1_interrupt
, IRQF_SHARED
, card_names
[pci_id
->driver_data
], card
)) {
1300 printk(KERN_ERR
"emu10k1: IRQ in use\n");
1305 pci_read_config_byte(pci_dev
, PCI_REVISION_ID
, &card
->chiprev
);
1306 pci_read_config_word(pci_dev
, PCI_SUBSYSTEM_ID
, &card
->model
);
1308 printk(KERN_INFO
"emu10k1: %s rev %d model %#04x found, IO at %#04lx-%#04lx, IRQ %d\n",
1309 card_names
[pci_id
->driver_data
], card
->chiprev
, card
->model
, card
->iobase
,
1310 card
->iobase
+ card
->length
- 1, card
->irq
);
1312 if (pci_id
->device
== PCI_DEVICE_ID_CREATIVE_AUDIGY
)
1313 card
->is_audigy
= 1;
1315 pci_read_config_dword(pci_dev
, PCI_SUBSYSTEM_VENDOR_ID
, &subsysvid
);
1316 card
->is_aps
= (subsysvid
== EMU_APS_SUBID
);
1318 spin_lock_init(&card
->lock
);
1319 mutex_init(&card
->open_sem
);
1320 card
->open_mode
= 0;
1321 init_waitqueue_head(&card
->open_wait
);
1323 ret
= emu10k1_audio_init(card
);
1325 printk(KERN_ERR
"emu10k1: cannot initialize audio devices\n");
1329 ret
= emu10k1_mixer_init(card
);
1331 printk(KERN_ERR
"emu10k1: cannot initialize AC97 codec\n");
1335 ret
= emu10k1_midi_init(card
);
1337 printk(KERN_ERR
"emu10k1: cannot register midi device\n");
1341 ret
= emu10k1_init(card
);
1343 printk(KERN_ERR
"emu10k1: cannot initialize device\n");
1344 goto err_emu10k1_init
;
1348 emu10k1_ecard_init(card
);
1350 ret
= emu10k1_register_devices(card
);
1354 /* proc entries must be created after registering devices, as
1355 * emu10k1_info_proc prints card->audio_dev &co. */
1356 ret
= emu10k1_proc_init(card
);
1358 printk(KERN_ERR
"emu10k1: cannot initialize proc directory\n");
1362 list_add(&card
->list
, &emu10k1_devs
);
1367 emu10k1_unregister_devices(card
);
1370 emu10k1_cleanup(card
);
1373 emu10k1_midi_cleanup(card
);
1376 emu10k1_mixer_cleanup(card
);
1379 emu10k1_audio_cleanup(card
);
1382 free_irq(card
->irq
, card
);
1385 release_region(card
->iobase
, card
->length
);
1386 pci_set_drvdata(pci_dev
, NULL
);
1394 static void __devexit
emu10k1_remove(struct pci_dev
*pci_dev
)
1396 struct emu10k1_card
*card
= pci_get_drvdata(pci_dev
);
1398 list_del(&card
->list
);
1400 emu10k1_unregister_devices(card
);
1401 emu10k1_cleanup(card
);
1402 emu10k1_midi_cleanup(card
);
1403 emu10k1_mixer_cleanup(card
);
1404 emu10k1_proc_cleanup(card
);
1405 emu10k1_audio_cleanup(card
);
1406 free_irq(card
->irq
, card
);
1407 release_region(card
->iobase
, card
->length
);
1409 pci_set_drvdata(pci_dev
, NULL
);
1412 MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@lists.sourceforge.net)");
1413 MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION
"\nCopyright (C) 1999 Creative Technology Ltd.");
1414 MODULE_LICENSE("GPL");
1416 static struct pci_driver emu10k1_pci_driver
= {
1418 .id_table
= emu10k1_pci_tbl
,
1419 .probe
= emu10k1_probe
,
1420 .remove
= __devexit_p(emu10k1_remove
),
1423 static int __init
emu10k1_init_module(void)
1425 printk(KERN_INFO
"Creative EMU10K1 PCI Audio Driver, version " DRIVER_VERSION
", " __TIME__
" " __DATE__
"\n");
1427 return pci_register_driver(&emu10k1_pci_driver
);
1430 static void __exit
emu10k1_cleanup_module(void)
1432 pci_unregister_driver(&emu10k1_pci_driver
);
1437 module_init(emu10k1_init_module
);
1438 module_exit(emu10k1_cleanup_module
);
1440 #ifdef EMU10K1_SEQUENCER
1443 extern int emu10k1_seq_midi_open(int dev
, int mode
,
1444 void (*input
)(int dev
, unsigned char midi_byte
),
1445 void (*output
)(int dev
));
1446 extern void emu10k1_seq_midi_close(int dev
);
1447 extern int emu10k1_seq_midi_out(int dev
, unsigned char midi_byte
);
1448 extern int emu10k1_seq_midi_start_read(int dev
);
1449 extern int emu10k1_seq_midi_end_read(int dev
);
1450 extern void emu10k1_seq_midi_kick(int dev
);
1451 extern int emu10k1_seq_midi_buffer_status(int dev
);
1453 static struct midi_operations emu10k1_midi_operations
=
1456 {"EMU10K1 MIDI", 0, 0, SNDCARD_EMU10K1
},
1459 emu10k1_seq_midi_open
,
1460 emu10k1_seq_midi_close
,
1462 emu10k1_seq_midi_out
,
1463 emu10k1_seq_midi_start_read
,
1464 emu10k1_seq_midi_end_read
,
1465 emu10k1_seq_midi_kick
,
1467 emu10k1_seq_midi_buffer_status
,