sb8.c 7.0 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/ioport.h>
  25. #include <linux/module.h>
  26. #include <sound/core.h>
  27. #include <sound/sb.h>
  28. #include <sound/opl3.h>
  29. #include <sound/initval.h>
  30. MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
  31. MODULE_DESCRIPTION("Sound Blaster 1.0/2.0/Pro");
  32. MODULE_LICENSE("GPL");
  33. MODULE_SUPPORTED_DEVICE("{{Creative Labs,SB 1.0/SB 2.0/SB Pro}}");
  34. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  35. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  36. static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  37. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260 */
  38. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  39. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 1,3 */
  40. module_param_array(index, int, NULL, 0444);
  41. MODULE_PARM_DESC(index, "Index value for Sound Blaster soundcard.");
  42. module_param_array(id, charp, NULL, 0444);
  43. MODULE_PARM_DESC(id, "ID string for Sound Blaster soundcard.");
  44. module_param_array(enable, bool, NULL, 0444);
  45. MODULE_PARM_DESC(enable, "Enable Sound Blaster soundcard.");
  46. module_param_array(port, long, NULL, 0444);
  47. MODULE_PARM_DESC(port, "Port # for SB8 driver.");
  48. module_param_array(irq, int, NULL, 0444);
  49. MODULE_PARM_DESC(irq, "IRQ # for SB8 driver.");
  50. module_param_array(dma8, int, NULL, 0444);
  51. MODULE_PARM_DESC(dma8, "8-bit DMA # for SB8 driver.");
  52. struct snd_sb8 {
  53. struct resource *fm_res; /* used to block FM i/o region for legacy cards */
  54. struct snd_sb *chip;
  55. };
  56. static irqreturn_t snd_sb8_interrupt(int irq, void *dev_id)
  57. {
  58. struct snd_sb *chip = dev_id;
  59. if (chip->open & SB_OPEN_PCM) {
  60. return snd_sb8dsp_interrupt(chip);
  61. } else {
  62. return snd_sb8dsp_midi_interrupt(chip);
  63. }
  64. }
  65. static void snd_sb8_free(struct snd_card *card)
  66. {
  67. struct snd_sb8 *acard = card->private_data;
  68. if (acard == NULL)
  69. return;
  70. release_and_free_resource(acard->fm_res);
  71. }
  72. static int snd_sb8_match(struct device *pdev, unsigned int dev)
  73. {
  74. if (!enable[dev])
  75. return 0;
  76. if (irq[dev] == SNDRV_AUTO_IRQ) {
  77. dev_err(pdev, "please specify irq\n");
  78. return 0;
  79. }
  80. if (dma8[dev] == SNDRV_AUTO_DMA) {
  81. dev_err(pdev, "please specify dma8\n");
  82. return 0;
  83. }
  84. return 1;
  85. }
  86. static int snd_sb8_probe(struct device *pdev, unsigned int dev)
  87. {
  88. struct snd_sb *chip;
  89. struct snd_card *card;
  90. struct snd_sb8 *acard;
  91. struct snd_opl3 *opl3;
  92. int err;
  93. err = snd_card_new(pdev, index[dev], id[dev], THIS_MODULE,
  94. sizeof(struct snd_sb8), &card);
  95. if (err < 0)
  96. return err;
  97. acard = card->private_data;
  98. card->private_free = snd_sb8_free;
  99. /* block the 0x388 port to avoid PnP conflicts */
  100. acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
  101. if (!acard->fm_res) {
  102. err = -EBUSY;
  103. goto _err;
  104. }
  105. if (port[dev] != SNDRV_AUTO_PORT) {
  106. if ((err = snd_sbdsp_create(card, port[dev], irq[dev],
  107. snd_sb8_interrupt,
  108. dma8[dev],
  109. -1,
  110. SB_HW_AUTO,
  111. &chip)) < 0)
  112. goto _err;
  113. } else {
  114. /* auto-probe legacy ports */
  115. static unsigned long possible_ports[] = {
  116. 0x220, 0x240, 0x260,
  117. };
  118. int i;
  119. for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
  120. err = snd_sbdsp_create(card, possible_ports[i],
  121. irq[dev],
  122. snd_sb8_interrupt,
  123. dma8[dev],
  124. -1,
  125. SB_HW_AUTO,
  126. &chip);
  127. if (err >= 0) {
  128. port[dev] = possible_ports[i];
  129. break;
  130. }
  131. }
  132. if (i >= ARRAY_SIZE(possible_ports)) {
  133. err = -EINVAL;
  134. goto _err;
  135. }
  136. }
  137. acard->chip = chip;
  138. if (chip->hardware >= SB_HW_16) {
  139. if (chip->hardware == SB_HW_ALS100)
  140. snd_printk(KERN_WARNING "ALS100 chip detected at 0x%lx, try snd-als100 module\n",
  141. port[dev]);
  142. else
  143. snd_printk(KERN_WARNING "SB 16 chip detected at 0x%lx, try snd-sb16 module\n",
  144. port[dev]);
  145. err = -ENODEV;
  146. goto _err;
  147. }
  148. if ((err = snd_sb8dsp_pcm(chip, 0)) < 0)
  149. goto _err;
  150. if ((err = snd_sbmixer_new(chip)) < 0)
  151. goto _err;
  152. if (chip->hardware == SB_HW_10 || chip->hardware == SB_HW_20) {
  153. if ((err = snd_opl3_create(card, chip->port + 8, 0,
  154. OPL3_HW_AUTO, 1,
  155. &opl3)) < 0) {
  156. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx\n", chip->port + 8);
  157. }
  158. } else {
  159. if ((err = snd_opl3_create(card, chip->port, chip->port + 2,
  160. OPL3_HW_AUTO, 1,
  161. &opl3)) < 0) {
  162. snd_printk(KERN_WARNING "sb8: no OPL device at 0x%lx-0x%lx\n",
  163. chip->port, chip->port + 2);
  164. }
  165. }
  166. if (err >= 0) {
  167. if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
  168. goto _err;
  169. }
  170. if ((err = snd_sb8dsp_midi(chip, 0)) < 0)
  171. goto _err;
  172. strcpy(card->driver, chip->hardware == SB_HW_PRO ? "SB Pro" : "SB8");
  173. strcpy(card->shortname, chip->name);
  174. sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
  175. chip->name,
  176. chip->port,
  177. irq[dev], dma8[dev]);
  178. if ((err = snd_card_register(card)) < 0)
  179. goto _err;
  180. dev_set_drvdata(pdev, card);
  181. return 0;
  182. _err:
  183. snd_card_free(card);
  184. return err;
  185. }
  186. static int snd_sb8_remove(struct device *pdev, unsigned int dev)
  187. {
  188. snd_card_free(dev_get_drvdata(pdev));
  189. return 0;
  190. }
  191. #ifdef CONFIG_PM
  192. static int snd_sb8_suspend(struct device *dev, unsigned int n,
  193. pm_message_t state)
  194. {
  195. struct snd_card *card = dev_get_drvdata(dev);
  196. struct snd_sb8 *acard = card->private_data;
  197. struct snd_sb *chip = acard->chip;
  198. snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
  199. snd_pcm_suspend_all(chip->pcm);
  200. snd_sbmixer_suspend(chip);
  201. return 0;
  202. }
  203. static int snd_sb8_resume(struct device *dev, unsigned int n)
  204. {
  205. struct snd_card *card = dev_get_drvdata(dev);
  206. struct snd_sb8 *acard = card->private_data;
  207. struct snd_sb *chip = acard->chip;
  208. snd_sbdsp_reset(chip);
  209. snd_sbmixer_resume(chip);
  210. snd_power_change_state(card, SNDRV_CTL_POWER_D0);
  211. return 0;
  212. }
  213. #endif
  214. #define DEV_NAME "sb8"
  215. static struct isa_driver snd_sb8_driver = {
  216. .match = snd_sb8_match,
  217. .probe = snd_sb8_probe,
  218. .remove = snd_sb8_remove,
  219. #ifdef CONFIG_PM
  220. .suspend = snd_sb8_suspend,
  221. .resume = snd_sb8_resume,
  222. #endif
  223. .driver = {
  224. .name = DEV_NAME
  225. },
  226. };
  227. static int __init alsa_card_sb8_init(void)
  228. {
  229. return isa_register_driver(&snd_sb8_driver, SNDRV_CARDS);
  230. }
  231. static void __exit alsa_card_sb8_exit(void)
  232. {
  233. isa_unregister_driver(&snd_sb8_driver);
  234. }
  235. module_init(alsa_card_sb8_init)
  236. module_exit(alsa_card_sb8_exit)