1 From a20f54fdd500e5bccc9bd1ca4ac9f150addf2e64 Mon Sep 17 00:00:00 2001
2 From: Lars-Peter Clausen <lars@metafoo.de>
3 Date: Sat, 27 Apr 2013 21:26:30 +0200
4 Subject: [PATCH 16/16] ASoC: jz4740: Use the generic dmaengine PCM driver
6 Since there is a dmaengine driver for the jz4740 DMA controller now we can use
7 the generic dmaengine PCM driver instead of a custom one.
9 Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
10 Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
12 sound/soc/jz4740/Kconfig | 1 +
13 sound/soc/jz4740/jz4740-i2s.c | 48 +++----
14 sound/soc/jz4740/jz4740-pcm.c | 310 ++---------------------------------------
15 sound/soc/jz4740/jz4740-pcm.h | 20 ---
16 4 files changed, 27 insertions(+), 352 deletions(-)
17 delete mode 100644 sound/soc/jz4740/jz4740-pcm.h
19 --- a/sound/soc/jz4740/Kconfig
20 +++ b/sound/soc/jz4740/Kconfig
23 tristate "SoC Audio for Ingenic JZ4740 SoC"
24 depends on MACH_JZ4740 && SND_SOC
25 + select SND_SOC_GENERIC_DMAENGINE_PCM
27 Say Y or M if you want to add support for codecs attached to
28 the JZ4740 I2S interface. You will also need to select the audio
29 --- a/sound/soc/jz4740/jz4740-i2s.c
30 +++ b/sound/soc/jz4740/jz4740-i2s.c
32 #include <sound/pcm_params.h>
33 #include <sound/soc.h>
34 #include <sound/initval.h>
35 +#include <sound/dmaengine_pcm.h>
37 +#include <asm/mach-jz4740/dma.h>
39 #include "jz4740-i2s.h"
40 -#include "jz4740-pcm.h"
43 #define JZ_REG_AIC_CONF 0x00
44 #define JZ_REG_AIC_CTRL 0x04
45 @@ -89,8 +92,8 @@ struct jz4740_i2s {
49 - struct jz4740_pcm_config pcm_config_playback;
50 - struct jz4740_pcm_config pcm_config_capture;
51 + struct snd_dmaengine_dai_dma_data playback_dma_data;
52 + struct snd_dmaengine_dai_dma_data capture_dma_data;
55 static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s,
56 @@ -233,8 +236,6 @@ static int jz4740_i2s_hw_params(struct s
57 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
59 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
60 - enum jz4740_dma_width dma_width;
61 - struct jz4740_pcm_config *pcm_config;
62 unsigned int sample_size;
65 @@ -243,11 +244,9 @@ static int jz4740_i2s_hw_params(struct s
66 switch (params_format(params)) {
67 case SNDRV_PCM_FORMAT_S8:
69 - dma_width = JZ4740_DMA_WIDTH_8BIT;
71 case SNDRV_PCM_FORMAT_S16:
73 - dma_width = JZ4740_DMA_WIDTH_16BIT;
77 @@ -260,22 +259,13 @@ static int jz4740_i2s_hw_params(struct s
78 ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO;
80 ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO;
82 - pcm_config = &i2s->pcm_config_playback;
83 - pcm_config->dma_config.dst_width = dma_width;
86 ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK;
87 ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET;
89 - pcm_config = &i2s->pcm_config_capture;
90 - pcm_config->dma_config.src_width = dma_width;
93 jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);
95 - snd_soc_dai_set_dma_data(dai, substream, pcm_config);
100 @@ -342,25 +332,19 @@ static int jz4740_i2s_resume(struct snd_
102 static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
104 - struct jz4740_dma_config *dma_config;
105 + struct snd_dmaengine_dai_dma_data *dma_data;
108 - dma_config = &i2s->pcm_config_playback.dma_config;
109 - dma_config->src_width = JZ4740_DMA_WIDTH_32BIT;
110 - dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
111 - dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT;
112 - dma_config->flags = JZ4740_DMA_SRC_AUTOINC;
113 - dma_config->mode = JZ4740_DMA_MODE_SINGLE;
114 - i2s->pcm_config_playback.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
115 + dma_data = &i2s->playback_dma_data;
116 + dma_data->maxburst = 16;
117 + dma_data->slave_id = JZ4740_DMA_TYPE_AIC_TRANSMIT;
118 + dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
121 - dma_config = &i2s->pcm_config_capture.dma_config;
122 - dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT;
123 - dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
124 - dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE;
125 - dma_config->flags = JZ4740_DMA_DST_AUTOINC;
126 - dma_config->mode = JZ4740_DMA_MODE_SINGLE;
127 - i2s->pcm_config_capture.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
128 + dma_data = &i2s->capture_dma_data;
129 + dma_data->maxburst = 16;
130 + dma_data->slave_id = JZ4740_DMA_TYPE_AIC_RECEIVE;
131 + dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
134 static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
135 @@ -371,6 +355,8 @@ static int jz4740_i2s_dai_probe(struct s
136 clk_enable(i2s->clk_aic);
138 jz4740_i2c_init_pcm_config(i2s);
139 + dai->playback_dma_data = &i2s->playback_dma_data;
140 + dai->capture_dma_data = &i2s->capture_dma_data;
142 conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
143 (8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
144 --- a/sound/soc/jz4740/jz4740-pcm.c
145 +++ b/sound/soc/jz4740/jz4740-pcm.c
147 #include <linux/platform_device.h>
148 #include <linux/slab.h>
150 -#include <linux/dma-mapping.h>
151 +#include <sound/dmaengine_pcm.h>
153 -#include <sound/core.h>
154 -#include <sound/pcm.h>
155 -#include <sound/pcm_params.h>
156 -#include <sound/soc.h>
158 -#include <asm/mach-jz4740/dma.h>
159 -#include "jz4740-pcm.h"
161 -struct jz4740_runtime_data {
162 - unsigned long dma_period;
163 - dma_addr_t dma_start;
164 - dma_addr_t dma_pos;
165 - dma_addr_t dma_end;
167 - struct jz4740_dma_chan *dma;
169 - dma_addr_t fifo_addr;
172 -/* identify hardware playback capabilities */
173 static const struct snd_pcm_hardware jz4740_pcm_hardware = {
174 .info = SNDRV_PCM_INFO_MMAP |
175 SNDRV_PCM_INFO_MMAP_VALID |
176 SNDRV_PCM_INFO_INTERLEAVED |
177 SNDRV_PCM_INFO_BLOCK_TRANSFER,
178 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
180 - .rates = SNDRV_PCM_RATE_8000_48000,
183 .period_bytes_min = 16,
184 .period_bytes_max = 2 * PAGE_SIZE,
186 @@ -59,290 +35,22 @@ static const struct snd_pcm_hardware jz4
190 -static void jz4740_pcm_start_transfer(struct jz4740_runtime_data *prtd,
191 - struct snd_pcm_substream *substream)
193 - unsigned long count;
195 - if (prtd->dma_pos == prtd->dma_end)
196 - prtd->dma_pos = prtd->dma_start;
198 - if (prtd->dma_pos + prtd->dma_period > prtd->dma_end)
199 - count = prtd->dma_end - prtd->dma_pos;
201 - count = prtd->dma_period;
203 - jz4740_dma_disable(prtd->dma);
205 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
206 - jz4740_dma_set_src_addr(prtd->dma, prtd->dma_pos);
207 - jz4740_dma_set_dst_addr(prtd->dma, prtd->fifo_addr);
209 - jz4740_dma_set_src_addr(prtd->dma, prtd->fifo_addr);
210 - jz4740_dma_set_dst_addr(prtd->dma, prtd->dma_pos);
213 - jz4740_dma_set_transfer_count(prtd->dma, count);
215 - prtd->dma_pos += count;
217 - jz4740_dma_enable(prtd->dma);
220 -static void jz4740_pcm_dma_transfer_done(struct jz4740_dma_chan *dma, int err,
223 - struct snd_pcm_substream *substream = dev_id;
224 - struct snd_pcm_runtime *runtime = substream->runtime;
225 - struct jz4740_runtime_data *prtd = runtime->private_data;
227 - snd_pcm_period_elapsed(substream);
229 - jz4740_pcm_start_transfer(prtd, substream);
232 -static int jz4740_pcm_hw_params(struct snd_pcm_substream *substream,
233 - struct snd_pcm_hw_params *params)
235 - struct snd_pcm_runtime *runtime = substream->runtime;
236 - struct jz4740_runtime_data *prtd = runtime->private_data;
237 - struct snd_soc_pcm_runtime *rtd = substream->private_data;
238 - struct jz4740_pcm_config *config;
240 - config = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
246 - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
247 - prtd->dma = jz4740_dma_request(substream, "PCM Capture");
249 - prtd->dma = jz4740_dma_request(substream, "PCM Playback");
255 - jz4740_dma_configure(prtd->dma, &config->dma_config);
256 - prtd->fifo_addr = config->fifo_addr;
258 - jz4740_dma_set_complete_cb(prtd->dma, jz4740_pcm_dma_transfer_done);
260 - snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
261 - runtime->dma_bytes = params_buffer_bytes(params);
263 - prtd->dma_period = params_period_bytes(params);
264 - prtd->dma_start = runtime->dma_addr;
265 - prtd->dma_pos = prtd->dma_start;
266 - prtd->dma_end = prtd->dma_start + runtime->dma_bytes;
271 -static int jz4740_pcm_hw_free(struct snd_pcm_substream *substream)
273 - struct jz4740_runtime_data *prtd = substream->runtime->private_data;
275 - snd_pcm_set_runtime_buffer(substream, NULL);
277 - jz4740_dma_free(prtd->dma);
284 -static int jz4740_pcm_prepare(struct snd_pcm_substream *substream)
286 - struct jz4740_runtime_data *prtd = substream->runtime->private_data;
291 - prtd->dma_pos = prtd->dma_start;
296 -static int jz4740_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
298 - struct snd_pcm_runtime *runtime = substream->runtime;
299 - struct jz4740_runtime_data *prtd = runtime->private_data;
302 - case SNDRV_PCM_TRIGGER_START:
303 - case SNDRV_PCM_TRIGGER_RESUME:
304 - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
305 - jz4740_pcm_start_transfer(prtd, substream);
307 - case SNDRV_PCM_TRIGGER_STOP:
308 - case SNDRV_PCM_TRIGGER_SUSPEND:
309 - case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
310 - jz4740_dma_disable(prtd->dma);
319 -static snd_pcm_uframes_t jz4740_pcm_pointer(struct snd_pcm_substream *substream)
321 - struct snd_pcm_runtime *runtime = substream->runtime;
322 - struct jz4740_runtime_data *prtd = runtime->private_data;
323 - unsigned long byte_offset;
324 - snd_pcm_uframes_t offset;
325 - struct jz4740_dma_chan *dma = prtd->dma;
327 - /* prtd->dma_pos points to the end of the current transfer. So by
328 - * subtracting prdt->dma_start we get the offset to the end of the
329 - * current period in bytes. By subtracting the residue of the transfer
330 - * we get the current offset in bytes. */
331 - byte_offset = prtd->dma_pos - prtd->dma_start;
332 - byte_offset -= jz4740_dma_get_residue(dma);
334 - offset = bytes_to_frames(runtime, byte_offset);
335 - if (offset >= runtime->buffer_size)
341 -static int jz4740_pcm_open(struct snd_pcm_substream *substream)
343 - struct snd_pcm_runtime *runtime = substream->runtime;
344 - struct jz4740_runtime_data *prtd;
346 - prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
350 - snd_soc_set_runtime_hwparams(substream, &jz4740_pcm_hardware);
352 - runtime->private_data = prtd;
357 -static int jz4740_pcm_close(struct snd_pcm_substream *substream)
359 - struct snd_pcm_runtime *runtime = substream->runtime;
360 - struct jz4740_runtime_data *prtd = runtime->private_data;
367 -static int jz4740_pcm_mmap(struct snd_pcm_substream *substream,
368 - struct vm_area_struct *vma)
370 - return remap_pfn_range(vma, vma->vm_start,
371 - substream->dma_buffer.addr >> PAGE_SHIFT,
372 - vma->vm_end - vma->vm_start, vma->vm_page_prot);
375 -static struct snd_pcm_ops jz4740_pcm_ops = {
376 - .open = jz4740_pcm_open,
377 - .close = jz4740_pcm_close,
378 - .ioctl = snd_pcm_lib_ioctl,
379 - .hw_params = jz4740_pcm_hw_params,
380 - .hw_free = jz4740_pcm_hw_free,
381 - .prepare = jz4740_pcm_prepare,
382 - .trigger = jz4740_pcm_trigger,
383 - .pointer = jz4740_pcm_pointer,
384 - .mmap = jz4740_pcm_mmap,
387 -static int jz4740_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
389 - struct snd_pcm_substream *substream = pcm->streams[stream].substream;
390 - struct snd_dma_buffer *buf = &substream->dma_buffer;
391 - size_t size = jz4740_pcm_hardware.buffer_bytes_max;
393 - buf->dev.type = SNDRV_DMA_TYPE_DEV;
394 - buf->dev.dev = pcm->card->dev;
395 - buf->private_data = NULL;
397 - buf->area = dma_alloc_noncoherent(pcm->card->dev, size,
398 - &buf->addr, GFP_KERNEL);
407 -static void jz4740_pcm_free(struct snd_pcm *pcm)
409 - struct snd_pcm_substream *substream;
410 - struct snd_dma_buffer *buf;
413 - for (stream = 0; stream < SNDRV_PCM_STREAM_LAST; ++stream) {
414 - substream = pcm->streams[stream].substream;
418 - buf = &substream->dma_buffer;
422 - dma_free_noncoherent(pcm->card->dev, buf->bytes, buf->area,
428 -static u64 jz4740_pcm_dmamask = DMA_BIT_MASK(32);
430 -static int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd)
432 - struct snd_card *card = rtd->card->snd_card;
433 - struct snd_pcm *pcm = rtd->pcm;
436 - if (!card->dev->dma_mask)
437 - card->dev->dma_mask = &jz4740_pcm_dmamask;
439 - if (!card->dev->coherent_dma_mask)
440 - card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
442 - if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
443 - ret = jz4740_pcm_preallocate_dma_buffer(pcm,
444 - SNDRV_PCM_STREAM_PLAYBACK);
449 - if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
450 - ret = jz4740_pcm_preallocate_dma_buffer(pcm,
451 - SNDRV_PCM_STREAM_CAPTURE);
460 -static struct snd_soc_platform_driver jz4740_soc_platform = {
461 - .ops = &jz4740_pcm_ops,
462 - .pcm_new = jz4740_pcm_new,
463 - .pcm_free = jz4740_pcm_free,
464 +static const struct snd_dmaengine_pcm_config jz4740_dmaengine_pcm_config = {
465 + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
466 + .pcm_hardware = &jz4740_pcm_hardware,
467 + .prealloc_buffer_size = 256 * PAGE_SIZE,
470 static int jz4740_pcm_probe(struct platform_device *pdev)
472 - return snd_soc_register_platform(&pdev->dev, &jz4740_soc_platform);
473 + return snd_dmaengine_pcm_register(&pdev->dev,
474 + &jz4740_dmaengine_pcm_config,
475 + SND_DMAENGINE_PCM_FLAG_COMPAT);
478 static int jz4740_pcm_remove(struct platform_device *pdev)
480 - snd_soc_unregister_platform(&pdev->dev);
481 + snd_dmaengine_pcm_unregister(&pdev->dev);
485 --- a/sound/soc/jz4740/jz4740-pcm.h
490 - * This program is free software; you can redistribute it and/or modify
491 - * it under the terms of the GNU General Public License version 2 as
492 - * published by the Free Software Foundation.
495 -#ifndef _JZ4740_PCM_H
496 -#define _JZ4740_PCM_H
498 -#include <linux/dma-mapping.h>
499 -#include <asm/mach-jz4740/dma.h>
502 -struct jz4740_pcm_config {
503 - struct jz4740_dma_config dma_config;
504 - phys_addr_t fifo_addr;