netvia.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  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. /****************************************************************/
  30. #if defined(CONFIG_NETVIA_VERSION) && CONFIG_NETVIA_VERSION >= 2
  31. /* last value written to the external register; we cannot read back */
  32. unsigned int last_er_val;
  33. #endif
  34. /****************************************************************/
  35. /****************************************************************/
  36. /* some sane bit macros */
  37. #define _BD(_b) (1U << (31-(_b)))
  38. #define _BDR(_l, _h) (((((1U << (31-(_l))) - 1) << 1) | 1) & ~((1U << (31-(_h))) - 1))
  39. #define _BW(_b) (1U << (15-(_b)))
  40. #define _BWR(_l, _h) (((((1U << (15-(_l))) - 1) << 1) | 1) & ~((1U << (15-(_h))) - 1))
  41. #define _BB(_b) (1U << (7-(_b)))
  42. #define _BBR(_l, _h) (((((1U << (7-(_l))) - 1) << 1) | 1) & ~((1U << (7-(_h))) - 1))
  43. #define _B(_b) _BD(_b)
  44. #define _BR(_l, _h) _BDR(_l, _h)
  45. /****************************************************************/
  46. #define _NOT_USED_ 0xFFFFFFFF
  47. /****************************************************************/
  48. #define CS_0000 0x00000000
  49. #define CS_0001 0x10000000
  50. #define CS_0010 0x20000000
  51. #define CS_0011 0x30000000
  52. #define CS_0100 0x40000000
  53. #define CS_0101 0x50000000
  54. #define CS_0110 0x60000000
  55. #define CS_0111 0x70000000
  56. #define CS_1000 0x80000000
  57. #define CS_1001 0x90000000
  58. #define CS_1010 0xA0000000
  59. #define CS_1011 0xB0000000
  60. #define CS_1100 0xC0000000
  61. #define CS_1101 0xD0000000
  62. #define CS_1110 0xE0000000
  63. #define CS_1111 0xF0000000
  64. #define BS_0000 0x00000000
  65. #define BS_0001 0x01000000
  66. #define BS_0010 0x02000000
  67. #define BS_0011 0x03000000
  68. #define BS_0100 0x04000000
  69. #define BS_0101 0x05000000
  70. #define BS_0110 0x06000000
  71. #define BS_0111 0x07000000
  72. #define BS_1000 0x08000000
  73. #define BS_1001 0x09000000
  74. #define BS_1010 0x0A000000
  75. #define BS_1011 0x0B000000
  76. #define BS_1100 0x0C000000
  77. #define BS_1101 0x0D000000
  78. #define BS_1110 0x0E000000
  79. #define BS_1111 0x0F000000
  80. #define A10_AAAA 0x00000000
  81. #define A10_AAA0 0x00200000
  82. #define A10_AAA1 0x00300000
  83. #define A10_000A 0x00800000
  84. #define A10_0000 0x00A00000
  85. #define A10_0001 0x00B00000
  86. #define A10_111A 0x00C00000
  87. #define A10_1110 0x00E00000
  88. #define A10_1111 0x00F00000
  89. #define RAS_0000 0x00000000
  90. #define RAS_0001 0x00040000
  91. #define RAS_1110 0x00080000
  92. #define RAS_1111 0x000C0000
  93. #define CAS_0000 0x00000000
  94. #define CAS_0001 0x00010000
  95. #define CAS_1110 0x00020000
  96. #define CAS_1111 0x00030000
  97. #define WE_0000 0x00000000
  98. #define WE_0001 0x00004000
  99. #define WE_1110 0x00008000
  100. #define WE_1111 0x0000C000
  101. #define GPL4_0000 0x00000000
  102. #define GPL4_0001 0x00001000
  103. #define GPL4_1110 0x00002000
  104. #define GPL4_1111 0x00003000
  105. #define GPL5_0000 0x00000000
  106. #define GPL5_0001 0x00000400
  107. #define GPL5_1110 0x00000800
  108. #define GPL5_1111 0x00000C00
  109. #define LOOP 0x00000080
  110. #define EXEN 0x00000040
  111. #define AMX_COL 0x00000000
  112. #define AMX_ROW 0x00000020
  113. #define AMX_MAR 0x00000030
  114. #define NA 0x00000008
  115. #define UTA 0x00000004
  116. #define TODT 0x00000002
  117. #define LAST 0x00000001
  118. const uint sdram_table[0x40] = {
  119. /* RSS */
  120. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  121. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  122. CS_0000 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  123. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  124. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  125. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  126. _NOT_USED_, _NOT_USED_,
  127. /* RBS */
  128. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  129. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  130. CS_0001 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  131. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  132. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  133. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  134. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL, /* PALL */
  135. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | TODT | LAST, /* NOP */
  136. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  137. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  138. /* WSS */
  139. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA,
  140. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  141. CS_0000 | BS_0001 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL | UTA,
  142. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST,
  143. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  144. /* WBS */
  145. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  146. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  147. CS_0001 | BS_0000 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL, /* WRITE */
  148. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  149. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  150. CS_1111 | BS_0001 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  151. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  152. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  153. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  154. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  155. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  156. /* UPT */
  157. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  158. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_0001 | WE_1111 | AMX_COL | LOOP,
  159. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  160. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL,
  161. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | LOOP,
  162. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | LAST,
  163. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  164. _NOT_USED_, _NOT_USED_,
  165. /* EXC */
  166. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL,
  167. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | TODT | LAST,
  168. /* REG */
  169. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1110 | AMX_MAR,
  170. CS_0001 | BS_1111 | A10_0001 | RAS_0001 | CAS_0001 | WE_0001 | AMX_MAR | TODT | LAST,
  171. };
  172. /* ------------------------------------------------------------------------- */
  173. /*
  174. * Check Board Identity:
  175. *
  176. * Test ETX ID string (ETX_xxx...)
  177. *
  178. * Return 1 always.
  179. */
  180. int checkboard(void)
  181. {
  182. #if !defined(CONFIG_NETVIA_VERSION) || CONFIG_NETVIA_VERSION == 1
  183. printf ("NETVIA v1\n");
  184. #else
  185. printf ("NETVIA v2+\n");
  186. #endif
  187. return (0);
  188. }
  189. /* ------------------------------------------------------------------------- */
  190. /* 0xC8 = 0b11001000 , CAS3, >> 2 = 0b00 11 0 010 */
  191. #define MAR_SDRAM_INIT 0x000000C8LU
  192. #define MCR_OP(x) ((unsigned long)((x) & 3) << (31-1))
  193. #define MCR_OP_MASK MCR_OP(3)
  194. #define MCR_UM(x) ((unsigned long)((x) & 1) << (31 - 8))
  195. #define MCR_UM_MASK MCR_UM(1)
  196. #define MCR_UM_UPMA MCR_UM(0)
  197. #define MCR_UM_UPMB MCR_UM(1)
  198. #define MCR_MB(x) ((unsigned long)((x) & 7) << (31 - 18))
  199. #define MCR_MB_MASK MCR_MB(7)
  200. #define MCR_MB_CS(x) MCR_MB(x)
  201. #define MCR_MCLF(x) ((unsigned long)((x) & 15) << (31 - 23))
  202. #define MCR_MCLF_MASK MCR_MCLF(15)
  203. long int initdram(int board_type)
  204. {
  205. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  206. volatile memctl8xx_t *memctl = &immap->im_memctl;
  207. long int size;
  208. upmconfig(UPMA, (uint *) sdram_table, sizeof(sdram_table) / sizeof(uint));
  209. /*
  210. * Preliminary prescaler for refresh
  211. */
  212. memctl->memc_mptpr = CFG_MPTPR_1BK_8K;
  213. memctl->memc_mar = MAR_SDRAM_INIT; /* 32-bit address to be output on the address bus if AMX = 0b11 */
  214. /*
  215. * Map controller bank 3 to the SDRAM bank at preliminary address.
  216. */
  217. memctl->memc_or3 = CFG_OR3_PRELIM;
  218. memctl->memc_br3 = CFG_BR3_PRELIM;
  219. memctl->memc_mamr = CFG_MAMR_9COL & ~MAMR_PTAE; /* no refresh yet */
  220. udelay(200);
  221. /* perform SDRAM initialisation sequence */
  222. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(1) | MCR_MAD(0x3C); /* precharge all */
  223. udelay(1);
  224. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(0) | MCR_MAD(0x30); /* refresh 16 times(0) */
  225. udelay(1);
  226. memctl->memc_mcr = MCR_OP_RUN | MCR_UM_UPMA | MCR_MB_CS3 | MCR_MCLF(1) | MCR_MAD(0x3E); /* exception program (write mar) */
  227. udelay(1);
  228. memctl->memc_mamr |= MAMR_PTAE; /* enable refresh */
  229. udelay(1000);
  230. memctl->memc_mamr = CFG_MAMR_9COL;
  231. size = SDRAM_MAX_SIZE;
  232. udelay(10000);
  233. return (size);
  234. }
  235. /* ------------------------------------------------------------------------- */
  236. int misc_init_r(void)
  237. {
  238. #if defined(CONFIG_NETVIA_VERSION) && CONFIG_NETVIA_VERSION >= 2
  239. last_er_val = 0xffffffff;
  240. #endif
  241. return(0);
  242. }
  243. /* ------------------------------------------------------------------------- */
  244. /* GP = general purpose, SP = special purpose (on chip peripheral) */
  245. /* bits that can have a special purpose or can be configured as inputs/outputs */
  246. #define PA_GP_INMASK 0
  247. #define PA_GP_OUTMASK (_BW(5) | _BWR(14, 15))
  248. #define PA_SP_MASK (_BW(4) | _BWR(6, 13))
  249. #define PA_ODR_VAL 0
  250. #define PA_GP_OUTVAL _BW(5)
  251. #define PA_SP_DIRVAL 0
  252. #define PB_GP_INMASK _B(28)
  253. #define PB_GP_OUTMASK (_BR(16, 19) | _BR(26, 27) | _BR(29, 31))
  254. #define PB_SP_MASK _BR(22, 25)
  255. #define PB_ODR_VAL 0
  256. #define PB_GP_OUTVAL (_BR(16, 19) | _BR(26, 27) | _BR(29, 31))
  257. #define PB_SP_DIRVAL 0
  258. #if !defined(CONFIG_NETVIA_VERSION) || CONFIG_NETVIA_VERSION == 1
  259. #define PC_GP_INMASK (_BWR(5, 7) | _BWR(9, 10) | _BW(13))
  260. #define PC_GP_OUTMASK _BW(12)
  261. #define PC_SP_MASK (_BW(4) | _BW(8))
  262. #define PC_SOVAL 0
  263. #define PC_INTVAL 0
  264. #define PC_GP_OUTVAL 0
  265. #define PC_SP_DIRVAL 0
  266. #define PD_GP_INMASK 0
  267. #define PD_GP_OUTMASK _BWR(3, 15)
  268. #define PD_SP_MASK 0
  269. #define PD_GP_OUTVAL (_BW(3) | _BW(5) | _BW(7) | _BWR(8, 15))
  270. #define PD_SP_DIRVAL 0
  271. #elif CONFIG_NETVIA_VERSION >= 2
  272. #define PC_GP_INMASK (_BW(5) | _BW(7) | _BWR(9, 11) | _BWR(13, 15))
  273. #define PC_GP_OUTMASK (_BW(6) | _BW(12))
  274. #define PC_SP_MASK (_BW(4) | _BW(8))
  275. #define PC_SOVAL 0
  276. #define PC_INTVAL _BW(7)
  277. #define PC_GP_OUTVAL (_BW(6) | _BW(12))
  278. #define PC_SP_DIRVAL 0
  279. #define PD_GP_INMASK 0
  280. #define PD_GP_OUTMASK _BWR(3, 15)
  281. #define PD_SP_MASK 0
  282. #define PD_GP_OUTVAL (_BW(3) | _BW(5) | _BW(9) | _BW(11))
  283. #define PD_SP_DIRVAL 0
  284. #else
  285. #error Unknown NETVIA board version.
  286. #endif
  287. int board_pre_init(void)
  288. {
  289. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  290. volatile iop8xx_t *ioport = &immap->im_ioport;
  291. volatile cpm8xx_t *cpm = &immap->im_cpm;
  292. volatile memctl8xx_t *memctl = &immap->im_memctl;
  293. /* DSP0 chip select */
  294. memctl->memc_or4 = ((0xFFFFFFFFLU & ~(DSP_SIZE - 1)) | OR_CSNT_SAM | OR_BI | OR_ACS_DIV2 | OR_SETA | OR_TRLX);
  295. memctl->memc_br4 = ((DSP0_BASE & BR_BA_MSK) | BR_PS_16 | BR_V);
  296. /* DSP1 chip select */
  297. memctl->memc_or5 = ((0xFFFFFFFFLU & ~(DSP_SIZE - 1)) | OR_CSNT_SAM | OR_BI | OR_ACS_DIV2 | OR_SETA | OR_TRLX);
  298. memctl->memc_br5 = ((DSP1_BASE & BR_BA_MSK) | BR_PS_16 | BR_V);
  299. /* FPGA chip select */
  300. memctl->memc_or6 = ((0xFFFFFFFFLU & ~(FPGA_SIZE - 1)) | OR_BI | OR_SCY_1_CLK);
  301. memctl->memc_br6 = ((FPGA_BASE & BR_BA_MSK) | BR_PS_8 | BR_V);
  302. #if defined(CONFIG_NETVIA_VERSION) && CONFIG_NETVIA_VERSION >= 2
  303. /* NAND chip select */
  304. memctl->memc_or1 = ((0xFFFFFFFFLU & ~(NAND_SIZE - 1)) | OR_CSNT_SAM | OR_BI | OR_SCY_8_CLK | OR_EHTR | OR_TRLX);
  305. memctl->memc_br1 = ((NAND_BASE & BR_BA_MSK) | BR_PS_8 | BR_V);
  306. /* kill this chip select */
  307. memctl->memc_br2 &= ~BR_V; /* invalid */
  308. /* external reg chip select */
  309. memctl->memc_or7 = ((0xFFFFFFFFLU & ~(ER_SIZE - 1)) | OR_BI | OR_SCY_4_CLK);
  310. memctl->memc_br7 = ((ER_BASE & BR_BA_MSK) | BR_PS_32 | BR_V);
  311. #endif
  312. ioport->iop_padat = PA_GP_OUTVAL;
  313. ioport->iop_paodr = PA_ODR_VAL;
  314. ioport->iop_padir = PA_GP_OUTMASK | PA_SP_DIRVAL;
  315. ioport->iop_papar = PA_SP_MASK;
  316. cpm->cp_pbdat = PB_GP_OUTVAL;
  317. cpm->cp_pbodr = PB_ODR_VAL;
  318. cpm->cp_pbdir = PB_GP_OUTMASK | PB_SP_DIRVAL;
  319. cpm->cp_pbpar = PB_SP_MASK;
  320. ioport->iop_pcdat = PC_GP_OUTVAL;
  321. ioport->iop_pcdir = PC_GP_OUTMASK | PC_SP_DIRVAL;
  322. ioport->iop_pcso = PC_SOVAL;
  323. ioport->iop_pcint = PC_INTVAL;
  324. ioport->iop_pcpar = PC_SP_MASK;
  325. ioport->iop_pddat = PD_GP_OUTVAL;
  326. ioport->iop_pddir = PD_GP_OUTMASK | PD_SP_DIRVAL;
  327. ioport->iop_pdpar = PD_SP_MASK;
  328. #if defined(CONFIG_NETVIA_VERSION) && CONFIG_NETVIA_VERSION >= 2
  329. /* external register init */
  330. *(volatile uint *)ER_BASE = 0xFFFFFFFF;
  331. #endif
  332. return 0;
  333. }
  334. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  335. #include <linux/mtd/nand.h>
  336. extern void nand_probe(ulong physadr);
  337. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  338. void nand_init(void)
  339. {
  340. nand_probe(CFG_NAND_BASE);
  341. if (nand_dev_desc[0].ChipID != NAND_ChipID_UNKNOWN) {
  342. nand_dev_desc[0].name = "NetVia NAND flash";
  343. puts("NAND: ");
  344. print_size(nand_dev_desc[0].totlen, "\n");
  345. }
  346. }
  347. #endif