inka4x0.c 7.6 KB

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