ls1043ardb.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2015 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <i2c.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/clock.h>
  9. #include <asm/arch/fsl_serdes.h>
  10. #include <asm/arch/soc.h>
  11. #include <fdt_support.h>
  12. #include <hwconfig.h>
  13. #include <ahci.h>
  14. #include <mmc.h>
  15. #include <scsi.h>
  16. #include <fm_eth.h>
  17. #include <fsl_esdhc.h>
  18. #include <fsl_ifc.h>
  19. #include <fsl_sec.h>
  20. #include "cpld.h"
  21. #ifdef CONFIG_U_QE
  22. #include <fsl_qe.h>
  23. #endif
  24. #include <asm/arch/ppa.h>
  25. DECLARE_GLOBAL_DATA_PTR;
  26. int board_early_init_f(void)
  27. {
  28. fsl_lsch2_early_init_f();
  29. return 0;
  30. }
  31. #ifndef CONFIG_SPL_BUILD
  32. int checkboard(void)
  33. {
  34. static const char *freq[2] = {"100.00MHZ", "156.25MHZ"};
  35. #ifndef CONFIG_SD_BOOT
  36. u8 cfg_rcw_src1, cfg_rcw_src2;
  37. u16 cfg_rcw_src;
  38. #endif
  39. u8 sd1refclk_sel;
  40. printf("Board: LS1043ARDB, boot from ");
  41. #ifdef CONFIG_SD_BOOT
  42. puts("SD\n");
  43. #else
  44. cfg_rcw_src1 = CPLD_READ(cfg_rcw_src1);
  45. cfg_rcw_src2 = CPLD_READ(cfg_rcw_src2);
  46. cpld_rev_bit(&cfg_rcw_src1);
  47. cfg_rcw_src = cfg_rcw_src1;
  48. cfg_rcw_src = (cfg_rcw_src << 1) | cfg_rcw_src2;
  49. if (cfg_rcw_src == 0x25)
  50. printf("vBank %d\n", CPLD_READ(vbank));
  51. else if (cfg_rcw_src == 0x106)
  52. puts("NAND\n");
  53. else
  54. printf("Invalid setting of SW4\n");
  55. #endif
  56. printf("CPLD: V%x.%x\nPCBA: V%x.0\n", CPLD_READ(cpld_ver),
  57. CPLD_READ(cpld_ver_sub), CPLD_READ(pcba_ver));
  58. puts("SERDES Reference Clocks:\n");
  59. sd1refclk_sel = CPLD_READ(sd1refclk_sel);
  60. printf("SD1_CLK1 = %s, SD1_CLK2 = %s\n", freq[sd1refclk_sel], freq[0]);
  61. return 0;
  62. }
  63. int board_init(void)
  64. {
  65. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  66. #ifdef CONFIG_SYS_FSL_ERRATUM_A010315
  67. erratum_a010315();
  68. #endif
  69. #ifdef CONFIG_FSL_IFC
  70. init_final_memctl_regs();
  71. #endif
  72. #ifdef CONFIG_SECURE_BOOT
  73. /* In case of Secure Boot, the IBR configures the SMMU
  74. * to allow only Secure transactions.
  75. * SMMU must be reset in bypass mode.
  76. * Set the ClientPD bit and Clear the USFCFG Bit
  77. */
  78. u32 val;
  79. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  80. out_le32(SMMU_SCR0, val);
  81. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  82. out_le32(SMMU_NSCR0, val);
  83. #endif
  84. #ifdef CONFIG_FSL_CAAM
  85. sec_init();
  86. #endif
  87. #ifdef CONFIG_FSL_LS_PPA
  88. ppa_init();
  89. #endif
  90. #ifdef CONFIG_U_QE
  91. u_qe_init();
  92. #endif
  93. /* invert AQR105 IRQ pins polarity */
  94. out_be32(&scfg->intpcr, AQR105_IRQ_MASK);
  95. return 0;
  96. }
  97. int config_board_mux(void)
  98. {
  99. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  100. u32 usb_pwrfault;
  101. if (hwconfig("qe-hdlc")) {
  102. out_be32(&scfg->rcwpmuxcr0,
  103. (in_be32(&scfg->rcwpmuxcr0) & ~0xff00) | 0x6600);
  104. printf("Assign to qe-hdlc clk, rcwpmuxcr0=%x\n",
  105. in_be32(&scfg->rcwpmuxcr0));
  106. } else {
  107. #ifdef CONFIG_HAS_FSL_XHCI_USB
  108. out_be32(&scfg->rcwpmuxcr0, 0x3333);
  109. out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
  110. usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
  111. SCFG_USBPWRFAULT_USB3_SHIFT) |
  112. (SCFG_USBPWRFAULT_DEDICATED <<
  113. SCFG_USBPWRFAULT_USB2_SHIFT) |
  114. (SCFG_USBPWRFAULT_SHARED <<
  115. SCFG_USBPWRFAULT_USB1_SHIFT);
  116. out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
  117. #endif
  118. }
  119. return 0;
  120. }
  121. #if defined(CONFIG_MISC_INIT_R)
  122. int misc_init_r(void)
  123. {
  124. config_board_mux();
  125. return 0;
  126. }
  127. #endif
  128. void fdt_del_qe(void *blob)
  129. {
  130. int nodeoff = 0;
  131. while ((nodeoff = fdt_node_offset_by_compatible(blob, 0,
  132. "fsl,qe")) >= 0) {
  133. fdt_del_node(blob, nodeoff);
  134. }
  135. }
  136. int ft_board_setup(void *blob, bd_t *bd)
  137. {
  138. u64 base[CONFIG_NR_DRAM_BANKS];
  139. u64 size[CONFIG_NR_DRAM_BANKS];
  140. /* fixup DT for the two DDR banks */
  141. base[0] = gd->bd->bi_dram[0].start;
  142. size[0] = gd->bd->bi_dram[0].size;
  143. base[1] = gd->bd->bi_dram[1].start;
  144. size[1] = gd->bd->bi_dram[1].size;
  145. fdt_fixup_memory_banks(blob, base, size, 2);
  146. ft_cpu_setup(blob, bd);
  147. #ifdef CONFIG_SYS_DPAA_FMAN
  148. fdt_fixup_fman_ethernet(blob);
  149. #endif
  150. /*
  151. * qe-hdlc and usb multi-use the pins,
  152. * when set hwconfig to qe-hdlc, delete usb node.
  153. */
  154. if (hwconfig("qe-hdlc"))
  155. #ifdef CONFIG_HAS_FSL_XHCI_USB
  156. fdt_del_node_and_alias(blob, "usb1");
  157. #endif
  158. /*
  159. * qe just support qe-uart and qe-hdlc,
  160. * if qe-uart and qe-hdlc are not set in hwconfig,
  161. * delete qe node.
  162. */
  163. if (!hwconfig("qe-uart") && !hwconfig("qe-hdlc"))
  164. fdt_del_qe(blob);
  165. return 0;
  166. }
  167. u8 flash_read8(void *addr)
  168. {
  169. return __raw_readb(addr + 1);
  170. }
  171. void flash_write16(u16 val, void *addr)
  172. {
  173. u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
  174. __raw_writew(shftval, addr);
  175. }
  176. u16 flash_read16(void *addr)
  177. {
  178. u16 val = __raw_readw(addr);
  179. return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
  180. }
  181. #endif