Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 1 | /* |
| 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 Iwai | 9fc20f0 | 2009-05-14 15:14:18 +0200 | [diff] [blame] | 14 | #include <linux/pci_ids.h> |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 15 | #include <sound/core.h> |
| 16 | #include <sound/initval.h> |
| 17 | #include "ctatc.h" |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 18 | |
| 19 | MODULE_AUTHOR("Creative Technology Ltd"); |
| 20 | MODULE_DESCRIPTION("X-Fi driver version 1.03"); |
Takashi Iwai | 67fbf88 | 2009-06-02 09:18:26 +0200 | [diff] [blame^] | 21 | MODULE_LICENSE("GPL v2"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 22 | MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}"); |
| 23 | |
| 24 | static unsigned int reference_rate = 48000; |
| 25 | static unsigned int multiple = 2; |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 26 | MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 27 | module_param(reference_rate, uint, S_IRUGO); |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 28 | MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 29 | module_param(multiple, uint, S_IRUGO); |
| 30 | |
| 31 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 32 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
| 33 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
| 34 | |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 35 | module_param_array(index, int, NULL, 0444); |
| 36 | MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver"); |
| 37 | module_param_array(id, charp, NULL, 0444); |
| 38 | MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver"); |
| 39 | module_param_array(enable, bool, NULL, 0444); |
| 40 | MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver"); |
| 41 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 42 | static struct pci_device_id ct_pci_dev_ids[] = { |
| 43 | /* only X-Fi is supported, so... */ |
Takashi Iwai | 9fc20f0 | 2009-05-14 15:14:18 +0200 | [diff] [blame] | 44 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1) }, |
| 45 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2) }, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 46 | { 0, } |
| 47 | }; |
| 48 | MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids); |
| 49 | |
| 50 | static int __devinit |
| 51 | ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) |
| 52 | { |
| 53 | static int dev; |
| 54 | struct snd_card *card; |
| 55 | struct ct_atc *atc; |
| 56 | int err; |
| 57 | |
| 58 | if (dev >= SNDRV_CARDS) |
| 59 | return -ENODEV; |
| 60 | |
| 61 | if (!enable[dev]) { |
| 62 | dev++; |
| 63 | return -ENOENT; |
| 64 | } |
| 65 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); |
| 66 | if (err) |
| 67 | return err; |
| 68 | if ((reference_rate != 48000) && (reference_rate != 44100)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 69 | printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n", |
| 70 | reference_rate); |
| 71 | printk(KERN_ERR "ctxfi: The valid values for reference_rate " |
| 72 | "are 48000 and 44100, Value 48000 is assumed.\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 73 | reference_rate = 48000; |
| 74 | } |
| 75 | if ((multiple != 1) && (multiple != 2)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 76 | printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n", |
| 77 | multiple); |
| 78 | printk(KERN_ERR "ctxfi: The valid values for multiple are " |
| 79 | "1 and 2, Value 2 is assumed.\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 80 | multiple = 2; |
| 81 | } |
| 82 | err = ct_atc_create(card, pci, reference_rate, multiple, &atc); |
| 83 | if (err < 0) |
| 84 | goto error; |
| 85 | |
| 86 | card->private_data = atc; |
| 87 | |
| 88 | /* Create alsa devices supported by this card */ |
| 89 | err = atc->create_alsa_devs(atc); |
| 90 | if (err < 0) |
| 91 | goto error; |
| 92 | |
| 93 | strcpy(card->driver, "SB-XFi"); |
| 94 | strcpy(card->shortname, "Creative X-Fi"); |
| 95 | strcpy(card->longname, "Creative ALSA Driver X-Fi"); |
| 96 | |
| 97 | err = snd_card_register(card); |
| 98 | if (err < 0) |
| 99 | goto error; |
| 100 | |
| 101 | pci_set_drvdata(pci, card); |
| 102 | dev++; |
| 103 | |
| 104 | return 0; |
| 105 | |
| 106 | error: |
| 107 | snd_card_free(card); |
| 108 | return err; |
| 109 | } |
| 110 | |
| 111 | static void __devexit ct_card_remove(struct pci_dev *pci) |
| 112 | { |
| 113 | snd_card_free(pci_get_drvdata(pci)); |
| 114 | pci_set_drvdata(pci, NULL); |
| 115 | } |
| 116 | |
| 117 | static struct pci_driver ct_driver = { |
| 118 | .name = "SB-XFi", |
| 119 | .id_table = ct_pci_dev_ids, |
| 120 | .probe = ct_card_probe, |
| 121 | .remove = __devexit_p(ct_card_remove), |
| 122 | }; |
| 123 | |
| 124 | static int __init ct_card_init(void) |
| 125 | { |
| 126 | return pci_register_driver(&ct_driver); |
| 127 | } |
| 128 | |
| 129 | static void __exit ct_card_exit(void) |
| 130 | { |
| 131 | pci_unregister_driver(&ct_driver); |
| 132 | } |
| 133 | |
| 134 | module_init(ct_card_init) |
| 135 | module_exit(ct_card_exit) |