2 * Driver for Digigram VX222 V2/Mic PCI soundcards
4 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
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.
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.
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
21 #include <linux/init.h>
22 #include <linux/interrupt.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/moduleparam.h>
26 #include <sound/core.h>
27 #include <sound/initval.h>
28 #include <sound/tlv.h>
31 #define CARD_NAME "VX222"
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 "}}");
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 */
44 module_param_array(index, int, NULL, 0444);
45 MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
46 module_param_array(id, charp, NULL, 0444);
47 MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
48 module_param_array(enable, bool, NULL, 0444);
49 MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
50 module_param_array(mic, bool, NULL, 0444);
51 MODULE_PARM_DESC(mic, "Enable Microphone.");
52 module_param_array(ibl, int, NULL, 0444);
53 MODULE_PARM_DESC(ibl, "Capture IBL size.");
63 static struct pci_device_id snd_vx222_ids[] = {
64 { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */
65 { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */
69 MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
75 static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
76 static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
78 static struct snd_vx_hardware vx222_old_hw = {
81 .type = VX_TYPE_BOARD,
86 .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
87 .output_level_db_scale = db_scale_old_vol,
90 static struct snd_vx_hardware vx222_v2_hw = {
98 .output_level_max = VX2_AKM_LEVEL_MAX,
99 .output_level_db_scale = db_scale_akm,
102 static struct snd_vx_hardware vx222_mic_hw = {
110 .output_level_max = VX2_AKM_LEVEL_MAX,
111 .output_level_db_scale = db_scale_akm,
117 static int snd_vx222_free(struct vx_core *chip)
119 struct snd_vx222 *vx = (struct snd_vx222 *)chip;
122 free_irq(chip->irq, (void*)chip);
124 pci_release_regions(vx->pci);
125 pci_disable_device(vx->pci);
130 static int snd_vx222_dev_free(struct snd_device *device)
132 struct vx_core *chip = device->device_data;
133 return snd_vx222_free(chip);
137 static int __devinit snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
138 struct snd_vx_hardware *hw,
139 struct snd_vx222 **rchip)
141 struct vx_core *chip;
142 struct snd_vx222 *vx;
144 static struct snd_device_ops ops = {
145 .dev_free = snd_vx222_dev_free,
147 struct snd_vx_ops *vx_ops;
149 /* enable PCI device */
150 if ((err = pci_enable_device(pci)) < 0)
154 vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
155 chip = snd_vx_create(card, hw, vx_ops,
156 sizeof(struct snd_vx222) - sizeof(struct vx_core));
158 pci_disable_device(pci);
161 vx = (struct snd_vx222 *)chip;
164 if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
165 snd_vx222_free(chip);
168 for (i = 0; i < 2; i++)
169 vx->port[i] = pci_resource_start(pci, i + 1);
171 if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED,
173 snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
174 snd_vx222_free(chip);
177 chip->irq = pci->irq;
179 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
180 snd_vx222_free(chip);
184 snd_card_set_dev(card, &pci->dev);
191 static int __devinit snd_vx222_probe(struct pci_dev *pci,
192 const struct pci_device_id *pci_id)
195 struct snd_card *card;
196 struct snd_vx_hardware *hw;
197 struct snd_vx222 *vx;
200 if (dev >= SNDRV_CARDS)
207 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
211 switch ((int)pci_id->driver_data) {
212 case VX_PCI_VX222_OLD:
215 case VX_PCI_VX222_NEW:
223 if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) {
227 card->private_data = vx;
228 vx->core.ibl.size = ibl[dev];
230 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
231 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
232 snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n",
233 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
235 #ifdef SND_VX_FW_LOADER
236 vx->core.dev = &pci->dev;
239 if ((err = snd_vx_setup_firmware(&vx->core)) < 0) {
244 if ((err = snd_card_register(card)) < 0) {
249 pci_set_drvdata(pci, card);
254 static void __devexit snd_vx222_remove(struct pci_dev *pci)
256 snd_card_free(pci_get_drvdata(pci));
257 pci_set_drvdata(pci, NULL);
261 static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state)
263 struct snd_card *card = pci_get_drvdata(pci);
264 struct snd_vx222 *vx = card->private_data;
267 err = snd_vx_suspend(&vx->core, state);
268 pci_disable_device(pci);
270 pci_set_power_state(pci, pci_choose_state(pci, state));
274 static int snd_vx222_resume(struct pci_dev *pci)
276 struct snd_card *card = pci_get_drvdata(pci);
277 struct snd_vx222 *vx = card->private_data;
279 pci_set_power_state(pci, PCI_D0);
280 pci_restore_state(pci);
281 if (pci_enable_device(pci) < 0) {
282 printk(KERN_ERR "vx222: pci_enable_device failed, "
283 "disabling device\n");
284 snd_card_disconnect(card);
288 return snd_vx_resume(&vx->core);
292 static struct pci_driver driver = {
293 .name = "Digigram VX222",
294 .id_table = snd_vx222_ids,
295 .probe = snd_vx222_probe,
296 .remove = __devexit_p(snd_vx222_remove),
298 .suspend = snd_vx222_suspend,
299 .resume = snd_vx222_resume,
303 static int __init alsa_card_vx222_init(void)
305 return pci_register_driver(&driver);
308 static void __exit alsa_card_vx222_exit(void)
310 pci_unregister_driver(&driver);
313 module_init(alsa_card_vx222_init)
314 module_exit(alsa_card_vx222_exit)