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