esteem192e.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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. *
  24. * Modified By Conn Clark to work with Esteem 192E 7/31/00
  25. *
  26. */
  27. #include <common.h>
  28. #include <mpc8xx.h>
  29. /* ------------------------------------------------------------------------- */
  30. static long int dram_size ( long int *base, long int maxsize);
  31. /* ------------------------------------------------------------------------- */
  32. #define _NOT_USED_ 0xFFFFFFFF
  33. const uint sdram_table[] =
  34. {
  35. /*
  36. * Single Read. (Offset 0 in UPMA RAM)
  37. *
  38. * active, NOP, read, precharge, NOP */
  39. 0x0F27CC04, 0x0EAECC04, 0x00B98C04, 0x00F74C00,
  40. 0x11FFCC05, /* last */
  41. /*
  42. * SDRAM Initialization (offset 5 in UPMA RAM)
  43. *
  44. * This is no UPM entry point. The following definition uses
  45. * the remaining space to establish an initialization
  46. * sequence, which is executed by a RUN command.
  47. * NOP, Program
  48. */
  49. 0x0F0A8C34, 0x1F354C37, /* last */
  50. _NOT_USED_, /* Not used */
  51. /*
  52. * Burst Read. (Offset 8 in UPMA RAM)
  53. * active, NOP, read, NOP, NOP, NOP, NOP, NOP */
  54. 0x0F37CC04, 0x0EFECC04, 0x00FDCC04, 0x00FFCC00,
  55. 0x00FFCC00, 0x01FFCC00, 0x0FFFCC00, 0x1FFFCC05, /* last */
  56. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  57. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  58. /*
  59. * Single Write. (Offset 18 in UPMA RAM)
  60. * active, NOP, write, NOP, precharge, NOP */
  61. 0x0F27CC04, 0x0EAE8C00, 0x01BD4C04, 0x0FFB8C04,
  62. 0x0FF74C04, 0x1FFFCC05, /* last */
  63. _NOT_USED_, _NOT_USED_,
  64. /*
  65. * Burst Write. (Offset 20 in UPMA RAM)
  66. * active, NOP, write, NOP, NOP, NOP, NOP, NOP */
  67. 0x0F37CC04, 0x0EFE8C00, 0x00FD4C00, 0x00FFCC00,
  68. 0x00FFCC00, 0x01FFCC04, 0x0FFFCC04, 0x1FFFCC05, /* last */
  69. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  70. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  71. /*
  72. * Refresh (Offset 30 in UPMA RAM)
  73. * precharge, NOP, auto_ref, NOP, NOP, NOP */
  74. 0x0FF74C34, 0x0FFACCB4, 0x0FF5CC34, 0x0FFFCC34,
  75. 0x0FFFCCB4, 0x1FFFCC35, /* last */
  76. _NOT_USED_, _NOT_USED_,
  77. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  78. /*
  79. * Exception. (Offset 3c in UPMA RAM)
  80. */
  81. 0x0FFB8C00, 0x1FF74C03, /* last */
  82. _NOT_USED_, _NOT_USED_
  83. };
  84. /* ------------------------------------------------------------------------- */
  85. /*
  86. * Check Board Identity:
  87. */
  88. int checkboard (void)
  89. {
  90. puts ("Board: Esteem 192E\n");
  91. return(0);
  92. }
  93. /* ------------------------------------------------------------------------- */
  94. long int initdram (int board_type)
  95. {
  96. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  97. volatile memctl8xx_t *memctl = &immap->im_memctl;
  98. long int size_b0, size_b1;
  99. /*
  100. * Explain frequency of refresh here
  101. */
  102. memctl->memc_mptpr = 0x0200; /* divide by 32 */
  103. memctl->memc_mamr = 0x18003112; /*CFG_MAMR_8COL;*/ /* 0x18005112 TODO: explain here */
  104. upmconfig(UPMA, (uint *)sdram_table, sizeof(sdram_table)/sizeof(uint));
  105. /*
  106. * Map cs 2 and 3 to the SDRAM banks 0 and 1 at
  107. * preliminary addresses - these have to be modified after the
  108. * SDRAM size has been determined.
  109. */
  110. memctl->memc_or2 = CFG_OR2_PRELIM; /* not defined yet */
  111. memctl->memc_br2 = CFG_BR2_PRELIM;
  112. memctl->memc_or3 = CFG_OR3_PRELIM;
  113. memctl->memc_br3 = CFG_BR3_PRELIM;
  114. /* perform SDRAM initializsation sequence */
  115. memctl->memc_mar = 0x00000088;
  116. memctl->memc_mcr = 0x80004830; /* SDRAM bank 0 execute 8 refresh */
  117. memctl->memc_mcr = 0x80004105; /* SDRAM bank 0 */
  118. memctl->memc_mcr = 0x80006830; /* SDRAM bank 1 execute 8 refresh */
  119. memctl->memc_mcr = 0x80006105; /* SDRAM bank 1 */
  120. memctl->memc_mamr = CFG_MAMR_8COL; /* 0x18803112 start refresh timer TODO: explain here */
  121. /* printf ("banks 0 and 1 are programed\n"); */
  122. /*
  123. * Check Bank 0 Memory Size for re-configuration
  124. *
  125. */
  126. size_b0 = dram_size ((ulong *)SDRAM_BASE2_PRELIM, SDRAM_MAX_SIZE);
  127. size_b1 = dram_size ((ulong *)SDRAM_BASE3_PRELIM, SDRAM_MAX_SIZE);
  128. printf ("\nbank 0 size %lu\nbank 1 size %lu\n",size_b0,size_b1);
  129. /* printf ("bank 1 size %u\n",size_b1); */
  130. if(size_b1 == 0) {
  131. /*
  132. * Adjust refresh rate if bank 0 isn't stuffed
  133. */
  134. memctl->memc_mptpr = 0x0400; /* divide by 64 */
  135. memctl->memc_br3 &= 0x0FFFFFFFE;
  136. /*
  137. * Adjust OR2 for size of bank 0
  138. */
  139. memctl->memc_or2 |= 7 * size_b0;
  140. }
  141. else {
  142. if(size_b0 < size_b1) {
  143. memctl->memc_br2 &= 0x00007FFE;
  144. memctl->memc_br3 &= 0x00007FFF;
  145. /*
  146. * Adjust OR3 for size of bank 1
  147. */
  148. memctl->memc_or3 |= 15 * size_b1;
  149. /*
  150. * Adjust OR2 for size of bank 0
  151. */
  152. memctl->memc_or2 |= 15 * size_b0;
  153. memctl->memc_br2 += (size_b1 + 1);
  154. }
  155. else {
  156. memctl->memc_br3 &= 0x00007FFE;
  157. /*
  158. * Adjust OR2 for size of bank 0
  159. */
  160. memctl->memc_or2 |= 15 * size_b0;
  161. /*
  162. * Adjust OR3 for size of bank 1
  163. */
  164. memctl->memc_or3 |= 15 * size_b1;
  165. memctl->memc_br3 += (size_b0 + 1);
  166. }
  167. }
  168. /* before leaving set all unused i/o pins to outputs */
  169. /*
  170. * --*Unused Pin List*--
  171. *
  172. * group/port bit number
  173. * IP_B 0,1,3,4,5 Taken care of in pcmcia-cs-x.x.xx
  174. * PA 5,7,8,9,14,15
  175. * PB 22,23,31
  176. * PC 4,5,6,7,10,11,12,13,14,15
  177. * PD 5,6,7
  178. *
  179. */
  180. /*
  181. * --*Pin Used for I/O List*--
  182. *
  183. * port input bit number output bit number either
  184. * PB 18,26,27
  185. * PD 3,4 8,9,10,11,12,13,14,15
  186. *
  187. */
  188. immap->im_ioport.iop_papar &= ~0x05C3; /* set pins as io */
  189. immap->im_ioport.iop_padir |= 0x05C3; /* set pins as output */
  190. immap->im_ioport.iop_paodr &= 0x0008; /* config pins 9 & 14 as normal outputs */
  191. immap->im_ioport.iop_padat |= 0x05C3; /* set unused pins as high */
  192. immap->im_cpm.cp_pbpar &= ~0x00001331; /* set unused port b pins as io */
  193. immap->im_cpm.cp_pbdir |= 0x00001331; /* set unused port b pins as output */
  194. immap->im_cpm.cp_pbodr &= ~0x00001331; /* config bits 18,22,23,26,27 & 31 as normal outputs */
  195. immap->im_cpm.cp_pbdat |= 0x00001331; /* set T/E LED, /NV_CS, & /POWER_ADJ_CS and the rest to a high */
  196. immap->im_ioport.iop_pcpar &= ~0x0F3F; /* set unused port c pins as io */
  197. immap->im_ioport.iop_pcdir |= 0x0F3F; /* set unused port c pins as output */
  198. immap->im_ioport.iop_pcso &= ~0x0F3F; /* clear special purpose bit for unused port c pins for clarity */
  199. immap->im_ioport.iop_pcdat |= 0x0F3F; /* set unused port c pins high*/
  200. immap->im_ioport.iop_pdpar &= 0xE000; /* set pins as io */
  201. immap->im_ioport.iop_pddir &= 0xE000; /* set bit 3 & 4 as inputs */
  202. immap->im_ioport.iop_pddir |= 0x07FF; /* set bits 5 - 15 as outputs */
  203. immap->im_ioport.iop_pddat = 0x0055; /* set alternating pattern on test port */
  204. return (size_b0 + size_b1);
  205. }
  206. /* ------------------------------------------------------------------------- */
  207. /*
  208. * Check memory range for valid RAM. A simple memory test determines
  209. * the actually available RAM size between addresses `base' and
  210. * `base + maxsize'. Some (not all) hardware errors are detected:
  211. * - short between address lines
  212. * - short between data lines
  213. */
  214. static long int dram_size ( long int *base, long int maxsize)
  215. {
  216. volatile long int *addr;
  217. long int cnt, val;
  218. for (cnt = maxsize/sizeof(long); cnt > 0; cnt >>= 1) {
  219. addr = base + cnt; /* pointer arith! */
  220. *addr = ~cnt;
  221. }
  222. /* write 0 to base address */
  223. addr = base;
  224. *addr = 0;
  225. /* check at base address */
  226. if ((val = *addr) != 0) {
  227. return (0);
  228. }
  229. for (cnt = 1; ; cnt <<= 1) {
  230. addr = base + cnt; /* pointer arith! */
  231. val = *addr;
  232. if (val != (~cnt)) {
  233. return (cnt * sizeof(long));
  234. }
  235. }
  236. /* NOTREACHED */
  237. }