cpu.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440
  1. /*
  2. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. /*
  23. * CPU specific code for the MPC83xx family.
  24. *
  25. * Derived from the MPC8260 and MPC85xx.
  26. */
  27. #include <common.h>
  28. #include <watchdog.h>
  29. #include <command.h>
  30. #include <mpc83xx.h>
  31. #include <asm/processor.h>
  32. #include <libfdt.h>
  33. DECLARE_GLOBAL_DATA_PTR;
  34. int checkcpu(void)
  35. {
  36. volatile immap_t *immr;
  37. ulong clock = gd->cpu_clk;
  38. u32 pvr = get_pvr();
  39. u32 spridr;
  40. char buf[32];
  41. immr = (immap_t *)CFG_IMMR;
  42. puts("CPU: ");
  43. switch (pvr & 0xffff0000) {
  44. case PVR_E300C1:
  45. printf("e300c1, ");
  46. break;
  47. case PVR_E300C2:
  48. printf("e300c2, ");
  49. break;
  50. case PVR_E300C3:
  51. printf("e300c3, ");
  52. break;
  53. case PVR_E300C4:
  54. printf("e300c4, ");
  55. break;
  56. default:
  57. printf("Unknown core, ");
  58. }
  59. spridr = immr->sysconf.spridr;
  60. switch(spridr) {
  61. case SPR_8349E_REV10:
  62. case SPR_8349E_REV11:
  63. case SPR_8349E_REV31:
  64. puts("MPC8349E, ");
  65. break;
  66. case SPR_8349_REV10:
  67. case SPR_8349_REV11:
  68. case SPR_8349_REV31:
  69. puts("MPC8349, ");
  70. break;
  71. case SPR_8347E_REV10_TBGA:
  72. case SPR_8347E_REV11_TBGA:
  73. case SPR_8347E_REV31_TBGA:
  74. case SPR_8347E_REV10_PBGA:
  75. case SPR_8347E_REV11_PBGA:
  76. case SPR_8347E_REV31_PBGA:
  77. puts("MPC8347E, ");
  78. break;
  79. case SPR_8347_REV10_TBGA:
  80. case SPR_8347_REV11_TBGA:
  81. case SPR_8347_REV31_TBGA:
  82. case SPR_8347_REV10_PBGA:
  83. case SPR_8347_REV11_PBGA:
  84. case SPR_8347_REV31_PBGA:
  85. puts("MPC8347, ");
  86. break;
  87. case SPR_8343E_REV10:
  88. case SPR_8343E_REV11:
  89. case SPR_8343E_REV31:
  90. puts("MPC8343E, ");
  91. break;
  92. case SPR_8343_REV10:
  93. case SPR_8343_REV11:
  94. case SPR_8343_REV31:
  95. puts("MPC8343, ");
  96. break;
  97. case SPR_8360E_REV10:
  98. case SPR_8360E_REV11:
  99. case SPR_8360E_REV12:
  100. case SPR_8360E_REV20:
  101. case SPR_8360E_REV21:
  102. puts("MPC8360E, ");
  103. break;
  104. case SPR_8360_REV10:
  105. case SPR_8360_REV11:
  106. case SPR_8360_REV12:
  107. case SPR_8360_REV20:
  108. case SPR_8360_REV21:
  109. puts("MPC8360, ");
  110. break;
  111. case SPR_8323E_REV10:
  112. case SPR_8323E_REV11:
  113. puts("MPC8323E, ");
  114. break;
  115. case SPR_8323_REV10:
  116. case SPR_8323_REV11:
  117. puts("MPC8323, ");
  118. break;
  119. case SPR_8321E_REV10:
  120. case SPR_8321E_REV11:
  121. puts("MPC8321E, ");
  122. break;
  123. case SPR_8321_REV10:
  124. case SPR_8321_REV11:
  125. puts("MPC8321, ");
  126. break;
  127. case SPR_8311_REV10:
  128. puts("MPC8311, ");
  129. break;
  130. case SPR_8311E_REV10:
  131. puts("MPC8311E, ");
  132. break;
  133. case SPR_8313_REV10:
  134. puts("MPC8313, ");
  135. break;
  136. case SPR_8313E_REV10:
  137. puts("MPC8313E, ");
  138. break;
  139. case SPR_8315E_REV10:
  140. puts("MPC8315E, ");
  141. break;
  142. case SPR_8315_REV10:
  143. puts("MPC8315, ");
  144. break;
  145. case SPR_8314E_REV10:
  146. puts("MPC8314E, ");
  147. break;
  148. case SPR_8314_REV10:
  149. puts("MPC8314, ");
  150. break;
  151. case SPR_8379E_REV10:
  152. puts("MPC8379E, ");
  153. break;
  154. case SPR_8379_REV10:
  155. puts("MPC8379, ");
  156. break;
  157. case SPR_8378E_REV10:
  158. puts("MPC8378E, ");
  159. break;
  160. case SPR_8378_REV10:
  161. puts("MPC8378, ");
  162. break;
  163. case SPR_8377E_REV10:
  164. puts("MPC8377E, ");
  165. break;
  166. case SPR_8377_REV10:
  167. puts("MPC8377, ");
  168. break;
  169. default:
  170. printf("Rev: Unknown revision number:%08x\n"
  171. "Warning: Unsupported cpu revision!\n",spridr);
  172. return 0;
  173. }
  174. #if defined(CONFIG_MPC834X)
  175. /* Multiple revisons of 834x processors may have the same SPRIDR value.
  176. * So use PVR to identify the revision number.
  177. */
  178. printf("Rev: %02x at %s MHz", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
  179. #else
  180. printf("Rev: %02x at %s MHz", spridr & 0x0000FFFF, strmhz(buf, clock));
  181. #endif
  182. printf(", CSB: %4d MHz\n", gd->csb_clk / 1000000);
  183. return 0;
  184. }
  185. /*
  186. * Program a UPM with the code supplied in the table.
  187. *
  188. * The 'dummy' variable is used to increment the MAD. 'dummy' is
  189. * supposed to be a pointer to the memory of the device being
  190. * programmed by the UPM. The data in the MDR is written into
  191. * memory and the MAD is incremented every time there's a read
  192. * from 'dummy'. Unfortunately, the current prototype for this
  193. * function doesn't allow for passing the address of this
  194. * device, and changing the prototype will break a number lots
  195. * of other code, so we need to use a round-about way of finding
  196. * the value for 'dummy'.
  197. *
  198. * The value can be extracted from the base address bits of the
  199. * Base Register (BR) associated with the specific UPM. To find
  200. * that BR, we need to scan all 8 BRs until we find the one that
  201. * has its MSEL bits matching the UPM we want. Once we know the
  202. * right BR, we can extract the base address bits from it.
  203. *
  204. * The MxMR and the BR and OR of the chosen bank should all be
  205. * configured before calling this function.
  206. *
  207. * Parameters:
  208. * upm: 0=UPMA, 1=UPMB, 2=UPMC
  209. * table: Pointer to an array of values to program
  210. * size: Number of elements in the array. Must be 64 or less.
  211. */
  212. void upmconfig (uint upm, uint *table, uint size)
  213. {
  214. #if defined(CONFIG_MPC834X)
  215. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  216. volatile lbus83xx_t *lbus = &immap->lbus;
  217. volatile uchar *dummy = NULL;
  218. const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
  219. volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
  220. uint i;
  221. /* Scan all the banks to determine the base address of the device */
  222. for (i = 0; i < 8; i++) {
  223. if ((lbus->bank[i].br & BR_MSEL) == msel) {
  224. dummy = (uchar *) (lbus->bank[i].br & BR_BA);
  225. break;
  226. }
  227. }
  228. if (!dummy) {
  229. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  230. hang();
  231. }
  232. /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
  233. *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
  234. for (i = 0; i < size; i++) {
  235. lbus->mdr = table[i];
  236. __asm__ __volatile__ ("sync");
  237. *dummy; /* Write the value to memory and increment MAD */
  238. __asm__ __volatile__ ("sync");
  239. }
  240. /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
  241. *mxmr &= 0xCFFFFFC0;
  242. #else
  243. printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
  244. hang();
  245. #endif
  246. }
  247. int
  248. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  249. {
  250. ulong msr;
  251. #ifndef MPC83xx_RESET
  252. ulong addr;
  253. #endif
  254. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  255. #ifdef MPC83xx_RESET
  256. /* Interrupts and MMU off */
  257. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  258. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  259. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  260. /* enable Reset Control Reg */
  261. immap->reset.rpr = 0x52535445;
  262. __asm__ __volatile__ ("sync");
  263. __asm__ __volatile__ ("isync");
  264. /* confirm Reset Control Reg is enabled */
  265. while(!((immap->reset.rcer) & RCER_CRE));
  266. printf("Resetting the board.");
  267. printf("\n");
  268. udelay(200);
  269. /* perform reset, only one bit */
  270. immap->reset.rcr = RCR_SWHR;
  271. #else /* ! MPC83xx_RESET */
  272. immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
  273. /* Interrupts and MMU off */
  274. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  275. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  276. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  277. /*
  278. * Trying to execute the next instruction at a non-existing address
  279. * should cause a machine check, resulting in reset
  280. */
  281. addr = CFG_RESET_ADDRESS;
  282. printf("resetting the board.");
  283. printf("\n");
  284. ((void (*)(void)) addr) ();
  285. #endif /* MPC83xx_RESET */
  286. return 1;
  287. }
  288. /*
  289. * Get timebase clock frequency (like cpu_clk in Hz)
  290. */
  291. unsigned long get_tbclk(void)
  292. {
  293. ulong tbclk;
  294. tbclk = (gd->bus_clk + 3L) / 4L;
  295. return tbclk;
  296. }
  297. #if defined(CONFIG_WATCHDOG)
  298. void watchdog_reset (void)
  299. {
  300. int re_enable = disable_interrupts();
  301. /* Reset the 83xx watchdog */
  302. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  303. immr->wdt.swsrr = 0x556c;
  304. immr->wdt.swsrr = 0xaa39;
  305. if (re_enable)
  306. enable_interrupts ();
  307. }
  308. #endif
  309. #if defined(CONFIG_DDR_ECC)
  310. void dma_init(void)
  311. {
  312. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  313. volatile dma83xx_t *dma = &immap->dma;
  314. volatile u32 status = swab32(dma->dmasr0);
  315. volatile u32 dmamr0 = swab32(dma->dmamr0);
  316. debug("DMA-init\n");
  317. /* initialize DMASARn, DMADAR and DMAABCRn */
  318. dma->dmadar0 = (u32)0;
  319. dma->dmasar0 = (u32)0;
  320. dma->dmabcr0 = 0;
  321. __asm__ __volatile__ ("sync");
  322. __asm__ __volatile__ ("isync");
  323. /* clear CS bit */
  324. dmamr0 &= ~DMA_CHANNEL_START;
  325. dma->dmamr0 = swab32(dmamr0);
  326. __asm__ __volatile__ ("sync");
  327. __asm__ __volatile__ ("isync");
  328. /* while the channel is busy, spin */
  329. while(status & DMA_CHANNEL_BUSY) {
  330. status = swab32(dma->dmasr0);
  331. }
  332. debug("DMA-init end\n");
  333. }
  334. uint dma_check(void)
  335. {
  336. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  337. volatile dma83xx_t *dma = &immap->dma;
  338. volatile u32 status = swab32(dma->dmasr0);
  339. volatile u32 byte_count = swab32(dma->dmabcr0);
  340. /* while the channel is busy, spin */
  341. while (status & DMA_CHANNEL_BUSY) {
  342. status = swab32(dma->dmasr0);
  343. }
  344. if (status & DMA_CHANNEL_TRANSFER_ERROR) {
  345. printf ("DMA Error: status = %x @ %d\n", status, byte_count);
  346. }
  347. return status;
  348. }
  349. int dma_xfer(void *dest, u32 count, void *src)
  350. {
  351. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  352. volatile dma83xx_t *dma = &immap->dma;
  353. volatile u32 dmamr0;
  354. /* initialize DMASARn, DMADAR and DMAABCRn */
  355. dma->dmadar0 = swab32((u32)dest);
  356. dma->dmasar0 = swab32((u32)src);
  357. dma->dmabcr0 = swab32(count);
  358. __asm__ __volatile__ ("sync");
  359. __asm__ __volatile__ ("isync");
  360. /* init direct transfer, clear CS bit */
  361. dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
  362. DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
  363. DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
  364. dma->dmamr0 = swab32(dmamr0);
  365. __asm__ __volatile__ ("sync");
  366. __asm__ __volatile__ ("isync");
  367. /* set CS to start DMA transfer */
  368. dmamr0 |= DMA_CHANNEL_START;
  369. dma->dmamr0 = swab32(dmamr0);
  370. __asm__ __volatile__ ("sync");
  371. __asm__ __volatile__ ("isync");
  372. return ((int)dma_check());
  373. }
  374. #endif /*CONFIG_DDR_ECC*/