Merge git://git.infradead.org/mtd-2.6
[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/init.h>
26 #include <linux/kernel.h>
27 #include <linux/types.h>
28 #include <linux/initrd.h>
29 #include <linux/irq.h>
30 #include <linux/ide.h>
31 #include <linux/ioport.h>
32 #include <linux/param.h>        /* for HZ */
33 #include <linux/root_dev.h>
34 #include <linux/serial.h>
35 #include <linux/serial_core.h>
36
37 #include <asm/cpu.h>
38 #include <asm/bootinfo.h>
39 #include <asm/addrspace.h>
40 #include <asm/time.h>
41 #include <asm/bcache.h>
42 #include <asm/irq.h>
43 #include <asm/reboot.h>
44 #include <asm/traps.h>
45 #include <asm/debug.h>
46
47 #include <asm/emma2rh/emma2rh.h>
48
49 #define USE_CPU_COUNTER_TIMER   /* whether we use cpu counter */
50
51 extern void markeins_led(const char *);
52
53 static int bus_frequency = 0;
54
55 static void markeins_machine_restart(char *command)
56 {
57         static void (*back_to_prom) (void) = (void (*)(void))0xbfc00000;
58
59         printk("cannot EMMA2RH Mark-eins restart.\n");
60         markeins_led("restart.");
61         back_to_prom();
62 }
63
64 static void markeins_machine_halt(void)
65 {
66         printk("EMMA2RH Mark-eins halted.\n");
67         markeins_led("halted.");
68         while (1) ;
69 }
70
71 static void markeins_machine_power_off(void)
72 {
73         printk("EMMA2RH Mark-eins halted. Please turn off the power.\n");
74         markeins_led("poweroff.");
75         while (1) ;
76 }
77
78 static unsigned long __initdata emma2rh_clock[4] = {
79         166500000, 187312500, 199800000, 210600000
80 };
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
90         return emma2rh_clock[reg];
91 }
92
93 void __init plat_time_init(void)
94 {
95         u32 reg;
96         if (bus_frequency == 0)
97                 bus_frequency = detect_bus_frequency(0);
98
99         reg = emma2rh_in32(EMMA2RH_BHIF_STRAP_0);
100         if ((reg & 0x3) == 0)
101                 reg = (reg >> 6) & 0x3;
102         else {
103                 reg = emma2rh_in32(EMMA2RH_BHIF_MAIN_CTRL);
104                 reg = (reg >> 4) & 0x3;
105         }
106         mips_hpt_frequency = (bus_frequency * (4 + reg)) / 4 / 2;
107 }
108
109 static void markeins_board_init(void);
110 extern void markeins_irq_setup(void);
111
112 static void inline __init markeins_sio_setup(void)
113 {
114 }
115
116 void __init plat_mem_setup(void)
117 {
118         /* initialize board - we don't trust the loader */
119         markeins_board_init();
120
121         set_io_port_base(KSEG1ADDR(EMMA2RH_PCI_IO_BASE));
122
123         _machine_restart = markeins_machine_restart;
124         _machine_halt = markeins_machine_halt;
125         pm_power_off = markeins_machine_power_off;
126
127         /* setup resource limits */
128         ioport_resource.start = EMMA2RH_PCI_IO_BASE;
129         ioport_resource.end = EMMA2RH_PCI_IO_BASE + EMMA2RH_PCI_IO_SIZE - 1;
130         iomem_resource.start = EMMA2RH_IO_BASE;
131         iomem_resource.end = EMMA2RH_ROM_BASE - 1;
132
133         /* Reboot on panic */
134         panic_timeout = 180;
135
136         markeins_sio_setup();
137 }
138
139 static void __init markeins_board_init(void)
140 {
141         u32 val;
142
143         val = emma2rh_in32(EMMA2RH_PBRD_INT_EN);        /* open serial interrupts. */
144         emma2rh_out32(EMMA2RH_PBRD_INT_EN, val | 0xaa);
145         val = emma2rh_in32(EMMA2RH_PBRD_CLKSEL);        /* set serial clocks. */
146         emma2rh_out32(EMMA2RH_PBRD_CLKSEL, val | 0x5);  /* 18MHz */
147         emma2rh_out32(EMMA2RH_PCI_CONTROL, 0);
148
149         markeins_led("MVL E2RH");
150 }