2008-04-25 05:55:19 -06:00
|
|
|
/*
|
|
|
|
* omap-pcm.c -- ALSA PCM interface for the OMAP SoC
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
*
|
2011-08-11 06:44:57 -06:00
|
|
|
* Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
|
2011-05-03 09:14:43 -06:00
|
|
|
* Peter Ujfalusi <peter.ujfalusi@ti.com>
|
2008-04-25 05:55:19 -06:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* version 2 as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
|
|
|
|
* 02110-1301 USA
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/dma-mapping.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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2011-07-15 10:38:28 -06:00
|
|
|
#include <linux/module.h>
|
2012-09-14 06:05:58 -06:00
|
|
|
#include <linux/omap-dma.h>
|
2008-04-25 05:55:19 -06:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
2012-09-14 06:05:58 -06:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2008-04-25 05:55:19 -06:00
|
|
|
#include <sound/soc.h>
|
2014-06-19 01:40:29 -06:00
|
|
|
#include <sound/omap-pcm.h>
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2012-10-15 17:24:23 -06:00
|
|
|
#ifdef CONFIG_ARCH_OMAP1
|
|
|
|
#define pcm_omap1510() cpu_is_omap1510()
|
|
|
|
#else
|
|
|
|
#define pcm_omap1510() 0
|
|
|
|
#endif
|
|
|
|
|
2008-04-25 05:55:19 -06:00
|
|
|
static const struct snd_pcm_hardware omap_pcm_hardware = {
|
|
|
|
.info = SNDRV_PCM_INFO_MMAP |
|
|
|
|
SNDRV_PCM_INFO_MMAP_VALID |
|
|
|
|
SNDRV_PCM_INFO_INTERLEAVED |
|
|
|
|
SNDRV_PCM_INFO_PAUSE |
|
2011-05-12 04:04:55 -06:00
|
|
|
SNDRV_PCM_INFO_RESUME |
|
|
|
|
SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
|
2008-04-25 05:55:19 -06:00
|
|
|
.period_bytes_min = 32,
|
|
|
|
.period_bytes_max = 64 * 1024,
|
|
|
|
.periods_min = 2,
|
|
|
|
.periods_max = 255,
|
|
|
|
.buffer_bytes_max = 128 * 1024,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* this may get called several times by oss emulation */
|
|
|
|
static int omap_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2010-03-22 03:11:15 -06:00
|
|
|
struct omap_pcm_dma_data *dma_data;
|
2012-09-14 06:05:58 -06:00
|
|
|
struct dma_slave_config config;
|
|
|
|
struct dma_chan *chan;
|
2008-04-25 05:55:19 -06:00
|
|
|
int err = 0;
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2010-03-22 03:11:15 -06:00
|
|
|
|
2009-04-21 19:56:50 -06:00
|
|
|
/* return if this is a bufferless transfer e.g.
|
|
|
|
* codec <--> BT codec or GSM modem -- lg FIXME */
|
2008-04-25 05:55:19 -06:00
|
|
|
if (!dma_data)
|
2009-04-21 19:56:50 -06:00
|
|
|
return 0;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
|
|
|
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
|
|
|
runtime->dma_bytes = params_buffer_bytes(params);
|
|
|
|
|
2012-09-14 06:05:58 -06:00
|
|
|
chan = snd_dmaengine_pcm_get_chan(substream);
|
|
|
|
if (!chan)
|
|
|
|
return -EINVAL;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2012-09-14 06:05:58 -06:00
|
|
|
/* fills in addr_width and direction */
|
|
|
|
err = snd_hwparams_to_dma_slave_config(substream, params, &config);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2013-04-03 03:06:05 -06:00
|
|
|
snd_dmaengine_pcm_set_config_from_dai_data(substream,
|
|
|
|
snd_soc_dai_get_dma_data(rtd->cpu_dai, substream),
|
|
|
|
&config);
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2012-09-14 06:05:58 -06:00
|
|
|
return dmaengine_slave_config(chan, &config);
|
2008-04-25 05:55:19 -06:00
|
|
|
}
|
|
|
|
|
2012-09-14 06:05:58 -06:00
|
|
|
static int omap_pcm_hw_free(struct snd_pcm_substream *substream)
|
2008-04-25 05:55:19 -06:00
|
|
|
{
|
2012-09-14 06:05:58 -06:00
|
|
|
snd_pcm_set_runtime_buffer(substream, NULL);
|
2008-04-25 05:55:19 -06:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t omap_pcm_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
snd_pcm_uframes_t offset;
|
|
|
|
|
2012-10-15 17:24:23 -06:00
|
|
|
if (pcm_omap1510())
|
2012-09-14 06:05:58 -06:00
|
|
|
offset = snd_dmaengine_pcm_pointer_no_residue(substream);
|
|
|
|
else
|
|
|
|
offset = snd_dmaengine_pcm_pointer(substream);
|
2008-04-25 05:55:19 -06:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_pcm_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2012-09-14 06:05:58 -06:00
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
2013-04-03 03:06:05 -06:00
|
|
|
struct snd_dmaengine_dai_dma_data *dma_data;
|
2013-07-11 06:35:43 -06:00
|
|
|
int ret;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
|
|
|
snd_soc_set_runtime_hwparams(substream, &omap_pcm_hardware);
|
|
|
|
|
2012-09-14 06:05:58 -06:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2013-02-05 05:43:39 -07:00
|
|
|
|
2013-07-11 06:35:43 -06:00
|
|
|
/* DT boot: filter_data is the DMA name */
|
|
|
|
if (rtd->cpu_dai->dev->of_node) {
|
|
|
|
struct dma_chan *chan;
|
|
|
|
|
|
|
|
chan = dma_request_slave_channel(rtd->cpu_dai->dev,
|
|
|
|
dma_data->filter_data);
|
|
|
|
ret = snd_dmaengine_pcm_open(substream, chan);
|
|
|
|
} else {
|
|
|
|
ret = snd_dmaengine_pcm_open_request_chan(substream,
|
|
|
|
omap_dma_filter_fn,
|
|
|
|
dma_data->filter_data);
|
|
|
|
}
|
|
|
|
return ret;
|
2008-04-25 05:55:19 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_pcm_mmap(struct snd_pcm_substream *substream,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
|
|
|
|
return dma_mmap_writecombine(substream->pcm->card->dev, vma,
|
|
|
|
runtime->dma_area,
|
|
|
|
runtime->dma_addr,
|
|
|
|
runtime->dma_bytes);
|
|
|
|
}
|
|
|
|
|
2009-01-17 12:14:26 -07:00
|
|
|
static struct snd_pcm_ops omap_pcm_ops = {
|
2008-04-25 05:55:19 -06:00
|
|
|
.open = omap_pcm_open,
|
2013-04-15 11:19:48 -06:00
|
|
|
.close = snd_dmaengine_pcm_close_release_chan,
|
2008-04-25 05:55:19 -06:00
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = omap_pcm_hw_params,
|
|
|
|
.hw_free = omap_pcm_hw_free,
|
2013-03-25 09:58:16 -06:00
|
|
|
.trigger = snd_dmaengine_pcm_trigger,
|
2008-04-25 05:55:19 -06:00
|
|
|
.pointer = omap_pcm_pointer,
|
|
|
|
.mmap = omap_pcm_mmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int omap_pcm_preallocate_dma_buffer(struct snd_pcm *pcm,
|
|
|
|
int stream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_substream *substream = pcm->streams[stream].substream;
|
|
|
|
struct snd_dma_buffer *buf = &substream->dma_buffer;
|
|
|
|
size_t size = omap_pcm_hardware.buffer_bytes_max;
|
|
|
|
|
|
|
|
buf->dev.type = SNDRV_DMA_TYPE_DEV;
|
|
|
|
buf->dev.dev = pcm->card->dev;
|
|
|
|
buf->private_data = NULL;
|
|
|
|
buf->area = dma_alloc_writecombine(pcm->card->dev, size,
|
|
|
|
&buf->addr, GFP_KERNEL);
|
|
|
|
if (!buf->area)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
buf->bytes = size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void omap_pcm_free_dma_buffers(struct snd_pcm *pcm)
|
|
|
|
{
|
|
|
|
struct snd_pcm_substream *substream;
|
|
|
|
struct snd_dma_buffer *buf;
|
|
|
|
int stream;
|
|
|
|
|
|
|
|
for (stream = 0; stream < 2; stream++) {
|
|
|
|
substream = pcm->streams[stream].substream;
|
|
|
|
if (!substream)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
buf = &substream->dma_buffer;
|
|
|
|
if (!buf->area)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
dma_free_writecombine(pcm->card->dev, buf->bytes,
|
|
|
|
buf->area, buf->addr);
|
|
|
|
buf->area = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 09:08:33 -06:00
|
|
|
static int omap_pcm_new(struct snd_soc_pcm_runtime *rtd)
|
2008-04-25 05:55:19 -06:00
|
|
|
{
|
2011-06-07 09:08:33 -06:00
|
|
|
struct snd_card *card = rtd->card->snd_card;
|
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
2013-06-27 05:53:37 -06:00
|
|
|
int ret;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2013-06-27 05:53:37 -06:00
|
|
|
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(64));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2008-04-25 05:55:19 -06:00
|
|
|
|
2011-12-31 17:58:44 -07:00
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
|
2008-04-25 05:55:19 -06:00
|
|
|
ret = omap_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_PLAYBACK);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2011-12-31 17:58:44 -07:00
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
|
2008-04-25 05:55:19 -06:00
|
|
|
ret = omap_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-04-24 20:02:02 -06:00
|
|
|
/* free preallocated buffers in case of error */
|
|
|
|
if (ret)
|
|
|
|
omap_pcm_free_dma_buffers(pcm);
|
|
|
|
|
2008-04-25 05:55:19 -06:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-17 14:15:21 -06:00
|
|
|
static struct snd_soc_platform_driver omap_soc_platform = {
|
|
|
|
.ops = &omap_pcm_ops,
|
2008-04-25 05:55:19 -06:00
|
|
|
.pcm_new = omap_pcm_new,
|
|
|
|
.pcm_free = omap_pcm_free_dma_buffers,
|
|
|
|
};
|
|
|
|
|
2014-04-16 06:46:12 -06:00
|
|
|
int omap_pcm_platform_register(struct device *dev)
|
|
|
|
{
|
|
|
|
return devm_snd_soc_register_platform(dev, &omap_soc_platform);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(omap_pcm_platform_register);
|
|
|
|
|
2011-08-11 06:44:57 -06:00
|
|
|
MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@bitmer.com>");
|
2008-04-25 05:55:19 -06:00
|
|
|
MODULE_DESCRIPTION("OMAP PCM DMA module");
|
|
|
|
MODULE_LICENSE("GPL");
|