Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Driver for Digigram VX222 V2/Mic PCI soundcards
0004  *
0005  * Copyright (c) 2002 by Takashi Iwai <tiwai@suse.de>
0006  */
0007 
0008 #include <linux/init.h>
0009 #include <linux/interrupt.h>
0010 #include <linux/pci.h>
0011 #include <linux/slab.h>
0012 #include <linux/module.h>
0013 #include <sound/core.h>
0014 #include <sound/initval.h>
0015 #include <sound/tlv.h>
0016 #include "vx222.h"
0017 
0018 #define CARD_NAME "VX222"
0019 
0020 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
0021 MODULE_DESCRIPTION("Digigram VX222 V2/Mic");
0022 MODULE_LICENSE("GPL");
0023 
0024 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;  /* Index 0-MAX */
0025 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;   /* ID for this card */
0026 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
0027 static bool mic[SNDRV_CARDS]; /* microphone */
0028 static int ibl[SNDRV_CARDS]; /* microphone */
0029 
0030 module_param_array(index, int, NULL, 0444);
0031 MODULE_PARM_DESC(index, "Index value for Digigram " CARD_NAME " soundcard.");
0032 module_param_array(id, charp, NULL, 0444);
0033 MODULE_PARM_DESC(id, "ID string for Digigram " CARD_NAME " soundcard.");
0034 module_param_array(enable, bool, NULL, 0444);
0035 MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
0036 module_param_array(mic, bool, NULL, 0444);
0037 MODULE_PARM_DESC(mic, "Enable Microphone.");
0038 module_param_array(ibl, int, NULL, 0444);
0039 MODULE_PARM_DESC(ibl, "Capture IBL size.");
0040 
0041 /*
0042  */
0043 
0044 enum {
0045     VX_PCI_VX222_OLD,
0046     VX_PCI_VX222_NEW
0047 };
0048 
0049 static const struct pci_device_id snd_vx222_ids[] = {
0050     { 0x10b5, 0x9050, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_OLD, },   /* PLX */
0051     { 0x10b5, 0x9030, 0x1369, PCI_ANY_ID, 0, 0, VX_PCI_VX222_NEW, },   /* PLX */
0052     { 0, }
0053 };
0054 
0055 MODULE_DEVICE_TABLE(pci, snd_vx222_ids);
0056 
0057 
0058 /*
0059  */
0060 
0061 static const DECLARE_TLV_DB_SCALE(db_scale_old_vol, -11350, 50, 0);
0062 static const DECLARE_TLV_DB_SCALE(db_scale_akm, -7350, 50, 0);
0063 
0064 static const struct snd_vx_hardware vx222_old_hw = {
0065 
0066     .name = "VX222/Old",
0067     .type = VX_TYPE_BOARD,
0068     /* hw specs */
0069     .num_codecs = 1,
0070     .num_ins = 1,
0071     .num_outs = 1,
0072     .output_level_max = VX_ANALOG_OUT_LEVEL_MAX,
0073     .output_level_db_scale = db_scale_old_vol,
0074 };
0075 
0076 static const struct snd_vx_hardware vx222_v2_hw = {
0077 
0078     .name = "VX222/v2",
0079     .type = VX_TYPE_V2,
0080     /* hw specs */
0081     .num_codecs = 1,
0082     .num_ins = 1,
0083     .num_outs = 1,
0084     .output_level_max = VX2_AKM_LEVEL_MAX,
0085     .output_level_db_scale = db_scale_akm,
0086 };
0087 
0088 static const struct snd_vx_hardware vx222_mic_hw = {
0089 
0090     .name = "VX222/Mic",
0091     .type = VX_TYPE_MIC,
0092     /* hw specs */
0093     .num_codecs = 1,
0094     .num_ins = 1,
0095     .num_outs = 1,
0096     .output_level_max = VX2_AKM_LEVEL_MAX,
0097     .output_level_db_scale = db_scale_akm,
0098 };
0099 
0100 
0101 /*
0102  */
0103 static int snd_vx222_create(struct snd_card *card, struct pci_dev *pci,
0104                 const struct snd_vx_hardware *hw,
0105                 struct snd_vx222 **rchip)
0106 {
0107     struct vx_core *chip;
0108     struct snd_vx222 *vx;
0109     int i, err;
0110     const struct snd_vx_ops *vx_ops;
0111 
0112     /* enable PCI device */
0113     err = pcim_enable_device(pci);
0114     if (err < 0)
0115         return err;
0116     pci_set_master(pci);
0117 
0118     vx_ops = hw->type == VX_TYPE_BOARD ? &vx222_old_ops : &vx222_ops;
0119     chip = snd_vx_create(card, hw, vx_ops,
0120                  sizeof(struct snd_vx222) - sizeof(struct vx_core));
0121     if (!chip)
0122         return -ENOMEM;
0123     vx = to_vx222(chip);
0124     vx->pci = pci;
0125 
0126     err = pci_request_regions(pci, CARD_NAME);
0127     if (err < 0)
0128         return err;
0129     for (i = 0; i < 2; i++)
0130         vx->port[i] = pci_resource_start(pci, i + 1);
0131 
0132     if (devm_request_threaded_irq(&pci->dev, pci->irq, snd_vx_irq_handler,
0133                       snd_vx_threaded_irq_handler, IRQF_SHARED,
0134                       KBUILD_MODNAME, chip)) {
0135         dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
0136         return -EBUSY;
0137     }
0138     chip->irq = pci->irq;
0139     card->sync_irq = chip->irq;
0140     *rchip = vx;
0141 
0142     return 0;
0143 }
0144 
0145 
0146 static int snd_vx222_probe(struct pci_dev *pci,
0147                const struct pci_device_id *pci_id)
0148 {
0149     static int dev;
0150     struct snd_card *card;
0151     const struct snd_vx_hardware *hw;
0152     struct snd_vx222 *vx;
0153     int err;
0154 
0155     if (dev >= SNDRV_CARDS)
0156         return -ENODEV;
0157     if (!enable[dev]) {
0158         dev++;
0159         return -ENOENT;
0160     }
0161 
0162     err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0163                 0, &card);
0164     if (err < 0)
0165         return err;
0166 
0167     switch ((int)pci_id->driver_data) {
0168     case VX_PCI_VX222_OLD:
0169         hw = &vx222_old_hw;
0170         break;
0171     case VX_PCI_VX222_NEW:
0172     default:
0173         if (mic[dev])
0174             hw = &vx222_mic_hw;
0175         else
0176             hw = &vx222_v2_hw;
0177         break;
0178     }
0179     err = snd_vx222_create(card, pci, hw, &vx);
0180     if (err < 0)
0181         return err;
0182     card->private_data = vx;
0183     vx->core.ibl.size = ibl[dev];
0184 
0185     sprintf(card->longname, "%s at 0x%lx & 0x%lx, irq %i",
0186         card->shortname, vx->port[0], vx->port[1], vx->core.irq);
0187     dev_dbg(card->dev, "%s at 0x%lx & 0x%lx, irq %i\n",
0188             card->shortname, vx->port[0], vx->port[1], vx->core.irq);
0189 
0190 #ifdef SND_VX_FW_LOADER
0191     vx->core.dev = &pci->dev;
0192 #endif
0193 
0194     err = snd_vx_setup_firmware(&vx->core);
0195     if (err < 0)
0196         return err;
0197 
0198     err = snd_card_register(card);
0199     if (err < 0)
0200         return err;
0201 
0202     pci_set_drvdata(pci, card);
0203     dev++;
0204     return 0;
0205 }
0206 
0207 #ifdef CONFIG_PM_SLEEP
0208 static int snd_vx222_suspend(struct device *dev)
0209 {
0210     struct snd_card *card = dev_get_drvdata(dev);
0211     struct snd_vx222 *vx = card->private_data;
0212 
0213     return snd_vx_suspend(&vx->core);
0214 }
0215 
0216 static int snd_vx222_resume(struct device *dev)
0217 {
0218     struct snd_card *card = dev_get_drvdata(dev);
0219     struct snd_vx222 *vx = card->private_data;
0220 
0221     return snd_vx_resume(&vx->core);
0222 }
0223 
0224 static SIMPLE_DEV_PM_OPS(snd_vx222_pm, snd_vx222_suspend, snd_vx222_resume);
0225 #define SND_VX222_PM_OPS    &snd_vx222_pm
0226 #else
0227 #define SND_VX222_PM_OPS    NULL
0228 #endif
0229 
0230 static struct pci_driver vx222_driver = {
0231     .name = KBUILD_MODNAME,
0232     .id_table = snd_vx222_ids,
0233     .probe = snd_vx222_probe,
0234     .driver = {
0235         .pm = SND_VX222_PM_OPS,
0236     },
0237 };
0238 
0239 module_pci_driver(vx222_driver);