shithub: riscv

Download patch

ref: 81f726b2b4cb699d2fcf7fd1b4f383650bba4a22
parent: 7265a09524fdac42b776d01f474a9eb16805ee59
author: cinap_lenrek <[email protected]>
date: Thu Sep 26 19:34:06 EDT 2013

audioac97: remove i/o bar magic, fix ac97mixreset busywait-forever timeout

the standard is i/o bar 0 is the mixer and bar 1 is status/control.
the magic with the bar sizes made it fail in qemu. so removing it
for now as all devices seen so far comply to the standard.

if we ever see a sis7012 where this might be swaped uncomment the i=0;

the busywait timeout is too long in ac97mixreset() because rd/wr
have a timeout on ther own. just remove the busy looping and do
a one second delay after mixer reset. (tested with t23)

--- a/sys/src/9/pc/audioac97.c
+++ b/sys/src/9/pc/audioac97.c
@@ -471,15 +471,16 @@
 	adev->ctlr = ctlr;
 	ctlr->adev = adev;
 
+	if((p->mem[0].bar & 1) == 0 || (p->mem[1].bar & 1) == 0){
+		print("ac97: not i/o regions 0x%04lux 0x%04lux\n", p->mem[0].bar, p->mem[1].bar);
+		return -1;
+	}
+
 	i = 1;
-	if(p->mem[0].size == 64)
-		i = 0;
-	else if(p->mem[1].size == 64)
-		i = 1;
-	else if(p->mem[0].size == 256)		/* sis7012 */
-		i = 1;
-	else if(p->mem[1].size == 256)
-		i = 0;
+	if(p->vid == 0x1039 && p->did == 0x7012){
+		ctlr->sis7012 = 1;
+		//i = 0;	i/o bars swaped?
+	}
 	ctlr->port = p->mem[i].bar & ~3;
 	if(ioalloc(ctlr->port, p->mem[i].size, 0, "ac97") < 0){
 		print("ac97: ioalloc failed for port 0x%04lux\n", ctlr->port);
@@ -495,8 +496,6 @@
 
 	irq = p->intl;
 	tbdf = p->tbdf;
-	if(p->vid == 0x1039 && p->did == 0x7012)
-		ctlr->sis7012 = 1;
 
 	print("#A%d: ac97 port 0x%04lux mixport 0x%04lux irq %d\n",
 		adev->ctlrno, ctlr->port, ctlr->mixport, irq);
--- a/sys/src/9/pc/audioac97mix.c
+++ b/sys/src/9/pc/audioac97mix.c
@@ -7,8 +7,6 @@
 #include "../port/error.h"
 #include "../port/audioif.h"
 
-enum { Maxbusywait = 500000 };
-
 enum {
 	Reset = 0x0,
 		Capmic = 0x1,
@@ -236,7 +234,6 @@
 {
 	Mixer *m;
 	ushort t;
-	int i;
 
 	m = malloc(sizeof(Mixer));
 	if(m == nil){
@@ -247,14 +244,9 @@
 	m->rr = rr;
 	m->wr(adev, Reset, 0);
 	m->wr(adev, Powerdowncsr, 0);
-
+	delay(1000);
 	t = (Adcpower | Dacpower | Anlpower | Refpower);
-	for(i = 0; i < Maxbusywait; i++){
-		if((m->rr(adev, Powerdowncsr) & t) == t)
-			break;
-		microdelay(1);
-	}
-	if(i == Maxbusywait)
+	if((m->rr(adev, Powerdowncsr) & t) != t)
 		print("#A%d: ac97 exhausted waiting powerup\n", adev->ctlrno);
 
 	t = m->rr(adev, Extid);