]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/pci/vx222/vx222.c
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.git] / sound / pci / vx222 / vx222.c
CommitLineData
1da177e4
LT
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
1da177e4
LT
21#include <linux/init.h>
22#include <linux/interrupt.h>
23#include <linux/pci.h>
24#include <linux/slab.h>
65a77217 25#include <linux/module.h>
1da177e4
LT
26#include <sound/core.h>
27#include <sound/initval.h>
1186ed8c 28#include <sound/tlv.h>
1da177e4
LT
29#include "vx222.h"
30
31#define CARD_NAME "VX222"
32
33MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
34MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
35MODULE_LICENSE("GPL");
36MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}");
37
38static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
39static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
a67ff6a5
RR
40static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
41static bool mic[SNDRV_CARDS]; /* microphone */
1da177e4
LT
42static int ibl[SNDRV_CARDS]; /* microphone */
43
44module_param_array(index, int, NULL, 0444);
45MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
46module_param_array(id, charp, NULL, 0444);
47MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
48module_param_array(enable, bool, NULL, 0444);
49MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
50module_param_array(mic, bool, NULL, 0444);
51MODULE_PARM_DESC(mic, "Enable Microphone.");
52module_param_array(ibl, int, NULL, 0444);
53MODULE_PARM_DESC(ibl, "Capture IBL size.");
54
55/*
56 */
57
58enum {
59 VX_PCI_VX222_OLD,
60 VX_PCI_VX222_NEW
61};
62
cebe41d4 63static DEFINE_PCI_DEVICE_TABLE(snd_vx222_ids) = {
1da177e4
LT
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 */
66 { 0, }
67};
68
69MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
70
71
72/*
73 */
74
0cb29ea0
TI
75static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
76static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
1186ed8c 77
1da177e4
LT
78static struct snd_vx_hardware vx222_old_hw = {
79
80 .name = "VX222/Old",
81 .type = VX_TYPE_BOARD,
82 /* hw specs */
83 .num_codecs = 1,
84 .num_ins = 1,
85 .num_outs = 1,
86 .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
1186ed8c 87 .output_level_db_scale = db_scale_old_vol,
1da177e4
LT
88};
89
90static struct snd_vx_hardware vx222_v2_hw = {
91
92 .name = "VX222/v2",
93 .type = VX_TYPE_V2,
94 /* hw specs */
95 .num_codecs = 1,
96 .num_ins = 1,
97 .num_outs = 1,
98 .output_level_max = VX2_AKM_LEVEL_MAX,
1186ed8c 99 .output_level_db_scale = db_scale_akm,
1da177e4
LT
100};
101
102static struct snd_vx_hardware vx222_mic_hw = {
103
104 .name = "VX222/Mic",
105 .type = VX_TYPE_MIC,
106 /* hw specs */
107 .num_codecs = 1,
108 .num_ins = 1,
109 .num_outs = 1,
110 .output_level_max = VX2_AKM_LEVEL_MAX,
1186ed8c 111 .output_level_db_scale = db_scale_akm,
1da177e4
LT
112};
113
114
115/*
116 */
af26367f 117static int snd_vx222_free(struct vx_core *chip)
1da177e4
LT
118{
119 struct snd_vx222 *vx = (struct snd_vx222 *)chip;
120
121 if (chip->irq >= 0)
122 free_irq(chip->irq, (void*)chip);
123 if (vx->port[0])
124 pci_release_regions(vx->pci);
125 pci_disable_device(vx->pci);
126 kfree(chip);
127 return 0;
128}
129
af26367f 130static int snd_vx222_dev_free(struct snd_device *device)
1da177e4 131{
af26367f 132 struct vx_core *chip = device->device_data;
1da177e4
LT
133 return snd_vx222_free(chip);
134}
135
136
e23e7a14
BP
137static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
138 struct snd_vx_hardware *hw,
139 struct snd_vx222 **rchip)
1da177e4 140{
af26367f 141 struct vx_core *chip;
1da177e4
LT
142 struct snd_vx222 *vx;
143 int i, err;
af26367f 144 static struct snd_device_ops ops = {
1da177e4
LT
145 .dev_free = snd_vx222_dev_free,
146 };
147 struct snd_vx_ops *vx_ops;
148
149 /* enable PCI device */
150 if ((err = pci_enable_device(pci)) < 0)
151 return err;
152 pci_set_master(pci);
153
154 vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
155 chip = snd_vx_create(card, hw, vx_ops,
af26367f 156 sizeof(struct snd_vx222) - sizeof(struct vx_core));
1da177e4
LT
157 if (! chip) {
158 pci_disable_device(pci);
159 return -ENOMEM;
160 }
161 vx = (struct snd_vx222 *)chip;
162 vx->pci = pci;
163
164 if ((err = pci_request_regions(pci, CARD_NAME)) < 0) {
165 snd_vx222_free(chip);
166 return err;
167 }
168 for (i = 0; i < 2; i++)
169 vx->port[i] = pci_resource_start(pci, i + 1);
170
437a5a46 171 if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED,
934c2b6d 172 KBUILD_MODNAME, chip)) {
4c826c49 173 dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
1da177e4
LT
174 snd_vx222_free(chip);
175 return -EBUSY;
176 }
177 chip->irq = pci->irq;
178
179 if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
180 snd_vx222_free(chip);
181 return err;
182 }
183
1da177e4
LT
184 *rchip = vx;
185 return 0;
186}
187
188
e23e7a14
BP
189static int snd_vx222_probe(struct pci_dev *pci,
190 const struct pci_device_id *pci_id)
1da177e4
LT
191{
192 static int dev;
af26367f 193 struct snd_card *card;
1da177e4
LT
194 struct snd_vx_hardware *hw;
195 struct snd_vx222 *vx;
196 int err;
197
198 if (dev >= SNDRV_CARDS)
199 return -ENODEV;
200 if (!enable[dev]) {
201 dev++;
202 return -ENOENT;
203 }
204
60c5772b
TI
205 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
206 0, &card);
e58de7ba
TI
207 if (err < 0)
208 return err;
1da177e4
LT
209
210 switch ((int)pci_id->driver_data) {
211 case VX_PCI_VX222_OLD:
212 hw = &vx222_old_hw;
213 break;
214 case VX_PCI_VX222_NEW:
215 default:
216 if (mic[dev])
217 hw = &vx222_mic_hw;
218 else
219 hw = &vx222_v2_hw;
220 break;
221 }
222 if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) {
223 snd_card_free(card);
224 return err;
225 }
0ed1cad1 226 card->private_data = vx;
1da177e4
LT
227 vx->core.ibl.size = ibl[dev];
228
229 sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
230 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
4c826c49 231 dev_dbg(card->dev, "%s at 0x%lx & 0x%lx, irq %i\n",
1da177e4
LT
232 card->shortname, vx->port[0], vx->port[1], vx->core.irq);
233
234#ifdef SND_VX_FW_LOADER
235 vx->core.dev = &pci->dev;
236#endif
237
238 if ((err = snd_vx_setup_firmware(&vx->core)) < 0) {
239 snd_card_free(card);
240 return err;
241 }
242
243 if ((err = snd_card_register(card)) < 0) {
244 snd_card_free(card);
245 return err;
246 }
247
248 pci_set_drvdata(pci, card);
249 dev++;
250 return 0;
251}
252
e23e7a14 253static void snd_vx222_remove(struct pci_dev *pci)
1da177e4
LT
254{
255 snd_card_free(pci_get_drvdata(pci));
1da177e4
LT
256}
257
c7561cd8 258#ifdef CONFIG_PM_SLEEP
68cb2b55 259static int snd_vx222_suspend(struct device *dev)
0ed1cad1 260{
68cb2b55
TI
261 struct pci_dev *pci = to_pci_dev(dev);
262 struct snd_card *card = dev_get_drvdata(dev);
0ed1cad1
TI
263 struct snd_vx222 *vx = card->private_data;
264 int err;
265
68cb2b55 266 err = snd_vx_suspend(&vx->core);
0ed1cad1
TI
267 pci_disable_device(pci);
268 pci_save_state(pci);
68cb2b55 269 pci_set_power_state(pci, PCI_D3hot);
0ed1cad1
TI
270 return err;
271}
272
68cb2b55 273static int snd_vx222_resume(struct device *dev)
0ed1cad1 274{
68cb2b55
TI
275 struct pci_dev *pci = to_pci_dev(dev);
276 struct snd_card *card = dev_get_drvdata(dev);
0ed1cad1
TI
277 struct snd_vx222 *vx = card->private_data;
278
0ed1cad1 279 pci_set_power_state(pci, PCI_D0);
30b35399
TI
280 pci_restore_state(pci);
281 if (pci_enable_device(pci) < 0) {
4c826c49 282 dev_err(dev, "pci_enable_device failed, disabling device\n");
30b35399
TI
283 snd_card_disconnect(card);
284 return -EIO;
285 }
0ed1cad1
TI
286 pci_set_master(pci);
287 return snd_vx_resume(&vx->core);
288}
68cb2b55
TI
289
290static SIMPLE_DEV_PM_OPS(snd_vx222_pm, snd_vx222_suspend, snd_vx222_resume);
291#define SND_VX222_PM_OPS &snd_vx222_pm
292#else
293#define SND_VX222_PM_OPS NULL
0ed1cad1
TI
294#endif
295
e9f66d9b 296static struct pci_driver vx222_driver = {
3733e424 297 .name = KBUILD_MODNAME,
1da177e4
LT
298 .id_table = snd_vx222_ids,
299 .probe = snd_vx222_probe,
e23e7a14 300 .remove = snd_vx222_remove,
68cb2b55
TI
301 .driver = {
302 .pm = SND_VX222_PM_OPS,
303 },
1da177e4
LT
304};
305
e9f66d9b 306module_pci_driver(vx222_driver);