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)  * Driver for audio on multifunction CS5535 companion device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (C) Jaya Kumar
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Based on Jaroslav Kysela and Takashi Iwai's examples.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * This work was sponsored by CIS(M) Sdn Bhd.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * todo: add be fmt support, spdif, pm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/pci.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <sound/core.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <sound/control.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <sound/initval.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <sound/asoundef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <sound/pcm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <sound/pcm_params.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <sound/ac97_codec.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include "cs5535audio.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) static const struct snd_pcm_hardware snd_cs5535audio_playback =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 	.info =			(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 				SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 				SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 		 		SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 		 		SNDRV_PCM_INFO_MMAP_VALID |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 		 		SNDRV_PCM_INFO_PAUSE |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 				SNDRV_PCM_INFO_RESUME
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	.formats =		(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 				SNDRV_PCM_FMTBIT_S16_LE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	.rates =		(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 				SNDRV_PCM_RATE_CONTINUOUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 				SNDRV_PCM_RATE_8000_48000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	.rate_min =		4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	.channels_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	.buffer_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 	.period_bytes_min =	64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	.period_bytes_max =	(64*1024 - 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	.periods_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	.periods_max =		CS5535AUDIO_MAX_DESCRIPTORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static const struct snd_pcm_hardware snd_cs5535audio_capture =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	.info =			(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 				SNDRV_PCM_INFO_MMAP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				SNDRV_PCM_INFO_INTERLEAVED |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		 		SNDRV_PCM_INFO_BLOCK_TRANSFER |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		 		SNDRV_PCM_INFO_MMAP_VALID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	.formats =		(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 				SNDRV_PCM_FMTBIT_S16_LE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	.rates =		(
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 				SNDRV_PCM_RATE_CONTINUOUS |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 				SNDRV_PCM_RATE_8000_48000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 				),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	.rate_min =		4000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	.rate_max =		48000,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	.channels_min =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	.channels_max =		2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	.buffer_bytes_max =	(128*1024),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	.period_bytes_min =	64,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	.period_bytes_max =	(64*1024 - 16),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	.periods_min =		1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	.periods_max =		CS5535AUDIO_MAX_DESCRIPTORS,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	.fifo_size =		0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) static int snd_cs5535audio_playback_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	runtime->hw = snd_cs5535audio_playback;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_FRONT_DAC];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	snd_pcm_limit_hw_rates(runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	cs5535au->playback_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	if ((err = snd_pcm_hw_constraint_integer(runtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 				SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static int snd_cs5535audio_playback_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) #define CS5535AUDIO_DESC_LIST_SIZE \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	PAGE_ALIGN(CS5535AUDIO_MAX_DESCRIPTORS * sizeof(struct cs5535audio_dma_desc))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static int cs5535audio_build_dma_packets(struct cs5535audio *cs5535au,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 					 struct cs5535audio_dma *dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 					 struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 					 unsigned int periods,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 					 unsigned int period_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	u32 addr, desc_addr, jmpprd_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	struct cs5535audio_dma_desc *lastdesc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (periods > CS5535AUDIO_MAX_DESCRIPTORS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (dma->desc_buf.area == NULL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		if (snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 					&cs5535au->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 					CS5535AUDIO_DESC_LIST_SIZE+1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 					&dma->desc_buf) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 			return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		dma->period_bytes = dma->periods = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	if (dma->periods == periods && dma->period_bytes == period_bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	/* the u32 cast is okay because in snd*create we successfully told
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)    	   pci alloc that we're only 32 bit capable so the uppper will be 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	addr = (u32) substream->runtime->dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	desc_addr = (u32) dma->desc_buf.addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	for (i = 0; i < periods; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 		struct cs5535audio_dma_desc *desc =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 			&((struct cs5535audio_dma_desc *) dma->desc_buf.area)[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 		desc->addr = cpu_to_le32(addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		desc->size = cpu_to_le16(period_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		desc->ctlreserved = cpu_to_le16(PRD_EOP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 		desc_addr += sizeof(struct cs5535audio_dma_desc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		addr += period_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	/* we reserved one dummy descriptor at the end to do the PRD jump */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	lastdesc = &((struct cs5535audio_dma_desc *) dma->desc_buf.area)[periods];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	lastdesc->addr = cpu_to_le32((u32) dma->desc_buf.addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	lastdesc->size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	lastdesc->ctlreserved = cpu_to_le16(PRD_JMP);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	jmpprd_addr = (u32)dma->desc_buf.addr +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 		sizeof(struct cs5535audio_dma_desc) * periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	dma->substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	dma->period_bytes = period_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	dma->periods = periods;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	spin_lock_irq(&cs5535au->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	dma->ops->disable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	dma->ops->setup_prd(cs5535au, jmpprd_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	spin_unlock_irq(&cs5535au->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static void cs5535audio_playback_enable_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_EN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) static void cs5535audio_playback_disable_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	cs_writeb(cs5535au, ACC_BM0_CMD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) static void cs5535audio_playback_pause_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	cs_writeb(cs5535au, ACC_BM0_CMD, BM_CTL_PAUSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) static void cs5535audio_playback_setup_prd(struct cs5535audio *cs5535au,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 					   u32 prd_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	cs_writel(cs5535au, ACC_BM0_PRD, prd_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) static u32 cs5535audio_playback_read_prd(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	return cs_readl(cs5535au, ACC_BM0_PRD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static u32 cs5535audio_playback_read_dma_pntr(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	return cs_readl(cs5535au, ACC_BM0_PNTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) static void cs5535audio_capture_enable_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_EN);
^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 void cs5535audio_capture_disable_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	cs_writeb(cs5535au, ACC_BM1_CMD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static void cs5535audio_capture_pause_dma(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	cs_writeb(cs5535au, ACC_BM1_CMD, BM_CTL_PAUSE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) static void cs5535audio_capture_setup_prd(struct cs5535audio *cs5535au,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 					  u32 prd_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	cs_writel(cs5535au, ACC_BM1_PRD, prd_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static u32 cs5535audio_capture_read_prd(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	return cs_readl(cs5535au, ACC_BM1_PRD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) static u32 cs5535audio_capture_read_dma_pntr(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	return cs_readl(cs5535au, ACC_BM1_PNTR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static void cs5535audio_clear_dma_packets(struct cs5535audio *cs5535au,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 					  struct cs5535audio_dma *dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 					  struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	snd_dma_free_pages(&dma->desc_buf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	dma->desc_buf.area = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	dma->substream = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) static int snd_cs5535audio_hw_params(struct snd_pcm_substream *substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 				     struct snd_pcm_hw_params *hw_params)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct cs5535audio_dma *dma = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	dma->buf_addr = substream->runtime->dma_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	dma->buf_bytes = params_buffer_bytes(hw_params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	err = cs5535audio_build_dma_packets(cs5535au, dma, substream,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 					    params_periods(hw_params),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 					    params_period_bytes(hw_params));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		dma->pcm_open_flag = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	return err;
^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) static int snd_cs5535audio_hw_free(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	struct cs5535audio_dma *dma = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (dma->pcm_open_flag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		if (substream == cs5535au->playback_substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 			snd_ac97_update_power(cs5535au->ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 					AC97_PCM_FRONT_DAC_RATE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 			snd_ac97_update_power(cs5535au->ac97,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 					AC97_PCM_LR_ADC_RATE, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		dma->pcm_open_flag = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	cs5535audio_clear_dma_packets(cs5535au, dma, substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) static int snd_cs5535audio_playback_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_FRONT_DAC_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 				 substream->runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static int snd_cs5535audio_trigger(struct snd_pcm_substream *substream, int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	struct cs5535audio_dma *dma = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	spin_lock(&cs5535au->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		dma->ops->pause_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 		dma->ops->enable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	case SNDRV_PCM_TRIGGER_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		dma->ops->enable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	case SNDRV_PCM_TRIGGER_RESUME:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		dma->ops->enable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	case SNDRV_PCM_TRIGGER_STOP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		dma->ops->disable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	case SNDRV_PCM_TRIGGER_SUSPEND:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 		dma->ops->disable_dma(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		dev_err(cs5535au->card->dev, "unhandled trigger\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		err = -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	spin_unlock(&cs5535au->reg_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) static snd_pcm_uframes_t snd_cs5535audio_pcm_pointer(struct snd_pcm_substream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 							*substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	u32 curdma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	struct cs5535audio_dma *dma;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 	dma = substream->runtime->private_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	curdma = dma->ops->read_dma_pntr(cs5535au);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 	if (curdma < dma->buf_addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		dev_err(cs5535au->card->dev, "curdma=%x < %x bufaddr.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 					curdma, dma->buf_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	curdma -= dma->buf_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 	if (curdma >= dma->buf_bytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 		dev_err(cs5535au->card->dev, "diff=%x >= %x buf_bytes.\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 					curdma, dma->buf_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return bytes_to_frames(substream->runtime, curdma);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) static int snd_cs5535audio_capture_open(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 	struct snd_pcm_runtime *runtime = substream->runtime;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	runtime->hw = snd_cs5535audio_capture;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 	runtime->hw.rates = cs5535au->ac97->rates[AC97_RATES_ADC];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	snd_pcm_limit_hw_rates(runtime);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 	cs5535au->capture_substream = substream;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	runtime->private_data = &(cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	if ((err = snd_pcm_hw_constraint_integer(runtime,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 					 SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 	olpc_capture_open(cs5535au->ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) static int snd_cs5535audio_capture_close(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	olpc_capture_close(cs5535au->ac97);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) static int snd_cs5535audio_capture_prepare(struct snd_pcm_substream *substream)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) 	struct cs5535audio *cs5535au = snd_pcm_substream_chip(substream);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) 	return snd_ac97_set_rate(cs5535au->ac97, AC97_PCM_LR_ADC_RATE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) 				 substream->runtime->rate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) static const struct snd_pcm_ops snd_cs5535audio_playback_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 	.open =		snd_cs5535audio_playback_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 	.close =	snd_cs5535audio_playback_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	.hw_params =	snd_cs5535audio_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	.hw_free =	snd_cs5535audio_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 	.prepare =	snd_cs5535audio_playback_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 	.trigger =	snd_cs5535audio_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	.pointer =	snd_cs5535audio_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) static const struct snd_pcm_ops snd_cs5535audio_capture_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	.open =		snd_cs5535audio_capture_open,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	.close =	snd_cs5535audio_capture_close,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	.hw_params =	snd_cs5535audio_hw_params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	.hw_free =	snd_cs5535audio_hw_free,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 	.prepare =	snd_cs5535audio_capture_prepare,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	.trigger =	snd_cs5535audio_trigger,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	.pointer =	snd_cs5535audio_pcm_pointer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) static const struct cs5535audio_dma_ops snd_cs5535audio_playback_dma_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387)         .type = CS5535AUDIO_DMA_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)         .enable_dma = cs5535audio_playback_enable_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389)         .disable_dma = cs5535audio_playback_disable_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390)         .setup_prd = cs5535audio_playback_setup_prd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391)         .read_prd = cs5535audio_playback_read_prd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)         .pause_dma = cs5535audio_playback_pause_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393)         .read_dma_pntr = cs5535audio_playback_read_dma_pntr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) static const struct cs5535audio_dma_ops snd_cs5535audio_capture_dma_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397)         .type = CS5535AUDIO_DMA_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)         .enable_dma = cs5535audio_capture_enable_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399)         .disable_dma = cs5535audio_capture_disable_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)         .setup_prd = cs5535audio_capture_setup_prd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)         .read_prd = cs5535audio_capture_read_prd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)         .pause_dma = cs5535audio_capture_pause_dma,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)         .read_dma_pntr = cs5535audio_capture_read_dma_pntr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) int snd_cs5535audio_pcm(struct cs5535audio *cs5535au)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	struct snd_pcm *pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) 	err = snd_pcm_new(cs5535au->card, "CS5535 Audio", 0, 1, 1, &pcm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 	cs5535au->dmas[CS5535AUDIO_DMA_PLAYBACK].ops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) 					&snd_cs5535audio_playback_dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) 	cs5535au->dmas[CS5535AUDIO_DMA_CAPTURE].ops =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 					&snd_cs5535audio_capture_dma_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 					&snd_cs5535audio_playback_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 	snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 					&snd_cs5535audio_capture_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 	pcm->private_data = cs5535au;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 	pcm->info_flags = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	strcpy(pcm->name, "CS5535 Audio");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 	snd_pcm_set_managed_buffer_all(pcm, SNDRV_DMA_TYPE_DEV,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 				       &cs5535au->pci->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 				       64*1024, 128*1024);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 	cs5535au->pcm = pcm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435)