sb8.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. /*
  2. * Driver for SoundBlaster 1.0/2.0/Pro soundcards and compatible
  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. #include <linux/init.h>
  22. #include <linux/err.h>
  23. #include <linux/isa.h>
  24. #include <linux/slab.h>
  25. #include <linux/ioport.h>
  26. #include <linux/moduleparam.h>
  27. #include <sound/core.h>
  28. #include <sound/sb.h>
  29. #include <sound/opl3.h>
  30. #include <sound/initval.h>
  31. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.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. struct snd_sb *chip;
  56. };
  57. static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id)
  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 __devinit snd_sb8_match(struct device *pdev, unsigned int dev)
  74. {
  75. if (!enable[dev])
  76. return 0;
  77. if (irq[dev] == SNDRV_AUTO_IRQ) {
  78. snd_printk(KERN_ERR "%s: please specify irq\n", pdev->bus_id);
  79. return 0;
  80. }
  81. if (dma8[dev] == SNDRV_AUTO_DMA) {
  82. snd_printk(KERN_ERR "%s: please specify dma8\n", pdev->bus_id);
  83. return 0;
  84. }
  85. return 1;
  86. }
  87. static int __devinit snd_sb8_probe(struct device *pdev, unsigned int dev)
  88. {
  89. struct snd_sb *chip;
  90. struct snd_card *card;
  91. struct snd_sb8 *acard;
  92. struct snd_opl3 *opl3;
  93. int err;
  94. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  95. sizeof(struct snd_sb8));
  96. if (card == NULL)
  97. return -ENOMEM;
  98. acard = card->private_data;
  99. card->private_free = snd_sb8_free;
  100. /* block the 0x388 port to avoid PnP conflicts */
  101. acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
  102. if (port[dev] != SNDRV_AUTO_PORT) {
  103. if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
  104. snd_sb8_interrupt,
  105. dma8[dev],
  106. -1,
  107. SB_HW_AUTO,
  108. &chip)) < 0)
  109. goto _err;
  110. } else {
  111. /* auto-probe legacy ports */
  112. static unsigned long possible_ports[] = {
  113. 0x220, 0x240, 0x260,
  114. };
  115. int i;
  116. for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
  117. err = snd_sbdsp_create(card, possible_ports[i],
  118. irq[dev],
  119. snd_sb8_interrupt,
  120. dma8[dev],
  121. -1,
  122. SB_HW_AUTO,
  123. &chip);
  124. if (err >= 0) {
  125. port[dev] = possible_ports[i];
  126. break;
  127. }
  128. }
  129. if (i >= ARRAY_SIZE(possible_ports))
  130. goto _err;
  131. }
  132. acard->chip = chip;
  133. if (chip->hardware >= SB_HW_16) {
  134. if (chip->hardware == SB_HW_ALS100)
  135. snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
  136. port[dev]);
  137. else
  138. snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
  139. port[dev]);
  140. err = -ENODEV;
  141. goto _err;
  142. }
  143. if ((err = snd_sb8dsp_pcm(chip, 0, NULL)) < 0)
  144. goto _err;
  145. if ((err = snd_sbmixer_new(chip)) < 0)
  146. goto _err;
  147. if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
  148. if ((err = snd_opl3_create(card, chip->port + 8, 0,
  149. OPL3_HW_AUTO, 1,
  150. &opl3)) < 0) {
  151. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
  152. }
  153. } else {
  154. if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
  155. OPL3_HW_AUTO, 1,
  156. &opl3)) < 0) {
  157. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
  158. chip->port, chip->port + 2);
  159. }
  160. }
  161. if (err >= 0) {
  162. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  163. goto _err;
  164. }
  165. if ((err = snd_sb8dsp_midi(chip, 0, NULL)) < 0)
  166. goto _err;
  167. strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
  168. strcpy(card->shortname, chip->name);
  169. sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
  170. chip->name,
  171. chip->port,
  172. irq[dev], dma8[dev]);
  173. snd_card_set_dev(card, pdev);
  174. if ((err = snd_card_register(card)) < 0)
  175. goto _err;
  176. dev_set_drvdata(pdev, card);
  177. return 0;
  178. _err:
  179. snd_card_free(card);
  180. return err;
  181. }
  182. static int __devexit snd_sb8_remove(struct device *pdev, unsigned int dev)
  183. {
  184. snd_card_free(dev_get_drvdata(pdev));
  185. dev_set_drvdata(pdev, NULL);
  186. return 0;
  187. }
  188. #ifdef CONFIG_PM
  189. static int snd_sb8_suspend(struct device *dev, unsigned int n,
  190. pm_message_t state)
  191. {
  192. struct snd_card *card = dev_get_drvdata(dev);
  193. struct snd_sb8 *acard = card->private_data;
  194. struct snd_sb *chip = acard->chip;
  195. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  196. snd_pcm_suspend_all(chip->pcm);
  197. snd_sbmixer_suspend(chip);
  198. return 0;
  199. }
  200. static int snd_sb8_resume(struct device *dev, unsigned int n)
  201. {
  202. struct snd_card *card = dev_get_drvdata(dev);
  203. struct snd_sb8 *acard = card->private_data;
  204. struct snd_sb *chip = acard->chip;
  205. snd_sbdsp_reset(chip);
  206. snd_sbmixer_resume(chip);
  207. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  208. return 0;
  209. }
  210. #endif
  211. #define DEV_NAME "sb8"
  212. static struct isa_driver snd_sb8_driver = {
  213. .match = snd_sb8_match,
  214. .probe = snd_sb8_probe,
  215. .remove = __devexit_p(snd_sb8_remove),
  216. #ifdef CONFIG_PM
  217. .suspend = snd_sb8_suspend,
  218. .resume = snd_sb8_resume,
  219. #endif
  220. .driver = {
  221. .name = DEV_NAME
  222. },
  223. };
  224. static int __init alsa_card_sb8_init(void)
  225. {
  226. return isa_register_driver(&snd_sb8_driver, SNDRV_CARDS);
  227. }
  228. static void __exit alsa_card_sb8_exit(void)
  229. {
  230. isa_unregister_driver(&snd_sb8_driver);
  231. }
  232. module_init(alsa_card_sb8_init)
  233. module_exit(alsa_card_sb8_exit)