Skip to contentSkip to conversation

cleanups of loongson support

PATCH In review Wu Zhangjin 2 participants 5 messages Nov 6, 2009 MIPS

lore
Share & tools
lore
#0 lore raw

cover cleanups of loongson support

The next two patches cleanup the machtype support and the serial port support, which will help to the coming support to share the same kernel image among different loongson2f family machines made by Lemote.

Wu Zhangjin (2):
[loongson] Cleanup the machtype support
[loongson] Cleanup the serial port support

 arch/mips/include/asm/mach-loongson/loongson.h |    4 +++
 arch/mips/include/asm/mach-loongson/machine.h  |    2 -
 arch/mips/loongson/common/Makefile             |    2 +-
 arch/mips/loongson/common/cmdline.c            |    4 ++-
 arch/mips/loongson/common/early_printk.c       |   11 +++++---
 arch/mips/loongson/common/init.c               |   11 +++++---
 arch/mips/loongson/common/machtype.c           |   17 +++++++-----
 arch/mips/loongson/common/serial.c             |   15 +++++-----
 arch/mips/loongson/common/uart_base.c          |   34 ++++++++++++++++++++++++
 9 files changed, 74 insertions(+), 26 deletions(-)
 create mode 100644 arch/mips/loongson/common/uart_base.c
#1 lore raw

PATCH 1/2 Cleanup the machtype support

We need to initialize mips_machtype as early as we can, So, we can choose corresponding code for different machines via it.

This patch moves the initialization of mips_machtype to prom_init().

---
 arch/mips/include/asm/mach-loongson/loongson.h |    1 +
 arch/mips/loongson/common/cmdline.c            |    4 +++-
 arch/mips/loongson/common/machtype.c           |   17 ++++++++++-------
 3 files changed, 14 insertions(+), 8 deletions(-)
arch/mips/include/asm/mach-loongson/loongson.h +1 -0
index e6869aa..efb2344 100644
@@ -29,6 +29,7 @@ extern unsigned long memsize, highmemsize;
 /* loongson-specific command line, env and memory initialization */
 extern void __init prom_init_memory(void);
 extern void __init prom_init_cmdline(void);
+extern void __init prom_init_machtype(void);
 extern void __init prom_init_env(void);
 
 /* irq operation functions */
arch/mips/loongson/common/cmdline.c +3 -1
index 75f1b24..7ad47f2 100644
@@ -9,7 +9,7 @@
  * Copyright (C) 2007 Lemote Inc. & Insititute of Computing Technology
  * Author: Fuxin Zhang, [email protected]
  *
- * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
+ * Copyright (C) 2009 Lemote Inc.
  * Author: Wu Zhangjin, [email protected]
  *
  * This program is free software; you can redistribute  it and/or modify it
@@ -49,4 +49,6 @@ void __init prom_init_cmdline(void)
 		strcat(arcs_cmdline, " console=ttyS0,115200");
 	if ((strstr(arcs_cmdline, "root=")) == NULL)
 		strcat(arcs_cmdline, " root=/dev/hda1");
+
+	prom_init_machtype();
 }
arch/mips/loongson/common/machtype.c +10 -7
index 7b34824..87b502f 100644
@@ -27,24 +27,27 @@ static const char *system_types[] = {
 
 const char *get_system_type(void)
 {
-	if (mips_machtype == MACH_UNKNOWN)
-		mips_machtype = LOONGSON_MACHTYPE;
-
 	return system_types[mips_machtype];
 }
 
-static __init int machtype_setup(char *str)
+void __init prom_init_machtype(void)
 {
+	char *str, *p;
 	int machtype = MACH_LEMOTE_FL2E;
 
+	mips_machtype = LOONGSON_MACHTYPE;
+
+	str = strstr(arcs_cmdline, "machtype=");
 	if (!str)
-		return -EINVAL;
+		return;
+	str += strlen("machtype=");
+	p = strstr(str, " ");
+	if (p)
+		*p++ = '\0';
 
 	for (; system_types[machtype]; machtype++)
 		if (strstr(system_types[machtype], str)) {
 			mips_machtype = machtype;
 			break;
 		}
-	return 0;
 }
-__setup("machtype=", machtype_setup);
Signature · 1 line
1.6.2.1
#2 lore raw

PATCH 2/2 Cleanup the serial port support

To share the same kernel image amon different machines, we have added the machtype command line support.

but in the old serial port implementation, we have hardcoded the uart base address as a macro in machine.h, which will break the intention of machtype. this patch fixes it, and also move the initialization of uart base address to uart_base.c to avoid remapping twice for early_printk.c and serial.c.

---
 arch/mips/include/asm/mach-loongson/loongson.h |    3 ++
 arch/mips/include/asm/mach-loongson/machine.h  |    2 -
 arch/mips/loongson/common/Makefile             |    2 +-
 arch/mips/loongson/common/early_printk.c       |   11 +++++---
 arch/mips/loongson/common/init.c               |   11 +++++---
 arch/mips/loongson/common/serial.c             |   17 +++++------
 arch/mips/loongson/common/uart_base.c          |   34 ++++++++++++++++++++++++
 7 files changed, 60 insertions(+), 20 deletions(-)
 create mode 100644 arch/mips/loongson/common/uart_base.c
arch/mips/include/asm/mach-loongson/loongson.h +3 -0
index efb2344..e4818b6 100644
@@ -31,6 +31,9 @@ extern void __init prom_init_memory(void);
 extern void __init prom_init_cmdline(void);
 extern void __init prom_init_machtype(void);
 extern void __init prom_init_env(void);
+extern unsigned long _loongson_uart_base;
+extern unsigned long uart8250_base[];
+extern inline void __maybe_unused prom_init_uart_base(void);
 
 /* irq operation functions */
 extern void bonito_irqdispatch(void);
arch/mips/include/asm/mach-loongson/machine.h +0 -2
index ea5954c..d2f5861 100644
@@ -13,8 +13,6 @@
 
 #ifdef CONFIG_LEMOTE_FULOONG2E
 
-#define LOONGSON_UART_BASE (LOONGSON_PCIIO_BASE + 0x3f8)
-
 #define LOONGSON_MACHTYPE MACH_LEMOTE_FL2E
 
 #endif
arch/mips/loongson/common/Makefile +1 -1
index d21d116..be6adf7 100644
@@ -3,7 +3,7 @@
 #
 
 obj-y += setup.o init.o cmdline.o env.o time.o reset.o irq.o \
-    pci.o bonito-irq.o mem.o machtype.o
+    pci.o bonito-irq.o mem.o machtype.o uart_base.o
 
 #
 # Early printk support
arch/mips/loongson/common/early_printk.c +7 -4
index 8ec4fb2..23e7a8f 100644
@@ -12,7 +12,6 @@
 #include <linux/serial_reg.h>
 
 #include <loongson.h>
-#include <machine.h>
 
 #define PORT(base, offset) (u8 *)(base + offset)
 
@@ -28,10 +27,14 @@ static inline void serial_out(unsigned char *base, int offset, int value)
 
 void prom_putchar(char c)
 {
-	unsigned char *uart_base =
-		(unsigned char *) ioremap_nocache(LOONGSON_UART_BASE, 8);
+	int timeout;
+	unsigned char *uart_base;
 
-	while ((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0)
+	uart_base = (unsigned char *)_loongson_uart_base;
+	timeout = 1024;
+
+	while (((serial_in(uart_base, UART_LSR) & UART_LSR_THRE) == 0) &&
+			(timeout-- > 0))
 		;
 
 	serial_out(uart_base, UART_TX, c);
arch/mips/loongson/common/init.c +7 -4
index b7e4913..3b1dbc1 100644
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Lemote Inc. & Insititute of Computing Technology
+ * Copyright (C) 2009 Lemote Inc.
  * Author: Wu Zhangjin, [email protected]
  *
  * This program is free software; you can redistribute  it and/or modify it
@@ -10,19 +10,22 @@
 
 #include <linux/bootmem.h>
 
-#include <asm/bootinfo.h>
-
 #include <loongson.h>
 
 void __init prom_init(void)
 {
-    /* init base address of io space */
+	/* init base address of io space */
 	set_io_port_base((unsigned long)
 		ioremap(LOONGSON_PCIIO_BASE, LOONGSON_PCIIO_SIZE));
 
 	prom_init_cmdline();
 	prom_init_env();
 	prom_init_memory();
+
+	/*init the uart base address */
+#if defined(CONFIG_EARLY_PRINTK) || defined(CONFIG_SERIAL_8250)
+	prom_init_uart_base();
+#endif
 }
 
 void __init prom_free_prom_memory(void)
arch/mips/loongson/common/serial.c +8 -9
index 6d341e4..dc6488c 100644
@@ -23,7 +23,6 @@
 {								\
 	.irq		= int,					\
 	.uartclk	= 1843200,				\
-	.iobase		= (LOONGSON_UART_BASE - LOONGSON_PCIIO_BASE),\
 	.iotype		= UPIO_PORT,				\
 	.flags		= UPF_BOOT_AUTOCONF | UPF_SKIP_TEST,	\
 	.regshift	= 0,					\
@@ -52,20 +51,20 @@ static struct plat_serial8250_port uart8250_data[][2] = {
 static struct platform_device uart8250_device = {
 	.name = "serial8250",
 	.id = PLAT8250_DEV_PLATFORM,
-	.dev = {
-		.platform_data = uart8250_data[LOONGSON_MACHTYPE],
-		},
 };
 
 static int __init serial_init(void)
 {
-	if (uart8250_data[LOONGSON_MACHTYPE][0].iotype == UPIO_MEM)
-		uart8250_data[LOONGSON_MACHTYPE][0].membase =
-			ioremap_nocache(LOONGSON_UART_BASE, 8);
+	if (uart8250_data[mips_machtype][0].iotype == UPIO_MEM)
+		uart8250_data[mips_machtype][0].membase =
+			(void __iomem *)_loongson_uart_base;
+	else if (uart8250_data[mips_machtype][0].iotype == UPIO_PORT)
+		uart8250_data[mips_machtype][0].iobase =
+		    uart8250_base[mips_machtype] - LOONGSON_PCIIO_BASE;
 
-	platform_device_register(&uart8250_device);
+	uart8250_device.dev.platform_data = uart8250_data[mips_machtype];
 
-	return 0;
+	return platform_device_register(&uart8250_device);
 }
 
 device_initcall(serial_init);
arch/mips/loongson/common/uart_base.c new file +34 -0
new file mode 100644
index 0000000..c3db78a
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2009 Lemote Inc.
+ * Author: Wu Zhangjin, [email protected]
+ *
+ * This program is free software; you can redistribute  it and/or modify it
+ * under  the terms of  the GNU General  Public License as published by the
+ * Free Software Foundation;  either version 2 of the  License, or (at your
+ * option) any later version.
+ */
+
+#include <linux/module.h>
+#include <asm/bootinfo.h>
+
+#include <loongson.h>
+
+unsigned long __maybe_unused _loongson_uart_base;
+EXPORT_SYMBOL(_loongson_uart_base);
+
+unsigned long __maybe_unused uart8250_base[] = {
+	[MACH_LOONGSON_UNKNOWN]	0,
+	[MACH_LEMOTE_FL2E]	(LOONGSON_PCIIO_BASE + 0x3f8),
+	[MACH_LEMOTE_FL2F]	(LOONGSON_PCIIO_BASE + 0x2f8),
+	[MACH_LEMOTE_ML2F7]	(LOONGSON_LIO1_BASE + 0x3f8),
+	[MACH_LEMOTE_YL2F89]	(LOONGSON_LIO1_BASE + 0x3f8),
+	[MACH_DEXXON_GDIUM2F10]	(LOONGSON_LIO1_BASE + 0x3f8),
+	[MACH_LOONGSON_END]	0,
+};
+EXPORT_SYMBOL(uart8250_base);
+
+inline void __maybe_unused prom_init_uart_base(void)
+{
+	_loongson_uart_base =
+		(unsigned long)ioremap_nocache(uart8250_base[mips_machtype], 8);
+}
Signature · 1 line
1.6.2.1
#3 lore raw

Re: [PATCH -queue 2/2] [loongson] Cleanup the serial port support

Quoted 10 lines · Wu Zhangjin

To share the same kernel image amon different machines, we have added the machtype command line support.

but in the old serial port implementation, we have hardcoded the uart base address as a macro in machine.h, which will break the intention of machtype. this patch fixes it, and also move the initialization of uart base address to uart_base.c to avoid remapping twice for early_printk.c and serial.c.

Thanks, queued for 2.6.33.

Ralf

#4 lore raw

Re: [PATCH -queue 1/2] [loongson] Cleanup the machtype support

In reply to Wu Zhangjin
Quoted 6 lines · Wu Zhangjin

We need to initialize mips_machtype as early as we can, So, we can choose corresponding code for different machines via it.

This patch moves the initialization of mips_machtype to prom_init().

Thanks, queued for 2.6.33.

Ralf