ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pci / trident / trident.c
1 /*
2  *  Driver for Trident 4DWave DX/NX & SiS SI7018 Audio PCI soundcard
3  *
4  *  Driver was originated by Trident <audio@tridentmicro.com>
5  *                           Fri Feb 19 15:55:28 MST 1999
6  *
7  *
8  *   This program is free software; you can redistribute it and/or modify
9  *   it under the terms of the GNU General Public License as published by
10  *   the Free Software Foundation; either version 2 of the License, or
11  *   (at your option) any later version.
12  *
13  *   This program is distributed in the hope that it will be useful,
14  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *   GNU General Public License for more details.
17  *
18  *   You should have received a copy of the GNU General Public License
19  *   along with this program; if not, write to the Free Software
20  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
21  *
22  */
23
24 #include <sound/driver.h>
25 #include <linux/init.h>
26 #include <linux/pci.h>
27 #include <linux/time.h>
28 #include <sound/core.h>
29 #include <sound/trident.h>
30 #define SNDRV_GET_ID
31 #include <sound/initval.h>
32
33 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>, <audio@tridentmicro.com>");
34 MODULE_DESCRIPTION("Trident 4D-WaveDX/NX & SiS SI7018");
35 MODULE_LICENSE("GPL");
36 MODULE_CLASSES("{sound}");
37 MODULE_DEVICES("{{Trident,4DWave DX},"
38                 "{Trident,4DWave NX},"
39                 "{SiS,SI7018 PCI Audio},"
40                 "{Best Union,Miss Melody 4DWave PCI},"
41                 "{HIS,4DWave PCI},"
42                 "{Warpspeed,ONSpeed 4DWave PCI},"
43                 "{Aztech Systems,PCI 64-Q3D},"
44                 "{Addonics,SV 750},"
45                 "{CHIC,True Sound 4Dwave},"
46                 "{Shark,Predator4D-PCI},"
47                 "{Jaton,SonicWave 4D},"
48                 "{Hoontech,SoundTrack Digital 4DWave NX}}");
49
50 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
51 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
52 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
53 static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32};
54 static int wavetable_size[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 8192};
55
56 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
57 MODULE_PARM_DESC(index, "Index value for Trident 4DWave PCI soundcard.");
58 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
59 MODULE_PARM(id, "1-" __MODULE_STRING(SNDRV_CARDS) "s");
60 MODULE_PARM_DESC(id, "ID string for Trident 4DWave PCI soundcard.");
61 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
62 MODULE_PARM(enable, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
63 MODULE_PARM_DESC(enable, "Enable Trident 4DWave PCI soundcard.");
64 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
65 MODULE_PARM(pcm_channels, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
66 MODULE_PARM_DESC(pcm_channels, "Number of hardware channels assigned for PCM.");
67 MODULE_PARM_SYNTAX(pcm_channels, SNDRV_ENABLED ",default:32,allows:{{1,32}}");
68 MODULE_PARM(wavetable_size, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
69 MODULE_PARM_DESC(wavetable_size, "Maximum memory size in kB for wavetable synth.");
70 MODULE_PARM_SYNTAX(wavetable_size, SNDRV_ENABLED ",default:8192,skill:advanced");
71
72 static struct pci_device_id snd_trident_ids[] = {
73         { 0x1023, 0x2000, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* Trident 4DWave DX PCI Audio */
74         { 0x1023, 0x2001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* Trident 4DWave NX PCI Audio */
75         { 0x1039, 0x7018, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* SiS SI7018 PCI Audio */
76         { 0, }
77 };
78
79 MODULE_DEVICE_TABLE(pci, snd_trident_ids);
80
81 static int __devinit snd_trident_probe(struct pci_dev *pci,
82                                        const struct pci_device_id *pci_id)
83 {
84         static int dev;
85         snd_card_t *card;
86         trident_t *trident;
87         const char *str;
88         int err, pcm_dev = 0;
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
101         if ((err = snd_trident_create(card, pci,
102                                       pcm_channels[dev],
103                                       ((pci->vendor << 16) | pci->device) == TRIDENT_DEVICE_ID_SI7018 ? 1 : 2,
104                                       wavetable_size[dev],
105                                       &trident)) < 0) {
106                 snd_card_free(card);
107                 return err;
108         }
109
110         switch (trident->device) {
111         case TRIDENT_DEVICE_ID_DX:
112                 str = "TRID4DWAVEDX";
113                 break;
114         case TRIDENT_DEVICE_ID_NX:
115                 str = "TRID4DWAVENX";
116                 break;
117         case TRIDENT_DEVICE_ID_SI7018:
118                 str = "SI7018";
119                 break;
120         default:
121                 str = "Unknown";
122         }
123         strcpy(card->driver, str);
124         if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
125                 strcpy(card->shortname, "SiS ");
126         } else {
127                 strcpy(card->shortname, "Trident ");
128         }
129         strcat(card->shortname, card->driver);
130         sprintf(card->longname, "%s PCI Audio at 0x%lx, irq %d",
131                 card->shortname, trident->port, trident->irq);
132
133         if ((err = snd_trident_pcm(trident, pcm_dev++, NULL)) < 0) {
134                 snd_card_free(card);
135                 return err;
136         }
137         switch (trident->device) {
138         case TRIDENT_DEVICE_ID_DX:
139         case TRIDENT_DEVICE_ID_NX:
140                 if ((err = snd_trident_foldback_pcm(trident, pcm_dev++, NULL)) < 0) {
141                         snd_card_free(card);
142                         return err;
143                 }
144                 break;
145         }
146         if (trident->device == TRIDENT_DEVICE_ID_NX || trident->device == TRIDENT_DEVICE_ID_SI7018) {
147                 if ((err = snd_trident_spdif_pcm(trident, pcm_dev++, NULL)) < 0) {
148                         snd_card_free(card);
149                         return err;
150                 }
151         }
152         if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE,
153                                        trident->midi_port, 1,
154                                        trident->irq, 0, &trident->rmidi)) < 0) {
155                 snd_card_free(card);
156                 return err;
157         }
158
159 #if defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE))
160         if ((err = snd_trident_attach_synthesizer(trident)) < 0) {
161                 snd_card_free(card);
162                 return err;
163         }
164 #endif
165
166         snd_trident_gameport(trident);
167
168         if ((err = snd_card_register(card)) < 0) {
169                 snd_card_free(card);
170                 return err;
171         }
172         pci_set_drvdata(pci, trident);
173         dev++;
174         return 0;
175 }
176
177 static void __devexit snd_trident_remove(struct pci_dev *pci)
178 {
179         trident_t *trident = snd_magic_cast(trident_t, pci_get_drvdata(pci), return);
180         if (trident)
181                 snd_card_free(trident->card);
182         pci_set_drvdata(pci, NULL);
183 }
184
185 #ifdef CONFIG_PM
186 static int snd_card_trident_suspend(struct pci_dev *pci, u32 state)
187 {
188         trident_t *chip = snd_magic_cast(trident_t, pci_get_drvdata(pci), return -ENXIO);
189         snd_trident_suspend(chip);
190         return 0;
191 }
192 static int snd_card_trident_resume(struct pci_dev *pci)
193 {
194         trident_t *chip = snd_magic_cast(trident_t, pci_get_drvdata(pci), return -ENXIO);
195         snd_trident_resume(chip);
196         return 0;
197 }
198 #endif
199
200 static struct pci_driver driver = {
201         .name = "Trident4DWaveAudio",
202         .id_table = snd_trident_ids,
203         .probe = snd_trident_probe,
204         .remove = __devexit_p(snd_trident_remove),
205 #ifdef CONFIG_PM
206         .suspend = snd_card_trident_suspend,
207         .resume = snd_card_trident_resume,
208 #endif
209 };
210
211 static int __init alsa_card_trident_init(void)
212 {
213         int err;
214
215         if ((err = pci_module_init(&driver)) < 0) {
216 #ifdef MODULE
217                 printk(KERN_ERR "Trident 4DWave PCI soundcard not found or device busy\n");
218 #endif
219                 return err;
220         }
221         return 0;
222 }
223
224 static void __exit alsa_card_trident_exit(void)
225 {
226         pci_unregister_driver(&driver);
227 }
228
229 module_init(alsa_card_trident_init)
230 module_exit(alsa_card_trident_exit)
231
232 #ifndef MODULE
233
234 /* format is: snd-trident=enable,index,id,
235                           pcm_channels,wavetable_size */
236
237 static int __init alsa_card_trident_setup(char *str)
238 {
239         static unsigned __initdata nr_dev = 0;
240
241         if (nr_dev >= SNDRV_CARDS)
242                 return 0;
243         (void)(get_option(&str,&enable[nr_dev]) == 2 &&
244                get_option(&str,&index[nr_dev]) == 2 &&
245                get_id(&str,&id[nr_dev]) == 2 &&
246                get_option(&str,&pcm_channels[nr_dev]) == 2 &&
247                get_option(&str,&wavetable_size[nr_dev]) == 2);
248         nr_dev++;
249         return 1;
250 }
251
252 __setup("snd-trident=", alsa_card_trident_setup);
253
254 #endif /* ifndef MODULE */