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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #include <linux/init.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/slab.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 25 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <sound/core.h> |
| 27 | #include <sound/initval.h> |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 28 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | #include "vx222.h" |
| 30 | |
| 31 | #define CARD_NAME "VX222" |
| 32 | |
| 33 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); |
| 34 | MODULE_DESCRIPTION("Digigram VX222 V2/Mic"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}"); |
| 37 | |
| 38 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 39 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 40 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 41 | static bool mic[SNDRV_CARDS]; /* microphone */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | static int ibl[SNDRV_CARDS]; /* microphone */ |
| 43 | |
| 44 | module_param_array(index, int, NULL, 0444); |
| 45 | MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard."); |
| 46 | module_param_array(id, charp, NULL, 0444); |
| 47 | MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard."); |
| 48 | module_param_array(enable, bool, NULL, 0444); |
| 49 | MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard."); |
| 50 | module_param_array(mic, bool, NULL, 0444); |
| 51 | MODULE_PARM_DESC(mic, "Enable Microphone."); |
| 52 | module_param_array(ibl, int, NULL, 0444); |
| 53 | MODULE_PARM_DESC(ibl, "Capture IBL size."); |
| 54 | |
| 55 | /* |
| 56 | */ |
| 57 | |
| 58 | enum { |
| 59 | VX_PCI_VX222_OLD, |
| 60 | VX_PCI_VX222_NEW |
| 61 | }; |
| 62 | |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 63 | static DEFINE_PCI_DEVICE_TABLE(snd_vx222_ids) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 69 | MODULE_DEVICE_TABLE(pci, snd_vx222_ids); |
| 70 | |
| 71 | |
| 72 | /* |
| 73 | */ |
| 74 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 75 | static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0); |
| 76 | static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0); |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 87 | .output_level_db_scale = db_scale_old_vol, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
| 90 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 99 | .output_level_db_scale = db_scale_akm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | }; |
| 101 | |
| 102 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 111 | .output_level_db_scale = db_scale_akm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | }; |
| 113 | |
| 114 | |
| 115 | /* |
| 116 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 117 | static int snd_vx222_free(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 130 | static int snd_vx222_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 132 | struct vx_core *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | return snd_vx222_free(chip); |
| 134 | } |
| 135 | |
| 136 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 137 | 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] | 138 | struct snd_vx_hardware *hw, |
| 139 | struct snd_vx222 **rchip) |
| 140 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 141 | struct vx_core *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | struct snd_vx222 *vx; |
| 143 | int i, err; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 144 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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, |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 156 | sizeof(struct snd_vx222) - sizeof(struct vx_core)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Takashi Iwai | 437a5a4 | 2006-11-21 12:14:23 +0100 | [diff] [blame] | 171 | if (request_irq(pci->irq, snd_vx_irq_handler, IRQF_SHARED, |
Takashi Iwai | 934c2b6 | 2011-06-10 16:36:37 +0200 | [diff] [blame] | 172 | KBUILD_MODNAME, chip)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); |
| 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 | |
| 184 | snd_card_set_dev(card, &pci->dev); |
| 185 | |
| 186 | *rchip = vx; |
| 187 | return 0; |
| 188 | } |
| 189 | |
| 190 | |
| 191 | static int __devinit snd_vx222_probe(struct pci_dev *pci, |
| 192 | const struct pci_device_id *pci_id) |
| 193 | { |
| 194 | static int dev; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 195 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | struct snd_vx_hardware *hw; |
| 197 | struct snd_vx222 *vx; |
| 198 | int err; |
| 199 | |
| 200 | if (dev >= SNDRV_CARDS) |
| 201 | return -ENODEV; |
| 202 | if (!enable[dev]) { |
| 203 | dev++; |
| 204 | return -ENOENT; |
| 205 | } |
| 206 | |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 207 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); |
| 208 | if (err < 0) |
| 209 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | } |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 227 | card->private_data = vx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | snd_printdd("%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 | |
| 254 | static void __devexit snd_vx222_remove(struct pci_dev *pci) |
| 255 | { |
| 256 | snd_card_free(pci_get_drvdata(pci)); |
| 257 | pci_set_drvdata(pci, NULL); |
| 258 | } |
| 259 | |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 260 | #ifdef CONFIG_PM |
| 261 | static int snd_vx222_suspend(struct pci_dev *pci, pm_message_t state) |
| 262 | { |
| 263 | struct snd_card *card = pci_get_drvdata(pci); |
| 264 | struct snd_vx222 *vx = card->private_data; |
| 265 | int err; |
| 266 | |
| 267 | err = snd_vx_suspend(&vx->core, state); |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 268 | pci_disable_device(pci); |
| 269 | pci_save_state(pci); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 270 | pci_set_power_state(pci, pci_choose_state(pci, state)); |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 271 | return err; |
| 272 | } |
| 273 | |
| 274 | static int snd_vx222_resume(struct pci_dev *pci) |
| 275 | { |
| 276 | struct snd_card *card = pci_get_drvdata(pci); |
| 277 | struct snd_vx222 *vx = card->private_data; |
| 278 | |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 279 | pci_set_power_state(pci, PCI_D0); |
Takashi Iwai | 30b3539 | 2006-10-11 18:52:53 +0200 | [diff] [blame] | 280 | pci_restore_state(pci); |
| 281 | if (pci_enable_device(pci) < 0) { |
| 282 | printk(KERN_ERR "vx222: pci_enable_device failed, " |
| 283 | "disabling device\n"); |
| 284 | snd_card_disconnect(card); |
| 285 | return -EIO; |
| 286 | } |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 287 | pci_set_master(pci); |
| 288 | return snd_vx_resume(&vx->core); |
| 289 | } |
| 290 | #endif |
| 291 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 292 | static struct pci_driver vx222_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 293 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | .id_table = snd_vx222_ids, |
| 295 | .probe = snd_vx222_probe, |
| 296 | .remove = __devexit_p(snd_vx222_remove), |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 297 | #ifdef CONFIG_PM |
| 298 | .suspend = snd_vx222_suspend, |
| 299 | .resume = snd_vx222_resume, |
| 300 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | }; |
| 302 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 303 | module_pci_driver(vx222_driver); |