Commit e695b6a4 authored by Linus Torvalds's avatar Linus Torvalds

Import 1.1.10

parent ccec108f
VERSION = 1
PATCHLEVEL = 1
SUBLEVEL = 9
SUBLEVEL = 10
all: Version zImage
......
......@@ -91,17 +91,20 @@ int el3_probe(struct device *dev)
/* First check for a board on the EISA bus. */
if (EISA_bus) {
for (ioaddr = 0x1000; ioaddr < 0x9000; ioaddr += 0x1000) {
if (inw(ioaddr) != 0x6d50)
/* Check the standard EISA ID register for an encoded '3Com'. */
if (inw(ioaddr + 0xC80) != 0x6d50)
continue;
/* Change the register set to the configuration window 0. */
outw(0x0800, ioaddr + 0xC80 + EL3_CMD);
irq = inw(ioaddr + 8) >> 12;
if_port = inw(ioaddr + 6)>>14;
for (i = 0; i < 3; i++)
phys_addr[i] = htons(read_eeprom(ioaddr, i));
/* Restore the "Manufacturer ID" to the EEPROM read register. */
/* The manual says to restore "Product ID" (reg. 3). !???! */
read_eeprom(ioaddr, 7);
/* Restore the "Product ID" to the EEPROM read register. */
read_eeprom(ioaddr, 3);
/* Was the EISA code an add-on hack? Nahhhhh... */
goto found;
......
......@@ -4,9 +4,3 @@ NOTE! This driver version is not compatible with the version 1.0c.
other programs using ioctl calls of the driver, they must be
recompiled. Most of them will not work without some source
modifications.
******** LINUX VERSION 0.99.14 OR LATER IS REQUIRED *******
See sound/Readme for more details
Hannu
Changelog for version 2.4
-------------------------
Changelog for version 2.5a
--------------------------
Since 2.5
- Minor fix to read from /dev/sequencer
Since 2.5-beta2
- Some fine tuning to the GUS v3.7 mixer code.
- Fixed speed limits for the plain SB (1.0 to 2.0).
Since 2.5-beta
- Fixed OPL-3 detection with SB. Caused problems with PAS16.
- GUS v3.7 mixer support.
Since 2.4
- Mixer support for Sound Galaxy NX Pro (define __SGNXPRO__ on your local.h).
- Fixed truncated sound on /dev/dsp when the device is closed.
- Linear volume mode for GUS
- Pitch bends larger than +/- 2 octaves.
- MIDI recording for SB and SB Pro. (Untested).
- Some other fixes.
- SB16 MIDI and DSP drivers only initialized if SB16 actually installed.
- Implemented better detection for OPL-3. This should be usefull if you
have an old SB Pro (the non-OPL-3 one) or a SB 2.0 clone which has a OPL-3.
- SVR4.2 support by Ian Hartas. Initial ALPHA TEST version (untested).
Since 2.3b
- Fixed bug which made it impossible to make long recordings to disk.
......
......@@ -5,7 +5,7 @@
#
#
VERSION = 2.4
VERSION = 2.5a
TARGET_OS = linux
.c.s:
......@@ -19,7 +19,7 @@ OBJS = soundcard.o audio.o dmabuf.o sb_dsp.o dev_table.o \
opl3.o sequencer.o midibuf.o sb_card.o pas2_card.o adlib_card.o \
pas2_pcm.o pas2_mixer.o pas2_midi.o gus_card.o gus_wave.o mpu401.o \
gus_midi.o gus_vol.o patmgr.o sb_mixer.o sb16_dsp.o sb_midi.o \
sb16_midi.o sound_switch.o
sb16_midi.o sound_switch.o ics2101.o
all: local.h sound.a
......
Release notes for the Linux Sound Driver 2.4
--------------------------------------------
Release notes for the Linux Sound Driver 2.5a
---------------------------------------------
This directory contains just the Linux version. The portable version
(SCO/ISC, FreeBSD/NetBSD and SVR4.2) is available from sunsite.unc.edu:
pub/Linux/kernel/sound.
This is mainly a bug fix release. There are couple of new things such as
linear volume mode for GUS and MIDI recording for SB 2.0 and SB Pro.
Also this version supports the mixer of GUS v3.7. (Support for GUS MAX and
the 16-bit daughtercard is coming sooner or later).
NOTE! The sound driver is a part of the Linux kernel distribution also.
Check that your kernel doesn't have more recent version than this
......@@ -17,17 +25,13 @@ time with the /dev/dsp. Also the WaveBlaster daughter board is supported.
No support for the ASP chip yet (the ASP chip can be installed but it's
not used by the driver).
You will need the snd-util-2.4.tar.gz and snd-data-0.1.tar.Z
You will need the snd-util-2.5.tar.gz and snd-data-0.1.tar.Z
packages to use this driver. They should be in the same
ftp site or BBS from where you got this driver. For
example at nic.funet.fi:pub/OS/Linux/*.
There is a new version of the tracker program available (tracker-3_19.lzh) but
I don't know where it is available. The tracker 3.10 has bugs and it don't work
without some fixes. Look at the README of the snd-util-2.3.
If you are looking for the installation instructions, please
look at linux/Readme.
look at $OS/Readme.
This version supports the following soundcards:
GUS, SoundBlaster, SB Pro, SB16, Pro Audio Spectrum 16 and AdLib.
......@@ -36,19 +40,6 @@ In addition there is rather limited support for MPU-401.
Most of the features of the /dev/sequencer device file are
available just for GUS owners.
NOTE! There are separate driver for CD-ROMS supported by
some soundcards. The driver for CDU31A (Fusion 16) is
called cdu31a-0.6.diff.z. It will be contained in the
Linux version 0.99.12. The driver for the CD-ROM of SB Pro
is sbpcd0.4.tar.gz (these were the latest versions when I wrote
this). These files should be at least at sunsite.unc.edu.
Also the SCSI interface of the PAS16 should be supported by
Linux 0.99.13k and later.
There is also a driver for joystick. Look for file joystick-0.5.tar.gz
(sunsite).
Compatibility with the earlier versions
---------------------------------------
......@@ -104,58 +95,6 @@ at the same time, the ioctl(SNDCTL_FM_LOAD_INSTR) is obsolete. In addition
there is some new fields which must be initialized. Look at the sbiset.c in
the snd-util-2.0 package for further info.
This version is almost 100% compatible with the alpha test version (1.99.9). The
difference is in the installation procedure.
Using this driver with other operating systems than Linux
---------------------------------------------------------
This package contains just the Linux version. The version 2.3
for SCO is available at nic.funet.fi:pub/OS/Linux/ALPHA/sound.
The version 2.3 doesn't work well with xxxxxBSD. Use the version
2.3 for them.
/dev/sndstat
------------
The /dev/sndstat is now available in the SCO and BSD versions also.
This is a new devicefile for debugging purposes. A better place for
it is in the /proc -directory but I was just too lazy to implement it
properly. The /dev/sndstat (major 14, minor 6) is a file which returns
info about the current configuration (see the example below). If you
send me a error/problem report, please include a printout from this
device to your message (cat /dev/sndstat).
Note! This device file is currently present only in the Linux version
of this driver.
------ cut here --- cat /dev/sndstat example --------
Sound Driver:1.99.7 (Fri Jul 9 17:01:47 GMT 1993 root@lucifer.savolai.fi)
Config options: 0x00000d4b
HW config:
Type 4: Gravis Ultrasound at 0x210 irq 15 drq 6
Type 3: ProAudioSpectrum at 0x388 irq 10 drq 3
Type 2: SoundBlaster at 0x220 irq 7 drq 1
Type 1: AdLib at 0x388 irq 0 drq 0
PCM devices:
00: Gravis UltraSound
01: Pro Audio Spectrum
02: SoundBlaster 2.0
Synth devices:
00: Gravis UltraSound
01: Yamaha OPL-3
Midi devices:
00: Gravis UltraSound
01: Pro Audio Spectrum
Mixer(s) installed
------ cut here ---- End of Example -----------
Known bugs/limitations
----------------------
......@@ -164,7 +103,6 @@ Known bugs/limitations
recording process too much. A delay longer than 0.1 to 0.3 seconds is
too much.
- The SB16 driver sometimes swaps the left and right channels together.
- Midi input doesn't work with SB and SB Pro (SB16 works).
- It's not possible to open /dev/dsp (or /dev/audio) while the
/dev/sequencer is open for output and GUS is the only soundcard
installed. It's possible if /dev/dsp is opened before /dev/sequencer
......@@ -173,9 +111,6 @@ Known bugs/limitations
- MPU-401 driver hangs the computer on boot if there is no MPU-401 installed.
It uses by default the I/O port 0x330 whic is used by Adaptec 1542 SCSI
adapter.
- There are some problems in midi input with MPU-401 and the SB16 midi
(MPU-401 emulation). This makes it impossible to read long sysex dumps
using these devices.
- The /dev/sequencer playback to GUS sounds sometimes rather weird. Hitting
^C and playing again should solve this problem. This is propably caused by
incompatibilities between GUS and certain VLB motherboards (like mine).
......@@ -225,16 +160,23 @@ contributors. (I could have forgotten some names.)
Mika Liljeberg uLaw encoding and decoding routines
Greg Lee Volume computation algorithm for the GUS and
lot's of valuable suggestions.
Andy Warner ISC port
Jim Lowe FreeBSD port
Andy Warner Initial ISC port
Jim Lowe Initial FreeBSD port
Anders Baekgaard Bughunting and valuable suggestions.
Joerg Schubert SB16 DSP support.
Andrew Robinson Improvements to the GUS driver
Megens SA MIDI recording for SB and SB Pro.
Mikael Nordqvist Linear volume support for GUS.
Ian Hartas SVR4.2 port
Markus Aroharju and
Risto Kankkunen Major contributions to the mixer support
of GUS v3.7.
Hunyue Yau Sound Galaxy NX Pro mixer support.
Regards,
Hannu Savolainen
hsavolai@cs.helsinki.fi
hannu@voxware.pp.fi, Hannu.Savolainen@Helsinki.fi
Snail mail: Hannu Savolainen
Pallaksentie 4 A 2
......
Sound Driver version 2.4 for Linux
Sound Driver version 2.5 for Linux
----------------------------------
NOTE! The sound driver is now a part of the Linux kernel distribution.
......@@ -174,7 +174,8 @@ If you want to play modules on a 386sx while recompiling the world, buy a GUS.
It runs without burning your CPU.
Hannu Savolainen
hsavolai@cs.helsinki.fi
Hannu.Savolainen@Helsinki.fi
(hannu@voxware.pp.fi (april 94 ->))
----------------- cut here ------------------------------
#!/bin/sh
......
......@@ -38,10 +38,12 @@
#define OFF 0
static int wr_buff_no[MAX_DSP_DEV]; /* != -1, if there is a
* incomplete output block */
static int wr_buff_size[MAX_DSP_DEV], wr_buff_ptr[MAX_DSP_DEV];
static int audio_mode[MAX_DSP_DEV];
#define AM_NONE 0
#define AM_WRITE 1
#define AM_READ 2
......@@ -181,7 +183,7 @@ audio_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
/* This just allows interrupts while the conversion is running */
__asm__ ("sti");
#endif
translate_bytes (ulaw_dsp, &wr_dma_buf[dev][wr_buff_ptr[dev]], l);
translate_bytes (ulaw_dsp, (unsigned char *) &wr_dma_buf[dev][wr_buff_ptr[dev]], l);
}
c -= l;
......@@ -242,7 +244,7 @@ audio_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
__asm__ ("sti");
#endif
translate_bytes (dsp_ulaw, dmabuf, l);
translate_bytes (dsp_ulaw, (unsigned char *) dmabuf, l);
}
COPY_TO_USER (buf, p, dmabuf, l);
......@@ -261,6 +263,7 @@ audio_ioctl (int dev, struct fileinfo *file,
unsigned int cmd, unsigned int arg)
{
int dev_type = dev & 0x0f;
dev = dev >> 4;
switch (cmd)
......@@ -321,14 +324,14 @@ audio_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
int
audio_open (int dev, struct fileinfo *file)
{
{
return RET_ERROR (ENXIO);
}
}
void
audio_release (int dev, struct fileinfo *file)
{
};
{
};
int
audio_ioctl (int dev, struct fileinfo *file,
unsigned int cmd, unsigned int arg)
......
......@@ -286,8 +286,8 @@ main (int argc, char *argv[])
}
}
if (selected_options & B(OPT_SB16))
selected_options |= B(OPT_SBPRO);
if (selected_options & B (OPT_SB16))
selected_options |= B (OPT_SBPRO);
if (!(selected_options & ANY_DEVS))
{
......@@ -319,8 +319,9 @@ main (int argc, char *argv[])
if (selected_options & B (OPT_SB) && selected_options & (B (OPT_AUDIO) | B (OPT_MIDI)))
{
fprintf (stderr, "\nIRQ number for SoundBlaster?\n"
"The IRQ adress is defined by the jumpers on your card and\n"
"7 is the factory default. Valid values are 9, 5, 7 and 10.\n"
"The IRQ address is defined by the jumpers on your card.\n"
"The factory default is either 5 or 7 (depending on the model).\n"
"Valid values are 9, 5, 7 and 10.\n"
"Enter the value: ");
num = ask_value ("%d", 7);
......@@ -331,9 +332,10 @@ main (int argc, char *argv[])
num = 7;
}
fprintf (stderr, "SoundBlaster IRQ set to %d\n", num);
printf ("#define SBC_BASE 0x220\n");
printf ("#define SBC_IRQ %d\n", num);
if (selected_options & B (OPT_SBPRO))
if (selected_options & (B (OPT_SBPRO) | B (OPT_PAS)))
{
fprintf (stderr, "\nDMA channel for SoundBlaster?\n"
......@@ -428,7 +430,7 @@ main (int argc, char *argv[])
if (selected_options & B (OPT_GUS))
{
fprintf (stderr, "\nI/O base for Gravis Ultrasound?\n"
"Valid choises are 210, 220, 230, 240, 250 or 260\n"
"Valid choices are 210, 220, 230, 240, 250 or 260\n"
"The factory default is 220\n"
"Enter the GUS I/O base: ");
......@@ -515,7 +517,7 @@ main (int argc, char *argv[])
{
def_size = 16384;
if (selected_options & (B (OPT_SBPRO) | B (OPT_PAS) | B(OPT_SB16)))
if (selected_options & (B (OPT_SBPRO) | B (OPT_PAS) | B (OPT_SB16)))
def_size = 32768;
#ifndef __386BSD__
......@@ -543,7 +545,7 @@ main (int argc, char *argv[])
fprintf (stderr, "The sound driver is now configured.\n");
#if defined(SCO) || defined(ISC) || defined(SYSV)
fprintf(stderr, "Rember to update the System file\n");
fprintf (stderr, "Remember to update the System file\n");
#endif
exit (0);
......
......@@ -55,7 +55,7 @@ sndtable_init (long mem_start)
#endif
}
else
supported_drivers[i].enabled=0; /* Mark as not detected */
supported_drivers[i].enabled = 0; /* Mark as not detected */
return mem_start;
}
......@@ -73,8 +73,9 @@ sndtable_probe (int unit, struct address_info *hw_config)
supported_drivers[i].config.io_base = hw_config->io_base;
supported_drivers[i].config.irq = hw_config->irq;
supported_drivers[i].config.dma = hw_config->dma;
if (supported_drivers[i].probe (hw_config)) return 1;
supported_drivers[i].enabled=0; /* Mark as not detected */
if (supported_drivers[i].probe (hw_config))
return 1;
supported_drivers[i].enabled = 0; /* Mark as not detected */
return 0;
}
......@@ -115,34 +116,36 @@ sndtable_get_cardcount (void)
}
#ifdef linux
void sound_setup(char *str, int *ints)
void
sound_setup (char *str, int *ints)
{
int i, n = sizeof (supported_drivers) / sizeof (struct card_info);
/*
/*
* First disable all drivers
*/
for (i=0;i<n;i++)
for (i = 0; i < n; i++)
supported_drivers[i].enabled = 0;
if (ints[0] == 0 || ints[1] == 0) return;
/*
if (ints[0] == 0 || ints[1] == 0)
return;
/*
* Then enable them one by time
*/
for (i=1;i<=ints[0];i++)
for (i = 1; i <= ints[0]; i++)
{
int card_type, ioaddr, irq, dma, ptr, j;
unsigned int val;
val = (unsigned int)ints[i];
val = (unsigned int) ints[i];
card_type = (val & 0x0ff00000) >> 20;
if (card_type > 127)
{
/* Add any future extensions here*/
/* Add any future extensions here */
return;
}
......@@ -151,12 +154,12 @@ void sound_setup(char *str, int *ints)
dma = (val & 0x0000000f);
ptr = -1;
for (j=0;j<n && ptr == -1;j++)
for (j = 0; j < n && ptr == -1; j++)
if (supported_drivers[j].card_type == card_type)
ptr = j;
if (ptr == -1)
printk("Sound: Invalid setup parameter 0x%08x\n", val);
printk ("Sound: Invalid setup parameter 0x%08x\n", val);
else
{
supported_drivers[ptr].enabled = 1;
......@@ -166,40 +169,49 @@ void sound_setup(char *str, int *ints)
}
}
}
#else
void sound_chconf(int card_type, int ioaddr, int irq, int dma)
void
sound_chconf (int card_type, int ioaddr, int irq, int dma)
{
int i, n = sizeof (supported_drivers) / sizeof (struct card_info);
int ptr, j;
ptr = -1;
for (j=0;j<n && ptr == -1;j++)
for (j = 0; j < n && ptr == -1; j++)
if (supported_drivers[j].card_type == card_type)
ptr = j;
if (ptr != -1)
{
supported_drivers[ptr].enabled = 1;
if (ioaddr) supported_drivers[ptr].config.io_base = ioaddr;
if (irq) supported_drivers[ptr].config.irq = irq;
if (dma) supported_drivers[ptr].config.dma = dma;
if (ioaddr)
supported_drivers[ptr].config.io_base = ioaddr;
if (irq)
supported_drivers[ptr].config.irq = irq;
if (dma)
supported_drivers[ptr].config.dma = dma;
}
}
#endif
struct address_info *sound_getconf(int card_type)
struct address_info *
sound_getconf (int card_type)
{
int j, ptr;
int n = sizeof (supported_drivers) / sizeof (struct card_info);
ptr = -1;
for (j=0;j<n && ptr == -1;j++)
for (j = 0; j < n && ptr == -1; j++)
if (supported_drivers[j].card_type == card_type)
ptr = j;
if (ptr == -1) return (struct address_info *)NULL;
if (ptr == -1)
return (struct address_info *) NULL;
return &supported_drivers[ptr].config;
}
#endif
......@@ -58,6 +58,9 @@ struct generic_midi_info{
struct audio_operations {
char name[32];
int flags;
#define NOTHING_SPECIAL 0
#define NEEDS_RESTART 1
int (*open) (int dev, int mode);
void (*close) (int dev);
void (*output_block) (int dev, unsigned long buf,
......@@ -96,6 +99,7 @@ struct synth_operations {
void (*aftertouch) (int dev, int voice, int pressure);
void (*controller) (int dev, int voice, int ctrl_num, int value);
void (*panning) (int dev, int voice, int value);
void (*volume_method) (int dev, int mode);
int (*pmgr_interface) (int dev, struct patmgr_info *info);
};
......@@ -177,7 +181,7 @@ struct generic_midi_operations {
{SBC_BASE, SBC_IRQ, SBC_DMA}, SND_DEFAULT_ENABLE},
#endif
#if !defined(EXCLUDE_SB) && !defined(EXCLUDE_SB16)
#if !defined(EXCLUDE_SB) && !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SBPRO)
#ifndef EXCLUDE_AUDIO
{SNDCARD_SB16, "SoundBlaster16", sb16_dsp_init, sb16_dsp_detect,
{SBC_BASE, SBC_IRQ, SB16_DMA}, SND_DEFAULT_ENABLE},
......
......@@ -88,12 +88,14 @@ static int bufferalloc_done[MAX_DSP_DEV] =
*/
static int dev_nbufs[MAX_DSP_DEV]; /* # of logical buffers ( >=
* sound_buffcounts[dev] */
static int dev_counts[MAX_DSP_DEV][MAX_SUB_BUFFERS];
static int dev_subdivision[MAX_DSP_DEV];
static unsigned long dev_buf_phys[MAX_DSP_DEV][MAX_SUB_BUFFERS];
static char *dev_buf[MAX_DSP_DEV][MAX_SUB_BUFFERS] =
{{NULL}};
{
{NULL}};
static int dev_buffsize[MAX_DSP_DEV];
static void
......@@ -139,9 +141,10 @@ reorganize_buffers (int dev)
bsz /= dev_subdivision[dev]; /* Use smaller buffers */
if (bsz == 0) bsz = 4096; /* Just a sanity check */
if (bsz == 0)
bsz = 4096; /* Just a sanity check */
while ((sound_buffsizes[dev]*sound_buffcounts[dev])/bsz > MAX_SUB_BUFFERS)
while ((sound_buffsizes[dev] * sound_buffcounts[dev]) / bsz > MAX_SUB_BUFFERS)
bsz <<= 1; /* Too much buffers */
dev_buffsize[dev] = bsz;
......@@ -175,7 +178,7 @@ reorganize_buffers (int dev)
}
static void
dma_init_buffers(int dev)
dma_init_buffers (int dev)
{
RESET_WAIT_QUEUE (dev_sleeper[dev], dev_sleep_flag[dev]);
dev_underrun[dev] = 0;
......@@ -210,7 +213,7 @@ DMAbuf_open (int dev, int mode)
}
#ifdef USE_RUNTIME_DMAMEM
sound_dma_malloc(dev);
sound_dma_malloc (dev);
#endif
if (snd_raw_buf[dev][0] == NULL)
......@@ -222,7 +225,7 @@ DMAbuf_open (int dev, int mode)
dev_modes[dev] = mode;
dev_subdivision[dev] = 0;
dma_init_buffers(dev);
dma_init_buffers (dev);
dsp_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_BITS, 8, 1);
dsp_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_CHANNELS, 1, 1);
dsp_devs[dev]->ioctl (dev, SOUND_PCM_WRITE_RATE, DSP_DEFAULT_SPEED, 1);
......@@ -236,39 +239,34 @@ dma_reset (int dev)
int retval;
unsigned long flags;
DISABLE_INTR(flags);
DISABLE_INTR (flags);
dsp_devs[dev]->reset (dev);
dsp_devs[dev]->close (dev);
if ((retval = dsp_devs[dev]->open (dev, dev_modes[dev])) < 0)
printk("Sound: Reset failed - Can't reopen device\n");
RESTORE_INTR(flags);
printk ("Sound: Reset failed - Can't reopen device\n");
RESTORE_INTR (flags);
dma_init_buffers(dev);
reorganize_buffers(dev);
dma_init_buffers (dev);
reorganize_buffers (dev);
}
static int
dma_sync (int dev)
{
unsigned long flags;
unsigned long time;
int timed_out;
if (dma_mode[dev] == DMODE_OUTPUT)
{
DISABLE_INTR (flags);
timed_out = 0;
time = GET_TIME ();
while ((!(PROCESS_ABORTING (dev_sleeper[dev], dev_sleep_flag[dev]) ||
dmabuf_interrupted[dev]) && !timed_out)
dmabuf_interrupted[dev]))
&& dev_qlen[dev])
{
DO_SLEEP (dev_sleeper[dev], dev_sleep_flag[dev], 10 * HZ);
if ((GET_TIME () - time) > (10 * HZ))
timed_out = 1;
if (TIMED_OUT (dev_sleeper[dev], dev_sleep_flag[dev]))
return dev_qlen[dev];
}
RESTORE_INTR (flags);
......@@ -304,7 +302,7 @@ DMAbuf_release (int dev, int mode)
}
#ifdef USE_RUNTIME_DMAMEM
sound_dma_free(dev);
sound_dma_free (dev);
#endif
dsp_devs[dev]->reset (dev);
......@@ -328,14 +326,14 @@ DMAbuf_getrdbuffer (int dev, char **buf, int *len)
{
if (dev_needs_restart[dev])
{
dma_reset(dev);
dma_reset (dev);
dev_needs_restart[dev] = 0;
}
if (dma_mode[dev] == DMODE_OUTPUT) /* Was output -> direction change */
{
dma_sync(dev);
dma_reset(dev);
dma_sync (dev);
dma_reset (dev);
dma_mode[dev] = DMODE_NONE;
}
......@@ -454,25 +452,27 @@ DMAbuf_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
case SNDCTL_DSP_SUBDIVIDE:
{
int fact = IOCTL_IN(arg);
int fact = IOCTL_IN (arg);
if (fact == 0)
{
fact = dev_subdivision[dev];
if (fact == 0) fact = 1;
return IOCTL_OUT(arg, fact);
if (fact == 0)
fact = 1;
return IOCTL_OUT (arg, fact);
}
if (dev_subdivision[dev] != 0) /* Too late to change */
return RET_ERROR(EINVAL);
return RET_ERROR (EINVAL);
if (fact > MAX_REALTIME_FACTOR) return RET_ERROR(EINVAL);
if (fact > MAX_REALTIME_FACTOR)
return RET_ERROR (EINVAL);
if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact !=16)
return RET_ERROR(EINVAL);
if (fact != 1 && fact != 2 && fact != 4 && fact != 8 && fact != 16)
return RET_ERROR (EINVAL);
dev_subdivision[dev] = fact;
return IOCTL_OUT(arg, fact);
return IOCTL_OUT (arg, fact);
}
break;
......@@ -480,6 +480,7 @@ DMAbuf_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
return dsp_devs[dev]->ioctl (dev, cmd, arg, local);
}
/* NOTREACHED */
return RET_ERROR (EIO);
}
......@@ -491,14 +492,13 @@ DMAbuf_getwrbuffer (int dev, char **buf, int *size)
if (dma_mode[dev] == DMODE_INPUT) /* Was input -> Direction change */
{
dma_reset(dev);
dma_reset (dev);
dma_mode[dev] = DMODE_NONE;
}
else
if (dev_needs_restart[dev]) /* Restart buffering */
else if (dev_needs_restart[dev]) /* Restart buffering */
{
dma_sync(dev);
dma_reset(dev);
dma_sync (dev);
dma_reset (dev);
}
dev_needs_restart[dev] = 0;
......@@ -563,7 +563,8 @@ DMAbuf_start_output (int dev, int buff_no, int l)
dev_counts[dev][dev_qtail[dev]] = l;
dev_needs_restart[dev] = (l != dev_buffsize[dev]);
dev_needs_restart[dev] = (l != dev_buffsize[dev]) &&
(sound_dma_automode[dev] || dsp_devs[dev]->flags & NEEDS_RESTART);
dev_qtail[dev] = (dev_qtail[dev] + 1) % dev_nbufs[dev];
......@@ -606,7 +607,7 @@ DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
set_dma_count (chan, sound_buffsizes[dev]);
enable_dma (chan);
RESTORE_INTR (flags);
#else
#else /* linux */
#ifdef __386BSD__
printk ("sound: Invalid DMA mode for device %d\n", dev);
......@@ -615,24 +616,24 @@ DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
snd_raw_buf_phys[dev][0],
sound_buffsizes[dev],
chan);
#else
#if defined(ISC) || defined(SCO)
#else /* __386BSD__ */
#if defined(ISC) || defined(SCO) || defined(SVR42)
#ifndef DMAMODE_AUTO
printk ("sound: Invalid DMA mode for device %d\n", dev);
#endif
#endif /* DMAMODE_AUTO */
dma_param (chan, ((dma_mode == DMA_MODE_READ) ? DMA_Rdmode : DMA_Wrmode)
#ifdef DMAMODE_AUTO
| DMAMODE_AUTO
#endif
#endif /* DMAMODE_AUTO */
,
snd_raw_buf_phys[dev][0], count);
dma_enable (chan);
#else
# error This routine is not valid for this OS.
#endif
#endif
#else /* SYSV */
#error This routine is not valid for this OS.
#endif /* SYSV */
#endif /* __386BSD__ */
#endif
#endif /* linux */
}
else
{
......@@ -645,24 +646,24 @@ DMAbuf_start_dma (int dev, unsigned long physaddr, int count, int dma_mode)
set_dma_count (chan, count);
enable_dma (chan);
RESTORE_INTR (flags);
#else
#else /* linux */
#ifdef __386BSD__
isa_dmastart ((dma_mode == DMA_MODE_READ) ? B_READ : B_WRITE,
physaddr,
count,
chan);
#else
#else /* __386BSD__ */
#if defined(ISC) || defined(SCO)
#if defined(ISC) || defined(SCO) || defined(SVR42)
dma_param (chan, ((dma_mode == DMA_MODE_READ) ? DMA_Rdmode : DMA_Wrmode),
physaddr, count);
dma_enable (chan);
#else
# error This routine is not valid for this OS.
#endif /* !ISC */
#endif
#else /* SYSV */
#error This routine is not valid for this OS.
#endif /* SYSV */
#endif /* __386BSD__ */
#endif
#endif /* linux */
}
return count;
......@@ -707,12 +708,12 @@ DMAbuf_outputintr (int dev, int underrun_flag)
!sound_dma_automode[dev]);
dev_active[dev] = 1;
}
else
if (underrun_flag)
else if (underrun_flag)
{
dev_underrun[dev]++;
dsp_devs[dev]->halt_xfer (dev);
dev_needs_restart[dev] = 1;
dev_needs_restart[dev] = (sound_dma_automode[dev] ||
dsp_devs[dev]->flags & NEEDS_RESTART);
}
DISABLE_INTR (flags);
......@@ -734,11 +735,11 @@ DMAbuf_inputintr (int dev)
}
else if (dev_qlen[dev] == (dev_nbufs[dev] - 1))
{
printk("Sound: Recording overrun\n");
printk ("Sound: Recording overrun\n");
dev_underrun[dev]++;
dsp_devs[dev]->halt_xfer (dev);
dev_active[dev] = 0;
dev_needs_restart[dev] = 1;
dev_needs_restart[dev] = sound_dma_automode[dev];
}
else
{
......
......@@ -106,7 +106,7 @@ gusintr (int unit)
unsigned char src;
#ifdef linux
sti();
sti ();
#endif
while (1)
......
......@@ -24,6 +24,8 @@
#define u_Command (gus_base + 0x103)
#define u_DataLo (gus_base + 0x104)
#define u_DataHi (gus_base + 0x105)
#define u_MixData (gus_base + 0x106) /* Rev. 3.7+ mixing */
#define u_MixSelect (gus_base + 0x506) /* registers. */
#define u_IrqStatus u_Status
# define MIDI_TX_IRQ 0x01 /* pending MIDI xmit IRQ */
# define MIDI_RX_IRQ 0x02 /* pending MIDI recv IRQ */
......@@ -32,4 +34,17 @@
# define WAVETABLE_IRQ 0x20 /* pending wavetable IRQ */
# define ENVELOPE_IRQ 0x40 /* pending volume envelope IRQ */
# define DMA_TC_IRQ 0x80 /* pending dma tc IRQ */
#define ICS2101 1
# define ICS_MIXDEVS 6
# define DEV_MIC 0
# define DEV_LINE 1
# define DEV_CD 2
# define DEV_GF1 3
# define DEV_UNUSED 4
# define DEV_VOL 5
# define CHN_LEFT 0
# define CHN_RIGHT 1
#define CS4231 2
#define u_DRAMIO (gus_base + 0x107)
static unsigned short gus_linearvol[128] = {
0x0000, 0x08ff, 0x09ff, 0x0a80, 0x0aff, 0x0b40, 0x0b80, 0x0bc0,
0x0bff, 0x0c20, 0x0c40, 0x0c60, 0x0c80, 0x0ca0, 0x0cc0, 0x0ce0,
0x0cff, 0x0d10, 0x0d20, 0x0d30, 0x0d40, 0x0d50, 0x0d60, 0x0d70,
0x0d80, 0x0d90, 0x0da0, 0x0db0, 0x0dc0, 0x0dd0, 0x0de0, 0x0df0,
0x0dff, 0x0e08, 0x0e10, 0x0e18, 0x0e20, 0x0e28, 0x0e30, 0x0e38,
0x0e40, 0x0e48, 0x0e50, 0x0e58, 0x0e60, 0x0e68, 0x0e70, 0x0e78,
0x0e80, 0x0e88, 0x0e90, 0x0e98, 0x0ea0, 0x0ea8, 0x0eb0, 0x0eb8,
0x0ec0, 0x0ec8, 0x0ed0, 0x0ed8, 0x0ee0, 0x0ee8, 0x0ef0, 0x0ef8,
0x0eff, 0x0f04, 0x0f08, 0x0f0c, 0x0f10, 0x0f14, 0x0f18, 0x0f1c,
0x0f20, 0x0f24, 0x0f28, 0x0f2c, 0x0f30, 0x0f34, 0x0f38, 0x0f3c,
0x0f40, 0x0f44, 0x0f48, 0x0f4c, 0x0f50, 0x0f54, 0x0f58, 0x0f5c,
0x0f60, 0x0f64, 0x0f68, 0x0f6c, 0x0f70, 0x0f74, 0x0f78, 0x0f7c,
0x0f80, 0x0f84, 0x0f88, 0x0f8c, 0x0f90, 0x0f94, 0x0f98, 0x0f9c,
0x0fa0, 0x0fa4, 0x0fa8, 0x0fac, 0x0fb0, 0x0fb4, 0x0fb8, 0x0fbc,
0x0fc0, 0x0fc4, 0x0fc8, 0x0fcc, 0x0fd0, 0x0fd4, 0x0fd8, 0x0fdc,
0x0fe0, 0x0fe4, 0x0fe8, 0x0fec, 0x0ff0, 0x0ff4, 0x0ff8, 0x0ffc
};
......@@ -5,6 +5,7 @@
*/
#include "sound_config.h"
#ifndef EXCLUDE_GUS
#include "gus_linearvol.h"
#define GUS_VOLUME gus_wave_volume
......@@ -109,4 +110,38 @@ gus_adagio_vol (int vel, int mainv, int xpn, int voicev)
return ((i << 8) + m);
}
/*
* Volume-values are interpreted as linear values. Volume is based on the
* value supplied with SEQ_START_NOTE(), channel main volume (if compiled in)
* and the volume set by the mixer-device (default 60%).
*/
unsigned short
gus_linear_vol (int vol, int mainvol)
{
int mixer_mainvol;
if (vol <= 0)
vol = 0;
else if (vol >= 127)
vol = 127;
#ifdef GUS_VOLUME
mixer_mainvol = GUS_VOLUME;
#else
mixer_mainvol = 100;
#endif
#ifdef GUS_USE_CHN_MAIN_VOLUME
if (mainvol <= 0)
mainvol = 0;
else if (mainvol >= 127)
mainvol = 127;
#else
mainvol = 128;
#endif
return gus_linearvol[(((vol * mainvol) / 128) * mixer_mainvol) / 100];
}
#endif
/*
* sound/gus_wave.c
*
......@@ -88,7 +87,6 @@ static int gus_line_vol = 100, gus_mic_vol = 0;
static int gus_recmask = SOUND_MASK_MIC;
static int recording_active = 0;
#define VOL_METHOD_ADAGIO 1
int gus_wave_volume = 60;
int gus_pcm_volume = 80;
static unsigned char mix_image = 0x00;
......@@ -130,16 +128,16 @@ static int pcm_bsize, /*
*/
pcm_banksize; /*
*
* * * * # bytes allocated for channels */
static int pcm_datasize[MAX_PCM_BUFFERS]; /*
*
* * * * Actual # of bytes
* in blk * */
static volatile int pcm_head, pcm_tail, pcm_qlen; /*
*
* * * * DRAM queue
* */
static volatile int pcm_active;
......@@ -228,9 +226,10 @@ static struct synth_info gus_info =
static void gus_poke (long addr, unsigned char data);
static void compute_and_set_volume (int voice, int volume, int ramp_time);
extern unsigned short gus_adagio_vol (int vel, int mainv, int xpn, int voicev);
extern unsigned short gus_linear_vol (int vol, int mainvol);
static void compute_volume (int voice, int volume);
static void do_volume_irq (int voice);
static void set_input_volumes(void);
static void set_input_volumes (void);
#define INSTANT_RAMP -1 /*
* * * Dont use ramping */
......@@ -398,6 +397,10 @@ gus_write_addr (int reg, unsigned long address, int is16bit)
gus_write16 (reg, (unsigned short) ((address >> 7) & 0xffff));
gus_write16 (reg + 1, (unsigned short) ((address << 9) & 0xffff));
/* Could writing twice fix problems with GUS_VOICE_POS() ? Lets try... */
gus_delay ();
gus_write16 (reg, (unsigned short) ((address >> 7) & 0xffff));
gus_write16 (reg + 1, (unsigned short) ((address << 9) & 0xffff));
}
static void
......@@ -588,10 +591,14 @@ step_envelope (int voice)
{
unsigned vol, prev_vol, phase;
unsigned char rate;
long int flags;
if (voices[voice].mode & WAVE_SUSTAIN_ON && voices[voice].env_phase == 2)
{
DISABLE_INTR (flags);
gus_select_voice (voice);
gus_rampoff ();
RESTORE_INTR (flags);
return; /*
* Sustain
*/
......@@ -608,13 +615,17 @@ step_envelope (int voice)
}
prev_vol = voices[voice].current_volume;
gus_voice_volume (prev_vol);
phase = ++voices[voice].env_phase;
compute_volume (voice, voices[voice].midi_volume);
vol = voices[voice].initial_volume * voices[voice].env_offset[phase] / 255;
rate = voices[voice].env_rate[phase];
DISABLE_INTR (flags);
gus_select_voice (voice);
gus_voice_volume (prev_vol);
gus_write8 (0x06, rate); /*
* Ramping rate
*/
......@@ -625,6 +636,7 @@ step_envelope (int voice)
* No significant volume change
*/
{
RESTORE_INTR (flags);
step_envelope (voice); /*
* Continue with the next phase
*/
......@@ -650,6 +662,7 @@ step_envelope (int voice)
*/
}
voices[voice].current_volume = vol;
RESTORE_INTR (flags);
}
static void
......@@ -662,7 +675,7 @@ init_envelope (int voice)
}
static void
start_release (int voice)
start_release (int voice, long int flags)
{
if (gus_read8 (0x00) & 0x03)
return; /*
......@@ -681,6 +694,7 @@ start_release (int voice)
voices[voice].mode &= ~WAVE_SUSTAIN_ON;
gus_rampoff ();
RESTORE_INTR (flags);
step_envelope (voice);
}
......@@ -688,12 +702,17 @@ static void
gus_voice_fade (int voice)
{
int instr_no = sample_map[voice], is16bits;
long int flags;
DISABLE_INTR (flags);
gus_select_voice (voice);
if (instr_no < 0 || instr_no > MAX_SAMPLE)
{
gus_write8 (0x00, 0x03); /*
* Hard stop
*/
RESTORE_INTR (flags);
return;
}
......@@ -705,7 +724,7 @@ gus_voice_fade (int voice)
if (voices[voice].mode & WAVE_ENVELOPES)
{
start_release (voice);
start_release (voice, flags);
return;
}
......@@ -728,6 +747,7 @@ gus_voice_fade (int voice)
* Down, once, irq
*/
voices[voice].volume_irq_mode = VMODE_HALT;
RESTORE_INTR (flags);
}
static void
......@@ -768,7 +788,7 @@ static void
gus_initialize (void)
{
unsigned long flags;
unsigned char dma_image, irq_image, tmp;
register unsigned char dma_image, irq_image, tmp;
static unsigned char gus_irq_map[16] =
{0, 0, 1, 3, 0, 2, 0, 4, 0, 0, 0, 5, 6, 0, 0, 7};
......@@ -1048,7 +1068,7 @@ guswave_set_instr (int dev, int voice, int instr_no)
if (sample_no < 0)
{
printk ("GUS: Undefined patch %d for voice %d\n", instr_no, voice);
return RET_ERROR (EINVAL); /*
return RET_ERROR (EINVAL);/*
* Patch not defined
*/
}
......@@ -1077,13 +1097,15 @@ guswave_kill_note (int dev, int voice, int velocity)
DISABLE_INTR (flags);
if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
{
voices[voice].kill_pending = 1;
RESTORE_INTR (flags);
}
else
{
gus_select_voice (voice);
RESTORE_INTR (flags);
gus_voice_fade (voice);
}
RESTORE_INTR (flags);
return 0;
}
......@@ -1145,6 +1167,13 @@ guswave_panning (int dev, int voice, int value)
voices[voice].panning = value;
}
static void
guswave_volume_method (int dev, int mode)
{
if (mode == VOL_METHOD_LINEAR || mode == VOL_METHOD_ADAGIO)
volume_method = mode;
}
static void
compute_volume (int voice, int volume)
{
......@@ -1160,6 +1189,11 @@ compute_volume (int voice, int volume)
voices[voice].patch_vol);
break;
case VOL_METHOD_LINEAR: /* Totally ignores patch-volume and expression */
voices[voice].initial_volume =
gus_linear_vol (volume, voices[voice].main_vol);
break;
default:
voices[voice].initial_volume = volume_base +
(voices[voice].midi_volume * volume_scale);
......@@ -1175,16 +1209,16 @@ compute_and_set_volume (int voice, int volume, int ramp_time)
int current, target, rate;
unsigned long flags;
compute_volume (voice, volume);
voices[voice].current_volume = voices[voice].initial_volume;
DISABLE_INTR (flags);
/*
/*
* CAUTION! Interrupts disabled. Enable them before returning
*/
gus_select_voice (voice);
compute_volume (voice, volume);
voices[voice].current_volume = voices[voice].initial_volume;
current = gus_read16 (0x09) >> 4;
target = voices[voice].initial_volume;
......@@ -1328,10 +1362,12 @@ guswave_controller (int dev, int voice, int ctrl_num, int value)
value /= 128;
#endif
case CTRL_EXPRESSION:
volume_method = VOL_METHOD_ADAGIO;
if (volume_method == VOL_METHOD_ADAGIO)
{
voices[voice].expression_vol = value;
if (voices[voice].volume_irq_mode != VMODE_START_NOTE)
dynamic_volume_change (voice);
}
break;
#ifdef FUTURE_VERSION
......@@ -1344,7 +1380,6 @@ guswave_controller (int dev, int voice, int ctrl_num, int value)
#endif
case CTRL_MAIN_VOLUME:
volume_method = VOL_METHOD_ADAGIO;
voices[voice].main_vol = value;
if (voices[voice].volume_irq_mode != VMODE_START_NOTE)
dynamic_volume_change (voice);
......@@ -1497,6 +1532,9 @@ guswave_start_note2 (int dev, int voice, int note_num, int volume)
* It may still be running
*/
gus_rampoff ();
RESTORE_INTR (flags);
if (voices[voice].mode & WAVE_ENVELOPES)
{
compute_volume (voice, volume);
......@@ -1505,6 +1543,9 @@ guswave_start_note2 (int dev, int voice, int note_num, int volume)
else
compute_and_set_volume (voice, volume, 0);
DISABLE_INTR (flags);
gus_select_voice (voice);
if (samples[sample].mode & WAVE_LOOP_BACK)
gus_write_addr (0x0a, sample_ptrs[sample] + samples[sample].len -
voices[voice].offset_pending, is16bits); /* Sample
......@@ -1557,7 +1598,7 @@ guswave_start_note2 (int dev, int voice, int note_num, int volume)
* Loop start
* location
*/
gus_write_addr (0x04, sample_ptrs[sample] + samples[sample].len-1, is16bits); /*
gus_write_addr (0x04, sample_ptrs[sample] + samples[sample].len - 1, is16bits); /*
* Loop
* end
* location
......@@ -1589,8 +1630,11 @@ guswave_start_note (int dev, int voice, int note_num, int volume)
if (voices[voice].volume_irq_mode == VMODE_START_NOTE)
voices[voice].volume_pending = volume;
else
{
RESTORE_INTR (flags);
ret_val = guswave_start_note2 (dev, voice, note_num, volume);
}
}
else
{
gus_select_voice (voice);
......@@ -1605,9 +1649,11 @@ guswave_start_note (int dev, int voice, int note_num, int volume)
if (voices[voice].sample_pending >= 0)
{
RESTORE_INTR (flags);
guswave_set_instr (voices[voice].dev_pending, voice,
voices[voice].sample_pending);
voices[voice].sample_pending = -1;
DISABLE_INTR (flags);
}
if ((mode & 0x01) || ((gus_read16 (0x09) >> 4) < 2065))
......@@ -1623,11 +1669,11 @@ guswave_start_note (int dev, int voice, int note_num, int volume)
gus_rampoff ();
gus_ramp_range (2000, 4065);
gus_ramp_rate (0, 63); /* Fastest possible rate */
gus_ramp_rate (0, 63);/* Fastest possible rate */
gus_rampon (0x20 | 0x40); /* Ramp down, once, irq */
RESTORE_INTR (flags);
}
}
RESTORE_INTR (flags);
return ret_val;
}
......@@ -2006,10 +2052,7 @@ guswave_hw_control (int dev, unsigned char *event)
break;
case _GUS_VOICEFADE:
DISABLE_INTR (flags);
gus_select_voice (voice);
gus_voice_fade (voice);
RESTORE_INTR (flags);
break;
case _GUS_VOICEMODE:
......@@ -2258,7 +2301,7 @@ gus_sampling_open (int dev, int mode)
if (mode & OPEN_READ)
{
recording_active = 1;
set_input_volumes();
set_input_volumes ();
}
return 0;
......@@ -2273,7 +2316,7 @@ gus_sampling_close (int dev)
active_device = 0;
if (recording_active)
set_input_volumes();
set_input_volumes ();
recording_active = 0;
}
......@@ -2345,7 +2388,7 @@ play_next_pcm_block (void)
mode[chn] |= 0x08; /*
* Enable loop
*/
ramp_mode[chn] = 0x03; /*
ramp_mode[chn] = 0x03;/*
* Disable rollover
*/
}
......@@ -2428,7 +2471,7 @@ play_next_pcm_block (void)
mode[chn] &= ~0x08; /*
* Disable loop
*/
mode[chn] |= 0x20; /*
mode[chn] |= 0x20;/*
* Enable loop IRQ
*/
voices[0].loop_irq_mode = LMODE_PCM_STOP;
......@@ -2716,6 +2759,7 @@ gus_copy_from_user (int dev, char *localbuf, int localoffs,
static struct audio_operations gus_sampling_operations =
{
"Gravis UltraSound",
NEEDS_RESTART,
gus_sampling_open,
gus_sampling_close,
gus_sampling_output_block,
......@@ -2745,6 +2789,7 @@ guswave_bender (int dev, int voice, int value)
gus_voice_freq (freq);
RESTORE_INTR (flags);
}
#endif
static int
......@@ -2968,6 +3013,7 @@ static struct synth_operations guswave_operations =
guswave_aftertouch,
guswave_controller,
guswave_panning,
guswave_volume_method,
guswave_patchmgr,
#ifdef FUTURE_VERSION
guswave_bender
......@@ -2975,39 +3021,43 @@ static struct synth_operations guswave_operations =
};
static void
set_input_volumes(void)
set_input_volumes (void)
{
unsigned long flags;
unsigned char mask = 0xff & ~0x06; /* Just line out enabled */
DISABLE_INTR(flags);
DISABLE_INTR (flags);
/*
/*
* Enable channels having vol > 10%
* Note! bit 0x01 means line in DISABLED while 0x04 means
* mic in ENABLED.
*/
if (gus_line_vol > 10) mask &= ~0x01;
if (gus_mic_vol > 10) mask |= 0x04;
if (gus_line_vol > 10)
mask &= ~0x01;
if (gus_mic_vol > 10)
mask |= 0x04;
if (recording_active)
{
/*
/*
* Disable channel, if not selected for recording
*/
if (!(gus_recmask & SOUND_MASK_LINE)) mask |= 0x01;
if (!(gus_recmask & SOUND_MASK_MIC)) mask &= ~0x04;
if (!(gus_recmask & SOUND_MASK_LINE))
mask |= 0x01;
if (!(gus_recmask & SOUND_MASK_MIC))
mask &= ~0x04;
}
mix_image &= ~0x07;
mix_image |= mask & 0x07;
OUTB (mix_image, u_Mixer);
RESTORE_INTR(flags);
RESTORE_INTR (flags);
}
static int
gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
int
gus_default_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
{
#define MIX_DEVS (SOUND_MASK_MIC|SOUND_MASK_LINE| \
SOUND_MASK_SYNTH|SOUND_MASK_PCM)
......@@ -3017,8 +3067,8 @@ gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
switch (cmd & 0xff)
{
case SOUND_MIXER_RECSRC:
gus_recmask = IOCTL_IN(arg) & MIX_DEVS;
if (!(gus_recmask & (SOUND_MASK_MIC|SOUND_MASK_LINE)))
gus_recmask = IOCTL_IN (arg) & MIX_DEVS;
if (!(gus_recmask & (SOUND_MASK_MIC | SOUND_MASK_LINE)))
gus_recmask = SOUND_MASK_MIC;
/* Note! Input volumes are updated during next open for recording */
return IOCTL_OUT (arg, gus_recmask);
......@@ -3027,10 +3077,13 @@ gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
case SOUND_MIXER_MIC:
{
int vol = IOCTL_IN (arg) & 0xff;
if (vol < 0) vol = 0;
if (vol > 100) vol = 100;
if (vol < 0)
vol = 0;
if (vol > 100)
vol = 100;
gus_mic_vol = vol;
set_input_volumes();
set_input_volumes ();
return IOCTL_OUT (arg, vol | (vol << 8));
}
break;
......@@ -3038,10 +3091,13 @@ gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
case SOUND_MIXER_LINE:
{
int vol = IOCTL_IN (arg) & 0xff;
if (vol < 0) vol = 0;
if (vol > 100) vol = 100;
if (vol < 0)
vol = 0;
if (vol > 100)
vol = 100;
gus_line_vol = vol;
set_input_volumes();
set_input_volumes ();
return IOCTL_OUT (arg, vol | (vol << 8));
}
break;
......@@ -3100,7 +3156,7 @@ gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
break;
case SOUND_MIXER_RECMASK:
return IOCTL_OUT (arg, SOUND_MASK_MIC|SOUND_MASK_LINE);
return IOCTL_OUT (arg, SOUND_MASK_MIC | SOUND_MASK_LINE);
break;
case SOUND_MIXER_CAPS:
......@@ -3133,13 +3189,93 @@ gus_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
static struct mixer_operations gus_mixer_operations =
{
gus_mixer_ioctl
gus_default_mixer_ioctl
};
static long
gus_default_mixer_init (long mem_start)
{
if (num_mixers < MAX_MIXER_DEV) /*
* Don't install if there is another
* mixer
*/
mixer_devs[num_mixers++] = &gus_mixer_operations;
return mem_start;
}
long
gus_wave_init (long mem_start, int irq, int dma)
{
printk (" <Gravis UltraSound %dk>", (int) gus_mem_size / 1024);
unsigned long flags;
unsigned char val;
char *model_num = "2.4";
int gus_type = 0x24; /* 2.4 */
int mixer_type = 0;
/*
* Try to identify the GUS model.
*
* Versions < 3.6 don't have the digital ASIC. Try to probe it first.
*/
DISABLE_INTR (flags);
OUTB (0x20, gus_base + 0x0f);
val = INB (gus_base + 0x0f);
RESTORE_INTR (flags);
if (val != 0xff && (val & 0x06)) /* Should be 0x02? */
{
/*
* It has the digital ASIC so the card is at least v3.4.
* Next try to detect the true model.
*/
val = INB (u_MixSelect);
/*
* Value 255 means pre-3.7 which don't have mixer.
* Values 5 thru 9 mean v3.7 which has a ICS2101 mixer.
* 10 and above is GUS MAX which has the CS4231 codec/mixer.
*
* Sorry. No GUS max support yet but it should be available
* soon after the SDK for GUS MAX is available.
*/
if (val == 255 || val < 5)
{
model_num = "3.4";
gus_type = 0x34;
}
else if (val < 10)
{
model_num = "3.7";
gus_type = 0x37;
mixer_type = ICS2101;
}
else
{
model_num = "MAX";
gus_type = 0x40;
mixer_type = CS4231;
}
}
else
{
/*
* ASIC not detected so the card must be 2.2 or 2.4.
* There could still be the 16-bit/mixer daughter card.
* It has the same codec/mixer than MAX.
* At this time there is no support for it but it will appear soon.
*/
}
printk (" <Gravis UltraSound %s (%dk)>", model_num, (int) gus_mem_size / 1024);
#ifndef SCO
sprintf (gus_info.name, "Gravis UltraSound %s (%dk)", model_num, (int) gus_mem_size / 1024);
#endif
if (irq < 0 || irq > 15)
{
......@@ -3179,11 +3315,21 @@ gus_wave_init (long mem_start, int irq, int dma)
else
printk ("GUS: Too many PCM devices available\n");
if (num_mixers < MAX_MIXER_DEV) /*
* Don't install if there is another
* mixer
/*
* Mixer dependent initialization.
*/
mixer_devs[num_mixers++] = &gus_mixer_operations;
switch (mixer_type)
{
case ICS2101:
gus_line_vol=gus_mic_vol=gus_wave_volume = gus_pcm_volume = 100;
return ics2101_mixer_init (mem_start);
case CS4231:
/* Available soon */
default:
return gus_default_mixer_init (mem_start);
}
return mem_start;
}
......@@ -3295,15 +3441,18 @@ do_volume_irq (int voice)
case VMODE_HALT: /*
* Decay phase finished
*/
RESTORE_INTR (flags);
gus_voice_init (voice);
break;
case VMODE_ENVELOPE:
gus_rampoff ();
RESTORE_INTR (flags);
step_envelope (voice);
break;
case VMODE_START_NOTE:
RESTORE_INTR (flags);
guswave_start_note2 (voices[voice].dev_pending, voice,
voices[voice].note_pending, voices[voice].volume_pending);
if (voices[voice].kill_pending)
......@@ -3318,8 +3467,6 @@ do_volume_irq (int voice)
default:;
}
RESTORE_INTR (flags);
}
void
......
/*
* sound/ics2101.c
*
* Driver for the ICS2101 mixer of GUS v3.7.
*
* Copyright by Hannu Savolainen 1994
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met: 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer. 2.
* Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND ANY
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
*/
#include "sound_config.h"
#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_GUS)
#include <linux/ultrasound.h>
#include "gus_hw.h"
#define MIX_DEVS (SOUND_MASK_MIC|SOUND_MASK_LINE| \
SOUND_MASK_SYNTH| \
SOUND_MASK_CD | SOUND_MASK_VOLUME)
extern int gus_base;
static int volumes[ICS_MIXDEVS];
static int left_fix[ICS_MIXDEVS] =
{1, 1, 1, 2, 1, 2};
static int right_fix[ICS_MIXDEVS] =
{2, 2, 2, 1, 2, 1};
static int
scale_vol(int vol)
{
#if 1
/*
* Experimental volume scaling by Risto Kankkunen.
* This should give smoother volume response than just
* a plain multiplication.
*/
int e;
if (vol < 0)
vol = 0;
if (vol > 100)
vol = 100;
vol = (31 * vol + 50) / 100;
e = 0;
if (vol) {
while (vol < 16) {
vol <<= 1;
e--;
}
vol -= 16;
e += 7;
}
return ((e << 4) + vol);
#else
return ((vol*127)+50)/100;
#endif
}
static void
write_mix (int dev, int chn, int vol)
{
int *selector;
unsigned long flags;
int ctrl_addr = dev << 3;
int attn_addr = dev << 3;
vol=scale_vol(vol);
if (chn == CHN_LEFT)
{
selector = left_fix;
ctrl_addr |= 0x00;
attn_addr |= 0x02;
}
else
{
selector = right_fix;
ctrl_addr |= 0x01;
attn_addr |= 0x03;
}
DISABLE_INTR (flags);
OUTB (ctrl_addr, u_MixSelect);
OUTB (selector[dev], u_MixData);
OUTB (attn_addr, u_MixSelect);
OUTB ((unsigned char) vol, u_MixData);
RESTORE_INTR (flags);
}
static int
set_volumes (int dev, int vol)
{
int left = vol & 0x00ff;
int right = (vol >> 8) & 0x00ff;
if (left < 0)
left = 0;
if (left > 100)
left = 100;
if (right < 0)
right = 0;
if (right > 100)
right = 100;
write_mix (dev, CHN_LEFT, left);
write_mix (dev, CHN_RIGHT, right);
vol = left + (right << 8);
volumes[dev] = vol;
return vol;
}
static int
ics2101_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
{
if (((cmd >> 8) & 0xff) == 'M')
{
if (cmd & IOC_IN)
switch (cmd & 0xff)
{
case SOUND_MIXER_RECSRC:
return gus_default_mixer_ioctl (dev, cmd, arg);
break;
case SOUND_MIXER_MIC:
return IOCTL_OUT (arg, set_volumes (DEV_MIC, IOCTL_IN (arg)));
break;
case SOUND_MIXER_CD:
return IOCTL_OUT (arg, set_volumes (DEV_CD, IOCTL_IN (arg)));
break;
case SOUND_MIXER_LINE:
return IOCTL_OUT (arg, set_volumes (DEV_LINE, IOCTL_IN (arg)));
break;
case SOUND_MIXER_SYNTH:
return IOCTL_OUT (arg, set_volumes (DEV_GF1, IOCTL_IN (arg)));
break;
case SOUND_MIXER_VOLUME:
return IOCTL_OUT (arg, set_volumes (DEV_VOL, IOCTL_IN (arg)));
break;
default:
return RET_ERROR (EINVAL);
}
else
switch (cmd & 0xff) /*
* Return parameters
*/
{
case SOUND_MIXER_RECSRC:
return gus_default_mixer_ioctl (dev, cmd, arg);
break;
case SOUND_MIXER_DEVMASK:
return IOCTL_OUT (arg, MIX_DEVS);
break;
case SOUND_MIXER_STEREODEVS:
return IOCTL_OUT (arg, SOUND_MASK_LINE | SOUND_MASK_CD |
SOUND_MASK_SYNTH | SOUND_MASK_VOLUME|
SOUND_MASK_MIC);
break;
case SOUND_MIXER_RECMASK:
return IOCTL_OUT (arg, SOUND_MASK_MIC | SOUND_MASK_LINE);
break;
case SOUND_MIXER_CAPS:
return IOCTL_OUT (arg, 0);
break;
case SOUND_MIXER_MIC:
return IOCTL_OUT (arg, volumes[DEV_MIC]);
break;
case SOUND_MIXER_LINE:
return IOCTL_OUT (arg, volumes[DEV_LINE]);
break;
case SOUND_MIXER_CD:
return IOCTL_OUT (arg, volumes[DEV_CD]);
break;
case SOUND_MIXER_VOLUME:
return IOCTL_OUT (arg, volumes[DEV_VOL]);
break;
case SOUND_MIXER_SYNTH:
return IOCTL_OUT (arg, volumes[DEV_GF1]);
break;
default:
return RET_ERROR (EINVAL);
}
}
return RET_ERROR (EINVAL);
}
static struct mixer_operations ics2101_mixer_operations =
{
ics2101_mixer_ioctl
};
long
ics2101_mixer_init (long mem_start)
{
int i;
if (num_mixers < MAX_MIXER_DEV)
{
mixer_devs[num_mixers++] = &ics2101_mixer_operations;
/*
* Some GUS v3.7 cards had some channels flipped. Disable
* the flipping feature if the model id is other than 5.
*/
if (INB (u_MixSelect) != 5)
{
for (i = 0; i < ICS_MIXDEVS; i++)
left_fix[i] = 1;
for (i = 0; i < ICS_MIXDEVS; i++)
right_fix[i] = 2;
}
set_volumes (DEV_GF1, 0x5a5a);
set_volumes (DEV_CD, 0x5a5a);
set_volumes (DEV_MIC, 0x0000);
set_volumes (DEV_LINE, 0x5a5a);
set_volumes (DEV_VOL, 0x5a5a);
set_volumes (DEV_UNUSED, 0x0000);
}
return mem_start;
}
#endif
......@@ -35,7 +35,7 @@
#if !defined(EXCLUDE_MPU401) && !defined(EXCLUDE_MIDI)
#define DATAPORT (mpu401_base) /* MPU-401 Data I/O Port on IBM */
#define DATAPORT (mpu401_base)/* MPU-401 Data I/O Port on IBM */
#define COMDPORT (mpu401_base+1) /* MPU-401 Command Port on IBM */
#define STATPORT (mpu401_base+1) /* MPU-401 Status Port on IBM */
......@@ -61,58 +61,16 @@ static int my_dev;
static int reset_mpu401 (void);
static void (*midi_input_intr) (int dev, unsigned char data);
static void
mpu401_input_loop (void)
void
mpuintr (int unit)
{
int count;
count = 10;
while (count) /* Not timed out */
if (input_avail ())
while (input_avail ())
{
unsigned char c = mpu401_read ();
count = 100;
if (mpu401_opened & OPEN_READ)
midi_input_intr (my_dev, c);
}
else
while (!input_avail () && count)
count--;
}
void
mpuintr (int unit)
{
if (input_avail ())
mpu401_input_loop ();
}
/*
* It looks like there is no input interrupts in the UART mode. Let's try
* polling.
*/
static void
poll_mpu401 (unsigned long dummy)
{
unsigned long flags;
DEFINE_TIMER(mpu401_timer, poll_mpu401);
if (!(mpu401_opened & OPEN_READ))
return; /* No longer required */
DISABLE_INTR (flags);
if (input_avail ())
mpu401_input_loop ();
ACTIVATE_TIMER(mpu401_timer, poll_mpu401, 1); /* Come back later */
RESTORE_INTR (flags);
}
static int
......@@ -127,11 +85,10 @@ mpu401_open (int dev, int mode,
return RET_ERROR (EBUSY);
}
mpu401_input_loop ();
mpuintr (0);
midi_input_intr = input;
mpu401_opened = mode;
poll_mpu401 (0); /* Enable input polling */
return 0;
}
......@@ -155,7 +112,7 @@ mpu401_out (int dev, unsigned char midi_byte)
DISABLE_INTR (flags);
if (input_avail ())
mpu401_input_loop ();
mpuintr (0);
RESTORE_INTR (flags);
......@@ -291,7 +248,7 @@ reset_mpu401 (void)
mpu401_opened = 0;
if (ok)
mpu401_input_loop (); /* Flush input before enabling interrupts */
mpuintr (0); /* Flush input before enabling interrupts */
RESTORE_INTR (flags);
......
......@@ -81,6 +81,9 @@ static unsigned char connection_mask = 0x00;
void
enable_opl3_mode (int left, int right, int both)
{
if (opl3_enabled)
return;
opl3_enabled = 1;
left_address = left;
right_address = right;
......@@ -627,7 +630,7 @@ opl3_command (int io_addr, unsigned int addr, unsigned int val)
* register. The OPL-3 survives with just two INBs
*/
OUTB ((unsigned char)(addr & 0xff), io_addr); /* Select register */
OUTB ((unsigned char) (addr & 0xff), io_addr); /* Select register */
if (!opl3_enabled)
tenmicrosec ();
......@@ -635,7 +638,7 @@ opl3_command (int io_addr, unsigned int addr, unsigned int val)
for (i = 0; i < 2; i++)
INB (io_addr);
OUTB ((unsigned char)(val & 0xff), io_addr + 1); /* Write to register */
OUTB ((unsigned char) (val & 0xff), io_addr + 1); /* Write to register */
if (!opl3_enabled)
{
......@@ -747,6 +750,11 @@ opl3_panning (int dev, int voice, int pressure)
{
}
static void
opl3_volume_method (int dev, int mode)
{
}
#define SET_VIBRATO(cell) { \
tmp = instr->operators[(cell-1)+(((cell-1)/2)*OFFS_4OP)]; \
if (pressure > 110) \
......@@ -886,6 +894,7 @@ static struct synth_operations opl3_operations =
opl3_aftertouch,
opl3_controller,
opl3_panning,
opl3_volume_method,
opl3_patchmgr
};
......@@ -894,8 +903,8 @@ opl3_init (long mem_start)
{
int i;
PERMANENT_MALLOC(struct sbi_instrument*, instrmap,
SBFM_MAXINSTR*sizeof(*instrmap), mem_start);
PERMANENT_MALLOC (struct sbi_instrument *, instrmap,
SBFM_MAXINSTR * sizeof (*instrmap), mem_start);
synth_devs[num_synths++] = &opl3_operations;
fm_model = 0;
......
......@@ -37,7 +37,6 @@
#include <linux/timer.h>
#include <linux/tty.h>
#include <linux/ctype.h>
#include <linux/string.h>
#include <asm/io.h>
#include <asm/segment.h>
#include <asm/system.h>
......@@ -46,6 +45,7 @@
#include <linux/wait.h>
#include <linux/malloc.h>
#include <linux/soundcard.h>
#include <linux/string.h>
typedef char snd_rw_buf;
......@@ -141,7 +141,7 @@ struct snd_wait {
#define DEFINE_TIMER(name, proc) \
static struct timer_list name = \
{NULL, NULL, 0, 0, proc}
{NULL, 0, 0, 0, proc}
/*
* The ACTIVATE_TIMER requests system to call 'proc' after 'time' ticks.
......
......@@ -138,11 +138,11 @@
char I_C_2_PCM_DMA_translate[] = /* R W PCM PCM DMA channel value translations */
{ 4, 1, 2, 3, 0, 5, 6, 7 };
char I_C_3_PCM_IRQ_translate[] = /* R W PCM PCM IRQ level value translation */
{ 0, 0, 1, 2, 3, 4, 5, 6, 0, 0, 7, 8, 9, 0, 10, 11 };
{ 0, 0, 1, 2, 3, 4, 5, 6, 0, 1, 7, 8, 9, 0, 10, 11 };
char E_C_MPU401_IRQ_translate[] = /* R W MIDI MPU401 emulation IRQ value translation */
{ 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x00, 0x05, 0x06, 0x07 };
{ 0x00, 0x00, 0x01, 0x02, 0x00, 0x03, 0x00, 0x04, 0x00, 0x01, 0x05, 0x06, 0x07 };
char E_C_SB_IRQ_translate[] = /* R W PCM SB emulation IRQ translate */
{ 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20, 0x00, 0x00, 0x28, 0x30, 0x38, 0, 0 };
{ 0x00, 0x00, 0x08, 0x10, 0x00, 0x18, 0x00, 0x20, 0x00, 0x08, 0x28, 0x30, 0x38, 0, 0 };
char E_C_SB_DMA_translate[] = /* R W PCM SB emulation DMA translate */
{ 0x00, 0x40, 0x80, 0xC0, 0, 0, 0, 0 };
char O_M_1_to_card[] = /* R W Control Translate (OM1 & 0x0f) to card type */
......
......@@ -197,13 +197,13 @@ config_pas_hw (struct address_info *hw_config)
}
}
/*
/*
* This fixes the timing problems of the PAS due to the Symphony chipset
* as per Media Vision. Only define this if your PAS doesn't work correctly.
*/
#ifdef SYMPHONY_PAS
OUTB(0x05,0xa8);
OUTB(0x60,0xa9);
OUTB (0x05, 0xa8);
OUTB (0x60, 0xa9);
#endif
#ifdef BROKEN_BUS_CLOCK
......@@ -231,7 +231,7 @@ config_pas_hw (struct address_info *hw_config)
{
struct address_info *sb_config;
if ((sb_config=sound_getconf(SNDCARD_SB)))
if ((sb_config = sound_getconf (SNDCARD_SB)))
{
unsigned char irq_dma;
......@@ -244,17 +244,17 @@ config_pas_hw (struct address_info *hw_config)
pas_write ((sb_config->io_base >> 4) & 0x0f, EMULATION_ADDRESS);
if (!E_C_SB_DMA_translate[sb_config->dma])
printk("\n\nPAS16 Warning: Invalid SB DMA %d\n\n",
printk ("\n\nPAS16 Warning: Invalid SB DMA %d\n\n",
sb_config->dma);
if (!E_C_SB_IRQ_translate[sb_config->irq])
printk("\n\nPAS16 Warning: Invalid SB IRQ %d\n\n",
printk ("\n\nPAS16 Warning: Invalid SB IRQ %d\n\n",
sb_config->irq);
irq_dma = E_C_SB_DMA_translate[sb_config->dma] |
E_C_SB_IRQ_translate[sb_config->irq];
pas_write(irq_dma, EMULATION_CONFIGURATION);
pas_write (irq_dma, EMULATION_CONFIGURATION);
}
}
#endif
......@@ -327,11 +327,11 @@ attach_pas_card (long mem_start, struct address_info *hw_config)
mem_start = pas_pcm_init (mem_start, hw_config);
#endif
# if !defined(EXCLUDE_SB_EMULATION) && !defined(EXCLUDE_SB)
#if !defined(EXCLUDE_SB_EMULATION) && !defined(EXCLUDE_SB)
sb_dsp_disable_midi (); /* The SB emulation don't support
* midi */
# endif
#endif
#ifndef EXCLUDE_YM3812
enable_opl3_mode (0x388, 0x38a, 0);
......
......@@ -337,14 +337,15 @@ pas_pcm_prepare_for_output (int dev, int bsize, int bcount)
static struct audio_operations pas_pcm_operations =
{
"Pro Audio Spectrum",
pas_pcm_open, /* */
pas_pcm_close, /* */
pas_pcm_output_block, /* */
pas_pcm_start_input, /* */
pas_pcm_ioctl, /* */
pas_pcm_prepare_for_input, /* */
pas_pcm_prepare_for_output, /* */
pas_pcm_reset, /* */
NOTHING_SPECIAL,
pas_pcm_open,
pas_pcm_close,
pas_pcm_output_block,
pas_pcm_start_input,
pas_pcm_ioctl,
pas_pcm_prepare_for_input,
pas_pcm_prepare_for_output,
pas_pcm_reset,
pas_pcm_reset, /* halt_xfer */
NULL, /* has_output_drained */
NULL /* copy_from_user */
......
......@@ -32,25 +32,26 @@
#define DEB(x)
#define DEB1(x)
/*
#define DEB_DMARES
*/
#define DEB_DMARES
*/
#include "sound_config.h"
#include "sb.h"
#include "sb_mixer.h"
#if defined(CONFIGURE_SOUNDCARD) && !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SB) && !defined(EXCLUDE_AUDIO) && !defined(EXCLUDE_SBPRO)
extern int sbc_base;
extern int sbc_base, sbc_minor, sbc_major;
static int sb16_dsp_ok = 0; /* Set to 1 after successful initialization */
static int sb16_dsp_ok = 0;/* Set to 1 after successful initialization */
static int dsp_16bit = 0;
static int dsp_stereo = 0;
static int dsp_current_speed = 8000;/*DSP_DEFAULT_SPEED;*/
static int dsp_current_speed = 8000; /*DSP_DEFAULT_SPEED; */
static int dsp_busy = 0;
static int dma16, dma8;
static unsigned long dsp_count = 0;
static int irq_mode = IMODE_NONE; /* IMODE_INPUT, IMODE_OUTPUT or
IMODE_NONE */
static int my_dev = 0;
......@@ -58,9 +59,9 @@ static volatile int intr_active = 0;
static int sb16_dsp_open (int dev, int mode);
static void sb16_dsp_close (int dev);
static void sb16_dsp_output_block (int dev, unsigned long buf, int count,int intrflag, int dma_restart);
static void sb16_dsp_start_input (int dev, unsigned long buf, int count,int intrflag, int dma_restart);
static int sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg,int local);
static void sb16_dsp_output_block (int dev, unsigned long buf, int count, int intrflag, int dma_restart);
static void sb16_dsp_start_input (int dev, unsigned long buf, int count, int intrflag, int dma_restart);
static int sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg, int local);
static int sb16_dsp_prepare_for_input (int dev, int bsize, int bcount);
static int sb16_dsp_prepare_for_output (int dev, int bsize, int bcount);
static void sb16_dsp_reset (int dev);
......@@ -73,6 +74,7 @@ int sb_reset_dsp (void);
static struct audio_operations sb16_dsp_operations =
{
"SoundBlaster 16",
NOTHING_SPECIAL,
sb16_dsp_open,
sb16_dsp_close,
sb16_dsp_output_block,
......@@ -86,70 +88,78 @@ static struct audio_operations sb16_dsp_operations =
NULL
};
static int sb_dsp_command01 (unsigned char val)
static int
sb_dsp_command01 (unsigned char val)
{
int i=1<<16;
int i = 1 << 16;
while(--i & (!INB (DSP_STATUS) & 0x80));
if(!i)
printk("SB16 sb_dsp_command01 Timeout\n");
return sb_dsp_command(val);
while (--i & (!INB (DSP_STATUS) & 0x80));
if (!i)
printk ("SB16 sb_dsp_command01 Timeout\n");
return sb_dsp_command (val);
}
static int wait_data_avail(int t)
static int
wait_data_avail (unsigned long t)
{
int loopc=5000000;
t+=GET_TIME();
do {
if(INB(DSP_DATA_AVAIL) & 0x80)
int loopc = 5000000;
t += GET_TIME ();
do
{
if (INB (DSP_DATA_AVAIL) & 0x80)
return 1;
} while(--loopc && GET_TIME()<t);
printk("!data_avail l=%d\n",loopc);
}
while (--loopc && GET_TIME () < t);
printk ("!data_avail l=%d\n", loopc);
return 0;
}
static int read_dsp(int t)
static int
read_dsp (int t)
{
if(!wait_data_avail(t))
if (!wait_data_avail ((unsigned long) t))
return -1;
else
return INB(DSP_READ);
return INB (DSP_READ);
}
static int dsp_ini2(void)
static int
dsp_ini2 (void)
{
#if 0
/* sb_setmixer(0x83, sb_getmixer(0x83) | 0x03); */
sb_dsp_command(0xe2);
sb_dsp_command(0x76); /* E0 ??? */
sb_dsp_command(0xe2);
sb_dsp_command(0x30); /* A0 ??? */
sb_dsp_command(0xe4);
sb_dsp_command(0xaa);
sb_dsp_command(0xe8);
if(read_dsp(100)!=0xaa)
printk("Error dsp_ini2\n");
sb_dsp_command (0xe2);
sb_dsp_command (0x76); /* E0 ??? */
sb_dsp_command (0xe2);
sb_dsp_command (0x30); /* A0 ??? */
sb_dsp_command (0xe4);
sb_dsp_command (0xaa);
sb_dsp_command (0xe8);
if (read_dsp (100) != 0xaa)
printk ("Error dsp_ini2\n");
#endif
return 0;
}
/*
static char *dsp_getmessage(unsigned char command,int maxn)
{
static char *dsp_getmessage(unsigned char command,int maxn)
{
static char buff[100];
int n=0;
sb_dsp_command(command);
while(n<maxn && wait_data_avail(2)) {
while(n<maxn && wait_data_avail(2L)) {
buff[++n]=INB(DSP_READ);
if(!buff[n])
break;
}
buff[0]=n;
return buff;
}
}
static void dsp_showmessage(unsigned char command,int len)
{
static void dsp_showmessage(unsigned char command,int len)
{
int n;
unsigned char *c;
c=dsp_getmessage(command,len);
......@@ -160,72 +170,82 @@ static void dsp_showmessage(unsigned char command,int len)
else
printk("|%x|",c[n]);
printk("\n");
}
*/
static int dsp_set_speed(int mode)
}
*/
static int
dsp_set_speed (int mode)
{
DEB(printk("dsp_set_speed(%d)\n",mode));
DEB (printk ("dsp_set_speed(%d)\n", mode));
if (mode)
{
if (mode < 5000) mode = 5000;
if (mode > 44100) mode = 44100;
dsp_current_speed=mode;
if (mode < 5000)
mode = 5000;
if (mode > 44100)
mode = 44100;
dsp_current_speed = mode;
}
return mode;
}
static int dsp_set_stereo(int mode)
static int
dsp_set_stereo (int mode)
{
DEB(printk("dsp_set_stereo(%d)\n",mode));
DEB (printk ("dsp_set_stereo(%d)\n", mode));
dsp_stereo=mode;
dsp_stereo = mode;
return mode;
}
static int dsp_set_bits(int arg) {
DEB(printk("dsp_set_bits(%d)\n",arg));
static int
dsp_set_bits (int arg)
{
DEB (printk ("dsp_set_bits(%d)\n", arg));
if (arg)
switch(arg) {
switch (arg)
{
case 8:
dsp_16bit=0; break;
dsp_16bit = 0;
break;
case 16:
dsp_16bit=1; break;
dsp_16bit = 1;
break;
default:
return RET_ERROR(EINVAL);
return RET_ERROR (EINVAL);
}
return dsp_16bit? 16:8;
return dsp_16bit ? 16 : 8;
}
static int
sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg,int local)
sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg, int local)
{
switch (cmd) {
switch (cmd)
{
case SOUND_PCM_WRITE_RATE:
if(local)
return dsp_set_speed(arg);
if (local)
return dsp_set_speed (arg);
return IOCTL_OUT (arg, dsp_set_speed (IOCTL_IN (arg)));
case SOUND_PCM_READ_RATE:
if(local)
if (local)
return dsp_current_speed;
return IOCTL_OUT (arg, dsp_current_speed);
case SNDCTL_DSP_STEREO:
if (local)
return dsp_set_stereo(arg);
return IOCTL_OUT (arg, dsp_set_stereo(IOCTL_IN(arg)));
return dsp_set_stereo (arg);
return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg)));
case SOUND_PCM_WRITE_CHANNELS:
if (local)
return dsp_set_stereo(arg-1)+1;
return dsp_set_stereo (arg - 1) + 1;
return IOCTL_OUT (arg, dsp_set_stereo (IOCTL_IN (arg) - 1) + 1);
case SOUND_PCM_READ_CHANNELS:
if (local)
return dsp_stereo+1;
return IOCTL_OUT (arg, dsp_stereo+1);
return dsp_stereo + 1;
return IOCTL_OUT (arg, dsp_stereo + 1);
case SNDCTL_DSP_SAMPLESIZE:
if (local)
......@@ -234,8 +254,8 @@ sb16_dsp_ioctl (int dev, unsigned int cmd, unsigned int arg,int local)
case SOUND_PCM_READ_BITS:
if (local)
return dsp_16bit?16:8;
return IOCTL_OUT (arg, dsp_16bit?16:8);
return dsp_16bit ? 16 : 8;
return IOCTL_OUT (arg, dsp_16bit ? 16 : 8);
case SOUND_PCM_WRITE_FILTER: /* NOT YET IMPLEMENTED */
if (IOCTL_IN (arg) > 1)
......@@ -252,37 +272,37 @@ sb16_dsp_open (int dev, int mode)
{
int retval;
DEB(printk("sb16_dsp_open()\n"));
DEB (printk ("sb16_dsp_open()\n"));
if (!sb16_dsp_ok)
{
printk ("SB16 Error: SoundBlaster board not installed\n");
return RET_ERROR(ENXIO);
return RET_ERROR (ENXIO);
}
if (intr_active)
return RET_ERROR(EBUSY);
return RET_ERROR (EBUSY);
retval = sb_get_irq ();
if (retval<0)
if (retval < 0)
return retval;
if (ALLOC_DMA_CHN (dma8))
{
printk ("SB16: Unable to grab DMA%d\n", dma8);
sb_free_irq();
return RET_ERROR(EBUSY);
sb_free_irq ();
return RET_ERROR (EBUSY);
}
if (dma16 != dma8)
if (ALLOC_DMA_CHN (dma16))
{
printk ("SB16: Unable to grab DMA%d\n", dma16);
sb_free_irq();
sb_free_irq ();
RELEASE_DMA_CHN (dma8);
return RET_ERROR(EBUSY);
return RET_ERROR (EBUSY);
}
dsp_ini2();
dsp_ini2 ();
irq_mode = IMODE_NONE;
dsp_busy = 1;
......@@ -294,9 +314,10 @@ static void
sb16_dsp_close (int dev)
{
unsigned long flags;
DEB(printk("sb16_dsp_close()\n"));
sb_dsp_command01(0xd9);
sb_dsp_command01(0xd5);
DEB (printk ("sb16_dsp_close()\n"));
sb_dsp_command01 (0xd9);
sb_dsp_command01 (0xd5);
DISABLE_INTR (flags);
RELEASE_DMA_CHN (dma8);
......@@ -310,7 +331,7 @@ DEB(printk("sb16_dsp_close()\n"));
}
static void
sb16_dsp_output_block (int dev, unsigned long buf, int count,int intrflag, int dma_restart)
sb16_dsp_output_block (int dev, unsigned long buf, int count, int intrflag, int dma_restart)
{
unsigned long flags, cnt;
......@@ -320,21 +341,24 @@ sb16_dsp_output_block (int dev, unsigned long buf, int count,int intrflag, int d
cnt--;
#ifdef DEB_DMARES
printk("output_block: %x %d %d\n",buf,count,intrflag);
if(intrflag) {
int pos,chan=sound_dsp_dmachan[dev];
printk ("output_block: %x %d %d\n", buf, count, intrflag);
if (intrflag)
{
int pos, chan = sound_dsp_dmachan[dev];
DISABLE_INTR (flags);
clear_dma_ff(chan);
disable_dma(chan);
pos=get_dma_residue(chan);
enable_dma(chan);
clear_dma_ff (chan);
disable_dma (chan);
pos = get_dma_residue (chan);
enable_dma (chan);
RESTORE_INTR (flags);
printk("dmapos=%d %x\n",pos,pos);
printk ("dmapos=%d %x\n", pos, pos);
}
#endif
if (sound_dma_automode[dev] &&
intrflag &&
cnt == dsp_count) {
cnt == dsp_count)
{
irq_mode = IMODE_OUTPUT;
intr_active = 1;
return; /* Auto mode on. No need to react */
......@@ -343,28 +367,28 @@ sb16_dsp_output_block (int dev, unsigned long buf, int count,int intrflag, int d
if (dma_restart)
{
sb16_dsp_halt(dev);
sb16_dsp_halt (dev);
DMAbuf_start_dma (dev, buf, count, DMA_MODE_WRITE);
}
sb_dsp_command (0x41);
sb_dsp_command ((unsigned char)((dsp_current_speed >> 8) & 0xff));
sb_dsp_command ((unsigned char)(dsp_current_speed & 0xff));
sb_dsp_command ((unsigned char)(dsp_16bit ? 0xb6 : 0xc6));
sb_dsp_command ((unsigned char)((dsp_stereo ? 0x20 : 0) +
(dsp_16bit ? 0x10:0)));
sb_dsp_command01 ((unsigned char)(cnt&0xff));
sb_dsp_command ((unsigned char)(cnt>>8));
sb_dsp_command ((unsigned char) ((dsp_current_speed >> 8) & 0xff));
sb_dsp_command ((unsigned char) (dsp_current_speed & 0xff));
sb_dsp_command ((unsigned char) (dsp_16bit ? 0xb6 : 0xc6));
sb_dsp_command ((unsigned char) ((dsp_stereo ? 0x20 : 0) +
(dsp_16bit ? 0x10 : 0)));
sb_dsp_command01 ((unsigned char) (cnt & 0xff));
sb_dsp_command ((unsigned char) (cnt >> 8));
/* sb_dsp_command (0);
sb_dsp_command (0); */
RESTORE_INTR (flags);
dsp_count=cnt;
dsp_count = cnt;
irq_mode = IMODE_OUTPUT;
intr_active = 1;
}
static void
sb16_dsp_start_input (int dev, unsigned long buf, int count,int intrflag, int dma_restart)
sb16_dsp_start_input (int dev, unsigned long buf, int count, int intrflag, int dma_restart)
{
unsigned long flags, cnt;
......@@ -374,21 +398,24 @@ sb16_dsp_start_input (int dev, unsigned long buf, int count,int intrflag, int dm
cnt--;
#ifdef DEB_DMARES
printk("start_input: %x %d %d\n",buf,count,intrflag);
if(intrflag) {
int pos,chan=sound_dsp_dmachan[dev];
printk ("start_input: %x %d %d\n", buf, count, intrflag);
if (intrflag)
{
int pos, chan = sound_dsp_dmachan[dev];
DISABLE_INTR (flags);
clear_dma_ff(chan);
disable_dma(chan);
pos=get_dma_residue(chan);
enable_dma(chan);
clear_dma_ff (chan);
disable_dma (chan);
pos = get_dma_residue (chan);
enable_dma (chan);
RESTORE_INTR (flags);
printk("dmapos=%d %x\n",pos,pos);
printk ("dmapos=%d %x\n", pos, pos);
}
#endif
if (sound_dma_automode[dev] &&
intrflag &&
cnt == dsp_count) {
cnt == dsp_count)
{
irq_mode = IMODE_INPUT;
intr_active = 1;
return; /* Auto mode on. No need to react */
......@@ -397,23 +424,23 @@ printk("start_input: %x %d %d\n",buf,count,intrflag);
if (dma_restart)
{
sb16_dsp_halt(dev);
sb16_dsp_halt (dev);
DMAbuf_start_dma (dev, buf, count, DMA_MODE_READ);
}
sb_dsp_command (0x42);
sb_dsp_command ((unsigned char)((dsp_current_speed >> 8) & 0xff));
sb_dsp_command ((unsigned char)(dsp_current_speed & 0xff));
sb_dsp_command ((unsigned char)(dsp_16bit ? 0xbe : 0xce));
sb_dsp_command ((unsigned char)((dsp_stereo ? 0x20 : 0) +
(dsp_16bit ? 0x10:0)));
sb_dsp_command01 ((unsigned char)(cnt&0xff));
sb_dsp_command ((unsigned char)(cnt>>8));
sb_dsp_command ((unsigned char) ((dsp_current_speed >> 8) & 0xff));
sb_dsp_command ((unsigned char) (dsp_current_speed & 0xff));
sb_dsp_command ((unsigned char) (dsp_16bit ? 0xbe : 0xce));
sb_dsp_command ((unsigned char) ((dsp_stereo ? 0x20 : 0) +
(dsp_16bit ? 0x10 : 0)));
sb_dsp_command01 ((unsigned char) (cnt & 0xff));
sb_dsp_command ((unsigned char) (cnt >> 8));
/* sb_dsp_command (0);
sb_dsp_command (0); */
RESTORE_INTR (flags);
dsp_count=cnt;
dsp_count = cnt;
irq_mode = IMODE_INPUT;
intr_active = 1;
}
......@@ -421,7 +448,7 @@ printk("start_input: %x %d %d\n",buf,count,intrflag);
static int
sb16_dsp_prepare_for_input (int dev, int bsize, int bcount)
{
sound_dsp_dmachan[my_dev] = dsp_16bit? dma16:dma8;
sound_dsp_dmachan[my_dev] = dsp_16bit ? dma16 : dma8;
dsp_count = 0;
dsp_cleanup ();
return 0;
......@@ -430,7 +457,7 @@ sb16_dsp_prepare_for_input (int dev, int bsize, int bcount)
static int
sb16_dsp_prepare_for_output (int dev, int bsize, int bcount)
{
sound_dsp_dmachan[my_dev] = dsp_16bit? dma16:dma8;
sound_dsp_dmachan[my_dev] = dsp_16bit ? dma16 : dma8;
dsp_count = 0;
dsp_cleanup ();
return 0;
......@@ -461,56 +488,47 @@ sb16_dsp_halt (int dev)
{
if (dsp_16bit)
{
sb_dsp_command01(0xd9);
sb_dsp_command01(0xd5);
sb_dsp_command01 (0xd9);
sb_dsp_command01 (0xd5);
}
else
{
sb_dsp_command01(0xda);
sb_dsp_command01(0xd0);
sb_dsp_command01 (0xda);
sb_dsp_command01 (0xd0);
}
}
static void
set_irq_hw(int level) {
set_irq_hw (int level)
{
int ival;
switch(level) {
switch (level)
{
case 5:
ival=2; break;
ival = 2;
break;
case 7:
ival=4; break;
ival = 4;
break;
case 10:
ival=8; break;
ival = 8;
break;
default:
printk("SB16_IRQ_LEVEL %d does not exist\n",level);
printk ("SB16_IRQ_LEVEL %d does not exist\n", level);
return;
}
sb_setmixer(IRQ_NR,ival);
sb_setmixer (IRQ_NR, ival);
}
long
sb16_dsp_init (long mem_start, struct address_info *hw_config)
{
int i, major, minor;
major = minor = 0;
sb_dsp_command (0xe1); /* Get version */
for (i = 1000; i; i--) {
if (INB (DSP_DATA_AVAIL) & 0x80)
{ /* wait for Data Ready */
if (major == 0)
major = INB (DSP_READ);
else
{
minor = INB (DSP_READ);
break;
}
}
}
if (sbc_major < 4)
return mem_start;
#ifndef SCO
sprintf (sb16_dsp_operations.name, "SoundBlaster 16 %d.%d", major, minor);
sprintf (sb16_dsp_operations.name, "SoundBlaster 16 %d.%d", sbc_major, sbc_minor);
#endif
printk (" <%s>", sb16_dsp_operations.name);
......@@ -537,15 +555,12 @@ sb16_dsp_detect (struct address_info *hw_config)
if (sb16_dsp_ok)
return 1; /* Already initialized */
if (!(sb_config=sound_getconf(SNDCARD_SB)))
if (!(sb_config = sound_getconf (SNDCARD_SB)))
{
printk("SB16 Error: Plain SB not configured\n");
printk ("SB16 Error: Plain SB not configured\n");
return 0;
}
if (sbc_base != hw_config->io_base)
printk("Warning! SB16 I/O != SB I/O\n");
/* sb_setmixer(OPSW,0xf);
if(sb_getmixer(OPSW)!=0xf)
return 0; */
......@@ -553,31 +568,24 @@ sb16_dsp_detect (struct address_info *hw_config)
if (!sb_reset_dsp ())
return 0;
if (hw_config->irq != sb_config->irq)
{
printk("SB16 Error: Invalid IRQ number %d/%d\n",
sb_config->irq, hw_config->irq);
return 0;
}
if (hw_config->dma < 4)
if (hw_config->dma != sb_config->dma)
{
printk("SB16 Error: Invalid DMA channel %d/%d\n",
printk ("SB16 Error: Invalid DMA channel %d/%d\n",
sb_config->dma, hw_config->dma);
return 0;
}
dma16 = hw_config->dma;
dma8 = sb_config->dma;
set_irq_hw(hw_config->irq);
sb_setmixer(DMA_NR, (1<<hw_config->dma) | (1<<sb_config->dma));
set_irq_hw (sb_config->irq);
sb_setmixer (DMA_NR, (1 << hw_config->dma) | (1 << sb_config->dma));
DEB(printk ("SoundBlaster 16: IRQ %d DMA %d OK\n",hw_config->irq,hw_config->dma));
DEB (printk ("SoundBlaster 16: IRQ %d DMA %d OK\n", sb_config->irq, hw_config->dma));
/*
/*
dsp_showmessage(0xe3,99);
*/
*/
sb16_dsp_ok = 1;
return 1;
}
......@@ -586,6 +594,7 @@ void
sb16_dsp_interrupt (int unused)
{
int data;
data = INB (DSP_DATA_AVL16); /* Interrupt acknowledge */
if (intr_active)
......@@ -605,4 +614,5 @@ sb16_dsp_interrupt (int unused)
printk ("SoundBlaster: Unexpected interrupt\n");
}
}
#endif
......@@ -58,26 +58,19 @@ static int my_dev;
static int reset_sb16midi (void);
static void (*midi_input_intr) (int dev, unsigned char data);
extern int sbc_major;
static void
sb16midi_input_loop (void)
{
int count;
count = 10;
while (count) /* Not timed out */
if (input_avail ())
while (input_avail ())
{
unsigned char c = sb16midi_read ();
count = 100;
if (sb16midi_opened & OPEN_READ)
midi_input_intr (my_dev, c);
}
else
while (!input_avail () && count)
count--;
}
void
......@@ -87,31 +80,6 @@ sb16midiintr (int unit)
sb16midi_input_loop ();
}
/*
* It looks like there is no input interrupts in the UART mode. Let's try
* polling.
*/
static void
poll_sb16midi (unsigned long dummy)
{
unsigned long flags;
DEFINE_TIMER(sb16midi_timer, poll_sb16midi);
if (!(sb16midi_opened & OPEN_READ))
return; /* No longer required */
DISABLE_INTR (flags);
if (input_avail ())
sb16midi_input_loop ();
ACTIVATE_TIMER(sb16midi_timer, poll_sb16midi, 1); /* Come back later */
RESTORE_INTR (flags);
}
static int
sb16midi_open (int dev, int mode,
void (*input) (int dev, unsigned char data),
......@@ -127,7 +95,6 @@ sb16midi_open (int dev, int mode,
midi_input_intr = input;
sb16midi_opened = mode;
poll_sb16midi (0); /* Enable input polling */
return 0;
}
......@@ -299,6 +266,8 @@ probe_sb16midi (struct address_info *hw_config)
int ok = 0;
sb16midi_base = hw_config->io_base;
if (sbc_major < 4)
return 0; /* SB16 not detected */
if (sb_get_irq () < 0)
return 0;
......
......@@ -25,6 +25,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Modified:
* Hunyue Yau Jan 6 1994
* Added code to support Sound Galaxy NX Pro
*
*/
#include "sound_config.h"
......@@ -37,6 +41,7 @@
int sbc_base = 0;
static int sbc_irq = 0;
static int open_mode=0;
/*
* The DSP channel can be used either for input or output. Variable
......@@ -49,7 +54,8 @@ static int sbc_irq = 0;
int sb_dsp_ok = 0; /* Set to 1 after successful initialization */
static int midi_disabled = 0;
int sb_dsp_highspeed = 0;
static int major=1, minor=0; /* DSP version */
int sbc_major = 1;
int sbc_minor = 0; /* DSP version */
static int dsp_stereo = 0;
static int dsp_current_speed = DSP_DEFAULT_SPEED;
static int sb16 = 0;
......@@ -60,10 +66,10 @@ int sb_midi_busy = 0; /* 1 if the process has output to MIDI */
int sb_dsp_busy = 0;
volatile int sb_irq_mode = IMODE_NONE; /* IMODE_INPUT, IMODE_OUTPUT
* or IMODE_NONE */
static volatile int irq_ok = 0;
int sb_dsp_model = 1; /* 1=SB, 2=SB Pro */
int sb_duplex_midi = 0;
static int my_dev = 0;
......@@ -80,9 +86,10 @@ int sb_dsp_command (unsigned char val);
int
sb_dsp_command (unsigned char val)
{
int i, limit;
int i;
unsigned long limit;
limit = GET_TIME () + 10; /* The timeout is 0.1 secods */
limit = GET_TIME () + HZ / 10;/* The timeout is 0.1 secods */
/*
* Note! the i<500000 is an emergency exit. The sb_dsp_command() is sometimes
......@@ -109,7 +116,7 @@ sb_dsp_command (unsigned char val)
void
sbintr (int unit)
{
int status, data;
int status;
#ifndef EXCLUDE_SBPRO
if (sb16)
......@@ -117,10 +124,12 @@ sbintr (int unit)
unsigned char src = sb_getmixer (IRQ_STAT); /* Interrupt source register */
#ifndef EXCLUDE_SB16
if (src & 3) sb16_dsp_interrupt(unit);
if (src & 3)
sb16_dsp_interrupt (unit);
#ifndef EXCLUDE_MIDI
if (src & 4) sb16midiintr (unit); /* MPU401 interrupt */
if (src & 4)
sb16midiintr (unit); /* MPU401 interrupt */
#endif
#endif
......@@ -152,10 +161,7 @@ sbintr (int unit)
break;
case IMODE_MIDI:
printk ("+");
data = INB (DSP_READ);
printk ("%x", data);
sb_midi_interrupt (unit);
break;
default:
......@@ -166,12 +172,13 @@ sbintr (int unit)
static int sb_irq_usecount = 0;
int
sb_get_irq(void)
sb_get_irq (void)
{
int ok;
if (!sb_irq_usecount)
if ((ok=snd_set_irq_handler(sbc_irq, sbintr))<0) return ok;
if ((ok = snd_set_irq_handler (sbc_irq, sbintr)) < 0)
return ok;
sb_irq_usecount++;
......@@ -179,13 +186,15 @@ sb_get_irq(void)
}
void
sb_free_irq(void)
sb_free_irq (void)
{
if (!sb_irq_usecount) return;
if (!sb_irq_usecount)
return;
sb_irq_usecount--;
if (!sb_irq_usecount) snd_release_irq(sbc_irq);
if (!sb_irq_usecount)
snd_release_irq (sbc_irq);
}
int
......@@ -227,17 +236,31 @@ dsp_speed (int speed)
{
unsigned char tconst;
unsigned long flags;
int max_speed = 44100;
if (speed < 4000)
speed = 4000;
if (speed > 44100)
speed = 44100; /* Invalid speed */
/*
* Older SB models don't support higher speeds than 22050.
*/
if (sb_dsp_model == 1 && speed > 22050)
speed = 22050;
/* SB Classic doesn't support higher speed */
if (sbc_major < 2 ||
(sbc_major == 2 && sbc_minor == 0))
max_speed = 22050;
/*
* SB models earlier than SB Pro have low limit for the input speed.
*/
if (open_mode != OPEN_WRITE) /* Recording is possible */
if (sbc_major < 3) /* Limited input speed with these cards */
if (sbc_major == 2 && sbc_minor > 0)
max_speed = 15000;
else
max_speed = 13000;
if (speed > max_speed)
speed = max_speed; /* Invalid speed */
if (dsp_stereo && speed > 22050)
speed = 22050;
......@@ -259,7 +282,7 @@ dsp_speed (int speed)
int tmp;
tconst = (unsigned char) ((65536 -
((256000000+speed/2) / speed)) >> 8);
((256000000 + speed / 2) / speed)) >> 8);
sb_dsp_highspeed = 1;
DISABLE_INTR (flags);
......@@ -268,22 +291,22 @@ dsp_speed (int speed)
RESTORE_INTR (flags);
tmp = 65536 - (tconst << 8);
speed = (256000000+tmp/2) / tmp;
speed = (256000000 + tmp / 2) / tmp;
}
else
{
int tmp;
sb_dsp_highspeed = 0;
tconst = (256 - ((1000000+speed/2) / speed)) & 0xff;
tconst = (256 - ((1000000 + speed / 2) / speed)) & 0xff;
DISABLE_INTR (flags);
if (sb_dsp_command (0x40)) /* Set time constant */
if (sb_dsp_command (0x40))/* Set time constant */
sb_dsp_command (tconst);
RESTORE_INTR (flags);
tmp = 256 - tconst;
speed = (1000000+tmp/2) / tmp;
speed = (1000000 + tmp / 2) / tmp;
}
if (dsp_stereo)
......@@ -301,7 +324,7 @@ dsp_set_stereo (int mode)
#ifdef EXCLUDE_SBPRO
return 0;
#else
if (sb_dsp_model == 1 || sb16)
if (sbc_major < 3 || sb16)
return 0; /* Sorry no stereo */
if (mode && sb_midi_busy)
......@@ -334,11 +357,11 @@ sb_dsp_output_block (int dev, unsigned long buf, int count,
if (sb_dsp_highspeed)
{
DISABLE_INTR (flags);
if (sb_dsp_command (0x48)) /* High speed size */
if (sb_dsp_command (0x48))/* High speed size */
{
sb_dsp_command ((unsigned char)(count & 0xff));
sb_dsp_command ((unsigned char)((count >> 8) & 0xff));
sb_dsp_command (0x91); /* High speed 8 bit DAC */
sb_dsp_command ((unsigned char) (count & 0xff));
sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
sb_dsp_command (0x91);/* High speed 8 bit DAC */
}
else
printk ("SB Error: Unable to start (high speed) DAC\n");
......@@ -347,10 +370,10 @@ sb_dsp_output_block (int dev, unsigned long buf, int count,
else
{
DISABLE_INTR (flags);
if (sb_dsp_command (0x14)) /* 8-bit DAC (DMA) */
if (sb_dsp_command (0x14))/* 8-bit DAC (DMA) */
{
sb_dsp_command ((unsigned char)(count & 0xff));
sb_dsp_command ((unsigned char)((count >> 8) & 0xff));
sb_dsp_command ((unsigned char) (count & 0xff));
sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
}
else
printk ("SB Error: Unable to start DAC\n");
......@@ -380,11 +403,11 @@ sb_dsp_start_input (int dev, unsigned long buf, int count, int intrflag,
if (sb_dsp_highspeed)
{
DISABLE_INTR (flags);
if (sb_dsp_command (0x48)) /* High speed size */
if (sb_dsp_command (0x48))/* High speed size */
{
sb_dsp_command ((unsigned char)(count & 0xff));
sb_dsp_command ((unsigned char)((count >> 8) & 0xff));
sb_dsp_command (0x99); /* High speed 8 bit ADC */
sb_dsp_command ((unsigned char) (count & 0xff));
sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
sb_dsp_command (0x99);/* High speed 8 bit ADC */
}
else
printk ("SB Error: Unable to start (high speed) ADC\n");
......@@ -393,10 +416,10 @@ sb_dsp_start_input (int dev, unsigned long buf, int count, int intrflag,
else
{
DISABLE_INTR (flags);
if (sb_dsp_command (0x24)) /* 8-bit ADC (DMA) */
if (sb_dsp_command (0x24))/* 8-bit ADC (DMA) */
{
sb_dsp_command ((unsigned char)(count & 0xff));
sb_dsp_command ((unsigned char)((count >> 8) & 0xff));
sb_dsp_command ((unsigned char) (count & 0xff));
sb_dsp_command ((unsigned char) ((count >> 8) & 0xff));
}
else
printk ("SB Error: Unable to start ADC\n");
......@@ -418,14 +441,14 @@ sb_dsp_prepare_for_input (int dev, int bsize, int bcount)
dsp_cleanup ();
dsp_speaker (OFF);
if (major == 3) /* SB Pro */
if (sbc_major == 3) /* SB Pro */
{
if (dsp_stereo)
sb_dsp_command(0xa8);
sb_dsp_command (0xa8);
else
sb_dsp_command(0xa0);
sb_dsp_command (0xa0);
dsp_speed (dsp_current_speed);/* Speed must be recalculated if #channels
dsp_speed (dsp_current_speed); /* Speed must be recalculated if #channels
* changes */
}
return 0;
......@@ -438,10 +461,10 @@ sb_dsp_prepare_for_output (int dev, int bsize, int bcount)
dsp_speaker (ON);
#ifndef EXCLUDE_SBPRO
if (major == 3) /* SB Pro */
if (sbc_major == 3) /* SB Pro */
{
sb_mixer_set_stereo(dsp_stereo);
dsp_speed (dsp_current_speed);/* Speed must be recalculated if #channels
sb_mixer_set_stereo (dsp_stereo);
dsp_speed (dsp_current_speed); /* Speed must be recalculated if #channels
* changes */
}
#endif
......@@ -457,7 +480,7 @@ static int
verify_irq (void)
{
#if 0
DEFINE_WAIT_QUEUE(testq, testf);
DEFINE_WAIT_QUEUE (testq, testf);
irq_ok = 0;
......@@ -472,9 +495,9 @@ verify_irq (void)
sb_dsp_command (0xf2); /* This should cause immediate interrupt */
DO_SLEEP(testq, testf, HZ / 5);
DO_SLEEP (testq, testf, HZ / 5);
sb_free_irq();
sb_free_irq ();
if (!irq_ok)
{
......@@ -506,12 +529,11 @@ sb_dsp_open (int dev, int mode)
if (!irq_verified)
{
verify_irq();
verify_irq ();
irq_verified = 1;
}
else
if (!irq_ok)
printk("SB Warning: Incorrect IRQ setting %d\n",
else if (!irq_ok)
printk ("SB Warning: Incorrect IRQ setting %d\n",
sbc_irq);
retval = sb_get_irq ();
......@@ -528,6 +550,7 @@ sb_dsp_open (int dev, int mode)
sb_irq_mode = IMODE_NONE;
sb_dsp_busy = 1;
open_mode = mode;
return 0;
}
......@@ -541,6 +564,7 @@ sb_dsp_close (int dev)
dsp_speaker (OFF);
sb_dsp_busy = 0;
sb_dsp_highspeed = 0;
open_mode = 0;
}
static int
......@@ -605,6 +629,7 @@ sb_dsp_reset (int dev)
DISABLE_INTR (flags);
sb_reset_dsp ();
dsp_speed (dsp_current_speed);
dsp_cleanup ();
RESTORE_INTR (flags);
......@@ -631,6 +656,7 @@ sb_dsp_detect (struct address_info *hw_config)
static struct audio_operations sb_dsp_operations =
{
"SoundBlaster",
NOTHING_SPECIAL,
sb_dsp_open,
sb_dsp_close,
sb_dsp_output_block,
......@@ -650,64 +676,69 @@ long
sb_dsp_init (long mem_start, struct address_info *hw_config)
{
int i;
int prostat = 0;
major = minor = 0;
sbc_major = sbc_minor = 0;
sb_dsp_command (0xe1); /* Get version */
for (i = 1000; i; i--)
{
if (INB (DSP_DATA_AVAIL) & 0x80)
{ /* wait for Data Ready */
if (major == 0)
major = INB (DSP_READ);
if (sbc_major == 0)
sbc_major = INB (DSP_READ);
else
{
minor = INB (DSP_READ);
sbc_minor = INB (DSP_READ);
break;
}
}
}
if (major == 2 || major == 3)
if (sbc_major == 2 || sbc_major == 3) /* SB 2.0 or SB Pro */
sb_duplex_midi = 1;
if (major == 4)
if (sbc_major == 4)
sb16 = 1;
if (major >= 3)
sb_dsp_model = 2;
#ifndef EXCLUDE_SBPRO
if (major >= 3)
sb_mixer_init(major);
if (sbc_major >= 3 ||
(sbc_major == 2 && sbc_minor == 1)) /* Sound Galaxy ??? */
prostat = sb_mixer_init (sbc_major);
#endif
#ifndef EXCLUDE_YM3812
if (major > 3 || (major == 3 && minor > 0)) /* SB Pro2 or later */
{
if (sbc_major > 3 ||
(sbc_major == 3 && INB (0x388) == 0x00)) /* Non OPL-3 should return 0x06 */
enable_opl3_mode (OPL3_LEFT, OPL3_RIGHT, OPL3_BOTH);
}
#endif
if (major >= 3)
if (sbc_major >= 3)
{
#ifndef SCO
sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", major, minor);
if (prostat)
{
sprintf (sb_dsp_operations.name, "Sound Galaxy NX Pro %d.%d", sbc_major, sbc_minor);
}
else
{
sprintf (sb_dsp_operations.name, "SoundBlaster Pro %d.%d", sbc_major, sbc_minor);
}
#endif
}
else
{
#ifndef SCO
sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", major, minor);
sprintf (sb_dsp_operations.name, "SoundBlaster %d.%d", sbc_major, sbc_minor);
#endif
}
printk (" <%s>", sb_dsp_operations.name);
#ifndef EXCLUDE_AUDIO
# if !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SBPRO)
#if !defined(EXCLUDE_SB16) && !defined(EXCLUDE_SBPRO)
if (!sb16) /* There is a better driver for SB16 */
# endif
#endif
if (num_dspdevs < MAX_DSP_DEV)
{
dsp_devs[my_dev = num_dspdevs++] = &sb_dsp_operations;
......@@ -723,7 +754,7 @@ sb_dsp_init (long mem_start, struct address_info *hw_config)
#ifndef EXCLUDE_MIDI
if (!midi_disabled && !sb16) /* Midi don't work in the SB emulation mode
* of PAS, SB16 has better midi interface */
sb_midi_init(major);
sb_midi_init (sbc_major);
#endif
sb_dsp_ok = 1;
......
......@@ -49,11 +49,16 @@ extern int sb_midi_busy; /* 1 if the process has output to MIDI */
extern int sb_dsp_busy;
extern int sb_dsp_highspeed;
extern volatile int sb_irq_mode; /* IMODE_INPUT, IMODE_OUTPUT
extern volatile int sb_irq_mode;/* IMODE_INPUT, IMODE_OUTPUT
* or IMODE_NONE */
extern int sb_dsp_model; /* 1=SB, 2=SB Pro */
extern int sb_duplex_midi;
extern int sb_intr_active;
extern int sbc_base;
static int input_opened = 0;
static void (*midi_input_intr) (int dev, unsigned char data);
static int my_dev = 0;
static int
sb_midi_open (int dev, int mode,
......@@ -72,7 +77,7 @@ sb_midi_open (int dev, int mode,
if (mode != OPEN_WRITE && !sb_duplex_midi)
{
if (num_midis == 1)
printk ("SoundBlaster: Midi input not currently supported\n");
printk ("SoundBlaster: MIDI input not supported with plain SB\n");
return RET_ERROR (EPERM);
}
......@@ -96,6 +101,9 @@ sb_midi_open (int dev, int mode,
sb_reset_dsp ();
if (!sb_dsp_command (0xf2)) /* This is undodumented, isn't it */
return RET_ERROR (EIO); /* be nice to DSP */
if (!sb_dsp_command (0x35))
return RET_ERROR (EIO); /* Enter the UART mode */
sb_intr_active = 1;
......@@ -105,6 +113,9 @@ sb_midi_open (int dev, int mode,
sb_reset_dsp ();
return 0; /* IRQ not free */
}
input_opened = 1;
my_dev = dev;
midi_input_intr = input;
}
sb_midi_busy = 1;
......@@ -122,6 +133,7 @@ sb_midi_close (int dev)
}
sb_intr_active = 0;
sb_midi_busy = 0;
input_opened = 0;
}
static int
......@@ -174,6 +186,21 @@ sb_midi_ioctl (int dev, unsigned cmd, unsigned arg)
return RET_ERROR (EPERM);
}
void
sb_midi_interrupt (int dummy)
{
unsigned long flags;
unsigned char data;
DISABLE_INTR (flags);
data = INB (DSP_READ);
if (input_opened)
midi_input_intr (my_dev, data);
RESTORE_INTR (flags);
}
static struct midi_operations sb_midi_operations =
{
{"SoundBlaster", 0, 0, SNDCARD_SB},
......@@ -189,7 +216,7 @@ static struct midi_operations sb_midi_operations =
};
void
sb_midi_init(int model)
sb_midi_init (int model)
{
midi_devs[num_midis++] = &sb_midi_operations;
}
......
......@@ -26,6 +26,10 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Modified:
* Hunyue Yau Jan 6 1994
* Added code to support the Sound Galaxy NX Pro mixer.
*
*/
#include "sound_config.h"
......@@ -53,12 +57,12 @@ sb_setmixer (unsigned int port, unsigned int value)
{
unsigned long flags;
DISABLE_INTR(flags);
OUTB ((unsigned char)(port & 0xff), MIXER_ADDR); /* Select register */
DISABLE_INTR (flags);
OUTB ((unsigned char) (port & 0xff), MIXER_ADDR); /* Select register */
tenmicrosec ();
OUTB ((unsigned char)(value & 0xff), MIXER_DATA);
OUTB ((unsigned char) (value & 0xff), MIXER_DATA);
tenmicrosec ();
RESTORE_INTR(flags);
RESTORE_INTR (flags);
}
int
......@@ -67,28 +71,41 @@ sb_getmixer (unsigned int port)
int val;
unsigned long flags;
DISABLE_INTR(flags);
OUTB ((unsigned char)(port & 0xff), MIXER_ADDR); /* Select register */
DISABLE_INTR (flags);
OUTB ((unsigned char) (port & 0xff), MIXER_ADDR); /* Select register */
tenmicrosec ();
val = INB (MIXER_DATA);
tenmicrosec ();
RESTORE_INTR(flags);
RESTORE_INTR (flags);
return val;
}
void
sb_mixer_set_stereo(int mode)
sb_mixer_set_stereo (int mode)
{
if (!mixer_initialized) return;
if (!mixer_initialized)
return;
sb_setmixer (OUT_FILTER, ((sb_getmixer (OUT_FILTER) & ~STEREO_DAC)
| (mode ? STEREO_DAC : MONO_DAC)));
}
/*
* Returns:
* 0 No mixer detected.
* 1 Only a plain Sound Blaster Pro style mixer detected.
* 2 The Sound Galaxy NX Pro mixer detected.
*/
static int
detect_mixer (void)
{
#ifdef __SGNXPRO__
int oldbass, oldtreble;
#endif
int retcode = 1;
/*
* Detect the mixer by changing parameters of two volume channels. If the
* values read back match with the values written, the mixer is there (is
......@@ -102,29 +119,52 @@ detect_mixer (void)
if (sb_getmixer (VOC_VOL) != 0x33)
return 0;
return 1;
#ifdef __SGNXPRO__
/* Attempt to detect the SG NX Pro by check for valid bass/treble
* registers.
*/
oldbass = sb_getmixer (BASS_LVL);
oldtreble = sb_getmixer (TREBLE_LVL);
sb_setmixer (BASS_LVL, 0xaa);
sb_setmixer (TREBLE_LVL, 0x55);
if ((sb_getmixer (BASS_LVL) != 0xaa) ||
(sb_getmixer (TREBLE_LVL) != 0x55))
{
retcode = 1; /* 1 == Only SB Pro detected */
}
else
retcode = 2; /* 2 == SG NX Pro detected */
/* Restore register in either case since SG NX Pro has EEPROM with
* 'preferred' values stored.
*/
sb_setmixer (BASS_LVL, oldbass);
sb_setmixer (TREBLE_LVL, oldtreble);
#endif
return retcode;
}
static void
change_bits(unsigned char *regval, int dev, int chn, int newval)
change_bits (unsigned char *regval, int dev, int chn, int newval)
{
unsigned char mask;
int shift;
mask = (1 << (*iomap)[dev][chn].nbits)-1;
mask = (1 << (*iomap)[dev][chn].nbits) - 1;
newval = ((newval * mask) + 50) / 100; /* Scale it */
shift = (*iomap)[dev][chn].bitoffs-(*iomap)[dev][LEFT_CHN].nbits+1;
shift = (*iomap)[dev][chn].bitoffs - (*iomap)[dev][LEFT_CHN].nbits + 1;
*regval &= ~(mask << shift); /* Filter out the previous value */
*regval |= (newval & mask) << shift; /* Set the new value */
}
static int
sb_mixer_get(int dev)
sb_mixer_get (int dev)
{
if (!((1<<dev) & supported_devices))
return RET_ERROR(EINVAL);
if (!((1 << dev) & supported_devices))
return RET_ERROR (EINVAL);
return levels[dev];
}
......@@ -138,50 +178,53 @@ sb_mixer_set (int dev, int value)
int regoffs;
unsigned char val;
if (left > 100) left = 100;
if (right > 100) right = 100;
if (left > 100)
left = 100;
if (right > 100)
right = 100;
if (dev > 31) return RET_ERROR(EINVAL);
if (dev > 31)
return RET_ERROR (EINVAL);
if (!(supported_devices & (1 << dev))) /* Not supported */
return RET_ERROR(EINVAL);
return RET_ERROR (EINVAL);
regoffs = (*iomap)[dev][LEFT_CHN].regno;
if (regoffs == 0)
return RET_ERROR(EINVAL);
return RET_ERROR (EINVAL);
val = sb_getmixer(regoffs);
change_bits(&val, dev, LEFT_CHN, left);
val = sb_getmixer (regoffs);
change_bits (&val, dev, LEFT_CHN, left);
levels[dev] = left|(left << 8);
levels[dev] = left | (left << 8);
if ((*iomap)[dev][RIGHT_CHN].regno != regoffs) /* Change register */
{
sb_setmixer(regoffs, val); /* Save the old one */
sb_setmixer (regoffs, val); /* Save the old one */
regoffs = (*iomap)[dev][RIGHT_CHN].regno;
if (regoffs == 0)
return left|(left << 8); /* Just left channel present */
return left | (left << 8); /* Just left channel present */
val = sb_getmixer(regoffs); /* Read the new one */
val = sb_getmixer (regoffs); /* Read the new one */
}
change_bits(&val, dev, RIGHT_CHN, right);
sb_setmixer(regoffs, val);
change_bits (&val, dev, RIGHT_CHN, right);
sb_setmixer (regoffs, val);
levels[dev] = left | (right << 8);
return left | (right << 8);
}
static void
set_recsrc(int src)
set_recsrc (int src)
{
sb_setmixer(RECORD_SRC, (sb_getmixer(RECORD_SRC)&~7) | (src&0x7));
sb_setmixer (RECORD_SRC, (sb_getmixer (RECORD_SRC) & ~7) | (src & 0x7));
}
static int
set_recmask(int mask)
set_recmask (int mask)
{
int devmask, i;
unsigned char regimageL, regimageR;
......@@ -209,7 +252,7 @@ set_recmask(int mask)
}
if (devmask ^ recmask)/* Input source changed */
if (devmask ^ recmask) /* Input source changed */
{
switch (devmask)
{
......@@ -234,17 +277,18 @@ set_recmask(int mask)
break;
case 4:
if (!devmask) devmask = SOUND_MASK_MIC;
if (!devmask)
devmask = SOUND_MASK_MIC;
regimageL = regimageR = 0;
for (i=0;i<SOUND_MIXER_NRDEVICES;i++)
if ((1<<i) & devmask)
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
if ((1 << i) & devmask)
{
regimageL |= sb16_recmasks_L[i];
regimageR |= sb16_recmasks_R[i];
}
sb_setmixer(SB16_IMASK_L, regimageL);
sb_setmixer(SB16_IMASK_R, regimageR);
sb_setmixer (SB16_IMASK_L, regimageL);
sb_setmixer (SB16_IMASK_R, regimageR);
break;
}
......@@ -261,7 +305,7 @@ sb_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
switch (cmd & 0xff)
{
case SOUND_MIXER_RECSRC:
return IOCTL_OUT(arg, set_recmask(IOCTL_IN(arg)));
return IOCTL_OUT (arg, set_recmask (IOCTL_IN (arg)));
break;
default:
......@@ -281,7 +325,7 @@ sb_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg)
case SOUND_MIXER_STEREODEVS:
return IOCTL_OUT (arg, supported_devices &
~(SOUND_MASK_MIC|SOUND_MASK_SPEAKER));
~(SOUND_MASK_MIC | SOUND_MASK_SPEAKER));
break;
case SOUND_MIXER_RECMASK:
......@@ -306,21 +350,33 @@ static struct mixer_operations sb_mixer_operations =
};
static void
sb_mixer_reset(void)
sb_mixer_reset (void)
{
int i;
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
sb_mixer_set (i, levels[i]);
set_recmask(SOUND_MASK_MIC);
set_recmask (SOUND_MASK_MIC);
}
void
sb_mixer_init(int major_model)
/*
* Returns a code depending on whether a SG NX Pro was detected.
* 0 == Plain SB 16 or SB Pro
* 1 == SG NX Pro detected.
*
* Used to update message.
*/
int
sb_mixer_init (int major_model)
{
sb_setmixer(0x00, 0); /* Reset mixer */
int mixerstat;
sb_setmixer (0x00, 0); /* Reset mixer */
if (!detect_mixer()) return; /* No mixer. Why? */
mixerstat = detect_mixer ();
if (!mixerstat)
return 0; /* No mixer. Why? */
mixer_initialized = 1;
mixer_model = major_model;
......@@ -329,9 +385,21 @@ sb_mixer_init(int major_model)
{
case 3:
mixer_caps = SOUND_CAP_EXCL_INPUT;
#ifdef __SGNXPRO__
if (mixerstat == 2)
{ /* A SGNXPRO was detected */
supported_devices = SGNXPRO_MIXER_DEVICES;
supported_rec_devices = SGNXPRO_RECORDING_DEVICES;
iomap = &sgnxpro_mix;
}
else
#endif
{ /* Otherwise plain SB Pro */
supported_devices = SBPRO_MIXER_DEVICES;
supported_rec_devices = SBPRO_RECORDING_DEVICES;
iomap = &sbpro_mix;
}
break;
case 4:
......@@ -342,12 +410,13 @@ sb_mixer_init(int major_model)
break;
default:
printk("SB Warning: Unsupported mixer type\n");
return;
printk ("SB Warning: Unsupported mixer type\n");
return 0;
}
mixer_devs[num_mixers++] = &sb_mixer_operations;
sb_mixer_reset();
sb_mixer_reset ();
return (mixerstat == 2);
}
#endif
......@@ -25,12 +25,28 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* Modified:
* Hunyue Yau Jan 6 1994
* Added defines for the Sound Galaxy NX Pro mixer.
*
*/
#define SBPRO_RECORDING_DEVICES (SOUND_MASK_LINE | SOUND_MASK_MIC | SOUND_MASK_CD)
/* Same as SB Pro, unless I find otherwise */
#define SGNXPRO_RECORDING_DEVICES SBPRO_RECORDING_DEVICES
#define SBPRO_MIXER_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_PCM | SOUND_MASK_LINE | SOUND_MASK_MIC | \
SOUND_MASK_CD | SOUND_MASK_VOLUME)
/* SG NX Pro has treble and bass settings on the mixer. The 'speaker'
* channel is the COVOX/DisneySoundSource emulation volume control
* on the mixer. It does NOT control speaker volume. Should have own
* mask eventually?
*/
#define SGNXPRO_MIXER_DEVICES (SBPRO_MIXER_DEVICES|SOUND_MASK_BASS| \
SOUND_MASK_TREBLE|SOUND_MASK_SPEAKER )
#define SB16_RECORDING_DEVICES (SOUND_MASK_SYNTH | SOUND_MASK_LINE | SOUND_MASK_MIC | \
SOUND_MASK_CD)
......@@ -62,6 +78,13 @@
#define IRQ_STAT 0x82
#define OPSW 0x3c
/*
* Additional registers on the SG NX Pro
*/
#define COVOX_VOL 0x42
#define TREBLE_LVL 0x44
#define BASS_LVL 0x46
#define FREQ_HI (1 << 3)/* Use High-frequency ANFI filters */
#define FREQ_LOW 0 /* Use Low-frequency ANFI filters */
#define FILT_ON 0 /* Yes, 0 to turn it on, 1 for off */
......@@ -108,6 +131,23 @@ MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0)
};
#ifdef __SGNXPRO__
mixer_tab sgnxpro_mix = {
MIX_ENT(SOUND_MIXER_VOLUME, 0x22, 7, 4, 0x22, 3, 4),
MIX_ENT(SOUND_MIXER_BASS, 0x46, 2, 3, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_TREBLE, 0x44, 2, 3, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_SYNTH, 0x26, 7, 4, 0x26, 3, 4),
MIX_ENT(SOUND_MIXER_PCM, 0x04, 7, 4, 0x04, 3, 4),
MIX_ENT(SOUND_MIXER_SPEAKER, 0x42, 2, 3, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_LINE, 0x2e, 7, 4, 0x2e, 3, 4),
MIX_ENT(SOUND_MIXER_MIC, 0x0a, 2, 3, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_CD, 0x28, 7, 4, 0x28, 3, 4),
MIX_ENT(SOUND_MIXER_IMIX, 0x00, 0, 0, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_ALTPCM, 0x00, 0, 0, 0x00, 0, 0),
MIX_ENT(SOUND_MIXER_RECLEV, 0x00, 0, 0, 0x00, 0, 0)
};
#endif
mixer_tab sb16_mix = {
MIX_ENT(SOUND_MIXER_VOLUME, 0x30, 7, 5, 0x31, 7, 5),
MIX_ENT(SOUND_MIXER_BASS, 0x46, 7, 4, 0x47, 7, 4),
......
......@@ -46,7 +46,7 @@ static int midi_opened[MAX_MIDI_DEV] =
static int midi_written[MAX_MIDI_DEV] =
{0};
long seq_time = 0; /* Reference point for the timer */
unsigned long seq_time = 0; /* Reference point for the timer */
#include "tuning.h"
......@@ -77,6 +77,7 @@ int
sequencer_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
{
int c = count, p = 0;
unsigned long flags;
dev = dev >> 4;
......@@ -85,13 +86,23 @@ sequencer_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
while (c > 3)
{
DISABLE_INTR (flags);
if (!iqlen)
{
if (c != count) /* Some data has been received */
{
RESTORE_INTR (flags);
return count - c; /* Return what we have */
}
DO_SLEEP (midi_sleeper, midi_sleep_flag, 0);
if (!iqlen)
{
RESTORE_INTR (flags);
return count - c;
}
}
COPY_TO_USER (buf, p, &iqueue[iqhead * IEV_SZ], IEV_SZ);
p += 4;
......@@ -99,6 +110,7 @@ sequencer_read (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
iqhead = (iqhead + 1) % SEQ_MAX_QUEUE;
iqlen--;
RESTORE_INTR (flags);
}
return count - c;
......@@ -118,11 +130,11 @@ copy_to_input (unsigned char *event)
if (iqlen >= (SEQ_MAX_QUEUE - 1))
return; /* Overflow */
DISABLE_INTR (flags);
memcpy (&iqueue[iqtail * IEV_SZ], event, IEV_SZ);
iqlen++;
iqtail = (iqtail + 1) % SEQ_MAX_QUEUE;
DISABLE_INTR (flags);
if (SOMEONE_WAITING (midi_sleeper, midi_sleep_flag))
{
WAKE_UP (midi_sleeper, midi_sleep_flag);
......@@ -327,6 +339,10 @@ extended_event (unsigned char *q)
synth_devs[dev]->controller (dev, q[3], q[4], *(short *) &q[5]);
break;
case SEQ_VOLMODE:
synth_devs[dev]->volume_method (dev, q[3]);
break;
default:
return RET_ERROR (EINVAL);
}
......@@ -346,7 +362,7 @@ seq_startplay (void)
qhead = ((this_one = qhead) + 1) % SEQ_MAX_QUEUE;
qlen--;
q = &queue[this_one*EV_SZ];
q = &queue[this_one * EV_SZ];
switch (q[0])
{
......@@ -463,7 +479,7 @@ seq_startplay (void)
int
sequencer_open (int dev, struct fileinfo *file)
{
{
int retval, mode, i;
dev = dev >> 4;
......@@ -543,7 +559,7 @@ sequencer_open (int dev, struct fileinfo *file)
pmgr_inform (i, PM_E_OPENED, 0, 0, 0, 0);
return 0;
}
}
void
seq_drain_midi_queues (void)
......@@ -578,7 +594,7 @@ seq_drain_midi_queues (void)
void
sequencer_release (int dev, struct fileinfo *file)
{
{
int i;
int mode = file->mode & O_ACCMODE;
......@@ -624,7 +640,7 @@ sequencer_release (int dev, struct fileinfo *file)
pmgr_inform (i, PM_E_CLOSED, 0, 0, 0, 0);
sequencer_busy = 0;
}
}
static int
seq_sync (void)
......@@ -687,7 +703,7 @@ seq_reset (void)
for (chn = 0; chn < 16; chn++)
{
midi_outc (i,
(unsigned char)(0xb0 + (chn & 0xff))); /* Channel msg */
(unsigned char) (0xb0 + (chn & 0xff))); /* Channel msg */
midi_outc (i, 0x7b);/* All notes off */
midi_outc (i, 0); /* Dummy parameter */
}
......@@ -1049,7 +1065,7 @@ unsigned long
compute_finetune (unsigned long base_freq, int bend, int range)
{
unsigned long amount;
int negative, semitones, cents;
int negative, semitones, cents, multiplier = 1;
if (!bend)
return base_freq;
......@@ -1073,13 +1089,20 @@ compute_finetune (unsigned long base_freq, int bend, int range)
if (bend > range)
bend = range;
/*
if (bend > 2399)
bend = 2399;
*/
while (bend > 2399)
{
multiplier *= 4;
bend -= 2400;
}
semitones = bend / 100;
cents = bend % 100;
amount = semitone_tuning[semitones] * cent_tuning[cents] / 10000;
amount = semitone_tuning[semitones] * multiplier * cent_tuning[cents] / 10000;
if (negative)
return (base_freq * 10000) / amount; /* Bend down */
......@@ -1093,8 +1116,9 @@ sequencer_init (long mem_start)
{
sequencer_ok = 1;
PERMANENT_MALLOC(unsigned char*, queue, SEQ_MAX_QUEUE*EV_SZ, mem_start);
PERMANENT_MALLOC(unsigned char*, iqueue, SEQ_MAX_QUEUE*IEV_SZ, mem_start);
PERMANENT_MALLOC (unsigned char *, queue, SEQ_MAX_QUEUE * EV_SZ, mem_start);
PERMANENT_MALLOC (unsigned char *, iqueue, SEQ_MAX_QUEUE * IEV_SZ, mem_start);
return mem_start;
}
......@@ -1114,14 +1138,14 @@ sequencer_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
int
sequencer_open (int dev, struct fileinfo *file)
{
{
return RET_ERROR (ENXIO);
}
}
void
sequencer_release (int dev, struct fileinfo *file)
{
}
{
}
int
sequencer_ioctl (int dev, struct fileinfo *file,
unsigned int cmd, unsigned int arg)
......
......@@ -129,12 +129,13 @@ int probe_sb16midi(struct address_info *hw_config);
/* From sb_midi.c */
void sb_midi_init(int model);
void sb_midi_interrupt(int dummy);
/* From sb_mixer.c */
void sb_setmixer (unsigned int port, unsigned int value);
int sb_getmixer (unsigned int port);
void sb_mixer_set_stereo(int mode);
void sb_mixer_init(int major_model);
int sb_mixer_init(int major_model);
/* From opl3.c */
int opl3_detect (int ioaddr);
......@@ -181,6 +182,7 @@ unsigned char gus_read8 (int reg);
void gus_write8(int reg, unsigned int data);
void guswave_dma_irq(void);
void gus_delay(void);
int gus_default_mixer_ioctl (int dev, unsigned int cmd, unsigned int arg);
/* From gus_midi.c */
long gus_midi_init(long mem_start);
......@@ -201,3 +203,6 @@ int pmgr_write (int dev, struct fileinfo *file, snd_rw_buf * buf, int count);
int pmgr_access(int dev, struct patmgr_info *rec);
int pmgr_inform(int dev, int event, unsigned long parm1, unsigned long parm2,
unsigned long parm3, unsigned long parm4);
/* From ics2101.c */
long ics2101_mixer_init(long mem_start);
......@@ -32,13 +32,16 @@
#ifdef CONFIGURE_SOUNDCARD
struct sbc_device
{
{
int usecount;
};
};
static struct sbc_device sbc_devices[SND_NDEVS] = {{0}};
static struct sbc_device sbc_devices[SND_NDEVS] =
{
{0}};
static int in_use = 0; /* Total # of open device files (excluding
* minor 0) */
/*
......@@ -53,7 +56,7 @@ put_status (char *s)
{
int l;
for (l=0;l<256,s[l];l++); /* l=strlen(s); */
for (l = 0; l < 256, s[l]; l++); /* l=strlen(s); */
if (status_len + l >= 4000)
return 0;
......@@ -72,24 +75,25 @@ put_status_int (unsigned int val, int radix)
static char hx[] = "0123456789abcdef";
char buf[11];
if (!val) return put_status("0");
if (!val)
return put_status ("0");
l = 0;
buf[10]=0;
buf[10] = 0;
while (val)
{
v = val % radix;
val = val / radix;
buf[9-l] = hx[v];
buf[9 - l] = hx[v];
l++;
}
if (status_len + l >= 4000)
return 0;
memcpy (&status_buf[status_len], &buf[10-l], l);
memcpy (&status_buf[status_len], &buf[10 - l], l);
status_len += l;
return 1;
......@@ -114,7 +118,7 @@ init_status (void)
if (!put_status ("Config options: "))
return;
if (!put_status_int(SELECTED_SOUND_OPTIONS, 16))
if (!put_status_int (SELECTED_SOUND_OPTIONS, 16))
return;
if (!put_status ("\n\nHW config: \n"))
......@@ -126,16 +130,26 @@ init_status (void)
if (!put_status ("("))
return;
if (!put_status ("Type ")) return;
if (!put_status_int(supported_drivers[i].card_type, 10)) return;
if (!put_status (": ")) return;
if (!put_status (supported_drivers[i].name)) return;
if (!put_status (" at 0x")) return;
if (!put_status_int(supported_drivers[i].config.io_base, 16)) return;
if (!put_status (" irq ")) return;
if (!put_status_int(supported_drivers[i].config.irq, 10)) return;
if (!put_status (" drq ")) return;
if (!put_status_int(supported_drivers[i].config.dma, 10)) return;
if (!put_status ("Type "))
return;
if (!put_status_int (supported_drivers[i].card_type, 10))
return;
if (!put_status (": "))
return;
if (!put_status (supported_drivers[i].name))
return;
if (!put_status (" at 0x"))
return;
if (!put_status_int (supported_drivers[i].config.io_base, 16))
return;
if (!put_status (" irq "))
return;
if (!put_status_int (supported_drivers[i].config.irq, 10))
return;
if (!put_status (" drq "))
return;
if (!put_status_int (supported_drivers[i].config.dma, 10))
return;
if (!supported_drivers[i].enabled)
if (!put_status (")"))
......@@ -150,10 +164,14 @@ init_status (void)
for (i = 0; i < num_dspdevs; i++)
{
if (!put_status_int(i, 10)) return;
if (!put_status(": "))return;
if (!put_status(dsp_devs[i]->name))return;
if (!put_status("\n"))return;
if (!put_status_int (i, 10))
return;
if (!put_status (": "))
return;
if (!put_status (dsp_devs[i]->name))
return;
if (!put_status ("\n"))
return;
}
if (!put_status ("\nSynth devices:\n"))
......@@ -161,10 +179,14 @@ init_status (void)
for (i = 0; i < num_synths; i++)
{
if (!put_status_int(i, 10)) return;
if (!put_status(": "))return;
if (!put_status(synth_devs[i]->info->name))return;
if (!put_status("\n"))return;
if (!put_status_int (i, 10))
return;
if (!put_status (": "))
return;
if (!put_status (synth_devs[i]->info->name))
return;
if (!put_status ("\n"))
return;
}
if (!put_status ("\nMidi devices:\n"))
......@@ -172,10 +194,14 @@ init_status (void)
for (i = 0; i < num_midis; i++)
{
if (!put_status_int(i, 10)) return;
if (!put_status(": "))return;
if (!put_status(midi_devs[i]->info.name))return;
if (!put_status("\n"))return;
if (!put_status_int (i, 10))
return;
if (!put_status (": "))
return;
if (!put_status (midi_devs[i]->info.name))
return;
if (!put_status ("\n"))
return;
}
if (num_mixers)
......@@ -191,7 +217,7 @@ init_status (void)
}
static int
read_status (snd_rw_buf *buf, int count)
read_status (snd_rw_buf * buf, int count)
{
/*
* Return at most 'count' bytes from the status_buf.
......@@ -206,14 +232,14 @@ read_status (snd_rw_buf *buf, int count)
if (l <= 0)
return 0;
COPY_TO_USER(buf, 0, &status_buf[status_ptr], l);
COPY_TO_USER (buf, 0, &status_buf[status_ptr], l);
status_ptr += l;
return l;
}
int
sound_read_sw (int dev, struct fileinfo *file, snd_rw_buf *buf, int count)
sound_read_sw (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
{
DEB (printk ("sound_read_sw(dev=%d, count=%d)\n", dev, count));
......@@ -246,7 +272,7 @@ sound_read_sw (int dev, struct fileinfo *file, snd_rw_buf *buf, int count)
}
int
sound_write_sw (int dev, struct fileinfo *file, snd_rw_buf *buf, int count)
sound_write_sw (int dev, struct fileinfo *file, snd_rw_buf * buf, int count)
{
DEB (printk ("sound_write_sw(dev=%d, count=%d)\n", dev, count));
......@@ -275,6 +301,7 @@ int
sound_open_sw (int dev, struct fileinfo *file)
{
int retval;
DEB (printk ("sound_open_sw(dev=%d) : usecount=%d\n", dev, sbc_devices[dev].usecount));
if ((dev >= SND_NDEVS) || (dev < 0))
......@@ -414,4 +441,5 @@ sound_ioctl_sw (int dev, struct fileinfo *file,
return RET_ERROR (EPERM);
}
#endif
......@@ -37,6 +37,7 @@
extern long seq_time;
static int soundcards_installed = 0; /* Number of installed
* soundcards */
static int soundcard_configured = 0;
......@@ -209,7 +210,7 @@ tenmicrosec (void)
}
int
snd_set_irq_handler (int interrupt_level, void(*hndlr)(int))
snd_set_irq_handler (int interrupt_level, void (*hndlr) (int))
{
int retcode;
......@@ -237,9 +238,9 @@ snd_set_irq_handler (int interrupt_level, void(*hndlr)(int))
}
void
snd_release_irq(int vect)
snd_release_irq (int vect)
{
free_irq(vect);
free_irq (vect);
}
void
......
......@@ -407,9 +407,11 @@ int do_mknod(const char * filename, int mode, dev_t dev)
iput(dir);
return -EPERM;
}
dir->i_count++;
down(&dir->i_sem);
error = dir->i_op->mknod(dir,basename,namelen,mode,dev);
up(&dir->i_sem);
iput(dir);
return error;
}
......@@ -462,9 +464,11 @@ static int do_mkdir(const char * pathname, int mode)
iput(dir);
return -EPERM;
}
dir->i_count++;
down(&dir->i_sem);
error = dir->i_op->mkdir(dir,basename,namelen,mode);
up(&dir->i_sem);
iput(dir);
return error;
}
......@@ -588,9 +592,11 @@ static int do_symlink(const char * oldname, const char * newname)
iput(dir);
return -EPERM;
}
dir->i_count++;
down(&dir->i_sem);
error = dir->i_op->symlink(dir,basename,namelen,oldname);
up(&dir->i_sem);
iput(dir);
return error;
}
......@@ -647,9 +653,11 @@ static int do_link(struct inode * oldinode, const char * newname)
iput(oldinode);
return -EPERM;
}
dir->i_count++;
down(&dir->i_sem);
error = dir->i_op->link(oldinode, dir, basename, namelen);
up(&dir->i_sem);
iput(dir);
return error;
}
......@@ -723,10 +731,12 @@ static int do_rename(const char * oldname, const char * newname)
iput(new_dir);
return -EPERM;
}
new_dir->i_count++;
down(&new_dir->i_sem);
error = old_dir->i_op->rename(old_dir, old_base, old_len,
new_dir, new_base, new_len);
up(&new_dir->i_sem);
iput(new_dir);
return error;
}
......
......@@ -52,20 +52,6 @@ __asm__ ("movl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
#define put_fs_long(x,addr) put_user_long((x),(int *)(addr))
static inline void and_user_long(unsigned long val,int * addr)
{
__asm__ ("andl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
}
#define and_fs_long(x,addr) and_user_long((x),(int *)(addr))
static inline void or_user_long(unsigned long val,int * addr)
{
__asm__ ("orl %0,%%fs:%1": /* no outputs */ :"ir" (val),"m" (*addr));
}
#define or_fs_long(x,addr) or_user_long((x),(int *)(addr))
static inline void __generic_memcpy_tofs(void * to, const void * from, unsigned long n)
{
__asm__("cld\n\t"
......
......@@ -365,9 +365,7 @@ __asm__("str %%ax\n\t" \
* tha math co-processor latest.
*/
#define switch_to(tsk) \
__asm__("cmpl %%ecx,_current\n\t" \
"je 1f\n\t" \
"cli\n\t" \
__asm__("cli\n\t" \
"xchgl %%ecx,_current\n\t" \
"ljmp %0\n\t" \
"sti\n\t" \
......
......@@ -34,7 +34,7 @@
*
* Regards,
* Hannu Savolainen
* hsavolai@cs.helsinki.fi
* hannu@voxware.pp.fi, Hannu.Savolainen@helsinki.fi
*/
#define SOUND_VERSION 203
......@@ -310,6 +310,14 @@ struct patmgr_info { /* Note! size must be < 4k since kmalloc() is used */
#define CTRL_EXPRESSION 253
#define CTRL_MAIN_VOLUME 252
#define SEQ_BALANCE 11
#define SEQ_VOLMODE 12
/*
* Volume mode decides how volumes are used
*/
#define VOL_METHOD_ADAGIO 1
#define VOL_METHOD_LINEAR 2
/*
* Note! SEQ_WAIT, SEQ_MIDIPUTC and SEQ_ECHO are used also as
......@@ -630,7 +638,8 @@ void seqbuf_dump(void); /* This function must be provided by programs */
* }
*/
#define SEQ_DEFINEBUF(len) unsigned char _seqbuf[len]; int _seqbuflen = len, _seqbufptr = 0
#define SEQ_DEFINEBUF(len) unsigned char _seqbuf[len]; int _seqbuflen = len; int _seqbufptr = 0
#define SEQ_DECLAREBUF() extern unsigned char _seqbuf[]; extern int _seqbuflen;extern int _seqbufptr
#define SEQ_PM_DEFINES struct patmgr_info _pm_info
#define _SEQ_NEEDBUF(len) if ((_seqbufptr+(len)) > _seqbuflen) seqbuf_dump()
#define _SEQ_ADVBUF(len) _seqbufptr += len
......@@ -644,6 +653,17 @@ void seqbuf_dump(void); /* This function must be provided by programs */
_pm_info.parm1 = bank, _pm_info.parm2 = 128, \
ioctl(seqfd, SNDCTL_PMGR_ACCESS, &_pm_info))
#define SEQ_VOLUME_MODE(dev, mode) {_SEQ_NEEDBUF(8);\
_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
_seqbuf[_seqbufptr+1] = SEQ_VOLMODE;\
_seqbuf[_seqbufptr+2] = (dev);\
_seqbuf[_seqbufptr+3] = (mode);\
_seqbuf[_seqbufptr+4] = 0;\
_seqbuf[_seqbufptr+5] = 0;\
_seqbuf[_seqbufptr+6] = 0;\
_seqbuf[_seqbufptr+7] = 0;\
_SEQ_ADVBUF(8);}
#define SEQ_START_NOTE(dev, voice, note, vol) {_SEQ_NEEDBUF(8);\
_seqbuf[_seqbufptr] = SEQ_EXTENDED;\
_seqbuf[_seqbufptr+1] = SEQ_NOTEON;\
......@@ -734,8 +754,8 @@ void seqbuf_dump(void); /* This function must be provided by programs */
_seqbuf[_seqbufptr+2] = (device);\
_seqbuf[_seqbufptr+3] = 0;\
_SEQ_ADVBUF(4);}
#define SEQ_WRPATCH(patch, len) {if (_seqbufptr) seqbuf_dump();\
if (write(seqfd, (char*)(patch), len)==-1) \
#define SEQ_WRPATCH(patchx, len) {if (_seqbufptr) seqbuf_dump();\
if (write(seqfd, (char*)(patchx), len)==-1) \
perror("Write patch: /dev/sequencer");}
#endif
......
......@@ -40,7 +40,7 @@
#define VM86_SIGNAL 0 /* return due to signal */
#define VM86_UNKNOWN 1 /* unhandled GP fault - IO-instruction or similar */
#define VM86_INTx 2 /* int3/int x instruction (ARG = x) */
#define VM86_STI 3 /* sti/popfl instruction enabled virtual interrupts */
#define VM86_STI 3 /* sti/popf/iret instruction enabled virtual interrupts */
/*
* This is the stack-layout when we have done a "SAVE_ALL" from vm86
......@@ -103,14 +103,6 @@ struct vm86_struct {
void handle_vm86_fault(struct vm86_regs *, long);
extern inline int is_revectored(int nr, struct revectored_struct * bitmap)
{
__asm__ __volatile__("btl %2,%%fs:%1\n\tsbbl %0,%0"
:"=r" (nr)
:"m" (*bitmap),"r" (nr));
return nr;
}
#endif
#endif
......@@ -84,7 +84,7 @@ int sys_msgsnd (int msqid, struct msgbuf *msgp, int msgsz, int msgflg)
if (msgque[id] == IPC_UNUSED || msgque[id] == IPC_NOID
|| ipcp->seq != msqid / MSGMNI) {
kfree_s (msgh, sizeof(*msgh) + msgsz);
kfree(msgh);
return -EIDRM;
}
......@@ -194,7 +194,7 @@ int sys_msgrcv (int msqid, struct msgbuf *msgp, int msgsz, long msgtyp,
wake_up (&msq->wwait);
put_fs_long (nmsg->msg_type, &msgp->mtype);
memcpy_tofs (msgp->mtext, nmsg->msg_spot, msgsz);
kfree_s (nmsg, sizeof(*nmsg) + msgsz);
kfree(nmsg);
return msgsz;
} else { /* did not find a message */
if (msgflg & IPC_NOWAIT)
......@@ -311,9 +311,9 @@ static void freeque (int id)
for (msgp = msq->msg_first; msgp; msgp = msgh ) {
msgh = msgp->msg_next;
msghdrs--;
kfree_s (msgp, sizeof(*msgp) + msgp->msg_ts);
kfree(msgp);
}
kfree_s (msq, sizeof (*msq));
kfree(msq);
}
int sys_msgctl (int msqid, int cmd, struct msqid_ds *buf)
......
......@@ -144,7 +144,7 @@ static void freeary (int id)
wake_up (&sma->eventn);
schedule();
}
kfree_s (sma, sizeof (*sma) + sma->sem_nsems * sizeof (struct sem));
kfree(sma);
return;
}
......
......@@ -95,7 +95,7 @@ static int newseg (key_t key, int shmflg, int size)
shm_segs[id] = (struct shmid_ds *) IPC_UNUSED;
if (shm_lock)
wake_up (&shm_lock);
kfree_s (shp, sizeof (*shp));
kfree(shp);
return -ENOMEM;
}
......@@ -186,9 +186,9 @@ static void killseg (int id)
shm_swp--;
}
}
kfree_s (shp->shm_pages, numpages * sizeof (ulong));
kfree(shp->shm_pages);
shm_tot -= numpages;
kfree_s (shp, sizeof (*shp));
kfree(shp);
return;
}
......@@ -439,7 +439,7 @@ int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *raddr)
if (!shmd)
return -ENOMEM;
if ((shp != shm_segs[id]) || (shp->shm_perm.seq != shmid / SHMMNI)) {
kfree_s (shmd, sizeof (*shmd));
kfree(shmd);
return -EIDRM;
}
shmd->shm_sgn = (SHM_SWP_TYPE << 1) | (id << SHM_ID_SHIFT) |
......@@ -458,7 +458,7 @@ int sys_shmat (int shmid, char *shmaddr, int shmflg, ulong *raddr)
if ((err = shm_map (shmd, shmflg & SHM_REMAP))) {
if (--shp->shm_nattch <= 0 && shp->shm_perm.mode & SHM_DEST)
killseg(id);
kfree_s (shmd, sizeof (*shmd));
kfree(shmd);
return err;
}
......@@ -497,7 +497,7 @@ static void detach (struct shm_desc **shmdp)
found:
unmap_page_range (shmd->start, shp->shm_segsz); /* sleeps */
kfree_s (shmd, sizeof (*shmd));
kfree(shmd);
shp->shm_lpid = current->pid;
shp->shm_dtime = CURRENT_TIME;
if (--shp->shm_nattch <= 0 && shp->shm_perm.mode & SHM_DEST)
......@@ -550,7 +550,7 @@ int shm_fork (struct task_struct *p1, struct task_struct *p2)
if (!tmp) {
while (new_desc) {
tmp = new_desc->task_next;
kfree_s (new_desc, sizeof (*new_desc));
kfree(new_desc);
new_desc = tmp;
}
free_page_tables (p2);
......
......@@ -222,7 +222,7 @@ asmlinkage void schedule(void)
++current->counter;
}
#endif
c = -1;
c = -1000;
next = p = &init_task;
for (;;) {
if ((p = p->next_task) == &init_task)
......@@ -235,7 +235,8 @@ asmlinkage void schedule(void)
for_each_task(p)
p->counter = (p->counter >> 1) + p->priority;
}
if(current != next)
if (current == next)
return;
kstat.context_swtch++;
switch_to(next);
/* Now maybe reload the debug registers */
......@@ -634,8 +635,8 @@ static void do_timer(struct pt_regs * regs)
}
#endif
}
if (current == task[0] || (--current->counter)<=0) {
current->counter=0;
if (current != task[0] && 0 > --current->counter) {
current->counter = 0;
need_resched = 1;
}
/* Update ITIMER_PROF for the current task */
......
......@@ -35,6 +35,23 @@ asmlinkage int sys_ni_syscall(void)
return -EINVAL;
}
asmlinkage int sys_idle(void)
{
int i;
/* Map out the low memory: it's no longer needed */
for (i = 0 ; i < 768 ; i++)
swapper_pg_dir[i] = 0;
/* endless idle loop with no priority at all */
current->counter = -100;
for (;;) {
if (!need_resched)
__asm__("hlt");
schedule();
}
}
static int proc_sel(struct task_struct *p, int which, int who)
{
switch (which) {
......
......@@ -22,13 +22,14 @@
/*
* virtual flags (16 and 32-bit versions)
*/
#define VFLAGS(regs) (*(unsigned short *)&(current->v86flags))
#define VEFLAGS(regs) (current->v86flags)
#define VFLAGS (*(unsigned short *)&(current->v86flags))
#define VEFLAGS (current->v86flags)
#define set_flags(X,new,mask) \
((X) = ((X) & ~(mask)) | ((new) & (mask)))
#define SAFE_MASK (0xDD5)
#define RETURN_MASK (0xDFF)
asmlinkage struct pt_regs * save_v86_state(struct vm86_regs * regs)
{
......@@ -38,6 +39,7 @@ asmlinkage struct pt_regs * save_v86_state(struct vm86_regs * regs)
printk("no vm86_info: BAD\n");
do_exit(SIGSEGV);
}
set_flags(regs->eflags, VEFLAGS, VIF_MASK | current->v86mask);
memcpy_tofs(&current->vm86_info->regs,regs,sizeof(*regs));
put_fs_long(current->screen_bitmap,&current->vm86_info->screen_bitmap);
tmp = current->tss.esp0;
......@@ -91,9 +93,9 @@ asmlinkage int sys_vm86(struct vm86_struct * v86)
* has set it up safely, so this makes sure interrupt etc flags are
* inherited from protected mode.
*/
current->v86flags = info.regs.eflags;
VEFLAGS = info.regs.eflags;
info.regs.eflags &= SAFE_MASK;
info.regs.eflags |= ~SAFE_MASK & pt_regs->eflags;
info.regs.eflags |= pt_regs->eflags & ~SAFE_MASK;
info.regs.eflags |= VM_MASK;
switch (info.cpu_type) {
......@@ -142,14 +144,14 @@ static inline void return_to_32bit(struct vm86_regs * regs16, int retval)
static inline void set_IF(struct vm86_regs * regs)
{
current->v86flags |= VIF_MASK;
if (current->v86flags & VIP_MASK)
VEFLAGS |= VIF_MASK;
if (VEFLAGS & VIP_MASK)
return_to_32bit(regs, VM86_STI);
}
static inline void clear_IF(struct vm86_regs * regs)
{
current->v86flags &= ~VIF_MASK;
VEFLAGS &= ~VIF_MASK;
}
static inline void clear_TF(struct vm86_regs * regs)
......@@ -159,7 +161,7 @@ static inline void clear_TF(struct vm86_regs * regs)
static inline void set_vflags_long(unsigned long eflags, struct vm86_regs * regs)
{
set_flags(VEFLAGS(regs), eflags, current->v86mask);
set_flags(VEFLAGS, eflags, current->v86mask);
set_flags(regs->eflags, eflags, SAFE_MASK);
if (eflags & IF_MASK)
set_IF(regs);
......@@ -167,7 +169,7 @@ static inline void set_vflags_long(unsigned long eflags, struct vm86_regs * regs
static inline void set_vflags_short(unsigned short flags, struct vm86_regs * regs)
{
set_flags(VFLAGS(regs), flags, current->v86mask);
set_flags(VFLAGS, flags, current->v86mask);
set_flags(regs->eflags, flags, SAFE_MASK);
if (flags & IF_MASK)
set_IF(regs);
......@@ -175,11 +177,19 @@ static inline void set_vflags_short(unsigned short flags, struct vm86_regs * reg
static inline unsigned long get_vflags(struct vm86_regs * regs)
{
unsigned long flags = regs->eflags & SAFE_MASK;
unsigned long flags = regs->eflags & RETURN_MASK;
if (current->v86flags & VIF_MASK)
if (VEFLAGS & VIF_MASK)
flags |= IF_MASK;
return flags | (VEFLAGS(regs) & current->v86mask);
return flags | (VEFLAGS & current->v86mask);
}
static inline int is_revectored(int nr, struct revectored_struct * bitmap)
{
__asm__ __volatile__("btl %2,%%fs:%1\n\tsbbl %0,%0"
:"=r" (nr)
:"m" (*bitmap),"r" (nr));
return nr;
}
/*
......
......@@ -1011,6 +1011,8 @@ void show_mem(void)
show_buffers();
}
extern unsigned long free_area_init(unsigned long, unsigned long);
/*
* paging_init() sets up the page tables - note that the first 4MB are
* already mapped by head.S.
......@@ -1056,7 +1058,7 @@ unsigned long paging_init(unsigned long start_mem, unsigned long end_mem)
}
}
invalidate();
return start_mem;
return free_area_init(start_mem, end_mem);
}
void mem_init(unsigned long start_low_mem,
......@@ -1065,33 +1067,12 @@ void mem_init(unsigned long start_low_mem,
int codepages = 0;
int reservedpages = 0;
int datapages = 0;
unsigned long tmp, mask;
unsigned short * p;
unsigned long tmp;
extern int etext;
cli();
end_mem &= PAGE_MASK;
high_memory = end_mem;
start_mem += 0x0000000f;
start_mem &= ~0x0000000f;
tmp = MAP_NR(end_mem);
mem_map = (unsigned short *) start_mem;
p = mem_map + tmp;
start_mem = (unsigned long) p;
while (p > mem_map)
*--p = MAP_PAGE_RESERVED;
/* set up the free-area data structures */
for (mask = PAGE_MASK, tmp = 0 ; tmp < NR_MEM_LISTS ; tmp++, mask <<= 1) {
unsigned long bitmap_size;
free_area_list[tmp].prev = free_area_list[tmp].next = &free_area_list[tmp];
end_mem = (end_mem + ~mask) & mask;
bitmap_size = end_mem >> (PAGE_SHIFT + tmp);
bitmap_size = (bitmap_size + 7) >> 3;
free_area_map[tmp] = (unsigned char *) start_mem;
memset((void *) start_mem, 0, bitmap_size);
start_mem += bitmap_size;
}
/* mark usable pages in the mem_map[] */
start_low_mem = PAGE_ALIGN(start_low_mem);
......
......@@ -263,17 +263,6 @@ static inline int try_to_swap_out(unsigned long * table_ptr)
return 1 + mem_map[MAP_NR(page)];
}
/*
* sys_idle() does nothing much: it just searches for likely candidates for
* swapping out or forgetting about. This speeds up the search when we
* actually have to swap.
*/
asmlinkage int sys_idle(void)
{
need_resched = 1;
return 0;
}
/*
* A new implementation of swap_out(). We do not swap complete processes,
* but only a small number of blocks, before we continue with the next
......@@ -896,3 +885,34 @@ void si_swapinfo(struct sysinfo *val)
val->totalswap <<= PAGE_SHIFT;
return;
}
/*
* set up the free-area data structures:
* - mark all pages MAP_PAGE_RESERVED
* - mark all memory queues empty
* - clear the memory bitmaps
*/
unsigned long free_area_init(unsigned long start_mem, unsigned long end_mem)
{
unsigned short * p;
unsigned long mask = PAGE_MASK;
int i;
mem_map = (unsigned short *) start_mem;
p = mem_map + MAP_NR(end_mem);
start_mem = (unsigned long) p;
while (p > mem_map)
*--p = MAP_PAGE_RESERVED;
for (i = 0 ; i < NR_MEM_LISTS ; i++, mask <<= 1) {
unsigned long bitmap_size;
free_area_list[i].prev = free_area_list[i].next = &free_area_list[i];
end_mem = (end_mem + ~mask) & mask;
bitmap_size = end_mem >> (PAGE_SHIFT + i);
bitmap_size = (bitmap_size + 7) >> 3;
free_area_map[i] = (unsigned char *) start_mem;
memset((void *) start_mem, 0, bitmap_size);
start_mem += bitmap_size;
}
return start_mem;
}
......@@ -186,6 +186,7 @@ void icmp_send(struct sk_buff *skb_in, int type, int code, struct device *dev)
icmp_statistics.IcmpOutErrors++;
return;
}
skb->free = 1;
/*
* Build Layer 2-3 headers for message back to source.
......
......@@ -387,7 +387,8 @@ void kfree_skb(struct sk_buff *skb, int rw)
{
if (skb == NULL)
{
printk("kfree_skb: skb = NULL\n");
printk("kfree_skb: skb = NULL (from %08lx)\n",
((unsigned long *) &skb)[-1]);
return;
}
IS_SKB(skb);
......@@ -397,9 +398,11 @@ void kfree_skb(struct sk_buff *skb, int rw)
return;
}
if (skb->free == 2)
printk("Warning: kfree_skb passed an skb that nobody set the free flag on!\n");
printk("Warning: kfree_skb passed an skb that nobody set the free flag on! (from %08lx)\n",
((unsigned long *) &skb)[-1]);
if (skb->next)
printk("Warning: kfree_skb passed an skb still on a list.\n");
printk("Warning: kfree_skb passed an skb still on a list (from %08lx).\n",
((unsigned long *) &skb)[-1]);
if (skb->sk)
{
if(skb->sk->prot!=NULL)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment