1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Driver for Digigram VX222 V2/Mic PCI soundcards
5 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/pci.h>
11 #include <linux/slab.h>
12 #include <linux/module.h>
13 #include <sound/core.h>
14 #include <sound/initval.h>
15 #include <sound/tlv.h>
18 #define CARD_NAME "VX222"
20 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
21 MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
22 MODULE_LICENSE("GPL");
23 MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME
"}}");
25 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
; /* Index 0-MAX */
26 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
; /* ID for this card */
27 static bool enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
; /* Enable this card */
28 static bool mic
[SNDRV_CARDS
]; /* microphone */
29 static int ibl
[SNDRV_CARDS
]; /* microphone */
31 module_param_array(index
, int, NULL
, 0444);
32 MODULE_PARM_DESC(index
, "Index value for Digigram " CARD_NAME
" soundcard.");
33 module_param_array(id
, charp
, NULL
, 0444);
34 MODULE_PARM_DESC(id
, "ID string for Digigram " CARD_NAME
" soundcard.");
35 module_param_array(enable
, bool, NULL
, 0444);
36 MODULE_PARM_DESC(enable
, "Enable Digigram " CARD_NAME
" soundcard.");
37 module_param_array(mic
, bool, NULL
, 0444);
38 MODULE_PARM_DESC(mic
, "Enable Microphone.");
39 module_param_array(ibl
, int, NULL
, 0444);
40 MODULE_PARM_DESC(ibl
, "Capture IBL size.");
50 static const struct pci_device_id snd_vx222_ids
[] = {
51 { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID
, 0, 0, VX_PCI_VX222_OLD
, }, /* PLX */
52 { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID
, 0, 0, VX_PCI_VX222_NEW
, }, /* PLX */
56 MODULE_DEVICE_TABLE(pci
, snd_vx222_ids
);
62 static const DECLARE_TLV_DB_SCALE(db_scale_old_vol
, -11350, 50, 0);
63 static const DECLARE_TLV_DB_SCALE(db_scale_akm
, -7350, 50, 0);
65 static const struct snd_vx_hardware vx222_old_hw
= {
68 .type
= VX_TYPE_BOARD
,
73 .output_level_max
= VX_ANALOG_OUT_LEVEL_MAX
,
74 .output_level_db_scale
= db_scale_old_vol
,
77 static const struct snd_vx_hardware vx222_v2_hw
= {
85 .output_level_max
= VX2_AKM_LEVEL_MAX
,
86 .output_level_db_scale
= db_scale_akm
,
89 static const struct snd_vx_hardware vx222_mic_hw
= {
97 .output_level_max
= VX2_AKM_LEVEL_MAX
,
98 .output_level_db_scale
= db_scale_akm
,
104 static int snd_vx222_free(struct vx_core
*chip
)
106 struct snd_vx222
*vx
= to_vx222(chip
);
109 free_irq(chip
->irq
, (void*)chip
);
111 pci_release_regions(vx
->pci
);
112 pci_disable_device(vx
->pci
);
117 static int snd_vx222_dev_free(struct snd_device
*device
)
119 struct vx_core
*chip
= device
->device_data
;
120 return snd_vx222_free(chip
);
124 static int snd_vx222_create(struct snd_card
*card
, struct pci_dev
*pci
,
125 const struct snd_vx_hardware
*hw
,
126 struct snd_vx222
**rchip
)
128 struct vx_core
*chip
;
129 struct snd_vx222
*vx
;
131 static const struct snd_device_ops ops
= {
132 .dev_free
= snd_vx222_dev_free
,
134 const struct snd_vx_ops
*vx_ops
;
136 /* enable PCI device */
137 if ((err
= pci_enable_device(pci
)) < 0)
141 vx_ops
= hw
->type
== VX_TYPE_BOARD
? &vx222_old_ops
: &vx222_ops
;
142 chip
= snd_vx_create(card
, hw
, vx_ops
,
143 sizeof(struct snd_vx222
) - sizeof(struct vx_core
));
145 pci_disable_device(pci
);
151 if ((err
= pci_request_regions(pci
, CARD_NAME
)) < 0) {
152 snd_vx222_free(chip
);
155 for (i
= 0; i
< 2; i
++)
156 vx
->port
[i
] = pci_resource_start(pci
, i
+ 1);
158 if (request_threaded_irq(pci
->irq
, snd_vx_irq_handler
,
159 snd_vx_threaded_irq_handler
, IRQF_SHARED
,
160 KBUILD_MODNAME
, chip
)) {
161 dev_err(card
->dev
, "unable to grab IRQ %d\n", pci
->irq
);
162 snd_vx222_free(chip
);
165 chip
->irq
= pci
->irq
;
166 card
->sync_irq
= chip
->irq
;
168 if ((err
= snd_device_new(card
, SNDRV_DEV_LOWLEVEL
, chip
, &ops
)) < 0) {
169 snd_vx222_free(chip
);
178 static int snd_vx222_probe(struct pci_dev
*pci
,
179 const struct pci_device_id
*pci_id
)
182 struct snd_card
*card
;
183 const struct snd_vx_hardware
*hw
;
184 struct snd_vx222
*vx
;
187 if (dev
>= SNDRV_CARDS
)
194 err
= snd_card_new(&pci
->dev
, index
[dev
], id
[dev
], THIS_MODULE
,
199 switch ((int)pci_id
->driver_data
) {
200 case VX_PCI_VX222_OLD
:
203 case VX_PCI_VX222_NEW
:
211 if ((err
= snd_vx222_create(card
, pci
, hw
, &vx
)) < 0) {
215 card
->private_data
= vx
;
216 vx
->core
.ibl
.size
= ibl
[dev
];
218 sprintf(card
->longname
, "%s at 0x%lx & 0x%lx, irq %i",
219 card
->shortname
, vx
->port
[0], vx
->port
[1], vx
->core
.irq
);
220 dev_dbg(card
->dev
, "%s at 0x%lx & 0x%lx, irq %i\n",
221 card
->shortname
, vx
->port
[0], vx
->port
[1], vx
->core
.irq
);
223 #ifdef SND_VX_FW_LOADER
224 vx
->core
.dev
= &pci
->dev
;
227 if ((err
= snd_vx_setup_firmware(&vx
->core
)) < 0) {
232 if ((err
= snd_card_register(card
)) < 0) {
237 pci_set_drvdata(pci
, card
);
242 static void snd_vx222_remove(struct pci_dev
*pci
)
244 snd_card_free(pci_get_drvdata(pci
));
247 #ifdef CONFIG_PM_SLEEP
248 static int snd_vx222_suspend(struct device
*dev
)
250 struct snd_card
*card
= dev_get_drvdata(dev
);
251 struct snd_vx222
*vx
= card
->private_data
;
253 return snd_vx_suspend(&vx
->core
);
256 static int snd_vx222_resume(struct device
*dev
)
258 struct snd_card
*card
= dev_get_drvdata(dev
);
259 struct snd_vx222
*vx
= card
->private_data
;
261 return snd_vx_resume(&vx
->core
);
264 static SIMPLE_DEV_PM_OPS(snd_vx222_pm
, snd_vx222_suspend
, snd_vx222_resume
);
265 #define SND_VX222_PM_OPS &snd_vx222_pm
267 #define SND_VX222_PM_OPS NULL
270 static struct pci_driver vx222_driver
= {
271 .name
= KBUILD_MODNAME
,
272 .id_table
= snd_vx222_ids
,
273 .probe
= snd_vx222_probe
,
274 .remove
= snd_vx222_remove
,
276 .pm
= SND_VX222_PM_OPS
,
280 module_pci_driver(vx222_driver
);