rbc823.c 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include "mpc8xx.h"
  25. #include <linux/mtd/doc2000.h>
  26. extern int kbd_init(void);
  27. extern int drv_kbd_init(void);
  28. /* ------------------------------------------------------------------------- */
  29. static long int dram_size (long int, long int *, long int);
  30. /* ------------------------------------------------------------------------- */
  31. #define _NOT_USED_ 0xFFFFFFFF
  32. const uint sdram_table[] =
  33. {
  34. /*
  35. * Single Read. (Offset 0 in UPMA RAM)
  36. */
  37. 0x1F07FC04, 0xEEAEFC04, 0x11ADFC04, 0xEFBBBC00,
  38. 0x1FF77C47, /* last */
  39. /*
  40. * SDRAM Initialization (offset 5 in UPMA RAM)
  41. *
  42. * This is no UPM entry point. The following definition uses
  43. * the remaining space to establish an initialization
  44. * sequence, which is executed by a RUN command.
  45. *
  46. */
  47. 0x1FF77C34, 0xEFEABC34, 0x1FB57C35, /* last */
  48. /*
  49. * Burst Read. (Offset 8 in UPMA RAM)
  50. */
  51. 0x1F07FC04, 0xEEAEFC04, 0x10ADFC04, 0xF0AFFC00,
  52. 0xF0AFFC00, 0xF1AFFC00, 0xEFBBBC00, 0x1FF77C47, /* last */
  53. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  54. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  55. /*
  56. * Single Write. (Offset 18 in UPMA RAM)
  57. */
  58. 0x1F27FC04, 0xEEAEBC00, 0x01B93C04, 0x1FF77C47, /* last */
  59. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  60. /*
  61. * Burst Write. (Offset 20 in UPMA RAM)
  62. */
  63. 0x1F07FC04, 0xEEAEBC00, 0x10AD7C00, 0xF0AFFC00,
  64. 0xF0AFFC00, 0xE1BBBC04, 0x1FF77C47, /* last */
  65. _NOT_USED_,
  66. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  67. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  68. /*
  69. * Refresh (Offset 30 in UPMA RAM)
  70. */
  71. 0x1FF5FC84, 0xFFFFFC04, 0xFFFFFC04, 0xFFFFFC04,
  72. 0xFFFFFC84, 0xFFFFFC07, /* last */
  73. _NOT_USED_, _NOT_USED_,
  74. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  75. /*
  76. * Exception. (Offset 3c in UPMA RAM)
  77. */
  78. 0x1FF7FC07, /* last */
  79. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  80. };
  81. const uint static_table[] =
  82. {
  83. /*
  84. * Single Read. (Offset 0 in UPMA RAM)
  85. */
  86. 0x0FFFFC04, 0x0FF3FC04, 0x0FF3CC04, 0x0FF3CC04,
  87. 0x0FF3EC04, 0x0FF3CC00, 0x0FF7FC04, 0x3FFFFC04,
  88. 0xFFFFFC04, 0xFFFFFC05, /* last */
  89. _NOT_USED_, _NOT_USED_,
  90. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  91. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  92. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  93. /*
  94. * Single Write. (Offset 18 in UPMA RAM)
  95. */
  96. 0x0FFFFC04, 0x00FFFC04, 0x00FFFC04, 0x00FFFC04,
  97. 0x01FFFC00, 0x3FFFFC04, 0xFFFFFC04, 0xFFFFFC05, /* last */
  98. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  99. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  100. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  101. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  102. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  103. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  104. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  105. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  106. };
  107. /* ------------------------------------------------------------------------- */
  108. /*
  109. * Check Board Identity:
  110. *
  111. * Test TQ ID string (TQM8xx...)
  112. * If present, check for "L" type (no second DRAM bank),
  113. * otherwise "L" type is assumed as default.
  114. *
  115. * Return 1 for "L" type, 0 else.
  116. */
  117. int checkboard (void)
  118. {
  119. char buf[64];
  120. int i = getenv_f("serial#", buf, sizeof(buf));
  121. if (i < 0 || strncmp(buf, "TQM8", 4)) {
  122. printf ("### No HW ID - assuming RBC823\n");
  123. return (0);
  124. }
  125. puts(buf);
  126. putc('\n');
  127. return (0);
  128. }
  129. /* ------------------------------------------------------------------------- */
  130. phys_size_t initdram (int board_type)
  131. {
  132. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  133. volatile memctl8xx_t *memctl = &immap->im_memctl;
  134. long int size_b0, size8, size9;
  135. upmconfig (UPMA, (uint *) sdram_table,
  136. sizeof (sdram_table) / sizeof (uint));
  137. /*
  138. * 1 Bank of 64Mbit x 2 devices
  139. */
  140. memctl->memc_mptpr = CONFIG_SYS_MPTPR_1BK_4K;
  141. memctl->memc_mar = 0x00000088;
  142. /*
  143. * Map controller SDRAM bank 0
  144. */
  145. memctl->memc_or4 = CONFIG_SYS_OR4_PRELIM;
  146. memctl->memc_br4 = CONFIG_SYS_BR4_PRELIM;
  147. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  148. udelay (200);
  149. /*
  150. * Perform SDRAM initializsation sequence
  151. */
  152. memctl->memc_mcr = 0x80008105; /* SDRAM bank 0 */
  153. udelay (1);
  154. memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_8X;
  155. udelay (200);
  156. memctl->memc_mcr = 0x80008130; /* SDRAM bank 0 - execute twice */
  157. udelay (1);
  158. memctl->memc_mamr = (CONFIG_SYS_MAMR_8COL & ~(MAMR_TLFA_MSK)) | MAMR_TLFA_4X;
  159. udelay (200);
  160. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  161. udelay (1000);
  162. /*
  163. * Preliminary prescaler for refresh (depends on number of
  164. * banks): This value is selected for four cycles every 62.4 us
  165. * with two SDRAM banks or four cycles every 31.2 us with one
  166. * bank. It will be adjusted after memory sizing.
  167. */
  168. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K; /* 16: but should be: CONFIG_SYS_MPTPR_1BK_4K */
  169. /*
  170. * Check Bank 0 Memory Size for re-configuration
  171. *
  172. * try 8 column mode
  173. */
  174. size8 = dram_size (CONFIG_SYS_MAMR_8COL, (long *) SDRAM_BASE4_PRELIM,
  175. SDRAM_MAX_SIZE);
  176. udelay (1000);
  177. /*
  178. * try 9 column mode
  179. */
  180. size9 = dram_size (CONFIG_SYS_MAMR_9COL, (long *) SDRAM_BASE4_PRELIM,
  181. SDRAM_MAX_SIZE);
  182. if (size8 < size9) { /* leave configuration at 9 columns */
  183. size_b0 = size9;
  184. /* debug ("SDRAM Bank 0 in 9 column mode: %ld MB\n", size >> 20); */
  185. } else { /* back to 8 columns */
  186. size_b0 = size8;
  187. memctl->memc_mamr = CONFIG_SYS_MAMR_8COL;
  188. udelay (500);
  189. /* debug ("SDRAM Bank 0 in 8 column mode: %ld MB\n", size >> 20); */
  190. }
  191. udelay (1000);
  192. /*
  193. * Adjust refresh rate depending on SDRAM type, both banks
  194. * For types > 128 MBit leave it at the current (fast) rate
  195. */
  196. if ((size_b0 < 0x02000000)) {
  197. /* reduce to 15.6 us (62.4 us / quad) */
  198. memctl->memc_mptpr = CONFIG_SYS_MPTPR_2BK_4K;
  199. udelay (1000);
  200. }
  201. /* SDRAM Bank 0 is bigger - map first */
  202. memctl->memc_or4 = ((-size_b0) & 0xFFFF0000) | CONFIG_SYS_OR_TIMING_SDRAM;
  203. memctl->memc_br4 = (CONFIG_SYS_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  204. udelay (10000);
  205. return (size_b0);
  206. }
  207. /* ------------------------------------------------------------------------- */
  208. /*
  209. * Check memory range for valid RAM. A simple memory test determines
  210. * the actually available RAM size between addresses `base' and
  211. * `base + maxsize'. Some (not all) hardware errors are detected:
  212. * - short between address lines
  213. * - short between data lines
  214. */
  215. static long int dram_size (long int mamr_value, long int *base,
  216. long int maxsize)
  217. {
  218. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  219. volatile memctl8xx_t *memctl = &immap->im_memctl;
  220. memctl->memc_mamr = mamr_value;
  221. return (get_ram_size (base, maxsize));
  222. }
  223. #ifdef CONFIG_CMD_DOC
  224. void doc_init (void)
  225. {
  226. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  227. volatile memctl8xx_t *memctl = &immap->im_memctl;
  228. upmconfig (UPMB, (uint *) static_table,
  229. sizeof (static_table) / sizeof (uint));
  230. memctl->memc_mbmr = MAMR_DSA_1_CYCL;
  231. doc_probe (FLASH_BASE1_PRELIM);
  232. }
  233. #endif