Esempio n. 1
0
/*
 *  Main dma routine, requests dma according where you are in main alsa buffer
 */
static void audio_process_dma(struct audio_stream_a *s)
{
	struct snd_pcm_substream *substream = s->stream;
	struct snd_pcm_runtime *runtime;
	unsigned int dma_size;
	unsigned int offset;
	dma_addr_t dma_base;
	int ret = 0;
	//int stream_id = substream->pstr->stream;
	
	DPRINTK("s: %d, dmach: %d. active: %d", (int)s, s->dmach, s->active);
	
	if (s->active) {
		substream = s->stream;
		runtime = substream->runtime;
		dma_size = frames_to_bytes(runtime, runtime->period_size);
		/*DPRINTK("frame_bits=%d, period_size=%d, dma_size 1=%d",
			runtime->frame_bits, (int)runtime->period_size, dma_size);*/
		if (dma_size > MAX_DMA_SIZE)
			dma_size = CUT_DMA_SIZE;
		offset = dma_size * s->period;

		/*DPRINTK("offset: 0x%x, ->dma_area: 0x%x, ->dma_addr: 0x%x, final addr: 0x%x",
			offset, (unsigned int)runtime->dma_area, runtime->dma_addr, runtime->dma_addr+offset);*/

		dma_base = __virt_to_phys((dma_addr_t)runtime->dma_area);
		
		if (((runtime->channels == 2) && (runtime->format == SNDRV_PCM_FORMAT_S16_LE))  ||
			((runtime->channels == 1) && (runtime->format == SNDRV_PCM_FORMAT_S16_LE))) {
			ret = wmt_start_dma(s->dmach, runtime->dma_addr + offset, 0, dma_size);
		}

		if (ret) {
			printk(KERN_ERR "audio_process_dma: cannot queue DMA buffer (%i) \n", ret);
			return;
		}

		s->period++;
		s->period %= runtime->periods;
		s->periods++;
		s->offset = offset;
	}
}
Esempio n. 2
0
/*
 *  Main dma routine, requests dma according where you are in main alsa buffer
 */
static void audio_process_dma(struct audio_stream_a *s)
{
	struct snd_pcm_substream *substream = s->stream;
	struct snd_pcm_runtime *runtime;
	unsigned int dma_size;
	unsigned int offset;
	dma_addr_t dma_base;
	int ret = 0;
	int stream_id = substream->pstr->stream;
	
	//DBG_DETAIL();
	DPRINTK("s: %d, dmach: %d. active: %d", (int)s, s->dmach, s->active);
	
	if (s->active) {
		substream = s->stream;
		runtime = substream->runtime;
		dma_size = frames_to_bytes(runtime, runtime->period_size);
		/*DPRINTK("frame_bits=%d, period_size=%d, dma_size 1=%d",
			runtime->frame_bits, (int)runtime->period_size, dma_size);*/
		if (dma_size > MAX_DMA_SIZE)
			dma_size = CUT_DMA_SIZE;
		offset = dma_size * s->period;

		/*DPRINTK("offset: 0x%x, ->dma_area: 0x%x, ->dma_addr: 0x%x, final addr: 0x%x",
			offset, (unsigned int)runtime->dma_area, runtime->dma_addr, runtime->dma_addr+offset);*/

		dma_base = __virt_to_phys((dma_addr_t)runtime->dma_area);

		//DPRINTK("dma address: 0x%x", dma_base+offset);
		/*DPRINTK("hw_ptr_interrupt: 0x%x, state: %d, hwptr: %u, applptr: %u, avail_min: %u", 
			(unsigned int)runtime->hw_ptr_interrupt, runtime->status->state, (unsigned int)runtime->status->hw_ptr,
			(unsigned int)runtime->control->appl_ptr, (unsigned int)runtime->control->avail_min);*/
		//DPRINTK("dmach: %u, dma_addr: %x, dma_size: %u", s->dmach, dma_base+offset, dma_size);
		//printk(KERN_INFO "offset: %u, dma_addr: %x, dma_size: %u\n", offset, dma_base+offset, dma_size);

#ifdef CONFIG_SND_WMT_SOC_I2S		
		if (!strcmp(wmt_dai_name, "i2s")) {
			if (stream_id == SNDRV_PCM_STREAM_PLAYBACK) {
				//printk(KERN_ERR  "audio_process_dma: format=0x%x, channels=0x%x \n", runtime->format, runtime->channels);
				
				wmt_sw_u2s(runtime->format, (unsigned char *)runtime->dma_buffer_p->area+offset, dma_size);
				
				if (((runtime->channels == 1) && (runtime->format == SNDRV_PCM_FORMAT_S16_LE)) ||
					((runtime->channels == 2) && (runtime->format == SNDRV_PCM_FORMAT_U8))) {
					wmt_pcm_fmt_trans(runtime->format, runtime->channels,
						(unsigned char *)runtime->dma_buffer_p->area + offset,
						(unsigned char *)dump_buf[stream_id].area + (2 * offset),
						dma_size);
					ret = wmt_start_dma(s->dmach, dump_buf[stream_id].addr + (2 * offset), 0, (2 * dma_size));
				}
				else if ((runtime->channels == 1) && (runtime->format == SNDRV_PCM_FORMAT_U8)) {
					wmt_pcm_fmt_trans(runtime->format, runtime->channels,
						(unsigned char *)runtime->dma_buffer_p->area + offset,
						(unsigned char *)dump_buf[stream_id].area + (4 * offset),
						dma_size);
					ret = wmt_start_dma(s->dmach, dump_buf[stream_id].addr + 4 * offset, 0, (4 * dma_size));
				}
				else if ((runtime->channels == 2) && (runtime->format == SNDRV_PCM_FORMAT_FLOAT)) {
					wmt_pcm_fmt_trans(runtime->format, runtime->channels,
						(unsigned char *)runtime->dma_buffer_p->area + offset,
						(unsigned char *)dump_buf[stream_id].area + (offset / 2),
						dma_size);
					ret = wmt_start_dma(s->dmach, dump_buf[stream_id].addr + (offset / 2), 0, (dma_size / 2));
				}
				else if ((runtime->channels == 1) && (runtime->format == SNDRV_PCM_FORMAT_FLOAT)) {
					wmt_pcm_fmt_trans(runtime->format, runtime->channels,
						(unsigned char *)runtime->dma_buffer_p->area + offset,
						(unsigned char *)dump_buf[stream_id].area + offset,
						dma_size);
					ret = wmt_start_dma(s->dmach, dump_buf[stream_id].addr + offset, 0, dma_size);
				}
			}
		
			if (((runtime->channels == 2) || (runtime->channels == 6)) && (runtime->format == SNDRV_PCM_FORMAT_S16_LE)) {
				if ((stream_id == SNDRV_PCM_STREAM_PLAYBACK) && (wfd_audbuf.enable)) {
					wmt_pcm_wfd_update(runtime->dma_buffer_p->area + offset, dma_size);
				}
				ret = wmt_start_dma(s->dmach, runtime->dma_addr + offset, 0, dma_size);
			}
		}
#endif
#ifdef CONFIG_SND_WMT_SOC_AC97
		if (!strcmp(wmt_dai_name, "ac97")) {
			ret = wmt_start_dma(s->dmach, runtime->dma_addr + offset, 0, dma_size);
		}
#endif

		if (ret) {
			printk(KERN_ERR  "audio_process_dma: cannot queue DMA buffer (%i) \n", ret);
			return;
		}

		s->period++;
		s->period %= runtime->periods;
		s->periods++;
		s->offset = offset;
	}
}