cpu.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275
  1. /*
  2. * (C) Copyright 2000-2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*
  24. * CPU specific code
  25. *
  26. * written or collected and sometimes rewritten by
  27. * Magnus Damm <damm@bitsmart.com>
  28. *
  29. * minor modifications by
  30. * Wolfgang Denk <wd@denx.de>
  31. */
  32. #include <common.h>
  33. #include <watchdog.h>
  34. #include <command.h>
  35. #include <asm/cache.h>
  36. #include <ppc4xx.h>
  37. #if defined(CONFIG_440)
  38. static int do_chip_reset( unsigned long sys0, unsigned long sys1 );
  39. #endif
  40. /* ------------------------------------------------------------------------- */
  41. int checkcpu (void)
  42. {
  43. #if defined(CONFIG_405GP) || \
  44. defined(CONFIG_405CR) || \
  45. defined(CONFIG_405EP) || \
  46. defined(CONFIG_440) || \
  47. defined(CONFIG_IOP480)
  48. uint pvr = get_pvr();
  49. #endif
  50. #if defined(CONFIG_405GP) || \
  51. defined(CONFIG_405CR) || \
  52. defined(CONFIG_405EP) || \
  53. defined(CONFIG_IOP480)
  54. DECLARE_GLOBAL_DATA_PTR;
  55. ulong clock = gd->cpu_clk;
  56. char buf[32];
  57. #endif
  58. #if defined(CONFIG_405GP) || defined(CONFIG_405CR) || defined(CONFIG_405EP)
  59. PPC405_SYS_INFO sys_info;
  60. puts ("CPU: ");
  61. get_sys_info(&sys_info);
  62. #ifdef CONFIG_405GP
  63. puts ("IBM PowerPC 405GP");
  64. if (pvr == PVR_405GPR_RB) {
  65. putc('r');
  66. }
  67. puts (" Rev. ");
  68. #endif
  69. #ifdef CONFIG_405CR
  70. puts ("IBM PowerPC 405CR Rev. ");
  71. #endif
  72. #ifdef CONFIG_405EP
  73. puts ("IBM PowerPC 405EP Rev. ");
  74. #endif
  75. switch (pvr) {
  76. case PVR_405GP_RB:
  77. case PVR_405GPR_RB:
  78. putc('B');
  79. break;
  80. case PVR_405GP_RC:
  81. #ifdef CONFIG_405CR
  82. case PVR_405CR_RC:
  83. #endif
  84. putc('C');
  85. break;
  86. case PVR_405GP_RD:
  87. putc('D');
  88. break;
  89. #ifdef CONFIG_405GP
  90. case PVR_405GP_RE:
  91. putc('E');
  92. break;
  93. #endif
  94. case PVR_405CR_RA:
  95. putc('A');
  96. break;
  97. case PVR_405CR_RB:
  98. case PVR_405EP_RB:
  99. putc('B');
  100. break;
  101. default:
  102. printf ("? (PVR=%08x)", pvr);
  103. break;
  104. }
  105. printf (" at %s MHz (PLB=%lu, OPB=%lu, EBC=%lu MHz)\n", strmhz(buf, clock),
  106. sys_info.freqPLB / 1000000,
  107. sys_info.freqPLB / sys_info.pllOpbDiv / 1000000,
  108. sys_info.freqPLB / sys_info.pllExtBusDiv / 1000000);
  109. #if defined(CONFIG_405GP)
  110. if (mfdcr(strap) & PSR_PCI_ASYNC_EN) {
  111. printf (" PCI async ext clock used, ");
  112. } else {
  113. printf (" PCI sync clock at %lu MHz, ",
  114. sys_info.freqPLB / sys_info.pllPciDiv / 1000000);
  115. }
  116. printf ("%sternal PCI arbiter enabled\n",
  117. (mfdcr(strap) & PSR_PCI_ARBIT_EN) ? "in" : "ex");
  118. #elif defined(CONFIG_405EP)
  119. printf (" IIC Boot EEPROM %sabled\n",
  120. (mfdcr(cpc0_boot) & CPC0_BOOT_SEP) ? "en" : "dis");
  121. printf (" PCI async ext clock used, ");
  122. printf ("%sternal PCI arbiter enabled\n",
  123. (mfdcr(cpc0_pci) & CPC0_PCI_ARBIT_EN) ? "in" : "ex");
  124. #endif
  125. #if defined(CONFIG_405EP)
  126. printf (" 16 kB I-Cache 16 kB D-Cache");
  127. #else
  128. printf (" 16 kB I-Cache %d kB D-Cache",
  129. ((pvr | 0x00000001) == PVR_405GPR_RB) ? 16 : 8);
  130. #endif
  131. #endif /* defined(CONFIG_405GP) || defined(CONFIG_405CR) */
  132. #ifdef CONFIG_IOP480
  133. printf ("PLX IOP480 (PVR=%08x)", pvr);
  134. printf (" at %s MHz:", strmhz(buf, clock));
  135. printf (" %u kB I-Cache", 4);
  136. printf (" %u kB D-Cache", 2);
  137. #endif
  138. #if defined(CONFIG_440)
  139. puts ("IBM PowerPC 440 G");
  140. switch(pvr) {
  141. case PVR_440GP_RB:
  142. puts("P Rev. B");
  143. /* See errata 1.12: CHIP_4 */
  144. if ((mfdcr(cpc0_sys0) != mfdcr(cpc0_strp0)) ||
  145. (mfdcr(cpc0_sys1) != mfdcr(cpc0_strp1)) ){
  146. puts ( "\n\t CPC0_SYSx DCRs corrupted. "
  147. "Resetting chip ...\n");
  148. udelay( 1000 * 1000 ); /* Give time for serial buf to clear */
  149. do_chip_reset ( mfdcr(cpc0_strp0),
  150. mfdcr(cpc0_strp1) );
  151. }
  152. break;
  153. case PVR_440GP_RC:
  154. puts("P Rev. C");
  155. break;
  156. case PVR_440GX_RA:
  157. puts("X Rev. A");
  158. break;
  159. case PVR_440GX_RB:
  160. puts("X Rev. B");
  161. break;
  162. default:
  163. printf ("UNKNOWN (PVR=%08x)", pvr);
  164. break;
  165. }
  166. #endif
  167. puts ("\n");
  168. return 0;
  169. }
  170. /* ------------------------------------------------------------------------- */
  171. int do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  172. {
  173. /*
  174. * Initiate system reset in debug control register DBCR
  175. */
  176. __asm__ __volatile__("lis 3, 0x3000" ::: "r3");
  177. #if defined(CONFIG_440)
  178. __asm__ __volatile__("mtspr 0x134, 3");
  179. #else
  180. __asm__ __volatile__("mtspr 0x3f2, 3");
  181. #endif
  182. return 1;
  183. }
  184. #if defined(CONFIG_440)
  185. static
  186. int do_chip_reset (unsigned long sys0, unsigned long sys1)
  187. {
  188. /* Changes to cpc0_sys0 and cpc0_sys1 require chip
  189. * reset.
  190. */
  191. mtdcr (cntrl0, mfdcr (cntrl0) | 0x80000000); /* Set SWE */
  192. mtdcr (cpc0_sys0, sys0);
  193. mtdcr (cpc0_sys1, sys1);
  194. mtdcr (cntrl0, mfdcr (cntrl0) & ~0x80000000); /* Clr SWE */
  195. mtspr (dbcr0, 0x20000000); /* Reset the chip */
  196. return 1;
  197. }
  198. #endif
  199. /*
  200. * Get timebase clock frequency
  201. */
  202. unsigned long get_tbclk (void)
  203. {
  204. #if defined(CONFIG_440)
  205. sys_info_t sys_info;
  206. get_sys_info(&sys_info);
  207. return (sys_info.freqProcessor);
  208. #elif defined(CONFIG_405GP) || \
  209. defined(CONFIG_405CR) || \
  210. defined(CONFIG_405) || \
  211. defined(CONFIG_405EP)
  212. PPC405_SYS_INFO sys_info;
  213. get_sys_info(&sys_info);
  214. return (sys_info.freqProcessor);
  215. #elif defined(CONFIG_IOP480)
  216. return (66000000);
  217. #else
  218. # error get_tbclk() not implemented
  219. #endif
  220. }
  221. #if defined(CONFIG_WATCHDOG)
  222. void
  223. watchdog_reset(void)
  224. {
  225. int re_enable = disable_interrupts();
  226. reset_4xx_watchdog();
  227. if (re_enable) enable_interrupts();
  228. }
  229. void
  230. reset_4xx_watchdog(void)
  231. {
  232. /*
  233. * Clear TSR(WIS) bit
  234. */
  235. mtspr(tsr, 0x40000000);
  236. }
  237. #endif /* CONFIG_WATCHDOG */