Jagan Teki | 105bd89 | 2017-02-24 15:32:54 +0530 | [diff] [blame] | 1 | /* |
| 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 | |
| 22 | DECLARE_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 | |
| 28 | static 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 | |
| 33 | int 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 Teki | 2e7aa95 | 2017-02-24 15:32:59 +0530 | [diff] [blame] | 40 | #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 | |
| 47 | static 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 | |
| 65 | static 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 Teki | 105bd89 | 2017-02-24 15:32:54 +0530 | [diff] [blame] | 106 | int board_init(void) |
| 107 | { |
| 108 | /* Address of boot parameters */ |
| 109 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 110 | |
Jagan Teki | 2e7aa95 | 2017-02-24 15:32:59 +0530 | [diff] [blame] | 111 | #ifdef CONFIG_NAND_MXS |
| 112 | setup_gpmi_nand(); |
| 113 | #endif |
Jagan Teki | 105bd89 | 2017-02-24 15:32:54 +0530 | [diff] [blame] | 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int dram_init(void) |
| 118 | { |
| 119 | gd->ram_size = imx_ddr_size(); |
| 120 | |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | #ifdef CONFIG_SPL_BUILD |
| 125 | #include <libfdt.h> |
| 126 | #include <spl.h> |
| 127 | |
| 128 | #include <asm/arch/crm_regs.h> |
| 129 | #include <asm/arch/mx6-ddr.h> |
| 130 | |
| 131 | /* MMC board initialization is needed till adding DM support in SPL */ |
| 132 | #if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC) |
| 133 | #include <mmc.h> |
| 134 | #include <fsl_esdhc.h> |
| 135 | |
| 136 | #define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \ |
| 137 | PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \ |
| 138 | PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS) |
| 139 | |
| 140 | static iomux_v3_cfg_t const usdhc1_pads[] = { |
| 141 | MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 142 | MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 143 | MX6_PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 144 | MX6_PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 145 | MX6_PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 146 | MX6_PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 147 | |
| 148 | /* VSELECT */ |
| 149 | MX6_PAD_GPIO1_IO05__USDHC1_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 150 | /* CD */ |
| 151 | MX6_PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 152 | /* RST_B */ |
| 153 | MX6_PAD_GPIO1_IO09__GPIO1_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL), |
| 154 | }; |
| 155 | |
| 156 | #define USDHC1_CD_GPIO IMX_GPIO_NR(1, 19) |
| 157 | |
| 158 | struct fsl_esdhc_cfg usdhc_cfg[1] = { |
| 159 | {USDHC1_BASE_ADDR, 0, 4}, |
| 160 | }; |
| 161 | |
| 162 | int board_mmc_getcd(struct mmc *mmc) |
| 163 | { |
| 164 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
| 165 | int ret = 0; |
| 166 | |
| 167 | switch (cfg->esdhc_base) { |
| 168 | case USDHC1_BASE_ADDR: |
| 169 | ret = !gpio_get_value(USDHC1_CD_GPIO); |
| 170 | break; |
| 171 | } |
| 172 | |
| 173 | return ret; |
| 174 | } |
| 175 | |
| 176 | int board_mmc_init(bd_t *bis) |
| 177 | { |
| 178 | int i, ret; |
| 179 | |
| 180 | /* |
| 181 | * According to the board_mmc_init() the following map is done: |
| 182 | * (U-boot device node) (Physical Port) |
| 183 | * mmc0 USDHC1 |
| 184 | */ |
| 185 | for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) { |
| 186 | switch (i) { |
| 187 | case 0: |
| 188 | imx_iomux_v3_setup_multiple_pads( |
| 189 | usdhc1_pads, ARRAY_SIZE(usdhc1_pads)); |
| 190 | gpio_direction_input(USDHC1_CD_GPIO); |
| 191 | usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 192 | break; |
| 193 | default: |
| 194 | printf("Warning - USDHC%d controller not supporting\n", |
| 195 | i + 1); |
| 196 | return 0; |
| 197 | } |
| 198 | |
| 199 | ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]); |
| 200 | if (ret) { |
| 201 | printf("Warning: failed to initialize mmc dev %d\n", i); |
| 202 | return ret; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | return 0; |
| 207 | } |
Jagan Teki | 931e84e | 2017-02-24 15:45:16 +0530 | [diff] [blame^] | 208 | |
| 209 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 210 | void board_boot_order(u32 *spl_boot_list) |
| 211 | { |
| 212 | u32 bmode = imx6_src_get_boot_mode(); |
| 213 | u8 boot_dev = BOOT_DEVICE_MMC1; |
| 214 | |
| 215 | switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) { |
| 216 | case IMX6_BMODE_SD: |
| 217 | case IMX6_BMODE_ESD: |
| 218 | /* SD/eSD - BOOT_DEVICE_MMC1 */ |
| 219 | break; |
| 220 | case IMX6_BMODE_MMC: |
| 221 | case IMX6_BMODE_EMMC: |
| 222 | /* MMC/eMMC */ |
| 223 | boot_dev = BOOT_DEVICE_MMC2; |
| 224 | break; |
| 225 | default: |
| 226 | /* Default - BOOT_DEVICE_MMC1 */ |
| 227 | printf("Wrong board boot order\n"); |
| 228 | break; |
| 229 | } |
| 230 | |
| 231 | spl_boot_list[0] = boot_dev; |
| 232 | } |
| 233 | #endif |
Jagan Teki | 105bd89 | 2017-02-24 15:32:54 +0530 | [diff] [blame] | 234 | #endif /* CONFIG_FSL_ESDHC */ |
| 235 | |
| 236 | static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = { |
| 237 | .grp_addds = 0x00000030, |
| 238 | .grp_ddrmode_ctl = 0x00020000, |
| 239 | .grp_b0ds = 0x00000030, |
| 240 | .grp_ctlds = 0x00000030, |
| 241 | .grp_b1ds = 0x00000030, |
| 242 | .grp_ddrpke = 0x00000000, |
| 243 | .grp_ddrmode = 0x00020000, |
| 244 | .grp_ddr_type = 0x000c0000, |
| 245 | }; |
| 246 | |
| 247 | static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = { |
| 248 | .dram_dqm0 = 0x00000030, |
| 249 | .dram_dqm1 = 0x00000030, |
| 250 | .dram_ras = 0x00000030, |
| 251 | .dram_cas = 0x00000030, |
| 252 | .dram_odt0 = 0x00000030, |
| 253 | .dram_odt1 = 0x00000030, |
| 254 | .dram_sdba2 = 0x00000000, |
| 255 | .dram_sdclk_0 = 0x00000008, |
| 256 | .dram_sdqs0 = 0x00000038, |
| 257 | .dram_sdqs1 = 0x00000030, |
| 258 | .dram_reset = 0x00000030, |
| 259 | }; |
| 260 | |
| 261 | static struct mx6_mmdc_calibration mx6_mmcd_calib = { |
| 262 | .p0_mpwldectrl0 = 0x00070007, |
| 263 | .p0_mpdgctrl0 = 0x41490145, |
| 264 | .p0_mprddlctl = 0x40404546, |
| 265 | .p0_mpwrdlctl = 0x4040524D, |
| 266 | }; |
| 267 | |
| 268 | struct mx6_ddr_sysinfo ddr_sysinfo = { |
| 269 | .dsize = 0, |
| 270 | .cs_density = 20, |
| 271 | .ncs = 1, |
| 272 | .cs1_mirror = 0, |
| 273 | .rtt_wr = 2, |
| 274 | .rtt_nom = 1, /* RTT_Nom = RZQ/2 */ |
| 275 | .walat = 1, /* Write additional latency */ |
| 276 | .ralat = 5, /* Read additional latency */ |
| 277 | .mif3_mode = 3, /* Command prediction working mode */ |
| 278 | .bi_on = 1, /* Bank interleaving enabled */ |
| 279 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 280 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
| 281 | .ddr_type = DDR_TYPE_DDR3, |
| 282 | }; |
| 283 | |
| 284 | static struct mx6_ddr3_cfg mem_ddr = { |
| 285 | .mem_speed = 800, |
| 286 | .density = 4, |
| 287 | .width = 16, |
| 288 | .banks = 8, |
| 289 | .rowaddr = 15, |
| 290 | .coladdr = 10, |
| 291 | .pagesz = 2, |
| 292 | .trcd = 1375, |
| 293 | .trcmin = 4875, |
| 294 | .trasmin = 3500, |
| 295 | }; |
| 296 | |
| 297 | static void ccgr_init(void) |
| 298 | { |
| 299 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 300 | |
| 301 | writel(0x00c03f3f, &ccm->CCGR0); |
| 302 | writel(0xfcffff00, &ccm->CCGR1); |
| 303 | writel(0x0cffffcc, &ccm->CCGR2); |
| 304 | writel(0x3f3c3030, &ccm->CCGR3); |
| 305 | writel(0xff00fffc, &ccm->CCGR4); |
| 306 | writel(0x033f30ff, &ccm->CCGR5); |
| 307 | writel(0x00c00fff, &ccm->CCGR6); |
| 308 | } |
| 309 | |
| 310 | static void spl_dram_init(void) |
| 311 | { |
| 312 | mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs); |
| 313 | mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr); |
| 314 | } |
| 315 | |
| 316 | void board_init_f(ulong dummy) |
| 317 | { |
| 318 | /* setup AIPS and disable watchdog */ |
| 319 | arch_cpu_init(); |
| 320 | |
| 321 | ccgr_init(); |
| 322 | |
| 323 | /* iomux and setup of i2c */ |
| 324 | board_early_init_f(); |
| 325 | |
| 326 | /* setup GP timer */ |
| 327 | timer_init(); |
| 328 | |
| 329 | /* UART clocks enabled and gd valid - init serial console */ |
| 330 | preloader_console_init(); |
| 331 | |
| 332 | /* DDR initialization */ |
| 333 | spl_dram_init(); |
| 334 | |
| 335 | /* Clear the BSS. */ |
| 336 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 337 | |
| 338 | /* load/boot image from boot device */ |
| 339 | board_init_r(NULL, 0); |
| 340 | } |
| 341 | #endif /* CONFIG_SPL_BUILD */ |