提交 bf974a0d 编写于 作者: S Sascha Hauer 提交者: Mark Brown

ASoC i.MX: switch to new DMA api

Signed-off-by: NSascha Hauer <s.hauer@pengutronix.de>
Acked-by: NLiam Girdwood <lrg@slimlogic.co.uk>
Signed-off-by: NMark Brown <broonie@opensource.wolfsonmicro.com>
上级 f562be51
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/dmaengine.h>
#include <sound/core.h> #include <sound/core.h>
#include <sound/initval.h> #include <sound/initval.h>
...@@ -27,165 +28,146 @@ ...@@ -27,165 +28,146 @@
#include <sound/pcm_params.h> #include <sound/pcm_params.h>
#include <sound/soc.h> #include <sound/soc.h>
#include <mach/dma-mx1-mx2.h> #include <mach/dma.h>
#include "imx-ssi.h" #include "imx-ssi.h"
struct imx_pcm_runtime_data { struct imx_pcm_runtime_data {
int sg_count; int period_bytes;
struct scatterlist *sg_list;
int period;
int periods; int periods;
unsigned long dma_addr;
int dma; int dma;
struct snd_pcm_substream *substream;
unsigned long offset; unsigned long offset;
unsigned long size; unsigned long size;
unsigned long period_cnt;
void *buf; void *buf;
int period_time; int period_time;
struct dma_async_tx_descriptor *desc;
struct dma_chan *dma_chan;
struct imx_dma_data dma_data;
}; };
/* Called by the DMA framework when a period has elapsed */ static void audio_dma_irq(void *data)
static void imx_ssi_dma_progression(int channel, void *data,
struct scatterlist *sg)
{ {
struct snd_pcm_substream *substream = data; struct snd_pcm_substream *substream = (struct snd_pcm_substream *)data;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data; struct imx_pcm_runtime_data *iprtd = runtime->private_data;
if (!sg) iprtd->offset += iprtd->period_bytes;
return; iprtd->offset %= iprtd->period_bytes * iprtd->periods;
runtime = iprtd->substream->runtime;
iprtd->offset = sg->dma_address - runtime->dma_addr; snd_pcm_period_elapsed(substream);
snd_pcm_period_elapsed(iprtd->substream);
} }
static void imx_ssi_dma_callback(int channel, void *data) static bool filter(struct dma_chan *chan, void *param)
{ {
pr_err("%s shouldn't be called\n", __func__); struct imx_pcm_runtime_data *iprtd = param;
}
static void snd_imx_dma_err_callback(int channel, void *data, int err) if (!imx_dma_is_general_purpose(chan))
{ return false;
struct snd_pcm_substream *substream = data;
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct imx_pcm_dma_params *dma_params =
snd_soc_dai_get_dma_data(rtd->dai->cpu_dai, substream);
struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
int ret;
pr_err("DMA timeout on channel %d -%s%s%s%s\n", chan->private = &iprtd->dma_data;
channel,
err & IMX_DMA_ERR_BURST ? " burst" : "",
err & IMX_DMA_ERR_REQUEST ? " request" : "",
err & IMX_DMA_ERR_TRANSFER ? " transfer" : "",
err & IMX_DMA_ERR_BUFFER ? " buffer" : "");
imx_dma_disable(iprtd->dma); return true;
ret = imx_dma_setup_sg(iprtd->dma, iprtd->sg_list, iprtd->sg_count,
IMX_DMA_LENGTH_LOOP, dma_params->dma_addr,
substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
DMA_MODE_WRITE : DMA_MODE_READ);
if (!ret)
imx_dma_enable(iprtd->dma);
} }
static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream) static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct imx_pcm_dma_params *dma_params; struct imx_pcm_dma_params *dma_params;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data; struct imx_pcm_runtime_data *iprtd = runtime->private_data;
struct dma_slave_config slave_config;
dma_cap_mask_t mask;
enum dma_slave_buswidth buswidth;
int ret; int ret;
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
iprtd->dma = imx_dma_request_by_prio(DRV_NAME, DMA_PRIO_HIGH); iprtd->dma_data.peripheral_type = IMX_DMATYPE_SSI;
if (iprtd->dma < 0) { iprtd->dma_data.priority = DMA_PRIO_HIGH;
pr_err("Failed to claim the audio DMA\n"); iprtd->dma_data.dma_request = dma_params->dma;
return -ENODEV;
}
ret = imx_dma_setup_handlers(iprtd->dma, /* Try to grab a DMA channel */
imx_ssi_dma_callback, dma_cap_zero(mask);
snd_imx_dma_err_callback, substream); dma_cap_set(DMA_SLAVE, mask);
if (ret) iprtd->dma_chan = dma_request_channel(mask, filter, iprtd);
goto out; if (!iprtd->dma_chan)
return -EINVAL;
ret = imx_dma_setup_progression_handler(iprtd->dma, switch (params_format(params)) {
imx_ssi_dma_progression); case SNDRV_PCM_FORMAT_S16_LE:
if (ret) { buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
pr_err("Failed to setup the DMA handler\n"); break;
goto out; case SNDRV_PCM_FORMAT_S20_3LE:
case SNDRV_PCM_FORMAT_S24_LE:
buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
break;
default:
return 0;
} }
ret = imx_dma_config_channel(iprtd->dma, if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
IMX_DMA_MEMSIZE_16 | IMX_DMA_TYPE_FIFO, slave_config.direction = DMA_TO_DEVICE;
IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR, slave_config.dst_addr = dma_params->dma_addr;
dma_params->dma, 1); slave_config.dst_addr_width = buswidth;
if (ret < 0) { slave_config.dst_maxburst = dma_params->burstsize;
pr_err("Cannot configure DMA channel: %d\n", ret); } else {
goto out; slave_config.direction = DMA_FROM_DEVICE;
slave_config.src_addr = dma_params->dma_addr;
slave_config.src_addr_width = buswidth;
slave_config.src_maxburst = dma_params->burstsize;
} }
imx_dma_config_burstlen(iprtd->dma, dma_params->burstsize * 2); ret = dmaengine_slave_config(iprtd->dma_chan, &slave_config);
if (ret)
return ret;
return 0; return 0;
out:
imx_dma_free(iprtd->dma);
return ret;
} }
static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream, static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data; struct imx_pcm_runtime_data *iprtd = runtime->private_data;
int i;
unsigned long dma_addr; unsigned long dma_addr;
struct dma_chan *chan;
struct imx_pcm_dma_params *dma_params;
int ret;
imx_ssi_dma_alloc(substream); dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
ret = imx_ssi_dma_alloc(substream, params);
if (ret)
return ret;
chan = iprtd->dma_chan;
iprtd->size = params_buffer_bytes(params); iprtd->size = params_buffer_bytes(params);
iprtd->periods = params_periods(params); iprtd->periods = params_periods(params);
iprtd->period = params_period_bytes(params); iprtd->period_bytes = params_period_bytes(params);
iprtd->offset = 0; iprtd->offset = 0;
iprtd->period_time = HZ / (params_rate(params) / iprtd->period_time = HZ / (params_rate(params) /
params_period_size(params)); params_period_size(params));
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
if (iprtd->sg_count != iprtd->periods) {
kfree(iprtd->sg_list);
iprtd->sg_list = kcalloc(iprtd->periods + 1,
sizeof(struct scatterlist), GFP_KERNEL);
if (!iprtd->sg_list)
return -ENOMEM;
iprtd->sg_count = iprtd->periods + 1;
}
sg_init_table(iprtd->sg_list, iprtd->sg_count);
dma_addr = runtime->dma_addr; dma_addr = runtime->dma_addr;
for (i = 0; i < iprtd->periods; i++) { iprtd->buf = (unsigned int *)substream->dma_buffer.area;
iprtd->sg_list[i].page_link = 0;
iprtd->sg_list[i].offset = 0; iprtd->desc = chan->device->device_prep_dma_cyclic(chan, dma_addr,
iprtd->sg_list[i].dma_address = dma_addr; iprtd->period_bytes * iprtd->periods,
iprtd->sg_list[i].length = iprtd->period; iprtd->period_bytes,
dma_addr += iprtd->period; substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
DMA_TO_DEVICE : DMA_FROM_DEVICE);
if (!iprtd->desc) {
dev_err(&chan->dev->device, "cannot prepare slave dma\n");
return -EINVAL;
} }
/* close the loop */ iprtd->desc->callback = audio_dma_irq;
iprtd->sg_list[iprtd->sg_count - 1].offset = 0; iprtd->desc->callback_param = substream;
iprtd->sg_list[iprtd->sg_count - 1].length = 0;
iprtd->sg_list[iprtd->sg_count - 1].page_link =
((unsigned long) iprtd->sg_list | 0x01) & ~0x02;
return 0; return 0;
} }
...@@ -194,41 +176,21 @@ static int snd_imx_pcm_hw_free(struct snd_pcm_substream *substream) ...@@ -194,41 +176,21 @@ static int snd_imx_pcm_hw_free(struct snd_pcm_substream *substream)
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data; struct imx_pcm_runtime_data *iprtd = runtime->private_data;
if (iprtd->dma >= 0) { if (iprtd->dma_chan) {
imx_dma_free(iprtd->dma); dma_release_channel(iprtd->dma_chan);
iprtd->dma = -EINVAL; iprtd->dma_chan = NULL;
} }
kfree(iprtd->sg_list);
iprtd->sg_list = NULL;
return 0; return 0;
} }
static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream) static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
{ {
struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_soc_pcm_runtime *rtd = substream->private_data;
struct imx_pcm_dma_params *dma_params; struct imx_pcm_dma_params *dma_params;
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
int err;
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
iprtd->substream = substream;
iprtd->buf = (unsigned int *)substream->dma_buffer.area;
iprtd->period_cnt = 0;
pr_debug("%s: buf: %p period: %d periods: %d\n",
__func__, iprtd->buf, iprtd->period, iprtd->periods);
err = imx_dma_setup_sg(iprtd->dma, iprtd->sg_list, iprtd->sg_count,
IMX_DMA_LENGTH_LOOP, dma_params->dma_addr,
substream->stream == SNDRV_PCM_STREAM_PLAYBACK ?
DMA_MODE_WRITE : DMA_MODE_READ);
if (err)
return err;
return 0; return 0;
} }
...@@ -241,14 +203,14 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) ...@@ -241,14 +203,14 @@ static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_RESUME: case SNDRV_PCM_TRIGGER_RESUME:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
imx_dma_enable(iprtd->dma); dmaengine_submit(iprtd->desc);
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
case SNDRV_PCM_TRIGGER_SUSPEND: case SNDRV_PCM_TRIGGER_SUSPEND:
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
imx_dma_disable(iprtd->dma); dmaengine_terminate_all(iprtd->dma_chan);
break; break;
default: default:
...@@ -263,6 +225,9 @@ static snd_pcm_uframes_t snd_imx_pcm_pointer(struct snd_pcm_substream *substream ...@@ -263,6 +225,9 @@ static snd_pcm_uframes_t snd_imx_pcm_pointer(struct snd_pcm_substream *substream
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data; struct imx_pcm_runtime_data *iprtd = runtime->private_data;
pr_debug("%s: %ld %ld\n", __func__, iprtd->offset,
bytes_to_frames(substream->runtime, iprtd->offset));
return bytes_to_frames(substream->runtime, iprtd->offset); return bytes_to_frames(substream->runtime, iprtd->offset);
} }
...@@ -279,7 +244,7 @@ static struct snd_pcm_hardware snd_imx_hardware = { ...@@ -279,7 +244,7 @@ static struct snd_pcm_hardware snd_imx_hardware = {
.channels_max = 2, .channels_max = 2,
.buffer_bytes_max = IMX_SSI_DMABUF_SIZE, .buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
.period_bytes_min = 128, .period_bytes_min = 128,
.period_bytes_max = 16 * 1024, .period_bytes_max = 65535, /* Limited by SDMA engine */
.periods_min = 2, .periods_min = 2,
.periods_max = 255, .periods_max = 255,
.fifo_size = 0, .fifo_size = 0,
...@@ -304,11 +269,23 @@ static int snd_imx_open(struct snd_pcm_substream *substream) ...@@ -304,11 +269,23 @@ static int snd_imx_open(struct snd_pcm_substream *substream)
} }
snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware); snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
return 0;
}
static int snd_imx_close(struct snd_pcm_substream *substream)
{
struct snd_pcm_runtime *runtime = substream->runtime;
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
kfree(iprtd);
return 0; return 0;
} }
static struct snd_pcm_ops imx_pcm_ops = { static struct snd_pcm_ops imx_pcm_ops = {
.open = snd_imx_open, .open = snd_imx_open,
.close = snd_imx_close,
.ioctl = snd_pcm_lib_ioctl, .ioctl = snd_pcm_lib_ioctl,
.hw_params = snd_imx_pcm_hw_params, .hw_params = snd_imx_pcm_hw_params,
.hw_free = snd_imx_pcm_hw_free, .hw_free = snd_imx_pcm_hw_free,
...@@ -340,7 +317,6 @@ static struct platform_driver imx_pcm_driver = { ...@@ -340,7 +317,6 @@ static struct platform_driver imx_pcm_driver = {
.name = "imx-pcm-audio", .name = "imx-pcm-audio",
.owner = THIS_MODULE, .owner = THIS_MODULE,
}, },
.probe = imx_soc_platform_probe, .probe = imx_soc_platform_probe,
.remove = __devexit_p(imx_soc_platform_remove), .remove = __devexit_p(imx_soc_platform_remove),
}; };
...@@ -356,4 +332,3 @@ static void __exit snd_imx_pcm_exit(void) ...@@ -356,4 +332,3 @@ static void __exit snd_imx_pcm_exit(void)
platform_driver_unregister(&imx_pcm_driver); platform_driver_unregister(&imx_pcm_driver);
} }
module_exit(snd_imx_pcm_exit); module_exit(snd_imx_pcm_exit);
...@@ -185,6 +185,9 @@ ...@@ -185,6 +185,9 @@
#define DRV_NAME "imx-ssi" #define DRV_NAME "imx-ssi"
#include <linux/dmaengine.h>
#include <mach/dma.h>
struct imx_pcm_dma_params { struct imx_pcm_dma_params {
int dma; int dma;
unsigned long dma_addr; unsigned long dma_addr;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册