mvs1.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * (C) Copyright 2000
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Changes for MATRIX Vision MVsensor (C) Copyright 2001
  6. * MATRIX Vision GmbH / hg, info@matrix-vision.de
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <mpc8xx.h>
  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. 0x1F0DFC04, 0xEEAFBC04, 0x11AF7C04, 0xEFBAFC00,
  38. 0x1FF5FC47, /* 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. 0x1FF5FC34, 0xEFEABC34, 0x1FB57C35, /* last */
  48. /*
  49. * Burst Read. (Offset 8 in UPMA RAM)
  50. */
  51. 0x1F0DFC04, 0xEEAFBC04, 0x10AF7C04, 0xF0AFFC00,
  52. 0xF0AFFC00, 0xF1AFFC00, 0xEFBAFC00, 0x1FF5FC47, /* 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. 0x1F0DFC04 /*0x1F2DFC04??*/, 0xEEABBC00, 0x01B27C04, 0x1FF5FC47, /* last */
  59. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  60. /*
  61. * Burst Write. (Offset 20 in UPMA RAM)
  62. */
  63. 0x1F0DFC04, 0xEEABBC00, 0x10A77C00, 0xF0AFFC00,
  64. 0xF0AFFC00, 0xE1BAFC04, 0x1FF5FC47, /* 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. 0x1FFD7C84, 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. 0x7FFFFC07, /* last */
  79. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  80. };
  81. /* ------------------------------------------------------------------------- */
  82. /*
  83. * Check Board Identity:
  84. */
  85. int checkboard (void)
  86. {
  87. puts ("Board: MATRIX Vision MVsensor\n");
  88. return 0;
  89. }
  90. #ifdef DO_RAM_TEST
  91. /* ------------------------------------------------------------------------- */
  92. /*
  93. * Test SDRAM by writing its address to itself and reading several times
  94. */
  95. #define READ_RUNS 4
  96. static void test_dram (unsigned long *start, unsigned long *end)
  97. {
  98. unsigned long *addr;
  99. unsigned long value;
  100. int read_runs, errors, addr_errors;
  101. printf ("\nChecking SDRAM from %p to %p\n", start, end);
  102. udelay (1000000);
  103. for (addr = start; addr < end; addr++)
  104. *addr = (unsigned long) addr;
  105. for (addr = start, addr_errors = 0; addr < end; addr++) {
  106. for (read_runs = READ_RUNS, errors = 0; read_runs > 0; read_runs--) {
  107. if ((value = *addr) != (unsigned long) addr)
  108. errors++;
  109. }
  110. if (errors > 0) {
  111. addr_errors++;
  112. printf ("SDRAM errors (%d) at %p, last read = %ld\n",
  113. errors, addr, value);
  114. udelay (10000);
  115. }
  116. }
  117. printf ("SDRAM check finished, total errors = %d\n", addr_errors);
  118. }
  119. #endif /* DO_RAM_TEST */
  120. /* ------------------------------------------------------------------------- */
  121. long int initdram (int board_type)
  122. {
  123. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  124. volatile memctl8xx_t *memctl = &immap->im_memctl;
  125. long int size_b0, size_b1, size8, size9;
  126. upmconfig (UPMA, (uint *) sdram_table,
  127. sizeof (sdram_table) / sizeof (uint));
  128. /*
  129. * Preliminary prescaler for refresh (depends on number of
  130. * banks): This value is selected for four cycles every 62.4 us
  131. * with two SDRAM banks or four cycles every 31.2 us with one
  132. * bank. It will be adjusted after memory sizing.
  133. */
  134. memctl->memc_mptpr = CFG_MPTPR_2BK_8K;
  135. memctl->memc_mar = 0x00000088;
  136. /*
  137. * Map controller banks 2 and 3 to the SDRAM banks 2 and 3 at
  138. * preliminary addresses - these have to be modified after the
  139. * SDRAM size has been determined.
  140. */
  141. memctl->memc_or2 = CFG_OR2_PRELIM;
  142. memctl->memc_br2 = CFG_BR2_PRELIM;
  143. #if defined (CFG_OR3_PRELIM) && defined (CFG_BR3_PRELIM)
  144. if (board_type == 0) { /* "L" type boards have only one bank SDRAM */
  145. memctl->memc_or3 = CFG_OR3_PRELIM;
  146. memctl->memc_br3 = CFG_BR3_PRELIM;
  147. }
  148. #endif
  149. memctl->memc_mamr = CFG_MAMR_8COL & (~(MAMR_PTAE)); /* no refresh yet */
  150. udelay (200);
  151. /* perform SDRAM initializsation sequence */
  152. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  153. udelay (1);
  154. memctl->memc_mcr = 0x80004230; /* SDRAM bank 0 - execute twice */
  155. udelay (1);
  156. if (board_type == 0) { /* "L" type boards have only one bank SDRAM */
  157. memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
  158. udelay (1);
  159. memctl->memc_mcr = 0x80006230; /* SDRAM bank 1 - execute twice */
  160. udelay (1);
  161. }
  162. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  163. udelay (1000);
  164. /*
  165. * Check Bank 0 Memory Size for re-configuration
  166. *
  167. * try 8 column mode
  168. */
  169. size8 = dram_size (CFG_MAMR_8COL, SDRAM_BASE2_PRELIM,
  170. SDRAM_MAX_SIZE);
  171. udelay (1000);
  172. /*
  173. * try 9 column mode
  174. */
  175. size9 = dram_size (CFG_MAMR_9COL, SDRAM_BASE2_PRELIM,
  176. SDRAM_MAX_SIZE);
  177. if (size8 < size9) { /* leave configuration at 9 columns */
  178. size_b0 = size9;
  179. } else { /* back to 8 columns */
  180. size_b0 = size8;
  181. memctl->memc_mamr = CFG_MAMR_8COL;
  182. udelay (500);
  183. }
  184. if (board_type == 0) { /* "L" type boards have only one bank SDRAM */
  185. /*
  186. * Check Bank 1 Memory Size
  187. * use current column settings
  188. * [9 column SDRAM may also be used in 8 column mode,
  189. * but then only half the real size will be used.]
  190. */
  191. #if defined (SDRAM_BASE3_PRELIM)
  192. size_b1 =
  193. dram_size (memctl->memc_mamr, (ulong *) SDRAM_BASE3_PRELIM,
  194. SDRAM_MAX_SIZE);
  195. #else
  196. size_b1 = 0;
  197. #endif
  198. } else {
  199. size_b1 = 0;
  200. }
  201. udelay (1000);
  202. /*
  203. * Adjust refresh rate depending on SDRAM type, both banks
  204. * For types > 128 MBit leave it at the current (fast) rate
  205. */
  206. if ((size_b0 < 0x02000000) && (size_b1 < 0x02000000)) {
  207. /* reduce to 15.6 us (62.4 us / quad) */
  208. memctl->memc_mptpr = CFG_MPTPR_2BK_4K;
  209. udelay (1000);
  210. }
  211. /*
  212. * Final mapping: map bigger bank first
  213. */
  214. if (size_b1 > size_b0) { /* SDRAM Bank 1 is bigger - map first */
  215. memctl->memc_or3 = ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  216. memctl->memc_br3 =
  217. (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  218. if (size_b0 > 0) {
  219. /*
  220. * Position Bank 0 immediately above Bank 1
  221. */
  222. memctl->memc_or2 =
  223. ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  224. memctl->memc_br2 =
  225. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  226. + size_b1;
  227. } else {
  228. unsigned long reg;
  229. /*
  230. * No bank 0
  231. *
  232. * invalidate bank
  233. */
  234. memctl->memc_br2 = 0;
  235. /* adjust refresh rate depending on SDRAM type, one bank */
  236. reg = memctl->memc_mptpr;
  237. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  238. memctl->memc_mptpr = reg;
  239. }
  240. } else { /* SDRAM Bank 0 is bigger - map first */
  241. memctl->memc_or2 = ((-size_b0) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  242. memctl->memc_br2 =
  243. (CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V;
  244. if (size_b1 > 0) {
  245. /*
  246. * Position Bank 1 immediately above Bank 0
  247. */
  248. memctl->memc_or3 =
  249. ((-size_b1) & 0xFFFF0000) | CFG_OR_TIMING_SDRAM;
  250. memctl->memc_br3 =
  251. ((CFG_SDRAM_BASE & BR_BA_MSK) | BR_MS_UPMA | BR_V)
  252. + size_b0;
  253. } else {
  254. unsigned long reg;
  255. /*
  256. * No bank 1
  257. *
  258. * invalidate bank
  259. */
  260. memctl->memc_br3 = 0;
  261. /* adjust refresh rate depending on SDRAM type, one bank */
  262. reg = memctl->memc_mptpr;
  263. reg >>= 1; /* reduce to CFG_MPTPR_1BK_8K / _4K */
  264. memctl->memc_mptpr = reg;
  265. }
  266. }
  267. udelay (10000);
  268. #ifdef DO_RAM_TEST
  269. if (size_b0 > 0)
  270. test_dram ((unsigned long *) CFG_SDRAM_BASE,
  271. (unsigned long *) (CFG_SDRAM_BASE + size_b0));
  272. #endif
  273. return (size_b0 + size_b1);
  274. }
  275. /* ------------------------------------------------------------------------- */
  276. /*
  277. * Check memory range for valid RAM. A simple memory test determines
  278. * the actually available RAM size between addresses `base' and
  279. * `base + maxsize'. Some (not all) hardware errors are detected:
  280. * - short between address lines
  281. * - short between data lines
  282. */
  283. static long int dram_size (long int mamr_value, long int *base,
  284. long int maxsize)
  285. {
  286. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  287. volatile memctl8xx_t *memctl = &immap->im_memctl;
  288. memctl->memc_mamr = mamr_value;
  289. return (get_ram_size(base, maxsize));
  290. }
  291. /* ------------------------------------------------------------------------- */
  292. u8 *dhcp_vendorex_prep (u8 * e)
  293. {
  294. char *ptr;
  295. /* DHCP vendor-class-identifier = 60 */
  296. if ((ptr = getenv ("dhcp_vendor-class-identifier"))) {
  297. *e++ = 60;
  298. *e++ = strlen (ptr);
  299. while (*ptr)
  300. *e++ = *ptr++;
  301. }
  302. /* my DHCP_CLIENT_IDENTIFIER = 61 */
  303. if ((ptr = getenv ("dhcp_client_id"))) {
  304. *e++ = 61;
  305. *e++ = strlen (ptr);
  306. while (*ptr)
  307. *e++ = *ptr++;
  308. }
  309. return e;
  310. }
  311. /* ------------------------------------------------------------------------- */
  312. u8 *dhcp_vendorex_proc (u8 * popt)
  313. {
  314. return NULL;
  315. }