sb16.c 18 KB

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