ibm44x_common.c 5.9 KB

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