blob: 6607b046455059c6077af376fdeeaeb81b66a79d [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
Jagan Tekic5d86812017-05-07 02:43:14 +053023#include "../common/board.h"
24
Jagan Teki105bd892017-02-24 15:32:54 +053025DECLARE_GLOBAL_DATA_PTR;
26
Jagan Teki2e7aa952017-02-24 15:32:59 +053027#ifdef CONFIG_NAND_MXS
28
29#define GPMI_PAD_CTRL0 (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
30#define GPMI_PAD_CTRL1 (PAD_CTL_DSE_40ohm | PAD_CTL_SPEED_MED | \
31 PAD_CTL_SRE_FAST)
32#define GPMI_PAD_CTRL2 (GPMI_PAD_CTRL0 | GPMI_PAD_CTRL1)
33
34static iomux_v3_cfg_t const nand_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +053035 IOMUX_PADS(PAD_NAND_DATA00__RAWNAND_DATA00 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
36 IOMUX_PADS(PAD_NAND_DATA01__RAWNAND_DATA01 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
37 IOMUX_PADS(PAD_NAND_DATA02__RAWNAND_DATA02 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
38 IOMUX_PADS(PAD_NAND_DATA03__RAWNAND_DATA03 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
39 IOMUX_PADS(PAD_NAND_DATA04__RAWNAND_DATA04 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
40 IOMUX_PADS(PAD_NAND_DATA05__RAWNAND_DATA05 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
41 IOMUX_PADS(PAD_NAND_DATA06__RAWNAND_DATA06 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
42 IOMUX_PADS(PAD_NAND_DATA07__RAWNAND_DATA07 | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
43 IOMUX_PADS(PAD_NAND_CLE__RAWNAND_CLE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
44 IOMUX_PADS(PAD_NAND_ALE__RAWNAND_ALE | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
45 IOMUX_PADS(PAD_NAND_CE0_B__RAWNAND_CE0_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
46 IOMUX_PADS(PAD_NAND_RE_B__RAWNAND_RE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
47 IOMUX_PADS(PAD_NAND_WE_B__RAWNAND_WE_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
48 IOMUX_PADS(PAD_NAND_WP_B__RAWNAND_WP_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
49 IOMUX_PADS(PAD_NAND_READY_B__RAWNAND_READY_B | MUX_PAD_CTRL(GPMI_PAD_CTRL2)),
Jagan Teki2e7aa952017-02-24 15:32:59 +053050};
51
Jagan Tekic5d86812017-05-07 02:43:14 +053052void setup_gpmi_nand(void)
Jagan Teki2e7aa952017-02-24 15:32:59 +053053{
54 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
55
56 /* config gpmi nand iomux */
Jagan Teki9910e302017-05-07 02:43:11 +053057 SETUP_IOMUX_PADS(nand_pads);
Jagan Teki2e7aa952017-02-24 15:32:59 +053058
59 clrbits_le32(&mxc_ccm->CCGR4,
60 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
61 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
62 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
63 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
64 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
65
66 /*
67 * config gpmi and bch clock to 100 MHz
68 * bch/gpmi select PLL2 PFD2 400M
69 * 100M = 400M / 4
70 */
71 clrbits_le32(&mxc_ccm->cscmr1,
72 MXC_CCM_CSCMR1_BCH_CLK_SEL |
73 MXC_CCM_CSCMR1_GPMI_CLK_SEL);
74 clrsetbits_le32(&mxc_ccm->cscdr1,
75 MXC_CCM_CSCDR1_BCH_PODF_MASK |
76 MXC_CCM_CSCDR1_GPMI_PODF_MASK,
77 (3 << MXC_CCM_CSCDR1_BCH_PODF_OFFSET) |
78 (3 << MXC_CCM_CSCDR1_GPMI_PODF_OFFSET));
79
80 /* enable gpmi and bch clock gating */
81 setbits_le32(&mxc_ccm->CCGR4,
82 MXC_CCM_CCGR4_RAWNAND_U_BCH_INPUT_APB_MASK |
83 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_BCH_MASK |
84 MXC_CCM_CCGR4_RAWNAND_U_GPMI_BCH_INPUT_GPMI_IO_MASK |
85 MXC_CCM_CCGR4_RAWNAND_U_GPMI_INPUT_APB_MASK |
86 MXC_CCM_CCGR4_PL301_MX6QPER1_BCH_MASK);
87
88 /* enable apbh clock gating */
89 setbits_le32(&mxc_ccm->CCGR0, MXC_CCM_CCGR0_APBHDMA_MASK);
90}
91#endif /* CONFIG_NAND_MXS */
92
Jagan Teki74207f22017-02-24 15:45:19 +053093#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki4aa145b2017-02-24 15:45:20 +053094int board_mmc_get_env_dev(int devno)
95{
96 /* dev 0 for SD/eSD, dev 1 for MMC/eMMC */
97 return (devno == 0) ? 0 : 1;
98}
Jagan Teki74207f22017-02-24 15:45:19 +053099#endif
100
Jagan Tekidf235812017-02-24 15:45:18 +0530101int board_late_init(void)
102{
103 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
104 IMX6_BMODE_SHIFT) {
105 case IMX6_BMODE_SD:
106 case IMX6_BMODE_ESD:
107 case IMX6_BMODE_MMC:
108 case IMX6_BMODE_EMMC:
Jagan Teki74207f22017-02-24 15:45:19 +0530109#ifdef CONFIG_ENV_IS_IN_MMC
110 mmc_late_init();
111#endif
Jagan Tekidf235812017-02-24 15:45:18 +0530112 setenv("modeboot", "mmcboot");
113 break;
114 case IMX6_BMODE_NAND:
115 setenv("modeboot", "nandboot");
116 break;
117 default:
118 setenv("modeboot", "");
119 break;
120 }
121
Jagan Teki38b08b42017-05-07 02:43:04 +0530122 if (is_mx6ul()) {
123#ifdef CONFIG_ENV_IS_IN_MMC
124 setenv("fdt_file", "imx6ul-isiot-emmc.dtb");
125#else
126 setenv("fdt_file", "imx6ul-isiot-nand.dtb");
127#endif
128 }
129
Jagan Tekidf235812017-02-24 15:45:18 +0530130 return 0;
131}
132
Jagan Teki105bd892017-02-24 15:32:54 +0530133#ifdef CONFIG_SPL_BUILD
Jagan Teki105bd892017-02-24 15:32:54 +0530134#include <spl.h>
135
Jagan Teki105bd892017-02-24 15:32:54 +0530136/* MMC board initialization is needed till adding DM support in SPL */
137#if defined(CONFIG_FSL_ESDHC) && !defined(CONFIG_DM_MMC)
138#include <mmc.h>
139#include <fsl_esdhc.h>
140
141#define USDHC_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
142 PAD_CTL_PUS_22K_UP | PAD_CTL_SPEED_LOW | \
143 PAD_CTL_DSE_80ohm | PAD_CTL_SRE_FAST | PAD_CTL_HYS)
144
145static iomux_v3_cfg_t const usdhc1_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +0530146 IOMUX_PADS(PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
147 IOMUX_PADS(PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
148 IOMUX_PADS(PAD_SD1_DATA0__USDHC1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
149 IOMUX_PADS(PAD_SD1_DATA1__USDHC1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
150 IOMUX_PADS(PAD_SD1_DATA2__USDHC1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
151 IOMUX_PADS(PAD_SD1_DATA3__USDHC1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530152
153 /* VSELECT */
Jagan Teki9910e302017-05-07 02:43:11 +0530154 IOMUX_PADS(PAD_GPIO1_IO05__USDHC1_VSELECT | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530155 /* CD */
Jagan Teki9910e302017-05-07 02:43:11 +0530156 IOMUX_PADS(PAD_UART1_RTS_B__GPIO1_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530157 /* RST_B */
Jagan Teki9910e302017-05-07 02:43:11 +0530158 IOMUX_PADS(PAD_GPIO1_IO09__GPIO1_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL)),
Jagan Teki105bd892017-02-24 15:32:54 +0530159};
160
Jagan Teki60dd2d42017-02-24 15:45:17 +0530161static iomux_v3_cfg_t const usdhc2_pads[] = {
Jagan Teki9910e302017-05-07 02:43:11 +0530162 IOMUX_PADS(PAD_NAND_ALE__USDHC2_RESET_B | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
163 IOMUX_PADS(PAD_NAND_RE_B__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
164 IOMUX_PADS(PAD_NAND_WE_B__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
165 IOMUX_PADS(PAD_NAND_DATA00__USDHC2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
166 IOMUX_PADS(PAD_NAND_DATA01__USDHC2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
167 IOMUX_PADS(PAD_NAND_DATA02__USDHC2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
168 IOMUX_PADS(PAD_NAND_DATA03__USDHC2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
169 IOMUX_PADS(PAD_NAND_DATA04__USDHC2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
170 IOMUX_PADS(PAD_NAND_DATA05__USDHC2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Jagan Teki60dd2d42017-02-24 15:45:17 +0530171};
172
Jagan Teki105bd892017-02-24 15:32:54 +0530173#define USDHC1_CD_GPIO IMX_GPIO_NR(1, 19)
Jagan Teki60dd2d42017-02-24 15:45:17 +0530174#define USDHC2_CD_GPIO IMX_GPIO_NR(4, 5)
Jagan Teki105bd892017-02-24 15:32:54 +0530175
Jagan Teki60dd2d42017-02-24 15:45:17 +0530176struct fsl_esdhc_cfg usdhc_cfg[2] = {
Jagan Teki105bd892017-02-24 15:32:54 +0530177 {USDHC1_BASE_ADDR, 0, 4},
Jagan Teki60dd2d42017-02-24 15:45:17 +0530178 {USDHC2_BASE_ADDR, 0, 8},
Jagan Teki105bd892017-02-24 15:32:54 +0530179};
180
181int board_mmc_getcd(struct mmc *mmc)
182{
183 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
184 int ret = 0;
185
186 switch (cfg->esdhc_base) {
187 case USDHC1_BASE_ADDR:
188 ret = !gpio_get_value(USDHC1_CD_GPIO);
189 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530190 case USDHC2_BASE_ADDR:
191 ret = !gpio_get_value(USDHC2_CD_GPIO);
192 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530193 }
194
195 return ret;
196}
197
198int board_mmc_init(bd_t *bis)
199{
200 int i, ret;
201
202 /*
203 * According to the board_mmc_init() the following map is done:
204 * (U-boot device node) (Physical Port)
205 * mmc0 USDHC1
Jagan Teki60dd2d42017-02-24 15:45:17 +0530206 * mmc1 USDHC2
Jagan Teki105bd892017-02-24 15:32:54 +0530207 */
208 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
209 switch (i) {
210 case 0:
Jagan Teki9910e302017-05-07 02:43:11 +0530211 SETUP_IOMUX_PADS(usdhc1_pads);
Jagan Teki105bd892017-02-24 15:32:54 +0530212 gpio_direction_input(USDHC1_CD_GPIO);
213 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
214 break;
Jagan Teki60dd2d42017-02-24 15:45:17 +0530215 case 1:
Jagan Teki9910e302017-05-07 02:43:11 +0530216 SETUP_IOMUX_PADS(usdhc2_pads);
Jagan Teki60dd2d42017-02-24 15:45:17 +0530217 gpio_direction_input(USDHC2_CD_GPIO);
218 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
219 break;
Jagan Teki105bd892017-02-24 15:32:54 +0530220 default:
221 printf("Warning - USDHC%d controller not supporting\n",
222 i + 1);
223 return 0;
224 }
225
226 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
227 if (ret) {
228 printf("Warning: failed to initialize mmc dev %d\n", i);
229 return ret;
230 }
231 }
232
233 return 0;
234}
Jagan Teki931e84e2017-02-24 15:45:16 +0530235
236#ifdef CONFIG_ENV_IS_IN_MMC
237void board_boot_order(u32 *spl_boot_list)
238{
239 u32 bmode = imx6_src_get_boot_mode();
240 u8 boot_dev = BOOT_DEVICE_MMC1;
241
242 switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
243 case IMX6_BMODE_SD:
244 case IMX6_BMODE_ESD:
245 /* SD/eSD - BOOT_DEVICE_MMC1 */
246 break;
247 case IMX6_BMODE_MMC:
248 case IMX6_BMODE_EMMC:
249 /* MMC/eMMC */
250 boot_dev = BOOT_DEVICE_MMC2;
251 break;
252 default:
253 /* Default - BOOT_DEVICE_MMC1 */
254 printf("Wrong board boot order\n");
255 break;
256 }
257
258 spl_boot_list[0] = boot_dev;
259}
260#endif
Jagan Teki105bd892017-02-24 15:32:54 +0530261#endif /* CONFIG_FSL_ESDHC */
Jagan Teki105bd892017-02-24 15:32:54 +0530262#endif /* CONFIG_SPL_BUILD */