wavefront.c 21 KB

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