pss.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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 bool pss_mixer = 1;
  108. #else
  109. static bool pss_mixer;
  110. #endif
  111. 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. };
  118. struct pss_confdata {
  119. int base;
  120. int irq;
  121. int dma;
  122. int *osp;
  123. struct pss_mixerdata mixer;
  124. int ad_mixer_dev;
  125. };
  126. static struct pss_confdata pss_data;
  127. static struct 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 bool pss_enable_joystick; /* Parameter for enabling the joystick */
  133. static coproc_operations pss_coproc_operations;
  134. static void pss_write(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct 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(struct pss_confdata *devc, unsigned char *block,
  267. int size, int flags)
  268. {
  269. int i, val, count;
  270. unsigned long limit;
  271. if (flags & CPF_FIRST)
  272. {
  273. /*_____ Warn DSP software that a boot is coming */
  274. outw(0x00fe, REG(PSS_DATA));
  275. limit = jiffies + HZ/10;
  276. for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
  277. if (inw(REG(PSS_DATA)) == 0x5500)
  278. break;
  279. outw(*block++, REG(PSS_DATA));
  280. pss_reset_dsp(devc);
  281. }
  282. count = 1;
  283. while ((flags&CPF_LAST) || count<size )
  284. {
  285. int j;
  286. for (j = 0; j < 327670; j++)
  287. {
  288. /*_____ Wait for BG to appear */
  289. if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
  290. break;
  291. }
  292. if (j == 327670)
  293. {
  294. /* It's ok we timed out when the file was empty */
  295. if (count >= size && flags & CPF_LAST)
  296. break;
  297. else
  298. {
  299. printk("\n");
  300. printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
  301. return 0;
  302. }
  303. }
  304. /*_____ Send the next byte */
  305. if (count >= size)
  306. {
  307. /* If not data in block send 0xffff */
  308. outw (0xffff, REG (PSS_DATA));
  309. }
  310. else
  311. {
  312. /*_____ Send the next byte */
  313. outw (*block++, REG (PSS_DATA));
  314. }
  315. count++;
  316. }
  317. if (flags & CPF_LAST)
  318. {
  319. /*_____ Why */
  320. outw(0, REG(PSS_DATA));
  321. limit = jiffies + HZ/10;
  322. for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
  323. val = inw(REG(PSS_STATUS));
  324. limit = jiffies + HZ/10;
  325. for (i = 0; i < 32768 && time_after_eq(limit, jiffies); i++)
  326. {
  327. val = inw(REG(PSS_STATUS));
  328. if (val & 0x4000)
  329. break;
  330. }
  331. /* now read the version */
  332. for (i = 0; i < 32000; i++)
  333. {
  334. val = inw(REG(PSS_STATUS));
  335. if (val & PSS_READ_FULL)
  336. break;
  337. }
  338. if (i == 32000)
  339. return 0;
  340. val = inw(REG(PSS_DATA));
  341. /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
  342. }
  343. return 1;
  344. }
  345. /* Mixer */
  346. static void set_master_volume(struct pss_confdata *devc, int left, int right)
  347. {
  348. static unsigned char log_scale[101] = {
  349. 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
  350. 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
  351. 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
  352. 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
  353. 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
  354. 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
  355. 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
  356. 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
  357. 0xfe, 0xfe, 0xff, 0xff, 0xff
  358. };
  359. pss_write(devc, 0x0010);
  360. pss_write(devc, log_scale[left] | 0x0000);
  361. pss_write(devc, 0x0010);
  362. pss_write(devc, log_scale[right] | 0x0100);
  363. }
  364. static void set_synth_volume(struct pss_confdata *devc, int volume)
  365. {
  366. int vol = ((0x8000*volume)/100L);
  367. pss_write(devc, 0x0080);
  368. pss_write(devc, vol);
  369. pss_write(devc, 0x0081);
  370. pss_write(devc, vol);
  371. }
  372. static void set_bass(struct pss_confdata *devc, int level)
  373. {
  374. int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
  375. pss_write(devc, 0x0010);
  376. pss_write(devc, vol | 0x0200);
  377. };
  378. static void set_treble(struct pss_confdata *devc, int level)
  379. {
  380. int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
  381. pss_write(devc, 0x0010);
  382. pss_write(devc, vol | 0x0300);
  383. };
  384. static void pss_mixer_reset(struct pss_confdata *devc)
  385. {
  386. set_master_volume(devc, 33, 33);
  387. set_bass(devc, 50);
  388. set_treble(devc, 50);
  389. set_synth_volume(devc, 30);
  390. pss_write (devc, 0x0010);
  391. pss_write (devc, 0x0800 | 0xce); /* Stereo */
  392. if(pss_mixer)
  393. {
  394. devc->mixer.volume_l = devc->mixer.volume_r = 33;
  395. devc->mixer.bass = 50;
  396. devc->mixer.treble = 50;
  397. devc->mixer.synth = 30;
  398. }
  399. }
  400. static int set_volume_mono(unsigned __user *p, unsigned int *aleft)
  401. {
  402. unsigned int left, volume;
  403. if (get_user(volume, p))
  404. return -EFAULT;
  405. left = volume & 0xff;
  406. if (left > 100)
  407. left = 100;
  408. *aleft = left;
  409. return 0;
  410. }
  411. static int set_volume_stereo(unsigned __user *p,
  412. unsigned int *aleft,
  413. unsigned int *aright)
  414. {
  415. unsigned int left, right, volume;
  416. if (get_user(volume, p))
  417. return -EFAULT;
  418. left = volume & 0xff;
  419. if (left > 100)
  420. left = 100;
  421. right = (volume >> 8) & 0xff;
  422. if (right > 100)
  423. right = 100;
  424. *aleft = left;
  425. *aright = right;
  426. return 0;
  427. }
  428. static int ret_vol_mono(int left)
  429. {
  430. return ((left << 8) | left);
  431. }
  432. static int ret_vol_stereo(int left, int right)
  433. {
  434. return ((right << 8) | left);
  435. }
  436. static int call_ad_mixer(struct pss_confdata *devc, unsigned int cmd,
  437. void __user *arg)
  438. {
  439. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  440. return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
  441. else
  442. return -EINVAL;
  443. }
  444. static int pss_mixer_ioctl (int dev, unsigned int cmd, void __user *arg)
  445. {
  446. struct pss_confdata *devc = mixer_devs[dev]->devc;
  447. int cmdf = cmd & 0xff;
  448. if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
  449. (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
  450. (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
  451. (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
  452. (cmdf != SOUND_MIXER_RECSRC))
  453. {
  454. return call_ad_mixer(devc, cmd, arg);
  455. }
  456. if (((cmd >> 8) & 0xff) != 'M')
  457. return -EINVAL;
  458. if (_SIOC_DIR (cmd) & _SIOC_WRITE)
  459. {
  460. switch (cmdf)
  461. {
  462. case SOUND_MIXER_RECSRC:
  463. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  464. return call_ad_mixer(devc, cmd, arg);
  465. else
  466. {
  467. int v;
  468. if (get_user(v, (int __user *)arg))
  469. return -EFAULT;
  470. if (v != 0)
  471. return -EINVAL;
  472. return 0;
  473. }
  474. case SOUND_MIXER_VOLUME:
  475. if (set_volume_stereo(arg,
  476. &devc->mixer.volume_l,
  477. &devc->mixer.volume_r))
  478. return -EFAULT;
  479. set_master_volume(devc, devc->mixer.volume_l,
  480. devc->mixer.volume_r);
  481. return ret_vol_stereo(devc->mixer.volume_l,
  482. devc->mixer.volume_r);
  483. case SOUND_MIXER_BASS:
  484. if (set_volume_mono(arg, &devc->mixer.bass))
  485. return -EFAULT;
  486. set_bass(devc, devc->mixer.bass);
  487. return ret_vol_mono(devc->mixer.bass);
  488. case SOUND_MIXER_TREBLE:
  489. if (set_volume_mono(arg, &devc->mixer.treble))
  490. return -EFAULT;
  491. set_treble(devc, devc->mixer.treble);
  492. return ret_vol_mono(devc->mixer.treble);
  493. case SOUND_MIXER_SYNTH:
  494. if (set_volume_mono(arg, &devc->mixer.synth))
  495. return -EFAULT;
  496. set_synth_volume(devc, devc->mixer.synth);
  497. return ret_vol_mono(devc->mixer.synth);
  498. default:
  499. return -EINVAL;
  500. }
  501. }
  502. else
  503. {
  504. int val, and_mask = 0, or_mask = 0;
  505. /*
  506. * Return parameters
  507. */
  508. switch (cmdf)
  509. {
  510. case SOUND_MIXER_DEVMASK:
  511. if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
  512. break;
  513. and_mask = ~0;
  514. or_mask = SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH;
  515. break;
  516. case SOUND_MIXER_STEREODEVS:
  517. if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
  518. break;
  519. and_mask = ~0;
  520. or_mask = SOUND_MASK_VOLUME;
  521. break;
  522. case SOUND_MIXER_RECMASK:
  523. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  524. return call_ad_mixer(devc, cmd, arg);
  525. break;
  526. case SOUND_MIXER_CAPS:
  527. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  528. return call_ad_mixer(devc, cmd, arg);
  529. or_mask = SOUND_CAP_EXCL_INPUT;
  530. break;
  531. case SOUND_MIXER_RECSRC:
  532. if (devc->ad_mixer_dev != NO_WSS_MIXER)
  533. return call_ad_mixer(devc, cmd, arg);
  534. break;
  535. case SOUND_MIXER_VOLUME:
  536. or_mask = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r);
  537. break;
  538. case SOUND_MIXER_BASS:
  539. or_mask = ret_vol_mono(devc->mixer.bass);
  540. break;
  541. case SOUND_MIXER_TREBLE:
  542. or_mask = ret_vol_mono(devc->mixer.treble);
  543. break;
  544. case SOUND_MIXER_SYNTH:
  545. or_mask = ret_vol_mono(devc->mixer.synth);
  546. break;
  547. default:
  548. return -EINVAL;
  549. }
  550. if (get_user(val, (int __user *)arg))
  551. return -EFAULT;
  552. val &= and_mask;
  553. val |= or_mask;
  554. if (put_user(val, (int __user *)arg))
  555. return -EFAULT;
  556. return val;
  557. }
  558. }
  559. static struct mixer_operations pss_mixer_operations =
  560. {
  561. .owner = THIS_MODULE,
  562. .id = "SOUNDPORT",
  563. .name = "PSS-AD1848",
  564. .ioctl = pss_mixer_ioctl
  565. };
  566. static void disable_all_emulations(void)
  567. {
  568. outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
  569. outw(0x0000, REG(CONF_WSS));
  570. outw(0x0000, REG(CONF_SB));
  571. outw(0x0000, REG(CONF_MIDI));
  572. outw(0x0000, REG(CONF_CDROM));
  573. }
  574. static void configure_nonsound_components(void)
  575. {
  576. /* Configure Joystick port */
  577. if(pss_enable_joystick)
  578. {
  579. outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
  580. printk(KERN_INFO "PSS: joystick enabled.\n");
  581. }
  582. else
  583. {
  584. printk(KERN_INFO "PSS: joystick port not enabled.\n");
  585. }
  586. /* Configure CDROM port */
  587. if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */
  588. printk(KERN_INFO "PSS: CDROM port not enabled.\n");
  589. } else if (!request_region(pss_cdrom_port, 2, "PSS CDROM")) {
  590. pss_cdrom_port = -1;
  591. printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
  592. } else {
  593. set_io_base(devc, CONF_CDROM, pss_cdrom_port);
  594. printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
  595. }
  596. }
  597. static int __init attach_pss(struct address_info *hw_config)
  598. {
  599. unsigned short id;
  600. char tmp[100];
  601. devc->base = hw_config->io_base;
  602. devc->irq = hw_config->irq;
  603. devc->dma = hw_config->dma;
  604. devc->osp = hw_config->osp;
  605. devc->ad_mixer_dev = NO_WSS_MIXER;
  606. if (!probe_pss(hw_config))
  607. return 0;
  608. id = inw(REG(PSS_ID)) & 0x00ff;
  609. /*
  610. * Disable all emulations. Will be enabled later (if required).
  611. */
  612. disable_all_emulations();
  613. #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
  614. if (sound_alloc_dma(hw_config->dma, "PSS"))
  615. {
  616. printk("pss.c: Can't allocate DMA channel.\n");
  617. release_region(hw_config->io_base, 0x10);
  618. release_region(hw_config->io_base+0x10, 0x9);
  619. return 0;
  620. }
  621. if (!set_irq(devc, CONF_PSS, devc->irq))
  622. {
  623. printk("PSS: IRQ allocation error.\n");
  624. release_region(hw_config->io_base, 0x10);
  625. release_region(hw_config->io_base+0x10, 0x9);
  626. return 0;
  627. }
  628. if (!set_dma(devc, CONF_PSS, devc->dma))
  629. {
  630. printk(KERN_ERR "PSS: DMA allocation error\n");
  631. release_region(hw_config->io_base, 0x10);
  632. release_region(hw_config->io_base+0x10, 0x9);
  633. return 0;
  634. }
  635. #endif
  636. configure_nonsound_components();
  637. pss_initialized = 1;
  638. sprintf(tmp, "ECHO-PSS Rev. %d", id);
  639. conf_printf(tmp, hw_config);
  640. return 1;
  641. }
  642. static int __init probe_pss_mpu(struct address_info *hw_config)
  643. {
  644. struct resource *ports;
  645. int timeout;
  646. if (!pss_initialized)
  647. return 0;
  648. ports = request_region(hw_config->io_base, 2, "mpu401");
  649. if (!ports) {
  650. printk(KERN_ERR "PSS: MPU I/O port conflict\n");
  651. return 0;
  652. }
  653. set_io_base(devc, CONF_MIDI, hw_config->io_base);
  654. if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
  655. printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
  656. goto fail;
  657. }
  658. if (!pss_synthLen) {
  659. printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
  660. goto fail;
  661. }
  662. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
  663. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  664. goto fail;
  665. }
  666. /*
  667. * Finally wait until the DSP algorithm has initialized itself and
  668. * deactivates receive interrupt.
  669. */
  670. for (timeout = 900000; timeout > 0; timeout--)
  671. {
  672. if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
  673. inb(hw_config->io_base); /* Discard it */
  674. else
  675. break; /* No more input */
  676. }
  677. if (!probe_mpu401(hw_config, ports))
  678. goto fail;
  679. attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
  680. if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
  681. midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
  682. return 1;
  683. fail:
  684. release_region(hw_config->io_base, 2);
  685. return 0;
  686. }
  687. static int pss_coproc_open(void *dev_info, int sub_device)
  688. {
  689. switch (sub_device)
  690. {
  691. case COPR_MIDI:
  692. if (pss_synthLen == 0)
  693. {
  694. printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
  695. return -EIO;
  696. }
  697. if (nonstandard_microcode)
  698. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  699. {
  700. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  701. return -EIO;
  702. }
  703. nonstandard_microcode = 0;
  704. break;
  705. default:
  706. break;
  707. }
  708. return 0;
  709. }
  710. static void pss_coproc_close(void *dev_info, int sub_device)
  711. {
  712. return;
  713. }
  714. static void pss_coproc_reset(void *dev_info)
  715. {
  716. if (pss_synthLen)
  717. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  718. {
  719. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  720. }
  721. nonstandard_microcode = 0;
  722. }
  723. static int download_boot_block(void *dev_info, copr_buffer * buf)
  724. {
  725. if (buf->len <= 0 || buf->len > sizeof(buf->data))
  726. return -EINVAL;
  727. if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
  728. {
  729. printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
  730. return -EIO;
  731. }
  732. nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
  733. return 0;
  734. }
  735. static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
  736. {
  737. copr_buffer *buf;
  738. copr_msg *mbuf;
  739. copr_debug_buf dbuf;
  740. unsigned short tmp;
  741. unsigned long flags;
  742. unsigned short *data;
  743. int i, err;
  744. /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
  745. switch (cmd)
  746. {
  747. case SNDCTL_COPR_RESET:
  748. pss_coproc_reset(dev_info);
  749. return 0;
  750. case SNDCTL_COPR_LOAD:
  751. buf = vmalloc(sizeof(copr_buffer));
  752. if (buf == NULL)
  753. return -ENOSPC;
  754. if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
  755. vfree(buf);
  756. return -EFAULT;
  757. }
  758. err = download_boot_block(dev_info, buf);
  759. vfree(buf);
  760. return err;
  761. case SNDCTL_COPR_SENDMSG:
  762. mbuf = vmalloc(sizeof(copr_msg));
  763. if (mbuf == NULL)
  764. return -ENOSPC;
  765. if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
  766. vfree(mbuf);
  767. return -EFAULT;
  768. }
  769. data = (unsigned short *)(mbuf->data);
  770. spin_lock_irqsave(&lock, flags);
  771. for (i = 0; i < mbuf->len; i++) {
  772. if (!pss_put_dspword(devc, *data++)) {
  773. spin_unlock_irqrestore(&lock,flags);
  774. mbuf->len = i; /* feed back number of WORDs sent */
  775. err = copy_to_user(arg, mbuf, sizeof(copr_msg));
  776. vfree(mbuf);
  777. return err ? -EFAULT : -EIO;
  778. }
  779. }
  780. spin_unlock_irqrestore(&lock,flags);
  781. vfree(mbuf);
  782. return 0;
  783. case SNDCTL_COPR_RCVMSG:
  784. err = 0;
  785. mbuf = vmalloc(sizeof(copr_msg));
  786. if (mbuf == NULL)
  787. return -ENOSPC;
  788. data = (unsigned short *)mbuf->data;
  789. spin_lock_irqsave(&lock, flags);
  790. for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
  791. mbuf->len = i; /* feed back number of WORDs read */
  792. if (!pss_get_dspword(devc, data++)) {
  793. if (i == 0)
  794. err = -EIO;
  795. break;
  796. }
  797. }
  798. spin_unlock_irqrestore(&lock,flags);
  799. if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
  800. err = -EFAULT;
  801. vfree(mbuf);
  802. return err;
  803. case SNDCTL_COPR_RDATA:
  804. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  805. return -EFAULT;
  806. spin_lock_irqsave(&lock, flags);
  807. if (!pss_put_dspword(devc, 0x00d0)) {
  808. spin_unlock_irqrestore(&lock,flags);
  809. return -EIO;
  810. }
  811. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  812. spin_unlock_irqrestore(&lock,flags);
  813. return -EIO;
  814. }
  815. if (!pss_get_dspword(devc, &tmp)) {
  816. spin_unlock_irqrestore(&lock,flags);
  817. return -EIO;
  818. }
  819. dbuf.parm1 = tmp;
  820. spin_unlock_irqrestore(&lock,flags);
  821. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  822. return -EFAULT;
  823. return 0;
  824. case SNDCTL_COPR_WDATA:
  825. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  826. return -EFAULT;
  827. spin_lock_irqsave(&lock, flags);
  828. if (!pss_put_dspword(devc, 0x00d1)) {
  829. spin_unlock_irqrestore(&lock,flags);
  830. return -EIO;
  831. }
  832. if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
  833. spin_unlock_irqrestore(&lock,flags);
  834. return -EIO;
  835. }
  836. tmp = (unsigned int)dbuf.parm2 & 0xffff;
  837. if (!pss_put_dspword(devc, tmp)) {
  838. spin_unlock_irqrestore(&lock,flags);
  839. return -EIO;
  840. }
  841. spin_unlock_irqrestore(&lock,flags);
  842. return 0;
  843. case SNDCTL_COPR_WCODE:
  844. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  845. return -EFAULT;
  846. spin_lock_irqsave(&lock, flags);
  847. if (!pss_put_dspword(devc, 0x00d3)) {
  848. spin_unlock_irqrestore(&lock,flags);
  849. return -EIO;
  850. }
  851. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  852. spin_unlock_irqrestore(&lock,flags);
  853. return -EIO;
  854. }
  855. tmp = (unsigned int)dbuf.parm2 & 0x00ff;
  856. if (!pss_put_dspword(devc, tmp)) {
  857. spin_unlock_irqrestore(&lock,flags);
  858. return -EIO;
  859. }
  860. tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
  861. if (!pss_put_dspword(devc, tmp)) {
  862. spin_unlock_irqrestore(&lock,flags);
  863. return -EIO;
  864. }
  865. spin_unlock_irqrestore(&lock,flags);
  866. return 0;
  867. case SNDCTL_COPR_RCODE:
  868. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  869. return -EFAULT;
  870. spin_lock_irqsave(&lock, flags);
  871. if (!pss_put_dspword(devc, 0x00d2)) {
  872. spin_unlock_irqrestore(&lock,flags);
  873. return -EIO;
  874. }
  875. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  876. spin_unlock_irqrestore(&lock,flags);
  877. return -EIO;
  878. }
  879. if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
  880. spin_unlock_irqrestore(&lock,flags);
  881. return -EIO;
  882. }
  883. dbuf.parm1 = tmp << 8;
  884. if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
  885. spin_unlock_irqrestore(&lock,flags);
  886. return -EIO;
  887. }
  888. dbuf.parm1 |= tmp & 0x00ff;
  889. spin_unlock_irqrestore(&lock,flags);
  890. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  891. return -EFAULT;
  892. return 0;
  893. default:
  894. return -EINVAL;
  895. }
  896. return -EINVAL;
  897. }
  898. static coproc_operations pss_coproc_operations =
  899. {
  900. "ADSP-2115",
  901. THIS_MODULE,
  902. pss_coproc_open,
  903. pss_coproc_close,
  904. pss_coproc_ioctl,
  905. pss_coproc_reset,
  906. &pss_data
  907. };
  908. static int __init probe_pss_mss(struct address_info *hw_config)
  909. {
  910. volatile int timeout;
  911. struct resource *ports;
  912. int my_mix = -999; /* gcc shut up */
  913. if (!pss_initialized)
  914. return 0;
  915. if (!request_region(hw_config->io_base, 4, "WSS config")) {
  916. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  917. return 0;
  918. }
  919. ports = request_region(hw_config->io_base + 4, 4, "ad1848");
  920. if (!ports) {
  921. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  922. release_region(hw_config->io_base, 4);
  923. return 0;
  924. }
  925. set_io_base(devc, CONF_WSS, hw_config->io_base);
  926. if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
  927. printk("PSS: WSS IRQ allocation error.\n");
  928. goto fail;
  929. }
  930. if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
  931. printk(KERN_ERR "PSS: WSS DMA allocation error\n");
  932. goto fail;
  933. }
  934. /*
  935. * For some reason the card returns 0xff in the WSS status register
  936. * immediately after boot. Probably MIDI+SB emulation algorithm
  937. * downloaded to the ADSP2115 spends some time initializing the card.
  938. * Let's try to wait until it finishes this task.
  939. */
  940. for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
  941. WSS_INITIALIZING); timeout++)
  942. ;
  943. outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
  944. for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
  945. (timeout < 100000); timeout++)
  946. ;
  947. if (!probe_ms_sound(hw_config, ports))
  948. goto fail;
  949. devc->ad_mixer_dev = NO_WSS_MIXER;
  950. if (pss_mixer)
  951. {
  952. if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
  953. "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
  954. &pss_mixer_operations,
  955. sizeof (struct mixer_operations),
  956. devc)) < 0)
  957. {
  958. printk(KERN_ERR "Could not install PSS mixer\n");
  959. goto fail;
  960. }
  961. }
  962. pss_mixer_reset(devc);
  963. attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
  964. if (hw_config->slots[0] != -1)
  965. {
  966. /* The MSS driver installed itself */
  967. audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
  968. if (pss_mixer && (num_mixers == (my_mix + 2)))
  969. {
  970. /* The MSS mixer installed */
  971. devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
  972. }
  973. }
  974. return 1;
  975. fail:
  976. release_region(hw_config->io_base + 4, 4);
  977. release_region(hw_config->io_base, 4);
  978. return 0;
  979. }
  980. static inline void __exit unload_pss(struct address_info *hw_config)
  981. {
  982. release_region(hw_config->io_base, 0x10);
  983. release_region(hw_config->io_base+0x10, 0x9);
  984. }
  985. static inline void __exit unload_pss_mpu(struct address_info *hw_config)
  986. {
  987. unload_mpu401(hw_config);
  988. }
  989. static inline void __exit unload_pss_mss(struct address_info *hw_config)
  990. {
  991. unload_ms_sound(hw_config);
  992. }
  993. static struct address_info cfg;
  994. static struct address_info cfg2;
  995. static struct address_info cfg_mpu;
  996. static int pss_io __initdata = -1;
  997. static int mss_io __initdata = -1;
  998. static int mss_irq __initdata = -1;
  999. static int mss_dma __initdata = -1;
  1000. static int mpu_io __initdata = -1;
  1001. static int mpu_irq __initdata = -1;
  1002. static bool pss_no_sound = 0; /* Just configure non-sound components */
  1003. static bool pss_keep_settings = 1; /* Keep hardware settings at module exit */
  1004. static char *pss_firmware = "/etc/sound/pss_synth";
  1005. module_param(pss_io, int, 0);
  1006. MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
  1007. module_param(mss_io, int, 0);
  1008. 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)");
  1009. module_param(mss_irq, int, 0);
  1010. MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
  1011. module_param(mss_dma, int, 0);
  1012. MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
  1013. module_param(mpu_io, int, 0);
  1014. 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)");
  1015. module_param(mpu_irq, int, 0);
  1016. MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
  1017. module_param(pss_cdrom_port, int, 0);
  1018. MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
  1019. module_param(pss_enable_joystick, bool, 0);
  1020. MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
  1021. module_param(pss_no_sound, bool, 0);
  1022. MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
  1023. module_param(pss_keep_settings, bool, 0);
  1024. MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
  1025. module_param(pss_firmware, charp, 0);
  1026. MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
  1027. module_param(pss_mixer, bool, 0);
  1028. 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.");
  1029. MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
  1030. 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).");
  1031. MODULE_LICENSE("GPL");
  1032. static int fw_load = 0;
  1033. static int pssmpu = 0, pssmss = 0;
  1034. /*
  1035. * Load a PSS sound card module
  1036. */
  1037. static int __init init_pss(void)
  1038. {
  1039. if(pss_no_sound) /* If configuring only nonsound components */
  1040. {
  1041. cfg.io_base = pss_io;
  1042. if(!probe_pss(&cfg))
  1043. return -ENODEV;
  1044. printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
  1045. printk(KERN_INFO "PSS: loading in no sound mode.\n");
  1046. disable_all_emulations();
  1047. configure_nonsound_components();
  1048. release_region(pss_io, 0x10);
  1049. release_region(pss_io + 0x10, 0x9);
  1050. return 0;
  1051. }
  1052. cfg.io_base = pss_io;
  1053. cfg2.io_base = mss_io;
  1054. cfg2.irq = mss_irq;
  1055. cfg2.dma = mss_dma;
  1056. cfg_mpu.io_base = mpu_io;
  1057. cfg_mpu.irq = mpu_irq;
  1058. if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
  1059. printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
  1060. return -EINVAL;
  1061. }
  1062. if (!pss_synth) {
  1063. fw_load = 1;
  1064. pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
  1065. }
  1066. if (!attach_pss(&cfg))
  1067. return -ENODEV;
  1068. /*
  1069. * Attach stuff
  1070. */
  1071. if (probe_pss_mpu(&cfg_mpu))
  1072. pssmpu = 1;
  1073. if (probe_pss_mss(&cfg2))
  1074. pssmss = 1;
  1075. return 0;
  1076. }
  1077. static void __exit cleanup_pss(void)
  1078. {
  1079. if(!pss_no_sound)
  1080. {
  1081. if (fw_load)
  1082. vfree(pss_synth);
  1083. if(pssmss)
  1084. unload_pss_mss(&cfg2);
  1085. if(pssmpu)
  1086. unload_pss_mpu(&cfg_mpu);
  1087. unload_pss(&cfg);
  1088. } else if (pss_cdrom_port != -1)
  1089. release_region(pss_cdrom_port, 2);
  1090. if(!pss_keep_settings) /* Keep hardware settings if asked */
  1091. {
  1092. disable_all_emulations();
  1093. printk(KERN_INFO "Resetting PSS sound card configurations.\n");
  1094. }
  1095. }
  1096. module_init(init_pss);
  1097. module_exit(cleanup_pss);
  1098. #ifndef MODULE
  1099. static int __init setup_pss(char *str)
  1100. {
  1101. /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
  1102. int ints[7];
  1103. str = get_options(str, ARRAY_SIZE(ints), ints);
  1104. pss_io = ints[1];
  1105. mss_io = ints[2];
  1106. mss_irq = ints[3];
  1107. mss_dma = ints[4];
  1108. mpu_io = ints[5];
  1109. mpu_irq = ints[6];
  1110. return 1;
  1111. }
  1112. __setup("pss=", setup_pss);
  1113. #endif