tqm8272.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960
  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;
  417. psize = 16 * 1024 * 1024;
  418. memctl->memc_psrt = CONFIG_SYS_PSRT;
  419. memctl->memc_mptpr = CONFIG_SYS_MPTPR;
  420. #ifndef CONFIG_SYS_RAMBOOT
  421. /* 60x SDRAM setup:
  422. */
  423. size8 = try_init (memctl, CONFIG_SYS_PSDMR_8COL, CONFIG_SYS_OR1_8COL,
  424. (uchar *) CONFIG_SYS_SDRAM_BASE, 8);
  425. size9 = try_init (memctl, CONFIG_SYS_PSDMR_9COL, CONFIG_SYS_OR1_9COL,
  426. (uchar *) CONFIG_SYS_SDRAM_BASE, 9);
  427. if (size8 < size9) {
  428. psize = size9;
  429. printf ("(60x:9COL - %ld MB, ", psize >> 20);
  430. } else {
  431. psize = try_init (memctl, CONFIG_SYS_PSDMR_8COL, CONFIG_SYS_OR1_8COL,
  432. (uchar *) CONFIG_SYS_SDRAM_BASE, 8);
  433. printf ("(60x:8COL - %ld MB, ", psize >> 20);
  434. }
  435. #endif /* CONFIG_SYS_RAMBOOT */
  436. icache_enable ();
  437. return (psize);
  438. }
  439. static inline int scanChar (char *p, int len, unsigned long *number)
  440. {
  441. int akt = 0;
  442. *number = 0;
  443. while (akt < len) {
  444. if ((*p >= '0') && (*p <= '9')) {
  445. *number *= 10;
  446. *number += *p - '0';
  447. p += 1;
  448. } else {
  449. if (*p == '-') return akt;
  450. return -1;
  451. }
  452. akt ++;
  453. }
  454. return akt;
  455. }
  456. static int dump_hwib(void)
  457. {
  458. HWIB_INFO *hw = &hwinf;
  459. char buf[64];
  460. int i = getenv_f("serial#", buf, sizeof(buf));
  461. volatile immap_t *immr = (immap_t *)CONFIG_SYS_IMMR;
  462. if (i < 0)
  463. buf[0] = '\0';
  464. if (hw->OK) {
  465. printf ("HWIB on %x\n", HWIB_INFO_START_ADDR);
  466. printf ("serial : %s\n", buf);
  467. printf ("ethaddr: %s\n", hw->ethaddr);
  468. printf ("FLASH : %x nr:%d\n", hw->flash, hw->flash_nr);
  469. printf ("RAM : %x cs:%d\n", hw->ram, hw->ram_cs);
  470. printf ("CPU : %lu\n", hw->cpunr);
  471. printf ("CAN : %d\n", hw->can);
  472. if (hw->eeprom) printf ("EEprom : %x\n", hw->eeprom);
  473. else printf ("No EEprom\n");
  474. if (hw->nand) {
  475. printf ("NAND : %x\n", hw->nand);
  476. printf ("NAND CS: %d\n", hw->nand_cs);
  477. } else { printf ("No NAND\n");}
  478. printf ("Bus %s mode.\n", (hw->Bus ? "60x" : "Single PQII"));
  479. printf (" real : %s\n", (immr->im_siu_conf.sc_bcr & BCR_EBM ? \
  480. "60x" : "Single PQII"));
  481. printf ("Option : %lx\n", hw->option);
  482. printf ("%s Security Engine\n", (hw->SecEng ? "with" : "no"));
  483. printf ("CPM Clk: %d\n", hw->cpmcl);
  484. printf ("CPU Clk: %d\n", hw->cpucl);
  485. printf ("Bus Clk: %d\n", hw->buscl);
  486. if (hw->busclk_real_ok) {
  487. printf (" real Clk: %d\n", hw->busclk_real);
  488. }
  489. printf ("CAS : %d\n", get_cas_latency());
  490. } else {
  491. printf("HWIB @%x not OK\n", HWIB_INFO_START_ADDR);
  492. }
  493. return 0;
  494. }
  495. static inline int search_real_busclk (int *clk)
  496. {
  497. int part = 0, pos = 0;
  498. char *p = (char *) CIB_INFO_START_ADDR;
  499. int ok = 0;
  500. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  501. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  502. return 0;
  503. }
  504. switch (part) {
  505. default:
  506. if (*p == '-') {
  507. ++part;
  508. }
  509. break;
  510. case 3:
  511. if (*p == '-') {
  512. ++part;
  513. break;
  514. }
  515. if (*p == 'b') {
  516. ok = 1;
  517. p++;
  518. break;
  519. }
  520. if (ok) {
  521. switch (*p) {
  522. case '6':
  523. *clk = 66666666;
  524. return 1;
  525. break;
  526. case '1':
  527. if (p[1] == '3') {
  528. *clk = 133333333;
  529. } else {
  530. *clk = 100000000;
  531. }
  532. return 1;
  533. break;
  534. }
  535. }
  536. break;
  537. }
  538. p++;
  539. }
  540. return 0;
  541. }
  542. int analyse_hwib (void)
  543. {
  544. char *p = (char *) HWIB_INFO_START_ADDR;
  545. int anz;
  546. int part = 1, i = 0, pos = 0;
  547. HWIB_INFO *hw = &hwinf;
  548. deb_printf(" %s pointer: %p\n", __FUNCTION__, p);
  549. /* Head = TQM */
  550. if (*((unsigned long *)p) != (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  551. deb_printf("No HWIB\n");
  552. return -1;
  553. }
  554. p += 3;
  555. if (scanChar (p, 4, &hw->cpunr) < 0) {
  556. deb_printf("No CPU\n");
  557. return -2;
  558. }
  559. p +=4;
  560. hw->flash = 0x200000 << (*p - 'A');
  561. p++;
  562. hw->flash_nr = *p - '0';
  563. p++;
  564. hw->ram = 0x2000000 << (*p - 'A');
  565. p++;
  566. if (*p == '2') {
  567. hw->ram_cs = 2;
  568. p++;
  569. }
  570. if (*p == 'A') hw->can = 1;
  571. if (*p == 'B') hw->can = 2;
  572. p +=1;
  573. p +=1; /* connector */
  574. if (*p != '0') {
  575. hw->eeprom = 0x1000 << (*p - 'A');
  576. }
  577. p++;
  578. if ((*p < '0') || (*p > '9')) {
  579. /* NAND before z-option */
  580. hw->nand = 0x8000000 << (*p - 'A');
  581. p++;
  582. hw->nand_cs = *p - '0';
  583. p += 2;
  584. }
  585. /* z-option */
  586. anz = scanChar (p, 4, &hw->option);
  587. if (anz < 0) {
  588. deb_printf("No option\n");
  589. return -3;
  590. }
  591. if (hw->option & 0x8) hw->Bus = 1;
  592. p += anz;
  593. if (*p != '-') {
  594. deb_printf("No -\n");
  595. return -4;
  596. }
  597. p++;
  598. /* C option */
  599. if (*p == 'E') {
  600. hw->SecEng = 1;
  601. p++;
  602. }
  603. switch (*p) {
  604. case 'M': hw->cpucl = 266666666;
  605. break;
  606. case 'P': hw->cpucl = 300000000;
  607. break;
  608. case 'T': hw->cpucl = 400000000;
  609. break;
  610. default:
  611. deb_printf("No CPU Clk: %c\n", *p);
  612. return -5;
  613. break;
  614. }
  615. p++;
  616. switch (*p) {
  617. case 'I': hw->cpmcl = 200000000;
  618. break;
  619. case 'M': hw->cpmcl = 300000000;
  620. break;
  621. default:
  622. deb_printf("No CPM Clk\n");
  623. return -6;
  624. break;
  625. }
  626. p++;
  627. switch (*p) {
  628. case 'B': hw->buscl = 66666666;
  629. break;
  630. case 'E': hw->buscl = 100000000;
  631. break;
  632. case 'F': hw->buscl = 133333333;
  633. break;
  634. default:
  635. deb_printf("No BUS Clk\n");
  636. return -7;
  637. break;
  638. }
  639. p++;
  640. hw->OK = 1;
  641. /* search MAC Address */
  642. while ((*p != '\0') && (pos < CONFIG_SYS_HWINFO_SIZE)) {
  643. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  644. return 0;
  645. }
  646. switch (part) {
  647. default:
  648. if (*p == ' ') {
  649. ++part;
  650. i = 0;
  651. }
  652. break;
  653. case 3: /* Copy MAC address */
  654. if (*p == ' ') {
  655. ++part;
  656. i = 0;
  657. break;
  658. }
  659. hw->ethaddr[i++] = *p;
  660. if ((i % 3) == 2)
  661. hw->ethaddr[i++] = ':';
  662. break;
  663. }
  664. p++;
  665. }
  666. hw->busclk_real_ok = search_real_busclk (&hw->busclk_real);
  667. return 0;
  668. }
  669. #if defined(CONFIG_GET_CPU_STR_F)
  670. /* !! This routine runs from Flash */
  671. char get_cpu_str_f (char *buf)
  672. {
  673. char *p = (char *) HWIB_INFO_START_ADDR;
  674. int i = 0;
  675. buf[i++] = 'M';
  676. buf[i++] = 'P';
  677. buf[i++] = 'C';
  678. if (*((unsigned long *)p) == (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  679. buf[i++] = *&p[3];
  680. buf[i++] = *&p[4];
  681. buf[i++] = *&p[5];
  682. buf[i++] = *&p[6];
  683. } else {
  684. buf[i++] = '8';
  685. buf[i++] = '2';
  686. buf[i++] = '7';
  687. buf[i++] = 'x';
  688. }
  689. buf[i++] = 0;
  690. return 0;
  691. }
  692. #endif
  693. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  694. /* !! This routine runs from Flash */
  695. unsigned long board_get_cpu_clk_f (void)
  696. {
  697. char *p = (char *) HWIB_INFO_START_ADDR;
  698. int i = 0;
  699. if (*((unsigned long *)p) == (unsigned long)CONFIG_SYS_HWINFO_MAGIC) {
  700. if (search_real_busclk (&i))
  701. return i;
  702. }
  703. return CONFIG_8260_CLKIN;
  704. }
  705. #endif
  706. #if CONFIG_BOARD_EARLY_INIT_R
  707. static int can_test (unsigned long off)
  708. {
  709. volatile unsigned char *base = (unsigned char *) (CONFIG_SYS_CAN_BASE + off);
  710. *(base + 0x17) = 'T';
  711. *(base + 0x18) = 'Q';
  712. *(base + 0x19) = 'M';
  713. if ((*(base + 0x17) != 'T') ||
  714. (*(base + 0x18) != 'Q') ||
  715. (*(base + 0x19) != 'M')) {
  716. return 0;
  717. }
  718. return 1;
  719. }
  720. static int can_config_one (unsigned long off)
  721. {
  722. volatile unsigned char *ctrl = (unsigned char *) (CONFIG_SYS_CAN_BASE + off);
  723. volatile unsigned char *cpu_if = (unsigned char *) (CONFIG_SYS_CAN_BASE + off + 0x02);
  724. volatile unsigned char *clkout = (unsigned char *) (CONFIG_SYS_CAN_BASE + off + 0x1f);
  725. unsigned char temp;
  726. *cpu_if = 0x45;
  727. temp = *ctrl;
  728. temp |= 0x40;
  729. *ctrl = temp;
  730. *clkout = 0x20;
  731. temp = *ctrl;
  732. temp &= ~0x40;
  733. *ctrl = temp;
  734. return 0;
  735. }
  736. static int can_config (void)
  737. {
  738. int ret = 0;
  739. can_config_one (0);
  740. if (hwinf.can == 2) {
  741. can_config_one (0x100);
  742. }
  743. /* make Test if they really there */
  744. ret += can_test (0);
  745. ret += can_test (0x100);
  746. return ret;
  747. }
  748. static int init_can (void)
  749. {
  750. volatile immap_t * immr = (immap_t *)CONFIG_SYS_IMMR;
  751. volatile memctl8260_t *memctl = &immr->im_memctl;
  752. int count = 0;
  753. if ((hwinf.OK) && (hwinf.can)) {
  754. memctl->memc_or4 = CONFIG_SYS_CAN_OR;
  755. memctl->memc_br4 = CONFIG_SYS_CAN_BR;
  756. /* upm Init */
  757. upmconfig (UPMC, (uint *) upmTableFast,
  758. sizeof (upmTableFast) / sizeof (uint));
  759. memctl->memc_mcmr = (MxMR_DSx_3_CYCL |
  760. MxMR_GPL_x4DIS |
  761. MxMR_RLFx_2X |
  762. MxMR_WLFx_2X |
  763. MxMR_OP_NORM);
  764. /* can configure */
  765. count = can_config ();
  766. printf ("CAN: %d @ %x\n", count, CONFIG_SYS_CAN_BASE);
  767. if (hwinf.can != count) printf("!!! difference to HWIB\n");
  768. } else {
  769. printf ("CAN: No\n");
  770. }
  771. return 0;
  772. }
  773. int board_early_init_r(void)
  774. {
  775. analyse_hwib ();
  776. init_can ();
  777. return 0;
  778. }
  779. #endif
  780. int do_hwib_dump (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  781. {
  782. dump_hwib ();
  783. return 0;
  784. }
  785. U_BOOT_CMD(
  786. hwib, 1, 1, do_hwib_dump,
  787. "dump HWIB'",
  788. ""
  789. );
  790. #ifdef CONFIG_SYS_UPDATE_FLASH_SIZE
  791. static int get_flash_timing (void)
  792. {
  793. /* get it from the option -tf in CIB */
  794. /* default is 0x00000c84 */
  795. int ret = 0x00000c84;
  796. int pos = 0;
  797. int nr = 0;
  798. char *p = (char *) CIB_INFO_START_ADDR;
  799. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  800. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  801. return ret;
  802. }
  803. if (*p == '-') {
  804. if ((p[1] == 't') && (p[2] == 'f')) {
  805. p += 6;
  806. ret = 0;
  807. while (nr < 8) {
  808. if ((*p >= '0') && (*p <= '9')) {
  809. ret *= 0x10;
  810. ret += *p - '0';
  811. p += 1;
  812. nr ++;
  813. } else if ((*p >= 'A') && (*p <= 'F')) {
  814. ret *= 10;
  815. ret += *p - '7';
  816. p += 1;
  817. nr ++;
  818. } else {
  819. if (nr < 8) return 0x00000c84;
  820. return ret;
  821. }
  822. }
  823. }
  824. }
  825. p++;
  826. pos++;
  827. }
  828. return ret;
  829. }
  830. /* Update the Flash_Size and the Flash Timing */
  831. int update_flash_size (int flash_size)
  832. {
  833. volatile immap_t * immr = (immap_t *)CONFIG_SYS_IMMR;
  834. volatile memctl8260_t *memctl = &immr->im_memctl;
  835. unsigned long reg;
  836. unsigned long tim;
  837. /* I must use reg, otherwise the board hang */
  838. reg = memctl->memc_or0;
  839. reg &= ~ORxU_AM_MSK;
  840. reg |= MEG_TO_AM(flash_size >> 20);
  841. tim = get_flash_timing ();
  842. reg &= ~0xfff;
  843. reg |= (tim & 0xfff);
  844. memctl->memc_or0 = reg;
  845. return 0;
  846. }
  847. #endif
  848. #ifdef CONFIG_PCI
  849. struct pci_controller hose;
  850. int board_early_init_f (void)
  851. {
  852. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  853. immap->im_clkrst.car_sccr |= M826X_SCCR_PCI_MODE_EN;
  854. return 0;
  855. }
  856. extern void pci_mpc8250_init(struct pci_controller *);
  857. void pci_init_board(void)
  858. {
  859. pci_mpc8250_init(&hose);
  860. }
  861. #endif
  862. int board_eth_init(bd_t *bis)
  863. {
  864. return pci_eth_init(bis);
  865. }