msnd_pinnacle.c 47 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940
  1. /*********************************************************************
  2. *
  3. * Turtle Beach MultiSound Sound Card Driver for Linux
  4. * Linux 2.0/2.2 Version
  5. *
  6. * msnd_pinnacle.c / msnd_classic.c
  7. *
  8. * -- If MSND_CLASSIC is defined:
  9. *
  10. * -> driver for Turtle Beach Classic/Monterey/Tahiti
  11. *
  12. * -- Else
  13. *
  14. * -> driver for Turtle Beach Pinnacle/Fiji
  15. *
  16. * Copyright (C) 1998 Andrew Veliath
  17. *
  18. * This program is free software; you can redistribute it and/or modify
  19. * it under the terms of the GNU General Public License as published by
  20. * the Free Software Foundation; either version 2 of the License, or
  21. * (at your option) any later version.
  22. *
  23. * This program is distributed in the hope that it will be useful,
  24. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  26. * GNU General Public License for more details.
  27. *
  28. * You should have received a copy of the GNU General Public License
  29. * along with this program; if not, write to the Free Software
  30. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  31. *
  32. * 12-3-2000 Modified IO port validation Steve Sycamore
  33. *
  34. ********************************************************************/
  35. #include <linux/kernel.h>
  36. #include <linux/module.h>
  37. #include <linux/types.h>
  38. #include <linux/delay.h>
  39. #include <linux/init.h>
  40. #include <linux/interrupt.h>
  41. #include <linux/mutex.h>
  42. #include <linux/gfp.h>
  43. #include <asm/irq.h>
  44. #include <asm/io.h>
  45. #include "sound_config.h"
  46. #include "sound_firmware.h"
  47. #ifdef MSND_CLASSIC
  48. # ifndef __alpha__
  49. # define SLOWIO
  50. # endif
  51. #endif
  52. #include "msnd.h"
  53. #ifdef MSND_CLASSIC
  54. # ifdef CONFIG_MSNDCLAS_HAVE_BOOT
  55. # define HAVE_DSPCODEH
  56. # endif
  57. # include "msnd_classic.h"
  58. # define LOGNAME "msnd_classic"
  59. #else
  60. # ifdef CONFIG_MSNDPIN_HAVE_BOOT
  61. # define HAVE_DSPCODEH
  62. # endif
  63. # include "msnd_pinnacle.h"
  64. # define LOGNAME "msnd_pinnacle"
  65. #endif
  66. #ifndef CONFIG_MSND_WRITE_NDELAY
  67. # define CONFIG_MSND_WRITE_NDELAY 1
  68. #endif
  69. #define get_play_delay_jiffies(size) ((size) * HZ * \
  70. dev.play_sample_size / 8 / \
  71. dev.play_sample_rate / \
  72. dev.play_channels)
  73. #define get_rec_delay_jiffies(size) ((size) * HZ * \
  74. dev.rec_sample_size / 8 / \
  75. dev.rec_sample_rate / \
  76. dev.rec_channels)
  77. static DEFINE_MUTEX(msnd_pinnacle_mutex);
  78. static multisound_dev_t dev;
  79. #ifndef HAVE_DSPCODEH
  80. static char *dspini, *permini;
  81. static int sizeof_dspini, sizeof_permini;
  82. #endif
  83. static int dsp_full_reset(void);
  84. static void dsp_write_flush(void);
  85. static __inline__ int chk_send_dsp_cmd(multisound_dev_t *dev, register BYTE cmd)
  86. {
  87. if (msnd_send_dsp_cmd(dev, cmd) == 0)
  88. return 0;
  89. dsp_full_reset();
  90. return msnd_send_dsp_cmd(dev, cmd);
  91. }
  92. static void reset_play_queue(void)
  93. {
  94. int n;
  95. LPDAQD lpDAQ;
  96. dev.last_playbank = -1;
  97. writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wHead);
  98. writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DAPQ + JQS_wTail);
  99. for (n = 0, lpDAQ = dev.base + DAPQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
  100. writew(PCTODSP_BASED((DWORD)(DAP_BUFF_SIZE * n)), lpDAQ + DAQDS_wStart);
  101. writew(0, lpDAQ + DAQDS_wSize);
  102. writew(1, lpDAQ + DAQDS_wFormat);
  103. writew(dev.play_sample_size, lpDAQ + DAQDS_wSampleSize);
  104. writew(dev.play_channels, lpDAQ + DAQDS_wChannels);
  105. writew(dev.play_sample_rate, lpDAQ + DAQDS_wSampleRate);
  106. writew(HIMT_PLAY_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
  107. writew(n, lpDAQ + DAQDS_wFlags);
  108. }
  109. }
  110. static void reset_record_queue(void)
  111. {
  112. int n;
  113. LPDAQD lpDAQ;
  114. unsigned long flags;
  115. dev.last_recbank = 2;
  116. writew(PCTODSP_OFFSET(0 * DAQDS__size), dev.DARQ + JQS_wHead);
  117. writew(PCTODSP_OFFSET(dev.last_recbank * DAQDS__size), dev.DARQ + JQS_wTail);
  118. /* Critical section: bank 1 access */
  119. spin_lock_irqsave(&dev.lock, flags);
  120. msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
  121. memset_io(dev.base, 0, DAR_BUFF_SIZE * 3);
  122. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  123. spin_unlock_irqrestore(&dev.lock, flags);
  124. for (n = 0, lpDAQ = dev.base + DARQ_DATA_BUFF; n < 3; ++n, lpDAQ += DAQDS__size) {
  125. writew(PCTODSP_BASED((DWORD)(DAR_BUFF_SIZE * n)) + 0x4000, lpDAQ + DAQDS_wStart);
  126. writew(DAR_BUFF_SIZE, lpDAQ + DAQDS_wSize);
  127. writew(1, lpDAQ + DAQDS_wFormat);
  128. writew(dev.rec_sample_size, lpDAQ + DAQDS_wSampleSize);
  129. writew(dev.rec_channels, lpDAQ + DAQDS_wChannels);
  130. writew(dev.rec_sample_rate, lpDAQ + DAQDS_wSampleRate);
  131. writew(HIMT_RECORD_DONE * 0x100 + n, lpDAQ + DAQDS_wIntMsg);
  132. writew(n, lpDAQ + DAQDS_wFlags);
  133. }
  134. }
  135. static void reset_queues(void)
  136. {
  137. if (dev.mode & FMODE_WRITE) {
  138. msnd_fifo_make_empty(&dev.DAPF);
  139. reset_play_queue();
  140. }
  141. if (dev.mode & FMODE_READ) {
  142. msnd_fifo_make_empty(&dev.DARF);
  143. reset_record_queue();
  144. }
  145. }
  146. static int dsp_set_format(struct file *file, int val)
  147. {
  148. int data, i;
  149. LPDAQD lpDAQ, lpDARQ;
  150. lpDAQ = dev.base + DAPQ_DATA_BUFF;
  151. lpDARQ = dev.base + DARQ_DATA_BUFF;
  152. switch (val) {
  153. case AFMT_U8:
  154. case AFMT_S16_LE:
  155. data = val;
  156. break;
  157. default:
  158. data = DEFSAMPLESIZE;
  159. break;
  160. }
  161. for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
  162. if (file->f_mode & FMODE_WRITE)
  163. writew(data, lpDAQ + DAQDS_wSampleSize);
  164. if (file->f_mode & FMODE_READ)
  165. writew(data, lpDARQ + DAQDS_wSampleSize);
  166. }
  167. if (file->f_mode & FMODE_WRITE)
  168. dev.play_sample_size = data;
  169. if (file->f_mode & FMODE_READ)
  170. dev.rec_sample_size = data;
  171. return data;
  172. }
  173. static int dsp_get_frag_size(void)
  174. {
  175. int size;
  176. size = dev.fifosize / 4;
  177. if (size > 32 * 1024)
  178. size = 32 * 1024;
  179. return size;
  180. }
  181. static int dsp_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  182. {
  183. int val, i, data, tmp;
  184. LPDAQD lpDAQ, lpDARQ;
  185. audio_buf_info abinfo;
  186. unsigned long flags;
  187. int __user *p = (int __user *)arg;
  188. lpDAQ = dev.base + DAPQ_DATA_BUFF;
  189. lpDARQ = dev.base + DARQ_DATA_BUFF;
  190. switch (cmd) {
  191. case SNDCTL_DSP_SUBDIVIDE:
  192. case SNDCTL_DSP_SETFRAGMENT:
  193. case SNDCTL_DSP_SETDUPLEX:
  194. case SNDCTL_DSP_POST:
  195. return 0;
  196. case SNDCTL_DSP_GETIPTR:
  197. case SNDCTL_DSP_GETOPTR:
  198. case SNDCTL_DSP_MAPINBUF:
  199. case SNDCTL_DSP_MAPOUTBUF:
  200. return -EINVAL;
  201. case SNDCTL_DSP_GETOSPACE:
  202. if (!(file->f_mode & FMODE_WRITE))
  203. return -EINVAL;
  204. spin_lock_irqsave(&dev.lock, flags);
  205. abinfo.fragsize = dsp_get_frag_size();
  206. abinfo.bytes = dev.DAPF.n - dev.DAPF.len;
  207. abinfo.fragstotal = dev.DAPF.n / abinfo.fragsize;
  208. abinfo.fragments = abinfo.bytes / abinfo.fragsize;
  209. spin_unlock_irqrestore(&dev.lock, flags);
  210. return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
  211. case SNDCTL_DSP_GETISPACE:
  212. if (!(file->f_mode & FMODE_READ))
  213. return -EINVAL;
  214. spin_lock_irqsave(&dev.lock, flags);
  215. abinfo.fragsize = dsp_get_frag_size();
  216. abinfo.bytes = dev.DARF.n - dev.DARF.len;
  217. abinfo.fragstotal = dev.DARF.n / abinfo.fragsize;
  218. abinfo.fragments = abinfo.bytes / abinfo.fragsize;
  219. spin_unlock_irqrestore(&dev.lock, flags);
  220. return copy_to_user((void __user *)arg, &abinfo, sizeof(abinfo)) ? -EFAULT : 0;
  221. case SNDCTL_DSP_RESET:
  222. dev.nresets = 0;
  223. reset_queues();
  224. return 0;
  225. case SNDCTL_DSP_SYNC:
  226. dsp_write_flush();
  227. return 0;
  228. case SNDCTL_DSP_GETBLKSIZE:
  229. tmp = dsp_get_frag_size();
  230. if (put_user(tmp, p))
  231. return -EFAULT;
  232. return 0;
  233. case SNDCTL_DSP_GETFMTS:
  234. val = AFMT_S16_LE | AFMT_U8;
  235. if (put_user(val, p))
  236. return -EFAULT;
  237. return 0;
  238. case SNDCTL_DSP_SETFMT:
  239. if (get_user(val, p))
  240. return -EFAULT;
  241. if (file->f_mode & FMODE_WRITE)
  242. data = val == AFMT_QUERY
  243. ? dev.play_sample_size
  244. : dsp_set_format(file, val);
  245. else
  246. data = val == AFMT_QUERY
  247. ? dev.rec_sample_size
  248. : dsp_set_format(file, val);
  249. if (put_user(data, p))
  250. return -EFAULT;
  251. return 0;
  252. case SNDCTL_DSP_NONBLOCK:
  253. if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags) &&
  254. file->f_mode & FMODE_WRITE)
  255. dev.play_ndelay = 1;
  256. if (file->f_mode & FMODE_READ)
  257. dev.rec_ndelay = 1;
  258. return 0;
  259. case SNDCTL_DSP_GETCAPS:
  260. val = DSP_CAP_DUPLEX | DSP_CAP_BATCH;
  261. if (put_user(val, p))
  262. return -EFAULT;
  263. return 0;
  264. case SNDCTL_DSP_SPEED:
  265. if (get_user(val, p))
  266. return -EFAULT;
  267. if (val < 8000)
  268. val = 8000;
  269. if (val > 48000)
  270. val = 48000;
  271. data = val;
  272. for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
  273. if (file->f_mode & FMODE_WRITE)
  274. writew(data, lpDAQ + DAQDS_wSampleRate);
  275. if (file->f_mode & FMODE_READ)
  276. writew(data, lpDARQ + DAQDS_wSampleRate);
  277. }
  278. if (file->f_mode & FMODE_WRITE)
  279. dev.play_sample_rate = data;
  280. if (file->f_mode & FMODE_READ)
  281. dev.rec_sample_rate = data;
  282. if (put_user(data, p))
  283. return -EFAULT;
  284. return 0;
  285. case SNDCTL_DSP_CHANNELS:
  286. case SNDCTL_DSP_STEREO:
  287. if (get_user(val, p))
  288. return -EFAULT;
  289. if (cmd == SNDCTL_DSP_CHANNELS) {
  290. switch (val) {
  291. case 1:
  292. case 2:
  293. data = val;
  294. break;
  295. default:
  296. val = data = 2;
  297. break;
  298. }
  299. } else {
  300. switch (val) {
  301. case 0:
  302. data = 1;
  303. break;
  304. default:
  305. val = 1;
  306. case 1:
  307. data = 2;
  308. break;
  309. }
  310. }
  311. for (i = 0; i < 3; ++i, lpDAQ += DAQDS__size, lpDARQ += DAQDS__size) {
  312. if (file->f_mode & FMODE_WRITE)
  313. writew(data, lpDAQ + DAQDS_wChannels);
  314. if (file->f_mode & FMODE_READ)
  315. writew(data, lpDARQ + DAQDS_wChannels);
  316. }
  317. if (file->f_mode & FMODE_WRITE)
  318. dev.play_channels = data;
  319. if (file->f_mode & FMODE_READ)
  320. dev.rec_channels = data;
  321. if (put_user(val, p))
  322. return -EFAULT;
  323. return 0;
  324. }
  325. return -EINVAL;
  326. }
  327. static int mixer_get(int d)
  328. {
  329. if (d > 31)
  330. return -EINVAL;
  331. switch (d) {
  332. case SOUND_MIXER_VOLUME:
  333. case SOUND_MIXER_PCM:
  334. case SOUND_MIXER_LINE:
  335. case SOUND_MIXER_IMIX:
  336. case SOUND_MIXER_LINE1:
  337. #ifndef MSND_CLASSIC
  338. case SOUND_MIXER_MIC:
  339. case SOUND_MIXER_SYNTH:
  340. #endif
  341. return (dev.left_levels[d] >> 8) * 100 / 0xff |
  342. (((dev.right_levels[d] >> 8) * 100 / 0xff) << 8);
  343. default:
  344. return 0;
  345. }
  346. }
  347. #define update_volm(a,b) \
  348. writew((dev.left_levels[a] >> 1) * \
  349. readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
  350. dev.SMA + SMA_##b##Left); \
  351. writew((dev.right_levels[a] >> 1) * \
  352. readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
  353. dev.SMA + SMA_##b##Right);
  354. #define update_potm(d,s,ar) \
  355. writeb((dev.left_levels[d] >> 8) * \
  356. readw(dev.SMA + SMA_wCurrMastVolLeft) / 0xffff, \
  357. dev.SMA + SMA_##s##Left); \
  358. writeb((dev.right_levels[d] >> 8) * \
  359. readw(dev.SMA + SMA_wCurrMastVolRight) / 0xffff, \
  360. dev.SMA + SMA_##s##Right); \
  361. if (msnd_send_word(&dev, 0, 0, ar) == 0) \
  362. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  363. #define update_pot(d,s,ar) \
  364. writeb(dev.left_levels[d] >> 8, \
  365. dev.SMA + SMA_##s##Left); \
  366. writeb(dev.right_levels[d] >> 8, \
  367. dev.SMA + SMA_##s##Right); \
  368. if (msnd_send_word(&dev, 0, 0, ar) == 0) \
  369. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  370. static int mixer_set(int d, int value)
  371. {
  372. int left = value & 0x000000ff;
  373. int right = (value & 0x0000ff00) >> 8;
  374. int bLeft, bRight;
  375. int wLeft, wRight;
  376. int updatemaster = 0;
  377. if (d > 31)
  378. return -EINVAL;
  379. bLeft = left * 0xff / 100;
  380. wLeft = left * 0xffff / 100;
  381. bRight = right * 0xff / 100;
  382. wRight = right * 0xffff / 100;
  383. dev.left_levels[d] = wLeft;
  384. dev.right_levels[d] = wRight;
  385. switch (d) {
  386. /* master volume unscaled controls */
  387. case SOUND_MIXER_LINE: /* line pot control */
  388. /* scaled by IMIX in digital mix */
  389. writeb(bLeft, dev.SMA + SMA_bInPotPosLeft);
  390. writeb(bRight, dev.SMA + SMA_bInPotPosRight);
  391. if (msnd_send_word(&dev, 0, 0, HDEXAR_IN_SET_POTS) == 0)
  392. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  393. break;
  394. #ifndef MSND_CLASSIC
  395. case SOUND_MIXER_MIC: /* mic pot control */
  396. /* scaled by IMIX in digital mix */
  397. writeb(bLeft, dev.SMA + SMA_bMicPotPosLeft);
  398. writeb(bRight, dev.SMA + SMA_bMicPotPosRight);
  399. if (msnd_send_word(&dev, 0, 0, HDEXAR_MIC_SET_POTS) == 0)
  400. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  401. break;
  402. #endif
  403. case SOUND_MIXER_VOLUME: /* master volume */
  404. writew(wLeft, dev.SMA + SMA_wCurrMastVolLeft);
  405. writew(wRight, dev.SMA + SMA_wCurrMastVolRight);
  406. /* fall through */
  407. case SOUND_MIXER_LINE1: /* aux pot control */
  408. /* scaled by master volume */
  409. /* fall through */
  410. /* digital controls */
  411. case SOUND_MIXER_SYNTH: /* synth vol (dsp mix) */
  412. case SOUND_MIXER_PCM: /* pcm vol (dsp mix) */
  413. case SOUND_MIXER_IMIX: /* input monitor (dsp mix) */
  414. /* scaled by master volume */
  415. updatemaster = 1;
  416. break;
  417. default:
  418. return 0;
  419. }
  420. if (updatemaster) {
  421. /* update master volume scaled controls */
  422. update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
  423. update_volm(SOUND_MIXER_IMIX, wCurrInVol);
  424. #ifndef MSND_CLASSIC
  425. update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
  426. #endif
  427. update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
  428. }
  429. return mixer_get(d);
  430. }
  431. static void mixer_setup(void)
  432. {
  433. update_pot(SOUND_MIXER_LINE, bInPotPos, HDEXAR_IN_SET_POTS);
  434. update_potm(SOUND_MIXER_LINE1, bAuxPotPos, HDEXAR_AUX_SET_POTS);
  435. update_volm(SOUND_MIXER_PCM, wCurrPlayVol);
  436. update_volm(SOUND_MIXER_IMIX, wCurrInVol);
  437. #ifndef MSND_CLASSIC
  438. update_pot(SOUND_MIXER_MIC, bMicPotPos, HDEXAR_MIC_SET_POTS);
  439. update_volm(SOUND_MIXER_SYNTH, wCurrMHdrVol);
  440. #endif
  441. }
  442. static unsigned long set_recsrc(unsigned long recsrc)
  443. {
  444. if (dev.recsrc == recsrc)
  445. return dev.recsrc;
  446. #ifdef HAVE_NORECSRC
  447. else if (recsrc == 0)
  448. dev.recsrc = 0;
  449. #endif
  450. else
  451. dev.recsrc ^= recsrc;
  452. #ifndef MSND_CLASSIC
  453. if (dev.recsrc & SOUND_MASK_IMIX) {
  454. if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
  455. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  456. }
  457. else if (dev.recsrc & SOUND_MASK_SYNTH) {
  458. if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_SYNTH_IN) == 0)
  459. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  460. }
  461. else if ((dev.recsrc & SOUND_MASK_DIGITAL1) && test_bit(F_HAVEDIGITAL, &dev.flags)) {
  462. if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_DAT_IN) == 0)
  463. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  464. }
  465. else {
  466. #ifdef HAVE_NORECSRC
  467. /* Select no input (?) */
  468. dev.recsrc = 0;
  469. #else
  470. dev.recsrc = SOUND_MASK_IMIX;
  471. if (msnd_send_word(&dev, 0, 0, HDEXAR_SET_ANA_IN) == 0)
  472. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ);
  473. #endif
  474. }
  475. #endif /* MSND_CLASSIC */
  476. return dev.recsrc;
  477. }
  478. static unsigned long force_recsrc(unsigned long recsrc)
  479. {
  480. dev.recsrc = 0;
  481. return set_recsrc(recsrc);
  482. }
  483. #define set_mixer_info() \
  484. memset(&info, 0, sizeof(info)); \
  485. strlcpy(info.id, "MSNDMIXER", sizeof(info.id)); \
  486. strlcpy(info.name, "MultiSound Mixer", sizeof(info.name));
  487. static int mixer_ioctl(unsigned int cmd, unsigned long arg)
  488. {
  489. if (cmd == SOUND_MIXER_INFO) {
  490. mixer_info info;
  491. set_mixer_info();
  492. info.modify_counter = dev.mixer_mod_count;
  493. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  494. return -EFAULT;
  495. return 0;
  496. } else if (cmd == SOUND_OLD_MIXER_INFO) {
  497. _old_mixer_info info;
  498. set_mixer_info();
  499. if (copy_to_user((void __user *)arg, &info, sizeof(info)))
  500. return -EFAULT;
  501. return 0;
  502. } else if (cmd == SOUND_MIXER_PRIVATE1) {
  503. dev.nresets = 0;
  504. dsp_full_reset();
  505. return 0;
  506. } else if (((cmd >> 8) & 0xff) == 'M') {
  507. int val = 0;
  508. if (_SIOC_DIR(cmd) & _SIOC_WRITE) {
  509. switch (cmd & 0xff) {
  510. case SOUND_MIXER_RECSRC:
  511. if (get_user(val, (int __user *)arg))
  512. return -EFAULT;
  513. val = set_recsrc(val);
  514. break;
  515. default:
  516. if (get_user(val, (int __user *)arg))
  517. return -EFAULT;
  518. val = mixer_set(cmd & 0xff, val);
  519. break;
  520. }
  521. ++dev.mixer_mod_count;
  522. return put_user(val, (int __user *)arg);
  523. } else {
  524. switch (cmd & 0xff) {
  525. case SOUND_MIXER_RECSRC:
  526. val = dev.recsrc;
  527. break;
  528. case SOUND_MIXER_DEVMASK:
  529. case SOUND_MIXER_STEREODEVS:
  530. val = SOUND_MASK_PCM |
  531. SOUND_MASK_LINE |
  532. SOUND_MASK_IMIX |
  533. SOUND_MASK_LINE1 |
  534. #ifndef MSND_CLASSIC
  535. SOUND_MASK_MIC |
  536. SOUND_MASK_SYNTH |
  537. #endif
  538. SOUND_MASK_VOLUME;
  539. break;
  540. case SOUND_MIXER_RECMASK:
  541. #ifdef MSND_CLASSIC
  542. val = 0;
  543. #else
  544. val = SOUND_MASK_IMIX |
  545. SOUND_MASK_SYNTH;
  546. if (test_bit(F_HAVEDIGITAL, &dev.flags))
  547. val |= SOUND_MASK_DIGITAL1;
  548. #endif
  549. break;
  550. case SOUND_MIXER_CAPS:
  551. val = SOUND_CAP_EXCL_INPUT;
  552. break;
  553. default:
  554. if ((val = mixer_get(cmd & 0xff)) < 0)
  555. return -EINVAL;
  556. break;
  557. }
  558. }
  559. return put_user(val, (int __user *)arg);
  560. }
  561. return -EINVAL;
  562. }
  563. static long dev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
  564. {
  565. int minor = iminor(file_inode(file));
  566. int ret;
  567. if (cmd == OSS_GETVERSION) {
  568. int sound_version = SOUND_VERSION;
  569. return put_user(sound_version, (int __user *)arg);
  570. }
  571. ret = -EINVAL;
  572. mutex_lock(&msnd_pinnacle_mutex);
  573. if (minor == dev.dsp_minor)
  574. ret = dsp_ioctl(file, cmd, arg);
  575. else if (minor == dev.mixer_minor)
  576. ret = mixer_ioctl(cmd, arg);
  577. mutex_unlock(&msnd_pinnacle_mutex);
  578. return ret;
  579. }
  580. static void dsp_write_flush(void)
  581. {
  582. int timeout = get_play_delay_jiffies(dev.DAPF.len);
  583. if (!(dev.mode & FMODE_WRITE) || !test_bit(F_WRITING, &dev.flags))
  584. return;
  585. set_bit(F_WRITEFLUSH, &dev.flags);
  586. wait_event_interruptible_timeout(
  587. dev.writeflush,
  588. !test_bit(F_WRITEFLUSH, &dev.flags),
  589. timeout);
  590. clear_bit(F_WRITEFLUSH, &dev.flags);
  591. if (!signal_pending(current)) {
  592. __set_current_state(TASK_INTERRUPTIBLE);
  593. schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE));
  594. }
  595. clear_bit(F_WRITING, &dev.flags);
  596. }
  597. static void dsp_halt(struct file *file)
  598. {
  599. if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
  600. clear_bit(F_READING, &dev.flags);
  601. chk_send_dsp_cmd(&dev, HDEX_RECORD_STOP);
  602. msnd_disable_irq(&dev);
  603. if (file) {
  604. printk(KERN_DEBUG LOGNAME ": Stopping read for %p\n", file);
  605. dev.mode &= ~FMODE_READ;
  606. }
  607. clear_bit(F_AUDIO_READ_INUSE, &dev.flags);
  608. }
  609. if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
  610. if (test_bit(F_WRITING, &dev.flags)) {
  611. dsp_write_flush();
  612. chk_send_dsp_cmd(&dev, HDEX_PLAY_STOP);
  613. }
  614. msnd_disable_irq(&dev);
  615. if (file) {
  616. printk(KERN_DEBUG LOGNAME ": Stopping write for %p\n", file);
  617. dev.mode &= ~FMODE_WRITE;
  618. }
  619. clear_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
  620. }
  621. }
  622. static int dsp_release(struct file *file)
  623. {
  624. dsp_halt(file);
  625. return 0;
  626. }
  627. static int dsp_open(struct file *file)
  628. {
  629. if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
  630. set_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
  631. clear_bit(F_WRITING, &dev.flags);
  632. msnd_fifo_make_empty(&dev.DAPF);
  633. reset_play_queue();
  634. if (file) {
  635. printk(KERN_DEBUG LOGNAME ": Starting write for %p\n", file);
  636. dev.mode |= FMODE_WRITE;
  637. }
  638. msnd_enable_irq(&dev);
  639. }
  640. if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
  641. set_bit(F_AUDIO_READ_INUSE, &dev.flags);
  642. clear_bit(F_READING, &dev.flags);
  643. msnd_fifo_make_empty(&dev.DARF);
  644. reset_record_queue();
  645. if (file) {
  646. printk(KERN_DEBUG LOGNAME ": Starting read for %p\n", file);
  647. dev.mode |= FMODE_READ;
  648. }
  649. msnd_enable_irq(&dev);
  650. }
  651. return 0;
  652. }
  653. static void set_default_play_audio_parameters(void)
  654. {
  655. dev.play_sample_size = DEFSAMPLESIZE;
  656. dev.play_sample_rate = DEFSAMPLERATE;
  657. dev.play_channels = DEFCHANNELS;
  658. }
  659. static void set_default_rec_audio_parameters(void)
  660. {
  661. dev.rec_sample_size = DEFSAMPLESIZE;
  662. dev.rec_sample_rate = DEFSAMPLERATE;
  663. dev.rec_channels = DEFCHANNELS;
  664. }
  665. static void set_default_audio_parameters(void)
  666. {
  667. set_default_play_audio_parameters();
  668. set_default_rec_audio_parameters();
  669. }
  670. static int dev_open(struct inode *inode, struct file *file)
  671. {
  672. int minor = iminor(inode);
  673. int err = 0;
  674. mutex_lock(&msnd_pinnacle_mutex);
  675. if (minor == dev.dsp_minor) {
  676. if ((file->f_mode & FMODE_WRITE &&
  677. test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
  678. (file->f_mode & FMODE_READ &&
  679. test_bit(F_AUDIO_READ_INUSE, &dev.flags))) {
  680. err = -EBUSY;
  681. goto out;
  682. }
  683. if ((err = dsp_open(file)) >= 0) {
  684. dev.nresets = 0;
  685. if (file->f_mode & FMODE_WRITE) {
  686. set_default_play_audio_parameters();
  687. if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags))
  688. dev.play_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
  689. else
  690. dev.play_ndelay = 0;
  691. }
  692. if (file->f_mode & FMODE_READ) {
  693. set_default_rec_audio_parameters();
  694. dev.rec_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
  695. }
  696. }
  697. }
  698. else if (minor == dev.mixer_minor) {
  699. /* nothing */
  700. } else
  701. err = -EINVAL;
  702. out:
  703. mutex_unlock(&msnd_pinnacle_mutex);
  704. return err;
  705. }
  706. static int dev_release(struct inode *inode, struct file *file)
  707. {
  708. int minor = iminor(inode);
  709. int err = 0;
  710. mutex_lock(&msnd_pinnacle_mutex);
  711. if (minor == dev.dsp_minor)
  712. err = dsp_release(file);
  713. else if (minor == dev.mixer_minor) {
  714. /* nothing */
  715. } else
  716. err = -EINVAL;
  717. mutex_unlock(&msnd_pinnacle_mutex);
  718. return err;
  719. }
  720. static __inline__ int pack_DARQ_to_DARF(register int bank)
  721. {
  722. register int size, timeout = 3;
  723. register WORD wTmp;
  724. LPDAQD DAQD;
  725. /* Increment the tail and check for queue wrap */
  726. wTmp = readw(dev.DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
  727. if (wTmp > readw(dev.DARQ + JQS_wSize))
  728. wTmp = 0;
  729. while (wTmp == readw(dev.DARQ + JQS_wHead) && timeout--)
  730. udelay(1);
  731. writew(wTmp, dev.DARQ + JQS_wTail);
  732. /* Get our digital audio queue struct */
  733. DAQD = bank * DAQDS__size + dev.base + DARQ_DATA_BUFF;
  734. /* Get length of data */
  735. size = readw(DAQD + DAQDS_wSize);
  736. /* Read data from the head (unprotected bank 1 access okay
  737. since this is only called inside an interrupt) */
  738. msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
  739. msnd_fifo_write_io(
  740. &dev.DARF,
  741. dev.base + bank * DAR_BUFF_SIZE,
  742. size);
  743. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  744. return 1;
  745. }
  746. static __inline__ int pack_DAPF_to_DAPQ(register int start)
  747. {
  748. register WORD DAPQ_tail;
  749. register int protect = start, nbanks = 0;
  750. LPDAQD DAQD;
  751. DAPQ_tail = readw(dev.DAPQ + JQS_wTail);
  752. while (DAPQ_tail != readw(dev.DAPQ + JQS_wHead) || start) {
  753. register int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
  754. register int n;
  755. unsigned long flags;
  756. /* Write the data to the new tail */
  757. if (protect) {
  758. /* Critical section: protect fifo in non-interrupt */
  759. spin_lock_irqsave(&dev.lock, flags);
  760. n = msnd_fifo_read_io(
  761. &dev.DAPF,
  762. dev.base + bank_num * DAP_BUFF_SIZE,
  763. DAP_BUFF_SIZE);
  764. spin_unlock_irqrestore(&dev.lock, flags);
  765. } else {
  766. n = msnd_fifo_read_io(
  767. &dev.DAPF,
  768. dev.base + bank_num * DAP_BUFF_SIZE,
  769. DAP_BUFF_SIZE);
  770. }
  771. if (!n)
  772. break;
  773. if (start)
  774. start = 0;
  775. /* Get our digital audio queue struct */
  776. DAQD = bank_num * DAQDS__size + dev.base + DAPQ_DATA_BUFF;
  777. /* Write size of this bank */
  778. writew(n, DAQD + DAQDS_wSize);
  779. ++nbanks;
  780. /* Then advance the tail */
  781. DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
  782. writew(DAPQ_tail, dev.DAPQ + JQS_wTail);
  783. /* Tell the DSP to play the bank */
  784. msnd_send_dsp_cmd(&dev, HDEX_PLAY_START);
  785. }
  786. return nbanks;
  787. }
  788. static int dsp_read(char __user *buf, size_t len)
  789. {
  790. int count = len;
  791. char *page = (char *)__get_free_page(GFP_KERNEL);
  792. int timeout = get_rec_delay_jiffies(DAR_BUFF_SIZE);
  793. if (!page)
  794. return -ENOMEM;
  795. while (count > 0) {
  796. int n, k;
  797. unsigned long flags;
  798. k = PAGE_SIZE;
  799. if (k > count)
  800. k = count;
  801. /* Critical section: protect fifo in non-interrupt */
  802. spin_lock_irqsave(&dev.lock, flags);
  803. n = msnd_fifo_read(&dev.DARF, page, k);
  804. spin_unlock_irqrestore(&dev.lock, flags);
  805. if (copy_to_user(buf, page, n)) {
  806. free_page((unsigned long)page);
  807. return -EFAULT;
  808. }
  809. buf += n;
  810. count -= n;
  811. if (n == k && count)
  812. continue;
  813. if (!test_bit(F_READING, &dev.flags) && dev.mode & FMODE_READ) {
  814. dev.last_recbank = -1;
  815. if (chk_send_dsp_cmd(&dev, HDEX_RECORD_START) == 0)
  816. set_bit(F_READING, &dev.flags);
  817. }
  818. if (dev.rec_ndelay) {
  819. free_page((unsigned long)page);
  820. return count == len ? -EAGAIN : len - count;
  821. }
  822. if (count > 0) {
  823. set_bit(F_READBLOCK, &dev.flags);
  824. if (wait_event_interruptible_timeout(
  825. dev.readblock,
  826. test_bit(F_READBLOCK, &dev.flags),
  827. timeout) <= 0)
  828. clear_bit(F_READING, &dev.flags);
  829. if (signal_pending(current)) {
  830. free_page((unsigned long)page);
  831. return -EINTR;
  832. }
  833. }
  834. }
  835. free_page((unsigned long)page);
  836. return len - count;
  837. }
  838. static int dsp_write(const char __user *buf, size_t len)
  839. {
  840. int count = len;
  841. char *page = (char *)__get_free_page(GFP_KERNEL);
  842. int timeout = get_play_delay_jiffies(DAP_BUFF_SIZE);
  843. if (!page)
  844. return -ENOMEM;
  845. while (count > 0) {
  846. int n, k;
  847. unsigned long flags;
  848. k = PAGE_SIZE;
  849. if (k > count)
  850. k = count;
  851. if (copy_from_user(page, buf, k)) {
  852. free_page((unsigned long)page);
  853. return -EFAULT;
  854. }
  855. /* Critical section: protect fifo in non-interrupt */
  856. spin_lock_irqsave(&dev.lock, flags);
  857. n = msnd_fifo_write(&dev.DAPF, page, k);
  858. spin_unlock_irqrestore(&dev.lock, flags);
  859. buf += n;
  860. count -= n;
  861. if (count && n == k)
  862. continue;
  863. if (!test_bit(F_WRITING, &dev.flags) && (dev.mode & FMODE_WRITE)) {
  864. dev.last_playbank = -1;
  865. if (pack_DAPF_to_DAPQ(1) > 0)
  866. set_bit(F_WRITING, &dev.flags);
  867. }
  868. if (dev.play_ndelay) {
  869. free_page((unsigned long)page);
  870. return count == len ? -EAGAIN : len - count;
  871. }
  872. if (count > 0) {
  873. set_bit(F_WRITEBLOCK, &dev.flags);
  874. wait_event_interruptible_timeout(
  875. dev.writeblock,
  876. test_bit(F_WRITEBLOCK, &dev.flags),
  877. timeout);
  878. if (signal_pending(current)) {
  879. free_page((unsigned long)page);
  880. return -EINTR;
  881. }
  882. }
  883. }
  884. free_page((unsigned long)page);
  885. return len - count;
  886. }
  887. static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  888. {
  889. int minor = iminor(file_inode(file));
  890. if (minor == dev.dsp_minor)
  891. return dsp_read(buf, count);
  892. else
  893. return -EINVAL;
  894. }
  895. static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  896. {
  897. int minor = iminor(file_inode(file));
  898. if (minor == dev.dsp_minor)
  899. return dsp_write(buf, count);
  900. else
  901. return -EINVAL;
  902. }
  903. static __inline__ void eval_dsp_msg(register WORD wMessage)
  904. {
  905. switch (HIBYTE(wMessage)) {
  906. case HIMT_PLAY_DONE:
  907. if (dev.last_playbank == LOBYTE(wMessage) || !test_bit(F_WRITING, &dev.flags))
  908. break;
  909. dev.last_playbank = LOBYTE(wMessage);
  910. if (pack_DAPF_to_DAPQ(0) <= 0) {
  911. if (!test_bit(F_WRITEBLOCK, &dev.flags)) {
  912. if (test_and_clear_bit(F_WRITEFLUSH, &dev.flags))
  913. wake_up_interruptible(&dev.writeflush);
  914. }
  915. clear_bit(F_WRITING, &dev.flags);
  916. }
  917. if (test_and_clear_bit(F_WRITEBLOCK, &dev.flags))
  918. wake_up_interruptible(&dev.writeblock);
  919. break;
  920. case HIMT_RECORD_DONE:
  921. if (dev.last_recbank == LOBYTE(wMessage))
  922. break;
  923. dev.last_recbank = LOBYTE(wMessage);
  924. pack_DARQ_to_DARF(dev.last_recbank);
  925. if (test_and_clear_bit(F_READBLOCK, &dev.flags))
  926. wake_up_interruptible(&dev.readblock);
  927. break;
  928. case HIMT_DSP:
  929. switch (LOBYTE(wMessage)) {
  930. #ifndef MSND_CLASSIC
  931. case HIDSP_PLAY_UNDER:
  932. #endif
  933. case HIDSP_INT_PLAY_UNDER:
  934. /* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
  935. clear_bit(F_WRITING, &dev.flags);
  936. break;
  937. case HIDSP_INT_RECORD_OVER:
  938. /* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
  939. clear_bit(F_READING, &dev.flags);
  940. break;
  941. default:
  942. /* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
  943. LOBYTE(wMessage), LOBYTE(wMessage)); */
  944. break;
  945. }
  946. break;
  947. case HIMT_MIDI_IN_UCHAR:
  948. if (dev.midi_in_interrupt)
  949. (*dev.midi_in_interrupt)(&dev);
  950. break;
  951. default:
  952. /* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
  953. break;
  954. }
  955. }
  956. static irqreturn_t intr(int irq, void *dev_id)
  957. {
  958. /* Send ack to DSP */
  959. msnd_inb(dev.io + HP_RXL);
  960. /* Evaluate queued DSP messages */
  961. while (readw(dev.DSPQ + JQS_wTail) != readw(dev.DSPQ + JQS_wHead)) {
  962. register WORD wTmp;
  963. eval_dsp_msg(readw(dev.pwDSPQData + 2*readw(dev.DSPQ + JQS_wHead)));
  964. if ((wTmp = readw(dev.DSPQ + JQS_wHead) + 1) > readw(dev.DSPQ + JQS_wSize))
  965. writew(0, dev.DSPQ + JQS_wHead);
  966. else
  967. writew(wTmp, dev.DSPQ + JQS_wHead);
  968. }
  969. return IRQ_HANDLED;
  970. }
  971. static const struct file_operations dev_fileops = {
  972. .owner = THIS_MODULE,
  973. .read = dev_read,
  974. .write = dev_write,
  975. .unlocked_ioctl = dev_ioctl,
  976. .open = dev_open,
  977. .release = dev_release,
  978. .llseek = noop_llseek,
  979. };
  980. static int reset_dsp(void)
  981. {
  982. int timeout = 100;
  983. msnd_outb(HPDSPRESET_ON, dev.io + HP_DSPR);
  984. mdelay(1);
  985. #ifndef MSND_CLASSIC
  986. dev.info = msnd_inb(dev.io + HP_INFO);
  987. #endif
  988. msnd_outb(HPDSPRESET_OFF, dev.io + HP_DSPR);
  989. mdelay(1);
  990. while (timeout-- > 0) {
  991. if (msnd_inb(dev.io + HP_CVR) == HP_CVR_DEF)
  992. return 0;
  993. mdelay(1);
  994. }
  995. printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
  996. return -EIO;
  997. }
  998. static int __init probe_multisound(void)
  999. {
  1000. #ifndef MSND_CLASSIC
  1001. char *xv, *rev = NULL;
  1002. char *pin = "Pinnacle", *fiji = "Fiji";
  1003. char *pinfiji = "Pinnacle/Fiji";
  1004. #endif
  1005. if (!request_region(dev.io, dev.numio, "probing")) {
  1006. printk(KERN_ERR LOGNAME ": I/O port conflict\n");
  1007. return -ENODEV;
  1008. }
  1009. if (reset_dsp() < 0) {
  1010. release_region(dev.io, dev.numio);
  1011. return -ENODEV;
  1012. }
  1013. #ifdef MSND_CLASSIC
  1014. dev.name = "Classic/Tahiti/Monterey";
  1015. printk(KERN_INFO LOGNAME ": %s, "
  1016. #else
  1017. switch (dev.info >> 4) {
  1018. case 0xf: xv = "<= 1.15"; break;
  1019. case 0x1: xv = "1.18/1.2"; break;
  1020. case 0x2: xv = "1.3"; break;
  1021. case 0x3: xv = "1.4"; break;
  1022. default: xv = "unknown"; break;
  1023. }
  1024. switch (dev.info & 0x7) {
  1025. case 0x0: rev = "I"; dev.name = pin; break;
  1026. case 0x1: rev = "F"; dev.name = pin; break;
  1027. case 0x2: rev = "G"; dev.name = pin; break;
  1028. case 0x3: rev = "H"; dev.name = pin; break;
  1029. case 0x4: rev = "E"; dev.name = fiji; break;
  1030. case 0x5: rev = "C"; dev.name = fiji; break;
  1031. case 0x6: rev = "D"; dev.name = fiji; break;
  1032. case 0x7:
  1033. rev = "A-B (Fiji) or A-E (Pinnacle)";
  1034. dev.name = pinfiji;
  1035. break;
  1036. }
  1037. printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
  1038. #endif /* MSND_CLASSIC */
  1039. "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
  1040. dev.name,
  1041. #ifndef MSND_CLASSIC
  1042. rev, xv,
  1043. #endif
  1044. dev.io, dev.io + dev.numio - 1,
  1045. dev.irq,
  1046. dev.base, dev.base + 0x7fff);
  1047. release_region(dev.io, dev.numio);
  1048. return 0;
  1049. }
  1050. static int init_sma(void)
  1051. {
  1052. static int initted;
  1053. WORD mastVolLeft, mastVolRight;
  1054. unsigned long flags;
  1055. #ifdef MSND_CLASSIC
  1056. msnd_outb(dev.memid, dev.io + HP_MEMM);
  1057. #endif
  1058. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1059. if (initted) {
  1060. mastVolLeft = readw(dev.SMA + SMA_wCurrMastVolLeft);
  1061. mastVolRight = readw(dev.SMA + SMA_wCurrMastVolRight);
  1062. } else
  1063. mastVolLeft = mastVolRight = 0;
  1064. memset_io(dev.base, 0, 0x8000);
  1065. /* Critical section: bank 1 access */
  1066. spin_lock_irqsave(&dev.lock, flags);
  1067. msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
  1068. memset_io(dev.base, 0, 0x8000);
  1069. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1070. spin_unlock_irqrestore(&dev.lock, flags);
  1071. dev.pwDSPQData = (dev.base + DSPQ_DATA_BUFF);
  1072. dev.pwMODQData = (dev.base + MODQ_DATA_BUFF);
  1073. dev.pwMIDQData = (dev.base + MIDQ_DATA_BUFF);
  1074. /* Motorola 56k shared memory base */
  1075. dev.SMA = dev.base + SMA_STRUCT_START;
  1076. /* Digital audio play queue */
  1077. dev.DAPQ = dev.base + DAPQ_OFFSET;
  1078. msnd_init_queue(dev.DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
  1079. /* Digital audio record queue */
  1080. dev.DARQ = dev.base + DARQ_OFFSET;
  1081. msnd_init_queue(dev.DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
  1082. /* MIDI out queue */
  1083. dev.MODQ = dev.base + MODQ_OFFSET;
  1084. msnd_init_queue(dev.MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
  1085. /* MIDI in queue */
  1086. dev.MIDQ = dev.base + MIDQ_OFFSET;
  1087. msnd_init_queue(dev.MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
  1088. /* DSP -> host message queue */
  1089. dev.DSPQ = dev.base + DSPQ_OFFSET;
  1090. msnd_init_queue(dev.DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
  1091. /* Setup some DSP values */
  1092. #ifndef MSND_CLASSIC
  1093. writew(1, dev.SMA + SMA_wCurrPlayFormat);
  1094. writew(dev.play_sample_size, dev.SMA + SMA_wCurrPlaySampleSize);
  1095. writew(dev.play_channels, dev.SMA + SMA_wCurrPlayChannels);
  1096. writew(dev.play_sample_rate, dev.SMA + SMA_wCurrPlaySampleRate);
  1097. #endif
  1098. writew(dev.play_sample_rate, dev.SMA + SMA_wCalFreqAtoD);
  1099. writew(mastVolLeft, dev.SMA + SMA_wCurrMastVolLeft);
  1100. writew(mastVolRight, dev.SMA + SMA_wCurrMastVolRight);
  1101. #ifndef MSND_CLASSIC
  1102. writel(0x00010000, dev.SMA + SMA_dwCurrPlayPitch);
  1103. writel(0x00000001, dev.SMA + SMA_dwCurrPlayRate);
  1104. #endif
  1105. writew(0x303, dev.SMA + SMA_wCurrInputTagBits);
  1106. initted = 1;
  1107. return 0;
  1108. }
  1109. static int __init calibrate_adc(WORD srate)
  1110. {
  1111. writew(srate, dev.SMA + SMA_wCalFreqAtoD);
  1112. if (dev.calibrate_signal == 0)
  1113. writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
  1114. | 0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
  1115. else
  1116. writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
  1117. & ~0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
  1118. if (msnd_send_word(&dev, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
  1119. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ) == 0) {
  1120. schedule_timeout_interruptible(HZ / 3);
  1121. return 0;
  1122. }
  1123. printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
  1124. return -EIO;
  1125. }
  1126. static int upload_dsp_code(void)
  1127. {
  1128. int ret = 0;
  1129. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1130. #ifndef HAVE_DSPCODEH
  1131. INITCODESIZE = mod_firmware_load(INITCODEFILE, &INITCODE);
  1132. if (!INITCODE) {
  1133. printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
  1134. return -EBUSY;
  1135. }
  1136. PERMCODESIZE = mod_firmware_load(PERMCODEFILE, &PERMCODE);
  1137. if (!PERMCODE) {
  1138. printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
  1139. vfree(INITCODE);
  1140. return -EBUSY;
  1141. }
  1142. #endif
  1143. memcpy_toio(dev.base, PERMCODE, PERMCODESIZE);
  1144. if (msnd_upload_host(&dev, INITCODE, INITCODESIZE) < 0) {
  1145. printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
  1146. ret = -ENODEV;
  1147. goto out;
  1148. }
  1149. #ifdef HAVE_DSPCODEH
  1150. printk(KERN_INFO LOGNAME ": DSP firmware uploaded (resident)\n");
  1151. #else
  1152. printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
  1153. #endif
  1154. out:
  1155. #ifndef HAVE_DSPCODEH
  1156. vfree(INITCODE);
  1157. vfree(PERMCODE);
  1158. #endif
  1159. return ret;
  1160. }
  1161. #ifdef MSND_CLASSIC
  1162. static void reset_proteus(void)
  1163. {
  1164. msnd_outb(HPPRORESET_ON, dev.io + HP_PROR);
  1165. mdelay(TIME_PRO_RESET);
  1166. msnd_outb(HPPRORESET_OFF, dev.io + HP_PROR);
  1167. mdelay(TIME_PRO_RESET_DONE);
  1168. }
  1169. #endif
  1170. static int initialize(void)
  1171. {
  1172. int err, timeout;
  1173. #ifdef MSND_CLASSIC
  1174. msnd_outb(HPWAITSTATE_0, dev.io + HP_WAIT);
  1175. msnd_outb(HPBITMODE_16, dev.io + HP_BITM);
  1176. reset_proteus();
  1177. #endif
  1178. if ((err = init_sma()) < 0) {
  1179. printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
  1180. return err;
  1181. }
  1182. if ((err = reset_dsp()) < 0)
  1183. return err;
  1184. if ((err = upload_dsp_code()) < 0) {
  1185. printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
  1186. return err;
  1187. }
  1188. timeout = 200;
  1189. while (readw(dev.base)) {
  1190. mdelay(1);
  1191. if (!timeout--) {
  1192. printk(KERN_DEBUG LOGNAME ": DSP reset timeout\n");
  1193. return -EIO;
  1194. }
  1195. }
  1196. mixer_setup();
  1197. return 0;
  1198. }
  1199. static int dsp_full_reset(void)
  1200. {
  1201. int rv;
  1202. if (test_bit(F_RESETTING, &dev.flags) || ++dev.nresets > 10)
  1203. return 0;
  1204. set_bit(F_RESETTING, &dev.flags);
  1205. printk(KERN_INFO LOGNAME ": DSP reset\n");
  1206. dsp_halt(NULL); /* Unconditionally halt */
  1207. if ((rv = initialize()))
  1208. printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
  1209. force_recsrc(dev.recsrc);
  1210. dsp_open(NULL);
  1211. clear_bit(F_RESETTING, &dev.flags);
  1212. return rv;
  1213. }
  1214. static int __init attach_multisound(void)
  1215. {
  1216. int err;
  1217. if ((err = request_irq(dev.irq, intr, 0, dev.name, &dev)) < 0) {
  1218. printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", dev.irq);
  1219. return err;
  1220. }
  1221. if (request_region(dev.io, dev.numio, dev.name) == NULL) {
  1222. free_irq(dev.irq, &dev);
  1223. return -EBUSY;
  1224. }
  1225. err = dsp_full_reset();
  1226. if (err < 0) {
  1227. release_region(dev.io, dev.numio);
  1228. free_irq(dev.irq, &dev);
  1229. return err;
  1230. }
  1231. if ((err = msnd_register(&dev)) < 0) {
  1232. printk(KERN_ERR LOGNAME ": Unable to register MultiSound\n");
  1233. release_region(dev.io, dev.numio);
  1234. free_irq(dev.irq, &dev);
  1235. return err;
  1236. }
  1237. if ((dev.dsp_minor = register_sound_dsp(&dev_fileops, -1)) < 0) {
  1238. printk(KERN_ERR LOGNAME ": Unable to register DSP operations\n");
  1239. msnd_unregister(&dev);
  1240. release_region(dev.io, dev.numio);
  1241. free_irq(dev.irq, &dev);
  1242. return dev.dsp_minor;
  1243. }
  1244. if ((dev.mixer_minor = register_sound_mixer(&dev_fileops, -1)) < 0) {
  1245. printk(KERN_ERR LOGNAME ": Unable to register mixer operations\n");
  1246. unregister_sound_mixer(dev.mixer_minor);
  1247. msnd_unregister(&dev);
  1248. release_region(dev.io, dev.numio);
  1249. free_irq(dev.irq, &dev);
  1250. return dev.mixer_minor;
  1251. }
  1252. dev.ext_midi_dev = dev.hdr_midi_dev = -1;
  1253. disable_irq(dev.irq);
  1254. calibrate_adc(dev.play_sample_rate);
  1255. #ifndef MSND_CLASSIC
  1256. force_recsrc(SOUND_MASK_IMIX);
  1257. #endif
  1258. return 0;
  1259. }
  1260. static void __exit unload_multisound(void)
  1261. {
  1262. release_region(dev.io, dev.numio);
  1263. free_irq(dev.irq, &dev);
  1264. unregister_sound_mixer(dev.mixer_minor);
  1265. unregister_sound_dsp(dev.dsp_minor);
  1266. msnd_unregister(&dev);
  1267. }
  1268. #ifndef MSND_CLASSIC
  1269. /* Pinnacle/Fiji Logical Device Configuration */
  1270. static int __init msnd_write_cfg(int cfg, int reg, int value)
  1271. {
  1272. msnd_outb(reg, cfg);
  1273. msnd_outb(value, cfg + 1);
  1274. if (value != msnd_inb(cfg + 1)) {
  1275. printk(KERN_ERR LOGNAME ": msnd_write_cfg: I/O error\n");
  1276. return -EIO;
  1277. }
  1278. return 0;
  1279. }
  1280. static int __init msnd_write_cfg_io0(int cfg, int num, WORD io)
  1281. {
  1282. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1283. return -EIO;
  1284. if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  1285. return -EIO;
  1286. if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  1287. return -EIO;
  1288. return 0;
  1289. }
  1290. static int __init msnd_write_cfg_io1(int cfg, int num, WORD io)
  1291. {
  1292. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1293. return -EIO;
  1294. if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  1295. return -EIO;
  1296. if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  1297. return -EIO;
  1298. return 0;
  1299. }
  1300. static int __init msnd_write_cfg_irq(int cfg, int num, WORD irq)
  1301. {
  1302. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1303. return -EIO;
  1304. if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  1305. return -EIO;
  1306. if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  1307. return -EIO;
  1308. return 0;
  1309. }
  1310. static int __init msnd_write_cfg_mem(int cfg, int num, int mem)
  1311. {
  1312. WORD wmem;
  1313. mem >>= 8;
  1314. mem &= 0xfff;
  1315. wmem = (WORD)mem;
  1316. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1317. return -EIO;
  1318. if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  1319. return -EIO;
  1320. if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  1321. return -EIO;
  1322. if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
  1323. return -EIO;
  1324. return 0;
  1325. }
  1326. static int __init msnd_activate_logical(int cfg, int num)
  1327. {
  1328. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1329. return -EIO;
  1330. if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  1331. return -EIO;
  1332. return 0;
  1333. }
  1334. static int __init msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
  1335. {
  1336. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1337. return -EIO;
  1338. if (msnd_write_cfg_io0(cfg, num, io0))
  1339. return -EIO;
  1340. if (msnd_write_cfg_io1(cfg, num, io1))
  1341. return -EIO;
  1342. if (msnd_write_cfg_irq(cfg, num, irq))
  1343. return -EIO;
  1344. if (msnd_write_cfg_mem(cfg, num, mem))
  1345. return -EIO;
  1346. if (msnd_activate_logical(cfg, num))
  1347. return -EIO;
  1348. return 0;
  1349. }
  1350. typedef struct msnd_pinnacle_cfg_device {
  1351. WORD io0, io1, irq;
  1352. int mem;
  1353. } msnd_pinnacle_cfg_t[4];
  1354. static int __init msnd_pinnacle_cfg_devices(int cfg, int reset, msnd_pinnacle_cfg_t device)
  1355. {
  1356. int i;
  1357. /* Reset devices if told to */
  1358. if (reset) {
  1359. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  1360. for (i = 0; i < 4; ++i)
  1361. if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  1362. return -EIO;
  1363. }
  1364. /* Configure specified devices */
  1365. for (i = 0; i < 4; ++i) {
  1366. switch (i) {
  1367. case 0: /* DSP */
  1368. if (!(device[i].io0 && device[i].irq && device[i].mem))
  1369. continue;
  1370. break;
  1371. case 1: /* MPU */
  1372. if (!(device[i].io0 && device[i].irq))
  1373. continue;
  1374. printk(KERN_INFO LOGNAME
  1375. ": Configuring MPU to I/O 0x%x IRQ %d\n",
  1376. device[i].io0, device[i].irq);
  1377. break;
  1378. case 2: /* IDE */
  1379. if (!(device[i].io0 && device[i].io1 && device[i].irq))
  1380. continue;
  1381. printk(KERN_INFO LOGNAME
  1382. ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
  1383. device[i].io0, device[i].io1, device[i].irq);
  1384. break;
  1385. case 3: /* Joystick */
  1386. if (!(device[i].io0))
  1387. continue;
  1388. printk(KERN_INFO LOGNAME
  1389. ": Configuring joystick to I/O 0x%x\n",
  1390. device[i].io0);
  1391. break;
  1392. }
  1393. /* Configure the device */
  1394. if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
  1395. return -EIO;
  1396. }
  1397. return 0;
  1398. }
  1399. #endif
  1400. #ifdef MODULE
  1401. MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
  1402. MODULE_DESCRIPTION ("Turtle Beach " LONGNAME " Linux Driver");
  1403. MODULE_LICENSE("GPL");
  1404. static int io __initdata = -1;
  1405. static int irq __initdata = -1;
  1406. static int mem __initdata = -1;
  1407. static int write_ndelay __initdata = -1;
  1408. #ifndef MSND_CLASSIC
  1409. /* Pinnacle/Fiji non-PnP Config Port */
  1410. static int cfg __initdata = -1;
  1411. /* Extra Peripheral Configuration */
  1412. static int reset __initdata = 0;
  1413. static int mpu_io __initdata = 0;
  1414. static int mpu_irq __initdata = 0;
  1415. static int ide_io0 __initdata = 0;
  1416. static int ide_io1 __initdata = 0;
  1417. static int ide_irq __initdata = 0;
  1418. static int joystick_io __initdata = 0;
  1419. /* If we have the digital daugherboard... */
  1420. static bool digital __initdata = false;
  1421. #endif
  1422. static int fifosize __initdata = DEFFIFOSIZE;
  1423. static int calibrate_signal __initdata = 0;
  1424. #else /* not a module */
  1425. static int write_ndelay __initdata = -1;
  1426. #ifdef MSND_CLASSIC
  1427. static int io __initdata = CONFIG_MSNDCLAS_IO;
  1428. static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
  1429. static int mem __initdata = CONFIG_MSNDCLAS_MEM;
  1430. #else /* Pinnacle/Fiji */
  1431. static int io __initdata = CONFIG_MSNDPIN_IO;
  1432. static int irq __initdata = CONFIG_MSNDPIN_IRQ;
  1433. static int mem __initdata = CONFIG_MSNDPIN_MEM;
  1434. /* Pinnacle/Fiji non-PnP Config Port */
  1435. #ifdef CONFIG_MSNDPIN_NONPNP
  1436. # ifndef CONFIG_MSNDPIN_CFG
  1437. # define CONFIG_MSNDPIN_CFG 0x250
  1438. # endif
  1439. #else
  1440. # ifdef CONFIG_MSNDPIN_CFG
  1441. # undef CONFIG_MSNDPIN_CFG
  1442. # endif
  1443. # define CONFIG_MSNDPIN_CFG -1
  1444. #endif
  1445. static int cfg __initdata = CONFIG_MSNDPIN_CFG;
  1446. /* If not a module, we don't need to bother with reset=1 */
  1447. static int reset;
  1448. /* Extra Peripheral Configuration (Default: Disable) */
  1449. #ifndef CONFIG_MSNDPIN_MPU_IO
  1450. # define CONFIG_MSNDPIN_MPU_IO 0
  1451. #endif
  1452. static int mpu_io __initdata = CONFIG_MSNDPIN_MPU_IO;
  1453. #ifndef CONFIG_MSNDPIN_MPU_IRQ
  1454. # define CONFIG_MSNDPIN_MPU_IRQ 0
  1455. #endif
  1456. static int mpu_irq __initdata = CONFIG_MSNDPIN_MPU_IRQ;
  1457. #ifndef CONFIG_MSNDPIN_IDE_IO0
  1458. # define CONFIG_MSNDPIN_IDE_IO0 0
  1459. #endif
  1460. static int ide_io0 __initdata = CONFIG_MSNDPIN_IDE_IO0;
  1461. #ifndef CONFIG_MSNDPIN_IDE_IO1
  1462. # define CONFIG_MSNDPIN_IDE_IO1 0
  1463. #endif
  1464. static int ide_io1 __initdata = CONFIG_MSNDPIN_IDE_IO1;
  1465. #ifndef CONFIG_MSNDPIN_IDE_IRQ
  1466. # define CONFIG_MSNDPIN_IDE_IRQ 0
  1467. #endif
  1468. static int ide_irq __initdata = CONFIG_MSNDPIN_IDE_IRQ;
  1469. #ifndef CONFIG_MSNDPIN_JOYSTICK_IO
  1470. # define CONFIG_MSNDPIN_JOYSTICK_IO 0
  1471. #endif
  1472. static int joystick_io __initdata = CONFIG_MSNDPIN_JOYSTICK_IO;
  1473. /* Have SPDIF (Digital) Daughterboard */
  1474. #ifndef CONFIG_MSNDPIN_DIGITAL
  1475. # define CONFIG_MSNDPIN_DIGITAL 0
  1476. #endif
  1477. static bool digital __initdata = CONFIG_MSNDPIN_DIGITAL;
  1478. #endif /* MSND_CLASSIC */
  1479. #ifndef CONFIG_MSND_FIFOSIZE
  1480. # define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
  1481. #endif
  1482. static int fifosize __initdata = CONFIG_MSND_FIFOSIZE;
  1483. #ifndef CONFIG_MSND_CALSIGNAL
  1484. # define CONFIG_MSND_CALSIGNAL 0
  1485. #endif
  1486. static int
  1487. calibrate_signal __initdata = CONFIG_MSND_CALSIGNAL;
  1488. #endif /* MODULE */
  1489. module_param (io, int, 0);
  1490. module_param (irq, int, 0);
  1491. module_param (mem, int, 0);
  1492. module_param (write_ndelay, int, 0);
  1493. module_param (fifosize, int, 0);
  1494. module_param (calibrate_signal, int, 0);
  1495. #ifndef MSND_CLASSIC
  1496. module_param (digital, bool, 0);
  1497. module_param (cfg, int, 0);
  1498. module_param (reset, int, 0);
  1499. module_param (mpu_io, int, 0);
  1500. module_param (mpu_irq, int, 0);
  1501. module_param (ide_io0, int, 0);
  1502. module_param (ide_io1, int, 0);
  1503. module_param (ide_irq, int, 0);
  1504. module_param (joystick_io, int, 0);
  1505. #endif
  1506. static int __init msnd_init(void)
  1507. {
  1508. int err;
  1509. #ifndef MSND_CLASSIC
  1510. static msnd_pinnacle_cfg_t pinnacle_devs;
  1511. #endif /* MSND_CLASSIC */
  1512. printk(KERN_INFO LOGNAME ": Turtle Beach " LONGNAME " Linux Driver Version "
  1513. VERSION ", Copyright (C) 1998 Andrew Veliath\n");
  1514. if (io == -1 || irq == -1 || mem == -1)
  1515. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  1516. #ifdef MSND_CLASSIC
  1517. if (io == -1 ||
  1518. !(io == 0x290 ||
  1519. io == 0x260 ||
  1520. io == 0x250 ||
  1521. io == 0x240 ||
  1522. io == 0x230 ||
  1523. io == 0x220 ||
  1524. io == 0x210 ||
  1525. io == 0x3e0)) {
  1526. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
  1527. return -EINVAL;
  1528. }
  1529. #else
  1530. if (io == -1 ||
  1531. io < 0x100 ||
  1532. io > 0x3e0 ||
  1533. (io % 0x10) != 0) {
  1534. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
  1535. return -EINVAL;
  1536. }
  1537. #endif /* MSND_CLASSIC */
  1538. if (irq == -1 ||
  1539. !(irq == 5 ||
  1540. irq == 7 ||
  1541. irq == 9 ||
  1542. irq == 10 ||
  1543. irq == 11 ||
  1544. irq == 12)) {
  1545. printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  1546. return -EINVAL;
  1547. }
  1548. if (mem == -1 ||
  1549. !(mem == 0xb0000 ||
  1550. mem == 0xc8000 ||
  1551. mem == 0xd0000 ||
  1552. mem == 0xd8000 ||
  1553. mem == 0xe0000 ||
  1554. mem == 0xe8000)) {
  1555. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  1556. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
  1557. return -EINVAL;
  1558. }
  1559. #ifdef MSND_CLASSIC
  1560. switch (irq) {
  1561. case 5: dev.irqid = HPIRQ_5; break;
  1562. case 7: dev.irqid = HPIRQ_7; break;
  1563. case 9: dev.irqid = HPIRQ_9; break;
  1564. case 10: dev.irqid = HPIRQ_10; break;
  1565. case 11: dev.irqid = HPIRQ_11; break;
  1566. case 12: dev.irqid = HPIRQ_12; break;
  1567. }
  1568. switch (mem) {
  1569. case 0xb0000: dev.memid = HPMEM_B000; break;
  1570. case 0xc8000: dev.memid = HPMEM_C800; break;
  1571. case 0xd0000: dev.memid = HPMEM_D000; break;
  1572. case 0xd8000: dev.memid = HPMEM_D800; break;
  1573. case 0xe0000: dev.memid = HPMEM_E000; break;
  1574. case 0xe8000: dev.memid = HPMEM_E800; break;
  1575. }
  1576. #else
  1577. if (cfg == -1) {
  1578. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  1579. } else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
  1580. printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
  1581. return -EINVAL;
  1582. } else {
  1583. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%x\n", cfg);
  1584. /* DSP */
  1585. pinnacle_devs[0].io0 = io;
  1586. pinnacle_devs[0].irq = irq;
  1587. pinnacle_devs[0].mem = mem;
  1588. /* The following are Pinnacle specific */
  1589. /* MPU */
  1590. pinnacle_devs[1].io0 = mpu_io;
  1591. pinnacle_devs[1].irq = mpu_irq;
  1592. /* IDE */
  1593. pinnacle_devs[2].io0 = ide_io0;
  1594. pinnacle_devs[2].io1 = ide_io1;
  1595. pinnacle_devs[2].irq = ide_irq;
  1596. /* Joystick */
  1597. pinnacle_devs[3].io0 = joystick_io;
  1598. if (!request_region(cfg, 2, "Pinnacle/Fiji Config")) {
  1599. printk(KERN_ERR LOGNAME ": Config port 0x%x conflict\n", cfg);
  1600. return -EIO;
  1601. }
  1602. if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
  1603. printk(KERN_ERR LOGNAME ": Device configuration error\n");
  1604. release_region(cfg, 2);
  1605. return -EIO;
  1606. }
  1607. release_region(cfg, 2);
  1608. }
  1609. #endif /* MSND_CLASSIC */
  1610. if (fifosize < 16)
  1611. fifosize = 16;
  1612. if (fifosize > 1024)
  1613. fifosize = 1024;
  1614. set_default_audio_parameters();
  1615. #ifdef MSND_CLASSIC
  1616. dev.type = msndClassic;
  1617. #else
  1618. dev.type = msndPinnacle;
  1619. #endif
  1620. dev.io = io;
  1621. dev.numio = DSP_NUMIO;
  1622. dev.irq = irq;
  1623. dev.base = ioremap(mem, 0x8000);
  1624. dev.fifosize = fifosize * 1024;
  1625. dev.calibrate_signal = calibrate_signal ? 1 : 0;
  1626. dev.recsrc = 0;
  1627. dev.dspq_data_buff = DSPQ_DATA_BUFF;
  1628. dev.dspq_buff_size = DSPQ_BUFF_SIZE;
  1629. if (write_ndelay == -1)
  1630. write_ndelay = CONFIG_MSND_WRITE_NDELAY;
  1631. if (write_ndelay)
  1632. clear_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
  1633. else
  1634. set_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
  1635. #ifndef MSND_CLASSIC
  1636. if (digital)
  1637. set_bit(F_HAVEDIGITAL, &dev.flags);
  1638. #endif
  1639. init_waitqueue_head(&dev.writeblock);
  1640. init_waitqueue_head(&dev.readblock);
  1641. init_waitqueue_head(&dev.writeflush);
  1642. msnd_fifo_init(&dev.DAPF);
  1643. msnd_fifo_init(&dev.DARF);
  1644. spin_lock_init(&dev.lock);
  1645. printk(KERN_INFO LOGNAME ": %u byte audio FIFOs (x2)\n", dev.fifosize);
  1646. if ((err = msnd_fifo_alloc(&dev.DAPF, dev.fifosize)) < 0) {
  1647. printk(KERN_ERR LOGNAME ": Couldn't allocate write FIFO\n");
  1648. return err;
  1649. }
  1650. if ((err = msnd_fifo_alloc(&dev.DARF, dev.fifosize)) < 0) {
  1651. printk(KERN_ERR LOGNAME ": Couldn't allocate read FIFO\n");
  1652. msnd_fifo_free(&dev.DAPF);
  1653. return err;
  1654. }
  1655. if ((err = probe_multisound()) < 0) {
  1656. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1657. msnd_fifo_free(&dev.DAPF);
  1658. msnd_fifo_free(&dev.DARF);
  1659. return err;
  1660. }
  1661. if ((err = attach_multisound()) < 0) {
  1662. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1663. msnd_fifo_free(&dev.DAPF);
  1664. msnd_fifo_free(&dev.DARF);
  1665. return err;
  1666. }
  1667. return 0;
  1668. }
  1669. static void __exit msdn_cleanup(void)
  1670. {
  1671. unload_multisound();
  1672. msnd_fifo_free(&dev.DAPF);
  1673. msnd_fifo_free(&dev.DARF);
  1674. }
  1675. module_init(msnd_init);
  1676. module_exit(msdn_cleanup);