cpu.c 9.6 KB

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