Linux on ARM based TI OMAP SoCs
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Peter Ujfalusi <peter.ujfalusi@ti.com>
Cc: alsa-devel@alsa-project.org,
	"Ivaylo Dimitrov" <ivo.g.dimitrov.75@gmail.com>,
	"Aaro Koskinen" <aaro.koskinen@iki.fi>,
	"Liam Girdwood" <lgirdwood@gmail.com>,
	"Sebastian Reichel" <sre@kernel.org>,
	"Mark Brown" <broonie@kernel.org>,
	"Jarkko Nikula" <jarkko.nikula@linux.intel.com>,
	"Pavel Machel" <pavel@ucw.cz>,
	"Pali Rohár" <pali.rohar@gmail.com>,
	linux-omap@vger.kernel.org
Subject: [PATCH] ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches
Date: Mon, 29 Aug 2016 11:27:46 -0700	[thread overview]
Message-ID: <20160829182746.53vrgbxadqodzzug@atomide.com> (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.

Let's fix the issue by adding PM QoS latency requirement for McBSP.
Based on my experiments a working latency value is somewhere
around 35 ms with 40 ms breaking. So let's use a safer value of 30 ms.

Note that this is different from snd_pcm_hw_constraint_step() as
that can configure things based on the buffer and period size.
However, that does not help to block idle between the fifo fills.

Note that in theory some omaps are capable of playing audio while
hitting deeper idle states. If somebody needs that and gets it
working, we can set the latency requirements accordingly.

Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 sound/soc/omap/mcbsp.c | 10 ++++++++++
 sound/soc/omap/mcbsp.h |  2 ++
 2 files changed, 12 insertions(+)

diff --git a/sound/soc/omap/mcbsp.c b/sound/soc/omap/mcbsp.c
--- 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>
 
@@ -643,6 +644,10 @@ void omap_mcbsp_start(struct omap_mcbsp *mcbsp, int tx, int rx)
 	int enable_srg = 0;
 	u16 w;
 
+	/* Prevent omap hardware from hitting off between fifo fills */
+	pm_qos_add_request(&mcbsp->pm_qos_req, PM_QOS_CPU_DMA_LATENCY,
+			   30 * 1000);
+
 	if (mcbsp->st_data)
 		omap_st_start(mcbsp);
 
@@ -731,6 +736,8 @@ void omap_mcbsp_stop(struct omap_mcbsp *mcbsp, int tx, int rx)
 
 	if (mcbsp->st_data)
 		omap_st_stop(mcbsp);
+
+	pm_qos_remove_request(&mcbsp->pm_qos_req);
 }
 
 int omap2_mcbsp_set_clks_src(struct omap_mcbsp *mcbsp, u8 fck_src_id)
@@ -1098,6 +1105,9 @@ err_thres:
 
 void omap_mcbsp_cleanup(struct omap_mcbsp *mcbsp)
 {
+	if (dev_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 61e93b1..e603f33 100644
--- a/sound/soc/omap/mcbsp.h
+++ b/sound/soc/omap/mcbsp.h
@@ -325,6 +325,8 @@ struct omap_mcbsp {
 	unsigned int in_freq;
 	int clk_div;
 	int wlen;
+
+	struct pm_qos_request pm_qos_req;
 };
 
 void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
-- 
2.9.3

             reply	other threads:[~2016-08-29 18:27 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-29 18:27 Tony Lindgren [this message]
     [not found] ` <201608300739.JrTVlIyd%fengguang.wu@intel.com>
2016-08-30 18:38   ` [PATCH] ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches Tony Lindgren
2016-08-31 17:24     ` Mark Brown
2016-08-31 17:42       ` Tony Lindgren
2016-08-31 11:37 ` Peter Ujfalusi
2016-08-31 14:13   ` Tony Lindgren
2016-08-31 16:59     ` Tony Lindgren
2016-08-31 18:33       ` Peter Ujfalusi
2016-08-31 19:41         ` Tony Lindgren
2016-09-01  6:57           ` Peter Ujfalusi
2016-09-01 14:50             ` Tony Lindgren
2016-09-02  7:30               ` Peter Ujfalusi
2016-09-02 14:56                 ` Tony Lindgren
2016-09-02 19:38                   ` Peter Ujfalusi
2016-09-02 20:40                     ` Tony Lindgren
2016-09-05  7:53                       ` Peter Ujfalusi
2016-09-06 20:16                         ` Tony Lindgren
2016-09-07 14:31                           ` Peter Ujfalusi
2016-09-08  3:53                             ` Tony Lindgren
2016-09-08 10:41                               ` Peter Ujfalusi
2016-09-08 10:49                                 ` Peter Ujfalusi
2016-09-08 14:48                                   ` Tony Lindgren
2016-09-09  6:51                                     ` Peter Ujfalusi
2016-09-09 23:45                                       ` Tony Lindgren
2016-09-13 11:45                                         ` Peter Ujfalusi
2016-09-13 13:45                                           ` Tony Lindgren
2016-09-02 15:54                 ` Pavel Machek
2016-09-02 19:45                   ` Peter Ujfalusi
2016-09-02 20:09                     ` Tony Lindgren
2016-09-03 16:08                       ` Sebastian Reichel
2016-09-06 20:08                         ` Tony Lindgren

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=20160829182746.53vrgbxadqodzzug@atomide.com \
    --to=tony@atomide.com \
    --cc=aaro.koskinen@iki.fi \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=ivo.g.dimitrov.75@gmail.com \
    --cc=jarkko.nikula@linux.intel.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-omap@vger.kernel.org \
    --cc=pali.rohar@gmail.com \
    --cc=pavel@ucw.cz \
    --cc=peter.ujfalusi@ti.com \
    --cc=sre@kernel.org \
    /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