fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / isa / ad1848 / ad1848_lib.c
index d0a62f7..666b3bc 100644 (file)
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
-#include <linux/pm.h>
 #include <linux/slab.h>
 #include <linux/ioport.h>
 #include <sound/core.h>
 #include <sound/ad1848.h>
 #include <sound/control.h>
+#include <sound/tlv.h>
 #include <sound/pcm_params.h>
 
 #include <asm/io.h>
@@ -69,7 +69,7 @@ static unsigned int rates[14] = {
        27042, 32000, 33075, 37800, 44100, 48000
 };
 
-static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
        .count = 14,
        .list = rates,
        .mask = 0,
@@ -99,7 +99,7 @@ static unsigned char snd_ad1848_original_image[16] =
  *  Basic I/O functions
  */
 
-void snd_ad1848_out(ad1848_t *chip,
+void snd_ad1848_out(struct snd_ad1848 *chip,
                           unsigned char reg,
                           unsigned char value)
 {
@@ -109,7 +109,7 @@ void snd_ad1848_out(ad1848_t *chip,
                udelay(100);
 #ifdef CONFIG_SND_DEBUG
        if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
-               snd_printk("auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
+               snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x, value = 0x%x\n", reg, value);
 #endif
        outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
        outb(chip->image[reg] = value, AD1848P(chip, REG));
@@ -119,9 +119,10 @@ void snd_ad1848_out(ad1848_t *chip,
 #endif
 }
 
-void snd_ad1848_dout(ad1848_t *chip,
-                    unsigned char reg,
-                    unsigned char value)
+EXPORT_SYMBOL(snd_ad1848_out);
+
+static void snd_ad1848_dout(struct snd_ad1848 *chip,
+                           unsigned char reg, unsigned char value)
 {
        int timeout;
 
@@ -132,7 +133,7 @@ void snd_ad1848_dout(ad1848_t *chip,
        mb();
 }
 
-unsigned char snd_ad1848_in(ad1848_t *chip, unsigned char reg)
+static unsigned char snd_ad1848_in(struct snd_ad1848 *chip, unsigned char reg)
 {
        int timeout;
 
@@ -140,16 +141,16 @@ unsigned char snd_ad1848_in(ad1848_t *chip, unsigned char reg)
                udelay(100);
 #ifdef CONFIG_SND_DEBUG
        if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
-               snd_printk("auto calibration time out - reg = 0x%x\n", reg);
+               snd_printk(KERN_WARNING "auto calibration time out - reg = 0x%x\n", reg);
 #endif
        outb(chip->mce_bit | reg, AD1848P(chip, REGSEL));
        mb();
        return inb(AD1848P(chip, REG));
 }
 
-#ifdef CONFIG_SND_DEBUG
+#if 0
 
-void snd_ad1848_debug(ad1848_t *chip)
+static void snd_ad1848_debug(struct snd_ad1848 *chip)
 {
        printk("AD1848 REGS:      INDEX = 0x%02x  ", inb(AD1848P(chip, REGSEL)));
        printk("                 STATUS = 0x%02x\n", inb(AD1848P(chip, STATUS)));
@@ -177,7 +178,7 @@ void snd_ad1848_debug(ad1848_t *chip)
  *  AD1848 detection / MCE routines
  */
 
-void snd_ad1848_mce_up(ad1848_t *chip)
+static void snd_ad1848_mce_up(struct snd_ad1848 *chip)
 {
        unsigned long flags;
        int timeout;
@@ -186,19 +187,19 @@ void snd_ad1848_mce_up(ad1848_t *chip)
                udelay(100);
 #ifdef CONFIG_SND_DEBUG
        if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
-               snd_printk("mce_up - auto calibration time out (0)\n");
+               snd_printk(KERN_WARNING "mce_up - auto calibration time out (0)\n");
 #endif
        spin_lock_irqsave(&chip->reg_lock, flags);
        chip->mce_bit |= AD1848_MCE;
        timeout = inb(AD1848P(chip, REGSEL));
        if (timeout == 0x80)
-               snd_printk("mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
+               snd_printk(KERN_WARNING "mce_up [0x%lx]: serious init problem - codec still busy\n", chip->port);
        if (!(timeout & AD1848_MCE))
                outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-void snd_ad1848_mce_down(ad1848_t *chip)
+static void snd_ad1848_mce_down(struct snd_ad1848 *chip)
 {
        unsigned long flags;
        int timeout;
@@ -215,13 +216,13 @@ void snd_ad1848_mce_down(ad1848_t *chip)
 #endif
 #ifdef CONFIG_SND_DEBUG
        if (inb(AD1848P(chip, REGSEL)) & AD1848_INIT)
-               snd_printk("mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
+               snd_printk(KERN_WARNING "mce_down [0x%lx] - auto calibration time out (0)\n", AD1848P(chip, REGSEL));
 #endif
        chip->mce_bit &= ~AD1848_MCE;
        timeout = inb(AD1848P(chip, REGSEL));
        outb(chip->mce_bit | (timeout & 0x1f), AD1848P(chip, REGSEL));
        if (timeout == 0x80)
-               snd_printk("mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
+               snd_printk(KERN_WARNING "mce_down [0x%lx]: serious init problem - codec still busy\n", chip->port);
        if ((timeout & AD1848_MCE) == 0) {
                spin_unlock_irqrestore(&chip->reg_lock, flags);
                return;
@@ -241,11 +242,10 @@ void snd_ad1848_mce_down(ad1848_t *chip)
        while (snd_ad1848_in(chip, AD1848_TEST_INIT) & AD1848_CALIB_IN_PROGRESS) {
                spin_unlock_irqrestore(&chip->reg_lock, flags);
                if (time <= 0) {
-                       snd_printk("mce_down - auto calibration time out (2)\n");
+                       snd_printk(KERN_ERR "mce_down - auto calibration time out (2)\n");
                        return;
                }
-               set_current_state(TASK_INTERRUPTIBLE);
-               time = schedule_timeout(time);
+               time = schedule_timeout_interruptible(time);
                spin_lock_irqsave(&chip->reg_lock, flags);
        }
 #if 0
@@ -255,11 +255,10 @@ void snd_ad1848_mce_down(ad1848_t *chip)
        while (inb(AD1848P(chip, REGSEL)) & AD1848_INIT) {
                spin_unlock_irqrestore(&chip->reg_lock, flags);
                if (time <= 0) {
-                       snd_printk("mce_down - auto calibration time out (3)\n");
+                       snd_printk(KERN_ERR "mce_down - auto calibration time out (3)\n");
                        return;
                }
-               set_current_state(TASK_INTERRUPTIBLE);
-               time = schedule_timeout(time);
+               time = schedule_timeout_interruptible(time);
                spin_lock_irqsave(&chip->reg_lock, flags);
        }
        spin_unlock_irqrestore(&chip->reg_lock, flags);
@@ -282,7 +281,7 @@ static unsigned int snd_ad1848_get_count(unsigned char format,
        return size;
 }
 
-static int snd_ad1848_trigger(ad1848_t *chip, unsigned char what,
+static int snd_ad1848_trigger(struct snd_ad1848 *chip, unsigned char what,
                              int channel, int cmd)
 {
        int result = 0;
@@ -327,7 +326,7 @@ static unsigned char snd_ad1848_get_rate(unsigned int rate)
        return freq_bits[13];
 }
 
-static int snd_ad1848_ioctl(snd_pcm_substream_t * substream,
+static int snd_ad1848_ioctl(struct snd_pcm_substream *substream,
                            unsigned int cmd, void *arg)
 {
        return snd_pcm_lib_ioctl(substream, cmd, arg);
@@ -351,7 +350,7 @@ static unsigned char snd_ad1848_get_format(int format, int channels)
        return rformat;
 }
 
-static void snd_ad1848_calibrate_mute(ad1848_t *chip, int mute)
+static void snd_ad1848_calibrate_mute(struct snd_ad1848 *chip, int mute)
 {
        unsigned long flags;
        
@@ -375,7 +374,7 @@ static void snd_ad1848_calibrate_mute(ad1848_t *chip, int mute)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 }
 
-static void snd_ad1848_set_data_format(ad1848_t *chip, snd_pcm_hw_params_t *hw_params)
+static void snd_ad1848_set_data_format(struct snd_ad1848 *chip, struct snd_pcm_hw_params *hw_params)
 {
        if (hw_params == NULL) {
                chip->image[AD1848_DATA_FORMAT] = 0x20;
@@ -387,13 +386,13 @@ static void snd_ad1848_set_data_format(ad1848_t *chip, snd_pcm_hw_params_t *hw_p
        // snd_printk(">>> pmode = 0x%x, dfr = 0x%x\n", pstr->mode, chip->image[AD1848_DATA_FORMAT]);
 }
 
-static int snd_ad1848_open(ad1848_t *chip, unsigned int mode)
+static int snd_ad1848_open(struct snd_ad1848 *chip, unsigned int mode)
 {
        unsigned long flags;
 
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        if (chip->mode & AD1848_MODE_OPEN) {
-               up(&chip->open_mutex);
+               mutex_unlock(&chip->open_mutex);
                return -EAGAIN;
        }
        snd_ad1848_mce_down(chip);
@@ -436,18 +435,18 @@ static int snd_ad1848_open(ad1848_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_ad1848_close(ad1848_t *chip)
+static void snd_ad1848_close(struct snd_ad1848 *chip)
 {
        unsigned long flags;
 
-       down(&chip->open_mutex);
+       mutex_lock(&chip->open_mutex);
        if (!chip->mode) {
-               up(&chip->open_mutex);
+               mutex_unlock(&chip->open_mutex);
                return;
        }
        /* disable IRQ */
@@ -475,31 +474,31 @@ static void snd_ad1848_close(ad1848_t *chip)
        spin_unlock_irqrestore(&chip->reg_lock, flags);
 
        chip->mode = 0;
-       up(&chip->open_mutex);
+       mutex_unlock(&chip->open_mutex);
 }
 
 /*
  *  ok.. exported functions..
  */
 
-static int snd_ad1848_playback_trigger(snd_pcm_substream_t * substream,
+static int snd_ad1848_playback_trigger(struct snd_pcm_substream *substream,
                                       int cmd)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        return snd_ad1848_trigger(chip, AD1848_PLAYBACK_ENABLE, SNDRV_PCM_STREAM_PLAYBACK, cmd);
 }
 
-static int snd_ad1848_capture_trigger(snd_pcm_substream_t * substream,
+static int snd_ad1848_capture_trigger(struct snd_pcm_substream *substream,
                                      int cmd)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        return snd_ad1848_trigger(chip, AD1848_CAPTURE_ENABLE, SNDRV_PCM_STREAM_CAPTURE, cmd);
 }
 
-static int snd_ad1848_playback_hw_params(snd_pcm_substream_t * substream,
-                                        snd_pcm_hw_params_t * hw_params)
+static int snd_ad1848_playback_hw_params(struct snd_pcm_substream *substream,
+                                        struct snd_pcm_hw_params *hw_params)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        unsigned long flags;
        int err;
 
@@ -516,15 +515,15 @@ static int snd_ad1848_playback_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_ad1848_playback_hw_free(snd_pcm_substream_t * substream)
+static int snd_ad1848_playback_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static int snd_ad1848_playback_prepare(snd_pcm_substream_t * substream)
+static int snd_ad1848_playback_prepare(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_ad1848 *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);
@@ -540,10 +539,10 @@ static int snd_ad1848_playback_prepare(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_ad1848_capture_hw_params(snd_pcm_substream_t * substream,
-                                       snd_pcm_hw_params_t * hw_params)
+static int snd_ad1848_capture_hw_params(struct snd_pcm_substream *substream,
+                                       struct snd_pcm_hw_params *hw_params)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        unsigned long flags;
        int err;
 
@@ -560,15 +559,15 @@ static int snd_ad1848_capture_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_ad1848_capture_hw_free(snd_pcm_substream_t * substream)
+static int snd_ad1848_capture_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static int snd_ad1848_capture_prepare(snd_pcm_substream_t * substream)
+static int snd_ad1848_capture_prepare(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_ad1848 *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);
@@ -584,9 +583,9 @@ static int snd_ad1848_capture_prepare(snd_pcm_substream_t * substream)
        return 0;
 }
 
-irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id)
 {
-       ad1848_t *chip = dev_id;
+       struct snd_ad1848 *chip = dev_id;
 
        if ((chip->mode & AD1848_MODE_PLAY) && chip->playback_substream &&
            (chip->mode & AD1848_MODE_RUNNING))
@@ -598,9 +597,9 @@ irqreturn_t snd_ad1848_interrupt(int irq, void *dev_id, struct pt_regs *regs)
        return IRQ_HANDLED;
 }
 
-static snd_pcm_uframes_t snd_ad1848_playback_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_ad1848_playback_pointer(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
        
        if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_PLAYBACK_ENABLE))
@@ -609,9 +608,9 @@ static snd_pcm_uframes_t snd_ad1848_playback_pointer(snd_pcm_substream_t * subst
        return bytes_to_frames(substream->runtime, ptr);
 }
 
-static snd_pcm_uframes_t snd_ad1848_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_ad1848_capture_pointer(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
 
        if (!(chip->image[AD1848_IFACE_CTRL] & AD1848_CAPTURE_ENABLE))
@@ -624,7 +623,7 @@ static snd_pcm_uframes_t snd_ad1848_capture_pointer(snd_pcm_substream_t * substr
 
  */
 
-static void snd_ad1848_thinkpad_twiddle(ad1848_t *chip, int on) {
+static void snd_ad1848_thinkpad_twiddle(struct snd_ad1848 *chip, int on) {
 
        int tmp;
 
@@ -645,41 +644,34 @@ static void snd_ad1848_thinkpad_twiddle(ad1848_t *chip, int on) {
 }
 
 #ifdef CONFIG_PM
-static int snd_ad1848_suspend(snd_card_t *card, unsigned int state)
+static void snd_ad1848_suspend(struct snd_ad1848 *chip)
 {
-       ad1848_t *chip = card->pm_private_data;
-
-       if (card->power_state == SNDRV_CTL_POWER_D3hot)
-               return 0;
-
        snd_pcm_suspend_all(chip->pcm);
-       /* FIXME: save registers? */
-
        if (chip->thinkpad_flag)
                snd_ad1848_thinkpad_twiddle(chip, 0);
-
-       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
-       return 0;
 }
 
-static int snd_ad1848_resume(snd_card_t *card, unsigned int state)
+static void snd_ad1848_resume(struct snd_ad1848 *chip)
 {
-       ad1848_t *chip = card->pm_private_data;
-
-       if (card->power_state == SNDRV_CTL_POWER_D0)
-               return 0;
+       int i;
 
        if (chip->thinkpad_flag)
                snd_ad1848_thinkpad_twiddle(chip, 1);
 
-       /* FIXME: restore registers? */
+       /* clear any pendings IRQ */
+       inb(AD1848P(chip, STATUS));
+       outb(0, AD1848P(chip, STATUS));
+       mb();
 
-       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
-       return 0;
+       snd_ad1848_mce_down(chip);
+       for (i = 0; i < 16; i++)
+               snd_ad1848_out(chip, i, chip->image[i]);
+       snd_ad1848_mce_up(chip);
+       snd_ad1848_mce_down(chip);
 }
 #endif /* CONFIG_PM */
 
-static int snd_ad1848_probe(ad1848_t * chip)
+static int snd_ad1848_probe(struct snd_ad1848 * chip)
 {
        unsigned long flags;
        int i, id, rev, ad1847;
@@ -759,7 +751,7 @@ static int snd_ad1848_probe(ad1848_t * chip)
 
  */
 
-static snd_pcm_hardware_t snd_ad1848_playback =
+static struct snd_pcm_hardware snd_ad1848_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_MMAP_VALID),
@@ -778,7 +770,7 @@ static snd_pcm_hardware_t snd_ad1848_playback =
        .fifo_size =            0,
 };
 
-static snd_pcm_hardware_t snd_ad1848_capture =
+static struct snd_pcm_hardware snd_ad1848_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_MMAP_VALID),
@@ -801,10 +793,10 @@ static snd_pcm_hardware_t snd_ad1848_capture =
 
  */
 
-static int snd_ad1848_playback_open(snd_pcm_substream_t * substream)
+static int snd_ad1848_playback_open(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = snd_ad1848_open(chip, AD1848_MODE_PLAY)) < 0)
@@ -817,10 +809,10 @@ static int snd_ad1848_playback_open(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_ad1848_capture_open(snd_pcm_substream_t * substream)
+static int snd_ad1848_capture_open(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = snd_ad1848_open(chip, AD1848_MODE_CAPTURE)) < 0)
@@ -833,9 +825,9 @@ static int snd_ad1848_capture_open(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_ad1848_playback_close(snd_pcm_substream_t * substream)
+static int snd_ad1848_playback_close(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
 
        chip->mode &= ~AD1848_MODE_PLAY;
        chip->playback_substream = NULL;
@@ -843,9 +835,9 @@ static int snd_ad1848_playback_close(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_ad1848_capture_close(snd_pcm_substream_t * substream)
+static int snd_ad1848_capture_close(struct snd_pcm_substream *substream)
 {
-       ad1848_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ad1848 *chip = snd_pcm_substream_chip(substream);
 
        chip->mode &= ~AD1848_MODE_CAPTURE;
        chip->capture_substream = NULL;
@@ -853,12 +845,9 @@ static int snd_ad1848_capture_close(snd_pcm_substream_t * substream)
        return 0;
 }
 
-static int snd_ad1848_free(ad1848_t *chip)
+static int snd_ad1848_free(struct snd_ad1848 *chip)
 {
-       if (chip->res_port) {
-               release_resource(chip->res_port);
-               kfree_nocheck(chip->res_port);
-       }
+       release_and_free_resource(chip->res_port);
        if (chip->irq >= 0)
                free_irq(chip->irq, (void *) chip);
        if (chip->dma >= 0) {
@@ -869,13 +858,13 @@ static int snd_ad1848_free(ad1848_t *chip)
        return 0;
 }
 
-static int snd_ad1848_dev_free(snd_device_t *device)
+static int snd_ad1848_dev_free(struct snd_device *device)
 {
-       ad1848_t *chip = device->device_data;
+       struct snd_ad1848 *chip = device->device_data;
        return snd_ad1848_free(chip);
 }
 
-static const char *snd_ad1848_chip_id(ad1848_t *chip)
+static const char *snd_ad1848_chip_id(struct snd_ad1848 *chip)
 {
        switch (chip->hardware) {
        case AD1848_HW_AD1847:  return "AD1847";
@@ -886,24 +875,24 @@ static const char *snd_ad1848_chip_id(ad1848_t *chip)
        }
 }
 
-int snd_ad1848_create(snd_card_t * card,
+int snd_ad1848_create(struct snd_card *card,
                      unsigned long port,
                      int irq, int dma,
                      unsigned short hardware,
-                     ad1848_t ** rchip)
+                     struct snd_ad1848 ** rchip)
 {
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free =     snd_ad1848_dev_free,
        };
-       ad1848_t *chip;
+       struct snd_ad1848 *chip;
        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);
-       init_MUTEX(&chip->open_mutex);
+       mutex_init(&chip->open_mutex);
        chip->card = card;
        chip->port = port;
        chip->irq = -1;
@@ -916,7 +905,7 @@ int snd_ad1848_create(snd_card_t * card,
                snd_ad1848_free(chip);
                return -EBUSY;
        }
-       if (request_irq(irq, snd_ad1848_interrupt, SA_INTERRUPT, "AD1848", (void *) chip)) {
+       if (request_irq(irq, snd_ad1848_interrupt, IRQF_DISABLED, "AD1848", (void *) chip)) {
                snd_printk(KERN_ERR "ad1848: can't grab IRQ %d\n", irq);
                snd_ad1848_free(chip);
                return -EBUSY;
@@ -933,7 +922,6 @@ int snd_ad1848_create(snd_card_t * card,
                chip->thinkpad_flag = 1;
                chip->hardware = AD1848_HW_DETECT; /* reset */
                snd_ad1848_thinkpad_twiddle(chip, 1);
-               snd_card_set_isa_pm_callback(card, snd_ad1848_suspend, snd_ad1848_resume, chip);
        }
 
        if (snd_ad1848_probe(chip) < 0) {
@@ -947,11 +935,18 @@ int snd_ad1848_create(snd_card_t * card,
                return err;
        }
 
+#ifdef CONFIG_PM
+       chip->suspend = snd_ad1848_suspend;
+       chip->resume = snd_ad1848_resume;
+#endif
+
        *rchip = chip;
        return 0;
 }
 
-static snd_pcm_ops_t snd_ad1848_playback_ops = {
+EXPORT_SYMBOL(snd_ad1848_create);
+
+static struct snd_pcm_ops snd_ad1848_playback_ops = {
        .open =         snd_ad1848_playback_open,
        .close =        snd_ad1848_playback_close,
        .ioctl =        snd_ad1848_ioctl,
@@ -962,7 +957,7 @@ static snd_pcm_ops_t snd_ad1848_playback_ops = {
        .pointer =      snd_ad1848_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_ad1848_capture_ops = {
+static struct snd_pcm_ops snd_ad1848_capture_ops = {
        .open =         snd_ad1848_capture_open,
        .close =        snd_ad1848_capture_close,
        .ioctl =        snd_ad1848_ioctl,
@@ -973,16 +968,9 @@ static snd_pcm_ops_t snd_ad1848_capture_ops = {
        .pointer =      snd_ad1848_capture_pointer,
 };
 
-static void snd_ad1848_pcm_free(snd_pcm_t *pcm)
+int snd_ad1848_pcm(struct snd_ad1848 *chip, int device, struct snd_pcm **rpcm)
 {
-       ad1848_t *chip = pcm->private_data;
-       chip->pcm = NULL;
-       snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-int snd_ad1848_pcm(ad1848_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, "AD1848", device, 1, 1, &pcm)) < 0)
@@ -991,7 +979,6 @@ int snd_ad1848_pcm(ad1848_t *chip, int device, snd_pcm_t **rpcm)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_ad1848_playback_ops);
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_ad1848_capture_ops);
 
-       pcm->private_free = snd_ad1848_pcm_free;
        pcm->private_data = chip;
        pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
        strcpy(pcm->name, snd_ad1848_chip_id(chip));
@@ -1006,17 +993,21 @@ int snd_ad1848_pcm(ad1848_t *chip, int device, snd_pcm_t **rpcm)
        return 0;
 }
 
-const snd_pcm_ops_t *snd_ad1848_get_pcm_ops(int direction)
+EXPORT_SYMBOL(snd_ad1848_pcm);
+
+const struct snd_pcm_ops *snd_ad1848_get_pcm_ops(int direction)
 {
        return direction == SNDRV_PCM_STREAM_PLAYBACK ?
                &snd_ad1848_playback_ops : &snd_ad1848_capture_ops;
 }
 
+EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
+
 /*
  *  MIXER part
  */
 
-static int snd_ad1848_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ad1848_info_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        static char *texts[4] = {
                "Line", "Aux", "Mic", "Mix"
@@ -1031,9 +1022,9 @@ static int snd_ad1848_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * u
        return 0;
 }
 
-static int snd_ad1848_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_get_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        
        spin_lock_irqsave(&chip->reg_lock, flags);
@@ -1043,9 +1034,9 @@ static int snd_ad1848_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
        return 0;
 }
 
-static int snd_ad1848_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_put_mux(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        unsigned short left, right;
        int change;
@@ -1066,7 +1057,7 @@ static int snd_ad1848_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t *
        return change;
 }
 
-static int snd_ad1848_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ad1848_info_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
 
@@ -1077,9 +1068,9 @@ static int snd_ad1848_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int snd_ad1848_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_get_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0xff;
@@ -1094,9 +1085,9 @@ static int snd_ad1848_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_ad1848_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_put_single(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int reg = kcontrol->private_value & 0xff;
        int shift = (kcontrol->private_value >> 8) & 0xff;
@@ -1117,7 +1108,7 @@ static int snd_ad1848_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return change;
 }
 
-static int snd_ad1848_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_ad1848_info_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 24) & 0xff;
 
@@ -1128,9 +1119,9 @@ static int snd_ad1848_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int snd_ad1848_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
@@ -1150,9 +1141,9 @@ static int snd_ad1848_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_ad1848_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ad1848_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
 {
-       ad1848_t *chip = snd_kcontrol_chip(kcontrol);
+       struct snd_ad1848 *chip = snd_kcontrol_chip(kcontrol);
        unsigned long flags;
        int left_reg = kcontrol->private_value & 0xff;
        int right_reg = (kcontrol->private_value >> 8) & 0xff;
@@ -1189,9 +1180,10 @@ static int snd_ad1848_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
 
 /*
  */
-int snd_ad1848_add_ctl(ad1848_t *chip, const char *name, int index, int type, unsigned long value)
+int snd_ad1848_add_ctl_elem(struct snd_ad1848 *chip,
+                           const struct ad1848_mix_elem *c)
 {
-       static snd_kcontrol_new_t newctls[] = {
+       static struct snd_kcontrol_new newctls[] = {
                [AD1848_MIX_SINGLE] = {
                        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                        .info = snd_ad1848_info_single,
@@ -1205,48 +1197,61 @@ int snd_ad1848_add_ctl(ad1848_t *chip, const char *name, int index, int type, un
                        .put = snd_ad1848_put_double,
                },
                [AD1848_MIX_CAPTURE] = {
+                       .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
                        .info = snd_ad1848_info_mux,
                        .get = snd_ad1848_get_mux,
                        .put = snd_ad1848_put_mux,
                },
        };
-       snd_kcontrol_t *ctl;
+       struct snd_kcontrol *ctl;
        int err;
 
-       ctl = snd_ctl_new1(&newctls[type], chip);
+       ctl = snd_ctl_new1(&newctls[c->type], chip);
        if (! ctl)
                return -ENOMEM;
-       strlcpy(ctl->id.name, name, sizeof(ctl->id.name));
-       ctl->id.index = index;
-       ctl->private_value = value;
-       if ((err = snd_ctl_add(chip->card, ctl)) < 0) {
-               snd_ctl_free_one(ctl);
-               return err;
+       strlcpy(ctl->id.name, c->name, sizeof(ctl->id.name));
+       ctl->id.index = c->index;
+       ctl->private_value = c->private_value;
+       if (c->tlv) {
+               ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
+               ctl->tlv.p = c->tlv;
        }
+       if ((err = snd_ctl_add(chip->card, ctl)) < 0)
+               return err;
        return 0;
 }
 
+EXPORT_SYMBOL(snd_ad1848_add_ctl_elem);
+
+static DECLARE_TLV_DB_SCALE(db_scale_6bit, -9450, 150, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_5bit_12db_max, -3450, 150, 0);
+static DECLARE_TLV_DB_SCALE(db_scale_rec_gain, 0, 150, 0);
 
 static struct ad1848_mix_elem snd_ad1848_controls[] = {
 AD1848_DOUBLE("PCM Playback Switch", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 7, 7, 1, 1),
-AD1848_DOUBLE("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1),
+AD1848_DOUBLE_TLV("PCM Playback Volume", 0, AD1848_LEFT_OUTPUT, AD1848_RIGHT_OUTPUT, 0, 0, 63, 1,
+                 db_scale_6bit),
 AD1848_DOUBLE("Aux Playback Switch", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 7, 7, 1, 1),
-AD1848_DOUBLE("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1),
+AD1848_DOUBLE_TLV("Aux Playback Volume", 0, AD1848_AUX1_LEFT_INPUT, AD1848_AUX1_RIGHT_INPUT, 0, 0, 31, 1,
+                 db_scale_5bit_12db_max),
 AD1848_DOUBLE("Aux Playback Switch", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 7, 7, 1, 1),
-AD1848_DOUBLE("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1),
-AD1848_DOUBLE("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0),
+AD1848_DOUBLE_TLV("Aux Playback Volume", 1, AD1848_AUX2_LEFT_INPUT, AD1848_AUX2_RIGHT_INPUT, 0, 0, 31, 1,
+                 db_scale_5bit_12db_max),
+AD1848_DOUBLE_TLV("Capture Volume", 0, AD1848_LEFT_INPUT, AD1848_RIGHT_INPUT, 0, 0, 15, 0,
+                 db_scale_rec_gain),
 {
        .name = "Capture Source",
        .type = AD1848_MIX_CAPTURE,
 },
 AD1848_SINGLE("Loopback Capture Switch", 0, AD1848_LOOPBACK, 0, 1, 0),
-AD1848_SINGLE("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0)
+AD1848_SINGLE_TLV("Loopback Capture Volume", 0, AD1848_LOOPBACK, 1, 63, 0,
+                 db_scale_6bit),
 };
                                         
-int snd_ad1848_mixer(ad1848_t *chip)
+int snd_ad1848_mixer(struct snd_ad1848 *chip)
 {
-       snd_card_t *card;
-       snd_pcm_t *pcm;
+       struct snd_card *card;
+       struct snd_pcm *pcm;
        unsigned int idx;
        int err;
 
@@ -1264,17 +1269,7 @@ int snd_ad1848_mixer(ad1848_t *chip)
        return 0;
 }
 
-EXPORT_SYMBOL(snd_ad1848_in);
-EXPORT_SYMBOL(snd_ad1848_out);
-EXPORT_SYMBOL(snd_ad1848_dout);
-EXPORT_SYMBOL(snd_ad1848_mce_up);
-EXPORT_SYMBOL(snd_ad1848_mce_down);
-EXPORT_SYMBOL(snd_ad1848_interrupt);
-EXPORT_SYMBOL(snd_ad1848_create);
-EXPORT_SYMBOL(snd_ad1848_pcm);
-EXPORT_SYMBOL(snd_ad1848_get_pcm_ops);
 EXPORT_SYMBOL(snd_ad1848_mixer);
-EXPORT_SYMBOL(snd_ad1848_add_ctl);
 
 /*
  *  INIT part