blob: d6a63d28950ac4ab59ab4d9d3c253e3a295c31f1 [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
Jagan Teki2e7aa952017-02-24 15:32:59 +053025#ifdef CONFIG_NAND_MXS
26
27#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
28#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
29 PAD_CTL_SRE_FAST)
30#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
31
32static iomux_v3_cfg_t const nand_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +053033 IOMUX_PADS(PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
34 IOMUX_PADS(PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
35 IOMUX_PADS(PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
36 IOMUX_PADS(PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
37 IOMUX_PADS(PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
38 IOMUX_PADS(PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
39 IOMUX_PADS(PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
40 IOMUX_PADS(PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
41 IOMUX_PADS(PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
42 IOMUX_PADS(PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
43 IOMUX_PADS(PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
44 IOMUX_PADS(PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
45 IOMUX_PADS(PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
46 IOMUX_PADS(PAD_NAND_WP_B__RAWNAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
47 IOMUX_PADS(PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
Jagan Teki2e7aa952017-02-24 15:32:59 +053048};
49
50static void setup_gpmi_nand(void)
51{
52 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
53
54 /* config gpmi nand iomux */
Jagan Teki9910e302017-05-07 02:43:11 +053055 SETUP_IOMUX_PADS(nand_pads);
Jagan Teki2e7aa952017-02-24 15:32:59 +053056
57 clrbits_le32(&mxc_ccm->CCGR4,
58 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
59 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
60 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
61 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
62 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
63
64 /*
65 * config gpmi and bch clock to 100 MHz
66 * bch/gpmi select PLL2 PFD2 400M
67 * 100M = 400M / 4
68 */
69 clrbits_le32(&mxc_ccm->cscmr1,
70 MXC_CCM_CSCMR1_BCH_CLK_SEL |
71 MXC_CCM_CSCMR1_GPMI_CLK_SEL);
72 clrsetbits_le32(&mxc_ccm->cscdr1,
73 MXC_CCM_CSCDR1_BCH_PODF_MASK |
74 MXC_CCM_CSCDR1_GPMI_PODF_MASK,
75 (3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
76 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
77
78 /* enable gpmi and bch clock gating */
79 setbits_le32(&mxc_ccm->CCGR4,
80 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
81 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
82 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
83 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
84 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
85
86 /* enable apbh clock gating */
87 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
88}
89#endif /* CONFIG_NAND_MXS */
90
Jagan Teki74207f22017-02-24 15:45:19 +053091#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki4aa145b2017-02-24 15:45:20 +053092int board_mmc_get_env_dev(int devno)
93{
94 /* dev 0 for SD/eSD, dev 1 for MMC/eMMC */
95 return (devno == 0) ? 0 : 1;
96}
97
Jagan Teki74207f22017-02-24 15:45:19 +053098static void mmc_late_init(void)
99{
100 char cmd[32];
101 char mmcblk[32];
102 u32 dev_no = mmc_get_env_dev();
103
104 setenv_ulong("mmcdev", dev_no);
105
106 /* Set mmcblk env */
107 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
108 setenv("mmcroot", mmcblk);
109
110 sprintf(cmd, "mmc dev %d", dev_no);
111 run_command(cmd, 0);
112}
113#endif
114
Jagan Tekidf235812017-02-24 15:45:18 +0530115int board_late_init(void)
116{
117 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
118 IMX6_BMODE_SHIFT) {
119 case IMX6_BMODE_SD:
120 case IMX6_BMODE_ESD:
121 case IMX6_BMODE_MMC:
122 case IMX6_BMODE_EMMC:
Jagan Teki74207f22017-02-24 15:45:19 +0530123#ifdef CONFIG_ENV_IS_IN_MMC
124 mmc_late_init();
125#endif
Jagan Tekidf235812017-02-24 15:45:18 +0530126 setenv("modeboot", "mmcboot");
127 break;
128 case IMX6_BMODE_NAND:
129 setenv("modeboot", "nandboot");
130 break;
131 default:
132 setenv("modeboot", "");
133 break;
134 }
135
Jagan Teki38b08b42017-05-07 02:43:04 +0530136 if (is_mx6ul()) {
137#ifdef CONFIG_ENV_IS_IN_MMC
138 setenv("fdt_file", "imx6ul-isiot-emmc.dtb");
139#else
140 setenv("fdt_file", "imx6ul-isiot-nand.dtb");
141#endif
142 }
143
Jagan Tekidf235812017-02-24 15:45:18 +0530144 return 0;
145}
146
Jagan Teki105bd892017-02-24 15:32:54 +0530147int board_init(void)
148{
149 /* Address of boot parameters */
150 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
151
Jagan Teki2e7aa952017-02-24 15:32:59 +0530152#ifdef CONFIG_NAND_MXS
153 setup_gpmi_nand();
154#endif
Jagan Teki105bd892017-02-24 15:32:54 +0530155 return 0;
156}
157
158int dram_init(void)
159{
160 gd->ram_size = imx_ddr_size();
161
162 return 0;
163}
164
165#ifdef CONFIG_SPL_BUILD
166#include <libfdt.h>
167#include <spl.h>
168
169#include <asm/arch/crm_regs.h>
170#include <asm/arch/mx6-ddr.h>
171
Jagan Teki85c95b72017-05-07 02:43:06 +0530172#define UART_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
173 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
174 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
175
176static iomux_v3_cfg_t const uart1_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +0530177 IOMUX_PADS(PAD_UART1_TX_DATA__UART1_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL)),
178 IOMUX_PADS(PAD_UART1_RX_DATA__UART1_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL)),
Jagan Teki85c95b72017-05-07 02:43:06 +0530179};
180
Jagan Teki105bd892017-02-24 15:32:54 +0530181/* MMC board initialization is needed till adding DM support in SPL */
182#if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC)
183#include <mmc.h>
184#include <fsl_esdhc.h>
185
186#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
187 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
188 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
189
190static iomux_v3_cfg_t const usdhc1_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +0530191 IOMUX_PADS(PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
192 IOMUX_PADS(PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
193 IOMUX_PADS(PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
194 IOMUX_PADS(PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
195 IOMUX_PADS(PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
196 IOMUX_PADS(PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530197
198 /* VSELECT */
Jagan Teki9910e302017-05-07 02:43:11 +0530199 IOMUX_PADS(PAD_GPIO1_IO05__USDHC1_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530200 /* CD */
Jagan Teki9910e302017-05-07 02:43:11 +0530201 IOMUX_PADS(PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530202 /* RST_B */
Jagan Teki9910e302017-05-07 02:43:11 +0530203 IOMUX_PADS(PAD_GPIO1_IO09__GPIO1_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530204};
205
Jagan Teki60dd2d42017-02-24 15:45:17 +0530206static iomux_v3_cfg_t const usdhc2_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +0530207 IOMUX_PADS(PAD_NAND_ALE__USDHC2_RESET_B | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
208 IOMUX_PADS(PAD_NAND_RE_B__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
209 IOMUX_PADS(PAD_NAND_WE_B__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
210 IOMUX_PADS(PAD_NAND_DATA00__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
211 IOMUX_PADS(PAD_NAND_DATA01__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
212 IOMUX_PADS(PAD_NAND_DATA02__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
213 IOMUX_PADS(PAD_NAND_DATA03__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
214 IOMUX_PADS(PAD_NAND_DATA04__USDHC2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
215 IOMUX_PADS(PAD_NAND_DATA05__USDHC2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki60dd2d42017-02-24 15:45:17 +0530216};
217
Jagan Teki105bd892017-02-24 15:32:54 +0530218#define USDHC1_CD_GPIO IMX_GPIO_NR(1, 19)
Jagan Teki60dd2d42017-02-24 15:45:17 +0530219#define USDHC2_CD_GPIO IMX_GPIO_NR(4, 5)
Jagan Teki105bd892017-02-24 15:32:54 +0530220
Jagan Teki60dd2d42017-02-24 15:45:17 +0530221struct fsl_esdhc_cfg usdhc_cfg[2] = {
Jagan Teki105bd892017-02-24 15:32:54 +0530222 {USDHC1_BASE_ADDR, 0, 4},
Jagan Teki60dd2d42017-02-24 15:45:17 +0530223 {USDHC2_BASE_ADDR, 0, 8},
Jagan Teki105bd892017-02-24 15:32:54 +0530224};
225
226int board_mmc_getcd(struct mmc *mmc)
227{
228 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
229 int ret = 0;
230
231 switch (cfg->esdhc_base) {
232 case USDHC1_BASE_ADDR:
233 ret = !gpio_get_value(USDHC1_CD_GPIO);
234 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530235 case USDHC2_BASE_ADDR:
236 ret = !gpio_get_value(USDHC2_CD_GPIO);
237 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530238 }
239
240 return ret;
241}
242
243int board_mmc_init(bd_t *bis)
244{
245 int i, ret;
246
247 /*
248 * According to the board_mmc_init() the following map is done:
249 * (U-boot device node) (Physical Port)
250 * mmc0 USDHC1
Jagan Teki60dd2d42017-02-24 15:45:17 +0530251 * mmc1 USDHC2
Jagan Teki105bd892017-02-24 15:32:54 +0530252 */
253 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
254 switch (i) {
255 case 0:
Jagan Teki9910e302017-05-07 02:43:11 +0530256 SETUP_IOMUX_PADS(usdhc1_pads);
Jagan Teki105bd892017-02-24 15:32:54 +0530257 gpio_direction_input(USDHC1_CD_GPIO);
258 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
259 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530260 case 1:
Jagan Teki9910e302017-05-07 02:43:11 +0530261 SETUP_IOMUX_PADS(usdhc2_pads);
Jagan Teki60dd2d42017-02-24 15:45:17 +0530262 gpio_direction_input(USDHC2_CD_GPIO);
263 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
264 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530265 default:
266 printf("Warning - USDHC%d controller not supporting\n",
267 i + 1);
268 return 0;
269 }
270
271 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
272 if (ret) {
273 printf("Warning: failed to initialize mmc dev %d\n", i);
274 return ret;
275 }
276 }
277
278 return 0;
279}
Jagan Teki931e84e2017-02-24 15:45:16 +0530280
281#ifdef CONFIG_ENV_IS_IN_MMC
282void board_boot_order(u32 *spl_boot_list)
283{
284 u32 bmode = imx6_src_get_boot_mode();
285 u8 boot_dev = BOOT_DEVICE_MMC1;
286
287 switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
288 case IMX6_BMODE_SD:
289 case IMX6_BMODE_ESD:
290 /* SD/eSD - BOOT_DEVICE_MMC1 */
291 break;
292 case IMX6_BMODE_MMC:
293 case IMX6_BMODE_EMMC:
294 /* MMC/eMMC */
295 boot_dev = BOOT_DEVICE_MMC2;
296 break;
297 default:
298 /* Default - BOOT_DEVICE_MMC1 */
299 printf("Wrong board boot order\n");
300 break;
301 }
302
303 spl_boot_list[0] = boot_dev;
304}
305#endif
Jagan Teki105bd892017-02-24 15:32:54 +0530306#endif /* CONFIG_FSL_ESDHC */
307
308static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = {
309 .grp_addds = 0x00000030,
310 .grp_ddrmode_ctl = 0x00020000,
311 .grp_b0ds = 0x00000030,
312 .grp_ctlds = 0x00000030,
313 .grp_b1ds = 0x00000030,
314 .grp_ddrpke = 0x00000000,
315 .grp_ddrmode = 0x00020000,
316 .grp_ddr_type = 0x000c0000,
317};
318
319static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = {
320 .dram_dqm0 = 0x00000030,
321 .dram_dqm1 = 0x00000030,
322 .dram_ras = 0x00000030,
323 .dram_cas = 0x00000030,
324 .dram_odt0 = 0x00000030,
325 .dram_odt1 = 0x00000030,
326 .dram_sdba2 = 0x00000000,
327 .dram_sdclk_0 = 0x00000008,
328 .dram_sdqs0 = 0x00000038,
329 .dram_sdqs1 = 0x00000030,
330 .dram_reset = 0x00000030,
331};
332
333static struct mx6_mmdc_calibration mx6_mmcd_calib = {
334 .p0_mpwldectrl0 = 0x00070007,
335 .p0_mpdgctrl0 = 0x41490145,
336 .p0_mprddlctl = 0x40404546,
337 .p0_mpwrdlctl = 0x4040524D,
338};
339
340struct mx6_ddr_sysinfo ddr_sysinfo = {
341 .dsize = 0,
342 .cs_density = 20,
343 .ncs = 1,
344 .cs1_mirror = 0,
345 .rtt_wr = 2,
346 .rtt_nom = 1, /* RTT_Nom = RZQ/2 */
347 .walat = 1, /* Write additional latency */
348 .ralat = 5, /* Read additional latency */
349 .mif3_mode = 3, /* Command prediction working mode */
350 .bi_on = 1, /* Bank interleaving enabled */
351 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
352 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
353 .ddr_type = DDR_TYPE_DDR3,
354};
355
356static struct mx6_ddr3_cfg mem_ddr = {
357 .mem_speed = 800,
358 .density = 4,
359 .width = 16,
360 .banks = 8,
361 .rowaddr = 15,
362 .coladdr = 10,
363 .pagesz = 2,
364 .trcd = 1375,
365 .trcmin = 4875,
366 .trasmin = 3500,
367};
368
369static void ccgr_init(void)
370{
371 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
372
373 writel(0x00c03f3f, &ccm->CCGR0);
374 writel(0xfcffff00, &ccm->CCGR1);
375 writel(0x0cffffcc, &ccm->CCGR2);
376 writel(0x3f3c3030, &ccm->CCGR3);
377 writel(0xff00fffc, &ccm->CCGR4);
378 writel(0x033f30ff, &ccm->CCGR5);
379 writel(0x00c00fff, &ccm->CCGR6);
380}
381
382static void spl_dram_init(void)
383{
384 mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs);
385 mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr);
386}
387
388void board_init_f(ulong dummy)
389{
390 /* setup AIPS and disable watchdog */
391 arch_cpu_init();
392
393 ccgr_init();
394
395 /* iomux and setup of i2c */
Jagan Teki9910e302017-05-07 02:43:11 +0530396 SETUP_IOMUX_PADS(uart1_pads);
Jagan Teki105bd892017-02-24 15:32:54 +0530397
398 /* setup GP timer */
399 timer_init();
400
401 /* UART clocks enabled and gd valid - init serial console */
402 preloader_console_init();
403
404 /* DDR initialization */
405 spl_dram_init();
406
407 /* Clear the BSS. */
408 memset(__bss_start, 0, __bss_end - __bss_start);
409
410 /* load/boot image from boot device */
411 board_init_r(NULL, 0);
412}
413#endif /* CONFIG_SPL_BUILD */