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