1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
257ca432fSFabio Estevam /*
357ca432fSFabio Estevam * Copyright (C) 2013 Freescale Semiconductor, Inc.
457ca432fSFabio Estevam *
557ca432fSFabio Estevam * Author: Fabio Estevam <fabio.estevam@freescale.com>
657ca432fSFabio Estevam */
757ca432fSFabio Estevam
857ca432fSFabio Estevam #include <asm/arch/clock.h>
957ca432fSFabio Estevam #include <asm/arch/iomux.h>
10e7d3b21bSPeng Fan #include <asm/arch/crm_regs.h>
1157ca432fSFabio Estevam #include <asm/arch/imx-regs.h>
12e7d3b21bSPeng Fan #include <asm/arch/mx6-ddr.h>
1357ca432fSFabio Estevam #include <asm/arch/mx6-pins.h>
1457ca432fSFabio Estevam #include <asm/arch/sys_proto.h>
1557ca432fSFabio Estevam #include <asm/gpio.h>
16552a848eSStefano Babic #include <asm/mach-imx/iomux-v3.h>
17552a848eSStefano Babic #include <asm/mach-imx/mxc_i2c.h>
18552a848eSStefano Babic #include <asm/mach-imx/spi.h>
1957ca432fSFabio Estevam #include <asm/io.h>
201ace4022SAlexey Brodkin #include <linux/sizes.h>
2157ca432fSFabio Estevam #include <common.h>
2257ca432fSFabio Estevam #include <fsl_esdhc.h>
23af38bf6bSPeng Fan #include <i2c.h>
2457ca432fSFabio Estevam #include <mmc.h>
2531f07964SFabio Estevam #include <netdev.h>
26af38bf6bSPeng Fan #include <power/pmic.h>
27af38bf6bSPeng Fan #include <power/pfuze100_pmic.h>
28af38bf6bSPeng Fan #include "../common/pfuze.h"
2957ca432fSFabio Estevam
3057ca432fSFabio Estevam DECLARE_GLOBAL_DATA_PTR;
3157ca432fSFabio Estevam
327e2173cfSBenoît Thébaudeau #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
337e2173cfSBenoît Thébaudeau PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
347e2173cfSBenoît Thébaudeau PAD_CTL_SRE_FAST | PAD_CTL_HYS)
3557ca432fSFabio Estevam
367e2173cfSBenoît Thébaudeau #define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \
377e2173cfSBenoît Thébaudeau PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
387e2173cfSBenoît Thébaudeau PAD_CTL_SRE_FAST | PAD_CTL_HYS)
3957ca432fSFabio Estevam
4031f07964SFabio Estevam #define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
4131f07964SFabio Estevam PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
4231f07964SFabio Estevam PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
4331f07964SFabio Estevam
44694c3bc1SFabio Estevam #define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
45694c3bc1SFabio Estevam PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
46694c3bc1SFabio Estevam
4716edd347SFabio Estevam #define OTGID_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
4816edd347SFabio Estevam PAD_CTL_PUS_47K_UP | PAD_CTL_SPEED_LOW |\
4916edd347SFabio Estevam PAD_CTL_DSE_80ohm | PAD_CTL_HYS | \
5016edd347SFabio Estevam PAD_CTL_SRE_FAST)
5116edd347SFabio Estevam
52ae765f3aSFabio Estevam #define ETH_PHY_POWER IMX_GPIO_NR(4, 21)
5331f07964SFabio Estevam
dram_init(void)5457ca432fSFabio Estevam int dram_init(void)
5557ca432fSFabio Estevam {
568259e9c9SVanessa Maegima gd->ram_size = imx_ddr_size();
5757ca432fSFabio Estevam
5857ca432fSFabio Estevam return 0;
5957ca432fSFabio Estevam }
6057ca432fSFabio Estevam
6157ca432fSFabio Estevam static iomux_v3_cfg_t const uart1_pads[] = {
6257ca432fSFabio Estevam MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
6357ca432fSFabio Estevam MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
6457ca432fSFabio Estevam };
6557ca432fSFabio Estevam
6661ebeb99STom Rini #ifdef CONFIG_SPL_BUILD
6736255d67SYe.Li static iomux_v3_cfg_t const usdhc1_pads[] = {
6836255d67SYe.Li /* 8 bit SD */
6936255d67SYe.Li MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7036255d67SYe.Li MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7136255d67SYe.Li MX6_PAD_SD1_DAT0__USDHC1_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7236255d67SYe.Li MX6_PAD_SD1_DAT1__USDHC1_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7336255d67SYe.Li MX6_PAD_SD1_DAT2__USDHC1_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7436255d67SYe.Li MX6_PAD_SD1_DAT3__USDHC1_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7536255d67SYe.Li MX6_PAD_SD1_DAT4__USDHC1_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7636255d67SYe.Li MX6_PAD_SD1_DAT5__USDHC1_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7736255d67SYe.Li MX6_PAD_SD1_DAT6__USDHC1_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7836255d67SYe.Li MX6_PAD_SD1_DAT7__USDHC1_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
7936255d67SYe.Li
8036255d67SYe.Li /*CD pin*/
8136255d67SYe.Li MX6_PAD_KEY_ROW7__GPIO_4_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
8236255d67SYe.Li };
8336255d67SYe.Li
8457ca432fSFabio Estevam static iomux_v3_cfg_t const usdhc2_pads[] = {
8557ca432fSFabio Estevam MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
8657ca432fSFabio Estevam MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
8757ca432fSFabio Estevam MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
8857ca432fSFabio Estevam MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
8957ca432fSFabio Estevam MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
9057ca432fSFabio Estevam MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
9136255d67SYe.Li
9236255d67SYe.Li /*CD pin*/
9336255d67SYe.Li MX6_PAD_SD2_DAT7__GPIO_5_0 | MUX_PAD_CTRL(NO_PAD_CTRL),
9436255d67SYe.Li };
9536255d67SYe.Li
9636255d67SYe.Li static iomux_v3_cfg_t const usdhc3_pads[] = {
9736255d67SYe.Li MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
9836255d67SYe.Li MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
9936255d67SYe.Li MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
10036255d67SYe.Li MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
10136255d67SYe.Li MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
10236255d67SYe.Li MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
10336255d67SYe.Li
10436255d67SYe.Li /*CD pin*/
10536255d67SYe.Li MX6_PAD_REF_CLK_32K__GPIO_3_22 | MUX_PAD_CTRL(NO_PAD_CTRL),
10657ca432fSFabio Estevam };
10761ebeb99STom Rini #endif
10857ca432fSFabio Estevam
10931f07964SFabio Estevam static iomux_v3_cfg_t const fec_pads[] = {
11031f07964SFabio Estevam MX6_PAD_FEC_MDC__FEC_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
11131f07964SFabio Estevam MX6_PAD_FEC_MDIO__FEC_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
11231f07964SFabio Estevam MX6_PAD_FEC_CRS_DV__FEC_RX_DV | MUX_PAD_CTRL(ENET_PAD_CTRL),
11331f07964SFabio Estevam MX6_PAD_FEC_RXD0__FEC_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
11431f07964SFabio Estevam MX6_PAD_FEC_RXD1__FEC_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
11531f07964SFabio Estevam MX6_PAD_FEC_TX_EN__FEC_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
11631f07964SFabio Estevam MX6_PAD_FEC_TXD0__FEC_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
11731f07964SFabio Estevam MX6_PAD_FEC_TXD1__FEC_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
11831f07964SFabio Estevam MX6_PAD_FEC_REF_CLK__FEC_REF_OUT | MUX_PAD_CTRL(ENET_PAD_CTRL),
11931f07964SFabio Estevam MX6_PAD_FEC_RX_ER__GPIO_4_19 | MUX_PAD_CTRL(NO_PAD_CTRL),
12031f07964SFabio Estevam MX6_PAD_FEC_TX_CLK__GPIO_4_21 | MUX_PAD_CTRL(NO_PAD_CTRL),
12131f07964SFabio Estevam };
12231f07964SFabio Estevam
123694c3bc1SFabio Estevam #ifdef CONFIG_MXC_SPI
124694c3bc1SFabio Estevam static iomux_v3_cfg_t ecspi1_pads[] = {
125694c3bc1SFabio Estevam MX6_PAD_ECSPI1_MISO__ECSPI_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
126694c3bc1SFabio Estevam MX6_PAD_ECSPI1_MOSI__ECSPI_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
127694c3bc1SFabio Estevam MX6_PAD_ECSPI1_SCLK__ECSPI_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
128694c3bc1SFabio Estevam MX6_PAD_ECSPI1_SS0__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
129694c3bc1SFabio Estevam };
130694c3bc1SFabio Estevam
board_spi_cs_gpio(unsigned bus,unsigned cs)131155fa9afSNikita Kiryanov int board_spi_cs_gpio(unsigned bus, unsigned cs)
132155fa9afSNikita Kiryanov {
133155fa9afSNikita Kiryanov return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(4, 11)) : -1;
134155fa9afSNikita Kiryanov }
135155fa9afSNikita Kiryanov
setup_spi(void)136694c3bc1SFabio Estevam static void setup_spi(void)
137694c3bc1SFabio Estevam {
138694c3bc1SFabio Estevam imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads));
139694c3bc1SFabio Estevam }
140694c3bc1SFabio Estevam #endif
141694c3bc1SFabio Estevam
setup_iomux_uart(void)14257ca432fSFabio Estevam static void setup_iomux_uart(void)
14357ca432fSFabio Estevam {
14457ca432fSFabio Estevam imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
14557ca432fSFabio Estevam }
14657ca432fSFabio Estevam
setup_iomux_fec(void)14731f07964SFabio Estevam static void setup_iomux_fec(void)
14831f07964SFabio Estevam {
14931f07964SFabio Estevam imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
15031f07964SFabio Estevam
151ae765f3aSFabio Estevam /* Power up LAN8720 PHY */
152001cdbbbSPeng Fan gpio_request(ETH_PHY_POWER, "eth_pwr");
153ae765f3aSFabio Estevam gpio_direction_output(ETH_PHY_POWER , 1);
154ae765f3aSFabio Estevam udelay(15000);
15531f07964SFabio Estevam }
15631f07964SFabio Estevam
board_mmc_get_env_dev(int devno)157fb0d0428SPeng Fan int board_mmc_get_env_dev(int devno)
158fb0d0428SPeng Fan {
159fb0d0428SPeng Fan return devno;
160fb0d0428SPeng Fan }
161fb0d0428SPeng Fan
162001cdbbbSPeng Fan #ifdef CONFIG_DM_PMIC_PFUZE100
power_init_board(void)163af38bf6bSPeng Fan int power_init_board(void)
164af38bf6bSPeng Fan {
165001cdbbbSPeng Fan struct udevice *dev;
166001cdbbbSPeng Fan int ret;
167001cdbbbSPeng Fan u32 dev_id, rev_id, i;
168001cdbbbSPeng Fan u32 switch_num = 6;
169001cdbbbSPeng Fan u32 offset = PFUZE100_SW1CMODE;
170af38bf6bSPeng Fan
171001cdbbbSPeng Fan ret = pmic_get("pfuze100", &dev);
172001cdbbbSPeng Fan if (ret == -ENODEV)
173001cdbbbSPeng Fan return 0;
174af38bf6bSPeng Fan
175001cdbbbSPeng Fan if (ret != 0)
176001cdbbbSPeng Fan return ret;
177001cdbbbSPeng Fan
178001cdbbbSPeng Fan dev_id = pmic_reg_read(dev, PFUZE100_DEVICEID);
179001cdbbbSPeng Fan rev_id = pmic_reg_read(dev, PFUZE100_REVID);
180001cdbbbSPeng Fan printf("PMIC: PFUZE100! DEV_ID=0x%x REV_ID=0x%x\n", dev_id, rev_id);
181001cdbbbSPeng Fan
182001cdbbbSPeng Fan /* set SW1AB staby volatage 0.975V */
183001cdbbbSPeng Fan pmic_clrsetbits(dev, PFUZE100_SW1ABSTBY, 0x3f, 0x1b);
184001cdbbbSPeng Fan
185001cdbbbSPeng Fan /* set SW1AB/VDDARM step ramp up time from 16us to 4us/25mV */
186001cdbbbSPeng Fan pmic_clrsetbits(dev, PFUZE100_SW1ABCONF, 0xc0, 0x40);
187001cdbbbSPeng Fan
188001cdbbbSPeng Fan /* set SW1C staby volatage 0.975V */
189001cdbbbSPeng Fan pmic_clrsetbits(dev, PFUZE100_SW1CSTBY, 0x3f, 0x1b);
190001cdbbbSPeng Fan
191001cdbbbSPeng Fan /* set SW1C/VDDSOC step ramp up time to from 16us to 4us/25mV */
192001cdbbbSPeng Fan pmic_clrsetbits(dev, PFUZE100_SW1CCONF, 0xc0, 0x40);
193001cdbbbSPeng Fan
194001cdbbbSPeng Fan /* Init mode to APS_PFM */
195001cdbbbSPeng Fan pmic_reg_write(dev, PFUZE100_SW1ABMODE, APS_PFM);
196001cdbbbSPeng Fan
197001cdbbbSPeng Fan for (i = 0; i < switch_num - 1; i++)
198001cdbbbSPeng Fan pmic_reg_write(dev, offset + i * SWITCH_SIZE, APS_PFM);
199001cdbbbSPeng Fan
200001cdbbbSPeng Fan return 0;
201af38bf6bSPeng Fan }
202af38bf6bSPeng Fan #endif
203af38bf6bSPeng Fan
20431f07964SFabio Estevam #ifdef CONFIG_FEC_MXC
board_eth_init(bd_t * bis)20531f07964SFabio Estevam int board_eth_init(bd_t *bis)
20631f07964SFabio Estevam {
20731f07964SFabio Estevam setup_iomux_fec();
20831f07964SFabio Estevam
20912c20c0cSFabio Estevam return cpu_eth_init(bis);
21031f07964SFabio Estevam }
21131f07964SFabio Estevam
setup_fec(void)21231f07964SFabio Estevam static int setup_fec(void)
21331f07964SFabio Estevam {
2140a11d6f2SFabio Estevam struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
21531f07964SFabio Estevam
21631f07964SFabio Estevam /* clear gpr1[14], gpr1[18:17] to select anatop clock */
21731f07964SFabio Estevam clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
21831f07964SFabio Estevam
2196d97dc10SPeng Fan return enable_fec_anatop_clock(0, ENET_50MHZ);
22031f07964SFabio Estevam }
22131f07964SFabio Estevam #endif
22231f07964SFabio Estevam
board_early_init_f(void)22357ca432fSFabio Estevam int board_early_init_f(void)
22457ca432fSFabio Estevam {
22557ca432fSFabio Estevam setup_iomux_uart();
226001cdbbbSPeng Fan
22757ca432fSFabio Estevam return 0;
22857ca432fSFabio Estevam }
22957ca432fSFabio Estevam
board_init(void)23057ca432fSFabio Estevam int board_init(void)
23157ca432fSFabio Estevam {
23257ca432fSFabio Estevam /* address of boot parameters */
23357ca432fSFabio Estevam gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
23457ca432fSFabio Estevam
235001cdbbbSPeng Fan #ifdef CONFIG_MXC_SPI
236001cdbbbSPeng Fan gpio_request(IMX_GPIO_NR(4, 11), "spi_cs");
237001cdbbbSPeng Fan setup_spi();
238af38bf6bSPeng Fan #endif
239af38bf6bSPeng Fan
24031f07964SFabio Estevam #ifdef CONFIG_FEC_MXC
24131f07964SFabio Estevam setup_fec();
24231f07964SFabio Estevam #endif
2433b9c1a5dSPeng Fan
24457ca432fSFabio Estevam return 0;
24557ca432fSFabio Estevam }
24657ca432fSFabio Estevam
checkboard(void)24757ca432fSFabio Estevam int checkboard(void)
24857ca432fSFabio Estevam {
24957ca432fSFabio Estevam puts("Board: MX6SLEVK\n");
25057ca432fSFabio Estevam
25157ca432fSFabio Estevam return 0;
25257ca432fSFabio Estevam }
253e7d3b21bSPeng Fan
254e7d3b21bSPeng Fan #ifdef CONFIG_SPL_BUILD
255e7d3b21bSPeng Fan #include <spl.h>
256b08c8c48SMasahiro Yamada #include <linux/libfdt.h>
257e7d3b21bSPeng Fan
258001cdbbbSPeng Fan #define USDHC1_CD_GPIO IMX_GPIO_NR(4, 7)
259001cdbbbSPeng Fan #define USDHC2_CD_GPIO IMX_GPIO_NR(5, 0)
260001cdbbbSPeng Fan #define USDHC3_CD_GPIO IMX_GPIO_NR(3, 22)
261001cdbbbSPeng Fan
262001cdbbbSPeng Fan static struct fsl_esdhc_cfg usdhc_cfg[3] = {
263001cdbbbSPeng Fan {USDHC1_BASE_ADDR},
264001cdbbbSPeng Fan {USDHC2_BASE_ADDR, 0, 4},
265001cdbbbSPeng Fan {USDHC3_BASE_ADDR, 0, 4},
266001cdbbbSPeng Fan };
267001cdbbbSPeng Fan
board_mmc_getcd(struct mmc * mmc)268001cdbbbSPeng Fan int board_mmc_getcd(struct mmc *mmc)
269001cdbbbSPeng Fan {
270001cdbbbSPeng Fan struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
271001cdbbbSPeng Fan int ret = 0;
272001cdbbbSPeng Fan
273001cdbbbSPeng Fan switch (cfg->esdhc_base) {
274001cdbbbSPeng Fan case USDHC1_BASE_ADDR:
27540b0dae1SFabio Estevam gpio_request(USDHC1_CD_GPIO, "cd1_gpio");
276001cdbbbSPeng Fan ret = !gpio_get_value(USDHC1_CD_GPIO);
277001cdbbbSPeng Fan break;
278001cdbbbSPeng Fan case USDHC2_BASE_ADDR:
27940b0dae1SFabio Estevam gpio_request(USDHC2_CD_GPIO, "cd2_gpio");
280001cdbbbSPeng Fan ret = !gpio_get_value(USDHC2_CD_GPIO);
281001cdbbbSPeng Fan break;
282001cdbbbSPeng Fan case USDHC3_BASE_ADDR:
28340b0dae1SFabio Estevam gpio_request(USDHC3_CD_GPIO, "cd3_gpio");
284001cdbbbSPeng Fan ret = !gpio_get_value(USDHC3_CD_GPIO);
285001cdbbbSPeng Fan break;
286001cdbbbSPeng Fan }
287001cdbbbSPeng Fan
288001cdbbbSPeng Fan return ret;
289001cdbbbSPeng Fan }
290001cdbbbSPeng Fan
board_mmc_init(bd_t * bis)291001cdbbbSPeng Fan int board_mmc_init(bd_t *bis)
292001cdbbbSPeng Fan {
293001cdbbbSPeng Fan struct src *src_regs = (struct src *)SRC_BASE_ADDR;
294001cdbbbSPeng Fan u32 val;
295001cdbbbSPeng Fan u32 port;
296001cdbbbSPeng Fan
297001cdbbbSPeng Fan val = readl(&src_regs->sbmr1);
298001cdbbbSPeng Fan
299001cdbbbSPeng Fan /* Boot from USDHC */
300001cdbbbSPeng Fan port = (val >> 11) & 0x3;
301001cdbbbSPeng Fan switch (port) {
302001cdbbbSPeng Fan case 0:
303001cdbbbSPeng Fan imx_iomux_v3_setup_multiple_pads(usdhc1_pads,
304001cdbbbSPeng Fan ARRAY_SIZE(usdhc1_pads));
305001cdbbbSPeng Fan gpio_direction_input(USDHC1_CD_GPIO);
306001cdbbbSPeng Fan usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
307001cdbbbSPeng Fan usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
308001cdbbbSPeng Fan break;
309001cdbbbSPeng Fan case 1:
310001cdbbbSPeng Fan imx_iomux_v3_setup_multiple_pads(usdhc2_pads,
311001cdbbbSPeng Fan ARRAY_SIZE(usdhc2_pads));
312001cdbbbSPeng Fan gpio_direction_input(USDHC2_CD_GPIO);
313001cdbbbSPeng Fan usdhc_cfg[0].esdhc_base = USDHC2_BASE_ADDR;
314001cdbbbSPeng Fan usdhc_cfg[0].max_bus_width = 4;
315001cdbbbSPeng Fan usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
316001cdbbbSPeng Fan break;
317001cdbbbSPeng Fan case 2:
318001cdbbbSPeng Fan imx_iomux_v3_setup_multiple_pads(usdhc3_pads,
319001cdbbbSPeng Fan ARRAY_SIZE(usdhc3_pads));
320001cdbbbSPeng Fan gpio_direction_input(USDHC3_CD_GPIO);
321001cdbbbSPeng Fan usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
322001cdbbbSPeng Fan usdhc_cfg[0].max_bus_width = 4;
323001cdbbbSPeng Fan usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
324001cdbbbSPeng Fan break;
325001cdbbbSPeng Fan }
326001cdbbbSPeng Fan
327001cdbbbSPeng Fan gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
328001cdbbbSPeng Fan return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
329001cdbbbSPeng Fan }
330001cdbbbSPeng Fan
331e7d3b21bSPeng Fan const struct mx6sl_iomux_ddr_regs mx6_ddr_ioregs = {
332e7d3b21bSPeng Fan .dram_sdqs0 = 0x00003030,
333e7d3b21bSPeng Fan .dram_sdqs1 = 0x00003030,
334e7d3b21bSPeng Fan .dram_sdqs2 = 0x00003030,
335e7d3b21bSPeng Fan .dram_sdqs3 = 0x00003030,
336e7d3b21bSPeng Fan .dram_dqm0 = 0x00000030,
337e7d3b21bSPeng Fan .dram_dqm1 = 0x00000030,
338e7d3b21bSPeng Fan .dram_dqm2 = 0x00000030,
339e7d3b21bSPeng Fan .dram_dqm3 = 0x00000030,
340e7d3b21bSPeng Fan .dram_cas = 0x00000030,
341e7d3b21bSPeng Fan .dram_ras = 0x00000030,
342e7d3b21bSPeng Fan .dram_sdclk_0 = 0x00000028,
343e7d3b21bSPeng Fan .dram_reset = 0x00000030,
344e7d3b21bSPeng Fan .dram_sdba2 = 0x00000000,
345e7d3b21bSPeng Fan .dram_odt0 = 0x00000008,
346e7d3b21bSPeng Fan .dram_odt1 = 0x00000008,
347e7d3b21bSPeng Fan };
348e7d3b21bSPeng Fan
349e7d3b21bSPeng Fan const struct mx6sl_iomux_grp_regs mx6_grp_ioregs = {
350e7d3b21bSPeng Fan .grp_b0ds = 0x00000030,
351e7d3b21bSPeng Fan .grp_b1ds = 0x00000030,
352e7d3b21bSPeng Fan .grp_b2ds = 0x00000030,
353e7d3b21bSPeng Fan .grp_b3ds = 0x00000030,
354e7d3b21bSPeng Fan .grp_addds = 0x00000030,
355e7d3b21bSPeng Fan .grp_ctlds = 0x00000030,
356e7d3b21bSPeng Fan .grp_ddrmode_ctl = 0x00020000,
357e7d3b21bSPeng Fan .grp_ddrpke = 0x00000000,
358e7d3b21bSPeng Fan .grp_ddrmode = 0x00020000,
359e7d3b21bSPeng Fan .grp_ddr_type = 0x00080000,
360e7d3b21bSPeng Fan };
361e7d3b21bSPeng Fan
362e7d3b21bSPeng Fan const struct mx6_mmdc_calibration mx6_mmcd_calib = {
363e7d3b21bSPeng Fan .p0_mpdgctrl0 = 0x20000000,
364e7d3b21bSPeng Fan .p0_mpdgctrl1 = 0x00000000,
365e7d3b21bSPeng Fan .p0_mprddlctl = 0x4241444a,
366e7d3b21bSPeng Fan .p0_mpwrdlctl = 0x3030312b,
367e7d3b21bSPeng Fan .mpzqlp2ctl = 0x1b4700c7,
368e7d3b21bSPeng Fan };
369e7d3b21bSPeng Fan
370e7d3b21bSPeng Fan static struct mx6_lpddr2_cfg mem_ddr = {
371e7d3b21bSPeng Fan .mem_speed = 800,
372e7d3b21bSPeng Fan .density = 4,
373e7d3b21bSPeng Fan .width = 32,
374e7d3b21bSPeng Fan .banks = 8,
375e7d3b21bSPeng Fan .rowaddr = 14,
376e7d3b21bSPeng Fan .coladdr = 10,
377e7d3b21bSPeng Fan .trcd_lp = 2000,
378e7d3b21bSPeng Fan .trppb_lp = 2000,
379e7d3b21bSPeng Fan .trpab_lp = 2250,
380e7d3b21bSPeng Fan .trasmin = 4200,
381e7d3b21bSPeng Fan };
382e7d3b21bSPeng Fan
ccgr_init(void)383e7d3b21bSPeng Fan static void ccgr_init(void)
384e7d3b21bSPeng Fan {
385e7d3b21bSPeng Fan struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
386e7d3b21bSPeng Fan
387e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR0);
388e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR1);
389e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR2);
390e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR3);
391e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR4);
392e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR5);
393e7d3b21bSPeng Fan writel(0xFFFFFFFF, &ccm->CCGR6);
394e7d3b21bSPeng Fan
395e7d3b21bSPeng Fan writel(0x00260324, &ccm->cbcmr);
396e7d3b21bSPeng Fan }
397e7d3b21bSPeng Fan
spl_dram_init(void)398e7d3b21bSPeng Fan static void spl_dram_init(void)
399e7d3b21bSPeng Fan {
400e7d3b21bSPeng Fan struct mx6_ddr_sysinfo sysinfo = {
401e7d3b21bSPeng Fan .dsize = mem_ddr.width / 32,
402e7d3b21bSPeng Fan .cs_density = 20,
403e7d3b21bSPeng Fan .ncs = 2,
404e7d3b21bSPeng Fan .cs1_mirror = 0,
405e7d3b21bSPeng Fan .walat = 0,
406e7d3b21bSPeng Fan .ralat = 2,
407e7d3b21bSPeng Fan .mif3_mode = 3,
408e7d3b21bSPeng Fan .bi_on = 1,
409e7d3b21bSPeng Fan .rtt_wr = 0, /* LPDDR2 does not need rtt_wr rtt_nom */
410e7d3b21bSPeng Fan .rtt_nom = 0,
411e7d3b21bSPeng Fan .sde_to_rst = 0, /* LPDDR2 does not need this field */
412e7d3b21bSPeng Fan .rst_to_cke = 0x10, /* JEDEC value for LPDDR2: 200us */
413e7d3b21bSPeng Fan .ddr_type = DDR_TYPE_LPDDR2,
414edf00937SFabio Estevam .refsel = 0, /* Refresh cycles at 64KHz */
415edf00937SFabio Estevam .refr = 3, /* 4 refresh commands per refresh cycle */
416e7d3b21bSPeng Fan };
417e7d3b21bSPeng Fan mx6sl_dram_iocfg(32, &mx6_ddr_ioregs, &mx6_grp_ioregs);
418e7d3b21bSPeng Fan mx6_dram_cfg(&sysinfo, &mx6_mmcd_calib, &mem_ddr);
419e7d3b21bSPeng Fan }
420e7d3b21bSPeng Fan
board_init_f(ulong dummy)421e7d3b21bSPeng Fan void board_init_f(ulong dummy)
422e7d3b21bSPeng Fan {
423e7d3b21bSPeng Fan /* setup AIPS and disable watchdog */
424e7d3b21bSPeng Fan arch_cpu_init();
425e7d3b21bSPeng Fan
426e7d3b21bSPeng Fan ccgr_init();
427e7d3b21bSPeng Fan
428e7d3b21bSPeng Fan /* iomux and setup of i2c */
429e7d3b21bSPeng Fan board_early_init_f();
430e7d3b21bSPeng Fan
431e7d3b21bSPeng Fan /* setup GP timer */
432e7d3b21bSPeng Fan timer_init();
433e7d3b21bSPeng Fan
434e7d3b21bSPeng Fan /* UART clocks enabled and gd valid - init serial console */
435e7d3b21bSPeng Fan preloader_console_init();
436e7d3b21bSPeng Fan
437e7d3b21bSPeng Fan /* DDR initialization */
438e7d3b21bSPeng Fan spl_dram_init();
439e7d3b21bSPeng Fan
440e7d3b21bSPeng Fan /* Clear the BSS. */
441e7d3b21bSPeng Fan memset(__bss_start, 0, __bss_end - __bss_start);
442e7d3b21bSPeng Fan
443e7d3b21bSPeng Fan /* load/boot image from boot device */
444e7d3b21bSPeng Fan board_init_r(NULL, 0);
445e7d3b21bSPeng Fan }
446e7d3b21bSPeng Fan #endif
447