m8xx_setup.c 13 KB

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