| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 <sound/driver.h> | 
 | 22 | #include <linux/init.h> | 
 | 23 | #include <linux/interrupt.h> | 
 | 24 | #include <linux/pci.h> | 
 | 25 | #include <linux/slab.h> | 
 | 26 | #include <linux/moduleparam.h> | 
 | 27 | #include <sound/core.h> | 
 | 28 | #include <sound/initval.h> | 
| Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 29 | #include <sound/tlv.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include "vx222.h" | 
 | 31 |  | 
 | 32 | #define CARD_NAME "VX222" | 
 | 33 |  | 
 | 34 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); | 
 | 35 | MODULE_DESCRIPTION("Digigram VX222 V2/Mic"); | 
 | 36 | MODULE_LICENSE("GPL"); | 
 | 37 | MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}"); | 
 | 38 |  | 
 | 39 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
 | 40 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
 | 41 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */ | 
 | 42 | static int mic[SNDRV_CARDS]; /* microphone */ | 
 | 43 | static int ibl[SNDRV_CARDS]; /* microphone */ | 
 | 44 |  | 
 | 45 | module_param_array(index, int, NULL, 0444); | 
 | 46 | MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard."); | 
 | 47 | module_param_array(id, charp, NULL, 0444); | 
 | 48 | MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard."); | 
 | 49 | module_param_array(enable, bool, NULL, 0444); | 
 | 50 | MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard."); | 
 | 51 | module_param_array(mic, bool, NULL, 0444); | 
 | 52 | MODULE_PARM_DESC(mic, "Enable Microphone."); | 
 | 53 | module_param_array(ibl, int, NULL, 0444); | 
 | 54 | MODULE_PARM_DESC(ibl, "Capture IBL size."); | 
 | 55 |  | 
 | 56 | /* | 
 | 57 |  */ | 
 | 58 |  | 
 | 59 | enum { | 
 | 60 | 	VX_PCI_VX222_OLD, | 
 | 61 | 	VX_PCI_VX222_NEW | 
 | 62 | }; | 
 | 63 |  | 
| Takashi Iwai | f40b689 | 2006-07-05 16:51:05 +0200 | [diff] [blame] | 64 | static struct pci_device_id snd_vx222_ids[] = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | 	{ 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, },   /* PLX */ | 
 | 66 | 	{ 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, },   /* PLX */ | 
 | 67 | 	{ 0, } | 
 | 68 | }; | 
 | 69 |  | 
 | 70 | MODULE_DEVICE_TABLE(pci, snd_vx222_ids); | 
 | 71 |  | 
 | 72 |  | 
 | 73 | /* | 
 | 74 |  */ | 
 | 75 |  | 
| Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 76 | static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0); | 
 | 77 | static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0); | 
| Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 78 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | static struct snd_vx_hardware vx222_old_hw = { | 
 | 80 |  | 
 | 81 | 	.name = "VX222/Old", | 
 | 82 | 	.type = VX_TYPE_BOARD, | 
 | 83 | 	/* hw specs */ | 
 | 84 | 	.num_codecs = 1, | 
 | 85 | 	.num_ins = 1, | 
 | 86 | 	.num_outs = 1, | 
 | 87 | 	.output_level_max = VX_ANALOG_OUT_LEVEL_MAX, | 
| Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 88 | 	.output_level_db_scale = db_scale_old_vol, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | }; | 
 | 90 |  | 
 | 91 | static struct snd_vx_hardware vx222_v2_hw = { | 
 | 92 |  | 
 | 93 | 	.name = "VX222/v2", | 
 | 94 | 	.type = VX_TYPE_V2, | 
 | 95 | 	/* hw specs */ | 
 | 96 | 	.num_codecs = 1, | 
 | 97 | 	.num_ins = 1, | 
 | 98 | 	.num_outs = 1, | 
 | 99 | 	.output_level_max = VX2_AKM_LEVEL_MAX, | 
| Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 100 | 	.output_level_db_scale = db_scale_akm, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | }; | 
 | 102 |  | 
 | 103 | static struct snd_vx_hardware vx222_mic_hw = { | 
 | 104 |  | 
 | 105 | 	.name = "VX222/Mic", | 
 | 106 | 	.type = VX_TYPE_MIC, | 
 | 107 | 	/* hw specs */ | 
 | 108 | 	.num_codecs = 1, | 
 | 109 | 	.num_ins = 1, | 
 | 110 | 	.num_outs = 1, | 
 | 111 | 	.output_level_max = VX2_AKM_LEVEL_MAX, | 
| Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 112 | 	.output_level_db_scale = db_scale_akm, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | }; | 
 | 114 |  | 
 | 115 |  | 
 | 116 | /* | 
 | 117 |  */ | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 118 | static int snd_vx222_free(struct vx_core *chip) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | { | 
 | 120 | 	struct snd_vx222 *vx = (struct snd_vx222 *)chip; | 
 | 121 |  | 
 | 122 | 	if (chip->irq >= 0) | 
 | 123 | 		free_irq(chip->irq, (void*)chip); | 
 | 124 | 	if (vx->port[0]) | 
 | 125 | 		pci_release_regions(vx->pci); | 
 | 126 | 	pci_disable_device(vx->pci); | 
 | 127 | 	kfree(chip); | 
 | 128 | 	return 0; | 
 | 129 | } | 
 | 130 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 131 | static int snd_vx222_dev_free(struct snd_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | { | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 133 | 	struct vx_core *chip = device->device_data; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 	return snd_vx222_free(chip); | 
 | 135 | } | 
 | 136 |  | 
 | 137 |  | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 138 | static int __devinit snd_vx222_create(struct snd_card *card, struct pci_dev *pci, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | 				      struct snd_vx_hardware *hw, | 
 | 140 | 				      struct snd_vx222 **rchip) | 
 | 141 | { | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 142 | 	struct vx_core *chip; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | 	struct snd_vx222 *vx; | 
 | 144 | 	int i, err; | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 145 | 	static struct snd_device_ops ops = { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | 		.dev_free =	snd_vx222_dev_free, | 
 | 147 | 	}; | 
 | 148 | 	struct snd_vx_ops *vx_ops; | 
 | 149 |  | 
 | 150 | 	/* enable PCI device */ | 
 | 151 | 	if ((err = pci_enable_device(pci)) < 0) | 
 | 152 | 		return err; | 
 | 153 | 	pci_set_master(pci); | 
 | 154 |  | 
 | 155 | 	vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops; | 
 | 156 | 	chip = snd_vx_create(card, hw, vx_ops, | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 157 | 			     sizeof(struct snd_vx222) - sizeof(struct vx_core)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | 	if (! chip) { | 
 | 159 | 		pci_disable_device(pci); | 
 | 160 | 		return -ENOMEM; | 
 | 161 | 	} | 
 | 162 | 	vx = (struct snd_vx222 *)chip; | 
 | 163 | 	vx->pci = pci; | 
 | 164 |  | 
 | 165 | 	if ((err = pci_request_regions(pci, CARD_NAME)) < 0) { | 
 | 166 | 		snd_vx222_free(chip); | 
 | 167 | 		return err; | 
 | 168 | 	} | 
 | 169 | 	for (i = 0; i < 2; i++) | 
 | 170 | 		vx->port[i] = pci_resource_start(pci, i + 1); | 
 | 171 |  | 
| Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 172 | 	if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED, | 
 | 173 | 			CARD_NAME, chip)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | 		snd_printk(KERN_ERR "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 | 	snd_card_set_dev(card, &pci->dev); | 
 | 186 |  | 
 | 187 | 	*rchip = vx; | 
 | 188 | 	return 0; | 
 | 189 | } | 
 | 190 |  | 
 | 191 |  | 
 | 192 | static int __devinit snd_vx222_probe(struct pci_dev *pci, | 
 | 193 | 				     const struct pci_device_id *pci_id) | 
 | 194 | { | 
 | 195 | 	static int dev; | 
| Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 196 | 	struct snd_card *card; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | 	struct snd_vx_hardware *hw; | 
 | 198 | 	struct snd_vx222 *vx; | 
 | 199 | 	int err; | 
 | 200 |  | 
 | 201 | 	if (dev >= SNDRV_CARDS) | 
 | 202 | 		return -ENODEV; | 
 | 203 | 	if (!enable[dev]) { | 
 | 204 | 		dev++; | 
 | 205 | 		return -ENOENT; | 
 | 206 | 	} | 
 | 207 |  | 
 | 208 | 	card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | 
 | 209 | 	if (card == NULL) | 
 | 210 | 		return -ENOMEM; | 
 | 211 |  | 
 | 212 | 	switch ((int)pci_id->driver_data) { | 
 | 213 | 	case VX_PCI_VX222_OLD: | 
 | 214 | 		hw = &vx222_old_hw; | 
 | 215 | 		break; | 
 | 216 | 	case VX_PCI_VX222_NEW: | 
 | 217 | 	default: | 
 | 218 | 		if (mic[dev]) | 
 | 219 | 			hw = &vx222_mic_hw; | 
 | 220 | 		else | 
 | 221 | 			hw = &vx222_v2_hw; | 
 | 222 | 		break; | 
 | 223 | 	} | 
 | 224 | 	if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) { | 
 | 225 | 		snd_card_free(card); | 
 | 226 | 		return err; | 
 | 227 | 	} | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 228 | 	card->private_data = vx; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | 	vx->core.ibl.size = ibl[dev]; | 
 | 230 |  | 
 | 231 | 	sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i", | 
 | 232 | 		card->shortname, vx->port[0], vx->port[1], vx->core.irq); | 
 | 233 | 	snd_printdd("%s at 0x%lx & 0x%lx, irq %i\n", | 
 | 234 | 		    card->shortname, vx->port[0], vx->port[1], vx->core.irq); | 
 | 235 |  | 
 | 236 | #ifdef SND_VX_FW_LOADER | 
 | 237 | 	vx->core.dev = &pci->dev; | 
 | 238 | #endif | 
 | 239 |  | 
 | 240 | 	if ((err = snd_vx_setup_firmware(&vx->core)) < 0) { | 
 | 241 | 		snd_card_free(card); | 
 | 242 | 		return err; | 
 | 243 | 	} | 
 | 244 |  | 
 | 245 | 	if ((err = snd_card_register(card)) < 0) { | 
 | 246 | 		snd_card_free(card); | 
 | 247 | 		return err; | 
 | 248 | 	} | 
 | 249 |  | 
 | 250 | 	pci_set_drvdata(pci, card); | 
 | 251 | 	dev++; | 
 | 252 | 	return 0; | 
 | 253 | } | 
 | 254 |  | 
 | 255 | static void __devexit snd_vx222_remove(struct pci_dev *pci) | 
 | 256 | { | 
 | 257 | 	snd_card_free(pci_get_drvdata(pci)); | 
 | 258 | 	pci_set_drvdata(pci, NULL); | 
 | 259 | } | 
 | 260 |  | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 261 | #ifdef CONFIG_PM | 
 | 262 | static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state) | 
 | 263 | { | 
 | 264 | 	struct snd_card *card = pci_get_drvdata(pci); | 
 | 265 | 	struct snd_vx222 *vx = card->private_data; | 
 | 266 | 	int err; | 
 | 267 |  | 
 | 268 | 	err = snd_vx_suspend(&vx->core, state); | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 269 | 	pci_disable_device(pci); | 
 | 270 | 	pci_save_state(pci); | 
| Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 271 | 	pci_set_power_state(pci, pci_choose_state(pci, state)); | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 272 | 	return err; | 
 | 273 | } | 
 | 274 |  | 
 | 275 | static int snd_vx222_resume(struct pci_dev *pci) | 
 | 276 | { | 
 | 277 | 	struct snd_card *card = pci_get_drvdata(pci); | 
 | 278 | 	struct snd_vx222 *vx = card->private_data; | 
 | 279 |  | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 280 | 	pci_set_power_state(pci, PCI_D0); | 
| Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 281 | 	pci_restore_state(pci); | 
 | 282 | 	if (pci_enable_device(pci) < 0) { | 
 | 283 | 		printk(KERN_ERR "vx222: pci_enable_device failed, " | 
 | 284 | 		       "disabling device\n"); | 
 | 285 | 		snd_card_disconnect(card); | 
 | 286 | 		return -EIO; | 
 | 287 | 	} | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 288 | 	pci_set_master(pci); | 
 | 289 | 	return snd_vx_resume(&vx->core); | 
 | 290 | } | 
 | 291 | #endif | 
 | 292 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | static struct pci_driver driver = { | 
 | 294 | 	.name = "Digigram VX222", | 
 | 295 | 	.id_table = snd_vx222_ids, | 
 | 296 | 	.probe = snd_vx222_probe, | 
 | 297 | 	.remove = __devexit_p(snd_vx222_remove), | 
| Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 298 | #ifdef CONFIG_PM | 
 | 299 | 	.suspend = snd_vx222_suspend, | 
 | 300 | 	.resume = snd_vx222_resume, | 
 | 301 | #endif | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | }; | 
 | 303 |  | 
 | 304 | static int __init alsa_card_vx222_init(void) | 
 | 305 | { | 
| Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 306 | 	return pci_register_driver(&driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | } | 
 | 308 |  | 
 | 309 | static void __exit alsa_card_vx222_exit(void) | 
 | 310 | { | 
 | 311 | 	pci_unregister_driver(&driver); | 
 | 312 | } | 
 | 313 |  | 
 | 314 | module_init(alsa_card_vx222_init) | 
 | 315 | module_exit(alsa_card_vx222_exit) |