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 = snd_pcm_format_width(DEFSAMPLESIZE);
  82. chip->play_sample_rate = DEFSAMPLERATE;
  83. chip->play_channels = DEFCHANNELS;
  84. chip->capture_sample_size = snd_pcm_format_width(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. u16 head, tail, size;
  157. /* Send ack to DSP */
  158. /* inb(chip->io + HP_RXL); */
  159. /* Evaluate queued DSP messages */
  160. head = readw(chip->DSPQ + JQS_wHead);
  161. tail = readw(chip->DSPQ + JQS_wTail);
  162. size = readw(chip->DSPQ + JQS_wSize);
  163. if (head > size || tail > size)
  164. goto out;
  165. while (head != tail) {
  166. snd_msnd_eval_dsp_msg(chip, readw(pwDSPQData + 2 * head));
  167. if (++head > size)
  168. head = 0;
  169. writew(head, chip->DSPQ + JQS_wHead);
  170. }
  171. out:
  172. /* Send ack to DSP */
  173. inb(chip->io + HP_RXL);
  174. return IRQ_HANDLED;
  175. }
  176. static int snd_msnd_reset_dsp(long io, unsigned char *info)
  177. {
  178. int timeout = 100;
  179. outb(HPDSPRESET_ON, io + HP_DSPR);
  180. msleep(1);
  181. #ifndef MSND_CLASSIC
  182. if (info)
  183. *info = inb(io + HP_INFO);
  184. #endif
  185. outb(HPDSPRESET_OFF, io + HP_DSPR);
  186. msleep(1);
  187. while (timeout-- > 0) {
  188. if (inb(io + HP_CVR) == HP_CVR_DEF)
  189. return 0;
  190. msleep(1);
  191. }
  192. snd_printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
  193. return -EIO;
  194. }
  195. static int snd_msnd_probe(struct snd_card *card)
  196. {
  197. struct snd_msnd *chip = card->private_data;
  198. unsigned char info;
  199. #ifndef MSND_CLASSIC
  200. char *xv, *rev = NULL;
  201. char *pin = "TB Pinnacle", *fiji = "TB Fiji";
  202. char *pinfiji = "TB Pinnacle/Fiji";
  203. #endif
  204. if (!request_region(chip->io, DSP_NUMIO, "probing")) {
  205. snd_printk(KERN_ERR LOGNAME ": I/O port conflict\n");
  206. return -ENODEV;
  207. }
  208. if (snd_msnd_reset_dsp(chip->io, &info) < 0) {
  209. release_region(chip->io, DSP_NUMIO);
  210. return -ENODEV;
  211. }
  212. #ifdef MSND_CLASSIC
  213. strcpy(card->shortname, "Classic/Tahiti/Monterey");
  214. strcpy(card->longname, "Turtle Beach Multisound");
  215. printk(KERN_INFO LOGNAME ": %s, "
  216. "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
  217. card->shortname,
  218. chip->io, chip->io + DSP_NUMIO - 1,
  219. chip->irq,
  220. chip->base, chip->base + 0x7fff);
  221. #else
  222. switch (info >> 4) {
  223. case 0xf:
  224. xv = "<= 1.15";
  225. break;
  226. case 0x1:
  227. xv = "1.18/1.2";
  228. break;
  229. case 0x2:
  230. xv = "1.3";
  231. break;
  232. case 0x3:
  233. xv = "1.4";
  234. break;
  235. default:
  236. xv = "unknown";
  237. break;
  238. }
  239. switch (info & 0x7) {
  240. case 0x0:
  241. rev = "I";
  242. strcpy(card->shortname, pin);
  243. break;
  244. case 0x1:
  245. rev = "F";
  246. strcpy(card->shortname, pin);
  247. break;
  248. case 0x2:
  249. rev = "G";
  250. strcpy(card->shortname, pin);
  251. break;
  252. case 0x3:
  253. rev = "H";
  254. strcpy(card->shortname, pin);
  255. break;
  256. case 0x4:
  257. rev = "E";
  258. strcpy(card->shortname, fiji);
  259. break;
  260. case 0x5:
  261. rev = "C";
  262. strcpy(card->shortname, fiji);
  263. break;
  264. case 0x6:
  265. rev = "D";
  266. strcpy(card->shortname, fiji);
  267. break;
  268. case 0x7:
  269. rev = "A-B (Fiji) or A-E (Pinnacle)";
  270. strcpy(card->shortname, pinfiji);
  271. break;
  272. }
  273. strcpy(card->longname, "Turtle Beach Multisound Pinnacle");
  274. printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
  275. "I/O 0x%lx-0x%lx, IRQ %d, memory mapped to 0x%lX-0x%lX\n",
  276. card->shortname,
  277. rev, xv,
  278. chip->io, chip->io + DSP_NUMIO - 1,
  279. chip->irq,
  280. chip->base, chip->base + 0x7fff);
  281. #endif
  282. release_region(chip->io, DSP_NUMIO);
  283. return 0;
  284. }
  285. static int snd_msnd_init_sma(struct snd_msnd *chip)
  286. {
  287. static int initted;
  288. u16 mastVolLeft, mastVolRight;
  289. unsigned long flags;
  290. #ifdef MSND_CLASSIC
  291. outb(chip->memid, chip->io + HP_MEMM);
  292. #endif
  293. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  294. /* Motorola 56k shared memory base */
  295. chip->SMA = chip->mappedbase + SMA_STRUCT_START;
  296. if (initted) {
  297. mastVolLeft = readw(chip->SMA + SMA_wCurrMastVolLeft);
  298. mastVolRight = readw(chip->SMA + SMA_wCurrMastVolRight);
  299. } else
  300. mastVolLeft = mastVolRight = 0;
  301. memset_io(chip->mappedbase, 0, 0x8000);
  302. /* Critical section: bank 1 access */
  303. spin_lock_irqsave(&chip->lock, flags);
  304. outb(HPBLKSEL_1, chip->io + HP_BLKS);
  305. memset_io(chip->mappedbase, 0, 0x8000);
  306. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  307. spin_unlock_irqrestore(&chip->lock, flags);
  308. /* Digital audio play queue */
  309. chip->DAPQ = chip->mappedbase + DAPQ_OFFSET;
  310. snd_msnd_init_queue(chip->DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
  311. /* Digital audio record queue */
  312. chip->DARQ = chip->mappedbase + DARQ_OFFSET;
  313. snd_msnd_init_queue(chip->DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
  314. /* MIDI out queue */
  315. chip->MODQ = chip->mappedbase + MODQ_OFFSET;
  316. snd_msnd_init_queue(chip->MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
  317. /* MIDI in queue */
  318. chip->MIDQ = chip->mappedbase + MIDQ_OFFSET;
  319. snd_msnd_init_queue(chip->MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
  320. /* DSP -> host message queue */
  321. chip->DSPQ = chip->mappedbase + DSPQ_OFFSET;
  322. snd_msnd_init_queue(chip->DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
  323. /* Setup some DSP values */
  324. #ifndef MSND_CLASSIC
  325. writew(1, chip->SMA + SMA_wCurrPlayFormat);
  326. writew(chip->play_sample_size, chip->SMA + SMA_wCurrPlaySampleSize);
  327. writew(chip->play_channels, chip->SMA + SMA_wCurrPlayChannels);
  328. writew(chip->play_sample_rate, chip->SMA + SMA_wCurrPlaySampleRate);
  329. #endif
  330. writew(chip->play_sample_rate, chip->SMA + SMA_wCalFreqAtoD);
  331. writew(mastVolLeft, chip->SMA + SMA_wCurrMastVolLeft);
  332. writew(mastVolRight, chip->SMA + SMA_wCurrMastVolRight);
  333. #ifndef MSND_CLASSIC
  334. writel(0x00010000, chip->SMA + SMA_dwCurrPlayPitch);
  335. writel(0x00000001, chip->SMA + SMA_dwCurrPlayRate);
  336. #endif
  337. writew(0x303, chip->SMA + SMA_wCurrInputTagBits);
  338. initted = 1;
  339. return 0;
  340. }
  341. static int upload_dsp_code(struct snd_card *card)
  342. {
  343. struct snd_msnd *chip = card->private_data;
  344. const struct firmware *init_fw = NULL, *perm_fw = NULL;
  345. int err;
  346. outb(HPBLKSEL_0, chip->io + HP_BLKS);
  347. err = request_firmware(&init_fw, INITCODEFILE, card->dev);
  348. if (err < 0) {
  349. printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
  350. goto cleanup1;
  351. }
  352. err = request_firmware(&perm_fw, PERMCODEFILE, card->dev);
  353. if (err < 0) {
  354. printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
  355. goto cleanup;
  356. }
  357. memcpy_toio(chip->mappedbase, perm_fw->data, perm_fw->size);
  358. if (snd_msnd_upload_host(chip, init_fw->data, init_fw->size) < 0) {
  359. printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
  360. err = -ENODEV;
  361. goto cleanup;
  362. }
  363. printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
  364. err = 0;
  365. cleanup:
  366. release_firmware(perm_fw);
  367. cleanup1:
  368. release_firmware(init_fw);
  369. return err;
  370. }
  371. #ifdef MSND_CLASSIC
  372. static void reset_proteus(struct snd_msnd *chip)
  373. {
  374. outb(HPPRORESET_ON, chip->io + HP_PROR);
  375. msleep(TIME_PRO_RESET);
  376. outb(HPPRORESET_OFF, chip->io + HP_PROR);
  377. msleep(TIME_PRO_RESET_DONE);
  378. }
  379. #endif
  380. static int snd_msnd_initialize(struct snd_card *card)
  381. {
  382. struct snd_msnd *chip = card->private_data;
  383. int err, timeout;
  384. #ifdef MSND_CLASSIC
  385. outb(HPWAITSTATE_0, chip->io + HP_WAIT);
  386. outb(HPBITMODE_16, chip->io + HP_BITM);
  387. reset_proteus(chip);
  388. #endif
  389. err = snd_msnd_init_sma(chip);
  390. if (err < 0) {
  391. printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
  392. return err;
  393. }
  394. err = snd_msnd_reset_dsp(chip->io, NULL);
  395. if (err < 0)
  396. return err;
  397. err = upload_dsp_code(card);
  398. if (err < 0) {
  399. printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
  400. return err;
  401. }
  402. timeout = 200;
  403. while (readw(chip->mappedbase)) {
  404. msleep(1);
  405. if (!timeout--) {
  406. snd_printd(KERN_ERR LOGNAME ": DSP reset timeout\n");
  407. return -EIO;
  408. }
  409. }
  410. snd_msndmix_setup(chip);
  411. return 0;
  412. }
  413. static int snd_msnd_dsp_full_reset(struct snd_card *card)
  414. {
  415. struct snd_msnd *chip = card->private_data;
  416. int rv;
  417. if (test_bit(F_RESETTING, &chip->flags) || ++chip->nresets > 10)
  418. return 0;
  419. set_bit(F_RESETTING, &chip->flags);
  420. snd_msnd_dsp_halt(chip, NULL); /* Unconditionally halt */
  421. rv = snd_msnd_initialize(card);
  422. if (rv)
  423. printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
  424. snd_msndmix_force_recsrc(chip, 0);
  425. clear_bit(F_RESETTING, &chip->flags);
  426. return rv;
  427. }
  428. static int snd_msnd_dev_free(struct snd_device *device)
  429. {
  430. snd_printdd("snd_msnd_chip_free()\n");
  431. return 0;
  432. }
  433. static int snd_msnd_send_dsp_cmd_chk(struct snd_msnd *chip, u8 cmd)
  434. {
  435. if (snd_msnd_send_dsp_cmd(chip, cmd) == 0)
  436. return 0;
  437. snd_msnd_dsp_full_reset(chip->card);
  438. return snd_msnd_send_dsp_cmd(chip, cmd);
  439. }
  440. static int snd_msnd_calibrate_adc(struct snd_msnd *chip, u16 srate)
  441. {
  442. snd_printdd("snd_msnd_calibrate_adc(%i)\n", srate);
  443. writew(srate, chip->SMA + SMA_wCalFreqAtoD);
  444. if (chip->calibrate_signal == 0)
  445. writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
  446. | 0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
  447. else
  448. writew(readw(chip->SMA + SMA_wCurrHostStatusFlags)
  449. & ~0x0001, chip->SMA + SMA_wCurrHostStatusFlags);
  450. if (snd_msnd_send_word(chip, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
  451. snd_msnd_send_dsp_cmd_chk(chip, HDEX_AUX_REQ) == 0) {
  452. schedule_timeout_interruptible(msecs_to_jiffies(333));
  453. return 0;
  454. }
  455. printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
  456. return -EIO;
  457. }
  458. /*
  459. * ALSA callback function, called when attempting to open the MIDI device.
  460. */
  461. static int snd_msnd_mpu401_open(struct snd_mpu401 *mpu)
  462. {
  463. snd_msnd_enable_irq(mpu->private_data);
  464. snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_START);
  465. return 0;
  466. }
  467. static void snd_msnd_mpu401_close(struct snd_mpu401 *mpu)
  468. {
  469. snd_msnd_send_dsp_cmd(mpu->private_data, HDEX_MIDI_IN_STOP);
  470. snd_msnd_disable_irq(mpu->private_data);
  471. }
  472. static long mpu_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  473. static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  474. static int snd_msnd_attach(struct snd_card *card)
  475. {
  476. struct snd_msnd *chip = card->private_data;
  477. int err;
  478. static struct snd_device_ops ops = {
  479. .dev_free = snd_msnd_dev_free,
  480. };
  481. err = request_irq(chip->irq, snd_msnd_interrupt, 0, card->shortname,
  482. chip);
  483. if (err < 0) {
  484. printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", chip->irq);
  485. return err;
  486. }
  487. if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) {
  488. free_irq(chip->irq, chip);
  489. return -EBUSY;
  490. }
  491. if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
  492. printk(KERN_ERR LOGNAME
  493. ": unable to grab memory region 0x%lx-0x%lx\n",
  494. chip->base, chip->base + BUFFSIZE - 1);
  495. release_region(chip->io, DSP_NUMIO);
  496. free_irq(chip->irq, chip);
  497. return -EBUSY;
  498. }
  499. chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
  500. if (!chip->mappedbase) {
  501. printk(KERN_ERR LOGNAME
  502. ": unable to map memory region 0x%lx-0x%lx\n",
  503. chip->base, chip->base + BUFFSIZE - 1);
  504. err = -EIO;
  505. goto err_release_region;
  506. }
  507. err = snd_msnd_dsp_full_reset(card);
  508. if (err < 0)
  509. goto err_release_region;
  510. /* Register device */
  511. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  512. if (err < 0)
  513. goto err_release_region;
  514. err = snd_msnd_pcm(card, 0);
  515. if (err < 0) {
  516. printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
  517. goto err_release_region;
  518. }
  519. err = snd_msndmix_new(card);
  520. if (err < 0) {
  521. printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
  522. goto err_release_region;
  523. }
  524. if (mpu_io[0] != SNDRV_AUTO_PORT) {
  525. struct snd_mpu401 *mpu;
  526. err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  527. mpu_io[0],
  528. MPU401_MODE_INPUT |
  529. MPU401_MODE_OUTPUT,
  530. mpu_irq[0],
  531. &chip->rmidi);
  532. if (err < 0) {
  533. printk(KERN_ERR LOGNAME
  534. ": error creating new Midi device\n");
  535. goto err_release_region;
  536. }
  537. mpu = chip->rmidi->private_data;
  538. mpu->open_input = snd_msnd_mpu401_open;
  539. mpu->close_input = snd_msnd_mpu401_close;
  540. mpu->private_data = chip;
  541. }
  542. disable_irq(chip->irq);
  543. snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
  544. snd_msndmix_force_recsrc(chip, 0);
  545. err = snd_card_register(card);
  546. if (err < 0)
  547. goto err_release_region;
  548. return 0;
  549. err_release_region:
  550. iounmap(chip->mappedbase);
  551. release_mem_region(chip->base, BUFFSIZE);
  552. release_region(chip->io, DSP_NUMIO);
  553. free_irq(chip->irq, chip);
  554. return err;
  555. }
  556. static void snd_msnd_unload(struct snd_card *card)
  557. {
  558. struct snd_msnd *chip = card->private_data;
  559. iounmap(chip->mappedbase);
  560. release_mem_region(chip->base, BUFFSIZE);
  561. release_region(chip->io, DSP_NUMIO);
  562. free_irq(chip->irq, chip);
  563. snd_card_free(card);
  564. }
  565. #ifndef MSND_CLASSIC
  566. /* Pinnacle/Fiji Logical Device Configuration */
  567. static int snd_msnd_write_cfg(int cfg, int reg, int value)
  568. {
  569. outb(reg, cfg);
  570. outb(value, cfg + 1);
  571. if (value != inb(cfg + 1)) {
  572. printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
  573. return -EIO;
  574. }
  575. return 0;
  576. }
  577. static int snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
  578. {
  579. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  580. return -EIO;
  581. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  582. return -EIO;
  583. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  584. return -EIO;
  585. return 0;
  586. }
  587. static int snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
  588. {
  589. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  590. return -EIO;
  591. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  592. return -EIO;
  593. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  594. return -EIO;
  595. return 0;
  596. }
  597. static int snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
  598. {
  599. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  600. return -EIO;
  601. if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  602. return -EIO;
  603. if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  604. return -EIO;
  605. return 0;
  606. }
  607. static int snd_msnd_write_cfg_mem(int cfg, int num, int mem)
  608. {
  609. u16 wmem;
  610. mem >>= 8;
  611. wmem = (u16)(mem & 0xfff);
  612. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  613. return -EIO;
  614. if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  615. return -EIO;
  616. if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  617. return -EIO;
  618. if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
  619. MEMTYPE_HIADDR | MEMTYPE_16BIT))
  620. return -EIO;
  621. return 0;
  622. }
  623. static int snd_msnd_activate_logical(int cfg, int num)
  624. {
  625. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  626. return -EIO;
  627. if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  628. return -EIO;
  629. return 0;
  630. }
  631. static int snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
  632. u16 io1, u16 irq, int mem)
  633. {
  634. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  635. return -EIO;
  636. if (snd_msnd_write_cfg_io0(cfg, num, io0))
  637. return -EIO;
  638. if (snd_msnd_write_cfg_io1(cfg, num, io1))
  639. return -EIO;
  640. if (snd_msnd_write_cfg_irq(cfg, num, irq))
  641. return -EIO;
  642. if (snd_msnd_write_cfg_mem(cfg, num, mem))
  643. return -EIO;
  644. if (snd_msnd_activate_logical(cfg, num))
  645. return -EIO;
  646. return 0;
  647. }
  648. static int snd_msnd_pinnacle_cfg_reset(int cfg)
  649. {
  650. int i;
  651. /* Reset devices if told to */
  652. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  653. for (i = 0; i < 4; ++i)
  654. if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  655. return -EIO;
  656. return 0;
  657. }
  658. #endif
  659. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  660. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  661. module_param_array(index, int, NULL, S_IRUGO);
  662. MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
  663. module_param_array(id, charp, NULL, S_IRUGO);
  664. MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
  665. static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  666. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  667. static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  668. #ifndef MSND_CLASSIC
  669. static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  670. /* Extra Peripheral Configuration (Default: Disable) */
  671. static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  672. static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  673. static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  674. static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  675. /* If we have the digital daugherboard... */
  676. static int digital[SNDRV_CARDS];
  677. /* Extra Peripheral Configuration */
  678. static int reset[SNDRV_CARDS];
  679. #endif
  680. static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
  681. static int calibrate_signal;
  682. #ifdef CONFIG_PNP
  683. static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  684. module_param_array(isapnp, bool, NULL, 0444);
  685. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  686. #define has_isapnp(x) isapnp[x]
  687. #else
  688. #define has_isapnp(x) 0
  689. #endif
  690. MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
  691. MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
  692. MODULE_LICENSE("GPL");
  693. MODULE_FIRMWARE(INITCODEFILE);
  694. MODULE_FIRMWARE(PERMCODEFILE);
  695. module_param_array(io, long, NULL, S_IRUGO);
  696. MODULE_PARM_DESC(io, "IO port #");
  697. module_param_array(irq, int, NULL, S_IRUGO);
  698. module_param_array(mem, long, NULL, S_IRUGO);
  699. module_param_array(write_ndelay, int, NULL, S_IRUGO);
  700. module_param(calibrate_signal, int, S_IRUGO);
  701. #ifndef MSND_CLASSIC
  702. module_param_array(digital, int, NULL, S_IRUGO);
  703. module_param_array(cfg, long, NULL, S_IRUGO);
  704. module_param_array(reset, int, 0, S_IRUGO);
  705. module_param_array(mpu_io, long, NULL, S_IRUGO);
  706. module_param_array(mpu_irq, int, NULL, S_IRUGO);
  707. module_param_array(ide_io0, long, NULL, S_IRUGO);
  708. module_param_array(ide_io1, long, NULL, S_IRUGO);
  709. module_param_array(ide_irq, int, NULL, S_IRUGO);
  710. module_param_array(joystick_io, long, NULL, S_IRUGO);
  711. #endif
  712. static int snd_msnd_isa_match(struct device *pdev, unsigned int i)
  713. {
  714. if (io[i] == SNDRV_AUTO_PORT)
  715. return 0;
  716. if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
  717. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  718. return 0;
  719. }
  720. #ifdef MSND_CLASSIC
  721. if (!(io[i] == 0x290 ||
  722. io[i] == 0x260 ||
  723. io[i] == 0x250 ||
  724. io[i] == 0x240 ||
  725. io[i] == 0x230 ||
  726. io[i] == 0x220 ||
  727. io[i] == 0x210 ||
  728. io[i] == 0x3e0)) {
  729. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
  730. " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
  731. "or 0x3E0\n");
  732. return 0;
  733. }
  734. #else
  735. if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
  736. printk(KERN_ERR LOGNAME
  737. ": \"io\" - DSP I/O base must within the range 0x100 "
  738. "to 0x3E0 and must be evenly divisible by 0x10\n");
  739. return 0;
  740. }
  741. #endif /* MSND_CLASSIC */
  742. if (!(irq[i] == 5 ||
  743. irq[i] == 7 ||
  744. irq[i] == 9 ||
  745. irq[i] == 10 ||
  746. irq[i] == 11 ||
  747. irq[i] == 12)) {
  748. printk(KERN_ERR LOGNAME
  749. ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  750. return 0;
  751. }
  752. if (!(mem[i] == 0xb0000 ||
  753. mem[i] == 0xc8000 ||
  754. mem[i] == 0xd0000 ||
  755. mem[i] == 0xd8000 ||
  756. mem[i] == 0xe0000 ||
  757. mem[i] == 0xe8000)) {
  758. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  759. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
  760. "0xe8000\n");
  761. return 0;
  762. }
  763. #ifndef MSND_CLASSIC
  764. if (cfg[i] == SNDRV_AUTO_PORT) {
  765. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  766. } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
  767. printk(KERN_INFO LOGNAME
  768. ": Config port must be 0x250, 0x260 or 0x270 "
  769. "(or unspecified for PnP mode)\n");
  770. return 0;
  771. }
  772. #endif /* MSND_CLASSIC */
  773. return 1;
  774. }
  775. static int snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
  776. {
  777. int err;
  778. struct snd_card *card;
  779. struct snd_msnd *chip;
  780. if (has_isapnp(idx)
  781. #ifndef MSND_CLASSIC
  782. || cfg[idx] == SNDRV_AUTO_PORT
  783. #endif
  784. ) {
  785. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  786. return -ENODEV;
  787. }
  788. err = snd_card_new(pdev, index[idx], id[idx], THIS_MODULE,
  789. sizeof(struct snd_msnd), &card);
  790. if (err < 0)
  791. return err;
  792. chip = card->private_data;
  793. chip->card = card;
  794. #ifdef MSND_CLASSIC
  795. switch (irq[idx]) {
  796. case 5:
  797. chip->irqid = HPIRQ_5; break;
  798. case 7:
  799. chip->irqid = HPIRQ_7; break;
  800. case 9:
  801. chip->irqid = HPIRQ_9; break;
  802. case 10:
  803. chip->irqid = HPIRQ_10; break;
  804. case 11:
  805. chip->irqid = HPIRQ_11; break;
  806. case 12:
  807. chip->irqid = HPIRQ_12; break;
  808. }
  809. switch (mem[idx]) {
  810. case 0xb0000:
  811. chip->memid = HPMEM_B000; break;
  812. case 0xc8000:
  813. chip->memid = HPMEM_C800; break;
  814. case 0xd0000:
  815. chip->memid = HPMEM_D000; break;
  816. case 0xd8000:
  817. chip->memid = HPMEM_D800; break;
  818. case 0xe0000:
  819. chip->memid = HPMEM_E000; break;
  820. case 0xe8000:
  821. chip->memid = HPMEM_E800; break;
  822. }
  823. #else
  824. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
  825. cfg[idx]);
  826. if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
  827. printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
  828. cfg[idx]);
  829. snd_card_free(card);
  830. return -EIO;
  831. }
  832. if (reset[idx])
  833. if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
  834. err = -EIO;
  835. goto cfg_error;
  836. }
  837. /* DSP */
  838. err = snd_msnd_write_cfg_logical(cfg[idx], 0,
  839. io[idx], 0,
  840. irq[idx], mem[idx]);
  841. if (err)
  842. goto cfg_error;
  843. /* The following are Pinnacle specific */
  844. /* MPU */
  845. if (mpu_io[idx] != SNDRV_AUTO_PORT
  846. && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
  847. printk(KERN_INFO LOGNAME
  848. ": Configuring MPU to I/O 0x%lx IRQ %d\n",
  849. mpu_io[idx], mpu_irq[idx]);
  850. err = snd_msnd_write_cfg_logical(cfg[idx], 1,
  851. mpu_io[idx], 0,
  852. mpu_irq[idx], 0);
  853. if (err)
  854. goto cfg_error;
  855. }
  856. /* IDE */
  857. if (ide_io0[idx] != SNDRV_AUTO_PORT
  858. && ide_io1[idx] != SNDRV_AUTO_PORT
  859. && ide_irq[idx] != SNDRV_AUTO_IRQ) {
  860. printk(KERN_INFO LOGNAME
  861. ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
  862. ide_io0[idx], ide_io1[idx], ide_irq[idx]);
  863. err = snd_msnd_write_cfg_logical(cfg[idx], 2,
  864. ide_io0[idx], ide_io1[idx],
  865. ide_irq[idx], 0);
  866. if (err)
  867. goto cfg_error;
  868. }
  869. /* Joystick */
  870. if (joystick_io[idx] != SNDRV_AUTO_PORT) {
  871. printk(KERN_INFO LOGNAME
  872. ": Configuring joystick to I/O 0x%lx\n",
  873. joystick_io[idx]);
  874. err = snd_msnd_write_cfg_logical(cfg[idx], 3,
  875. joystick_io[idx], 0,
  876. 0, 0);
  877. if (err)
  878. goto cfg_error;
  879. }
  880. release_region(cfg[idx], 2);
  881. #endif /* MSND_CLASSIC */
  882. set_default_audio_parameters(chip);
  883. #ifdef MSND_CLASSIC
  884. chip->type = msndClassic;
  885. #else
  886. chip->type = msndPinnacle;
  887. #endif
  888. chip->io = io[idx];
  889. chip->irq = irq[idx];
  890. chip->base = mem[idx];
  891. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  892. chip->recsrc = 0;
  893. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  894. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  895. if (write_ndelay[idx])
  896. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  897. else
  898. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  899. #ifndef MSND_CLASSIC
  900. if (digital[idx])
  901. set_bit(F_HAVEDIGITAL, &chip->flags);
  902. #endif
  903. spin_lock_init(&chip->lock);
  904. err = snd_msnd_probe(card);
  905. if (err < 0) {
  906. printk(KERN_ERR LOGNAME ": Probe failed\n");
  907. snd_card_free(card);
  908. return err;
  909. }
  910. err = snd_msnd_attach(card);
  911. if (err < 0) {
  912. printk(KERN_ERR LOGNAME ": Attach failed\n");
  913. snd_card_free(card);
  914. return err;
  915. }
  916. dev_set_drvdata(pdev, card);
  917. return 0;
  918. #ifndef MSND_CLASSIC
  919. cfg_error:
  920. release_region(cfg[idx], 2);
  921. snd_card_free(card);
  922. return err;
  923. #endif
  924. }
  925. static int snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
  926. {
  927. snd_msnd_unload(dev_get_drvdata(pdev));
  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 = snd_msnd_isa_remove,
  934. /* FIXME: suspend, resume */
  935. .driver = {
  936. .name = DEV_NAME
  937. },
  938. };
  939. #ifdef CONFIG_PNP
  940. static int 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_new(&pcard->card->dev,
  977. index[idx], id[idx], THIS_MODULE,
  978. sizeof(struct snd_msnd), &card);
  979. if (ret < 0)
  980. return ret;
  981. chip = card->private_data;
  982. chip->card = card;
  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 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 = 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);