X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fpci%2Fes1938.c;h=6f9094ca4fb4b8b5780d1d30ca62e41e8d90d0a2;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=87afa49a0334eca61ac844def454e4de9084a9ba;hpb=9213980e6a70d8473e0ffd4b39ab5b6caaba9ff5;p=linux-2.6.git diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c index 87afa49a0..6f9094ca4 100644 --- a/sound/pci/es1938.c +++ b/sound/pci/es1938.c @@ -54,6 +54,8 @@ #include #include #include +#include +#include #include #include #include @@ -63,38 +65,28 @@ #include -#define chip_t es1938_t - MODULE_AUTHOR("Jaromir Koutek "); MODULE_DESCRIPTION("ESS Solo-1"); MODULE_LICENSE("GPL"); -MODULE_CLASSES("{sound}"); -MODULE_DEVICES("{{ESS,ES1938}," +MODULE_SUPPORTED_DEVICE("{{ESS,ES1938}," "{ESS,ES1946}," "{ESS,ES1969}," "{TerraTec,128i PCI}}"); -#ifndef PCI_VENDOR_ID_ESS -#define PCI_VENDOR_ID_ESS 0x125d -#endif -#ifndef PCI_DEVICE_ID_ESS_ES1938 -#define PCI_DEVICE_ID_ESS_ES1938 0x1969 +#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) +#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 */ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ -static int boot_devs; -module_param_array(index, int, boot_devs, 0444); +module_param_array(index, int, NULL, 0444); MODULE_PARM_DESC(index, "Index value for ESS Solo-1 soundcard."); -MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC); -module_param_array(id, charp, boot_devs, 0444); +module_param_array(id, charp, NULL, 0444); MODULE_PARM_DESC(id, "ID string for ESS Solo-1 soundcard."); -MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC); -module_param_array(enable, bool, boot_devs, 0444); +module_param_array(enable, bool, NULL, 0444); MODULE_PARM_DESC(enable, "Enable ESS Solo-1 soundcard."); -MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); #define SLIO_REG(chip, x) ((chip)->io_port + ESSIO_REG_##x) @@ -200,38 +192,33 @@ MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC); */ -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; - struct resource *res_io_port; unsigned long sb_port; - struct resource *res_sb_port; unsigned long vc_port; - struct resource *res_vc_port; unsigned long mpu_port; - struct resource *res_mpu_port; unsigned long game_port; - struct resource *res_game_port; unsigned long ddma_port; 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_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; @@ -243,16 +230,19 @@ struct _snd_es1938 { spinlock_t reg_lock; spinlock_t mixer_lock; - snd_info_entry_t *proc_entry; + struct snd_info_entry *proc_entry; -#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) - struct gameport gameport; +#ifdef SUPPORT_JOYSTICK + struct gameport *gameport; +#endif +#ifdef CONFIG_PM + unsigned char saved_regs[SAVED_REG_SIZE]; #endif }; static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs); -static struct pci_device_id snd_es1938_ids[] = { +static struct pci_device_id snd_es1938_ids[] __devinitdata = { { 0x125d, 0x1969, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* Solo-1 */ { 0, } }; @@ -267,7 +257,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); @@ -275,14 +265,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; @@ -291,7 +281,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; } @@ -299,7 +289,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; @@ -311,7 +302,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); @@ -321,7 +313,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; @@ -331,27 +323,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); @@ -359,14 +351,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; @@ -376,7 +368,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; } @@ -384,7 +376,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; @@ -398,7 +391,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); @@ -408,7 +402,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; @@ -421,7 +415,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); @@ -447,13 +441,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, @@ -468,18 +462,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 @@ -501,7 +495,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)); @@ -509,7 +503,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)); @@ -524,7 +518,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)); @@ -544,17 +538,19 @@ 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: + case SNDRV_PCM_TRIGGER_RESUME: val = 0x0f; chip->active |= ADC1; break; case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: val = 0x00; chip->active &= ~ADC1; break; @@ -565,19 +561,26 @@ 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: /* 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: + case SNDRV_PCM_TRIGGER_SUSPEND: outb(0, SLIO_REG(chip, AUDIO2MODE)); snd_es1938_mixer_write(chip, ESSSB_IREG_AUDIO2CONTROL1, 0); chip->active &= ~DAC2; @@ -588,17 +591,19 @@ 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: + case SNDRV_PCM_TRIGGER_RESUME: val = 5; chip->active |= DAC1; break; case SNDRV_PCM_TRIGGER_STOP: + case SNDRV_PCM_TRIGGER_SUSPEND: val = 0; chip->active &= ~DAC1; break; @@ -609,7 +614,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) { @@ -625,10 +630,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); @@ -673,10 +678,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); @@ -690,6 +695,8 @@ static int snd_es1938_playback1_prepare(snd_pcm_substream_t * substream) chip->dma2_shift = 2 - mono - is8; + snd_es1938_reset_fifo(chip); + /* set clock and counters */ snd_es1938_rate_set(chip, substream, DAC2); @@ -699,7 +706,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); @@ -707,10 +715,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); @@ -749,7 +757,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: @@ -761,9 +769,9 @@ 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) +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; size_t old, new; #if 1 @@ -778,9 +786,9 @@ static snd_pcm_uframes_t snd_es1938_capture_pointer(snd_pcm_substream_t * substr 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)); @@ -790,9 +798,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 @@ -807,7 +815,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: @@ -819,14 +827,14 @@ 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); @@ -845,8 +853,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; @@ -856,7 +864,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); } @@ -864,19 +872,20 @@ 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, .channels_min = 1, .channels_max = 2, - .buffer_bytes_max = 65536, + .buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */ .period_bytes_min = 64, - .period_bytes_max = 65536, + .period_bytes_max = 0x8000, .periods_min = 1, .periods_max = 1024, .fifo_size = 256, @@ -885,29 +894,30 @@ 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, .channels_min = 1, .channels_max = 2, - .buffer_bytes_max = 65536, + .buffer_bytes_max = 0x8000, /* DMA controller screws on higher values */ .period_bytes_min = 64, - .period_bytes_max = 65536, + .period_bytes_max = 0x8000, .periods_min = 1, .periods_max = 1024, .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; @@ -919,10 +929,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: @@ -944,17 +954,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: @@ -970,7 +980,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, @@ -981,7 +991,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, @@ -993,33 +1003,24 @@ static snd_pcm_ops_t snd_es1938_capture_ops = { .copy = snd_es1938_capture_copy, }; -static void snd_es1938_free_pcm(snd_pcm_t *pcm) +static int __devinit snd_es1938_new_pcm(struct es1938 *chip, int device) { - snd_pcm_lib_preallocate_free_for_all(pcm); -} - -static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device, snd_pcm_t ** rpcm) -{ - snd_pcm_t *pcm; + struct snd_pcm *pcm; int err; - if (rpcm) - *rpcm = NULL; if ((err = snd_pcm_new(chip->card, "es-1938-1946", device, 2, 1, &pcm)) < 0) 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->private_free = snd_es1938_free_pcm; pcm->info_flags = 0; strcpy(pcm->name, "ESS Solo-1"); snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, snd_dma_pci_data(chip->pci), 64*1024, 64*1024); - if (rpcm) - *rpcm = pcm; + chip->pcm = pcm; return 0; } @@ -1028,7 +1029,8 @@ static int __devinit snd_es1938_new_pcm(es1938_t *chip, int device, snd_pcm_t ** * *** 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", @@ -1044,16 +1046,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) @@ -1061,7 +1065,8 @@ 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) +static int snd_es1938_info_spatializer_enable(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 1; @@ -1070,17 +1075,19 @@ static int snd_es1938_info_spatializer_enable(snd_kcontrol_t *kcontrol, snd_ctl_ return 0; } -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; @@ -1093,7 +1100,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; @@ -1102,15 +1110,17 @@ 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) +static int snd_es1938_info_hw_switch(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) { uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; uinfo->count = 2; @@ -1119,24 +1129,25 @@ static int snd_es1938_info_hw_switch(snd_kcontrol_t *kcontrol, snd_ctl_elem_info return 0; } -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_magic_cast(es1938_t, _snd_kcontrol_chip(kcontrol), return); + 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) @@ -1145,7 +1156,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); @@ -1159,7 +1170,8 @@ static int snd_es1938_reg_read(es1938_t *chip, unsigned char reg) .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; @@ -1170,9 +1182,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; @@ -1186,9 +1199,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; @@ -1209,7 +1223,8 @@ static int snd_es1938_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t .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; @@ -1220,9 +1235,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; @@ -1245,9 +1261,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; @@ -1280,7 +1297,7 @@ 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[] = { +static struct snd_kcontrol_new snd_es1938_controls[] = { ES1938_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0), ES1938_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1), { @@ -1340,53 +1357,158 @@ ES1938_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0) /* ---------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------- */ -static int snd_es1938_free(es1938_t *chip) +/* + * initialize the chip - used by resume callback, too + */ +static void snd_es1938_chip_init(struct es1938 *chip) { - /*if (chip->rmidi) - snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0);*/ -#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) - if (chip->gameport.io) - gameport_unregister_port(&chip->gameport); -#endif - if (chip->res_io_port) { - release_resource(chip->res_io_port); - kfree_nocheck(chip->res_io_port); - } - if (chip->res_sb_port) { - release_resource(chip->res_sb_port); - kfree_nocheck(chip->res_sb_port); - } - if (chip->res_vc_port) { - release_resource(chip->res_vc_port); - kfree_nocheck(chip->res_vc_port); + /* 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)); +} + +#ifdef CONFIG_PM +/* + * PM support + */ + +static unsigned char saved_regs[SAVED_REG_SIZE+1] = { + 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, +}; + + +static int es1938_suspend(struct pci_dev *pci, pm_message_t state) +{ + 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 */ + 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 */ + if (chip->irq >= 0) + free_irq(chip->irq, chip); + pci_disable_device(pci); + pci_save_state(pci); + return 0; +} + +static int es1938_resume(struct pci_dev *pci) +{ + struct snd_card *card = pci_get_drvdata(pci); + struct es1938 *chip = card->private_data; + unsigned char *s, *d; + + pci_restore_state(pci); + pci_enable_device(pci); + request_irq(pci->irq, snd_es1938_interrupt, + SA_INTERRUPT|SA_SHIRQ, "ES1938", chip); + chip->irq = pci->irq; + 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); } - if (chip->res_mpu_port) { - release_resource(chip->res_mpu_port); - kfree_nocheck(chip->res_mpu_port); + + snd_power_change_state(card, SNDRV_CTL_POWER_D0); + return 0; +} +#endif /* CONFIG_PM */ + +#ifdef SUPPORT_JOYSTICK +static int __devinit snd_es1938_create_gameport(struct es1938 *chip) +{ + struct gameport *gp; + + chip->gameport = gp = gameport_allocate_port(); + if (!gp) { + printk(KERN_ERR "es1938: cannot allocate memory for gameport\n"); + return -ENOMEM; } - if (chip->res_game_port) { - release_resource(chip->res_game_port); - kfree_nocheck(chip->res_game_port); + + 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; +} + +static void snd_es1938_free_gameport(struct es1938 *chip) +{ + if (chip->gameport) { + gameport_unregister_port(chip->gameport); + chip->gameport = NULL; } +} +#else +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(struct es1938 *chip) +{ + /* 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); + if (chip->irq >= 0) - free_irq(chip->irq, (void *)chip); - snd_magic_kfree(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 = snd_magic_cast(es1938_t, device->device_data, return -ENXIO); + 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, }; @@ -1396,85 +1518,47 @@ 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_24BIT_MASK) < 0 || + pci_set_consistent_dma_mask(pci, DMA_24BIT_MASK) < 0) { + snd_printk(KERN_ERR "architecture does not support 24bit PCI busmaster DMA\n"); + pci_disable_device(pci); return -ENXIO; } - chip = snd_magic_kcalloc(es1938_t, 0, GFP_KERNEL); - if (chip == NULL) + chip = kzalloc(sizeof(*chip), GFP_KERNEL); + if (chip == NULL) { + pci_disable_device(pci); return -ENOMEM; + } spin_lock_init(&chip->reg_lock); spin_lock_init(&chip->mixer_lock); chip->card = card; chip->pci = pci; - chip->io_port = pci_resource_start(pci, 0); - if ((chip->res_io_port = request_region(chip->io_port, 8, "ESS Solo-1")) == NULL) { - snd_printk("unable to grab region 0x%lx-0x%lx\n", chip->io_port, chip->io_port + 8 - 1); - snd_es1938_free(chip); - return -EBUSY; + if ((err = pci_request_regions(pci, "ESS Solo-1")) < 0) { + kfree(chip); + pci_disable_device(pci); + return err; } + chip->io_port = pci_resource_start(pci, 0); chip->sb_port = pci_resource_start(pci, 1); - if ((chip->res_sb_port = request_region(chip->sb_port, 0x10, "ESS Solo-1 SB")) == NULL) { - snd_printk("unable to grab SB region 0x%lx-0x%lx\n", chip->sb_port, chip->sb_port + 0x10 - 1); - snd_es1938_free(chip); - return -EBUSY; - } chip->vc_port = pci_resource_start(pci, 2); - if ((chip->res_vc_port = request_region(chip->vc_port, 0x10, "ESS Solo-1 VC (DMA)")) == NULL) { - snd_printk("unable to grab VC (DMA) region 0x%lx-0x%lx\n", chip->vc_port, chip->vc_port + 0x10 - 1); - snd_es1938_free(chip); - return -EBUSY; - } chip->mpu_port = pci_resource_start(pci, 3); - if ((chip->res_mpu_port = request_region(chip->mpu_port, 4, "ESS Solo-1 MIDI")) == NULL) { - snd_printk("unable to grab MIDI region 0x%lx-0x%lx\n", chip->mpu_port, chip->mpu_port + 4 - 1); - snd_es1938_free(chip); - return -EBUSY; - } chip->game_port = pci_resource_start(pci, 4); - if ((chip->res_game_port = request_region(chip->game_port, 4, "ESS Solo-1 GAME")) == NULL) { - snd_printk("unable to grab GAME region 0x%lx-0x%lx\n", chip->game_port, chip->game_port + 4 - 1); - snd_es1938_free(chip); - return -EBUSY; - } - 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, SA_INTERRUPT|SA_SHIRQ, + "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 - /* reset chip */ - snd_es1938_reset(chip); - /* configure native mode */ - - /* enable bus master */ - pci_set_master(pci); - - /* disable legacy audio */ - pci_write_config_word(pci, SL_PCI_LEGACYCONTROL, 0x805f); - - /* set DDMA base */ chip->ddma_port = chip->vc_port + 0x00; /* fix from Thomas Sailer */ - pci_write_config_word(pci, SL_PCI_DDMACONTROL, chip->ddma_port | 1); - /* set DMA/IRQ policy */ - pci_write_config_dword(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)); - - /* enable bus mastering */ - pci_set_master(pci); + snd_es1938_chip_init(chip); if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) { snd_es1938_free(chip); @@ -1492,7 +1576,7 @@ static int __devinit snd_es1938_create(snd_card_t * card, * -------------------------------------------------------------------- */ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *regs) { - es1938_t *chip = snd_magic_cast(es1938_t, dev_id, return IRQ_NONE); + struct es1938 *chip = dev_id; unsigned char status, audiostatus; int handled = 0; @@ -1505,9 +1589,12 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r 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("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))); #endif /* clear irq */ handled = 1; @@ -1522,8 +1609,10 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r 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("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))); #endif /* clear irq */ @@ -1540,8 +1629,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); @@ -1549,6 +1640,9 @@ static irqreturn_t snd_es1938_interrupt(int irq, void *dev_id, struct pt_regs *r /* 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; @@ -1560,22 +1654,18 @@ 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(snd_pcm_t *pcm) +static int __devinit snd_es1938_mixer(struct es1938 *chip) { - snd_card_t *card; - es1938_t *chip; + struct snd_card *card; unsigned int idx; int err; - snd_assert(pcm != NULL && pcm->card != NULL, return -EINVAL); - - card = pcm->card; - chip = snd_pcm_chip(pcm); + card = chip->card; - strcpy(card->mixername, pcm->name); + 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: @@ -1606,10 +1696,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; - snd_pcm_t *pcm; - opl3_t *opl3; + struct snd_card *card; + struct es1938 *chip; + struct snd_opl3 *opl3; int idx, err; if (dev >= SNDRV_CARDS) @@ -1633,6 +1722,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)"); @@ -1641,11 +1731,11 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci, chip->revision, chip->irq); - if ((err = snd_es1938_new_pcm(chip, 0, &pcm)) < 0) { + if ((err = snd_es1938_new_pcm(chip, 0)) < 0) { snd_card_free(card); return err; } - if ((err = snd_es1938_mixer(pcm)) < 0) { + if ((err = snd_es1938_mixer(chip)) < 0) { snd_card_free(card); return err; } @@ -1668,13 +1758,13 @@ 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) { printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); - } /*else - snd_es1938_mixer_bits(chip, ESSSB_IREG_MPU401CONTROL, 0x40, 0x40);*/ + } 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); + } -#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE)) - chip->gameport.io = chip->game_port; - gameport_register_port(&chip->gameport); -#endif + snd_es1938_create_gameport(chip); if ((err = snd_card_register(card)) < 0) { snd_card_free(card); @@ -1697,11 +1787,15 @@ static struct pci_driver driver = { .id_table = snd_es1938_ids, .probe = snd_es1938_probe, .remove = __devexit_p(snd_es1938_remove), +#ifdef CONFIG_PM + .suspend = es1938_suspend, + .resume = es1938_resume, +#endif }; static int __init alsa_card_es1938_init(void) { - return pci_module_init(&driver); + return pci_register_driver(&driver); } static void __exit alsa_card_es1938_exit(void)