tqm8272.c 35 KB

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