ppc4xx_setup.c 7.0 KB

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