root/sound/pci/ctxfi/xfi.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ct_card_probe
  2. ct_card_remove
  3. ct_card_suspend
  4. ct_card_resume

   1 // SPDX-License-Identifier: GPL-2.0-only
   2 /*
   3  * xfi linux driver.
   4  *
   5  * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
   6  */
   7 
   8 #include <linux/init.h>
   9 #include <linux/pci.h>
  10 #include <linux/moduleparam.h>
  11 #include <linux/pci_ids.h>
  12 #include <linux/module.h>
  13 #include <sound/core.h>
  14 #include <sound/initval.h>
  15 #include "ctatc.h"
  16 #include "cthardware.h"
  17 
  18 MODULE_AUTHOR("Creative Technology Ltd");
  19 MODULE_DESCRIPTION("X-Fi driver version 1.03");
  20 MODULE_LICENSE("GPL v2");
  21 MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
  22 
  23 static unsigned int reference_rate = 48000;
  24 static unsigned int multiple = 2;
  25 MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
  26 module_param(reference_rate, uint, 0444);
  27 MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
  28 module_param(multiple, uint, 0444);
  29 
  30 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
  31 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
  32 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  33 static unsigned int subsystem[SNDRV_CARDS];
  34 
  35 module_param_array(index, int, NULL, 0444);
  36 MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
  37 module_param_array(id, charp, NULL, 0444);
  38 MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
  39 module_param_array(enable, bool, NULL, 0444);
  40 MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
  41 module_param_array(subsystem, int, NULL, 0444);
  42 MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
  43 
  44 static const struct pci_device_id ct_pci_dev_ids[] = {
  45         /* only X-Fi is supported, so... */
  46         { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
  47           .driver_data = ATC20K1,
  48         },
  49         { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
  50           .driver_data = ATC20K2,
  51         },
  52         { 0, }
  53 };
  54 MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
  55 
  56 static int
  57 ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
  58 {
  59         static int dev;
  60         struct snd_card *card;
  61         struct ct_atc *atc;
  62         int err;
  63 
  64         if (dev >= SNDRV_CARDS)
  65                 return -ENODEV;
  66 
  67         if (!enable[dev]) {
  68                 dev++;
  69                 return -ENOENT;
  70         }
  71         err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  72                            0, &card);
  73         if (err)
  74                 return err;
  75         if ((reference_rate != 48000) && (reference_rate != 44100)) {
  76                 dev_err(card->dev,
  77                         "Invalid reference_rate value %u!!!\n",
  78                         reference_rate);
  79                 dev_err(card->dev,
  80                         "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n");
  81                 reference_rate = 48000;
  82         }
  83         if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
  84                 dev_err(card->dev, "Invalid multiple value %u!!!\n",
  85                         multiple);
  86                 dev_err(card->dev,
  87                         "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n");
  88                 multiple = 2;
  89         }
  90         err = ct_atc_create(card, pci, reference_rate, multiple,
  91                             pci_id->driver_data, subsystem[dev], &atc);
  92         if (err < 0)
  93                 goto error;
  94 
  95         card->private_data = atc;
  96 
  97         /* Create alsa devices supported by this card */
  98         err = ct_atc_create_alsa_devs(atc);
  99         if (err < 0)
 100                 goto error;
 101 
 102         strcpy(card->driver, "SB-XFi");
 103         strcpy(card->shortname, "Creative X-Fi");
 104         snprintf(card->longname, sizeof(card->longname), "%s %s %s",
 105                  card->shortname, atc->chip_name, atc->model_name);
 106 
 107         err = snd_card_register(card);
 108         if (err < 0)
 109                 goto error;
 110 
 111         pci_set_drvdata(pci, card);
 112         dev++;
 113 
 114         return 0;
 115 
 116 error:
 117         snd_card_free(card);
 118         return err;
 119 }
 120 
 121 static void ct_card_remove(struct pci_dev *pci)
 122 {
 123         snd_card_free(pci_get_drvdata(pci));
 124 }
 125 
 126 #ifdef CONFIG_PM_SLEEP
 127 static int ct_card_suspend(struct device *dev)
 128 {
 129         struct snd_card *card = dev_get_drvdata(dev);
 130         struct ct_atc *atc = card->private_data;
 131 
 132         return atc->suspend(atc);
 133 }
 134 
 135 static int ct_card_resume(struct device *dev)
 136 {
 137         struct snd_card *card = dev_get_drvdata(dev);
 138         struct ct_atc *atc = card->private_data;
 139 
 140         return atc->resume(atc);
 141 }
 142 
 143 static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
 144 #define CT_CARD_PM_OPS  &ct_card_pm
 145 #else
 146 #define CT_CARD_PM_OPS  NULL
 147 #endif
 148 
 149 static struct pci_driver ct_driver = {
 150         .name = KBUILD_MODNAME,
 151         .id_table = ct_pci_dev_ids,
 152         .probe = ct_card_probe,
 153         .remove = ct_card_remove,
 154         .driver = {
 155                 .pm = CT_CARD_PM_OPS,
 156         },
 157 };
 158 
 159 module_pci_driver(ct_driver);

/* [<][>][^][v][top][bottom][index][help] */