Clean up Lemote Loongson 2E Support
PATCH 1/1 Clean up Lemote Loongson 2E Support
This patch eliminates magic numbers and accessors for memory-mapped registers. As well, it removes some inline assembly and restructures how the early printk code behaves.
Signed-off-by Philippe Vachon <[email protected]>
--- arch/mips/include/asm/mach-lemote/loongson2e.h | 58 +++++++++++ arch/mips/lemote/lm2e/dbg_io.c | 125 ++--------------------- arch/mips/lemote/lm2e/prom.c | 10 +-- arch/mips/lemote/lm2e/reset.c | 18 ++-- 4 files changed, 80 insertions(+), 131 deletions(-) create mode 100644 arch/mips/include/asm/mach-lemote/loongson2e.h
arch/mips/include/asm/mach-lemote/loongson2e.h new file +58 -0
@@ -0,0 +1,58 @@ +/* Accessor functions for the Loongson 2E MMIO registers +* +* 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. +* +*/ +#ifndef __ASM_MACH_LEMOTE_LOONGSON2E +#define __ASM_MACH_LEMOTE_LOONGSON2E + +#include <linux/types.h> + +/* Loongson 2E Control Registers */ +#define LS2E_REG_BASE 0x1fe00100/* start of config registers */ +#define LS2E_GENCFG_REG (LS2E_REG_BASE + 0x04) + +#define LS2E_RESET_VECTOR 0x1fc00000/* this should be obvious! */ + +/* UART address (16550 -- on the Fulong) */ +#define LS2E_UART_BASE 0x1fd003f8 + +/* Various system parameters passed from PMON */ +extern unsigned long bus_clock; +extern unsigned long cpu_clock_freq; +extern unsigned int memsize, highmemsize; + +static inline void ls2e_writeb (uint8_t value,phys_addr_t addr) +{ + *(volatile uint8_t *)addr = value; +} + +static inline void ls2e_writew (uint16_t value,phys_addr_t addr) +{ + *(volatile uint16_t *)addr = value; +} + +static inline void ls2e_writel (uint32_t value,phys_addr_t addr) +{ + *(volatile uint32_t *)addr = value; +} + +static inline uint8_t ls2e_readb (phys_addr_t addr) +{ +return *(volatile uint8_t *)addr; +} + +static inline uint16_t ls2e_readw (phys_addr_t addr) +{ +return *(volatile uint16_t *)addr; +} + +static inline uint32_t ls2e_readl (phys_addr_t addr) +{ +return *(volatile uint32_t *)addr; +} + +#endif /* __ASM_MACH_LEMOTE_LOONGSON2E */
arch/mips/lemote/lm2e/dbg_io.c +11 -114
139 lines not on this page · raw message
arch/mips/lemote/lm2e/prom.c +1 -9
@@ -18,10 +18,7 @@#include <linux/bootmem.h> #include <asm/bootinfo.h> -extern unsigned long bus_clock; -extern unsigned long cpu_clock_freq; -extern unsigned int memsize, highmemsize; -extern int putDebugChar (unsigned char byte); +#include <loongson2e.h> static int argc;/* pmon passes arguments in 32bit pointers */
@@ -90,8 +87,3 @@ do { \void __init prom_free_prom_memory (void ) { } - -void prom_putchar (char c) -{ -putDebugChar (c); -}
arch/mips/lemote/lm2e/reset.c +10 -8
@@ -7,20 +7,22 @@* Copyright (C) 2007 Lemote, Inc. & Institute of Computing Technology * Author: Fuxin Zhang, [email protected] */ +#include <linux/pm.h> +#include <linux/io.h> +#include <loongson2e.h> #include <asm/reboot.h> static void loongson2e_restart (char *command) { -#ifdef CONFIG_32BIT - *(unsigned long *)0xbfe00104 &= ~(1 <<2 ); - *(unsigned long *)0xbfe00104 |= (1 <<2 ); -#else - *(unsigned long *)0xffffffffbfe00104 &= ~(1 <<2 ); - *(unsigned long *)0xffffffffbfe00104 |= (1 <<2 ); -#endif - __asm__ __volatile__("jr\t%0" ::"r" (0xbfc00000 )); +uint32_t ctl = + (ls2e_readl ((phys_addr_t )ioremap_nocache (LS2E_GENCFG_REG ,4 )) + & ~(1 <<2 )) |1 <<2 ; + +ls2e_writel (ctl, (phys_addr_t )ioremap_nocache (LS2E_GENCFG_REG ,4 )); + + ((void (*)(void ))ioremap_nocache (LS2E_RESET_VECTOR ,4 ))(); }static void loongson2e_halt (void )
Signature · 1 line
1.6.1
arch/mips/include/asm/mach-lemote/loongson2e.h line 30
Quoted 3 lines · Philippe Vachon
arch/mips/include/asm/mach-lemote/loongson2e.h new file +3
-0+static inline void ls2e_writeb (uint8_t value,phys_addr_t addr) +{ + *(volatile uint8_t *)addr = value;
So is addr a physical addres or a virtual one? In the first case you can't dereference it, in the latter the type is wrong.
Ralf
Quoted 7 lines · Ralf Baechle
arch/mips/include/asm/mach-lemote/loongson2e.h line 30
Quoted 3 lines
arch/mips/include/asm/mach-lemote/loongson2e.h new file +3
-0+static inline void ls2e_writeb (uint8_t value,phys_addr_t addr) +{ + *(volatile uint8_t *)addr = value;So is addr a physical addres or a virtual one? In the first case you can't dereference it, in the latter the type is wrong.
Aha, you caught me. That should be 'unsigned long' as opposed to phys_addr_t, as the address is a virtual address.
P.