inka4x0.c 7.0 KB

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