msnd_pinnacle.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247
  1. /*********************************************************************
  2. *
  3. * Linux multisound pinnacle/fiji driver for ALSA.
  4. *
  5. * 2002/06/30 Karsten Wiese:
  6. * for now this is only used to build a pinnacle / fiji driver.
  7. * the OSS parent of this code is designed to also support
  8. * the multisound classic via the file msnd_classic.c.
  9. * to make it easier for some brave heart to implemt classic
  10. * support in alsa, i left all the MSND_CLASSIC tokens in this file.
  11. * but for now this untested & undone.
  12. *
  13. *
  14. * ripped from linux kernel 2.4.18 by Karsten Wiese.
  15. *
  16. * the following is a copy of the 2.4.18 OSS FREE file-heading comment:
  17. *
  18. * Turtle Beach MultiSound Sound Card Driver for Linux
  19. * msnd_pinnacle.c / msnd_classic.c
  20. *
  21. * -- If MSND_CLASSIC is defined:
  22. *
  23. * -> driver for Turtle Beach Classic/Monterey/Tahiti
  24. *
  25. * -- Else
  26. *
  27. * -> driver for Turtle Beach Pinnacle/Fiji
  28. *
  29. * 12-3-2000 Modified IO port validation Steve Sycamore
  30. *
  31. * Copyright (C) 1998 Andrew Veliath
  32. *
  33. * This program is free software; you can redistribute it and/or modify
  34. * it under the terms of the GNU General Public License as published by
  35. * the Free Software Foundation; either version 2 of the License, or
  36. * (at your option) any later version.
  37. *
  38. * This program is distributed in the hope that it will be useful,
  39. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  40. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  41. * GNU General Public License for more details.
  42. *
  43. * You should have received a copy of the GNU General Public License
  44. * along with this program; if not, write to the Free Software
  45. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  46. *
  47. ********************************************************************/
  48. #include <linux/kernel.h>
  49. #include <linux/module.h>
  50. #include <linux/interrupt.h>
  51. #include <linux/types.h>
  52. #include <linux/delay.h>
  53. #include <linux/ioport.h>
  54. #include <linux/firmware.h>
  55. #include <linux/isa.h>
  56. #include <linux/isapnp.h>
  57. #include <linux/irq.h>
  58. #include <linux/io.h>
  59. #include <sound/core.h>
  60. #include <sound/initval.h>
  61. #include <sound/asound.h>
  62. #include <sound/pcm.h>
  63. #include <sound/mpu401.h>
  64. #ifdef MSND_CLASSIC
  65. # ifndef __alpha__
  66. # define SLOWIO
  67. # endif
  68. #endif
  69. #include "msnd.h"
  70. #ifdef MSND_CLASSIC
  71. # include "msnd_classic.h"
  72. # define LOGNAME "msnd_classic"
  73. # define DEV_NAME "msnd-classic"
  74. #else
  75. # include "msnd_pinnacle.h"
  76. # define LOGNAME "snd_msnd_pinnacle"
  77. # define DEV_NAME "msnd-pinnacle"
  78. #endif
  79. static void __devinit set_default_audio_parameters(struct snd_msnd *chip)
  80. {
  81. chip->play_sample_size = DEFSAMPLESIZE;
  82. chip->play_sample_rate = DEFSAMPLERATE;
  83. chip->play_channels = DEFCHANNELS;
  84. chip->capture_sample_size = DEFSAMPLESIZE;
  85. chip->capture_sample_rate = DEFSAMPLERATE;
  86. chip->capture_channels = DEFCHANNELS;
  87. }
  88. static void snd_msnd_eval_dsp_msg(struct snd_msnd *chip, u16 wMessage)
  89. {
  90. switch (HIBYTE(wMessage)) {
  91. case HIMT_PLAY_DONE: {
  92. if (chip->banksPlayed < 3)
  93. snd_printdd("%08X: HIMT_PLAY_DONE: %i\n",
  94. (unsigned)jiffies, LOBYTE(wMessage));
  95. if (chip->last_playbank == LOBYTE(wMessage)) {
  96. snd_printdd("chip.last_playbank == LOBYTE(wMessage)\n");
  97. break;
  98. }
  99. chip->banksPlayed++;
  100. if (test_bit(F_WRITING, &chip->flags))
  101. snd_msnd_DAPQ(chip, 0);
  102. chip->last_playbank = LOBYTE(wMessage);
  103. chip->playDMAPos += chip->play_period_bytes;
  104. if (chip->playDMAPos > chip->playLimit)
  105. chip->playDMAPos = 0;
  106. snd_pcm_period_elapsed(chip->playback_substream);
  107. break;
  108. }
  109. case HIMT_RECORD_DONE:
  110. if (chip->last_recbank == LOBYTE(wMessage))
  111. break;
  112. chip->last_recbank = LOBYTE(wMessage);
  113. chip->captureDMAPos += chip->capturePeriodBytes;
  114. if (chip->captureDMAPos > (chip->captureLimit))
  115. chip->captureDMAPos = 0;
  116. if (test_bit(F_READING, &chip->flags))
  117. snd_msnd_DARQ(chip, chip->last_recbank);
  118. snd_pcm_period_elapsed(chip->capture_substream);
  119. break;
  120. case HIMT_DSP:
  121. switch (LOBYTE(wMessage)) {
  122. #ifndef MSND_CLASSIC
  123. case HIDSP_PLAY_UNDER:
  124. #endif
  125. case HIDSP_INT_PLAY_UNDER:
  126. snd_printd(KERN_WARNING LOGNAME ": Play underflow %i\n",
  127. chip->banksPlayed);
  128. if (chip->banksPlayed > 2)
  129. clear_bit(F_WRITING, &chip->flags);
  130. break;
  131. case HIDSP_INT_RECORD_OVER:
  132. snd_printd(KERN_WARNING LOGNAME ": Record overflow\n");
  133. clear_bit(F_READING, &chip->flags);
  134. break;
  135. default:
  136. snd_printd(KERN_WARNING LOGNAME
  137. ": DSP message %d 0x%02x\n",
  138. LOBYTE(wMessage), LOBYTE(wMessage));
  139. break;
  140. }
  141. break;
  142. case HIMT_MIDI_IN_UCHAR:
  143. if (chip->msndmidi_mpu)
  144. snd_msndmidi_input_read(chip->msndmidi_mpu);
  145. break;
  146. default:
  147. snd_printd(KERN_WARNING LOGNAME ": HIMT message %d 0x%02x\n",
  148. HIBYTE(wMessage), HIBYTE(wMessage));
  149. break;
  150. }
  151. }
  152. static irqreturn_t snd_msnd_interrupt(int irq, void *dev_id)
  153. {
  154. struct snd_msnd *chip = dev_id;
  155. void *pwDSPQData = chip->mappedbase + DSPQ_DATA_BUFF;
  156. 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 __devinit 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 __devinit 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 __devinit 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, NULL);
  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. if (chip->mappedbase)
  551. iounmap(chip->mappedbase);
  552. release_mem_region(chip->base, BUFFSIZE);
  553. release_region(chip->io, DSP_NUMIO);
  554. free_irq(chip->irq, chip);
  555. return err;
  556. }
  557. static void __devexit snd_msnd_unload(struct snd_card *card)
  558. {
  559. struct snd_msnd *chip = card->private_data;
  560. iounmap(chip->mappedbase);
  561. release_mem_region(chip->base, BUFFSIZE);
  562. release_region(chip->io, DSP_NUMIO);
  563. free_irq(chip->irq, chip);
  564. snd_card_free(card);
  565. }
  566. #ifndef MSND_CLASSIC
  567. /* Pinnacle/Fiji Logical Device Configuration */
  568. static int __devinit snd_msnd_write_cfg(int cfg, int reg, int value)
  569. {
  570. outb(reg, cfg);
  571. outb(value, cfg + 1);
  572. if (value != inb(cfg + 1)) {
  573. printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
  574. return -EIO;
  575. }
  576. return 0;
  577. }
  578. static int __devinit snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
  579. {
  580. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  581. return -EIO;
  582. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  583. return -EIO;
  584. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  585. return -EIO;
  586. return 0;
  587. }
  588. static int __devinit snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
  589. {
  590. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  591. return -EIO;
  592. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  593. return -EIO;
  594. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  595. return -EIO;
  596. return 0;
  597. }
  598. static int __devinit snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
  599. {
  600. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  601. return -EIO;
  602. if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  603. return -EIO;
  604. if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  605. return -EIO;
  606. return 0;
  607. }
  608. static int __devinit snd_msnd_write_cfg_mem(int cfg, int num, int mem)
  609. {
  610. u16 wmem;
  611. mem >>= 8;
  612. wmem = (u16)(mem & 0xfff);
  613. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  614. return -EIO;
  615. if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  616. return -EIO;
  617. if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  618. return -EIO;
  619. if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
  620. MEMTYPE_HIADDR | MEMTYPE_16BIT))
  621. return -EIO;
  622. return 0;
  623. }
  624. static int __devinit snd_msnd_activate_logical(int cfg, int num)
  625. {
  626. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  627. return -EIO;
  628. if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  629. return -EIO;
  630. return 0;
  631. }
  632. static int __devinit snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
  633. u16 io1, u16 irq, int mem)
  634. {
  635. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  636. return -EIO;
  637. if (snd_msnd_write_cfg_io0(cfg, num, io0))
  638. return -EIO;
  639. if (snd_msnd_write_cfg_io1(cfg, num, io1))
  640. return -EIO;
  641. if (snd_msnd_write_cfg_irq(cfg, num, irq))
  642. return -EIO;
  643. if (snd_msnd_write_cfg_mem(cfg, num, mem))
  644. return -EIO;
  645. if (snd_msnd_activate_logical(cfg, num))
  646. return -EIO;
  647. return 0;
  648. }
  649. static int __devinit snd_msnd_pinnacle_cfg_reset(int cfg)
  650. {
  651. int i;
  652. /* Reset devices if told to */
  653. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  654. for (i = 0; i < 4; ++i)
  655. if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  656. return -EIO;
  657. return 0;
  658. }
  659. #endif
  660. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  661. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  662. module_param_array(index, int, NULL, S_IRUGO);
  663. MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
  664. module_param_array(id, charp, NULL, S_IRUGO);
  665. MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
  666. static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  667. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  668. static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  669. #ifndef MSND_CLASSIC
  670. static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  671. /* Extra Peripheral Configuration (Default: Disable) */
  672. static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  673. static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  674. static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  675. static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  676. /* If we have the digital daugherboard... */
  677. static int digital[SNDRV_CARDS];
  678. /* Extra Peripheral Configuration */
  679. static int reset[SNDRV_CARDS];
  680. #endif
  681. static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
  682. static int calibrate_signal;
  683. #ifdef CONFIG_PNP
  684. static bool isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  685. module_param_array(isapnp, bool, NULL, 0444);
  686. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  687. #define has_isapnp(x) isapnp[x]
  688. #else
  689. #define has_isapnp(x) 0
  690. #endif
  691. MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
  692. MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
  693. MODULE_LICENSE("GPL");
  694. MODULE_FIRMWARE(INITCODEFILE);
  695. MODULE_FIRMWARE(PERMCODEFILE);
  696. module_param_array(io, long, NULL, S_IRUGO);
  697. MODULE_PARM_DESC(io, "IO port #");
  698. module_param_array(irq, int, NULL, S_IRUGO);
  699. module_param_array(mem, long, NULL, S_IRUGO);
  700. module_param_array(write_ndelay, int, NULL, S_IRUGO);
  701. module_param(calibrate_signal, int, S_IRUGO);
  702. #ifndef MSND_CLASSIC
  703. module_param_array(digital, int, NULL, S_IRUGO);
  704. module_param_array(cfg, long, NULL, S_IRUGO);
  705. module_param_array(reset, int, 0, S_IRUGO);
  706. module_param_array(mpu_io, long, NULL, S_IRUGO);
  707. module_param_array(mpu_irq, int, NULL, S_IRUGO);
  708. module_param_array(ide_io0, long, NULL, S_IRUGO);
  709. module_param_array(ide_io1, long, NULL, S_IRUGO);
  710. module_param_array(ide_irq, int, NULL, S_IRUGO);
  711. module_param_array(joystick_io, long, NULL, S_IRUGO);
  712. #endif
  713. static int __devinit snd_msnd_isa_match(struct device *pdev, unsigned int i)
  714. {
  715. if (io[i] == SNDRV_AUTO_PORT)
  716. return 0;
  717. if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
  718. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  719. return 0;
  720. }
  721. #ifdef MSND_CLASSIC
  722. if (!(io[i] == 0x290 ||
  723. io[i] == 0x260 ||
  724. io[i] == 0x250 ||
  725. io[i] == 0x240 ||
  726. io[i] == 0x230 ||
  727. io[i] == 0x220 ||
  728. io[i] == 0x210 ||
  729. io[i] == 0x3e0)) {
  730. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
  731. " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
  732. "or 0x3E0\n");
  733. return 0;
  734. }
  735. #else
  736. if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
  737. printk(KERN_ERR LOGNAME
  738. ": \"io\" - DSP I/O base must within the range 0x100 "
  739. "to 0x3E0 and must be evenly divisible by 0x10\n");
  740. return 0;
  741. }
  742. #endif /* MSND_CLASSIC */
  743. if (!(irq[i] == 5 ||
  744. irq[i] == 7 ||
  745. irq[i] == 9 ||
  746. irq[i] == 10 ||
  747. irq[i] == 11 ||
  748. irq[i] == 12)) {
  749. printk(KERN_ERR LOGNAME
  750. ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  751. return 0;
  752. }
  753. if (!(mem[i] == 0xb0000 ||
  754. mem[i] == 0xc8000 ||
  755. mem[i] == 0xd0000 ||
  756. mem[i] == 0xd8000 ||
  757. mem[i] == 0xe0000 ||
  758. mem[i] == 0xe8000)) {
  759. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  760. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
  761. "0xe8000\n");
  762. return 0;
  763. }
  764. #ifndef MSND_CLASSIC
  765. if (cfg[i] == SNDRV_AUTO_PORT) {
  766. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  767. } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
  768. printk(KERN_INFO LOGNAME
  769. ": Config port must be 0x250, 0x260 or 0x270 "
  770. "(or unspecified for PnP mode)\n");
  771. return 0;
  772. }
  773. #endif /* MSND_CLASSIC */
  774. return 1;
  775. }
  776. static int __devinit snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
  777. {
  778. int err;
  779. struct snd_card *card;
  780. struct snd_msnd *chip;
  781. if (has_isapnp(idx)
  782. #ifndef MSND_CLASSIC
  783. || cfg[idx] == SNDRV_AUTO_PORT
  784. #endif
  785. ) {
  786. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  787. return -ENODEV;
  788. }
  789. err = snd_card_create(index[idx], id[idx], THIS_MODULE,
  790. sizeof(struct snd_msnd), &card);
  791. if (err < 0)
  792. return err;
  793. snd_card_set_dev(card, pdev);
  794. chip = card->private_data;
  795. chip->card = card;
  796. #ifdef MSND_CLASSIC
  797. switch (irq[idx]) {
  798. case 5:
  799. chip->irqid = HPIRQ_5; break;
  800. case 7:
  801. chip->irqid = HPIRQ_7; break;
  802. case 9:
  803. chip->irqid = HPIRQ_9; break;
  804. case 10:
  805. chip->irqid = HPIRQ_10; break;
  806. case 11:
  807. chip->irqid = HPIRQ_11; break;
  808. case 12:
  809. chip->irqid = HPIRQ_12; break;
  810. }
  811. switch (mem[idx]) {
  812. case 0xb0000:
  813. chip->memid = HPMEM_B000; break;
  814. case 0xc8000:
  815. chip->memid = HPMEM_C800; break;
  816. case 0xd0000:
  817. chip->memid = HPMEM_D000; break;
  818. case 0xd8000:
  819. chip->memid = HPMEM_D800; break;
  820. case 0xe0000:
  821. chip->memid = HPMEM_E000; break;
  822. case 0xe8000:
  823. chip->memid = HPMEM_E800; break;
  824. }
  825. #else
  826. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
  827. cfg[idx]);
  828. if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
  829. printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
  830. cfg[idx]);
  831. snd_card_free(card);
  832. return -EIO;
  833. }
  834. if (reset[idx])
  835. if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
  836. err = -EIO;
  837. goto cfg_error;
  838. }
  839. /* DSP */
  840. err = snd_msnd_write_cfg_logical(cfg[idx], 0,
  841. io[idx], 0,
  842. irq[idx], mem[idx]);
  843. if (err)
  844. goto cfg_error;
  845. /* The following are Pinnacle specific */
  846. /* MPU */
  847. if (mpu_io[idx] != SNDRV_AUTO_PORT
  848. && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
  849. printk(KERN_INFO LOGNAME
  850. ": Configuring MPU to I/O 0x%lx IRQ %d\n",
  851. mpu_io[idx], mpu_irq[idx]);
  852. err = snd_msnd_write_cfg_logical(cfg[idx], 1,
  853. mpu_io[idx], 0,
  854. mpu_irq[idx], 0);
  855. if (err)
  856. goto cfg_error;
  857. }
  858. /* IDE */
  859. if (ide_io0[idx] != SNDRV_AUTO_PORT
  860. && ide_io1[idx] != SNDRV_AUTO_PORT
  861. && ide_irq[idx] != SNDRV_AUTO_IRQ) {
  862. printk(KERN_INFO LOGNAME
  863. ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
  864. ide_io0[idx], ide_io1[idx], ide_irq[idx]);
  865. err = snd_msnd_write_cfg_logical(cfg[idx], 2,
  866. ide_io0[idx], ide_io1[idx],
  867. ide_irq[idx], 0);
  868. if (err)
  869. goto cfg_error;
  870. }
  871. /* Joystick */
  872. if (joystick_io[idx] != SNDRV_AUTO_PORT) {
  873. printk(KERN_INFO LOGNAME
  874. ": Configuring joystick to I/O 0x%lx\n",
  875. joystick_io[idx]);
  876. err = snd_msnd_write_cfg_logical(cfg[idx], 3,
  877. joystick_io[idx], 0,
  878. 0, 0);
  879. if (err)
  880. goto cfg_error;
  881. }
  882. release_region(cfg[idx], 2);
  883. #endif /* MSND_CLASSIC */
  884. set_default_audio_parameters(chip);
  885. #ifdef MSND_CLASSIC
  886. chip->type = msndClassic;
  887. #else
  888. chip->type = msndPinnacle;
  889. #endif
  890. chip->io = io[idx];
  891. chip->irq = irq[idx];
  892. chip->base = mem[idx];
  893. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  894. chip->recsrc = 0;
  895. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  896. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  897. if (write_ndelay[idx])
  898. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  899. else
  900. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  901. #ifndef MSND_CLASSIC
  902. if (digital[idx])
  903. set_bit(F_HAVEDIGITAL, &chip->flags);
  904. #endif
  905. spin_lock_init(&chip->lock);
  906. err = snd_msnd_probe(card);
  907. if (err < 0) {
  908. printk(KERN_ERR LOGNAME ": Probe failed\n");
  909. snd_card_free(card);
  910. return err;
  911. }
  912. err = snd_msnd_attach(card);
  913. if (err < 0) {
  914. printk(KERN_ERR LOGNAME ": Attach failed\n");
  915. snd_card_free(card);
  916. return err;
  917. }
  918. dev_set_drvdata(pdev, card);
  919. return 0;
  920. #ifndef MSND_CLASSIC
  921. cfg_error:
  922. release_region(cfg[idx], 2);
  923. snd_card_free(card);
  924. return err;
  925. #endif
  926. }
  927. static int __devexit snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
  928. {
  929. snd_msnd_unload(dev_get_drvdata(pdev));
  930. dev_set_drvdata(pdev, NULL);
  931. return 0;
  932. }
  933. static struct isa_driver snd_msnd_driver = {
  934. .match = snd_msnd_isa_match,
  935. .probe = snd_msnd_isa_probe,
  936. .remove = __devexit_p(snd_msnd_isa_remove),
  937. /* FIXME: suspend, resume */
  938. .driver = {
  939. .name = DEV_NAME
  940. },
  941. };
  942. #ifdef CONFIG_PNP
  943. static int __devinit snd_msnd_pnp_detect(struct pnp_card_link *pcard,
  944. const struct pnp_card_device_id *pid)
  945. {
  946. static int idx;
  947. struct pnp_dev *pnp_dev;
  948. struct pnp_dev *mpu_dev;
  949. struct snd_card *card;
  950. struct snd_msnd *chip;
  951. int ret;
  952. for ( ; idx < SNDRV_CARDS; idx++) {
  953. if (has_isapnp(idx))
  954. break;
  955. }
  956. if (idx >= SNDRV_CARDS)
  957. return -ENODEV;
  958. /*
  959. * Check that we still have room for another sound card ...
  960. */
  961. pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  962. if (!pnp_dev)
  963. return -ENODEV;
  964. mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
  965. if (!mpu_dev)
  966. return -ENODEV;
  967. if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
  968. printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
  969. return -EBUSY;
  970. }
  971. if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
  972. printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
  973. return -EBUSY;
  974. }
  975. /*
  976. * Create a new ALSA sound card entry, in anticipation
  977. * of detecting our hardware ...
  978. */
  979. ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
  980. sizeof(struct snd_msnd), &card);
  981. if (ret < 0)
  982. return ret;
  983. chip = card->private_data;
  984. chip->card = card;
  985. snd_card_set_dev(card, &pcard->card->dev);
  986. /*
  987. * Read the correct parameters off the ISA PnP bus ...
  988. */
  989. io[idx] = pnp_port_start(pnp_dev, 0);
  990. irq[idx] = pnp_irq(pnp_dev, 0);
  991. mem[idx] = pnp_mem_start(pnp_dev, 0);
  992. mpu_io[idx] = pnp_port_start(mpu_dev, 0);
  993. mpu_irq[idx] = pnp_irq(mpu_dev, 0);
  994. set_default_audio_parameters(chip);
  995. #ifdef MSND_CLASSIC
  996. chip->type = msndClassic;
  997. #else
  998. chip->type = msndPinnacle;
  999. #endif
  1000. chip->io = io[idx];
  1001. chip->irq = irq[idx];
  1002. chip->base = mem[idx];
  1003. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  1004. chip->recsrc = 0;
  1005. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  1006. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  1007. if (write_ndelay[idx])
  1008. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1009. else
  1010. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1011. #ifndef MSND_CLASSIC
  1012. if (digital[idx])
  1013. set_bit(F_HAVEDIGITAL, &chip->flags);
  1014. #endif
  1015. spin_lock_init(&chip->lock);
  1016. ret = snd_msnd_probe(card);
  1017. if (ret < 0) {
  1018. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1019. goto _release_card;
  1020. }
  1021. ret = snd_msnd_attach(card);
  1022. if (ret < 0) {
  1023. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1024. goto _release_card;
  1025. }
  1026. pnp_set_card_drvdata(pcard, card);
  1027. ++idx;
  1028. return 0;
  1029. _release_card:
  1030. snd_card_free(card);
  1031. return ret;
  1032. }
  1033. static void __devexit snd_msnd_pnp_remove(struct pnp_card_link *pcard)
  1034. {
  1035. snd_msnd_unload(pnp_get_card_drvdata(pcard));
  1036. pnp_set_card_drvdata(pcard, NULL);
  1037. }
  1038. static int isa_registered;
  1039. static int pnp_registered;
  1040. static struct pnp_card_device_id msnd_pnpids[] = {
  1041. /* Pinnacle PnP */
  1042. { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
  1043. { .id = "" } /* end */
  1044. };
  1045. MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
  1046. static struct pnp_card_driver msnd_pnpc_driver = {
  1047. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1048. .name = "msnd_pinnacle",
  1049. .id_table = msnd_pnpids,
  1050. .probe = snd_msnd_pnp_detect,
  1051. .remove = __devexit_p(snd_msnd_pnp_remove),
  1052. };
  1053. #endif /* CONFIG_PNP */
  1054. static int __init snd_msnd_init(void)
  1055. {
  1056. int err;
  1057. err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
  1058. #ifdef CONFIG_PNP
  1059. if (!err)
  1060. isa_registered = 1;
  1061. err = pnp_register_card_driver(&msnd_pnpc_driver);
  1062. if (!err)
  1063. pnp_registered = 1;
  1064. if (isa_registered)
  1065. err = 0;
  1066. #endif
  1067. return err;
  1068. }
  1069. static void __exit snd_msnd_exit(void)
  1070. {
  1071. #ifdef CONFIG_PNP
  1072. if (pnp_registered)
  1073. pnp_unregister_card_driver(&msnd_pnpc_driver);
  1074. if (isa_registered)
  1075. #endif
  1076. isa_unregister_driver(&snd_msnd_driver);
  1077. }
  1078. module_init(snd_msnd_init);
  1079. module_exit(snd_msnd_exit);