blob: 69d41db530d0ce5b9a5244adfd64dacc798dc6c2 [file] [log] [blame]
Marek Vasutd5914012011-01-19 04:40:37 +00001/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +00002 * Copyright (C) 2009 Freescale Semiconductor, Inc.
Marek Vasutd5914012011-01-19 04:40:37 +00003 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
Matt Sealeyfdd63c92012-08-27 05:58:30 +00004 * Copyright (C) 2009-2012 Genesi USA, Inc.
Marek Vasutd5914012011-01-19 04:40:37 +00005 *
6 * See file CREDITS for list of people who contributed to this
7 * project.
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <asm/io.h>
Matt Sealeyfdd63c92012-08-27 05:58:30 +000027#include <asm/arch/iomux-mx51.h>
Stefano Babice70a1062011-08-21 10:53:32 +020028#include <asm/gpio.h>
Marek Vasutd5914012011-01-19 04:40:37 +000029#include <asm/errno.h>
30#include <asm/arch/sys_proto.h>
31#include <asm/arch/crm_regs.h>
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +000032#include <asm/arch/clock.h>
Marek Vasutd5914012011-01-19 04:40:37 +000033#include <i2c.h>
34#include <mmc.h>
35#include <fsl_esdhc.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000036#include <power/pmic.h>
Marek Vasutd5914012011-01-19 04:40:37 +000037#include <fsl_pmic.h>
38#include <mc13892.h>
39
40DECLARE_GLOBAL_DATA_PTR;
41
42/*
43 * Compile-time error checking
44 */
45#ifndef CONFIG_MXC_SPI
46#error "CONFIG_MXC_SPI not set, this is essential for board's operation!"
47#endif
48
49/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +000050 * Board revisions
51 *
52 * Note that we get these revisions here for convenience, but we only set
53 * up for the production model Smarttop (1.3) and Smartbook (2.0).
54 *
Marek Vasutd5914012011-01-19 04:40:37 +000055 */
Marek Vasutd5914012011-01-19 04:40:37 +000056#define EFIKAMX_BOARD_REV_11 0x1
57#define EFIKAMX_BOARD_REV_12 0x2
58#define EFIKAMX_BOARD_REV_13 0x3
59#define EFIKAMX_BOARD_REV_14 0x4
60
Marek Vasutaf708cb2011-09-25 09:55:43 +000061#define EFIKASB_BOARD_REV_13 0x1
62#define EFIKASB_BOARD_REV_20 0x2
63
Marek Vasutd5914012011-01-19 04:40:37 +000064/*
65 * Board identification
66 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +000067static u32 get_mx_rev(void)
Marek Vasutd5914012011-01-19 04:40:37 +000068{
69 u32 rev = 0;
70 /*
71 * Retrieve board ID:
Matt Sealeyfdd63c92012-08-27 05:58:30 +000072 *
73 * gpio: 16 17 11
74 * ==============
75 * r1.1: 1+ 1 1
76 * r1.2: 1 1 0
77 * r1.3: 1 0 1
78 * r1.4: 1 0 0
79 *
80 * + note: r1.1 does not strap this pin properly so it needs to
81 * be hacked or ignored.
Marek Vasutd5914012011-01-19 04:40:37 +000082 */
Marek Vasutd5914012011-01-19 04:40:37 +000083
Matt Sealeyfdd63c92012-08-27 05:58:30 +000084 /* set to 1 in order to get correct value on board rev 1.1 */
Stefano Babicac966aa2012-08-28 03:10:51 +000085 gpio_direction_output(IMX_GPIO_NR(3, 16), 1);
86 gpio_direction_input(IMX_GPIO_NR(3, 11));
87 gpio_direction_input(IMX_GPIO_NR(3, 16));
88 gpio_direction_input(IMX_GPIO_NR(3, 17));
Marek Vasutd5914012011-01-19 04:40:37 +000089
Stefano Babicac966aa2012-08-28 03:10:51 +000090 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 16))) << 0;
91 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 17))) << 1;
92 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 11))) << 2;
Marek Vasutd5914012011-01-19 04:40:37 +000093
94 return (~rev & 0x7) + 1;
95}
96
Eric Nelson6e142322012-10-03 07:26:38 +000097static iomux_v3_cfg_t const efikasb_revision_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +000098 MX51_PAD_EIM_CS3__GPIO2_28,
99 MX51_PAD_EIM_CS4__GPIO2_29,
100};
101
102static inline u32 get_sb_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000103{
104 u32 rev = 0;
105
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000106 imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads,
107 ARRAY_SIZE(efikasb_revision_pads));
Stefano Babicac966aa2012-08-28 03:10:51 +0000108 gpio_direction_input(IMX_GPIO_NR(2, 28));
109 gpio_direction_input(IMX_GPIO_NR(2, 29));
Marek Vasutaf708cb2011-09-25 09:55:43 +0000110
Stefano Babicac966aa2012-08-28 03:10:51 +0000111 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0;
112 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000113
114 return rev;
115}
116
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000117inline uint32_t get_efikamx_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000118{
119 if (machine_is_efikamx())
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000120 return get_mx_rev();
121 else if (machine_is_efikasb())
122 return get_sb_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000123}
124
Marek Vasutd5914012011-01-19 04:40:37 +0000125u32 get_board_rev(void)
126{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000127 return get_cpu_rev() | (get_efikamx_rev() << 8);
Marek Vasutd5914012011-01-19 04:40:37 +0000128}
129
130/*
131 * DRAM initialization
132 */
133int dram_init(void)
134{
135 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +0000136 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000137 PHYS_SDRAM_1_SIZE);
Marek Vasutd5914012011-01-19 04:40:37 +0000138 return 0;
139}
140
141/*
142 * UART configuration
143 */
Eric Nelson6e142322012-10-03 07:26:38 +0000144static iomux_v3_cfg_t const efikamx_uart_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000145 MX51_PAD_UART1_RXD__UART1_RXD,
146 MX51_PAD_UART1_TXD__UART1_TXD,
147 MX51_PAD_UART1_RTS__UART1_RTS,
148 MX51_PAD_UART1_CTS__UART1_CTS,
149};
Marek Vasutd5914012011-01-19 04:40:37 +0000150
151/*
152 * SPI configuration
153 */
Eric Nelson6e142322012-10-03 07:26:38 +0000154static iomux_v3_cfg_t const efikamx_spi_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000155 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
156 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
157 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
158 MX51_PAD_CSPI1_SS0__GPIO4_24,
159 MX51_PAD_CSPI1_SS1__GPIO4_25,
160 MX51_PAD_GPIO1_6__GPIO1_6,
161};
Marek Vasutd5914012011-01-19 04:40:37 +0000162
Stefano Babicac966aa2012-08-28 03:10:51 +0000163#define EFIKAMX_SPI_SS0 IMX_GPIO_NR(4, 24)
164#define EFIKAMX_SPI_SS1 IMX_GPIO_NR(4, 25)
165#define EFIKAMX_PMIC_IRQ IMX_GPIO_NR(1, 6)
Marek Vasutd5914012011-01-19 04:40:37 +0000166
167/*
168 * PMIC configuration
169 */
170#ifdef CONFIG_MXC_SPI
171static void power_init(void)
172{
173 unsigned int val;
174 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200175 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000176 int ret;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200177
Łukasz Majewskic7336812012-11-13 03:21:55 +0000178 ret = pmic_init(I2C_PMIC);
179 if (ret)
180 return;
181
182 p = pmic_get("FSL_PMIC");
183 if (!p)
184 return;
Marek Vasutd5914012011-01-19 04:40:37 +0000185
186 /* Write needed to Power Gate 2 register */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200187 pmic_reg_read(p, REG_POWER_MISC, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000188 val &= ~PWGT2SPIEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200189 pmic_reg_write(p, REG_POWER_MISC, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000190
191 /* Externally powered */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200192 pmic_reg_read(p, REG_CHARGE, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000193 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200194 pmic_reg_write(p, REG_CHARGE, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000195
196 /* power up the system first */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200197 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Marek Vasutd5914012011-01-19 04:40:37 +0000198
199 /* Set core voltage to 1.1V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200200 pmic_reg_read(p, REG_SW_0, &val);
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000201 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200202 pmic_reg_write(p, REG_SW_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000203
204 /* Setup VCC (SW2) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200205 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000206 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200207 pmic_reg_write(p, REG_SW_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000208
209 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200210 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000211 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200212 pmic_reg_write(p, REG_SW_2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000213 udelay(50);
214
215 /* Raise the core frequency to 800MHz */
216 writel(0x0, &mxc_ccm->cacrr);
217
218 /* Set switchers in Auto in NORMAL mode & STANDBY mode */
219 /* Setup the switcher mode for SW1 & SW2*/
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200220 pmic_reg_read(p, REG_SW_4, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000221 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
222 (SWMODE_MASK << SWMODE2_SHIFT)));
223 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
224 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200225 pmic_reg_write(p, REG_SW_4, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000226
227 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200228 pmic_reg_read(p, REG_SW_5, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000229 val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
230 (SWMODE_MASK << SWMODE4_SHIFT)));
231 val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
232 (SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200233 pmic_reg_write(p, REG_SW_5, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000234
Marek Vasut55723952011-09-28 02:19:57 +0000235 /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200236 pmic_reg_read(p, REG_SETTING_0, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000237 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000238 val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200239 pmic_reg_write(p, REG_SETTING_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000240
241 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200242 pmic_reg_read(p, REG_SETTING_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000243 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000244 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200245 pmic_reg_write(p, REG_SETTING_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000246
Marek Vasut55723952011-09-28 02:19:57 +0000247 /* Enable VGEN1, VGEN2, VDIG, VPLL */
248 pmic_reg_read(p, REG_MODE_0, &val);
249 val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN;
250 pmic_reg_write(p, REG_MODE_0, val);
251
Marek Vasutd5914012011-01-19 04:40:37 +0000252 /* Configure VGEN3 and VCAM regulators to use external PNP */
253 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200254 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000255 udelay(200);
256
257 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
258 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
Marek Vasut55723952011-09-28 02:19:57 +0000259 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200260 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000261
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200262 pmic_reg_read(p, REG_POWER_CTL2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000263 val |= WDIRESET;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200264 pmic_reg_write(p, REG_POWER_CTL2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000265
266 udelay(2500);
267}
268#else
269static inline void power_init(void) { }
270#endif
271
272/*
273 * MMC configuration
274 */
275#ifdef CONFIG_FSL_ESDHC
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000276
Marek Vasutd5914012011-01-19 04:40:37 +0000277struct fsl_esdhc_cfg esdhc_cfg[2] = {
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000278 {MMC_SDHC1_BASE_ADDR},
279 {MMC_SDHC2_BASE_ADDR},
Marek Vasutd5914012011-01-19 04:40:37 +0000280};
281
Eric Nelson6e142322012-10-03 07:26:38 +0000282static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000283 MX51_PAD_SD1_CMD__SD1_CMD,
284 MX51_PAD_SD1_CLK__SD1_CLK,
285 MX51_PAD_SD1_DATA0__SD1_DATA0,
286 MX51_PAD_SD1_DATA1__SD1_DATA1,
287 MX51_PAD_SD1_DATA2__SD1_DATA2,
288 MX51_PAD_SD1_DATA3__SD1_DATA3,
289 MX51_PAD_GPIO1_1__SD1_WP,
290};
291
Stefano Babicac966aa2012-08-28 03:10:51 +0000292#define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000293
Eric Nelson6e142322012-10-03 07:26:38 +0000294static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000295 MX51_PAD_GPIO1_0__SD1_CD,
296 MX51_PAD_EIM_CS2__SD1_CD,
297};
298
Stefano Babicac966aa2012-08-28 03:10:51 +0000299#define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0)
300#define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000301
Eric Nelson6e142322012-10-03 07:26:38 +0000302static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000303 MX51_PAD_SD2_CMD__SD2_CMD,
304 MX51_PAD_SD2_CLK__SD2_CLK,
305 MX51_PAD_SD2_DATA0__SD2_DATA0,
306 MX51_PAD_SD2_DATA1__SD2_DATA1,
307 MX51_PAD_SD2_DATA2__SD2_DATA2,
308 MX51_PAD_SD2_DATA3__SD2_DATA3,
309 MX51_PAD_GPIO1_7__SD2_WP,
310 MX51_PAD_GPIO1_8__SD2_CD,
311};
312
Stefano Babicac966aa2012-08-28 03:10:51 +0000313#define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8)
314#define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000315
316static inline uint32_t efikamx_mmc_getcd(u32 base)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000317{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000318 if (base == MMC_SDHC1_BASE_ADDR)
319 if (machine_is_efikamx())
320 return EFIKAMX_SDHC1_CD;
321 else
322 return EFIKASB_SDHC1_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000323 else
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000324 return EFIKASB_SDHC2_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000325}
326
Thierry Reding314284b2012-01-02 01:15:36 +0000327int board_mmc_getcd(struct mmc *mmc)
Marek Vasutd5914012011-01-19 04:40:37 +0000328{
329 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000330 uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base);
331 int ret = !gpio_get_value(cd);
Marek Vasutd5914012011-01-19 04:40:37 +0000332
Thierry Reding314284b2012-01-02 01:15:36 +0000333 return ret;
Marek Vasutd5914012011-01-19 04:40:37 +0000334}
Marek Vasutaf708cb2011-09-25 09:55:43 +0000335
Marek Vasutd5914012011-01-19 04:40:37 +0000336int board_mmc_init(bd_t *bis)
337{
338 int ret;
339
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000340 /*
341 * All Efika MX boards use eSDHC1 with a common write-protect GPIO
342 */
343 imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads,
344 ARRAY_SIZE(efikamx_sdhc1_pads));
345 gpio_direction_input(EFIKAMX_SDHC1_WP);
Marek Vasutd5914012011-01-19 04:40:37 +0000346
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000347 /*
348 * Smartbook and Smarttop differ on the location of eSDHC1
349 * carrier-detect GPIO
350 */
351 if (machine_is_efikamx()) {
352 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]);
353 gpio_direction_input(EFIKAMX_SDHC1_CD);
354 } else if (machine_is_efikasb()) {
355 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]);
356 gpio_direction_input(EFIKASB_SDHC1_CD);
357 }
Marek Vasutd5914012011-01-19 04:40:37 +0000358
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000359 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
360 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
361
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000362 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
Marek Vasutd5914012011-01-19 04:40:37 +0000363
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000364 if (machine_is_efikasb()) {
Marek Vasutd5914012011-01-19 04:40:37 +0000365
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000366 imx_iomux_v3_setup_multiple_pads(efikasb_sdhc2_pads,
367 ARRAY_SIZE(efikasb_sdhc2_pads));
368 gpio_direction_input(EFIKASB_SDHC2_CD);
369 gpio_direction_input(EFIKASB_SDHC2_WP);
Marek Vasutd5914012011-01-19 04:40:37 +0000370 if (!ret)
371 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]);
Marek Vasutd5914012011-01-19 04:40:37 +0000372 }
Marek Vasutaf708cb2011-09-25 09:55:43 +0000373
Marek Vasutd5914012011-01-19 04:40:37 +0000374 return ret;
375}
376#endif
377
378/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000379 * PATA
Marek Vasutd5914012011-01-19 04:40:37 +0000380 */
Eric Nelson6e142322012-10-03 07:26:38 +0000381static iomux_v3_cfg_t const efikamx_pata_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000382 MX51_PAD_NANDF_WE_B__PATA_DIOW,
383 MX51_PAD_NANDF_RE_B__PATA_DIOR,
384 MX51_PAD_NANDF_ALE__PATA_BUFFER_EN,
385 MX51_PAD_NANDF_CLE__PATA_RESET_B,
386 MX51_PAD_NANDF_WP_B__PATA_DMACK,
387 MX51_PAD_NANDF_RB0__PATA_DMARQ,
388 MX51_PAD_NANDF_RB1__PATA_IORDY,
389 MX51_PAD_GPIO_NAND__PATA_INTRQ,
390 MX51_PAD_NANDF_CS2__PATA_CS_0,
391 MX51_PAD_NANDF_CS3__PATA_CS_1,
392 MX51_PAD_NANDF_CS4__PATA_DA_0,
393 MX51_PAD_NANDF_CS5__PATA_DA_1,
394 MX51_PAD_NANDF_CS6__PATA_DA_2,
395 MX51_PAD_NANDF_D15__PATA_DATA15,
396 MX51_PAD_NANDF_D14__PATA_DATA14,
397 MX51_PAD_NANDF_D13__PATA_DATA13,
398 MX51_PAD_NANDF_D12__PATA_DATA12,
399 MX51_PAD_NANDF_D11__PATA_DATA11,
400 MX51_PAD_NANDF_D10__PATA_DATA10,
401 MX51_PAD_NANDF_D9__PATA_DATA9,
402 MX51_PAD_NANDF_D8__PATA_DATA8,
403 MX51_PAD_NANDF_D7__PATA_DATA7,
404 MX51_PAD_NANDF_D6__PATA_DATA6,
405 MX51_PAD_NANDF_D5__PATA_DATA5,
406 MX51_PAD_NANDF_D4__PATA_DATA4,
407 MX51_PAD_NANDF_D3__PATA_DATA3,
408 MX51_PAD_NANDF_D2__PATA_DATA2,
409 MX51_PAD_NANDF_D1__PATA_DATA1,
410 MX51_PAD_NANDF_D0__PATA_DATA0,
411};
Marek Vasutd5914012011-01-19 04:40:37 +0000412
413/*
Marek Vasutd98d8bc2011-06-24 21:46:07 +0200414 * EHCI USB
415 */
416#ifdef CONFIG_CMD_USB
417extern void setup_iomux_usb(void);
418#else
419static inline void setup_iomux_usb(void) { }
420#endif
421
422/*
Marek Vasutd5914012011-01-19 04:40:37 +0000423 * LED configuration
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000424 *
425 * Smarttop LED pad config is done in the DCD
426 *
Marek Vasutd5914012011-01-19 04:40:37 +0000427 */
Stefano Babicac966aa2012-08-28 03:10:51 +0000428#define EFIKAMX_LED_BLUE IMX_GPIO_NR(3, 13)
429#define EFIKAMX_LED_GREEN IMX_GPIO_NR(3, 14)
430#define EFIKAMX_LED_RED IMX_GPIO_NR(3, 15)
Stefano Babice70a1062011-08-21 10:53:32 +0200431
Eric Nelson6e142322012-10-03 07:26:38 +0000432static iomux_v3_cfg_t const efikasb_led_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000433 MX51_PAD_GPIO1_3__GPIO1_3,
434 MX51_PAD_EIM_CS0__GPIO2_25,
435};
Stefano Babice70a1062011-08-21 10:53:32 +0200436
Stefano Babicac966aa2012-08-28 03:10:51 +0000437#define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25)
438#define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */
Marek Vasutd5914012011-01-19 04:40:37 +0000439
440/*
441 * Board initialization
442 */
Marek Vasutd5914012011-01-19 04:40:37 +0000443int board_early_init_f(void)
444{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000445 if (machine_is_efikasb()) {
446 imx_iomux_v3_setup_multiple_pads(efikasb_led_pads,
447 ARRAY_SIZE(efikasb_led_pads));
448 gpio_direction_output(EFIKASB_CAPSLOCK_LED, 0);
449 gpio_direction_output(EFIKASB_MESSAGE_LED, 1);
450 } else if (machine_is_efikamx()) {
451 /*
452 * Set up GPIO directions for LEDs.
453 * IOMUX has been done in the DCD already.
454 * Turn the red LED on for pre-relocation code.
455 */
456 gpio_direction_output(EFIKAMX_LED_BLUE, 0);
457 gpio_direction_output(EFIKAMX_LED_GREEN, 0);
458 gpio_direction_output(EFIKAMX_LED_RED, 1);
459 }
460
461 /*
462 * Both these pad configurations for UART and SPI are kind of redundant
463 * since they are the Power-On Defaults for the i.MX51. But, it seems we
464 * should make absolutely sure that they are set up correctly.
465 */
466 imx_iomux_v3_setup_multiple_pads(efikamx_uart_pads,
467 ARRAY_SIZE(efikamx_uart_pads));
468 imx_iomux_v3_setup_multiple_pads(efikamx_spi_pads,
469 ARRAY_SIZE(efikamx_spi_pads));
470
471 /* not technically required for U-Boot operation but do it anyway. */
472 gpio_direction_input(EFIKAMX_PMIC_IRQ);
473 /* Deselect both CS for now, otherwise NOR doesn't probe properly. */
474 gpio_direction_output(EFIKAMX_SPI_SS0, 0);
475 gpio_direction_output(EFIKAMX_SPI_SS1, 1);
Marek Vasutd5914012011-01-19 04:40:37 +0000476
477 return 0;
478}
479
480int board_init(void)
481{
Marek Vasutd5914012011-01-19 04:40:37 +0000482 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
483
484 return 0;
485}
486
487int board_late_init(void)
488{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000489 if (machine_is_efikamx()) {
490 /*
491 * Set up Blue LED for "In U-Boot" status.
492 * We're all relocated and ready to U-Boot!
493 */
494 gpio_set_value(EFIKAMX_LED_RED, 0);
495 gpio_set_value(EFIKAMX_LED_GREEN, 0);
496 gpio_set_value(EFIKAMX_LED_BLUE, 1);
497 }
Marek Vasutd5914012011-01-19 04:40:37 +0000498
499 power_init();
500
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000501 imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads,
502 ARRAY_SIZE(efikamx_pata_pads));
Marek Vasutd98d8bc2011-06-24 21:46:07 +0200503 setup_iomux_usb();
504
Marek Vasutd5914012011-01-19 04:40:37 +0000505 return 0;
506}
507
508int checkboard(void)
509{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000510 u32 rev = get_efikamx_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000511
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000512 printf("Board: Genesi Efika MX ");
513 if (machine_is_efikamx())
514 printf("Smarttop (1.%i)\n", rev & 0xf);
515 else if (machine_is_efikasb())
516 printf("Smartbook\n");
Marek Vasutd5914012011-01-19 04:40:37 +0000517
518 return 0;
519}