Loading...
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
5 */
6
7/*
8 NOTES:
9 - sometimes the sound is metallic and sibilant, unloading and
10 reloading the module may solve this.
11*/
12
13#include <linux/pci.h>
14#include <linux/time.h>
15#include <linux/init.h>
16#include <linux/module.h>
17#include <sound/core.h>
18#include "cs46xx.h"
19#include <sound/initval.h>
20
21MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
22MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
23MODULE_LICENSE("GPL");
24MODULE_SUPPORTED_DEVICE("{{Cirrus Logic,Sound Fusion (CS4280)},"
25 "{Cirrus Logic,Sound Fusion (CS4610)},"
26 "{Cirrus Logic,Sound Fusion (CS4612)},"
27 "{Cirrus Logic,Sound Fusion (CS4615)},"
28 "{Cirrus Logic,Sound Fusion (CS4622)},"
29 "{Cirrus Logic,Sound Fusion (CS4624)},"
30 "{Cirrus Logic,Sound Fusion (CS4630)}}");
31
32static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
33static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
34static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
35static bool external_amp[SNDRV_CARDS];
36static bool thinkpad[SNDRV_CARDS];
37static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
38
39module_param_array(index, int, NULL, 0444);
40MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
41module_param_array(id, charp, NULL, 0444);
42MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
43module_param_array(enable, bool, NULL, 0444);
44MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
45module_param_array(external_amp, bool, NULL, 0444);
46MODULE_PARM_DESC(external_amp, "Force to enable external amplifier.");
47module_param_array(thinkpad, bool, NULL, 0444);
48MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
49module_param_array(mmap_valid, bool, NULL, 0444);
50MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
51
52static const struct pci_device_id snd_cs46xx_ids[] = {
53 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
54 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
55 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
56 { 0, }
57};
58
59MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
60
61static int snd_card_cs46xx_probe(struct pci_dev *pci,
62 const struct pci_device_id *pci_id)
63{
64 static int dev;
65 struct snd_card *card;
66 struct snd_cs46xx *chip;
67 int err;
68
69 if (dev >= SNDRV_CARDS)
70 return -ENODEV;
71 if (!enable[dev]) {
72 dev++;
73 return -ENOENT;
74 }
75
76 err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
77 0, &card);
78 if (err < 0)
79 return err;
80 if ((err = snd_cs46xx_create(card, pci,
81 external_amp[dev], thinkpad[dev],
82 &chip)) < 0) {
83 snd_card_free(card);
84 return err;
85 }
86 card->private_data = chip;
87 chip->accept_valid = mmap_valid[dev];
88 if ((err = snd_cs46xx_pcm(chip, 0)) < 0) {
89 snd_card_free(card);
90 return err;
91 }
92#ifdef CONFIG_SND_CS46XX_NEW_DSP
93 if ((err = snd_cs46xx_pcm_rear(chip, 1)) < 0) {
94 snd_card_free(card);
95 return err;
96 }
97 if ((err = snd_cs46xx_pcm_iec958(chip, 2)) < 0) {
98 snd_card_free(card);
99 return err;
100 }
101#endif
102 if ((err = snd_cs46xx_mixer(chip, 2)) < 0) {
103 snd_card_free(card);
104 return err;
105 }
106#ifdef CONFIG_SND_CS46XX_NEW_DSP
107 if (chip->nr_ac97_codecs ==2) {
108 if ((err = snd_cs46xx_pcm_center_lfe(chip, 3)) < 0) {
109 snd_card_free(card);
110 return err;
111 }
112 }
113#endif
114 if ((err = snd_cs46xx_midi(chip, 0)) < 0) {
115 snd_card_free(card);
116 return err;
117 }
118 if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
119 snd_card_free(card);
120 return err;
121 }
122
123
124 snd_cs46xx_gameport(chip);
125
126 strcpy(card->driver, "CS46xx");
127 strcpy(card->shortname, "Sound Fusion CS46xx");
128 sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
129 card->shortname,
130 chip->ba0_addr,
131 chip->ba1_addr,
132 chip->irq);
133
134 if ((err = snd_card_register(card)) < 0) {
135 snd_card_free(card);
136 return err;
137 }
138
139 pci_set_drvdata(pci, card);
140 dev++;
141 return 0;
142}
143
144static void snd_card_cs46xx_remove(struct pci_dev *pci)
145{
146 snd_card_free(pci_get_drvdata(pci));
147}
148
149static struct pci_driver cs46xx_driver = {
150 .name = KBUILD_MODNAME,
151 .id_table = snd_cs46xx_ids,
152 .probe = snd_card_cs46xx_probe,
153 .remove = snd_card_cs46xx_remove,
154#ifdef CONFIG_PM_SLEEP
155 .driver = {
156 .pm = &snd_cs46xx_pm,
157 },
158#endif
159};
160
161module_pci_driver(cs46xx_driver);
1/*
2 * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
3 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4 *
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 *
20 */
21
22/*
23 NOTES:
24 - sometimes the sound is metallic and sibilant, unloading and
25 reloading the module may solve this.
26*/
27
28#include <linux/pci.h>
29#include <linux/time.h>
30#include <linux/init.h>
31#include <linux/module.h>
32#include <sound/core.h>
33#include <sound/cs46xx.h>
34#include <sound/initval.h>
35
36MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
37MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
38MODULE_LICENSE("GPL");
39MODULE_SUPPORTED_DEVICE("{{Cirrus Logic,Sound Fusion (CS4280)},"
40 "{Cirrus Logic,Sound Fusion (CS4610)},"
41 "{Cirrus Logic,Sound Fusion (CS4612)},"
42 "{Cirrus Logic,Sound Fusion (CS4615)},"
43 "{Cirrus Logic,Sound Fusion (CS4622)},"
44 "{Cirrus Logic,Sound Fusion (CS4624)},"
45 "{Cirrus Logic,Sound Fusion (CS4630)}}");
46
47static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
48static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
49static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
50static bool external_amp[SNDRV_CARDS];
51static bool thinkpad[SNDRV_CARDS];
52static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
53
54module_param_array(index, int, NULL, 0444);
55MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
56module_param_array(id, charp, NULL, 0444);
57MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
58module_param_array(enable, bool, NULL, 0444);
59MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
60module_param_array(external_amp, bool, NULL, 0444);
61MODULE_PARM_DESC(external_amp, "Force to enable external amplifer.");
62module_param_array(thinkpad, bool, NULL, 0444);
63MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
64module_param_array(mmap_valid, bool, NULL, 0444);
65MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
66
67static DEFINE_PCI_DEVICE_TABLE(snd_cs46xx_ids) = {
68 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
69 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
70 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
71 { 0, }
72};
73
74MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
75
76static int __devinit snd_card_cs46xx_probe(struct pci_dev *pci,
77 const struct pci_device_id *pci_id)
78{
79 static int dev;
80 struct snd_card *card;
81 struct snd_cs46xx *chip;
82 int err;
83
84 if (dev >= SNDRV_CARDS)
85 return -ENODEV;
86 if (!enable[dev]) {
87 dev++;
88 return -ENOENT;
89 }
90
91 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
92 if (err < 0)
93 return err;
94 if ((err = snd_cs46xx_create(card, pci,
95 external_amp[dev], thinkpad[dev],
96 &chip)) < 0) {
97 snd_card_free(card);
98 return err;
99 }
100 card->private_data = chip;
101 chip->accept_valid = mmap_valid[dev];
102 if ((err = snd_cs46xx_pcm(chip, 0, NULL)) < 0) {
103 snd_card_free(card);
104 return err;
105 }
106#ifdef CONFIG_SND_CS46XX_NEW_DSP
107 if ((err = snd_cs46xx_pcm_rear(chip,1, NULL)) < 0) {
108 snd_card_free(card);
109 return err;
110 }
111 if ((err = snd_cs46xx_pcm_iec958(chip,2,NULL)) < 0) {
112 snd_card_free(card);
113 return err;
114 }
115#endif
116 if ((err = snd_cs46xx_mixer(chip, 2)) < 0) {
117 snd_card_free(card);
118 return err;
119 }
120#ifdef CONFIG_SND_CS46XX_NEW_DSP
121 if (chip->nr_ac97_codecs ==2) {
122 if ((err = snd_cs46xx_pcm_center_lfe(chip,3,NULL)) < 0) {
123 snd_card_free(card);
124 return err;
125 }
126 }
127#endif
128 if ((err = snd_cs46xx_midi(chip, 0, NULL)) < 0) {
129 snd_card_free(card);
130 return err;
131 }
132 if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
133 snd_card_free(card);
134 return err;
135 }
136
137
138 snd_cs46xx_gameport(chip);
139
140 strcpy(card->driver, "CS46xx");
141 strcpy(card->shortname, "Sound Fusion CS46xx");
142 sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
143 card->shortname,
144 chip->ba0_addr,
145 chip->ba1_addr,
146 chip->irq);
147
148 if ((err = snd_card_register(card)) < 0) {
149 snd_card_free(card);
150 return err;
151 }
152
153 pci_set_drvdata(pci, card);
154 dev++;
155 return 0;
156}
157
158static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci)
159{
160 snd_card_free(pci_get_drvdata(pci));
161 pci_set_drvdata(pci, NULL);
162}
163
164static struct pci_driver cs46xx_driver = {
165 .name = KBUILD_MODNAME,
166 .id_table = snd_cs46xx_ids,
167 .probe = snd_card_cs46xx_probe,
168 .remove = __devexit_p(snd_card_cs46xx_remove),
169#ifdef CONFIG_PM
170 .suspend = snd_cs46xx_suspend,
171 .resume = snd_cs46xx_resume,
172#endif
173};
174
175module_pci_driver(cs46xx_driver);