2008-04-25 19:55:19 +08:00
|
|
|
/*
|
|
|
|
* omap-pcm.c -- ALSA PCM interface for the OMAP SoC
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Nokia Corporation
|
|
|
|
*
|
2011-08-11 20:44:57 +08:00
|
|
|
* Contact: Jarkko Nikula <jarkko.nikula@bitmer.com>
|
2011-05-03 23:14:43 +08:00
|
|
|
* Peter Ujfalusi <peter.ujfalusi@ti.com>
|
2008-04-25 19:55:19 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2011-07-16 00:38:28 +08:00
|
|
|
#include <linux/module.h>
|
2012-09-14 20:05:58 +08:00
|
|
|
#include <linux/omap-dma.h>
|
2008-04-25 19:55:19 +08:00
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
2012-09-14 20:05:58 +08:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2008-04-25 19:55:19 +08:00
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include "omap-pcm.h"
|
|
|
|
|
2012-10-16 07:24:23 +08:00
|
|
|
#ifdef CONFIG_ARCH_OMAP1
|
|
|
|
#define pcm_omap1510() cpu_is_omap1510()
|
|
|
|
#else
|
|
|
|
#define pcm_omap1510() 0
|
|
|
|
#endif
|
|
|
|
|
2008-04-25 19:55:19 +08: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 18:04:55 +08:00
|
|
|
SNDRV_PCM_INFO_RESUME |
|
|
|
|
SNDRV_PCM_INFO_NO_PERIOD_WAKEUP,
|
2010-02-23 05:09:19 +08:00
|
|
|
.formats = SNDRV_PCM_FMTBIT_S16_LE |
|
|
|
|
SNDRV_PCM_FMTBIT_S32_LE,
|
2008-04-25 19:55:19 +08:00
|
|
|
.period_bytes_min = 32,
|
|
|
|
.period_bytes_max = 64 * 1024,
|
|
|
|
.periods_min = 2,
|
|
|
|
.periods_max = 255,
|
|
|
|
.buffer_bytes_max = 128 * 1024,
|
|
|
|
};
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
static int omap_pcm_get_dma_buswidth(int num_bits)
|
2008-04-25 19:55:19 +08:00
|
|
|
{
|
2012-09-14 20:05:58 +08:00
|
|
|
int buswidth;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
switch (num_bits) {
|
|
|
|
case 16:
|
|
|
|
buswidth = DMA_SLAVE_BUSWIDTH_2_BYTES;
|
|
|
|
break;
|
|
|
|
case 32:
|
|
|
|
buswidth = DMA_SLAVE_BUSWIDTH_4_BYTES;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
buswidth = -EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return buswidth;
|
2008-04-25 19:55:19 +08:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
|
2008-04-25 19:55:19 +08:00
|
|
|
/* 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 17:11:15 +08:00
|
|
|
struct omap_pcm_dma_data *dma_data;
|
2012-09-14 20:05:58 +08:00
|
|
|
struct dma_slave_config config;
|
|
|
|
struct dma_chan *chan;
|
2008-04-25 19:55:19 +08:00
|
|
|
int err = 0;
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2010-03-22 17:11:15 +08:00
|
|
|
|
2009-04-22 09:56:50 +08:00
|
|
|
/* return if this is a bufferless transfer e.g.
|
|
|
|
* codec <--> BT codec or GSM modem -- lg FIXME */
|
2008-04-25 19:55:19 +08:00
|
|
|
if (!dma_data)
|
2009-04-22 09:56:50 +08:00
|
|
|
return 0;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
|
|
|
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
|
|
|
runtime->dma_bytes = params_buffer_bytes(params);
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
chan = snd_dmaengine_pcm_get_chan(substream);
|
|
|
|
if (!chan)
|
|
|
|
return -EINVAL;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
/* fills in addr_width and direction */
|
|
|
|
err = snd_hwparams_to_dma_slave_config(substream, params, &config);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
/* Override the *_dma addr_width if requested by the DAI driver */
|
|
|
|
if (dma_data->data_type) {
|
|
|
|
int buswidth = omap_pcm_get_dma_buswidth(dma_data->data_type);
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
config.dst_addr_width = buswidth;
|
|
|
|
else
|
|
|
|
config.src_addr_width = buswidth;
|
|
|
|
}
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
config.src_addr = dma_data->port_addr;
|
|
|
|
config.dst_addr = dma_data->port_addr;
|
|
|
|
config.src_maxburst = dma_data->packet_size;
|
|
|
|
config.dst_maxburst = dma_data->packet_size;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
return dmaengine_slave_config(chan, &config);
|
2008-04-25 19:55:19 +08:00
|
|
|
}
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
static int omap_pcm_hw_free(struct snd_pcm_substream *substream)
|
2008-04-25 19:55:19 +08:00
|
|
|
{
|
2012-09-14 20:05:58 +08:00
|
|
|
snd_pcm_set_runtime_buffer(substream, NULL);
|
2008-04-25 19:55:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
2012-09-14 20:05:58 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
|
|
struct omap_pcm_dma_data *dma_data;
|
2008-04-25 19:55:19 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
|
|
|
|
2008-04-25 19:55:19 +08:00
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2009-08-20 21:18:25 +08:00
|
|
|
/* Configure McBSP internal buffer usage */
|
|
|
|
if (dma_data->set_threshold)
|
|
|
|
dma_data->set_threshold(substream);
|
2008-04-25 19:55:19 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
ret = -EINVAL;
|
|
|
|
}
|
2012-09-14 20:05:58 +08:00
|
|
|
|
|
|
|
if (ret == 0)
|
|
|
|
ret = snd_dmaengine_pcm_trigger(substream, cmd);
|
2008-04-25 19:55:19 +08:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t omap_pcm_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
snd_pcm_uframes_t offset;
|
|
|
|
|
2012-10-16 07:24:23 +08:00
|
|
|
if (pcm_omap1510())
|
2012-09-14 20:05:58 +08:00
|
|
|
offset = snd_dmaengine_pcm_pointer_no_residue(substream);
|
|
|
|
else
|
|
|
|
offset = snd_dmaengine_pcm_pointer(substream);
|
2008-04-25 19:55:19 +08:00
|
|
|
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_pcm_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2012-09-14 20:05:58 +08:00
|
|
|
struct snd_soc_pcm_runtime *rtd = substream->private_data;
|
|
|
|
struct omap_pcm_dma_data *dma_data;
|
2008-04-25 19:55:19 +08:00
|
|
|
|
|
|
|
snd_soc_set_runtime_hwparams(substream, &omap_pcm_hardware);
|
|
|
|
|
2012-09-14 20:05:58 +08:00
|
|
|
dma_data = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
|
2013-02-05 20:43:39 +08:00
|
|
|
|
|
|
|
return snd_dmaengine_pcm_open(substream, omap_dma_filter_fn,
|
|
|
|
&dma_data->dma_req);
|
2008-04-25 19:55:19 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int omap_pcm_close(struct snd_pcm_substream *substream)
|
|
|
|
{
|
2012-09-14 20:05:58 +08:00
|
|
|
snd_dmaengine_pcm_close(substream);
|
2008-04-25 19:55:19 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
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-18 03:14:26 +08:00
|
|
|
static struct snd_pcm_ops omap_pcm_ops = {
|
2008-04-25 19:55:19 +08:00
|
|
|
.open = omap_pcm_open,
|
|
|
|
.close = omap_pcm_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = omap_pcm_hw_params,
|
|
|
|
.hw_free = omap_pcm_hw_free,
|
|
|
|
.trigger = omap_pcm_trigger,
|
|
|
|
.pointer = omap_pcm_pointer,
|
|
|
|
.mmap = omap_pcm_mmap,
|
|
|
|
};
|
|
|
|
|
2009-08-20 21:18:22 +08:00
|
|
|
static u64 omap_pcm_dmamask = DMA_BIT_MASK(64);
|
2008-04-25 19:55:19 +08:00
|
|
|
|
|
|
|
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 23:08:33 +08:00
|
|
|
static int omap_pcm_new(struct snd_soc_pcm_runtime *rtd)
|
2008-04-25 19:55:19 +08:00
|
|
|
{
|
2011-06-07 23:08:33 +08:00
|
|
|
struct snd_card *card = rtd->card->snd_card;
|
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
2008-04-25 19:55:19 +08:00
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
if (!card->dev->dma_mask)
|
|
|
|
card->dev->dma_mask = &omap_pcm_dmamask;
|
|
|
|
if (!card->dev->coherent_dma_mask)
|
2009-08-20 21:18:22 +08:00
|
|
|
card->dev->coherent_dma_mask = DMA_BIT_MASK(64);
|
2008-04-25 19:55:19 +08:00
|
|
|
|
2012-01-01 08:58:44 +08:00
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
|
2008-04-25 19:55:19 +08:00
|
|
|
ret = omap_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_PLAYBACK);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
2012-01-01 08:58:44 +08:00
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
|
2008-04-25 19:55:19 +08:00
|
|
|
ret = omap_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
if (ret)
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
2012-04-25 10:02:02 +08:00
|
|
|
/* free preallocated buffers in case of error */
|
|
|
|
if (ret)
|
|
|
|
omap_pcm_free_dma_buffers(pcm);
|
|
|
|
|
2008-04-25 19:55:19 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static struct snd_soc_platform_driver omap_soc_platform = {
|
|
|
|
.ops = &omap_pcm_ops,
|
2008-04-25 19:55:19 +08:00
|
|
|
.pcm_new = omap_pcm_new,
|
|
|
|
.pcm_free = omap_pcm_free_dma_buffers,
|
|
|
|
};
|
|
|
|
|
2012-12-07 22:26:29 +08:00
|
|
|
static int omap_pcm_probe(struct platform_device *pdev)
|
2010-03-18 04:15:21 +08:00
|
|
|
{
|
|
|
|
return snd_soc_register_platform(&pdev->dev,
|
|
|
|
&omap_soc_platform);
|
|
|
|
}
|
|
|
|
|
2012-12-07 22:26:29 +08:00
|
|
|
static int omap_pcm_remove(struct platform_device *pdev)
|
2010-03-18 04:15:21 +08:00
|
|
|
{
|
|
|
|
snd_soc_unregister_platform(&pdev->dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct platform_driver omap_pcm_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "omap-pcm-audio",
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
},
|
|
|
|
|
|
|
|
.probe = omap_pcm_probe,
|
2012-12-07 22:26:29 +08:00
|
|
|
.remove = omap_pcm_remove,
|
2010-03-18 04:15:21 +08:00
|
|
|
};
|
|
|
|
|
2011-11-25 10:12:16 +08:00
|
|
|
module_platform_driver(omap_pcm_driver);
|
2008-12-04 03:58:17 +08:00
|
|
|
|
2011-08-11 20:44:57 +08:00
|
|
|
MODULE_AUTHOR("Jarkko Nikula <jarkko.nikula@bitmer.com>");
|
2008-04-25 19:55:19 +08:00
|
|
|
MODULE_DESCRIPTION("OMAP PCM DMA module");
|
|
|
|
MODULE_LICENSE("GPL");
|
2012-07-12 21:08:16 +08:00
|
|
|
MODULE_ALIAS("platform:omap-pcm-audio");
|