netvia.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  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. * Pantelis Antoniou, Intracom S.A., panto@intracom.gr
  25. * U-Boot port on NetVia board
  26. */
  27. #include <common.h>
  28. #include "mpc8xx.h"
  29. /* some sane bit macros */
  30. #define _BD(_b) (1U << (31-(_b)))
  31. #define _BDR(_l, _h) (((((1U << (31-(_l))) - 1) << 1) | 1) & ~((1U << (31-(_h))) - 1))
  32. #define _BW(_b) (1U << (15-(_b)))
  33. #define _BWR(_l, _h) (((((1U << (15-(_l))) - 1) << 1) | 1) & ~((1U << (15-(_h))) - 1))
  34. #define _BB(_b) (1U << (7-(_b)))
  35. #define _BBR(_l, _h) (((((1U << (7-(_l))) - 1) << 1) | 1) & ~((1U << (7-(_h))) - 1))
  36. #define _B(_b) _BD(_b)
  37. #define _BR(_l, _h) _BDR(_l, _h)
  38. /* ------------------------------------------------------------------------- */
  39. /* ------------------------------------------------------------------------- */
  40. #define _NOT_USED_ 0xFFFFFFFF
  41. /* ------------------------------------------------------------------------- */
  42. #define CS_0000 0x00000000
  43. #define CS_0001 0x10000000
  44. #define CS_0010 0x20000000
  45. #define CS_0011 0x30000000
  46. #define CS_0100 0x40000000
  47. #define CS_0101 0x50000000
  48. #define CS_0110 0x60000000
  49. #define CS_0111 0x70000000
  50. #define CS_1000 0x80000000
  51. #define CS_1001 0x90000000
  52. #define CS_1010 0xA0000000
  53. #define CS_1011 0xB0000000
  54. #define CS_1100 0xC0000000
  55. #define CS_1101 0xD0000000
  56. #define CS_1110 0xE0000000
  57. #define CS_1111 0xF0000000
  58. #define BS_0000 0x00000000
  59. #define BS_0001 0x01000000
  60. #define BS_0010 0x02000000
  61. #define BS_0011 0x03000000
  62. #define BS_0100 0x04000000
  63. #define BS_0101 0x05000000
  64. #define BS_0110 0x06000000
  65. #define BS_0111 0x07000000
  66. #define BS_1000 0x08000000
  67. #define BS_1001 0x09000000
  68. #define BS_1010 0x0A000000
  69. #define BS_1011 0x0B000000
  70. #define BS_1100 0x0C000000
  71. #define BS_1101 0x0D000000
  72. #define BS_1110 0x0E000000
  73. #define BS_1111 0x0F000000
  74. #define A10_AAAA 0x00000000
  75. #define A10_AAA0 0x00200000
  76. #define A10_AAA1 0x00300000
  77. #define A10_000A 0x00800000
  78. #define A10_0000 0x00A00000
  79. #define A10_0001 0x00B00000
  80. #define A10_111A 0x00C00000
  81. #define A10_1110 0x00E00000
  82. #define A10_1111 0x00F00000
  83. #define RAS_0000 0x00000000
  84. #define RAS_0001 0x00040000
  85. #define RAS_1110 0x00080000
  86. #define RAS_1111 0x000C0000
  87. #define CAS_0000 0x00000000
  88. #define CAS_0001 0x00010000
  89. #define CAS_1110 0x00020000
  90. #define CAS_1111 0x00030000
  91. #define WE_0000 0x00000000
  92. #define WE_0001 0x00004000
  93. #define WE_1110 0x00008000
  94. #define WE_1111 0x0000C000
  95. #define GPL4_0000 0x00000000
  96. #define GPL4_0001 0x00001000
  97. #define GPL4_1110 0x00002000
  98. #define GPL4_1111 0x00003000
  99. #define GPL5_0000 0x00000000
  100. #define GPL5_0001 0x00000400
  101. #define GPL5_1110 0x00000800
  102. #define GPL5_1111 0x00000C00
  103. #define LOOP 0x00000080
  104. #define EXEN 0x00000040
  105. #define AMX_COL 0x00000000
  106. #define AMX_ROW 0x00000020
  107. #define AMX_MAR 0x00000030
  108. #define NA 0x00000008
  109. #define UTA 0x00000004
  110. #define TODT 0x00000002
  111. #define LAST 0x00000001
  112. const uint sdram_table[0x40] = {
  113. /* RSS */
  114. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  115. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  116. CS_0000 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  117. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  118. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  119. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  120. _NOT_USED_, _NOT_USED_,
  121. /* RBS */
  122. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  123. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  124. CS_0001 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  125. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  126. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  127. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  128. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL, /* PALL */
  129. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | TODT | LAST, /* NOP */
  130. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  131. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  132. /* WSS */
  133. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA,
  134. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  135. CS_0000 | BS_0001 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL | UTA,
  136. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST,
  137. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  138. /* WBS */
  139. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  140. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  141. CS_0001 | BS_0000 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL, /* WRITE */
  142. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  143. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  144. CS_1111 | BS_0001 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  145. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  146. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  147. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  148. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  149. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  150. /* UPT */
  151. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  152. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_0001 | WE_1111 | AMX_COL | LOOP,
  153. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  154. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  155. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | LOOP,
  156. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | LAST,
  157. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  158. _NOT_USED_, _NOT_USED_,
  159. /* EXC */
  160. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL,
  161. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | TODT | LAST,
  162. /* REG */
  163. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1110 | AMX_MAR,
  164. CS_0001 | BS_1111 | A10_0001 | RAS_0001 | CAS_0001 | WE_0001 | AMX_MAR | TODT | LAST,
  165. };
  166. /* ------------------------------------------------------------------------- */
  167. /*
  168. * Check Board Identity:
  169. *
  170. * Test ETX ID string (ETX_xxx...)
  171. *
  172. * Return 1 always.
  173. */
  174. int checkboard(void)
  175. {
  176. printf ("NETVIA\n");
  177. return (0);
  178. }
  179. /* ------------------------------------------------------------------------- */
  180. /* 0xC8 = 0b11001000 , CAS3, >> 2 = 0b00 11 0 010 */
  181. #define MAR_SDRAM_INIT 0x000000C8LU
  182. #define MCR_OP(x) ((unsigned long)((x) & 3) << (31-1))
  183. #define MCR_OP_MASK MCR_OP(3)
  184. #define MCR_UM(x) ((unsigned long)((x) & 1) << (31 - 8))
  185. #define MCR_UM_MASK MCR_UM(1)
  186. #define MCR_UM_UPMA MCR_UM(0)
  187. #define MCR_UM_UPMB MCR_UM(1)
  188. #define MCR_MB(x) ((unsigned long)((x) & 7) << (31 - 18))
  189. #define MCR_MB_MASK MCR_MB(7)
  190. #define MCR_MB_CS(x) MCR_MB(x)
  191. #define MCR_MCLF(x) ((unsigned long)((x) & 15) << (31 - 23))
  192. #define MCR_MCLF_MASK MCR_MCLF(15)
  193. long int initdram(int board_type)
  194. {
  195. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  196. volatile memctl8xx_t *memctl = &immap->im_memctl;
  197. long int size;
  198. upmconfig(UPMA, (uint *) sdram_table, sizeof(sdram_table) / sizeof(uint));
  199. /*
  200. * Preliminary prescaler for refresh
  201. */
  202. memctl->memc_mptpr = CFG_MPTPR_1BK_8K;
  203. memctl->memc_mar = MAR_SDRAM_INIT; /* 32-bit address to be output on the address bus if AMX = 0b11 */
  204. /*
  205. * Map controller bank 3 to the SDRAM bank at preliminary address.
  206. */
  207. memctl->memc_or3 = CFG_OR3_PRELIM;
  208. memctl->memc_br3 = CFG_BR3_PRELIM;
  209. memctl->memc_mamr = CFG_MAMR_9COL & ~MAMR_PTAE; /* no refresh yet */
  210. udelay(200);
  211. /* perform SDRAM initialisation sequence */
  212. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(1) | MCR_MAD(0x3C); /* precharge all */
  213. udelay(1);
  214. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(0) | MCR_MAD(0x30); /* refresh 16 times(0) */
  215. udelay(1);
  216. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(1) | MCR_MAD(0x3E); /* exception program (write mar) */
  217. udelay(1);
  218. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  219. udelay(1000);
  220. memctl->memc_mamr = CFG_MAMR_9COL;
  221. size = SDRAM_MAX_SIZE;
  222. udelay(10000);
  223. /* do the ram test */
  224. {
  225. register unsigned long *rp;
  226. register unsigned long v;
  227. /* first fill */
  228. for (rp = (unsigned long *)0; rp < (unsigned long *)SDRAM_MAX_SIZE; )
  229. *rp++ = (unsigned long)rp;
  230. /* now check */
  231. for (rp = (unsigned long *)0; rp < (unsigned long *)SDRAM_MAX_SIZE; rp++) {
  232. if ((v = *rp) != (unsigned long)rp) {
  233. printf("ERROR at 0x%lx (0x%lx)\n", (unsigned long)rp, v);
  234. return -1;
  235. }
  236. }
  237. }
  238. return (size);
  239. }
  240. /* ------------------------------------------------------------------------- */
  241. int misc_init_r(void)
  242. {
  243. return(0);
  244. }
  245. /* ------------------------------------------------------------------------- */
  246. /* bits that can have a special purpose or can be configured as inputs/outputs */
  247. #define PA_MASK (_BWR(4, 9) | _BWR(12, 15))
  248. #define PA_ODR_MASK (_BW(9) | _BW(12) | _BW(14))
  249. #define PA_ODR_VAL 0
  250. #define PA_GP_INMASK 0
  251. #define PA_GP_OUTMASK (_BW(5) | _BW(14) | _BW(15))
  252. #define PA_SP_OUTMASK 0
  253. #define PA_GP_OUTVAL _BW(5)
  254. #define PA_SP_OUTVAL 0
  255. #define PB_MASK (_BR(16, 19) | _BR(22, 31))
  256. #define PB_ODR_MASK PB_MASK
  257. #define PB_ODR_VAL 0
  258. #define PB_GP_INMASK 0
  259. #define PB_GP_OUTMASK (_BR(16, 19) | _BR(26, 27) | _B(31))
  260. #define PB_SP_OUTMASK _BR(28, 30)
  261. #define PB_SP_OUTVAL _BR(28, 30)
  262. #define PB_GP_OUTVAL (_BR(16, 19) | _BR(26, 27) | _B(31))
  263. #define PC_MASK _BWR(4, 15)
  264. #define PC_SO_MASK (_BWR(6, 11) | _BWR(14, 15))
  265. #define PC_SO_VAL 0
  266. #define PC_INT_MASK PC_MASK
  267. #define PC_INT_VAL 0
  268. #define PC_GP_INMASK (_BWR(5, 7) | _BWR(9, 10) | _BW(13))
  269. #define PC_GP_OUTMASK _BW(12)
  270. #define PC_SP_OUTMASK 0
  271. #define PC_SP_OUTVAL _BW(12)
  272. #define PC_GP_OUTVAL 0
  273. #define PD_MASK _BWR(0, 15)
  274. #define PD_GP_INMASK 0
  275. #define PD_GP_OUTMASK _BWR(3, 15)
  276. #define PD_SP_OUTMASK 0
  277. #define PD_GP_OUTVAL (_BW(3) | _BW(5) | _BW(7) | _BWR(8, 15))
  278. #define PD_SP_OUTVAL 0
  279. int board_pre_init(void)
  280. {
  281. register volatile immap_t *immap = (immap_t *) CFG_IMMR;
  282. register volatile iop8xx_t *ioport = &immap->im_ioport;
  283. register volatile cpm8xx_t *cpm = &immap->im_cpm;
  284. ioport->iop_padat = (ioport->iop_padat & ~PA_MASK) | PA_SP_OUTVAL | PA_GP_OUTVAL;
  285. ioport->iop_paodr = (ioport->iop_paodr & ~PA_ODR_MASK) | PA_ODR_VAL;
  286. ioport->iop_padir = (ioport->iop_padir & ~PA_GP_INMASK)| PA_SP_OUTMASK | PA_GP_OUTMASK;
  287. ioport->iop_papar = (ioport->iop_papar & ~(PA_GP_INMASK & PA_GP_OUTMASK));
  288. cpm->cp_pbdat = (ioport->iop_padat & ~PB_MASK) | PB_SP_OUTVAL | PB_GP_OUTVAL;
  289. cpm->cp_pbodr = (ioport->iop_paodr & ~PB_ODR_MASK) | PB_ODR_VAL;
  290. cpm->cp_pbdir = (ioport->iop_padir & ~PB_GP_INMASK)| PB_SP_OUTMASK | PB_GP_OUTMASK;
  291. cpm->cp_pbpar = (ioport->iop_papar & ~(PB_GP_INMASK & PB_GP_OUTMASK));
  292. ioport->iop_pcdat = (ioport->iop_pcdat & ~PC_MASK) | PC_SP_OUTVAL | PC_GP_OUTVAL;
  293. ioport->iop_pcdir = (ioport->iop_pcdir & ~PC_GP_INMASK)| PC_SP_OUTMASK | PC_GP_OUTMASK;
  294. ioport->iop_pcso = (ioport->iop_pcso & ~PC_SO_MASK) | PC_SO_VAL;
  295. ioport->iop_pcint = (ioport->iop_pcint & ~PC_INT_MASK) | PC_INT_VAL;
  296. ioport->iop_pcpar = (ioport->iop_pcpar & ~(PC_GP_INMASK & PC_GP_OUTMASK));
  297. ioport->iop_pddat = (ioport->iop_pddat & ~PD_MASK) | PD_SP_OUTVAL | PD_GP_OUTVAL;
  298. ioport->iop_pddir = (ioport->iop_pddir & ~PD_GP_INMASK)| PD_SP_OUTMASK | PD_GP_OUTMASK;
  299. ioport->iop_pdpar = (ioport->iop_pdpar & ~(PD_GP_INMASK & PD_GP_OUTMASK));
  300. return 0;
  301. }