4 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
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.
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>
19 #include "cthardware.h"
21 MODULE_AUTHOR("Creative Technology Ltd");
22 MODULE_DESCRIPTION("X-Fi driver version 1.03");
23 MODULE_LICENSE("GPL v2");
24 MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
26 static unsigned int reference_rate
= 48000;
27 static unsigned int multiple
= 2;
28 MODULE_PARM_DESC(reference_rate
, "Reference rate (default=48000)");
29 module_param(reference_rate
, uint
, S_IRUGO
);
30 MODULE_PARM_DESC(multiple
, "Rate multiplier (default=2)");
31 module_param(multiple
, uint
, S_IRUGO
);
33 static int index
[SNDRV_CARDS
] = SNDRV_DEFAULT_IDX
;
34 static char *id
[SNDRV_CARDS
] = SNDRV_DEFAULT_STR
;
35 static int enable
[SNDRV_CARDS
] = SNDRV_DEFAULT_ENABLE_PNP
;
36 static unsigned int subsystem
[SNDRV_CARDS
];
38 module_param_array(index
, int, NULL
, 0444);
39 MODULE_PARM_DESC(index
, "Index value for Creative X-Fi driver");
40 module_param_array(id
, charp
, NULL
, 0444);
41 MODULE_PARM_DESC(id
, "ID string for Creative X-Fi driver");
42 module_param_array(enable
, bool, NULL
, 0444);
43 MODULE_PARM_DESC(enable
, "Enable Creative X-Fi driver");
44 module_param_array(subsystem
, int, NULL
, 0444);
45 MODULE_PARM_DESC(subsystem
, "Override subsystem ID for Creative X-Fi driver");
47 static DEFINE_PCI_DEVICE_TABLE(ct_pci_dev_ids
) = {
48 /* only X-Fi is supported, so... */
49 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE
, PCI_DEVICE_ID_CREATIVE_20K1
),
50 .driver_data
= ATC20K1
,
52 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE
, PCI_DEVICE_ID_CREATIVE_20K2
),
53 .driver_data
= ATC20K2
,
57 MODULE_DEVICE_TABLE(pci
, ct_pci_dev_ids
);
60 ct_card_probe(struct pci_dev
*pci
, const struct pci_device_id
*pci_id
)
63 struct snd_card
*card
;
67 if (dev
>= SNDRV_CARDS
)
74 err
= snd_card_create(index
[dev
], id
[dev
], THIS_MODULE
, 0, &card
);
77 if ((reference_rate
!= 48000) && (reference_rate
!= 44100)) {
78 printk(KERN_ERR
"ctxfi: Invalid reference_rate value %u!!!\n",
80 printk(KERN_ERR
"ctxfi: The valid values for reference_rate "
81 "are 48000 and 44100, Value 48000 is assumed.\n");
82 reference_rate
= 48000;
84 if ((multiple
!= 1) && (multiple
!= 2) && (multiple
!= 4)) {
85 printk(KERN_ERR
"ctxfi: Invalid multiple value %u!!!\n",
87 printk(KERN_ERR
"ctxfi: The valid values for multiple are "
88 "1, 2 and 4, Value 2 is assumed.\n");
91 err
= ct_atc_create(card
, pci
, reference_rate
, multiple
,
92 pci_id
->driver_data
, subsystem
[dev
], &atc
);
96 card
->private_data
= atc
;
98 /* Create alsa devices supported by this card */
99 err
= ct_atc_create_alsa_devs(atc
);
103 strcpy(card
->driver
, "SB-XFi");
104 strcpy(card
->shortname
, "Creative X-Fi");
105 snprintf(card
->longname
, sizeof(card
->longname
), "%s %s %s",
106 card
->shortname
, atc
->chip_name
, atc
->model_name
);
108 err
= snd_card_register(card
);
112 pci_set_drvdata(pci
, card
);
122 static void __devexit
ct_card_remove(struct pci_dev
*pci
)
124 snd_card_free(pci_get_drvdata(pci
));
125 pci_set_drvdata(pci
, NULL
);
129 static int ct_card_suspend(struct pci_dev
*pci
, pm_message_t state
)
131 struct snd_card
*card
= pci_get_drvdata(pci
);
132 struct ct_atc
*atc
= card
->private_data
;
134 return atc
->suspend(atc
, state
);
137 static int ct_card_resume(struct pci_dev
*pci
)
139 struct snd_card
*card
= pci_get_drvdata(pci
);
140 struct ct_atc
*atc
= card
->private_data
;
142 return atc
->resume(atc
);
146 static struct pci_driver ct_driver
= {
147 .name
= KBUILD_MODNAME
,
148 .id_table
= ct_pci_dev_ids
,
149 .probe
= ct_card_probe
,
150 .remove
= __devexit_p(ct_card_remove
),
152 .suspend
= ct_card_suspend
,
153 .resume
= ct_card_resume
,
157 static int __init
ct_card_init(void)
159 return pci_register_driver(&ct_driver
);
162 static void __exit
ct_card_exit(void)
164 pci_unregister_driver(&ct_driver
);
167 module_init(ct_card_init
)
168 module_exit(ct_card_exit
)