m8xx_setup.c 12 KB

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