From: Matt Ranostay <matt@ranostay.consulting>
To: alsa-devel@alsa-project.org, linux-omap@vger.kernel.org
Cc: Tony Lindgren <tony@atomide.com>,
Peter Ujfalusi <peter.ujfalusi@ti.com>,
Matt Ranostay <matt@ranostay.consulting>
Subject: [PATCH v6] ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches
Date: Tue, 10 Jan 2017 21:46:00 -0800 [thread overview]
Message-ID: <20170111054600.12982-1-matt@ranostay.consulting> (raw)
We can get audio errors if hitting deeper idle states on omaps:
[alsa.c:230] error: Fatal problem with alsa output, error -5.
[audio.c:614] error: Error in writing audio (Input/output error?)!
This seems to happen with off mode idle enabled as power for the
whole SoC may get cut off between filling the McBSP fifo using DMA.
While active DMA blocks deeper idle states in hardware, McBSP
activity does not seem to do so.
Basing the QoS latency calculation on the FIFO size, threshold,
sample rate, and channels.
Based on the original patch by Tony Lindgren
Link: https://patchwork.kernel.org/patch/9305867/
Cc: Tony Lindgren <tony@atomide.com>
Cc: Peter Ujfalusi <peter.ujfalusi@ti.com>
Signed-off-by: Matt Ranostay <matt@ranostay.consulting>
---
hanges from v1:
* add calculations for latency per number of FIFO locations
Changes from v2:
* add missing mcbsp.h header change
Changes from v3:
* base the latency calculations on threshold, buffer size, sample
rate, and channels
Changes from v4:
* using Peter Ujfalusi's suggestions for restoring a higher latency on
audio stream completion, or if not applicable remove the QoS request
Changes from v5:
* clean up latency checking logic
* move logic to .prepare and .shutdown to avoid functions that can sleep
sound/soc/omap/mcbsp.c | 4 ++++
sound/soc/omap/mcbsp.h | 3 +++
sound/soc/omap/omap-mcbsp.c | 44 +++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 50 insertions(+), 1 deletion(-)
diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
index 06fec5699cc8..e1c3d21dc5ed 100644
--- a/sound/soc/omap/mcbsp.c
+++ b/sound/soc/omap/mcbsp.c
@@ -25,6 +25,7 @@
#include <linux/io.h>
#include <linux/slab.h>
#include <linux/pm_runtime.h>
+#include <linux/pm_qos.h>
#include <linux/platform_data/asoc-ti-mcbsp.h>
@@ -1098,6 +1099,9 @@ int omap_mcbsp_init(struct platform_device *pdev)
void omap_mcbsp_cleanup(struct omap_mcbsp *mcbsp)
{
+ if (pm_qos_request_active(&mcbsp->pm_qos_req))
+ pm_qos_remove_request(&mcbsp->pm_qos_req);
+
if (mcbsp->pdata->buffer_size)
sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
diff --git a/sound/soc/omap/mcbsp.h b/sound/soc/omap/mcbsp.h
index 61e93b1c185d..46ae1269a698 100644
--- a/sound/soc/omap/mcbsp.h
+++ b/sound/soc/omap/mcbsp.h
@@ -323,8 +323,11 @@ struct omap_mcbsp {
unsigned int fmt;
unsigned int in_freq;
+ unsigned int latency[2];
int clk_div;
int wlen;
+
+ struct pm_qos_request pm_qos_req;
};
void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
diff --git a/sound/soc/omap/omap-mcbsp.c b/sound/soc/omap/omap-mcbsp.c
index d018e966e533..3814a234ef61 100644
--- a/sound/soc/omap/omap-mcbsp.c
+++ b/sound/soc/omap/omap-mcbsp.c
@@ -157,6 +157,16 @@ static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
struct snd_soc_dai *cpu_dai)
{
struct omap_mcbsp *mcbsp = snd_soc_dai_get_drvdata(cpu_dai);
+ int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
+ int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
+ int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+
+ mcbsp->latency[stream1] = 0;
+ if (mcbsp->latency[stream2])
+ pm_qos_update_request(&mcbsp->pm_qos_req,
+ mcbsp->latency[stream2]);
+ else
+ pm_qos_remove_request(&mcbsp->pm_qos_req);
if (!cpu_dai->active) {
omap_mcbsp_free(mcbsp);
@@ -164,6 +174,28 @@ static void omap_mcbsp_dai_shutdown(struct snd_pcm_substream *substream,
}
}
+static int omap_mcbsp_dai_prepare(struct snd_pcm_substream *substream,
+ struct snd_soc_dai *cpu_dai)
+{
+ struct omap_mcbsp *mcbsp = snd_soc_dai_get_drvdata(cpu_dai);
+ struct pm_qos_request *pm_qos_req = &mcbsp->pm_qos_req;
+ int tx = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK);
+ int stream1 = tx ? SNDRV_PCM_STREAM_PLAYBACK : SNDRV_PCM_STREAM_CAPTURE;
+ int stream2 = tx ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
+ int latency = mcbsp->latency[stream2];
+
+ /* Prevent omap hardware from hitting off between FIFO fills */
+ if (!latency || mcbsp->latency[stream1] < latency)
+ latency = mcbsp->latency[stream1];
+
+ if (pm_qos_request_active(pm_qos_req))
+ pm_qos_update_request(pm_qos_req, latency);
+ else if (latency)
+ pm_qos_add_request(pm_qos_req, PM_QOS_CPU_DMA_LATENCY, latency);
+
+ return 0;
+}
+
static int omap_mcbsp_dai_trigger(struct snd_pcm_substream *substream, int cmd,
struct snd_soc_dai *cpu_dai)
{
@@ -226,6 +258,7 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
int wlen, channels, wpf;
int pkt_size = 0;
unsigned int format, div, framesize, master;
+ unsigned int buffer_size = mcbsp->pdata->buffer_size;
dma_data = snd_soc_dai_get_dma_data(cpu_dai, substream);
channels = params_channels(params);
@@ -240,7 +273,9 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
default:
return -EINVAL;
}
- if (mcbsp->pdata->buffer_size) {
+ if (buffer_size) {
+ int latency;
+
if (mcbsp->dma_op_mode == MCBSP_DMA_MODE_THRESHOLD) {
int period_words, max_thrsh;
int divider = 0;
@@ -271,6 +306,12 @@ static int omap_mcbsp_dai_hw_params(struct snd_pcm_substream *substream,
/* Use packet mode for non mono streams */
pkt_size = channels;
}
+
+ latency = ((((buffer_size - pkt_size) / channels) * 1000)
+ / (params->rate_num / params->rate_den));
+
+ mcbsp->latency[substream->stream] = latency;
+
omap_mcbsp_set_threshold(substream, pkt_size);
}
@@ -554,6 +595,7 @@ static int omap_mcbsp_dai_set_dai_sysclk(struct snd_soc_dai *cpu_dai,
static const struct snd_soc_dai_ops mcbsp_dai_ops = {
.startup = omap_mcbsp_dai_startup,
.shutdown = omap_mcbsp_dai_shutdown,
+ .prepare = omap_mcbsp_dai_prepare,
.trigger = omap_mcbsp_dai_trigger,
.delay = omap_mcbsp_dai_delay,
.hw_params = omap_mcbsp_dai_hw_params,
--
2.10.2
next reply other threads:[~2017-01-11 5:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-01-11 5:46 Matt Ranostay [this message]
2017-01-11 7:26 ` [PATCH v6] ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches Peter Ujfalusi
2017-01-11 8:32 ` Matt Ranostay
-- strict thread matches above, loose matches on Subject: below --
2017-01-12 7:35 Matt Ranostay
2017-01-12 7:55 ` Peter Ujfalusi
2017-01-13 3:21 ` Matt Ranostay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170111054600.12982-1-matt@ranostay.consulting \
--to=matt@ranostay.consulting \
--cc=alsa-devel@alsa-project.org \
--cc=linux-omap@vger.kernel.org \
--cc=peter.ujfalusi@ti.com \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).