sb8.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /*
  2. * Driver for SoundBlaster 1.0/2.0/Pro soundcards and compatible
  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. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/slab.h>
  24. #include <linux/ioport.h>
  25. #include <linux/moduleparam.h>
  26. #include <sound/core.h>
  27. #include <sound/sb.h>
  28. #include <sound/opl3.h>
  29. #define SNDRV_LEGACY_AUTO_PROBE
  30. #include <sound/initval.h>
  31. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  32. MODULE_DESCRIPTION("Sound Blaster 1.0/2.0/Pro");
  33. MODULE_LICENSE("GPL");
  34. MODULE_SUPPORTED_DEVICE("{{Creative Labs,SB 1.0/SB 2.0/SB Pro}}");
  35. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  36. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  37. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  38. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
  39. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  40. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3 */
  41. module_param_array(index, int, NULL, 0444);
  42. MODULE_PARM_DESC(index, "Index value for Sound Blaster soundcard.");
  43. module_param_array(id, charp, NULL, 0444);
  44. MODULE_PARM_DESC(id, "ID string for Sound Blaster soundcard.");
  45. module_param_array(enable, bool, NULL, 0444);
  46. MODULE_PARM_DESC(enable, "Enable Sound Blaster soundcard.");
  47. module_param_array(port, long, NULL, 0444);
  48. MODULE_PARM_DESC(port, "Port # for SB8 driver.");
  49. module_param_array(irq, int, NULL, 0444);
  50. MODULE_PARM_DESC(irq, "IRQ # for SB8 driver.");
  51. module_param_array(dma8, int, NULL, 0444);
  52. MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver.");
  53. struct snd_sb8 {
  54. struct resource *fm_res; /* used to block FM i/o region for legacy cards */
  55. };
  56. static snd_card_t *snd_sb8_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  57. static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id, struct pt_regs *regs)
  58. {
  59. sb_t *chip = dev_id;
  60. if (chip->open & SB_OPEN_PCM) {
  61. return snd_sb8dsp_interrupt(chip);
  62. } else {
  63. return snd_sb8dsp_midi_interrupt(chip);
  64. }
  65. }
  66. static void snd_sb8_free(snd_card_t *card)
  67. {
  68. struct snd_sb8 *acard = (struct snd_sb8 *)card->private_data;
  69. if (acard == NULL)
  70. return;
  71. if (acard->fm_res) {
  72. release_resource(acard->fm_res);
  73. kfree_nocheck(acard->fm_res);
  74. }
  75. }
  76. static int __init snd_sb8_probe(int dev)
  77. {
  78. sb_t *chip;
  79. snd_card_t *card;
  80. struct snd_sb8 *acard;
  81. opl3_t *opl3;
  82. int err;
  83. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  84. sizeof(struct snd_sb8));
  85. if (card == NULL)
  86. return -ENOMEM;
  87. acard = (struct snd_sb8 *)card->private_data;
  88. card->private_free = snd_sb8_free;
  89. /* block the 0x388 port to avoid PnP conflicts */
  90. acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
  91. if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
  92. snd_sb8_interrupt,
  93. dma8[dev],
  94. -1,
  95. SB_HW_AUTO,
  96. &chip)) < 0) {
  97. snd_card_free(card);
  98. return err;
  99. }
  100. if (chip->hardware >= SB_HW_16) {
  101. snd_card_free(card);
  102. if (chip->hardware == SB_HW_ALS100)
  103. snd_printdd("ALS100 chip detected at 0x%lx, try snd-als100 module\n",
  104. port[dev]);
  105. else
  106. snd_printdd("SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
  107. port[dev]);
  108. return -ENODEV;
  109. }
  110. if ((err = snd_sb8dsp_pcm(chip, 0, NULL)) < 0) {
  111. snd_card_free(card);
  112. return err;
  113. }
  114. if ((err = snd_sbmixer_new(chip)) < 0) {
  115. snd_card_free(card);
  116. return err;
  117. }
  118. if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
  119. if ((err = snd_opl3_create(card, chip->port + 8, 0,
  120. OPL3_HW_AUTO, 1,
  121. &opl3)) < 0) {
  122. snd_printk(KERN_ERR "sb8: no OPL device at 0x%lx\n", chip->port + 8);
  123. }
  124. } else {
  125. if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
  126. OPL3_HW_AUTO, 1,
  127. &opl3)) < 0) {
  128. snd_printk(KERN_ERR "sb8: no OPL device at 0x%lx-0x%lx\n",
  129. chip->port, chip->port + 2);
  130. }
  131. }
  132. if (err >= 0) {
  133. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
  134. snd_card_free(card);
  135. return err;
  136. }
  137. }
  138. if ((err = snd_sb8dsp_midi(chip, 0, NULL)) < 0) {
  139. snd_card_free(card);
  140. return err;
  141. }
  142. strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
  143. strcpy(card->shortname, chip->name);
  144. sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
  145. chip->name,
  146. chip->port,
  147. irq[dev], dma8[dev]);
  148. if ((err = snd_card_register(card)) < 0) {
  149. snd_card_free(card);
  150. return err;
  151. }
  152. snd_sb8_cards[dev] = card;
  153. return 0;
  154. }
  155. static int __init snd_card_sb8_legacy_auto_probe(unsigned long xport)
  156. {
  157. static int dev;
  158. int res;
  159. for ( ; dev < SNDRV_CARDS; dev++) {
  160. if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
  161. continue;
  162. port[dev] = xport;
  163. res = snd_sb8_probe(dev);
  164. if (res < 0)
  165. port[dev] = SNDRV_AUTO_PORT;
  166. return res;
  167. }
  168. return -ENODEV;
  169. }
  170. static int __init alsa_card_sb8_init(void)
  171. {
  172. static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
  173. int dev, cards, i;
  174. for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
  175. if (port[dev] == SNDRV_AUTO_PORT)
  176. continue;
  177. if (snd_sb8_probe(dev) >= 0)
  178. cards++;
  179. }
  180. i = snd_legacy_auto_probe(possible_ports, snd_card_sb8_legacy_auto_probe);
  181. if (i > 0)
  182. cards += i;
  183. if (!cards) {
  184. #ifdef MODULE
  185. snd_printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n");
  186. #endif
  187. return -ENODEV;
  188. }
  189. return 0;
  190. }
  191. static void __exit alsa_card_sb8_exit(void)
  192. {
  193. int idx;
  194. for (idx = 0; idx < SNDRV_CARDS; idx++)
  195. snd_card_free(snd_sb8_cards[idx]);
  196. }
  197. module_init(alsa_card_sb8_init)
  198. module_exit(alsa_card_sb8_exit)