61 #include <linux/module.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"
119 #ifdef CONFIG_PSS_MIXER
120 static bool pss_mixer = 1;
122 static bool pss_mixer;
147 static int pss_initialized;
148 static int nonstandard_microcode;
149 static int pss_cdrom_port = -1;
150 static bool pss_enable_joystick;
166 for (i = 0; i < 5000000 &&
time_before(jiffies, limit); i++)
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)
196 if ((
id >> 8) !=
'E') {
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
221 if (irq < 0 || irq > 15)
224 tmp =
inw(
REG(dev)) & ~0x38;
226 if ((bits = irq_bits[irq]) == 0 && irq != 0)
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;
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
253 if (dma < 0 || dma > 7)
256 tmp =
inw(
REG(dev)) & ~0x07;
258 if ((bits = dma_bits[dma]) == 0 && dma != 4)
282 for (i = 0; i < 327680; i++)
294 static int pss_get_dspword(
pss_confdata * devc,
unsigned short *word)
298 for (i = 0; i < 327680; i++)
321 for (i = 0; i < 32768 &&
time_before(jiffies, limit); i++)
329 while ((flags&
CPF_LAST) || count<size )
333 for (j = 0; j < 327670; j++)
343 if (count >= size && flags & CPF_LAST)
348 printk(
KERN_ERR "PSS: Download timeout problems, byte %d=%d\n", count, size);
366 if (flags & CPF_LAST)
384 for (i = 0; i < 32000; i++)
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);
422 pss_write(devc, 0x0080);
423 pss_write(devc, vol);
424 pss_write(devc, 0x0081);
425 pss_write(devc, vol);
430 int vol = (
int)(((0xfd - 0xf0) * level)/100
L) + 0xf0;
431 pss_write(devc, 0x0010);
432 pss_write(devc, vol | 0x0200);
437 int vol = (((0xfd - 0xf0) * level)/100
L) + 0xf0;
438 pss_write(devc, 0x0010);
439 pss_write(devc, vol | 0x0300);
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);
460 static int set_volume_mono(
unsigned __user *
p,
unsigned int *aleft)
466 left = volume & 0xff;
473 static int set_volume_stereo(
unsigned __user *p,
475 unsigned int *aright)
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);
510 static int pss_mixer_ioctl (
int dev,
unsigned int cmd,
void __user *arg)
513 int cmdf = cmd & 0xff;
521 return call_ad_mixer(devc, cmd, arg);
524 if (((cmd >> 8) & 0xff) !=
'M')
533 return call_ad_mixer(devc, cmd, arg);
544 if (set_volume_stereo(arg,
554 if (set_volume_mono(arg, &devc->
mixer.
bass))
584 if (call_ad_mixer(devc, cmd, arg) == -
EINVAL)
591 if (call_ad_mixer(devc, cmd, arg) == -
EINVAL)
599 return call_ad_mixer(devc, cmd, arg);
604 return call_ad_mixer(devc, cmd, arg);
610 return call_ad_mixer(devc, cmd, arg);
631 if (
get_user(val, (
int __user *)arg))
635 if (
put_user(val, (
int __user *)arg))
645 .name =
"PSS-AD1848",
646 .ioctl = pss_mixer_ioctl
649 static void disable_all_emulations(
void)
658 static void configure_nonsound_components(
void)
662 if(pss_enable_joystick)
674 if (pss_cdrom_port == -1) {
680 set_io_base(devc,
CONF_CDROM, pss_cdrom_port);
681 printk(
KERN_INFO "PSS: CDROM I/O port set to 0x%x.\n", pss_cdrom_port);
691 devc->
irq = hw_config->
irq;
692 devc->
dma = hw_config->
dma;
693 devc->
osp = hw_config->
osp;
696 if (!probe_pss(hw_config))
705 disable_all_emulations();
707 #ifdef YOU_REALLY_WANT_TO_ALLOCATE_THESE_RESOURCES
710 printk(
"pss.c: Can't allocate DMA channel.\n");
717 printk(
"PSS: IRQ allocation error.\n");
731 configure_nonsound_components();
733 sprintf(tmp,
"ECHO-PSS Rev. %d",
id);
743 if (!pss_initialized)
758 printk(
KERN_ERR "PSS: Can't enable MPU. MIDI synth microcode not available.\n");
761 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST)) {
762 printk(
KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
771 for (timeout = 900000; timeout > 0; timeout--)
773 if ((
inb(hw_config->
io_base + 1) & 0x80) == 0)
783 if (hw_config->
slots[1] != -1)
791 static int pss_coproc_open(
void *
dev_info,
int sub_device)
796 if (pss_synthLen == 0)
801 if (nonstandard_microcode)
802 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
804 printk(
KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
807 nonstandard_microcode = 0;
816 static void pss_coproc_close(
void *dev_info,
int sub_device)
821 static void pss_coproc_reset(
void *dev_info)
824 if (!pss_download_boot(devc, pss_synth, pss_synthLen, CPF_FIRST | CPF_LAST))
826 printk(
KERN_ERR "PSS: Unable to load MIDI synth microcode to DSP.\n");
828 nonstandard_microcode = 0;
833 if (buf->
len <= 0 || buf->
len >
sizeof(buf->
data))
836 if (!pss_download_boot(devc, buf->
data, buf->
len, buf->
flags))
841 nonstandard_microcode = 1;
845 static int pss_coproc_ioctl(
void *dev_info,
unsigned int cmd,
void __user *arg,
int local)
852 unsigned short *
data;
859 pss_coproc_reset(dev_info);
870 err = download_boot_block(dev_info, buf);
882 data = (
unsigned short *)(mbuf->
data);
884 for (i = 0; i < mbuf->
len; i++) {
885 if (!pss_put_dspword(devc, *data++)) {
886 spin_unlock_irqrestore(&lock,flags);
893 spin_unlock_irqrestore(&lock,flags);
902 data = (
unsigned short *)mbuf->
data;
904 for (i = 0; i <
sizeof(mbuf->
data)/
sizeof(
unsigned short); i++) {
906 if (!pss_get_dspword(devc, data++)) {
912 spin_unlock_irqrestore(&lock,flags);
922 if (!pss_put_dspword(devc, 0x00d0)) {
923 spin_unlock_irqrestore(&lock,flags);
926 if (!pss_put_dspword(devc, (
unsigned short)(dbuf.
parm1 & 0xffff))) {
927 spin_unlock_irqrestore(&lock,flags);
930 if (!pss_get_dspword(devc, &tmp)) {
931 spin_unlock_irqrestore(&lock,flags);
935 spin_unlock_irqrestore(&lock,flags);
944 if (!pss_put_dspword(devc, 0x00d1)) {
945 spin_unlock_irqrestore(&lock,flags);
948 if (!pss_put_dspword(devc, (
unsigned short) (dbuf.
parm1 & 0xffff))) {
949 spin_unlock_irqrestore(&lock,flags);
952 tmp = (
unsigned int)dbuf.
parm2 & 0xffff;
953 if (!pss_put_dspword(devc, tmp)) {
954 spin_unlock_irqrestore(&lock,flags);
957 spin_unlock_irqrestore(&lock,flags);
964 if (!pss_put_dspword(devc, 0x00d3)) {
965 spin_unlock_irqrestore(&lock,flags);
968 if (!pss_put_dspword(devc, (
unsigned short)(dbuf.
parm1 & 0xffff))) {
969 spin_unlock_irqrestore(&lock,flags);
972 tmp = (
unsigned int)dbuf.
parm2 & 0x00ff;
973 if (!pss_put_dspword(devc, tmp)) {
974 spin_unlock_irqrestore(&lock,flags);
977 tmp = ((
unsigned int)dbuf.
parm2 >> 8) & 0xffff;
978 if (!pss_put_dspword(devc, tmp)) {
979 spin_unlock_irqrestore(&lock,flags);
982 spin_unlock_irqrestore(&lock,flags);
989 if (!pss_put_dspword(devc, 0x00d2)) {
990 spin_unlock_irqrestore(&lock,flags);
993 if (!pss_put_dspword(devc, (
unsigned short)(dbuf.
parm1 & 0xffff))) {
994 spin_unlock_irqrestore(&lock,flags);
997 if (!pss_get_dspword(devc, &tmp)) {
998 spin_unlock_irqrestore(&lock,flags);
1001 dbuf.
parm1 = tmp << 8;
1002 if (!pss_get_dspword(devc, &tmp)) {
1003 spin_unlock_irqrestore(&lock,flags);
1006 dbuf.
parm1 |= tmp & 0x00ff;
1007 spin_unlock_irqrestore(&lock,flags);
1031 volatile int timeout;
1035 if (!pss_initialized)
1050 printk(
"PSS: WSS IRQ allocation error.\n");
1070 (timeout < 100000); timeout++)
1080 "PSS-SPEAKERS and AD1848 (through MSS audio codec)",
1081 &pss_mixer_operations,
1089 pss_mixer_reset(devc);
1092 if (hw_config->
slots[0] != -1)
1096 if (pss_mixer && (
num_mixers == (my_mix + 2)))
1131 static int mss_io __initdata = -1;
1132 static int mss_irq __initdata = -1;
1133 static int mss_dma __initdata = -1;
1134 static int mpu_io __initdata = -1;
1135 static int mpu_irq __initdata = -1;
1136 static bool pss_no_sound = 0;
1137 static bool pss_keep_settings = 1;
1138 static char *pss_firmware =
"/etc/sound/pss_synth";
1141 MODULE_PARM_DESC(pss_io,
"Set i/o base of PSS card (probably 0x220 or 0x240)");
1143 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)");
1149 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)");
1153 MODULE_PARM_DESC(pss_cdrom_port,
"Set the PSS CDROM port i/o base (0x340 or other)");
1155 MODULE_PARM_DESC(pss_enable_joystick,
"Enables the PSS joystick port (1 to enable, 0 to disable)");
1157 MODULE_PARM_DESC(pss_no_sound,
"Configure sound compoents (0 - no, 1 - yes)");
1159 MODULE_PARM_DESC(pss_keep_settings,
"Keep hardware setting at driver unloading (0 - no, 1 - yes)");
1161 MODULE_PARM_DESC(pss_firmware,
"Location of the firmware file (default - /etc/sound/pss_synth)");
1163 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.");
1165 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).");
1169 static int fw_load = 0;
1170 static int pssmpu = 0, pssmss = 0;
1176 static int __init init_pss(
void)
1181 cfg.io_base = pss_io;
1182 if(!probe_pss(&
cfg))
1186 disable_all_emulations();
1187 configure_nonsound_components();
1193 cfg.io_base = pss_io;
1195 cfg2.io_base = mss_io;
1199 cfg_mpu.io_base = mpu_io;
1200 cfg_mpu.irq = mpu_irq;
1202 if (
cfg.io_base == -1 || cfg2.io_base == -1 || cfg2.irq == -1 ||
cfg.dma == -1) {
1203 printk(
KERN_INFO "pss: mss_io, mss_dma, mss_irq and pss_io must be set.\n");
1211 if (!attach_pss(&
cfg))
1216 if (probe_pss_mpu(&cfg_mpu))
1219 if (probe_pss_mss(&cfg2))
1225 static void __exit cleanup_pss(
void)
1229 if(fw_load && pss_synth)
1232 unload_pss_mss(&cfg2);
1234 unload_pss_mpu(&cfg_mpu);
1236 }
else if (pss_cdrom_port != -1)
1239 if(!pss_keep_settings)
1241 disable_all_emulations();