msnd_pinnacle.c 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  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->f_path.dentry->d_inode);
  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. if (!(dev.mode & FMODE_WRITE) || !test_bit(F_WRITING, &dev.flags))
  583. return;
  584. set_bit(F_WRITEFLUSH, &dev.flags);
  585. interruptible_sleep_on_timeout(
  586. &dev.writeflush,
  587. get_play_delay_jiffies(dev.DAPF.len));
  588. clear_bit(F_WRITEFLUSH, &dev.flags);
  589. if (!signal_pending(current)) {
  590. current->state = TASK_INTERRUPTIBLE;
  591. schedule_timeout(get_play_delay_jiffies(DAP_BUFF_SIZE));
  592. }
  593. clear_bit(F_WRITING, &dev.flags);
  594. }
  595. static void dsp_halt(struct file *file)
  596. {
  597. if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
  598. clear_bit(F_READING, &dev.flags);
  599. chk_send_dsp_cmd(&dev, HDEX_RECORD_STOP);
  600. msnd_disable_irq(&dev);
  601. if (file) {
  602. printk(KERN_DEBUG LOGNAME ": Stopping read for %p\n", file);
  603. dev.mode &= ~FMODE_READ;
  604. }
  605. clear_bit(F_AUDIO_READ_INUSE, &dev.flags);
  606. }
  607. if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
  608. if (test_bit(F_WRITING, &dev.flags)) {
  609. dsp_write_flush();
  610. chk_send_dsp_cmd(&dev, HDEX_PLAY_STOP);
  611. }
  612. msnd_disable_irq(&dev);
  613. if (file) {
  614. printk(KERN_DEBUG LOGNAME ": Stopping write for %p\n", file);
  615. dev.mode &= ~FMODE_WRITE;
  616. }
  617. clear_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
  618. }
  619. }
  620. static int dsp_release(struct file *file)
  621. {
  622. dsp_halt(file);
  623. return 0;
  624. }
  625. static int dsp_open(struct file *file)
  626. {
  627. if ((file ? file->f_mode : dev.mode) & FMODE_WRITE) {
  628. set_bit(F_AUDIO_WRITE_INUSE, &dev.flags);
  629. clear_bit(F_WRITING, &dev.flags);
  630. msnd_fifo_make_empty(&dev.DAPF);
  631. reset_play_queue();
  632. if (file) {
  633. printk(KERN_DEBUG LOGNAME ": Starting write for %p\n", file);
  634. dev.mode |= FMODE_WRITE;
  635. }
  636. msnd_enable_irq(&dev);
  637. }
  638. if ((file ? file->f_mode : dev.mode) & FMODE_READ) {
  639. set_bit(F_AUDIO_READ_INUSE, &dev.flags);
  640. clear_bit(F_READING, &dev.flags);
  641. msnd_fifo_make_empty(&dev.DARF);
  642. reset_record_queue();
  643. if (file) {
  644. printk(KERN_DEBUG LOGNAME ": Starting read for %p\n", file);
  645. dev.mode |= FMODE_READ;
  646. }
  647. msnd_enable_irq(&dev);
  648. }
  649. return 0;
  650. }
  651. static void set_default_play_audio_parameters(void)
  652. {
  653. dev.play_sample_size = DEFSAMPLESIZE;
  654. dev.play_sample_rate = DEFSAMPLERATE;
  655. dev.play_channels = DEFCHANNELS;
  656. }
  657. static void set_default_rec_audio_parameters(void)
  658. {
  659. dev.rec_sample_size = DEFSAMPLESIZE;
  660. dev.rec_sample_rate = DEFSAMPLERATE;
  661. dev.rec_channels = DEFCHANNELS;
  662. }
  663. static void set_default_audio_parameters(void)
  664. {
  665. set_default_play_audio_parameters();
  666. set_default_rec_audio_parameters();
  667. }
  668. static int dev_open(struct inode *inode, struct file *file)
  669. {
  670. int minor = iminor(inode);
  671. int err = 0;
  672. mutex_lock(&msnd_pinnacle_mutex);
  673. if (minor == dev.dsp_minor) {
  674. if ((file->f_mode & FMODE_WRITE &&
  675. test_bit(F_AUDIO_WRITE_INUSE, &dev.flags)) ||
  676. (file->f_mode & FMODE_READ &&
  677. test_bit(F_AUDIO_READ_INUSE, &dev.flags))) {
  678. err = -EBUSY;
  679. goto out;
  680. }
  681. if ((err = dsp_open(file)) >= 0) {
  682. dev.nresets = 0;
  683. if (file->f_mode & FMODE_WRITE) {
  684. set_default_play_audio_parameters();
  685. if (!test_bit(F_DISABLE_WRITE_NDELAY, &dev.flags))
  686. dev.play_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
  687. else
  688. dev.play_ndelay = 0;
  689. }
  690. if (file->f_mode & FMODE_READ) {
  691. set_default_rec_audio_parameters();
  692. dev.rec_ndelay = (file->f_flags & O_NDELAY) ? 1 : 0;
  693. }
  694. }
  695. }
  696. else if (minor == dev.mixer_minor) {
  697. /* nothing */
  698. } else
  699. err = -EINVAL;
  700. out:
  701. mutex_unlock(&msnd_pinnacle_mutex);
  702. return err;
  703. }
  704. static int dev_release(struct inode *inode, struct file *file)
  705. {
  706. int minor = iminor(inode);
  707. int err = 0;
  708. mutex_lock(&msnd_pinnacle_mutex);
  709. if (minor == dev.dsp_minor)
  710. err = dsp_release(file);
  711. else if (minor == dev.mixer_minor) {
  712. /* nothing */
  713. } else
  714. err = -EINVAL;
  715. mutex_unlock(&msnd_pinnacle_mutex);
  716. return err;
  717. }
  718. static __inline__ int pack_DARQ_to_DARF(register int bank)
  719. {
  720. register int size, timeout = 3;
  721. register WORD wTmp;
  722. LPDAQD DAQD;
  723. /* Increment the tail and check for queue wrap */
  724. wTmp = readw(dev.DARQ + JQS_wTail) + PCTODSP_OFFSET(DAQDS__size);
  725. if (wTmp > readw(dev.DARQ + JQS_wSize))
  726. wTmp = 0;
  727. while (wTmp == readw(dev.DARQ + JQS_wHead) && timeout--)
  728. udelay(1);
  729. writew(wTmp, dev.DARQ + JQS_wTail);
  730. /* Get our digital audio queue struct */
  731. DAQD = bank * DAQDS__size + dev.base + DARQ_DATA_BUFF;
  732. /* Get length of data */
  733. size = readw(DAQD + DAQDS_wSize);
  734. /* Read data from the head (unprotected bank 1 access okay
  735. since this is only called inside an interrupt) */
  736. msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
  737. msnd_fifo_write_io(
  738. &dev.DARF,
  739. dev.base + bank * DAR_BUFF_SIZE,
  740. size);
  741. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  742. return 1;
  743. }
  744. static __inline__ int pack_DAPF_to_DAPQ(register int start)
  745. {
  746. register WORD DAPQ_tail;
  747. register int protect = start, nbanks = 0;
  748. LPDAQD DAQD;
  749. DAPQ_tail = readw(dev.DAPQ + JQS_wTail);
  750. while (DAPQ_tail != readw(dev.DAPQ + JQS_wHead) || start) {
  751. register int bank_num = DAPQ_tail / PCTODSP_OFFSET(DAQDS__size);
  752. register int n;
  753. unsigned long flags;
  754. /* Write the data to the new tail */
  755. if (protect) {
  756. /* Critical section: protect fifo in non-interrupt */
  757. spin_lock_irqsave(&dev.lock, flags);
  758. n = msnd_fifo_read_io(
  759. &dev.DAPF,
  760. dev.base + bank_num * DAP_BUFF_SIZE,
  761. DAP_BUFF_SIZE);
  762. spin_unlock_irqrestore(&dev.lock, flags);
  763. } else {
  764. n = msnd_fifo_read_io(
  765. &dev.DAPF,
  766. dev.base + bank_num * DAP_BUFF_SIZE,
  767. DAP_BUFF_SIZE);
  768. }
  769. if (!n)
  770. break;
  771. if (start)
  772. start = 0;
  773. /* Get our digital audio queue struct */
  774. DAQD = bank_num * DAQDS__size + dev.base + DAPQ_DATA_BUFF;
  775. /* Write size of this bank */
  776. writew(n, DAQD + DAQDS_wSize);
  777. ++nbanks;
  778. /* Then advance the tail */
  779. DAPQ_tail = (++bank_num % 3) * PCTODSP_OFFSET(DAQDS__size);
  780. writew(DAPQ_tail, dev.DAPQ + JQS_wTail);
  781. /* Tell the DSP to play the bank */
  782. msnd_send_dsp_cmd(&dev, HDEX_PLAY_START);
  783. }
  784. return nbanks;
  785. }
  786. static int dsp_read(char __user *buf, size_t len)
  787. {
  788. int count = len;
  789. char *page = (char *)__get_free_page(GFP_KERNEL);
  790. if (!page)
  791. return -ENOMEM;
  792. while (count > 0) {
  793. int n, k;
  794. unsigned long flags;
  795. k = PAGE_SIZE;
  796. if (k > count)
  797. k = count;
  798. /* Critical section: protect fifo in non-interrupt */
  799. spin_lock_irqsave(&dev.lock, flags);
  800. n = msnd_fifo_read(&dev.DARF, page, k);
  801. spin_unlock_irqrestore(&dev.lock, flags);
  802. if (copy_to_user(buf, page, n)) {
  803. free_page((unsigned long)page);
  804. return -EFAULT;
  805. }
  806. buf += n;
  807. count -= n;
  808. if (n == k && count)
  809. continue;
  810. if (!test_bit(F_READING, &dev.flags) && dev.mode & FMODE_READ) {
  811. dev.last_recbank = -1;
  812. if (chk_send_dsp_cmd(&dev, HDEX_RECORD_START) == 0)
  813. set_bit(F_READING, &dev.flags);
  814. }
  815. if (dev.rec_ndelay) {
  816. free_page((unsigned long)page);
  817. return count == len ? -EAGAIN : len - count;
  818. }
  819. if (count > 0) {
  820. set_bit(F_READBLOCK, &dev.flags);
  821. if (!interruptible_sleep_on_timeout(
  822. &dev.readblock,
  823. get_rec_delay_jiffies(DAR_BUFF_SIZE)))
  824. clear_bit(F_READING, &dev.flags);
  825. clear_bit(F_READBLOCK, &dev.flags);
  826. if (signal_pending(current)) {
  827. free_page((unsigned long)page);
  828. return -EINTR;
  829. }
  830. }
  831. }
  832. free_page((unsigned long)page);
  833. return len - count;
  834. }
  835. static int dsp_write(const char __user *buf, size_t len)
  836. {
  837. int count = len;
  838. char *page = (char *)__get_free_page(GFP_KERNEL);
  839. if (!page)
  840. return -ENOMEM;
  841. while (count > 0) {
  842. int n, k;
  843. unsigned long flags;
  844. k = PAGE_SIZE;
  845. if (k > count)
  846. k = count;
  847. if (copy_from_user(page, buf, k)) {
  848. free_page((unsigned long)page);
  849. return -EFAULT;
  850. }
  851. /* Critical section: protect fifo in non-interrupt */
  852. spin_lock_irqsave(&dev.lock, flags);
  853. n = msnd_fifo_write(&dev.DAPF, page, k);
  854. spin_unlock_irqrestore(&dev.lock, flags);
  855. buf += n;
  856. count -= n;
  857. if (count && n == k)
  858. continue;
  859. if (!test_bit(F_WRITING, &dev.flags) && (dev.mode & FMODE_WRITE)) {
  860. dev.last_playbank = -1;
  861. if (pack_DAPF_to_DAPQ(1) > 0)
  862. set_bit(F_WRITING, &dev.flags);
  863. }
  864. if (dev.play_ndelay) {
  865. free_page((unsigned long)page);
  866. return count == len ? -EAGAIN : len - count;
  867. }
  868. if (count > 0) {
  869. set_bit(F_WRITEBLOCK, &dev.flags);
  870. interruptible_sleep_on_timeout(
  871. &dev.writeblock,
  872. get_play_delay_jiffies(DAP_BUFF_SIZE));
  873. clear_bit(F_WRITEBLOCK, &dev.flags);
  874. if (signal_pending(current)) {
  875. free_page((unsigned long)page);
  876. return -EINTR;
  877. }
  878. }
  879. }
  880. free_page((unsigned long)page);
  881. return len - count;
  882. }
  883. static ssize_t dev_read(struct file *file, char __user *buf, size_t count, loff_t *off)
  884. {
  885. int minor = iminor(file->f_path.dentry->d_inode);
  886. if (minor == dev.dsp_minor)
  887. return dsp_read(buf, count);
  888. else
  889. return -EINVAL;
  890. }
  891. static ssize_t dev_write(struct file *file, const char __user *buf, size_t count, loff_t *off)
  892. {
  893. int minor = iminor(file->f_path.dentry->d_inode);
  894. if (minor == dev.dsp_minor)
  895. return dsp_write(buf, count);
  896. else
  897. return -EINVAL;
  898. }
  899. static __inline__ void eval_dsp_msg(register WORD wMessage)
  900. {
  901. switch (HIBYTE(wMessage)) {
  902. case HIMT_PLAY_DONE:
  903. if (dev.last_playbank == LOBYTE(wMessage) || !test_bit(F_WRITING, &dev.flags))
  904. break;
  905. dev.last_playbank = LOBYTE(wMessage);
  906. if (pack_DAPF_to_DAPQ(0) <= 0) {
  907. if (!test_bit(F_WRITEBLOCK, &dev.flags)) {
  908. if (test_and_clear_bit(F_WRITEFLUSH, &dev.flags))
  909. wake_up_interruptible(&dev.writeflush);
  910. }
  911. clear_bit(F_WRITING, &dev.flags);
  912. }
  913. if (test_bit(F_WRITEBLOCK, &dev.flags))
  914. wake_up_interruptible(&dev.writeblock);
  915. break;
  916. case HIMT_RECORD_DONE:
  917. if (dev.last_recbank == LOBYTE(wMessage))
  918. break;
  919. dev.last_recbank = LOBYTE(wMessage);
  920. pack_DARQ_to_DARF(dev.last_recbank);
  921. if (test_bit(F_READBLOCK, &dev.flags))
  922. wake_up_interruptible(&dev.readblock);
  923. break;
  924. case HIMT_DSP:
  925. switch (LOBYTE(wMessage)) {
  926. #ifndef MSND_CLASSIC
  927. case HIDSP_PLAY_UNDER:
  928. #endif
  929. case HIDSP_INT_PLAY_UNDER:
  930. /* printk(KERN_DEBUG LOGNAME ": Play underflow\n"); */
  931. clear_bit(F_WRITING, &dev.flags);
  932. break;
  933. case HIDSP_INT_RECORD_OVER:
  934. /* printk(KERN_DEBUG LOGNAME ": Record overflow\n"); */
  935. clear_bit(F_READING, &dev.flags);
  936. break;
  937. default:
  938. /* printk(KERN_DEBUG LOGNAME ": DSP message %d 0x%02x\n",
  939. LOBYTE(wMessage), LOBYTE(wMessage)); */
  940. break;
  941. }
  942. break;
  943. case HIMT_MIDI_IN_UCHAR:
  944. if (dev.midi_in_interrupt)
  945. (*dev.midi_in_interrupt)(&dev);
  946. break;
  947. default:
  948. /* printk(KERN_DEBUG LOGNAME ": HIMT message %d 0x%02x\n", HIBYTE(wMessage), HIBYTE(wMessage)); */
  949. break;
  950. }
  951. }
  952. static irqreturn_t intr(int irq, void *dev_id)
  953. {
  954. /* Send ack to DSP */
  955. msnd_inb(dev.io + HP_RXL);
  956. /* Evaluate queued DSP messages */
  957. while (readw(dev.DSPQ + JQS_wTail) != readw(dev.DSPQ + JQS_wHead)) {
  958. register WORD wTmp;
  959. eval_dsp_msg(readw(dev.pwDSPQData + 2*readw(dev.DSPQ + JQS_wHead)));
  960. if ((wTmp = readw(dev.DSPQ + JQS_wHead) + 1) > readw(dev.DSPQ + JQS_wSize))
  961. writew(0, dev.DSPQ + JQS_wHead);
  962. else
  963. writew(wTmp, dev.DSPQ + JQS_wHead);
  964. }
  965. return IRQ_HANDLED;
  966. }
  967. static const struct file_operations dev_fileops = {
  968. .owner = THIS_MODULE,
  969. .read = dev_read,
  970. .write = dev_write,
  971. .unlocked_ioctl = dev_ioctl,
  972. .open = dev_open,
  973. .release = dev_release,
  974. .llseek = noop_llseek,
  975. };
  976. static int reset_dsp(void)
  977. {
  978. int timeout = 100;
  979. msnd_outb(HPDSPRESET_ON, dev.io + HP_DSPR);
  980. mdelay(1);
  981. #ifndef MSND_CLASSIC
  982. dev.info = msnd_inb(dev.io + HP_INFO);
  983. #endif
  984. msnd_outb(HPDSPRESET_OFF, dev.io + HP_DSPR);
  985. mdelay(1);
  986. while (timeout-- > 0) {
  987. if (msnd_inb(dev.io + HP_CVR) == HP_CVR_DEF)
  988. return 0;
  989. mdelay(1);
  990. }
  991. printk(KERN_ERR LOGNAME ": Cannot reset DSP\n");
  992. return -EIO;
  993. }
  994. static int __init probe_multisound(void)
  995. {
  996. #ifndef MSND_CLASSIC
  997. char *xv, *rev = NULL;
  998. char *pin = "Pinnacle", *fiji = "Fiji";
  999. char *pinfiji = "Pinnacle/Fiji";
  1000. #endif
  1001. if (!request_region(dev.io, dev.numio, "probing")) {
  1002. printk(KERN_ERR LOGNAME ": I/O port conflict\n");
  1003. return -ENODEV;
  1004. }
  1005. if (reset_dsp() < 0) {
  1006. release_region(dev.io, dev.numio);
  1007. return -ENODEV;
  1008. }
  1009. #ifdef MSND_CLASSIC
  1010. dev.name = "Classic/Tahiti/Monterey";
  1011. printk(KERN_INFO LOGNAME ": %s, "
  1012. #else
  1013. switch (dev.info >> 4) {
  1014. case 0xf: xv = "<= 1.15"; break;
  1015. case 0x1: xv = "1.18/1.2"; break;
  1016. case 0x2: xv = "1.3"; break;
  1017. case 0x3: xv = "1.4"; break;
  1018. default: xv = "unknown"; break;
  1019. }
  1020. switch (dev.info & 0x7) {
  1021. case 0x0: rev = "I"; dev.name = pin; break;
  1022. case 0x1: rev = "F"; dev.name = pin; break;
  1023. case 0x2: rev = "G"; dev.name = pin; break;
  1024. case 0x3: rev = "H"; dev.name = pin; break;
  1025. case 0x4: rev = "E"; dev.name = fiji; break;
  1026. case 0x5: rev = "C"; dev.name = fiji; break;
  1027. case 0x6: rev = "D"; dev.name = fiji; break;
  1028. case 0x7:
  1029. rev = "A-B (Fiji) or A-E (Pinnacle)";
  1030. dev.name = pinfiji;
  1031. break;
  1032. }
  1033. printk(KERN_INFO LOGNAME ": %s revision %s, Xilinx version %s, "
  1034. #endif /* MSND_CLASSIC */
  1035. "I/O 0x%x-0x%x, IRQ %d, memory mapped to %p-%p\n",
  1036. dev.name,
  1037. #ifndef MSND_CLASSIC
  1038. rev, xv,
  1039. #endif
  1040. dev.io, dev.io + dev.numio - 1,
  1041. dev.irq,
  1042. dev.base, dev.base + 0x7fff);
  1043. release_region(dev.io, dev.numio);
  1044. return 0;
  1045. }
  1046. static int init_sma(void)
  1047. {
  1048. static int initted;
  1049. WORD mastVolLeft, mastVolRight;
  1050. unsigned long flags;
  1051. #ifdef MSND_CLASSIC
  1052. msnd_outb(dev.memid, dev.io + HP_MEMM);
  1053. #endif
  1054. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1055. if (initted) {
  1056. mastVolLeft = readw(dev.SMA + SMA_wCurrMastVolLeft);
  1057. mastVolRight = readw(dev.SMA + SMA_wCurrMastVolRight);
  1058. } else
  1059. mastVolLeft = mastVolRight = 0;
  1060. memset_io(dev.base, 0, 0x8000);
  1061. /* Critical section: bank 1 access */
  1062. spin_lock_irqsave(&dev.lock, flags);
  1063. msnd_outb(HPBLKSEL_1, dev.io + HP_BLKS);
  1064. memset_io(dev.base, 0, 0x8000);
  1065. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1066. spin_unlock_irqrestore(&dev.lock, flags);
  1067. dev.pwDSPQData = (dev.base + DSPQ_DATA_BUFF);
  1068. dev.pwMODQData = (dev.base + MODQ_DATA_BUFF);
  1069. dev.pwMIDQData = (dev.base + MIDQ_DATA_BUFF);
  1070. /* Motorola 56k shared memory base */
  1071. dev.SMA = dev.base + SMA_STRUCT_START;
  1072. /* Digital audio play queue */
  1073. dev.DAPQ = dev.base + DAPQ_OFFSET;
  1074. msnd_init_queue(dev.DAPQ, DAPQ_DATA_BUFF, DAPQ_BUFF_SIZE);
  1075. /* Digital audio record queue */
  1076. dev.DARQ = dev.base + DARQ_OFFSET;
  1077. msnd_init_queue(dev.DARQ, DARQ_DATA_BUFF, DARQ_BUFF_SIZE);
  1078. /* MIDI out queue */
  1079. dev.MODQ = dev.base + MODQ_OFFSET;
  1080. msnd_init_queue(dev.MODQ, MODQ_DATA_BUFF, MODQ_BUFF_SIZE);
  1081. /* MIDI in queue */
  1082. dev.MIDQ = dev.base + MIDQ_OFFSET;
  1083. msnd_init_queue(dev.MIDQ, MIDQ_DATA_BUFF, MIDQ_BUFF_SIZE);
  1084. /* DSP -> host message queue */
  1085. dev.DSPQ = dev.base + DSPQ_OFFSET;
  1086. msnd_init_queue(dev.DSPQ, DSPQ_DATA_BUFF, DSPQ_BUFF_SIZE);
  1087. /* Setup some DSP values */
  1088. #ifndef MSND_CLASSIC
  1089. writew(1, dev.SMA + SMA_wCurrPlayFormat);
  1090. writew(dev.play_sample_size, dev.SMA + SMA_wCurrPlaySampleSize);
  1091. writew(dev.play_channels, dev.SMA + SMA_wCurrPlayChannels);
  1092. writew(dev.play_sample_rate, dev.SMA + SMA_wCurrPlaySampleRate);
  1093. #endif
  1094. writew(dev.play_sample_rate, dev.SMA + SMA_wCalFreqAtoD);
  1095. writew(mastVolLeft, dev.SMA + SMA_wCurrMastVolLeft);
  1096. writew(mastVolRight, dev.SMA + SMA_wCurrMastVolRight);
  1097. #ifndef MSND_CLASSIC
  1098. writel(0x00010000, dev.SMA + SMA_dwCurrPlayPitch);
  1099. writel(0x00000001, dev.SMA + SMA_dwCurrPlayRate);
  1100. #endif
  1101. writew(0x303, dev.SMA + SMA_wCurrInputTagBits);
  1102. initted = 1;
  1103. return 0;
  1104. }
  1105. static int __init calibrate_adc(WORD srate)
  1106. {
  1107. writew(srate, dev.SMA + SMA_wCalFreqAtoD);
  1108. if (dev.calibrate_signal == 0)
  1109. writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
  1110. | 0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
  1111. else
  1112. writew(readw(dev.SMA + SMA_wCurrHostStatusFlags)
  1113. & ~0x0001, dev.SMA + SMA_wCurrHostStatusFlags);
  1114. if (msnd_send_word(&dev, 0, 0, HDEXAR_CAL_A_TO_D) == 0 &&
  1115. chk_send_dsp_cmd(&dev, HDEX_AUX_REQ) == 0) {
  1116. current->state = TASK_INTERRUPTIBLE;
  1117. schedule_timeout(HZ / 3);
  1118. return 0;
  1119. }
  1120. printk(KERN_WARNING LOGNAME ": ADC calibration failed\n");
  1121. return -EIO;
  1122. }
  1123. static int upload_dsp_code(void)
  1124. {
  1125. int ret = 0;
  1126. msnd_outb(HPBLKSEL_0, dev.io + HP_BLKS);
  1127. #ifndef HAVE_DSPCODEH
  1128. INITCODESIZE = mod_firmware_load(INITCODEFILE, &INITCODE);
  1129. if (!INITCODE) {
  1130. printk(KERN_ERR LOGNAME ": Error loading " INITCODEFILE);
  1131. return -EBUSY;
  1132. }
  1133. PERMCODESIZE = mod_firmware_load(PERMCODEFILE, &PERMCODE);
  1134. if (!PERMCODE) {
  1135. printk(KERN_ERR LOGNAME ": Error loading " PERMCODEFILE);
  1136. vfree(INITCODE);
  1137. return -EBUSY;
  1138. }
  1139. #endif
  1140. memcpy_toio(dev.base, PERMCODE, PERMCODESIZE);
  1141. if (msnd_upload_host(&dev, INITCODE, INITCODESIZE) < 0) {
  1142. printk(KERN_WARNING LOGNAME ": Error uploading to DSP\n");
  1143. ret = -ENODEV;
  1144. goto out;
  1145. }
  1146. #ifdef HAVE_DSPCODEH
  1147. printk(KERN_INFO LOGNAME ": DSP firmware uploaded (resident)\n");
  1148. #else
  1149. printk(KERN_INFO LOGNAME ": DSP firmware uploaded\n");
  1150. #endif
  1151. out:
  1152. #ifndef HAVE_DSPCODEH
  1153. vfree(INITCODE);
  1154. vfree(PERMCODE);
  1155. #endif
  1156. return ret;
  1157. }
  1158. #ifdef MSND_CLASSIC
  1159. static void reset_proteus(void)
  1160. {
  1161. msnd_outb(HPPRORESET_ON, dev.io + HP_PROR);
  1162. mdelay(TIME_PRO_RESET);
  1163. msnd_outb(HPPRORESET_OFF, dev.io + HP_PROR);
  1164. mdelay(TIME_PRO_RESET_DONE);
  1165. }
  1166. #endif
  1167. static int initialize(void)
  1168. {
  1169. int err, timeout;
  1170. #ifdef MSND_CLASSIC
  1171. msnd_outb(HPWAITSTATE_0, dev.io + HP_WAIT);
  1172. msnd_outb(HPBITMODE_16, dev.io + HP_BITM);
  1173. reset_proteus();
  1174. #endif
  1175. if ((err = init_sma()) < 0) {
  1176. printk(KERN_WARNING LOGNAME ": Cannot initialize SMA\n");
  1177. return err;
  1178. }
  1179. if ((err = reset_dsp()) < 0)
  1180. return err;
  1181. if ((err = upload_dsp_code()) < 0) {
  1182. printk(KERN_WARNING LOGNAME ": Cannot upload DSP code\n");
  1183. return err;
  1184. }
  1185. timeout = 200;
  1186. while (readw(dev.base)) {
  1187. mdelay(1);
  1188. if (!timeout--) {
  1189. printk(KERN_DEBUG LOGNAME ": DSP reset timeout\n");
  1190. return -EIO;
  1191. }
  1192. }
  1193. mixer_setup();
  1194. return 0;
  1195. }
  1196. static int dsp_full_reset(void)
  1197. {
  1198. int rv;
  1199. if (test_bit(F_RESETTING, &dev.flags) || ++dev.nresets > 10)
  1200. return 0;
  1201. set_bit(F_RESETTING, &dev.flags);
  1202. printk(KERN_INFO LOGNAME ": DSP reset\n");
  1203. dsp_halt(NULL); /* Unconditionally halt */
  1204. if ((rv = initialize()))
  1205. printk(KERN_WARNING LOGNAME ": DSP reset failed\n");
  1206. force_recsrc(dev.recsrc);
  1207. dsp_open(NULL);
  1208. clear_bit(F_RESETTING, &dev.flags);
  1209. return rv;
  1210. }
  1211. static int __init attach_multisound(void)
  1212. {
  1213. int err;
  1214. if ((err = request_irq(dev.irq, intr, 0, dev.name, &dev)) < 0) {
  1215. printk(KERN_ERR LOGNAME ": Couldn't grab IRQ %d\n", dev.irq);
  1216. return err;
  1217. }
  1218. if (request_region(dev.io, dev.numio, dev.name) == NULL) {
  1219. free_irq(dev.irq, &dev);
  1220. return -EBUSY;
  1221. }
  1222. err = dsp_full_reset();
  1223. if (err < 0) {
  1224. release_region(dev.io, dev.numio);
  1225. free_irq(dev.irq, &dev);
  1226. return err;
  1227. }
  1228. if ((err = msnd_register(&dev)) < 0) {
  1229. printk(KERN_ERR LOGNAME ": Unable to register MultiSound\n");
  1230. release_region(dev.io, dev.numio);
  1231. free_irq(dev.irq, &dev);
  1232. return err;
  1233. }
  1234. if ((dev.dsp_minor = register_sound_dsp(&dev_fileops, -1)) < 0) {
  1235. printk(KERN_ERR LOGNAME ": Unable to register DSP operations\n");
  1236. msnd_unregister(&dev);
  1237. release_region(dev.io, dev.numio);
  1238. free_irq(dev.irq, &dev);
  1239. return dev.dsp_minor;
  1240. }
  1241. if ((dev.mixer_minor = register_sound_mixer(&dev_fileops, -1)) < 0) {
  1242. printk(KERN_ERR LOGNAME ": Unable to register mixer operations\n");
  1243. unregister_sound_mixer(dev.mixer_minor);
  1244. msnd_unregister(&dev);
  1245. release_region(dev.io, dev.numio);
  1246. free_irq(dev.irq, &dev);
  1247. return dev.mixer_minor;
  1248. }
  1249. dev.ext_midi_dev = dev.hdr_midi_dev = -1;
  1250. disable_irq(dev.irq);
  1251. calibrate_adc(dev.play_sample_rate);
  1252. #ifndef MSND_CLASSIC
  1253. force_recsrc(SOUND_MASK_IMIX);
  1254. #endif
  1255. return 0;
  1256. }
  1257. static void __exit unload_multisound(void)
  1258. {
  1259. release_region(dev.io, dev.numio);
  1260. free_irq(dev.irq, &dev);
  1261. unregister_sound_mixer(dev.mixer_minor);
  1262. unregister_sound_dsp(dev.dsp_minor);
  1263. msnd_unregister(&dev);
  1264. }
  1265. #ifndef MSND_CLASSIC
  1266. /* Pinnacle/Fiji Logical Device Configuration */
  1267. static int __init msnd_write_cfg(int cfg, int reg, int value)
  1268. {
  1269. msnd_outb(reg, cfg);
  1270. msnd_outb(value, cfg + 1);
  1271. if (value != msnd_inb(cfg + 1)) {
  1272. printk(KERN_ERR LOGNAME ": msnd_write_cfg: I/O error\n");
  1273. return -EIO;
  1274. }
  1275. return 0;
  1276. }
  1277. static int __init msnd_write_cfg_io0(int cfg, int num, WORD io)
  1278. {
  1279. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1280. return -EIO;
  1281. if (msnd_write_cfg(cfg, IREG_IO0_BASEHI, HIBYTE(io)))
  1282. return -EIO;
  1283. if (msnd_write_cfg(cfg, IREG_IO0_BASELO, LOBYTE(io)))
  1284. return -EIO;
  1285. return 0;
  1286. }
  1287. static int __init msnd_write_cfg_io1(int cfg, int num, WORD io)
  1288. {
  1289. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1290. return -EIO;
  1291. if (msnd_write_cfg(cfg, IREG_IO1_BASEHI, HIBYTE(io)))
  1292. return -EIO;
  1293. if (msnd_write_cfg(cfg, IREG_IO1_BASELO, LOBYTE(io)))
  1294. return -EIO;
  1295. return 0;
  1296. }
  1297. static int __init msnd_write_cfg_irq(int cfg, int num, WORD irq)
  1298. {
  1299. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1300. return -EIO;
  1301. if (msnd_write_cfg(cfg, IREG_IRQ_NUMBER, LOBYTE(irq)))
  1302. return -EIO;
  1303. if (msnd_write_cfg(cfg, IREG_IRQ_TYPE, IRQTYPE_EDGE))
  1304. return -EIO;
  1305. return 0;
  1306. }
  1307. static int __init msnd_write_cfg_mem(int cfg, int num, int mem)
  1308. {
  1309. WORD wmem;
  1310. mem >>= 8;
  1311. mem &= 0xfff;
  1312. wmem = (WORD)mem;
  1313. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1314. return -EIO;
  1315. if (msnd_write_cfg(cfg, IREG_MEMBASEHI, HIBYTE(wmem)))
  1316. return -EIO;
  1317. if (msnd_write_cfg(cfg, IREG_MEMBASELO, LOBYTE(wmem)))
  1318. return -EIO;
  1319. if (wmem && msnd_write_cfg(cfg, IREG_MEMCONTROL, (MEMTYPE_HIADDR | MEMTYPE_16BIT)))
  1320. return -EIO;
  1321. return 0;
  1322. }
  1323. static int __init msnd_activate_logical(int cfg, int num)
  1324. {
  1325. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1326. return -EIO;
  1327. if (msnd_write_cfg(cfg, IREG_ACTIVATE, LD_ACTIVATE))
  1328. return -EIO;
  1329. return 0;
  1330. }
  1331. static int __init msnd_write_cfg_logical(int cfg, int num, WORD io0, WORD io1, WORD irq, int mem)
  1332. {
  1333. if (msnd_write_cfg(cfg, IREG_LOGDEVICE, num))
  1334. return -EIO;
  1335. if (msnd_write_cfg_io0(cfg, num, io0))
  1336. return -EIO;
  1337. if (msnd_write_cfg_io1(cfg, num, io1))
  1338. return -EIO;
  1339. if (msnd_write_cfg_irq(cfg, num, irq))
  1340. return -EIO;
  1341. if (msnd_write_cfg_mem(cfg, num, mem))
  1342. return -EIO;
  1343. if (msnd_activate_logical(cfg, num))
  1344. return -EIO;
  1345. return 0;
  1346. }
  1347. typedef struct msnd_pinnacle_cfg_device {
  1348. WORD io0, io1, irq;
  1349. int mem;
  1350. } msnd_pinnacle_cfg_t[4];
  1351. static int __init msnd_pinnacle_cfg_devices(int cfg, int reset, msnd_pinnacle_cfg_t device)
  1352. {
  1353. int i;
  1354. /* Reset devices if told to */
  1355. if (reset) {
  1356. printk(KERN_INFO LOGNAME ": Resetting all devices\n");
  1357. for (i = 0; i < 4; ++i)
  1358. if (msnd_write_cfg_logical(cfg, i, 0, 0, 0, 0))
  1359. return -EIO;
  1360. }
  1361. /* Configure specified devices */
  1362. for (i = 0; i < 4; ++i) {
  1363. switch (i) {
  1364. case 0: /* DSP */
  1365. if (!(device[i].io0 && device[i].irq && device[i].mem))
  1366. continue;
  1367. break;
  1368. case 1: /* MPU */
  1369. if (!(device[i].io0 && device[i].irq))
  1370. continue;
  1371. printk(KERN_INFO LOGNAME
  1372. ": Configuring MPU to I/O 0x%x IRQ %d\n",
  1373. device[i].io0, device[i].irq);
  1374. break;
  1375. case 2: /* IDE */
  1376. if (!(device[i].io0 && device[i].io1 && device[i].irq))
  1377. continue;
  1378. printk(KERN_INFO LOGNAME
  1379. ": Configuring IDE to I/O 0x%x, 0x%x IRQ %d\n",
  1380. device[i].io0, device[i].io1, device[i].irq);
  1381. break;
  1382. case 3: /* Joystick */
  1383. if (!(device[i].io0))
  1384. continue;
  1385. printk(KERN_INFO LOGNAME
  1386. ": Configuring joystick to I/O 0x%x\n",
  1387. device[i].io0);
  1388. break;
  1389. }
  1390. /* Configure the device */
  1391. if (msnd_write_cfg_logical(cfg, i, device[i].io0, device[i].io1, device[i].irq, device[i].mem))
  1392. return -EIO;
  1393. }
  1394. return 0;
  1395. }
  1396. #endif
  1397. #ifdef MODULE
  1398. MODULE_AUTHOR ("Andrew Veliath <andrewtv@usa.net>");
  1399. MODULE_DESCRIPTION ("Turtle Beach " LONGNAME " Linux Driver");
  1400. MODULE_LICENSE("GPL");
  1401. static int io __initdata = -1;
  1402. static int irq __initdata = -1;
  1403. static int mem __initdata = -1;
  1404. static int write_ndelay __initdata = -1;
  1405. #ifndef MSND_CLASSIC
  1406. /* Pinnacle/Fiji non-PnP Config Port */
  1407. static int cfg __initdata = -1;
  1408. /* Extra Peripheral Configuration */
  1409. static int reset __initdata = 0;
  1410. static int mpu_io __initdata = 0;
  1411. static int mpu_irq __initdata = 0;
  1412. static int ide_io0 __initdata = 0;
  1413. static int ide_io1 __initdata = 0;
  1414. static int ide_irq __initdata = 0;
  1415. static int joystick_io __initdata = 0;
  1416. /* If we have the digital daugherboard... */
  1417. static bool digital __initdata = false;
  1418. #endif
  1419. static int fifosize __initdata = DEFFIFOSIZE;
  1420. static int calibrate_signal __initdata = 0;
  1421. #else /* not a module */
  1422. static int write_ndelay __initdata = -1;
  1423. #ifdef MSND_CLASSIC
  1424. static int io __initdata = CONFIG_MSNDCLAS_IO;
  1425. static int irq __initdata = CONFIG_MSNDCLAS_IRQ;
  1426. static int mem __initdata = CONFIG_MSNDCLAS_MEM;
  1427. #else /* Pinnacle/Fiji */
  1428. static int io __initdata = CONFIG_MSNDPIN_IO;
  1429. static int irq __initdata = CONFIG_MSNDPIN_IRQ;
  1430. static int mem __initdata = CONFIG_MSNDPIN_MEM;
  1431. /* Pinnacle/Fiji non-PnP Config Port */
  1432. #ifdef CONFIG_MSNDPIN_NONPNP
  1433. # ifndef CONFIG_MSNDPIN_CFG
  1434. # define CONFIG_MSNDPIN_CFG 0x250
  1435. # endif
  1436. #else
  1437. # ifdef CONFIG_MSNDPIN_CFG
  1438. # undef CONFIG_MSNDPIN_CFG
  1439. # endif
  1440. # define CONFIG_MSNDPIN_CFG -1
  1441. #endif
  1442. static int cfg __initdata = CONFIG_MSNDPIN_CFG;
  1443. /* If not a module, we don't need to bother with reset=1 */
  1444. static int reset;
  1445. /* Extra Peripheral Configuration (Default: Disable) */
  1446. #ifndef CONFIG_MSNDPIN_MPU_IO
  1447. # define CONFIG_MSNDPIN_MPU_IO 0
  1448. #endif
  1449. static int mpu_io __initdata = CONFIG_MSNDPIN_MPU_IO;
  1450. #ifndef CONFIG_MSNDPIN_MPU_IRQ
  1451. # define CONFIG_MSNDPIN_MPU_IRQ 0
  1452. #endif
  1453. static int mpu_irq __initdata = CONFIG_MSNDPIN_MPU_IRQ;
  1454. #ifndef CONFIG_MSNDPIN_IDE_IO0
  1455. # define CONFIG_MSNDPIN_IDE_IO0 0
  1456. #endif
  1457. static int ide_io0 __initdata = CONFIG_MSNDPIN_IDE_IO0;
  1458. #ifndef CONFIG_MSNDPIN_IDE_IO1
  1459. # define CONFIG_MSNDPIN_IDE_IO1 0
  1460. #endif
  1461. static int ide_io1 __initdata = CONFIG_MSNDPIN_IDE_IO1;
  1462. #ifndef CONFIG_MSNDPIN_IDE_IRQ
  1463. # define CONFIG_MSNDPIN_IDE_IRQ 0
  1464. #endif
  1465. static int ide_irq __initdata = CONFIG_MSNDPIN_IDE_IRQ;
  1466. #ifndef CONFIG_MSNDPIN_JOYSTICK_IO
  1467. # define CONFIG_MSNDPIN_JOYSTICK_IO 0
  1468. #endif
  1469. static int joystick_io __initdata = CONFIG_MSNDPIN_JOYSTICK_IO;
  1470. /* Have SPDIF (Digital) Daughterboard */
  1471. #ifndef CONFIG_MSNDPIN_DIGITAL
  1472. # define CONFIG_MSNDPIN_DIGITAL 0
  1473. #endif
  1474. static bool digital __initdata = CONFIG_MSNDPIN_DIGITAL;
  1475. #endif /* MSND_CLASSIC */
  1476. #ifndef CONFIG_MSND_FIFOSIZE
  1477. # define CONFIG_MSND_FIFOSIZE DEFFIFOSIZE
  1478. #endif
  1479. static int fifosize __initdata = CONFIG_MSND_FIFOSIZE;
  1480. #ifndef CONFIG_MSND_CALSIGNAL
  1481. # define CONFIG_MSND_CALSIGNAL 0
  1482. #endif
  1483. static int
  1484. calibrate_signal __initdata = CONFIG_MSND_CALSIGNAL;
  1485. #endif /* MODULE */
  1486. module_param (io, int, 0);
  1487. module_param (irq, int, 0);
  1488. module_param (mem, int, 0);
  1489. module_param (write_ndelay, int, 0);
  1490. module_param (fifosize, int, 0);
  1491. module_param (calibrate_signal, int, 0);
  1492. #ifndef MSND_CLASSIC
  1493. module_param (digital, bool, 0);
  1494. module_param (cfg, int, 0);
  1495. module_param (reset, int, 0);
  1496. module_param (mpu_io, int, 0);
  1497. module_param (mpu_irq, int, 0);
  1498. module_param (ide_io0, int, 0);
  1499. module_param (ide_io1, int, 0);
  1500. module_param (ide_irq, int, 0);
  1501. module_param (joystick_io, int, 0);
  1502. #endif
  1503. static int __init msnd_init(void)
  1504. {
  1505. int err;
  1506. #ifndef MSND_CLASSIC
  1507. static msnd_pinnacle_cfg_t pinnacle_devs;
  1508. #endif /* MSND_CLASSIC */
  1509. printk(KERN_INFO LOGNAME ": Turtle Beach " LONGNAME " Linux Driver Version "
  1510. VERSION ", Copyright (C) 1998 Andrew Veliath\n");
  1511. if (io == -1 || irq == -1 || mem == -1)
  1512. printk(KERN_WARNING LOGNAME ": io, irq and mem must be set\n");
  1513. #ifdef MSND_CLASSIC
  1514. if (io == -1 ||
  1515. !(io == 0x290 ||
  1516. io == 0x260 ||
  1517. io == 0x250 ||
  1518. io == 0x240 ||
  1519. io == 0x230 ||
  1520. io == 0x220 ||
  1521. io == 0x210 ||
  1522. io == 0x3e0)) {
  1523. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must be set to 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x290, or 0x3E0\n");
  1524. return -EINVAL;
  1525. }
  1526. #else
  1527. if (io == -1 ||
  1528. io < 0x100 ||
  1529. io > 0x3e0 ||
  1530. (io % 0x10) != 0) {
  1531. printk(KERN_ERR LOGNAME ": \"io\" - DSP I/O base must within the range 0x100 to 0x3E0 and must be evenly divisible by 0x10\n");
  1532. return -EINVAL;
  1533. }
  1534. #endif /* MSND_CLASSIC */
  1535. if (irq == -1 ||
  1536. !(irq == 5 ||
  1537. irq == 7 ||
  1538. irq == 9 ||
  1539. irq == 10 ||
  1540. irq == 11 ||
  1541. irq == 12)) {
  1542. printk(KERN_ERR LOGNAME ": \"irq\" - must be set to 5, 7, 9, 10, 11 or 12\n");
  1543. return -EINVAL;
  1544. }
  1545. if (mem == -1 ||
  1546. !(mem == 0xb0000 ||
  1547. mem == 0xc8000 ||
  1548. mem == 0xd0000 ||
  1549. mem == 0xd8000 ||
  1550. mem == 0xe0000 ||
  1551. mem == 0xe8000)) {
  1552. printk(KERN_ERR LOGNAME ": \"mem\" - must be set to "
  1553. "0xb0000, 0xc8000, 0xd0000, 0xd8000, 0xe0000 or 0xe8000\n");
  1554. return -EINVAL;
  1555. }
  1556. #ifdef MSND_CLASSIC
  1557. switch (irq) {
  1558. case 5: dev.irqid = HPIRQ_5; break;
  1559. case 7: dev.irqid = HPIRQ_7; break;
  1560. case 9: dev.irqid = HPIRQ_9; break;
  1561. case 10: dev.irqid = HPIRQ_10; break;
  1562. case 11: dev.irqid = HPIRQ_11; break;
  1563. case 12: dev.irqid = HPIRQ_12; break;
  1564. }
  1565. switch (mem) {
  1566. case 0xb0000: dev.memid = HPMEM_B000; break;
  1567. case 0xc8000: dev.memid = HPMEM_C800; break;
  1568. case 0xd0000: dev.memid = HPMEM_D000; break;
  1569. case 0xd8000: dev.memid = HPMEM_D800; break;
  1570. case 0xe0000: dev.memid = HPMEM_E000; break;
  1571. case 0xe8000: dev.memid = HPMEM_E800; break;
  1572. }
  1573. #else
  1574. if (cfg == -1) {
  1575. printk(KERN_INFO LOGNAME ": Assuming PnP mode\n");
  1576. } else if (cfg != 0x250 && cfg != 0x260 && cfg != 0x270) {
  1577. printk(KERN_INFO LOGNAME ": Config port must be 0x250, 0x260 or 0x270 (or unspecified for PnP mode)\n");
  1578. return -EINVAL;
  1579. } else {
  1580. printk(KERN_INFO LOGNAME ": Non-PnP mode: configuring at port 0x%x\n", cfg);
  1581. /* DSP */
  1582. pinnacle_devs[0].io0 = io;
  1583. pinnacle_devs[0].irq = irq;
  1584. pinnacle_devs[0].mem = mem;
  1585. /* The following are Pinnacle specific */
  1586. /* MPU */
  1587. pinnacle_devs[1].io0 = mpu_io;
  1588. pinnacle_devs[1].irq = mpu_irq;
  1589. /* IDE */
  1590. pinnacle_devs[2].io0 = ide_io0;
  1591. pinnacle_devs[2].io1 = ide_io1;
  1592. pinnacle_devs[2].irq = ide_irq;
  1593. /* Joystick */
  1594. pinnacle_devs[3].io0 = joystick_io;
  1595. if (!request_region(cfg, 2, "Pinnacle/Fiji Config")) {
  1596. printk(KERN_ERR LOGNAME ": Config port 0x%x conflict\n", cfg);
  1597. return -EIO;
  1598. }
  1599. if (msnd_pinnacle_cfg_devices(cfg, reset, pinnacle_devs)) {
  1600. printk(KERN_ERR LOGNAME ": Device configuration error\n");
  1601. release_region(cfg, 2);
  1602. return -EIO;
  1603. }
  1604. release_region(cfg, 2);
  1605. }
  1606. #endif /* MSND_CLASSIC */
  1607. if (fifosize < 16)
  1608. fifosize = 16;
  1609. if (fifosize > 1024)
  1610. fifosize = 1024;
  1611. set_default_audio_parameters();
  1612. #ifdef MSND_CLASSIC
  1613. dev.type = msndClassic;
  1614. #else
  1615. dev.type = msndPinnacle;
  1616. #endif
  1617. dev.io = io;
  1618. dev.numio = DSP_NUMIO;
  1619. dev.irq = irq;
  1620. dev.base = ioremap(mem, 0x8000);
  1621. dev.fifosize = fifosize * 1024;
  1622. dev.calibrate_signal = calibrate_signal ? 1 : 0;
  1623. dev.recsrc = 0;
  1624. dev.dspq_data_buff = DSPQ_DATA_BUFF;
  1625. dev.dspq_buff_size = DSPQ_BUFF_SIZE;
  1626. if (write_ndelay == -1)
  1627. write_ndelay = CONFIG_MSND_WRITE_NDELAY;
  1628. if (write_ndelay)
  1629. clear_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
  1630. else
  1631. set_bit(F_DISABLE_WRITE_NDELAY, &dev.flags);
  1632. #ifndef MSND_CLASSIC
  1633. if (digital)
  1634. set_bit(F_HAVEDIGITAL, &dev.flags);
  1635. #endif
  1636. init_waitqueue_head(&dev.writeblock);
  1637. init_waitqueue_head(&dev.readblock);
  1638. init_waitqueue_head(&dev.writeflush);
  1639. msnd_fifo_init(&dev.DAPF);
  1640. msnd_fifo_init(&dev.DARF);
  1641. spin_lock_init(&dev.lock);
  1642. printk(KERN_INFO LOGNAME ": %u byte audio FIFOs (x2)\n", dev.fifosize);
  1643. if ((err = msnd_fifo_alloc(&dev.DAPF, dev.fifosize)) < 0) {
  1644. printk(KERN_ERR LOGNAME ": Couldn't allocate write FIFO\n");
  1645. return err;
  1646. }
  1647. if ((err = msnd_fifo_alloc(&dev.DARF, dev.fifosize)) < 0) {
  1648. printk(KERN_ERR LOGNAME ": Couldn't allocate read FIFO\n");
  1649. msnd_fifo_free(&dev.DAPF);
  1650. return err;
  1651. }
  1652. if ((err = probe_multisound()) < 0) {
  1653. printk(KERN_ERR LOGNAME ": Probe failed\n");
  1654. msnd_fifo_free(&dev.DAPF);
  1655. msnd_fifo_free(&dev.DARF);
  1656. return err;
  1657. }
  1658. if ((err = attach_multisound()) < 0) {
  1659. printk(KERN_ERR LOGNAME ": Attach failed\n");
  1660. msnd_fifo_free(&dev.DAPF);
  1661. msnd_fifo_free(&dev.DARF);
  1662. return err;
  1663. }
  1664. return 0;
  1665. }
  1666. static void __exit msdn_cleanup(void)
  1667. {
  1668. unload_multisound();
  1669. msnd_fifo_free(&dev.DAPF);
  1670. msnd_fifo_free(&dev.DARF);
  1671. }
  1672. module_init(msnd_init);
  1673. module_exit(msdn_cleanup);