Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  *                   Creative Labs, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  *  Routines for control of EMU10K1 chips / PCM routines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6)  *  Multichannel PCM support Copyright (c) Lee Revell <rlrevell@joe-job.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8)  *  BUGS:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9)  *    --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11)  *  TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12)  *    --
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/time.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <sound/emu10k1.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) static void snd_emu10k1_pcm_interrupt(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) 				      struct snd_emu10k1_voice *voice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) 	if ((epcm = voice->epcm) == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) 	if (epcm->substream == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) 	dev_dbg(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) 		"IRQ: position = 0x%x, period = 0x%x, size = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) 			epcm->substream->runtime->hw->pointer(emu, epcm->substream),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) 			snd_pcm_lib_period_bytes(epcm->substream),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) 			snd_pcm_lib_buffer_bytes(epcm->substream));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) 	snd_pcm_period_elapsed(epcm->substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) static void snd_emu10k1_pcm_ac97adc_interrupt(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 					      unsigned int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) 	if (status & IPR_ADCBUFHALFFULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) 		if (emu->pcm_capture_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51) 	snd_pcm_period_elapsed(emu->pcm_capture_substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) static void snd_emu10k1_pcm_ac97mic_interrupt(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 					      unsigned int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58) 	if (status & IPR_MICBUFHALFFULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) 		if (emu->pcm_capture_mic_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63) 	snd_pcm_period_elapsed(emu->pcm_capture_mic_substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) static void snd_emu10k1_pcm_efx_interrupt(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) 					  unsigned int status)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70) 	if (status & IPR_EFXBUFHALFFULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71) 		if (emu->pcm_capture_efx_substream->runtime->mode == SNDRV_PCM_MODE_FRAME)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) 			return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75) 	snd_pcm_period_elapsed(emu->pcm_capture_efx_substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76) }	 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) static snd_pcm_uframes_t snd_emu10k1_efx_playback_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83) 	unsigned int ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 	if (!epcm->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) 	ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 	ptr += runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) 	ptr -= epcm->ccca_start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90) 	ptr %= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92) 	return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95) static int snd_emu10k1_pcm_channel_alloc(struct snd_emu10k1_pcm * epcm, int voices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) 	int err, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 	if (epcm->voices[1] != NULL && voices < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 		snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 		epcm->voices[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 	for (i = 0; i < voices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 		if (epcm->voices[i] == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) 	if (i == voices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108) 		return 0; /* already allocated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110) 	for (i = 0; i < ARRAY_SIZE(epcm->voices); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111) 		if (epcm->voices[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112) 			snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113) 			epcm->voices[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116) 	err = snd_emu10k1_voice_alloc(epcm->emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117) 				      epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118) 				      voices,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) 				      &epcm->voices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	epcm->voices[0]->epcm = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	if (voices > 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		for (i = 1; i < voices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 			epcm->voices[i] = &epcm->emu->voices[epcm->voices[0]->number + i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 			epcm->voices[i]->epcm = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) 	if (epcm->extra == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 		err = snd_emu10k1_voice_alloc(epcm->emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) 					      epcm->type == PLAYBACK_EMUVOICE ? EMU10K1_PCM : EMU10K1_EFX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133) 					      1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134) 					      &epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135) 		if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136) 			/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137) 			dev_dbg(emu->card->dev, "pcm_channel_alloc: "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138) 			       "failed extra: voices=%d, frame=%d\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139) 			       voices, frame);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140) 			*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141) 			for (i = 0; i < voices; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) 				snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) 				epcm->voices[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 		epcm->extra->epcm = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		epcm->extra->interrupt = snd_emu10k1_pcm_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) static const unsigned int capture_period_sizes[31] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	384,	448,	512,	640,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	384*2,	448*2,	512*2,	640*2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 	384*4,	448*4,	512*4,	640*4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	384*8,	448*8,	512*8,	640*8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 	384*16,	448*16,	512*16,	640*16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 	384*32,	448*32,	512*32,	640*32,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	384*64,	448*64,	512*64,	640*64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 	384*128,448*128,512*128
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) static const struct snd_pcm_hw_constraint_list hw_constraints_capture_period_sizes = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	.count = 31,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) 	.list = capture_period_sizes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 	.mask = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170) static const unsigned int capture_rates[8] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171) 	8000, 11025, 16000, 22050, 24000, 32000, 44100, 48000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) static const struct snd_pcm_hw_constraint_list hw_constraints_capture_rates = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) 	.count = 8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	.list = capture_rates,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 	.mask = 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) static unsigned int snd_emu10k1_capture_rate_reg(unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	switch (rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	case 8000:	return ADCCR_SAMPLERATE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	case 11025:	return ADCCR_SAMPLERATE_11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 	case 16000:	return ADCCR_SAMPLERATE_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 	case 22050:	return ADCCR_SAMPLERATE_22;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 	case 24000:	return ADCCR_SAMPLERATE_24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 	case 32000:	return ADCCR_SAMPLERATE_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 	case 44100:	return ADCCR_SAMPLERATE_44;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 	case 48000:	return ADCCR_SAMPLERATE_48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 			snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 			return ADCCR_SAMPLERATE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) static unsigned int snd_emu10k1_audigy_capture_rate_reg(unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	switch (rate) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	case 8000:	return A_ADCCR_SAMPLERATE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	case 11025:	return A_ADCCR_SAMPLERATE_11;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) 	case 12000:	return A_ADCCR_SAMPLERATE_12; /* really supported? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 	case 16000:	return ADCCR_SAMPLERATE_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) 	case 22050:	return ADCCR_SAMPLERATE_22;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205) 	case 24000:	return ADCCR_SAMPLERATE_24;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206) 	case 32000:	return ADCCR_SAMPLERATE_32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207) 	case 44100:	return ADCCR_SAMPLERATE_44;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208) 	case 48000:	return ADCCR_SAMPLERATE_48;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210) 			snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211) 			return A_ADCCR_SAMPLERATE_8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) static unsigned int emu10k1_calc_pitch_target(unsigned int rate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) 	unsigned int pitch_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	pitch_target = (rate << 8) / 375;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	pitch_target = (pitch_target >> 1) + (pitch_target & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 	return pitch_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) #define PITCH_48000 0x00004000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) #define PITCH_96000 0x00008000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) #define PITCH_85000 0x00007155
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) #define PITCH_80726 0x00006ba2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) #define PITCH_67882 0x00005a82
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) #define PITCH_57081 0x00004c1c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) static unsigned int emu10k1_select_interprom(unsigned int pitch_target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 	if (pitch_target == PITCH_48000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) 		return CCCA_INTERPROM_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 	else if (pitch_target < PITCH_48000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) 		return CCCA_INTERPROM_1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237) 	else if (pitch_target >= PITCH_96000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238) 		return CCCA_INTERPROM_0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239) 	else if (pitch_target >= PITCH_85000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240) 		return CCCA_INTERPROM_6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241) 	else if (pitch_target >= PITCH_80726)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242) 		return CCCA_INTERPROM_5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) 	else if (pitch_target >= PITCH_67882)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 		return CCCA_INTERPROM_4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 	else if (pitch_target >= PITCH_57081)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 		return CCCA_INTERPROM_3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) 	else  
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 		return CCCA_INTERPROM_2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)  * calculate cache invalidate size 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  * stereo: channel is stereo
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  * w_16: using 16bit samples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * returns: cache invalidate size in samples
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259) static inline int emu10k1_ccis(int stereo, int w_16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) 	if (w_16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 		return stereo ? 24 : 26;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 		return stereo ? 24*2 : 26*2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) static void snd_emu10k1_pcm_init_voice(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 				       int master, int extra,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 				       struct snd_emu10k1_voice *evoice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 				       unsigned int start_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 				       unsigned int end_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 				       struct snd_emu10k1_pcm_mixer *mix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 	struct snd_pcm_substream *substream = evoice->epcm->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 	unsigned int silent_page, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 	int voice, stereo, w_16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 	unsigned char send_amount[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	unsigned char send_routing[8];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 	unsigned int pitch_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	unsigned int ccis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 	voice = evoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) 	stereo = runtime->channels == 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287) 	w_16 = snd_pcm_format_width(runtime->format) == 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289) 	if (!extra && stereo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290) 		start_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291) 		end_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293) 	if (w_16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294) 		start_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295) 		end_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298) 	spin_lock_irqsave(&emu->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) 	/* volume parameters */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 	if (extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) 		memset(send_routing, 0, sizeof(send_routing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 		send_routing[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 		send_routing[1] = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 		send_routing[2] = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 		send_routing[3] = 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		memset(send_amount, 0, sizeof(send_amount));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 		/* mono, left, right (master voice = left) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		tmp = stereo ? (master ? 1 : 2) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 		memcpy(send_routing, &mix->send_routing[tmp][0], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 		memcpy(send_amount, &mix->send_volume[tmp][0], 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 	ccis = emu10k1_ccis(stereo, w_16);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 	if (master) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 		evoice->epcm->ccca_start_addr = start_addr + ccis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 		if (extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 			start_addr += ccis;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 			end_addr += ccis + emu->delay_pcm_irq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 		if (stereo && !extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 			snd_emu10k1_ptr_write(emu, CPF, voice, CPF_STEREO_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 			snd_emu10k1_ptr_write(emu, CPF, (voice + 1), CPF_STEREO_MASK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 			snd_emu10k1_ptr_write(emu, CPF, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331) 	/* setup routing */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332) 	if (emu->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) 		snd_emu10k1_ptr_write(emu, A_FXRT1, voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) 				      snd_emu10k1_compose_audigy_fxrt1(send_routing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 		snd_emu10k1_ptr_write(emu, A_FXRT2, voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 				      snd_emu10k1_compose_audigy_fxrt2(send_routing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 		snd_emu10k1_ptr_write(emu, A_SENDAMOUNTS, voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 				      ((unsigned int)send_amount[4] << 24) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 				      ((unsigned int)send_amount[5] << 16) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 				      ((unsigned int)send_amount[6] << 8) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 				      (unsigned int)send_amount[7]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 		snd_emu10k1_ptr_write(emu, FXRT, voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 				      snd_emu10k1_compose_send_routing(send_routing));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 	/* Stop CA */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 	/* Assumption that PT is already 0 so no harm overwriting */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	snd_emu10k1_ptr_write(emu, PTRX, voice, (send_amount[0] << 8) | send_amount[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	snd_emu10k1_ptr_write(emu, DSL, voice, end_addr | (send_amount[3] << 24));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 	snd_emu10k1_ptr_write(emu, PSST, voice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 			(start_addr + (extra ? emu->delay_pcm_irq : 0)) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) 			(send_amount[2] << 24));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 	if (emu->card_capabilities->emu_model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) 		pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354) 	else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355) 		pitch_target = emu10k1_calc_pitch_target(runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356) 	if (extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357) 		snd_emu10k1_ptr_write(emu, CCCA, voice, start_addr |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) 			      emu10k1_select_interprom(pitch_target) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) 			      (w_16 ? 0 : CCCA_8BITSELECT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		snd_emu10k1_ptr_write(emu, CCCA, voice, (start_addr + ccis) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 			      emu10k1_select_interprom(pitch_target) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 			      (w_16 ? 0 : CCCA_8BITSELECT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) 	/* Clear filter delay memory */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 	snd_emu10k1_ptr_write(emu, Z1, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) 	snd_emu10k1_ptr_write(emu, Z2, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367) 	/* invalidate maps */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368) 	silent_page = ((unsigned int)emu->silent_page.addr << emu->address_mode) | (emu->address_mode ? MAP_PTI_MASK1 : MAP_PTI_MASK0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369) 	snd_emu10k1_ptr_write(emu, MAPA, voice, silent_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370) 	snd_emu10k1_ptr_write(emu, MAPB, voice, silent_page);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) 	/* modulation envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 	snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) 	snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	snd_emu10k1_ptr_write(emu, ATKHLDM, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 	snd_emu10k1_ptr_write(emu, DCYSUSM, voice, 0x007f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	snd_emu10k1_ptr_write(emu, LFOVAL1, voice, 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	snd_emu10k1_ptr_write(emu, LFOVAL2, voice, 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	snd_emu10k1_ptr_write(emu, FMMOD, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 	snd_emu10k1_ptr_write(emu, TREMFRQ, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	snd_emu10k1_ptr_write(emu, FM2FRQ2, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	snd_emu10k1_ptr_write(emu, ENVVAL, voice, 0x8000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 	/* volume envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	snd_emu10k1_ptr_write(emu, ATKHLDV, voice, 0x7f7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 	snd_emu10k1_ptr_write(emu, ENVVOL, voice, 0x0000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	/* filter envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	snd_emu10k1_ptr_write(emu, PEFE_FILTERAMOUNT, voice, 0x7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	/* pitch envelope */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	snd_emu10k1_ptr_write(emu, PEFE_PITCHAMOUNT, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	spin_unlock_irqrestore(&emu->reg_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) static int snd_emu10k1_playback_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) 					  struct snd_pcm_hw_params *hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399) 	size_t alloc_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 	if ((err = snd_emu10k1_pcm_channel_alloc(epcm, params_channels(hw_params))) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 	alloc_size = params_buffer_bytes(hw_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	if (emu->iommu_workaround)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		alloc_size += EMUPAGESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 	err = snd_pcm_lib_malloc_pages(substream, alloc_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 	if (emu->iommu_workaround && runtime->dma_bytes >= EMUPAGESIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		runtime->dma_bytes -= EMUPAGESIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 	if (err > 0) {	/* change */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 		int mapped;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		if (epcm->memblk != NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 			snd_emu10k1_free_pages(emu, epcm->memblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 		epcm->memblk = snd_emu10k1_alloc_pages(emu, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 		epcm->start_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 		if (! epcm->memblk)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 		mapped = ((struct snd_emu10k1_memblk *)epcm->memblk)->mapped_page;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 		if (mapped < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 		epcm->start_addr = mapped << PAGE_SHIFT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) static int snd_emu10k1_playback_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 	if (runtime->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 	if (epcm->extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 		snd_emu10k1_voice_free(epcm->emu, epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 		epcm->extra = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 	if (epcm->voices[1]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) 		snd_emu10k1_voice_free(epcm->emu, epcm->voices[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444) 		epcm->voices[1] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446) 	if (epcm->voices[0]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) 		snd_emu10k1_voice_free(epcm->emu, epcm->voices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) 		epcm->voices[0] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	if (epcm->memblk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 		snd_emu10k1_free_pages(emu, epcm->memblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 		epcm->memblk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 		epcm->start_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 	snd_pcm_lib_free_pages(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) static int snd_emu10k1_efx_playback_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) 	if (runtime->private_data == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	if (epcm->extra) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 		snd_emu10k1_voice_free(epcm->emu, epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		epcm->extra = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 	for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 		if (epcm->voices[i]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) 			snd_emu10k1_voice_free(epcm->emu, epcm->voices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 			epcm->voices[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479) 	if (epcm->memblk) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480) 		snd_emu10k1_free_pages(emu, epcm->memblk);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481) 		epcm->memblk = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482) 		epcm->start_addr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484) 	snd_pcm_lib_free_pages(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) static int snd_emu10k1_playback_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	unsigned int start_addr, end_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 	start_addr = epcm->start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 	end_addr = snd_pcm_lib_period_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 	if (runtime->channels == 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 		start_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 		end_addr >>= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	end_addr += start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 				   start_addr, end_addr, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 	start_addr = epcm->start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 	snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 				   start_addr, end_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 				   &emu->pcm_mixer[substream->number]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 	if (epcm->voices[1])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 		snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[1],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 					   start_addr, end_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 					   &emu->pcm_mixer[substream->number]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) static int snd_emu10k1_efx_playback_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	unsigned int start_addr, end_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	unsigned int channel_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) 	start_addr = epcm->start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 	end_addr = epcm->start_addr + snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529) 	 * the kX driver leaves some space between voices
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531) 	channel_size = ( end_addr - start_addr ) / NUM_EFX_PLAYBACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) 	snd_emu10k1_pcm_init_voice(emu, 1, 1, epcm->extra,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				   start_addr, start_addr + (channel_size / 2), NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	/* only difference with the master voice is we use it for the pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	snd_emu10k1_pcm_init_voice(emu, 1, 0, epcm->voices[0],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 				   start_addr, start_addr + channel_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 				   &emu->efx_pcm_mixer[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	start_addr += channel_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	for (i = 1; i < NUM_EFX_PLAYBACK; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 		snd_emu10k1_pcm_init_voice(emu, 0, 0, epcm->voices[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 					   start_addr, start_addr + channel_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 					   &emu->efx_pcm_mixer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 		start_addr += channel_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) static const struct snd_pcm_hardware snd_emu10k1_efx_playback =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_NONINTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) 				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 	.formats =		SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) 	.rates =		SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560) 	.rate_min =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562) 	.channels_min =		NUM_EFX_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563) 	.channels_max =		NUM_EFX_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564) 	.buffer_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565) 	.period_bytes_min =	64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566) 	.period_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568) 	.periods_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572) static int snd_emu10k1_capture_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 	/* zeroing the buffer size will stop capture */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) 	snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	switch (epcm->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	case CAPTURE_AC97ADC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 		snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	case CAPTURE_EFX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 		if (emu->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 			snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 			snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 			snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	}	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	snd_emu10k1_ptr_write(emu, epcm->capture_ba_reg, 0, runtime->dma_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	epcm->capture_bufsize = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	epcm->capture_bs_val = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	for (idx = 0; idx < 31; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 		if (capture_period_sizes[idx] == epcm->capture_bufsize) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 			epcm->capture_bs_val = idx + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	if (epcm->capture_bs_val == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 		snd_BUG();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 		epcm->capture_bs_val++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	if (epcm->type == CAPTURE_AC97ADC) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 		epcm->capture_cr_val = emu->audigy ? A_ADCCR_LCHANENABLE : ADCCR_LCHANENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 		if (runtime->channels > 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 			epcm->capture_cr_val |= emu->audigy ? A_ADCCR_RCHANENABLE : ADCCR_RCHANENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 		epcm->capture_cr_val |= emu->audigy ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 			snd_emu10k1_audigy_capture_rate_reg(runtime->rate) :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 			snd_emu10k1_capture_rate_reg(runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) static void snd_emu10k1_playback_invalidate_cache(struct snd_emu10k1 *emu, int extra, struct snd_emu10k1_voice *evoice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621) 	struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622) 	unsigned int voice, stereo, i, ccis, cra = 64, cs, sample;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624) 	if (evoice == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) 	runtime = evoice->epcm->substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 	voice = evoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) 	stereo = (!extra && runtime->channels == 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	sample = snd_pcm_format_width(runtime->format) == 16 ? 0 : 0x80808080;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	ccis = emu10k1_ccis(stereo, sample == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	/* set cs to 2 * number of cache registers beside the invalidated */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	cs = (sample == 0) ? (32-ccis) : (64-ccis+1) >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	if (cs > 16) cs = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	for (i = 0; i < cs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 		snd_emu10k1_ptr_write(emu, CD0 + i, voice, sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 		if (stereo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 			snd_emu10k1_ptr_write(emu, CD0 + i, voice + 1, sample);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 	/* reset cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 	snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice, cra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	if (stereo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 		snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice + 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 		snd_emu10k1_ptr_write(emu, CCR_READADDRESS, voice + 1, cra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 	/* fill cache */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 	snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice, ccis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	if (stereo) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		snd_emu10k1_ptr_write(emu, CCR_CACHEINVALIDSIZE, voice+1, ccis);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) static void snd_emu10k1_playback_prepare_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 					       int master, int extra,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 					       struct snd_emu10k1_pcm_mixer *mix)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 	struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 	unsigned int attn, vattn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	unsigned int voice, tmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 	if (evoice == NULL)	/* skip second voice for mono */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	substream = evoice->epcm->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	voice = evoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 	attn = extra ? 0 : 0x00ff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	tmp = runtime->channels == 2 ? (master ? 1 : 2) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	vattn = mix != NULL ? (mix->attn[tmp] << 16) : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 	snd_emu10k1_ptr_write(emu, IFATN, voice, attn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	snd_emu10k1_ptr_write(emu, VTFT, voice, vattn | 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 	snd_emu10k1_ptr_write(emu, CVCF, voice, vattn | 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	snd_emu10k1_ptr_write(emu, DCYSUSV, voice, 0x7f7f);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	snd_emu10k1_voice_clear_loop_stop(emu, voice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) }	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) static void snd_emu10k1_playback_trigger_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice, int master, int extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 	struct snd_pcm_runtime *runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 	unsigned int voice, pitch, pitch_target;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 	if (evoice == NULL)	/* skip second voice for mono */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 	substream = evoice->epcm->substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 	runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 	voice = evoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 	pitch = snd_emu10k1_rate_to_pitch(runtime->rate) >> 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 	if (emu->card_capabilities->emu_model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		pitch_target = PITCH_48000; /* Disable interpolators on emu1010 card */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 	else 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		pitch_target = emu10k1_calc_pitch_target(runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 	snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, pitch_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 	if (master || evoice->epcm->type == PLAYBACK_EFX)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, pitch_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 	snd_emu10k1_ptr_write(emu, IP, voice, pitch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 	if (extra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 		snd_emu10k1_voice_intr_enable(emu, voice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) static void snd_emu10k1_playback_stop_voice(struct snd_emu10k1 *emu, struct snd_emu10k1_voice *evoice)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 	unsigned int voice;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 	if (evoice == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 	voice = evoice->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 	snd_emu10k1_voice_intr_disable(emu, voice);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 	snd_emu10k1_ptr_write(emu, PTRX_PITCHTARGET, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 	snd_emu10k1_ptr_write(emu, CPF_CURRENTPITCH, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 	snd_emu10k1_ptr_write(emu, IFATN, voice, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 	snd_emu10k1_ptr_write(emu, VTFT, voice, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 	snd_emu10k1_ptr_write(emu, CVCF, voice, 0xffff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 	snd_emu10k1_ptr_write(emu, IP, voice, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) static inline void snd_emu10k1_playback_mangle_extra(struct snd_emu10k1 *emu,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 		struct snd_emu10k1_pcm *epcm,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 		struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 		struct snd_pcm_runtime *runtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 	unsigned int ptr, period_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 	/* try to sychronize the current position for the interrupt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 	   source voice */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 	period_pos = runtime->status->hw_ptr - runtime->hw_ptr_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 	period_pos %= runtime->period_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 	ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->extra->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 	ptr &= ~0x00ffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 	ptr |= epcm->ccca_start_addr + period_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 	snd_emu10k1_ptr_write(emu, CCCA, epcm->extra->number, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) static int snd_emu10k1_playback_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 				        int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 	struct snd_emu10k1_pcm_mixer *mix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 	dev_dbg(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		"trigger - emu10k1 = 0x%x, cmd = %i, pointer = %i\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	       (int)emu, cmd, substream->ops->pointer(substream))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	spin_lock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);	/* do we need this? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 		snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) 		if (cmd == SNDRV_PCM_TRIGGER_PAUSE_RELEASE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 			snd_emu10k1_playback_mangle_extra(emu, epcm, substream, runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) 		mix = &emu->pcm_mixer[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762) 		snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 1, 0, mix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763) 		snd_emu10k1_playback_prepare_voice(emu, epcm->voices[1], 0, 0, mix);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764) 		snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765) 		snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 1, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766) 		snd_emu10k1_playback_trigger_voice(emu, epcm->voices[1], 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767) 		snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) 		epcm->running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 		epcm->running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 		snd_emu10k1_playback_stop_voice(emu, epcm->voices[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 		snd_emu10k1_playback_stop_voice(emu, epcm->voices[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 		snd_emu10k1_playback_stop_voice(emu, epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) 		result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782) 	spin_unlock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786) static int snd_emu10k1_capture_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787) 				       int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	spin_lock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 		/* hmm this should cause full and half full interrupt to be raised? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) 		outl(epcm->capture_ipr, emu->port + IPR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 		snd_emu10k1_intr_enable(emu, epcm->capture_inte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) 		/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802) 		dev_dbg(emu->card->dev, "adccr = 0x%x, adcbs = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803) 		       epcm->adccr, epcm->adcbs);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804) 		*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805) 		switch (epcm->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806) 		case CAPTURE_AC97ADC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) 			snd_emu10k1_ptr_write(emu, ADCCR, 0, epcm->capture_cr_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 		case CAPTURE_EFX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 			if (emu->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 				snd_emu10k1_ptr_write(emu, A_FXWC1, 0, epcm->capture_cr_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 				snd_emu10k1_ptr_write(emu, A_FXWC2, 0, epcm->capture_cr_val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 				dev_dbg(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 					"cr_val=0x%x, cr_val2=0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 					epcm->capture_cr_val,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 					epcm->capture_cr_val2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 				snd_emu10k1_ptr_write(emu, FXWC, 0, epcm->capture_cr_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 		default:	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 		snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, epcm->capture_bs_val);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		epcm->running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		epcm->first_ptr = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 		epcm->running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 		snd_emu10k1_intr_disable(emu, epcm->capture_inte);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		outl(epcm->capture_ipr, emu->port + IPR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		snd_emu10k1_ptr_write(emu, epcm->capture_bs_reg, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		switch (epcm->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 		case CAPTURE_AC97ADC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 			snd_emu10k1_ptr_write(emu, ADCCR, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 		case CAPTURE_EFX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 			if (emu->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 				snd_emu10k1_ptr_write(emu, A_FXWC1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 				snd_emu10k1_ptr_write(emu, A_FXWC2, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 			} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 				snd_emu10k1_ptr_write(emu, FXWC, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 		result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	spin_unlock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) static snd_pcm_uframes_t snd_emu10k1_playback_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 	unsigned int ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 	if (!epcm->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 	ptr = snd_emu10k1_ptr_read(emu, CCCA, epcm->voices[0]->number) & 0x00ffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) #if 0	/* Perex's code */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 	ptr += runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 	ptr -= epcm->ccca_start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 	ptr %= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) #else	/* EMU10K1 Open Source code from Creative */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 	if (ptr < epcm->ccca_start_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 		ptr += runtime->buffer_size - epcm->ccca_start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 	else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 		ptr -= epcm->ccca_start_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 		if (ptr >= runtime->buffer_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 			ptr -= runtime->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 	dev_dbg(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 	       "ptr = 0x%lx, buffer_size = 0x%lx, period_size = 0x%lx\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 	       (long)ptr, (long)runtime->buffer_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 	       (long)runtime->period_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	return ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) static int snd_emu10k1_efx_playback_trigger(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 				        int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	spin_lock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) 		/* prepare voices */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901) 		for (i = 0; i < NUM_EFX_PLAYBACK; i++) {	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902) 			snd_emu10k1_playback_invalidate_cache(emu, 0, epcm->voices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904) 		snd_emu10k1_playback_invalidate_cache(emu, 1, epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) 		fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 		snd_emu10k1_playback_prepare_voice(emu, epcm->extra, 1, 1, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 		snd_emu10k1_playback_prepare_voice(emu, epcm->voices[0], 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 						   &emu->efx_pcm_mixer[0]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 		for (i = 1; i < NUM_EFX_PLAYBACK; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 			snd_emu10k1_playback_prepare_voice(emu, epcm->voices[i], 0, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 							   &emu->efx_pcm_mixer[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		snd_emu10k1_playback_trigger_voice(emu, epcm->voices[0], 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 		snd_emu10k1_playback_trigger_voice(emu, epcm->extra, 1, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		for (i = 1; i < NUM_EFX_PLAYBACK; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 			snd_emu10k1_playback_trigger_voice(emu, epcm->voices[i], 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 		epcm->running = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 		epcm->running = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		for (i = 0; i < NUM_EFX_PLAYBACK; i++) {	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 			snd_emu10k1_playback_stop_voice(emu, epcm->voices[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 		snd_emu10k1_playback_stop_voice(emu, epcm->extra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) 		result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933) 	spin_unlock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938) static snd_pcm_uframes_t snd_emu10k1_capture_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	struct snd_emu10k1_pcm *epcm = runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	unsigned int ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	if (!epcm->running)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	if (epcm->first_ptr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 		udelay(50);	/* hack, it takes awhile until capture is started */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 		epcm->first_ptr = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 	ptr = snd_emu10k1_ptr_read(emu, epcm->capture_idx_reg, 0) & 0x0000ffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	return bytes_to_frames(runtime, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956)  *  Playback support device description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) static const struct snd_pcm_hardware snd_emu10k1_playback =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 				 SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_PAUSE),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 	.rates =		SNDRV_PCM_RATE_CONTINUOUS | SNDRV_PCM_RATE_8000_96000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 	.rate_min =		4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 	.rate_max =		96000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 	.channels_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 	.buffer_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	.period_bytes_min =	64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 	.period_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	.periods_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	.periods_max =		1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980)  *  Capture support device description
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) static const struct snd_pcm_hardware snd_emu10k1_capture =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 				 SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	.formats =		SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	.rates =		SNDRV_PCM_RATE_8000_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	.rate_min =		8000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	.channels_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	.buffer_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	.period_bytes_min =	384,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 	.period_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	.periods_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) static const struct snd_pcm_hardware snd_emu10k1_capture_efx =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 				 SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 				 SNDRV_PCM_INFO_MMAP_VALID),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	.formats =		SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	.rates =		SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 | 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 				 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 				 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	.rate_min =		44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 	.rate_max =		192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	.channels_min =		8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 	.channels_max =		8,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	.buffer_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	.period_bytes_min =	384,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 	.period_bytes_max =	(64*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	.periods_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) static void snd_emu10k1_pcm_mixer_notify1(struct snd_emu10k1 *emu, struct snd_kcontrol *kctl, int idx, int activate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	struct snd_ctl_elem_id id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	if (! kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	if (activate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 		kctl->vd[idx].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 		kctl->vd[idx].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 	snd_ctl_notify(emu->card, SNDRV_CTL_EVENT_MASK_VALUE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 		       SNDRV_CTL_EVENT_MASK_INFO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 		       snd_ctl_build_ioff(&id, kctl, idx));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) static void snd_emu10k1_pcm_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_routing, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_send_volume, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_attn, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) static void snd_emu10k1_pcm_efx_mixer_notify(struct snd_emu10k1 *emu, int idx, int activate)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_routing, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_send_volume, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) 	snd_emu10k1_pcm_mixer_notify1(emu, emu->ctl_efx_attn, idx, activate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058) static void snd_emu10k1_pcm_free_substream(struct snd_pcm_runtime *runtime)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060) 	kfree(runtime->private_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) static int snd_emu10k1_efx_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	struct snd_emu10k1_pcm_mixer *mix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		mix = &emu->efx_pcm_mixer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 		mix->epcm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 		snd_emu10k1_pcm_efx_mixer_notify(emu, i, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) static int snd_emu10k1_efx_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	struct snd_emu10k1_pcm_mixer *mix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) 	epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	if (epcm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 	epcm->emu = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) 	epcm->type = PLAYBACK_EFX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090) 	epcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092) 	emu->pcm_playback_efx_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094) 	runtime->private_data = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) 	runtime->private_free = snd_emu10k1_pcm_free_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) 	runtime->hw = snd_emu10k1_efx_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 	for (i = 0; i < NUM_EFX_PLAYBACK; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) 		mix = &emu->efx_pcm_mixer[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 		mix->send_routing[0][0] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) 		memset(&mix->send_volume, 0, sizeof(mix->send_volume));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102) 		mix->send_volume[0][0] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103) 		mix->attn[0] = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104) 		mix->epcm = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105) 		snd_emu10k1_pcm_efx_mixer_notify(emu, i, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	struct snd_emu10k1_pcm_mixer *mix;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 	int i, err, sample_rate;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 	epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 	if (epcm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 	epcm->emu = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	epcm->type = PLAYBACK_EMUVOICE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 	epcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 	runtime->private_data = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 	runtime->private_free = snd_emu10k1_pcm_free_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	runtime->hw = snd_emu10k1_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 		kfree(epcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	if ((err = snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 256, UINT_MAX)) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 		kfree(epcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	if (emu->card_capabilities->emu_model && emu->emu1010.internal_clock == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 		sample_rate = 44100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		sample_rate = 48000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	err = snd_pcm_hw_rule_noresample(runtime, sample_rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 		kfree(epcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) 	mix = &emu->pcm_mixer[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 	for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) 		mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147) 	memset(&mix->send_volume, 0, sizeof(mix->send_volume));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148) 	mix->send_volume[0][0] = mix->send_volume[0][1] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149) 	mix->send_volume[1][0] = mix->send_volume[2][1] = 255;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150) 	mix->attn[0] = mix->attn[1] = mix->attn[2] = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151) 	mix->epcm = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152) 	snd_emu10k1_pcm_mixer_notify(emu, substream->number, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156) static int snd_emu10k1_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 	struct snd_emu10k1_pcm_mixer *mix = &emu->pcm_mixer[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) 	mix->epcm = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	snd_emu10k1_pcm_mixer_notify(emu, substream->number, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) static int snd_emu10k1_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 	if (epcm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	epcm->emu = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 	epcm->type = CAPTURE_AC97ADC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 	epcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	epcm->capture_ipr = IPR_ADCBUFFULL|IPR_ADCBUFHALFFULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 	epcm->capture_inte = INTE_ADCBUFENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	epcm->capture_ba_reg = ADCBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	epcm->capture_bs_reg = ADCBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 	epcm->capture_idx_reg = emu->audigy ? A_ADCIDX : ADCIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 	runtime->private_data = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	runtime->private_free = snd_emu10k1_pcm_free_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 	runtime->hw = snd_emu10k1_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	emu->capture_interrupt = snd_emu10k1_pcm_ac97adc_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	emu->pcm_capture_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, &hw_constraints_capture_rates);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) static int snd_emu10k1_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	emu->capture_interrupt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	emu->pcm_capture_substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) static int snd_emu10k1_capture_mic_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 	epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) 	if (epcm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 	epcm->emu = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	epcm->type = CAPTURE_AC97MIC;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 	epcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 	epcm->capture_ipr = IPR_MICBUFFULL|IPR_MICBUFHALFFULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	epcm->capture_inte = INTE_MICBUFENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) 	epcm->capture_ba_reg = MICBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 	epcm->capture_bs_reg = MICBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) 	epcm->capture_idx_reg = emu->audigy ? A_MICIDX : MICIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219) 	substream->runtime->private_data = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220) 	substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221) 	runtime->hw = snd_emu10k1_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222) 	runtime->hw.rates = SNDRV_PCM_RATE_8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223) 	runtime->hw.rate_min = runtime->hw.rate_max = 8000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224) 	runtime->hw.channels_min = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225) 	emu->capture_mic_interrupt = snd_emu10k1_pcm_ac97mic_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226) 	emu->pcm_capture_mic_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227) 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) static int snd_emu10k1_capture_mic_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	emu->capture_interrupt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 	emu->pcm_capture_mic_substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) static int snd_emu10k1_capture_efx_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	struct snd_emu10k1_pcm *epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	int nefx = emu->audigy ? 64 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	epcm = kzalloc(sizeof(*epcm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (epcm == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 	epcm->emu = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	epcm->type = CAPTURE_EFX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 	epcm->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	epcm->capture_ipr = IPR_EFXBUFFULL|IPR_EFXBUFHALFFULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	epcm->capture_inte = INTE_EFXBUFENABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	epcm->capture_ba_reg = FXBA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	epcm->capture_bs_reg = FXBS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	epcm->capture_idx_reg = FXIDX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	substream->runtime->private_data = epcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	substream->runtime->private_free = snd_emu10k1_pcm_free_substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	runtime->hw = snd_emu10k1_capture_efx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 	runtime->hw.rates = SNDRV_PCM_RATE_48000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 	runtime->hw.rate_min = runtime->hw.rate_max = 48000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 	spin_lock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 	if (emu->card_capabilities->emu_model) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 		/*  Nb. of channels has been increased to 16 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 		/* TODO
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 		 * SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S32_LE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		 * SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 		 * SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		 * SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		 * rate_min = 44100,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 		 * rate_max = 192000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 		 * channels_min = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		 * channels_max = 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		 * Need to add mixer control to fix sample rate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		 *                 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		 * There are 32 mono channels of 16bits each.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		 * 24bit Audio uses 2x channels over 16bit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		 * 96kHz uses 2x channels over 48kHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		 * 192kHz uses 4x channels over 48kHz
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 		 * So, for 48kHz 24bit, one has 16 channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 		 * for 96kHz 24bit, one has 8 channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 		 * for 192kHz 24bit, one has 4 channels
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 		 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) #if 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) 		switch (emu->emu1010.internal_clock) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 		case 0:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 			/* For 44.1kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 			runtime->hw.rates = SNDRV_PCM_RATE_44100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) 			runtime->hw.rate_min = runtime->hw.rate_max = 44100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 			runtime->hw.channels_min =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) 				runtime->hw.channels_max = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296) 		case 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297) 			/* For 48kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298) 			runtime->hw.rates = SNDRV_PCM_RATE_48000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) 			runtime->hw.rate_min = runtime->hw.rate_max = 48000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) 			runtime->hw.channels_min =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 				runtime->hw.channels_max = 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 		/* For 96kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 		runtime->hw.rates = SNDRV_PCM_RATE_96000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 		runtime->hw.rate_min = runtime->hw.rate_max = 96000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		runtime->hw.channels_min = runtime->hw.channels_max = 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) #if 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		/* For 192kHz */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		runtime->hw.rates = SNDRV_PCM_RATE_192000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 		runtime->hw.rate_min = runtime->hw.rate_max = 192000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 		runtime->hw.channels_min = runtime->hw.channels_max = 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 		runtime->hw.formats = SNDRV_PCM_FMTBIT_S32_LE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		/* efx_voices_mask[0] is expected to be zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319)  		 * efx_voices_mask[1] is expected to have 32bits set
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		runtime->hw.channels_min = runtime->hw.channels_max = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 		for (idx = 0; idx < nefx; idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 			if (emu->efx_voices_mask[idx/32] & (1 << (idx%32))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) 				runtime->hw.channels_min++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 				runtime->hw.channels_max++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330) 	epcm->capture_cr_val = emu->efx_voices_mask[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331) 	epcm->capture_cr_val2 = emu->efx_voices_mask[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332) 	spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333) 	emu->capture_efx_interrupt = snd_emu10k1_pcm_efx_interrupt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) 	emu->pcm_capture_efx_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) 	snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, &hw_constraints_capture_period_sizes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) static int snd_emu10k1_capture_efx_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	emu->capture_interrupt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 	emu->pcm_capture_efx_substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) static const struct snd_pcm_ops snd_emu10k1_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 	.open =			snd_emu10k1_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	.close =		snd_emu10k1_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 	.hw_params =		snd_emu10k1_playback_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	.hw_free =		snd_emu10k1_playback_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	.prepare =		snd_emu10k1_playback_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 	.trigger =		snd_emu10k1_playback_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 	.pointer =		snd_emu10k1_playback_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) static const struct snd_pcm_ops snd_emu10k1_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	.open =			snd_emu10k1_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	.close =		snd_emu10k1_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	.prepare =		snd_emu10k1_capture_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 	.trigger =		snd_emu10k1_capture_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	.pointer =		snd_emu10k1_capture_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) /* EFX playback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) static const struct snd_pcm_ops snd_emu10k1_efx_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 	.open =			snd_emu10k1_efx_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	.close =		snd_emu10k1_efx_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	.hw_params =		snd_emu10k1_playback_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 	.hw_free =		snd_emu10k1_efx_playback_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	.prepare =		snd_emu10k1_efx_playback_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 	.trigger =		snd_emu10k1_efx_playback_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) 	.pointer =		snd_emu10k1_efx_playback_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) int snd_emu10k1_pcm(struct snd_emu10k1 *emu, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383) 	if ((err = snd_pcm_new(emu->card, "emu10k1", device, 32, 1, &pcm)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386) 	pcm->private_data = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	strcpy(pcm->name, "ADC Capture/Standard PCM Playback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 	emu->pcm = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 	/* playback substream can't use managed buffers due to alignment */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 		snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 					      &emu->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 					      64*1024, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 	for (substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream; substream; substream = substream->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 					   &emu->pci->dev, 64*1024, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) int snd_emu10k1_pcm_multi(struct snd_emu10k1 *emu, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 	struct snd_pcm_substream *substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 	if ((err = snd_pcm_new(emu->card, "emu10k1", device, 1, 0, &pcm)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 	pcm->private_data = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_efx_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 	pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	strcpy(pcm->name, "Multichannel Playback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 	emu->pcm_multi = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 	for (substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream; substream; substream = substream->next)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 		snd_pcm_lib_preallocate_pages(substream, SNDRV_DMA_TYPE_DEV_SG,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 					      &emu->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 					      64*1024, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) static const struct snd_pcm_ops snd_emu10k1_capture_mic_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 	.open =			snd_emu10k1_capture_mic_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 	.close =		snd_emu10k1_capture_mic_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 	.prepare =		snd_emu10k1_capture_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 	.trigger =		snd_emu10k1_capture_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 	.pointer =		snd_emu10k1_capture_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) int snd_emu10k1_pcm_mic(struct snd_emu10k1 *emu, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 	if ((err = snd_pcm_new(emu->card, "emu10k1 mic", device, 0, 1, &pcm)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 	pcm->private_data = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_mic_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	strcpy(pcm->name, "Mic Capture");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	emu->pcm_mic = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) 	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 				       64*1024, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466) static int snd_emu10k1_pcm_efx_voices_mask_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468) 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469) 	int nefx = emu->audigy ? 64 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) 	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) 	uinfo->count = nefx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	uinfo->value.integer.min = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 	uinfo->value.integer.max = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) static int snd_emu10k1_pcm_efx_voices_mask_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	int nefx = emu->audigy ? 64 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 	int idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	spin_lock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 	for (idx = 0; idx < nefx; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 		ucontrol->value.integer.value[idx] = (emu->efx_voices_mask[idx / 32] & (1 << (idx % 32))) ? 1 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 	spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) static int snd_emu10k1_pcm_efx_voices_mask_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492) 	struct snd_emu10k1 *emu = snd_kcontrol_chip(kcontrol);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493) 	unsigned int nval[2], bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) 	int nefx = emu->audigy ? 64 : 32;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) 	int nefxb = emu->audigy ? 7 : 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	int change, idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1498) 	nval[0] = nval[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1499) 	for (idx = 0, bits = 0; idx < nefx; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1500) 		if (ucontrol->value.integer.value[idx]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1501) 			nval[idx / 32] |= 1 << (idx % 32);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1502) 			bits++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1503) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1504) 		
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1505) 	for (idx = 0; idx < nefxb; idx++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1506) 		if (1 << idx == bits)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1507) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1508) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1509) 	if (idx >= nefxb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1510) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1512) 	spin_lock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1513) 	change = (nval[0] != emu->efx_voices_mask[0]) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1514) 		(nval[1] != emu->efx_voices_mask[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1515) 	emu->efx_voices_mask[0] = nval[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1516) 	emu->efx_voices_mask[1] = nval[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1517) 	spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1518) 	return change;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1519) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1520) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1521) static const struct snd_kcontrol_new snd_emu10k1_pcm_efx_voices_mask = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1522) 	.iface = SNDRV_CTL_ELEM_IFACE_PCM,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1523) 	.name = "Captured FX8010 Outputs",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1524) 	.info = snd_emu10k1_pcm_efx_voices_mask_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1525) 	.get = snd_emu10k1_pcm_efx_voices_mask_get,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1526) 	.put = snd_emu10k1_pcm_efx_voices_mask_put
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1527) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1528) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1529) static const struct snd_pcm_ops snd_emu10k1_capture_efx_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1530) 	.open =			snd_emu10k1_capture_efx_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1531) 	.close =		snd_emu10k1_capture_efx_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1532) 	.prepare =		snd_emu10k1_capture_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1533) 	.trigger =		snd_emu10k1_capture_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1534) 	.pointer =		snd_emu10k1_capture_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1535) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1536) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1538) /* EFX playback */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1540) #define INITIAL_TRAM_SHIFT     14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1541) #define INITIAL_TRAM_POS(size) ((((size) / 2) - INITIAL_TRAM_SHIFT) - 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1542) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1543) static void snd_emu10k1_fx8010_playback_irq(struct snd_emu10k1 *emu, void *private_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1544) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1545) 	struct snd_pcm_substream *substream = private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1546) 	snd_pcm_period_elapsed(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1547) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1548) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1549) static void snd_emu10k1_fx8010_playback_tram_poke1(unsigned short *dst_left,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1550) 						   unsigned short *dst_right,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1551) 						   unsigned short *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1552) 						   unsigned int count,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1553) 						   unsigned int tram_shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1554) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1555) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1556) 	dev_dbg(emu->card->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1557) 		"tram_poke1: dst_left = 0x%p, dst_right = 0x%p, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1558) 	       "src = 0x%p, count = 0x%x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1559) 	       dst_left, dst_right, src, count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1560) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1561) 	if ((tram_shift & 1) == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1562) 		while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1563) 			*dst_left-- = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1564) 			*dst_right-- = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1565) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1566) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1567) 		while (count--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1568) 			*dst_right-- = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1569) 			*dst_left-- = *src++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1570) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1571) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1572) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1573) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1574) static void fx8010_pb_trans_copy(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1575) 				 struct snd_pcm_indirect *rec, size_t bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1576) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1577) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1578) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1579) 	unsigned int tram_size = pcm->buffer_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1580) 	unsigned short *src = (unsigned short *)(substream->runtime->dma_area + rec->sw_data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1581) 	unsigned int frames = bytes >> 2, count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1582) 	unsigned int tram_pos = pcm->tram_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1583) 	unsigned int tram_shift = pcm->tram_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1584) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1585) 	while (frames > tram_pos) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1586) 		count = tram_pos + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1587) 		snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1588) 						       (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1589) 						       src, count, tram_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1590) 		src += count * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1591) 		frames -= count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1592) 		tram_pos = (tram_size / 2) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1593) 		tram_shift++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1594) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1595) 	snd_emu10k1_fx8010_playback_tram_poke1((unsigned short *)emu->fx8010.etram_pages.area + tram_pos,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1596) 					       (unsigned short *)emu->fx8010.etram_pages.area + tram_pos + tram_size / 2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1597) 					       src, frames, tram_shift);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1598) 	tram_pos -= frames;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1599) 	pcm->tram_pos = tram_pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1600) 	pcm->tram_shift = tram_shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1601) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1603) static int snd_emu10k1_fx8010_playback_transfer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1604) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1605) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1606) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1608) 	return snd_pcm_indirect_playback_transfer(substream, &pcm->pcm_rec,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1609) 						  fx8010_pb_trans_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1610) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1612) static int snd_emu10k1_fx8010_playback_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1613) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1614) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1615) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1616) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1617) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1618) 	for (i = 0; i < pcm->channels; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1619) 		snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1620) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1622) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1623) static int snd_emu10k1_fx8010_playback_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1624) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1625) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1626) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1627) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1628) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1629) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1630) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1631) 	dev_dbg(emu->card->dev, "prepare: etram_pages = 0x%p, dma_area = 0x%x, "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1632) 	       "buffer_size = 0x%x (0x%x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1633) 	       emu->fx8010.etram_pages, runtime->dma_area,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1634) 	       runtime->buffer_size, runtime->buffer_size << 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1635) 	*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1636) 	memset(&pcm->pcm_rec, 0, sizeof(pcm->pcm_rec));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1637) 	pcm->pcm_rec.hw_buffer_size = pcm->buffer_size * 2; /* byte size */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1638) 	pcm->pcm_rec.sw_buffer_size = snd_pcm_lib_buffer_bytes(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1639) 	pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1640) 	pcm->tram_shift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1641) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_running, 0, 0);	/* reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1642) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);	/* reset */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1643) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_size, 0, runtime->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1644) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_ptr, 0, 0);		/* reset ptr number */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1645) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_count, 0, runtime->period_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1646) 	snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_tmpcount, 0, runtime->period_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1647) 	for (i = 0; i < pcm->channels; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1648) 		snd_emu10k1_ptr_write(emu, TANKMEMADDRREGBASE + 0x80 + pcm->etram[i], 0, (TANKMEMADDRREG_READ|TANKMEMADDRREG_ALIGN) + i * (runtime->buffer_size / pcm->channels));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1649) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1650) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1652) static int snd_emu10k1_fx8010_playback_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1653) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1654) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1655) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1656) 	int result = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1657) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1658) 	spin_lock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1659) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1660) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1661) 		/* follow thru */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1662) 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1663) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1664) #ifdef EMU10K1_SET_AC3_IEC958
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1665) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1666) 		int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1667) 		for (i = 0; i < 3; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1668) 			unsigned int bits;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1669) 			bits = SPCS_CLKACCY_1000PPM | SPCS_SAMPLERATE_48 |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1670) 			       SPCS_CHANNELNUM_LEFT | SPCS_SOURCENUM_UNSPEC | SPCS_GENERATIONSTATUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1671) 			       0x00001200 | SPCS_EMPHASIS_NONE | SPCS_COPYRIGHT | SPCS_NOTAUDIODATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1672) 			snd_emu10k1_ptr_write(emu, SPCS0 + i, 0, bits);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1673) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1674) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1675) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1676) 		result = snd_emu10k1_fx8010_register_irq_handler(emu, snd_emu10k1_fx8010_playback_irq, pcm->gpr_running, substream, &pcm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1677) 		if (result < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1678) 			goto __err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1679) 		snd_emu10k1_fx8010_playback_transfer(substream);	/* roll the ball */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1680) 		snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1681) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1682) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1683) 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1684) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1685) 		snd_emu10k1_fx8010_unregister_irq_handler(emu, &pcm->irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1686) 		snd_emu10k1_ptr_write(emu, emu->gpr_base + pcm->gpr_trigger, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1687) 		pcm->tram_pos = INITIAL_TRAM_POS(pcm->buffer_size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1688) 		pcm->tram_shift = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1689) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1690) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1691) 		result = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1692) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1693) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1694)       __err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1695) 	spin_unlock(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1696) 	return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1697) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1698) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1699) static snd_pcm_uframes_t snd_emu10k1_fx8010_playback_pointer(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1700) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1701) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1702) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1703) 	size_t ptr; /* byte pointer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1704) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1705) 	if (!snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_trigger, 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1706) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1707) 	ptr = snd_emu10k1_ptr_read(emu, emu->gpr_base + pcm->gpr_ptr, 0) << 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1708) 	return snd_pcm_indirect_playback_pointer(substream, &pcm->pcm_rec, ptr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1709) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1710) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1711) static const struct snd_pcm_hardware snd_emu10k1_fx8010_playback =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1712) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1713) 	.info =			(SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1714) 				 SNDRV_PCM_INFO_RESUME |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1715) 				 /* SNDRV_PCM_INFO_MMAP_VALID | */ SNDRV_PCM_INFO_PAUSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1716) 				 SNDRV_PCM_INFO_SYNC_APPLPTR),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1717) 	.formats =		SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1718) 	.rates =		SNDRV_PCM_RATE_48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1719) 	.rate_min =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1720) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1721) 	.channels_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1722) 	.channels_max =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1723) 	.buffer_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1724) 	.period_bytes_min =	1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1725) 	.period_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1726) 	.periods_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1727) 	.periods_max =		1024,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1728) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1729) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1730) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1731) static int snd_emu10k1_fx8010_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1732) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1733) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1734) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1735) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1736) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1737) 	runtime->hw = snd_emu10k1_fx8010_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1738) 	runtime->hw.channels_min = runtime->hw.channels_max = pcm->channels;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1739) 	runtime->hw.period_bytes_max = (pcm->buffer_size * 2) / 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1740) 	spin_lock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1741) 	if (pcm->valid == 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1742) 		spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1743) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1744) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1745) 	pcm->opened = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1746) 	spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1747) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1748) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1749) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1750) static int snd_emu10k1_fx8010_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1751) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1752) 	struct snd_emu10k1 *emu = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1753) 	struct snd_emu10k1_fx8010_pcm *pcm = &emu->fx8010.pcm[substream->number];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1754) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1755) 	spin_lock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1756) 	pcm->opened = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1757) 	spin_unlock_irq(&emu->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1758) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1761) static const struct snd_pcm_ops snd_emu10k1_fx8010_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1762) 	.open =			snd_emu10k1_fx8010_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1763) 	.close =		snd_emu10k1_fx8010_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1764) 	.hw_free =		snd_emu10k1_fx8010_playback_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1765) 	.prepare =		snd_emu10k1_fx8010_playback_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1766) 	.trigger =		snd_emu10k1_fx8010_playback_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1767) 	.pointer =		snd_emu10k1_fx8010_playback_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1768) 	.ack =			snd_emu10k1_fx8010_playback_transfer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1769) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1770) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1771) int snd_emu10k1_pcm_efx(struct snd_emu10k1 *emu, int device)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1772) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1773) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1774) 	struct snd_kcontrol *kctl;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1775) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1776) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1777) 	if ((err = snd_pcm_new(emu->card, "emu10k1 efx", device, 8, 1, &pcm)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1778) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1779) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1780) 	pcm->private_data = emu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1781) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1782) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &snd_emu10k1_fx8010_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1783) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &snd_emu10k1_capture_efx_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1784) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1785) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1786) 	strcpy(pcm->name, "Multichannel Capture/PT Playback");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1787) 	emu->pcm_efx = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1788) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1789) 	/* EFX capture - record the "FXBUS2" channels, by default we connect the EXTINs 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1790) 	 * to these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1791) 	 */	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1792) 	
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1793) 	/* emu->efx_voices_mask[0] = FXWC_DEFAULTROUTE_C | FXWC_DEFAULTROUTE_A; */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1794) 	if (emu->audigy) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1795) 		emu->efx_voices_mask[0] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1796) 		if (emu->card_capabilities->emu_model)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1797) 			/* Pavel Hofman - 32 voices will be used for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1798) 			 * capture (write mode) -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1799) 			 * each bit = corresponding voice
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1800) 			 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1801) 			emu->efx_voices_mask[1] = 0xffffffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1802) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1803) 			emu->efx_voices_mask[1] = 0xffff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1804) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1805) 		emu->efx_voices_mask[0] = 0xffff0000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1806) 		emu->efx_voices_mask[1] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1807) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1808) 	/* For emu1010, the control has to set 32 upper bits (voices)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1809) 	 * out of the 64 bits (voices) to true for the 16-channels capture
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1810) 	 * to work correctly. Correct A_FXWC2 initial value (0xffffffff)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1811) 	 * is already defined but the snd_emu10k1_pcm_efx_voices_mask
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1812) 	 * control can override this register's value.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1813) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1814) 	kctl = snd_ctl_new1(&snd_emu10k1_pcm_efx_voices_mask, emu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1815) 	if (!kctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1816) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1817) 	kctl->id.device = device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1818) 	err = snd_ctl_add(emu->card, kctl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1819) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1820) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1822) 	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV, &emu->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1823) 				       64*1024, 64*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1824) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1825) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1826) }