tqm8272.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234
  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. if ((*p >= '0') && (*p <= '9')) {
  531. *number *= 10;
  532. *number += *p - '0';
  533. p += 1;
  534. } else {
  535. if (*p == '-') return akt;
  536. return -1;
  537. }
  538. akt ++;
  539. }
  540. return akt;
  541. }
  542. typedef struct{
  543. int Bus;
  544. int flash;
  545. int flash_nr;
  546. int ram;
  547. int ram_cs;
  548. int nand;
  549. int nand_cs;
  550. int eeprom;
  551. int can;
  552. unsigned long cpunr;
  553. unsigned long option;
  554. int SecEng;
  555. int cpucl;
  556. int cpmcl;
  557. int buscl;
  558. int busclk_real_ok;
  559. int busclk_real;
  560. unsigned char OK;
  561. unsigned char ethaddr[20];
  562. } HWIB_INFO;
  563. HWIB_INFO hwinf = {0, 0, 1, 0, 1, 0, 0, 0, 0, 8272, 0 ,0,
  564. 0, 0, 0, 0, 0, 0};
  565. static int dump_hwib(void)
  566. {
  567. HWIB_INFO *hw = &hwinf;
  568. volatile immap_t *immr = (immap_t *)CFG_IMMR;
  569. char *s = getenv("serial#");
  570. if (hw->OK) {
  571. printf ("HWIB on %x\n", HWIB_INFO_START_ADDR);
  572. printf ("serial : %s\n", s);
  573. printf ("ethaddr: %s\n", hw->ethaddr);
  574. printf ("FLASH : %x nr:%d\n", hw->flash, hw->flash_nr);
  575. printf ("RAM : %x cs:%d\n", hw->ram, hw->ram_cs);
  576. printf ("CPU : %d\n", hw->cpunr);
  577. printf ("CAN : %d\n", hw->can);
  578. if (hw->eeprom) printf ("EEprom : %x\n", hw->eeprom);
  579. else printf ("No EEprom\n");
  580. if (hw->nand) {
  581. printf ("NAND : %x\n", hw->nand);
  582. printf ("NAND CS: %d\n", hw->nand_cs);
  583. } else { printf ("No NAND\n");}
  584. printf ("Bus %s mode.\n", (hw->Bus ? "60x" : "Single PQII"));
  585. printf (" real : %s\n", (immr->im_siu_conf.sc_bcr & BCR_EBM ? \
  586. "60x" : "Single PQII"));
  587. printf ("Option : %x\n", hw->option);
  588. printf ("%s Security Engine\n", (hw->SecEng ? "with" : "no"));
  589. printf ("CPM Clk: %d\n", hw->cpmcl);
  590. printf ("CPU Clk: %d\n", hw->cpucl);
  591. printf ("Bus Clk: %d\n", hw->buscl);
  592. if (hw->busclk_real_ok) {
  593. printf (" real Clk: %d\n", hw->busclk_real);
  594. }
  595. printf ("CAS : %d\n", get_cas_latency());
  596. } else {
  597. printf("HWIB @%x not OK\n", HWIB_INFO_START_ADDR);
  598. }
  599. return 0;
  600. }
  601. static inline int search_real_busclk (int *clk)
  602. {
  603. int part = 0, pos = 0;
  604. char *p = (char *) CIB_INFO_START_ADDR;
  605. int ok = 0;
  606. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  607. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  608. return 0;
  609. }
  610. switch (part) {
  611. default:
  612. if (*p == '-') {
  613. ++part;
  614. }
  615. break;
  616. case 3:
  617. if (*p == '-') {
  618. ++part;
  619. break;
  620. }
  621. if (*p == 'b') {
  622. ok = 1;
  623. p++;
  624. break;
  625. }
  626. if (ok) {
  627. switch (*p) {
  628. case '6':
  629. *clk = 66666666;
  630. return 1;
  631. break;
  632. case '1':
  633. if (p[1] == '3') {
  634. *clk = 133333333;
  635. } else {
  636. *clk = 100000000;
  637. }
  638. return 1;
  639. break;
  640. }
  641. }
  642. break;
  643. }
  644. p++;
  645. }
  646. return 0;
  647. }
  648. int analyse_hwib (void)
  649. {
  650. char *p = (char *) HWIB_INFO_START_ADDR;
  651. int anz;
  652. int part = 1, i = 0, pos = 0;
  653. HWIB_INFO *hw = &hwinf;
  654. deb_printf(" %s pointer: %p\n", __FUNCTION__, p);
  655. /* Head = TQM */
  656. if (*((unsigned long *)p) != (unsigned long)CFG_HWINFO_MAGIC) {
  657. deb_printf("No HWIB\n");
  658. return -1;
  659. }
  660. p += 3;
  661. if (scanChar (p, 4, &hw->cpunr) < 0) {
  662. deb_printf("No CPU\n");
  663. return -2;
  664. }
  665. p +=4;
  666. hw->flash = 0x200000 << (*p - 'A');
  667. p++;
  668. hw->flash_nr = *p - '0';
  669. p++;
  670. hw->ram = 0x2000000 << (*p - 'A');
  671. p++;
  672. if (*p == '2') {
  673. hw->ram_cs = 2;
  674. p++;
  675. }
  676. if (*p == 'A') hw->can = 1;
  677. if (*p == 'B') hw->can = 2;
  678. p +=1;
  679. p +=1; /* connector */
  680. if (*p != '0') {
  681. hw->eeprom = 0x100 << (*p - 'A');
  682. }
  683. p++;
  684. if ((*p < '0') || (*p > '9')) {
  685. /* NAND before z-option */
  686. hw->nand = 0x8000000 << (*p - 'A');
  687. p++;
  688. hw->nand_cs = *p - '0';
  689. p += 2;
  690. }
  691. /* z-option */
  692. anz = scanChar (p, 4, &hw->option);
  693. if (anz < 0) {
  694. deb_printf("No option\n");
  695. return -3;
  696. }
  697. if (hw->option & 0x8) hw->Bus = 1;
  698. p += anz;
  699. if (*p != '-') {
  700. deb_printf("No -\n");
  701. return -4;
  702. }
  703. p++;
  704. /* C option */
  705. if (*p == 'E') {
  706. hw->SecEng = 1;
  707. p++;
  708. }
  709. switch (*p) {
  710. case 'M': hw->cpucl = 266666666;
  711. break;
  712. case 'P': hw->cpucl = 300000000;
  713. break;
  714. case 'T': hw->cpucl = 400000000;
  715. break;
  716. default:
  717. deb_printf("No CPU Clk: %c\n", *p);
  718. return -5;
  719. break;
  720. }
  721. p++;
  722. switch (*p) {
  723. case 'I': hw->cpmcl = 200000000;
  724. break;
  725. case 'M': hw->cpmcl = 300000000;
  726. break;
  727. default:
  728. deb_printf("No CPM Clk\n");
  729. return -6;
  730. break;
  731. }
  732. p++;
  733. switch (*p) {
  734. case 'B': hw->buscl = 66666666;
  735. break;
  736. case 'E': hw->buscl = 100000000;
  737. break;
  738. case 'F': hw->buscl = 133333333;
  739. break;
  740. default:
  741. deb_printf("No BUS Clk\n");
  742. return -7;
  743. break;
  744. }
  745. p++;
  746. hw->OK = 1;
  747. /* search MAC Address */
  748. while ((*p != '\0') && (pos < CFG_HWINFO_SIZE)) {
  749. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  750. return 0;
  751. }
  752. switch (part) {
  753. default:
  754. if (*p == ' ') {
  755. ++part;
  756. i = 0;
  757. }
  758. break;
  759. case 3: /* Copy MAC address */
  760. if (*p == ' ') {
  761. ++part;
  762. i = 0;
  763. break;
  764. }
  765. hw->ethaddr[i++] = *p;
  766. if ((i % 3) == 2)
  767. hw->ethaddr[i++] = ':';
  768. break;
  769. }
  770. p++;
  771. }
  772. hw->busclk_real_ok = search_real_busclk (&hw->busclk_real);
  773. return 0;
  774. }
  775. #if defined(CONFIG_GET_CPU_STR_F)
  776. /* !! This routine runs from Flash */
  777. char get_cpu_str_f (char *buf)
  778. {
  779. char *p = (char *) HWIB_INFO_START_ADDR;
  780. int i = 0;
  781. buf[i++] = 'M';
  782. buf[i++] = 'P';
  783. buf[i++] = 'C';
  784. if (*((unsigned long *)p) == (unsigned long)CFG_HWINFO_MAGIC) {
  785. buf[i++] = *&p[3];
  786. buf[i++] = *&p[4];
  787. buf[i++] = *&p[5];
  788. buf[i++] = *&p[6];
  789. } else {
  790. buf[i++] = '8';
  791. buf[i++] = '2';
  792. buf[i++] = '7';
  793. buf[i++] = 'x';
  794. }
  795. buf[i++] = 0;
  796. return 0;
  797. }
  798. #endif
  799. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  800. /* !! This routine runs from Flash */
  801. unsigned long board_get_cpu_clk_f (void)
  802. {
  803. char *p = (char *) HWIB_INFO_START_ADDR;
  804. int i = 0;
  805. if (*((unsigned long *)p) == (unsigned long)CFG_HWINFO_MAGIC) {
  806. if (search_real_busclk (&i))
  807. return i;
  808. }
  809. return CONFIG_8260_CLKIN;
  810. }
  811. #endif
  812. #if CONFIG_BOARD_EARLY_INIT_R
  813. static int can_test (unsigned long off)
  814. {
  815. volatile unsigned char *base = (unsigned char *) (CFG_CAN_BASE + off);
  816. *(base + 0x17) = 'T';
  817. *(base + 0x18) = 'Q';
  818. *(base + 0x19) = 'M';
  819. if ((*(base + 0x17) != 'T') ||
  820. (*(base + 0x18) != 'Q') ||
  821. (*(base + 0x19) != 'M')) {
  822. return 0;
  823. }
  824. return 1;
  825. }
  826. static int can_config_one (unsigned long off)
  827. {
  828. volatile unsigned char *ctrl = (unsigned char *) (CFG_CAN_BASE + off);
  829. volatile unsigned char *cpu_if = (unsigned char *) (CFG_CAN_BASE + off + 0x02);
  830. volatile unsigned char *clkout = (unsigned char *) (CFG_CAN_BASE + off + 0x1f);
  831. unsigned char temp;
  832. *cpu_if = 0x45;
  833. temp = *ctrl;
  834. temp |= 0x40;
  835. *ctrl = temp;
  836. *clkout = 0x20;
  837. temp = *ctrl;
  838. temp &= ~0x40;
  839. *ctrl = temp;
  840. return 0;
  841. }
  842. static int can_config (void)
  843. {
  844. int ret = 0;
  845. can_config_one (0);
  846. if (hwinf.can == 2) {
  847. can_config_one (0x100);
  848. }
  849. /* make Test if they really there */
  850. ret += can_test (0);
  851. ret += can_test (0x100);
  852. return ret;
  853. }
  854. static int init_can (void)
  855. {
  856. volatile immap_t * immr = (immap_t *)CFG_IMMR;
  857. volatile memctl8260_t *memctl = &immr->im_memctl;
  858. int count = 0;
  859. if ((hwinf.OK) && (hwinf.can)) {
  860. memctl->memc_or4 = CFG_CAN_OR;
  861. memctl->memc_br4 = CFG_CAN_BR;
  862. /* upm Init */
  863. upmconfig (UPMC, (uint *) upmTableFast,
  864. sizeof (upmTableFast) / sizeof (uint));
  865. memctl->memc_mcmr = (MxMR_DSx_3_CYCL |
  866. MxMR_GPL_x4DIS |
  867. MxMR_RLFx_2X |
  868. MxMR_WLFx_2X |
  869. MxMR_OP_NORM);
  870. /* can configure */
  871. count = can_config ();
  872. printf ("CAN: %d @ %x\n", count, CFG_CAN_BASE);
  873. if (hwinf.can != count) printf("!!! difference to HWIB\n");
  874. } else {
  875. printf ("CAN: No\n");
  876. }
  877. return 0;
  878. }
  879. int board_early_init_r(void)
  880. {
  881. analyse_hwib ();
  882. init_can ();
  883. return 0;
  884. }
  885. #endif
  886. int do_hwib_dump (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
  887. {
  888. dump_hwib ();
  889. return 0;
  890. }
  891. U_BOOT_CMD(
  892. hwib, 1, 1, do_hwib_dump,
  893. "hwib - dump HWIB'\n",
  894. "\n"
  895. );
  896. #ifdef CFG_UPDATE_FLASH_SIZE
  897. static int get_flash_timing (void)
  898. {
  899. /* get it from the option -tf in CIB */
  900. /* default is 0x00000c84 */
  901. int ret = 0x00000c84;
  902. int pos = 0;
  903. int nr = 0;
  904. char *p = (char *) CIB_INFO_START_ADDR;
  905. while ((*p != '\0') && (pos < CIB_INFO_LEN)) {
  906. if (*p < ' ' || *p > '~') { /* ASCII strings! */
  907. return ret;
  908. }
  909. if (*p == '-') {
  910. if ((p[1] == 't') && (p[2] == 'f')) {
  911. p += 6;
  912. ret = 0;
  913. while (nr < 8) {
  914. if ((*p >= '0') && (*p <= '9')) {
  915. ret *= 0x10;
  916. ret += *p - '0';
  917. p += 1;
  918. nr ++;
  919. } else if ((*p >= 'A') && (*p <= 'F')) {
  920. ret *= 10;
  921. ret += *p - '7';
  922. p += 1;
  923. nr ++;
  924. } else {
  925. if (nr < 8) return 0x00000c84;
  926. return ret;
  927. }
  928. }
  929. }
  930. }
  931. p++;
  932. pos++;
  933. }
  934. return ret;
  935. }
  936. /* Update the Flash_Size and the Flash Timing */
  937. int update_flash_size (int flash_size)
  938. {
  939. volatile immap_t * immr = (immap_t *)CFG_IMMR;
  940. volatile memctl8260_t *memctl = &immr->im_memctl;
  941. unsigned long reg;
  942. unsigned long tim;
  943. /* I must use reg, otherwise the board hang */
  944. reg = memctl->memc_or0;
  945. reg &= ~ORxU_AM_MSK;
  946. reg |= MEG_TO_AM(flash_size >> 20);
  947. tim = get_flash_timing ();
  948. reg &= ~0xfff;
  949. reg |= (tim & 0xfff);
  950. memctl->memc_or0 = reg;
  951. return 0;
  952. }
  953. #endif
  954. #if (CONFIG_COMMANDS & CFG_CMD_NAND)
  955. #include <nand.h>
  956. #include <linux/mtd/mtd.h>
  957. static u8 hwctl = 0;
  958. static void upmnand_hwcontrol(struct mtd_info *mtdinfo, int cmd)
  959. {
  960. switch (cmd) {
  961. case NAND_CTL_SETCLE:
  962. hwctl |= 0x1;
  963. break;
  964. case NAND_CTL_CLRCLE:
  965. hwctl &= ~0x1;
  966. break;
  967. case NAND_CTL_SETALE:
  968. hwctl |= 0x2;
  969. break;
  970. case NAND_CTL_CLRALE:
  971. hwctl &= ~0x2;
  972. break;
  973. }
  974. }
  975. static void upmnand_write_byte(struct mtd_info *mtdinfo, u_char byte)
  976. {
  977. struct nand_chip *this = mtdinfo->priv;
  978. ulong base = (ulong) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
  979. if (hwctl & 0x1) {
  980. WRITE_NAND_UPM(byte, base, CFG_NAND_UPM_WRITE_CMD_OFS);
  981. } else if (hwctl & 0x2) {
  982. WRITE_NAND_UPM(byte, base, CFG_NAND_UPM_WRITE_ADDR_OFS);
  983. } else {
  984. WRITE_NAND(byte, base);
  985. }
  986. }
  987. static u_char upmnand_read_byte(struct mtd_info *mtdinfo)
  988. {
  989. struct nand_chip *this = mtdinfo->priv;
  990. ulong base = (ulong) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
  991. return READ_NAND(base);
  992. }
  993. static int tqm8272_dev_ready(struct mtd_info *mtdinfo)
  994. {
  995. /* constant delay (see also tR in the datasheet) */
  996. udelay(12); \
  997. return 1;
  998. }
  999. #ifndef CONFIG_NAND_SPL
  1000. static void tqm8272_read_buf(struct mtd_info *mtdinfo, uint8_t *buf, int len)
  1001. {
  1002. struct nand_chip *this = mtdinfo->priv;
  1003. unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
  1004. int i;
  1005. for (i = 0; i< len; i++)
  1006. buf[i] = *base;
  1007. }
  1008. static void tqm8272_write_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
  1009. {
  1010. struct nand_chip *this = mtdinfo->priv;
  1011. unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
  1012. int i;
  1013. for (i = 0; i< len; i++)
  1014. *base = buf[i];
  1015. }
  1016. static int tqm8272_verify_buf(struct mtd_info *mtdinfo, const uint8_t *buf, int len)
  1017. {
  1018. struct nand_chip *this = mtdinfo->priv;
  1019. unsigned char *base = (unsigned char *) (this->IO_ADDR_W + chipsel * CFG_NAND_CS_DIST);
  1020. int i;
  1021. for (i = 0; i < len; i++)
  1022. if (buf[i] != *base)
  1023. return -1;
  1024. return 0;
  1025. }
  1026. #endif /* #ifndef CONFIG_NAND_SPL */
  1027. void board_nand_select_device(struct nand_chip *nand, int chip)
  1028. {
  1029. chipsel = chip;
  1030. }
  1031. int board_nand_init(struct nand_chip *nand)
  1032. {
  1033. static int UpmInit = 0;
  1034. volatile immap_t * immr = (immap_t *)CFG_IMMR;
  1035. volatile memctl8260_t *memctl = &immr->im_memctl;
  1036. if (hwinf.nand == 0) return -1;
  1037. /* Setup the UPM */
  1038. if (UpmInit == 0) {
  1039. switch (hwinf.busclk_real) {
  1040. case 100000000:
  1041. upmconfig (UPMB, (uint *) upmTable100,
  1042. sizeof (upmTable100) / sizeof (uint));
  1043. break;
  1044. case 133333333:
  1045. upmconfig (UPMB, (uint *) upmTable133,
  1046. sizeof (upmTable133) / sizeof (uint));
  1047. break;
  1048. default:
  1049. upmconfig (UPMB, (uint *) upmTable67,
  1050. sizeof (upmTable67) / sizeof (uint));
  1051. break;
  1052. }
  1053. UpmInit = 1;
  1054. }
  1055. /* Setup the memctrl */
  1056. memctl->memc_or3 = CFG_NAND_OR;
  1057. memctl->memc_br3 = CFG_NAND_BR;
  1058. memctl->memc_mbmr = (MxMR_OP_NORM);
  1059. nand->eccmode = NAND_ECC_SOFT;
  1060. nand->hwcontrol = upmnand_hwcontrol;
  1061. nand->read_byte = upmnand_read_byte;
  1062. nand->write_byte = upmnand_write_byte;
  1063. nand->dev_ready = tqm8272_dev_ready;
  1064. #ifndef CONFIG_NAND_SPL
  1065. nand->write_buf = tqm8272_write_buf;
  1066. nand->read_buf = tqm8272_read_buf;
  1067. nand->verify_buf = tqm8272_verify_buf;
  1068. #endif
  1069. /*
  1070. * Select required NAND chip
  1071. */
  1072. board_nand_select_device(nand, 0);
  1073. return 0;
  1074. }
  1075. #endif /* CFG_CMD_NAND */
  1076. #ifdef CONFIG_PCI
  1077. struct pci_controller hose;
  1078. int board_early_init_f (void)
  1079. {
  1080. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  1081. immap->im_clkrst.car_sccr |= M826X_SCCR_PCI_MODE_EN;
  1082. return 0;
  1083. }
  1084. extern void pci_mpc8250_init(struct pci_controller *);
  1085. void pci_init_board(void)
  1086. {
  1087. pci_mpc8250_init(&hose);
  1088. }
  1089. #endif