nc650.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /*
  2. * (C) Copyright 2006 Detlev Zundel, dzu@denx.de
  3. * (C) Copyright 2001
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <config.h>
  26. #include <mpc8xx.h>
  27. /*
  28. * Memory Controller Using
  29. *
  30. * CS0 - Flash memory (0x40000000)
  31. * CS3 - SDRAM (0x00000000}
  32. */
  33. /* ------------------------------------------------------------------------- */
  34. #define _not_used_ 0xffffffff
  35. const uint sdram_table[] = {
  36. /* single read. (offset 0 in upm RAM) */
  37. 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
  38. 0x1ff77c47,
  39. /* MRS initialization (offset 5) */
  40. 0x1ff77c34, 0xefeabc34, 0x1fb57c35,
  41. /* burst read. (offset 8 in upm RAM) */
  42. 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
  43. 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47,
  44. _not_used_, _not_used_, _not_used_, _not_used_,
  45. _not_used_, _not_used_, _not_used_, _not_used_,
  46. /* single write. (offset 18 in upm RAM) */
  47. 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47,
  48. _not_used_, _not_used_, _not_used_, _not_used_,
  49. /* burst write. (offset 20 in upm RAM) */
  50. 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  51. 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _not_used_,
  52. _not_used_, _not_used_, _not_used_, _not_used_,
  53. _not_used_, _not_used_, _not_used_, _not_used_,
  54. /* refresh. (offset 30 in upm RAM) */
  55. 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  56. 0xfffffc84, 0xfffffc07, _not_used_, _not_used_,
  57. _not_used_, _not_used_, _not_used_, _not_used_,
  58. /* exception. (offset 3c in upm RAM) */
  59. 0x7ffffc07, _not_used_, _not_used_, _not_used_
  60. };
  61. const uint nand_flash_table[] = {
  62. /* single read. (offset 0 in upm RAM) */
  63. 0x0ff3fc04, 0x0ff3fc04, 0x0ff3fc04, 0x0ffffc04,
  64. 0xfffffc00, 0xfffffc05, 0xfffffc05, 0xfffffc05,
  65. /* burst read. (offset 8 in upm RAM) */
  66. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  67. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  68. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  69. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  70. /* single write. (offset 18 in upm RAM) */
  71. 0x00fffc04, 0x00fffc04, 0x00fffc04, 0x0ffffc04,
  72. 0x0ffffc84, 0x0ffffc84, 0xfffffc00, 0xfffffc05,
  73. /* burst write. (offset 20 in upm RAM) */
  74. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  75. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  76. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  77. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  78. /* refresh. (offset 30 in upm RAM) */
  79. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  80. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  81. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05,
  82. /* exception. (offset 3c in upm RAM) */
  83. 0xffffcc05, 0xffffcc05, 0xffffcc05, 0xffffcc05
  84. };
  85. /* ------------------------------------------------------------------------- */
  86. /*
  87. * Check Board Identity:
  88. */
  89. int checkboard (void)
  90. {
  91. #if !defined(CONFIG_CP850)
  92. puts ("Board: NC650");
  93. #else
  94. puts ("Board: CP850");
  95. #endif
  96. #if defined(CONFIG_IDS852_REV1)
  97. puts (" with IDS852 rev 1 module\n");
  98. #elif defined(CONFIG_IDS852_REV2)
  99. puts (" with IDS852 rev 2 module\n");
  100. #endif
  101. return 0;
  102. }
  103. /* ------------------------------------------------------------------------- */
  104. static long int dram_size (long int, long int *, long int);
  105. /* ------------------------------------------------------------------------- */
  106. phys_size_t initdram (int board_type)
  107. {
  108. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  109. volatile memctl8xx_t *memctl = &immap->im_memctl;
  110. long int size8, size9;
  111. long int size_b0 = 0;
  112. unsigned long reg;
  113. upmconfig (UPMA, (uint *) sdram_table,
  114. sizeof (sdram_table) / sizeof (uint));
  115. /*
  116. * Preliminary prescaler for refresh (depends on number of
  117. * banks): This value is selected for four cycles every 62.4 us
  118. * with two SDRAM banks or four cycles every 31.2 us with one
  119. * bank. It will be adjusted after memory sizing.
  120. */
  121. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_8K;
  122. memctl->memc_mar = 0x00000088;
  123. /*
  124. * Map controller bank 1 to the SDRAM bank at
  125. * preliminary address - these have to be modified after the
  126. * SDRAM size has been determined.
  127. */
  128. memctl->memc_or3 = CONFIG_SYS_OR3_PRELIM;
  129. memctl->memc_br3 = CONFIG_SYS_BR3_PRELIM;
  130. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  131. udelay (200);
  132. /* perform SDRAM initializsation sequence */
  133. memctl->memc_mcr = 0x80006105; /* SDRAM bank 0 */
  134. udelay (200);
  135. memctl->memc_mcr = 0x80006230; /* SDRAM bank 0 - execute twice */
  136. udelay (200);
  137. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  138. udelay (1000);
  139. /*
  140. * Check Bank 0 Memory Size for re-configuration
  141. *
  142. * try 8 column mode
  143. */
  144. size8 = dram_size (CONFIG_SYS_MAMR_8COL, SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
  145. udelay (1000);
  146. /*
  147. * try 9 column mode
  148. */
  149. size9 = dram_size (CONFIG_SYS_MAMR_9COL, SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
  150. udelay (1000);
  151. if (size8 < size9) {
  152. size_b0 = size9;
  153. } else {
  154. size_b0 = size8;
  155. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
  156. udelay (500);
  157. }
  158. /*
  159. * Adjust refresh rate depending on SDRAM type, both banks.
  160. * For types > 128 MBit leave it at the current (fast) rate
  161. */
  162. if ((size_b0 < 0x02000000)) {
  163. /* reduce to 15.6 us (62.4 us / quad) */
  164. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
  165. udelay (1000);
  166. }
  167. /*
  168. * Final mapping
  169. */
  170. memctl->memc_or3 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  171. memctl->memc_br3 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  172. /* adjust refresh rate depending on SDRAM type, one bank */
  173. reg = memctl->memc_mptpr;
  174. reg >>= 1; /* reduce to CONFIG_SYS_MPTPR_1BK_8K / _4K */
  175. memctl->memc_mptpr = reg;
  176. udelay (10000);
  177. /* Configure UPMB for NAND flash access */
  178. upmconfig (UPMB, (uint *) nand_flash_table,
  179. sizeof (nand_flash_table) / sizeof (uint));
  180. memctl->memc_mbmr = CONFIG_SYS_MBMR_NAND;
  181. return (size_b0);
  182. }
  183. /* ------------------------------------------------------------------------- */
  184. /*
  185. * Check memory range for valid RAM. A simple memory test determines
  186. * the actually available RAM size between addresses `base' and
  187. * `base + maxsize'. Some (not all) hardware errors are detected:
  188. * - short between address lines
  189. * - short between data lines
  190. */
  191. static long int dram_size (long int mamr_value, long int *base, long int maxsize)
  192. {
  193. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  194. volatile memctl8xx_t *memctl = &immap->im_memctl;
  195. memctl->memc_mamr = mamr_value;
  196. return (get_ram_size(base, maxsize));
  197. }
  198. #if defined(CONFIG_CP850)
  199. #define DPRAM_VARNAME "KP850DIP"
  200. #define PARAM_ADDR 0x7C0
  201. #define NAME_ADDR 0x7F8
  202. #define BOARD_NAME "KP01"
  203. #define DEFAULT_LB "241111"
  204. int misc_init_r(void)
  205. {
  206. int iCompatMode = 0;
  207. char *pParam = NULL;
  208. char *envlb;
  209. /*
  210. First byte in CPLD read address space signals compatibility mode
  211. 0 - cp850
  212. 1 - kp852
  213. */
  214. pParam = (char*)(CONFIG_SYS_CPLD_BASE);
  215. if( *pParam != 0)
  216. iCompatMode = 1;
  217. if ( iCompatMode != 0) {
  218. /*
  219. In KP852 compatibility mode we have to write to
  220. DPRAM as early as possible the binary coded
  221. line config and board name.
  222. The line config is derived from the environment
  223. variable DPRAM_VARNAME by converting from ASCII
  224. to binary per character.
  225. */
  226. if ( (envlb = getenv ( DPRAM_VARNAME )) == 0) {
  227. setenv( DPRAM_VARNAME, DEFAULT_LB);
  228. envlb = DEFAULT_LB;
  229. }
  230. /* Status string */
  231. printf("Mode: KP852(LB=%s)\n", envlb);
  232. /* copy appl init */
  233. pParam = (char*)(DPRAM_BASE_ADDR + PARAM_ADDR);
  234. while (*envlb) {
  235. *(pParam++) = *(envlb++) - '0';
  236. }
  237. *pParam = '\0';
  238. /* copy board id */
  239. pParam = (char*)(DPRAM_BASE_ADDR + NAME_ADDR);
  240. strcpy( pParam, BOARD_NAME);
  241. } else {
  242. puts("Mode: CP850\n");
  243. }
  244. return 0;
  245. }
  246. #endif