4 * The low level driver for the Personal Sound System (ECHO ESC614).
7 * Copyright (C) by Hannu Savolainen 1993-1997
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
14 * Thomas Sailer ioctl code reworked (vmalloc/vfree removed)
15 * Alan Cox modularisation, clean up.
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
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
60 #include <linux/config.h>
61 #include <linux/init.h>
62 #include <linux/module.h>
63 #include <linux/spinlock.h>
65 #include "sound_config.h"
66 #include "sound_firmware.h"
74 #define REG(x) (devc->base+x)
88 #define CONF_CDROM 0x16
89 #define CONF_MIDI 0x18
94 #define PSS_FLAG3 0x0800
95 #define PSS_FLAG2 0x0400
96 #define PSS_FLAG1 0x1000
97 #define PSS_FLAG0 0x0800
98 #define PSS_WRITE_EMPTY 0x8000
99 #define PSS_READ_FULL 0x4000
110 #define WSS_INITIALIZING 0x80
111 #define WSS_AUTOCALIBRATION 0x20
113 #define NO_WSS_MIXER -1
117 #include "pss_boot.h"
119 /* If compiled into kernel, it enable or disable pss mixer */
120 #ifdef CONFIG_PSS_MIXER
121 static unsigned char pss_mixer = 1;
123 static unsigned char pss_mixer;
127 typedef struct pss_mixerdata {
128 unsigned int volume_l;
129 unsigned int volume_r;
135 typedef struct pss_confdata {
144 static pss_confdata pss_data;
145 static pss_confdata *devc = &pss_data;
146 static spinlock_t lock=SPIN_LOCK_UNLOCKED;
148 static int pss_initialized;
149 static int nonstandard_microcode;
150 static int pss_cdrom_port = -1; /* Parameter for the PSS cdrom port */
151 static int pss_enable_joystick; /* Parameter for enabling the joystick */
153 static void pss_write(pss_confdata *devc, int data)
155 unsigned long i, limit;
157 limit = jiffies + HZ/10; /* The timeout is 0.1 seconds */
159 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
160 * called while interrupts are disabled. This means that the timer is
161 * disabled also. However the timeout situation is a abnormal condition.
162 * Normally the DSP should be ready to accept commands after just couple of
166 for (i = 0; i < 5000000 && time_before(jiffies, limit); i++)
168 if (inw(REG(PSS_STATUS)) & PSS_WRITE_EMPTY)
170 outw(data, REG(PSS_DATA));
174 printk(KERN_WARNING "PSS: DSP Command (%04x) Timeout.\n", data);
177 int __init probe_pss(struct address_info *hw_config)
182 devc->base = hw_config->io_base;
183 irq = devc->irq = hw_config->irq;
184 dma = devc->dma = hw_config->dma;
185 devc->osp = hw_config->osp;
187 if (devc->base != 0x220 && devc->base != 0x240)
188 if (devc->base != 0x230 && devc->base != 0x250) /* Some cards use these */
191 if (check_region(devc->base, 0x19 /*16*/)) {
192 printk(KERN_ERR "PSS: I/O port conflict\n");
195 id = inw(REG(PSS_ID));
196 if ((id >> 8) != 'E') {
197 printk(KERN_ERR "No PSS signature detected at 0x%x (0x%x)\n", devc->base, id);
203 static int set_irq(pss_confdata * devc, int dev, int irq)
205 static unsigned short irq_bits[16] =
207 0x0000, 0x0000, 0x0000, 0x0008,
208 0x0000, 0x0010, 0x0000, 0x0018,
209 0x0000, 0x0020, 0x0028, 0x0030,
210 0x0038, 0x0000, 0x0000, 0x0000
213 unsigned short tmp, bits;
215 if (irq < 0 || irq > 15)
218 tmp = inw(REG(dev)) & ~0x38; /* Load confreg, mask IRQ bits out */
220 if ((bits = irq_bits[irq]) == 0 && irq != 0)
222 printk(KERN_ERR "PSS: Invalid IRQ %d\n", irq);
225 outw(tmp | bits, REG(dev));
229 static int set_io_base(pss_confdata * devc, int dev, int base)
231 unsigned short tmp = inw(REG(dev)) & 0x003f;
232 unsigned short bits = (base & 0x0ffc) << 4;
234 outw(bits | tmp, REG(dev));
239 static int set_dma(pss_confdata * devc, int dev, int dma)
241 static unsigned short dma_bits[8] =
243 0x0001, 0x0002, 0x0000, 0x0003,
244 0x0000, 0x0005, 0x0006, 0x0007
247 unsigned short tmp, bits;
249 if (dma < 0 || dma > 7)
252 tmp = inw(REG(dev)) & ~0x07; /* Load confreg, mask DMA bits out */
254 if ((bits = dma_bits[dma]) == 0 && dma != 4)
256 printk(KERN_ERR "PSS: Invalid DMA %d\n", dma);
259 outw(tmp | bits, REG(dev));
263 static int pss_reset_dsp(pss_confdata * devc)
265 unsigned long i, limit = jiffies + HZ/10;
267 outw(0x2000, REG(PSS_CONTROL));
268 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
269 inw(REG(PSS_CONTROL));
270 outw(0x0000, REG(PSS_CONTROL));
274 static int pss_put_dspword(pss_confdata * devc, unsigned short word)
278 for (i = 0; i < 327680; i++)
280 val = inw(REG(PSS_STATUS));
281 if (val & PSS_WRITE_EMPTY)
283 outw(word, REG(PSS_DATA));
290 static int pss_get_dspword(pss_confdata * devc, unsigned short *word)
294 for (i = 0; i < 327680; i++)
296 val = inw(REG(PSS_STATUS));
297 if (val & PSS_READ_FULL)
299 *word = inw(REG(PSS_DATA));
306 static int pss_download_boot(pss_confdata * devc, unsigned char *block, int size, int flags)
311 if (flags & CPF_FIRST)
313 /*_____ Warn DSP software that a boot is coming */
314 outw(0x00fe, REG(PSS_DATA));
316 limit = jiffies + HZ/10;
317 for (i = 0; i < 32768 && time_before(jiffies, limit); i++)
318 if (inw(REG(PSS_DATA)) == 0x5500)
321 outw(*block++, REG(PSS_DATA));
325 while ((flags&CPF_LAST) || count<size )
329 for (j = 0; j < 327670; j++)
331 /*_____ Wait for BG to appear */
332 if (inw(REG(PSS_STATUS)) & PSS_FLAG3)
338 /* It's ok we timed out when the file was empty */
339 if (count >= size && flags & CPF_LAST)
344 printk(KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
348 /*_____ Send the next byte */
351 /* If not data in block send 0xffff */
352 outw (0xffff, REG (PSS_DATA));
356 /*_____ Send the next byte */
357 outw (*block++, REG (PSS_DATA));
362 if (flags & CPF_LAST)
365 outw(0, REG(PSS_DATA));
367 limit = jiffies + HZ/10;
368 for (i = 0; i < 32768 && (limit - jiffies >= 0); i++)
369 val = inw(REG(PSS_STATUS));
371 limit = jiffies + HZ/10;
372 for (i = 0; i < 32768 && (limit-jiffies >= 0); i++)
374 val = inw(REG(PSS_STATUS));
379 /* now read the version */
380 for (i = 0; i < 32000; i++)
382 val = inw(REG(PSS_STATUS));
383 if (val & PSS_READ_FULL)
389 val = inw(REG(PSS_DATA));
390 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
396 static void set_master_volume(pss_confdata *devc, int left, int right)
398 static unsigned char log_scale[101] = {
399 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
400 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
401 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
402 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
403 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
404 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
405 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
406 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
407 0xfe, 0xfe, 0xff, 0xff, 0xff
409 pss_write(devc, 0x0010);
410 pss_write(devc, log_scale[left] | 0x0000);
411 pss_write(devc, 0x0010);
412 pss_write(devc, log_scale[right] | 0x0100);
415 static void set_synth_volume(pss_confdata *devc, int volume)
417 int vol = ((0x8000*volume)/100L);
418 pss_write(devc, 0x0080);
419 pss_write(devc, vol);
420 pss_write(devc, 0x0081);
421 pss_write(devc, vol);
424 static void set_bass(pss_confdata *devc, int level)
426 int vol = (int)(((0xfd - 0xf0) * level)/100L) + 0xf0;
427 pss_write(devc, 0x0010);
428 pss_write(devc, vol | 0x0200);
431 static void set_treble(pss_confdata *devc, int level)
433 int vol = (((0xfd - 0xf0) * level)/100L) + 0xf0;
434 pss_write(devc, 0x0010);
435 pss_write(devc, vol | 0x0300);
438 static void pss_mixer_reset(pss_confdata *devc)
440 set_master_volume(devc, 33, 33);
442 set_treble(devc, 50);
443 set_synth_volume(devc, 30);
444 pss_write (devc, 0x0010);
445 pss_write (devc, 0x0800 | 0xce); /* Stereo */
449 devc->mixer.volume_l = devc->mixer.volume_r = 33;
450 devc->mixer.bass = 50;
451 devc->mixer.treble = 50;
452 devc->mixer.synth = 30;
456 static void arg_to_volume_mono(unsigned int volume, int *aleft)
460 left = volume & 0x00ff;
466 static void arg_to_volume_stereo(unsigned int volume, int *aleft, int *aright)
468 arg_to_volume_mono(volume, aleft);
469 arg_to_volume_mono(volume >> 8, aright);
472 static int ret_vol_mono(int left)
474 return ((left << 8) | left);
477 static int ret_vol_stereo(int left, int right)
479 return ((right << 8) | left);
482 static int call_ad_mixer(pss_confdata *devc,unsigned int cmd, caddr_t arg)
484 if (devc->ad_mixer_dev != NO_WSS_MIXER)
485 return mixer_devs[devc->ad_mixer_dev]->ioctl(devc->ad_mixer_dev, cmd, arg);
490 static int pss_mixer_ioctl (int dev, unsigned int cmd, caddr_t arg)
492 pss_confdata *devc = mixer_devs[dev]->devc;
493 int cmdf = cmd & 0xff;
495 if ((cmdf != SOUND_MIXER_VOLUME) && (cmdf != SOUND_MIXER_BASS) &&
496 (cmdf != SOUND_MIXER_TREBLE) && (cmdf != SOUND_MIXER_SYNTH) &&
497 (cmdf != SOUND_MIXER_DEVMASK) && (cmdf != SOUND_MIXER_STEREODEVS) &&
498 (cmdf != SOUND_MIXER_RECMASK) && (cmdf != SOUND_MIXER_CAPS) &&
499 (cmdf != SOUND_MIXER_RECSRC))
501 return call_ad_mixer(devc, cmd, arg);
504 if (((cmd >> 8) & 0xff) != 'M')
507 if (_SIOC_DIR (cmd) & _SIOC_WRITE)
511 case SOUND_MIXER_RECSRC:
512 if (devc->ad_mixer_dev != NO_WSS_MIXER)
513 return call_ad_mixer(devc, cmd, arg);
516 if (*(int *)arg != 0)
520 case SOUND_MIXER_VOLUME:
521 arg_to_volume_stereo(*(unsigned int *)arg, &devc->mixer.volume_l,
522 &devc->mixer.volume_r);
523 set_master_volume(devc, devc->mixer.volume_l,
524 devc->mixer.volume_r);
525 return ret_vol_stereo(devc->mixer.volume_l,
526 devc->mixer.volume_r);
528 case SOUND_MIXER_BASS:
529 arg_to_volume_mono(*(unsigned int *)arg,
531 set_bass(devc, devc->mixer.bass);
532 return ret_vol_mono(devc->mixer.bass);
534 case SOUND_MIXER_TREBLE:
535 arg_to_volume_mono(*(unsigned int *)arg,
536 &devc->mixer.treble);
537 set_treble(devc, devc->mixer.treble);
538 return ret_vol_mono(devc->mixer.treble);
540 case SOUND_MIXER_SYNTH:
541 arg_to_volume_mono(*(unsigned int *)arg,
543 set_synth_volume(devc, devc->mixer.synth);
544 return ret_vol_mono(devc->mixer.synth);
558 case SOUND_MIXER_DEVMASK:
559 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
560 *(int *)arg = 0; /* no mixer devices */
561 return (*(int *)arg |= SOUND_MASK_VOLUME | SOUND_MASK_BASS | SOUND_MASK_TREBLE | SOUND_MASK_SYNTH);
563 case SOUND_MIXER_STEREODEVS:
564 if (call_ad_mixer(devc, cmd, arg) == -EINVAL)
565 *(int *)arg = 0; /* no stereo devices */
566 return (*(int *)arg |= SOUND_MASK_VOLUME);
568 case SOUND_MIXER_RECMASK:
569 if (devc->ad_mixer_dev != NO_WSS_MIXER)
570 return call_ad_mixer(devc, cmd, arg);
572 return (*(int *)arg = 0); /* no record devices */
574 case SOUND_MIXER_CAPS:
575 if (devc->ad_mixer_dev != NO_WSS_MIXER)
576 return call_ad_mixer(devc, cmd, arg);
578 return (*(int *)arg = SOUND_CAP_EXCL_INPUT);
580 case SOUND_MIXER_RECSRC:
581 if (devc->ad_mixer_dev != NO_WSS_MIXER)
582 return call_ad_mixer(devc, cmd, arg);
584 return (*(int *)arg = 0); /* no record source */
586 case SOUND_MIXER_VOLUME:
587 return (*(int *)arg = ret_vol_stereo(devc->mixer.volume_l, devc->mixer.volume_r));
589 case SOUND_MIXER_BASS:
590 return (*(int *)arg = ret_vol_mono(devc->mixer.bass));
592 case SOUND_MIXER_TREBLE:
593 return (*(int *)arg = ret_vol_mono(devc->mixer.treble));
595 case SOUND_MIXER_SYNTH:
596 return (*(int *)arg = ret_vol_mono(devc->mixer.synth));
603 static struct mixer_operations pss_mixer_operations =
605 .owner = THIS_MODULE,
607 .name = "PSS-AD1848",
608 .ioctl = pss_mixer_ioctl
611 void disable_all_emulations(void)
613 outw(0x0000, REG(CONF_PSS)); /* 0x0400 enables joystick */
614 outw(0x0000, REG(CONF_WSS));
615 outw(0x0000, REG(CONF_SB));
616 outw(0x0000, REG(CONF_MIDI));
617 outw(0x0000, REG(CONF_CDROM));
620 void configure_nonsound_components(void)
622 /* Configure Joystick port */
624 if(pss_enable_joystick)
626 outw(0x0400, REG(CONF_PSS)); /* 0x0400 enables joystick */
627 printk(KERN_INFO "PSS: joystick enabled.\n");
631 printk(KERN_INFO "PSS: joystick port not enabled.\n");
634 /* Configure CDROM port */
636 if(pss_cdrom_port == -1) /* If cdrom port enablation wasn't requested */
638 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
640 else if(check_region(pss_cdrom_port, 2))
642 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
644 else if(!set_io_base(devc, CONF_CDROM, pss_cdrom_port))
646 printk(KERN_ERR "PSS: CDROM I/O port could not be set.\n");
648 else /* CDROM port successfully configured */
650 printk(KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
654 void __init attach_pss(struct address_info *hw_config)
659 devc->base = hw_config->io_base;
660 devc->irq = hw_config->irq;
661 devc->dma = hw_config->dma;
662 devc->osp = hw_config->osp;
663 devc->ad_mixer_dev = NO_WSS_MIXER;
665 if (!probe_pss(hw_config))
668 request_region(hw_config->io_base, 0x10, "PSS mixer, SB emulation");
669 request_region(hw_config->io_base + 0x10, 0x9, "PSS config");
671 id = inw(REG(PSS_ID)) & 0x00ff;
674 * Disable all emulations. Will be enabled later (if required).
677 disable_all_emulations();
679 #if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
680 if (sound_alloc_dma(hw_config->dma, "PSS"))
682 printk("pss.c: Can't allocate DMA channel.\n");
685 if (!set_irq(devc, CONF_PSS, devc->irq))
687 printk("PSS: IRQ allocation error.\n");
690 if (!set_dma(devc, CONF_PSS, devc->dma))
692 printk(KERN_ERR "PSS: DMA allocation error\n");
697 configure_nonsound_components();
699 sprintf(tmp, "ECHO-PSS Rev. %d", id);
700 conf_printf(tmp, hw_config);
703 int __init probe_pss_mpu(struct address_info *hw_config)
707 if (!pss_initialized)
710 if (check_region(hw_config->io_base, 2))
712 printk(KERN_ERR "PSS: MPU I/O port conflict\n");
715 if (!set_io_base(devc, CONF_MIDI, hw_config->io_base))
717 printk(KERN_ERR "PSS: MIDI base could not be set.\n");
720 if (!set_irq(devc, CONF_MIDI, hw_config->irq))
722 printk(KERN_ERR "PSS: MIDI IRQ allocation error.\n");
727 printk(KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
730 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
732 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
737 * Finally wait until the DSP algorithm has initialized itself and
738 * deactivates receive interrupt.
741 for (timeout = 900000; timeout > 0; timeout--)
743 if ((inb(hw_config->io_base + 1) & 0x80) == 0) /* Input data avail */
744 inb(hw_config->io_base); /* Discard it */
746 break; /* No more input */
749 return probe_mpu401(hw_config);
752 static int pss_coproc_open(void *dev_info, int sub_device)
757 if (pss_synthLen == 0)
759 printk(KERN_ERR "PSS: MIDI synth microcode not available.\n");
762 if (nonstandard_microcode)
763 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
765 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
768 nonstandard_microcode = 0;
777 static void pss_coproc_close(void *dev_info, int sub_device)
782 static void pss_coproc_reset(void *dev_info)
785 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
787 printk(KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
789 nonstandard_microcode = 0;
792 static int download_boot_block(void *dev_info, copr_buffer * buf)
794 if (buf->len <= 0 || buf->len > sizeof(buf->data))
797 if (!pss_download_boot(devc, buf->data, buf->len, buf->flags))
799 printk(KERN_ERR "PSS: Unable to load microcode block to DSP.\n");
802 nonstandard_microcode = 1; /* The MIDI microcode has been overwritten */
806 static int pss_coproc_ioctl(void *dev_info, unsigned int cmd, caddr_t arg, int local)
813 unsigned short *data;
815 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
819 case SNDCTL_COPR_RESET:
820 pss_coproc_reset(dev_info);
823 case SNDCTL_COPR_LOAD:
824 buf = (copr_buffer *) vmalloc(sizeof(copr_buffer));
827 if (copy_from_user(buf, arg, sizeof(copr_buffer))) {
831 err = download_boot_block(dev_info, buf);
835 case SNDCTL_COPR_SENDMSG:
836 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
839 if (copy_from_user(mbuf, arg, sizeof(copr_msg))) {
843 data = (unsigned short *)(mbuf->data);
844 spin_lock_irqsave(&lock, flags);
845 for (i = 0; i < mbuf->len; i++) {
846 if (!pss_put_dspword(devc, *data++)) {
847 spin_unlock_irqrestore(&lock,flags);
848 mbuf->len = i; /* feed back number of WORDs sent */
849 err = copy_to_user(arg, mbuf, sizeof(copr_msg));
851 return err ? -EFAULT : -EIO;
854 spin_unlock_irqrestore(&lock,flags);
858 case SNDCTL_COPR_RCVMSG:
860 mbuf = (copr_msg *)vmalloc(sizeof(copr_msg));
863 data = (unsigned short *)mbuf->data;
864 spin_lock_irqsave(&lock, flags);
865 for (i = 0; i < sizeof(mbuf->data)/sizeof(unsigned short); i++) {
866 mbuf->len = i; /* feed back number of WORDs read */
867 if (!pss_get_dspword(devc, data++)) {
873 spin_unlock_irqrestore(&lock,flags);
874 if (copy_to_user(arg, mbuf, sizeof(copr_msg)))
879 case SNDCTL_COPR_RDATA:
880 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
882 spin_lock_irqsave(&lock, flags);
883 if (!pss_put_dspword(devc, 0x00d0)) {
884 spin_unlock_irqrestore(&lock,flags);
887 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
888 spin_unlock_irqrestore(&lock,flags);
891 if (!pss_get_dspword(devc, &tmp)) {
892 spin_unlock_irqrestore(&lock,flags);
896 spin_unlock_irqrestore(&lock,flags);
897 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
901 case SNDCTL_COPR_WDATA:
902 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
904 spin_lock_irqsave(&lock, flags);
905 if (!pss_put_dspword(devc, 0x00d1)) {
906 spin_unlock_irqrestore(&lock,flags);
909 if (!pss_put_dspword(devc, (unsigned short) (dbuf.parm1 & 0xffff))) {
910 spin_unlock_irqrestore(&lock,flags);
913 tmp = (unsigned int)dbuf.parm2 & 0xffff;
914 if (!pss_put_dspword(devc, tmp)) {
915 spin_unlock_irqrestore(&lock,flags);
918 spin_unlock_irqrestore(&lock,flags);
921 case SNDCTL_COPR_WCODE:
922 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
924 spin_lock_irqsave(&lock, flags);
925 if (!pss_put_dspword(devc, 0x00d3)) {
926 spin_unlock_irqrestore(&lock,flags);
929 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
930 spin_unlock_irqrestore(&lock,flags);
933 tmp = (unsigned int)dbuf.parm2 & 0x00ff;
934 if (!pss_put_dspword(devc, tmp)) {
935 spin_unlock_irqrestore(&lock,flags);
938 tmp = ((unsigned int)dbuf.parm2 >> 8) & 0xffff;
939 if (!pss_put_dspword(devc, tmp)) {
940 spin_unlock_irqrestore(&lock,flags);
943 spin_unlock_irqrestore(&lock,flags);
946 case SNDCTL_COPR_RCODE:
947 if (copy_from_user(&dbuf, arg, sizeof(dbuf)))
949 spin_lock_irqsave(&lock, flags);
950 if (!pss_put_dspword(devc, 0x00d2)) {
951 spin_unlock_irqrestore(&lock,flags);
954 if (!pss_put_dspword(devc, (unsigned short)(dbuf.parm1 & 0xffff))) {
955 spin_unlock_irqrestore(&lock,flags);
958 if (!pss_get_dspword(devc, &tmp)) { /* Read MSB */
959 spin_unlock_irqrestore(&lock,flags);
962 dbuf.parm1 = tmp << 8;
963 if (!pss_get_dspword(devc, &tmp)) { /* Read LSB */
964 spin_unlock_irqrestore(&lock,flags);
967 dbuf.parm1 |= tmp & 0x00ff;
968 spin_unlock_irqrestore(&lock,flags);
969 if (copy_to_user(arg, &dbuf, sizeof(dbuf)))
979 static coproc_operations pss_coproc_operations =
990 static void __init attach_pss_mpu(struct address_info *hw_config)
992 attach_mpu401(hw_config, THIS_MODULE); /* Slot 1 */
993 if (hw_config->slots[1] != -1) /* The MPU driver installed itself */
994 midi_devs[hw_config->slots[1]]->coproc = &pss_coproc_operations;
997 static int __init probe_pss_mss(struct address_info *hw_config)
999 volatile int timeout;
1001 if (!pss_initialized)
1004 if (check_region(hw_config->io_base, 8))
1006 printk(KERN_ERR "PSS: WSS I/O port conflicts.\n");
1009 if (!set_io_base(devc, CONF_WSS, hw_config->io_base))
1011 printk("PSS: WSS base not settable.\n");
1014 if (!set_irq(devc, CONF_WSS, hw_config->irq))
1016 printk("PSS: WSS IRQ allocation error.\n");
1019 if (!set_dma(devc, CONF_WSS, hw_config->dma))
1021 printk(KERN_ERR "PSS: WSS DMA allocation error\n");
1025 * For some reason the card returns 0xff in the WSS status register
1026 * immediately after boot. Probably MIDI+SB emulation algorithm
1027 * downloaded to the ADSP2115 spends some time initializing the card.
1028 * Let's try to wait until it finishes this task.
1030 for (timeout = 0; timeout < 100000 && (inb(hw_config->io_base + WSS_INDEX) &
1031 WSS_INITIALIZING); timeout++)
1034 outb((0x0b), hw_config->io_base + WSS_INDEX); /* Required by some cards */
1036 for (timeout = 0; (inb(hw_config->io_base + WSS_DATA) & WSS_AUTOCALIBRATION) &&
1037 (timeout < 100000); timeout++)
1040 return probe_ms_sound(hw_config);
1043 static void __init attach_pss_mss(struct address_info *hw_config)
1045 int my_mix = -999; /* gcc shut up */
1047 devc->ad_mixer_dev = NO_WSS_MIXER;
1050 if ((my_mix = sound_install_mixer (MIXER_DRIVER_VERSION,
1051 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1052 &pss_mixer_operations,
1053 sizeof (struct mixer_operations),
1056 printk(KERN_ERR "Could not install PSS mixer\n");
1060 pss_mixer_reset(devc);
1061 attach_ms_sound(hw_config, THIS_MODULE); /* Slot 0 */
1063 if (hw_config->slots[0] != -1)
1065 /* The MSS driver installed itself */
1066 audio_devs[hw_config->slots[0]]->coproc = &pss_coproc_operations;
1067 if (pss_mixer && (num_mixers == (my_mix + 2)))
1069 /* The MSS mixer installed */
1070 devc->ad_mixer_dev = audio_devs[hw_config->slots[0]]->mixer_dev;
1075 static inline void __exit unload_pss(struct address_info *hw_config)
1077 release_region(hw_config->io_base, 0x10);
1078 release_region(hw_config->io_base+0x10, 0x9);
1081 static inline void __exit unload_pss_mpu(struct address_info *hw_config)
1083 unload_mpu401(hw_config);
1086 static inline void __exit unload_pss_mss(struct address_info *hw_config)
1088 unload_ms_sound(hw_config);
1092 static struct address_info cfg;
1093 static struct address_info cfg2;
1094 static struct address_info cfg_mpu;
1096 static int pss_io __initdata = -1;
1097 static int mss_io __initdata = -1;
1098 static int mss_irq __initdata = -1;
1099 static int mss_dma __initdata = -1;
1100 static int mpu_io __initdata = -1;
1101 static int mpu_irq __initdata = -1;
1102 static int pss_no_sound __initdata = 0; /* Just configure non-sound components */
1103 static int pss_keep_settings = 1; /* Keep hardware settings at module exit */
1104 static char *pss_firmware = "/etc/sound/pss_synth";
1106 MODULE_PARM(pss_io, "i");
1107 MODULE_PARM_DESC(pss_io, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1108 MODULE_PARM(mss_io, "i");
1109 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)");
1110 MODULE_PARM(mss_irq, "i");
1111 MODULE_PARM_DESC(mss_irq, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1112 MODULE_PARM(mss_dma, "i");
1113 MODULE_PARM_DESC(mss_dma, "Set WSS (audio) DMA (0, 1, 3)");
1114 MODULE_PARM(mpu_io, "i");
1115 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)");
1116 MODULE_PARM(mpu_irq, "i");
1117 MODULE_PARM_DESC(mpu_irq, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1118 MODULE_PARM(pss_cdrom_port, "i");
1119 MODULE_PARM_DESC(pss_cdrom_port, "Set the PSS CDROM port i/o base (0x340 or other)");
1120 MODULE_PARM(pss_enable_joystick, "i");
1121 MODULE_PARM_DESC(pss_enable_joystick, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1122 MODULE_PARM(pss_no_sound, "i");
1123 MODULE_PARM_DESC(pss_no_sound, "Configure sound compoents (0 - no, 1 - yes)");
1124 MODULE_PARM(pss_keep_settings, "i");
1125 MODULE_PARM_DESC(pss_keep_settings, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1126 MODULE_PARM(pss_firmware, "s");
1127 MODULE_PARM_DESC(pss_firmware, "Location of the firmware file (default - /etc/sound/pss_synth)");
1128 MODULE_PARM(pss_mixer, "b");
1129 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.");
1130 MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1131 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).");
1132 MODULE_LICENSE("GPL");
1135 static int fw_load = 0;
1136 static int pssmpu = 0, pssmss = 0;
1139 * Load a PSS sound card module
1142 static int __init init_pss(void)
1145 if(pss_no_sound) /* If configuring only nonsound components */
1147 cfg.io_base = pss_io;
1148 if(!probe_pss(&cfg))
1150 printk(KERN_INFO "ECHO-PSS Rev. %d\n", inw(REG(PSS_ID)) & 0x00ff);
1151 printk(KERN_INFO "PSS: loading in no sound mode.\n");
1152 disable_all_emulations();
1153 configure_nonsound_components();
1157 cfg.io_base = pss_io;
1159 cfg2.io_base = mss_io;
1163 cfg_mpu.io_base = mpu_io;
1164 cfg_mpu.irq = mpu_irq;
1166 if (cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 || cfg.dma == -1) {
1167 printk(KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1173 pss_synthLen = mod_firmware_load(pss_firmware, (void *) &pss_synth);
1175 if (!probe_pss(&cfg))
1181 if (probe_pss_mpu(&cfg_mpu)) {
1183 attach_pss_mpu(&cfg_mpu);
1185 if (probe_pss_mss(&cfg2)) {
1187 attach_pss_mss(&cfg2);
1193 static void __exit cleanup_pss(void)
1197 if(fw_load && pss_synth)
1200 unload_pss_mss(&cfg2);
1202 unload_pss_mpu(&cfg_mpu);
1206 if(!pss_keep_settings) /* Keep hardware settings if asked */
1208 disable_all_emulations();
1209 printk(KERN_INFO "Resetting PSS sound card configurations.\n");
1213 module_init(init_pss);
1214 module_exit(cleanup_pss);
1217 static int __init setup_pss(char *str)
1219 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1222 str = get_options(str, ARRAY_SIZE(ints), ints);
1234 __setup("pss=", setup_pss);