shithub: n900

Download patch

ref: 7ceb0a090d1fb8ce39a12fd76c01bd1c11343118
parent: d0fb274a9820f51d4fe0eb8cd13c6f0c53c0a3df
author: mia soweli <inbox@tachibana-labs.org>
date: Sat Jun 10 10:10:46 EDT 2023

mmc: interrupts

--- a/mmcn900.c
+++ b/mmcn900.c
@@ -64,6 +64,7 @@
 
 typedef struct Ctlr Ctlr;
 struct Ctlr {
+	char *name;
 	u32int *io;
 	ulong irq;
 
@@ -100,7 +101,31 @@
 	return snprint(inquiry, len, "MMC Host Controller");
 }
 
+static void
+n900mmcintr(Ureg *, void *aux)
+{
+	Ctlr *ctlr;
+
+	ctlr = aux;
+	ilock(ctlr);
+	if(csr32r(ctlr, Rstatus) & STcmd)
+		wakeup(ctlr);
+
+	iunlock(ctlr);
+}
+
 static int
+n900mmcdone(void *aux)
+{
+	Ctlr *ctlr = aux;
+
+	if(csr32r(ctlr, Rstatus) & STcmd)
+		return 1;
+
+	return 0;
+}
+
+static int
 n900mmccmd(SDio *io, SDiocmd *iocmd, u32int arg, u32int *resp)
 {
 	Ctlr *ctlr;
@@ -138,14 +163,11 @@
 	csr32w(ctlr, Rarg, arg);
 	csr32w(ctlr, Rcmd, cmd);
 
-	/* FIXME: interrupts */
-	while(!(csr32r(ctlr, Rstatus) & STcmd)) {
-		if(csr32r(ctlr, Rstatus) & STmaskerr)
-			error(Eio);
+	/* wait for command to be done */
+	tsleep(ctlr, n900mmcdone, ctlr, 100);
+	if(csr32r(ctlr, Rstatus) & STmaskerr)
+		error(Eio);
 
-		delay(10);
-	}
-
 	/* unpack the response */
 	switch(cmd & CRmask) {
 	case CRnone:
@@ -264,8 +286,8 @@
 {
 	int i;
 	static Ctlr ctlr[2] = {
-		{ .io = (u32int*) PHYSMMC1, .irq = IRQMMC1, },
-		{ .io = (u32int*) PHYSMMC2, .irq = IRQMMC2, },
+		{ .name = "mmc1", .io = (u32int*) PHYSMMC1, .irq = IRQMMC1, },
+		{ .name = "mmc2", .io = (u32int*) PHYSMMC2, .irq = IRQMMC2, },
 	};
 
 	static SDio io[nelem(ctlr)];
@@ -281,5 +303,6 @@
 		io[i].aux = &ctlr[i];
 
 		addmmcio(&io[i]);
+		intrenable(ctlr[i].irq, n900mmcintr, &ctlr[i], BUSUNKNOWN, ctlr[i].name);
 	}
 }