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 firmware 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 bool pss_mixer
= 1;
122 static bool pss_mixer
;
126 struct pss_mixerdata
{
127 unsigned int volume_l
;
128 unsigned int volume_r
;
134 struct pss_confdata
{
139 struct pss_mixerdata mixer
;
143 static struct pss_confdata pss_data
;
144 static struct 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 bool pss_enable_joystick
; /* Parameter for enabling the joystick */
151 static coproc_operations pss_coproc_operations
;
153 static void pss_write(struct 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(struct 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(struct 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(struct 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(struct pss_confdata
*devc
)
269 unsigned long i
, limit
= jiffies
+ HZ
/10;
271 outw(0x2000, REG(PSS_CONTROL
));
272 for (i
= 0; i
< 32768 && time_after_eq(limit
, jiffies
); i
++)
273 inw(REG(PSS_CONTROL
));
274 outw(0x0000, REG(PSS_CONTROL
));
278 static int pss_put_dspword(struct 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(struct 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(struct pss_confdata
*devc
, unsigned char *block
,
316 if (flags
& CPF_FIRST
)
318 /*_____ Warn DSP software that a boot is coming */
319 outw(0x00fe, REG(PSS_DATA
));
321 limit
= jiffies
+ HZ
/10;
322 for (i
= 0; i
< 32768 && time_before(jiffies
, limit
); i
++)
323 if (inw(REG(PSS_DATA
)) == 0x5500)
326 outw(*block
++, REG(PSS_DATA
));
330 while ((flags
&CPF_LAST
) || count
<size
)
334 for (j
= 0; j
< 327670; j
++)
336 /*_____ Wait for BG to appear */
337 if (inw(REG(PSS_STATUS
)) & PSS_FLAG3
)
343 /* It's ok we timed out when the file was empty */
344 if (count
>= size
&& flags
& CPF_LAST
)
349 printk(KERN_ERR
"PSS: Download timeout problems, byte %d=%d\n", count
, size
);
353 /*_____ Send the next byte */
356 /* If not data in block send 0xffff */
357 outw (0xffff, REG (PSS_DATA
));
361 /*_____ Send the next byte */
362 outw (*block
++, REG (PSS_DATA
));
367 if (flags
& CPF_LAST
)
370 outw(0, REG(PSS_DATA
));
372 limit
= jiffies
+ HZ
/10;
373 for (i
= 0; i
< 32768 && time_after_eq(limit
, jiffies
); i
++)
374 val
= inw(REG(PSS_STATUS
));
376 limit
= jiffies
+ HZ
/10;
377 for (i
= 0; i
< 32768 && time_after_eq(limit
, jiffies
); i
++)
379 val
= inw(REG(PSS_STATUS
));
384 /* now read the version */
385 for (i
= 0; i
< 32000; i
++)
387 val
= inw(REG(PSS_STATUS
));
388 if (val
& PSS_READ_FULL
)
394 val
= inw(REG(PSS_DATA
));
395 /* printk( "<PSS: microcode version %d.%d loaded>", val/16, val % 16); */
401 static void set_master_volume(struct pss_confdata
*devc
, int left
, int right
)
403 static unsigned char log_scale
[101] = {
404 0xdb, 0xe0, 0xe3, 0xe5, 0xe7, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xed, 0xee,
405 0xef, 0xef, 0xf0, 0xf0, 0xf1, 0xf1, 0xf2, 0xf2, 0xf2, 0xf3, 0xf3, 0xf3,
406 0xf4, 0xf4, 0xf4, 0xf5, 0xf5, 0xf5, 0xf5, 0xf6, 0xf6, 0xf6, 0xf6, 0xf7,
407 0xf7, 0xf7, 0xf7, 0xf7, 0xf8, 0xf8, 0xf8, 0xf8, 0xf8, 0xf9, 0xf9, 0xf9,
408 0xf9, 0xf9, 0xf9, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfa, 0xfb, 0xfb,
409 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfb, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc,
410 0xfc, 0xfc, 0xfc, 0xfc, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd, 0xfd,
411 0xfd, 0xfd, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe, 0xfe,
412 0xfe, 0xfe, 0xff, 0xff, 0xff
414 pss_write(devc
, 0x0010);
415 pss_write(devc
, log_scale
[left
] | 0x0000);
416 pss_write(devc
, 0x0010);
417 pss_write(devc
, log_scale
[right
] | 0x0100);
420 static void set_synth_volume(struct pss_confdata
*devc
, int volume
)
422 int vol
= ((0x8000*volume
)/100L);
423 pss_write(devc
, 0x0080);
424 pss_write(devc
, vol
);
425 pss_write(devc
, 0x0081);
426 pss_write(devc
, vol
);
429 static void set_bass(struct pss_confdata
*devc
, int level
)
431 int vol
= (int)(((0xfd - 0xf0) * level
)/100L) + 0xf0;
432 pss_write(devc
, 0x0010);
433 pss_write(devc
, vol
| 0x0200);
436 static void set_treble(struct pss_confdata
*devc
, int level
)
438 int vol
= (((0xfd - 0xf0) * level
)/100L) + 0xf0;
439 pss_write(devc
, 0x0010);
440 pss_write(devc
, vol
| 0x0300);
443 static void pss_mixer_reset(struct pss_confdata
*devc
)
445 set_master_volume(devc
, 33, 33);
447 set_treble(devc
, 50);
448 set_synth_volume(devc
, 30);
449 pss_write (devc
, 0x0010);
450 pss_write (devc
, 0x0800 | 0xce); /* Stereo */
454 devc
->mixer
.volume_l
= devc
->mixer
.volume_r
= 33;
455 devc
->mixer
.bass
= 50;
456 devc
->mixer
.treble
= 50;
457 devc
->mixer
.synth
= 30;
461 static int set_volume_mono(unsigned __user
*p
, unsigned int *aleft
)
463 unsigned int left
, volume
;
464 if (get_user(volume
, p
))
467 left
= volume
& 0xff;
474 static int set_volume_stereo(unsigned __user
*p
,
476 unsigned int *aright
)
478 unsigned int left
, right
, volume
;
479 if (get_user(volume
, p
))
482 left
= volume
& 0xff;
485 right
= (volume
>> 8) & 0xff;
493 static int ret_vol_mono(int left
)
495 return ((left
<< 8) | left
);
498 static int ret_vol_stereo(int left
, int right
)
500 return ((right
<< 8) | left
);
503 static int call_ad_mixer(struct pss_confdata
*devc
, unsigned int cmd
,
506 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
507 return mixer_devs
[devc
->ad_mixer_dev
]->ioctl(devc
->ad_mixer_dev
, cmd
, arg
);
512 static int pss_mixer_ioctl (int dev
, unsigned int cmd
, void __user
*arg
)
514 struct pss_confdata
*devc
= mixer_devs
[dev
]->devc
;
515 int cmdf
= cmd
& 0xff;
517 if ((cmdf
!= SOUND_MIXER_VOLUME
) && (cmdf
!= SOUND_MIXER_BASS
) &&
518 (cmdf
!= SOUND_MIXER_TREBLE
) && (cmdf
!= SOUND_MIXER_SYNTH
) &&
519 (cmdf
!= SOUND_MIXER_DEVMASK
) && (cmdf
!= SOUND_MIXER_STEREODEVS
) &&
520 (cmdf
!= SOUND_MIXER_RECMASK
) && (cmdf
!= SOUND_MIXER_CAPS
) &&
521 (cmdf
!= SOUND_MIXER_RECSRC
))
523 return call_ad_mixer(devc
, cmd
, arg
);
526 if (((cmd
>> 8) & 0xff) != 'M')
529 if (_SIOC_DIR (cmd
) & _SIOC_WRITE
)
533 case SOUND_MIXER_RECSRC
:
534 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
535 return call_ad_mixer(devc
, cmd
, arg
);
539 if (get_user(v
, (int __user
*)arg
))
545 case SOUND_MIXER_VOLUME
:
546 if (set_volume_stereo(arg
,
547 &devc
->mixer
.volume_l
,
548 &devc
->mixer
.volume_r
))
550 set_master_volume(devc
, devc
->mixer
.volume_l
,
551 devc
->mixer
.volume_r
);
552 return ret_vol_stereo(devc
->mixer
.volume_l
,
553 devc
->mixer
.volume_r
);
555 case SOUND_MIXER_BASS
:
556 if (set_volume_mono(arg
, &devc
->mixer
.bass
))
558 set_bass(devc
, devc
->mixer
.bass
);
559 return ret_vol_mono(devc
->mixer
.bass
);
561 case SOUND_MIXER_TREBLE
:
562 if (set_volume_mono(arg
, &devc
->mixer
.treble
))
564 set_treble(devc
, devc
->mixer
.treble
);
565 return ret_vol_mono(devc
->mixer
.treble
);
567 case SOUND_MIXER_SYNTH
:
568 if (set_volume_mono(arg
, &devc
->mixer
.synth
))
570 set_synth_volume(devc
, devc
->mixer
.synth
);
571 return ret_vol_mono(devc
->mixer
.synth
);
579 int val
, and_mask
= 0, or_mask
= 0;
585 case SOUND_MIXER_DEVMASK
:
586 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
589 or_mask
= SOUND_MASK_VOLUME
| SOUND_MASK_BASS
| SOUND_MASK_TREBLE
| SOUND_MASK_SYNTH
;
592 case SOUND_MIXER_STEREODEVS
:
593 if (call_ad_mixer(devc
, cmd
, arg
) == -EINVAL
)
596 or_mask
= SOUND_MASK_VOLUME
;
599 case SOUND_MIXER_RECMASK
:
600 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
601 return call_ad_mixer(devc
, cmd
, arg
);
604 case SOUND_MIXER_CAPS
:
605 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
606 return call_ad_mixer(devc
, cmd
, arg
);
607 or_mask
= SOUND_CAP_EXCL_INPUT
;
610 case SOUND_MIXER_RECSRC
:
611 if (devc
->ad_mixer_dev
!= NO_WSS_MIXER
)
612 return call_ad_mixer(devc
, cmd
, arg
);
615 case SOUND_MIXER_VOLUME
:
616 or_mask
= ret_vol_stereo(devc
->mixer
.volume_l
, devc
->mixer
.volume_r
);
619 case SOUND_MIXER_BASS
:
620 or_mask
= ret_vol_mono(devc
->mixer
.bass
);
623 case SOUND_MIXER_TREBLE
:
624 or_mask
= ret_vol_mono(devc
->mixer
.treble
);
627 case SOUND_MIXER_SYNTH
:
628 or_mask
= ret_vol_mono(devc
->mixer
.synth
);
633 if (get_user(val
, (int __user
*)arg
))
637 if (put_user(val
, (int __user
*)arg
))
643 static struct mixer_operations pss_mixer_operations
=
645 .owner
= THIS_MODULE
,
647 .name
= "PSS-AD1848",
648 .ioctl
= pss_mixer_ioctl
651 static void disable_all_emulations(void)
653 outw(0x0000, REG(CONF_PSS
)); /* 0x0400 enables joystick */
654 outw(0x0000, REG(CONF_WSS
));
655 outw(0x0000, REG(CONF_SB
));
656 outw(0x0000, REG(CONF_MIDI
));
657 outw(0x0000, REG(CONF_CDROM
));
660 static void configure_nonsound_components(void)
662 /* Configure Joystick port */
664 if(pss_enable_joystick
)
666 outw(0x0400, REG(CONF_PSS
)); /* 0x0400 enables joystick */
667 printk(KERN_INFO
"PSS: joystick enabled.\n");
671 printk(KERN_INFO
"PSS: joystick port not enabled.\n");
674 /* Configure CDROM port */
676 if (pss_cdrom_port
== -1) { /* If cdrom port enablation wasn't requested */
677 printk(KERN_INFO
"PSS: CDROM port not enabled.\n");
678 } else if (!request_region(pss_cdrom_port
, 2, "PSS CDROM")) {
680 printk(KERN_ERR
"PSS: CDROM I/O port conflict.\n");
682 set_io_base(devc
, CONF_CDROM
, pss_cdrom_port
);
683 printk(KERN_INFO
"PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port
);
687 static int __init
attach_pss(struct address_info
*hw_config
)
692 devc
->base
= hw_config
->io_base
;
693 devc
->irq
= hw_config
->irq
;
694 devc
->dma
= hw_config
->dma
;
695 devc
->osp
= hw_config
->osp
;
696 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
698 if (!probe_pss(hw_config
))
701 id
= inw(REG(PSS_ID
)) & 0x00ff;
704 * Disable all emulations. Will be enabled later (if required).
707 disable_all_emulations();
709 #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
710 if (sound_alloc_dma(hw_config
->dma
, "PSS"))
712 printk("pss.c: Can't allocate DMA channel.\n");
713 release_region(hw_config
->io_base
, 0x10);
714 release_region(hw_config
->io_base
+0x10, 0x9);
717 if (!set_irq(devc
, CONF_PSS
, devc
->irq
))
719 printk("PSS: IRQ allocation error.\n");
720 release_region(hw_config
->io_base
, 0x10);
721 release_region(hw_config
->io_base
+0x10, 0x9);
724 if (!set_dma(devc
, CONF_PSS
, devc
->dma
))
726 printk(KERN_ERR
"PSS: DMA allocation error\n");
727 release_region(hw_config
->io_base
, 0x10);
728 release_region(hw_config
->io_base
+0x10, 0x9);
733 configure_nonsound_components();
735 sprintf(tmp
, "ECHO-PSS Rev. %d", id
);
736 conf_printf(tmp
, hw_config
);
740 static int __init
probe_pss_mpu(struct address_info
*hw_config
)
742 struct resource
*ports
;
745 if (!pss_initialized
)
748 ports
= request_region(hw_config
->io_base
, 2, "mpu401");
751 printk(KERN_ERR
"PSS: MPU I/O port conflict\n");
754 set_io_base(devc
, CONF_MIDI
, hw_config
->io_base
);
755 if (!set_irq(devc
, CONF_MIDI
, hw_config
->irq
)) {
756 printk(KERN_ERR
"PSS: MIDI IRQ allocation error.\n");
760 printk(KERN_ERR
"PSS: Can't enable MPU. MIDI synth microcode not available.\n");
763 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
)) {
764 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
769 * Finally wait until the DSP algorithm has initialized itself and
770 * deactivates receive interrupt.
773 for (timeout
= 900000; timeout
> 0; timeout
--)
775 if ((inb(hw_config
->io_base
+ 1) & 0x80) == 0) /* Input data avail */
776 inb(hw_config
->io_base
); /* Discard it */
778 break; /* No more input */
781 if (!probe_mpu401(hw_config
, ports
))
784 attach_mpu401(hw_config
, THIS_MODULE
); /* Slot 1 */
785 if (hw_config
->slots
[1] != -1) /* The MPU driver installed itself */
786 midi_devs
[hw_config
->slots
[1]]->coproc
= &pss_coproc_operations
;
789 release_region(hw_config
->io_base
, 2);
793 static int pss_coproc_open(void *dev_info
, int sub_device
)
798 if (pss_synthLen
== 0)
800 printk(KERN_ERR
"PSS: MIDI synth microcode not available.\n");
803 if (nonstandard_microcode
)
804 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
806 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
809 nonstandard_microcode
= 0;
818 static void pss_coproc_close(void *dev_info
, int sub_device
)
823 static void pss_coproc_reset(void *dev_info
)
826 if (!pss_download_boot(devc
, pss_synth
, pss_synthLen
, CPF_FIRST
| CPF_LAST
))
828 printk(KERN_ERR
"PSS: Unable to load MIDI synth microcode to DSP.\n");
830 nonstandard_microcode
= 0;
833 static int download_boot_block(void *dev_info
, copr_buffer
* buf
)
835 if (buf
->len
<= 0 || buf
->len
> sizeof(buf
->data
))
838 if (!pss_download_boot(devc
, buf
->data
, buf
->len
, buf
->flags
))
840 printk(KERN_ERR
"PSS: Unable to load microcode block to DSP.\n");
843 nonstandard_microcode
= 1; /* The MIDI microcode has been overwritten */
847 static int pss_coproc_ioctl(void *dev_info
, unsigned int cmd
, void __user
*arg
, int local
)
854 unsigned short *data
;
856 /* printk( "PSS coproc ioctl %x %x %d\n", cmd, arg, local); */
860 case SNDCTL_COPR_RESET
:
861 pss_coproc_reset(dev_info
);
864 case SNDCTL_COPR_LOAD
:
865 buf
= vmalloc(sizeof(copr_buffer
));
868 if (copy_from_user(buf
, arg
, sizeof(copr_buffer
))) {
872 err
= download_boot_block(dev_info
, buf
);
876 case SNDCTL_COPR_SENDMSG
:
877 mbuf
= vmalloc(sizeof(copr_msg
));
880 if (copy_from_user(mbuf
, arg
, sizeof(copr_msg
))) {
884 data
= (unsigned short *)(mbuf
->data
);
885 spin_lock_irqsave(&lock
, flags
);
886 for (i
= 0; i
< mbuf
->len
; i
++) {
887 if (!pss_put_dspword(devc
, *data
++)) {
888 spin_unlock_irqrestore(&lock
,flags
);
889 mbuf
->len
= i
; /* feed back number of WORDs sent */
890 err
= copy_to_user(arg
, mbuf
, sizeof(copr_msg
));
892 return err
? -EFAULT
: -EIO
;
895 spin_unlock_irqrestore(&lock
,flags
);
899 case SNDCTL_COPR_RCVMSG
:
901 mbuf
= vmalloc(sizeof(copr_msg
));
904 data
= (unsigned short *)mbuf
->data
;
905 spin_lock_irqsave(&lock
, flags
);
906 for (i
= 0; i
< sizeof(mbuf
->data
)/sizeof(unsigned short); i
++) {
907 mbuf
->len
= i
; /* feed back number of WORDs read */
908 if (!pss_get_dspword(devc
, data
++)) {
914 spin_unlock_irqrestore(&lock
,flags
);
915 if (copy_to_user(arg
, mbuf
, sizeof(copr_msg
)))
920 case SNDCTL_COPR_RDATA
:
921 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
923 spin_lock_irqsave(&lock
, flags
);
924 if (!pss_put_dspword(devc
, 0x00d0)) {
925 spin_unlock_irqrestore(&lock
,flags
);
928 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
929 spin_unlock_irqrestore(&lock
,flags
);
932 if (!pss_get_dspword(devc
, &tmp
)) {
933 spin_unlock_irqrestore(&lock
,flags
);
937 spin_unlock_irqrestore(&lock
,flags
);
938 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
942 case SNDCTL_COPR_WDATA
:
943 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
945 spin_lock_irqsave(&lock
, flags
);
946 if (!pss_put_dspword(devc
, 0x00d1)) {
947 spin_unlock_irqrestore(&lock
,flags
);
950 if (!pss_put_dspword(devc
, (unsigned short) (dbuf
.parm1
& 0xffff))) {
951 spin_unlock_irqrestore(&lock
,flags
);
954 tmp
= (unsigned int)dbuf
.parm2
& 0xffff;
955 if (!pss_put_dspword(devc
, tmp
)) {
956 spin_unlock_irqrestore(&lock
,flags
);
959 spin_unlock_irqrestore(&lock
,flags
);
962 case SNDCTL_COPR_WCODE
:
963 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
965 spin_lock_irqsave(&lock
, flags
);
966 if (!pss_put_dspword(devc
, 0x00d3)) {
967 spin_unlock_irqrestore(&lock
,flags
);
970 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
971 spin_unlock_irqrestore(&lock
,flags
);
974 tmp
= (unsigned int)dbuf
.parm2
& 0x00ff;
975 if (!pss_put_dspword(devc
, tmp
)) {
976 spin_unlock_irqrestore(&lock
,flags
);
979 tmp
= ((unsigned int)dbuf
.parm2
>> 8) & 0xffff;
980 if (!pss_put_dspword(devc
, tmp
)) {
981 spin_unlock_irqrestore(&lock
,flags
);
984 spin_unlock_irqrestore(&lock
,flags
);
987 case SNDCTL_COPR_RCODE
:
988 if (copy_from_user(&dbuf
, arg
, sizeof(dbuf
)))
990 spin_lock_irqsave(&lock
, flags
);
991 if (!pss_put_dspword(devc
, 0x00d2)) {
992 spin_unlock_irqrestore(&lock
,flags
);
995 if (!pss_put_dspword(devc
, (unsigned short)(dbuf
.parm1
& 0xffff))) {
996 spin_unlock_irqrestore(&lock
,flags
);
999 if (!pss_get_dspword(devc
, &tmp
)) { /* Read MSB */
1000 spin_unlock_irqrestore(&lock
,flags
);
1003 dbuf
.parm1
= tmp
<< 8;
1004 if (!pss_get_dspword(devc
, &tmp
)) { /* Read LSB */
1005 spin_unlock_irqrestore(&lock
,flags
);
1008 dbuf
.parm1
|= tmp
& 0x00ff;
1009 spin_unlock_irqrestore(&lock
,flags
);
1010 if (copy_to_user(arg
, &dbuf
, sizeof(dbuf
)))
1020 static coproc_operations pss_coproc_operations
=
1031 static int __init
probe_pss_mss(struct address_info
*hw_config
)
1033 volatile int timeout
;
1034 struct resource
*ports
;
1035 int my_mix
= -999; /* gcc shut up */
1037 if (!pss_initialized
)
1040 if (!request_region(hw_config
->io_base
, 4, "WSS config")) {
1041 printk(KERN_ERR
"PSS: WSS I/O port conflicts.\n");
1044 ports
= request_region(hw_config
->io_base
+ 4, 4, "ad1848");
1046 printk(KERN_ERR
"PSS: WSS I/O port conflicts.\n");
1047 release_region(hw_config
->io_base
, 4);
1050 set_io_base(devc
, CONF_WSS
, hw_config
->io_base
);
1051 if (!set_irq(devc
, CONF_WSS
, hw_config
->irq
)) {
1052 printk("PSS: WSS IRQ allocation error.\n");
1055 if (!set_dma(devc
, CONF_WSS
, hw_config
->dma
)) {
1056 printk(KERN_ERR
"PSS: WSS DMA allocation error\n");
1060 * For some reason the card returns 0xff in the WSS status register
1061 * immediately after boot. Probably MIDI+SB emulation algorithm
1062 * downloaded to the ADSP2115 spends some time initializing the card.
1063 * Let's try to wait until it finishes this task.
1065 for (timeout
= 0; timeout
< 100000 && (inb(hw_config
->io_base
+ WSS_INDEX
) &
1066 WSS_INITIALIZING
); timeout
++)
1069 outb((0x0b), hw_config
->io_base
+ WSS_INDEX
); /* Required by some cards */
1071 for (timeout
= 0; (inb(hw_config
->io_base
+ WSS_DATA
) & WSS_AUTOCALIBRATION
) &&
1072 (timeout
< 100000); timeout
++)
1075 if (!probe_ms_sound(hw_config
, ports
))
1078 devc
->ad_mixer_dev
= NO_WSS_MIXER
;
1081 if ((my_mix
= sound_install_mixer (MIXER_DRIVER_VERSION
,
1082 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1083 &pss_mixer_operations
,
1084 sizeof (struct mixer_operations
),
1087 printk(KERN_ERR
"Could not install PSS mixer\n");
1091 pss_mixer_reset(devc
);
1092 attach_ms_sound(hw_config
, ports
, THIS_MODULE
); /* Slot 0 */
1094 if (hw_config
->slots
[0] != -1)
1096 /* The MSS driver installed itself */
1097 audio_devs
[hw_config
->slots
[0]]->coproc
= &pss_coproc_operations
;
1098 if (pss_mixer
&& (num_mixers
== (my_mix
+ 2)))
1100 /* The MSS mixer installed */
1101 devc
->ad_mixer_dev
= audio_devs
[hw_config
->slots
[0]]->mixer_dev
;
1106 release_region(hw_config
->io_base
+ 4, 4);
1107 release_region(hw_config
->io_base
, 4);
1111 static inline void __exit
unload_pss(struct address_info
*hw_config
)
1113 release_region(hw_config
->io_base
, 0x10);
1114 release_region(hw_config
->io_base
+0x10, 0x9);
1117 static inline void __exit
unload_pss_mpu(struct address_info
*hw_config
)
1119 unload_mpu401(hw_config
);
1122 static inline void __exit
unload_pss_mss(struct address_info
*hw_config
)
1124 unload_ms_sound(hw_config
);
1128 static struct address_info cfg
;
1129 static struct address_info cfg2
;
1130 static struct address_info cfg_mpu
;
1132 static int pss_io __initdata
= -1;
1133 static int mss_io __initdata
= -1;
1134 static int mss_irq __initdata
= -1;
1135 static int mss_dma __initdata
= -1;
1136 static int mpu_io __initdata
= -1;
1137 static int mpu_irq __initdata
= -1;
1138 static bool pss_no_sound
= 0; /* Just configure non-sound components */
1139 static bool pss_keep_settings
= 1; /* Keep hardware settings at module exit */
1140 static char *pss_firmware
= "/etc/sound/pss_synth";
1142 module_param(pss_io
, int, 0);
1143 MODULE_PARM_DESC(pss_io
, "Set i/o base of PSS card (probably 0x220 or 0x240)");
1144 module_param(mss_io
, int, 0);
1145 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)");
1146 module_param(mss_irq
, int, 0);
1147 MODULE_PARM_DESC(mss_irq
, "Set WSS (audio) IRQ (3, 5, 7, 9, 10, 11, 12)");
1148 module_param(mss_dma
, int, 0);
1149 MODULE_PARM_DESC(mss_dma
, "Set WSS (audio) DMA (0, 1, 3)");
1150 module_param(mpu_io
, int, 0);
1151 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)");
1152 module_param(mpu_irq
, int, 0);
1153 MODULE_PARM_DESC(mpu_irq
, "Set MIDI IRQ (3, 5, 7, 9, 10, 11, 12)");
1154 module_param(pss_cdrom_port
, int, 0);
1155 MODULE_PARM_DESC(pss_cdrom_port
, "Set the PSS CDROM port i/o base (0x340 or other)");
1156 module_param(pss_enable_joystick
, bool, 0);
1157 MODULE_PARM_DESC(pss_enable_joystick
, "Enables the PSS joystick port (1 to enable, 0 to disable)");
1158 module_param(pss_no_sound
, bool, 0);
1159 MODULE_PARM_DESC(pss_no_sound
, "Configure sound compoents (0 - no, 1 - yes)");
1160 module_param(pss_keep_settings
, bool, 0);
1161 MODULE_PARM_DESC(pss_keep_settings
, "Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1162 module_param(pss_firmware
, charp
, 0);
1163 MODULE_PARM_DESC(pss_firmware
, "Location of the firmware file (default - /etc/sound/pss_synth)");
1164 module_param(pss_mixer
, bool, 0);
1165 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.");
1166 MODULE_AUTHOR("Hannu Savolainen, Vladimir Michl");
1167 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).");
1168 MODULE_LICENSE("GPL");
1171 static int fw_load
= 0;
1172 static int pssmpu
= 0, pssmss
= 0;
1175 * Load a PSS sound card module
1178 static int __init
init_pss(void)
1181 if(pss_no_sound
) /* If configuring only nonsound components */
1183 cfg
.io_base
= pss_io
;
1184 if(!probe_pss(&cfg
))
1186 printk(KERN_INFO
"ECHO-PSS Rev. %d\n", inw(REG(PSS_ID
)) & 0x00ff);
1187 printk(KERN_INFO
"PSS: loading in no sound mode.\n");
1188 disable_all_emulations();
1189 configure_nonsound_components();
1190 release_region(pss_io
, 0x10);
1191 release_region(pss_io
+ 0x10, 0x9);
1195 cfg
.io_base
= pss_io
;
1197 cfg2
.io_base
= mss_io
;
1201 cfg_mpu
.io_base
= mpu_io
;
1202 cfg_mpu
.irq
= mpu_irq
;
1204 if (cfg
.io_base
== -1 || cfg2
.io_base
== -1 || cfg2
.irq
== -1 || cfg
.dma
== -1) {
1205 printk(KERN_INFO
"pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1211 pss_synthLen
= mod_firmware_load(pss_firmware
, (void *) &pss_synth
);
1213 if (!attach_pss(&cfg
))
1218 if (probe_pss_mpu(&cfg_mpu
))
1221 if (probe_pss_mss(&cfg2
))
1227 static void __exit
cleanup_pss(void)
1234 unload_pss_mss(&cfg2
);
1236 unload_pss_mpu(&cfg_mpu
);
1238 } else if (pss_cdrom_port
!= -1)
1239 release_region(pss_cdrom_port
, 2);
1241 if(!pss_keep_settings
) /* Keep hardware settings if asked */
1243 disable_all_emulations();
1244 printk(KERN_INFO
"Resetting PSS sound card configurations.\n");
1248 module_init(init_pss
);
1249 module_exit(cleanup_pss
);
1252 static int __init
setup_pss(char *str
)
1254 /* io, mss_io, mss_irq, mss_dma, mpu_io, mpu_irq */
1257 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1269 __setup("pss=", setup_pss
);