ALSA: hda_intel: fix handling of non-completion stream interrupts
[safe/jmp/linux-2.6] / sound / pci / oxygen / oxygen_pcm.c
index 09a16e4..9dff695 100644 (file)
@@ -129,7 +129,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
 
        runtime->private_data = (void *)(uintptr_t)channel;
        if (channel == PCM_B && chip->has_ac97_1 &&
-           (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1))
+           (chip->model.device_config & CAPTURE_2_FROM_AC97_1))
                runtime->hw = oxygen_ac97_hardware;
        else
                runtime->hw = *oxygen_hardware[channel];
@@ -140,11 +140,11 @@ static int oxygen_open(struct snd_pcm_substream *substream,
                runtime->hw.rate_min = 44100;
                break;
        case PCM_MULTICH:
-               runtime->hw.channels_max = chip->model->dac_channels;
+               runtime->hw.channels_max = chip->model.dac_channels;
                break;
        }
-       if (chip->model->pcm_hardware_filter)
-               chip->model->pcm_hardware_filter(channel, &runtime->hw);
+       if (chip->model.pcm_hardware_filter)
+               chip->model.pcm_hardware_filter(channel, &runtime->hw);
        err = snd_pcm_hw_constraint_step(runtime, 0,
                                         SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
        if (err < 0)
@@ -165,6 +165,12 @@ static int oxygen_open(struct snd_pcm_substream *substream,
                if (err < 0)
                        return err;
        }
+       if (channel == PCM_MULTICH) {
+               err = snd_pcm_hw_constraint_minmax
+                       (runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 0, 8192000);
+               if (err < 0)
+                       return err;
+       }
        snd_pcm_set_sync(substream);
        chip->streams[channel] = substream;
 
@@ -265,13 +271,16 @@ static unsigned int oxygen_rate(struct snd_pcm_hw_params *hw_params)
        }
 }
 
-static unsigned int oxygen_i2s_mclk(struct snd_pcm_hw_params *hw_params)
+unsigned int oxygen_default_i2s_mclk(struct oxygen *chip,
+                                    unsigned int channel,
+                                    struct snd_pcm_hw_params *hw_params)
 {
        if (params_rate(hw_params) <= 96000)
                return OXYGEN_I2S_MCLK_256;
        else
                return OXYGEN_I2S_MCLK_128;
 }
+EXPORT_SYMBOL(oxygen_default_i2s_mclk);
 
 static unsigned int oxygen_i2s_bits(struct snd_pcm_hw_params *hw_params)
 {
@@ -348,8 +357,8 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
                             OXYGEN_REC_FORMAT_A_MASK);
        oxygen_write16_masked(chip, OXYGEN_I2S_A_FORMAT,
                              oxygen_rate(hw_params) |
-                             oxygen_i2s_mclk(hw_params) |
-                             chip->model->adc_i2s_format |
+                             chip->model.get_i2s_mclk(chip, PCM_A, hw_params) |
+                             chip->model.adc_i2s_format |
                              oxygen_i2s_bits(hw_params),
                              OXYGEN_I2S_RATE_MASK |
                              OXYGEN_I2S_FORMAT_MASK |
@@ -358,7 +367,7 @@ static int oxygen_rec_a_hw_params(struct snd_pcm_substream *substream,
        spin_unlock_irq(&chip->reg_lock);
 
        mutex_lock(&chip->mutex);
-       chip->model->set_adc_params(chip, hw_params);
+       chip->model.set_adc_params(chip, hw_params);
        mutex_unlock(&chip->mutex);
        return 0;
 }
@@ -375,7 +384,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
                return err;
 
        is_ac97 = chip->has_ac97_1 &&
-               (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
+               (chip->model.device_config & CAPTURE_2_FROM_AC97_1);
 
        spin_lock_irq(&chip->reg_lock);
        oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
@@ -384,8 +393,9 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
        if (!is_ac97)
                oxygen_write16_masked(chip, OXYGEN_I2S_B_FORMAT,
                                      oxygen_rate(hw_params) |
-                                     oxygen_i2s_mclk(hw_params) |
-                                     chip->model->adc_i2s_format |
+                                     chip->model.get_i2s_mclk(chip, PCM_B,
+                                                              hw_params) |
+                                     chip->model.adc_i2s_format |
                                      oxygen_i2s_bits(hw_params),
                                      OXYGEN_I2S_RATE_MASK |
                                      OXYGEN_I2S_FORMAT_MASK |
@@ -395,7 +405,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
 
        if (!is_ac97) {
                mutex_lock(&chip->mutex);
-               chip->model->set_adc_params(chip, hw_params);
+               chip->model.set_adc_params(chip, hw_params);
                mutex_unlock(&chip->mutex);
        }
        return 0;
@@ -429,6 +439,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
        if (err < 0)
                return err;
 
+       mutex_lock(&chip->mutex);
        spin_lock_irq(&chip->reg_lock);
        oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
                            OXYGEN_SPDIF_OUT_ENABLE);
@@ -440,6 +451,7 @@ static int oxygen_spdif_hw_params(struct snd_pcm_substream *substream,
                              OXYGEN_SPDIF_OUT_RATE_MASK);
        oxygen_update_spdif_source(chip);
        spin_unlock_irq(&chip->reg_lock);
+       mutex_unlock(&chip->mutex);
        return 0;
 }
 
@@ -453,6 +465,7 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
        if (err < 0)
                return err;
 
+       mutex_lock(&chip->mutex);
        spin_lock_irq(&chip->reg_lock);
        oxygen_write8_masked(chip, OXYGEN_PLAY_CHANNELS,
                             oxygen_play_channels(hw_params),
@@ -462,17 +475,19 @@ static int oxygen_multich_hw_params(struct snd_pcm_substream *substream,
                             OXYGEN_MULTICH_FORMAT_MASK);
        oxygen_write16_masked(chip, OXYGEN_I2S_MULTICH_FORMAT,
                              oxygen_rate(hw_params) |
-                             chip->model->dac_i2s_format |
+                             chip->model.dac_i2s_format |
+                             chip->model.get_i2s_mclk(chip, PCM_MULTICH,
+                                                      hw_params) |
                              oxygen_i2s_bits(hw_params),
                              OXYGEN_I2S_RATE_MASK |
                              OXYGEN_I2S_FORMAT_MASK |
+                             OXYGEN_I2S_MCLK_MASK |
                              OXYGEN_I2S_BITS_MASK);
-       oxygen_update_dac_routing(chip);
        oxygen_update_spdif_source(chip);
        spin_unlock_irq(&chip->reg_lock);
 
-       mutex_lock(&chip->mutex);
-       chip->model->set_dac_params(chip, hw_params);
+       chip->model.set_dac_params(chip, hw_params);
+       oxygen_update_dac_routing(chip);
        mutex_unlock(&chip->mutex);
        return 0;
 }
@@ -481,10 +496,14 @@ static int oxygen_hw_free(struct snd_pcm_substream *substream)
 {
        struct oxygen *chip = snd_pcm_substream_chip(substream);
        unsigned int channel = oxygen_substream_channel(substream);
+       unsigned int channel_mask = 1 << channel;
 
        spin_lock_irq(&chip->reg_lock);
-       chip->interrupt_mask &= ~(1 << channel);
+       chip->interrupt_mask &= ~channel_mask;
        oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
+
+       oxygen_set_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
+       oxygen_clear_bits8(chip, OXYGEN_DMA_FLUSH, channel_mask);
        spin_unlock_irq(&chip->reg_lock);
 
        return snd_pcm_lib_free_pages(substream);
@@ -651,25 +670,26 @@ int oxygen_pcm_init(struct oxygen *chip)
        int outs, ins;
        int err;
 
-       outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S);
-       ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 |
-                                            CAPTURE_0_FROM_I2S_2));
+       outs = !!(chip->model.device_config & PLAYBACK_0_TO_I2S);
+       ins = !!(chip->model.device_config & (CAPTURE_0_FROM_I2S_1 |
+                                             CAPTURE_0_FROM_I2S_2));
        if (outs | ins) {
-               err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm);
+               err = snd_pcm_new(chip->card, "Multichannel",
+                                 0, outs, ins, &pcm);
                if (err < 0)
                        return err;
                if (outs)
                        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
                                        &oxygen_multich_ops);
-               if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
+               if (chip->model.device_config & CAPTURE_0_FROM_I2S_1)
                        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
                                        &oxygen_rec_a_ops);
-               else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2)
+               else if (chip->model.device_config & CAPTURE_0_FROM_I2S_2)
                        snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
                                        &oxygen_rec_b_ops);
                pcm->private_data = chip;
                pcm->private_free = oxygen_pcm_free;
-               strcpy(pcm->name, "Analog");
+               strcpy(pcm->name, "Multichannel");
                if (outs)
                        snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
                                                      SNDRV_DMA_TYPE_DEV,
@@ -684,8 +704,8 @@ int oxygen_pcm_init(struct oxygen *chip)
                                                      BUFFER_BYTES_MAX);
        }
 
-       outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF);
-       ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF);
+       outs = !!(chip->model.device_config & PLAYBACK_1_TO_SPDIF);
+       ins = !!(chip->model.device_config & CAPTURE_1_FROM_SPDIF);
        if (outs | ins) {
                err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
                if (err < 0)
@@ -706,11 +726,11 @@ int oxygen_pcm_init(struct oxygen *chip)
        }
 
        if (chip->has_ac97_1) {
-               outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1);
-               ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
+               outs = !!(chip->model.device_config & PLAYBACK_2_TO_AC97_1);
+               ins = !!(chip->model.device_config & CAPTURE_2_FROM_AC97_1);
        } else {
                outs = 0;
-               ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2);
+               ins = !!(chip->model.device_config & CAPTURE_2_FROM_I2S_2);
        }
        if (outs | ins) {
                err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",