linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / sound / pci / cmipci.c
index a5ce723..c03b0a0 100644 (file)
@@ -43,8 +43,7 @@
 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
 MODULE_DESCRIPTION("C-Media CMI8x38 PCI");
 MODULE_LICENSE("GPL");
-MODULE_CLASSES("{sound}");
-MODULE_DEVICES("{{C-Media,CMI8738},"
+MODULE_SUPPORTED_DEVICE("{{C-Media,CMI8738},"
                "{C-Media,CMI8738B},"
                "{C-Media,CMI8338A},"
                "{C-Media,CMI8338B}}");
@@ -62,36 +61,22 @@ static int soft_ac3[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS-1)]=1};
 #ifdef SUPPORT_JOYSTICK
 static int joystick_port[SNDRV_CARDS];
 #endif
-static int boot_devs;
 
-module_param_array(index, int, boot_devs, 0444);
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for C-Media PCI soundcard.");
-MODULE_PARM_SYNTAX(index, SNDRV_INDEX_DESC);
-module_param_array(id, charp, boot_devs, 0444);
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for C-Media PCI soundcard.");
-MODULE_PARM_SYNTAX(id, SNDRV_ID_DESC);
-module_param_array(enable, bool, boot_devs, 0444);
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable C-Media PCI soundcard.");
-MODULE_PARM_SYNTAX(enable, SNDRV_ENABLE_DESC);
-module_param_array(mpu_port, long, boot_devs, 0444);
+module_param_array(mpu_port, long, NULL, 0444);
 MODULE_PARM_DESC(mpu_port, "MPU-401 port.");
-MODULE_PARM_SYNTAX(mpu_port, SNDRV_ENABLED ",allows:{{0},{0x330},{0x320},{0x310},{0x300}},dialog:list");
-module_param_array(fm_port, long, boot_devs, 0444);
+module_param_array(fm_port, long, NULL, 0444);
 MODULE_PARM_DESC(fm_port, "FM port.");
-MODULE_PARM_SYNTAX(fm_port, SNDRV_ENABLED ",allows:{{0},{0x388},{0x3c8},{0x3e0},{0x3e8}},dialog:list");
-module_param_array(soft_ac3, bool, boot_devs, 0444);
+module_param_array(soft_ac3, bool, NULL, 0444);
 MODULE_PARM_DESC(soft_ac3, "Sofware-conversion of raw SPDIF packets (model 033 only).");
 #ifdef SUPPORT_JOYSTICK
-module_param_array(joystick_port, int, boot_devs, 0444);
+module_param_array(joystick_port, int, NULL, 0444);
 MODULE_PARM_DESC(joystick_port, "Joystick port address.");
-MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201}},dialog:list");
-#endif
-
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8738
-#define PCI_DEVICE_ID_CMEDIA_CM8738    0x0111
-#endif
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8738B
-#define PCI_DEVICE_ID_CMEDIA_CM8738B   0x0112
 #endif
 
 /*
@@ -164,6 +149,8 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_CHIP_MASK2          0xff000000
 #define CM_CHIP_039            0x04000000
 #define CM_CHIP_039_6CH                0x01000000
+#define CM_CHIP_055            0x08000000
+#define CM_CHIP_8768           0x20000000
 #define CM_TDMA_INT_EN         0x00040000
 #define CM_CH1_INT_EN          0x00020000
 #define CM_CH0_INT_EN          0x00010000
@@ -282,6 +269,7 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_MICGAINZ            0x01    /* mic boost */
 #define CM_MICGAINZ_SHIFT      0
 
+#define CM_REG_MIXER3          0x24
 #define CM_REG_AUX_VOL         0x26
 #define CM_VAUXL_MASK          0xf0
 #define CM_VAUXR_MASK          0x0f
@@ -312,7 +300,7 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_REG_FM_PCI          0x50
 
 /*
- * for CMI-8338 .. this is not valid for CMI-8738.
+ * access from SB-mixer port
  */
 #define CM_REG_EXTENT_IND      0xf0
 #define CM_VPHONE_MASK         0xe0    /* Phone volume control (0-3) << 5 */
@@ -321,6 +309,7 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_VSPKM               0x08    /* Speaker mute control, default high */
 #define CM_RLOOPREN            0x04    /* Rec. R-channel enable */
 #define CM_RLOOPLEN            0x02    /* Rec. L-channel enable */
+#define CM_VADMIC3             0x01    /* Mic record boost */
 
 /*
  * CMI-8338 spec ver 0.5 (this is not valid for CMI-8738):
@@ -336,6 +325,14 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_REG_CH0_FRAME2      0x84
 #define CM_REG_CH1_FRAME1      0x88    /* 0-15: count of samples at bus master; buffer size */
 #define CM_REG_CH1_FRAME2      0x8C    /* 16-31: count of samples at codec; fragment size */
+#define CM_REG_EXT_MISC                0x90
+#define CM_REG_MISC_CTRL_8768  0x92    /* reg. name the same as 0x18 */
+#define CM_CHB3D8C             0x20    /* 7.1 channels support */
+#define CM_SPD32FMT            0x10    /* SPDIF/IN 32k */
+#define CM_ADC2SPDIF           0x08    /* ADC output to SPDIF/OUT */
+#define CM_SHAREADC            0x04    /* DAC in ADC as Center/LFE */
+#define CM_REALTCMP            0x02    /* monitor the CMPL/CMPR of ADC */
+#define CM_INVLRCK             0x01    /* invert ZVPORT's LRCK */
 
 /*
  * size of i/o region
@@ -345,25 +342,6 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
 #define CM_EXTENT_SYNTH          0x4
 
 
-/*
- * pci ids
- */
-#ifndef PCI_VENDOR_ID_CMEDIA
-#define PCI_VENDOR_ID_CMEDIA         0x13F6
-#endif
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8338A
-#define PCI_DEVICE_ID_CMEDIA_CM8338A 0x0100
-#endif
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8338B
-#define PCI_DEVICE_ID_CMEDIA_CM8338B 0x0101
-#endif
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8738
-#define PCI_DEVICE_ID_CMEDIA_CM8738  0x0111
-#endif
-#ifndef PCI_DEVICE_ID_CMEDIA_CM8738B
-#define PCI_DEVICE_ID_CMEDIA_CM8738B 0x0112
-#endif
-
 /*
  * channels for playback / capture
  */
@@ -402,13 +380,8 @@ MODULE_PARM_SYNTAX(joystick_port, SNDRV_ENABLED ",allows:{{0},{1},{0x200},{0x201
  * driver data
  */
 
-typedef struct snd_stru_cmipci cmipci_t;
-typedef struct snd_stru_cmipci_pcm cmipci_pcm_t;
-
-#define chip_t cmipci_t
-
-struct snd_stru_cmipci_pcm {
-       snd_pcm_substream_t *substream;
+struct cmipci_pcm {
+       struct snd_pcm_substream *substream;
        int running;            /* dac/adc running? */
        unsigned int dma_size;  /* in frames */
        unsigned int period_size;       /* in frames */
@@ -434,20 +407,19 @@ static const struct cmipci_mixer_auto_switches cm_saved_mixer[] = {
 };
 #define CM_SAVED_MIXERS                ARRAY_SIZE(cm_saved_mixer)
 
-struct snd_stru_cmipci {
-       snd_card_t *card;
+struct cmipci {
+       struct snd_card *card;
 
        struct pci_dev *pci;
        unsigned int device;    /* device ID */
        int irq;
 
        unsigned long iobase;
-       struct resource *res_iobase;
        unsigned int ctrl;      /* FUNCTRL0 current value */
 
-       snd_pcm_t *pcm;         /* DAC/ADC PCM */
-       snd_pcm_t *pcm2;        /* 2nd DAC */
-       snd_pcm_t *pcm_spdif;   /* SPDIF */
+       struct snd_pcm *pcm;            /* DAC/ADC PCM */
+       struct snd_pcm *pcm2;   /* 2nd DAC */
+       struct snd_pcm *pcm_spdif;      /* SPDIF */
 
        int chip_version;
        int max_channels;
@@ -464,98 +436,111 @@ struct snd_stru_cmipci {
        unsigned int dig_status;
        unsigned int dig_pcm_status;
 
-       snd_pcm_hardware_t *hw_info[3]; /* for playbacks */
+       struct snd_pcm_hardware *hw_info[3]; /* for playbacks */
 
        int opened[2];  /* open mode */
        struct semaphore open_mutex;
 
-       int mixer_insensitive: 1;
-       snd_kcontrol_t *mixer_res_ctl[CM_SAVED_MIXERS];
+       unsigned int mixer_insensitive: 1;
+       struct snd_kcontrol *mixer_res_ctl[CM_SAVED_MIXERS];
        int mixer_res_status[CM_SAVED_MIXERS];
 
-       opl3_t *opl3;
-       snd_hwdep_t *opl3hwdep;
-
-       cmipci_pcm_t channel[2];        /* ch0 - DAC, ch1 - ADC or 2nd DAC */
+       struct cmipci_pcm channel[2];   /* ch0 - DAC, ch1 - ADC or 2nd DAC */
 
        /* external MIDI */
-       snd_rawmidi_t *rmidi;
+       struct snd_rawmidi *rmidi;
 
 #ifdef SUPPORT_JOYSTICK
-       struct gameport gameport;
-       struct resource *res_joystick;
+       struct gameport *gameport;
 #endif
 
        spinlock_t reg_lock;
+
+#ifdef CONFIG_PM
+       unsigned int saved_regs[0x20];
+       unsigned char saved_mixers[0x20];
+#endif
 };
 
 
 /* read/write operations for dword register */
-inline static void snd_cmipci_write(cmipci_t *cm, unsigned int cmd, unsigned int data)
+static inline void snd_cmipci_write(struct cmipci *cm, unsigned int cmd, unsigned int data)
 {
        outl(data, cm->iobase + cmd);
 }
-inline static unsigned int snd_cmipci_read(cmipci_t *cm, unsigned int cmd)
+
+static inline unsigned int snd_cmipci_read(struct cmipci *cm, unsigned int cmd)
 {
        return inl(cm->iobase + cmd);
 }
 
 /* read/write operations for word register */
-inline static void snd_cmipci_write_w(cmipci_t *cm, unsigned int cmd, unsigned short data)
+static inline void snd_cmipci_write_w(struct cmipci *cm, unsigned int cmd, unsigned short data)
 {
        outw(data, cm->iobase + cmd);
 }
-inline static unsigned short snd_cmipci_read_w(cmipci_t *cm, unsigned int cmd)
+
+static inline unsigned short snd_cmipci_read_w(struct cmipci *cm, unsigned int cmd)
 {
        return inw(cm->iobase + cmd);
 }
 
 /* read/write operations for byte register */
-inline static void snd_cmipci_write_b(cmipci_t *cm, unsigned int cmd, unsigned char data)
+static inline void snd_cmipci_write_b(struct cmipci *cm, unsigned int cmd, unsigned char data)
 {
        outb(data, cm->iobase + cmd);
 }
 
-inline static unsigned char snd_cmipci_read_b(cmipci_t *cm, unsigned int cmd)
+static inline unsigned char snd_cmipci_read_b(struct cmipci *cm, unsigned int cmd)
 {
        return inb(cm->iobase + cmd);
 }
 
 /* bit operations for dword register */
-static void snd_cmipci_set_bit(cmipci_t *cm, unsigned int cmd, unsigned int flag)
+static int snd_cmipci_set_bit(struct cmipci *cm, unsigned int cmd, unsigned int flag)
 {
-       unsigned int val;
-       val = inl(cm->iobase + cmd);
+       unsigned int val, oval;
+       val = oval = inl(cm->iobase + cmd);
        val |= flag;
+       if (val == oval)
+               return 0;
        outl(val, cm->iobase + cmd);
+       return 1;
 }
 
-static void snd_cmipci_clear_bit(cmipci_t *cm, unsigned int cmd, unsigned int flag)
+static int snd_cmipci_clear_bit(struct cmipci *cm, unsigned int cmd, unsigned int flag)
 {
-       unsigned int val;
-       val = inl(cm->iobase + cmd);
+       unsigned int val, oval;
+       val = oval = inl(cm->iobase + cmd);
        val &= ~flag;
+       if (val == oval)
+               return 0;
        outl(val, cm->iobase + cmd);
+       return 1;
 }
 
-#if 0 // not used
 /* bit operations for byte register */
-static void snd_cmipci_set_bit_b(cmipci_t *cm, unsigned int cmd, unsigned char flag)
+static int snd_cmipci_set_bit_b(struct cmipci *cm, unsigned int cmd, unsigned char flag)
 {
-       unsigned char val;
-       val = inb(cm->iobase + cmd);
+       unsigned char val, oval;
+       val = oval = inb(cm->iobase + cmd);
        val |= flag;
+       if (val == oval)
+               return 0;
        outb(val, cm->iobase + cmd);
+       return 1;
 }
 
-static void snd_cmipci_clear_bit_b(cmipci_t *cm, unsigned int cmd, unsigned char flag)
+static int snd_cmipci_clear_bit_b(struct cmipci *cm, unsigned int cmd, unsigned char flag)
 {
-       unsigned char val;
-       val = inb(cm->iobase + cmd);
+       unsigned char val, oval;
+       val = oval = inb(cm->iobase + cmd);
        val &= ~flag;
+       if (val == oval)
+               return 0;
        outb(val, cm->iobase + cmd);
+       return 1;
 }
-#endif
 
 
 /*
@@ -627,7 +612,7 @@ out:
  * at the register CM_REG_FUNCTRL1 (0x04).
  * Problem: other ways are also possible (any information about that?)
  */
-static void snd_cmipci_set_pll(cmipci_t *cm, unsigned int rate, unsigned int slot)
+static void snd_cmipci_set_pll(struct cmipci *cm, unsigned int rate, unsigned int slot)
 {
        unsigned int reg = CM_REG_PLL + slot;
        /*
@@ -645,16 +630,16 @@ static void snd_cmipci_set_pll(cmipci_t *cm, unsigned int rate, unsigned int slo
 }
 #endif /* USE_VAR48KRATE */
 
-static int snd_cmipci_hw_params(snd_pcm_substream_t * substream,
-                               snd_pcm_hw_params_t * hw_params)
+static int snd_cmipci_hw_params(struct snd_pcm_substream *substream,
+                               struct snd_pcm_hw_params *hw_params)
 {
        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
 }
 
-static int snd_cmipci_playback2_hw_params(snd_pcm_substream_t * substream,
-                                         snd_pcm_hw_params_t * hw_params)
+static int snd_cmipci_playback2_hw_params(struct snd_pcm_substream *substream,
+                                         struct snd_pcm_hw_params *hw_params)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        if (params_channels(hw_params) > 2) {
                down(&cm->open_mutex);
                if (cm->opened[CM_CH_PLAY]) {
@@ -668,7 +653,7 @@ static int snd_cmipci_playback2_hw_params(snd_pcm_substream_t * substream,
        return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(hw_params));
 }
 
-static void snd_cmipci_ch_reset(cmipci_t *cm, int ch)
+static void snd_cmipci_ch_reset(struct cmipci *cm, int ch)
 {
        int reset = CM_RST_CH0 << (cm->channel[ch].ch);
        snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset);
@@ -676,7 +661,7 @@ static void snd_cmipci_ch_reset(cmipci_t *cm, int ch)
        udelay(10);
 }
 
-static int snd_cmipci_hw_free(snd_pcm_substream_t * substream)
+static int snd_cmipci_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
@@ -685,29 +670,32 @@ static int snd_cmipci_hw_free(snd_pcm_substream_t * substream)
 /*
  */
 
-static unsigned int hw_channels[] = {1, 2, 4, 5, 6};
-static snd_pcm_hw_constraint_list_t hw_constraints_channels_4 = {
+static unsigned int hw_channels[] = {1, 2, 4, 5, 6, 8};
+static struct snd_pcm_hw_constraint_list hw_constraints_channels_4 = {
        .count = 3,
        .list = hw_channels,
        .mask = 0,
 };
-static snd_pcm_hw_constraint_list_t hw_constraints_channels_6 = {
+static struct snd_pcm_hw_constraint_list hw_constraints_channels_6 = {
        .count = 5,
        .list = hw_channels,
        .mask = 0,
 };
+static struct snd_pcm_hw_constraint_list hw_constraints_channels_8 = {
+       .count = 6,
+       .list = hw_channels,
+       .mask = 0,
+};
 
-static int set_dac_channels(cmipci_t *cm, cmipci_pcm_t *rec, int channels)
+static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int channels)
 {
-       unsigned long flags;
-
        if (channels > 2) {
                if (! cm->can_multi_ch)
                        return -EINVAL;
                if (rec->fmt != 0x03) /* stereo 16bit only */
                        return -EINVAL;
 
-               spin_lock_irqsave(&cm->reg_lock, flags);
+               spin_lock_irq(&cm->reg_lock);
                snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_NXCHG);
                snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC);
                if (channels > 4) {
@@ -717,25 +705,32 @@ static int set_dac_channels(cmipci_t *cm, cmipci_pcm_t *rec, int channels)
                        snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D5C);
                        snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_CHB3D);
                }
-               if (channels == 6) {
+               if (channels >= 6) {
                        snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_CHB3D6C);
                        snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_ENCENTER);
                } else {
                        snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_CHB3D6C);
                        snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_ENCENTER);
                }
-               spin_unlock_irqrestore(&cm->reg_lock, flags);
+               if (cm->chip_version == 68) {
+                       if (channels == 8) {
+                               snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL_8768, CM_CHB3D8C);
+                       } else {
+                               snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL_8768, CM_CHB3D8C);
+                       }
+               }
+               spin_unlock_irq(&cm->reg_lock);
 
        } else {
                if (cm->can_multi_ch) {
-                       spin_lock_irqsave(&cm->reg_lock, flags);
+                       spin_lock_irq(&cm->reg_lock);
                        snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_NXCHG);
                        snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D);
                        snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_CHB3D5C);
                        snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_CHB3D6C);
                        snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_ENCENTER);
                        snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_XCHGDAC);
-                       spin_unlock_irqrestore(&cm->reg_lock, flags);
+                       spin_unlock_irq(&cm->reg_lock);
                }
        }
        return 0;
@@ -746,12 +741,11 @@ static int set_dac_channels(cmipci_t *cm, cmipci_pcm_t *rec, int channels)
  * prepare playback/capture channel
  * channel to be used must have been set in rec->ch.
  */
-static int snd_cmipci_pcm_prepare(cmipci_t *cm, cmipci_pcm_t *rec,
-                                snd_pcm_substream_t *substream)
+static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
+                                struct snd_pcm_substream *substream)
 {
-       unsigned long flags;
        unsigned int reg, freq, val;
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct snd_pcm_runtime *runtime = substream->runtime;
 
        rec->fmt = 0;
        rec->shift = 0;
@@ -777,7 +771,7 @@ static int snd_cmipci_pcm_prepare(cmipci_t *cm, cmipci_pcm_t *rec,
                rec->period_size = (rec->period_size * runtime->channels) / 2;
        }
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
 
        /* set buffer address */
        reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
@@ -822,7 +816,7 @@ static int snd_cmipci_pcm_prepare(cmipci_t *cm, cmipci_pcm_t *rec,
        //snd_printd("cmipci: chformat = %08x\n", val);
 
        rec->running = 0;
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
 
        return 0;
 }
@@ -830,8 +824,8 @@ static int snd_cmipci_pcm_prepare(cmipci_t *cm, cmipci_pcm_t *rec,
 /*
  * PCM trigger/stop
  */
-static int snd_cmipci_pcm_trigger(cmipci_t *cm, cmipci_pcm_t *rec,
-                                snd_pcm_substream_t *substream, int cmd)
+static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec,
+                                 struct snd_pcm_substream *substream, int cmd)
 {
        unsigned int inthld, chen, reset, pause;
        int result = 0;
@@ -862,10 +856,12 @@ static int snd_cmipci_pcm_trigger(cmipci_t *cm, cmipci_pcm_t *rec,
                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                cm->ctrl |= pause;
                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
+       case SNDRV_PCM_TRIGGER_RESUME:
                cm->ctrl &= ~pause;
                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
                break;
@@ -880,8 +876,8 @@ static int snd_cmipci_pcm_trigger(cmipci_t *cm, cmipci_pcm_t *rec,
 /*
  * return the current pointer
  */
-static snd_pcm_uframes_t snd_cmipci_pcm_pointer(cmipci_t *cm, cmipci_pcm_t *rec,
-                                         snd_pcm_substream_t *substream)
+static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci_pcm *rec,
+                                               struct snd_pcm_substream *substream)
 {
        size_t ptr;
        unsigned int reg;
@@ -905,16 +901,16 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(cmipci_t *cm, cmipci_pcm_t *rec,
  * playback
  */
 
-static int snd_cmipci_playback_trigger(snd_pcm_substream_t *substream,
+static int snd_cmipci_playback_trigger(struct snd_pcm_substream *substream,
                                       int cmd)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_PLAY], substream, cmd);
 }
 
-static snd_pcm_uframes_t snd_cmipci_playback_pointer(snd_pcm_substream_t *substream)
+static snd_pcm_uframes_t snd_cmipci_playback_pointer(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_PLAY], substream);
 }
 
@@ -924,16 +920,16 @@ static snd_pcm_uframes_t snd_cmipci_playback_pointer(snd_pcm_substream_t *substr
  * capture
  */
 
-static int snd_cmipci_capture_trigger(snd_pcm_substream_t *substream,
+static int snd_cmipci_capture_trigger(struct snd_pcm_substream *substream,
                                     int cmd)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_CAPT], substream, cmd);
 }
 
-static snd_pcm_uframes_t snd_cmipci_capture_pointer(snd_pcm_substream_t *substream)
+static snd_pcm_uframes_t snd_cmipci_capture_pointer(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        return snd_cmipci_pcm_pointer(cm, &cm->channel[CM_CH_CAPT], substream);
 }
 
@@ -942,47 +938,45 @@ static snd_pcm_uframes_t snd_cmipci_capture_pointer(snd_pcm_substream_t *substre
  * hw preparation for spdif
  */
 
-static int snd_cmipci_spdif_default_info(snd_kcontrol_t *kcontrol,
-                                        snd_ctl_elem_info_t *uinfo)
+static int snd_cmipci_spdif_default_info(struct snd_kcontrol *kcontrol,
+                                        struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
        uinfo->count = 1;
        return 0;
 }
 
-static int snd_cmipci_spdif_default_get(snd_kcontrol_t *kcontrol,
-                                       snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdif_default_get(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct cmipci *chip = snd_kcontrol_chip(kcontrol);
        int i;
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        for (i = 0; i < 4; i++)
                ucontrol->value.iec958.status[i] = (chip->dig_status >> (i * 8)) & 0xff;
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return 0;
 }
 
-static int snd_cmipci_spdif_default_put(snd_kcontrol_t * kcontrol,
-                                        snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_spdif_default_put(struct snd_kcontrol *kcontrol,
+                                        struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct cmipci *chip = snd_kcontrol_chip(kcontrol);
        int i, change;
        unsigned int val;
 
        val = 0;
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        for (i = 0; i < 4; i++)
                val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
        change = val != chip->dig_status;
        chip->dig_status = val;
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return change;
 }
 
-static snd_kcontrol_new_t snd_cmipci_spdif_default __devinitdata =
+static struct snd_kcontrol_new snd_cmipci_spdif_default __devinitdata =
 {
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,DEFAULT),
@@ -991,16 +985,16 @@ static snd_kcontrol_new_t snd_cmipci_spdif_default __devinitdata =
        .put =          snd_cmipci_spdif_default_put
 };
 
-static int snd_cmipci_spdif_mask_info(snd_kcontrol_t *kcontrol,
-                                     snd_ctl_elem_info_t *uinfo)
+static int snd_cmipci_spdif_mask_info(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
        uinfo->count = 1;
        return 0;
 }
 
-static int snd_cmipci_spdif_mask_get(snd_kcontrol_t * kcontrol,
-                                    snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdif_mask_get(struct snd_kcontrol *kcontrol,
+                                    struct snd_ctl_elem_value *ucontrol)
 {
        ucontrol->value.iec958.status[0] = 0xff;
        ucontrol->value.iec958.status[1] = 0xff;
@@ -1009,56 +1003,54 @@ static int snd_cmipci_spdif_mask_get(snd_kcontrol_t * kcontrol,
        return 0;
 }
 
-static snd_kcontrol_new_t snd_cmipci_spdif_mask __devinitdata =
+static struct snd_kcontrol_new snd_cmipci_spdif_mask __devinitdata =
 {
        .access =       SNDRV_CTL_ELEM_ACCESS_READ,
-       .iface =        SNDRV_CTL_ELEM_IFACE_MIXER,
+       .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
        .name =         SNDRV_CTL_NAME_IEC958("",PLAYBACK,CON_MASK),
        .info =         snd_cmipci_spdif_mask_info,
        .get =          snd_cmipci_spdif_mask_get,
 };
 
-static int snd_cmipci_spdif_stream_info(snd_kcontrol_t *kcontrol,
-                                       snd_ctl_elem_info_t *uinfo)
+static int snd_cmipci_spdif_stream_info(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_IEC958;
        uinfo->count = 1;
        return 0;
 }
 
-static int snd_cmipci_spdif_stream_get(snd_kcontrol_t *kcontrol,
-                                      snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdif_stream_get(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct cmipci *chip = snd_kcontrol_chip(kcontrol);
        int i;
 
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        for (i = 0; i < 4; i++)
                ucontrol->value.iec958.status[i] = (chip->dig_pcm_status >> (i * 8)) & 0xff;
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return 0;
 }
 
-static int snd_cmipci_spdif_stream_put(snd_kcontrol_t *kcontrol,
-                                      snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdif_stream_put(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *chip = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
+       struct cmipci *chip = snd_kcontrol_chip(kcontrol);
        int i, change;
        unsigned int val;
 
        val = 0;
-       spin_lock_irqsave(&chip->reg_lock, flags);
+       spin_lock_irq(&chip->reg_lock);
        for (i = 0; i < 4; i++)
                val |= (unsigned int)ucontrol->value.iec958.status[i] << (i * 8);
        change = val != chip->dig_pcm_status;
        chip->dig_pcm_status = val;
-       spin_unlock_irqrestore(&chip->reg_lock, flags);
+       spin_unlock_irq(&chip->reg_lock);
        return change;
 }
 
-static snd_kcontrol_new_t snd_cmipci_spdif_stream __devinitdata =
+static struct snd_kcontrol_new snd_cmipci_spdif_stream __devinitdata =
 {
        .access =       SNDRV_CTL_ELEM_ACCESS_READWRITE | SNDRV_CTL_ELEM_ACCESS_INACTIVE,
        .iface =        SNDRV_CTL_ELEM_IFACE_PCM,
@@ -1072,63 +1064,74 @@ static snd_kcontrol_new_t snd_cmipci_spdif_stream __devinitdata =
  */
 
 /* save mixer setting and mute for AC3 playback */
-static void save_mixer_state(cmipci_t *cm)
+static int save_mixer_state(struct cmipci *cm)
 {
        if (! cm->mixer_insensitive) {
+               struct snd_ctl_elem_value *val;
                unsigned int i;
+
+               val = kmalloc(sizeof(*val), GFP_ATOMIC);
+               if (!val)
+                       return -ENOMEM;
                for (i = 0; i < CM_SAVED_MIXERS; i++) {
-                       snd_kcontrol_t *ctl = cm->mixer_res_ctl[i];
+                       struct snd_kcontrol *ctl = cm->mixer_res_ctl[i];
                        if (ctl) {
-                               snd_ctl_elem_value_t val;
                                int event;
-                               memset(&val, 0, sizeof(val));
-                               ctl->get(ctl, &val);
-                               cm->mixer_res_status[i] = val.value.integer.value[0];
-                               val.value.integer.value[0] = cm_saved_mixer[i].toggle_on;
+                               memset(val, 0, sizeof(*val));
+                               ctl->get(ctl, val);
+                               cm->mixer_res_status[i] = val->value.integer.value[0];
+                               val->value.integer.value[0] = cm_saved_mixer[i].toggle_on;
                                event = SNDRV_CTL_EVENT_MASK_INFO;
-                               if (cm->mixer_res_status[i] != val.value.integer.value[0]) {
-                                       ctl->put(ctl, &val); /* toggle */
+                               if (cm->mixer_res_status[i] != val->value.integer.value[0]) {
+                                       ctl->put(ctl, val); /* toggle */
                                        event |= SNDRV_CTL_EVENT_MASK_VALUE;
                                }
                                ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
                                snd_ctl_notify(cm->card, event, &ctl->id);
                        }
                }
+               kfree(val);
                cm->mixer_insensitive = 1;
        }
+       return 0;
 }
 
 
 /* restore the previously saved mixer status */
-static void restore_mixer_state(cmipci_t *cm)
+static void restore_mixer_state(struct cmipci *cm)
 {
        if (cm->mixer_insensitive) {
+               struct snd_ctl_elem_value *val;
                unsigned int i;
+
+               val = kmalloc(sizeof(*val), GFP_KERNEL);
+               if (!val)
+                       return;
                cm->mixer_insensitive = 0; /* at first clear this;
                                              otherwise the changes will be ignored */
                for (i = 0; i < CM_SAVED_MIXERS; i++) {
-                       snd_kcontrol_t *ctl = cm->mixer_res_ctl[i];
+                       struct snd_kcontrol *ctl = cm->mixer_res_ctl[i];
                        if (ctl) {
-                               snd_ctl_elem_value_t val;
                                int event;
 
-                               memset(&val, 0, sizeof(val));
+                               memset(val, 0, sizeof(*val));
                                ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
-                               ctl->get(ctl, &val);
+                               ctl->get(ctl, val);
                                event = SNDRV_CTL_EVENT_MASK_INFO;
-                               if (val.value.integer.value[0] != cm->mixer_res_status[i]) {
-                                       val.value.integer.value[0] = cm->mixer_res_status[i];
-                                       ctl->put(ctl, &val);
+                               if (val->value.integer.value[0] != cm->mixer_res_status[i]) {
+                                       val->value.integer.value[0] = cm->mixer_res_status[i];
+                                       ctl->put(ctl, val);
                                        event |= SNDRV_CTL_EVENT_MASK_VALUE;
                                }
                                snd_ctl_notify(cm->card, event, &ctl->id);
                        }
                }
+               kfree(val);
        }
 }
 
 /* spinlock held! */
-static void setup_ac3(cmipci_t *cm, snd_pcm_substream_t *subs, int do_ac3, int rate)
+static void setup_ac3(struct cmipci *cm, struct snd_pcm_substream *subs, int do_ac3, int rate)
 {
        if (do_ac3) {
                /* AC3EN for 037 */
@@ -1175,17 +1178,17 @@ static void setup_ac3(cmipci_t *cm, snd_pcm_substream_t *subs, int do_ac3, int r
        }
 }
 
-static void setup_spdif_playback(cmipci_t *cm, snd_pcm_substream_t *subs, int up, int do_ac3)
+static int setup_spdif_playback(struct cmipci *cm, struct snd_pcm_substream *subs, int up, int do_ac3)
 {
-       int rate;
-       unsigned long flags;
+       int rate, err;
 
        rate = subs->runtime->rate;
 
        if (up && do_ac3)
-               save_mixer_state(cm);
+               if ((err = save_mixer_state(cm)) < 0)
+                       return err;
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        cm->spdif_playback_avail = up;
        if (up) {
                /* they are controlled via "IEC958 Output Switch" */
@@ -1207,7 +1210,8 @@ static void setup_spdif_playback(cmipci_t *cm, snd_pcm_substream_t *subs, int up
                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_PLAYBACK_SPDF);
                setup_ac3(cm, subs, 0, 0);
        }
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
+       return 0;
 }
 
 
@@ -1216,69 +1220,71 @@ static void setup_spdif_playback(cmipci_t *cm, snd_pcm_substream_t *subs, int up
  */
 
 /* playback - enable spdif only on the certain condition */
-static int snd_cmipci_playback_prepare(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback_prepare(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        int rate = substream->runtime->rate;
-       int do_spdif, do_ac3 = 0;
+       int err, do_spdif, do_ac3 = 0;
+
        do_spdif = ((rate == 44100 || rate == 48000) &&
                    substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE &&
                    substream->runtime->channels == 2);
        if (do_spdif && cm->can_ac3_hw) 
                do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO;
-       setup_spdif_playback(cm, substream, do_spdif, do_ac3);
+       if ((err = setup_spdif_playback(cm, substream, do_spdif, do_ac3)) < 0)
+               return err;
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream);
 }
 
 /* playback  (via device #2) - enable spdif always */
-static int snd_cmipci_playback_spdif_prepare(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback_spdif_prepare(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       int do_ac3;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       int err, do_ac3;
+
        if (cm->can_ac3_hw) 
                do_ac3 = cm->dig_pcm_status & IEC958_AES0_NONAUDIO;
        else
                do_ac3 = 1; /* doesn't matter */
-       setup_spdif_playback(cm, substream, 1, do_ac3);
+       if ((err = setup_spdif_playback(cm, substream, 1, do_ac3)) < 0)
+               return err;
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream);
 }
 
-static int snd_cmipci_playback_hw_free(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback_hw_free(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        setup_spdif_playback(cm, substream, 0, 0);
        restore_mixer_state(cm);
        return snd_cmipci_hw_free(substream);
 }
 
 /* capture */
-static int snd_cmipci_capture_prepare(snd_pcm_substream_t *substream)
+static int snd_cmipci_capture_prepare(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream);
 }
 
 /* capture with spdif (via device #2) */
-static int snd_cmipci_capture_spdif_prepare(snd_pcm_substream_t *substream)
+static int snd_cmipci_capture_spdif_prepare(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       unsigned long flags;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
 
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream);
 }
 
-static int snd_cmipci_capture_spdif_hw_free(snd_pcm_substream_t *subs)
+static int snd_cmipci_capture_spdif_hw_free(struct snd_pcm_substream *subs)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(subs);
-       unsigned long flags;
+       struct cmipci *cm = snd_pcm_substream_chip(subs);
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
 
        return snd_cmipci_hw_free(subs);
 }
@@ -1289,7 +1295,7 @@ static int snd_cmipci_capture_spdif_hw_free(snd_pcm_substream_t *subs)
  */
 static irqreturn_t snd_cmipci_interrupt(int irq, void *dev_id, struct pt_regs *regs)
 {
-       cmipci_t *cm = snd_magic_cast(cmipci_t, dev_id, return IRQ_NONE);
+       struct cmipci *cm = dev_id;
        unsigned int status, mask = 0;
        
        /* fastpath out, to ease interrupt sharing */
@@ -1324,11 +1330,11 @@ static irqreturn_t snd_cmipci_interrupt(int irq, void *dev_id, struct pt_regs *r
  */
 
 /* playback on channel A */
-static snd_pcm_hardware_t snd_cmipci_playback =
+static struct snd_pcm_hardware snd_cmipci_playback =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             5512,
@@ -1344,11 +1350,11 @@ static snd_pcm_hardware_t snd_cmipci_playback =
 };
 
 /* capture on channel B */
-static snd_pcm_hardware_t snd_cmipci_capture =
+static struct snd_pcm_hardware snd_cmipci_capture =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             5512,
@@ -1364,11 +1370,11 @@ static snd_pcm_hardware_t snd_cmipci_capture =
 };
 
 /* playback on channel B - stereo 16bit only? */
-static snd_pcm_hardware_t snd_cmipci_playback2 =
+static struct snd_pcm_hardware snd_cmipci_playback2 =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_5512 | SNDRV_PCM_RATE_8000_48000,
        .rate_min =             5512,
@@ -1384,11 +1390,11 @@ static snd_pcm_hardware_t snd_cmipci_playback2 =
 };
 
 /* spdif playback on channel A */
-static snd_pcm_hardware_t snd_cmipci_playback_spdif =
+static struct snd_pcm_hardware snd_cmipci_playback_spdif =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
        .rate_min =             44100,
@@ -1404,11 +1410,11 @@ static snd_pcm_hardware_t snd_cmipci_playback_spdif =
 };
 
 /* spdif playback on channel A (32bit, IEC958 subframes) */
-static snd_pcm_hardware_t snd_cmipci_playback_iec958_subframe =
+static struct snd_pcm_hardware snd_cmipci_playback_iec958_subframe =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE,
        .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
        .rate_min =             44100,
@@ -1424,11 +1430,11 @@ static snd_pcm_hardware_t snd_cmipci_playback_iec958_subframe =
 };
 
 /* spdif capture on channel B */
-static snd_pcm_hardware_t snd_cmipci_capture_spdif =
+static struct snd_pcm_hardware snd_cmipci_capture_spdif =
 {
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_PAUSE |
-                                SNDRV_PCM_INFO_MMAP_VALID),
+                                SNDRV_PCM_INFO_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
        .formats =              SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
        .rate_min =             44100,
@@ -1446,9 +1452,8 @@ static snd_pcm_hardware_t snd_cmipci_capture_spdif =
 /*
  * check device open/close
  */
-static int open_device_check(cmipci_t *cm, int mode, snd_pcm_substream_t *subs)
+static int open_device_check(struct cmipci *cm, int mode, struct snd_pcm_substream *subs)
 {
-       unsigned long flags;
        int ch = mode & CM_OPEN_CH_MASK;
 
        /* FIXME: a file should wait until the device becomes free
@@ -1466,17 +1471,16 @@ static int open_device_check(cmipci_t *cm, int mode, snd_pcm_substream_t *subs)
        if (! (mode & CM_OPEN_DAC)) {
                /* disable dual DAC mode */
                cm->channel[ch].is_dac = 0;
-               spin_lock_irqsave(&cm->reg_lock, flags);
+               spin_lock_irq(&cm->reg_lock);
                snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC);
-               spin_unlock_irqrestore(&cm->reg_lock, flags);
+               spin_unlock_irq(&cm->reg_lock);
        }
        up(&cm->open_mutex);
        return 0;
 }
 
-static void close_device_check(cmipci_t *cm, int mode)
+static void close_device_check(struct cmipci *cm, int mode)
 {
-       unsigned long flags;
        int ch = mode & CM_OPEN_CH_MASK;
 
        down(&cm->open_mutex);
@@ -1490,9 +1494,9 @@ static void close_device_check(cmipci_t *cm, int mode)
                if (! cm->channel[ch].is_dac) {
                        /* enable dual DAC mode again */
                        cm->channel[ch].is_dac = 1;
-                       spin_lock_irqsave(&cm->reg_lock, flags);
+                       spin_lock_irq(&cm->reg_lock);
                        snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_ENDBDAC);
-                       spin_unlock_irqrestore(&cm->reg_lock, flags);
+                       spin_unlock_irq(&cm->reg_lock);
                }
        }
        up(&cm->open_mutex);
@@ -1501,37 +1505,42 @@ static void close_device_check(cmipci_t *cm, int mode)
 /*
  */
 
-static int snd_cmipci_playback_open(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback_open(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = open_device_check(cm, CM_OPEN_PLAYBACK, substream)) < 0)
                return err;
        runtime->hw = snd_cmipci_playback;
+       runtime->hw.channels_max = cm->max_channels;
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        cm->dig_pcm_status = cm->dig_status;
        return 0;
 }
 
-static int snd_cmipci_capture_open(snd_pcm_substream_t *substream)
+static int snd_cmipci_capture_open(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = open_device_check(cm, CM_OPEN_CAPTURE, substream)) < 0)
                return err;
        runtime->hw = snd_cmipci_capture;
+       if (cm->chip_version == 68) {   // 8768 only supports 44k/48k recording
+               runtime->hw.rate_min = 41000;
+               runtime->hw.rates = SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000;
+       }
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        return 0;
 }
 
-static int snd_cmipci_playback2_open(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback2_open(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = open_device_check(cm, CM_OPEN_PLAYBACK2, substream)) < 0) /* use channel B */
@@ -1543,8 +1552,10 @@ static int snd_cmipci_playback2_open(snd_pcm_substream_t *substream)
                        runtime->hw.channels_max = cm->max_channels;
                        if (cm->max_channels == 4)
                                snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels_4);
-                       else
+                       else if (cm->max_channels == 6)
                                snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels_6);
+                       else if (cm->max_channels == 8)
+                               snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &hw_constraints_channels_8);
                }
                snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        }
@@ -1552,10 +1563,10 @@ static int snd_cmipci_playback2_open(snd_pcm_substream_t *substream)
        return 0;
 }
 
-static int snd_cmipci_playback_spdif_open(snd_pcm_substream_t *substream)
+static int snd_cmipci_playback_spdif_open(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = open_device_check(cm, CM_OPEN_SPDIF_PLAYBACK, substream)) < 0) /* use channel A */
@@ -1572,10 +1583,10 @@ static int snd_cmipci_playback_spdif_open(snd_pcm_substream_t *substream)
        return 0;
 }
 
-static int snd_cmipci_capture_spdif_open(snd_pcm_substream_t * substream)
+static int snd_cmipci_capture_spdif_open(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
-       snd_pcm_runtime_t *runtime = substream->runtime;
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       struct snd_pcm_runtime *runtime = substream->runtime;
        int err;
 
        if ((err = open_device_check(cm, CM_OPEN_SPDIF_CAPTURE, substream)) < 0) /* use channel B */
@@ -1589,38 +1600,38 @@ static int snd_cmipci_capture_spdif_open(snd_pcm_substream_t * substream)
 /*
  */
 
-static int snd_cmipci_playback_close(snd_pcm_substream_t * substream)
+static int snd_cmipci_playback_close(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        close_device_check(cm, CM_OPEN_PLAYBACK);
        return 0;
 }
 
-static int snd_cmipci_capture_close(snd_pcm_substream_t * substream)
+static int snd_cmipci_capture_close(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        close_device_check(cm, CM_OPEN_CAPTURE);
        return 0;
 }
 
-static int snd_cmipci_playback2_close(snd_pcm_substream_t * substream)
+static int snd_cmipci_playback2_close(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        close_device_check(cm, CM_OPEN_PLAYBACK2);
        close_device_check(cm, CM_OPEN_PLAYBACK_MULTI);
        return 0;
 }
 
-static int snd_cmipci_playback_spdif_close(snd_pcm_substream_t * substream)
+static int snd_cmipci_playback_spdif_close(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        close_device_check(cm, CM_OPEN_SPDIF_PLAYBACK);
        return 0;
 }
 
-static int snd_cmipci_capture_spdif_close(snd_pcm_substream_t * substream)
+static int snd_cmipci_capture_spdif_close(struct snd_pcm_substream *substream)
 {
-       cmipci_t *cm = snd_pcm_substream_chip(substream);
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
        close_device_check(cm, CM_OPEN_SPDIF_CAPTURE);
        return 0;
 }
@@ -1629,7 +1640,7 @@ static int snd_cmipci_capture_spdif_close(snd_pcm_substream_t * substream)
 /*
  */
 
-static snd_pcm_ops_t snd_cmipci_playback_ops = {
+static struct snd_pcm_ops snd_cmipci_playback_ops = {
        .open =         snd_cmipci_playback_open,
        .close =        snd_cmipci_playback_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1640,7 +1651,7 @@ static snd_pcm_ops_t snd_cmipci_playback_ops = {
        .pointer =      snd_cmipci_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_cmipci_capture_ops = {
+static struct snd_pcm_ops snd_cmipci_capture_ops = {
        .open =         snd_cmipci_capture_open,
        .close =        snd_cmipci_capture_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1651,7 +1662,7 @@ static snd_pcm_ops_t snd_cmipci_capture_ops = {
        .pointer =      snd_cmipci_capture_pointer,
 };
 
-static snd_pcm_ops_t snd_cmipci_playback2_ops = {
+static struct snd_pcm_ops snd_cmipci_playback2_ops = {
        .open =         snd_cmipci_playback2_open,
        .close =        snd_cmipci_playback2_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1662,7 +1673,7 @@ static snd_pcm_ops_t snd_cmipci_playback2_ops = {
        .pointer =      snd_cmipci_capture_pointer,     /* channel B */
 };
 
-static snd_pcm_ops_t snd_cmipci_playback_spdif_ops = {
+static struct snd_pcm_ops snd_cmipci_playback_spdif_ops = {
        .open =         snd_cmipci_playback_spdif_open,
        .close =        snd_cmipci_playback_spdif_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1673,7 +1684,7 @@ static snd_pcm_ops_t snd_cmipci_playback_spdif_ops = {
        .pointer =      snd_cmipci_playback_pointer,
 };
 
-static snd_pcm_ops_t snd_cmipci_capture_spdif_ops = {
+static struct snd_pcm_ops snd_cmipci_capture_spdif_ops = {
        .open =         snd_cmipci_capture_spdif_open,
        .close =        snd_cmipci_capture_spdif_close,
        .ioctl =        snd_pcm_lib_ioctl,
@@ -1688,14 +1699,9 @@ static snd_pcm_ops_t snd_cmipci_capture_spdif_ops = {
 /*
  */
 
-static void snd_cmipci_pcm_free(snd_pcm_t *pcm)
-{
-       snd_pcm_lib_preallocate_free_for_all(pcm);
-}
-
-static int __devinit snd_cmipci_pcm_new(cmipci_t *cm, int device)
+static int __devinit snd_cmipci_pcm_new(struct cmipci *cm, int device)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm);
@@ -1706,7 +1712,6 @@ static int __devinit snd_cmipci_pcm_new(cmipci_t *cm, int device)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cmipci_capture_ops);
 
        pcm->private_data = cm;
-       pcm->private_free = snd_cmipci_pcm_free;
        pcm->info_flags = 0;
        strcpy(pcm->name, "C-Media PCI DAC/ADC");
        cm->pcm = pcm;
@@ -1717,9 +1722,9 @@ static int __devinit snd_cmipci_pcm_new(cmipci_t *cm, int device)
        return 0;
 }
 
-static int __devinit snd_cmipci_pcm2_new(cmipci_t *cm, int device)
+static int __devinit snd_cmipci_pcm2_new(struct cmipci *cm, int device)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 0, &pcm);
@@ -1729,7 +1734,6 @@ static int __devinit snd_cmipci_pcm2_new(cmipci_t *cm, int device)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_cmipci_playback2_ops);
 
        pcm->private_data = cm;
-       pcm->private_free = snd_cmipci_pcm_free;
        pcm->info_flags = 0;
        strcpy(pcm->name, "C-Media PCI 2nd DAC");
        cm->pcm2 = pcm;
@@ -1740,9 +1744,9 @@ static int __devinit snd_cmipci_pcm2_new(cmipci_t *cm, int device)
        return 0;
 }
 
-static int __devinit snd_cmipci_pcm_spdif_new(cmipci_t *cm, int device)
+static int __devinit snd_cmipci_pcm_spdif_new(struct cmipci *cm, int device)
 {
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
        int err;
 
        err = snd_pcm_new(cm->card, cm->card->driver, device, 1, 1, &pcm);
@@ -1753,7 +1757,6 @@ static int __devinit snd_cmipci_pcm_spdif_new(cmipci_t *cm, int device)
        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_cmipci_capture_spdif_ops);
 
        pcm->private_data = cm;
-       pcm->private_free = snd_cmipci_pcm_free;
        pcm->info_flags = 0;
        strcpy(pcm->name, "C-Media PCI IEC958");
        cm->pcm_spdif = pcm;
@@ -1773,13 +1776,13 @@ static int __devinit snd_cmipci_pcm_spdif_new(cmipci_t *cm, int device)
  *   - Output mute switches
  */
 
-static void snd_cmipci_mixer_write(cmipci_t *s, unsigned char idx, unsigned char data)
+static void snd_cmipci_mixer_write(struct cmipci *s, unsigned char idx, unsigned char data)
 {
        outb(idx, s->iobase + CM_REG_SB16_ADDR);
        outb(data, s->iobase + CM_REG_SB16_DATA);
 }
 
-static unsigned char snd_cmipci_mixer_read(cmipci_t *s, unsigned char idx)
+static unsigned char snd_cmipci_mixer_read(struct cmipci *s, unsigned char idx)
 {
        unsigned char v;
 
@@ -1791,13 +1794,13 @@ static unsigned char snd_cmipci_mixer_read(cmipci_t *s, unsigned char idx)
 /*
  * general mixer element
  */
-typedef struct cmipci_sb_reg {
+struct cmipci_sb_reg {
        unsigned int left_reg, right_reg;
        unsigned int left_shift, right_shift;
        unsigned int mask;
        unsigned int invert: 1;
        unsigned int stereo: 1;
-} cmipci_sb_reg_t;
+};
 
 #define COMPOSE_SB_REG(lreg,rreg,lshift,rshift,mask,invert,stereo) \
  ((lreg) | ((rreg) << 8) | (lshift << 16) | (rshift << 19) | (mask << 24) | (invert << 22) | (stereo << 23))
@@ -1814,7 +1817,7 @@ typedef struct cmipci_sb_reg {
 #define CMIPCI_SB_SW_STEREO(xname,lshift,rshift) CMIPCI_DOUBLE(xname, SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, lshift, rshift, 1, 0, 1)
 #define CMIPCI_SB_SW_MONO(xname,shift) CMIPCI_DOUBLE(xname, SB_DSP4_OUTPUT_SW, SB_DSP4_OUTPUT_SW, shift, shift, 1, 0, 0)
 
-static void cmipci_sb_reg_decode(cmipci_sb_reg_t *r, unsigned long val)
+static void cmipci_sb_reg_decode(struct cmipci_sb_reg *r, unsigned long val)
 {
        r->left_reg = val & 0xff;
        r->right_reg = (val >> 8) & 0xff;
@@ -1825,9 +1828,10 @@ static void cmipci_sb_reg_decode(cmipci_sb_reg_t *r, unsigned long val)
        r->mask = (val >> 24) & 0xff;
 }
 
-static int snd_cmipci_info_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_cmipci_info_volume(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_info *uinfo)
 {
-       cmipci_sb_reg_t reg;
+       struct cmipci_sb_reg reg;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
        uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -1837,15 +1841,15 @@ static int snd_cmipci_info_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t
        return 0;
 }
  
-static int snd_cmipci_get_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_get_volume(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       cmipci_sb_reg_t reg;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        int val;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        val = (snd_cmipci_mixer_read(cm, reg.left_reg) >> reg.left_shift) & reg.mask;
        if (reg.invert)
                val = reg.mask - val;
@@ -1856,15 +1860,15 @@ static int snd_cmipci_get_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                        val = reg.mask - val;
                 ucontrol->value.integer.value[1] = val;
        }
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return 0;
 }
 
-static int snd_cmipci_put_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_put_volume(struct snd_kcontrol *kcontrol,
+                                struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       cmipci_sb_reg_t reg;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        int change;
        int left, right, oleft, oright;
 
@@ -1880,7 +1884,7 @@ static int snd_cmipci_put_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                right <<= reg.right_shift;
        } else
                right = 0;
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        oleft = snd_cmipci_mixer_read(cm, reg.left_reg);
        left |= oleft & ~(reg.mask << reg.left_shift);
        change = left != oleft;
@@ -1895,7 +1899,7 @@ static int snd_cmipci_put_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
                snd_cmipci_mixer_write(cm, reg.right_reg, right);
        } else
                snd_cmipci_mixer_write(cm, reg.left_reg, left);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return change;
 }
 
@@ -1909,7 +1913,8 @@ static int snd_cmipci_put_volume(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t
   .private_value = COMPOSE_SB_REG(SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, left_shift, right_shift, 1, 0, 1), \
 }
 
-static int snd_cmipci_info_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_info_t * uinfo)
+static int snd_cmipci_info_input_sw(struct snd_kcontrol *kcontrol,
+                                   struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        uinfo->count = 4;
@@ -1918,18 +1923,18 @@ static int snd_cmipci_info_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_info
        return 0;
 }
  
-static int snd_cmipci_get_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_get_input_sw(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       cmipci_sb_reg_t reg;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        int val1, val2;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        val1 = snd_cmipci_mixer_read(cm, reg.left_reg);
        val2 = snd_cmipci_mixer_read(cm, reg.right_reg);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        ucontrol->value.integer.value[0] = (val1 >> reg.left_shift) & 1;
        ucontrol->value.integer.value[1] = (val2 >> reg.left_shift) & 1;
        ucontrol->value.integer.value[2] = (val1 >> reg.right_shift) & 1;
@@ -1937,16 +1942,16 @@ static int snd_cmipci_get_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
        return 0;
 }
 
-static int snd_cmipci_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_put_input_sw(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       unsigned long flags;
-       cmipci_sb_reg_t reg;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        int change;
        int val1, val2, oval1, oval2;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        oval1 = snd_cmipci_mixer_read(cm, reg.left_reg);
        oval2 = snd_cmipci_mixer_read(cm, reg.right_reg);
        val1 = oval1 & ~((1 << reg.left_shift) | (1 << reg.right_shift));
@@ -1958,7 +1963,7 @@ static int snd_cmipci_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
        change = val1 != oval1 || val2 != oval2;
        snd_cmipci_mixer_write(cm, reg.left_reg, val1);
        snd_cmipci_mixer_write(cm, reg.right_reg, val2);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return change;
 }
 
@@ -1994,9 +1999,10 @@ static int snd_cmipci_put_input_sw(snd_kcontrol_t * kcontrol, snd_ctl_elem_value
   .private_value = COMPOSE_SB_REG(reg, reg, shift, shift, mask, 0, 0), \
 }
 
-static int snd_cmipci_info_native_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
+static int snd_cmipci_info_native_mixer(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_info *uinfo)
 {
-       cmipci_sb_reg_t reg;
+       struct cmipci_sb_reg reg;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
        uinfo->type = reg.mask == 1 ? SNDRV_CTL_ELEM_TYPE_BOOLEAN : SNDRV_CTL_ELEM_TYPE_INTEGER;
@@ -2007,15 +2013,15 @@ static int snd_cmipci_info_native_mixer(snd_kcontrol_t *kcontrol, snd_ctl_elem_i
 
 }
 
-static int snd_cmipci_get_native_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_get_native_mixer(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       cmipci_sb_reg_t reg;
-       unsigned long flags;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        unsigned char oreg, val;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        oreg = inb(cm->iobase + reg.left_reg);
        val = (oreg >> reg.left_shift) & reg.mask;
        if (reg.invert)
@@ -2027,19 +2033,19 @@ static int snd_cmipci_get_native_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_v
                        val = reg.mask - val;
                ucontrol->value.integer.value[1] = val;
        }
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return 0;
 }
 
-static int snd_cmipci_put_native_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_value_t * ucontrol)
+static int snd_cmipci_put_native_mixer(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
-       cmipci_sb_reg_t reg;
-       unsigned long flags;
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci_sb_reg reg;
        unsigned char oreg, nreg, val;
 
        cmipci_sb_reg_decode(&reg, kcontrol->private_value);
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        oreg = inb(cm->iobase + reg.left_reg);
        val = ucontrol->value.integer.value[0] & reg.mask;
        if (reg.invert)
@@ -2054,22 +2060,24 @@ static int snd_cmipci_put_native_mixer(snd_kcontrol_t * kcontrol, snd_ctl_elem_v
                nreg |= (val << reg.right_shift);
        }
        outb(nreg, cm->iobase + reg.left_reg);
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return (nreg != oreg);
 }
 
 /*
  * special case - check mixer sensitivity
  */
-static int snd_cmipci_get_native_mixer_sensitive(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_get_native_mixer_sensitive(struct snd_kcontrol *kcontrol,
+                                                struct snd_ctl_elem_value *ucontrol)
 {
-       //cmipci_t *cm = snd_kcontrol_chip(kcontrol);
+       //struct cmipci *cm = snd_kcontrol_chip(kcontrol);
        return snd_cmipci_get_native_mixer(kcontrol, ucontrol);
 }
 
-static int snd_cmipci_put_native_mixer_sensitive(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_put_native_mixer_sensitive(struct snd_kcontrol *kcontrol,
+                                                struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
        if (cm->mixer_insensitive) {
                /* ignored */
                return 0;
@@ -2078,9 +2086,7 @@ static int snd_cmipci_put_native_mixer_sensitive(snd_kcontrol_t *kcontrol, snd_c
 }
 
 
-#define num_controls(ary) (sizeof(ary) / sizeof(snd_kcontrol_new_t))
-
-static snd_kcontrol_new_t snd_cmipci_mixers[] __devinitdata = {
+static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
        CMIPCI_SB_VOL_STEREO("Master Playback Volume", SB_DSP4_MASTER_DEV, 3, 31),
        CMIPCI_MIXER_SW_MONO("3D Control - Switch", CM_REG_MIXER1, CM_X3DEN_SHIFT, 0),
        CMIPCI_SB_VOL_STEREO("PCM Playback Volume", SB_DSP4_PCM_DEV, 3, 31),
@@ -2110,23 +2116,30 @@ static snd_kcontrol_new_t snd_cmipci_mixers[] __devinitdata = {
        CMIPCI_MIXER_VOL_STEREO("Aux Playback Volume", CM_REG_AUX_VOL, 4, 0, 15),
        CMIPCI_MIXER_SW_STEREO("Aux Playback Switch", CM_REG_MIXER2, CM_VAUXLM_SHIFT, CM_VAUXRM_SHIFT, 0),
        CMIPCI_MIXER_SW_STEREO("Aux Capture Switch", CM_REG_MIXER2, CM_RAUXLEN_SHIFT, CM_RAUXREN_SHIFT, 0),
-       CMIPCI_MIXER_SW_MONO("Mic Boost", CM_REG_MIXER2, CM_MICGAINZ_SHIFT, 1),
+       CMIPCI_MIXER_SW_MONO("Mic Boost Playback Switch", CM_REG_MIXER2, CM_MICGAINZ_SHIFT, 1),
        CMIPCI_MIXER_VOL_MONO("Mic Capture Volume", CM_REG_MIXER2, CM_VADMIC_SHIFT, 7),
+       CMIPCI_SB_VOL_MONO("Phone Playback Volume", CM_REG_EXTENT_IND, 5, 7),
+       CMIPCI_DOUBLE("Phone Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 4, 4, 1, 0, 0),
+       CMIPCI_DOUBLE("PC Speaker Playnack Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0),
+       CMIPCI_DOUBLE("Mic Boost Capture Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 0, 0, 1, 0, 0),
 };
 
 /*
  * other switches
  */
 
-typedef struct snd_cmipci_switch_args {
+struct cmipci_switch_args {
        int reg;                /* register index */
        unsigned int mask;      /* mask bits */
        unsigned int mask_on;   /* mask bits to turn on */
-       int is_byte: 1;         /* byte access? */
-       int ac3_sensitive: 1;   /* access forbidden during non-audio operation? */
-} snd_cmipci_switch_args_t;
+       unsigned int is_byte: 1;                /* byte access? */
+       unsigned int ac3_sensitive: 1;  /* access forbidden during
+                                        * non-audio operation?
+                                        */
+};
 
-static int snd_cmipci_uswitch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t *uinfo)
+static int snd_cmipci_uswitch_info(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_info *uinfo)
 {
        uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
        uinfo->count = 1;
@@ -2135,16 +2148,17 @@ static int snd_cmipci_uswitch_info(snd_kcontrol_t *kcontrol, snd_ctl_elem_info_t
        return 0;
 }
 
-static int _snd_cmipci_uswitch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol, snd_cmipci_switch_args_t *args)
+static int _snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol,
+                                  struct cmipci_switch_args *args)
 {
-       unsigned long flags;
        unsigned int val;
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        if (args->ac3_sensitive && cm->mixer_insensitive) {
                ucontrol->value.integer.value[0] = 0;
-               spin_unlock_irqrestore(&cm->reg_lock, flags);
+               spin_unlock_irq(&cm->reg_lock);
                return 0;
        }
        if (args->is_byte)
@@ -2152,28 +2166,31 @@ static int _snd_cmipci_uswitch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_
        else
                val = snd_cmipci_read(cm, args->reg);
        ucontrol->value.integer.value[0] = ((val & args->mask) == args->mask_on) ? 1 : 0;
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return 0;
 }
 
-static int snd_cmipci_uswitch_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
 {
-       snd_cmipci_switch_args_t *args = (snd_cmipci_switch_args_t*)kcontrol->private_value;
+       struct cmipci_switch_args *args;
+       args = (struct cmipci_switch_args *)kcontrol->private_value;
        snd_assert(args != NULL, return -EINVAL);
        return _snd_cmipci_uswitch_get(kcontrol, ucontrol, args);
 }
 
-static int _snd_cmipci_uswitch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol, snd_cmipci_switch_args_t *args)
+static int _snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,
+                                  struct snd_ctl_elem_value *ucontrol,
+                                  struct cmipci_switch_args *args)
 {
-       unsigned long flags;
        unsigned int val;
        int change;
-       cmipci_t *cm = snd_kcontrol_chip(kcontrol);
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        if (args->ac3_sensitive && cm->mixer_insensitive) {
                /* ignored */
-               spin_unlock_irqrestore(&cm->reg_lock, flags);
+               spin_unlock_irq(&cm->reg_lock);
                return 0;
        }
        if (args->is_byte)
@@ -2192,19 +2209,21 @@ static int _snd_cmipci_uswitch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_
                else
                        snd_cmipci_write(cm, args->reg, val);
        }
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
        return change;
 }
 
-static int snd_cmipci_uswitch_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,
+                                 struct snd_ctl_elem_value *ucontrol)
 {
-       snd_cmipci_switch_args_t *args = (snd_cmipci_switch_args_t*)kcontrol->private_value;
+       struct cmipci_switch_args *args;
+       args = (struct cmipci_switch_args *)kcontrol->private_value;
        snd_assert(args != NULL, return -EINVAL);
        return _snd_cmipci_uswitch_put(kcontrol, ucontrol, args);
 }
 
 #define DEFINE_SWITCH_ARG(sname, xreg, xmask, xmask_on, xis_byte, xac3) \
-static snd_cmipci_switch_args_t cmipci_switch_arg_##sname = { \
+static struct cmipci_switch_args cmipci_switch_arg_##sname = { \
   .reg = xreg, \
   .mask = xmask, \
   .mask_on = xmask_on, \
@@ -2239,8 +2258,8 @@ DEFINE_SWITCH_ARG(exchange_dac, CM_REG_MISC_CTRL, CM_XCHGDAC, 0, 0, 0); /* rever
 DEFINE_SWITCH_ARG(exchange_dac, CM_REG_MISC_CTRL, CM_XCHGDAC, CM_XCHGDAC, 0, 0);
 #endif
 DEFINE_BIT_SWITCH_ARG(fourch, CM_REG_MISC_CTRL, CM_N4SPK3D, 0, 0);
-DEFINE_BIT_SWITCH_ARG(line_rear, CM_REG_MIXER1, CM_SPK4, 1, 0);
-DEFINE_BIT_SWITCH_ARG(line_bass, CM_REG_LEGACY_CTRL, CM_LINE_AS_BASS, 0, 0);
+// DEFINE_BIT_SWITCH_ARG(line_rear, CM_REG_MIXER1, CM_SPK4, 1, 0);
+// DEFINE_BIT_SWITCH_ARG(line_bass, CM_REG_LEGACY_CTRL, CM_LINE_AS_BASS, 0, 0);
 // DEFINE_BIT_SWITCH_ARG(joystick, CM_REG_FUNCTRL1, CM_JYSTK_EN, 0, 0); /* now module option */
 DEFINE_SWITCH_ARG(modem, CM_REG_MISC_CTRL, CM_FLINKON|CM_FLINKOFF, CM_FLINKON, 0, 0);
 
@@ -2261,7 +2280,8 @@ DEFINE_SWITCH_ARG(modem, CM_REG_MISC_CTRL, CM_FLINKON|CM_FLINKOFF, CM_FLINKON, 0
  * callbacks for spdif output switch
  * needs toggle two registers..
  */
-static int snd_cmipci_spdout_enable_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdout_enable_get(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_value *ucontrol)
 {
        int changed;
        changed = _snd_cmipci_uswitch_get(kcontrol, ucontrol, &cmipci_switch_arg_spdif_enable);
@@ -2269,9 +2289,10 @@ static int snd_cmipci_spdout_enable_get(snd_kcontrol_t *kcontrol, snd_ctl_elem_v
        return changed;
 }
 
-static int snd_cmipci_spdout_enable_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_value_t *ucontrol)
+static int snd_cmipci_spdout_enable_put(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_value *ucontrol)
 {
-       cmipci_t *chip = snd_kcontrol_chip(kcontrol);
+       struct cmipci *chip = snd_kcontrol_chip(kcontrol);
        int changed;
        changed = _snd_cmipci_uswitch_put(kcontrol, ucontrol, &cmipci_switch_arg_spdif_enable);
        changed |= _snd_cmipci_uswitch_put(kcontrol, ucontrol, &cmipci_switch_arg_spdo2dac);
@@ -2289,18 +2310,122 @@ static int snd_cmipci_spdout_enable_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_v
 }
 
 
+static int snd_cmipci_line_in_mode_info(struct snd_kcontrol *kcontrol,
+                                       struct snd_ctl_elem_info *uinfo)
+{
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       static char *texts[3] = { "Line-In", "Rear Output", "Bass Output" };
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = cm->chip_version >= 39 ? 3 : 2;
+       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+               uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
+       strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+       return 0;
+}
+
+static inline unsigned int get_line_in_mode(struct cmipci *cm)
+{
+       unsigned int val;
+       if (cm->chip_version >= 39) {
+               val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL);
+               if (val & CM_LINE_AS_BASS)
+                       return 2;
+       }
+       val = snd_cmipci_read_b(cm, CM_REG_MIXER1);
+       if (val & CM_SPK4)
+               return 1;
+       return 0;
+}
+
+static int snd_cmipci_line_in_mode_get(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
+{
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+
+       spin_lock_irq(&cm->reg_lock);
+       ucontrol->value.enumerated.item[0] = get_line_in_mode(cm);
+       spin_unlock_irq(&cm->reg_lock);
+       return 0;
+}
+
+static int snd_cmipci_line_in_mode_put(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_value *ucontrol)
+{
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       int change;
+
+       spin_lock_irq(&cm->reg_lock);
+       if (ucontrol->value.enumerated.item[0] == 2)
+               change = snd_cmipci_set_bit(cm, CM_REG_LEGACY_CTRL, CM_LINE_AS_BASS);
+       else
+               change = snd_cmipci_clear_bit(cm, CM_REG_LEGACY_CTRL, CM_LINE_AS_BASS);
+       if (ucontrol->value.enumerated.item[0] == 1)
+               change |= snd_cmipci_set_bit_b(cm, CM_REG_MIXER1, CM_SPK4);
+       else
+               change |= snd_cmipci_clear_bit_b(cm, CM_REG_MIXER1, CM_SPK4);
+       spin_unlock_irq(&cm->reg_lock);
+       return change;
+}
+
+static int snd_cmipci_mic_in_mode_info(struct snd_kcontrol *kcontrol,
+                                      struct snd_ctl_elem_info *uinfo)
+{
+       static char *texts[2] = { "Mic-In", "Center/LFE Output" };
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+       uinfo->count = 1;
+       uinfo->value.enumerated.items = 2;
+       if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
+               uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
+       strcpy(uinfo->value.enumerated.name, texts[uinfo->value.enumerated.item]);
+       return 0;
+}
+
+static int snd_cmipci_mic_in_mode_get(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol)
+{
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       /* same bit as spdi_phase */
+       spin_lock_irq(&cm->reg_lock);
+       ucontrol->value.enumerated.item[0] = 
+               (snd_cmipci_read_b(cm, CM_REG_MISC) & CM_SPDIF_INVERSE) ? 1 : 0;
+       spin_unlock_irq(&cm->reg_lock);
+       return 0;
+}
+
+static int snd_cmipci_mic_in_mode_put(struct snd_kcontrol *kcontrol,
+                                     struct snd_ctl_elem_value *ucontrol)
+{
+       struct cmipci *cm = snd_kcontrol_chip(kcontrol);
+       int change;
+
+       spin_lock_irq(&cm->reg_lock);
+       if (ucontrol->value.enumerated.item[0])
+               change = snd_cmipci_set_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE);
+       else
+               change = snd_cmipci_clear_bit_b(cm, CM_REG_MISC, CM_SPDIF_INVERSE);
+       spin_unlock_irq(&cm->reg_lock);
+       return change;
+}
+
 /* both for CM8338/8738 */
-static snd_kcontrol_new_t snd_cmipci_mixer_switches[] __devinitdata = {
+static struct snd_kcontrol_new snd_cmipci_mixer_switches[] __devinitdata = {
        DEFINE_MIXER_SWITCH("Four Channel Mode", fourch),
-       DEFINE_MIXER_SWITCH("Line-In As Rear", line_rear),
+       {
+               .name = "Line-In Mode",
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .info = snd_cmipci_line_in_mode_info,
+               .get = snd_cmipci_line_in_mode_get,
+               .put = snd_cmipci_line_in_mode_put,
+       },
 };
 
 /* for non-multichannel chips */
-static snd_kcontrol_new_t snd_cmipci_nomulti_switch __devinitdata =
+static struct snd_kcontrol_new snd_cmipci_nomulti_switch __devinitdata =
 DEFINE_MIXER_SWITCH("Exchange DAC", exchange_dac);
 
 /* only for CM8738 */
-static snd_kcontrol_new_t snd_cmipci_8738_mixer_switches[] __devinitdata = {
+static struct snd_kcontrol_new snd_cmipci_8738_mixer_switches[] __devinitdata = {
 #if 0 /* controlled in pcm device */
        DEFINE_MIXER_SWITCH("IEC958 In Record", spdif_in),
        DEFINE_MIXER_SWITCH("IEC958 Out", spdif_out),
@@ -2322,33 +2447,37 @@ static snd_kcontrol_new_t snd_cmipci_8738_mixer_switches[] __devinitdata = {
 };
 
 /* only for model 033/037 */
-static snd_kcontrol_new_t snd_cmipci_old_mixer_switches[] __devinitdata = {
+static struct snd_kcontrol_new snd_cmipci_old_mixer_switches[] __devinitdata = {
        DEFINE_MIXER_SWITCH("IEC958 Mix Analog", spdif_dac_out),
        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase),
        DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel1),
 };
 
 /* only for model 039 or later */
-static snd_kcontrol_new_t snd_cmipci_extra_mixer_switches[] __devinitdata = {
-       DEFINE_MIXER_SWITCH("Line-In As Bass", line_bass),
+static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata = {
        DEFINE_MIXER_SWITCH("IEC958 In Select", spdif_in_sel2),
        DEFINE_MIXER_SWITCH("IEC958 In Phase Inverse", spdi_phase2),
-       DEFINE_MIXER_SWITCH("Mic As Center/LFE", spdi_phase), /* same bit as spdi_phase */
+       {
+               .name = "Mic-In Mode",
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .info = snd_cmipci_mic_in_mode_info,
+               .get = snd_cmipci_mic_in_mode_get,
+               .put = snd_cmipci_mic_in_mode_put,
+       }
 };
 
 /* card control switches */
-static snd_kcontrol_new_t snd_cmipci_control_switches[] __devinitdata = {
+static struct snd_kcontrol_new snd_cmipci_control_switches[] __devinitdata = {
        // DEFINE_CARD_SWITCH("Joystick", joystick), /* now module option */
        DEFINE_CARD_SWITCH("Modem", modem),
 };
 
 
-static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
+static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
 {
-       unsigned long flags;
-       snd_card_t *card;
-       snd_kcontrol_new_t *sw;
-       snd_kcontrol_t *kctl;
+       struct snd_card *card;
+       struct snd_kcontrol_new *sw;
+       struct snd_kcontrol *kctl;
        unsigned int idx;
        int err;
 
@@ -2358,18 +2487,23 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
 
        strcpy(card->mixername, "CMedia PCI");
 
-       spin_lock_irqsave(&cm->reg_lock, flags);
+       spin_lock_irq(&cm->reg_lock);
        snd_cmipci_mixer_write(cm, 0x00, 0x00);         /* mixer reset */
-       spin_unlock_irqrestore(&cm->reg_lock, flags);
+       spin_unlock_irq(&cm->reg_lock);
 
-       for (idx = 0; idx < num_controls(snd_cmipci_mixers); idx++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_mixers); idx++) {
+               if (cm->chip_version == 68) {   // 8768 has no PCM volume
+                       if (!strcmp(snd_cmipci_mixers[idx].name,
+                               "PCM Playback Volume"))
+                               continue;
+               }
                if ((err = snd_ctl_add(card, snd_ctl_new1(&snd_cmipci_mixers[idx], cm))) < 0)
                        return err;
        }
 
        /* mixer switches */
        sw = snd_cmipci_mixer_switches;
-       for (idx = 0; idx < num_controls(snd_cmipci_mixer_switches); idx++, sw++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_mixer_switches); idx++, sw++) {
                err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
                if (err < 0)
                        return err;
@@ -2382,7 +2516,7 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
        if (cm->device == PCI_DEVICE_ID_CMEDIA_CM8738 ||
            cm->device == PCI_DEVICE_ID_CMEDIA_CM8738B) {
                sw = snd_cmipci_8738_mixer_switches;
-               for (idx = 0; idx < num_controls(snd_cmipci_8738_mixer_switches); idx++, sw++) {
+               for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_8738_mixer_switches); idx++, sw++) {
                        err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
                        if (err < 0)
                                return err;
@@ -2400,7 +2534,7 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
                }
                if (cm->chip_version <= 37) {
                        sw = snd_cmipci_old_mixer_switches;
-                       for (idx = 0; idx < num_controls(snd_cmipci_old_mixer_switches); idx++, sw++) {
+                       for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_old_mixer_switches); idx++, sw++) {
                                err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
                                if (err < 0)
                                        return err;
@@ -2409,7 +2543,7 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
        }
        if (cm->chip_version >= 39) {
                sw = snd_cmipci_extra_mixer_switches;
-               for (idx = 0; idx < num_controls(snd_cmipci_extra_mixer_switches); idx++, sw++) {
+               for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_extra_mixer_switches); idx++, sw++) {
                        err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
                        if (err < 0)
                                return err;
@@ -2418,15 +2552,15 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
 
        /* card switches */
        sw = snd_cmipci_control_switches;
-       for (idx = 0; idx < num_controls(snd_cmipci_control_switches); idx++, sw++) {
+       for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_control_switches); idx++, sw++) {
                err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
                if (err < 0)
                        return err;
        }
 
        for (idx = 0; idx < CM_SAVED_MIXERS; idx++) {
-               snd_ctl_elem_id_t id;
-               snd_kcontrol_t *ctl;
+               struct snd_ctl_elem_id id;
+               struct snd_kcontrol *ctl;
                memset(&id, 0, sizeof(id));
                id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
                strcpy(id.name, cm_saved_mixer[idx].name);
@@ -2443,10 +2577,10 @@ static int __devinit snd_cmipci_mixer_new(cmipci_t *cm, int pcm_spdif_device)
  */
 
 #ifdef CONFIG_PROC_FS
-static void snd_cmipci_proc_read(snd_info_entry_t *entry, 
-                                snd_info_buffer_t *buffer)
+static void snd_cmipci_proc_read(struct snd_info_entry *entry, 
+                                struct snd_info_buffer *buffer)
 {
-       cmipci_t *cm = snd_magic_cast(cmipci_t, entry->private_data, return);
+       struct cmipci *cm = entry->private_data;
        int i;
        
        snd_iprintf(buffer, "%s\n\n", cm->card->longname);
@@ -2462,15 +2596,15 @@ static void snd_cmipci_proc_read(snd_info_entry_t *entry,
        }
 }
 
-static void __devinit snd_cmipci_proc_init(cmipci_t *cm)
+static void __devinit snd_cmipci_proc_init(struct cmipci *cm)
 {
-       snd_info_entry_t *entry;
+       struct snd_info_entry *entry;
 
        if (! snd_card_proc_new(cm->card, "cmipci", &entry))
                snd_info_set_text_ops(entry, cm, 1024, snd_cmipci_proc_read);
 }
 #else /* !CONFIG_PROC_FS */
-static inline void snd_cmipci_proc_init(cmipci_t *cm) {}
+static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
 #endif
 
 
@@ -2488,7 +2622,7 @@ static struct pci_device_id snd_cmipci_ids[] = {
  * check chip version and capabilities
  * driver name is modified according to the chip model
  */
-static void __devinit query_chip(cmipci_t *cm)
+static void __devinit query_chip(struct cmipci *cm)
 {
        unsigned int detect;
 
@@ -2513,34 +2647,98 @@ static void __devinit query_chip(cmipci_t *cm)
                }
        } else {
                /* check reg 0Ch, bit 26 */
-               if (detect & CM_CHIP_039) {
+               if (detect & CM_CHIP_8768) {
+                       cm->chip_version = 68;
+                       cm->max_channels = 8;
+                       cm->can_ac3_hw = 1;
+                       cm->has_dual_dac = 1;
+                       cm->can_multi_ch = 1;
+               } else if (detect & CM_CHIP_055) {
+                       cm->chip_version = 55;
+                       cm->max_channels = 6;
+                       cm->can_ac3_hw = 1;
+                       cm->has_dual_dac = 1;
+                       cm->can_multi_ch = 1;
+               } else if (detect & CM_CHIP_039) {
                        cm->chip_version = 39;
-                       if (detect & CM_CHIP_039_6CH)
-                               cm->max_channels  = 6;
+                       if (detect & CM_CHIP_039_6CH) /* 4 or 6 channels */
+                               cm->max_channels = 6;
                        else
                                cm->max_channels = 4;
                        cm->can_ac3_hw = 1;
                        cm->has_dual_dac = 1;
                        cm->can_multi_ch = 1;
                } else {
-                       cm->chip_version = 55; /* 4 or 6 channels */
-                       cm->max_channels  = 6;
-                       cm->can_ac3_hw = 1;
-                       cm->has_dual_dac = 1;
-                       cm->can_multi_ch = 1;
+                       printk(KERN_ERR "chip %x version not supported\n", detect);
                }
        }
+}
 
-       /* added -MCx suffix for chip supporting multi-channels */
-       if (cm->can_multi_ch)
-               sprintf(cm->card->driver + strlen(cm->card->driver),
-                       "-MC%d", cm->max_channels);
-       else if (cm->can_ac3_sw)
-               strcpy(cm->card->driver + strlen(cm->card->driver), "-SWIEC");
+#ifdef SUPPORT_JOYSTICK
+static int __devinit snd_cmipci_create_gameport(struct cmipci *cm, int dev)
+{
+       static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
+       struct gameport *gp;
+       struct resource *r = NULL;
+       int i, io_port = 0;
+
+       if (joystick_port[dev] == 0)
+               return -ENODEV;
+
+       if (joystick_port[dev] == 1) { /* auto-detect */
+               for (i = 0; ports[i]; i++) {
+                       io_port = ports[i];
+                       r = request_region(io_port, 1, "CMIPCI gameport");
+                       if (r)
+                               break;
+               }
+       } else {
+               io_port = joystick_port[dev];
+               r = request_region(io_port, 1, "CMIPCI gameport");
+       }
+
+       if (!r) {
+               printk(KERN_WARNING "cmipci: cannot reserve joystick ports\n");
+               return -EBUSY;
+       }
+
+       cm->gameport = gp = gameport_allocate_port();
+       if (!gp) {
+               printk(KERN_ERR "cmipci: cannot allocate memory for gameport\n");
+               release_and_free_resource(r);
+               return -ENOMEM;
+       }
+       gameport_set_name(gp, "C-Media Gameport");
+       gameport_set_phys(gp, "pci%s/gameport0", pci_name(cm->pci));
+       gameport_set_dev_parent(gp, &cm->pci->dev);
+       gp->io = io_port;
+       gameport_set_port_data(gp, r);
+
+       snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
+
+       gameport_register_port(cm->gameport);
+
+       return 0;
 }
 
+static void snd_cmipci_free_gameport(struct cmipci *cm)
+{
+       if (cm->gameport) {
+               struct resource *r = gameport_get_port_data(cm->gameport);
+
+               gameport_unregister_port(cm->gameport);
+               cm->gameport = NULL;
+
+               snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
+               release_and_free_resource(r);
+       }
+}
+#else
+static inline int snd_cmipci_create_gameport(struct cmipci *cm, int dev) { return -ENOSYS; }
+static inline void snd_cmipci_free_gameport(struct cmipci *cm) { }
+#endif
 
-static int snd_cmipci_free(cmipci_t *cm)
+static int snd_cmipci_free(struct cmipci *cm)
 {
        if (cm->irq >= 0) {
                snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
@@ -2556,51 +2754,94 @@ static int snd_cmipci_free(cmipci_t *cm)
 
                synchronize_irq(cm->irq);
 
-               free_irq(cm->irq, (void *)cm);
-       }
-#ifdef SUPPORT_JOYSTICK
-       if (cm->res_joystick) {
-               gameport_unregister_port(&cm->gameport);
-               snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
-               release_resource(cm->res_joystick);
-               kfree_nocheck(cm->res_joystick);
-       }
-#endif
-       if (cm->res_iobase) {
-               release_resource(cm->res_iobase);
-               kfree_nocheck(cm->res_iobase);
+               free_irq(cm->irq, cm);
        }
-       snd_magic_kfree(cm);
+
+       snd_cmipci_free_gameport(cm);
+       pci_release_regions(cm->pci);
+       pci_disable_device(cm->pci);
+       kfree(cm);
        return 0;
 }
 
-static int snd_cmipci_dev_free(snd_device_t *device)
+static int snd_cmipci_dev_free(struct snd_device *device)
 {
-       cmipci_t *cm = snd_magic_cast(cmipci_t, device->device_data, return -ENXIO);
+       struct cmipci *cm = device->device_data;
        return snd_cmipci_free(cm);
 }
 
-static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
-                                      int dev, cmipci_t **rcmipci)
+static int __devinit snd_cmipci_create_fm(struct cmipci *cm, long fm_port)
+{
+       long iosynth;
+       unsigned int val;
+       struct snd_opl3 *opl3;
+       int err;
+
+       /* first try FM regs in PCI port range */
+       iosynth = cm->iobase + CM_REG_FM_PCI;
+       err = snd_opl3_create(cm->card, iosynth, iosynth + 2,
+                             OPL3_HW_OPL3, 1, &opl3);
+       if (err < 0) {
+               /* then try legacy ports */
+               val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
+               iosynth = fm_port;
+               switch (iosynth) {
+               case 0x3E8: val |= CM_FMSEL_3E8; break;
+               case 0x3E0: val |= CM_FMSEL_3E0; break;
+               case 0x3C8: val |= CM_FMSEL_3C8; break;
+               case 0x388: val |= CM_FMSEL_388; break;
+               default:
+                           return 0;
+               }
+               snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
+               /* enable FM */
+               snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
+
+               if (snd_opl3_create(cm->card, iosynth, iosynth + 2,
+                                   OPL3_HW_OPL3, 0, &opl3) < 0) {
+                       printk(KERN_ERR "cmipci: no OPL device at %#lx, "
+                              "skipping...\n", iosynth);
+                       /* disable FM */
+                       snd_cmipci_write(cm, CM_REG_LEGACY_CTRL,
+                                        val & ~CM_FMSEL_MASK);
+                       snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
+                       return 0;
+               }
+       }
+       if ((err = snd_opl3_hwdep_new(opl3, 0, 1, NULL)) < 0) {
+               printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
+               return err;
+       }
+       return 0;
+}
+
+static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pci,
+                                      int dev, struct cmipci **rcmipci)
 {
-       cmipci_t *cm;
+       struct cmipci *cm;
        int err;
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free =     snd_cmipci_dev_free,
        };
        unsigned int val = 0;
-       long iomidi = mpu_port[dev];
-       long iosynth = fm_port[dev];
+       long iomidi;
+       int integrated_midi;
        int pcm_index, pcm_spdif_index;
+       static struct pci_device_id intel_82437vx[] = {
+               { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
+               { },
+       };
 
        *rcmipci = NULL;
 
        if ((err = pci_enable_device(pci)) < 0)
                return err;
 
-       cm = snd_magic_kcalloc(cmipci_t, 0, GFP_KERNEL);
-       if (cm == NULL)
+       cm = kzalloc(sizeof(*cm), GFP_KERNEL);
+       if (cm == NULL) {
+               pci_disable_device(pci);
                return -ENOMEM;
+       }
 
        spin_lock_init(&cm->reg_lock);
        init_MUTEX(&cm->open_mutex);
@@ -2608,20 +2849,22 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
        cm->card = card;
        cm->pci = pci;
        cm->irq = -1;
-       cm->iobase = pci_resource_start(pci, 0);
        cm->channel[0].ch = 0;
        cm->channel[1].ch = 1;
        cm->channel[0].is_dac = cm->channel[1].is_dac = 1; /* dual DAC mode */
 
-       if ((cm->res_iobase = request_region(cm->iobase, CM_EXTENT_CODEC, card->driver)) == NULL) {
-               snd_printk("unable to grab ports 0x%lx-0x%lx\n", cm->iobase, cm->iobase + CM_EXTENT_CODEC - 1);
-               err = -EBUSY;
-               goto __error;
+       if ((err = pci_request_regions(pci, card->driver)) < 0) {
+               kfree(cm);
+               pci_disable_device(pci);
+               return err;
        }
-       if (request_irq(pci->irq, snd_cmipci_interrupt, SA_INTERRUPT|SA_SHIRQ, card->driver, (void *)cm)) {
-               snd_printk("unable to grab IRQ %d\n", pci->irq);
-               err = -EBUSY;
-               goto __error;
+       cm->iobase = pci_resource_start(pci, 0);
+
+       if (request_irq(pci->irq, snd_cmipci_interrupt,
+                       SA_INTERRUPT|SA_SHIRQ, card->driver, cm)) {
+               snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
+               snd_cmipci_free(cm);
+               return -EBUSY;
        }
        cm->irq = pci->irq;
 
@@ -2635,7 +2878,15 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
        cm->max_channels = 2;
        cm->do_soft_ac3 = soft_ac3[dev];
 
-       query_chip(cm);
+       if (pci->device != PCI_DEVICE_ID_CMEDIA_CM8338A &&
+           pci->device != PCI_DEVICE_ID_CMEDIA_CM8338B)
+               query_chip(cm);
+       /* added -MCx suffix for chip supporting multi-channels */
+       if (cm->can_multi_ch)
+               sprintf(cm->card->driver + strlen(cm->card->driver),
+                       "-MC%d", cm->max_channels);
+       else if (cm->can_ac3_sw)
+               strcpy(cm->card->driver + strlen(cm->card->driver), "-SWIEC");
 
        cm->dig_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
        cm->dig_pcm_status = SNDRV_PCM_DEFAULT_CON_SPDIF;
@@ -2667,60 +2918,40 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
        switch (pci->device) {
        case PCI_DEVICE_ID_CMEDIA_CM8738:
        case PCI_DEVICE_ID_CMEDIA_CM8738B:
-               /* PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX */
-               if (! pci_find_device(0x8086, 0x7030, NULL))
+               if (!pci_dev_present(intel_82437vx)) 
                        snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_TXVX);
                break;
        default:
                break;
        }
 
-       /* set MPU address */
-       switch (iomidi) {
-       case 0x320: val = CM_VMPU_320; break;
-       case 0x310: val = CM_VMPU_310; break;
-       case 0x300: val = CM_VMPU_300; break;
-       case 0x330: val = CM_VMPU_330; break;
-       default:
-               iomidi = 0; break;
-       }
-       if (iomidi > 0) {
-               snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
-               /* enable UART */
-               snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
-       }
-
-       /* set FM address */
-       val = snd_cmipci_read(cm, CM_REG_LEGACY_CTRL) & ~CM_FMSEL_MASK;
-       switch (iosynth) {
-       case 0x3E8: val |= CM_FMSEL_3E8; break;
-       case 0x3E0: val |= CM_FMSEL_3E0; break;
-       case 0x3C8: val |= CM_FMSEL_3C8; break;
-       case 0x388: val |= CM_FMSEL_388; break;
-       default:
-               iosynth = 0; break;
+       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, cm, &ops)) < 0) {
+               snd_cmipci_free(cm);
+               return err;
        }
-       if (iosynth > 0) {
-               snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
-               /* enable FM */
-               snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
 
-               if (snd_opl3_create(card, iosynth, iosynth + 2,
-                                   OPL3_HW_OPL3, 0, &cm->opl3) < 0) {
-                       printk(KERN_ERR "cmipci: no OPL device at 0x%lx, skipping...\n", iosynth);
-                       iosynth = 0;
-               } else {
-                       if ((err = snd_opl3_hwdep_new(cm->opl3, 0, 1, &cm->opl3hwdep)) < 0) {
-                               printk(KERN_ERR "cmipci: cannot create OPL3 hwdep\n");
-                               return err;
-                       }
+       integrated_midi = snd_cmipci_read_b(cm, CM_REG_MPU_PCI) != 0xff;
+       if (integrated_midi)
+               iomidi = cm->iobase + CM_REG_MPU_PCI;
+       else {
+               iomidi = mpu_port[dev];
+               switch (iomidi) {
+               case 0x320: val = CM_VMPU_320; break;
+               case 0x310: val = CM_VMPU_310; break;
+               case 0x300: val = CM_VMPU_300; break;
+               case 0x330: val = CM_VMPU_330; break;
+               default:
+                           iomidi = 0; break;
+               }
+               if (iomidi > 0) {
+                       snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val);
+                       /* enable UART */
+                       snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_UART_EN);
                }
        }
-       if (! iosynth) {
-               /* disable FM */
-               snd_cmipci_write(cm, CM_REG_LEGACY_CTRL, val & ~CM_FMSEL_MASK);
-               snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_FM_EN);
-       }
+
+       if ((err = snd_cmipci_create_fm(cm, fm_port[dev])) < 0)
+               return err;
 
        /* reset mixer */
        snd_cmipci_mixer_write(cm, 0, 0);
@@ -2730,35 +2961,31 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
        /* create pcm devices */
        pcm_index = pcm_spdif_index = 0;
        if ((err = snd_cmipci_pcm_new(cm, pcm_index)) < 0)
-               goto __error;
+               return err;
        pcm_index++;
        if (cm->has_dual_dac) {
                if ((err = snd_cmipci_pcm2_new(cm, pcm_index)) < 0)
-                       goto __error;
+                       return err;
                pcm_index++;
        }
        if (cm->can_ac3_hw || cm->can_ac3_sw) {
                pcm_spdif_index = pcm_index;
                if ((err = snd_cmipci_pcm_spdif_new(cm, pcm_index)) < 0)
-                       goto __error;
+                       return err;
        }
 
        /* create mixer interface & switches */
        if ((err = snd_cmipci_mixer_new(cm, pcm_spdif_index)) < 0)
-               goto __error;
+               return err;
 
        if (iomidi > 0) {
                if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
-                                              iomidi, 0,
+                                              iomidi, integrated_midi,
                                               cm->irq, 0, &cm->rmidi)) < 0) {
                        printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
                }
        }
 
-       if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, cm, &ops)) < 0) {
-               snd_cmipci_free(cm);
-               return err;
-       }
 #ifdef USE_VAR48KRATE
        for (val = 0; val < ARRAY_SIZE(rates); val++)
                snd_cmipci_set_pll(cm, rates[val], val);
@@ -2769,39 +2996,13 @@ static int __devinit snd_cmipci_create(snd_card_t *card, struct pci_dev *pci,
        snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPDIF48K|CM_SPDF_AC97);
 #endif /* USE_VAR48KRATE */
 
-#ifdef SUPPORT_JOYSTICK
-       if (joystick_port[dev] > 0) {
-               if (joystick_port[dev] == 1) { /* auto-detect */
-                       static int ports[] = { 0x201, 0x200, 0 }; /* FIXME: majority is 0x201? */
-                       int i;
-                       for (i = 0; ports[i]; i++) {
-                               joystick_port[dev] = ports[i];
-                               cm->res_joystick = request_region(ports[i], 8, "CMIPCI gameport");
-                               if (cm->res_joystick)
-                                       break;
-                       }
-               } else {
-                       cm->res_joystick = request_region(joystick_port[dev], 8, "CMIPCI gameport");
-               }
-       }
-       if (cm->res_joystick) {
-               cm->gameport.io = joystick_port[dev];
-               snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
-               gameport_register_port(&cm->gameport);
-       } else {
-               if (joystick_port[dev] > 0)
-                       printk(KERN_WARNING "cmipci: cannot reserve joystick ports\n");
+       if (snd_cmipci_create_gameport(cm, dev) < 0)
                snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_JYSTK_EN);
-       }
-#endif
+
        snd_card_set_dev(card, &pci->dev);
 
        *rcmipci = cm;
        return 0;
-
- __error:
-       snd_cmipci_free(cm);
-       return err;
 }
 
 /*
@@ -2813,8 +3014,8 @@ static int __devinit snd_cmipci_probe(struct pci_dev *pci,
                                      const struct pci_device_id *pci_id)
 {
        static int dev;
-       snd_card_t *card;
-       cmipci_t *cm;
+       struct snd_card *card;
+       struct cmipci *cm;
        int err;
 
        if (dev >= SNDRV_CARDS)
@@ -2846,6 +3047,7 @@ static int __devinit snd_cmipci_probe(struct pci_dev *pci,
                snd_card_free(card);
                return err;
        }
+       card->private_data = cm;
 
        sprintf(card->shortname, "C-Media PCI %s", card->driver);
        sprintf(card->longname, "%s (model %d) at 0x%lx, irq %i",
@@ -2873,16 +3075,98 @@ static void __devexit snd_cmipci_remove(struct pci_dev *pci)
 }
 
 
+#ifdef CONFIG_PM
+/*
+ * power management
+ */
+static unsigned char saved_regs[] = {
+       CM_REG_FUNCTRL1, CM_REG_CHFORMAT, CM_REG_LEGACY_CTRL, CM_REG_MISC_CTRL,
+       CM_REG_MIXER0, CM_REG_MIXER1, CM_REG_MIXER2, CM_REG_MIXER3, CM_REG_PLL,
+       CM_REG_CH0_FRAME1, CM_REG_CH0_FRAME2,
+       CM_REG_CH1_FRAME1, CM_REG_CH1_FRAME2, CM_REG_EXT_MISC,
+       CM_REG_INT_STATUS, CM_REG_INT_HLDCLR, CM_REG_FUNCTRL0,
+};
+
+static unsigned char saved_mixers[] = {
+       SB_DSP4_MASTER_DEV, SB_DSP4_MASTER_DEV + 1,
+       SB_DSP4_PCM_DEV, SB_DSP4_PCM_DEV + 1,
+       SB_DSP4_SYNTH_DEV, SB_DSP4_SYNTH_DEV + 1,
+       SB_DSP4_CD_DEV, SB_DSP4_CD_DEV + 1,
+       SB_DSP4_LINE_DEV, SB_DSP4_LINE_DEV + 1,
+       SB_DSP4_MIC_DEV, SB_DSP4_SPEAKER_DEV,
+       CM_REG_EXTENT_IND, SB_DSP4_OUTPUT_SW,
+       SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT,
+};
+
+static int snd_cmipci_suspend(struct pci_dev *pci, pm_message_t state)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct cmipci *cm = card->private_data;
+       int i;
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       
+       snd_pcm_suspend_all(cm->pcm);
+       snd_pcm_suspend_all(cm->pcm2);
+       snd_pcm_suspend_all(cm->pcm_spdif);
+
+       /* save registers */
+       for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+               cm->saved_regs[i] = snd_cmipci_read(cm, saved_regs[i]);
+       for (i = 0; i < ARRAY_SIZE(saved_mixers); i++)
+               cm->saved_mixers[i] = snd_cmipci_mixer_read(cm, saved_mixers[i]);
+
+       /* disable ints */
+       snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0);
+
+       pci_set_power_state(pci, PCI_D3hot);
+       pci_disable_device(pci);
+       pci_save_state(pci);
+       return 0;
+}
+
+static int snd_cmipci_resume(struct pci_dev *pci)
+{
+       struct snd_card *card = pci_get_drvdata(pci);
+       struct cmipci *cm = card->private_data;
+       int i;
+
+       pci_restore_state(pci);
+       pci_enable_device(pci);
+       pci_set_power_state(pci, PCI_D0);
+       pci_set_master(pci);
+
+       /* reset / initialize to a sane state */
+       snd_cmipci_write(cm, CM_REG_INT_HLDCLR, 0);
+       snd_cmipci_ch_reset(cm, CM_CH_PLAY);
+       snd_cmipci_ch_reset(cm, CM_CH_CAPT);
+       snd_cmipci_mixer_write(cm, 0, 0);
+
+       /* restore registers */
+       for (i = 0; i < ARRAY_SIZE(saved_regs); i++)
+               snd_cmipci_write(cm, saved_regs[i], cm->saved_regs[i]);
+       for (i = 0; i < ARRAY_SIZE(saved_mixers); i++)
+               snd_cmipci_mixer_write(cm, saved_mixers[i], cm->saved_mixers[i]);
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif /* CONFIG_PM */
+
 static struct pci_driver driver = {
        .name = "C-Media PCI",
        .id_table = snd_cmipci_ids,
        .probe = snd_cmipci_probe,
        .remove = __devexit_p(snd_cmipci_remove),
+#ifdef CONFIG_PM
+       .suspend = snd_cmipci_suspend,
+       .resume = snd_cmipci_resume,
+#endif
 };
        
 static int __init alsa_card_cmipci_init(void)
 {
-       return pci_module_init(&driver);
+       return pci_register_driver(&driver);
 }
 
 static void __exit alsa_card_cmipci_exit(void)