cpu.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Copyright (C) 2004-2006 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 <ft_build.h>
  32. #include <asm/processor.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. if ((pvr & 0xFFFF0000) != PVR_83xx) {
  43. puts("Not MPC83xx Family!!!\n");
  44. return -1;
  45. }
  46. spridr = immr->sysconf.spridr;
  47. puts("CPU: ");
  48. switch(spridr) {
  49. case SPR_8349E_REV10:
  50. case SPR_8349E_REV11:
  51. case SPR_8349E_REV31:
  52. puts("MPC8349E, ");
  53. break;
  54. case SPR_8349_REV10:
  55. case SPR_8349_REV11:
  56. case SPR_8349_REV31:
  57. puts("MPC8349, ");
  58. break;
  59. case SPR_8347E_REV10_TBGA:
  60. case SPR_8347E_REV11_TBGA:
  61. case SPR_8347E_REV31_TBGA:
  62. case SPR_8347E_REV10_PBGA:
  63. case SPR_8347E_REV11_PBGA:
  64. case SPR_8347E_REV31_PBGA:
  65. puts("MPC8347E, ");
  66. break;
  67. case SPR_8347_REV10_TBGA:
  68. case SPR_8347_REV11_TBGA:
  69. case SPR_8347_REV31_TBGA:
  70. case SPR_8347_REV10_PBGA:
  71. case SPR_8347_REV11_PBGA:
  72. case SPR_8347_REV31_PBGA:
  73. puts("MPC8347, ");
  74. break;
  75. case SPR_8343E_REV10:
  76. case SPR_8343E_REV11:
  77. case SPR_8343E_REV31:
  78. puts("MPC8343E, ");
  79. break;
  80. case SPR_8343_REV10:
  81. case SPR_8343_REV11:
  82. case SPR_8343_REV31:
  83. puts("MPC8343, ");
  84. break;
  85. case SPR_8360E_REV10:
  86. case SPR_8360E_REV11:
  87. case SPR_8360E_REV12:
  88. case SPR_8360E_REV20:
  89. puts("MPC8360E, ");
  90. break;
  91. case SPR_8360_REV10:
  92. case SPR_8360_REV11:
  93. case SPR_8360_REV12:
  94. case SPR_8360_REV20:
  95. puts("MPC8360, ");
  96. break;
  97. case SPR_8323E_REV10:
  98. case SPR_8323E_REV11:
  99. puts("MPC8323E, ");
  100. break;
  101. case SPR_8323_REV10:
  102. case SPR_8323_REV11:
  103. puts("MPC8323, ");
  104. break;
  105. case SPR_8321E_REV10:
  106. case SPR_8321E_REV11:
  107. puts("MPC8321E, ");
  108. break;
  109. case SPR_8321_REV10:
  110. case SPR_8321_REV11:
  111. puts("MPC8321, ");
  112. break;
  113. default:
  114. puts("Rev: Unknown revision number.\nWarning: Unsupported cpu revision!\n");
  115. return 0;
  116. }
  117. #if defined(CONFIG_MPC834X)
  118. /* Multiple revisons of 834x processors may have the same SPRIDR value.
  119. * So use PVR to identify the revision number.
  120. */
  121. printf("Rev: %02x at %s MHz\n", PVR_MAJ(pvr)<<4 | PVR_MIN(pvr), strmhz(buf, clock));
  122. #else
  123. printf("Rev: %02x at %s MHz\n", spridr & 0x0000FFFF, strmhz(buf, clock));
  124. #endif
  125. return 0;
  126. }
  127. /*
  128. * Program a UPM with the code supplied in the table.
  129. *
  130. * The 'dummy' variable is used to increment the MAD. 'dummy' is
  131. * supposed to be a pointer to the memory of the device being
  132. * programmed by the UPM. The data in the MDR is written into
  133. * memory and the MAD is incremented every time there's a read
  134. * from 'dummy'. Unfortunately, the current prototype for this
  135. * function doesn't allow for passing the address of this
  136. * device, and changing the prototype will break a number lots
  137. * of other code, so we need to use a round-about way of finding
  138. * the value for 'dummy'.
  139. *
  140. * The value can be extracted from the base address bits of the
  141. * Base Register (BR) associated with the specific UPM. To find
  142. * that BR, we need to scan all 8 BRs until we find the one that
  143. * has its MSEL bits matching the UPM we want. Once we know the
  144. * right BR, we can extract the base address bits from it.
  145. *
  146. * The MxMR and the BR and OR of the chosen bank should all be
  147. * configured before calling this function.
  148. *
  149. * Parameters:
  150. * upm: 0=UPMA, 1=UPMB, 2=UPMC
  151. * table: Pointer to an array of values to program
  152. * size: Number of elements in the array. Must be 64 or less.
  153. */
  154. void upmconfig (uint upm, uint *table, uint size)
  155. {
  156. #if defined(CONFIG_MPC834X)
  157. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  158. volatile lbus83xx_t *lbus = &immap->lbus;
  159. volatile uchar *dummy = NULL;
  160. const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
  161. volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
  162. uint i;
  163. /* Scan all the banks to determine the base address of the device */
  164. for (i = 0; i < 8; i++) {
  165. if ((lbus->bank[i].br & BR_MSEL) == msel) {
  166. dummy = (uchar *) (lbus->bank[i].br & BR_BA);
  167. break;
  168. }
  169. }
  170. if (!dummy) {
  171. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  172. hang();
  173. }
  174. /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
  175. *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
  176. for (i = 0; i < size; i++) {
  177. lbus->mdr = table[i];
  178. __asm__ __volatile__ ("sync");
  179. *dummy; /* Write the value to memory and increment MAD */
  180. __asm__ __volatile__ ("sync");
  181. }
  182. /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
  183. *mxmr &= 0xCFFFFFC0;
  184. #else
  185. printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
  186. hang();
  187. #endif
  188. }
  189. int
  190. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  191. {
  192. ulong msr;
  193. #ifndef MPC83xx_RESET
  194. ulong addr;
  195. #endif
  196. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  197. #ifdef MPC83xx_RESET
  198. /* Interrupts and MMU off */
  199. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  200. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  201. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  202. /* enable Reset Control Reg */
  203. immap->reset.rpr = 0x52535445;
  204. __asm__ __volatile__ ("sync");
  205. __asm__ __volatile__ ("isync");
  206. /* confirm Reset Control Reg is enabled */
  207. while(!((immap->reset.rcer) & RCER_CRE));
  208. printf("Resetting the board.");
  209. printf("\n");
  210. udelay(200);
  211. /* perform reset, only one bit */
  212. immap->reset.rcr = RCR_SWHR;
  213. #else /* ! MPC83xx_RESET */
  214. immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
  215. /* Interrupts and MMU off */
  216. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  217. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  218. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  219. /*
  220. * Trying to execute the next instruction at a non-existing address
  221. * should cause a machine check, resulting in reset
  222. */
  223. addr = CFG_RESET_ADDRESS;
  224. printf("resetting the board.");
  225. printf("\n");
  226. ((void (*)(void)) addr) ();
  227. #endif /* MPC83xx_RESET */
  228. return 1;
  229. }
  230. /*
  231. * Get timebase clock frequency (like cpu_clk in Hz)
  232. */
  233. unsigned long get_tbclk(void)
  234. {
  235. ulong tbclk;
  236. tbclk = (gd->bus_clk + 3L) / 4L;
  237. return tbclk;
  238. }
  239. #if defined(CONFIG_WATCHDOG)
  240. void watchdog_reset (void)
  241. {
  242. int re_enable = disable_interrupts();
  243. /* Reset the 83xx watchdog */
  244. volatile immap_t *immr = (immap_t *) CFG_IMMR;
  245. immr->wdt.swsrr = 0x556c;
  246. immr->wdt.swsrr = 0xaa39;
  247. if (re_enable)
  248. enable_interrupts ();
  249. }
  250. #endif
  251. #if defined(CONFIG_OF_FLAT_TREE)
  252. void
  253. ft_cpu_setup(void *blob, bd_t *bd)
  254. {
  255. u32 *p;
  256. int len;
  257. ulong clock;
  258. clock = bd->bi_busfreq;
  259. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  260. if (p != NULL)
  261. *p = cpu_to_be32(clock);
  262. p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
  263. if (p != NULL)
  264. *p = cpu_to_be32(clock);
  265. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  266. if (p != NULL)
  267. *p = cpu_to_be32(clock);
  268. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  269. if (p != NULL)
  270. *p = cpu_to_be32(clock);
  271. #ifdef CONFIG_MPC83XX_TSEC1
  272. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/mac-address", &len);
  273. if (p != NULL)
  274. memcpy(p, bd->bi_enetaddr, 6);
  275. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/local-mac-address", &len);
  276. if (p != NULL)
  277. memcpy(p, bd->bi_enetaddr, 6);
  278. #endif
  279. #ifdef CONFIG_MPC83XX_TSEC2
  280. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/mac-address", &len);
  281. if (p != NULL)
  282. memcpy(p, bd->bi_enet1addr, 6);
  283. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/local-mac-address", &len);
  284. if (p != NULL)
  285. memcpy(p, bd->bi_enet1addr, 6);
  286. #endif
  287. #ifdef CONFIG_UEC_ETH1
  288. #if CFG_UEC1_UCC_NUM == 0 /* UCC1 */
  289. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/mac-address", &len);
  290. if (p != NULL)
  291. memcpy(p, bd->bi_enetaddr, 6);
  292. p = ft_get_prop(blob, "/" OF_QE "/ucc@2000/local-mac-address", &len);
  293. if (p != NULL)
  294. memcpy(p, bd->bi_enetaddr, 6);
  295. #elif CFG_UEC1_UCC_NUM == 2 /* UCC3 */
  296. p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/mac-address", &len);
  297. if (p != NULL)
  298. memcpy(p, bd->bi_enetaddr, 6);
  299. p = ft_get_prop(blob, "/" OF_QE "/ucc@2200/local-mac-address", &len);
  300. if (p != NULL)
  301. memcpy(p, bd->bi_enetaddr, 6);
  302. #endif
  303. #endif
  304. #ifdef CONFIG_UEC_ETH2
  305. #if CFG_UEC2_UCC_NUM == 1 /* UCC2 */
  306. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/mac-address", &len);
  307. if (p != NULL)
  308. memcpy(p, bd->bi_enet1addr, 6);
  309. p = ft_get_prop(blob, "/" OF_QE "/ucc@3000/local-mac-address", &len);
  310. if (p != NULL)
  311. memcpy(p, bd->bi_enet1addr, 6);
  312. #elif CFG_UEC2_UCC_NUM == 3 /* UCC4 */
  313. p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/mac-address", &len);
  314. if (p != NULL)
  315. memcpy(p, bd->bi_enet1addr, 6);
  316. p = ft_get_prop(blob, "/" OF_QE "/ucc@3200/local-mac-address", &len);
  317. if (p != NULL)
  318. memcpy(p, bd->bi_enet1addr, 6);
  319. #endif
  320. #endif
  321. }
  322. #endif
  323. #if defined(CONFIG_DDR_ECC)
  324. void dma_init(void)
  325. {
  326. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  327. volatile dma83xx_t *dma = &immap->dma;
  328. volatile u32 status = swab32(dma->dmasr0);
  329. volatile u32 dmamr0 = swab32(dma->dmamr0);
  330. debug("DMA-init\n");
  331. /* initialize DMASARn, DMADAR and DMAABCRn */
  332. dma->dmadar0 = (u32)0;
  333. dma->dmasar0 = (u32)0;
  334. dma->dmabcr0 = 0;
  335. __asm__ __volatile__ ("sync");
  336. __asm__ __volatile__ ("isync");
  337. /* clear CS bit */
  338. dmamr0 &= ~DMA_CHANNEL_START;
  339. dma->dmamr0 = swab32(dmamr0);
  340. __asm__ __volatile__ ("sync");
  341. __asm__ __volatile__ ("isync");
  342. /* while the channel is busy, spin */
  343. while(status & DMA_CHANNEL_BUSY) {
  344. status = swab32(dma->dmasr0);
  345. }
  346. debug("DMA-init end\n");
  347. }
  348. uint dma_check(void)
  349. {
  350. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  351. volatile dma83xx_t *dma = &immap->dma;
  352. volatile u32 status = swab32(dma->dmasr0);
  353. volatile u32 byte_count = swab32(dma->dmabcr0);
  354. /* while the channel is busy, spin */
  355. while (status & DMA_CHANNEL_BUSY) {
  356. status = swab32(dma->dmasr0);
  357. }
  358. if (status & DMA_CHANNEL_TRANSFER_ERROR) {
  359. printf ("DMA Error: status = %x @ %d\n", status, byte_count);
  360. }
  361. return status;
  362. }
  363. int dma_xfer(void *dest, u32 count, void *src)
  364. {
  365. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  366. volatile dma83xx_t *dma = &immap->dma;
  367. volatile u32 dmamr0;
  368. /* initialize DMASARn, DMADAR and DMAABCRn */
  369. dma->dmadar0 = swab32((u32)dest);
  370. dma->dmasar0 = swab32((u32)src);
  371. dma->dmabcr0 = swab32(count);
  372. __asm__ __volatile__ ("sync");
  373. __asm__ __volatile__ ("isync");
  374. /* init direct transfer, clear CS bit */
  375. dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
  376. DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
  377. DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
  378. dma->dmamr0 = swab32(dmamr0);
  379. __asm__ __volatile__ ("sync");
  380. __asm__ __volatile__ ("isync");
  381. /* set CS to start DMA transfer */
  382. dmamr0 |= DMA_CHANNEL_START;
  383. dma->dmamr0 = swab32(dmamr0);
  384. __asm__ __volatile__ ("sync");
  385. __asm__ __volatile__ ("isync");
  386. return ((int)dma_check());
  387. }
  388. #endif /*CONFIG_DDR_ECC*/