pss.c 32 KB

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