Commit e9e7d7fa authored by Linus Torvalds's avatar Linus Torvalds

v2.4.7.8 -> v2.4.8

  - Rik van Riel: free up swap cache on swapin when swap is full..
  - Robert Love: merge emu10k sound driver.  This one is better ("Yeah,
  you actually get sound out of it")
  - Jeremy Linton: swapin/swapoff race condition fix
parent 6c4b34bf
VERSION = 2 VERSION = 2
PATCHLEVEL = 4 PATCHLEVEL = 4
SUBLEVEL = 8 SUBLEVEL = 8
EXTRAVERSION =-pre8 EXTRAVERSION =
KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION) KERNELRELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
......
...@@ -73,7 +73,7 @@ subdir-$(CONFIG_SOUND_EMU10K1) += emu10k1 ...@@ -73,7 +73,7 @@ subdir-$(CONFIG_SOUND_EMU10K1) += emu10k1
subdir-$(CONFIG_SOUND_CS4281) += cs4281 subdir-$(CONFIG_SOUND_CS4281) += cs4281
ifeq ($(CONFIG_SOUND_EMU10K1),y) ifeq ($(CONFIG_SOUND_EMU10K1),y)
obj-y += emu10k1/emu10k1.o obj-y += ac97_codec.o emu10k1/emu10k1.o
endif endif
ifeq ($(CONFIG_SOUND_CS4281),y) ifeq ($(CONFIG_SOUND_CS4281),y)
......
...@@ -39,22 +39,6 @@ ...@@ -39,22 +39,6 @@
#include <linux/types.h> #include <linux/types.h>
/* ------------------- DEFINES -------------------- */
#define CMD_WRITEFN0 0x0
#define CMD_READFN0 0x1
#define CMD_WRITEPTR 0x2
#define CMD_READPTR 0x3
#define CMD_SETRECSRC 0x4
#define CMD_GETRECSRC 0x5
#define CMD_GETVOICEPARAM 0x6
#define CMD_SETVOICEPARAM 0x7
struct mixer_private_ioctl {
u32 cmd;
u32 val[10];
};
/************************************************************************************************/ /************************************************************************************************/
/* PCI function 0 registers, address = <val> + PCIBASE0 */ /* PCI function 0 registers, address = <val> + PCIBASE0 */
/************************************************************************************************/ /************************************************************************************************/
...@@ -171,7 +155,10 @@ struct mixer_private_ioctl { ...@@ -171,7 +155,10 @@ struct mixer_private_ioctl {
#define HCFG_CODECFORMAT_I2S 0x00010000 /* I2S CODEC format -- Secondary (Rear) Output */ #define HCFG_CODECFORMAT_I2S 0x00010000 /* I2S CODEC format -- Secondary (Rear) Output */
#define HCFG_GPINPUT0 0x00004000 /* External pin112 */ #define HCFG_GPINPUT0 0x00004000 /* External pin112 */
#define HCFG_GPINPUT1 0x00002000 /* External pin110 */ #define HCFG_GPINPUT1 0x00002000 /* External pin110 */
#define HCFG_GPOUTPUT_MASK 0x00001c00 /* External pins which may be controlled */ #define HCFG_GPOUTPUT_MASK 0x00001c00 /* External pins which may be controlled */
#define HCFG_GPOUT0 0x00001000 /* set to enable digital out on 5.1 cards */
#define HCFG_JOYENABLE 0x00000200 /* Internal joystick enable */ #define HCFG_JOYENABLE 0x00000200 /* Internal joystick enable */
#define HCFG_PHASETRACKENABLE 0x00000100 /* Phase tracking enable */ #define HCFG_PHASETRACKENABLE 0x00000100 /* Phase tracking enable */
/* 1 = Force all 3 async digital inputs to use */ /* 1 = Force all 3 async digital inputs to use */
...@@ -224,54 +211,6 @@ struct mixer_private_ioctl { ...@@ -224,54 +211,6 @@ struct mixer_private_ioctl {
#define AC97ADDRESS_READY 0x80 /* Read-only bit, reflects CODEC READY signal */ #define AC97ADDRESS_READY 0x80 /* Read-only bit, reflects CODEC READY signal */
#define AC97ADDRESS_ADDRESS 0x7f /* Address of indexed AC97 register */ #define AC97ADDRESS_ADDRESS 0x7f /* Address of indexed AC97 register */
/************************************************************************************************/
/* PCI function 1 registers, address = <val> + PCIBASE1 */
/************************************************************************************************/
#define JOYSTICK1 0x00 /* Analog joystick port register */
#define JOYSTICK2 0x01 /* Analog joystick port register */
#define JOYSTICK3 0x02 /* Analog joystick port register */
#define JOYSTICK4 0x03 /* Analog joystick port register */
#define JOYSTICK5 0x04 /* Analog joystick port register */
#define JOYSTICK6 0x05 /* Analog joystick port register */
#define JOYSTICK7 0x06 /* Analog joystick port register */
#define JOYSTICK8 0x07 /* Analog joystick port register */
/* When writing, any write causes JOYSTICK_COMPARATOR output enable to be pulsed on write. */
/* When reading, use these bitfields: */
#define JOYSTICK_BUTTONS 0x0f /* Joystick button data */
#define JOYSTICK_COMPARATOR 0xf0 /* Joystick comparator data */
/********************************************************************************************************/
/* AC97 pointer-offset register set, accessed through the AC97ADDRESS and AC97DATA registers */
/********************************************************************************************************/
#define AC97_RESET 0x00
#define AC97_MASTERVOLUME 0x02 /* Master volume */
#define AC97_HEADPHONEVOLUME 0x04 /* Headphone volume */
#define AC97_MASTERVOLUMEMONO 0x06 /* Mast volume mono */
#define AC97_MASTERTONE 0x08
#define AC97_PCBEEPVOLUME 0x0a /* PC speaker system beep volume */
#define AC97_PHONEVOLUME 0x0c
#define AC97_MICVOLUME 0x0e
#define AC97_LINEINVOLUME 0x10
#define AC97_CDVOLUME 0x12
#define AC97_VIDEOVOLUME 0x14
#define AC97_AUXVOLUME 0x16
#define AC97_PCMOUTVOLUME 0x18
#define AC97_RECORDSELECT 0x1a
#define AC97_RECORDGAIN 0x1c
#define AC97_RECORDGAINMIC 0x1e
#define AC97_GENERALPURPOSE 0x20
#define AC97_3DCONTROL 0x22
#define AC97_MODEMRATE 0x24
#define AC97_POWERDOWN 0x26
#define AC97_VENDORID1 0x7c
#define AC97_VENDORID2 0x7e
#define AC97_ZVIDEOVOLUME 0xec
#define AC97_AC3VOLUME 0xed
/********************************************************************************************************/ /********************************************************************************************************/
/* Emu10k1 pointer-offset register set, accessed through the PTR and DATA registers */ /* Emu10k1 pointer-offset register set, accessed through the PTR and DATA registers */
/********************************************************************************************************/ /********************************************************************************************************/
...@@ -568,6 +507,16 @@ struct mixer_private_ioctl { ...@@ -568,6 +507,16 @@ struct mixer_private_ioctl {
#define DBG 0x52 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */ #define DBG 0x52 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
/* definitions for debug register - taken from the alsa drivers */
#define DBG_ZC 0x80000000 /* zero tram counter */
#define DBG_SATURATION_OCCURED 0x02000000 /* saturation control */
#define DBG_SATURATION_ADDR 0x01ff0000 /* saturation address */
#define DBG_SINGLE_STEP 0x00008000 /* single step mode */
#define DBG_STEP 0x00004000 /* start single step */
#define DBG_CONDITION_CODE 0x00003e00 /* condition code */
#define DBG_SINGLE_STEP_ADDR 0x000001ff /* single step address */
#define REG53 0x53 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */ #define REG53 0x53 /* DO NOT PROGRAM THIS REGISTER!!! MAY DESTROY CHIP */
#define SPCS0 0x54 /* SPDIF output Channel Status 0 register */ #define SPCS0 0x54 /* SPDIF output Channel Status 0 register */
...@@ -616,6 +565,10 @@ struct mixer_private_ioctl { ...@@ -616,6 +565,10 @@ struct mixer_private_ioctl {
#define SPBYPASS 0x5e /* SPDIF BYPASS mode register */ #define SPBYPASS 0x5e /* SPDIF BYPASS mode register */
#define SPBYPASS_ENABLE 0x00000001 /* Enable SPDIF bypass mode */ #define SPBYPASS_ENABLE 0x00000001 /* Enable SPDIF bypass mode */
#define AC97SLOT 0x5f /* additional AC97 slots enable bits */
#define AC97SLOT_CNTR 0x10 /* Center enable */
#define AC97SLOT_LFE 0x20 /* LFE enable */
#define CDSRCS 0x60 /* CD-ROM Sample Rate Converter status register */ #define CDSRCS 0x60 /* CD-ROM Sample Rate Converter status register */
#define GPSRCS 0x61 /* General Purpose SPDIF sample rate cvt status */ #define GPSRCS 0x61 /* General Purpose SPDIF sample rate cvt status */
......
...@@ -5,8 +5,9 @@ ...@@ -5,8 +5,9 @@
O_TARGET := emu10k1.o O_TARGET := emu10k1.o
obj-y := audio.o cardmi.o cardmo.o cardwi.o cardwo.o ecard.o \ obj-y := audio.o cardmi.o cardmo.o cardwi.o cardwo.o ecard.o \
emuadxmg.o hwaccess.o irqmgr.o main.o midi.o mixer.o \ efxmgr.o emuadxmg.o hwaccess.o irqmgr.o joystick.o \
recmgr.o timer.o voicemgr.o main.o midi.o mixer.o passthrough.o recmgr.o timer.o \
voicemgr.o
obj-m := $(O_TARGET) obj-m := $(O_TARGET)
ifdef DEBUG ifdef DEBUG
......
...@@ -48,6 +48,8 @@ ...@@ -48,6 +48,8 @@
#include "recmgr.h" #include "recmgr.h"
#include "irqmgr.h" #include "irqmgr.h"
#include "audio.h" #include "audio.h"
#include "8010.h"
#include "passthrough.h"
static void calculate_ofrag(struct woinst *); static void calculate_ofrag(struct woinst *);
static void calculate_ifrag(struct wiinst *); static void calculate_ifrag(struct wiinst *);
...@@ -167,6 +169,18 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t ...@@ -167,6 +169,18 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t
return -ENXIO; return -ENXIO;
} }
if (woinst->format.passthrough) {
int r;
woinst->buffer.ossfragshift = PT_BLOCKSIZE_LOG2;
woinst->buffer.numfrags = PT_BLOCKCOUNT;
calculate_ofrag(woinst);
r = emu10k1_pt_write(file, buffer, count);
spin_unlock_irqrestore(&woinst->lock, flags);
return r;
}
if (woinst->state == WAVE_STATE_CLOSED) { if (woinst->state == WAVE_STATE_CLOSED) {
calculate_ofrag(woinst); calculate_ofrag(woinst);
...@@ -188,6 +202,11 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t ...@@ -188,6 +202,11 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
ret = 0; ret = 0;
if (count % woinst->format.bytespersample)
return -EINVAL;
count /= woinst->num_voices;
while (count > 0) { while (count > 0) {
u32 bytestocopy; u32 bytestocopy;
...@@ -206,8 +225,8 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t ...@@ -206,8 +225,8 @@ static ssize_t emu10k1_audio_write(struct file *file, const char *buffer, size_t
emu10k1_waveout_xferdata(woinst, (u8 *) buffer, &bytestocopy); emu10k1_waveout_xferdata(woinst, (u8 *) buffer, &bytestocopy);
count -= bytestocopy; count -= bytestocopy;
buffer += bytestocopy; buffer += bytestocopy * woinst->num_voices;
ret += bytestocopy; ret += bytestocopy * woinst->num_voices;
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
woinst->total_copied += bytestocopy; woinst->total_copied += bytestocopy;
...@@ -267,14 +286,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -267,14 +286,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
if (woinst->state & WAVE_STATE_OPEN) { if (woinst->state & WAVE_STATE_OPEN) {
if (woinst->mmapped) {
int i;
/* Undo marking the pages as reserved */
for (i = 0; i < woinst->buffer.pages; i++)
mem_map_unreserve(virt_to_page(woinst->buffer.addr[i]));
}
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
} }
...@@ -289,8 +300,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -289,8 +300,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
if (file->f_mode & FMODE_READ) { if (file->f_mode & FMODE_READ) {
spin_lock_irqsave(&wiinst->lock, flags); spin_lock_irqsave(&wiinst->lock, flags);
if (wiinst->state & WAVE_STATE_OPEN) if (wiinst->state & WAVE_STATE_OPEN) {
emu10k1_wavein_close(wave_dev); emu10k1_wavein_close(wave_dev);
}
wiinst->mmapped = 0; wiinst->mmapped = 0;
wiinst->total_recorded = 0; wiinst->total_recorded = 0;
...@@ -316,15 +328,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -316,15 +328,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
interruptible_sleep_on(&woinst->wait_queue); interruptible_sleep_on(&woinst->wait_queue);
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
} }
if (woinst->mmapped) {
int i;
/* Undo marking the pages as reserved */
for (i = 0; i < woinst->buffer.pages; i++)
mem_map_unreserve(virt_to_page(woinst->buffer.addr[i]));
}
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
} }
...@@ -339,8 +342,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -339,8 +342,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
if (file->f_mode & FMODE_READ) { if (file->f_mode & FMODE_READ) {
spin_lock_irqsave(&wiinst->lock, flags); spin_lock_irqsave(&wiinst->lock, flags);
if (wiinst->state & WAVE_STATE_OPEN) if (wiinst->state & WAVE_STATE_OPEN) {
emu10k1_wavein_close(wave_dev); emu10k1_wavein_close(wave_dev);
}
wiinst->mmapped = 0; wiinst->mmapped = 0;
wiinst->total_recorded = 0; wiinst->total_recorded = 0;
...@@ -490,7 +494,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -490,7 +494,6 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
return -EINVAL; return -EINVAL;
} }
val = wiinst->format.channels; val = wiinst->format.channels;
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
...@@ -532,9 +535,13 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -532,9 +535,13 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
if (file->f_mode & FMODE_READ) if (file->f_mode & FMODE_READ)
val = AFMT_S16_LE; val = AFMT_S16_LE;
else if (file->f_mode & FMODE_WRITE) else if (file->f_mode & FMODE_WRITE) {
val = AFMT_S16_LE | AFMT_U8; val = AFMT_S16_LE | AFMT_U8;
if (emu10k1_find_control_gpr(&wave_dev->card->mgr,
wave_dev->card->pt.patch_name,
wave_dev->card->pt.enable_gpr_name) >= 0)
val |= AFMT_AC3;
}
return put_user(val, (int *) arg); return put_user(val, (int *) arg);
case SNDCTL_DSP_SETFMT: /* Same as SNDCTL_DSP_SAMPLESIZE */ case SNDCTL_DSP_SETFMT: /* Same as SNDCTL_DSP_SAMPLESIZE */
...@@ -552,17 +559,17 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -552,17 +559,17 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_lock_irqsave(&wiinst->lock, flags); spin_lock_irqsave(&wiinst->lock, flags);
format = wiinst->format; format = wiinst->format;
format.bitsperchannel = val; format.id = val;
if (emu10k1_wavein_setformat(wave_dev, &format) < 0) { if (emu10k1_wavein_setformat(wave_dev, &format) < 0) {
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
return -EINVAL; return -EINVAL;
} }
val = wiinst->format.bitsperchannel; val = wiinst->format.id;
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
DPD(2, "set recording sample size -> %d\n", val); DPD(2, "set recording format -> %d\n", val);
} }
if (file->f_mode & FMODE_WRITE) { if (file->f_mode & FMODE_WRITE) {
...@@ -571,27 +578,27 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -571,27 +578,27 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
format = woinst->format; format = woinst->format;
format.bitsperchannel = val; format.id = val;
if (emu10k1_waveout_setformat(wave_dev, &format) < 0) { if (emu10k1_waveout_setformat(wave_dev, &format) < 0) {
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
return -EINVAL; return -EINVAL;
} }
val = woinst->format.bitsperchannel; val = woinst->format.id;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
DPD(2, "set playback sample size -> %d\n", val); DPD(2, "set playback format -> %d\n", val);
} }
return put_user((val == 16) ? AFMT_S16_LE : AFMT_U8, (int *) arg); return put_user(val, (int *) arg);
} else { } else {
if (file->f_mode & FMODE_READ) if (file->f_mode & FMODE_READ)
val = wiinst->format.bitsperchannel; val = wiinst->format.id;
else if (file->f_mode & FMODE_WRITE) else if (file->f_mode & FMODE_WRITE)
val = woinst->format.bitsperchannel; val = woinst->format.id;
return put_user((val == 16) ? AFMT_S16_LE : AFMT_U8, (int *) arg); return put_user(val, (int *) arg);
} }
break; break;
...@@ -602,7 +609,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -602,7 +609,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
else if (file->f_mode & FMODE_WRITE) else if (file->f_mode & FMODE_WRITE)
val = woinst->format.bitsperchannel; val = woinst->format.bitsperchannel;
return put_user((val == 16) ? AFMT_S16_LE : AFMT_U8, (int *) arg); return put_user(val, (int *) arg);
case SOUND_PCM_READ_RATE: case SOUND_PCM_READ_RATE:
...@@ -705,9 +712,10 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -705,9 +712,10 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
} }
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
info.fragstotal = woinst->buffer.numfrags; info.bytes *= woinst->num_voices;
info.fragments = info.bytes / woinst->buffer.fragment_size; info.fragsize = woinst->buffer.fragment_size * woinst->num_voices;
info.fragsize = woinst->buffer.fragment_size; info.fragstotal = woinst->buffer.numfrags * woinst->num_voices;
info.fragments = info.bytes / info.fragsize;
if (copy_to_user((int *) arg, &info, sizeof(info))) if (copy_to_user((int *) arg, &info, sizeof(info)))
return -EFAULT; return -EFAULT;
...@@ -763,6 +771,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -763,6 +771,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
} else } else
val = 0; val = 0;
val *= woinst->num_voices;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
return put_user(val, (int *) arg); return put_user(val, (int *) arg);
...@@ -790,6 +799,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -790,6 +799,9 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
cinfo.blocks = 0; cinfo.blocks = 0;
} }
if(wiinst->mmapped)
wiinst->buffer.bytestocopy %= wiinst->buffer.fragment_size;
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
if (copy_to_user((void *) arg, &cinfo, sizeof(cinfo))) if (copy_to_user((void *) arg, &cinfo, sizeof(cinfo)))
...@@ -808,19 +820,31 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -808,19 +820,31 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
if (woinst->state & WAVE_STATE_OPEN) { if (woinst->state & WAVE_STATE_OPEN ||
(woinst->format.passthrough && wave_dev->card->pt.state)) {
int num_fragments;
if (woinst->format.passthrough) {
emu10k1_pt_waveout_update(wave_dev);
cinfo.bytes = woinst->total_played;
} else {
emu10k1_waveout_update(woinst); emu10k1_waveout_update(woinst);
cinfo.bytes = woinst->total_played;
}
cinfo.ptr = woinst->buffer.hw_pos; cinfo.ptr = woinst->buffer.hw_pos;
cinfo.bytes = cinfo.ptr + woinst->total_played - woinst->total_played % woinst->buffer.size; num_fragments = cinfo.bytes / woinst->buffer.fragment_size;
cinfo.blocks = cinfo.bytes / woinst->buffer.fragment_size - woinst->blocks; cinfo.blocks = num_fragments - woinst->blocks;
woinst->blocks = cinfo.bytes / woinst->buffer.fragment_size; woinst->blocks = num_fragments;
cinfo.bytes *= woinst->num_voices;
cinfo.ptr *= woinst->num_voices;
} else { } else {
cinfo.ptr = 0; cinfo.ptr = 0;
cinfo.bytes = 0; cinfo.bytes = 0;
cinfo.blocks = 0; cinfo.blocks = 0;
} }
if(woinst->mmapped)
woinst->buffer.bytestocopy %= woinst->buffer.fragment_size; if (woinst->mmapped)
woinst->buffer.free_bytes %= woinst->buffer.fragment_size;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
...@@ -836,7 +860,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -836,7 +860,7 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
calculate_ofrag(woinst); calculate_ofrag(woinst);
val = woinst->buffer.fragment_size; val = woinst->buffer.fragment_size * woinst->num_voices;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
} }
...@@ -878,13 +902,14 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -878,13 +902,14 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
if (get_user(val, (int *) arg)) if (get_user(val, (int *) arg))
return -EFAULT; return -EFAULT;
DPD(2, "val is 0x%x\n", val); DPD(2, "val is %#x\n", val);
if (val == 0) if (val == 0)
return -EIO; return -EIO;
if (file->f_mode & FMODE_WRITE) { if (file->f_mode & FMODE_WRITE) {
if (woinst->state & WAVE_STATE_OPEN) /* digital pass-through fragment count and size are fixed values */
if (woinst->state & WAVE_STATE_OPEN || woinst->format.passthrough)
return -EINVAL; /* too late to change */ return -EINVAL; /* too late to change */
woinst->buffer.ossfragshift = val & 0xffff; woinst->buffer.ossfragshift = val & 0xffff;
...@@ -905,118 +930,167 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -905,118 +930,167 @@ static int emu10k1_audio_ioctl(struct inode *inode, struct file *file, unsigned
{ {
copr_buffer *buf; copr_buffer *buf;
u32 i; u32 i;
int ret = -EFAULT;
DPF(2, "SNDCTL_COPR_LOAD:\n"); DPF(4, "SNDCTL_COPR_LOAD:\n");
buf = kmalloc(sizeof(copr_buffer), GFP_KERNEL); buf = kmalloc(sizeof(copr_buffer), GFP_KERNEL);
if(buf == NULL) if (!buf)
return -ENOMEM; return -ENOMEM;
if (copy_from_user(buf, (copr_buffer *) arg, sizeof(buf))) if (copy_from_user(buf, (copr_buffer *) arg, sizeof(copr_buffer))) {
goto fail; kfree (buf);
return -EFAULT;
if ((buf->command != 1) && (buf->command != 2))
{
ret = -EINVAL;
goto fail;
} }
if ((buf->offs < 0x100) if ((buf->command != CMD_READ) && (buf->command != CMD_WRITE)) {
|| (buf->offs < 0x000) kfree (buf);
|| (buf->offs + buf->len > 0x800) || (buf->len > 1000)) return -EINVAL;
{ }
ret = -EINVAL; #ifdef DBGEMU
goto fail; if ( (buf->offs < 0) || (buf->offs + buf->len > 0x800) || (buf->len > 1000)) {
#else
if ( ((buf->offs < 0x100 ) || (buf->offs + buf->len > 0x800) || (buf->len > 1000))
&& !( ( buf->offs == DBG) && (buf->len ==1) )){
#endif
kfree(buf);
return -EINVAL;
} }
if (buf->command == 1) {
if (buf->command == CMD_READ) {
for (i = 0; i < buf->len; i++) for (i = 0; i < buf->len; i++)
((u32 *) buf->data)[i] = sblive_readptr(wave_dev->card, buf->offs + i, 0); ((u32 *) buf->data)[i] = sblive_readptr(wave_dev->card, buf->offs + i, 0);
if (copy_to_user((copr_buffer *) arg, buf, sizeof(buf))) if (copy_to_user((copr_buffer *) arg, buf, sizeof(copr_buffer))) {
goto fail; kfree(buf);
return -EFAULT;
}
} else { } else {
for (i = 0; i < buf->len; i++) for (i = 0; i < buf->len; i++)
sblive_writeptr(wave_dev->card, buf->offs + i, 0, ((u32 *) buf->data)[i]); sblive_writeptr(wave_dev->card, buf->offs + i, 0, ((u32 *) buf->data)[i]);
} }
ret = 0;
fail: kfree (buf);
kfree(buf); break;
return ret;
} }
default: /* Default is unrecognized command */ default: /* Default is unrecognized command */
DPD(2, "default: 0x%x\n", cmd); DPD(2, "default: %#x\n", cmd);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
} }
static struct page *emu10k1_mm_nopage (struct vm_area_struct * vma, unsigned long address, int write_access)
{
struct emu10k1_wavedevice *wave_dev = vma->vm_private_data;
struct woinst *woinst = wave_dev->woinst;
struct wiinst *wiinst = wave_dev->wiinst;
struct page *dmapage;
unsigned long pgoff;
int rd, wr;
if (address > vma->vm_end) {
DPF(2, "EXIT, returning NOPAGE_SIGBUS\n");
return NOPAGE_SIGBUS; /* Disallow mremap */
}
pgoff = vma->vm_pgoff + ((address - vma->vm_start) >> PAGE_SHIFT);
if (woinst != NULL)
wr = woinst->mmapped;
else
wr = 0;
if (wiinst != NULL)
rd = wiinst->mmapped;
else
rd = 0;
/* if full-duplex (read+write) and we have two sets of bufs,
* then the playback buffers come first, sez soundcard.c */
if (wr) {
if (pgoff >= woinst->buffer.pages) {
pgoff -= woinst->buffer.pages;
dmapage = virt_to_page ((u8 *) wiinst->buffer.addr + pgoff * PAGE_SIZE);
} else
dmapage = virt_to_page (woinst->buffer.mem[0].addr[pgoff]);
} else {
dmapage = virt_to_page ((u8 *) wiinst->buffer.addr + pgoff * PAGE_SIZE);
}
get_page (dmapage);
return dmapage;
}
struct vm_operations_struct emu10k1_mm_ops = {
nopage: emu10k1_mm_nopage,
};
static int emu10k1_audio_mmap(struct file *file, struct vm_area_struct *vma) static int emu10k1_audio_mmap(struct file *file, struct vm_area_struct *vma)
{ {
struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data; struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
unsigned long maxsize, size, offset, pgoffset;
struct woinst *woinst = NULL;
struct wiinst *wiinst = NULL;
unsigned long flags;
DPF(2, "emu10k1_audio_mmap()\n"); DPF(2, "emu10k1_audio_mmap()\n");
if (vma_get_pgoff(vma) != 0) maxsize = 0;
return -ENXIO;
lock_kernel();
if (vma->vm_flags & VM_WRITE) { if (vma->vm_flags & VM_WRITE) {
struct woinst *woinst = wave_dev->woinst; woinst = wave_dev->woinst;
u32 size;
unsigned long flags;
int i;
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
if (woinst->state == WAVE_STATE_CLOSED) { /* No m'mapping possible for multichannel */
calculate_ofrag(woinst); if (woinst->num_voices > 1) {
if (emu10k1_waveout_open(wave_dev) < 0) {
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
ERROR();
unlock_kernel();
return -EINVAL; return -EINVAL;
} }
/* Now mark the pages as reserved, otherwise remap_page_range doesn't do what we want */ if (woinst->state == WAVE_STATE_CLOSED) {
for (i = 0; i < woinst->buffer.pages; i++) calculate_ofrag(woinst);
mem_map_reserve(virt_to_page(woinst->buffer.addr[i]));
}
size = vma->vm_end - vma->vm_start;
if (size > (PAGE_SIZE * woinst->buffer.pages)) { if (emu10k1_waveout_open(wave_dev) < 0) {
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
unlock_kernel(); ERROR();
return -EINVAL; return -EINVAL;
} }
for (i = 0; i < woinst->buffer.pages; i++) {
if (remap_page_range(vma->vm_start + (i * PAGE_SIZE), virt_to_phys(woinst->buffer.addr[i]), PAGE_SIZE, vma->vm_page_prot)) {
spin_unlock_irqrestore(&woinst->lock, flags);
unlock_kernel();
return -EAGAIN;
}
} }
woinst->mmapped = 1; woinst->mmapped = 1;
maxsize += woinst->buffer.pages * PAGE_SIZE;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
} }
if (vma->vm_flags & VM_READ) { if (vma->vm_flags & VM_READ) {
struct wiinst *wiinst = wave_dev->wiinst; wiinst = wave_dev->wiinst;
unsigned long flags;
spin_lock_irqsave(&wiinst->lock, flags); spin_lock_irqsave(&wiinst->lock, flags);
if (wiinst->state == WAVE_STATE_CLOSED) {
calculate_ifrag(wiinst);
if (emu10k1_wavein_open(wave_dev) < 0) {
spin_unlock_irqrestore(&wiinst->lock, flags);
ERROR();
return -EINVAL;
}
}
wiinst->mmapped = 1; wiinst->mmapped = 1;
maxsize += wiinst->buffer.pages * PAGE_SIZE;
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
} }
unlock_kernel(); size = vma->vm_end - vma->vm_start;
pgoffset = vma->vm_pgoff;
offset = pgoffset << PAGE_SHIFT;
if (offset + size > maxsize)
return -EINVAL;
vma->vm_flags |= VM_RESERVED;
vma->vm_ops = &emu10k1_mm_ops;
vma->vm_private_data = wave_dev;
return 0; return 0;
} }
...@@ -1024,7 +1098,7 @@ static int emu10k1_audio_mmap(struct file *file, struct vm_area_struct *vma) ...@@ -1024,7 +1098,7 @@ static int emu10k1_audio_mmap(struct file *file, struct vm_area_struct *vma)
static int emu10k1_audio_open(struct inode *inode, struct file *file) static int emu10k1_audio_open(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = MINOR(inode->i_rdev);
struct emu10k1_card *card=NULL; struct emu10k1_card *card = NULL;
struct list_head *entry; struct list_head *entry;
struct emu10k1_wavedevice *wave_dev; struct emu10k1_wavedevice *wave_dev;
...@@ -1035,17 +1109,19 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1035,17 +1109,19 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
list_for_each(entry, &emu10k1_devs) { list_for_each(entry, &emu10k1_devs) {
card = list_entry(entry, struct emu10k1_card, list); card = list_entry(entry, struct emu10k1_card, list);
if (!((card->audio_num ^ minor) & ~0xf) || !((card->audio1_num ^ minor) & ~0xf)) if (!((card->audio_dev ^ minor) & ~0xf) || !((card->audio_dev1 ^ minor) & ~0xf))
break; goto match;
} }
if (entry == &emu10k1_devs)
return -ENODEV; return -ENODEV;
if ((wave_dev = (struct emu10k1_wavedevice *) match:
kmalloc(sizeof(struct emu10k1_wavedevice), GFP_KERNEL)) == NULL) {
wave_dev = (struct emu10k1_wavedevice *) kmalloc(sizeof(struct emu10k1_wavedevice), GFP_KERNEL);
if (wave_dev == NULL) {
ERROR(); ERROR();
return -EINVAL; return -ENOMEM;
} }
wave_dev->card = card; wave_dev->card = card;
...@@ -1067,16 +1143,19 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1067,16 +1143,19 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
switch (wiinst->recsrc) { switch (wiinst->recsrc) {
case WAVERECORD_AC97: case WAVERECORD_AC97:
wiinst->format.id = AFMT_S16_LE;
wiinst->format.samplingrate = 8000; wiinst->format.samplingrate = 8000;
wiinst->format.bitsperchannel = 16; wiinst->format.bitsperchannel = 16;
wiinst->format.channels = 1; wiinst->format.channels = 1;
break; break;
case WAVERECORD_MIC: case WAVERECORD_MIC:
wiinst->format.id = AFMT_S16_LE;
wiinst->format.samplingrate = 8000; wiinst->format.samplingrate = 8000;
wiinst->format.bitsperchannel = 16; wiinst->format.bitsperchannel = 16;
wiinst->format.channels = 1; wiinst->format.channels = 1;
break; break;
case WAVERECORD_FX: case WAVERECORD_FX:
wiinst->format.id = AFMT_S16_LE;
wiinst->format.samplingrate = 48000; wiinst->format.samplingrate = 48000;
wiinst->format.bitsperchannel = 16; wiinst->format.bitsperchannel = 16;
wiinst->format.channels = hweight32(wiinst->fxwc); wiinst->format.channels = hweight32(wiinst->fxwc);
...@@ -1105,6 +1184,7 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1105,6 +1184,7 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
if (file->f_mode & FMODE_WRITE) { if (file->f_mode & FMODE_WRITE) {
struct woinst *woinst; struct woinst *woinst;
int i;
if ((woinst = (struct woinst *) kmalloc(sizeof(struct woinst), GFP_KERNEL)) == NULL) { if ((woinst = (struct woinst *) kmalloc(sizeof(struct woinst), GFP_KERNEL)) == NULL) {
ERROR(); ERROR();
...@@ -1114,6 +1194,7 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1114,6 +1194,7 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
if (wave_dev->wiinst != NULL) { if (wave_dev->wiinst != NULL) {
woinst->format = wave_dev->wiinst->format; woinst->format = wave_dev->wiinst->format;
} else { } else {
woinst->format.id = AFMT_U8;
woinst->format.samplingrate = 8000; woinst->format.samplingrate = 8000;
woinst->format.bitsperchannel = 8; woinst->format.bitsperchannel = 8;
woinst->format.channels = 1; woinst->format.channels = 1;
...@@ -1124,7 +1205,13 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1124,7 +1205,13 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
woinst->buffer.fragment_size = 0; woinst->buffer.fragment_size = 0;
woinst->buffer.ossfragshift = 0; woinst->buffer.ossfragshift = 0;
woinst->buffer.numfrags = 0; woinst->buffer.numfrags = 0;
woinst->device = (card->audio1_num == minor); woinst->device = (card->audio_dev1 == minor);
woinst->timer.state = TIMER_STATE_UNINSTALLED;
woinst->num_voices = 1;
for (i = 0; i < WAVEOUT_MAXVOICES; i++) {
woinst->voice[i].usage = VOICE_USAGE_FREE;
woinst->buffer.mem[i].emupageindex = -1;
}
init_waitqueue_head(&woinst->wait_queue); init_waitqueue_head(&woinst->wait_queue);
...@@ -1137,45 +1224,6 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file) ...@@ -1137,45 +1224,6 @@ static int emu10k1_audio_open(struct inode *inode, struct file *file)
wave_dev->woinst = woinst; wave_dev->woinst = woinst;
emu10k1_waveout_setformat(wave_dev, &woinst->format); emu10k1_waveout_setformat(wave_dev, &woinst->format);
#ifdef PRIVATE_PCM_VOLUME
{
int i;
int j = -1;
/*
* find out if we've already been in this table
* xmms reopens dsp on every move of slider
* this way we keep the same local pcm for such
* process
*/
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files)
break;
// here we should select last used memeber
// improve me in case its not sufficient
if (j < 0 && !sblive_pcm_volume[i].opened)
j = i;
}
// current task not found
if (i == MAX_PCM_CHANNELS) {
// add new entry
if (j < 0)
printk(KERN_WARNING "emu10k1: too many writters!\n");
i = (j >= 0) ? j : 0;
DPD(2, "new pcm private %p\n", current->files);
sblive_pcm_volume[i].files = current->files;
sblive_pcm_volume[i].mixer = pcm_last_mixer;
sblive_pcm_volume[i].attn_l = 0;
sblive_pcm_volume[i].attn_r = 0;
sblive_pcm_volume[i].channel_l = NUM_G;
sblive_pcm_volume[i].channel_r = NUM_G;
} else
DPD(2, "old pcm private %p 0x%x\n", current->files,
sblive_pcm_volume[i].mixer);
sblive_pcm_volume[i].opened++;
}
#endif
} }
file->private_data = (void *) wave_dev; file->private_data = (void *) wave_dev;
...@@ -1189,7 +1237,6 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file) ...@@ -1189,7 +1237,6 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file)
struct emu10k1_card *card; struct emu10k1_card *card;
unsigned long flags; unsigned long flags;
lock_kernel();
card = wave_dev->card; card = wave_dev->card;
DPF(2, "emu10k1_audio_release()\n"); DPF(2, "emu10k1_audio_release()\n");
...@@ -1199,6 +1246,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file) ...@@ -1199,6 +1246,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file)
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
if (woinst->format.passthrough && card->pt.state != PT_STATE_INACTIVE)
emu10k1_pt_stop(card);
if (woinst->state & WAVE_STATE_OPEN) { if (woinst->state & WAVE_STATE_OPEN) {
if (woinst->state & WAVE_STATE_STARTED) { if (woinst->state & WAVE_STATE_STARTED) {
if (!(file->f_flags & O_NONBLOCK)) { if (!(file->f_flags & O_NONBLOCK)) {
...@@ -1211,31 +1261,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file) ...@@ -1211,31 +1261,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file)
} }
} }
} }
if (woinst->mmapped) {
int i;
/* Undo marking the pages as reserved */
for (i = 0; i < woinst->buffer.pages; i++)
mem_map_unreserve(virt_to_page(woinst->buffer.addr[i]));
}
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
} }
#ifdef PRIVATE_PCM_VOLUME
{
int i;
/* mark as closed
* NOTE: structure remains unchanged for next reopen */
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
sblive_pcm_volume[i].opened--;
break;
}
}
}
#endif
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
/* wait for the tasklet (bottom-half) to finish */ /* wait for the tasklet (bottom-half) to finish */
tasklet_unlock_wait(&woinst->timer.tasklet); tasklet_unlock_wait(&woinst->timer.tasklet);
...@@ -1247,8 +1275,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file) ...@@ -1247,8 +1275,9 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file)
spin_lock_irqsave(&wiinst->lock, flags); spin_lock_irqsave(&wiinst->lock, flags);
if (wiinst->state & WAVE_STATE_OPEN) if (wiinst->state & WAVE_STATE_OPEN) {
emu10k1_wavein_close(wave_dev); emu10k1_wavein_close(wave_dev);
}
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
tasklet_unlock_wait(&wiinst->timer.tasklet); tasklet_unlock_wait(&wiinst->timer.tasklet);
...@@ -1257,12 +1286,13 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file) ...@@ -1257,12 +1286,13 @@ static int emu10k1_audio_release(struct inode *inode, struct file *file)
kfree(wave_dev); kfree(wave_dev);
if (waitqueue_active(&card->open_wait))
wake_up_interruptible(&card->open_wait); wake_up_interruptible(&card->open_wait);
unlock_kernel();
return 0; return 0;
} }
/* FIXME sort out poll() + mmap() */
static unsigned int emu10k1_audio_poll(struct file *file, struct poll_table_struct *wait) static unsigned int emu10k1_audio_poll(struct file *file, struct poll_table_struct *wait)
{ {
struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data; struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
...@@ -1292,11 +1322,6 @@ static unsigned int emu10k1_audio_poll(struct file *file, struct poll_table_stru ...@@ -1292,11 +1322,6 @@ static unsigned int emu10k1_audio_poll(struct file *file, struct poll_table_stru
} else } else
mask |= POLLOUT | POLLWRNORM; mask |= POLLOUT | POLLWRNORM;
if(woinst->mmapped) {
spin_unlock_irqrestore(&woinst->lock, flags);
return mask;
}
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
} }
...@@ -1336,7 +1361,7 @@ static void calculate_ofrag(struct woinst *woinst) ...@@ -1336,7 +1361,7 @@ static void calculate_ofrag(struct woinst *woinst)
return; return;
if (!buffer->ossfragshift) { if (!buffer->ossfragshift) {
fragsize = (woinst->format.bytespersec * WAVEOUT_DEFAULTFRAGLEN) / 1000 - 1; fragsize = (woinst->format.bytespervoicesample * woinst->format.samplingrate * WAVEOUT_DEFAULTFRAGLEN) / 1000 - 1;
while (fragsize) { while (fragsize) {
fragsize >>= 1; fragsize >>= 1;
...@@ -1352,7 +1377,8 @@ static void calculate_ofrag(struct woinst *woinst) ...@@ -1352,7 +1377,8 @@ static void calculate_ofrag(struct woinst *woinst)
if (!buffer->numfrags) { if (!buffer->numfrags) {
u32 numfrags; u32 numfrags;
numfrags = (woinst->format.bytespersec * WAVEOUT_DEFAULTBUFLEN) / (buffer->fragment_size * 1000) - 1; numfrags = (woinst->format.bytespervoicesample * woinst->format.samplingrate * WAVEOUT_DEFAULTBUFLEN) /
(buffer->fragment_size * 1000) - 1;
buffer->numfrags = 1; buffer->numfrags = 1;
...@@ -1452,13 +1478,13 @@ static void calculate_ifrag(struct wiinst *wiinst) ...@@ -1452,13 +1478,13 @@ static void calculate_ifrag(struct wiinst *wiinst)
} }
buffer->numfrags = buffer->size / buffer->fragment_size; buffer->numfrags = buffer->size / buffer->fragment_size;
buffer->pages = buffer->size / PAGE_SIZE + ((buffer->size % PAGE_SIZE) ? 1 : 0);
if (buffer->size % buffer->fragment_size) if (buffer->size % buffer->fragment_size)
BUG(); BUG();
DPD(2, " calculated recording fragment_size -> %d\n", buffer->fragment_size); DPD(2, " calculated recording fragment_size -> %d\n", buffer->fragment_size);
DPD(2, " calculated recording numfrags -> %d\n", buffer->numfrags); DPD(2, " calculated recording numfrags -> %d\n", buffer->numfrags);
DPD(2, " buffer size register -> 0x%2x\n", buffer->sizeregval); DPD(2, " buffer size register -> %#04x\n", buffer->sizeregval);
return; return;
} }
...@@ -1478,17 +1504,11 @@ void emu10k1_wavein_bh(unsigned long refdata) ...@@ -1478,17 +1504,11 @@ void emu10k1_wavein_bh(unsigned long refdata)
} }
emu10k1_wavein_update(wave_dev->card, wiinst); emu10k1_wavein_update(wave_dev->card, wiinst);
if (wiinst->mmapped) {
spin_unlock_irqrestore(&wiinst->lock, flags);
return;
}
emu10k1_wavein_getxfersize(wiinst, &bytestocopy); emu10k1_wavein_getxfersize(wiinst, &bytestocopy);
spin_unlock_irqrestore(&wiinst->lock, flags); spin_unlock_irqrestore(&wiinst->lock, flags);
if (bytestocopy >= wiinst->buffer.fragment_size) if (bytestocopy >= wiinst->buffer.fragment_size && waitqueue_active(&wiinst->wait_queue))
wake_up_interruptible(&wiinst->wait_queue); wake_up_interruptible(&wiinst->wait_queue);
else else
DPD(3, "Not enough transfer size, %d\n", bytestocopy); DPD(3, "Not enough transfer size, %d\n", bytestocopy);
...@@ -1519,7 +1539,7 @@ void emu10k1_waveout_bh(unsigned long refdata) ...@@ -1519,7 +1539,7 @@ void emu10k1_waveout_bh(unsigned long refdata)
} else } else
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
if (bytestocopy >= woinst->buffer.fragment_size) if (bytestocopy >= woinst->buffer.fragment_size && waitqueue_active(&woinst->wait_queue))
wake_up_interruptible(&woinst->wait_queue); wake_up_interruptible(&woinst->wait_queue);
else else
DPD(3, "Not enough transfer size -> %d\n", bytestocopy); DPD(3, "Not enough transfer size -> %d\n", bytestocopy);
......
/* /*
********************************************************************** **********************************************************************
* sblive_mi.c - MIDI UART input HAL for emu10k1 driver * sblive_mi.c - MIDI UART input HAL for emu10k1 driver
...@@ -291,7 +290,7 @@ int emu10k1_mpuin_callback(struct emu10k1_mpuin *card_mpuin, u32 msg, unsigned l ...@@ -291,7 +290,7 @@ int emu10k1_mpuin_callback(struct emu10k1_mpuin *card_mpuin, u32 msg, unsigned l
if (msg == ICARDMIDI_INDATA || msg == ICARDMIDI_INDATAERROR) { if (msg == ICARDMIDI_INDATA || msg == ICARDMIDI_INDATAERROR) {
callback_msg[1] = data; callback_msg[1] = data;
callback_msg[2] = bytesvalid; callback_msg[2] = bytesvalid;
DPD(2, "emu10k1_mpuin_callback: midimsg = %lx\n", data); DPD(2, "emu10k1_mpuin_callback: midimsg = %#lx\n", data);
} else { } else {
midiq = (struct midi_queue *) data; midiq = (struct midi_queue *) data;
midihdr = (struct midi_hdr *) midiq->refdata; midihdr = (struct midi_hdr *) midiq->refdata;
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
#define _CARDMI_H #define _CARDMI_H
#include "icardmid.h" #include "icardmid.h"
#include <linux/sched.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
typedef enum typedef enum
......
/* /*
********************************************************************** **********************************************************************
* cardmo.c - MIDI UART output HAL for emu10k1 driver * cardmo.c - MIDI UART output HAL for emu10k1 driver
......
...@@ -36,6 +36,12 @@ ...@@ -36,6 +36,12 @@
#include "audio.h" #include "audio.h"
#include "cardwi.h" #include "cardwi.h"
/**
* query_format - returns a valid sound format
*
* This function will return a valid sound format as close
* to the requested one as possible.
*/
void query_format(int recsrc, struct wave_format *wave_fmt) void query_format(int recsrc, struct wave_format *wave_fmt)
{ {
...@@ -62,8 +68,18 @@ void query_format(int recsrc, struct wave_format *wave_fmt) ...@@ -62,8 +68,18 @@ void query_format(int recsrc, struct wave_format *wave_fmt)
else else
wave_fmt->samplingrate = 0x1F40; wave_fmt->samplingrate = 0x1F40;
if ((wave_fmt->bitsperchannel != 8) && (wave_fmt->bitsperchannel != 16)) switch (wave_fmt->id) {
case AFMT_S16_LE:
wave_fmt->bitsperchannel = 16; wave_fmt->bitsperchannel = 16;
break;
case AFMT_U8:
wave_fmt->bitsperchannel = 8;
break;
default:
wave_fmt->id = AFMT_S16_LE;
wave_fmt->bitsperchannel = 16;
break;
}
break; break;
...@@ -80,13 +96,13 @@ void query_format(int recsrc, struct wave_format *wave_fmt) ...@@ -80,13 +96,13 @@ void query_format(int recsrc, struct wave_format *wave_fmt)
wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3; wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel; wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate; wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
return;
} }
static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer) static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
{ {
if ((buffer->addr = pci_alloc_consistent(card->pci_dev, buffer->size * buffer->cov, &buffer->dma_handle)) == NULL) buffer->addr = pci_alloc_consistent(card->pci_dev, buffer->size * buffer->cov,
&buffer->dma_handle);
if (buffer->addr == NULL)
return -1; return -1;
return 0; return 0;
...@@ -95,9 +111,8 @@ static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer) ...@@ -95,9 +111,8 @@ static int alloc_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
static void free_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer) static void free_buffer(struct emu10k1_card *card, struct wavein_buffer *buffer)
{ {
if (buffer->addr != NULL) if (buffer->addr != NULL)
pci_free_consistent(card->pci_dev, buffer->size * buffer->cov, buffer->addr, buffer->dma_handle); pci_free_consistent(card->pci_dev, buffer->size * buffer->cov,
buffer->addr, buffer->dma_handle);
return;
} }
int emu10k1_wavein_open(struct emu10k1_wavedevice *wave_dev) int emu10k1_wavein_open(struct emu10k1_wavedevice *wave_dev)
...@@ -195,8 +210,6 @@ void emu10k1_wavein_close(struct emu10k1_wavedevice *wave_dev) ...@@ -195,8 +210,6 @@ void emu10k1_wavein_close(struct emu10k1_wavedevice *wave_dev)
spin_unlock_irqrestore(&card->lock, flags); spin_unlock_irqrestore(&card->lock, flags);
wiinst->state = WAVE_STATE_CLOSED; wiinst->state = WAVE_STATE_CLOSED;
return;
} }
void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev) void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev)
...@@ -214,8 +227,6 @@ void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev) ...@@ -214,8 +227,6 @@ void emu10k1_wavein_start(struct emu10k1_wavedevice *wave_dev)
wiinst->buffer.bytestocopy = 0; wiinst->buffer.bytestocopy = 0;
wiinst->state |= WAVE_STATE_STARTED; wiinst->state |= WAVE_STATE_STARTED;
return;
} }
void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev) void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev)
...@@ -232,8 +243,6 @@ void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev) ...@@ -232,8 +243,6 @@ void emu10k1_wavein_stop(struct emu10k1_wavedevice *wave_dev)
emu10k1_stop_record(card, &wiinst->buffer); emu10k1_stop_record(card, &wiinst->buffer);
wiinst->state &= ~WAVE_STATE_STARTED; wiinst->state &= ~WAVE_STATE_STARTED;
return;
} }
int emu10k1_wavein_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format) int emu10k1_wavein_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
...@@ -282,20 +291,21 @@ void emu10k1_wavein_getxfersize(struct wiinst *wiinst, u32 * size) ...@@ -282,20 +291,21 @@ void emu10k1_wavein_getxfersize(struct wiinst *wiinst, u32 * size)
*size = buffer->bytestocopy; *size = buffer->bytestocopy;
if (wiinst->mmapped)
return;
if (*size > buffer->size) { if (*size > buffer->size) {
*size = buffer->size; *size = buffer->size;
buffer->pos = buffer->hw_pos; buffer->pos = buffer->hw_pos;
buffer->bytestocopy = buffer->size; buffer->bytestocopy = buffer->size;
DPF(1, "buffer overrun\n"); DPF(1, "buffer overrun\n");
} }
return;
} }
static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov) static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov)
{ {
if (cov == 1) if (cov == 1)
copy_to_user(dst, src + str, len); __copy_to_user(dst, src + str, len);
else { else {
u8 byte; u8 byte;
u32 i; u32 i;
...@@ -304,11 +314,9 @@ static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov) ...@@ -304,11 +314,9 @@ static void copy_block(u8 *dst, u8 * src, u32 str, u32 len, u8 cov)
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
byte = src[2 * i] ^ 0x80; byte = src[2 * i] ^ 0x80;
copy_to_user(dst + i, &byte, 1); __copy_to_user(dst + i, &byte, 1);
} }
} }
return;
} }
void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size) void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size)
...@@ -340,8 +348,6 @@ void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size) ...@@ -340,8 +348,6 @@ void emu10k1_wavein_xferdata(struct wiinst *wiinst, u8 * data, u32 * size)
} else { } else {
copy_block(data, buffer->addr, start, sizetocopy, buffer->cov); copy_block(data, buffer->addr, start, sizetocopy, buffer->cov);
} }
return;
} }
void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst) void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst)
...@@ -362,6 +368,4 @@ void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst) ...@@ -362,6 +368,4 @@ void emu10k1_wavein_update(struct emu10k1_card *card, struct wiinst *wiinst)
wiinst->buffer.bytestocopy += diff; wiinst->buffer.bytestocopy += diff;
wiinst->buffer.hw_pos = hw_pos; wiinst->buffer.hw_pos = hw_pos;
return;
} }
...@@ -43,6 +43,7 @@ struct wavein_buffer { ...@@ -43,6 +43,7 @@ struct wavein_buffer {
u32 pos; /* software cursor position */ u32 pos; /* software cursor position */
u32 bytestocopy; /* bytes of recorded data available */ u32 bytestocopy; /* bytes of recorded data available */
u32 size; u32 size;
u32 pages;
u32 sizereg; u32 sizereg;
u32 sizeregval; u32 sizeregval;
u32 addrreg; u32 addrreg;
......
...@@ -42,25 +42,91 @@ static u32 samplerate_to_linearpitch(u32 samplingrate) ...@@ -42,25 +42,91 @@ static u32 samplerate_to_linearpitch(u32 samplingrate)
return (samplingrate >> 1) + (samplingrate & 1); return (samplingrate >> 1) + (samplingrate & 1);
} }
static void query_format(struct wave_format *wave_fmt) static void query_format(struct emu10k1_wavedevice *wave_dev, struct wave_format *wave_fmt)
{ {
if ((wave_fmt->channels != 1) && (wave_fmt->channels != 2)) int i, j, do_passthrough = 0, is_ac3 = 0;
struct emu10k1_card *card = wave_dev->card;
struct woinst *woinst = wave_dev->woinst;
if ((wave_fmt->channels > 2) && (wave_fmt->id != AFMT_S16_LE) && (wave_fmt->id != AFMT_U8))
wave_fmt->channels = 2; wave_fmt->channels = 2;
if ((wave_fmt->channels < 1) || (wave_fmt->channels > WAVEOUT_MAXVOICES))
wave_fmt->channels = 2;
if (wave_fmt->channels == 2)
woinst->num_voices = 1;
else
woinst->num_voices = wave_fmt->channels;
if (wave_fmt->samplingrate >= 0x2ee00) if (wave_fmt->samplingrate >= 0x2ee00)
wave_fmt->samplingrate = 0x2ee00; wave_fmt->samplingrate = 0x2ee00;
if ((wave_fmt->bitsperchannel != 8) && (wave_fmt->bitsperchannel != 16)) wave_fmt->passthrough = 0;
do_passthrough = is_ac3 = 0;
if (card->pt.selected)
do_passthrough = 1;
switch (wave_fmt->id) {
case AFMT_S16_LE:
wave_fmt->bitsperchannel = 16;
break;
case AFMT_U8:
wave_fmt->bitsperchannel = 8;
break;
case AFMT_AC3:
do_passthrough = 1;
is_ac3 = 1;
break;
default:
wave_fmt->id = AFMT_S16_LE;
wave_fmt->bitsperchannel = 16;
break;
}
if (do_passthrough) {
i = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.intr_gpr_name);
j = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.enable_gpr_name);
/* currently only one waveout instance may use pass-through */
if (i < 0 || j < 0 || woinst->state != WAVE_STATE_CLOSED ||
card->pt.state != PT_STATE_INACTIVE ||
(wave_fmt->samplingrate != 48000 && !is_ac3) ||
(wave_fmt->samplingrate != 48000 && !is_ac3)) {
DPF(2, "unable to set pass-through mode\n");
} else {
wave_fmt->samplingrate = 48000;
wave_fmt->channels = 2;
wave_fmt->passthrough = 1;
card->pt.intr_gpr = i;
card->pt.enable_gpr = j;
card->pt.state = PT_STATE_INACTIVE;
card->pt.pos_gpr = emu10k1_find_control_gpr(&card->mgr, card->pt.patch_name, card->pt.pos_gpr_name);
DPD(2, "is_ac3 is %d\n", is_ac3);
card->pt.ac3data = is_ac3;
wave_fmt->bitsperchannel = 16; wave_fmt->bitsperchannel = 16;
}
}
wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3; wave_fmt->bytesperchannel = wave_fmt->bitsperchannel >> 3;
if (wave_fmt->channels == 2)
wave_fmt->bytespervoicesample = wave_fmt->channels * wave_fmt->bytesperchannel;
else
wave_fmt->bytespervoicesample = wave_fmt->bytesperchannel;
wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel; wave_fmt->bytespersample = wave_fmt->channels * wave_fmt->bytesperchannel;
wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate; wave_fmt->bytespersec = wave_fmt->bytespersample * wave_fmt->samplingrate;
return;
} }
static int alloc_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer) /**
* alloc_buffer -
*
* allocates the memory buffer for a voice. Two page tables are kept for each buffer.
* One (dma_handle) keeps track of the host memory pages used and the other (virtualpagetable)
* is passed to the device so that it can do DMA to host memory.
*
*/
static int alloc_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer, unsigned int voicenum)
{ {
u32 pageindex, pagecount; u32 pageindex, pagecount;
unsigned long busaddx; unsigned long busaddx;
...@@ -68,59 +134,67 @@ static int alloc_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer ...@@ -68,59 +134,67 @@ static int alloc_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer
DPD(2, "requested pages is: %d\n", buffer->pages); DPD(2, "requested pages is: %d\n", buffer->pages);
if ((buffer->emupageindex = emu10k1_addxmgr_alloc(buffer->pages * PAGE_SIZE, card)) < 0) if ((buffer->mem[voicenum].emupageindex =
emu10k1_addxmgr_alloc(buffer->pages * PAGE_SIZE, card)) < 0)
return -1; return -1;
/* Fill in virtual memory table */ /* Fill in virtual memory table */
for (pagecount = 0; pagecount < buffer->pages; pagecount++) { for (pagecount = 0; pagecount < buffer->pages; pagecount++) {
if ((buffer->addr[pagecount] = pci_alloc_consistent(card->pci_dev, PAGE_SIZE, &buffer->dma_handle[pagecount])) == NULL) { if ((buffer->mem[voicenum].addr[pagecount] =
pci_alloc_consistent(card->pci_dev, PAGE_SIZE,
&buffer->mem[voicenum].dma_handle[pagecount])) == NULL) {
buffer->pages = pagecount; buffer->pages = pagecount;
return -1; return -1;
} }
DPD(2, "Virtual Addx: %p\n", buffer->addr[pagecount]); DPD(2, "Virtual Addx: %p\n", buffer->mem[voicenum].addr[pagecount]);
for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) { for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) {
busaddx = buffer->dma_handle[pagecount] + i * EMUPAGESIZE; busaddx = buffer->mem[voicenum].dma_handle[pagecount] + i * EMUPAGESIZE;
DPD(3, "Bus Addx: %lx\n", busaddx); DPD(3, "Bus Addx: %#lx\n", busaddx);
pageindex = buffer->emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i; pageindex = buffer->mem[voicenum].emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i;
((u32 *) card->virtualpagetable.addr)[pageindex] = ((u32 *) card->virtualpagetable.addr)[pageindex] = cpu_to_le32((busaddx * 2) | pageindex);
cpu_to_le32((busaddx * 2) | pageindex);
} }
} }
return 0; return 0;
} }
static void free_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer) /**
* free_buffer -
*
* frees the memory buffer for a voice.
*/
static void free_buffer(struct emu10k1_card *card, struct waveout_buffer *buffer, unsigned int voicenum)
{ {
u32 pagecount, pageindex; u32 pagecount, pageindex;
int i; int i;
if (buffer->emupageindex < 0) if (buffer->mem[voicenum].emupageindex < 0)
return; return;
for (pagecount = 0; pagecount < buffer->pages; pagecount++) { for (pagecount = 0; pagecount < buffer->pages; pagecount++) {
pci_free_consistent(card->pci_dev, PAGE_SIZE, buffer->addr[pagecount], buffer->dma_handle[pagecount]); pci_free_consistent(card->pci_dev, PAGE_SIZE,
buffer->mem[voicenum].addr[pagecount],
buffer->mem[voicenum].dma_handle[pagecount]);
for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) { for (i = 0; i < PAGE_SIZE / EMUPAGESIZE; i++) {
pageindex = buffer->emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i; pageindex = buffer->mem[voicenum].emupageindex + pagecount * PAGE_SIZE / EMUPAGESIZE + i;
((u32 *) card->virtualpagetable.addr)[pageindex] = (card->silentpage.dma_handle * 2) | pageindex; ((u32 *) card->virtualpagetable.addr)[pageindex] =
cpu_to_le32((card->silentpage.dma_handle * 2) | pageindex);
} }
} }
emu10k1_addxmgr_free(card, buffer->emupageindex); emu10k1_addxmgr_free(card, buffer->mem[voicenum].emupageindex);
buffer->emupageindex = -1; buffer->mem[voicenum].emupageindex = -1;
return;
} }
static int get_voice(struct emu10k1_card *card, struct woinst *woinst) static int get_voice(struct emu10k1_card *card, struct woinst *woinst, unsigned int voicenum)
{ {
struct emu_voice *voice = &woinst->voice; struct emu_voice *voice = &woinst->voice[voicenum];
/* Allocate voices here, if no voices available, return error. /* Allocate voices here, if no voices available, return error.
* Init voice_allocdesc first.*/ * Init voice_allocdesc first.*/
...@@ -134,17 +208,20 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -134,17 +208,20 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
if (woinst->format.bitsperchannel == 16) if (woinst->format.bitsperchannel == 16)
voice->flags |= VOICE_FLAGS_16BIT; voice->flags |= VOICE_FLAGS_16BIT;
if (emu10k1_voice_alloc(card, voice) < 0) if (emu10k1_voice_alloc(card, voice) < 0) {
voice->usage = VOICE_USAGE_FREE;
return -1; return -1;
}
/* Calculate pitch */ /* Calculate pitch */
voice->initial_pitch = (u16) (srToPitch(woinst->format.samplingrate) >> 8); voice->initial_pitch = (u16) (srToPitch(woinst->format.samplingrate) >> 8);
voice->pitch_target = samplerate_to_linearpitch(woinst->format.samplingrate); voice->pitch_target = samplerate_to_linearpitch(woinst->format.samplingrate);
DPD(2, "Initial pitch --> 0x%x\n", voice->initial_pitch); DPD(2, "Initial pitch --> %#x\n", voice->initial_pitch);
voice->startloop = (woinst->buffer.emupageindex << 12) / woinst->format.bytespersample; voice->startloop = (woinst->buffer.mem[voicenum].emupageindex << 12) /
voice->endloop = voice->startloop + woinst->buffer.size / woinst->format.bytespersample; woinst->format.bytespervoicesample;
voice->endloop = voice->startloop + woinst->buffer.size / woinst->format.bytespervoicesample;
voice->start = voice->startloop; voice->start = voice->startloop;
if (voice->flags & VOICE_FLAGS_STEREO) { if (voice->flags & VOICE_FLAGS_STEREO) {
...@@ -154,7 +231,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -154,7 +231,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
voice->params[0].send_d = card->waveout.send_d[1]; voice->params[0].send_d = card->waveout.send_d[1];
if (woinst->device) if (woinst->device)
voice->params[0].send_routing = 0xd23c; voice->params[0].send_routing = 0x7654;
else else
voice->params[0].send_routing = card->waveout.send_routing[1]; voice->params[0].send_routing = card->waveout.send_routing[1];
...@@ -170,7 +247,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -170,7 +247,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
voice->params[1].send_d = card->waveout.send_d[2]; voice->params[1].send_d = card->waveout.send_d[2];
if (woinst->device) if (woinst->device)
voice->params[1].send_routing = 0xd23c; voice->params[1].send_routing = 0x7654;
else else
voice->params[1].send_routing = card->waveout.send_routing[2]; voice->params[1].send_routing = card->waveout.send_routing[2];
...@@ -179,6 +256,15 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -179,6 +256,15 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
voice->params[1].initial_attn = 0x00; voice->params[1].initial_attn = 0x00;
voice->params[1].byampl_env_sustain = 0x7f; voice->params[1].byampl_env_sustain = 0x7f;
voice->params[1].byampl_env_decay = 0x7f; voice->params[1].byampl_env_decay = 0x7f;
} else {
if (woinst->num_voices > 1) {
voice->params[0].send_a = 0xff;
voice->params[0].send_b = 0;
voice->params[0].send_c = 0;
voice->params[0].send_d = 0;
voice->params[0].send_routing =
0xfff0 + card->mchannel_fx + voicenum;
} else { } else {
voice->params[0].send_a = card->waveout.send_a[0]; voice->params[0].send_a = card->waveout.send_a[0];
voice->params[0].send_b = card->waveout.send_b[0]; voice->params[0].send_b = card->waveout.send_b[0];
...@@ -186,9 +272,10 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -186,9 +272,10 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
voice->params[0].send_d = card->waveout.send_d[0]; voice->params[0].send_d = card->waveout.send_d[0];
if (woinst->device) if (woinst->device)
voice->params[0].send_routing = 0xd23c; voice->params[0].send_routing = 0x7654;
else else
voice->params[0].send_routing = card->waveout.send_routing[0]; voice->params[0].send_routing = card->waveout.send_routing[0];
}
voice->params[0].volume_target = 0xffff; voice->params[0].volume_target = 0xffff;
voice->params[0].initial_fc = 0xff; voice->params[0].initial_fc = 0xff;
...@@ -197,7 +284,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst) ...@@ -197,7 +284,7 @@ static int get_voice(struct emu10k1_card *card, struct woinst *woinst)
voice->params[0].byampl_env_decay = 0x7f; voice->params[0].byampl_env_decay = 0x7f;
} }
DPD(2, "voice: startloop=0x%x, endloop=0x%x\n", voice->startloop, voice->endloop); DPD(2, "voice: startloop=%#x, endloop=%#x\n", voice->startloop, voice->endloop);
emu10k1_voice_playback_setup(voice); emu10k1_voice_playback_setup(voice);
...@@ -208,29 +295,34 @@ int emu10k1_waveout_open(struct emu10k1_wavedevice *wave_dev) ...@@ -208,29 +295,34 @@ int emu10k1_waveout_open(struct emu10k1_wavedevice *wave_dev)
{ {
struct emu10k1_card *card = wave_dev->card; struct emu10k1_card *card = wave_dev->card;
struct woinst *woinst = wave_dev->woinst; struct woinst *woinst = wave_dev->woinst;
struct waveout_buffer *buffer = &woinst->buffer;
unsigned int voicenum;
u32 delay; u32 delay;
DPF(2, "emu10k1_waveout_open()\n"); DPF(2, "emu10k1_waveout_open()\n");
if (alloc_buffer(card, &woinst->buffer) < 0) { for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
if (alloc_buffer(card, buffer, voicenum) < 0) {
ERROR(); ERROR();
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
return -1; return -1;
} }
woinst->buffer.fill_silence = 0; if (get_voice(card, woinst, voicenum) < 0) {
woinst->buffer.silence_bytes = 0;
woinst->buffer.silence_pos = 0;
woinst->buffer.hw_pos = 0;
woinst->buffer.bytestocopy = woinst->buffer.size;
if (get_voice(card, woinst) < 0) {
ERROR(); ERROR();
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
return -1; return -1;
} }
}
delay = (48000 * woinst->buffer.fragment_size) / woinst->format.bytespersec; buffer->fill_silence = 0;
buffer->silence_bytes = 0;
buffer->silence_pos = 0;
buffer->hw_pos = 0;
buffer->free_bytes = woinst->buffer.size;
delay = (48000 * woinst->buffer.fragment_size) /
(woinst->format.samplingrate * woinst->format.bytespervoicesample);
emu10k1_timer_install(card, &woinst->timer, delay / 2); emu10k1_timer_install(card, &woinst->timer, delay / 2);
...@@ -243,6 +335,7 @@ void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev) ...@@ -243,6 +335,7 @@ void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev)
{ {
struct emu10k1_card *card = wave_dev->card; struct emu10k1_card *card = wave_dev->card;
struct woinst *woinst = wave_dev->woinst; struct woinst *woinst = wave_dev->woinst;
unsigned int voicenum;
DPF(2, "emu10k1_waveout_close()\n"); DPF(2, "emu10k1_waveout_close()\n");
...@@ -250,13 +343,12 @@ void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev) ...@@ -250,13 +343,12 @@ void emu10k1_waveout_close(struct emu10k1_wavedevice *wave_dev)
emu10k1_timer_uninstall(card, &woinst->timer); emu10k1_timer_uninstall(card, &woinst->timer);
emu10k1_voice_free(&woinst->voice); for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
emu10k1_voice_free(&woinst->voice[voicenum]);
free_buffer(card, &woinst->buffer); free_buffer(card, &woinst->buffer, voicenum);
}
woinst->state = WAVE_STATE_CLOSED; woinst->state = WAVE_STATE_CLOSED;
return;
} }
void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev) void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev)
...@@ -265,21 +357,20 @@ void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev) ...@@ -265,21 +357,20 @@ void emu10k1_waveout_start(struct emu10k1_wavedevice *wave_dev)
struct woinst *woinst = wave_dev->woinst; struct woinst *woinst = wave_dev->woinst;
DPF(2, "emu10k1_waveout_start()\n"); DPF(2, "emu10k1_waveout_start()\n");
/* Actual start */
emu10k1_voice_start(&woinst->voice, woinst->total_played); /* Actual start */
emu10k1_voices_start(woinst->voice, woinst->num_voices, woinst->total_played);
emu10k1_timer_enable(card, &woinst->timer); emu10k1_timer_enable(card, &woinst->timer);
woinst->state |= WAVE_STATE_STARTED; woinst->state |= WAVE_STATE_STARTED;
return;
} }
int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format) int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_format *format)
{ {
struct emu10k1_card *card = wave_dev->card; struct emu10k1_card *card = wave_dev->card;
struct woinst *woinst = wave_dev->woinst; struct woinst *woinst = wave_dev->woinst;
unsigned int voicenum;
u32 delay; u32 delay;
DPF(2, "emu10k1_waveout_setformat()\n"); DPF(2, "emu10k1_waveout_setformat()\n");
...@@ -287,7 +378,7 @@ int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_f ...@@ -287,7 +378,7 @@ int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_f
if (woinst->state & WAVE_STATE_STARTED) if (woinst->state & WAVE_STATE_STARTED)
return -1; return -1;
query_format(format); query_format(wave_dev, format);
if (woinst->format.samplingrate != format->samplingrate || if (woinst->format.samplingrate != format->samplingrate ||
woinst->format.channels != format->channels || woinst->format.channels != format->channels ||
...@@ -299,15 +390,19 @@ int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_f ...@@ -299,15 +390,19 @@ int emu10k1_waveout_setformat(struct emu10k1_wavedevice *wave_dev, struct wave_f
return 0; return 0;
emu10k1_timer_uninstall(card, &woinst->timer); emu10k1_timer_uninstall(card, &woinst->timer);
emu10k1_voice_free(&woinst->voice);
if (get_voice(card, woinst) < 0) { for (voicenum = 0; voicenum < woinst->num_voices; voicenum++) {
emu10k1_voice_free(&woinst->voice[voicenum]);
if (get_voice(card, woinst, voicenum) < 0) {
ERROR(); ERROR();
emu10k1_waveout_close(wave_dev); emu10k1_waveout_close(wave_dev);
return -1; return -1;
} }
}
delay = (48000 * woinst->buffer.fragment_size) / woinst->format.bytespersec; delay = (48000 * woinst->buffer.fragment_size) /
(woinst->format.samplingrate * woinst->format.bytespervoicesample);
emu10k1_timer_install(card, &woinst->timer, delay / 2); emu10k1_timer_install(card, &woinst->timer, delay / 2);
} }
...@@ -327,93 +422,159 @@ void emu10k1_waveout_stop(struct emu10k1_wavedevice *wave_dev) ...@@ -327,93 +422,159 @@ void emu10k1_waveout_stop(struct emu10k1_wavedevice *wave_dev)
emu10k1_timer_disable(card, &woinst->timer); emu10k1_timer_disable(card, &woinst->timer);
/* Stop actual voice */ /* Stop actual voices */
emu10k1_voice_stop(&woinst->voice); emu10k1_voices_stop(woinst->voice, woinst->num_voices);
emu10k1_waveout_update(woinst); emu10k1_waveout_update(woinst);
woinst->state &= ~WAVE_STATE_STARTED; woinst->state &= ~WAVE_STATE_STARTED;
return;
} }
void emu10k1_waveout_getxfersize(struct woinst *woinst, u32 * size) /**
* emu10k1_waveout_getxfersize -
*
* gives the total free bytes on the voice buffer, including silence bytes
* (basically: total_free_bytes = free_bytes + silence_bytes).
*
*/
void emu10k1_waveout_getxfersize(struct woinst *woinst, u32 *total_free_bytes)
{ {
struct waveout_buffer *buffer = &woinst->buffer; struct waveout_buffer *buffer = &woinst->buffer;
int pending; int pending_bytes;
if (woinst->mmapped) { if (woinst->mmapped) {
*size = buffer->bytestocopy; *total_free_bytes = buffer->free_bytes;
return; return;
} }
pending = buffer->size - buffer->bytestocopy; pending_bytes = buffer->size - buffer->free_bytes;
buffer->fill_silence = (pending < (signed) buffer->fragment_size) ? 1 : 0; buffer->fill_silence = (pending_bytes < (signed) buffer->fragment_size) ? 1 : 0;
if (pending > (signed) buffer->silence_bytes) { if (pending_bytes > (signed) buffer->silence_bytes) {
*size = buffer->bytestocopy + buffer->silence_bytes; *total_free_bytes = (buffer->free_bytes + buffer->silence_bytes);
} else { } else {
*size = buffer->size; *total_free_bytes = buffer->size;
buffer->silence_bytes = pending; buffer->silence_bytes = pending_bytes;
if (pending < 0) { if (pending_bytes < 0) {
buffer->silence_pos = buffer->hw_pos; buffer->silence_pos = buffer->hw_pos;
buffer->silence_bytes = 0; buffer->silence_bytes = 0;
buffer->bytestocopy = buffer->size; buffer->free_bytes = buffer->size;
DPF(1, "buffer underrun\n"); DPF(1, "buffer underrun\n");
} }
} }
return;
} }
/**
* copy_block -
*
* copies a block of pcm data to a voice buffer.
* Notice that the voice buffer is actually a set of disjointed memory pages.
*
*/
static void copy_block(void **dst, u32 str, u8 *src, u32 len) static void copy_block(void **dst, u32 str, u8 *src, u32 len)
{ {
int i, j, k; unsigned int pg;
unsigned int pgoff;
unsigned int k;
i = str / PAGE_SIZE; pg = str / PAGE_SIZE;
j = str % PAGE_SIZE; pgoff = str % PAGE_SIZE;
if (len > PAGE_SIZE - j) { if (len > PAGE_SIZE - pgoff) {
k = PAGE_SIZE - j; k = PAGE_SIZE - pgoff;
copy_from_user(dst[i] + j, src, k); __copy_from_user((u8 *)dst[pg] + pgoff, src, k);
len -= k; len -= k;
while (len > PAGE_SIZE) { while (len > PAGE_SIZE) {
copy_from_user(dst[++i], src + k, PAGE_SIZE); __copy_from_user(dst[++pg], src + k, PAGE_SIZE);
k += PAGE_SIZE; k += PAGE_SIZE;
len -= PAGE_SIZE; len -= PAGE_SIZE;
} }
copy_from_user(dst[++i], src + k, len); __copy_from_user(dst[++pg], src + k, len);
} else } else
copy_from_user(dst[i] + j, src, len); __copy_from_user((u8 *)dst[pg] + pgoff, src, len);
return;
} }
static void fill_block(void **dst, u32 str, u8 src, u32 len) /**
* copy_ilv_block -
*
* copies a block of pcm data containing n interleaved channels to n mono voice buffers.
* Notice that the voice buffer is actually a set of disjointed memory pages.
*
*/
static void copy_ilv_block(struct woinst *woinst, u32 str, u8 *src, u32 len)
{ {
int i, j, k; unsigned int pg;
unsigned int pgoff;
unsigned int voice_num;
struct waveout_mem *mem = woinst->buffer.mem;
pg = str / PAGE_SIZE;
pgoff = str % PAGE_SIZE;
while (len) {
for (voice_num = 0; voice_num < woinst->num_voices; voice_num++) {
__copy_from_user((u8 *)(mem[voice_num].addr[pg]) + pgoff, src, woinst->format.bytespervoicesample);
src += woinst->format.bytespervoicesample;
}
len -= woinst->format.bytespervoicesample;
i = str / PAGE_SIZE; pgoff += woinst->format.bytespervoicesample;
j = str % PAGE_SIZE; if (pgoff >= PAGE_SIZE) {
pgoff = 0;
pg++;
}
}
}
if (len > PAGE_SIZE - j) { /**
k = PAGE_SIZE - j; * fill_block -
memset(dst[i] + j, src, k); *
* fills a set voice buffers with a block of a given sample.
*
*/
static void fill_block(struct woinst *woinst, u32 str, u8 data, u32 len)
{
unsigned int pg;
unsigned int pgoff;
unsigned int voice_num;
struct waveout_mem *mem = woinst->buffer.mem;
unsigned int k;
pg = str / PAGE_SIZE;
pgoff = str % PAGE_SIZE;
if (len > PAGE_SIZE - pgoff) {
k = PAGE_SIZE - pgoff;
for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
memset((u8 *)mem[voice_num].addr[pg] + pgoff, data, k);
len -= k; len -= k;
while (len > PAGE_SIZE) { while (len > PAGE_SIZE) {
memset(dst[++i], src, PAGE_SIZE); pg++;
for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
memset(mem[voice_num].addr[pg], data, PAGE_SIZE);
len -= PAGE_SIZE; len -= PAGE_SIZE;
} }
memset(dst[++i], src, len); pg++;
for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
} else memset(mem[voice_num].addr[pg], data, len);
memset(dst[i] + j, src, len);
return; } else {
for (voice_num = 0; voice_num < woinst->num_voices; voice_num++)
memset((u8 *)mem[voice_num].addr[pg] + pgoff, data, len);
}
} }
/**
* emu10k1_waveout_xferdata -
*
* copies pcm data to the voice buffer. Silence samples
* previously added to the buffer are overwritten.
*
*/
void emu10k1_waveout_xferdata(struct woinst *woinst, u8 *data, u32 *size) void emu10k1_waveout_xferdata(struct woinst *woinst, u8 *data, u32 *size)
{ {
struct waveout_buffer *buffer = &woinst->buffer; struct waveout_buffer *buffer = &woinst->buffer;
...@@ -429,63 +590,82 @@ void emu10k1_waveout_xferdata(struct woinst *woinst, u8 *data, u32 *size) ...@@ -429,63 +590,82 @@ void emu10k1_waveout_xferdata(struct woinst *woinst, u8 *data, u32 *size)
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
start = (buffer->size + buffer->silence_pos - buffer->silence_bytes) % buffer->size; start = (buffer->size + buffer->silence_pos - buffer->silence_bytes) % buffer->size;
if(sizetocopy > buffer->silence_bytes) { if (sizetocopy > buffer->silence_bytes) {
buffer->silence_pos += sizetocopy - buffer->silence_bytes; buffer->silence_pos += sizetocopy - buffer->silence_bytes;
buffer->bytestocopy -= sizetocopy - buffer->silence_bytes; buffer->free_bytes -= sizetocopy - buffer->silence_bytes;
buffer->silence_bytes = 0; buffer->silence_bytes = 0;
} else } else
buffer->silence_bytes -= sizetocopy; buffer->silence_bytes -= sizetocopy;
sizetocopy_now = buffer->size - start;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
sizetocopy_now = buffer->size - start;
if (sizetocopy > sizetocopy_now) { if (sizetocopy > sizetocopy_now) {
sizetocopy -= sizetocopy_now; sizetocopy -= sizetocopy_now;
copy_block(buffer->addr, start, data, sizetocopy_now); if (woinst->num_voices > 1) {
copy_block(buffer->addr, 0, data + sizetocopy_now, sizetocopy); copy_ilv_block(woinst, start, data, sizetocopy_now);
copy_ilv_block(woinst, 0, data + sizetocopy_now * woinst->num_voices, sizetocopy);
} else { } else {
copy_block(buffer->addr, start, data, sizetocopy); copy_block(buffer->mem[0].addr, start, data, sizetocopy_now);
copy_block(buffer->mem[0].addr, 0, data + sizetocopy_now, sizetocopy);
}
} else {
if (woinst->num_voices > 1)
copy_ilv_block(woinst, start, data, sizetocopy);
else
copy_block(buffer->mem[0].addr, start, data, sizetocopy);
} }
return;
} }
/**
* emu10k1_waveout_fillsilence -
*
* adds samples of silence to the voice buffer so that we
* don't loop over stale pcm data.
*
*/
void emu10k1_waveout_fillsilence(struct woinst *woinst) void emu10k1_waveout_fillsilence(struct woinst *woinst)
{ {
struct waveout_buffer *buffer = &woinst->buffer; struct waveout_buffer *buffer = &woinst->buffer;
u16 filldata;
u32 sizetocopy, sizetocopy_now, start; u32 sizetocopy, sizetocopy_now, start;
u8 filldata;
unsigned long flags; unsigned long flags;
sizetocopy = woinst->buffer.fragment_size; sizetocopy = buffer->fragment_size;
if (woinst->format.bitsperchannel == 16) if (woinst->format.bitsperchannel == 16)
filldata = 0x0000; filldata = 0x00;
else else
filldata = 0x8080; filldata = 0x80;
spin_lock_irqsave(&woinst->lock, flags); spin_lock_irqsave(&woinst->lock, flags);
buffer->silence_bytes += sizetocopy; buffer->silence_bytes += sizetocopy;
buffer->bytestocopy -= sizetocopy; buffer->free_bytes -= sizetocopy;
buffer->silence_pos %= buffer->size; buffer->silence_pos %= buffer->size;
start = buffer->silence_pos; start = buffer->silence_pos;
buffer->silence_pos += sizetocopy; buffer->silence_pos += sizetocopy;
sizetocopy_now = buffer->size - start;
spin_unlock_irqrestore(&woinst->lock, flags); spin_unlock_irqrestore(&woinst->lock, flags);
sizetocopy_now = buffer->size - start;
if (sizetocopy > sizetocopy_now) { if (sizetocopy > sizetocopy_now) {
sizetocopy -= sizetocopy_now; sizetocopy -= sizetocopy_now;
fill_block(buffer->addr, start, filldata, sizetocopy_now); fill_block(woinst, start, filldata, sizetocopy_now);
fill_block(buffer->addr, 0, filldata, sizetocopy); fill_block(woinst, 0, filldata, sizetocopy);
} else { } else {
fill_block(buffer->addr, start, filldata, sizetocopy); fill_block(woinst, start, filldata, sizetocopy);
} }
return;
} }
/**
* emu10k1_waveout_update -
*
* updates the position of the voice buffer hardware pointer (hw_pos)
* and the number of free bytes on the buffer (free_bytes).
* The free bytes _don't_ include silence bytes that may have been
* added to the buffer.
*
*/
void emu10k1_waveout_update(struct woinst *woinst) void emu10k1_waveout_update(struct woinst *woinst)
{ {
u32 hw_pos; u32 hw_pos;
...@@ -496,20 +676,18 @@ void emu10k1_waveout_update(struct woinst *woinst) ...@@ -496,20 +676,18 @@ void emu10k1_waveout_update(struct woinst *woinst)
hw_pos = woinst->buffer.hw_pos; hw_pos = woinst->buffer.hw_pos;
} else { } else {
/* hw_pos in sample units */ /* hw_pos in sample units */
hw_pos = sblive_readptr(woinst->voice.card, CCCA_CURRADDR, woinst->voice.num); hw_pos = sblive_readptr(woinst->voice[0].card, CCCA_CURRADDR, woinst->voice[0].num);
if(hw_pos < woinst->voice.start) if(hw_pos < woinst->voice[0].start)
hw_pos += woinst->buffer.size / woinst->format.bytespersample - woinst->voice.start; hw_pos += woinst->buffer.size / woinst->format.bytespervoicesample - woinst->voice[0].start;
else else
hw_pos -= woinst->voice.start; hw_pos -= woinst->voice[0].start;
hw_pos *= woinst->format.bytespersample; hw_pos *= woinst->format.bytespervoicesample;
} }
diff = (woinst->buffer.size + hw_pos - woinst->buffer.hw_pos) % woinst->buffer.size; diff = (woinst->buffer.size + hw_pos - woinst->buffer.hw_pos) % woinst->buffer.size;
woinst->total_played += diff; woinst->total_played += diff;
woinst->buffer.bytestocopy += diff; woinst->buffer.free_bytes += diff;
woinst->buffer.hw_pos = hw_pos; woinst->buffer.hw_pos = hw_pos;
return;
} }
...@@ -45,6 +45,14 @@ ...@@ -45,6 +45,14 @@
#define WAVEOUT_DEFAULTBUFLEN 500 /* Time to play the entire buffer in ms */ #define WAVEOUT_DEFAULTBUFLEN 500 /* Time to play the entire buffer in ms */
#define WAVEOUT_MINFRAGSHIFT 6 #define WAVEOUT_MINFRAGSHIFT 6
#define WAVEOUT_MAXVOICES 6
/* waveout_mem is cardwo internal */
struct waveout_mem {
int emupageindex;
void *addr[BUFMAXPAGES];
dma_addr_t dma_handle[BUFMAXPAGES];
};
struct waveout_buffer { struct waveout_buffer {
u16 ossfragshift; u16 ossfragshift;
...@@ -52,20 +60,19 @@ struct waveout_buffer { ...@@ -52,20 +60,19 @@ struct waveout_buffer {
u32 fragment_size; /* in bytes units */ u32 fragment_size; /* in bytes units */
u32 size; /* in bytes units */ u32 size; /* in bytes units */
u32 pages; /* buffer size in page units*/ u32 pages; /* buffer size in page units*/
int emupageindex; struct waveout_mem mem[WAVEOUT_MAXVOICES];
void *addr[BUFMAXPAGES]; u32 silence_pos; /* software cursor position (including silence bytes) */
dma_addr_t dma_handle[BUFMAXPAGES];
u32 silence_pos; /* software cursor position (including silence) */
u32 hw_pos; /* hardware cursor position */ u32 hw_pos; /* hardware cursor position */
u32 bytestocopy; /* free space on buffer (including silence) */ u32 free_bytes; /* free bytes available on the buffer (not including silence bytes) */
u8 fill_silence; u8 fill_silence;
u32 silence_bytes; /* silence bytes in buffer */ u32 silence_bytes; /* silence bytes on the buffer */
}; };
struct woinst struct woinst
{ {
u8 state; u8 state;
struct emu_voice voice; u8 num_voices;
struct emu_voice voice[WAVEOUT_MAXVOICES];
struct emu_timer timer; struct emu_timer timer;
struct wave_format format; struct wave_format format;
struct waveout_buffer buffer; struct waveout_buffer buffer;
......
...@@ -83,10 +83,13 @@ static void ecard_write(struct emu10k1_card *card, u32 value) ...@@ -83,10 +83,13 @@ static void ecard_write(struct emu10k1_card *card, u32 value)
{ {
u16 count; u16 count;
u32 data, hcvalue; u32 data, hcvalue;
unsigned long flags;
hcvalue = emu10k1_readfn0(card, HCFG) & ~(HOOKN_BIT|HANDN_BIT|PULSEN_BIT); spin_lock_irqsave(&card->lock, flags);
emu10k1_writefn0(card, HCFG, hcvalue); hcvalue = inl(card->iobase + HCFG) & ~(HOOKN_BIT|HANDN_BIT|PULSEN_BIT);
outl(card->iobase + HCFG, hcvalue);
for (count = 0 ; count < EC_NUM_CONTROL_BITS; count++) { for (count = 0 ; count < EC_NUM_CONTROL_BITS; count++) {
...@@ -94,19 +97,21 @@ static void ecard_write(struct emu10k1_card *card, u32 value) ...@@ -94,19 +97,21 @@ static void ecard_write(struct emu10k1_card *card, u32 value)
data = ((value & 0x1) ? PULSEN_BIT : 0); data = ((value & 0x1) ? PULSEN_BIT : 0);
value >>= 1; value >>= 1;
emu10k1_writefn0(card, HCFG, hcvalue | data); outl(card->iobase + HCFG, hcvalue | data);
/* Clock the shift register */ /* Clock the shift register */
emu10k1_writefn0(card, HCFG, hcvalue | data | HANDN_BIT); outl(card->iobase + HCFG, hcvalue | data | HANDN_BIT);
emu10k1_writefn0(card, HCFG, hcvalue | data); outl(card->iobase + HCFG, hcvalue | data);
} }
/* Latch the bits */ /* Latch the bits */
emu10k1_writefn0(card, HCFG, hcvalue | HOOKN_BIT); outl(card->iobase + HCFG, hcvalue | HOOKN_BIT);
emu10k1_writefn0(card, HCFG, hcvalue); outl(card->iobase + HCFG, hcvalue);
spin_unlock_irqrestore(&card->lock, flags);
} }
int __devinit emu10k1_ecard_init(struct emu10k1_card *card) void __devinit emu10k1_ecard_init(struct emu10k1_card *card)
{ {
u32 hcvalue; u32 hcvalue;
struct ecard_state ecard; struct ecard_state ecard;
...@@ -125,7 +130,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card) ...@@ -125,7 +130,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card)
* and enable audio output */ * and enable audio output */
hcvalue = emu10k1_readfn0(card, HCFG); hcvalue = emu10k1_readfn0(card, HCFG);
emu10k1_writefn0(card, HCFG, hcvalue | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S); emu10k1_writefn0(card, HCFG, hcvalue | HCFG_AUDIOENABLE | HCFG_CODECFORMAT_I2S);
emu10k1_readfn0(card, HCFG);
/* Step 1: Turn off the led and deassert TRIM_CS */ /* Step 1: Turn off the led and deassert TRIM_CS */
ecard_write(card, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN); ecard_write(card, EC_ADCCAL | EC_LEDN | EC_TRIM_CSN);
...@@ -148,8 +152,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card) ...@@ -148,8 +152,6 @@ int __devinit emu10k1_ecard_init(struct emu10k1_card *card)
/* Step 5: Set the analog input gain */ /* Step 5: Set the analog input gain */
ecard_setadcgain(card, &ecard, ecard.adc_gain); ecard_setadcgain(card, &ecard, ecard.adc_gain);
return 0;
} }
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
#include "8010.h" #include "8010.h"
#include "hwaccess.h" #include "hwaccess.h"
#include <linux/init.h> #include <linux/init.h>
#include <linux/sched.h>
/* In A1 Silicon, these bits are in the HC register */ /* In A1 Silicon, these bits are in the HC register */
#define HOOKN_BIT (1L << 12) #define HOOKN_BIT (1L << 12)
...@@ -109,6 +108,6 @@ struct ecard_state { ...@@ -109,6 +108,6 @@ struct ecard_state {
u16 mux2_setting; u16 mux2_setting;
}; };
int emu10k1_ecard_init(struct emu10k1_card *) __devinit; void emu10k1_ecard_init(struct emu10k1_card *) __devinit;
#endif /* _ECARD_H */ #endif /* _ECARD_H */
/*
**********************************************************************
* efxmgr.c
* Copyright 1999, 2000 Creative Labs, Inc.
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* October 20, 1999 Bertrand Lee base code release
*
**********************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*
**********************************************************************
*/
#include <linux/bitops.h>
#include "hwaccess.h"
#include "efxmgr.h"
int emu10k1_find_control_gpr(struct patch_manager *mgr, const char *patch_name, const char *gpr_name)
{
struct dsp_patch *patch;
struct dsp_rpatch *rpatch;
char s[PATCH_NAME_SIZE + 4];
u32 *gpr_used;
int i;
DPD(2, "emu10k1_find_control_gpr(): %s %s\n", patch_name, gpr_name);
rpatch = &mgr->rpatch;
if (!strcmp(rpatch->name, patch_name)) {
gpr_used = rpatch->gpr_used;
goto match;
}
for(i = 0; i < mgr->current_pages * PATCHES_PER_PAGE; i++) {
patch = PATCH(mgr, i);
sprintf(s,"%s", patch->name);
if (!strcmp(s, patch_name)) {
gpr_used = patch->gpr_used;
goto match;
}
}
return -1;
match:
for (i = 0; i < NUM_GPRS; i++)
if (mgr->gpr[i].type == GPR_TYPE_CONTROL &&
test_bit(i, gpr_used) &&
!strcmp(mgr->gpr[i].name, gpr_name))
return i;
return -1;
}
void emu10k1_set_control_gpr(struct emu10k1_card *card, int addr, s32 val, int flag)
{
struct patch_manager *mgr = &card->mgr;
DPD(2, "emu10k1_set_control_gpr(): %d %x\n", addr, val);
if (addr < 0 || addr >= NUM_GPRS)
return;
if (flag)
val += sblive_readptr(card, GPR_BASE + addr, 0);
if (val > mgr->gpr[addr].max)
val = mgr->gpr[addr].max;
else if (val < mgr->gpr[addr].min)
val = mgr->gpr[addr].min;
sblive_writeptr(card, GPR_BASE + addr, 0, val);
}
//TODO: make this configurable:
#define VOLCTRL_CHANNEL SOUND_MIXER_VOLUME
#define VOLCTRL_STEP_SIZE 5
//An internal function for setting OSS mixer controls.
void emu10k1_set_oss_vol(struct emu10k1_card *card, int oss_mixer,
unsigned int left, unsigned int right){
extern struct oss_scaling volume_params[SOUND_MIXER_NRDEVICES];
card->ac97.mixer_state[oss_mixer] = (right << 8) | left;
if (!card->isaps)
card->ac97.write_mixer(&card->ac97, oss_mixer, left, right);
emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left,
volume_params[oss_mixer].scale,
volume_params[oss_mixer].muting);
emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right,
volume_params[oss_mixer].scale,
volume_params[oss_mixer].muting);
}
//FIXME: mute should unmute when pressed a second time
void emu10k1_mute_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
spin_lock_irqsave(&mgr->lock, flags);
emu10k1_set_oss_vol(card,VOLCTRL_CHANNEL,0,0);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_volincr_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
unsigned int oss_channel=VOLCTRL_CHANNEL, left=0,right=0;
spin_lock_irqsave(&mgr->lock, flags);
left = card->ac97.mixer_state[oss_channel] & 0xff;
right = (card->ac97.mixer_state[oss_channel] >> 8) & 0xff;
if((left+=VOLCTRL_STEP_SIZE )>100)
left=100;
if((right+=VOLCTRL_STEP_SIZE )>100)
right=100;
emu10k1_set_oss_vol(card,oss_channel,left,right);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_voldecr_irqhandler(struct emu10k1_card *card)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
int oss_channel=VOLCTRL_CHANNEL, left=0,right=0;
spin_lock_irqsave(&mgr->lock, flags);
left = card->ac97.mixer_state[oss_channel] & 0xff;
right = (card->ac97.mixer_state[oss_channel] >> 8) & 0xff;
if((left-=VOLCTRL_STEP_SIZE )<0)
left=0;
if((right-=VOLCTRL_STEP_SIZE )<0)
right=0;
emu10k1_set_oss_vol(card,oss_channel,left,right);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_set_volume_gpr(struct emu10k1_card *card, int addr, s32 vol, int scale, int muting)
{
struct patch_manager *mgr = &card->mgr;
unsigned long flags;
const s32 log2lin[5] ={ // attenuation (dB)
0x7fffffff, // 0.0
0x7fffffff * 0.840896415253715 , // 1.5
0x7fffffff * 0.707106781186548, // 3.0
0x7fffffff * 0.594603557501361 , // 4.5
};
if (addr < 0)
return;
vol = (100 - vol ) * scale / 100;
// Thanks to the comp.dsp newsgroup for this neat trick:
vol = vol >= muting ? 0: log2lin[vol&3]>>(vol>>2);
spin_lock_irqsave(&mgr->lock, flags);
emu10k1_set_control_gpr(card, addr, vol, 0);
spin_unlock_irqrestore(&mgr->lock, flags);
}
void emu10k1_dsp_irqhandler(struct emu10k1_card *card)
{
unsigned long flags;
if (card->pt.state != PT_STATE_INACTIVE) {
u32 bc;
bc = sblive_readptr(card, GPR_BASE + card->pt.intr_gpr, 0);
if (bc != 0) {
spin_lock_irqsave(&card->lock, flags);
card->pt.blocks_played = bc;
if (card->pt.blocks_played >= card->pt.blocks_copied) {
DPF(1, "buffer underrun in passthrough playback\n");
emu10k1_pt_stop(card);
}
wake_up_interruptible(&card->pt.wait);
spin_unlock_irqrestore(&card->lock, flags);
DPD(3, "pt interrupt, bc = %d\n", bc);
}
}
}
...@@ -39,5 +39,204 @@ ...@@ -39,5 +39,204 @@
WRITE_EFX(card, (pc) * 2 + 1, ((op) << 20) | ((z) << 10) | (w)); \ WRITE_EFX(card, (pc) * 2 + 1, ((op) << 20) | ((z) << 10) | (w)); \
++pc; } while (0) ++pc; } while (0)
#define NUM_INPUTS 0x20
#define NUM_OUTPUTS 0x20
#define NUM_GPRS 0x100
#define GPR_NAME_SIZE 32
#define PATCH_NAME_SIZE 32
struct dsp_rpatch {
char name[PATCH_NAME_SIZE];
u16 code_start;
u16 code_size;
u32 gpr_used[NUM_GPRS / 32];
u32 gpr_input[NUM_GPRS / 32];
u32 route[NUM_OUTPUTS];
u32 route_v[NUM_OUTPUTS];
};
struct dsp_patch {
char name[PATCH_NAME_SIZE];
u8 id;
u32 input; /* bitmap of the lines used as inputs */
u32 output; /* bitmap of the lines used as outputs */
u16 code_start;
u16 code_size;
u32 gpr_used[NUM_GPRS / 32]; /* bitmap of used gprs */
u32 gpr_input[NUM_GPRS / 32];
u8 traml_istart; /* starting address of the internal tram lines used */ u8 traml_isize; /* number of internal tram lines used */
u8 traml_estart;
u8 traml_esize;
u16 tramb_istart; /* starting address of the internal tram memory used */
u16 tramb_isize; /* amount of internal memory used */
u32 tramb_estart;
u32 tramb_esize;
};
struct dsp_gpr {
u8 type; /* gpr type, STATIC, DYNAMIC, INPUT, OUTPUT, CONTROL */
char name[GPR_NAME_SIZE]; /* gpr value, only valid for control gprs */
s32 min, max; /* value range for this gpr, only valid for control gprs */
u8 line; /* which input/output line is the gpr attached, only valid for input/output gprs */
u8 usage;
};
enum {
GPR_TYPE_NULL = 0,
GPR_TYPE_IO,
GPR_TYPE_STATIC,
GPR_TYPE_DYNAMIC,
GPR_TYPE_CONTROL,
GPR_TYPE_CONSTANT
};
#define GPR_BASE 0x100
#define OUTPUT_BASE 0x20
//We can get this info by looking at the code start
//#define PATCH_TYPE_INPUT 0x1
//#define PATCH_TYPE_OUTPUT 0x2
#define MAX_PATCHES_PAGES 32
struct patch_manager {
void *patch[MAX_PATCHES_PAGES];
int current_pages;
struct dsp_rpatch rpatch;
struct dsp_gpr gpr[NUM_GPRS]; /* gpr usage table */
spinlock_t lock;
s16 ctrl_gpr[SOUND_MIXER_NRDEVICES][2];
};
#define PATCHES_PER_PAGE (PAGE_SIZE / sizeof(struct dsp_patch))
#define PATCH(mgr, i) ((struct dsp_patch *) (mgr)->patch[(i) / PATCHES_PER_PAGE] + (i) % PATCHES_PER_PAGE)
/* PCM volume control */
#define TMP_PCM_L 0x100 //temp PCM L (after the vol control)
#define TMP_PCM_R 0x101
#define VOL_PCM_L 0x102 //vol PCM
#define VOL_PCM_R 0x103
/* Routing patch */
#define TMP_AC_L 0x104 //tmp ac97 out
#define TMP_AC_R 0x105
#define TMP_REAR_L 0x106 //output - Temp Rear
#define TMP_REAR_R 0x107
#define TMP_DIGI_L 0x108 //output - Temp digital
#define TMP_DIGI_R 0x109
#define DSP_VOL_L 0x10a // main dsp volume
#define DSP_VOL_R 0x10b
/* hw inputs */
#define PCM_IN_L 0x00
#define PCM_IN_R 0x01
#define PCM1_IN_L 0x04
#define PCM1_IN_R 0x05
#define AC97_IN_L 0x10
#define AC97_IN_R 0x11
#define SPDIF_CD_L 0x12
#define SPDIF_CD_R 0x13
/* hw outputs */
#define AC97_FRONT_L 0x20
#define AC97_FRONT_R 0x21
#define DIGITAL_OUT_L 0x22
#define DIGITAL_OUT_R 0x23
#define ANALOG_REAR_L 0x28
#define ANALOG_REAR_R 0x29
#define ADC_REC_L 0x2a
#define ADC_REC_R 0x2b
#define INPUT_PATCH_START(patch, nm, ln, i) \
do { \
patch = PATCH(mgr, patch_n); \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
patch->input = (1<<(0x1f&ln)); \
patch->output= (1<<(0x1f&ln)); \
patch->id = i; \
} while(0)
#define INPUT_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
patch_n++; \
} while(0)
#define ROUTING_PATCH_START(patch, nm) \
do { \
patch = &mgr->rpatch; \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
} while(0)
#define ROUTING_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
} while(0)
#define CONNECT(input, output) set_bit(input, &rpatch->route[(output) - OUTPUT_BASE]);
#define CONNECT_V(input, output) set_bit(input, &rpatch->route_v[(output) - OUTPUT_BASE]);
#define OUTPUT_PATCH_START(patch, nm, ln, i) \
do { \
patch = PATCH(mgr, patch_n); \
strcpy(patch->name, nm); \
patch->code_start = pc * 2; \
patch->input = (1<<(0x1f&ln)); \
patch->output= (1<<(0x1f&ln)); \
patch->id = i; \
} while(0)
#define OUTPUT_PATCH_END(patch) \
do { \
patch->code_size = pc * 2 - patch->code_start; \
patch_n++; \
} while(0)
#define GET_OUTPUT_GPR(patch, g, ln) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].line = ln; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#define GET_INPUT_GPR(patch, g, ln) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_IO; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].line = ln; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
set_bit((g) - GPR_BASE, patch->gpr_input); \
} while(0)
#define GET_DYNAMIC_GPR(patch, g) \
do { \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_DYNAMIC; \
mgr->gpr[(g) - GPR_BASE].usage++; \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#define GET_CONTROL_GPR(patch, g, nm, a, b) \
do { \
strcpy(mgr->gpr[(g) - GPR_BASE].name, nm); \
mgr->gpr[(g) - GPR_BASE].type = GPR_TYPE_CONTROL; \
mgr->gpr[(g) - GPR_BASE].usage++; \
mgr->gpr[(g) - GPR_BASE].min = a; \
mgr->gpr[(g) - GPR_BASE].max = b; \
sblive_writeptr(card, g, 0, b); \
set_bit((g) - GPR_BASE, patch->gpr_used); \
} while(0)
#endif /* _EFXMGR_H */ #endif /* _EFXMGR_H */
#ifndef __EMU_WRAPPER_H
#define __EMU_WRAPPER_H
#define vma_get_pgoff(v) ((v)->vm_pgoff)
#define PCI_SET_DMA_MASK(pdev,mask) (((pdev)->dma_mask) = (mask))
#endif
...@@ -355,51 +355,33 @@ static void sblive_wcwait(struct emu10k1_card *card, u32 wait) ...@@ -355,51 +355,33 @@ static void sblive_wcwait(struct emu10k1_card *card, u32 wait)
} }
} }
int sblive_readac97(struct emu10k1_card *card, u8 index, u16 * data) u16 emu10k1_ac97_read(struct ac97_codec *codec, u8 reg)
{ {
struct emu10k1_card *card = codec->private_data;
u16 data;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&card->lock, flags); spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS); outb(reg, card->iobase + AC97ADDRESS);
*data = inw(card->iobase + AC97DATA); data = inw(card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags); spin_unlock_irqrestore(&card->lock, flags);
return 0; return data;
}
int sblive_writeac97(struct emu10k1_card *card, u8 index, u16 data)
{
unsigned long flags;
spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS);
outw(data, card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags);
return 0;
} }
int sblive_rmwac97(struct emu10k1_card *card, u8 index, u16 data, u16 mask) void emu10k1_ac97_write(struct ac97_codec *codec, u8 reg, u16 value)
{ {
u16 temp; struct emu10k1_card *card = codec->private_data;
unsigned long flags; unsigned long flags;
spin_lock_irqsave(&card->lock, flags); spin_lock_irqsave(&card->lock, flags);
outb(index, card->iobase + AC97ADDRESS); outb(reg, card->iobase + AC97ADDRESS);
temp = inw(card->iobase + AC97DATA); outw(value, card->iobase + AC97DATA);
temp &= ~mask;
data &= mask;
temp |= data;
outw(temp, card->iobase + AC97DATA);
spin_unlock_irqrestore(&card->lock, flags); spin_unlock_irqrestore(&card->lock, flags);
return 0;
} }
/********************************************************* /*********************************************************
......
...@@ -35,9 +35,12 @@ ...@@ -35,9 +35,12 @@
#include <linux/fs.h> #include <linux/fs.h>
#include <linux/sound.h> #include <linux/sound.h>
#include <linux/soundcard.h> #include <linux/soundcard.h>
#include <linux/ac97_codec.h>
#include <linux/pci.h> #include <linux/pci.h>
#include "emu_wrapper.h" #include "passthrough.h"
#include "efxmgr.h"
#include "midi.h"
#define EMUPAGESIZE 4096 /* don't change */ #define EMUPAGESIZE 4096 /* don't change */
#define NUM_G 64 /* use all channels */ #define NUM_G 64 /* use all channels */
...@@ -93,6 +96,38 @@ struct emu10k1_wavein ...@@ -93,6 +96,38 @@ struct emu10k1_wavein
u32 fxwc; u32 fxwc;
}; };
#define CMD_READ 1
#define CMD_WRITE 2
struct mixer_private_ioctl {
u32 cmd;
u32 val[90];
};
/* bogus ioctls numbers to escape from OSS mixer limitations */
#define CMD_WRITEFN0 _IOW('D', 0, struct mixer_private_ioctl)
#define CMD_READFN0 _IOR('D', 1, struct mixer_private_ioctl)
#define CMD_WRITEPTR _IOW('D', 2, struct mixer_private_ioctl)
#define CMD_READPTR _IOR('D', 3, struct mixer_private_ioctl)
#define CMD_SETRECSRC _IOW('D', 4, struct mixer_private_ioctl)
#define CMD_GETRECSRC _IOR('D', 5, struct mixer_private_ioctl)
#define CMD_GETVOICEPARAM _IOR('D', 6, struct mixer_private_ioctl)
#define CMD_SETVOICEPARAM _IOW('D', 7, struct mixer_private_ioctl)
#define CMD_GETPATCH _IOR('D', 8, struct mixer_private_ioctl)
#define CMD_GETGPR _IOR('D', 9, struct mixer_private_ioctl)
#define CMD_GETCTLGPR _IOR('D', 10, struct mixer_private_ioctl)
#define CMD_SETPATCH _IOW('D', 11, struct mixer_private_ioctl)
#define CMD_SETGPR _IOW('D', 12, struct mixer_private_ioctl)
#define CMD_SETCTLGPR _IOW('D', 13, struct mixer_private_ioctl)
#define CMD_SETGPOUT _IOW('D', 14, struct mixer_private_ioctl)
#define CMD_GETGPR2OSS _IOR('D', 15, struct mixer_private_ioctl)
#define CMD_SETGPR2OSS _IOW('D', 16, struct mixer_private_ioctl)
#define CMD_SETMCH_FX _IOW('D', 17, struct mixer_private_ioctl)
#define CMD_SETPASSTHROUGH _IOW('D', 18, struct mixer_private_ioctl)
struct oss_scaling {
char scale, muting;
};
struct emu10k1_card struct emu10k1_card
{ {
...@@ -117,20 +152,25 @@ struct emu10k1_card ...@@ -117,20 +152,25 @@ struct emu10k1_card
unsigned short model; unsigned short model;
unsigned int irq; unsigned int irq;
int audio_num; int audio_dev;
int audio1_num; int audio_dev1;
int mixer_num; int midi_dev;
int midi_num; #ifdef EMU10K1_SEQUENCER
int seq_dev;
struct emu10k1_mididevice *seq_mididev;
#endif
struct ac97_codec ac97;
int ac97_supported_mixers;
int ac97_stereo_mixers;
/* Number of first fx voice for multichannel output */
u8 mchannel_fx;
struct emu10k1_waveout waveout; struct emu10k1_waveout waveout;
struct emu10k1_wavein wavein; struct emu10k1_wavein wavein;
struct emu10k1_mpuout *mpuout; struct emu10k1_mpuout *mpuout;
struct emu10k1_mpuin *mpuin; struct emu10k1_mpuin *mpuin;
u16 arrwVol[SOUND_MIXER_NRDEVICES + 1];
/* array is used from the member 1 to save (-1) operation */
u32 digmix[9 * 6 * 2];
unsigned int modcnt;
struct semaphore open_sem; struct semaphore open_sem;
mode_t open_mode; mode_t open_mode;
wait_queue_head_t open_wait; wait_queue_head_t open_wait;
...@@ -141,26 +181,25 @@ struct emu10k1_card ...@@ -141,26 +181,25 @@ struct emu10k1_card
u8 chiprev; /* Chip revision */ u8 chiprev; /* Chip revision */
int isaps; int isaps;
struct patch_manager mgr;
struct pt_data pt;
}; };
int emu10k1_addxmgr_alloc(u32, struct emu10k1_card *); int emu10k1_addxmgr_alloc(u32, struct emu10k1_card *);
void emu10k1_addxmgr_free(struct emu10k1_card *, int); void emu10k1_addxmgr_free(struct emu10k1_card *, int);
#ifdef PRIVATE_PCM_VOLUME
#define MAX_PCM_CHANNELS NUM_G int emu10k1_find_control_gpr(struct patch_manager *, const char *, const char *);
struct sblive_pcm_volume_rec { void emu10k1_set_control_gpr(struct emu10k1_card *, int , s32, int );
struct files_struct *files; // identification of the same thread
u8 attn_l; // attenuation for left channel void emu10k1_set_volume_gpr(struct emu10k1_card *, int, s32, int, int);
u8 attn_r; // attenuation for right channel
u16 mixer; // saved mixer value for return
u8 channel_l; // idx of left channel #define VOL_6BIT 0x40,0x40
u8 channel_r; // idx of right channel #define VOL_5BIT 0x20,0x20
int opened; // counter - locks element #define VOL_4BIT 0x10,0x7f
};
extern struct sblive_pcm_volume_rec sblive_pcm_volume[];
extern u16 pcm_last_mixer;
#endif
#define TIMEOUT 16384 #define TIMEOUT 16384
...@@ -185,10 +224,9 @@ void emu10k1_irq_disable(struct emu10k1_card *, u32); ...@@ -185,10 +224,9 @@ void emu10k1_irq_disable(struct emu10k1_card *, u32);
void emu10k1_set_stop_on_loop(struct emu10k1_card *, u32); void emu10k1_set_stop_on_loop(struct emu10k1_card *, u32);
void emu10k1_clear_stop_on_loop(struct emu10k1_card *, u32); void emu10k1_clear_stop_on_loop(struct emu10k1_card *, u32);
/* AC97 Mixer access function */ /* AC97 Codec register access function */
int sblive_readac97(struct emu10k1_card *, u8, u16 *); u16 emu10k1_ac97_read(struct ac97_codec *, u8);
int sblive_writeac97(struct emu10k1_card *, u8, u16); void emu10k1_ac97_write(struct ac97_codec *, u8, u16);
int sblive_rmwac97(struct emu10k1_card *, u8, u16, u16);
/* MPU access function*/ /* MPU access function*/
int emu10k1_mpu_write_data(struct emu10k1_card *, u8); int emu10k1_mpu_write_data(struct emu10k1_card *, u8);
......
...@@ -34,12 +34,15 @@ ...@@ -34,12 +34,15 @@
struct wave_format struct wave_format
{ {
int id;
int samplingrate; int samplingrate;
u8 bitsperchannel; u8 bitsperchannel;
u8 channels; /* 1 = Mono, 2 = Stereo */ u8 channels; /* 1 = Mono, 2 = Stereo, 3, ... = Multichannel */
u8 bytesperchannel; u8 bytesperchannel;
u8 bytespervoicesample;
u8 bytespersample; u8 bytespersample;
int bytespersec; int bytespersec;
u8 passthrough;
}; };
/* emu10k1_wave states */ /* emu10k1_wave states */
......
...@@ -41,10 +41,7 @@ ...@@ -41,10 +41,7 @@
void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs) void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{ {
struct emu10k1_card *card = (struct emu10k1_card *) dev_id; struct emu10k1_card *card = (struct emu10k1_card *) dev_id;
u32 irqstatus, tmp; u32 irqstatus;
if (!(irqstatus = emu10k1_readfn0(card, IPR)))
return;
DPD(4, "emu10k1_interrupt called, irq = %u\n", irq); DPD(4, "emu10k1_interrupt called, irq = %u\n", irq);
...@@ -60,16 +57,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs) ...@@ -60,16 +57,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
** - Eric ** - Eric
*/ */
do { while ((irqstatus = inl(card->iobase + IPR))) {
DPD(4, "irq status %x\n", irqstatus); DPD(4, "irq status %#x\n", irqstatus);
tmp = irqstatus; /* acknowledge interrupt */
outl(irqstatus, card->iobase + IPR);
if (irqstatus & IRQTYPE_TIMER) { if (irqstatus & IRQTYPE_TIMER) {
emu10k1_timer_irqhandler(card); emu10k1_timer_irqhandler(card);
irqstatus &= ~IRQTYPE_TIMER; irqstatus &= ~IRQTYPE_TIMER;
} }
if (irqstatus & IRQTYPE_DSP) {
emu10k1_dsp_irqhandler(card);
irqstatus &= ~IRQTYPE_DSP;
}
if (irqstatus & IRQTYPE_MPUIN) { if (irqstatus & IRQTYPE_MPUIN) {
emu10k1_mpuin_irqhandler(card); emu10k1_mpuin_irqhandler(card);
irqstatus &= ~IRQTYPE_MPUIN; irqstatus &= ~IRQTYPE_MPUIN;
...@@ -80,13 +83,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs) ...@@ -80,13 +83,22 @@ void emu10k1_interrupt(int irq, void *dev_id, struct pt_regs *regs)
irqstatus &= ~IRQTYPE_MPUOUT; irqstatus &= ~IRQTYPE_MPUOUT;
} }
if (irqstatus) if (irqstatus & IPR_MUTE) {
emu10k1_irq_disable(card, irqstatus); emu10k1_mute_irqhandler(card);
irqstatus &=~IPR_MUTE;
}
emu10k1_writefn0(card, IPR, tmp); if (irqstatus & IPR_VOLINCR) {
emu10k1_volincr_irqhandler(card);
irqstatus &=~IPR_VOLINCR;
}
} while ((irqstatus = emu10k1_readfn0(card, IPR))); if (irqstatus & IPR_VOLDECR) {
emu10k1_voldecr_irqhandler(card);
irqstatus &=~IPR_VOLDECR;
}
return; if (irqstatus)
emu10k1_irq_disable(card, irqstatus);
}
} }
...@@ -44,5 +44,9 @@ ...@@ -44,5 +44,9 @@
#define IRQTYPE_DSP IPR_FXDSP #define IRQTYPE_DSP IPR_FXDSP
void emu10k1_timer_irqhandler(struct emu10k1_card *); void emu10k1_timer_irqhandler(struct emu10k1_card *);
void emu10k1_dsp_irqhandler(struct emu10k1_card *);
void emu10k1_mute_irqhandler(struct emu10k1_card *);
void emu10k1_volincr_irqhandler(struct emu10k1_card *);
void emu10k1_voldecr_irqhandler(struct emu10k1_card *);
#endif /* _IRQ_H */ #endif /* _IRQ_H */
/*
**********************************************************************
* joystick.c - Creative EMU10K1 Joystick port driver
* Copyright 2000 Rui Sousa.
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* April 1, 2000 Rui Sousa initial version
* April 28, 2000 Rui Sousa fixed a kernel oops,
* make use of kcompat24 for
* 2.2 kernels compatibility.
* May 1, 2000 Rui Sousa improved kernel compatibility
* layer.
*
**********************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*
**********************************************************************/
#include <linux/module.h>
#include <linux/init.h>
#include <linux/version.h>
#include <linux/pci.h>
#include <linux/slab.h>
#include <linux/ioport.h>
#include <linux/list.h>
#define DRIVER_VERSION "0.3.1"
#ifndef PCI_VENDOR_ID_CREATIVE
#define PCI_VENDOR_ID_CREATIVE 0x1102
#endif
#ifndef PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK
#define PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK 0x7002
#endif
/* PCI function 1 registers, address = <val> + PCIBASE1 */
#define JOYSTICK1 0x00 /* Analog joystick port register */
#define JOYSTICK2 0x01 /* Analog joystick port register */
#define JOYSTICK3 0x02 /* Analog joystick port register */
#define JOYSTICK4 0x03 /* Analog joystick port register */
#define JOYSTICK5 0x04 /* Analog joystick port register */
#define JOYSTICK6 0x05 /* Analog joystick port register */
#define JOYSTICK7 0x06 /* Analog joystick port register */
#define JOYSTICK8 0x07 /* Analog joystick port register */
/* When writing, any write causes JOYSTICK_COMPARATOR output enable to be pulsed on write. */
/* When reading, use these bitfields: */
#define JOYSTICK_BUTTONS 0x0f /* Joystick button data */
#define JOYSTICK_COMPARATOR 0xf0 /* Joystick comparator data */
#define NR_DEV 5
static int io[NR_DEV] = { 0, };
enum {
EMU10K1_JOYSTICK = 0
};
static char *card_names[] = {
"EMU10K1 Joystick Port"
};
static struct pci_device_id emu10k1_joy_pci_tbl[] __devinitdata = {
{PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_EMU10K1_JOYSTICK,
PCI_ANY_ID, PCI_ANY_ID, 0, 0, EMU10K1_JOYSTICK},
{0,}
};
MODULE_DEVICE_TABLE(pci, emu10k1_joy_pci_tbl);
struct emu10k1_joy_card {
struct list_head list;
struct pci_dev *pci_dev;
unsigned long iobase;
unsigned long length;
u8 addr_changed;
};
static LIST_HEAD(emu10k1_joy_devs);
static unsigned int devindex = 0;
/* Driver initialization routine */
static int __devinit emu10k1_joy_probe(struct pci_dev *pci_dev, const struct pci_device_id *pci_id)
{
struct emu10k1_joy_card *card;
u16 model;
u8 chiprev;
if ((card = kmalloc(sizeof(struct emu10k1_joy_card), GFP_KERNEL)) == NULL) {
printk(KERN_ERR "emu10k1-joy: out of memory\n");
return -ENOMEM;
}
memset(card, 0, sizeof(struct emu10k1_joy_card));
if (pci_enable_device(pci_dev)) {
printk(KERN_ERR "emu10k1-joy: couldn't enable device\n");
kfree(card);
return -ENODEV;
}
card->iobase = pci_resource_start(pci_dev, 0);
card->length = pci_resource_len(pci_dev, 0);
if (request_region(card->iobase, card->length, card_names[pci_id->driver_data])
== NULL) {
printk(KERN_ERR "emu10k1-joy: IO space in use\n");
kfree(card);
return -ENODEV;
}
pci_set_drvdata(pci_dev, card);
card->pci_dev = pci_dev;
card->addr_changed = 0;
pci_read_config_byte(pci_dev, PCI_REVISION_ID, &chiprev);
pci_read_config_word(pci_dev, PCI_SUBSYSTEM_ID, &model);
printk(KERN_INFO "emu10k1-joy: %s rev %d model 0x%x found, IO at 0x%04lx-0x%04lx\n",
card_names[pci_id->driver_data], chiprev, model, card->iobase,
card->iobase + card->length - 1);
if (io[devindex]) {
if ((io[devindex] & ~0x18) != 0x200) {
printk(KERN_ERR "emu10k1-joy: invalid io value\n");
release_region(card->iobase, card->length);
kfree(card);
return -ENODEV;
}
card->addr_changed = 1;
pci_write_config_dword(pci_dev, PCI_BASE_ADDRESS_0, io[devindex]);
printk(KERN_INFO "emu10k1-joy: IO ports mirrored at 0x%03x\n", io[devindex]);
}
list_add(&card->list, &emu10k1_joy_devs);
devindex++;
return 0;
}
static void __devexit emu10k1_joy_remove(struct pci_dev *pci_dev)
{
struct emu10k1_joy_card *card = pci_get_drvdata(pci_dev);
if(card->addr_changed)
pci_write_config_dword(pci_dev, PCI_BASE_ADDRESS_0, card->iobase);
release_region(card->iobase, card->length);
list_del(&card->list);
kfree(card);
pci_set_drvdata(pci_dev, NULL);
}
MODULE_PARM(io, "1-" __MODULE_STRING(NR_DEV) "i");
MODULE_PARM_DESC(io, "sets joystick port address");
MODULE_AUTHOR("Rui Sousa (Email to: emu10k1-devel@opensource.creative.com)");
MODULE_DESCRIPTION("Creative EMU10K1 PCI Joystick Port v" DRIVER_VERSION
"\nCopyright (C) 2000 Rui Sousa");
static struct pci_driver emu10k1_joy_pci_driver = {
name:"emu10k1 joystick",
id_table:emu10k1_joy_pci_tbl,
probe:emu10k1_joy_probe,
remove:emu10k1_joy_remove,
};
static int __init emu10k1_joy_init_module(void)
{
printk(KERN_INFO "Creative EMU10K1 PCI Joystick Port, version " DRIVER_VERSION ", " __TIME__
" " __DATE__ "\n");
return pci_module_init(&emu10k1_joy_pci_driver);
}
static void __exit emu10k1_joy_cleanup_module(void)
{
pci_unregister_driver(&emu10k1_joy_pci_driver);
return;
}
module_init(emu10k1_joy_init_module);
module_exit(emu10k1_joy_cleanup_module);
...@@ -31,8 +31,10 @@ ...@@ -31,8 +31,10 @@
* *
* Supported devices: * Supported devices:
* /dev/dsp: Standard /dev/dsp device, OSS-compatible * /dev/dsp: Standard /dev/dsp device, OSS-compatible
* /dev/dsp1: Routes to rear speakers only
* /dev/mixer: Standard /dev/mixer device, OSS-compatible * /dev/mixer: Standard /dev/mixer device, OSS-compatible
* /dev/midi: Raw MIDI UART device, mostly OSS-compatible * /dev/midi: Raw MIDI UART device, mostly OSS-compatible
* /dev/sequencer: Sequencer Interface (requires sound.o)
* *
* Revision history: * Revision history:
* 0.1 beta Initial release * 0.1 beta Initial release
...@@ -45,9 +47,27 @@ ...@@ -45,9 +47,27 @@
* code reorganization and cleanup. * code reorganization and cleanup.
* 0.7 Support for the Emu-APS. Bug fixes for voice cache setup, mmaped sound + poll(). * 0.7 Support for the Emu-APS. Bug fixes for voice cache setup, mmaped sound + poll().
* Support for setting external TRAM size. * Support for setting external TRAM size.
* 0.8 Make use of the kernel ac97 interface. Support for a dsp patch manager.
* 0.9 Re-enables rear speakers volume controls
* 0.10 Initializes rear speaker volume.
* Dynamic patch storage allocation.
* New private ioctls to change control gpr values.
* Enable volume control interrupts.
* By default enable dsp routes to digital out.
* 0.11 Fixed fx / 4 problem.
* 0.12 Implemented mmaped for recording.
* Fixed bug: not unreserving mmaped buffer pages.
* IRQ handler cleanup.
* 0.13 Fixed problem with dsp1
* Simplified dsp patch writing (inside the driver)
* Fixed several bugs found by the Stanford tools
* 0.14 New control gpr to oss mixer mapping feature (Chris Purnell)
* Added AC3 Passthrough Support (Juha Yrjola)
* Added Support for 5.1 cards (digital out and the third analog out)
* 0.15 Added Sequencer Support (Daniel Mack)
* Support for multichannel pcm playback (Eduard Hasenleithner)
* *
********************************************************************** *********************************************************************/
*/
/* These are only included once per module */ /* These are only included once per module */
#include <linux/version.h> #include <linux/version.h>
...@@ -55,6 +75,7 @@ ...@@ -55,6 +75,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/delay.h> #include <linux/delay.h>
#include <linux/proc_fs.h>
#include "hwaccess.h" #include "hwaccess.h"
#include "8010.h" #include "8010.h"
...@@ -66,7 +87,19 @@ ...@@ -66,7 +87,19 @@
#include "recmgr.h" #include "recmgr.h"
#include "ecard.h" #include "ecard.h"
#define DRIVER_VERSION "0.7"
#ifdef EMU10K1_SEQUENCER
#define MIDI_SYNTH_NAME "EMU10K1 MIDI"
#define MIDI_SYNTH_CAPS SYNTH_CAP_INPUT
#include "sound_config.h"
#include "midi_synth.h"
/* this should be in dev_table.h */
#define SNDCARD_EMU10K1 46
#endif
#define DRIVER_VERSION "0.15"
/* FIXME: is this right? */ /* FIXME: is this right? */
/* does the card support 32 bit bus master?*/ /* does the card support 32 bit bus master?*/
...@@ -106,124 +139,164 @@ extern struct file_operations emu10k1_audio_fops; ...@@ -106,124 +139,164 @@ extern struct file_operations emu10k1_audio_fops;
extern struct file_operations emu10k1_mixer_fops; extern struct file_operations emu10k1_mixer_fops;
extern struct file_operations emu10k1_midi_fops; extern struct file_operations emu10k1_midi_fops;
#ifdef EMU10K1_SEQUENCER
static struct midi_operations emu10k1_midi_operations;
#endif
extern void emu10k1_interrupt(int, void *, struct pt_regs *s); extern void emu10k1_interrupt(int, void *, struct pt_regs *s);
extern int emu10k1_mixer_wrch(struct emu10k1_card *, unsigned int, int);
static void __devinit audio_init(struct emu10k1_card *card) static int __devinit emu10k1_audio_init(struct emu10k1_card *card)
{ {
card->audio_dev = register_sound_dsp(&emu10k1_audio_fops, -1);
if (card->audio_dev < 0) {
printk(KERN_ERR "emu10k1: cannot register first audio device!\n");
goto err_dev;
}
card->audio_dev1 = register_sound_dsp(&emu10k1_audio_fops, -1);
if (card->audio_dev1 < 0) {
printk(KERN_ERR "emu10k1: cannot register second audio device!\n");
goto err_dev1;
}
/* Assign default playback voice parameters */ /* Assign default playback voice parameters */
card->mchannel_fx = 8;
/* mono voice */ /* mono voice */
card->waveout.send_a[0] = 0x00; card->waveout.send_a[0] = 0xff;
card->waveout.send_b[0] = 0xff; card->waveout.send_b[0] = 0xff;
card->waveout.send_c[0] = 0xff; card->waveout.send_c[0] = 0x00;
card->waveout.send_d[0] = 0x00; card->waveout.send_d[0] = 0x00;
card->waveout.send_routing[0] = 0xd01c; card->waveout.send_routing[0] = 0x3210;
/* stereo voice */ /* stereo voice */
card->waveout.send_a[1] = 0x00; /* left */
card->waveout.send_a[1] = 0xff;
card->waveout.send_b[1] = 0x00; card->waveout.send_b[1] = 0x00;
card->waveout.send_c[1] = 0xff; card->waveout.send_c[1] = 0x00;
card->waveout.send_d[1] = 0x00; card->waveout.send_d[1] = 0x00;
card->waveout.send_routing[1] = 0xd01c; card->waveout.send_routing[1] = 0x3210;
/* right */
card->waveout.send_a[2] = 0x00; card->waveout.send_a[2] = 0x00;
card->waveout.send_b[2] = 0xff; card->waveout.send_b[2] = 0xff;
card->waveout.send_c[2] = 0x00; card->waveout.send_c[2] = 0x00;
card->waveout.send_d[2] = 0x00; card->waveout.send_d[2] = 0x00;
card->waveout.send_routing[2] = 0xd01c; card->waveout.send_routing[2] = 0x3210;
/* Assign default recording parameters */ /* Assign default recording parameters */
/* FIXME */
if(card->isaps) if(card->isaps)
card->wavein.recsrc = WAVERECORD_FX; card->wavein.recsrc = WAVERECORD_FX;
else else
card->wavein.recsrc = WAVERECORD_AC97; card->wavein.recsrc = WAVERECORD_AC97;
card->wavein.fxwc = 0x0003; card->wavein.fxwc = 0x0003;
return 0;
return; err_dev1:
unregister_sound_dsp(card->audio_dev);
err_dev:
return -ENODEV;
}
static void __devinit emu10k1_audio_cleanup(struct emu10k1_card *card)
{
unregister_sound_dsp(card->audio_dev1);
unregister_sound_dsp(card->audio_dev);
} }
static void __devinit mixer_init(struct emu10k1_card *card) static int __devinit emu10k1_mixer_init(struct emu10k1_card *card)
{ {
int count; char s[32];
struct initvol { card->ac97.dev_mixer = register_sound_mixer(&emu10k1_mixer_fops, -1);
int mixch; if (card->ac97.dev_mixer < 0) {
int vol; printk(KERN_ERR "emu10k1: cannot register mixer device\n");
} initvol[] = { return -EIO;
{
SOUND_MIXER_VOLUME, 0x5050}, {
SOUND_MIXER_OGAIN, 0x3232}, {
SOUND_MIXER_SPEAKER, 0x3232}, {
SOUND_MIXER_PHONEIN, 0x3232}, {
SOUND_MIXER_MIC, 0x0000}, {
SOUND_MIXER_LINE, 0x0000}, {
SOUND_MIXER_CD, 0x4b4b}, {
SOUND_MIXER_LINE1, 0x4b4b}, {
SOUND_MIXER_LINE3, 0x3232}, {
SOUND_MIXER_DIGITAL1, 0x6464}, {
SOUND_MIXER_DIGITAL2, 0x6464}, {
SOUND_MIXER_PCM, 0x6464}, {
SOUND_MIXER_RECLEV, 0x0404}, {
SOUND_MIXER_TREBLE, 0x3232}, {
SOUND_MIXER_BASS, 0x3232}, {
SOUND_MIXER_LINE2, 0x4b4b}};
int initdig[] = { 0, 1, 2, 3, 6, 7, 18, 19, 20, 21, 24, 25, 72, 73, 74, 75, 78, 79,
94, 95
};
for (count = 0; count < sizeof(card->digmix) / sizeof(card->digmix[0]); count++) {
card->digmix[count] = 0x80000000;
sblive_writeptr(card, FXGPREGBASE + 0x10 + count, 0, 0);
}
card->modcnt = 0; // Should this be here or in open() ?
if (!card->isaps) {
for (count = 0; count < sizeof(initdig) / sizeof(initdig[0]); count++) {
card->digmix[initdig[count]] = 0x7fffffff;
sblive_writeptr(card, FXGPREGBASE + 0x10 + initdig[count], 0, 0x7fffffff);
}
/* Reset */
sblive_writeac97(card, AC97_RESET, 0);
#if 0
/* Check status word */
{
u16 reg;
sblive_readac97(card, AC97_RESET, &reg);
DPD(2, "RESET 0x%x\n", reg);
sblive_readac97(card, AC97_MASTERTONE, &reg);
DPD(2, "MASTER_TONE 0x%x\n", reg);
} }
#endif
/* Set default recording source to mic in */ card->ac97.private_data = card;
sblive_writeac97(card, AC97_RECORDSELECT, 0);
/* Set default AC97 "PCM" volume to acceptable max */ if(!card->isaps) {
//sblive_writeac97(card, AC97_PCMOUTVOLUME, 0); card->ac97.id = 0;
//sblive_writeac97(card, AC97_LINE2, 0); card->ac97.codec_read = emu10k1_ac97_read;
card->ac97.codec_write = emu10k1_ac97_write;
if (ac97_probe_codec (&card->ac97) == 0) {
printk(KERN_ERR "emu10k1: unable to probe AC97 codec\n");
goto err_out;
} }
/* 5.1: Enable the additional AC97 Slots. If the emu10k1 version
does not support this, it shouldn't do any harm */
sblive_writeptr(card, AC97SLOT, 0, AC97SLOT_CNTR|AC97SLOT_LFE);
/* Set default volumes for all mixer channels */
for (count = 0; count < sizeof(initvol) / sizeof(initvol[0]); count++) { if (!proc_mkdir ("driver/emu10k1", 0)) {
emu10k1_mixer_wrch(card, initvol[count].mixch, initvol[count].vol); printk(KERN_ERR "emu10k1: unable to create proc directory driver/emu10k1\n");
goto err_out;
} }
return; sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
if (!proc_mkdir (s, 0)) {
printk(KERN_ERR "emu10k1: unable to create proc directory %s\n", s);
goto err_emu10k1_proc;
}
sprintf(s, "driver/emu10k1/%s/ac97", card->pci_dev->slot_name);
if (!create_proc_read_entry (s, 0, 0, ac97_read_proc, &card->ac97)) {
printk(KERN_ERR "emu10k1: unable to create proc entry %s\n", s);
goto err_ac97_proc;
}
card->ac97_supported_mixers = card->ac97.supported_mixers;
card->ac97_stereo_mixers = card->ac97.stereo_mixers;
}
return 0;
err_ac97_proc:
sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
remove_proc_entry(s, NULL);
err_emu10k1_proc:
remove_proc_entry("driver/emu10k1", NULL);
err_out:
unregister_sound_mixer (card->ac97.dev_mixer);
return -EIO;
}
static void __devinit emu10k1_mixer_cleanup(struct emu10k1_card *card)
{
char s[32];
if(!card->isaps) {
sprintf(s, "driver/emu10k1/%s/ac97", card->pci_dev->slot_name);
remove_proc_entry(s, NULL);
sprintf(s, "driver/emu10k1/%s", card->pci_dev->slot_name);
remove_proc_entry(s, NULL);
remove_proc_entry("driver/emu10k1", NULL);
}
unregister_sound_mixer (card->ac97.dev_mixer);
} }
static int __devinit midi_init(struct emu10k1_card *card) static int __devinit emu10k1_midi_init(struct emu10k1_card *card)
{ {
if ((card->mpuout = kmalloc(sizeof(struct emu10k1_mpuout), GFP_KERNEL)) int ret;
== NULL) {
card->midi_dev = register_sound_midi(&emu10k1_midi_fops, -1);
if (card->midi_dev < 0) {
printk(KERN_ERR "emu10k1: cannot register midi device!\n");
return -ENODEV;
}
card->mpuout = kmalloc(sizeof(struct emu10k1_mpuout), GFP_KERNEL);
if (card->mpuout == NULL) {
printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n"); printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuout: out of memory\n");
return -1; ret = -ENOMEM;
goto err_out1;
} }
memset(card->mpuout, 0, sizeof(struct emu10k1_mpuout)); memset(card->mpuout, 0, sizeof(struct emu10k1_mpuout));
...@@ -236,10 +309,11 @@ static int __devinit midi_init(struct emu10k1_card *card) ...@@ -236,10 +309,11 @@ static int __devinit midi_init(struct emu10k1_card *card)
spin_lock_init(&card->mpuout->lock); spin_lock_init(&card->mpuout->lock);
if ((card->mpuin = kmalloc(sizeof(struct emu10k1_mpuin), GFP_KERNEL)) == NULL) { card->mpuin = kmalloc(sizeof(struct emu10k1_mpuin), GFP_KERNEL);
kfree(card->mpuout); if (card->mpuin == NULL) {
printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n"); printk(KERN_WARNING "emu10k1: Unable to allocate emu10k1_mpuin: out of memory\n");
return -1; ret = -ENOMEM;
goto err_out2;
} }
memset(card->mpuin, 0, sizeof(struct emu10k1_mpuin)); memset(card->mpuin, 0, sizeof(struct emu10k1_mpuin));
...@@ -253,10 +327,65 @@ static int __devinit midi_init(struct emu10k1_card *card) ...@@ -253,10 +327,65 @@ static int __devinit midi_init(struct emu10k1_card *card)
/* Reset the MPU port */ /* Reset the MPU port */
if (emu10k1_mpu_reset(card) < 0) { if (emu10k1_mpu_reset(card) < 0) {
ERROR(); ERROR();
return -1; ret = -EIO;
goto err_out3;
} }
#ifdef EMU10K1_SEQUENCER
card->seq_dev = sound_alloc_mididev();
if(card->seq_dev == -1)
printk(KERN_WARNING "emu10k1: unable to register sequencer device!");
else {
std_midi_synth.midi_dev = card->seq_dev;
midi_devs[card->seq_dev] =
(struct midi_operations *)
kmalloc(sizeof(struct midi_operations), GFP_KERNEL);
if(midi_devs[card->seq_dev] == NULL) {
printk(KERN_ERR "emu10k1: unable to allocate memory!");
sound_unload_mididev(card->seq_dev);
card->seq_dev = -1;
return 0; return 0;
} else {
memcpy((char *)midi_devs[card->seq_dev],
(char *)&emu10k1_midi_operations,
sizeof(struct midi_operations));
midi_devs[card->seq_dev]->devc = card;
sequencer_init();
}
}
card->seq_mididev = 0;
#endif
return 0;
err_out3:
kfree(card->mpuin);
err_out2:
kfree(card->mpuout);
err_out1:
unregister_sound_midi(card->midi_dev);
return ret;
}
static void __devinit emu10k1_midi_cleanup(struct emu10k1_card *card)
{
tasklet_unlock_wait(&card->mpuout->tasklet);
kfree(card->mpuout);
tasklet_unlock_wait(&card->mpuin->tasklet);
kfree(card->mpuin);
#ifdef EMU10K1_SEQUENCER
if(card->seq_dev > -1) {
kfree(midi_devs[card->seq_dev]);
midi_devs[card->seq_dev] = NULL;
sound_unload_mididev(card->seq_dev);
card->seq_dev = -1;
}
#endif
unregister_sound_midi(card->midi_dev);
} }
static void __devinit voice_init(struct emu10k1_card *card) static void __devinit voice_init(struct emu10k1_card *card)
...@@ -265,8 +394,6 @@ static void __devinit voice_init(struct emu10k1_card *card) ...@@ -265,8 +394,6 @@ static void __devinit voice_init(struct emu10k1_card *card)
for (i = 0; i < NUM_G; i++) for (i = 0; i < NUM_G; i++)
card->voicetable[i] = VOICE_USAGE_FREE; card->voicetable[i] = VOICE_USAGE_FREE;
return;
} }
static void __devinit timer_init(struct emu10k1_card *card) static void __devinit timer_init(struct emu10k1_card *card)
...@@ -274,8 +401,6 @@ static void __devinit timer_init(struct emu10k1_card *card) ...@@ -274,8 +401,6 @@ static void __devinit timer_init(struct emu10k1_card *card)
INIT_LIST_HEAD(&card->timers); INIT_LIST_HEAD(&card->timers);
card->timer_delay = TIMER_STOPPED; card->timer_delay = TIMER_STOPPED;
card->timer_lock = SPIN_LOCK_UNLOCKED; card->timer_lock = SPIN_LOCK_UNLOCKED;
return;
} }
static void __devinit addxmgr_init(struct emu10k1_card *card) static void __devinit addxmgr_init(struct emu10k1_card *card)
...@@ -289,17 +414,29 @@ static void __devinit addxmgr_init(struct emu10k1_card *card) ...@@ -289,17 +414,29 @@ static void __devinit addxmgr_init(struct emu10k1_card *card)
/* This page is reserved by the driver */ /* This page is reserved by the driver */
card->emupagetable[0] = 0x8001; card->emupagetable[0] = 0x8001;
card->emupagetable[1] = MAXPAGES - 1; card->emupagetable[1] = MAXPAGES - 1;
}
return; static void __devinit fx_cleanup(struct patch_manager *mgr)
{
int i;
for(i = 0; i < mgr->current_pages; i++)
free_page((unsigned long) mgr->patch[i]);
} }
static void __devinit fx_init(struct emu10k1_card *card) static int __devinit fx_init(struct emu10k1_card *card)
{ {
int i, j, k; struct patch_manager *mgr = &card->mgr;
#ifdef TONE_CONTROL struct dsp_patch *patch;
int l; struct dsp_rpatch *rpatch;
#endif s32 left, right;
int i;
u32 pc = 0; u32 pc = 0;
u32 patch_n;
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
mgr->ctrl_gpr[i][0] = -1;
mgr->ctrl_gpr[i][1] = -1;
}
for (i = 0; i < 512; i++) for (i = 0; i < 512; i++)
OP(6, 0x40, 0x40, 0x40, 0x40); OP(6, 0x40, 0x40, 0x40, 0x40);
...@@ -310,60 +447,175 @@ static void __devinit fx_init(struct emu10k1_card *card) ...@@ -310,60 +447,175 @@ static void __devinit fx_init(struct emu10k1_card *card)
TANKMEMADDRREGBASE + i, 0, TANKMEMADDRREGBASE + i, 0,
TAGLIST_END); TAGLIST_END);
pc = 0; mgr->current_pages = 5 / PATCHES_PER_PAGE + 1;
for(i = 0; i < mgr->current_pages; i++) {
for (j = 0; j < 2; j++) { mgr->patch[i] = (void *)__get_free_pages(GFP_KERNEL, 1);
if (mgr->patch[i] == NULL) {
OP(4, 0x100, 0x40, j, 0x44); mgr->current_pages = i;
OP(4, 0x101, 0x40, j + 2, 0x44); fx_cleanup(mgr);
return -ENOMEM;
for (i = 0; i < 6; i++) {
k = i * 18 + j;
OP(0, 0x102, 0x40, 0x110 + k, 0x100);
OP(0, 0x102, 0x102, 0x112 + k, 0x101);
OP(0, 0x102, 0x102, 0x114 + k, 0x10 + j);
OP(0, 0x102, 0x102, 0x116 + k, 0x12 + j);
OP(0, 0x102, 0x102, 0x118 + k, 0x14 + j);
OP(0, 0x102, 0x102, 0x11a + k, 0x16 + j);
OP(0, 0x102, 0x102, 0x11c + k, 0x18 + j);
OP(0, 0x102, 0x102, 0x11e + k, 0x1a + j);
#ifdef TONE_CONTROL
OP(0, 0x102, 0x102, 0x120 + k, 0x1c + j);
k = 0x1a0 + i * 8 + j * 4;
OP(0, 0x40, 0x40, 0x102, 0x180 + j);
OP(7, k + 1, k, k + 1, 0x184 + j);
OP(7, k, 0x102, k, 0x182 + j);
OP(7, k + 3, k + 2, k + 3, 0x188 + j);
OP(0, k + 2, 0x56, k + 2, 0x186 + j);
OP(6, k + 2, k + 2, k + 2, 0x40);
l = 0x1d0 + i * 8 + j * 4;
OP(0, 0x40, 0x40, k + 2, 0x190 + j);
OP(7, l + 1, l, l + 1, 0x194 + j);
OP(7, l, k + 2, l, 0x192 + j);
OP(7, l + 3, l + 2, l + 3, 0x198 + j);
OP(0, l + 2, 0x56, l + 2, 0x196 + j);
OP(4, l + 2, 0x40, l + 2, 0x46);
if ((i == 0) && !card->isaps)
OP(4, 0x20 + (i * 2) + j, 0x40, l + 2, 0x50); /* FIXME: Is this really needed? */
else
OP(6, 0x20 + (i * 2) + j, l + 2, 0x40, 0x40);
#else
OP(0, 0x20 + (i * 2) + j, 0x102, 0x120 + k, 0x1c + j);
#endif
} }
memset(mgr->patch[i], 0, PAGE_SIZE);
} }
pc = 0;
patch_n = 0;
/* FX volume correction */
INPUT_PATCH_START(patch, "Pcm L vol correction", 0x0, 0);
GET_OUTPUT_GPR(patch, 0x100, 0x0);
OP(4, 0x100, 0x40, PCM_IN_L, 0x44);
INPUT_PATCH_END(patch);
INPUT_PATCH_START(patch, "Pcm R vol correction", 0x1, 0);
GET_OUTPUT_GPR(patch, 0x101, 0x1);
OP(4, 0x101, 0x40, PCM_IN_R, 0x44);
INPUT_PATCH_END(patch);
ROUTING_PATCH_START(rpatch, "Routing");
GET_INPUT_GPR(rpatch, 0x100, 0x0);
GET_INPUT_GPR(rpatch, 0x101, 0x1);
GET_DYNAMIC_GPR(rpatch, 0x102);
GET_DYNAMIC_GPR(rpatch, 0x103);
GET_OUTPUT_GPR(rpatch, 0x104, 0x8);
GET_OUTPUT_GPR(rpatch, 0x105, 0x9);
GET_OUTPUT_GPR(rpatch, 0x10a, 0x2);
GET_OUTPUT_GPR(rpatch, 0x10b, 0x3);
GET_CONTROL_GPR(rpatch, 0x106, "Vol Pcm L:Rear L", 0, 0x7fffffff);
GET_CONTROL_GPR(rpatch, 0x107, "Vol Pcm R:Rear R", 0, 0x7fffffff);
/* input buffer */
OP(6, 0x102, AC97_IN_L, 0x40, 0x40);
OP(6, 0x103, AC97_IN_R, 0x40, 0x40);
/* Digital In + PCM --> AC97 out (front speakers)*/
OP(6, AC97_FRONT_L, 0x100, SPDIF_CD_L, 0x40);
CONNECT(PCM_IN_L, AC97_FRONT_L);
CONNECT(SPDIF_CD_L, AC97_FRONT_L);
OP(6, AC97_FRONT_R, 0x101, SPDIF_CD_R, 0x40);
CONNECT(PCM_IN_R, AC97_FRONT_R);
CONNECT(SPDIF_CD_R, AC97_FRONT_R);
/* Digital In + PCM + AC97 In + PCM1 --> Rear Channel */
OP(0, 0x104, PCM1_IN_L, 0x100, 0x106);
OP(6, 0x104, 0x104, SPDIF_CD_L, 0x102);
CONNECT(AC97_IN_L, ANALOG_REAR_L);
CONNECT_V(PCM_IN_L, ANALOG_REAR_L);
CONNECT(SPDIF_CD_L, ANALOG_REAR_L);
CONNECT(PCM1_IN_L, ANALOG_REAR_L);
OP(0, 0x105, PCM1_IN_R, 0x101, 0x107);
OP(6, 0x105, 0x105, SPDIF_CD_R, 0x103);
CONNECT(AC97_IN_R, ANALOG_REAR_R);
CONNECT_V(PCM_IN_R, ANALOG_REAR_R);
CONNECT(SPDIF_CD_R, ANALOG_REAR_R);
CONNECT(PCM1_IN_R, ANALOG_REAR_R);
/* Digital In + PCM + AC97 In --> Digital out */
OP(6, 0x10b, 0x100, 0x102, SPDIF_CD_L);
CONNECT(PCM_IN_L, DIGITAL_OUT_L);
CONNECT(AC97_IN_L, DIGITAL_OUT_L);
CONNECT(SPDIF_CD_L, DIGITAL_OUT_L);
OP(6, 0x10a, 0x101, 0x103, SPDIF_CD_R);
CONNECT(PCM_IN_R, DIGITAL_OUT_R);
CONNECT(AC97_IN_R, DIGITAL_OUT_R);
CONNECT(SPDIF_CD_R, DIGITAL_OUT_R);
/* AC97 In --> ADC Recording Buffer */
OP(6, ADC_REC_L, 0x102, 0x40, 0x40);
CONNECT(AC97_IN_L, ADC_REC_L);
OP(6, ADC_REC_R, 0x103, 0x40, 0x40);
CONNECT(AC97_IN_R, ADC_REC_R);
ROUTING_PATCH_END(rpatch);
// Master volume control on rear
OUTPUT_PATCH_START(patch, "Vol Master L", 0x8, 0);
GET_INPUT_GPR(patch, 0x104, 0x8);
GET_CONTROL_GPR(patch, 0x108, "Vol", 0, 0x7fffffff);
OP(0, ANALOG_REAR_L, 0x040, 0x104, 0x108);
OUTPUT_PATCH_END(patch);
OUTPUT_PATCH_START(patch, "Vol Master R", 0x9, 0);
GET_INPUT_GPR(patch, 0x105, 0x9);
GET_CONTROL_GPR(patch, 0x109, "Vol", 0, 0x7fffffff);
OP(0, ANALOG_REAR_R, 0x040, 0x105, 0x109);
OUTPUT_PATCH_END(patch);
//Master volume control on front-digital
OUTPUT_PATCH_START(patch, "Vol Master L", 0x2, 1);
GET_INPUT_GPR(patch, 0x10a, 0x2);
GET_CONTROL_GPR(patch, 0x108, "Vol", 0, 0x7fffffff);
OP(0, DIGITAL_OUT_L, 0x040, 0x10a, 0x108);
OUTPUT_PATCH_END(patch);
OUTPUT_PATCH_START(patch, "Vol Master R", 0x3, 1);
GET_INPUT_GPR(patch, 0x10b, 0x3);
GET_CONTROL_GPR(patch, 0x109, "Vol", 0, 0x7fffffff);
OP(0, DIGITAL_OUT_R, 0x040, 0x10b, 0x109);
OUTPUT_PATCH_END(patch);
/* delimiter patch */
patch = PATCH(mgr, patch_n);
patch->code_size = 0;
sblive_writeptr(card, DBG, 0, 0); sblive_writeptr(card, DBG, 0, 0);
return; mgr->lock = SPIN_LOCK_UNLOCKED;
mgr->ctrl_gpr[SOUND_MIXER_VOLUME][0] = 8;
mgr->ctrl_gpr[SOUND_MIXER_VOLUME][1] = 9;
left = card->ac97.mixer_state[SOUND_MIXER_VOLUME] & 0xff;
right = (card->ac97.mixer_state[SOUND_MIXER_VOLUME] >> 8) & 0xff;
emu10k1_set_volume_gpr(card, 8, left, VOL_6BIT);
emu10k1_set_volume_gpr(card, 9, right, VOL_6BIT);
mgr->ctrl_gpr[SOUND_MIXER_PCM][0] = 6;
mgr->ctrl_gpr[SOUND_MIXER_PCM][1] = 7;
left = card->ac97.mixer_state[SOUND_MIXER_PCM] & 0xff;
right = (card->ac97.mixer_state[SOUND_MIXER_PCM] >> 8) & 0xff;
emu10k1_set_volume_gpr(card, 6, left, VOL_5BIT);
emu10k1_set_volume_gpr(card, 7, right, VOL_5BIT);
return 0;
} }
static int __devinit hw_init(struct emu10k1_card *card) static int __devinit hw_init(struct emu10k1_card *card)
{ {
int nCh; int nCh;
u32 pagecount; /* tmp */ u32 pagecount; /* tmp */
int ret;
/* Disable audio and lock cache */ /* Disable audio and lock cache */
emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE); emu10k1_writefn0(card, HCFG, HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK | HCFG_MUTEBUTTONENABLE);
...@@ -454,29 +706,32 @@ static int __devinit hw_init(struct emu10k1_card *card) ...@@ -454,29 +706,32 @@ static int __devinit hw_init(struct emu10k1_card *card)
TAGLIST_END); TAGLIST_END);
fx_init(card); /* initialize effects engine */ ret = fx_init(card); /* initialize effects engine */
if (ret < 0)
return ret;
card->tankmem.size = 0; card->tankmem.size = 0;
card->virtualpagetable.size = MAXPAGES * sizeof(u32); card->virtualpagetable.size = MAXPAGES * sizeof(u32);
if ((card->virtualpagetable.addr = pci_alloc_consistent(card->pci_dev, card->virtualpagetable.size, &card->virtualpagetable.dma_handle)) == card->virtualpagetable.addr = pci_alloc_consistent(card->pci_dev, card->virtualpagetable.size, &card->virtualpagetable.dma_handle);
NULL) { if (card->virtualpagetable.addr == NULL) {
ERROR(); ERROR();
return -1; ret = -ENOMEM;
goto err0;
} }
card->silentpage.size = EMUPAGESIZE; card->silentpage.size = EMUPAGESIZE;
if ((card->silentpage.addr = pci_alloc_consistent(card->pci_dev, card->silentpage.size, &card->silentpage.dma_handle)) == NULL) { card->silentpage.addr = pci_alloc_consistent(card->pci_dev, card->silentpage.size, &card->silentpage.dma_handle);
if (card->silentpage.addr == NULL) {
ERROR(); ERROR();
pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle); ret = -ENOMEM;
return -1; goto err1;
} }
for (pagecount = 0; pagecount < MAXPAGES; pagecount++) for (pagecount = 0; pagecount < MAXPAGES; pagecount++)
((u32 *) card->virtualpagetable.addr)[pagecount] = ((u32 *) card->virtualpagetable.addr)[pagecount] = cpu_to_le32((card->silentpage.dma_handle * 2) | pagecount);
cpu_to_le32((card->silentpage.dma_handle * 2) | pagecount);
/* Init page table & tank memory base register */ /* Init page table & tank memory base register */
sblive_writeptr_tag(card, 0, sblive_writeptr_tag(card, 0,
...@@ -499,20 +754,29 @@ static int __devinit hw_init(struct emu10k1_card *card) ...@@ -499,20 +754,29 @@ static int __devinit hw_init(struct emu10k1_card *card)
/* Lock Sound Memory = 0 */ /* Lock Sound Memory = 0 */
/* Auto Mute = 1 */ /* Auto Mute = 1 */
sblive_rmwac97(card, AC97_MASTERVOLUME, 0x8000, 0x8000); if (card->model == 0x20 || card->model == 0xc400 ||
sblive_writeac97(card, AC97_MASTERVOLUME, 0);
sblive_writeac97(card, AC97_PCMOUTVOLUME, 0);
if(card->model == 0x20 || card->model == 0xc400 ||
(card->model == 0x21 && card->chiprev < 6)) (card->model == 0x21 && card->chiprev < 6))
emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE); emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE);
else else
emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE); emu10k1_writefn0(card, HCFG, HCFG_AUDIOENABLE | HCFG_LOCKTANKCACHE_MASK | HCFG_AUTOMUTE | HCFG_JOYENABLE);
/* Enable Vol_Ctrl irqs */
emu10k1_irq_enable(card, INTE_VOLINCRENABLE | INTE_VOLDECRENABLE | INTE_MUTEENABLE | INTE_FXDSPENABLE);
/* FIXME: TOSLink detection */ /* FIXME: TOSLink detection */
card->has_toslink = 0; card->has_toslink = 0;
/* Initialize digital passthrough variables */
card->pt.pos_gpr = card->pt.intr_gpr = card->pt.enable_gpr = -1;
card->pt.selected = 0;
card->pt.state = PT_STATE_INACTIVE;
card->pt.spcs_to_use = 0x01;
card->pt.patch_name = "AC3pass";
card->pt.intr_gpr_name = "count";
card->pt.enable_gpr_name = "enable";
card->pt.pos_gpr_name = "ptr";
init_waitqueue_head(&card->pt.wait);
/* tmp = sblive_readfn0(card, HCFG); /* tmp = sblive_readfn0(card, HCFG);
if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) { if (tmp & (HCFG_GPINPUT0 | HCFG_GPINPUT1)) {
sblive_writefn0(card, HCFG, tmp | 0x800); sblive_writefn0(card, HCFG, tmp | 0x800);
...@@ -526,6 +790,13 @@ static int __devinit hw_init(struct emu10k1_card *card) ...@@ -526,6 +790,13 @@ static int __devinit hw_init(struct emu10k1_card *card)
} }
*/ */
return 0; return 0;
err1:
pci_free_consistent(card->pci_dev, card->virtualpagetable.size, card->virtualpagetable.addr, card->virtualpagetable.dma_handle);
err0:
fx_cleanup(&card->mgr);
return ret;
} }
static int __devinit emu10k1_init(struct emu10k1_card *card) static int __devinit emu10k1_init(struct emu10k1_card *card)
...@@ -538,23 +809,12 @@ static int __devinit emu10k1_init(struct emu10k1_card *card) ...@@ -538,23 +809,12 @@ static int __devinit emu10k1_init(struct emu10k1_card *card)
timer_init(card); timer_init(card);
addxmgr_init(card); addxmgr_init(card);
DPD(2, " hw control register -> 0x%x\n", emu10k1_readfn0(card, HCFG)); DPD(2, " hw control register -> %#x\n", emu10k1_readfn0(card, HCFG));
return 0; return 0;
} }
static void __devexit midi_exit(struct emu10k1_card *card) static void __devinit emu10k1_cleanup(struct emu10k1_card *card)
{
tasklet_unlock_wait(&card->mpuout->tasklet);
kfree(card->mpuout);
tasklet_unlock_wait(&card->mpuin->tasklet);
kfree(card->mpuin);
return;
}
static void __devinit emu10k1_exit(struct emu10k1_card *card)
{ {
int ch; int ch;
...@@ -605,7 +865,8 @@ static void __devinit emu10k1_exit(struct emu10k1_card *card) ...@@ -605,7 +865,8 @@ static void __devinit emu10k1_exit(struct emu10k1_card *card)
if(card->tankmem.size != 0) if(card->tankmem.size != 0)
pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle); pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
return; /* release patch storage memory */
fx_cleanup(&card->mgr);
} }
/* Driver initialization routine */ /* Driver initialization routine */
...@@ -615,34 +876,32 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev ...@@ -615,34 +876,32 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev
u32 subsysvid; u32 subsysvid;
int ret; int ret;
if ((ret=pci_enable_device(pci_dev)))
return ret;
if ((card = kmalloc(sizeof(struct emu10k1_card), GFP_KERNEL)) == NULL) {
printk(KERN_ERR "emu10k1: out of memory\n");
return -ENOMEM;
}
memset(card, 0, sizeof(struct emu10k1_card));
if (pci_set_dma_mask(pci_dev, EMU10K1_DMA_MASK)) { if (pci_set_dma_mask(pci_dev, EMU10K1_DMA_MASK)) {
printk(KERN_ERR "emu10k1: architecture does not support 32bit PCI busmaster DMA\n"); printk(KERN_ERR "emu10k1: architecture does not support 32bit PCI busmaster DMA\n");
kfree(card);
return -ENODEV; return -ENODEV;
} }
if (pci_enable_device(pci_dev))
return -EIO;
pci_set_master(pci_dev); pci_set_master(pci_dev);
if ((card = kmalloc(sizeof(struct emu10k1_card), GFP_KERNEL)) == NULL) {
printk(KERN_ERR "emu10k1: out of memory\n");
return -ENOMEM;
}
memset(card, 0, sizeof(struct emu10k1_card));
card->iobase = pci_resource_start(pci_dev, 0); card->iobase = pci_resource_start(pci_dev, 0);
card->length = pci_resource_len(pci_dev, 0); card->length = pci_resource_len(pci_dev, 0);
if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) { if (request_region(card->iobase, card->length, card_names[pci_id->driver_data]) == NULL) {
printk(KERN_ERR "emu10k1: IO space in use\n"); printk(KERN_ERR "emu10k1: IO space in use\n");
kfree(card); ret = -EBUSY;
return -ENODEV; goto err_region;
} }
pci_set_drvdata(pci_dev, card); pci_set_drvdata(pci_dev, card);
PCI_SET_DMA_MASK(pci_dev, EMU10K1_DMA_MASK);
card->irq = pci_dev->irq; card->irq = pci_dev->irq;
card->pci_dev = pci_dev; card->pci_dev = pci_dev;
...@@ -650,6 +909,7 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev ...@@ -650,6 +909,7 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev
/* Reserve IRQ Line */ /* Reserve IRQ Line */
if (request_irq(card->irq, emu10k1_interrupt, SA_SHIRQ, card_names[pci_id->driver_data], card)) { if (request_irq(card->irq, emu10k1_interrupt, SA_SHIRQ, card_names[pci_id->driver_data], card)) {
printk(KERN_ERR "emu10k1: IRQ in use\n"); printk(KERN_ERR "emu10k1: IRQ in use\n");
ret = -EBUSY;
goto err_irq; goto err_irq;
} }
...@@ -668,40 +928,30 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev ...@@ -668,40 +928,30 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev
card->open_mode = 0; card->open_mode = 0;
init_waitqueue_head(&card->open_wait); init_waitqueue_head(&card->open_wait);
/* Register devices */ ret = emu10k1_audio_init(card);
if ((card->audio_num = register_sound_dsp(&emu10k1_audio_fops, -1)) < 0) { if(ret < 0) {
printk(KERN_ERR "emu10k1: cannot register first audio device!\n"); printk(KERN_ERR "emu10k1: cannot initialize audio devices\n");
goto err_dev0; goto err_audio;
}
if ((card->audio1_num = register_sound_dsp(&emu10k1_audio_fops, -1)) < 0) {
printk(KERN_ERR "emu10k1: cannot register second audio device!\n");
goto err_dev1;
} }
if ((card->mixer_num = register_sound_mixer(&emu10k1_mixer_fops, -1)) < 0) { ret = emu10k1_mixer_init(card);
printk(KERN_ERR "emu10k1: cannot register mixer device!\n"); if(ret < 0) {
goto err_dev2; printk(KERN_ERR "emu10k1: cannot initialize AC97 codec\n");
goto err_mixer;
} }
if ((card->midi_num = register_sound_midi(&emu10k1_midi_fops, -1)) < 0) { ret = emu10k1_midi_init(card);
printk(KERN_ERR "emu10k1: cannot register midi device!\n"); if (ret < 0) {
goto err_dev3; printk(KERN_ERR "emu10k1: cannot register midi device\n");
goto err_midi;
} }
if (emu10k1_init(card) < 0) { ret = emu10k1_init(card);
printk(KERN_ERR "emu10k1: cannot initialize device!\n"); if (ret < 0) {
printk(KERN_ERR "emu10k1: cannot initialize device\n");
goto err_emu10k1_init; goto err_emu10k1_init;
} }
if (midi_init(card) < 0) {
printk(KERN_ERR "emu10k1: cannot initialize midi!\n");
goto err_midi_init;
}
audio_init(card);
mixer_init(card);
if (card->isaps) if (card->isaps)
emu10k1_ecard_init(card); emu10k1_ecard_init(card);
...@@ -709,52 +959,41 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev ...@@ -709,52 +959,41 @@ static int __devinit emu10k1_probe(struct pci_dev *pci_dev, const struct pci_dev
return 0; return 0;
err_midi_init: err_emu10k1_init:
emu10k1_exit(card); emu10k1_midi_cleanup(card);
err_emu10k1_init:
unregister_sound_midi(card->midi_num);
err_dev3:
unregister_sound_mixer(card->mixer_num);
err_dev2: err_midi:
unregister_sound_dsp(card->audio1_num); emu10k1_mixer_cleanup(card);
err_dev1: err_mixer:
unregister_sound_dsp(card->audio_num); emu10k1_audio_cleanup(card);
err_dev0: err_audio:
free_irq(card->irq, card); free_irq(card->irq, card);
err_irq: err_irq:
release_region(card->iobase, card->length); release_region(card->iobase, card->length);
pci_set_drvdata(pci_dev, NULL);
err_region:
kfree(card); kfree(card);
return -ENODEV; return ret;
} }
static void __devexit emu10k1_remove(struct pci_dev *pci_dev) static void __devexit emu10k1_remove(struct pci_dev *pci_dev)
{ {
struct emu10k1_card *card = pci_get_drvdata(pci_dev); struct emu10k1_card *card = pci_get_drvdata(pci_dev);
midi_exit(card); list_del(&card->list);
emu10k1_exit(card);
unregister_sound_midi(card->midi_num);
unregister_sound_mixer(card->mixer_num);
unregister_sound_dsp(card->audio1_num);
unregister_sound_dsp(card->audio_num);
emu10k1_cleanup(card);
emu10k1_midi_cleanup(card);
emu10k1_mixer_cleanup(card);
emu10k1_audio_cleanup(card);
free_irq(card->irq, card); free_irq(card->irq, card);
release_region(card->iobase, card->length); release_region(card->iobase, card->length);
list_del(&card->list);
kfree(card); kfree(card);
pci_set_drvdata(pci_dev, NULL); pci_set_drvdata(pci_dev, NULL);
} }
...@@ -762,10 +1001,10 @@ MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@opensource.creat ...@@ -762,10 +1001,10 @@ MODULE_AUTHOR("Bertrand Lee, Cai Ying. (Email to: emu10k1-devel@opensource.creat
MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION "\nCopyright (C) 1999 Creative Technology Ltd."); MODULE_DESCRIPTION("Creative EMU10K1 PCI Audio Driver v" DRIVER_VERSION "\nCopyright (C) 1999 Creative Technology Ltd.");
static struct pci_driver emu10k1_pci_driver = { static struct pci_driver emu10k1_pci_driver = {
name:"emu10k1", name: "emu10k1",
id_table:emu10k1_pci_tbl, id_table: emu10k1_pci_tbl,
probe:emu10k1_probe, probe: emu10k1_probe,
remove:emu10k1_remove, remove: emu10k1_remove,
}; };
static int __init emu10k1_init_module(void) static int __init emu10k1_init_module(void)
...@@ -784,3 +1023,36 @@ static void __exit emu10k1_cleanup_module(void) ...@@ -784,3 +1023,36 @@ static void __exit emu10k1_cleanup_module(void)
module_init(emu10k1_init_module); module_init(emu10k1_init_module);
module_exit(emu10k1_cleanup_module); module_exit(emu10k1_cleanup_module);
#ifdef EMU10K1_SEQUENCER
/* in midi.c */
extern int emu10k1_seq_midi_open(int dev, int mode,
void (*input)(int dev, unsigned char midi_byte),
void (*output)(int dev));
extern void emu10k1_seq_midi_close(int dev);
extern int emu10k1_seq_midi_out(int dev, unsigned char midi_byte);
extern int emu10k1_seq_midi_start_read(int dev);
extern int emu10k1_seq_midi_end_read(int dev);
extern void emu10k1_seq_midi_kick(int dev);
extern int emu10k1_seq_midi_buffer_status(int dev);
static struct midi_operations emu10k1_midi_operations =
{
{"EMU10K1 MIDI", 0, 0, SNDCARD_EMU10K1},
&std_midi_synth,
{0},
emu10k1_seq_midi_open,
emu10k1_seq_midi_close,
NULL,
emu10k1_seq_midi_out,
emu10k1_seq_midi_start_read,
emu10k1_seq_midi_end_read,
emu10k1_seq_midi_kick,
NULL,
emu10k1_seq_midi_buffer_status,
NULL
};
#endif
/* /*
********************************************************************** **********************************************************************
* midi.c - /dev/midi interface for emu10k1 driver * midi.c - /dev/midi interface for emu10k1 driver
...@@ -43,6 +42,10 @@ ...@@ -43,6 +42,10 @@
#include "cardmi.h" #include "cardmi.h"
#include "midi.h" #include "midi.h"
#ifdef EMU10K1_SEQUENCER
#include "sound_config.h"
#endif
static spinlock_t midi_spinlock __attribute((unused)) = SPIN_LOCK_UNLOCKED; static spinlock_t midi_spinlock __attribute((unused)) = SPIN_LOCK_UNLOCKED;
static void init_midi_hdr(struct midi_hdr *midihdr) static void init_midi_hdr(struct midi_hdr *midihdr)
...@@ -85,23 +88,30 @@ static int midiin_add_buffer(struct emu10k1_mididevice *midi_dev, struct midi_hd ...@@ -85,23 +88,30 @@ static int midiin_add_buffer(struct emu10k1_mididevice *midi_dev, struct midi_hd
static int emu10k1_midi_open(struct inode *inode, struct file *file) static int emu10k1_midi_open(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = MINOR(inode->i_rdev);
struct emu10k1_card *card=NULL; struct emu10k1_card *card = NULL;
struct emu10k1_mididevice *midi_dev; struct emu10k1_mididevice *midi_dev;
struct list_head *entry; struct list_head *entry;
DPF(2, "emu10k1_midi_open()\n"); DPF(2, "emu10k1_midi_open()\n");
/* Check for correct device to open */ /* Check for correct device to open */
list_for_each(entry, &emu10k1_devs) { list_for_each(entry, &emu10k1_devs) {
card = list_entry(entry, struct emu10k1_card, list); card = list_entry(entry, struct emu10k1_card, list);
if (card->midi_num == minor) if (card->midi_dev == minor)
break; goto match;
} }
if (entry == &emu10k1_devs)
return -ENODEV; return -ENODEV;
match:
#ifdef EMU10K1_SEQUENCER
if(card->seq_mididev) /* card is opened by sequencer */
return -EBUSY;
#endif
/* Wait for device to become free */ /* Wait for device to become free */
down(&card->open_sem); down(&card->open_sem);
while (card->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) { while (card->open_mode & (file->f_mode << FMODE_MIDI_SHIFT)) {
...@@ -235,6 +245,7 @@ static int emu10k1_midi_release(struct inode *inode, struct file *file) ...@@ -235,6 +245,7 @@ static int emu10k1_midi_release(struct inode *inode, struct file *file)
unlock_kernel(); unlock_kernel();
return 0; return 0;
} }
...@@ -245,7 +256,7 @@ static ssize_t emu10k1_midi_read(struct file *file, char *buffer, size_t count, ...@@ -245,7 +256,7 @@ static ssize_t emu10k1_midi_read(struct file *file, char *buffer, size_t count,
u16 cnt; u16 cnt;
unsigned long flags; unsigned long flags;
DPD(4, "emu10k1_midi_read(), count %x\n", (u32) count); DPD(4, "emu10k1_midi_read(), count %#x\n", (u32) count);
if (pos != &file->f_pos) if (pos != &file->f_pos)
return -ESPIPE; return -ESPIPE;
...@@ -320,7 +331,7 @@ static ssize_t emu10k1_midi_write(struct file *file, const char *buffer, size_t ...@@ -320,7 +331,7 @@ static ssize_t emu10k1_midi_write(struct file *file, const char *buffer, size_t
ssize_t ret = 0; ssize_t ret = 0;
unsigned long flags; unsigned long flags;
DPD(4, "emu10k1_midi_write(), count=%x\n", (u32) count); DPD(4, "emu10k1_midi_write(), count=%#x\n", (u32) count);
if (pos != &file->f_pos) if (pos != &file->f_pos)
return -ESPIPE; return -ESPIPE;
...@@ -441,3 +452,154 @@ struct file_operations emu10k1_midi_fops = { ...@@ -441,3 +452,154 @@ struct file_operations emu10k1_midi_fops = {
open: emu10k1_midi_open, open: emu10k1_midi_open,
release: emu10k1_midi_release, release: emu10k1_midi_release,
}; };
#ifdef EMU10K1_SEQUENCER
/* functions used for sequencer access */
int emu10k1_seq_midi_open(int dev, int mode,
void (*input) (int dev, unsigned char data),
void (*output) (int dev))
{
struct emu10k1_card *card;
struct midi_openinfo dsCardMidiOpenInfo;
struct emu10k1_mididevice *midi_dev;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
card = midi_devs[dev]->devc;
if(card->open_mode) /* card is opened native */
return -EBUSY;
DPF(2, "emu10k1_seq_midi_open()\n");
if ((midi_dev = (struct emu10k1_mididevice *) kmalloc(sizeof(*midi_dev), GFP_KERNEL)) == NULL) {
return -EINVAL;
}
midi_dev->card = card;
midi_dev->mistate = MIDIIN_STATE_STOPPED;
init_waitqueue_head(&midi_dev->oWait);
init_waitqueue_head(&midi_dev->iWait);
midi_dev->ird = 0;
midi_dev->iwr = 0;
midi_dev->icnt = 0;
INIT_LIST_HEAD(&midi_dev->mid_hdrs);
dsCardMidiOpenInfo.refdata = (unsigned long) midi_dev;
if (emu10k1_mpuout_open(card, &dsCardMidiOpenInfo) < 0) {
ERROR();
return -ENODEV;
}
card->seq_mididev = midi_dev;
return 0;
}
void emu10k1_seq_midi_close(int dev)
{
struct emu10k1_card *card;
DPF(2, "emu10k1_seq_midi_close()\n");
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return;
card = midi_devs[dev]->devc;
emu10k1_mpuout_close(card);
if(card->seq_mididev) {
kfree(card->seq_mididev);
card->seq_mididev = 0;
}
}
int emu10k1_seq_midi_out(int dev, unsigned char midi_byte)
{
struct emu10k1_card *card;
struct midi_hdr *midihdr;
unsigned long flags;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
card = midi_devs[dev]->devc;
if ((midihdr = (struct midi_hdr *) kmalloc(sizeof(struct midi_hdr), GFP_KERNEL)) == NULL)
return -EINVAL;
midihdr->bufferlength = 1;
midihdr->bytesrecorded = 0;
midihdr->flags = 0;
if ((midihdr->data = (u8 *) kmalloc(1, GFP_KERNEL)) == NULL) {
ERROR();
kfree(midihdr);
return -EINVAL;
}
*(midihdr->data) = midi_byte;
spin_lock_irqsave(&midi_spinlock, flags);
if (emu10k1_mpuout_add_buffer(card, midihdr) < 0) {
ERROR();
kfree(midihdr->data);
kfree(midihdr);
spin_unlock_irqrestore(&midi_spinlock, flags);
return -EINVAL;
}
spin_unlock_irqrestore(&midi_spinlock, flags);
return 1;
}
int emu10k1_seq_midi_start_read(int dev)
{
return 0;
}
int emu10k1_seq_midi_end_read(int dev)
{
return 0;
}
void emu10k1_seq_midi_kick(int dev)
{
}
int emu10k1_seq_midi_buffer_status(int dev)
{
int count;
struct midi_queue *queue;
struct emu10k1_card *card;
if( midi_devs[dev] == NULL
|| midi_devs[dev]->devc == NULL)
return -EINVAL;
count = 0;
card = midi_devs[dev]->devc;
queue = card->mpuout->firstmidiq;
while(queue != NULL) {
count++;
if(queue == card->mpuout->lastmidiq)
break;
queue = queue->next;
}
return count;
}
#endif
...@@ -3,9 +3,6 @@ ...@@ -3,9 +3,6 @@
* mixer.c - /dev/mixer interface for emu10k1 driver * mixer.c - /dev/mixer interface for emu10k1 driver
* Copyright 1999, 2000 Creative Labs, Inc. * Copyright 1999, 2000 Creative Labs, Inc.
* *
* This program uses some code from es1371.c, Copyright 1998-1999
* Thomas Sailer
*
********************************************************************** **********************************************************************
* *
* Date Author Summary of changes * Date Author Summary of changes
...@@ -36,824 +33,368 @@ ...@@ -36,824 +33,368 @@
#define __NO_VERSION__ /* Kernel version only defined once */ #define __NO_VERSION__ /* Kernel version only defined once */
#include <linux/module.h> #include <linux/module.h>
#include <linux/version.h> #include <linux/version.h>
#include <linux/bitops.h>
#include <asm/uaccess.h> #include <asm/uaccess.h>
#include <linux/fs.h>
#include "hwaccess.h" #include "hwaccess.h"
#include "8010.h" #include "8010.h"
#include "recmgr.h" #include "recmgr.h"
#define AC97_PESSIMISTIC //FIXME: SOUND_MIXER_VOLUME should be selectable 5 or 6 bit
#undef OSS_DOCUMENTED_MIXER_SEMANTICS const struct oss_scaling volume_params[SOUND_MIXER_NRDEVICES]= {
/* Used by the ac97 driver */
#define vol_to_hw_5(swvol) (31 - (((swvol) * 31) / 100)) [SOUND_MIXER_VOLUME] = {VOL_6BIT},
#define vol_to_hw_4(swvol) (15 - (((swvol) * 15) / 100)) [SOUND_MIXER_BASS] = {VOL_4BIT},
[SOUND_MIXER_TREBLE] = {VOL_4BIT},
#define vol_to_sw_5(hwvol) (((31 - (hwvol)) * 100) / 31) [SOUND_MIXER_PCM] = {VOL_5BIT},
#define vol_to_sw_4(hwvol) (((15 - (hwvol)) * 100) / 15) [SOUND_MIXER_SPEAKER] = {VOL_4BIT},
[SOUND_MIXER_LINE] = {VOL_5BIT},
[SOUND_MIXER_MIC] = {VOL_5BIT},
[SOUND_MIXER_CD] = {VOL_5BIT},
[SOUND_MIXER_ALTPCM] = {VOL_6BIT},
[SOUND_MIXER_IGAIN] = {VOL_4BIT},
[SOUND_MIXER_LINE1] = {VOL_5BIT},
[SOUND_MIXER_PHONEIN] = {VOL_5BIT},
[SOUND_MIXER_PHONEOUT] = {VOL_6BIT},
[SOUND_MIXER_VIDEO] = {VOL_5BIT},
/* Not used by the ac97 driver */
[SOUND_MIXER_SYNTH] = {VOL_5BIT},
[SOUND_MIXER_IMIX] = {VOL_5BIT},
[SOUND_MIXER_RECLEV] = {VOL_5BIT},
[SOUND_MIXER_OGAIN] = {VOL_5BIT},
[SOUND_MIXER_LINE2] = {VOL_5BIT},
[SOUND_MIXER_LINE3] = {VOL_5BIT},
[SOUND_MIXER_DIGITAL1] = {VOL_5BIT},
[SOUND_MIXER_DIGITAL2] = {VOL_5BIT},
[SOUND_MIXER_DIGITAL3] = {VOL_5BIT},
[SOUND_MIXER_RADIO] = {VOL_5BIT},
[SOUND_MIXER_MONITOR] = {VOL_5BIT}
};
static loff_t emu10k1_mixer_llseek(struct file *file, loff_t offset, int origin)
{
DPF(2, "sblive_mixer_llseek() called\n");
return -ESPIPE;
}
#define DM_MUTE 0x80000000 /* Mixer file operations */
#ifdef PRIVATE_PCM_VOLUME static int emu10k1_private_mixer(struct emu10k1_card *card, unsigned int cmd, unsigned long arg)
struct sblive_pcm_volume_rec sblive_pcm_volume[MAX_PCM_CHANNELS]; {
u16 pcm_last_mixer = 0x6464; struct mixer_private_ioctl *ctl;
#endif struct dsp_patch *patch;
u32 size, page;
int addr, size_reg, i, ret;
unsigned int id, ch;
/* Mapping arrays */ switch (cmd) {
static const unsigned int recsrc[] = {
SOUND_MASK_MIC,
SOUND_MASK_CD,
SOUND_MASK_VIDEO,
SOUND_MASK_LINE1,
SOUND_MASK_LINE,
SOUND_MASK_VOLUME,
SOUND_MASK_OGAIN, /* Used to be PHONEOUT */
SOUND_MASK_PHONEIN,
#ifdef TONE_CONTROL
SOUND_MASK_TREBLE,
SOUND_MASK_BASS,
#endif
};
static const unsigned char volreg[SOUND_MIXER_NRDEVICES] = { case SOUND_MIXER_PRIVATE3:
/* 5 bit stereo */
[SOUND_MIXER_LINE] = AC97_LINEINVOLUME,
[SOUND_MIXER_CD] = AC97_CDVOLUME,
[SOUND_MIXER_VIDEO] = AC97_VIDEOVOLUME,
[SOUND_MIXER_LINE1] = AC97_AUXVOLUME,
/* [SOUND_MIXER_PCM] = AC97_PCMOUTVOLUME, */
/* 5 bit stereo, setting 6th bit equal to maximum attenuation */
/* [SOUND_MIXER_VOLUME] = AC97_MASTERVOLUME, */
[SOUND_MIXER_PHONEOUT] = AC97_HEADPHONEVOLUME,
/* 5 bit mono, setting 6th bit equal to maximum attenuation */
[SOUND_MIXER_OGAIN] = AC97_MASTERVOLUMEMONO,
/* 5 bit mono */
[SOUND_MIXER_PHONEIN] = AC97_PHONEVOLUME,
/* 4 bit mono but shifted by 1 */
[SOUND_MIXER_SPEAKER] = AC97_PCBEEPVOLUME,
/* 5 bit mono, 7th bit = preamp */
[SOUND_MIXER_MIC] = AC97_MICVOLUME,
/* 4 bit stereo */
[SOUND_MIXER_RECLEV] = AC97_RECORDGAIN,
/* 4 bit mono */
[SOUND_MIXER_IGAIN] = AC97_RECORDGAINMIC,
/* test code */
[SOUND_MIXER_BASS] = AC97_GENERALPURPOSE,
[SOUND_MIXER_TREBLE] = AC97_MASTERTONE,
[SOUND_MIXER_LINE2] = AC97_PCMOUTVOLUME,
[SOUND_MIXER_DIGITAL2] = AC97_MASTERVOLUME
};
#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS ctl = (struct mixer_private_ioctl *) kmalloc(sizeof(struct mixer_private_ioctl), GFP_KERNEL);
if (ctl == NULL)
return -ENOMEM;
#define swab(x) ((((x) >> 8) & 0xff) | (((x) << 8) & 0xff00)) if (copy_from_user(ctl, (void *) arg, sizeof(struct mixer_private_ioctl))) {
kfree(ctl);
return -EFAULT;
}
/* FIXME: mixer_rdch() is broken. */ ret = 0;
switch (ctl->cmd) {
#ifdef DBGEMU
case CMD_WRITEFN0:
emu10k1_writefn0(card, ctl->val[0], ctl->val[1]);
break;
static int mixer_rdch(struct emu10k1_card *card, unsigned int ch, int *arg) case CMD_WRITEPTR:
{ if (ctl->val[1] >= 0x40 || ctl->val[0] > 0xff) {
u16 reg; ret = -EINVAL;
int j;
int nL, nR;
switch (ch) {
case SOUND_MIXER_PCM:
case SOUND_MIXER_VOLUME:
#ifdef TONE_CONTROL
case SOUND_MIXER_TREBLE:
case SOUND_MIXER_BASS:
#endif
return put_user(0x0000, (int *) arg);
default:
break; break;
} }
if(card->isaps) if ((ctl->val[0] & 0x7ff) > 0x3f)
return -EINVAL; ctl->val[1] = 0x00;
switch (ch) {
case SOUND_MIXER_LINE:
case SOUND_MIXER_CD:
case SOUND_MIXER_VIDEO:
case SOUND_MIXER_LINE1:
sblive_readac97(card, volreg[ch], &reg);
nL = ((~(reg >> 8) & 0x1f) * 100) / 32;
nR = (~(reg & 0x1f) * 100) / 32;
DPD(2, "mixer_rdch: l=%d, r=%d\n", nL, nR);
return put_user(reg & 0x8000 ? 0 : (nL << 8) | nR, (int *) arg);
case SOUND_MIXER_OGAIN:
case SOUND_MIXER_PHONEIN:
sblive_readac97(card, volreg[ch], &reg);
return put_user(reg & 0x8000 ? 0 : ~(reg & 0x1f) * 0x64 / 0x20 * 0x101, (int *) arg);
case SOUND_MIXER_SPEAKER:
sblive_readac97(card, volreg[ch], &reg);
return put_user(reg & 0x8000 ? 0 : ~((reg >> 1) & 0xf) * 0x64 / 0x10 * 0x101, (int *) arg);
case SOUND_MIXER_MIC:
sblive_readac97(card, volreg[ch], &reg);
return put_user(reg & 0x8000 ? 0 : ~(reg & 0x1f) * 0x64 / 0x20 * 0x101 + ((reg & 0x40) ? 0x1e1e : 0), (int *) arg);
case SOUND_MIXER_RECLEV:
sblive_readac97(card, volreg[ch], &reg);
nL = ((~(reg >> 8) & 0x1f) * 100) / 16;
nR = (~(reg & 0x1f) * 100) / 16;
return put_user(reg & 0x8000 ? 0 : (nL << 8) | nR, (int *) arg);
default:
return -EINVAL;
}
}
#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */ sblive_writeptr(card, ctl->val[0], ctl->val[1], ctl->val[2]);
static const unsigned char volidx[SOUND_MIXER_NRDEVICES] = {
/* 5 bit stereo */
[SOUND_MIXER_LINE] = 1,
[SOUND_MIXER_CD] = 2,
[SOUND_MIXER_VIDEO] = 3,
[SOUND_MIXER_LINE1] = 4,
[SOUND_MIXER_PCM] = 5,
/* 6 bit stereo */
[SOUND_MIXER_VOLUME] = 6,
[SOUND_MIXER_PHONEOUT] = 7,
/* 6 bit mono */
[SOUND_MIXER_OGAIN] = 8,
[SOUND_MIXER_PHONEIN] = 9,
/* 4 bit mono but shifted by 1 */
[SOUND_MIXER_SPEAKER] = 10,
/* 6 bit mono + preamp */
[SOUND_MIXER_MIC] = 11,
/* 4 bit stereo */
[SOUND_MIXER_RECLEV] = 12,
/* 4 bit mono */
[SOUND_MIXER_IGAIN] = 13,
[SOUND_MIXER_TREBLE] = 14,
[SOUND_MIXER_BASS] = 15,
[SOUND_MIXER_LINE2] = 16,
[SOUND_MIXER_LINE3] = 17,
[SOUND_MIXER_DIGITAL1] = 18,
[SOUND_MIXER_DIGITAL2] = 19
};
#ifdef TONE_CONTROL break;
#endif
static const u32 bass_table[41][5] = { case CMD_READFN0:
{ 0x3e4f844f, 0x84ed4cc3, 0x3cc69927, 0x7b03553a, 0xc4da8486 }, ctl->val[2] = emu10k1_readfn0(card, ctl->val[0]);
{ 0x3e69a17a, 0x84c280fb, 0x3cd77cd4, 0x7b2f2a6f, 0xc4b08d1d },
{ 0x3e82ff42, 0x849991d5, 0x3ce7466b, 0x7b5917c6, 0xc48863ee },
{ 0x3e9bab3c, 0x847267f0, 0x3cf5ffe8, 0x7b813560, 0xc461f22c },
{ 0x3eb3b275, 0x844ced29, 0x3d03b295, 0x7ba79a1c, 0xc43d223b },
{ 0x3ecb2174, 0x84290c8b, 0x3d106714, 0x7bcc5ba3, 0xc419dfa5 },
{ 0x3ee2044b, 0x8406b244, 0x3d1c2561, 0x7bef8e77, 0xc3f8170f },
{ 0x3ef86698, 0x83e5cb96, 0x3d26f4d8, 0x7c114600, 0xc3d7b625 },
{ 0x3f0e5390, 0x83c646c9, 0x3d30dc39, 0x7c319498, 0xc3b8ab97 },
{ 0x3f23d60b, 0x83a81321, 0x3d39e1af, 0x7c508b9c, 0xc39ae704 },
{ 0x3f38f884, 0x838b20d2, 0x3d420ad2, 0x7c6e3b75, 0xc37e58f1 },
{ 0x3f4dc52c, 0x836f60ef, 0x3d495cab, 0x7c8ab3a6, 0xc362f2be },
{ 0x3f6245e8, 0x8354c565, 0x3d4fdbb8, 0x7ca602d6, 0xc348a69b },
{ 0x3f76845f, 0x833b40ec, 0x3d558bf0, 0x7cc036df, 0xc32f677c },
{ 0x3f8a8a03, 0x8322c6fb, 0x3d5a70c4, 0x7cd95cd7, 0xc317290b },
{ 0x3f9e6014, 0x830b4bc3, 0x3d5e8d25, 0x7cf1811a, 0xc2ffdfa5 },
{ 0x3fb20fae, 0x82f4c420, 0x3d61e37f, 0x7d08af56, 0xc2e9804a },
{ 0x3fc5a1cc, 0x82df2592, 0x3d6475c3, 0x7d1ef294, 0xc2d40096 },
{ 0x3fd91f55, 0x82ca6632, 0x3d664564, 0x7d345541, 0xc2bf56b9 },
{ 0x3fec9120, 0x82b67cac, 0x3d675356, 0x7d48e138, 0xc2ab796e },
{ 0x40000000, 0x82a36037, 0x3d67a012, 0x7d5c9fc9, 0xc2985fee },
{ 0x401374c7, 0x8291088a, 0x3d672b93, 0x7d6f99c3, 0xc28601f2 },
{ 0x4026f857, 0x827f6dd7, 0x3d65f559, 0x7d81d77c, 0xc27457a3 },
{ 0x403a939f, 0x826e88c5, 0x3d63fc63, 0x7d9360d4, 0xc2635996 },
{ 0x404e4faf, 0x825e5266, 0x3d613f32, 0x7da43d42, 0xc25300c6 },
{ 0x406235ba, 0x824ec434, 0x3d5dbbc3, 0x7db473d7, 0xc243468e },
{ 0x40764f1f, 0x823fd80c, 0x3d596f8f, 0x7dc40b44, 0xc23424a2 },
{ 0x408aa576, 0x82318824, 0x3d545787, 0x7dd309e2, 0xc2259509 },
{ 0x409f4296, 0x8223cf0b, 0x3d4e7012, 0x7de175b5, 0xc2179218 },
{ 0x40b430a0, 0x8216a7a1, 0x3d47b505, 0x7def5475, 0xc20a1670 },
{ 0x40c97a0a, 0x820a0d12, 0x3d4021a1, 0x7dfcab8d, 0xc1fd1cf5 },
{ 0x40df29a6, 0x81fdfad6, 0x3d37b08d, 0x7e098028, 0xc1f0a0ca },
{ 0x40f54ab1, 0x81f26ca9, 0x3d2e5bd1, 0x7e15d72b, 0xc1e49d52 },
{ 0x410be8da, 0x81e75e89, 0x3d241cce, 0x7e21b544, 0xc1d90e24 },
{ 0x41231051, 0x81dcccb3, 0x3d18ec37, 0x7e2d1ee6, 0xc1cdef10 },
{ 0x413acdd0, 0x81d2b39e, 0x3d0cc20a, 0x7e38184e, 0xc1c33c13 },
{ 0x41532ea7, 0x81c90ffb, 0x3cff9585, 0x7e42a58b, 0xc1b8f15a },
{ 0x416c40cd, 0x81bfdeb2, 0x3cf15d21, 0x7e4cca7c, 0xc1af0b3f },
{ 0x418612ea, 0x81b71cdc, 0x3ce20e85, 0x7e568ad3, 0xc1a58640 },
{ 0x41a0b465, 0x81aec7c5, 0x3cd19e7c, 0x7e5fea1e, 0xc19c5f03 },
{ 0x41bc3573, 0x81a6dcea, 0x3cc000e9, 0x7e68ebc2, 0xc1939250 }
};
static const u32 treble_table[41][5] = { if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
{ 0x0125cba9, 0xfed5debd, 0x00599b6c, 0x0d2506da, 0xfa85b354 }, ret = -EFAULT;
{ 0x0142f67e, 0xfeb03163, 0x0066cd0f, 0x0d14c69d, 0xfa914473 },
{ 0x016328bd, 0xfe860158, 0x0075b7f2, 0x0d03eb27, 0xfa9d32d2 },
{ 0x0186b438, 0xfe56c982, 0x00869234, 0x0cf27048, 0xfaa97fca },
{ 0x01adf358, 0xfe21f5fe, 0x00999842, 0x0ce051c2, 0xfab62ca5 },
{ 0x01d949fa, 0xfde6e287, 0x00af0d8d, 0x0ccd8b4a, 0xfac33aa7 },
{ 0x02092669, 0xfda4d8bf, 0x00c73d4c, 0x0cba1884, 0xfad0ab07 },
{ 0x023e0268, 0xfd5b0e4a, 0x00e27b54, 0x0ca5f509, 0xfade7ef2 },
{ 0x0278645c, 0xfd08a2b0, 0x01012509, 0x0c911c63, 0xfaecb788 },
{ 0x02b8e091, 0xfcac9d1a, 0x0123a262, 0x0c7b8a14, 0xfafb55df },
{ 0x03001a9a, 0xfc45e9ce, 0x014a6709, 0x0c65398f, 0xfb0a5aff },
{ 0x034ec6d7, 0xfbd3576b, 0x0175f397, 0x0c4e2643, 0xfb19c7e4 },
{ 0x03a5ac15, 0xfb5393ee, 0x01a6d6ed, 0x0c364b94, 0xfb299d7c },
{ 0x0405a562, 0xfac52968, 0x01ddafae, 0x0c1da4e2, 0xfb39dca5 },
{ 0x046fa3fe, 0xfa267a66, 0x021b2ddd, 0x0c042d8d, 0xfb4a8631 },
{ 0x04e4b17f, 0xf975be0f, 0x0260149f, 0x0be9e0f2, 0xfb5b9ae0 },
{ 0x0565f220, 0xf8b0fbe5, 0x02ad3c29, 0x0bceba73, 0xfb6d1b60 },
{ 0x05f4a745, 0xf7d60722, 0x030393d4, 0x0bb2b578, 0xfb7f084d },
{ 0x06923236, 0xf6e279bd, 0x03642465, 0x0b95cd75, 0xfb916233 },
{ 0x07401713, 0xf5d3aef9, 0x03d01283, 0x0b77fded, 0xfba42984 },
{ 0x08000000, 0xf4a6bd88, 0x0448a161, 0x0b594278, 0xfbb75e9f },
{ 0x08d3c097, 0xf3587131, 0x04cf35a4, 0x0b3996c9, 0xfbcb01cb },
{ 0x09bd59a2, 0xf1e543f9, 0x05655880, 0x0b18f6b2, 0xfbdf1333 },
{ 0x0abefd0f, 0xf04956ca, 0x060cbb12, 0x0af75e2c, 0xfbf392e8 },
{ 0x0bdb123e, 0xee806984, 0x06c739fe, 0x0ad4c962, 0xfc0880dd },
{ 0x0d143a94, 0xec85d287, 0x0796e150, 0x0ab134b0, 0xfc1ddce5 },
{ 0x0e6d5664, 0xea547598, 0x087df0a0, 0x0a8c9cb6, 0xfc33a6ad },
{ 0x0fe98a2a, 0xe7e6ba35, 0x097edf83, 0x0a66fe5b, 0xfc49ddc2 },
{ 0x118c4421, 0xe536813a, 0x0a9c6248, 0x0a4056d7, 0xfc608185 },
{ 0x1359422e, 0xe23d19eb, 0x0bd96efb, 0x0a18a3bf, 0xfc77912c },
{ 0x1554982b, 0xdef33645, 0x0d3942bd, 0x09efe312, 0xfc8f0bc1 },
{ 0x1782b68a, 0xdb50deb1, 0x0ebf676d, 0x09c6133f, 0xfca6f019 },
{ 0x19e8715d, 0xd74d64fd, 0x106fb999, 0x099b3337, 0xfcbf3cd6 },
{ 0x1c8b07b8, 0xd2df56ab, 0x124e6ec8, 0x096f4274, 0xfcd7f060 },
{ 0x1f702b6d, 0xcdfc6e92, 0x14601c10, 0x0942410b, 0xfcf108e5 },
{ 0x229e0933, 0xc89985cd, 0x16a9bcfa, 0x09142fb5, 0xfd0a8451 },
{ 0x261b5118, 0xc2aa8409, 0x1930bab6, 0x08e50fdc, 0xfd24604d },
{ 0x29ef3f5d, 0xbc224f28, 0x1bfaf396, 0x08b4e3aa, 0xfd3e9a3b },
{ 0x2e21a59b, 0xb4f2ba46, 0x1f0ec2d6, 0x0883ae15, 0xfd592f33 },
{ 0x32baf44b, 0xad0c7429, 0x227308a3, 0x085172eb, 0xfd741bfd },
{ 0x37c4448b, 0xa45ef51d, 0x262f3267, 0x081e36dc, 0xfd8f5d14 }
};
static void set_bass(struct emu10k1_card *card, int l, int r) break;
{
int i;
l = (l * 40 + 50) / 100; case CMD_READPTR:
r = (r * 40 + 50) / 100; if (ctl->val[1] >= 0x40 || (ctl->val[0] & 0x7ff) > 0xff) {
for (i = 0; i < 5; i++) { ret = -EINVAL;
sblive_writeptr(card, FXGPREGBASE + 0x80 + (i * 2), 0, bass_table[l][i]); break;
sblive_writeptr(card, FXGPREGBASE + 0x80 + (i * 2) + 1, 0, bass_table[r][i]);
} }
}
static void set_treble(struct emu10k1_card *card, int l, int r) if ((ctl->val[0] & 0x7ff) > 0x3f)
{ ctl->val[1] = 0x00;
int i;
l = (l * 40 + 50) / 100; ctl->val[2] = sblive_readptr(card, ctl->val[0], ctl->val[1]);
r = (r * 40 + 50) / 100;
for (i = 0; i < 5; i++) {
sblive_writeptr(card, FXGPREGBASE + 0x90 + (i * 2), 0, treble_table[l][i]);
sblive_writeptr(card, FXGPREGBASE + 0x90 + (i * 2) + 1, 0, treble_table[r][i]);
}
}
#endif if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
ret = -EFAULT;
static const u32 db_table[101] = { break;
0x00000000, 0x01571f82, 0x01674b41, 0x01783a1b, 0x0189f540,
0x019c8651, 0x01aff763, 0x01c45306, 0x01d9a446, 0x01eff6b8,
0x0207567a, 0x021fd03d, 0x0239714c, 0x02544792, 0x027061a1,
0x028dcebb, 0x02ac9edc, 0x02cce2bf, 0x02eeabe8, 0x03120cb0,
0x0337184e, 0x035de2df, 0x03868173, 0x03b10a18, 0x03dd93e9,
0x040c3713, 0x043d0cea, 0x04702ff3, 0x04a5bbf2, 0x04ddcdfb,
0x0518847f, 0x0555ff62, 0x05966005, 0x05d9c95d, 0x06206005,
0x066a4a52, 0x06b7b067, 0x0708bc4c, 0x075d9a01, 0x07b6779d,
0x08138561, 0x0874f5d5, 0x08dafde1, 0x0945d4ed, 0x09b5b4fd,
0x0a2adad1, 0x0aa58605, 0x0b25f936, 0x0bac7a24, 0x0c3951d8,
0x0ccccccc, 0x0d673b17, 0x0e08f093, 0x0eb24510, 0x0f639481,
0x101d3f2d, 0x10dfa9e6, 0x11ab3e3f, 0x12806ac3, 0x135fa333,
0x144960c5, 0x153e2266, 0x163e6cfe, 0x174acbb7, 0x1863d04d,
0x198a1357, 0x1abe349f, 0x1c00db77, 0x1d52b712, 0x1eb47ee6,
0x2026f30f, 0x21aadcb6, 0x23410e7e, 0x24ea64f9, 0x26a7c71d,
0x287a26c4, 0x2a62812c, 0x2c61df84, 0x2e795779, 0x30aa0bcf,
0x32f52cfe, 0x355bf9d8, 0x37dfc033, 0x3a81dda4, 0x3d43c038,
0x4026e73c, 0x432ce40f, 0x46575af8, 0x49a8040f, 0x4d20ac2a,
0x50c335d3, 0x54919a57, 0x588dead1, 0x5cba514a, 0x611911ea,
0x65ac8c2f, 0x6a773c39, 0x6f7bbc23, 0x74bcc56c, 0x7a3d3272,
0x7fffffff,
};
static void aps_update_digital(struct emu10k1_card *card) case CMD_SETRECSRC:
{ switch (ctl->val[0]) {
int i, l1, r1, l2, r2; case WAVERECORD_AC97:
if (card->isaps) {
i = card->arrwVol[volidx[SOUND_MIXER_VOLUME]]; ret = -EINVAL;
l1 = (i & 0xff); break;
r1 = ((i >> 8) & 0xff);
i = card->arrwVol[volidx[SOUND_MIXER_PCM]];
l2 = (i & 0xff);
r2 = ((i >> 8) & 0xff);
for (i = 0; i < 108; i++) {
if (card->digmix[i] != DM_MUTE) {
if ((i % 18 >= 0) && (i % 18 < 4))
card->digmix[i] = ((i & 1) ? ((u64) db_table[r1] * (u64) db_table[r2]) : ((u64) db_table[l1] * (u64) db_table[l2])) >> 31;
else
card->digmix[i] = (i & 1) ? db_table[r1] : db_table[l1];
sblive_writeptr(card, FXGPREGBASE + 0x10 + i, 0, card->digmix[i]);
} }
card->wavein.recsrc = WAVERECORD_AC97;
break;
case WAVERECORD_MIC:
card->wavein.recsrc = WAVERECORD_MIC;
break;
case WAVERECORD_FX:
card->wavein.recsrc = WAVERECORD_FX;
card->wavein.fxwc = ctl->val[1] & 0xffff;
if (!card->wavein.fxwc)
ret = -EINVAL;
break;
default:
ret = -EINVAL;
break;
} }
} break;
static void update_digital(struct emu10k1_card *card) case CMD_GETRECSRC:
{ ctl->val[0] = card->wavein.recsrc;
int i, k, l1, r1, l2, r2, l3, r3, l4, r4; ctl->val[1] = card->wavein.fxwc;
u64 j; if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
ret = -EFAULT;
i = card->arrwVol[volidx[SOUND_MIXER_VOLUME]];
l1 = (i & 0xff);
r1 = ((i >> 8) & 0xff);
i = card->arrwVol[volidx[SOUND_MIXER_LINE3]];
l2 = i & 0xff;
r2 = (i >> 8) & 0xff;
i = card->arrwVol[volidx[SOUND_MIXER_PCM]];
l3 = i & 0xff;
r3 = (i >> 8) & 0xff;
i = card->arrwVol[volidx[SOUND_MIXER_DIGITAL1]];
l4 = i & 0xff;
r4 = (i >> 8) & 0xff;
i = (r1 * r2) / 50;
if (r2 > 50)
r2 = 2 * r1 - i;
else {
r2 = r1;
r1 = i;
}
i = (l1 * l2) / 50; break;
if (l2 > 50)
l2 = 2 * l1 - i;
else {
l2 = l1;
l1 = i;
}
for (i = 0; i < 36; i++) { case CMD_GETVOICEPARAM:
if (card->digmix[i] != DM_MUTE) { ctl->val[0] = card->waveout.send_routing[0];
if (((i >= 0) && (i < 4)) || ((i >= 18) && (i < 22))) ctl->val[1] = card->waveout.send_a[0] | card->waveout.send_b[0] << 8 |
j = (i & 1) ? ((u64) db_table[r1] * (u64) db_table[r3]) : ((u64) db_table[l1] * (u64) db_table[l3]); card->waveout.send_c[0] << 16 | card->waveout.send_d[0] << 24;
else if ((i == 6) || (i == 7) || (i == 24) || (i == 25))
j = (i & 1) ? ((u64) db_table[r1] * (u64) db_table[r4]) : ((u64) db_table[l1] * (u64) db_table[l4]);
else
j = ((i & 1) ? db_table[r1] : db_table[l1]) << 31;
card->digmix[i] = j >> 31;
sblive_writeptr(card, FXGPREGBASE + 0x10 + i, 0, card->digmix[i]);
}
}
for (i = 72; i < 90; i++) { ctl->val[2] = card->waveout.send_routing[1];
if (card->digmix[i] != DM_MUTE) { ctl->val[3] = card->waveout.send_a[1] | card->waveout.send_b[1] << 8 |
if ((i >= 72) && (i < 76)) card->waveout.send_c[1] << 16 | card->waveout.send_d[1] << 24;
j = (i & 1) ? ((u64) db_table[r2] * (u64) db_table[r3]) : ((u64) db_table[l2] * (u64) db_table[l3]);
else if ((i == 78) || (i == 79))
j = (i & 1) ? ((u64) db_table[r2] * (u64) db_table[r4]) : ((u64) db_table[l2] * (u64) db_table[l4]);
else
j = ((i & 1) ? db_table[r2] : db_table[l2]) << 31;
card->digmix[i] = j >> 31;
sblive_writeptr(card, FXGPREGBASE + 0x10 + i, 0, card->digmix[i]);
}
}
for (i = 36; i <= 90; i += 18) { ctl->val[4] = card->waveout.send_routing[2];
if (i != 72) { ctl->val[5] = card->waveout.send_a[2] | card->waveout.send_b[2] << 8 |
for (k = 0; k < 4; k++) card->waveout.send_c[2] << 16 | card->waveout.send_d[2] << 24;
if (card->digmix[i + k] != DM_MUTE) {
card->digmix[i + k] = db_table[l3];
sblive_writeptr(card, FXGPREGBASE + 0x10 + i + k, 0, card->digmix[i + k]);
}
if (card->digmix[i + 6] != DM_MUTE) {
card->digmix[i + 6] = db_table[l4];
sblive_writeptr(card, FXGPREGBASE + 0x10 + i + 6, 0, card->digmix[i + 6]);
}
if (card->digmix[i + 7] != DM_MUTE) {
card->digmix[i + 7] = db_table[r4];
sblive_writeptr(card, FXGPREGBASE + 0x10 + i + 7, 0, card->digmix[i + 7]);
}
}
}
} if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
ret = -EFAULT;
#ifdef PRIVATE_PCM_VOLUME break;
/* calc & set attenuation factor for given channel */ case CMD_SETVOICEPARAM:
static int set_pcm_attn(struct emu10k1_card *card, int ch, int l) card->waveout.send_routing[0] = ctl->val[0] & 0xffff;
{ card->waveout.send_a[0] = ctl->val[1] & 0xff;
#ifndef PCMLEVEL card->waveout.send_b[0] = (ctl->val[1] >> 8) & 0xff;
#define PCMLEVEL 110 /* almost silence */ card->waveout.send_c[0] = (ctl->val[1] >> 16) & 0xff;
#endif card->waveout.send_d[0] = (ctl->val[1] >> 24) & 0xff;
int vol = IFATN_ATTENUATION_MASK; /* silence */
card->waveout.send_routing[1] = ctl->val[2] & 0xffff;
card->waveout.send_a[1] = ctl->val[3] & 0xff;
card->waveout.send_b[1] = (ctl->val[3] >> 8) & 0xff;
card->waveout.send_c[1] = (ctl->val[3] >> 16) & 0xff;
card->waveout.send_d[1] = (ctl->val[3] >> 24) & 0xff;
card->waveout.send_routing[2] = ctl->val[4] & 0xffff;
card->waveout.send_a[2] = ctl->val[5] & 0xff;
card->waveout.send_b[2] = (ctl->val[5] >> 8) & 0xff;
card->waveout.send_c[2] = (ctl->val[5] >> 16) & 0xff;
card->waveout.send_d[2] = (ctl->val[5] >> 24) & 0xff;
if (l > 0) break;
vol = (PCMLEVEL - (l * PCMLEVEL + 50) / 100);
sblive_writeptr(card, IFATN, ch, IFATN_FILTERCUTOFF_MASK | vol);
DPD(2, "SOUND_MIXER_PCM: channel:%d level:%d attn:%d\n", ch, l, vol);
return vol; case CMD_SETMCH_FX:
#undef PCMLEVEL card->mchannel_fx = ctl->val[0] & 0x000f;
} break;
/* update value of local PCM volume level (using channel attenuation) case CMD_GETPATCH:
* if (ctl->val[0] == 0) {
* return 1: in case its local change if (copy_to_user((void *) arg, &card->mgr.rpatch, sizeof(struct dsp_rpatch)))
* 0: if the current process doesn't have entry in table ret = -EFAULT;
* (it means this process have not opened audio (mixer usually)
*/
static int update_pcm_attn(struct emu10k1_card *card, unsigned l1, unsigned r1)
{
int i;
int mixer = (r1 << 8) | l1;
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
sblive_pcm_volume[i].mixer = pcm_last_mixer = mixer;
if (sblive_pcm_volume[i].opened) {
if (sblive_pcm_volume[i].channel_r < NUM_G) {
sblive_pcm_volume[i].attn_r = set_pcm_attn(card, sblive_pcm_volume[i].channel_r, r1);
if (sblive_pcm_volume[i].channel_l < NUM_G)
sblive_pcm_volume[i].attn_l = set_pcm_attn(card, sblive_pcm_volume[i].channel_l, l1);
} else { } else {
/* mono voice */ if ((ctl->val[0] - 1) / PATCHES_PER_PAGE >= card->mgr.current_pages) {
if (sblive_pcm_volume[i].channel_l < NUM_G) ret = -EINVAL;
sblive_pcm_volume[i].attn_l = break;
set_pcm_attn(card, sblive_pcm_volume[i].channel_l, (l1 >= r1) ? l1 : r1);
/* to correctly handle mono voice here we would need
to go into stereo mode and move the voice to the right & left
looks a bit overcomplicated... */
}
} }
return 1; if (copy_to_user((void *) arg, PATCH(&card->mgr, ctl->val[0] - 1), sizeof(struct dsp_patch)))
ret = -EFAULT;
}
} }
card->arrwVol[volidx[SOUND_MIXER_PCM]] = mixer; break;
return 0;
}
#endif
int emu10k1_mixer_wrch(struct emu10k1_card *card, unsigned int ch, int val)
{
int i;
unsigned l1, r1;
u16 wval;
l1 = val & 0xff;
r1 = (val >> 8) & 0xff;
if (l1 > 100)
l1 = 100;
if (r1 > 100)
r1 = 100;
DPD(4, "emu10k1_mixer_wrch() called: ch=%u, l1=%u, r1=%u\n", ch, l1, r1);
if (!volidx[ch])
return -EINVAL;
#ifdef PRIVATE_PCM_VOLUME
if (ch != SOUND_MIXER_PCM)
#endif
card->arrwVol[volidx[ch]] = (r1 << 8) | l1;
switch (ch) { case CMD_GETGPR:
case SOUND_MIXER_VOLUME: id = ctl->val[0];
DPF(4, "SOUND_MIXER_VOLUME:\n");
if (card->isaps)
aps_update_digital(card);
else
update_digital(card);
return 0;
case SOUND_MIXER_PCM:
DPF(4, "SOUND_MIXER_PCM\n");
#ifdef PRIVATE_PCM_VOLUME
if (update_pcm_attn(card, l1, r1))
return 0;
#endif
if (card->isaps)
aps_update_digital(card);
else
update_digital(card);
return 0;
#ifdef TONE_CONTROL
case SOUND_MIXER_TREBLE:
DPF(4, "SOUND_MIXER_TREBLE:\n");
set_treble(card, l1, r1);
return 0;
case SOUND_MIXER_BASS: if (id > NUM_GPRS) {
DPF(4, "SOUND_MIXER_BASS:\n"); ret = -EINVAL;
set_bass(card, l1, r1);
return 0;
#endif
default:
break; break;
} }
if (copy_to_user((void *) arg, &card->mgr.gpr[id], sizeof(struct dsp_gpr)))
ret = -EFAULT;
if (card->isaps) break;
return -EINVAL;
switch (ch) {
case SOUND_MIXER_DIGITAL1:
case SOUND_MIXER_LINE3:
DPD(4, "SOUND_MIXER_%s:\n", (ch == SOUND_MIXER_DIGITAL1) ? "DIGITAL1" : "LINE3");
update_digital(card);
return 0;
case SOUND_MIXER_DIGITAL2:
case SOUND_MIXER_LINE2:
case SOUND_MIXER_LINE1:
case SOUND_MIXER_LINE:
case SOUND_MIXER_CD:
DPD(4, "SOUND_MIXER_%s:\n",
(ch == SOUND_MIXER_LINE1) ? "LINE1" :
(ch == SOUND_MIXER_LINE2) ? "LINE2" : (ch == SOUND_MIXER_LINE) ? "LINE" : (ch == SOUND_MIXER_DIGITAL2) ? "DIGITAL2" : "CD");
wval = ((((100 - l1) * 32 + 50) / 100) << 8) | (((100 - r1) * 32 + 50) / 100);
if (wval == 0x2020)
wval = 0x8000;
else
wval -= ((wval & 0x2020) / 0x20);
sblive_writeac97(card, volreg[ch], wval);
return 0;
case SOUND_MIXER_OGAIN: case CMD_GETCTLGPR:
case SOUND_MIXER_PHONEIN: addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, &((char *) ctl->val)[PATCH_NAME_SIZE]);
DPD(4, "SOUND_MIXER_%s:\n", (ch == SOUND_MIXER_PHONEIN) ? "PHONEIN" : "OGAIN"); ctl->val[0] = sblive_readptr(card, addr, 0);
sblive_writeac97(card, volreg[ch], (l1 < 2) ? 0x8000 : ((100 - l1) * 32 + 50) / 100);
return 0;
case SOUND_MIXER_SPEAKER: if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
DPF(4, "SOUND_MIXER_SPEAKER:\n"); ret = -EFAULT;
sblive_writeac97(card, volreg[ch], (l1 < 4) ? 0x8000 : (((100 - l1) * 16 + 50) / 100) << 1);
return 0;
case SOUND_MIXER_MIC: break;
DPF(4, "SOUND_MIXER_MIC:\n");
i = 0;
if (l1 >= 30)
/* 20dB / (34.5dB + 12dB + 20dB) * 100 = 30 */
{
l1 -= 30;
i = 0x40;
}
sblive_writeac97(card, volreg[ch], (l1 < 2) ? 0x8000 : ((((70 - l1) * 0x20 + 35) / 70) | i));
return 0;
case SOUND_MIXER_RECLEV:
DPF(4, "SOUND_MIXER_RECLEV:\n");
wval = (((l1 * 16 + 50) / 100) << 8) | ((r1 * 16 + 50) / 100); case CMD_SETPATCH:
if (wval == 0) if (ctl->val[0] == 0)
wval = 0x8000; memcpy(&card->mgr.rpatch, &ctl->val[1], sizeof(struct dsp_rpatch));
else { else {
if (wval & 0xff) page = (ctl->val[0] - 1) / PATCHES_PER_PAGE;
wval--; if (page > MAX_PATCHES_PAGES) {
if (wval & 0xff00) ret = -EINVAL;
wval -= 0x0100; break;
} }
sblive_writeac97(card, volreg[ch], wval);
return 0;
default: if (page >= card->mgr.current_pages) {
DPF(2, "Got unknown SOUND_MIXER ioctl\n"); for(i = card->mgr.current_pages; i < page + 1; i++) {
return -EINVAL; card->mgr.patch[i] = (void *)__get_free_pages(GFP_KERNEL, 1);
if(card->mgr.patch[i] == NULL) {
card->mgr.current_pages = i;
ret = -ENOMEM;
break;
} }
} memset(card->mgr.patch[i], 0, PAGE_SIZE);
}
static loff_t emu10k1_mixer_llseek(struct file *file, loff_t offset, int origin) card->mgr.current_pages = page + 1;
{
DPF(2, "sblive_mixer_llseek() called\n");
return -ESPIPE;
}
/* Mixer file operations */
/* FIXME: Do we need spinlocks in here? */
/* WARNING! not all the ioctl's are supported by the emu-APS
(anything AC97 related). As a general rule keep the AC97 related ioctls
separate from the rest. This will make it easier to rewrite the mixer
using the kernel AC97 interface. */
static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
{
static const char id[] = "SBLive";
static const char name[] = "Creative SBLive";
int i, val;
struct emu10k1_card *card = (struct emu10k1_card *) file->private_data;
u16 reg;
switch (cmd) {
case SOUND_MIXER_INFO:{
mixer_info info;
DPF(4, "SOUND_MIXER_INFO\n");
strncpy(info.id, id, sizeof(info.id));
strncpy(info.name, name, sizeof(info.name));
info.modify_counter = card->modcnt;
if (copy_to_user((void *) arg, &info, sizeof(info)))
return -EFAULT;
return 0;
} }
break;
case SOUND_OLD_MIXER_INFO:{
_old_mixer_info info;
DPF(4, "SOUND_OLD_MIXER_INFO\n"); patch = PATCH(&card->mgr, ctl->val[0] - 1);
strncpy(info.id, id, sizeof(info.id)); memcpy(patch, &ctl->val[1], sizeof(struct dsp_patch));
strncpy(info.name, name, sizeof(info.name));
if (copy_to_user((void *) arg, &info, sizeof(info))) if(patch->code_size == 0) {
return -EFAULT; for(i = page + 1; i < card->mgr.current_pages; i++)
free_page((unsigned long) card->mgr.patch[i]);
return 0; card->mgr.current_pages = page + 1;
}
} }
break; break;
case OSS_GETVERSION: case CMD_SETGPR:
DPF(4, "OSS_GETVERSION\n"); if (ctl->val[0] > NUM_GPRS) {
return put_user(SOUND_VERSION, (int *) arg); ret = -EINVAL;
break; break;
}
case SOUND_MIXER_PRIVATE1: memcpy(&card->mgr.gpr[ctl->val[0]], &ctl->val[1], sizeof(struct dsp_gpr));
DPF(4, "SOUND_MIXER_PRIVATE1");
if (copy_to_user((void *) arg, card->digmix, sizeof(card->digmix)))
return -EFAULT;
return 0;
break; break;
case SOUND_MIXER_PRIVATE2:
DPF(4, "SOUND_MIXER_PRIVATE2");
if (copy_from_user(card->digmix, (void *) arg, sizeof(card->digmix)))
return -EFAULT;
for (i = 0; i < sizeof(card->digmix) / sizeof(card->digmix[0]); i++)
sblive_writeptr(card, FXGPREGBASE + 0x10 + i, 0, (card->digmix[i] & DM_MUTE) ? 0 : card->digmix[i]);
return 0;
case CMD_SETCTLGPR:
addr = emu10k1_find_control_gpr(&card->mgr, (char *) ctl->val, (char *) ctl->val + PATCH_NAME_SIZE);
emu10k1_set_control_gpr(card, addr, *((s32 *)((char *) ctl->val + 2 * PATCH_NAME_SIZE)), 0);
break; break;
case SOUND_MIXER_PRIVATE3: {
struct mixer_private_ioctl ctl;
if (copy_from_user(&ctl, (void *) arg, sizeof(struct mixer_private_ioctl)))
return -EFAULT;
switch (ctl.cmd) { case CMD_SETGPOUT:
#ifdef EMU10K1_DEBUG if( ctl->val[0]>2 || ctl->val[1]>1){
case CMD_WRITEFN0: ret= -EINVAL;
emu10k1_writefn0(card, ctl.val[0], ctl.val[1]);
return 0;
break; break;
}
case CMD_WRITEPTR: emu10k1_writefn0(card, (1<<24)| (((ctl->val[0])+10)<<16 ) | HCFG ,ctl->val[1]);
if(ctl.val[1] >= 0x40)
return -EINVAL;
if(ctl.val[0] > 0xff)
return -EINVAL;
if((ctl.val[0] & 0x7ff) > 0x3f)
ctl.val[1] = 0x00;
sblive_writeptr(card, ctl.val[0], ctl.val[1], ctl.val[2]);
return 0;
break; break;
#endif
case CMD_READFN0:
ctl.val[2] = emu10k1_readfn0(card, ctl.val[0]);
if (copy_to_user((void *) arg, &ctl, sizeof(struct mixer_private_ioctl))) case CMD_GETGPR2OSS:
return -EFAULT; id = ctl->val[0];
ch = ctl->val[1];
return 0; if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
ret = -EINVAL;
break; break;
}
case CMD_READPTR: ctl->val[2] = card->mgr.ctrl_gpr[id][ch];
if(ctl.val[1] >= 0x40)
return -EINVAL;
if((ctl.val[0] & 0x7ff) > 0xff)
return -EINVAL;
if((ctl.val[0] & 0x7ff) > 0x3f)
ctl.val[1] = 0x00;
ctl.val[2] = sblive_readptr(card, ctl.val[0], ctl.val[1]);
if (copy_to_user((void *) arg, &ctl, sizeof(struct mixer_private_ioctl)))
return -EFAULT;
return 0; if (copy_to_user((void *) arg, ctl, sizeof(struct mixer_private_ioctl)))
ret = -EFAULT;
break; break;
case CMD_SETRECSRC: case CMD_SETGPR2OSS:
switch(ctl.val[0]){ id = ctl->val[0];
case WAVERECORD_AC97: ch = ctl->val[1];
if(card->isaps) addr = ctl->val[2];
return -EINVAL;
card->wavein.recsrc = WAVERECORD_AC97; if (id >= SOUND_MIXER_NRDEVICES || ch >= 2) {
break; ret = -EINVAL;
case WAVERECORD_MIC:
card->wavein.recsrc = WAVERECORD_MIC;
break;
case WAVERECORD_FX:
card->wavein.recsrc = WAVERECORD_FX;
card->wavein.fxwc = ctl.val[1] & 0xffff;
if(!card->wavein.fxwc)
return -EINVAL;
break; break;
default:
return -EINVAL;
} }
return 0;
break;
case CMD_GETRECSRC: card->mgr.ctrl_gpr[id][ch] = addr;
ctl.val[0] = card->wavein.recsrc;
ctl.val[1] = card->wavein.fxwc;
if (copy_to_user((void *) arg, &ctl, sizeof(struct mixer_private_ioctl)))
return -EFAULT;
return 0; if (card->isaps)
break; break;
case CMD_GETVOICEPARAM: if (addr >= 0) {
unsigned int state = card->ac97.mixer_state[id];
ctl.val[0] = card->waveout.send_routing[0]; if (ch) {
ctl.val[1] = card->waveout.send_a[0] | card->waveout.send_b[0] << 8 | state >>= 8;
card->waveout.send_c[0] << 16 | card->waveout.send_d[0] << 24; card->ac97.stereo_mixers |= (1<<id);
} else {
ctl.val[2] = card->waveout.send_routing[1]; card->ac97.supported_mixers |= (1<<id);
ctl.val[3] = card->waveout.send_a[1] | card->waveout.send_b[1] << 8 | }
card->waveout.send_c[1] << 16 | card->waveout.send_d[1] << 24;
ctl.val[4] = card->waveout.send_routing[2];
ctl.val[5] = card->waveout.send_a[2] | card->waveout.send_b[2] << 8 |
card->waveout.send_c[2] << 16 | card->waveout.send_d[2] << 24;
if (copy_to_user((void *) arg, &ctl, sizeof(struct mixer_private_ioctl)))
return -EFAULT;
return 0; emu10k1_set_volume_gpr(card, addr, state & 0xff,
volume_params[id].scale,
volume_params[id].muting);
} else {
if (ch) {
card->ac97.stereo_mixers &= ~(1<<id);
card->ac97.stereo_mixers |= card->ac97_stereo_mixers;
} else {
card->ac97.supported_mixers &= ~(1<<id);
card->ac97.supported_mixers |= card->ac97_supported_mixers;
}
}
break; break;
case CMD_SETPASSTHROUGH:
case CMD_SETVOICEPARAM: card->pt.selected = ctl->val[0] ? 1 : 0;
card->waveout.send_routing[0] = ctl.val[0] & 0xffff; if (card->pt.state != PT_STATE_INACTIVE)
card->waveout.send_a[0] = ctl.val[1] & 0xff; break;
card->waveout.send_b[0] = (ctl.val[1] >> 8) & 0xff; card->pt.spcs_to_use = ctl->val[0] & 0x07;
card->waveout.send_c[0] = (ctl.val[1] >> 16) & 0xff;
card->waveout.send_d[0] = (ctl.val[1] >> 24) & 0xff;
card->waveout.send_routing[1] = ctl.val[2] & 0xffff;
card->waveout.send_a[1] = ctl.val[3] & 0xff;
card->waveout.send_b[1] = (ctl.val[3] >> 8) & 0xff;
card->waveout.send_c[1] = (ctl.val[3] >> 16) & 0xff;
card->waveout.send_d[1] = (ctl.val[3] >> 24) & 0xff;
card->waveout.send_routing[2] = ctl.val[4] & 0xffff;
card->waveout.send_a[2] = ctl.val[5] & 0xff;
card->waveout.send_b[2] = (ctl.val[5] >> 8) & 0xff;
card->waveout.send_c[2] = (ctl.val[5] >> 16) & 0xff;
card->waveout.send_d[2] = (ctl.val[5] >> 24) & 0xff;
return 0;
break; break;
default: default:
return -EINVAL; ret = -EINVAL;
break; break;
} }
}
kfree(ctl);
return ret;
break; break;
case SOUND_MIXER_PRIVATE4:{ case SOUND_MIXER_PRIVATE4:
u32 size;
int size_reg = 0;
if (copy_from_user(&size, (void *) arg, sizeof(size))) if (copy_from_user(&size, (void *) arg, sizeof(size)))
return -EFAULT; return -EFAULT;
DPD(2,"External tram size 0x%x\n", size); DPD(2, "External tram size %#x\n", size);
if(size > 0x1fffff) if (size > 0x1fffff)
return -EINVAL; return -EINVAL;
size_reg = 0;
if (size != 0) { if (size != 0) {
size = (size - 1) >> 14; size = (size - 1) >> 14;
...@@ -865,224 +406,84 @@ static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned ...@@ -865,224 +406,84 @@ static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned
size = 0x4000 << size_reg; size = 0x4000 << size_reg;
} }
DPD(2,"External tram size 0x%x 0x%x\n", size, size_reg); DPD(2, "External tram size %#x %#x\n", size, size_reg);
if (size != card->tankmem.size) { if (size != card->tankmem.size) {
if (card->tankmem.size > 0) { if (card->tankmem.size > 0) {
emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 1); emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 1);
sblive_writeptr_tag(card, 0, TCB, 0, sblive_writeptr_tag(card, 0, TCB, 0, TCBS, 0, TAGLIST_END);
TCBS, 0,
TAGLIST_END);
pci_free_consistent(card->pci_dev, card->tankmem.size, pci_free_consistent(card->pci_dev, card->tankmem.size, card->tankmem.addr, card->tankmem.dma_handle);
card->tankmem.addr, card->tankmem.dma_handle);
card->tankmem.size = 0; card->tankmem.size = 0;
} }
if (size != 0) { if (size != 0) {
if ((card->tankmem.addr = pci_alloc_consistent(card->pci_dev, size, card->tankmem.addr = pci_alloc_consistent(card->pci_dev, size, &card->tankmem.dma_handle);
&card->tankmem.dma_handle)) == NULL) if (card->tankmem.addr == NULL)
return -ENOMEM; return -ENOMEM;
card->tankmem.size = size; card->tankmem.size = size;
sblive_writeptr_tag(card, 0, TCB, card->tankmem.dma_handle, sblive_writeptr_tag(card, 0, TCB, card->tankmem.dma_handle, TCBS, size_reg, TAGLIST_END);
TCBS, size_reg,
TAGLIST_END);
emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 0); emu10k1_writefn0(card, HCFG_LOCKTANKCACHE, 0);
} }
} }
return 0; return 0;
}
break; break;
default: default:
break; break;
} }
if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
return -EINVAL; return -EINVAL;
}
if (_IOC_DIR(cmd) == _IOC_READ) {
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_DEVMASK: /* Arg contains a bit for each supported device */
DPF(4, "SOUND_MIXER_READ_DEVMASK\n");
if (card->isaps)
#ifdef TONE_CONTROL
return put_user(SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_BASS | SOUND_MASK_TREBLE,
(int *) arg);
#else
return put_user(SOUND_MASK_PCM | SOUND_MASK_VOLUME,
(int *) arg);
#endif
#ifdef TONE_CONTROL
return put_user(SOUND_MASK_LINE | SOUND_MASK_CD |
SOUND_MASK_OGAIN | SOUND_MASK_LINE1 |
SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_PHONEIN | SOUND_MASK_MIC |
SOUND_MASK_BASS | SOUND_MASK_TREBLE |
SOUND_MASK_RECLEV | SOUND_MASK_SPEAKER |
SOUND_MASK_LINE3 | SOUND_MASK_DIGITAL1 |
SOUND_MASK_DIGITAL2 | SOUND_MASK_LINE2, (int *) arg);
#else
return put_user(SOUND_MASK_LINE | SOUND_MASK_CD |
SOUND_MASK_OGAIN | SOUND_MASK_LINE1 |
SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_PHONEIN | SOUND_MASK_MIC |
SOUND_MASK_RECLEV | SOUND_MASK_SPEAKER |
SOUND_MASK_LINE3 | SOUND_MASK_DIGITAL1 |
SOUND_MASK_DIGITAL2 | SOUND_MASK_LINE2, (int *) arg);
#endif
case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
DPF(2, "SOUND_MIXER_READ_RECMASK\n");
if (card->isaps)
return put_user(0, (int *) arg);
return put_user(SOUND_MASK_MIC | SOUND_MASK_CD |
SOUND_MASK_LINE1 | SOUND_MASK_LINE |
SOUND_MASK_VOLUME | SOUND_MASK_OGAIN |
SOUND_MASK_PHONEIN, (int *) arg);
case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
DPF(2, "SOUND_MIXER_READ_STEREODEVS\n");
if (card->isaps)
#ifdef TONE_CONTROL
return put_user(SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_BASS | SOUND_MASK_TREBLE,
(int *) arg);
#else
return put_user(SOUND_MASK_PCM | SOUND_MASK_VOLUME,
(int *) arg);
#endif
#ifdef TONE_CONTROL
return put_user(SOUND_MASK_LINE | SOUND_MASK_CD |
SOUND_MASK_OGAIN | SOUND_MASK_LINE1 |
SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_BASS | SOUND_MASK_TREBLE |
SOUND_MASK_RECLEV | SOUND_MASK_LINE3 |
SOUND_MASK_DIGITAL1 | SOUND_MASK_DIGITAL2 |
SOUND_MASK_LINE2, (int *) arg);
#else
return put_user(SOUND_MASK_LINE | SOUND_MASK_CD |
SOUND_MASK_OGAIN | SOUND_MASK_LINE1 |
SOUND_MASK_PCM | SOUND_MASK_VOLUME |
SOUND_MASK_RECLEV | SOUND_MASK_LINE3 |
SOUND_MASK_DIGITAL1 | SOUND_MASK_DIGITAL2 |
SOUND_MASK_LINE2, (int *) arg);
#endif
case SOUND_MIXER_CAPS:
DPF(2, "SOUND_MIXER_READ_CAPS\n");
return put_user(SOUND_CAP_EXCL_INPUT, (int *) arg);
#ifdef PRIVATE_PCM_VOLUME
case SOUND_MIXER_PCM:
/* needs to be before default: !!*/
{
int i;
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
return put_user((int) sblive_pcm_volume[i].mixer, (int *) arg);
}
}
}
#endif
default:
break;
}
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
DPF(2, "SOUND_MIXER_READ_RECSRC\n");
if (card->isaps)
return put_user(0, (int *) arg);
sblive_readac97(card, AC97_RECORDSELECT, &reg);
return put_user(recsrc[reg & 7], (int *) arg);
default:
i = _IOC_NR(cmd);
DPD(4, "SOUND_MIXER_READ(%d)\n", i);
if (i >= SOUND_MIXER_NRDEVICES)
return -EINVAL;
#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
return mixer_rdch(card, i, (int *) arg);
#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
if (!volidx[i])
return -EINVAL;
return put_user(card->arrwVol[volidx[i]], (int *) arg);
#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
}
}
/* End of _IOC_READ */ static int emu10k1_mixer_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
if (_IOC_DIR(cmd) != (_IOC_READ | _IOC_WRITE)) {
return -EINVAL; int ret;
struct emu10k1_card *card = file->private_data;
/* _IOC_WRITE */ ret = -EINVAL;
card->modcnt++; if (!card->isaps)
ret = card->ac97.mixer_ioctl(&card->ac97, cmd, arg);
switch (_IOC_NR(cmd)) { if (ret < 0)
case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */ ret = emu10k1_private_mixer(card, cmd, arg);
DPF(2, "SOUND_MIXER_WRITE_RECSRC\n"); else{
unsigned int oss_mixer, left, right;
if (card->isaps) oss_mixer = _IOC_NR(cmd);
return -EINVAL;
if (get_user(val, (int *) arg)) if ((_IOC_DIR(cmd) == (_IOC_WRITE|_IOC_READ)) && oss_mixer<=SOUND_MIXER_NRDEVICES ) {
return -EFAULT;
i = hweight32(val); left = card->ac97.mixer_state[oss_mixer] & 0xff;
if (i == 0) right = (card->ac97.mixer_state[oss_mixer] >> 8) & 0xff;
return 0; /* val = mixer_recmask(s); */ if(card->ac97.supported_mixers|(1<<oss_mixer))
else if (i > 1) { emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][0], left,
sblive_readac97(card, AC97_RECORDSELECT, &reg); volume_params[oss_mixer].scale,
val &= ~recsrc[reg & 7]; volume_params[oss_mixer].muting);
if(card->ac97.stereo_mixers |(1<<oss_mixer))
emu10k1_set_volume_gpr(card, card->mgr.ctrl_gpr[oss_mixer][1], right,
volume_params[oss_mixer].scale,
volume_params[oss_mixer].muting);
} }
for (i = 0; i < 8; i++) {
if (val & recsrc[i]) {
DPD(2, "Selecting record source to be 0x%04x\n", 0x0101 * i);
sblive_writeac97(card, AC97_RECORDSELECT, 0x0101 * i);
return 0;
}
} }
return 0;
default:
i = _IOC_NR(cmd);
DPD(4, "SOUND_MIXER_WRITE(%d)\n", i);
if (i >= SOUND_MIXER_NRDEVICES)
return -EINVAL;
if (get_user(val, (int *) arg))
return -EFAULT;
if (emu10k1_mixer_wrch(card, i, val)) return ret;
return -EINVAL;
#ifdef OSS_DOCUMENTED_MIXER_SEMANTICS
return mixer_rdch(card, i, (int *) arg);
#else /* OSS_DOCUMENTED_MIXER_SEMANTICS */
return put_user(card->arrwVol[volidx[i]], (int *) arg);
#endif /* OSS_DOCUMENTED_MIXER_SEMANTICS */
}
} }
static int emu10k1_mixer_open(struct inode *inode, struct file *file) static int emu10k1_mixer_open(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = MINOR(inode->i_rdev);
struct emu10k1_card *card; struct emu10k1_card *card = NULL;
struct list_head *entry; struct list_head *entry;
DPF(4, "emu10k1_mixer_open()\n"); DPF(4, "emu10k1_mixer_open()\n");
...@@ -1090,13 +491,13 @@ static int emu10k1_mixer_open(struct inode *inode, struct file *file) ...@@ -1090,13 +491,13 @@ static int emu10k1_mixer_open(struct inode *inode, struct file *file)
list_for_each(entry, &emu10k1_devs) { list_for_each(entry, &emu10k1_devs) {
card = list_entry(entry, struct emu10k1_card, list); card = list_entry(entry, struct emu10k1_card, list);
if (card->mixer_num == minor) if (card->ac97.dev_mixer == minor)
break; goto match;
} }
if (entry == &emu10k1_devs)
return -ENODEV; return -ENODEV;
match:
file->private_data = card; file->private_data = card;
return 0; return 0;
} }
......
/*
**********************************************************************
* passthrough.c -- Emu10k1 digital passthrough
* Copyright (C) 2001 Juha Yrjl <jyrjola@cc.hut.fi>
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* May 15, 2001 Juha Yrjl base code release
*
**********************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*
**********************************************************************
*/
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/poll.h>
#include <linux/malloc.h>
#include <linux/version.h>
#include <linux/bitops.h>
#include <asm/io.h>
#include <linux/sched.h>
#include <linux/smp_lock.h>
#include <linux/wrapper.h>
#include "hwaccess.h"
#include "cardwo.h"
#include "cardwi.h"
#include "recmgr.h"
#include "irqmgr.h"
#include "audio.h"
#include "8010.h"
#include "passthrough.h"
static void pt_putsamples(struct pt_data *pt, u16 *ptr, u16 left, u16 right)
{
unsigned int idx;
ptr[pt->copyptr] = left;
idx = pt->copyptr + PT_SAMPLES/2;
idx %= PT_SAMPLES;
ptr[idx] = right;
}
static inline int pt_can_write(struct pt_data *pt)
{
return pt->blocks_copied < pt->blocks_played + 8;
}
static int pt_wait_for_write(struct emu10k1_wavedevice *wavedev, int nonblock)
{
struct emu10k1_card *card = wavedev->card;
struct pt_data *pt = &card->pt;
if (nonblock && !pt_can_write(pt))
return -EAGAIN;
while (!pt_can_write(pt) && pt->state != PT_STATE_INACTIVE) {
interruptible_sleep_on(&pt->wait);
if (signal_pending(current))
return -ERESTARTSYS;
}
if (pt->state == PT_STATE_INACTIVE)
return -EAGAIN;
return 0;
}
static int pt_putblock(struct emu10k1_wavedevice *wave_dev, u16 *block, int nonblock)
{
struct woinst *woinst = wave_dev->woinst;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
u16 *ptr = (u16 *) card->tankmem.addr;
int i = 0, r;
unsigned long flags;
r = pt_wait_for_write(wave_dev, nonblock);
if (r < 0)
return r;
spin_lock_irqsave(&card->pt.lock, flags);
while (i < PT_BLOCKSAMPLES) {
pt_putsamples(pt, ptr, block[2*i], block[2*i+1]);
if (pt->copyptr == 0)
pt->copyptr = PT_SAMPLES;
pt->copyptr--;
i++;
}
woinst->total_copied += PT_BLOCKSIZE;
pt->blocks_copied++;
if (pt->blocks_copied >= 4 && pt->state != PT_STATE_PLAYING) {
DPF(2, "activating digital pass-through playback\n");
sblive_writeptr(card, GPR_BASE + pt->enable_gpr, 0, 1);
pt->state = PT_STATE_PLAYING;
}
spin_unlock_irqrestore(&card->pt.lock, flags);
return 0;
}
static int pt_setup(struct emu10k1_wavedevice *wave_dev)
{
u32 bits;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
int i;
for (i = 0; i < 3; i++) {
pt->old_spcs[i] = sblive_readptr(card, SPCS0 + i, 0);
if (pt->spcs_to_use & (1 << i)) {
DPD(2, "using S/PDIF port %d\n", i);
bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT;
if (pt->ac3data)
bits |= SPCS_NOTAUDIODATA;
sblive_writeptr(card, SPCS0 + i, 0, bits);
}
}
return 0;
}
ssize_t emu10k1_pt_write(struct file *file, const char *buffer, size_t count)
{
struct emu10k1_wavedevice *wave_dev = (struct emu10k1_wavedevice *) file->private_data;
struct emu10k1_card *card = wave_dev->card;
struct pt_data *pt = &card->pt;
int nonblock, i, r, blocks, blocks_copied, bytes_copied = 0;
DPD(3, "emu10k1_pt_write(): %d bytes\n", count);
nonblock = file->f_flags & O_NONBLOCK;
if (card->tankmem.size < PT_SAMPLES*2)
return -EFAULT;
if (pt->state == PT_STATE_INACTIVE) {
DPF(2, "bufptr init\n");
pt->playptr = PT_SAMPLES-1;
pt->copyptr = PT_INITPTR;
pt->blocks_played = pt->blocks_copied = 0;
memset(card->tankmem.addr, 0, card->tankmem.size);
pt->state = PT_STATE_ACTIVATED;
pt->buf = kmalloc(PT_BLOCKSIZE, GFP_KERNEL);
pt->prepend_size = 0;
if (pt->buf == NULL)
return -ENOMEM;
pt_setup(wave_dev);
}
if (pt->prepend_size) {
int needed = PT_BLOCKSIZE - pt->prepend_size;
DPD(3, "prepend size %d, prepending %d bytes\n", pt->prepend_size, needed);
if (count < needed) {
copy_from_user(pt->buf + pt->prepend_size, buffer, count);
pt->prepend_size += count;
DPD(3, "prepend size now %d\n", pt->prepend_size);
return count;
}
copy_from_user(pt->buf + pt->prepend_size, buffer, needed);
r = pt_putblock(wave_dev, (u16 *) pt->buf, nonblock);
if (r)
return r;
bytes_copied += needed;
pt->prepend_size = 0;
}
blocks = (count-bytes_copied)/PT_BLOCKSIZE;
blocks_copied = 0;
while (blocks > 0) {
u16 *bufptr = (u16 *) buffer + (bytes_copied/2);
copy_from_user(pt->buf, bufptr, PT_BLOCKSIZE);
bufptr = (u16 *) pt->buf;
r = pt_putblock(wave_dev, bufptr, nonblock);
if (r) {
if (bytes_copied)
return bytes_copied;
else
return r;
}
bytes_copied += PT_BLOCKSIZE;
blocks--;
blocks_copied++;
}
i = count - bytes_copied;
if (i) {
pt->prepend_size = i;
copy_from_user(pt->buf, buffer + bytes_copied, i);
bytes_copied += i;
DPD(3, "filling prepend buffer with %d bytes", i);
}
return bytes_copied;
}
void emu10k1_pt_stop(struct emu10k1_card *card)
{
struct pt_data *pt = &card->pt;
int i;
unsigned long flags;
spin_lock_irqsave(&card->pt.lock, flags);
if (pt->state != PT_STATE_INACTIVE) {
DPF(2, "digital pass-through stopped\n");
sblive_writeptr(card, GPR_BASE + pt->enable_gpr, 0, 0);
for (i = 0; i < 3; i++) {
if (pt->spcs_to_use & (1 << i))
sblive_writeptr(card, SPCS0 + i, 0, pt->old_spcs[i]);
}
pt->state = PT_STATE_INACTIVE;
kfree(pt->buf);
}
spin_unlock_irqrestore(&card->pt.lock, flags);
}
void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev)
{
struct woinst *woinst = wave_dev->woinst;
struct pt_data *pt = &wave_dev->card->pt;
u32 pos;
if (pt->state == PT_STATE_PLAYING && pt->pos_gpr >= 0) {
pos = sblive_readptr(wave_dev->card, GPR_BASE + pt->pos_gpr, 0);
if (pos > PT_BLOCKSAMPLES)
pos = PT_BLOCKSAMPLES;
pos = 4 * (PT_BLOCKSAMPLES - pos);
} else
pos = 0;
woinst->total_played = pt->blocks_played * woinst->buffer.fragment_size + pos;
woinst->buffer.hw_pos = pos;
}
/*
**********************************************************************
* passthrough.h -- Emu10k1 digital passthrough header file
* Copyright (C) 2001 Juha Yrjl <jyrjola@cc.hut.fi>
*
**********************************************************************
*
* Date Author Summary of changes
* ---- ------ ------------------
* May 15, 2001 Juha Yrjl base code release
*
**********************************************************************
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program; if not, write to the Free
* Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139,
* USA.
*
**********************************************************************
*/
#ifndef _PASSTHROUGH_H
#define _PASSTHROUGH_H
#include "audio.h"
/* number of 16-bit stereo samples in XTRAM buffer */
#define PT_SAMPLES 0x8000
#define PT_BLOCKSAMPLES 0x400
#define PT_BLOCKSIZE (PT_BLOCKSAMPLES*4)
#define PT_BLOCKSIZE_LOG2 12
#define PT_BLOCKCOUNT (PT_SAMPLES/PT_BLOCKSAMPLES)
#define PT_INITPTR (PT_SAMPLES/2-1)
#define PT_STATE_INACTIVE 0
#define PT_STATE_ACTIVATED 1
#define PT_STATE_PLAYING 2
/* passthrough struct */
struct pt_data
{
u8 selected, state, spcs_to_use;
int intr_gpr, enable_gpr, pos_gpr;
u32 blocks_played, blocks_copied, old_spcs[3];
u32 playptr, copyptr;
u32 prepend_size;
u8 *buf;
u8 ac3data;
char *patch_name, *intr_gpr_name, *enable_gpr_name, *pos_gpr_name;
wait_queue_head_t wait;
spinlock_t lock;
};
ssize_t emu10k1_pt_write(struct file *file, const char *buf, size_t count);
void emu10k1_pt_stop(struct emu10k1_card *card);
void emu10k1_pt_waveout_update(struct emu10k1_wavedevice *wave_dev);
#endif /* _PASSTHROUGH_H */
...@@ -130,7 +130,7 @@ void emu10k1_set_record_src(struct emu10k1_card *card, struct wiinst *wiinst) ...@@ -130,7 +130,7 @@ void emu10k1_set_record_src(struct emu10k1_card *card, struct wiinst *wiinst)
break; break;
} }
DPD(2, "bus addx: %x\n", buffer->dma_handle); DPD(2, "bus addx: %#x\n", buffer->dma_handle);
sblive_writeptr(card, buffer->addrreg, 0, buffer->dma_handle); sblive_writeptr(card, buffer->addrreg, 0, buffer->dma_handle);
......
...@@ -65,21 +65,6 @@ int emu10k1_voice_alloc(struct emu10k1_card *card, struct emu_voice *voice) ...@@ -65,21 +65,6 @@ int emu10k1_voice_alloc(struct emu10k1_card *card, struct emu_voice *voice)
voice->card = card; voice->card = card;
voice->num = i; voice->num = i;
#ifdef PRIVATE_PCM_VOLUME
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
sblive_pcm_volume[i].channel_l = voice->num;
DPD(2, "preset left: %d\n", voice->num);
if (voice->flags & VOICE_FLAGS_STEREO) {
sblive_pcm_volume[i].channel_r = voice->num + 1;
DPD(2, "preset right: %d\n", voice->num + 1);
}
break;
}
}
#endif
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) { for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
DPD(2, " voice allocated -> %d\n", voice->num + i); DPD(2, " voice allocated -> %d\n", voice->num + i);
...@@ -104,20 +89,6 @@ void emu10k1_voice_free(struct emu_voice *voice) ...@@ -104,20 +89,6 @@ void emu10k1_voice_free(struct emu_voice *voice)
if (voice->usage == VOICE_USAGE_FREE) if (voice->usage == VOICE_USAGE_FREE)
return; return;
#ifdef PRIVATE_PCM_VOLUME
for (i = 0; i < MAX_PCM_CHANNELS; i++) {
if (sblive_pcm_volume[i].files == current->files) {
if (voice->num == sblive_pcm_volume[i].channel_l)
sblive_pcm_volume[i].channel_l = NUM_G;
if ((voice->flags & VOICE_FLAGS_STEREO)
&& (voice->num + 1) == sblive_pcm_volume[i].channel_r) {
sblive_pcm_volume[i].channel_r = NUM_G;
}
break;
}
}
#endif
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) { for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) {
DPD(2, " voice released -> %d\n", voice->num + i); DPD(2, " voice released -> %d\n", voice->num + i);
...@@ -139,8 +110,6 @@ void emu10k1_voice_free(struct emu_voice *voice) ...@@ -139,8 +110,6 @@ void emu10k1_voice_free(struct emu_voice *voice)
card->voicetable[voice->num + 1] = VOICE_USAGE_FREE; card->voicetable[voice->num + 1] = VOICE_USAGE_FREE;
spin_unlock_irqrestore(&card->lock, flags); spin_unlock_irqrestore(&card->lock, flags);
return;
} }
void emu10k1_voice_playback_setup(struct emu_voice *voice) void emu10k1_voice_playback_setup(struct emu_voice *voice)
...@@ -203,38 +172,22 @@ void emu10k1_voice_playback_setup(struct emu_voice *voice) ...@@ -203,38 +172,22 @@ void emu10k1_voice_playback_setup(struct emu_voice *voice)
/* pitch envelope */ /* pitch envelope */
PEFE_PITCHAMOUNT, 0, TAGLIST_END); PEFE_PITCHAMOUNT, 0, TAGLIST_END);
#ifdef PRIVATE_PCM_VOLUME
{
int j;
for (j = 0; j < MAX_PCM_CHANNELS; j++) {
if (sblive_pcm_volume[j].channel_l == voice->num + i) {
voice->params[i].initial_attn = (sblive_pcm_volume[j].channel_r < NUM_G) ? sblive_pcm_volume[i].attn_l :
// test for mono channel (reverse logic is correct here!)
(sblive_pcm_volume[j].attn_r >
sblive_pcm_volume[j].attn_l) ? sblive_pcm_volume[j].attn_l : sblive_pcm_volume[j].attn_r;
DPD(2, "set left volume %d\n", voice->params[i].initial_attn);
break;
} else if (sblive_pcm_volume[j].channel_r == voice->num + i) {
voice->params[i].initial_attn = sblive_pcm_volume[j].attn_r;
DPD(2, "set right volume %d\n", voice->params[i].initial_attn);
break;
}
}
}
#endif
voice->params[i].fc_target = 0xffff; voice->params[i].fc_target = 0xffff;
} }
return;
} }
void emu10k1_voice_start(struct emu_voice *voice, int set) void emu10k1_voices_start(struct emu_voice *first_voice, unsigned int num_voices, int set)
{ {
struct emu10k1_card *card = voice->card; struct emu10k1_card *card = first_voice->card;
int i; struct emu_voice *voice;
unsigned int voicenum;
int j;
DPF(2, "emu10k1_voice_start()\n"); DPF(2, "emu10k1_voices_start()\n");
for (voicenum = 0; voicenum < num_voices; voicenum++)
{
voice = first_voice + voicenum;
if (!set) { if (!set) {
u32 cra, ccis, cs, sample; u32 cra, ccis, cs, sample;
...@@ -255,8 +208,8 @@ void emu10k1_voice_start(struct emu_voice *voice, int set) ...@@ -255,8 +208,8 @@ void emu10k1_voice_start(struct emu_voice *voice, int set)
ccis *= 2; ccis *= 2;
} }
for(i = 0; i < cs; i++) for(j = 0; j < cs; j++)
sblive_writeptr(card, CD0 + i, voice->num, sample); sblive_writeptr(card, CD0 + j, voice->num, sample);
/* Reset cache */ /* Reset cache */
sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, 0); sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, 0);
...@@ -272,36 +225,49 @@ void emu10k1_voice_start(struct emu_voice *voice, int set) ...@@ -272,36 +225,49 @@ void emu10k1_voice_start(struct emu_voice *voice, int set)
sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, ccis); sblive_writeptr(card, CCR_CACHEINVALIDSIZE, voice->num, ccis);
} }
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) { for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr_tag(card, voice->num + i, sblive_writeptr_tag(card, voice->num + j,
IFATN, (voice->params[i].initial_fc << 8) | voice->params[i].initial_attn, IFATN, (voice->params[j].initial_fc << 8) | voice->params[j].initial_attn,
VTFT, (voice->params[i].volume_target << 16) | voice->params[i].fc_target, VTFT, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
CVCF, (voice->params[i].volume_target << 16) | voice->params[i].fc_target, CVCF, (voice->params[j].volume_target << 16) | voice->params[j].fc_target,
DCYSUSV, (voice->params[i].byampl_env_sustain << 8) | voice->params[i].byampl_env_decay, DCYSUSV, (voice->params[j].byampl_env_sustain << 8) | voice->params[j].byampl_env_decay,
TAGLIST_END); TAGLIST_END);
emu10k1_clear_stop_on_loop(card, voice->num + i); emu10k1_clear_stop_on_loop(card, voice->num + j);
}
}
sblive_writeptr(card, PTRX_PITCHTARGET, voice->num + i, voice->pitch_target); for (voicenum = 0; voicenum < num_voices; voicenum++)
{
voice = first_voice + voicenum;
if (i == 0) for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr(card, PTRX_PITCHTARGET, voice->num + j, voice->pitch_target);
if (j == 0)
sblive_writeptr(card, CPF_CURRENTPITCH, voice->num, voice->pitch_target); sblive_writeptr(card, CPF_CURRENTPITCH, voice->num, voice->pitch_target);
sblive_writeptr(card, IP, voice->num + i, voice->initial_pitch); sblive_writeptr(card, IP, voice->num + j, voice->initial_pitch);
}
} }
return;
} }
void emu10k1_voice_stop(struct emu_voice *voice) void emu10k1_voices_stop(struct emu_voice *first_voice, int num_voices)
{ {
struct emu10k1_card *card = voice->card; struct emu10k1_card *card = first_voice->card;
int i; struct emu_voice *voice;
unsigned int voice_num;
int j;
DPF(2, "emu10k1_voice_stop()\n"); DPF(2, "emu10k1_voice_stop()\n");
for (i = 0; i < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); i++) { for (voice_num = 0; voice_num < num_voices; voice_num++)
sblive_writeptr_tag(card, voice->num + i, {
voice = first_voice + voice_num;
for (j = 0; j < (voice->flags & VOICE_FLAGS_STEREO ? 2 : 1); j++) {
sblive_writeptr_tag(card, voice->num + j,
PTRX_PITCHTARGET, 0, PTRX_PITCHTARGET, 0,
CPF_CURRENTPITCH, 0, CPF_CURRENTPITCH, 0,
IFATN, 0xffff, IFATN, 0xffff,
...@@ -310,7 +276,6 @@ void emu10k1_voice_stop(struct emu_voice *voice) ...@@ -310,7 +276,6 @@ void emu10k1_voice_stop(struct emu_voice *voice)
IP, 0, IP, 0,
TAGLIST_END); TAGLIST_END);
} }
}
return;
} }
...@@ -85,7 +85,7 @@ struct emu_voice ...@@ -85,7 +85,7 @@ struct emu_voice
int emu10k1_voice_alloc(struct emu10k1_card *, struct emu_voice *); int emu10k1_voice_alloc(struct emu10k1_card *, struct emu_voice *);
void emu10k1_voice_free(struct emu_voice *); void emu10k1_voice_free(struct emu_voice *);
void emu10k1_voice_playback_setup(struct emu_voice *); void emu10k1_voice_playback_setup(struct emu_voice *);
void emu10k1_voice_start(struct emu_voice *, int); void emu10k1_voices_start(struct emu_voice *, unsigned int, int);
void emu10k1_voice_stop(struct emu_voice *); void emu10k1_voices_stop(struct emu_voice *, int);
#endif /* _VOICEMGR_H */ #endif /* _VOICEMGR_H */
...@@ -115,17 +115,15 @@ union bdflush_param { ...@@ -115,17 +115,15 @@ union bdflush_param {
struct { struct {
int nfract; /* Percentage of buffer cache dirty to int nfract; /* Percentage of buffer cache dirty to
activate bdflush */ activate bdflush */
int ndirty; /* Maximum number of dirty blocks to write out per int dummy1; /* old "ndirty" */
wake-cycle */ int dummy2; /* old "nrefill" */
int nrefill; /* Number of clean buffers to try to obtain int dummy3; /* unused */
each time we call refill */
int dummy1; /* unused */
int interval; /* jiffies delay between kupdate flushes */ int interval; /* jiffies delay between kupdate flushes */
int age_buffer; /* Time for normal buffer to age before we flush it */ int age_buffer; /* Time for normal buffer to age before we flush it */
int nfract_sync; /* Percentage of buffer cache dirty to int nfract_sync;/* Percentage of buffer cache dirty to
activate bdflush synchronously */ activate bdflush synchronously */
int dummy2; /* unused */ int dummy4; /* unused */
int dummy3; /* unused */ int dummy5; /* unused */
} b_un; } b_un;
unsigned int data[N_PARAM]; unsigned int data[N_PARAM];
} bdf_prm = {{30, 64, 64, 256, 5*HZ, 30*HZ, 60, 0, 0}}; } bdf_prm = {{30, 64, 64, 256, 5*HZ, 30*HZ, 60, 0, 0}};
...@@ -1067,7 +1065,6 @@ struct buffer_head * getblk(kdev_t dev, int block, int size) ...@@ -1067,7 +1065,6 @@ struct buffer_head * getblk(kdev_t dev, int block, int size)
out: out:
write_unlock(&hash_table_lock); write_unlock(&hash_table_lock);
spin_unlock(&lru_list_lock); spin_unlock(&lru_list_lock);
touch_buffer(bh);
return bh; return bh;
} }
...@@ -1234,6 +1231,7 @@ struct buffer_head * bread(kdev_t dev, int block, int size) ...@@ -1234,6 +1231,7 @@ struct buffer_head * bread(kdev_t dev, int block, int size)
struct buffer_head * bh; struct buffer_head * bh;
bh = getblk(dev, block, size); bh = getblk(dev, block, size);
touch_buffer(bh);
if (buffer_uptodate(bh)) if (buffer_uptodate(bh))
return bh; return bh;
ll_rw_block(READ, 1, &bh); ll_rw_block(READ, 1, &bh);
...@@ -2601,20 +2599,19 @@ static int sync_old_buffers(void) ...@@ -2601,20 +2599,19 @@ static int sync_old_buffers(void)
sync_supers(0); sync_supers(0);
unlock_kernel(); unlock_kernel();
spin_lock(&lru_list_lock);
for (;;) { for (;;) {
if (write_some_buffers(NODEV)) {
struct buffer_head *bh; struct buffer_head *bh;
spin_lock(&lru_list_lock); spin_lock(&lru_list_lock);
bh = lru_list[BUF_DIRTY]; bh = lru_list[BUF_DIRTY];
if (bh && !time_before(jiffies, bh->b_flushtime)) if (!bh || time_before(jiffies, bh->b_flushtime))
break;
if (write_some_buffers(NODEV))
continue; continue;
spin_unlock(&lru_list_lock);
}
run_task_queue(&tq_disk);
return 0; return 0;
} }
spin_unlock(&lru_list_lock);
return 0;
} }
int block_sync_page(struct page *page) int block_sync_page(struct page *page)
......
...@@ -148,6 +148,7 @@ extern void delete_from_swap_cache_nolock(struct page *page); ...@@ -148,6 +148,7 @@ extern void delete_from_swap_cache_nolock(struct page *page);
extern void free_page_and_swap_cache(struct page *page); extern void free_page_and_swap_cache(struct page *page);
/* linux/mm/swapfile.c */ /* linux/mm/swapfile.c */
extern int vm_swap_full(void);
extern unsigned int nr_swapfiles; extern unsigned int nr_swapfiles;
extern struct swap_info_struct swap_info[]; extern struct swap_info_struct swap_info[];
extern int is_swap_partition(kdev_t); extern int is_swap_partition(kdev_t);
......
...@@ -1098,9 +1098,10 @@ void swapin_readahead(swp_entry_t entry) ...@@ -1098,9 +1098,10 @@ void swapin_readahead(swp_entry_t entry)
*/ */
static int do_swap_page(struct mm_struct * mm, static int do_swap_page(struct mm_struct * mm,
struct vm_area_struct * vma, unsigned long address, struct vm_area_struct * vma, unsigned long address,
pte_t * page_table, swp_entry_t entry, int write_access) pte_t * page_table, pte_t orig_pte, int write_access)
{ {
struct page *page; struct page *page;
swp_entry_t entry = pte_to_swp_entry(orig_pte);
pte_t pte; pte_t pte;
spin_unlock(&mm->page_table_lock); spin_unlock(&mm->page_table_lock);
...@@ -1112,7 +1113,11 @@ static int do_swap_page(struct mm_struct * mm, ...@@ -1112,7 +1113,11 @@ static int do_swap_page(struct mm_struct * mm,
unlock_kernel(); unlock_kernel();
if (!page) { if (!page) {
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
return -1; /*
* Back out if somebody else faulted in this pte while
* we released the page table lock.
*/
return pte_same(*page_table, orig_pte) ? -1 : 1;
} }
} }
...@@ -1128,7 +1133,7 @@ static int do_swap_page(struct mm_struct * mm, ...@@ -1128,7 +1133,7 @@ static int do_swap_page(struct mm_struct * mm,
* released the page table lock. * released the page table lock.
*/ */
spin_lock(&mm->page_table_lock); spin_lock(&mm->page_table_lock);
if (pte_present(*page_table)) { if (!pte_same(*page_table, orig_pte)) {
UnlockPage(page); UnlockPage(page);
page_cache_release(page); page_cache_release(page);
return 1; return 1;
...@@ -1139,8 +1144,14 @@ static int do_swap_page(struct mm_struct * mm, ...@@ -1139,8 +1144,14 @@ static int do_swap_page(struct mm_struct * mm,
pte = mk_pte(page, vma->vm_page_prot); pte = mk_pte(page, vma->vm_page_prot);
swap_free(entry); swap_free(entry);
if (write_access && exclusive_swap_page(page)) if (exclusive_swap_page(page)) {
if (write_access)
pte = pte_mkwrite(pte_mkdirty(pte)); pte = pte_mkwrite(pte_mkdirty(pte));
if (vm_swap_full()) {
delete_from_swap_cache_nolock(page);
pte = pte_mkdirty(pte);
}
}
UnlockPage(page); UnlockPage(page);
flush_page_to_ram(page); flush_page_to_ram(page);
...@@ -1297,7 +1308,7 @@ static inline int handle_pte_fault(struct mm_struct *mm, ...@@ -1297,7 +1308,7 @@ static inline int handle_pte_fault(struct mm_struct *mm,
*/ */
if (pte_none(entry)) if (pte_none(entry))
return do_no_page(mm, vma, address, write_access, pte); return do_no_page(mm, vma, address, write_access, pte);
return do_swap_page(mm, vma, address, pte, pte_to_swp_entry(entry), write_access); return do_swap_page(mm, vma, address, pte, entry, write_access);
} }
if (write_access) { if (write_access) {
......
...@@ -589,7 +589,7 @@ unsigned int nr_free_buffer_pages (void) ...@@ -589,7 +589,7 @@ unsigned int nr_free_buffer_pages (void)
zonelist_t *zonelist; zonelist_t *zonelist;
zone_t **zonep, *zone; zone_t **zonep, *zone;
zonelist = contig_page_data.node_zonelists + (GFP_KERNEL & GFP_ZONEMASK); zonelist = contig_page_data.node_zonelists + (GFP_NOFS & GFP_ZONEMASK);
zonep = zonelist->zones; zonep = zonelist->zones;
for (zone = *zonep++; zone; zone = *zonep++) { for (zone = *zonep++; zone; zone = *zonep++) {
......
...@@ -19,11 +19,31 @@ ...@@ -19,11 +19,31 @@
spinlock_t swaplock = SPIN_LOCK_UNLOCKED; spinlock_t swaplock = SPIN_LOCK_UNLOCKED;
unsigned int nr_swapfiles; unsigned int nr_swapfiles;
int total_swap_pages;
struct swap_list_t swap_list = {-1, -1}; struct swap_list_t swap_list = {-1, -1};
struct swap_info_struct swap_info[MAX_SWAPFILES]; struct swap_info_struct swap_info[MAX_SWAPFILES];
/*
* When swap space gets filled up, we will set this flag.
* This will make do_swap_page(), in the page fault path,
* free swap entries on swapin so we'll reclaim swap space
* in order to be able to swap something out.
*
* At the moment we start reclaiming when swap usage goes
* over 80% of swap space.
*
* XXX: Random numbers, fixme.
*/
#define SWAP_FULL_PCT 80
int vm_swap_full (void)
{
int swap_used = total_swap_pages - nr_swap_pages;
return swap_used * 100 > total_swap_pages * SWAP_FULL_PCT;
}
#define SWAPFILE_CLUSTER 256 #define SWAPFILE_CLUSTER 256
static inline int scan_swap_map(struct swap_info_struct *si, unsigned short count) static inline int scan_swap_map(struct swap_info_struct *si, unsigned short count)
...@@ -329,56 +349,26 @@ static void unuse_process(struct mm_struct * mm, ...@@ -329,56 +349,26 @@ static void unuse_process(struct mm_struct * mm,
} }
/* /*
* We completely avoid races by reading each swap page in advance, * this is called when we find a page in the swap list
* and then search for the process using it. All the necessary * all the locks have been dropped at this point which
* page table adjustments can then be made atomically. * isn't a problem because we rescan the swap map
* and we _don't_ clear the refrence count if for
* some reason it isn't 0
*/ */
static int try_to_unuse(unsigned int type)
static inline int free_found_swap_entry(unsigned int type, int i)
{ {
struct swap_info_struct * si = &swap_info[type];
struct task_struct *p; struct task_struct *p;
struct page *page; struct page *page;
swp_entry_t entry; swp_entry_t entry;
int i;
while (1) { entry = SWP_ENTRY(type, i);
/*
* The algorithm is inefficient but seldomly used
* and probably not worth fixing.
*
* Make sure that we aren't completely killing
* interactive performance.
*/
if (current->need_resched)
schedule();
/* /*
* Find a swap page in use and read it in. * Get a page for the entry, using the existing swap
*/ * cache page if there is one. Otherwise, get a clean
swap_device_lock(si); * page and read the swap into it.
for (i = 1; i < si->max ; i++) {
if (si->swap_map[i] > 0 && si->swap_map[i] != SWAP_MAP_BAD) {
/*
* Prevent swaphandle from being completely
* unused by swap_free while we are trying
* to read in the page - this prevents warning
* messages from rw_swap_page_base.
*/ */
if (si->swap_map[i] != SWAP_MAP_MAX)
si->swap_map[i]++;
swap_device_unlock(si);
goto found_entry;
}
}
swap_device_unlock(si);
break;
found_entry:
entry = SWP_ENTRY(type, i);
/* Get a page for the entry, using the existing swap
cache page if there is one. Otherwise, get a clean
page and read the swap into it. */
page = read_swap_cache_async(entry); page = read_swap_cache_async(entry);
if (!page) { if (!page) {
swap_free(entry); swap_free(entry);
...@@ -393,25 +383,100 @@ static int try_to_unuse(unsigned int type) ...@@ -393,25 +383,100 @@ static int try_to_unuse(unsigned int type)
unuse_process(p->mm, entry, page); unuse_process(p->mm, entry, page);
read_unlock(&tasklist_lock); read_unlock(&tasklist_lock);
shmem_unuse(entry, page); shmem_unuse(entry, page);
/* Now get rid of the extra reference to the temporary /*
page we've been using. */ * Now get rid of the extra reference to the temporary
* page we've been using.
*/
page_cache_release(page); page_cache_release(page);
/* /*
* Check for and clear any overflowed swap map counts. * Check for and clear any overflowed swap map counts.
*/ */
swap_free(entry); swap_free(entry);
return 0;
}
/*
* We completely avoid races by reading each swap page in advance,
* and then search for the process using it. All the necessary
* page table adjustments can then be made atomically.
*/
static int try_to_unuse(unsigned int type)
{
struct swap_info_struct * si = &swap_info[type];
int ret, foundpage;
do {
int i;
/*
* The algorithm is inefficient but seldomly used
*
* Find a swap page in use and read it in.
*/
foundpage = 0;
swap_device_lock(si);
for (i = 1; i < si->max ; i++) {
int count = si->swap_map[i];
if (!count || count == SWAP_MAP_BAD)
continue;
/*
* Prevent swaphandle from being completely
* unused by swap_free while we are trying
* to read in the page - this prevents warning
* messages from rw_swap_page_base.
*/
foundpage = 1;
if (count != SWAP_MAP_MAX)
si->swap_map[i] = count + 1;
swap_device_unlock(si);
ret = free_found_swap_entry(type,i);
if (ret)
return ret;
/*
* we pick up the swap_list_lock() to guard the nr_swap_pages,
* si->swap_map[] should only be changed if it is SWAP_MAP_MAX
* otherwise ugly stuff can happen with other people who are in
* the middle of a swap operation to this device. This kind of
* operation can sometimes be detected with the undead swap
* check. Don't worry about these 'undead' entries for now
* they will be caught the next time though the top loop.
* Do worry, about the weak locking that allows this to happen
* because if it happens to a page that is SWAP_MAP_MAX
* then bad stuff can happen.
*/
swap_list_lock(); swap_list_lock();
swap_device_lock(si); swap_device_lock(si);
if (si->swap_map[i] > 0) { if (si->swap_map[i] > 0) {
if (si->swap_map[i] != SWAP_MAP_MAX) /* normally this would just kill the swap page if
* it still existed, it appears though that the locks
* are a little fuzzy
*/
if (si->swap_map[i] != SWAP_MAP_MAX) {
printk("VM: Undead swap entry %08lx\n", printk("VM: Undead swap entry %08lx\n",
entry.val); SWP_ENTRY(type, i).val);
} else {
nr_swap_pages++; nr_swap_pages++;
si->swap_map[i] = 0; si->swap_map[i] = 0;
} }
}
swap_device_unlock(si); swap_device_unlock(si);
swap_list_unlock(); swap_list_unlock();
/*
* This lock stuff is ulgy!
* Make sure that we aren't completely killing
* interactive performance.
*/
if (current->need_resched)
schedule();
swap_device_lock(si);
} }
swap_device_unlock(si);
} while (foundpage);
return 0; return 0;
} }
...@@ -462,6 +527,7 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -462,6 +527,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
swap_list.next = swap_list.head; swap_list.next = swap_list.head;
} }
nr_swap_pages -= p->pages; nr_swap_pages -= p->pages;
total_swap_pages -= p->pages;
swap_list_unlock(); swap_list_unlock();
p->flags = SWP_USED; p->flags = SWP_USED;
err = try_to_unuse(type); err = try_to_unuse(type);
...@@ -477,6 +543,7 @@ asmlinkage long sys_swapoff(const char * specialfile) ...@@ -477,6 +543,7 @@ asmlinkage long sys_swapoff(const char * specialfile)
else else
swap_info[prev].next = p - swap_info; swap_info[prev].next = p - swap_info;
nr_swap_pages += p->pages; nr_swap_pages += p->pages;
total_swap_pages += p->pages;
swap_list_unlock(); swap_list_unlock();
p->flags = SWP_WRITEOK; p->flags = SWP_WRITEOK;
goto out_dput; goto out_dput;
...@@ -764,6 +831,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags) ...@@ -764,6 +831,7 @@ asmlinkage long sys_swapon(const char * specialfile, int swap_flags)
p->pages = nr_good_pages; p->pages = nr_good_pages;
swap_list_lock(); swap_list_lock();
nr_swap_pages += nr_good_pages; nr_swap_pages += nr_good_pages;
total_swap_pages += nr_good_pages;
printk(KERN_INFO "Adding Swap: %dk swap-space (priority %d)\n", printk(KERN_INFO "Adding Swap: %dk swap-space (priority %d)\n",
nr_good_pages<<(PAGE_SHIFT-10), p->prio); nr_good_pages<<(PAGE_SHIFT-10), p->prio);
......
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