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