m8xx_setup.c 13 KB

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