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