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> |
Paul Gortmaker | da155d5 | 2011-07-15 12:38:28 -0400 | [diff] [blame] | 15 | #include <linux/module.h> |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 16 | #include <sound/core.h> |
| 17 | #include <sound/initval.h> |
| 18 | #include "ctatc.h" |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 19 | #include "cthardware.h" |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 20 | |
| 21 | MODULE_AUTHOR("Creative Technology Ltd"); |
| 22 | MODULE_DESCRIPTION("X-Fi driver version 1.03"); |
Takashi Iwai | 67fbf88 | 2009-06-02 09:18:26 +0200 | [diff] [blame] | 23 | MODULE_LICENSE("GPL v2"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 24 | MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}"); |
| 25 | |
| 26 | static unsigned int reference_rate = 48000; |
| 27 | static unsigned int multiple = 2; |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 28 | MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 29 | module_param(reference_rate, uint, S_IRUGO); |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 30 | MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 31 | module_param(multiple, uint, S_IRUGO); |
| 32 | |
| 33 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; |
| 34 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 35 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 36 | static unsigned int subsystem[SNDRV_CARDS]; |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 37 | |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 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"); |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 44 | module_param_array(subsystem, int, NULL, 0444); |
| 45 | MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver"); |
Takashi Iwai | aae80dc | 2009-05-26 18:35:27 +0200 | [diff] [blame] | 46 | |
Alexey Dobriyan | cebe41d | 2010-02-06 00:21:03 +0200 | [diff] [blame] | 47 | static DEFINE_PCI_DEVICE_TABLE(ct_pci_dev_ids) = { |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 48 | /* only X-Fi is supported, so... */ |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 49 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1), |
| 50 | .driver_data = ATC20K1, |
| 51 | }, |
| 52 | { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2), |
| 53 | .driver_data = ATC20K2, |
| 54 | }, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 55 | { 0, } |
| 56 | }; |
| 57 | MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids); |
| 58 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 59 | static int |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 60 | ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) |
| 61 | { |
| 62 | static int dev; |
| 63 | struct snd_card *card; |
| 64 | struct ct_atc *atc; |
| 65 | int err; |
| 66 | |
| 67 | if (dev >= SNDRV_CARDS) |
| 68 | return -ENODEV; |
| 69 | |
| 70 | if (!enable[dev]) { |
| 71 | dev++; |
| 72 | return -ENOENT; |
| 73 | } |
| 74 | err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); |
| 75 | if (err) |
| 76 | return err; |
| 77 | if ((reference_rate != 48000) && (reference_rate != 44100)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 78 | printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n", |
| 79 | reference_rate); |
| 80 | printk(KERN_ERR "ctxfi: The valid values for reference_rate " |
| 81 | "are 48000 and 44100, Value 48000 is assumed.\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 82 | reference_rate = 48000; |
| 83 | } |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 84 | if ((multiple != 1) && (multiple != 2) && (multiple != 4)) { |
Takashi Iwai | b3e0afe | 2009-05-14 15:19:30 +0200 | [diff] [blame] | 85 | printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n", |
| 86 | multiple); |
| 87 | printk(KERN_ERR "ctxfi: The valid values for multiple are " |
Harry Butterworth | 5530921 | 2011-06-11 16:02:06 +0800 | [diff] [blame] | 88 | "1, 2 and 4, Value 2 is assumed.\n"); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 89 | multiple = 2; |
| 90 | } |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 91 | err = ct_atc_create(card, pci, reference_rate, multiple, |
Takashi Iwai | 408bffd | 2010-01-14 09:19:46 +0100 | [diff] [blame] | 92 | pci_id->driver_data, subsystem[dev], &atc); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 93 | if (err < 0) |
| 94 | goto error; |
| 95 | |
| 96 | card->private_data = atc; |
| 97 | |
| 98 | /* Create alsa devices supported by this card */ |
Takashi Iwai | 2a36f67 | 2009-06-05 16:34:10 +0200 | [diff] [blame] | 99 | err = ct_atc_create_alsa_devs(atc); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 100 | if (err < 0) |
| 101 | goto error; |
| 102 | |
| 103 | strcpy(card->driver, "SB-XFi"); |
| 104 | strcpy(card->shortname, "Creative X-Fi"); |
Takashi Iwai | 9470195 | 2009-06-08 18:10:32 +0200 | [diff] [blame] | 105 | snprintf(card->longname, sizeof(card->longname), "%s %s %s", |
| 106 | card->shortname, atc->chip_name, atc->model_name); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 107 | |
| 108 | err = snd_card_register(card); |
| 109 | if (err < 0) |
| 110 | goto error; |
| 111 | |
| 112 | pci_set_drvdata(pci, card); |
| 113 | dev++; |
| 114 | |
| 115 | return 0; |
| 116 | |
| 117 | error: |
| 118 | snd_card_free(card); |
| 119 | return err; |
| 120 | } |
| 121 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 122 | static void ct_card_remove(struct pci_dev *pci) |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 123 | { |
| 124 | snd_card_free(pci_get_drvdata(pci)); |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 125 | } |
| 126 | |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 127 | #ifdef CONFIG_PM_SLEEP |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 128 | static int ct_card_suspend(struct device *dev) |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 129 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 130 | struct snd_card *card = dev_get_drvdata(dev); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 131 | struct ct_atc *atc = card->private_data; |
| 132 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 133 | return atc->suspend(atc); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 134 | } |
| 135 | |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 136 | static int ct_card_resume(struct device *dev) |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 137 | { |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 138 | struct snd_card *card = dev_get_drvdata(dev); |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 139 | struct ct_atc *atc = card->private_data; |
| 140 | |
| 141 | return atc->resume(atc); |
| 142 | } |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 143 | |
| 144 | static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume); |
| 145 | #define CT_CARD_PM_OPS &ct_card_pm |
| 146 | #else |
| 147 | #define CT_CARD_PM_OPS NULL |
Wai Yew CHAY | 29959a0 | 2009-06-22 14:52:34 +0200 | [diff] [blame] | 148 | #endif |
| 149 | |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 150 | static struct pci_driver ct_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 151 | .name = KBUILD_MODNAME, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 152 | .id_table = ct_pci_dev_ids, |
| 153 | .probe = ct_card_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 154 | .remove = ct_card_remove, |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 155 | .driver = { |
| 156 | .pm = CT_CARD_PM_OPS, |
| 157 | }, |
Wai Yew CHAY | 8cc7236 | 2009-05-14 08:05:58 +0200 | [diff] [blame] | 158 | }; |
| 159 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 160 | module_pci_driver(ct_driver); |