blob: 3e314daec2f431d7cb2900a508b7264713e3dd23 [file] [log] [blame]
Fabio Estevam7891e252012-09-13 03:18:20 +00001/*
2 * Copyright (C) 2012 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 Estevam7891e252012-09-13 03:18:20 +00007 */
8
Fabio Estevam7891e252012-09-13 03:18:20 +00009#include <asm/arch/clock.h>
10#include <asm/arch/imx-regs.h>
11#include <asm/arch/iomux.h>
Pierre Aubertc1747972013-06-04 09:00:15 +020012#include <asm/arch/mx6-pins.h>
Fabio Estevam7891e252012-09-13 03:18:20 +000013#include <asm/errno.h>
14#include <asm/gpio.h>
15#include <asm/imx-common/iomux-v3.h>
Otavio Salvador85449db2013-03-16 08:05:07 +000016#include <asm/imx-common/boot_mode.h>
Eric Benard053b7952014-04-04 19:05:54 +020017#include <asm/imx-common/video.h>
Fabio Estevam7891e252012-09-13 03:18:20 +000018#include <mmc.h>
19#include <fsl_esdhc.h>
20#include <miiphy.h>
21#include <netdev.h>
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -050022#include <asm/arch/mxc_hdmi.h>
23#include <asm/arch/crm_regs.h>
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -050024#include <asm/io.h>
25#include <asm/arch/sys_proto.h>
Fabio Estevam7891e252012-09-13 03:18:20 +000026DECLARE_GLOBAL_DATA_PTR;
27
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000028#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
29 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
30 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000031
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000032#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
33 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
34 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000035
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000036#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
37 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000038
Fabio Estevam8bfa9c62013-11-08 16:20:54 -020039#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
40 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
41
Fabio Estevam7891e252012-09-13 03:18:20 +000042int dram_init(void)
43{
44 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
45
46 return 0;
47}
48
Eric Nelson6e142322012-10-03 07:26:38 +000049iomux_v3_cfg_t const uart1_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070050 MX6_PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
51 MX6_PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Fabio Estevam7891e252012-09-13 03:18:20 +000052};
53
Eric Nelson6e142322012-10-03 07:26:38 +000054iomux_v3_cfg_t const enet_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000055 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
56 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson10fda482013-11-04 17:00:51 -070057 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
58 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
59 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
60 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
61 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000062 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
63 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson10fda482013-11-04 17:00:51 -070064 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
65 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
66 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
67 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
68 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000069 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
Fabio Estevama0d21fc2012-09-18 17:24:23 +000070 /* AR8031 PHY Reset */
Eric Nelson10fda482013-11-04 17:00:51 -070071 MX6_PAD_ENET_CRS_DV__GPIO1_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevama0d21fc2012-09-18 17:24:23 +000072};
73
74static void setup_iomux_enet(void)
75{
76 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
77
78 /* Reset AR8031 PHY */
79 gpio_direction_output(IMX_GPIO_NR(1, 25) , 0);
80 udelay(500);
81 gpio_set_value(IMX_GPIO_NR(1, 25), 1);
82}
83
Shawn Guode7d02a2012-12-30 14:14:59 +000084iomux_v3_cfg_t const usdhc2_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070085 MX6_PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
86 MX6_PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
87 MX6_PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
88 MX6_PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
89 MX6_PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
90 MX6_PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
91 MX6_PAD_NANDF_D4__SD2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
92 MX6_PAD_NANDF_D5__SD2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93 MX6_PAD_NANDF_D6__SD2_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_NANDF_D7__SD2_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Shawn Guode7d02a2012-12-30 14:14:59 +000096};
97
Eric Nelson6e142322012-10-03 07:26:38 +000098iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070099 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
100 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
101 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
102 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
103 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
104 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
105 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
106 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
107 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
108 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
109 MX6_PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Fabio Estevam7891e252012-09-13 03:18:20 +0000110};
111
Shawn Guode7d02a2012-12-30 14:14:59 +0000112iomux_v3_cfg_t const usdhc4_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700113 MX6_PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
114 MX6_PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
115 MX6_PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
116 MX6_PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
117 MX6_PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
118 MX6_PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
119 MX6_PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
120 MX6_PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
121 MX6_PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
122 MX6_PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Shawn Guode7d02a2012-12-30 14:14:59 +0000123};
124
Fabio Estevam8bfa9c62013-11-08 16:20:54 -0200125iomux_v3_cfg_t const ecspi1_pads[] = {
126 MX6_PAD_KEY_COL0__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
127 MX6_PAD_KEY_COL1__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
128 MX6_PAD_KEY_ROW0__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
129 MX6_PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
130};
131
132static void setup_spi(void)
133{
134 imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads));
135}
136
Marek Vasute919aa22014-03-23 22:45:41 +0100137iomux_v3_cfg_t const pcie_pads[] = {
138 MX6_PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL), /* POWER */
139 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(NO_PAD_CTRL), /* RESET */
140};
141
142static void setup_pcie(void)
143{
144 imx_iomux_v3_setup_multiple_pads(pcie_pads, ARRAY_SIZE(pcie_pads));
145}
146
Fabio Estevambe4ab3d2013-12-04 01:08:16 -0200147iomux_v3_cfg_t const di0_pads[] = {
148 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK, /* DISP0_CLK */
149 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN02, /* DISP0_HSYNC */
150 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN03, /* DISP0_VSYNC */
151};
152
Fabio Estevam7891e252012-09-13 03:18:20 +0000153static void setup_iomux_uart(void)
154{
155 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
156}
157
158#ifdef CONFIG_FSL_ESDHC
Shawn Guode7d02a2012-12-30 14:14:59 +0000159struct fsl_esdhc_cfg usdhc_cfg[3] = {
160 {USDHC2_BASE_ADDR},
Fabio Estevam7891e252012-09-13 03:18:20 +0000161 {USDHC3_BASE_ADDR},
Shawn Guode7d02a2012-12-30 14:14:59 +0000162 {USDHC4_BASE_ADDR},
Fabio Estevam7891e252012-09-13 03:18:20 +0000163};
164
Shawn Guode7d02a2012-12-30 14:14:59 +0000165#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 2)
166#define USDHC3_CD_GPIO IMX_GPIO_NR(2, 0)
167
Fabio Estevam7891e252012-09-13 03:18:20 +0000168int board_mmc_getcd(struct mmc *mmc)
169{
Shawn Guode7d02a2012-12-30 14:14:59 +0000170 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Otavio Salvador60bb4622013-03-16 08:05:06 +0000171 int ret = 0;
Shawn Guode7d02a2012-12-30 14:14:59 +0000172
173 switch (cfg->esdhc_base) {
174 case USDHC2_BASE_ADDR:
Otavio Salvador60bb4622013-03-16 08:05:06 +0000175 ret = !gpio_get_value(USDHC2_CD_GPIO);
176 break;
Shawn Guode7d02a2012-12-30 14:14:59 +0000177 case USDHC3_BASE_ADDR:
Otavio Salvador60bb4622013-03-16 08:05:06 +0000178 ret = !gpio_get_value(USDHC3_CD_GPIO);
179 break;
180 case USDHC4_BASE_ADDR:
181 ret = 1; /* eMMC/uSDHC4 is always present */
182 break;
Shawn Guode7d02a2012-12-30 14:14:59 +0000183 }
Otavio Salvador60bb4622013-03-16 08:05:06 +0000184
185 return ret;
Fabio Estevam7891e252012-09-13 03:18:20 +0000186}
187
188int board_mmc_init(bd_t *bis)
189{
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000190 s32 status = 0;
Shawn Guode7d02a2012-12-30 14:14:59 +0000191 int i;
Fabio Estevam7891e252012-09-13 03:18:20 +0000192
Otavio Salvador28ff9172013-03-16 08:05:05 +0000193 /*
194 * According to the board_mmc_init() the following map is done:
195 * (U-boot device node) (Physical Port)
196 * mmc0 SD2
197 * mmc1 SD3
198 * mmc2 eMMC
199 */
Shawn Guode7d02a2012-12-30 14:14:59 +0000200 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
201 switch (i) {
202 case 0:
203 imx_iomux_v3_setup_multiple_pads(
204 usdhc2_pads, ARRAY_SIZE(usdhc2_pads));
205 gpio_direction_input(USDHC2_CD_GPIO);
206 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
207 break;
208 case 1:
209 imx_iomux_v3_setup_multiple_pads(
210 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
211 gpio_direction_input(USDHC3_CD_GPIO);
212 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
213 break;
214 case 2:
215 imx_iomux_v3_setup_multiple_pads(
216 usdhc4_pads, ARRAY_SIZE(usdhc4_pads));
217 usdhc_cfg[2].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
218 break;
219 default:
220 printf("Warning: you configured more USDHC controllers"
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000221 "(%d) then supported by the board (%d)\n",
222 i + 1, CONFIG_SYS_FSL_USDHC_NUM);
223 return status;
224 }
Shawn Guode7d02a2012-12-30 14:14:59 +0000225
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000226 status |= fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
Shawn Guode7d02a2012-12-30 14:14:59 +0000227 }
228
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000229 return status;
Fabio Estevam7891e252012-09-13 03:18:20 +0000230}
231#endif
232
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000233int mx6_rgmii_rework(struct phy_device *phydev)
234{
235 unsigned short val;
236
237 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
238 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
239 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
240 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
241
242 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
243 val &= 0xffe3;
244 val |= 0x18;
245 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
246
247 /* introduce tx clock delay */
248 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
249 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
250 val |= 0x0100;
251 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
252
253 return 0;
254}
255
256int board_phy_config(struct phy_device *phydev)
257{
258 mx6_rgmii_rework(phydev);
259
260 if (phydev->drv->config)
261 phydev->drv->config(phydev);
262
263 return 0;
264}
265
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500266#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200267static void disable_lvds(struct display_info_t const *dev)
268{
269 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
270
271 int reg = readl(&iomux->gpr[2]);
272
273 reg &= ~(IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
274 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
275
276 writel(reg, &iomux->gpr[2]);
277}
278
Fabio Estevamd9b89462013-09-04 15:12:38 -0300279static void do_enable_hdmi(struct display_info_t const *dev)
280{
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200281 disable_lvds(dev);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300282 imx_enable_hdmi_phy();
283}
284
285static void enable_lvds(struct display_info_t const *dev)
286{
287 struct iomuxc *iomux = (struct iomuxc *)
288 IOMUXC_BASE_ADDR;
289 u32 reg = readl(&iomux->gpr[2]);
Fabio Estevam119e9902013-12-04 01:08:17 -0200290 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
291 IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300292 writel(reg, &iomux->gpr[2]);
293}
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200294
Eric Benard053b7952014-04-04 19:05:54 +0200295struct display_info_t const displays[] = {{
Fabio Estevamd9b89462013-09-04 15:12:38 -0300296 .bus = -1,
297 .addr = 0,
Fabio Estevam119e9902013-12-04 01:08:17 -0200298 .pixfmt = IPU_PIX_FMT_RGB666,
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200299 .detect = NULL,
300 .enable = enable_lvds,
Fabio Estevamd9b89462013-09-04 15:12:38 -0300301 .mode = {
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200302 .name = "Hannstar-XGA",
Fabio Estevamd9b89462013-09-04 15:12:38 -0300303 .refresh = 60,
304 .xres = 1024,
305 .yres = 768,
306 .pixclock = 15385,
307 .left_margin = 220,
308 .right_margin = 40,
309 .upper_margin = 21,
310 .lower_margin = 7,
311 .hsync_len = 60,
312 .vsync_len = 10,
313 .sync = FB_SYNC_EXT,
314 .vmode = FB_VMODE_NONINTERLACED
315} }, {
316 .bus = -1,
317 .addr = 0,
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200318 .pixfmt = IPU_PIX_FMT_RGB24,
319 .detect = detect_hdmi,
320 .enable = do_enable_hdmi,
Fabio Estevamd9b89462013-09-04 15:12:38 -0300321 .mode = {
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200322 .name = "HDMI",
Fabio Estevamd9b89462013-09-04 15:12:38 -0300323 .refresh = 60,
324 .xres = 1024,
325 .yres = 768,
326 .pixclock = 15385,
327 .left_margin = 220,
328 .right_margin = 40,
329 .upper_margin = 21,
330 .lower_margin = 7,
331 .hsync_len = 60,
332 .vsync_len = 10,
333 .sync = FB_SYNC_EXT,
334 .vmode = FB_VMODE_NONINTERLACED
335} } };
Eric Benard053b7952014-04-04 19:05:54 +0200336size_t display_count = ARRAY_SIZE(displays);
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500337
338static void setup_display(void)
339{
340 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300341 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500342 int reg;
343
Fabio Estevambe4ab3d2013-12-04 01:08:16 -0200344 /* Setup HSYNC, VSYNC, DISP_CLK for debugging purposes */
345 imx_iomux_v3_setup_multiple_pads(di0_pads, ARRAY_SIZE(di0_pads));
346
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500347 enable_ipu_clock();
348 imx_setup_hdmi();
349
Fabio Estevamd9b89462013-09-04 15:12:38 -0300350 /* Turn on LDB0, LDB1, IPU,IPU DI0 clocks */
Liu Ying12307432013-11-29 22:38:39 +0800351 reg = readl(&mxc_ccm->CCGR3);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300352 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK | MXC_CCM_CCGR3_LDB_DI1_MASK;
353 writel(reg, &mxc_ccm->CCGR3);
354
355 /* set LDB0, LDB1 clk select to 011/011 */
356 reg = readl(&mxc_ccm->cs2cdr);
357 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
358 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
359 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
360 | (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
361 writel(reg, &mxc_ccm->cs2cdr);
362
363 reg = readl(&mxc_ccm->cscmr2);
364 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV | MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV;
365 writel(reg, &mxc_ccm->cscmr2);
366
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500367 reg = readl(&mxc_ccm->chsccdr);
368 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
369 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300370 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
371 << MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500372 writel(reg, &mxc_ccm->chsccdr);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300373
374 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
375 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW
376 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
377 | IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
378 | IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
379 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
380 | IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
381 | IOMUXC_GPR2_LVDS_CH0_MODE_DISABLED
382 | IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0;
383 writel(reg, &iomux->gpr[2]);
384
385 reg = readl(&iomux->gpr[3]);
386 reg = (reg & ~(IOMUXC_GPR3_LVDS1_MUX_CTL_MASK
387 | IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
388 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
389 << IOMUXC_GPR3_LVDS1_MUX_CTL_OFFSET);
390 writel(reg, &iomux->gpr[3]);
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500391}
392#endif /* CONFIG_VIDEO_IPUV3 */
393
394/*
395 * Do not overwrite the console
396 * Use always serial for U-Boot console
397 */
398int overwrite_console(void)
399{
400 return 1;
401}
402
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000403int board_eth_init(bd_t *bis)
404{
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000405 setup_iomux_enet();
Marek Vasute919aa22014-03-23 22:45:41 +0100406 setup_pcie();
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000407
Fabio Estevam92c707a2014-01-04 17:36:32 -0200408 return cpu_eth_init(bis);
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000409}
410
Fabio Estevam7891e252012-09-13 03:18:20 +0000411int board_early_init_f(void)
412{
413 setup_iomux_uart();
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500414#if defined(CONFIG_VIDEO_IPUV3)
415 setup_display();
416#endif
Fabio Estevam7891e252012-09-13 03:18:20 +0000417
418 return 0;
419}
420
421int board_init(void)
422{
423 /* address of boot parameters */
424 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
425
Fabio Estevam8bfa9c62013-11-08 16:20:54 -0200426#ifdef CONFIG_MXC_SPI
427 setup_spi();
428#endif
429
Fabio Estevam7891e252012-09-13 03:18:20 +0000430 return 0;
431}
432
Otavio Salvador85449db2013-03-16 08:05:07 +0000433#ifdef CONFIG_CMD_BMODE
434static const struct boot_mode board_boot_modes[] = {
435 /* 4 bit bus width */
436 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
437 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
438 /* 8 bit bus width */
439 {"emmc", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
440 {NULL, 0},
441};
442#endif
443
444int board_late_init(void)
445{
446#ifdef CONFIG_CMD_BMODE
447 add_board_boot_modes(board_boot_modes);
448#endif
449
450 return 0;
451}
452
Fabio Estevam7891e252012-09-13 03:18:20 +0000453int checkboard(void)
454{
Pierre Aubertc1747972013-06-04 09:00:15 +0200455 puts("Board: MX6-SabreSD\n");
Fabio Estevam7891e252012-09-13 03:18:20 +0000456 return 0;
457}