msnd_pinnacle.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  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 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 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 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 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);
  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 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 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 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 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 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 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 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 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 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 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 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_new(pdev, index[idx], id[idx], THIS_MODULE,
  787. sizeof(struct snd_msnd), &card);
  788. if (err < 0)
  789. return err;
  790. chip = card->private_data;
  791. chip->card = card;
  792. #ifdef MSND_CLASSIC
  793. switch (irq[idx]) {
  794. case 5:
  795. chip->irqid = HPIRQ_5; break;
  796. case 7:
  797. chip->irqid = HPIRQ_7; break;
  798. case 9:
  799. chip->irqid = HPIRQ_9; break;
  800. case 10:
  801. chip->irqid = HPIRQ_10; break;
  802. case 11:
  803. chip->irqid = HPIRQ_11; break;
  804. case 12:
  805. chip->irqid = HPIRQ_12; break;
  806. }
  807. switch (mem[idx]) {
  808. case 0xb0000:
  809. chip->memid = HPMEM_B000; break;
  810. case 0xc8000:
  811. chip->memid = HPMEM_C800; break;
  812. case 0xd0000:
  813. chip->memid = HPMEM_D000; break;
  814. case 0xd8000:
  815. chip->memid = HPMEM_D800; break;
  816. case 0xe0000:
  817. chip->memid = HPMEM_E000; break;
  818. case 0xe8000:
  819. chip->memid = HPMEM_E800; break;
  820. }
  821. #else
  822. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
  823. cfg[idx]);
  824. if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
  825. printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
  826. cfg[idx]);
  827. snd_card_free(card);
  828. return -EIO;
  829. }
  830. if (reset[idx])
  831. if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
  832. err = -EIO;
  833. goto cfg_error;
  834. }
  835. /* DSP */
  836. err = snd_msnd_write_cfg_logical(cfg[idx], 0,
  837. io[idx], 0,
  838. irq[idx], mem[idx]);
  839. if (err)
  840. goto cfg_error;
  841. /* The following are Pinnacle specific */
  842. /* MPU */
  843. if (mpu_io[idx] != SNDRV_AUTO_PORT
  844. && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
  845. printk(KERN_INFO LOGNAME
  846. ": Configuring MPU to I/O 0x%lx IRQ %d\n",
  847. mpu_io[idx], mpu_irq[idx]);
  848. err = snd_msnd_write_cfg_logical(cfg[idx], 1,
  849. mpu_io[idx], 0,
  850. mpu_irq[idx], 0);
  851. if (err)
  852. goto cfg_error;
  853. }
  854. /* IDE */
  855. if (ide_io0[idx] != SNDRV_AUTO_PORT
  856. && ide_io1[idx] != SNDRV_AUTO_PORT
  857. && ide_irq[idx] != SNDRV_AUTO_IRQ) {
  858. printk(KERN_INFO LOGNAME
  859. ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
  860. ide_io0[idx], ide_io1[idx], ide_irq[idx]);
  861. err = snd_msnd_write_cfg_logical(cfg[idx], 2,
  862. ide_io0[idx], ide_io1[idx],
  863. ide_irq[idx], 0);
  864. if (err)
  865. goto cfg_error;
  866. }
  867. /* Joystick */
  868. if (joystick_io[idx] != SNDRV_AUTO_PORT) {
  869. printk(KERN_INFO LOGNAME
  870. ": Configuring joystick to I/O 0x%lx\n",
  871. joystick_io[idx]);
  872. err = snd_msnd_write_cfg_logical(cfg[idx], 3,
  873. joystick_io[idx], 0,
  874. 0, 0);
  875. if (err)
  876. goto cfg_error;
  877. }
  878. release_region(cfg[idx], 2);
  879. #endif /* MSND_CLASSIC */
  880. set_default_audio_parameters(chip);
  881. #ifdef MSND_CLASSIC
  882. chip->type = msndClassic;
  883. #else
  884. chip->type = msndPinnacle;
  885. #endif
  886. chip->io = io[idx];
  887. chip->irq = irq[idx];
  888. chip->base = mem[idx];
  889. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  890. chip->recsrc = 0;
  891. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  892. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  893. if (write_ndelay[idx])
  894. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  895. else
  896. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  897. #ifndef MSND_CLASSIC
  898. if (digital[idx])
  899. set_bit(F_HAVEDIGITAL, &chip->flags);
  900. #endif
  901. spin_lock_init(&chip->lock);
  902. err = snd_msnd_probe(card);
  903. if (err < 0) {
  904. printk(KERN_ERR LOGNAME ": Probe failed\n");
  905. snd_card_free(card);
  906. return err;
  907. }
  908. err = snd_msnd_attach(card);
  909. if (err < 0) {
  910. printk(KERN_ERR LOGNAME ": Attach failed\n");
  911. snd_card_free(card);
  912. return err;
  913. }
  914. dev_set_drvdata(pdev, card);
  915. return 0;
  916. #ifndef MSND_CLASSIC
  917. cfg_error:
  918. release_region(cfg[idx], 2);
  919. snd_card_free(card);
  920. return err;
  921. #endif
  922. }
  923. static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
  924. {
  925. snd_msnd_unload(dev_get_drvdata(pdev));
  926. return 0;
  927. }
  928. static struct isa_driver snd_msnd_driver = {
  929. .match = snd_msnd_isa_match,
  930. .probe = snd_msnd_isa_probe,
  931. .remove = snd_msnd_isa_remove,
  932. /* FIXME: suspend, resume */
  933. .driver = {
  934. .name = DEV_NAME
  935. },
  936. };
  937. #ifdef CONFIG_PNP
  938. static int snd_msnd_pnp_detect(struct pnp_card_link *pcard,
  939. const struct pnp_card_device_id *pid)
  940. {
  941. static int idx;
  942. struct pnp_dev *pnp_dev;
  943. struct pnp_dev *mpu_dev;
  944. struct snd_card *card;
  945. struct snd_msnd *chip;
  946. int ret;
  947. for ( ; idx < SNDRV_CARDS; idx++) {
  948. if (has_isapnp(idx))
  949. break;
  950. }
  951. if (idx >= SNDRV_CARDS)
  952. return -ENODEV;
  953. /*
  954. * Check that we still have room for another sound card ...
  955. */
  956. pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  957. if (!pnp_dev)
  958. return -ENODEV;
  959. mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
  960. if (!mpu_dev)
  961. return -ENODEV;
  962. if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
  963. printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
  964. return -EBUSY;
  965. }
  966. if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
  967. printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
  968. return -EBUSY;
  969. }
  970. /*
  971. * Create a new ALSA sound card entry, in anticipation
  972. * of detecting our hardware ...
  973. */
  974. ret = snd_card_new(&pcard->card->dev,
  975. index[idx], id[idx], THIS_MODULE,
  976. sizeof(struct snd_msnd), &card);
  977. if (ret < 0)
  978. return ret;
  979. chip = card->private_data;
  980. chip->card = card;
  981. /*
  982. * Read the correct parameters off the ISA PnP bus ...
  983. */
  984. io[idx] = pnp_port_start(pnp_dev, 0);
  985. irq[idx] = pnp_irq(pnp_dev, 0);
  986. mem[idx] = pnp_mem_start(pnp_dev, 0);
  987. mpu_io[idx] = pnp_port_start(mpu_dev, 0);
  988. mpu_irq[idx] = pnp_irq(mpu_dev, 0);
  989. set_default_audio_parameters(chip);
  990. #ifdef MSND_CLASSIC
  991. chip->type = msndClassic;
  992. #else
  993. chip->type = msndPinnacle;
  994. #endif
  995. chip->io = io[idx];
  996. chip->irq = irq[idx];
  997. chip->base = mem[idx];
  998. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  999. chip->recsrc = 0;
  1000. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  1001. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  1002. if (write_ndelay[idx])
  1003. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1004. else
  1005. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1006. #ifndef MSND_CLASSIC
  1007. if (digital[idx])
  1008. set_bit(F_HAVEDIGITAL, &chip->flags);
  1009. #endif
  1010. spin_lock_init(&chip->lock);
  1011. ret = snd_msnd_probe(card);
  1012. if (ret < 0) {
  1013. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1014. goto _release_card;
  1015. }
  1016. ret = snd_msnd_attach(card);
  1017. if (ret < 0) {
  1018. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1019. goto _release_card;
  1020. }
  1021. pnp_set_card_drvdata(pcard, card);
  1022. ++idx;
  1023. return 0;
  1024. _release_card:
  1025. snd_card_free(card);
  1026. return ret;
  1027. }
  1028. static void snd_msnd_pnp_remove(struct pnp_card_link *pcard)
  1029. {
  1030. snd_msnd_unload(pnp_get_card_drvdata(pcard));
  1031. pnp_set_card_drvdata(pcard, NULL);
  1032. }
  1033. static int isa_registered;
  1034. static int pnp_registered;
  1035. static struct pnp_card_device_id msnd_pnpids[] = {
  1036. /* Pinnacle PnP */
  1037. { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
  1038. { .id = "" } /* end */
  1039. };
  1040. MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
  1041. static struct pnp_card_driver msnd_pnpc_driver = {
  1042. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1043. .name = "msnd_pinnacle",
  1044. .id_table = msnd_pnpids,
  1045. .probe = snd_msnd_pnp_detect,
  1046. .remove = snd_msnd_pnp_remove,
  1047. };
  1048. #endif /* CONFIG_PNP */
  1049. static int __init snd_msnd_init(void)
  1050. {
  1051. int err;
  1052. err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
  1053. #ifdef CONFIG_PNP
  1054. if (!err)
  1055. isa_registered = 1;
  1056. err = pnp_register_card_driver(&msnd_pnpc_driver);
  1057. if (!err)
  1058. pnp_registered = 1;
  1059. if (isa_registered)
  1060. err = 0;
  1061. #endif
  1062. return err;
  1063. }
  1064. static void __exit snd_msnd_exit(void)
  1065. {
  1066. #ifdef CONFIG_PNP
  1067. if (pnp_registered)
  1068. pnp_unregister_card_driver(&msnd_pnpc_driver);
  1069. if (isa_registered)
  1070. #endif
  1071. isa_unregister_driver(&snd_msnd_driver);
  1072. }
  1073. module_init(snd_msnd_init);
  1074. module_exit(snd_msnd_exit);