fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / pci / fm801.c
index 9a0e158..b7b361c 100644 (file)
@@ -2,6 +2,7 @@
  *  The driver for the ForteMedia FM801 based soundcards
  *  Copyright (c) by Jaroslav Kysela <perex@suse.cz>
  *
+ *  Support FM only card by Andy Shevchenko <andy@smile.org.ua>
  *
  *   This program is free software; you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License as published by
@@ -28,6 +29,7 @@
 #include <linux/moduleparam.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
+#include <sound/tlv.h>
 #include <sound/ac97_codec.h>
 #include <sound/mpu401.h>
 #include <sound/opl3.h>
@@ -35,7 +37,7 @@
 
 #include <asm/io.h>
 
-#if (defined(CONFIG_SND_FM801_TEA575X) || defined(CONFIG_SND_FM801_TEA575X_MODULE)) && (defined(CONFIG_VIDEO_DEV) || defined(CONFIG_VIDEO_DEV_MODULE))
+#ifdef CONFIG_SND_FM801_TEA575X_BOOL
 #include <sound/tea575x-tuner.h>
 #define TEA575X_RADIO 1
 #endif
@@ -54,18 +56,18 @@ static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;  /* Enable this card *
  *    1 = MediaForte 256-PCS
  *    2 = MediaForte 256-PCPR
  *    3 = MediaForte 64-PCR
+ *   16 = setup tuner only (this is additional bit), i.e. SF-64-PCR FM card
  *  High 16-bits are video (radio) device number + 1
  */
-static int tea575x_tuner[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = 0 };
-static int boot_devs;
+static int tea575x_tuner[SNDRV_CARDS];
 
-module_param_array(index, int, boot_devs, 0444);
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for the FM801 soundcard.");
-module_param_array(id, charp, boot_devs, 0444);
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for the FM801 soundcard.");
-module_param_array(enable, bool, boot_devs, 0444);
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
-module_param_array(tea575x_tuner, bool, boot_devs, 0444);
+module_param_array(tea575x_tuner, int, NULL, 0444);
 MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
 
 /*
@@ -104,7 +106,11 @@ MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
 #define FM801_OPL3_DATA1       0x6b    /* OPL3 Bank 1 Write */
 #define FM801_POWERDOWN                0x70    /* Blocks Power Down Control */
 
-#define FM801_AC97_ADDR_SHIFT  10
+/* codec access */
+#define FM801_AC97_READ                (1<<7)  /* read=1, write=0 */
+#define FM801_AC97_VALID       (1<<8)  /* port valid=1 */
+#define FM801_AC97_BUSY                (1<<9)  /* busy=1 */
+#define FM801_AC97_ADDR_SHIFT  10      /* codec id (2bit) */
 
 /* playback and record control register bits */
 #define FM801_BUF1_LAST                (1<<1)
@@ -148,15 +154,14 @@ MODULE_PARM_DESC(tea575x_tuner, "Enable TEA575x tuner.");
 
  */
 
-typedef struct _snd_fm801 fm801_t;
-
-struct _snd_fm801 {
+struct fm801 {
        int irq;
 
        unsigned long port;     /* I/O port number */
        unsigned int multichannel: 1,   /* multichannel support */
                     secondary: 1;      /* secondary codec */
        unsigned char secondary_addr;   /* address of the secondary codec */
+       unsigned int tea575x_tuner;     /* tuner flags */
 
        unsigned short ply_ctrl; /* playback control */
        unsigned short cap_ctrl; /* capture control */
@@ -173,29 +178,34 @@ struct _snd_fm801 {
        unsigned int cap_size;
        unsigned int cap_pos;
 
-       ac97_bus_t *ac97_bus;
-       ac97_t *ac97;
-       ac97_t *ac97_sec;
+       struct snd_ac97_bus *ac97_bus;
+       struct snd_ac97 *ac97;
+       struct snd_ac97 *ac97_sec;
 
        struct pci_dev *pci;
-       snd_card_t *card;
-       snd_pcm_t *pcm;
-       snd_rawmidi_t *rmidi;
-       snd_pcm_substream_t *playback_substream;
-       snd_pcm_substream_t *capture_substream;
+       struct snd_card *card;
+       struct snd_pcm *pcm;
+       struct snd_rawmidi *rmidi;
+       struct snd_pcm_substream *playback_substream;
+       struct snd_pcm_substream *capture_substream;
        unsigned int p_dma_size;
        unsigned int c_dma_size;
 
        spinlock_t reg_lock;
-       snd_info_entry_t *proc_entry;
+       struct snd_info_entry *proc_entry;
 
 #ifdef TEA575X_RADIO
-       tea575x_t tea;
+       struct snd_tea575x tea;
+#endif
+
+#ifdef CONFIG_PM
+       u16 saved_regs[0x20];
 #endif
 };
 
 static struct pci_device_id snd_fm801_ids[] = {
        { 0x1319, 0x0801, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* FM801 */
+       { 0x5213, 0x0510, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MULTIMEDIA_AUDIO << 8, 0xffff00, 0, },   /* Gallant Odyssey Sound 4 */
        { 0, }
 };
 
@@ -205,38 +215,39 @@ MODULE_DEVICE_TABLE(pci, snd_fm801_ids);
  *  common I/O routines
  */
 
-static int snd_fm801_update_bits(fm801_t *chip, unsigned short reg,
+static int snd_fm801_update_bits(struct fm801 *chip, unsigned short reg,
                                 unsigned short mask, unsigned short value)
 {
        int change;
+       unsigned long flags;
        unsigned short old, new;
 
-       spin_lock(&chip->reg_lock);
+       spin_lock_irqsave(&chip->reg_lock, flags);
        old = inw(chip->port + reg);
        new = (old & ~mask) | value;
        change = old != new;
        if (change)
                outw(new, chip->port + reg);
-       spin_unlock(&chip->reg_lock);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
        return change;
 }
 
-static void snd_fm801_codec_write(ac97_t *ac97,
+static void snd_fm801_codec_write(struct snd_ac97 *ac97,
                                  unsigned short reg,
                                  unsigned short val)
 {
-       fm801_t *chip = ac97->private_data;
+       struct fm801 *chip = ac97->private_data;
        int idx;
 
        /*
         *  Wait until the codec interface is not ready..
         */
        for (idx = 0; idx < 100; idx++) {
-               if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+               if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
                        goto ok1;
                udelay(10);
        }
-       snd_printk("AC'97 interface is busy (1)\n");
+       snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
        return;
 
  ok1:
@@ -247,47 +258,48 @@ static void snd_fm801_codec_write(ac97_t *ac97,
         *  Wait until the write command is not completed..
          */
        for (idx = 0; idx < 1000; idx++) {
-               if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+               if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
                        return;
                udelay(10);
        }
-       snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num);
+       snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
 }
 
-static unsigned short snd_fm801_codec_read(ac97_t *ac97, unsigned short reg)
+static unsigned short snd_fm801_codec_read(struct snd_ac97 *ac97, unsigned short reg)
 {
-       fm801_t *chip = ac97->private_data;
+       struct fm801 *chip = ac97->private_data;
        int idx;
 
        /*
         *  Wait until the codec interface is not ready..
         */
        for (idx = 0; idx < 100; idx++) {
-               if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+               if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
                        goto ok1;
                udelay(10);
        }
-       snd_printk("AC'97 interface is busy (1)\n");
+       snd_printk(KERN_ERR "AC'97 interface is busy (1)\n");
        return 0;
 
  ok1:
        /* read command */
-       outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | (1<<7), FM801_REG(chip, AC97_CMD));
+       outw(reg | (ac97->addr << FM801_AC97_ADDR_SHIFT) | FM801_AC97_READ,
+            FM801_REG(chip, AC97_CMD));
        for (idx = 0; idx < 100; idx++) {
-               if (!(inw(FM801_REG(chip, AC97_CMD)) & (1<<9)))
+               if (!(inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_BUSY))
                        goto ok2;
                udelay(10);
        }
-       snd_printk("AC'97 interface #%d is busy (2)\n", ac97->num);
+       snd_printk(KERN_ERR "AC'97 interface #%d is busy (2)\n", ac97->num);
        return 0;
 
  ok2:
        for (idx = 0; idx < 1000; idx++) {
-               if (inw(FM801_REG(chip, AC97_CMD)) & (1<<8))
+               if (inw(FM801_REG(chip, AC97_CMD)) & FM801_AC97_VALID)
                        goto ok3;
                udelay(10);
        }
-       snd_printk("AC'97 interface #%d is not valid (2)\n", ac97->num);
+       snd_printk(KERN_ERR "AC'97 interface #%d is not valid (2)\n", ac97->num);
        return 0;
 
  ok3:
@@ -300,7 +312,7 @@ static unsigned int rates[] = {
   38400, 44100, 48000
 };
 
-static snd_pcm_hw_constraint_list_t hw_constraints_rates = {
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
        .count = ARRAY_SIZE(rates),
        .list = rates,
        .mask = 0,
@@ -310,10 +322,8 @@ static unsigned int channels[] = {
   2, 4, 6
 };
 
-#define CHANNELS sizeof(channels) / sizeof(channels[0])
-
-static snd_pcm_hw_constraint_list_t hw_constraints_channels = {
-       .count = CHANNELS,
+static struct snd_pcm_hw_constraint_list hw_constraints_channels = {
+       .count = ARRAY_SIZE(channels),
        .list = channels,
        .mask = 0,
 };
@@ -337,10 +347,10 @@ static unsigned short snd_fm801_rate_bits(unsigned int rate)
  *  PCM part
  */
 
-static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
+static int snd_fm801_playback_trigger(struct snd_pcm_substream *substream,
                                      int cmd)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
 
        spin_lock(&chip->reg_lock);
        switch (cmd) {
@@ -355,9 +365,11 @@ static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
                chip->ply_ctrl &= ~(FM801_START | FM801_PAUSE);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                chip->ply_ctrl |= FM801_PAUSE;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+       case SNDRV_PCM_TRIGGER_RESUME:
                chip->ply_ctrl &= ~FM801_PAUSE;
                break;
        default:
@@ -370,10 +382,10 @@ static int snd_fm801_playback_trigger(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
+static int snd_fm801_capture_trigger(struct snd_pcm_substream *substream,
                                     int cmd)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
 
        spin_lock(&chip->reg_lock);
        switch (cmd) {
@@ -388,9 +400,11 @@ static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
                chip->cap_ctrl &= ~(FM801_START | FM801_PAUSE);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                chip->cap_ctrl |= FM801_PAUSE;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+       case SNDRV_PCM_TRIGGER_RESUME:
                chip->cap_ctrl &= ~FM801_PAUSE;
                break;
        default:
@@ -403,26 +417,25 @@ static int snd_fm801_capture_trigger(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_fm801_hw_params(snd_pcm_substream_t * substream,
-                              snd_pcm_hw_params_t * hw_params)
+static int snd_fm801_hw_params(struct snd_pcm_substream *substream,
+                              struct snd_pcm_hw_params *hw_params)
 {
        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
 }
 
-static int snd_fm801_hw_free(snd_pcm_substream_t * substream)
+static int snd_fm801_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static int snd_fm801_playback_prepare(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_prepare(struct snd_pcm_substream *substream)
 {
-       unsigned long flags;
-       fm801_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        chip->ply_size = snd_pcm_lib_buffer_bytes(substream);
        chip->ply_count = snd_pcm_lib_period_bytes(substream);
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        chip->ply_ctrl &= ~(FM801_START | FM801_16BIT |
                             FM801_STEREO | FM801_RATE_MASK |
                             FM801_CHANNELS_MASK);
@@ -443,19 +456,18 @@ static int snd_fm801_playback_prepare(snd_pcm_substream_t * substream)
        chip->ply_pos = 0;
        outl(chip->ply_buffer, FM801_REG(chip, PLY_BUF1));
        outl(chip->ply_buffer + (chip->ply_count % chip->ply_size), FM801_REG(chip, PLY_BUF2));
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return 0;
 }
 
-static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_prepare(struct snd_pcm_substream *substream)
 {
-       unsigned long flags;
-       fm801_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        chip->cap_size = snd_pcm_lib_buffer_bytes(substream);
        chip->cap_count = snd_pcm_lib_period_bytes(substream);
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        chip->cap_ctrl &= ~(FM801_START | FM801_16BIT |
                             FM801_STEREO | FM801_RATE_MASK);
        if (snd_pcm_format_width(runtime->format) == 16)
@@ -470,13 +482,13 @@ static int snd_fm801_capture_prepare(snd_pcm_substream_t * substream)
        chip->cap_pos = 0;
        outl(chip->cap_buffer, FM801_REG(chip, CAP_BUF1));
        outl(chip->cap_buffer + (chip->cap_count % chip->cap_size), FM801_REG(chip, CAP_BUF2));
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return 0;
 }
 
-static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_fm801_playback_pointer(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
 
        if (!(chip->ply_ctrl & FM801_START))
@@ -491,9 +503,9 @@ static snd_pcm_uframes_t snd_fm801_playback_pointer(snd_pcm_substream_t * substr
        return bytes_to_frames(substream->runtime, ptr);
 }
 
-static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substream)
+static snd_pcm_uframes_t snd_fm801_capture_pointer(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
        size_t ptr;
 
        if (!(chip->cap_ctrl & FM801_START))
@@ -508,9 +520,9 @@ static snd_pcm_uframes_t snd_fm801_capture_pointer(snd_pcm_substream_t * substre
        return bytes_to_frames(substream->runtime, ptr);
 }
 
-static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id)
 {
-       fm801_t *chip = dev_id;
+       struct fm801 *chip = dev_id;
        unsigned short status;
        unsigned int tmp;
 
@@ -549,18 +561,18 @@ static irqreturn_t snd_fm801_interrupt(int irq, void *dev_id, struct pt_regs *re
                snd_pcm_period_elapsed(chip->capture_substream);
        }
        if (chip->rmidi && (status & FM801_IRQ_MPU))
-               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
+               snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
        if (status & FM801_IRQ_VOLUME)
                ;/* TODO */
 
        return IRQ_HANDLED;
 }
 
-static snd_pcm_hardware_t snd_fm801_playback =
+static struct snd_pcm_hardware snd_fm801_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                                SNDRV_PCM_INFO_PAUSE |
+                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
                                 SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
@@ -576,11 +588,11 @@ static snd_pcm_hardware_t snd_fm801_playback =
        .fifo_size =            0,
 };
 
-static snd_pcm_hardware_t snd_fm801_capture =
+static struct snd_pcm_hardware snd_fm801_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                                SNDRV_PCM_INFO_PAUSE |
+                                SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME |
                                 SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000,
@@ -596,55 +608,59 @@ static snd_pcm_hardware_t snd_fm801_capture =
        .fifo_size =            0,
 };
 
-static int snd_fm801_playback_open(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_open(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        chip->playback_substream = substream;
        runtime->hw = snd_fm801_playback;
-       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                  &hw_constraints_rates);
        if (chip->multichannel) {
                runtime->hw.channels_max = 6;
-               snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels);
+               snd_pcm_hw_constraint_list(runtime, 0,
+                                          SNDRV_PCM_HW_PARAM_CHANNELS,
+                                          &hw_constraints_channels);
        }
        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
                return err;
        return 0;
 }
 
-static int snd_fm801_capture_open(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_open(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        chip->capture_substream = substream;
        runtime->hw = snd_fm801_capture;
-       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+       snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
+                                  &hw_constraints_rates);
        if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
                return err;
        return 0;
 }
 
-static int snd_fm801_playback_close(snd_pcm_substream_t * substream)
+static int snd_fm801_playback_close(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
 
        chip->playback_substream = NULL;
        return 0;
 }
 
-static int snd_fm801_capture_close(snd_pcm_substream_t * substream)
+static int snd_fm801_capture_close(struct snd_pcm_substream *substream)
 {
-       fm801_t *chip = snd_pcm_substream_chip(substream);
+       struct fm801 *chip = snd_pcm_substream_chip(substream);
 
        chip->capture_substream = NULL;
        return 0;
 }
 
-static snd_pcm_ops_t snd_fm801_playback_ops = {
+static struct snd_pcm_ops snd_fm801_playback_ops = {
        .open =         snd_fm801_playback_open,
        .close =        snd_fm801_playback_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -655,7 +671,7 @@ static snd_pcm_ops_t snd_fm801_playback_ops = {
        .pointer =      snd_fm801_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_fm801_capture_ops = {
+static struct snd_pcm_ops snd_fm801_capture_ops = {
        .open =         snd_fm801_capture_open,
        .close =        snd_fm801_capture_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -666,16 +682,9 @@ static snd_pcm_ops_t snd_fm801_capture_ops = {
        .pointer =      snd_fm801_capture_pointer,
 };
 
-static void snd_fm801_pcm_free(snd_pcm_t *pcm)
-{
-       fm801_t *chip = pcm->private_data;
-       chip->pcm = NULL;
-       snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
+static int __devinit snd_fm801_pcm(struct fm801 *chip, int device, struct snd_pcm ** rpcm)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        if (rpcm)
@@ -687,7 +696,6 @@ static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_fm801_capture_ops);
 
        pcm->private_data = chip;
-       pcm->private_free = snd_fm801_pcm_free;
        pcm->info_flags = 0;
        strcpy(pcm->name, "FM801");
        chip->pcm = pcm;
@@ -712,9 +720,9 @@ static int __devinit snd_fm801_pcm(fm801_t *chip, int device, snd_pcm_t ** rpcm)
 #define TEA_256PCS_WRITE_ENABLE                2       /* inverted */
 #define TEA_256PCS_BUS_CLOCK           3
 
-static void snd_fm801_tea575x_256pcs_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_256pcs_write(struct snd_tea575x *tea, unsigned int val)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        int i = 25;
 
@@ -756,9 +764,9 @@ static void snd_fm801_tea575x_256pcs_write(tea575x_t *tea, unsigned int val)
        spin_unlock_irq(&chip->reg_lock);
 }
 
-static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_256pcs_read(struct snd_tea575x *tea)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        unsigned int val = 0;
        int i;
@@ -800,9 +808,9 @@ static unsigned int snd_fm801_tea575x_256pcs_read(tea575x_t *tea)
 #define TEA_256PCPR_DATA               1
 #define TEA_256PCPR_WRITE_ENABLE       2       /* inverted */
 
-static void snd_fm801_tea575x_256pcpr_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_256pcpr_write(struct snd_tea575x *tea, unsigned int val)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        int i = 25;
 
@@ -844,9 +852,9 @@ static void snd_fm801_tea575x_256pcpr_write(tea575x_t *tea, unsigned int val)
        spin_unlock_irq(&chip->reg_lock);
 }
 
-static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_256pcpr_read(struct snd_tea575x *tea)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        unsigned int val = 0;
        int i;
@@ -888,9 +896,9 @@ static unsigned int snd_fm801_tea575x_256pcpr_read(tea575x_t *tea)
 #define TEA_64PCR_WRITE_ENABLE         1       /* inverted */
 #define TEA_64PCR_DATA                 2
 
-static void snd_fm801_tea575x_64pcr_write(tea575x_t *tea, unsigned int val)
+static void snd_fm801_tea575x_64pcr_write(struct snd_tea575x *tea, unsigned int val)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        int i = 25;
 
@@ -932,9 +940,9 @@ static void snd_fm801_tea575x_64pcr_write(tea575x_t *tea, unsigned int val)
        spin_unlock_irq(&chip->reg_lock);
 }
 
-static unsigned int snd_fm801_tea575x_64pcr_read(tea575x_t *tea)
+static unsigned int snd_fm801_tea575x_64pcr_read(struct snd_tea575x *tea)
 {
-       fm801_t *chip = tea->private_data;
+       struct fm801 *chip = tea->private_data;
        unsigned short reg;
        unsigned int val = 0;
        int i;
@@ -999,7 +1007,8 @@ static struct snd_tea575x_ops snd_fm801_tea_ops[3] = {
   .get = snd_fm801_get_single, .put = snd_fm801_put_single, \
   .private_value = reg | (shift << 8) | (mask << 16) | (invert << 24) }
 
-static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_single(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
 
@@ -1010,9 +1019,10 @@ static int snd_fm801_info_single(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
        return 0;
 }
 
-static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_single(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *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;
@@ -1024,9 +1034,10 @@ static int snd_fm801_get_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_single(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *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;
@@ -1043,8 +1054,16 @@ static int snd_fm801_put_single(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .info = snd_fm801_info_double, \
   .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
   .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24) }
+#define FM801_DOUBLE_TLV(xname, reg, shift_left, shift_right, mask, invert, xtlv) \
+{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
+  .access = SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_TLV_READ, \
+  .name = xname, .info = snd_fm801_info_double, \
+  .get = snd_fm801_get_double, .put = snd_fm801_put_double, \
+  .private_value = reg | (shift_left << 8) | (shift_right << 12) | (mask << 16) | (invert << 24), \
+  .tlv = { .p = (xtlv) } }
 
-static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_double(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_info *uinfo)
 {
        int mask = (kcontrol->private_value >> 16) & 0xff;
 
@@ -1055,9 +1074,10 @@ static int snd_fm801_info_double(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *
        return 0;
 }
 
-static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_double(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *chip = snd_kcontrol_chip(kcontrol);
         int reg = kcontrol->private_value & 0xff;
        int shift_left = (kcontrol->private_value >> 8) & 0x0f;
        int shift_right = (kcontrol->private_value >> 12) & 0x0f;
@@ -1075,9 +1095,10 @@ static int snd_fm801_get_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        return 0;
 }
 
-static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_double(struct snd_kcontrol *kcontrol,
+                               struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *chip = snd_kcontrol_chip(kcontrol);
        int reg = kcontrol->private_value & 0xff;
        int shift_left = (kcontrol->private_value >> 8) & 0x0f;
        int shift_right = (kcontrol->private_value >> 12) & 0x0f;
@@ -1096,7 +1117,8 @@ static int snd_fm801_put_double(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                                     (val1 << shift_left ) | (val2 << shift_right));
 }
 
-static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_fm801_info_mux(struct snd_kcontrol *kcontrol,
+                             struct snd_ctl_elem_info *uinfo)
 {
        static char *texts[5] = {
                "AC97 Primary", "FM", "I2S", "PCM", "AC97 Secondary"
@@ -1111,9 +1133,10 @@ static int snd_fm801_info_mux(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t * ui
        return 0;
 }
 
-static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_get_mux(struct snd_kcontrol *kcontrol,
+                            struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *chip = snd_kcontrol_chip(kcontrol);
         unsigned short val;
  
        val = inw(FM801_REG(chip, REC_SRC)) & 7;
@@ -1123,9 +1146,10 @@ static int snd_fm801_get_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * u
         return 0;
 }
 
-static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_fm801_put_mux(struct snd_kcontrol *kcontrol,
+                            struct snd_ctl_elem_value *ucontrol)
 {
-       fm801_t *chip = snd_kcontrol_chip(kcontrol);
+       struct fm801 *chip = snd_kcontrol_chip(kcontrol);
         unsigned short val;
  
         if ((val = ucontrol->value.enumerated.item[0]) > 4)
@@ -1133,14 +1157,19 @@ static int snd_fm801_put_mux(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * u
        return snd_fm801_update_bits(chip, FM801_REC_SRC, 7, val);
 }
 
-#define FM801_CONTROLS (sizeof(snd_fm801_controls)/sizeof(snd_kcontrol_new_t))
+static DECLARE_TLV_DB_SCALE(db_scale_dsp, -3450, 150, 0);
 
-static snd_kcontrol_new_t snd_fm801_controls[] __devinitdata = {
-FM801_DOUBLE("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1),
+#define FM801_CONTROLS ARRAY_SIZE(snd_fm801_controls)
+
+static struct snd_kcontrol_new snd_fm801_controls[] __devinitdata = {
+FM801_DOUBLE_TLV("Wave Playback Volume", FM801_PCM_VOL, 0, 8, 31, 1,
+                db_scale_dsp),
 FM801_SINGLE("Wave Playback Switch", FM801_PCM_VOL, 15, 1, 1),
-FM801_DOUBLE("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1),
+FM801_DOUBLE_TLV("I2S Playback Volume", FM801_I2S_VOL, 0, 8, 31, 1,
+                db_scale_dsp),
 FM801_SINGLE("I2S Playback Switch", FM801_I2S_VOL, 15, 1, 1),
-FM801_DOUBLE("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1),
+FM801_DOUBLE_TLV("FM Playback Volume", FM801_FM_VOL, 0, 8, 31, 1,
+                db_scale_dsp),
 FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
 {
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -1151,26 +1180,26 @@ FM801_SINGLE("FM Playback Switch", FM801_FM_VOL, 15, 1, 1),
 }
 };
 
-#define FM801_CONTROLS_MULTI (sizeof(snd_fm801_controls_multi)/sizeof(snd_kcontrol_new_t))
+#define FM801_CONTROLS_MULTI ARRAY_SIZE(snd_fm801_controls_multi)
 
-static snd_kcontrol_new_t snd_fm801_controls_multi[] __devinitdata = {
+static struct snd_kcontrol_new snd_fm801_controls_multi[] __devinitdata = {
 FM801_SINGLE("AC97 2ch->4ch Copy Switch", FM801_CODEC_CTRL, 7, 1, 0),
 FM801_SINGLE("AC97 18-bit Switch", FM801_CODEC_CTRL, 10, 1, 0),
-FM801_SINGLE("IEC958 Capture Switch", FM801_I2S_MODE, 8, 1, 0),
-FM801_SINGLE("IEC958 Raw Data Playback Switch", FM801_I2S_MODE, 9, 1, 0),
-FM801_SINGLE("IEC958 Raw Data Capture Switch", FM801_I2S_MODE, 10, 1, 0),
-FM801_SINGLE("IEC958 Playback Switch", FM801_GEN_CTRL, 2, 1, 0),
+FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), FM801_I2S_MODE, 8, 1, 0),
+FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",PLAYBACK,SWITCH), FM801_I2S_MODE, 9, 1, 0),
+FM801_SINGLE(SNDRV_CTL_NAME_IEC958("Raw Data ",CAPTURE,SWITCH), FM801_I2S_MODE, 10, 1, 0),
+FM801_SINGLE(SNDRV_CTL_NAME_IEC958("",PLAYBACK,SWITCH), FM801_GEN_CTRL, 2, 1, 0),
 };
 
-static void snd_fm801_mixer_free_ac97_bus(ac97_bus_t *bus)
+static void snd_fm801_mixer_free_ac97_bus(struct snd_ac97_bus *bus)
 {
-       fm801_t *chip = bus->private_data;
+       struct fm801 *chip = bus->private_data;
        chip->ac97_bus = NULL;
 }
 
-static void snd_fm801_mixer_free_ac97(ac97_t *ac97)
+static void snd_fm801_mixer_free_ac97(struct snd_ac97 *ac97)
 {
-       fm801_t *chip = ac97->private_data;
+       struct fm801 *chip = ac97->private_data;
        if (ac97->num == 0) {
                chip->ac97 = NULL;
        } else {
@@ -1178,12 +1207,12 @@ static void snd_fm801_mixer_free_ac97(ac97_t *ac97)
        }
 }
 
-static int __devinit snd_fm801_mixer(fm801_t *chip)
+static int __devinit snd_fm801_mixer(struct fm801 *chip)
 {
-       ac97_template_t ac97;
+       struct snd_ac97_template ac97;
        unsigned int i;
        int err;
-       static ac97_bus_ops_t ops = {
+       static struct snd_ac97_bus_ops ops = {
                .write = snd_fm801_codec_write,
                .read = snd_fm801_codec_read,
        };
@@ -1216,7 +1245,94 @@ static int __devinit snd_fm801_mixer(fm801_t *chip)
  *  initialization routines
  */
 
-static int snd_fm801_free(fm801_t *chip)
+static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
+                         unsigned short reg, unsigned long waits)
+{
+       unsigned long timeout = jiffies + waits;
+
+       outw(FM801_AC97_READ | (codec_id << FM801_AC97_ADDR_SHIFT) | reg,
+            FM801_REG(chip, AC97_CMD));
+       udelay(5);
+       do {
+               if ((inw(FM801_REG(chip, AC97_CMD)) & (FM801_AC97_VALID|FM801_AC97_BUSY))
+                   == FM801_AC97_VALID)
+                       return 0;
+               schedule_timeout_uninterruptible(1);
+       } while (time_after(timeout, jiffies));
+       return -EIO;
+}
+
+static int snd_fm801_chip_init(struct fm801 *chip, int resume)
+{
+       int id;
+       unsigned short cmdw;
+
+       if (chip->tea575x_tuner & 0x0010)
+               goto __ac97_ok;
+
+       /* codec cold reset + AC'97 warm reset */
+       outw((1<<5) | (1<<6), FM801_REG(chip, CODEC_CTRL));
+       inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
+       udelay(100);
+       outw(0, FM801_REG(chip, CODEC_CTRL));
+
+       if (wait_for_codec(chip, 0, AC97_RESET, msecs_to_jiffies(750)) < 0) {
+               snd_printk(KERN_ERR "Primary AC'97 codec not found\n");
+               if (! resume)
+                       return -EIO;
+       }
+
+       if (chip->multichannel) {
+               if (chip->secondary_addr) {
+                       wait_for_codec(chip, chip->secondary_addr,
+                                      AC97_VENDOR_ID1, msecs_to_jiffies(50));
+               } else {
+                       /* my card has the secondary codec */
+                       /* at address #3, so the loop is inverted */
+                       for (id = 3; id > 0; id--) {
+                               if (! wait_for_codec(chip, id, AC97_VENDOR_ID1,
+                                                    msecs_to_jiffies(50))) {
+                                       cmdw = inw(FM801_REG(chip, AC97_DATA));
+                                       if (cmdw != 0xffff && cmdw != 0) {
+                                               chip->secondary = 1;
+                                               chip->secondary_addr = id;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+
+               /* the recovery phase, it seems that probing for non-existing codec might */
+               /* cause timeout problems */
+               wait_for_codec(chip, 0, AC97_VENDOR_ID1, msecs_to_jiffies(750));
+       }
+
+      __ac97_ok:
+
+       /* init volume */
+       outw(0x0808, FM801_REG(chip, PCM_VOL));
+       outw(0x9f1f, FM801_REG(chip, FM_VOL));
+       outw(0x8808, FM801_REG(chip, I2S_VOL));
+
+       /* I2S control - I2S mode */
+       outw(0x0003, FM801_REG(chip, I2S_MODE));
+
+       /* interrupt setup */
+       cmdw = inw(FM801_REG(chip, IRQ_MASK));
+       if (chip->irq < 0)
+               cmdw |= 0x00c3;         /* mask everything, no PCM nor MPU */
+       else
+               cmdw &= ~0x0083;        /* unmask MPU, PLAYBACK & CAPTURE */
+       outw(cmdw, FM801_REG(chip, IRQ_MASK));
+
+       /* interrupt clear */
+       outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
+
+       return 0;
+}
+
+
+static int snd_fm801_free(struct fm801 *chip)
 {
        unsigned short cmdw;
 
@@ -1233,137 +1349,67 @@ static int snd_fm801_free(fm801_t *chip)
        snd_tea575x_exit(&chip->tea);
 #endif
        if (chip->irq >= 0)
-               free_irq(chip->irq, (void *)chip);
+               free_irq(chip->irq, chip);
        pci_release_regions(chip->pci);
+       pci_disable_device(chip->pci);
 
        kfree(chip);
        return 0;
 }
 
-static int snd_fm801_dev_free(snd_device_t *device)
+static int snd_fm801_dev_free(struct snd_device *device)
 {
-       fm801_t *chip = device->device_data;
+       struct fm801 *chip = device->device_data;
        return snd_fm801_free(chip);
 }
 
-static int __devinit snd_fm801_create(snd_card_t * card,
+static int __devinit snd_fm801_create(struct snd_card *card,
                                      struct pci_dev * pci,
                                      int tea575x_tuner,
-                                     fm801_t ** rchip)
+                                     struct fm801 ** rchip)
 {
-       fm801_t *chip;
-       unsigned char rev, id;
-       unsigned short cmdw;
-       unsigned long timeout;
+       struct fm801 *chip;
+       unsigned char rev;
        int err;
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free =     snd_fm801_dev_free,
        };
 
        *rchip = NULL;
        if ((err = pci_enable_device(pci)) < 0)
                return err;
-       chip = kcalloc(1, sizeof(*chip), GFP_KERNEL);
-       if (chip == NULL)
+       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+       if (chip == NULL) {
+               pci_disable_device(pci);
                return -ENOMEM;
+       }
        spin_lock_init(&chip->reg_lock);
        chip->card = card;
        chip->pci = pci;
        chip->irq = -1;
+       chip->tea575x_tuner = tea575x_tuner;
        if ((err = pci_request_regions(pci, "FM801")) < 0) {
                kfree(chip);
+               pci_disable_device(pci);
                return err;
        }
        chip->port = pci_resource_start(pci, 0);
-       if (request_irq(pci->irq, snd_fm801_interrupt, SA_INTERRUPT|SA_SHIRQ, "FM801", (void *)chip)) {
-               snd_printk("unable to grab IRQ %d\n", chip->irq);
-               snd_fm801_free(chip);
-               return -EBUSY;
+       if ((tea575x_tuner & 0x0010) == 0) {
+               if (request_irq(pci->irq, snd_fm801_interrupt, IRQF_SHARED,
+                               "FM801", chip)) {
+                       snd_printk(KERN_ERR "unable to grab IRQ %d\n", chip->irq);
+                       snd_fm801_free(chip);
+                       return -EBUSY;
+               }
+               chip->irq = pci->irq;
+               pci_set_master(pci);
        }
-       chip->irq = pci->irq;
-       pci_set_master(pci);
 
        pci_read_config_byte(pci, PCI_REVISION_ID, &rev);
        if (rev >= 0xb1)        /* FM801-AU */
                chip->multichannel = 1;
 
-       /* codec cold reset + AC'97 warm reset */
-       outw((1<<5)|(1<<6), FM801_REG(chip, CODEC_CTRL));
-       inw(FM801_REG(chip, CODEC_CTRL)); /* flush posting data */
-       udelay(100);
-       outw(0, FM801_REG(chip, CODEC_CTRL));
-
-       timeout = (jiffies + (3 * HZ) / 4) + 1;         /* min 750ms */
-
-       outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
-       udelay(5);
-       do {
-               if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
-                       goto __ac97_secondary;
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(1);
-       } while (time_after(timeout, jiffies));
-       snd_printk("Primary AC'97 codec not found\n");
-       snd_fm801_free(chip);
-       return -EIO;
-
-      __ac97_secondary:
-       if (!chip->multichannel)        /* lookup is not required */
-               goto __ac97_ok;
-       for (id = 3; id > 0; id--) {    /* my card has the secondary codec */
-                                       /* at address #3, so the loop is inverted */
-
-               timeout = jiffies + HZ / 20;
-
-               outw((1<<7) | (id << FM801_AC97_ADDR_SHIFT) | AC97_VENDOR_ID1, FM801_REG(chip, AC97_CMD));
-               udelay(5);
-               do {
-                       if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8)) {
-                               cmdw = inw(FM801_REG(chip, AC97_DATA));
-                               if (cmdw != 0xffff && cmdw != 0) {
-                                       chip->secondary = 1;
-                                       chip->secondary_addr = id;
-                                       goto __ac97_ok;
-                               }
-                       }
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(1);
-               } while (time_after(timeout, jiffies));
-       }
-
-       /* the recovery phase, it seems that probing for non-existing codec might */
-       /* cause timeout problems */
-       timeout = (jiffies + (3 * HZ) / 4) + 1;         /* min 750ms */
-
-       outw((1<<7) | (0 << FM801_AC97_ADDR_SHIFT), FM801_REG(chip, AC97_CMD));
-       udelay(5);
-       do {
-               if ((inw(FM801_REG(chip, AC97_CMD)) & (3<<8)) == (1<<8))
-                       goto __ac97_ok;
-               set_current_state(TASK_UNINTERRUPTIBLE);
-               schedule_timeout(1);
-       } while (time_after(timeout, jiffies));
-       snd_printk("Primary AC'97 codec not responding\n");
-       snd_fm801_free(chip);
-       return -EIO;
-
-      __ac97_ok:
-
-       /* init volume */
-       outw(0x0808, FM801_REG(chip, PCM_VOL));
-       outw(0x9f1f, FM801_REG(chip, FM_VOL));
-       outw(0x8808, FM801_REG(chip, I2S_VOL));
-
-       /* I2S control - I2S mode */
-       outw(0x0003, FM801_REG(chip, I2S_MODE));
-
-       /* interrupt setup - unmask MPU, PLAYBACK & CAPTURE */
-       cmdw = inw(FM801_REG(chip, IRQ_MASK));
-       cmdw &= ~0x0083;
-       outw(cmdw, FM801_REG(chip, IRQ_MASK));
-
-       /* interrupt clear */
-       outw(FM801_IRQ_PLAYBACK|FM801_IRQ_CAPTURE|FM801_IRQ_MPU, FM801_REG(chip, IRQ_STATUS));
+       snd_fm801_chip_init(chip, 0);
 
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
                snd_fm801_free(chip);
@@ -1373,12 +1419,12 @@ static int __devinit snd_fm801_create(snd_card_t * card,
        snd_card_set_dev(card, &pci->dev);
 
 #ifdef TEA575X_RADIO
-       if (tea575x_tuner > 0 && (tea575x_tuner & 0xffff) < 4) {
+       if (tea575x_tuner > 0 && (tea575x_tuner & 0x000f) < 4) {
                chip->tea.dev_nr = tea575x_tuner >> 16;
                chip->tea.card = card;
                chip->tea.freq_fixup = 10700;
                chip->tea.private_data = chip;
-               chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0xffff) - 1];
+               chip->tea.ops = &snd_fm801_tea_ops[(tea575x_tuner & 0x000f) - 1];
                snd_tea575x_init(&chip->tea);
        }
 #endif
@@ -1391,9 +1437,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
                                          const struct pci_device_id *pci_id)
 {
        static int dev;
-       snd_card_t *card;
-       fm801_t *chip;
-       opl3_t *opl3;
+       struct snd_card *card;
+       struct fm801 *chip;
+       struct snd_opl3 *opl3;
        int err;
 
         if (dev >= SNDRV_CARDS)
@@ -1410,6 +1456,7 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
                snd_card_free(card);
                return err;
        }
+       card->private_data = chip;
 
        strcpy(card->driver, "FM801");
        strcpy(card->shortname, "ForteMedia FM801-");
@@ -1417,6 +1464,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
        sprintf(card->longname, "%s at 0x%lx, irq %i",
                card->shortname, chip->port, chip->irq);
 
+       if (tea575x_tuner[dev] & 0x0010)
+               goto __fm801_tuner_only;
+
        if ((err = snd_fm801_pcm(chip, 0, NULL)) < 0) {
                snd_card_free(card);
                return err;
@@ -1426,7 +1476,8 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
                return err;
        }
        if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
-                                      FM801_REG(chip, MPU401_DATA), 1,
+                                      FM801_REG(chip, MPU401_DATA),
+                                      MPU401_INFO_INTEGRATED,
                                       chip->irq, 0, &chip->rmidi)) < 0) {
                snd_card_free(card);
                return err;
@@ -1442,6 +1493,7 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
                return err;
        }
 
+      __fm801_tuner_only:
        if ((err = snd_card_register(card)) < 0) {
                snd_card_free(card);
                return err;
@@ -1457,16 +1509,75 @@ static void __devexit snd_card_fm801_remove(struct pci_dev *pci)
        pci_set_drvdata(pci, NULL);
 }
 
+#ifdef CONFIG_PM
+static unsigned char saved_regs[] = {
+       FM801_PCM_VOL, FM801_I2S_VOL, FM801_FM_VOL, FM801_REC_SRC,
+       FM801_PLY_CTRL, FM801_PLY_COUNT, FM801_PLY_BUF1, FM801_PLY_BUF2,
+       FM801_CAP_CTRL, FM801_CAP_COUNT, FM801_CAP_BUF1, FM801_CAP_BUF2,
+       FM801_CODEC_CTRL, FM801_I2S_MODE, FM801_VOLUME, FM801_GEN_CTRL,
+};
+
+static int snd_fm801_suspend(struct pci_dev *pci, pm_message_t state)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct fm801 *chip = card->private_data;
+       int i;
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       snd_pcm_suspend_all(chip->pcm);
+       snd_ac97_suspend(chip->ac97);
+       snd_ac97_suspend(chip->ac97_sec);
+       for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+               chip->saved_regs[i] = inw(chip->port + saved_regs[i]);
+       /* FIXME: tea575x suspend */
+
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       pci_set_power_state(pci, pci_choose_state(pci, state));
+       return 0;
+}
+
+static int snd_fm801_resume(struct pci_dev *pci)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct fm801 *chip = card->private_data;
+       int i;
+
+       pci_set_power_state(pci, PCI_D0);
+       pci_restore_state(pci);
+       if (pci_enable_device(pci) < 0) {
+               printk(KERN_ERR "fm801: pci_enable_device failed, "
+                      "disabling device\n");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
+       pci_set_master(pci);
+
+       snd_fm801_chip_init(chip, 1);
+       snd_ac97_resume(chip->ac97);
+       snd_ac97_resume(chip->ac97_sec);
+       for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+               outw(chip->saved_regs[i], chip->port + saved_regs[i]);
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif
+
 static struct pci_driver driver = {
        .name = "FM801",
        .id_table = snd_fm801_ids,
        .probe = snd_card_fm801_probe,
        .remove = __devexit_p(snd_card_fm801_remove),
+#ifdef CONFIG_PM
+       .suspend = snd_fm801_suspend,
+       .resume = snd_fm801_resume,
+#endif
 };
 
 static int __init alsa_card_fm801_init(void)
 {
-       return pci_module_init(&driver);
+       return pci_register_driver(&driver);
 }
 
 static void __exit alsa_card_fm801_exit(void)