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> 1157ca432fSFabio Estevam #include <asm/arch/imx-regs.h> 1257ca432fSFabio Estevam #include <asm/arch/mx6-pins.h> 1357ca432fSFabio Estevam #include <asm/arch/sys_proto.h> 1457ca432fSFabio Estevam #include <asm/gpio.h> 1557ca432fSFabio Estevam #include <asm/imx-common/iomux-v3.h> 1657ca432fSFabio Estevam #include <asm/io.h> 171ace4022SAlexey Brodkin #include <linux/sizes.h> 1857ca432fSFabio Estevam #include <common.h> 1957ca432fSFabio Estevam #include <fsl_esdhc.h> 2057ca432fSFabio Estevam #include <mmc.h> 2131f07964SFabio Estevam #include <netdev.h> 2257ca432fSFabio Estevam 2357ca432fSFabio Estevam DECLARE_GLOBAL_DATA_PTR; 2457ca432fSFabio Estevam 257e2173cfSBenoît Thébaudeau #define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \ 267e2173cfSBenoît Thébaudeau PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \ 277e2173cfSBenoît Thébaudeau PAD_CTL_SRE_FAST | PAD_CTL_HYS) 2857ca432fSFabio Estevam 297e2173cfSBenoît Thébaudeau #define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \ 307e2173cfSBenoît Thébaudeau PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \ 317e2173cfSBenoît Thébaudeau PAD_CTL_SRE_FAST | PAD_CTL_HYS) 3257ca432fSFabio Estevam 3331f07964SFabio Estevam #define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \ 3431f07964SFabio Estevam PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \ 3531f07964SFabio Estevam PAD_CTL_DSE_40ohm | PAD_CTL_HYS) 3631f07964SFabio Estevam 37*694c3bc1SFabio Estevam #define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \ 38*694c3bc1SFabio Estevam PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST) 39*694c3bc1SFabio Estevam 4031f07964SFabio Estevam #define ETH_PHY_RESET IMX_GPIO_NR(4, 21) 4131f07964SFabio Estevam 4257ca432fSFabio Estevam int dram_init(void) 4357ca432fSFabio Estevam { 4457ca432fSFabio Estevam gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE); 4557ca432fSFabio Estevam 4657ca432fSFabio Estevam return 0; 4757ca432fSFabio Estevam } 4857ca432fSFabio Estevam 4957ca432fSFabio Estevam static iomux_v3_cfg_t const uart1_pads[] = { 5057ca432fSFabio Estevam MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL), 5157ca432fSFabio Estevam MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL), 5257ca432fSFabio Estevam }; 5357ca432fSFabio Estevam 5457ca432fSFabio Estevam static iomux_v3_cfg_t const usdhc2_pads[] = { 5557ca432fSFabio Estevam MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL), 5657ca432fSFabio Estevam MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL), 5757ca432fSFabio Estevam MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL), 5857ca432fSFabio Estevam MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL), 5957ca432fSFabio Estevam MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL), 6057ca432fSFabio Estevam MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL), 6157ca432fSFabio Estevam }; 6257ca432fSFabio Estevam 6331f07964SFabio Estevam static iomux_v3_cfg_t const fec_pads[] = { 6431f07964SFabio Estevam MX6_PAD_FEC_MDC__FEC_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL), 6531f07964SFabio Estevam MX6_PAD_FEC_MDIO__FEC_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL), 6631f07964SFabio Estevam MX6_PAD_FEC_CRS_DV__FEC_RX_DV | MUX_PAD_CTRL(ENET_PAD_CTRL), 6731f07964SFabio Estevam MX6_PAD_FEC_RXD0__FEC_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL), 6831f07964SFabio Estevam MX6_PAD_FEC_RXD1__FEC_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL), 6931f07964SFabio Estevam MX6_PAD_FEC_TX_EN__FEC_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL), 7031f07964SFabio Estevam MX6_PAD_FEC_TXD0__FEC_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL), 7131f07964SFabio Estevam MX6_PAD_FEC_TXD1__FEC_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL), 7231f07964SFabio Estevam MX6_PAD_FEC_REF_CLK__FEC_REF_OUT | MUX_PAD_CTRL(ENET_PAD_CTRL), 7331f07964SFabio Estevam MX6_PAD_FEC_RX_ER__GPIO_4_19 | MUX_PAD_CTRL(NO_PAD_CTRL), 7431f07964SFabio Estevam MX6_PAD_FEC_TX_CLK__GPIO_4_21 | MUX_PAD_CTRL(NO_PAD_CTRL), 7531f07964SFabio Estevam }; 7631f07964SFabio Estevam 77*694c3bc1SFabio Estevam #ifdef CONFIG_MXC_SPI 78*694c3bc1SFabio Estevam static iomux_v3_cfg_t ecspi1_pads[] = { 79*694c3bc1SFabio Estevam MX6_PAD_ECSPI1_MISO__ECSPI_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL), 80*694c3bc1SFabio Estevam MX6_PAD_ECSPI1_MOSI__ECSPI_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL), 81*694c3bc1SFabio Estevam MX6_PAD_ECSPI1_SCLK__ECSPI_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL), 82*694c3bc1SFabio Estevam MX6_PAD_ECSPI1_SS0__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL), 83*694c3bc1SFabio Estevam }; 84*694c3bc1SFabio Estevam 85*694c3bc1SFabio Estevam static void setup_spi(void) 86*694c3bc1SFabio Estevam { 87*694c3bc1SFabio Estevam imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads)); 88*694c3bc1SFabio Estevam } 89*694c3bc1SFabio Estevam #endif 90*694c3bc1SFabio Estevam 9157ca432fSFabio Estevam static void setup_iomux_uart(void) 9257ca432fSFabio Estevam { 9357ca432fSFabio Estevam imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads)); 9457ca432fSFabio Estevam } 9557ca432fSFabio Estevam 9631f07964SFabio Estevam static void setup_iomux_fec(void) 9731f07964SFabio Estevam { 9831f07964SFabio Estevam imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads)); 9931f07964SFabio Estevam 10031f07964SFabio Estevam /* Reset LAN8720 PHY */ 10131f07964SFabio Estevam gpio_direction_output(ETH_PHY_RESET , 0); 10231f07964SFabio Estevam udelay(1000); 10331f07964SFabio Estevam gpio_set_value(ETH_PHY_RESET, 1); 10431f07964SFabio Estevam } 10531f07964SFabio Estevam 10657ca432fSFabio Estevam static struct fsl_esdhc_cfg usdhc_cfg[1] = { 10757ca432fSFabio Estevam {USDHC2_BASE_ADDR}, 10857ca432fSFabio Estevam }; 10957ca432fSFabio Estevam 11057ca432fSFabio Estevam int board_mmc_getcd(struct mmc *mmc) 11157ca432fSFabio Estevam { 11257ca432fSFabio Estevam return 1; /* Assume boot SD always present */ 11357ca432fSFabio Estevam } 11457ca432fSFabio Estevam 11557ca432fSFabio Estevam int board_mmc_init(bd_t *bis) 11657ca432fSFabio Estevam { 11757ca432fSFabio Estevam imx_iomux_v3_setup_multiple_pads(usdhc2_pads, ARRAY_SIZE(usdhc2_pads)); 11857ca432fSFabio Estevam 11957ca432fSFabio Estevam usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); 12057ca432fSFabio Estevam return fsl_esdhc_initialize(bis, &usdhc_cfg[0]); 12157ca432fSFabio Estevam } 12257ca432fSFabio Estevam 12331f07964SFabio Estevam #ifdef CONFIG_FEC_MXC 12431f07964SFabio Estevam int board_eth_init(bd_t *bis) 12531f07964SFabio Estevam { 12631f07964SFabio Estevam setup_iomux_fec(); 12731f07964SFabio Estevam 12812c20c0cSFabio Estevam return cpu_eth_init(bis); 12931f07964SFabio Estevam } 13031f07964SFabio Estevam 13131f07964SFabio Estevam static int setup_fec(void) 13231f07964SFabio Estevam { 13331f07964SFabio Estevam struct iomuxc_base_regs *iomuxc_regs = 13431f07964SFabio Estevam (struct iomuxc_base_regs *)IOMUXC_BASE_ADDR; 13531f07964SFabio Estevam int ret; 13631f07964SFabio Estevam 13731f07964SFabio Estevam /* clear gpr1[14], gpr1[18:17] to select anatop clock */ 13831f07964SFabio Estevam clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0); 13931f07964SFabio Estevam 1405f98d0b5SFabio Estevam ret = enable_fec_anatop_clock(ENET_50MHz); 14131f07964SFabio Estevam if (ret) 14231f07964SFabio Estevam return ret; 14331f07964SFabio Estevam 14431f07964SFabio Estevam return 0; 14531f07964SFabio Estevam } 14631f07964SFabio Estevam #endif 14731f07964SFabio Estevam 14831f07964SFabio Estevam 14957ca432fSFabio Estevam int board_early_init_f(void) 15057ca432fSFabio Estevam { 15157ca432fSFabio Estevam setup_iomux_uart(); 152*694c3bc1SFabio Estevam #ifdef CONFIG_MXC_SPI 153*694c3bc1SFabio Estevam setup_spi(); 154*694c3bc1SFabio Estevam #endif 15557ca432fSFabio Estevam return 0; 15657ca432fSFabio Estevam } 15757ca432fSFabio Estevam 15857ca432fSFabio Estevam int board_init(void) 15957ca432fSFabio Estevam { 16057ca432fSFabio Estevam /* address of boot parameters */ 16157ca432fSFabio Estevam gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; 16257ca432fSFabio Estevam 16331f07964SFabio Estevam #ifdef CONFIG_FEC_MXC 16431f07964SFabio Estevam setup_fec(); 16531f07964SFabio Estevam #endif 16657ca432fSFabio Estevam return 0; 16757ca432fSFabio Estevam } 16857ca432fSFabio Estevam 16957ca432fSFabio Estevam u32 get_board_rev(void) 17057ca432fSFabio Estevam { 17157ca432fSFabio Estevam return get_cpu_rev(); 17257ca432fSFabio Estevam } 17357ca432fSFabio Estevam 17457ca432fSFabio Estevam int checkboard(void) 17557ca432fSFabio Estevam { 17657ca432fSFabio Estevam puts("Board: MX6SLEVK\n"); 17757ca432fSFabio Estevam 17857ca432fSFabio Estevam return 0; 17957ca432fSFabio Estevam } 180