[coreboot] r3640 - trunk/coreboot-v2/src/southbridge/amd/sb600

svn at coreboot.org svn at coreboot.org
Tue Oct 7 18:25:10 CEST 2008


Author: jcrouse
Date: 2008-10-07 18:25:10 +0200 (Tue, 07 Oct 2008)
New Revision: 3640

Modified:
   trunk/coreboot-v2/src/southbridge/amd/sb600/sb600_hda.c
Log:
[PATCH] coreboot:  Don't loop forever waiting for HDA codecs

We shouldn't assume the presence of a working HDA codec, so put in
a reasonable timeout of 50usecs (timeout value borrowed from the kernel).
This makes SimNow work, since apparently though the codec is 
present in Simnow, it is non functional.

Signed-off-by: Jordan Crouse <jordan.crouse at amd.com>
Acked-by: Ronald G. Minnich <rminnich at gmail.com>



Modified: trunk/coreboot-v2/src/southbridge/amd/sb600/sb600_hda.c
===================================================================
--- trunk/coreboot-v2/src/southbridge/amd/sb600/sb600_hda.c	2008-10-07 12:21:12 UTC (rev 3639)
+++ trunk/coreboot-v2/src/southbridge/amd/sb600/sb600_hda.c	2008-10-07 16:25:10 UTC (rev 3640)
@@ -26,6 +26,10 @@
 #include <delay.h>
 #include "sb600.h"
 
+#define HDA_ICII_REG 0x68
+#define   HDA_ICII_BUSY (1 << 0)
+#define   HDA_ICII_VALID  (1 << 1)
+
 static int set_bits(u8 * port, u32 mask, u32 val)
 {
 	u32 dword;
@@ -160,6 +164,51 @@
 	return sizeof(cim_verb_data) / sizeof(u32);
 }
 
+/**
+ *  Wait 50usec for for the codec to indicate it is ready
+ *  no response would imply that the codec is non-operative
+ */
+
+static int wait_for_ready(u8 *base)
+{
+	/* Use a 50 usec timeout - the Linux kernel uses the
+	 * same duration */
+
+	int timeout = 50;
+
+	while(timeout--) {
+		u32 dword=readl(base +  HDA_ICII_REG);
+		if (!(dword & HDA_ICII_BUSY))
+			return 0;
+		udelay(1);
+	}
+
+	return -1;
+}
+
+/**
+ *  Wait 50usec for for the codec to indicate that it accepted
+ *  the previous command.  No response would imply that the code
+ *  is non-operative
+ */
+
+static int wait_for_valid(u8 *base)
+{
+	/* Use a 50 usec timeout - the Linux kernel uses the
+	 * same duration */
+
+	int timeout = 50;
+	while(timeout--) {
+		u32 dword = readl(base + HDA_ICII_REG);
+		if ((dword & (HDA_ICII_VALID | HDA_ICII_BUSY)) ==
+			HDA_ICII_VALID)
+			return 0;
+		udelay(1);
+	}
+
+	return 1;
+}
+
 static void codec_init(u8 * base, int addr)
 {
 	u32 dword;
@@ -168,16 +217,14 @@
 	int i;
 
 	/* 1 */
-	do {
-		dword = readl(base + 0x68);
-	} while (dword & 1);
+	if (wait_for_ready(base) == -1)
+		return;
 
 	dword = (addr << 28) | 0x000f0000;
 	writel(dword, base + 0x60);
 
-	do {
-		dword = readl(base + 0x68);
-	} while ((dword & 3) != 2);
+	if (wait_for_valid(base) == -1)
+		return;
 
 	dword = readl(base + 0x64);
 
@@ -193,15 +240,13 @@
 	printk_debug("verb_size: %d\n", verb_size);
 	/* 3 */
 	for (i = 0; i < verb_size; i++) {
-		do {
-			dword = readl(base + 0x68);
-		} while (dword & 1);
+		if (wait_for_ready(base) == -1)
+			return;
 
 		writel(verb[i], base + 0x60);
 
-		do {
-			dword = readl(base + 0x68);
-		} while ((dword & 3) != 2);
+		if (wait_for_valid(base) == -1)
+			return;
 	}
 	printk_debug("verb loaded!\n");
 }





More information about the coreboot mailing list