sb8.c 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 struct snd_card *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. struct snd_sb *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(struct snd_card *card)
  67. {
  68. struct snd_sb8 *acard = (struct snd_sb8 *)card->private_data;
  69. if (acard == NULL)
  70. return;
  71. release_and_free_resource(acard->fm_res);
  72. }
  73. static int __init snd_sb8_probe(int dev)
  74. {
  75. struct snd_sb *chip;
  76. struct snd_card *card;
  77. struct snd_sb8 *acard;
  78. struct snd_opl3 *opl3;
  79. int err;
  80. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  81. sizeof(struct snd_sb8));
  82. if (card == NULL)
  83. return -ENOMEM;
  84. acard = (struct snd_sb8 *)card->private_data;
  85. card->private_free = snd_sb8_free;
  86. /* block the 0x388 port to avoid PnP conflicts */
  87. acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
  88. if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
  89. snd_sb8_interrupt,
  90. dma8[dev],
  91. -1,
  92. SB_HW_AUTO,
  93. &chip)) < 0)
  94. goto _err;
  95. if (chip->hardware >= SB_HW_16) {
  96. if (chip->hardware == SB_HW_ALS100)
  97. snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
  98. port[dev]);
  99. else
  100. snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
  101. port[dev]);
  102. err = -ENODEV;
  103. goto _err;
  104. }
  105. if ((err = snd_sb8dsp_pcm(chip, 0, NULL)) < 0)
  106. goto _err;
  107. if ((err = snd_sbmixer_new(chip)) < 0)
  108. goto _err;
  109. if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
  110. if ((err = snd_opl3_create(card, chip->port + 8, 0,
  111. OPL3_HW_AUTO, 1,
  112. &opl3)) < 0) {
  113. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
  114. }
  115. } else {
  116. if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
  117. OPL3_HW_AUTO, 1,
  118. &opl3)) < 0) {
  119. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
  120. chip->port, chip->port + 2);
  121. }
  122. }
  123. if (err >= 0) {
  124. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  125. goto _err;
  126. }
  127. if ((err = snd_sb8dsp_midi(chip, 0, NULL)) < 0)
  128. goto _err;
  129. strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
  130. strcpy(card->shortname, chip->name);
  131. sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
  132. chip->name,
  133. chip->port,
  134. irq[dev], dma8[dev]);
  135. if ((err = snd_card_set_generic_dev(card)) < 0)
  136. goto _err;
  137. if ((err = snd_card_register(card)) < 0)
  138. goto _err;
  139. snd_sb8_cards[dev] = card;
  140. return 0;
  141. _err:
  142. snd_card_free(card);
  143. return err;
  144. }
  145. static int __init snd_card_sb8_legacy_auto_probe(unsigned long xport)
  146. {
  147. static int dev;
  148. int res;
  149. for ( ; dev < SNDRV_CARDS; dev++) {
  150. if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
  151. continue;
  152. port[dev] = xport;
  153. res = snd_sb8_probe(dev);
  154. if (res < 0)
  155. port[dev] = SNDRV_AUTO_PORT;
  156. return res;
  157. }
  158. return -ENODEV;
  159. }
  160. static int __init alsa_card_sb8_init(void)
  161. {
  162. static unsigned long possible_ports[] = {0x220, 0x240, 0x260, -1};
  163. int dev, cards, i;
  164. for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
  165. if (port[dev] == SNDRV_AUTO_PORT)
  166. continue;
  167. if (snd_sb8_probe(dev) >= 0)
  168. cards++;
  169. }
  170. i = snd_legacy_auto_probe(possible_ports, snd_card_sb8_legacy_auto_probe);
  171. if (i > 0)
  172. cards += i;
  173. if (!cards) {
  174. #ifdef MODULE
  175. snd_printk(KERN_ERR "Sound Blaster soundcard not found or device busy\n");
  176. #endif
  177. return -ENODEV;
  178. }
  179. return 0;
  180. }
  181. static void __exit alsa_card_sb8_exit(void)
  182. {
  183. int idx;
  184. for (idx = 0; idx < SNDRV_CARDS; idx++)
  185. snd_card_free(snd_sb8_cards[idx]);
  186. }
  187. module_init(alsa_card_sb8_init)
  188. module_exit(alsa_card_sb8_exit)