msnd_pinnacle.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246
  1. /*********************************************************************
  2. *
  3. * Linux multisound pinnacle/fiji driver for ALSA.
  4. *
  5. * 2002/06/30 Karsten Wiese:
  6. * for now this is only used to build a pinnacle / fiji driver.
  7. * the OSS parent of this code is designed to also support
  8. * the multisound classic via the file msnd_classic.c.
  9. * to make it easier for some brave heart to implemt classic
  10. * support in alsa, i left all the MSND_CLASSIC tokens in this file.
  11. * but for now this untested & undone.
  12. *
  13. *
  14. * ripped from linux kernel 2.4.18 by Karsten Wiese.
  15. *
  16. * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
  17. *
  18. * Turtle Beach MultiSound Sound Card Driver for Linux
  19. * msnd_pinnacle.c / msnd_classic.c
  20. *
  21. * -- If MSND_CLASSIC is defined:
  22. *
  23. * -> driver for Turtle Beach Classic/Monterey/Tahiti
  24. *
  25. * -- Else
  26. *
  27. * -> driver for Turtle Beach Pinnacle/Fiji
  28. *
  29. * 12-3-2000 Modified IO port validation Steve Sycamore
  30. *
  31. * Copyright (C) 1998 Andrew Veliath
  32. *
  33. * This program is free software; you can redistribute it and/or modify
  34. * it under the terms of the GNU General Public License as published by
  35. * the Free Software Foundation; either version 2 of the License, or
  36. * (at your option) any later version.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU General Public License
  44. * along with this program; if not, write to the Free Software
  45. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46. *
  47. ********************************************************************/
  48. #include <linux/kernel.h>
  49. #include <linux/module.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/types.h>
  52. #include <linux/delay.h>
  53. #include <linux/ioport.h>
  54. #include <linux/firmware.h>
  55. #include <linux/isa.h>
  56. #include <linux/isapnp.h>
  57. #include <linux/irq.h>
  58. #include <linux/io.h>
  59. #include <sound/core.h>
  60. #include <sound/initval.h>
  61. #include <sound/asound.h>
  62. #include <sound/pcm.h>
  63. #include <sound/mpu401.h>
  64. #ifdef MSND_CLASSIC
  65. # ifndef __alpha__
  66. # define SLOWIO
  67. # endif
  68. #endif
  69. #include "msnd.h"
  70. #ifdef MSND_CLASSIC
  71. # include "msnd_classic.h"
  72. # define LOGNAME "msnd_classic"
  73. # define DEV_NAME "msnd-classic"
  74. #else
  75. # include "msnd_pinnacle.h"
  76. # define LOGNAME "snd_msnd_pinnacle"
  77. # define DEV_NAME "msnd-pinnacle"
  78. #endif
  79. static void __devinit set_default_audio_parameters(struct snd_msnd *chip)
  80. {
  81. chip->play_sample_size = DEFSAMPLESIZE;
  82. chip->play_sample_rate = DEFSAMPLERATE;
  83. chip->play_channels = DEFCHANNELS;
  84. chip->capture_sample_size = DEFSAMPLESIZE;
  85. chip->capture_sample_rate = DEFSAMPLERATE;
  86. chip->capture_channels = DEFCHANNELS;
  87. }
  88. static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
  89. {
  90. switch (HIBYTE(wMessage)) {
  91. case HIMT_PLAY_DONE: {
  92. if (chip->banksPlayed < 3)
  93. snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
  94. (unsigned)jiffies, LOBYTE(wMessage));
  95. if (chip->last_playbank == LOBYTE(wMessage)) {
  96. snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
  97. break;
  98. }
  99. chip->banksPlayed++;
  100. if (test_bit(F_WRITING, &chip->flags))
  101. snd_msnd_DAPQ(chip, 0);
  102. chip->last_playbank = LOBYTE(wMessage);
  103. chip->playDMAPos += chip->play_period_bytes;
  104. if (chip->playDMAPos > chip->playLimit)
  105. chip->playDMAPos = 0;
  106. snd_pcm_period_elapsed(chip->playback_substream);
  107. break;
  108. }
  109. case HIMT_RECORD_DONE:
  110. if (chip->last_recbank == LOBYTE(wMessage))
  111. break;
  112. chip->last_recbank = LOBYTE(wMessage);
  113. chip->captureDMAPos += chip->capturePeriodBytes;
  114. if (chip->captureDMAPos > (chip->captureLimit))
  115. chip->captureDMAPos = 0;
  116. if (test_bit(F_READING, &chip->flags))
  117. snd_msnd_DARQ(chip, chip->last_recbank);
  118. snd_pcm_period_elapsed(chip->capture_substream);
  119. break;
  120. case HIMT_DSP:
  121. switch (LOBYTE(wMessage)) {
  122. #ifndef MSND_CLASSIC
  123. case HIDSP_PLAY_UNDER:
  124. #endif
  125. case HIDSP_INT_PLAY_UNDER:
  126. snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
  127. chip->banksPlayed);
  128. if (chip->banksPlayed > 2)
  129. clear_bit(F_WRITING, &chip->flags);
  130. break;
  131. case HIDSP_INT_RECORD_OVER:
  132. snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
  133. clear_bit(F_READING, &chip->flags);
  134. break;
  135. default:
  136. snd_printd(KERN_WARNING LOGNAME
  137. ": DSP message %d 0x%02x\n",
  138. LOBYTE(wMessage), LOBYTE(wMessage));
  139. break;
  140. }
  141. break;
  142. case HIMT_MIDI_IN_UCHAR:
  143. if (chip->msndmidi_mpu)
  144. snd_msndmidi_input_read(chip->msndmidi_mpu);
  145. break;
  146. default:
  147. snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
  148. HIBYTE(wMessage), HIBYTE(wMessage));
  149. break;
  150. }
  151. }
  152. static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
  153. {
  154. struct snd_msnd *chip = dev_id;
  155. void *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
  156. /* Send ack to DSP */
  157. /* inb(chip->io + HP_RXL); */
  158. /* Evaluate queued DSP messages */
  159. while (readw(chip->DSPQ + JQS_wTail) != readw(chip->DSPQ + JQS_wHead)) {
  160. u16 wTmp;
  161. snd_msnd_eval_dsp_msg(chip,
  162. readw(pwDSPQData + 2 * readw(chip->DSPQ + JQS_wHead)));
  163. wTmp = readw(chip->DSPQ + JQS_wHead) + 1;
  164. if (wTmp > readw(chip->DSPQ + JQS_wSize))
  165. writew(0, chip->DSPQ + JQS_wHead);
  166. else
  167. writew(wTmp, chip->DSPQ + JQS_wHead);
  168. }
  169. /* Send ack to DSP */
  170. inb(chip->io + HP_RXL);
  171. return IRQ_HANDLED;
  172. }
  173. static int snd_msnd_reset_dsp(long io, unsigned char *info)
  174. {
  175. int timeout = 100;
  176. outb(HPDSPRESET_ON, io + HP_DSPR);
  177. msleep(1);
  178. #ifndef MSND_CLASSIC
  179. if (info)
  180. *info = inb(io + HP_INFO);
  181. #endif
  182. outb(HPDSPRESET_OFF, io + HP_DSPR);
  183. msleep(1);
  184. while (timeout-- > 0) {
  185. if (inb(io + HP_CVR) == HP_CVR_DEF)
  186. return 0;
  187. msleep(1);
  188. }
  189. snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
  190. return -EIO;
  191. }
  192. static int __devinit snd_msnd_probe(struct snd_card *card)
  193. {
  194. struct snd_msnd *chip = card->private_data;
  195. unsigned char info;
  196. #ifndef MSND_CLASSIC
  197. char *xv, *rev = NULL;
  198. char *pin = "TB Pinnacle", *fiji = "TB Fiji";
  199. char *pinfiji = "TB Pinnacle/Fiji";
  200. #endif
  201. if (!request_region(chip->io, DSP_NUMIO, "probing")) {
  202. snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
  203. return -ENODEV;
  204. }
  205. if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
  206. release_region(chip->io, DSP_NUMIO);
  207. return -ENODEV;
  208. }
  209. #ifdef MSND_CLASSIC
  210. strcpy(card->shortname, "Classic/Tahiti/Monterey");
  211. strcpy(card->longname, "Turtle Beach Multisound");
  212. printk(KERN_INFO LOGNAME ": %s, "
  213. "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
  214. card->shortname,
  215. chip->io, chip->io + DSP_NUMIO - 1,
  216. chip->irq,
  217. chip->base, chip->base + 0x7fff);
  218. #else
  219. switch (info >> 4) {
  220. case 0xf:
  221. xv = "<= 1.15";
  222. break;
  223. case 0x1:
  224. xv = "1.18/1.2";
  225. break;
  226. case 0x2:
  227. xv = "1.3";
  228. break;
  229. case 0x3:
  230. xv = "1.4";
  231. break;
  232. default:
  233. xv = "unknown";
  234. break;
  235. }
  236. switch (info & 0x7) {
  237. case 0x0:
  238. rev = "I";
  239. strcpy(card->shortname, pin);
  240. break;
  241. case 0x1:
  242. rev = "F";
  243. strcpy(card->shortname, pin);
  244. break;
  245. case 0x2:
  246. rev = "G";
  247. strcpy(card->shortname, pin);
  248. break;
  249. case 0x3:
  250. rev = "H";
  251. strcpy(card->shortname, pin);
  252. break;
  253. case 0x4:
  254. rev = "E";
  255. strcpy(card->shortname, fiji);
  256. break;
  257. case 0x5:
  258. rev = "C";
  259. strcpy(card->shortname, fiji);
  260. break;
  261. case 0x6:
  262. rev = "D";
  263. strcpy(card->shortname, fiji);
  264. break;
  265. case 0x7:
  266. rev = "A-B (Fiji) or A-E (Pinnacle)";
  267. strcpy(card->shortname, pinfiji);
  268. break;
  269. }
  270. strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
  271. printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
  272. "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
  273. card->shortname,
  274. rev, xv,
  275. chip->io, chip->io + DSP_NUMIO - 1,
  276. chip->irq,
  277. chip->base, chip->base + 0x7fff);
  278. #endif
  279. release_region(chip->io, DSP_NUMIO);
  280. return 0;
  281. }
  282. static int snd_msnd_init_sma(struct snd_msnd *chip)
  283. {
  284. static int initted;
  285. u16 mastVolLeft, mastVolRight;
  286. unsigned long flags;
  287. #ifdef MSND_CLASSIC
  288. outb(chip->memid, chip->io + HP_MEMM);
  289. #endif
  290. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  291. /* Motorola 56k shared memory base */
  292. chip->SMA = chip->mappedbase + SMA_STRUCT_START;
  293. if (initted) {
  294. mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
  295. mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
  296. } else
  297. mastVolLeft = mastVolRight = 0;
  298. memset_io(chip->mappedbase, 0, 0x8000);
  299. /* Critical section: bank 1 access */
  300. spin_lock_irqsave(&chip->lock, flags);
  301. outb(HPBLKSEL_1, chip->io + HP_BLKS);
  302. memset_io(chip->mappedbase, 0, 0x8000);
  303. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  304. spin_unlock_irqrestore(&chip->lock, flags);
  305. /* Digital audio play queue */
  306. chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
  307. snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
  308. /* Digital audio record queue */
  309. chip->DARQ = chip->mappedbase + DARQ_OFFSET;
  310. snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
  311. /* MIDI out queue */
  312. chip->MODQ = chip->mappedbase + MODQ_OFFSET;
  313. snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
  314. /* MIDI in queue */
  315. chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
  316. snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
  317. /* DSP -> host message queue */
  318. chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
  319. snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
  320. /* Setup some DSP values */
  321. #ifndef MSND_CLASSIC
  322. writew(1, chip->SMA + SMA_wCurrPlayFormat);
  323. writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
  324. writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
  325. writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
  326. #endif
  327. writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
  328. writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
  329. writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
  330. #ifndef MSND_CLASSIC
  331. writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
  332. writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
  333. #endif
  334. writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
  335. initted = 1;
  336. return 0;
  337. }
  338. static int upload_dsp_code(struct snd_card *card)
  339. {
  340. struct snd_msnd *chip = card->private_data;
  341. const struct firmware *init_fw = NULL, *perm_fw = NULL;
  342. int err;
  343. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  344. err = request_firmware(&init_fw, INITCODEFILE, card->dev);
  345. if (err < 0) {
  346. printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
  347. goto cleanup1;
  348. }
  349. err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
  350. if (err < 0) {
  351. printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
  352. goto cleanup;
  353. }
  354. memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
  355. if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
  356. printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
  357. err = -ENODEV;
  358. goto cleanup;
  359. }
  360. printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
  361. err = 0;
  362. cleanup:
  363. release_firmware(perm_fw);
  364. cleanup1:
  365. release_firmware(init_fw);
  366. return err;
  367. }
  368. #ifdef MSND_CLASSIC
  369. static void reset_proteus(struct snd_msnd *chip)
  370. {
  371. outb(HPPRORESET_ON, chip->io + HP_PROR);
  372. msleep(TIME_PRO_RESET);
  373. outb(HPPRORESET_OFF, chip->io + HP_PROR);
  374. msleep(TIME_PRO_RESET_DONE);
  375. }
  376. #endif
  377. static int snd_msnd_initialize(struct snd_card *card)
  378. {
  379. struct snd_msnd *chip = card->private_data;
  380. int err, timeout;
  381. #ifdef MSND_CLASSIC
  382. outb(HPWAITSTATE_0, chip->io + HP_WAIT);
  383. outb(HPBITMODE_16, chip->io + HP_BITM);
  384. reset_proteus(chip);
  385. #endif
  386. err = snd_msnd_init_sma(chip);
  387. if (err < 0) {
  388. printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
  389. return err;
  390. }
  391. err = snd_msnd_reset_dsp(chip->io, NULL);
  392. if (err < 0)
  393. return err;
  394. err = upload_dsp_code(card);
  395. if (err < 0) {
  396. printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
  397. return err;
  398. }
  399. timeout = 200;
  400. while (readw(chip->mappedbase)) {
  401. msleep(1);
  402. if (!timeout--) {
  403. snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
  404. return -EIO;
  405. }
  406. }
  407. snd_msndmix_setup(chip);
  408. return 0;
  409. }
  410. static int snd_msnd_dsp_full_reset(struct snd_card *card)
  411. {
  412. struct snd_msnd *chip = card->private_data;
  413. int rv;
  414. if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
  415. return 0;
  416. set_bit(F_RESETTING, &chip->flags);
  417. snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */
  418. rv = snd_msnd_initialize(card);
  419. if (rv)
  420. printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
  421. snd_msndmix_force_recsrc(chip, 0);
  422. clear_bit(F_RESETTING, &chip->flags);
  423. return rv;
  424. }
  425. static int snd_msnd_dev_free(struct snd_device *device)
  426. {
  427. snd_printdd("snd_msnd_chip_free()\n");
  428. return 0;
  429. }
  430. static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
  431. {
  432. if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
  433. return 0;
  434. snd_msnd_dsp_full_reset(chip->card);
  435. return snd_msnd_send_dsp_cmd(chip, cmd);
  436. }
  437. static int __devinit snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
  438. {
  439. snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
  440. writew(srate, chip->SMA + SMA_wCalFreqAtoD);
  441. if (chip->calibrate_signal == 0)
  442. writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
  443. | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
  444. else
  445. writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
  446. & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
  447. if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
  448. snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
  449. schedule_timeout_interruptible(msecs_to_jiffies(333));
  450. return 0;
  451. }
  452. printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
  453. return -EIO;
  454. }
  455. /*
  456. * ALSA callback function, called when attempting to open the MIDI device.
  457. */
  458. static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
  459. {
  460. snd_msnd_enable_irq(mpu->private_data);
  461. snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
  462. return 0;
  463. }
  464. static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
  465. {
  466. snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
  467. snd_msnd_disable_irq(mpu->private_data);
  468. }
  469. static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  470. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  471. static int __devinit snd_msnd_attach(struct snd_card *card)
  472. {
  473. struct snd_msnd *chip = card->private_data;
  474. int err;
  475. static struct snd_device_ops ops = {
  476. .dev_free = snd_msnd_dev_free,
  477. };
  478. err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname,
  479. chip);
  480. if (err < 0) {
  481. printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
  482. return err;
  483. }
  484. if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) {
  485. free_irq(chip->irq, chip);
  486. return -EBUSY;
  487. }
  488. if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
  489. printk(KERN_ERR LOGNAME
  490. ": unable to grab memory region 0x%lx-0x%lx\n",
  491. chip->base, chip->base + BUFFSIZE - 1);
  492. release_region(chip->io, DSP_NUMIO);
  493. free_irq(chip->irq, chip);
  494. return -EBUSY;
  495. }
  496. chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
  497. if (!chip->mappedbase) {
  498. printk(KERN_ERR LOGNAME
  499. ": unable to map memory region 0x%lx-0x%lx\n",
  500. chip->base, chip->base + BUFFSIZE - 1);
  501. err = -EIO;
  502. goto err_release_region;
  503. }
  504. err = snd_msnd_dsp_full_reset(card);
  505. if (err < 0)
  506. goto err_release_region;
  507. /* Register device */
  508. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  509. if (err < 0)
  510. goto err_release_region;
  511. err = snd_msnd_pcm(card, 0, NULL);
  512. if (err < 0) {
  513. printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
  514. goto err_release_region;
  515. }
  516. err = snd_msndmix_new(card);
  517. if (err < 0) {
  518. printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
  519. goto err_release_region;
  520. }
  521. if (mpu_io[0] != SNDRV_AUTO_PORT) {
  522. struct snd_mpu401 *mpu;
  523. err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  524. mpu_io[0],
  525. MPU401_MODE_INPUT |
  526. MPU401_MODE_OUTPUT,
  527. mpu_irq[0],
  528. &chip->rmidi);
  529. if (err < 0) {
  530. printk(KERN_ERR LOGNAME
  531. ": error creating new Midi device\n");
  532. goto err_release_region;
  533. }
  534. mpu = chip->rmidi->private_data;
  535. mpu->open_input = snd_msnd_mpu401_open;
  536. mpu->close_input = snd_msnd_mpu401_close;
  537. mpu->private_data = chip;
  538. }
  539. disable_irq(chip->irq);
  540. snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
  541. snd_msndmix_force_recsrc(chip, 0);
  542. err = snd_card_register(card);
  543. if (err < 0)
  544. goto err_release_region;
  545. return 0;
  546. err_release_region:
  547. if (chip->mappedbase)
  548. iounmap(chip->mappedbase);
  549. release_mem_region(chip->base, BUFFSIZE);
  550. release_region(chip->io, DSP_NUMIO);
  551. free_irq(chip->irq, chip);
  552. return err;
  553. }
  554. static void __devexit snd_msnd_unload(struct snd_card *card)
  555. {
  556. struct snd_msnd *chip = card->private_data;
  557. iounmap(chip->mappedbase);
  558. release_mem_region(chip->base, BUFFSIZE);
  559. release_region(chip->io, DSP_NUMIO);
  560. free_irq(chip->irq, chip);
  561. snd_card_free(card);
  562. }
  563. #ifndef MSND_CLASSIC
  564. /* Pinnacle/Fiji Logical Device Configuration */
  565. static int __devinit snd_msnd_write_cfg(int cfg, int reg, int value)
  566. {
  567. outb(reg, cfg);
  568. outb(value, cfg + 1);
  569. if (value != inb(cfg + 1)) {
  570. printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
  571. return -EIO;
  572. }
  573. return 0;
  574. }
  575. static int __devinit snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
  576. {
  577. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  578. return -EIO;
  579. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  580. return -EIO;
  581. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  582. return -EIO;
  583. return 0;
  584. }
  585. static int __devinit snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
  586. {
  587. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  588. return -EIO;
  589. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  590. return -EIO;
  591. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  592. return -EIO;
  593. return 0;
  594. }
  595. static int __devinit snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
  596. {
  597. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  598. return -EIO;
  599. if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  600. return -EIO;
  601. if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  602. return -EIO;
  603. return 0;
  604. }
  605. static int __devinit snd_msnd_write_cfg_mem(int cfg, int num, int mem)
  606. {
  607. u16 wmem;
  608. mem >>= 8;
  609. wmem = (u16)(mem & 0xfff);
  610. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  611. return -EIO;
  612. if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  613. return -EIO;
  614. if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  615. return -EIO;
  616. if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
  617. MEMTYPE_HIADDR | MEMTYPE_16BIT))
  618. return -EIO;
  619. return 0;
  620. }
  621. static int __devinit snd_msnd_activate_logical(int cfg, int num)
  622. {
  623. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  624. return -EIO;
  625. if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  626. return -EIO;
  627. return 0;
  628. }
  629. static int __devinit snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
  630. u16 io1, u16 irq, int mem)
  631. {
  632. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  633. return -EIO;
  634. if (snd_msnd_write_cfg_io0(cfg, num, io0))
  635. return -EIO;
  636. if (snd_msnd_write_cfg_io1(cfg, num, io1))
  637. return -EIO;
  638. if (snd_msnd_write_cfg_irq(cfg, num, irq))
  639. return -EIO;
  640. if (snd_msnd_write_cfg_mem(cfg, num, mem))
  641. return -EIO;
  642. if (snd_msnd_activate_logical(cfg, num))
  643. return -EIO;
  644. return 0;
  645. }
  646. static int __devinit snd_msnd_pinnacle_cfg_reset(int cfg)
  647. {
  648. int i;
  649. /* Reset devices if told to */
  650. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  651. for (i = 0; i < 4; ++i)
  652. if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  653. return -EIO;
  654. return 0;
  655. }
  656. #endif
  657. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  658. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  659. module_param_array(index, int, NULL, S_IRUGO);
  660. MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
  661. module_param_array(id, charp, NULL, S_IRUGO);
  662. MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
  663. static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  664. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  665. static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  666. #ifndef MSND_CLASSIC
  667. static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  668. /* Extra Peripheral Configuration (Default: Disable) */
  669. static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  670. static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  671. static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  672. static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  673. /* If we have the digital daugherboard... */
  674. static int digital[SNDRV_CARDS];
  675. /* Extra Peripheral Configuration */
  676. static int reset[SNDRV_CARDS];
  677. #endif
  678. static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
  679. static int calibrate_signal;
  680. #ifdef CONFIG_PNP
  681. static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  682. module_param_array(isapnp, bool, NULL, 0444);
  683. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  684. #define has_isapnp(x) isapnp[x]
  685. #else
  686. #define has_isapnp(x) 0
  687. #endif
  688. MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
  689. MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
  690. MODULE_LICENSE("GPL");
  691. MODULE_FIRMWARE(INITCODEFILE);
  692. MODULE_FIRMWARE(PERMCODEFILE);
  693. module_param_array(io, long, NULL, S_IRUGO);
  694. MODULE_PARM_DESC(io, "IO port #");
  695. module_param_array(irq, int, NULL, S_IRUGO);
  696. module_param_array(mem, long, NULL, S_IRUGO);
  697. module_param_array(write_ndelay, int, NULL, S_IRUGO);
  698. module_param(calibrate_signal, int, S_IRUGO);
  699. #ifndef MSND_CLASSIC
  700. module_param_array(digital, int, NULL, S_IRUGO);
  701. module_param_array(cfg, long, NULL, S_IRUGO);
  702. module_param_array(reset, int, 0, S_IRUGO);
  703. module_param_array(mpu_io, long, NULL, S_IRUGO);
  704. module_param_array(mpu_irq, int, NULL, S_IRUGO);
  705. module_param_array(ide_io0, long, NULL, S_IRUGO);
  706. module_param_array(ide_io1, long, NULL, S_IRUGO);
  707. module_param_array(ide_irq, int, NULL, S_IRUGO);
  708. module_param_array(joystick_io, long, NULL, S_IRUGO);
  709. #endif
  710. static int __devinit snd_msnd_isa_match(struct device *pdev, unsigned int i)
  711. {
  712. if (io[i] == SNDRV_AUTO_PORT)
  713. return 0;
  714. if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
  715. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  716. return 0;
  717. }
  718. #ifdef MSND_CLASSIC
  719. if (!(io[i] == 0x290 ||
  720. io[i] == 0x260 ||
  721. io[i] == 0x250 ||
  722. io[i] == 0x240 ||
  723. io[i] == 0x230 ||
  724. io[i] == 0x220 ||
  725. io[i] == 0x210 ||
  726. io[i] == 0x3e0)) {
  727. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
  728. " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
  729. "or 0x3E0\n");
  730. return 0;
  731. }
  732. #else
  733. if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
  734. printk(KERN_ERR LOGNAME
  735. ": \"io\" - DSP I/O base must within the range 0x100 "
  736. "to 0x3E0 and must be evenly divisible by 0x10\n");
  737. return 0;
  738. }
  739. #endif /* MSND_CLASSIC */
  740. if (!(irq[i] == 5 ||
  741. irq[i] == 7 ||
  742. irq[i] == 9 ||
  743. irq[i] == 10 ||
  744. irq[i] == 11 ||
  745. irq[i] == 12)) {
  746. printk(KERN_ERR LOGNAME
  747. ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  748. return 0;
  749. }
  750. if (!(mem[i] == 0xb0000 ||
  751. mem[i] == 0xc8000 ||
  752. mem[i] == 0xd0000 ||
  753. mem[i] == 0xd8000 ||
  754. mem[i] == 0xe0000 ||
  755. mem[i] == 0xe8000)) {
  756. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  757. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
  758. "0xe8000\n");
  759. return 0;
  760. }
  761. #ifndef MSND_CLASSIC
  762. if (cfg[i] == SNDRV_AUTO_PORT) {
  763. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  764. } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
  765. printk(KERN_INFO LOGNAME
  766. ": Config port must be 0x250, 0x260 or 0x270 "
  767. "(or unspecified for PnP mode)\n");
  768. return 0;
  769. }
  770. #endif /* MSND_CLASSIC */
  771. return 1;
  772. }
  773. static int __devinit snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
  774. {
  775. int err;
  776. struct snd_card *card;
  777. struct snd_msnd *chip;
  778. if (has_isapnp(idx)
  779. #ifndef MSND_CLASSIC
  780. || cfg[idx] == SNDRV_AUTO_PORT
  781. #endif
  782. ) {
  783. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  784. return -ENODEV;
  785. }
  786. err = snd_card_create(index[idx], id[idx], THIS_MODULE,
  787. sizeof(struct snd_msnd), &card);
  788. if (err < 0)
  789. return err;
  790. snd_card_set_dev(card, pdev);
  791. chip = card->private_data;
  792. chip->card = card;
  793. #ifdef MSND_CLASSIC
  794. switch (irq[idx]) {
  795. case 5:
  796. chip->irqid = HPIRQ_5; break;
  797. case 7:
  798. chip->irqid = HPIRQ_7; break;
  799. case 9:
  800. chip->irqid = HPIRQ_9; break;
  801. case 10:
  802. chip->irqid = HPIRQ_10; break;
  803. case 11:
  804. chip->irqid = HPIRQ_11; break;
  805. case 12:
  806. chip->irqid = HPIRQ_12; break;
  807. }
  808. switch (mem[idx]) {
  809. case 0xb0000:
  810. chip->memid = HPMEM_B000; break;
  811. case 0xc8000:
  812. chip->memid = HPMEM_C800; break;
  813. case 0xd0000:
  814. chip->memid = HPMEM_D000; break;
  815. case 0xd8000:
  816. chip->memid = HPMEM_D800; break;
  817. case 0xe0000:
  818. chip->memid = HPMEM_E000; break;
  819. case 0xe8000:
  820. chip->memid = HPMEM_E800; break;
  821. }
  822. #else
  823. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
  824. cfg[idx]);
  825. if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
  826. printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
  827. cfg[idx]);
  828. snd_card_free(card);
  829. return -EIO;
  830. }
  831. if (reset[idx])
  832. if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
  833. err = -EIO;
  834. goto cfg_error;
  835. }
  836. /* DSP */
  837. err = snd_msnd_write_cfg_logical(cfg[idx], 0,
  838. io[idx], 0,
  839. irq[idx], mem[idx]);
  840. if (err)
  841. goto cfg_error;
  842. /* The following are Pinnacle specific */
  843. /* MPU */
  844. if (mpu_io[idx] != SNDRV_AUTO_PORT
  845. && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
  846. printk(KERN_INFO LOGNAME
  847. ": Configuring MPU to I/O 0x%lx IRQ %d\n",
  848. mpu_io[idx], mpu_irq[idx]);
  849. err = snd_msnd_write_cfg_logical(cfg[idx], 1,
  850. mpu_io[idx], 0,
  851. mpu_irq[idx], 0);
  852. if (err)
  853. goto cfg_error;
  854. }
  855. /* IDE */
  856. if (ide_io0[idx] != SNDRV_AUTO_PORT
  857. && ide_io1[idx] != SNDRV_AUTO_PORT
  858. && ide_irq[idx] != SNDRV_AUTO_IRQ) {
  859. printk(KERN_INFO LOGNAME
  860. ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
  861. ide_io0[idx], ide_io1[idx], ide_irq[idx]);
  862. err = snd_msnd_write_cfg_logical(cfg[idx], 2,
  863. ide_io0[idx], ide_io1[idx],
  864. ide_irq[idx], 0);
  865. if (err)
  866. goto cfg_error;
  867. }
  868. /* Joystick */
  869. if (joystick_io[idx] != SNDRV_AUTO_PORT) {
  870. printk(KERN_INFO LOGNAME
  871. ": Configuring joystick to I/O 0x%lx\n",
  872. joystick_io[idx]);
  873. err = snd_msnd_write_cfg_logical(cfg[idx], 3,
  874. joystick_io[idx], 0,
  875. 0, 0);
  876. if (err)
  877. goto cfg_error;
  878. }
  879. release_region(cfg[idx], 2);
  880. #endif /* MSND_CLASSIC */
  881. set_default_audio_parameters(chip);
  882. #ifdef MSND_CLASSIC
  883. chip->type = msndClassic;
  884. #else
  885. chip->type = msndPinnacle;
  886. #endif
  887. chip->io = io[idx];
  888. chip->irq = irq[idx];
  889. chip->base = mem[idx];
  890. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  891. chip->recsrc = 0;
  892. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  893. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  894. if (write_ndelay[idx])
  895. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  896. else
  897. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  898. #ifndef MSND_CLASSIC
  899. if (digital[idx])
  900. set_bit(F_HAVEDIGITAL, &chip->flags);
  901. #endif
  902. spin_lock_init(&chip->lock);
  903. err = snd_msnd_probe(card);
  904. if (err < 0) {
  905. printk(KERN_ERR LOGNAME ": Probe failed\n");
  906. snd_card_free(card);
  907. return err;
  908. }
  909. err = snd_msnd_attach(card);
  910. if (err < 0) {
  911. printk(KERN_ERR LOGNAME ": Attach failed\n");
  912. snd_card_free(card);
  913. return err;
  914. }
  915. dev_set_drvdata(pdev, card);
  916. return 0;
  917. #ifndef MSND_CLASSIC
  918. cfg_error:
  919. release_region(cfg[idx], 2);
  920. snd_card_free(card);
  921. return err;
  922. #endif
  923. }
  924. static int __devexit snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
  925. {
  926. snd_msnd_unload(dev_get_drvdata(pdev));
  927. dev_set_drvdata(pdev, NULL);
  928. return 0;
  929. }
  930. static struct isa_driver snd_msnd_driver = {
  931. .match = snd_msnd_isa_match,
  932. .probe = snd_msnd_isa_probe,
  933. .remove = __devexit_p(snd_msnd_isa_remove),
  934. /* FIXME: suspend, resume */
  935. .driver = {
  936. .name = DEV_NAME
  937. },
  938. };
  939. #ifdef CONFIG_PNP
  940. static int __devinit snd_msnd_pnp_detect(struct pnp_card_link *pcard,
  941. const struct pnp_card_device_id *pid)
  942. {
  943. static int idx;
  944. struct pnp_dev *pnp_dev;
  945. struct pnp_dev *mpu_dev;
  946. struct snd_card *card;
  947. struct snd_msnd *chip;
  948. int ret;
  949. for ( ; idx < SNDRV_CARDS; idx++) {
  950. if (has_isapnp(idx))
  951. break;
  952. }
  953. if (idx >= SNDRV_CARDS)
  954. return -ENODEV;
  955. /*
  956. * Check that we still have room for another sound card ...
  957. */
  958. pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  959. if (!pnp_dev)
  960. return -ENODEV;
  961. mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
  962. if (!mpu_dev)
  963. return -ENODEV;
  964. if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
  965. printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
  966. return -EBUSY;
  967. }
  968. if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
  969. printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
  970. return -EBUSY;
  971. }
  972. /*
  973. * Create a new ALSA sound card entry, in anticipation
  974. * of detecting our hardware ...
  975. */
  976. ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
  977. sizeof(struct snd_msnd), &card);
  978. if (ret < 0)
  979. return ret;
  980. chip = card->private_data;
  981. chip->card = card;
  982. snd_card_set_dev(card, &pcard->card->dev);
  983. /*
  984. * Read the correct parameters off the ISA PnP bus ...
  985. */
  986. io[idx] = pnp_port_start(pnp_dev, 0);
  987. irq[idx] = pnp_irq(pnp_dev, 0);
  988. mem[idx] = pnp_mem_start(pnp_dev, 0);
  989. mpu_io[idx] = pnp_port_start(mpu_dev, 0);
  990. mpu_irq[idx] = pnp_irq(mpu_dev, 0);
  991. set_default_audio_parameters(chip);
  992. #ifdef MSND_CLASSIC
  993. chip->type = msndClassic;
  994. #else
  995. chip->type = msndPinnacle;
  996. #endif
  997. chip->io = io[idx];
  998. chip->irq = irq[idx];
  999. chip->base = mem[idx];
  1000. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  1001. chip->recsrc = 0;
  1002. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  1003. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  1004. if (write_ndelay[idx])
  1005. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1006. else
  1007. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1008. #ifndef MSND_CLASSIC
  1009. if (digital[idx])
  1010. set_bit(F_HAVEDIGITAL, &chip->flags);
  1011. #endif
  1012. spin_lock_init(&chip->lock);
  1013. ret = snd_msnd_probe(card);
  1014. if (ret < 0) {
  1015. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1016. goto _release_card;
  1017. }
  1018. ret = snd_msnd_attach(card);
  1019. if (ret < 0) {
  1020. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1021. goto _release_card;
  1022. }
  1023. pnp_set_card_drvdata(pcard, card);
  1024. ++idx;
  1025. return 0;
  1026. _release_card:
  1027. snd_card_free(card);
  1028. return ret;
  1029. }
  1030. static void __devexit snd_msnd_pnp_remove(struct pnp_card_link *pcard)
  1031. {
  1032. snd_msnd_unload(pnp_get_card_drvdata(pcard));
  1033. pnp_set_card_drvdata(pcard, NULL);
  1034. }
  1035. static int isa_registered;
  1036. static int pnp_registered;
  1037. static struct pnp_card_device_id msnd_pnpids[] = {
  1038. /* Pinnacle PnP */
  1039. { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
  1040. { .id = "" } /* end */
  1041. };
  1042. MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
  1043. static struct pnp_card_driver msnd_pnpc_driver = {
  1044. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1045. .name = "msnd_pinnacle",
  1046. .id_table = msnd_pnpids,
  1047. .probe = snd_msnd_pnp_detect,
  1048. .remove = __devexit_p(snd_msnd_pnp_remove),
  1049. };
  1050. #endif /* CONFIG_PNP */
  1051. static int __init snd_msnd_init(void)
  1052. {
  1053. int err;
  1054. err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
  1055. #ifdef CONFIG_PNP
  1056. if (!err)
  1057. isa_registered = 1;
  1058. err = pnp_register_card_driver(&msnd_pnpc_driver);
  1059. if (!err)
  1060. pnp_registered = 1;
  1061. if (isa_registered)
  1062. err = 0;
  1063. #endif
  1064. return err;
  1065. }
  1066. static void __exit snd_msnd_exit(void)
  1067. {
  1068. #ifdef CONFIG_PNP
  1069. if (pnp_registered)
  1070. pnp_unregister_card_driver(&msnd_pnpc_driver);
  1071. if (isa_registered)
  1072. #endif
  1073. isa_unregister_driver(&snd_msnd_driver);
  1074. }
  1075. module_init(snd_msnd_init);
  1076. module_exit(snd_msnd_exit);