cpu.c 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. #include <tsec.h>
  34. DECLARE_GLOBAL_DATA_PTR;
  35. int checkcpu(void)
  36. {
  37. volatile immap_t *immr;
  38. ulong clock = gd->cpu_clk;
  39. u32 pvr = get_pvr();
  40. u32 spridr;
  41. char buf[32];
  42. int i;
  43. const struct cpu_type {
  44. char name[15];
  45. u32 partid;
  46. } cpu_type_list [] = {
  47. CPU_TYPE_ENTRY(8311),
  48. CPU_TYPE_ENTRY(8313),
  49. CPU_TYPE_ENTRY(8314),
  50. CPU_TYPE_ENTRY(8315),
  51. CPU_TYPE_ENTRY(8321),
  52. CPU_TYPE_ENTRY(8323),
  53. CPU_TYPE_ENTRY(8343),
  54. CPU_TYPE_ENTRY(8347_TBGA_),
  55. CPU_TYPE_ENTRY(8347_PBGA_),
  56. CPU_TYPE_ENTRY(8349),
  57. CPU_TYPE_ENTRY(8358_TBGA_),
  58. CPU_TYPE_ENTRY(8358_PBGA_),
  59. CPU_TYPE_ENTRY(8360),
  60. CPU_TYPE_ENTRY(8377),
  61. CPU_TYPE_ENTRY(8378),
  62. CPU_TYPE_ENTRY(8379),
  63. };
  64. immr = (immap_t *)CFG_IMMR;
  65. puts("CPU: ");
  66. switch (pvr & 0xffff0000) {
  67. case PVR_E300C1:
  68. printf("e300c1, ");
  69. break;
  70. case PVR_E300C2:
  71. printf("e300c2, ");
  72. break;
  73. case PVR_E300C3:
  74. printf("e300c3, ");
  75. break;
  76. case PVR_E300C4:
  77. printf("e300c4, ");
  78. break;
  79. default:
  80. printf("Unknown core, ");
  81. }
  82. spridr = immr->sysconf.spridr;
  83. for (i = 0; i < ARRAY_SIZE(cpu_type_list); i++)
  84. if (cpu_type_list[i].partid == PARTID_NO_E(spridr)) {
  85. puts("MPC");
  86. puts(cpu_type_list[i].name);
  87. if (IS_E_PROCESSOR(spridr))
  88. puts("E");
  89. if (REVID_MAJOR(spridr) >= 2)
  90. puts("A");
  91. printf(", Rev: %d.%d", REVID_MAJOR(spridr),
  92. REVID_MINOR(spridr));
  93. break;
  94. }
  95. if (i == ARRAY_SIZE(cpu_type_list))
  96. printf("(SPRIDR %08x unknown), ", spridr);
  97. printf(" at %s MHz, ", strmhz(buf, clock));
  98. printf("CSB: %s MHz\n", strmhz(buf, gd->csb_clk));
  99. return 0;
  100. }
  101. /*
  102. * Program a UPM with the code supplied in the table.
  103. *
  104. * The 'dummy' variable is used to increment the MAD. 'dummy' is
  105. * supposed to be a pointer to the memory of the device being
  106. * programmed by the UPM. The data in the MDR is written into
  107. * memory and the MAD is incremented every time there's a write
  108. * to 'dummy'. Unfortunately, the current prototype for this
  109. * function doesn't allow for passing the address of this
  110. * device, and changing the prototype will break a number lots
  111. * of other code, so we need to use a round-about way of finding
  112. * the value for 'dummy'.
  113. *
  114. * The value can be extracted from the base address bits of the
  115. * Base Register (BR) associated with the specific UPM. To find
  116. * that BR, we need to scan all 8 BRs until we find the one that
  117. * has its MSEL bits matching the UPM we want. Once we know the
  118. * right BR, we can extract the base address bits from it.
  119. *
  120. * The MxMR and the BR and OR of the chosen bank should all be
  121. * configured before calling this function.
  122. *
  123. * Parameters:
  124. * upm: 0=UPMA, 1=UPMB, 2=UPMC
  125. * table: Pointer to an array of values to program
  126. * size: Number of elements in the array. Must be 64 or less.
  127. */
  128. void upmconfig (uint upm, uint *table, uint size)
  129. {
  130. #if defined(CONFIG_MPC834X)
  131. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  132. volatile lbus83xx_t *lbus = &immap->lbus;
  133. volatile uchar *dummy = NULL;
  134. const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
  135. volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
  136. uint i;
  137. /* Scan all the banks to determine the base address of the device */
  138. for (i = 0; i < 8; i++) {
  139. if ((lbus->bank[i].br & BR_MSEL) == msel) {
  140. dummy = (uchar *) (lbus->bank[i].br & BR_BA);
  141. break;
  142. }
  143. }
  144. if (!dummy) {
  145. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  146. hang();
  147. }
  148. /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
  149. *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
  150. for (i = 0; i < size; i++) {
  151. lbus->mdr = table[i];
  152. __asm__ __volatile__ ("sync");
  153. *dummy = 0; /* Write the value to memory and increment MAD */
  154. __asm__ __volatile__ ("sync");
  155. while(((*mxmr & 0x3f) != ((i + 1) & 0x3f)));
  156. }
  157. /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
  158. *mxmr &= 0xCFFFFFC0;
  159. #else
  160. printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
  161. hang();
  162. #endif
  163. }
  164. int
  165. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  166. {
  167. ulong msr;
  168. #ifndef MPC83xx_RESET
  169. ulong addr;
  170. #endif
  171. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  172. #ifdef MPC83xx_RESET
  173. /* Interrupts and MMU off */
  174. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  175. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  176. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  177. /* enable Reset Control Reg */
  178. immap->reset.rpr = 0x52535445;
  179. __asm__ __volatile__ ("sync");
  180. __asm__ __volatile__ ("isync");
  181. /* confirm Reset Control Reg is enabled */
  182. while(!((immap->reset.rcer) & RCER_CRE));
  183. printf("Resetting the board.");
  184. printf("\n");
  185. udelay(200);
  186. /* perform reset, only one bit */
  187. immap->reset.rcr = RCR_SWHR;
  188. #else /* ! MPC83xx_RESET */
  189. immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
  190. /* Interrupts and MMU off */
  191. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  192. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  193. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  194. /*
  195. * Trying to execute the next instruction at a non-existing address
  196. * should cause a machine check, resulting in reset
  197. */
  198. addr = CFG_RESET_ADDRESS;
  199. printf("resetting the board.");
  200. printf("\n");
  201. ((void (*)(void)) addr) ();
  202. #endif /* MPC83xx_RESET */
  203. return 1;
  204. }
  205. /*
  206. * Get timebase clock frequency (like cpu_clk in Hz)
  207. */
  208. unsigned long get_tbclk(void)
  209. {
  210. ulong tbclk;
  211. tbclk = (gd->bus_clk + 3L) / 4L;
  212. return tbclk;
  213. }
  214. #if defined(CONFIG_WATCHDOG)
  215. void watchdog_reset (void)
  216. {
  217. int re_enable = disable_interrupts();
  218. /* Reset the 83xx watchdog */
  219. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  220. immr->wdt.swsrr = 0x556c;
  221. immr->wdt.swsrr = 0xaa39;
  222. if (re_enable)
  223. enable_interrupts ();
  224. }
  225. #endif
  226. #if defined(CONFIG_DDR_ECC)
  227. void dma_init(void)
  228. {
  229. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  230. volatile dma83xx_t *dma = &immap->dma;
  231. volatile u32 status = swab32(dma->dmasr0);
  232. volatile u32 dmamr0 = swab32(dma->dmamr0);
  233. debug("DMA-init\n");
  234. /* initialize DMASARn, DMADAR and DMAABCRn */
  235. dma->dmadar0 = (u32)0;
  236. dma->dmasar0 = (u32)0;
  237. dma->dmabcr0 = 0;
  238. __asm__ __volatile__ ("sync");
  239. __asm__ __volatile__ ("isync");
  240. /* clear CS bit */
  241. dmamr0 &= ~DMA_CHANNEL_START;
  242. dma->dmamr0 = swab32(dmamr0);
  243. __asm__ __volatile__ ("sync");
  244. __asm__ __volatile__ ("isync");
  245. /* while the channel is busy, spin */
  246. while(status & DMA_CHANNEL_BUSY) {
  247. status = swab32(dma->dmasr0);
  248. }
  249. debug("DMA-init end\n");
  250. }
  251. uint dma_check(void)
  252. {
  253. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  254. volatile dma83xx_t *dma = &immap->dma;
  255. volatile u32 status = swab32(dma->dmasr0);
  256. volatile u32 byte_count = swab32(dma->dmabcr0);
  257. /* while the channel is busy, spin */
  258. while (status & DMA_CHANNEL_BUSY) {
  259. status = swab32(dma->dmasr0);
  260. }
  261. if (status & DMA_CHANNEL_TRANSFER_ERROR) {
  262. printf ("DMA Error: status = %x @ %d\n", status, byte_count);
  263. }
  264. return status;
  265. }
  266. int dma_xfer(void *dest, u32 count, void *src)
  267. {
  268. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  269. volatile dma83xx_t *dma = &immap->dma;
  270. volatile u32 dmamr0;
  271. /* initialize DMASARn, DMADAR and DMAABCRn */
  272. dma->dmadar0 = swab32((u32)dest);
  273. dma->dmasar0 = swab32((u32)src);
  274. dma->dmabcr0 = swab32(count);
  275. __asm__ __volatile__ ("sync");
  276. __asm__ __volatile__ ("isync");
  277. /* init direct transfer, clear CS bit */
  278. dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
  279. DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
  280. DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
  281. dma->dmamr0 = swab32(dmamr0);
  282. __asm__ __volatile__ ("sync");
  283. __asm__ __volatile__ ("isync");
  284. /* set CS to start DMA transfer */
  285. dmamr0 |= DMA_CHANNEL_START;
  286. dma->dmamr0 = swab32(dmamr0);
  287. __asm__ __volatile__ ("sync");
  288. __asm__ __volatile__ ("isync");
  289. return ((int)dma_check());
  290. }
  291. #endif /*CONFIG_DDR_ECC*/
  292. /*
  293. * Initializes on-chip ethernet controllers.
  294. * to override, implement board_eth_init()
  295. */
  296. int cpu_eth_init(bd_t *bis)
  297. {
  298. #if defined(CONFIG_TSEC_ENET)
  299. tsec_standard_init(bis);
  300. #endif
  301. return 0;
  302. }