cs46xx.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. NOTES:
  23. - sometimes the sound is metallic and sibilant, unloading and
  24. reloading the module may solve this.
  25. */
  26. #include <linux/pci.h>
  27. #include <linux/time.h>
  28. #include <linux/init.h>
  29. #include <linux/module.h>
  30. #include <sound/core.h>
  31. #include "cs46xx.h"
  32. #include <sound/initval.h>
  33. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  34. MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
  35. MODULE_LICENSE("GPL");
  36. MODULE_SUPPORTED_DEVICE("{{Cirrus Logic,Sound Fusion (CS4280)},"
  37. "{Cirrus Logic,Sound Fusion (CS4610)},"
  38. "{Cirrus Logic,Sound Fusion (CS4612)},"
  39. "{Cirrus Logic,Sound Fusion (CS4615)},"
  40. "{Cirrus Logic,Sound Fusion (CS4622)},"
  41. "{Cirrus Logic,Sound Fusion (CS4624)},"
  42. "{Cirrus Logic,Sound Fusion (CS4630)}}");
  43. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  44. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  45. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  46. static bool external_amp[SNDRV_CARDS];
  47. static bool thinkpad[SNDRV_CARDS];
  48. static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  49. module_param_array(index, int, NULL, 0444);
  50. MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
  51. module_param_array(id, charp, NULL, 0444);
  52. MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
  53. module_param_array(enable, bool, NULL, 0444);
  54. MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
  55. module_param_array(external_amp, bool, NULL, 0444);
  56. MODULE_PARM_DESC(external_amp, "Force to enable external amplifer.");
  57. module_param_array(thinkpad, bool, NULL, 0444);
  58. MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
  59. module_param_array(mmap_valid, bool, NULL, 0444);
  60. MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
  61. static const struct pci_device_id snd_cs46xx_ids[] = {
  62. { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
  63. { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
  64. { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
  65. { 0, }
  66. };
  67. MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
  68. static int snd_card_cs46xx_probe(struct pci_dev *pci,
  69. const struct pci_device_id *pci_id)
  70. {
  71. static int dev;
  72. struct snd_card *card;
  73. struct snd_cs46xx *chip;
  74. int err;
  75. if (dev >= SNDRV_CARDS)
  76. return -ENODEV;
  77. if (!enable[dev]) {
  78. dev++;
  79. return -ENOENT;
  80. }
  81. err = snd_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  82. 0, &card);
  83. if (err < 0)
  84. return err;
  85. if ((err = snd_cs46xx_create(card, pci,
  86. external_amp[dev], thinkpad[dev],
  87. &chip)) < 0) {
  88. snd_card_free(card);
  89. return err;
  90. }
  91. card->private_data = chip;
  92. chip->accept_valid = mmap_valid[dev];
  93. if ((err = snd_cs46xx_pcm(chip, 0)) < 0) {
  94. snd_card_free(card);
  95. return err;
  96. }
  97. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  98. if ((err = snd_cs46xx_pcm_rear(chip, 1)) < 0) {
  99. snd_card_free(card);
  100. return err;
  101. }
  102. if ((err = snd_cs46xx_pcm_iec958(chip, 2)) < 0) {
  103. snd_card_free(card);
  104. return err;
  105. }
  106. #endif
  107. if ((err = snd_cs46xx_mixer(chip, 2)) < 0) {
  108. snd_card_free(card);
  109. return err;
  110. }
  111. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  112. if (chip->nr_ac97_codecs ==2) {
  113. if ((err = snd_cs46xx_pcm_center_lfe(chip, 3)) < 0) {
  114. snd_card_free(card);
  115. return err;
  116. }
  117. }
  118. #endif
  119. if ((err = snd_cs46xx_midi(chip, 0)) < 0) {
  120. snd_card_free(card);
  121. return err;
  122. }
  123. if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
  124. snd_card_free(card);
  125. return err;
  126. }
  127. snd_cs46xx_gameport(chip);
  128. strcpy(card->driver, "CS46xx");
  129. strcpy(card->shortname, "Sound Fusion CS46xx");
  130. sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
  131. card->shortname,
  132. chip->ba0_addr,
  133. chip->ba1_addr,
  134. chip->irq);
  135. if ((err = snd_card_register(card)) < 0) {
  136. snd_card_free(card);
  137. return err;
  138. }
  139. pci_set_drvdata(pci, card);
  140. dev++;
  141. return 0;
  142. }
  143. static void snd_card_cs46xx_remove(struct pci_dev *pci)
  144. {
  145. snd_card_free(pci_get_drvdata(pci));
  146. }
  147. static struct pci_driver cs46xx_driver = {
  148. .name = KBUILD_MODNAME,
  149. .id_table = snd_cs46xx_ids,
  150. .probe = snd_card_cs46xx_probe,
  151. .remove = snd_card_cs46xx_remove,
  152. #ifdef CONFIG_PM_SLEEP
  153. .driver = {
  154. .pm = &snd_cs46xx_pm,
  155. },
  156. #endif
  157. };
  158. module_pci_driver(cs46xx_driver);