tqm8272.c 36 KB

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