vserver 1.9.3
[linux-2.6.git] / arch / ppc / syslib / m8260_setup.c
1 /*
2  *  arch/ppc/syslib/m8260_setup.c
3  *
4  *  Copyright (C) 1995  Linus Torvalds
5  *  Adapted from 'alpha' version by Gary Thomas
6  *  Modified by Cort Dougan (cort@cs.nmt.edu)
7  *  Modified for MBX using prep/chrp/pmac functions by Dan (dmalek@jlc.net)
8  *  Further modified for generic 8xx and 8260 by Dan.
9  */
10
11 #include <linux/config.h>
12 #include <linux/sched.h>
13 #include <linux/kernel.h>
14 #include <linux/mm.h>
15 #include <linux/stddef.h>
16 #include <linux/slab.h>
17 #include <linux/init.h>
18 #include <linux/initrd.h>
19 #include <linux/seq_file.h>
20 #include <linux/irq.h>
21
22 #include <asm/mmu.h>
23 #include <asm/io.h>
24 #include <asm/pgtable.h>
25 #include <asm/mpc8260.h>
26 #include <asm/immap_cpm2.h>
27 #include <asm/machdep.h>
28 #include <asm/bootinfo.h>
29 #include <asm/time.h>
30
31 #include "cpm2_pic.h"
32
33 unsigned char __res[sizeof(bd_t)];
34
35 extern void cpm2_reset(void);
36 extern void m8260_find_bridges(void);
37 extern void idma_pci9_init(void);
38
39 static void __init
40 m8260_setup_arch(void)
41 {
42         /* Print out Vendor and Machine info. */
43         printk(KERN_INFO "%s %s port\n", CPUINFO_VENDOR, CPUINFO_MACHINE);
44
45         /* Reset the Communication Processor Module. */
46         cpm2_reset();
47 #ifdef CONFIG_8260_PCI9
48         /* Initialise IDMA for PCI erratum workaround */
49         idma_pci9_init();
50 #endif
51 #ifdef CONFIG_PCI_8260
52         m8260_find_bridges();
53 #endif
54 #ifdef CONFIG_BLK_DEV_INITRD
55         if (initrd_start)
56                 ROOT_DEV = Root_RAM0;
57 #endif
58 }
59
60 /* The decrementer counts at the system (internal) clock frequency
61  * divided by four.
62  */
63 static void __init
64 m8260_calibrate_decr(void)
65 {
66         bd_t *binfo = (bd_t *)__res;
67         int freq, divisor;
68
69         freq = binfo->bi_busfreq;
70         divisor = 4;
71         tb_ticks_per_jiffy = freq / HZ / divisor;
72         tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
73 }
74
75 /* The 8260 has an internal 1-second timer update register that
76  * we should use for this purpose.
77  */
78 static uint rtc_time;
79
80 static int
81 m8260_set_rtc_time(unsigned long time)
82 {
83         rtc_time = time;
84
85         return(0);
86 }
87
88 static unsigned long
89 m8260_get_rtc_time(void)
90 {
91         /* Get time from the RTC.
92         */
93         return((unsigned long)rtc_time);
94 }
95
96 #ifndef BOOTROM_RESTART_ADDR
97 #warning "Using default BOOTROM_RESTART_ADDR!"
98 #define BOOTROM_RESTART_ADDR    0xff000104
99 #endif
100
101 static void
102 m8260_restart(char *cmd)
103 {
104         extern void m8260_gorom(bd_t *bi, uint addr);
105         uint    startaddr;
106
107         /* Most boot roms have a warmstart as the second instruction
108          * of the reset vector.  If that doesn't work for you, change this
109          * or the reboot program to send a proper address.
110          */
111         startaddr = BOOTROM_RESTART_ADDR;
112         if (cmd != NULL) {
113                 if (!strncmp(cmd, "startaddr=", 10))
114                         startaddr = simple_strtoul(&cmd[10], NULL, 0);
115         }
116
117         m8260_gorom((void*)__pa(__res), startaddr);
118 }
119
120 static void
121 m8260_halt(void)
122 {
123         local_irq_disable();
124         while (1);
125 }
126
127 static void
128 m8260_power_off(void)
129 {
130         m8260_halt();
131 }
132
133 static int
134 m8260_show_cpuinfo(struct seq_file *m)
135 {
136         bd_t *bp = (bd_t *)__res;
137
138         seq_printf(m, "vendor\t\t: %s\n"
139                    "machine\t\t: %s\n"
140                    "\n"
141                    "mem size\t\t: 0x%08x\n"
142                    "console baud\t\t: %d\n"
143                    "\n"
144                    "core clock\t: %u MHz\n"
145                    "CPM  clock\t: %u MHz\n"
146                    "bus  clock\t: %u MHz\n",
147                    CPUINFO_VENDOR, CPUINFO_MACHINE, bp->bi_memsize,
148                    bp->bi_baudrate, bp->bi_intfreq / 1000000,
149                    bp->bi_cpmfreq / 1000000, bp->bi_busfreq / 1000000);
150         return 0;
151 }
152
153 /* Initialize the internal interrupt controller.  The number of
154  * interrupts supported can vary with the processor type, and the
155  * 8260 family can have up to 64.
156  * External interrupts can be either edge or level triggered, and
157  * need to be initialized by the appropriate driver.
158  */
159 static void __init
160 m8260_init_IRQ(void)
161 {
162         int i;
163
164         for ( i = 0 ; i < NR_SIU_INTS ; i++ )
165                 irq_desc[i].handler = &cpm2_pic;
166
167         /* Initialize the default interrupt mapping priorities,
168          * in case the boot rom changed something on us.
169          */
170         cpm2_immr->im_intctl.ic_sicr = 0;
171         cpm2_immr->im_intctl.ic_siprr = 0x05309770;
172         cpm2_immr->im_intctl.ic_scprrh = 0x05309770;
173         cpm2_immr->im_intctl.ic_scprrl = 0x05309770;
174 }
175
176 /*
177  * Same hack as 8xx
178  */
179 static unsigned long __init
180 m8260_find_end_of_memory(void)
181 {
182         bd_t *binfo = (bd_t *)__res;
183
184         return binfo->bi_memsize;
185 }
186
187 /* Map the IMMR, plus anything else we can cover
188  * in that upper space according to the memory controller
189  * chip select mapping.  Grab another bunch of space
190  * below that for stuff we can't cover in the upper.
191  */
192 static void __init
193 m8260_map_io(void)
194 {
195         uint addr;
196
197         /* Map IMMR region to a 256MB BAT */
198         addr = (cpm2_immr != NULL) ? (uint)cpm2_immr : CPM_MAP_ADDR;
199         io_block_mapping(addr, addr, 0x10000000, _PAGE_IO);
200
201         /* Map I/O region to a 256MB BAT */
202         io_block_mapping(IO_VIRT_ADDR, IO_PHYS_ADDR, 0x10000000, _PAGE_IO);
203 }
204
205 /* Place-holder for board-specific init */
206 void __attribute__ ((weak)) __init
207 m82xx_board_init(void)
208 {
209 }
210
211 /* Inputs:
212  *   r3 - Optional pointer to a board information structure.
213  *   r4 - Optional pointer to the physical starting address of the init RAM
214  *        disk.
215  *   r5 - Optional pointer to the physical ending address of the init RAM
216  *        disk.
217  *   r6 - Optional pointer to the physical starting address of any kernel
218  *        command-line parameters.
219  *   r7 - Optional pointer to the physical ending address of any kernel
220  *        command-line parameters.
221  */
222 void __init
223 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
224               unsigned long r6, unsigned long r7)
225 {
226         parse_bootinfo(find_bootinfo());
227
228         if ( r3 )
229                 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
230
231 #ifdef CONFIG_BLK_DEV_INITRD
232         /* take care of initrd if we have one */
233         if ( r4 ) {
234                 initrd_start = r4 + KERNELBASE;
235                 initrd_end = r5 + KERNELBASE;
236         }
237 #endif /* CONFIG_BLK_DEV_INITRD */
238         /* take care of cmd line */
239         if ( r6 ) {
240                 *(char *)(r7+KERNELBASE) = 0;
241                 strcpy(cmd_line, (char *)(r6+KERNELBASE));
242         }
243
244         /* Call back for board-specific settings. */
245         m82xx_board_init();
246
247         ppc_md.setup_arch               = m8260_setup_arch;
248         ppc_md.show_cpuinfo             = m8260_show_cpuinfo;
249         ppc_md.init_IRQ                 = m8260_init_IRQ;
250         ppc_md.get_irq                  = cpm2_get_irq;
251
252         ppc_md.restart                  = m8260_restart;
253         ppc_md.power_off                = m8260_power_off;
254         ppc_md.halt                     = m8260_halt;
255
256         ppc_md.set_rtc_time             = m8260_set_rtc_time;
257         ppc_md.get_rtc_time             = m8260_get_rtc_time;
258         ppc_md.calibrate_decr           = m8260_calibrate_decr;
259
260         ppc_md.find_end_of_memory       = m8260_find_end_of_memory;
261         ppc_md.setup_io_mappings        = m8260_map_io;
262 }