2009-11-25 23:41:04 +08:00
|
|
|
/*
|
|
|
|
* imx-pcm-dma-mx2.c -- ALSA Soc Audio Layer
|
|
|
|
*
|
|
|
|
* Copyright 2009 Sascha Hauer <s.hauer@pengutronix.de>
|
|
|
|
*
|
|
|
|
* This code is based on code copyrighted by Freescale,
|
|
|
|
* Liam Girdwood, Javier Martin and probably others.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2 of the License, or (at your
|
|
|
|
* option) any later version.
|
|
|
|
*/
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/dma-mapping.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/platform_device.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2010-11-05 00:05:43 +08:00
|
|
|
#include <linux/dmaengine.h>
|
2012-02-01 18:42:19 +08:00
|
|
|
#include <linux/types.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
2012-02-22 17:49:09 +08:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2010-11-05 00:05:43 +08:00
|
|
|
#include <mach/dma.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-03-05 22:30:55 +08:00
|
|
|
#include "imx-pcm.h"
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2010-11-05 00:05:43 +08:00
|
|
|
static bool filter(struct dma_chan *chan, void *param)
|
2009-11-25 23:41:04 +08:00
|
|
|
{
|
2010-11-05 00:05:43 +08:00
|
|
|
if (!imx_dma_is_general_purpose(chan))
|
|
|
|
return false;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
chan->private = param;
|
2010-04-08 17:31:25 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
return true;
|
2012-02-22 17:49:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2012-02-22 17:49:09 +08:00
|
|
|
struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
|
2012-02-22 17:49:06 +08:00
|
|
|
struct imx_pcm_dma_params *dma_params;
|
|
|
|
struct dma_slave_config slave_config;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
ret = snd_hwparams_to_dma_slave_config(substream, params, &slave_config);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-02-01 18:42:19 +08:00
|
|
|
slave_config.device_fc = false;
|
|
|
|
|
2010-11-05 00:05:43 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
|
|
|
|
slave_config.dst_addr = dma_params->dma_addr;
|
2011-07-06 17:18:33 +08:00
|
|
|
slave_config.dst_maxburst = dma_params->burstsize;
|
2010-11-05 00:05:43 +08:00
|
|
|
} else {
|
|
|
|
slave_config.src_addr = dma_params->dma_addr;
|
2011-07-06 17:18:33 +08:00
|
|
|
slave_config.src_maxburst = dma_params->burstsize;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
|
|
|
|
2012-02-22 17:49:06 +08:00
|
|
|
ret = dmaengine_slave_config(chan, &slave_config);
|
2010-11-05 00:05:43 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_pcm_hardware snd_imx_hardware = {
|
|
|
|
.info = SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_BLOCK_TRANSFER |
|
|
|
|
SNDRV_PCM_INFO_MMAP |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_PAUSE |
|
|
|
|
SNDRV_PCM_INFO_RESUME,
|
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE,
|
|
|
|
.rate_min = 8000,
|
|
|
|
.channels_min = 2,
|
|
|
|
.channels_max = 2,
|
|
|
|
.buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
|
|
|
|
.period_bytes_min = 128,
|
2010-11-05 00:05:43 +08:00
|
|
|
.period_bytes_max = 65535, /* Limited by SDMA engine */
|
2009-11-25 23:41:04 +08:00
|
|
|
.periods_min = 2,
|
|
|
|
.periods_max = 255,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int snd_imx_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2012-02-22 17:49:09 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
|
|
struct imx_pcm_dma_params *dma_params;
|
|
|
|
struct imx_dma_data *dma_data;
|
2009-11-25 23:41:04 +08:00
|
|
|
int ret;
|
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
snd_soc_set_runtime_hwparams(substream, &snd_imx_hardware);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
dma_data = kzalloc(sizeof(*dma_data), GFP_KERNEL);
|
2012-03-28 15:34:56 +08:00
|
|
|
dma_data->peripheral_type = dma_params->shared_peripheral ?
|
|
|
|
IMX_DMATYPE_SSI_SP : IMX_DMATYPE_SSI;
|
2012-02-22 17:49:09 +08:00
|
|
|
dma_data->priority = DMA_PRIO_HIGH;
|
|
|
|
dma_data->dma_request = dma_params->dma;
|
|
|
|
|
|
|
|
ret = snd_dmaengine_pcm_open(substream, filter, dma_data);
|
|
|
|
if (ret) {
|
|
|
|
kfree(dma_data);
|
|
|
|
return 0;
|
2012-02-22 17:49:06 +08:00
|
|
|
}
|
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
snd_dmaengine_pcm_set_data(substream, dma_data);
|
2010-11-05 00:05:43 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_imx_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2012-02-22 17:49:09 +08:00
|
|
|
struct imx_dma_data *dma_data = snd_dmaengine_pcm_get_data(substream);
|
2010-11-05 00:05:43 +08:00
|
|
|
|
2012-02-22 17:49:09 +08:00
|
|
|
snd_dmaengine_pcm_close(substream);
|
|
|
|
kfree(dma_data);
|
2010-11-05 00:05:43 +08:00
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_pcm_ops imx_pcm_ops = {
|
|
|
|
.open = snd_imx_open,
|
2010-11-05 00:05:43 +08:00
|
|
|
.close = snd_imx_close,
|
2009-11-25 23:41:04 +08:00
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_imx_pcm_hw_params,
|
2012-02-22 17:49:09 +08:00
|
|
|
.trigger = snd_dmaengine_pcm_trigger,
|
|
|
|
.pointer = snd_dmaengine_pcm_pointer,
|
2009-11-25 23:41:04 +08:00
|
|
|
.mmap = snd_imx_pcm_mmap,
|
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_platform_driver imx_soc_platform_mx2 = {
|
|
|
|
.ops = &imx_pcm_ops,
|
2009-11-25 23:41:04 +08:00
|
|
|
.pcm_new = imx_pcm_new,
|
|
|
|
.pcm_free = imx_pcm_free,
|
|
|
|
};
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int __devinit imx_soc_platform_probe(struct platform_device *pdev)
|
2009-11-25 23:41:04 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
return snd_soc_register_platform(&pdev->dev, &imx_soc_platform_mx2);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int __devexit imx_soc_platform_remove(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
snd_soc_unregister_platform(&pdev->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver imx_pcm_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "imx-pcm-audio",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
.probe = imx_soc_platform_probe,
|
|
|
|
.remove = __devexit_p(imx_soc_platform_remove),
|
|
|
|
};
|
|
|
|
|
2011-11-24 15:03:50 +08:00
|
|
|
module_platform_driver(imx_pcm_driver);
|
2011-06-23 04:21:49 +08:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_ALIAS("platform:imx-pcm-audio");
|