]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - sound/pci/ctxfi/xfi.c
ALSA: pci: Convert to snd_card_new() with a device pointer
[mirror_ubuntu-bionic-kernel.git] / sound / pci / ctxfi / xfi.c
CommitLineData
8cc72361
WYC
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>
9fc20f03 14#include <linux/pci_ids.h>
da155d5b 15#include <linux/module.h>
8cc72361
WYC
16#include <sound/core.h>
17#include <sound/initval.h>
18#include "ctatc.h"
9470195a 19#include "cthardware.h"
8cc72361
WYC
20
21MODULE_AUTHOR("Creative Technology Ltd");
22MODULE_DESCRIPTION("X-Fi driver version 1.03");
67fbf880 23MODULE_LICENSE("GPL v2");
8cc72361
WYC
24MODULE_SUPPORTED_DEVICE("{{Creative Labs, Sound Blaster X-Fi}");
25
26static unsigned int reference_rate = 48000;
27static unsigned int multiple = 2;
aae80dc2 28MODULE_PARM_DESC(reference_rate, "Reference rate (default=48000)");
8cc72361 29module_param(reference_rate, uint, S_IRUGO);
aae80dc2 30MODULE_PARM_DESC(multiple, "Rate multiplier (default=2)");
8cc72361
WYC
31module_param(multiple, uint, S_IRUGO);
32
33static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
34static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
a67ff6a5 35static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
408bffd0 36static unsigned int subsystem[SNDRV_CARDS];
8cc72361 37
aae80dc2
TI
38module_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");
408bffd0
TI
44module_param_array(subsystem, int, NULL, 0444);
45MODULE_PARM_DESC(subsystem, "Override subsystem ID for Creative X-Fi driver");
aae80dc2 46
cebe41d4 47static DEFINE_PCI_DEVICE_TABLE(ct_pci_dev_ids) = {
8cc72361 48 /* only X-Fi is supported, so... */
9470195a
TI
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 },
8cc72361
WYC
55 { 0, }
56};
57MODULE_DEVICE_TABLE(pci, ct_pci_dev_ids);
58
e23e7a14 59static int
8cc72361
WYC
60ct_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 }
60c5772b
TI
74 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
75 0, &card);
8cc72361
WYC
76 if (err)
77 return err;
78 if ((reference_rate != 48000) && (reference_rate != 44100)) {
b3e0afe6
TI
79 printk(KERN_ERR "ctxfi: Invalid reference_rate value %u!!!\n",
80 reference_rate);
81 printk(KERN_ERR "ctxfi: The valid values for reference_rate "
82 "are 48000 and 44100, Value 48000 is assumed.\n");
8cc72361
WYC
83 reference_rate = 48000;
84 }
55309216 85 if ((multiple != 1) && (multiple != 2) && (multiple != 4)) {
b3e0afe6
TI
86 printk(KERN_ERR "ctxfi: Invalid multiple value %u!!!\n",
87 multiple);
88 printk(KERN_ERR "ctxfi: The valid values for multiple are "
55309216 89 "1, 2 and 4, Value 2 is assumed.\n");
8cc72361
WYC
90 multiple = 2;
91 }
9470195a 92 err = ct_atc_create(card, pci, reference_rate, multiple,
408bffd0 93 pci_id->driver_data, subsystem[dev], &atc);
8cc72361
WYC
94 if (err < 0)
95 goto error;
96
97 card->private_data = atc;
98
99 /* Create alsa devices supported by this card */
2a36f67f 100 err = ct_atc_create_alsa_devs(atc);
8cc72361
WYC
101 if (err < 0)
102 goto error;
103
104 strcpy(card->driver, "SB-XFi");
105 strcpy(card->shortname, "Creative X-Fi");
9470195a
TI
106 snprintf(card->longname, sizeof(card->longname), "%s %s %s",
107 card->shortname, atc->chip_name, atc->model_name);
8cc72361
WYC
108
109 err = snd_card_register(card);
110 if (err < 0)
111 goto error;
112
113 pci_set_drvdata(pci, card);
114 dev++;
115
116 return 0;
117
118error:
119 snd_card_free(card);
120 return err;
121}
122
e23e7a14 123static void ct_card_remove(struct pci_dev *pci)
8cc72361
WYC
124{
125 snd_card_free(pci_get_drvdata(pci));
8cc72361
WYC
126}
127
c7561cd8 128#ifdef CONFIG_PM_SLEEP
68cb2b55 129static int ct_card_suspend(struct device *dev)
29959a09 130{
68cb2b55 131 struct snd_card *card = dev_get_drvdata(dev);
29959a09
WYC
132 struct ct_atc *atc = card->private_data;
133
68cb2b55 134 return atc->suspend(atc);
29959a09
WYC
135}
136
68cb2b55 137static int ct_card_resume(struct device *dev)
29959a09 138{
68cb2b55 139 struct snd_card *card = dev_get_drvdata(dev);
29959a09
WYC
140 struct ct_atc *atc = card->private_data;
141
142 return atc->resume(atc);
143}
68cb2b55
TI
144
145static SIMPLE_DEV_PM_OPS(ct_card_pm, ct_card_suspend, ct_card_resume);
146#define CT_CARD_PM_OPS &ct_card_pm
147#else
148#define CT_CARD_PM_OPS NULL
29959a09
WYC
149#endif
150
8cc72361 151static struct pci_driver ct_driver = {
3733e424 152 .name = KBUILD_MODNAME,
8cc72361
WYC
153 .id_table = ct_pci_dev_ids,
154 .probe = ct_card_probe,
e23e7a14 155 .remove = ct_card_remove,
68cb2b55
TI
156 .driver = {
157 .pm = CT_CARD_PM_OPS,
158 },
8cc72361
WYC
159};
160
e9f66d9b 161module_pci_driver(ct_driver);