p2041rdb.c 5.4 KB

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