patch-2_6_7-vs1_9_1_12
[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 <linux/moduleparam.h>
33 #include <sound/core.h>
34 #include <sound/cs46xx.h>
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 static int boot_devs;
56
57 module_param_array(index, int, boot_devs, 0444);
58 MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
59 MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
60 module_param_array(id, charp, boot_devs, 0444);
61 MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
62 MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
63 module_param_array(enable, bool, boot_devs, 0444);
64 MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
65 MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
66 module_param_array(external_amp, bool, boot_devs, 0444);
67 MODULE_PARM_DESC(external_amp, "Force to enable external amplifer.");
68 MODULE_PARM_SYNTAX(external_amp, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
69 module_param_array(thinkpad, bool, boot_devs, 0444);
70 MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
71 MODULE_PARM_SYNTAX(thinkpad, SNDRV_ENABLED "," SNDRV_BOOLEAN_FALSE_DESC);
72 module_param_array(mmap_valid, bool, boot_devs, 0444);
73 MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
74 MODULE_PARM_SYNTAX(mmap_valid, SNDRV_ENABLED "," SNDRV_BOOLEAN_TRUE_DESC);
75
76 static struct pci_device_id snd_cs46xx_ids[] = {
77         { 0x1013, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4280 */
78         { 0x1013, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4612 */
79         { 0x1013, 0x6004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4615 */
80         { 0, }
81 };
82
83 MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
84
85 static int __devinit snd_card_cs46xx_probe(struct pci_dev *pci,
86                                            const struct pci_device_id *pci_id)
87 {
88         static int dev;
89         snd_card_t *card;
90         cs46xx_t *chip;
91         int err;
92
93         if (dev >= SNDRV_CARDS)
94                 return -ENODEV;
95         if (!enable[dev]) {
96                 dev++;
97                 return -ENOENT;
98         }
99
100         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
101         if (card == NULL)
102                 return -ENOMEM;
103         if ((err = snd_cs46xx_create(card, pci,
104                                      external_amp[dev], thinkpad[dev],
105                                      &chip)) < 0) {
106                 snd_card_free(card);
107                 return err;
108         }
109         chip->accept_valid = mmap_valid[dev];
110         if ((err = snd_cs46xx_pcm(chip, 0, NULL)) < 0) {
111                 snd_card_free(card);
112                 return err;
113         }
114 #ifdef CONFIG_SND_CS46XX_NEW_DSP
115         if ((err = snd_cs46xx_pcm_rear(chip,1, NULL)) < 0) {
116                 snd_card_free(card);
117                 return err;
118         }
119         if ((err = snd_cs46xx_pcm_iec958(chip,2,NULL)) < 0) {
120                 snd_card_free(card);
121                 return err;
122         }
123 #endif
124         if ((err = snd_cs46xx_mixer(chip)) < 0) {
125                 snd_card_free(card);
126                 return err;
127         }
128 #ifdef CONFIG_SND_CS46XX_NEW_DSP
129         if (chip->nr_ac97_codecs ==2) {
130                 if ((err = snd_cs46xx_pcm_center_lfe(chip,3,NULL)) < 0) {
131                         snd_card_free(card);
132                         return err;
133                 }
134         }
135 #endif
136         if ((err = snd_cs46xx_midi(chip, 0, NULL)) < 0) {
137                 snd_card_free(card);
138                 return err;
139         }
140         if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
141                 snd_card_free(card);
142                 return err;
143         }
144
145
146         snd_cs46xx_gameport(chip);
147
148         strcpy(card->driver, "CS46xx");
149         strcpy(card->shortname, "Sound Fusion CS46xx");
150         sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
151                 card->shortname,
152                 chip->ba0_addr,
153                 chip->ba1_addr,
154                 chip->irq);
155
156         if ((err = snd_card_register(card)) < 0) {
157                 snd_card_free(card);
158                 return err;
159         }
160
161         pci_set_drvdata(pci, card);
162         dev++;
163         return 0;
164 }
165
166 static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci)
167 {
168         snd_card_free(pci_get_drvdata(pci));
169         pci_set_drvdata(pci, NULL);
170 }
171
172 static struct pci_driver driver = {
173         .name = "Sound Fusion CS46xx",
174         .id_table = snd_cs46xx_ids,
175         .probe = snd_card_cs46xx_probe,
176         .remove = __devexit_p(snd_card_cs46xx_remove),
177         SND_PCI_PM_CALLBACKS
178 };
179
180 static int __init alsa_card_cs46xx_init(void)
181 {
182         return pci_module_init(&driver);
183 }
184
185 static void __exit alsa_card_cs46xx_exit(void)
186 {
187         pci_unregister_driver(&driver);
188 }
189
190 module_init(alsa_card_cs46xx_init)
191 module_exit(alsa_card_cs46xx_exit)