cs46xx.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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/moduleparam.h>
  30. #include <sound/core.h>
  31. #include <sound/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 int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  46. static int external_amp[SNDRV_CARDS];
  47. static int thinkpad[SNDRV_CARDS];
  48. static int 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 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 __devinit 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_create(index[dev], id[dev], THIS_MODULE, 0, &card);
  82. if (err < 0)
  83. return err;
  84. if ((err = snd_cs46xx_create(card, pci,
  85. external_amp[dev], thinkpad[dev],
  86. &chip)) < 0) {
  87. snd_card_free(card);
  88. return err;
  89. }
  90. card->private_data = chip;
  91. chip->accept_valid = mmap_valid[dev];
  92. if ((err = snd_cs46xx_pcm(chip, 0, NULL)) < 0) {
  93. snd_card_free(card);
  94. return err;
  95. }
  96. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  97. if ((err = snd_cs46xx_pcm_rear(chip,1, NULL)) < 0) {
  98. snd_card_free(card);
  99. return err;
  100. }
  101. if ((err = snd_cs46xx_pcm_iec958(chip,2,NULL)) < 0) {
  102. snd_card_free(card);
  103. return err;
  104. }
  105. #endif
  106. if ((err = snd_cs46xx_mixer(chip, 2)) < 0) {
  107. snd_card_free(card);
  108. return err;
  109. }
  110. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  111. if (chip->nr_ac97_codecs ==2) {
  112. if ((err = snd_cs46xx_pcm_center_lfe(chip,3,NULL)) < 0) {
  113. snd_card_free(card);
  114. return err;
  115. }
  116. }
  117. #endif
  118. if ((err = snd_cs46xx_midi(chip, 0, NULL)) < 0) {
  119. snd_card_free(card);
  120. return err;
  121. }
  122. if ((err = snd_cs46xx_start_dsp(chip)) < 0) {
  123. snd_card_free(card);
  124. return err;
  125. }
  126. snd_cs46xx_gameport(chip);
  127. strcpy(card->driver, "CS46xx");
  128. strcpy(card->shortname, "Sound Fusion CS46xx");
  129. sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
  130. card->shortname,
  131. chip->ba0_addr,
  132. chip->ba1_addr,
  133. chip->irq);
  134. if ((err = snd_card_register(card)) < 0) {
  135. snd_card_free(card);
  136. return err;
  137. }
  138. pci_set_drvdata(pci, card);
  139. dev++;
  140. return 0;
  141. }
  142. static void __devexit snd_card_cs46xx_remove(struct pci_dev *pci)
  143. {
  144. snd_card_free(pci_get_drvdata(pci));
  145. pci_set_drvdata(pci, NULL);
  146. }
  147. static struct pci_driver driver = {
  148. .name = "Sound Fusion CS46xx",
  149. .id_table = snd_cs46xx_ids,
  150. .probe = snd_card_cs46xx_probe,
  151. .remove = __devexit_p(snd_card_cs46xx_remove),
  152. #ifdef CONFIG_PM
  153. .suspend = snd_cs46xx_suspend,
  154. .resume = snd_cs46xx_resume,
  155. #endif
  156. };
  157. static int __init alsa_card_cs46xx_init(void)
  158. {
  159. return pci_register_driver(&driver);
  160. }
  161. static void __exit alsa_card_cs46xx_exit(void)
  162. {
  163. pci_unregister_driver(&driver);
  164. }
  165. module_init(alsa_card_cs46xx_init)
  166. module_exit(alsa_card_cs46xx_exit)