cpu.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  1. /*
  2. * (C) Copyright 2001
  3. * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
  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.c
  25. *
  26. * CPU specific code
  27. *
  28. * written or collected and sometimes rewritten by
  29. * Magnus Damm <damm@bitsmart.com>
  30. *
  31. * minor modifications by
  32. * Wolfgang Denk <wd@denx.de>
  33. *
  34. * more modifications by
  35. * Josh Huber <huber@mclx.com>
  36. * added support for the 74xx series of cpus
  37. * added support for the 7xx series of cpus
  38. * made the code a little less hard-coded, and more auto-detectish
  39. */
  40. #include <common.h>
  41. #include <command.h>
  42. #include <74xx_7xx.h>
  43. #include <asm/cache.h>
  44. #ifdef CONFIG_AMIGAONEG3SE
  45. #include "../board/MAI/AmigaOneG3SE/via686.h"
  46. #include "../board/MAI/AmigaOneG3SE/memio.h"
  47. #endif
  48. cpu_t
  49. get_cpu_type(void)
  50. {
  51. uint pvr = get_pvr();
  52. cpu_t type;
  53. type = CPU_UNKNOWN;
  54. switch (PVR_VER(pvr)) {
  55. case 0x000c:
  56. type = CPU_7400;
  57. break;
  58. case 0x0008:
  59. type = CPU_750;
  60. if (((pvr >> 8) & 0xff) == 0x01) {
  61. type = CPU_750CX; /* old CX (80100 and 8010x?)*/
  62. } else if (((pvr >> 8) & 0xff) == 0x22) {
  63. type = CPU_750CX; /* CX (82201,82202) and CXe (82214) */
  64. } else if (((pvr >> 8) & 0xff) == 0x33) {
  65. type = CPU_750CX; /* CXe (83311) */
  66. } else if (((pvr >> 12) & 0xF) == 0x3) {
  67. type = CPU_755;
  68. }
  69. break;
  70. case 0x7000:
  71. type = CPU_750FX;
  72. break;
  73. case 0x800C:
  74. type = CPU_7410;
  75. break;
  76. case 0x8000:
  77. type = CPU_7450;
  78. break;
  79. default:
  80. break;
  81. }
  82. return type;
  83. }
  84. /* ------------------------------------------------------------------------- */
  85. #if !defined(CONFIG_BAB7xx)
  86. int checkcpu (void)
  87. {
  88. DECLARE_GLOBAL_DATA_PTR;
  89. uint type = get_cpu_type();
  90. uint pvr = get_pvr();
  91. ulong clock = gd->cpu_clk;
  92. char buf[32];
  93. char *str;
  94. puts ("CPU: ");
  95. switch (type) {
  96. case CPU_750CX:
  97. printf ("750CX%s v%d.%d", (pvr&0xf0)?"e":"",
  98. (pvr>>8) & 0xf,
  99. pvr & 0xf);
  100. goto PR_CLK;
  101. case CPU_750:
  102. str = "750";
  103. break;
  104. case CPU_750FX:
  105. str = "750FX";
  106. break;
  107. case CPU_755:
  108. str = "755";
  109. break;
  110. case CPU_7400:
  111. str = "MPC7400";
  112. break;
  113. case CPU_7410:
  114. str = "MPC7410";
  115. break;
  116. case CPU_7450:
  117. str = "MPC7450";
  118. break;
  119. default:
  120. printf("Unknown CPU -- PVR: 0x%08x\n", pvr);
  121. return -1;
  122. }
  123. printf ("%s v%d.%d", str, (pvr >> 8) & 0xFF, pvr & 0xFF);
  124. PR_CLK:
  125. printf (" @ %s MHz\n", strmhz(buf, clock));
  126. return (0);
  127. }
  128. #endif
  129. /* these two functions are unimplemented currently [josh] */
  130. /* -------------------------------------------------------------------- */
  131. /* L1 i-cache */
  132. int
  133. checkicache(void)
  134. {
  135. return 0; /* XXX */
  136. }
  137. /* -------------------------------------------------------------------- */
  138. /* L1 d-cache */
  139. int
  140. checkdcache(void)
  141. {
  142. return 0; /* XXX */
  143. }
  144. /* -------------------------------------------------------------------- */
  145. static inline void
  146. soft_restart(unsigned long addr)
  147. {
  148. /* SRR0 has system reset vector, SRR1 has default MSR value */
  149. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  150. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  151. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  152. __asm__ __volatile__ ("mtspr 27, 4");
  153. __asm__ __volatile__ ("rfi");
  154. while(1); /* not reached */
  155. }
  156. #if !defined(CONFIG_PCIPPC2) && \
  157. !defined(CONFIG_BAB7xx) && \
  158. !defined(CONFIG_ELPPC)
  159. /* no generic way to do board reset. simply call soft_reset. */
  160. void
  161. do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  162. {
  163. ulong addr;
  164. /* flush and disable I/D cache */
  165. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  166. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  167. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  168. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  169. __asm__ __volatile__ ("sync");
  170. __asm__ __volatile__ ("mtspr 1008, 4");
  171. __asm__ __volatile__ ("isync");
  172. __asm__ __volatile__ ("sync");
  173. __asm__ __volatile__ ("mtspr 1008, 5");
  174. __asm__ __volatile__ ("isync");
  175. __asm__ __volatile__ ("sync");
  176. #ifdef CFG_RESET_ADDRESS
  177. addr = CFG_RESET_ADDRESS;
  178. #else
  179. /*
  180. * note: when CFG_MONITOR_BASE points to a RAM address,
  181. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  182. * address. Better pick an address known to be invalid on your
  183. * system and assign it to CFG_RESET_ADDRESS.
  184. */
  185. addr = CFG_MONITOR_BASE - sizeof (ulong);
  186. #endif
  187. soft_restart(addr);
  188. while(1); /* not reached */
  189. }
  190. #endif
  191. /* ------------------------------------------------------------------------- */
  192. /*
  193. * For the 7400 the TB clock runs at 1/4 the cpu bus speed.
  194. */
  195. #ifdef CONFIG_AMIGAONEG3SE
  196. unsigned long get_tbclk(void)
  197. {
  198. DECLARE_GLOBAL_DATA_PTR;
  199. return (gd->bus_clk / 4);
  200. }
  201. #else /* ! CONFIG_AMIGAONEG3SE */
  202. unsigned long get_tbclk (void)
  203. {
  204. return CFG_BUS_HZ / 4;
  205. }
  206. #endif /* CONFIG_AMIGAONEG3SE */
  207. /* ------------------------------------------------------------------------- */
  208. #if defined(CONFIG_WATCHDOG)
  209. #if !defined(CONFIG_PCIPPC2) && !defined(CONFIG_BAB7xx)
  210. void
  211. watchdog_reset(void)
  212. {
  213. }
  214. #endif /* !CONFIG_PCIPPC2 && !CONFIG_BAB7xx */
  215. #endif /* CONFIG_WATCHDOG */
  216. /* ------------------------------------------------------------------------- */