cs46xx.c 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * The driver for the Cirrus Logic's Sound Fusion CS46XX based soundcards
  4. * Copyright (c) by Jaroslav Kysela <[email protected]>
  5. */
  6. /*
  7. NOTES:
  8. - sometimes the sound is metallic and sibilant, unloading and
  9. reloading the module may solve this.
  10. */
  11. #include <linux/pci.h>
  12. #include <linux/time.h>
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <sound/core.h>
  16. #include "cs46xx.h"
  17. #include <sound/initval.h>
  18. MODULE_AUTHOR("Jaroslav Kysela <[email protected]>");
  19. MODULE_DESCRIPTION("Cirrus Logic Sound Fusion CS46XX");
  20. MODULE_LICENSE("GPL");
  21. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  22. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  23. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
  24. static bool external_amp[SNDRV_CARDS];
  25. static bool thinkpad[SNDRV_CARDS];
  26. static bool mmap_valid[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  27. module_param_array(index, int, NULL, 0444);
  28. MODULE_PARM_DESC(index, "Index value for the CS46xx soundcard.");
  29. module_param_array(id, charp, NULL, 0444);
  30. MODULE_PARM_DESC(id, "ID string for the CS46xx soundcard.");
  31. module_param_array(enable, bool, NULL, 0444);
  32. MODULE_PARM_DESC(enable, "Enable CS46xx soundcard.");
  33. module_param_array(external_amp, bool, NULL, 0444);
  34. MODULE_PARM_DESC(external_amp, "Force to enable external amplifier.");
  35. module_param_array(thinkpad, bool, NULL, 0444);
  36. MODULE_PARM_DESC(thinkpad, "Force to enable Thinkpad's CLKRUN control.");
  37. module_param_array(mmap_valid, bool, NULL, 0444);
  38. MODULE_PARM_DESC(mmap_valid, "Support OSS mmap.");
  39. static const struct pci_device_id snd_cs46xx_ids[] = {
  40. { PCI_VDEVICE(CIRRUS, 0x6001), 0, }, /* CS4280 */
  41. { PCI_VDEVICE(CIRRUS, 0x6003), 0, }, /* CS4612 */
  42. { PCI_VDEVICE(CIRRUS, 0x6004), 0, }, /* CS4615 */
  43. { 0, }
  44. };
  45. MODULE_DEVICE_TABLE(pci, snd_cs46xx_ids);
  46. static int snd_card_cs46xx_probe(struct pci_dev *pci,
  47. const struct pci_device_id *pci_id)
  48. {
  49. static int dev;
  50. struct snd_card *card;
  51. struct snd_cs46xx *chip;
  52. int err;
  53. if (dev >= SNDRV_CARDS)
  54. return -ENODEV;
  55. if (!enable[dev]) {
  56. dev++;
  57. return -ENOENT;
  58. }
  59. err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
  60. sizeof(*chip), &card);
  61. if (err < 0)
  62. return err;
  63. chip = card->private_data;
  64. err = snd_cs46xx_create(card, pci,
  65. external_amp[dev], thinkpad[dev]);
  66. if (err < 0)
  67. goto error;
  68. card->private_data = chip;
  69. chip->accept_valid = mmap_valid[dev];
  70. err = snd_cs46xx_pcm(chip, 0);
  71. if (err < 0)
  72. goto error;
  73. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  74. err = snd_cs46xx_pcm_rear(chip, 1);
  75. if (err < 0)
  76. goto error;
  77. err = snd_cs46xx_pcm_iec958(chip, 2);
  78. if (err < 0)
  79. goto error;
  80. #endif
  81. err = snd_cs46xx_mixer(chip, 2);
  82. if (err < 0)
  83. goto error;
  84. #ifdef CONFIG_SND_CS46XX_NEW_DSP
  85. if (chip->nr_ac97_codecs ==2) {
  86. err = snd_cs46xx_pcm_center_lfe(chip, 3);
  87. if (err < 0)
  88. goto error;
  89. }
  90. #endif
  91. err = snd_cs46xx_midi(chip, 0);
  92. if (err < 0)
  93. goto error;
  94. err = snd_cs46xx_start_dsp(chip);
  95. if (err < 0)
  96. goto error;
  97. snd_cs46xx_gameport(chip);
  98. strcpy(card->driver, "CS46xx");
  99. strcpy(card->shortname, "Sound Fusion CS46xx");
  100. sprintf(card->longname, "%s at 0x%lx/0x%lx, irq %i",
  101. card->shortname,
  102. chip->ba0_addr,
  103. chip->ba1_addr,
  104. chip->irq);
  105. err = snd_card_register(card);
  106. if (err < 0)
  107. goto error;
  108. pci_set_drvdata(pci, card);
  109. dev++;
  110. return 0;
  111. error:
  112. snd_card_free(card);
  113. return err;
  114. }
  115. static struct pci_driver cs46xx_driver = {
  116. .name = KBUILD_MODNAME,
  117. .id_table = snd_cs46xx_ids,
  118. .probe = snd_card_cs46xx_probe,
  119. #ifdef CONFIG_PM_SLEEP
  120. .driver = {
  121. .pm = &snd_cs46xx_pm,
  122. },
  123. #endif
  124. };
  125. module_pci_driver(cs46xx_driver);