Merge branch 'linus' into cont_syslog
[safe/jmp/linux-2.6] / sound / pci / cmipci.c
index 7cf4fc1..329968e 100644 (file)
@@ -20,7 +20,6 @@
 /* Does not work. Warning may block system in capture mode */
 /* #define USE_VAR48KRATE */
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -150,6 +149,8 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address.");
 #define CM_CH0_SRATE_176K      0x00000200
 #define CM_CH0_SRATE_96K       0x00000200      /* model 055? */
 #define CM_CH0_SRATE_88K       0x00000100
+#define CM_CH0_SRATE_128K      0x00000300
+#define CM_CH0_SRATE_MASK      0x00000300
 
 #define CM_SPDIF_INVERSE2      0x00000080      /* model 055? */
 #define CM_DBLSPDS             0x00000040      /* double SPDIF sample rate 88.2/96 */
@@ -246,10 +247,9 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address.");
 #define CM_MMODE_MASK          0x00000E00      /* model DAA interface mode */
 #define CM_SPDIF_SELECT2       0x00000100      /* for model > 039 ? */
 #define CM_ENCENTER            0x00000080
-#define CM_FLINKON             0x00000080      /* force modem link detection on, model 037 */
+#define CM_FLINKON             0x00000040      /* force modem link detection on, model 037 */
 #define CM_MUTECH1             0x00000040      /* mute PCI ch1 to DAC */
-#define CM_FLINKOFF            0x00000040      /* force modem link detection off, model 037 */
-#define CM_UNKNOWN_18_5                0x00000020      /* ? */
+#define CM_FLINKOFF            0x00000020      /* force modem link detection off, model 037 */
 #define CM_MIDSMP              0x00000010      /* 1/2 interpolation at front end DAC */
 #define CM_UPDDMA_MASK         0x0000000C      /* TDMA position update notification */
 #define CM_UPDDMA_2048         0x00000000
@@ -431,15 +431,14 @@ MODULE_PARM_DESC(joystick_port, "Joystick port address.");
 
 struct cmipci_pcm {
        struct snd_pcm_substream *substream;
-       int running;            /* dac/adc running? */
+       u8 running;             /* dac/adc running? */
+       u8 fmt;                 /* format bits */
+       u8 is_dac;
+       u8 needs_silencing;
        unsigned int dma_size;  /* in frames */
-       unsigned int period_size;       /* in frames */
+       unsigned int shift;
+       unsigned int ch;        /* channel (0/1) */
        unsigned int offset;    /* physical address of the buffer */
-       unsigned int fmt;       /* format bits */
-       int ch;                 /* channel (0/1) */
-       unsigned int is_dac;            /* is dac? */
-       int bytes_per_frame;
-       int shift;
 };
 
 /* mixer elements toggled/resumed during ac3 playback */
@@ -475,6 +474,7 @@ struct cmipci {
        unsigned int can_ac3_sw: 1;
        unsigned int can_ac3_hw: 1;
        unsigned int can_multi_ch: 1;
+       unsigned int can_96k: 1;        /* samplerate above 48k */
        unsigned int do_soft_ac3: 1;
 
        unsigned int spdif_playback_avail: 1;   /* spdif ready? */
@@ -605,8 +605,6 @@ static unsigned int snd_cmipci_rate_freq(unsigned int rate)
 {
        unsigned int i;
 
-       if (rate > 48000)
-               rate /= 2;
        for (i = 0; i < ARRAY_SIZE(rates); i++) {
                if (rates[i] == rate)
                        return i;
@@ -784,7 +782,8 @@ static int set_dac_channels(struct cmipci *cm, struct cmipci_pcm *rec, int chann
 static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
                                 struct snd_pcm_substream *substream)
 {
-       unsigned int reg, freq, val;
+       unsigned int reg, freq, freq_ext, val;
+       unsigned int period_size;
        struct snd_pcm_runtime *runtime = substream->runtime;
 
        rec->fmt = 0;
@@ -804,11 +803,11 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
        rec->offset = runtime->dma_addr;
        /* buffer and period sizes in frame */
        rec->dma_size = runtime->buffer_size << rec->shift;
-       rec->period_size = runtime->period_size << rec->shift;
+       period_size = runtime->period_size << rec->shift;
        if (runtime->channels > 2) {
                /* multi-channels */
                rec->dma_size = (rec->dma_size * runtime->channels) / 2;
-               rec->period_size = (rec->period_size * runtime->channels) / 2;
+               period_size = (period_size * runtime->channels) / 2;
        }
 
        spin_lock_irq(&cm->reg_lock);
@@ -819,7 +818,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
        /* program sample counts */
        reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
        snd_cmipci_write_w(cm, reg, rec->dma_size - 1);
-       snd_cmipci_write_w(cm, reg + 2, rec->period_size - 1);
+       snd_cmipci_write_w(cm, reg + 2, period_size - 1);
 
        /* set adc/dac flag */
        val = rec->ch ? CM_CHADC1 : CM_CHADC0;
@@ -831,7 +830,17 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
        //snd_printd("cmipci: functrl0 = %08x\n", cm->ctrl);
 
        /* set sample rate */
-       freq = snd_cmipci_rate_freq(runtime->rate);
+       freq = 0;
+       freq_ext = 0;
+       if (runtime->rate > 48000)
+               switch (runtime->rate) {
+               case 88200:  freq_ext = CM_CH0_SRATE_88K; break;
+               case 96000:  freq_ext = CM_CH0_SRATE_96K; break;
+               case 128000: freq_ext = CM_CH0_SRATE_128K; break;
+               default:     snd_BUG(); break;
+               }
+       else
+               freq = snd_cmipci_rate_freq(runtime->rate);
        val = snd_cmipci_read(cm, CM_REG_FUNCTRL1);
        if (rec->ch) {
                val &= ~CM_DSFC_MASK;
@@ -852,19 +861,20 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
                val &= ~CM_CH0FMT_MASK;
                val |= rec->fmt << CM_CH0FMT_SHIFT;
        }
-       if (cm->chip_version == 68) {
-               if (runtime->rate == 88200)
-                       val |= CM_CH0_SRATE_88K << (rec->ch * 2);
-               else
-                       val &= ~(CM_CH0_SRATE_88K << (rec->ch * 2));
-               if (runtime->rate == 96000)
-                       val |= CM_CH0_SRATE_96K << (rec->ch * 2);
-               else
-                       val &= ~(CM_CH0_SRATE_96K << (rec->ch * 2));
+       if (cm->can_96k) {
+               val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2));
+               val |= freq_ext << (rec->ch * 2);
        }
        snd_cmipci_write(cm, CM_REG_CHFORMAT, val);
        //snd_printd("cmipci: chformat = %08x\n", val);
 
+       if (!rec->is_dac && cm->chip_version) {
+               if (runtime->rate > 44100)
+                       snd_cmipci_set_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K);
+               else
+                       snd_cmipci_clear_bit(cm, CM_REG_EXT_MISC, CM_ADC48K44K);
+       }
+
        rec->running = 0;
        spin_unlock_irq(&cm->reg_lock);
 
@@ -875,7 +885,7 @@ static int snd_cmipci_pcm_prepare(struct cmipci *cm, struct cmipci_pcm *rec,
  * PCM trigger/stop
  */
 static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec,
-                                 struct snd_pcm_substream *substream, int cmd)
+                                 int cmd)
 {
        unsigned int inthld, chen, reset, pause;
        int result = 0;
@@ -904,6 +914,7 @@ static int snd_cmipci_pcm_trigger(struct cmipci *cm, struct cmipci_pcm *rec,
                cm->ctrl &= ~chen;
                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | reset);
                snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~reset);
+               rec->needs_silencing = rec->is_dac;
                break;
        case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
        case SNDRV_PCM_TRIGGER_SUSPEND:
@@ -930,13 +941,21 @@ static snd_pcm_uframes_t snd_cmipci_pcm_pointer(struct cmipci *cm, struct cmipci
                                                struct snd_pcm_substream *substream)
 {
        size_t ptr;
-       unsigned int reg;
+       unsigned int reg, rem, tries;
+
        if (!rec->running)
                return 0;
 #if 1 // this seems better..
        reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
-       ptr = rec->dma_size - (snd_cmipci_read_w(cm, reg) + 1);
-       ptr >>= rec->shift;
+       for (tries = 0; tries < 3; tries++) {
+               rem = snd_cmipci_read_w(cm, reg);
+               if (rem < rec->dma_size)
+                       goto ok;
+       } 
+       printk(KERN_ERR "cmipci: invalid PCM pointer: %#x\n", rem);
+       return SNDRV_PCM_POS_XRUN;
+ok:
+       ptr = (rec->dma_size - (rem + 1)) >> rec->shift;
 #else
        reg = rec->ch ? CM_REG_CH1_FRAME1 : CM_REG_CH0_FRAME1;
        ptr = snd_cmipci_read(cm, reg) - rec->offset;
@@ -955,7 +974,7 @@ static int snd_cmipci_playback_trigger(struct snd_pcm_substream *substream,
                                       int cmd)
 {
        struct cmipci *cm = snd_pcm_substream_chip(substream);
-       return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_PLAY], substream, cmd);
+       return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_PLAY], cmd);
 }
 
 static snd_pcm_uframes_t snd_cmipci_playback_pointer(struct snd_pcm_substream *substream)
@@ -974,7 +993,7 @@ static int snd_cmipci_capture_trigger(struct snd_pcm_substream *substream,
                                     int cmd)
 {
        struct cmipci *cm = snd_pcm_substream_chip(substream);
-       return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_CAPT], substream, cmd);
+       return snd_cmipci_pcm_trigger(cm, &cm->channel[CM_CH_CAPT], cmd);
 }
 
 static snd_pcm_uframes_t snd_cmipci_capture_pointer(struct snd_pcm_substream *substream)
@@ -1280,7 +1299,7 @@ static int snd_cmipci_playback_prepare(struct snd_pcm_substream *substream)
        int rate = substream->runtime->rate;
        int err, do_spdif, do_ac3 = 0;
 
-       do_spdif = (rate >= 44100 &&
+       do_spdif = (rate >= 44100 && rate <= 96000 &&
                    substream->runtime->format == SNDRV_PCM_FORMAT_S16_LE &&
                    substream->runtime->channels == 2);
        if (do_spdif && cm->can_ac3_hw) 
@@ -1305,11 +1324,73 @@ static int snd_cmipci_playback_spdif_prepare(struct snd_pcm_substream *substream
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_PLAY], substream);
 }
 
+/*
+ * Apparently, the samples last played on channel A stay in some buffer, even
+ * after the channel is reset, and get added to the data for the rear DACs when
+ * playing a multichannel stream on channel B.  This is likely to generate
+ * wraparounds and thus distortions.
+ * To avoid this, we play at least one zero sample after the actual stream has
+ * stopped.
+ */
+static void snd_cmipci_silence_hack(struct cmipci *cm, struct cmipci_pcm *rec)
+{
+       struct snd_pcm_runtime *runtime = rec->substream->runtime;
+       unsigned int reg, val;
+
+       if (rec->needs_silencing && runtime && runtime->dma_area) {
+               /* set up a small silence buffer */
+               memset(runtime->dma_area, 0, PAGE_SIZE);
+               reg = rec->ch ? CM_REG_CH1_FRAME2 : CM_REG_CH0_FRAME2;
+               val = ((PAGE_SIZE / 4) - 1) | (((PAGE_SIZE / 4) / 2 - 1) << 16);
+               snd_cmipci_write(cm, reg, val);
+       
+               /* configure for 16 bits, 2 channels, 8 kHz */
+               if (runtime->channels > 2)
+                       set_dac_channels(cm, rec, 2);
+               spin_lock_irq(&cm->reg_lock);
+               val = snd_cmipci_read(cm, CM_REG_FUNCTRL1);
+               val &= ~(CM_ASFC_MASK << (rec->ch * 3));
+               val |= (4 << CM_ASFC_SHIFT) << (rec->ch * 3);
+               snd_cmipci_write(cm, CM_REG_FUNCTRL1, val);
+               val = snd_cmipci_read(cm, CM_REG_CHFORMAT);
+               val &= ~(CM_CH0FMT_MASK << (rec->ch * 2));
+               val |= (3 << CM_CH0FMT_SHIFT) << (rec->ch * 2);
+               if (cm->can_96k)
+                       val &= ~(CM_CH0_SRATE_MASK << (rec->ch * 2));
+               snd_cmipci_write(cm, CM_REG_CHFORMAT, val);
+       
+               /* start stream (we don't need interrupts) */
+               cm->ctrl |= CM_CHEN0 << rec->ch;
+               snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl);
+               spin_unlock_irq(&cm->reg_lock);
+
+               msleep(1);
+
+               /* stop and reset stream */
+               spin_lock_irq(&cm->reg_lock);
+               cm->ctrl &= ~(CM_CHEN0 << rec->ch);
+               val = CM_RST_CH0 << rec->ch;
+               snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl | val);
+               snd_cmipci_write(cm, CM_REG_FUNCTRL0, cm->ctrl & ~val);
+               spin_unlock_irq(&cm->reg_lock);
+
+               rec->needs_silencing = 0;
+       }
+}
+
 static int snd_cmipci_playback_hw_free(struct snd_pcm_substream *substream)
 {
        struct cmipci *cm = snd_pcm_substream_chip(substream);
        setup_spdif_playback(cm, substream, 0, 0);
        restore_mixer_state(cm);
+       snd_cmipci_silence_hack(cm, &cm->channel[0]);
+       return snd_cmipci_hw_free(substream);
+}
+
+static int snd_cmipci_playback2_hw_free(struct snd_pcm_substream *substream)
+{
+       struct cmipci *cm = snd_pcm_substream_chip(substream);
+       snd_cmipci_silence_hack(cm, &cm->channel[1]);
        return snd_cmipci_hw_free(substream);
 }
 
@@ -1327,6 +1408,17 @@ static int snd_cmipci_capture_spdif_prepare(struct snd_pcm_substream *substream)
 
        spin_lock_irq(&cm->reg_lock);
        snd_cmipci_set_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF);
+       if (cm->can_96k) {
+               if (substream->runtime->rate > 48000)
+                       snd_cmipci_set_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS);
+               else
+                       snd_cmipci_clear_bit(cm, CM_REG_CHFORMAT, CM_DBLSPDS);
+       }
+       if (snd_pcm_format_width(substream->runtime->format) > 16)
+               snd_cmipci_set_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL);
+       else
+               snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL);
+
        spin_unlock_irq(&cm->reg_lock);
 
        return snd_cmipci_pcm_prepare(cm, &cm->channel[CM_CH_CAPT], substream);
@@ -1338,6 +1430,7 @@ static int snd_cmipci_capture_spdif_hw_free(struct snd_pcm_substream *subs)
 
        spin_lock_irq(&cm->reg_lock);
        snd_cmipci_clear_bit(cm, CM_REG_FUNCTRL1, CM_CAPTURE_SPDF);
+       snd_cmipci_clear_bit(cm, CM_REG_MISC_CTRL, CM_SPD32SEL);
        spin_unlock_irq(&cm->reg_lock);
 
        return snd_cmipci_hw_free(subs);
@@ -1489,7 +1582,8 @@ 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_RESUME | SNDRV_PCM_INFO_MMAP_VALID),
-       .formats =              SNDRV_PCM_FMTBIT_S16_LE,
+       .formats =              SNDRV_PCM_FMTBIT_S16_LE |
+                               SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE,
        .rates =                SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000,
        .rate_min =             44100,
        .rate_max =             48000,
@@ -1503,6 +1597,14 @@ static struct snd_pcm_hardware snd_cmipci_capture_spdif =
        .fifo_size =            0,
 };
 
+static unsigned int rate_constraints[] = { 5512, 8000, 11025, 16000, 22050,
+                       32000, 44100, 48000, 88200, 96000, 128000 };
+static struct snd_pcm_hw_constraint_list hw_constraints_rates = {
+               .count = ARRAY_SIZE(rate_constraints),
+               .list = rate_constraints,
+               .mask = 0,
+};
+
 /*
  * check device open/close
  */
@@ -1572,6 +1674,13 @@ static int snd_cmipci_playback_open(struct snd_pcm_substream *substream)
                runtime->hw.rates |= SNDRV_PCM_RATE_88200 |
                                     SNDRV_PCM_RATE_96000;
                runtime->hw.rate_max = 96000;
+       } else if (cm->chip_version == 55) {
+               err = snd_pcm_hw_constraint_list(runtime, 0,
+                       SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+               if (err < 0)
+                       return err;
+               runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
+               runtime->hw.rate_max = 128000;
        }
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        cm->dig_pcm_status = cm->dig_status;
@@ -1590,6 +1699,13 @@ static int snd_cmipci_capture_open(struct snd_pcm_substream *substream)
        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;
+       } else if (cm->chip_version == 55) {
+               err = snd_pcm_hw_constraint_list(runtime, 0,
+                       SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+               if (err < 0)
+                       return err;
+               runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
+               runtime->hw.rate_max = 128000;
        }
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        return 0;
@@ -1621,6 +1737,13 @@ static int snd_cmipci_playback2_open(struct snd_pcm_substream *substream)
                runtime->hw.rates |= SNDRV_PCM_RATE_88200 |
                                     SNDRV_PCM_RATE_96000;
                runtime->hw.rate_max = 96000;
+       } else if (cm->chip_version == 55) {
+               err = snd_pcm_hw_constraint_list(runtime, 0,
+                       SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_rates);
+               if (err < 0)
+                       return err;
+               runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
+               runtime->hw.rate_max = 128000;
        }
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x10000);
        return 0;
@@ -1640,7 +1763,7 @@ static int snd_cmipci_playback_spdif_open(struct snd_pcm_substream *substream)
                        runtime->hw.formats |= SNDRV_PCM_FMTBIT_S32_LE;
                        snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
                }
-               if (cm->chip_version == 68) {
+               if (cm->can_96k) {
                        runtime->hw.rates |= SNDRV_PCM_RATE_88200 |
                                             SNDRV_PCM_RATE_96000;
                        runtime->hw.rate_max = 96000;
@@ -1662,6 +1785,11 @@ static int snd_cmipci_capture_spdif_open(struct snd_pcm_substream *substream)
        if ((err = open_device_check(cm, CM_OPEN_SPDIF_CAPTURE, substream)) < 0) /* use channel B */
                return err;
        runtime->hw = snd_cmipci_capture_spdif;
+       if (cm->can_96k && !(cm->chip_version == 68)) {
+               runtime->hw.rates |= SNDRV_PCM_RATE_88200 |
+                                    SNDRV_PCM_RATE_96000;
+               runtime->hw.rate_max = 96000;
+       }
        snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 0, 0x40000);
        return 0;
 }
@@ -1737,7 +1865,7 @@ static struct snd_pcm_ops snd_cmipci_playback2_ops = {
        .close =        snd_cmipci_playback2_close,
        .ioctl =        snd_pcm_lib_ioctl,
        .hw_params =    snd_cmipci_playback2_hw_params,
-       .hw_free =      snd_cmipci_hw_free,
+       .hw_free =      snd_cmipci_playback2_hw_free,
        .prepare =      snd_cmipci_capture_prepare,     /* channel B */
        .trigger =      snd_cmipci_capture_trigger,     /* channel B */
        .pointer =      snd_cmipci_capture_pointer,     /* channel B */
@@ -2182,7 +2310,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
        CMIPCI_SB_VOL_MONO("Mic Playback Volume", SB_DSP4_MIC_DEV, 3, 31),
        CMIPCI_SB_SW_MONO("Mic Playback Switch", 0),
        CMIPCI_DOUBLE("Mic Capture Switch", SB_DSP4_INPUT_LEFT, SB_DSP4_INPUT_RIGHT, 0, 0, 1, 0, 0),
-       CMIPCI_SB_VOL_MONO("PC Speaker Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
+       CMIPCI_SB_VOL_MONO("Beep Playback Volume", SB_DSP4_SPEAKER_DEV, 6, 3),
        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),
@@ -2190,7 +2318,7 @@ static struct snd_kcontrol_new snd_cmipci_mixers[] __devinitdata = {
        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 Playback Switch", CM_REG_EXTENT_IND, CM_REG_EXTENT_IND, 3, 3, 1, 0, 0),
+       CMIPCI_DOUBLE("Beep Playback 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),
 };
 
@@ -2237,7 +2365,8 @@ static int snd_cmipci_uswitch_get(struct snd_kcontrol *kcontrol,
 {
        struct cmipci_switch_args *args;
        args = (struct cmipci_switch_args *)kcontrol->private_value;
-       snd_assert(args != NULL, return -EINVAL);
+       if (snd_BUG_ON(!args))
+               return -EINVAL;
        return _snd_cmipci_uswitch_get(kcontrol, ucontrol, args);
 }
 
@@ -2281,7 +2410,8 @@ static int snd_cmipci_uswitch_put(struct snd_kcontrol *kcontrol,
 {
        struct cmipci_switch_args *args;
        args = (struct cmipci_switch_args *)kcontrol->private_value;
-       snd_assert(args != NULL, return -EINVAL);
+       if (snd_BUG_ON(!args))
+               return -EINVAL;
        return _snd_cmipci_uswitch_put(kcontrol, ucontrol, args);
 }
 
@@ -2530,10 +2660,8 @@ static struct snd_kcontrol_new snd_cmipci_extra_mixer_switches[] __devinitdata =
 };
 
 /* card control switches */
-static struct snd_kcontrol_new snd_cmipci_control_switches[] __devinitdata = {
-       // DEFINE_CARD_SWITCH("Joystick", joystick), /* now module option */
-       DEFINE_CARD_SWITCH("Modem", modem),
-};
+static struct snd_kcontrol_new snd_cmipci_modem_switch __devinitdata =
+DEFINE_CARD_SWITCH("Modem", modem);
 
 
 static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_device)
@@ -2544,7 +2672,8 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
        unsigned int idx;
        int err;
 
-       snd_assert(cm != NULL && cm->card != NULL, return -EINVAL);
+       if (snd_BUG_ON(!cm || !cm->card))
+               return -EINVAL;
 
        card = cm->card;
 
@@ -2614,20 +2743,25 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
        }
 
        /* card switches */
-       sw = snd_cmipci_control_switches;
-       for (idx = 0; idx < ARRAY_SIZE(snd_cmipci_control_switches); idx++, sw++) {
-               err = snd_ctl_add(cm->card, snd_ctl_new1(sw, cm));
+       /*
+        * newer chips don't have the register bits to force modem link
+        * detection; the bit that was FLINKON now mutes CH1
+        */
+       if (cm->chip_version < 39) {
+               err = snd_ctl_add(cm->card,
+                                 snd_ctl_new1(&snd_cmipci_modem_switch, cm));
                if (err < 0)
                        return err;
        }
 
        for (idx = 0; idx < CM_SAVED_MIXERS; idx++) {
-               struct snd_ctl_elem_id id;
+               struct snd_ctl_elem_id elem_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);
-               if ((ctl = snd_ctl_find_id(cm->card, &id)) != NULL)
+               memset(&elem_id, 0, sizeof(elem_id));
+               elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
+               strcpy(elem_id.name, cm_saved_mixer[idx].name);
+               ctl = snd_ctl_find_id(cm->card, &elem_id);
+               if (ctl)
                        cm->mixer_res_ctl[idx] = ctl;
        }
 
@@ -2670,12 +2804,12 @@ static inline void snd_cmipci_proc_init(struct cmipci *cm) {}
 #endif
 
 
-static struct pci_device_id snd_cmipci_ids[] = {
-       {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {PCI_VENDOR_ID_CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {PCI_VENDOR_ID_AL, PCI_DEVICE_ID_CMEDIA_CM8738, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+static DEFINE_PCI_DEVICE_TABLE(snd_cmipci_ids) = {
+       {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338A), 0},
+       {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8338B), 0},
+       {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
+       {PCI_VDEVICE(CMEDIA, PCI_DEVICE_ID_CMEDIA_CM8738B), 0},
+       {PCI_VDEVICE(AL, PCI_DEVICE_ID_CMEDIA_CM8738), 0},
        {0,},
 };
 
@@ -2721,9 +2855,11 @@ static void __devinit query_chip(struct cmipci *cm)
                } else if (detect & CM_CHIP_8768) {
                        cm->chip_version = 68;
                        cm->max_channels = 8;
+                       cm->can_96k = 1;
                } else {
                        cm->chip_version = 55;
                        cm->max_channels = 6;
+                       cm->can_96k = 1;
                }
                cm->can_ac3_hw = 1;
                cm->can_multi_ch = 1;
@@ -2808,8 +2944,6 @@ static int snd_cmipci_free(struct cmipci *cm)
                /* reset mixer */
                snd_cmipci_mixer_write(cm, 0, 0);
 
-               synchronize_irq(cm->irq);
-
                free_irq(cm->irq, cm);
        }
 
@@ -2888,11 +3022,11 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
                .dev_free =     snd_cmipci_dev_free,
        };
        unsigned int val;
-       long iomidi;
+       long iomidi = 0;
        int integrated_midi = 0;
        char modelstr[16];
        int pcm_index, pcm_spdif_index;
-       static struct pci_device_id intel_82437vx[] = {
+       static DEFINE_PCI_DEVICE_TABLE(intel_82437vx) = {
                { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX) },
                { },
        };
@@ -3146,9 +3280,9 @@ static int __devinit snd_cmipci_probe(struct pci_dev *pci,
                return -ENOENT;
        }
 
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
-       if (card == NULL)
-               return -ENOMEM;
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
+       if (err < 0)
+               return err;
        
        switch (pci->device) {
        case PCI_DEVICE_ID_CMEDIA_CM8738: