blob: f42e7e1a107457bf99091d5813b438a88fe31f2f [file] [log] [blame]
Wai Yew CHAY8cc72362009-05-14 08:05:58 +02001/*
2 * xfi linux driver.
3 *
4 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
5 *
6 * This source file is released under GPL v2 license (no other versions).
7 * See the COPYING file included in the main directory of this source
8 * distribution for the license terms and conditions.
9 */
10
11#include <linux/init.h>
12#include <linux/pci.h>
13#include <linux/moduleparam.h>
Takashi Iwai9fc20f02009-05-14 15:14:18 +020014#include <linux/pci_ids.h>
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020015#include <sound/core.h>
16#include <sound/initval.h>
17#include "ctatc.h"
Takashi Iwai94701952009-06-08 18:10:32 +020018#include "cthardware.h"
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020019
20MODULE_AUTHOR("Creative Technology Ltd");
21MODULE_DESCRIPTION("X-Fi driver version 1.03");
Takashi Iwai67fbf882009-06-02 09:18:26 +020022MODULE_LICENSE("GPL v2");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020023MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
24
25static unsigned int reference_rate = 48000;
26static unsigned int multiple = 2;
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020027MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020028module_param(reference_rate, uint, S_IRUGO);
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020029MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020030module_param(multiple, uint, S_IRUGO);
31
32static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
33static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
34static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Iwai408bffd2010-01-14 09:19:46 +010035static unsigned int subsystem[SNDRV_CARDS];
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020036
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020037module_param_array(index, int, NULL, 0444);
38MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
39module_param_array(id, charp, NULL, 0444);
40MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
41module_param_array(enable, bool, NULL, 0444);
42MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
Takashi Iwai408bffd2010-01-14 09:19:46 +010043module_param_array(subsystem, int, NULL, 0444);
44MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020045
Alexey Dobriyancebe41d2010-02-06 00:21:03 +020046static DEFINE_PCI_DEVICE_TABLE(ct_pci_dev_ids) = {
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020047 /* only X-Fi is supported, so... */
Takashi Iwai94701952009-06-08 18:10:32 +020048 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
49 .driver_data = ATC20K1,
50 },
51 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
52 .driver_data = ATC20K2,
53 },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020054 { 0, }
55};
56MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
57
58static int __devinit
59ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
60{
61 static int dev;
62 struct snd_card *card;
63 struct ct_atc *atc;
64 int err;
65
66 if (dev >= SNDRV_CARDS)
67 return -ENODEV;
68
69 if (!enable[dev]) {
70 dev++;
71 return -ENOENT;
72 }
73 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
74 if (err)
75 return err;
76 if ((reference_rate != 48000) && (reference_rate != 44100)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020077 printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
78 reference_rate);
79 printk(KERN_ERR "ctxfi: The valid values for reference_rate "
80 "are 48000 and 44100, Value 48000 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020081 reference_rate = 48000;
82 }
83 if ((multiple != 1) && (multiple != 2)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020084 printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
85 multiple);
86 printk(KERN_ERR "ctxfi: The valid values for multiple are "
87 "1 and 2, Value 2 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020088 multiple = 2;
89 }
Takashi Iwai94701952009-06-08 18:10:32 +020090 err = ct_atc_create(card, pci, reference_rate, multiple,
Takashi Iwai408bffd2010-01-14 09:19:46 +010091 pci_id->driver_data, subsystem[dev], &atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020092 if (err < 0)
93 goto error;
94
95 card->private_data = atc;
96
97 /* Create alsa devices supported by this card */
Takashi Iwai2a36f672009-06-05 16:34:10 +020098 err = ct_atc_create_alsa_devs(atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020099 if (err < 0)
100 goto error;
101
102 strcpy(card->driver, "SB-XFi");
103 strcpy(card->shortname, "Creative X-Fi");
Takashi Iwai94701952009-06-08 18:10:32 +0200104 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
105 card->shortname, atc->chip_name, atc->model_name);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200106
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
116error:
117 snd_card_free(card);
118 return err;
119}
120
121static void __devexit ct_card_remove(struct pci_dev *pci)
122{
123 snd_card_free(pci_get_drvdata(pci));
124 pci_set_drvdata(pci, NULL);
125}
126
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200127#ifdef CONFIG_PM
128static int ct_card_suspend(struct pci_dev *pci, pm_message_t state)
129{
130 struct snd_card *card = pci_get_drvdata(pci);
131 struct ct_atc *atc = card->private_data;
132
133 return atc->suspend(atc, state);
134}
135
136static int ct_card_resume(struct pci_dev *pci)
137{
138 struct snd_card *card = pci_get_drvdata(pci);
139 struct ct_atc *atc = card->private_data;
140
141 return atc->resume(atc);
142}
143#endif
144
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200145static struct pci_driver ct_driver = {
146 .name = "SB-XFi",
147 .id_table = ct_pci_dev_ids,
148 .probe = ct_card_probe,
149 .remove = __devexit_p(ct_card_remove),
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200150#ifdef CONFIG_PM
151 .suspend = ct_card_suspend,
152 .resume = ct_card_resume,
153#endif
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200154};
155
156static int __init ct_card_init(void)
157{
158 return pci_register_driver(&ct_driver);
159}
160
161static void __exit ct_card_exit(void)
162{
163 pci_unregister_driver(&ct_driver);
164}
165
166module_init(ct_card_init)
167module_exit(ct_card_exit)