wavefront.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718
  1. /*
  2. * ALSA card-level driver for Turtle Beach Wavefront cards
  3. * (Maui,Tropez,Tropez+)
  4. *
  5. * Copyright (c) 1997-1999 by Paul Barton-Davis <pbd@op.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <sound/driver.h>
  22. #include <linux/init.h>
  23. #include <linux/interrupt.h>
  24. #include <linux/slab.h>
  25. #include <linux/pnp.h>
  26. #include <linux/moduleparam.h>
  27. #include <sound/core.h>
  28. #include <sound/initval.h>
  29. #include <sound/opl3.h>
  30. #include <sound/snd_wavefront.h>
  31. MODULE_AUTHOR("Paul Barton-Davis <pbd@op.net>");
  32. MODULE_DESCRIPTION("Turtle Beach Wavefront");
  33. MODULE_LICENSE("GPL");
  34. MODULE_SUPPORTED_DEVICE("{{Turtle Beach,Maui/Tropez/Tropez+}}");
  35. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  36. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  37. static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE; /* Enable this card */
  38. static int isapnp[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 1};
  39. static long cs4232_pcm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  40. static int cs4232_pcm_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 5,7,9,11,12,15 */
  41. static long cs4232_mpu_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  42. static int cs4232_mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 9,11,12,15 */
  43. static long ics2115_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  44. static int ics2115_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ; /* 2,9,11,12,15 */
  45. static long fm_port[SNDRV_CARDS] = SNDRV_DEFAULT_PORT; /* PnP setup */
  46. static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  47. static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA; /* 0,1,3,5,6,7 */
  48. static int use_cs4232_midi[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
  49. module_param_array(index, int, NULL, 0444);
  50. MODULE_PARM_DESC(index, "Index value for WaveFront soundcard.");
  51. module_param_array(id, charp, NULL, 0444);
  52. MODULE_PARM_DESC(id, "ID string for WaveFront soundcard.");
  53. module_param_array(enable, bool, NULL, 0444);
  54. MODULE_PARM_DESC(enable, "Enable WaveFront soundcard.");
  55. #ifdef CONFIG_PNP
  56. module_param_array(isapnp, bool, NULL, 0444);
  57. MODULE_PARM_DESC(isapnp, "ISA PnP detection for WaveFront soundcards.");
  58. #endif
  59. module_param_array(cs4232_pcm_port, long, NULL, 0444);
  60. MODULE_PARM_DESC(cs4232_pcm_port, "Port # for CS4232 PCM interface.");
  61. module_param_array(cs4232_pcm_irq, int, NULL, 0444);
  62. MODULE_PARM_DESC(cs4232_pcm_irq, "IRQ # for CS4232 PCM interface.");
  63. module_param_array(dma1, int, NULL, 0444);
  64. MODULE_PARM_DESC(dma1, "DMA1 # for CS4232 PCM interface.");
  65. module_param_array(dma2, int, NULL, 0444);
  66. MODULE_PARM_DESC(dma2, "DMA2 # for CS4232 PCM interface.");
  67. module_param_array(cs4232_mpu_port, long, NULL, 0444);
  68. MODULE_PARM_DESC(cs4232_mpu_port, "port # for CS4232 MPU-401 interface.");
  69. module_param_array(cs4232_mpu_irq, int, NULL, 0444);
  70. MODULE_PARM_DESC(cs4232_mpu_irq, "IRQ # for CS4232 MPU-401 interface.");
  71. module_param_array(ics2115_irq, int, NULL, 0444);
  72. MODULE_PARM_DESC(ics2115_irq, "IRQ # for ICS2115.");
  73. module_param_array(ics2115_port, long, NULL, 0444);
  74. MODULE_PARM_DESC(ics2115_port, "Port # for ICS2115.");
  75. module_param_array(fm_port, long, NULL, 0444);
  76. MODULE_PARM_DESC(fm_port, "FM port #.");
  77. module_param_array(use_cs4232_midi, bool, NULL, 0444);
  78. MODULE_PARM_DESC(use_cs4232_midi, "Use CS4232 MPU-401 interface (inaccessibly located inside your computer)");
  79. static snd_card_t *snd_wavefront_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
  80. #ifdef CONFIG_PNP
  81. static struct pnp_card_device_id snd_wavefront_pnpids[] = {
  82. /* Tropez */
  83. { .id = "CSC7532", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
  84. /* Tropez+ */
  85. { .id = "CSC7632", .devs = { { "CSC0000" }, { "CSC0010" }, { "PnPb006" }, { "CSC0004" } } },
  86. { .id = "" }
  87. };
  88. MODULE_DEVICE_TABLE(pnp_card, snd_wavefront_pnpids);
  89. static int __devinit
  90. snd_wavefront_pnp (int dev, snd_wavefront_card_t *acard, struct pnp_card_link *card,
  91. const struct pnp_card_device_id *id)
  92. {
  93. struct pnp_dev *pdev;
  94. struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
  95. int err;
  96. if (!cfg)
  97. return -ENOMEM;
  98. /* Check for each logical device. */
  99. /* CS4232 chip (aka "windows sound system") is logical device 0 */
  100. acard->wss = pnp_request_card_device(card, id->devs[0].id, NULL);
  101. if (acard->wss == NULL) {
  102. kfree(cfg);
  103. return -EBUSY;
  104. }
  105. /* there is a game port at logical device 1, but we ignore it completely */
  106. /* the control interface is logical device 2, but we ignore it
  107. completely. in fact, nobody even seems to know what it
  108. does.
  109. */
  110. /* Only configure the CS4232 MIDI interface if its been
  111. specifically requested. It is logical device 3.
  112. */
  113. if (use_cs4232_midi[dev]) {
  114. acard->mpu = pnp_request_card_device(card, id->devs[2].id, NULL);
  115. if (acard->mpu == NULL) {
  116. kfree(cfg);
  117. return -EBUSY;
  118. }
  119. }
  120. /* The ICS2115 synth is logical device 4 */
  121. acard->synth = pnp_request_card_device(card, id->devs[3].id, NULL);
  122. if (acard->synth == NULL) {
  123. kfree(cfg);
  124. return -EBUSY;
  125. }
  126. /* PCM/FM initialization */
  127. pdev = acard->wss;
  128. pnp_init_resource_table(cfg);
  129. /* An interesting note from the Tropez+ FAQ:
  130. Q. [Ports] Why is the base address of the WSS I/O ports off by 4?
  131. A. WSS I/O requires a block of 8 I/O addresses ("ports"). Of these, the first
  132. 4 are used to identify and configure the board. With the advent of PnP,
  133. these first 4 addresses have become obsolete, and software applications
  134. only use the last 4 addresses to control the codec chip. Therefore, the
  135. base address setting "skips past" the 4 unused addresses.
  136. */
  137. if (cs4232_pcm_port[dev] != SNDRV_AUTO_PORT)
  138. pnp_resource_change(&cfg->port_resource[0], cs4232_pcm_port[dev], 4);
  139. if (fm_port[dev] != SNDRV_AUTO_PORT)
  140. pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
  141. if (dma1[dev] != SNDRV_AUTO_DMA)
  142. pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
  143. if (dma2[dev] != SNDRV_AUTO_DMA)
  144. pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
  145. if (cs4232_pcm_irq[dev] != SNDRV_AUTO_IRQ)
  146. pnp_resource_change(&cfg->irq_resource[0], cs4232_pcm_irq[dev], 1);
  147. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  148. snd_printk(KERN_ERR "PnP WSS the requested resources are invalid, using auto config\n");
  149. err = pnp_activate_dev(pdev);
  150. if (err < 0) {
  151. snd_printk(KERN_ERR "PnP WSS pnp configure failure\n");
  152. kfree(cfg);
  153. return err;
  154. }
  155. cs4232_pcm_port[dev] = pnp_port_start(pdev, 0);
  156. fm_port[dev] = pnp_port_start(pdev, 1);
  157. dma1[dev] = pnp_dma(pdev, 0);
  158. dma2[dev] = pnp_dma(pdev, 1);
  159. cs4232_pcm_irq[dev] = pnp_irq(pdev, 0);
  160. /* Synth initialization */
  161. pdev = acard->synth;
  162. pnp_init_resource_table(cfg);
  163. if (ics2115_port[dev] != SNDRV_AUTO_PORT) {
  164. pnp_resource_change(&cfg->port_resource[0], ics2115_port[dev], 16);
  165. }
  166. if (ics2115_port[dev] != SNDRV_AUTO_IRQ) {
  167. pnp_resource_change(&cfg->irq_resource[0], ics2115_irq[dev], 1);
  168. }
  169. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  170. snd_printk(KERN_ERR "PnP ICS2115 the requested resources are invalid, using auto config\n");
  171. err = pnp_activate_dev(pdev);
  172. if (err < 0) {
  173. snd_printk(KERN_ERR "PnP ICS2115 pnp configure failure\n");
  174. kfree(cfg);
  175. return err;
  176. }
  177. ics2115_port[dev] = pnp_port_start(pdev, 0);
  178. ics2115_irq[dev] = pnp_irq(pdev, 0);
  179. /* CS4232 MPU initialization. Configure this only if
  180. explicitly requested, since its physically inaccessible and
  181. consumes another IRQ.
  182. */
  183. if (use_cs4232_midi[dev]) {
  184. pdev = acard->mpu;
  185. pnp_init_resource_table(cfg);
  186. if (cs4232_mpu_port[dev] != SNDRV_AUTO_PORT)
  187. pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_port[dev], 2);
  188. if (cs4232_mpu_irq[dev] != SNDRV_AUTO_IRQ)
  189. pnp_resource_change(&cfg->port_resource[0], cs4232_mpu_irq[dev], 1);
  190. if (pnp_manual_config_dev(pdev, cfg, 0) < 0)
  191. snd_printk(KERN_ERR "PnP MPU401 the requested resources are invalid, using auto config\n");
  192. err = pnp_activate_dev(pdev);
  193. if (err < 0) {
  194. snd_printk(KERN_ERR "PnP MPU401 pnp configure failure\n");
  195. cs4232_mpu_port[dev] = SNDRV_AUTO_PORT;
  196. } else {
  197. cs4232_mpu_port[dev] = pnp_port_start(pdev, 0);
  198. cs4232_mpu_irq[dev] = pnp_irq(pdev, 0);
  199. }
  200. snd_printk ("CS4232 MPU: port=0x%lx, irq=%i\n",
  201. cs4232_mpu_port[dev],
  202. cs4232_mpu_irq[dev]);
  203. }
  204. snd_printdd ("CS4232: pcm port=0x%lx, fm port=0x%lx, dma1=%i, dma2=%i, irq=%i\nICS2115: port=0x%lx, irq=%i\n",
  205. cs4232_pcm_port[dev],
  206. fm_port[dev],
  207. dma1[dev],
  208. dma2[dev],
  209. cs4232_pcm_irq[dev],
  210. ics2115_port[dev],
  211. ics2115_irq[dev]);
  212. kfree(cfg);
  213. return 0;
  214. }
  215. #endif /* CONFIG_PNP */
  216. static irqreturn_t snd_wavefront_ics2115_interrupt(int irq,
  217. void *dev_id,
  218. struct pt_regs *regs)
  219. {
  220. snd_wavefront_card_t *acard;
  221. acard = (snd_wavefront_card_t *) dev_id;
  222. if (acard == NULL)
  223. return IRQ_NONE;
  224. if (acard->wavefront.interrupts_are_midi) {
  225. snd_wavefront_midi_interrupt (acard);
  226. } else {
  227. snd_wavefront_internal_interrupt (acard);
  228. }
  229. return IRQ_HANDLED;
  230. }
  231. static snd_hwdep_t * __devinit
  232. snd_wavefront_new_synth (snd_card_t *card,
  233. int hw_dev,
  234. snd_wavefront_card_t *acard)
  235. {
  236. snd_hwdep_t *wavefront_synth;
  237. if (snd_wavefront_detect (acard) < 0) {
  238. return NULL;
  239. }
  240. if (snd_wavefront_start (&acard->wavefront) < 0) {
  241. return NULL;
  242. }
  243. if (snd_hwdep_new(card, "WaveFront", hw_dev, &wavefront_synth) < 0)
  244. return NULL;
  245. strcpy (wavefront_synth->name,
  246. "WaveFront (ICS2115) wavetable synthesizer");
  247. wavefront_synth->ops.open = snd_wavefront_synth_open;
  248. wavefront_synth->ops.release = snd_wavefront_synth_release;
  249. wavefront_synth->ops.ioctl = snd_wavefront_synth_ioctl;
  250. return wavefront_synth;
  251. }
  252. static snd_hwdep_t * __devinit
  253. snd_wavefront_new_fx (snd_card_t *card,
  254. int hw_dev,
  255. snd_wavefront_card_t *acard,
  256. unsigned long port)
  257. {
  258. snd_hwdep_t *fx_processor;
  259. if (snd_wavefront_fx_start (&acard->wavefront)) {
  260. snd_printk ("cannot initialize YSS225 FX processor");
  261. return NULL;
  262. }
  263. if (snd_hwdep_new (card, "YSS225", hw_dev, &fx_processor) < 0)
  264. return NULL;
  265. sprintf (fx_processor->name, "YSS225 FX Processor at 0x%lx", port);
  266. fx_processor->ops.open = snd_wavefront_fx_open;
  267. fx_processor->ops.release = snd_wavefront_fx_release;
  268. fx_processor->ops.ioctl = snd_wavefront_fx_ioctl;
  269. return fx_processor;
  270. }
  271. static snd_wavefront_mpu_id internal_id = internal_mpu;
  272. static snd_wavefront_mpu_id external_id = external_mpu;
  273. static snd_rawmidi_t * __devinit
  274. snd_wavefront_new_midi (snd_card_t *card,
  275. int midi_dev,
  276. snd_wavefront_card_t *acard,
  277. unsigned long port,
  278. snd_wavefront_mpu_id mpu)
  279. {
  280. snd_rawmidi_t *rmidi;
  281. static int first = 1;
  282. if (first) {
  283. first = 0;
  284. acard->wavefront.midi.base = port;
  285. if (snd_wavefront_midi_start (acard)) {
  286. snd_printk ("cannot initialize MIDI interface\n");
  287. return NULL;
  288. }
  289. }
  290. if (snd_rawmidi_new (card, "WaveFront MIDI", midi_dev, 1, 1, &rmidi) < 0)
  291. return NULL;
  292. if (mpu == internal_mpu) {
  293. strcpy(rmidi->name, "WaveFront MIDI (Internal)");
  294. rmidi->private_data = &internal_id;
  295. } else {
  296. strcpy(rmidi->name, "WaveFront MIDI (External)");
  297. rmidi->private_data = &external_id;
  298. }
  299. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_OUTPUT, &snd_wavefront_midi_output);
  300. snd_rawmidi_set_ops(rmidi, SNDRV_RAWMIDI_STREAM_INPUT, &snd_wavefront_midi_input);
  301. rmidi->info_flags |= SNDRV_RAWMIDI_INFO_OUTPUT |
  302. SNDRV_RAWMIDI_INFO_INPUT |
  303. SNDRV_RAWMIDI_INFO_DUPLEX;
  304. return rmidi;
  305. }
  306. static void
  307. snd_wavefront_free(snd_card_t *card)
  308. {
  309. snd_wavefront_card_t *acard = (snd_wavefront_card_t *)card->private_data;
  310. if (acard) {
  311. release_and_free_resource(acard->wavefront.res_base);
  312. if (acard->wavefront.irq > 0)
  313. free_irq(acard->wavefront.irq, (void *)acard);
  314. }
  315. }
  316. static int __devinit
  317. snd_wavefront_probe (int dev, struct pnp_card_link *pcard,
  318. const struct pnp_card_device_id *pid)
  319. {
  320. snd_card_t *card;
  321. snd_wavefront_card_t *acard;
  322. cs4231_t *chip;
  323. snd_hwdep_t *wavefront_synth;
  324. snd_rawmidi_t *ics2115_internal_rmidi = NULL;
  325. snd_rawmidi_t *ics2115_external_rmidi = NULL;
  326. snd_hwdep_t *fx_processor;
  327. int hw_dev = 0, midi_dev = 0, err;
  328. #ifdef CONFIG_PNP
  329. if (!isapnp[dev]) {
  330. #endif
  331. if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
  332. snd_printk("specify CS4232 port\n");
  333. return -EINVAL;
  334. }
  335. if (ics2115_port[dev] == SNDRV_AUTO_PORT) {
  336. snd_printk("specify ICS2115 port\n");
  337. return -ENODEV;
  338. }
  339. #ifdef CONFIG_PNP
  340. }
  341. #endif
  342. card = snd_card_new (index[dev],
  343. id[dev],
  344. THIS_MODULE,
  345. sizeof(snd_wavefront_card_t));
  346. if (card == NULL) {
  347. return -ENOMEM;
  348. }
  349. acard = (snd_wavefront_card_t *)card->private_data;
  350. acard->wavefront.irq = -1;
  351. spin_lock_init(&acard->wavefront.irq_lock);
  352. init_waitqueue_head(&acard->wavefront.interrupt_sleeper);
  353. spin_lock_init(&acard->wavefront.midi.open);
  354. spin_lock_init(&acard->wavefront.midi.virtual);
  355. card->private_free = snd_wavefront_free;
  356. #ifdef CONFIG_PNP
  357. if (isapnp[dev]) {
  358. if (snd_wavefront_pnp (dev, acard, pcard, pid) < 0) {
  359. if (cs4232_pcm_port[dev] == SNDRV_AUTO_PORT) {
  360. snd_printk ("isapnp detection failed\n");
  361. snd_card_free (card);
  362. return -ENODEV;
  363. }
  364. }
  365. snd_card_set_dev(card, &pcard->card->dev);
  366. }
  367. #endif /* CONFIG_PNP */
  368. /* --------- PCM --------------- */
  369. if ((err = snd_cs4231_create (card,
  370. cs4232_pcm_port[dev],
  371. -1,
  372. cs4232_pcm_irq[dev],
  373. dma1[dev],
  374. dma2[dev],
  375. CS4231_HW_DETECT, 0, &chip)) < 0) {
  376. snd_card_free(card);
  377. snd_printk ("can't allocate CS4231 device\n");
  378. return err;
  379. }
  380. if ((err = snd_cs4231_pcm (chip, 0, NULL)) < 0) {
  381. snd_card_free(card);
  382. return err;
  383. }
  384. if ((err = snd_cs4231_timer (chip, 0, NULL)) < 0) {
  385. snd_card_free(card);
  386. return err;
  387. }
  388. /* ---------- OPL3 synth --------- */
  389. if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
  390. opl3_t *opl3;
  391. if ((err = snd_opl3_create(card,
  392. fm_port[dev],
  393. fm_port[dev] + 2,
  394. OPL3_HW_OPL3_CS,
  395. 0, &opl3)) < 0) {
  396. snd_printk ("can't allocate or detect OPL3 synth\n");
  397. snd_card_free(card);
  398. return err;
  399. }
  400. if ((err = snd_opl3_hwdep_new(opl3, hw_dev, 1, NULL)) < 0) {
  401. snd_card_free(card);
  402. return err;
  403. }
  404. hw_dev++;
  405. }
  406. /* ------- ICS2115 Wavetable synth ------- */
  407. if ((acard->wavefront.res_base = request_region(ics2115_port[dev], 16, "ICS2115")) == NULL) {
  408. snd_printk("unable to grab ICS2115 i/o region 0x%lx-0x%lx\n", ics2115_port[dev], ics2115_port[dev] + 16 - 1);
  409. snd_card_free(card);
  410. return -EBUSY;
  411. }
  412. if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt, SA_INTERRUPT, "ICS2115", (void *)acard)) {
  413. snd_printk("unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
  414. snd_card_free(card);
  415. return -EBUSY;
  416. }
  417. acard->wavefront.irq = ics2115_irq[dev];
  418. acard->wavefront.base = ics2115_port[dev];
  419. if ((wavefront_synth = snd_wavefront_new_synth (card, hw_dev, acard)) == NULL) {
  420. snd_printk ("can't create WaveFront synth device\n");
  421. snd_card_free(card);
  422. return -ENOMEM;
  423. }
  424. strcpy (wavefront_synth->name, "ICS2115 Wavetable MIDI Synthesizer");
  425. wavefront_synth->iface = SNDRV_HWDEP_IFACE_ICS2115;
  426. hw_dev++;
  427. /* --------- Mixer ------------ */
  428. if ((err = snd_cs4231_mixer(chip)) < 0) {
  429. snd_printk ("can't allocate mixer device\n");
  430. snd_card_free(card);
  431. return err;
  432. }
  433. /* -------- CS4232 MPU-401 interface -------- */
  434. if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
  435. if ((err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
  436. cs4232_mpu_port[dev], 0,
  437. cs4232_mpu_irq[dev],
  438. SA_INTERRUPT,
  439. NULL)) < 0) {
  440. snd_printk ("can't allocate CS4232 MPU-401 device\n");
  441. snd_card_free(card);
  442. return err;
  443. }
  444. midi_dev++;
  445. }
  446. /* ------ ICS2115 internal MIDI ------------ */
  447. if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
  448. ics2115_internal_rmidi =
  449. snd_wavefront_new_midi (card,
  450. midi_dev,
  451. acard,
  452. ics2115_port[dev],
  453. internal_mpu);
  454. if (ics2115_internal_rmidi == NULL) {
  455. snd_printk ("can't setup ICS2115 internal MIDI device\n");
  456. snd_card_free(card);
  457. return -ENOMEM;
  458. }
  459. midi_dev++;
  460. }
  461. /* ------ ICS2115 external MIDI ------------ */
  462. if (ics2115_port[dev] > 0 && ics2115_port[dev] != SNDRV_AUTO_PORT) {
  463. ics2115_external_rmidi =
  464. snd_wavefront_new_midi (card,
  465. midi_dev,
  466. acard,
  467. ics2115_port[dev],
  468. external_mpu);
  469. if (ics2115_external_rmidi == NULL) {
  470. snd_printk ("can't setup ICS2115 external MIDI device\n");
  471. snd_card_free(card);
  472. return -ENOMEM;
  473. }
  474. midi_dev++;
  475. }
  476. /* FX processor for Tropez+ */
  477. if (acard->wavefront.has_fx) {
  478. fx_processor = snd_wavefront_new_fx (card,
  479. hw_dev,
  480. acard,
  481. ics2115_port[dev]);
  482. if (fx_processor == NULL) {
  483. snd_printk ("can't setup FX device\n");
  484. snd_card_free(card);
  485. return -ENOMEM;
  486. }
  487. hw_dev++;
  488. strcpy(card->driver, "Tropez+");
  489. strcpy(card->shortname, "Turtle Beach Tropez+");
  490. } else {
  491. /* Need a way to distinguish between Maui and Tropez */
  492. strcpy(card->driver, "WaveFront");
  493. strcpy(card->shortname, "Turtle Beach WaveFront");
  494. }
  495. /* ----- Register the card --------- */
  496. /* Not safe to include "Turtle Beach" in longname, due to
  497. length restrictions
  498. */
  499. sprintf(card->longname, "%s PCM 0x%lx irq %d dma %d",
  500. card->driver,
  501. chip->port,
  502. cs4232_pcm_irq[dev],
  503. dma1[dev]);
  504. if (dma2[dev] >= 0 && dma2[dev] < 8)
  505. sprintf(card->longname + strlen(card->longname), "&%d", dma2[dev]);
  506. if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
  507. sprintf (card->longname + strlen (card->longname),
  508. " MPU-401 0x%lx irq %d",
  509. cs4232_mpu_port[dev],
  510. cs4232_mpu_irq[dev]);
  511. }
  512. sprintf (card->longname + strlen (card->longname),
  513. " SYNTH 0x%lx irq %d",
  514. ics2115_port[dev],
  515. ics2115_irq[dev]);
  516. if ((err = snd_card_set_generic_dev(card)) < 0) {
  517. snd_card_free(card);
  518. return err;
  519. }
  520. if ((err = snd_card_register(card)) < 0) {
  521. snd_card_free(card);
  522. return err;
  523. }
  524. if (pcard)
  525. pnp_set_card_drvdata(pcard, card);
  526. else
  527. snd_wavefront_legacy[dev] = card;
  528. return 0;
  529. }
  530. #ifdef CONFIG_PNP
  531. static int __devinit snd_wavefront_pnp_detect(struct pnp_card_link *card,
  532. const struct pnp_card_device_id *id)
  533. {
  534. static int dev;
  535. int res;
  536. for ( ; dev < SNDRV_CARDS; dev++) {
  537. if (!enable[dev] || !isapnp[dev])
  538. continue;
  539. res = snd_wavefront_probe(dev, card, id);
  540. if (res < 0)
  541. return res;
  542. dev++;
  543. return 0;
  544. }
  545. return -ENODEV;
  546. }
  547. static void __devexit snd_wavefront_pnp_remove(struct pnp_card_link * pcard)
  548. {
  549. snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
  550. snd_card_disconnect(card);
  551. snd_card_free_in_thread(card);
  552. }
  553. static struct pnp_card_driver wavefront_pnpc_driver = {
  554. .flags = PNP_DRIVER_RES_DISABLE,
  555. .name = "wavefront",
  556. .id_table = snd_wavefront_pnpids,
  557. .probe = snd_wavefront_pnp_detect,
  558. .remove = __devexit_p(snd_wavefront_pnp_remove),
  559. };
  560. #endif /* CONFIG_PNP */
  561. static int __init alsa_card_wavefront_init(void)
  562. {
  563. int cards = 0;
  564. int dev;
  565. for (dev = 0; dev < SNDRV_CARDS; dev++) {
  566. if (!enable[dev])
  567. continue;
  568. #ifdef CONFIG_PNP
  569. if (isapnp[dev])
  570. continue;
  571. #endif
  572. if (snd_wavefront_probe(dev, NULL, NULL) >= 0)
  573. cards++;
  574. }
  575. #ifdef CONFIG_PNP
  576. cards += pnp_register_card_driver(&wavefront_pnpc_driver);
  577. #endif
  578. if (!cards) {
  579. #ifdef CONFIG_PNP
  580. pnp_unregister_card_driver(&wavefront_pnpc_driver);
  581. #endif
  582. #ifdef MODULE
  583. printk (KERN_ERR "No WaveFront cards found or devices busy\n");
  584. #endif
  585. return -ENODEV;
  586. }
  587. return 0;
  588. }
  589. static void __exit alsa_card_wavefront_exit(void)
  590. {
  591. int idx;
  592. #ifdef CONFIG_PNP
  593. pnp_unregister_card_driver(&wavefront_pnpc_driver);
  594. #endif
  595. for (idx = 0; idx < SNDRV_CARDS; idx++)
  596. snd_card_free(snd_wavefront_legacy[idx]);
  597. }
  598. module_init(alsa_card_wavefront_init)
  599. module_exit(alsa_card_wavefront_exit)