pss.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283
  1. /*
  2. * sound/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 fireware 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/config.h>
  59. #include <linux/init.h>
  60. #include <linux/module.h>
  61. #include <linux/spinlock.h>
  62. #include "sound_config.h"
  63. #include "sound_firmware.h"
  64. #include "ad1848.h"
  65. #include "mpu401.h"
  66. /*
  67. * PSS registers.
  68. */
  69. #define REG(x) (devc->base+x)
  70. #define PSS_DATA 0
  71. #define PSS_STATUS 2
  72. #define PSS_CONTROL 2
  73. #define PSS_ID 4
  74. #define PSS_IRQACK 4
  75. #define PSS_PIO 0x1a
  76. /*
  77. * Config registers
  78. */
  79. #define CONF_PSS 0x10
  80. #define CONF_WSS 0x12
  81. #define CONF_SB 0x14
  82. #define CONF_CDROM 0x16
  83. #define CONF_MIDI 0x18
  84. /*
  85. * Status bits.
  86. */
  87. #define PSS_FLAG3 0x0800
  88. #define PSS_FLAG2 0x0400
  89. #define PSS_FLAG1 0x1000
  90. #define PSS_FLAG0 0x0800
  91. #define PSS_WRITE_EMPTY 0x8000
  92. #define PSS_READ_FULL 0x4000
  93. /*
  94. * WSS registers
  95. */
  96. #define WSS_INDEX 4
  97. #define WSS_DATA 5
  98. /*
  99. * WSS status bits
  100. */
  101. #define WSS_INITIALIZING 0x80
  102. #define WSS_AUTOCALIBRATION 0x20
  103. #define NO_WSS_MIXER -1
  104. #include "coproc.h"
  105. #include "pss_boot.h"
  106. /* If compiled into kernel, it enable or disable pss mixer */
  107. #ifdef CONFIG_PSS_MIXER
  108. static int pss_mixer = 1;
  109. #else
  110. static int pss_mixer;
  111. #endif
  112. typedef struct pss_mixerdata {
  113. unsigned int volume_l;
  114. unsigned int volume_r;
  115. unsigned int bass;
  116. unsigned int treble;
  117. unsigned int synth;
  118. } pss_mixerdata;
  119. typedef struct pss_confdata {
  120. int base;
  121. int irq;
  122. int dma;
  123. int *osp;
  124. pss_mixerdata mixer;
  125. int ad_mixer_dev;
  126. } pss_confdata;
  127. static pss_confdata pss_data;
  128. static pss_confdata *devc = &pss_data;
  129. static DEFINE_SPINLOCK(lock);
  130. static int pss_initialized;
  131. static int nonstandard_microcode;
  132. static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
  133. static int pss_enable_joystick; /* Parameter for enabling the joystick */
  134. static coproc_operations pss_coproc_operations;
  135. static void pss_write(pss_confdata *devc, int data)
  136. {
  137. unsigned long i, limit;
  138. limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
  139. /*
  140. * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
  141. * called while interrupts are disabled. This means that the timer is
  142. * disabled also. However the timeout situation is a abnormal condition.
  143. * Normally the DSP should be ready to accept commands after just couple of
  144. * loops.
  145. */
  146. for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
  147. {
  148. if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
  149. {
  150. outw(data, REG(PSS_DATA));
  151. return;
  152. }
  153. }
  154. printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
  155. }
  156. static int __init probe_pss(struct address_info *hw_config)
  157. {
  158. unsigned short id;
  159. int irq, dma;
  160. devc->base = hw_config->io_base;
  161. irq = devc->irq = hw_config->irq;
  162. dma = devc->dma = hw_config->dma;
  163. devc->osp = hw_config->osp;
  164. if (devc->base != 0x220 && devc->base != 0x240)
  165. if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
  166. return 0;
  167. if (!request_region(devc->base, 0x10, "PSS mixer, SB emulation")) {
  168. printk(KERN_ERR "PSS: I/O port conflict\n");
  169. return 0;
  170. }
  171. id = inw(REG(PSS_ID));
  172. if ((id >> 8) != 'E') {
  173. printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
  174. release_region(devc->base, 0x10);
  175. return 0;
  176. }
  177. if (!request_region(devc->base + 0x10, 0x9, "PSS config")) {
  178. printk(KERN_ERR "PSS: I/O port conflict\n");
  179. release_region(devc->base, 0x10);
  180. return 0;
  181. }
  182. return 1;
  183. }
  184. static int set_irq(pss_confdata * devc, int dev, int irq)
  185. {
  186. static unsigned short irq_bits[16] =
  187. {
  188. 0x0000, 0x0000, 0x0000, 0x0008,
  189. 0x0000, 0x0010, 0x0000, 0x0018,
  190. 0x0000, 0x0020, 0x0028, 0x0030,
  191. 0x0038, 0x0000, 0x0000, 0x0000
  192. };
  193. unsigned short tmp, bits;
  194. if (irq < 0 || irq > 15)
  195. return 0;
  196. tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
  197. if ((bits = irq_bits[irq]) == 0 && irq != 0)
  198. {
  199. printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
  200. return 0;
  201. }
  202. outw(tmp | bits, REG(dev));
  203. return 1;
  204. }
  205. static int set_io_base(pss_confdata * devc, int dev, int base)
  206. {
  207. unsigned short tmp = inw(REG(dev)) & 0x003f;
  208. unsigned short bits = (base & 0x0ffc) << 4;
  209. outw(bits | tmp, REG(dev));
  210. return 1;
  211. }
  212. static int set_dma(pss_confdata * devc, int dev, int dma)
  213. {
  214. static unsigned short dma_bits[8] =
  215. {
  216. 0x0001, 0x0002, 0x0000, 0x0003,
  217. 0x0000, 0x0005, 0x0006, 0x0007
  218. };
  219. unsigned short tmp, bits;
  220. if (dma < 0 || dma > 7)
  221. return 0;
  222. tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
  223. if ((bits = dma_bits[dma]) == 0 && dma != 4)
  224. {
  225. printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
  226. return 0;
  227. }
  228. outw(tmp | bits, REG(dev));
  229. return 1;
  230. }
  231. static int pss_reset_dsp(pss_confdata * devc)
  232. {
  233. unsigned long i, limit = jiffies + HZ/10;
  234. outw(0x2000, REG(PSS_CONTROL));
  235. for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
  236. inw(REG(PSS_CONTROL));
  237. outw(0x0000, REG(PSS_CONTROL));
  238. return 1;
  239. }
  240. static int pss_put_dspword(pss_confdata * devc, unsigned short word)
  241. {
  242. int i, val;
  243. for (i = 0; i < 327680; i++)
  244. {
  245. val = inw(REG(PSS_STATUS));
  246. if (val & PSS_WRITE_EMPTY)
  247. {
  248. outw(word, REG(PSS_DATA));
  249. return 1;
  250. }
  251. }
  252. return 0;
  253. }
  254. static int pss_get_dspword(pss_confdata * devc, unsigned short *word)
  255. {
  256. int i, val;
  257. for (i = 0; i < 327680; i++)
  258. {
  259. val = inw(REG(PSS_STATUS));
  260. if (val & PSS_READ_FULL)
  261. {
  262. *word = inw(REG(PSS_DATA));
  263. return 1;
  264. }
  265. }
  266. return 0;
  267. }
  268. static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size, int flags)
  269. {
  270. int i, val, count;
  271. unsigned long limit;
  272. if (flags & CPF_FIRST)
  273. {
  274. /*_____ Warn DSP software that a boot is coming */
  275. outw(0x00fe, REG(PSS_DATA));
  276. limit = jiffies + HZ/10;
  277. for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
  278. if (inw(REG(PSS_DATA)) == 0x5500)
  279. break;
  280. outw(*block++, REG(PSS_DATA));
  281. pss_reset_dsp(devc);
  282. }
  283. count = 1;
  284. while ((flags&CPF_LAST) || count<size )
  285. {
  286. int j;
  287. for (j = 0; j < 327670; j++)
  288. {
  289. /*_____ Wait for BG to appear */
  290. if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
  291. break;
  292. }
  293. if (j == 327670)
  294. {
  295. /* It's ok we timed out when the file was empty */
  296. if (count >= size && flags & CPF_LAST)
  297. break;
  298. else
  299. {
  300. printk("\n");
  301. printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
  302. return 0;
  303. }
  304. }
  305. /*_____ Send the next byte */
  306. if (count >= size)
  307. {
  308. /* If not data in block send 0xffff */
  309. outw (0xffff, REG (PSS_DATA));
  310. }
  311. else
  312. {
  313. /*_____ Send the next byte */
  314. outw (*block++, REG (PSS_DATA));
  315. };
  316. count++;
  317. }
  318. if (flags & CPF_LAST)
  319. {
  320. /*_____ Why */
  321. outw(0, REG(PSS_DATA));
  322. limit = jiffies + HZ/10;
  323. for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
  324. val = inw(REG(PSS_STATUS));
  325. limit = jiffies + HZ/10;
  326. for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
  327. {
  328. val = inw(REG(PSS_STATUS));
  329. if (val & 0x4000)
  330. break;
  331. }
  332. /* now read the version */
  333. for (i = 0; i < 32000; i++)
  334. {
  335. val = inw(REG(PSS_STATUS));
  336. if (val & PSS_READ_FULL)
  337. break;
  338. }
  339. if (i == 32000)
  340. return 0;
  341. val = inw(REG(PSS_DATA));
  342. /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
  343. }
  344. return 1;
  345. }
  346. /* Mixer */
  347. static void set_master_volume(pss_confdata *devc, int left, int right)
  348. {
  349. static unsigned char log_scale[101] = {
  350. 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
  351. 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
  352. 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
  353. 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
  354. 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
  355. 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
  356. 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
  357. 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
  358. 0xfe, 0xfe, 0xff, 0xff, 0xff
  359. };
  360. pss_write(devc, 0x0010);
  361. pss_write(devc, log_scale[left] | 0x0000);
  362. pss_write(devc, 0x0010);
  363. pss_write(devc, log_scale[right] | 0x0100);
  364. }
  365. static void set_synth_volume(pss_confdata *devc, int volume)
  366. {
  367. int vol = ((0x8000*volume)/100L);
  368. pss_write(devc, 0x0080);
  369. pss_write(devc, vol);
  370. pss_write(devc, 0x0081);
  371. pss_write(devc, vol);
  372. }
  373. static void set_bass(pss_confdata *devc, int level)
  374. {
  375. int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
  376. pss_write(devc, 0x0010);
  377. pss_write(devc, vol | 0x0200);
  378. };
  379. static void set_treble(pss_confdata *devc, int level)
  380. {
  381. int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
  382. pss_write(devc, 0x0010);
  383. pss_write(devc, vol | 0x0300);
  384. };
  385. static void pss_mixer_reset(pss_confdata *devc)
  386. {
  387. set_master_volume(devc, 33, 33);
  388. set_bass(devc, 50);
  389. set_treble(devc, 50);
  390. set_synth_volume(devc, 30);
  391. pss_write (devc, 0x0010);
  392. pss_write (devc, 0x0800 | 0xce); /* Stereo */
  393. if(pss_mixer)
  394. {
  395. devc->mixer.volume_l = devc->mixer.volume_r = 33;
  396. devc->mixer.bass = 50;
  397. devc->mixer.treble = 50;
  398. devc->mixer.synth = 30;
  399. }
  400. }
  401. static int set_volume_mono(unsigned __user *p, int *aleft)
  402. {
  403. int left;
  404. unsigned volume;
  405. if (get_user(volume, p))
  406. return -EFAULT;
  407. left = volume & 0xff;
  408. if (left > 100)
  409. left = 100;
  410. *aleft = left;
  411. return 0;
  412. }
  413. static int set_volume_stereo(unsigned __user *p, int *aleft, int *aright)
  414. {
  415. int left, right;
  416. unsigned volume;
  417. if (get_user(volume, p))
  418. return -EFAULT;
  419. left = volume & 0xff;
  420. if (left > 100)
  421. left = 100;
  422. right = (volume >> 8) & 0xff;
  423. if (right > 100)
  424. right = 100;
  425. *aleft = left;
  426. *aright = right;
  427. return 0;
  428. }
  429. static int ret_vol_mono(int left)
  430. {
  431. return ((left << 8) | left);
  432. }
  433. static int ret_vol_stereo(int left, int right)
  434. {
  435. return ((right << 8) | left);
  436. }
  437. static int call_ad_mixer(pss_confdata *devc,unsigned int cmd, 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. 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. {
  589. printk(KERN_INFO "PSS: CDROM port not enabled.\n");
  590. }
  591. else if(check_region(pss_cdrom_port, 2))
  592. {
  593. printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
  594. }
  595. else if(!set_io_base(devc, CONF_CDROM, pss_cdrom_port))
  596. {
  597. printk(KERN_ERR "PSS: CDROM I/O port could not be set.\n");
  598. }
  599. else /* CDROM port successfully configured */
  600. {
  601. printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
  602. }
  603. }
  604. static int __init attach_pss(struct address_info *hw_config)
  605. {
  606. unsigned short id;
  607. char tmp[100];
  608. devc->base = hw_config->io_base;
  609. devc->irq = hw_config->irq;
  610. devc->dma = hw_config->dma;
  611. devc->osp = hw_config->osp;
  612. devc->ad_mixer_dev = NO_WSS_MIXER;
  613. if (!probe_pss(hw_config))
  614. return 0;
  615. id = inw(REG(PSS_ID)) & 0x00ff;
  616. /*
  617. * Disable all emulations. Will be enabled later (if required).
  618. */
  619. disable_all_emulations();
  620. #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
  621. if (sound_alloc_dma(hw_config->dma, "PSS"))
  622. {
  623. printk("pss.c: Can't allocate DMA channel.\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_irq(devc, CONF_PSS, devc->irq))
  629. {
  630. printk("PSS: IRQ 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. if (!set_dma(devc, CONF_PSS, devc->dma))
  636. {
  637. printk(KERN_ERR "PSS: DMA allocation error\n");
  638. release_region(hw_config->io_base, 0x10);
  639. release_region(hw_config->io_base+0x10, 0x9);
  640. return 0;
  641. }
  642. #endif
  643. configure_nonsound_components();
  644. pss_initialized = 1;
  645. sprintf(tmp, "ECHO-PSS Rev. %d", id);
  646. conf_printf(tmp, hw_config);
  647. return 1;
  648. }
  649. static int __init probe_pss_mpu(struct address_info *hw_config)
  650. {
  651. struct resource *ports;
  652. int timeout;
  653. if (!pss_initialized)
  654. return 0;
  655. ports = request_region(hw_config->io_base, 2, "mpu401");
  656. if (!ports) {
  657. printk(KERN_ERR "PSS: MPU I/O port conflict\n");
  658. return 0;
  659. }
  660. if (!set_io_base(devc, CONF_MIDI, hw_config->io_base)) {
  661. printk(KERN_ERR "PSS: MIDI base could not be set.\n");
  662. goto fail;
  663. }
  664. if (!set_irq(devc, CONF_MIDI, hw_config->irq)) {
  665. printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
  666. goto fail;
  667. }
  668. if (!pss_synthLen) {
  669. printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
  670. goto fail;
  671. }
  672. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
  673. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  674. goto fail;
  675. }
  676. /*
  677. * Finally wait until the DSP algorithm has initialized itself and
  678. * deactivates receive interrupt.
  679. */
  680. for (timeout = 900000; timeout > 0; timeout--)
  681. {
  682. if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
  683. inb(hw_config->io_base); /* Discard it */
  684. else
  685. break; /* No more input */
  686. }
  687. if (!probe_mpu401(hw_config, ports))
  688. goto fail;
  689. attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
  690. if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
  691. midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
  692. return 1;
  693. fail:
  694. release_region(hw_config->io_base, 2);
  695. return 0;
  696. }
  697. static int pss_coproc_open(void *dev_info, int sub_device)
  698. {
  699. switch (sub_device)
  700. {
  701. case COPR_MIDI:
  702. if (pss_synthLen == 0)
  703. {
  704. printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
  705. return -EIO;
  706. }
  707. if (nonstandard_microcode)
  708. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  709. {
  710. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  711. return -EIO;
  712. }
  713. nonstandard_microcode = 0;
  714. break;
  715. default:
  716. break;
  717. }
  718. return 0;
  719. }
  720. static void pss_coproc_close(void *dev_info, int sub_device)
  721. {
  722. return;
  723. }
  724. static void pss_coproc_reset(void *dev_info)
  725. {
  726. if (pss_synthLen)
  727. if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
  728. {
  729. printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
  730. }
  731. nonstandard_microcode = 0;
  732. }
  733. static int download_boot_block(void *dev_info, copr_buffer * buf)
  734. {
  735. if (buf->len <= 0 || buf->len > sizeof(buf->data))
  736. return -EINVAL;
  737. if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
  738. {
  739. printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
  740. return -EIO;
  741. }
  742. nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
  743. return 0;
  744. }
  745. static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, void __user *arg, int local)
  746. {
  747. copr_buffer *buf;
  748. copr_msg *mbuf;
  749. copr_debug_buf dbuf;
  750. unsigned short tmp;
  751. unsigned long flags;
  752. unsigned short *data;
  753. int i, err;
  754. /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
  755. switch (cmd)
  756. {
  757. case SNDCTL_COPR_RESET:
  758. pss_coproc_reset(dev_info);
  759. return 0;
  760. case SNDCTL_COPR_LOAD:
  761. buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
  762. if (buf == NULL)
  763. return -ENOSPC;
  764. if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
  765. vfree(buf);
  766. return -EFAULT;
  767. }
  768. err = download_boot_block(dev_info, buf);
  769. vfree(buf);
  770. return err;
  771. case SNDCTL_COPR_SENDMSG:
  772. mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
  773. if (mbuf == NULL)
  774. return -ENOSPC;
  775. if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
  776. vfree(mbuf);
  777. return -EFAULT;
  778. }
  779. data = (unsigned short *)(mbuf->data);
  780. spin_lock_irqsave(&lock, flags);
  781. for (i = 0; i < mbuf->len; i++) {
  782. if (!pss_put_dspword(devc, *data++)) {
  783. spin_unlock_irqrestore(&lock,flags);
  784. mbuf->len = i; /* feed back number of WORDs sent */
  785. err = copy_to_user(arg, mbuf, sizeof(copr_msg));
  786. vfree(mbuf);
  787. return err ? -EFAULT : -EIO;
  788. }
  789. }
  790. spin_unlock_irqrestore(&lock,flags);
  791. vfree(mbuf);
  792. return 0;
  793. case SNDCTL_COPR_RCVMSG:
  794. err = 0;
  795. mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
  796. if (mbuf == NULL)
  797. return -ENOSPC;
  798. data = (unsigned short *)mbuf->data;
  799. spin_lock_irqsave(&lock, flags);
  800. for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
  801. mbuf->len = i; /* feed back number of WORDs read */
  802. if (!pss_get_dspword(devc, data++)) {
  803. if (i == 0)
  804. err = -EIO;
  805. break;
  806. }
  807. }
  808. spin_unlock_irqrestore(&lock,flags);
  809. if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
  810. err = -EFAULT;
  811. vfree(mbuf);
  812. return err;
  813. case SNDCTL_COPR_RDATA:
  814. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  815. return -EFAULT;
  816. spin_lock_irqsave(&lock, flags);
  817. if (!pss_put_dspword(devc, 0x00d0)) {
  818. spin_unlock_irqrestore(&lock,flags);
  819. return -EIO;
  820. }
  821. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  822. spin_unlock_irqrestore(&lock,flags);
  823. return -EIO;
  824. }
  825. if (!pss_get_dspword(devc, &tmp)) {
  826. spin_unlock_irqrestore(&lock,flags);
  827. return -EIO;
  828. }
  829. dbuf.parm1 = tmp;
  830. spin_unlock_irqrestore(&lock,flags);
  831. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  832. return -EFAULT;
  833. return 0;
  834. case SNDCTL_COPR_WDATA:
  835. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  836. return -EFAULT;
  837. spin_lock_irqsave(&lock, flags);
  838. if (!pss_put_dspword(devc, 0x00d1)) {
  839. spin_unlock_irqrestore(&lock,flags);
  840. return -EIO;
  841. }
  842. if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
  843. spin_unlock_irqrestore(&lock,flags);
  844. return -EIO;
  845. }
  846. tmp = (unsigned int)dbuf.parm2 & 0xffff;
  847. if (!pss_put_dspword(devc, tmp)) {
  848. spin_unlock_irqrestore(&lock,flags);
  849. return -EIO;
  850. }
  851. spin_unlock_irqrestore(&lock,flags);
  852. return 0;
  853. case SNDCTL_COPR_WCODE:
  854. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  855. return -EFAULT;
  856. spin_lock_irqsave(&lock, flags);
  857. if (!pss_put_dspword(devc, 0x00d3)) {
  858. spin_unlock_irqrestore(&lock,flags);
  859. return -EIO;
  860. }
  861. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  862. spin_unlock_irqrestore(&lock,flags);
  863. return -EIO;
  864. }
  865. tmp = (unsigned int)dbuf.parm2 & 0x00ff;
  866. if (!pss_put_dspword(devc, tmp)) {
  867. spin_unlock_irqrestore(&lock,flags);
  868. return -EIO;
  869. }
  870. tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
  871. if (!pss_put_dspword(devc, tmp)) {
  872. spin_unlock_irqrestore(&lock,flags);
  873. return -EIO;
  874. }
  875. spin_unlock_irqrestore(&lock,flags);
  876. return 0;
  877. case SNDCTL_COPR_RCODE:
  878. if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
  879. return -EFAULT;
  880. spin_lock_irqsave(&lock, flags);
  881. if (!pss_put_dspword(devc, 0x00d2)) {
  882. spin_unlock_irqrestore(&lock,flags);
  883. return -EIO;
  884. }
  885. if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
  886. spin_unlock_irqrestore(&lock,flags);
  887. return -EIO;
  888. }
  889. if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
  890. spin_unlock_irqrestore(&lock,flags);
  891. return -EIO;
  892. }
  893. dbuf.parm1 = tmp << 8;
  894. if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
  895. spin_unlock_irqrestore(&lock,flags);
  896. return -EIO;
  897. }
  898. dbuf.parm1 |= tmp & 0x00ff;
  899. spin_unlock_irqrestore(&lock,flags);
  900. if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
  901. return -EFAULT;
  902. return 0;
  903. default:
  904. return -EINVAL;
  905. }
  906. return -EINVAL;
  907. }
  908. static coproc_operations pss_coproc_operations =
  909. {
  910. "ADSP-2115",
  911. THIS_MODULE,
  912. pss_coproc_open,
  913. pss_coproc_close,
  914. pss_coproc_ioctl,
  915. pss_coproc_reset,
  916. &pss_data
  917. };
  918. static int __init probe_pss_mss(struct address_info *hw_config)
  919. {
  920. volatile int timeout;
  921. struct resource *ports;
  922. int my_mix = -999; /* gcc shut up */
  923. if (!pss_initialized)
  924. return 0;
  925. if (!request_region(hw_config->io_base, 4, "WSS config")) {
  926. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  927. return 0;
  928. }
  929. ports = request_region(hw_config->io_base + 4, 4, "ad1848");
  930. if (!ports) {
  931. printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
  932. release_region(hw_config->io_base, 4);
  933. return 0;
  934. }
  935. if (!set_io_base(devc, CONF_WSS, hw_config->io_base)) {
  936. printk("PSS: WSS base not settable.\n");
  937. goto fail;
  938. }
  939. if (!set_irq(devc, CONF_WSS, hw_config->irq)) {
  940. printk("PSS: WSS IRQ allocation error.\n");
  941. goto fail;
  942. }
  943. if (!set_dma(devc, CONF_WSS, hw_config->dma)) {
  944. printk(KERN_ERR "PSS: WSS DMA allocation error\n");
  945. goto fail;
  946. }
  947. /*
  948. * For some reason the card returns 0xff in the WSS status register
  949. * immediately after boot. Probably MIDI+SB emulation algorithm
  950. * downloaded to the ADSP2115 spends some time initializing the card.
  951. * Let's try to wait until it finishes this task.
  952. */
  953. for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
  954. WSS_INITIALIZING); timeout++)
  955. ;
  956. outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
  957. for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
  958. (timeout < 100000); timeout++)
  959. ;
  960. if (!probe_ms_sound(hw_config, ports))
  961. goto fail;
  962. devc->ad_mixer_dev = NO_WSS_MIXER;
  963. if (pss_mixer)
  964. {
  965. if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
  966. "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
  967. &pss_mixer_operations,
  968. sizeof (struct mixer_operations),
  969. devc)) < 0)
  970. {
  971. printk(KERN_ERR "Could not install PSS mixer\n");
  972. goto fail;
  973. }
  974. }
  975. pss_mixer_reset(devc);
  976. attach_ms_sound(hw_config, ports, THIS_MODULE); /* Slot 0 */
  977. if (hw_config->slots[0] != -1)
  978. {
  979. /* The MSS driver installed itself */
  980. audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
  981. if (pss_mixer && (num_mixers == (my_mix + 2)))
  982. {
  983. /* The MSS mixer installed */
  984. devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
  985. }
  986. }
  987. return 1;
  988. fail:
  989. release_region(hw_config->io_base + 4, 4);
  990. release_region(hw_config->io_base, 4);
  991. return 0;
  992. }
  993. static inline void __exit unload_pss(struct address_info *hw_config)
  994. {
  995. release_region(hw_config->io_base, 0x10);
  996. release_region(hw_config->io_base+0x10, 0x9);
  997. }
  998. static inline void __exit unload_pss_mpu(struct address_info *hw_config)
  999. {
  1000. unload_mpu401(hw_config);
  1001. }
  1002. static inline void __exit unload_pss_mss(struct address_info *hw_config)
  1003. {
  1004. unload_ms_sound(hw_config);
  1005. }
  1006. static struct address_info cfg;
  1007. static struct address_info cfg2;
  1008. static struct address_info cfg_mpu;
  1009. static int pss_io __initdata = -1;
  1010. static int mss_io __initdata = -1;
  1011. static int mss_irq __initdata = -1;
  1012. static int mss_dma __initdata = -1;
  1013. static int mpu_io __initdata = -1;
  1014. static int mpu_irq __initdata = -1;
  1015. static int pss_no_sound = 0; /* Just configure non-sound components */
  1016. static int pss_keep_settings = 1; /* Keep hardware settings at module exit */
  1017. static char *pss_firmware = "/etc/sound/pss_synth";
  1018. module_param(pss_io, int, 0);
  1019. MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
  1020. module_param(mss_io, int, 0);
  1021. 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)");
  1022. module_param(mss_irq, int, 0);
  1023. MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
  1024. module_param(mss_dma, int, 0);
  1025. MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
  1026. module_param(mpu_io, int, 0);
  1027. 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)");
  1028. module_param(mpu_irq, int, 0);
  1029. MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
  1030. module_param(pss_cdrom_port, int, 0);
  1031. MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
  1032. module_param(pss_enable_joystick, bool, 0);
  1033. MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
  1034. module_param(pss_no_sound, bool, 0);
  1035. MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
  1036. module_param(pss_keep_settings, bool, 0);
  1037. MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
  1038. module_param(pss_firmware, charp, 0);
  1039. MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
  1040. module_param(pss_mixer, bool, 0);
  1041. 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.");
  1042. MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
  1043. 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).");
  1044. MODULE_LICENSE("GPL");
  1045. static int fw_load = 0;
  1046. static int pssmpu = 0, pssmss = 0;
  1047. /*
  1048. * Load a PSS sound card module
  1049. */
  1050. static int __init init_pss(void)
  1051. {
  1052. if(pss_no_sound) /* If configuring only nonsound components */
  1053. {
  1054. cfg.io_base = pss_io;
  1055. if(!probe_pss(&cfg))
  1056. return -ENODEV;
  1057. printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
  1058. printk(KERN_INFO "PSS: loading in no sound mode.\n");
  1059. disable_all_emulations();
  1060. configure_nonsound_components();
  1061. release_region(pss_io, 0x10);
  1062. release_region(pss_io + 0x10, 0x9);
  1063. return 0;
  1064. }
  1065. cfg.io_base = pss_io;
  1066. cfg2.io_base = mss_io;
  1067. cfg2.irq = mss_irq;
  1068. cfg2.dma = mss_dma;
  1069. cfg_mpu.io_base = mpu_io;
  1070. cfg_mpu.irq = mpu_irq;
  1071. if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
  1072. printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
  1073. return -EINVAL;
  1074. }
  1075. if (!pss_synth) {
  1076. fw_load = 1;
  1077. pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
  1078. }
  1079. if (!attach_pss(&cfg))
  1080. return -ENODEV;
  1081. /*
  1082. * Attach stuff
  1083. */
  1084. if (probe_pss_mpu(&cfg_mpu))
  1085. pssmpu = 1;
  1086. if (probe_pss_mss(&cfg2))
  1087. pssmss = 1;
  1088. return 0;
  1089. }
  1090. static void __exit cleanup_pss(void)
  1091. {
  1092. if(!pss_no_sound)
  1093. {
  1094. if(fw_load && pss_synth)
  1095. vfree(pss_synth);
  1096. if(pssmss)
  1097. unload_pss_mss(&cfg2);
  1098. if(pssmpu)
  1099. unload_pss_mpu(&cfg_mpu);
  1100. unload_pss(&cfg);
  1101. }
  1102. if(!pss_keep_settings) /* Keep hardware settings if asked */
  1103. {
  1104. disable_all_emulations();
  1105. printk(KERN_INFO "Resetting PSS sound card configurations.\n");
  1106. }
  1107. }
  1108. module_init(init_pss);
  1109. module_exit(cleanup_pss);
  1110. #ifndef MODULE
  1111. static int __init setup_pss(char *str)
  1112. {
  1113. /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
  1114. int ints[7];
  1115. str = get_options(str, ARRAY_SIZE(ints), ints);
  1116. pss_io = ints[1];
  1117. mss_io = ints[2];
  1118. mss_irq = ints[3];
  1119. mss_dma = ints[4];
  1120. mpu_io = ints[5];
  1121. mpu_irq = ints[6];
  1122. return 1;
  1123. }
  1124. __setup("pss=", setup_pss);
  1125. #endif