blob: b5249e74a779a3a1b1f16a9be3a5c9a9c5c32521 [file] [log] [blame]
Stefano Babice1b6f592010-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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Stefano Babice1b6f592010-07-06 19:32:09 +02008 */
9
10#include <common.h>
11#include <asm/io.h>
12#include <asm/arch/imx-regs.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020013#include <asm/arch/crm_regs.h>
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +000014#include <asm/arch/clock.h>
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +000015#include <asm/arch/iomux-mx51.h>
Stefano Babic60d973d2011-08-21 10:57:53 +020016#include <asm/gpio.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020017#include <asm/arch/sys_proto.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020018#include <i2c.h>
19#include <mmc.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000020#include <power/pmic.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020021#include <fsl_esdhc.h>
22#include <fsl_pmic.h>
23#include <mc13892.h>
Stefano Babic445a4822010-10-21 10:34:39 +020024#include <linux/fb.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020025
Marek Vasutff5c108c2011-10-06 00:25:03 +020026#include <ipu_pixfmt.h>
27
Stefano Babice1b6f592010-07-06 19:32:09 +020028DECLARE_GLOBAL_DATA_PTR;
29
Eric Nelson1c39f122012-10-03 07:27:39 +000030static struct fb_videomode const nec_nl6448bc26_09c = {
Stefano Babic445a4822010-10-21 10:34:39 +020031 "NEC_NL6448BC26-09C",
32 60, /* Refresh */
33 640, /* xres */
34 480, /* yres */
35 37650, /* pixclock = 26.56Mhz */
36 48, /* left margin */
37 16, /* right margin */
38 31, /* upper margin */
39 12, /* lower margin */
40 96, /* hsync-len */
41 2, /* vsync-len */
42 0, /* sync */
43 FB_VMODE_NONINTERLACED, /* vmode */
44 0, /* flag */
45};
46
Fabio Estevam1c711b92011-05-10 07:50:46 +000047#ifdef CONFIG_HW_WATCHDOG
48#include <watchdog.h>
Stefano Babice1b6f592010-07-06 19:32:09 +020049void hw_watchdog_reset(void)
50{
51 int val;
52
53 /* toggle watchdog trigger pin */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +000054 val = gpio_get_value(IMX_GPIO_NR(3, 2));
Stefano Babice1b6f592010-07-06 19:32:09 +020055 val = val ? 0 : 1;
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +000056 gpio_set_value(IMX_GPIO_NR(3, 2), val);
Stefano Babice1b6f592010-07-06 19:32:09 +020057}
58#endif
59
60static void init_drive_strength(void)
61{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +000062 static const iomux_v3_cfg_t ddr_pads[] = {
63 NEW_PAD_CTRL(MX51_GRP_PKEDDR, 0),
64 NEW_PAD_CTRL(MX51_GRP_PKEADDR, PAD_CTL_PKE),
65 NEW_PAD_CTRL(MX51_GRP_DDRAPKS, 0),
66 NEW_PAD_CTRL(MX51_GRP_DDRAPUS, PAD_CTL_PUS_100K_UP),
67 NEW_PAD_CTRL(MX51_GRP_DDR_SR_A1, PAD_CTL_SRE_FAST),
68 NEW_PAD_CTRL(MX51_GRP_DDR_A0, PAD_CTL_DSE_HIGH),
69 NEW_PAD_CTRL(MX51_GRP_DDR_A1, PAD_CTL_DSE_HIGH),
70 NEW_PAD_CTRL(MX51_PAD_DRAM_RAS__DRAM_RAS,
71 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
72 NEW_PAD_CTRL(MX51_PAD_DRAM_CAS__DRAM_CAS,
73 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
74 NEW_PAD_CTRL(MX51_GRP_PKEDDR, PAD_CTL_PKE),
75 NEW_PAD_CTRL(MX51_GRP_DDRPKS, 0),
76 NEW_PAD_CTRL(MX51_GRP_HYSDDR0, 0),
77 NEW_PAD_CTRL(MX51_GRP_HYSDDR1, 0),
78 NEW_PAD_CTRL(MX51_GRP_HYSDDR2, 0),
79 NEW_PAD_CTRL(MX51_GRP_HYSDDR3, 0),
80 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B0, PAD_CTL_SRE_FAST),
81 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B1, PAD_CTL_SRE_FAST),
82 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B2, PAD_CTL_SRE_FAST),
83 NEW_PAD_CTRL(MX51_GRP_DRAM_SR_B4, PAD_CTL_SRE_FAST),
84 NEW_PAD_CTRL(MX51_GRP_DDRPUS, PAD_CTL_PUS_100K_UP),
85 NEW_PAD_CTRL(MX51_GRP_INMODE1, 0),
86 NEW_PAD_CTRL(MX51_GRP_DRAM_B0, PAD_CTL_DSE_MED),
87 NEW_PAD_CTRL(MX51_GRP_DRAM_B1, PAD_CTL_DSE_MED),
88 NEW_PAD_CTRL(MX51_GRP_DRAM_B2, PAD_CTL_DSE_MED),
89 NEW_PAD_CTRL(MX51_GRP_DRAM_B4, PAD_CTL_DSE_MED),
Stefano Babice1b6f592010-07-06 19:32:09 +020090
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +000091 NEW_PAD_CTRL(MX51_PAD_DRAM_SDWE__DRAM_SDWE, MX51_GPIO_PAD_CTRL),
92 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCKE0__DRAM_SDCKE0,
93 MX51_GPIO_PAD_CTRL),
94 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCKE1__DRAM_SDCKE1,
95 MX51_GPIO_PAD_CTRL),
96 NEW_PAD_CTRL(MX51_PAD_DRAM_SDCLK__DRAM_SDCLK,
97 MX51_GPIO_PAD_CTRL),
98 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS0__DRAM_SDQS0,
99 MX51_GPIO_PAD_CTRL),
100 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS1__DRAM_SDQS1,
101 MX51_GPIO_PAD_CTRL),
102 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS2__DRAM_SDQS2,
103 MX51_GPIO_PAD_CTRL),
104 NEW_PAD_CTRL(MX51_PAD_DRAM_SDQS3__DRAM_SDQS3,
105 MX51_GPIO_PAD_CTRL),
106 NEW_PAD_CTRL(MX51_PAD_DRAM_CS0__DRAM_CS0, MX51_GPIO_PAD_CTRL),
107 NEW_PAD_CTRL(MX51_PAD_DRAM_CS1__DRAM_CS1, MX51_GPIO_PAD_CTRL),
108 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM0__DRAM_DQM0, MX51_GPIO_PAD_CTRL),
109 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM1__DRAM_DQM1, MX51_GPIO_PAD_CTRL),
110 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM2__DRAM_DQM2, MX51_GPIO_PAD_CTRL),
111 NEW_PAD_CTRL(MX51_PAD_DRAM_DQM3__DRAM_DQM3, MX51_GPIO_PAD_CTRL),
112 };
113
114 imx_iomux_v3_setup_multiple_pads(ddr_pads, ARRAY_SIZE(ddr_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200115}
116
Stefano Babice1b6f592010-07-06 19:32:09 +0200117int dram_init(void)
118{
Stefano Babice1b6f592010-07-06 19:32:09 +0200119 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
120 PHYS_SDRAM_1_SIZE);
Stefano Babice1b6f592010-07-06 19:32:09 +0200121
122 return 0;
123}
124
125static void setup_weim(void)
126{
127 struct weim *pweim = (struct weim *)WEIM_BASE_ADDR;
128
Fabio Estevamf8252972011-06-11 17:41:53 +0000129 pweim->cs0gcr1 = 0x004100b9;
130 pweim->cs0gcr2 = 0x00000001;
131 pweim->cs0rcr1 = 0x0a018000;
132 pweim->cs0rcr2 = 0;
133 pweim->cs0wcr1 = 0x0704a240;
Stefano Babice1b6f592010-07-06 19:32:09 +0200134}
135
136static void setup_uart(void)
137{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000138 static const iomux_v3_cfg_t uart_pads[] = {
139 MX51_PAD_EIM_D25__UART3_RXD, /* console RX */
140 MX51_PAD_EIM_D26__UART3_TXD, /* console TX */
141 };
142
143 imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200144}
145
146#ifdef CONFIG_MXC_SPI
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300147int board_spi_cs_gpio(unsigned bus, unsigned cs)
148{
149 return (bus == 0 && cs == 1) ? 121 : -1;
150}
151
Stefano Babice1b6f592010-07-06 19:32:09 +0200152void spi_io_init(void)
153{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000154 static const iomux_v3_cfg_t spi_pads[] = {
155 NEW_PAD_CTRL(MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI, PAD_CTL_HYS |
156 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
157 NEW_PAD_CTRL(MX51_PAD_CSPI1_MISO__ECSPI1_MISO, PAD_CTL_HYS |
158 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
159 NEW_PAD_CTRL(MX51_PAD_CSPI1_SS0__ECSPI1_SS0, PAD_CTL_HYS |
160 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
161 NEW_PAD_CTRL(MX51_PAD_CSPI1_SS1__ECSPI1_SS1, PAD_CTL_HYS |
162 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
163 NEW_PAD_CTRL(MX51_PAD_DI1_PIN11__ECSPI1_SS2, PAD_CTL_HYS |
164 PAD_CTL_PKE | PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
165 NEW_PAD_CTRL(MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK, PAD_CTL_HYS |
166 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST),
167 };
Stefano Babice1b6f592010-07-06 19:32:09 +0200168
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000169 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200170}
171
172static void reset_peripherals(int reset)
173{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000174#ifdef CONFIG_VISION2_HW_1_0
175 static const iomux_v3_cfg_t fec_cfg_pads[] = {
176 /* RXD1 */
177 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__GPIO2_23, NO_PAD_CTRL),
178 /* RXD2 */
179 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, NO_PAD_CTRL),
180 /* RXD3 */
181 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__GPIO2_28, NO_PAD_CTRL),
182 /* RXER */
183 NEW_PAD_CTRL(MX51_PAD_EIM_CS4__GPIO2_29, NO_PAD_CTRL),
184 /* COL */
185 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__GPIO3_10, NO_PAD_CTRL),
186 /* RCLK */
187 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__GPIO3_11, NO_PAD_CTRL),
188 /* RXD0 */
189 NEW_PAD_CTRL(MX51_PAD_NANDF_D9__GPIO3_31, NO_PAD_CTRL),
190 };
191
192 static const iomux_v3_cfg_t fec_pads[] = {
193 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__FEC_RDATA3, MX51_PAD_CTRL_2),
194 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__FEC_RDATA2, MX51_PAD_CTRL_2),
195 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__FEC_RDATA1, MX51_PAD_CTRL_2),
196 MX51_PAD_NANDF_D9__FEC_RDATA0,
197 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__FEC_RX_CLK, MX51_PAD_CTRL_4),
198 MX51_PAD_EIM_CS4__FEC_RX_ER,
199 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__FEC_COL, MX51_PAD_CTRL_4),
200 };
201#endif
202
Stefano Babice1b6f592010-07-06 19:32:09 +0200203 if (reset) {
204
205 /* reset_n is on NANDF_D15 */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000206 gpio_direction_output(IMX_GPIO_NR(3, 25), 0);
Stefano Babice1b6f592010-07-06 19:32:09 +0200207
208#ifdef CONFIG_VISION2_HW_1_0
209 /*
210 * set FEC Configuration lines
211 * set levels of FEC config lines
212 */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000213 gpio_direction_output(IMX_GPIO_NR(3, 11), 0);
214 gpio_direction_output(IMX_GPIO_NR(3, 10), 1);
215 gpio_direction_output(IMX_GPIO_NR(3, 31), 1);
Stefano Babice1b6f592010-07-06 19:32:09 +0200216
217 /* set direction of FEC config lines */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000218 gpio_direction_output(IMX_GPIO_NR(2, 27), 0);
219 gpio_direction_output(IMX_GPIO_NR(2, 28), 0);
220 gpio_direction_output(IMX_GPIO_NR(2, 29), 0);
221 gpio_direction_output(IMX_GPIO_NR(2, 23), 1);
Stefano Babice1b6f592010-07-06 19:32:09 +0200222
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000223 imx_iomux_v3_setup_multiple_pads(fec_cfg_pads,
224 ARRAY_SIZE(fec_cfg_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200225#endif
226
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000227 /* activate reset_n pin */
228 imx_iomux_v3_setup_pad(
229 NEW_PAD_CTRL(MX51_PAD_NANDF_D15__GPIO3_25,
230 PAD_CTL_DSE_MAX));
Stefano Babice1b6f592010-07-06 19:32:09 +0200231 } else {
232 /* set FEC Control lines */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000233 gpio_direction_input(IMX_GPIO_NR(3, 25));
Stefano Babice1b6f592010-07-06 19:32:09 +0200234 udelay(500);
235
236#ifdef CONFIG_VISION2_HW_1_0
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000237 imx_iomux_v3_setup_multiple_pads(fec_pads,
238 ARRAY_SIZE(fec_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200239#endif
240 }
241}
242
243static void power_init_mx51(void)
244{
245 unsigned int val;
Stefano Babic470760e2011-10-02 12:58:03 +0200246 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000247 int ret;
248
249 ret = pmic_init(I2C_PMIC);
250 if (ret)
251 return;
Stefano Babic470760e2011-10-02 12:58:03 +0200252
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000253 p = pmic_get("FSL_PMIC");
254 if (!p)
255 return;
Stefano Babice1b6f592010-07-06 19:32:09 +0200256
257 /* Write needed to Power Gate 2 register */
Stefano Babic470760e2011-10-02 12:58:03 +0200258 pmic_reg_read(p, REG_POWER_MISC, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200259
260 /* enable VCAM with 2.775V to enable read from PMIC */
261 val = VCAMCONFIG | VCAMEN;
Stefano Babic470760e2011-10-02 12:58:03 +0200262 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200263
264 /*
265 * Set switchers in Auto in NORMAL mode & STANDBY mode
266 * Setup the switcher mode for SW1 & SW2
267 */
Stefano Babic470760e2011-10-02 12:58:03 +0200268 pmic_reg_read(p, REG_SW_4, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200269 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
270 (SWMODE_MASK << SWMODE2_SHIFT)));
271 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
272 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babic470760e2011-10-02 12:58:03 +0200273 pmic_reg_write(p, REG_SW_4, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200274
275 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babic470760e2011-10-02 12:58:03 +0200276 pmic_reg_read(p, REG_SW_5, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200277 val &= ~((SWMODE_MASK << SWMODE4_SHIFT) |
278 (SWMODE_MASK << SWMODE3_SHIFT));
279 val |= (SWMODE_AUTO_AUTO << SWMODE4_SHIFT) |
280 (SWMODE_AUTO_AUTO << SWMODE3_SHIFT);
Stefano Babic470760e2011-10-02 12:58:03 +0200281 pmic_reg_write(p, REG_SW_5, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200282
283
284 /* Set VGEN3 to 1.8V, VCAM to 3.0V */
Stefano Babic470760e2011-10-02 12:58:03 +0200285 pmic_reg_read(p, REG_SETTING_0, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200286 val &= ~(VCAM_MASK | VGEN3_MASK);
287 val |= VCAM_3_0;
Stefano Babic470760e2011-10-02 12:58:03 +0200288 pmic_reg_write(p, REG_SETTING_0, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200289
290 /* Set VVIDEO to 2.775V, VAUDIO to 3V0, VSD to 1.8V */
Stefano Babic470760e2011-10-02 12:58:03 +0200291 pmic_reg_read(p, REG_SETTING_1, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200292 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
293 val |= VVIDEO_2_775 | VAUDIO_3_0 | VSD_1_8;
Stefano Babic470760e2011-10-02 12:58:03 +0200294 pmic_reg_write(p, REG_SETTING_1, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200295
296 /* Configure VGEN3 and VCAM regulators to use external PNP */
297 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babic470760e2011-10-02 12:58:03 +0200298 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200299 udelay(200);
300
301 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
302 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
303 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babic470760e2011-10-02 12:58:03 +0200304 pmic_reg_write(p, REG_MODE_1, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200305
Stefano Babic470760e2011-10-02 12:58:03 +0200306 pmic_reg_read(p, REG_POWER_CTL2, &val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200307 val |= WDIRESET;
Stefano Babic470760e2011-10-02 12:58:03 +0200308 pmic_reg_write(p, REG_POWER_CTL2, val);
Stefano Babice1b6f592010-07-06 19:32:09 +0200309
310 udelay(2500);
311
312}
313#endif
314
315static void setup_gpios(void)
316{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000317 static const iomux_v3_cfg_t gpio_pads_1[] = {
318 NEW_PAD_CTRL(MX51_PAD_GPIO1_7__GPIO1_7, PAD_CTL_PKE |
319 PAD_CTL_DSE_MED), /* CAM_SUP_DISn */
320 NEW_PAD_CTRL(MX51_PAD_DI1_PIN12__GPIO3_1, PAD_CTL_PKE |
321 PAD_CTL_DSE_MED), /* DAB Display EN */
322 NEW_PAD_CTRL(MX51_PAD_DI1_PIN13__GPIO3_2, PAD_CTL_PKE |
323 PAD_CTL_DSE_MED), /* WDOG_TRIGGER */
324 };
Stefano Babice1b6f592010-07-06 19:32:09 +0200325
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000326 static const iomux_v3_cfg_t gpio_pads_2[] = {
327 NEW_PAD_CTRL(MX51_PAD_DI1_D0_CS__GPIO3_3, PAD_CTL_PKE |
328 PAD_CTL_DSE_MED), /* Display2 TxEN */
329 NEW_PAD_CTRL(MX51_PAD_DI1_D1_CS__GPIO3_4, PAD_CTL_PKE |
330 PAD_CTL_DSE_MED), /* DAB Light EN */
331 NEW_PAD_CTRL(MX51_PAD_DISPB2_SER_DIN__GPIO3_5, PAD_CTL_PKE |
332 PAD_CTL_DSE_MED), /* AUDIO_MUTE */
333 NEW_PAD_CTRL(MX51_PAD_DISPB2_SER_DIO__GPIO3_6, PAD_CTL_PKE |
334 PAD_CTL_DSE_MED), /* SPARE_OUT */
335 NEW_PAD_CTRL(MX51_PAD_NANDF_D14__GPIO3_26, PAD_CTL_PKE |
336 PAD_CTL_DSE_MED), /* BEEPER_EN */
337 NEW_PAD_CTRL(MX51_PAD_NANDF_D13__GPIO3_27, PAD_CTL_PKE |
338 PAD_CTL_DSE_MED), /* POWER_OFF */
339 NEW_PAD_CTRL(MX51_PAD_NANDF_D10__GPIO3_30, PAD_CTL_PKE |
340 PAD_CTL_DSE_MED), /* FRAM_WE */
341 NEW_PAD_CTRL(MX51_PAD_CSPI1_RDY__GPIO4_26, PAD_CTL_PKE |
342 PAD_CTL_DSE_MED), /* EXPANSION_EN */
343 MX51_PAD_GPIO1_2__PWM1_PWMO,
344 };
Stefano Babice1b6f592010-07-06 19:32:09 +0200345
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000346 unsigned int i;
Stefano Babice1b6f592010-07-06 19:32:09 +0200347
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000348 imx_iomux_v3_setup_multiple_pads(gpio_pads_1, ARRAY_SIZE(gpio_pads_1));
Stefano Babice1b6f592010-07-06 19:32:09 +0200349
350 /* Now we need to trigger the watchdog */
351 WATCHDOG_RESET();
352
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000353 imx_iomux_v3_setup_multiple_pads(gpio_pads_2, ARRAY_SIZE(gpio_pads_2));
Stefano Babic445a4822010-10-21 10:34:39 +0200354
Stefano Babice1b6f592010-07-06 19:32:09 +0200355 /*
356 * Set GPIO1_4 to high and output; it is used to reset
357 * the system on reboot
358 */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000359 gpio_direction_output(IMX_GPIO_NR(1, 4), 1);
Stefano Babice1b6f592010-07-06 19:32:09 +0200360
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000361 gpio_direction_output(IMX_GPIO_NR(1, 7), 0);
362 for (i = IMX_GPIO_NR(3, 1); i < IMX_GPIO_NR(3, 7); i++)
Stefano Babic60d973d2011-08-21 10:57:53 +0200363 gpio_direction_output(i, 0);
Stefano Babice1b6f592010-07-06 19:32:09 +0200364
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000365 gpio_direction_output(IMX_GPIO_NR(3, 30), 0);
Stefano Babice1b6f592010-07-06 19:32:09 +0200366
367 /* Set POWER_OFF high */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000368 gpio_direction_output(IMX_GPIO_NR(3, 27), 1);
Stefano Babice1b6f592010-07-06 19:32:09 +0200369
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000370 gpio_direction_output(IMX_GPIO_NR(3, 26), 0);
Stefano Babice1b6f592010-07-06 19:32:09 +0200371
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000372 gpio_direction_output(IMX_GPIO_NR(4, 26), 0);
Stefano Babice1b6f592010-07-06 19:32:09 +0200373
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000374 gpio_direction_output(IMX_GPIO_NR(4, 25), 1);
Stefano Babice1b6f592010-07-06 19:32:09 +0200375
376 WATCHDOG_RESET();
377}
378
379static void setup_fec(void)
380{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000381 static const iomux_v3_cfg_t fec_pads[] = {
382 NEW_PAD_CTRL(MX51_PAD_EIM_EB2__FEC_MDIO, PAD_CTL_HYS |
383 PAD_CTL_PUS_22K_UP | PAD_CTL_ODE |
384 PAD_CTL_DSE_HIGH | PAD_CTL_SRE_FAST),
385 MX51_PAD_NANDF_CS3__FEC_MDC,
386 NEW_PAD_CTRL(MX51_PAD_EIM_CS3__FEC_RDATA3, MX51_PAD_CTRL_2),
387 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__FEC_RDATA2, MX51_PAD_CTRL_2),
388 NEW_PAD_CTRL(MX51_PAD_EIM_EB3__FEC_RDATA1, MX51_PAD_CTRL_2),
389 MX51_PAD_NANDF_D9__FEC_RDATA0,
390 MX51_PAD_NANDF_CS6__FEC_TDATA3,
391 MX51_PAD_NANDF_CS5__FEC_TDATA2,
392 MX51_PAD_NANDF_CS4__FEC_TDATA1,
393 MX51_PAD_NANDF_D8__FEC_TDATA0,
394 MX51_PAD_NANDF_CS7__FEC_TX_EN,
395 MX51_PAD_NANDF_CS2__FEC_TX_ER,
396 MX51_PAD_NANDF_RDY_INT__FEC_TX_CLK,
397 NEW_PAD_CTRL(MX51_PAD_NANDF_RB2__FEC_COL, MX51_PAD_CTRL_4),
398 NEW_PAD_CTRL(MX51_PAD_NANDF_RB3__FEC_RX_CLK, MX51_PAD_CTRL_4),
399 MX51_PAD_EIM_CS5__FEC_CRS,
400 MX51_PAD_EIM_CS4__FEC_RX_ER,
401 NEW_PAD_CTRL(MX51_PAD_NANDF_D11__FEC_RX_DV, MX51_PAD_CTRL_4),
402 };
Stefano Babice1b6f592010-07-06 19:32:09 +0200403
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000404 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200405}
406
407struct fsl_esdhc_cfg esdhc_cfg[1] = {
Benoît Thébaudeauc08d11c2012-08-13 07:28:16 +0000408 {MMC_SDHC1_BASE_ADDR},
Stefano Babice1b6f592010-07-06 19:32:09 +0200409};
410
411int get_mmc_getcd(u8 *cd, struct mmc *mmc)
412{
413 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
414
415 if (cfg->esdhc_base == MMC_SDHC1_BASE_ADDR)
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000416 *cd = gpio_get_value(IMX_GPIO_NR(1, 0));
Stefano Babice1b6f592010-07-06 19:32:09 +0200417 else
418 *cd = 0;
419
420 return 0;
421}
422
423#ifdef CONFIG_FSL_ESDHC
424int board_mmc_init(bd_t *bis)
425{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000426 static const iomux_v3_cfg_t sd1_pads[] = {
427 NEW_PAD_CTRL(MX51_PAD_SD1_CMD__SD1_CMD, PAD_CTL_DSE_MAX |
428 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
429 NEW_PAD_CTRL(MX51_PAD_SD1_CLK__SD1_CLK, PAD_CTL_DSE_MAX |
430 PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
431 NEW_PAD_CTRL(MX51_PAD_SD1_DATA0__SD1_DATA0, PAD_CTL_DSE_MAX |
432 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
433 NEW_PAD_CTRL(MX51_PAD_SD1_DATA1__SD1_DATA1, PAD_CTL_DSE_MAX |
434 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
435 NEW_PAD_CTRL(MX51_PAD_SD1_DATA2__SD1_DATA2, PAD_CTL_DSE_MAX |
436 PAD_CTL_HYS | PAD_CTL_PUS_47K_UP | PAD_CTL_SRE_FAST),
437 NEW_PAD_CTRL(MX51_PAD_SD1_DATA3__SD1_DATA3, PAD_CTL_DSE_MAX |
438 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_SRE_FAST),
439 NEW_PAD_CTRL(MX51_PAD_GPIO1_0__SD1_CD, PAD_CTL_HYS),
440 NEW_PAD_CTRL(MX51_PAD_GPIO1_1__SD1_WP, PAD_CTL_HYS),
441 };
442
443 imx_iomux_v3_setup_multiple_pads(sd1_pads, ARRAY_SIZE(sd1_pads));
Stefano Babice1b6f592010-07-06 19:32:09 +0200444
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000445 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
Stefano Babice1b6f592010-07-06 19:32:09 +0200446 return fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
447}
448#endif
449
Stefano Babic61852442011-09-28 11:21:15 +0200450void lcd_enable(void)
451{
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000452 static const iomux_v3_cfg_t lcd_pads[] = {
453 MX51_PAD_DI1_PIN2__DI1_PIN2,
454 MX51_PAD_DI1_PIN3__DI1_PIN3,
455 };
456
Stefano Babic61852442011-09-28 11:21:15 +0200457 int ret;
458
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000459 imx_iomux_v3_setup_multiple_pads(lcd_pads, ARRAY_SIZE(lcd_pads));
Stefano Babic61852442011-09-28 11:21:15 +0200460
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000461 gpio_set_value(IMX_GPIO_NR(1, 2), 1);
462 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_GPIO1_2__GPIO1_2,
463 NO_PAD_CTRL));
Stefano Babic61852442011-09-28 11:21:15 +0200464
Fabio Estevam01e07e72012-05-10 15:07:34 +0000465 ret = ipuv3_fb_init(&nec_nl6448bc26_09c, 0, IPU_PIX_FMT_RGB666);
Stefano Babic61852442011-09-28 11:21:15 +0200466 if (ret)
467 puts("LCD cannot be configured\n");
468}
469
Stefano Babice1b6f592010-07-06 19:32:09 +0200470int board_early_init_f(void)
471{
472
473
474 init_drive_strength();
475
476 /* Setup debug led */
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000477 gpio_direction_output(IMX_GPIO_NR(1, 6), 0);
478 imx_iomux_v3_setup_pad(NEW_PAD_CTRL(MX51_PAD_GPIO1_6__GPIO1_6,
479 PAD_CTL_DSE_MAX | PAD_CTL_SRE_FAST));
Stefano Babice1b6f592010-07-06 19:32:09 +0200480
481 /* wait a little while to give the pll time to settle */
482 sdelay(100000);
483
484 setup_weim();
485 setup_uart();
486 setup_fec();
487 setup_gpios();
488
489 spi_io_init();
490
491 return 0;
492}
493
Stefano Babic445a4822010-10-21 10:34:39 +0200494static void backlight(int on)
495{
496 if (on) {
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000497 gpio_set_value(IMX_GPIO_NR(3, 1), 1);
Stefano Babic445a4822010-10-21 10:34:39 +0200498 udelay(10000);
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000499 gpio_set_value(IMX_GPIO_NR(3, 4), 1);
Stefano Babic445a4822010-10-21 10:34:39 +0200500 } else {
Benoît Thébaudeaue9e08a72013-05-03 10:32:29 +0000501 gpio_set_value(IMX_GPIO_NR(3, 1), 0);
502 gpio_set_value(IMX_GPIO_NR(3, 4), 0);
Stefano Babic445a4822010-10-21 10:34:39 +0200503 }
504}
505
Stefano Babice1b6f592010-07-06 19:32:09 +0200506int board_init(void)
507{
Stefano Babice1b6f592010-07-06 19:32:09 +0200508 /* address of boot parameters */
509 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
510
Stefano Babic61852442011-09-28 11:21:15 +0200511 lcd_enable();
512
513 backlight(1);
514
Stefano Babice1b6f592010-07-06 19:32:09 +0200515 return 0;
516}
517
518int board_late_init(void)
519{
520 power_init_mx51();
521
522 reset_peripherals(1);
523 udelay(2000);
524 reset_peripherals(0);
525 udelay(2000);
526
527 /* Early revisions require a second reset */
528#ifdef CONFIG_VISION2_HW_1_0
529 reset_peripherals(1);
530 udelay(2000);
531 reset_peripherals(0);
532 udelay(2000);
533#endif
534
535 return 0;
536}
537
Fabio Estevamacc86c52012-08-05 07:31:34 +0000538/*
539 * Do not overwrite the console
540 * Use always serial for U-Boot console
541 */
542int overwrite_console(void)
543{
544 return 1;
545}
546
Stefano Babice1b6f592010-07-06 19:32:09 +0200547int checkboard(void)
548{
Jason Liu8b7b69b2011-04-22 02:55:42 +0000549 puts("Board: TTControl Vision II CPU V\n");
Stefano Babice1b6f592010-07-06 19:32:09 +0200550
551 return 0;
552}
553
Stefano Babic445a4822010-10-21 10:34:39 +0200554int do_vision_lcd(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
555{
556 int on;
557
558 if (argc < 2)
559 return cmd_usage(cmdtp);
560
561 on = (strcmp(argv[1], "on") == 0);
562 backlight(on);
563
564 return 0;
565}
566
567U_BOOT_CMD(
568 lcdbl, CONFIG_SYS_MAXARGS, 1, do_vision_lcd,
569 "Vision2 Backlight",
570 "lcdbl [on|off]\n"
571);