tsi108_init.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652
  1. /*****************************************************************************
  2. * (C) Copyright 2003; Tundra Semiconductor Corp.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. *****************************************************************************/
  6. /*----------------------------------------------------------------------------
  7. * FILENAME: tsi108_init.c
  8. *
  9. * Originator: Alex Bounine
  10. *
  11. * DESCRIPTION:
  12. * Initialization code for the Tundra Tsi108 bridge chip
  13. *---------------------------------------------------------------------------*/
  14. #include <common.h>
  15. #include <74xx_7xx.h>
  16. #include <config.h>
  17. #include <version.h>
  18. #include <asm/processor.h>
  19. #include <tsi108.h>
  20. DECLARE_GLOBAL_DATA_PTR;
  21. extern void mpicInit (int verbose);
  22. /*
  23. * Configuration Options
  24. */
  25. typedef struct {
  26. ulong upper;
  27. ulong lower;
  28. } PB2OCN_LUT_ENTRY;
  29. PB2OCN_LUT_ENTRY pb2ocn_lut1[32] = {
  30. /* 0 - 7 */
  31. {0x00000000, 0x00000201}, /* PBA=0xE000_0000 -> PCI/X (Byte-Swap) */
  32. {0x00000000, 0x00000201}, /* PBA=0xE100_0000 -> PCI/X (Byte-Swap) */
  33. {0x00000000, 0x00000201}, /* PBA=0xE200_0000 -> PCI/X (Byte-Swap) */
  34. {0x00000000, 0x00000201}, /* PBA=0xE300_0000 -> PCI/X (Byte-Swap) */
  35. {0x00000000, 0x00000201}, /* PBA=0xE400_0000 -> PCI/X (Byte-Swap) */
  36. {0x00000000, 0x00000201}, /* PBA=0xE500_0000 -> PCI/X (Byte-Swap) */
  37. {0x00000000, 0x00000201}, /* PBA=0xE600_0000 -> PCI/X (Byte-Swap) */
  38. {0x00000000, 0x00000201}, /* PBA=0xE700_0000 -> PCI/X (Byte-Swap) */
  39. /* 8 - 15 */
  40. {0x00000000, 0x00000201}, /* PBA=0xE800_0000 -> PCI/X (Byte-Swap) */
  41. {0x00000000, 0x00000201}, /* PBA=0xE900_0000 -> PCI/X (Byte-Swap) */
  42. {0x00000000, 0x00000201}, /* PBA=0xEA00_0000 -> PCI/X (Byte-Swap) */
  43. {0x00000000, 0x00000201}, /* PBA=0xEB00_0000 -> PCI/X (Byte-Swap) */
  44. {0x00000000, 0x00000201}, /* PBA=0xEC00_0000 -> PCI/X (Byte-Swap) */
  45. {0x00000000, 0x00000201}, /* PBA=0xED00_0000 -> PCI/X (Byte-Swap) */
  46. {0x00000000, 0x00000201}, /* PBA=0xEE00_0000 -> PCI/X (Byte-Swap) */
  47. {0x00000000, 0x00000201}, /* PBA=0xEF00_0000 -> PCI/X (Byte-Swap) */
  48. /* 16 - 23 */
  49. {0x00000000, 0x00000201}, /* PBA=0xF000_0000 -> PCI/X (Byte-Swap) */
  50. {0x00000000, 0x00000201}, /* PBA=0xF100_0000 -> PCI/X (Byte-Swap) */
  51. {0x00000000, 0x00000201}, /* PBA=0xF200_0000 -> PCI/X (Byte-Swap) */
  52. {0x00000000, 0x00000201}, /* PBA=0xF300_0000 -> PCI/X (Byte-Swap) */
  53. {0x00000000, 0x00000201}, /* PBA=0xF400_0000 -> PCI/X (Byte-Swap) */
  54. {0x00000000, 0x00000201}, /* PBA=0xF500_0000 -> PCI/X (Byte-Swap) */
  55. {0x00000000, 0x00000201}, /* PBA=0xF600_0000 -> PCI/X (Byte-Swap) */
  56. {0x00000000, 0x00000201}, /* PBA=0xF700_0000 -> PCI/X (Byte-Swap) */
  57. /* 24 - 31 */
  58. {0x00000000, 0x00000201}, /* PBA=0xF800_0000 -> PCI/X (Byte-Swap) */
  59. {0x00000000, 0x00000201}, /* PBA=0xF900_0000 -> PCI/X (Byte-Swap) */
  60. {0x00000000, 0x00000241}, /* PBA=0xFA00_0000 -> PCI/X PCI I/O (Byte-Swap + Translate) */
  61. {0x00000000, 0x00000201}, /* PBA=0xFB00_0000 -> PCI/X PCI Config (Byte-Swap) */
  62. {0x00000000, 0x02000240}, /* PBA=0xFC00_0000 -> HLP */
  63. {0x00000000, 0x01000240}, /* PBA=0xFD00_0000 -> HLP */
  64. {0x00000000, 0x03000240}, /* PBA=0xFE00_0000 -> HLP */
  65. {0x00000000, 0x00000240} /* PBA=0xFF00_0000 -> HLP : (Translation Enabled + Byte-Swap)*/
  66. };
  67. #ifdef CONFIG_SYS_CLK_SPREAD
  68. typedef struct {
  69. ulong ctrl0;
  70. ulong ctrl1;
  71. } PLL_CTRL_SET;
  72. /*
  73. * Clock Generator SPLL0 initialization values
  74. * PLL0 configuration table for various PB_CLKO freq.
  75. * Uses pre-calculated values for Fs = 30 kHz, D = 0.5%
  76. * Fout depends on required PB_CLKO. Based on Fref = 33 MHz
  77. */
  78. static PLL_CTRL_SET pll0_config[8] = {
  79. {0x00000000, 0x00000000}, /* 0: bypass */
  80. {0x00000000, 0x00000000}, /* 1: reserved */
  81. {0x00430044, 0x00000043}, /* 2: CG_PB_CLKO = 183 MHz */
  82. {0x005c0044, 0x00000039}, /* 3: CG_PB_CLKO = 100 MHz */
  83. {0x005c0044, 0x00000039}, /* 4: CG_PB_CLKO = 133 MHz */
  84. {0x004a0044, 0x00000040}, /* 5: CG_PB_CLKO = 167 MHz */
  85. {0x005c0044, 0x00000039}, /* 6: CG_PB_CLKO = 200 MHz */
  86. {0x004f0044, 0x0000003e} /* 7: CG_PB_CLKO = 233 MHz */
  87. };
  88. #endif /* CONFIG_SYS_CLK_SPREAD */
  89. /*
  90. * Prosessor Bus Clock (in MHz) defined by CG_PB_SELECT
  91. * (based on recommended Tsi108 reference clock 33MHz)
  92. */
  93. static int pb_clk_sel[8] = { 0, 0, 183, 100, 133, 167, 200, 233 };
  94. /*
  95. * get_board_bus_clk ()
  96. *
  97. * returns the bus clock in Hz.
  98. */
  99. unsigned long get_board_bus_clk (void)
  100. {
  101. ulong i;
  102. /* Detect PB clock freq. */
  103. i = in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PWRUP_STATUS);
  104. i = (i >> 16) & 0x07; /* Get PB PLL multiplier */
  105. return pb_clk_sel[i] * 1000000;
  106. }
  107. /*
  108. * board_early_init_f ()
  109. *
  110. * board-specific initialization executed from flash
  111. */
  112. int board_early_init_f (void)
  113. {
  114. ulong i;
  115. gd->mem_clk = 0;
  116. i = in32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET +
  117. CG_PWRUP_STATUS);
  118. i = (i >> 20) & 0x07; /* Get GD PLL multiplier */
  119. switch (i) {
  120. case 0: /* external clock */
  121. printf ("Using external clock\n");
  122. break;
  123. case 1: /* system clock */
  124. gd->mem_clk = gd->bus_clk;
  125. break;
  126. case 4: /* 133 MHz */
  127. case 5: /* 166 MHz */
  128. case 6: /* 200 MHz */
  129. gd->mem_clk = pb_clk_sel[i] * 1000000;
  130. break;
  131. default:
  132. printf ("Invalid DDR2 clock setting\n");
  133. return -1;
  134. }
  135. printf ("BUS: %lu MHz\n", get_board_bus_clk() / 1000000);
  136. printf ("MEM: %lu MHz\n", gd->mem_clk / 1000000);
  137. return 0;
  138. }
  139. /*
  140. * board_early_init_r() - Tsi108 initialization function executed right after
  141. * relocation. Contains code that cannot be executed from flash.
  142. */
  143. int board_early_init_r (void)
  144. {
  145. ulong temp, i;
  146. ulong reg_val;
  147. volatile ulong *reg_ptr;
  148. reg_ptr =
  149. (ulong *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + 0x900);
  150. for (i = 0; i < 32; i++) {
  151. *reg_ptr++ = 0x00000201; /* SWAP ENABLED */
  152. *reg_ptr++ = 0x00;
  153. }
  154. __asm__ __volatile__ ("eieio");
  155. __asm__ __volatile__ ("sync");
  156. /* Setup PB_OCN_BAR2: size 256B + ENable @ 0x0_80000000 */
  157. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + PB_OCN_BAR2,
  158. 0x80000001);
  159. __asm__ __volatile__ ("sync");
  160. /* Make sure that OCN_BAR2 decoder is set (to allow following immediate
  161. * read from SDRAM)
  162. */
  163. temp = in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + PB_OCN_BAR2);
  164. __asm__ __volatile__ ("sync");
  165. /*
  166. * Remap PB_OCN_BAR1 to accomodate PCI-bus aperture and EPROM into the
  167. * processor bus address space. Immediately after reset LUT and address
  168. * translation are disabled for this BAR. Now we have to initialize LUT
  169. * and switch from the BOOT mode to the normal operation mode.
  170. *
  171. * The aperture defined by PB_OCN_BAR1 startes at address 0xE0000000
  172. * and covers 512MB of address space. To allow larger aperture we also
  173. * have to relocate register window of Tsi108
  174. *
  175. * Initialize LUT (32-entries) prior switching PB_OCN_BAR1 from BOOT
  176. * mode.
  177. *
  178. * initialize pointer to LUT associated with PB_OCN_BAR1
  179. */
  180. reg_ptr =
  181. (ulong *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + 0x800);
  182. for (i = 0; i < 32; i++) {
  183. *reg_ptr++ = pb2ocn_lut1[i].lower;
  184. *reg_ptr++ = pb2ocn_lut1[i].upper;
  185. }
  186. __asm__ __volatile__ ("sync");
  187. /* Base addresses for CS0, CS1, CS2, CS3 */
  188. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B0_ADDR,
  189. 0x00000000);
  190. __asm__ __volatile__ ("sync");
  191. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B1_ADDR,
  192. 0x00100000);
  193. __asm__ __volatile__ ("sync");
  194. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B2_ADDR,
  195. 0x00200000);
  196. __asm__ __volatile__ ("sync");
  197. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B3_ADDR,
  198. 0x00300000);
  199. __asm__ __volatile__ ("sync");
  200. /* Masks for HLP banks */
  201. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B0_MASK,
  202. 0xFFF00000);
  203. __asm__ __volatile__ ("sync");
  204. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B1_MASK,
  205. 0xFFF00000);
  206. __asm__ __volatile__ ("sync");
  207. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B2_MASK,
  208. 0xFFF00000);
  209. __asm__ __volatile__ ("sync");
  210. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B3_MASK,
  211. 0xFFF00000);
  212. __asm__ __volatile__ ("sync");
  213. /* Set CTRL0 values for banks */
  214. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B0_CTRL0,
  215. 0x7FFC44C2);
  216. __asm__ __volatile__ ("sync");
  217. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B1_CTRL0,
  218. 0x7FFC44C0);
  219. __asm__ __volatile__ ("sync");
  220. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B2_CTRL0,
  221. 0x7FFC44C0);
  222. __asm__ __volatile__ ("sync");
  223. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B3_CTRL0,
  224. 0x7FFC44C2);
  225. __asm__ __volatile__ ("sync");
  226. /* Set banks to latched mode, enabled, and other default settings */
  227. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B0_CTRL1,
  228. 0x7C0F2000);
  229. __asm__ __volatile__ ("sync");
  230. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B1_CTRL1,
  231. 0x7C0F2000);
  232. __asm__ __volatile__ ("sync");
  233. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B2_CTRL1,
  234. 0x7C0F2000);
  235. __asm__ __volatile__ ("sync");
  236. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_HLP_REG_OFFSET + HLP_B3_CTRL1,
  237. 0x7C0F2000);
  238. __asm__ __volatile__ ("sync");
  239. /*
  240. * Set new value for PB_OCN_BAR1: switch from BOOT to LUT mode.
  241. * value for PB_OCN_BAR1: (BA-0xE000_0000 + size 512MB + ENable)
  242. */
  243. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + PB_OCN_BAR1,
  244. 0xE0000011);
  245. __asm__ __volatile__ ("sync");
  246. /* Make sure that OCN_BAR2 decoder is set (to allow following
  247. * immediate read from SDRAM)
  248. */
  249. temp = in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + PB_OCN_BAR1);
  250. __asm__ __volatile__ ("sync");
  251. /*
  252. * SRI: At this point we have enabled the HLP banks. That means we can
  253. * now read from the NVRAM and initialize the environment variables.
  254. * We will over-ride the env_init called in board_init_f
  255. * This is really a work-around because, the HLP bank 1
  256. * where NVRAM resides is not visible during board_init_f
  257. * (arch/powerpc/lib/board.c)
  258. * Alternatively, we could use the I2C EEPROM at start-up to configure
  259. * and enable all HLP banks and not just HLP 0 as is being done for
  260. * Taiga Rev. 2.
  261. */
  262. env_init ();
  263. #ifndef DISABLE_PBM
  264. /*
  265. * For IBM processors we have to set Address-Only commands generated
  266. * by PBM that are different from ones set after reset.
  267. */
  268. temp = get_cpu_type ();
  269. if ((CPU_750FX == temp) || (CPU_750GX == temp))
  270. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PB_REG_OFFSET + PB_MCMD,
  271. 0x00009955);
  272. #endif /* DISABLE_PBM */
  273. #ifdef CONFIG_PCI
  274. /*
  275. * Initialize PCI/X block
  276. */
  277. /* Map PCI/X Configuration Space (16MB @ 0x0_FE000000) */
  278. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET +
  279. PCI_PFAB_BAR0_UPPER, 0);
  280. __asm__ __volatile__ ("sync");
  281. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_PFAB_BAR0,
  282. 0xFB000001);
  283. __asm__ __volatile__ ("sync");
  284. /* Set Bus Number for the attached PCI/X bus (we will use 0 for NB) */
  285. temp = in32(CONFIG_SYS_TSI108_CSR_BASE +
  286. TSI108_PCI_REG_OFFSET + PCI_PCIX_STAT);
  287. temp &= ~0xFF00; /* Clear the BUS_NUM field */
  288. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_PCIX_STAT,
  289. temp);
  290. /* Map PCI/X IO Space (64KB @ 0x0_FD000000) takes one 16MB LUT entry */
  291. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_PFAB_IO_UPPER,
  292. 0);
  293. __asm__ __volatile__ ("sync");
  294. /* This register is on the PCI side to interpret the address it receives
  295. * and maps it as a IO address.
  296. */
  297. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_PFAB_IO,
  298. 0x00000001);
  299. __asm__ __volatile__ ("sync");
  300. /*
  301. * Map PCI/X Memory Space
  302. *
  303. * Transactions directed from OCM to PCI Memory Space are directed
  304. * from PB to PCI
  305. * unchanged (as defined by PB_OCN_BAR1,2 and LUT settings).
  306. * If address remapping is required the corresponding PCI_PFAB_MEM32
  307. * and PCI_PFAB_PFMx register groups have to be configured.
  308. *
  309. * Map the path from the PCI/X bus into the system memory
  310. *
  311. * The memory mapped window assotiated with PCI P2O_BAR2 provides
  312. * access to the system memory without address remapping.
  313. * All system memory is opened for accesses initiated by PCI/X bus
  314. * masters.
  315. *
  316. * Initialize LUT associated with PCI P2O_BAR2
  317. *
  318. * set pointer to LUT associated with PCI P2O_BAR2
  319. */
  320. reg_ptr =
  321. (ulong *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + 0x500);
  322. #ifdef DISABLE_PBM
  323. /* In case when PBM is disabled (no HW supported cache snoopng on PB)
  324. * P2O_BAR2 is directly mapped into the system memory without address
  325. * translation.
  326. */
  327. reg_val = 0x00000004; /* SDRAM port + NO Addr_Translation */
  328. for (i = 0; i < 32; i++) {
  329. *reg_ptr++ = reg_val; /* P2O_BAR2_LUTx */
  330. *reg_ptr++ = 0; /* P2O_BAR2_LUT_UPPERx */
  331. }
  332. /* value for PCI BAR2 (size = 512MB, Enabled, No Addr. Translation) */
  333. reg_val = 0x00007500;
  334. #else
  335. reg_val = 0x00000002; /* Destination port = PBM */
  336. for (i = 0; i < 32; i++) {
  337. *reg_ptr++ = reg_val; /* P2O_BAR2_LUTx */
  338. /* P2O_BAR2_LUT_UPPERx : Set data swapping mode for PBM (byte swapping) */
  339. *reg_ptr++ = 0x40000000;
  340. /* offset = 16MB, address translation is enabled to allow byte swapping */
  341. reg_val += 0x01000000;
  342. }
  343. /* value for PCI BAR2 (size = 512MB, Enabled, Address Translation Enabled) */
  344. reg_val = 0x00007100;
  345. #endif
  346. __asm__ __volatile__ ("eieio");
  347. __asm__ __volatile__ ("sync");
  348. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_PAGE_SIZES,
  349. reg_val);
  350. __asm__ __volatile__ ("sync");
  351. /* Set 64-bit PCI bus address for system memory
  352. * ( 0 is the best choice for easy mapping)
  353. */
  354. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR2,
  355. 0x00000000);
  356. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR2_UPPER,
  357. 0x00000000);
  358. __asm__ __volatile__ ("sync");
  359. #ifndef DISABLE_PBM
  360. /*
  361. * The memory mapped window assotiated with PCI P2O_BAR3 provides
  362. * access to the system memory using SDRAM OCN port and address
  363. * translation. This is alternative way to access SDRAM from PCI
  364. * required for Tsi108 emulation testing.
  365. * All system memory is opened for accesses initiated by
  366. * PCI/X bus masters.
  367. *
  368. * Initialize LUT associated with PCI P2O_BAR3
  369. *
  370. * set pointer to LUT associated with PCI P2O_BAR3
  371. */
  372. reg_ptr =
  373. (ulong *) (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + 0x600);
  374. reg_val = 0x00000004; /* Destination port = SDC */
  375. for (i = 0; i < 32; i++) {
  376. *reg_ptr++ = reg_val; /* P2O_BAR3_LUTx */
  377. /* P2O_BAR3_LUT_UPPERx : Set data swapping mode for PBM (byte swapping) */
  378. *reg_ptr++ = 0;
  379. /* offset = 16MB, address translation is enabled to allow byte swapping */
  380. reg_val += 0x01000000;
  381. }
  382. __asm__ __volatile__ ("eieio");
  383. __asm__ __volatile__ ("sync");
  384. /* Configure PCI P2O_BAR3 (size = 512MB, Enabled) */
  385. reg_val =
  386. in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET +
  387. PCI_P2O_PAGE_SIZES);
  388. reg_val &= ~0x00FF;
  389. reg_val |= 0x0071;
  390. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_PAGE_SIZES,
  391. reg_val);
  392. __asm__ __volatile__ ("sync");
  393. /* Set 64-bit base PCI bus address for window (0x20000000) */
  394. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR3_UPPER,
  395. 0x00000000);
  396. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR3,
  397. 0x20000000);
  398. __asm__ __volatile__ ("sync");
  399. #endif /* !DISABLE_PBM */
  400. #ifdef ENABLE_PCI_CSR_BAR
  401. /* open if required access to Tsi108 CSRs from the PCI/X bus */
  402. /* enable BAR0 on the PCI/X bus */
  403. reg_val = in32(CONFIG_SYS_TSI108_CSR_BASE +
  404. TSI108_PCI_REG_OFFSET + PCI_MISC_CSR);
  405. reg_val |= 0x02;
  406. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_MISC_CSR,
  407. reg_val);
  408. __asm__ __volatile__ ("sync");
  409. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR0_UPPER,
  410. 0x00000000);
  411. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_P2O_BAR0,
  412. CONFIG_SYS_TSI108_CSR_BASE);
  413. __asm__ __volatile__ ("sync");
  414. #endif
  415. /*
  416. * Finally enable PCI/X Bus Master and Memory Space access
  417. */
  418. reg_val = in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_CSR);
  419. reg_val |= 0x06;
  420. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_PCI_REG_OFFSET + PCI_CSR, reg_val);
  421. __asm__ __volatile__ ("sync");
  422. #endif /* CONFIG_PCI */
  423. /*
  424. * Initialize MPIC outputs (interrupt pins):
  425. * Interrupt routing on the Grendel Emul. Board:
  426. * PB_INT[0] -> INT (CPU0)
  427. * PB_INT[1] -> INT (CPU1)
  428. * PB_INT[2] -> MCP (CPU0)
  429. * PB_INT[3] -> MCP (CPU1)
  430. * Set interrupt controller outputs as Level_Sensitive/Active_Low
  431. */
  432. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_MPIC_REG_OFFSET + MPIC_CSR(0), 0x02);
  433. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_MPIC_REG_OFFSET + MPIC_CSR(1), 0x02);
  434. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_MPIC_REG_OFFSET + MPIC_CSR(2), 0x02);
  435. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_MPIC_REG_OFFSET + MPIC_CSR(3), 0x02);
  436. __asm__ __volatile__ ("sync");
  437. /*
  438. * Ensure that Machine Check exception is enabled
  439. * We need it to support PCI Bus probing (configuration reads)
  440. */
  441. reg_val = mfmsr ();
  442. mtmsr(reg_val | MSR_ME);
  443. return 0;
  444. }
  445. /*
  446. * Needed to print out L2 cache info
  447. * used in the misc_init_r function
  448. */
  449. unsigned long get_l2cr (void)
  450. {
  451. unsigned long l2controlreg;
  452. asm volatile ("mfspr %0, 1017":"=r" (l2controlreg):);
  453. return l2controlreg;
  454. }
  455. /*
  456. * misc_init_r()
  457. *
  458. * various things to do after relocation
  459. *
  460. */
  461. int misc_init_r (void)
  462. {
  463. #ifdef CONFIG_SYS_CLK_SPREAD /* Initialize Spread-Spectrum Clock generation */
  464. ulong i;
  465. /* Ensure that Spread-Spectrum is disabled */
  466. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PLL0_CTRL0, 0);
  467. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PLL1_CTRL0, 0);
  468. /* Initialize PLL1: CG_PCI_CLK , internal OCN_CLK
  469. * Uses pre-calculated value for Fout = 800 MHz, Fs = 30 kHz, D = 0.5%
  470. */
  471. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PLL1_CTRL0,
  472. 0x002e0044); /* D = 0.25% */
  473. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PLL1_CTRL1,
  474. 0x00000039); /* BWADJ */
  475. /* Initialize PLL0: CG_PB_CLKO */
  476. /* Detect PB clock freq. */
  477. i = in32(CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PWRUP_STATUS);
  478. i = (i >> 16) & 0x07; /* Get PB PLL multiplier */
  479. out32 (CONFIG_SYS_TSI108_CSR_BASE +
  480. TSI108_CLK_REG_OFFSET + CG_PLL0_CTRL0, pll0_config[i].ctrl0);
  481. out32 (CONFIG_SYS_TSI108_CSR_BASE +
  482. TSI108_CLK_REG_OFFSET + CG_PLL0_CTRL1, pll0_config[i].ctrl1);
  483. /* Wait and set SSEN for both PLL0 and 1 */
  484. udelay (1000);
  485. out32 (CONFIG_SYS_TSI108_CSR_BASE + TSI108_CLK_REG_OFFSET + CG_PLL1_CTRL0,
  486. 0x802e0044); /* D=0.25% */
  487. out32 (CONFIG_SYS_TSI108_CSR_BASE +
  488. TSI108_CLK_REG_OFFSET + CG_PLL0_CTRL0,
  489. 0x80000000 | pll0_config[i].ctrl0);
  490. #endif /* CONFIG_SYS_CLK_SPREAD */
  491. #ifdef CONFIG_SYS_L2
  492. l2cache_enable ();
  493. #endif
  494. printf ("BUS: %lu MHz\n", gd->bus_clk / 1000000);
  495. printf ("MEM: %lu MHz\n", gd->mem_clk / 1000000);
  496. /*
  497. * All the information needed to print the cache details is avaiblable
  498. * at this point i.e. above call to l2cache_enable is the very last
  499. * thing done with regards to enabling diabling the cache.
  500. * So this seems like a good place to print all this information
  501. */
  502. printf ("CACHE: ");
  503. switch (get_cpu_type()) {
  504. case CPU_7447A:
  505. printf ("L1 Instruction cache - 32KB 8-way");
  506. (get_hid0 () & (1 << 15)) ? printf (" ENABLED\n") :
  507. printf (" DISABLED\n");
  508. printf ("L1 Data cache - 32KB 8-way");
  509. (get_hid0 () & (1 << 14)) ? printf (" ENABLED\n") :
  510. printf (" DISABLED\n");
  511. printf ("Unified L2 cache - 512KB 8-way");
  512. (get_l2cr () & (1 << 31)) ? printf (" ENABLED\n") :
  513. printf (" DISABLED\n");
  514. printf ("\n");
  515. break;
  516. case CPU_7448:
  517. printf ("L1 Instruction cache - 32KB 8-way");
  518. (get_hid0 () & (1 << 15)) ? printf (" ENABLED\n") :
  519. printf (" DISABLED\n");
  520. printf ("L1 Data cache - 32KB 8-way");
  521. (get_hid0 () & (1 << 14)) ? printf (" ENABLED\n") :
  522. printf (" DISABLED\n");
  523. printf ("Unified L2 cache - 1MB 8-way");
  524. (get_l2cr () & (1 << 31)) ? printf (" ENABLED\n") :
  525. printf (" DISABLED\n");
  526. break;
  527. default:
  528. break;
  529. }
  530. return 0;
  531. }