msnd_pinnacle.c 48 KB

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