yosemite.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  1. /*
  2. * (C) Copyright 2006-2007
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <asm/ppc4xx.h>
  9. #include <asm/processor.h>
  10. #include <asm/io.h>
  11. #include <spd_sdram.h>
  12. #include <libfdt.h>
  13. #include <fdt_support.h>
  14. DECLARE_GLOBAL_DATA_PTR;
  15. extern flash_info_t flash_info[CONFIG_SYS_MAX_FLASH_BANKS]; /* info for FLASH chips */
  16. static inline u32 get_async_pci_freq(void)
  17. {
  18. if (in_8((void *)(CONFIG_SYS_BCSR_BASE + 5)) &
  19. CONFIG_SYS_BCSR5_PCI66EN)
  20. return 66666666;
  21. else
  22. return 33333333;
  23. }
  24. int board_early_init_f(void)
  25. {
  26. register uint reg;
  27. /*--------------------------------------------------------------------
  28. * Setup the external bus controller/chip selects
  29. *-------------------------------------------------------------------*/
  30. mtdcr(EBC0_CFGADDR, EBC0_CFG);
  31. reg = mfdcr(EBC0_CFGDATA);
  32. mtdcr(EBC0_CFGDATA, reg | 0x04000000); /* Set ATC */
  33. /*--------------------------------------------------------------------
  34. * Setup the GPIO pins
  35. *-------------------------------------------------------------------*/
  36. /*CPLD cs */
  37. /*setup Address lines for flash size 64Meg. */
  38. out32(GPIO0_OSRL, in32(GPIO0_OSRL) | 0x50010000);
  39. out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x50010000);
  40. out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x50000000);
  41. /*setup emac */
  42. out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xC080);
  43. out32(GPIO0_TSRL, in32(GPIO0_TSRL) | 0x40);
  44. out32(GPIO0_ISR1L, in32(GPIO0_ISR1L) | 0x55);
  45. out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0x50004000);
  46. out32(GPIO0_ISR1H, in32(GPIO0_ISR1H) | 0x00440000);
  47. /*UART1 */
  48. out32(GPIO1_TCR, in32(GPIO1_TCR) | 0x02000000);
  49. out32(GPIO1_OSRL, in32(GPIO1_OSRL) | 0x00080000);
  50. out32(GPIO1_ISR2L, in32(GPIO1_ISR2L) | 0x00010000);
  51. /* external interrupts IRQ0...3 */
  52. out32(GPIO1_TCR, in32(GPIO1_TCR) & ~0x00f00000);
  53. out32(GPIO1_TSRL, in32(GPIO1_TSRL) & ~0x0000ff00);
  54. out32(GPIO1_ISR1L, in32(GPIO1_ISR1L) | 0x00005500);
  55. #ifdef CONFIG_440EP
  56. /*setup USB 2.0 */
  57. out32(GPIO1_TCR, in32(GPIO1_TCR) | 0xc0000000);
  58. out32(GPIO1_OSRL, in32(GPIO1_OSRL) | 0x50000000);
  59. out32(GPIO0_TCR, in32(GPIO0_TCR) | 0xf);
  60. out32(GPIO0_OSRH, in32(GPIO0_OSRH) | 0xaa);
  61. out32(GPIO0_ISR2H, in32(GPIO0_ISR2H) | 0x00000500);
  62. #endif
  63. /*--------------------------------------------------------------------
  64. * Setup the interrupt controller polarities, triggers, etc.
  65. *-------------------------------------------------------------------*/
  66. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  67. mtdcr(UIC0ER, 0x00000000); /* disable all */
  68. mtdcr(UIC0CR, 0x00000009); /* ATI & UIC1 crit are critical */
  69. mtdcr(UIC0PR, 0xfffffe13); /* per ref-board manual */
  70. mtdcr(UIC0TR, 0x01c00008); /* per ref-board manual */
  71. mtdcr(UIC0VR, 0x00000001); /* int31 highest, base=0x000 */
  72. mtdcr(UIC0SR, 0xffffffff); /* clear all */
  73. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  74. mtdcr(UIC1ER, 0x00000000); /* disable all */
  75. mtdcr(UIC1CR, 0x00000000); /* all non-critical */
  76. mtdcr(UIC1PR, 0xffffe0ff); /* per ref-board manual */
  77. mtdcr(UIC1TR, 0x00ffc000); /* per ref-board manual */
  78. mtdcr(UIC1VR, 0x00000001); /* int31 highest, base=0x000 */
  79. mtdcr(UIC1SR, 0xffffffff); /* clear all */
  80. /*--------------------------------------------------------------------
  81. * Setup other serial configuration
  82. *-------------------------------------------------------------------*/
  83. mfsdr(SDR0_PCI0, reg);
  84. mtsdr(SDR0_PCI0, 0x80000000 | reg); /* PCI arbiter enabled */
  85. mtsdr(SDR0_PFC0, 0x00003e00); /* Pin function */
  86. mtsdr(SDR0_PFC1, 0x00048000); /* Pin function: UART0 has 4 pins */
  87. /* Check and reconfigure the PCI sync clock if necessary */
  88. ppc4xx_pci_sync_clock_config(get_async_pci_freq());
  89. /*clear tmrclk divisor */
  90. *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x04) = 0x00;
  91. /*enable ethernet */
  92. *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x08) = 0xf0;
  93. #ifdef CONFIG_440EP
  94. /*enable usb 1.1 fs device and remove usb 2.0 reset */
  95. *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x09) = 0x00;
  96. #endif
  97. /*get rid of flash write protect */
  98. *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x07) = 0x00;
  99. return 0;
  100. }
  101. int misc_init_r (void)
  102. {
  103. uint pbcr;
  104. int size_val = 0;
  105. /* Re-do sizing to get full correct info */
  106. mtdcr(EBC0_CFGADDR, PB0CR);
  107. pbcr = mfdcr(EBC0_CFGDATA);
  108. switch (gd->bd->bi_flashsize) {
  109. case 1 << 20:
  110. size_val = 0;
  111. break;
  112. case 2 << 20:
  113. size_val = 1;
  114. break;
  115. case 4 << 20:
  116. size_val = 2;
  117. break;
  118. case 8 << 20:
  119. size_val = 3;
  120. break;
  121. case 16 << 20:
  122. size_val = 4;
  123. break;
  124. case 32 << 20:
  125. size_val = 5;
  126. break;
  127. case 64 << 20:
  128. size_val = 6;
  129. break;
  130. case 128 << 20:
  131. size_val = 7;
  132. break;
  133. }
  134. pbcr = (pbcr & 0x0001ffff) | gd->bd->bi_flashstart | (size_val << 17);
  135. mtdcr(EBC0_CFGADDR, PB0CR);
  136. mtdcr(EBC0_CFGDATA, pbcr);
  137. /* adjust flash start and offset */
  138. gd->bd->bi_flashstart = 0 - gd->bd->bi_flashsize;
  139. gd->bd->bi_flashoffset = 0;
  140. /* Monitor protection ON by default */
  141. (void)flash_protect(FLAG_PROTECT_SET,
  142. -CONFIG_SYS_MONITOR_LEN,
  143. 0xffffffff,
  144. &flash_info[0]);
  145. return 0;
  146. }
  147. int checkboard(void)
  148. {
  149. char buf[64];
  150. int i = getenv_f("serial#", buf, sizeof(buf));
  151. u8 rev;
  152. u32 clock = get_async_pci_freq();
  153. #ifdef CONFIG_440EP
  154. printf("Board: Yosemite - AMCC PPC440EP Evaluation Board");
  155. #else
  156. printf("Board: Yellowstone - AMCC PPC440GR Evaluation Board");
  157. #endif
  158. rev = in_8((void *)(CONFIG_SYS_BCSR_BASE + 0));
  159. printf(", Rev. %X, PCI-Async=%d MHz", rev, clock / 1000000);
  160. if (i > 0) {
  161. puts(", serial# ");
  162. puts(buf);
  163. }
  164. putc('\n');
  165. /*
  166. * Reconfiguration of the PCI sync clock is already done,
  167. * now check again if everything is in range:
  168. */
  169. if (ppc4xx_pci_sync_clock_config(clock)) {
  170. printf("ERROR: PCI clocking incorrect (async=%d "
  171. "sync=%ld)!\n", clock, get_PCI_freq());
  172. }
  173. return (0);
  174. }
  175. /*************************************************************************
  176. * initdram -- doesn't use serial presence detect.
  177. *
  178. * Assumes: 256 MB, ECC, non-registered
  179. * PLB @ 133 MHz
  180. *
  181. ************************************************************************/
  182. #define NUM_TRIES 64
  183. #define NUM_READS 10
  184. void sdram_tr1_set(int ram_address, int* tr1_value)
  185. {
  186. int i;
  187. int j, k;
  188. volatile unsigned int* ram_pointer = (unsigned int*)ram_address;
  189. int first_good = -1, last_bad = 0x1ff;
  190. unsigned long test[NUM_TRIES] = {
  191. 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
  192. 0x00000000, 0x00000000, 0xFFFFFFFF, 0xFFFFFFFF,
  193. 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
  194. 0xFFFFFFFF, 0xFFFFFFFF, 0x00000000, 0x00000000,
  195. 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
  196. 0xAAAAAAAA, 0xAAAAAAAA, 0x55555555, 0x55555555,
  197. 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
  198. 0x55555555, 0x55555555, 0xAAAAAAAA, 0xAAAAAAAA,
  199. 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
  200. 0xA5A5A5A5, 0xA5A5A5A5, 0x5A5A5A5A, 0x5A5A5A5A,
  201. 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
  202. 0x5A5A5A5A, 0x5A5A5A5A, 0xA5A5A5A5, 0xA5A5A5A5,
  203. 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
  204. 0xAA55AA55, 0xAA55AA55, 0x55AA55AA, 0x55AA55AA,
  205. 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55,
  206. 0x55AA55AA, 0x55AA55AA, 0xAA55AA55, 0xAA55AA55 };
  207. /* go through all possible SDRAM0_TR1[RDCT] values */
  208. for (i=0; i<=0x1ff; i++) {
  209. /* set the current value for TR1 */
  210. mtsdram(SDRAM0_TR1, (0x80800800 | i));
  211. /* write values */
  212. for (j=0; j<NUM_TRIES; j++) {
  213. ram_pointer[j] = test[j];
  214. /* clear any cache at ram location */
  215. __asm__("dcbf 0,%0": :"r" (&ram_pointer[j]));
  216. }
  217. /* read values back */
  218. for (j=0; j<NUM_TRIES; j++) {
  219. for (k=0; k<NUM_READS; k++) {
  220. /* clear any cache at ram location */
  221. __asm__("dcbf 0,%0": :"r" (&ram_pointer[j]));
  222. if (ram_pointer[j] != test[j])
  223. break;
  224. }
  225. /* read error */
  226. if (k != NUM_READS) {
  227. break;
  228. }
  229. }
  230. /* we have a SDRAM0_TR1[RDCT] that is part of the window */
  231. if (j == NUM_TRIES) {
  232. if (first_good == -1)
  233. first_good = i; /* found beginning of window */
  234. } else { /* bad read */
  235. /* if we have not had a good read then don't care */
  236. if(first_good != -1) {
  237. /* first failure after a good read */
  238. last_bad = i-1;
  239. break;
  240. }
  241. }
  242. }
  243. /* return the current value for TR1 */
  244. *tr1_value = (first_good + last_bad) / 2;
  245. }
  246. phys_size_t initdram(int board)
  247. {
  248. register uint reg;
  249. int tr1_bank1, tr1_bank2;
  250. /*--------------------------------------------------------------------
  251. * Setup some default
  252. *------------------------------------------------------------------*/
  253. mtsdram(SDRAM0_UABBA, 0x00000000); /* ubba=0 (default) */
  254. mtsdram(SDRAM0_SLIO, 0x00000000); /* rdre=0 wrre=0 rarw=0 */
  255. mtsdram(SDRAM0_DEVOPT, 0x00000000); /* dll=0 ds=0 (normal) */
  256. mtsdram(SDRAM0_CLKTR, 0x40000000); /* ?? */
  257. mtsdram(SDRAM0_WDDCTR, 0x40000000); /* ?? */
  258. /*clear this first, if the DDR is enabled by a debugger
  259. then you can not make changes. */
  260. mtsdram(SDRAM0_CFG0, 0x00000000); /* Disable EEC */
  261. /*--------------------------------------------------------------------
  262. * Setup for board-specific specific mem
  263. *------------------------------------------------------------------*/
  264. /*
  265. * Following for CAS Latency = 2.5 @ 133 MHz PLB
  266. */
  267. mtsdram(SDRAM0_B0CR, 0x000a4001); /* SDBA=0x000 128MB, Mode 3, enabled */
  268. mtsdram(SDRAM0_B1CR, 0x080a4001); /* SDBA=0x080 128MB, Mode 3, enabled */
  269. mtsdram(SDRAM0_TR0, 0x410a4012); /* ?? */
  270. mtsdram(SDRAM0_RTR, 0x04080000); /* ?? */
  271. mtsdram(SDRAM0_CFG1, 0x00000000); /* Self-refresh exit, disable PM */
  272. mtsdram(SDRAM0_CFG0, 0x30000000); /* Disable EEC */
  273. udelay(400); /* Delay 200 usecs (min) */
  274. /*--------------------------------------------------------------------
  275. * Enable the controller, then wait for DCEN to complete
  276. *------------------------------------------------------------------*/
  277. mtsdram(SDRAM0_CFG0, 0x80000000); /* Enable */
  278. for (;;) {
  279. mfsdram(SDRAM0_MCSTS, reg);
  280. if (reg & 0x80000000)
  281. break;
  282. }
  283. sdram_tr1_set(0x00000000, &tr1_bank1);
  284. sdram_tr1_set(0x08000000, &tr1_bank2);
  285. mtsdram(SDRAM0_TR1, (((tr1_bank1+tr1_bank2)/2) | 0x80800800));
  286. return CONFIG_SYS_SDRAM_BANKS * (CONFIG_SYS_KBYTES_SDRAM * 1024); /* return bytes */
  287. }
  288. /*************************************************************************
  289. * hw_watchdog_reset
  290. *
  291. * This routine is called to reset (keep alive) the watchdog timer
  292. *
  293. ************************************************************************/
  294. #if defined(CONFIG_HW_WATCHDOG)
  295. void hw_watchdog_reset(void)
  296. {
  297. }
  298. #endif
  299. void board_reset(void)
  300. {
  301. /* give reset to BCSR */
  302. *(unsigned char *)(CONFIG_SYS_BCSR_BASE | 0x06) = 0x09;
  303. }