ppc4xx_setup.c 7.6 KB

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