mucmc52.c 11 KB

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