blob: 1cc3abe6fa435657b7969024acd52278cedc482f [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * 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 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/initrd.h>
32#include <linux/ioport.h>
33#include <linux/bootmem.h>
34#include <linux/seq_file.h>
35#include <linux/root_dev.h>
36
37#include <asm/mmu.h>
38#include <asm/reg.h>
39#include <asm/residual.h>
40#include <asm/io.h>
41#include <asm/pgtable.h>
42#include <asm/mpc8xx.h>
43#include <asm/8xx_immap.h>
44#include <asm/machdep.h>
45#include <asm/bootinfo.h>
46#include <asm/time.h>
47#include <asm/xmon.h>
Vitaly Bordug457e04c2005-11-02 22:55:14 +030048#include <asm/ppc_sys.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50#include "ppc8xx_pic.h"
51
52static int m8xx_set_rtc_time(unsigned long time);
53static unsigned long m8xx_get_rtc_time(void);
54void m8xx_calibrate_decr(void);
55
56unsigned char __res[sizeof(bd_t)];
57
58extern void m8xx_ide_init(void);
59
60extern unsigned long find_available_memory(void);
Marcelo Tosatti62c592edea2005-08-30 13:40:22 -030061extern void m8xx_cpm_reset(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070062extern void m8xx_wdt_handler_install(bd_t *bp);
63extern void rpxfb_alloc_pages(void);
64extern void cpm_interrupt_init(void);
65
66void __attribute__ ((weak))
67board_init(void)
68{
69}
70
71void __init
72m8xx_setup_arch(void)
73{
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 /* Reset the Communication Processor Module.
75 */
Marcelo Tosatti079da352005-08-07 09:42:47 -070076 m8xx_cpm_reset();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78#ifdef CONFIG_FB_RPX
79 rpxfb_alloc_pages();
80#endif
81
82#ifdef notdef
83 ROOT_DEV = Root_HDA1; /* hda1 */
84#endif
85
86#ifdef CONFIG_BLK_DEV_INITRD
87#if 0
88 ROOT_DEV = Root_FD0; /* floppy */
89 rd_prompt = 1;
90 rd_doload = 1;
91 rd_image_start = 0;
92#endif
93#if 0 /* XXX this may need to be updated for the new bootmem stuff,
94 or possibly just deleted (see set_phys_avail() in init.c).
95 - paulus. */
96 /* initrd_start and size are setup by boot/head.S and kernel/head.S */
97 if ( initrd_start )
98 {
99 if (initrd_end > *memory_end_p)
100 {
101 printk("initrd extends beyond end of memory "
102 "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
103 initrd_end,*memory_end_p);
104 initrd_start = 0;
105 }
106 }
107#endif
108#endif
109 board_init();
110}
111
112void
113abort(void)
114{
115#ifdef CONFIG_XMON
116 xmon(0);
117#endif
118 machine_restart(NULL);
119
120 /* not reached */
121 for (;;);
122}
123
124/* A place holder for time base interrupts, if they are ever enabled. */
125irqreturn_t timebase_interrupt(int irq, void * dev, struct pt_regs * regs)
126{
127 printk ("timebase_interrupt()\n");
128
129 return IRQ_HANDLED;
130}
131
132static struct irqaction tbint_irqaction = {
133 .handler = timebase_interrupt,
134 .mask = CPU_MASK_NONE,
135 .name = "tbint",
136};
137
138/* The decrementer counts at the system (internal) clock frequency divided by
139 * sixteen, or external oscillator divided by four. We force the processor
140 * to use system clock divided by sixteen.
141 */
142void __init m8xx_calibrate_decr(void)
143{
144 bd_t *binfo = (bd_t *)__res;
145 int freq, fp, divisor;
146
147 /* Unlock the SCCR. */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700148 out_be32(&((immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk, ~KAPWR_KEY);
149 out_be32(&((immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk, KAPWR_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
151 /* Force all 8xx processors to use divide by 16 processor clock. */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700152 out_be32(&((immap_t *)IMAP_ADDR)->im_clkrst.car_sccr,
153 in_be32(&((immap_t *)IMAP_ADDR)->im_clkrst.car_sccr)|0x02000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 /* Processor frequency is MHz.
155 * The value 'fp' is the number of decrementer ticks per second.
156 */
157 fp = binfo->bi_intfreq / 16;
158 freq = fp*60; /* try to make freq/1e6 an integer */
159 divisor = 60;
160 printk("Decrementer Frequency = %d/%d\n", freq, divisor);
161 tb_ticks_per_jiffy = freq / HZ / divisor;
162 tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);
163
164 /* Perform some more timer/timebase initialization. This used
165 * to be done elsewhere, but other changes caused it to get
166 * called more than once....that is a bad thing.
167 *
168 * First, unlock all of the registers we are going to modify.
169 * To protect them from corruption during power down, registers
170 * that are maintained by keep alive power are "locked". To
171 * modify these registers we have to write the key value to
172 * the key location associated with the register.
173 * Some boards power up with these unlocked, while others
174 * are locked. Writing anything (including the unlock code?)
175 * to the unlocked registers will lock them again. So, here
176 * we guarantee the registers are locked, then we unlock them
177 * for our use.
178 */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700179 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk, ~KAPWR_KEY);
180 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck, ~KAPWR_KEY);
181 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk, ~KAPWR_KEY);
182 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk, KAPWR_KEY);
183 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck, KAPWR_KEY);
184 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk, KAPWR_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185
186 /* Disable the RTC one second and alarm interrupts. */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700187 out_be16(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc, in_be16(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc) & ~(RTCSC_SIE | RTCSC_ALE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 /* Enable the RTC */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700189 out_be16(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc, in_be16(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc) | (RTCSC_RTF | RTCSC_RTE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190
191 /* Enabling the decrementer also enables the timebase interrupts
192 * (or from the other point of view, to get decrementer interrupts
193 * we have to enable the timebase). The decrementer interrupt
194 * is wired into the vector table, nothing to do here for that.
195 */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700196 out_be16(&((immap_t *)IMAP_ADDR)->im_sit.sit_tbscr, (mk_int_int_mask(DEC_INTERRUPT) << 8) | (TBSCR_TBF | TBSCR_TBE));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198 if (setup_irq(DEC_INTERRUPT, &tbint_irqaction))
199 panic("Could not allocate timer IRQ!");
200
201#ifdef CONFIG_8xx_WDT
202 /* Install watchdog timer handler early because it might be
203 * already enabled by the bootloader
204 */
205 m8xx_wdt_handler_install(binfo);
206#endif
207}
208
209/* The RTC on the MPC8xx is an internal register.
210 * We want to protect this during power down, so we need to unlock,
211 * modify, and re-lock.
212 */
213static int
214m8xx_set_rtc_time(unsigned long time)
215{
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700216 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck, KAPWR_KEY);
217 out_be32(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtc, time);
218 out_be32(&((immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck, ~KAPWR_KEY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 return(0);
220}
221
222static unsigned long
223m8xx_get_rtc_time(void)
224{
225 /* Get time from the RTC. */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700226 return (unsigned long) in_be32(&((immap_t *)IMAP_ADDR)->im_sit.sit_rtc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
229static void
230m8xx_restart(char *cmd)
231{
232 __volatile__ unsigned char dummy;
233
234 local_irq_disable();
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700235 out_be32(&((immap_t *)IMAP_ADDR)->im_clkrst.car_plprcr, in_be32(&((immap_t *)IMAP_ADDR)->im_clkrst.car_plprcr) | 0x00000080);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
237 /* Clear the ME bit in MSR to cause checkstop on machine check
238 */
239 mtmsr(mfmsr() & ~0x1000);
240
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700241 dummy = in_8(&((immap_t *)IMAP_ADDR)->im_clkrst.res[0]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 printk("Restart failed\n");
243 while(1);
244}
245
246static void
247m8xx_power_off(void)
248{
249 m8xx_restart(NULL);
250}
251
252static void
253m8xx_halt(void)
254{
255 m8xx_restart(NULL);
256}
257
258
259static int
260m8xx_show_percpuinfo(struct seq_file *m, int i)
261{
262 bd_t *bp;
263
264 bp = (bd_t *)__res;
265
Marcelo Tosatti62c592edea2005-08-30 13:40:22 -0300266 seq_printf(m, "clock\t\t: %uMHz\n"
267 "bus clock\t: %uMHz\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 bp->bi_intfreq / 1000000,
269 bp->bi_busfreq / 1000000);
270
271 return 0;
272}
273
274#ifdef CONFIG_PCI
275static struct irqaction mbx_i8259_irqaction = {
276 .handler = mbx_i8259_action,
277 .mask = CPU_MASK_NONE,
278 .name = "i8259 cascade",
279};
280#endif
281
282/* Initialize the internal interrupt controller. The number of
283 * interrupts supported can vary with the processor type, and the
284 * 82xx family can have up to 64.
285 * External interrupts can be either edge or level triggered, and
286 * need to be initialized by the appropriate driver.
287 */
288static void __init
289m8xx_init_IRQ(void)
290{
291 int i;
292
293 for (i = SIU_IRQ_OFFSET ; i < SIU_IRQ_OFFSET + NR_SIU_INTS ; i++)
294 irq_desc[i].handler = &ppc8xx_pic;
295
296 cpm_interrupt_init();
297
298#if defined(CONFIG_PCI)
299 for (i = I8259_IRQ_OFFSET ; i < I8259_IRQ_OFFSET + NR_8259_INTS ; i++)
300 irq_desc[i].handler = &i8259_pic;
301
302 i8259_pic_irq_offset = I8259_IRQ_OFFSET;
303 i8259_init(0);
304
305 /* The i8259 cascade interrupt must be level sensitive. */
Marcelo Tosattie37b0c92005-10-28 17:46:10 -0700306 out_be32(&((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel, in_be32(&((immap_t *)IMAP_ADDR)->im_siu_conf.sc_siel & ~(0x80000000 >> ISA_BRIDGE_INT)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
308 if (setup_irq(ISA_BRIDGE_INT, &mbx_i8259_irqaction))
309 enable_irq(ISA_BRIDGE_INT);
310#endif /* CONFIG_PCI */
311}
312
313/* -------------------------------------------------------------------- */
314
315/*
316 * This is a big hack right now, but it may turn into something real
317 * someday.
318 *
319 * For the 8xx boards (at this time anyway), there is nothing to initialize
320 * associated the PROM. Rather than include all of the prom.c
321 * functions in the image just to get prom_init, all we really need right
322 * now is the initialization of the physical memory region.
323 */
324static unsigned long __init
325m8xx_find_end_of_memory(void)
326{
327 bd_t *binfo;
328 extern unsigned char __res[];
329
330 binfo = (bd_t *)__res;
331
332 return binfo->bi_memsize;
333}
334
335/*
336 * Now map in some of the I/O space that is generically needed
337 * or shared with multiple devices.
338 * All of this fits into the same 4Mbyte region, so it only
339 * requires one page table page. (or at least it used to -- paulus)
340 */
341static void __init
342m8xx_map_io(void)
343{
344 io_block_mapping(IMAP_ADDR, IMAP_ADDR, IMAP_SIZE, _PAGE_IO);
345#ifdef CONFIG_MBX
346 io_block_mapping(NVRAM_ADDR, NVRAM_ADDR, NVRAM_SIZE, _PAGE_IO);
347 io_block_mapping(MBX_CSR_ADDR, MBX_CSR_ADDR, MBX_CSR_SIZE, _PAGE_IO);
348 io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
349
350 /* Map some of the PCI/ISA I/O space to get the IDE interface.
351 */
352 io_block_mapping(PCI_ISA_IO_ADDR, PCI_ISA_IO_ADDR, 0x4000, _PAGE_IO);
353 io_block_mapping(PCI_IDE_ADDR, PCI_IDE_ADDR, 0x4000, _PAGE_IO);
354#endif
355#if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
356 io_block_mapping(RPX_CSR_ADDR, RPX_CSR_ADDR, RPX_CSR_SIZE, _PAGE_IO);
357#if !defined(CONFIG_PCI)
358 io_block_mapping(_IO_BASE,_IO_BASE,_IO_BASE_SIZE, _PAGE_IO);
359#endif
360#endif
361#if defined(CONFIG_HTDMSOUND) || defined(CONFIG_RPXTOUCH) || defined(CONFIG_FB_RPX)
362 io_block_mapping(HIOX_CSR_ADDR, HIOX_CSR_ADDR, HIOX_CSR_SIZE, _PAGE_IO);
363#endif
364#ifdef CONFIG_FADS
365 io_block_mapping(BCSR_ADDR, BCSR_ADDR, BCSR_SIZE, _PAGE_IO);
366#endif
367#ifdef CONFIG_PCI
368 io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
369#endif
370#if defined(CONFIG_NETTA)
371 io_block_mapping(_IO_BASE,_IO_BASE,_IO_BASE_SIZE, _PAGE_IO);
372#endif
373}
374
375void __init
376platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
377 unsigned long r6, unsigned long r7)
378{
379 parse_bootinfo(find_bootinfo());
380
381 if ( r3 )
382 memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
383
384#ifdef CONFIG_PCI
385 m8xx_setup_pci_ptrs();
386#endif
387
388#ifdef CONFIG_BLK_DEV_INITRD
389 /* take care of initrd if we have one */
390 if ( r4 )
391 {
392 initrd_start = r4 + KERNELBASE;
393 initrd_end = r5 + KERNELBASE;
394 }
395#endif /* CONFIG_BLK_DEV_INITRD */
396 /* take care of cmd line */
397 if ( r6 )
398 {
399 *(char *)(r7+KERNELBASE) = 0;
400 strcpy(cmd_line, (char *)(r6+KERNELBASE));
401 }
402
Vitaly Bordug1461b4e2005-10-28 17:46:28 -0700403 identify_ppc_sys_by_name(BOARD_CHIP_NAME);
404
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 ppc_md.setup_arch = m8xx_setup_arch;
406 ppc_md.show_percpuinfo = m8xx_show_percpuinfo;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 ppc_md.init_IRQ = m8xx_init_IRQ;
408 ppc_md.get_irq = m8xx_get_irq;
409 ppc_md.init = NULL;
410
411 ppc_md.restart = m8xx_restart;
412 ppc_md.power_off = m8xx_power_off;
413 ppc_md.halt = m8xx_halt;
414
415 ppc_md.time_init = NULL;
416 ppc_md.set_rtc_time = m8xx_set_rtc_time;
417 ppc_md.get_rtc_time = m8xx_get_rtc_time;
418 ppc_md.calibrate_decr = m8xx_calibrate_decr;
419
420 ppc_md.find_end_of_memory = m8xx_find_end_of_memory;
421 ppc_md.setup_io_mappings = m8xx_map_io;
422
Marcelo Tosatti566ecb92005-08-23 17:20:44 -0300423#if defined(CONFIG_BLK_DEV_MPC8xx_IDE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 m8xx_ide_init();
425#endif
426}