fads.c 27 KB

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