sb16.c 22 KB

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