Thomas Gleixner | 1a59d1b8 | 2019-05-27 08:55:05 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Driver for Digigram VX222 V2/Mic PCI soundcards |
| 4 | * |
| 5 | * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/init.h> |
| 9 | #include <linux/interrupt.h> |
| 10 | #include <linux/pci.h> |
| 11 | #include <linux/slab.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 12 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <sound/core.h> |
| 14 | #include <sound/initval.h> |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 15 | #include <sound/tlv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include "vx222.h" |
| 17 | |
| 18 | #define CARD_NAME "VX222" |
| 19 | |
| 20 | MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); |
| 21 | MODULE_DESCRIPTION("Digigram VX222 V2/Mic"); |
| 22 | MODULE_LICENSE("GPL"); |
| 23 | MODULE_SUPPORTED_DEVICE("{{Digigram," CARD_NAME "}}"); |
| 24 | |
| 25 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 26 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 27 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 28 | static bool mic[SNDRV_CARDS]; /* microphone */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static int ibl[SNDRV_CARDS]; /* microphone */ |
| 30 | |
| 31 | module_param_array(index, int, NULL, 0444); |
| 32 | MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard."); |
| 33 | module_param_array(id, charp, NULL, 0444); |
| 34 | MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard."); |
| 35 | module_param_array(enable, bool, NULL, 0444); |
| 36 | MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard."); |
| 37 | module_param_array(mic, bool, NULL, 0444); |
| 38 | MODULE_PARM_DESC(mic, "Enable Microphone."); |
| 39 | module_param_array(ibl, int, NULL, 0444); |
| 40 | MODULE_PARM_DESC(ibl, "Capture IBL size."); |
| 41 | |
| 42 | /* |
| 43 | */ |
| 44 | |
| 45 | enum { |
| 46 | VX_PCI_VX222_OLD, |
| 47 | VX_PCI_VX222_NEW |
| 48 | }; |
| 49 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 50 | static const struct pci_device_id snd_vx222_ids[] = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
| 56 | MODULE_DEVICE_TABLE(pci, snd_vx222_ids); |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | */ |
| 61 | |
Takashi Iwai | 0cb29ea | 2007-01-29 15:33:49 +0100 | [diff] [blame] | 62 | static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0); |
| 63 | static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0); |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 74 | .output_level_db_scale = db_scale_old_vol, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
| 77 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 86 | .output_level_db_scale = db_scale_akm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | }; |
| 88 | |
| 89 | static 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, |
Takashi Iwai | 1186ed8 | 2006-08-23 19:53:28 +0200 | [diff] [blame] | 98 | .output_level_db_scale = db_scale_akm, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | |
| 102 | /* |
| 103 | */ |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 104 | static int snd_vx222_free(struct vx_core *chip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | { |
Takashi Iwai | 5f976f5 | 2017-05-12 10:02:08 +0200 | [diff] [blame] | 106 | struct snd_vx222 *vx = to_vx222(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 117 | static int snd_vx222_dev_free(struct snd_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 119 | struct vx_core *chip = device->device_data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return snd_vx222_free(chip); |
| 121 | } |
| 122 | |
| 123 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 124 | static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci, |
| 125 | struct snd_vx_hardware *hw, |
| 126 | struct snd_vx222 **rchip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | { |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 128 | struct vx_core *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | struct snd_vx222 *vx; |
| 130 | int i, err; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 131 | static struct snd_device_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | .dev_free = snd_vx222_dev_free, |
| 133 | }; |
| 134 | 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, |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 143 | sizeof(struct snd_vx222) - sizeof(struct vx_core)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | if (! chip) { |
| 145 | pci_disable_device(pci); |
| 146 | return -ENOMEM; |
| 147 | } |
Takashi Iwai | 5f976f5 | 2017-05-12 10:02:08 +0200 | [diff] [blame] | 148 | vx = to_vx222(chip); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Takashi Iwai | db0a521 | 2014-09-09 17:17:20 +0200 | [diff] [blame] | 158 | if (request_threaded_irq(pci->irq, snd_vx_irq_handler, |
| 159 | snd_vx_threaded_irq_handler, IRQF_SHARED, |
| 160 | KBUILD_MODNAME, chip)) { |
Takashi Iwai | 4c826c4 | 2014-02-26 12:13:57 +0100 | [diff] [blame] | 161 | dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | snd_vx222_free(chip); |
| 163 | return -EBUSY; |
| 164 | } |
| 165 | chip->irq = pci->irq; |
| 166 | |
| 167 | if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { |
| 168 | snd_vx222_free(chip); |
| 169 | return err; |
| 170 | } |
| 171 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | *rchip = vx; |
| 173 | return 0; |
| 174 | } |
| 175 | |
| 176 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 177 | static int snd_vx222_probe(struct pci_dev *pci, |
| 178 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | { |
| 180 | static int dev; |
Takashi Iwai | af26367 | 2005-11-17 14:46:59 +0100 | [diff] [blame] | 181 | struct snd_card *card; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | struct snd_vx_hardware *hw; |
| 183 | struct snd_vx222 *vx; |
| 184 | int err; |
| 185 | |
| 186 | if (dev >= SNDRV_CARDS) |
| 187 | return -ENODEV; |
| 188 | if (!enable[dev]) { |
| 189 | dev++; |
| 190 | return -ENOENT; |
| 191 | } |
| 192 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 193 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 194 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 195 | if (err < 0) |
| 196 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | switch ((int)pci_id->driver_data) { |
| 199 | case VX_PCI_VX222_OLD: |
| 200 | hw = &vx222_old_hw; |
| 201 | break; |
| 202 | case VX_PCI_VX222_NEW: |
| 203 | default: |
| 204 | if (mic[dev]) |
| 205 | hw = &vx222_mic_hw; |
| 206 | else |
| 207 | hw = &vx222_v2_hw; |
| 208 | break; |
| 209 | } |
| 210 | if ((err = snd_vx222_create(card, pci, hw, &vx)) < 0) { |
| 211 | snd_card_free(card); |
| 212 | return err; |
| 213 | } |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 214 | card->private_data = vx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | vx->core.ibl.size = ibl[dev]; |
| 216 | |
| 217 | sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i", |
| 218 | card->shortname, vx->port[0], vx->port[1], vx->core.irq); |
Takashi Iwai | 4c826c4 | 2014-02-26 12:13:57 +0100 | [diff] [blame] | 219 | dev_dbg(card->dev, "%s at 0x%lx & 0x%lx, irq %i\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | card->shortname, vx->port[0], vx->port[1], vx->core.irq); |
| 221 | |
| 222 | #ifdef SND_VX_FW_LOADER |
| 223 | vx->core.dev = &pci->dev; |
| 224 | #endif |
| 225 | |
| 226 | if ((err = snd_vx_setup_firmware(&vx->core)) < 0) { |
| 227 | snd_card_free(card); |
| 228 | return err; |
| 229 | } |
| 230 | |
| 231 | if ((err = snd_card_register(card)) < 0) { |
| 232 | snd_card_free(card); |
| 233 | return err; |
| 234 | } |
| 235 | |
| 236 | pci_set_drvdata(pci, card); |
| 237 | dev++; |
| 238 | return 0; |
| 239 | } |
| 240 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 241 | static void snd_vx222_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | { |
| 243 | snd_card_free(pci_get_drvdata(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 246 | #ifdef CONFIG_PM_SLEEP |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 247 | static int snd_vx222_suspend(struct device *dev) |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 248 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 249 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 250 | struct snd_vx222 *vx = card->private_data; |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 251 | |
Takashi Iwai | de0c869 | 2015-01-08 12:50:48 +0100 | [diff] [blame] | 252 | return snd_vx_suspend(&vx->core); |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 253 | } |
| 254 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 255 | static int snd_vx222_resume(struct device *dev) |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 256 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 257 | struct snd_card *card = dev_get_drvdata(dev); |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 258 | struct snd_vx222 *vx = card->private_data; |
| 259 | |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 260 | return snd_vx_resume(&vx->core); |
| 261 | } |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 262 | |
| 263 | static SIMPLE_DEV_PM_OPS(snd_vx222_pm, snd_vx222_suspend, snd_vx222_resume); |
| 264 | #define SND_VX222_PM_OPS &snd_vx222_pm |
| 265 | #else |
| 266 | #define SND_VX222_PM_OPS NULL |
Takashi Iwai | 0ed1cad | 2005-11-17 16:06:05 +0100 | [diff] [blame] | 267 | #endif |
| 268 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 269 | static struct pci_driver vx222_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 270 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | .id_table = snd_vx222_ids, |
| 272 | .probe = snd_vx222_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 273 | .remove = snd_vx222_remove, |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 274 | .driver = { |
| 275 | .pm = SND_VX222_PM_OPS, |
| 276 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | }; |
| 278 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 279 | module_pci_driver(vx222_driver); |