vserver 1.9.3
[linux-2.6.git] / sound / pci / vx222 / vx222.c
1 /*
2  * Driver for Digigram VX222 V2/Mic PCI soundcards
3  *
4  * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
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 #include <sound/driver.h>
22 #include <linux/init.h>
23 #include <linux/interrupt.h>
24 #include <linux/pci.h>
25 #include <linux/slab.h>
26 #include <linux/moduleparam.h>
27 #include <sound/core.h>
28 #include <sound/initval.h>
29 #include "vx222.h"
30
31 #define CARD_NAME "VX222"
32
33 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
34 MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
35 MODULE_LICENSE("GPL");
36 MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}");
37
38 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;      /* Index 0-MAX */
39 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;       /* ID for this card */
40 static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;      /* Enable this card */
41 static int mic[SNDRV_CARDS]; /* microphone */
42 static int ibl[SNDRV_CARDS]; /* microphone */
43 static int boot_devs;
44
45 module_param_array(index, int, boot_devs, 0444);
46 MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
47 module_param_array(id, charp, boot_devs, 0444);
48 MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
49 module_param_array(enable, bool, boot_devs, 0444);
50 MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
51 module_param_array(mic, bool, boot_devs, 0444);
52 MODULE_PARM_DESC(mic, "Enable Microphone.");
53 module_param_array(ibl, int, boot_devs, 0444);
54 MODULE_PARM_DESC(ibl, "Capture IBL size.");
55
56 /*
57  */
58
59 enum {
60         VX_PCI_VX222_OLD,
61         VX_PCI_VX222_NEW
62 };
63
64 static struct pci_device_id snd_vx222_ids[] = {
65         { 0x10b5, 0x9050, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, },   /* PLX */
66         { 0x10b5, 0x9030, PCI_ANY_ID, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, },   /* PLX */
67         { 0, }
68 };
69
70 MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
71
72
73 /*
74  */
75
76 static struct snd_vx_hardware vx222_old_hw = {
77
78         .name = "VX222/Old",
79         .type = VX_TYPE_BOARD,
80         /* hw specs */
81         .num_codecs = 1,
82         .num_ins = 1,
83         .num_outs = 1,
84         .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
85 };
86
87 static struct snd_vx_hardware vx222_v2_hw = {
88
89         .name = "VX222/v2",
90         .type = VX_TYPE_V2,
91         /* hw specs */
92         .num_codecs = 1,
93         .num_ins = 1,
94         .num_outs = 1,
95         .output_level_max = VX2_AKM_LEVEL_MAX,
96 };
97
98 static struct snd_vx_hardware vx222_mic_hw = {
99
100         .name = "VX222/Mic",
101         .type = VX_TYPE_MIC,
102         /* hw specs */
103         .num_codecs = 1,
104         .num_ins = 1,
105         .num_outs = 1,
106         .output_level_max = VX2_AKM_LEVEL_MAX,
107 };
108
109
110 /*
111  */
112 static int snd_vx222_free(vx_core_t *chip)
113 {
114         struct snd_vx222 *vx = (struct snd_vx222 *)chip;
115
116         if (chip->irq >= 0)
117                 free_irq(chip->irq, (void*)chip);
118         if (vx->port[0])
119                 pci_release_regions(vx->pci);
120         kfree(chip);
121         return 0;
122 }
123
124 static int snd_vx222_dev_free(snd_device_t *device)
125 {
126         vx_core_t *chip = device->device_data;
127         return snd_vx222_free(chip);
128 }
129
130
131 static int __devinit snd_vx222_create(snd_card_t *card, struct pci_dev *pci,
132                                       struct snd_vx_hardware *hw,
133                                       struct snd_vx222 **rchip)
134 {
135         vx_core_t *chip;
136         struct snd_vx222 *vx;
137         int i, err;
138         static snd_device_ops_t ops = {
139                 .dev_free =     snd_vx222_dev_free,
140         };
141         struct snd_vx_ops *vx_ops;
142
143         /* enable PCI device */
144         if ((err = pci_enable_device(pci)) < 0)
145                 return err;
146         pci_set_master(pci);
147
148         vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
149         chip = snd_vx_create(card, hw, vx_ops,
150                              sizeof(struct snd_vx222) - sizeof(vx_core_t));
151         if (! chip)
152                 return -ENOMEM;
153         vx = (struct snd_vx222 *)chip;
154         vx->pci = pci;
155
156         if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
157                 snd_vx222_free(chip);
158                 return err;
159         }
160         for (i = 0; i < 2; i++)
161                 vx->port[i] = pci_resource_start(pci, i + 1);
162
163         if (request_irq(pci->irq, snd_vx_irq_handler, SA_INTERRUPT|SA_SHIRQ,
164                         CARD_NAME, (void *) chip)) {
165                 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
166                 snd_vx222_free(chip);
167                 return -EBUSY;
168         }
169         chip->irq = pci->irq;
170
171         if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
172                 snd_vx222_free(chip);
173                 return err;
174         }
175
176         snd_card_set_dev(card, &pci->dev);
177
178         *rchip = vx;
179         return 0;
180 }
181
182
183 static int __devinit snd_vx222_probe(struct pci_dev *pci,
184                                      const struct pci_device_id *pci_id)
185 {
186         static int dev;
187         snd_card_t *card;
188         struct snd_vx_hardware *hw;
189         struct snd_vx222 *vx;
190         int err;
191
192         if (dev >= SNDRV_CARDS)
193                 return -ENODEV;
194         if (!enable[dev]) {
195                 dev++;
196                 return -ENOENT;
197         }
198
199         card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
200         if (card == NULL)
201                 return -ENOMEM;
202
203         switch ((int)pci_id->driver_data) {
204         case VX_PCI_VX222_OLD:
205                 hw = &vx222_old_hw;
206                 break;
207         case VX_PCI_VX222_NEW:
208         default:
209                 if (mic[dev])
210                         hw = &vx222_mic_hw;
211                 else
212                         hw = &vx222_v2_hw;
213                 break;
214         }
215         if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) {
216                 snd_card_free(card);
217                 return err;
218         }
219         vx->core.ibl.size = ibl[dev];
220
221         sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
222                 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
223         snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n",
224                     card->shortname, vx->port[0], vx->port[1], vx->core.irq);
225
226         if ((err = snd_vx_hwdep_new(&vx->core)) < 0) {
227                 snd_card_free(card);
228                 return err;
229         }
230
231         if ((err = snd_card_register(card)) < 0) {
232                 snd_card_free(card);
233                 return err;
234         }
235
236         pci_set_drvdata(pci, card);
237         dev++;
238         return 0;
239 }
240
241 static void __devexit snd_vx222_remove(struct pci_dev *pci)
242 {
243         snd_card_free(pci_get_drvdata(pci));
244         pci_set_drvdata(pci, NULL);
245 }
246
247 static struct pci_driver driver = {
248         .name = "Digigram VX222",
249         .id_table = snd_vx222_ids,
250         .probe = snd_vx222_probe,
251         .remove = __devexit_p(snd_vx222_remove),
252 };
253
254 static int __init alsa_card_vx222_init(void)
255 {
256         return pci_module_init(&driver);
257 }
258
259 static void __exit alsa_card_vx222_exit(void)
260 {
261         pci_unregister_driver(&driver);
262 }
263
264 module_init(alsa_card_vx222_init)
265 module_exit(alsa_card_vx222_exit)