msnd_pinnacle.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245
  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. if (request_region(chip->io, DSP_NUMIO, card->shortname) == NULL) {
  483. free_irq(chip->irq, chip);
  484. return -EBUSY;
  485. }
  486. if (!request_mem_region(chip->base, BUFFSIZE, card->shortname)) {
  487. printk(KERN_ERR LOGNAME
  488. ": unable to grab memory region 0x%lx-0x%lx\n",
  489. chip->base, chip->base + BUFFSIZE - 1);
  490. release_region(chip->io, DSP_NUMIO);
  491. free_irq(chip->irq, chip);
  492. return -EBUSY;
  493. }
  494. chip->mappedbase = ioremap_nocache(chip->base, 0x8000);
  495. if (!chip->mappedbase) {
  496. printk(KERN_ERR LOGNAME
  497. ": unable to map memory region 0x%lx-0x%lx\n",
  498. chip->base, chip->base + BUFFSIZE - 1);
  499. err = -EIO;
  500. goto err_release_region;
  501. }
  502. err = snd_msnd_dsp_full_reset(card);
  503. if (err < 0)
  504. goto err_release_region;
  505. /* Register device */
  506. err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
  507. if (err < 0)
  508. goto err_release_region;
  509. err = snd_msnd_pcm(card, 0, NULL);
  510. if (err < 0) {
  511. printk(KERN_ERR LOGNAME ": error creating new PCM device\n");
  512. goto err_release_region;
  513. }
  514. err = snd_msndmix_new(card);
  515. if (err < 0) {
  516. printk(KERN_ERR LOGNAME ": error creating new Mixer device\n");
  517. goto err_release_region;
  518. }
  519. if (mpu_io[0] != SNDRV_AUTO_PORT) {
  520. struct snd_mpu401 *mpu;
  521. err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
  522. mpu_io[0],
  523. MPU401_MODE_INPUT |
  524. MPU401_MODE_OUTPUT,
  525. mpu_irq[0], IRQF_DISABLED,
  526. &chip->rmidi);
  527. if (err < 0) {
  528. printk(KERN_ERR LOGNAME
  529. ": error creating new Midi device\n");
  530. goto err_release_region;
  531. }
  532. mpu = chip->rmidi->private_data;
  533. mpu->open_input = snd_msnd_mpu401_open;
  534. mpu->close_input = snd_msnd_mpu401_close;
  535. mpu->private_data = chip;
  536. }
  537. disable_irq(chip->irq);
  538. snd_msnd_calibrate_adc(chip, chip->play_sample_rate);
  539. snd_msndmix_force_recsrc(chip, 0);
  540. err = snd_card_register(card);
  541. if (err < 0)
  542. goto err_release_region;
  543. return 0;
  544. err_release_region:
  545. if (chip->mappedbase)
  546. iounmap(chip->mappedbase);
  547. release_mem_region(chip->base, BUFFSIZE);
  548. release_region(chip->io, DSP_NUMIO);
  549. free_irq(chip->irq, chip);
  550. return err;
  551. }
  552. static void __devexit snd_msnd_unload(struct snd_card *card)
  553. {
  554. struct snd_msnd *chip = card->private_data;
  555. iounmap(chip->mappedbase);
  556. release_mem_region(chip->base, BUFFSIZE);
  557. release_region(chip->io, DSP_NUMIO);
  558. free_irq(chip->irq, chip);
  559. snd_card_free(card);
  560. }
  561. #ifndef MSND_CLASSIC
  562. /* Pinnacle/Fiji Logical Device Configuration */
  563. static int __devinit snd_msnd_write_cfg(int cfg, int reg, int value)
  564. {
  565. outb(reg, cfg);
  566. outb(value, cfg + 1);
  567. if (value != inb(cfg + 1)) {
  568. printk(KERN_ERR LOGNAME ": snd_msnd_write_cfg: I/O error\n");
  569. return -EIO;
  570. }
  571. return 0;
  572. }
  573. static int __devinit snd_msnd_write_cfg_io0(int cfg, int num, u16 io)
  574. {
  575. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  576. return -EIO;
  577. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  578. return -EIO;
  579. if (snd_msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  580. return -EIO;
  581. return 0;
  582. }
  583. static int __devinit snd_msnd_write_cfg_io1(int cfg, int num, u16 io)
  584. {
  585. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  586. return -EIO;
  587. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  588. return -EIO;
  589. if (snd_msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  590. return -EIO;
  591. return 0;
  592. }
  593. static int __devinit snd_msnd_write_cfg_irq(int cfg, int num, u16 irq)
  594. {
  595. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  596. return -EIO;
  597. if (snd_msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  598. return -EIO;
  599. if (snd_msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  600. return -EIO;
  601. return 0;
  602. }
  603. static int __devinit snd_msnd_write_cfg_mem(int cfg, int num, int mem)
  604. {
  605. u16 wmem;
  606. mem >>= 8;
  607. wmem = (u16)(mem & 0xfff);
  608. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  609. return -EIO;
  610. if (snd_msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  611. return -EIO;
  612. if (snd_msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  613. return -EIO;
  614. if (wmem && snd_msnd_write_cfg(cfg, IREG_MEMCONTROL,
  615. MEMTYPE_HIADDR | MEMTYPE_16BIT))
  616. return -EIO;
  617. return 0;
  618. }
  619. static int __devinit snd_msnd_activate_logical(int cfg, int num)
  620. {
  621. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  622. return -EIO;
  623. if (snd_msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  624. return -EIO;
  625. return 0;
  626. }
  627. static int __devinit snd_msnd_write_cfg_logical(int cfg, int num, u16 io0,
  628. u16 io1, u16 irq, int mem)
  629. {
  630. if (snd_msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  631. return -EIO;
  632. if (snd_msnd_write_cfg_io0(cfg, num, io0))
  633. return -EIO;
  634. if (snd_msnd_write_cfg_io1(cfg, num, io1))
  635. return -EIO;
  636. if (snd_msnd_write_cfg_irq(cfg, num, irq))
  637. return -EIO;
  638. if (snd_msnd_write_cfg_mem(cfg, num, mem))
  639. return -EIO;
  640. if (snd_msnd_activate_logical(cfg, num))
  641. return -EIO;
  642. return 0;
  643. }
  644. static int __devinit snd_msnd_pinnacle_cfg_reset(int cfg)
  645. {
  646. int i;
  647. /* Reset devices if told to */
  648. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  649. for (i = 0; i < 4; ++i)
  650. if (snd_msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  651. return -EIO;
  652. return 0;
  653. }
  654. #endif
  655. static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
  656. static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
  657. module_param_array(index, int, NULL, S_IRUGO);
  658. MODULE_PARM_DESC(index, "Index value for msnd_pinnacle soundcard.");
  659. module_param_array(id, charp, NULL, S_IRUGO);
  660. MODULE_PARM_DESC(id, "ID string for msnd_pinnacle soundcard.");
  661. static long io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  662. static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  663. static long mem[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  664. #ifndef MSND_CLASSIC
  665. static long cfg[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  666. /* Extra Peripheral Configuration (Default: Disable) */
  667. static long ide_io0[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  668. static long ide_io1[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  669. static int ide_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;
  670. static long joystick_io[SNDRV_CARDS] = SNDRV_DEFAULT_PORT;
  671. /* If we have the digital daugherboard... */
  672. static int digital[SNDRV_CARDS];
  673. /* Extra Peripheral Configuration */
  674. static int reset[SNDRV_CARDS];
  675. #endif
  676. static int write_ndelay[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 1 };
  677. static int calibrate_signal;
  678. #ifdef CONFIG_PNP
  679. static int isapnp[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
  680. module_param_array(isapnp, bool, NULL, 0444);
  681. MODULE_PARM_DESC(isapnp, "ISA PnP detection for specified soundcard.");
  682. #define has_isapnp(x) isapnp[x]
  683. #else
  684. #define has_isapnp(x) 0
  685. #endif
  686. MODULE_AUTHOR("Karsten Wiese <annabellesgarden@yahoo.de>");
  687. MODULE_DESCRIPTION("Turtle Beach " LONGNAME " Linux Driver");
  688. MODULE_LICENSE("GPL");
  689. MODULE_FIRMWARE(INITCODEFILE);
  690. MODULE_FIRMWARE(PERMCODEFILE);
  691. module_param_array(io, long, NULL, S_IRUGO);
  692. MODULE_PARM_DESC(io, "IO port #");
  693. module_param_array(irq, int, NULL, S_IRUGO);
  694. module_param_array(mem, long, NULL, S_IRUGO);
  695. module_param_array(write_ndelay, int, NULL, S_IRUGO);
  696. module_param(calibrate_signal, int, S_IRUGO);
  697. #ifndef MSND_CLASSIC
  698. module_param_array(digital, int, NULL, S_IRUGO);
  699. module_param_array(cfg, long, NULL, S_IRUGO);
  700. module_param_array(reset, int, 0, S_IRUGO);
  701. module_param_array(mpu_io, long, NULL, S_IRUGO);
  702. module_param_array(mpu_irq, int, NULL, S_IRUGO);
  703. module_param_array(ide_io0, long, NULL, S_IRUGO);
  704. module_param_array(ide_io1, long, NULL, S_IRUGO);
  705. module_param_array(ide_irq, int, NULL, S_IRUGO);
  706. module_param_array(joystick_io, long, NULL, S_IRUGO);
  707. #endif
  708. static int __devinit snd_msnd_isa_match(struct device *pdev, unsigned int i)
  709. {
  710. if (io[i] == SNDRV_AUTO_PORT)
  711. return 0;
  712. if (irq[i] == SNDRV_AUTO_PORT || mem[i] == SNDRV_AUTO_PORT) {
  713. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  714. return 0;
  715. }
  716. #ifdef MSND_CLASSIC
  717. if (!(io[i] == 0x290 ||
  718. io[i] == 0x260 ||
  719. io[i] == 0x250 ||
  720. io[i] == 0x240 ||
  721. io[i] == 0x230 ||
  722. io[i] == 0x220 ||
  723. io[i] == 0x210 ||
  724. io[i] == 0x3e0)) {
  725. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set "
  726. " to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, "
  727. "or 0x3E0\n");
  728. return 0;
  729. }
  730. #else
  731. if (io[i] < 0x100 || io[i] > 0x3e0 || (io[i] % 0x10) != 0) {
  732. printk(KERN_ERR LOGNAME
  733. ": \"io\" - DSP I/O base must within the range 0x100 "
  734. "to 0x3E0 and must be evenly divisible by 0x10\n");
  735. return 0;
  736. }
  737. #endif /* MSND_CLASSIC */
  738. if (!(irq[i] == 5 ||
  739. irq[i] == 7 ||
  740. irq[i] == 9 ||
  741. irq[i] == 10 ||
  742. irq[i] == 11 ||
  743. irq[i] == 12)) {
  744. printk(KERN_ERR LOGNAME
  745. ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  746. return 0;
  747. }
  748. if (!(mem[i] == 0xb0000 ||
  749. mem[i] == 0xc8000 ||
  750. mem[i] == 0xd0000 ||
  751. mem[i] == 0xd8000 ||
  752. mem[i] == 0xe0000 ||
  753. mem[i] == 0xe8000)) {
  754. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  755. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or "
  756. "0xe8000\n");
  757. return 0;
  758. }
  759. #ifndef MSND_CLASSIC
  760. if (cfg[i] == SNDRV_AUTO_PORT) {
  761. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  762. } else if (cfg[i] != 0x250 && cfg[i] != 0x260 && cfg[i] != 0x270) {
  763. printk(KERN_INFO LOGNAME
  764. ": Config port must be 0x250, 0x260 or 0x270 "
  765. "(or unspecified for PnP mode)\n");
  766. return 0;
  767. }
  768. #endif /* MSND_CLASSIC */
  769. return 1;
  770. }
  771. static int __devinit snd_msnd_isa_probe(struct device *pdev, unsigned int idx)
  772. {
  773. int err;
  774. struct snd_card *card;
  775. struct snd_msnd *chip;
  776. if (has_isapnp(idx)
  777. #ifndef MSND_CLASSIC
  778. || cfg[idx] == SNDRV_AUTO_PORT
  779. #endif
  780. ) {
  781. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  782. return -ENODEV;
  783. }
  784. err = snd_card_create(index[idx], id[idx], THIS_MODULE,
  785. sizeof(struct snd_msnd), &card);
  786. if (err < 0)
  787. return err;
  788. snd_card_set_dev(card, pdev);
  789. chip = card->private_data;
  790. chip->card = card;
  791. #ifdef MSND_CLASSIC
  792. switch (irq[idx]) {
  793. case 5:
  794. chip->irqid = HPIRQ_5; break;
  795. case 7:
  796. chip->irqid = HPIRQ_7; break;
  797. case 9:
  798. chip->irqid = HPIRQ_9; break;
  799. case 10:
  800. chip->irqid = HPIRQ_10; break;
  801. case 11:
  802. chip->irqid = HPIRQ_11; break;
  803. case 12:
  804. chip->irqid = HPIRQ_12; break;
  805. }
  806. switch (mem[idx]) {
  807. case 0xb0000:
  808. chip->memid = HPMEM_B000; break;
  809. case 0xc8000:
  810. chip->memid = HPMEM_C800; break;
  811. case 0xd0000:
  812. chip->memid = HPMEM_D000; break;
  813. case 0xd8000:
  814. chip->memid = HPMEM_D800; break;
  815. case 0xe0000:
  816. chip->memid = HPMEM_E000; break;
  817. case 0xe8000:
  818. chip->memid = HPMEM_E800; break;
  819. }
  820. #else
  821. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%lx\n",
  822. cfg[idx]);
  823. if (!request_region(cfg[idx], 2, "Pinnacle/Fiji Config")) {
  824. printk(KERN_ERR LOGNAME ": Config port 0x%lx conflict\n",
  825. cfg[idx]);
  826. snd_card_free(card);
  827. return -EIO;
  828. }
  829. if (reset[idx])
  830. if (snd_msnd_pinnacle_cfg_reset(cfg[idx])) {
  831. err = -EIO;
  832. goto cfg_error;
  833. }
  834. /* DSP */
  835. err = snd_msnd_write_cfg_logical(cfg[idx], 0,
  836. io[idx], 0,
  837. irq[idx], mem[idx]);
  838. if (err)
  839. goto cfg_error;
  840. /* The following are Pinnacle specific */
  841. /* MPU */
  842. if (mpu_io[idx] != SNDRV_AUTO_PORT
  843. && mpu_irq[idx] != SNDRV_AUTO_IRQ) {
  844. printk(KERN_INFO LOGNAME
  845. ": Configuring MPU to I/O 0x%lx IRQ %d\n",
  846. mpu_io[idx], mpu_irq[idx]);
  847. err = snd_msnd_write_cfg_logical(cfg[idx], 1,
  848. mpu_io[idx], 0,
  849. mpu_irq[idx], 0);
  850. if (err)
  851. goto cfg_error;
  852. }
  853. /* IDE */
  854. if (ide_io0[idx] != SNDRV_AUTO_PORT
  855. && ide_io1[idx] != SNDRV_AUTO_PORT
  856. && ide_irq[idx] != SNDRV_AUTO_IRQ) {
  857. printk(KERN_INFO LOGNAME
  858. ": Configuring IDE to I/O 0x%lx, 0x%lx IRQ %d\n",
  859. ide_io0[idx], ide_io1[idx], ide_irq[idx]);
  860. err = snd_msnd_write_cfg_logical(cfg[idx], 2,
  861. ide_io0[idx], ide_io1[idx],
  862. ide_irq[idx], 0);
  863. if (err)
  864. goto cfg_error;
  865. }
  866. /* Joystick */
  867. if (joystick_io[idx] != SNDRV_AUTO_PORT) {
  868. printk(KERN_INFO LOGNAME
  869. ": Configuring joystick to I/O 0x%lx\n",
  870. joystick_io[idx]);
  871. err = snd_msnd_write_cfg_logical(cfg[idx], 3,
  872. joystick_io[idx], 0,
  873. 0, 0);
  874. if (err)
  875. goto cfg_error;
  876. }
  877. release_region(cfg[idx], 2);
  878. #endif /* MSND_CLASSIC */
  879. set_default_audio_parameters(chip);
  880. #ifdef MSND_CLASSIC
  881. chip->type = msndClassic;
  882. #else
  883. chip->type = msndPinnacle;
  884. #endif
  885. chip->io = io[idx];
  886. chip->irq = irq[idx];
  887. chip->base = mem[idx];
  888. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  889. chip->recsrc = 0;
  890. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  891. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  892. if (write_ndelay[idx])
  893. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  894. else
  895. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  896. #ifndef MSND_CLASSIC
  897. if (digital[idx])
  898. set_bit(F_HAVEDIGITAL, &chip->flags);
  899. #endif
  900. spin_lock_init(&chip->lock);
  901. err = snd_msnd_probe(card);
  902. if (err < 0) {
  903. printk(KERN_ERR LOGNAME ": Probe failed\n");
  904. snd_card_free(card);
  905. return err;
  906. }
  907. err = snd_msnd_attach(card);
  908. if (err < 0) {
  909. printk(KERN_ERR LOGNAME ": Attach failed\n");
  910. snd_card_free(card);
  911. return err;
  912. }
  913. dev_set_drvdata(pdev, card);
  914. return 0;
  915. #ifndef MSND_CLASSIC
  916. cfg_error:
  917. release_region(cfg[idx], 2);
  918. snd_card_free(card);
  919. return err;
  920. #endif
  921. }
  922. static int __devexit snd_msnd_isa_remove(struct device *pdev, unsigned int dev)
  923. {
  924. snd_msnd_unload(dev_get_drvdata(pdev));
  925. dev_set_drvdata(pdev, NULL);
  926. return 0;
  927. }
  928. #define DEV_NAME "msnd-pinnacle"
  929. static struct isa_driver snd_msnd_driver = {
  930. .match = snd_msnd_isa_match,
  931. .probe = snd_msnd_isa_probe,
  932. .remove = __devexit_p(snd_msnd_isa_remove),
  933. /* FIXME: suspend, resume */
  934. .driver = {
  935. .name = DEV_NAME
  936. },
  937. };
  938. #ifdef CONFIG_PNP
  939. static int __devinit snd_msnd_pnp_detect(struct pnp_card_link *pcard,
  940. const struct pnp_card_device_id *pid)
  941. {
  942. static int idx;
  943. struct pnp_dev *pnp_dev;
  944. struct pnp_dev *mpu_dev;
  945. struct snd_card *card;
  946. struct snd_msnd *chip;
  947. int ret;
  948. for ( ; idx < SNDRV_CARDS; idx++) {
  949. if (has_isapnp(idx))
  950. break;
  951. }
  952. if (idx >= SNDRV_CARDS)
  953. return -ENODEV;
  954. /*
  955. * Check that we still have room for another sound card ...
  956. */
  957. pnp_dev = pnp_request_card_device(pcard, pid->devs[0].id, NULL);
  958. if (!pnp_dev)
  959. return -ENODEV;
  960. mpu_dev = pnp_request_card_device(pcard, pid->devs[1].id, NULL);
  961. if (!mpu_dev)
  962. return -ENODEV;
  963. if (!pnp_is_active(pnp_dev) && pnp_activate_dev(pnp_dev) < 0) {
  964. printk(KERN_INFO "msnd_pinnacle: device is inactive\n");
  965. return -EBUSY;
  966. }
  967. if (!pnp_is_active(mpu_dev) && pnp_activate_dev(mpu_dev) < 0) {
  968. printk(KERN_INFO "msnd_pinnacle: MPU device is inactive\n");
  969. return -EBUSY;
  970. }
  971. /*
  972. * Create a new ALSA sound card entry, in anticipation
  973. * of detecting our hardware ...
  974. */
  975. ret = snd_card_create(index[idx], id[idx], THIS_MODULE,
  976. sizeof(struct snd_msnd), &card);
  977. if (ret < 0)
  978. return ret;
  979. chip = card->private_data;
  980. chip->card = card;
  981. snd_card_set_dev(card, &pcard->card->dev);
  982. /*
  983. * Read the correct parameters off the ISA PnP bus ...
  984. */
  985. io[idx] = pnp_port_start(pnp_dev, 0);
  986. irq[idx] = pnp_irq(pnp_dev, 0);
  987. mem[idx] = pnp_mem_start(pnp_dev, 0);
  988. mpu_io[idx] = pnp_port_start(mpu_dev, 0);
  989. mpu_irq[idx] = pnp_irq(mpu_dev, 0);
  990. set_default_audio_parameters(chip);
  991. #ifdef MSND_CLASSIC
  992. chip->type = msndClassic;
  993. #else
  994. chip->type = msndPinnacle;
  995. #endif
  996. chip->io = io[idx];
  997. chip->irq = irq[idx];
  998. chip->base = mem[idx];
  999. chip->calibrate_signal = calibrate_signal ? 1 : 0;
  1000. chip->recsrc = 0;
  1001. chip->dspq_data_buff = DSPQ_DATA_BUFF;
  1002. chip->dspq_buff_size = DSPQ_BUFF_SIZE;
  1003. if (write_ndelay[idx])
  1004. clear_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1005. else
  1006. set_bit(F_DISABLE_WRITE_NDELAY, &chip->flags);
  1007. #ifndef MSND_CLASSIC
  1008. if (digital[idx])
  1009. set_bit(F_HAVEDIGITAL, &chip->flags);
  1010. #endif
  1011. spin_lock_init(&chip->lock);
  1012. ret = snd_msnd_probe(card);
  1013. if (ret < 0) {
  1014. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1015. goto _release_card;
  1016. }
  1017. ret = snd_msnd_attach(card);
  1018. if (ret < 0) {
  1019. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1020. goto _release_card;
  1021. }
  1022. pnp_set_card_drvdata(pcard, card);
  1023. ++idx;
  1024. return 0;
  1025. _release_card:
  1026. snd_card_free(card);
  1027. return ret;
  1028. }
  1029. static void __devexit snd_msnd_pnp_remove(struct pnp_card_link *pcard)
  1030. {
  1031. snd_msnd_unload(pnp_get_card_drvdata(pcard));
  1032. pnp_set_card_drvdata(pcard, NULL);
  1033. }
  1034. static int isa_registered;
  1035. static int pnp_registered;
  1036. static struct pnp_card_device_id msnd_pnpids[] = {
  1037. /* Pinnacle PnP */
  1038. { .id = "BVJ0440", .devs = { { "TBS0000" }, { "TBS0001" } } },
  1039. { .id = "" } /* end */
  1040. };
  1041. MODULE_DEVICE_TABLE(pnp_card, msnd_pnpids);
  1042. static struct pnp_card_driver msnd_pnpc_driver = {
  1043. .flags = PNP_DRIVER_RES_DO_NOT_CHANGE,
  1044. .name = "msnd_pinnacle",
  1045. .id_table = msnd_pnpids,
  1046. .probe = snd_msnd_pnp_detect,
  1047. .remove = __devexit_p(snd_msnd_pnp_remove),
  1048. };
  1049. #endif /* CONFIG_PNP */
  1050. static int __init snd_msnd_init(void)
  1051. {
  1052. int err;
  1053. err = isa_register_driver(&snd_msnd_driver, SNDRV_CARDS);
  1054. #ifdef CONFIG_PNP
  1055. if (!err)
  1056. isa_registered = 1;
  1057. err = pnp_register_card_driver(&msnd_pnpc_driver);
  1058. if (!err)
  1059. pnp_registered = 1;
  1060. if (isa_registered)
  1061. err = 0;
  1062. #endif
  1063. return err;
  1064. }
  1065. static void __exit snd_msnd_exit(void)
  1066. {
  1067. #ifdef CONFIG_PNP
  1068. if (pnp_registered)
  1069. pnp_unregister_card_driver(&msnd_pnpc_driver);
  1070. if (isa_registered)
  1071. #endif
  1072. isa_unregister_driver(&snd_msnd_driver);
  1073. }
  1074. module_init(snd_msnd_init);
  1075. module_exit(snd_msnd_exit);