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 diff --git a/sound/soc/jz4740/Kconfig b/sound/soc/jz4740/Kconfig
20 index 5351cba..29f76af 100644
21 --- a/sound/soc/jz4740/Kconfig
22 +++ b/sound/soc/jz4740/Kconfig
25 tristate "SoC Audio for Ingenic JZ4740 SoC"
26 depends on MACH_JZ4740 && SND_SOC
27 + select SND_SOC_GENERIC_DMAENGINE_PCM
29 Say Y or M if you want to add support for codecs attached to
30 the JZ4740 I2S interface. You will also need to select the audio
31 diff --git a/sound/soc/jz4740/jz4740-i2s.c b/sound/soc/jz4740/jz4740-i2s.c
32 index 9a12644..5d04134 100644
33 --- a/sound/soc/jz4740/jz4740-i2s.c
34 +++ b/sound/soc/jz4740/jz4740-i2s.c
36 #include <sound/pcm_params.h>
37 #include <sound/soc.h>
38 #include <sound/initval.h>
39 +#include <sound/dmaengine_pcm.h>
41 +#include <asm/mach-jz4740/dma.h>
43 #include "jz4740-i2s.h"
44 -#include "jz4740-pcm.h"
47 #define JZ_REG_AIC_CONF 0x00
48 #define JZ_REG_AIC_CTRL 0x04
49 @@ -89,8 +92,8 @@ struct jz4740_i2s {
53 - struct jz4740_pcm_config pcm_config_playback;
54 - struct jz4740_pcm_config pcm_config_capture;
55 + struct snd_dmaengine_dai_dma_data playback_dma_data;
56 + struct snd_dmaengine_dai_dma_data capture_dma_data;
59 static inline uint32_t jz4740_i2s_read(const struct jz4740_i2s *i2s,
60 @@ -233,8 +236,6 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
61 struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
63 struct jz4740_i2s *i2s = snd_soc_dai_get_drvdata(dai);
64 - enum jz4740_dma_width dma_width;
65 - struct jz4740_pcm_config *pcm_config;
66 unsigned int sample_size;
69 @@ -243,11 +244,9 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
70 switch (params_format(params)) {
71 case SNDRV_PCM_FORMAT_S8:
73 - dma_width = JZ4740_DMA_WIDTH_8BIT;
75 case SNDRV_PCM_FORMAT_S16:
77 - dma_width = JZ4740_DMA_WIDTH_16BIT;
81 @@ -260,22 +259,13 @@ static int jz4740_i2s_hw_params(struct snd_pcm_substream *substream,
82 ctrl |= JZ_AIC_CTRL_MONO_TO_STEREO;
84 ctrl &= ~JZ_AIC_CTRL_MONO_TO_STEREO;
86 - pcm_config = &i2s->pcm_config_playback;
87 - pcm_config->dma_config.dst_width = dma_width;
90 ctrl &= ~JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_MASK;
91 ctrl |= sample_size << JZ_AIC_CTRL_INPUT_SAMPLE_SIZE_OFFSET;
93 - pcm_config = &i2s->pcm_config_capture;
94 - pcm_config->dma_config.src_width = dma_width;
97 jz4740_i2s_write(i2s, JZ_REG_AIC_CTRL, ctrl);
99 - snd_soc_dai_set_dma_data(dai, substream, pcm_config);
104 @@ -342,25 +332,19 @@ static int jz4740_i2s_resume(struct snd_soc_dai *dai)
106 static void jz4740_i2c_init_pcm_config(struct jz4740_i2s *i2s)
108 - struct jz4740_dma_config *dma_config;
109 + struct snd_dmaengine_dai_dma_data *dma_data;
112 - dma_config = &i2s->pcm_config_playback.dma_config;
113 - dma_config->src_width = JZ4740_DMA_WIDTH_32BIT;
114 - dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
115 - dma_config->request_type = JZ4740_DMA_TYPE_AIC_TRANSMIT;
116 - dma_config->flags = JZ4740_DMA_SRC_AUTOINC;
117 - dma_config->mode = JZ4740_DMA_MODE_SINGLE;
118 - i2s->pcm_config_playback.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
119 + dma_data = &i2s->playback_dma_data;
120 + dma_data->maxburst = 16;
121 + dma_data->slave_id = JZ4740_DMA_TYPE_AIC_TRANSMIT;
122 + dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
125 - dma_config = &i2s->pcm_config_capture.dma_config;
126 - dma_config->dst_width = JZ4740_DMA_WIDTH_32BIT;
127 - dma_config->transfer_size = JZ4740_DMA_TRANSFER_SIZE_16BYTE;
128 - dma_config->request_type = JZ4740_DMA_TYPE_AIC_RECEIVE;
129 - dma_config->flags = JZ4740_DMA_DST_AUTOINC;
130 - dma_config->mode = JZ4740_DMA_MODE_SINGLE;
131 - i2s->pcm_config_capture.fifo_addr = i2s->phys_base + JZ_REG_AIC_FIFO;
132 + dma_data = &i2s->capture_dma_data;
133 + dma_data->maxburst = 16;
134 + dma_data->slave_id = JZ4740_DMA_TYPE_AIC_RECEIVE;
135 + dma_data->addr = i2s->phys_base + JZ_REG_AIC_FIFO;
138 static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
139 @@ -371,6 +355,8 @@ static int jz4740_i2s_dai_probe(struct snd_soc_dai *dai)
140 clk_enable(i2s->clk_aic);
142 jz4740_i2c_init_pcm_config(i2s);
143 + dai->playback_dma_data = &i2s->playback_dma_data;
144 + dai->capture_dma_data = &i2s->capture_dma_data;
146 conf = (7 << JZ_AIC_CONF_FIFO_RX_THRESHOLD_OFFSET) |
147 (8 << JZ_AIC_CONF_FIFO_TX_THRESHOLD_OFFSET) |
148 diff --git a/sound/soc/jz4740/jz4740-pcm.c b/sound/soc/jz4740/jz4740-pcm.c
149 index 7100592..79fcade 100644
150 --- a/sound/soc/jz4740/jz4740-pcm.c
151 +++ b/sound/soc/jz4740/jz4740-pcm.c
153 #include <linux/platform_device.h>
154 #include <linux/slab.h>
156 -#include <linux/dma-mapping.h>
157 +#include <sound/dmaengine_pcm.h>
159 -#include <sound/core.h>
160 -#include <sound/pcm.h>
161 -#include <sound/pcm_params.h>
162 -#include <sound/soc.h>
164 -#include <asm/mach-jz4740/dma.h>
165 -#include "jz4740-pcm.h"
167 -struct jz4740_runtime_data {
168 - unsigned long dma_period;
169 - dma_addr_t dma_start;
170 - dma_addr_t dma_pos;
171 - dma_addr_t dma_end;
173 - struct jz4740_dma_chan *dma;
175 - dma_addr_t fifo_addr;
178 -/* identify hardware playback capabilities */
179 static const struct snd_pcm_hardware jz4740_pcm_hardware = {
180 .info = SNDRV_PCM_INFO_MMAP |
181 SNDRV_PCM_INFO_MMAP_VALID |
182 SNDRV_PCM_INFO_INTERLEAVED |
183 SNDRV_PCM_INFO_BLOCK_TRANSFER,
184 .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S8,
186 - .rates = SNDRV_PCM_RATE_8000_48000,
189 .period_bytes_min = 16,
190 .period_bytes_max = 2 * PAGE_SIZE,
192 @@ -59,290 +35,22 @@ static const struct snd_pcm_hardware jz4740_pcm_hardware = {
196 -static void jz4740_pcm_start_transfer(struct jz4740_runtime_data *prtd,
197 - struct snd_pcm_substream *substream)
199 - unsigned long count;
201 - if (prtd->dma_pos == prtd->dma_end)
202 - prtd->dma_pos = prtd->dma_start;
204 - if (prtd->dma_pos + prtd->dma_period > prtd->dma_end)
205 - count = prtd->dma_end - prtd->dma_pos;
207 - count = prtd->dma_period;
209 - jz4740_dma_disable(prtd->dma);
211 - if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
212 - jz4740_dma_set_src_addr(prtd->dma, prtd->dma_pos);
213 - jz4740_dma_set_dst_addr(prtd->dma, prtd->fifo_addr);
215 - jz4740_dma_set_src_addr(prtd->dma, prtd->fifo_addr);
216 - jz4740_dma_set_dst_addr(prtd->dma, prtd->dma_pos);
219 - jz4740_dma_set_transfer_count(prtd->dma, count);
221 - prtd->dma_pos += count;
223 - jz4740_dma_enable(prtd->dma);
226 -static void jz4740_pcm_dma_transfer_done(struct jz4740_dma_chan *dma, int err,
229 - struct snd_pcm_substream *substream = dev_id;
230 - struct snd_pcm_runtime *runtime = substream->runtime;
231 - struct jz4740_runtime_data *prtd = runtime->private_data;
233 - snd_pcm_period_elapsed(substream);
235 - jz4740_pcm_start_transfer(prtd, substream);
238 -static int jz4740_pcm_hw_params(struct snd_pcm_substream *substream,
239 - struct snd_pcm_hw_params *params)
241 - struct snd_pcm_runtime *runtime = substream->runtime;
242 - struct jz4740_runtime_data *prtd = runtime->private_data;
243 - struct snd_soc_pcm_runtime *rtd = substream->private_data;
244 - struct jz4740_pcm_config *config;
246 - config = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
252 - if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
253 - prtd->dma = jz4740_dma_request(substream, "PCM Capture");
255 - prtd->dma = jz4740_dma_request(substream, "PCM Playback");
261 - jz4740_dma_configure(prtd->dma, &config->dma_config);
262 - prtd->fifo_addr = config->fifo_addr;
264 - jz4740_dma_set_complete_cb(prtd->dma, jz4740_pcm_dma_transfer_done);
266 - snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
267 - runtime->dma_bytes = params_buffer_bytes(params);
269 - prtd->dma_period = params_period_bytes(params);
270 - prtd->dma_start = runtime->dma_addr;
271 - prtd->dma_pos = prtd->dma_start;
272 - prtd->dma_end = prtd->dma_start + runtime->dma_bytes;
277 -static int jz4740_pcm_hw_free(struct snd_pcm_substream *substream)
279 - struct jz4740_runtime_data *prtd = substream->runtime->private_data;
281 - snd_pcm_set_runtime_buffer(substream, NULL);
283 - jz4740_dma_free(prtd->dma);
290 -static int jz4740_pcm_prepare(struct snd_pcm_substream *substream)
292 - struct jz4740_runtime_data *prtd = substream->runtime->private_data;
297 - prtd->dma_pos = prtd->dma_start;
302 -static int jz4740_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
304 - struct snd_pcm_runtime *runtime = substream->runtime;
305 - struct jz4740_runtime_data *prtd = runtime->private_data;
308 - case SNDRV_PCM_TRIGGER_START:
309 - case SNDRV_PCM_TRIGGER_RESUME:
310 - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
311 - jz4740_pcm_start_transfer(prtd, substream);
313 - case SNDRV_PCM_TRIGGER_STOP:
314 - case SNDRV_PCM_TRIGGER_SUSPEND:
315 - case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
316 - jz4740_dma_disable(prtd->dma);
325 -static snd_pcm_uframes_t jz4740_pcm_pointer(struct snd_pcm_substream *substream)
327 - struct snd_pcm_runtime *runtime = substream->runtime;
328 - struct jz4740_runtime_data *prtd = runtime->private_data;
329 - unsigned long byte_offset;
330 - snd_pcm_uframes_t offset;
331 - struct jz4740_dma_chan *dma = prtd->dma;
333 - /* prtd->dma_pos points to the end of the current transfer. So by
334 - * subtracting prdt->dma_start we get the offset to the end of the
335 - * current period in bytes. By subtracting the residue of the transfer
336 - * we get the current offset in bytes. */
337 - byte_offset = prtd->dma_pos - prtd->dma_start;
338 - byte_offset -= jz4740_dma_get_residue(dma);
340 - offset = bytes_to_frames(runtime, byte_offset);
341 - if (offset >= runtime->buffer_size)
347 -static int jz4740_pcm_open(struct snd_pcm_substream *substream)
349 - struct snd_pcm_runtime *runtime = substream->runtime;
350 - struct jz4740_runtime_data *prtd;
352 - prtd = kzalloc(sizeof(*prtd), GFP_KERNEL);
356 - snd_soc_set_runtime_hwparams(substream, &jz4740_pcm_hardware);
358 - runtime->private_data = prtd;
363 -static int jz4740_pcm_close(struct snd_pcm_substream *substream)
365 - struct snd_pcm_runtime *runtime = substream->runtime;
366 - struct jz4740_runtime_data *prtd = runtime->private_data;
373 -static int jz4740_pcm_mmap(struct snd_pcm_substream *substream,
374 - struct vm_area_struct *vma)
376 - return remap_pfn_range(vma, vma->vm_start,
377 - substream->dma_buffer.addr >> PAGE_SHIFT,
378 - vma->vm_end - vma->vm_start, vma->vm_page_prot);
381 -static struct snd_pcm_ops jz4740_pcm_ops = {
382 - .open = jz4740_pcm_open,
383 - .close = jz4740_pcm_close,
384 - .ioctl = snd_pcm_lib_ioctl,
385 - .hw_params = jz4740_pcm_hw_params,
386 - .hw_free = jz4740_pcm_hw_free,
387 - .prepare = jz4740_pcm_prepare,
388 - .trigger = jz4740_pcm_trigger,
389 - .pointer = jz4740_pcm_pointer,
390 - .mmap = jz4740_pcm_mmap,
393 -static int jz4740_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
395 - struct snd_pcm_substream *substream = pcm->streams[stream].substream;
396 - struct snd_dma_buffer *buf = &substream->dma_buffer;
397 - size_t size = jz4740_pcm_hardware.buffer_bytes_max;
399 - buf->dev.type = SNDRV_DMA_TYPE_DEV;
400 - buf->dev.dev = pcm->card->dev;
401 - buf->private_data = NULL;
403 - buf->area = dma_alloc_noncoherent(pcm->card->dev, size,
404 - &buf->addr, GFP_KERNEL);
413 -static void jz4740_pcm_free(struct snd_pcm *pcm)
415 - struct snd_pcm_substream *substream;
416 - struct snd_dma_buffer *buf;
419 - for (stream = 0; stream < SNDRV_PCM_STREAM_LAST; ++stream) {
420 - substream = pcm->streams[stream].substream;
424 - buf = &substream->dma_buffer;
428 - dma_free_noncoherent(pcm->card->dev, buf->bytes, buf->area,
434 -static u64 jz4740_pcm_dmamask = DMA_BIT_MASK(32);
436 -static int jz4740_pcm_new(struct snd_soc_pcm_runtime *rtd)
438 - struct snd_card *card = rtd->card->snd_card;
439 - struct snd_pcm *pcm = rtd->pcm;
442 - if (!card->dev->dma_mask)
443 - card->dev->dma_mask = &jz4740_pcm_dmamask;
445 - if (!card->dev->coherent_dma_mask)
446 - card->dev->coherent_dma_mask = DMA_BIT_MASK(32);
448 - if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
449 - ret = jz4740_pcm_preallocate_dma_buffer(pcm,
450 - SNDRV_PCM_STREAM_PLAYBACK);
455 - if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
456 - ret = jz4740_pcm_preallocate_dma_buffer(pcm,
457 - SNDRV_PCM_STREAM_CAPTURE);
466 -static struct snd_soc_platform_driver jz4740_soc_platform = {
467 - .ops = &jz4740_pcm_ops,
468 - .pcm_new = jz4740_pcm_new,
469 - .pcm_free = jz4740_pcm_free,
470 +static const struct snd_dmaengine_pcm_config jz4740_dmaengine_pcm_config = {
471 + .prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config,
472 + .pcm_hardware = &jz4740_pcm_hardware,
473 + .prealloc_buffer_size = 256 * PAGE_SIZE,
476 static int jz4740_pcm_probe(struct platform_device *pdev)
478 - return snd_soc_register_platform(&pdev->dev, &jz4740_soc_platform);
479 + return snd_dmaengine_pcm_register(&pdev->dev,
480 + &jz4740_dmaengine_pcm_config,
481 + SND_DMAENGINE_PCM_FLAG_COMPAT);
484 static int jz4740_pcm_remove(struct platform_device *pdev)
486 - snd_soc_unregister_platform(&pdev->dev);
487 + snd_dmaengine_pcm_unregister(&pdev->dev);
491 diff --git a/sound/soc/jz4740/jz4740-pcm.h b/sound/soc/jz4740/jz4740-pcm.h
492 deleted file mode 100644
493 index 1220cbb..0000000
494 --- a/sound/soc/jz4740/jz4740-pcm.h
499 - * This program is free software; you can redistribute it and/or modify
500 - * it under the terms of the GNU General Public License version 2 as
501 - * published by the Free Software Foundation.
504 -#ifndef _JZ4740_PCM_H
505 -#define _JZ4740_PCM_H
507 -#include <linux/dma-mapping.h>
508 -#include <asm/mach-jz4740/dma.h>
511 -struct jz4740_pcm_config {
512 - struct jz4740_dma_config dma_config;
513 - phys_addr_t fifo_addr;