sb16.c 20 KB

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