blob: 9cc758a17302ad61841ea434efd11b555beb470d [file] [log] [blame]
Stefano Babicf8f8acd2010-07-06 19:32:09 +02001/*
2 * (C) Copyright 2010
3 * Stefano Babic, DENX Software Engineering, sbabic@denx.de.
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
27#include <asm/io.h>
28#include <asm/arch/imx-regs.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020029#include <asm/arch/crm_regs.h>
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +000030#include <asm/arch/clock.h>
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +000031#include <asm/arch/iomux-mx51.h>
Stefano Babic4c0443c2011-08-21 10:57:53 +020032#include <asm/gpio.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020033#include <asm/arch/sys_proto.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020034#include <i2c.h>
35#include <mmc.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000036#include <power/pmic.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020037#include <fsl_esdhc.h>
38#include <fsl_pmic.h>
39#include <mc13892.h>
Stefano Babica0152c42010-10-21 10:34:39 +020040#include <linux/fb.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020041
Marek Vasut02ae1a12011-10-06 00:25:03 +020042#include <ipu_pixfmt.h>
43
Stefano Babicf8f8acd2010-07-06 19:32:09 +020044DECLARE_GLOBAL_DATA_PTR;
45
Eric Nelson08fd6a32012-10-03 07:27:39 +000046static struct fb_videomode const nec_nl6448bc26_09c = {
Stefano Babica0152c42010-10-21 10:34:39 +020047 "NEC_NL6448BC26-09C",
48 60, /* Refresh */
49 640, /* xres */
50 480, /* yres */
51 37650, /* pixclock = 26.56Mhz */
52 48, /* left margin */
53 16, /* right margin */
54 31, /* upper margin */
55 12, /* lower margin */
56 96, /* hsync-len */
57 2, /* vsync-len */
58 0, /* sync */
59 FB_VMODE_NONINTERLACED, /* vmode */
60 0, /* flag */
61};
62
Fabio Estevamc08f68c2011-05-10 07:50:46 +000063#ifdef CONFIG_HW_WATCHDOG
64#include <watchdog.h>
Stefano Babicf8f8acd2010-07-06 19:32:09 +020065void hw_watchdog_reset(void)
66{
67 int val;
68
69 /* toggle watchdog trigger pin */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +000070 val = gpio_get_value(IMX_GPIO_NR(3, 2));
Stefano Babicf8f8acd2010-07-06 19:32:09 +020071 val = val ? 0 : 1;
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +000072 gpio_set_value(IMX_GPIO_NR(3, 2), val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +020073}
74#endif
75
76static void init_drive_strength(void)
77{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +000078 static const iomux_v3_cfg_t ddr_pads[] = {
79 NEW_PAD_CTRL(MX51_GRP_PKEDDR, 0),
80 NEW_PAD_CTRL(MX51_GRP_PKEADDR, PAD_CTL_PKE),
81 NEW_PAD_CTRL(MX51_GRP_DDRAPKS, 0),
82 NEW_PAD_CTRL(MX51_GRP_DDRAPUS, PAD_CTL_PUS_100K_UP),
83 NEW_PAD_CTRL(MX51_GRP_DDR_SR_A1, PAD_CTL_SRE_FAST),
84 NEW_PAD_CTRL(MX51_GRP_DDR_A0, PAD_CTL_DSE_HIGH),
85 NEW_PAD_CTRL(MX51_GRP_DDR_A1, PAD_CTL_DSE_HIGH),
86 NEW_PAD_CTRL(MX51_PAD_DRAM_RAS__DRAM_RAS,
87 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
88 NEW_PAD_CTRL(MX51_PAD_DRAM_CAS__DRAM_CAS,
89 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
90 NEW_PAD_CTRL(MX51_GRP_PKEDDR, PAD_CTL_PKE),
91 NEW_PAD_CTRL(MX51_GRP_DDRPKS, 0),
92 NEW_PAD_CTRL(MX51_GRP_HYSDDR0, 0),
93 NEW_PAD_CTRL(MX51_GRP_HYSDDR1, 0),
94 NEW_PAD_CTRL(MX51_GRP_HYSDDR2, 0),
95 NEW_PAD_CTRL(MX51_GRP_HYSDDR3, 0),
96 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B0, PAD_CTL_SRE_FAST),
97 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B1, PAD_CTL_SRE_FAST),
98 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B2, PAD_CTL_SRE_FAST),
99 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B4, PAD_CTL_SRE_FAST),
100 NEW_PAD_CTRL(MX51_GRP_DDRPUS, PAD_CTL_PUS_100K_UP),
101 NEW_PAD_CTRL(MX51_GRP_INMODE1, 0),
102 NEW_PAD_CTRL(MX51_GRP_DRAM_B0, PAD_CTL_DSE_MED),
103 NEW_PAD_CTRL(MX51_GRP_DRAM_B1, PAD_CTL_DSE_MED),
104 NEW_PAD_CTRL(MX51_GRP_DRAM_B2, PAD_CTL_DSE_MED),
105 NEW_PAD_CTRL(MX51_GRP_DRAM_B4, PAD_CTL_DSE_MED),
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200106
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000107 NEW_PAD_CTRL(MX51_PAD_DRAM_SDWE__DRAM_SDWE, MX51_GPIO_PAD_CTRL),
108 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCKE0__DRAM_SDCKE0,
109 MX51_GPIO_PAD_CTRL),
110 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCKE1__DRAM_SDCKE1,
111 MX51_GPIO_PAD_CTRL),
112 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCLK__DRAM_SDCLK,
113 MX51_GPIO_PAD_CTRL),
114 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS0__DRAM_SDQS0,
115 MX51_GPIO_PAD_CTRL),
116 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS1__DRAM_SDQS1,
117 MX51_GPIO_PAD_CTRL),
118 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS2__DRAM_SDQS2,
119 MX51_GPIO_PAD_CTRL),
120 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS3__DRAM_SDQS3,
121 MX51_GPIO_PAD_CTRL),
122 NEW_PAD_CTRL(MX51_PAD_DRAM_CS0__DRAM_CS0, MX51_GPIO_PAD_CTRL),
123 NEW_PAD_CTRL(MX51_PAD_DRAM_CS1__DRAM_CS1, MX51_GPIO_PAD_CTRL),
124 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM0__DRAM_DQM0, MX51_GPIO_PAD_CTRL),
125 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM1__DRAM_DQM1, MX51_GPIO_PAD_CTRL),
126 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM2__DRAM_DQM2, MX51_GPIO_PAD_CTRL),
127 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM3__DRAM_DQM3, MX51_GPIO_PAD_CTRL),
128 };
129
130 imx_iomux_v3_setup_multiple_pads(ddr_pads, ARRAY_SIZE(ddr_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200131}
132
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200133int dram_init(void)
134{
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200135 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
136 PHYS_SDRAM_1_SIZE);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200137
138 return 0;
139}
140
141static void setup_weim(void)
142{
143 struct weim *pweim = (struct weim *)WEIM_BASE_ADDR;
144
Fabio Estevamea113822011-06-11 17:41:53 +0000145 pweim->cs0gcr1 = 0x004100b9;
146 pweim->cs0gcr2 = 0x00000001;
147 pweim->cs0rcr1 = 0x0a018000;
148 pweim->cs0rcr2 = 0;
149 pweim->cs0wcr1 = 0x0704a240;
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200150}
151
152static void setup_uart(void)
153{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000154 static const iomux_v3_cfg_t uart_pads[] = {
155 MX51_PAD_EIM_D25__UART3_RXD, /* console RX */
156 MX51_PAD_EIM_D26__UART3_TXD, /* console TX */
157 };
158
159 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200160}
161
162#ifdef CONFIG_MXC_SPI
163void spi_io_init(void)
164{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000165 static const iomux_v3_cfg_t spi_pads[] = {
166 NEW_PAD_CTRL(MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI, PAD_CTL_HYS |
167 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
168 NEW_PAD_CTRL(MX51_PAD_CSPI1_MISO__ECSPI1_MISO, PAD_CTL_HYS |
169 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
170 NEW_PAD_CTRL(MX51_PAD_CSPI1_SS0__ECSPI1_SS0, PAD_CTL_HYS |
171 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
172 NEW_PAD_CTRL(MX51_PAD_CSPI1_SS1__ECSPI1_SS1, PAD_CTL_HYS |
173 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
174 NEW_PAD_CTRL(MX51_PAD_DI1_PIN11__ECSPI1_SS2, PAD_CTL_HYS |
175 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
176 NEW_PAD_CTRL(MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK, PAD_CTL_HYS |
177 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
178 };
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200179
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000180 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200181}
182
183static void reset_peripherals(int reset)
184{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000185#ifdef CONFIG_VISION2_HW_1_0
186 static const iomux_v3_cfg_t fec_cfg_pads[] = {
187 /* RXD1 */
188 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__GPIO2_23, NO_PAD_CTRL),
189 /* RXD2 */
190 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, NO_PAD_CTRL),
191 /* RXD3 */
192 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__GPIO2_28, NO_PAD_CTRL),
193 /* RXER */
194 NEW_PAD_CTRL(MX51_PAD_EIM_CS4__GPIO2_29, NO_PAD_CTRL),
195 /* COL */
196 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__GPIO3_10, NO_PAD_CTRL),
197 /* RCLK */
198 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__GPIO3_11, NO_PAD_CTRL),
199 /* RXD0 */
200 NEW_PAD_CTRL(MX51_PAD_NANDF_D9__GPIO3_31, NO_PAD_CTRL),
201 };
202
203 static const iomux_v3_cfg_t fec_pads[] = {
204 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__FEC_RDATA3, MX51_PAD_CTRL_2),
205 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__FEC_RDATA2, MX51_PAD_CTRL_2),
206 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__FEC_RDATA1, MX51_PAD_CTRL_2),
207 MX51_PAD_NANDF_D9__FEC_RDATA0,
208 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__FEC_RX_CLK, MX51_PAD_CTRL_4),
209 MX51_PAD_EIM_CS4__FEC_RX_ER,
210 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__FEC_COL, MX51_PAD_CTRL_4),
211 };
212#endif
213
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200214 if (reset) {
215
216 /* reset_n is on NANDF_D15 */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000217 gpio_direction_output(IMX_GPIO_NR(3, 25), 0);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200218
219#ifdef CONFIG_VISION2_HW_1_0
220 /*
221 * set FEC Configuration lines
222 * set levels of FEC config lines
223 */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000224 gpio_direction_output(IMX_GPIO_NR(3, 11), 0);
225 gpio_direction_output(IMX_GPIO_NR(3, 10), 1);
226 gpio_direction_output(IMX_GPIO_NR(3, 31), 1);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200227
228 /* set direction of FEC config lines */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000229 gpio_direction_output(IMX_GPIO_NR(2, 27), 0);
230 gpio_direction_output(IMX_GPIO_NR(2, 28), 0);
231 gpio_direction_output(IMX_GPIO_NR(2, 29), 0);
232 gpio_direction_output(IMX_GPIO_NR(2, 23), 1);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200233
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000234 imx_iomux_v3_setup_multiple_pads(fec_cfg_pads,
235 ARRAY_SIZE(fec_cfg_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200236#endif
237
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000238 /* activate reset_n pin */
239 imx_iomux_v3_setup_pad(
240 NEW_PAD_CTRL(MX51_PAD_NANDF_D15__GPIO3_25,
241 PAD_CTL_DSE_MAX));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200242 } else {
243 /* set FEC Control lines */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000244 gpio_direction_input(IMX_GPIO_NR(3, 25));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200245 udelay(500);
246
247#ifdef CONFIG_VISION2_HW_1_0
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000248 imx_iomux_v3_setup_multiple_pads(fec_pads,
249 ARRAY_SIZE(fec_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200250#endif
251 }
252}
253
254static void power_init_mx51(void)
255{
256 unsigned int val;
Stefano Babicbac395e2011-10-02 12:58:03 +0200257 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000258 int ret;
Stefano Babicbac395e2011-10-02 12:58:03 +0200259
Łukasz Majewskic7336812012-11-13 03:21:55 +0000260 ret = pmic_init(I2C_PMIC);
261 if (ret)
262 return;
263
264 p = pmic_get("FSL_PMIC");
265 if (!p)
266 return;
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200267
268 /* Write needed to Power Gate 2 register */
Stefano Babicbac395e2011-10-02 12:58:03 +0200269 pmic_reg_read(p, REG_POWER_MISC, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200270
271 /* enable VCAM with 2.775V to enable read from PMIC */
272 val = VCAMCONFIG | VCAMEN;
Stefano Babicbac395e2011-10-02 12:58:03 +0200273 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200274
275 /*
276 * Set switchers in Auto in NORMAL mode & STANDBY mode
277 * Setup the switcher mode for SW1 & SW2
278 */
Stefano Babicbac395e2011-10-02 12:58:03 +0200279 pmic_reg_read(p, REG_SW_4, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200280 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
281 (SWMODE_MASK << SWMODE2_SHIFT)));
282 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
283 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babicbac395e2011-10-02 12:58:03 +0200284 pmic_reg_write(p, REG_SW_4, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200285
286 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babicbac395e2011-10-02 12:58:03 +0200287 pmic_reg_read(p, REG_SW_5, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200288 val &= ~((SWMODE_MASK << SWMODE4_SHIFT) |
289 (SWMODE_MASK << SWMODE3_SHIFT));
290 val |= (SWMODE_AUTO_AUTO << SWMODE4_SHIFT) |
291 (SWMODE_AUTO_AUTO << SWMODE3_SHIFT);
Stefano Babicbac395e2011-10-02 12:58:03 +0200292 pmic_reg_write(p, REG_SW_5, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200293
294
295 /* Set VGEN3 to 1.8V, VCAM to 3.0V */
Stefano Babicbac395e2011-10-02 12:58:03 +0200296 pmic_reg_read(p, REG_SETTING_0, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200297 val &= ~(VCAM_MASK | VGEN3_MASK);
298 val |= VCAM_3_0;
Stefano Babicbac395e2011-10-02 12:58:03 +0200299 pmic_reg_write(p, REG_SETTING_0, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200300
301 /* Set VVIDEO to 2.775V, VAUDIO to 3V0, VSD to 1.8V */
Stefano Babicbac395e2011-10-02 12:58:03 +0200302 pmic_reg_read(p, REG_SETTING_1, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200303 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
304 val |= VVIDEO_2_775 | VAUDIO_3_0 | VSD_1_8;
Stefano Babicbac395e2011-10-02 12:58:03 +0200305 pmic_reg_write(p, REG_SETTING_1, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200306
307 /* Configure VGEN3 and VCAM regulators to use external PNP */
308 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babicbac395e2011-10-02 12:58:03 +0200309 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200310 udelay(200);
311
312 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
313 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
314 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babicbac395e2011-10-02 12:58:03 +0200315 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200316
Stefano Babicbac395e2011-10-02 12:58:03 +0200317 pmic_reg_read(p, REG_POWER_CTL2, &val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200318 val |= WDIRESET;
Stefano Babicbac395e2011-10-02 12:58:03 +0200319 pmic_reg_write(p, REG_POWER_CTL2, val);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200320
321 udelay(2500);
322
323}
324#endif
325
326static void setup_gpios(void)
327{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000328 static const iomux_v3_cfg_t gpio_pads_1[] = {
329 NEW_PAD_CTRL(MX51_PAD_GPIO1_7__GPIO1_7, PAD_CTL_PKE |
330 PAD_CTL_DSE_MED), /* CAM_SUP_DISn */
331 NEW_PAD_CTRL(MX51_PAD_DI1_PIN12__GPIO3_1, PAD_CTL_PKE |
332 PAD_CTL_DSE_MED), /* DAB Display EN */
333 NEW_PAD_CTRL(MX51_PAD_DI1_PIN13__GPIO3_2, PAD_CTL_PKE |
334 PAD_CTL_DSE_MED), /* WDOG_TRIGGER */
335 };
336
337 static const iomux_v3_cfg_t gpio_pads_2[] = {
338 NEW_PAD_CTRL(MX51_PAD_DI1_D0_CS__GPIO3_3, PAD_CTL_PKE |
339 PAD_CTL_DSE_MED), /* Display2 TxEN */
340 NEW_PAD_CTRL(MX51_PAD_DI1_D1_CS__GPIO3_4, PAD_CTL_PKE |
341 PAD_CTL_DSE_MED), /* DAB Light EN */
342 NEW_PAD_CTRL(MX51_PAD_DISPB2_SER_DIN__GPIO3_5, PAD_CTL_PKE |
343 PAD_CTL_DSE_MED), /* AUDIO_MUTE */
344 NEW_PAD_CTRL(MX51_PAD_DISPB2_SER_DIO__GPIO3_6, PAD_CTL_PKE |
345 PAD_CTL_DSE_MED), /* SPARE_OUT */
346 NEW_PAD_CTRL(MX51_PAD_NANDF_D14__GPIO3_26, PAD_CTL_PKE |
347 PAD_CTL_DSE_MED), /* BEEPER_EN */
348 NEW_PAD_CTRL(MX51_PAD_NANDF_D13__GPIO3_27, PAD_CTL_PKE |
349 PAD_CTL_DSE_MED), /* POWER_OFF */
350 NEW_PAD_CTRL(MX51_PAD_NANDF_D10__GPIO3_30, PAD_CTL_PKE |
351 PAD_CTL_DSE_MED), /* FRAM_WE */
352 NEW_PAD_CTRL(MX51_PAD_CSPI1_RDY__GPIO4_26, PAD_CTL_PKE |
353 PAD_CTL_DSE_MED), /* EXPANSION_EN */
354 MX51_PAD_GPIO1_2__PWM1_PWMO,
355 };
356
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200357 unsigned int i;
358
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000359 imx_iomux_v3_setup_multiple_pads(gpio_pads_1, ARRAY_SIZE(gpio_pads_1));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200360
361 /* Now we need to trigger the watchdog */
362 WATCHDOG_RESET();
363
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000364 imx_iomux_v3_setup_multiple_pads(gpio_pads_2, ARRAY_SIZE(gpio_pads_2));
Stefano Babica0152c42010-10-21 10:34:39 +0200365
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200366 /*
367 * Set GPIO1_4 to high and output; it is used to reset
368 * the system on reboot
369 */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000370 gpio_direction_output(IMX_GPIO_NR(1, 4), 1);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200371
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000372 gpio_direction_output(IMX_GPIO_NR(1, 7), 0);
373 for (i = IMX_GPIO_NR(3, 1); i < IMX_GPIO_NR(3, 7); i++)
Stefano Babic4c0443c2011-08-21 10:57:53 +0200374 gpio_direction_output(i, 0);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200375
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000376 gpio_direction_output(IMX_GPIO_NR(3, 30), 0);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200377
378 /* Set POWER_OFF high */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000379 gpio_direction_output(IMX_GPIO_NR(3, 27), 1);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200380
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000381 gpio_direction_output(IMX_GPIO_NR(3, 26), 0);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200382
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000383 gpio_direction_output(IMX_GPIO_NR(4, 26), 0);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200384
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000385 gpio_direction_output(IMX_GPIO_NR(4, 25), 1);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200386
387 WATCHDOG_RESET();
388}
389
390static void setup_fec(void)
391{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000392 static const iomux_v3_cfg_t fec_pads[] = {
393 NEW_PAD_CTRL(MX51_PAD_EIM_EB2__FEC_MDIO, PAD_CTL_HYS |
394 PAD_CTL_PUS_22K_UP | PAD_CTL_ODE |
395 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
396 MX51_PAD_NANDF_CS3__FEC_MDC,
397 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__FEC_RDATA3, MX51_PAD_CTRL_2),
398 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__FEC_RDATA2, MX51_PAD_CTRL_2),
399 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__FEC_RDATA1, MX51_PAD_CTRL_2),
400 MX51_PAD_NANDF_D9__FEC_RDATA0,
401 MX51_PAD_NANDF_CS6__FEC_TDATA3,
402 MX51_PAD_NANDF_CS5__FEC_TDATA2,
403 MX51_PAD_NANDF_CS4__FEC_TDATA1,
404 MX51_PAD_NANDF_D8__FEC_TDATA0,
405 MX51_PAD_NANDF_CS7__FEC_TX_EN,
406 MX51_PAD_NANDF_CS2__FEC_TX_ER,
407 MX51_PAD_NANDF_RDY_INT__FEC_TX_CLK,
408 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__FEC_COL, MX51_PAD_CTRL_4),
409 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__FEC_RX_CLK, MX51_PAD_CTRL_4),
410 MX51_PAD_EIM_CS5__FEC_CRS,
411 MX51_PAD_EIM_CS4__FEC_RX_ER,
412 NEW_PAD_CTRL(MX51_PAD_NANDF_D11__FEC_RX_DV, MX51_PAD_CTRL_4),
413 };
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200414
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000415 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200416}
417
418struct fsl_esdhc_cfg esdhc_cfg[1] = {
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000419 {MMC_SDHC1_BASE_ADDR},
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200420};
421
422int get_mmc_getcd(u8 *cd, struct mmc *mmc)
423{
424 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
425
426 if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000427 *cd = gpio_get_value(IMX_GPIO_NR(1, 0));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200428 else
429 *cd = 0;
430
431 return 0;
432}
433
434#ifdef CONFIG_FSL_ESDHC
435int board_mmc_init(bd_t *bis)
436{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000437 static const iomux_v3_cfg_t sd1_pads[] = {
438 NEW_PAD_CTRL(MX51_PAD_SD1_CMD__SD1_CMD, PAD_CTL_DSE_MAX |
439 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
440 NEW_PAD_CTRL(MX51_PAD_SD1_CLK__SD1_CLK, PAD_CTL_DSE_MAX |
441 PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
442 NEW_PAD_CTRL(MX51_PAD_SD1_DATA0__SD1_DATA0, PAD_CTL_DSE_MAX |
443 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
444 NEW_PAD_CTRL(MX51_PAD_SD1_DATA1__SD1_DATA1, PAD_CTL_DSE_MAX |
445 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
446 NEW_PAD_CTRL(MX51_PAD_SD1_DATA2__SD1_DATA2, PAD_CTL_DSE_MAX |
447 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
448 NEW_PAD_CTRL(MX51_PAD_SD1_DATA3__SD1_DATA3, PAD_CTL_DSE_MAX |
449 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_SRE_FAST),
450 NEW_PAD_CTRL(MX51_PAD_GPIO1_0__SD1_CD, PAD_CTL_HYS),
451 NEW_PAD_CTRL(MX51_PAD_GPIO1_1__SD1_WP, PAD_CTL_HYS),
452 };
453
454 imx_iomux_v3_setup_multiple_pads(sd1_pads, ARRAY_SIZE(sd1_pads));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200455
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000456 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200457 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
458}
459#endif
460
Stefano Babice9934f02011-09-28 11:21:15 +0200461void lcd_enable(void)
462{
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000463 static const iomux_v3_cfg_t lcd_pads[] = {
464 MX51_PAD_DI1_PIN2__DI1_PIN2,
465 MX51_PAD_DI1_PIN3__DI1_PIN3,
466 };
467
Stefano Babice9934f02011-09-28 11:21:15 +0200468 int ret;
469
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000470 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
Stefano Babice9934f02011-09-28 11:21:15 +0200471
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000472 gpio_set_value(IMX_GPIO_NR(1, 2), 1);
473 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_GPIO1_2__GPIO1_2,
474 NO_PAD_CTRL));
Stefano Babice9934f02011-09-28 11:21:15 +0200475
Fabio Estevama1b0e192012-05-10 15:07:34 +0000476 ret = ipuv3_fb_init(&nec_nl6448bc26_09c, 0, IPU_PIX_FMT_RGB666);
Stefano Babice9934f02011-09-28 11:21:15 +0200477 if (ret)
478 puts("LCD cannot be configured\n");
479}
480
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200481int board_early_init_f(void)
482{
483
484
485 init_drive_strength();
486
487 /* Setup debug led */
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000488 gpio_direction_output(IMX_GPIO_NR(1, 6), 0);
489 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_GPIO1_6__GPIO1_6,
490 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST));
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200491
492 /* wait a little while to give the pll time to settle */
493 sdelay(100000);
494
495 setup_weim();
496 setup_uart();
497 setup_fec();
498 setup_gpios();
499
500 spi_io_init();
501
502 return 0;
503}
504
Stefano Babica0152c42010-10-21 10:34:39 +0200505static void backlight(int on)
506{
507 if (on) {
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000508 gpio_set_value(IMX_GPIO_NR(3, 1), 1);
Stefano Babica0152c42010-10-21 10:34:39 +0200509 udelay(10000);
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000510 gpio_set_value(IMX_GPIO_NR(3, 4), 1);
Stefano Babica0152c42010-10-21 10:34:39 +0200511 } else {
Benoît Thébaudeau6ea42172013-05-03 10:32:29 +0000512 gpio_set_value(IMX_GPIO_NR(3, 1), 0);
513 gpio_set_value(IMX_GPIO_NR(3, 4), 0);
Stefano Babica0152c42010-10-21 10:34:39 +0200514 }
515}
516
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200517int board_init(void)
518{
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200519 /* address of boot parameters */
520 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
521
Stefano Babice9934f02011-09-28 11:21:15 +0200522 lcd_enable();
523
524 backlight(1);
525
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200526 return 0;
527}
528
529int board_late_init(void)
530{
531 power_init_mx51();
532
533 reset_peripherals(1);
534 udelay(2000);
535 reset_peripherals(0);
536 udelay(2000);
537
538 /* Early revisions require a second reset */
539#ifdef CONFIG_VISION2_HW_1_0
540 reset_peripherals(1);
541 udelay(2000);
542 reset_peripherals(0);
543 udelay(2000);
544#endif
545
546 return 0;
547}
548
Fabio Estevamfca37fc2012-08-05 07:31:34 +0000549/*
550 * Do not overwrite the console
551 * Use always serial for U-Boot console
552 */
553int overwrite_console(void)
554{
555 return 1;
556}
557
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200558int checkboard(void)
559{
Jason Liu51958902011-04-22 02:55:42 +0000560 puts("Board: TTControl Vision II CPU V\n");
Stefano Babicf8f8acd2010-07-06 19:32:09 +0200561
562 return 0;
563}
564
Stefano Babica0152c42010-10-21 10:34:39 +0200565int do_vision_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
566{
567 int on;
568
569 if (argc < 2)
570 return cmd_usage(cmdtp);
571
572 on = (strcmp(argv[1], "on") == 0);
573 backlight(on);
574
575 return 0;
576}
577
578U_BOOT_CMD(
579 lcdbl, CONFIG_SYS_MAXARGS, 1, do_vision_lcd,
580 "Vision2 Backlight",
581 "lcdbl [on|off]\n"
582);