X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=sound%2Fpci%2Fes1938.c;h=fb83e1ffa5cb5e99ed3b697bedaf5fe66ff78e91;hb=2c7a3fb3f81df7318c70d2b8ecbd87f008e28d52;hp=7bfbdfc2f8bcdca20fc2ec3d2ffc40bc02798d7a;hpb=93b9f426374a07d46f582fdf284e4e26d8fe9756;p=safe%2Fjmp%2Flinux-2.6 diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index 7bfbdfc..fb83e1f 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c @@ -1,7 +1,7 @@ /* * Driver for ESS Solo-1 (ES1938, ES1946, ES1969) soundcard * Copyright (c) by Jaromir Koutek , - * Jaroslav Kysela , + * Jaroslav Kysela , * Thomas Sailer , * Abramo Bagnara , * Markus Gruber @@ -47,7 +47,6 @@ */ -#include #include #include #include @@ -55,12 +54,14 @@ #include #include #include +#include #include #include #include #include #include #include +#include #include @@ -191,11 +192,9 @@ MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard."); */ -typedef struct _snd_es1938 es1938_t; - #define SAVED_REG_SIZE 32 /* max. number of registers to save */ -struct _snd_es1938 { +struct es1938 { int irq; unsigned long io_port; @@ -208,19 +207,18 @@ struct _snd_es1938 { unsigned char irqmask; unsigned char revision; - snd_kcontrol_t *hw_volume; - snd_kcontrol_t *hw_switch; - snd_kcontrol_t *master_volume; - snd_kcontrol_t *master_switch; + struct snd_kcontrol *hw_volume; + struct snd_kcontrol *hw_switch; + struct snd_kcontrol *master_volume; + struct snd_kcontrol *master_switch; struct pci_dev *pci; - snd_card_t *card; - snd_pcm_t *pcm; - snd_pcm_substream_t *capture_substream; - snd_pcm_substream_t *playback1_substream; - snd_pcm_substream_t *playback2_substream; - snd_kmixer_t *mixer; - snd_rawmidi_t *rmidi; + 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; unsigned int dma1_size; unsigned int dma2_size; @@ -228,11 +226,12 @@ struct _snd_es1938 { unsigned int dma2_start; unsigned int dma1_shift; unsigned int dma2_shift; + unsigned int last_capture_dmaaddr; unsigned int active; spinlock_t reg_lock; spinlock_t mixer_lock; - snd_info_entry_t *proc_entry; + struct snd_info_entry *proc_entry; #ifdef SUPPORT_JOYSTICK struct gameport *gameport; @@ -242,10 +241,10 @@ struct _snd_es1938 { #endif }; -static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs); +static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id); static struct pci_device_id snd_es1938_ids[] = { - { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */ + { PCI_VDEVICE(ESS, 0x1969), 0, }, /* Solo-1 */ { 0, } }; @@ -259,7 +258,7 @@ MODULE_DEVICE_TABLE(pci, snd_es1938_ids); /* ----------------------------------------------------------------- * Write to a mixer register * -----------------------------------------------------------------*/ -static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned char val) +static void snd_es1938_mixer_write(struct es1938 *chip, unsigned char reg, unsigned char val) { unsigned long flags; spin_lock_irqsave(&chip->mixer_lock, flags); @@ -267,14 +266,14 @@ static void snd_es1938_mixer_write(es1938_t *chip, unsigned char reg, unsigned c outb(val, SLSB_REG(chip, MIXERDATA)); spin_unlock_irqrestore(&chip->mixer_lock, flags); #ifdef REG_DEBUG - snd_printk("Mixer reg %02x set to %02x\n", reg, val); + snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, val); #endif } /* ----------------------------------------------------------------- * Read from a mixer register * -----------------------------------------------------------------*/ -static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg) +static int snd_es1938_mixer_read(struct es1938 *chip, unsigned char reg) { int data; unsigned long flags; @@ -283,7 +282,7 @@ static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg) data = inb(SLSB_REG(chip, MIXERDATA)); spin_unlock_irqrestore(&chip->mixer_lock, flags); #ifdef REG_DEBUG - snd_printk("Mixer reg %02x now is %02x\n", reg, data); + snd_printk(KERN_DEBUG "Mixer reg %02x now is %02x\n", reg, data); #endif return data; } @@ -291,7 +290,8 @@ static int snd_es1938_mixer_read(es1938_t *chip, unsigned char reg) /* ----------------------------------------------------------------- * Write to some bits of a mixer register (return old value) * -----------------------------------------------------------------*/ -static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val) +static int snd_es1938_mixer_bits(struct es1938 *chip, unsigned char reg, + unsigned char mask, unsigned char val) { unsigned long flags; unsigned char old, new, oval; @@ -303,7 +303,8 @@ static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned cha new = (old & ~mask) | (val & mask); outb(new, SLSB_REG(chip, MIXERDATA)); #ifdef REG_DEBUG - snd_printk("Mixer reg %02x was %02x, set to %02x\n", reg, old, new); + snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x\n", + reg, old, new); #endif } spin_unlock_irqrestore(&chip->mixer_lock, flags); @@ -313,7 +314,7 @@ static int snd_es1938_mixer_bits(es1938_t *chip, unsigned char reg, unsigned cha /* ----------------------------------------------------------------- * Write command to Controller Registers * -----------------------------------------------------------------*/ -static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd) +static void snd_es1938_write_cmd(struct es1938 *chip, unsigned char cmd) { int i; unsigned char v; @@ -323,27 +324,27 @@ static void snd_es1938_write_cmd(es1938_t *chip, unsigned char cmd) return; } } - printk("snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v); + printk(KERN_ERR "snd_es1938_write_cmd timeout (0x02%x/0x02%x)\n", cmd, v); } /* ----------------------------------------------------------------- * Read the Read Data Buffer * -----------------------------------------------------------------*/ -static int snd_es1938_get_byte(es1938_t *chip) +static int snd_es1938_get_byte(struct es1938 *chip) { int i; unsigned char v; for (i = GET_LOOP_TIMEOUT; i; i--) if ((v = inb(SLSB_REG(chip, STATUS))) & 0x80) return inb(SLSB_REG(chip, READDATA)); - snd_printk("get_byte timeout: status 0x02%x\n", v); + snd_printk(KERN_ERR "get_byte timeout: status 0x02%x\n", v); return -ENODEV; } /* ----------------------------------------------------------------- * Write value cmd register * -----------------------------------------------------------------*/ -static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char val) +static void snd_es1938_write(struct es1938 *chip, unsigned char reg, unsigned char val) { unsigned long flags; spin_lock_irqsave(&chip->reg_lock, flags); @@ -351,14 +352,14 @@ static void snd_es1938_write(es1938_t *chip, unsigned char reg, unsigned char va snd_es1938_write_cmd(chip, val); spin_unlock_irqrestore(&chip->reg_lock, flags); #ifdef REG_DEBUG - snd_printk("Reg %02x set to %02x\n", reg, val); + snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, val); #endif } /* ----------------------------------------------------------------- * Read data from cmd register and return it * -----------------------------------------------------------------*/ -static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg) +static unsigned char snd_es1938_read(struct es1938 *chip, unsigned char reg) { unsigned char val; unsigned long flags; @@ -368,7 +369,7 @@ static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg) val = snd_es1938_get_byte(chip); spin_unlock_irqrestore(&chip->reg_lock, flags); #ifdef REG_DEBUG - snd_printk("Reg %02x now is %02x\n", reg, val); + snd_printk(KERN_DEBUG "Reg %02x now is %02x\n", reg, val); #endif return val; } @@ -376,7 +377,8 @@ static unsigned char snd_es1938_read(es1938_t *chip, unsigned char reg) /* ----------------------------------------------------------------- * Write data to cmd register and return old value * -----------------------------------------------------------------*/ -static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask, unsigned char val) +static int snd_es1938_bits(struct es1938 *chip, unsigned char reg, unsigned char mask, + unsigned char val) { unsigned long flags; unsigned char old, new, oval; @@ -390,7 +392,8 @@ static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask new = (old & ~mask) | (val & mask); snd_es1938_write_cmd(chip, new); #ifdef REG_DEBUG - snd_printk("Reg %02x was %02x, set to %02x\n", reg, old, new); + snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x\n", + reg, old, new); #endif } spin_unlock_irqrestore(&chip->reg_lock, flags); @@ -400,7 +403,7 @@ static int snd_es1938_bits(es1938_t *chip, unsigned char reg, unsigned char mask /* -------------------------------------------------------------------- * Reset the chip * --------------------------------------------------------------------*/ -static void snd_es1938_reset(es1938_t *chip) +static void snd_es1938_reset(struct es1938 *chip) { int i; @@ -413,7 +416,7 @@ static void snd_es1938_reset(es1938_t *chip) goto __next; } } - snd_printk("ESS Solo-1 reset failed\n"); + snd_printk(KERN_ERR "ESS Solo-1 reset failed\n"); __next: snd_es1938_write_cmd(chip, ESS_CMD_ENABLEEXT); @@ -439,13 +442,13 @@ static void snd_es1938_reset(es1938_t *chip) /* -------------------------------------------------------------------- * Reset the FIFOs * --------------------------------------------------------------------*/ -static void snd_es1938_reset_fifo(es1938_t *chip) +static void snd_es1938_reset_fifo(struct es1938 *chip) { outb(2, SLSB_REG(chip, RESET)); outb(0, SLSB_REG(chip, RESET)); } -static ratnum_t clocks[2] = { +static struct snd_ratnum clocks[2] = { { .num = 793800, .den_min = 1, @@ -460,18 +463,18 @@ static ratnum_t clocks[2] = { } }; -static snd_pcm_hw_constraint_ratnums_t hw_constraints_clocks = { +static struct snd_pcm_hw_constraint_ratnums hw_constraints_clocks = { .nrats = 2, .rats = clocks, }; -static void snd_es1938_rate_set(es1938_t *chip, - snd_pcm_substream_t *substream, +static void snd_es1938_rate_set(struct es1938 *chip, + struct snd_pcm_substream *substream, int mode) { unsigned int bits, div0; - snd_pcm_runtime_t *runtime = substream->runtime; + struct snd_pcm_runtime *runtime = substream->runtime; if (runtime->rate_num == clocks[0].num) bits = 128 - runtime->rate_den; else @@ -493,7 +496,7 @@ static void snd_es1938_rate_set(es1938_t *chip, * Configure Solo1 builtin DMA Controller * --------------------------------------------------------------------*/ -static void snd_es1938_playback1_setdma(es1938_t *chip) +static void snd_es1938_playback1_setdma(struct es1938 *chip) { outb(0x00, SLIO_REG(chip, AUDIO2MODE)); outl(chip->dma2_start, SLIO_REG(chip, AUDIO2DMAADDR)); @@ -501,7 +504,7 @@ static void snd_es1938_playback1_setdma(es1938_t *chip) outw(chip->dma2_size, SLIO_REG(chip, AUDIO2DMACOUNT)); } -static void snd_es1938_playback2_setdma(es1938_t *chip) +static void snd_es1938_playback2_setdma(struct es1938 *chip) { /* Enable DMA controller */ outb(0xc4, SLDM_REG(chip, DMACOMMAND)); @@ -516,7 +519,7 @@ static void snd_es1938_playback2_setdma(es1938_t *chip) outb(0, SLDM_REG(chip, DMAMASK)); } -static void snd_es1938_capture_setdma(es1938_t *chip) +static void snd_es1938_capture_setdma(struct es1938 *chip) { /* Enable DMA controller */ outb(0xc4, SLDM_REG(chip, DMACOMMAND)); @@ -526,6 +529,7 @@ static void snd_es1938_capture_setdma(es1938_t *chip) outb(1, SLDM_REG(chip, DMAMASK)); outb(0x14, SLDM_REG(chip, DMAMODE)); outl(chip->dma1_start, SLDM_REG(chip, DMAADDR)); + chip->last_capture_dmaaddr = chip->dma1_start; outw(chip->dma1_size - 1, SLDM_REG(chip, DMACOUNT)); /* 3. Unmask DMA */ outb(0, SLDM_REG(chip, DMAMASK)); @@ -536,10 +540,10 @@ static void snd_es1938_capture_setdma(es1938_t *chip) * *** PCM part *** */ -static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream, +static int snd_es1938_capture_trigger(struct snd_pcm_substream *substream, int cmd) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); int val; switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -559,10 +563,10 @@ static int snd_es1938_capture_trigger(snd_pcm_substream_t * substream, return 0; } -static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream, +static int snd_es1938_playback1_trigger(struct snd_pcm_substream *substream, int cmd) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); switch (cmd) { case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_RESUME: @@ -589,10 +593,10 @@ static int snd_es1938_playback1_trigger(snd_pcm_substream_t * substream, return 0; } -static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream, +static int snd_es1938_playback2_trigger(struct snd_pcm_substream *substream, int cmd) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); int val; switch (cmd) { case SNDRV_PCM_TRIGGER_START: @@ -612,7 +616,7 @@ static int snd_es1938_playback2_trigger(snd_pcm_substream_t * substream, return 0; } -static int snd_es1938_playback_trigger(snd_pcm_substream_t *substream, +static int snd_es1938_playback_trigger(struct snd_pcm_substream *substream, int cmd) { switch (substream->number) { @@ -628,10 +632,10 @@ static int snd_es1938_playback_trigger(snd_pcm_substream_t *substream, /* -------------------------------------------------------------------- * First channel for Extended Mode Audio 1 ADC Operation * --------------------------------------------------------------------*/ -static int snd_es1938_capture_prepare(snd_pcm_substream_t * substream) +static int snd_es1938_capture_prepare(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int u, is8, mono; unsigned int size = snd_pcm_lib_buffer_bytes(substream); unsigned int count = snd_pcm_lib_period_bytes(substream); @@ -676,10 +680,10 @@ static int snd_es1938_capture_prepare(snd_pcm_substream_t * substream) /* ------------------------------------------------------------------------------ * Second Audio channel DAC Operation * ------------------------------------------------------------------------------*/ -static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream) +static int snd_es1938_playback1_prepare(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int u, is8, mono; unsigned int size = snd_pcm_lib_buffer_bytes(substream); unsigned int count = snd_pcm_lib_period_bytes(substream); @@ -704,7 +708,8 @@ static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream) snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2TCOUNTH, count >> 8); /* initialize and configure Audio 2 DAC */ - snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x40 | (u ? 0 : 4) | (mono ? 0 : 2) | (is8 ? 0 : 1)); + snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL2, 0x40 | (u ? 0 : 4) | + (mono ? 0 : 2) | (is8 ? 0 : 1)); /* program DMA */ snd_es1938_playback1_setdma(chip); @@ -712,10 +717,10 @@ static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream) return 0; } -static int snd_es1938_playback2_prepare(snd_pcm_substream_t * substream) +static int snd_es1938_playback2_prepare(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; int u, is8, mono; unsigned int size = snd_pcm_lib_buffer_bytes(substream); unsigned int count = snd_pcm_lib_period_bytes(substream); @@ -754,7 +759,7 @@ static int snd_es1938_playback2_prepare(snd_pcm_substream_t * substream) return 0; } -static int snd_es1938_playback_prepare(snd_pcm_substream_t *substream) +static int snd_es1938_playback_prepare(struct snd_pcm_substream *substream) { switch (substream->number) { case 0: @@ -766,26 +771,47 @@ static int snd_es1938_playback_prepare(snd_pcm_substream_t *substream) return -EINVAL; } -static snd_pcm_uframes_t snd_es1938_capture_pointer(snd_pcm_substream_t * substream) +/* 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. +*/ +static snd_pcm_uframes_t snd_es1938_capture_pointer(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); size_t ptr; +#if 0 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; + 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; #endif return ptr >> chip->dma1_shift; } -static snd_pcm_uframes_t snd_es1938_playback1_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_es1938_playback1_pointer(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); size_t ptr; #if 1 ptr = chip->dma2_size - inw(SLIO_REG(chip, AUDIO2DMACOUNT)); @@ -795,9 +821,9 @@ static snd_pcm_uframes_t snd_es1938_playback1_pointer(snd_pcm_substream_t * subs return ptr >> chip->dma2_shift; } -static snd_pcm_uframes_t snd_es1938_playback2_pointer(snd_pcm_substream_t * substream) +static snd_pcm_uframes_t snd_es1938_playback2_pointer(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); size_t ptr; size_t old, new; #if 1 @@ -812,7 +838,7 @@ static snd_pcm_uframes_t snd_es1938_playback2_pointer(snd_pcm_substream_t * subs return ptr >> chip->dma1_shift; } -static snd_pcm_uframes_t snd_es1938_playback_pointer(snd_pcm_substream_t *substream) +static snd_pcm_uframes_t snd_es1938_playback_pointer(struct snd_pcm_substream *substream) { switch (substream->number) { case 0: @@ -824,17 +850,18 @@ static snd_pcm_uframes_t snd_es1938_playback_pointer(snd_pcm_substream_t *substr return -EINVAL; } -static int snd_es1938_capture_copy(snd_pcm_substream_t *substream, +static int snd_es1938_capture_copy(struct snd_pcm_substream *substream, int channel, snd_pcm_uframes_t pos, void __user *dst, snd_pcm_uframes_t count) { - snd_pcm_runtime_t *runtime = substream->runtime; - es1938_t *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); pos <<= chip->dma1_shift; count <<= chip->dma1_shift; - snd_assert(pos + count <= chip->dma1_size, return -EINVAL); + if (snd_BUG_ON(pos + count > chip->dma1_size)) + return -EINVAL; if (pos + count < chip->dma1_size) { if (copy_to_user(dst, runtime->dma_area + pos + 1, count)) return -EFAULT; @@ -850,8 +877,8 @@ static int snd_es1938_capture_copy(snd_pcm_substream_t *substream, /* * buffer management */ -static int snd_es1938_pcm_hw_params(snd_pcm_substream_t *substream, - snd_pcm_hw_params_t * hw_params) +static int snd_es1938_pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { int err; @@ -861,7 +888,7 @@ static int snd_es1938_pcm_hw_params(snd_pcm_substream_t *substream, return 0; } -static int snd_es1938_pcm_hw_free(snd_pcm_substream_t *substream) +static int snd_es1938_pcm_hw_free(struct snd_pcm_substream *substream) { return snd_pcm_lib_free_pages(substream); } @@ -869,11 +896,12 @@ static int snd_es1938_pcm_hw_free(snd_pcm_substream_t *substream) /* ---------------------------------------------------------------------- * Audio1 Capture (ADC) * ----------------------------------------------------------------------*/ -static snd_pcm_hardware_t snd_es1938_capture = +static struct snd_pcm_hardware snd_es1938_capture = { .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER), - .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE, + .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 6000, .rate_max = 48000, @@ -890,12 +918,13 @@ static snd_pcm_hardware_t snd_es1938_capture = /* ----------------------------------------------------------------------- * Audio2 Playback (DAC) * -----------------------------------------------------------------------*/ -static snd_pcm_hardware_t snd_es1938_playback = +static struct snd_pcm_hardware snd_es1938_playback = { .info = (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID), - .formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE, + .formats = (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE | + SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE), .rates = SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000, .rate_min = 6000, .rate_max = 48000, @@ -909,10 +938,10 @@ static snd_pcm_hardware_t snd_es1938_playback = .fifo_size = 256, }; -static int snd_es1938_capture_open(snd_pcm_substream_t * substream) +static int snd_es1938_capture_open(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; if (chip->playback2_substream) return -EAGAIN; @@ -924,10 +953,10 @@ static int snd_es1938_capture_open(snd_pcm_substream_t * substream) return 0; } -static int snd_es1938_playback_open(snd_pcm_substream_t * substream) +static int snd_es1938_playback_open(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); - snd_pcm_runtime_t *runtime = substream->runtime; + struct es1938 *chip = snd_pcm_substream_chip(substream); + struct snd_pcm_runtime *runtime = substream->runtime; switch (substream->number) { case 0: @@ -949,17 +978,17 @@ static int snd_es1938_playback_open(snd_pcm_substream_t * substream) return 0; } -static int snd_es1938_capture_close(snd_pcm_substream_t * substream) +static int snd_es1938_capture_close(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); chip->capture_substream = NULL; return 0; } -static int snd_es1938_playback_close(snd_pcm_substream_t * substream) +static int snd_es1938_playback_close(struct snd_pcm_substream *substream) { - es1938_t *chip = snd_pcm_substream_chip(substream); + struct es1938 *chip = snd_pcm_substream_chip(substream); switch (substream->number) { case 0: @@ -975,7 +1004,7 @@ static int snd_es1938_playback_close(snd_pcm_substream_t * substream) return 0; } -static snd_pcm_ops_t snd_es1938_playback_ops = { +static struct snd_pcm_ops snd_es1938_playback_ops = { .open = snd_es1938_playback_open, .close = snd_es1938_playback_close, .ioctl = snd_pcm_lib_ioctl, @@ -986,7 +1015,7 @@ static snd_pcm_ops_t snd_es1938_playback_ops = { .pointer = snd_es1938_playback_pointer, }; -static snd_pcm_ops_t snd_es1938_capture_ops = { +static struct snd_pcm_ops snd_es1938_capture_ops = { .open = snd_es1938_capture_open, .close = snd_es1938_capture_close, .ioctl = snd_pcm_lib_ioctl, @@ -998,14 +1027,9 @@ static snd_pcm_ops_t snd_es1938_capture_ops = { .copy = snd_es1938_capture_copy, }; -static void snd_es1938_free_pcm(snd_pcm_t *pcm) -{ - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device) +static int __devinit snd_es1938_new_pcm(struct es1938 *chip, int device) { - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; if ((err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm)) < 0) @@ -1014,7 +1038,6 @@ static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device) snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_es1938_capture_ops); pcm->private_data = chip; - pcm->private_free = snd_es1938_free_pcm; pcm->info_flags = 0; strcpy(pcm->name, "ESS Solo-1"); @@ -1030,7 +1053,8 @@ static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device) * *** Mixer part *** */ -static int snd_es1938_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_es1938_info_mux(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { static char *texts[8] = { "Mic", "Mic Master", "CD", "AOUT", @@ -1046,16 +1070,18 @@ static int snd_es1938_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * u return 0; } -static int snd_es1938_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_mux(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); ucontrol->value.enumerated.item[0] = snd_es1938_mixer_read(chip, 0x1c) & 0x07; return 0; } -static int snd_es1938_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_put_mux(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); unsigned char val = ucontrol->value.enumerated.item[0]; if (val > 7) @@ -1063,26 +1089,21 @@ static int snd_es1938_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * return snd_es1938_mixer_bits(chip, 0x1c, 0x07, val) != val; } -static int snd_es1938_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; - return 0; -} +#define snd_es1938_info_spatializer_enable snd_ctl_boolean_mono_info -static int snd_es1938_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_spatializer_enable(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); unsigned char val = snd_es1938_mixer_read(chip, 0x50); ucontrol->value.integer.value[0] = !!(val & 8); return 0; } -static int snd_es1938_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_put_spatializer_enable(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); unsigned char oval, nval; int change; nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04; @@ -1095,7 +1116,8 @@ static int snd_es1938_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_ return change; } -static int snd_es1938_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_es1938_info_hw_volume(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; uinfo->count = 2; @@ -1104,41 +1126,36 @@ static int snd_es1938_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info return 0; } -static int snd_es1938_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_hw_volume(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); 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; } -static int snd_es1938_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) -{ - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - uinfo->count = 2; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = 1; - return 0; -} +#define snd_es1938_info_hw_switch snd_ctl_boolean_stereo_info -static int snd_es1938_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_hw_switch(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); 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; } -static void snd_es1938_hwv_free(snd_kcontrol_t *kcontrol) +static void snd_es1938_hwv_free(struct snd_kcontrol *kcontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); chip->master_volume = NULL; chip->master_switch = NULL; chip->hw_volume = NULL; chip->hw_switch = NULL; } -static int snd_es1938_reg_bits(es1938_t *chip, unsigned char reg, +static int snd_es1938_reg_bits(struct es1938 *chip, unsigned char reg, unsigned char mask, unsigned char val) { if (reg < 0xa0) @@ -1147,7 +1164,7 @@ static int snd_es1938_reg_bits(es1938_t *chip, unsigned char reg, return snd_es1938_bits(chip, reg, mask, val); } -static int snd_es1938_reg_read(es1938_t *chip, unsigned char reg) +static int snd_es1938_reg_read(struct es1938 *chip, unsigned char reg) { if (reg < 0xa0) return snd_es1938_mixer_read(chip, reg); @@ -1155,13 +1172,22 @@ static int snd_es1938_reg_read(es1938_t *chip, unsigned char reg) return snd_es1938_read(chip, reg); } +#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 } } #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) } -static int snd_es1938_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_es1938_info_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 16) & 0xff; @@ -1172,9 +1198,10 @@ static int snd_es1938_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_es1938_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; @@ -1188,9 +1215,10 @@ static int snd_es1938_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t return 0; } -static int snd_es1938_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_put_single(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); int reg = kcontrol->private_value & 0xff; int shift = (kcontrol->private_value >> 8) & 0xff; int mask = (kcontrol->private_value >> 16) & 0xff; @@ -1205,13 +1233,22 @@ static int snd_es1938_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t return snd_es1938_reg_bits(chip, reg, mask, val) != val; } +#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 } } #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) } -static int snd_es1938_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo) +static int snd_es1938_info_double(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { int mask = (kcontrol->private_value >> 24) & 0xff; @@ -1222,9 +1259,10 @@ static int snd_es1938_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t return 0; } -static int snd_es1938_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_get_double(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; @@ -1247,9 +1285,10 @@ static int snd_es1938_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t return 0; } -static int snd_es1938_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol) +static int snd_es1938_put_double(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) { - es1938_t *chip = snd_kcontrol_chip(kcontrol); + struct es1938 *chip = snd_kcontrol_chip(kcontrol); int left_reg = kcontrol->private_value & 0xff; int right_reg = (kcontrol->private_value >> 8) & 0xff; int shift_left = (kcontrol->private_value >> 16) & 0x07; @@ -1282,8 +1321,41 @@ static int snd_es1938_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t return change; } -static snd_kcontrol_new_t snd_es1938_controls[] = { -ES1938_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0), +static unsigned int db_scale_master[] = { + TLV_DB_RANGE_HEAD(2), + 0, 54, TLV_DB_SCALE_ITEM(-3600, 50, 1), + 54, 63, TLV_DB_SCALE_ITEM(-900, 100, 0), +}; + +static unsigned int db_scale_audio1[] = { + TLV_DB_RANGE_HEAD(2), + 0, 8, TLV_DB_SCALE_ITEM(-3300, 300, 1), + 8, 15, TLV_DB_SCALE_ITEM(-900, 150, 0), +}; + +static unsigned int db_scale_audio2[] = { + TLV_DB_RANGE_HEAD(2), + 0, 8, TLV_DB_SCALE_ITEM(-3450, 300, 1), + 8, 15, TLV_DB_SCALE_ITEM(-1050, 150, 0), +}; + +static unsigned int db_scale_mic[] = { + TLV_DB_RANGE_HEAD(2), + 0, 8, TLV_DB_SCALE_ITEM(-2400, 300, 1), + 8, 15, TLV_DB_SCALE_ITEM(0, 150, 0), +}; + +static unsigned int db_scale_line[] = { + TLV_DB_RANGE_HEAD(2), + 0, 8, TLV_DB_SCALE_ITEM(-3150, 300, 1), + 8, 15, TLV_DB_SCALE_ITEM(-750, 150, 0), +}; + +static const DECLARE_TLV_DB_SCALE(db_scale_capture, 0, 150, 0); + +static struct snd_kcontrol_new snd_es1938_controls[] = { +ES1938_DOUBLE_TLV("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0, + db_scale_master), ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -1294,20 +1366,28 @@ ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), }, { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, + .access = (SNDRV_CTL_ELEM_ACCESS_READ | + SNDRV_CTL_ELEM_ACCESS_TLV_READ), .name = "Hardware Master Playback Switch", - .access = SNDRV_CTL_ELEM_ACCESS_READ, .info = snd_es1938_info_hw_switch, .get = snd_es1938_get_hw_switch, + .tlv = { .p = db_scale_master }, }, ES1938_SINGLE("Hardware Volume Split", 0, 0x64, 7, 1, 0), -ES1938_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0), +ES1938_DOUBLE_TLV("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0, + db_scale_line), ES1938_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0), -ES1938_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0), -ES1938_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), -ES1938_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0), -ES1938_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0), -ES1938_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0), -ES1938_SINGLE("PC Speaker Volume", 0, 0x3c, 0, 7, 0), +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), +ES1938_SINGLE("Beep Volume", 0, 0x3c, 0, 7, 0), ES1938_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0), ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), { @@ -1317,16 +1397,26 @@ ES1938_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1), .get = snd_es1938_get_mux, .put = snd_es1938_put_mux, }, -ES1938_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0), -ES1938_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0), -ES1938_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0), -ES1938_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0), -ES1938_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0), -ES1938_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0), -ES1938_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0), -ES1938_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0), -ES1938_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0), -ES1938_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0), +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), ES1938_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0), { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, @@ -1345,7 +1435,7 @@ ES1938_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0) /* * initialize the chip - used by resume callback, too */ -static void snd_es1938_chip_init(es1938_t *chip) +static void snd_es1938_chip_init(struct es1938 *chip) { /* reset chip */ snd_es1938_reset(chip); @@ -1384,11 +1474,13 @@ static unsigned char saved_regs[SAVED_REG_SIZE+1] = { }; -static int es1938_suspend(snd_card_t *card, pm_message_t state) +static int es1938_suspend(struct pci_dev *pci, pm_message_t state) { - es1938_t *chip = card->pm_private_data; + struct snd_card *card = pci_get_drvdata(pci); + struct es1938 *chip = card->private_data; unsigned char *s, *d; + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); snd_pcm_suspend_all(chip->pcm); /* save mixer-related registers */ @@ -1396,21 +1488,39 @@ static int es1938_suspend(snd_card_t *card, pm_message_t state) *d = snd_es1938_reg_read(chip, *s); outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ - if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); - pci_disable_device(chip->pci); + if (chip->irq >= 0) { + free_irq(chip->irq, chip); + chip->irq = -1; + } + pci_disable_device(pci); + pci_save_state(pci); + pci_set_power_state(pci, pci_choose_state(pci, state)); return 0; } -static int es1938_resume(snd_card_t *card) +static int es1938_resume(struct pci_dev *pci) { - es1938_t *chip = card->pm_private_data; + struct snd_card *card = pci_get_drvdata(pci); + struct es1938 *chip = card->private_data; unsigned char *s, *d; - pci_enable_device(chip->pci); - request_irq(chip->pci->irq, snd_es1938_interrupt, - SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip); - chip->irq = chip->pci->irq; + pci_set_power_state(pci, PCI_D0); + pci_restore_state(pci); + if (pci_enable_device(pci) < 0) { + printk(KERN_ERR "es1938: pci_enable_device failed, " + "disabling device\n"); + snd_card_disconnect(card); + return -EIO; + } + + if (request_irq(pci->irq, snd_es1938_interrupt, + IRQF_SHARED, "ES1938", chip)) { + printk(KERN_ERR "es1938: unable to grab IRQ %d, " + "disabling device\n", pci->irq); + snd_card_disconnect(card); + return -EIO; + } + chip->irq = pci->irq; snd_es1938_chip_init(chip); /* restore mixer-related registers */ @@ -1421,12 +1531,13 @@ static int es1938_resume(snd_card_t *card) snd_es1938_write(chip, *s, *d); } + snd_power_change_state(card, SNDRV_CTL_POWER_D0); return 0; } #endif /* CONFIG_PM */ #ifdef SUPPORT_JOYSTICK -static int __devinit snd_es1938_create_gameport(es1938_t *chip) +static int __devinit snd_es1938_create_gameport(struct es1938 *chip) { struct gameport *gp; @@ -1446,7 +1557,7 @@ static int __devinit snd_es1938_create_gameport(es1938_t *chip) return 0; } -static void snd_es1938_free_gameport(es1938_t *chip) +static void snd_es1938_free_gameport(struct es1938 *chip) { if (chip->gameport) { gameport_unregister_port(chip->gameport); @@ -1454,11 +1565,11 @@ static void snd_es1938_free_gameport(es1938_t *chip) } } #else -static inline int snd_es1938_create_gameport(es1938_t *chip) { return -ENOSYS; } -static inline void snd_es1938_free_gameport(es1938_t *chip) { } +static inline int snd_es1938_create_gameport(struct es1938 *chip) { return -ENOSYS; } +static inline void snd_es1938_free_gameport(struct es1938 *chip) { } #endif /* SUPPORT_JOYSTICK */ -static int snd_es1938_free(es1938_t *chip) +static int snd_es1938_free(struct es1938 *chip) { /* disable irqs */ outb(0x00, SLIO_REG(chip, IRQCONTROL)); @@ -1468,26 +1579,26 @@ static int snd_es1938_free(es1938_t *chip) snd_es1938_free_gameport(chip); if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); + free_irq(chip->irq, chip); pci_release_regions(chip->pci); pci_disable_device(chip->pci); kfree(chip); return 0; } -static int snd_es1938_dev_free(snd_device_t *device) +static int snd_es1938_dev_free(struct snd_device *device) { - es1938_t *chip = device->device_data; + struct es1938 *chip = device->device_data; return snd_es1938_free(chip); } -static int __devinit snd_es1938_create(snd_card_t * card, +static int __devinit snd_es1938_create(struct snd_card *card, struct pci_dev * pci, - es1938_t ** rchip) + struct es1938 ** rchip) { - es1938_t *chip; + struct es1938 *chip; int err; - static snd_device_ops_t ops = { + static struct snd_device_ops ops = { .dev_free = snd_es1938_dev_free, }; @@ -1497,9 +1608,9 @@ static int __devinit snd_es1938_create(snd_card_t * card, if ((err = pci_enable_device(pci)) < 0) return err; /* check, if we can restrict PCI DMA transfers to 24 bits */ - if (pci_set_dma_mask(pci, 0x00ffffff) < 0 || - pci_set_consistent_dma_mask(pci, 0x00ffffff) < 0) { - snd_printk("architecture does not support 24bit PCI busmaster DMA\n"); + if (pci_set_dma_mask(pci, DMA_BIT_MASK(24)) < 0 || + pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(24)) < 0) { + snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); pci_disable_device(pci); return -ENXIO; } @@ -1513,6 +1624,7 @@ static int __devinit snd_es1938_create(snd_card_t * card, spin_lock_init(&chip->mixer_lock); chip->card = card; chip->pci = pci; + chip->irq = -1; if ((err = pci_request_regions(pci, "ESS Solo-1")) < 0) { kfree(chip); pci_disable_device(pci); @@ -1523,14 +1635,15 @@ static int __devinit snd_es1938_create(snd_card_t * card, chip->vc_port = pci_resource_start(pci, 2); chip->mpu_port = pci_resource_start(pci, 3); chip->game_port = pci_resource_start(pci, 4); - if (request_irq(pci->irq, snd_es1938_interrupt, SA_INTERRUPT|SA_SHIRQ, "ES1938", (void *)chip)) { - snd_printk("unable to grab IRQ %d\n", pci->irq); + if (request_irq(pci->irq, snd_es1938_interrupt, IRQF_SHARED, + "ES1938", chip)) { + snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq); snd_es1938_free(chip); return -EBUSY; } chip->irq = pci->irq; #ifdef ES1938_DDEBUG - snd_printk("create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", + snd_printk(KERN_DEBUG "create: io: 0x%lx, sb: 0x%lx, vc: 0x%lx, mpu: 0x%lx, game: 0x%lx\n", chip->io_port, chip->sb_port, chip->vc_port, chip->mpu_port, chip->game_port); #endif @@ -1538,8 +1651,6 @@ static int __devinit snd_es1938_create(snd_card_t * card, snd_es1938_chip_init(chip); - snd_card_set_pm_callback(card, es1938_suspend, es1938_resume, chip); - if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { snd_es1938_free(chip); return err; @@ -1554,24 +1665,31 @@ static int __devinit snd_es1938_create(snd_card_t * card, /* -------------------------------------------------------------------- * Interrupt handler * -------------------------------------------------------------------- */ -static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs) +static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id) { - es1938_t *chip = dev_id; + struct es1938 *chip = dev_id; unsigned char status, audiostatus; int handled = 0; status = inb(SLIO_REG(chip, IRQCONTROL)); #if 0 - printk("Es1938debug - interrupt status: =0x%x\n", status); + printk(KERN_DEBUG "Es1938debug - interrupt status: =0x%x\n", status); #endif /* AUDIO 1 */ if (status & 0x10) { #if 0 - printk("Es1938debug - AUDIO channel 1 interrupt\n"); - printk("Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", inw(SLDM_REG(chip, DMACOUNT))); - printk("Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", inl(SLDM_REG(chip, DMAADDR))); - printk("Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", inl(SLDM_REG(chip, DMASTATUS))); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 1 interrupt\n"); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 1 DMAC DMA count: %u\n", + inw(SLDM_REG(chip, DMACOUNT))); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 1 DMAC DMA base: %u\n", + inl(SLDM_REG(chip, DMAADDR))); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 1 DMAC DMA status: 0x%x\n", + inl(SLDM_REG(chip, DMASTATUS))); #endif /* clear irq */ handled = 1; @@ -1585,9 +1703,14 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r /* AUDIO 2 */ if (status & 0x20) { #if 0 - printk("Es1938debug - AUDIO channel 2 interrupt\n"); - printk("Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", inw(SLIO_REG(chip, AUDIO2DMACOUNT))); - printk("Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", inl(SLIO_REG(chip, AUDIO2DMAADDR))); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 2 interrupt\n"); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 2 DMAC DMA count: %u\n", + inw(SLIO_REG(chip, AUDIO2DMACOUNT))); + printk(KERN_DEBUG + "Es1938debug - AUDIO channel 2 DMAC DMA base: %u\n", + inl(SLIO_REG(chip, AUDIO2DMAADDR))); #endif /* clear irq */ @@ -1604,8 +1727,10 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r 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) { - 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); + 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); } /* ack interrupt */ snd_es1938_mixer_write(chip, 0x66, 0x00); @@ -1619,7 +1744,7 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r // snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0); /* ack? */ if (chip->rmidi) { handled = 1; - snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs); + snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data); } } return IRQ_RETVAL(handled); @@ -1627,9 +1752,9 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r #define ES1938_DMA_SIZE 64 -static int __devinit snd_es1938_mixer(es1938_t *chip) +static int __devinit snd_es1938_mixer(struct es1938 *chip) { - snd_card_t *card; + struct snd_card *card; unsigned int idx; int err; @@ -1638,7 +1763,7 @@ static int __devinit snd_es1938_mixer(es1938_t *chip) strcpy(card->mixername, "ESS Solo-1"); for (idx = 0; idx < ARRAY_SIZE(snd_es1938_controls); idx++) { - snd_kcontrol_t *kctl; + struct snd_kcontrol *kctl; kctl = snd_ctl_new1(&snd_es1938_controls[idx], chip); switch (idx) { case 0: @@ -1669,9 +1794,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, const struct pci_device_id *pci_id) { static int dev; - snd_card_t *card; - es1938_t *chip; - opl3_t *opl3; + struct snd_card *card; + struct es1938 *chip; + struct snd_opl3 *opl3; int idx, err; if (dev >= SNDRV_CARDS) @@ -1681,9 +1806,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, return -ENOENT; } - card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0); - if (card == NULL) - return -ENOMEM; + err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); + if (err < 0) + return err; for (idx = 0; idx < 5; idx++) { if (pci_resource_start(pci, idx) == 0 || !(pci_resource_flags(pci, idx) & IORESOURCE_IO)) { @@ -1695,6 +1820,7 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, snd_card_free(card); return err; } + card->private_data = chip; strcpy(card->driver, "ES1938"); strcpy(card->shortname, "ESS ES1938 (Solo-1)"); @@ -1728,7 +1854,8 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, } } if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, - chip->mpu_port, 1, chip->irq, 0, &chip->rmidi) < 0) { + chip->mpu_port, MPU401_INFO_INTEGRATED, + chip->irq, 0, &chip->rmidi) < 0) { printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); } else { // this line is vital for MIDI interrupt handling on ess-solo1 @@ -1756,11 +1883,13 @@ static void __devexit snd_es1938_remove(struct pci_dev *pci) static struct pci_driver driver = { .name = "ESS ES1938 (Solo-1)", - .owner = THIS_MODULE, .id_table = snd_es1938_ids, .probe = snd_es1938_probe, .remove = __devexit_p(snd_es1938_remove), - SND_PCI_PM_CALLBACKS +#ifdef CONFIG_PM + .suspend = es1938_suspend, + .resume = es1938_resume, +#endif }; static int __init alsa_card_es1938_init(void)