p2041rdb.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. /*
  2. * Copyright 2011,2012 Freescale Semiconductor, Inc.
  3. *
  4. * See file CREDITS for list of people who contributed to this
  5. * project.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License as
  9. * published by the Free Software Foundation; either version 2 of
  10. * the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  20. * MA 02111-1307 USA
  21. */
  22. #include <common.h>
  23. #include <command.h>
  24. #include <netdev.h>
  25. #include <linux/compiler.h>
  26. #include <asm/mmu.h>
  27. #include <asm/processor.h>
  28. #include <asm/cache.h>
  29. #include <asm/immap_85xx.h>
  30. #include <asm/fsl_law.h>
  31. #include <asm/fsl_serdes.h>
  32. #include <asm/fsl_portals.h>
  33. #include <asm/fsl_liodn.h>
  34. #include <fm_eth.h>
  35. extern void pci_of_setup(void *blob, bd_t *bd);
  36. #include "cpld.h"
  37. DECLARE_GLOBAL_DATA_PTR;
  38. int checkboard(void)
  39. {
  40. u8 sw;
  41. struct cpu_type *cpu = gd->arch.cpu;
  42. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  43. unsigned int i;
  44. printf("Board: %sRDB, ", cpu->name);
  45. printf("CPLD version: %d.%d ", CPLD_READ(cpld_ver),
  46. CPLD_READ(cpld_ver_sub));
  47. sw = CPLD_READ(fbank_sel);
  48. printf("vBank: %d\n", sw & 0x1);
  49. /*
  50. * Display the RCW, so that no one gets confused as to what RCW
  51. * we're actually using for this boot.
  52. */
  53. puts("Reset Configuration Word (RCW):");
  54. for (i = 0; i < ARRAY_SIZE(gur->rcwsr); i++) {
  55. u32 rcw = in_be32(&gur->rcwsr[i]);
  56. if ((i % 4) == 0)
  57. printf("\n %08x:", i * 4);
  58. printf(" %08x", rcw);
  59. }
  60. puts("\n");
  61. /*
  62. * Display the actual SERDES reference clocks as configured by the
  63. * dip switches on the board. Note that the SWx registers could
  64. * technically be set to force the reference clocks to match the
  65. * values that the SERDES expects (or vice versa). For now, however,
  66. * we just display both values and hope the user notices when they
  67. * don't match.
  68. */
  69. puts("SERDES Reference Clocks: ");
  70. sw = in_8(&CPLD_SW(2)) >> 2;
  71. for (i = 0; i < 2; i++) {
  72. static const char * const freq[][3] = {{"0", "100", "125"},
  73. {"100", "156.25", "125"}
  74. };
  75. unsigned int clock = (sw >> (2 * i)) & 3;
  76. printf("Bank%u=%sMhz ", i+1, freq[i][clock]);
  77. }
  78. puts("\n");
  79. return 0;
  80. }
  81. int board_early_init_f(void)
  82. {
  83. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  84. /* board only uses the DDR_MCK0/1, so disable the DDR_MCK2/3 */
  85. setbits_be32(&gur->ddrclkdr, 0x000f000f);
  86. return 0;
  87. }
  88. #define CPLD_LANE_A_SEL 0x1
  89. #define CPLD_LANE_G_SEL 0x2
  90. #define CPLD_LANE_C_SEL 0x4
  91. #define CPLD_LANE_D_SEL 0x8
  92. void board_config_lanes_mux(void)
  93. {
  94. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  95. int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
  96. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  97. u8 mux = 0;
  98. switch (srds_prtcl) {
  99. case 0x2:
  100. case 0x5:
  101. case 0x9:
  102. case 0xa:
  103. case 0xf:
  104. break;
  105. case 0x8:
  106. mux |= CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
  107. break;
  108. case 0x14:
  109. mux |= CPLD_LANE_A_SEL;
  110. break;
  111. case 0x17:
  112. mux |= CPLD_LANE_G_SEL;
  113. break;
  114. case 0x16:
  115. case 0x19:
  116. case 0x1a:
  117. mux |= CPLD_LANE_G_SEL | CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
  118. break;
  119. case 0x1c:
  120. mux |= CPLD_LANE_G_SEL | CPLD_LANE_A_SEL;
  121. break;
  122. default:
  123. printf("Fman:Unsupported SerDes Protocol 0x%02x\n", srds_prtcl);
  124. break;
  125. }
  126. CPLD_WRITE(serdes_mux, mux);
  127. }
  128. int board_early_init_r(void)
  129. {
  130. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  131. const u8 flash_esel = find_tlb_idx((void *)flashbase, 1);
  132. /*
  133. * Remap Boot flash + PROMJET region to caching-inhibited
  134. * so that flash can be erased properly.
  135. */
  136. /* Flush d-cache and invalidate i-cache of any FLASH data */
  137. flush_dcache();
  138. invalidate_icache();
  139. /* invalidate existing TLB entry for flash + promjet */
  140. disable_tlb(flash_esel);
  141. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  142. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  143. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  144. set_liodns();
  145. setup_portals();
  146. board_config_lanes_mux();
  147. return 0;
  148. }
  149. unsigned long get_board_sys_clk(unsigned long dummy)
  150. {
  151. u8 sysclk_conf = CPLD_READ(sysclk_sw1);
  152. switch (sysclk_conf & 0x7) {
  153. case CPLD_SYSCLK_83:
  154. return 83333333;
  155. case CPLD_SYSCLK_100:
  156. return 100000000;
  157. default:
  158. return 66666666;
  159. }
  160. }
  161. static const char *serdes_clock_to_string(u32 clock)
  162. {
  163. switch (clock) {
  164. case SRDS_PLLCR0_RFCK_SEL_100:
  165. return "100";
  166. case SRDS_PLLCR0_RFCK_SEL_125:
  167. return "125";
  168. case SRDS_PLLCR0_RFCK_SEL_156_25:
  169. return "156.25";
  170. default:
  171. return "150";
  172. }
  173. }
  174. #define NUM_SRDS_BANKS 2
  175. int misc_init_r(void)
  176. {
  177. serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  178. u32 actual[NUM_SRDS_BANKS];
  179. unsigned int i;
  180. u8 sw;
  181. static const int freq[][3] = {
  182. {0, SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_125},
  183. {SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_156_25,
  184. SRDS_PLLCR0_RFCK_SEL_125}
  185. };
  186. sw = in_8(&CPLD_SW(2)) >> 2;
  187. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  188. unsigned int clock = (sw >> (2 * i)) & 3;
  189. if (clock == 0x3) {
  190. printf("Warning: SDREFCLK%u switch setting of '11' is "
  191. "unsupported\n", i + 1);
  192. break;
  193. }
  194. if (i == 0 && clock == 0)
  195. puts("Warning: SDREFCLK1 switch setting of"
  196. "'00' is unsupported\n");
  197. else
  198. actual[i] = freq[i][clock];
  199. /*
  200. * PC board uses a different CPLD with PB board, this CPLD
  201. * has cpld_ver_sub = 1, and pcba_ver = 5. But CPLD on PB
  202. * board has cpld_ver_sub = 0, and pcba_ver = 4.
  203. */
  204. if ((i == 1) && (CPLD_READ(cpld_ver_sub) == 1) &&
  205. (CPLD_READ(pcba_ver) == 5)) {
  206. /* PC board bank2 frequency */
  207. actual[i] = freq[i-1][clock];
  208. }
  209. }
  210. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  211. u32 expected = in_be32(&regs->bank[i].pllcr0);
  212. expected &= SRDS_PLLCR0_RFCK_SEL_MASK;
  213. if (expected != actual[i]) {
  214. printf("Warning: SERDES bank %u expects reference clock"
  215. " %sMHz, but actual is %sMHz\n", i + 1,
  216. serdes_clock_to_string(expected),
  217. serdes_clock_to_string(actual[i]));
  218. }
  219. }
  220. return 0;
  221. }
  222. void ft_board_setup(void *blob, bd_t *bd)
  223. {
  224. phys_addr_t base;
  225. phys_size_t size;
  226. ft_cpu_setup(blob, bd);
  227. base = getenv_bootm_low();
  228. size = getenv_bootm_size();
  229. fdt_fixup_memory(blob, (u64)base, (u64)size);
  230. #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
  231. fdt_fixup_dr_usb(blob, bd);
  232. #endif
  233. #ifdef CONFIG_PCI
  234. pci_of_setup(blob, bd);
  235. #endif
  236. fdt_fixup_liodn(blob);
  237. #ifdef CONFIG_SYS_DPAA_FMAN
  238. fdt_fixup_fman_ethernet(blob);
  239. #endif
  240. }