m8xx_setup.c 10.8 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1
/*
2
 *  arch/ppc/kernel/setup.c
Linus Torvalds's avatar
Linus Torvalds committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
 *
 *  Copyright (C) 1995  Linus Torvalds
 *  Adapted from 'alpha' version by Gary Thomas
 *  Modified by Cort Dougan (cort@cs.nmt.edu)
 *  Modified for MBX using prep/chrp/pmac functions by Dan (dmalek@jlc.net)
 *  Further modified for generic 8xx by Dan.
 */

/*
 * bootup setup stuff..
 */

#include <linux/config.h>
#include <linux/errno.h>
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/stddef.h>
#include <linux/unistd.h>
#include <linux/ptrace.h>
Linus Torvalds's avatar
Linus Torvalds committed
23
#include <linux/slab.h>
Linus Torvalds's avatar
Linus Torvalds committed
24 25 26 27 28 29 30 31 32 33
#include <linux/user.h>
#include <linux/a.out.h>
#include <linux/tty.h>
#include <linux/major.h>
#include <linux/interrupt.h>
#include <linux/reboot.h>
#include <linux/init.h>
#include <linux/blk.h>
#include <linux/ioport.h>
#include <linux/bootmem.h>
Linus Torvalds's avatar
Linus Torvalds committed
34
#include <linux/seq_file.h>
Alexander Viro's avatar
Alexander Viro committed
35
#include <linux/root_dev.h>
Linus Torvalds's avatar
Linus Torvalds committed
36 37 38 39 40 41

#include <asm/mmu.h>
#include <asm/processor.h>
#include <asm/residual.h>
#include <asm/io.h>
#include <asm/pgtable.h>
Linus Torvalds's avatar
Linus Torvalds committed
42
#include <asm/mpc8xx.h>
Linus Torvalds's avatar
Linus Torvalds committed
43 44
#include <asm/8xx_immap.h>
#include <asm/machdep.h>
45
#include <asm/bootinfo.h>
Linus Torvalds's avatar
Linus Torvalds committed
46
#include <asm/time.h>
47

Linus Torvalds's avatar
Linus Torvalds committed
48 49 50
#include "ppc8xx_pic.h"

static int m8xx_set_rtc_time(unsigned long time);
Linus Torvalds's avatar
Linus Torvalds committed
51
static unsigned long m8xx_get_rtc_time(void);
Linus Torvalds's avatar
Linus Torvalds committed
52 53 54
void m8xx_calibrate_decr(void);

unsigned char __res[sizeof(bd_t)];
Linus Torvalds's avatar
Linus Torvalds committed
55

Linus Torvalds's avatar
Linus Torvalds committed
56
extern void m8xx_ide_init(void);
Linus Torvalds's avatar
Linus Torvalds committed
57 58 59

extern unsigned long find_available_memory(void);
extern void m8xx_cpm_reset(uint);
60
extern void rpxfb_alloc_pages(void);
Linus Torvalds's avatar
Linus Torvalds committed
61 62 63 64 65

void __init
m8xx_setup_arch(void)
{
	int	cpm_page;
66

Linus Torvalds's avatar
Linus Torvalds committed
67
	cpm_page = (int) alloc_bootmem_pages(PAGE_SIZE);
68

Linus Torvalds's avatar
Linus Torvalds committed
69 70 71 72
	/* Reset the Communication Processor Module.
	*/
	m8xx_cpm_reset(cpm_page);

73 74 75 76
#ifdef CONFIG_FB_RPX
	rpxfb_alloc_pages();
#endif

Linus Torvalds's avatar
Linus Torvalds committed
77
#ifdef notdef
Alexander Viro's avatar
Alexander Viro committed
78
	ROOT_DEV = Root_HDA1; /* hda1 */
Linus Torvalds's avatar
Linus Torvalds committed
79
#endif
80

Linus Torvalds's avatar
Linus Torvalds committed
81 82
#ifdef CONFIG_BLK_DEV_INITRD
#if 0
Alexander Viro's avatar
Alexander Viro committed
83
	ROOT_DEV = Root_FD0; /* floppy */
Linus Torvalds's avatar
Linus Torvalds committed
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
	rd_prompt = 1;
	rd_doload = 1;
	rd_image_start = 0;
#endif
#if 0	/* XXX this may need to be updated for the new bootmem stuff,
	   or possibly just deleted (see set_phys_avail() in init.c).
	   - paulus. */
	/* initrd_start and size are setup by boot/head.S and kernel/head.S */
	if ( initrd_start )
	{
		if (initrd_end > *memory_end_p)
		{
			printk("initrd extends beyond end of memory "
			       "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
			       initrd_end,*memory_end_p);
			initrd_start = 0;
		}
	}
#endif
#endif
}

void
abort(void)
{
#ifdef CONFIG_XMON
	xmon(0);
#endif
	machine_restart(NULL);
113 114 115

	/* not reached */
	for (;;);
Linus Torvalds's avatar
Linus Torvalds committed
116 117
}

Linus Torvalds's avatar
Linus Torvalds committed
118
/* A place holder for time base interrupts, if they are ever enabled. */
Linus Torvalds's avatar
Linus Torvalds committed
119 120
void timebase_interrupt(int irq, void * dev, struct pt_regs * regs)
{
Linus Torvalds's avatar
Linus Torvalds committed
121
	printk ("timebase_interrupt()\n");
Linus Torvalds's avatar
Linus Torvalds committed
122 123 124 125 126 127 128 129 130 131 132
}

/* The decrementer counts at the system (internal) clock frequency divided by
 * sixteen, or external oscillator divided by four.  We force the processor
 * to use system clock divided by sixteen.
 */
void __init m8xx_calibrate_decr(void)
{
	bd_t	*binfo = (bd_t *)__res;
	int freq, fp, divisor;

Linus Torvalds's avatar
Linus Torvalds committed
133
	/* Unlock the SCCR. */
Linus Torvalds's avatar
Linus Torvalds committed
134 135 136
	((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = ~KAPWR_KEY;
	((volatile immap_t *)IMAP_ADDR)->im_clkrstk.cark_sccrk = KAPWR_KEY;

Linus Torvalds's avatar
Linus Torvalds committed
137
	/* Force all 8xx processors to use divide by 16 processor clock. */
Linus Torvalds's avatar
Linus Torvalds committed
138 139 140 141 142
	((volatile immap_t *)IMAP_ADDR)->im_clkrst.car_sccr |= 0x02000000;

	/* Processor frequency is MHz.
	 * The value 'fp' is the number of decrementer ticks per second.
	 */
Linus Torvalds's avatar
Linus Torvalds committed
143
	fp = binfo->bi_intfreq / 16;
Linus Torvalds's avatar
Linus Torvalds committed
144 145
	freq = fp*60;	/* try to make freq/1e6 an integer */
        divisor = 60;
Linus Torvalds's avatar
Linus Torvalds committed
146
        printk("Decrementer Frequency = %d/%d\n", freq, divisor);
Linus Torvalds's avatar
Linus Torvalds committed
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166
        tb_ticks_per_jiffy = freq / HZ / divisor;
	tb_to_us = mulhwu_scale_factor(freq / divisor, 1000000);

	/* Perform some more timer/timebase initialization.  This used
	 * to be done elsewhere, but other changes caused it to get
	 * called more than once....that is a bad thing.
	 *
	 * First, unlock all of the registers we are going to modify.
	 * To protect them from corruption during power down, registers
	 * that are maintained by keep alive power are "locked".  To
	 * modify these registers we have to write the key value to
	 * the key location associated with the register.
	 * Some boards power up with these unlocked, while others
	 * are locked.  Writing anything (including the unlock code?)
	 * to the unlocked registers will lock them again.  So, here
	 * we guarantee the registers are locked, then we unlock them
	 * for our use.
	 */
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk = ~KAPWR_KEY;
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck = ~KAPWR_KEY;
Linus Torvalds's avatar
Linus Torvalds committed
167
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk    = ~KAPWR_KEY;
Linus Torvalds's avatar
Linus Torvalds committed
168 169 170
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbscrk =  KAPWR_KEY;
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtcsck =  KAPWR_KEY;
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_tbk    =  KAPWR_KEY;
Linus Torvalds's avatar
Linus Torvalds committed
171

Linus Torvalds's avatar
Linus Torvalds committed
172
	/* Disable the RTC one second and alarm interrupts. */
Linus Torvalds's avatar
Linus Torvalds committed
173 174
	((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc &=
						~(RTCSC_SIE | RTCSC_ALE);
Linus Torvalds's avatar
Linus Torvalds committed
175 176 177
	/* Enable the RTC */
	((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtcsc |=
						(RTCSC_RTF | RTCSC_RTE);
Linus Torvalds's avatar
Linus Torvalds committed
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204

	/* Enabling the decrementer also enables the timebase interrupts
	 * (or from the other point of view, to get decrementer interrupts
	 * we have to enable the timebase).  The decrementer interrupt
	 * is wired into the vector table, nothing to do here for that.
	 */
	((volatile immap_t *)IMAP_ADDR)->im_sit.sit_tbscr =
				((mk_int_int_mask(DEC_INTERRUPT) << 8) |
					 (TBSCR_TBF | TBSCR_TBE));

	if (request_8xxirq(DEC_INTERRUPT, timebase_interrupt, 0, "tbint", NULL) != 0)
		panic("Could not allocate timer IRQ!");
}

/* The RTC on the MPC8xx is an internal register.
 * We want to protect this during power down, so we need to unlock,
 * modify, and re-lock.
 */
static int
m8xx_set_rtc_time(unsigned long time)
{
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = KAPWR_KEY;
	((volatile immap_t *)IMAP_ADDR)->im_sit.sit_rtc = time;
	((volatile immap_t *)IMAP_ADDR)->im_sitk.sitk_rtck = ~KAPWR_KEY;
	return(0);
}

Linus Torvalds's avatar
Linus Torvalds committed
205
static unsigned long
Linus Torvalds's avatar
Linus Torvalds committed
206 207
m8xx_get_rtc_time(void)
{
Linus Torvalds's avatar
Linus Torvalds committed
208
	/* Get time from the RTC. */
Linus Torvalds's avatar
Linus Torvalds committed
209 210 211
	return((unsigned long)(((immap_t *)IMAP_ADDR)->im_sit.sit_rtc));
}

Linus Torvalds's avatar
Linus Torvalds committed
212
static void
Linus Torvalds's avatar
Linus Torvalds committed
213 214
m8xx_restart(char *cmd)
{
Linus Torvalds's avatar
Linus Torvalds committed
215 216
	__volatile__ unsigned char dummy;
	uint	msr;
Linus Torvalds's avatar
Linus Torvalds committed
217

Linus Torvalds's avatar
Linus Torvalds committed
218 219 220 221 222 223 224 225 226 227
	cli();
	((immap_t *)IMAP_ADDR)->im_clkrst.car_plprcr |= 0x00000080;

	/* Clear the ME bit in MSR to cause checkstop on machine check
	*/
	__asm__("mfmsr %0" : "=r" (msr) );
	msr &= ~0x1000;
	__asm__("mtmsr %0" : : "r" (msr) );

	dummy = ((immap_t *)IMAP_ADDR)->im_clkrst.res[0];
228
	printk("Restart failed\n");
Linus Torvalds's avatar
Linus Torvalds committed
229
	while(1);
Linus Torvalds's avatar
Linus Torvalds committed
230 231
}

Linus Torvalds's avatar
Linus Torvalds committed
232
static void
Linus Torvalds's avatar
Linus Torvalds committed
233 234 235 236 237
m8xx_power_off(void)
{
   m8xx_restart(NULL);
}

Linus Torvalds's avatar
Linus Torvalds committed
238
static void
Linus Torvalds's avatar
Linus Torvalds committed
239 240 241 242 243 244
m8xx_halt(void)
{
   m8xx_restart(NULL);
}


Linus Torvalds's avatar
Linus Torvalds committed
245
static int
Linus Torvalds's avatar
Linus Torvalds committed
246
m8xx_show_percpuinfo(struct seq_file *m, int i)
Linus Torvalds's avatar
Linus Torvalds committed
247 248 249 250
{
	bd_t	*bp;

	bp = (bd_t *)__res;
251 252 253

	seq_printf(m, "clock\t\t: %dMHz\n"
		   "bus clock\t: %dMHz\n",
Linus Torvalds's avatar
Linus Torvalds committed
254 255
		   bp->bi_intfreq / 1000000,
		   bp->bi_busfreq / 1000000);
Linus Torvalds's avatar
Linus Torvalds committed
256

Linus Torvalds's avatar
Linus Torvalds committed
257
	return 0;
Linus Torvalds's avatar
Linus Torvalds committed
258 259 260 261 262 263 264 265
}

/* Initialize the internal interrupt controller.  The number of
 * interrupts supported can vary with the processor type, and the
 * 82xx family can have up to 64.
 * External interrupts can be either edge or level triggered, and
 * need to be initialized by the appropriate driver.
 */
Linus Torvalds's avatar
Linus Torvalds committed
266
static void __init
Linus Torvalds's avatar
Linus Torvalds committed
267 268 269 270 271 272 273
m8xx_init_IRQ(void)
{
	int i;
	void cpm_interrupt_init(void);

        for ( i = 0 ; i < NR_SIU_INTS ; i++ )
                irq_desc[i].handler = &ppc8xx_pic;
274

Linus Torvalds's avatar
Linus Torvalds committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
	/* We could probably incorporate the CPM into the multilevel
	 * interrupt structure.
	 */
	cpm_interrupt_init();
        unmask_irq(CPM_INTERRUPT);

#if defined(CONFIG_PCI)
        for ( i = NR_SIU_INTS ; i < (NR_SIU_INTS + NR_8259_INTS) ; i++ )
                irq_desc[i].handler = &i8259_pic;
        i8259_pic.irq_offset = NR_SIU_INTS;
        i8259_init();
        request_8xxirq(ISA_BRIDGE_INT, mbx_i8259_action, 0, "8259 cascade", NULL);
        enable_irq(ISA_BRIDGE_INT);
#endif
}

Linus Torvalds's avatar
Linus Torvalds committed
291 292
/* -------------------------------------------------------------------- */

Linus Torvalds's avatar
Linus Torvalds committed
293 294 295 296 297 298 299 300 301
/*
 * This is a big hack right now, but it may turn into something real
 * someday.
 *
 * For the 8xx boards (at this time anyway), there is nothing to initialize
 * associated the PROM.  Rather than include all of the prom.c
 * functions in the image just to get prom_init, all we really need right
 * now is the initialization of the physical memory region.
 */
Linus Torvalds's avatar
Linus Torvalds committed
302 303
static unsigned long __init
m8xx_find_end_of_memory(void)
Linus Torvalds's avatar
Linus Torvalds committed
304 305 306
{
	bd_t	*binfo;
	extern unsigned char __res[];
307

Linus Torvalds's avatar
Linus Torvalds committed
308 309 310 311 312
	binfo = (bd_t *)__res;

	return binfo->bi_memsize;
}

Linus Torvalds's avatar
Linus Torvalds committed
313 314 315 316 317 318
/*
 * Now map in some of the I/O space that is generically needed
 * or shared with multiple devices.
 * All of this fits into the same 4Mbyte region, so it only
 * requires one page table page.  (or at least it used to  -- paulus)
 */
Linus Torvalds's avatar
Linus Torvalds committed
319 320
static void __init
m8xx_map_io(void)
Linus Torvalds's avatar
Linus Torvalds committed
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
{
        io_block_mapping(IMAP_ADDR, IMAP_ADDR, IMAP_SIZE, _PAGE_IO);
#ifdef CONFIG_MBX
        io_block_mapping(NVRAM_ADDR, NVRAM_ADDR, NVRAM_SIZE, _PAGE_IO);
        io_block_mapping(MBX_CSR_ADDR, MBX_CSR_ADDR, MBX_CSR_SIZE, _PAGE_IO);
        io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);

	/* Map some of the PCI/ISA I/O space to get the IDE interface.
	*/
        io_block_mapping(PCI_ISA_IO_ADDR, PCI_ISA_IO_ADDR, 0x4000, _PAGE_IO);
        io_block_mapping(PCI_IDE_ADDR, PCI_IDE_ADDR, 0x4000, _PAGE_IO);
#endif
#if defined(CONFIG_RPXLITE) || defined(CONFIG_RPXCLASSIC)
	io_block_mapping(RPX_CSR_ADDR, RPX_CSR_ADDR, RPX_CSR_SIZE, _PAGE_IO);
#if !defined(CONFIG_PCI)
	io_block_mapping(_IO_BASE,_IO_BASE,_IO_BASE_SIZE, _PAGE_IO);
#endif
#endif
#ifdef CONFIG_HTDMSOUND
	io_block_mapping(HIOX_CSR_ADDR, HIOX_CSR_ADDR, HIOX_CSR_SIZE, _PAGE_IO);
#endif
#ifdef CONFIG_FADS
	io_block_mapping(BCSR_ADDR, BCSR_ADDR, BCSR_SIZE, _PAGE_IO);
#endif
#ifdef CONFIG_PCI
        io_block_mapping(PCI_CSR_ADDR, PCI_CSR_ADDR, PCI_CSR_SIZE, _PAGE_IO);
#endif
}

Linus Torvalds's avatar
Linus Torvalds committed
350
void __init
Linus Torvalds's avatar
Linus Torvalds committed
351
platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
Linus Torvalds's avatar
Linus Torvalds committed
352
		unsigned long r6, unsigned long r7)
Linus Torvalds's avatar
Linus Torvalds committed
353
{
354 355
	parse_bootinfo(find_bootinfo());

Linus Torvalds's avatar
Linus Torvalds committed
356 357
	if ( r3 )
		memcpy( (void *)__res,(void *)(r3+KERNELBASE), sizeof(bd_t) );
358

Linus Torvalds's avatar
Linus Torvalds committed
359 360 361 362 363 364 365 366 367 368 369 370 371 372
#ifdef CONFIG_PCI
	m8xx_setup_pci_ptrs();
#endif

#ifdef CONFIG_BLK_DEV_INITRD
	/* take care of initrd if we have one */
	if ( r4 )
	{
		initrd_start = r4 + KERNELBASE;
		initrd_end = r5 + KERNELBASE;
	}
#endif /* CONFIG_BLK_DEV_INITRD */
	/* take care of cmd line */
	if ( r6 )
373
	{
Linus Torvalds's avatar
Linus Torvalds committed
374 375 376 377
		*(char *)(r7+KERNELBASE) = 0;
		strcpy(cmd_line, (char *)(r6+KERNELBASE));
	}

Linus Torvalds's avatar
Linus Torvalds committed
378
	ppc_md.setup_arch		= m8xx_setup_arch;
Linus Torvalds's avatar
Linus Torvalds committed
379
	ppc_md.show_percpuinfo		= m8xx_show_percpuinfo;
Linus Torvalds's avatar
Linus Torvalds committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
	ppc_md.irq_cannonicalize	= NULL;
	ppc_md.init_IRQ			= m8xx_init_IRQ;
	ppc_md.get_irq			= m8xx_get_irq;
	ppc_md.init			= NULL;

	ppc_md.restart			= m8xx_restart;
	ppc_md.power_off		= m8xx_power_off;
	ppc_md.halt			= m8xx_halt;

	ppc_md.time_init		= NULL;
	ppc_md.set_rtc_time		= m8xx_set_rtc_time;
	ppc_md.get_rtc_time		= m8xx_get_rtc_time;
	ppc_md.calibrate_decr		= m8xx_calibrate_decr;

	ppc_md.find_end_of_memory	= m8xx_find_end_of_memory;
	ppc_md.setup_io_mappings	= m8xx_map_io;

Linus Torvalds's avatar
Linus Torvalds committed
397
#if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
Linus Torvalds's avatar
Linus Torvalds committed
398
	m8xx_ide_init();
399
#endif
Linus Torvalds's avatar
Linus Torvalds committed
400
}