ppc4xx_setup.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. /*
  2. *
  3. * Copyright (c) 1999-2000 Grant Erickson <grant@lcse.umn.edu>
  4. *
  5. * Copyright 2000-2001 MontaVista Software Inc.
  6. * Completed implementation.
  7. * Author: MontaVista Software, Inc. <source@mvista.com>
  8. * Frank Rowand <frank_rowand@mvista.com>
  9. * Debbie Chu <debbie_chu@mvista.com>
  10. * Further modifications by Armin Kuster
  11. *
  12. * Module name: ppc4xx_setup.c
  13. *
  14. */
  15. #include <linux/config.h>
  16. #include <linux/init.h>
  17. #include <linux/smp.h>
  18. #include <linux/threads.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/irq.h>
  21. #include <linux/reboot.h>
  22. #include <linux/param.h>
  23. #include <linux/string.h>
  24. #include <linux/initrd.h>
  25. #include <linux/pci.h>
  26. #include <linux/rtc.h>
  27. #include <linux/console.h>
  28. #include <linux/ide.h>
  29. #include <linux/serial_reg.h>
  30. #include <linux/seq_file.h>
  31. #include <asm/system.h>
  32. #include <asm/processor.h>
  33. #include <asm/machdep.h>
  34. #include <asm/page.h>
  35. #include <asm/kgdb.h>
  36. #include <asm/ibm4xx.h>
  37. #include <asm/time.h>
  38. #include <asm/todc.h>
  39. #include <asm/ppc4xx_pic.h>
  40. #include <asm/pci-bridge.h>
  41. #include <asm/bootinfo.h>
  42. #include <syslib/gen550.h>
  43. /* Function Prototypes */
  44. extern void abort(void);
  45. extern void ppc4xx_find_bridges(void);
  46. /* Global Variables */
  47. bd_t __res;
  48. void __init
  49. ppc4xx_setup_arch(void)
  50. {
  51. #if !defined(CONFIG_BDI_SWITCH)
  52. /*
  53. * The Abatron BDI JTAG debugger does not tolerate others
  54. * mucking with the debug registers.
  55. */
  56. mtspr(SPRN_DBCR0, (DBCR0_IDM));
  57. mtspr(SPRN_DBSR, 0xffffffff);
  58. #endif
  59. /* Setup PCI host bridges */
  60. #ifdef CONFIG_PCI
  61. ppc4xx_find_bridges();
  62. #endif
  63. }
  64. /*
  65. * This routine pretty-prints the platform's internal CPU clock
  66. * frequencies into the buffer for usage in /proc/cpuinfo.
  67. */
  68. static int
  69. ppc4xx_show_percpuinfo(struct seq_file *m, int i)
  70. {
  71. seq_printf(m, "clock\t\t: %ldMHz\n", (long)__res.bi_intfreq / 1000000);
  72. return 0;
  73. }
  74. /*
  75. * This routine pretty-prints the platform's internal bus clock
  76. * frequencies into the buffer for usage in /proc/cpuinfo.
  77. */
  78. static int
  79. ppc4xx_show_cpuinfo(struct seq_file *m)
  80. {
  81. bd_t *bip = &__res;
  82. seq_printf(m, "machine\t\t: %s\n", PPC4xx_MACHINE_NAME);
  83. seq_printf(m, "plb bus clock\t: %ldMHz\n",
  84. (long) bip->bi_busfreq / 1000000);
  85. #ifdef CONFIG_PCI
  86. seq_printf(m, "pci bus clock\t: %dMHz\n",
  87. bip->bi_pci_busfreq / 1000000);
  88. #endif
  89. return 0;
  90. }
  91. /*
  92. * Return the virtual address representing the top of physical RAM.
  93. */
  94. static unsigned long __init
  95. ppc4xx_find_end_of_memory(void)
  96. {
  97. return ((unsigned long) __res.bi_memsize);
  98. }
  99. void __init
  100. ppc4xx_map_io(void)
  101. {
  102. io_block_mapping(PPC4xx_ONB_IO_VADDR,
  103. PPC4xx_ONB_IO_PADDR, PPC4xx_ONB_IO_SIZE, _PAGE_IO);
  104. #ifdef CONFIG_PCI
  105. io_block_mapping(PPC4xx_PCI_IO_VADDR,
  106. PPC4xx_PCI_IO_PADDR, PPC4xx_PCI_IO_SIZE, _PAGE_IO);
  107. io_block_mapping(PPC4xx_PCI_CFG_VADDR,
  108. PPC4xx_PCI_CFG_PADDR, PPC4xx_PCI_CFG_SIZE, _PAGE_IO);
  109. io_block_mapping(PPC4xx_PCI_LCFG_VADDR,
  110. PPC4xx_PCI_LCFG_PADDR, PPC4xx_PCI_LCFG_SIZE, _PAGE_IO);
  111. #endif
  112. }
  113. void __init
  114. ppc4xx_init_IRQ(void)
  115. {
  116. ppc4xx_pic_init();
  117. }
  118. static void
  119. ppc4xx_restart(char *cmd)
  120. {
  121. printk("%s\n", cmd);
  122. abort();
  123. }
  124. static void
  125. ppc4xx_power_off(void)
  126. {
  127. printk("System Halted\n");
  128. local_irq_disable();
  129. while (1) ;
  130. }
  131. static void
  132. ppc4xx_halt(void)
  133. {
  134. printk("System Halted\n");
  135. local_irq_disable();
  136. while (1) ;
  137. }
  138. /*
  139. * This routine retrieves the internal processor frequency from the board
  140. * information structure, sets up the kernel timer decrementer based on
  141. * that value, enables the 4xx programmable interval timer (PIT) and sets
  142. * it up for auto-reload.
  143. */
  144. static void __init
  145. ppc4xx_calibrate_decr(void)
  146. {
  147. unsigned int freq;
  148. bd_t *bip = &__res;
  149. #if defined(CONFIG_WALNUT) || defined(CONFIG_SYCAMORE)
  150. /* Walnut boot rom sets DCR CHCR1 (aka CPC0_CR1) bit CETE to 1 */
  151. mtdcr(DCRN_CHCR1, mfdcr(DCRN_CHCR1) & ~CHR1_CETE);
  152. #endif
  153. freq = bip->bi_tbfreq;
  154. tb_ticks_per_jiffy = freq / HZ;
  155. tb_to_us = mulhwu_scale_factor(freq, 1000000);
  156. /* Set the time base to zero.
  157. ** At 200 Mhz, time base will rollover in ~2925 years.
  158. */
  159. mtspr(SPRN_TBWL, 0);
  160. mtspr(SPRN_TBWU, 0);
  161. /* Clear any pending timer interrupts */
  162. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_PIS | TSR_FIS);
  163. mtspr(SPRN_TCR, TCR_PIE | TCR_ARE);
  164. /* Set the PIT reload value and just let it run. */
  165. mtspr(SPRN_PIT, tb_ticks_per_jiffy);
  166. }
  167. /*
  168. * IDE stuff.
  169. * should be generic for every IDE PCI chipset
  170. */
  171. #if defined(CONFIG_PCI) && defined(CONFIG_IDE)
  172. static void
  173. ppc4xx_ide_init_hwif_ports(hw_regs_t * hw, unsigned long data_port,
  174. unsigned long ctrl_port, int *irq)
  175. {
  176. int i;
  177. for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; ++i)
  178. hw->io_ports[i] = data_port + i - IDE_DATA_OFFSET;
  179. hw->io_ports[IDE_CONTROL_OFFSET] = ctrl_port;
  180. }
  181. #endif /* defined(CONFIG_PCI) && defined(CONFIG_IDE) */
  182. TODC_ALLOC();
  183. /*
  184. * Input(s):
  185. * r3 - Optional pointer to a board information structure.
  186. * r4 - Optional pointer to the physical starting address of the init RAM
  187. * disk.
  188. * r5 - Optional pointer to the physical ending address of the init RAM
  189. * disk.
  190. * r6 - Optional pointer to the physical starting address of any kernel
  191. * command-line parameters.
  192. * r7 - Optional pointer to the physical ending address of any kernel
  193. * command-line parameters.
  194. */
  195. void __init
  196. ppc4xx_init(unsigned long r3, unsigned long r4, unsigned long r5,
  197. unsigned long r6, unsigned long r7)
  198. {
  199. parse_bootinfo(find_bootinfo());
  200. /*
  201. * If we were passed in a board information, copy it into the
  202. * residual data area.
  203. */
  204. if (r3)
  205. __res = *(bd_t *)(r3 + KERNELBASE);
  206. #if defined(CONFIG_BLK_DEV_INITRD)
  207. /*
  208. * If the init RAM disk has been configured in, and there's a valid
  209. * starting address for it, set it up.
  210. */
  211. if (r4) {
  212. initrd_start = r4 + KERNELBASE;
  213. initrd_end = r5 + KERNELBASE;
  214. }
  215. #endif /* CONFIG_BLK_DEV_INITRD */
  216. /* Copy the kernel command line arguments to a safe place. */
  217. if (r6) {
  218. *(char *) (r7 + KERNELBASE) = 0;
  219. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  220. }
  221. /* Initialize machine-dependent vectors */
  222. ppc_md.setup_arch = ppc4xx_setup_arch;
  223. ppc_md.show_percpuinfo = ppc4xx_show_percpuinfo;
  224. ppc_md.show_cpuinfo = ppc4xx_show_cpuinfo;
  225. ppc_md.init_IRQ = ppc4xx_init_IRQ;
  226. ppc_md.restart = ppc4xx_restart;
  227. ppc_md.power_off = ppc4xx_power_off;
  228. ppc_md.halt = ppc4xx_halt;
  229. ppc_md.calibrate_decr = ppc4xx_calibrate_decr;
  230. ppc_md.find_end_of_memory = ppc4xx_find_end_of_memory;
  231. ppc_md.setup_io_mappings = ppc4xx_map_io;
  232. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  233. ppc_md.progress = gen550_progress;
  234. #endif
  235. #if defined(CONFIG_PCI) && defined(CONFIG_IDE)
  236. ppc_ide_md.ide_init_hwif = ppc4xx_ide_init_hwif_ports;
  237. #endif /* defined(CONFIG_PCI) && defined(CONFIG_IDE) */
  238. }
  239. /* Called from MachineCheckException */
  240. void platform_machine_check(struct pt_regs *regs)
  241. {
  242. #if defined(DCRN_PLB0_BEAR)
  243. printk("PLB0: BEAR= 0x%08x ACR= 0x%08x BESR= 0x%08x\n",
  244. mfdcr(DCRN_PLB0_BEAR), mfdcr(DCRN_PLB0_ACR),
  245. mfdcr(DCRN_PLB0_BESR));
  246. #endif
  247. #if defined(DCRN_POB0_BEAR)
  248. printk("PLB0 to OPB: BEAR= 0x%08x BESR0= 0x%08x BESR1= 0x%08x\n",
  249. mfdcr(DCRN_POB0_BEAR), mfdcr(DCRN_POB0_BESR0),
  250. mfdcr(DCRN_POB0_BESR1));
  251. #endif
  252. }