fads.c 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Modified by, Yuli Barcohen, Arabella Software Ltd., yuli@arabellasw.com
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. */
  9. #include <config.h>
  10. #include <common.h>
  11. #include <mpc8xx.h>
  12. #include <pcmcia.h>
  13. #define _NOT_USED_ 0xFFFFFFFF
  14. /* ========================================================================= */
  15. #ifndef CONFIG_MPC885ADS /* No old DRAM on MPC885ADS */
  16. #if defined(CONFIG_DRAM_50MHZ)
  17. /* 50MHz tables */
  18. static const uint dram_60ns[] =
  19. { 0x8fffec24, 0x0fffec04, 0x0cffec04, 0x00ffec04,
  20. 0x00ffec00, 0x37ffec47, _NOT_USED_, _NOT_USED_,
  21. 0x8fffec24, 0x0fffec04, 0x08ffec04, 0x00ffec0c,
  22. 0x03ffec00, 0x00ffec44, 0x00ffcc08, 0x0cffcc44,
  23. 0x00ffec0c, 0x03ffec00, 0x00ffec44, 0x00ffcc00,
  24. 0x3fffc847, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  25. 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x11bfcc47,
  26. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  27. 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x03afcc4c,
  28. 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
  29. 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
  30. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  31. 0xc0ffcc84, 0x00ffcc04, 0x07ffcc04, 0x3fffcc06,
  32. 0xffffcc85, 0xffffcc05, _NOT_USED_, _NOT_USED_,
  33. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  34. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  35. static const uint dram_70ns[] =
  36. { 0x8fffcc24, 0x0fffcc04, 0x0cffcc04, 0x00ffcc04,
  37. 0x00ffcc00, 0x37ffcc47, _NOT_USED_, _NOT_USED_,
  38. 0x8fffcc24, 0x0fffcc04, 0x0cffcc04, 0x00ffcc04,
  39. 0x00ffcc08, 0x0cffcc44, 0x00ffec0c, 0x03ffec00,
  40. 0x00ffec44, 0x00ffcc08, 0x0cffcc44, 0x00ffec04,
  41. 0x00ffec00, 0x3fffec47, _NOT_USED_, _NOT_USED_,
  42. 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x11bfcc47,
  43. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  44. 0x8fafcc24, 0x0fafcc04, 0x0cafcc00, 0x03afcc4c,
  45. 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
  46. 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
  47. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  48. 0xe0ffcc84, 0x00ffcc04, 0x00ffcc04, 0x0fffcc04,
  49. 0x7fffcc06, 0xffffcc85, 0xffffcc05, _NOT_USED_,
  50. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  51. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  52. static const uint edo_60ns[] =
  53. { 0x8ffbec24, 0x0ff3ec04, 0x0cf3ec04, 0x00f3ec04,
  54. 0x00f3ec00, 0x37f7ec47, _NOT_USED_, _NOT_USED_,
  55. 0x8fffec24, 0x0ffbec04, 0x0cf3ec04, 0x00f3ec0c,
  56. 0x0cf3ec00, 0x00f3ec4c, 0x0cf3ec00, 0x00f3ec4c,
  57. 0x0cf3ec00, 0x00f3ec44, 0x03f3ec00, 0x3ff7ec47,
  58. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  59. 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x11bfcc47,
  60. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  61. 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x03afcc4c,
  62. 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
  63. 0x0cafcc00, 0x33bfcc4f, _NOT_USED_, _NOT_USED_,
  64. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  65. 0xc0ffcc84, 0x00ffcc04, 0x07ffcc04, 0x3fffcc06,
  66. 0xffffcc85, 0xffffcc05, _NOT_USED_, _NOT_USED_,
  67. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  68. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  69. static const uint edo_70ns[] =
  70. { 0x8ffbcc24, 0x0ff3cc04, 0x0cf3cc04, 0x00f3cc04,
  71. 0x00f3cc00, 0x37f7cc47, _NOT_USED_, _NOT_USED_,
  72. 0x8fffcc24, 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc0c,
  73. 0x03f3cc00, 0x00f3cc44, 0x00f3ec0c, 0x0cf3ec00,
  74. 0x00f3ec4c, 0x03f3ec00, 0x00f3ec44, 0x00f3cc00,
  75. 0x33f7cc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  76. 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x11bfcc47,
  77. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  78. 0x8fffcc24, 0x0fefcc04, 0x0cafcc00, 0x03afcc4c,
  79. 0x0cafcc00, 0x03afcc4c, 0x0cafcc00, 0x03afcc4c,
  80. 0x0cafcc00, 0x33bfcc47, _NOT_USED_, _NOT_USED_,
  81. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  82. 0xe0ffcc84, 0x00ffcc04, 0x00ffcc04, 0x0fffcc04,
  83. 0x7fffcc04, 0xffffcc86, 0xffffcc05, _NOT_USED_,
  84. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  85. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  86. #elif defined(CONFIG_DRAM_25MHZ)
  87. /* 25MHz tables */
  88. static const uint dram_60ns[] =
  89. { 0x0fffcc04, 0x08ffcc00, 0x33ffcc47, _NOT_USED_,
  90. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  91. 0x0fffcc24, 0x0fffcc04, 0x08ffcc00, 0x03ffcc4c,
  92. 0x08ffcc00, 0x03ffcc4c, 0x08ffcc00, 0x03ffcc4c,
  93. 0x08ffcc00, 0x33ffcc47, _NOT_USED_, _NOT_USED_,
  94. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  95. 0x0fafcc04, 0x08afcc00, 0x3fbfcc47, _NOT_USED_,
  96. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  97. 0x0fafcc04, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
  98. 0x01afcc4c, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
  99. 0x31bfcc43, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  100. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  101. 0x80ffcc84, 0x13ffcc04, 0xffffcc87, 0xffffcc05,
  102. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  103. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  104. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  105. static const uint dram_70ns[] =
  106. { 0x0fffec04, 0x08ffec04, 0x00ffec00, 0x3fffcc47,
  107. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  108. 0x0fffcc24, 0x0fffcc04, 0x08ffcc00, 0x03ffcc4c,
  109. 0x08ffcc00, 0x03ffcc4c, 0x08ffcc00, 0x03ffcc4c,
  110. 0x08ffcc00, 0x33ffcc47, _NOT_USED_, _NOT_USED_,
  111. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  112. 0x0fafcc04, 0x08afcc00, 0x3fbfcc47, _NOT_USED_,
  113. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  114. 0x0fafcc04, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
  115. 0x01afcc4c, 0x0cafcc00, 0x01afcc4c, 0x0cafcc00,
  116. 0x31bfcc43, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  117. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  118. 0xc0ffcc84, 0x01ffcc04, 0x7fffcc86, 0xffffcc05,
  119. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  120. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  121. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  122. static const uint edo_60ns[] =
  123. { 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc00, 0x33f7cc47,
  124. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  125. 0x0ffbcc04, 0x09f3cc0c, 0x09f3cc0c, 0x09f3cc0c,
  126. 0x08f3cc00, 0x3ff7cc47, _NOT_USED_, _NOT_USED_,
  127. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  128. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  129. 0x0fefcc04, 0x08afcc04, 0x00afcc00, 0x3fbfcc47,
  130. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  131. 0x0fefcc04, 0x08afcc00, 0x07afcc48, 0x08afcc48,
  132. 0x08afcc48, 0x39bfcc47, _NOT_USED_, _NOT_USED_,
  133. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  134. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  135. 0x80ffcc84, 0x13ffcc04, 0xffffcc87, 0xffffcc05,
  136. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  137. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  138. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  139. static const uint edo_70ns[] =
  140. { 0x0ffbcc04, 0x0cf3cc04, 0x00f3cc00, 0x33f7cc47,
  141. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  142. 0x0ffbec04, 0x08f3ec04, 0x03f3ec48, 0x08f3cc00,
  143. 0x0ff3cc4c, 0x08f3cc00, 0x0ff3cc4c, 0x08f3cc00,
  144. 0x3ff7cc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  145. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  146. 0x0fefcc04, 0x08afcc04, 0x00afcc00, 0x3fbfcc47,
  147. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  148. 0x0fefcc04, 0x08afcc00, 0x07afcc4c, 0x08afcc00,
  149. 0x07afcc4c, 0x08afcc00, 0x07afcc4c, 0x08afcc00,
  150. 0x37bfcc47, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  151. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  152. 0xc0ffcc84, 0x01ffcc04, 0x7fffcc86, 0xffffcc05,
  153. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  154. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  155. 0x33ffcc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  156. #else
  157. #error dram not correctly defined - use CONFIG_DRAM_25MHZ or CONFIG_DRAM_50MHZ
  158. #endif
  159. /* ------------------------------------------------------------------------- */
  160. static int _draminit (uint base, uint noMbytes, uint edo, uint delay)
  161. {
  162. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  163. volatile memctl8xx_t *memctl = &immap->im_memctl;
  164. /* init upm */
  165. switch (delay) {
  166. case 70:
  167. if (edo) {
  168. upmconfig (UPMA, (uint *) edo_70ns,
  169. sizeof (edo_70ns) / sizeof (uint));
  170. } else {
  171. upmconfig (UPMA, (uint *) dram_70ns,
  172. sizeof (dram_70ns) / sizeof (uint));
  173. }
  174. break;
  175. case 60:
  176. if (edo) {
  177. upmconfig (UPMA, (uint *) edo_60ns,
  178. sizeof (edo_60ns) / sizeof (uint));
  179. } else {
  180. upmconfig (UPMA, (uint *) dram_60ns,
  181. sizeof (dram_60ns) / sizeof (uint));
  182. }
  183. break;
  184. default:
  185. return -1;
  186. }
  187. memctl->memc_mptpr = 0x0400; /* divide by 16 */
  188. switch (noMbytes) {
  189. case 4: /* 4 Mbyte uses only CS2 */
  190. memctl->memc_mamr = 0x13a01114; /* PTA 0x13 AMA 010 */
  191. memctl->memc_or2 = 0xffc00800; /* 4M */
  192. break;
  193. case 8: /* 8 Mbyte uses both CS3 and CS2 */
  194. memctl->memc_mamr = 0x13a01114; /* PTA 0x13 AMA 010 */
  195. memctl->memc_or3 = 0xffc00800; /* 4M */
  196. memctl->memc_br3 = 0x00400081 + base;
  197. memctl->memc_or2 = 0xffc00800; /* 4M */
  198. break;
  199. case 16: /* 16 Mbyte uses only CS2 */
  200. memctl->memc_mamr = 0x13b01114; /* PTA 0x13 AMA 011 */
  201. memctl->memc_or2 = 0xff000800; /* 16M */
  202. break;
  203. case 32: /* 32 Mbyte uses both CS3 and CS2 */
  204. memctl->memc_mamr = 0x13b01114; /* PTA 0x13 AMA 011 */
  205. memctl->memc_or3 = 0xff000800; /* 16M */
  206. memctl->memc_br3 = 0x01000081 + base;
  207. memctl->memc_or2 = 0xff000800; /* 16M */
  208. break;
  209. default:
  210. return -1;
  211. }
  212. memctl->memc_br2 = 0x81 + base; /* use upma */
  213. *((uint *) BCSR1) &= ~BCSR1_DRAM_EN; /* enable dram */
  214. /* if no dimm is inserted, noMbytes is still detected as 8m, so
  215. * sanity check top and bottom of memory */
  216. /* check bytes / 2 because get_ram_size tests at base+bytes, which
  217. * is not mapped */
  218. if (noMbytes == 8)
  219. if (get_ram_size ((long *) base, noMbytes << 19) != noMbytes << 19) {
  220. *((uint *) BCSR1) |= BCSR1_DRAM_EN; /* disable dram */
  221. return -1;
  222. }
  223. return 0;
  224. }
  225. /* ------------------------------------------------------------------------- */
  226. static void _dramdisable(void)
  227. {
  228. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  229. volatile memctl8xx_t *memctl = &immap->im_memctl;
  230. memctl->memc_br2 = 0x00000000;
  231. memctl->memc_br3 = 0x00000000;
  232. /* maybe we should turn off upma here or something */
  233. }
  234. #endif /* !CONFIG_MPC885ADS */
  235. /* ========================================================================= */
  236. #ifdef CONFIG_FADS /* SDRAM exists on FADS and newer boards */
  237. #if defined(CONFIG_SDRAM_100MHZ)
  238. /* ------------------------------------------------------------------------- */
  239. /* sdram table by Dan Malek */
  240. /* This has the stretched early timing so the 50 MHz
  241. * processor can make the 100 MHz timing. This will
  242. * work at all processor speeds.
  243. */
  244. #ifdef SDRAM_ALT_INIT_SEQENCE
  245. # define SDRAM_MBMRVALUE0 0xc3802114 /* PTx=195,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=4 */
  246. #define SDRAM_MBMRVALUE1 SDRAM_MBMRVALUE0
  247. # define SDRAM_MCRVALUE0 0x80808111 /* run upmb cs4 loop 1 addr 0x11 MRS */
  248. # define SDRAM_MCRVALUE1 SDRAM_MCRVALUE0 /* ??? why not 0x80808130? */
  249. #else
  250. # define SDRAM_MxMR_PTx 195
  251. # define UPM_MRS_ADDR 0x11
  252. # define UPM_REFRESH_ADDR 0x30 /* or 0x11 if we want to be like above? */
  253. #endif /* !SDRAM_ALT_INIT_SEQUENCE */
  254. static const uint sdram_table[] =
  255. {
  256. /* single read. (offset 0 in upm RAM) */
  257. 0xefebfc24, 0x1f07fc24, 0xeeaefc04, 0x11adfc04,
  258. 0xefbbbc00, 0x1ff77c45, _NOT_USED_, _NOT_USED_,
  259. /* burst read. (offset 8 in upm RAM) */
  260. 0xefebfc24, 0x1f07fc24, 0xeeaefc04, 0x10adfc04,
  261. 0xf0affc00, 0xf0affc00, 0xf1affc00, 0xefbbbc00,
  262. 0x1ff77c45,
  263. /* precharge + MRS. (offset 11 in upm RAM) */
  264. 0xeffbbc04, 0x1ff77c34, 0xefeabc34,
  265. 0x1fb57c35, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  266. /* single write. (offset 18 in upm RAM) */
  267. 0xefebfc24, 0x1f07fc24, 0xeeaebc00, 0x01b93c04,
  268. 0x1ff77c45, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  269. /* burst write. (offset 20 in upm RAM) */
  270. 0xefebfc24, 0x1f07fc24, 0xeeaebc00, 0x10ad7c00,
  271. 0xf0affc00, 0xf0affc00, 0xe1bbbc04, 0x1ff77c45,
  272. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  273. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  274. /* refresh. (offset 30 in upm RAM) */
  275. 0xeffafc84, 0x1ff5fc04, 0xfffffc04, 0xfffffc04,
  276. 0xfffffc84, 0xfffffc07, _NOT_USED_, _NOT_USED_,
  277. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  278. /* exception. (offset 3c in upm RAM) */
  279. 0xeffffc06, 0x1ffffc07, _NOT_USED_, _NOT_USED_ };
  280. #elif defined(CONFIG_SDRAM_50MHZ)
  281. /* ------------------------------------------------------------------------- */
  282. /* sdram table stolen from the fads manual */
  283. /* for chip MB811171622A-100 */
  284. /* this table is for 32-50MHz operation */
  285. #ifdef SDRAM_ALT_INIT_SEQENCE
  286. # define SDRAM_MBMRVALUE0 0x80802114 /* PTx=128,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=4 */
  287. # define SDRAM_MBMRVALUE1 0x80802118 /* PTx=128,PTxE,AMx=0,DSx=1,A11,RLFx=1,WLFx=1,TLFx=8 */
  288. # define SDRAM_MCRVALUE0 0x80808105 /* run upmb cs4 loop 1 addr 0x5 MRS */
  289. # define SDRAM_MCRVALUE1 0x80808130 /* run upmb cs4 loop 1 addr 0x30 REFRESH */
  290. # define SDRAM_MPTRVALUE 0x400
  291. #define SDRAM_MARVALUE 0x88
  292. #else
  293. # define SDRAM_MxMR_PTx 128
  294. # define UPM_MRS_ADDR 0x5
  295. # define UPM_REFRESH_ADDR 0x30
  296. #endif /* !SDRAM_ALT_INIT_SEQUENCE */
  297. static const uint sdram_table[] =
  298. {
  299. /* single read. (offset 0 in upm RAM) */
  300. 0x1f07fc04, 0xeeaefc04, 0x11adfc04, 0xefbbbc00,
  301. 0x1ff77c47,
  302. /* precharge + MRS. (offset 5 in upm RAM) */
  303. 0x1ff77c34, 0xefeabc34, 0x1fb57c35,
  304. /* burst read. (offset 8 in upm RAM) */
  305. 0x1f07fc04, 0xeeaefc04, 0x10adfc04, 0xf0affc00,
  306. 0xf0affc00, 0xf1affc00, 0xefbbbc00, 0x1ff77c47,
  307. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  308. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  309. /* single write. (offset 18 in upm RAM) */
  310. 0x1f27fc04, 0xeeaebc00, 0x01b93c04, 0x1ff77c47,
  311. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  312. /* burst write. (offset 20 in upm RAM) */
  313. 0x1f07fc04, 0xeeaebc00, 0x10ad7c00, 0xf0affc00,
  314. 0xf0affc00, 0xe1bbbc04, 0x1ff77c47, _NOT_USED_,
  315. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  316. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  317. /* refresh. (offset 30 in upm RAM) */
  318. 0x1ff5fc84, 0xfffffc04, 0xfffffc04, 0xfffffc04,
  319. 0xfffffc84, 0xfffffc07, _NOT_USED_, _NOT_USED_,
  320. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  321. /* exception. (offset 3c in upm RAM) */
  322. 0x7ffffc07, _NOT_USED_, _NOT_USED_, _NOT_USED_ };
  323. /* ------------------------------------------------------------------------- */
  324. #else
  325. #error SDRAM not correctly configured
  326. #endif
  327. /* ------------------------------------------------------------------------- */
  328. /*
  329. * Memory Periodic Timer Prescaler
  330. */
  331. #define SDRAM_OR4VALUE 0x00000a00 /* SAM,GL5A/S=01,addr mask or'ed on later */
  332. #define SDRAM_BR4VALUE 0x000000c1 /* UPMB,base addr or'ed on later */
  333. /* ------------------------------------------------------------------------- */
  334. #ifdef SDRAM_ALT_INIT_SEQENCE
  335. /* ------------------------------------------------------------------------- */
  336. static int _initsdram(uint base, uint noMbytes)
  337. {
  338. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  339. volatile memctl8xx_t *memctl = &immap->im_memctl;
  340. upmconfig(UPMB, (uint *)sdram_table,sizeof(sdram_table)/sizeof(uint));
  341. memctl->memc_mptpr = SDRAM_MPTPRVALUE;
  342. /* Configure the refresh (mostly). This needs to be
  343. * based upon processor clock speed and optimized to provide
  344. * the highest level of performance. For multiple banks,
  345. * this time has to be divided by the number of banks.
  346. * Although it is not clear anywhere, it appears the
  347. * refresh steps through the chip selects for this UPM
  348. * on each refresh cycle.
  349. * We have to be careful changing
  350. * UPM registers after we ask it to run these commands.
  351. */
  352. memctl->memc_mbmr = SDRAM_MBMRVALUE0; /* TLF 4 */
  353. memctl->memc_mar = SDRAM_MARVALUE; /* MRS code */
  354. udelay(200);
  355. /* Now run the precharge/nop/mrs commands.
  356. */
  357. memctl->memc_mcr = 0x80808111; /* run umpb cs4 1 count 1, addr 0x11 ??? (50MHz) */
  358. /* run umpb cs4 1 count 1, addr 0x11 precharge+MRS (100MHz) */
  359. udelay(200);
  360. /* Run 8 refresh cycles */
  361. memctl->memc_mcr = SDRAM_MCRVALUE0; /* run upmb cs4 loop 1 addr 0x5 precharge+MRS (50 MHz)*/
  362. /* run upmb cs4 loop 1 addr 0x11 precharge+MRS (100MHz) */
  363. udelay(200);
  364. memctl->memc_mbmr = SDRAM_MBMRVALUE1; /* TLF 4 (100 MHz) or TLF 8 (50MHz) */
  365. memctl->memc_mcr = SDRAM_MCRVALUE1; /* run upmb cs4 loop 1 addr 0x30 refr (50 MHz) */
  366. /* run upmb cs4 loop 1 addr 0x11 precharge+MRS ??? (100MHz) */
  367. udelay(200);
  368. memctl->memc_mbmr = SDRAM_MBMRVALUE0; /* TLF 4 */
  369. memctl->memc_or4 = SDRAM_OR4VALUE | ~((noMbytes<<20)-1);
  370. memctl->memc_br4 = SDRAM_BR4VALUE | base;
  371. return 0;
  372. }
  373. /* ------------------------------------------------------------------------- */
  374. #else /* !SDRAM_ALT_INIT_SEQUENCE */
  375. /* ------------------------------------------------------------------------- */
  376. /* refresh rate 15.6 us (= 64 ms / 4K = 62.4 / quad bursts) for <= 128 MBit */
  377. # define MPTPR_2BK_4K MPTPR_PTP_DIV16 /* setting for 2 banks */
  378. # define MPTPR_1BK_4K MPTPR_PTP_DIV32 /* setting for 1 bank */
  379. /* refresh rate 7.8 us (= 64 ms / 8K = 31.2 / quad bursts) for 256 MBit */
  380. # define MPTPR_2BK_8K MPTPR_PTP_DIV8 /* setting for 2 banks */
  381. # define MPTPR_1BK_8K MPTPR_PTP_DIV16 /* setting for 1 bank */
  382. /*
  383. * MxMR settings for SDRAM
  384. */
  385. /* 8 column SDRAM */
  386. # define SDRAM_MxMR_8COL ((SDRAM_MxMR_PTx << MBMR_PTB_SHIFT) | MBMR_PTBE | \
  387. MBMR_AMB_TYPE_0 | MBMR_DSB_1_CYCL | MBMR_G0CLB_A11 | \
  388. MBMR_RLFB_1X | MBMR_WLFB_1X | MBMR_TLFB_4X)
  389. /* 9 column SDRAM */
  390. # define SDRAM_MxMR_9COL ((SDRAM_MxMR_PTx << MBMR_PTB_SHIFT) | MBMR_PTAE | \
  391. MBMR_AMB_TYPE_1 | MBMR_DSB_1_CYCL | MBMR_G0CLB_A10 | \
  392. MBMR_RLFB_1X | MBMR_WLFB_1X | MBMR_TLFB_4X)
  393. static int _initsdram(uint base, uint noMbytes)
  394. {
  395. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  396. volatile memctl8xx_t *memctl = &immap->im_memctl;
  397. upmconfig(UPMB, (uint *)sdram_table,sizeof(sdram_table)/sizeof(uint));
  398. memctl->memc_mptpr = MPTPR_2BK_4K;
  399. memctl->memc_mbmr = SDRAM_MxMR_8COL & (~(MBMR_PTBE)); /* no refresh yet */
  400. /* map CS 4 */
  401. memctl->memc_or4 = SDRAM_OR4VALUE | ~((noMbytes<<20)-1);
  402. memctl->memc_br4 = SDRAM_BR4VALUE | base;
  403. /* Perform SDRAM initilization */
  404. # ifdef UPM_NOP_ADDR /* not currently in UPM table */
  405. /* step 1: nop */
  406. memctl->memc_mar = 0x00000000;
  407. memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
  408. MCR_MLCF(0) | UPM_NOP_ADDR;
  409. # endif
  410. /* step 2: delay */
  411. udelay(200);
  412. # ifdef UPM_PRECHARGE_ADDR /* merged with MRS in UPM table */
  413. /* step 3: precharge */
  414. memctl->memc_mar = 0x00000000;
  415. memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
  416. MCR_MLCF(4) | UPM_PRECHARGE_ADDR;
  417. # endif
  418. /* step 4: refresh */
  419. memctl->memc_mar = 0x00000000;
  420. memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
  421. MCR_MLCF(2) | UPM_REFRESH_ADDR;
  422. /*
  423. * note: for some reason, the UPM values we are using include
  424. * precharge with MRS
  425. */
  426. /* step 5: mrs */
  427. memctl->memc_mar = 0x00000088;
  428. memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
  429. MCR_MLCF(1) | UPM_MRS_ADDR;
  430. # ifdef UPM_NOP_ADDR
  431. memctl->memc_mar = 0x00000000;
  432. memctl->memc_mcr = MCR_UPM_B | MCR_OP_RUN | MCR_MB_CS4 |
  433. MCR_MLCF(0) | UPM_NOP_ADDR;
  434. # endif
  435. /*
  436. * Enable refresh
  437. */
  438. memctl->memc_mbmr |= MBMR_PTBE;
  439. return 0;
  440. }
  441. #endif /* !SDRAM_ALT_INIT_SEQUENCE */
  442. /* ------------------------------------------------------------------------- */
  443. static void _sdramdisable(void)
  444. {
  445. volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
  446. volatile memctl8xx_t *memctl = &immap->im_memctl;
  447. memctl->memc_br4 = 0x00000000;
  448. /* maybe we should turn off upmb here or something */
  449. }
  450. /* ------------------------------------------------------------------------- */
  451. static int initsdram(uint base, uint *noMbytes)
  452. {
  453. uint m = CONFIG_SYS_SDRAM_SIZE>>20;
  454. /* _initsdram needs access to sdram */
  455. *((uint *)BCSR1) |= BCSR1_SDRAM_EN; /* enable sdram */
  456. if(!_initsdram(base, m))
  457. {
  458. *noMbytes += m;
  459. return 0;
  460. }
  461. else
  462. {
  463. *((uint *)BCSR1) &= ~BCSR1_SDRAM_EN; /* disable sdram */
  464. _sdramdisable();
  465. return -1;
  466. }
  467. }
  468. #endif /* CONFIG_FADS */
  469. /* ========================================================================= */
  470. phys_size_t initdram (int board_type)
  471. {
  472. uint sdramsz = 0; /* size of sdram in Mbytes */
  473. uint m = 0; /* size of dram in Mbytes */
  474. #ifndef CONFIG_MPC885ADS
  475. uint base = 0; /* base of dram in bytes */
  476. uint k, s;
  477. #endif
  478. #ifdef CONFIG_FADS
  479. if (!initsdram (0x00000000, &sdramsz)) {
  480. #ifndef CONFIG_MPC885ADS
  481. base = sdramsz << 20;
  482. #endif
  483. printf ("(%u MB SDRAM) ", sdramsz);
  484. }
  485. #endif
  486. #ifndef CONFIG_MPC885ADS /* No old DRAM on MPC885ADS */
  487. k = (*((uint *) BCSR2) >> 23) & 0x0f;
  488. switch (k & 0x3) {
  489. /* "MCM36100 / MT8D132X" */
  490. case 0x00:
  491. m = 4;
  492. break;
  493. /* "MCM36800 / MT16D832X" */
  494. case 0x01:
  495. m = 32;
  496. break;
  497. /* "MCM36400 / MT8D432X" */
  498. case 0x02:
  499. m = 16;
  500. break;
  501. /* "MCM36200 / MT16D832X ?" */
  502. case 0x03:
  503. m = 8;
  504. break;
  505. }
  506. switch (k >> 2) {
  507. case 0x02:
  508. k = 70;
  509. break;
  510. case 0x03:
  511. k = 60;
  512. break;
  513. default:
  514. printf ("unknown dramdelay (0x%x) - defaulting to 70 ns", k);
  515. k = 70;
  516. }
  517. #ifdef CONFIG_FADS
  518. /* the FADS is missing this bit, all rams treated as non-edo */
  519. s = 0;
  520. #else
  521. s = (*((uint *) BCSR2) >> 27) & 0x01;
  522. #endif
  523. if (!_draminit (base, m, s, k)) {
  524. printf ("%dM %dns %sDRAM: ", m, k, s ? "EDO " : "");
  525. } else {
  526. _dramdisable ();
  527. m = 0;
  528. }
  529. #endif /* !CONFIG_MPC885ADS */
  530. m += sdramsz; /* add sdram size to total */
  531. return (m << 20);
  532. }
  533. /* ------------------------------------------------------------------------- */
  534. int testdram (void)
  535. {
  536. /* TODO: XXX XXX XXX */
  537. printf ("test: 16 MB - ok\n");
  538. return (0);
  539. }
  540. /* ========================================================================= */
  541. /*
  542. * Check Board Identity:
  543. */
  544. int checkboard (void)
  545. {
  546. #if defined(CONFIG_MPC86xADS)
  547. puts ("Board: MPC86xADS\n");
  548. #elif defined(CONFIG_MPC885ADS)
  549. puts ("Board: MPC885ADS\n");
  550. #else /* Only old ADS/FADS have got revision ID in BCSR3 */
  551. uint r = (((*((uint *) BCSR3) >> 23) & 1) << 3)
  552. | (((*((uint *) BCSR3) >> 19) & 1) << 2)
  553. | (((*((uint *) BCSR3) >> 16) & 3));
  554. puts ("Board: ");
  555. #if defined(CONFIG_FADS)
  556. puts ("FADS");
  557. checkdboard ();
  558. #else
  559. puts ("ADS");
  560. #endif
  561. puts (" rev ");
  562. switch (r) {
  563. case 0x00:
  564. puts ("ENG\n");
  565. break;
  566. case 0x01:
  567. puts ("PILOT\n");
  568. break;
  569. default:
  570. printf ("unknown (0x%x)\n", r);
  571. return -1;
  572. }
  573. #endif /* CONFIG_MPC86xADS */
  574. return 0;
  575. }
  576. /* ========================================================================= */
  577. #if defined(CONFIG_CMD_PCMCIA)
  578. #ifdef CONFIG_SYS_PCMCIA_MEM_ADDR
  579. volatile unsigned char *pcmcia_mem = (unsigned char*)CONFIG_SYS_PCMCIA_MEM_ADDR;
  580. #endif
  581. int pcmcia_init(void)
  582. {
  583. volatile pcmconf8xx_t *pcmp;
  584. uint v, slota = 0, slotb = 0;
  585. /*
  586. ** Enable the PCMCIA for a Flash card.
  587. */
  588. pcmp = (pcmconf8xx_t *)(&(((immap_t *)CONFIG_SYS_IMMR)->im_pcmcia));
  589. #if 0
  590. pcmp->pcmc_pbr0 = CONFIG_SYS_PCMCIA_MEM_ADDR;
  591. pcmp->pcmc_por0 = 0xc00ff05d;
  592. #endif
  593. /* Set all slots to zero by default. */
  594. pcmp->pcmc_pgcra = 0;
  595. pcmp->pcmc_pgcrb = 0;
  596. #ifdef CONFIG_PCMCIA_SLOT_A
  597. pcmp->pcmc_pgcra = 0x40;
  598. #endif
  599. #ifdef CONFIG_PCMCIA_SLOT_B
  600. pcmp->pcmc_pgcrb = 0x40;
  601. #endif
  602. /* enable PCMCIA buffers */
  603. *((uint *)BCSR1) &= ~BCSR1_PCCEN;
  604. /* Check if any PCMCIA card is plugged in. */
  605. #ifdef CONFIG_PCMCIA_SLOT_A
  606. slota = (pcmp->pcmc_pipr & 0x18000000) == 0 ;
  607. #endif
  608. #ifdef CONFIG_PCMCIA_SLOT_B
  609. slotb = (pcmp->pcmc_pipr & 0x00001800) == 0 ;
  610. #endif
  611. if (!(slota || slotb)) {
  612. printf("No card present\n");
  613. pcmp->pcmc_pgcra = 0;
  614. pcmp->pcmc_pgcrb = 0;
  615. return -1;
  616. }
  617. else
  618. printf("Card present (");
  619. v = 0;
  620. /* both the ADS and the FADS have a 5V keyed pcmcia connector (?)
  621. **
  622. ** Paolo - Yes, but i have to insert some 3.3V card in that slot on
  623. ** my FADS... :-)
  624. */
  625. #if defined(CONFIG_MPC86x)
  626. switch ((pcmp->pcmc_pipr >> 30) & 3)
  627. #elif defined(CONFIG_MPC823) || defined(CONFIG_MPC850)
  628. switch ((pcmp->pcmc_pipr >> 14) & 3)
  629. #endif
  630. {
  631. case 0x03 :
  632. printf("5V");
  633. v = 5;
  634. break;
  635. case 0x01 :
  636. printf("5V and 3V");
  637. #ifdef CONFIG_FADS
  638. v = 3; /* User lower voltage if supported! */
  639. #else
  640. v = 5;
  641. #endif
  642. break;
  643. case 0x00 :
  644. printf("5V, 3V and x.xV");
  645. #ifdef CONFIG_FADS
  646. v = 3; /* User lower voltage if supported! */
  647. #else
  648. v = 5;
  649. #endif
  650. break;
  651. }
  652. switch (v) {
  653. #ifdef CONFIG_FADS
  654. case 3:
  655. printf("; using 3V");
  656. /*
  657. ** Enable 3 volt Vcc.
  658. */
  659. *((uint *)BCSR1) &= ~BCSR1_PCCVCC1;
  660. *((uint *)BCSR1) |= BCSR1_PCCVCC0;
  661. break;
  662. #endif
  663. case 5:
  664. printf("; using 5V");
  665. #ifdef CONFIG_FADS
  666. /*
  667. ** Enable 5 volt Vcc.
  668. */
  669. *((uint *)BCSR1) &= ~BCSR1_PCCVCC0;
  670. *((uint *)BCSR1) |= BCSR1_PCCVCC1;
  671. #endif
  672. break;
  673. default:
  674. *((uint *)BCSR1) |= BCSR1_PCCEN; /* disable pcmcia */
  675. printf("; unknown voltage");
  676. return -1;
  677. }
  678. printf(")\n");
  679. /* disable pcmcia reset after a while */
  680. udelay(20);
  681. #ifdef CONFIG_PCMCIA_SLOT_A
  682. pcmp->pcmc_pgcra = 0;
  683. #endif
  684. #ifdef CONFIG_PCMCIA_SLOT_B
  685. pcmp->pcmc_pgcrb = 0;
  686. #endif
  687. /* If you using a real hd you should give a short
  688. * spin-up time. */
  689. #ifdef CONFIG_DISK_SPINUP_TIME
  690. udelay(CONFIG_DISK_SPINUP_TIME);
  691. #endif
  692. return 0;
  693. }
  694. #endif
  695. /* ========================================================================= */
  696. #ifdef CONFIG_SYS_PC_IDE_RESET
  697. void ide_set_reset(int on)
  698. {
  699. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  700. /*
  701. * Configure PC for IDE Reset Pin
  702. */
  703. if (on) { /* assert RESET */
  704. immr->im_ioport.iop_pcdat &= ~(CONFIG_SYS_PC_IDE_RESET);
  705. } else { /* release RESET */
  706. immr->im_ioport.iop_pcdat |= CONFIG_SYS_PC_IDE_RESET;
  707. }
  708. /* program port pin as GPIO output */
  709. immr->im_ioport.iop_pcpar &= ~(CONFIG_SYS_PC_IDE_RESET);
  710. immr->im_ioport.iop_pcso &= ~(CONFIG_SYS_PC_IDE_RESET);
  711. immr->im_ioport.iop_pcdir |= CONFIG_SYS_PC_IDE_RESET;
  712. }
  713. #endif /* CONFIG_SYS_PC_IDE_RESET */