netta2.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  1. /*
  2. * (C) Copyright 2000-2004
  3. * Pantelis Antoniou, Intracom S.A., panto@intracom.gr
  4. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. /*
  25. * Pantelis Antoniou, Intracom S.A., panto@intracom.gr
  26. * U-Boot port on NetTA4 board
  27. */
  28. #include <common.h>
  29. #include <miiphy.h>
  30. #include "mpc8xx.h"
  31. #ifdef CONFIG_HW_WATCHDOG
  32. #include <watchdog.h>
  33. #endif
  34. int fec8xx_miiphy_read(char *devname, unsigned char addr,
  35. unsigned char reg, unsigned short *value);
  36. int fec8xx_miiphy_write(char *devname, unsigned char addr,
  37. unsigned char reg, unsigned short value);
  38. /****************************************************************/
  39. /* some sane bit macros */
  40. #define _BD(_b) (1U << (31-(_b)))
  41. #define _BDR(_l, _h) (((((1U << (31-(_l))) - 1) << 1) | 1) & ~((1U << (31-(_h))) - 1))
  42. #define _BW(_b) (1U << (15-(_b)))
  43. #define _BWR(_l, _h) (((((1U << (15-(_l))) - 1) << 1) | 1) & ~((1U << (15-(_h))) - 1))
  44. #define _BB(_b) (1U << (7-(_b)))
  45. #define _BBR(_l, _h) (((((1U << (7-(_l))) - 1) << 1) | 1) & ~((1U << (7-(_h))) - 1))
  46. #define _B(_b) _BD(_b)
  47. #define _BR(_l, _h) _BDR(_l, _h)
  48. /****************************************************************/
  49. /*
  50. * Check Board Identity:
  51. *
  52. * Return 1 always.
  53. */
  54. int checkboard(void)
  55. {
  56. printf ("Intracom NetTA2 V%d\n", CONFIG_NETTA2_VERSION);
  57. return (0);
  58. }
  59. /****************************************************************/
  60. #define _NOT_USED_ 0xFFFFFFFF
  61. /****************************************************************/
  62. #define CS_0000 0x00000000
  63. #define CS_0001 0x10000000
  64. #define CS_0010 0x20000000
  65. #define CS_0011 0x30000000
  66. #define CS_0100 0x40000000
  67. #define CS_0101 0x50000000
  68. #define CS_0110 0x60000000
  69. #define CS_0111 0x70000000
  70. #define CS_1000 0x80000000
  71. #define CS_1001 0x90000000
  72. #define CS_1010 0xA0000000
  73. #define CS_1011 0xB0000000
  74. #define CS_1100 0xC0000000
  75. #define CS_1101 0xD0000000
  76. #define CS_1110 0xE0000000
  77. #define CS_1111 0xF0000000
  78. #define BS_0000 0x00000000
  79. #define BS_0001 0x01000000
  80. #define BS_0010 0x02000000
  81. #define BS_0011 0x03000000
  82. #define BS_0100 0x04000000
  83. #define BS_0101 0x05000000
  84. #define BS_0110 0x06000000
  85. #define BS_0111 0x07000000
  86. #define BS_1000 0x08000000
  87. #define BS_1001 0x09000000
  88. #define BS_1010 0x0A000000
  89. #define BS_1011 0x0B000000
  90. #define BS_1100 0x0C000000
  91. #define BS_1101 0x0D000000
  92. #define BS_1110 0x0E000000
  93. #define BS_1111 0x0F000000
  94. #define GPL0_AAAA 0x00000000
  95. #define GPL0_AAA0 0x00200000
  96. #define GPL0_AAA1 0x00300000
  97. #define GPL0_000A 0x00800000
  98. #define GPL0_0000 0x00A00000
  99. #define GPL0_0001 0x00B00000
  100. #define GPL0_111A 0x00C00000
  101. #define GPL0_1110 0x00E00000
  102. #define GPL0_1111 0x00F00000
  103. #define GPL1_0000 0x00000000
  104. #define GPL1_0001 0x00040000
  105. #define GPL1_1110 0x00080000
  106. #define GPL1_1111 0x000C0000
  107. #define GPL2_0000 0x00000000
  108. #define GPL2_0001 0x00010000
  109. #define GPL2_1110 0x00020000
  110. #define GPL2_1111 0x00030000
  111. #define GPL3_0000 0x00000000
  112. #define GPL3_0001 0x00004000
  113. #define GPL3_1110 0x00008000
  114. #define GPL3_1111 0x0000C000
  115. #define GPL4_0000 0x00000000
  116. #define GPL4_0001 0x00001000
  117. #define GPL4_1110 0x00002000
  118. #define GPL4_1111 0x00003000
  119. #define GPL5_0000 0x00000000
  120. #define GPL5_0001 0x00000400
  121. #define GPL5_1110 0x00000800
  122. #define GPL5_1111 0x00000C00
  123. #define LOOP 0x00000080
  124. #define EXEN 0x00000040
  125. #define AMX_COL 0x00000000
  126. #define AMX_ROW 0x00000020
  127. #define AMX_MAR 0x00000030
  128. #define NA 0x00000008
  129. #define UTA 0x00000004
  130. #define TODT 0x00000002
  131. #define LAST 0x00000001
  132. #define A10_AAAA GPL0_AAAA
  133. #define A10_AAA0 GPL0_AAA0
  134. #define A10_AAA1 GPL0_AAA1
  135. #define A10_000A GPL0_000A
  136. #define A10_0000 GPL0_0000
  137. #define A10_0001 GPL0_0001
  138. #define A10_111A GPL0_111A
  139. #define A10_1110 GPL0_1110
  140. #define A10_1111 GPL0_1111
  141. #define RAS_0000 GPL1_0000
  142. #define RAS_0001 GPL1_0001
  143. #define RAS_1110 GPL1_1110
  144. #define RAS_1111 GPL1_1111
  145. #define CAS_0000 GPL2_0000
  146. #define CAS_0001 GPL2_0001
  147. #define CAS_1110 GPL2_1110
  148. #define CAS_1111 GPL2_1111
  149. #define WE_0000 GPL3_0000
  150. #define WE_0001 GPL3_0001
  151. #define WE_1110 GPL3_1110
  152. #define WE_1111 GPL3_1111
  153. /* #define CAS_LATENCY 3 */
  154. #define CAS_LATENCY 2
  155. const uint sdram_table[0x40] = {
  156. #if CAS_LATENCY == 3
  157. /* RSS */
  158. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  159. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  160. CS_0000 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  161. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  162. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  163. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  164. _NOT_USED_, _NOT_USED_,
  165. /* RBS */
  166. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  167. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  168. CS_0001 | BS_1111 | A10_0001 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  169. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  170. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  171. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  172. CS_0001 | BS_0001 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL, /* PALL */
  173. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | TODT | LAST, /* NOP */
  174. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  175. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  176. /* WSS */
  177. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  178. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  179. CS_0000 | BS_0001 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL | UTA, /* WRITE */
  180. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  181. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  182. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  183. /* WBS */
  184. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  185. CS_1111 | BS_1111 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  186. CS_0001 | BS_0000 | A10_0000 | RAS_1111 | CAS_0001 | WE_0000 | AMX_COL, /* WRITE */
  187. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  188. CS_1111 | BS_0000 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  189. CS_1111 | BS_0001 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  190. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  191. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA, /* PALL */
  192. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  193. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  194. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  195. #endif
  196. #if CAS_LATENCY == 2
  197. /* RSS */
  198. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  199. CS_1110 | BS_1110 | A10_0000 | RAS_1111 | CAS_1110 | WE_1111 | AMX_COL | UTA, /* NOP */
  200. CS_0001 | BS_0001 | A10_0000 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  201. CS_1110 | BS_1111 | A10_0001 | RAS_1110 | CAS_1111 | WE_1110 | AMX_COL, /* NOP */
  202. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST, /* PALL */
  203. _NOT_USED_,
  204. _NOT_USED_, _NOT_USED_,
  205. /* RBS */
  206. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  207. CS_1110 | BS_1110 | A10_0000 | RAS_1111 | CAS_1110 | WE_1111 | AMX_COL | UTA, /* NOP */
  208. CS_0001 | BS_0000 | A10_0000 | RAS_1111 | CAS_0001 | WE_1111 | AMX_COL | UTA, /* READ */
  209. CS_1111 | BS_0000 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  210. CS_1111 | BS_0000 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  211. CS_1111 | BS_0001 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  212. CS_1110 | BS_1111 | A10_0001 | RAS_1110 | CAS_1111 | WE_1110 | AMX_COL, /* NOP */
  213. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST, /* PALL */
  214. _NOT_USED_,
  215. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  216. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  217. /* WSS */
  218. CS_0001 | BS_1111 | A10_AAA0 | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  219. CS_1110 | BS_1110 | A10_0000 | RAS_1111 | CAS_1110 | WE_1110 | AMX_COL, /* NOP */
  220. CS_0000 | BS_0001 | A10_0001 | RAS_1110 | CAS_0001 | WE_0000 | AMX_COL | UTA, /* WRITE */
  221. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST, /* PALL */
  222. _NOT_USED_,
  223. _NOT_USED_, _NOT_USED_,
  224. _NOT_USED_,
  225. /* WBS */
  226. CS_0001 | BS_1111 | A10_AAAA | RAS_0001 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* ACT */
  227. CS_1110 | BS_1110 | A10_0000 | RAS_1111 | CAS_1110 | WE_1110 | AMX_COL, /* NOP */
  228. CS_0001 | BS_0000 | A10_0000 | RAS_1111 | CAS_0001 | WE_0001 | AMX_COL, /* WRITE */
  229. CS_1111 | BS_0000 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  230. CS_1111 | BS_0000 | A10_0000 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL, /* NOP */
  231. CS_1110 | BS_0001 | A10_0001 | RAS_1110 | CAS_1111 | WE_1110 | AMX_COL | UTA, /* NOP */
  232. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | TODT | LAST, /* PALL */
  233. _NOT_USED_,
  234. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  235. _NOT_USED_, _NOT_USED_, _NOT_USED_,
  236. _NOT_USED_, _NOT_USED_,
  237. #endif
  238. /* UPT */
  239. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_0001 | WE_1111 | AMX_COL | UTA | LOOP, /* ATRFR */
  240. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  241. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  242. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA, /* NOP */
  243. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | LOOP, /* NOP */
  244. CS_1111 | BS_1111 | A10_1111 | RAS_1111 | CAS_1111 | WE_1111 | AMX_COL | UTA | TODT | LAST, /* NOP */
  245. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  246. _NOT_USED_, _NOT_USED_,
  247. /* EXC */
  248. CS_0001 | BS_1111 | A10_1111 | RAS_0001 | CAS_1111 | WE_0001 | AMX_COL | UTA | LAST,
  249. _NOT_USED_,
  250. /* REG */
  251. CS_1110 | BS_1111 | A10_1110 | RAS_1110 | CAS_1110 | WE_1110 | AMX_MAR | UTA,
  252. CS_0001 | BS_1111 | A10_0001 | RAS_0001 | CAS_0001 | WE_0001 | AMX_MAR | UTA | LAST,
  253. };
  254. #if CONFIG_NETTA2_VERSION == 2
  255. static const uint nandcs_table[0x40] = {
  256. /* RSS */
  257. CS_1000 | GPL4_1111 | GPL5_1111 | UTA,
  258. CS_0000 | GPL4_1110 | GPL5_1111 | UTA,
  259. CS_0000 | GPL4_0000 | GPL5_1111 | UTA,
  260. CS_0000 | GPL4_0000 | GPL5_1111 | UTA,
  261. CS_0000 | GPL4_0000 | GPL5_1111,
  262. CS_0000 | GPL4_0001 | GPL5_1111 | UTA,
  263. CS_0000 | GPL4_1111 | GPL5_1111 | UTA,
  264. CS_0011 | GPL4_1111 | GPL5_1111 | UTA | LAST, /* NOP */
  265. /* RBS */
  266. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  267. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  268. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  269. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  270. /* WSS */
  271. CS_1000 | GPL4_1111 | GPL5_1110 | UTA,
  272. CS_0000 | GPL4_1111 | GPL5_0000 | UTA,
  273. CS_0000 | GPL4_1111 | GPL5_0000 | UTA,
  274. CS_0000 | GPL4_1111 | GPL5_0000 | UTA,
  275. CS_0000 | GPL4_1111 | GPL5_0001 | UTA,
  276. CS_0000 | GPL4_1111 | GPL5_1111 | UTA,
  277. CS_0000 | GPL4_1111 | GPL5_1111,
  278. CS_0011 | GPL4_1111 | GPL5_1111 | UTA | LAST,
  279. /* WBS */
  280. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  281. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  282. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  283. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  284. /* UPT */
  285. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  286. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  287. _NOT_USED_, _NOT_USED_, _NOT_USED_, _NOT_USED_,
  288. /* EXC */
  289. CS_0001 | LAST,
  290. _NOT_USED_,
  291. /* REG */
  292. CS_1110 ,
  293. CS_0001 | LAST,
  294. };
  295. #endif
  296. /* 0xC8 = 0b11001000 , CAS3, >> 2 = 0b00 11 0 010 */
  297. /* 0x88 = 0b10001000 , CAS2, >> 2 = 0b00 10 0 010 */
  298. #define MAR_SDRAM_INIT ((CAS_LATENCY << 6) | 0x00000008LU)
  299. /* 8 */
  300. #define CFG_MAMR ((CFG_MAMR_PTA << MAMR_PTA_SHIFT) | MAMR_PTAE | \
  301. MAMR_AMA_TYPE_0 | MAMR_DSA_1_CYCL | MAMR_G0CLA_A11 | \
  302. MAMR_RLFA_1X | MAMR_WLFA_1X | MAMR_TLFA_4X)
  303. void check_ram(unsigned int addr, unsigned int size)
  304. {
  305. unsigned int i, j, v, vv;
  306. volatile unsigned int *p;
  307. unsigned int pv;
  308. p = (unsigned int *)addr;
  309. pv = (unsigned int)p;
  310. for (i = 0; i < size / sizeof(unsigned int); i++, pv += sizeof(unsigned int))
  311. *p++ = pv;
  312. p = (unsigned int *)addr;
  313. for (i = 0; i < size / sizeof(unsigned int); i++) {
  314. v = (unsigned int)p;
  315. vv = *p;
  316. if (vv != v) {
  317. printf("%p: read %08x instead of %08x\n", p, vv, v);
  318. hang();
  319. }
  320. p++;
  321. }
  322. for (j = 0; j < 5; j++) {
  323. switch (j) {
  324. case 0: v = 0x00000000; break;
  325. case 1: v = 0xffffffff; break;
  326. case 2: v = 0x55555555; break;
  327. case 3: v = 0xaaaaaaaa; break;
  328. default:v = 0xdeadbeef; break;
  329. }
  330. p = (unsigned int *)addr;
  331. for (i = 0; i < size / sizeof(unsigned int); i++) {
  332. *p = v;
  333. vv = *p;
  334. if (vv != v) {
  335. printf("%p: read %08x instead of %08x\n", p, vv, v);
  336. hang();
  337. }
  338. *p = ~v;
  339. p++;
  340. }
  341. }
  342. }
  343. long int initdram(int board_type)
  344. {
  345. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  346. volatile memctl8xx_t *memctl = &immap->im_memctl;
  347. long int size;
  348. upmconfig(UPMB, (uint *) sdram_table, sizeof(sdram_table) / sizeof(sdram_table[0]));
  349. /*
  350. * Preliminary prescaler for refresh
  351. */
  352. memctl->memc_mptpr = MPTPR_PTP_DIV8;
  353. memctl->memc_mar = MAR_SDRAM_INIT; /* 32-bit address to be output on the address bus if AMX = 0b11 */
  354. /*
  355. * Map controller bank 3 to the SDRAM bank at preliminary address.
  356. */
  357. memctl->memc_or3 = CFG_OR3_PRELIM;
  358. memctl->memc_br3 = CFG_BR3_PRELIM;
  359. memctl->memc_mbmr = CFG_MAMR & ~MAMR_PTAE; /* no refresh yet */
  360. udelay(200);
  361. /* perform SDRAM initialisation sequence */
  362. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS3 | MCR_MLCF(1) | MCR_MAD(0x3C); /* precharge all */
  363. udelay(1);
  364. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS3 | MCR_MLCF(2) | MCR_MAD(0x30); /* refresh 2 times(0) */
  365. udelay(1);
  366. memctl->memc_mcr = MCR_OP_RUN | MCR_UPM_B | MCR_MB_CS3 | MCR_MLCF(1) | MCR_MAD(0x3E); /* exception program (write mar)*/
  367. udelay(1);
  368. memctl->memc_mbmr |= MAMR_PTAE; /* enable refresh */
  369. udelay(10000);
  370. {
  371. u32 d1, d2;
  372. d1 = 0xAA55AA55;
  373. *(volatile u32 *)0 = d1;
  374. d2 = *(volatile u32 *)0;
  375. if (d1 != d2) {
  376. printf("DRAM fails: wrote 0x%08x read 0x%08x\n", d1, d2);
  377. hang();
  378. }
  379. d1 = 0x55AA55AA;
  380. *(volatile u32 *)0 = d1;
  381. d2 = *(volatile u32 *)0;
  382. if (d1 != d2) {
  383. printf("DRAM fails: wrote 0x%08x read 0x%08x\n", d1, d2);
  384. hang();
  385. }
  386. }
  387. size = get_ram_size((long *)0, SDRAM_MAX_SIZE);
  388. if (size == 0) {
  389. printf("SIZE is zero: LOOP on 0\n");
  390. for (;;) {
  391. *(volatile u32 *)0 = 0;
  392. (void)*(volatile u32 *)0;
  393. }
  394. }
  395. return size;
  396. }
  397. /* ------------------------------------------------------------------------- */
  398. void reset_phys(void)
  399. {
  400. int phyno;
  401. unsigned short v;
  402. udelay(10000);
  403. /* reset the damn phys */
  404. mii_init();
  405. for (phyno = 0; phyno < 32; ++phyno) {
  406. fec8xx_miiphy_read(NULL, phyno, PHY_PHYIDR1, &v);
  407. if (v == 0xFFFF)
  408. continue;
  409. fec8xx_miiphy_write(NULL, phyno, PHY_BMCR, PHY_BMCR_POWD);
  410. udelay(10000);
  411. fec8xx_miiphy_write(NULL, phyno, PHY_BMCR,
  412. PHY_BMCR_RESET | PHY_BMCR_AUTON);
  413. udelay(10000);
  414. }
  415. }
  416. /* ------------------------------------------------------------------------- */
  417. /* GP = general purpose, SP = special purpose (on chip peripheral) */
  418. /* bits that can have a special purpose or can be configured as inputs/outputs */
  419. #define PA_GP_INMASK 0
  420. #define PA_GP_OUTMASK (_BW(3) | _BW(7) | _BW(10) | _BW(14) | _BW(15))
  421. #define PA_SP_MASK 0
  422. #define PA_ODR_VAL 0
  423. #define PA_GP_OUTVAL (_BW(3) | _BW(14) | _BW(15))
  424. #define PA_SP_DIRVAL 0
  425. #define PB_GP_INMASK _B(28)
  426. #define PB_GP_OUTMASK (_B(19) | _B(23) | _B(26) | _B(27) | _B(29) | _B(30))
  427. #define PB_SP_MASK (_BR(22, 25))
  428. #define PB_ODR_VAL 0
  429. #define PB_GP_OUTVAL (_B(26) | _B(27) | _B(29) | _B(30))
  430. #define PB_SP_DIRVAL 0
  431. #if CONFIG_NETTA2_VERSION == 1
  432. #define PC_GP_INMASK _BW(12)
  433. #define PC_GP_OUTMASK (_BW(10) | _BW(11) | _BW(13) | _BW(15))
  434. #elif CONFIG_NETTA2_VERSION == 2
  435. #define PC_GP_INMASK (_BW(13) | _BW(15))
  436. #define PC_GP_OUTMASK (_BW(10) | _BW(11) | _BW(12))
  437. #endif
  438. #define PC_SP_MASK 0
  439. #define PC_SOVAL 0
  440. #define PC_INTVAL 0
  441. #define PC_GP_OUTVAL (_BW(10) | _BW(11))
  442. #define PC_SP_DIRVAL 0
  443. #if CONFIG_NETTA2_VERSION == 1
  444. #define PE_GP_INMASK _B(31)
  445. #define PE_GP_OUTMASK (_B(17) | _B(18) |_B(20) | _B(24) | _B(27) | _B(28) | _B(29) | _B(30))
  446. #define PE_GP_OUTVAL (_B(20) | _B(24) | _B(27) | _B(28))
  447. #elif CONFIG_NETTA2_VERSION == 2
  448. #define PE_GP_INMASK _BR(28, 31)
  449. #define PE_GP_OUTMASK (_B(17) | _B(18) |_B(20) | _B(24) | _B(27))
  450. #define PE_GP_OUTVAL (_B(20) | _B(24) | _B(27))
  451. #endif
  452. #define PE_SP_MASK 0
  453. #define PE_ODR_VAL 0
  454. #define PE_SP_DIRVAL 0
  455. int board_early_init_f(void)
  456. {
  457. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  458. volatile iop8xx_t *ioport = &immap->im_ioport;
  459. volatile cpm8xx_t *cpm = &immap->im_cpm;
  460. volatile memctl8xx_t *memctl = &immap->im_memctl;
  461. /* NAND chip select */
  462. #if CONFIG_NETTA2_VERSION == 1
  463. memctl->memc_or1 = ((0xFFFFFFFFLU & ~(NAND_SIZE - 1)) | OR_CSNT_SAM | OR_BI | OR_SCY_8_CLK | OR_EHTR | OR_TRLX);
  464. memctl->memc_br1 = ((NAND_BASE & BR_BA_MSK) | BR_PS_8 | BR_V);
  465. #elif CONFIG_NETTA2_VERSION == 2
  466. upmconfig(UPMA, (uint *) nandcs_table, sizeof(nandcs_table) / sizeof(nandcs_table[0]));
  467. memctl->memc_or1 = ((0xFFFFFFFFLU & ~(NAND_SIZE - 1)) | OR_BI | OR_G5LS);
  468. memctl->memc_br1 = ((NAND_BASE & BR_BA_MSK) | BR_PS_8 | BR_V | BR_MS_UPMA);
  469. memctl->memc_mamr = 0; /* all clear */
  470. #endif
  471. /* DSP chip select */
  472. memctl->memc_or2 = ((0xFFFFFFFFLU & ~(DSP_SIZE - 1)) | OR_CSNT_SAM | OR_BI | OR_ACS_DIV2 | OR_SETA | OR_TRLX);
  473. memctl->memc_br2 = ((DSP_BASE & BR_BA_MSK) | BR_PS_16 | BR_V);
  474. #if CONFIG_NETTA2_VERSION == 1
  475. memctl->memc_br4 &= ~BR_V;
  476. #endif
  477. memctl->memc_br5 &= ~BR_V;
  478. memctl->memc_br6 &= ~BR_V;
  479. memctl->memc_br7 &= ~BR_V;
  480. ioport->iop_padat = PA_GP_OUTVAL;
  481. ioport->iop_paodr = PA_ODR_VAL;
  482. ioport->iop_padir = PA_GP_OUTMASK | PA_SP_DIRVAL;
  483. ioport->iop_papar = PA_SP_MASK;
  484. cpm->cp_pbdat = PB_GP_OUTVAL;
  485. cpm->cp_pbodr = PB_ODR_VAL;
  486. cpm->cp_pbdir = PB_GP_OUTMASK | PB_SP_DIRVAL;
  487. cpm->cp_pbpar = PB_SP_MASK;
  488. ioport->iop_pcdat = PC_GP_OUTVAL;
  489. ioport->iop_pcdir = PC_GP_OUTMASK | PC_SP_DIRVAL;
  490. ioport->iop_pcso = PC_SOVAL;
  491. ioport->iop_pcint = PC_INTVAL;
  492. ioport->iop_pcpar = PC_SP_MASK;
  493. cpm->cp_pedat = PE_GP_OUTVAL;
  494. cpm->cp_peodr = PE_ODR_VAL;
  495. cpm->cp_pedir = PE_GP_OUTMASK | PE_SP_DIRVAL;
  496. cpm->cp_pepar = PE_SP_MASK;
  497. return 0;
  498. }
  499. #if defined(CONFIG_CMD_NAND)
  500. #include <linux/mtd/nand_legacy.h>
  501. extern ulong nand_probe(ulong physadr);
  502. extern struct nand_chip nand_dev_desc[CFG_MAX_NAND_DEVICE];
  503. void nand_init(void)
  504. {
  505. unsigned long totlen;
  506. totlen = nand_probe(CFG_NAND_BASE);
  507. printf ("%4lu MB\n", totlen >> 20);
  508. }
  509. #endif
  510. #ifdef CONFIG_HW_WATCHDOG
  511. void hw_watchdog_reset(void)
  512. {
  513. /* XXX add here the really funky stuff */
  514. }
  515. #endif
  516. #ifdef CONFIG_SHOW_ACTIVITY
  517. /* called from timer interrupt every 1/CFG_HZ sec */
  518. void board_show_activity(ulong timestamp)
  519. {
  520. }
  521. /* called when looping */
  522. void show_activity(int arg)
  523. {
  524. }
  525. #endif
  526. #if defined(CFG_CONSOLE_IS_IN_ENV) && defined(CFG_CONSOLE_OVERWRITE_ROUTINE)
  527. int overwrite_console(void)
  528. {
  529. /* printf("overwrite_console called\n"); */
  530. return 0;
  531. }
  532. #endif
  533. extern int drv_phone_init(void);
  534. extern int drv_phone_use_me(void);
  535. extern int drv_phone_is_idle(void);
  536. int misc_init_r(void)
  537. {
  538. return 0;
  539. }
  540. int last_stage_init(void)
  541. {
  542. #if CONFIG_NETTA2_VERSION == 2
  543. int i;
  544. #endif
  545. #if CONFIG_NETTA2_VERSION == 2
  546. /* assert peripheral reset */
  547. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat &= ~_BW(12);
  548. for (i = 0; i < 10; i++)
  549. udelay(1000);
  550. ((volatile immap_t *)CFG_IMMR)->im_ioport.iop_pcdat |= _BW(12);
  551. #endif
  552. reset_phys();
  553. return 0;
  554. }