Linux Audio

Check our new training course

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