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