Skip to contentSkip to conversation

ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches

PATCH Superseded Matt Ranostay 2 participants 3 messages Jan 11, 2017

Subsystems (2)

v6 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

PATCH v6 1/1 ASoC: omap-mcbsp: Add PM QoS support for McBSP to prevent glitches

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

Cc Tony Lindgren <[email protected]>
Cc Peter Ujfalusi <[email protected]>

---
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(-)
sound/soc/omap/mcbsp.c +4 -0
index 06fec5699cc8..e1c3d21dc5ed 100644
@@ -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);
 
sound/soc/omap/mcbsp.h +3 -0
index 61e93b1c185d..46ae1269a698 100644
@@ -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,
sound/soc/omap/omap-mcbsp.c +43 -1

80 lines not on this page · raw message

Signature · 1 line
2.10.2
#1 lore raw
Quoted 56 lines · Matt Ranostay

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

Cc Tony Lindgren <[email protected]>
Cc Peter Ujfalusi <[email protected]>

---
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(-)
sound/soc/omap/mcbsp.c +1 -0
index 06fec5699cc8..e1c3d21dc5ed 100644
@@ -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>
 

sound/soc/omap/mcbsp.c int omap_mcbsp_init(struct platform_device *pdev) · line 1104

Quoted 6 lines
sound/soc/omap/mcbsp.c +3 -0
@@ -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);
+

It might be better to do this in asoc_mcbsp_remove() in omap-mcbsp.c so the pm_qos stuff is handled within one file.

sound/soc/omap/omap-mcbsp.c

Quoted 23 lines
sound/soc/omap/mcbsp.c +0 -0
 	if (mcbsp->pdata->buffer_size)
 		sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
 
sound/soc/omap/mcbsp.h +3 -0
index 61e93b1c185d..46ae1269a698 100644
@@ -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,
sound/soc/omap/omap-mcbsp.c +0 -0
index d018e966e533..3814a234ef61 100644

#include <linux/pm_qos.h> ?

Signature · 1 line
Péter
#2 lore raw
Quoted 62 lines · Peter Ujfalusi
Quoted 59 lines · Matt Ranostay

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

Cc Tony Lindgren <[email protected]>
Cc Peter Ujfalusi <[email protected]>

---
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(-)
sound/soc/omap/mcbsp.c +1 -0
index 06fec5699cc8..e1c3d21dc5ed 100644
@@ -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)
 
Quoted 8 lines

sound/soc/omap/mcbsp.c int omap_mcbsp_init(struct platform_device *pdev) · line 1104

Quoted 5 lines
sound/soc/omap/mcbsp.c +3 -0
 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);
+

It might be better to do this in asoc_mcbsp_remove() in omap-mcbsp.c so the pm_qos stuff is handled within one file.

Good point will I test tomorrow esp if I have a foot of snow outside...

Quoted 19 lines
Quoted 19 lines
sound/soc/omap/mcbsp.c +0 -0
   if (mcbsp->pdata->buffer_size)
       sysfs_remove_group(&mcbsp->dev->kobj, &additional_attr_group);
 
sound/soc/omap/mcbsp.h +3 -0
index 61e93b1c185d..46ae1269a698 100644
@@ -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;
 };
 
Quoted 11 lines

sound/soc/omap/omap-mcbsp.c

Quoted 5 lines
sound/soc/omap/mcbsp.h +0 -0
 void omap_mcbsp_config(struct omap_mcbsp *mcbsp,
sound/soc/omap/omap-mcbsp.c +0 -0
index d018e966e533..3814a234ef61 100644

#include <linux/pm_qos.h> ?

Signature · 1 line
Péter

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel