ibm44x_common.c 5.9 KB

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