2009-11-25 23:41:04 +08: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 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
2013-06-20 21:20:21 +08:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
#include <sound/initval.h>
|
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/pcm_params.h>
|
|
|
|
#include <sound/soc.h>
|
|
|
|
|
|
|
|
#include <asm/fiq.h>
|
|
|
|
|
2012-08-24 21:14:29 +08:00
|
|
|
#include <linux/platform_data/asoc-imx-ssi.h>
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
#include "imx-ssi.h"
|
2013-06-20 21:20:21 +08:00
|
|
|
#include "imx-pcm.h"
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
struct imx_pcm_runtime_data {
|
2013-03-20 13:22:40 +08:00
|
|
|
unsigned int period;
|
2009-11-25 23:41:04 +08:00
|
|
|
int periods;
|
|
|
|
unsigned long offset;
|
2010-04-08 17:31:26 +08:00
|
|
|
struct hrtimer hrt;
|
|
|
|
int poll_time_ns;
|
|
|
|
struct snd_pcm_substream *substream;
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
atomic_t playing;
|
|
|
|
atomic_t capturing;
|
2009-11-25 23:41:04 +08:00
|
|
|
};
|
|
|
|
|
2010-04-08 17:31:26 +08:00
|
|
|
static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
|
2010-02-25 20:52:10 +08:00
|
|
|
{
|
2010-04-08 17:31:26 +08: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 23:41:04 +08:00
|
|
|
struct pt_regs regs;
|
|
|
|
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
|
2010-04-14 15:17:30 +08:00
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
|
2009-11-25 23:41:04 +08: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;
|
|
|
|
|
ASoC: fsl: imx-pcm-fiq: remove bogus period delta calculation
Originally snd_hrtimer_callback() used iprtd->period_time for
some jiffies based estimation to determine the right moment
to call snd_pcm_period_elapsed(). As timer drifts may well be a
problem, this was changed in commit b4e82b5b785670b6 to be based
on buffer transmission progress, using iprtd->offset and
runtime->buffer_size to calculate the amount of data since last
period had elapsed.
Unfortunately, iprtd->offset counts in bytes, while
runtime->buffer_size counts frames, so adding these to find some
delta is like comparing apples and oranges, and eventually results
in negative delta values every now and then. This is no big harm,
because it simply causes snd_pcm_period_elapsed() being called
more often than necessary, as negative delta is taken for a
large unsigned value by implicit conversion rule.
Nonetheless, the calculation is broken, so one would replace
the runtime->buffer_size by its equivalent in bytes.
But then, there are chances snd_pcm_period_elapsed() is called
late, because calculating the moment for the elapsed period
into delta is based against the iprtd->last_offset, which is not
necessarily the first byte of the period in question, but some
random byte which the FIQ handler left us with in r8/r9 by
accident. Again, negative impact is low, as there are plenty of
periods already prefilled with data, and snd_pcm_period_elapsed()
will probably be called latest when the following period is
reached. However, the calculation is conceptually broken, and we
are best off removing the clever stuff altogether.
snd_pcm_period_elapsed() is now simply called once everytime
snd_hrtimer_callback() is run, which may not be most accurate,
but at least this way we are quite sure we dont miss an end of
period. There is not much extra effort wasted by superfluous
calls to snd_pcm_period_elapsed(), as the timer frequency
closely matches the period size anyway.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-05 20:13:54 +08:00
|
|
|
snd_pcm_period_elapsed(substream);
|
2010-02-25 20:52:10 +08:00
|
|
|
|
2010-04-08 17:31:26 +08:00
|
|
|
hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns));
|
2010-02-25 20:52:10 +08:00
|
|
|
|
2010-04-08 17:31:26 +08:00
|
|
|
return HRTIMER_RESTART;
|
2009-11-25 23:41:04 +08: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->periods = params_periods(params);
|
ASoC: fsl: imx-pcm-fiq: remove bogus period delta calculation
Originally snd_hrtimer_callback() used iprtd->period_time for
some jiffies based estimation to determine the right moment
to call snd_pcm_period_elapsed(). As timer drifts may well be a
problem, this was changed in commit b4e82b5b785670b6 to be based
on buffer transmission progress, using iprtd->offset and
runtime->buffer_size to calculate the amount of data since last
period had elapsed.
Unfortunately, iprtd->offset counts in bytes, while
runtime->buffer_size counts frames, so adding these to find some
delta is like comparing apples and oranges, and eventually results
in negative delta values every now and then. This is no big harm,
because it simply causes snd_pcm_period_elapsed() being called
more often than necessary, as negative delta is taken for a
large unsigned value by implicit conversion rule.
Nonetheless, the calculation is broken, so one would replace
the runtime->buffer_size by its equivalent in bytes.
But then, there are chances snd_pcm_period_elapsed() is called
late, because calculating the moment for the elapsed period
into delta is based against the iprtd->last_offset, which is not
necessarily the first byte of the period in question, but some
random byte which the FIQ handler left us with in r8/r9 by
accident. Again, negative impact is low, as there are plenty of
periods already prefilled with data, and snd_pcm_period_elapsed()
will probably be called latest when the following period is
reached. However, the calculation is conceptually broken, and we
are best off removing the clever stuff altogether.
snd_pcm_period_elapsed() is now simply called once everytime
snd_hrtimer_callback() is run, which may not be most accurate,
but at least this way we are quite sure we dont miss an end of
period. There is not much extra effort wasted by superfluous
calls to snd_pcm_period_elapsed(), as the timer frequency
closely matches the period size anyway.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
2013-11-05 20:13:54 +08:00
|
|
|
iprtd->period = params_period_bytes(params);
|
2009-11-25 23:41:04 +08:00
|
|
|
iprtd->offset = 0;
|
2010-04-08 17:31:26 +08:00
|
|
|
iprtd->poll_time_ns = 1000000000 / params_rate(params) *
|
|
|
|
params_period_size(params);
|
2009-11-25 23:41:04 +08: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 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:
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
atomic_set(&iprtd->playing, 1);
|
|
|
|
else
|
|
|
|
atomic_set(&iprtd->capturing, 1);
|
2010-04-08 17:31:26 +08:00
|
|
|
hrtimer_start(&iprtd->hrt, ns_to_ktime(iprtd->poll_time_ns),
|
|
|
|
HRTIMER_MODE_REL);
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
enable_fiq(imx_pcm_fiq);
|
2009-11-25 23:41:04 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SNDRV_PCM_TRIGGER_STOP:
|
|
|
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
|
|
|
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
atomic_set(&iprtd->playing, 0);
|
|
|
|
else
|
|
|
|
atomic_set(&iprtd->capturing, 0);
|
|
|
|
if (!atomic_read(&iprtd->playing) &&
|
|
|
|
!atomic_read(&iprtd->capturing))
|
2009-11-25 23:41:04 +08:00
|
|
|
disable_fiq(imx_pcm_fiq);
|
|
|
|
break;
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
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,
|
|
|
|
.buffer_bytes_max = IMX_SSI_DMABUF_SIZE,
|
|
|
|
.period_bytes_min = 128,
|
|
|
|
.period_bytes_max = 16 * 1024,
|
2010-04-14 15:17:31 +08:00
|
|
|
.periods_min = 4,
|
2009-11-25 23:41:04 +08: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-17 00:16:54 +08:00
|
|
|
if (iprtd == NULL)
|
|
|
|
return -ENOMEM;
|
2009-11-25 23:41:04 +08:00
|
|
|
runtime->private_data = iprtd;
|
|
|
|
|
2010-04-08 17:31:26 +08:00
|
|
|
iprtd->substream = substream;
|
|
|
|
|
ASoC: fsl: imx-pcm-fiq: omit fiq counter to avoid harm in unbalanced situations
Unbalanced calls to snd_imx_pcm_trigger() may result in endless
FIQ activity and thus provoke eternal sound. While on the first glance,
the switch statement looks pretty symmetric, the SUSPEND/RESUME
pair is not: the suspend case comes along snd_pcm_suspend_all(),
which for fsl/imx-pcm-fiq is called only at snd_soc_suspend(),
but the resume case originates straight from the SNDRV_PCM_IOCTL_RESUME.
This way userland may provoke an unbalanced resume, which might cause
the fiq_enable counter to increase and never return to zero again,
so eventually imx_pcm_fiq is never disabled.
Simply removing the fiq_enable will solve the problem, as long as
one never goes play and capture game simultaneously, but beware
trying both at once, the early TRIGGER_STOP will cut off the other
activity prematurely. So now playing and capturing is scrutinized
separately, instead of by counting.
Signed-off-by: Oskar Schirmer <oskar@scara.com>
Signed-off-by: Mark Brown <broonie@linaro.org>
Cc: stable@vger.kernel.org
2013-11-12 23:46:38 +08:00
|
|
|
atomic_set(&iprtd->playing, 0);
|
|
|
|
atomic_set(&iprtd->capturing, 0);
|
2010-04-08 17:31:26 +08:00
|
|
|
hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
iprtd->hrt.function = snd_hrtimer_callback;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
ret = snd_pcm_hw_constraint_integer(substream->runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
2010-07-17 00:16:54 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
kfree(iprtd);
|
2009-11-25 23:41:04 +08:00
|
|
|
return ret;
|
2010-07-17 00:16:54 +08:00
|
|
|
}
|
2009-11-25 23:41:04 +08: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 17:31:26 +08:00
|
|
|
hrtimer_cancel(&iprtd->hrt);
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
kfree(iprtd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-25 11:18:50 +08:00
|
|
|
static int snd_imx_pcm_mmap(struct snd_pcm_substream *substream,
|
|
|
|
struct vm_area_struct *vma)
|
|
|
|
{
|
|
|
|
struct snd_pcm_runtime *runtime = substream->runtime;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dma_mmap_writecombine(substream->pcm->card->dev, vma,
|
|
|
|
runtime->dma_area, runtime->dma_addr, runtime->dma_bytes);
|
|
|
|
|
|
|
|
pr_debug("%s: ret: %d %p 0x%08x 0x%08x\n", __func__, ret,
|
|
|
|
runtime->dma_area,
|
|
|
|
runtime->dma_addr,
|
|
|
|
runtime->dma_bytes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2009-11-25 23:41:04 +08:00
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2013-04-25 11:18:50 +08:00
|
|
|
static int imx_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 = IMX_SSI_DMABUF_SIZE;
|
|
|
|
|
|
|
|
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 int imx_pcm_new(struct snd_soc_pcm_runtime *rtd)
|
|
|
|
{
|
|
|
|
struct snd_card *card = rtd->card->snd_card;
|
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
2013-06-27 19:53:37 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-04-25 11:18:50 +08:00
|
|
|
|
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream) {
|
|
|
|
ret = imx_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_PLAYBACK);
|
|
|
|
if (ret)
|
2014-02-24 11:20:43 +08:00
|
|
|
return ret;
|
2013-04-25 11:18:50 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream) {
|
|
|
|
ret = imx_pcm_preallocate_dma_buffer(pcm,
|
|
|
|
SNDRV_PCM_STREAM_CAPTURE);
|
|
|
|
if (ret)
|
2014-02-24 11:20:43 +08:00
|
|
|
return ret;
|
2013-04-25 11:18:50 +08:00
|
|
|
}
|
|
|
|
|
2014-02-24 11:20:43 +08:00
|
|
|
return 0;
|
2013-04-25 11:18:50 +08:00
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static int ssi_irq = 0;
|
|
|
|
|
2011-06-07 23:08:33 +08:00
|
|
|
static int imx_pcm_fiq_new(struct snd_soc_pcm_runtime *rtd)
|
2009-11-25 23:41:04 +08:00
|
|
|
{
|
2011-06-07 23:08:33 +08:00
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
2011-08-25 21:54:56 +08:00
|
|
|
struct snd_pcm_substream *substream;
|
2009-11-25 23:41:04 +08:00
|
|
|
int ret;
|
|
|
|
|
2011-06-07 23:08:33 +08:00
|
|
|
ret = imx_pcm_new(rtd);
|
2009-11-25 23:41:04 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-08-25 21:54:56 +08:00
|
|
|
substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
|
|
|
if (substream) {
|
2009-11-25 23:41:04 +08:00
|
|
|
struct snd_dma_buffer *buf = &substream->dma_buffer;
|
|
|
|
|
|
|
|
imx_ssi_fiq_tx_buffer = (unsigned long)buf->area;
|
|
|
|
}
|
|
|
|
|
2011-08-25 21:54:56 +08:00
|
|
|
substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
|
|
|
|
if (substream) {
|
2009-11-25 23:41:04 +08:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2013-04-25 11:18:50 +08:00
|
|
|
static void imx_pcm_free(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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
static void imx_pcm_fiq_free(struct snd_pcm *pcm)
|
|
|
|
{
|
|
|
|
mxc_set_irq_fiq(ssi_irq, 0);
|
|
|
|
release_fiq(&fh);
|
|
|
|
imx_pcm_free(pcm);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct snd_soc_platform_driver imx_soc_platform_fiq = {
|
|
|
|
.ops = &imx_pcm_ops,
|
2009-11-25 23:41:04 +08:00
|
|
|
.pcm_new = imx_pcm_fiq_new,
|
2010-03-18 04:15:21 +08:00
|
|
|
.pcm_free = imx_pcm_fiq_free,
|
2009-11-25 23:41:04 +08:00
|
|
|
};
|
|
|
|
|
2013-06-20 21:20:21 +08:00
|
|
|
int imx_pcm_fiq_init(struct platform_device *pdev,
|
|
|
|
struct imx_pcm_fiq_params *params)
|
2009-11-25 23:41:04 +08:00
|
|
|
{
|
2010-03-18 04:15:21 +08:00
|
|
|
int ret;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
|
|
|
ret = claim_fiq(&fh);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to claim fiq: %d", ret);
|
2010-03-18 04:15:21 +08:00
|
|
|
return ret;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 21:20:21 +08:00
|
|
|
mxc_set_irq_fiq(params->irq, 1);
|
|
|
|
ssi_irq = params->irq;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2013-06-20 21:20:21 +08:00
|
|
|
imx_pcm_fiq = params->irq;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2013-06-20 21:20:21 +08:00
|
|
|
imx_ssi_fiq_base = (unsigned long)params->base;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2013-06-20 21:20:21 +08:00
|
|
|
params->dma_params_tx->maxburst = 4;
|
|
|
|
params->dma_params_rx->maxburst = 6;
|
2009-11-25 23:41:04 +08:00
|
|
|
|
2010-03-18 04:15:21 +08:00
|
|
|
ret = snd_soc_register_platform(&pdev->dev, &imx_soc_platform_fiq);
|
|
|
|
if (ret)
|
|
|
|
goto failed_register;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed_register:
|
|
|
|
mxc_set_irq_fiq(ssi_irq, 0);
|
|
|
|
release_fiq(&fh);
|
|
|
|
|
|
|
|
return ret;
|
2009-11-25 23:41:04 +08:00
|
|
|
}
|
2013-04-25 11:18:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(imx_pcm_fiq_init);
|
2013-04-25 11:18:48 +08:00
|
|
|
|
|
|
|
void imx_pcm_fiq_exit(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
snd_soc_unregister_platform(&pdev->dev);
|
|
|
|
}
|
2013-04-25 11:18:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(imx_pcm_fiq_exit);
|
2013-08-16 19:07:19 +08:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|