shithub: riscv

Download patch

ref: 7b6675ff1a1da63c2f738b50d3ee2eb062c3ab63
parent: 0918ce10dc7b3e39506b8c4177e68a7b3233f5a9
author: ment <[email protected]>
date: Mon Jun 27 19:01:58 EDT 2011

audio/hda: added archfile command interface

--- a/sys/src/9/pc/audiohda.c
+++ b/sys/src/9/pc/audiohda.c
@@ -277,9 +277,9 @@
 	uchar *mem;
 	ulong size;
 	
+	Queue *q;
 	ulong *corb;
 	ulong corbsize;
-	
 	ulong *rirb;
 	ulong rirbsize;
 	
@@ -370,6 +370,8 @@
 	"other",
 };
 
+Ctlr *lastcard;
+
 static int
 waitup8(Ctlr *ctlr, int reg, uchar mask, uchar set)
 {
@@ -1264,6 +1266,45 @@
 	return nil;
 }
 
+static long
+hdacmdread(Chan *, void *a, long n, vlong)
+{
+	Ctlr *ctlr;
+	
+	ctlr = lastcard;
+	if(ctlr == nil)
+		error(Enodev);
+	if(n & 7)
+		error(Ebadarg);
+	return qread(ctlr->q, a, n);
+}
+
+static long
+hdacmdwrite(Chan *, void *a, long n, vlong)
+{
+	Ctlr *ctlr;
+	ulong *lp;
+	int i;
+	uint w[2];
+	
+	ctlr = lastcard;
+	if(ctlr == nil)
+		error(Enodev);
+	if(n & 3)
+		error(Ebadarg);
+	lp = a;
+	qlock(ctlr);
+	for(i=0; i<n/4; i++){
+		if(hdacmd(ctlr, lp[i], w) < 0){
+			w[0] = 0;
+			w[1] = ~0;
+		}
+		qproduce(ctlr->q, w, sizeof(w));
+	}
+	qunlock(ctlr);
+	return n;
+}
+
 static int
 hdareset(Audio *adev)
 {
@@ -1304,6 +1345,7 @@
 	
 	ctlr->no = adev->ctlrno;
 	ctlr->size = p->mem[0].size;
+	ctlr->q = qopen(256, 0, 0, 0);
 	ctlr->mem = vmap(p->mem[0].bar & ~0x0F, ctlr->size);
 	if(ctlr->mem == nil){
 		print("#A%d: can't map %.8lux\n", ctlr->no, p->mem[0].bar);
@@ -1345,6 +1387,8 @@
 	adev->ctl = hdactl;
 	
 	intrenable(irq, hdainterrupt, adev, tbdf, "hda");
+	lastcard = ctlr;
+	addarchfile("hdacmd", 0664, hdacmdread, hdacmdwrite);
 	
 	return 0;
 }
@@ -1354,3 +1398,4 @@
 {
 	addaudiocard("hda", hdareset);
 }
+