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/init.h>
61 #include <linux/module.h>
62 #include <linux/spinlock.h>
64 #include "sound_config.h"
65 #include "sound_firmware.h"
73 #define REG(x) (devc->base+x)
87 #define CONF_CDROM 0x16
88 #define CONF_MIDI 0x18
93 #define PSS_FLAG3 0x0800
94 #define PSS_FLAG2 0x0400
95 #define PSS_FLAG1 0x1000
96 #define PSS_FLAG0 0x0800
97 #define PSS_WRITE_EMPTY 0x8000
98 #define PSS_READ_FULL 0x4000
109 #define WSS_INITIALIZING 0x80
110 #define WSS_AUTOCALIBRATION 0x20
112 #define NO_WSS_MIXER -1
116 #include "pss_boot.h"
118 /* If compiled into kernel, it enable or disable pss mixer */
119 #ifdef CONFIG_PSS_MIXER
120 static int pss_mixer
= 1;
122 static int pss_mixer
;
126 typedef struct pss_mixerdata
{
127 unsigned int volume_l
;
128 unsigned int volume_r
;
134 typedef struct pss_confdata
{
143 static pss_confdata pss_data
;
144 static pss_confdata
*devc
= &pss_data
;
145 static DEFINE_SPINLOCK(lock
);
147 static int pss_initialized
;
148 static int nonstandard_microcode
;
149 static int pss_cdrom_port
= -1; /* Parameter for the PSS cdrom port */
150 static int pss_enable_joystick
; /* Parameter for enabling the joystick */
151 static coproc_operations pss_coproc_operations
;
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 static 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 (!request_region(devc
->base
, 0x10, "PSS mixer, SB emulation")) {
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
);
198 release_region(devc
->base
, 0x10);
201 if (!request_region(devc
->base
+ 0x10, 0x9, "PSS config")) {
202 printk(KERN_ERR
"PSS: I/O port conflict\n");
203 release_region(devc
->base
, 0x10);
209 static int set_irq(pss_confdata
* devc
, int dev
, int irq
)
211 static unsigned short irq_bits
[16] =
213 0x0000, 0x0000, 0x0000, 0x0008,
214 0x0000, 0x0010, 0x0000, 0x0018,
215 0x0000, 0x0020, 0x0028, 0x0030,
216 0x0038, 0x0000, 0x0000, 0x0000
219 unsigned short tmp
, bits
;
221 if (irq
< 0 || irq
> 15)
224 tmp
= inw(REG(dev
)) & ~0x38; /* Load confreg, mask IRQ bits out */
226 if ((bits
= irq_bits
[irq
]) == 0 && irq
!= 0)
228 printk(KERN_ERR
"PSS: Invalid IRQ %d\n", irq
);
231 outw(tmp
| bits
, REG(dev
));
235 static void set_io_base(pss_confdata
* devc
, int dev
, int base
)
237 unsigned short tmp
= inw(REG(dev
)) & 0x003f;
238 unsigned short bits
= (base
& 0x0ffc) << 4;
240 outw(bits
| tmp
, REG(dev
));
243 static int set_dma(pss_confdata
* devc
, int dev
, int dma
)
245 static unsigned short dma_bits
[8] =
247 0x0001, 0x0002, 0x0000, 0x0003,
248 0x0000, 0x0005, 0x0006, 0x0007
251 unsigned short tmp
, bits
;
253 if (dma
< 0 || dma
> 7)
256 tmp
= inw(REG(dev
)) & ~0x07; /* Load confreg, mask DMA bits out */
258 if ((bits
= dma_bits
[dma
]) == 0 && dma
!= 4)
260 printk(KERN_ERR
"PSS: Invalid DMA %d\n", dma
);
263 outw(tmp
| bits
, REG(dev
));
267 static int pss_reset_dsp(pss_confdata
* devc
)
269 unsigned long i
, limit
= jiffies
+ HZ
/10;
271 outw(0x2000, REG(PSS_CONTROL
));
272 for (i
= 0; i
< 32768 && (limit
-jiffies
>= 0); i
++)
273 inw(REG(PSS_CONTROL
));
274 outw(0x0000, REG(PSS_CONTROL
));
278 static int pss_put_dspword(pss_confdata
* devc
, unsigned short word
)
282 for (i
= 0; i
< 327680; i
++)
284 val
= inw(REG(PSS_STATUS
));
285 if (val
& PSS_WRITE_EMPTY
)
287 outw(word
, REG(PSS_DATA
));
294 static int pss_get_dspword(pss_confdata
* devc
, unsigned short *word
)
298 for (i
= 0; i
< 327680; i
++)
300 val
= inw(REG(PSS_STATUS
));
301 if (val
& PSS_READ_FULL
)
303 *word
= inw(REG(PSS_DATA
));
310 static int pss_download_boot(pss_confdata
* devc
, unsigned char *block
, int size
, int flags
)
315 if (flags
& CPF_FIRST
)
317 /*_____ Warn DSP software that a boot is coming */
318 outw(0x00fe, REG(PSS_DATA
));
320 limit
= jiffies
+ HZ
/10;
321 for (i
= 0; i
< 32768 && time_before(jiffies
, limit
); i
++)
322 if (inw(REG(PSS_DATA
)) == 0x5500)
325 outw(*block
++, REG(PSS_DATA
));
329 while ((flags
&CPF_LAST
) || count
<size
)
333 for (j
= 0; j
< 327670; j
++)
335 /*_____ Wait for BG to appear */
336 if (inw(REG(PSS_STATUS
)) & PSS_FLAG3
)
342 /* It's ok we timed out when the file was empty */
343 if (count
>= size
&& flags
& CPF_LAST
)
348 printk(KERN_ERR
"PSS: Download timeout problems, byte %d=%d\n", count
, size
);
352 /*_____ Send the next byte */
355 /* If not data in block send 0xffff */
356 outw (0xffff, REG (PSS_DATA
));
360 /*_____ Send the next byte */
361 outw (*block
++, REG (PSS_DATA
));
366 if (flags
& CPF_LAST
)
369 outw(0, REG(PSS_DATA
));
371 limit
= jiffies
+ HZ
/10;
372 for (i
= 0; i
< 32768 && (limit
- jiffies
>= 0); i
++)
373 val
= inw(REG(PSS_STATUS
));
375 limit
= jiffies
+ HZ
/10;
376 for (i
= 0; i
< 32768 && (limit
-jiffies
>= 0); i
++)
378 val
= inw(REG(PSS_STATUS
));
383 /* now read the version */
384 for (i
= 0; i
< 32000; i
++)
386 val
= inw(REG(PSS_STATUS
));
387 if (val
& PSS_READ_FULL
)
393 val
= inw(REG(PSS_DATA
));
394 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
400 static void set_master_volume(pss_confdata
*devc
, int left
, int right
)
402 static unsigned char log_scale
[101] = {
403 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
404 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
405 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
406 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
407 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
408 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
409 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
410 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
411 0xfe, 0xfe, 0xff, 0xff, 0xff
413 pss_write(devc
, 0x0010);
414 pss_write(devc
, log_scale
[left
] | 0x0000);
415 pss_write(devc
, 0x0010);
416 pss_write(devc
, log_scale
[right
] | 0x0100);
419 static void set_synth_volume(pss_confdata
*devc
, int volume
)
421 int vol
= ((0x8000*volume
)/100L);
422 pss_write(devc
, 0x0080);
423 pss_write(devc
, vol
);
424 pss_write(devc
, 0x0081);
425 pss_write(devc
, vol
);
428 static void set_bass(pss_confdata
*devc
, int level
)
430 int vol
= (int)(((0xfd - 0xf0) * level
)/100L) + 0xf0;
431 pss_write(devc
, 0x0010);
432 pss_write(devc
, vol
| 0x0200);
435 static void set_treble(pss_confdata
*devc
, int level
)
437 int vol
= (((0xfd - 0xf0) * level
)/100L) + 0xf0;
438 pss_write(devc
, 0x0010);
439 pss_write(devc
, vol
| 0x0300);
442 static void pss_mixer_reset(pss_confdata
*devc
)
444 set_master_volume(devc
, 33, 33);
446 set_treble(devc
, 50);
447 set_synth_volume(devc
, 30);
448 pss_write (devc
, 0x0010);
449 pss_write (devc
, 0x0800 | 0xce); /* Stereo */
453 devc
->mixer
.volume_l
= devc
->mixer
.volume_r
= 33;
454 devc
->mixer
.bass
= 50;
455 devc
->mixer
.treble
= 50;
456 devc
->mixer
.synth
= 30;
460 static int set_volume_mono(unsigned __user
*p
, unsigned int *aleft
)
462 unsigned int left
, volume
;
463 if (get_user(volume
, p
))
466 left
= volume
& 0xff;
473 static int set_volume_stereo(unsigned __user
*p
,
475 unsigned int *aright
)
477 unsigned int left
, right
, volume
;
478 if (get_user(volume
, p
))
481 left
= volume
& 0xff;
484 right
= (volume
>> 8) & 0xff;
492 static int ret_vol_mono(int left
)
494 return ((left
<< 8) | left
);
497 static int ret_vol_stereo(int left
, int right
)
499 return ((right
<< 8) | left
);
502 static int call_ad_mixer(pss_confdata
*devc
,unsigned int cmd
, void __user
*arg
)
504 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
505 return mixer_devs
[devc
->ad_mixer_dev
]->ioctl(devc
->ad_mixer_dev
, cmd
, arg
);
510 static int pss_mixer_ioctl (int dev
, unsigned int cmd
, void __user
*arg
)
512 pss_confdata
*devc
= mixer_devs
[dev
]->devc
;
513 int cmdf
= cmd
& 0xff;
515 if ((cmdf
!= SOUND_MIXER_VOLUME
) && (cmdf
!= SOUND_MIXER_BASS
) &&
516 (cmdf
!= SOUND_MIXER_TREBLE
) && (cmdf
!= SOUND_MIXER_SYNTH
) &&
517 (cmdf
!= SOUND_MIXER_DEVMASK
) && (cmdf
!= SOUND_MIXER_STEREODEVS
) &&
518 (cmdf
!= SOUND_MIXER_RECMASK
) && (cmdf
!= SOUND_MIXER_CAPS
) &&
519 (cmdf
!= SOUND_MIXER_RECSRC
))
521 return call_ad_mixer(devc
, cmd
, arg
);
524 if (((cmd
>> 8) & 0xff) != 'M')
527 if (_SIOC_DIR (cmd
) & _SIOC_WRITE
)
531 case SOUND_MIXER_RECSRC
:
532 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
533 return call_ad_mixer(devc
, cmd
, arg
);
537 if (get_user(v
, (int __user
*)arg
))
543 case SOUND_MIXER_VOLUME
:
544 if (set_volume_stereo(arg
,
545 &devc
->mixer
.volume_l
,
546 &devc
->mixer
.volume_r
))
548 set_master_volume(devc
, devc
->mixer
.volume_l
,
549 devc
->mixer
.volume_r
);
550 return ret_vol_stereo(devc
->mixer
.volume_l
,
551 devc
->mixer
.volume_r
);
553 case SOUND_MIXER_BASS
:
554 if (set_volume_mono(arg
, &devc
->mixer
.bass
))
556 set_bass(devc
, devc
->mixer
.bass
);
557 return ret_vol_mono(devc
->mixer
.bass
);
559 case SOUND_MIXER_TREBLE
:
560 if (set_volume_mono(arg
, &devc
->mixer
.treble
))
562 set_treble(devc
, devc
->mixer
.treble
);
563 return ret_vol_mono(devc
->mixer
.treble
);
565 case SOUND_MIXER_SYNTH
:
566 if (set_volume_mono(arg
, &devc
->mixer
.synth
))
568 set_synth_volume(devc
, devc
->mixer
.synth
);
569 return ret_vol_mono(devc
->mixer
.synth
);
577 int val
, and_mask
= 0, or_mask
= 0;
583 case SOUND_MIXER_DEVMASK
:
584 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
587 or_mask
= SOUND_MASK_VOLUME
| SOUND_MASK_BASS
| SOUND_MASK_TREBLE
| SOUND_MASK_SYNTH
;
590 case SOUND_MIXER_STEREODEVS
:
591 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
594 or_mask
= SOUND_MASK_VOLUME
;
597 case SOUND_MIXER_RECMASK
:
598 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
599 return call_ad_mixer(devc
, cmd
, arg
);
602 case SOUND_MIXER_CAPS
:
603 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
604 return call_ad_mixer(devc
, cmd
, arg
);
605 or_mask
= SOUND_CAP_EXCL_INPUT
;
608 case SOUND_MIXER_RECSRC
:
609 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
610 return call_ad_mixer(devc
, cmd
, arg
);
613 case SOUND_MIXER_VOLUME
:
614 or_mask
= ret_vol_stereo(devc
->mixer
.volume_l
, devc
->mixer
.volume_r
);
617 case SOUND_MIXER_BASS
:
618 or_mask
= ret_vol_mono(devc
->mixer
.bass
);
621 case SOUND_MIXER_TREBLE
:
622 or_mask
= ret_vol_mono(devc
->mixer
.treble
);
625 case SOUND_MIXER_SYNTH
:
626 or_mask
= ret_vol_mono(devc
->mixer
.synth
);
631 if (get_user(val
, (int __user
*)arg
))
635 if (put_user(val
, (int __user
*)arg
))
641 static struct mixer_operations pss_mixer_operations
=
643 .owner
= THIS_MODULE
,
645 .name
= "PSS-AD1848",
646 .ioctl
= pss_mixer_ioctl
649 static void disable_all_emulations(void)
651 outw(0x0000, REG(CONF_PSS
)); /* 0x0400 enables joystick */
652 outw(0x0000, REG(CONF_WSS
));
653 outw(0x0000, REG(CONF_SB
));
654 outw(0x0000, REG(CONF_MIDI
));
655 outw(0x0000, REG(CONF_CDROM
));
658 static void configure_nonsound_components(void)
660 /* Configure Joystick port */
662 if(pss_enable_joystick
)
664 outw(0x0400, REG(CONF_PSS
)); /* 0x0400 enables joystick */
665 printk(KERN_INFO
"PSS: joystick enabled.\n");
669 printk(KERN_INFO
"PSS: joystick port not enabled.\n");
672 /* Configure CDROM port */
674 if (pss_cdrom_port
== -1) { /* If cdrom port enablation wasn't requested */
675 printk(KERN_INFO
"PSS: CDROM port not enabled.\n");
676 } else if (check_region(pss_cdrom_port
, 2)) {
677 printk(KERN_ERR
"PSS: CDROM I/O port conflict.\n");
679 set_io_base(devc
, CONF_CDROM
, pss_cdrom_port
);
680 printk(KERN_INFO
"PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port
);
684 static int __init
attach_pss(struct address_info
*hw_config
)
689 devc
->base
= hw_config
->io_base
;
690 devc
->irq
= hw_config
->irq
;
691 devc
->dma
= hw_config
->dma
;
692 devc
->osp
= hw_config
->osp
;
693 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
695 if (!probe_pss(hw_config
))
698 id
= inw(REG(PSS_ID
)) & 0x00ff;
701 * Disable all emulations. Will be enabled later (if required).
704 disable_all_emulations();
706 #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
707 if (sound_alloc_dma(hw_config
->dma
, "PSS"))
709 printk("pss.c: Can't allocate DMA channel.\n");
710 release_region(hw_config
->io_base
, 0x10);
711 release_region(hw_config
->io_base
+0x10, 0x9);
714 if (!set_irq(devc
, CONF_PSS
, devc
->irq
))
716 printk("PSS: IRQ allocation error.\n");
717 release_region(hw_config
->io_base
, 0x10);
718 release_region(hw_config
->io_base
+0x10, 0x9);
721 if (!set_dma(devc
, CONF_PSS
, devc
->dma
))
723 printk(KERN_ERR
"PSS: DMA allocation error\n");
724 release_region(hw_config
->io_base
, 0x10);
725 release_region(hw_config
->io_base
+0x10, 0x9);
730 configure_nonsound_components();
732 sprintf(tmp
, "ECHO-PSS Rev. %d", id
);
733 conf_printf(tmp
, hw_config
);
737 static int __init
probe_pss_mpu(struct address_info
*hw_config
)
739 struct resource
*ports
;
742 if (!pss_initialized
)
745 ports
= request_region(hw_config
->io_base
, 2, "mpu401");
748 printk(KERN_ERR
"PSS: MPU I/O port conflict\n");
751 set_io_base(devc
, CONF_MIDI
, hw_config
->io_base
);
752 if (!set_irq(devc
, CONF_MIDI
, hw_config
->irq
)) {
753 printk(KERN_ERR
"PSS: MIDI IRQ allocation error.\n");
757 printk(KERN_ERR
"PSS: Can't enable MPU. MIDI synth microcode not available.\n");
760 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
)) {
761 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
766 * Finally wait until the DSP algorithm has initialized itself and
767 * deactivates receive interrupt.
770 for (timeout
= 900000; timeout
> 0; timeout
--)
772 if ((inb(hw_config
->io_base
+ 1) & 0x80) == 0) /* Input data avail */
773 inb(hw_config
->io_base
); /* Discard it */
775 break; /* No more input */
778 if (!probe_mpu401(hw_config
, ports
))
781 attach_mpu401(hw_config
, THIS_MODULE
); /* Slot 1 */
782 if (hw_config
->slots
[1] != -1) /* The MPU driver installed itself */
783 midi_devs
[hw_config
->slots
[1]]->coproc
= &pss_coproc_operations
;
786 release_region(hw_config
->io_base
, 2);
790 static int pss_coproc_open(void *dev_info
, int sub_device
)
795 if (pss_synthLen
== 0)
797 printk(KERN_ERR
"PSS: MIDI synth microcode not available.\n");
800 if (nonstandard_microcode
)
801 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
803 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
806 nonstandard_microcode
= 0;
815 static void pss_coproc_close(void *dev_info
, int sub_device
)
820 static void pss_coproc_reset(void *dev_info
)
823 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
825 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
827 nonstandard_microcode
= 0;
830 static int download_boot_block(void *dev_info
, copr_buffer
* buf
)
832 if (buf
->len
<= 0 || buf
->len
> sizeof(buf
->data
))
835 if (!pss_download_boot(devc
, buf
->data
, buf
->len
, buf
->flags
))
837 printk(KERN_ERR
"PSS: Unable to load microcode block to DSP.\n");
840 nonstandard_microcode
= 1; /* The MIDI microcode has been overwritten */
844 static int pss_coproc_ioctl(void *dev_info
, unsigned int cmd
, void __user
*arg
, int local
)
851 unsigned short *data
;
853 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
857 case SNDCTL_COPR_RESET
:
858 pss_coproc_reset(dev_info
);
861 case SNDCTL_COPR_LOAD
:
862 buf
= (copr_buffer
*) vmalloc(sizeof(copr_buffer
));
865 if (copy_from_user(buf
, arg
, sizeof(copr_buffer
))) {
869 err
= download_boot_block(dev_info
, buf
);
873 case SNDCTL_COPR_SENDMSG
:
874 mbuf
= (copr_msg
*)vmalloc(sizeof(copr_msg
));
877 if (copy_from_user(mbuf
, arg
, sizeof(copr_msg
))) {
881 data
= (unsigned short *)(mbuf
->data
);
882 spin_lock_irqsave(&lock
, flags
);
883 for (i
= 0; i
< mbuf
->len
; i
++) {
884 if (!pss_put_dspword(devc
, *data
++)) {
885 spin_unlock_irqrestore(&lock
,flags
);
886 mbuf
->len
= i
; /* feed back number of WORDs sent */
887 err
= copy_to_user(arg
, mbuf
, sizeof(copr_msg
));
889 return err
? -EFAULT
: -EIO
;
892 spin_unlock_irqrestore(&lock
,flags
);
896 case SNDCTL_COPR_RCVMSG
:
898 mbuf
= (copr_msg
*)vmalloc(sizeof(copr_msg
));
901 data
= (unsigned short *)mbuf
->data
;
902 spin_lock_irqsave(&lock
, flags
);
903 for (i
= 0; i
< sizeof(mbuf
->data
)/sizeof(unsigned short); i
++) {
904 mbuf
->len
= i
; /* feed back number of WORDs read */
905 if (!pss_get_dspword(devc
, data
++)) {
911 spin_unlock_irqrestore(&lock
,flags
);
912 if (copy_to_user(arg
, mbuf
, sizeof(copr_msg
)))
917 case SNDCTL_COPR_RDATA
:
918 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
920 spin_lock_irqsave(&lock
, flags
);
921 if (!pss_put_dspword(devc
, 0x00d0)) {
922 spin_unlock_irqrestore(&lock
,flags
);
925 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
926 spin_unlock_irqrestore(&lock
,flags
);
929 if (!pss_get_dspword(devc
, &tmp
)) {
930 spin_unlock_irqrestore(&lock
,flags
);
934 spin_unlock_irqrestore(&lock
,flags
);
935 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
939 case SNDCTL_COPR_WDATA
:
940 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
942 spin_lock_irqsave(&lock
, flags
);
943 if (!pss_put_dspword(devc
, 0x00d1)) {
944 spin_unlock_irqrestore(&lock
,flags
);
947 if (!pss_put_dspword(devc
, (unsigned short) (dbuf
.parm1
& 0xffff))) {
948 spin_unlock_irqrestore(&lock
,flags
);
951 tmp
= (unsigned int)dbuf
.parm2
& 0xffff;
952 if (!pss_put_dspword(devc
, tmp
)) {
953 spin_unlock_irqrestore(&lock
,flags
);
956 spin_unlock_irqrestore(&lock
,flags
);
959 case SNDCTL_COPR_WCODE
:
960 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
962 spin_lock_irqsave(&lock
, flags
);
963 if (!pss_put_dspword(devc
, 0x00d3)) {
964 spin_unlock_irqrestore(&lock
,flags
);
967 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
968 spin_unlock_irqrestore(&lock
,flags
);
971 tmp
= (unsigned int)dbuf
.parm2
& 0x00ff;
972 if (!pss_put_dspword(devc
, tmp
)) {
973 spin_unlock_irqrestore(&lock
,flags
);
976 tmp
= ((unsigned int)dbuf
.parm2
>> 8) & 0xffff;
977 if (!pss_put_dspword(devc
, tmp
)) {
978 spin_unlock_irqrestore(&lock
,flags
);
981 spin_unlock_irqrestore(&lock
,flags
);
984 case SNDCTL_COPR_RCODE
:
985 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
987 spin_lock_irqsave(&lock
, flags
);
988 if (!pss_put_dspword(devc
, 0x00d2)) {
989 spin_unlock_irqrestore(&lock
,flags
);
992 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
993 spin_unlock_irqrestore(&lock
,flags
);
996 if (!pss_get_dspword(devc
, &tmp
)) { /* Read MSB */
997 spin_unlock_irqrestore(&lock
,flags
);
1000 dbuf
.parm1
= tmp
<< 8;
1001 if (!pss_get_dspword(devc
, &tmp
)) { /* Read LSB */
1002 spin_unlock_irqrestore(&lock
,flags
);
1005 dbuf
.parm1
|= tmp
& 0x00ff;
1006 spin_unlock_irqrestore(&lock
,flags
);
1007 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
1017 static coproc_operations pss_coproc_operations
=
1028 static int __init
probe_pss_mss(struct address_info
*hw_config
)
1030 volatile int timeout
;
1031 struct resource
*ports
;
1032 int my_mix
= -999; /* gcc shut up */
1034 if (!pss_initialized
)
1037 if (!request_region(hw_config
->io_base
, 4, "WSS config")) {
1038 printk(KERN_ERR
"PSS: WSS I/O port conflicts.\n");
1041 ports
= request_region(hw_config
->io_base
+ 4, 4, "ad1848");
1043 printk(KERN_ERR
"PSS: WSS I/O port conflicts.\n");
1044 release_region(hw_config
->io_base
, 4);
1047 set_io_base(devc
, CONF_WSS
, hw_config
->io_base
);
1048 if (!set_irq(devc
, CONF_WSS
, hw_config
->irq
)) {
1049 printk("PSS: WSS IRQ allocation error.\n");
1052 if (!set_dma(devc
, CONF_WSS
, hw_config
->dma
)) {
1053 printk(KERN_ERR
"PSS: WSS DMA allocation error\n");
1057 * For some reason the card returns 0xff in the WSS status register
1058 * immediately after boot. Probably MIDI+SB emulation algorithm
1059 * downloaded to the ADSP2115 spends some time initializing the card.
1060 * Let's try to wait until it finishes this task.
1062 for (timeout
= 0; timeout
< 100000 && (inb(hw_config
->io_base
+ WSS_INDEX
) &
1063 WSS_INITIALIZING
); timeout
++)
1066 outb((0x0b), hw_config
->io_base
+ WSS_INDEX
); /* Required by some cards */
1068 for (timeout
= 0; (inb(hw_config
->io_base
+ WSS_DATA
) & WSS_AUTOCALIBRATION
) &&
1069 (timeout
< 100000); timeout
++)
1072 if (!probe_ms_sound(hw_config
, ports
))
1075 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
1078 if ((my_mix
= sound_install_mixer (MIXER_DRIVER_VERSION
,
1079 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1080 &pss_mixer_operations
,
1081 sizeof (struct mixer_operations
),
1084 printk(KERN_ERR
"Could not install PSS mixer\n");
1088 pss_mixer_reset(devc
);
1089 attach_ms_sound(hw_config
, ports
, THIS_MODULE
); /* Slot 0 */
1091 if (hw_config
->slots
[0] != -1)
1093 /* The MSS driver installed itself */
1094 audio_devs
[hw_config
->slots
[0]]->coproc
= &pss_coproc_operations
;
1095 if (pss_mixer
&& (num_mixers
== (my_mix
+ 2)))
1097 /* The MSS mixer installed */
1098 devc
->ad_mixer_dev
= audio_devs
[hw_config
->slots
[0]]->mixer_dev
;
1103 release_region(hw_config
->io_base
+ 4, 4);
1104 release_region(hw_config
->io_base
, 4);
1108 static inline void __exit
unload_pss(struct address_info
*hw_config
)
1110 release_region(hw_config
->io_base
, 0x10);
1111 release_region(hw_config
->io_base
+0x10, 0x9);
1114 static inline void __exit
unload_pss_mpu(struct address_info
*hw_config
)
1116 unload_mpu401(hw_config
);
1119 static inline void __exit
unload_pss_mss(struct address_info
*hw_config
)
1121 unload_ms_sound(hw_config
);
1125 static struct address_info cfg
;
1126 static struct address_info cfg2
;
1127 static struct address_info cfg_mpu
;
1129 static int pss_io __initdata
= -1;
1130 static int mss_io __initdata
= -1;
1131 static int mss_irq __initdata
= -1;
1132 static int mss_dma __initdata
= -1;
1133 static int mpu_io __initdata
= -1;
1134 static int mpu_irq __initdata
= -1;
1135 static int pss_no_sound
= 0; /* Just configure non-sound components */
1136 static int pss_keep_settings
= 1; /* Keep hardware settings at module exit */
1137 static char *pss_firmware
= "/etc/sound/pss_synth";
1139 module_param(pss_io
, int, 0);
1140 MODULE_PARM_DESC(pss_io
, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1141 module_param(mss_io
, int, 0);
1142 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)");
1143 module_param(mss_irq
, int, 0);
1144 MODULE_PARM_DESC(mss_irq
, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1145 module_param(mss_dma
, int, 0);
1146 MODULE_PARM_DESC(mss_dma
, "Set WSS (audio) DMA (0, 1, 3)");
1147 module_param(mpu_io
, int, 0);
1148 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)");
1149 module_param(mpu_irq
, int, 0);
1150 MODULE_PARM_DESC(mpu_irq
, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1151 module_param(pss_cdrom_port
, int, 0);
1152 MODULE_PARM_DESC(pss_cdrom_port
, "Set the PSS CDROM port i/o base (0x340 or other)");
1153 module_param(pss_enable_joystick
, bool, 0);
1154 MODULE_PARM_DESC(pss_enable_joystick
, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1155 module_param(pss_no_sound
, bool, 0);
1156 MODULE_PARM_DESC(pss_no_sound
, "Configure sound compoents (0 - no, 1 - yes)");
1157 module_param(pss_keep_settings
, bool, 0);
1158 MODULE_PARM_DESC(pss_keep_settings
, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1159 module_param(pss_firmware
, charp
, 0);
1160 MODULE_PARM_DESC(pss_firmware
, "Location of the firmware file (default - /etc/sound/pss_synth)");
1161 module_param(pss_mixer
, bool, 0);
1162 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.");
1163 MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1164 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).");
1165 MODULE_LICENSE("GPL");
1168 static int fw_load
= 0;
1169 static int pssmpu
= 0, pssmss
= 0;
1172 * Load a PSS sound card module
1175 static int __init
init_pss(void)
1178 if(pss_no_sound
) /* If configuring only nonsound components */
1180 cfg
.io_base
= pss_io
;
1181 if(!probe_pss(&cfg
))
1183 printk(KERN_INFO
"ECHO-PSS Rev. %d\n", inw(REG(PSS_ID
)) & 0x00ff);
1184 printk(KERN_INFO
"PSS: loading in no sound mode.\n");
1185 disable_all_emulations();
1186 configure_nonsound_components();
1187 release_region(pss_io
, 0x10);
1188 release_region(pss_io
+ 0x10, 0x9);
1192 cfg
.io_base
= pss_io
;
1194 cfg2
.io_base
= mss_io
;
1198 cfg_mpu
.io_base
= mpu_io
;
1199 cfg_mpu
.irq
= mpu_irq
;
1201 if (cfg
.io_base
== -1 || cfg2
.io_base
== -1 || cfg2
.irq
== -1 || cfg
.dma
== -1) {
1202 printk(KERN_INFO
"pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1208 pss_synthLen
= mod_firmware_load(pss_firmware
, (void *) &pss_synth
);
1210 if (!attach_pss(&cfg
))
1215 if (probe_pss_mpu(&cfg_mpu
))
1218 if (probe_pss_mss(&cfg2
))
1224 static void __exit
cleanup_pss(void)
1228 if(fw_load
&& pss_synth
)
1231 unload_pss_mss(&cfg2
);
1233 unload_pss_mpu(&cfg_mpu
);
1237 if(!pss_keep_settings
) /* Keep hardware settings if asked */
1239 disable_all_emulations();
1240 printk(KERN_INFO
"Resetting PSS sound card configurations.\n");
1244 module_init(init_pss
);
1245 module_exit(cleanup_pss
);
1248 static int __init
setup_pss(char *str
)
1250 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1253 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1265 __setup("pss=", setup_pss
);