Merge branch 'sched/for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tip...
[pandora-kernel.git] / sound / isa / cs423x / cs4231_lib.c
index 3231825..521db70 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
+ *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
  *  Routines for control of CS4231(A)/CS4232/InterWave & compatible chips
  *
  *  Bugs:
@@ -24,7 +24,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <linux/delay.h>
 #include <linux/pm.h>
 #include <linux/init.h>
@@ -39,7 +38,7 @@
 #include <asm/dma.h>
 #include <asm/irq.h>
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("Routines for control of CS4231(A)/CS4232/InterWave & compatible chips");
 MODULE_LICENSE("GPL");
 
@@ -73,13 +72,13 @@ static unsigned int rates[14] = {
        27042, 32000, 33075, 37800, 44100, 48000
 };
 
-static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
-       .count = 14,
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
+       .count = ARRAY_SIZE(rates),
        .list = rates,
        .mask = 0,
 };
 
-static int snd_cs4231_xrate(snd_pcm_runtime_t *runtime)
+static int snd_cs4231_xrate(struct snd_pcm_runtime *runtime)
 {
        return snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
 }
@@ -120,80 +119,86 @@ static unsigned char snd_cs4231_original_image[32] =
        0x00,                   /* 1f/31 - cbrl */
 };
 
+static unsigned char snd_opti93x_original_image[32] =
+{
+       0x00,           /* 00/00 - l_mixout_outctrl */
+       0x00,           /* 01/01 - r_mixout_outctrl */
+       0x88,           /* 02/02 - l_cd_inctrl */
+       0x88,           /* 03/03 - r_cd_inctrl */
+       0x88,           /* 04/04 - l_a1/fm_inctrl */
+       0x88,           /* 05/05 - r_a1/fm_inctrl */
+       0x80,           /* 06/06 - l_dac_inctrl */
+       0x80,           /* 07/07 - r_dac_inctrl */
+       0x00,           /* 08/08 - ply_dataform_reg */
+       0x00,           /* 09/09 - if_conf */
+       0x00,           /* 0a/10 - pin_ctrl */
+       0x00,           /* 0b/11 - err_init_reg */
+       0x0a,           /* 0c/12 - id_reg */
+       0x00,           /* 0d/13 - reserved */
+       0x00,           /* 0e/14 - ply_upcount_reg */
+       0x00,           /* 0f/15 - ply_lowcount_reg */
+       0x88,           /* 10/16 - reserved/l_a1_inctrl */
+       0x88,           /* 11/17 - reserved/r_a1_inctrl */
+       0x88,           /* 12/18 - l_line_inctrl */
+       0x88,           /* 13/19 - r_line_inctrl */
+       0x88,           /* 14/20 - l_mic_inctrl */
+       0x88,           /* 15/21 - r_mic_inctrl */
+       0x80,           /* 16/22 - l_out_outctrl */
+       0x80,           /* 17/23 - r_out_outctrl */
+       0x00,           /* 18/24 - reserved */
+       0x00,           /* 19/25 - reserved */
+       0x00,           /* 1a/26 - reserved */
+       0x00,           /* 1b/27 - reserved */
+       0x00,           /* 1c/28 - cap_dataform_reg */
+       0x00,           /* 1d/29 - reserved */
+       0x00,           /* 1e/30 - cap_upcount_reg */
+       0x00            /* 1f/31 - cap_lowcount_reg */
+};
+
 /*
  *  Basic I/O functions
  */
 
-#if !defined(EBUS_SUPPORT) && !defined(SBUS_SUPPORT)
-#define __CS4231_INLINE__ inline
-#else
-#define __CS4231_INLINE__ /* nothing */
-#endif
-
-static __CS4231_INLINE__ void cs4231_outb(cs4231_t *chip, u8 offset, u8 val)
+static inline void cs4231_outb(struct snd_cs4231 *chip, u8 offset, u8 val)
 {
-#ifdef EBUS_SUPPORT
-       if (chip->ebus->flag) {
-               writeb(val, chip->port + (offset << 2));
-       } else {
-#endif
-#ifdef SBUS_SUPPORT
-               sbus_writeb(val, chip->port + (offset << 2));
-#endif
-#ifdef EBUS_SUPPORT
-       }
-#endif
-#ifdef LEGACY_SUPPORT
        outb(val, chip->port + offset);
-#endif
 }
 
-static __CS4231_INLINE__ u8 cs4231_inb(cs4231_t *chip, u8 offset)
+static inline u8 cs4231_inb(struct snd_cs4231 *chip, u8 offset)
 {
-#ifdef EBUS_SUPPORT
-       if (chip->ebus_flag) {
-               return readb(chip->port + (offset << 2));
-       } else {
-#endif
-#ifdef SBUS_SUPPORT
-               return sbus_readb(chip->port + (offset << 2));
-#endif
-#ifdef EBUS_SUPPORT
-       }
-#endif
-#ifdef LEGACY_SUPPORT
        return inb(chip->port + offset);
-#endif
 }
 
-static void snd_cs4231_outm(cs4231_t *chip, unsigned char reg,
-                           unsigned char mask, unsigned char value)
+static void snd_cs4231_wait(struct snd_cs4231 *chip)
 {
        int timeout;
-       unsigned char tmp;
 
        for (timeout = 250;
             timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
             timeout--)
                udelay(100);
+}
+
+static void snd_cs4231_outm(struct snd_cs4231 *chip, unsigned char reg,
+                           unsigned char mask, unsigned char value)
+{
+       unsigned char tmp = (chip->image[reg] & mask) | value;
+
+       snd_cs4231_wait(chip);
 #ifdef CONFIG_SND_DEBUG
        if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
                snd_printk("outm: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
 #endif
-       if (chip->calibrate_mute) {
-               chip->image[reg] &= mask;
-               chip->image[reg] |= value;
-       } else {
+       chip->image[reg] = tmp;
+       if (!chip->calibrate_mute) {
                cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | reg);
-               mb();
-               tmp = (chip->image[reg] & mask) | value;
+               wmb();
                cs4231_outb(chip, CS4231P(REG), tmp);
-               chip->image[reg] = tmp;
                mb();
        }
 }
 
-static void snd_cs4231_dout(cs4231_t *chip, unsigned char reg, unsigned char value)
+static void snd_cs4231_dout(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
 {
        int timeout;
 
@@ -206,14 +211,9 @@ static void snd_cs4231_dout(cs4231_t *chip, unsigned char reg, unsigned char val
        mb();
 }
 
-void snd_cs4231_out(cs4231_t *chip, unsigned char reg, unsigned char value)
+void snd_cs4231_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char value)
 {
-       int timeout;
-
-       for (timeout = 250;
-            timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
-            timeout--)
-               udelay(100);
+       snd_cs4231_wait(chip);
 #ifdef CONFIG_SND_DEBUG
        if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
                snd_printk("out: auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
@@ -222,19 +222,13 @@ void snd_cs4231_out(cs4231_t *chip, unsigned char reg, unsigned char value)
        cs4231_outb(chip, CS4231P(REG), value);
        chip->image[reg] = value;
        mb();
-#if 0
-       printk("codec out - reg 0x%x = 0x%x\n", chip->mce_bit | reg, value);
-#endif
+       snd_printdd("codec out - reg 0x%x = 0x%x\n",
+                       chip->mce_bit | reg, value);
 }
 
-unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
+unsigned char snd_cs4231_in(struct snd_cs4231 *chip, unsigned char reg)
 {
-       int timeout;
-
-       for (timeout = 250;
-            timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT);
-            timeout--)
-               udelay(100);
+       snd_cs4231_wait(chip);
 #ifdef CONFIG_SND_DEBUG
        if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
                snd_printk("in: auto calibration time out - reg = 0x%x\n", reg);
@@ -244,7 +238,7 @@ unsigned char snd_cs4231_in(cs4231_t *chip, unsigned char reg)
        return cs4231_inb(chip, CS4231P(REG));
 }
 
-void snd_cs4236_ext_out(cs4231_t *chip, unsigned char reg, unsigned char val)
+void snd_cs4236_ext_out(struct snd_cs4231 *chip, unsigned char reg, unsigned char val)
 {
        cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
        cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
@@ -255,7 +249,7 @@ void snd_cs4236_ext_out(cs4231_t *chip, unsigned char reg, unsigned char val)
 #endif
 }
 
-unsigned char snd_cs4236_ext_in(cs4231_t *chip, unsigned char reg)
+unsigned char snd_cs4236_ext_in(struct snd_cs4231 *chip, unsigned char reg)
 {
        cs4231_outb(chip, CS4231P(REGSEL), chip->mce_bit | 0x17);
        cs4231_outb(chip, CS4231P(REG), reg | (chip->image[CS4236_EXT_REG] & 0x01));
@@ -273,7 +267,7 @@ unsigned char snd_cs4236_ext_in(cs4231_t *chip, unsigned char reg)
 
 #if 0
 
-static void snd_cs4231_debug(cs4231_t *chip)
+static void snd_cs4231_debug(struct snd_cs4231 *chip)
 {
        printk("CS4231 REGS:      INDEX = 0x%02x  ", cs4231_inb(chip, CS4231P(REGSEL)));
        printk("                 STATUS = 0x%02x\n", cs4231_inb(chip, CS4231P(STATUS)));
@@ -317,7 +311,7 @@ static void snd_cs4231_debug(cs4231_t *chip)
  *  CS4231 detection / MCE routines
  */
 
-static void snd_cs4231_busy_wait(cs4231_t *chip)
+static void snd_cs4231_busy_wait(struct snd_cs4231 *chip)
 {
        int timeout;
 
@@ -331,13 +325,12 @@ static void snd_cs4231_busy_wait(cs4231_t *chip)
                udelay(10);
 }
 
-void snd_cs4231_mce_up(cs4231_t *chip)
+void snd_cs4231_mce_up(struct snd_cs4231 *chip)
 {
        unsigned long flags;
        int timeout;
 
-       for (timeout = 250; timeout > 0 && (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT); timeout--)
-               udelay(100);
+       snd_cs4231_wait(chip);
 #ifdef CONFIG_SND_DEBUG
        if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
                snd_printk("mce_up - auto calibration time out (0)\n");
@@ -352,15 +345,14 @@ void snd_cs4231_mce_up(cs4231_t *chip)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-void snd_cs4231_mce_down(cs4231_t *chip)
+void snd_cs4231_mce_down(struct snd_cs4231 *chip)
 {
        unsigned long flags;
+       unsigned long end_time;
        int timeout;
 
        snd_cs4231_busy_wait(chip);
-#if 0
-       printk("(1) timeout = %i\n", timeout);
-#endif
+
 #ifdef CONFIG_SND_DEBUG
        if (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT)
                snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", (long)CS4231P(REGSEL));
@@ -376,44 +368,43 @@ void snd_cs4231_mce_down(cs4231_t *chip)
            !(chip->hardware & (CS4231_HW_CS4231_MASK | CS4231_HW_CS4232_MASK))) {
                return;
        }
-       snd_cs4231_busy_wait(chip);
 
-       /* calibration process */
+       /*
+        * Wait for (possible -- during init auto-calibration may not be set)
+        * calibration process to start. Needs upto 5 sample periods on AD1848
+        * which at the slowest possible rate of 5.5125 kHz means 907 us.
+        */
+       msleep(1);
 
-       for (timeout = 500; timeout > 0 && (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0; timeout--)
-               udelay(10);
-       if ((snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) == 0) {
-               snd_printd("cs4231_mce_down - auto calibration time out (1)\n");
-               return;
-       }
-#if 0
-       printk("(2) timeout = %i, jiffies = %li\n", timeout, jiffies);
-#endif
-       /* in 10 ms increments, check condition, up to 250 ms */
-       timeout = 25;
-       while (snd_cs4231_in(chip, CS4231_TEST_INIT) & CS4231_CALIB_IN_PROGRESS) {
-               if (--timeout < 0) {
-                       snd_printk("mce_down - auto calibration time out (2)\n");
+       snd_printdd("(1) jiffies = %lu\n", jiffies);
+
+       /* check condition up to 250 ms */
+       end_time = jiffies + msecs_to_jiffies(250);
+       while (snd_cs4231_in(chip, CS4231_TEST_INIT) &
+               CS4231_CALIB_IN_PROGRESS) {
+
+               if (time_after(jiffies, end_time)) {
+                       snd_printk(KERN_ERR "mce_down - "
+                                       "auto calibration time out (2)\n");
                        return;
                }
-               msleep(10);
+               msleep(1);
        }
-#if 0
-       printk("(3) jiffies = %li\n", jiffies);
-#endif
-       /* in 10 ms increments, check condition, up to 100 ms */
-       timeout = 10;
+
+       snd_printdd("(2) jiffies = %lu\n", jiffies);
+
+       /* check condition up to 100 ms */
+       end_time = jiffies + msecs_to_jiffies(100);
        while (cs4231_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
-               if (--timeout < 0) {
+               if (time_after(jiffies, end_time)) {
                        snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
                        return;
                }
-               msleep(10);
+               msleep(1);
        }
-#if 0
-       printk("(4) jiffies = %li\n", jiffies);
-       snd_printk("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
-#endif
+
+       snd_printdd("(3) jiffies = %lu\n", jiffies);
+       snd_printd("mce_down - exit = 0x%x\n", cs4231_inb(chip, CS4231P(REGSEL)));
 }
 
 static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size)
@@ -431,14 +422,13 @@ static unsigned int snd_cs4231_get_count(unsigned char format, unsigned int size
        return size;
 }
 
-static int snd_cs4231_trigger(snd_pcm_substream_t *substream,
+static int snd_cs4231_trigger(struct snd_pcm_substream *substream,
                              int cmd)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        int result = 0;
        unsigned int what;
-       struct list_head *pos;
-       snd_pcm_substream_t *s;
+       struct snd_pcm_substream *s;
        int do_start;
 
 #if 0
@@ -457,8 +447,7 @@ static int snd_cs4231_trigger(snd_pcm_substream_t *substream,
        }
 
        what = 0;
-       snd_pcm_group_for_each(pos, substream) {
-               s = snd_pcm_group_substream_entry(pos);
+       snd_pcm_group_for_each_entry(s, substream) {
                if (s == chip->playback_substream) {
                        what |= CS4231_PLAYBACK_ENABLE;
                        snd_pcm_trigger_done(s, substream);
@@ -493,14 +482,14 @@ static unsigned char snd_cs4231_get_rate(unsigned int rate)
 {
        int i;
 
-       for (i = 0; i < 14; i++)
+       for (i = 0; i < ARRAY_SIZE(rates); i++)
                if (rate == rates[i])
                        return freq_bits[i];
        // snd_BUG();
-       return freq_bits[13];
+       return freq_bits[ARRAY_SIZE(rates) - 1];
 }
 
-static unsigned char snd_cs4231_get_format(cs4231_t *chip,
+static unsigned char snd_cs4231_get_format(struct snd_cs4231 *chip,
                                           int format,
                                            int channels)
 {
@@ -522,7 +511,7 @@ static unsigned char snd_cs4231_get_format(cs4231_t *chip,
        return rformat;
 }
 
-static void snd_cs4231_calibrate_mute(cs4231_t *chip, int mute)
+static void snd_cs4231_calibrate_mute(struct snd_cs4231 *chip, int mute)
 {
        unsigned long flags;
 
@@ -556,14 +545,14 @@ static void snd_cs4231_calibrate_mute(cs4231_t *chip, int mute)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-static void snd_cs4231_playback_format(cs4231_t *chip,
-                                      snd_pcm_hw_params_t *params,
+static void snd_cs4231_playback_format(struct snd_cs4231 *chip,
+                                      struct snd_pcm_hw_params *params,
                                       unsigned char pdfr)
 {
        unsigned long flags;
        int full_calib = 1;
 
-       down(&chip->mce_mutex);
+       mutex_lock(&chip->mce_mutex);
        snd_cs4231_calibrate_mute(chip, 1);
        if (chip->hardware == CS4231_HW_CS4231A ||
            (chip->hardware & CS4231_HW_CS4232_MASK)) {
@@ -589,20 +578,22 @@ static void snd_cs4231_playback_format(cs4231_t *chip,
                        snd_cs4231_out(chip, CS4231_PLAYBK_FORMAT, chip->image[CS4231_PLAYBK_FORMAT] = pdfr);
                }
                spin_unlock_irqrestore(&chip->reg_lock, flags);
+               if (chip->hardware == CS4231_HW_OPL3SA2)
+                       udelay(100);    /* this seems to help */
                snd_cs4231_mce_down(chip);
        }
        snd_cs4231_calibrate_mute(chip, 0);
-       up(&chip->mce_mutex);
+       mutex_unlock(&chip->mce_mutex);
 }
 
-static void snd_cs4231_capture_format(cs4231_t *chip,
-                                     snd_pcm_hw_params_t *params,
+static void snd_cs4231_capture_format(struct snd_cs4231 *chip,
+                                     struct snd_pcm_hw_params *params,
                                       unsigned char cdfr)
 {
        unsigned long flags;
        int full_calib = 1;
 
-       down(&chip->mce_mutex);
+       mutex_lock(&chip->mce_mutex);
        snd_cs4231_calibrate_mute(chip, 1);
        if (chip->hardware == CS4231_HW_CS4231A ||
            (chip->hardware & CS4231_HW_CS4232_MASK)) {
@@ -635,27 +626,27 @@ static void snd_cs4231_capture_format(cs4231_t *chip,
                snd_cs4231_mce_down(chip);
        }
        snd_cs4231_calibrate_mute(chip, 0);
-       up(&chip->mce_mutex);
+       mutex_unlock(&chip->mce_mutex);
 }
 
 /*
  *  Timer interface
  */
 
-static unsigned long snd_cs4231_timer_resolution(snd_timer_t * timer)
+static unsigned long snd_cs4231_timer_resolution(struct snd_timer * timer)
 {
-       cs4231_t *chip = snd_timer_chip(timer);
+       struct snd_cs4231 *chip = snd_timer_chip(timer);
        if (chip->hardware & CS4231_HW_CS4236B_MASK)
                return 14467;
        else
                return chip->image[CS4231_PLAYBK_FORMAT] & 1 ? 9969 : 9920;
 }
 
-static int snd_cs4231_timer_start(snd_timer_t * timer)
+static int snd_cs4231_timer_start(struct snd_timer * timer)
 {
        unsigned long flags;
        unsigned int ticks;
-       cs4231_t *chip = snd_timer_chip(timer);
+       struct snd_cs4231 *chip = snd_timer_chip(timer);
        spin_lock_irqsave(&chip->reg_lock, flags);
        ticks = timer->sticks;
        if ((chip->image[CS4231_ALT_FEATURE_1] & CS4231_TIMER_ENABLE) == 0 ||
@@ -669,17 +660,17 @@ static int snd_cs4231_timer_start(snd_timer_t * timer)
        return 0;
 }
 
-static int snd_cs4231_timer_stop(snd_timer_t * timer)
+static int snd_cs4231_timer_stop(struct snd_timer * timer)
 {
        unsigned long flags;
-       cs4231_t *chip = snd_timer_chip(timer);
+       struct snd_cs4231 *chip = snd_timer_chip(timer);
        spin_lock_irqsave(&chip->reg_lock, flags);
        snd_cs4231_out(chip, CS4231_ALT_FEATURE_1, chip->image[CS4231_ALT_FEATURE_1] &= ~CS4231_TIMER_ENABLE);
        spin_unlock_irqrestore(&chip->reg_lock, flags);
        return 0;
 }
 
-static void snd_cs4231_init(cs4231_t *chip)
+static void snd_cs4231_init(struct snd_cs4231 *chip)
 {
        unsigned long flags;
 
@@ -737,19 +728,19 @@ static void snd_cs4231_init(cs4231_t *chip)
 #endif
 }
 
-static int snd_cs4231_open(cs4231_t *chip, unsigned int mode)
+static int snd_cs4231_open(struct snd_cs4231 *chip, unsigned int mode)
 {
        unsigned long flags;
 
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        if ((chip->mode & mode) ||
            ((chip->mode & CS4231_MODE_OPEN) && chip->single_dma)) {
-               up(&chip->open_mutex);
+               mutex_unlock(&chip->open_mutex);
                return -EAGAIN;
        }
        if (chip->mode & CS4231_MODE_OPEN) {
                chip->mode |= mode;
-               up(&chip->open_mutex);
+               mutex_unlock(&chip->open_mutex);
                return 0;
        }
        /* ok. now enable and ack CODEC IRQ */
@@ -769,18 +760,18 @@ static int snd_cs4231_open(cs4231_t *chip, unsigned int mode)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        chip->mode = mode;
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
        return 0;
 }
 
-static void snd_cs4231_close(cs4231_t *chip, unsigned int mode)
+static void snd_cs4231_close(struct snd_cs4231 *chip, unsigned int mode)
 {
        unsigned long flags;
 
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        chip->mode &= ~mode;
        if (chip->mode & CS4231_MODE_OPEN) {
-               up(&chip->open_mutex);
+               mutex_unlock(&chip->open_mutex);
                return;
        }
        snd_cs4231_calibrate_mute(chip, 1);
@@ -817,28 +808,28 @@ static void snd_cs4231_close(cs4231_t *chip, unsigned int mode)
        snd_cs4231_calibrate_mute(chip, 0);
 
        chip->mode = 0;
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
 }
 
 /*
  *  timer open/close
  */
 
-static int snd_cs4231_timer_open(snd_timer_t * timer)
+static int snd_cs4231_timer_open(struct snd_timer * timer)
 {
-       cs4231_t *chip = snd_timer_chip(timer);
+       struct snd_cs4231 *chip = snd_timer_chip(timer);
        snd_cs4231_open(chip, CS4231_MODE_TIMER);
        return 0;
 }
 
-static int snd_cs4231_timer_close(snd_timer_t * timer)
+static int snd_cs4231_timer_close(struct snd_timer * timer)
 {
-       cs4231_t *chip = snd_timer_chip(timer);
+       struct snd_cs4231 *chip = snd_timer_chip(timer);
        snd_cs4231_close(chip, CS4231_MODE_TIMER);
        return 0;
 }
 
-static struct _snd_timer_hardware snd_cs4231_timer_table =
+static struct snd_timer_hardware snd_cs4231_timer_table =
 {
        .flags =        SNDRV_TIMER_HW_AUTO,
        .resolution =   9945,
@@ -854,10 +845,10 @@ static struct _snd_timer_hardware snd_cs4231_timer_table =
  *  ok.. exported functions..
  */
 
-static int snd_cs4231_playback_hw_params(snd_pcm_substream_t * substream,
-                                        snd_pcm_hw_params_t * hw_params)
+static int snd_cs4231_playback_hw_params(struct snd_pcm_substream *substream,
+                                        struct snd_pcm_hw_params *hw_params)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        unsigned char new_pdfr;
        int err;
 
@@ -869,16 +860,15 @@ static int snd_cs4231_playback_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_cs4231_playback_hw_free(snd_pcm_substream_t * substream)
+static int snd_cs4231_playback_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-#ifdef LEGACY_SUPPORT
-static int snd_cs4231_playback_prepare(snd_pcm_substream_t * substream)
+static int snd_cs4231_playback_prepare(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned long flags;
        unsigned int size = snd_pcm_lib_buffer_bytes(substream);
        unsigned int count = snd_pcm_lib_period_bytes(substream);
@@ -896,12 +886,11 @@ static int snd_cs4231_playback_prepare(snd_pcm_substream_t * substream)
 #endif
        return 0;
 }
-#endif /* LEGACY_SUPPORT */
 
-static int snd_cs4231_capture_hw_params(snd_pcm_substream_t * substream,
-                                       snd_pcm_hw_params_t * hw_params)
+static int snd_cs4231_capture_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *hw_params)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        unsigned char new_cdfr;
        int err;
 
@@ -913,16 +902,15 @@ static int snd_cs4231_capture_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_cs4231_capture_hw_free(snd_pcm_substream_t * substream)
+static int snd_cs4231_capture_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-#ifdef LEGACY_SUPPORT
-static int snd_cs4231_capture_prepare(snd_pcm_substream_t * substream)
+static int snd_cs4231_capture_prepare(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        unsigned long flags;
        unsigned int size = snd_pcm_lib_buffer_bytes(substream);
        unsigned int count = snd_pcm_lib_period_bytes(substream);
@@ -942,9 +930,8 @@ static int snd_cs4231_capture_prepare(snd_pcm_substream_t * substream)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
        return 0;
 }
-#endif
 
-static void snd_cs4231_overrange(cs4231_t *chip)
+void snd_cs4231_overrange(struct snd_cs4231 *chip)
 {
        unsigned long flags;
        unsigned char res;
@@ -956,9 +943,9 @@ static void snd_cs4231_overrange(cs4231_t *chip)
                chip->capture_substream->runtime->overrange++;
 }
 
-irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id)
 {
-       cs4231_t *chip = dev_id;
+       struct snd_cs4231 *chip = dev_id;
        unsigned char status;
 
        status = snd_cs4231_in(chip, CS4231_IRQ_STATUS);
@@ -998,10 +985,9 @@ irqreturn_t snd_cs4231_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
-#ifdef LEGACY_SUPPORT
-static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_cs4231_playback_pointer(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
 
        if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_PLAYBACK_ENABLE))
@@ -1010,9 +996,9 @@ static snd_pcm_uframes_t snd_cs4231_playback_pointer(snd_pcm_substream_t * subst
        return bytes_to_frames(substream->runtime, ptr);
 }
 
-static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_cs4231_capture_pointer(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
        
        if (!(chip->image[CS4231_IFACE_CTRL] & CS4231_RECORD_ENABLE))
@@ -1020,13 +1006,12 @@ static snd_pcm_uframes_t snd_cs4231_capture_pointer(snd_pcm_substream_t * substr
        ptr = snd_dma_pointer(chip->dma2, chip->c_dma_size);
        return bytes_to_frames(substream->runtime, ptr);
 }
-#endif /* LEGACY_SUPPORT */
 
 /*
 
  */
 
-static int snd_cs4231_probe(cs4231_t *chip)
+static int snd_cs4231_probe(struct snd_cs4231 *chip)
 {
        unsigned long flags;
        int i, id, rev;
@@ -1105,8 +1090,11 @@ static int snd_cs4231_probe(cs4231_t *chip)
        chip->image[CS4231_IFACE_CTRL] =
            (chip->image[CS4231_IFACE_CTRL] & ~CS4231_SINGLE_DMA) |
            (chip->single_dma ? CS4231_SINGLE_DMA : 0);
-       chip->image[CS4231_ALT_FEATURE_1] = 0x80;
-       chip->image[CS4231_ALT_FEATURE_2] = chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
+       if (chip->hardware != CS4231_HW_OPTI93X) {
+               chip->image[CS4231_ALT_FEATURE_1] = 0x80;
+               chip->image[CS4231_ALT_FEATURE_2] =
+                       chip->hardware == CS4231_HW_INTERWAVE ? 0xc2 : 0x01;
+       }
        ptr = (unsigned char *) &chip->image;
        snd_cs4231_mce_down(chip);
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1190,7 +1178,7 @@ static int snd_cs4231_probe(cs4231_t *chip)
 
  */
 
-static snd_pcm_hardware_t snd_cs4231_playback =
+static struct snd_pcm_hardware snd_cs4231_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_MMAP_VALID |
@@ -1211,7 +1199,7 @@ static snd_pcm_hardware_t snd_cs4231_playback =
        .fifo_size =            0,
 };
 
-static snd_pcm_hardware_t snd_cs4231_capture =
+static struct snd_pcm_hardware snd_cs4231_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_MMAP_VALID |
@@ -1236,10 +1224,10 @@ static snd_pcm_hardware_t snd_cs4231_capture =
 
  */
 
-static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
+static int snd_cs4231_playback_open(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        runtime->hw = snd_cs4231_playback;
@@ -1253,7 +1241,6 @@ static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
            chip->hardware == CS4231_HW_CS4239)
                runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
 
-#ifdef LEGACY_SUPPORT
        snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.buffer_bytes_max);
        snd_pcm_limit_isa_dma_size(chip->dma1, &runtime->hw.period_bytes_max);
 
@@ -1261,29 +1248,23 @@ static int snd_cs4231_playback_open(snd_pcm_substream_t * substream)
                if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma1)) < 0)
                        return err;
        }
-#endif
 
        if ((err = snd_cs4231_open(chip, CS4231_MODE_PLAY)) < 0) {
-#ifdef LEGACY_SUPPORT
                if (chip->release_dma)
                        chip->release_dma(chip, chip->dma_private_data, chip->dma1);
-#endif
                snd_free_pages(runtime->dma_area, runtime->dma_bytes);
                return err;
        }
        chip->playback_substream = substream;
-#if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
-       chip->p_periods_sent = 0;
-#endif
        snd_pcm_set_sync(substream);
        chip->rate_constraint(runtime);
        return 0;
 }
 
-static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
+static int snd_cs4231_capture_open(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        runtime->hw = snd_cs4231_capture;
@@ -1293,7 +1274,6 @@ static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
            chip->hardware == CS4231_HW_CS4239)
                runtime->hw.formats = SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE;
 
-#ifdef LEGACY_SUPPORT
        snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.buffer_bytes_max);
        snd_pcm_limit_isa_dma_size(chip->dma2, &runtime->hw.period_bytes_max);
 
@@ -1301,37 +1281,31 @@ static int snd_cs4231_capture_open(snd_pcm_substream_t * substream)
                if ((err = chip->claim_dma(chip, chip->dma_private_data, chip->dma2)) < 0)
                        return err;
        }
-#endif
 
        if ((err = snd_cs4231_open(chip, CS4231_MODE_RECORD)) < 0) {
-#ifdef LEGACY_SUPPORT
                if (chip->release_dma)
                        chip->release_dma(chip, chip->dma_private_data, chip->dma2);
-#endif
                snd_free_pages(runtime->dma_area, runtime->dma_bytes);
                return err;
        }
        chip->capture_substream = substream;
-#if defined(SBUS_SUPPORT) || defined(EBUS_SUPPORT)
-       chip->c_periods_sent = 0;
-#endif
        snd_pcm_set_sync(substream);
        chip->rate_constraint(runtime);
        return 0;
 }
 
-static int snd_cs4231_playback_close(snd_pcm_substream_t * substream)
+static int snd_cs4231_playback_close(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
 
        chip->playback_substream = NULL;
        snd_cs4231_close(chip, CS4231_MODE_PLAY);
        return 0;
 }
 
-static int snd_cs4231_capture_close(snd_pcm_substream_t * substream)
+static int snd_cs4231_capture_close(struct snd_pcm_substream *substream)
 {
-       cs4231_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_cs4231 *chip = snd_pcm_substream_chip(substream);
 
        chip->capture_substream = NULL;
        snd_cs4231_close(chip, CS4231_MODE_RECORD);
@@ -1341,13 +1315,12 @@ static int snd_cs4231_capture_close(snd_pcm_substream_t * substream)
 #ifdef CONFIG_PM
 
 /* lowlevel suspend callback for CS4231 */
-static void snd_cs4231_suspend(cs4231_t *chip)
+static void snd_cs4231_suspend(struct snd_cs4231 *chip)
 {
        int reg;
        unsigned long flags;
        
-       if (chip->pcm)
-               snd_pcm_suspend_all(chip->pcm);
+       snd_pcm_suspend_all(chip->pcm);
        spin_lock_irqsave(&chip->reg_lock, flags);
        for (reg = 0; reg < 32; reg++)
                chip->image[reg] = snd_cs4231_in(chip, reg);
@@ -1355,11 +1328,11 @@ static void snd_cs4231_suspend(cs4231_t *chip)
 }
 
 /* lowlevel resume callback for CS4231 */
-static void snd_cs4231_resume(cs4231_t *chip)
+static void snd_cs4231_resume(struct snd_cs4231 *chip)
 {
        int reg;
        unsigned long flags;
-       int timeout;
+       /* int timeout; */
        
        snd_cs4231_mce_up(chip);
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1373,7 +1346,7 @@ static void snd_cs4231_resume(cs4231_t *chip)
                }
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
-#if 0
+#if 1
        snd_cs4231_mce_down(chip);
 #else
        /* The following is a workaround to avoid freeze after resume on TP600E.
@@ -1395,36 +1368,12 @@ static void snd_cs4231_resume(cs4231_t *chip)
        snd_cs4231_busy_wait(chip);
 #endif
 }
-
-static int snd_cs4231_pm_suspend(snd_card_t *card, pm_message_t state)
-{
-       cs4231_t *chip = card->pm_private_data;
-       if (chip->suspend)
-               chip->suspend(chip);
-       return 0;
-}
-
-static int snd_cs4231_pm_resume(snd_card_t *card)
-{
-       cs4231_t *chip = card->pm_private_data;
-       if (chip->resume)
-               chip->resume(chip);
-       return 0;
-}
 #endif /* CONFIG_PM */
 
-#ifdef LEGACY_SUPPORT
-
-static int snd_cs4231_free(cs4231_t *chip)
+static int snd_cs4231_free(struct snd_cs4231 *chip)
 {
-       if (chip->res_port) {
-               release_resource(chip->res_port);
-               kfree_nocheck(chip->res_port);
-       }
-       if (chip->res_cport) {
-               release_resource(chip->res_cport);
-               kfree_nocheck(chip->res_cport);
-       }
+       release_and_free_resource(chip->res_port);
+       release_and_free_resource(chip->res_cport);
        if (chip->irq >= 0) {
                disable_irq(chip->irq);
                if (!(chip->hwshare & CS4231_HWSHARE_IRQ))
@@ -1444,15 +1393,13 @@ static int snd_cs4231_free(cs4231_t *chip)
        return 0;
 }
 
-static int snd_cs4231_dev_free(snd_device_t *device)
+static int snd_cs4231_dev_free(struct snd_device *device)
 {
-       cs4231_t *chip = device->device_data;
+       struct snd_cs4231 *chip = device->device_data;
        return snd_cs4231_free(chip);   
 }
 
-#endif /* LEGACY_SUPPORT */
-
-const char *snd_cs4231_chip_id(cs4231_t *chip)
+const char *snd_cs4231_chip_id(struct snd_cs4231 *chip)
 {
        switch (chip->hardware) {
        case CS4231_HW_CS4231:  return "CS4231";
@@ -1468,16 +1415,17 @@ const char *snd_cs4231_chip_id(cs4231_t *chip)
        case CS4231_HW_INTERWAVE: return "AMD InterWave";
        case CS4231_HW_OPL3SA2: return chip->card->shortname;
        case CS4231_HW_AD1845: return "AD1845";
+       case CS4231_HW_OPTI93X: return "OPTi 93x";
        default: return "???";
        }
 }
 
-static int snd_cs4231_new(snd_card_t * card,
+static int snd_cs4231_new(struct snd_card *card,
                          unsigned short hardware,
                          unsigned short hwshare,
-                         cs4231_t ** rchip)
+                         struct snd_cs4231 ** rchip)
 {
-       cs4231_t *chip;
+       struct snd_cs4231 *chip;
 
        *rchip = NULL;
        chip = kzalloc(sizeof(*chip), GFP_KERNEL);
@@ -1487,32 +1435,35 @@ static int snd_cs4231_new(snd_card_t * card,
        chip->hwshare = hwshare;
 
        spin_lock_init(&chip->reg_lock);
-       init_MUTEX(&chip->mce_mutex);
-       init_MUTEX(&chip->open_mutex);
+       mutex_init(&chip->mce_mutex);
+       mutex_init(&chip->open_mutex);
        chip->card = card;
        chip->rate_constraint = snd_cs4231_xrate;
        chip->set_playback_format = snd_cs4231_playback_format;
        chip->set_capture_format = snd_cs4231_capture_format;
-        memcpy(&chip->image, &snd_cs4231_original_image, sizeof(snd_cs4231_original_image));
-        
+       if (chip->hardware == CS4231_HW_OPTI93X)
+               memcpy(&chip->image, &snd_opti93x_original_image,
+                      sizeof(snd_opti93x_original_image));
+       else
+               memcpy(&chip->image, &snd_cs4231_original_image,
+                      sizeof(snd_cs4231_original_image));
+
         *rchip = chip;
         return 0;
 }
 
-#ifdef LEGACY_SUPPORT
-
-int snd_cs4231_create(snd_card_t * card,
+int snd_cs4231_create(struct snd_card *card,
                      unsigned long port,
                      unsigned long cport,
                      int irq, int dma1, int dma2,
                      unsigned short hardware,
                      unsigned short hwshare,
-                     cs4231_t ** rchip)
+                     struct snd_cs4231 ** rchip)
 {
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free =     snd_cs4231_dev_free,
        };
-       cs4231_t *chip;
+       struct snd_cs4231 *chip;
        int err;
 
        err = snd_cs4231_new(card, hardware, hwshare, &chip);
@@ -1535,7 +1486,7 @@ int snd_cs4231_create(snd_card_t * card,
                return -ENODEV;
        }
        chip->cport = cport;
-       if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, SA_INTERRUPT, "CS4231", (void *) chip)) {
+       if (!(hwshare & CS4231_HWSHARE_IRQ) && request_irq(irq, snd_cs4231_interrupt, IRQF_DISABLED, "CS4231", (void *) chip)) {
                snd_printk(KERN_ERR "cs4231: can't grab IRQ %d\n", irq);
                snd_cs4231_free(chip);
                return -EBUSY;
@@ -1565,10 +1516,12 @@ int snd_cs4231_create(snd_card_t * card,
        }
        snd_cs4231_init(chip);
 
+#if 0
        if (chip->hardware & CS4231_HW_CS4232_MASK) {
                if (chip->res_cport == NULL)
                        snd_printk("CS4232 control port features are not accessible\n");
        }
+#endif
 
        /* Register device */
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
@@ -1580,16 +1533,13 @@ int snd_cs4231_create(snd_card_t * card,
        /* Power Management */
        chip->suspend = snd_cs4231_suspend;
        chip->resume = snd_cs4231_resume;
-       snd_card_set_isa_pm_callback(card, snd_cs4231_pm_suspend, snd_cs4231_pm_resume, chip);
 #endif
 
        *rchip = chip;
        return 0;
 }
 
-#endif /* LEGACY_SUPPORT */
-
-static snd_pcm_ops_t snd_cs4231_playback_ops = {
+static struct snd_pcm_ops snd_cs4231_playback_ops = {
        .open =         snd_cs4231_playback_open,
        .close =        snd_cs4231_playback_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1600,7 +1550,7 @@ static snd_pcm_ops_t snd_cs4231_playback_ops = {
        .pointer =      snd_cs4231_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_cs4231_capture_ops = {
+static struct snd_pcm_ops snd_cs4231_capture_ops = {
        .open =         snd_cs4231_capture_open,
        .close =        snd_cs4231_capture_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1611,31 +1561,23 @@ static snd_pcm_ops_t snd_cs4231_capture_ops = {
        .pointer =      snd_cs4231_capture_pointer,
 };
 
-static void snd_cs4231_pcm_free(snd_pcm_t *pcm)
+int snd_cs4231_pcm(struct snd_cs4231 *chip, int device, struct snd_pcm **rpcm)
 {
-       cs4231_t *chip = pcm->private_data;
-       chip->pcm = NULL;
-       snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
-{
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        if ((err = snd_pcm_new(chip->card, "CS4231", device, 1, 1, &pcm)) < 0)
                return err;
 
        spin_lock_init(&chip->reg_lock);
-       init_MUTEX(&chip->mce_mutex);
-       init_MUTEX(&chip->open_mutex);
+       mutex_init(&chip->mce_mutex);
+       mutex_init(&chip->open_mutex);
 
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cs4231_playback_ops);
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cs4231_capture_ops);
        
        /* global setup */
        pcm->private_data = chip;
-       pcm->private_free = snd_cs4231_pcm_free;
        pcm->info_flags = 0;
        if (chip->single_dma)
                pcm->info_flags |= SNDRV_PCM_INFO_HALF_DUPLEX;
@@ -1643,27 +1585,9 @@ int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
                pcm->info_flags |= SNDRV_PCM_INFO_JOINT_DUPLEX;
        strcpy(pcm->name, snd_cs4231_chip_id(chip));
 
-#ifdef LEGACY_SUPPORT
        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
                                              snd_dma_isa_data(),
                                              64*1024, chip->dma1 > 3 || chip->dma2 > 3 ? 128*1024 : 64*1024);
-#else
-#  ifdef EBUS_SUPPORT
-        if (chip->ebus_flag) {
-                snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
-                                                     chip->dev_u.pdev,
-                                                     64*1024, 128*1024);
-        } else {
-#  endif
-#  ifdef SBUS_SUPPORT
-                snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_SBUS,
-                                                     chip->dev_u.sdev,
-                                                     64*1024, 128*1024);
-#  endif
-#  ifdef EBUS_SUPPORT
-        }
-#  endif
-#endif
 
        chip->pcm = pcm;
        if (rpcm)
@@ -1671,16 +1595,16 @@ int snd_cs4231_pcm(cs4231_t *chip, int device, snd_pcm_t **rpcm)
        return 0;
 }
 
-static void snd_cs4231_timer_free(snd_timer_t *timer)
+static void snd_cs4231_timer_free(struct snd_timer *timer)
 {
-       cs4231_t *chip = timer->private_data;
+       struct snd_cs4231 *chip = timer->private_data;
        chip->timer = NULL;
 }
 
-int snd_cs4231_timer(cs4231_t *chip, int device, snd_timer_t **rtimer)
+int snd_cs4231_timer(struct snd_cs4231 *chip, int device, struct snd_timer **rtimer)
 {
-       snd_timer_t *timer;
-       snd_timer_id_t tid;
+       struct snd_timer *timer;
+       struct snd_timer_id tid;
        int err;
 
        /* Timer initialization */
@@ -1705,7 +1629,7 @@ int snd_cs4231_timer(cs4231_t *chip, int device, snd_timer_t **rtimer)
  *  MIXER part
  */
 
-static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_cs4231_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        static char *texts[4] = {
                "Line", "Aux", "Mic", "Mix"
@@ -1717,7 +1641,7 @@ static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * u
                "Line", "Synth", "Mic", "Mix"
        };
        char **ptexts = texts;
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
 
        snd_assert(chip->card != NULL, return -EINVAL);
        uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
@@ -1735,9 +1659,9 @@ static int snd_cs4231_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * u
        return 0;
 }
 
-static int snd_cs4231_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cs4231_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1747,9 +1671,9 @@ static int snd_cs4231_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
        return 0;
 }
 
-static int snd_cs4231_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cs4231_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        unsigned short left, right;
        int change;
@@ -1770,7 +1694,7 @@ static int snd_cs4231_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
        return change;
 }
 
-int snd_cs4231_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+int snd_cs4231_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
 
@@ -1781,9 +1705,9 @@ int snd_cs4231_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo
        return 0;
 }
 
-int snd_cs4231_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+int snd_cs4231_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0xff;
@@ -1798,9 +1722,9 @@ int snd_cs4231_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucon
        return 0;
 }
 
-int snd_cs4231_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+int snd_cs4231_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0xff;
@@ -1821,7 +1745,7 @@ int snd_cs4231_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucon
        return change;
 }
 
-int snd_cs4231_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+int snd_cs4231_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 24) & 0xff;
 
@@ -1832,9 +1756,9 @@ int snd_cs4231_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo
        return 0;
 }
 
-int snd_cs4231_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+int snd_cs4231_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
@@ -1854,9 +1778,9 @@ int snd_cs4231_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucon
        return 0;
 }
 
-int snd_cs4231_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+int snd_cs4231_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       cs4231_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_cs4231 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
@@ -1885,7 +1809,7 @@ int snd_cs4231_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucon
        return change;
 }
 
-static snd_kcontrol_new_t snd_cs4231_controls[] = {
+static struct snd_kcontrol_new snd_cs4231_controls[] = {
 CS4231_DOUBLE("PCM Playback Switch", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
 CS4231_DOUBLE("PCM Playback Volume", 0, CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 63, 1),
 CS4231_DOUBLE("Line Playback Switch", 0, CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
@@ -1911,9 +1835,51 @@ CS4231_SINGLE("Loopback Capture Switch", 0, CS4231_LOOPBACK, 0, 1, 0),
 CS4231_SINGLE("Loopback Capture Volume", 0, CS4231_LOOPBACK, 2, 63, 1)
 };
                                         
-int snd_cs4231_mixer(cs4231_t *chip)
+static struct snd_kcontrol_new snd_opti93x_controls[] = {
+CS4231_DOUBLE("Master Playback Switch", 0,
+             OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 7, 7, 1, 1),
+CS4231_DOUBLE("Master Playback Volume", 0,
+             OPTi93X_OUT_LEFT, OPTi93X_OUT_RIGHT, 1, 1, 31, 1),
+CS4231_DOUBLE("PCM Playback Switch", 0,
+             CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("PCM Playback Volume", 0,
+             CS4231_LEFT_OUTPUT, CS4231_RIGHT_OUTPUT, 0, 0, 31, 1),
+CS4231_DOUBLE("FM Playback Switch", 0,
+             CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("FM Playback Volume", 0,
+             CS4231_AUX2_LEFT_INPUT, CS4231_AUX2_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Line Playback Switch", 0,
+             CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 7, 7, 1, 1),
+CS4231_DOUBLE("Line Playback Volume", 0,
+             CS4231_LEFT_LINE_IN, CS4231_RIGHT_LINE_IN, 0, 0, 15, 1),
+CS4231_DOUBLE("Mic Playback Switch", 0,
+             OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Mic Playback Volume", 0,
+             OPTi93X_MIC_LEFT_INPUT, OPTi93X_MIC_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Mic Boost", 0,
+             CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 5, 5, 1, 0),
+CS4231_DOUBLE("CD Playback Switch", 0,
+             CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("CD Playback Volume", 0,
+             CS4231_AUX1_LEFT_INPUT, CS4231_AUX1_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Aux Playback Switch", 0,
+             OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 7, 7, 1, 1),
+CS4231_DOUBLE("Aux Playback Volume", 0,
+             OPTi931_AUX_LEFT_INPUT, OPTi931_AUX_RIGHT_INPUT, 1, 1, 15, 1),
+CS4231_DOUBLE("Capture Volume", 0,
+             CS4231_LEFT_INPUT, CS4231_RIGHT_INPUT, 0, 0, 15, 0),
+{
+       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .name = "Capture Source",
+       .info = snd_cs4231_info_mux,
+       .get = snd_cs4231_get_mux,
+       .put = snd_cs4231_put_mux,
+}
+};
+
+int snd_cs4231_mixer(struct snd_cs4231 *chip)
 {
-       snd_card_t *card;
+       struct snd_card *card;
        unsigned int idx;
        int err;
 
@@ -1923,10 +1889,22 @@ int snd_cs4231_mixer(cs4231_t *chip)
 
        strcpy(card->mixername, chip->pcm->name);
 
-       for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
-               if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cs4231_controls[idx], chip))) < 0)
-                       return err;
-       }
+       if (chip->hardware == CS4231_HW_OPTI93X)
+               for (idx = 0; idx < ARRAY_SIZE(snd_opti93x_controls); idx++) {
+                       err = snd_ctl_add(card,
+                                       snd_ctl_new1(&snd_opti93x_controls[idx],
+                                                    chip));
+                       if (err < 0)
+                               return err;
+               }
+       else
+               for (idx = 0; idx < ARRAY_SIZE(snd_cs4231_controls); idx++) {
+                       err = snd_ctl_add(card,
+                                       snd_ctl_new1(&snd_cs4231_controls[idx],
+                                                    chip));
+                       if (err < 0)
+                               return err;
+               }
        return 0;
 }
 
@@ -1936,6 +1914,7 @@ EXPORT_SYMBOL(snd_cs4236_ext_out);
 EXPORT_SYMBOL(snd_cs4236_ext_in);
 EXPORT_SYMBOL(snd_cs4231_mce_up);
 EXPORT_SYMBOL(snd_cs4231_mce_down);
+EXPORT_SYMBOL(snd_cs4231_overrange);
 EXPORT_SYMBOL(snd_cs4231_interrupt);
 EXPORT_SYMBOL(snd_cs4231_chip_id);
 EXPORT_SYMBOL(snd_cs4231_create);