fads.c 27 KB

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