0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/init.h>
0009 #include <linux/pci.h>
0010 #include <linux/moduleparam.h>
0011 #include <linux/pci_ids.h>
0012 #include <linux/module.h>
0013 #include <sound/core.h>
0014 #include <sound/initval.h>
0015 #include "ctatc.h"
0016 #include "cthardware.h"
0017
0018 MODULE_AUTHOR("Creative Technology Ltd");
0019 MODULE_DESCRIPTION("X-Fi driver version 1.03");
0020 MODULE_LICENSE("GPL v2");
0021
0022 static unsigned int reference_rate = 48000;
0023 static unsigned int multiple = 2;
0024 MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
0025 module_param(reference_rate, uint, 0444);
0026 MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
0027 module_param(multiple, uint, 0444);
0028
0029 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
0030 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
0031 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
0032 static unsigned int subsystem[SNDRV_CARDS];
0033
0034 module_param_array(index, int, NULL, 0444);
0035 MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
0036 module_param_array(id, charp, NULL, 0444);
0037 MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
0038 module_param_array(enable, bool, NULL, 0444);
0039 MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
0040 module_param_array(subsystem, int, NULL, 0444);
0041 MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
0042
0043 static const struct pci_device_id ct_pci_dev_ids[] = {
0044
0045 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
0046 .driver_data = ATC20K1,
0047 },
0048 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
0049 .driver_data = ATC20K2,
0050 },
0051 { 0, }
0052 };
0053 MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
0054
0055 static int
0056 ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
0057 {
0058 static int dev;
0059 struct snd_card *card;
0060 struct ct_atc *atc;
0061 int err;
0062
0063 if (dev >= SNDRV_CARDS)
0064 return -ENODEV;
0065
0066 if (!enable[dev]) {
0067 dev++;
0068 return -ENOENT;
0069 }
0070 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0071 0, &card);
0072 if (err)
0073 return err;
0074 if ((reference_rate != 48000) && (reference_rate != 44100)) {
0075 dev_err(card->dev,
0076 "Invalid reference_rate value %u!!!\n",
0077 reference_rate);
0078 dev_err(card->dev,
0079 "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n");
0080 reference_rate = 48000;
0081 }
0082 if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
0083 dev_err(card->dev, "Invalid multiple value %u!!!\n",
0084 multiple);
0085 dev_err(card->dev,
0086 "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n");
0087 multiple = 2;
0088 }
0089 err = ct_atc_create(card, pci, reference_rate, multiple,
0090 pci_id->driver_data, subsystem[dev], &atc);
0091 if (err < 0)
0092 goto error;
0093
0094 card->private_data = atc;
0095
0096
0097 err = ct_atc_create_alsa_devs(atc);
0098 if (err < 0)
0099 goto error;
0100
0101 strcpy(card->driver, "SB-XFi");
0102 strcpy(card->shortname, "Creative X-Fi");
0103 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
0104 card->shortname, atc->chip_name, atc->model_name);
0105
0106 err = snd_card_register(card);
0107 if (err < 0)
0108 goto error;
0109
0110 pci_set_drvdata(pci, card);
0111 dev++;
0112
0113 return 0;
0114
0115 error:
0116 snd_card_free(card);
0117 return err;
0118 }
0119
0120 static void ct_card_remove(struct pci_dev *pci)
0121 {
0122 snd_card_free(pci_get_drvdata(pci));
0123 }
0124
0125 #ifdef CONFIG_PM_SLEEP
0126 static int ct_card_suspend(struct device *dev)
0127 {
0128 struct snd_card *card = dev_get_drvdata(dev);
0129 struct ct_atc *atc = card->private_data;
0130
0131 return atc->suspend(atc);
0132 }
0133
0134 static int ct_card_resume(struct device *dev)
0135 {
0136 struct snd_card *card = dev_get_drvdata(dev);
0137 struct ct_atc *atc = card->private_data;
0138
0139 return atc->resume(atc);
0140 }
0141
0142 static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
0143 #define CT_CARD_PM_OPS &ct_card_pm
0144 #else
0145 #define CT_CARD_PM_OPS NULL
0146 #endif
0147
0148 static struct pci_driver ct_driver = {
0149 .name = KBUILD_MODNAME,
0150 .id_table = ct_pci_dev_ids,
0151 .probe = ct_card_probe,
0152 .remove = ct_card_remove,
0153 .driver = {
0154 .pm = CT_CARD_PM_OPS,
0155 },
0156 };
0157
0158 module_pci_driver(ct_driver);