p2041rdb.c 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /*
  2. * Copyright 2011,2012 Freescale Semiconductor, Inc.
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <command.h>
  8. #include <netdev.h>
  9. #include <linux/compiler.h>
  10. #include <asm/mmu.h>
  11. #include <asm/processor.h>
  12. #include <asm/cache.h>
  13. #include <asm/immap_85xx.h>
  14. #include <asm/fsl_law.h>
  15. #include <asm/fsl_serdes.h>
  16. #include <asm/fsl_liodn.h>
  17. #include <fm_eth.h>
  18. extern void pci_of_setup(void *blob, bd_t *bd);
  19. #include "cpld.h"
  20. DECLARE_GLOBAL_DATA_PTR;
  21. int checkboard(void)
  22. {
  23. u8 sw;
  24. struct cpu_type *cpu = gd->arch.cpu;
  25. unsigned int i;
  26. printf("Board: %sRDB, ", cpu->name);
  27. printf("CPLD version: %d.%d ", CPLD_READ(cpld_ver),
  28. CPLD_READ(cpld_ver_sub));
  29. sw = CPLD_READ(fbank_sel);
  30. printf("vBank: %d\n", sw & 0x1);
  31. /*
  32. * Display the actual SERDES reference clocks as configured by the
  33. * dip switches on the board. Note that the SWx registers could
  34. * technically be set to force the reference clocks to match the
  35. * values that the SERDES expects (or vice versa). For now, however,
  36. * we just display both values and hope the user notices when they
  37. * don't match.
  38. */
  39. puts("SERDES Reference Clocks: ");
  40. sw = in_8(&CPLD_SW(2)) >> 2;
  41. for (i = 0; i < 2; i++) {
  42. static const char * const freq[][3] = {{"0", "100", "125"},
  43. {"100", "156.25", "125"}
  44. };
  45. unsigned int clock = (sw >> (2 * i)) & 3;
  46. printf("Bank%u=%sMhz ", i+1, freq[i][clock]);
  47. }
  48. puts("\n");
  49. return 0;
  50. }
  51. int board_early_init_f(void)
  52. {
  53. ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  54. /* board only uses the DDR_MCK0/1, so disable the DDR_MCK2/3 */
  55. setbits_be32(&gur->ddrclkdr, 0x000f000f);
  56. return 0;
  57. }
  58. #define CPLD_LANE_A_SEL 0x1
  59. #define CPLD_LANE_G_SEL 0x2
  60. #define CPLD_LANE_C_SEL 0x4
  61. #define CPLD_LANE_D_SEL 0x8
  62. void board_config_lanes_mux(void)
  63. {
  64. ccsr_gur_t *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR;
  65. int srds_prtcl = (in_be32(&gur->rcwsr[4]) &
  66. FSL_CORENET_RCWSR4_SRDS_PRTCL) >> 26;
  67. u8 mux = 0;
  68. switch (srds_prtcl) {
  69. case 0x2:
  70. case 0x5:
  71. case 0x9:
  72. case 0xa:
  73. case 0xf:
  74. break;
  75. case 0x8:
  76. mux |= CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
  77. break;
  78. case 0x14:
  79. mux |= CPLD_LANE_A_SEL;
  80. break;
  81. case 0x17:
  82. mux |= CPLD_LANE_G_SEL;
  83. break;
  84. case 0x16:
  85. case 0x19:
  86. case 0x1a:
  87. mux |= CPLD_LANE_G_SEL | CPLD_LANE_C_SEL | CPLD_LANE_D_SEL;
  88. break;
  89. case 0x1c:
  90. mux |= CPLD_LANE_G_SEL | CPLD_LANE_A_SEL;
  91. break;
  92. default:
  93. printf("Fman:Unsupported SerDes Protocol 0x%02x\n", srds_prtcl);
  94. break;
  95. }
  96. CPLD_WRITE(serdes_mux, mux);
  97. }
  98. int board_early_init_r(void)
  99. {
  100. const unsigned int flashbase = CONFIG_SYS_FLASH_BASE;
  101. int flash_esel = find_tlb_idx((void *)flashbase, 1);
  102. /*
  103. * Remap Boot flash + PROMJET region to caching-inhibited
  104. * so that flash can be erased properly.
  105. */
  106. /* Flush d-cache and invalidate i-cache of any FLASH data */
  107. flush_dcache();
  108. invalidate_icache();
  109. if (flash_esel == -1) {
  110. /* very unlikely unless something is messed up */
  111. puts("Error: Could not find TLB for FLASH BASE\n");
  112. flash_esel = 2; /* give our best effort to continue */
  113. } else {
  114. /* invalidate existing TLB entry for flash + promjet */
  115. disable_tlb(flash_esel);
  116. }
  117. set_tlb(1, flashbase, CONFIG_SYS_FLASH_BASE_PHYS,
  118. MAS3_SX|MAS3_SW|MAS3_SR, MAS2_I|MAS2_G,
  119. 0, flash_esel, BOOKE_PAGESZ_256M, 1);
  120. board_config_lanes_mux();
  121. return 0;
  122. }
  123. unsigned long get_board_sys_clk(unsigned long dummy)
  124. {
  125. u8 sysclk_conf = CPLD_READ(sysclk_sw1);
  126. switch (sysclk_conf & 0x7) {
  127. case CPLD_SYSCLK_83:
  128. return 83333333;
  129. case CPLD_SYSCLK_100:
  130. return 100000000;
  131. default:
  132. return 66666666;
  133. }
  134. }
  135. #define NUM_SRDS_BANKS 2
  136. int misc_init_r(void)
  137. {
  138. serdes_corenet_t *regs = (void *)CONFIG_SYS_FSL_CORENET_SERDES_ADDR;
  139. u32 actual[NUM_SRDS_BANKS];
  140. unsigned int i;
  141. u8 sw;
  142. static const int freq[][3] = {
  143. {0, SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_125},
  144. {SRDS_PLLCR0_RFCK_SEL_100, SRDS_PLLCR0_RFCK_SEL_156_25,
  145. SRDS_PLLCR0_RFCK_SEL_125}
  146. };
  147. sw = in_8(&CPLD_SW(2)) >> 2;
  148. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  149. unsigned int clock = (sw >> (2 * i)) & 3;
  150. if (clock == 0x3) {
  151. printf("Warning: SDREFCLK%u switch setting of '11' is "
  152. "unsupported\n", i + 1);
  153. break;
  154. }
  155. if (i == 0 && clock == 0)
  156. puts("Warning: SDREFCLK1 switch setting of"
  157. "'00' is unsupported\n");
  158. else
  159. actual[i] = freq[i][clock];
  160. /*
  161. * PC board uses a different CPLD with PB board, this CPLD
  162. * has cpld_ver_sub = 1, and pcba_ver = 5. But CPLD on PB
  163. * board has cpld_ver_sub = 0, and pcba_ver = 4.
  164. */
  165. if ((i == 1) && (CPLD_READ(cpld_ver_sub) == 1) &&
  166. (CPLD_READ(pcba_ver) == 5)) {
  167. /* PC board bank2 frequency */
  168. actual[i] = freq[i-1][clock];
  169. }
  170. }
  171. for (i = 0; i < NUM_SRDS_BANKS; i++) {
  172. u32 expected = in_be32(&regs->bank[i].pllcr0);
  173. expected &= SRDS_PLLCR0_RFCK_SEL_MASK;
  174. if (expected != actual[i]) {
  175. printf("Warning: SERDES bank %u expects reference clock"
  176. " %sMHz, but actual is %sMHz\n", i + 1,
  177. serdes_clock_to_string(expected),
  178. serdes_clock_to_string(actual[i]));
  179. }
  180. }
  181. return 0;
  182. }
  183. int ft_board_setup(void *blob, bd_t *bd)
  184. {
  185. phys_addr_t base;
  186. phys_size_t size;
  187. ft_cpu_setup(blob, bd);
  188. base = getenv_bootm_low();
  189. size = getenv_bootm_size();
  190. fdt_fixup_memory(blob, (u64)base, (u64)size);
  191. #if defined(CONFIG_HAS_FSL_DR_USB) || defined(CONFIG_HAS_FSL_MPH_USB)
  192. fsl_fdt_fixup_dr_usb(blob, bd);
  193. #endif
  194. #ifdef CONFIG_PCI
  195. pci_of_setup(blob, bd);
  196. #endif
  197. fdt_fixup_liodn(blob);
  198. #ifdef CONFIG_SYS_DPAA_FMAN
  199. fdt_fixup_fman_ethernet(blob);
  200. #endif
  201. return 0;
  202. }