[ALSA] hda-codec - Add speaker automute to ALC260 HP models
[safe/jmp/linux-2.6] / sound / pci / ali5451 / ali5451.c
index d683f77..6a905ed 100644 (file)
@@ -25,7 +25,6 @@
  *
  */
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -33,6 +32,7 @@
 #include <linux/pci.h>
 #include <linux/slab.h>
 #include <linux/moduleparam.h>
+#include <linux/dma-mapping.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/info.h>
@@ -45,31 +45,33 @@ MODULE_DESCRIPTION("ALI M5451");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}");
 
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
-static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32};
-static int spdif[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
+static int index = SNDRV_DEFAULT_IDX1; /* Index */
+static char *id = SNDRV_DEFAULT_STR1;  /* ID for this card */
+static int pcm_channels = 32;
+static int spdif;
 
-module_param_array(index, int, NULL, 0444);
+module_param(index, int, 0444);
 MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio.");
-module_param_array(id, charp, NULL, 0444);
+module_param(id, charp, 0444);
 MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable ALI 5451 PCI Audio.");
-module_param_array(pcm_channels, int, NULL, 0444);
+module_param(pcm_channels, int, 0444);
 MODULE_PARM_DESC(pcm_channels, "PCM Channels");
-module_param_array(spdif, bool, NULL, 0444);
+module_param(spdif, bool, 0444);
 MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
 
+/* just for backward compatibility */
+static int enable;
+module_param(enable, bool, 0444);
+
+
 /*
  *  Debug part definitions
  */
 
-//#define ALI_DEBUG
+/* #define ALI_DEBUG */
 
 #ifdef ALI_DEBUG
-#define snd_ali_printk(format, args...) printk(format, ##args);
+#define snd_ali_printk(format, args...) printk(KERN_DEBUG format, ##args);
 #else
 #define snd_ali_printk(format, args...)
 #endif
@@ -102,10 +104,10 @@ MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
  *  Direct Registers
  */
 
-#define ALI_LEGACY_DMAR0        0x00  // ADR0
-#define ALI_LEGACY_DMAR4        0x04  // CNT0
-#define ALI_LEGACY_DMAR11       0x0b  // MOD 
-#define ALI_LEGACY_DMAR15       0x0f  // MMR 
+#define ALI_LEGACY_DMAR0        0x00  /* ADR0 */
+#define ALI_LEGACY_DMAR4        0x04  /* CNT0 */
+#define ALI_LEGACY_DMAR11       0x0b  /* MOD  */
+#define ALI_LEGACY_DMAR15       0x0f  /* MMR  */
 #define ALI_MPUR0              0x20
 #define ALI_MPUR1              0x21
 #define ALI_MPUR2              0x22
@@ -168,11 +170,11 @@ MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
 #define MAX_CODECS 2
 
 
-typedef struct snd_stru_ali ali_t;
-typedef struct snd_ali_stru_voice snd_ali_voice_t;
+struct snd_ali;
+struct snd_ali_voice;
 
-typedef struct snd_ali_channel_control {
-       // register data
+struct snd_ali_channel_control {
+       /* register data */
        struct REGDATA {
                unsigned int start;
                unsigned int stop;
@@ -180,7 +182,7 @@ typedef struct snd_ali_channel_control {
                unsigned int ainten;
        } data;
                
-       // register addresses
+       /* register addresses */
        struct REGS {
                unsigned int start;
                unsigned int stop;
@@ -190,23 +192,22 @@ typedef struct snd_ali_channel_control {
                unsigned int ac97write;
        } regs;
 
-} snd_ali_channel_control_t;
+};
 
-struct snd_ali_stru_voice {
+struct snd_ali_voice {
        unsigned int number;
-       unsigned int use: 1,
-           pcm: 1,
-           midi: 1,
-           mode: 1,
-           synth: 1;
+       unsigned int use :1,
+               pcm :1,
+               midi :1,
+               mode :1,
+               synth :1,
+               running :1;
 
        /* PCM data */
-       ali_t *codec;
-       snd_pcm_substream_t *substream;
-       snd_ali_voice_t *extra;
+       struct snd_ali *codec;
+       struct snd_pcm_substream *substream;
+       struct snd_ali_voice *extra;
        
-       unsigned int running: 1;
-
        int eso;                /* final ESO value for channel */
        int count;              /* runtime->period_size */
 
@@ -217,43 +218,41 @@ struct snd_ali_stru_voice {
 };
 
 
-typedef struct snd_stru_alidev {
+struct snd_alidev {
 
-       snd_ali_voice_t voices[ALI_CHANNELS];   
+       struct snd_ali_voice voices[ALI_CHANNELS];      
 
        unsigned int    chcnt;                  /* num of opened channels */
        unsigned int    chmap;                  /* bitmap for opened channels */
        unsigned int synthcount;
 
-} alidev_t;
+};
 
 
-#ifdef CONFIG_PM
 #define ALI_GLOBAL_REGS                56
 #define ALI_CHANNEL_REGS       8
-typedef struct snd_ali_image {
-       unsigned long regs[ALI_GLOBAL_REGS];
-       unsigned long channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS];
-} ali_image_t;
-#endif
+struct snd_ali_image {
+       u32 regs[ALI_GLOBAL_REGS];
+       u32 channel_regs[ALI_CHANNELS][ALI_CHANNEL_REGS];
+};
 
 
-struct snd_stru_ali {
-       unsigned long   irq;
+struct snd_ali {
+       int             irq;
        unsigned long   port;
        unsigned char   revision;
 
-       unsigned int hw_initialized1;
-       unsigned int spdif_support1;
+       unsigned int hw_initialized :1;
+       unsigned int spdif_support :1;
 
        struct pci_dev  *pci;
        struct pci_dev  *pci_m1533;
        struct pci_dev  *pci_m7101;
 
-       snd_card_t      *card;
-       snd_pcm_t       *pcm[MAX_CODECS];
-       alidev_t        synth;
-       snd_ali_channel_control_t chregs;
+       struct snd_card *card;
+       struct snd_pcm  *pcm[MAX_CODECS];
+       struct snd_alidev       synth;
+       struct snd_ali_channel_control chregs;
 
        /* S/PDIF Mask */
        unsigned int    spdif_mask;
@@ -263,8 +262,8 @@ struct snd_stru_ali {
 
        unsigned int num_of_codecs;
 
-       ac97_bus_t *ac97_bus;
-       ac97_t *ac97[MAX_CODECS];
+       struct snd_ac97_bus *ac97_bus;
+       struct snd_ac97 *ac97[MAX_CODECS];
        unsigned short  ac97_ext_id;
        unsigned short  ac97_ext_status;
 
@@ -272,141 +271,57 @@ struct snd_stru_ali {
        spinlock_t      voice_alloc;
 
 #ifdef CONFIG_PM
-       ali_image_t *image;
+       struct snd_ali_image *image;
 #endif
 };
 
 static struct pci_device_id snd_ali_ids[] = {
-       {0x10b9, 0x5451, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, },
+       {PCI_DEVICE(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M5451), 0, 0, 0},
        {0, }
 };
 MODULE_DEVICE_TABLE(pci, snd_ali_ids);
 
-static void snd_ali_clear_voices(ali_t *, unsigned int, unsigned int);
-static unsigned short snd_ali_codec_peek(ali_t *, int, unsigned short);
-static void snd_ali_codec_poke(ali_t *, int, unsigned short, unsigned short);
-
-/*
- *  Debug Part
- */
-
-#ifdef ALI_DEBUG
-
-static void ali_read_regs(ali_t *codec, int channel)
-{
-       int i,j;
-       unsigned int dwVal;
-
-       printk("channel %d registers map:\n", channel);
-       outb((unsigned char)(channel & 0x001f), ALI_REG(codec,ALI_GC_CIR));
-
-       printk("    ");
-       for(j=0;j<8;j++)
-               printk("%2.2x       ", j*4);
-       printk("\n");
-
-       for (i=0; i<=0xf8/4;i++) {
-               if(i%8 == 0)
-                       printk("%2.2x  ", (i*4/0x10)*0x10);
-               dwVal = inl(ALI_REG(codec,i*4));
-               printk("%8.8x ", dwVal);
-               if ((i+1)%8 == 0)
-                       printk("\n");
-       }
-       printk("\n");
-}
-static void ali_read_cfg(unsigned int vendor, unsigned deviceid)
-{
-       unsigned int dwVal;
-       struct pci_dev *pci_dev;
-       int i,j;
-
-       pci_dev = pci_get_device(vendor, deviceid, NULL);
-       if (pci_dev == NULL)
-               return ;
-
-       printk("\nM%x PCI CFG\n", deviceid);
-       printk("    ");
-       for(j=0;j<8;j++)
-               printk("%d        ",j);
-       printk("\n");
-
-       for(i=0;i<8;i++) {
-               printk("%d   ",i);
-               for(j=0;j<8;j++)
-               {
-                       pci_read_config_dword(pci_dev, i*0x20+j*4, &dwVal);
-                       printk("%8.8x ", dwVal);
-               }
-               printk("\n");
-       }
-       pci_dev_put(pci_dev);
- }
-static void ali_read_ac97regs(ali_t *codec, int secondary)
-{
-       unsigned short i,j;
-       unsigned short wVal;
-
-       printk("\ncodec %d registers map:\n", secondary);
-
-       printk("    ");
-       for(j=0;j<8;j++)
-               printk("%2.2x   ",j*2);
-       printk("\n");
-
-       for (i=0; i<64;i++) {
-               if(i%8 == 0)
-                       printk("%2.2x  ", (i/8)*0x10);
-               wVal = snd_ali_codec_peek(codec, secondary, i*2);
-               printk("%4.4x ", wVal);
-               if ((i+1)%8 == 0)
-                       printk("\n");
-       }
-       printk("\n");
-}
-
-#endif
+static void snd_ali_clear_voices(struct snd_ali *, unsigned int, unsigned int);
+static unsigned short snd_ali_codec_peek(struct snd_ali *, int, unsigned short);
+static void snd_ali_codec_poke(struct snd_ali *, int, unsigned short,
+                              unsigned short);
 
 /*
  *  AC97 ACCESS
  */
 
-static inline unsigned int snd_ali_5451_peek(ali_t *codec,
-                                               unsigned int port )
+static inline unsigned int snd_ali_5451_peek(struct snd_ali *codec,
+                                            unsigned int port)
 {
        return (unsigned int)inl(ALI_REG(codec, port)); 
 }
 
-static inline void snd_ali_5451_poke(  ali_t *codec,
-                                       unsigned int port,
-                                       unsigned int val )
+static inline void snd_ali_5451_poke(struct snd_ali *codec,
+                                    unsigned int port,
+                                    unsigned int val)
 {
        outl((unsigned int)val, ALI_REG(codec, port));
 }
 
-static int snd_ali_codec_ready(        ali_t *codec,
-                               unsigned int port,
-                               int sched )
+static int snd_ali_codec_ready(struct snd_ali *codec,
+                              unsigned int port)
 {
        unsigned long end_time;
        unsigned int res;
        
-       end_time = jiffies + 10 * msecs_to_jiffies(250);
+       end_time = jiffies + msecs_to_jiffies(250);
        do {
                res = snd_ali_5451_peek(codec,port);
-               if (! (res & 0x8000))
+               if (!(res & 0x8000))
                        return 0;
-               if (sched) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(1);
-               }
+               schedule_timeout_uninterruptible(1);
        } while (time_after_eq(end_time, jiffies));
        snd_ali_5451_poke(codec, port, res & ~0x8000);
        snd_printdd("ali_codec_ready: codec is not ready.\n ");
        return -EIO;
 }
 
-static int snd_ali_stimer_ready(ali_t *codec, int sched)
+static int snd_ali_stimer_ready(struct snd_ali *codec)
 {
        unsigned long end_time;
        unsigned long dwChk1,dwChk2;
@@ -414,92 +329,92 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched)
        dwChk1 = snd_ali_5451_peek(codec, ALI_STIMER);
        dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
 
-       end_time = jiffies + 10 * msecs_to_jiffies(250);
+       end_time = jiffies + msecs_to_jiffies(250);
        do {
                dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
                if (dwChk2 != dwChk1)
                        return 0;
-               if (sched) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(1);
-               }
+               schedule_timeout_uninterruptible(1);
        } while (time_after_eq(end_time, jiffies));
-       snd_printk("ali_stimer_read: stimer is not ready.\n");
+       snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
        return -EIO;
 }
 
-static void snd_ali_codec_poke(ali_t *codec,int secondary,
-                                    unsigned short reg,
-                                    unsigned short val)
+static void snd_ali_codec_poke(struct snd_ali *codec,int secondary,
+                              unsigned short reg,
+                              unsigned short val)
 {
-       unsigned int dwVal = 0;
-       unsigned int port = 0;
+       unsigned int dwVal;
+       unsigned int port;
 
        if (reg >= 0x80) {
-               snd_printk("ali_codec_poke: reg(%xh) invalid.\n", reg);
+               snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg);
                return;
        }
 
        port = codec->chregs.regs.ac97write;
 
-       if (snd_ali_codec_ready(codec, port, 0) < 0)
+       if (snd_ali_codec_ready(codec, port) < 0)
                return;
-       if (snd_ali_stimer_ready(codec, 0) < 0)
+       if (snd_ali_stimer_ready(codec) < 0)
                return;
 
        dwVal  = (unsigned int) (reg & 0xff);
        dwVal |= 0x8000 | (val << 16);
-       if (secondary) dwVal |= 0x0080;
-       if (codec->revision == ALI_5451_V02) dwVal |= 0x0100;
+       if (secondary)
+               dwVal |= 0x0080;
+       if (codec->revision == ALI_5451_V02)
+               dwVal |= 0x0100;
 
-       snd_ali_5451_poke(codec,port,dwVal);
+       snd_ali_5451_poke(codec, port, dwVal);
 
        return ;
 }
 
-static unsigned short snd_ali_codec_peek( ali_t *codec,
-                                         int secondary,
-                                         unsigned short reg)
+static unsigned short snd_ali_codec_peek(struct snd_ali *codec,
+                                        int secondary,
+                                        unsigned short reg)
 {
-       unsigned int dwVal = 0;
-       unsigned int port = 0;
+       unsigned int dwVal;
+       unsigned int port;
 
        if (reg >= 0x80) {
-               snd_printk("ali_codec_peek: reg(%xh) invalid.\n", reg);
+               snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg);
                return ~0;
        }
 
        port = codec->chregs.regs.ac97read;
 
-       if (snd_ali_codec_ready(codec, port, 0) < 0)
+       if (snd_ali_codec_ready(codec, port) < 0)
                return ~0;
-       if (snd_ali_stimer_ready(codec, 0) < 0)
+       if (snd_ali_stimer_ready(codec) < 0)
                return ~0;
 
        dwVal  = (unsigned int) (reg & 0xff);
        dwVal |= 0x8000;                                /* bit 15*/
-       if (secondary) dwVal |= 0x0080;
+       if (secondary)
+               dwVal |= 0x0080;
 
        snd_ali_5451_poke(codec, port, dwVal);
 
-       if (snd_ali_stimer_ready(codec, 0) < 0)
+       if (snd_ali_stimer_ready(codec) < 0)
                return ~0;
-       if (snd_ali_codec_ready(codec, port, 0) < 0)
+       if (snd_ali_codec_ready(codec, port) < 0)
                return ~0;
        
-       return (snd_ali_5451_peek(codec, port) & 0xffff0000)>>16;
+       return (snd_ali_5451_peek(codec, port) & 0xffff0000) >> 16;
 }
 
-static void snd_ali_codec_write(ac97_t *ac97,
+static void snd_ali_codec_write(struct snd_ac97 *ac97,
                                unsigned short reg,
                                unsigned short val )
 {
-       ali_t *codec = ac97->private_data;
+       struct snd_ali *codec = ac97->private_data;
 
        snd_ali_printk("codec_write: reg=%xh data=%xh.\n", reg, val);
-       if(reg == AC97_GPIO_STATUS) {
-               outl((val << ALI_AC97_GPIO_DATA_SHIFT)|ALI_AC97_GPIO_ENABLE,
-                       ALI_REG(codec, ALI_AC97_GPIO));
+       if (reg == AC97_GPIO_STATUS) {
+               outl((val << ALI_AC97_GPIO_DATA_SHIFT) | ALI_AC97_GPIO_ENABLE,
+                    ALI_REG(codec, ALI_AC97_GPIO));
                return;
        }
        snd_ali_codec_poke(codec, ac97->num, reg, val);
@@ -507,25 +422,27 @@ static void snd_ali_codec_write(ac97_t *ac97,
 }
 
 
-static unsigned short snd_ali_codec_read(ac97_t *ac97, unsigned short reg)
+static unsigned short snd_ali_codec_read(struct snd_ac97 *ac97,
+                                        unsigned short reg)
 {
-       ali_t *codec = ac97->private_data;
+       struct snd_ali *codec = ac97->private_data;
 
        snd_ali_printk("codec_read reg=%xh.\n", reg);
-       return (snd_ali_codec_peek(codec, ac97->num, reg));
+       return snd_ali_codec_peek(codec, ac97->num, reg);
 }
 
 /*
  *     AC97 Reset
  */
 
-static int snd_ali_reset_5451(ali_t *codec)
+static int snd_ali_reset_5451(struct snd_ali *codec)
 {
-       struct pci_dev *pci_dev = NULL;
+       struct pci_dev *pci_dev;
        unsigned short wCount, wReg;
        unsigned int   dwVal;
        
-       if ((pci_dev = codec->pci_m1533) != NULL) {
+       pci_dev = codec->pci_m1533;
+       if (pci_dev) {
                pci_read_config_dword(pci_dev, 0x7c, &dwVal);
                pci_write_config_dword(pci_dev, 0x7c, dwVal | 0x08000000);
                udelay(5000);
@@ -545,7 +462,7 @@ static int snd_ali_reset_5451(ali_t *codec)
        wCount = 200;
        while(wCount--) {
                wReg = snd_ali_codec_peek(codec, 0, AC97_POWERDOWN);
-               if((wReg & 0x000f) == 0x000f)
+               if ((wReg & 0x000f) == 0x000f)
                        return 0;
                udelay(5000);
        }
@@ -557,10 +474,10 @@ static int snd_ali_reset_5451(ali_t *codec)
 
 #ifdef CODEC_RESET
 
-static int snd_ali_reset_codec(ali_t *codec)
+static int snd_ali_reset_codec(struct snd_ali *codec)
 {
-       struct pci_dev *pci_dev = NULL;
-       unsigned char bVal = 0;
+       struct pci_dev *pci_dev;
+       unsigned char bVal;
        unsigned int   dwVal;
        unsigned short wCount, wReg;
 
@@ -583,9 +500,9 @@ static int snd_ali_reset_codec(ali_t *codec)
        udelay(15000);
 
        wCount = 200;
-       while(wCount--) {
+       while (wCount--) {
                wReg = snd_ali_codec_read(codec->ac97, AC97_POWERDOWN);
-               if((wReg & 0x000f) == 0x000f)
+               if ((wReg & 0x000f) == 0x000f)
                        return 0;
                udelay(5000);
        }
@@ -598,25 +515,27 @@ static int snd_ali_reset_codec(ali_t *codec)
  *  ALI 5451 Controller
  */
 
-static void snd_ali_enable_special_channel(ali_t *codec, unsigned int channel)
+static void snd_ali_enable_special_channel(struct snd_ali *codec,
+                                          unsigned int channel)
 {
-       unsigned long dwVal = 0;
+       unsigned long dwVal;
 
-       dwVal  = inl(ALI_REG(codec,ALI_GLOBAL_CONTROL));
+       dwVal  = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
        dwVal |= 1 << (channel & 0x0000001f);
-       outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL));
+       outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
 }
 
-static void snd_ali_disable_special_channel(ali_t *codec, unsigned int channel)
+static void snd_ali_disable_special_channel(struct snd_ali *codec,
+                                           unsigned int channel)
 {
-       unsigned long dwVal = 0;
+       unsigned long dwVal;
 
-       dwVal  = inl(ALI_REG(codec,ALI_GLOBAL_CONTROL));
+       dwVal  = inl(ALI_REG(codec, ALI_GLOBAL_CONTROL));
        dwVal &= ~(1 << (channel & 0x0000001f));
-       outl(dwVal, ALI_REG(codec,ALI_GLOBAL_CONTROL));
+       outl(dwVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
 }
 
-static void snd_ali_enable_address_interrupt(ali_t * codec)
+static void snd_ali_enable_address_interrupt(struct snd_ali *codec)
 {
        unsigned int gc;
 
@@ -626,7 +545,7 @@ static void snd_ali_enable_address_interrupt(ali_t * codec)
        outl( gc, ALI_REG(codec, ALI_GC_CIR));
 }
 
-static void snd_ali_disable_address_interrupt(ali_t * codec)
+static void snd_ali_disable_address_interrupt(struct snd_ali *codec)
 {
        unsigned int gc;
 
@@ -636,40 +555,43 @@ static void snd_ali_disable_address_interrupt(ali_t * codec)
        outl(gc, ALI_REG(codec, ALI_GC_CIR));
 }
 
-#if 0 // not used
-static void snd_ali_enable_voice_irq(ali_t *codec, unsigned int channel)
+#if 0 /* not used */
+static void snd_ali_enable_voice_irq(struct snd_ali *codec,
+                                    unsigned int channel)
 {
        unsigned int mask;
-       snd_ali_channel_control_t *pchregs = &(codec->chregs);
+       struct snd_ali_channel_control *pchregs = &(codec->chregs);
 
        snd_ali_printk("enable_voice_irq channel=%d\n",channel);
        
        mask = 1 << (channel & 0x1f);
-       pchregs->data.ainten  = inl(ALI_REG(codec,pchregs->regs.ainten));
+       pchregs->data.ainten  = inl(ALI_REG(codec, pchregs->regs.ainten));
        pchregs->data.ainten |= mask;
-       outl(pchregs->data.ainten,ALI_REG(codec,pchregs->regs.ainten));
+       outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
 }
 #endif
 
-static void snd_ali_disable_voice_irq(ali_t *codec, unsigned int channel)
+static void snd_ali_disable_voice_irq(struct snd_ali *codec,
+                                     unsigned int channel)
 {
        unsigned int mask;
-       snd_ali_channel_control_t *pchregs = &(codec->chregs);
+       struct snd_ali_channel_control *pchregs = &(codec->chregs);
 
        snd_ali_printk("disable_voice_irq channel=%d\n",channel);
 
        mask = 1 << (channel & 0x1f);
-       pchregs->data.ainten  = inl(ALI_REG(codec,pchregs->regs.ainten));
+       pchregs->data.ainten  = inl(ALI_REG(codec, pchregs->regs.ainten));
        pchregs->data.ainten &= ~mask;
-       outl(pchregs->data.ainten,ALI_REG(codec,pchregs->regs.ainten));
+       outl(pchregs->data.ainten, ALI_REG(codec, pchregs->regs.ainten));
 }
 
-static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel)
+static int snd_ali_alloc_pcm_channel(struct snd_ali *codec, int channel)
 {
        unsigned int idx =  channel & 0x1f;
 
        if (codec->synth.chcnt >= ALI_CHANNELS){
-               snd_printk("ali_alloc_pcm_channel: no free channels.\n");
+               snd_printk(KERN_ERR
+                          "ali_alloc_pcm_channel: no free channels.\n");
                return -1;
        }
 
@@ -682,49 +604,55 @@ static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel)
        return -1;
 }
 
-static int snd_ali_find_free_channel(ali_t * codec, int rec)
+static int snd_ali_find_free_channel(struct snd_ali * codec, int rec)
 {
        int idx;
        int result = -1;
 
        snd_ali_printk("find_free_channel: for %s\n",rec ? "rec" : "pcm");
 
-       // recording
+       /* recording */
        if (rec) {
                if (codec->spdif_support &&
-                   (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_IN_SUPPORT))
+                   (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
+                    ALI_SPDIF_IN_SUPPORT))
                        idx = ALI_SPDIF_IN_CHANNEL;
                else
                        idx = ALI_PCM_IN_CHANNEL;
 
-               if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
+               result = snd_ali_alloc_pcm_channel(codec, idx);
+               if (result >= 0)
                        return result;
-               } else {
-                       snd_printk("ali_find_free_channel: record channel is busy now.\n");
+               else {
+                       snd_printk(KERN_ERR "ali_find_free_channel: "
+                                  "record channel is busy now.\n");
                        return -1;
                }
        }
 
-       //playback...
+       /* playback... */
        if (codec->spdif_support &&
-           (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_OUT_CH_ENABLE)) {
+           (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
+            ALI_SPDIF_OUT_CH_ENABLE)) {
                idx = ALI_SPDIF_OUT_CHANNEL;
-               if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
+               result = snd_ali_alloc_pcm_channel(codec, idx);
+               if (result >= 0)
                        return result;
-               } else {
-                       snd_printk("ali_find_free_channel: S/PDIF out channel is in busy now.\n");
-               }
+               else
+                       snd_printk(KERN_ERR "ali_find_free_channel: "
+                                  "S/PDIF out channel is in busy now.\n");
        }
 
        for (idx = 0; idx < ALI_CHANNELS; idx++) {
-               if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0)
+               result = snd_ali_alloc_pcm_channel(codec, idx);
+               if (result >= 0)
                        return result;
        }
-       snd_printk("ali_find_free_channel: no free channels.\n");
+       snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n");
        return -1;
 }
 
-static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
+static void snd_ali_free_channel_pcm(struct snd_ali *codec, int channel)
 {
        unsigned int idx = channel & 0x0000001f;
 
@@ -734,7 +662,8 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
                return;
 
        if (!(codec->synth.chmap & (1 << idx))) {
-               snd_printk("ali_free_channel_pcm: channel %d is not in use.\n",channel);
+               snd_printk(KERN_ERR "ali_free_channel_pcm: "
+                          "channel %d is not in use.\n", channel);
                return;
        } else {
                codec->synth.chmap &= ~(1 << idx);
@@ -742,8 +671,8 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
        }
 }
 
-#if 0 // not used
-static void snd_ali_start_voice(ali_t * codec, unsigned int channel)
+#if 0 /* not used */
+static void snd_ali_start_voice(struct snd_ali *codec, unsigned int channel)
 {
        unsigned int mask = 1 << (channel & 0x1f);
        
@@ -752,7 +681,7 @@ static void snd_ali_start_voice(ali_t * codec, unsigned int channel)
 }
 #endif
 
-static void snd_ali_stop_voice(ali_t * codec, unsigned int channel)
+static void snd_ali_stop_voice(struct snd_ali *codec, unsigned int channel)
 {
        unsigned int mask = 1 << (channel & 0x1f);
 
@@ -764,7 +693,7 @@ static void snd_ali_stop_voice(ali_t * codec, unsigned int channel)
  *    S/PDIF Part
  */
 
-static void snd_ali_delay(ali_t *codec,int interval)
+static void snd_ali_delay(struct snd_ali *codec,int interval)
 {
        unsigned long  begintimer,currenttimer;
 
@@ -772,89 +701,95 @@ static void snd_ali_delay(ali_t *codec,int interval)
        currenttimer = inl(ALI_REG(codec, ALI_STIMER));
 
        while (currenttimer < begintimer + interval) {
-               if(snd_ali_stimer_ready(codec, 1) < 0)
+               if (snd_ali_stimer_ready(codec) < 0)
                        break;
                currenttimer = inl(ALI_REG(codec,  ALI_STIMER));
+               cpu_relax();
        }
 }
 
-static void snd_ali_detect_spdif_rate(ali_t *codec)
+static void snd_ali_detect_spdif_rate(struct snd_ali *codec)
 {
-       u16 wval  = 0;
+       u16 wval;
        u16 count = 0;
-       u8  bval = 0, R1 = 0, R2 = 0;
+       u8  bval, R1 = 0, R2;
 
-       bval  = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+       bval  = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
        bval |= 0x1F;
-       outb(bval,ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+       outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL + 1));
 
-       while (((R1 < 0x0B )||(R1 > 0x0E)) && (R1 != 0x12) && count <= 50000) {
+       while ((R1 < 0x0b || R1 > 0x0e) && R1 != 0x12 && count <= 50000) {
                count ++;
                snd_ali_delay(codec, 6);
-               bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
+               bval = inb(ALI_REG(codec, ALI_SPDIF_CTRL + 1));
                R1 = bval & 0x1F;
        }
 
        if (count > 50000) {
-               snd_printk("ali_detect_spdif_rate: timeout!\n");
+               snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
                return;
        }
 
-       count = 0;
-       while (count++ <= 50000) {
+       for (count = 0; count <= 50000; count++) {
                snd_ali_delay(codec, 6);
                bval = inb(ALI_REG(codec,ALI_SPDIF_CTRL + 1));
                R2 = bval & 0x1F;
-               if (R2 != R1) R1 = R2; else break;
+               if (R2 != R1)
+                       R1 = R2;
+               else
+                       break;
        }
 
        if (count > 50000) {
-               snd_printk("ali_detect_spdif_rate: timeout!\n");
+               snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
                return;
        }
 
        if (R2 >= 0x0b && R2 <= 0x0e) {
-               wval  = inw(ALI_REG(codec,ALI_SPDIF_CTRL + 2));
-               wval &= 0xE0F0;
-               wval |= (u16)0x09 << 8 | (u16)0x05;
-               outw(wval,ALI_REG(codec,ALI_SPDIF_CTRL + 2));
+               wval  = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
+               wval &= 0xe0f0;
+               wval |= (0x09 << 8) | 0x05;
+               outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
 
-               bval  = inb(ALI_REG(codec,ALI_SPDIF_CS +3)) & 0xF0;
-               outb(bval|0x02,ALI_REG(codec,ALI_SPDIF_CS + 3));
+               bval  = inb(ALI_REG(codec, ALI_SPDIF_CS + 3)) & 0xf0;
+               outb(bval | 0x02, ALI_REG(codec, ALI_SPDIF_CS + 3));
        } else if (R2 == 0x12) {
-               wval  = inw(ALI_REG(codec,ALI_SPDIF_CTRL + 2));
-               wval &= 0xE0F0;
-               wval |= (u16)0x0E << 8 | (u16)0x08;
-               outw(wval,ALI_REG(codec,ALI_SPDIF_CTRL + 2));
+               wval  = inw(ALI_REG(codec, ALI_SPDIF_CTRL + 2));
+               wval &= 0xe0f0;
+               wval |= (0x0e << 8) | 0x08;
+               outw(wval, ALI_REG(codec, ALI_SPDIF_CTRL + 2));
 
-               bval  = inb(ALI_REG(codec,ALI_SPDIF_CS +3)) & 0xF0;
-               outb(bval|0x03,ALI_REG(codec,ALI_SPDIF_CS + 3));
+               bval  = inb(ALI_REG(codec,ALI_SPDIF_CS + 3)) & 0xf0;
+               outb(bval | 0x03, ALI_REG(codec, ALI_SPDIF_CS + 3));
        }
 }
 
-static unsigned int snd_ali_get_spdif_in_rate(ali_t *codec)
+static unsigned int snd_ali_get_spdif_in_rate(struct snd_ali *codec)
 {
-       u32     dwRate = 0;
-       u8      bval = 0;
+       u32     dwRate;
+       u8      bval;
 
-       bval  = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
-       bval &= 0x7F;
+       bval  = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
+       bval &= 0x7f;
        bval |= 0x40;
-       outb(bval, ALI_REG(codec,ALI_SPDIF_CTRL));
+       outb(bval, ALI_REG(codec, ALI_SPDIF_CTRL));
 
        snd_ali_detect_spdif_rate(codec);
 
-       bval  = inb(ALI_REG(codec,ALI_SPDIF_CS + 3));
-       bval &= 0x0F;
+       bval  = inb(ALI_REG(codec, ALI_SPDIF_CS + 3));
+       bval &= 0x0f;
 
-       if (bval == 0) dwRate = 44100;
-       if (bval == 1) dwRate = 48000;
-       if (bval == 2) dwRate = 32000;
+       switch (bval) {
+       case 0: dwRate = 44100; break;
+       case 1: dwRate = 48000; break;
+       case 2: dwRate = 32000; break;
+       default: dwRate = 0; break;
+       }
 
        return dwRate;
 }
 
-static void snd_ali_enable_spdif_in(ali_t *codec)
+static void snd_ali_enable_spdif_in(struct snd_ali *codec)
 {      
        unsigned int dwVal;
 
@@ -869,7 +804,7 @@ static void snd_ali_enable_spdif_in(ali_t *codec)
        snd_ali_enable_special_channel(codec, ALI_SPDIF_IN_CHANNEL);
 }
 
-static void snd_ali_disable_spdif_in(ali_t *codec)
+static void snd_ali_disable_spdif_in(struct snd_ali *codec)
 {
        unsigned int dwVal;
        
@@ -881,33 +816,34 @@ static void snd_ali_disable_spdif_in(ali_t *codec)
 }
 
 
-static void snd_ali_set_spdif_out_rate(ali_t *codec, unsigned int rate)
+static void snd_ali_set_spdif_out_rate(struct snd_ali *codec, unsigned int rate)
 {
        unsigned char  bVal;
-       unsigned int  dwRate = 0;
+       unsigned int  dwRate;
        
-       if (rate == 32000) dwRate = 0x300;
-       if (rate == 44100) dwRate = 0;
-       if (rate == 48000) dwRate = 0x200;
+       switch (rate) {
+       case 32000: dwRate = 0x300; break;
+       case 48000: dwRate = 0x200; break;
+       default: dwRate = 0; break;
+       }
        
        bVal  = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
        bVal &= (unsigned char)(~(1<<6));
        
-       bVal |= 0x80;           //select right
+       bVal |= 0x80;           /* select right */
        outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
        outb(dwRate | 0x20, ALI_REG(codec, ALI_SPDIF_CS + 2));
        
-       bVal &= (~0x80);        //select left
+       bVal &= ~0x80;  /* select left */
        outb(bVal, ALI_REG(codec, ALI_SPDIF_CTRL));
        outw(rate | 0x10, ALI_REG(codec, ALI_SPDIF_CS + 2));
 }
 
-static void snd_ali_enable_spdif_out(ali_t *codec)
+static void snd_ali_enable_spdif_out(struct snd_ali *codec)
 {
        unsigned short wVal;
        unsigned char bVal;
-
-        struct pci_dev *pci_dev = NULL;
+        struct pci_dev *pci_dev;
 
         pci_dev = codec->pci_m1533;
         if (pci_dev == NULL)
@@ -930,17 +866,15 @@ static void snd_ali_enable_spdif_out(ali_t *codec)
        bVal = inb(ALI_REG(codec, ALI_SPDIF_CTRL));
        outb(bVal & ALI_SPDIF_OUT_CH_STATUS, ALI_REG(codec, ALI_SPDIF_CTRL));
    
-       {
-               wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
-               wVal |= ALI_SPDIF_OUT_SEL_PCM;
-               outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
-               snd_ali_disable_special_channel(codec,ALI_SPDIF_OUT_CHANNEL);
-       }
+       wVal = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
+       wVal |= ALI_SPDIF_OUT_SEL_PCM;
+       outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
+       snd_ali_disable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
 }
 
-static void snd_ali_enable_spdif_chnout(ali_t *codec)
+static void snd_ali_enable_spdif_chnout(struct snd_ali *codec)
 {
-       unsigned short wVal = 0;
+       unsigned short wVal;
 
        wVal  = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
        wVal &= ~ALI_SPDIF_OUT_SEL_PCM;
@@ -953,12 +887,13 @@ static void snd_ali_enable_spdif_chnout(ali_t *codec)
                wVal &= (~0x0002);
        outw(wVal, ALI_REG(codec, ALI_SPDIF_CS));
 */
-       snd_ali_enable_special_channel(codec,ALI_SPDIF_OUT_CHANNEL);
+       snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
 }
 
-static void snd_ali_disable_spdif_chnout(ali_t *codec)
+static void snd_ali_disable_spdif_chnout(struct snd_ali *codec)
 {
-       unsigned short wVal = 0;
+       unsigned short wVal;
+
        wVal  = inw(ALI_REG(codec, ALI_GLOBAL_CONTROL));
        wVal |= ALI_SPDIF_OUT_SEL_PCM;
        outw(wVal, ALI_REG(codec, ALI_GLOBAL_CONTROL));
@@ -966,7 +901,7 @@ static void snd_ali_disable_spdif_chnout(ali_t *codec)
        snd_ali_enable_special_channel(codec, ALI_SPDIF_OUT_CHANNEL);
 }
 
-static void snd_ali_disable_spdif_out(ali_t *codec)
+static void snd_ali_disable_spdif_out(struct snd_ali *codec)
 {
        unsigned char  bVal;
 
@@ -976,11 +911,11 @@ static void snd_ali_disable_spdif_out(ali_t *codec)
        snd_ali_disable_spdif_chnout(codec);
 }
 
-static void snd_ali_update_ptr(ali_t *codec,int channel)
+static void snd_ali_update_ptr(struct snd_ali *codec, int channel)
 {
-       snd_ali_voice_t *pvoice = NULL;
-       snd_pcm_runtime_t *runtime;
-       snd_ali_channel_control_t *pchregs = NULL;
+       struct snd_ali_voice *pvoice;
+       struct snd_pcm_runtime *runtime;
+       struct snd_ali_channel_control *pchregs;
        unsigned int old, mask;
 #ifdef ALI_DEBUG
        unsigned int temp, cspf;
@@ -988,9 +923,9 @@ static void snd_ali_update_ptr(ali_t *codec,int channel)
 
        pchregs = &(codec->chregs);
 
-       // check if interrupt occurred for channel
+       /* check if interrupt occurred for channel */
        old  = pchregs->data.aint;
-       mask = ((unsigned int) 1L) << (channel & 0x1f);
+       mask = 1U << (channel & 0x1f);
 
        if (!(old & mask))
                return;
@@ -1009,7 +944,8 @@ static void snd_ali_update_ptr(ali_t *codec,int channel)
                cspf = (inl(ALI_REG(codec, ALI_CSPF)) & mask) == mask;
 #endif
                if (pvoice->running) {
-                       snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n",(u16)temp,cspf);
+                       snd_ali_printk("update_ptr: cso=%4.4x cspf=%d.\n",
+                                      (u16)temp, cspf);
                        spin_unlock(&codec->reg_lock);
                        snd_pcm_period_elapsed(pvoice->substream);
                        spin_lock(&codec->reg_lock);
@@ -1031,71 +967,67 @@ static void snd_ali_update_ptr(ali_t *codec,int channel)
        pchregs->data.aint = old & (~mask);
 }
 
-static void snd_ali_interrupt(ali_t * codec)
+static irqreturn_t snd_ali_card_interrupt(int irq, void *dev_id)
 {
+       struct snd_ali  *codec = dev_id;
        int channel;
        unsigned int audio_int;
-       snd_ali_channel_control_t *pchregs = NULL;
-       pchregs = &(codec->chregs);
+       struct snd_ali_channel_control *pchregs;
+
+       if (codec == NULL || !codec->hw_initialized)
+               return IRQ_NONE;
 
        audio_int = inl(ALI_REG(codec, ALI_MISCINT));
+       if (!audio_int)
+               return IRQ_NONE;
+
+       pchregs = &(codec->chregs);
        if (audio_int & ADDRESS_IRQ) {
-               // get interrupt status for all channels
-               pchregs->data.aint = inl(ALI_REG(codec,pchregs->regs.aint));
-               for (channel = 0; channel < ALI_CHANNELS; channel++) {
+               /* get interrupt status for all channels */
+               pchregs->data.aint = inl(ALI_REG(codec, pchregs->regs.aint));
+               for (channel = 0; channel < ALI_CHANNELS; channel++)
                        snd_ali_update_ptr(codec, channel);
-               }
        }
        outl((TARGET_REACHED | MIXER_OVERFLOW | MIXER_UNDERFLOW),
-               ALI_REG(codec,ALI_MISCINT));
-}
+               ALI_REG(codec, ALI_MISCINT));
 
-
-static irqreturn_t snd_ali_card_interrupt(int irq,
-                                  void *dev_id,
-                                  struct pt_regs *regs)
-{
-       ali_t   *codec = dev_id;
-
-       if (codec == NULL)
-               return IRQ_NONE;
-       snd_ali_interrupt(codec);
        return IRQ_HANDLED;
 }
 
 
-static snd_ali_voice_t *snd_ali_alloc_voice(ali_t * codec, int type, int rec, int channel)
+static struct snd_ali_voice *snd_ali_alloc_voice(struct snd_ali * codec,
+                                                int type, int rec, int channel)
 {
-       snd_ali_voice_t *pvoice = NULL;
-       unsigned long flags;
+       struct snd_ali_voice *pvoice;
        int idx;
 
-       snd_ali_printk("alloc_voice: type=%d rec=%d\n",type,rec);
+       snd_ali_printk("alloc_voice: type=%d rec=%d\n", type, rec);
 
-       spin_lock_irqsave(&codec->voice_alloc, flags);
+       spin_lock_irq(&codec->voice_alloc);
        if (type == SNDRV_ALI_VOICE_TYPE_PCM) {
                idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
                        snd_ali_find_free_channel(codec,rec);
-               if(idx < 0) {
-                       snd_printk("ali_alloc_voice: err.\n");
-                       spin_unlock_irqrestore(&codec->voice_alloc, flags);
+               if (idx < 0) {
+                       snd_printk(KERN_ERR "ali_alloc_voice: err.\n");
+                       spin_unlock_irq(&codec->voice_alloc);
                        return NULL;
                }
                pvoice = &(codec->synth.voices[idx]);
+               pvoice->codec = codec;
                pvoice->use = 1;
                pvoice->pcm = 1;
                pvoice->mode = rec;
-               spin_unlock_irqrestore(&codec->voice_alloc, flags);
+               spin_unlock_irq(&codec->voice_alloc);
                return pvoice;
        }
-       spin_unlock_irqrestore(&codec->voice_alloc, flags);
+       spin_unlock_irq(&codec->voice_alloc);
        return NULL;
 }
 
 
-static void snd_ali_free_voice(ali_t * codec, snd_ali_voice_t *pvoice)
+static void snd_ali_free_voice(struct snd_ali * codec,
+                              struct snd_ali_voice *pvoice)
 {
-       unsigned long flags;
        void (*private_free)(void *);
        void *private_data;
 
@@ -1103,25 +1035,24 @@ static void snd_ali_free_voice(ali_t * codec, snd_ali_voice_t *pvoice)
        if (pvoice == NULL || !pvoice->use)
                return;
        snd_ali_clear_voices(codec, pvoice->number, pvoice->number);
-       spin_lock_irqsave(&codec->voice_alloc, flags);
+       spin_lock_irq(&codec->voice_alloc);
        private_free = pvoice->private_free;
        private_data = pvoice->private_data;
        pvoice->private_free = NULL;
        pvoice->private_data = NULL;
-       if (pvoice->pcm) {
+       if (pvoice->pcm)
                snd_ali_free_channel_pcm(codec, pvoice->number);
-       }
        pvoice->use = pvoice->pcm = pvoice->synth = 0;
        pvoice->substream = NULL;
-       spin_unlock_irqrestore(&codec->voice_alloc, flags);
+       spin_unlock_irq(&codec->voice_alloc);
        if (private_free)
                private_free(private_data);
 }
 
 
-static void snd_ali_clear_voices(ali_t * codec,
-                         unsigned int v_min,
-                         unsigned int v_max)
+static void snd_ali_clear_voices(struct snd_ali *codec,
+                                unsigned int v_min,
+                                unsigned int v_max)
 {
        unsigned int i;
 
@@ -1131,7 +1062,7 @@ static void snd_ali_clear_voices(ali_t * codec,
        }
 }
 
-static void snd_ali_write_voice_regs(ali_t * codec,
+static void snd_ali_write_voice_regs(struct snd_ali *codec,
                         unsigned int Channel,
                         unsigned int LBA,
                         unsigned int CSO,
@@ -1146,7 +1077,7 @@ static void snd_ali_write_voice_regs(ali_t * codec,
 {
        unsigned int ctlcmds[4];
        
-       outb((unsigned char)(Channel & 0x001f),ALI_REG(codec,ALI_GC_CIR));
+       outb((unsigned char)(Channel & 0x001f), ALI_REG(codec, ALI_GC_CIR));
 
        ctlcmds[0] =  (CSO << 16) | (ALPHA_FMS & 0x0000ffff);
        ctlcmds[1] =  LBA;
@@ -1159,10 +1090,10 @@ static void snd_ali_write_voice_regs(ali_t * codec,
 
        outb(Channel, ALI_REG(codec, ALI_GC_CIR));
 
-       outl(ctlcmds[0], ALI_REG(codec,ALI_CSO_ALPHA_FMS));
-       outl(ctlcmds[1], ALI_REG(codec,ALI_LBA));
-       outl(ctlcmds[2], ALI_REG(codec,ALI_ESO_DELTA));
-       outl(ctlcmds[3], ALI_REG(codec,ALI_GVSEL_PAN_VOC_CTRL_EC));
+       outl(ctlcmds[0], ALI_REG(codec, ALI_CSO_ALPHA_FMS));
+       outl(ctlcmds[1], ALI_REG(codec, ALI_LBA));
+       outl(ctlcmds[2], ALI_REG(codec, ALI_ESO_DELTA));
+       outl(ctlcmds[3], ALI_REG(codec, ALI_GVSEL_PAN_VOC_CTRL_EC));
 
        outl(0x30000000, ALI_REG(codec, ALI_EBUF1));    /* Still Mode */
        outl(0x30000000, ALI_REG(codec, ALI_EBUF2));    /* Still Mode */
@@ -1172,8 +1103,10 @@ static unsigned int snd_ali_convert_rate(unsigned int rate, int rec)
 {
        unsigned int delta;
 
-       if (rate < 4000)  rate = 4000;
-       if (rate > 48000) rate = 48000;
+       if (rate < 4000)
+               rate = 4000;
+       if (rate > 48000)
+               rate = 48000;
 
        if (rec) {
                if (rate == 44100)
@@ -1198,21 +1131,21 @@ static unsigned int snd_ali_convert_rate(unsigned int rate, int rec)
        return delta;
 }
 
-static unsigned int snd_ali_control_mode(snd_pcm_substream_t *substream)
+static unsigned int snd_ali_control_mode(struct snd_pcm_substream *substream)
 {
        unsigned int CTRL;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        /* set ctrl mode
           CTRL default: 8-bit (unsigned) mono, loop mode enabled
         */
        CTRL = 0x00000001;
        if (snd_pcm_format_width(runtime->format) == 16)
-               CTRL |= 0x00000008;     // 16-bit data
+               CTRL |= 0x00000008;     /* 16-bit data */
        if (!snd_pcm_format_unsigned(runtime->format))
-               CTRL |= 0x00000002;     // signed data
+               CTRL |= 0x00000002;     /* signed data */
        if (runtime->channels > 1)
-               CTRL |= 0x00000004;     // stereo data
+               CTRL |= 0x00000004;     /* stereo data */
        return CTRL;
 }
 
@@ -1220,45 +1153,39 @@ static unsigned int snd_ali_control_mode(snd_pcm_substream_t *substream)
  *  PCM part
  */
 
-static int snd_ali_ioctl(snd_pcm_substream_t * substream,
-                                 unsigned int cmd, void *arg)
-{
-       return snd_pcm_lib_ioctl(substream, cmd, arg);
-}
-
-static int snd_ali_trigger(snd_pcm_substream_t *substream,
+static int snd_ali_trigger(struct snd_pcm_substream *substream,
                               int cmd)
                                    
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       struct list_head *pos;
-       snd_pcm_substream_t *s;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_substream *s;
        unsigned int what, whati, capture_flag;
-       snd_ali_voice_t *pvoice = NULL, *evoice = NULL;
+       struct snd_ali_voice *pvoice, *evoice;
        unsigned int val;
        int do_start;
 
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
        case SNDRV_PCM_TRIGGER_RESUME:
-               do_start = 1; break;
+               do_start = 1;
+               break;
        case SNDRV_PCM_TRIGGER_STOP:
        case SNDRV_PCM_TRIGGER_SUSPEND:
-               do_start = 0; break;
+               do_start = 0;
+               break;
        default:
                return -EINVAL;
        }
 
        what = whati = capture_flag = 0;
-       snd_pcm_group_for_each(pos, substream) {
-               s = snd_pcm_group_substream_entry(pos);
-               if ((ali_t *) snd_pcm_substream_chip(s) == codec) {
-                       pvoice = (snd_ali_voice_t *) s->runtime->private_data;
+       snd_pcm_group_for_each_entry(s, substream) {
+               if ((struct snd_ali *) snd_pcm_substream_chip(s) == codec) {
+                       pvoice = s->runtime->private_data;
                        evoice = pvoice->extra;
                        what |= 1 << (pvoice->number & 0x1f);
-                       if (evoice == NULL) {
+                       if (evoice == NULL)
                                whati |= 1 << (pvoice->number & 0x1f);
-                       else {
+                       else {
                                whati |= 1 << (evoice->number & 0x1f);
                                what |= 1 << (evoice->number & 0x1f);
                        }
@@ -1277,48 +1204,51 @@ static int snd_ali_trigger(snd_pcm_substream_t *substream,
                }
        }
        spin_lock(&codec->reg_lock);
-       if (! do_start) {
+       if (!do_start)
                outl(what, ALI_REG(codec, ALI_STOP));
-       }
        val = inl(ALI_REG(codec, ALI_AINTEN));
-       if (do_start) {
+       if (do_start)
                val |= whati;
-       } else {
+       else
                val &= ~whati;
-       }
        outl(val, ALI_REG(codec, ALI_AINTEN));
-       if (do_start) {
+       if (do_start)
                outl(what, ALI_REG(codec, ALI_START));
-       }
-       snd_ali_printk("trigger: what=%xh whati=%xh\n",what,whati);
+       snd_ali_printk("trigger: what=%xh whati=%xh\n", what, whati);
        spin_unlock(&codec->reg_lock);
 
        return 0;
 }
 
-static int snd_ali_playback_hw_params(snd_pcm_substream_t * substream,
-                                snd_pcm_hw_params_t * hw_params)
+static int snd_ali_playback_hw_params(struct snd_pcm_substream *substream,
+                                     struct snd_pcm_hw_params *hw_params)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
-       snd_ali_voice_t *evoice = pvoice->extra;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
+       struct snd_ali_voice *evoice = pvoice->extra;
        int err;
-       err = snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
-       if (err < 0) return err;
+
+       err = snd_pcm_lib_malloc_pages(substream,
+                                      params_buffer_bytes(hw_params));
+       if (err < 0)
+               return err;
        
        /* voice management */
 
-       if (params_buffer_size(hw_params)/2 != params_period_size(hw_params)) {
-               if (evoice == NULL) {
-                       evoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, 0, -1);
-                       if (evoice == NULL)
+       if (params_buffer_size(hw_params) / 2 !=
+           params_period_size(hw_params)) {
+               if (!evoice) {
+                       evoice = snd_ali_alloc_voice(codec,
+                                                    SNDRV_ALI_VOICE_TYPE_PCM,
+                                                    0, -1);
+                       if (!evoice)
                                return -ENOMEM;
                        pvoice->extra = evoice;
                        evoice->substream = substream;
                }
        } else {
-               if (evoice != NULL) {
+               if (evoice) {
                        snd_ali_free_voice(codec, evoice);
                        pvoice->extra = evoice = NULL;
                }
@@ -1327,39 +1257,39 @@ static int snd_ali_playback_hw_params(snd_pcm_substream_t * substream,
        return 0;
 }
 
-static int snd_ali_playback_hw_free(snd_pcm_substream_t * substream)
+static int snd_ali_playback_hw_free(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
-       snd_ali_voice_t *evoice = pvoice ? pvoice->extra : NULL;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
+       struct snd_ali_voice *evoice = pvoice ? pvoice->extra : NULL;
 
        snd_pcm_lib_free_pages(substream);
-       if (evoice != NULL) {
+       if (evoice) {
                snd_ali_free_voice(codec, evoice);
                pvoice->extra = NULL;
        }
        return 0;
 }
 
-static int snd_ali_hw_params(snd_pcm_substream_t * substream,
-                                snd_pcm_hw_params_t * hw_params)
+static int snd_ali_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));
+       return snd_pcm_lib_malloc_pages(substream,
+                                       params_buffer_bytes(hw_params));
 }
 
-static int snd_ali_hw_free(snd_pcm_substream_t * substream)
+static int snd_ali_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static int snd_ali_playback_prepare(snd_pcm_substream_t * substream)
+static int snd_ali_playback_prepare(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
-       snd_ali_voice_t *evoice = pvoice->extra;
-       unsigned long flags;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
+       struct snd_ali_voice *evoice = pvoice->extra;
 
        unsigned int LBA;
        unsigned int Delta;
@@ -1372,17 +1302,18 @@ static int snd_ali_playback_prepare(snd_pcm_substream_t * substream)
        
        snd_ali_printk("playback_prepare ...\n");
 
-       spin_lock_irqsave(&codec->reg_lock, flags);     
+       spin_lock_irq(&codec->reg_lock);        
        
        /* set Delta (rate) value */
        Delta = snd_ali_convert_rate(runtime->rate, 0);
 
-       if ((pvoice->number == ALI_SPDIF_IN_CHANNEL) || 
-           (pvoice->number == ALI_PCM_IN_CHANNEL))
+       if (pvoice->number == ALI_SPDIF_IN_CHANNEL || 
+           pvoice->number == ALI_PCM_IN_CHANNEL)
                snd_ali_disable_special_channel(codec, pvoice->number);
        else if (codec->spdif_support &&
-                (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) & ALI_SPDIF_OUT_CH_ENABLE)
-                && (pvoice->number == ALI_SPDIF_OUT_CHANNEL)) {
+                (inl(ALI_REG(codec, ALI_GLOBAL_CONTROL)) &
+                 ALI_SPDIF_OUT_CH_ENABLE)
+                && pvoice->number == ALI_SPDIF_OUT_CHANNEL) {
                snd_ali_set_spdif_out_rate(codec, runtime->rate);
                Delta = 0x1000;
        }
@@ -1396,7 +1327,8 @@ static int snd_ali_playback_prepare(snd_pcm_substream_t * substream)
        /* set target ESO for channel */
        pvoice->eso = runtime->buffer_size; 
 
-       snd_ali_printk("playback_prepare: eso=%xh count=%xh\n",pvoice->eso,pvoice->count);
+       snd_ali_printk("playback_prepare: eso=%xh count=%xh\n",
+                      pvoice->eso, pvoice->count);
 
        /* set ESO to capture first MIDLP interrupt */
        ESO = pvoice->eso -1;
@@ -1407,47 +1339,48 @@ static int snd_ali_playback_prepare(snd_pcm_substream_t * substream)
        PAN = 0;
        VOL = 0;
        EC = 0;
-       snd_ali_printk("playback_prepare:\n    ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n",pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL);
-       snd_ali_write_voice_regs(    codec,
-                                    pvoice->number,
-                                    LBA,
-                                    0, /* cso */
-                                    ESO,
-                                    Delta,
-                                    0, /* alpha */
-                                    GVSEL,
-                                    PAN,
-                                    VOL,
-                                    CTRL,
-                                    EC);
-       if (evoice != NULL) {
+       snd_ali_printk("playback_prepare:\n");
+       snd_ali_printk("ch=%d, Rate=%d Delta=%xh,GVSEL=%xh,PAN=%xh,CTRL=%xh\n",
+                      pvoice->number,runtime->rate,Delta,GVSEL,PAN,CTRL);
+       snd_ali_write_voice_regs(codec,
+                                pvoice->number,
+                                LBA,
+                                0,     /* cso */
+                                ESO,
+                                Delta,
+                                0,     /* alpha */
+                                GVSEL,
+                                PAN,
+                                VOL,
+                                CTRL,
+                                EC);
+       if (evoice) {
                evoice->count = pvoice->count;
                evoice->eso = pvoice->count << 1;
                ESO = evoice->eso - 1;
                snd_ali_write_voice_regs(codec,
-                                    evoice->number,
-                                    LBA,
-                                    0, /* cso */
-                                    ESO,
-                                    Delta,
-                                    0, /* alpha */
-                                    GVSEL,
-                                    (unsigned int)0x7f,
-                                    (unsigned int)0x3ff,
-                                    CTRL,
-                                    EC);
-       }
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
+                                        evoice->number,
+                                        LBA,
+                                        0,     /* cso */
+                                        ESO,
+                                        Delta,
+                                        0,     /* alpha */
+                                        GVSEL,
+                                        0x7f,
+                                        0x3ff,
+                                        CTRL,
+                                        EC);
+       }
+       spin_unlock_irq(&codec->reg_lock);
        return 0;
 }
 
 
-static int snd_ali_prepare(snd_pcm_substream_t * substream)
+static int snd_ali_prepare(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
-       unsigned long flags;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
        unsigned int LBA;
        unsigned int Delta;
        unsigned int ESO;
@@ -1458,7 +1391,7 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
        unsigned int EC;
        u8       bValue;
 
-       spin_lock_irqsave(&codec->reg_lock, flags);
+       spin_lock_irq(&codec->reg_lock);
 
        snd_ali_printk("ali_prepare...\n");
 
@@ -1468,40 +1401,42 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
                 pvoice->number == ALI_MODEM_OUT_CHANNEL) ? 
                0x1000 : snd_ali_convert_rate(runtime->rate, pvoice->mode);
 
-       // Prepare capture intr channel
+       /* Prepare capture intr channel */
        if (pvoice->number == ALI_SPDIF_IN_CHANNEL) {
 
                unsigned int rate;
                
-               if (codec->revision != ALI_5451_V02) {
-                       spin_unlock_irqrestore(&codec->reg_lock, flags);                        
+               spin_unlock_irq(&codec->reg_lock);
+               if (codec->revision != ALI_5451_V02)
                        return -1;
-               }
+
                rate = snd_ali_get_spdif_in_rate(codec);
                if (rate == 0) {
-                       snd_printk("ali_capture_preapre: spdif rate detect err!\n");
+                       snd_printk(KERN_WARNING "ali_capture_preapre: "
+                                  "spdif rate detect err!\n");
                        rate = 48000;
                }
+               spin_lock_irq(&codec->reg_lock);
                bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
                if (bValue & 0x10) {
                        outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
-                       printk("clear SPDIF parity error flag.\n");
+                       printk(KERN_WARNING "clear SPDIF parity error flag.\n");
                }
 
                if (rate != 48000)
-                       Delta = ((rate << 12)/runtime->rate)&0x00ffff;
+                       Delta = ((rate << 12) / runtime->rate) & 0x00ffff;
        }
 
-       // set target ESO for channel 
+       /* set target ESO for channel  */
        pvoice->eso = runtime->buffer_size; 
 
-       // set interrupt count size 
+       /* set interrupt count size  */
        pvoice->count = runtime->period_size;
 
-       // set Loop Back Address 
+       /* set Loop Back Address  */
        LBA = runtime->dma_addr;
 
-       // set ESO to capture first MIDLP interrupt 
+       /* set ESO to capture first MIDLP interrupt  */
        ESO = pvoice->eso - 1;
        CTRL = snd_ali_control_mode(substream);
        GVSEL = 0;
@@ -1522,18 +1457,18 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
                                     CTRL,
                                     EC);
 
-
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
+       spin_unlock_irq(&codec->reg_lock);
 
        return 0;
 }
 
 
-static snd_pcm_uframes_t snd_ali_playback_pointer(snd_pcm_substream_t *substream)
+static snd_pcm_uframes_t
+snd_ali_playback_pointer(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
        unsigned int cso;
 
        spin_lock(&codec->reg_lock);
@@ -1550,36 +1485,35 @@ static snd_pcm_uframes_t snd_ali_playback_pointer(snd_pcm_substream_t *substream
 }
 
 
-static snd_pcm_uframes_t snd_ali_pointer(snd_pcm_substream_t *substream)
+static snd_pcm_uframes_t snd_ali_pointer(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice = runtime->private_data;
        unsigned int cso;
-       unsigned long flags;
 
-       spin_lock_irqsave(&codec->reg_lock, flags);
+       spin_lock(&codec->reg_lock);
        if (!pvoice->running) {
-               spin_unlock_irqrestore(&codec->reg_lock, flags);
+               spin_unlock_irq(&codec->reg_lock);
                return 0;
        }
        outb(pvoice->number, ALI_REG(codec, ALI_GC_CIR));
        cso = inw(ALI_REG(codec, ALI_CSO_ALPHA_FMS + 2));
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
+       spin_unlock(&codec->reg_lock);
 
        return cso;
 }
 
-static snd_pcm_hardware_t snd_ali_playback =
+static struct snd_pcm_hardware snd_ali_playback =
 {
-       .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                                SNDRV_PCM_INFO_MMAP_VALID |
-                                SNDRV_PCM_INFO_RESUME |
-                                SNDRV_PCM_INFO_SYNC_START),
-       .formats =              (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
-                                SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
-       .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+       .info =         (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+                        SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                        SNDRV_PCM_INFO_MMAP_VALID |
+                        SNDRV_PCM_INFO_RESUME |
+                        SNDRV_PCM_INFO_SYNC_START),
+       .formats =      (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
+                        SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
+       .rates =        SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             4000,
        .rate_max =             48000,
        .channels_min =         1,
@@ -1596,16 +1530,16 @@ static snd_pcm_hardware_t snd_ali_playback =
  *  Capture support device description
  */
 
-static snd_pcm_hardware_t snd_ali_capture =
+static struct snd_pcm_hardware snd_ali_capture =
 {
-       .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                                SNDRV_PCM_INFO_MMAP_VALID |
-                                SNDRV_PCM_INFO_RESUME |
-                                SNDRV_PCM_INFO_SYNC_START),
-       .formats =              (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
-                                SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
-       .rates =                SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
+       .info =         (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+                        SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                        SNDRV_PCM_INFO_MMAP_VALID |
+                        SNDRV_PCM_INFO_RESUME |
+                        SNDRV_PCM_INFO_SYNC_START),
+       .formats =      (SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE |
+                        SNDRV_PCM_FMTBIT_S8 | SNDRV_PCM_FMTBIT_U16_LE),
+       .rates =        SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             4000,
        .rate_max =             48000,
        .channels_min =         1,
@@ -1618,36 +1552,28 @@ static snd_pcm_hardware_t snd_ali_capture =
        .fifo_size =            0,
 };
 
-static void snd_ali_pcm_free_substream(snd_pcm_runtime_t *runtime)
+static void snd_ali_pcm_free_substream(struct snd_pcm_runtime *runtime)
 {
-       unsigned long flags;
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) runtime->private_data;
-       ali_t *codec;
+       struct snd_ali_voice *pvoice = runtime->private_data;
+       struct snd_ali *codec;
 
        if (pvoice) {
                codec = pvoice->codec;
-               spin_lock_irqsave(&codec->reg_lock, flags);
                snd_ali_free_voice(pvoice->codec, pvoice);
-               spin_unlock_irqrestore(&codec->reg_lock, flags);
        }
 }
 
-static int snd_ali_open(snd_pcm_substream_t * substream, int rec, int channel,
-               snd_pcm_hardware_t *phw)
+static int snd_ali_open(struct snd_pcm_substream *substream, int rec,
+                       int channel, struct snd_pcm_hardware *phw)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
-       snd_ali_voice_t *pvoice;
-       unsigned long flags = 0;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
+       struct snd_ali_voice *pvoice;
 
-       spin_lock_irqsave(&codec->reg_lock, flags);
-       pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec, channel);
-       if (pvoice == NULL) {
-               spin_unlock_irqrestore(&codec->reg_lock, flags);
+       pvoice = snd_ali_alloc_voice(codec, SNDRV_ALI_VOICE_TYPE_PCM, rec,
+                                    channel);
+       if (!pvoice)
                return -EAGAIN;
-       }
-       pvoice->codec = codec;
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
 
        pvoice->substream = substream;
        runtime->private_data = pvoice;
@@ -1655,39 +1581,40 @@ static int snd_ali_open(snd_pcm_substream_t * substream, int rec, int channel,
 
        runtime->hw = *phw;
        snd_pcm_set_sync(substream);
-       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 64*1024);
+       snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
+                                    0, 64*1024);
        return 0;
 }
 
-static int snd_ali_playback_open(snd_pcm_substream_t * substream)
+static int snd_ali_playback_open(struct snd_pcm_substream *substream)
 {
        return snd_ali_open(substream, 0, -1, &snd_ali_playback);
 }
 
-static int snd_ali_capture_open(snd_pcm_substream_t * substream)
+static int snd_ali_capture_open(struct snd_pcm_substream *substream)
 {
        return snd_ali_open(substream, 1, -1, &snd_ali_capture);
 }
 
-static int snd_ali_playback_close(snd_pcm_substream_t * substream)
+static int snd_ali_playback_close(struct snd_pcm_substream *substream)
 {
        return 0;
 }
 
-static int snd_ali_close(snd_pcm_substream_t * substream)
+static int snd_ali_close(struct snd_pcm_substream *substream)
 {
-       ali_t *codec = snd_pcm_substream_chip(substream);
-       snd_ali_voice_t *pvoice = (snd_ali_voice_t *) substream->runtime->private_data;
+       struct snd_ali *codec = snd_pcm_substream_chip(substream);
+       struct snd_ali_voice *pvoice = substream->runtime->private_data;
 
        snd_ali_disable_special_channel(codec,pvoice->number);
 
        return 0;
 }
 
-static snd_pcm_ops_t snd_ali_playback_ops = {
+static struct snd_pcm_ops snd_ali_playback_ops = {
        .open =         snd_ali_playback_open,
        .close =        snd_ali_playback_close,
-       .ioctl =        snd_ali_ioctl,
+       .ioctl =        snd_pcm_lib_ioctl,
        .hw_params =    snd_ali_playback_hw_params,
        .hw_free =      snd_ali_playback_hw_free,
        .prepare =      snd_ali_playback_prepare,
@@ -1695,10 +1622,10 @@ static snd_pcm_ops_t snd_ali_playback_ops = {
        .pointer =      snd_ali_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_ali_capture_ops = {
+static struct snd_pcm_ops snd_ali_capture_ops = {
        .open =         snd_ali_capture_open,
        .close =        snd_ali_close,
-       .ioctl =        snd_ali_ioctl,
+       .ioctl =        snd_pcm_lib_ioctl,
        .hw_params =    snd_ali_hw_params,
        .hw_free =      snd_ali_hw_free,
        .prepare =      snd_ali_prepare,
@@ -1710,25 +1637,27 @@ static snd_pcm_ops_t snd_ali_capture_ops = {
  * Modem PCM
  */
 
-static int snd_ali_modem_hw_params(snd_pcm_substream_t * substream,
-                                snd_pcm_hw_params_t * hw_params)
+static int snd_ali_modem_hw_params(struct snd_pcm_substream *substream,
+                                struct snd_pcm_hw_params *hw_params)
 {
-       ali_t *chip = snd_pcm_substream_chip(substream);
+       struct snd_ali *chip = snd_pcm_substream_chip(substream);
        unsigned int modem_num = chip->num_of_codecs - 1;
-       snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE, params_rate(hw_params));
+       snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_RATE,
+                      params_rate(hw_params));
        snd_ac97_write(chip->ac97[modem_num], AC97_LINE1_LEVEL, 0);
        return snd_ali_hw_params(substream, hw_params);
 }
 
-static snd_pcm_hardware_t snd_ali_modem =
+static struct snd_pcm_hardware snd_ali_modem =
 {
-       .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                                SNDRV_PCM_INFO_BLOCK_TRANSFER |
-                                SNDRV_PCM_INFO_MMAP_VALID |
-                                SNDRV_PCM_INFO_RESUME |
-                                SNDRV_PCM_INFO_SYNC_START),
-       .formats =              SNDRV_PCM_FMTBIT_S16_LE,
-       .rates =                SNDRV_PCM_RATE_KNOT|SNDRV_PCM_RATE_8000|SNDRV_PCM_RATE_16000,
+       .info =         (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
+                        SNDRV_PCM_INFO_BLOCK_TRANSFER |
+                        SNDRV_PCM_INFO_MMAP_VALID |
+                        SNDRV_PCM_INFO_RESUME |
+                        SNDRV_PCM_INFO_SYNC_START),
+       .formats =      SNDRV_PCM_FMTBIT_S16_LE,
+       .rates =        (SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000 |
+                        SNDRV_PCM_RATE_16000),
        .rate_min =             8000,
        .rate_max =             16000,
        .channels_min =         1,
@@ -1741,32 +1670,34 @@ static snd_pcm_hardware_t snd_ali_modem =
        .fifo_size =            0,
 };
 
-static int snd_ali_modem_open(snd_pcm_substream_t * substream, int rec, int channel)
+static int snd_ali_modem_open(struct snd_pcm_substream *substream, int rec,
+                             int channel)
 {
-       static unsigned int rates [] = {8000,9600,12000,16000};
-       static snd_pcm_hw_constraint_list_t hw_constraint_rates = {
+       static unsigned int rates[] = {8000, 9600, 12000, 16000};
+       static struct snd_pcm_hw_constraint_list hw_constraint_rates = {
                .count = ARRAY_SIZE(rates),
                .list = rates,
                .mask = 0,
        };
        int err = snd_ali_open(substream, rec, channel, &snd_ali_modem);
+
        if (err)
                return err;
        return snd_pcm_hw_constraint_list(substream->runtime, 0,
                        SNDRV_PCM_HW_PARAM_RATE, &hw_constraint_rates);
 }
 
-static int snd_ali_modem_playback_open(snd_pcm_substream_t * substream)
+static int snd_ali_modem_playback_open(struct snd_pcm_substream *substream)
 {
        return snd_ali_modem_open(substream, 0, ALI_MODEM_OUT_CHANNEL);
 }
 
-static int snd_ali_modem_capture_open(snd_pcm_substream_t * substream)
+static int snd_ali_modem_capture_open(struct snd_pcm_substream *substream)
 {
        return snd_ali_modem_open(substream, 1, ALI_MODEM_IN_CHANNEL);
 }
 
-static snd_pcm_ops_t snd_ali_modem_playback_ops = {
+static struct snd_pcm_ops snd_ali_modem_playback_ops = {
        .open =         snd_ali_modem_playback_open,
        .close =        snd_ali_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1777,7 +1708,7 @@ static snd_pcm_ops_t snd_ali_modem_playback_ops = {
        .pointer =      snd_ali_pointer,
 };
 
-static snd_pcm_ops_t snd_ali_modem_capture_ops = {
+static struct snd_pcm_ops snd_ali_modem_capture_ops = {
        .open =         snd_ali_modem_capture_open,
        .close =        snd_ali_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1793,41 +1724,46 @@ struct ali_pcm_description {
        char *name;
        unsigned int playback_num;
        unsigned int capture_num;
-       snd_pcm_ops_t *playback_ops;
-       snd_pcm_ops_t *capture_ops;
+       struct snd_pcm_ops *playback_ops;
+       struct snd_pcm_ops *capture_ops;
+       unsigned short class;
 };
 
 
-static void snd_ali_pcm_free(snd_pcm_t *pcm)
+static void snd_ali_pcm_free(struct snd_pcm *pcm)
 {
-       ali_t *codec = pcm->private_data;
+       struct snd_ali *codec = pcm->private_data;
        codec->pcm[pcm->device] = NULL;
 }
 
 
-static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_description *desc)
+static int __devinit snd_ali_pcm(struct snd_ali * codec, int device,
+                                struct ali_pcm_description *desc)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        err = snd_pcm_new(codec->card, desc->name, device,
                          desc->playback_num, desc->capture_num, &pcm);
        if (err < 0) {
-               snd_printk("snd_ali_pcm: err called snd_pcm_new.\n");
+               snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n");
                return err;
        }
        pcm->private_data = codec;
        pcm->private_free = snd_ali_pcm_free;
-       pcm->info_flags = 0;
        if (desc->playback_ops)
-               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops);
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
+                               desc->playback_ops);
        if (desc->capture_ops)
-               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, desc->capture_ops);
+               snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
+                               desc->capture_ops);
 
        snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
-                                             snd_dma_pci_data(codec->pci), 64*1024, 128*1024);
+                                             snd_dma_pci_data(codec->pci),
+                                             64*1024, 128*1024);
 
        pcm->info_flags = 0;
+       pcm->dev_class = desc->class;
        pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
        strcpy(pcm->name, desc->name);
        codec->pcm[0] = pcm;
@@ -1835,16 +1771,29 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
 }
 
 static struct ali_pcm_description ali_pcms[] = {
-       { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops },
-       { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops }
+       { .name = "ALI 5451",
+         .playback_num = ALI_CHANNELS,
+         .capture_num = 1,
+         .playback_ops = &snd_ali_playback_ops,
+         .capture_ops = &snd_ali_capture_ops
+       },
+       { .name = "ALI 5451 modem",
+         .playback_num = 1,
+         .capture_num = 1,
+         .playback_ops = &snd_ali_modem_playback_ops,
+         .capture_ops = &snd_ali_modem_capture_ops,
+         .class = SNDRV_PCM_CLASS_MODEM
+       }
 };
 
-static int __devinit snd_ali_build_pcms(ali_t *codec)
+static int __devinit snd_ali_build_pcms(struct snd_ali *codec)
 {
        int i, err;
-       for(i = 0 ; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms) ; i++)
-               if((err = snd_ali_pcm(codec, i, &ali_pcms[i])) < 0)
+       for (i = 0; i < codec->num_of_codecs && i < ARRAY_SIZE(ali_pcms); i++) {
+               err = snd_ali_pcm(codec, i, &ali_pcms[i]);
+               if (err < 0)
                        return err;
+       }
        return 0;
 }
 
@@ -1854,30 +1803,24 @@ static int __devinit snd_ali_build_pcms(ali_t *codec)
 .info = snd_ali5451_spdif_info, .get = snd_ali5451_spdif_get, \
 .put = snd_ali5451_spdif_put, .private_value = value}
 
-static int snd_ali5451_spdif_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
-{
-        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-        uinfo->count = 1;
-        uinfo->value.integer.min = 0;
-        uinfo->value.integer.max = 1;
-        return 0;
-}
+#define snd_ali5451_spdif_info         snd_ctl_boolean_mono_info
 
-static int snd_ali5451_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       unsigned long flags;
-       ali_t *codec = kcontrol->private_data;
+       struct snd_ali *codec = kcontrol->private_data;
        unsigned int enable;
 
        enable = ucontrol->value.integer.value[0] ? 1 : 0;
 
-       spin_lock_irqsave(&codec->reg_lock, flags);
-       switch(kcontrol->private_value) {
+       spin_lock_irq(&codec->reg_lock);
+       switch (kcontrol->private_value) {
        case 0:
                enable = (codec->spdif_mask & 0x02) ? 1 : 0;
                break;
        case 1:
-               enable = ((codec->spdif_mask & 0x02) && (codec->spdif_mask & 0x04)) ? 1 : 0;
+               enable = ((codec->spdif_mask & 0x02) &&
+                         (codec->spdif_mask & 0x04)) ? 1 : 0;
                break;
        case 2:
                enable = (codec->spdif_mask & 0x01) ? 1 : 0;
@@ -1886,19 +1829,19 @@ static int snd_ali5451_spdif_get(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                break;
        }
        ucontrol->value.integer.value[0] = enable;
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
+       spin_unlock_irq(&codec->reg_lock);
        return 0;
 }
 
-static int snd_ali5451_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       unsigned long flags;
-       ali_t *codec = kcontrol->private_data;
+       struct snd_ali *codec = kcontrol->private_data;
        unsigned int change = 0, enable = 0;
 
        enable = ucontrol->value.integer.value[0] ? 1 : 0;
 
-       spin_lock_irqsave(&codec->reg_lock, flags);
+       spin_lock_irq(&codec->reg_lock);
        switch (kcontrol->private_value) {
        case 0:
                change = (codec->spdif_mask & 0x02) ? 1 : 0;
@@ -1943,12 +1886,12 @@ static int snd_ali5451_spdif_put(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
        default:
                break;
        }
-       spin_unlock_irqrestore(&codec->reg_lock, flags);
+       spin_unlock_irq(&codec->reg_lock);
        
        return change;
 }
 
-static snd_kcontrol_new_t snd_ali5451_mixer_spdif[] __devinitdata = {
+static struct snd_kcontrol_new snd_ali5451_mixer_spdif[] __devinitdata = {
        /* spdif aplayback switch */
        /* FIXME: "IEC958 Playback Switch" may conflict with one on ac97_codec */
        ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH), 0, 0),
@@ -1958,79 +1901,72 @@ static snd_kcontrol_new_t snd_ali5451_mixer_spdif[] __devinitdata = {
        ALI5451_SPDIF(SNDRV_CTL_NAME_IEC958("",CAPTURE,SWITCH), 0, 2)
 };
 
-static void snd_ali_mixer_free_ac97_bus(ac97_bus_t *bus)
-{
-       ali_t *codec = bus->private_data;
-       codec->ac97_bus = NULL;
-}
-
-static void snd_ali_mixer_free_ac97(ac97_t *ac97)
-{
-       ali_t *codec = ac97->private_data;
-       codec->ac97[ac97->num] = NULL;
-}
-
-static int __devinit snd_ali_mixer(ali_t * codec)
+static int __devinit snd_ali_mixer(struct snd_ali * codec)
 {
-       ac97_template_t ac97;
+       struct snd_ac97_template ac97;
        unsigned int idx;
        int i, err;
-       static ac97_bus_ops_t ops = {
+       static struct snd_ac97_bus_ops ops = {
                .write = snd_ali_codec_write,
                .read = snd_ali_codec_read,
        };
 
-       if ((err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus)) < 0)
+       err = snd_ac97_bus(codec->card, 0, &ops, codec, &codec->ac97_bus);
+       if (err < 0)
                return err;
-       codec->ac97_bus->private_free = snd_ali_mixer_free_ac97_bus;
 
        memset(&ac97, 0, sizeof(ac97));
        ac97.private_data = codec;
-       ac97.private_free = snd_ali_mixer_free_ac97;
 
-       for ( i = 0 ; i < codec->num_of_codecs ; i++) {
+       for (i = 0; i < codec->num_of_codecs; i++) {
                ac97.num = i;
-               if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) {
-                       snd_printk("ali mixer %d creating error.\n", i);
-                       if(i == 0)
-               return err;
-       }
+               err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i]);
+               if (err < 0) {
+                       snd_printk(KERN_ERR
+                                  "ali mixer %d creating error.\n", i);
+                       if (i == 0)
+                               return err;
+                       codec->num_of_codecs = 1;
+                       break;
+               }
        }
 
        if (codec->spdif_support) {
-               for(idx = 0; idx < ARRAY_SIZE(snd_ali5451_mixer_spdif); idx++) {
-                       err=snd_ctl_add(codec->card, snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec));
-                       if (err < 0) return err;
+               for (idx = 0; idx < ARRAY_SIZE(snd_ali5451_mixer_spdif); idx++) {
+                       err = snd_ctl_add(codec->card,
+                                         snd_ctl_new1(&snd_ali5451_mixer_spdif[idx], codec));
+                       if (err < 0)
+                               return err;
                }
        }
        return 0;
 }
 
 #ifdef CONFIG_PM
-static int ali_suspend(snd_card_t *card, pm_message_t state)
+static int ali_suspend(struct pci_dev *pci, pm_message_t state)
 {
-       ali_t *chip = card->pm_private_data;
-       ali_image_t *im;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct snd_ali *chip = card->private_data;
+       struct snd_ali_image *im;
        int i, j;
 
        im = chip->image;
-       if (! im)
+       if (!im)
                return 0;
 
-       for(i = 0 ; i < chip->num_of_codecs ; i++) {
-               if (chip->pcm[i])
-                       snd_pcm_suspend_all(chip->pcm[i]);
-               if(chip->ac97[i])
-                       snd_ac97_suspend(chip->ac97[i]);
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       for (i = 0; i < chip->num_of_codecs; i++) {
+               snd_pcm_suspend_all(chip->pcm[i]);
+               snd_ac97_suspend(chip->ac97[i]);
        }
 
        spin_lock_irq(&chip->reg_lock);
        
        im->regs[ALI_MISCINT >> 2] = inl(ALI_REG(chip, ALI_MISCINT));
-       // im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START));
+       /* im->regs[ALI_START >> 2] = inl(ALI_REG(chip, ALI_START)); */
        im->regs[ALI_STOP >> 2] = inl(ALI_REG(chip, ALI_STOP));
        
-       // disable all IRQ bits
+       /* disable all IRQ bits */
        outl(0, ALI_REG(chip, ALI_MISCINT));
        
        for (i = 0; i < ALI_GLOBAL_REGS; i++) { 
@@ -2045,25 +1981,37 @@ static int ali_suspend(snd_card_t *card, pm_message_t state)
                        im->channel_regs[i][j] = inl(ALI_REG(chip, j*4 + 0xe0));
        }
 
-       // stop all HW channel
+       /* stop all HW channel */
        outl(0xffffffff, ALI_REG(chip, ALI_STOP));
 
        spin_unlock_irq(&chip->reg_lock);
-       pci_disable_device(chip->pci);
+
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       pci_set_power_state(pci, pci_choose_state(pci, state));
        return 0;
 }
 
-static int ali_resume(snd_card_t *card)
+static int ali_resume(struct pci_dev *pci)
 {
-       ali_t *chip = card->pm_private_data;
-       ali_image_t *im;
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct snd_ali *chip = card->private_data;
+       struct snd_ali_image *im;
        int i, j;
 
        im = chip->image;
-       if (! im)
+       if (!im)
                return 0;
 
-       pci_enable_device(chip->pci);
+       pci_set_power_state(pci, PCI_D0);
+       pci_restore_state(pci);
+       if (pci_enable_device(pci) < 0) {
+               printk(KERN_ERR "ali5451: pci_enable_device failed, "
+                      "disabling device\n");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
+       pci_set_master(pci);
 
        spin_lock_irq(&chip->reg_lock);
        
@@ -2074,33 +2022,34 @@ static int ali_resume(snd_card_t *card)
        }
        
        for (i = 0; i < ALI_GLOBAL_REGS; i++) { 
-               if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP) || (i*4 == ALI_START))
+               if ((i*4 == ALI_MISCINT) || (i*4 == ALI_STOP) ||
+                   (i*4 == ALI_START))
                        continue;
                outl(im->regs[i], ALI_REG(chip, i*4));
        }
        
-       // start HW channel
+       /* start HW channel */
        outl(im->regs[ALI_START >> 2], ALI_REG(chip, ALI_START));
-       // restore IRQ enable bits
+       /* restore IRQ enable bits */
        outl(im->regs[ALI_MISCINT >> 2], ALI_REG(chip, ALI_MISCINT));
        
        spin_unlock_irq(&chip->reg_lock);
 
-       for(i = 0 ; i < chip->num_of_codecs ; i++)
-               if(chip->ac97[i])
-                       snd_ac97_resume(chip->ac97[i]);
+       for (i = 0 ; i < chip->num_of_codecs; i++)
+               snd_ac97_resume(chip->ac97[i]);
        
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
        return 0;
 }
 #endif /* CONFIG_PM */
 
-static int snd_ali_free(ali_t * codec)
+static int snd_ali_free(struct snd_ali * codec)
 {
        if (codec->hw_initialized)
                snd_ali_disable_address_interrupt(codec);
        if (codec->irq >= 0) {
                synchronize_irq(codec->irq);
-               free_irq(codec->irq, (void *)codec);
+               free_irq(codec->irq, codec);
        }
        if (codec->port)
                pci_release_regions(codec->pci);
@@ -2114,16 +2063,16 @@ static int snd_ali_free(ali_t * codec)
        return 0;
 }
 
-static int snd_ali_chip_init(ali_t *codec)
+static int snd_ali_chip_init(struct snd_ali *codec)
 {
        unsigned int legacy;
        unsigned char temp;
-       struct pci_dev *pci_dev = NULL;
+       struct pci_dev *pci_dev;
 
        snd_ali_printk("chip initializing ... \n");
 
        if (snd_ali_reset_5451(codec)) {
-               snd_printk("ali_chip_init: reset 5451 error.\n");
+               snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n");
                return -1;
        }
 
@@ -2151,7 +2100,8 @@ static int snd_ali_chip_init(ali_t *codec)
        outb(0x10,       ALI_REG(codec, ALI_MPUR2));
 
        codec->ac97_ext_id = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_ID);
-       codec->ac97_ext_status = snd_ali_codec_peek(codec, 0, AC97_EXTENDED_STATUS);
+       codec->ac97_ext_status = snd_ali_codec_peek(codec, 0,
+                                                   AC97_EXTENDED_STATUS);
        if (codec->spdif_support) {
                snd_ali_enable_spdif_out(codec);
                codec->spdif_mask = 0x00000002;
@@ -2163,8 +2113,9 @@ static int snd_ali_chip_init(ali_t *codec)
        if (inl(ALI_REG(codec, ALI_SCTRL)) & ALI_SCTRL_CODEC2_READY) {
                codec->num_of_codecs++;
                outl(inl(ALI_REG(codec, ALI_SCTRL)) |
-                       (ALI_SCTRL_LINE_IN2|ALI_SCTRL_GPIO_IN2|ALI_SCTRL_LINE_OUT_EN),
-                       ALI_REG(codec, ALI_SCTRL));
+                    (ALI_SCTRL_LINE_IN2 | ALI_SCTRL_GPIO_IN2 |
+                     ALI_SCTRL_LINE_OUT_EN),
+                    ALI_REG(codec, ALI_SCTRL));
        }
 
        snd_ali_printk("chip initialize succeed.\n");
@@ -2173,59 +2124,59 @@ static int snd_ali_chip_init(ali_t *codec)
 }
 
 /* proc for register dump */
-static void snd_ali_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buf)
+static void snd_ali_proc_read(struct snd_info_entry *entry,
+                             struct snd_info_buffer *buf)
 {
-       ali_t *codec = entry->private_data;
+       struct snd_ali *codec = entry->private_data;
        int i;
-       for(i = 0 ; i < 256 ; i+= 4)
+       for (i = 0; i < 256 ; i+= 4)
                snd_iprintf(buf, "%02x: %08x\n", i, inl(ALI_REG(codec, i)));
 }
 
-static void __devinit snd_ali_proc_init(ali_t *codec)
+static void __devinit snd_ali_proc_init(struct snd_ali *codec)
 {
-       snd_info_entry_t *entry;
-       if(!snd_card_proc_new(codec->card, "ali5451", &entry))
-               snd_info_set_text_ops(entry, codec, 1024, snd_ali_proc_read);
+       struct snd_info_entry *entry;
+       if (!snd_card_proc_new(codec->card, "ali5451", &entry))
+               snd_info_set_text_ops(entry, codec, snd_ali_proc_read);
 }
 
-static int __devinit snd_ali_resources(ali_t *codec)
+static int __devinit snd_ali_resources(struct snd_ali *codec)
 {
        int err;
 
        snd_ali_printk("resouces allocation ...\n");
-       if ((err = pci_request_regions(codec->pci, "ALI 5451")) < 0)
+       err = pci_request_regions(codec->pci, "ALI 5451");
+       if (err < 0)
                return err;
        codec->port = pci_resource_start(codec->pci, 0);
 
-       if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) {
-               snd_printk("Unable to request irq.\n");
+       if (request_irq(codec->pci->irq, snd_ali_card_interrupt,
+                       IRQF_SHARED, "ALI 5451", codec)) {
+               snd_printk(KERN_ERR "Unable to request irq.\n");
                return -EBUSY;
        }
        codec->irq = codec->pci->irq;
        snd_ali_printk("resouces allocated.\n");
        return 0;
 }
-static int snd_ali_dev_free(snd_device_t *device) 
+static int snd_ali_dev_free(struct snd_device *device)
 {
-       ali_t *codec=device->device_data;
+       struct snd_ali *codec = device->device_data;
        snd_ali_free(codec);
        return 0;
 }
 
-static int __devinit snd_ali_create(snd_card_t * card,
+static int __devinit snd_ali_create(struct snd_card *card,
                                    struct pci_dev *pci,
                                    int pcm_streams,
                                    int spdif_support,
-                                   ali_t ** r_ali)
+                                   struct snd_ali ** r_ali)
 {
-       ali_t *codec;
+       struct snd_ali *codec;
        int i, err;
-       unsigned short cmdw = 0;
-       struct pci_dev *pci_dev = NULL;
-        static snd_device_ops_t ops = {
-               (snd_dev_free_t *)snd_ali_dev_free,
-               NULL,
-               NULL
+       unsigned short cmdw;
+       static struct snd_device_ops ops = {
+               .dev_free = snd_ali_dev_free,
         };
 
        *r_ali = NULL;
@@ -2233,17 +2184,20 @@ static int __devinit snd_ali_create(snd_card_t * card,
        snd_ali_printk("creating ...\n");
 
        /* enable PCI device */
-       if ((err = pci_enable_device(pci)) < 0)
+       err = pci_enable_device(pci);
+       if (err < 0)
                return err;
        /* check, if we can restrict PCI DMA transfers to 31 bits */
-       if (pci_set_dma_mask(pci, 0x7fffffff) < 0 ||
-           pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) {
-               snd_printk("architecture does not support 31bit PCI busmaster DMA\n");
+       if (pci_set_dma_mask(pci, DMA_31BIT_MASK) < 0 ||
+           pci_set_consistent_dma_mask(pci, DMA_31BIT_MASK) < 0) {
+               snd_printk(KERN_ERR "architecture does not support "
+                          "31bit PCI busmaster DMA\n");
                pci_disable_device(pci);
                return -ENXIO;
        }
 
-       if ((codec = kzalloc(sizeof(*codec), GFP_KERNEL)) == NULL) {
+       codec = kzalloc(sizeof(*codec), GFP_KERNEL);
+       if (!codec) {
                pci_disable_device(pci);
                return -ENOMEM;
        }
@@ -2254,7 +2208,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
        codec->card = card;
        codec->pci = pci;
        codec->irq = -1;
-       pci_read_config_byte(pci, PCI_REVISION_ID, &codec->revision);
+       codec->revision = pci->revision;
        codec->spdif_support = spdif_support;
 
        if (pcm_streams < 1)
@@ -2299,44 +2253,43 @@ static int __devinit snd_ali_create(snd_card_t * card,
        codec->chregs.data.ainten = 0x00;
 
        /* M1533: southbridge */
-       pci_dev = pci_get_device(0x10b9, 0x1533, NULL);
-       codec->pci_m1533 = pci_dev;
-       if (! codec->pci_m1533) {
+       codec->pci_m1533 = pci_get_device(0x10b9, 0x1533, NULL);
+       if (!codec->pci_m1533) {
                snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n");
                snd_ali_free(codec);
                return -ENODEV;
        }
        /* M7101: power management */
-       pci_dev = pci_get_device(0x10b9, 0x7101, NULL);
-       codec->pci_m7101 = pci_dev;
-       if (! codec->pci_m7101 && codec->revision == ALI_5451_V02) {
+       codec->pci_m7101 = pci_get_device(0x10b9, 0x7101, NULL);
+       if (!codec->pci_m7101 && codec->revision == ALI_5451_V02) {
                snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n");
                snd_ali_free(codec);
                return -ENODEV;
        }
 
        snd_ali_printk("snd_device_new is called.\n");
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops)) < 0) {
+       err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, codec, &ops);
+       if (err < 0) {
                snd_ali_free(codec);
                return err;
        }
 
+       snd_card_set_dev(card, &pci->dev);
+
        /* initialise synth voices*/
-       for (i = 0; i < ALI_CHANNELS; i++ ) {
+       for (i = 0; i < ALI_CHANNELS; i++)
                codec->synth.voices[i].number = i;
-       }
 
-       if ((err = snd_ali_chip_init(codec)) < 0) {
-               snd_printk("ali create: chip init error.\n");
+       err = snd_ali_chip_init(codec);
+       if (err < 0) {
+               snd_printk(KERN_ERR "ali create: chip init error.\n");
                return err;
        }
 
 #ifdef CONFIG_PM
        codec->image = kmalloc(sizeof(*codec->image), GFP_KERNEL);
-       if (! codec->image)
+       if (!codec->image)
                snd_printk(KERN_WARNING "can't allocate apm buffer\n");
-       else
-               snd_card_set_pm_callback(card, ali_suspend, ali_resume, codec);
 #endif
 
        snd_ali_enable_address_interrupt(codec);
@@ -2350,57 +2303,50 @@ static int __devinit snd_ali_create(snd_card_t * card,
 static int __devinit snd_ali_probe(struct pci_dev *pci,
                                   const struct pci_device_id *pci_id)
 {
-       static int dev;
-       snd_card_t *card;
-       ali_t *codec;
+       struct snd_card *card;
+       struct snd_ali *codec;
        int err;
 
        snd_ali_printk("probe ...\n");
 
-        if (dev >= SNDRV_CARDS)
-                return -ENODEV;
-       if (!enable[dev]) {
-               dev++;
-               return -ENOENT;
-       }
-
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
-       if (card == NULL)
+       card = snd_card_new(index, id, THIS_MODULE, 0);
+       if (!card)
                return -ENOMEM;
 
-       if ((err = snd_ali_create(card, pci, pcm_channels[dev], spdif[dev], &codec)) < 0) {
-               snd_card_free(card);
-               return err;
-       }
+       err = snd_ali_create(card, pci, pcm_channels, spdif, &codec);
+       if (err < 0)
+               goto error;
+       card->private_data = codec;
 
        snd_ali_printk("mixer building ...\n");
-       if ((err = snd_ali_mixer(codec)) < 0) {
-               snd_card_free(card);
-               return err;
-       }
+       err = snd_ali_mixer(codec);
+       if (err < 0)
+               goto error;
        
        snd_ali_printk("pcm building ...\n");
-       if ((err = snd_ali_build_pcms(codec)) < 0) {
-               snd_card_free(card);
-               return err;
-       }
+       err = snd_ali_build_pcms(codec);
+       if (err < 0)
+               goto error;
 
        snd_ali_proc_init(codec);
 
        strcpy(card->driver, "ALI5451");
        strcpy(card->shortname, "ALI 5451");
        
-       sprintf(card->longname, "%s at 0x%lx, irq %li",
+       sprintf(card->longname, "%s at 0x%lx, irq %i",
                card->shortname, codec->port, codec->irq);
 
        snd_ali_printk("register card.\n");
-       if ((err = snd_card_register(card)) < 0) {
-               snd_card_free(card);
-               return err;
-       }
+       err = snd_card_register(card);
+       if (err < 0)
+               goto error;
+
        pci_set_drvdata(pci, card);
-       dev++;
        return 0;
+
+ error:
+       snd_card_free(card);
+       return err;
 }
 
 static void __devexit snd_ali_remove(struct pci_dev *pci)
@@ -2411,11 +2357,13 @@ static void __devexit snd_ali_remove(struct pci_dev *pci)
 
 static struct pci_driver driver = {
        .name = "ALI 5451",
-       .owner = THIS_MODULE,
        .id_table = snd_ali_ids,
        .probe = snd_ali_probe,
        .remove = __devexit_p(snd_ali_remove),
-       SND_PCI_PM_CALLBACKS
+#ifdef CONFIG_PM
+       .suspend = ali_suspend,
+       .resume = ali_resume,
+#endif
 };                                
 
 static int __init alsa_card_ali_init(void)