spl.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * SPL board functions for CompuLab CL-SOM-iMX7 module
  4. *
  5. * (C) Copyright 2017 CompuLab, Ltd. http://www.compulab.com
  6. *
  7. * Author: Uri Mashiach <uri.mashiach@compulab.co.il>
  8. */
  9. #include <common.h>
  10. #include <hang.h>
  11. #include <init.h>
  12. #include <spl.h>
  13. #include <fsl_esdhc_imx.h>
  14. #include <asm/mach-imx/iomux-v3.h>
  15. #include <asm/arch-mx7/mx7-pins.h>
  16. #include <asm/arch-mx7/clock.h>
  17. #include <asm/arch-mx7/mx7-ddr.h>
  18. #include "common.h"
  19. #ifdef CONFIG_FSL_ESDHC_IMX
  20. static struct fsl_esdhc_cfg cl_som_imx7_spl_usdhc_cfg = {
  21. USDHC1_BASE_ADDR, 0, 4};
  22. int board_mmc_init(struct bd_info *bis)
  23. {
  24. cl_som_imx7_usdhc1_pads_set();
  25. cl_som_imx7_spl_usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
  26. return fsl_esdhc_initialize(bis, &cl_som_imx7_spl_usdhc_cfg);
  27. }
  28. #endif /* CONFIG_FSL_ESDHC_IMX */
  29. static iomux_v3_cfg_t const led_pads[] = {
  30. MX7D_PAD_SAI1_TX_SYNC__GPIO6_IO14 | MUX_PAD_CTRL(PAD_CTL_PUS_PU5KOHM |
  31. PAD_CTL_PUE | PAD_CTL_SRE_SLOW)
  32. };
  33. static struct ddrc cl_som_imx7_spl_ddrc_regs_val = {
  34. .init1 = 0x00690000,
  35. .init0 = 0x00020083,
  36. .init3 = 0x09300004,
  37. .init4 = 0x04080000,
  38. .init5 = 0x00100004,
  39. .rankctl = 0x0000033F,
  40. .dramtmg1 = 0x0007020E,
  41. .dramtmg2 = 0x03040407,
  42. .dramtmg3 = 0x00002006,
  43. .dramtmg4 = 0x04020305,
  44. .dramtmg5 = 0x03030202,
  45. .dramtmg8 = 0x00000803,
  46. .zqctl0 = 0x00810021,
  47. .dfitmg0 = 0x02098204,
  48. .dfitmg1 = 0x00030303,
  49. .dfiupd0 = 0x80400003,
  50. .dfiupd1 = 0x00100020,
  51. .dfiupd2 = 0x80100004,
  52. .addrmap4 = 0x00000F0F,
  53. .odtcfg = 0x06000604,
  54. .odtmap = 0x00000001,
  55. };
  56. static struct ddrc_mp cl_som_imx7_spl_ddrc_mp_val = {
  57. .pctrl_0 = 0x00000001,
  58. };
  59. static struct ddr_phy cl_som_imx7_spl_ddr_phy_regs_val = {
  60. .phy_con0 = 0x17420F40,
  61. .phy_con1 = 0x10210100,
  62. .phy_con4 = 0x00060807,
  63. .mdll_con0 = 0x1010007E,
  64. .drvds_con0 = 0x00000D6E,
  65. .cmd_sdll_con0 = 0x00000010,
  66. .offset_lp_con0 = 0x0000000F,
  67. };
  68. struct mx7_calibration cl_som_imx7_spl_calib_param = {
  69. .num_val = 5,
  70. .values = {
  71. 0x0E407304,
  72. 0x0E447304,
  73. 0x0E447306,
  74. 0x0E447304,
  75. 0x0E407304,
  76. },
  77. };
  78. static void cl_som_imx7_spl_dram_cfg_size(u32 ram_size)
  79. {
  80. switch (ram_size) {
  81. case SZ_256M:
  82. cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01041001;
  83. cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x00400046;
  84. cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E1109;
  85. cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000014;
  86. cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00151515;
  87. cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x03030303;
  88. cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F0F0303;
  89. cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0C0C0C0C;
  90. cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x04040404;
  91. break;
  92. case SZ_512M:
  93. cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01040001;
  94. cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x00400046;
  95. cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E1109;
  96. cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000015;
  97. cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00161616;
  98. cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
  99. cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F0F0404;
  100. cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0C0C0C0C;
  101. cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x04040404;
  102. break;
  103. case SZ_1G:
  104. cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01040001;
  105. cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x00400046;
  106. cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E1109;
  107. cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000016;
  108. cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00171717;
  109. cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
  110. cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F040404;
  111. cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0A0A0A0A;
  112. cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x02020202;
  113. break;
  114. case SZ_2G:
  115. cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01040001;
  116. cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x0040005E;
  117. cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E110A;
  118. cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000018;
  119. cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00181818;
  120. cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
  121. cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x04040404;
  122. cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0A0A0A0A;
  123. cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x04040404;
  124. break;
  125. }
  126. mx7_dram_cfg(&cl_som_imx7_spl_ddrc_regs_val,
  127. &cl_som_imx7_spl_ddrc_mp_val,
  128. &cl_som_imx7_spl_ddr_phy_regs_val,
  129. &cl_som_imx7_spl_calib_param);
  130. }
  131. static void cl_som_imx7_spl_dram_cfg(void)
  132. {
  133. ulong ram_size_test, ram_size = 0;
  134. for (ram_size = SZ_2G; ram_size >= SZ_256M; ram_size >>= 1) {
  135. cl_som_imx7_spl_dram_cfg_size(ram_size);
  136. ram_size_test = get_ram_size((long int *)PHYS_SDRAM, ram_size);
  137. if (ram_size_test == ram_size)
  138. break;
  139. }
  140. if (ram_size < SZ_256M) {
  141. puts("!!!ERROR!!! DRAM detection failed!!!\n");
  142. hang();
  143. }
  144. }
  145. #ifdef CONFIG_SPL_SPI_SUPPORT
  146. static void cl_som_imx7_spl_spi_init(void)
  147. {
  148. cl_som_imx7_espi1_pads_set();
  149. }
  150. #else /* !CONFIG_SPL_SPI_SUPPORT */
  151. static void cl_som_imx7_spl_spi_init(void) {}
  152. #endif /* CONFIG_SPL_SPI_SUPPORT */
  153. void board_init_f(ulong dummy)
  154. {
  155. imx_iomux_v3_setup_multiple_pads(led_pads, 1);
  156. /* setup AIPS and disable watchdog */
  157. arch_cpu_init();
  158. /* setup GP timer */
  159. timer_init();
  160. cl_som_imx7_spl_spi_init();
  161. cl_som_imx7_uart1_pads_set();
  162. /* UART clocks enabled and gd valid - init serial console */
  163. preloader_console_init();
  164. /* DRAM detection */
  165. cl_som_imx7_spl_dram_cfg();
  166. /* Clear the BSS. */
  167. memset(__bss_start, 0, __bss_end - __bss_start);
  168. /* load/boot image from boot device */
  169. board_init_r(NULL, 0);
  170. }
  171. void spl_board_init(void)
  172. {
  173. u32 boot_device = spl_boot_device();
  174. if (boot_device == BOOT_DEVICE_SPI)
  175. puts("Booting from SPI flash\n");
  176. else if (boot_device == BOOT_DEVICE_MMC1)
  177. puts("Booting from SD card\n");
  178. else
  179. puts("Unknown boot device\n");
  180. }
  181. void board_boot_order(u32 *spl_boot_list)
  182. {
  183. spl_boot_list[0] = spl_boot_device();
  184. switch (spl_boot_list[0]) {
  185. case BOOT_DEVICE_SPI:
  186. spl_boot_list[1] = BOOT_DEVICE_MMC1;
  187. break;
  188. case BOOT_DEVICE_MMC1:
  189. spl_boot_list[1] = BOOT_DEVICE_SPI;
  190. break;
  191. }
  192. }