2009-11-25 08:41:04 -07:00
|
|
|
/*
|
|
|
|
* imx-pcm-fiq.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 02:04:11 -06:00
|
|
|
#include <linux/slab.h>
|
2009-11-25 08:41:04 -07:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include <asm/fiq.h>
|
|
|
|
|
|
|
|
#include <mach/ssi.h>
|
|
|
|
|
|
|
|
#include "imx-ssi.h"
|
|
|
|
|
|
|
|
struct imx_pcm_runtime_data {
|
|
|
|
int period;
|
|
|
|
int periods;
|
|
|
|
unsigned long offset;
|
2010-02-25 05:52:10 -07:00
|
|
|
unsigned long last_offset;
|
2009-11-25 08:41:04 -07:00
|
|
|
unsigned long size;
|
2010-04-08 03:31:26 -06:00
|
|
|
struct hrtimer hrt;
|
|
|
|
int poll_time_ns;
|
|
|
|
struct snd_pcm_substream *substream;
|
2010-04-14 01:17:30 -06:00
|
|
|
atomic_t running;
|
2009-11-25 08:41:04 -07:00
|
|
|
};
|
|
|
|
|
2010-04-08 03:31:26 -06:00
|
|
|
static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
|
2010-02-25 05:52:10 -07:00
|
|
|
{
|
2010-04-08 03:31:26 -06:00
|
|
|
struct imx_pcm_runtime_data *iprtd =
|
|
|
|
container_of(hrt, struct imx_pcm_runtime_data, hrt);
|
|
|
|
struct snd_pcm_substream *substream = iprtd->substream;
|
2009-11-25 08:41:04 -07:00
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct pt_regs regs;
|
2010-02-25 05:52:10 -07:00
|
|
|
unsigned long delta;
|
2009-11-25 08:41:04 -07:00
|
|
|
|
2010-04-14 01:17:30 -06:00
|
|
|
if (!atomic_read(&iprtd->running))
|
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
|
2009-11-25 08:41:04 -07:00
|
|
|
get_fiq_regs(®s);
|
|
|
|
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
iprtd->offset = regs.ARM_r8 & 0xffff;
|
|
|
|
else
|
|
|
|
iprtd->offset = regs.ARM_r9 & 0xffff;
|
|
|
|
|
2010-02-25 05:52:10 -07:00
|
|
|
/* How much data have we transferred since the last period report? */
|
|
|
|
if (iprtd->offset >= iprtd->last_offset)
|
|
|
|
delta = iprtd->offset - iprtd->last_offset;
|
|
|
|
else
|
|
|
|
delta = runtime->buffer_size + iprtd->offset
|
|
|
|
- iprtd->last_offset;
|
|
|
|
|
|
|
|
/* If we've transferred at least a period then report it and
|
|
|
|
* reset our poll time */
|
2010-04-08 03:31:26 -06:00
|
|
|
if (delta >= iprtd->period) {
|
2010-02-25 05:52:10 -07:00
|
|
|
snd_pcm_period_elapsed(substream);
|
|
|
|
iprtd->last_offset = iprtd->offset;
|
|
|
|
}
|
|
|
|
|
2010-04-08 03:31:26 -06:00
|
|
|
hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns));
|
2010-02-25 05:52:10 -07:00
|
|
|
|
2010-04-08 03:31:26 -06:00
|
|
|
return HRTIMER_RESTART;
|
2009-11-25 08:41:04 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct fiq_handler fh = {
|
|
|
|
.name = DRV_NAME,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,
|
|
|
|
struct snd_pcm_hw_params *params)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
|
|
|
|
|
|
|
|
iprtd->size = params_buffer_bytes(params);
|
|
|
|
iprtd->periods = params_periods(params);
|
2010-02-25 05:52:10 -07:00
|
|
|
iprtd->period = params_period_bytes(params) ;
|
2009-11-25 08:41:04 -07:00
|
|
|
iprtd->offset = 0;
|
2010-02-25 05:52:10 -07:00
|
|
|
iprtd->last_offset = 0;
|
2010-04-08 03:31:26 -06:00
|
|
|
iprtd->poll_time_ns = 1000000000 / params_rate(params) *
|
|
|
|
params_period_size(params);
|
2009-11-25 08:41:04 -07:00
|
|
|
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int snd_imx_pcm_prepare(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
|
|
|
|
struct pt_regs regs;
|
|
|
|
|
|
|
|
get_fiq_regs(®s);
|
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
regs.ARM_r8 = (iprtd->period * iprtd->periods - 1) << 16;
|
|
|
|
else
|
|
|
|
regs.ARM_r9 = (iprtd->period * iprtd->periods - 1) << 16;
|
|
|
|
|
|
|
|
set_fiq_regs(®s);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int fiq_enable;
|
|
|
|
static int imx_pcm_fiq;
|
|
|
|
|
|
|
|
static int snd_imx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
|
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
case SNDRV_PCM_TRIGGER_START:
|
|
|
|
case SNDRV_PCM_TRIGGER_RESUME:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
|
2010-04-14 01:17:30 -06:00
|
|
|
atomic_set(&iprtd->running, 1);
|
2010-04-08 03:31:26 -06:00
|
|
|
hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
|
|
|
|
HRTIMER_MODE_REL);
|
2009-11-25 08:41:04 -07:00
|
|
|
if (++fiq_enable == 1)
|
|
|
|
enable_fiq(imx_pcm_fiq);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
2010-04-14 01:17:30 -06:00
|
|
|
atomic_set(&iprtd->running, 0);
|
|
|
|
|
2009-11-25 08:41:04 -07:00
|
|
|
if (--fiq_enable == 0)
|
|
|
|
disable_fiq(imx_pcm_fiq);
|
|
|
|
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static snd_pcm_uframes_t snd_imx_pcm_pointer(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct imx_pcm_runtime_data *iprtd = runtime->private_data;
|
|
|
|
|
|
|
|
return bytes_to_frames(substream->runtime, iprtd->offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
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,
|
|
|
|
.period_bytes_max = 16 * 1024,
|
2010-04-14 01:17:31 -06:00
|
|
|
.periods_min = 4,
|
2009-11-25 08:41:04 -07:00
|
|
|
.periods_max = 255,
|
|
|
|
.fifo_size = 0,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int snd_imx_open(struct snd_pcm_substream *substream)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
struct imx_pcm_runtime_data *iprtd;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL);
|
2010-07-16 10:16:54 -06:00
|
|
|
if (iprtd == NULL)
|
|
|
|
return -ENOMEM;
|
2009-11-25 08:41:04 -07:00
|
|
|
runtime->private_data = iprtd;
|
|
|
|
|
2010-04-08 03:31:26 -06:00
|
|
|
iprtd->substream = substream;
|
|
|
|
|
2010-04-14 01:17:30 -06:00
|
|
|
atomic_set(&iprtd->running, 0);
|
2010-04-08 03:31:26 -06:00
|
|
|
hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
iprtd->hrt.function = snd_hrtimer_callback;
|
2009-11-25 08:41:04 -07:00
|
|
|
|
|
|
|
ret = snd_pcm_hw_constraint_integer(substream->runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
2010-07-16 10:16:54 -06:00
|
|
|
if (ret < 0) {
|
|
|
|
kfree(iprtd);
|
2009-11-25 08:41:04 -07:00
|
|
|
return ret;
|
2010-07-16 10:16:54 -06:00
|
|
|
}
|
2009-11-25 08:41:04 -07:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2010-04-08 03:31:26 -06:00
|
|
|
hrtimer_cancel(&iprtd->hrt);
|
|
|
|
|
2009-11-25 08:41:04 -07:00
|
|
|
kfree(iprtd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_pcm_ops imx_pcm_ops = {
|
|
|
|
.open = snd_imx_open,
|
|
|
|
.close = snd_imx_close,
|
|
|
|
.ioctl = snd_pcm_lib_ioctl,
|
|
|
|
.hw_params = snd_imx_pcm_hw_params,
|
|
|
|
.prepare = snd_imx_pcm_prepare,
|
|
|
|
.trigger = snd_imx_pcm_trigger,
|
|
|
|
.pointer = snd_imx_pcm_pointer,
|
|
|
|
.mmap = snd_imx_pcm_mmap,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int imx_pcm_fiq_new(struct snd_card *card, struct snd_soc_dai *dai,
|
|
|
|
struct snd_pcm *pcm)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = imx_pcm_new(card, dai, pcm);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (dai->playback.channels_min) {
|
|
|
|
struct snd_pcm_substream *substream =
|
|
|
|
pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
|
|
|
struct snd_dma_buffer *buf = &substream->dma_buffer;
|
|
|
|
|
|
|
|
imx_ssi_fiq_tx_buffer = (unsigned long)buf->area;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dai->capture.channels_min) {
|
|
|
|
struct snd_pcm_substream *substream =
|
|
|
|
pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
|
|
|
|
struct snd_dma_buffer *buf = &substream->dma_buffer;
|
|
|
|
|
|
|
|
imx_ssi_fiq_rx_buffer = (unsigned long)buf->area;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_fiq_handler(&imx_ssi_fiq_start,
|
|
|
|
&imx_ssi_fiq_end - &imx_ssi_fiq_start);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_platform imx_soc_platform_fiq = {
|
|
|
|
.pcm_ops = &imx_pcm_ops,
|
|
|
|
.pcm_new = imx_pcm_fiq_new,
|
|
|
|
.pcm_free = imx_pcm_free,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct snd_soc_platform *imx_ssi_fiq_init(struct platform_device *pdev,
|
|
|
|
struct imx_ssi *ssi)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
ret = claim_fiq(&fh);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to claim fiq: %d", ret);
|
|
|
|
return ERR_PTR(ret);
|
|
|
|
}
|
|
|
|
|
|
|
|
mxc_set_irq_fiq(ssi->irq, 1);
|
|
|
|
|
|
|
|
imx_pcm_fiq = ssi->irq;
|
|
|
|
|
|
|
|
imx_ssi_fiq_base = (unsigned long)ssi->base;
|
|
|
|
|
|
|
|
ssi->dma_params_tx.burstsize = 4;
|
|
|
|
ssi->dma_params_rx.burstsize = 6;
|
|
|
|
|
|
|
|
return &imx_soc_platform_fiq;
|
|
|
|
}
|
|
|
|
|
|
|
|
void imx_ssi_fiq_exit(struct platform_device *pdev,
|
|
|
|
struct imx_ssi *ssi)
|
|
|
|
{
|
|
|
|
mxc_set_irq_fiq(ssi->irq, 0);
|
|
|
|
release_fiq(&fh);
|
|
|
|
}
|
|
|
|
|