inka4x0.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  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_MPC5200_DDR)
  33. #include "mt46v16m16-75.h"
  34. #else
  35. #include "mt48lc16m16a2-75.h"
  36. #endif
  37. #ifndef CFG_RAMBOOT
  38. static void sdram_start (int hi_addr)
  39. {
  40. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  41. /* unlock mode register */
  42. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  43. __asm__ volatile ("sync");
  44. /* precharge all banks */
  45. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  46. __asm__ volatile ("sync");
  47. #if SDRAM_DDR
  48. /* set mode register: extended mode */
  49. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  50. __asm__ volatile ("sync");
  51. /* set mode register: reset DLL */
  52. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  53. __asm__ volatile ("sync");
  54. #endif
  55. /* precharge all banks */
  56. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  57. __asm__ volatile ("sync");
  58. /* auto refresh */
  59. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  60. __asm__ volatile ("sync");
  61. /* set mode register */
  62. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  63. __asm__ volatile ("sync");
  64. /* normal operation */
  65. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  66. __asm__ volatile ("sync");
  67. }
  68. #endif
  69. /*
  70. * ATTENTION: Although partially referenced initdram does NOT make real use
  71. * use of CFG_SDRAM_BASE. The code does not work if CFG_SDRAM_BASE
  72. * is something else than 0x00000000.
  73. */
  74. long int initdram (int board_type)
  75. {
  76. ulong dramsize = 0;
  77. #ifndef CFG_RAMBOOT
  78. ulong test1, test2;
  79. /* setup SDRAM chip selects */
  80. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  81. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  82. __asm__ volatile ("sync");
  83. /* setup config registers */
  84. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  85. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  86. __asm__ volatile ("sync");
  87. #if SDRAM_DDR
  88. /* set tap delay */
  89. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  90. __asm__ volatile ("sync");
  91. #endif
  92. /* find RAM size using SDRAM CS0 only */
  93. sdram_start(0);
  94. test1 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  95. sdram_start(1);
  96. test2 = get_ram_size((ulong *)CFG_SDRAM_BASE, 0x20000000);
  97. if (test1 > test2) {
  98. sdram_start(0);
  99. dramsize = test1;
  100. } else {
  101. dramsize = test2;
  102. }
  103. /* memory smaller than 1MB is impossible */
  104. if (dramsize < (1 << 20)) {
  105. dramsize = 0;
  106. }
  107. /* set SDRAM CS0 size according to the amount of RAM found */
  108. if (dramsize > 0) {
  109. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  110. __builtin_ffs(dramsize >> 20) - 1;
  111. } else {
  112. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  113. }
  114. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  115. #else /* CFG_RAMBOOT */
  116. /* retrieve size of memory connected to SDRAM CS0 */
  117. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  118. if (dramsize >= 0x13) {
  119. dramsize = (1 << (dramsize - 0x13)) << 20;
  120. } else {
  121. dramsize = 0;
  122. }
  123. /* retrieve size of memory connected to SDRAM CS1 */
  124. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  125. if (dramsize2 >= 0x13) {
  126. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  127. } else {
  128. dramsize2 = 0;
  129. }
  130. #endif /* CFG_RAMBOOT */
  131. /* return dramsize + dramsize2; */
  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. uchar 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. : CFG_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 (CFG_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 /* defined (CFG_CMD_IDE) && defined (CONFIG_IDE_RESET) */