ibm44x_common.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 <syslib/gen550.h>
  30. phys_addr_t fixup_bigphys_addr(phys_addr_t addr, phys_addr_t size)
  31. {
  32. phys_addr_t page_4gb = 0;
  33. /*
  34. * Trap the least significant 32-bit portions of an
  35. * address in the 440's 36-bit address space. Fix
  36. * them up with the appropriate ERPN
  37. */
  38. if ((addr >= PPC44x_IO_LO) && (addr <= PPC44x_IO_HI))
  39. page_4gb = PPC44x_IO_PAGE;
  40. else if ((addr >= PPC44x_PCI0CFG_LO) && (addr <= PPC44x_PCI0CFG_HI))
  41. page_4gb = PPC44x_PCICFG_PAGE;
  42. #ifdef CONFIG_440SP
  43. else if ((addr >= PPC44x_PCI1CFG_LO) && (addr <= PPC44x_PCI1CFG_HI))
  44. page_4gb = PPC44x_PCICFG_PAGE;
  45. else if ((addr >= PPC44x_PCI2CFG_LO) && (addr <= PPC44x_PCI2CFG_HI))
  46. page_4gb = PPC44x_PCICFG_PAGE;
  47. #endif
  48. else if ((addr >= PPC44x_PCIMEM_LO) && (addr <= PPC44x_PCIMEM_HI))
  49. page_4gb = PPC44x_PCIMEM_PAGE;
  50. return (page_4gb | addr);
  51. };
  52. EXPORT_SYMBOL(fixup_bigphys_addr);
  53. void __init ibm44x_calibrate_decr(unsigned int freq)
  54. {
  55. tb_ticks_per_jiffy = freq / HZ;
  56. tb_to_us = mulhwu_scale_factor(freq, 1000000);
  57. /* Set the time base to zero */
  58. mtspr(SPRN_TBWL, 0);
  59. mtspr(SPRN_TBWU, 0);
  60. /* Clear any pending timer interrupts */
  61. mtspr(SPRN_TSR, TSR_ENW | TSR_WIS | TSR_DIS | TSR_FIS);
  62. /* Enable decrementer interrupt */
  63. mtspr(SPRN_TCR, TCR_DIE);
  64. }
  65. extern void abort(void);
  66. static void ibm44x_restart(char *cmd)
  67. {
  68. local_irq_disable();
  69. abort();
  70. }
  71. static void ibm44x_power_off(void)
  72. {
  73. local_irq_disable();
  74. for(;;);
  75. }
  76. static void ibm44x_halt(void)
  77. {
  78. local_irq_disable();
  79. for(;;);
  80. }
  81. /*
  82. * Read the 44x memory controller to get size of system memory.
  83. */
  84. static unsigned long __init ibm44x_find_end_of_memory(void)
  85. {
  86. u32 i, bank_config;
  87. u32 mem_size = 0;
  88. for (i=0; i<4; i++)
  89. {
  90. switch (i)
  91. {
  92. case 0:
  93. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B0CR);
  94. break;
  95. case 1:
  96. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B1CR);
  97. break;
  98. case 2:
  99. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B2CR);
  100. break;
  101. case 3:
  102. mtdcr(DCRN_SDRAM0_CFGADDR, SDRAM0_B3CR);
  103. break;
  104. }
  105. bank_config = mfdcr(DCRN_SDRAM0_CFGDATA);
  106. if (!(bank_config & SDRAM_CONFIG_BANK_ENABLE))
  107. continue;
  108. switch (SDRAM_CONFIG_BANK_SIZE(bank_config))
  109. {
  110. case SDRAM_CONFIG_SIZE_8M:
  111. mem_size += PPC44x_MEM_SIZE_8M;
  112. break;
  113. case SDRAM_CONFIG_SIZE_16M:
  114. mem_size += PPC44x_MEM_SIZE_16M;
  115. break;
  116. case SDRAM_CONFIG_SIZE_32M:
  117. mem_size += PPC44x_MEM_SIZE_32M;
  118. break;
  119. case SDRAM_CONFIG_SIZE_64M:
  120. mem_size += PPC44x_MEM_SIZE_64M;
  121. break;
  122. case SDRAM_CONFIG_SIZE_128M:
  123. mem_size += PPC44x_MEM_SIZE_128M;
  124. break;
  125. case SDRAM_CONFIG_SIZE_256M:
  126. mem_size += PPC44x_MEM_SIZE_256M;
  127. break;
  128. case SDRAM_CONFIG_SIZE_512M:
  129. mem_size += PPC44x_MEM_SIZE_512M;
  130. break;
  131. }
  132. }
  133. return mem_size;
  134. }
  135. void __init ibm44x_platform_init(void)
  136. {
  137. ppc_md.init_IRQ = ppc4xx_pic_init;
  138. ppc_md.find_end_of_memory = ibm44x_find_end_of_memory;
  139. ppc_md.restart = ibm44x_restart;
  140. ppc_md.power_off = ibm44x_power_off;
  141. ppc_md.halt = ibm44x_halt;
  142. #ifdef CONFIG_SERIAL_TEXT_DEBUG
  143. ppc_md.progress = gen550_progress;
  144. #endif /* CONFIG_SERIAL_TEXT_DEBUG */
  145. #ifdef CONFIG_KGDB
  146. ppc_md.kgdb_map_scc = gen550_kgdb_map_scc;
  147. #endif
  148. /*
  149. * The Abatron BDI JTAG debugger does not tolerate others
  150. * mucking with the debug registers.
  151. */
  152. #if !defined(CONFIG_BDI_SWITCH)
  153. /* Enable internal debug mode */
  154. mtspr(SPRN_DBCR0, (DBCR0_IDM));
  155. /* Clear any residual debug events */
  156. mtspr(SPRN_DBSR, 0xffffffff);
  157. #endif
  158. }
  159. /* Called from MachineCheckException */
  160. void platform_machine_check(struct pt_regs *regs)
  161. {
  162. printk("PLB0: BEAR=0x%08x%08x ACR= 0x%08x BESR= 0x%08x\n",
  163. mfdcr(DCRN_PLB0_BEARH), mfdcr(DCRN_PLB0_BEARL),
  164. mfdcr(DCRN_PLB0_ACR), mfdcr(DCRN_PLB0_BESR));
  165. printk("POB0: BEAR=0x%08x%08x BESR0=0x%08x BESR1=0x%08x\n",
  166. mfdcr(DCRN_POB0_BEARH), mfdcr(DCRN_POB0_BEARL),
  167. mfdcr(DCRN_POB0_BESR0), mfdcr(DCRN_POB0_BESR1));
  168. printk("OPB0: BEAR=0x%08x%08x BSTAT=0x%08x\n",
  169. mfdcr(DCRN_OPB0_BEARH), mfdcr(DCRN_OPB0_BEARL),
  170. mfdcr(DCRN_OPB0_BSTAT));
  171. }