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"); |
| 21 | MODULE_LICENSE("GPLv2"); |
| 22 | MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}"); |
| 23 | |
| 24 | static unsigned int reference_rate = 48000; |
| 25 | static unsigned int multiple = 2; |
| 26 | module_param(reference_rate, uint, S_IRUGO); |
| 27 | module_param(multiple, uint, S_IRUGO); |
| 28 | |
| 29 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 30 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
| 31 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
| 32 | |
| 33 | static struct pci_device_id ct_pci_dev_ids[] = { |
| 34 | /* only X-Fi is supported, so... */ |
Takashi Iwai | 9fc20f0 | 2009-05-14 15:14:18 +0200 | [diff] [blame] | 35 | { 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 CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 37 | { 0, } |
| 38 | }; |
| 39 | MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids); |
| 40 | |
| 41 | static int __devinit |
| 42 | ct_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 Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 60 | 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 CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 64 | reference_rate = 48000; |
| 65 | } |
| 66 | if ((multiple != 1) && (multiple != 2)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 67 | 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 CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 71 | 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 | |
| 97 | error: |
| 98 | snd_card_free(card); |
| 99 | return err; |
| 100 | } |
| 101 | |
| 102 | static 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 | |
| 108 | static 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 | |
| 115 | static int __init ct_card_init(void) |
| 116 | { |
| 117 | return pci_register_driver(&ct_driver); |
| 118 | } |
| 119 | |
| 120 | static void __exit ct_card_exit(void) |
| 121 | { |
| 122 | pci_unregister_driver(&ct_driver); |
| 123 | } |
| 124 | |
| 125 | module_init(ct_card_init) |
| 126 | module_exit(ct_card_exit) |