fads.c 27 KB

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