Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  *  The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
0004  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
0005  */
0006 
0007 /*
0008   NOTES:
0009   - sometimes the sound is metallic and sibilant, unloading and 
0010     reloading the module may solve this.
0011 */
0012 
0013 #include <linux/pci.h>
0014 #include <linux/time.h>
0015 #include <linux/init.h>
0016 #include <linux/module.h>
0017 #include <sound/core.h>
0018 #include "cs46xx.h"
0019 #include <sound/initval.h>
0020 
0021 MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
0022 MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
0023 MODULE_LICENSE("GPL");
0024 
0025 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;  /* Index 0-MAX */
0026 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;   /* ID for this card */
0027 static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
0028 static bool external_amp[SNDRV_CARDS];
0029 static bool thinkpad[SNDRV_CARDS];
0030 static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
0031 
0032 module_param_array(index, int, NULL, 0444);
0033 MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
0034 module_param_array(id, charp, NULL, 0444);
0035 MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
0036 module_param_array(enable, bool, NULL, 0444);
0037 MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
0038 module_param_array(external_amp, bool, NULL, 0444);
0039 MODULE_PARM_DESC(external_amp, "Force to enable external amplifier.");
0040 module_param_array(thinkpad, bool, NULL, 0444);
0041 MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
0042 module_param_array(mmap_valid, bool, NULL, 0444);
0043 MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
0044 
0045 static const struct pci_device_id snd_cs46xx_ids[] = {
0046     { PCI_VDEVICE(CIRRUS, 0x6001), 0, },   /* CS4280 */
0047     { PCI_VDEVICE(CIRRUS, 0x6003), 0, },   /* CS4612 */
0048     { PCI_VDEVICE(CIRRUS, 0x6004), 0, },   /* CS4615 */
0049     { 0, }
0050 };
0051 
0052 MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
0053 
0054 static int snd_card_cs46xx_probe(struct pci_dev *pci,
0055                  const struct pci_device_id *pci_id)
0056 {
0057     static int dev;
0058     struct snd_card *card;
0059     struct snd_cs46xx *chip;
0060     int err;
0061 
0062     if (dev >= SNDRV_CARDS)
0063         return -ENODEV;
0064     if (!enable[dev]) {
0065         dev++;
0066         return -ENOENT;
0067     }
0068 
0069     err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
0070                 sizeof(*chip), &card);
0071     if (err < 0)
0072         return err;
0073     chip = card->private_data;
0074     err = snd_cs46xx_create(card, pci,
0075                 external_amp[dev], thinkpad[dev]);
0076     if (err < 0)
0077         goto error;
0078     card->private_data = chip;
0079     chip->accept_valid = mmap_valid[dev];
0080     err = snd_cs46xx_pcm(chip, 0);
0081     if (err < 0)
0082         goto error;
0083 #ifdef CONFIG_SND_CS46XX_NEW_DSP
0084     err = snd_cs46xx_pcm_rear(chip, 1);
0085     if (err < 0)
0086         goto error;
0087     err = snd_cs46xx_pcm_iec958(chip, 2);
0088     if (err < 0)
0089         goto error;
0090 #endif
0091     err = snd_cs46xx_mixer(chip, 2);
0092     if (err < 0)
0093         goto error;
0094 #ifdef CONFIG_SND_CS46XX_NEW_DSP
0095     if (chip->nr_ac97_codecs ==2) {
0096         err = snd_cs46xx_pcm_center_lfe(chip, 3);
0097         if (err < 0)
0098             goto error;
0099     }
0100 #endif
0101     err = snd_cs46xx_midi(chip, 0);
0102     if (err < 0)
0103         goto error;
0104     err = snd_cs46xx_start_dsp(chip);
0105     if (err < 0)
0106         goto error;
0107 
0108     snd_cs46xx_gameport(chip);
0109 
0110     strcpy(card->driver, "CS46xx");
0111     strcpy(card->shortname, "Sound Fusion CS46xx");
0112     sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
0113         card->shortname,
0114         chip->ba0_addr,
0115         chip->ba1_addr,
0116         chip->irq);
0117 
0118     err = snd_card_register(card);
0119     if (err < 0)
0120         goto error;
0121 
0122     pci_set_drvdata(pci, card);
0123     dev++;
0124     return 0;
0125 
0126  error:
0127     snd_card_free(card);
0128     return err;
0129 }
0130 
0131 static struct pci_driver cs46xx_driver = {
0132     .name = KBUILD_MODNAME,
0133     .id_table = snd_cs46xx_ids,
0134     .probe = snd_card_cs46xx_probe,
0135 #ifdef CONFIG_PM_SLEEP
0136     .driver = {
0137         .pm = &snd_cs46xx_pm,
0138     },
0139 #endif
0140 };
0141 
0142 module_pci_driver(cs46xx_driver);