msnd_pinnacle.c 31 KB

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