inka4x0.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. * SPDX-License-Identifier: GPL-2.0+
  18. */
  19. #include <asm/io.h>
  20. #include <common.h>
  21. #include <mpc5xxx.h>
  22. #include <pci.h>
  23. #if defined(CONFIG_DDR_MT46V16M16)
  24. #include "mt46v16m16-75.h"
  25. #elif defined(CONFIG_SDR_MT48LC16M16A2)
  26. #include "mt48lc16m16a2-75.h"
  27. #elif defined(CONFIG_DDR_MT46V32M16)
  28. #include "mt46v32m16.h"
  29. #elif defined(CONFIG_DDR_HYB25D512160BF)
  30. #include "hyb25d512160bf.h"
  31. #elif defined(CONFIG_DDR_K4H511638C)
  32. #include "k4h511638c.h"
  33. #else
  34. #error "INKA4x0 SDRAM: invalid chip type specified!"
  35. #endif
  36. #ifndef CONFIG_SYS_RAMBOOT
  37. static void sdram_start (int hi_addr)
  38. {
  39. volatile struct mpc5xxx_sdram *sdram =
  40. (struct mpc5xxx_sdram *)MPC5XXX_SDRAM;
  41. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  42. /* unlock mode register */
  43. out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000000 | hi_addr_bit);
  44. /* precharge all banks */
  45. out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit);
  46. #if SDRAM_DDR
  47. /* set mode register: extended mode */
  48. out_be32(&sdram->mode, SDRAM_EMODE);
  49. /* set mode register: reset DLL */
  50. out_be32(&sdram->mode, SDRAM_MODE | 0x04000000);
  51. #endif
  52. /* precharge all banks */
  53. out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000002 | hi_addr_bit);
  54. /* auto refresh */
  55. out_be32(&sdram->ctrl, SDRAM_CONTROL | 0x80000004 | hi_addr_bit);
  56. /* set mode register */
  57. out_be32(&sdram->mode, SDRAM_MODE);
  58. /* normal operation */
  59. out_be32(&sdram->ctrl, SDRAM_CONTROL | hi_addr_bit);
  60. }
  61. #endif
  62. /*
  63. * ATTENTION: Although partially referenced initdram does NOT make real use
  64. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  65. * is something else than 0x00000000.
  66. */
  67. phys_size_t initdram (int board_type)
  68. {
  69. volatile struct mpc5xxx_mmap_ctl *mm =
  70. (struct mpc5xxx_mmap_ctl *) CONFIG_SYS_MBAR;
  71. volatile struct mpc5xxx_cdm *cdm =
  72. (struct mpc5xxx_cdm *) MPC5XXX_CDM;
  73. volatile struct mpc5xxx_sdram *sdram =
  74. (struct mpc5xxx_sdram *) MPC5XXX_SDRAM;
  75. ulong dramsize = 0;
  76. #ifndef CONFIG_SYS_RAMBOOT
  77. long test1, test2;
  78. /* setup SDRAM chip selects */
  79. out_be32(&mm->sdram0, 0x0000001c); /* 512MB at 0x0 */
  80. out_be32(&mm->sdram1, 0x40000000); /* disabled */
  81. /* setup config registers */
  82. out_be32(&sdram->config1, SDRAM_CONFIG1);
  83. out_be32(&sdram->config2, SDRAM_CONFIG2);
  84. #if SDRAM_DDR
  85. /* set tap delay */
  86. out_be32(&cdm->porcfg, SDRAM_TAPDELAY);
  87. #endif
  88. /* find RAM size using SDRAM CS0 only */
  89. sdram_start(0);
  90. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  91. sdram_start(1);
  92. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  93. if (test1 > test2) {
  94. sdram_start(0);
  95. dramsize = test1;
  96. } else {
  97. dramsize = test2;
  98. }
  99. /* memory smaller than 1MB is impossible */
  100. if (dramsize < (1 << 20)) {
  101. dramsize = 0;
  102. }
  103. /* set SDRAM CS0 size according to the amount of RAM found */
  104. if (dramsize > 0) {
  105. out_be32(&mm->sdram0, 0x13 +
  106. __builtin_ffs(dramsize >> 20) - 1);
  107. } else {
  108. out_be32(&mm->sdram0, 0); /* disabled */
  109. }
  110. out_be32(&mm->sdram1, dramsize); /* disabled */
  111. #else /* CONFIG_SYS_RAMBOOT */
  112. /* retrieve size of memory connected to SDRAM CS0 */
  113. dramsize = in_be32(&mm->sdram0) & 0xFF;
  114. if (dramsize >= 0x13) {
  115. dramsize = (1 << (dramsize - 0x13)) << 20;
  116. } else {
  117. dramsize = 0;
  118. }
  119. #endif /* CONFIG_SYS_RAMBOOT */
  120. return dramsize;
  121. }
  122. int checkboard (void)
  123. {
  124. puts ("Board: INKA 4X0\n");
  125. return 0;
  126. }
  127. void flash_preinit(void)
  128. {
  129. volatile struct mpc5xxx_lpb *lpb = (struct mpc5xxx_lpb *)MPC5XXX_LPB;
  130. /*
  131. * Now, when we are in RAM, enable flash write
  132. * access for detection process.
  133. * Note that CS_BOOT (CS0) cannot be cleared when
  134. * executing in flash.
  135. */
  136. clrbits_be32(&lpb->cs0_cfg, 0x1); /* clear RO */
  137. }
  138. int misc_init_f (void)
  139. {
  140. volatile struct mpc5xxx_gpio *gpio =
  141. (struct mpc5xxx_gpio *) MPC5XXX_GPIO;
  142. volatile struct mpc5xxx_wu_gpio *wu_gpio =
  143. (struct mpc5xxx_wu_gpio *)MPC5XXX_WU_GPIO;
  144. volatile struct mpc5xxx_gpt *gpt;
  145. char tmp[10];
  146. int i, br;
  147. i = getenv_f("brightness", tmp, sizeof(tmp));
  148. br = (i > 0)
  149. ? (int) simple_strtoul (tmp, NULL, 10)
  150. : CONFIG_SYS_BRIGHTNESS;
  151. if (br > 255)
  152. br = 255;
  153. /* Initialize GPIO output pins.
  154. */
  155. /* Configure GPT as GPIO output (and set them as they control low-active LEDs */
  156. for (i = 0; i <= 5; i++) {
  157. gpt = (struct mpc5xxx_gpt *)(MPC5XXX_GPT + (i * 0x10));
  158. out_be32(&gpt->emsr, 0x34);
  159. }
  160. /* Configure GPT7 as PWM timer, 1kHz, no ints. */
  161. gpt = (struct mpc5xxx_gpt *)(MPC5XXX_GPT + (7 * 0x10));
  162. out_be32(&gpt->emsr, 0); /* Disable */
  163. out_be32(&gpt->cir, 0x020000fe);
  164. out_be32(&gpt->pwmcr, (br << 16));
  165. out_be32(&gpt->emsr, 0x3); /* Enable PWM mode and start */
  166. /* Configure PSC3_6,7 as GPIO output */
  167. setbits_be32(&gpio->simple_gpioe, MPC5XXX_GPIO_SIMPLE_PSC3_6 |
  168. MPC5XXX_GPIO_SIMPLE_PSC3_7);
  169. setbits_be32(&gpio->simple_ddr, MPC5XXX_GPIO_SIMPLE_PSC3_6 |
  170. MPC5XXX_GPIO_SIMPLE_PSC3_7);
  171. /* Configure PSC3_9 and GPIO_WKUP6,7 as GPIO output */
  172. setbits_8(&wu_gpio->enable, MPC5XXX_GPIO_WKUP_6 |
  173. MPC5XXX_GPIO_WKUP_7 |
  174. MPC5XXX_GPIO_WKUP_PSC3_9);
  175. setbits_8(&wu_gpio->ddr, MPC5XXX_GPIO_WKUP_6 |
  176. MPC5XXX_GPIO_WKUP_7 |
  177. MPC5XXX_GPIO_WKUP_PSC3_9);
  178. /* Set LR mirror bit because it is low-active */
  179. setbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_7);
  180. /* Reset Coral-P graphics controller */
  181. setbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_PSC3_9);
  182. /* Enable display backlight */
  183. clrbits_8(&gpio->sint_inten, MPC5XXX_GPIO_SINT_PSC3_8);
  184. setbits_8(&gpio->sint_gpioe, MPC5XXX_GPIO_SINT_PSC3_8);
  185. setbits_8(&gpio->sint_ddr, MPC5XXX_GPIO_SINT_PSC3_8);
  186. setbits_8(&gpio->sint_dvo, MPC5XXX_GPIO_SINT_PSC3_8);
  187. /*
  188. * Configure three wire serial interface to RTC (PSC1_4,
  189. * PSC2_4, PSC3_4, PSC3_5)
  190. */
  191. setbits_8(&wu_gpio->enable, MPC5XXX_GPIO_WKUP_PSC1_4 |
  192. MPC5XXX_GPIO_WKUP_PSC2_4);
  193. setbits_8(&wu_gpio->ddr, MPC5XXX_GPIO_WKUP_PSC1_4 |
  194. MPC5XXX_GPIO_WKUP_PSC2_4);
  195. clrbits_8(&wu_gpio->dvo, MPC5XXX_GPIO_WKUP_PSC1_4);
  196. clrbits_8(&gpio->sint_inten, MPC5XXX_GPIO_SINT_PSC3_4 |
  197. MPC5XXX_GPIO_SINT_PSC3_5);
  198. setbits_8(&gpio->sint_gpioe, MPC5XXX_GPIO_SINT_PSC3_4 |
  199. MPC5XXX_GPIO_SINT_PSC3_5);
  200. setbits_8(&gpio->sint_ddr, MPC5XXX_GPIO_SINT_PSC3_5);
  201. clrbits_8(&gpio->sint_dvo, MPC5XXX_GPIO_SINT_PSC3_5);
  202. return 0;
  203. }
  204. #ifdef CONFIG_PCI
  205. static struct pci_controller hose;
  206. extern void pci_mpc5xxx_init(struct pci_controller *);
  207. void pci_init_board(void)
  208. {
  209. pci_mpc5xxx_init(&hose);
  210. }
  211. #endif