sb16.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. /*
  2. * Driver for SoundBlaster 16/AWE32/AWE64 soundcards
  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 <asm/dma.h>
  23. #include <linux/init.h>
  24. #include <linux/slab.h>
  25. #include <linux/pnp.h>
  26. #include <linux/moduleparam.h>
  27. #include <sound/core.h>
  28. #include <sound/sb.h>
  29. #include <sound/sb16_csp.h>
  30. #include <sound/mpu401.h>
  31. #include <sound/opl3.h>
  32. #include <sound/emu8000.h>
  33. #include <sound/seq_device.h>
  34. #define SNDRV_LEGACY_AUTO_PROBE
  35. #define SNDRV_LEGACY_FIND_FREE_IRQ
  36. #define SNDRV_LEGACY_FIND_FREE_DMA
  37. #include <sound/initval.h>
  38. #ifdef SNDRV_SBAWE
  39. #define PFX "sbawe: "
  40. #else
  41. #define PFX "sb16: "
  42. #endif
  43. MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
  44. MODULE_LICENSE("GPL");
  45. #ifndef SNDRV_SBAWE
  46. MODULE_DESCRIPTION("Sound Blaster 16");
  47. MODULE_SUPPORTED_DEVICE("{{Creative Labs,SB 16},"
  48. "{Creative Labs,SB Vibra16S},"
  49. "{Creative Labs,SB Vibra16C},"
  50. "{Creative Labs,SB Vibra16CL},"
  51. "{Creative Labs,SB Vibra16X}}");
  52. #else
  53. MODULE_DESCRIPTION("Sound Blaster AWE");
  54. MODULE_SUPPORTED_DEVICE("{{Creative Labs,SB AWE 32},"
  55. "{Creative Labs,SB AWE 64},"
  56. "{Creative Labs,SB AWE 64 Gold}}");
  57. #endif
  58. #if 0
  59. #define SNDRV_DEBUG_IRQ
  60. #endif
  61. #if defined(SNDRV_SBAWE) && (defined(CONFIG_SND_SEQUENCER) || (defined(MODULE) && defined(CONFIG_SND_SEQUENCER_MODULE)))
  62. #define SNDRV_SBAWE_EMU8000
  63. #endif
  64. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  65. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  66. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_ISAPNP; /* Enable this card */
  67. #ifdef CONFIG_PNP
  68. static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  69. #endif
  70. static long port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x220,0x240,0x260,0x280 */
  71. static long mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* 0x330,0x300 */
  72. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  73. #ifdef SNDRV_SBAWE_EMU8000
  74. static long awe_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  75. #endif
  76. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,10 */
  77. static int dma8[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3 */
  78. static int dma16[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 5,6,7 */
  79. static int mic_agc[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  80. #ifdef CONFIG_SND_SB16_CSP
  81. static int csp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
  82. #endif
  83. #ifdef SNDRV_SBAWE_EMU8000
  84. static int seq_ports[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 4};
  85. #endif
  86. module_param_array(index, int, NULL, 0444);
  87. MODULE_PARM_DESC(index, "Index value for SoundBlaster 16 soundcard.");
  88. module_param_array(id, charp, NULL, 0444);
  89. MODULE_PARM_DESC(id, "ID string for SoundBlaster 16 soundcard.");
  90. module_param_array(enable, bool, NULL, 0444);
  91. MODULE_PARM_DESC(enable, "Enable SoundBlaster 16 soundcard.");
  92. #ifdef CONFIG_PNP
  93. module_param_array(isapnp, bool, NULL, 0444);
  94. MODULE_PARM_DESC(isapnp, "PnP detection for specified soundcard.");
  95. #endif
  96. module_param_array(port, long, NULL, 0444);
  97. MODULE_PARM_DESC(port, "Port # for SB16 driver.");
  98. module_param_array(mpu_port, long, NULL, 0444);
  99. MODULE_PARM_DESC(mpu_port, "MPU-401 port # for SB16 driver.");
  100. module_param_array(fm_port, long, NULL, 0444);
  101. MODULE_PARM_DESC(fm_port, "FM port # for SB16 PnP driver.");
  102. #ifdef SNDRV_SBAWE_EMU8000
  103. module_param_array(awe_port, long, NULL, 0444);
  104. MODULE_PARM_DESC(awe_port, "AWE port # for SB16 PnP driver.");
  105. #endif
  106. module_param_array(irq, int, NULL, 0444);
  107. MODULE_PARM_DESC(irq, "IRQ # for SB16 driver.");
  108. module_param_array(dma8, int, NULL, 0444);
  109. MODULE_PARM_DESC(dma8, "8-bit DMA # for SB16 driver.");
  110. module_param_array(dma16, int, NULL, 0444);
  111. MODULE_PARM_DESC(dma16, "16-bit DMA # for SB16 driver.");
  112. module_param_array(mic_agc, int, NULL, 0444);
  113. MODULE_PARM_DESC(mic_agc, "Mic Auto-Gain-Control switch.");
  114. #ifdef CONFIG_SND_SB16_CSP
  115. module_param_array(csp, int, NULL, 0444);
  116. MODULE_PARM_DESC(csp, "ASP/CSP chip support.");
  117. #endif
  118. #ifdef SNDRV_SBAWE_EMU8000
  119. module_param_array(seq_ports, int, NULL, 0444);
  120. MODULE_PARM_DESC(seq_ports, "Number of sequencer ports for WaveTable synth.");
  121. #endif
  122. struct snd_card_sb16 {
  123. struct resource *fm_res; /* used to block FM i/o region for legacy cards */
  124. #ifdef CONFIG_PNP
  125. int dev_no;
  126. struct pnp_dev *dev;
  127. #ifdef SNDRV_SBAWE_EMU8000
  128. struct pnp_dev *devwt;
  129. #endif
  130. #endif
  131. };
  132. static snd_card_t *snd_sb16_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  133. #ifdef CONFIG_PNP
  134. static struct pnp_card_device_id snd_sb16_pnpids[] = {
  135. #ifndef SNDRV_SBAWE
  136. /* Sound Blaster 16 PnP */
  137. { .id = "CTL0024", .devs = { { "CTL0031" } } },
  138. /* Sound Blaster 16 PnP */
  139. { .id = "CTL0025", .devs = { { "CTL0031" } } },
  140. /* Sound Blaster 16 PnP */
  141. { .id = "CTL0026", .devs = { { "CTL0031" } } },
  142. /* Sound Blaster 16 PnP */
  143. { .id = "CTL0027", .devs = { { "CTL0031" } } },
  144. /* Sound Blaster 16 PnP */
  145. { .id = "CTL0028", .devs = { { "CTL0031" } } },
  146. /* Sound Blaster 16 PnP */
  147. { .id = "CTL0029", .devs = { { "CTL0031" } } },
  148. /* Sound Blaster 16 PnP */
  149. { .id = "CTL002a", .devs = { { "CTL0031" } } },
  150. /* Sound Blaster 16 PnP */
  151. /* Note: This card has also a CTL0051:StereoEnhance device!!! */
  152. { .id = "CTL002b", .devs = { { "CTL0031" } } },
  153. /* Sound Blaster 16 PnP */
  154. { .id = "CTL002c", .devs = { { "CTL0031" } } },
  155. /* Sound Blaster Vibra16S */
  156. { .id = "CTL0051", .devs = { { "CTL0001" } } },
  157. /* Sound Blaster Vibra16C */
  158. { .id = "CTL0070", .devs = { { "CTL0001" } } },
  159. /* Sound Blaster Vibra16CL - added by ctm@ardi.com */
  160. { .id = "CTL0080", .devs = { { "CTL0041" } } },
  161. /* Sound Blaster 16 'value' PnP. It says model ct4130 on the pcb, */
  162. /* but ct4131 on a sticker on the board.. */
  163. { .id = "CTL0086", .devs = { { "CTL0041" } } },
  164. /* Sound Blaster Vibra16X */
  165. { .id = "CTL00f0", .devs = { { "CTL0043" } } },
  166. #else /* SNDRV_SBAWE defined */
  167. /* Sound Blaster AWE 32 PnP */
  168. { .id = "CTL0035", .devs = { { "CTL0031" }, { "CTL0021" } } },
  169. /* Sound Blaster AWE 32 PnP */
  170. { .id = "CTL0039", .devs = { { "CTL0031" }, { "CTL0021" } } },
  171. /* Sound Blaster AWE 32 PnP */
  172. { .id = "CTL0042", .devs = { { "CTL0031" }, { "CTL0021" } } },
  173. /* Sound Blaster AWE 32 PnP */
  174. { .id = "CTL0043", .devs = { { "CTL0031" }, { "CTL0021" } } },
  175. /* Sound Blaster AWE 32 PnP */
  176. /* Note: This card has also a CTL0051:StereoEnhance device!!! */
  177. { .id = "CTL0044", .devs = { { "CTL0031" }, { "CTL0021" } } },
  178. /* Sound Blaster AWE 32 PnP */
  179. /* Note: This card has also a CTL0051:StereoEnhance device!!! */
  180. { .id = "CTL0045", .devs = { { "CTL0031" }, { "CTL0021" } } },
  181. /* Sound Blaster AWE 32 PnP */
  182. { .id = "CTL0046", .devs = { { "CTL0031" }, { "CTL0021" } } },
  183. /* Sound Blaster AWE 32 PnP */
  184. { .id = "CTL0047", .devs = { { "CTL0031" }, { "CTL0021" } } },
  185. /* Sound Blaster AWE 32 PnP */
  186. { .id = "CTL0048", .devs = { { "CTL0031" }, { "CTL0021" } } },
  187. /* Sound Blaster AWE 32 PnP */
  188. { .id = "CTL0054", .devs = { { "CTL0031" }, { "CTL0021" } } },
  189. /* Sound Blaster AWE 32 PnP */
  190. { .id = "CTL009a", .devs = { { "CTL0041" }, { "CTL0021" } } },
  191. /* Sound Blaster AWE 32 PnP */
  192. { .id = "CTL009c", .devs = { { "CTL0041" }, { "CTL0021" } } },
  193. /* Sound Blaster 32 PnP */
  194. { .id = "CTL009f", .devs = { { "CTL0041" }, { "CTL0021" } } },
  195. /* Sound Blaster AWE 64 PnP */
  196. { .id = "CTL009d", .devs = { { "CTL0042" }, { "CTL0022" } } },
  197. /* Sound Blaster AWE 64 PnP Gold */
  198. { .id = "CTL009e", .devs = { { "CTL0044" }, { "CTL0023" } } },
  199. /* Sound Blaster AWE 64 PnP Gold */
  200. { .id = "CTL00b2", .devs = { { "CTL0044" }, { "CTL0023" } } },
  201. /* Sound Blaster AWE 64 PnP */
  202. { .id = "CTL00c1", .devs = { { "CTL0042" }, { "CTL0022" } } },
  203. /* Sound Blaster AWE 64 PnP */
  204. { .id = "CTL00c3", .devs = { { "CTL0045" }, { "CTL0022" } } },
  205. /* Sound Blaster AWE 64 PnP */
  206. { .id = "CTL00c5", .devs = { { "CTL0045" }, { "CTL0022" } } },
  207. /* Sound Blaster AWE 64 PnP */
  208. { .id = "CTL00c7", .devs = { { "CTL0045" }, { "CTL0022" } } },
  209. /* Sound Blaster AWE 64 PnP */
  210. { .id = "CTL00e4", .devs = { { "CTL0045" }, { "CTL0022" } } },
  211. /* Sound Blaster AWE 64 PnP */
  212. { .id = "CTL00e9", .devs = { { "CTL0045" }, { "CTL0022" } } },
  213. /* Sound Blaster 16 PnP (AWE) */
  214. { .id = "CTL00ed", .devs = { { "CTL0041" }, { "CTL0070" } } },
  215. /* Generic entries */
  216. { .id = "CTLXXXX" , .devs = { { "CTL0031" }, { "CTL0021" } } },
  217. { .id = "CTLXXXX" , .devs = { { "CTL0041" }, { "CTL0021" } } },
  218. { .id = "CTLXXXX" , .devs = { { "CTL0042" }, { "CTL0022" } } },
  219. { .id = "CTLXXXX" , .devs = { { "CTL0044" }, { "CTL0023" } } },
  220. { .id = "CTLXXXX" , .devs = { { "CTL0045" }, { "CTL0022" } } },
  221. #endif /* SNDRV_SBAWE */
  222. /* Sound Blaster 16 PnP (Virtual PC 2004)*/
  223. { .id = "tBA03b0", .devs = { { "PNPb003" } } },
  224. { .id = "", }
  225. };
  226. MODULE_DEVICE_TABLE(pnp_card, snd_sb16_pnpids);
  227. #endif /* CONFIG_PNP */
  228. #ifdef SNDRV_SBAWE_EMU8000
  229. #define DRIVER_NAME "snd-card-sbawe"
  230. #else
  231. #define DRIVER_NAME "snd-card-sb16"
  232. #endif
  233. #ifdef CONFIG_PNP
  234. static int __devinit snd_card_sb16_pnp(int dev, struct snd_card_sb16 *acard,
  235. struct pnp_card_link *card,
  236. const struct pnp_card_device_id *id)
  237. {
  238. struct pnp_dev *pdev;
  239. struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
  240. int err;
  241. if (!cfg)
  242. return -ENOMEM;
  243. acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
  244. if (acard->dev == NULL) {
  245. kfree(cfg);
  246. return -ENODEV;
  247. }
  248. #ifdef SNDRV_SBAWE_EMU8000
  249. acard->devwt = pnp_request_card_device(card, id->devs[1].id, acard->dev);
  250. #endif
  251. /* Audio initialization */
  252. pdev = acard->dev;
  253. pnp_init_resource_table(cfg);
  254. /* override resources */
  255. if (port[dev] != SNDRV_AUTO_PORT)
  256. pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
  257. if (mpu_port[dev] != SNDRV_AUTO_PORT)
  258. pnp_resource_change(&cfg->port_resource[1], mpu_port[dev], 2);
  259. if (fm_port[dev] != SNDRV_AUTO_PORT)
  260. pnp_resource_change(&cfg->port_resource[2], fm_port[dev], 4);
  261. if (dma8[dev] != SNDRV_AUTO_DMA)
  262. pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
  263. if (dma16[dev] != SNDRV_AUTO_DMA)
  264. pnp_resource_change(&cfg->dma_resource[1], dma16[dev], 1);
  265. if (irq[dev] != SNDRV_AUTO_IRQ)
  266. pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
  267. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  268. snd_printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
  269. err = pnp_activate_dev(pdev);
  270. if (err < 0) {
  271. snd_printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
  272. kfree(cfg);
  273. return err;
  274. }
  275. port[dev] = pnp_port_start(pdev, 0);
  276. mpu_port[dev] = pnp_port_start(pdev, 1);
  277. fm_port[dev] = pnp_port_start(pdev, 2);
  278. dma8[dev] = pnp_dma(pdev, 0);
  279. dma16[dev] = pnp_dma(pdev, 1);
  280. irq[dev] = pnp_irq(pdev, 0);
  281. snd_printdd("pnp SB16: port=0x%lx, mpu port=0x%lx, fm port=0x%lx\n",
  282. port[dev], mpu_port[dev], fm_port[dev]);
  283. snd_printdd("pnp SB16: dma1=%i, dma2=%i, irq=%i\n",
  284. dma8[dev], dma16[dev], irq[dev]);
  285. #ifdef SNDRV_SBAWE_EMU8000
  286. /* WaveTable initialization */
  287. pdev = acard->devwt;
  288. if (pdev != NULL) {
  289. pnp_init_resource_table(cfg);
  290. /* override resources */
  291. if (awe_port[dev] != SNDRV_AUTO_PORT) {
  292. pnp_resource_change(&cfg->port_resource[0], awe_port[dev], 4);
  293. pnp_resource_change(&cfg->port_resource[1], awe_port[dev] + 0x400, 4);
  294. pnp_resource_change(&cfg->port_resource[2], awe_port[dev] + 0x800, 4);
  295. }
  296. if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
  297. snd_printk(KERN_ERR PFX "WaveTable the requested resources are invalid, using auto config\n");
  298. err = pnp_activate_dev(pdev);
  299. if (err < 0) {
  300. goto __wt_error;
  301. }
  302. awe_port[dev] = pnp_port_start(pdev, 0);
  303. snd_printdd("pnp SB16: wavetable port=0x%lx\n", pnp_port_start(pdev, 0));
  304. } else {
  305. __wt_error:
  306. if (pdev) {
  307. pnp_release_card_device(pdev);
  308. snd_printk(KERN_ERR PFX "WaveTable pnp configure failure\n");
  309. }
  310. acard->devwt = NULL;
  311. awe_port[dev] = -1;
  312. }
  313. #endif
  314. kfree(cfg);
  315. return 0;
  316. }
  317. #endif /* CONFIG_PNP */
  318. static void snd_sb16_free(snd_card_t *card)
  319. {
  320. struct snd_card_sb16 *acard = (struct snd_card_sb16 *)card->private_data;
  321. if (acard == NULL)
  322. return;
  323. release_and_free_resource(acard->fm_res);
  324. }
  325. #ifdef CONFIG_PNP
  326. #define is_isapnp_selected(dev) isapnp[dev]
  327. #else
  328. #define is_isapnp_selected(dev) 0
  329. #endif
  330. static int __init snd_sb16_probe(int dev,
  331. struct pnp_card_link *pcard,
  332. const struct pnp_card_device_id *pid)
  333. {
  334. static int possible_irqs[] = {5, 9, 10, 7, -1};
  335. static int possible_dmas8[] = {1, 3, 0, -1};
  336. static int possible_dmas16[] = {5, 6, 7, -1};
  337. int xirq, xdma8, xdma16;
  338. sb_t *chip;
  339. snd_card_t *card;
  340. struct snd_card_sb16 *acard;
  341. opl3_t *opl3;
  342. snd_hwdep_t *synth = NULL;
  343. #ifdef CONFIG_SND_SB16_CSP
  344. snd_hwdep_t *xcsp = NULL;
  345. #endif
  346. unsigned long flags;
  347. int err;
  348. card = snd_card_new(index[dev], id[dev], THIS_MODULE,
  349. sizeof(struct snd_card_sb16));
  350. if (card == NULL)
  351. return -ENOMEM;
  352. acard = (struct snd_card_sb16 *) card->private_data;
  353. card->private_free = snd_sb16_free;
  354. #ifdef CONFIG_PNP
  355. if (isapnp[dev]) {
  356. if ((err = snd_card_sb16_pnp(dev, acard, pcard, pid)))
  357. goto _err;
  358. snd_card_set_dev(card, &pcard->card->dev);
  359. }
  360. #endif
  361. xirq = irq[dev];
  362. xdma8 = dma8[dev];
  363. xdma16 = dma16[dev];
  364. if (! is_isapnp_selected(dev)) {
  365. if (xirq == SNDRV_AUTO_IRQ) {
  366. if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
  367. snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
  368. err = -EBUSY;
  369. goto _err;
  370. }
  371. }
  372. if (xdma8 == SNDRV_AUTO_DMA) {
  373. if ((xdma8 = snd_legacy_find_free_dma(possible_dmas8)) < 0) {
  374. snd_printk(KERN_ERR PFX "unable to find a free 8-bit DMA\n");
  375. err = -EBUSY;
  376. goto _err;
  377. }
  378. }
  379. if (xdma16 == SNDRV_AUTO_DMA) {
  380. if ((xdma16 = snd_legacy_find_free_dma(possible_dmas16)) < 0) {
  381. snd_printk(KERN_ERR PFX "unable to find a free 16-bit DMA\n");
  382. err = -EBUSY;
  383. goto _err;
  384. }
  385. }
  386. /* non-PnP FM port address is hardwired with base port address */
  387. fm_port[dev] = port[dev];
  388. /* block the 0x388 port to avoid PnP conflicts */
  389. acard->fm_res = request_region(0x388, 4, "SoundBlaster FM");
  390. #ifdef SNDRV_SBAWE_EMU8000
  391. /* non-PnP AWE port address is hardwired with base port address */
  392. awe_port[dev] = port[dev] + 0x400;
  393. #endif
  394. }
  395. if ((err = snd_sbdsp_create(card,
  396. port[dev],
  397. xirq,
  398. snd_sb16dsp_interrupt,
  399. xdma8,
  400. xdma16,
  401. SB_HW_AUTO,
  402. &chip)) < 0)
  403. goto _err;
  404. if (chip->hardware != SB_HW_16) {
  405. snd_printk(KERN_ERR PFX "SB 16 chip was not detected at 0x%lx\n", port[dev]);
  406. err = -ENODEV;
  407. goto _err;
  408. }
  409. chip->mpu_port = mpu_port[dev];
  410. if (! is_isapnp_selected(dev) && (err = snd_sb16dsp_configure(chip)) < 0)
  411. goto _err;
  412. if ((err = snd_sb16dsp_pcm(chip, 0, NULL)) < 0)
  413. goto _err;
  414. strcpy(card->driver,
  415. #ifdef SNDRV_SBAWE_EMU8000
  416. awe_port[dev] > 0 ? "SB AWE" :
  417. #endif
  418. "SB16");
  419. strcpy(card->shortname, chip->name);
  420. sprintf(card->longname, "%s at 0x%lx, irq %i, dma ",
  421. chip->name,
  422. chip->port,
  423. xirq);
  424. if (xdma8 >= 0)
  425. sprintf(card->longname + strlen(card->longname), "%d", xdma8);
  426. if (xdma16 >= 0)
  427. sprintf(card->longname + strlen(card->longname), "%s%d",
  428. xdma8 >= 0 ? "&" : "", xdma16);
  429. if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
  430. if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
  431. chip->mpu_port, 0,
  432. xirq, 0, &chip->rmidi)) < 0)
  433. goto _err;
  434. chip->rmidi_callback = snd_mpu401_uart_interrupt;
  435. }
  436. #ifdef SNDRV_SBAWE_EMU8000
  437. if (awe_port[dev] == SNDRV_AUTO_PORT)
  438. awe_port[dev] = 0; /* disable */
  439. #endif
  440. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  441. if (snd_opl3_create(card, fm_port[dev], fm_port[dev] + 2,
  442. OPL3_HW_OPL3,
  443. acard->fm_res != NULL || fm_port[dev] == port[dev],
  444. &opl3) < 0) {
  445. snd_printk(KERN_ERR PFX "no OPL device at 0x%lx-0x%lx\n",
  446. fm_port[dev], fm_port[dev] + 2);
  447. } else {
  448. #ifdef SNDRV_SBAWE_EMU8000
  449. int seqdev = awe_port[dev] > 0 ? 2 : 1;
  450. #else
  451. int seqdev = 1;
  452. #endif
  453. if ((err = snd_opl3_hwdep_new(opl3, 0, seqdev, &synth)) < 0)
  454. goto _err;
  455. }
  456. }
  457. if ((err = snd_sbmixer_new(chip)) < 0)
  458. goto _err;
  459. #ifdef CONFIG_SND_SB16_CSP
  460. /* CSP chip on SB16ASP/AWE32 */
  461. if ((chip->hardware == SB_HW_16) && csp[dev]) {
  462. snd_sb_csp_new(chip, synth != NULL ? 1 : 0, &xcsp);
  463. if (xcsp) {
  464. chip->csp = xcsp->private_data;
  465. chip->hardware = SB_HW_16CSP;
  466. } else {
  467. snd_printk(KERN_INFO PFX "warning - CSP chip not detected on soundcard #%i\n", dev + 1);
  468. }
  469. }
  470. #endif
  471. #ifdef SNDRV_SBAWE_EMU8000
  472. if (awe_port[dev] > 0) {
  473. if ((err = snd_emu8000_new(card, 1, awe_port[dev],
  474. seq_ports[dev], NULL)) < 0) {
  475. snd_printk(KERN_ERR PFX "fatal error - EMU-8000 synthesizer not detected at 0x%lx\n", awe_port[dev]);
  476. goto _err;
  477. }
  478. }
  479. #endif
  480. /* setup Mic AGC */
  481. spin_lock_irqsave(&chip->mixer_lock, flags);
  482. snd_sbmixer_write(chip, SB_DSP4_MIC_AGC,
  483. (snd_sbmixer_read(chip, SB_DSP4_MIC_AGC) & 0x01) |
  484. (mic_agc[dev] ? 0x00 : 0x01));
  485. spin_unlock_irqrestore(&chip->mixer_lock, flags);
  486. if ((err = snd_card_set_generic_dev(card)) < 0)
  487. goto _err;
  488. if ((err = snd_card_register(card)) < 0)
  489. goto _err;
  490. if (pcard)
  491. pnp_set_card_drvdata(pcard, card);
  492. else
  493. snd_sb16_legacy[dev] = card;
  494. return 0;
  495. _err:
  496. snd_card_free(card);
  497. return err;
  498. }
  499. static int __init snd_sb16_probe_legacy_port(unsigned long xport)
  500. {
  501. static int dev;
  502. int res;
  503. for ( ; dev < SNDRV_CARDS; dev++) {
  504. if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
  505. continue;
  506. if (is_isapnp_selected(dev))
  507. continue;
  508. port[dev] = xport;
  509. res = snd_sb16_probe(dev, NULL, NULL);
  510. if (res < 0)
  511. port[dev] = SNDRV_AUTO_PORT;
  512. return res;
  513. }
  514. return -ENODEV;
  515. }
  516. #ifdef CONFIG_PNP
  517. static int __devinit snd_sb16_pnp_detect(struct pnp_card_link *card,
  518. const struct pnp_card_device_id *id)
  519. {
  520. static int dev;
  521. int res;
  522. for ( ; dev < SNDRV_CARDS; dev++) {
  523. if (!enable[dev] || !isapnp[dev])
  524. continue;
  525. res = snd_sb16_probe(dev, card, id);
  526. if (res < 0)
  527. return res;
  528. dev++;
  529. return 0;
  530. }
  531. return -ENODEV;
  532. }
  533. static void __devexit snd_sb16_pnp_remove(struct pnp_card_link * pcard)
  534. {
  535. snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
  536. snd_card_disconnect(card);
  537. snd_card_free_in_thread(card);
  538. }
  539. static struct pnp_card_driver sb16_pnpc_driver = {
  540. .flags = PNP_DRIVER_RES_DISABLE,
  541. .name = "sb16",
  542. .id_table = snd_sb16_pnpids,
  543. .probe = snd_sb16_pnp_detect,
  544. .remove = __devexit_p(snd_sb16_pnp_remove),
  545. };
  546. #endif /* CONFIG_PNP */
  547. static int __init alsa_card_sb16_init(void)
  548. {
  549. int dev, cards = 0, i;
  550. static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
  551. /* legacy non-auto cards at first */
  552. for (dev = 0; dev < SNDRV_CARDS; dev++) {
  553. if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
  554. continue;
  555. if (is_isapnp_selected(dev))
  556. continue;
  557. if (!snd_sb16_probe(dev, NULL, NULL)) {
  558. cards++;
  559. continue;
  560. }
  561. #ifdef MODULE
  562. snd_printk(KERN_ERR "Sound Blaster 16+ soundcard #%i not found at 0x%lx or device busy\n", dev, port[dev]);
  563. #endif
  564. }
  565. /* legacy auto configured cards */
  566. i = snd_legacy_auto_probe(possible_ports, snd_sb16_probe_legacy_port);
  567. if (i > 0)
  568. cards += i;
  569. #ifdef CONFIG_PNP
  570. /* PnP cards at last */
  571. i = pnp_register_card_driver(&sb16_pnpc_driver);
  572. if (i >0)
  573. cards += i;
  574. #endif
  575. if (!cards) {
  576. #ifdef CONFIG_PNP
  577. pnp_unregister_card_driver(&sb16_pnpc_driver);
  578. #endif
  579. #ifdef MODULE
  580. snd_printk(KERN_ERR "Sound Blaster 16 soundcard not found or device busy\n");
  581. #ifdef SNDRV_SBAWE_EMU8000
  582. snd_printk(KERN_ERR "In case, if you have non-AWE card, try snd-sb16 module\n");
  583. #else
  584. snd_printk(KERN_ERR "In case, if you have AWE card, try snd-sbawe module\n");
  585. #endif
  586. #endif
  587. return -ENODEV;
  588. }
  589. return 0;
  590. }
  591. static void __exit alsa_card_sb16_exit(void)
  592. {
  593. int dev;
  594. #ifdef CONFIG_PNP
  595. /* PnP cards first */
  596. pnp_unregister_card_driver(&sb16_pnpc_driver);
  597. #endif
  598. for (dev = 0; dev < SNDRV_CARDS; dev++)
  599. snd_card_free(snd_sb16_legacy[dev]);
  600. }
  601. module_init(alsa_card_sb16_init)
  602. module_exit(alsa_card_sb16_exit)