blob: b96e4ce8967f963eef4995084374e4c8abbbf481 [file] [log] [blame]
Jagan Teki105bd892017-02-24 15:32:54 +05301/*
2 * Copyright (C) 2016 Amarula Solutions B.V.
3 * Copyright (C) 2016 Engicam S.r.l.
4 * Author: Jagan Teki <jagan@amarulasolutions.com>
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
Jagan Teki74207f22017-02-24 15:45:19 +053010#include <mmc.h>
Jagan Teki105bd892017-02-24 15:32:54 +053011
12#include <asm/io.h>
13#include <asm/gpio.h>
14#include <linux/sizes.h>
15
16#include <asm/arch/clock.h>
17#include <asm/arch/crm_regs.h>
18#include <asm/arch/iomux.h>
19#include <asm/arch/mx6-pins.h>
20#include <asm/arch/sys_proto.h>
21#include <asm/imx-common/iomux-v3.h>
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
26 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
27 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
28
29static iomux_v3_cfg_t const uart1_pads[] = {
30 MX6_PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL),
31 MX6_PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL),
32};
33
34int board_early_init_f(void)
35{
36 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
37
38 return 0;
39}
40
Jagan Teki2e7aa952017-02-24 15:32:59 +053041#ifdef CONFIG_NAND_MXS
42
43#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
44#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
45 PAD_CTL_SRE_FAST)
46#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
47
48static iomux_v3_cfg_t const nand_pads[] = {
49 MX6_PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
50 MX6_PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
51 MX6_PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
52 MX6_PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
53 MX6_PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
54 MX6_PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
55 MX6_PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
56 MX6_PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
57 MX6_PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
58 MX6_PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
59 MX6_PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
60 MX6_PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
61 MX6_PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
62 MX6_PAD_NAND_WP_B__RAWNAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
63 MX6_PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2),
64};
65
66static void setup_gpmi_nand(void)
67{
68 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
69
70 /* config gpmi nand iomux */
71 imx_iomux_v3_setup_multiple_pads(nand_pads, ARRAY_SIZE(nand_pads));
72
73 clrbits_le32(&mxc_ccm->CCGR4,
74 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
75 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
76 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
77 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
78 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
79
80 /*
81 * config gpmi and bch clock to 100 MHz
82 * bch/gpmi select PLL2 PFD2 400M
83 * 100M = 400M / 4
84 */
85 clrbits_le32(&mxc_ccm->cscmr1,
86 MXC_CCM_CSCMR1_BCH_CLK_SEL |
87 MXC_CCM_CSCMR1_GPMI_CLK_SEL);
88 clrsetbits_le32(&mxc_ccm->cscdr1,
89 MXC_CCM_CSCDR1_BCH_PODF_MASK |
90 MXC_CCM_CSCDR1_GPMI_PODF_MASK,
91 (3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
92 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
93
94 /* enable gpmi and bch clock gating */
95 setbits_le32(&mxc_ccm->CCGR4,
96 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
97 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
98 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
99 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
100 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
101
102 /* enable apbh clock gating */
103 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
104}
105#endif /* CONFIG_NAND_MXS */
106
Jagan Teki74207f22017-02-24 15:45:19 +0530107#ifdef CONFIG_ENV_IS_IN_MMC
108static void mmc_late_init(void)
109{
110 char cmd[32];
111 char mmcblk[32];
112 u32 dev_no = mmc_get_env_dev();
113
114 setenv_ulong("mmcdev", dev_no);
115
116 /* Set mmcblk env */
117 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
118 setenv("mmcroot", mmcblk);
119
120 sprintf(cmd, "mmc dev %d", dev_no);
121 run_command(cmd, 0);
122}
123#endif
124
Jagan Tekidf235812017-02-24 15:45:18 +0530125int board_late_init(void)
126{
127 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
128 IMX6_BMODE_SHIFT) {
129 case IMX6_BMODE_SD:
130 case IMX6_BMODE_ESD:
131 case IMX6_BMODE_MMC:
132 case IMX6_BMODE_EMMC:
Jagan Teki74207f22017-02-24 15:45:19 +0530133#ifdef CONFIG_ENV_IS_IN_MMC
134 mmc_late_init();
135#endif
Jagan Tekidf235812017-02-24 15:45:18 +0530136 setenv("modeboot", "mmcboot");
137 break;
138 case IMX6_BMODE_NAND:
139 setenv("modeboot", "nandboot");
140 break;
141 default:
142 setenv("modeboot", "");
143 break;
144 }
145
146 return 0;
147}
148
Jagan Teki105bd892017-02-24 15:32:54 +0530149int board_init(void)
150{
151 /* Address of boot parameters */
152 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
153
Jagan Teki2e7aa952017-02-24 15:32:59 +0530154#ifdef CONFIG_NAND_MXS
155 setup_gpmi_nand();
156#endif
Jagan Teki105bd892017-02-24 15:32:54 +0530157 return 0;
158}
159
160int dram_init(void)
161{
162 gd->ram_size = imx_ddr_size();
163
164 return 0;
165}
166
167#ifdef CONFIG_SPL_BUILD
168#include <libfdt.h>
169#include <spl.h>
170
171#include <asm/arch/crm_regs.h>
172#include <asm/arch/mx6-ddr.h>
173
174/* MMC board initialization is needed till adding DM support in SPL */
175#if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC)
176#include <mmc.h>
177#include <fsl_esdhc.h>
178
179#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
180 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
181 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
182
183static iomux_v3_cfg_t const usdhc1_pads[] = {
184 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
185 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
186 MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
187 MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
188 MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
189 MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
190
191 /* VSELECT */
192 MX6_PAD_GPIO1_IO05__USDHC1_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL),
193 /* CD */
194 MX6_PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL),
195 /* RST_B */
196 MX6_PAD_GPIO1_IO09__GPIO1_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
197};
198
Jagan Teki60dd2d42017-02-24 15:45:17 +0530199static iomux_v3_cfg_t const usdhc2_pads[] = {
200 MX6_PAD_NAND_ALE__USDHC2_RESET_B | MUX_PAD_CTRL(USDHC_PAD_CTRL),
201 MX6_PAD_NAND_RE_B__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
202 MX6_PAD_NAND_WE_B__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
203 MX6_PAD_NAND_DATA00__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
204 MX6_PAD_NAND_DATA01__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
205 MX6_PAD_NAND_DATA02__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
206 MX6_PAD_NAND_DATA03__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
207 MX6_PAD_NAND_DATA04__USDHC2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
208 MX6_PAD_NAND_DATA05__USDHC2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
209};
210
Jagan Teki105bd892017-02-24 15:32:54 +0530211#define USDHC1_CD_GPIO IMX_GPIO_NR(1, 19)
Jagan Teki60dd2d42017-02-24 15:45:17 +0530212#define USDHC2_CD_GPIO IMX_GPIO_NR(4, 5)
Jagan Teki105bd892017-02-24 15:32:54 +0530213
Jagan Teki60dd2d42017-02-24 15:45:17 +0530214struct fsl_esdhc_cfg usdhc_cfg[2] = {
Jagan Teki105bd892017-02-24 15:32:54 +0530215 {USDHC1_BASE_ADDR, 0, 4},
Jagan Teki60dd2d42017-02-24 15:45:17 +0530216 {USDHC2_BASE_ADDR, 0, 8},
Jagan Teki105bd892017-02-24 15:32:54 +0530217};
218
219int board_mmc_getcd(struct mmc *mmc)
220{
221 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
222 int ret = 0;
223
224 switch (cfg->esdhc_base) {
225 case USDHC1_BASE_ADDR:
226 ret = !gpio_get_value(USDHC1_CD_GPIO);
227 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530228 case USDHC2_BASE_ADDR:
229 ret = !gpio_get_value(USDHC2_CD_GPIO);
230 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530231 }
232
233 return ret;
234}
235
236int board_mmc_init(bd_t *bis)
237{
238 int i, ret;
239
240 /*
241 * According to the board_mmc_init() the following map is done:
242 * (U-boot device node) (Physical Port)
243 * mmc0 USDHC1
Jagan Teki60dd2d42017-02-24 15:45:17 +0530244 * mmc1 USDHC2
Jagan Teki105bd892017-02-24 15:32:54 +0530245 */
246 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
247 switch (i) {
248 case 0:
249 imx_iomux_v3_setup_multiple_pads(
250 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
251 gpio_direction_input(USDHC1_CD_GPIO);
252 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
253 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530254 case 1:
255 imx_iomux_v3_setup_multiple_pads(
256 usdhc1_pads, ARRAY_SIZE(usdhc2_pads));
257 gpio_direction_input(USDHC2_CD_GPIO);
258 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
259 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530260 default:
261 printf("Warning - USDHC%d controller not supporting\n",
262 i + 1);
263 return 0;
264 }
265
266 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
267 if (ret) {
268 printf("Warning: failed to initialize mmc dev %d\n", i);
269 return ret;
270 }
271 }
272
273 return 0;
274}
Jagan Teki931e84e2017-02-24 15:45:16 +0530275
276#ifdef CONFIG_ENV_IS_IN_MMC
277void board_boot_order(u32 *spl_boot_list)
278{
279 u32 bmode = imx6_src_get_boot_mode();
280 u8 boot_dev = BOOT_DEVICE_MMC1;
281
282 switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
283 case IMX6_BMODE_SD:
284 case IMX6_BMODE_ESD:
285 /* SD/eSD - BOOT_DEVICE_MMC1 */
286 break;
287 case IMX6_BMODE_MMC:
288 case IMX6_BMODE_EMMC:
289 /* MMC/eMMC */
290 boot_dev = BOOT_DEVICE_MMC2;
291 break;
292 default:
293 /* Default - BOOT_DEVICE_MMC1 */
294 printf("Wrong board boot order\n");
295 break;
296 }
297
298 spl_boot_list[0] = boot_dev;
299}
300#endif
Jagan Teki105bd892017-02-24 15:32:54 +0530301#endif /* CONFIG_FSL_ESDHC */
302
303static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
304 .grp_addds = 0x00000030,
305 .grp_ddrmode_ctl = 0x00020000,
306 .grp_b0ds = 0x00000030,
307 .grp_ctlds = 0x00000030,
308 .grp_b1ds = 0x00000030,
309 .grp_ddrpke = 0x00000000,
310 .grp_ddrmode = 0x00020000,
311 .grp_ddr_type = 0x000c0000,
312};
313
314static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
315 .dram_dqm0 = 0x00000030,
316 .dram_dqm1 = 0x00000030,
317 .dram_ras = 0x00000030,
318 .dram_cas = 0x00000030,
319 .dram_odt0 = 0x00000030,
320 .dram_odt1 = 0x00000030,
321 .dram_sdba2 = 0x00000000,
322 .dram_sdclk_0 = 0x00000008,
323 .dram_sdqs0 = 0x00000038,
324 .dram_sdqs1 = 0x00000030,
325 .dram_reset = 0x00000030,
326};
327
328static struct mx6_mmdc_calibration mx6_mmcd_calib = {
329 .p0_mpwldectrl0 = 0x00070007,
330 .p0_mpdgctrl0 = 0x41490145,
331 .p0_mprddlctl = 0x40404546,
332 .p0_mpwrdlctl = 0x4040524D,
333};
334
335struct mx6_ddr_sysinfo ddr_sysinfo = {
336 .dsize = 0,
337 .cs_density = 20,
338 .ncs = 1,
339 .cs1_mirror = 0,
340 .rtt_wr = 2,
341 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
342 .walat = 1, /* Write additional latency */
343 .ralat = 5, /* Read additional latency */
344 .mif3_mode = 3, /* Command prediction working mode */
345 .bi_on = 1, /* Bank interleaving enabled */
346 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
347 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
348 .ddr_type = DDR_TYPE_DDR3,
349};
350
351static struct mx6_ddr3_cfg mem_ddr = {
352 .mem_speed = 800,
353 .density = 4,
354 .width = 16,
355 .banks = 8,
356 .rowaddr = 15,
357 .coladdr = 10,
358 .pagesz = 2,
359 .trcd = 1375,
360 .trcmin = 4875,
361 .trasmin = 3500,
362};
363
364static void ccgr_init(void)
365{
366 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
367
368 writel(0x00c03f3f, &ccm->CCGR0);
369 writel(0xfcffff00, &ccm->CCGR1);
370 writel(0x0cffffcc, &ccm->CCGR2);
371 writel(0x3f3c3030, &ccm->CCGR3);
372 writel(0xff00fffc, &ccm->CCGR4);
373 writel(0x033f30ff, &ccm->CCGR5);
374 writel(0x00c00fff, &ccm->CCGR6);
375}
376
377static void spl_dram_init(void)
378{
379 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
380 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
381}
382
383void board_init_f(ulong dummy)
384{
385 /* setup AIPS and disable watchdog */
386 arch_cpu_init();
387
388 ccgr_init();
389
390 /* iomux and setup of i2c */
391 board_early_init_f();
392
393 /* setup GP timer */
394 timer_init();
395
396 /* UART clocks enabled and gd valid - init serial console */
397 preloader_console_init();
398
399 /* DDR initialization */
400 spl_dram_init();
401
402 /* Clear the BSS. */
403 memset(__bss_start, 0, __bss_end - __bss_start);
404
405 /* load/boot image from boot device */
406 board_init_r(NULL, 0);
407}
408#endif /* CONFIG_SPL_BUILD */