blob: 98c3b831f1e1aca28d3968c8e790737dacef4c7d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Ilya Ledvich38a53c62017-09-24 09:00:25 +03002/*
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>
Ilya Ledvich38a53c62017-09-24 09:00:25 +03008 */
9
10#include <common.h>
Simon Glassf11478f2019-12-28 10:45:07 -070011#include <hang.h>
Simon Glass8e16b1e2019-12-28 10:45:05 -070012#include <init.h>
Ilya Ledvich38a53c62017-09-24 09:00:25 +030013#include <spl.h>
Yangbo Lu73340382019-06-21 11:42:28 +080014#include <fsl_esdhc_imx.h>
Ilya Ledvich38a53c62017-09-24 09:00:25 +030015#include <asm/mach-imx/iomux-v3.h>
16#include <asm/arch-mx7/mx7-pins.h>
17#include <asm/arch-mx7/clock.h>
18#include <asm/arch-mx7/mx7-ddr.h>
Shiji Yangbb112342023-08-03 09:47:16 +080019#include <asm/sections.h>
Ilya Ledvich38a53c62017-09-24 09:00:25 +030020#include "common.h"
21
Yangbo Lu73340382019-06-21 11:42:28 +080022#ifdef CONFIG_FSL_ESDHC_IMX
Ilya Ledvich38a53c62017-09-24 09:00:25 +030023
24static struct fsl_esdhc_cfg cl_som_imx7_spl_usdhc_cfg = {
25 USDHC1_BASE_ADDR, 0, 4};
26
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +090027int board_mmc_init(struct bd_info *bis)
Ilya Ledvich38a53c62017-09-24 09:00:25 +030028{
29 cl_som_imx7_usdhc1_pads_set();
30 cl_som_imx7_spl_usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
31 return fsl_esdhc_initialize(bis, &cl_som_imx7_spl_usdhc_cfg);
32}
Yangbo Lu73340382019-06-21 11:42:28 +080033#endif /* CONFIG_FSL_ESDHC_IMX */
Ilya Ledvich38a53c62017-09-24 09:00:25 +030034
35static iomux_v3_cfg_t const led_pads[] = {
36 MX7D_PAD_SAI1_TX_SYNC__GPIO6_IO14 | MUX_PAD_CTRL(PAD_CTL_PUS_PU5KOHM |
37 PAD_CTL_PUE | PAD_CTL_SRE_SLOW)
38};
39
40static struct ddrc cl_som_imx7_spl_ddrc_regs_val = {
41 .init1 = 0x00690000,
42 .init0 = 0x00020083,
43 .init3 = 0x09300004,
44 .init4 = 0x04080000,
45 .init5 = 0x00100004,
46 .rankctl = 0x0000033F,
47 .dramtmg1 = 0x0007020E,
48 .dramtmg2 = 0x03040407,
49 .dramtmg3 = 0x00002006,
50 .dramtmg4 = 0x04020305,
51 .dramtmg5 = 0x03030202,
52 .dramtmg8 = 0x00000803,
53 .zqctl0 = 0x00810021,
54 .dfitmg0 = 0x02098204,
55 .dfitmg1 = 0x00030303,
56 .dfiupd0 = 0x80400003,
57 .dfiupd1 = 0x00100020,
58 .dfiupd2 = 0x80100004,
59 .addrmap4 = 0x00000F0F,
60 .odtcfg = 0x06000604,
61 .odtmap = 0x00000001,
62};
63
64static struct ddrc_mp cl_som_imx7_spl_ddrc_mp_val = {
65 .pctrl_0 = 0x00000001,
66};
67
68static struct ddr_phy cl_som_imx7_spl_ddr_phy_regs_val = {
69 .phy_con0 = 0x17420F40,
70 .phy_con1 = 0x10210100,
71 .phy_con4 = 0x00060807,
72 .mdll_con0 = 0x1010007E,
73 .drvds_con0 = 0x00000D6E,
74 .cmd_sdll_con0 = 0x00000010,
75 .offset_lp_con0 = 0x0000000F,
76};
77
78struct mx7_calibration cl_som_imx7_spl_calib_param = {
79 .num_val = 5,
80 .values = {
81 0x0E407304,
82 0x0E447304,
83 0x0E447306,
84 0x0E447304,
85 0x0E407304,
86 },
87};
88
89static void cl_som_imx7_spl_dram_cfg_size(u32 ram_size)
90{
91 switch (ram_size) {
92 case SZ_256M:
93 cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01041001;
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 = 0x00000014;
97 cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00151515;
98 cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x03030303;
99 cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F0F0303;
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_512M:
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 = 0x00000015;
108 cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00161616;
109 cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
110 cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F0F0404;
111 cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0C0C0C0C;
112 cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x04040404;
113 break;
114 case SZ_1G:
115 cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01040001;
116 cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x00400046;
117 cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E1109;
118 cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000016;
119 cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00171717;
120 cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
121 cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x0F040404;
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 = 0x02020202;
124 break;
125 case SZ_2G:
126 cl_som_imx7_spl_ddrc_regs_val.mstr = 0x01040001;
127 cl_som_imx7_spl_ddrc_regs_val.rfshtmg = 0x0040005E;
128 cl_som_imx7_spl_ddrc_regs_val.dramtmg0 = 0x090E110A;
129 cl_som_imx7_spl_ddrc_regs_val.addrmap0 = 0x00000018;
130 cl_som_imx7_spl_ddrc_regs_val.addrmap1 = 0x00181818;
131 cl_som_imx7_spl_ddrc_regs_val.addrmap5 = 0x04040404;
132 cl_som_imx7_spl_ddrc_regs_val.addrmap6 = 0x04040404;
133 cl_som_imx7_spl_ddr_phy_regs_val.offset_rd_con0 = 0x0A0A0A0A;
134 cl_som_imx7_spl_ddr_phy_regs_val.offset_wr_con0 = 0x04040404;
135 break;
136 }
137
138 mx7_dram_cfg(&cl_som_imx7_spl_ddrc_regs_val,
139 &cl_som_imx7_spl_ddrc_mp_val,
140 &cl_som_imx7_spl_ddr_phy_regs_val,
141 &cl_som_imx7_spl_calib_param);
142}
143
144static void cl_som_imx7_spl_dram_cfg(void)
145{
146 ulong ram_size_test, ram_size = 0;
147
148 for (ram_size = SZ_2G; ram_size >= SZ_256M; ram_size >>= 1) {
149 cl_som_imx7_spl_dram_cfg_size(ram_size);
150 ram_size_test = get_ram_size((long int *)PHYS_SDRAM, ram_size);
151 if (ram_size_test == ram_size)
152 break;
153 }
154
155 if (ram_size < SZ_256M) {
156 puts("!!!ERROR!!! DRAM detection failed!!!\n");
157 hang();
158 }
159}
160
Simon Glassa5820472021-08-08 12:20:14 -0600161#ifdef CONFIG_SPL_SPI
Ilya Ledvich38a53c62017-09-24 09:00:25 +0300162
163static void cl_som_imx7_spl_spi_init(void)
164{
165 cl_som_imx7_espi1_pads_set();
166}
Simon Glassa5820472021-08-08 12:20:14 -0600167#else /* !CONFIG_SPL_SPI */
Ilya Ledvich38a53c62017-09-24 09:00:25 +0300168static void cl_som_imx7_spl_spi_init(void) {}
Simon Glassa5820472021-08-08 12:20:14 -0600169#endif /* CONFIG_SPL_SPI */
Ilya Ledvich38a53c62017-09-24 09:00:25 +0300170
171void board_init_f(ulong dummy)
172{
173 imx_iomux_v3_setup_multiple_pads(led_pads, 1);
174 /* setup AIPS and disable watchdog */
175 arch_cpu_init();
176 /* setup GP timer */
177 timer_init();
178 cl_som_imx7_spl_spi_init();
179 cl_som_imx7_uart1_pads_set();
180 /* UART clocks enabled and gd valid - init serial console */
181 preloader_console_init();
182 /* DRAM detection */
183 cl_som_imx7_spl_dram_cfg();
184 /* Clear the BSS. */
185 memset(__bss_start, 0, __bss_end - __bss_start);
186 /* load/boot image from boot device */
187 board_init_r(NULL, 0);
188}
189
190void spl_board_init(void)
191{
192 u32 boot_device = spl_boot_device();
193
194 if (boot_device == BOOT_DEVICE_SPI)
195 puts("Booting from SPI flash\n");
196 else if (boot_device == BOOT_DEVICE_MMC1)
197 puts("Booting from SD card\n");
198 else
199 puts("Unknown boot device\n");
200}
201
202void board_boot_order(u32 *spl_boot_list)
203{
204 spl_boot_list[0] = spl_boot_device();
205 switch (spl_boot_list[0]) {
206 case BOOT_DEVICE_SPI:
207 spl_boot_list[1] = BOOT_DEVICE_MMC1;
208 break;
209 case BOOT_DEVICE_MMC1:
210 spl_boot_list[1] = BOOT_DEVICE_SPI;
211 break;
212 }
213}