yosemite.c 11 KB

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