Merge tag 'sound-6.4-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai...
[linux-block.git] / sound / pci / emu10k1 / emupcm.c
index 6ec394fb1846845464b5e80158ce401ea4c03fcd..b0c0ef342756f825c161520b2a80019c9f58949f 100644 (file)
@@ -76,23 +76,6 @@ static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu,
        snd_pcm_period_elapsed(emu->pcm_capture_efx_substream);
 }       
 
-static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream *substream)
-{
-       struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_emu10k1_pcm *epcm = runtime->private_data;
-       unsigned int ptr;
-
-       if (!epcm->running)
-               return 0;
-       ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
-       ptr += runtime->buffer_size;
-       ptr -= epcm->ccca_start_addr;
-       ptr %= runtime->buffer_size;
-
-       return ptr;
-}
-
 static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voices)
 {
        int err, i;
@@ -343,7 +326,6 @@ static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
        } else
                snd_emu10k1_ptr_write(emu, FXRT, voice,
                                      snd_emu10k1_compose_send_routing(send_routing));
-       /* Stop CA */
        /* Assumption that PT is already 0 so no harm overwriting */
        snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]);
        snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24));
@@ -429,36 +411,6 @@ static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream,
 }
 
 static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream *substream)
-{
-       struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
-       struct snd_pcm_runtime *runtime = substream->runtime;
-       struct snd_emu10k1_pcm *epcm;
-
-       if (runtime->private_data == NULL)
-               return 0;
-       epcm = runtime->private_data;
-       if (epcm->extra) {
-               snd_emu10k1_voice_free(epcm->emu, epcm->extra);
-               epcm->extra = NULL;
-       }
-       if (epcm->voices[1]) {
-               snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
-               epcm->voices[1] = NULL;
-       }
-       if (epcm->voices[0]) {
-               snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]);
-               epcm->voices[0] = NULL;
-       }
-       if (epcm->memblk) {
-               snd_emu10k1_free_pages(emu, epcm->memblk);
-               epcm->memblk = NULL;
-               epcm->start_addr = 0;
-       }
-       snd_pcm_lib_free_pages(substream);
-       return 0;
-}
-
-static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream *substream)
 {
        struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
        struct snd_pcm_runtime *runtime = substream->runtime;
@@ -527,9 +479,6 @@ static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)
        start_addr = epcm->start_addr;
        end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
 
-       /*
-        * the kX driver leaves some space between voices
-        */
        channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK;
 
        snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
@@ -1091,8 +1040,6 @@ static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream)
        epcm->type = PLAYBACK_EFX;
        epcm->substream = substream;
        
-       emu->pcm_playback_efx_substream = substream;
-
        runtime->private_data = epcm;
        runtime->private_free = snd_emu10k1_pcm_free_substream;
        runtime->hw = snd_emu10k1_efx_playback;
@@ -1267,9 +1214,7 @@ static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
        runtime->hw.rate_min = runtime->hw.rate_max = 48000;
        spin_lock_irq(&emu->reg_lock);
        if (emu->card_capabilities->emu_model) {
-               /*  Nb. of channels has been increased to 16 */
                /* TODO
-                * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
                 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
                 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
                 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
@@ -1280,13 +1225,14 @@ static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
                 * Need to add mixer control to fix sample rate
                 *                 
                 * There are 32 mono channels of 16bits each.
-                * 24bit Audio uses 2x channels over 16bit
-                * 96kHz uses 2x channels over 48kHz
-                * 192kHz uses 4x channels over 48kHz
-                * So, for 48kHz 24bit, one has 16 channels
-                * for 96kHz 24bit, one has 8 channels
-                * for 192kHz 24bit, one has 4 channels
-                *
+                * 24bit Audio uses 2x channels over 16bit,
+                * 96kHz uses 2x channels over 48kHz,
+                * 192kHz uses 4x channels over 48kHz.
+                * So, for 48kHz 24bit, one has 16 channels,
+                * for 96kHz 24bit, one has 8 channels,
+                * for 192kHz 24bit, one has 4 channels.
+                * 1010rev2 and 1616(m) cards have double that,
+                * but we don't exceed 16 channels anyway.
                 */
 #if 1
                switch (emu->emu1010.internal_clock) {
@@ -1372,10 +1318,10 @@ static const struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
        .open =                 snd_emu10k1_efx_playback_open,
        .close =                snd_emu10k1_efx_playback_close,
        .hw_params =            snd_emu10k1_playback_hw_params,
-       .hw_free =              snd_emu10k1_efx_playback_hw_free,
+       .hw_free =              snd_emu10k1_playback_hw_free,
        .prepare =              snd_emu10k1_efx_playback_prepare,
        .trigger =              snd_emu10k1_efx_playback_trigger,
-       .pointer =              snd_emu10k1_efx_playback_pointer,
+       .pointer =              snd_emu10k1_playback_pointer,
 };
 
 int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device)
@@ -1508,11 +1454,12 @@ static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol *kcontrol, st
                        nval[idx / 32] |= 1 << (idx % 32);
                        bits++;
                }
-               
+
+       // Check that the number of requested channels is a power of two
+       // not bigger than the number of available channels.
        for (idx = 0; idx < nefxb; idx++)
                if (1 << idx == bits)
                        break;
-       
        if (idx >= nefxb)
                return -EINVAL;
 
@@ -1802,7 +1749,6 @@ int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device)
         * to these
         */     
        
-       /* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
        if (emu->audigy) {
                emu->efx_voices_mask[0] = 0;
                if (emu->card_capabilities->emu_model)