blob: 76541748e7bcf8ec43ccd5964d90faf4258f442a [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;
35
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020036module_param_array(index, int, NULL, 0444);
37MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
38module_param_array(id, charp, NULL, 0444);
39MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
40module_param_array(enable, bool, NULL, 0444);
41MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
42
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020043static struct pci_device_id ct_pci_dev_ids[] = {
44 /* only X-Fi is supported, so... */
Takashi Iwai94701952009-06-08 18:10:32 +020045 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
46 .driver_data = ATC20K1,
47 },
48 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
49 .driver_data = ATC20K2,
50 },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020051 { 0, }
52};
53MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
54
55static int __devinit
56ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
57{
58 static int dev;
59 struct snd_card *card;
60 struct ct_atc *atc;
61 int err;
62
63 if (dev >= SNDRV_CARDS)
64 return -ENODEV;
65
66 if (!enable[dev]) {
67 dev++;
68 return -ENOENT;
69 }
70 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
71 if (err)
72 return err;
73 if ((reference_rate != 48000) && (reference_rate != 44100)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020074 printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
75 reference_rate);
76 printk(KERN_ERR "ctxfi: The valid values for reference_rate "
77 "are 48000 and 44100, Value 48000 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020078 reference_rate = 48000;
79 }
80 if ((multiple != 1) && (multiple != 2)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020081 printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
82 multiple);
83 printk(KERN_ERR "ctxfi: The valid values for multiple are "
84 "1 and 2, Value 2 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020085 multiple = 2;
86 }
Takashi Iwai94701952009-06-08 18:10:32 +020087 err = ct_atc_create(card, pci, reference_rate, multiple,
88 pci_id->driver_data, &atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020089 if (err < 0)
90 goto error;
91
92 card->private_data = atc;
93
94 /* Create alsa devices supported by this card */
Takashi Iwai2a36f672009-06-05 16:34:10 +020095 err = ct_atc_create_alsa_devs(atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020096 if (err < 0)
97 goto error;
98
99 strcpy(card->driver, "SB-XFi");
100 strcpy(card->shortname, "Creative X-Fi");
Takashi Iwai94701952009-06-08 18:10:32 +0200101 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
102 card->shortname, atc->chip_name, atc->model_name);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200103
104 err = snd_card_register(card);
105 if (err < 0)
106 goto error;
107
108 pci_set_drvdata(pci, card);
109 dev++;
110
111 return 0;
112
113error:
114 snd_card_free(card);
115 return err;
116}
117
118static void __devexit ct_card_remove(struct pci_dev *pci)
119{
120 snd_card_free(pci_get_drvdata(pci));
121 pci_set_drvdata(pci, NULL);
122}
123
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200124#ifdef CONFIG_PM
125static int ct_card_suspend(struct pci_dev *pci, pm_message_t state)
126{
127 struct snd_card *card = pci_get_drvdata(pci);
128 struct ct_atc *atc = card->private_data;
129
130 return atc->suspend(atc, state);
131}
132
133static int ct_card_resume(struct pci_dev *pci)
134{
135 struct snd_card *card = pci_get_drvdata(pci);
136 struct ct_atc *atc = card->private_data;
137
138 return atc->resume(atc);
139}
140#endif
141
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200142static struct pci_driver ct_driver = {
143 .name = "SB-XFi",
144 .id_table = ct_pci_dev_ids,
145 .probe = ct_card_probe,
146 .remove = __devexit_p(ct_card_remove),
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200147#ifdef CONFIG_PM
148 .suspend = ct_card_suspend,
149 .resume = ct_card_resume,
150#endif
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200151};
152
153static int __init ct_card_init(void)
154{
155 return pci_register_driver(&ct_driver);
156}
157
158static void __exit ct_card_exit(void)
159{
160 pci_unregister_driver(&ct_driver);
161}
162
163module_init(ct_card_init)
164module_exit(ct_card_exit)