hmi1001.c 7.1 KB

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