blob: d7d932eeb8a3fd70c7d78a6b41cd016cc811d5f8 [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>
Fabio Estevam7891e252012-09-13 03:18:20 +000017#include <mmc.h>
18#include <fsl_esdhc.h>
19#include <miiphy.h>
20#include <netdev.h>
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -050021#include <asm/arch/mxc_hdmi.h>
22#include <asm/arch/crm_regs.h>
23#include <linux/fb.h>
24#include <ipu_pixfmt.h>
25#include <asm/io.h>
26#include <asm/arch/sys_proto.h>
Fabio Estevam7891e252012-09-13 03:18:20 +000027DECLARE_GLOBAL_DATA_PTR;
28
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000029#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
30 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
31 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000032
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000033#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
34 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
35 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000036
Benoît Thébaudeau7e2173c2013-04-26 01:34:47 +000037#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
38 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
Fabio Estevam7891e252012-09-13 03:18:20 +000039
Fabio Estevam8bfa9c62013-11-08 16:20:54 -020040#define SPI_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_SPEED_MED | \
41 PAD_CTL_DSE_40ohm | PAD_CTL_SRE_FAST)
42
Fabio Estevam7891e252012-09-13 03:18:20 +000043int dram_init(void)
44{
45 gd->ram_size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
46
47 return 0;
48}
49
Eric Nelson6e142322012-10-03 07:26:38 +000050iomux_v3_cfg_t const uart1_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070051 MX6_PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
52 MX6_PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
Fabio Estevam7891e252012-09-13 03:18:20 +000053};
54
Eric Nelson6e142322012-10-03 07:26:38 +000055iomux_v3_cfg_t const enet_pads[] = {
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000056 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
57 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson10fda482013-11-04 17:00:51 -070058 MX6_PAD_RGMII_TXC__RGMII_TXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
59 MX6_PAD_RGMII_TD0__RGMII_TD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
60 MX6_PAD_RGMII_TD1__RGMII_TD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
61 MX6_PAD_RGMII_TD2__RGMII_TD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
62 MX6_PAD_RGMII_TD3__RGMII_TD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000063 MX6_PAD_RGMII_TX_CTL__RGMII_TX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
64 MX6_PAD_ENET_REF_CLK__ENET_TX_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelson10fda482013-11-04 17:00:51 -070065 MX6_PAD_RGMII_RXC__RGMII_RXC | MUX_PAD_CTRL(ENET_PAD_CTRL),
66 MX6_PAD_RGMII_RD0__RGMII_RD0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
67 MX6_PAD_RGMII_RD1__RGMII_RD1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
68 MX6_PAD_RGMII_RD2__RGMII_RD2 | MUX_PAD_CTRL(ENET_PAD_CTRL),
69 MX6_PAD_RGMII_RD3__RGMII_RD3 | MUX_PAD_CTRL(ENET_PAD_CTRL),
Eric Nelsoncfb8b9d2013-02-19 10:07:01 +000070 MX6_PAD_RGMII_RX_CTL__RGMII_RX_CTL | MUX_PAD_CTRL(ENET_PAD_CTRL),
Fabio Estevama0d21fc2012-09-18 17:24:23 +000071 /* AR8031 PHY Reset */
Eric Nelson10fda482013-11-04 17:00:51 -070072 MX6_PAD_ENET_CRS_DV__GPIO1_IO25 | MUX_PAD_CTRL(NO_PAD_CTRL),
Fabio Estevama0d21fc2012-09-18 17:24:23 +000073};
74
75static void setup_iomux_enet(void)
76{
77 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
78
79 /* Reset AR8031 PHY */
80 gpio_direction_output(IMX_GPIO_NR(1, 25) , 0);
81 udelay(500);
82 gpio_set_value(IMX_GPIO_NR(1, 25), 1);
83}
84
Shawn Guode7d02a2012-12-30 14:14:59 +000085iomux_v3_cfg_t const usdhc2_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -070086 MX6_PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
87 MX6_PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
88 MX6_PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
89 MX6_PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
90 MX6_PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
91 MX6_PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
92 MX6_PAD_NANDF_D4__SD2_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93 MX6_PAD_NANDF_D5__SD2_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_NANDF_D6__SD2_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_NANDF_D7__SD2_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Shawn Guode7d02a2012-12-30 14:14:59 +000097};
98
Eric Nelson6e142322012-10-03 07:26:38 +000099iomux_v3_cfg_t const usdhc3_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700100 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
101 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
102 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
103 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
104 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
105 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
106 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
107 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
108 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
109 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
110 MX6_PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
Fabio Estevam7891e252012-09-13 03:18:20 +0000111};
112
Shawn Guode7d02a2012-12-30 14:14:59 +0000113iomux_v3_cfg_t const usdhc4_pads[] = {
Eric Nelson10fda482013-11-04 17:00:51 -0700114 MX6_PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
115 MX6_PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
116 MX6_PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
117 MX6_PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
118 MX6_PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
119 MX6_PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
120 MX6_PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
121 MX6_PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
122 MX6_PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
123 MX6_PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
Shawn Guode7d02a2012-12-30 14:14:59 +0000124};
125
Fabio Estevam8bfa9c62013-11-08 16:20:54 -0200126iomux_v3_cfg_t const ecspi1_pads[] = {
127 MX6_PAD_KEY_COL0__ECSPI1_SCLK | MUX_PAD_CTRL(SPI_PAD_CTRL),
128 MX6_PAD_KEY_COL1__ECSPI1_MISO | MUX_PAD_CTRL(SPI_PAD_CTRL),
129 MX6_PAD_KEY_ROW0__ECSPI1_MOSI | MUX_PAD_CTRL(SPI_PAD_CTRL),
130 MX6_PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL),
131};
132
133static void setup_spi(void)
134{
135 imx_iomux_v3_setup_multiple_pads(ecspi1_pads, ARRAY_SIZE(ecspi1_pads));
136}
137
Marek Vasute919aa22014-03-23 22:45:41 +0100138iomux_v3_cfg_t const pcie_pads[] = {
139 MX6_PAD_EIM_D19__GPIO3_IO19 | MUX_PAD_CTRL(NO_PAD_CTRL), /* POWER */
140 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(NO_PAD_CTRL), /* RESET */
141};
142
143static void setup_pcie(void)
144{
145 imx_iomux_v3_setup_multiple_pads(pcie_pads, ARRAY_SIZE(pcie_pads));
146}
147
Fabio Estevambe4ab3d2013-12-04 01:08:16 -0200148iomux_v3_cfg_t const di0_pads[] = {
149 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK, /* DISP0_CLK */
150 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN02, /* DISP0_HSYNC */
151 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN03, /* DISP0_VSYNC */
152};
153
Fabio Estevam7891e252012-09-13 03:18:20 +0000154static void setup_iomux_uart(void)
155{
156 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
157}
158
159#ifdef CONFIG_FSL_ESDHC
Shawn Guode7d02a2012-12-30 14:14:59 +0000160struct fsl_esdhc_cfg usdhc_cfg[3] = {
161 {USDHC2_BASE_ADDR},
Fabio Estevam7891e252012-09-13 03:18:20 +0000162 {USDHC3_BASE_ADDR},
Shawn Guode7d02a2012-12-30 14:14:59 +0000163 {USDHC4_BASE_ADDR},
Fabio Estevam7891e252012-09-13 03:18:20 +0000164};
165
Shawn Guode7d02a2012-12-30 14:14:59 +0000166#define USDHC2_CD_GPIO IMX_GPIO_NR(2, 2)
167#define USDHC3_CD_GPIO IMX_GPIO_NR(2, 0)
168
Fabio Estevam7891e252012-09-13 03:18:20 +0000169int board_mmc_getcd(struct mmc *mmc)
170{
Shawn Guode7d02a2012-12-30 14:14:59 +0000171 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Otavio Salvador60bb4622013-03-16 08:05:06 +0000172 int ret = 0;
Shawn Guode7d02a2012-12-30 14:14:59 +0000173
174 switch (cfg->esdhc_base) {
175 case USDHC2_BASE_ADDR:
Otavio Salvador60bb4622013-03-16 08:05:06 +0000176 ret = !gpio_get_value(USDHC2_CD_GPIO);
177 break;
Shawn Guode7d02a2012-12-30 14:14:59 +0000178 case USDHC3_BASE_ADDR:
Otavio Salvador60bb4622013-03-16 08:05:06 +0000179 ret = !gpio_get_value(USDHC3_CD_GPIO);
180 break;
181 case USDHC4_BASE_ADDR:
182 ret = 1; /* eMMC/uSDHC4 is always present */
183 break;
Shawn Guode7d02a2012-12-30 14:14:59 +0000184 }
Otavio Salvador60bb4622013-03-16 08:05:06 +0000185
186 return ret;
Fabio Estevam7891e252012-09-13 03:18:20 +0000187}
188
189int board_mmc_init(bd_t *bis)
190{
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000191 s32 status = 0;
Shawn Guode7d02a2012-12-30 14:14:59 +0000192 int i;
Fabio Estevam7891e252012-09-13 03:18:20 +0000193
Otavio Salvador28ff9172013-03-16 08:05:05 +0000194 /*
195 * According to the board_mmc_init() the following map is done:
196 * (U-boot device node) (Physical Port)
197 * mmc0 SD2
198 * mmc1 SD3
199 * mmc2 eMMC
200 */
Shawn Guode7d02a2012-12-30 14:14:59 +0000201 for (i = 0; i < CONFIG_SYS_FSL_USDHC_NUM; i++) {
202 switch (i) {
203 case 0:
204 imx_iomux_v3_setup_multiple_pads(
205 usdhc2_pads, ARRAY_SIZE(usdhc2_pads));
206 gpio_direction_input(USDHC2_CD_GPIO);
207 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
208 break;
209 case 1:
210 imx_iomux_v3_setup_multiple_pads(
211 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
212 gpio_direction_input(USDHC3_CD_GPIO);
213 usdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
214 break;
215 case 2:
216 imx_iomux_v3_setup_multiple_pads(
217 usdhc4_pads, ARRAY_SIZE(usdhc4_pads));
218 usdhc_cfg[2].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
219 break;
220 default:
221 printf("Warning: you configured more USDHC controllers"
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000222 "(%d) then supported by the board (%d)\n",
223 i + 1, CONFIG_SYS_FSL_USDHC_NUM);
224 return status;
225 }
Shawn Guode7d02a2012-12-30 14:14:59 +0000226
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000227 status |= fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
Shawn Guode7d02a2012-12-30 14:14:59 +0000228 }
229
Otavio Salvadorf07e2862013-04-19 03:41:58 +0000230 return status;
Fabio Estevam7891e252012-09-13 03:18:20 +0000231}
232#endif
233
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000234int mx6_rgmii_rework(struct phy_device *phydev)
235{
236 unsigned short val;
237
238 /* To enable AR8031 ouput a 125MHz clk from CLK_25M */
239 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x7);
240 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, 0x8016);
241 phy_write(phydev, MDIO_DEVAD_NONE, 0xd, 0x4007);
242
243 val = phy_read(phydev, MDIO_DEVAD_NONE, 0xe);
244 val &= 0xffe3;
245 val |= 0x18;
246 phy_write(phydev, MDIO_DEVAD_NONE, 0xe, val);
247
248 /* introduce tx clock delay */
249 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x5);
250 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x1e);
251 val |= 0x0100;
252 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, val);
253
254 return 0;
255}
256
257int board_phy_config(struct phy_device *phydev)
258{
259 mx6_rgmii_rework(phydev);
260
261 if (phydev->drv->config)
262 phydev->drv->config(phydev);
263
264 return 0;
265}
266
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500267#if defined(CONFIG_VIDEO_IPUV3)
Fabio Estevamd9b89462013-09-04 15:12:38 -0300268struct display_info_t {
269 int bus;
270 int addr;
271 int pixfmt;
272 int (*detect)(struct display_info_t const *dev);
273 void (*enable)(struct display_info_t const *dev);
274 struct fb_videomode mode;
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500275};
276
Fabio Estevamd9b89462013-09-04 15:12:38 -0300277static int detect_hdmi(struct display_info_t const *dev)
278{
279 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
280 return readb(&hdmi->phy_stat0) & HDMI_DVI_STAT;
281}
282
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200283
284static void disable_lvds(struct display_info_t const *dev)
285{
286 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
287
288 int reg = readl(&iomux->gpr[2]);
289
290 reg &= ~(IOMUXC_GPR2_LVDS_CH0_MODE_MASK |
291 IOMUXC_GPR2_LVDS_CH1_MODE_MASK);
292
293 writel(reg, &iomux->gpr[2]);
294}
295
Fabio Estevamd9b89462013-09-04 15:12:38 -0300296static void do_enable_hdmi(struct display_info_t const *dev)
297{
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200298 disable_lvds(dev);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300299 imx_enable_hdmi_phy();
300}
301
302static void enable_lvds(struct display_info_t const *dev)
303{
304 struct iomuxc *iomux = (struct iomuxc *)
305 IOMUXC_BASE_ADDR;
306 u32 reg = readl(&iomux->gpr[2]);
Fabio Estevam119e9902013-12-04 01:08:17 -0200307 reg |= IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT |
308 IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300309 writel(reg, &iomux->gpr[2]);
310}
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200311
Fabio Estevamd9b89462013-09-04 15:12:38 -0300312static struct display_info_t const displays[] = {{
313 .bus = -1,
314 .addr = 0,
Fabio Estevam119e9902013-12-04 01:08:17 -0200315 .pixfmt = IPU_PIX_FMT_RGB666,
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200316 .detect = NULL,
317 .enable = enable_lvds,
Fabio Estevamd9b89462013-09-04 15:12:38 -0300318 .mode = {
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200319 .name = "Hannstar-XGA",
Fabio Estevamd9b89462013-09-04 15:12:38 -0300320 .refresh = 60,
321 .xres = 1024,
322 .yres = 768,
323 .pixclock = 15385,
324 .left_margin = 220,
325 .right_margin = 40,
326 .upper_margin = 21,
327 .lower_margin = 7,
328 .hsync_len = 60,
329 .vsync_len = 10,
330 .sync = FB_SYNC_EXT,
331 .vmode = FB_VMODE_NONINTERLACED
332} }, {
333 .bus = -1,
334 .addr = 0,
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200335 .pixfmt = IPU_PIX_FMT_RGB24,
336 .detect = detect_hdmi,
337 .enable = do_enable_hdmi,
Fabio Estevamd9b89462013-09-04 15:12:38 -0300338 .mode = {
Fabio Estevamb48e3b02013-11-25 10:34:26 -0200339 .name = "HDMI",
Fabio Estevamd9b89462013-09-04 15:12:38 -0300340 .refresh = 60,
341 .xres = 1024,
342 .yres = 768,
343 .pixclock = 15385,
344 .left_margin = 220,
345 .right_margin = 40,
346 .upper_margin = 21,
347 .lower_margin = 7,
348 .hsync_len = 60,
349 .vsync_len = 10,
350 .sync = FB_SYNC_EXT,
351 .vmode = FB_VMODE_NONINTERLACED
352} } };
353
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500354int board_video_skip(void)
355{
Fabio Estevamd9b89462013-09-04 15:12:38 -0300356 int i;
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500357 int ret;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300358 char const *panel = getenv("panel");
359 if (!panel) {
360 for (i = 0; i < ARRAY_SIZE(displays); i++) {
361 struct display_info_t const *dev = displays+i;
Fabio Estevam1601ba42013-09-11 18:14:29 -0300362 if (dev->detect && dev->detect(dev)) {
Fabio Estevamd9b89462013-09-04 15:12:38 -0300363 panel = dev->mode.name;
364 printf("auto-detected panel %s\n", panel);
365 break;
366 }
367 }
368 if (!panel) {
369 panel = displays[0].mode.name;
370 printf("No panel detected: default to %s\n", panel);
Fabio Estevam59f46f42013-09-11 18:14:30 -0300371 i = 0;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300372 }
373 } else {
374 for (i = 0; i < ARRAY_SIZE(displays); i++) {
375 if (!strcmp(panel, displays[i].mode.name))
376 break;
377 }
378 }
379 if (i < ARRAY_SIZE(displays)) {
380 ret = ipuv3_fb_init(&displays[i].mode, 0,
381 displays[i].pixfmt);
382 if (!ret) {
383 displays[i].enable(displays+i);
384 printf("Display: %s (%ux%u)\n",
385 displays[i].mode.name,
386 displays[i].mode.xres,
387 displays[i].mode.yres);
388 } else
389 printf("LCD %s cannot be configured: %d\n",
390 displays[i].mode.name, ret);
391 } else {
392 printf("unsupported panel %s\n", panel);
393 return -EINVAL;
394 }
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500395
Fabio Estevamd9b89462013-09-04 15:12:38 -0300396 return 0;
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500397}
398
399static void setup_display(void)
400{
401 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Fabio Estevamd9b89462013-09-04 15:12:38 -0300402 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500403 int reg;
404
Fabio Estevambe4ab3d2013-12-04 01:08:16 -0200405 /* Setup HSYNC, VSYNC, DISP_CLK for debugging purposes */
406 imx_iomux_v3_setup_multiple_pads(di0_pads, ARRAY_SIZE(di0_pads));
407
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500408 enable_ipu_clock();
409 imx_setup_hdmi();
410
Fabio Estevamd9b89462013-09-04 15:12:38 -0300411 /* Turn on LDB0, LDB1, IPU,IPU DI0 clocks */
Liu Ying12307432013-11-29 22:38:39 +0800412 reg = readl(&mxc_ccm->CCGR3);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300413 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK | MXC_CCM_CCGR3_LDB_DI1_MASK;
414 writel(reg, &mxc_ccm->CCGR3);
415
416 /* set LDB0, LDB1 clk select to 011/011 */
417 reg = readl(&mxc_ccm->cs2cdr);
418 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
419 | MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
420 reg |= (3 << MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
421 | (3 << MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
422 writel(reg, &mxc_ccm->cs2cdr);
423
424 reg = readl(&mxc_ccm->cscmr2);
425 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV | MXC_CCM_CSCMR2_LDB_DI1_IPU_DIV;
426 writel(reg, &mxc_ccm->cscmr2);
427
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500428 reg = readl(&mxc_ccm->chsccdr);
429 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
430 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300431 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
432 << MXC_CCM_CHSCCDR_IPU1_DI1_CLK_SEL_OFFSET);
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500433 writel(reg, &mxc_ccm->chsccdr);
Fabio Estevamd9b89462013-09-04 15:12:38 -0300434
435 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
436 | IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_LOW
437 | IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
438 | IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
439 | IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
440 | IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
441 | IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
442 | IOMUXC_GPR2_LVDS_CH0_MODE_DISABLED
443 | IOMUXC_GPR2_LVDS_CH1_MODE_ENABLED_DI0;
444 writel(reg, &iomux->gpr[2]);
445
446 reg = readl(&iomux->gpr[3]);
447 reg = (reg & ~(IOMUXC_GPR3_LVDS1_MUX_CTL_MASK
448 | IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
449 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
450 << IOMUXC_GPR3_LVDS1_MUX_CTL_OFFSET);
451 writel(reg, &iomux->gpr[3]);
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500452}
453#endif /* CONFIG_VIDEO_IPUV3 */
454
455/*
456 * Do not overwrite the console
457 * Use always serial for U-Boot console
458 */
459int overwrite_console(void)
460{
461 return 1;
462}
463
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000464int board_eth_init(bd_t *bis)
465{
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000466 setup_iomux_enet();
Marek Vasute919aa22014-03-23 22:45:41 +0100467 setup_pcie();
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000468
Fabio Estevam92c707a2014-01-04 17:36:32 -0200469 return cpu_eth_init(bis);
Fabio Estevama0d21fc2012-09-18 17:24:23 +0000470}
471
Fabio Estevam7891e252012-09-13 03:18:20 +0000472int board_early_init_f(void)
473{
474 setup_iomux_uart();
Pardeep Kumar Singla58cc9782013-07-25 12:12:14 -0500475#if defined(CONFIG_VIDEO_IPUV3)
476 setup_display();
477#endif
Fabio Estevam7891e252012-09-13 03:18:20 +0000478
479 return 0;
480}
481
482int board_init(void)
483{
484 /* address of boot parameters */
485 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
486
Fabio Estevam8bfa9c62013-11-08 16:20:54 -0200487#ifdef CONFIG_MXC_SPI
488 setup_spi();
489#endif
490
Fabio Estevam7891e252012-09-13 03:18:20 +0000491 return 0;
492}
493
Otavio Salvador85449db2013-03-16 08:05:07 +0000494#ifdef CONFIG_CMD_BMODE
495static const struct boot_mode board_boot_modes[] = {
496 /* 4 bit bus width */
497 {"sd2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
498 {"sd3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
499 /* 8 bit bus width */
500 {"emmc", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
501 {NULL, 0},
502};
503#endif
504
505int board_late_init(void)
506{
507#ifdef CONFIG_CMD_BMODE
508 add_board_boot_modes(board_boot_modes);
509#endif
510
511 return 0;
512}
513
Fabio Estevam7891e252012-09-13 03:18:20 +0000514int checkboard(void)
515{
Pierre Aubertc1747972013-06-04 09:00:15 +0200516 puts("Board: MX6-SabreSD\n");
Fabio Estevam7891e252012-09-13 03:18:20 +0000517 return 0;
518}