4 * BRIEF MODULE DESCRIPTION
5 * Momentum Computer Ocelot-C and -CS board dependent boot routines
7 * Copyright (C) 1996, 1997, 2001 Ralf Baechle
8 * Copyright (C) 2000 RidgeRun, Inc.
9 * Copyright (C) 2001 Red Hat, Inc.
10 * Copyright (C) 2002 Momentum Computer
12 * Author: Matthew Dharm, Momentum Computer
15 * Louis Hamilton, Red Hat, Inc.
16 * hamilton@redhat.com [MIPS64 modifications]
18 * Author: RidgeRun, Inc.
19 * glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
21 * Copyright 2001 MontaVista Software Inc.
22 * Author: jsun@mvista.com or jsun@junsun.net
24 * This program is free software; you can redistribute it and/or modify it
25 * under the terms of the GNU General Public License as published by the
26 * Free Software Foundation; either version 2 of the License, or (at your
27 * option) any later version.
29 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
30 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
31 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
32 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
36 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 * You should have received a copy of the GNU General Public License along
41 * with this program; if not, write to the Free Software Foundation, Inc.,
42 * 675 Mass Ave, Cambridge, MA 02139, USA.
45 #include <linux/init.h>
46 #include <linux/kernel.h>
47 #include <linux/types.h>
48 #include <linux/mc146818rtc.h>
50 #include <linux/swap.h>
51 #include <linux/ioport.h>
52 #include <linux/sched.h>
53 #include <linux/interrupt.h>
54 #include <linux/pci.h>
55 #include <linux/timex.h>
56 #include <linux/vmalloc.h>
58 #include <asm/bootinfo.h>
60 #include <asm/bootinfo.h>
64 #include <asm/processor.h>
65 #include <asm/ptrace.h>
66 #include <asm/reboot.h>
67 #include <asm/mc146818rtc.h>
68 #include <linux/version.h>
69 #include <linux/bootmem.h>
70 #include <linux/blk.h>
71 #include <asm/mv64340.h>
72 #include "ocelot_c_fpga.h"
74 unsigned long mv64340_base;
75 extern unsigned long mv64340_sram_base;
76 unsigned long cpu_clock;
78 /* These functions are used for rebooting or halting the machine*/
79 extern void momenco_ocelot_restart(char *command);
80 extern void momenco_ocelot_halt(void);
81 extern void momenco_ocelot_power_off(void);
83 void momenco_time_init(void);
85 static char reset_reason;
87 void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1, unsigned long entryhi, unsigned long pagemask);
88 #define ENTRYLO(x) ((pte_val(mk_pte_phys((x), PAGE_KERNEL_UNCACHED)) >> 6)|1)
90 /* setup code for a handoff from a version 2 PMON 2000 PROM */
91 void PMON_v2_setup(void)
93 /* Some wired TLB entries for the MV64340 and perhiperals. The
94 MV64340 is going to be hit on every IRQ anyway - there's
95 absolutely no point in letting it be a random TLB entry, as
96 it'll just cause needless churning of the TLB. And we use
97 the other half for the serial port, which is just a PITA
100 Device Physical Virtual
101 MV64340 Internal Regs 0xf4000000 0xf4000000
102 Ocelot-C[S] PLD (CS0) 0xfc000000 0xfc000000
103 NVRAM (CS1) 0xfc800000 0xfc800000
104 UARTs (CS2) 0xfd000000 0xfd000000
105 Internal SRAM 0xfe000000 0xfe000000
106 M-Systems DOC (CS3) 0xff000000 0xff000000
108 printk("PMON_v2_setup\n");
111 /* marvell and extra space */
112 add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), 0xfffffffff4000000, PM_64K);
113 /* fpga, rtc, and uart */
114 add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), 0xfffffffffc000000, PM_16M);
115 /* m-sys and internal SRAM */
116 add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000), 0xfffffffffe000000, PM_16M);
118 mv64340_base = 0xfffffffff4000000;
119 mv64340_sram_base = 0xfffffffffe000000;
121 /* marvell and extra space */
122 add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), 0xf4000000, PM_64K);
123 /* fpga, rtc, and uart */
124 add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), 0xfc000000, PM_16M);
125 /* m-sys and internal SRAM */
126 add_wired_entry(ENTRYLO(0xfe000000), ENTRYLO(0xff000000), 0xfe000000, PM_16M);
128 mv64340_base = 0xf4000000;
129 mv64340_sram_base = 0xfe000000;
133 #define CONV_BCD_TO_BIN(val) (((val) & 0xf) + (((val) >> 4) * 10))
134 #define CONV_BIN_TO_BCD(val) (((val) % 10) + (((val) / 10) << 4))
136 unsigned long m48t37y_get_time(void)
139 unsigned char *rtc_base = (unsigned char*)0xfffffffffc800000;
141 unsigned char* rtc_base = (unsigned char*)0xfc800000;
143 unsigned int year, month, day, hour, min, sec;
145 /* stop the update */
146 rtc_base[0x7ff8] = 0x40;
148 year = CONV_BCD_TO_BIN(rtc_base[0x7fff]);
149 year += CONV_BCD_TO_BIN(rtc_base[0x7ff1]) * 100;
151 month = CONV_BCD_TO_BIN(rtc_base[0x7ffe]);
153 day = CONV_BCD_TO_BIN(rtc_base[0x7ffd]);
155 hour = CONV_BCD_TO_BIN(rtc_base[0x7ffb]);
156 min = CONV_BCD_TO_BIN(rtc_base[0x7ffa]);
157 sec = CONV_BCD_TO_BIN(rtc_base[0x7ff9]);
159 /* start the update */
160 rtc_base[0x7ff8] = 0x00;
162 return mktime(year, month, day, hour, min, sec);
165 int m48t37y_set_time(unsigned long sec)
168 unsigned char* rtc_base = (unsigned char*)0xfffffffffc800000;
170 unsigned char* rtc_base = (unsigned char*)0xfc800000;
174 /* convert to a more useful format -- note months count from 0 */
179 rtc_base[0x7ff8] = 0x80;
182 rtc_base[0x7fff] = CONV_BIN_TO_BCD(tm.tm_year % 100);
183 rtc_base[0x7ff1] = CONV_BIN_TO_BCD(tm.tm_year / 100);
186 rtc_base[0x7ffe] = CONV_BIN_TO_BCD(tm.tm_mon);
189 rtc_base[0x7ffd] = CONV_BIN_TO_BCD(tm.tm_mday);
192 rtc_base[0x7ffb] = CONV_BIN_TO_BCD(tm.tm_hour);
193 rtc_base[0x7ffa] = CONV_BIN_TO_BCD(tm.tm_min);
194 rtc_base[0x7ff9] = CONV_BIN_TO_BCD(tm.tm_sec);
196 /* day of week -- not really used, but let's keep it up-to-date */
197 rtc_base[0x7ffc] = CONV_BIN_TO_BCD(tm.tm_wday + 1);
199 /* disable writing */
200 rtc_base[0x7ff8] = 0x00;
205 void momenco_timer_setup(struct irqaction *irq)
210 void momenco_time_init(void)
212 #ifdef CONFIG_CPU_SR71000
213 mips_hpt_frequency = cpu_clock;
214 #elif defined(CONFIG_CPU_RM7000)
215 mips_hpt_frequency = cpu_clock / 2;
217 #error Unknown CPU for this board
219 printk("momenco_time_init cpu_clock=%d\n", cpu_clock);
220 board_timer_setup = momenco_timer_setup;
222 rtc_get_time = m48t37y_get_time;
223 rtc_set_time = m48t37y_set_time;
226 void __init momenco_ocelot_c_setup(void)
228 unsigned int tmpword;
230 board_time_init = momenco_time_init;
232 _machine_restart = momenco_ocelot_restart;
233 _machine_halt = momenco_ocelot_halt;
234 _machine_power_off = momenco_ocelot_power_off;
237 * initrd_start = (ulong)ocelot_initrd_start;
238 * initrd_end = (ulong)ocelot_initrd_start + (ulong)ocelot_initrd_size;
239 * initrd_below_start_ok = 1;
242 /* do handoff reconfiguration */
245 /* shut down ethernet ports, just to be sure our memory doesn't get
246 * corrupted by random ethernet traffic.
248 MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
249 MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
250 MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
251 MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
253 while (MV_READ_DATA(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
255 while (MV_READ_DATA(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
257 while (MV_READ_DATA(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
259 while (MV_READ_DATA(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
260 MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0), MV_READ_DATA(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
261 MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1), MV_READ_DATA(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
263 /* Turn off the Bit-Error LED */
264 OCELOT_FPGA_WRITE(0x80, CLR);
266 tmpword = OCELOT_FPGA_READ(BOARDREV);
267 #ifdef CONFIG_CPU_SR71000
269 printk("Momenco Ocelot-CS: Board Assembly Rev. %c\n",
272 printk("Momenco Ocelot-CS: Board Assembly Revision #0x%x\n",
276 printk("Momenco Ocelot-C: Board Assembly Rev. %c\n",
279 printk("Momenco Ocelot-C: Board Assembly Revision #0x%x\n",
283 tmpword = OCELOT_FPGA_READ(FPGA_REV);
284 printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
285 tmpword = OCELOT_FPGA_READ(RESET_STATUS);
286 printk("Reset reason: 0x%x\n", tmpword);
289 printk(" - Power-up reset\n");
292 printk(" - Push-button reset\n");
295 printk(" - cPCI bus reset\n");
298 printk(" - Watchdog reset\n");
301 printk(" - Software reset\n");
304 printk(" - Unknown reset cause\n");
306 reset_reason = tmpword;
307 OCELOT_FPGA_WRITE(0xff, RESET_STATUS);
309 tmpword = OCELOT_FPGA_READ(CPCI_ID);
310 printk("cPCI ID register: 0x%02x\n", tmpword);
311 printk(" - Slot number: %d\n", tmpword & 0x1f);
312 printk(" - PCI bus present: %s\n", tmpword & 0x40 ? "yes" : "no");
313 printk(" - System Slot: %s\n", tmpword & 0x20 ? "yes" : "no");
315 tmpword = OCELOT_FPGA_READ(BOARD_STATUS);
316 printk("Board Status register: 0x%02x\n", tmpword);
317 printk(" - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
318 printk(" - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
319 printk(" - L3 Cache size: %d MiB\n", (1<<((tmpword&12) >> 2))&~1);
320 printk(" - SDRAM size: %d MiB\n", 1<<(6+(tmpword&3)));
325 add_memory_region(0x0, 0x200<<20, BOOT_MEM_RAM);
329 add_memory_region(0x0, 0x100<<20, BOOT_MEM_RAM);
333 add_memory_region(0x0, 0x80<<20, BOOT_MEM_RAM);
336 /* 1GiB -- needs CONFIG_HIGHMEM */
337 add_memory_region(0x0, 0x400<<20, BOOT_MEM_RAM);
342 #ifndef CONFIG_MIPS64
343 /* This needs to be one of the first initcalls, because no I/O port access
344 can work before this */
345 static int io_base_ioremap(void)
347 /* we're mapping PCI accesses from 0xc0000000 to 0xf0000000 */
348 void *io_remap_range = ioremap(0xc0000000, 0x30000000);
350 if (!io_remap_range) {
351 panic("Could not ioremap I/O port range");
353 printk("io_remap_range set at 0x%08x\n", (uint32_t)io_remap_range);
354 set_io_port_base(io_remap_range - 0xc0000000);
359 module_init(io_base_ioremap);