hmi1001.c 7.1 KB

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