shithub: riscv

Download patch

ref: bdc9a81b2fba73ecfeb1a35954aef9f0cef69897
parent: e0e2e9d81b4dbdabb7521dcc68e9f980f26cc3a9
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Thu Aug 18 20:46:34 EDT 2022

imx8/sai: flush the ring on close to avoid garbage leftovers on restarts

--- a/sys/src/9/imx8/sai.c
+++ b/sys/src/9/imx8/sai.c
@@ -156,6 +156,15 @@
 }
 
 static void
+setempty(Ctlr *ctlr)
+{
+	ilock(ctlr);
+	ctlr->w.ri = 0;
+	ctlr->w.wi = 0;
+	iunlock(ctlr);
+}
+
+static void
 saistop(Ctlr *ctlr)
 {
 	if(!ctlr->wactive)
@@ -164,6 +173,13 @@
 	wr(TCSR, TCSR_FR | TCSR_SR);
 }
 
+static int
+inactive(void *arg)
+{
+	Ctlr *ctlr = arg;
+	return !ctlr->wactive;
+}
+
 static long
 saiwrite(Audio *adev, void *a, long n, vlong)
 {
@@ -193,8 +209,10 @@
 {
 	Ctlr *ctlr = adev->ctlr;
 
-	if(mode == OWRITE || mode == ORDWR)
-		saistop(ctlr);
+	if(mode == OWRITE || mode == ORDWR){
+		sleep(&ctlr->w.r, inactive, ctlr);
+		setempty(ctlr);
+	}
 }
 
 static void