Merge tag 'gpio-fixes-for-v5.19-rc6' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / sound / pci / cs46xx / cs46xx.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
1da177e4
LT
2/*
3 * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
c1017a4c 4 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>
1da177e4
LT
5 */
6
7/*
8 NOTES:
9 - sometimes the sound is metallic and sibilant, unloading and
10 reloading the module may solve this.
11*/
12
1da177e4
LT
13#include <linux/pci.h>
14#include <linux/time.h>
15#include <linux/init.h>
65a77217 16#include <linux/module.h>
1da177e4 17#include <sound/core.h>
81fcb170 18#include "cs46xx.h"
1da177e4
LT
19#include <sound/initval.h>
20
c1017a4c 21MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
1da177e4
LT
22MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
23MODULE_LICENSE("GPL");
1da177e4
LT
24
25static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
26static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
a67ff6a5
RR
27static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
28static bool external_amp[SNDRV_CARDS];
29static bool thinkpad[SNDRV_CARDS];
30static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
1da177e4
LT
31
32module_param_array(index, int, NULL, 0444);
33MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
34module_param_array(id, charp, NULL, 0444);
35MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
36module_param_array(enable, bool, NULL, 0444);
37MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
38module_param_array(external_amp, bool, NULL, 0444);
dfd9944f 39MODULE_PARM_DESC(external_amp, "Force to enable external amplifier.");
1da177e4
LT
40module_param_array(thinkpad, bool, NULL, 0444);
41MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
42module_param_array(mmap_valid, bool, NULL, 0444);
43MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
44
9baa3c34 45static const struct pci_device_id snd_cs46xx_ids[] = {
28d27aae
JP
46 { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
47 { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
48 { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
1da177e4
LT
49 { 0, }
50};
51
52MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
53
e23e7a14
BP
54static int snd_card_cs46xx_probe(struct pci_dev *pci,
55 const struct pci_device_id *pci_id)
1da177e4
LT
56{
57 static int dev;
3d19f804
TI
58 struct snd_card *card;
59 struct snd_cs46xx *chip;
1da177e4
LT
60 int err;
61
62 if (dev >= SNDRV_CARDS)
63 return -ENODEV;
64 if (!enable[dev]) {
65 dev++;
66 return -ENOENT;
67 }
68
5bff69b3
TI
69 err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
70 sizeof(*chip), &card);
e58de7ba
TI
71 if (err < 0)
72 return err;
5bff69b3 73 chip = card->private_data;
cbc2d997 74 err = snd_cs46xx_create(card, pci,
5bff69b3
TI
75 external_amp[dev], thinkpad[dev]);
76 if (err < 0)
c5e58c45 77 goto error;
cb28e45b 78 card->private_data = chip;
1da177e4 79 chip->accept_valid = mmap_valid[dev];
cbc2d997 80 err = snd_cs46xx_pcm(chip, 0);
5bff69b3 81 if (err < 0)
c5e58c45 82 goto error;
1da177e4 83#ifdef CONFIG_SND_CS46XX_NEW_DSP
cbc2d997 84 err = snd_cs46xx_pcm_rear(chip, 1);
5bff69b3 85 if (err < 0)
c5e58c45 86 goto error;
cbc2d997 87 err = snd_cs46xx_pcm_iec958(chip, 2);
5bff69b3 88 if (err < 0)
c5e58c45 89 goto error;
1da177e4 90#endif
cbc2d997 91 err = snd_cs46xx_mixer(chip, 2);
5bff69b3 92 if (err < 0)
c5e58c45 93 goto error;
1da177e4
LT
94#ifdef CONFIG_SND_CS46XX_NEW_DSP
95 if (chip->nr_ac97_codecs ==2) {
cbc2d997 96 err = snd_cs46xx_pcm_center_lfe(chip, 3);
5bff69b3 97 if (err < 0)
c5e58c45 98 goto error;
1da177e4
LT
99 }
100#endif
cbc2d997 101 err = snd_cs46xx_midi(chip, 0);
5bff69b3 102 if (err < 0)
c5e58c45 103 goto error;
cbc2d997 104 err = snd_cs46xx_start_dsp(chip);
5bff69b3 105 if (err < 0)
c5e58c45 106 goto error;
1da177e4
LT
107
108 snd_cs46xx_gameport(chip);
109
110 strcpy(card->driver, "CS46xx");
111 strcpy(card->shortname, "Sound Fusion CS46xx");
112 sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
113 card->shortname,
114 chip->ba0_addr,
115 chip->ba1_addr,
116 chip->irq);
117
cbc2d997 118 err = snd_card_register(card);
5bff69b3 119 if (err < 0)
c5e58c45 120 goto error;
1da177e4
LT
121
122 pci_set_drvdata(pci, card);
123 dev++;
124 return 0;
c5e58c45
TI
125
126 error:
127 snd_card_free(card);
128 return err;
1da177e4
LT
129}
130
e9f66d9b 131static struct pci_driver cs46xx_driver = {
3733e424 132 .name = KBUILD_MODNAME,
1da177e4
LT
133 .id_table = snd_cs46xx_ids,
134 .probe = snd_card_cs46xx_probe,
c7561cd8 135#ifdef CONFIG_PM_SLEEP
68cb2b55
TI
136 .driver = {
137 .pm = &snd_cs46xx_pm,
138 },
cb28e45b 139#endif
1da177e4
LT
140};
141
e9f66d9b 142module_pci_driver(cs46xx_driver);