2009-11-25 22: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 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2009-11-25 22:41:04 +07:00
|
|
|
|
|
|
|
#include <sound/core.h>
|
2013-06-20 20:20:21 +07:00
|
|
|
#include <sound/dmaengine_pcm.h>
|
2009-11-25 22:41:04 +07: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 20:14:29 +07:00
|
|
|
#include <linux/platform_data/asoc-imx-ssi.h>
|
2009-11-25 22:41:04 +07:00
|
|
|
|
|
|
|
#include "imx-ssi.h"
|
2013-06-20 20:20:21 +07:00
|
|
|
#include "imx-pcm.h"
|
2009-11-25 22:41:04 +07:00
|
|
|
|
|
|
|
struct imx_pcm_runtime_data {
|
2013-03-20 12:22:40 +07:00
|
|
|
unsigned int period;
|
2009-11-25 22:41:04 +07:00
|
|
|
int periods;
|
|
|
|
unsigned long offset;
|
2010-04-08 16:31:26 +07: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 22:46:38 +07:00
|
|
|
atomic_t playing;
|
|
|
|
atomic_t capturing;
|
2009-11-25 22:41:04 +07:00
|
|
|
};
|
|
|
|
|
2010-04-08 16:31:26 +07:00
|
|
|
static enum hrtimer_restart snd_hrtimer_callback(struct hrtimer *hrt)
|
2010-02-25 19:52:10 +07:00
|
|
|
{
|
2010-04-08 16:31:26 +07: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 22:41:04 +07: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 22:46:38 +07:00
|
|
|
if (!atomic_read(&iprtd->playing) && !atomic_read(&iprtd->capturing))
|
2010-04-14 14:17:30 +07:00
|
|
|
return HRTIMER_NORESTART;
|
|
|
|
|
2009-11-25 22: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;
|
|
|
|
|
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 19:13:54 +07:00
|
|
|
snd_pcm_period_elapsed(substream);
|
2010-02-25 19:52:10 +07:00
|
|
|
|
2010-04-08 16:31:26 +07:00
|
|
|
hrtimer_forward_now(hrt, ns_to_ktime(iprtd->poll_time_ns));
|
2010-02-25 19:52:10 +07:00
|
|
|
|
2010-04-08 16:31:26 +07:00
|
|
|
return HRTIMER_RESTART;
|
2009-11-25 22: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->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 19:13:54 +07:00
|
|
|
iprtd->period = params_period_bytes(params);
|
2009-11-25 22:41:04 +07:00
|
|
|
iprtd->offset = 0;
|
2010-04-08 16:31:26 +07:00
|
|
|
iprtd->poll_time_ns = 1000000000 / params_rate(params) *
|
|
|
|
params_period_size(params);
|
2009-11-25 22: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 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 22:46:38 +07:00
|
|
|
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
|
|
|
|
atomic_set(&iprtd->playing, 1);
|
|
|
|
else
|
|
|
|
atomic_set(&iprtd->capturing, 1);
|
2010-04-08 16:31:26 +07: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 22:46:38 +07:00
|
|
|
enable_fiq(imx_pcm_fiq);
|
2009-11-25 22:41:04 +07: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 22:46:38 +07: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 22:41:04 +07: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 22:46:38 +07:00
|
|
|
|
2009-11-25 22:41:04 +07: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);
|
|
|
|
}
|
|
|
|
|
2017-08-17 17:16:07 +07:00
|
|
|
static const struct snd_pcm_hardware snd_imx_hardware = {
|
2009-11-25 22:41:04 +07:00
|
|
|
.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 14:17:31 +07:00
|
|
|
.periods_min = 4,
|
2009-11-25 22: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 23:16:54 +07:00
|
|
|
if (iprtd == NULL)
|
|
|
|
return -ENOMEM;
|
2009-11-25 22:41:04 +07:00
|
|
|
runtime->private_data = iprtd;
|
|
|
|
|
2010-04-08 16:31:26 +07: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 22:46:38 +07:00
|
|
|
atomic_set(&iprtd->playing, 0);
|
|
|
|
atomic_set(&iprtd->capturing, 0);
|
2010-04-08 16:31:26 +07:00
|
|
|
hrtimer_init(&iprtd->hrt, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
|
|
|
|
iprtd->hrt.function = snd_hrtimer_callback;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
|
|
|
ret = snd_pcm_hw_constraint_integer(substream->runtime,
|
|
|
|
SNDRV_PCM_HW_PARAM_PERIODS);
|
2010-07-16 23:16:54 +07:00
|
|
|
if (ret < 0) {
|
|
|
|
kfree(iprtd);
|
2009-11-25 22:41:04 +07:00
|
|
|
return ret;
|
2010-07-16 23:16:54 +07:00
|
|
|
}
|
2009-11-25 22: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 16:31:26 +07:00
|
|
|
hrtimer_cancel(&iprtd->hrt);
|
|
|
|
|
2009-11-25 22:41:04 +07:00
|
|
|
kfree(iprtd);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-25 10:18:50 +07: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;
|
|
|
|
|
dma, mm/pat: Rename dma_*_writecombine() to dma_*_wc()
Rename dma_*_writecombine() to dma_*_wc(), so that the naming
is coherent across the various write-combining APIs. Keep the
old names for compatibility for a while, these can be removed
at a later time. A guard is left to enable backporting of the
rename, and later remove of the old mapping defines seemlessly.
Build tested successfully with allmodconfig.
The following Coccinelle SmPL patch was used for this simple
transformation:
@ rename_dma_alloc_writecombine @
expression dev, size, dma_addr, gfp;
@@
-dma_alloc_writecombine(dev, size, dma_addr, gfp)
+dma_alloc_wc(dev, size, dma_addr, gfp)
@ rename_dma_free_writecombine @
expression dev, size, cpu_addr, dma_addr;
@@
-dma_free_writecombine(dev, size, cpu_addr, dma_addr)
+dma_free_wc(dev, size, cpu_addr, dma_addr)
@ rename_dma_mmap_writecombine @
expression dev, vma, cpu_addr, dma_addr, size;
@@
-dma_mmap_writecombine(dev, vma, cpu_addr, dma_addr, size)
+dma_mmap_wc(dev, vma, cpu_addr, dma_addr, size)
We also keep the old names as compatibility helpers, and
guard against their definition to make backporting easier.
Generated-by: Coccinelle SmPL
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bhelgaas@google.com
Cc: bp@suse.de
Cc: dan.j.williams@intel.com
Cc: daniel.vetter@ffwll.ch
Cc: dhowells@redhat.com
Cc: julia.lawall@lip6.fr
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: luto@amacapital.net
Cc: mst@redhat.com
Cc: tomi.valkeinen@ti.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1453516462-4844-1-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-23 09:34:22 +07:00
|
|
|
ret = dma_mmap_wc(substream->pcm->card->dev, vma, runtime->dma_area,
|
|
|
|
runtime->dma_addr, runtime->dma_bytes);
|
2013-04-25 10:18:50 +07:00
|
|
|
|
2016-04-13 03:51:03 +07:00
|
|
|
pr_debug("%s: ret: %d %p %pad 0x%08zx\n", __func__, ret,
|
2013-04-25 10:18:50 +07:00
|
|
|
runtime->dma_area,
|
2015-12-08 22:35:51 +07:00
|
|
|
&runtime->dma_addr,
|
2013-04-25 10:18:50 +07:00
|
|
|
runtime->dma_bytes);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2017-08-14 12:56:26 +07:00
|
|
|
static const struct snd_pcm_ops imx_pcm_ops = {
|
2009-11-25 22:41:04 +07:00
|
|
|
.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 10:18:50 +07: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;
|
dma, mm/pat: Rename dma_*_writecombine() to dma_*_wc()
Rename dma_*_writecombine() to dma_*_wc(), so that the naming
is coherent across the various write-combining APIs. Keep the
old names for compatibility for a while, these can be removed
at a later time. A guard is left to enable backporting of the
rename, and later remove of the old mapping defines seemlessly.
Build tested successfully with allmodconfig.
The following Coccinelle SmPL patch was used for this simple
transformation:
@ rename_dma_alloc_writecombine @
expression dev, size, dma_addr, gfp;
@@
-dma_alloc_writecombine(dev, size, dma_addr, gfp)
+dma_alloc_wc(dev, size, dma_addr, gfp)
@ rename_dma_free_writecombine @
expression dev, size, cpu_addr, dma_addr;
@@
-dma_free_writecombine(dev, size, cpu_addr, dma_addr)
+dma_free_wc(dev, size, cpu_addr, dma_addr)
@ rename_dma_mmap_writecombine @
expression dev, vma, cpu_addr, dma_addr, size;
@@
-dma_mmap_writecombine(dev, vma, cpu_addr, dma_addr, size)
+dma_mmap_wc(dev, vma, cpu_addr, dma_addr, size)
We also keep the old names as compatibility helpers, and
guard against their definition to make backporting easier.
Generated-by: Coccinelle SmPL
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bhelgaas@google.com
Cc: bp@suse.de
Cc: dan.j.williams@intel.com
Cc: daniel.vetter@ffwll.ch
Cc: dhowells@redhat.com
Cc: julia.lawall@lip6.fr
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: luto@amacapital.net
Cc: mst@redhat.com
Cc: tomi.valkeinen@ti.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1453516462-4844-1-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-23 09:34:22 +07:00
|
|
|
buf->area = dma_alloc_wc(pcm->card->dev, size, &buf->addr, GFP_KERNEL);
|
2013-04-25 10:18:50 +07:00
|
|
|
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 18:53:37 +07:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2013-04-25 10:18:50 +07: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 10:20:43 +07:00
|
|
|
return ret;
|
2013-04-25 10:18:50 +07: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 10:20:43 +07:00
|
|
|
return ret;
|
2013-04-25 10:18:50 +07:00
|
|
|
}
|
|
|
|
|
2014-02-24 10:20:43 +07:00
|
|
|
return 0;
|
2013-04-25 10:18:50 +07:00
|
|
|
}
|
|
|
|
|
2017-02-25 17:47:26 +07:00
|
|
|
static int ssi_irq;
|
2010-03-18 03:15:21 +07:00
|
|
|
|
2011-06-07 22:08:33 +07:00
|
|
|
static int imx_pcm_fiq_new(struct snd_soc_pcm_runtime *rtd)
|
2009-11-25 22:41:04 +07:00
|
|
|
{
|
2011-06-07 22:08:33 +07:00
|
|
|
struct snd_pcm *pcm = rtd->pcm;
|
2011-08-25 20:54:56 +07:00
|
|
|
struct snd_pcm_substream *substream;
|
2009-11-25 22:41:04 +07:00
|
|
|
int ret;
|
|
|
|
|
2011-06-07 22:08:33 +07:00
|
|
|
ret = imx_pcm_new(rtd);
|
2009-11-25 22:41:04 +07:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2011-08-25 20:54:56 +07:00
|
|
|
substream = pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream;
|
|
|
|
if (substream) {
|
2009-11-25 22:41:04 +07:00
|
|
|
struct snd_dma_buffer *buf = &substream->dma_buffer;
|
|
|
|
|
|
|
|
imx_ssi_fiq_tx_buffer = (unsigned long)buf->area;
|
|
|
|
}
|
|
|
|
|
2011-08-25 20:54:56 +07:00
|
|
|
substream = pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream;
|
|
|
|
if (substream) {
|
2009-11-25 22:41:04 +07: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 10:18:50 +07: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, mm/pat: Rename dma_*_writecombine() to dma_*_wc()
Rename dma_*_writecombine() to dma_*_wc(), so that the naming
is coherent across the various write-combining APIs. Keep the
old names for compatibility for a while, these can be removed
at a later time. A guard is left to enable backporting of the
rename, and later remove of the old mapping defines seemlessly.
Build tested successfully with allmodconfig.
The following Coccinelle SmPL patch was used for this simple
transformation:
@ rename_dma_alloc_writecombine @
expression dev, size, dma_addr, gfp;
@@
-dma_alloc_writecombine(dev, size, dma_addr, gfp)
+dma_alloc_wc(dev, size, dma_addr, gfp)
@ rename_dma_free_writecombine @
expression dev, size, cpu_addr, dma_addr;
@@
-dma_free_writecombine(dev, size, cpu_addr, dma_addr)
+dma_free_wc(dev, size, cpu_addr, dma_addr)
@ rename_dma_mmap_writecombine @
expression dev, vma, cpu_addr, dma_addr, size;
@@
-dma_mmap_writecombine(dev, vma, cpu_addr, dma_addr, size)
+dma_mmap_wc(dev, vma, cpu_addr, dma_addr, size)
We also keep the old names as compatibility helpers, and
guard against their definition to make backporting easier.
Generated-by: Coccinelle SmPL
Suggested-by: Ingo Molnar <mingo@kernel.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@suse.com>
Cc: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: airlied@linux.ie
Cc: akpm@linux-foundation.org
Cc: benh@kernel.crashing.org
Cc: bhelgaas@google.com
Cc: bp@suse.de
Cc: dan.j.williams@intel.com
Cc: daniel.vetter@ffwll.ch
Cc: dhowells@redhat.com
Cc: julia.lawall@lip6.fr
Cc: konrad.wilk@oracle.com
Cc: linux-fbdev@vger.kernel.org
Cc: linux-pci@vger.kernel.org
Cc: luto@amacapital.net
Cc: mst@redhat.com
Cc: tomi.valkeinen@ti.com
Cc: toshi.kani@hp.com
Cc: vinod.koul@intel.com
Cc: xen-devel@lists.xensource.com
Link: http://lkml.kernel.org/r/1453516462-4844-1-git-send-email-mcgrof@do-not-panic.com
Signed-off-by: Ingo Molnar <mingo@kernel.org>
2016-01-23 09:34:22 +07:00
|
|
|
dma_free_wc(pcm->card->dev, buf->bytes, buf->area, buf->addr);
|
2013-04-25 10:18:50 +07:00
|
|
|
buf->area = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-18 03:15:21 +07: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);
|
|
|
|
}
|
|
|
|
|
2017-08-14 18:38:42 +07:00
|
|
|
static const struct snd_soc_platform_driver imx_soc_platform_fiq = {
|
2010-03-18 03:15:21 +07:00
|
|
|
.ops = &imx_pcm_ops,
|
2009-11-25 22:41:04 +07:00
|
|
|
.pcm_new = imx_pcm_fiq_new,
|
2010-03-18 03:15:21 +07:00
|
|
|
.pcm_free = imx_pcm_fiq_free,
|
2009-11-25 22:41:04 +07:00
|
|
|
};
|
|
|
|
|
2013-06-20 20:20:21 +07:00
|
|
|
int imx_pcm_fiq_init(struct platform_device *pdev,
|
|
|
|
struct imx_pcm_fiq_params *params)
|
2009-11-25 22:41:04 +07:00
|
|
|
{
|
2010-03-18 03:15:21 +07:00
|
|
|
int ret;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
|
|
|
ret = claim_fiq(&fh);
|
|
|
|
if (ret) {
|
|
|
|
dev_err(&pdev->dev, "failed to claim fiq: %d", ret);
|
2010-03-18 03:15:21 +07:00
|
|
|
return ret;
|
2009-11-25 22:41:04 +07:00
|
|
|
}
|
|
|
|
|
2013-06-20 20:20:21 +07:00
|
|
|
mxc_set_irq_fiq(params->irq, 1);
|
|
|
|
ssi_irq = params->irq;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
2013-06-20 20:20:21 +07:00
|
|
|
imx_pcm_fiq = params->irq;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
2013-06-20 20:20:21 +07:00
|
|
|
imx_ssi_fiq_base = (unsigned long)params->base;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
2013-06-20 20:20:21 +07:00
|
|
|
params->dma_params_tx->maxburst = 4;
|
|
|
|
params->dma_params_rx->maxburst = 6;
|
2009-11-25 22:41:04 +07:00
|
|
|
|
2010-03-18 03:15:21 +07: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 22:41:04 +07:00
|
|
|
}
|
2013-04-25 10:18:50 +07:00
|
|
|
EXPORT_SYMBOL_GPL(imx_pcm_fiq_init);
|
2013-04-25 10:18:48 +07:00
|
|
|
|
|
|
|
void imx_pcm_fiq_exit(struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
snd_soc_unregister_platform(&pdev->dev);
|
|
|
|
}
|
2013-04-25 10:18:50 +07:00
|
|
|
EXPORT_SYMBOL_GPL(imx_pcm_fiq_exit);
|
2013-08-16 18:07:19 +07:00
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|