tqm8272.c 35 KB

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