Patchwork Loongson support

login
register
about
Submitter Vladimir 'φ-coder/phcoder' Serbinenko
Date 2010-09-17 15:55:02
Message ID <4C938F56.6060802@gmail.com>
Download mbox | patch
Permalink /patch/1957/
State Superseded
Headers show

Comments

Support for Loongson-2F flashing.

Signed-off-by: Vladimir 'phcoder' Serbinenko

Patch

Index: internal.c
===================================================================
--- internal.c	(revision 1178)
+++ internal.c	(working copy)
@@ -242,7 +242,7 @@ 
 	 * The error code might have been a warning only.
 	 * Besides that, we don't check the board enable return code either.
 	 */
-#if defined(__i386__) || defined(__x86_64__)
+#if defined(__i386__) || defined(__x86_64__) || defined (__mips)
 	return 0;
 #else
 	msg_perr("Your platform is not supported yet for the internal "
Index: processor_enable.c
===================================================================
--- processor_enable.c	(revision 1178)
+++ processor_enable.c	(working copy)
@@ -37,8 +37,60 @@ 
 
 #else
 
+#if defined (__MIPSEL__) && defined (__linux)
+#include <stdio.h>
+#include <string.h>
+#include <ctype.h>
+#endif
+
+static int is_loongson(void)
+{
+	/* FIXME: detect loongson on FreeBSD and OpenBSD as well.  */
+#if !defined (__MIPSEL__) || !defined (__linux)
+	return 0;
+#else
+	FILE *cpuinfo;
+	cpuinfo = fopen("/proc/cpuinfo", "rb");
+	if (!cpuinfo)
+		return 0;
+	while (!feof(cpuinfo)) {
+		char line[512], *ptr;
+		if (fgets(line, sizeof(line), cpuinfo) == NULL)
+			break;
+		ptr = line;
+		while (*ptr && isspace(*ptr))
+			ptr++;
+		if (memcmp(ptr, "cpu", sizeof("cpu") - 1) == 0)
+			ptr += sizeof("cpu") - 1;
+		while (*ptr && isspace(*ptr))
+			ptr++;
+		if (memcmp(ptr, "model", sizeof("model") - 1) != 0)
+			continue;
+		ptr += sizeof("model") - 1;
+		while (*ptr && isspace(*ptr))
+			ptr++;
+		if (*ptr != ':')
+			continue;
+		ptr++;
+		while (*ptr && isspace(*ptr))
+			ptr++;
+		fclose(cpuinfo);
+		return (memcmp(ptr, "ICT Loongson-2 V0.3",
+			       sizeof("ICT Loongson-2 V0.3") - 1) == 0)
+		    || (memcmp(ptr, "Godson2 V0.3  FPU V0.1",
+			       sizeof("Godson2 V0.3  FPU V0.1") - 1) == 0);
+	}
+	fclose(cpuinfo);
+	return 0;
+#endif
+}
+
 int processor_flash_enable(void)
 {
+	if (is_loongson()) {
+		flashbase = 0x1fc00000;
+		return 0;
+	}
 	/* Not implemented yet. Oh well. */
 	return 1;
 }