pss.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. /*
  2. * sound/oss/pss.c
  3. *
  4. * The low level driver for the Personal Sound System (ECHO ESC614).
  5. *
  6. *
  7. * Copyright (C) by Hannu Savolainen 1993-1997
  8. *
  9. * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
  10. * Version 2 (June 1991). See the "COPYING" file distributed with this software
  11. * for more info.
  12. *
  13. *
  14. * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
  15. * Alan Cox modularisation, clean up.
  16. *
  17. * 98-02-21: Vladimir Michl <vladimir.michl@upol.cz>
  18. * Added mixer device for Beethoven ADSP-16 (master volume,
  19. * bass, treble, synth), only for speakers.
  20. * Fixed bug in pss_write (exchange parameters)
  21. * Fixed config port of SB
  22. * Requested two regions for PSS (PSS mixer, PSS config)
  23. * Modified pss_download_boot
  24. * To probe_pss_mss added test for initialize AD1848
  25. * 98-05-28: Vladimir Michl <vladimir.michl@upol.cz>
  26. * Fixed computation of mixer volumes
  27. * 04-05-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
  28. * Added code that allows the user to enable his cdrom and/or
  29. * joystick through the module parameters pss_cdrom_port and
  30. * pss_enable_joystick. pss_cdrom_port takes a port address as its
  31. * argument. pss_enable_joystick takes either a 0 or a non-0 as its
  32. * argument.
  33. * 04-06-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
  34. * Separated some code into new functions for easier reuse.
  35. * Cleaned up and streamlined new code. Added code to allow a user
  36. * to only use this driver for enabling non-sound components
  37. * through the new module parameter pss_no_sound (flag). Added
  38. * code that would allow a user to decide whether the driver should
  39. * reset the configured hardware settings for the PSS board through
  40. * the module parameter pss_keep_settings (flag). This flag will
  41. * allow a user to free up resources in use by this card if needbe,
  42. * furthermore it allows him to use this driver to just enable the
  43. * emulations and then be unloaded as it is no longer needed. Both
  44. * new settings are only available to this driver if compiled as a
  45. * module. The default settings of all new parameters are set to
  46. * load the driver as it did in previous versions.
  47. * 04-07-1999: Anthony Barbachan <barbcode@xmen.cis.fordham.edu>
  48. * Added module parameter pss_firmware to allow the user to tell
  49. * the driver where the firmware file is located. The default
  50. * setting is the previous hardcoded setting "/etc/sound/pss_synth".
  51. * 00-03-03: Christoph Hellwig <chhellwig@infradead.org>
  52. * Adapted to module_init/module_exit
  53. * 11-10-2000: Bartlomiej Zolnierkiewicz <bkz@linux-ide.org>
  54. * Added __init to probe_pss(), attach_pss() and probe_pss_mpu()
  55. * 02-Jan-2001: Chris Rankin
  56. * Specify that this module owns the coprocessor
  57. */
  58. #include <linux/init.h>
  59. #include <linux/module.h>
  60. #include <linux/spinlock.h>
  61. #include "sound_config.h"
  62. #include "sound_firmware.h"
  63. #include "ad1848.h"
  64. #include "mpu401.h"
  65. /*
  66. * PSS registers.
  67. */
  68. #define REG(x) (devc->base+x)
  69. #define PSS_DATA 0
  70. #define PSS_STATUS 2
  71. #define PSS_CONTROL 2
  72. #define PSS_ID 4
  73. #define PSS_IRQACK 4
  74. #define PSS_PIO 0x1a
  75. /*
  76. * Config registers
  77. */
  78. #define CONF_PSS 0x10
  79. #define CONF_WSS 0x12
  80. #define CONF_SB 0x14
  81. #define CONF_CDROM 0x16
  82. #define CONF_MIDI 0x18
  83. /*
  84. * Status bits.
  85. */
  86. #define PSS_FLAG3 0x0800
  87. #define PSS_FLAG2 0x0400
  88. #define PSS_FLAG1 0x1000
  89. #define PSS_FLAG0 0x0800
  90. #define PSS_WRITE_EMPTY 0x8000
  91. #define PSS_READ_FULL 0x4000
  92. /*
  93. * WSS registers
  94. */
  95. #define WSS_INDEX 4
  96. #define WSS_DATA 5
  97. /*
  98. * WSS status bits
  99. */
  100. #define WSS_INITIALIZING 0x80
  101. #define WSS_AUTOCALIBRATION 0x20
  102. #define NO_WSS_MIXER -1
  103. #include "coproc.h"
  104. #include "pss_boot.h"
  105. /* If compiled into kernel, it enable or disable pss mixer */
  106. #ifdef CONFIG_PSS_MIXER
  107. static int pss_mixer = 1;
  108. #else
  109. static int pss_mixer;
  110. #endif
  111. typedef struct pss_mixerdata {
  112. unsigned int volume_l;
  113. unsigned int volume_r;
  114. unsigned int bass;
  115. unsigned int treble;
  116. unsigned int synth;
  117. } pss_mixerdata;
  118. typedef struct pss_confdata {
  119. int base;
  120. int irq;
  121. int dma;
  122. int *osp;
  123. pss_mixerdata mixer;
  124. int ad_mixer_dev;
  125. } pss_confdata;
  126. static pss_confdata pss_data;
  127. static pss_confdata *devc = &pss_data;
  128. static DEFINE_SPINLOCK(lock);
  129. static int pss_initialized;
  130. static int nonstandard_microcode;
  131. static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
  132. static int pss_enable_joystick; /* Parameter for enabling the joystick */
  133. static coproc_operations pss_coproc_operations;
  134. static void pss_write(pss_confdata *devc, int data)
  135. {
  136. unsigned long i, limit;
  137. limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
  138. /*
  139. * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
  140. * called while interrupts are disabled. This means that the timer is
  141. * disabled also. However the timeout situation is a abnormal condition.
  142. * Normally the DSP should be ready to accept commands after just couple of
  143. * loops.
  144. */
  145. for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
  146. {
  147. if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
  148. {
  149. outw(data, REG(PSS_DATA));
  150. return;
  151. }
  152. }
  153. printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
  154. }
  155. static int __init probe_pss(struct address_info *hw_config)
  156. {
  157. unsigned short id;
  158. int irq, dma;
  159. devc->base = hw_config->io_base;
  160. irq = devc->irq = hw_config->irq;
  161. dma = devc->dma = hw_config->dma;
  162. devc->osp = hw_config->osp;
  163. if (devc->base != 0x220 && devc->base != 0x240)
  164. if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
  165. return 0;
  166. if (!request_region(devc->base, 0x10, "PSS mixer, SB emulation")) {
  167. printk(KERN_ERR "PSS: I/O port conflict\n");
  168. return 0;
  169. }
  170. id = inw(REG(PSS_ID));
  171. if ((id >> 8) != 'E') {
  172. printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
  173. release_region(devc->base, 0x10);
  174. return 0;
  175. }
  176. if (!request_region(devc->base + 0x10, 0x9, "PSS config")) {
  177. printk(KERN_ERR "PSS: I/O port conflict\n");
  178. release_region(devc->base, 0x10);
  179. return 0;
  180. }
  181. return 1;
  182. }
  183. static int set_irq(pss_confdata * devc, int dev, int irq)
  184. {
  185. static unsigned short irq_bits[16] =
  186. {
  187. 0x0000, 0x0000, 0x0000, 0x0008,
  188. 0x0000, 0x0010, 0x0000, 0x0018,
  189. 0x0000, 0x0020, 0x0028, 0x0030,
  190. 0x0038, 0x0000, 0x0000, 0x0000
  191. };
  192. unsigned short tmp, bits;
  193. if (irq < 0 || irq > 15)
  194. return 0;
  195. tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
  196. if ((bits = irq_bits[irq]) == 0 && irq != 0)
  197. {
  198. printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
  199. return 0;
  200. }
  201. outw(tmp | bits, REG(dev));
  202. return 1;
  203. }
  204. static void set_io_base(pss_confdata * devc, int dev, int base)
  205. {
  206. unsigned short tmp = inw(REG(dev)) & 0x003f;
  207. unsigned short bits = (base & 0x0ffc) << 4;
  208. outw(bits | tmp, REG(dev));
  209. }
  210. static int set_dma(pss_confdata * devc, int dev, int dma)
  211. {
  212. static unsigned short dma_bits[8] =
  213. {
  214. 0x0001, 0x0002, 0x0000, 0x0003,
  215. 0x0000, 0x0005, 0x0006, 0x0007
  216. };
  217. unsigned short tmp, bits;
  218. if (dma < 0 || dma > 7)
  219. return 0;
  220. tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
  221. if ((bits = dma_bits[dma]) == 0 && dma != 4)
  222. {
  223. printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
  224. return 0;
  225. }
  226. outw(tmp | bits, REG(dev));
  227. return 1;
  228. }
  229. static int pss_reset_dsp(pss_confdata * devc)
  230. {
  231. unsigned long i, limit = jiffies + HZ/10;
  232. outw(0x2000, REG(PSS_CONTROL));
  233. for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
  234. inw(REG(PSS_CONTROL));
  235. outw(0x0000, REG(PSS_CONTROL));
  236. return 1;
  237. }
  238. static int pss_put_dspword(pss_confdata * devc, unsigned short word)
  239. {
  240. int i, val;
  241. for (i = 0; i < 327680; i++)
  242. {
  243. val = inw(REG(PSS_STATUS));
  244. if (val & PSS_WRITE_EMPTY)
  245. {
  246. outw(word, REG(PSS_DATA));
  247. return 1;
  248. }
  249. }
  250. return 0;
  251. }
  252. static int pss_get_dspword(pss_confdata * devc, unsigned short *word)
  253. {
  254. int i, val;
  255. for (i = 0; i < 327680; i++)
  256. {
  257. val = inw(REG(PSS_STATUS));
  258. if (val & PSS_READ_FULL)
  259. {
  260. *word = inw(REG(PSS_DATA));
  261. return 1;
  262. }
  263. }
  264. return 0;
  265. }
  266. static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size, int flags)
  267. {
  268. int i, val, count;
  269. unsigned long limit;
  270. if (flags & CPF_FIRST)
  271. {
  272. /*_____ Warn DSP software that a boot is coming */
  273. outw(0x00fe, REG(PSS_DATA));
  274. limit = jiffies + HZ/10;
  275. for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
  276. if (inw(REG(PSS_DATA)) == 0x5500)
  277. break;
  278. outw(*block++, REG(PSS_DATA));
  279. pss_reset_dsp(devc);
  280. }
  281. count = 1;
  282. while ((flags&CPF_LAST) || count<size )
  283. {
  284. int j;
  285. for (j = 0; j < 327670; j++)
  286. {
  287. /*_____ Wait for BG to appear */
  288. if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
  289. break;
  290. }
  291. if (j == 327670)
  292. {
  293. /* It's ok we timed out when the file was empty */
  294. if (count >= size && flags & CPF_LAST)
  295. break;
  296. else
  297. {
  298. printk("\n");
  299. printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
  300. return 0;
  301. }
  302. }
  303. /*_____ Send the next byte */
  304. if (count >= size)
  305. {
  306. /* If not data in block send 0xffff */
  307. outw (0xffff, REG (PSS_DATA));
  308. }
  309. else
  310. {
  311. /*_____ Send the next byte */
  312. outw (*block++, REG (PSS_DATA));
  313. };
  314. count++;
  315. }
  316. if (flags & CPF_LAST)
  317. {
  318. /*_____ Why */
  319. outw(0, REG(PSS_DATA));
  320. limit = jiffies + HZ/10;
  321. for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
  322. val = inw(REG(PSS_STATUS));
  323. limit = jiffies + HZ/10;
  324. for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
  325. {
  326. val = inw(REG(PSS_STATUS));
  327. if (val & 0x4000)
  328. break;
  329. }
  330. /* now read the version */
  331. for (i = 0; i < 32000; i++)
  332. {
  333. val = inw(REG(PSS_STATUS));
  334. if (val & PSS_READ_FULL)
  335. break;
  336. }
  337. if (i == 32000)
  338. return 0;
  339. val = inw(REG(PSS_DATA));
  340. /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
  341. }
  342. return 1;
  343. }
  344. /* Mixer */
  345. static void set_master_volume(pss_confdata *devc, int left, int right)
  346. {
  347. static unsigned char log_scale[101] = {
  348. 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
  349. 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
  350. 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
  351. 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
  352. 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
  353. 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
  354. 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
  355. 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
  356. 0xfe, 0xfe, 0xff, 0xff, 0xff
  357. };
  358. pss_write(devc, 0x0010);
  359. pss_write(devc, log_scale[left] | 0x0000);
  360. pss_write(devc, 0x0010);
  361. pss_write(devc, log_scale[right] | 0x0100);
  362. }
  363. static void set_synth_volume(pss_confdata *devc, int volume)
  364. {
  365. int vol = ((0x8000*volume)/100L);
  366. pss_write(devc, 0x0080);
  367. pss_write(devc, vol);
  368. pss_write(devc, 0x0081);
  369. pss_write(devc, vol);
  370. }
  371. static void set_bass(pss_confdata *devc, int level)
  372. {
  373. int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
  374. pss_write(devc, 0x0010);
  375. pss_write(devc, vol | 0x0200);
  376. };
  377. static void set_treble(pss_confdata *devc, int level)
  378. {
  379. int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
  380. pss_write(devc, 0x0010);
  381. pss_write(devc, vol | 0x0300);
  382. };
  383. static void pss_mixer_reset(pss_confdata *devc)
  384. {
  385. set_master_volume(devc, 33, 33);
  386. set_bass(devc, 50);
  387. set_treble(devc, 50);
  388. set_synth_volume(devc, 30);
  389. pss_write (devc, 0x0010);
  390. pss_write (devc, 0x0800 | 0xce); /* Stereo */
  391. if(pss_mixer)
  392. {
  393. devc->mixer.volume_l = devc->mixer.volume_r = 33;
  394. devc->mixer.bass = 50;
  395. devc->mixer.treble = 50;
  396. devc->mixer.synth = 30;
  397. }
  398. }
  399. static int set_volume_mono(unsigned __user *p, unsigned int *aleft)
  400. {
  401. unsigned int left, volume;
  402. if (get_user(volume, p))
  403. return -EFAULT;
  404. left = volume & 0xff;
  405. if (left > 100)
  406. left = 100;
  407. *aleft = left;
  408. return 0;
  409. }
  410. static int set_volume_stereo(unsigned __user *p,
  411. unsigned int *aleft,
  412. unsigned int *aright)
  413. {
  414. unsigned int left, right, volume;
  415. if (get_user(volume, p))
  416. return -EFAULT;
  417. left = volume & 0xff;
  418. if (left > 100)
  419. left = 100;
  420. right = (volume >> 8) & 0xff;
  421. if (right > 100)
  422. right = 100;
  423. *aleft = left;
  424. *aright = right;
  425. return 0;
  426. }
  427. static int ret_vol_mono(int left)
  428. {
  429. return ((left << 8) | left);
  430. }
  431. static int ret_vol_stereo(int left, int right)
  432. {
  433. return ((right << 8) | left);
  434. }
  435. static int call_ad_mixer(pss_confdata *devc,unsigned int cmd, void __user *arg)
  436. {
  437. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  438. return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
  439. else
  440. return -EINVAL;
  441. }
  442. static int pss_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
  443. {
  444. pss_confdata *devc = mixer_devs[dev]->devc;
  445. int cmdf = cmd & 0xff;
  446. if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
  447. (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
  448. (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
  449. (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
  450. (cmdf != SOUND_MIXER_RECSRC))
  451. {
  452. return call_ad_mixer(devc, cmd, arg);
  453. }
  454. if (((cmd >> 8) & 0xff) != 'M')
  455. return -EINVAL;
  456. if (_SIOC_DIR (cmd) & _SIOC_WRITE)
  457. {
  458. switch (cmdf)
  459. {
  460. case SOUND_MIXER_RECSRC:
  461. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  462. return call_ad_mixer(devc, cmd, arg);
  463. else
  464. {
  465. int v;
  466. if (get_user(v, (int __user *)arg))
  467. return -EFAULT;
  468. if (v != 0)
  469. return -EINVAL;
  470. return 0;
  471. }
  472. case SOUND_MIXER_VOLUME:
  473. if (set_volume_stereo(arg,
  474. &devc->mixer.volume_l,
  475. &devc->mixer.volume_r))
  476. return -EFAULT;
  477. set_master_volume(devc, devc->mixer.volume_l,
  478. devc->mixer.volume_r);
  479. return ret_vol_stereo(devc->mixer.volume_l,
  480. devc->mixer.volume_r);
  481. case SOUND_MIXER_BASS:
  482. if (set_volume_mono(arg, &devc->mixer.bass))
  483. return -EFAULT;
  484. set_bass(devc, devc->mixer.bass);
  485. return ret_vol_mono(devc->mixer.bass);
  486. case SOUND_MIXER_TREBLE:
  487. if (set_volume_mono(arg, &devc->mixer.treble))
  488. return -EFAULT;
  489. set_treble(devc, devc->mixer.treble);
  490. return ret_vol_mono(devc->mixer.treble);
  491. case SOUND_MIXER_SYNTH:
  492. if (set_volume_mono(arg, &devc->mixer.synth))
  493. return -EFAULT;
  494. set_synth_volume(devc, devc->mixer.synth);
  495. return ret_vol_mono(devc->mixer.synth);
  496. default:
  497. return -EINVAL;
  498. }
  499. }
  500. else
  501. {
  502. int val, and_mask = 0, or_mask = 0;
  503. /*
  504. * Return parameters
  505. */
  506. switch (cmdf)
  507. {
  508. case SOUND_MIXER_DEVMASK:
  509. if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
  510. break;
  511. and_mask = ~0;
  512. or_mask = SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH;
  513. break;
  514. case SOUND_MIXER_STEREODEVS:
  515. if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
  516. break;
  517. and_mask = ~0;
  518. or_mask = SOUND_MASK_VOLUME;
  519. break;
  520. case SOUND_MIXER_RECMASK:
  521. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  522. return call_ad_mixer(devc, cmd, arg);
  523. break;
  524. case SOUND_MIXER_CAPS:
  525. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  526. return call_ad_mixer(devc, cmd, arg);
  527. or_mask = SOUND_CAP_EXCL_INPUT;
  528. break;
  529. case SOUND_MIXER_RECSRC:
  530. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  531. return call_ad_mixer(devc, cmd, arg);
  532. break;
  533. case SOUND_MIXER_VOLUME:
  534. or_mask = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r);
  535. break;
  536. case SOUND_MIXER_BASS:
  537. or_mask = ret_vol_mono(devc->mixer.bass);
  538. break;
  539. case SOUND_MIXER_TREBLE:
  540. or_mask = ret_vol_mono(devc->mixer.treble);
  541. break;
  542. case SOUND_MIXER_SYNTH:
  543. or_mask = ret_vol_mono(devc->mixer.synth);
  544. break;
  545. default:
  546. return -EINVAL;
  547. }
  548. if (get_user(val, (int __user *)arg))
  549. return -EFAULT;
  550. val &= and_mask;
  551. val |= or_mask;
  552. if (put_user(val, (int __user *)arg))
  553. return -EFAULT;
  554. return val;
  555. }
  556. }
  557. static struct mixer_operations pss_mixer_operations =
  558. {
  559. .owner = THIS_MODULE,
  560. .id = "SOUNDPORT",
  561. .name = "PSS-AD1848",
  562. .ioctl = pss_mixer_ioctl
  563. };
  564. static void disable_all_emulations(void)
  565. {
  566. outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
  567. outw(0x0000, REG(CONF_WSS));
  568. outw(0x0000, REG(CONF_SB));
  569. outw(0x0000, REG(CONF_MIDI));
  570. outw(0x0000, REG(CONF_CDROM));
  571. }
  572. static void configure_nonsound_components(void)
  573. {
  574. /* Configure Joystick port */
  575. if(pss_enable_joystick)
  576. {
  577. outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
  578. printk(KERN_INFO "PSS: joystick enabled.\n");
  579. }
  580. else
  581. {
  582. printk(KERN_INFO "PSS: joystick port not enabled.\n");
  583. }
  584. /* Configure CDROM port */
  585. if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */
  586. printk(KERN_INFO "PSS: CDROM port not enabled.\n");
  587. } else if (check_region(pss_cdrom_port, 2)) {
  588. printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
  589. } else {
  590. set_io_base(devc, CONF_CDROM, pss_cdrom_port);
  591. printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
  592. }
  593. }
  594. static int __init attach_pss(struct address_info *hw_config)
  595. {
  596. unsigned short id;
  597. char tmp[100];
  598. devc->base = hw_config->io_base;
  599. devc->irq = hw_config->irq;
  600. devc->dma = hw_config->dma;
  601. devc->osp = hw_config->osp;
  602. devc->ad_mixer_dev = NO_WSS_MIXER;
  603. if (!probe_pss(hw_config))
  604. return 0;
  605. id = inw(REG(PSS_ID)) & 0x00ff;
  606. /*
  607. * Disable all emulations. Will be enabled later (if required).
  608. */
  609. disable_all_emulations();
  610. #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
  611. if (sound_alloc_dma(hw_config->dma, "PSS"))
  612. {
  613. printk("pss.c: Can't allocate DMA channel.\n");
  614. release_region(hw_config->io_base, 0x10);
  615. release_region(hw_config->io_base+0x10, 0x9);
  616. return 0;
  617. }
  618. if (!set_irq(devc, CONF_PSS, devc->irq))
  619. {
  620. printk("PSS: IRQ allocation error.\n");
  621. release_region(hw_config->io_base, 0x10);
  622. release_region(hw_config->io_base+0x10, 0x9);
  623. return 0;
  624. }
  625. if (!set_dma(devc, CONF_PSS, devc->dma))
  626. {
  627. printk(KERN_ERR "PSS: DMA allocation error\n");
  628. release_region(hw_config->io_base, 0x10);
  629. release_region(hw_config->io_base+0x10, 0x9);
  630. return 0;
  631. }
  632. #endif
  633. configure_nonsound_components();
  634. pss_initialized = 1;
  635. sprintf(tmp, "ECHO-PSS Rev. %d", id);
  636. conf_printf(tmp, hw_config);
  637. return 1;
  638. }
  639. static int __init probe_pss_mpu(struct address_info *hw_config)
  640. {
  641. struct resource *ports;
  642. int timeout;
  643. if (!pss_initialized)
  644. return 0;
  645. ports = request_region(hw_config->io_base, 2, "mpu401");
  646. if (!ports) {
  647. printk(KERN_ERR "PSS: MPU I/O port conflict\n");
  648. return 0;
  649. }
  650. set_io_base(devc, CONF_MIDI, hw_config->io_base);
  651. if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
  652. printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
  653. goto fail;
  654. }
  655. if (!pss_synthLen) {
  656. printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
  657. goto fail;
  658. }
  659. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
  660. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  661. goto fail;
  662. }
  663. /*
  664. * Finally wait until the DSP algorithm has initialized itself and
  665. * deactivates receive interrupt.
  666. */
  667. for (timeout = 900000; timeout > 0; timeout--)
  668. {
  669. if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
  670. inb(hw_config->io_base); /* Discard it */
  671. else
  672. break; /* No more input */
  673. }
  674. if (!probe_mpu401(hw_config, ports))
  675. goto fail;
  676. attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
  677. if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
  678. midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
  679. return 1;
  680. fail:
  681. release_region(hw_config->io_base, 2);
  682. return 0;
  683. }
  684. static int pss_coproc_open(void *dev_info, int sub_device)
  685. {
  686. switch (sub_device)
  687. {
  688. case COPR_MIDI:
  689. if (pss_synthLen == 0)
  690. {
  691. printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
  692. return -EIO;
  693. }
  694. if (nonstandard_microcode)
  695. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  696. {
  697. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  698. return -EIO;
  699. }
  700. nonstandard_microcode = 0;
  701. break;
  702. default:
  703. break;
  704. }
  705. return 0;
  706. }
  707. static void pss_coproc_close(void *dev_info, int sub_device)
  708. {
  709. return;
  710. }
  711. static void pss_coproc_reset(void *dev_info)
  712. {
  713. if (pss_synthLen)
  714. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  715. {
  716. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  717. }
  718. nonstandard_microcode = 0;
  719. }
  720. static int download_boot_block(void *dev_info, copr_buffer * buf)
  721. {
  722. if (buf->len <= 0 || buf->len > sizeof(buf->data))
  723. return -EINVAL;
  724. if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
  725. {
  726. printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
  727. return -EIO;
  728. }
  729. nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
  730. return 0;
  731. }
  732. static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
  733. {
  734. copr_buffer *buf;
  735. copr_msg *mbuf;
  736. copr_debug_buf dbuf;
  737. unsigned short tmp;
  738. unsigned long flags;
  739. unsigned short *data;
  740. int i, err;
  741. /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
  742. switch (cmd)
  743. {
  744. case SNDCTL_COPR_RESET:
  745. pss_coproc_reset(dev_info);
  746. return 0;
  747. case SNDCTL_COPR_LOAD:
  748. buf = vmalloc(sizeof(copr_buffer));
  749. if (buf == NULL)
  750. return -ENOSPC;
  751. if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
  752. vfree(buf);
  753. return -EFAULT;
  754. }
  755. err = download_boot_block(dev_info, buf);
  756. vfree(buf);
  757. return err;
  758. case SNDCTL_COPR_SENDMSG:
  759. mbuf = vmalloc(sizeof(copr_msg));
  760. if (mbuf == NULL)
  761. return -ENOSPC;
  762. if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
  763. vfree(mbuf);
  764. return -EFAULT;
  765. }
  766. data = (unsigned short *)(mbuf->data);
  767. spin_lock_irqsave(&lock, flags);
  768. for (i = 0; i < mbuf->len; i++) {
  769. if (!pss_put_dspword(devc, *data++)) {
  770. spin_unlock_irqrestore(&lock,flags);
  771. mbuf->len = i; /* feed back number of WORDs sent */
  772. err = copy_to_user(arg, mbuf, sizeof(copr_msg));
  773. vfree(mbuf);
  774. return err ? -EFAULT : -EIO;
  775. }
  776. }
  777. spin_unlock_irqrestore(&lock,flags);
  778. vfree(mbuf);
  779. return 0;
  780. case SNDCTL_COPR_RCVMSG:
  781. err = 0;
  782. mbuf = vmalloc(sizeof(copr_msg));
  783. if (mbuf == NULL)
  784. return -ENOSPC;
  785. data = (unsigned short *)mbuf->data;
  786. spin_lock_irqsave(&lock, flags);
  787. for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
  788. mbuf->len = i; /* feed back number of WORDs read */
  789. if (!pss_get_dspword(devc, data++)) {
  790. if (i == 0)
  791. err = -EIO;
  792. break;
  793. }
  794. }
  795. spin_unlock_irqrestore(&lock,flags);
  796. if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
  797. err = -EFAULT;
  798. vfree(mbuf);
  799. return err;
  800. case SNDCTL_COPR_RDATA:
  801. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  802. return -EFAULT;
  803. spin_lock_irqsave(&lock, flags);
  804. if (!pss_put_dspword(devc, 0x00d0)) {
  805. spin_unlock_irqrestore(&lock,flags);
  806. return -EIO;
  807. }
  808. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  809. spin_unlock_irqrestore(&lock,flags);
  810. return -EIO;
  811. }
  812. if (!pss_get_dspword(devc, &tmp)) {
  813. spin_unlock_irqrestore(&lock,flags);
  814. return -EIO;
  815. }
  816. dbuf.parm1 = tmp;
  817. spin_unlock_irqrestore(&lock,flags);
  818. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  819. return -EFAULT;
  820. return 0;
  821. case SNDCTL_COPR_WDATA:
  822. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  823. return -EFAULT;
  824. spin_lock_irqsave(&lock, flags);
  825. if (!pss_put_dspword(devc, 0x00d1)) {
  826. spin_unlock_irqrestore(&lock,flags);
  827. return -EIO;
  828. }
  829. if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
  830. spin_unlock_irqrestore(&lock,flags);
  831. return -EIO;
  832. }
  833. tmp = (unsigned int)dbuf.parm2 & 0xffff;
  834. if (!pss_put_dspword(devc, tmp)) {
  835. spin_unlock_irqrestore(&lock,flags);
  836. return -EIO;
  837. }
  838. spin_unlock_irqrestore(&lock,flags);
  839. return 0;
  840. case SNDCTL_COPR_WCODE:
  841. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  842. return -EFAULT;
  843. spin_lock_irqsave(&lock, flags);
  844. if (!pss_put_dspword(devc, 0x00d3)) {
  845. spin_unlock_irqrestore(&lock,flags);
  846. return -EIO;
  847. }
  848. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  849. spin_unlock_irqrestore(&lock,flags);
  850. return -EIO;
  851. }
  852. tmp = (unsigned int)dbuf.parm2 & 0x00ff;
  853. if (!pss_put_dspword(devc, tmp)) {
  854. spin_unlock_irqrestore(&lock,flags);
  855. return -EIO;
  856. }
  857. tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
  858. if (!pss_put_dspword(devc, tmp)) {
  859. spin_unlock_irqrestore(&lock,flags);
  860. return -EIO;
  861. }
  862. spin_unlock_irqrestore(&lock,flags);
  863. return 0;
  864. case SNDCTL_COPR_RCODE:
  865. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  866. return -EFAULT;
  867. spin_lock_irqsave(&lock, flags);
  868. if (!pss_put_dspword(devc, 0x00d2)) {
  869. spin_unlock_irqrestore(&lock,flags);
  870. return -EIO;
  871. }
  872. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  873. spin_unlock_irqrestore(&lock,flags);
  874. return -EIO;
  875. }
  876. if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
  877. spin_unlock_irqrestore(&lock,flags);
  878. return -EIO;
  879. }
  880. dbuf.parm1 = tmp << 8;
  881. if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
  882. spin_unlock_irqrestore(&lock,flags);
  883. return -EIO;
  884. }
  885. dbuf.parm1 |= tmp & 0x00ff;
  886. spin_unlock_irqrestore(&lock,flags);
  887. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  888. return -EFAULT;
  889. return 0;
  890. default:
  891. return -EINVAL;
  892. }
  893. return -EINVAL;
  894. }
  895. static coproc_operations pss_coproc_operations =
  896. {
  897. "ADSP-2115",
  898. THIS_MODULE,
  899. pss_coproc_open,
  900. pss_coproc_close,
  901. pss_coproc_ioctl,
  902. pss_coproc_reset,
  903. &pss_data
  904. };
  905. static int __init probe_pss_mss(struct address_info *hw_config)
  906. {
  907. volatile int timeout;
  908. struct resource *ports;
  909. int my_mix = -999; /* gcc shut up */
  910. if (!pss_initialized)
  911. return 0;
  912. if (!request_region(hw_config->io_base, 4, "WSS config")) {
  913. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  914. return 0;
  915. }
  916. ports = request_region(hw_config->io_base + 4, 4, "ad1848");
  917. if (!ports) {
  918. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  919. release_region(hw_config->io_base, 4);
  920. return 0;
  921. }
  922. set_io_base(devc, CONF_WSS, hw_config->io_base);
  923. if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
  924. printk("PSS: WSS IRQ allocation error.\n");
  925. goto fail;
  926. }
  927. if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
  928. printk(KERN_ERR "PSS: WSS DMA allocation error\n");
  929. goto fail;
  930. }
  931. /*
  932. * For some reason the card returns 0xff in the WSS status register
  933. * immediately after boot. Probably MIDI+SB emulation algorithm
  934. * downloaded to the ADSP2115 spends some time initializing the card.
  935. * Let's try to wait until it finishes this task.
  936. */
  937. for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
  938. WSS_INITIALIZING); timeout++)
  939. ;
  940. outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
  941. for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
  942. (timeout < 100000); timeout++)
  943. ;
  944. if (!probe_ms_sound(hw_config, ports))
  945. goto fail;
  946. devc->ad_mixer_dev = NO_WSS_MIXER;
  947. if (pss_mixer)
  948. {
  949. if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
  950. "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
  951. &pss_mixer_operations,
  952. sizeof (struct mixer_operations),
  953. devc)) < 0)
  954. {
  955. printk(KERN_ERR "Could not install PSS mixer\n");
  956. goto fail;
  957. }
  958. }
  959. pss_mixer_reset(devc);
  960. attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
  961. if (hw_config->slots[0] != -1)
  962. {
  963. /* The MSS driver installed itself */
  964. audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
  965. if (pss_mixer && (num_mixers == (my_mix + 2)))
  966. {
  967. /* The MSS mixer installed */
  968. devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
  969. }
  970. }
  971. return 1;
  972. fail:
  973. release_region(hw_config->io_base + 4, 4);
  974. release_region(hw_config->io_base, 4);
  975. return 0;
  976. }
  977. static inline void __exit unload_pss(struct address_info *hw_config)
  978. {
  979. release_region(hw_config->io_base, 0x10);
  980. release_region(hw_config->io_base+0x10, 0x9);
  981. }
  982. static inline void __exit unload_pss_mpu(struct address_info *hw_config)
  983. {
  984. unload_mpu401(hw_config);
  985. }
  986. static inline void __exit unload_pss_mss(struct address_info *hw_config)
  987. {
  988. unload_ms_sound(hw_config);
  989. }
  990. static struct address_info cfg;
  991. static struct address_info cfg2;
  992. static struct address_info cfg_mpu;
  993. static int pss_io __initdata = -1;
  994. static int mss_io __initdata = -1;
  995. static int mss_irq __initdata = -1;
  996. static int mss_dma __initdata = -1;
  997. static int mpu_io __initdata = -1;
  998. static int mpu_irq __initdata = -1;
  999. static int pss_no_sound = 0; /* Just configure non-sound components */
  1000. static int pss_keep_settings = 1; /* Keep hardware settings at module exit */
  1001. static char *pss_firmware = "/etc/sound/pss_synth";
  1002. module_param(pss_io, int, 0);
  1003. MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
  1004. module_param(mss_io, int, 0);
  1005. MODULE_PARM_DESC(mss_io, "Set WSS (audio) i/o base (0x530, 0x604, 0xE80, 0xF40, or other. Address must end in 0 or 4 and must be from 0x100 to 0xFF4)");
  1006. module_param(mss_irq, int, 0);
  1007. MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
  1008. module_param(mss_dma, int, 0);
  1009. MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
  1010. module_param(mpu_io, int, 0);
  1011. MODULE_PARM_DESC(mpu_io, "Set MIDI i/o base (0x330 or other. Address must be on 4 location boundaries and must be from 0x100 to 0xFFC)");
  1012. module_param(mpu_irq, int, 0);
  1013. MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
  1014. module_param(pss_cdrom_port, int, 0);
  1015. MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
  1016. module_param(pss_enable_joystick, bool, 0);
  1017. MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
  1018. module_param(pss_no_sound, bool, 0);
  1019. MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
  1020. module_param(pss_keep_settings, bool, 0);
  1021. MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
  1022. module_param(pss_firmware, charp, 0);
  1023. MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
  1024. module_param(pss_mixer, bool, 0);
  1025. MODULE_PARM_DESC(pss_mixer, "Enable (1) or disable (0) PSS mixer (controlling of output volume, bass, treble, synth volume). The mixer is not available on all PSS cards.");
  1026. MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
  1027. MODULE_DESCRIPTION("Module for PSS sound cards (based on AD1848, ADSP-2115 and ESC614). This module includes control of output amplifier and synth volume of the Beethoven ADSP-16 card (this may work with other PSS cards).");
  1028. MODULE_LICENSE("GPL");
  1029. static int fw_load = 0;
  1030. static int pssmpu = 0, pssmss = 0;
  1031. /*
  1032. * Load a PSS sound card module
  1033. */
  1034. static int __init init_pss(void)
  1035. {
  1036. if(pss_no_sound) /* If configuring only nonsound components */
  1037. {
  1038. cfg.io_base = pss_io;
  1039. if(!probe_pss(&cfg))
  1040. return -ENODEV;
  1041. printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
  1042. printk(KERN_INFO "PSS: loading in no sound mode.\n");
  1043. disable_all_emulations();
  1044. configure_nonsound_components();
  1045. release_region(pss_io, 0x10);
  1046. release_region(pss_io + 0x10, 0x9);
  1047. return 0;
  1048. }
  1049. cfg.io_base = pss_io;
  1050. cfg2.io_base = mss_io;
  1051. cfg2.irq = mss_irq;
  1052. cfg2.dma = mss_dma;
  1053. cfg_mpu.io_base = mpu_io;
  1054. cfg_mpu.irq = mpu_irq;
  1055. if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
  1056. printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
  1057. return -EINVAL;
  1058. }
  1059. if (!pss_synth) {
  1060. fw_load = 1;
  1061. pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
  1062. }
  1063. if (!attach_pss(&cfg))
  1064. return -ENODEV;
  1065. /*
  1066. * Attach stuff
  1067. */
  1068. if (probe_pss_mpu(&cfg_mpu))
  1069. pssmpu = 1;
  1070. if (probe_pss_mss(&cfg2))
  1071. pssmss = 1;
  1072. return 0;
  1073. }
  1074. static void __exit cleanup_pss(void)
  1075. {
  1076. if(!pss_no_sound)
  1077. {
  1078. if(fw_load && pss_synth)
  1079. vfree(pss_synth);
  1080. if(pssmss)
  1081. unload_pss_mss(&cfg2);
  1082. if(pssmpu)
  1083. unload_pss_mpu(&cfg_mpu);
  1084. unload_pss(&cfg);
  1085. }
  1086. if(!pss_keep_settings) /* Keep hardware settings if asked */
  1087. {
  1088. disable_all_emulations();
  1089. printk(KERN_INFO "Resetting PSS sound card configurations.\n");
  1090. }
  1091. }
  1092. module_init(init_pss);
  1093. module_exit(cleanup_pss);
  1094. #ifndef MODULE
  1095. static int __init setup_pss(char *str)
  1096. {
  1097. /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
  1098. int ints[7];
  1099. str = get_options(str, ARRAY_SIZE(ints), ints);
  1100. pss_io = ints[1];
  1101. mss_io = ints[2];
  1102. mss_irq = ints[3];
  1103. mss_dma = ints[4];
  1104. mpu_io = ints[5];
  1105. mpu_irq = ints[6];
  1106. return 1;
  1107. }
  1108. __setup("pss=", setup_pss);
  1109. #endif