cpu.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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. * Change log:
  23. *
  24. * 20050101: Eran Liberty (liberty@freescale.com)
  25. * Initial file creating (porting from 85XX & 8260)
  26. */
  27. /*
  28. * CPU specific code for the MPC83xx family.
  29. *
  30. * Derived from the MPC8260 and MPC85xx.
  31. */
  32. #include <common.h>
  33. #include <watchdog.h>
  34. #include <command.h>
  35. #include <mpc83xx.h>
  36. #include <ft_build.h>
  37. #include <asm/processor.h>
  38. DECLARE_GLOBAL_DATA_PTR;
  39. int checkcpu(void)
  40. {
  41. ulong clock = gd->cpu_clk;
  42. u32 pvr = get_pvr();
  43. char buf[32];
  44. if ((pvr & 0xFFFF0000) != PVR_83xx) {
  45. puts("Not MPC83xx Family!!!\n");
  46. return -1;
  47. }
  48. puts("CPU: MPC83xx, ");
  49. switch(pvr) {
  50. case PVR_8349_REV10:
  51. break;
  52. case PVR_8349_REV11:
  53. break;
  54. default:
  55. puts("Rev: Unknown\n");
  56. return -1; /* Not sure what this is */
  57. }
  58. printf("Rev: %d.%d at %s MHz\n", (pvr & 0xf0) >> 4,
  59. (pvr & 0x0f), strmhz(buf, clock));
  60. return 0;
  61. }
  62. /**
  63. * Program a UPM with the code supplied in the table.
  64. *
  65. * The 'dummy' variable is used to increment the MAD. 'dummy' is
  66. * supposed to be a pointer to the memory of the device being
  67. * programmed by the UPM. The data in the MDR is written into
  68. * memory and the MAD is incremented every time there's a read
  69. * from 'dummy'. Unfortunately, the current prototype for this
  70. * function doesn't allow for passing the address of this
  71. * device, and changing the prototype will break a number lots
  72. * of other code, so we need to use a round-about way of finding
  73. * the value for 'dummy'.
  74. *
  75. * The value can be extracted from the base address bits of the
  76. * Base Register (BR) associated with the specific UPM. To find
  77. * that BR, we need to scan all 8 BRs until we find the one that
  78. * has its MSEL bits matching the UPM we want. Once we know the
  79. * right BR, we can extract the base address bits from it.
  80. *
  81. * The MxMR and the BR and OR of the chosen bank should all be
  82. * configured before calling this function.
  83. *
  84. * Parameters:
  85. * upm: 0=UPMA, 1=UPMB, 2=UPMC
  86. * table: Pointer to an array of values to program
  87. * size: Number of elements in the array. Must be 64 or less.
  88. */
  89. void upmconfig (uint upm, uint *table, uint size)
  90. {
  91. #if defined(CONFIG_MPC834X)
  92. volatile immap_t *immap = (immap_t *) CFG_IMMRBAR;
  93. volatile lbus83xx_t *lbus = &immap->lbus;
  94. volatile uchar *dummy = NULL;
  95. const u32 msel = (upm + 4) << BR_MSEL_SHIFT; /* What the MSEL field in BRn should be */
  96. volatile u32 *mxmr = &lbus->mamr + upm; /* Pointer to mamr, mbmr, or mcmr */
  97. uint i;
  98. /* Scan all the banks to determine the base address of the device */
  99. for (i = 0; i < 8; i++) {
  100. if ((lbus->bank[i].br & BR_MSEL) == msel) {
  101. dummy = (uchar *) (lbus->bank[i].br & BR_BA);
  102. break;
  103. }
  104. }
  105. if (!dummy) {
  106. printf("Error: %s() could not find matching BR\n", __FUNCTION__);
  107. hang();
  108. }
  109. /* Set the OP field in the MxMR to "write" and the MAD field to 000000 */
  110. *mxmr = (*mxmr & 0xCFFFFFC0) | 0x10000000;
  111. for (i = 0; i < size; i++) {
  112. lbus->mdr = table[i];
  113. __asm__ __volatile__ ("sync");
  114. *dummy; /* Write the value to memory and increment MAD */
  115. __asm__ __volatile__ ("sync");
  116. }
  117. /* Set the OP field in the MxMR to "normal" and the MAD field to 000000 */
  118. *mxmr &= 0xCFFFFFC0;
  119. #else
  120. printf("Error: %s() not defined for this configuration.\n", __FUNCTION__);
  121. hang();
  122. #endif
  123. }
  124. int
  125. do_reset (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  126. {
  127. ulong msr;
  128. #ifndef MPC83xx_RESET
  129. ulong addr;
  130. #endif
  131. volatile immap_t *immap = (immap_t *) CFG_IMMRBAR;
  132. #ifdef MPC83xx_RESET
  133. /* Interrupts and MMU off */
  134. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  135. msr &= ~( MSR_EE | MSR_IR | MSR_DR);
  136. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  137. /* enable Reset Control Reg */
  138. immap->reset.rpr = 0x52535445;
  139. __asm__ __volatile__ ("sync");
  140. __asm__ __volatile__ ("isync");
  141. /* confirm Reset Control Reg is enabled */
  142. while(!((immap->reset.rcer) & RCER_CRE));
  143. printf("Resetting the board.");
  144. printf("\n");
  145. udelay(200);
  146. /* perform reset, only one bit */
  147. immap->reset.rcr = RCR_SWHR;
  148. #else /* ! MPC83xx_RESET */
  149. immap->reset.rmr = RMR_CSRE; /* Checkstop Reset enable */
  150. /* Interrupts and MMU off */
  151. __asm__ __volatile__ ("mfmsr %0":"=r" (msr):);
  152. msr &= ~(MSR_ME | MSR_EE | MSR_IR | MSR_DR);
  153. __asm__ __volatile__ ("mtmsr %0"::"r" (msr));
  154. /*
  155. * Trying to execute the next instruction at a non-existing address
  156. * should cause a machine check, resulting in reset
  157. */
  158. addr = CFG_RESET_ADDRESS;
  159. printf("resetting the board.");
  160. printf("\n");
  161. ((void (*)(void)) addr) ();
  162. #endif /* MPC83xx_RESET */
  163. return 1;
  164. }
  165. /*
  166. * Get timebase clock frequency (like cpu_clk in Hz)
  167. */
  168. unsigned long get_tbclk(void)
  169. {
  170. ulong tbclk;
  171. tbclk = (gd->bus_clk + 3L) / 4L;
  172. return tbclk;
  173. }
  174. #if defined(CONFIG_WATCHDOG)
  175. void watchdog_reset (void)
  176. {
  177. #ifdef CONFIG_MPC834X
  178. int re_enable = disable_interrupts();
  179. /* Reset the 83xx watchdog */
  180. volatile immap_t *immr = (immap_t *) CFG_IMMRBAR;
  181. immr->wdt.swsrr = 0x556c;
  182. immr->wdt.swsrr = 0xaa39;
  183. if (re_enable)
  184. enable_interrupts ();
  185. #else
  186. hang();
  187. #endif
  188. }
  189. #endif
  190. #if defined(CONFIG_OF_FLAT_TREE)
  191. void
  192. ft_cpu_setup(void *blob, bd_t *bd)
  193. {
  194. u32 *p;
  195. int len;
  196. ulong clock;
  197. clock = bd->bi_busfreq;
  198. p = ft_get_prop(blob, "/cpus/" OF_CPU "/bus-frequency", &len);
  199. if (p != NULL)
  200. *p = cpu_to_be32(clock);
  201. p = ft_get_prop(blob, "/" OF_SOC "/bus-frequency", &len);
  202. if (p != NULL)
  203. *p = cpu_to_be32(clock);
  204. p = ft_get_prop(blob, "/" OF_SOC "/serial@4500/clock-frequency", &len);
  205. if (p != NULL)
  206. *p = cpu_to_be32(clock);
  207. p = ft_get_prop(blob, "/" OF_SOC "/serial@4600/clock-frequency", &len);
  208. if (p != NULL)
  209. *p = cpu_to_be32(clock);
  210. #ifdef CONFIG_MPC83XX_TSEC1
  211. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@24000/address", &len);
  212. memcpy(p, bd->bi_enetaddr, 6);
  213. #endif
  214. #ifdef CONFIG_MPC83XX_TSEC2
  215. p = ft_get_prop(blob, "/" OF_SOC "/ethernet@25000/address", &len);
  216. memcpy(p, bd->bi_enet1addr, 6);
  217. #endif
  218. }
  219. #endif
  220. #if defined(CONFIG_DDR_ECC)
  221. void dma_init(void)
  222. {
  223. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  224. volatile dma83xx_t *dma = &immap->dma;
  225. volatile u32 status = swab32(dma->dmasr0);
  226. volatile u32 dmamr0 = swab32(dma->dmamr0);
  227. debug("DMA-init\n");
  228. /* initialize DMASARn, DMADAR and DMAABCRn */
  229. dma->dmadar0 = (u32)0;
  230. dma->dmasar0 = (u32)0;
  231. dma->dmabcr0 = 0;
  232. __asm__ __volatile__ ("sync");
  233. __asm__ __volatile__ ("isync");
  234. /* clear CS bit */
  235. dmamr0 &= ~DMA_CHANNEL_START;
  236. dma->dmamr0 = swab32(dmamr0);
  237. __asm__ __volatile__ ("sync");
  238. __asm__ __volatile__ ("isync");
  239. /* while the channel is busy, spin */
  240. while(status & DMA_CHANNEL_BUSY) {
  241. status = swab32(dma->dmasr0);
  242. }
  243. debug("DMA-init end\n");
  244. }
  245. uint dma_check(void)
  246. {
  247. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  248. volatile dma83xx_t *dma = &immap->dma;
  249. volatile u32 status = swab32(dma->dmasr0);
  250. volatile u32 byte_count = swab32(dma->dmabcr0);
  251. /* while the channel is busy, spin */
  252. while (status & DMA_CHANNEL_BUSY) {
  253. status = swab32(dma->dmasr0);
  254. }
  255. if (status & DMA_CHANNEL_TRANSFER_ERROR) {
  256. printf ("DMA Error: status = %x @ %d\n", status, byte_count);
  257. }
  258. return status;
  259. }
  260. int dma_xfer(void *dest, u32 count, void *src)
  261. {
  262. volatile immap_t *immap = (immap_t *)CFG_IMMRBAR;
  263. volatile dma83xx_t *dma = &immap->dma;
  264. volatile u32 dmamr0;
  265. /* initialize DMASARn, DMADAR and DMAABCRn */
  266. dma->dmadar0 = swab32((u32)dest);
  267. dma->dmasar0 = swab32((u32)src);
  268. dma->dmabcr0 = swab32(count);
  269. __asm__ __volatile__ ("sync");
  270. __asm__ __volatile__ ("isync");
  271. /* init direct transfer, clear CS bit */
  272. dmamr0 = (DMA_CHANNEL_TRANSFER_MODE_DIRECT |
  273. DMA_CHANNEL_SOURCE_ADDRESS_HOLD_8B |
  274. DMA_CHANNEL_SOURCE_ADRESSS_HOLD_EN);
  275. dma->dmamr0 = swab32(dmamr0);
  276. __asm__ __volatile__ ("sync");
  277. __asm__ __volatile__ ("isync");
  278. /* set CS to start DMA transfer */
  279. dmamr0 |= DMA_CHANNEL_START;
  280. dma->dmamr0 = swab32(dmamr0);
  281. __asm__ __volatile__ ("sync");
  282. __asm__ __volatile__ ("isync");
  283. return ((int)dma_check());
  284. }
  285. #endif /*CONFIG_DDR_ECC*/