blob: f2f32779de986ff9d50b6853f024113d79ef9752 [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>
Paul Gortmakerda155d52011-07-15 12:38:28 -040015#include <linux/module.h>
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020016#include <sound/core.h>
17#include <sound/initval.h>
18#include "ctatc.h"
Takashi Iwai94701952009-06-08 18:10:32 +020019#include "cthardware.h"
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020020
21MODULE_AUTHOR("Creative Technology Ltd");
22MODULE_DESCRIPTION("X-Fi driver version 1.03");
Takashi Iwai67fbf882009-06-02 09:18:26 +020023MODULE_LICENSE("GPL v2");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020024MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
25
26static unsigned int reference_rate = 48000;
27static unsigned int multiple = 2;
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020028MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020029module_param(reference_rate, uint, S_IRUGO);
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020030MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020031module_param(multiple, uint, S_IRUGO);
32
33static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
34static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103035static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Iwai408bffd2010-01-14 09:19:46 +010036static unsigned int subsystem[SNDRV_CARDS];
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020037
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020038module_param_array(index, int, NULL, 0444);
39MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
40module_param_array(id, charp, NULL, 0444);
41MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
42module_param_array(enable, bool, NULL, 0444);
43MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
Takashi Iwai408bffd2010-01-14 09:19:46 +010044module_param_array(subsystem, int, NULL, 0444);
45MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020046
Benoit Taine9baa3c32014-08-08 15:56:03 +020047static const struct pci_device_id ct_pci_dev_ids[] = {
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020048 /* only X-Fi is supported, so... */
Takashi Iwai94701952009-06-08 18:10:32 +020049 { 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 CHAY8cc72362009-05-14 08:05:58 +020055 { 0, }
56};
57MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
58
Bill Pembertone23e7a12012-12-06 12:35:10 -050059static int
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020060ct_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 }
Takashi Iwai60c57722014-01-29 14:20:19 +010074 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
75 0, &card);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020076 if (err)
77 return err;
78 if ((reference_rate != 48000) && (reference_rate != 44100)) {
Sudip Mukherjee0cae90a2014-09-29 14:33:26 +053079 dev_err(card->dev,
80 "Invalid reference_rate value %u!!!\n",
81 reference_rate);
82 dev_err(card->dev,
83 "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020084 reference_rate = 48000;
85 }
Harry Butterworth55309212011-06-11 16:02:06 +080086 if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
Sudip Mukherjee0cae90a2014-09-29 14:33:26 +053087 dev_err(card->dev, "Invalid multiple value %u!!!\n",
88 multiple);
89 dev_err(card->dev,
90 "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020091 multiple = 2;
92 }
Takashi Iwai94701952009-06-08 18:10:32 +020093 err = ct_atc_create(card, pci, reference_rate, multiple,
Takashi Iwai408bffd2010-01-14 09:19:46 +010094 pci_id->driver_data, subsystem[dev], &atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020095 if (err < 0)
96 goto error;
97
98 card->private_data = atc;
99
100 /* Create alsa devices supported by this card */
Takashi Iwai2a36f672009-06-05 16:34:10 +0200101 err = ct_atc_create_alsa_devs(atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200102 if (err < 0)
103 goto error;
104
105 strcpy(card->driver, "SB-XFi");
106 strcpy(card->shortname, "Creative X-Fi");
Takashi Iwai94701952009-06-08 18:10:32 +0200107 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
108 card->shortname, atc->chip_name, atc->model_name);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200109
110 err = snd_card_register(card);
111 if (err < 0)
112 goto error;
113
114 pci_set_drvdata(pci, card);
115 dev++;
116
117 return 0;
118
119error:
120 snd_card_free(card);
121 return err;
122}
123
Bill Pembertone23e7a12012-12-06 12:35:10 -0500124static void ct_card_remove(struct pci_dev *pci)
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200125{
126 snd_card_free(pci_get_drvdata(pci));
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200127}
128
Takashi Iwaic7561cd2012-08-14 18:12:04 +0200129#ifdef CONFIG_PM_SLEEP
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200130static int ct_card_suspend(struct device *dev)
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200131{
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200132 struct snd_card *card = dev_get_drvdata(dev);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200133 struct ct_atc *atc = card->private_data;
134
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200135 return atc->suspend(atc);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200136}
137
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200138static int ct_card_resume(struct device *dev)
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200139{
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200140 struct snd_card *card = dev_get_drvdata(dev);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200141 struct ct_atc *atc = card->private_data;
142
143 return atc->resume(atc);
144}
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200145
146static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
147#define CT_CARD_PM_OPS &ct_card_pm
148#else
149#define CT_CARD_PM_OPS NULL
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200150#endif
151
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200152static struct pci_driver ct_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +0200153 .name = KBUILD_MODNAME,
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200154 .id_table = ct_pci_dev_ids,
155 .probe = ct_card_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -0500156 .remove = ct_card_remove,
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200157 .driver = {
158 .pm = CT_CARD_PM_OPS,
159 },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200160};
161
Takashi Iwaie9f66d92012-04-24 12:25:00 +0200162module_pci_driver(ct_driver);