cpu.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  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. #if defined(CONFIG_OF_FLAT_TREE)
  45. #include <ft_build.h>
  46. #endif
  47. #ifdef CONFIG_AMIGAONEG3SE
  48. #include "../board/MAI/AmigaOneG3SE/via686.h"
  49. #include "../board/MAI/AmigaOneG3SE/memio.h"
  50. #endif
  51. DECLARE_GLOBAL_DATA_PTR;
  52. cpu_t
  53. get_cpu_type(void)
  54. {
  55. uint pvr = get_pvr();
  56. cpu_t type;
  57. type = CPU_UNKNOWN;
  58. switch (PVR_VER(pvr)) {
  59. case 0x000c:
  60. type = CPU_7400;
  61. break;
  62. case 0x0008:
  63. type = CPU_750;
  64. if (((pvr >> 8) & 0xff) == 0x01) {
  65. type = CPU_750CX; /* old CX (80100 and 8010x?)*/
  66. } else if (((pvr >> 8) & 0xff) == 0x22) {
  67. type = CPU_750CX; /* CX (82201,82202) and CXe (82214) */
  68. } else if (((pvr >> 8) & 0xff) == 0x33) {
  69. type = CPU_750CX; /* CXe (83311) */
  70. } else if (((pvr >> 12) & 0xF) == 0x3) {
  71. type = CPU_755;
  72. }
  73. break;
  74. case 0x7000:
  75. type = CPU_750FX;
  76. break;
  77. case 0x7002:
  78. type = CPU_750GX;
  79. break;
  80. case 0x800C:
  81. type = CPU_7410;
  82. break;
  83. case 0x8000:
  84. type = CPU_7450;
  85. break;
  86. case 0x8001:
  87. type = CPU_7455;
  88. break;
  89. case 0x8002:
  90. type = CPU_7457;
  91. break;
  92. case 0x8003:
  93. type = CPU_7447A;
  94. break;
  95. case 0x8004:
  96. type = CPU_7448;
  97. break;
  98. default:
  99. break;
  100. }
  101. return type;
  102. }
  103. /* ------------------------------------------------------------------------- */
  104. #if !defined(CONFIG_BAB7xx)
  105. int checkcpu (void)
  106. {
  107. uint type = get_cpu_type();
  108. uint pvr = get_pvr();
  109. ulong clock = gd->cpu_clk;
  110. char buf[32];
  111. char *str;
  112. puts ("CPU: ");
  113. switch (type) {
  114. case CPU_750CX:
  115. printf ("750CX%s v%d.%d", (pvr&0xf0)?"e":"",
  116. (pvr>>8) & 0xf,
  117. pvr & 0xf);
  118. goto PR_CLK;
  119. case CPU_750:
  120. str = "750";
  121. break;
  122. case CPU_750FX:
  123. str = "750FX";
  124. break;
  125. case CPU_750GX:
  126. str = "750GX";
  127. break;
  128. case CPU_755:
  129. str = "755";
  130. break;
  131. case CPU_7400:
  132. str = "MPC7400";
  133. break;
  134. case CPU_7410:
  135. str = "MPC7410";
  136. break;
  137. case CPU_7447A:
  138. str = "MPC7447A";
  139. break;
  140. case CPU_7448:
  141. str = "MPC7448";
  142. break;
  143. case CPU_7450:
  144. str = "MPC7450";
  145. break;
  146. case CPU_7455:
  147. str = "MPC7455";
  148. break;
  149. case CPU_7457:
  150. str = "MPC7457";
  151. break;
  152. default:
  153. printf("Unknown CPU -- PVR: 0x%08x\n", pvr);
  154. return -1;
  155. }
  156. printf ("%s v%d.%d", str, (pvr >> 8) & 0xFF, pvr & 0xFF);
  157. PR_CLK:
  158. printf (" @ %s MHz\n", strmhz(buf, clock));
  159. return (0);
  160. }
  161. #endif
  162. /* these two functions are unimplemented currently [josh] */
  163. /* -------------------------------------------------------------------- */
  164. /* L1 i-cache */
  165. int
  166. checkicache(void)
  167. {
  168. return 0; /* XXX */
  169. }
  170. /* -------------------------------------------------------------------- */
  171. /* L1 d-cache */
  172. int
  173. checkdcache(void)
  174. {
  175. return 0; /* XXX */
  176. }
  177. /* -------------------------------------------------------------------- */
  178. static inline void
  179. soft_restart(unsigned long addr)
  180. {
  181. /* SRR0 has system reset vector, SRR1 has default MSR value */
  182. /* rfi restores MSR from SRR1 and sets the PC to the SRR0 value */
  183. __asm__ __volatile__ ("mtspr 26, %0" :: "r" (addr));
  184. __asm__ __volatile__ ("li 4, (1 << 6)" ::: "r4");
  185. __asm__ __volatile__ ("mtspr 27, 4");
  186. __asm__ __volatile__ ("rfi");
  187. while(1); /* not reached */
  188. }
  189. #if !defined(CONFIG_PCIPPC2) && \
  190. !defined(CONFIG_BAB7xx) && \
  191. !defined(CONFIG_ELPPC) && \
  192. !defined(CONFIG_PPMC7XX)
  193. /* no generic way to do board reset. simply call soft_reset. */
  194. void
  195. do_reset (cmd_tbl_t *cmdtp, int flag, int argc, char *argv[])
  196. {
  197. ulong addr;
  198. /* flush and disable I/D cache */
  199. __asm__ __volatile__ ("mfspr 3, 1008" ::: "r3");
  200. __asm__ __volatile__ ("ori 5, 5, 0xcc00" ::: "r5");
  201. __asm__ __volatile__ ("ori 4, 3, 0xc00" ::: "r4");
  202. __asm__ __volatile__ ("andc 5, 3, 5" ::: "r5");
  203. __asm__ __volatile__ ("sync");
  204. __asm__ __volatile__ ("mtspr 1008, 4");
  205. __asm__ __volatile__ ("isync");
  206. __asm__ __volatile__ ("sync");
  207. __asm__ __volatile__ ("mtspr 1008, 5");
  208. __asm__ __volatile__ ("isync");
  209. __asm__ __volatile__ ("sync");
  210. #ifdef CFG_RESET_ADDRESS
  211. addr = CFG_RESET_ADDRESS;
  212. #else
  213. /*
  214. * note: when CFG_MONITOR_BASE points to a RAM address,
  215. * CFG_MONITOR_BASE - sizeof (ulong) is usually a valid
  216. * address. Better pick an address known to be invalid on your
  217. * system and assign it to CFG_RESET_ADDRESS.
  218. */
  219. addr = CFG_MONITOR_BASE - sizeof (ulong);
  220. #endif
  221. soft_restart(addr);
  222. while(1); /* not reached */
  223. }
  224. #endif
  225. /* ------------------------------------------------------------------------- */
  226. /*
  227. * For the 7400 the TB clock runs at 1/4 the cpu bus speed.
  228. */
  229. #if defined(CONFIG_AMIGAONEG3SE) || defined(CFG_CONFIG_BUS_CLK)
  230. unsigned long get_tbclk(void)
  231. {
  232. return (gd->bus_clk / 4);
  233. }
  234. #else /* ! CONFIG_AMIGAONEG3SE and !CFG_CONFIG_BUS_CLK*/
  235. unsigned long get_tbclk (void)
  236. {
  237. return CFG_BUS_HZ / 4;
  238. }
  239. #endif /* CONFIG_AMIGAONEG3SE or CFG_CONFIG_BUS_CLK*/
  240. /* ------------------------------------------------------------------------- */
  241. #if defined(CONFIG_WATCHDOG)
  242. #if !defined(CONFIG_PCIPPC2) && !defined(CONFIG_BAB7xx)
  243. void
  244. watchdog_reset(void)
  245. {
  246. }
  247. #endif /* !CONFIG_PCIPPC2 && !CONFIG_BAB7xx */
  248. #endif /* CONFIG_WATCHDOG */
  249. /* ------------------------------------------------------------------------- */
  250. #ifdef CONFIG_OF_FLAT_TREE
  251. void
  252. ft_cpu_setup (void *blob, bd_t *bd)
  253. {
  254. u32 *p;
  255. ulong clock;
  256. int len;
  257. clock = bd->bi_busfreq;
  258. p = ft_get_prop (blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  259. if (p != NULL)
  260. *p = cpu_to_be32 (clock);
  261. #if defined(CONFIG_TSI108_ETH)
  262. p = ft_get_prop (blob, "/" OF_TSI "/ethernet@6200/address", &len);
  263. memcpy (p, bd->bi_enetaddr, 6);
  264. #endif
  265. #if defined(CONFIG_HAS_ETH1)
  266. p = ft_get_prop (blob, "/" OF_TSI "/ethernet@6600/address", &len);
  267. memcpy (p, bd->bi_enet1addr, 6);
  268. #endif
  269. }
  270. #endif
  271. /* ------------------------------------------------------------------------- */