Merge http://gkernel.bkbits.net/linus-2.5
[opensuse:kernel.git] / sound / oss / emu10k1 / main.c
1 /*
2  **********************************************************************
3  *     main.c - Creative EMU10K1 audio driver
4  *     Copyright 1999, 2000 Creative Labs, Inc.
5  *
6  **********************************************************************
7  *
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
12  *
13  **********************************************************************
14  *
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.
19  *
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.
24  *
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,
28  *     USA.
29  *
30  **********************************************************************
31  *
32  *      Supported devices:
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)
38  *
39  *      Revision history:
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  *
73  *********************************************************************/
74
75 /* These are only included once per module */
76 #include <linux/version.h>
77 #include <linux/module.h>
78 #include <linux/slab.h>
79 #include <linux/init.h>
80 #include <linux/delay.h>
81 #include <linux/proc_fs.h>
82
83 #include "hwaccess.h"
84 #include "8010.h"
85 #include "efxmgr.h"
86 #include "cardwo.h"
87 #include "cardwi.h"
88 #include "cardmo.h"
89 #include "cardmi.h"
90 #include "recmgr.h"
91 #include "ecard.h"
92
93
94 #ifdef EMU10K1_SEQUENCER
95 #define MIDI_SYNTH_NAME "EMU10K1 MIDI"
96 #define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
97  
98 #include "../sound_config.h"
99 #include "../midi_synth.h"
100
101 /* this should be in dev_table.h */
102 #define SNDCARD_EMU10K1 46
103 #endif
104  
105 #define DRIVER_VERSION "0.16"
106
107 /* FIXME: is this right? */
108 /* does the card support 32 bit bus master?*/
109 #define EMU10K1_DMA_MASK                0xffffffff      /* DMA buffer mask for pci_alloc_consist */
110
111 #ifndef PCI_VENDOR_ID_CREATIVE
112 #define PCI_VENDOR_ID_CREATIVE 0x1102
113 #endif
114
115 #ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1
116 #define PCI_DEVICE_ID_CREATIVE_EMU10K1 0x0002
117 #endif
118
119 #define EMU_APS_SUBID   0x40011102
120  
121 enum {
122         EMU10K1 = 0,
123 };
124
125 static char *card_names[] __devinitdata = {
126         "EMU10K1",
127 };
128
129 static struct pci_device_id emu10k1_pci_tbl[] = {
130         {PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_EMU10K1,
131          PCI_ANY_ID, PCI_ANY_ID, 0, 0, EMU10K1},
132         {0,}
133 };
134
135 MODULE_DEVICE_TABLE(pci, emu10k1_pci_tbl);
136
137 /* Global var instantiation */
138
139 LIST_HEAD(emu10k1_devs);
140
141 extern struct file_operations emu10k1_audio_fops;
142 extern struct file_operations emu10k1_mixer_fops;
143 extern struct file_operations emu10k1_midi_fops;
144
145 #ifdef EMU10K1_SEQUENCER
146 static struct midi_operations emu10k1_midi_operations;
147 #endif
148
149 extern void emu10k1_interrupt(int, void *, struct pt_regs *s);
150
151 static int __devinit emu10k1_audio_init(struct emu10k1_card *card)
152 {
153         card->audio_dev = register_sound_dsp(&emu10k1_audio_fops, -1);
154         if (card->audio_dev < 0) {
155                 printk(KERN_ERR "emu10k1: cannot register first audio device!\n");
156                 goto err_dev;
157         }
158
159         card->audio_dev1 = register_sound_dsp(&emu10k1_audio_fops, -1);
160         if (card->audio_dev1 < 0) {
161                 printk(KERN_ERR "emu10k1: cannot register second audio device!\n");
162                 goto err_dev1;
163         }
164
165         /* Assign default playback voice parameters */
166         card->mchannel_fx = 8;
167         /* mono voice */
168         card->waveout.send_a[0] = 0xff;
169         card->waveout.send_b[0] = 0xff;
170         card->waveout.send_c[0] = 0x00;
171         card->waveout.send_d[0] = 0x00;
172         card->waveout.send_routing[0] = 0x3210;
173
174         /* stereo voice */
175         /* left */
176         card->waveout.send_a[1] = 0xff;
177         card->waveout.send_b[1] = 0x00;
178         card->waveout.send_c[1] = 0x00;
179         card->waveout.send_d[1] = 0x00;
180         card->waveout.send_routing[1] = 0x3210;
181
182         /* right */
183         card->waveout.send_a[2] = 0x00;
184         card->waveout.send_b[2] = 0xff;
185         card->waveout.send_c[2] = 0x00;
186         card->waveout.send_d[2] = 0x00;
187         card->waveout.send_routing[2] = 0x3210;
188
189         /* Assign default recording parameters */
190         /* FIXME */
191         if(card->isaps)
192                 card->wavein.recsrc = WAVERECORD_FX;
193         else
194                 card->wavein.recsrc = WAVERECORD_AC97;
195
196         card->wavein.fxwc = 0x0003;
197         return 0;
198
199 err_dev1:
200         unregister_sound_dsp(card->audio_dev);
201 err_dev:
202         return -ENODEV;
203 }
204
205 static void __devinit emu10k1_audio_cleanup(struct emu10k1_card *card)
206 {
207         unregister_sound_dsp(card->audio_dev1);
208         unregister_sound_dsp(card->audio_dev);
209 }
210
211 static int __devinit emu10k1_mixer_init(struct emu10k1_card *card)
212 {
213         char s[32];
214         card->ac97.dev_mixer = register_sound_mixer(&emu10k1_mixer_fops, -1);
215         if (card->ac97.dev_mixer < 0) {
216                 printk(KERN_ERR "emu10k1: cannot register mixer device\n");
217                 return -EIO;
218         }
219
220         card->ac97.private_data = card;
221
222         if (!card->isaps) {
223                 card->ac97.id = 0;
224                 card->ac97.codec_read = emu10k1_ac97_read;
225                 card->ac97.codec_write = emu10k1_ac97_write;
226
227                 if (ac97_probe_codec (&card->ac97) == 0) {
228                         printk(KERN_ERR "emu10k1: unable to probe AC97 codec\n");
229                         goto err_out;
230                 }
231                 /* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
232                         does not support this, it shouldn't do any harm */
233                 sblive_writeptr(card, AC97SLOT, 0, AC97SLOT_CNTR | AC97SLOT_LFE);
234
235                 // Force 5bit
236                 //card->ac97.bit_resolution=5;
237
238                 if (!proc_mkdir ("driver/emu10k1", 0)) {
239                         printk(KERN_ERR "emu10k1: unable to create proc directory driver/emu10k1\n");
240                         goto err_out;
241                 }
242
243                 sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
244                 if (!proc_mkdir (s, 0)) {
245                         printk(KERN_ERR "emu10k1: unable to create proc directory %s\n", s);
246                         goto err_emu10k1_proc;
247                 }
248         
249                 sprintf(s, "driver/emu10k1/%s/ac97", card->pci_dev->slot_name);
250                 if (!create_proc_read_entry (s, 0, 0, ac97_read_proc, &card->ac97)) {
251                         printk(KERN_ERR "emu10k1: unable to create proc entry %s\n", s);
252                         goto err_ac97_proc;
253                 }
254
255                 /* these will store the original values and never be modified */
256                 card->ac97_supported_mixers = card->ac97.supported_mixers;
257                 card->ac97_stereo_mixers = card->ac97.stereo_mixers;
258         }
259
260         return 0;
261
262  err_ac97_proc:
263         sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
264         remove_proc_entry(s, NULL);
265
266  err_emu10k1_proc:
267         remove_proc_entry("driver/emu10k1", NULL);
268  err_out:
269         unregister_sound_mixer (card->ac97.dev_mixer);
270         return -EIO;
271 }
272
273 static void __devinit emu10k1_mixer_cleanup(struct emu10k1_card *card)
274 {
275         char s[32];
276
277         if (!card->isaps) {
278                 sprintf(s, "driver/emu10k1/%s/ac97", card->pci_dev->slot_name);
279                 remove_proc_entry(s, NULL);
280
281                 sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
282                 remove_proc_entry(s, NULL);
283
284                 remove_proc_entry("driver/emu10k1", NULL);
285         }
286
287         unregister_sound_mixer (card->ac97.dev_mixer);
288 }
289
290 static int __devinit emu10k1_midi_init(struct emu10k1_card *card)
291 {
292         int ret;
293
294         card->midi_dev = register_sound_midi(&emu10k1_midi_fops, -1);
295         if (card->midi_dev < 0) {
296                 printk(KERN_ERR "emu10k1: cannot register midi device!\n");
297                 return -ENODEV;
298         }
299
300
301         card->mpuout = kmalloc(sizeof(struct emu10k1_mpuout), GFP_KERNEL);
302         if (card->mpuout == NULL) {
303                 printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n");
304                 ret = -ENOMEM;
305                 goto err_out1;
306         }
307
308         memset(card->mpuout, 0, sizeof(struct emu10k1_mpuout));
309
310         card->mpuout->intr = 1;
311         card->mpuout->status = FLAGS_AVAILABLE;
312         card->mpuout->state = CARDMIDIOUT_STATE_DEFAULT;
313
314         tasklet_init(&card->mpuout->tasklet, emu10k1_mpuout_bh, (unsigned long) card);
315
316         spin_lock_init(&card->mpuout->lock);
317
318         card->mpuin = kmalloc(sizeof(struct emu10k1_mpuin), GFP_KERNEL);
319         if (card->mpuin == NULL) {
320                 printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n");
321                 ret = -ENOMEM;
322                 goto err_out2;
323         }
324
325         memset(card->mpuin, 0, sizeof(struct emu10k1_mpuin));
326
327         card->mpuin->status = FLAGS_AVAILABLE;
328
329         tasklet_init(&card->mpuin->tasklet, emu10k1_mpuin_bh, (unsigned long) card->mpuin);
330
331         spin_lock_init(&card->mpuin->lock);
332
333         /* Reset the MPU port */
334         if (emu10k1_mpu_reset(card) < 0) {
335                 ERROR();
336                 ret = -EIO;
337                 goto err_out3;
338         }
339
340 #ifdef EMU10K1_SEQUENCER
341         card->seq_dev = sound_alloc_mididev();
342         if (card->seq_dev == -1)
343                         printk(KERN_WARNING "emu10k1: unable to register sequencer device!");
344         else {
345                         std_midi_synth.midi_dev = card->seq_dev;
346                         midi_devs[card->seq_dev] = 
347                                         (struct midi_operations *)
348                                         kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
349                         
350                         if (midi_devs[card->seq_dev] == NULL) {
351                                 printk(KERN_ERR "emu10k1: unable to allocate memory!");
352                                 sound_unload_mididev(card->seq_dev);
353                                 card->seq_dev = -1;
354                                 return 0;
355                         } else {
356                                 memcpy((char *)midi_devs[card->seq_dev], 
357                                         (char *)&emu10k1_midi_operations, 
358                                         sizeof(struct midi_operations));
359                                 midi_devs[card->seq_dev]->devc = card;
360                                 sequencer_init();
361                         }
362         }
363         card->seq_mididev = 0;
364 #endif
365         return 0;
366
367 err_out3:
368         kfree(card->mpuin);
369 err_out2:
370         kfree(card->mpuout);
371 err_out1:
372         unregister_sound_midi(card->midi_dev);
373         return ret;
374 }
375
376 static void __devinit emu10k1_midi_cleanup(struct emu10k1_card *card)
377 {
378         tasklet_kill(&card->mpuout->tasklet);
379         kfree(card->mpuout);
380
381         tasklet_kill(&card->mpuin->tasklet);
382         kfree(card->mpuin);
383
384 #ifdef EMU10K1_SEQUENCER
385         if (card->seq_dev > -1) {
386                 kfree(midi_devs[card->seq_dev]);
387                 midi_devs[card->seq_dev] = NULL;
388                 sound_unload_mididev(card->seq_dev);
389                 card->seq_dev = -1;
390         }
391 #endif
392
393         unregister_sound_midi(card->midi_dev);
394 }
395
396 static void __devinit voice_init(struct emu10k1_card *card)
397 {
398         int i;
399
400         for (i = 0; i < NUM_G; i++)
401                 card->voicetable[i] = VOICE_USAGE_FREE;
402 }
403
404 static void __devinit timer_init(struct emu10k1_card *card)
405 {
406         INIT_LIST_HEAD(&card->timers);
407         card->timer_delay = TIMER_STOPPED;
408         card->timer_lock = SPIN_LOCK_UNLOCKED;
409 }
410
411 static void __devinit addxmgr_init(struct emu10k1_card *card)
412 {
413         u32 count;
414
415         for (count = 0; count < MAXPAGES; count++)
416                 card->emupagetable[count] = 0;
417
418         /* Mark first page as used */
419         /* This page is reserved by the driver */
420         card->emupagetable[0] = 0x8001;
421         card->emupagetable[1] = MAXPAGES - 1;
422 }
423
424 static void __devinit fx_cleanup(struct patch_manager *mgr)
425 {
426         int i;
427         for(i = 0; i < mgr->current_pages; i++)
428                 free_page((unsigned long) mgr->patch[i]);
429 }
430
431 static int __devinit fx_init(struct emu10k1_card *card)
432 {
433         struct patch_manager *mgr = &card->mgr;
434         struct dsp_patch *patch;
435         struct dsp_rpatch *rpatch;
436         s32 left, right;
437         int i;
438         u32 pc = 0;
439         u32 patch_n;
440
441         for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
442                 mgr->ctrl_gpr[i][0] = -1;
443                 mgr->ctrl_gpr[i][1] = -1;
444         }
445
446         for (i = 0; i < 512; i++)
447                 OP(6, 0x40, 0x40, 0x40, 0x40);
448
449         for (i = 0; i < 256; i++)
450                 sblive_writeptr_tag(card, 0,
451                                     FXGPREGBASE + i, 0,
452                                     TANKMEMADDRREGBASE + i, 0,
453                                     TAGLIST_END);
454
455         /* !! The number bellow must equal the number of patches, currently 11 !! */
456         mgr->current_pages = (11 + PATCHES_PER_PAGE - 1) / PATCHES_PER_PAGE;
457         for (i = 0; i < mgr->current_pages; i++) {
458                 mgr->patch[i] = (void *)__get_free_page(GFP_KERNEL);
459                 if (mgr->patch[i] == NULL) {
460                         mgr->current_pages = i;
461                         fx_cleanup(mgr);
462                         return -ENOMEM;
463                 }
464                 memset(mgr->patch[i], 0, PAGE_SIZE);
465         }
466
467         pc = 0;
468         patch_n = 0;
469         //first free GPR = 0x11b
470
471         /* FX volume correction and Volume control*/
472         INPUT_PATCH_START(patch, "Pcm L vol", 0x0, 0);
473         GET_OUTPUT_GPR(patch, 0x100, 0x0);
474         GET_CONTROL_GPR(patch, 0x106, "Vol", 0, 0x7fffffff);
475         GET_DYNAMIC_GPR(patch, 0x112);
476
477         OP(4, 0x112, 0x40, PCM_IN_L, 0x44); //*4
478         OP(0, 0x100, 0x040, 0x112, 0x106);  //*vol
479         INPUT_PATCH_END(patch);
480
481
482         INPUT_PATCH_START(patch, "Pcm R vol", 0x1, 0);
483         GET_OUTPUT_GPR(patch, 0x101, 0x1);
484         GET_CONTROL_GPR(patch, 0x107, "Vol", 0, 0x7fffffff);
485         GET_DYNAMIC_GPR(patch, 0x112);
486
487         OP(4, 0x112, 0x40, PCM_IN_R, 0x44); 
488         OP(0, 0x101, 0x040, 0x112, 0x107);
489
490         INPUT_PATCH_END(patch);
491
492
493         // CD-Digital In Volume control
494         INPUT_PATCH_START(patch, "CD-Digital Vol L", 0x12, 0);
495         GET_OUTPUT_GPR(patch, 0x10c, 0x12);
496         GET_CONTROL_GPR(patch, 0x10d, "Vol", 0, 0x7fffffff);
497
498         OP(0, 0x10c, 0x040, SPDIF_CD_L, 0x10d);
499         INPUT_PATCH_END(patch);
500
501         INPUT_PATCH_START(patch, "CD-Digital Vol R", 0x13, 0);
502         GET_OUTPUT_GPR(patch, 0x10e, 0x13);
503         GET_CONTROL_GPR(patch, 0x10f, "Vol", 0, 0x7fffffff);
504
505         OP(0, 0x10e, 0x040, SPDIF_CD_R, 0x10f);
506         INPUT_PATCH_END(patch);
507
508         //Volume Correction for Multi-channel Inputs
509         INPUT_PATCH_START(patch, "Multi-Channel Gain", 0x08, 0);
510         patch->input=patch->output=0x3F00;
511
512         GET_OUTPUT_GPR(patch, 0x113, MULTI_FRONT_L);
513         GET_OUTPUT_GPR(patch, 0x114, MULTI_FRONT_R);
514         GET_OUTPUT_GPR(patch, 0x115, MULTI_REAR_L);
515         GET_OUTPUT_GPR(patch, 0x116, MULTI_REAR_R);
516         GET_OUTPUT_GPR(patch, 0x117, MULTI_CENTER);
517         GET_OUTPUT_GPR(patch, 0x118, MULTI_LFE);
518
519         OP(4, 0x113, 0x40, MULTI_FRONT_L, 0x44);
520         OP(4, 0x114, 0x40, MULTI_FRONT_R, 0x44);
521         OP(4, 0x115, 0x40, MULTI_REAR_L, 0x44);
522         OP(4, 0x116, 0x40, MULTI_REAR_R, 0x44);
523         OP(4, 0x117, 0x40, MULTI_CENTER, 0x44);
524         OP(4, 0x118, 0x40, MULTI_LFE, 0x44);
525         
526         INPUT_PATCH_END(patch);
527
528
529         //Routing patch start
530         ROUTING_PATCH_START(rpatch, "Routing");
531         GET_INPUT_GPR(rpatch, 0x100, 0x0);
532         GET_INPUT_GPR(rpatch, 0x101, 0x1);
533         GET_INPUT_GPR(rpatch, 0x10c, 0x12);
534         GET_INPUT_GPR(rpatch, 0x10e, 0x13);
535         GET_INPUT_GPR(rpatch, 0x113, MULTI_FRONT_L);
536         GET_INPUT_GPR(rpatch, 0x114, MULTI_FRONT_R);
537         GET_INPUT_GPR(rpatch, 0x115, MULTI_REAR_L);
538         GET_INPUT_GPR(rpatch, 0x116, MULTI_REAR_R);
539         GET_INPUT_GPR(rpatch, 0x117, MULTI_CENTER);
540         GET_INPUT_GPR(rpatch, 0x118, MULTI_LFE);
541
542         GET_DYNAMIC_GPR(rpatch, 0x102);
543         GET_DYNAMIC_GPR(rpatch, 0x103);
544
545         GET_OUTPUT_GPR(rpatch, 0x104, 0x8);
546         GET_OUTPUT_GPR(rpatch, 0x105, 0x9);
547         GET_OUTPUT_GPR(rpatch, 0x10a, 0x2);
548         GET_OUTPUT_GPR(rpatch, 0x10b, 0x3);
549
550
551         /* input buffer */
552         OP(6, 0x102, AC97_IN_L, 0x40, 0x40);
553         OP(6, 0x103, AC97_IN_R, 0x40, 0x40);
554
555
556         /* Digital In + PCM + MULTI_FRONT-> AC97 out (front speakers)*/
557         OP(6, AC97_FRONT_L, 0x100, 0x10c, 0x113);
558
559         CONNECT(MULTI_FRONT_L, AC97_FRONT_L);
560         CONNECT(PCM_IN_L, AC97_FRONT_L);
561         CONNECT(SPDIF_CD_L, AC97_FRONT_L);
562
563         OP(6, AC97_FRONT_R, 0x101, 0x10e, 0x114);
564
565         CONNECT(MULTI_FRONT_R, AC97_FRONT_R);
566         CONNECT(PCM_IN_R, AC97_FRONT_R);
567         CONNECT(SPDIF_CD_R, AC97_FRONT_R);
568
569         /* Digital In + PCM + AC97 In + PCM1 + MULTI_REAR --> Rear Channel */ 
570         OP(6, 0x104, PCM1_IN_L, 0x100, 0x115);
571         OP(6, 0x104, 0x104, 0x10c, 0x102);
572
573         CONNECT(MULTI_REAR_L, ANALOG_REAR_L);
574         CONNECT(AC97_IN_L, ANALOG_REAR_L);
575         CONNECT(PCM_IN_L, ANALOG_REAR_L);
576         CONNECT(SPDIF_CD_L, ANALOG_REAR_L);
577         CONNECT(PCM1_IN_L, ANALOG_REAR_L);
578
579         OP(6, 0x105, PCM1_IN_R, 0x101, 0x116);
580         OP(6, 0x105, 0x105, 0x10e, 0x103);
581
582         CONNECT(MULTI_REAR_R, ANALOG_REAR_R);
583         CONNECT(AC97_IN_R, ANALOG_REAR_R);
584         CONNECT(PCM_IN_R, ANALOG_REAR_R);
585         CONNECT(SPDIF_CD_R, ANALOG_REAR_R);
586         CONNECT(PCM1_IN_R, ANALOG_REAR_R);
587
588         /* Digital In + PCM + AC97 In + MULTI_FRONT --> Digital out */
589         OP(6, 0x10b, 0x100, 0x102, 0x10c);
590         OP(6, 0x10b, 0x10b, 0x113, 0x40);
591
592         CONNECT(MULTI_FRONT_L, DIGITAL_OUT_L);
593         CONNECT(PCM_IN_L, DIGITAL_OUT_L);
594         CONNECT(AC97_IN_L, DIGITAL_OUT_L);
595         CONNECT(SPDIF_CD_L, DIGITAL_OUT_L);
596
597         OP(6, 0x10a, 0x101, 0x103, 0x10e);
598         OP(6, 0x10b, 0x10b, 0x114, 0x40);
599
600         CONNECT(MULTI_FRONT_R, DIGITAL_OUT_R);
601         CONNECT(PCM_IN_R, DIGITAL_OUT_R);
602         CONNECT(AC97_IN_R, DIGITAL_OUT_R);
603         CONNECT(SPDIF_CD_R, DIGITAL_OUT_R);
604
605         /* AC97 In --> ADC Recording Buffer */
606         OP(6, ADC_REC_L, 0x102, 0x40, 0x40);
607
608         CONNECT(AC97_IN_L, ADC_REC_L);
609
610         OP(6, ADC_REC_R, 0x103, 0x40, 0x40);
611
612         CONNECT(AC97_IN_R, ADC_REC_R);
613
614
615         /* fx12:Analog-Center */
616         OP(6, ANALOG_CENTER, 0x117, 0x40, 0x40);
617         CONNECT(MULTI_CENTER, ANALOG_CENTER);
618
619         /* fx11:Analog-LFE */
620         OP(6, ANALOG_LFE, 0x118, 0x40, 0x40);
621         CONNECT(MULTI_LFE, ANALOG_LFE);
622
623         /* fx12:Digital-Center */
624         OP(6, DIGITAL_CENTER, 0x117, 0x40, 0x40);
625         CONNECT(MULTI_CENTER, DIGITAL_CENTER);
626
627         /* fx11:Analog-LFE */
628         OP(6, DIGITAL_LFE, 0x118, 0x40, 0x40);
629         CONNECT(MULTI_LFE, DIGITAL_LFE);
630         
631         ROUTING_PATCH_END(rpatch);
632
633
634         // Rear volume control
635         OUTPUT_PATCH_START(patch, "Vol Rear L", 0x8, 0);
636         GET_INPUT_GPR(patch, 0x104, 0x8);
637         GET_CONTROL_GPR(patch, 0x119, "Vol", 0, 0x7fffffff);
638
639         OP(0, ANALOG_REAR_L, 0x040, 0x104, 0x119);
640         OUTPUT_PATCH_END(patch);
641
642
643         OUTPUT_PATCH_START(patch, "Vol Rear R", 0x9, 0);
644         GET_INPUT_GPR(patch, 0x105, 0x9);
645         GET_CONTROL_GPR(patch, 0x11a, "Vol", 0, 0x7fffffff);
646
647         OP(0, ANALOG_REAR_R, 0x040, 0x105, 0x11a);
648         OUTPUT_PATCH_END(patch);
649
650
651         //Master volume control on front-digital
652         OUTPUT_PATCH_START(patch, "Vol Master L", 0x2, 1);
653         GET_INPUT_GPR(patch, 0x10a, 0x2);
654         GET_CONTROL_GPR(patch, 0x108, "Vol", 0, 0x7fffffff);
655
656         OP(0, DIGITAL_OUT_L, 0x040, 0x10a, 0x108);
657         OUTPUT_PATCH_END(patch);
658
659
660         OUTPUT_PATCH_START(patch, "Vol Master R", 0x3, 1);
661         GET_INPUT_GPR(patch, 0x10b, 0x3);
662         GET_CONTROL_GPR(patch, 0x109, "Vol", 0, 0x7fffffff);
663
664         OP(0, DIGITAL_OUT_R, 0x040, 0x10b, 0x109);
665         OUTPUT_PATCH_END(patch);
666
667
668         /* delimiter patch */
669         patch = PATCH(mgr, patch_n);
670         patch->code_size = 0;
671
672         sblive_writeptr(card, DBG, 0, 0);
673
674         mgr->lock = SPIN_LOCK_UNLOCKED;
675
676
677         //Master volume
678         mgr->ctrl_gpr[SOUND_MIXER_VOLUME][0] = 8;
679         mgr->ctrl_gpr[SOUND_MIXER_VOLUME][1] = 9;
680
681         left = card->ac97.mixer_state[SOUND_MIXER_VOLUME] & 0xff;
682         right = (card->ac97.mixer_state[SOUND_MIXER_VOLUME] >> 8) & 0xff;
683
684         emu10k1_set_volume_gpr(card, 8, left, 1 << card->ac97.bit_resolution);
685         emu10k1_set_volume_gpr(card, 9, right, 1 << card->ac97.bit_resolution);
686
687         //Rear volume
688         mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][0] = 0x19;
689         mgr->ctrl_gpr[ SOUND_MIXER_OGAIN ][1] = 0x1a;
690
691         left = right = 67;
692         card->ac97.mixer_state[SOUND_MIXER_OGAIN] = (right << 8) | left;
693
694         card->ac97.supported_mixers |= SOUND_MASK_OGAIN;
695         card->ac97.stereo_mixers |= SOUND_MASK_OGAIN;
696
697         emu10k1_set_volume_gpr(card, 0x19, left, VOL_5BIT);
698         emu10k1_set_volume_gpr(card, 0x1a, right, VOL_5BIT);
699
700         //PCM Volume
701         mgr->ctrl_gpr[SOUND_MIXER_PCM][0] = 6;
702         mgr->ctrl_gpr[SOUND_MIXER_PCM][1] = 7;
703
704         left = card->ac97.mixer_state[SOUND_MIXER_PCM] & 0xff;
705         right = (card->ac97.mixer_state[SOUND_MIXER_PCM] >> 8) & 0xff;
706
707         emu10k1_set_volume_gpr(card, 6, left, VOL_5BIT);
708         emu10k1_set_volume_gpr(card, 7, right, VOL_5BIT);
709
710         //CD-Digital Volume
711         mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][0] = 0xd;
712         mgr->ctrl_gpr[SOUND_MIXER_DIGITAL1][1] = 0xf;
713
714         left = right = 67;
715         card->ac97.mixer_state[SOUND_MIXER_DIGITAL1] = (right << 8) | left; 
716
717         card->ac97.supported_mixers |= SOUND_MASK_DIGITAL1;
718         card->ac97.stereo_mixers |= SOUND_MASK_DIGITAL1;
719
720         emu10k1_set_volume_gpr(card, 0xd, left, VOL_5BIT);
721         emu10k1_set_volume_gpr(card, 0xf, right, VOL_5BIT);
722
723         //hard wire the ac97's pcm, we'll do that in dsp code instead.
724         emu10k1_ac97_write(&card->ac97, 0x18, 0x0);
725         card->ac97_supported_mixers &= ~SOUND_MASK_PCM;
726         card->ac97_stereo_mixers &= ~SOUND_MASK_PCM;
727
728         //set Igain to 0dB by default, maybe consider hardwiring it here.
729         emu10k1_ac97_write(&card->ac97, AC97_RECORD_GAIN, 0x0000);
730         card->ac97.mixer_state[SOUND_MIXER_IGAIN] = 0x101; 
731
732         return 0;
733 }
734
735 static int __devinit hw_init(struct emu10k1_card *card)
736 {
737         int nCh;
738         u32 pagecount; /* tmp */
739         int ret;
740
741         /* Disable audio and lock cache */
742         emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
743
744         /* Reset recording buffers */
745         sblive_writeptr_tag(card, 0,
746                             MICBS, ADCBS_BUFSIZE_NONE,
747                             MICBA, 0,
748                             FXBS, ADCBS_BUFSIZE_NONE,
749                             FXBA, 0,
750                             ADCBS, ADCBS_BUFSIZE_NONE,
751                             ADCBA, 0,
752                             TAGLIST_END);
753
754         /* Disable channel interrupt */
755         emu10k1_writefn0(card, INTE, 0);
756         sblive_writeptr_tag(card, 0,
757                             CLIEL, 0,
758                             CLIEH, 0,
759                             SOLEL, 0,
760                             SOLEH, 0,
761                             TAGLIST_END);
762
763         /* Init envelope engine */
764         for (nCh = 0; nCh < NUM_G; nCh++) {
765                 sblive_writeptr_tag(card, nCh,
766                                     DCYSUSV, 0,
767                                     IP, 0,
768                                     VTFT, 0xffff,
769                                     CVCF, 0xffff,
770                                     PTRX, 0,
771                                     CPF, 0,
772                                     CCR, 0,
773
774                                     PSST, 0,
775                                     DSL, 0x10,
776                                     CCCA, 0,
777                                     Z1, 0,
778                                     Z2, 0,
779                                     FXRT, 0xd01c0000,
780
781                                     ATKHLDM, 0,
782                                     DCYSUSM, 0,
783                                     IFATN, 0xffff,
784                                     PEFE, 0,
785                                     FMMOD, 0,
786                                     TREMFRQ, 24,        /* 1 Hz */
787                                     FM2FRQ2, 24,        /* 1 Hz */
788                                     TEMPENV, 0,
789
790                                     /*** These are last so OFF prevents writing ***/
791                                     LFOVAL2, 0,
792                                     LFOVAL1, 0,
793                                     ATKHLDV, 0,
794                                     ENVVOL, 0,
795                                     ENVVAL, 0,
796                                     TAGLIST_END);
797         }
798
799         /*
800          ** Init to 0x02109204 :
801          ** Clock accuracy    = 0     (1000ppm)
802          ** Sample Rate       = 2     (48kHz)
803          ** Audio Channel     = 1     (Left of 2)
804          ** Source Number     = 0     (Unspecified)
805          ** Generation Status = 1     (Original for Cat Code 12)
806          ** Cat Code          = 12    (Digital Signal Mixer)
807          ** Mode              = 0     (Mode 0)
808          ** Emphasis          = 0     (None)
809          ** CP                = 1     (Copyright unasserted)
810          ** AN                = 0     (Digital audio)
811          ** P                 = 0     (Consumer)
812          */
813
814         sblive_writeptr_tag(card, 0,
815
816                             /* SPDIF0 */
817                             SPCS0, (SPCS_CLKACCY_1000PPM | 0x002000000 |
818                                     SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
819
820                             /* SPDIF1 */
821                             SPCS1, (SPCS_CLKACCY_1000PPM | 0x002000000 |
822                                     SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
823
824                             /* SPDIF2 & SPDIF3 */
825                             SPCS2, (SPCS_CLKACCY_1000PPM | 0x002000000 |
826                                     SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS | 0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT),
827
828                             TAGLIST_END);
829
830         ret = fx_init(card);            /* initialize effects engine */
831         if (ret < 0)
832                 return ret;
833
834         card->tankmem.size = 0;
835
836         card->virtualpagetable.size = MAXPAGES * sizeof(u32);
837
838         card->virtualpagetable.addr = pci_alloc_consistent(card->pci_dev, card->virtualpagetable.size, &card->virtualpagetable.dma_handle);
839         if (card->virtualpagetable.addr == NULL) {
840                 ERROR();
841                 ret = -ENOMEM;
842                 goto err0;
843         }
844
845         card->silentpage.size = EMUPAGESIZE;
846
847         card->silentpage.addr = pci_alloc_consistent(card->pci_dev, card->silentpage.size, &card->silentpage.dma_handle);
848         if (card->silentpage.addr == NULL) {
849                 ERROR();
850                 ret = -ENOMEM;
851                 goto err1;
852         }
853
854         for (pagecount = 0; pagecount < MAXPAGES; pagecount++)
855                 ((u32 *) card->virtualpagetable.addr)[pagecount] = cpu_to_le32((card->silentpage.dma_handle * 2) | pagecount);
856
857         /* Init page table & tank memory base register */
858         sblive_writeptr_tag(card, 0,
859                             PTB, card->virtualpagetable.dma_handle,
860                             TCB, 0,
861                             TCBS, 0,
862                             TAGLIST_END);
863
864         for (nCh = 0; nCh < NUM_G; nCh++) {
865                 sblive_writeptr_tag(card, nCh,
866                                     MAPA, MAP_PTI_MASK | (card->silentpage.dma_handle * 2),
867                                     MAPB, MAP_PTI_MASK | (card->silentpage.dma_handle * 2),
868                                     TAGLIST_END);
869         }
870
871         /* Hokay, now enable the AUD bit */
872         /* Enable Audio = 1 */
873         /* Mute Disable Audio = 0 */
874         /* Lock Tank Memory = 1 */
875         /* Lock Sound Memory = 0 */
876         /* Auto Mute = 1 */
877
878         if (card->model == 0x20 || card->model == 0xc400 ||
879           (card->model == 0x21 && card->chiprev < 6))
880                 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE  | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE);
881         else
882                 emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE  | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE);
883
884         /* Enable Vol_Ctrl irqs */
885         emu10k1_irq_enable(card, INTE_VOLINCRENABLE | INTE_VOLDECRENABLE | INTE_MUTEENABLE | INTE_FXDSPENABLE);
886
887         /* FIXME: TOSLink detection */
888         card->has_toslink = 0;
889
890         /* Initialize digital passthrough variables */
891         card->pt.pos_gpr = card->pt.intr_gpr = card->pt.enable_gpr = -1;
892         card->pt.selected = 0;
893         card->pt.state = PT_STATE_INACTIVE;
894         card->pt.spcs_to_use = 0x01;
895         card->pt.patch_name = "AC3pass";
896         card->pt.intr_gpr_name = "count";
897         card->pt.enable_gpr_name = "enable";
898         card->pt.pos_gpr_name = "ptr";
899         spin_lock_init(&card->pt.lock);
900         init_waitqueue_head(&card->pt.wait);
901
902 /*      tmp = sblive_readfn0(card, HCFG);
903         if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
904                 sblive_writefn0(card, HCFG, tmp | 0x800);
905
906                 udelay(512);
907
908                 if (tmp != (sblive_readfn0(card, HCFG) & ~0x800)) {
909                         card->has_toslink = 1;
910                         sblive_writefn0(card, HCFG, tmp);
911                 }
912         }
913 */
914         return 0;
915
916   err1:
917         pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle);
918   err0:
919         fx_cleanup(&card->mgr);
920
921         return ret;
922 }
923
924 static int __devinit emu10k1_init(struct emu10k1_card *card)
925 {
926         /* Init Card */
927         if (hw_init(card) < 0)
928                 return -1;
929
930         voice_init(card);
931         timer_init(card);
932         addxmgr_init(card);
933
934         DPD(2, "  hw control register -> %#x\n", emu10k1_readfn0(card, HCFG));
935
936         return 0;
937 }
938
939 static void __devinit emu10k1_cleanup(struct emu10k1_card *card)
940 {
941         int ch;
942
943         emu10k1_writefn0(card, INTE, 0);
944
945         /** Shutdown the chip **/
946         for (ch = 0; ch < NUM_G; ch++)
947                 sblive_writeptr(card, DCYSUSV, ch, 0);
948
949         for (ch = 0; ch < NUM_G; ch++) {
950                 sblive_writeptr_tag(card, ch,
951                                     VTFT, 0,
952                                     CVCF, 0,
953                                     PTRX, 0,
954                                     CPF, 0,
955                                     TAGLIST_END);
956         }
957
958         /* Disable audio and lock cache */
959         emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
960
961         sblive_writeptr_tag(card, 0,
962                             PTB, 0,
963
964                             /* Reset recording buffers */
965                             MICBS, ADCBS_BUFSIZE_NONE,
966                             MICBA, 0,
967                             FXBS, ADCBS_BUFSIZE_NONE,
968                             FXBA, 0,
969                             FXWC, 0,
970                             ADCBS, ADCBS_BUFSIZE_NONE,
971                             ADCBA, 0,
972                             TCBS, 0,
973                             TCB, 0,
974                             DBG, 0x8000,
975
976                             /* Disable channel interrupt */
977                             CLIEL, 0,
978                             CLIEH, 0,
979                             SOLEL, 0,
980                             SOLEH, 0,
981                             TAGLIST_END);
982
983
984         pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle);
985         pci_free_consistent(card->pci_dev, card->silentpage.size, card->silentpage.addr, card->silentpage.dma_handle);
986         
987         if(card->tankmem.size != 0)
988                 pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
989
990         /* release patch storage memory */
991         fx_cleanup(&card->mgr);
992 }
993
994 /* Driver initialization routine */
995 static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
996 {
997         struct emu10k1_card *card;
998         u32 subsysvid;
999         int ret;
1000
1001         if (pci_set_dma_mask(pci_dev, EMU10K1_DMA_MASK)) {
1002                 printk(KERN_ERR "emu10k1: architecture does not support 32bit PCI busmaster DMA\n");
1003                 return -ENODEV;
1004         }
1005
1006         if (pci_enable_device(pci_dev))
1007                 return -EIO;
1008
1009         pci_set_master(pci_dev);
1010
1011         if ((card = kmalloc(sizeof(struct emu10k1_card), GFP_KERNEL)) == NULL) {
1012                 printk(KERN_ERR "emu10k1: out of memory\n");
1013                 return -ENOMEM;
1014         }
1015         memset(card, 0, sizeof(struct emu10k1_card));
1016
1017         card->iobase = pci_resource_start(pci_dev, 0);
1018         card->length = pci_resource_len(pci_dev, 0); 
1019
1020         if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
1021                 printk(KERN_ERR "emu10k1: IO space in use\n");
1022                 ret = -EBUSY;
1023                 goto err_region;
1024         }
1025
1026         pci_set_drvdata(pci_dev, card);
1027
1028         card->irq = pci_dev->irq;
1029         card->pci_dev = pci_dev;
1030
1031         /* Reserve IRQ Line */
1032         if (request_irq(card->irq, emu10k1_interrupt, SA_SHIRQ, card_names[pci_id->driver_data], card)) {
1033                 printk(KERN_ERR "emu10k1: IRQ in use\n");
1034                 ret = -EBUSY;
1035                 goto err_irq;
1036         }
1037
1038         pci_read_config_byte(pci_dev, PCI_REVISION_ID, &card->chiprev);
1039         pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &card->model);
1040
1041         printk(KERN_INFO "emu10k1: %s rev %d model 0x%x found, IO at 0x%04lx-0x%04lx, IRQ %d\n",
1042                 card_names[pci_id->driver_data], card->chiprev, card->model, card->iobase,
1043                 card->iobase + card->length - 1, card->irq);
1044
1045         pci_read_config_dword(pci_dev, PCI_SUBSYSTEM_VENDOR_ID, &subsysvid);
1046         card->isaps = (subsysvid == EMU_APS_SUBID);
1047
1048         spin_lock_init(&card->lock);
1049         init_MUTEX(&card->open_sem);
1050         card->open_mode = 0;
1051         init_waitqueue_head(&card->open_wait);
1052
1053         ret = emu10k1_audio_init(card);
1054         if(ret < 0) {
1055                 printk(KERN_ERR "emu10k1: cannot initialize audio devices\n");
1056                 goto err_audio;
1057         }
1058
1059         ret = emu10k1_mixer_init(card);
1060         if(ret < 0) {
1061                 printk(KERN_ERR "emu10k1: cannot initialize AC97 codec\n");
1062                 goto err_mixer;
1063         }
1064
1065         ret = emu10k1_midi_init(card);
1066         if (ret < 0) {
1067                 printk(KERN_ERR "emu10k1: cannot register midi device\n");
1068                 goto err_midi;
1069         }
1070
1071         ret = emu10k1_init(card);
1072         if (ret < 0) {
1073                 printk(KERN_ERR "emu10k1: cannot initialize device\n");
1074                 goto err_emu10k1_init;
1075         }
1076
1077         if (card->isaps)
1078                 emu10k1_ecard_init(card);
1079
1080         list_add(&card->list, &emu10k1_devs);
1081
1082         return 0;
1083
1084 err_emu10k1_init:
1085         emu10k1_midi_cleanup(card);
1086
1087 err_midi:
1088         emu10k1_mixer_cleanup(card);
1089
1090 err_mixer:
1091         emu10k1_audio_cleanup(card);
1092
1093 err_audio:
1094         free_irq(card->irq, card);
1095
1096 err_irq:
1097         release_region(card->iobase, card->length);
1098         pci_set_drvdata(pci_dev, NULL);
1099
1100 err_region:
1101         kfree(card);
1102
1103         return ret;
1104 }
1105
1106 static void __devexit emu10k1_remove(struct pci_dev *pci_dev)
1107 {
1108         struct emu10k1_card *card = pci_get_drvdata(pci_dev);
1109
1110         list_del(&card->list);
1111
1112         emu10k1_cleanup(card);
1113         emu10k1_midi_cleanup(card);
1114         emu10k1_mixer_cleanup(card);
1115         emu10k1_audio_cleanup(card);    
1116         free_irq(card->irq, card);
1117         release_region(card->iobase, card->length);
1118         kfree(card);
1119         pci_set_drvdata(pci_dev, NULL);
1120 }
1121
1122 MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@opensource.creative.com)");
1123 MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION "\nCopyright (C) 1999 Creative Technology Ltd.");
1124 MODULE_LICENSE("GPL");
1125
1126 static struct pci_driver emu10k1_pci_driver = {
1127         name:           "emu10k1",
1128         id_table:       emu10k1_pci_tbl,
1129         probe:          emu10k1_probe,
1130         remove:         __devexit_p(emu10k1_remove),
1131 };
1132
1133 static int __init emu10k1_init_module(void)
1134 {
1135         printk(KERN_INFO "Creative EMU10K1 PCI Audio Driver, version " DRIVER_VERSION ", " __TIME__ " " __DATE__ "\n");
1136
1137         return pci_module_init(&emu10k1_pci_driver);
1138 }
1139
1140 static void __exit emu10k1_cleanup_module(void)
1141 {
1142         pci_unregister_driver(&emu10k1_pci_driver);
1143
1144         return;
1145 }
1146
1147 module_init(emu10k1_init_module);
1148 module_exit(emu10k1_cleanup_module);
1149
1150 #ifdef EMU10K1_SEQUENCER
1151
1152 /* in midi.c */
1153 extern int emu10k1_seq_midi_open(int dev, int mode, 
1154                                 void (*input)(int dev, unsigned char midi_byte),
1155                                 void (*output)(int dev));
1156 extern void emu10k1_seq_midi_close(int dev);
1157 extern int emu10k1_seq_midi_out(int dev, unsigned char midi_byte);
1158 extern int emu10k1_seq_midi_start_read(int dev);
1159 extern int emu10k1_seq_midi_end_read(int dev);
1160 extern void emu10k1_seq_midi_kick(int dev);
1161 extern int emu10k1_seq_midi_buffer_status(int dev);
1162
1163 static struct midi_operations emu10k1_midi_operations =
1164 {
1165         THIS_MODULE,
1166         {"EMU10K1 MIDI", 0, 0, SNDCARD_EMU10K1},
1167         &std_midi_synth,
1168         {0},
1169         emu10k1_seq_midi_open,
1170         emu10k1_seq_midi_close,
1171         NULL,
1172         emu10k1_seq_midi_out,
1173         emu10k1_seq_midi_start_read,
1174         emu10k1_seq_midi_end_read,
1175         emu10k1_seq_midi_kick,
1176         NULL,
1177         emu10k1_seq_midi_buffer_status,
1178         NULL
1179 };
1180
1181 #endif