ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pci / cs46xx / cs46xx.c
1 /*
2  *  The driver for the Cirrus Logic's Sound Fusion CS46XX 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 /*
23   NOTES:
24   - sometimes the sound is metallic and sibilant, unloading and 
25     reloading the module may solve this.
26 */
27
28 #include <sound/driver.h>
29 #include <linux/pci.h>
30 #include <linux/time.h>
31 #include <linux/init.h>
32 #include <sound/core.h>
33 #include <sound/cs46xx.h>
34 #define SNDRV_GET_ID
35 #include <sound/initval.h>
36
37 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
38 MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
39 MODULE_LICENSE("GPL");
40 MODULE_CLASSES("{sound}");
41 MODULE_DEVICES("{{Cirrus Logic,Sound Fusion (CS4280)},"
42                 "{Cirrus Logic,Sound Fusion (CS4610)},"
43                 "{Cirrus Logic,Sound Fusion (CS4612)},"
44                 "{Cirrus Logic,Sound Fusion (CS4615)},"
45                 "{Cirrus Logic,Sound Fusion (CS4622)},"
46                 "{Cirrus Logic,Sound Fusion (CS4624)},"
47                 "{Cirrus Logic,Sound Fusion (CS4630)}}");
48
49 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
50 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
51 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
52 static int external_amp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
53 static int thinkpad[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
54 static int mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
55
56 MODULE_PARM(index, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
57 MODULE_PARM_DESC(index, "Index value for the CS46xx 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 the CS46xx 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 CS46xx soundcard.");
64 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
65 MODULE_PARM(external_amp, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
66 MODULE_PARM_DESC(external_amp, "Force to enable external amplifer.");
67 MODULE_PARM_SYNTAX(external_amp, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
68 MODULE_PARM(thinkpad, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
69 MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
70 MODULE_PARM_SYNTAX(thinkpad, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
71 MODULE_PARM(mmap_valid, "1-" __MODULE_STRING(SNDRV_CARDS) "i");
72 MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
73 MODULE_PARM_SYNTAX(mmap_valid, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC);
74
75 static struct pci_device_id snd_cs46xx_ids[] = {
76         { 0x1013, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4280 */
77         { 0x1013, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4612 */
78         { 0x1013, 0x6004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4615 */
79         { 0, }
80 };
81
82 MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
83
84 static int __devinit snd_card_cs46xx_probe(struct pci_dev *pci,
85                                            const struct pci_device_id *pci_id)
86 {
87         static int dev;
88         snd_card_t *card;
89         cs46xx_t *chip;
90         int err;
91
92         if (dev >= SNDRV_CARDS)
93                 return -ENODEV;
94         if (!enable[dev]) {
95                 dev++;
96                 return -ENOENT;
97         }
98
99         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
100         if (card == NULL)
101                 return -ENOMEM;
102         if ((err = snd_cs46xx_create(card, pci,
103                                      external_amp[dev], thinkpad[dev],
104                                      &chip)) < 0) {
105                 snd_card_free(card);
106                 return err;
107         }
108         chip->accept_valid = mmap_valid[dev];
109         if ((err = snd_cs46xx_pcm(chip, 0, NULL)) < 0) {
110                 snd_card_free(card);
111                 return err;
112         }
113 #ifdef CONFIG_SND_CS46XX_NEW_DSP
114         if ((err = snd_cs46xx_pcm_rear(chip,1, NULL)) < 0) {
115                 snd_card_free(card);
116                 return err;
117         }
118         if ((err = snd_cs46xx_pcm_iec958(chip,2,NULL)) < 0) {
119                 snd_card_free(card);
120                 return err;
121         }
122 #endif
123         if ((err = snd_cs46xx_mixer(chip)) < 0) {
124                 snd_card_free(card);
125                 return err;
126         }
127 #ifdef CONFIG_SND_CS46XX_NEW_DSP
128         if (chip->nr_ac97_codecs ==2) {
129                 if ((err = snd_cs46xx_pcm_center_lfe(chip,3,NULL)) < 0) {
130                         snd_card_free(card);
131                         return err;
132                 }
133         }
134 #endif
135         if ((err = snd_cs46xx_midi(chip, 0, NULL)) < 0) {
136                 snd_card_free(card);
137                 return err;
138         }
139         if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
140                 snd_card_free(card);
141                 return err;
142         }
143
144
145         snd_cs46xx_gameport(chip);
146
147         strcpy(card->driver, "CS46xx");
148         strcpy(card->shortname, "Sound Fusion CS46xx");
149         sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
150                 card->shortname,
151                 chip->ba0_addr,
152                 chip->ba1_addr,
153                 chip->irq);
154
155         if ((err = snd_card_register(card)) < 0) {
156                 snd_card_free(card);
157                 return err;
158         }
159
160         pci_set_drvdata(pci, chip);
161         dev++;
162         return 0;
163 }
164
165 #ifdef CONFIG_PM
166 static int snd_card_cs46xx_suspend(struct pci_dev *pci, u32 state)
167 {
168         cs46xx_t *chip = snd_magic_cast(cs46xx_t, pci_get_drvdata(pci), return -ENXIO);
169         snd_cs46xx_suspend(chip);
170         return 0;
171 }
172 static int snd_card_cs46xx_resume(struct pci_dev *pci)
173 {
174         cs46xx_t *chip = snd_magic_cast(cs46xx_t, pci_get_drvdata(pci), return -ENXIO);
175         snd_cs46xx_resume(chip);
176         return 0;
177 }
178 #endif
179
180 static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci)
181 {
182         cs46xx_t *chip = snd_magic_cast(cs46xx_t, pci_get_drvdata(pci), return);
183         if (chip)
184                 snd_card_free(chip->card);
185         pci_set_drvdata(pci, NULL);
186 }
187
188 static struct pci_driver driver = {
189         .name = "Sound Fusion CS46xx",
190         .id_table = snd_cs46xx_ids,
191         .probe = snd_card_cs46xx_probe,
192         .remove = __devexit_p(snd_card_cs46xx_remove),
193 #ifdef CONFIG_PM
194         .suspend = snd_card_cs46xx_suspend,
195         .resume = snd_card_cs46xx_resume,
196 #endif
197 };
198
199 static int __init alsa_card_cs46xx_init(void)
200 {
201         int err;
202
203         if ((err = pci_module_init(&driver)) < 0) {
204 #ifdef MODULE
205                 printk(KERN_ERR "Sound Fusion CS46xx soundcard not found or device busy\n");
206 #endif
207                 return err;
208         }
209         return 0;
210 }
211
212 static void __exit alsa_card_cs46xx_exit(void)
213 {
214         pci_unregister_driver(&driver);
215 }
216
217 module_init(alsa_card_cs46xx_init)
218 module_exit(alsa_card_cs46xx_exit)
219
220 #ifndef MODULE
221
222 /* format is: snd-cs46xx=enable,index,id,mmap_valid,external_amp,thinkpad */
223
224 static int __init alsa_card_cs46xx_setup(char *str)
225 {
226         static unsigned __initdata nr_dev = 0;
227
228         if (nr_dev >= SNDRV_CARDS)
229                 return 0;
230         (void)(get_option(&str,&enable[nr_dev]) == 2 &&
231                get_option(&str,&index[nr_dev]) == 2 &&
232                get_id(&str,&id[nr_dev]) == 2 &&
233                get_option(&str,&mmap_valid[nr_dev]) == 2 &&
234                get_option(&str,&external_amp[nr_dev]) == 2 &&
235                get_option(&str,&thinkpad[nr_dev]) == 2);
236         nr_dev++;
237         return 1;
238 }
239
240 __setup("snd-cs46xx=", alsa_card_cs46xx_setup);
241
242 #endif /* ifndef MODULE */