blob: 6918614ec1b2bc5de4b4fb1c2494f6df4a8696d6 [file] [log] [blame]
Fabio Estevam11027402013-03-15 10:43:48 +00001/*
2 * Copyright (C) 2013 Freescale Semiconductor, Inc.
3 *
4 * Author: Fabio Estevam <fabio.estevam@freescale.com>
5 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Fabio Estevam11027402013-03-15 10:43:48 +00007 */
8
9#include <asm/arch/clock.h>
Fabio Estevam0296f282013-05-23 07:50:23 +000010#include <asm/arch/crm_regs.h>
Fabio Estevam11027402013-03-15 10:43:48 +000011#include <asm/arch/iomux.h>
12#include <asm/arch/imx-regs.h>
13#include <asm/arch/mx6-pins.h>
Fabio Estevam0296f282013-05-23 07:50:23 +000014#include <asm/arch/mxc_hdmi.h>
Fabio Estevam11027402013-03-15 10:43:48 +000015#include <asm/arch/sys_proto.h>
16#include <asm/gpio.h>
17#include <asm/imx-common/iomux-v3.h>
Otavio Salvador54b8ce22013-04-19 03:42:03 +000018#include <asm/imx-common/boot_mode.h>
Fabio Estevam11027402013-03-15 10:43:48 +000019#include <asm/io.h>
20#include <asm/sizes.h>
21#include <common.h>
22#include <fsl_esdhc.h>
Fabio Estevam0296f282013-05-23 07:50:23 +000023#include <ipu_pixfmt.h>
Fabio Estevam11027402013-03-15 10:43:48 +000024#include <mmc.h>
25#include <miiphy.h>
26#include <netdev.h>
Fabio Estevam0296f282013-05-23 07:50:23 +000027#include <linux/fb.h>
Fabio Estevam55e0f192014-02-15 14:52:00 -020028#include <phy.h>
Fabio Estevam11027402013-03-15 10:43:48 +000029
30DECLARE_GLOBAL_DATA_PTR;
31
Benoît Thébaudeau21670242013-04-26 01:34:47 +000032#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
33 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
34 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam11027402013-03-15 10:43:48 +000035
Benoît Thébaudeau21670242013-04-26 01:34:47 +000036#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
37 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
38 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam11027402013-03-15 10:43:48 +000039
Benoît Thébaudeau21670242013-04-26 01:34:47 +000040#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
41 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevam11027402013-03-15 10:43:48 +000042
Otavio Salvadorfe651042013-04-19 03:42:02 +000043#define USDHC1_CD_GPIO IMX_GPIO_NR(1, 2)
Otavio Salvador36fda7f2013-04-19 03:42:01 +000044#define USDHC3_CD_GPIO IMX_GPIO_NR(3, 9)
Fabio Estevam11027402013-03-15 10:43:48 +000045#define ETH_PHY_RESET IMX_GPIO_NR(3, 29)
46
47int dram_init(void)
48{
Tapani Utriainen048a64d2013-06-26 17:51:49 +080049 gd->ram_size = (phys_size_t)CONFIG_DDR_MB * 1024 * 1024;
Fabio Estevam11027402013-03-15 10:43:48 +000050
51 return 0;
52}
53
54static iomux_v3_cfg_t const uart1_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -070055 MX6_PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
56 MX6_PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Fabio Estevam11027402013-03-15 10:43:48 +000057};
58
Fabio Estevam4b891692014-02-15 14:51:58 -020059static iomux_v3_cfg_t const usdhc1_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -070060 MX6_PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
61 MX6_PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
62 MX6_PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
63 MX6_PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
64 MX6_PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
65 MX6_PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Otavio Salvadorfe651042013-04-19 03:42:02 +000066 /* Carrier MicroSD Card Detect */
Eric Nelson3d3be0a2013-11-04 17:00:51 -070067 MX6_PAD_GPIO_2__GPIO1_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL),
Otavio Salvadorfe651042013-04-19 03:42:02 +000068};
69
Fabio Estevam11027402013-03-15 10:43:48 +000070static iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelson3d3be0a2013-11-04 17:00:51 -070071 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
72 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
73 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
74 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
75 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
76 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Otavio Salvador36fda7f2013-04-19 03:42:01 +000077 /* SOM MicroSD Card Detect */
Eric Nelson3d3be0a2013-11-04 17:00:51 -070078 MX6_PAD_EIM_DA9__GPIO3_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevam11027402013-03-15 10:43:48 +000079};
80
81static iomux_v3_cfg_t const enet_pads[] = {
82 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
83 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson3d3be0a2013-11-04 17:00:51 -070084 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
85 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
86 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
87 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
88 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Fabio Estevam11027402013-03-15 10:43:48 +000089 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
90 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson3d3be0a2013-11-04 17:00:51 -070091 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
92 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
93 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
94 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
95 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Fabio Estevam11027402013-03-15 10:43:48 +000096 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
97 /* AR8031 PHY Reset */
Eric Nelson3d3be0a2013-11-04 17:00:51 -070098 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevam11027402013-03-15 10:43:48 +000099};
100
101static void setup_iomux_uart(void)
102{
103 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
104}
105
106static void setup_iomux_enet(void)
107{
108 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
109
110 /* Reset AR8031 PHY */
111 gpio_direction_output(ETH_PHY_RESET, 0);
112 udelay(500);
113 gpio_set_value(ETH_PHY_RESET, 1);
114}
115
Otavio Salvadorfe651042013-04-19 03:42:02 +0000116static struct fsl_esdhc_cfg usdhc_cfg[2] = {
Fabio Estevam11027402013-03-15 10:43:48 +0000117 {USDHC3_BASE_ADDR},
Otavio Salvadorfe651042013-04-19 03:42:02 +0000118 {USDHC1_BASE_ADDR},
Fabio Estevam11027402013-03-15 10:43:48 +0000119};
120
Otavio Salvador36fda7f2013-04-19 03:42:01 +0000121int board_mmc_getcd(struct mmc *mmc)
122{
123 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
124 int ret = 0;
125
126 switch (cfg->esdhc_base) {
Otavio Salvadorfe651042013-04-19 03:42:02 +0000127 case USDHC1_BASE_ADDR:
128 ret = !gpio_get_value(USDHC1_CD_GPIO);
129 break;
Otavio Salvador36fda7f2013-04-19 03:42:01 +0000130 case USDHC3_BASE_ADDR:
131 ret = !gpio_get_value(USDHC3_CD_GPIO);
132 break;
133 }
134
135 return ret;
136}
137
Fabio Estevam11027402013-03-15 10:43:48 +0000138int board_mmc_init(bd_t *bis)
139{
Otavio Salvadorfe651042013-04-19 03:42:02 +0000140 s32 status = 0;
141 u32 index = 0;
Fabio Estevam11027402013-03-15 10:43:48 +0000142
Otavio Salvadorfe651042013-04-19 03:42:02 +0000143 /*
144 * Following map is done:
145 * (U-boot device node) (Physical Port)
146 * mmc0 SOM MicroSD
147 * mmc1 Carrier board MicroSD
148 */
149 for (index = 0; index < CONFIG_SYS_FSL_USDHC_NUM; ++index) {
150 switch (index) {
151 case 0:
152 imx_iomux_v3_setup_multiple_pads(
153 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
154 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
155 usdhc_cfg[0].max_bus_width = 4;
156 gpio_direction_input(USDHC3_CD_GPIO);
157 break;
158 case 1:
159 imx_iomux_v3_setup_multiple_pads(
160 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
161 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
162 usdhc_cfg[1].max_bus_width = 4;
163 gpio_direction_input(USDHC1_CD_GPIO);
164 break;
165 default:
166 printf("Warning: you configured more USDHC controllers"
167 "(%d) then supported by the board (%d)\n",
168 index + 1, CONFIG_SYS_FSL_USDHC_NUM);
169 return status;
170 }
171
172 status |= fsl_esdhc_initialize(bis, &usdhc_cfg[index]);
173 }
Abbas Razae6bf9772013-03-25 09:13:34 +0000174
Otavio Salvadorfe651042013-04-19 03:42:02 +0000175 return status;
Fabio Estevam11027402013-03-15 10:43:48 +0000176}
177
178static int mx6_rgmii_rework(struct phy_device *phydev)
179{
180 unsigned short val;
181
182 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
183 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
184 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
185 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
186
187 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
188 val &= 0xffe3;
189 val |= 0x18;
190 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
191
192 /* introduce tx clock delay */
193 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
194 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
195 val |= 0x0100;
196 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
197
198 return 0;
199}
200
201int board_phy_config(struct phy_device *phydev)
202{
203 mx6_rgmii_rework(phydev);
204
205 if (phydev->drv->config)
206 phydev->drv->config(phydev);
207
208 return 0;
209}
210
Fabio Estevam0296f282013-05-23 07:50:23 +0000211#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevam0296f282013-05-23 07:50:23 +0000212static struct fb_videomode const hdmi = {
213 .name = "HDMI",
214 .refresh = 60,
215 .xres = 1024,
216 .yres = 768,
217 .pixclock = 15385,
218 .left_margin = 220,
219 .right_margin = 40,
220 .upper_margin = 21,
221 .lower_margin = 7,
222 .hsync_len = 60,
223 .vsync_len = 10,
224 .sync = FB_SYNC_EXT,
225 .vmode = FB_VMODE_NONINTERLACED
226};
227
228int board_video_skip(void)
229{
230 int ret;
231
232 ret = ipuv3_fb_init(&hdmi, 0, IPU_PIX_FMT_RGB24);
233
Fabio Estevam7be45ce2013-11-03 22:03:03 -0200234 if (ret) {
Fabio Estevam0296f282013-05-23 07:50:23 +0000235 printf("HDMI cannot be configured: %d\n", ret);
Fabio Estevam7be45ce2013-11-03 22:03:03 -0200236 return ret;
237 }
Fabio Estevam0296f282013-05-23 07:50:23 +0000238
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500239 imx_enable_hdmi_phy();
Fabio Estevam0296f282013-05-23 07:50:23 +0000240
241 return ret;
242}
243
244static void setup_display(void)
245{
246 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevam0296f282013-05-23 07:50:23 +0000247 int reg;
248
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500249 enable_ipu_clock();
250 imx_setup_hdmi();
Fabio Estevam0296f282013-05-23 07:50:23 +0000251
252 reg = readl(&mxc_ccm->chsccdr);
Fabio Estevam0296f282013-05-23 07:50:23 +0000253 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500254 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevam0296f282013-05-23 07:50:23 +0000255 writel(reg, &mxc_ccm->chsccdr);
256}
257#endif /* CONFIG_VIDEO_IPUV3 */
258
Fabio Estevam11027402013-03-15 10:43:48 +0000259int board_eth_init(bd_t *bis)
260{
Fabio Estevam11027402013-03-15 10:43:48 +0000261 setup_iomux_enet();
262
Fabio Estevamc3cc3052014-01-04 17:36:28 -0200263 return cpu_eth_init(bis);
Fabio Estevam11027402013-03-15 10:43:48 +0000264}
265
266int board_early_init_f(void)
267{
268 setup_iomux_uart();
Fabio Estevam0296f282013-05-23 07:50:23 +0000269#if defined(CONFIG_VIDEO_IPUV3)
270 setup_display();
271#endif
Fabio Estevam11027402013-03-15 10:43:48 +0000272 return 0;
273}
274
Fabio Estevam0296f282013-05-23 07:50:23 +0000275/*
276 * Do not overwrite the console
277 * Use always serial for U-Boot console
278 */
279int overwrite_console(void)
280{
281 return 1;
282}
283
Otavio Salvador54b8ce22013-04-19 03:42:03 +0000284#ifdef CONFIG_CMD_BMODE
285static const struct boot_mode board_boot_modes[] = {
286 /* 4 bit bus width */
287 {"mmc0", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
288 {"mmc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
289 {NULL, 0},
290};
291#endif
292
293int board_late_init(void)
294{
295#ifdef CONFIG_CMD_BMODE
296 add_board_boot_modes(board_boot_modes);
297#endif
298
299 return 0;
300}
301
Fabio Estevam11027402013-03-15 10:43:48 +0000302int board_init(void)
303{
304 /* address of boot parameters */
305 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
306
307 return 0;
308}
309
Fabio Estevam11027402013-03-15 10:43:48 +0000310int checkboard(void)
311{
312 puts("Board: Wandboard\n");
313
314 return 0;
315}