Lines Matching +full:ssc +full:- +full:on

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * atmel-pcm.c -- ALSA PCM interface for the Atmel atmel SoC.
10 * Based on at91-pcm. by:
14 * Based on pxa2xx-pcm.c by:
25 #include <linux/dma-mapping.h>
27 #include <linux/atmel-ssc.h>
34 #include "atmel-pcm.h"
40 struct snd_card *card = rtd->card->snd_card; in atmel_pcm_new()
43 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); in atmel_pcm_new()
47 snd_pcm_set_managed_buffer_all(rtd->pcm, SNDRV_DMA_TYPE_DEV, in atmel_pcm_new()
48 card->dev, ATMEL_SSC_DMABUF_SIZE, in atmel_pcm_new()
54 /*--------------------------------------------------------------------------*\
56 \*--------------------------------------------------------------------------*/
73 /*--------------------------------------------------------------------------*\
75 \*--------------------------------------------------------------------------*/
85 /*--------------------------------------------------------------------------*\
87 \*--------------------------------------------------------------------------*/
91 struct atmel_runtime_data *prtd = substream->runtime->private_data; in atmel_pcm_dma_irq()
92 struct atmel_pcm_dma_params *params = prtd->params; in atmel_pcm_dma_irq()
97 if (ssc_sr & params->mask->ssc_endbuf) { in atmel_pcm_dma_irq()
98 pr_warn("atmel-pcm: buffer %s on %s (SSC_SR=%#x, count=%d)\n", in atmel_pcm_dma_irq()
99 substream->stream == SNDRV_PCM_STREAM_PLAYBACK in atmel_pcm_dma_irq()
101 params->name, ssc_sr, count); in atmel_pcm_dma_irq()
103 /* re-start the PDC */ in atmel_pcm_dma_irq()
104 ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR, in atmel_pcm_dma_irq()
105 params->mask->pdc_disable); in atmel_pcm_dma_irq()
106 prtd->period_ptr += prtd->period_size; in atmel_pcm_dma_irq()
107 if (prtd->period_ptr >= prtd->dma_buffer_end) in atmel_pcm_dma_irq()
108 prtd->period_ptr = prtd->dma_buffer; in atmel_pcm_dma_irq()
110 ssc_writex(params->ssc->regs, params->pdc->xpr, in atmel_pcm_dma_irq()
111 prtd->period_ptr); in atmel_pcm_dma_irq()
112 ssc_writex(params->ssc->regs, params->pdc->xcr, in atmel_pcm_dma_irq()
113 prtd->period_size / params->pdc_xfer_size); in atmel_pcm_dma_irq()
114 ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR, in atmel_pcm_dma_irq()
115 params->mask->pdc_enable); in atmel_pcm_dma_irq()
118 if (ssc_sr & params->mask->ssc_endx) { in atmel_pcm_dma_irq()
120 prtd->period_ptr += prtd->period_size; in atmel_pcm_dma_irq()
121 if (prtd->period_ptr >= prtd->dma_buffer_end) in atmel_pcm_dma_irq()
122 prtd->period_ptr = prtd->dma_buffer; in atmel_pcm_dma_irq()
124 ssc_writex(params->ssc->regs, params->pdc->xnpr, in atmel_pcm_dma_irq()
125 prtd->period_ptr); in atmel_pcm_dma_irq()
126 ssc_writex(params->ssc->regs, params->pdc->xncr, in atmel_pcm_dma_irq()
127 prtd->period_size / params->pdc_xfer_size); in atmel_pcm_dma_irq()
134 /*--------------------------------------------------------------------------*\
136 \*--------------------------------------------------------------------------*/
141 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_pcm_hw_params()
142 struct atmel_runtime_data *prtd = runtime->private_data; in atmel_pcm_hw_params()
148 prtd->params = snd_soc_dai_get_dma_data(snd_soc_rtd_to_cpu(rtd, 0), substream); in atmel_pcm_hw_params()
149 prtd->params->dma_intr_handler = atmel_pcm_dma_irq; in atmel_pcm_hw_params()
151 prtd->dma_buffer = runtime->dma_addr; in atmel_pcm_hw_params()
152 prtd->dma_buffer_end = runtime->dma_addr + runtime->dma_bytes; in atmel_pcm_hw_params()
153 prtd->period_size = params_period_bytes(params); in atmel_pcm_hw_params()
155 pr_debug("atmel-pcm: " in atmel_pcm_hw_params()
158 prtd->params->name, in atmel_pcm_hw_params()
159 runtime->dma_bytes, in atmel_pcm_hw_params()
160 prtd->period_size); in atmel_pcm_hw_params()
167 struct atmel_runtime_data *prtd = substream->runtime->private_data; in atmel_pcm_hw_free()
168 struct atmel_pcm_dma_params *params = prtd->params; in atmel_pcm_hw_free()
171 ssc_writex(params->ssc->regs, SSC_PDC_PTCR, in atmel_pcm_hw_free()
172 params->mask->pdc_disable); in atmel_pcm_hw_free()
173 prtd->params->dma_intr_handler = NULL; in atmel_pcm_hw_free()
182 struct atmel_runtime_data *prtd = substream->runtime->private_data; in atmel_pcm_prepare()
183 struct atmel_pcm_dma_params *params = prtd->params; in atmel_pcm_prepare()
185 ssc_writex(params->ssc->regs, SSC_IDR, in atmel_pcm_prepare()
186 params->mask->ssc_endx | params->mask->ssc_endbuf); in atmel_pcm_prepare()
187 ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR, in atmel_pcm_prepare()
188 params->mask->pdc_disable); in atmel_pcm_prepare()
195 struct snd_pcm_runtime *rtd = substream->runtime; in atmel_pcm_trigger()
196 struct atmel_runtime_data *prtd = rtd->private_data; in atmel_pcm_trigger()
197 struct atmel_pcm_dma_params *params = prtd->params; in atmel_pcm_trigger()
200 pr_debug("atmel-pcm:buffer_size = %ld," in atmel_pcm_trigger()
202 rtd->buffer_size, rtd->dma_area, rtd->dma_bytes); in atmel_pcm_trigger()
206 prtd->period_ptr = prtd->dma_buffer; in atmel_pcm_trigger()
208 ssc_writex(params->ssc->regs, params->pdc->xpr, in atmel_pcm_trigger()
209 prtd->period_ptr); in atmel_pcm_trigger()
210 ssc_writex(params->ssc->regs, params->pdc->xcr, in atmel_pcm_trigger()
211 prtd->period_size / params->pdc_xfer_size); in atmel_pcm_trigger()
213 prtd->period_ptr += prtd->period_size; in atmel_pcm_trigger()
214 ssc_writex(params->ssc->regs, params->pdc->xnpr, in atmel_pcm_trigger()
215 prtd->period_ptr); in atmel_pcm_trigger()
216 ssc_writex(params->ssc->regs, params->pdc->xncr, in atmel_pcm_trigger()
217 prtd->period_size / params->pdc_xfer_size); in atmel_pcm_trigger()
219 pr_debug("atmel-pcm: trigger: " in atmel_pcm_trigger()
222 (unsigned long)prtd->period_ptr, in atmel_pcm_trigger()
223 ssc_readx(params->ssc->regs, params->pdc->xpr), in atmel_pcm_trigger()
224 ssc_readx(params->ssc->regs, params->pdc->xcr), in atmel_pcm_trigger()
225 ssc_readx(params->ssc->regs, params->pdc->xnpr), in atmel_pcm_trigger()
226 ssc_readx(params->ssc->regs, params->pdc->xncr)); in atmel_pcm_trigger()
228 ssc_writex(params->ssc->regs, SSC_IER, in atmel_pcm_trigger()
229 params->mask->ssc_endx | params->mask->ssc_endbuf); in atmel_pcm_trigger()
230 ssc_writex(params->ssc->regs, SSC_PDC_PTCR, in atmel_pcm_trigger()
231 params->mask->pdc_enable); in atmel_pcm_trigger()
234 ssc_readx(params->ssc->regs, SSC_SR), in atmel_pcm_trigger()
235 ssc_readx(params->ssc->regs, SSC_IER)); in atmel_pcm_trigger()
241 ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR, in atmel_pcm_trigger()
242 params->mask->pdc_disable); in atmel_pcm_trigger()
247 ssc_writex(params->ssc->regs, ATMEL_PDC_PTCR, in atmel_pcm_trigger()
248 params->mask->pdc_enable); in atmel_pcm_trigger()
252 ret = -EINVAL; in atmel_pcm_trigger()
261 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_pcm_pointer()
262 struct atmel_runtime_data *prtd = runtime->private_data; in atmel_pcm_pointer()
263 struct atmel_pcm_dma_params *params = prtd->params; in atmel_pcm_pointer()
267 ptr = (dma_addr_t) ssc_readx(params->ssc->regs, params->pdc->xpr); in atmel_pcm_pointer()
268 x = bytes_to_frames(runtime, ptr - prtd->dma_buffer); in atmel_pcm_pointer()
270 if (x == runtime->buffer_size) in atmel_pcm_pointer()
279 struct snd_pcm_runtime *runtime = substream->runtime; in atmel_pcm_open()
293 ret = -ENOMEM; in atmel_pcm_open()
296 runtime->private_data = prtd; in atmel_pcm_open()
305 struct atmel_runtime_data *prtd = substream->runtime->private_data; in atmel_pcm_close()