blob: 19310ed26e88852fd6b9229c8423c2562372c416 [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"
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020018
19MODULE_AUTHOR("Creative Technology Ltd");
20MODULE_DESCRIPTION("X-Fi driver version 1.03");
21MODULE_LICENSE("GPLv2");
22MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
23
24static unsigned int reference_rate = 48000;
25static unsigned int multiple = 2;
26module_param(reference_rate, uint, S_IRUGO);
27module_param(multiple, uint, S_IRUGO);
28
29static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
30static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
31static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
32
33static struct pci_device_id ct_pci_dev_ids[] = {
34 /* only X-Fi is supported, so... */
Takashi Iwai9fc20f02009-05-14 15:14:18 +020035 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1) },
36 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2) },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020037 { 0, }
38};
39MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
40
41static int __devinit
42ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
43{
44 static int dev;
45 struct snd_card *card;
46 struct ct_atc *atc;
47 int err;
48
49 if (dev >= SNDRV_CARDS)
50 return -ENODEV;
51
52 if (!enable[dev]) {
53 dev++;
54 return -ENOENT;
55 }
56 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
57 if (err)
58 return err;
59 if ((reference_rate != 48000) && (reference_rate != 44100)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020060 printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
61 reference_rate);
62 printk(KERN_ERR "ctxfi: The valid values for reference_rate "
63 "are 48000 and 44100, Value 48000 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020064 reference_rate = 48000;
65 }
66 if ((multiple != 1) && (multiple != 2)) {
Takashi Iwaib3e0afe2009-05-14 15:19:30 +020067 printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
68 multiple);
69 printk(KERN_ERR "ctxfi: The valid values for multiple are "
70 "1 and 2, Value 2 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020071 multiple = 2;
72 }
73 err = ct_atc_create(card, pci, reference_rate, multiple, &atc);
74 if (err < 0)
75 goto error;
76
77 card->private_data = atc;
78
79 /* Create alsa devices supported by this card */
80 err = atc->create_alsa_devs(atc);
81 if (err < 0)
82 goto error;
83
84 strcpy(card->driver, "SB-XFi");
85 strcpy(card->shortname, "Creative X-Fi");
86 strcpy(card->longname, "Creative ALSA Driver X-Fi");
87
88 err = snd_card_register(card);
89 if (err < 0)
90 goto error;
91
92 pci_set_drvdata(pci, card);
93 dev++;
94
95 return 0;
96
97error:
98 snd_card_free(card);
99 return err;
100}
101
102static void __devexit ct_card_remove(struct pci_dev *pci)
103{
104 snd_card_free(pci_get_drvdata(pci));
105 pci_set_drvdata(pci, NULL);
106}
107
108static struct pci_driver ct_driver = {
109 .name = "SB-XFi",
110 .id_table = ct_pci_dev_ids,
111 .probe = ct_card_probe,
112 .remove = __devexit_p(ct_card_remove),
113};
114
115static int __init ct_card_init(void)
116{
117 return pci_register_driver(&ct_driver);
118}
119
120static void __exit ct_card_exit(void)
121{
122 pci_unregister_driver(&ct_driver);
123}
124
125module_init(ct_card_init)
126module_exit(ct_card_exit)