rt288x: fix serial console
[lede.git] / target / linux / ramips / files / arch / mips / ralink / rt288x / setup.c
1 /*
2  * Ralink RT288x SoC specific setup
3  *
4  * Copyright (C) 2008 Gabor Juhos <juhosg@openwrt.org>
5  * Copyright (C) 2008 Imre Kaloz <kaloz@openwrt.org>
6  *
7  * Parts of this file are based on Ralink's 2.6.21 BSP
8  *
9  * This program is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU General Public License version 2 as published
11  * by the Free Software Foundation.
12  */
13
14 #include <linux/kernel.h>
15 #include <linux/init.h>
16 #include <linux/io.h>
17 #include <linux/serial_8250.h>
18
19 #include <asm/bootinfo.h>
20 #include <asm/mips_machine.h>
21 #include <asm/reboot.h>
22 #include <asm/time.h>
23
24 #include <asm/mach-ralink/rt288x.h>
25 #include <asm/mach-ralink/rt288x_regs.h>
26
27 #define RT288X_MEM_SIZE_MIN (2 * 1024 * 1024)
28 #define RT288X_MEM_SIZE_MAX (128 * 1024 * 1024)
29
30 unsigned long rt288x_mach_type;
31
32 static void rt288x_restart(char *command)
33 {
34         rt288x_sysc_wr(RT2880_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
35         while (1)
36                 if (cpu_wait)
37                         cpu_wait();
38 }
39
40 static void rt288x_halt(void)
41 {
42         while (1)
43                 cpu_wait();
44 }
45
46 static void __init rt288x_detect_mem_size(void)
47 {
48         unsigned long size;
49
50         for (size = RT288X_MEM_SIZE_MIN; size < RT288X_MEM_SIZE_MAX;
51              size <<= 1 ) {
52                 if (!memcmp(rt288x_detect_mem_size,
53                             rt288x_detect_mem_size + size, 1024))
54                         break;
55         }
56
57         add_memory_region(RT2880_SDRAM_BASE, size, BOOT_MEM_RAM);
58 }
59
60 static void __init rt288x_early_serial_setup(void)
61 {
62         struct uart_port p;
63         int err;
64
65         memset(&p, 0, sizeof(p));
66         p.flags         = UPF_SKIP_TEST;
67         p.iotype        = UPIO_AU;
68         p.uartclk       = rt288x_sys_freq;
69         p.regshift      = 2;
70         p.type          = PORT_16550A;
71
72         p.mapbase       = RT2880_UART0_BASE;
73         p.membase       = ioremap_nocache(p.mapbase, RT2880_UART0_SIZE);
74         p.line          = 0;
75         p.irq           = RT2880_INTC_IRQ_UART0;
76
77         err = early_serial_setup(&p);
78         if (err)
79                 printk(KERN_ERR "RT288x: early UART0 registration failed %d\n",
80                         err);
81
82         p.mapbase       = RT2880_UART1_BASE;
83         p.membase       = ioremap_nocache(p.mapbase, RT2880_UART1_SIZE);
84         p.line          = 1;
85         p.irq           = RT2880_INTC_IRQ_UART1;
86
87         err = early_serial_setup(&p);
88         if (err)
89                 printk(KERN_ERR "RT288x: early UART1 registration failed %d\n",
90                         err);
91 }
92
93 const char *get_system_type(void)
94 {
95         return rt288x_sys_type;
96 }
97
98 unsigned int __cpuinit get_c0_compare_irq(void)
99 {
100         return CP0_LEGACY_COMPARE_IRQ;
101 }
102
103 void __init plat_mem_setup(void)
104 {
105         set_io_port_base(KSEG1);
106
107         rt288x_sysc_base = ioremap_nocache(RT2880_SYSC_BASE, RT2880_SYSC_SIZE);
108         rt288x_memc_base = ioremap_nocache(RT2880_MEMC_BASE, RT2880_MEMC_SIZE);
109
110         rt288x_detect_mem_size();
111         rt288x_detect_sys_type();
112         rt288x_detect_sys_freq();
113
114         printk(KERN_INFO "%s running at %lu.%02lu MHz\n", get_system_type(),
115                 rt288x_cpu_freq / 1000000,
116                 (rt288x_cpu_freq % 1000000) * 100 / 1000000);
117
118         _machine_restart = rt288x_restart;
119         _machine_halt = rt288x_halt;
120         pm_power_off = rt288x_halt;
121
122         rt288x_early_serial_setup();
123 }
124
125 void __init plat_time_init(void)
126 {
127         mips_hpt_frequency = rt288x_cpu_freq / 2;
128 }
129
130 static int __init rt288x_machine_setup(void)
131 {
132         mips_machine_setup(rt288x_mach_type);
133
134         return 0;
135 }
136
137 arch_initcall(rt288x_machine_setup);