tqm8272.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957
  1. /*
  2. * (C) Copyright 2006
  3. * Heiko Schocher, DENX Software Engineering, hs@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 <ioports.h>
  25. #include <mpc8260.h>
  26. #include <command.h>
  27. #include <netdev.h>
  28. #ifdef CONFIG_PCI
  29. #include <pci.h>
  30. #include <asm/m8260_pci.h>
  31. #endif
  32. #include "tqm8272.h"
  33. #if 0
  34. #define deb_printf(fmt,arg...) \
  35. printf ("TQM8272 %s %s: " fmt,__FILE__, __FUNCTION__, ##arg)
  36. #else
  37. #define deb_printf(fmt,arg...) \
  38. do { } while (0)
  39. #endif
  40. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  41. unsigned long board_get_cpu_clk_f (void);
  42. #endif
  43. /*
  44. * I/O Port configuration table
  45. *
  46. * if conf is 1, then that port pin will be configured at boot time
  47. * according to the five values podr/pdir/ppar/psor/pdat for that entry
  48. */
  49. const iop_conf_t iop_conf_tab[4][32] = {
  50. /* Port A configuration */
  51. { /* conf ppar psor pdir podr pdat */
  52. /* PA31 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 *ATMTXEN */
  53. /* PA30 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTCA */
  54. /* PA29 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTSOC */
  55. /* PA28 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 *ATMRXEN */
  56. /* PA27 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRSOC */
  57. /* PA26 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRCA */
  58. /* PA25 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[0] */
  59. /* PA24 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[1] */
  60. /* PA23 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[2] */
  61. /* PA22 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[3] */
  62. /* PA21 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[4] */
  63. /* PA20 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[5] */
  64. /* PA19 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[6] */
  65. /* PA18 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMTXD[7] */
  66. /* PA17 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[7] */
  67. /* PA16 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[6] */
  68. /* PA15 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[5] */
  69. /* PA14 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[4] */
  70. /* PA13 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[3] */
  71. /* PA12 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[2] */
  72. /* PA11 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[1] */
  73. /* PA10 */ { 0, 0, 0, 1, 0, 0 }, /* FCC1 ATMRXD[0] */
  74. /* PA9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC2 TXD */
  75. /* PA8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC2 RXD */
  76. /* PA7 */ { 0, 0, 0, 1, 0, 0 }, /* PA7 */
  77. /* PA6 */ { 0, 0, 0, 1, 0, 0 }, /* PA6 */
  78. /* PA5 */ { 0, 0, 0, 1, 0, 0 }, /* PA5 */
  79. /* PA4 */ { 0, 0, 0, 1, 0, 0 }, /* PA4 */
  80. /* PA3 */ { 0, 0, 0, 1, 0, 0 }, /* PA3 */
  81. /* PA2 */ { 0, 0, 0, 1, 0, 0 }, /* PA2 */
  82. /* PA1 */ { 0, 0, 0, 1, 0, 0 }, /* PA1 */
  83. /* PA0 */ { 0, 0, 0, 1, 0, 0 } /* PA0 */
  84. },
  85. /* Port B configuration */
  86. { /* conf ppar psor pdir podr pdat */
  87. /* PB31 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TX_ER */
  88. /* PB30 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_DV */
  89. /* PB29 */ { 1, 1, 1, 1, 0, 0 }, /* FCC2 MII TX_EN */
  90. /* PB28 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_ER */
  91. /* PB27 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII COL */
  92. /* PB26 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII CRS */
  93. /* PB25 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[3] */
  94. /* PB24 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[2] */
  95. /* PB23 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[1] */
  96. /* PB22 */ { 1, 1, 0, 1, 0, 0 }, /* FCC2 MII TxD[0] */
  97. /* PB21 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[0] */
  98. /* PB20 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[1] */
  99. /* PB19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[2] */
  100. /* PB18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RxD[3] */
  101. /* PB17 */ { 0, 0, 0, 0, 0, 0 }, /* PB17 */
  102. /* PB16 */ { 0, 0, 0, 0, 0, 0 }, /* PB16 */
  103. /* PB15 */ { 0, 0, 0, 0, 0, 0 }, /* PB15 */
  104. /* PB14 */ { 0, 0, 0, 0, 0, 0 }, /* PB14 */
  105. /* PB13 */ { 0, 0, 0, 0, 0, 0 }, /* PB13 */
  106. /* PB12 */ { 0, 0, 0, 0, 0, 0 }, /* PB12 */
  107. /* PB11 */ { 0, 0, 0, 0, 0, 0 }, /* PB11 */
  108. /* PB10 */ { 0, 0, 0, 0, 0, 0 }, /* PB10 */
  109. /* PB9 */ { 0, 0, 0, 0, 0, 0 }, /* PB9 */
  110. /* PB8 */ { 0, 0, 0, 0, 0, 0 }, /* PB8 */
  111. /* PB7 */ { 0, 0, 0, 0, 0, 0 }, /* PB7 */
  112. /* PB6 */ { 0, 0, 0, 0, 0, 0 }, /* PB6 */
  113. /* PB5 */ { 0, 0, 0, 0, 0, 0 }, /* PB5 */
  114. /* PB4 */ { 0, 0, 0, 0, 0, 0 }, /* PB4 */
  115. /* PB3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  116. /* PB2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  117. /* PB1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  118. /* PB0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  119. },
  120. /* Port C */
  121. { /* conf ppar psor pdir podr pdat */
  122. /* PC31 */ { 0, 0, 0, 1, 0, 0 }, /* PC31 */
  123. /* PC30 */ { 0, 0, 0, 0, 0, 0 }, /* PC30 */
  124. /* PC29 */ { 1, 1, 1, 0, 0, 0 }, /* SCC1 EN *CLSN */
  125. /* PC28 */ { 0, 0, 0, 1, 0, 0 }, /* PC28 */
  126. /* PC27 */ { 0, 0, 0, 1, 0, 0 }, /* PC27 */
  127. /* PC26 */ { 0, 0, 0, 1, 0, 0 }, /* PC26 */
  128. /* PC25 */ { 0, 0, 0, 1, 0, 0 }, /* PC25 */
  129. /* PC24 */ { 0, 0, 0, 1, 0, 0 }, /* PC24 */
  130. /* PC23 */ { 0, 1, 0, 1, 0, 0 }, /* ATMTFCLK */
  131. /* PC22 */ { 0, 1, 0, 0, 0, 0 }, /* ATMRFCLK */
  132. /* PC21 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RXCLK */
  133. /* PC20 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN TXCLK */
  134. /* PC19 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII RX_CLK */
  135. /* PC18 */ { 1, 1, 0, 0, 0, 0 }, /* FCC2 MII TX_CLK */
  136. /* PC17 */ { 1, 0, 0, 1, 0, 0 }, /* PC17 MDC */
  137. /* PC16 */ { 1, 0, 0, 0, 0, 0 }, /* PC16 MDIO*/
  138. /* PC15 */ { 0, 0, 0, 1, 0, 0 }, /* PC15 */
  139. /* PC14 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN *CD */
  140. /* PC13 */ { 0, 0, 0, 1, 0, 0 }, /* PC13 */
  141. /* PC12 */ { 0, 0, 0, 1, 0, 0 }, /* PC12 */
  142. /* PC11 */ { 0, 0, 0, 1, 0, 0 }, /* PC11 */
  143. /* PC10 */ { 0, 0, 0, 1, 0, 0 }, /* PC10 */
  144. /* PC9 */ { 0, 0, 0, 1, 0, 0 }, /* PC9 */
  145. /* PC8 */ { 0, 0, 0, 1, 0, 0 }, /* PC8 */
  146. /* PC7 */ { 0, 0, 0, 1, 0, 0 }, /* PC7 */
  147. /* PC6 */ { 0, 0, 0, 1, 0, 0 }, /* PC6 */
  148. /* PC5 */ { 1, 1, 0, 1, 0, 0 }, /* PC5 SMC1 TXD */
  149. /* PC4 */ { 1, 1, 0, 0, 0, 0 }, /* PC4 SMC1 RXD */
  150. /* PC3 */ { 0, 0, 0, 1, 0, 0 }, /* PC3 */
  151. /* PC2 */ { 0, 0, 0, 1, 0, 1 }, /* ENET FDE */
  152. /* PC1 */ { 0, 0, 0, 1, 0, 0 }, /* ENET DSQE */
  153. /* PC0 */ { 0, 0, 0, 1, 0, 0 }, /* ENET LBK */
  154. },
  155. /* Port D */
  156. { /* conf ppar psor pdir podr pdat */
  157. /* PD31 */ { 1, 1, 0, 0, 0, 0 }, /* SCC1 EN RxD */
  158. /* PD30 */ { 1, 1, 1, 1, 0, 0 }, /* SCC1 EN TxD */
  159. /* PD29 */ { 1, 1, 0, 1, 0, 0 }, /* SCC1 EN TENA */
  160. /* PD28 */ { 0, 0, 0, 1, 0, 0 }, /* PD28 */
  161. /* PD27 */ { 0, 0, 0, 1, 0, 0 }, /* PD27 */
  162. /* PD26 */ { 0, 0, 0, 1, 0, 0 }, /* PD26 */
  163. /* PD25 */ { 0, 0, 0, 1, 0, 0 }, /* PD25 */
  164. /* PD24 */ { 0, 0, 0, 1, 0, 0 }, /* PD24 */
  165. /* PD23 */ { 0, 0, 0, 1, 0, 0 }, /* PD23 */
  166. /* PD22 */ { 0, 0, 0, 1, 0, 0 }, /* PD22 */
  167. /* PD21 */ { 0, 0, 0, 1, 0, 0 }, /* PD21 */
  168. /* PD20 */ { 0, 0, 0, 1, 0, 0 }, /* PD20 */
  169. /* PD19 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
  170. /* PD18 */ { 0, 0, 0, 1, 0, 0 }, /* PD19 */
  171. /* PD17 */ { 0, 1, 0, 0, 0, 0 }, /* FCC1 ATMRXPRTY */
  172. /* PD16 */ { 0, 1, 0, 1, 0, 0 }, /* FCC1 ATMTXPRTY */
  173. #if defined(CONFIG_SOFT_I2C)
  174. /* PD15 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SDA */
  175. /* PD14 */ { 1, 0, 0, 1, 1, 1 }, /* I2C SCL */
  176. #else
  177. #if defined(CONFIG_HARD_I2C)
  178. /* PD15 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SDA */
  179. /* PD14 */ { 1, 1, 1, 0, 1, 0 }, /* I2C SCL */
  180. #else /* normal I/O port pins */
  181. /* PD15 */ { 0, 1, 1, 0, 1, 0 }, /* I2C SDA */
  182. /* PD14 */ { 0, 1, 1, 0, 1, 0 }, /* I2C SCL */
  183. #endif
  184. #endif
  185. /* PD13 */ { 0, 0, 0, 0, 0, 0 }, /* PD13 */
  186. /* PD12 */ { 0, 0, 0, 0, 0, 0 }, /* PD12 */
  187. /* PD11 */ { 0, 0, 0, 0, 0, 0 }, /* PD11 */
  188. /* PD10 */ { 0, 0, 0, 0, 0, 0 }, /* PD10 */
  189. /* PD9 */ { 1, 1, 0, 1, 0, 0 }, /* SMC1 TXD */
  190. /* PD8 */ { 1, 1, 0, 0, 0, 0 }, /* SMC1 RXD */
  191. /* PD7 */ { 0, 0, 0, 1, 0, 1 }, /* PD7 */
  192. /* PD6 */ { 0, 0, 0, 1, 0, 1 }, /* PD6 */
  193. /* PD5 */ { 0, 0, 0, 1, 0, 0 }, /* PD5 */
  194. /* PD4 */ { 0, 0, 0, 1, 0, 1 }, /* PD4 */
  195. /* PD3 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  196. /* PD2 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  197. /* PD1 */ { 0, 0, 0, 0, 0, 0 }, /* pin doesn't exist */
  198. /* PD0 */ { 0, 0, 0, 0, 0, 0 } /* pin doesn't exist */
  199. }
  200. };
  201. /* UPM pattern for slow init */
  202. static const uint upmTableSlow[] =
  203. {
  204. /* Offset UPM Read Single RAM array entry */
  205. /* 0x00 */ 0xffffee00, 0x00ffcc80, 0x00ffcf00, 0x00ffdc00,
  206. /* 0x04 */ 0x00ffce80, 0x00ffcc00, 0x00ffee00, 0x3fffcc07,
  207. /* UPM Read Burst RAM array entry -> unused */
  208. /* 0x08 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  209. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  210. /* UPM Read Burst RAM array entry -> unused */
  211. /* 0x10 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  212. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  213. /* UPM Write Single RAM array entry */
  214. /* 0x18 */ 0xffffee00, 0x00ffec80, 0x00ffef00, 0x00fffc80,
  215. /* 0x1C */ 0x00fffe00, 0x00ffec00, 0x0fffef00, 0x3fffec05,
  216. /* UPM Write Burst RAM array entry -> unused */
  217. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  218. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  219. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  220. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  221. /* UPM Refresh Timer RAM array entry -> unused */
  222. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  223. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  224. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  225. /* UPM Exception RAM array entry -> unused */
  226. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  227. };
  228. /* UPM pattern for fast init */
  229. static const uint upmTableFast[] =
  230. {
  231. /* Offset UPM Read Single RAM array entry */
  232. /* 0x00 */ 0xffffee00, 0x00ffcc80, 0x00ffcd80, 0x00ffdc00,
  233. /* 0x04 */ 0x00ffdc00, 0x00ffcf00, 0x00ffec00, 0x3fffcc07,
  234. /* UPM Read Burst RAM array entry -> unused */
  235. /* 0x08 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  236. /* 0x0C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  237. /* UPM Read Burst RAM array entry -> unused */
  238. /* 0x10 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  239. /* 0x14 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  240. /* UPM Write Single RAM array entry */
  241. /* 0x18 */ 0xffffee00, 0x00ffec80, 0x00ffee80, 0x00fffc00,
  242. /* 0x1C */ 0x00fffc00, 0x00ffec00, 0x0fffef00, 0x3fffec05,
  243. /* UPM Write Burst RAM array entry -> unused */
  244. /* 0x20 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  245. /* 0x24 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  246. /* 0x28 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  247. /* 0x2C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  248. /* UPM Refresh Timer RAM array entry -> unused */
  249. /* 0x30 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  250. /* 0x34 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc00,
  251. /* 0x38 */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  252. /* UPM Exception RAM array entry -> unused */
  253. /* 0x3C */ 0xfffffc00, 0xfffffc00, 0xfffffc00, 0xfffffc01,
  254. };
  255. /* ------------------------------------------------------------------------- */
  256. /* Check Board Identity:
  257. */
  258. int checkboard (void)
  259. {
  260. char *p = (char *) HWIB_INFO_START_ADDR;
  261. puts ("Board: ");
  262. if (*((unsigned long *)p) == (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  263. puts (p);
  264. } else {
  265. puts ("No HWIB assuming TQM8272");
  266. }
  267. putc ('\n');
  268. return 0;
  269. }
  270. /* ------------------------------------------------------------------------- */
  271. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  272. static int get_cas_latency (void)
  273. {
  274. /* get it from the option -ts in CIB */
  275. /* default is 3 */
  276. int ret = 3;
  277. int pos = 0;
  278. char *p = (char *) CIB_INFO_START_ADDR;
  279. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  280. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  281. return ret;
  282. }
  283. if (*p == '-') {
  284. if ((p[1] == 't') && (p[2] == 's')) {
  285. return (p[4] - '0');
  286. }
  287. }
  288. p++;
  289. pos++;
  290. }
  291. return ret;
  292. }
  293. #endif
  294. static ulong set_sdram_timing (volatile uint *sdmr_ptr, ulong sdmr, int col)
  295. {
  296. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  297. int clk = board_get_cpu_clk_f ();
  298. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  299. int busmode = (immr->im_siu_conf.sc_bcr & BCR_EBM ? 1 : 0);
  300. int cas;
  301. sdmr = sdmr & ~(PSDMR_RFRC_MSK | PSDMR_PRETOACT_MSK | PSDMR_WRC_MSK | \
  302. PSDMR_BUFCMD);
  303. if (busmode) {
  304. switch (clk) {
  305. case 66666666:
  306. sdmr |= (PSDMR_RFRC_66MHZ_60X | \
  307. PSDMR_PRETOACT_66MHZ_60X | \
  308. PSDMR_WRC_66MHZ_60X | \
  309. PSDMR_BUFCMD_66MHZ_60X);
  310. break;
  311. case 100000000:
  312. sdmr |= (PSDMR_RFRC_100MHZ_60X | \
  313. PSDMR_PRETOACT_100MHZ_60X | \
  314. PSDMR_WRC_100MHZ_60X | \
  315. PSDMR_BUFCMD_100MHZ_60X);
  316. break;
  317. }
  318. } else {
  319. switch (clk) {
  320. case 66666666:
  321. sdmr |= (PSDMR_RFRC_66MHZ_SINGLE | \
  322. PSDMR_PRETOACT_66MHZ_SINGLE | \
  323. PSDMR_WRC_66MHZ_SINGLE | \
  324. PSDMR_BUFCMD_66MHZ_SINGLE);
  325. break;
  326. case 100000000:
  327. sdmr |= (PSDMR_RFRC_100MHZ_SINGLE | \
  328. PSDMR_PRETOACT_100MHZ_SINGLE | \
  329. PSDMR_WRC_100MHZ_SINGLE | \
  330. PSDMR_BUFCMD_100MHZ_SINGLE);
  331. break;
  332. case 133333333:
  333. sdmr |= (PSDMR_RFRC_133MHZ_SINGLE | \
  334. PSDMR_PRETOACT_133MHZ_SINGLE | \
  335. PSDMR_WRC_133MHZ_SINGLE | \
  336. PSDMR_BUFCMD_133MHZ_SINGLE);
  337. break;
  338. }
  339. }
  340. cas = get_cas_latency();
  341. sdmr &=~ (PSDMR_CL_MSK | PSDMR_LDOTOPRE_MSK);
  342. sdmr |= cas;
  343. sdmr |= ((cas - 1) << 6);
  344. return sdmr;
  345. #else
  346. return sdmr;
  347. #endif
  348. }
  349. /* Try SDRAM initialization with P/LSDMR=sdmr and ORx=orx
  350. *
  351. * This routine performs standard 8260 initialization sequence
  352. * and calculates the available memory size. It may be called
  353. * several times to try different SDRAM configurations on both
  354. * 60x and local buses.
  355. */
  356. static long int try_init (volatile memctl8260_t * memctl, ulong sdmr,
  357. ulong orx, volatile uchar * base, int col)
  358. {
  359. volatile uchar c = 0xff;
  360. volatile uint *sdmr_ptr;
  361. volatile uint *orx_ptr;
  362. ulong maxsize, size;
  363. int i;
  364. /* We must be able to test a location outsize the maximum legal size
  365. * to find out THAT we are outside; but this address still has to be
  366. * mapped by the controller. That means, that the initial mapping has
  367. * to be (at least) twice as large as the maximum expected size.
  368. */
  369. maxsize = (1 + (~orx | 0x7fff)) / 2;
  370. /* Since CONFIG_SYS_SDRAM_BASE is always 0 (??), we assume that
  371. * we are configuring CS1 if base != 0
  372. */
  373. sdmr_ptr = base ? &memctl->memc_lsdmr : &memctl->memc_psdmr;
  374. orx_ptr = base ? &memctl->memc_or2 : &memctl->memc_or1;
  375. *orx_ptr = orx;
  376. sdmr = set_sdram_timing (sdmr_ptr, sdmr, col);
  377. /*
  378. * Quote from 8260 UM (10.4.2 SDRAM Power-On Initialization, 10-35):
  379. *
  380. * "At system reset, initialization software must set up the
  381. * programmable parameters in the memory controller banks registers
  382. * (ORx, BRx, P/LSDMR). After all memory parameters are configured,
  383. * system software should execute the following initialization sequence
  384. * for each SDRAM device.
  385. *
  386. * 1. Issue a PRECHARGE-ALL-BANKS command
  387. * 2. Issue eight CBR REFRESH commands
  388. * 3. Issue a MODE-SET command to initialize the mode register
  389. *
  390. * The initial commands are executed by setting P/LSDMR[OP] and
  391. * accessing the SDRAM with a single-byte transaction."
  392. *
  393. * The appropriate BRx/ORx registers have already been set when we
  394. * get here. The SDRAM can be accessed at the address CONFIG_SYS_SDRAM_BASE.
  395. */
  396. *sdmr_ptr = sdmr | PSDMR_OP_PREA;
  397. *base = c;
  398. *sdmr_ptr = sdmr | PSDMR_OP_CBRR;
  399. for (i = 0; i < 8; i++)
  400. *base = c;
  401. *sdmr_ptr = sdmr | PSDMR_OP_MRW;
  402. *(base + CONFIG_SYS_MRS_OFFS) = c; /* setting MR on address lines */
  403. *sdmr_ptr = sdmr | PSDMR_OP_NORM | PSDMR_RFEN;
  404. *base = c;
  405. size = get_ram_size((long *)base, maxsize);
  406. *orx_ptr = orx | ~(size - 1);
  407. return (size);
  408. }
  409. phys_size_t initdram (int board_type)
  410. {
  411. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  412. volatile memctl8260_t *memctl = &immap->im_memctl;
  413. #ifndef CONFIG_SYS_RAMBOOT
  414. long size8, size9;
  415. #endif
  416. long psize, lsize;
  417. psize = 16 * 1024 * 1024;
  418. lsize = 0;
  419. memctl->memc_psrt = CONFIG_SYS_PSRT;
  420. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  421. #ifndef CONFIG_SYS_RAMBOOT
  422. /* 60x SDRAM setup:
  423. */
  424. size8 = try_init (memctl, CONFIG_SYS_PSDMR_8COL, CONFIG_SYS_OR1_8COL,
  425. (uchar *) CONFIG_SYS_SDRAM_BASE, 8);
  426. size9 = try_init (memctl, CONFIG_SYS_PSDMR_9COL, CONFIG_SYS_OR1_9COL,
  427. (uchar *) CONFIG_SYS_SDRAM_BASE, 9);
  428. if (size8 < size9) {
  429. psize = size9;
  430. printf ("(60x:9COL - %ld MB, ", psize >> 20);
  431. } else {
  432. psize = try_init (memctl, CONFIG_SYS_PSDMR_8COL, CONFIG_SYS_OR1_8COL,
  433. (uchar *) CONFIG_SYS_SDRAM_BASE, 8);
  434. printf ("(60x:8COL - %ld MB, ", psize >> 20);
  435. }
  436. #endif /* CONFIG_SYS_RAMBOOT */
  437. icache_enable ();
  438. return (psize);
  439. }
  440. static inline int scanChar (char *p, int len, unsigned long *number)
  441. {
  442. int akt = 0;
  443. *number = 0;
  444. while (akt < len) {
  445. if ((*p >= '0') && (*p <= '9')) {
  446. *number *= 10;
  447. *number += *p - '0';
  448. p += 1;
  449. } else {
  450. if (*p == '-') return akt;
  451. return -1;
  452. }
  453. akt ++;
  454. }
  455. return akt;
  456. }
  457. static int dump_hwib(void)
  458. {
  459. HWIB_INFO *hw = &hwinf;
  460. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  461. char *s = getenv("serial#");
  462. if (hw->OK) {
  463. printf ("HWIB on %x\n", HWIB_INFO_START_ADDR);
  464. printf ("serial : %s\n", s);
  465. printf ("ethaddr: %s\n", hw->ethaddr);
  466. printf ("FLASH : %x nr:%d\n", hw->flash, hw->flash_nr);
  467. printf ("RAM : %x cs:%d\n", hw->ram, hw->ram_cs);
  468. printf ("CPU : %lu\n", hw->cpunr);
  469. printf ("CAN : %d\n", hw->can);
  470. if (hw->eeprom) printf ("EEprom : %x\n", hw->eeprom);
  471. else printf ("No EEprom\n");
  472. if (hw->nand) {
  473. printf ("NAND : %x\n", hw->nand);
  474. printf ("NAND CS: %d\n", hw->nand_cs);
  475. } else { printf ("No NAND\n");}
  476. printf ("Bus %s mode.\n", (hw->Bus ? "60x" : "Single PQII"));
  477. printf (" real : %s\n", (immr->im_siu_conf.sc_bcr & BCR_EBM ? \
  478. "60x" : "Single PQII"));
  479. printf ("Option : %lx\n", hw->option);
  480. printf ("%s Security Engine\n", (hw->SecEng ? "with" : "no"));
  481. printf ("CPM Clk: %d\n", hw->cpmcl);
  482. printf ("CPU Clk: %d\n", hw->cpucl);
  483. printf ("Bus Clk: %d\n", hw->buscl);
  484. if (hw->busclk_real_ok) {
  485. printf (" real Clk: %d\n", hw->busclk_real);
  486. }
  487. printf ("CAS : %d\n", get_cas_latency());
  488. } else {
  489. printf("HWIB @%x not OK\n", HWIB_INFO_START_ADDR);
  490. }
  491. return 0;
  492. }
  493. static inline int search_real_busclk (int *clk)
  494. {
  495. int part = 0, pos = 0;
  496. char *p = (char *) CIB_INFO_START_ADDR;
  497. int ok = 0;
  498. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  499. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  500. return 0;
  501. }
  502. switch (part) {
  503. default:
  504. if (*p == '-') {
  505. ++part;
  506. }
  507. break;
  508. case 3:
  509. if (*p == '-') {
  510. ++part;
  511. break;
  512. }
  513. if (*p == 'b') {
  514. ok = 1;
  515. p++;
  516. break;
  517. }
  518. if (ok) {
  519. switch (*p) {
  520. case '6':
  521. *clk = 66666666;
  522. return 1;
  523. break;
  524. case '1':
  525. if (p[1] == '3') {
  526. *clk = 133333333;
  527. } else {
  528. *clk = 100000000;
  529. }
  530. return 1;
  531. break;
  532. }
  533. }
  534. break;
  535. }
  536. p++;
  537. }
  538. return 0;
  539. }
  540. int analyse_hwib (void)
  541. {
  542. char *p = (char *) HWIB_INFO_START_ADDR;
  543. int anz;
  544. int part = 1, i = 0, pos = 0;
  545. HWIB_INFO *hw = &hwinf;
  546. deb_printf(" %s pointer: %p\n", __FUNCTION__, p);
  547. /* Head = TQM */
  548. if (*((unsigned long *)p) != (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  549. deb_printf("No HWIB\n");
  550. return -1;
  551. }
  552. p += 3;
  553. if (scanChar (p, 4, &hw->cpunr) < 0) {
  554. deb_printf("No CPU\n");
  555. return -2;
  556. }
  557. p +=4;
  558. hw->flash = 0x200000 << (*p - 'A');
  559. p++;
  560. hw->flash_nr = *p - '0';
  561. p++;
  562. hw->ram = 0x2000000 << (*p - 'A');
  563. p++;
  564. if (*p == '2') {
  565. hw->ram_cs = 2;
  566. p++;
  567. }
  568. if (*p == 'A') hw->can = 1;
  569. if (*p == 'B') hw->can = 2;
  570. p +=1;
  571. p +=1; /* connector */
  572. if (*p != '0') {
  573. hw->eeprom = 0x1000 << (*p - 'A');
  574. }
  575. p++;
  576. if ((*p < '0') || (*p > '9')) {
  577. /* NAND before z-option */
  578. hw->nand = 0x8000000 << (*p - 'A');
  579. p++;
  580. hw->nand_cs = *p - '0';
  581. p += 2;
  582. }
  583. /* z-option */
  584. anz = scanChar (p, 4, &hw->option);
  585. if (anz < 0) {
  586. deb_printf("No option\n");
  587. return -3;
  588. }
  589. if (hw->option & 0x8) hw->Bus = 1;
  590. p += anz;
  591. if (*p != '-') {
  592. deb_printf("No -\n");
  593. return -4;
  594. }
  595. p++;
  596. /* C option */
  597. if (*p == 'E') {
  598. hw->SecEng = 1;
  599. p++;
  600. }
  601. switch (*p) {
  602. case 'M': hw->cpucl = 266666666;
  603. break;
  604. case 'P': hw->cpucl = 300000000;
  605. break;
  606. case 'T': hw->cpucl = 400000000;
  607. break;
  608. default:
  609. deb_printf("No CPU Clk: %c\n", *p);
  610. return -5;
  611. break;
  612. }
  613. p++;
  614. switch (*p) {
  615. case 'I': hw->cpmcl = 200000000;
  616. break;
  617. case 'M': hw->cpmcl = 300000000;
  618. break;
  619. default:
  620. deb_printf("No CPM Clk\n");
  621. return -6;
  622. break;
  623. }
  624. p++;
  625. switch (*p) {
  626. case 'B': hw->buscl = 66666666;
  627. break;
  628. case 'E': hw->buscl = 100000000;
  629. break;
  630. case 'F': hw->buscl = 133333333;
  631. break;
  632. default:
  633. deb_printf("No BUS Clk\n");
  634. return -7;
  635. break;
  636. }
  637. p++;
  638. hw->OK = 1;
  639. /* search MAC Address */
  640. while ((*p != '\0') && (pos < CONFIG_SYS_HWINFO_SIZE)) {
  641. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  642. return 0;
  643. }
  644. switch (part) {
  645. default:
  646. if (*p == ' ') {
  647. ++part;
  648. i = 0;
  649. }
  650. break;
  651. case 3: /* Copy MAC address */
  652. if (*p == ' ') {
  653. ++part;
  654. i = 0;
  655. break;
  656. }
  657. hw->ethaddr[i++] = *p;
  658. if ((i % 3) == 2)
  659. hw->ethaddr[i++] = ':';
  660. break;
  661. }
  662. p++;
  663. }
  664. hw->busclk_real_ok = search_real_busclk (&hw->busclk_real);
  665. return 0;
  666. }
  667. #if defined(CONFIG_GET_CPU_STR_F)
  668. /* !! This routine runs from Flash */
  669. char get_cpu_str_f (char *buf)
  670. {
  671. char *p = (char *) HWIB_INFO_START_ADDR;
  672. int i = 0;
  673. buf[i++] = 'M';
  674. buf[i++] = 'P';
  675. buf[i++] = 'C';
  676. if (*((unsigned long *)p) == (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  677. buf[i++] = *&p[3];
  678. buf[i++] = *&p[4];
  679. buf[i++] = *&p[5];
  680. buf[i++] = *&p[6];
  681. } else {
  682. buf[i++] = '8';
  683. buf[i++] = '2';
  684. buf[i++] = '7';
  685. buf[i++] = 'x';
  686. }
  687. buf[i++] = 0;
  688. return 0;
  689. }
  690. #endif
  691. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  692. /* !! This routine runs from Flash */
  693. unsigned long board_get_cpu_clk_f (void)
  694. {
  695. char *p = (char *) HWIB_INFO_START_ADDR;
  696. int i = 0;
  697. if (*((unsigned long *)p) == (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  698. if (search_real_busclk (&i))
  699. return i;
  700. }
  701. return CONFIG_8260_CLKIN;
  702. }
  703. #endif
  704. #if CONFIG_BOARD_EARLY_INIT_R
  705. static int can_test (unsigned long off)
  706. {
  707. volatile unsigned char *base = (unsigned char *) (CONFIG_SYS_CAN_BASE + off);
  708. *(base + 0x17) = 'T';
  709. *(base + 0x18) = 'Q';
  710. *(base + 0x19) = 'M';
  711. if ((*(base + 0x17) != 'T') ||
  712. (*(base + 0x18) != 'Q') ||
  713. (*(base + 0x19) != 'M')) {
  714. return 0;
  715. }
  716. return 1;
  717. }
  718. static int can_config_one (unsigned long off)
  719. {
  720. volatile unsigned char *ctrl = (unsigned char *) (CONFIG_SYS_CAN_BASE + off);
  721. volatile unsigned char *cpu_if = (unsigned char *) (CONFIG_SYS_CAN_BASE + off + 0x02);
  722. volatile unsigned char *clkout = (unsigned char *) (CONFIG_SYS_CAN_BASE + off + 0x1f);
  723. unsigned char temp;
  724. *cpu_if = 0x45;
  725. temp = *ctrl;
  726. temp |= 0x40;
  727. *ctrl = temp;
  728. *clkout = 0x20;
  729. temp = *ctrl;
  730. temp &= ~0x40;
  731. *ctrl = temp;
  732. return 0;
  733. }
  734. static int can_config (void)
  735. {
  736. int ret = 0;
  737. can_config_one (0);
  738. if (hwinf.can == 2) {
  739. can_config_one (0x100);
  740. }
  741. /* make Test if they really there */
  742. ret += can_test (0);
  743. ret += can_test (0x100);
  744. return ret;
  745. }
  746. static int init_can (void)
  747. {
  748. volatile immap_t * immr = (immap_t *)CONFIG_SYS_IMMR;
  749. volatile memctl8260_t *memctl = &immr->im_memctl;
  750. int count = 0;
  751. if ((hwinf.OK) && (hwinf.can)) {
  752. memctl->memc_or4 = CONFIG_SYS_CAN_OR;
  753. memctl->memc_br4 = CONFIG_SYS_CAN_BR;
  754. /* upm Init */
  755. upmconfig (UPMC, (uint *) upmTableFast,
  756. sizeof (upmTableFast) / sizeof (uint));
  757. memctl->memc_mcmr = (MxMR_DSx_3_CYCL |
  758. MxMR_GPL_x4DIS |
  759. MxMR_RLFx_2X |
  760. MxMR_WLFx_2X |
  761. MxMR_OP_NORM);
  762. /* can configure */
  763. count = can_config ();
  764. printf ("CAN: %d @ %x\n", count, CONFIG_SYS_CAN_BASE);
  765. if (hwinf.can != count) printf("!!! difference to HWIB\n");
  766. } else {
  767. printf ("CAN: No\n");
  768. }
  769. return 0;
  770. }
  771. int board_early_init_r(void)
  772. {
  773. analyse_hwib ();
  774. init_can ();
  775. return 0;
  776. }
  777. #endif
  778. int do_hwib_dump (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  779. {
  780. dump_hwib ();
  781. return 0;
  782. }
  783. U_BOOT_CMD(
  784. hwib, 1, 1, do_hwib_dump,
  785. "dump HWIB'",
  786. "\n"
  787. );
  788. #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
  789. static int get_flash_timing (void)
  790. {
  791. /* get it from the option -tf in CIB */
  792. /* default is 0x00000c84 */
  793. int ret = 0x00000c84;
  794. int pos = 0;
  795. int nr = 0;
  796. char *p = (char *) CIB_INFO_START_ADDR;
  797. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  798. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  799. return ret;
  800. }
  801. if (*p == '-') {
  802. if ((p[1] == 't') && (p[2] == 'f')) {
  803. p += 6;
  804. ret = 0;
  805. while (nr < 8) {
  806. if ((*p >= '0') && (*p <= '9')) {
  807. ret *= 0x10;
  808. ret += *p - '0';
  809. p += 1;
  810. nr ++;
  811. } else if ((*p >= 'A') && (*p <= 'F')) {
  812. ret *= 10;
  813. ret += *p - '7';
  814. p += 1;
  815. nr ++;
  816. } else {
  817. if (nr < 8) return 0x00000c84;
  818. return ret;
  819. }
  820. }
  821. }
  822. }
  823. p++;
  824. pos++;
  825. }
  826. return ret;
  827. }
  828. /* Update the Flash_Size and the Flash Timing */
  829. int update_flash_size (int flash_size)
  830. {
  831. volatile immap_t * immr = (immap_t *)CONFIG_SYS_IMMR;
  832. volatile memctl8260_t *memctl = &immr->im_memctl;
  833. unsigned long reg;
  834. unsigned long tim;
  835. /* I must use reg, otherwise the board hang */
  836. reg = memctl->memc_or0;
  837. reg &= ~ORxU_AM_MSK;
  838. reg |= MEG_TO_AM(flash_size >> 20);
  839. tim = get_flash_timing ();
  840. reg &= ~0xfff;
  841. reg |= (tim & 0xfff);
  842. memctl->memc_or0 = reg;
  843. return 0;
  844. }
  845. #endif
  846. #ifdef CONFIG_PCI
  847. struct pci_controller hose;
  848. int board_early_init_f (void)
  849. {
  850. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  851. immap->im_clkrst.car_sccr |= M826X_SCCR_PCI_MODE_EN;
  852. return 0;
  853. }
  854. extern void pci_mpc8250_init(struct pci_controller *);
  855. void pci_init_board(void)
  856. {
  857. pci_mpc8250_init(&hose);
  858. }
  859. #endif
  860. int board_eth_init(bd_t *bis)
  861. {
  862. return pci_eth_init(bis);
  863. }