1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2013 Freescale Semiconductor, Inc.
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
8 #include <asm/arch/clock.h>
9 #include <asm/arch/iomux.h>
10 #include <asm/arch/crm_regs.h>
11 #include <asm/arch/imx-regs.h>
12 #include <asm/arch/mx6-ddr.h>
13 #include <asm/arch/mx6-pins.h>
14 #include <asm/arch/sys_proto.h>
16 #include <asm/mach-imx/iomux-v3.h>
17 #include <asm/mach-imx/mxc_i2c.h>
19 #include <linux/sizes.h>
21 #include <fsl_esdhc_imx.h>
24 #include <power/pmic.h>
25 #include <power/pfuze100_pmic.h>
26 #include "../common/pfuze.h"
28 DECLARE_GLOBAL_DATA_PTR;
30 #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
31 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
32 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
34 #define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \
35 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
36 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
38 #define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
39 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
40 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
42 #define OTGID_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
43 PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW |\
44 PAD_CTL_DSE_80ohm | PAD_CTL_HYS | \
47 #define ETH_PHY_POWER IMX_GPIO_NR(4, 21)
51 gd->ram_size = imx_ddr_size();
56 static iomux_v3_cfg_t const uart1_pads[] = {
57 MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
58 MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
61 #ifdef CONFIG_SPL_BUILD
62 static iomux_v3_cfg_t const usdhc1_pads[] = {
64 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
65 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
66 MX6_PAD_SD1_DAT0__USDHC1_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
67 MX6_PAD_SD1_DAT1__USDHC1_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
68 MX6_PAD_SD1_DAT2__USDHC1_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
69 MX6_PAD_SD1_DAT3__USDHC1_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
70 MX6_PAD_SD1_DAT4__USDHC1_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
71 MX6_PAD_SD1_DAT5__USDHC1_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
72 MX6_PAD_SD1_DAT6__USDHC1_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
73 MX6_PAD_SD1_DAT7__USDHC1_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
76 MX6_PAD_KEY_ROW7__GPIO_4_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
79 static iomux_v3_cfg_t const usdhc2_pads[] = {
80 MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
81 MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
82 MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
83 MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
84 MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
85 MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
88 MX6_PAD_SD2_DAT7__GPIO_5_0 | MUX_PAD_CTRL(NO_PAD_CTRL),
91 static iomux_v3_cfg_t const usdhc3_pads[] = {
92 MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93 MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97 MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
100 MX6_PAD_REF_CLK_32K__GPIO_3_22 | MUX_PAD_CTRL(NO_PAD_CTRL),
104 static void setup_iomux_uart(void)
106 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
109 int board_mmc_get_env_dev(int devno)
114 #ifdef CONFIG_DM_PMIC_PFUZE100
115 int power_init_board(void)
119 u32 dev_id, rev_id, i;
121 u32 offset = PFUZE100_SW1CMODE;
123 ret = pmic_get("pfuze100@08", &dev);
130 dev_id = pmic_reg_read(dev, PFUZE100_DEVICEID);
131 rev_id = pmic_reg_read(dev, PFUZE100_REVID);
132 printf("PMIC: PFUZE100! DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
134 /* set SW1AB staby volatage 0.975V */
135 pmic_clrsetbits(dev, PFUZE100_SW1ABSTBY, 0x3f, 0x1b);
137 /* set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */
138 pmic_clrsetbits(dev, PFUZE100_SW1ABCONF, 0xc0, 0x40);
140 /* set SW1C staby volatage 0.975V */
141 pmic_clrsetbits(dev, PFUZE100_SW1CSTBY, 0x3f, 0x1b);
143 /* set SW1C/VDDSOC step ramp up time to from 16us to 4us/25mV */
144 pmic_clrsetbits(dev, PFUZE100_SW1CCONF, 0xc0, 0x40);
146 /* Init mode to APS_PFM */
147 pmic_reg_write(dev, PFUZE100_SW1ABMODE, APS_PFM);
149 for (i = 0; i < switch_num - 1; i++)
150 pmic_reg_write(dev, offset + i * SWITCH_SIZE, APS_PFM);
156 #ifdef CONFIG_FEC_MXC
158 static int setup_fec(void)
160 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
162 /* clear gpr1[14], gpr1[18:17] to select anatop clock */
163 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
165 return enable_fec_anatop_clock(0, ENET_50MHZ);
169 int board_early_init_f(void)
178 /* address of boot parameters */
179 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
181 #ifdef CONFIG_FEC_MXC
190 puts("Board: MX6SLEVK\n");
195 #ifdef CONFIG_SPL_BUILD
197 #include <linux/libfdt.h>
199 #define USDHC1_CD_GPIO IMX_GPIO_NR(4, 7)
200 #define USDHC2_CD_GPIO IMX_GPIO_NR(5, 0)
201 #define USDHC3_CD_GPIO IMX_GPIO_NR(3, 22)
203 static struct fsl_esdhc_cfg usdhc_cfg[3] = {
205 {USDHC2_BASE_ADDR, 0, 4},
206 {USDHC3_BASE_ADDR, 0, 4},
209 int board_mmc_getcd(struct mmc *mmc)
211 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
214 switch (cfg->esdhc_base) {
215 case USDHC1_BASE_ADDR:
216 gpio_request(USDHC1_CD_GPIO, "cd1_gpio");
217 ret = !gpio_get_value(USDHC1_CD_GPIO);
219 case USDHC2_BASE_ADDR:
220 gpio_request(USDHC2_CD_GPIO, "cd2_gpio");
221 ret = !gpio_get_value(USDHC2_CD_GPIO);
223 case USDHC3_BASE_ADDR:
224 gpio_request(USDHC3_CD_GPIO, "cd3_gpio");
225 ret = !gpio_get_value(USDHC3_CD_GPIO);
232 int board_mmc_init(bd_t *bis)
234 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
238 val = readl(&src_regs->sbmr1);
240 /* Boot from USDHC */
241 port = (val >> 11) & 0x3;
244 imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
245 ARRAY_SIZE(usdhc1_pads));
246 gpio_direction_input(USDHC1_CD_GPIO);
247 usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
248 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
251 imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
252 ARRAY_SIZE(usdhc2_pads));
253 gpio_direction_input(USDHC2_CD_GPIO);
254 usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
255 usdhc_cfg[0].max_bus_width = 4;
256 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
259 imx_iomux_v3_setup_multiple_pads(usdhc3_pads,
260 ARRAY_SIZE(usdhc3_pads));
261 gpio_direction_input(USDHC3_CD_GPIO);
262 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
263 usdhc_cfg[0].max_bus_width = 4;
264 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
268 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
269 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
272 const struct mx6sl_iomux_ddr_regs mx6_ddr_ioregs = {
273 .dram_sdqs0 = 0x00003030,
274 .dram_sdqs1 = 0x00003030,
275 .dram_sdqs2 = 0x00003030,
276 .dram_sdqs3 = 0x00003030,
277 .dram_dqm0 = 0x00000030,
278 .dram_dqm1 = 0x00000030,
279 .dram_dqm2 = 0x00000030,
280 .dram_dqm3 = 0x00000030,
281 .dram_cas = 0x00000030,
282 .dram_ras = 0x00000030,
283 .dram_sdclk_0 = 0x00000028,
284 .dram_reset = 0x00000030,
285 .dram_sdba2 = 0x00000000,
286 .dram_odt0 = 0x00000008,
287 .dram_odt1 = 0x00000008,
290 const struct mx6sl_iomux_grp_regs mx6_grp_ioregs = {
291 .grp_b0ds = 0x00000030,
292 .grp_b1ds = 0x00000030,
293 .grp_b2ds = 0x00000030,
294 .grp_b3ds = 0x00000030,
295 .grp_addds = 0x00000030,
296 .grp_ctlds = 0x00000030,
297 .grp_ddrmode_ctl = 0x00020000,
298 .grp_ddrpke = 0x00000000,
299 .grp_ddrmode = 0x00020000,
300 .grp_ddr_type = 0x00080000,
303 const struct mx6_mmdc_calibration mx6_mmcd_calib = {
304 .p0_mpdgctrl0 = 0x20000000,
305 .p0_mpdgctrl1 = 0x00000000,
306 .p0_mprddlctl = 0x4241444a,
307 .p0_mpwrdlctl = 0x3030312b,
308 .mpzqlp2ctl = 0x1b4700c7,
311 static struct mx6_lpddr2_cfg mem_ddr = {
324 static void ccgr_init(void)
326 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
328 writel(0xFFFFFFFF, &ccm->CCGR0);
329 writel(0xFFFFFFFF, &ccm->CCGR1);
330 writel(0xFFFFFFFF, &ccm->CCGR2);
331 writel(0xFFFFFFFF, &ccm->CCGR3);
332 writel(0xFFFFFFFF, &ccm->CCGR4);
333 writel(0xFFFFFFFF, &ccm->CCGR5);
334 writel(0xFFFFFFFF, &ccm->CCGR6);
336 writel(0x00260324, &ccm->cbcmr);
339 static void spl_dram_init(void)
341 struct mx6_ddr_sysinfo sysinfo = {
342 .dsize = mem_ddr.width / 32,
350 .rtt_wr = 0, /* LPDDR2 does not need rtt_wr rtt_nom */
352 .sde_to_rst = 0, /* LPDDR2 does not need this field */
353 .rst_to_cke = 0x10, /* JEDEC value for LPDDR2: 200us */
354 .ddr_type = DDR_TYPE_LPDDR2,
355 .refsel = 0, /* Refresh cycles at 64KHz */
356 .refr = 3, /* 4 refresh commands per refresh cycle */
358 mx6sl_dram_iocfg(32, &mx6_ddr_ioregs, &mx6_grp_ioregs);
359 mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr);
362 void board_init_f(ulong dummy)
364 /* setup AIPS and disable watchdog */
369 /* iomux and setup of i2c */
370 board_early_init_f();
375 /* UART clocks enabled and gd valid - init serial console */
376 preloader_console_init();
378 /* DDR initialization */
382 memset(__bss_start, 0, __bss_end - __bss_start);
384 /* load/boot image from boot device */
385 board_init_r(NULL, 0);