Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (C) 2018 Technexion Ltd. |
| 4 | * |
| 5 | * Author: Richard Hu <richard.hu@technexion.com> |
| 6 | */ |
| 7 | |
Joris Offouga | 525447f | 2019-04-04 14:00:55 +0200 | [diff] [blame] | 8 | #include <asm/arch/clock.h> |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 9 | #include <asm/arch/imx-regs.h> |
| 10 | #include <asm/arch/crm_regs.h> |
Joris Offouga | 525447f | 2019-04-04 14:00:55 +0200 | [diff] [blame] | 11 | #include <asm/arch/mx7-pins.h> |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 12 | #include <asm/arch/sys_proto.h> |
| 13 | #include <asm/arch-mx7/mx7-ddr.h> |
Joris Offouga | 525447f | 2019-04-04 14:00:55 +0200 | [diff] [blame] | 14 | #include <asm/mach-imx/iomux-v3.h> |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 15 | #include <asm/gpio.h> |
Joris Offouga | 525447f | 2019-04-04 14:00:55 +0200 | [diff] [blame] | 16 | #include <fsl_esdhc.h> |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 17 | #include <spl.h> |
| 18 | |
| 19 | #if defined(CONFIG_SPL_BUILD) |
Fabio Estevam | dbc3ba0 | 2018-06-29 15:19:14 -0300 | [diff] [blame] | 20 | |
| 21 | #ifdef CONFIG_SPL_OS_BOOT |
| 22 | int spl_start_uboot(void) |
| 23 | { |
| 24 | return 0; |
| 25 | } |
| 26 | #endif |
| 27 | |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 28 | static struct ddrc ddrc_regs_val = { |
| 29 | .mstr = 0x01040001, |
| 30 | .rfshtmg = 0x00400046, |
| 31 | .init1 = 0x00690000, |
| 32 | .init0 = 0x00020083, |
| 33 | .init3 = 0x09300004, |
| 34 | .init4 = 0x04080000, |
| 35 | .init5 = 0x00100004, |
| 36 | .rankctl = 0x0000033F, |
| 37 | .dramtmg0 = 0x09081109, |
| 38 | .dramtmg1 = 0x0007020d, |
| 39 | .dramtmg2 = 0x03040407, |
| 40 | .dramtmg3 = 0x00002006, |
| 41 | .dramtmg4 = 0x04020205, |
| 42 | .dramtmg5 = 0x03030202, |
| 43 | .dramtmg8 = 0x00000803, |
| 44 | .zqctl0 = 0x00800020, |
| 45 | .dfitmg0 = 0x02098204, |
| 46 | .dfitmg1 = 0x00030303, |
| 47 | .dfiupd0 = 0x80400003, |
| 48 | .dfiupd1 = 0x00100020, |
| 49 | .dfiupd2 = 0x80100004, |
| 50 | .addrmap4 = 0x00000F0F, |
| 51 | .odtcfg = 0x06000604, |
| 52 | .odtmap = 0x00000001, |
| 53 | .rfshtmg = 0x00400046, |
| 54 | .dramtmg0 = 0x09081109, |
| 55 | .addrmap0 = 0x0000001f, |
| 56 | .addrmap1 = 0x00080808, |
| 57 | .addrmap4 = 0x00000f0f, |
| 58 | .addrmap5 = 0x07070707, |
| 59 | .addrmap6 = 0x0f0f0707, |
| 60 | }; |
| 61 | |
| 62 | static struct ddrc_mp ddrc_mp_val = { |
| 63 | .pctrl_0 = 0x00000001, |
| 64 | }; |
| 65 | |
| 66 | static struct ddr_phy ddr_phy_regs_val = { |
| 67 | .phy_con0 = 0x17420f40, |
| 68 | .phy_con1 = 0x10210100, |
| 69 | .phy_con4 = 0x00060807, |
| 70 | .mdll_con0 = 0x1010007e, |
| 71 | .drvds_con0 = 0x00000d6e, |
| 72 | .cmd_sdll_con0 = 0x00000010, |
| 73 | .offset_lp_con0 = 0x0000000f, |
| 74 | .offset_rd_con0 = 0x08080808, |
| 75 | .offset_wr_con0 = 0x08080808, |
| 76 | }; |
| 77 | |
| 78 | static struct mx7_calibration calib_param = { |
| 79 | .num_val = 5, |
| 80 | .values = { |
| 81 | 0x0E407304, |
| 82 | 0x0E447304, |
| 83 | 0x0E447306, |
| 84 | 0x0E447304, |
| 85 | 0x0E447304, |
| 86 | }, |
| 87 | }; |
| 88 | |
| 89 | static void gpr_init(void) |
| 90 | { |
| 91 | struct iomuxc_gpr_base_regs *gpr_regs = |
| 92 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 93 | writel(0x4F400005, &gpr_regs->gpr[1]); |
| 94 | } |
| 95 | |
| 96 | static bool is_1g(void) |
| 97 | { |
| 98 | gpio_direction_input(IMX_GPIO_NR(1, 12)); |
| 99 | return !gpio_get_value(IMX_GPIO_NR(1, 12)); |
| 100 | } |
| 101 | |
| 102 | static void ddr_init(void) |
| 103 | { |
Fabio Estevam | 1dfd980 | 2018-06-29 15:19:16 -0300 | [diff] [blame] | 104 | if (is_1g()) |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 105 | ddrc_regs_val.addrmap6 = 0x0f070707; |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 106 | |
| 107 | mx7_dram_cfg(&ddrc_regs_val, &ddrc_mp_val, &ddr_phy_regs_val, |
| 108 | &calib_param); |
| 109 | } |
| 110 | |
| 111 | void board_init_f(ulong dummy) |
| 112 | { |
| 113 | arch_cpu_init(); |
| 114 | gpr_init(); |
| 115 | board_early_init_f(); |
| 116 | timer_init(); |
| 117 | preloader_console_init(); |
| 118 | ddr_init(); |
| 119 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 120 | board_init_r(NULL, 0); |
| 121 | } |
| 122 | |
| 123 | void reset_cpu(ulong addr) |
| 124 | { |
| 125 | } |
Joris Offouga | 525447f | 2019-04-04 14:00:55 +0200 | [diff] [blame] | 126 | |
| 127 | #define USDHC_PAD_CTRL (PAD_CTL_DSE_3P3V_32OHM | PAD_CTL_SRE_SLOW | \ |
| 128 | PAD_CTL_HYS | PAD_CTL_PUE | PAD_CTL_PUS_PU47KOHM) |
| 129 | |
| 130 | static iomux_v3_cfg_t const usdhc3_pads[] = { |
| 131 | MX7D_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 132 | MX7D_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 133 | MX7D_PAD_SD3_DATA0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 134 | MX7D_PAD_SD3_DATA1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 135 | MX7D_PAD_SD3_DATA2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 136 | MX7D_PAD_SD3_DATA3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 137 | MX7D_PAD_SD3_DATA4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 138 | MX7D_PAD_SD3_DATA5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 139 | MX7D_PAD_SD3_DATA6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 140 | MX7D_PAD_SD3_DATA7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 141 | MX7D_PAD_GPIO1_IO14__GPIO1_IO14 | MUX_PAD_CTRL(USDHC_PAD_CTRL), |
| 142 | }; |
| 143 | |
| 144 | static struct fsl_esdhc_cfg usdhc_cfg[1] = { |
| 145 | {USDHC3_BASE_ADDR}, |
| 146 | }; |
| 147 | |
| 148 | int board_mmc_getcd(struct mmc *mmc) |
| 149 | { |
| 150 | /* Assume uSDHC3 emmc is always present */ |
| 151 | return 1; |
| 152 | } |
| 153 | |
| 154 | int board_mmc_init(bd_t *bis) |
| 155 | { |
| 156 | imx_iomux_v3_setup_multiple_pads(usdhc3_pads, ARRAY_SIZE(usdhc3_pads)); |
| 157 | usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK); |
| 158 | return fsl_esdhc_initialize(bis, &usdhc_cfg[0]); |
| 159 | } |
Fabio Estevam | 6ed3981 | 2018-06-29 15:19:11 -0300 | [diff] [blame] | 160 | #endif |