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