hmi1001.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. /*
  2. * (C) Copyright 2003-2008
  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. #include <asm/processor.h>
  33. #include <malloc.h>
  34. #ifndef CONFIG_SYS_RAMBOOT
  35. static void sdram_start (int hi_addr)
  36. {
  37. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  38. /* unlock mode register */
  39. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000000 | hi_addr_bit;
  40. __asm__ volatile ("sync");
  41. /* precharge all banks */
  42. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  43. __asm__ volatile ("sync");
  44. #if SDRAM_DDR
  45. /* set mode register: extended mode */
  46. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_EMODE;
  47. __asm__ volatile ("sync");
  48. /* set mode register: reset DLL */
  49. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE | 0x04000000;
  50. __asm__ volatile ("sync");
  51. #endif
  52. /* precharge all banks */
  53. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000002 | hi_addr_bit;
  54. __asm__ volatile ("sync");
  55. /* auto refresh */
  56. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | 0x80000004 | hi_addr_bit;
  57. __asm__ volatile ("sync");
  58. /* set mode register */
  59. *(vu_long *)MPC5XXX_SDRAM_MODE = SDRAM_MODE;
  60. __asm__ volatile ("sync");
  61. /* normal operation */
  62. *(vu_long *)MPC5XXX_SDRAM_CTRL = SDRAM_CONTROL | hi_addr_bit;
  63. __asm__ volatile ("sync");
  64. }
  65. #endif
  66. /*
  67. * ATTENTION: Although partially referenced initdram does NOT make real use
  68. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  69. * is something else than 0x00000000.
  70. */
  71. phys_size_t initdram (int board_type)
  72. {
  73. ulong dramsize = 0;
  74. #ifndef CONFIG_SYS_RAMBOOT
  75. ulong test1, test2;
  76. uint svr, pvr;
  77. /* setup SDRAM chip selects */
  78. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x0000001c; /* 512MB at 0x0 */
  79. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = 0x40000000; /* disabled */
  80. __asm__ volatile ("sync");
  81. /* setup config registers */
  82. *(vu_long *)MPC5XXX_SDRAM_CONFIG1 = SDRAM_CONFIG1;
  83. *(vu_long *)MPC5XXX_SDRAM_CONFIG2 = SDRAM_CONFIG2;
  84. __asm__ volatile ("sync");
  85. #if SDRAM_DDR
  86. /* set tap delay */
  87. *(vu_long *)MPC5XXX_CDM_PORCFG = SDRAM_TAPDELAY;
  88. __asm__ volatile ("sync");
  89. #endif
  90. /* find RAM size using SDRAM CS0 only */
  91. sdram_start(0);
  92. test1 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  93. sdram_start(1);
  94. test2 = get_ram_size((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  95. if (test1 > test2) {
  96. sdram_start(0);
  97. dramsize = test1;
  98. } else {
  99. dramsize = test2;
  100. }
  101. /* memory smaller than 1MB is impossible */
  102. if (dramsize < (1 << 20)) {
  103. dramsize = 0;
  104. }
  105. /* set SDRAM CS0 size according to the amount of RAM found */
  106. if (dramsize > 0) {
  107. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0x13 +
  108. __builtin_ffs(dramsize >> 20) - 1;
  109. } else {
  110. *(vu_long *)MPC5XXX_SDRAM_CS0CFG = 0; /* disabled */
  111. }
  112. *(vu_long *)MPC5XXX_SDRAM_CS1CFG = dramsize; /* disabled */
  113. #else /* CONFIG_SYS_RAMBOOT */
  114. /* retrieve size of memory connected to SDRAM CS0 */
  115. dramsize = *(vu_long *)MPC5XXX_SDRAM_CS0CFG & 0xFF;
  116. if (dramsize >= 0x13) {
  117. dramsize = (1 << (dramsize - 0x13)) << 20;
  118. } else {
  119. dramsize = 0;
  120. }
  121. /* retrieve size of memory connected to SDRAM CS1 */
  122. dramsize2 = *(vu_long *)MPC5XXX_SDRAM_CS1CFG & 0xFF;
  123. if (dramsize2 >= 0x13) {
  124. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  125. } else {
  126. dramsize2 = 0;
  127. }
  128. #endif /* CONFIG_SYS_RAMBOOT */
  129. /*
  130. * On MPC5200B we need to set the special configuration delay in the
  131. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  132. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  133. *
  134. * "The SDelay should be written to a value of 0x00000004. It is
  135. * required to account for changes caused by normal wafer processing
  136. * parameters."
  137. */
  138. svr = get_svr();
  139. pvr = get_pvr();
  140. if ((SVR_MJREV(svr) >= 2) &&
  141. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  142. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  143. __asm__ volatile ("sync");
  144. }
  145. /* return dramsize + dramsize2; */
  146. return dramsize;
  147. }
  148. int checkboard (void)
  149. {
  150. puts ("Board: HMI1001\n");
  151. return 0;
  152. }
  153. #ifdef CONFIG_PREBOOT
  154. static uchar kbd_magic_prefix[] = "key_magic";
  155. static uchar kbd_command_prefix[] = "key_cmd";
  156. #define S1_ROT 0xf0
  157. #define S2_Q 0x40
  158. #define S2_M 0x20
  159. struct kbd_data_t {
  160. char s1;
  161. char s2;
  162. };
  163. struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
  164. {
  165. kbd_data->s1 = *((volatile uchar*)(CONFIG_SYS_STATUS1_BASE));
  166. kbd_data->s2 = *((volatile uchar*)(CONFIG_SYS_STATUS2_BASE));
  167. return kbd_data;
  168. }
  169. static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
  170. {
  171. char s1 = str[0];
  172. char s2;
  173. if (s1 >= '0' && s1 <= '9')
  174. s1 -= '0';
  175. else if (s1 >= 'a' && s1 <= 'f')
  176. s1 = s1 - 'a' + 10;
  177. else if (s1 >= 'A' && s1 <= 'F')
  178. s1 = s1 - 'A' + 10;
  179. else
  180. return -1;
  181. if (((S1_ROT & kbd_data->s1) >> 4) != s1)
  182. return -1;
  183. s2 = (S2_Q | S2_M) & kbd_data->s2;
  184. switch (str[1]) {
  185. case 'q':
  186. case 'Q':
  187. if (s2 == S2_Q)
  188. return -1;
  189. break;
  190. case 'm':
  191. case 'M':
  192. if (s2 == S2_M)
  193. return -1;
  194. break;
  195. case '\0':
  196. if (s2 == (S2_Q | S2_M))
  197. return 0;
  198. default:
  199. return -1;
  200. }
  201. if (str[2])
  202. return -1;
  203. return 0;
  204. }
  205. static char *key_match (const struct kbd_data_t *kbd_data)
  206. {
  207. char magic[sizeof (kbd_magic_prefix) + 1];
  208. char *suffix;
  209. char *kbd_magic_keys;
  210. /*
  211. * The following string defines the characters that can be appended
  212. * to "key_magic" to form the names of environment variables that
  213. * hold "magic" key codes, i. e. such key codes that can cause
  214. * pre-boot actions. If the string is empty (""), then only
  215. * "key_magic" is checked (old behaviour); the string "125" causes
  216. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  217. */
  218. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  219. kbd_magic_keys = "";
  220. /* loop over all magic keys;
  221. * use '\0' suffix in case of empty string
  222. */
  223. for (suffix = kbd_magic_keys; *suffix ||
  224. suffix == kbd_magic_keys; ++suffix) {
  225. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  226. if (compare_magic(kbd_data, getenv(magic)) == 0) {
  227. char cmd_name[sizeof (kbd_command_prefix) + 1];
  228. char *cmd;
  229. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  230. cmd = getenv (cmd_name);
  231. return (cmd);
  232. }
  233. }
  234. return (NULL);
  235. }
  236. #endif /* CONFIG_PREBOOT */
  237. int misc_init_r (void)
  238. {
  239. #ifdef CONFIG_PREBOOT
  240. struct kbd_data_t kbd_data;
  241. /* Decode keys */
  242. char *str = strdup (key_match (get_keys (&kbd_data)));
  243. /* Set or delete definition */
  244. setenv ("preboot", str);
  245. free (str);
  246. #endif /* CONFIG_PREBOOT */
  247. return 0;
  248. }
  249. int board_early_init_r (void)
  250. {
  251. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  252. *(vu_long *)MPC5XXX_BOOTCS_START =
  253. *(vu_long *)MPC5XXX_CS0_START = START_REG(CONFIG_SYS_FLASH_BASE);
  254. *(vu_long *)MPC5XXX_BOOTCS_STOP =
  255. *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE);
  256. return 0;
  257. }
  258. #ifdef CONFIG_PCI
  259. static struct pci_controller hose;
  260. extern void pci_mpc5xxx_init(struct pci_controller *);
  261. void pci_init_board(void)
  262. {
  263. pci_mpc5xxx_init(&hose);
  264. }
  265. #endif