cpu.c 9.8 KB

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