Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 3 | * Copyright (c) by Jaroslav Kysela <perex@perex.cz> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/pci.h> |
| 29 | #include <linux/time.h> |
| 30 | #include <linux/init.h> |
Paul Gortmaker | 65a7721 | 2011-07-15 13:13:37 -0400 | [diff] [blame] | 31 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <sound/core.h> |
Takashi Iwai | 81fcb17 | 2012-07-02 16:37:05 +0200 | [diff] [blame] | 33 | #include "cs46xx.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <sound/initval.h> |
| 35 | |
Jaroslav Kysela | c1017a4 | 2007-10-15 09:50:19 +0200 | [diff] [blame] | 36 | MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX"); |
| 38 | MODULE_LICENSE("GPL"); |
| 39 | MODULE_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 | |
| 47 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ |
| 48 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ |
Rusty Russell | a67ff6a | 2011-12-15 13:49:36 +1030 | [diff] [blame] | 49 | static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ |
| 50 | static bool external_amp[SNDRV_CARDS]; |
| 51 | static bool thinkpad[SNDRV_CARDS]; |
| 52 | static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
| 54 | module_param_array(index, int, NULL, 0444); |
| 55 | MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard."); |
| 56 | module_param_array(id, charp, NULL, 0444); |
| 57 | MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard."); |
| 58 | module_param_array(enable, bool, NULL, 0444); |
| 59 | MODULE_PARM_DESC(enable, "Enable CS46xx soundcard."); |
| 60 | module_param_array(external_amp, bool, NULL, 0444); |
| 61 | MODULE_PARM_DESC(external_amp, "Force to enable external amplifer."); |
| 62 | module_param_array(thinkpad, bool, NULL, 0444); |
| 63 | MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control."); |
| 64 | module_param_array(mmap_valid, bool, NULL, 0444); |
| 65 | MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); |
| 66 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 67 | static const struct pci_device_id snd_cs46xx_ids[] = { |
Joe Perches | 28d27aa | 2009-06-24 22:13:35 -0700 | [diff] [blame] | 68 | { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */ |
| 69 | { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */ |
| 70 | { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | { 0, } |
| 72 | }; |
| 73 | |
| 74 | MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids); |
| 75 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 76 | static int snd_card_cs46xx_probe(struct pci_dev *pci, |
| 77 | const struct pci_device_id *pci_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | static int dev; |
Takashi Iwai | 3d19f80 | 2005-11-17 14:48:14 +0100 | [diff] [blame] | 80 | struct snd_card *card; |
| 81 | struct snd_cs46xx *chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | int err; |
| 83 | |
| 84 | if (dev >= SNDRV_CARDS) |
| 85 | return -ENODEV; |
| 86 | if (!enable[dev]) { |
| 87 | dev++; |
| 88 | return -ENOENT; |
| 89 | } |
| 90 | |
Takashi Iwai | 60c5772 | 2014-01-29 14:20:19 +0100 | [diff] [blame] | 91 | err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE, |
| 92 | 0, &card); |
Takashi Iwai | e58de7b | 2008-12-28 16:44:30 +0100 | [diff] [blame] | 93 | if (err < 0) |
| 94 | return err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | if ((err = snd_cs46xx_create(card, pci, |
| 96 | external_amp[dev], thinkpad[dev], |
| 97 | &chip)) < 0) { |
| 98 | snd_card_free(card); |
| 99 | return err; |
| 100 | } |
Takashi Iwai | cb28e45 | 2005-11-17 16:09:04 +0100 | [diff] [blame] | 101 | card->private_data = chip; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | chip->accept_valid = mmap_valid[dev]; |
Lars-Peter Clausen | 72134c4 | 2015-01-02 12:24:47 +0100 | [diff] [blame] | 103 | if ((err = snd_cs46xx_pcm(chip, 0)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | snd_card_free(card); |
| 105 | return err; |
| 106 | } |
| 107 | #ifdef CONFIG_SND_CS46XX_NEW_DSP |
Lars-Peter Clausen | 72134c4 | 2015-01-02 12:24:47 +0100 | [diff] [blame] | 108 | if ((err = snd_cs46xx_pcm_rear(chip, 1)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | snd_card_free(card); |
| 110 | return err; |
| 111 | } |
Lars-Peter Clausen | 72134c4 | 2015-01-02 12:24:47 +0100 | [diff] [blame] | 112 | if ((err = snd_cs46xx_pcm_iec958(chip, 2)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | snd_card_free(card); |
| 114 | return err; |
| 115 | } |
| 116 | #endif |
Clemens Ladisch | 67ed416 | 2005-07-29 15:32:58 +0200 | [diff] [blame] | 117 | if ((err = snd_cs46xx_mixer(chip, 2)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | snd_card_free(card); |
| 119 | return err; |
| 120 | } |
| 121 | #ifdef CONFIG_SND_CS46XX_NEW_DSP |
| 122 | if (chip->nr_ac97_codecs ==2) { |
Lars-Peter Clausen | 72134c4 | 2015-01-02 12:24:47 +0100 | [diff] [blame] | 123 | if ((err = snd_cs46xx_pcm_center_lfe(chip, 3)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | snd_card_free(card); |
| 125 | return err; |
| 126 | } |
| 127 | } |
| 128 | #endif |
Lars-Peter Clausen | 72134c4 | 2015-01-02 12:24:47 +0100 | [diff] [blame] | 129 | if ((err = snd_cs46xx_midi(chip, 0)) < 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | snd_card_free(card); |
| 131 | return err; |
| 132 | } |
| 133 | if ((err = snd_cs46xx_start_dsp(chip)) < 0) { |
| 134 | snd_card_free(card); |
| 135 | return err; |
| 136 | } |
| 137 | |
| 138 | |
| 139 | snd_cs46xx_gameport(chip); |
| 140 | |
| 141 | strcpy(card->driver, "CS46xx"); |
| 142 | strcpy(card->shortname, "Sound Fusion CS46xx"); |
| 143 | sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i", |
| 144 | card->shortname, |
| 145 | chip->ba0_addr, |
| 146 | chip->ba1_addr, |
| 147 | chip->irq); |
| 148 | |
| 149 | if ((err = snd_card_register(card)) < 0) { |
| 150 | snd_card_free(card); |
| 151 | return err; |
| 152 | } |
| 153 | |
| 154 | pci_set_drvdata(pci, card); |
| 155 | dev++; |
| 156 | return 0; |
| 157 | } |
| 158 | |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 159 | static void snd_card_cs46xx_remove(struct pci_dev *pci) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | { |
| 161 | snd_card_free(pci_get_drvdata(pci)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 164 | static struct pci_driver cs46xx_driver = { |
Takashi Iwai | 3733e42 | 2011-06-10 16:20:20 +0200 | [diff] [blame] | 165 | .name = KBUILD_MODNAME, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | .id_table = snd_cs46xx_ids, |
| 167 | .probe = snd_card_cs46xx_probe, |
Bill Pemberton | e23e7a1 | 2012-12-06 12:35:10 -0500 | [diff] [blame] | 168 | .remove = snd_card_cs46xx_remove, |
Takashi Iwai | c7561cd | 2012-08-14 18:12:04 +0200 | [diff] [blame] | 169 | #ifdef CONFIG_PM_SLEEP |
Takashi Iwai | 68cb2b5 | 2012-07-02 15:20:37 +0200 | [diff] [blame] | 170 | .driver = { |
| 171 | .pm = &snd_cs46xx_pm, |
| 172 | }, |
Takashi Iwai | cb28e45 | 2005-11-17 16:09:04 +0100 | [diff] [blame] | 173 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | }; |
| 175 | |
Takashi Iwai | e9f66d9 | 2012-04-24 12:25:00 +0200 | [diff] [blame] | 176 | module_pci_driver(cs46xx_driver); |