ALSA: Return proper error code at probe in sound/isa/*
[linux-2.6.git] / sound / isa / es18xx.c
index f654d59..8cfbff7 100644 (file)
  * - contrarily to some pages in DS_1869.PDF the rates can be set
  *   independently.
  *
+ * - Zoom Video is implemented by sharing the FM DAC, thus the user can
+ *   have either FM playback or Video playback but not both simultaneously.
+ *   The Video Playback Switch mixer control toggles this choice.
+ *
  * BUGS:
  *
  * - There is a major trouble I noted:
  *
  */
 
-
-#include <sound/driver.h>
-#include <asm/io.h>
-#include <asm/dma.h>
+/*
+ * ES1879 NOTES:
+ * - When Zoom Video is enabled (reg 0x71 bit 6 toggled on) the PCM playback
+ *   seems to be effected (speaker_test plays a lower frequency). Can't find
+ *   anything in the datasheet to account for this, so a Video Playback Switch
+ *   control has been included to allow ZV to be enabled only when necessary.
+ *   Then again on at least one test system the 0x71 bit 6 enable bit is not 
+ *   needed for ZV, so maybe the datasheet is entirely wrong here.
+ */
 #include <linux/init.h>
-#include <linux/pm.h>
+#include <linux/err.h>
+#include <linux/isa.h>
 #include <linux/slab.h>
 #include <linux/pnp.h>
 #include <linux/isapnp.h>
 #include <linux/moduleparam.h>
+#include <linux/delay.h>
+
+#include <asm/io.h>
+#include <asm/dma.h>
 #include <sound/core.h>
 #include <sound/control.h>
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
-#define SNDRV_LEGACY_AUTO_PROBE
 #define SNDRV_LEGACY_FIND_FREE_IRQ
 #define SNDRV_LEGACY_FIND_FREE_DMA
 #include <sound/initval.h>
 
 #define PFX "es18xx: "
 
-struct _snd_es18xx {
+struct snd_es18xx {
        unsigned long port;             /* port of ESS chip */
        unsigned long mpu_port;         /* MPU-401 port of ESS chip */
        unsigned long fm_port;          /* FM port */
@@ -107,18 +121,18 @@ struct _snd_es18xx {
        unsigned int dma1_shift;
        unsigned int dma2_shift;
 
-       snd_card_t *card;
-       snd_pcm_t *pcm;
-       snd_pcm_substream_t *playback_a_substream;
-       snd_pcm_substream_t *capture_a_substream;
-       snd_pcm_substream_t *playback_b_substream;
+       struct snd_card *card;
+       struct snd_pcm *pcm;
+       struct snd_pcm_substream *playback_a_substream;
+       struct snd_pcm_substream *capture_a_substream;
+       struct snd_pcm_substream *playback_b_substream;
 
-       snd_rawmidi_t *rmidi;
+       struct snd_rawmidi *rmidi;
 
-       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;
 
        spinlock_t reg_lock;
        spinlock_t mixer_lock;
@@ -128,6 +142,14 @@ struct _snd_es18xx {
 #endif
 };
 
+struct snd_audiodrive {
+       struct snd_es18xx *chip;
+#ifdef CONFIG_PNP
+       struct pnp_dev *dev;
+       struct pnp_dev *devc;
+#endif
+};
+
 #define AUDIO1_IRQ     0x01
 #define AUDIO2_IRQ     0x02
 #define HWV_IRQ                0x04
@@ -140,7 +162,7 @@ struct _snd_es18xx {
 #define ES18XX_DUPLEX_SAME 0x0010      /* Playback and record must share the same rate */
 #define ES18XX_NEW_RATE        0x0020  /* More precise rate setting */
 #define ES18XX_AUXB    0x0040  /* AuxB mixer control */
-#define ES18XX_HWV     0x0080  /* Has hardware volume */
+#define ES18XX_HWV     0x0080  /* Has separate hardware volume mixer controls*/
 #define ES18XX_MONO    0x0100  /* Mono_in mixer control */
 #define ES18XX_I2S     0x0200  /* I2S mixer control */
 #define ES18XX_MUTEREC 0x0400  /* Record source can be muted */
@@ -155,8 +177,6 @@ struct _snd_es18xx {
 #define ES18XX_PM_FM   0x020
 #define ES18XX_PM_SUS  0x080
 
-typedef struct _snd_es18xx es18xx_t;
-
 /* Lowlevel */
 
 #define DAC1 0x01
@@ -164,7 +184,7 @@ typedef struct _snd_es18xx es18xx_t;
 #define DAC2 0x04
 #define MILLISECOND 10000
 
-static int snd_es18xx_dsp_command(es18xx_t *chip, unsigned char val)
+static int snd_es18xx_dsp_command(struct snd_es18xx *chip, unsigned char val)
 {
         int i;
 
@@ -173,24 +193,25 @@ static int snd_es18xx_dsp_command(es18xx_t *chip, unsigned char val)
                         outb(val, chip->port + 0x0C);
                         return 0;
                 }
-        snd_printk("dsp_command: timeout (0x%x)\n", val);
+       snd_printk(KERN_ERR "dsp_command: timeout (0x%x)\n", val);
         return -EINVAL;
 }
 
-static int snd_es18xx_dsp_get_byte(es18xx_t *chip)
+static int snd_es18xx_dsp_get_byte(struct snd_es18xx *chip)
 {
         int i;
 
         for(i = MILLISECOND/10; i; i--)
                 if (inb(chip->port + 0x0C) & 0x40)
                         return inb(chip->port + 0x0A);
-        snd_printk("dsp_get_byte failed: 0x%lx = 0x%x!!!\n", chip->port + 0x0A, inb(chip->port + 0x0A));
+       snd_printk(KERN_ERR "dsp_get_byte failed: 0x%lx = 0x%x!!!\n",
+                  chip->port + 0x0A, inb(chip->port + 0x0A));
         return -ENODEV;
 }
 
 #undef REG_DEBUG
 
-static int snd_es18xx_write(es18xx_t *chip,
+static int snd_es18xx_write(struct snd_es18xx *chip,
                            unsigned char reg, unsigned char data)
 {
        unsigned long flags;
@@ -204,12 +225,12 @@ static int snd_es18xx_write(es18xx_t *chip,
  end:
         spin_unlock_irqrestore(&chip->reg_lock, flags);
 #ifdef REG_DEBUG
-       snd_printk("Reg %02x set to %02x\n", reg, data);
+       snd_printk(KERN_DEBUG "Reg %02x set to %02x\n", reg, data);
 #endif
        return ret;
 }
 
-static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
+static int snd_es18xx_read(struct snd_es18xx *chip, unsigned char reg)
 {
        unsigned long flags;
        int ret, data;
@@ -223,7 +244,7 @@ static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
        data = snd_es18xx_dsp_get_byte(chip);
        ret = data;
 #ifdef REG_DEBUG
-       snd_printk("Reg %02x now is %02x (%d)\n", reg, data, ret);
+       snd_printk(KERN_DEBUG "Reg %02x now is %02x (%d)\n", reg, data, ret);
 #endif
  end:
         spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -231,7 +252,7 @@ static int snd_es18xx_read(es18xx_t *chip, unsigned char reg)
 }
 
 /* Return old value */
-static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
+static int snd_es18xx_bits(struct snd_es18xx *chip, unsigned char reg,
                           unsigned char mask, unsigned char val)
 {
         int ret;
@@ -259,7 +280,8 @@ static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
                if (ret < 0)
                        goto end;
 #ifdef REG_DEBUG
-               snd_printk("Reg %02x was %02x, set to %02x (%d)\n", reg, old, new, ret);
+               snd_printk(KERN_DEBUG "Reg %02x was %02x, set to %02x (%d)\n",
+                          reg, old, new, ret);
 #endif
        }
        ret = oval;
@@ -268,7 +290,7 @@ static int snd_es18xx_bits(es18xx_t *chip, unsigned char reg,
        return ret;
 }
 
-static inline void snd_es18xx_mixer_write(es18xx_t *chip,
+static inline void snd_es18xx_mixer_write(struct snd_es18xx *chip,
                            unsigned char reg, unsigned char data)
 {
        unsigned long flags;
@@ -277,11 +299,11 @@ static inline void snd_es18xx_mixer_write(es18xx_t *chip,
         outb(data, chip->port + 0x05);
         spin_unlock_irqrestore(&chip->mixer_lock, flags);
 #ifdef REG_DEBUG
-       snd_printk("Mixer reg %02x set to %02x\n", reg, data);
+       snd_printk(KERN_DEBUG "Mixer reg %02x set to %02x\n", reg, data);
 #endif
 }
 
-static inline int snd_es18xx_mixer_read(es18xx_t *chip, unsigned char reg)
+static inline int snd_es18xx_mixer_read(struct snd_es18xx *chip, unsigned char reg)
 {
        unsigned long flags;
        int data;
@@ -290,13 +312,13 @@ static inline int snd_es18xx_mixer_read(es18xx_t *chip, unsigned char reg)
        data = inb(chip->port + 0x05);
         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;
 }
 
 /* Return old value */
-static inline int snd_es18xx_mixer_bits(es18xx_t *chip, unsigned char reg,
+static inline int snd_es18xx_mixer_bits(struct snd_es18xx *chip, unsigned char reg,
                                        unsigned char mask, unsigned char val)
 {
        unsigned char old, new, oval;
@@ -309,14 +331,15 @@ static inline int snd_es18xx_mixer_bits(es18xx_t *chip, unsigned char reg,
                new = (old & ~mask) | (val & mask);
                outb(new, chip->port + 0x05);
 #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);
        return oval;
 }
 
-static inline int snd_es18xx_mixer_writable(es18xx_t *chip, unsigned char reg,
+static inline int snd_es18xx_mixer_writable(struct snd_es18xx *chip, unsigned char reg,
                                            unsigned char mask)
 {
        int old, expected, new;
@@ -329,13 +352,14 @@ static inline int snd_es18xx_mixer_writable(es18xx_t *chip, unsigned char reg,
        new = inb(chip->port + 0x05);
         spin_unlock_irqrestore(&chip->mixer_lock, flags);
 #ifdef REG_DEBUG
-       snd_printk("Mixer reg %02x was %02x, set to %02x, now is %02x\n", reg, old, expected, new);
+       snd_printk(KERN_DEBUG "Mixer reg %02x was %02x, set to %02x, now is %02x\n",
+                  reg, old, expected, new);
 #endif
        return expected == new;
 }
 
 
-static int snd_es18xx_reset(es18xx_t *chip)
+static int snd_es18xx_reset(struct snd_es18xx *chip)
 {
        int i;
         outb(0x03, chip->port + 0x06);
@@ -347,7 +371,7 @@ static int snd_es18xx_reset(es18xx_t *chip)
        return 0;
 }
 
-static int snd_es18xx_reset_fifo(es18xx_t *chip)
+static int snd_es18xx_reset_fifo(struct snd_es18xx *chip)
 {
         outb(0x02, chip->port + 0x06);
         inb(chip->port + 0x06);
@@ -355,7 +379,7 @@ static int snd_es18xx_reset_fifo(es18xx_t *chip)
        return 0;
 }
 
-static ratnum_t new_clocks[2] = {
+static struct snd_ratnum new_clocks[2] = {
        {
                .num = 793800,
                .den_min = 1,
@@ -370,12 +394,12 @@ static ratnum_t new_clocks[2] = {
        }
 };
 
-static snd_pcm_hw_constraint_ratnums_t new_hw_constraints_clocks = {
+static struct snd_pcm_hw_constraint_ratnums new_hw_constraints_clocks = {
        .nrats = 2,
        .rats = new_clocks,
 };
 
-static ratnum_t old_clocks[2] = {
+static struct snd_ratnum old_clocks[2] = {
        {
                .num = 795444,
                .den_min = 1,
@@ -390,18 +414,18 @@ static ratnum_t old_clocks[2] = {
        }
 };
 
-static snd_pcm_hw_constraint_ratnums_t old_hw_constraints_clocks  = {
+static struct snd_pcm_hw_constraint_ratnums old_hw_constraints_clocks  = {
        .nrats = 2,
        .rats = old_clocks,
 };
 
 
-static void snd_es18xx_rate_set(es18xx_t *chip, 
-                               snd_pcm_substream_t *substream,
+static void snd_es18xx_rate_set(struct snd_es18xx *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 (chip->caps & ES18XX_NEW_RATE) {
                if (runtime->rate_num == new_clocks[0].num)
                        bits = 128 - runtime->rate_den;
@@ -431,10 +455,10 @@ static void snd_es18xx_rate_set(es18xx_t *chip,
        }
 }
 
-static int snd_es18xx_playback_hw_params(snd_pcm_substream_t * substream,
-                                        snd_pcm_hw_params_t * hw_params)
+static int snd_es18xx_playback_hw_params(struct snd_pcm_substream *substream,
+                                        struct snd_pcm_hw_params *hw_params)
 {
-       es18xx_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        int shift, err;
 
        shift = 0;
@@ -459,15 +483,15 @@ static int snd_es18xx_playback_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_es18xx_pcm_hw_free(snd_pcm_substream_t * substream)
+static int snd_es18xx_pcm_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static int snd_es18xx_playback1_prepare(es18xx_t *chip,
-                                       snd_pcm_substream_t *substream)
+static int snd_es18xx_playback1_prepare(struct snd_es18xx *chip,
+                                       struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int size = snd_pcm_lib_buffer_bytes(substream);
        unsigned int count = snd_pcm_lib_period_bytes(substream);
 
@@ -492,8 +516,8 @@ static int snd_es18xx_playback1_prepare(es18xx_t *chip,
        return 0;
 }
 
-static int snd_es18xx_playback1_trigger(es18xx_t *chip,
-                                       snd_pcm_substream_t * substream,
+static int snd_es18xx_playback1_trigger(struct snd_es18xx *chip,
+                                       struct snd_pcm_substream *substream,
                                        int cmd)
 {
        switch (cmd) {
@@ -542,10 +566,10 @@ static int snd_es18xx_playback1_trigger(es18xx_t *chip,
        return 0;
 }
 
-static int snd_es18xx_capture_hw_params(snd_pcm_substream_t * substream,
-                                       snd_pcm_hw_params_t * hw_params)
+static int snd_es18xx_capture_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *hw_params)
 {
-       es18xx_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        int shift, err;
 
        shift = 0;
@@ -565,10 +589,10 @@ static int snd_es18xx_capture_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_es18xx_capture_prepare(snd_pcm_substream_t *substream)
+static int snd_es18xx_capture_prepare(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int size = snd_pcm_lib_buffer_bytes(substream);
        unsigned int count = snd_pcm_lib_period_bytes(substream);
 
@@ -598,16 +622,16 @@ static int snd_es18xx_capture_prepare(snd_pcm_substream_t *substream)
                          (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
                          (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
 
-        /* Set DMA controler */
+        /* Set DMA controller */
         snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_READ | DMA_AUTOINIT);
 
        return 0;
 }
 
-static int snd_es18xx_capture_trigger(snd_pcm_substream_t *substream,
+static int snd_es18xx_capture_trigger(struct snd_pcm_substream *substream,
                                      int cmd)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
@@ -633,10 +657,10 @@ static int snd_es18xx_capture_trigger(snd_pcm_substream_t *substream,
        return 0;
 }
 
-static int snd_es18xx_playback2_prepare(es18xx_t *chip,
-                                       snd_pcm_substream_t *substream)
+static int snd_es18xx_playback2_prepare(struct snd_es18xx *chip,
+                                       struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned int size = snd_pcm_lib_buffer_bytes(substream);
        unsigned int count = snd_pcm_lib_period_bytes(substream);
 
@@ -664,14 +688,14 @@ static int snd_es18xx_playback2_prepare(es18xx_t *chip,
                          (snd_pcm_format_width(runtime->format) == 16 ? 0x04 : 0x00) |
                          (snd_pcm_format_unsigned(runtime->format) ? 0x00 : 0x20));
 
-        /* Set DMA controler */
+        /* Set DMA controller */
         snd_dma_program(chip->dma1, runtime->dma_addr, size, DMA_MODE_WRITE | DMA_AUTOINIT);
 
        return 0;
 }
 
-static int snd_es18xx_playback2_trigger(es18xx_t *chip,
-                                       snd_pcm_substream_t *substream,
+static int snd_es18xx_playback2_trigger(struct snd_es18xx *chip,
+                                       struct snd_pcm_substream *substream,
                                        int cmd)
 {
        switch (cmd) {
@@ -710,28 +734,28 @@ static int snd_es18xx_playback2_trigger(es18xx_t *chip,
        return 0;
 }
 
-static int snd_es18xx_playback_prepare(snd_pcm_substream_t *substream)
+static int snd_es18xx_playback_prepare(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
                return snd_es18xx_playback1_prepare(chip, substream);
        else
                return snd_es18xx_playback2_prepare(chip, substream);
 }
 
-static int snd_es18xx_playback_trigger(snd_pcm_substream_t *substream,
+static int snd_es18xx_playback_trigger(struct snd_pcm_substream *substream,
                                       int cmd)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
                return snd_es18xx_playback1_trigger(chip, substream, cmd);
        else
                return snd_es18xx_playback2_trigger(chip, substream, cmd);
 }
 
-static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id)
 {
-       es18xx_t *chip = dev_id;
+       struct snd_es18xx *chip = dev_id;
        unsigned char status;
 
        if (chip->caps & ES18XX_CONTROL) {
@@ -774,13 +798,16 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *r
 
        /* MPU */
        if ((status & MPU_IRQ) && chip->rmidi)
-               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
+               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
 
        /* Hardware volume */
        if (status & HWV_IRQ) {
-               int split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
-               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);
+               int split = 0;
+               if (chip->caps & ES18XX_HWV) {
+                       split = snd_es18xx_mixer_read(chip, 0x64) & 0x80;
+                       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);
@@ -791,9 +818,9 @@ static irqreturn_t snd_es18xx_interrupt(int irq, void *dev_id, struct pt_regs *r
        return IRQ_HANDLED;
 }
 
-static snd_pcm_uframes_t snd_es18xx_playback_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_es18xx_playback_pointer(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        int pos;
 
        if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
@@ -809,9 +836,9 @@ static snd_pcm_uframes_t snd_es18xx_playback_pointer(snd_pcm_substream_t * subst
        }
 }
 
-static snd_pcm_uframes_t snd_es18xx_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_es18xx_capture_pointer(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
        int pos;
 
         if (!(chip->active & ADC1))
@@ -820,7 +847,7 @@ static snd_pcm_uframes_t snd_es18xx_capture_pointer(snd_pcm_substream_t * substr
        return pos >> chip->dma1_shift;
 }
 
-static snd_pcm_hardware_t snd_es18xx_playback =
+static struct snd_pcm_hardware snd_es18xx_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_RESUME |
@@ -840,7 +867,7 @@ static snd_pcm_hardware_t snd_es18xx_playback =
        .fifo_size =            0,
 };
 
-static snd_pcm_hardware_t snd_es18xx_capture =
+static struct snd_pcm_hardware snd_es18xx_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_RESUME |
@@ -860,10 +887,10 @@ static snd_pcm_hardware_t snd_es18xx_capture =
        .fifo_size =            0,
 };
 
-static int snd_es18xx_playback_open(snd_pcm_substream_t * substream)
+static int snd_es18xx_playback_open(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
 
        if (substream->number == 0 && (chip->caps & ES18XX_PCM2)) {
                if ((chip->caps & ES18XX_DUPLEX_MONO) &&
@@ -885,10 +912,10 @@ static int snd_es18xx_playback_open(snd_pcm_substream_t * substream)
         return 0;
 }
 
-static int snd_es18xx_capture_open(snd_pcm_substream_t * substream)
+static int snd_es18xx_capture_open(struct snd_pcm_substream *substream)
 {
-       snd_pcm_runtime_t *runtime = substream->runtime;
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
 
         if (chip->playback_b_substream)
                 return -EAGAIN;
@@ -903,9 +930,9 @@ static int snd_es18xx_capture_open(snd_pcm_substream_t * substream)
         return 0;
 }
 
-static int snd_es18xx_playback_close(snd_pcm_substream_t * substream)
+static int snd_es18xx_playback_close(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
 
        if (substream->number == 0 && (chip->caps & ES18XX_PCM2))
                chip->playback_a_substream = NULL;
@@ -916,9 +943,9 @@ static int snd_es18xx_playback_close(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_es18xx_capture_close(snd_pcm_substream_t * substream)
+static int snd_es18xx_capture_close(struct snd_pcm_substream *substream)
 {
-        es18xx_t *chip = snd_pcm_substream_chip(substream);
+        struct snd_es18xx *chip = snd_pcm_substream_chip(substream);
 
         chip->capture_a_substream = NULL;
        snd_pcm_lib_free_pages(substream);
@@ -929,59 +956,133 @@ static int snd_es18xx_capture_close(snd_pcm_substream_t * substream)
  *  MIXER part
  */
 
-static int snd_es18xx_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+/* Record source mux routines:
+ * Depending on the chipset this mux switches between 4, 5, or 8 possible inputs.
+ * bit table for the 4/5 source mux:
+ * reg 1C:
+ *  b2 b1 b0   muxSource
+ *   x  0  x   microphone
+ *   0  1  x   CD
+ *   1  1  0   line
+ *   1  1  1   mixer
+ * if it's "mixer" and it's a 5 source mux chipset then reg 7A bit 3 determines
+ * either the play mixer or the capture mixer.
+ *
+ * "map4Source" translates from source number to reg bit pattern
+ * "invMap4Source" translates from reg bit pattern to source number
+ */
+
+static int snd_es18xx_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
-       static char *texts[8] = {
+       static char *texts4Source[4] = {
+               "Mic", "CD", "Line", "Master"
+       };
+       static char *texts5Source[5] = {
+               "Mic", "CD", "Line", "Master", "Mix"
+       };
+       static char *texts8Source[8] = {
                "Mic", "Mic Master", "CD", "AOUT",
                "Mic1", "Mix", "Line", "Master"
        };
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
 
        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
        uinfo->count = 1;
-       uinfo->value.enumerated.items = 8;
-       if (uinfo->value.enumerated.item > 7)
-               uinfo->value.enumerated.item = 7;
-       strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+       switch (chip->version) {
+       case 0x1868:
+       case 0x1878:
+               uinfo->value.enumerated.items = 4;
+               if (uinfo->value.enumerated.item > 3)
+                       uinfo->value.enumerated.item = 3;
+               strcpy(uinfo->value.enumerated.name, texts4Source[uinfo->value.enumerated.item]);
+               break;
+       case 0x1887:
+       case 0x1888:
+               uinfo->value.enumerated.items = 5;
+               if (uinfo->value.enumerated.item > 4)
+                       uinfo->value.enumerated.item = 4;
+               strcpy(uinfo->value.enumerated.name, texts5Source[uinfo->value.enumerated.item]);
+               break;
+       case 0x1869: /* DS somewhat contradictory for 1869: could be be 5 or 8 */
+       case 0x1879:
+               uinfo->value.enumerated.items = 8;
+               if (uinfo->value.enumerated.item > 7)
+                       uinfo->value.enumerated.item = 7;
+               strcpy(uinfo->value.enumerated.name, texts8Source[uinfo->value.enumerated.item]);
+               break;
+       default:
+               return -EINVAL;
+       }
        return 0;
 }
 
-static int snd_es18xx_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
-       ucontrol->value.enumerated.item[0] = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
+       static unsigned char invMap4Source[8] = {0, 0, 1, 1, 0, 0, 2, 3};
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
+       int muxSource = snd_es18xx_mixer_read(chip, 0x1c) & 0x07;
+       if (!(chip->version == 0x1869 || chip->version == 0x1879)) {
+               muxSource = invMap4Source[muxSource];
+               if (muxSource==3 && 
+                   (chip->version == 0x1887 || chip->version == 0x1888) &&
+                   (snd_es18xx_mixer_read(chip, 0x7a) & 0x08)
+               ) 
+                       muxSource = 4;
+       }
+       ucontrol->value.enumerated.item[0] = muxSource;
        return 0;
 }
 
-static int snd_es18xx_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       static unsigned char map4Source[4] = {0, 2, 6, 7};
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        unsigned char val = ucontrol->value.enumerated.item[0];
-       
-       if (val > 7)
+       unsigned char retVal = 0;
+
+       switch (chip->version) {
+ /* 5 source chips */
+       case 0x1887:
+       case 0x1888:
+               if (val > 4)
+                       return -EINVAL;
+               if (val == 4) {
+                       retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x08) != 0x08;
+                       val = 3;
+               } else
+                       retVal = snd_es18xx_mixer_bits(chip, 0x7a, 0x08, 0x00) != 0x00;
+ /* 4 source chips */
+       case 0x1868:
+       case 0x1878:
+               if (val > 3)
+                       return -EINVAL;
+               val = map4Source[val];
+               break;
+ /* 8 source chips */
+       case 0x1869:
+       case 0x1879:
+               if (val > 7)
+                       return -EINVAL;
+               break;
+       default:
                return -EINVAL;
-       return snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val;
+       }
+       return (snd_es18xx_mixer_bits(chip, 0x1c, 0x07, val) != val) || retVal;
 }
 
-static int snd_es18xx_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_es18xx_info_spatializer_enable     snd_ctl_boolean_mono_info
 
-static int snd_es18xx_get_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        unsigned char val = snd_es18xx_mixer_read(chip, 0x50);
        ucontrol->value.integer.value[0] = !!(val & 8);
        return 0;
 }
 
-static int snd_es18xx_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_put_spatializer_enable(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        unsigned char oval, nval;
        int change;
        nval = ucontrol->value.integer.value[0] ? 0x0c : 0x04;
@@ -994,7 +1095,7 @@ static int snd_es18xx_put_spatializer_enable(snd_kcontrol_t * kcontrol, snd_ctl_
        return change;
 }
 
-static int snd_es18xx_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_es18xx_info_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
        uinfo->count = 2;
@@ -1003,41 +1104,34 @@ static int snd_es18xx_info_hw_volume(snd_kcontrol_t *kcontrol, snd_ctl_elem_info
        return 0;
 }
 
-static int snd_es18xx_get_hw_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_hw_volume(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        ucontrol->value.integer.value[0] = snd_es18xx_mixer_read(chip, 0x61) & 0x3f;
        ucontrol->value.integer.value[1] = snd_es18xx_mixer_read(chip, 0x63) & 0x3f;
        return 0;
 }
 
-static int snd_es18xx_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_es18xx_info_hw_switch      snd_ctl_boolean_stereo_info
 
-static int snd_es18xx_get_hw_switch(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_hw_switch(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        ucontrol->value.integer.value[0] = !(snd_es18xx_mixer_read(chip, 0x61) & 0x40);
        ucontrol->value.integer.value[1] = !(snd_es18xx_mixer_read(chip, 0x63) & 0x40);
        return 0;
 }
 
-static void snd_es18xx_hwv_free(snd_kcontrol_t *kcontrol)
+static void snd_es18xx_hwv_free(struct snd_kcontrol *kcontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *chip = snd_kcontrol_chip(kcontrol);
        chip->master_volume = NULL;
        chip->master_switch = NULL;
        chip->hw_volume = NULL;
        chip->hw_switch = NULL;
 }
 
-static int snd_es18xx_reg_bits(es18xx_t *chip, unsigned char reg,
+static int snd_es18xx_reg_bits(struct snd_es18xx *chip, unsigned char reg,
                               unsigned char mask, unsigned char val)
 {
        if (reg < 0xa0)
@@ -1046,7 +1140,7 @@ static int snd_es18xx_reg_bits(es18xx_t *chip, unsigned char reg,
                return snd_es18xx_bits(chip, reg, mask, val);
 }
 
-static int snd_es18xx_reg_read(es18xx_t *chip, unsigned char reg)
+static int snd_es18xx_reg_read(struct snd_es18xx *chip, unsigned char reg)
 {
        if (reg < 0xa0)
                return snd_es18xx_mixer_read(chip, reg);
@@ -1060,7 +1154,7 @@ static int snd_es18xx_reg_read(es18xx_t *chip, unsigned char reg)
   .get = snd_es18xx_get_single, .put = snd_es18xx_put_single, \
   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
 
-static int snd_es18xx_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_es18xx_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
 
@@ -1071,9 +1165,9 @@ static int snd_es18xx_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int snd_es18xx_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *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;
@@ -1087,9 +1181,9 @@ static int snd_es18xx_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_es18xx_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *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;
@@ -1110,7 +1204,7 @@ static int snd_es18xx_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
   .get = snd_es18xx_get_double, .put = snd_es18xx_put_double, \
   .private_value = left_reg | (right_reg << 8) | (shift_left << 16) | (shift_right << 19) | (mask << 24) | (invert << 22) }
 
-static int snd_es18xx_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_es18xx_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 24) & 0xff;
 
@@ -1121,9 +1215,9 @@ static int snd_es18xx_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int snd_es18xx_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *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;
@@ -1146,9 +1240,9 @@ static int snd_es18xx_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_es18xx_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_es18xx_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       es18xx_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_es18xx *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;
@@ -1181,19 +1275,22 @@ static int snd_es18xx_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return change;
 }
 
-static snd_kcontrol_new_t snd_es18xx_base_controls[] = {
+/* Mixer controls
+ * These arrays contain setup data for mixer controls.
+ * 
+ * The controls that are universal to all chipsets are fully initialized
+ * here.
+ */
+static struct snd_kcontrol_new snd_es18xx_base_controls[] = {
 ES18XX_DOUBLE("Master Playback Volume", 0, 0x60, 0x62, 0, 0, 63, 0),
 ES18XX_DOUBLE("Master Playback Switch", 0, 0x60, 0x62, 6, 6, 1, 1),
 ES18XX_DOUBLE("Line Playback Volume", 0, 0x3e, 0x3e, 4, 0, 15, 0),
 ES18XX_DOUBLE("CD Playback Volume", 0, 0x38, 0x38, 4, 0, 15, 0),
 ES18XX_DOUBLE("FM Playback Volume", 0, 0x36, 0x36, 4, 0, 15, 0),
-ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
 ES18XX_DOUBLE("Mic Playback Volume", 0, 0x1a, 0x1a, 4, 0, 15, 0),
 ES18XX_DOUBLE("Aux Playback Volume", 0, 0x3a, 0x3a, 4, 0, 15, 0),
-ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0),
 ES18XX_SINGLE("Record Monitor", 0, 0xa8, 3, 1, 0),
 ES18XX_DOUBLE("Capture Volume", 0, 0xb4, 0xb4, 4, 0, 15, 0),
-ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
 {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Capture Source",
@@ -1203,29 +1300,47 @@ ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
 }
 };
 
-static snd_kcontrol_new_t snd_es18xx_mono_in_control = 
-ES18XX_DOUBLE("Mono Input Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0);
-
-static snd_kcontrol_new_t snd_es18xx_recmix_controls[] = {
+static struct snd_kcontrol_new snd_es18xx_recmix_controls[] = {
 ES18XX_DOUBLE("PCM Capture Volume", 0, 0x69, 0x69, 4, 0, 15, 0),
 ES18XX_DOUBLE("Mic Capture Volume", 0, 0x68, 0x68, 4, 0, 15, 0),
 ES18XX_DOUBLE("Line Capture Volume", 0, 0x6e, 0x6e, 4, 0, 15, 0),
 ES18XX_DOUBLE("FM Capture Volume", 0, 0x6b, 0x6b, 4, 0, 15, 0),
-ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0),
 ES18XX_DOUBLE("CD Capture Volume", 0, 0x6a, 0x6a, 4, 0, 15, 0),
 ES18XX_DOUBLE("Aux Capture Volume", 0, 0x6c, 0x6c, 4, 0, 15, 0)
 };
 
-static snd_kcontrol_new_t snd_es18xx_pcm1_controls[] = {
+/*
+ * The chipset specific mixer controls
+ */
+static struct snd_kcontrol_new snd_es18xx_opt_speaker =
+       ES18XX_SINGLE("PC Speaker Playback Volume", 0, 0x3c, 0, 7, 0);
+
+static struct snd_kcontrol_new snd_es18xx_opt_1869[] = {
+ES18XX_SINGLE("Capture Switch", 0, 0x1c, 4, 1, 1),
+ES18XX_SINGLE("Video Playback Switch", 0, 0x7f, 0, 1, 0),
+ES18XX_DOUBLE("Mono Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
+ES18XX_DOUBLE("Mono Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
+};
+
+static struct snd_kcontrol_new snd_es18xx_opt_1878 =
+       ES18XX_DOUBLE("Video Playback Volume", 0, 0x68, 0x68, 4, 0, 15, 0);
+
+static struct snd_kcontrol_new snd_es18xx_opt_1879[] = {
+ES18XX_SINGLE("Video Playback Switch", 0, 0x71, 6, 1, 0),
+ES18XX_DOUBLE("Video Playback Volume", 0, 0x6d, 0x6d, 4, 0, 15, 0),
+ES18XX_DOUBLE("Video Capture Volume", 0, 0x6f, 0x6f, 4, 0, 15, 0)
+};
+
+static struct snd_kcontrol_new snd_es18xx_pcm1_controls[] = {
 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x14, 0x14, 4, 0, 15, 0),
 };
 
-static snd_kcontrol_new_t snd_es18xx_pcm2_controls[] = {
+static struct snd_kcontrol_new snd_es18xx_pcm2_controls[] = {
 ES18XX_DOUBLE("PCM Playback Volume", 0, 0x7c, 0x7c, 4, 0, 15, 0),
 ES18XX_DOUBLE("PCM Playback Volume", 1, 0x14, 0x14, 4, 0, 15, 0)
 };
 
-static snd_kcontrol_new_t snd_es18xx_spatializer_controls[] = {
+static struct snd_kcontrol_new snd_es18xx_spatializer_controls[] = {
 ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
 {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1236,13 +1351,13 @@ ES18XX_SINGLE("3D Control - Level", 0, 0x52, 0, 63, 0),
 }
 };
 
-static snd_kcontrol_new_t snd_es18xx_micpre1_control = 
+static struct snd_kcontrol_new snd_es18xx_micpre1_control = 
 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0xa9, 2, 1, 0);
 
-static snd_kcontrol_new_t snd_es18xx_micpre2_control =
+static struct snd_kcontrol_new snd_es18xx_micpre2_control =
 ES18XX_SINGLE("Mic Boost (+26dB)", 0, 0x7d, 3, 1, 0);
 
-static snd_kcontrol_new_t snd_es18xx_hw_volume_controls[] = {
+static struct snd_kcontrol_new snd_es18xx_hw_volume_controls[] = {
 {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .name = "Hardware Master Playback Volume",
@@ -1260,8 +1375,7 @@ static snd_kcontrol_new_t snd_es18xx_hw_volume_controls[] = {
 ES18XX_SINGLE("Hardware Master Volume Split", 0, 0x64, 7, 1, 0),
 };
 
-#if 0
-static int __devinit snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
+static int __devinit snd_es18xx_config_read(struct snd_es18xx *chip, unsigned char reg)
 {
        int data;
        unsigned long flags;
@@ -1271,9 +1385,8 @@ static int __devinit snd_es18xx_config_read(es18xx_t *chip, unsigned char reg)
         spin_unlock_irqrestore(&chip->ctrl_lock, flags);
        return data;
 }
-#endif
 
-static void __devinit snd_es18xx_config_write(es18xx_t *chip, 
+static void __devinit snd_es18xx_config_write(struct snd_es18xx *chip, 
                                              unsigned char reg, unsigned char data)
 {
        /* No need for spinlocks, this function is used only in
@@ -1281,11 +1394,11 @@ static void __devinit snd_es18xx_config_write(es18xx_t *chip,
        outb(reg, chip->ctrl_port);
        outb(data, chip->ctrl_port + 1);
 #ifdef REG_DEBUG
-       snd_printk("Config reg %02x set to %02x\n", reg, data);
+       snd_printk(KERN_DEBUG "Config reg %02x set to %02x\n", reg, data);
 #endif
 }
 
-static int __devinit snd_es18xx_initialize(es18xx_t *chip)
+static int __devinit snd_es18xx_initialize(struct snd_es18xx *chip)
 {
        int mask = 0;
 
@@ -1328,6 +1441,8 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
                snd_es18xx_write(chip, 0xB2, 0x50);
                /* Enable MPU and hardware volume interrupt */
                snd_es18xx_mixer_write(chip, 0x64, 0x42);
+               /* Enable ESS wavetable input */
+               snd_es18xx_mixer_bits(chip, 0x48, 0x10, 0x10);
        }
        else {
                int irqmask, dma1mask, dma2mask;
@@ -1346,7 +1461,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
                        irqmask = 3;
                        break;
                default:
-                       snd_printk("invalid irq %d\n", chip->irq);
+                       snd_printk(KERN_ERR "invalid irq %d\n", chip->irq);
                        return -ENODEV;
                }
                switch (chip->dma1) {
@@ -1360,7 +1475,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
                        dma1mask = 3;
                        break;
                default:
-                       snd_printk("invalid dma1 %d\n", chip->dma1);
+                       snd_printk(KERN_ERR "invalid dma1 %d\n", chip->dma1);
                        return -ENODEV;
                }
                switch (chip->dma2) {
@@ -1377,7 +1492,7 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
                        dma2mask = 3;
                        break;
                default:
-                       snd_printk("invalid dma2 %d\n", chip->dma2);
+                       snd_printk(KERN_ERR "invalid dma2 %d\n", chip->dma2);
                        return -ENODEV;
                }
 
@@ -1417,6 +1532,17 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
                snd_es18xx_mixer_write(chip, 0x58, 0x94);
                snd_es18xx_mixer_write(chip, 0x5a, 0x80);
        }
+       /* Flip the "enable I2S" bits for those chipsets that need it */
+       switch (chip->version) {
+       case 0x1879:
+               //Leaving I2S enabled on the 1879 screws up the PCM playback (rate effected somehow)
+               //so a Switch control has been added to toggle this 0x71 bit on/off:
+               //snd_es18xx_mixer_bits(chip, 0x71, 0x40, 0x40);
+               /* Note: we fall through on purpose here. */
+       case 0x1878:
+               snd_es18xx_config_write(chip, 0x29, snd_es18xx_config_read(chip, 0x29) | 0x40);
+               break;
+       }
        /* Mute input source */
        if (chip->caps & ES18XX_MUTEREC)
                mask = 0x10;
@@ -1434,13 +1560,13 @@ static int __devinit snd_es18xx_initialize(es18xx_t *chip)
         return 0;
 }
 
-static int __devinit snd_es18xx_identify(es18xx_t *chip)
+static int __devinit snd_es18xx_identify(struct snd_es18xx *chip)
 {
        int hi,lo;
 
        /* reset */
        if (snd_es18xx_reset(chip) < 0) {
-                snd_printk("reset at 0x%lx failed!!!\n", chip->port);
+               snd_printk(KERN_ERR "reset at 0x%lx failed!!!\n", chip->port);
                return -ENODEV;
        }
 
@@ -1466,11 +1592,14 @@ static int __devinit snd_es18xx_identify(es18xx_t *chip)
        }
                        
         outb(0x40, chip->port + 0x04);
+       udelay(10);
        hi = inb(chip->port + 0x05);
+       udelay(10);
        lo = inb(chip->port + 0x05);
        if (hi != lo) {
                chip->version = hi << 8 | lo;
                chip->ctrl_port = inb(chip->port + 0x05) << 8;
+               udelay(10);
                chip->ctrl_port += inb(chip->port + 0x05);
 
                if ((chip->res_ctrl_port = request_region(chip->ctrl_port, 8, "ES18xx - CTRL")) == NULL) {
@@ -1500,7 +1629,7 @@ static int __devinit snd_es18xx_identify(es18xx_t *chip)
        return 0;
 }
 
-static int __devinit snd_es18xx_probe(es18xx_t *chip)
+static int __devinit snd_es18xx_probe(struct snd_es18xx *chip)
 {
        if (snd_es18xx_identify(chip) < 0) {
                snd_printk(KERN_ERR PFX "[0x%lx] ESS chip not found\n", chip->port);
@@ -1509,25 +1638,25 @@ static int __devinit snd_es18xx_probe(es18xx_t *chip)
 
        switch (chip->version) {
        case 0x1868:
-               chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL | ES18XX_HWV;
+               chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_CONTROL;
                break;
        case 0x1869:
                chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_MONO | ES18XX_MUTEREC | ES18XX_CONTROL | ES18XX_HWV;
                break;
        case 0x1878:
-               chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
+               chip->caps = ES18XX_DUPLEX_MONO | ES18XX_DUPLEX_SAME | ES18XX_I2S | ES18XX_CONTROL;
                break;
        case 0x1879:
                chip->caps = ES18XX_PCM2 | ES18XX_SPATIALIZER | ES18XX_RECMIX | ES18XX_NEW_RATE | ES18XX_AUXB | ES18XX_I2S | ES18XX_CONTROL | ES18XX_HWV;
                break;
        case 0x1887:
-               chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
+               chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
                break;
        case 0x1888:
-               chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME | ES18XX_HWV;
+               chip->caps = ES18XX_PCM2 | ES18XX_RECMIX | ES18XX_AUXB | ES18XX_DUPLEX_SAME;
                break;
        default:
-                snd_printk("[0x%lx] unsupported chip ES%x\n",
+               snd_printk(KERN_ERR "[0x%lx] unsupported chip ES%x\n",
                            chip->port, chip->version);
                 return -ENODEV;
         }
@@ -1540,7 +1669,7 @@ static int __devinit snd_es18xx_probe(es18xx_t *chip)
         return snd_es18xx_initialize(chip);
 }
 
-static snd_pcm_ops_t snd_es18xx_playback_ops = {
+static struct snd_pcm_ops snd_es18xx_playback_ops = {
        .open =         snd_es18xx_playback_open,
        .close =        snd_es18xx_playback_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1551,7 +1680,7 @@ static snd_pcm_ops_t snd_es18xx_playback_ops = {
        .pointer =      snd_es18xx_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_es18xx_capture_ops = {
+static struct snd_pcm_ops snd_es18xx_capture_ops = {
        .open =         snd_es18xx_capture_open,
        .close =        snd_es18xx_capture_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1562,27 +1691,19 @@ static snd_pcm_ops_t snd_es18xx_capture_ops = {
        .pointer =      snd_es18xx_capture_pointer,
 };
 
-static void snd_es18xx_pcm_free(snd_pcm_t *pcm)
-{
-       es18xx_t *codec = pcm->private_data;
-       codec->pcm = NULL;
-       snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-static int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpcm)
+static int __devinit snd_es18xx_pcm(struct snd_es18xx *chip, int device, struct snd_pcm ** rpcm)
 {
-        snd_pcm_t *pcm;
+        struct snd_pcm *pcm;
        char str[16];
        int err;
 
        if (rpcm)
                *rpcm = NULL;
        sprintf(str, "ES%x", chip->version);
-       if (chip->caps & ES18XX_PCM2) {
+       if (chip->caps & ES18XX_PCM2)
                err = snd_pcm_new(chip->card, str, device, 2, 1, &pcm);
-       } else {
+       else
                err = snd_pcm_new(chip->card, str, device, 1, 1, &pcm);
-       }
         if (err < 0)
                 return err;
 
@@ -1591,7 +1712,6 @@ static int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpc
 
        /* global setup */
         pcm->private_data = chip;
-       pcm->private_free = snd_es18xx_pcm_free;
         pcm->info_flags = 0;
        if (chip->caps & ES18XX_DUPLEX_SAME)
                pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
@@ -1612,9 +1732,12 @@ static int __devinit snd_es18xx_pcm(es18xx_t *chip, int device, snd_pcm_t ** rpc
 
 /* Power Management support functions */
 #ifdef CONFIG_PM
-static int snd_es18xx_suspend(snd_card_t *card, pm_message_t state)
+static int snd_es18xx_suspend(struct snd_card *card, pm_message_t state)
 {
-       es18xx_t *chip = card->pm_private_data;
+       struct snd_audiodrive *acard = card->private_data;
+       struct snd_es18xx *chip = acard->chip;
+
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
 
        snd_pcm_suspend_all(chip->pcm);
 
@@ -1627,31 +1750,24 @@ static int snd_es18xx_suspend(snd_card_t *card, pm_message_t state)
        return 0;
 }
 
-static int snd_es18xx_resume(snd_card_t *card)
+static int snd_es18xx_resume(struct snd_card *card)
 {
-       es18xx_t *chip = card->pm_private_data;
+       struct snd_audiodrive *acard = card->private_data;
+       struct snd_es18xx *chip = acard->chip;
 
        /* restore PM register, we won't wake till (not 0x07) i/o activity though */
        snd_es18xx_write(chip, ES18XX_PM, chip->pm_reg ^= ES18XX_PM_FM);
 
+       snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0);
        return 0;
 }
 #endif /* CONFIG_PM */
 
-static int snd_es18xx_free(es18xx_t *chip)
+static int snd_es18xx_free(struct snd_es18xx *chip)
 {
-       if (chip->res_port) {
-               release_resource(chip->res_port);
-               kfree_nocheck(chip->res_port);
-       }
-       if (chip->res_ctrl_port) {
-               release_resource(chip->res_ctrl_port);
-               kfree_nocheck(chip->res_ctrl_port);
-       }
-       if (chip->res_mpu_port) {
-               release_resource(chip->res_mpu_port);
-               kfree_nocheck(chip->res_mpu_port);
-       }
+       release_and_free_resource(chip->res_port);
+       release_and_free_resource(chip->res_ctrl_port);
+       release_and_free_resource(chip->res_mpu_port);
        if (chip->irq >= 0)
                free_irq(chip->irq, (void *) chip);
        if (chip->dma1 >= 0) {
@@ -1666,27 +1782,27 @@ static int snd_es18xx_free(es18xx_t *chip)
        return 0;
 }
 
-static int snd_es18xx_dev_free(snd_device_t *device)
+static int snd_es18xx_dev_free(struct snd_device *device)
 {
-       es18xx_t *chip = device->device_data;
+       struct snd_es18xx *chip = device->device_data;
        return snd_es18xx_free(chip);
 }
 
-static int __devinit snd_es18xx_new_device(snd_card_t * card,
+static int __devinit snd_es18xx_new_device(struct snd_card *card,
                                           unsigned long port,
                                           unsigned long mpu_port,
                                           unsigned long fm_port,
                                           int irq, int dma1, int dma2,
-                                          es18xx_t ** rchip)
+                                          struct snd_es18xx ** rchip)
 {
-        es18xx_t *chip;
-       static snd_device_ops_t ops = {
+        struct snd_es18xx *chip;
+       static struct snd_device_ops ops = {
                .dev_free =     snd_es18xx_dev_free,
         };
        int err;
 
        *rchip = NULL;
-        chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
+        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
        if (chip == NULL)
                return -ENOMEM;
        spin_lock_init(&chip->reg_lock);
@@ -1708,7 +1824,7 @@ static int __devinit snd_es18xx_new_device(snd_card_t * card,
                return -EBUSY;
        }
 
-       if (request_irq(irq, snd_es18xx_interrupt, SA_INTERRUPT, "ES18xx", (void *) chip)) {
+       if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", (void *) chip)) {
                snd_es18xx_free(chip);
                snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
                return -EBUSY;
@@ -1741,9 +1857,9 @@ static int __devinit snd_es18xx_new_device(snd_card_t * card,
         return 0;
 }
 
-static int __devinit snd_es18xx_mixer(es18xx_t *chip)
+static int __devinit snd_es18xx_mixer(struct snd_es18xx *chip)
 {
-       snd_card_t *card;
+       struct snd_card *card;
        int err;
        unsigned int idx;
 
@@ -1752,7 +1868,7 @@ static int __devinit snd_es18xx_mixer(es18xx_t *chip)
        strcpy(card->mixername, chip->pcm->name);
 
        for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_base_controls); idx++) {
-               snd_kcontrol_t *kctl;
+               struct snd_kcontrol *kctl;
                kctl = snd_ctl_new1(&snd_es18xx_base_controls[idx], chip);
                if (chip->caps & ES18XX_HWV) {
                        switch (idx) {
@@ -1781,10 +1897,6 @@ static int __devinit snd_es18xx_mixer(es18xx_t *chip)
                }
        }
 
-       if (chip->caps & ES18XX_MONO) {
-               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_mono_in_control, chip))) < 0)
-                       return err;
-       }
        if (chip->caps & ES18XX_RECMIX) {
                for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_recmix_controls); idx++) {
                        if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_recmix_controls[idx], chip))) < 0)
@@ -1810,7 +1922,7 @@ static int __devinit snd_es18xx_mixer(es18xx_t *chip)
        }
        if (chip->caps & ES18XX_HWV) {
                for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_hw_volume_controls); idx++) {
-                       snd_kcontrol_t *kctl;
+                       struct snd_kcontrol *kctl;
                        kctl = snd_ctl_new1(&snd_es18xx_hw_volume_controls[idx], chip);
                        if (idx == 0)
                                chip->hw_volume = kctl;
@@ -1822,6 +1934,36 @@ static int __devinit snd_es18xx_mixer(es18xx_t *chip)
                        
                }
        }
+       /* finish initializing other chipset specific controls
+        */
+       if (chip->version != 0x1868) {
+               err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_speaker,
+                                                    chip));
+               if (err < 0)
+                       return err;
+       }
+       if (chip->version == 0x1869) {
+               for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1869); idx++) {
+                       err = snd_ctl_add(card,
+                                         snd_ctl_new1(&snd_es18xx_opt_1869[idx],
+                                                      chip));
+                       if (err < 0)
+                               return err;
+               }
+       } else if (chip->version == 0x1878) {
+               err = snd_ctl_add(card, snd_ctl_new1(&snd_es18xx_opt_1878,
+                                                    chip));
+               if (err < 0)
+                       return err;
+       } else if (chip->version == 0x1879) {
+               for (idx = 0; idx < ARRAY_SIZE(snd_es18xx_opt_1879); idx++) {
+                       err = snd_ctl_add(card,
+                                         snd_ctl_new1(&snd_es18xx_opt_1879[idx],
+                                                      chip));
+                       if (err < 0)
+                               return err;
+               }
+       }
        return 0;
 }
        
@@ -1880,16 +2022,55 @@ MODULE_PARM_DESC(dma1, "DMA 1 # for ES18xx driver.");
 module_param_array(dma2, int, NULL, 0444);
 MODULE_PARM_DESC(dma2, "DMA 2 # for ES18xx driver.");
 
-struct snd_audiodrive {
 #ifdef CONFIG_PNP
-       struct pnp_dev *dev;
-       struct pnp_dev *devc;
-#endif
+static int isa_registered;
+static int pnp_registered;
+static int pnpc_registered;
+
+static struct pnp_device_id snd_audiodrive_pnpbiosids[] = {
+       { .id = "ESS1869" },
+       { .id = "ESS1879" },
+       { .id = "" }            /* end */
 };
 
-static snd_card_t *snd_audiodrive_legacy[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
+MODULE_DEVICE_TABLE(pnp, snd_audiodrive_pnpbiosids);
 
-#ifdef CONFIG_PNP
+/* PnP main device initialization */
+static int __devinit snd_audiodrive_pnp_init_main(int dev, struct pnp_dev *pdev)
+{
+       if (pnp_activate_dev(pdev) < 0) {
+               snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
+               return -EBUSY;
+       }
+       /* ok. hack using Vendor-Defined Card-Level registers */
+       /* skip csn and logdev initialization - already done in isapnp_configure */
+       if (pnp_device_is_isapnp(pdev)) {
+               isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
+               isapnp_write_byte(0x27, pnp_irq(pdev, 0));      /* Hardware Volume IRQ Number */
+               if (mpu_port[dev] != SNDRV_AUTO_PORT)
+                       isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
+               isapnp_write_byte(0x72, pnp_irq(pdev, 0));      /* second IRQ */
+               isapnp_cfg_end();
+       }
+       port[dev] = pnp_port_start(pdev, 0);
+       fm_port[dev] = pnp_port_start(pdev, 1);
+       mpu_port[dev] = pnp_port_start(pdev, 2);
+       dma1[dev] = pnp_dma(pdev, 0);
+       dma2[dev] = pnp_dma(pdev, 1);
+       irq[dev] = pnp_irq(pdev, 0);
+       snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
+       snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
+       return 0;
+}
+
+static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
+                                       struct pnp_dev *pdev)
+{
+       acard->dev = pdev;
+       if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0)
+               return -EBUSY;
+       return 0;
+}
 
 static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
        /* ESS 1868 (integrated on Compaq dual P-Pro motherboard and Genius 18PnP 3D) */
@@ -1912,78 +2093,28 @@ static struct pnp_card_device_id snd_audiodrive_pnpids[] = {
 
 MODULE_DEVICE_TABLE(pnp_card, snd_audiodrive_pnpids);
 
-static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
+static int __devinit snd_audiodrive_pnpc(int dev, struct snd_audiodrive *acard,
                                        struct pnp_card_link *card,
                                        const struct pnp_card_device_id *id)
 {
-       struct pnp_dev *pdev;
-       struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
-       int err;
-
-       if (!cfg)
-               return -ENOMEM;
        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
-       if (acard->dev == NULL) {
-               kfree(cfg);
+       if (acard->dev == NULL)
                return -EBUSY;
-       }
+
        acard->devc = pnp_request_card_device(card, id->devs[1].id, NULL);
-       if (acard->devc == NULL) {
-               kfree(cfg);
+       if (acard->devc == NULL)
                return -EBUSY;
-       }
+
        /* Control port initialization */
-       err = pnp_activate_dev(acard->devc);
-       if (err < 0) {
+       if (pnp_activate_dev(acard->devc) < 0) {
                snd_printk(KERN_ERR PFX "PnP control configure failure (out of resources?)\n");
                return -EAGAIN;
        }
-       snd_printdd("pnp: port=0x%lx\n", pnp_port_start(acard->devc, 0));
-       /* PnP initialization */
-       pdev = acard->dev;
-       pnp_init_resource_table(cfg);
-       if (port[dev] != SNDRV_AUTO_PORT)
-               pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
-       if (fm_port[dev] != SNDRV_AUTO_PORT)
-               pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
-       if (mpu_port[dev] != SNDRV_AUTO_PORT)
-               pnp_resource_change(&cfg->port_resource[2], mpu_port[dev], 2);
-       if (dma1[dev] != SNDRV_AUTO_DMA)
-               pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
-       if (dma2[dev] != SNDRV_AUTO_DMA)
-               pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
-       if (irq[dev] != SNDRV_AUTO_IRQ)
-               pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
-       err = pnp_manual_config_dev(pdev, cfg, 0);
-       if (err < 0)
-               snd_printk(KERN_ERR PFX "PnP manual resources are invalid, using auto config\n");
-       err = pnp_activate_dev(pdev);
-       if (err < 0) {
-               snd_printk(KERN_ERR PFX "PnP configure failure (out of resources?)\n");
-               kfree(cfg);
+       snd_printdd("pnp: port=0x%llx\n",
+                       (unsigned long long)pnp_port_start(acard->devc, 0));
+       if (snd_audiodrive_pnp_init_main(dev, acard->dev) < 0)
                return -EBUSY;
-       }
-       /* ok. hack using Vendor-Defined Card-Level registers */
-       /* skip csn and logdev initialization - already done in isapnp_configure */
-       if (pnp_device_is_isapnp(pdev)) {
-               isapnp_cfg_begin(isapnp_card_number(pdev), isapnp_csn_number(pdev));
-               isapnp_write_byte(0x27, pnp_irq(pdev, 0));      /* Hardware Volume IRQ Number */
-               if (mpu_port[dev] != SNDRV_AUTO_PORT)
-                       isapnp_write_byte(0x28, pnp_irq(pdev, 0)); /* MPU-401 IRQ Number */
-               isapnp_write_byte(0x72, pnp_irq(pdev, 0));      /* second IRQ */
-               isapnp_cfg_end();
-       } else {
-               snd_printk(KERN_ERR PFX "unable to install ISA PnP hack, expect malfunction\n");
-       }
-       port[dev] = pnp_port_start(pdev, 0);
-       fm_port[dev] = pnp_port_start(pdev, 1);
-       mpu_port[dev] = pnp_port_start(pdev, 2);
-       dma1[dev] = pnp_dma(pdev, 0);
-       dma2[dev] = pnp_dma(pdev, 1);
-       irq[dev] = pnp_irq(pdev, 0);
-       snd_printdd("PnP ES18xx: port=0x%lx, fm port=0x%lx, mpu port=0x%lx\n", port[dev], fm_port[dev], mpu_port[dev]);
-       snd_printdd("PnP ES18xx: dma1=%i, dma2=%i, irq=%i\n", dma1[dev], dma2[dev], irq[dev]);
-       kfree(cfg);
+
        return 0;
 }
 #endif /* CONFIG_PNP */
@@ -1994,227 +2125,327 @@ static int __devinit snd_audiodrive_pnp(int dev, struct snd_audiodrive *acard,
 #define is_isapnp_selected(dev)                0
 #endif
 
-static int __devinit snd_audiodrive_probe(int dev, struct pnp_card_link *pcard,
-                                         const struct pnp_card_device_id *pid)
+static int snd_es18xx_card_new(int dev, struct snd_card **cardp)
 {
-       static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
-       static int possible_dmas[] = {1, 0, 3, 5, -1};
-       int xirq, xdma1, xdma2;
-       snd_card_t *card;
-       struct snd_audiodrive *acard;
-       es18xx_t *chip;
-       opl3_t *opl3;
-       int err;
-
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE,
-                           sizeof(struct snd_audiodrive));
-       if (card == NULL)
-               return -ENOMEM;
-       acard = (struct snd_audiodrive *)card->private_data;
-#ifdef CONFIG_PNP
-       if (isapnp[dev]) {
-               if ((err = snd_audiodrive_pnp(dev, acard, pcard, pid)) < 0) {
-                       snd_card_free(card);
-                       return err;
-               }
-               snd_card_set_dev(card, &pcard->card->dev);
-       }
-#endif
+       return snd_card_create(index[dev], id[dev], THIS_MODULE,
+                              sizeof(struct snd_audiodrive), cardp);
+}
 
-       xirq = irq[dev];
-       if (xirq == SNDRV_AUTO_IRQ) {
-               if ((xirq = snd_legacy_find_free_irq(possible_irqs)) < 0) {
-                       snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
-                       err = -EBUSY;
-                       goto _err;
-               }
-       }
-       xdma1 = dma1[dev];
-        if (xdma1 == SNDRV_AUTO_DMA) {
-                if ((xdma1 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
-                       snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
-                       err = -EBUSY;
-                       goto _err;
-                }
-        }
-       xdma2 = dma2[dev];
-        if (xdma2 == SNDRV_AUTO_DMA) {
-                if ((xdma2 = snd_legacy_find_free_dma(possible_dmas)) < 0) {
-                       snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
-                       err = -EBUSY;
-                       goto _err;
-                }
-        }
+static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
+{
+       struct snd_audiodrive *acard = card->private_data;
+       struct snd_es18xx *chip;
+       struct snd_opl3 *opl3;
+       int err;
 
        if ((err = snd_es18xx_new_device(card,
                                         port[dev],
                                         mpu_port[dev],
                                         fm_port[dev],
-                                        xirq, xdma1, xdma2,
+                                        irq[dev], dma1[dev], dma2[dev],
                                         &chip)) < 0)
-               goto _err;
+               return err;
+       acard->chip = chip;
 
        sprintf(card->driver, "ES%x", chip->version);
+       
        sprintf(card->shortname, "ESS AudioDrive ES%x", chip->version);
-       if (xdma1 != xdma2)
+       if (dma1[dev] != dma2[dev])
                sprintf(card->longname, "%s at 0x%lx, irq %d, dma1 %d, dma2 %d",
                        card->shortname,
                        chip->port,
-                       xirq, xdma1, xdma2);
+                       irq[dev], dma1[dev], dma2[dev]);
        else
                sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
                        card->shortname,
                        chip->port,
-                       xirq, xdma1);
+                       irq[dev], dma1[dev]);
 
        if ((err = snd_es18xx_pcm(chip, 0, NULL)) < 0)
-               goto _err;
+               return err;
 
        if ((err = snd_es18xx_mixer(chip)) < 0)
-               goto _err;
+               return err;
 
        if (fm_port[dev] > 0 && fm_port[dev] != SNDRV_AUTO_PORT) {
                if (snd_opl3_create(card, chip->fm_port, chip->fm_port + 2, OPL3_HW_OPL3, 0, &opl3) < 0) {
                        snd_printk(KERN_WARNING PFX "opl3 not detected at 0x%lx\n", chip->fm_port);
                } else {
                        if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0)
-                               goto _err;
+                               return err;
                }
        }
 
        if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
                                               chip->mpu_port, 0,
-                                              xirq, 0,
+                                              irq[dev], 0,
                                               &chip->rmidi)) < 0)
-                       goto _err;
+                       return err;
        }
 
-       if ((err = snd_card_set_generic_dev(card)) < 0)
-               goto _err;
+       return snd_card_register(card);
+}
 
-       /* Power Management */
-       snd_card_set_isa_pm_callback(card, snd_es18xx_suspend, snd_es18xx_resume, chip);
+static int __devinit snd_es18xx_isa_match(struct device *pdev, unsigned int dev)
+{
+       return enable[dev] && !is_isapnp_selected(dev);
+}
 
-       if ((err = snd_card_register(card)) < 0)
-               goto _err;
+static int __devinit snd_es18xx_isa_probe1(int dev, struct device *devptr)
+{
+       struct snd_card *card;
+       int err;
 
-       if (pcard)
-               pnp_set_card_drvdata(pcard, card);
-       else
-               snd_audiodrive_legacy[dev] = card;
+       err = snd_es18xx_card_new(dev, &card);
+       if (err < 0)
+               return err;
+       snd_card_set_dev(card, devptr);
+       if ((err = snd_audiodrive_probe(card, dev)) < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       dev_set_drvdata(devptr, card);
        return 0;
+}
 
- _err:
-       snd_card_free(card);
-       return err;
+static int __devinit snd_es18xx_isa_probe(struct device *pdev, unsigned int dev)
+{
+       int err;
+       static int possible_irqs[] = {5, 9, 10, 7, 11, 12, -1};
+       static int possible_dmas[] = {1, 0, 3, 5, -1};
+
+       if (irq[dev] == SNDRV_AUTO_IRQ) {
+               if ((irq[dev] = snd_legacy_find_free_irq(possible_irqs)) < 0) {
+                       snd_printk(KERN_ERR PFX "unable to find a free IRQ\n");
+                       return -EBUSY;
+               }
+       }
+       if (dma1[dev] == SNDRV_AUTO_DMA) {
+               if ((dma1[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+                       snd_printk(KERN_ERR PFX "unable to find a free DMA1\n");
+                       return -EBUSY;
+               }
+       }
+       if (dma2[dev] == SNDRV_AUTO_DMA) {
+               if ((dma2[dev] = snd_legacy_find_free_dma(possible_dmas)) < 0) {
+                       snd_printk(KERN_ERR PFX "unable to find a free DMA2\n");
+                       return -EBUSY;
+               }
+       }
+
+       if (port[dev] != SNDRV_AUTO_PORT) {
+               return snd_es18xx_isa_probe1(dev, pdev);
+       } else {
+               static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280};
+               int i;
+               for (i = 0; i < ARRAY_SIZE(possible_ports); i++) {
+                       port[dev] = possible_ports[i];
+                       err = snd_es18xx_isa_probe1(dev, pdev);
+                       if (! err)
+                               return 0;
+               }
+               return err;
+       }
+}
+
+static int __devexit snd_es18xx_isa_remove(struct device *devptr,
+                                          unsigned int dev)
+{
+       snd_card_free(dev_get_drvdata(devptr));
+       dev_set_drvdata(devptr, NULL);
+       return 0;
+}
+
+#ifdef CONFIG_PM
+static int snd_es18xx_isa_suspend(struct device *dev, unsigned int n,
+                                 pm_message_t state)
+{
+       return snd_es18xx_suspend(dev_get_drvdata(dev), state);
+}
+
+static int snd_es18xx_isa_resume(struct device *dev, unsigned int n)
+{
+       return snd_es18xx_resume(dev_get_drvdata(dev));
 }
+#endif
+
+#define DEV_NAME "es18xx"
 
-static int __devinit snd_audiodrive_probe_legacy_port(unsigned long xport)
+static struct isa_driver snd_es18xx_isa_driver = {
+       .match          = snd_es18xx_isa_match,
+       .probe          = snd_es18xx_isa_probe,
+       .remove         = __devexit_p(snd_es18xx_isa_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_es18xx_isa_suspend,
+       .resume         = snd_es18xx_isa_resume,
+#endif
+       .driver         = {
+               .name   = DEV_NAME
+       },
+};
+
+
+#ifdef CONFIG_PNP
+static int __devinit snd_audiodrive_pnp_detect(struct pnp_dev *pdev,
+                                           const struct pnp_device_id *id)
 {
        static int dev;
-       int res;
+       int err;
+       struct snd_card *card;
 
-       for ( ; dev < SNDRV_CARDS; dev++) {
-               if (!enable[dev] || port[dev] != SNDRV_AUTO_PORT)
-                       continue;
-               if (is_isapnp_selected(dev))
-                       continue;
-               port[dev] = xport;
-               res = snd_audiodrive_probe(dev, NULL, NULL);
-               if (res < 0)
-                       port[dev] = SNDRV_AUTO_PORT;
-               return res;
+       if (pnp_device_is_isapnp(pdev))
+               return -ENOENT; /* we have another procedure - card */
+       for (; dev < SNDRV_CARDS; dev++) {
+               if (enable[dev] && isapnp[dev])
+                       break;
+       }
+       if (dev >= SNDRV_CARDS)
+               return -ENODEV;
+
+       err = snd_es18xx_card_new(dev, &card);
+       if (err < 0)
+               return err;
+       if ((err = snd_audiodrive_pnp(dev, card->private_data, pdev)) < 0) {
+               snd_card_free(card);
+               return err;
        }
-       return -ENODEV;
+       snd_card_set_dev(card, &pdev->dev);
+       if ((err = snd_audiodrive_probe(card, dev)) < 0) {
+               snd_card_free(card);
+               return err;
+       }
+       pnp_set_drvdata(pdev, card);
+       dev++;
+       return 0;
 }
 
+static void __devexit snd_audiodrive_pnp_remove(struct pnp_dev * pdev)
+{
+       snd_card_free(pnp_get_drvdata(pdev));
+       pnp_set_drvdata(pdev, NULL);
+}
 
-#ifdef CONFIG_PNP
-static int __devinit snd_audiodrive_pnp_detect(struct pnp_card_link *card,
-                                              const struct pnp_card_device_id *id)
+#ifdef CONFIG_PM
+static int snd_audiodrive_pnp_suspend(struct pnp_dev *pdev, pm_message_t state)
+{
+       return snd_es18xx_suspend(pnp_get_drvdata(pdev), state);
+}
+static int snd_audiodrive_pnp_resume(struct pnp_dev *pdev)
+{
+       return snd_es18xx_resume(pnp_get_drvdata(pdev));
+}
+#endif
+
+static struct pnp_driver es18xx_pnp_driver = {
+       .name = "es18xx-pnpbios",
+       .id_table = snd_audiodrive_pnpbiosids,
+       .probe = snd_audiodrive_pnp_detect,
+       .remove = __devexit_p(snd_audiodrive_pnp_remove),
+#ifdef CONFIG_PM
+       .suspend = snd_audiodrive_pnp_suspend,
+       .resume = snd_audiodrive_pnp_resume,
+#endif
+};
+
+static int __devinit snd_audiodrive_pnpc_detect(struct pnp_card_link *pcard,
+                                              const struct pnp_card_device_id *pid)
 {
        static int dev;
+       struct snd_card *card;
        int res;
 
        for ( ; dev < SNDRV_CARDS; dev++) {
-               if (!enable[dev] || !isapnp[dev])
-                       continue;
-                res = snd_audiodrive_probe(dev, card, id);
-               if (res < 0)
-                       return res;
-               dev++;
-               return 0;
-        }
+               if (enable[dev] && isapnp[dev])
+                       break;
+       }
+       if (dev >= SNDRV_CARDS)
+               return -ENODEV;
 
-        return -ENODEV;
+       res = snd_es18xx_card_new(dev, &card);
+       if (res < 0)
+               return res;
+
+       if ((res = snd_audiodrive_pnpc(dev, card->private_data, pcard, pid)) < 0) {
+               snd_card_free(card);
+               return res;
+       }
+       snd_card_set_dev(card, &pcard->card->dev);
+       if ((res = snd_audiodrive_probe(card, dev)) < 0) {
+               snd_card_free(card);
+               return res;
+       }
+
+       pnp_set_card_drvdata(pcard, card);
+       dev++;
+       return 0;
+}
+
+static void __devexit snd_audiodrive_pnpc_remove(struct pnp_card_link * pcard)
+{
+       snd_card_free(pnp_get_card_drvdata(pcard));
+       pnp_set_card_drvdata(pcard, NULL);
 }
 
-static void __devexit snd_audiodrive_pnp_remove(struct pnp_card_link * pcard)
+#ifdef CONFIG_PM
+static int snd_audiodrive_pnpc_suspend(struct pnp_card_link *pcard, pm_message_t state)
 {
-       snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
+       return snd_es18xx_suspend(pnp_get_card_drvdata(pcard), state);
+}
 
-       snd_card_disconnect(card);
-       snd_card_free_in_thread(card);
+static int snd_audiodrive_pnpc_resume(struct pnp_card_link *pcard)
+{
+       return snd_es18xx_resume(pnp_get_card_drvdata(pcard));
 }
 
+#endif
+
 static struct pnp_card_driver es18xx_pnpc_driver = {
        .flags = PNP_DRIVER_RES_DISABLE,
        .name = "es18xx",
        .id_table = snd_audiodrive_pnpids,
-       .probe = snd_audiodrive_pnp_detect,
-       .remove = __devexit_p(snd_audiodrive_pnp_remove),
+       .probe = snd_audiodrive_pnpc_detect,
+       .remove = __devexit_p(snd_audiodrive_pnpc_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_audiodrive_pnpc_suspend,
+       .resume         = snd_audiodrive_pnpc_resume,
+#endif
 };
 #endif /* CONFIG_PNP */
 
 static int __init alsa_card_es18xx_init(void)
 {
-       static unsigned long possible_ports[] = {0x220, 0x240, 0x260, 0x280, -1};
-       int dev, cards = 0, i;
-
-       /* legacy non-auto cards at first */
-       for (dev = 0; dev < SNDRV_CARDS; dev++) {
-               if (!enable[dev] || port[dev] == SNDRV_AUTO_PORT)
-                       continue;
-               if (is_isapnp_selected(dev))
-                       continue;
-               if (snd_audiodrive_probe(dev, NULL, NULL) >= 0)
-                       cards++;
-       }
-       /* legacy auto configured cards */
-       i = snd_legacy_auto_probe(possible_ports, snd_audiodrive_probe_legacy_port);
-       if (i > 0)
-               cards += i;
+       int err;
 
+       err = isa_register_driver(&snd_es18xx_isa_driver, SNDRV_CARDS);
 #ifdef CONFIG_PNP
-       /* ISA PnP cards at last */
-       i = pnp_register_card_driver(&es18xx_pnpc_driver);
-       if (i > 0)
-               cards += i;
+       if (!err)
+               isa_registered = 1;
 
+       err = pnp_register_driver(&es18xx_pnp_driver);
+       if (!err)
+               pnp_registered = 1;
+
+       err = pnp_register_card_driver(&es18xx_pnpc_driver);
+       if (!err)
+               pnpc_registered = 1;
+
+       if (isa_registered || pnp_registered)
+               err = 0;
 #endif
-       if(!cards) {
-#ifdef CONFIG_PNP
-               pnp_unregister_card_driver(&es18xx_pnpc_driver);
-#endif
-#ifdef MODULE
-               snd_printk(KERN_ERR "ESS AudioDrive ES18xx soundcard not found or device busy\n");
-#endif
-               return -ENODEV;
-       }
-       return 0;
+       return err;
 }
 
 static void __exit alsa_card_es18xx_exit(void)
 {
-       int idx;
-
 #ifdef CONFIG_PNP
-       /* PnP cards first */
-       pnp_unregister_card_driver(&es18xx_pnpc_driver);
+       if (pnpc_registered)
+               pnp_unregister_card_driver(&es18xx_pnpc_driver);
+       if (pnp_registered)
+               pnp_unregister_driver(&es18xx_pnp_driver);
+       if (isa_registered)
 #endif
-       for(idx = 0; idx < SNDRV_CARDS; idx++)
-               snd_card_free(snd_audiodrive_legacy[idx]);
+               isa_unregister_driver(&snd_es18xx_isa_driver);
 }
 
 module_init(alsa_card_es18xx_init)