spl.c 5.9 KB

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