ls1046aqds.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2016 Freescale Semiconductor, Inc.
  4. */
  5. #include <common.h>
  6. #include <i2c.h>
  7. #include <fdt_support.h>
  8. #include <fsl_ddr_sdram.h>
  9. #include <asm/io.h>
  10. #include <asm/arch/clock.h>
  11. #include <asm/arch/fsl_serdes.h>
  12. #include <asm/arch/ppa.h>
  13. #include <asm/arch/fdt.h>
  14. #include <asm/arch/mmu.h>
  15. #include <asm/arch/soc.h>
  16. #include <ahci.h>
  17. #include <hwconfig.h>
  18. #include <mmc.h>
  19. #include <scsi.h>
  20. #include <fm_eth.h>
  21. #include <fsl_csu.h>
  22. #include <fsl_esdhc.h>
  23. #include <fsl_ifc.h>
  24. #include <fsl_sec.h>
  25. #include <spl.h>
  26. #include "../common/vid.h"
  27. #include "../common/qixis.h"
  28. #include "ls1046aqds_qixis.h"
  29. DECLARE_GLOBAL_DATA_PTR;
  30. enum {
  31. MUX_TYPE_GPIO,
  32. };
  33. int checkboard(void)
  34. {
  35. char buf[64];
  36. #ifndef CONFIG_SD_BOOT
  37. u8 sw;
  38. #endif
  39. puts("Board: LS1046AQDS, boot from ");
  40. #ifdef CONFIG_SD_BOOT
  41. puts("SD\n");
  42. #else
  43. sw = QIXIS_READ(brdcfg[0]);
  44. sw = (sw & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  45. if (sw < 0x8)
  46. printf("vBank: %d\n", sw);
  47. else if (sw == 0x8)
  48. puts("PromJet\n");
  49. else if (sw == 0x9)
  50. puts("NAND\n");
  51. else if (sw == 0xF)
  52. printf("QSPI\n");
  53. else
  54. printf("invalid setting of SW%u\n", QIXIS_LBMAP_SWITCH);
  55. #endif
  56. printf("Sys ID: 0x%02x, Sys Ver: 0x%02x\n",
  57. QIXIS_READ(id), QIXIS_READ(arch));
  58. printf("FPGA: v%d (%s), build %d\n",
  59. (int)QIXIS_READ(scver), qixis_read_tag(buf),
  60. (int)qixis_read_minor());
  61. return 0;
  62. }
  63. bool if_board_diff_clk(void)
  64. {
  65. u8 diff_conf = QIXIS_READ(brdcfg[11]);
  66. return diff_conf & 0x40;
  67. }
  68. unsigned long get_board_sys_clk(void)
  69. {
  70. u8 sysclk_conf = QIXIS_READ(brdcfg[1]);
  71. switch (sysclk_conf & 0x0f) {
  72. case QIXIS_SYSCLK_64:
  73. return 64000000;
  74. case QIXIS_SYSCLK_83:
  75. return 83333333;
  76. case QIXIS_SYSCLK_100:
  77. return 100000000;
  78. case QIXIS_SYSCLK_125:
  79. return 125000000;
  80. case QIXIS_SYSCLK_133:
  81. return 133333333;
  82. case QIXIS_SYSCLK_150:
  83. return 150000000;
  84. case QIXIS_SYSCLK_160:
  85. return 160000000;
  86. case QIXIS_SYSCLK_166:
  87. return 166666666;
  88. }
  89. return 66666666;
  90. }
  91. unsigned long get_board_ddr_clk(void)
  92. {
  93. u8 ddrclk_conf = QIXIS_READ(brdcfg[1]);
  94. if (if_board_diff_clk())
  95. return get_board_sys_clk();
  96. switch ((ddrclk_conf & 0x30) >> 4) {
  97. case QIXIS_DDRCLK_100:
  98. return 100000000;
  99. case QIXIS_DDRCLK_125:
  100. return 125000000;
  101. case QIXIS_DDRCLK_133:
  102. return 133333333;
  103. }
  104. return 66666666;
  105. }
  106. #ifdef CONFIG_LPUART
  107. u32 get_lpuart_clk(void)
  108. {
  109. return gd->bus_clk;
  110. }
  111. #endif
  112. int select_i2c_ch_pca9547(u8 ch)
  113. {
  114. int ret;
  115. ret = i2c_write(I2C_MUX_PCA_ADDR_PRI, 0, 1, &ch, 1);
  116. if (ret) {
  117. puts("PCA: failed to select proper channel\n");
  118. return ret;
  119. }
  120. return 0;
  121. }
  122. int dram_init(void)
  123. {
  124. /*
  125. * When resuming from deep sleep, the I2C channel may not be
  126. * in the default channel. So, switch to the default channel
  127. * before accessing DDR SPD.
  128. */
  129. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  130. fsl_initdram();
  131. #if !defined(CONFIG_SPL) || defined(CONFIG_SPL_BUILD)
  132. /* This will break-before-make MMU for DDR */
  133. update_early_mmu_table();
  134. #endif
  135. return 0;
  136. }
  137. int i2c_multiplexer_select_vid_channel(u8 channel)
  138. {
  139. return select_i2c_ch_pca9547(channel);
  140. }
  141. int board_early_init_f(void)
  142. {
  143. #ifdef CONFIG_HAS_FSL_XHCI_USB
  144. struct ccsr_scfg *scfg = (struct ccsr_scfg *)CONFIG_SYS_FSL_SCFG_ADDR;
  145. u32 usb_pwrfault;
  146. #endif
  147. #ifdef CONFIG_LPUART
  148. u8 uart;
  149. #endif
  150. #ifdef CONFIG_SYS_I2C_EARLY_INIT
  151. i2c_early_init_f();
  152. #endif
  153. fsl_lsch2_early_init_f();
  154. #ifdef CONFIG_HAS_FSL_XHCI_USB
  155. out_be32(&scfg->rcwpmuxcr0, 0x3333);
  156. out_be32(&scfg->usbdrvvbus_selcr, SCFG_USBDRVVBUS_SELCR_USB1);
  157. usb_pwrfault = (SCFG_USBPWRFAULT_DEDICATED <<
  158. SCFG_USBPWRFAULT_USB3_SHIFT) |
  159. (SCFG_USBPWRFAULT_DEDICATED <<
  160. SCFG_USBPWRFAULT_USB2_SHIFT) |
  161. (SCFG_USBPWRFAULT_SHARED <<
  162. SCFG_USBPWRFAULT_USB1_SHIFT);
  163. out_be32(&scfg->usbpwrfault_selcr, usb_pwrfault);
  164. #endif
  165. #ifdef CONFIG_LPUART
  166. /* We use lpuart0 as system console */
  167. uart = QIXIS_READ(brdcfg[14]);
  168. uart &= ~CFG_UART_MUX_MASK;
  169. uart |= CFG_LPUART_EN << CFG_UART_MUX_SHIFT;
  170. QIXIS_WRITE(brdcfg[14], uart);
  171. #endif
  172. return 0;
  173. }
  174. #ifdef CONFIG_FSL_DEEP_SLEEP
  175. /* determine if it is a warm boot */
  176. bool is_warm_boot(void)
  177. {
  178. #define DCFG_CCSR_CRSTSR_WDRFR (1 << 3)
  179. struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
  180. if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
  181. return 1;
  182. return 0;
  183. }
  184. #endif
  185. int config_board_mux(int ctrl_type)
  186. {
  187. u8 reg14;
  188. reg14 = QIXIS_READ(brdcfg[14]);
  189. switch (ctrl_type) {
  190. case MUX_TYPE_GPIO:
  191. reg14 = (reg14 & (~0x6)) | 0x2;
  192. break;
  193. default:
  194. puts("Unsupported mux interface type\n");
  195. return -1;
  196. }
  197. QIXIS_WRITE(brdcfg[14], reg14);
  198. return 0;
  199. }
  200. int config_serdes_mux(void)
  201. {
  202. return 0;
  203. }
  204. #ifdef CONFIG_MISC_INIT_R
  205. int misc_init_r(void)
  206. {
  207. if (hwconfig("gpio"))
  208. config_board_mux(MUX_TYPE_GPIO);
  209. return 0;
  210. }
  211. #endif
  212. int board_init(void)
  213. {
  214. select_i2c_ch_pca9547(I2C_MUX_CH_DEFAULT);
  215. #ifdef CONFIG_SYS_FSL_SERDES
  216. config_serdes_mux();
  217. #endif
  218. if (adjust_vdd(0))
  219. printf("Warning: Adjusting core voltage failed.\n");
  220. #ifdef CONFIG_FSL_LS_PPA
  221. ppa_init();
  222. #endif
  223. #ifdef CONFIG_SECURE_BOOT
  224. /*
  225. * In case of Secure Boot, the IBR configures the SMMU
  226. * to allow only Secure transactions.
  227. * SMMU must be reset in bypass mode.
  228. * Set the ClientPD bit and Clear the USFCFG Bit
  229. */
  230. u32 val;
  231. val = (in_le32(SMMU_SCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  232. out_le32(SMMU_SCR0, val);
  233. val = (in_le32(SMMU_NSCR0) | SCR0_CLIENTPD_MASK) & ~(SCR0_USFCFG_MASK);
  234. out_le32(SMMU_NSCR0, val);
  235. #endif
  236. #ifdef CONFIG_FSL_CAAM
  237. sec_init();
  238. #endif
  239. return 0;
  240. }
  241. #ifdef CONFIG_OF_BOARD_SETUP
  242. int ft_board_setup(void *blob, bd_t *bd)
  243. {
  244. u64 base[CONFIG_NR_DRAM_BANKS];
  245. u64 size[CONFIG_NR_DRAM_BANKS];
  246. u8 reg;
  247. /* fixup DT for the two DDR banks */
  248. base[0] = gd->bd->bi_dram[0].start;
  249. size[0] = gd->bd->bi_dram[0].size;
  250. base[1] = gd->bd->bi_dram[1].start;
  251. size[1] = gd->bd->bi_dram[1].size;
  252. fdt_fixup_memory_banks(blob, base, size, 2);
  253. ft_cpu_setup(blob, bd);
  254. #ifdef CONFIG_SYS_DPAA_FMAN
  255. fdt_fixup_fman_ethernet(blob);
  256. fdt_fixup_board_enet(blob);
  257. #endif
  258. reg = QIXIS_READ(brdcfg[0]);
  259. reg = (reg & QIXIS_LBMAP_MASK) >> QIXIS_LBMAP_SHIFT;
  260. /* Disable IFC if QSPI is enabled */
  261. if (reg == 0xF)
  262. do_fixup_by_compat(blob, "fsl,ifc",
  263. "status", "disabled", 8 + 1, 1);
  264. return 0;
  265. }
  266. #endif
  267. u8 flash_read8(void *addr)
  268. {
  269. return __raw_readb(addr + 1);
  270. }
  271. void flash_write16(u16 val, void *addr)
  272. {
  273. u16 shftval = (((val >> 8) & 0xff) | ((val << 8) & 0xff00));
  274. __raw_writew(shftval, addr);
  275. }
  276. u16 flash_read16(void *addr)
  277. {
  278. u16 val = __raw_readw(addr);
  279. return (((val) >> 8) & 0x00ff) | (((val) << 8) & 0xff00);
  280. }