Lines Matching +full:sub +full:- +full:frame

1 // SPDX-License-Identifier: GPL-2.0
5 // Copyright (c) 2017-2018 Socionext Inc.
9 #include <linux/dma-mapping.h>
26 struct snd_compr *compr = rtd->compr; in uniphier_aio_comprdma_new()
27 struct device *dev = compr->card->dev; in uniphier_aio_comprdma_new()
29 struct uniphier_aio_sub *sub = &aio->sub[compr->direction]; in uniphier_aio_comprdma_new() local
37 sub->compr_area = kzalloc(size, GFP_KERNEL); in uniphier_aio_comprdma_new()
38 if (!sub->compr_area) in uniphier_aio_comprdma_new()
39 return -ENOMEM; in uniphier_aio_comprdma_new()
41 if (sub->swm->dir == PORT_DIR_OUTPUT) in uniphier_aio_comprdma_new()
44 sub->compr_addr = dma_map_single(dev, sub->compr_area, size, dma_dir); in uniphier_aio_comprdma_new()
45 if (dma_mapping_error(dev, sub->compr_addr)) { in uniphier_aio_comprdma_new()
46 kfree(sub->compr_area); in uniphier_aio_comprdma_new()
47 sub->compr_area = NULL; in uniphier_aio_comprdma_new()
49 return -ENOMEM; in uniphier_aio_comprdma_new()
52 sub->compr_bytes = size; in uniphier_aio_comprdma_new()
59 struct snd_compr *compr = rtd->compr; in uniphier_aio_comprdma_free()
60 struct device *dev = compr->card->dev; in uniphier_aio_comprdma_free()
62 struct uniphier_aio_sub *sub = &aio->sub[compr->direction]; in uniphier_aio_comprdma_free() local
65 if (sub->swm->dir == PORT_DIR_OUTPUT) in uniphier_aio_comprdma_free()
68 dma_unmap_single(dev, sub->compr_addr, sub->compr_bytes, dma_dir); in uniphier_aio_comprdma_free()
69 kfree(sub->compr_area); in uniphier_aio_comprdma_free()
70 sub->compr_area = NULL; in uniphier_aio_comprdma_free()
78 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_open()
80 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_open() local
83 if (sub->cstream) in uniphier_aio_compr_open()
84 return -EBUSY; in uniphier_aio_compr_open()
86 sub->cstream = cstream; in uniphier_aio_compr_open()
87 sub->pass_through = 1; in uniphier_aio_compr_open()
88 sub->use_mmap = false; in uniphier_aio_compr_open()
94 ret = aio_init(sub); in uniphier_aio_compr_open()
104 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_free()
106 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_free() local
116 sub->cstream = NULL; in uniphier_aio_compr_free()
125 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_get_params()
127 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_get_params() local
129 *params = sub->cparams.codec; in uniphier_aio_compr_get_params()
138 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_set_params()
140 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_set_params() local
141 struct device *dev = &aio->chip->pdev->dev; in uniphier_aio_compr_set_params()
143 if (params->codec.id != SND_AUDIOCODEC_IEC61937) { in uniphier_aio_compr_set_params()
145 params->codec.id); in uniphier_aio_compr_set_params()
146 return -EINVAL; in uniphier_aio_compr_set_params()
148 if (params->codec.profile != SND_AUDIOPROFILE_IEC61937_SPDIF) { in uniphier_aio_compr_set_params()
150 params->codec.profile); in uniphier_aio_compr_set_params()
151 return -EINVAL; in uniphier_aio_compr_set_params()
154 /* IEC frame type will be changed after received valid data */ in uniphier_aio_compr_set_params()
155 sub->iec_pc = IEC61937_PC_AAC; in uniphier_aio_compr_set_params()
157 sub->cparams = *params; in uniphier_aio_compr_set_params()
158 sub->setting = 1; in uniphier_aio_compr_set_params()
160 aio_port_reset(sub); in uniphier_aio_compr_set_params()
161 aio_src_reset(sub); in uniphier_aio_compr_set_params()
169 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_hw_free()
171 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_hw_free() local
173 sub->setting = 0; in uniphier_aio_compr_hw_free()
181 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_prepare()
182 struct snd_compr_runtime *runtime = cstream->runtime; in uniphier_aio_compr_prepare()
184 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_prepare() local
185 int bytes = runtime->fragment_size; in uniphier_aio_compr_prepare()
189 ret = aiodma_ch_set_param(sub); in uniphier_aio_compr_prepare()
193 spin_lock_irqsave(&sub->lock, flags); in uniphier_aio_compr_prepare()
194 ret = aiodma_rb_set_buffer(sub, sub->compr_addr, in uniphier_aio_compr_prepare()
195 sub->compr_addr + sub->compr_bytes, in uniphier_aio_compr_prepare()
197 spin_unlock_irqrestore(&sub->lock, flags); in uniphier_aio_compr_prepare()
201 ret = aio_port_set_param(sub, sub->pass_through, &sub->params); in uniphier_aio_compr_prepare()
204 ret = aio_oport_set_stream_type(sub, sub->iec_pc); in uniphier_aio_compr_prepare()
207 aio_port_set_enable(sub, 1); in uniphier_aio_compr_prepare()
209 ret = aio_if_set_param(sub, sub->pass_through); in uniphier_aio_compr_prepare()
220 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_trigger()
221 struct snd_compr_runtime *runtime = cstream->runtime; in uniphier_aio_compr_trigger()
223 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_trigger() local
224 struct device *dev = &aio->chip->pdev->dev; in uniphier_aio_compr_trigger()
225 int bytes = runtime->fragment_size, ret = 0; in uniphier_aio_compr_trigger()
228 spin_lock_irqsave(&sub->lock, flags); in uniphier_aio_compr_trigger()
231 aiodma_rb_sync(sub, sub->compr_addr, sub->compr_bytes, bytes); in uniphier_aio_compr_trigger()
232 aiodma_ch_set_enable(sub, 1); in uniphier_aio_compr_trigger()
233 sub->running = 1; in uniphier_aio_compr_trigger()
237 sub->running = 0; in uniphier_aio_compr_trigger()
238 aiodma_ch_set_enable(sub, 0); in uniphier_aio_compr_trigger()
243 ret = -EINVAL; in uniphier_aio_compr_trigger()
245 spin_unlock_irqrestore(&sub->lock, flags); in uniphier_aio_compr_trigger()
254 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_pointer()
255 struct snd_compr_runtime *runtime = cstream->runtime; in uniphier_aio_compr_pointer()
257 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_pointer() local
258 int bytes = runtime->fragment_size; in uniphier_aio_compr_pointer()
262 spin_lock_irqsave(&sub->lock, flags); in uniphier_aio_compr_pointer()
264 aiodma_rb_sync(sub, sub->compr_addr, sub->compr_bytes, bytes); in uniphier_aio_compr_pointer()
266 if (sub->swm->dir == PORT_DIR_OUTPUT) { in uniphier_aio_compr_pointer()
267 pos = sub->rd_offs; in uniphier_aio_compr_pointer()
269 tstamp->copied_total = sub->rd_total / 2; in uniphier_aio_compr_pointer()
271 pos = sub->wr_offs; in uniphier_aio_compr_pointer()
272 tstamp->copied_total = sub->rd_total; in uniphier_aio_compr_pointer()
274 tstamp->byte_offset = pos; in uniphier_aio_compr_pointer()
276 spin_unlock_irqrestore(&sub->lock, flags); in uniphier_aio_compr_pointer()
281 static int aio_compr_send_to_hw(struct uniphier_aio_sub *sub, in aio_compr_send_to_hw() argument
285 u32 *dstbuf = (u32 *)(sub->compr_area + sub->wr_offs); in aio_compr_send_to_hw()
302 sub->iec_header = true; in aio_compr_send_to_hw()
306 if (sub->iec_header && sub->iec_pc != pc) { in aio_compr_send_to_hw()
307 /* Force overwrite IEC frame type */ in aio_compr_send_to_hw()
308 sub->iec_pc = pc; in aio_compr_send_to_hw()
309 ret = aio_oport_set_stream_type(sub, pc); in aio_compr_send_to_hw()
313 sub->iec_header = false; in aio_compr_send_to_hw()
318 dstsize -= sizeof(u32) * 2; in aio_compr_send_to_hw()
328 struct snd_soc_pcm_runtime *rtd = cstream->private_data; in uniphier_aio_compr_copy()
329 struct snd_compr_runtime *runtime = cstream->runtime; in uniphier_aio_compr_copy()
330 struct device *carddev = rtd->compr->card->dev; in uniphier_aio_compr_copy()
332 struct uniphier_aio_sub *sub = &aio->sub[cstream->direction]; in uniphier_aio_compr_copy() local
333 size_t cnt = min_t(size_t, count, aio_rb_space_to_end(sub) / 2); in uniphier_aio_compr_copy()
334 int bytes = runtime->fragment_size; in uniphier_aio_compr_copy()
342 if (sub->swm->dir == PORT_DIR_OUTPUT) { in uniphier_aio_compr_copy()
343 dma_addr_t dmapos = sub->compr_addr + sub->wr_offs; in uniphier_aio_compr_copy()
349 ret = aio_compr_send_to_hw(sub, buf, s); in uniphier_aio_compr_copy()
352 dma_addr_t dmapos = sub->compr_addr + sub->rd_offs; in uniphier_aio_compr_copy()
357 ret = copy_to_user(buf, sub->compr_area + sub->rd_offs, s); in uniphier_aio_compr_copy()
361 return -EFAULT; in uniphier_aio_compr_copy()
363 spin_lock_irqsave(&sub->lock, flags); in uniphier_aio_compr_copy()
365 sub->threshold = 2 * bytes; in uniphier_aio_compr_copy()
366 aiodma_rb_set_threshold(sub, sub->compr_bytes, 2 * bytes); in uniphier_aio_compr_copy()
368 if (sub->swm->dir == PORT_DIR_OUTPUT) { in uniphier_aio_compr_copy()
369 sub->wr_offs += s; in uniphier_aio_compr_copy()
370 if (sub->wr_offs >= sub->compr_bytes) in uniphier_aio_compr_copy()
371 sub->wr_offs -= sub->compr_bytes; in uniphier_aio_compr_copy()
373 sub->rd_offs += s; in uniphier_aio_compr_copy()
374 if (sub->rd_offs >= sub->compr_bytes) in uniphier_aio_compr_copy()
375 sub->rd_offs -= sub->compr_bytes; in uniphier_aio_compr_copy()
377 aiodma_rb_sync(sub, sub->compr_addr, sub->compr_bytes, bytes); in uniphier_aio_compr_copy()
379 spin_unlock_irqrestore(&sub->lock, flags); in uniphier_aio_compr_copy()
388 caps->num_codecs = 1; in uniphier_aio_compr_get_caps()
389 caps->min_fragment_size = AUD_MIN_FRAGMENT_SIZE; in uniphier_aio_compr_get_caps()
390 caps->max_fragment_size = AUD_MAX_FRAGMENT_SIZE; in uniphier_aio_compr_get_caps()
391 caps->min_fragments = AUD_MIN_FRAGMENT; in uniphier_aio_compr_get_caps()
392 caps->max_fragments = AUD_MAX_FRAGMENT; in uniphier_aio_compr_get_caps()
393 caps->codecs[0] = SND_AUDIOCODEC_IEC61937; in uniphier_aio_compr_get_caps()
415 if (codec->codec == SND_AUDIOCODEC_IEC61937) in uniphier_aio_compr_get_codec_caps()
418 return -EINVAL; in uniphier_aio_compr_get_codec_caps()