1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Driver for Digigram VX222 V2/Mic PCI soundcards
4 *
5 * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
6 */
7
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>
16#include "vx222.h"
17
18#define CARD_NAME "VX222"
19
20MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
21MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
22MODULE_LICENSE("GPL");
23
24static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
25static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
26static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
27static bool mic[SNDRV_CARDS]; /* microphone */
28static int ibl[SNDRV_CARDS]; /* microphone */
29
30module_param_array(index, int, NULL, 0444);
31MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
32module_param_array(id, charp, NULL, 0444);
33MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
34module_param_array(enable, bool, NULL, 0444);
35MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
36module_param_array(mic, bool, NULL, 0444);
37MODULE_PARM_DESC(mic, "Enable Microphone.");
38module_param_array(ibl, int, NULL, 0444);
39MODULE_PARM_DESC(ibl, "Capture IBL size.");
40
41/*
42 */
43
44enum {
45 VX_PCI_VX222_OLD,
46 VX_PCI_VX222_NEW
47};
48
49static const struct pci_device_id snd_vx222_ids[] = {
50 { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, }, /* PLX */
51 { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, }, /* PLX */
52 { 0, }
53};
54
55MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
56
57
58/*
59 */
60
61static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
62static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
63
64static const struct snd_vx_hardware vx222_old_hw = {
65
66 .name = "VX222/Old",
67 .type = VX_TYPE_BOARD,
68 /* hw specs */
69 .num_codecs = 1,
70 .num_ins = 1,
71 .num_outs = 1,
72 .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
73 .output_level_db_scale = db_scale_old_vol,
74};
75
76static const struct snd_vx_hardware vx222_v2_hw = {
77
78 .name = "VX222/v2",
79 .type = VX_TYPE_V2,
80 /* hw specs */
81 .num_codecs = 1,
82 .num_ins = 1,
83 .num_outs = 1,
84 .output_level_max = VX2_AKM_LEVEL_MAX,
85 .output_level_db_scale = db_scale_akm,
86};
87
88static const struct snd_vx_hardware vx222_mic_hw = {
89
90 .name = "VX222/Mic",
91 .type = VX_TYPE_MIC,
92 /* hw specs */
93 .num_codecs = 1,
94 .num_ins = 1,
95 .num_outs = 1,
96 .output_level_max = VX2_AKM_LEVEL_MAX,
97 .output_level_db_scale = db_scale_akm,
98};
99
100
101/*
102 */
103static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
104 const struct snd_vx_hardware *hw,
105 struct snd_vx222 **rchip)
106{
107 struct vx_core *chip;
108 struct snd_vx222 *vx;
109 int i, err;
110 const struct snd_vx_ops *vx_ops;
111
112 /* enable PCI device */
113 err = pcim_enable_device(pdev: pci);
114 if (err < 0)
115 return err;
116 pci_set_master(dev: pci);
117
118 vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
119 chip = snd_vx_create(card, hw, ops: vx_ops,
120 extra_size: sizeof(struct snd_vx222) - sizeof(struct vx_core));
121 if (!chip)
122 return -ENOMEM;
123 vx = to_vx222(chip);
124 vx->pci = pci;
125
126 err = pci_request_regions(pci, CARD_NAME);
127 if (err < 0)
128 return err;
129 for (i = 0; i < 2; i++)
130 vx->port[i] = pci_resource_start(pci, i + 1);
131
132 if (devm_request_threaded_irq(dev: &pci->dev, irq: pci->irq, handler: snd_vx_irq_handler,
133 thread_fn: snd_vx_threaded_irq_handler, IRQF_SHARED,
134 KBUILD_MODNAME, dev_id: chip)) {
135 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
136 return -EBUSY;
137 }
138 chip->irq = pci->irq;
139 card->sync_irq = chip->irq;
140 *rchip = vx;
141
142 return 0;
143}
144
145
146static int snd_vx222_probe(struct pci_dev *pci,
147 const struct pci_device_id *pci_id)
148{
149 static int dev;
150 struct snd_card *card;
151 const struct snd_vx_hardware *hw;
152 struct snd_vx222 *vx;
153 int err;
154
155 if (dev >= SNDRV_CARDS)
156 return -ENODEV;
157 if (!enable[dev]) {
158 dev++;
159 return -ENOENT;
160 }
161
162 err = snd_devm_card_new(parent: &pci->dev, idx: index[dev], xid: id[dev], THIS_MODULE,
163 extra_size: 0, card_ret: &card);
164 if (err < 0)
165 return err;
166
167 switch ((int)pci_id->driver_data) {
168 case VX_PCI_VX222_OLD:
169 hw = &vx222_old_hw;
170 break;
171 case VX_PCI_VX222_NEW:
172 default:
173 if (mic[dev])
174 hw = &vx222_mic_hw;
175 else
176 hw = &vx222_v2_hw;
177 break;
178 }
179 err = snd_vx222_create(card, pci, hw, rchip: &vx);
180 if (err < 0)
181 return err;
182 card->private_data = vx;
183 vx->core.ibl.size = ibl[dev];
184
185 sprintf(buf: card->longname, fmt: "%s at 0x%lx & 0x%lx, irq %i",
186 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
187 dev_dbg(card->dev, "%s at 0x%lx & 0x%lx, irq %i\n",
188 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
189
190#ifdef SND_VX_FW_LOADER
191 vx->core.dev = &pci->dev;
192#endif
193
194 err = snd_vx_setup_firmware(chip: &vx->core);
195 if (err < 0)
196 return err;
197
198 err = snd_card_register(card);
199 if (err < 0)
200 return err;
201
202 pci_set_drvdata(pdev: pci, data: card);
203 dev++;
204 return 0;
205}
206
207#ifdef CONFIG_PM_SLEEP
208static int snd_vx222_suspend(struct device *dev)
209{
210 struct snd_card *card = dev_get_drvdata(dev);
211 struct snd_vx222 *vx = card->private_data;
212
213 return snd_vx_suspend(card: &vx->core);
214}
215
216static int snd_vx222_resume(struct device *dev)
217{
218 struct snd_card *card = dev_get_drvdata(dev);
219 struct snd_vx222 *vx = card->private_data;
220
221 return snd_vx_resume(card: &vx->core);
222}
223
224static SIMPLE_DEV_PM_OPS(snd_vx222_pm, snd_vx222_suspend, snd_vx222_resume);
225#define SND_VX222_PM_OPS &snd_vx222_pm
226#else
227#define SND_VX222_PM_OPS NULL
228#endif
229
230static struct pci_driver vx222_driver = {
231 .name = KBUILD_MODNAME,
232 .id_table = snd_vx222_ids,
233 .probe = snd_vx222_probe,
234 .driver = {
235 .pm = SND_VX222_PM_OPS,
236 },
237};
238
239module_pci_driver(vx222_driver);
240

source code of linux/sound/pci/vx222/vx222.c