Merge master.kernel.org:/pub/scm/linux/kernel/git/wim/linux-2.6-watchdog
[pandora-kernel.git] / arch / mips / emma2rh / markeins / setup.c
1 /*
2  *  arch/mips/emma2rh/markeins/setup.c
3  *      This file is setup for EMMA2RH Mark-eins.
4  *
5  *  Copyright (C) NEC Electronics Corporation 2004-2006
6  *
7  *  This file is based on the arch/mips/ddb5xxx/ddb5477/setup.c.
8  *
9  *      Copyright 2001 MontaVista Software Inc.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25 #include <linux/config.h>
26 #include <linux/init.h>
27 #include <linux/kernel.h>
28 #include <linux/types.h>
29 #include <linux/initrd.h>
30 #include <linux/irq.h>
31 #include <linux/ide.h>
32 #include <linux/ioport.h>
33 #include <linux/param.h>        /* for HZ */
34 #include <linux/root_dev.h>
35 #include <linux/serial.h>
36 #include <linux/serial_core.h>
37
38 #include <asm/cpu.h>
39 #include <asm/bootinfo.h>
40 #include <asm/addrspace.h>
41 #include <asm/time.h>
42 #include <asm/bcache.h>
43 #include <asm/irq.h>
44 #include <asm/reboot.h>
45 #include <asm/gdb-stub.h>
46 #include <asm/traps.h>
47 #include <asm/debug.h>
48
49 #include <asm/emma2rh/emma2rh.h>
50
51 #define USE_CPU_COUNTER_TIMER   /* whether we use cpu counter */
52
53 extern void markeins_led(const char *);
54
55 static int bus_frequency = 0;
56
57 static void markeins_machine_restart(char *command)
58 {
59         static void (*back_to_prom) (void) = (void (*)(void))0xbfc00000;
60
61         printk("cannot EMMA2RH Mark-eins restart.\n");
62         markeins_led("restart.");
63         back_to_prom();
64 }
65
66 static void markeins_machine_halt(void)
67 {
68         printk("EMMA2RH Mark-eins halted.\n");
69         markeins_led("halted.");
70         while (1) ;
71 }
72
73 static void markeins_machine_power_off(void)
74 {
75         printk("EMMA2RH Mark-eins halted. Please turn off the power.\n");
76         markeins_led("poweroff.");
77         while (1) ;
78 }
79
80 static unsigned long clock[4] = { 166500000, 187312500, 199800000, 210600000 };
81
82 static unsigned int __init detect_bus_frequency(unsigned long rtc_base)
83 {
84         u32 reg;
85
86         /* detect from boot strap */
87         reg = emma2rh_in32(EMMA2RH_BHIF_STRAP_0);
88         reg = (reg >> 4) & 0x3;
89         return clock[reg];
90 }
91
92 static void __init emma2rh_time_init(void)
93 {
94         u32 reg;
95         if (bus_frequency == 0)
96                 bus_frequency = detect_bus_frequency(0);
97
98         reg = emma2rh_in32(EMMA2RH_BHIF_STRAP_0);
99         if ((reg & 0x3) == 0)
100                 reg = (reg >> 6) & 0x3;
101         else {
102                 reg = emma2rh_in32(EMMA2RH_BHIF_MAIN_CTRL);
103                 reg = (reg >> 4) & 0x3;
104         }
105         mips_hpt_frequency = (bus_frequency * (4 + reg)) / 4 / 2;
106 }
107
108 static void __init emma2rh_timer_setup(struct irqaction *irq)
109 {
110         /* we are using the cpu counter for timer interrupts */
111         setup_irq(CPU_IRQ_BASE + 7, irq);
112 }
113
114 static void markeins_board_init(void);
115 extern void markeins_irq_setup(void);
116
117 static void inline __init markeins_sio_setup(void)
118 {
119 #ifdef CONFIG_KGDB_8250
120         struct uart_port emma_port;
121
122         memset(&emma_port, 0, sizeof(emma_port));
123
124         emma_port.flags =
125             UPF_BOOT_AUTOCONF | UPF_SKIP_TEST;
126         emma_port.iotype = UPIO_MEM;
127         emma_port.regshift = 4; /* I/O addresses are every 8 bytes */
128         emma_port.uartclk = 18544000;   /* Clock rate of the chip */
129
130         emma_port.line = 0;
131         emma_port.mapbase = KSEG1ADDR(EMMA2RH_PFUR0_BASE + 3);
132         emma_port.membase = (u8*)emma_port.mapbase;
133         early_serial_setup(&emma_port);
134
135         emma_port.line = 1;
136         emma_port.mapbase = KSEG1ADDR(EMMA2RH_PFUR1_BASE + 3);
137         emma_port.membase = (u8*)emma_port.mapbase;
138         early_serial_setup(&emma_port);
139
140         emma_port.irq = EMMA2RH_IRQ_PFUR1;
141         kgdb8250_add_port(1, &emma_port);
142 #endif
143 }
144
145 void __init plat_mem_setup(void)
146 {
147         /* initialize board - we don't trust the loader */
148         markeins_board_init();
149
150         set_io_port_base(KSEG1ADDR(EMMA2RH_PCI_IO_BASE));
151
152         board_time_init = emma2rh_time_init;
153         board_timer_setup = emma2rh_timer_setup;
154
155         _machine_restart = markeins_machine_restart;
156         _machine_halt = markeins_machine_halt;
157         pm_power_off = markeins_machine_power_off;
158
159         /* setup resource limits */
160         ioport_resource.start = EMMA2RH_PCI_IO_BASE;
161         ioport_resource.end = EMMA2RH_PCI_IO_BASE + EMMA2RH_PCI_IO_SIZE - 1;
162         iomem_resource.start = EMMA2RH_IO_BASE;
163         iomem_resource.end = EMMA2RH_ROM_BASE - 1;
164
165         /* Reboot on panic */
166         panic_timeout = 180;
167
168         markeins_sio_setup();
169 }
170
171 static void __init markeins_board_init(void)
172 {
173         u32 val;
174
175         val = emma2rh_in32(EMMA2RH_PBRD_INT_EN);        /* open serial interrupts. */
176         emma2rh_out32(EMMA2RH_PBRD_INT_EN, val | 0xaa);
177         val = emma2rh_in32(EMMA2RH_PBRD_CLKSEL);        /* set serial clocks. */
178         emma2rh_out32(EMMA2RH_PBRD_CLKSEL, val | 0x5);  /* 18MHz */
179         emma2rh_out32(EMMA2RH_PCI_CONTROL, 0);
180
181         markeins_led("MVL E2RH");
182 }