hmi1001.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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. /*
  128. * On MPC5200B we need to set the special configuration delay in the
  129. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  130. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  131. *
  132. * "The SDelay should be written to a value of 0x00000004. It is
  133. * required to account for changes caused by normal wafer processing
  134. * parameters."
  135. */
  136. svr = get_svr();
  137. pvr = get_pvr();
  138. if ((SVR_MJREV(svr) >= 2) &&
  139. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  140. *(vu_long *)MPC5XXX_SDRAM_SDELAY = 0x04;
  141. __asm__ volatile ("sync");
  142. }
  143. /* return dramsize + dramsize2; */
  144. return dramsize;
  145. }
  146. int checkboard (void)
  147. {
  148. puts ("Board: HMI1001\n");
  149. return 0;
  150. }
  151. #ifdef CONFIG_PREBOOT
  152. static uchar kbd_magic_prefix[] = "key_magic";
  153. static uchar kbd_command_prefix[] = "key_cmd";
  154. #define S1_ROT 0xf0
  155. #define S2_Q 0x40
  156. #define S2_M 0x20
  157. struct kbd_data_t {
  158. char s1;
  159. char s2;
  160. };
  161. struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
  162. {
  163. kbd_data->s1 = *((volatile uchar*)(CFG_STATUS1_BASE));
  164. kbd_data->s2 = *((volatile uchar*)(CFG_STATUS2_BASE));
  165. return kbd_data;
  166. }
  167. static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
  168. {
  169. char s1 = str[0];
  170. char s2;
  171. if (s1 >= '0' && s1 <= '9')
  172. s1 -= '0';
  173. else if (s1 >= 'a' && s1 <= 'f')
  174. s1 = s1 - 'a' + 10;
  175. else if (s1 >= 'A' && s1 <= 'F')
  176. s1 = s1 - 'A' + 10;
  177. else
  178. return -1;
  179. if (((S1_ROT & kbd_data->s1) >> 4) != s1)
  180. return -1;
  181. s2 = (S2_Q | S2_M) & kbd_data->s2;
  182. switch (str[1]) {
  183. case 'q':
  184. case 'Q':
  185. if (s2 == S2_Q)
  186. return -1;
  187. break;
  188. case 'm':
  189. case 'M':
  190. if (s2 == S2_M)
  191. return -1;
  192. break;
  193. case '\0':
  194. if (s2 == (S2_Q | S2_M))
  195. return 0;
  196. default:
  197. return -1;
  198. }
  199. if (str[2])
  200. return -1;
  201. return 0;
  202. }
  203. static char *key_match (const struct kbd_data_t *kbd_data)
  204. {
  205. char magic[sizeof (kbd_magic_prefix) + 1];
  206. char *suffix;
  207. char *kbd_magic_keys;
  208. /*
  209. * The following string defines the characters that can be appended
  210. * to "key_magic" to form the names of environment variables that
  211. * hold "magic" key codes, i. e. such key codes that can cause
  212. * pre-boot actions. If the string is empty (""), then only
  213. * "key_magic" is checked (old behaviour); the string "125" causes
  214. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  215. */
  216. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  217. kbd_magic_keys = "";
  218. /* loop over all magic keys;
  219. * use '\0' suffix in case of empty string
  220. */
  221. for (suffix = kbd_magic_keys; *suffix ||
  222. suffix == kbd_magic_keys; ++suffix) {
  223. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  224. if (compare_magic(kbd_data, getenv(magic)) == 0) {
  225. char cmd_name[sizeof (kbd_command_prefix) + 1];
  226. char *cmd;
  227. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  228. cmd = getenv (cmd_name);
  229. return (cmd);
  230. }
  231. }
  232. return (NULL);
  233. }
  234. #endif /* CONFIG_PREBOOT */
  235. int misc_init_r (void)
  236. {
  237. #ifdef CONFIG_PREBOOT
  238. struct kbd_data_t kbd_data;
  239. /* Decode keys */
  240. char *str = strdup (key_match (get_keys (&kbd_data)));
  241. /* Set or delete definition */
  242. setenv ("preboot", str);
  243. free (str);
  244. #endif /* CONFIG_PREBOOT */
  245. return 0;
  246. }
  247. int board_early_init_r (void)
  248. {
  249. *(vu_long *)MPC5XXX_BOOTCS_CFG &= ~0x1; /* clear RO */
  250. *(vu_long *)MPC5XXX_BOOTCS_START =
  251. *(vu_long *)MPC5XXX_CS0_START = START_REG(CFG_FLASH_BASE);
  252. *(vu_long *)MPC5XXX_BOOTCS_STOP =
  253. *(vu_long *)MPC5XXX_CS0_STOP = STOP_REG(CFG_FLASH_BASE, CFG_FLASH_SIZE);
  254. return 0;
  255. }
  256. #ifdef CONFIG_PCI
  257. static struct pci_controller hose;
  258. extern void pci_mpc5xxx_init(struct pci_controller *);
  259. void pci_init_board(void)
  260. {
  261. pci_mpc5xxx_init(&hose);
  262. }
  263. #endif