2019-05-27 06:55:05 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Driver for ESS Solo-1 (ES1938, ES1946, ES1969) soundcard
|
|
|
|
* Copyright (c) by Jaromir Koutek <miri@punknet.cz>,
|
2007-10-15 07:50:19 +00:00
|
|
|
* Jaroslav Kysela <perex@perex.cz>,
|
2005-04-16 22:20:36 +00:00
|
|
|
* Thomas Sailer <sailer@ife.ee.ethz.ch>,
|
|
|
|
* Abramo Bagnara <abramo@alsa-project.org>,
|
|
|
|
* Markus Gruber <gruber@eikon.tum.de>
|
|
|
|
*
|
|
|
|
* Rewritten from sonicvibes.c source.
|
|
|
|
*
|
|
|
|
* TODO:
|
|
|
|
* Rewrite better spinlocks
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
NOTES:
|
|
|
|
- Capture data is written unaligned starting from dma_base + 1 so I need to
|
|
|
|
disable mmap and to add a copy callback.
|
|
|
|
- After several cycle of the following:
|
|
|
|
while : ; do arecord -d1 -f cd -t raw | aplay -f cd ; done
|
|
|
|
a "playback write error (DMA or IRQ trouble?)" may happen.
|
|
|
|
This is due to playback interrupts not generated.
|
|
|
|
I suspect a timing issue.
|
|
|
|
- Sometimes the interrupt handler is invoked wrongly during playback.
|
|
|
|
This generates some harmless "Unexpected hw_pointer: wrong interrupt
|
|
|
|
acknowledge".
|
|
|
|
I've seen that using small period sizes.
|
|
|
|
Reproducible with:
|
|
|
|
mpg123 test.mp3 &
|
|
|
|
hdparm -t -T /dev/hda
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/gameport.h>
|
2011-07-15 17:13:37 +00:00
|
|
|
#include <linux/module.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/delay.h>
|
2006-03-28 09:56:48 +00:00
|
|
|
#include <linux/dma-mapping.h>
|
2015-01-28 15:49:33 +00:00
|
|
|
#include <linux/io.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/control.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/opl3.h>
|
|
|
|
#include <sound/mpu401.h>
|
|
|
|
#include <sound/initval.h>
|
2006-09-06 11:35:27 +00:00
|
|
|
#include <sound/tlv.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Jaromir Koutek <miri@punknet.cz>");
|
|
|
|
MODULE_DESCRIPTION("ESS Solo-1");
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
2016-11-12 22:26:41 +00:00
|
|
|
#if IS_REACHABLE(CONFIG_GAMEPORT)
|
2005-04-16 22:20:36 +00:00
|
|
|
#define SUPPORT_JOYSTICK 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
|
|
|
|
static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
|
2011-12-15 03:19:36 +00:00
|
|
|
static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
module_param_array(index, int, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(index, "Index value for ESS Solo-1 soundcard.");
|
|
|
|
module_param_array(id, charp, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(id, "ID string for ESS Solo-1 soundcard.");
|
|
|
|
module_param_array(enable, bool, NULL, 0444);
|
|
|
|
MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard.");
|
|
|
|
|
|
|
|
#define SLIO_REG(chip, x) ((chip)->io_port + ESSIO_REG_##x)
|
|
|
|
|
|
|
|
#define SLDM_REG(chip, x) ((chip)->ddma_port + ESSDM_REG_##x)
|
|
|
|
|
|
|
|
#define SLSB_REG(chip, x) ((chip)->sb_port + ESSSB_REG_##x)
|
|
|
|
|
|
|
|
#define SL_PCI_LEGACYCONTROL 0x40
|
|
|
|
#define SL_PCI_CONFIG 0x50
|
|
|
|
#define SL_PCI_DDMACONTROL 0x60
|
|
|
|
|
|
|
|
#define ESSIO_REG_AUDIO2DMAADDR 0
|
|
|
|
#define ESSIO_REG_AUDIO2DMACOUNT 4
|
|
|
|
#define ESSIO_REG_AUDIO2MODE 6
|
|
|
|
#define ESSIO_REG_IRQCONTROL 7
|
|
|
|
|
|
|
|
#define ESSDM_REG_DMAADDR 0x00
|
|
|
|
#define ESSDM_REG_DMACOUNT 0x04
|
|
|
|
#define ESSDM_REG_DMACOMMAND 0x08
|
|
|
|
#define ESSDM_REG_DMASTATUS 0x08
|
|
|
|
#define ESSDM_REG_DMAMODE 0x0b
|
|
|
|
#define ESSDM_REG_DMACLEAR 0x0d
|
|
|
|
#define ESSDM_REG_DMAMASK 0x0f
|
|
|
|
|
|
|
|
#define ESSSB_REG_FMLOWADDR 0x00
|
|
|
|
#define ESSSB_REG_FMHIGHADDR 0x02
|
|
|
|
#define ESSSB_REG_MIXERADDR 0x04
|
|
|
|
#define ESSSB_REG_MIXERDATA 0x05
|
|
|
|
|
|
|
|
#define ESSSB_IREG_AUDIO1 0x14
|
|
|
|
#define ESSSB_IREG_MICMIX 0x1a
|
|
|
|
#define ESSSB_IREG_RECSRC 0x1c
|
|
|
|
#define ESSSB_IREG_MASTER 0x32
|
|
|
|
#define ESSSB_IREG_FM 0x36
|
|
|
|
#define ESSSB_IREG_AUXACD 0x38
|
|
|
|
#define ESSSB_IREG_AUXB 0x3a
|
|
|
|
#define ESSSB_IREG_PCSPEAKER 0x3c
|
|
|
|
#define ESSSB_IREG_LINE 0x3e
|
|
|
|
#define ESSSB_IREG_SPATCONTROL 0x50
|
|
|
|
#define ESSSB_IREG_SPATLEVEL 0x52
|
|
|
|
#define ESSSB_IREG_MASTER_LEFT 0x60
|
|
|
|
#define ESSSB_IREG_MASTER_RIGHT 0x62
|
|
|
|
#define ESSSB_IREG_MPU401CONTROL 0x64
|
|
|
|
#define ESSSB_IREG_MICMIXRECORD 0x68
|
|
|
|
#define ESSSB_IREG_AUDIO2RECORD 0x69
|
|
|
|
#define ESSSB_IREG_AUXACDRECORD 0x6a
|
|
|
|
#define ESSSB_IREG_FMRECORD 0x6b
|
|
|
|
#define ESSSB_IREG_AUXBRECORD 0x6c
|
|
|
|
#define ESSSB_IREG_MONO 0x6d
|
|
|
|
#define ESSSB_IREG_LINERECORD 0x6e
|
|
|
|
#define ESSSB_IREG_MONORECORD 0x6f
|
|
|
|
#define ESSSB_IREG_AUDIO2SAMPLE 0x70
|
|
|
|
#define ESSSB_IREG_AUDIO2MODE 0x71
|
|
|
|
#define ESSSB_IREG_AUDIO2FILTER 0x72
|
|
|
|
#define ESSSB_IREG_AUDIO2TCOUNTL 0x74
|
|
|
|
#define ESSSB_IREG_AUDIO2TCOUNTH 0x76
|
|
|
|
#define ESSSB_IREG_AUDIO2CONTROL1 0x78
|
|
|
|
#define ESSSB_IREG_AUDIO2CONTROL2 0x7a
|
|
|
|
#define ESSSB_IREG_AUDIO2 0x7c
|
|
|
|
|
|
|
|
#define ESSSB_REG_RESET 0x06
|
|
|
|
|
|
|
|
#define ESSSB_REG_READDATA 0x0a
|
|
|
|
#define ESSSB_REG_WRITEDATA 0x0c
|
|
|
|
#define ESSSB_REG_READSTATUS 0x0c
|
|
|
|
|
|
|
|
#define ESSSB_REG_STATUS 0x0e
|
|
|
|
|
|
|
|
#define ESS_CMD_EXTSAMPLERATE 0xa1
|
|
|
|
#define ESS_CMD_FILTERDIV 0xa2
|
|
|
|
#define ESS_CMD_DMACNTRELOADL 0xa4
|
|
|
|
#define ESS_CMD_DMACNTRELOADH 0xa5
|
|
|
|
#define ESS_CMD_ANALOGCONTROL 0xa8
|
|
|
|
#define ESS_CMD_IRQCONTROL 0xb1
|
|
|
|
#define ESS_CMD_DRQCONTROL 0xb2
|
|
|
|
#define ESS_CMD_RECLEVEL 0xb4
|
|
|
|
#define ESS_CMD_SETFORMAT 0xb6
|
|
|
|
#define ESS_CMD_SETFORMAT2 0xb7
|
|
|
|
#define ESS_CMD_DMACONTROL 0xb8
|
|
|
|
#define ESS_CMD_DMATYPE 0xb9
|
|
|
|
#define ESS_CMD_OFFSETLEFT 0xba
|
|
|
|
#define ESS_CMD_OFFSETRIGHT 0xbb
|
|
|
|
#define ESS_CMD_READREG 0xc0
|
|
|
|
#define ESS_CMD_ENABLEEXT 0xc6
|
|
|
|
#define ESS_CMD_PAUSEDMA 0xd0
|
|
|
|
#define ESS_CMD_ENABLEAUDIO1 0xd1
|
|
|
|
#define ESS_CMD_STOPAUDIO1 0xd3
|
|
|
|
#define ESS_CMD_AUDIO1STATUS 0xd8
|
|
|
|
#define ESS_CMD_CONTDMA 0xd4
|
|
|
|
#define ESS_CMD_TESTIRQ 0xf2
|
|
|
|
|
|
|
|
#define ESS_RECSRC_MIC 0
|
|
|
|
#define ESS_RECSRC_AUXACD 2
|
|
|
|
#define ESS_RECSRC_AUXB 5
|
|
|
|
#define ESS_RECSRC_LINE 6
|
|
|
|
#define ESS_RECSRC_NONE 7
|
|
|
|
|
|
|
|
#define DAC1 0x01
|
|
|
|
#define ADC1 0x02
|
|
|
|
#define DAC2 0x04
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define SAVED_REG_SIZE 32 /* max. number of registers to save */
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 {
|
2005-04-16 22:20:36 +00:00
|
|
|
int irq;
|
|
|
|
|
|
|
|
unsigned long io_port;
|
|
|
|
unsigned long sb_port;
|
|
|
|
unsigned long vc_port;
|
|
|
|
unsigned long mpu_port;
|
|
|
|
unsigned long game_port;
|
|
|
|
unsigned long ddma_port;
|
|
|
|
|
|
|
|
unsigned char irqmask;
|
|
|
|
unsigned char revision;
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_kcontrol *hw_volume;
|
|
|
|
struct snd_kcontrol *hw_switch;
|
|
|
|
struct snd_kcontrol *master_volume;
|
|
|
|
struct snd_kcontrol *master_switch;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
struct pci_dev *pci;
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_card *card;
|
|
|
|
struct snd_pcm *pcm;
|
|
|
|
struct snd_pcm_substream *capture_substream;
|
|
|
|
struct snd_pcm_substream *playback1_substream;
|
|
|
|
struct snd_pcm_substream *playback2_substream;
|
|
|
|
struct snd_rawmidi *rmidi;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
unsigned int dma1_size;
|
|
|
|
unsigned int dma2_size;
|
|
|
|
unsigned int dma1_start;
|
|
|
|
unsigned int dma2_start;
|
|
|
|
unsigned int dma1_shift;
|
|
|
|
unsigned int dma2_shift;
|
2008-01-30 07:25:13 +00:00
|
|
|
unsigned int last_capture_dmaaddr;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int active;
|
|
|
|
|
|
|
|
spinlock_t reg_lock;
|
|
|
|
spinlock_t mixer_lock;
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_info_entry *proc_entry;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef SUPPORT_JOYSTICK
|
|
|
|
struct gameport *gameport;
|
|
|
|
#endif
|
|
|
|
unsigned char saved_regs[SAVED_REG_SIZE];
|
|
|
|
};
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2014-08-08 13:56:03 +00:00
|
|
|
static const struct pci_device_id snd_es1938_ids[] = {
|
2009-06-25 05:13:35 +00:00
|
|
|
{ PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */
|
2005-04-16 22:20:36 +00:00
|
|
|
{ 0, }
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, snd_es1938_ids);
|
|
|
|
|
|
|
|
#define RESET_LOOP_TIMEOUT 0x10000
|
|
|
|
#define WRITE_LOOP_TIMEOUT 0x10000
|
|
|
|
#define GET_LOOP_TIMEOUT 0x01000
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Write to a mixer register
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_mixer_write(struct es1938 *chip, unsigned char reg, unsigned char val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->mixer_lock, flags);
|
|
|
|
outb(reg, SLSB_REG(chip, MIXERADDR));
|
|
|
|
outb(val, SLSB_REG(chip, MIXERDATA));
|
|
|
|
spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev, "Mixer reg %02x set to %02x\n", reg, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Read from a mixer register
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_mixer_read(struct es1938 *chip, unsigned char reg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int data;
|
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->mixer_lock, flags);
|
|
|
|
outb(reg, SLSB_REG(chip, MIXERADDR));
|
|
|
|
data = inb(SLSB_REG(chip, MIXERDATA));
|
|
|
|
spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev, "Mixer reg %02x now is %02x\n", reg, data);
|
2005-04-16 22:20:36 +00:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Write to some bits of a mixer register (return old value)
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_mixer_bits(struct es1938 *chip, unsigned char reg,
|
|
|
|
unsigned char mask, unsigned char val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char old, new, oval;
|
|
|
|
spin_lock_irqsave(&chip->mixer_lock, flags);
|
|
|
|
outb(reg, SLSB_REG(chip, MIXERADDR));
|
|
|
|
old = inb(SLSB_REG(chip, MIXERDATA));
|
|
|
|
oval = old & mask;
|
|
|
|
if (val != oval) {
|
|
|
|
new = (old & ~mask) | (val & mask);
|
|
|
|
outb(new, SLSB_REG(chip, MIXERDATA));
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"Mixer reg %02x was %02x, set to %02x\n",
|
2005-10-20 16:26:44 +00:00
|
|
|
reg, old, new);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&chip->mixer_lock, flags);
|
|
|
|
return oval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Write command to Controller Registers
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_write_cmd(struct es1938 *chip, unsigned char cmd)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char v;
|
|
|
|
for (i = 0; i < WRITE_LOOP_TIMEOUT; i++) {
|
2021-06-08 14:04:59 +00:00
|
|
|
v = inb(SLSB_REG(chip, READSTATUS));
|
|
|
|
if (!(v & 0x80)) {
|
2005-04-16 22:20:36 +00:00
|
|
|
outb(cmd, SLSB_REG(chip, WRITEDATA));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(chip->card->dev,
|
|
|
|
"snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Read the Read Data Buffer
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_byte(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
unsigned char v;
|
2021-06-08 14:04:59 +00:00
|
|
|
for (i = GET_LOOP_TIMEOUT; i; i--) {
|
|
|
|
v = inb(SLSB_REG(chip, STATUS));
|
|
|
|
if (v & 0x80)
|
2005-04-16 22:20:36 +00:00
|
|
|
return inb(SLSB_REG(chip, READDATA));
|
2021-06-08 14:04:59 +00:00
|
|
|
}
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(chip->card->dev, "get_byte timeout: status 0x02%x\n", v);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Write value cmd register
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_write(struct es1938 *chip, unsigned char reg, unsigned char val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->reg_lock, flags);
|
|
|
|
snd_es1938_write_cmd(chip, reg);
|
|
|
|
snd_es1938_write_cmd(chip, val);
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev, "Reg %02x set to %02x\n", reg, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Read data from cmd register and return it
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static unsigned char snd_es1938_read(struct es1938 *chip, unsigned char reg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
unsigned long flags;
|
|
|
|
spin_lock_irqsave(&chip->reg_lock, flags);
|
|
|
|
snd_es1938_write_cmd(chip, ESS_CMD_READREG);
|
|
|
|
snd_es1938_write_cmd(chip, reg);
|
|
|
|
val = snd_es1938_get_byte(chip);
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev, "Reg %02x now is %02x\n", reg, val);
|
2005-04-16 22:20:36 +00:00
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------
|
|
|
|
* Write data to cmd register and return old value
|
|
|
|
* -----------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_bits(struct es1938 *chip, unsigned char reg, unsigned char mask,
|
|
|
|
unsigned char val)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned char old, new, oval;
|
|
|
|
spin_lock_irqsave(&chip->reg_lock, flags);
|
|
|
|
snd_es1938_write_cmd(chip, ESS_CMD_READREG);
|
|
|
|
snd_es1938_write_cmd(chip, reg);
|
|
|
|
old = snd_es1938_get_byte(chip);
|
|
|
|
oval = old & mask;
|
|
|
|
if (val != oval) {
|
|
|
|
snd_es1938_write_cmd(chip, reg);
|
|
|
|
new = (old & ~mask) | (val & mask);
|
|
|
|
snd_es1938_write_cmd(chip, new);
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev, "Reg %02x was %02x, set to %02x\n",
|
2005-10-20 16:26:44 +00:00
|
|
|
reg, old, new);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
|
|
return oval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
* Reset the chip
|
|
|
|
* --------------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_reset(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
outb(3, SLSB_REG(chip, RESET));
|
|
|
|
inb(SLSB_REG(chip, RESET));
|
|
|
|
outb(0, SLSB_REG(chip, RESET));
|
|
|
|
for (i = 0; i < RESET_LOOP_TIMEOUT; i++) {
|
|
|
|
if (inb(SLSB_REG(chip, STATUS)) & 0x80) {
|
|
|
|
if (inb(SLSB_REG(chip, READDATA)) == 0xaa)
|
|
|
|
goto __next;
|
|
|
|
}
|
|
|
|
}
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(chip->card->dev, "ESS Solo-1 reset failed\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
__next:
|
|
|
|
snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT);
|
|
|
|
|
|
|
|
/* Demand transfer DMA: 4 bytes per DMA request */
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMATYPE, 2);
|
|
|
|
|
|
|
|
/* Change behaviour of register A1
|
|
|
|
4x oversampling
|
|
|
|
2nd channel DAC asynchronous */
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2MODE, 0x32);
|
|
|
|
/* enable/select DMA channel and IRQ channel */
|
|
|
|
snd_es1938_bits(chip, ESS_CMD_IRQCONTROL, 0xf0, 0x50);
|
|
|
|
snd_es1938_bits(chip, ESS_CMD_DRQCONTROL, 0xf0, 0x50);
|
|
|
|
snd_es1938_write_cmd(chip, ESS_CMD_ENABLEAUDIO1);
|
|
|
|
/* Set spatializer parameters to recommended values */
|
|
|
|
snd_es1938_mixer_write(chip, 0x54, 0x8f);
|
|
|
|
snd_es1938_mixer_write(chip, 0x56, 0x95);
|
|
|
|
snd_es1938_mixer_write(chip, 0x58, 0x94);
|
|
|
|
snd_es1938_mixer_write(chip, 0x5a, 0x80);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
* Reset the FIFOs
|
|
|
|
* --------------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_reset_fifo(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
outb(2, SLSB_REG(chip, RESET));
|
|
|
|
outb(0, SLSB_REG(chip, RESET));
|
|
|
|
}
|
|
|
|
|
2017-06-07 12:19:56 +00:00
|
|
|
static const struct snd_ratnum clocks[2] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.num = 793800,
|
|
|
|
.den_min = 1,
|
|
|
|
.den_max = 128,
|
|
|
|
.den_step = 1,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.num = 768000,
|
|
|
|
.den_min = 1,
|
|
|
|
.den_max = 128,
|
|
|
|
.den_step = 1,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-06-07 12:19:56 +00:00
|
|
|
static const struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.nrats = 2,
|
|
|
|
.rats = clocks,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_rate_set(struct es1938 *chip,
|
|
|
|
struct snd_pcm_substream *substream,
|
2005-04-16 22:20:36 +00:00
|
|
|
int mode)
|
|
|
|
{
|
|
|
|
unsigned int bits, div0;
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (runtime->rate_num == clocks[0].num)
|
|
|
|
bits = 128 - runtime->rate_den;
|
|
|
|
else
|
|
|
|
bits = 256 - runtime->rate_den;
|
|
|
|
|
|
|
|
/* set filter register */
|
|
|
|
div0 = 256 - 7160000*20/(8*82*runtime->rate);
|
|
|
|
|
|
|
|
if (mode == DAC2) {
|
|
|
|
snd_es1938_mixer_write(chip, 0x70, bits);
|
|
|
|
snd_es1938_mixer_write(chip, 0x72, div0);
|
|
|
|
} else {
|
|
|
|
snd_es1938_write(chip, 0xA1, bits);
|
|
|
|
snd_es1938_write(chip, 0xA2, div0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
* Configure Solo1 builtin DMA Controller
|
|
|
|
* --------------------------------------------------------------------*/
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_playback1_setdma(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
outb(0x00, SLIO_REG(chip, AUDIO2MODE));
|
|
|
|
outl(chip->dma2_start, SLIO_REG(chip, AUDIO2DMAADDR));
|
|
|
|
outw(0, SLIO_REG(chip, AUDIO2DMACOUNT));
|
|
|
|
outw(chip->dma2_size, SLIO_REG(chip, AUDIO2DMACOUNT));
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_playback2_setdma(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* Enable DMA controller */
|
|
|
|
outb(0xc4, SLDM_REG(chip, DMACOMMAND));
|
|
|
|
/* 1. Master reset */
|
|
|
|
outb(0, SLDM_REG(chip, DMACLEAR));
|
|
|
|
/* 2. Mask DMA */
|
|
|
|
outb(1, SLDM_REG(chip, DMAMASK));
|
|
|
|
outb(0x18, SLDM_REG(chip, DMAMODE));
|
|
|
|
outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
|
|
|
|
outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
|
|
|
|
/* 3. Unmask DMA */
|
|
|
|
outb(0, SLDM_REG(chip, DMAMASK));
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_capture_setdma(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* Enable DMA controller */
|
|
|
|
outb(0xc4, SLDM_REG(chip, DMACOMMAND));
|
|
|
|
/* 1. Master reset */
|
|
|
|
outb(0, SLDM_REG(chip, DMACLEAR));
|
|
|
|
/* 2. Mask DMA */
|
|
|
|
outb(1, SLDM_REG(chip, DMAMASK));
|
|
|
|
outb(0x14, SLDM_REG(chip, DMAMODE));
|
|
|
|
outl(chip->dma1_start, SLDM_REG(chip, DMAADDR));
|
2008-01-30 07:25:13 +00:00
|
|
|
chip->last_capture_dmaaddr = chip->dma1_start;
|
2005-04-16 22:20:36 +00:00
|
|
|
outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT));
|
|
|
|
/* 3. Unmask DMA */
|
|
|
|
outb(0, SLDM_REG(chip, DMAMASK));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* *** PCM part ***
|
|
|
|
*/
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_capture_trigger(struct snd_pcm_substream *substream,
|
2005-04-16 22:20:36 +00:00
|
|
|
int cmd)
|
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
int val;
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2005-04-16 22:20:36 +00:00
|
|
|
val = 0x0f;
|
|
|
|
chip->active |= ADC1;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2005-04-16 22:20:36 +00:00
|
|
|
val = 0x00;
|
|
|
|
chip->active &= ~ADC1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback1_trigger(struct snd_pcm_substream *substream,
|
2005-04-16 22:20:36 +00:00
|
|
|
int cmd)
|
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2005-04-16 22:20:36 +00:00
|
|
|
/* According to the documentation this should be:
|
|
|
|
0x13 but that value may randomly swap stereo channels */
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x92);
|
|
|
|
udelay(10);
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0x93);
|
|
|
|
/* This two stage init gives the FIFO -> DAC connection time to
|
|
|
|
* settle before first data from DMA flows in. This should ensure
|
|
|
|
* no swapping of stereo channels. Report a bug if otherwise :-) */
|
|
|
|
outb(0x0a, SLIO_REG(chip, AUDIO2MODE));
|
|
|
|
chip->active |= DAC2;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2005-04-16 22:20:36 +00:00
|
|
|
outb(0, SLIO_REG(chip, AUDIO2MODE));
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0);
|
|
|
|
chip->active &= ~DAC2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback2_trigger(struct snd_pcm_substream *substream,
|
2005-04-16 22:20:36 +00:00
|
|
|
int cmd)
|
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
int val;
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
2005-04-16 22:20:36 +00:00
|
|
|
val = 5;
|
|
|
|
chip->active |= DAC1;
|
|
|
|
break;
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
2005-10-10 11:42:24 +00:00
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
2005-04-16 22:20:36 +00:00
|
|
|
val = 0;
|
|
|
|
chip->active &= ~DAC1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACONTROL, val);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback_trigger(struct snd_pcm_substream *substream,
|
2005-04-16 22:20:36 +00:00
|
|
|
int cmd)
|
|
|
|
{
|
|
|
|
switch (substream->number) {
|
|
|
|
case 0:
|
|
|
|
return snd_es1938_playback1_trigger(substream, cmd);
|
|
|
|
case 1:
|
|
|
|
return snd_es1938_playback2_trigger(substream, cmd);
|
|
|
|
}
|
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
* First channel for Extended Mode Audio 1 ADC Operation
|
|
|
|
* --------------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_capture_prepare(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
int u, is8, mono;
|
|
|
|
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
|
|
|
unsigned int count = snd_pcm_lib_period_bytes(substream);
|
|
|
|
|
|
|
|
chip->dma1_size = size;
|
|
|
|
chip->dma1_start = runtime->dma_addr;
|
|
|
|
|
|
|
|
mono = (runtime->channels > 1) ? 0 : 1;
|
|
|
|
is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
|
|
|
u = snd_pcm_format_unsigned(runtime->format);
|
|
|
|
|
|
|
|
chip->dma1_shift = 2 - mono - is8;
|
|
|
|
|
|
|
|
snd_es1938_reset_fifo(chip);
|
|
|
|
|
|
|
|
/* program type */
|
|
|
|
snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
|
|
|
|
|
|
|
|
/* set clock and counters */
|
|
|
|
snd_es1938_rate_set(chip, substream, ADC1);
|
|
|
|
|
|
|
|
count = 0x10000 - count;
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
|
|
|
|
|
|
|
|
/* initialize and configure ADC */
|
|
|
|
snd_es1938_write(chip, ESS_CMD_SETFORMAT2, u ? 0x51 : 0x71);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_SETFORMAT2, 0x90 |
|
|
|
|
(u ? 0x00 : 0x20) |
|
|
|
|
(is8 ? 0x00 : 0x04) |
|
|
|
|
(mono ? 0x40 : 0x08));
|
|
|
|
|
|
|
|
// snd_es1938_reset_fifo(chip);
|
|
|
|
|
|
|
|
/* 11. configure system interrupt controller and DMA controller */
|
|
|
|
snd_es1938_capture_setdma(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ------------------------------------------------------------------------------
|
|
|
|
* Second Audio channel DAC Operation
|
|
|
|
* ------------------------------------------------------------------------------*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback1_prepare(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
int u, is8, mono;
|
|
|
|
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
|
|
|
unsigned int count = snd_pcm_lib_period_bytes(substream);
|
|
|
|
|
|
|
|
chip->dma2_size = size;
|
|
|
|
chip->dma2_start = runtime->dma_addr;
|
|
|
|
|
|
|
|
mono = (runtime->channels > 1) ? 0 : 1;
|
|
|
|
is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
|
|
|
u = snd_pcm_format_unsigned(runtime->format);
|
|
|
|
|
|
|
|
chip->dma2_shift = 2 - mono - is8;
|
|
|
|
|
|
|
|
snd_es1938_reset_fifo(chip);
|
|
|
|
|
|
|
|
/* set clock and counters */
|
|
|
|
snd_es1938_rate_set(chip, substream, DAC2);
|
|
|
|
|
|
|
|
count >>= 1;
|
|
|
|
count = 0x10000 - count;
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTL, count & 0xff);
|
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTH, count >> 8);
|
|
|
|
|
|
|
|
/* initialize and configure Audio 2 DAC */
|
2005-11-17 14:04:01 +00:00
|
|
|
snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x40 | (u ? 0 : 4) |
|
|
|
|
(mono ? 0 : 2) | (is8 ? 0 : 1));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* program DMA */
|
|
|
|
snd_es1938_playback1_setdma(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback2_prepare(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
int u, is8, mono;
|
|
|
|
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
|
|
|
|
unsigned int count = snd_pcm_lib_period_bytes(substream);
|
|
|
|
|
|
|
|
chip->dma1_size = size;
|
|
|
|
chip->dma1_start = runtime->dma_addr;
|
|
|
|
|
|
|
|
mono = (runtime->channels > 1) ? 0 : 1;
|
|
|
|
is8 = snd_pcm_format_width(runtime->format) == 16 ? 0 : 1;
|
|
|
|
u = snd_pcm_format_unsigned(runtime->format);
|
|
|
|
|
|
|
|
chip->dma1_shift = 2 - mono - is8;
|
|
|
|
|
|
|
|
count = 0x10000 - count;
|
|
|
|
|
|
|
|
/* reset */
|
|
|
|
snd_es1938_reset_fifo(chip);
|
|
|
|
|
|
|
|
snd_es1938_bits(chip, ESS_CMD_ANALOGCONTROL, 0x03, (mono ? 2 : 1));
|
|
|
|
|
|
|
|
/* set clock and counters */
|
|
|
|
snd_es1938_rate_set(chip, substream, DAC1);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACNTRELOADL, count & 0xff);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_DMACNTRELOADH, count >> 8);
|
|
|
|
|
|
|
|
/* initialized and configure DAC */
|
|
|
|
snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x80 : 0x00);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_SETFORMAT, u ? 0x51 : 0x71);
|
|
|
|
snd_es1938_write(chip, ESS_CMD_SETFORMAT2,
|
|
|
|
0x90 | (mono ? 0x40 : 0x08) |
|
|
|
|
(is8 ? 0x00 : 0x04) | (u ? 0x00 : 0x20));
|
|
|
|
|
|
|
|
/* program DMA */
|
|
|
|
snd_es1938_playback2_setdma(chip);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback_prepare(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
switch (substream->number) {
|
|
|
|
case 0:
|
|
|
|
return snd_es1938_playback1_prepare(substream);
|
|
|
|
case 1:
|
|
|
|
return snd_es1938_playback2_prepare(substream);
|
|
|
|
}
|
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2008-01-30 07:25:13 +00:00
|
|
|
/* during the incrementing of dma counters the DMA register reads sometimes
|
|
|
|
returns garbage. To ensure a valid hw pointer, the following checks which
|
|
|
|
should be very unlikely to fail are used:
|
|
|
|
- is the current DMA address in the valid DMA range ?
|
|
|
|
- is the sum of DMA address and DMA counter pointing to the last DMA byte ?
|
|
|
|
One can argue this could differ by one byte depending on which register is
|
|
|
|
updated first, so the implementation below allows for that.
|
|
|
|
*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static snd_pcm_uframes_t snd_es1938_capture_pointer(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t ptr;
|
2008-01-30 07:25:13 +00:00
|
|
|
#if 0
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t old, new;
|
|
|
|
/* This stuff is *needed*, don't ask why - AB */
|
|
|
|
old = inw(SLDM_REG(chip, DMACOUNT));
|
|
|
|
while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
|
|
|
|
old = new;
|
|
|
|
ptr = chip->dma1_size - 1 - new;
|
|
|
|
#else
|
2008-01-30 07:25:13 +00:00
|
|
|
size_t count;
|
|
|
|
unsigned int diff;
|
|
|
|
|
|
|
|
ptr = inl(SLDM_REG(chip, DMAADDR));
|
|
|
|
count = inw(SLDM_REG(chip, DMACOUNT));
|
|
|
|
diff = chip->dma1_start + chip->dma1_size - ptr - count;
|
|
|
|
|
|
|
|
if (diff > 3 || ptr < chip->dma1_start
|
|
|
|
|| ptr >= chip->dma1_start+chip->dma1_size)
|
|
|
|
ptr = chip->last_capture_dmaaddr; /* bad, use last saved */
|
|
|
|
else
|
|
|
|
chip->last_capture_dmaaddr = ptr; /* good, remember it */
|
|
|
|
|
|
|
|
ptr -= chip->dma1_start;
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
return ptr >> chip->dma1_shift;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static snd_pcm_uframes_t snd_es1938_playback1_pointer(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t ptr;
|
|
|
|
#if 1
|
|
|
|
ptr = chip->dma2_size - inw(SLIO_REG(chip, AUDIO2DMACOUNT));
|
|
|
|
#else
|
|
|
|
ptr = inl(SLIO_REG(chip, AUDIO2DMAADDR)) - chip->dma2_start;
|
|
|
|
#endif
|
|
|
|
return ptr >> chip->dma2_shift;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static snd_pcm_uframes_t snd_es1938_playback2_pointer(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
size_t ptr;
|
|
|
|
size_t old, new;
|
|
|
|
#if 1
|
|
|
|
/* This stuff is *needed*, don't ask why - AB */
|
|
|
|
old = inw(SLDM_REG(chip, DMACOUNT));
|
|
|
|
while ((new = inw(SLDM_REG(chip, DMACOUNT))) != old)
|
|
|
|
old = new;
|
|
|
|
ptr = chip->dma1_size - 1 - new;
|
|
|
|
#else
|
|
|
|
ptr = inl(SLDM_REG(chip, DMAADDR)) - chip->dma1_start;
|
|
|
|
#endif
|
|
|
|
return ptr >> chip->dma1_shift;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static snd_pcm_uframes_t snd_es1938_playback_pointer(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
switch (substream->number) {
|
|
|
|
case 0:
|
|
|
|
return snd_es1938_playback1_pointer(substream);
|
|
|
|
case 1:
|
|
|
|
return snd_es1938_playback2_pointer(substream);
|
|
|
|
}
|
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_capture_copy(struct snd_pcm_substream *substream,
|
2017-05-10 18:16:36 +00:00
|
|
|
int channel, unsigned long pos,
|
2023-08-15 19:01:18 +00:00
|
|
|
struct iov_iter *dst, unsigned long count)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2017-05-10 18:16:36 +00:00
|
|
|
|
2008-08-08 15:12:14 +00:00
|
|
|
if (snd_BUG_ON(pos + count > chip->dma1_size))
|
|
|
|
return -EINVAL;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pos + count < chip->dma1_size) {
|
2023-08-15 19:01:18 +00:00
|
|
|
if (copy_to_iter(runtime->dma_area + pos + 1, count, dst) != count)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
} else {
|
2023-08-15 19:01:18 +00:00
|
|
|
if (copy_to_iter(runtime->dma_area + pos + 1, count - 1, dst) != count - 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
2023-08-15 19:01:18 +00:00
|
|
|
if (copy_to_iter(runtime->dma_area, 1, dst) != 1)
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EFAULT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------------------------------------------------------------
|
|
|
|
* Audio1 Capture (ADC)
|
|
|
|
* ----------------------------------------------------------------------*/
|
2017-08-12 15:31:28 +00:00
|
|
|
static const struct snd_pcm_hardware snd_es1938_capture =
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.info = (SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER),
|
2005-11-17 14:04:01 +00:00
|
|
|
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
|
2005-04-16 22:20:36 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
|
|
|
.rate_min = 6000,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */
|
|
|
|
.period_bytes_min = 64,
|
|
|
|
.period_bytes_max = 0x8000,
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = 1024,
|
|
|
|
.fifo_size = 256,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* -----------------------------------------------------------------------
|
|
|
|
* Audio2 Playback (DAC)
|
|
|
|
* -----------------------------------------------------------------------*/
|
2017-08-12 15:31:28 +00:00
|
|
|
static const struct snd_pcm_hardware snd_es1938_playback =
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
.info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID),
|
2005-11-17 14:04:01 +00:00
|
|
|
.formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
|
2005-04-16 22:20:36 +00:00
|
|
|
.rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
|
|
|
|
.rate_min = 6000,
|
|
|
|
.rate_max = 48000,
|
|
|
|
.channels_min = 1,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */
|
|
|
|
.period_bytes_min = 64,
|
|
|
|
.period_bytes_max = 0x8000,
|
|
|
|
.periods_min = 1,
|
|
|
|
.periods_max = 1024,
|
|
|
|
.fifo_size = 256,
|
|
|
|
};
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_capture_open(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (chip->playback2_substream)
|
|
|
|
return -EAGAIN;
|
|
|
|
chip->capture_substream = substream;
|
|
|
|
runtime->hw = snd_es1938_capture;
|
|
|
|
snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
&hw_constraints_clocks);
|
|
|
|
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback_open(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (substream->number) {
|
|
|
|
case 0:
|
|
|
|
chip->playback1_substream = substream;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
if (chip->capture_substream)
|
|
|
|
return -EAGAIN;
|
|
|
|
chip->playback2_substream = substream;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
runtime->hw = snd_es1938_playback;
|
|
|
|
snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
|
|
|
|
&hw_constraints_clocks);
|
|
|
|
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 0, 0xff00);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_capture_close(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
chip->capture_substream = NULL;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_playback_close(struct snd_pcm_substream *substream)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_pcm_substream_chip(substream);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
switch (substream->number) {
|
|
|
|
case 0:
|
|
|
|
chip->playback1_substream = NULL;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
chip->playback2_substream = NULL;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
snd_BUG();
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-09-01 22:13:10 +00:00
|
|
|
static const struct snd_pcm_ops snd_es1938_playback_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = snd_es1938_playback_open,
|
|
|
|
.close = snd_es1938_playback_close,
|
|
|
|
.prepare = snd_es1938_playback_prepare,
|
|
|
|
.trigger = snd_es1938_playback_trigger,
|
|
|
|
.pointer = snd_es1938_playback_pointer,
|
|
|
|
};
|
|
|
|
|
2016-09-01 22:13:10 +00:00
|
|
|
static const struct snd_pcm_ops snd_es1938_capture_ops = {
|
2005-04-16 22:20:36 +00:00
|
|
|
.open = snd_es1938_capture_open,
|
|
|
|
.close = snd_es1938_capture_close,
|
|
|
|
.prepare = snd_es1938_capture_prepare,
|
|
|
|
.trigger = snd_es1938_capture_trigger,
|
|
|
|
.pointer = snd_es1938_capture_pointer,
|
2023-08-15 19:01:18 +00:00
|
|
|
.copy = snd_es1938_capture_copy,
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2012-12-06 17:35:10 +00:00
|
|
|
static int snd_es1938_new_pcm(struct es1938 *chip, int device)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_pcm *pcm;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm);
|
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_es1938_playback_ops);
|
|
|
|
snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1938_capture_ops);
|
|
|
|
|
|
|
|
pcm->private_data = chip;
|
|
|
|
pcm->info_flags = 0;
|
|
|
|
strcpy(pcm->name, "ESS Solo-1");
|
|
|
|
|
2019-12-09 09:49:10 +00:00
|
|
|
snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
|
|
|
|
&chip->pci->dev, 64*1024, 64*1024);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
chip->pcm = pcm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* *** Mixer part ***
|
|
|
|
*/
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_info_mux(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2014-10-20 16:17:08 +00:00
|
|
|
static const char * const texts[8] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
"Mic", "Mic Master", "CD", "AOUT",
|
|
|
|
"Mic1", "Mix", "Line", "Master"
|
|
|
|
};
|
|
|
|
|
2014-10-20 16:17:08 +00:00
|
|
|
return snd_ctl_enum_info(uinfo, 1, 8, texts);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_mux(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
ucontrol->value.enumerated.item[0] = snd_es1938_mixer_read(chip, 0x1c) & 0x07;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_put_mux(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char val = ucontrol->value.enumerated.item[0];
|
|
|
|
|
|
|
|
if (val > 7)
|
|
|
|
return -EINVAL;
|
|
|
|
return snd_es1938_mixer_bits(chip, 0x1c, 0x07, val) != val;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:42:26 +00:00
|
|
|
#define snd_es1938_info_spatializer_enable snd_ctl_boolean_mono_info
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_spatializer_enable(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char val = snd_es1938_mixer_read(chip, 0x50);
|
|
|
|
ucontrol->value.integer.value[0] = !!(val & 8);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_put_spatializer_enable(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char oval, nval;
|
|
|
|
int change;
|
|
|
|
nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
|
|
|
|
oval = snd_es1938_mixer_read(chip, 0x50) & 0x0c;
|
|
|
|
change = nval != oval;
|
|
|
|
if (change) {
|
|
|
|
snd_es1938_mixer_write(chip, 0x50, nval & ~0x04);
|
|
|
|
snd_es1938_mixer_write(chip, 0x50, nval);
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_info_hw_volume(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = 63;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_hw_volume(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
ucontrol->value.integer.value[0] = snd_es1938_mixer_read(chip, 0x61) & 0x3f;
|
|
|
|
ucontrol->value.integer.value[1] = snd_es1938_mixer_read(chip, 0x63) & 0x3f;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-23 13:42:26 +00:00
|
|
|
#define snd_es1938_info_hw_switch snd_ctl_boolean_stereo_info
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_hw_switch(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
ucontrol->value.integer.value[0] = !(snd_es1938_mixer_read(chip, 0x61) & 0x40);
|
|
|
|
ucontrol->value.integer.value[1] = !(snd_es1938_mixer_read(chip, 0x63) & 0x40);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_hwv_free(struct snd_kcontrol *kcontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
chip->master_volume = NULL;
|
|
|
|
chip->master_switch = NULL;
|
|
|
|
chip->hw_volume = NULL;
|
|
|
|
chip->hw_switch = NULL;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_reg_bits(struct es1938 *chip, unsigned char reg,
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned char mask, unsigned char val)
|
|
|
|
{
|
|
|
|
if (reg < 0xa0)
|
|
|
|
return snd_es1938_mixer_bits(chip, reg, mask, val);
|
|
|
|
else
|
|
|
|
return snd_es1938_bits(chip, reg, mask, val);
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_reg_read(struct es1938 *chip, unsigned char reg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (reg < 0xa0)
|
|
|
|
return snd_es1938_mixer_read(chip, reg);
|
|
|
|
else
|
|
|
|
return snd_es1938_read(chip, reg);
|
|
|
|
}
|
|
|
|
|
2006-09-06 11:35:27 +00:00
|
|
|
#define ES1938_SINGLE_TLV(xname, xindex, reg, shift, mask, invert, xtlv) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,\
|
|
|
|
.name = xname, .index = xindex, \
|
|
|
|
.info = snd_es1938_info_single, \
|
|
|
|
.get = snd_es1938_get_single, .put = snd_es1938_put_single, \
|
|
|
|
.private_value = reg | (shift << 8) | (mask << 16) | (invert << 24), \
|
|
|
|
.tlv = { .p = xtlv } }
|
2005-04-16 22:20:36 +00:00
|
|
|
#define ES1938_SINGLE(xname, xindex, reg, shift, mask, invert) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
|
|
|
|
.info = snd_es1938_info_single, \
|
|
|
|
.get = snd_es1938_get_single, .put = snd_es1938_put_single, \
|
|
|
|
.private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_info_single(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
|
|
|
|
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 1;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = mask;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_single(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
int reg = kcontrol->private_value & 0xff;
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
val = snd_es1938_reg_read(chip, reg);
|
|
|
|
ucontrol->value.integer.value[0] = (val >> shift) & mask;
|
|
|
|
if (invert)
|
|
|
|
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_put_single(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
int reg = kcontrol->private_value & 0xff;
|
|
|
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
|
|
|
int mask = (kcontrol->private_value >> 16) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
unsigned char val;
|
|
|
|
|
|
|
|
val = (ucontrol->value.integer.value[0] & mask);
|
|
|
|
if (invert)
|
|
|
|
val = mask - val;
|
|
|
|
mask <<= shift;
|
|
|
|
val <<= shift;
|
|
|
|
return snd_es1938_reg_bits(chip, reg, mask, val) != val;
|
|
|
|
}
|
|
|
|
|
2006-09-06 11:35:27 +00:00
|
|
|
#define ES1938_DOUBLE_TLV(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert, xtlv) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ,\
|
|
|
|
.name = xname, .index = xindex, \
|
|
|
|
.info = snd_es1938_info_double, \
|
|
|
|
.get = snd_es1938_get_double, .put = snd_es1938_put_double, \
|
|
|
|
.private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22), \
|
|
|
|
.tlv = { .p = xtlv } }
|
2005-04-16 22:20:36 +00:00
|
|
|
#define ES1938_DOUBLE(xname, xindex, left_reg, right_reg, shift_left, shift_right, mask, invert) \
|
|
|
|
{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex, \
|
|
|
|
.info = snd_es1938_info_double, \
|
|
|
|
.get = snd_es1938_get_double, .put = snd_es1938_put_double, \
|
|
|
|
.private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_info_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_info *uinfo)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
|
|
|
|
uinfo->type = mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
|
|
|
|
uinfo->count = 2;
|
|
|
|
uinfo->value.integer.min = 0;
|
|
|
|
uinfo->value.integer.max = mask;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_get_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
int left_reg = kcontrol->private_value & 0xff;
|
|
|
|
int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
|
|
|
int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
|
|
|
int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
|
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 22) & 1;
|
|
|
|
unsigned char left, right;
|
|
|
|
|
|
|
|
left = snd_es1938_reg_read(chip, left_reg);
|
|
|
|
if (left_reg != right_reg)
|
|
|
|
right = snd_es1938_reg_read(chip, right_reg);
|
|
|
|
else
|
|
|
|
right = left;
|
|
|
|
ucontrol->value.integer.value[0] = (left >> shift_left) & mask;
|
|
|
|
ucontrol->value.integer.value[1] = (right >> shift_right) & mask;
|
|
|
|
if (invert) {
|
|
|
|
ucontrol->value.integer.value[0] = mask - ucontrol->value.integer.value[0];
|
|
|
|
ucontrol->value.integer.value[1] = mask - ucontrol->value.integer.value[1];
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static int snd_es1938_put_double(struct snd_kcontrol *kcontrol,
|
|
|
|
struct snd_ctl_elem_value *ucontrol)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = snd_kcontrol_chip(kcontrol);
|
2005-04-16 22:20:36 +00:00
|
|
|
int left_reg = kcontrol->private_value & 0xff;
|
|
|
|
int right_reg = (kcontrol->private_value >> 8) & 0xff;
|
|
|
|
int shift_left = (kcontrol->private_value >> 16) & 0x07;
|
|
|
|
int shift_right = (kcontrol->private_value >> 19) & 0x07;
|
|
|
|
int mask = (kcontrol->private_value >> 24) & 0xff;
|
|
|
|
int invert = (kcontrol->private_value >> 22) & 1;
|
|
|
|
int change;
|
|
|
|
unsigned char val1, val2, mask1, mask2;
|
|
|
|
|
|
|
|
val1 = ucontrol->value.integer.value[0] & mask;
|
|
|
|
val2 = ucontrol->value.integer.value[1] & mask;
|
|
|
|
if (invert) {
|
|
|
|
val1 = mask - val1;
|
|
|
|
val2 = mask - val2;
|
|
|
|
}
|
|
|
|
val1 <<= shift_left;
|
|
|
|
val2 <<= shift_right;
|
|
|
|
mask1 = mask << shift_left;
|
|
|
|
mask2 = mask << shift_right;
|
|
|
|
if (left_reg != right_reg) {
|
|
|
|
change = 0;
|
|
|
|
if (snd_es1938_reg_bits(chip, left_reg, mask1, val1) != val1)
|
|
|
|
change = 1;
|
|
|
|
if (snd_es1938_reg_bits(chip, right_reg, mask2, val2) != val2)
|
|
|
|
change = 1;
|
|
|
|
} else {
|
|
|
|
change = (snd_es1938_reg_bits(chip, left_reg, mask1 | mask2,
|
|
|
|
val1 | val2) != (val1 | val2));
|
|
|
|
}
|
|
|
|
return change;
|
|
|
|
}
|
|
|
|
|
2011-11-20 16:21:34 +00:00
|
|
|
static const DECLARE_TLV_DB_RANGE(db_scale_master,
|
2006-09-06 11:35:27 +00:00
|
|
|
0, 54, TLV_DB_SCALE_ITEM(-3600, 50, 1),
|
|
|
|
54, 63, TLV_DB_SCALE_ITEM(-900, 100, 0),
|
2011-11-20 16:21:34 +00:00
|
|
|
);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2011-11-20 16:21:34 +00:00
|
|
|
static const DECLARE_TLV_DB_RANGE(db_scale_audio1,
|
2006-09-06 11:35:27 +00:00
|
|
|
0, 8, TLV_DB_SCALE_ITEM(-3300, 300, 1),
|
|
|
|
8, 15, TLV_DB_SCALE_ITEM(-900, 150, 0),
|
2011-11-20 16:21:34 +00:00
|
|
|
);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2011-11-20 16:21:34 +00:00
|
|
|
static const DECLARE_TLV_DB_RANGE(db_scale_audio2,
|
2006-09-06 11:35:27 +00:00
|
|
|
0, 8, TLV_DB_SCALE_ITEM(-3450, 300, 1),
|
|
|
|
8, 15, TLV_DB_SCALE_ITEM(-1050, 150, 0),
|
2011-11-20 16:21:34 +00:00
|
|
|
);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2011-11-20 16:21:34 +00:00
|
|
|
static const DECLARE_TLV_DB_RANGE(db_scale_mic,
|
2006-09-06 11:35:27 +00:00
|
|
|
0, 8, TLV_DB_SCALE_ITEM(-2400, 300, 1),
|
|
|
|
8, 15, TLV_DB_SCALE_ITEM(0, 150, 0),
|
2011-11-20 16:21:34 +00:00
|
|
|
);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2011-11-20 16:21:34 +00:00
|
|
|
static const DECLARE_TLV_DB_RANGE(db_scale_line,
|
2006-09-06 11:35:27 +00:00
|
|
|
0, 8, TLV_DB_SCALE_ITEM(-3150, 300, 1),
|
|
|
|
8, 15, TLV_DB_SCALE_ITEM(-750, 150, 0),
|
2011-11-20 16:21:34 +00:00
|
|
|
);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2007-01-29 14:33:49 +00:00
|
|
|
static const DECLARE_TLV_DB_SCALE(db_scale_capture, 0, 150, 0);
|
2006-09-06 11:35:27 +00:00
|
|
|
|
2020-01-03 08:16:53 +00:00
|
|
|
static const struct snd_kcontrol_new snd_es1938_controls[] = {
|
2006-09-06 11:35:27 +00:00
|
|
|
ES1938_DOUBLE_TLV("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0,
|
|
|
|
db_scale_master),
|
2005-04-16 22:20:36 +00:00
|
|
|
ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Hardware Master Playback Volume",
|
|
|
|
.access = SNDRV_CTL_ELEM_ACCESS_READ,
|
|
|
|
.info = snd_es1938_info_hw_volume,
|
|
|
|
.get = snd_es1938_get_hw_volume,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
2006-09-22 08:58:40 +00:00
|
|
|
.access = (SNDRV_CTL_ELEM_ACCESS_READ |
|
2006-09-06 11:35:27 +00:00
|
|
|
SNDRV_CTL_ELEM_ACCESS_TLV_READ),
|
2005-04-16 22:20:36 +00:00
|
|
|
.name = "Hardware Master Playback Switch",
|
|
|
|
.info = snd_es1938_info_hw_switch,
|
|
|
|
.get = snd_es1938_get_hw_switch,
|
2006-09-06 11:35:27 +00:00
|
|
|
.tlv = { .p = db_scale_master },
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
ES1938_SINGLE("Hardware Volume Split", 0, 0x64, 7, 1, 0),
|
2006-09-06 11:35:27 +00:00
|
|
|
ES1938_DOUBLE_TLV("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
2005-04-16 22:20:36 +00:00
|
|
|
ES1938_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
|
2006-09-06 11:35:27 +00:00
|
|
|
ES1938_DOUBLE_TLV("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0,
|
|
|
|
db_scale_mic),
|
|
|
|
ES1938_DOUBLE_TLV("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0,
|
|
|
|
db_scale_mic),
|
|
|
|
ES1938_DOUBLE_TLV("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0,
|
|
|
|
db_scale_capture),
|
2009-11-03 14:47:25 +00:00
|
|
|
ES1938_SINGLE("Beep Volume", 0, 0x3c, 0, 7, 0),
|
2005-04-16 22:20:36 +00:00
|
|
|
ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
|
|
|
|
ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "Capture Source",
|
|
|
|
.info = snd_es1938_info_mux,
|
|
|
|
.get = snd_es1938_get_mux,
|
|
|
|
.put = snd_es1938_put_mux,
|
|
|
|
},
|
2006-09-06 11:35:27 +00:00
|
|
|
ES1938_DOUBLE_TLV("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0,
|
|
|
|
db_scale_audio2),
|
|
|
|
ES1938_DOUBLE_TLV("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0,
|
|
|
|
db_scale_mic),
|
|
|
|
ES1938_DOUBLE_TLV("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0,
|
|
|
|
db_scale_mic),
|
|
|
|
ES1938_DOUBLE_TLV("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0,
|
|
|
|
db_scale_line),
|
|
|
|
ES1938_DOUBLE_TLV("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0,
|
|
|
|
db_scale_audio2),
|
|
|
|
ES1938_DOUBLE_TLV("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0,
|
|
|
|
db_scale_audio1),
|
2005-04-16 22:20:36 +00:00
|
|
|
ES1938_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
|
|
|
|
{
|
|
|
|
.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
|
|
|
|
.name = "3D Control - Switch",
|
|
|
|
.info = snd_es1938_info_spatializer_enable,
|
|
|
|
.get = snd_es1938_get_spatializer_enable,
|
|
|
|
.put = snd_es1938_put_spatializer_enable,
|
|
|
|
},
|
|
|
|
ES1938_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0)
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/* ---------------------------------------------------------------------------- */
|
|
|
|
/* ---------------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
/*
|
|
|
|
* initialize the chip - used by resume callback, too
|
|
|
|
*/
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_chip_init(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
/* reset chip */
|
|
|
|
snd_es1938_reset(chip);
|
|
|
|
|
|
|
|
/* configure native mode */
|
|
|
|
|
|
|
|
/* enable bus master */
|
|
|
|
pci_set_master(chip->pci);
|
|
|
|
|
|
|
|
/* disable legacy audio */
|
|
|
|
pci_write_config_word(chip->pci, SL_PCI_LEGACYCONTROL, 0x805f);
|
|
|
|
|
|
|
|
/* set DDMA base */
|
|
|
|
pci_write_config_word(chip->pci, SL_PCI_DDMACONTROL, chip->ddma_port | 1);
|
|
|
|
|
|
|
|
/* set DMA/IRQ policy */
|
|
|
|
pci_write_config_dword(chip->pci, SL_PCI_CONFIG, 0);
|
|
|
|
|
|
|
|
/* enable Audio 1, Audio 2, MPU401 IRQ and HW volume IRQ*/
|
|
|
|
outb(0xf0, SLIO_REG(chip, IRQCONTROL));
|
|
|
|
|
|
|
|
/* reset DMA */
|
|
|
|
outb(0, SLDM_REG(chip, DMACLEAR));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* PM support
|
|
|
|
*/
|
|
|
|
|
2020-01-05 14:47:49 +00:00
|
|
|
static const unsigned char saved_regs[SAVED_REG_SIZE+1] = {
|
2005-04-16 22:20:36 +00:00
|
|
|
0x14, 0x1a, 0x1c, 0x3a, 0x3c, 0x3e, 0x36, 0x38,
|
|
|
|
0x50, 0x52, 0x60, 0x61, 0x62, 0x63, 0x64, 0x68,
|
|
|
|
0x69, 0x6a, 0x6b, 0x6d, 0x6e, 0x6f, 0x7c, 0x7d,
|
|
|
|
0xa8, 0xb4,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-07-02 13:20:37 +00:00
|
|
|
static int es1938_suspend(struct device *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-07-02 13:20:37 +00:00
|
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
2005-11-17 15:08:27 +00:00
|
|
|
struct es1938 *chip = card->private_data;
|
2020-01-05 14:47:49 +00:00
|
|
|
const unsigned char *s;
|
|
|
|
unsigned char *d;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-11-17 15:08:27 +00:00
|
|
|
snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
/* save mixer-related registers */
|
|
|
|
for (s = saved_regs, d = chip->saved_regs; *s; s++, d++)
|
|
|
|
*d = snd_es1938_reg_read(chip, *s);
|
|
|
|
|
|
|
|
outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
|
2006-10-11 16:52:53 +00:00
|
|
|
if (chip->irq >= 0) {
|
2005-11-17 15:08:27 +00:00
|
|
|
free_irq(chip->irq, chip);
|
2006-10-11 16:52:53 +00:00
|
|
|
chip->irq = -1;
|
2019-12-10 06:34:17 +00:00
|
|
|
card->sync_irq = -1;
|
2006-10-11 16:52:53 +00:00
|
|
|
}
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-07-02 13:20:37 +00:00
|
|
|
static int es1938_resume(struct device *dev)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2012-07-02 13:20:37 +00:00
|
|
|
struct pci_dev *pci = to_pci_dev(dev);
|
|
|
|
struct snd_card *card = dev_get_drvdata(dev);
|
2005-11-17 15:08:27 +00:00
|
|
|
struct es1938 *chip = card->private_data;
|
2020-01-05 14:47:49 +00:00
|
|
|
const unsigned char *s;
|
|
|
|
unsigned char *d;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-10-11 16:52:53 +00:00
|
|
|
if (request_irq(pci->irq, snd_es1938_interrupt,
|
2011-06-10 14:36:37 +00:00
|
|
|
IRQF_SHARED, KBUILD_MODNAME, chip)) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(dev, "unable to grab IRQ %d, disabling device\n",
|
|
|
|
pci->irq);
|
2006-10-11 16:52:53 +00:00
|
|
|
snd_card_disconnect(card);
|
|
|
|
return -EIO;
|
|
|
|
}
|
2005-11-17 15:08:27 +00:00
|
|
|
chip->irq = pci->irq;
|
2019-12-10 06:34:17 +00:00
|
|
|
card->sync_irq = chip->irq;
|
2005-04-16 22:20:36 +00:00
|
|
|
snd_es1938_chip_init(chip);
|
|
|
|
|
|
|
|
/* restore mixer-related registers */
|
|
|
|
for (s = saved_regs, d = chip->saved_regs; *s; s++, d++) {
|
|
|
|
if (*s < 0xa0)
|
|
|
|
snd_es1938_mixer_write(chip, *s, *d);
|
|
|
|
else
|
|
|
|
snd_es1938_write(chip, *s, *d);
|
|
|
|
}
|
|
|
|
|
2005-11-17 15:08:27 +00:00
|
|
|
snd_power_change_state(card, SNDRV_CTL_POWER_D0);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2012-07-02 13:20:37 +00:00
|
|
|
|
2024-02-07 15:51:32 +00:00
|
|
|
static DEFINE_SIMPLE_DEV_PM_OPS(es1938_pm, es1938_suspend, es1938_resume);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#ifdef SUPPORT_JOYSTICK
|
2012-12-06 17:35:10 +00:00
|
|
|
static int snd_es1938_create_gameport(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct gameport *gp;
|
|
|
|
|
|
|
|
chip->gameport = gp = gameport_allocate_port();
|
|
|
|
if (!gp) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(chip->card->dev,
|
|
|
|
"cannot allocate memory for gameport\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
|
|
|
|
gameport_set_name(gp, "ES1938");
|
|
|
|
gameport_set_phys(gp, "pci%s/gameport0", pci_name(chip->pci));
|
|
|
|
gameport_set_dev_parent(gp, &chip->pci->dev);
|
|
|
|
gp->io = chip->game_port;
|
|
|
|
|
|
|
|
gameport_register_port(gp);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2005-11-17 14:04:01 +00:00
|
|
|
static void snd_es1938_free_gameport(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (chip->gameport) {
|
|
|
|
gameport_unregister_port(chip->gameport);
|
|
|
|
chip->gameport = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
2005-11-17 14:04:01 +00:00
|
|
|
static inline int snd_es1938_create_gameport(struct es1938 *chip) { return -ENOSYS; }
|
|
|
|
static inline void snd_es1938_free_gameport(struct es1938 *chip) { }
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* SUPPORT_JOYSTICK */
|
|
|
|
|
2021-07-15 07:58:39 +00:00
|
|
|
static void snd_es1938_free(struct snd_card *card)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-07-15 07:58:39 +00:00
|
|
|
struct es1938 *chip = card->private_data;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/* disable irqs */
|
|
|
|
outb(0x00, SLIO_REG(chip, IRQCONTROL));
|
|
|
|
if (chip->rmidi)
|
|
|
|
snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0);
|
|
|
|
|
|
|
|
snd_es1938_free_gameport(chip);
|
|
|
|
|
2008-04-22 11:50:34 +00:00
|
|
|
if (chip->irq >= 0)
|
2005-11-17 14:04:01 +00:00
|
|
|
free_irq(chip->irq, chip);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2012-12-06 17:35:10 +00:00
|
|
|
static int snd_es1938_create(struct snd_card *card,
|
2021-07-15 07:58:39 +00:00
|
|
|
struct pci_dev *pci)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2021-07-15 07:58:39 +00:00
|
|
|
struct es1938 *chip = card->private_data;
|
2005-04-16 22:20:36 +00:00
|
|
|
int err;
|
|
|
|
|
|
|
|
/* enable PCI device */
|
2021-07-15 07:58:39 +00:00
|
|
|
err = pcim_enable_device(pci);
|
2021-06-08 14:04:59 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
/* check, if we can restrict PCI DMA transfers to 24 bits */
|
2021-01-14 12:54:11 +00:00
|
|
|
if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(24))) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(card->dev,
|
|
|
|
"architecture does not support 24bit PCI busmaster DMA\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
spin_lock_init(&chip->reg_lock);
|
|
|
|
spin_lock_init(&chip->mixer_lock);
|
|
|
|
chip->card = card;
|
|
|
|
chip->pci = pci;
|
2006-10-11 16:52:53 +00:00
|
|
|
chip->irq = -1;
|
2021-06-08 14:04:59 +00:00
|
|
|
err = pci_request_regions(pci, "ESS Solo-1");
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
chip->io_port = pci_resource_start(pci, 0);
|
|
|
|
chip->sb_port = pci_resource_start(pci, 1);
|
|
|
|
chip->vc_port = pci_resource_start(pci, 2);
|
|
|
|
chip->mpu_port = pci_resource_start(pci, 3);
|
|
|
|
chip->game_port = pci_resource_start(pci, 4);
|
2021-07-15 07:58:39 +00:00
|
|
|
/* still use non-managed irq handler as it's re-acquired at PM resume */
|
2006-11-21 11:14:23 +00:00
|
|
|
if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED,
|
2011-06-10 14:36:37 +00:00
|
|
|
KBUILD_MODNAME, chip)) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(card->dev, "unable to grab IRQ %d\n", pci->irq);
|
2005-04-16 22:20:36 +00:00
|
|
|
return -EBUSY;
|
|
|
|
}
|
|
|
|
chip->irq = pci->irq;
|
2019-12-10 06:34:17 +00:00
|
|
|
card->sync_irq = chip->irq;
|
2021-07-15 07:58:39 +00:00
|
|
|
card->private_free = snd_es1938_free;
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(card->dev,
|
|
|
|
"create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port);
|
|
|
|
|
|
|
|
chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */
|
|
|
|
|
|
|
|
snd_es1938_chip_init(chip);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------
|
|
|
|
* Interrupt handler
|
|
|
|
* -------------------------------------------------------------------- */
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct es1938 *chip = dev_id;
|
2020-07-02 19:35:59 +00:00
|
|
|
unsigned char status;
|
|
|
|
__always_unused unsigned char audiostatus;
|
2005-04-16 22:20:36 +00:00
|
|
|
int handled = 0;
|
|
|
|
|
|
|
|
status = inb(SLIO_REG(chip, IRQCONTROL));
|
|
|
|
#if 0
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
|
|
|
"Es1938debug - interrupt status: =0x%x\n", status);
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* AUDIO 1 */
|
|
|
|
if (status & 0x10) {
|
|
|
|
#if 0
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 1 interrupt\n");
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n",
|
2005-11-17 14:04:01 +00:00
|
|
|
inw(SLDM_REG(chip, DMACOUNT)));
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n",
|
2005-11-17 14:04:01 +00:00
|
|
|
inl(SLDM_REG(chip, DMAADDR)));
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n",
|
2005-11-17 14:04:01 +00:00
|
|
|
inl(SLDM_REG(chip, DMASTATUS)));
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
|
|
|
/* clear irq */
|
|
|
|
handled = 1;
|
|
|
|
audiostatus = inb(SLSB_REG(chip, STATUS));
|
|
|
|
if (chip->active & ADC1)
|
|
|
|
snd_pcm_period_elapsed(chip->capture_substream);
|
|
|
|
else if (chip->active & DAC1)
|
|
|
|
snd_pcm_period_elapsed(chip->playback2_substream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* AUDIO 2 */
|
|
|
|
if (status & 0x20) {
|
|
|
|
#if 0
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 2 interrupt\n");
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n",
|
2005-11-17 14:04:01 +00:00
|
|
|
inw(SLIO_REG(chip, AUDIO2DMACOUNT)));
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_dbg(chip->card->dev,
|
2009-02-05 15:11:31 +00:00
|
|
|
"Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n",
|
2005-11-17 14:04:01 +00:00
|
|
|
inl(SLIO_REG(chip, AUDIO2DMAADDR)));
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
/* clear irq */
|
|
|
|
handled = 1;
|
|
|
|
snd_es1938_mixer_bits(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x80, 0);
|
|
|
|
if (chip->active & DAC2)
|
|
|
|
snd_pcm_period_elapsed(chip->playback1_substream);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Hardware volume */
|
|
|
|
if (status & 0x40) {
|
|
|
|
int split = snd_es1938_mixer_read(chip, 0x64) & 0x80;
|
|
|
|
handled = 1;
|
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_switch->id);
|
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, &chip->hw_volume->id);
|
|
|
|
if (!split) {
|
2005-11-17 14:04:01 +00:00
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
|
|
|
|
&chip->master_switch->id);
|
|
|
|
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
|
|
|
|
&chip->master_volume->id);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
/* ack interrupt */
|
|
|
|
snd_es1938_mixer_write(chip, 0x66, 0x00);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* MPU401 */
|
|
|
|
if (status & 0x80) {
|
|
|
|
// the following line is evil! It switches off MIDI interrupt handling after the first interrupt received.
|
|
|
|
// replacing the last 0 by 0x40 works for ESS-Solo1, but just doing nothing works as well!
|
|
|
|
// andreas@flying-snail.de
|
|
|
|
// snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0); /* ack? */
|
|
|
|
if (chip->rmidi) {
|
|
|
|
handled = 1;
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 13:55:46 +00:00
|
|
|
snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return IRQ_RETVAL(handled);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ES1938_DMA_SIZE 64
|
|
|
|
|
2012-12-06 17:35:10 +00:00
|
|
|
static int snd_es1938_mixer(struct es1938 *chip)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_card *card;
|
2005-04-16 22:20:36 +00:00
|
|
|
unsigned int idx;
|
|
|
|
int err;
|
|
|
|
|
|
|
|
card = chip->card;
|
|
|
|
|
|
|
|
strcpy(card->mixername, "ESS Solo-1");
|
|
|
|
|
|
|
|
for (idx = 0; idx < ARRAY_SIZE(snd_es1938_controls); idx++) {
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_kcontrol *kctl;
|
2005-04-16 22:20:36 +00:00
|
|
|
kctl = snd_ctl_new1(&snd_es1938_controls[idx], chip);
|
|
|
|
switch (idx) {
|
|
|
|
case 0:
|
|
|
|
chip->master_volume = kctl;
|
|
|
|
kctl->private_free = snd_es1938_hwv_free;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
chip->master_switch = kctl;
|
|
|
|
kctl->private_free = snd_es1938_hwv_free;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
chip->hw_volume = kctl;
|
|
|
|
kctl->private_free = snd_es1938_hwv_free;
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
chip->hw_switch = kctl;
|
|
|
|
kctl->private_free = snd_es1938_hwv_free;
|
|
|
|
break;
|
|
|
|
}
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_ctl_add(card, kctl);
|
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-04-12 10:26:11 +00:00
|
|
|
static int __snd_es1938_probe(struct pci_dev *pci,
|
|
|
|
const struct pci_device_id *pci_id)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
static int dev;
|
2005-11-17 14:04:01 +00:00
|
|
|
struct snd_card *card;
|
|
|
|
struct es1938 *chip;
|
|
|
|
struct snd_opl3 *opl3;
|
2005-04-16 22:20:36 +00:00
|
|
|
int idx, err;
|
|
|
|
|
|
|
|
if (dev >= SNDRV_CARDS)
|
|
|
|
return -ENODEV;
|
|
|
|
if (!enable[dev]) {
|
|
|
|
dev++;
|
|
|
|
return -ENOENT;
|
|
|
|
}
|
|
|
|
|
2021-07-15 07:58:39 +00:00
|
|
|
err = snd_devm_card_new(&pci->dev, index[dev], id[dev], THIS_MODULE,
|
|
|
|
sizeof(*chip), &card);
|
2008-12-28 15:44:30 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
2021-07-15 07:58:39 +00:00
|
|
|
chip = card->private_data;
|
|
|
|
|
|
|
|
for (idx = 0; idx < 5; idx++)
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pci_resource_start(pci, idx) == 0 ||
|
2021-07-15 07:58:39 +00:00
|
|
|
!(pci_resource_flags(pci, idx) & IORESOURCE_IO))
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
err = snd_es1938_create(card, pci);
|
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
strcpy(card->driver, "ES1938");
|
|
|
|
strcpy(card->shortname, "ESS ES1938 (Solo-1)");
|
|
|
|
sprintf(card->longname, "%s rev %i, irq %i",
|
|
|
|
card->shortname,
|
|
|
|
chip->revision,
|
|
|
|
chip->irq);
|
|
|
|
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_es1938_new_pcm(chip, 0);
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_es1938_mixer(chip);
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
if (snd_opl3_create(card,
|
|
|
|
SLSB_REG(chip, FMLOWADDR),
|
|
|
|
SLSB_REG(chip, FMHIGHADDR),
|
|
|
|
OPL3_HW_OPL3, 1, &opl3) < 0) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(card->dev, "OPL3 not detected at 0x%lx\n",
|
2005-04-16 22:20:36 +00:00
|
|
|
SLSB_REG(chip, FMLOWADDR));
|
|
|
|
} else {
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_opl3_timer_new(opl3, 0, 1);
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_opl3_hwdep_new(opl3, 0, 1, NULL);
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
|
ALSA: mpu401: clean up interrupt specification
The semantics of snd_mpu401_uart_new()'s interrupt parameters are
somewhat counterintuitive: To prevent the function from allocating its
own interrupt, either the irq number must be invalid, or the irq_flags
parameter must be zero. At the same time, the irq parameter being
invalid specifies that the mpu401 code has to work without an interrupt
allocated by the caller. This implies that, if there is an interrupt
and it is allocated by the caller, the irq parameter must be set to
a valid-looking number which then isn't actually used.
With the removal of IRQF_DISABLED, zero becomes a valid irq_flags value,
which forces us to handle the parameters differently.
This patch introduces a new flag MPU401_INFO_IRQ_HOOK for when the
device interrupt is handled by the caller, and makes the allocation of
the interrupt to depend only on the irq parameter. As suggested by
Takashi, the irq_flags parameter was dropped because, when used, it had
the constant value IRQF_DISABLED.
Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
2011-09-13 09:24:41 +00:00
|
|
|
chip->mpu_port,
|
|
|
|
MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
|
|
|
|
-1, &chip->rmidi) < 0) {
|
2014-02-25 13:21:18 +00:00
|
|
|
dev_err(card->dev, "unable to initialize MPU-401\n");
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
// this line is vital for MIDI interrupt handling on ess-solo1
|
|
|
|
// andreas@flying-snail.de
|
|
|
|
snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0x40);
|
|
|
|
}
|
|
|
|
|
|
|
|
snd_es1938_create_gameport(chip);
|
|
|
|
|
2021-06-08 14:04:59 +00:00
|
|
|
err = snd_card_register(card);
|
2021-07-15 07:58:39 +00:00
|
|
|
if (err < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
return err;
|
|
|
|
|
|
|
|
pci_set_drvdata(pci, card);
|
|
|
|
dev++;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-04-12 10:26:11 +00:00
|
|
|
static int snd_es1938_probe(struct pci_dev *pci,
|
|
|
|
const struct pci_device_id *pci_id)
|
|
|
|
{
|
|
|
|
return snd_card_free_on_error(&pci->dev, __snd_es1938_probe(pci, pci_id));
|
|
|
|
}
|
|
|
|
|
2012-04-24 10:25:00 +00:00
|
|
|
static struct pci_driver es1938_driver = {
|
2011-06-10 14:20:20 +00:00
|
|
|
.name = KBUILD_MODNAME,
|
2005-04-16 22:20:36 +00:00
|
|
|
.id_table = snd_es1938_ids,
|
|
|
|
.probe = snd_es1938_probe,
|
2012-07-02 13:20:37 +00:00
|
|
|
.driver = {
|
2024-02-07 15:51:32 +00:00
|
|
|
.pm = &es1938_pm,
|
2012-07-02 13:20:37 +00:00
|
|
|
},
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
2012-04-24 10:25:00 +00:00
|
|
|
module_pci_driver(es1938_driver);
|