| 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 | 
|  | 3 | *  Copyright (c) by Jaroslav Kysela <perex@suse.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 <sound/driver.h> | 
|  | 29 | #include <linux/pci.h> | 
|  | 30 | #include <linux/time.h> | 
|  | 31 | #include <linux/init.h> | 
|  | 32 | #include <linux/moduleparam.h> | 
|  | 33 | #include <sound/core.h> | 
|  | 34 | #include <sound/cs46xx.h> | 
|  | 35 | #include <sound/initval.h> | 
|  | 36 |  | 
|  | 37 | MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>"); | 
|  | 38 | MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX"); | 
|  | 39 | MODULE_LICENSE("GPL"); | 
|  | 40 | MODULE_SUPPORTED_DEVICE("{{Cirrus Logic,Sound Fusion (CS4280)}," | 
|  | 41 | "{Cirrus Logic,Sound Fusion (CS4610)}," | 
|  | 42 | "{Cirrus Logic,Sound Fusion (CS4612)}," | 
|  | 43 | "{Cirrus Logic,Sound Fusion (CS4615)}," | 
|  | 44 | "{Cirrus Logic,Sound Fusion (CS4622)}," | 
|  | 45 | "{Cirrus Logic,Sound Fusion (CS4624)}," | 
|  | 46 | "{Cirrus Logic,Sound Fusion (CS4630)}}"); | 
|  | 47 |  | 
|  | 48 | static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;	/* Index 0-MAX */ | 
|  | 49 | static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;	/* ID for this card */ | 
|  | 50 | static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;	/* Enable this card */ | 
|  | 51 | static int external_amp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; | 
|  | 52 | static int thinkpad[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0}; | 
|  | 53 | static int mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1}; | 
|  | 54 |  | 
|  | 55 | module_param_array(index, int, NULL, 0444); | 
|  | 56 | MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard."); | 
|  | 57 | module_param_array(id, charp, NULL, 0444); | 
|  | 58 | MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard."); | 
|  | 59 | module_param_array(enable, bool, NULL, 0444); | 
|  | 60 | MODULE_PARM_DESC(enable, "Enable CS46xx soundcard."); | 
|  | 61 | module_param_array(external_amp, bool, NULL, 0444); | 
|  | 62 | MODULE_PARM_DESC(external_amp, "Force to enable external amplifer."); | 
|  | 63 | module_param_array(thinkpad, bool, NULL, 0444); | 
|  | 64 | MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control."); | 
|  | 65 | module_param_array(mmap_valid, bool, NULL, 0444); | 
|  | 66 | MODULE_PARM_DESC(mmap_valid, "Support OSS mmap."); | 
|  | 67 |  | 
|  | 68 | static struct pci_device_id snd_cs46xx_ids[] = { | 
|  | 69 | { 0x1013, 0x6001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4280 */ | 
|  | 70 | { 0x1013, 0x6003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4612 */ | 
|  | 71 | { 0x1013, 0x6004, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },   /* CS4615 */ | 
|  | 72 | { 0, } | 
|  | 73 | }; | 
|  | 74 |  | 
|  | 75 | MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids); | 
|  | 76 |  | 
|  | 77 | static int __devinit snd_card_cs46xx_probe(struct pci_dev *pci, | 
|  | 78 | const struct pci_device_id *pci_id) | 
|  | 79 | { | 
|  | 80 | static int dev; | 
|  | 81 | snd_card_t *card; | 
|  | 82 | cs46xx_t *chip; | 
|  | 83 | int err; | 
|  | 84 |  | 
|  | 85 | if (dev >= SNDRV_CARDS) | 
|  | 86 | return -ENODEV; | 
|  | 87 | if (!enable[dev]) { | 
|  | 88 | dev++; | 
|  | 89 | return -ENOENT; | 
|  | 90 | } | 
|  | 91 |  | 
|  | 92 | card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); | 
|  | 93 | if (card == NULL) | 
|  | 94 | return -ENOMEM; | 
|  | 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 | } | 
|  | 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)) < 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 |  | 
|  | 158 | static 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 |  | 
|  | 164 | static struct pci_driver driver = { | 
|  | 165 | .name = "Sound Fusion CS46xx", | 
|  | 166 | .id_table = snd_cs46xx_ids, | 
|  | 167 | .probe = snd_card_cs46xx_probe, | 
|  | 168 | .remove = __devexit_p(snd_card_cs46xx_remove), | 
|  | 169 | SND_PCI_PM_CALLBACKS | 
|  | 170 | }; | 
|  | 171 |  | 
|  | 172 | static int __init alsa_card_cs46xx_init(void) | 
|  | 173 | { | 
| Takashi Iwai | 01d25d4 | 2005-04-11 16:58:24 +0200 | [diff] [blame] | 174 | return pci_register_driver(&driver); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } | 
|  | 176 |  | 
|  | 177 | static void __exit alsa_card_cs46xx_exit(void) | 
|  | 178 | { | 
|  | 179 | pci_unregister_driver(&driver); | 
|  | 180 | } | 
|  | 181 |  | 
|  | 182 | module_init(alsa_card_cs46xx_init) | 
|  | 183 | module_exit(alsa_card_cs46xx_exit) |