msnd_pinnacle.c 30 KB

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