blob: 8c07c6463c246f72e4e8eaa59f7dbb910c347169 [file] [log] [blame]
Thomas Gleixner5765e782019-05-31 01:09:25 -07001// SPDX-License-Identifier: GPL-2.0-only
Wai Yew CHAY8cc72362009-05-14 08:05:58 +02002/*
3 * xfi linux driver.
4 *
5 * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved.
Wai Yew CHAY8cc72362009-05-14 08:05:58 +02006 */
7
8#include <linux/init.h>
9#include <linux/pci.h>
10#include <linux/moduleparam.h>
Takashi Iwai9fc20f02009-05-14 15:14:18 +020011#include <linux/pci_ids.h>
Paul Gortmakerda155d52011-07-15 12:38:28 -040012#include <linux/module.h>
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020013#include <sound/core.h>
14#include <sound/initval.h>
15#include "ctatc.h"
Takashi Iwai94701952009-06-08 18:10:32 +020016#include "cthardware.h"
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020017
18MODULE_AUTHOR("Creative Technology Ltd");
19MODULE_DESCRIPTION("X-Fi driver version 1.03");
Takashi Iwai67fbf882009-06-02 09:18:26 +020020MODULE_LICENSE("GPL v2");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020021MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
22
23static unsigned int reference_rate = 48000;
24static unsigned int multiple = 2;
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020025MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
Joe Perches6a73cf42018-05-23 12:20:59 -070026module_param(reference_rate, uint, 0444);
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020027MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
Joe Perches6a73cf42018-05-23 12:20:59 -070028module_param(multiple, uint, 0444);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020029
30static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
31static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
Rusty Russella67ff6a2011-12-15 13:49:36 +103032static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
Takashi Iwai408bffd2010-01-14 09:19:46 +010033static unsigned int subsystem[SNDRV_CARDS];
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020034
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020035module_param_array(index, int, NULL, 0444);
36MODULE_PARM_DESC(index, "Index value for Creative X-Fi driver");
37module_param_array(id, charp, NULL, 0444);
38MODULE_PARM_DESC(id, "ID string for Creative X-Fi driver");
39module_param_array(enable, bool, NULL, 0444);
40MODULE_PARM_DESC(enable, "Enable Creative X-Fi driver");
Takashi Iwai408bffd2010-01-14 09:19:46 +010041module_param_array(subsystem, int, NULL, 0444);
42MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
Takashi Iwaiaae80dc2009-05-26 18:35:27 +020043
Benoit Taine9baa3c32014-08-08 15:56:03 +020044static const struct pci_device_id ct_pci_dev_ids[] = {
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020045 /* only X-Fi is supported, so... */
Takashi Iwai94701952009-06-08 18:10:32 +020046 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K1),
47 .driver_data = ATC20K1,
48 },
49 { PCI_DEVICE(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2),
50 .driver_data = ATC20K2,
51 },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020052 { 0, }
53};
54MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
55
Bill Pembertone23e7a12012-12-06 12:35:10 -050056static int
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020057ct_card_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
58{
59 static int dev;
60 struct snd_card *card;
61 struct ct_atc *atc;
62 int err;
63
64 if (dev >= SNDRV_CARDS)
65 return -ENODEV;
66
67 if (!enable[dev]) {
68 dev++;
69 return -ENOENT;
70 }
Takashi Iwai60c57722014-01-29 14:20:19 +010071 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
72 0, &card);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020073 if (err)
74 return err;
75 if ((reference_rate != 48000) && (reference_rate != 44100)) {
Sudip Mukherjee0cae90a2014-09-29 14:33:26 +053076 dev_err(card->dev,
77 "Invalid reference_rate value %u!!!\n",
78 reference_rate);
79 dev_err(card->dev,
80 "The valid values for reference_rate are 48000 and 44100, Value 48000 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020081 reference_rate = 48000;
82 }
Harry Butterworth55309212011-06-11 16:02:06 +080083 if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
Sudip Mukherjee0cae90a2014-09-29 14:33:26 +053084 dev_err(card->dev, "Invalid multiple value %u!!!\n",
85 multiple);
86 dev_err(card->dev,
87 "The valid values for multiple are 1, 2 and 4, Value 2 is assumed.\n");
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020088 multiple = 2;
89 }
Takashi Iwai94701952009-06-08 18:10:32 +020090 err = ct_atc_create(card, pci, reference_rate, multiple,
Takashi Iwai408bffd2010-01-14 09:19:46 +010091 pci_id->driver_data, subsystem[dev], &atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020092 if (err < 0)
93 goto error;
94
95 card->private_data = atc;
96
97 /* Create alsa devices supported by this card */
Takashi Iwai2a36f672009-06-05 16:34:10 +020098 err = ct_atc_create_alsa_devs(atc);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +020099 if (err < 0)
100 goto error;
101
102 strcpy(card->driver, "SB-XFi");
103 strcpy(card->shortname, "Creative X-Fi");
Takashi Iwai94701952009-06-08 18:10:32 +0200104 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
105 card->shortname, atc->chip_name, atc->model_name);
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200106
107 err = snd_card_register(card);
108 if (err < 0)
109 goto error;
110
111 pci_set_drvdata(pci, card);
112 dev++;
113
114 return 0;
115
116error:
117 snd_card_free(card);
118 return err;
119}
120
Bill Pembertone23e7a12012-12-06 12:35:10 -0500121static void ct_card_remove(struct pci_dev *pci)
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200122{
123 snd_card_free(pci_get_drvdata(pci));
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200124}
125
Takashi Iwaic7561cd2012-08-14 18:12:04 +0200126#ifdef CONFIG_PM_SLEEP
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200127static int ct_card_suspend(struct device *dev)
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200128{
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200129 struct snd_card *card = dev_get_drvdata(dev);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200130 struct ct_atc *atc = card->private_data;
131
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200132 return atc->suspend(atc);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200133}
134
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200135static int ct_card_resume(struct device *dev)
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200136{
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200137 struct snd_card *card = dev_get_drvdata(dev);
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200138 struct ct_atc *atc = card->private_data;
139
140 return atc->resume(atc);
141}
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200142
143static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
144#define CT_CARD_PM_OPS &ct_card_pm
145#else
146#define CT_CARD_PM_OPS NULL
Wai Yew CHAY29959a02009-06-22 14:52:34 +0200147#endif
148
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200149static struct pci_driver ct_driver = {
Takashi Iwai3733e422011-06-10 16:20:20 +0200150 .name = KBUILD_MODNAME,
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200151 .id_table = ct_pci_dev_ids,
152 .probe = ct_card_probe,
Bill Pembertone23e7a12012-12-06 12:35:10 -0500153 .remove = ct_card_remove,
Takashi Iwai68cb2b52012-07-02 15:20:37 +0200154 .driver = {
155 .pm = CT_CARD_PM_OPS,
156 },
Wai Yew CHAY8cc72362009-05-14 08:05:58 +0200157};
158
Takashi Iwaie9f66d92012-04-24 12:25:00 +0200159module_pci_driver(ct_driver);