This commit was manufactured by cvs2svn to create branch 'vserver'.
[linux-2.6.git] / arch / mips / momentum / ocelot_3 / setup.c
1 /*
2  * setup.c
3  *
4  * BRIEF MODULE DESCRIPTION
5  * Momentum Computer Ocelot-3 board dependent boot routines
6  *
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
11  *
12  * Author: Matthew Dharm, Momentum Computer
13  *   mdharm@momenco.com
14  *
15  * Louis Hamilton, Red Hat, Inc.
16  *   hamilton@redhat.com  [MIPS64 modifications]
17  *
18  * Author: RidgeRun, Inc.
19  *   glonnon@ridgerun.com, skranz@ridgerun.com, stevej@ridgerun.com
20  *
21  * Copyright 2001 MontaVista Software Inc.
22  * Author: jsun@mvista.com or jsun@junsun.net
23  *
24  * Copyright 2004 PMC-Sierra
25  * Author: Manish Lachwani (lachwani@pmc-sierra.com)
26  *
27  * Copyright (C) 2004 MontaVista Software Inc.
28  * Author: Manish Lachwani, mlachwani@mvista.com
29  *
30  *  This program is free software; you can redistribute  it and/or modify it
31  *  under  the terms of  the GNU General  Public License as published by the
32  *  Free Software Foundation;  either version 2 of the  License, or (at your
33  *  option) any later version.
34  *
35  *  THIS  SOFTWARE  IS PROVIDED   ``AS  IS'' AND   ANY  EXPRESS OR IMPLIED
36  *  WARRANTIES,   INCLUDING, BUT NOT  LIMITED  TO, THE IMPLIED WARRANTIES OF
37  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN
38  *  NO  EVENT  SHALL   THE AUTHOR  BE    LIABLE FOR ANY   DIRECT, INDIRECT,
39  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
40  *  NOT LIMITED   TO, PROCUREMENT OF  SUBSTITUTE GOODS  OR SERVICES; LOSS OF
41  *  USE, DATA,  OR PROFITS; OR  BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
42  *  ANY THEORY OF LIABILITY, WHETHER IN  CONTRACT, STRICT LIABILITY, OR TORT
43  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
44  *  THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
45  *
46  *  You should have received a copy of the  GNU General Public License along
47  *  with this program; if not, write  to the Free Software Foundation, Inc.,
48  *  675 Mass Ave, Cambridge, MA 02139, USA.
49  */
50 #include <linux/config.h>
51 #include <linux/init.h>
52 #include <linux/kernel.h>
53 #include <linux/types.h>
54 #include <linux/mc146818rtc.h>
55 #include <linux/ioport.h>
56 #include <linux/interrupt.h>
57 #include <linux/pci.h>
58 #include <linux/timex.h>
59 #include <linux/bootmem.h>
60 #include <linux/mv643xx.h>
61 #include <asm/time.h>
62 #include <asm/page.h>
63 #include <asm/bootinfo.h>
64 #include <asm/io.h>
65 #include <asm/irq.h>
66 #include <asm/pci.h>
67 #include <asm/processor.h>
68 #include <asm/ptrace.h>
69 #include <asm/reboot.h>
70 #include <asm/mc146818rtc.h>
71 #include <asm/tlbflush.h>
72 #include "ocelot_3_fpga.h"
73
74 /* Marvell Discovery Register Base */
75 unsigned long marvell_base = (signed)0xf4000000;
76
77 /* CPU clock */
78 unsigned long cpu_clock;
79
80 /* RTC/NVRAM */
81 unsigned char* rtc_base = (unsigned char*)(signed)0xfc800000;
82
83 /* FPGA Base */
84 unsigned long ocelot_fpga_base = (signed)0xfc000000;
85
86 /* Serial base */
87 unsigned long uart_base = (signed)0xfd000000;
88
89 /*
90  * Marvell Discovery SRAM. This is one place where Ethernet
91  * Tx and Rx descriptors can be placed to improve performance
92  */
93 extern unsigned long mv64340_sram_base;
94
95 /* These functions are used for rebooting or halting the machine*/
96 extern void momenco_ocelot_restart(char *command);
97 extern void momenco_ocelot_halt(void);
98 extern void momenco_ocelot_power_off(void);
99
100 void momenco_time_init(void);
101 static char reset_reason;
102
103 void add_wired_entry(unsigned long entrylo0, unsigned long entrylo1,
104                      unsigned long entryhi, unsigned long pagemask);
105
106 static inline unsigned long ENTRYLO(unsigned long paddr)
107 {
108         return ((paddr & PAGE_MASK) |
109                 (_PAGE_PRESENT | __READABLE | __WRITEABLE | _PAGE_GLOBAL |
110                 _CACHE_UNCACHED)) >> 6;
111 }
112
113 void __init bus_error_init(void)
114 {
115         /* nothing */
116 }
117
118 /*
119  * setup code for a handoff from a version 2 PMON 2000 PROM
120  */
121 void setup_wired_tlb_entries(void)
122 {
123         write_c0_wired(0);
124         local_flush_tlb_all();
125
126         /* marvell and extra space */
127         add_wired_entry(ENTRYLO(0xf4000000), ENTRYLO(0xf4010000), (signed)0xf4000000, PM_64K);
128
129         /* fpga, rtc, and uart */
130         add_wired_entry(ENTRYLO(0xfc000000), ENTRYLO(0xfd000000), (signed)0xfc000000, PM_16M);
131 }
132
133 #define CONV_BCD_TO_BIN(val)    (((val) & 0xf) + (((val) >> 4) * 10))
134 #define CONV_BIN_TO_BCD(val)    (((val) % 10) + (((val) / 10) << 4))
135
136 unsigned long m48t37y_get_time(void)
137 {
138         unsigned int year, month, day, hour, min, sec;
139
140         /* stop the update */
141         rtc_base[0x7ff8] = 0x40;
142
143         year = CONV_BCD_TO_BIN(rtc_base[0x7fff]);
144         year += CONV_BCD_TO_BIN(rtc_base[0x7ff1]) * 100;
145
146         month = CONV_BCD_TO_BIN(rtc_base[0x7ffe]);
147
148         day = CONV_BCD_TO_BIN(rtc_base[0x7ffd]);
149
150         hour = CONV_BCD_TO_BIN(rtc_base[0x7ffb]);
151         min = CONV_BCD_TO_BIN(rtc_base[0x7ffa]);
152         sec = CONV_BCD_TO_BIN(rtc_base[0x7ff9]);
153
154         /* start the update */
155         rtc_base[0x7ff8] = 0x00;
156
157         return mktime(year, month, day, hour, min, sec);
158 }
159
160 int m48t37y_set_time(unsigned long sec)
161 {
162         struct rtc_time tm;
163
164         /* convert to a more useful format -- note months count from 0 */
165         to_tm(sec, &tm);
166         tm.tm_mon += 1;
167
168         /* enable writing */
169         rtc_base[0x7ff8] = 0x80;
170
171         /* year */
172         rtc_base[0x7fff] = CONV_BIN_TO_BCD(tm.tm_year % 100);
173         rtc_base[0x7ff1] = CONV_BIN_TO_BCD(tm.tm_year / 100);
174
175         /* month */
176         rtc_base[0x7ffe] = CONV_BIN_TO_BCD(tm.tm_mon);
177
178         /* day */
179         rtc_base[0x7ffd] = CONV_BIN_TO_BCD(tm.tm_mday);
180
181         /* hour/min/sec */
182         rtc_base[0x7ffb] = CONV_BIN_TO_BCD(tm.tm_hour);
183         rtc_base[0x7ffa] = CONV_BIN_TO_BCD(tm.tm_min);
184         rtc_base[0x7ff9] = CONV_BIN_TO_BCD(tm.tm_sec);
185
186         /* day of week -- not really used, but let's keep it up-to-date */
187         rtc_base[0x7ffc] = CONV_BIN_TO_BCD(tm.tm_wday + 1);
188
189         /* disable writing */
190         rtc_base[0x7ff8] = 0x00;
191
192         return 0;
193 }
194
195 void momenco_timer_setup(struct irqaction *irq)
196 {
197         setup_irq(7, irq);      /* Timer interrupt, unmask status IM7 */
198 }
199
200 void momenco_time_init(void)
201 {
202         setup_wired_tlb_entries();
203
204         /*
205          * Ocelot-3 board has been built with both
206          * the Rm7900 and the Rm7065C
207          */
208         mips_hpt_frequency = cpu_clock / 2;
209         board_timer_setup = momenco_timer_setup;
210
211         rtc_get_time = m48t37y_get_time;
212         rtc_set_time = m48t37y_set_time;
213 }
214
215 /*
216  * PCI Support for Ocelot-3
217  */
218
219 /* Bus #0 IO and MEM space */
220 #define OCELOT_3_PCI_IO_0_START         0xe0000000
221 #define OCELOT_3_PCI_IO_0_SIZE          0x08000000
222 #define OCELOT_3_PCI_MEM_0_START        0xc0000000
223 #define OCELOT_3_PCI_MEM_0_SIZE         0x10000000
224
225 /* Bus #1 IO and MEM space */
226 #define OCELOT_3_PCI_IO_1_START         0xe8000000
227 #define OCELOT_3_PCI_IO_1_SIZE          0x08000000
228 #define OCELOT_3_PCI_MEM_1_START        0xd0000000
229 #define OCELOT_3_PCI_MEM_1_SIZE         0x10000000
230
231 static struct resource mv_pci_io_mem0_resource = {
232         .name   = "MV64340 PCI0 IO MEM",
233         .start  = OCELOT_3_PCI_IO_0_START,
234         .end    = OCELOT_3_PCI_IO_0_START + OCELOT_3_PCI_IO_0_SIZE - 1,
235         .flags  = IORESOURCE_IO,
236 };
237
238 static struct resource mv_pci_io_mem1_resource = {
239         .name   = "MV64340 PCI1 IO MEM",
240         .start  = OCELOT_3_PCI_IO_1_START,
241         .end    = OCELOT_3_PCI_IO_1_START + OCELOT_3_PCI_IO_1_SIZE - 1,
242         .flags  = IORESOURCE_IO,
243 };
244
245 static struct resource mv_pci_mem0_resource = {
246         .name   = "MV64340 PCI0 MEM",
247         .start  = OCELOT_3_PCI_MEM_0_START,
248         .end    = OCELOT_3_PCI_MEM_0_START + OCELOT_3_PCI_MEM_0_SIZE - 1,
249         .flags  = IORESOURCE_MEM,
250 };
251
252 static struct resource mv_pci_mem1_resource = {
253         .name   = "MV64340 PCI1 MEM",
254         .start  = OCELOT_3_PCI_MEM_1_START,
255         .end    = OCELOT_3_PCI_MEM_1_START + OCELOT_3_PCI_MEM_1_SIZE - 1,
256         .flags  = IORESOURCE_MEM,
257 };
258
259 static struct mv_pci_controller mv_bus0_controller = {
260         .pcic = {
261                  .pci_ops       = &mv_pci_ops,
262                  .mem_resource  = &mv_pci_mem0_resource,
263                  .io_resource   = &mv_pci_io_mem0_resource,
264         },
265         .config_addr    = MV64340_PCI_0_CONFIG_ADDR,
266         .config_vreg    = MV64340_PCI_0_CONFIG_DATA_VIRTUAL_REG,
267 };
268
269 static struct mv_pci_controller mv_bus1_controller = {
270         .pcic = {
271                  .pci_ops       = &mv_pci_ops,
272                  .mem_resource  = &mv_pci_mem1_resource,
273                  .io_resource   = &mv_pci_io_mem1_resource,
274         },
275         .config_addr    = MV64340_PCI_1_CONFIG_ADDR,
276         .config_vreg    = MV64340_PCI_1_CONFIG_DATA_VIRTUAL_REG,
277 };
278
279 static __init int __init ja_pci_init(void)
280 {
281         uint32_t enable;
282         extern int pci_probe_only;
283
284         /* PMON will assign PCI resources */
285         pci_probe_only = 1;
286
287         enable = ~MV_READ(MV64340_BASE_ADDR_ENABLE);
288         /*
289          * We require at least one enabled I/O or PCI memory window or we
290          * will ignore this PCI bus.  We ignore PCI windows 1, 2 and 3.
291          */
292         if (enable & (0x01 <<  9) || enable & (0x01 << 10))
293                 register_pci_controller(&mv_bus0_controller.pcic);
294
295         if (enable & (0x01 << 14) || enable & (0x01 << 15))
296                 register_pci_controller(&mv_bus1_controller.pcic);
297
298         ioport_resource.end = OCELOT_3_PCI_IO_0_START + OCELOT_3_PCI_IO_0_SIZE +
299                                         OCELOT_3_PCI_IO_1_SIZE - 1;
300
301         iomem_resource.end = OCELOT_3_PCI_MEM_0_START + OCELOT_3_PCI_MEM_0_SIZE +
302                                         OCELOT_3_PCI_MEM_1_SIZE - 1;
303
304         set_io_port_base(OCELOT_3_PCI_IO_0_START); /* mips_io_port_base */
305
306         return 0;
307 }
308
309 arch_initcall(ja_pci_init);
310
311 static int __init momenco_ocelot_3_setup(void)
312 {
313         unsigned int tmpword;
314
315         board_time_init = momenco_time_init;
316
317         _machine_restart = momenco_ocelot_restart;
318         _machine_halt = momenco_ocelot_halt;
319         _machine_power_off = momenco_ocelot_power_off;
320
321         /* Wired TLB entries */
322         setup_wired_tlb_entries();
323
324         /* shut down ethernet ports, just to be sure our memory doesn't get
325          * corrupted by random ethernet traffic.
326          */
327         MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0), 0xff << 8);
328         MV_WRITE(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1), 0xff << 8);
329         MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0), 0xff << 8);
330         MV_WRITE(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1), 0xff << 8);
331         do {}
332           while (MV_READ(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(0)) & 0xff);
333         do {}
334           while (MV_READ(MV64340_ETH_RECEIVE_QUEUE_COMMAND_REG(1)) & 0xff);
335         do {}
336           while (MV_READ(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(0)) & 0xff);
337         do {}
338           while (MV_READ(MV64340_ETH_TRANSMIT_QUEUE_COMMAND_REG(1)) & 0xff);
339         MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0),
340                  MV_READ(MV64340_ETH_PORT_SERIAL_CONTROL_REG(0)) & ~1);
341         MV_WRITE(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1),
342                  MV_READ(MV64340_ETH_PORT_SERIAL_CONTROL_REG(1)) & ~1);
343
344         /* Turn off the Bit-Error LED */
345         OCELOT_FPGA_WRITE(0x80, CLR);
346
347         tmpword = OCELOT_FPGA_READ(BOARDREV);
348         if (tmpword < 26)
349                 printk("Momenco Ocelot-3: Board Assembly Rev. %c\n",
350                         'A'+tmpword);
351         else
352                 printk("Momenco Ocelot-3: Board Assembly Revision #0x%x\n",
353                         tmpword);
354
355         tmpword = OCELOT_FPGA_READ(FPGA_REV);
356         printk("FPGA Rev: %d.%d\n", tmpword>>4, tmpword&15);
357         tmpword = OCELOT_FPGA_READ(RESET_STATUS);
358         printk("Reset reason: 0x%x\n", tmpword);
359         switch (tmpword) {
360                 case 0x1:
361                         printk("  - Power-up reset\n");
362                         break;
363                 case 0x2:
364                         printk("  - Push-button reset\n");
365                         break;
366                 case 0x4:
367                         printk("  - cPCI bus reset\n");
368                         break;
369                 case 0x8:
370                         printk("  - Watchdog reset\n");
371                         break;
372                 case 0x10:
373                         printk("  - Software reset\n");
374                         break;
375                 default:
376                         printk("  - Unknown reset cause\n");
377         }
378         reset_reason = tmpword;
379         OCELOT_FPGA_WRITE(0xff, RESET_STATUS);
380
381         tmpword = OCELOT_FPGA_READ(CPCI_ID);
382         printk("cPCI ID register: 0x%02x\n", tmpword);
383         printk("  - Slot number: %d\n", tmpword & 0x1f);
384         printk("  - PCI bus present: %s\n", tmpword & 0x40 ? "yes" : "no");
385         printk("  - System Slot: %s\n", tmpword & 0x20 ? "yes" : "no");
386
387         tmpword = OCELOT_FPGA_READ(BOARD_STATUS);
388         printk("Board Status register: 0x%02x\n", tmpword);
389         printk("  - User jumper: %s\n", (tmpword & 0x80)?"installed":"absent");
390         printk("  - Boot flash write jumper: %s\n", (tmpword&0x40)?"installed":"absent");
391         printk("  - L3 cache size: %d MB\n", (1<<((tmpword&12) >> 2))&~1);
392
393         /* Support for 128 MB memory */
394         add_memory_region(0x0, 0x08000000, BOOT_MEM_RAM);
395
396         return 0;
397 }
398
399 early_initcall(momenco_ocelot_3_setup);