1 /*
2 * linux/arch/ppc/kernel/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 /*
12 * bootup setup stuff..
13 */
14
15 #include <linux/config.h>
16 #include <linux/errno.h>
17 #include <linux/sched.h>
18 #include <linux/kernel.h>
19 #include <linux/mm.h>
20 #include <linux/stddef.h>
21 #include <linux/unistd.h>
22 #include <linux/ptrace.h>
23 #include <linux/slab.h>
24 #include <linux/user.h>
25 #include <linux/a.out.h>
26 #include <linux/tty.h>
27 #include <linux/major.h>
28 #include <linux/interrupt.h>
29 #include <linux/reboot.h>
30 #include <linux/init.h>
31 #include <linux/blk.h>
32 #include <linux/ioport.h>
33 #include <linux/ide.h>
34 #include <linux/seq_file.h>
35
36 #include <asm/mmu.h>
37 #include <asm/processor.h>
38 #include <asm/residual.h>
39 #include <asm/io.h>
40 #include <asm/pgtable.h>
41 #include <asm/ide.h>
42 #include <asm/mpc8260.h>
43 #include <asm/immap_cpm2.h>
44 #include <asm/machdep.h>
45 #include <asm/bootinfo.h>
46 #include <asm/time.h>
47
48 #include "cpm2_pic.h"
49
50 static int m8260_set_rtc_time(unsigned long time);
51 static unsigned long m8260_get_rtc_time(void);
52 static void m8260_calibrate_decr(void);
53
54 unsigned char __res[sizeof(bd_t)];
55
56 extern void cpm2_reset(void);
57
58 static void __init
m8260_setup_arch(void)59 m8260_setup_arch(void)
60 {
61 /* Reset the Communication Processor Module.
62 */
63 cpm2_reset();
64 }
65
66 static void
abort(void)67 abort(void)
68 {
69 #ifdef CONFIG_XMON
70 extern void xmon(void *);
71 xmon(0);
72 #endif
73 machine_restart(NULL);
74 }
75
76 /* The decrementer counts at the system (internal) clock frequency
77 * divided by four.
78 */
79 static void __init
m8260_calibrate_decr(void)80 m8260_calibrate_decr(void)
81 {
82 bd_t *binfo = (bd_t *)__res;
83 int freq, divisor;
84
85 freq = binfo->bi_busfreq;
86 divisor = 4;
87 tb_ticks_per_jiffy = freq / HZ / divisor;
88 tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
89 }
90
91 /* The 8260 has an internal 1-second timer update register that
92 * we should use for this purpose.
93 */
94 static uint rtc_time;
95
96 static int
m8260_set_rtc_time(unsigned long time)97 m8260_set_rtc_time(unsigned long time)
98 {
99 rtc_time = time;
100 return(0);
101 }
102
103 static unsigned long
m8260_get_rtc_time(void)104 m8260_get_rtc_time(void)
105 {
106
107 /* Get time from the RTC.
108 */
109 return((unsigned long)rtc_time);
110 }
111
112 static void
m8260_restart(char * cmd)113 m8260_restart(char *cmd)
114 {
115 extern void m8260_gorom(bd_t *bi, uint addr);
116 uint startaddr;
117
118 /* Most boot roms have a warmstart as the second instruction
119 * of the reset vector. If that doesn't work for you, change this
120 * or the reboot program to send a proper address.
121 */
122 startaddr = 0xff000104;
123
124 if (cmd != NULL) {
125 if (!strncmp(cmd, "startaddr=", 10))
126 startaddr = simple_strtoul(&cmd[10], NULL, 0);
127 }
128
129 m8260_gorom((unsigned int)__pa(__res), startaddr);
130 }
131
132 static void
m8260_power_off(void)133 m8260_power_off(void)
134 {
135 m8260_restart(NULL);
136 }
137
138 static void
m8260_halt(void)139 m8260_halt(void)
140 {
141 m8260_restart(NULL);
142 }
143
144
145 static int
m8260_show_percpuinfo(struct seq_file * m,int i)146 m8260_show_percpuinfo(struct seq_file *m, int i)
147 {
148 bd_t *bp;
149
150 bp = (bd_t *)__res;
151
152 seq_printf(m, "core clock\t: %d MHz\n"
153 "CPM clock\t: %d MHz\n"
154 "bus clock\t: %d MHz\n",
155 bp->bi_intfreq / 1000000,
156 bp->bi_cpmfreq / 1000000,
157 bp->bi_busfreq / 1000000);
158
159 return 0;
160 }
161
162 /* Initialize the internal interrupt controller. The number of
163 * interrupts supported can vary with the processor type, and the
164 * 8260 family can have up to 64.
165 * External interrupts can be either edge or level triggered, and
166 * need to be initialized by the appropriate driver.
167 */
168 static void __init
m8260_init_IRQ(void)169 m8260_init_IRQ(void)
170 {
171 int i;
172 void cpm_interrupt_init(void);
173
174 #if 0
175 cpm2_pic.irq_offset = 0;
176 #endif
177 for ( i = 0 ; i < NR_SIU_INTS ; i++ )
178 irq_desc[i].handler = &cpm2_pic;
179
180 /* Initialize the default interrupt mapping priorities,
181 * in case the boot rom changed something on us.
182 */
183 cpm2_immr->im_intctl.ic_sicr = 0;
184 cpm2_immr->im_intctl.ic_siprr = 0x05309770;
185 cpm2_immr->im_intctl.ic_scprrh = 0x05309770;
186 cpm2_immr->im_intctl.ic_scprrl = 0x05309770;
187
188 }
189
190 /*
191 * Same hack as 8xx
192 */
193 static unsigned long __init
m8260_find_end_of_memory(void)194 m8260_find_end_of_memory(void)
195 {
196 bd_t *binfo;
197 extern unsigned char __res[];
198
199 binfo = (bd_t *)__res;
200
201 return binfo->bi_memsize;
202 }
203
204 /* Map the IMMR, plus anything else we can cover
205 * in that upper space according to the memory controller
206 * chip select mapping. Grab another bunch of space
207 * below that for stuff we can't cover in the upper.
208 */
209 static void __init
m8260_map_io(void)210 m8260_map_io(void)
211 {
212 io_block_mapping(0xf0000000, 0xf0000000, 0x10000000, _PAGE_IO);
213 io_block_mapping(0xe0000000, 0xe0000000, 0x10000000, _PAGE_IO);
214 }
215
216 void __init
platform_init(unsigned long r3,unsigned long r4,unsigned long r5,unsigned long r6,unsigned long r7)217 platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
218 unsigned long r6, unsigned long r7)
219 {
220 parse_bootinfo(find_bootinfo());
221
222 if ( r3 )
223 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
224
225 #ifdef CONFIG_BLK_DEV_INITRD
226 /* take care of initrd if we have one */
227 if ( r4 )
228 {
229 initrd_start = r4 + KERNELBASE;
230 initrd_end = r5 + KERNELBASE;
231 }
232 #endif /* CONFIG_BLK_DEV_INITRD */
233 /* take care of cmd line */
234 if ( r6 )
235 {
236
237 *(char *)(r7+KERNELBASE) = 0;
238 strcpy(cmd_line, (char *)(r6+KERNELBASE));
239 }
240
241 ppc_md.setup_arch = m8260_setup_arch;
242 ppc_md.show_percpuinfo = m8260_show_percpuinfo;
243 ppc_md.irq_cannonicalize = NULL;
244 ppc_md.init_IRQ = m8260_init_IRQ;
245 ppc_md.get_irq = cpm2_get_irq;
246 ppc_md.init = NULL;
247
248 ppc_md.restart = m8260_restart;
249 ppc_md.power_off = m8260_power_off;
250 ppc_md.halt = m8260_halt;
251
252 ppc_md.time_init = NULL;
253 ppc_md.set_rtc_time = m8260_set_rtc_time;
254 ppc_md.get_rtc_time = m8260_get_rtc_time;
255 ppc_md.calibrate_decr = m8260_calibrate_decr;
256
257 ppc_md.find_end_of_memory = m8260_find_end_of_memory;
258 ppc_md.setup_io_mappings = m8260_map_io;
259
260 ppc_md.kbd_setkeycode = NULL;
261 ppc_md.kbd_getkeycode = NULL;
262 ppc_md.kbd_translate = NULL;
263 ppc_md.kbd_unexpected_up = NULL;
264 ppc_md.kbd_leds = NULL;
265 ppc_md.kbd_init_hw = NULL;
266 ppc_md.ppc_kbd_sysrq_xlate = NULL;
267 }
268
269