05184f0bd806ffee10354163fbcf388f07439d6a
[openwrt/openwrt.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/mips_machine.h>
20 #include <asm/reboot.h>
21 #include <asm/time.h>
22
23 #include <asm/mach-ralink/common.h>
24 #include <asm/mach-ralink/rt288x.h>
25 #include <asm/mach-ralink/rt288x_regs.h>
26
27 unsigned long rt288x_mach_type;
28
29 static void rt288x_restart(char *command)
30 {
31 rt288x_sysc_wr(RT2880_RESET_SYSTEM, SYSC_REG_RESET_CTRL);
32 while (1)
33 if (cpu_wait)
34 cpu_wait();
35 }
36
37 static void rt288x_halt(void)
38 {
39 while (1)
40 cpu_wait();
41 }
42
43 static void __init rt288x_early_serial_setup(void)
44 {
45 struct uart_port p;
46 int err;
47
48 memset(&p, 0, sizeof(p));
49 p.flags = UPF_SKIP_TEST;
50 p.iotype = UPIO_AU;
51 p.uartclk = rt288x_sys_freq;
52 p.regshift = 2;
53 p.type = PORT_16550A;
54
55 p.mapbase = RT2880_UART0_BASE;
56 p.membase = ioremap_nocache(p.mapbase, RT2880_UART0_SIZE);
57 p.line = 0;
58 p.irq = RT2880_INTC_IRQ_UART0;
59
60 err = early_serial_setup(&p);
61 if (err)
62 printk(KERN_ERR "RT288x: early UART0 registration failed %d\n",
63 err);
64
65 p.mapbase = RT2880_UART1_BASE;
66 p.membase = ioremap_nocache(p.mapbase, RT2880_UART1_SIZE);
67 p.line = 1;
68 p.irq = RT2880_INTC_IRQ_UART1;
69
70 err = early_serial_setup(&p);
71 if (err)
72 printk(KERN_ERR "RT288x: early UART1 registration failed %d\n",
73 err);
74 }
75
76 unsigned int __cpuinit get_c0_compare_irq(void)
77 {
78 return CP0_LEGACY_COMPARE_IRQ;
79 }
80
81 void __init ramips_soc_setup(void)
82 {
83 rt288x_sysc_base = ioremap_nocache(RT2880_SYSC_BASE, RT2880_SYSC_SIZE);
84 rt288x_memc_base = ioremap_nocache(RT2880_MEMC_BASE, RT2880_MEMC_SIZE);
85
86 rt288x_detect_sys_type();
87 rt288x_detect_sys_freq();
88
89 printk(KERN_INFO "%s running at %lu.%02lu MHz\n", ramips_sys_type,
90 rt288x_cpu_freq / 1000000,
91 (rt288x_cpu_freq % 1000000) * 100 / 1000000);
92
93 _machine_restart = rt288x_restart;
94 _machine_halt = rt288x_halt;
95 pm_power_off = rt288x_halt;
96
97 rt288x_early_serial_setup();
98 }
99
100 void __init plat_time_init(void)
101 {
102 mips_hpt_frequency = rt288x_cpu_freq / 2;
103 }
104
105 static int __init rt288x_machine_setup(void)
106 {
107 mips_machine_setup(rt288x_mach_type);
108
109 return 0;
110 }
111
112 arch_initcall(rt288x_machine_setup);