sb8.c 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. dev_err(pdev, "please specify irq\n");
  79. return 0;
  80. }
  81. if (dma8[dev] == SNDRV_AUTO_DMA) {
  82. dev_err(pdev, "please specify dma8\n");
  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. err = snd_card_create(index[dev], id[dev], THIS_MODULE,
  95. sizeof(struct snd_sb8), &card);
  96. if (err < 0)
  97. return err;
  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. err = -EINVAL;
  131. goto _err;
  132. }
  133. }
  134. acard->chip = chip;
  135. if (chip->hardware >= SB_HW_16) {
  136. if (chip->hardware == SB_HW_ALS100)
  137. snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
  138. port[dev]);
  139. else
  140. snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
  141. port[dev]);
  142. err = -ENODEV;
  143. goto _err;
  144. }
  145. if ((err = snd_sb8dsp_pcm(chip, 0, NULL)) < 0)
  146. goto _err;
  147. if ((err = snd_sbmixer_new(chip)) < 0)
  148. goto _err;
  149. if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
  150. if ((err = snd_opl3_create(card, chip->port + 8, 0,
  151. OPL3_HW_AUTO, 1,
  152. &opl3)) < 0) {
  153. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
  154. }
  155. } else {
  156. if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
  157. OPL3_HW_AUTO, 1,
  158. &opl3)) < 0) {
  159. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
  160. chip->port, chip->port + 2);
  161. }
  162. }
  163. if (err >= 0) {
  164. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  165. goto _err;
  166. }
  167. if ((err = snd_sb8dsp_midi(chip, 0, NULL)) < 0)
  168. goto _err;
  169. strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
  170. strcpy(card->shortname, chip->name);
  171. sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
  172. chip->name,
  173. chip->port,
  174. irq[dev], dma8[dev]);
  175. snd_card_set_dev(card, pdev);
  176. if ((err = snd_card_register(card)) < 0)
  177. goto _err;
  178. dev_set_drvdata(pdev, card);
  179. return 0;
  180. _err:
  181. snd_card_free(card);
  182. return err;
  183. }
  184. static int __devexit snd_sb8_remove(struct device *pdev, unsigned int dev)
  185. {
  186. snd_card_free(dev_get_drvdata(pdev));
  187. dev_set_drvdata(pdev, NULL);
  188. return 0;
  189. }
  190. #ifdef CONFIG_PM
  191. static int snd_sb8_suspend(struct device *dev, unsigned int n,
  192. pm_message_t state)
  193. {
  194. struct snd_card *card = dev_get_drvdata(dev);
  195. struct snd_sb8 *acard = card->private_data;
  196. struct snd_sb *chip = acard->chip;
  197. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  198. snd_pcm_suspend_all(chip->pcm);
  199. snd_sbmixer_suspend(chip);
  200. return 0;
  201. }
  202. static int snd_sb8_resume(struct device *dev, unsigned int n)
  203. {
  204. struct snd_card *card = dev_get_drvdata(dev);
  205. struct snd_sb8 *acard = card->private_data;
  206. struct snd_sb *chip = acard->chip;
  207. snd_sbdsp_reset(chip);
  208. snd_sbmixer_resume(chip);
  209. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  210. return 0;
  211. }
  212. #endif
  213. #define DEV_NAME "sb8"
  214. static struct isa_driver snd_sb8_driver = {
  215. .match = snd_sb8_match,
  216. .probe = snd_sb8_probe,
  217. .remove = __devexit_p(snd_sb8_remove),
  218. #ifdef CONFIG_PM
  219. .suspend = snd_sb8_suspend,
  220. .resume = snd_sb8_resume,
  221. #endif
  222. .driver = {
  223. .name = DEV_NAME
  224. },
  225. };
  226. static int __init alsa_card_sb8_init(void)
  227. {
  228. return isa_register_driver(&snd_sb8_driver, SNDRV_CARDS);
  229. }
  230. static void __exit alsa_card_sb8_exit(void)
  231. {
  232. isa_unregister_driver(&snd_sb8_driver);
  233. }
  234. module_init(alsa_card_sb8_init)
  235. module_exit(alsa_card_sb8_exit)