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
30 #include <linux/config.h>
31 #include <linux/module.h>
33 #include "sound_config.h"
34 #include "sound_firmware.h"
35 #include "soundmodule.h"
43 #define REG(x) (devc->base+x)
57 #define CONF_CDROM 0x16
58 #define CONF_MIDI 0x18
63 #define PSS_FLAG3 0x0800
64 #define PSS_FLAG2 0x0400
65 #define PSS_FLAG1 0x1000
66 #define PSS_FLAG0 0x0800
67 #define PSS_WRITE_EMPTY 0x8000
68 #define PSS_READ_FULL 0x4000
79 #define WSS_INITIALIZING 0x80
80 #define WSS_AUTOCALIBRATION 0x20
82 #define NO_WSS_MIXER -1
89 static int pss_synthLen
= 0;
90 static unsigned char *pss_synth
=
94 /* If compiled into kernel, it enable or disable pss mixer */
95 #ifdef CONFIG_PSS_MIXER
96 static unsigned char pss_mixer
= 1;
98 static unsigned char pss_mixer
= 0;
102 typedef struct pss_mixerdata
{
103 unsigned int volume_l
;
104 unsigned int volume_r
;
110 typedef struct pss_confdata
{
119 static pss_confdata pss_data
;
120 static pss_confdata
*devc
= &pss_data
;
122 static int pss_initialized
= 0;
123 static int nonstandard_microcode
= 0;
125 static void pss_write(pss_confdata
*devc
, int data
)
129 limit
= jiffies
+ HZ
/10; /* The timeout is 0.1 seconds */
131 * Note! the i<5000000 is an emergency exit. The dsp_command() is sometimes
132 * called while interrupts are disabled. This means that the timer is
133 * disabled also. However the timeout situation is a abnormal condition.
134 * Normally the DSP should be ready to accept commands after just couple of
138 for (i
= 0; i
< 5000000 && time_before(jiffies
, limit
); i
++)
140 if (inw(REG(PSS_STATUS
)) & PSS_WRITE_EMPTY
)
142 outw(data
, REG(PSS_DATA
));
146 printk(KERN_WARNING
"PSS: DSP Command (%04x) Timeout.\n", data
);
149 int probe_pss(struct address_info
*hw_config
)
154 devc
->base
= hw_config
->io_base
;
155 irq
= devc
->irq
= hw_config
->irq
;
156 dma
= devc
->dma
= hw_config
->dma
;
157 devc
->osp
= hw_config
->osp
;
159 if (devc
->base
!= 0x220 && devc
->base
!= 0x240)
160 if (devc
->base
!= 0x230 && devc
->base
!= 0x250) /* Some cards use these */
163 if (check_region(devc
->base
, 0x19 /*16*/)) {
164 printk(KERN_ERR
"PSS: I/O port conflict\n");
167 id
= inw(REG(PSS_ID
));
168 if ((id
>> 8) != 'E') {
169 printk(KERN_ERR
"No PSS signature detected at 0x%x (0x%x)\n", devc
->base
, id
);
175 static int set_irq(pss_confdata
* devc
, int dev
, int irq
)
177 static unsigned short irq_bits
[16] =
179 0x0000, 0x0000, 0x0000, 0x0008,
180 0x0000, 0x0010, 0x0000, 0x0018,
181 0x0000, 0x0020, 0x0028, 0x0030,
182 0x0038, 0x0000, 0x0000, 0x0000
185 unsigned short tmp
, bits
;
187 if (irq
< 0 || irq
> 15)
190 tmp
= inw(REG(dev
)) & ~0x38; /* Load confreg, mask IRQ bits out */
192 if ((bits
= irq_bits
[irq
]) == 0 && irq
!= 0)
194 printk(KERN_ERR
"PSS: Invalid IRQ %d\n", irq
);
197 outw(tmp
| bits
, REG(dev
));
201 static int set_io_base(pss_confdata
* devc
, int dev
, int base
)
203 unsigned short tmp
= inw(REG(dev
)) & 0x003f;
204 unsigned short bits
= (base
& 0x0ffc) << 4;
206 outw(bits
| tmp
, REG(dev
));
211 static int set_dma(pss_confdata
* devc
, int dev
, int dma
)
213 static unsigned short dma_bits
[8] =
215 0x0001, 0x0002, 0x0000, 0x0003,
216 0x0000, 0x0005, 0x0006, 0x0007
219 unsigned short tmp
, bits
;
221 if (dma
< 0 || dma
> 7)
224 tmp
= inw(REG(dev
)) & ~0x07; /* Load confreg, mask DMA bits out */
226 if ((bits
= dma_bits
[dma
]) == 0 && dma
!= 4)
228 printk(KERN_ERR
"PSS: Invalid DMA %d\n", dma
);
231 outw(tmp
| bits
, REG(dev
));
235 static int pss_reset_dsp(pss_confdata
* devc
)
237 unsigned long i
, limit
= jiffies
+ HZ
/10;
239 outw(0x2000, REG(PSS_CONTROL
));
240 for (i
= 0; i
< 32768 && (limit
-jiffies
>= 0); i
++)
241 inw(REG(PSS_CONTROL
));
242 outw(0x0000, REG(PSS_CONTROL
));
246 static int pss_put_dspword(pss_confdata
* devc
, unsigned short word
)
250 for (i
= 0; i
< 327680; i
++)
252 val
= inw(REG(PSS_STATUS
));
253 if (val
& PSS_WRITE_EMPTY
)
255 outw(word
, REG(PSS_DATA
));
262 static int pss_get_dspword(pss_confdata
* devc
, unsigned short *word
)
266 for (i
= 0; i
< 327680; i
++)
268 val
= inw(REG(PSS_STATUS
));
269 if (val
& PSS_READ_FULL
)
271 *word
= inw(REG(PSS_DATA
));
278 static int pss_download_boot(pss_confdata
* devc
, unsigned char *block
, int size
, int flags
)
280 int i
, limit
, val
, count
;
282 if (flags
& CPF_FIRST
)
284 /*_____ Warn DSP software that a boot is coming */
285 outw(0x00fe, REG(PSS_DATA
));
287 limit
= jiffies
+ HZ
/10;
288 for (i
= 0; i
< 32768 && time_before(jiffies
, limit
); i
++)
289 if (inw(REG(PSS_DATA
)) == 0x5500)
292 outw(*block
++, REG(PSS_DATA
));
296 while ((flags
&CPF_LAST
) || count
<size
)
300 for (j
= 0; j
< 327670; j
++)
302 /*_____ Wait for BG to appear */
303 if (inw(REG(PSS_STATUS
)) & PSS_FLAG3
)
309 /* It's ok we timed out when the file was empty */
310 if (count
>= size
&& flags
& CPF_LAST
)
315 printk(KERN_ERR
"PSS: Download timeout problems, byte %d=%d\n", count
, size
);
319 /*_____ Send the next byte */
322 /* If not data in block send 0xffff */
323 outw (0xffff, REG (PSS_DATA
));
327 /*_____ Send the next byte */
328 outw (*block
++, REG (PSS_DATA
));
333 if (flags
& CPF_LAST
)
336 outw(0, REG(PSS_DATA
));
338 limit
= jiffies
+ HZ
/10;
339 for (i
= 0; i
< 32768 && (limit
- jiffies
>= 0); i
++)
340 val
= inw(REG(PSS_STATUS
));
342 limit
= jiffies
+ HZ
/10;
343 for (i
= 0; i
< 32768 && (limit
-jiffies
>= 0); i
++)
345 val
= inw(REG(PSS_STATUS
));
350 /* now read the version */
351 for (i
= 0; i
< 32000; i
++)
353 val
= inw(REG(PSS_STATUS
));
354 if (val
& PSS_READ_FULL
)
360 val
= inw(REG(PSS_DATA
));
361 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
367 static void set_master_volume(pss_confdata
*devc
, int left
, int right
)
369 static unsigned char log_scale
[101] = {
370 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
371 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
372 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
373 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
374 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
375 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
376 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
377 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
378 0xfe, 0xfe, 0xff, 0xff, 0xff
380 pss_write(devc
, 0x0010);
381 pss_write(devc
, log_scale
[left
] | 0x0000);
382 pss_write(devc
, 0x0010);
383 pss_write(devc
, log_scale
[right
] | 0x0100);
386 static void set_synth_volume(pss_confdata
*devc
, int volume
)
388 int vol
= ((0x8000*volume
)/100L);
389 pss_write(devc
, 0x0080);
390 pss_write(devc
, vol
);
391 pss_write(devc
, 0x0081);
392 pss_write(devc
, vol
);
395 static void set_bass(pss_confdata
*devc
, int level
)
397 int vol
= (int)(((0xfd - 0xf0) * level
)/100L) + 0xf0;
398 pss_write(devc
, 0x0010);
399 pss_write(devc
, vol
| 0x0200);
402 static void set_treble(pss_confdata
*devc
, int level
)
404 int vol
= (((0xfd - 0xf0) * level
)/100L) + 0xf0;
405 pss_write(devc
, 0x0010);
406 pss_write(devc
, vol
| 0x0300);
409 static void pss_mixer_reset(pss_confdata
*devc
)
411 set_master_volume(devc
, 33, 33);
413 set_treble(devc
, 50);
414 set_synth_volume(devc
, 30);
415 pss_write (devc
, 0x0010);
416 pss_write (devc
, 0x0800 | 0xce); /* Stereo */
420 devc
->mixer
.volume_l
= devc
->mixer
.volume_r
= 33;
421 devc
->mixer
.bass
= 50;
422 devc
->mixer
.treble
= 50;
423 devc
->mixer
.synth
= 30;
427 static void arg_to_volume_mono(unsigned int volume
, int *aleft
)
431 left
= volume
& 0x00ff;
437 static void arg_to_volume_stereo(unsigned int volume
, int *aleft
, int *aright
)
439 arg_to_volume_mono(volume
, aleft
);
440 arg_to_volume_mono(volume
>> 8, aright
);
443 static int ret_vol_mono(int left
)
445 return ((left
<< 8) | left
);
448 static int ret_vol_stereo(int left
, int right
)
450 return ((right
<< 8) | left
);
453 static int call_ad_mixer(pss_confdata
*devc
,unsigned int cmd
, caddr_t arg
)
455 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
456 return mixer_devs
[devc
->ad_mixer_dev
]->ioctl(devc
->ad_mixer_dev
, cmd
, arg
);
461 static int pss_mixer_ioctl (int dev
, unsigned int cmd
, caddr_t arg
)
463 pss_confdata
*devc
= mixer_devs
[dev
]->devc
;
464 int cmdf
= cmd
& 0xff;
466 if ((cmdf
!= SOUND_MIXER_VOLUME
) && (cmdf
!= SOUND_MIXER_BASS
) &&
467 (cmdf
!= SOUND_MIXER_TREBLE
) && (cmdf
!= SOUND_MIXER_SYNTH
) &&
468 (cmdf
!= SOUND_MIXER_DEVMASK
) && (cmdf
!= SOUND_MIXER_STEREODEVS
) &&
469 (cmdf
!= SOUND_MIXER_RECMASK
) && (cmdf
!= SOUND_MIXER_CAPS
) &&
470 (cmdf
!= SOUND_MIXER_RECSRC
))
472 return call_ad_mixer(devc
, cmd
, arg
);
475 if (((cmd
>> 8) & 0xff) != 'M')
478 if (_SIOC_DIR (cmd
) & _SIOC_WRITE
)
482 case SOUND_MIXER_RECSRC
:
483 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
484 return call_ad_mixer(devc
, cmd
, arg
);
487 if (*(int *)arg
!= 0)
491 case SOUND_MIXER_VOLUME
:
492 arg_to_volume_stereo(*(unsigned int *)arg
, &devc
->mixer
.volume_l
,
493 &devc
->mixer
.volume_r
);
494 set_master_volume(devc
, devc
->mixer
.volume_l
,
495 devc
->mixer
.volume_r
);
496 return ret_vol_stereo(devc
->mixer
.volume_l
,
497 devc
->mixer
.volume_r
);
499 case SOUND_MIXER_BASS
:
500 arg_to_volume_mono(*(unsigned int *)arg
,
502 set_bass(devc
, devc
->mixer
.bass
);
503 return ret_vol_mono(devc
->mixer
.bass
);
505 case SOUND_MIXER_TREBLE
:
506 arg_to_volume_mono(*(unsigned int *)arg
,
507 &devc
->mixer
.treble
);
508 set_treble(devc
, devc
->mixer
.treble
);
509 return ret_vol_mono(devc
->mixer
.treble
);
511 case SOUND_MIXER_SYNTH
:
512 arg_to_volume_mono(*(unsigned int *)arg
,
514 set_synth_volume(devc
, devc
->mixer
.synth
);
515 return ret_vol_mono(devc
->mixer
.synth
);
529 case SOUND_MIXER_DEVMASK
:
530 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
531 *(int *)arg
= 0; /* no mixer devices */
532 return (*(int *)arg
|= SOUND_MASK_VOLUME
| SOUND_MASK_BASS
| SOUND_MASK_TREBLE
| SOUND_MASK_SYNTH
);
534 case SOUND_MIXER_STEREODEVS
:
535 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
536 *(int *)arg
= 0; /* no stereo devices */
537 return (*(int *)arg
|= SOUND_MASK_VOLUME
);
539 case SOUND_MIXER_RECMASK
:
540 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
541 return call_ad_mixer(devc
, cmd
, arg
);
543 return (*(int *)arg
= 0); /* no record devices */
545 case SOUND_MIXER_CAPS
:
546 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
547 return call_ad_mixer(devc
, cmd
, arg
);
549 return (*(int *)arg
= SOUND_CAP_EXCL_INPUT
);
551 case SOUND_MIXER_RECSRC
:
552 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
553 return call_ad_mixer(devc
, cmd
, arg
);
555 return (*(int *)arg
= 0); /* no record source */
557 case SOUND_MIXER_VOLUME
:
558 return (*(int *)arg
= ret_vol_stereo(devc
->mixer
.volume_l
, devc
->mixer
.volume_r
));
560 case SOUND_MIXER_BASS
:
561 return (*(int *)arg
= ret_vol_mono(devc
->mixer
.bass
));
563 case SOUND_MIXER_TREBLE
:
564 return (*(int *)arg
= ret_vol_mono(devc
->mixer
.treble
));
566 case SOUND_MIXER_SYNTH
:
567 return (*(int *)arg
= ret_vol_mono(devc
->mixer
.synth
));
574 static struct mixer_operations pss_mixer_operations
=
581 void attach_pss(struct address_info
*hw_config
)
586 devc
->base
= hw_config
->io_base
;
587 devc
->irq
= hw_config
->irq
;
588 devc
->dma
= hw_config
->dma
;
589 devc
->osp
= hw_config
->osp
;
590 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
592 if (!probe_pss(hw_config
))
595 request_region(hw_config
->io_base
, 0x10, "PSS mixer, SB emulation");
596 request_region(hw_config
->io_base
+ 0x10, 0x9, "PSS config");
598 id
= inw(REG(PSS_ID
)) & 0x00ff;
601 * Disable all emulations. Will be enabled later (if required).
603 outw(0x0000, REG(CONF_PSS
)); /* 0x0400 enables joystick */
604 outw(0x0000, REG(CONF_WSS
));
605 outw(0x0000, REG(CONF_SB
));
606 outw(0x0000, REG(CONF_MIDI
));
607 outw(0x0000, REG(CONF_CDROM
));
609 #if YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
610 if (sound_alloc_dma(hw_config
->dma
, "PSS"))
612 printk("pss.c: Can't allocate DMA channel.\n");
615 if (!set_irq(devc
, CONF_PSS
, devc
->irq
))
617 printk("PSS: IRQ allocation error.\n");
620 if (!set_dma(devc
, CONF_PSS
, devc
->dma
))
622 printk(KERN_ERR
"PSS: DMA allocation error\n");
628 sprintf(tmp
, "ECHO-PSS Rev. %d", id
);
629 conf_printf(tmp
, hw_config
);
632 int probe_pss_mpu(struct address_info
*hw_config
)
636 if (!pss_initialized
)
639 if (check_region(hw_config
->io_base
, 2))
641 printk(KERN_ERR
"PSS: MPU I/O port conflict\n");
644 if (!set_io_base(devc
, CONF_MIDI
, hw_config
->io_base
))
646 printk(KERN_ERR
"PSS: MIDI base could not be set.\n");
649 if (!set_irq(devc
, CONF_MIDI
, hw_config
->irq
))
651 printk(KERN_ERR
"PSS: MIDI IRQ allocation error.\n");
656 printk(KERN_ERR
"PSS: Can't enable MPU. MIDI synth microcode not available.\n");
659 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");
666 * Finally wait until the DSP algorithm has initialized itself and
667 * deactivates receive interrupt.
670 for (timeout
= 900000; timeout
> 0; timeout
--)
672 if ((inb(hw_config
->io_base
+ 1) & 0x80) == 0) /* Input data avail */
673 inb(hw_config
->io_base
); /* Discard it */
675 break; /* No more input */
678 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
679 return probe_mpu401(hw_config
);
685 static int pss_coproc_open(void *dev_info
, int sub_device
)
690 if (pss_synthLen
== 0)
692 printk(KERN_ERR
"PSS: MIDI synth microcode not available.\n");
695 if (nonstandard_microcode
)
696 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
698 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
701 nonstandard_microcode
= 0;
709 static void pss_coproc_close(void *dev_info
, int sub_device
)
714 static void pss_coproc_reset(void *dev_info
)
717 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
719 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
721 nonstandard_microcode
= 0;
724 static int download_boot_block(void *dev_info
, copr_buffer
* buf
)
726 if (buf
->len
<= 0 || buf
->len
> sizeof(buf
->data
))
729 if (!pss_download_boot(devc
, buf
->data
, buf
->len
, buf
->flags
))
731 printk(KERN_ERR
"PSS: Unable to load microcode block to DSP.\n");
734 nonstandard_microcode
= 1; /* The MIDI microcode has been overwritten */
738 static int pss_coproc_ioctl(void *dev_info
, unsigned int cmd
, caddr_t arg
, int local
)
745 unsigned short *data
;
747 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
751 case SNDCTL_COPR_RESET
:
752 pss_coproc_reset(dev_info
);
755 case SNDCTL_COPR_LOAD
:
756 buf
= (copr_buffer
*) vmalloc(sizeof(copr_buffer
));
759 if (copy_from_user(buf
, arg
, sizeof(copr_buffer
))) {
763 err
= download_boot_block(dev_info
, buf
);
767 case SNDCTL_COPR_SENDMSG
:
768 mbuf
= (copr_msg
*)vmalloc(sizeof(copr_msg
));
771 if (copy_from_user(mbuf
, arg
, sizeof(copr_msg
))) {
775 data
= (unsigned short *)(mbuf
->data
);
778 for (i
= 0; i
< mbuf
->len
; i
++) {
779 if (!pss_put_dspword(devc
, *data
++)) {
780 restore_flags(flags
);
781 mbuf
->len
= i
; /* feed back number of WORDs sent */
782 err
= copy_to_user(arg
, mbuf
, sizeof(copr_msg
));
784 return err
? -EFAULT
: -EIO
;
787 restore_flags(flags
);
791 case SNDCTL_COPR_RCVMSG
:
793 mbuf
= (copr_msg
*)vmalloc(sizeof(copr_msg
));
796 data
= (unsigned short *)mbuf
->data
;
799 for (i
= 0; i
< sizeof(mbuf
->data
)/sizeof(unsigned short); i
++) {
800 mbuf
->len
= i
; /* feed back number of WORDs read */
801 if (!pss_get_dspword(devc
, data
++)) {
807 restore_flags(flags
);
808 if (copy_to_user(arg
, mbuf
, sizeof(copr_msg
)))
813 case SNDCTL_COPR_RDATA
:
814 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
818 if (!pss_put_dspword(devc
, 0x00d0)) {
819 restore_flags(flags
);
822 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
823 restore_flags(flags
);
826 if (!pss_get_dspword(devc
, &tmp
)) {
827 restore_flags(flags
);
831 restore_flags(flags
);
832 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
836 case SNDCTL_COPR_WDATA
:
837 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
841 if (!pss_put_dspword(devc
, 0x00d1)) {
842 restore_flags(flags
);
845 if (!pss_put_dspword(devc
, (unsigned short) (dbuf
.parm1
& 0xffff))) {
846 restore_flags(flags
);
849 tmp
= (unsigned int)dbuf
.parm2
& 0xffff;
850 if (!pss_put_dspword(devc
, tmp
)) {
851 restore_flags(flags
);
854 restore_flags(flags
);
857 case SNDCTL_COPR_WCODE
:
858 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
862 if (!pss_put_dspword(devc
, 0x00d3)) {
863 restore_flags(flags
);
866 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
867 restore_flags(flags
);
870 tmp
= (unsigned int)dbuf
.parm2
& 0x00ff;
871 if (!pss_put_dspword(devc
, tmp
)) {
872 restore_flags(flags
);
875 tmp
= ((unsigned int)dbuf
.parm2
>> 8) & 0xffff;
876 if (!pss_put_dspword(devc
, tmp
)) {
877 restore_flags(flags
);
880 restore_flags(flags
);
883 case SNDCTL_COPR_RCODE
:
884 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
888 if (!pss_put_dspword(devc
, 0x00d2)) {
889 restore_flags(flags
);
892 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
893 restore_flags(flags
);
896 if (!pss_get_dspword(devc
, &tmp
)) { /* Read MSB */
897 restore_flags(flags
);
900 dbuf
.parm1
= tmp
<< 8;
901 if (!pss_get_dspword(devc
, &tmp
)) { /* Read LSB */
902 restore_flags(flags
);
905 dbuf
.parm1
|= tmp
& 0x00ff;
906 restore_flags(flags
);
907 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
917 static coproc_operations pss_coproc_operations
=
927 void attach_pss_mpu(struct address_info
*hw_config
)
929 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
930 attach_mpu401(hw_config
); /* Slot 1 */
931 if (hw_config
->slots
[1] != -1) /* The MPU driver installed itself */
932 midi_devs
[hw_config
->slots
[1]]->coproc
= &pss_coproc_operations
;
936 int probe_pss_mss(struct address_info
*hw_config
)
938 volatile int timeout
;
940 if (!pss_initialized
)
943 if (check_region(hw_config
->io_base
, 8))
945 printk(KERN_ERR
"PSS: WSS I/O port conflicts.\n");
948 if (!set_io_base(devc
, CONF_WSS
, hw_config
->io_base
))
950 printk("PSS: WSS base not settable.\n");
953 if (!set_irq(devc
, CONF_WSS
, hw_config
->irq
))
955 printk("PSS: WSS IRQ allocation error.\n");
958 if (!set_dma(devc
, CONF_WSS
, hw_config
->dma
))
960 printk(KERN_ERR
"PSS: WSS DMA allocation error\n");
964 * For some reason the card returns 0xff in the WSS status register
965 * immediately after boot. Probably MIDI+SB emulation algorithm
966 * downloaded to the ADSP2115 spends some time initializing the card.
967 * Let's try to wait until it finishes this task.
969 for (timeout
= 0; timeout
< 100000 && (inb(hw_config
->io_base
+ WSS_INDEX
) & WSS_INITIALIZING
); timeout
++);
971 outb((0x0b), hw_config
->io_base
+ WSS_INDEX
); /* Required by some cards */
973 for (timeout
= 0; (inb(hw_config
->io_base
+ WSS_DATA
) & WSS_AUTOCALIBRATION
) && (timeout
< 100000); timeout
++);
975 return probe_ms_sound(hw_config
);
978 void attach_pss_mss(struct address_info
*hw_config
)
980 int my_mix
= -999; /* gcc shut up */
982 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
985 if ((my_mix
= sound_install_mixer (MIXER_DRIVER_VERSION
,
986 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
987 &pss_mixer_operations
,
988 sizeof (struct mixer_operations
),
991 printk(KERN_ERR
"Could not install PSS mixer\n");
995 pss_mixer_reset(devc
);
996 attach_ms_sound(hw_config
); /* Slot 0 */
998 if (hw_config
->slots
[0] != -1)
1000 /* The MSS driver installed itself */
1001 audio_devs
[hw_config
->slots
[0]]->coproc
= &pss_coproc_operations
;
1002 if (pss_mixer
&& (num_mixers
== (my_mix
+ 2)))
1004 /* The MSS mixer installed */
1005 devc
->ad_mixer_dev
= audio_devs
[hw_config
->slots
[0]]->mixer_dev
;
1010 void unload_pss(struct address_info
*hw_config
)
1012 release_region(hw_config
->io_base
, 0x10);
1013 release_region(hw_config
->io_base
+0x10, 0x9);
1016 void unload_pss_mpu(struct address_info
*hw_config
)
1018 #if (defined(CONFIG_MPU401) || defined(CONFIG_MPU_EMU)) && defined(CONFIG_MIDI)
1019 unload_mpu401(hw_config
);
1023 void unload_pss_mss(struct address_info
*hw_config
)
1025 unload_ms_sound(hw_config
);
1039 struct address_info cfgpss
= { 0 /* pss_io */, 0, -1, -1 };
1040 struct address_info cfgmpu
= { 0 /* mpu_io */, 0 /* mpu_irq */, 0, -1 };
1041 struct address_info cfgmss
= { 0 /* mss_io */, 0 /* mss_irq */, 0 /* mss_dma */, -1 };
1043 MODULE_PARM(pss_io
, "i");
1044 MODULE_PARM_DESC(pss_io
, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1045 MODULE_PARM(mss_io
, "i");
1046 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)");
1047 MODULE_PARM(mss_irq
, "i");
1048 MODULE_PARM_DESC(mss_irq
, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1049 MODULE_PARM(mss_dma
, "i");
1050 MODULE_PARM_DESC(mss_dma
, "Set WSS (audio) DMA (0, 1, 3)");
1051 MODULE_PARM(mpu_io
, "i");
1052 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)");
1053 MODULE_PARM(mpu_irq
, "i");
1054 MODULE_PARM_DESC(mpu_irq
, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1055 MODULE_PARM(pss_mixer
, "b");
1056 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.");
1057 MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1058 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).\n");
1060 static int fw_load
= 0;
1061 static int pssmpu
= 0, pssmss
= 0;
1064 * Load a PSS sound card module
1067 int init_module(void)
1069 if (pss_io
== -1 || mss_io
== -1 || mss_irq
== -1 || mss_dma
== -1) {
1070 printk(KERN_INFO
"pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1074 cfgpss
.io_base
= pss_io
;
1076 cfgmss
.io_base
= mss_io
;
1077 cfgmss
.irq
= mss_irq
;
1078 cfgmss
.dma
= mss_dma
;
1080 cfgmpu
.io_base
= mpu_io
;
1081 cfgmpu
.irq
= mpu_irq
;
1086 pss_synthLen
= mod_firmware_load("/etc/sound/pss_synth", (void *) &pss_synth
);
1088 if (!probe_pss(&cfgpss
))
1090 attach_pss(&cfgpss
);
1094 if (probe_pss_mpu(&cfgmpu
)) {
1096 attach_pss_mpu(&cfgmpu
);
1098 if (probe_pss_mss(&cfgmss
)) {
1100 attach_pss_mss(&cfgmss
);
1106 void cleanup_module(void)
1108 if (fw_load
&& pss_synth
)
1111 unload_pss_mss(&cfgmss
);
1113 unload_pss_mpu(&cfgmpu
);
1114 unload_pss(&cfgpss
);