ibm44x_common.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. * PPC44x system library
  3. *
  4. * Matt Porter <mporter@kernel.crashing.org>
  5. * Copyright 2002-2005 MontaVista Software Inc.
  6. *
  7. * Eugene Surovegin <eugene.surovegin@zultys.com> or <ebs@ebshome.net>
  8. * Copyright (c) 2003, 2004 Zultys Technologies
  9. *
  10. * This program is free software; you can redistribute it and/or modify it
  11. * under the terms of the GNU General Public License as published by the
  12. * Free Software Foundation; either version 2 of the License, or (at your
  13. * option) any later version.
  14. *
  15. */
  16. #include <linux/time.h>
  17. #include <linux/types.h>
  18. #include <linux/serial.h>
  19. #include <linux/module.h>
  20. #include <linux/initrd.h>
  21. #include <asm/ibm44x.h>
  22. #include <asm/mmu.h>
  23. #include <asm/machdep.h>
  24. #include <asm/time.h>
  25. #include <asm/ppc4xx_pic.h>
  26. #include <asm/param.h>
  27. #include <asm/bootinfo.h>
  28. #include <asm/ppcboot.h>
  29. #include <syslib/gen550.h>
  30. /* Global Variables */
  31. bd_t __res;
  32. phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size)
  33. {
  34. phys_addr_t page_4gb = 0;
  35. /*
  36. * Trap the least significant 32-bit portions of an
  37. * address in the 440's 36-bit address space. Fix
  38. * them up with the appropriate ERPN
  39. */
  40. if ((addr >= PPC44x_IO_LO) && (addr <= PPC44x_IO_HI))
  41. page_4gb = PPC44x_IO_PAGE;
  42. else if ((addr >= PPC44x_PCI0CFG_LO) && (addr <= PPC44x_PCI0CFG_HI))
  43. page_4gb = PPC44x_PCICFG_PAGE;
  44. #ifdef CONFIG_440SP
  45. else if ((addr >= PPC44x_PCI1CFG_LO) && (addr <= PPC44x_PCI1CFG_HI))
  46. page_4gb = PPC44x_PCICFG_PAGE;
  47. else if ((addr >= PPC44x_PCI2CFG_LO) && (addr <= PPC44x_PCI2CFG_HI))
  48. page_4gb = PPC44x_PCICFG_PAGE;
  49. #endif
  50. else if ((addr >= PPC44x_PCIMEM_LO) && (addr <= PPC44x_PCIMEM_HI))
  51. page_4gb = PPC44x_PCIMEM_PAGE;
  52. return (page_4gb | addr);
  53. };
  54. EXPORT_SYMBOL(fixup_bigphys_addr);
  55. void __init ibm44x_calibrate_decr(unsigned int freq)
  56. {
  57. tb_ticks_per_jiffy = freq / HZ;
  58. tb_to_us = mulhwu_scale_factor(freq, 1000000);
  59. /* Set the time base to zero */
  60. mtspr(SPRN_TBWL, 0);
  61. mtspr(SPRN_TBWU, 0);
  62. /* Clear any pending timer interrupts */
  63. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
  64. /* Enable decrementer interrupt */
  65. mtspr(SPRN_TCR, TCR_DIE);
  66. }
  67. extern void abort(void);
  68. static void ibm44x_restart(char *cmd)
  69. {
  70. local_irq_disable();
  71. abort();
  72. }
  73. static void ibm44x_power_off(void)
  74. {
  75. local_irq_disable();
  76. for(;;);
  77. }
  78. static void ibm44x_halt(void)
  79. {
  80. local_irq_disable();
  81. for(;;);
  82. }
  83. /*
  84. * Read the 44x memory controller to get size of system memory.
  85. */
  86. static unsigned long __init ibm44x_find_end_of_memory(void)
  87. {
  88. u32 i, bank_config;
  89. u32 mem_size = 0;
  90. for (i=0; i<4; i++)
  91. {
  92. switch (i)
  93. {
  94. case 0:
  95. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
  96. break;
  97. case 1:
  98. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
  99. break;
  100. case 2:
  101. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
  102. break;
  103. case 3:
  104. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
  105. break;
  106. }
  107. bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
  108. if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
  109. continue;
  110. switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
  111. {
  112. case SDRAM_CONFIG_SIZE_8M:
  113. mem_size += PPC44x_MEM_SIZE_8M;
  114. break;
  115. case SDRAM_CONFIG_SIZE_16M:
  116. mem_size += PPC44x_MEM_SIZE_16M;
  117. break;
  118. case SDRAM_CONFIG_SIZE_32M:
  119. mem_size += PPC44x_MEM_SIZE_32M;
  120. break;
  121. case SDRAM_CONFIG_SIZE_64M:
  122. mem_size += PPC44x_MEM_SIZE_64M;
  123. break;
  124. case SDRAM_CONFIG_SIZE_128M:
  125. mem_size += PPC44x_MEM_SIZE_128M;
  126. break;
  127. case SDRAM_CONFIG_SIZE_256M:
  128. mem_size += PPC44x_MEM_SIZE_256M;
  129. break;
  130. case SDRAM_CONFIG_SIZE_512M:
  131. mem_size += PPC44x_MEM_SIZE_512M;
  132. break;
  133. }
  134. }
  135. return mem_size;
  136. }
  137. void __init ibm44x_platform_init(unsigned long r3, unsigned long r4, unsigned long r5,
  138. unsigned long r6, unsigned long r7)
  139. {
  140. parse_bootinfo(find_bootinfo());
  141. /*
  142. * If we were passed in a board information, copy it into the
  143. * residual data area.
  144. */
  145. if (r3)
  146. __res = *(bd_t *)(r3 + KERNELBASE);
  147. #if defined(CONFIG_BLK_DEV_INITRD)
  148. /*
  149. * If the init RAM disk has been configured in, and there's a valid
  150. * starting address for it, set it up.
  151. */
  152. if (r4) {
  153. initrd_start = r4 + KERNELBASE;
  154. initrd_end = r5 + KERNELBASE;
  155. }
  156. #endif /* CONFIG_BLK_DEV_INITRD */
  157. /* Copy the kernel command line arguments to a safe place. */
  158. if (r6) {
  159. *(char *) (r7 + KERNELBASE) = 0;
  160. strcpy(cmd_line, (char *) (r6 + KERNELBASE));
  161. }
  162. ppc_md.init_IRQ = ppc4xx_pic_init;
  163. ppc_md.find_end_of_memory = ibm44x_find_end_of_memory;
  164. ppc_md.restart = ibm44x_restart;
  165. ppc_md.power_off = ibm44x_power_off;
  166. ppc_md.halt = ibm44x_halt;
  167. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  168. ppc_md.progress = gen550_progress;
  169. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  170. #ifdef CONFIG_KGDB
  171. ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
  172. #endif
  173. /*
  174. * The Abatron BDI JTAG debugger does not tolerate others
  175. * mucking with the debug registers.
  176. */
  177. #if !defined(CONFIG_BDI_SWITCH)
  178. /* Enable internal debug mode */
  179. mtspr(SPRN_DBCR0, (DBCR0_IDM));
  180. /* Clear any residual debug events */
  181. mtspr(SPRN_DBSR, 0xffffffff);
  182. #endif
  183. }
  184. /* Called from machine_check_exception */
  185. void platform_machine_check(struct pt_regs *regs)
  186. {
  187. #if defined(CONFIG_440SP) || defined(CONFIG_440SPE)
  188. printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x%08x\n",
  189. mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL),
  190. mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESRH),
  191. mfdcr(DCRN_PLB0_BESRL));
  192. printk("PLB1: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x%08x\n",
  193. mfdcr(DCRN_PLB1_BEARH), mfdcr(DCRN_PLB1_BEARL),
  194. mfdcr(DCRN_PLB1_ACR), mfdcr(DCRN_PLB1_BESRH),
  195. mfdcr(DCRN_PLB1_BESRL));
  196. #else
  197. printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x\n",
  198. mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL),
  199. mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESR));
  200. #endif
  201. printk("POB0: BEAR=0x%08x%08x BESR0=0x%08x BESR1=0x%08x\n",
  202. mfdcr(DCRN_POB0_BEARH), mfdcr(DCRN_POB0_BEARL),
  203. mfdcr(DCRN_POB0_BESR0), mfdcr(DCRN_POB0_BESR1));
  204. printk("OPB0: BEAR=0x%08x%08x BSTAT=0x%08x\n",
  205. mfdcr(DCRN_OPB0_BEARH), mfdcr(DCRN_OPB0_BEARL),
  206. mfdcr(DCRN_OPB0_BSTAT));
  207. }