blob: cac6d73a7f81a9a1f3a7b8bd1b3b682b8fd16807 [file] [log] [blame]
Fabio Estevam57ca4322013-04-10 09:32:58 +00001/*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
5 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Fabio Estevam57ca4322013-04-10 09:32:58 +00007 */
8
9#include <asm/arch/clock.h>
10#include <asm/arch/iomux.h>
11#include <asm/arch/imx-regs.h>
12#include <asm/arch/mx6-pins.h>
13#include <asm/arch/sys_proto.h>
14#include <asm/gpio.h>
15#include <asm/imx-common/iomux-v3.h>
Eric Nelson3acb0112014-09-30 15:40:03 -070016#include <asm/imx-common/spi.h>
Fabio Estevam57ca4322013-04-10 09:32:58 +000017#include <asm/io.h>
Alexey Brodkin1ace4022014-02-26 17:47:58 +040018#include <linux/sizes.h>
Fabio Estevam57ca4322013-04-10 09:32:58 +000019#include <common.h>
20#include <fsl_esdhc.h>
21#include <mmc.h>
Fabio Estevam31f07962013-09-13 00:36:28 -030022#include <netdev.h>
Fabio Estevam57ca4322013-04-10 09:32:58 +000023
24DECLARE_GLOBAL_DATA_PTR;
25
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000026#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
27 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
28 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam57ca4322013-04-10 09:32:58 +000029
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000030#define USDHC_PAD_CTRL (PAD_CTL_PUS_22K_UP | \
31 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
32 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam57ca4322013-04-10 09:32:58 +000033
Fabio Estevam31f07962013-09-13 00:36:28 -030034#define ENET_PAD_CTRL (PAD_CTL_PKE | PAD_CTL_PUE | \
35 PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | \
36 PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
37
Fabio Estevam694c3bc2014-04-11 08:39:43 -030038#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
39 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
40
Fabio Estevam31f07962013-09-13 00:36:28 -030041#define ETH_PHY_RESET IMX_GPIO_NR(4, 21)
42
Fabio Estevam57ca4322013-04-10 09:32:58 +000043int dram_init(void)
44{
45 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
46
47 return 0;
48}
49
50static iomux_v3_cfg_t const uart1_pads[] = {
51 MX6_PAD_UART1_TXD__UART1_TXD | MUX_PAD_CTRL(UART_PAD_CTRL),
52 MX6_PAD_UART1_RXD__UART1_RXD | MUX_PAD_CTRL(UART_PAD_CTRL),
53};
54
Ye.Li36255d62014-10-30 18:30:54 +080055static iomux_v3_cfg_t const usdhc1_pads[] = {
56 /* 8 bit SD */
57 MX6_PAD_SD1_CLK__USDHC1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
58 MX6_PAD_SD1_CMD__USDHC1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
59 MX6_PAD_SD1_DAT0__USDHC1_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
60 MX6_PAD_SD1_DAT1__USDHC1_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
61 MX6_PAD_SD1_DAT2__USDHC1_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
62 MX6_PAD_SD1_DAT3__USDHC1_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
63 MX6_PAD_SD1_DAT4__USDHC1_DAT4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
64 MX6_PAD_SD1_DAT5__USDHC1_DAT5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
65 MX6_PAD_SD1_DAT6__USDHC1_DAT6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
66 MX6_PAD_SD1_DAT7__USDHC1_DAT7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
67
68 /*CD pin*/
69 MX6_PAD_KEY_ROW7__GPIO_4_7 | MUX_PAD_CTRL(NO_PAD_CTRL),
70};
71
Fabio Estevam57ca4322013-04-10 09:32:58 +000072static iomux_v3_cfg_t const usdhc2_pads[] = {
73 MX6_PAD_SD2_CLK__USDHC2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
74 MX6_PAD_SD2_CMD__USDHC2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
75 MX6_PAD_SD2_DAT0__USDHC2_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
76 MX6_PAD_SD2_DAT1__USDHC2_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
77 MX6_PAD_SD2_DAT2__USDHC2_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
78 MX6_PAD_SD2_DAT3__USDHC2_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Ye.Li36255d62014-10-30 18:30:54 +080079
80 /*CD pin*/
81 MX6_PAD_SD2_DAT7__GPIO_5_0 | MUX_PAD_CTRL(NO_PAD_CTRL),
82};
83
84static iomux_v3_cfg_t const usdhc3_pads[] = {
85 MX6_PAD_SD3_CLK__USDHC3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
86 MX6_PAD_SD3_CMD__USDHC3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
87 MX6_PAD_SD3_DAT0__USDHC3_DAT0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
88 MX6_PAD_SD3_DAT1__USDHC3_DAT1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
89 MX6_PAD_SD3_DAT2__USDHC3_DAT2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
90 MX6_PAD_SD3_DAT3__USDHC3_DAT3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
91
92 /*CD pin*/
93 MX6_PAD_REF_CLK_32K__GPIO_3_22 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevam57ca4322013-04-10 09:32:58 +000094};
95
Fabio Estevam31f07962013-09-13 00:36:28 -030096static iomux_v3_cfg_t const fec_pads[] = {
97 MX6_PAD_FEC_MDC__FEC_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
98 MX6_PAD_FEC_MDIO__FEC_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
99 MX6_PAD_FEC_CRS_DV__FEC_RX_DV | MUX_PAD_CTRL(ENET_PAD_CTRL),
100 MX6_PAD_FEC_RXD0__FEC_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
101 MX6_PAD_FEC_RXD1__FEC_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
102 MX6_PAD_FEC_TX_EN__FEC_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
103 MX6_PAD_FEC_TXD0__FEC_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
104 MX6_PAD_FEC_TXD1__FEC_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
105 MX6_PAD_FEC_REF_CLK__FEC_REF_OUT | MUX_PAD_CTRL(ENET_PAD_CTRL),
106 MX6_PAD_FEC_RX_ER__GPIO_4_19 | MUX_PAD_CTRL(NO_PAD_CTRL),
107 MX6_PAD_FEC_TX_CLK__GPIO_4_21 | MUX_PAD_CTRL(NO_PAD_CTRL),
108};
109
Fabio Estevam694c3bc2014-04-11 08:39:43 -0300110#ifdef CONFIG_MXC_SPI
111static iomux_v3_cfg_t ecspi1_pads[] = {
112 MX6_PAD_ECSPI1_MISO__ECSPI_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
113 MX6_PAD_ECSPI1_MOSI__ECSPI_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
114 MX6_PAD_ECSPI1_SCLK__ECSPI_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
115 MX6_PAD_ECSPI1_SS0__GPIO4_IO11 | MUX_PAD_CTRL(NO_PAD_CTRL),
116};
117
Nikita Kiryanov155fa9a2014-08-20 15:08:50 +0300118int board_spi_cs_gpio(unsigned bus, unsigned cs)
119{
120 return (bus == 0 && cs == 0) ? (IMX_GPIO_NR(4, 11)) : -1;
121}
122
Fabio Estevam694c3bc2014-04-11 08:39:43 -0300123static void setup_spi(void)
124{
125 imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads));
126}
127#endif
128
Fabio Estevam57ca4322013-04-10 09:32:58 +0000129static void setup_iomux_uart(void)
130{
131 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
132}
133
Fabio Estevam31f07962013-09-13 00:36:28 -0300134static void setup_iomux_fec(void)
135{
136 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
137
138 /* Reset LAN8720 PHY */
139 gpio_direction_output(ETH_PHY_RESET , 0);
140 udelay(1000);
141 gpio_set_value(ETH_PHY_RESET, 1);
142}
143
Ye.Li36255d62014-10-30 18:30:54 +0800144#define USDHC1_CD_GPIO IMX_GPIO_NR(4, 7)
145#define USDHC2_CD_GPIO IMX_GPIO_NR(5, 0)
146#define USDHC3_CD_GPIO IMX_GPIO_NR(3, 22)
147
148static struct fsl_esdhc_cfg usdhc_cfg[3] = {
149 {USDHC1_BASE_ADDR},
150 {USDHC2_BASE_ADDR, 0, 4},
151 {USDHC3_BASE_ADDR, 0, 4},
Fabio Estevam57ca4322013-04-10 09:32:58 +0000152};
153
154int board_mmc_getcd(struct mmc *mmc)
155{
Ye.Li36255d62014-10-30 18:30:54 +0800156 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
157 int ret = 0;
158
159 switch (cfg->esdhc_base) {
160 case USDHC1_BASE_ADDR:
161 ret = !gpio_get_value(USDHC1_CD_GPIO);
162 break;
163 case USDHC2_BASE_ADDR:
164 ret = !gpio_get_value(USDHC2_CD_GPIO);
165 break;
166 case USDHC3_BASE_ADDR:
167 ret = !gpio_get_value(USDHC3_CD_GPIO);
168 break;
169 }
170
171 return ret;
Fabio Estevam57ca4322013-04-10 09:32:58 +0000172}
173
174int board_mmc_init(bd_t *bis)
175{
Ye.Li36255d62014-10-30 18:30:54 +0800176 int i, ret;
Fabio Estevam57ca4322013-04-10 09:32:58 +0000177
Ye.Li36255d62014-10-30 18:30:54 +0800178 /*
179 * According to the board_mmc_init() the following map is done:
180 * (U-boot device node) (Physical Port)
181 * mmc0 USDHC1
182 * mmc1 USDHC2
183 * mmc2 USDHC3
184 */
185 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
186 switch (i) {
187 case 0:
188 imx_iomux_v3_setup_multiple_pads(
189 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
190 gpio_direction_input(USDHC1_CD_GPIO);
191 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
192 break;
193 case 1:
194 imx_iomux_v3_setup_multiple_pads(
195 usdhc2_pads, ARRAY_SIZE(usdhc2_pads));
196 gpio_direction_input(USDHC2_CD_GPIO);
197 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
198 break;
199 case 2:
200 imx_iomux_v3_setup_multiple_pads(
201 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
202 gpio_direction_input(USDHC3_CD_GPIO);
203 usdhc_cfg[2].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
204 break;
205 default:
206 printf("Warning: you configured more USDHC controllers"
207 "(%d) than supported by the board\n", i + 1);
208 return -EINVAL;
209 }
210
211 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
212 if (ret) {
213 printf("Warning: failed to initialize "
214 "mmc dev %d\n", i);
215 return ret;
216 }
217 }
218
219 return 0;
Fabio Estevam57ca4322013-04-10 09:32:58 +0000220}
221
Fabio Estevam31f07962013-09-13 00:36:28 -0300222#ifdef CONFIG_FEC_MXC
223int board_eth_init(bd_t *bis)
224{
Fabio Estevam31f07962013-09-13 00:36:28 -0300225 setup_iomux_fec();
226
Fabio Estevam12c20c02014-01-04 17:36:33 -0200227 return cpu_eth_init(bis);
Fabio Estevam31f07962013-09-13 00:36:28 -0300228}
229
230static int setup_fec(void)
231{
Fabio Estevam0a11d6f2014-07-09 17:59:54 -0300232 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Fabio Estevam31f07962013-09-13 00:36:28 -0300233
234 /* clear gpr1[14], gpr1[18:17] to select anatop clock */
235 clrsetbits_le32(&iomuxc_regs->gpr[1], IOMUX_GPR1_FEC_MASK, 0);
236
Stefan Roese77317452014-11-27 13:46:43 +0100237 return enable_fec_anatop_clock(ENET_50MHZ);
Fabio Estevam31f07962013-09-13 00:36:28 -0300238}
239#endif
240
241
Fabio Estevam57ca4322013-04-10 09:32:58 +0000242int board_early_init_f(void)
243{
244 setup_iomux_uart();
Fabio Estevam694c3bc2014-04-11 08:39:43 -0300245#ifdef CONFIG_MXC_SPI
246 setup_spi();
247#endif
Fabio Estevam57ca4322013-04-10 09:32:58 +0000248 return 0;
249}
250
251int board_init(void)
252{
253 /* address of boot parameters */
254 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
255
Fabio Estevam31f07962013-09-13 00:36:28 -0300256#ifdef CONFIG_FEC_MXC
257 setup_fec();
258#endif
Fabio Estevam57ca4322013-04-10 09:32:58 +0000259 return 0;
260}
261
262u32 get_board_rev(void)
263{
264 return get_cpu_rev();
265}
266
267int checkboard(void)
268{
269 puts("Board: MX6SLEVK\n");
270
271 return 0;
272}