Jagan Teki | e9dfa1e | 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 | 6788a7e | 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 | e9dfa1e | 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 | 6788a7e | 2017-02-24 15:32:59 +0530 | [diff] [blame] | 111 | #ifdef CONFIG_NAND_MXS |
| 112 | setup_gpmi_nand(); |
| 113 | #endif |
Jagan Teki | e9dfa1e | 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 | } |
| 208 | #endif /* CONFIG_FSL_ESDHC */ |
| 209 | |
| 210 | static struct mx6ul_iomux_grp_regs mx6_grp_ioregs = { |
| 211 | .grp_addds = 0x00000030, |
| 212 | .grp_ddrmode_ctl = 0x00020000, |
| 213 | .grp_b0ds = 0x00000030, |
| 214 | .grp_ctlds = 0x00000030, |
| 215 | .grp_b1ds = 0x00000030, |
| 216 | .grp_ddrpke = 0x00000000, |
| 217 | .grp_ddrmode = 0x00020000, |
| 218 | .grp_ddr_type = 0x000c0000, |
| 219 | }; |
| 220 | |
| 221 | static struct mx6ul_iomux_ddr_regs mx6_ddr_ioregs = { |
| 222 | .dram_dqm0 = 0x00000030, |
| 223 | .dram_dqm1 = 0x00000030, |
| 224 | .dram_ras = 0x00000030, |
| 225 | .dram_cas = 0x00000030, |
| 226 | .dram_odt0 = 0x00000030, |
| 227 | .dram_odt1 = 0x00000030, |
| 228 | .dram_sdba2 = 0x00000000, |
| 229 | .dram_sdclk_0 = 0x00000008, |
| 230 | .dram_sdqs0 = 0x00000038, |
| 231 | .dram_sdqs1 = 0x00000030, |
| 232 | .dram_reset = 0x00000030, |
| 233 | }; |
| 234 | |
| 235 | static struct mx6_mmdc_calibration mx6_mmcd_calib = { |
| 236 | .p0_mpwldectrl0 = 0x00070007, |
| 237 | .p0_mpdgctrl0 = 0x41490145, |
| 238 | .p0_mprddlctl = 0x40404546, |
| 239 | .p0_mpwrdlctl = 0x4040524D, |
| 240 | }; |
| 241 | |
| 242 | struct mx6_ddr_sysinfo ddr_sysinfo = { |
| 243 | .dsize = 0, |
| 244 | .cs_density = 20, |
| 245 | .ncs = 1, |
| 246 | .cs1_mirror = 0, |
| 247 | .rtt_wr = 2, |
| 248 | .rtt_nom = 1, /* RTT_Nom = RZQ/2 */ |
| 249 | .walat = 1, /* Write additional latency */ |
| 250 | .ralat = 5, /* Read additional latency */ |
| 251 | .mif3_mode = 3, /* Command prediction working mode */ |
| 252 | .bi_on = 1, /* Bank interleaving enabled */ |
| 253 | .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */ |
| 254 | .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */ |
| 255 | .ddr_type = DDR_TYPE_DDR3, |
| 256 | }; |
| 257 | |
| 258 | static struct mx6_ddr3_cfg mem_ddr = { |
| 259 | .mem_speed = 800, |
| 260 | .density = 4, |
| 261 | .width = 16, |
| 262 | .banks = 8, |
| 263 | .rowaddr = 15, |
| 264 | .coladdr = 10, |
| 265 | .pagesz = 2, |
| 266 | .trcd = 1375, |
| 267 | .trcmin = 4875, |
| 268 | .trasmin = 3500, |
| 269 | }; |
| 270 | |
| 271 | static void ccgr_init(void) |
| 272 | { |
| 273 | struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 274 | |
| 275 | writel(0x00c03f3f, &ccm->CCGR0); |
| 276 | writel(0xfcffff00, &ccm->CCGR1); |
| 277 | writel(0x0cffffcc, &ccm->CCGR2); |
| 278 | writel(0x3f3c3030, &ccm->CCGR3); |
| 279 | writel(0xff00fffc, &ccm->CCGR4); |
| 280 | writel(0x033f30ff, &ccm->CCGR5); |
| 281 | writel(0x00c00fff, &ccm->CCGR6); |
| 282 | } |
| 283 | |
| 284 | static void spl_dram_init(void) |
| 285 | { |
| 286 | mx6ul_dram_iocfg(mem_ddr.width, &mx6_ddr_ioregs, &mx6_grp_ioregs); |
| 287 | mx6_dram_cfg(&ddr_sysinfo, &mx6_mmcd_calib, &mem_ddr); |
| 288 | } |
| 289 | |
| 290 | void board_init_f(ulong dummy) |
| 291 | { |
| 292 | /* setup AIPS and disable watchdog */ |
| 293 | arch_cpu_init(); |
| 294 | |
| 295 | ccgr_init(); |
| 296 | |
| 297 | /* iomux and setup of i2c */ |
| 298 | board_early_init_f(); |
| 299 | |
| 300 | /* setup GP timer */ |
| 301 | timer_init(); |
| 302 | |
| 303 | /* UART clocks enabled and gd valid - init serial console */ |
| 304 | preloader_console_init(); |
| 305 | |
| 306 | /* DDR initialization */ |
| 307 | spl_dram_init(); |
| 308 | |
| 309 | /* Clear the BSS. */ |
| 310 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 311 | |
| 312 | /* load/boot image from boot device */ |
| 313 | board_init_r(NULL, 0); |
| 314 | } |
| 315 | #endif /* CONFIG_SPL_BUILD */ |