inka4x0.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. /*
  2. * (C) Copyright 2008-2009
  3. * Andreas Pfefferle, DENX Software Engineering, ap@denx.de.
  4. *
  5. * (C) Copyright 2009
  6. * Detlev Zundel, DENX Software Engineering, dzu@denx.de.
  7. *
  8. * (C) Copyright 2004
  9. * Mark Jonas, Freescale Semiconductor, mark.jonas@motorola.com.
  10. *
  11. * (C) Copyright 2004
  12. * Martin Krause, TQ-Systems GmbH, martin.krause@tqs.de
  13. *
  14. * (C) Copyright 2003-2004
  15. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  16. *
  17. * See file CREDITS for list of people who contributed to this
  18. * project.
  19. *
  20. * This program is free software; you can redistribute it and/or
  21. * modify it under the terms of the GNU General Public License as
  22. * published by the Free Software Foundation; either version 2 of
  23. * the License, or (at your option) any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  33. * MA 02111-1307 USA
  34. */
  35. #include <common.h>
  36. #include <mpc5xxx.h>
  37. #include <pci.h>
  38. #if defined(CONFIG_DDR_MT46V16M16)
  39. #include "mt46v16m16-75.h"
  40. #elif defined(CONFIG_SDR_MT48LC16M16A2)
  41. #include "mt48lc16m16a2-75.h"
  42. #elif defined(CONFIG_DDR_MT46V32M16)
  43. #include "mt46v32m16.h"
  44. #elif defined(CONFIG_DDR_HYB25D512160BF)
  45. #include "hyb25d512160bf.h"
  46. #elif defined(CONFIG_DDR_K4H511638C)
  47. #include "k4h511638c.h"
  48. #else
  49. #error "INKA4x0 SDRAM: invalid chip type specified!"
  50. #endif
  51. #ifndef CONFIG_SYS_RAMBOOT
  52. static void sdram_start (int hi_addr)
  53. {
  54. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  55. /* unlock mode register */
  56. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  57. __asm__ volatile ("sync");
  58. /* precharge all banks */
  59. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  60. __asm__ volatile ("sync");
  61. #if SDRAM_DDR
  62. /* set mode register: extended mode */
  63. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  64. __asm__ volatile ("sync");
  65. /* set mode register: reset DLL */
  66. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  67. __asm__ volatile ("sync");
  68. #endif
  69. /* precharge all banks */
  70. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  71. __asm__ volatile ("sync");
  72. /* auto refresh */
  73. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  74. __asm__ volatile ("sync");
  75. /* set mode register */
  76. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  77. __asm__ volatile ("sync");
  78. /* normal operation */
  79. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  80. __asm__ volatile ("sync");
  81. }
  82. #endif
  83. /*
  84. * ATTENTION: Although partially referenced initdram does NOT make real use
  85. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  86. * is something else than 0x00000000.
  87. */
  88. phys_size_t initdram (int board_type)
  89. {
  90. ulong dramsize = 0;
  91. #ifndef CONFIG_SYS_RAMBOOT
  92. long test1, test2;
  93. /* setup SDRAM chip selects */
  94. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  95. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  96. __asm__ volatile ("sync");
  97. /* setup config registers */
  98. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  99. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  100. __asm__ volatile ("sync");
  101. #if SDRAM_DDR
  102. /* set tap delay */
  103. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  104. __asm__ volatile ("sync");
  105. #endif
  106. /* find RAM size using SDRAM CS0 only */
  107. sdram_start(0);
  108. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  109. sdram_start(1);
  110. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  111. if (test1 > test2) {
  112. sdram_start(0);
  113. dramsize = test1;
  114. } else {
  115. dramsize = test2;
  116. }
  117. /* memory smaller than 1MB is impossible */
  118. if (dramsize < (1 << 20)) {
  119. dramsize = 0;
  120. }
  121. /* set SDRAM CS0 size according to the amount of RAM found */
  122. if (dramsize > 0) {
  123. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  124. __builtin_ffs(dramsize >> 20) - 1;
  125. } else {
  126. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  127. }
  128. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  129. #else /* CONFIG_SYS_RAMBOOT */
  130. /* retrieve size of memory connected to SDRAM CS0 */
  131. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  132. if (dramsize >= 0x13) {
  133. dramsize = (1 << (dramsize - 0x13)) << 20;
  134. } else {
  135. dramsize = 0;
  136. }
  137. #endif /* CONFIG_SYS_RAMBOOT */
  138. return dramsize;
  139. }
  140. int checkboard (void)
  141. {
  142. puts ("Board: INKA 4X0\n");
  143. return 0;
  144. }
  145. void flash_preinit(void)
  146. {
  147. /*
  148. * Now, when we are in RAM, enable flash write
  149. * access for detection process.
  150. * Note that CS_BOOT cannot be cleared when
  151. * executing in flash.
  152. */
  153. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  154. }
  155. int misc_init_r (void) {
  156. extern int inkadiag_init_r (void);
  157. /*
  158. * The command table used for the subcommands of inkadiag
  159. * needs to be relocated manually.
  160. */
  161. return inkadiag_init_r();
  162. }
  163. int misc_init_f (void)
  164. {
  165. char tmp[10];
  166. int i, br;
  167. i = getenv_r("brightness", tmp, sizeof(tmp));
  168. br = (i > 0)
  169. ? (int) simple_strtoul (tmp, NULL, 10)
  170. : CONFIG_SYS_BRIGHTNESS;
  171. if (br > 255)
  172. br = 255;
  173. /* Initialize GPIO output pins.
  174. */
  175. /* Configure GPT as GPIO output (and set them as they control low-active LEDs */
  176. *(vu_long *)MPC5XXX_GPT0_ENABLE =
  177. *(vu_long *)MPC5XXX_GPT1_ENABLE =
  178. *(vu_long *)MPC5XXX_GPT2_ENABLE =
  179. *(vu_long *)MPC5XXX_GPT3_ENABLE =
  180. *(vu_long *)MPC5XXX_GPT4_ENABLE =
  181. *(vu_long *)MPC5XXX_GPT5_ENABLE = 0x34;
  182. /* Configure GPT7 as PWM timer, 1kHz, no ints. */
  183. *(vu_long *)MPC5XXX_GPT7_ENABLE = 0;/* Disable */
  184. *(vu_long *)MPC5XXX_GPT7_COUNTER = 0x020000fe;
  185. *(vu_long *)MPC5XXX_GPT7_PWMCFG = (br << 16);
  186. *(vu_long *)MPC5XXX_GPT7_ENABLE = 0x3;/* Enable PWM mode and start */
  187. /* Configure PSC3_6,7 as GPIO output */
  188. *(vu_long *)MPC5XXX_GPIO_ENABLE |= 0x00003000;
  189. *(vu_long *)MPC5XXX_GPIO_DIR |= 0x00003000;
  190. /* Configure PSC3_8 as GPIO output, no interrupt */
  191. *(vu_long *)MPC5XXX_GPIO_SI_ENABLE |= 0x04000000;
  192. *(vu_long *)MPC5XXX_GPIO_SI_DIR |= 0x04000000;
  193. *(vu_long *)MPC5XXX_GPIO_SI_IEN &= ~0x04000000;
  194. /* Configure PSC3_9 and GPIO_WKUP6,7 as GPIO output */
  195. *(vu_long *)MPC5XXX_WU_GPIO_ENABLE |= 0xc4000000;
  196. *(vu_long *)MPC5XXX_WU_GPIO_DIR |= 0xc4000000;
  197. /* Set LR mirror bit because it is low-active */
  198. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_WKUP_7;
  199. /*
  200. * Reset Coral-P graphics controller
  201. */
  202. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC3_9;
  203. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC3_9;
  204. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC3_9;
  205. return 0;
  206. }
  207. #ifdef CONFIG_PCI
  208. static struct pci_controller hose;
  209. extern void pci_mpc5xxx_init(struct pci_controller *);
  210. void pci_init_board(void)
  211. {
  212. pci_mpc5xxx_init(&hose);
  213. }
  214. #endif
  215. #if defined(CONFIG_CMD_IDE) && defined(CONFIG_IDE_RESET)
  216. void init_ide_reset (void)
  217. {
  218. debug ("init_ide_reset\n");
  219. /* Configure PSC1_4 as GPIO output for ATA reset */
  220. *(vu_long *) MPC5XXX_WU_GPIO_ENABLE |= GPIO_PSC1_4;
  221. *(vu_long *) MPC5XXX_WU_GPIO_DIR |= GPIO_PSC1_4;
  222. /* Deassert reset */
  223. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  224. }
  225. void ide_set_reset (int idereset)
  226. {
  227. debug ("ide_reset(%d)\n", idereset);
  228. if (idereset) {
  229. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O &= ~GPIO_PSC1_4;
  230. /* Make a delay. MPC5200 spec says 25 usec min */
  231. udelay(500000);
  232. } else {
  233. *(vu_long *) MPC5XXX_WU_GPIO_DATA_O |= GPIO_PSC1_4;
  234. }
  235. }
  236. #endif