upgrade to linux 2.6.10-1.12_FC2
[linux-2.6.git] / sound / pci / emu10k1 / emu10k1.c
1 /*
2  *  The driver for the EMU10K1 (SB Live!) based soundcards
3  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19  *
20  */
21
22 #include <sound/driver.h>
23 #include <linux/init.h>
24 #include <linux/pci.h>
25 #include <linux/time.h>
26 #include <linux/moduleparam.h>
27 #include <sound/core.h>
28 #include <sound/emu10k1.h>
29 #include <sound/initval.h>
30
31 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
32 MODULE_DESCRIPTION("EMU10K1");
33 MODULE_LICENSE("GPL");
34 MODULE_SUPPORTED_DEVICE("{{Creative Labs,SB Live!/PCI512/E-mu APS},"
35                "{Creative Labs,SB Audigy}}");
36
37 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
38 #define ENABLE_SYNTH
39 #include <sound/emu10k1_synth.h>
40 #endif
41
42 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
43 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
44 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
45 static int extin[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
46 static int extout[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
47 static int seq_ports[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
48 static int max_synth_voices[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 64};
49 static int max_buffer_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 128};
50 static int enable_ir[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
51
52 module_param_array(index, int, NULL, 0444);
53 MODULE_PARM_DESC(index, "Index value for the EMU10K1 soundcard.");
54 module_param_array(id, charp, NULL, 0444);
55 MODULE_PARM_DESC(id, "ID string for the EMU10K1 soundcard.");
56 module_param_array(enable, bool, NULL, 0444);
57 MODULE_PARM_DESC(enable, "Enable the EMU10K1 soundcard.");
58 module_param_array(extin, int, NULL, 0444);
59 MODULE_PARM_DESC(extin, "Available external inputs for FX8010. Zero=default.");
60 module_param_array(extout, int, NULL, 0444);
61 MODULE_PARM_DESC(extout, "Available external outputs for FX8010. Zero=default.");
62 module_param_array(seq_ports, int, NULL, 0444);
63 MODULE_PARM_DESC(seq_ports, "Allocated sequencer ports for internal synthesizer.");
64 module_param_array(max_synth_voices, int, NULL, 0444);
65 MODULE_PARM_DESC(max_synth_voices, "Maximum number of voices for WaveTable.");
66 module_param_array(max_buffer_size, int, NULL, 0444);
67 MODULE_PARM_DESC(max_buffer_size, "Maximum sample buffer size in MB.");
68 module_param_array(enable_ir, bool, NULL, 0444);
69 MODULE_PARM_DESC(enable_ir, "Enable IR.");
70
71 static struct pci_device_id snd_emu10k1_ids[] = {
72         { 0x1102, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },    /* EMU10K1 */
73         { 0x1102, 0x0004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 1 },    /* Audigy */
74         { 0, }
75 };
76
77 MODULE_DEVICE_TABLE(pci, snd_emu10k1_ids);
78
79 static int __devinit snd_card_emu10k1_probe(struct pci_dev *pci,
80                                             const struct pci_device_id *pci_id)
81 {
82         static int dev;
83         snd_card_t *card;
84         emu10k1_t *emu;
85 #ifdef ENABLE_SYNTH
86         snd_seq_device_t *wave = NULL;
87 #endif
88         int err;
89
90         if (dev >= SNDRV_CARDS)
91                 return -ENODEV;
92         if (!enable[dev]) {
93                 dev++;
94                 return -ENOENT;
95         }
96
97         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
98         if (card == NULL)
99                 return -ENOMEM;
100         if (max_buffer_size[dev] < 32)
101                 max_buffer_size[dev] = 32;
102         else if (max_buffer_size[dev] > 1024)
103                 max_buffer_size[dev] = 1024;
104         if ((err = snd_emu10k1_create(card, pci, extin[dev], extout[dev],
105                                       (long)max_buffer_size[dev] * 1024 * 1024,
106                                       enable_ir[dev],
107                                       &emu)) < 0) {
108                 snd_card_free(card);
109                 return err;
110         }               
111         if ((err = snd_emu10k1_pcm(emu, 0, NULL)) < 0) {
112                 snd_card_free(card);
113                 return err;
114         }               
115         if ((err = snd_emu10k1_pcm_mic(emu, 1, NULL)) < 0) {
116                 snd_card_free(card);
117                 return err;
118         }               
119         if ((err = snd_emu10k1_pcm_efx(emu, 2, NULL)) < 0) {
120                 snd_card_free(card);
121                 return err;
122         }               
123         if ((err = snd_emu10k1_mixer(emu)) < 0) {
124                 snd_card_free(card);
125                 return err;
126         }
127         if (emu->audigy) {
128                 if ((err = snd_emu10k1_audigy_midi(emu)) < 0) {
129                         snd_card_free(card);
130                         return err;
131                 }
132         } else {
133                 if ((err = snd_emu10k1_midi(emu)) < 0) {
134                         snd_card_free(card);
135                         return err;
136                 }
137         }
138         if ((err = snd_emu10k1_fx8010_new(emu, 0, NULL)) < 0) {
139                 snd_card_free(card);
140                 return err;
141         }
142 #ifdef ENABLE_SYNTH
143         if (snd_seq_device_new(card, 1, SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH,
144                                sizeof(snd_emu10k1_synth_arg_t), &wave) < 0 ||
145             wave == NULL) {
146                 snd_printk("can't initialize Emu10k1 wavetable synth\n");
147         } else {
148                 snd_emu10k1_synth_arg_t *arg;
149                 arg = SNDRV_SEQ_DEVICE_ARGPTR(wave);
150                 strcpy(wave->name, "Emu-10k1 Synth");
151                 arg->hwptr = emu;
152                 arg->index = 1;
153                 arg->seq_ports = seq_ports[dev];
154                 arg->max_voices = max_synth_voices[dev];
155         }
156 #endif
157  
158         if (emu->audigy && (emu->revision == 4) ) {
159                 strcpy(card->driver, "Audigy2");
160                 strcpy(card->shortname, "Sound Blaster Audigy2");
161         } else if (emu->audigy) {
162                 strcpy(card->driver, "Audigy");
163                 strcpy(card->shortname, "Sound Blaster Audigy");
164         } else if (emu->APS) {
165                 strcpy(card->driver, "E-mu APS");
166                 strcpy(card->shortname, "E-mu APS");
167         } else {
168                 strcpy(card->driver, "EMU10K1");
169                 strcpy(card->shortname, "Sound Blaster Live!");
170         }
171         sprintf(card->longname, "%s (rev.%d) at 0x%lx, irq %i", card->shortname, emu->revision, emu->port, emu->irq);
172
173         if ((err = snd_card_register(card)) < 0) {
174                 snd_card_free(card);
175                 return err;
176         }
177         pci_set_drvdata(pci, card);
178         dev++;
179         return 0;
180 }
181
182 static void __devexit snd_card_emu10k1_remove(struct pci_dev *pci)
183 {
184         snd_card_free(pci_get_drvdata(pci));
185         pci_set_drvdata(pci, NULL);
186 }
187
188 static struct pci_driver driver = {
189         .name = "EMU10K1_Audigy",
190         .id_table = snd_emu10k1_ids,
191         .probe = snd_card_emu10k1_probe,
192         .remove = __devexit_p(snd_card_emu10k1_remove),
193 };
194
195 static int __init alsa_card_emu10k1_init(void)
196 {
197         return pci_module_init(&driver);
198 }
199
200 static void __exit alsa_card_emu10k1_exit(void)
201 {
202         pci_unregister_driver(&driver);
203 }
204
205 module_init(alsa_card_emu10k1_init)
206 module_exit(alsa_card_emu10k1_exit)