mucmc52.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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. * (C) Copyright 2008
  12. * Heiko Schocher, DENX Software Engineering, hs@denx.de.
  13. *
  14. * See file CREDITS for list of people who contributed to this
  15. * project.
  16. *
  17. * This program is free software; you can redistribute it and/or
  18. * modify it under the terms of the GNU General Public License as
  19. * published by the Free Software Foundation; either version 2 of
  20. * the License, or (at your option) any later version.
  21. *
  22. * This program is distributed in the hope that it will be useful,
  23. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  24. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  25. * GNU General Public License for more details.
  26. *
  27. * You should have received a copy of the GNU General Public License
  28. * along with this program; if not, write to the Free Software
  29. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  30. * MA 02111-1307 USA
  31. */
  32. #include <common.h>
  33. #include <fdt_support.h>
  34. #include <mpc5xxx.h>
  35. #include <pci.h>
  36. #include <malloc.h>
  37. #include <asm/processor.h>
  38. #include <asm/io.h>
  39. #ifndef CONFIG_SYS_RAMBOOT
  40. static void sdram_start (int hi_addr)
  41. {
  42. long hi_addr_bit = hi_addr ? 0x01000000 : 0;
  43. /* unlock mode register */
  44. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
  45. (SDRAM_CONTROL | 0x80000000 | hi_addr_bit));
  46. __asm__ volatile ("sync");
  47. /* precharge all banks */
  48. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
  49. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  50. __asm__ volatile ("sync");
  51. #if SDRAM_DDR
  52. /* set mode register: extended mode */
  53. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_EMODE));
  54. __asm__ volatile ("sync");
  55. /* set mode register: reset DLL */
  56. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE,
  57. (SDRAM_MODE | 0x04000000));
  58. __asm__ volatile ("sync");
  59. #endif
  60. /* precharge all banks */
  61. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
  62. (SDRAM_CONTROL | 0x80000002 | hi_addr_bit));
  63. __asm__ volatile ("sync");
  64. /* auto refresh */
  65. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
  66. (SDRAM_CONTROL | 0x80000004 | hi_addr_bit));
  67. __asm__ volatile ("sync");
  68. /* set mode register */
  69. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_MODE, (SDRAM_MODE));
  70. __asm__ volatile ("sync");
  71. /* normal operation */
  72. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CTRL,
  73. (SDRAM_CONTROL | hi_addr_bit));
  74. __asm__ volatile ("sync");
  75. }
  76. #endif
  77. /*
  78. * ATTENTION: Although partially referenced initdram does NOT make real use
  79. * use of CONFIG_SYS_SDRAM_BASE. The code does not work if CONFIG_SYS_SDRAM_BASE
  80. * is something else than 0x00000000.
  81. */
  82. phys_size_t initdram (int board_type)
  83. {
  84. ulong dramsize = 0;
  85. ulong dramsize2 = 0;
  86. uint svr, pvr;
  87. #ifndef CONFIG_SYS_RAMBOOT
  88. ulong test1, test2;
  89. /* setup SDRAM chip selects */
  90. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0x0000001c); /* 512MB at 0x0 */
  91. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, 0x80000000);/* disabled */
  92. __asm__ volatile ("sync");
  93. /* setup config registers */
  94. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG1, SDRAM_CONFIG1);
  95. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CONFIG2, SDRAM_CONFIG2);
  96. __asm__ volatile ("sync");
  97. #if SDRAM_DDR
  98. /* set tap delay */
  99. out_be32 ((unsigned __iomem *)MPC5XXX_CDM_PORCFG, SDRAM_TAPDELAY);
  100. __asm__ volatile ("sync");
  101. #endif
  102. /* find RAM size using SDRAM CS0 only */
  103. sdram_start (0);
  104. test1 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  105. sdram_start(1);
  106. test2 = get_ram_size ((long *)CONFIG_SYS_SDRAM_BASE, 0x20000000);
  107. if (test1 > test2) {
  108. sdram_start (0);
  109. dramsize = test1;
  110. } else {
  111. dramsize = test2;
  112. }
  113. /* memory smaller than 1MB is impossible */
  114. if (dramsize < (1 << 20)) {
  115. dramsize = 0;
  116. }
  117. /* set SDRAM CS0 size according to the amount of RAM found */
  118. if (dramsize > 0) {
  119. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG,
  120. (0x13 + __builtin_ffs(dramsize >> 20) - 1));
  121. } else {
  122. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG, 0); /* disabled */
  123. }
  124. /* let SDRAM CS1 start right after CS0 */
  125. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, (dramsize + 0x0000001c));/*512MB*/
  126. /* find RAM size using SDRAM CS1 only */
  127. if (!dramsize)
  128. sdram_start (0);
  129. test2 = test1 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  130. if (!dramsize) {
  131. sdram_start (1);
  132. test2 = get_ram_size ((long *)(CONFIG_SYS_SDRAM_BASE + dramsize), 0x20000000);
  133. }
  134. if (test1 > test2) {
  135. sdram_start (0);
  136. dramsize2 = test1;
  137. } else {
  138. dramsize2 = test2;
  139. }
  140. /* memory smaller than 1MB is impossible */
  141. if (dramsize2 < (1 << 20)) {
  142. dramsize2 = 0;
  143. }
  144. /* set SDRAM CS1 size according to the amount of RAM found */
  145. if (dramsize2 > 0) {
  146. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG,
  147. (dramsize | (0x13 + __builtin_ffs(dramsize2 >> 20) - 1)));
  148. } else {
  149. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG, dramsize); /* disabled */
  150. }
  151. #else /* CONFIG_SYS_RAMBOOT */
  152. /* retrieve size of memory connected to SDRAM CS0 */
  153. dramsize = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS0CFG) & 0xFF;
  154. if (dramsize >= 0x13) {
  155. dramsize = (1 << (dramsize - 0x13)) << 20;
  156. } else {
  157. dramsize = 0;
  158. }
  159. /* retrieve size of memory connected to SDRAM CS1 */
  160. dramsize2 = in_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_CS1CFG) & 0xFF;
  161. if (dramsize2 >= 0x13) {
  162. dramsize2 = (1 << (dramsize2 - 0x13)) << 20;
  163. } else {
  164. dramsize2 = 0;
  165. }
  166. #endif /* CONFIG_SYS_RAMBOOT */
  167. /*
  168. * On MPC5200B we need to set the special configuration delay in the
  169. * DDR controller. Please refer to Freescale's AN3221 "MPC5200B SDRAM
  170. * Initialization and Configuration", 3.3.1 SDelay--MBAR + 0x0190:
  171. *
  172. * "The SDelay should be written to a value of 0x00000004. It is
  173. * required to account for changes caused by normal wafer processing
  174. * parameters."
  175. */
  176. svr = get_svr();
  177. pvr = get_pvr();
  178. if ((SVR_MJREV(svr) >= 2) &&
  179. (PVR_MAJ(pvr) == 1) && (PVR_MIN(pvr) == 4)) {
  180. out_be32 ((unsigned __iomem *)MPC5XXX_SDRAM_SDELAY, 0x04);
  181. __asm__ volatile ("sync");
  182. }
  183. return dramsize + dramsize2;
  184. }
  185. int checkboard (void)
  186. {
  187. puts ("Board: MUC.MC-52 HW WDT ");
  188. #if defined(CONFIG_HW_WATCHDOG)
  189. puts ("enabled\n");
  190. #else
  191. puts ("disabled\n");
  192. #endif
  193. return 0;
  194. }
  195. #ifdef CONFIG_PREBOOT
  196. static uchar kbd_magic_prefix[] = "key_magic";
  197. static uchar kbd_command_prefix[] = "key_cmd";
  198. #define S1_ROT 0xf0
  199. #define S2_Q 0x40
  200. #define S2_M 0x20
  201. struct kbd_data_t {
  202. char s1;
  203. char s2;
  204. };
  205. struct kbd_data_t* get_keys (struct kbd_data_t *kbd_data)
  206. {
  207. kbd_data->s1 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS1_BASE);
  208. kbd_data->s2 = in_8 ((volatile uchar*)CONFIG_SYS_STATUS2_BASE);
  209. return kbd_data;
  210. }
  211. static int compare_magic (const struct kbd_data_t *kbd_data, char *str)
  212. {
  213. char s1 = str[0];
  214. char s2;
  215. if (s1 >= '0' && s1 <= '9')
  216. s1 -= '0';
  217. else if (s1 >= 'a' && s1 <= 'f')
  218. s1 = s1 - 'a' + 10;
  219. else if (s1 >= 'A' && s1 <= 'F')
  220. s1 = s1 - 'A' + 10;
  221. else
  222. return -1;
  223. if (((S1_ROT & kbd_data->s1) >> 4) != s1)
  224. return -1;
  225. s2 = (S2_Q | S2_M) & kbd_data->s2;
  226. switch (str[1]) {
  227. case 'q':
  228. case 'Q':
  229. if (s2 == S2_Q)
  230. return -1;
  231. break;
  232. case 'm':
  233. case 'M':
  234. if (s2 == S2_M)
  235. return -1;
  236. break;
  237. case '\0':
  238. if (s2 == (S2_Q | S2_M))
  239. return 0;
  240. default:
  241. return -1;
  242. }
  243. if (str[2])
  244. return -1;
  245. return 0;
  246. }
  247. static char *key_match (const struct kbd_data_t *kbd_data)
  248. {
  249. char magic[sizeof (kbd_magic_prefix) + 1];
  250. char *suffix;
  251. char *kbd_magic_keys;
  252. /*
  253. * The following string defines the characters that can be appended
  254. * to "key_magic" to form the names of environment variables that
  255. * hold "magic" key codes, i. e. such key codes that can cause
  256. * pre-boot actions. If the string is empty (""), then only
  257. * "key_magic" is checked (old behaviour); the string "125" causes
  258. * checks for "key_magic1", "key_magic2" and "key_magic5", etc.
  259. */
  260. if ((kbd_magic_keys = getenv ("magic_keys")) == NULL)
  261. kbd_magic_keys = "";
  262. /* loop over all magic keys;
  263. * use '\0' suffix in case of empty string
  264. */
  265. for (suffix = kbd_magic_keys; *suffix ||
  266. suffix == kbd_magic_keys; ++suffix) {
  267. sprintf (magic, "%s%c", kbd_magic_prefix, *suffix);
  268. if (compare_magic(kbd_data, getenv(magic)) == 0) {
  269. char cmd_name[sizeof (kbd_command_prefix) + 1];
  270. char *cmd;
  271. sprintf (cmd_name, "%s%c", kbd_command_prefix, *suffix);
  272. cmd = getenv (cmd_name);
  273. return (cmd);
  274. }
  275. }
  276. return (NULL);
  277. }
  278. #endif /* CONFIG_PREBOOT */
  279. int misc_init_r (void)
  280. {
  281. #ifdef CONFIG_PREBOOT
  282. struct kbd_data_t kbd_data;
  283. /* Decode keys */
  284. char *str = strdup (key_match (get_keys (&kbd_data)));
  285. /* Set or delete definition */
  286. setenv ("preboot", str);
  287. free (str);
  288. #endif /* CONFIG_PREBOOT */
  289. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), ' ');
  290. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), ' ');
  291. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), ' ');
  292. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), ' ');
  293. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), ' ');
  294. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), ' ');
  295. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), ' ');
  296. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), ' ');
  297. return 0;
  298. }
  299. int board_early_init_r (void)
  300. {
  301. out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG, in_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_CFG) & ~0x1);
  302. out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_START, START_REG(CONFIG_SYS_FLASH_BASE));
  303. out_be32 ((unsigned __iomem *)MPC5XXX_CS0_START, START_REG(CONFIG_SYS_FLASH_BASE));
  304. out_be32 ((unsigned __iomem *)MPC5XXX_BOOTCS_STOP,
  305. STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
  306. out_be32 ((unsigned __iomem *)MPC5XXX_CS0_STOP,
  307. STOP_REG(CONFIG_SYS_FLASH_BASE, CONFIG_SYS_FLASH_SIZE));
  308. return 0;
  309. }
  310. int last_stage_init (void)
  311. {
  312. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x38), 'M');
  313. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x39), 'U');
  314. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3A), 'C');
  315. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3B), '.');
  316. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3C), 'M');
  317. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3D), 'C');
  318. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3E), '5');
  319. out_8 ((volatile uchar *)(CONFIG_SYS_DISPLAY_BASE + 0x3F), '2');
  320. return 0;
  321. }
  322. #if defined(CONFIG_HW_WATCHDOG)
  323. #define GPT_OUT_0 0x00000027
  324. #define GPT_OUT_1 0x00000037
  325. void hw_watchdog_reset (void)
  326. {
  327. /* Trigger HW Watchdog with TIMER_0 */
  328. out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_1);
  329. out_be32 ((unsigned __iomem *)MPC5XXX_GPT0_ENABLE, GPT_OUT_0);
  330. }
  331. #endif
  332. #ifdef CONFIG_PCI
  333. static struct pci_controller hose;
  334. extern void pci_mpc5xxx_init (struct pci_controller *);
  335. void pci_init_board (void)
  336. {
  337. pci_mpc5xxx_init (&hose);
  338. }
  339. #endif
  340. #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
  341. void ft_board_setup(void *blob, bd_t *bd)
  342. {
  343. ft_cpu_setup(blob, bd);
  344. }
  345. #endif /* defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) */