blob: 6d98c94db9144e772b2fa8fe6212bd52b80a79d9 [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>
32#include <i2c.h>
33#include <mmc.h>
34#include <fsl_esdhc.h>
Stefano Babic9c38f7d2011-10-06 11:44:26 +020035#include <pmic.h>
Marek Vasutd5914012011-01-19 04:40:37 +000036#include <fsl_pmic.h>
37#include <mc13892.h>
38
39DECLARE_GLOBAL_DATA_PTR;
40
41/*
42 * Compile-time error checking
43 */
44#ifndef CONFIG_MXC_SPI
45#error "CONFIG_MXC_SPI not set, this is essential for board's operation!"
46#endif
47
48/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +000049 * Board revisions
50 *
51 * Note that we get these revisions here for convenience, but we only set
52 * up for the production model Smarttop (1.3) and Smartbook (2.0).
53 *
Marek Vasutd5914012011-01-19 04:40:37 +000054 */
Marek Vasutd5914012011-01-19 04:40:37 +000055#define EFIKAMX_BOARD_REV_11 0x1
56#define EFIKAMX_BOARD_REV_12 0x2
57#define EFIKAMX_BOARD_REV_13 0x3
58#define EFIKAMX_BOARD_REV_14 0x4
59
Marek Vasutaf708cb2011-09-25 09:55:43 +000060#define EFIKASB_BOARD_REV_13 0x1
61#define EFIKASB_BOARD_REV_20 0x2
62
Marek Vasutd5914012011-01-19 04:40:37 +000063/*
64 * Board identification
65 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +000066static u32 get_mx_rev(void)
Marek Vasutd5914012011-01-19 04:40:37 +000067{
68 u32 rev = 0;
69 /*
70 * Retrieve board ID:
Matt Sealeyfdd63c92012-08-27 05:58:30 +000071 *
72 * gpio: 16 17 11
73 * ==============
74 * r1.1: 1+ 1 1
75 * r1.2: 1 1 0
76 * r1.3: 1 0 1
77 * r1.4: 1 0 0
78 *
79 * + note: r1.1 does not strap this pin properly so it needs to
80 * be hacked or ignored.
Marek Vasutd5914012011-01-19 04:40:37 +000081 */
Marek Vasutd5914012011-01-19 04:40:37 +000082
Matt Sealeyfdd63c92012-08-27 05:58:30 +000083 /* set to 1 in order to get correct value on board rev 1.1 */
Stefano Babicac966aa2012-08-28 03:10:51 +000084 gpio_direction_output(IMX_GPIO_NR(3, 16), 1);
85 gpio_direction_input(IMX_GPIO_NR(3, 11));
86 gpio_direction_input(IMX_GPIO_NR(3, 16));
87 gpio_direction_input(IMX_GPIO_NR(3, 17));
Marek Vasutd5914012011-01-19 04:40:37 +000088
Stefano Babicac966aa2012-08-28 03:10:51 +000089 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 16))) << 0;
90 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 17))) << 1;
91 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 11))) << 2;
Marek Vasutd5914012011-01-19 04:40:37 +000092
93 return (~rev & 0x7) + 1;
94}
95
Matt Sealeyfdd63c92012-08-27 05:58:30 +000096static iomux_v3_cfg_t efikasb_revision_pads[] = {
97 MX51_PAD_EIM_CS3__GPIO2_28,
98 MX51_PAD_EIM_CS4__GPIO2_29,
99};
100
101static inline u32 get_sb_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000102{
103 u32 rev = 0;
104
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000105 imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads,
106 ARRAY_SIZE(efikasb_revision_pads));
Stefano Babicac966aa2012-08-28 03:10:51 +0000107 gpio_direction_input(IMX_GPIO_NR(2, 28));
108 gpio_direction_input(IMX_GPIO_NR(2, 29));
Marek Vasutaf708cb2011-09-25 09:55:43 +0000109
Stefano Babicac966aa2012-08-28 03:10:51 +0000110 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0;
111 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000112
113 return rev;
114}
115
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000116inline uint32_t get_efikamx_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000117{
118 if (machine_is_efikamx())
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000119 return get_mx_rev();
120 else if (machine_is_efikasb())
121 return get_sb_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000122}
123
Marek Vasutd5914012011-01-19 04:40:37 +0000124u32 get_board_rev(void)
125{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000126 return get_cpu_rev() | (get_efikamx_rev() << 8);
Marek Vasutd5914012011-01-19 04:40:37 +0000127}
128
129/*
130 * DRAM initialization
131 */
132int dram_init(void)
133{
134 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +0000135 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000136 PHYS_SDRAM_1_SIZE);
Marek Vasutd5914012011-01-19 04:40:37 +0000137 return 0;
138}
139
140/*
141 * UART configuration
142 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000143static iomux_v3_cfg_t efikamx_uart_pads[] = {
144 MX51_PAD_UART1_RXD__UART1_RXD,
145 MX51_PAD_UART1_TXD__UART1_TXD,
146 MX51_PAD_UART1_RTS__UART1_RTS,
147 MX51_PAD_UART1_CTS__UART1_CTS,
148};
Marek Vasutd5914012011-01-19 04:40:37 +0000149
150/*
151 * SPI configuration
152 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000153static iomux_v3_cfg_t efikamx_spi_pads[] = {
154 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
155 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
156 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
157 MX51_PAD_CSPI1_SS0__GPIO4_24,
158 MX51_PAD_CSPI1_SS1__GPIO4_25,
159 MX51_PAD_GPIO1_6__GPIO1_6,
160};
Marek Vasutd5914012011-01-19 04:40:37 +0000161
Stefano Babicac966aa2012-08-28 03:10:51 +0000162#define EFIKAMX_SPI_SS0 IMX_GPIO_NR(4, 24)
163#define EFIKAMX_SPI_SS1 IMX_GPIO_NR(4, 25)
164#define EFIKAMX_PMIC_IRQ IMX_GPIO_NR(1, 6)
Marek Vasutd5914012011-01-19 04:40:37 +0000165
166/*
167 * PMIC configuration
168 */
169#ifdef CONFIG_MXC_SPI
170static void power_init(void)
171{
172 unsigned int val;
173 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200174 struct pmic *p;
175
176 pmic_init();
177 p = get_pmic();
Marek Vasutd5914012011-01-19 04:40:37 +0000178
179 /* Write needed to Power Gate 2 register */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200180 pmic_reg_read(p, REG_POWER_MISC, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000181 val &= ~PWGT2SPIEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200182 pmic_reg_write(p, REG_POWER_MISC, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000183
184 /* Externally powered */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200185 pmic_reg_read(p, REG_CHARGE, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000186 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200187 pmic_reg_write(p, REG_CHARGE, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000188
189 /* power up the system first */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200190 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Marek Vasutd5914012011-01-19 04:40:37 +0000191
192 /* Set core voltage to 1.1V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200193 pmic_reg_read(p, REG_SW_0, &val);
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000194 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200195 pmic_reg_write(p, REG_SW_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000196
197 /* Setup VCC (SW2) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200198 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000199 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200200 pmic_reg_write(p, REG_SW_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000201
202 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200203 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000204 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200205 pmic_reg_write(p, REG_SW_2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000206 udelay(50);
207
208 /* Raise the core frequency to 800MHz */
209 writel(0x0, &mxc_ccm->cacrr);
210
211 /* Set switchers in Auto in NORMAL mode & STANDBY mode */
212 /* Setup the switcher mode for SW1 & SW2*/
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200213 pmic_reg_read(p, REG_SW_4, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000214 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
215 (SWMODE_MASK << SWMODE2_SHIFT)));
216 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
217 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200218 pmic_reg_write(p, REG_SW_4, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000219
220 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200221 pmic_reg_read(p, REG_SW_5, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000222 val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
223 (SWMODE_MASK << SWMODE4_SHIFT)));
224 val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
225 (SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200226 pmic_reg_write(p, REG_SW_5, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000227
Marek Vasut55723952011-09-28 02:19:57 +0000228 /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200229 pmic_reg_read(p, REG_SETTING_0, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000230 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000231 val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200232 pmic_reg_write(p, REG_SETTING_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000233
234 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200235 pmic_reg_read(p, REG_SETTING_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000236 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000237 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200238 pmic_reg_write(p, REG_SETTING_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000239
Marek Vasut55723952011-09-28 02:19:57 +0000240 /* Enable VGEN1, VGEN2, VDIG, VPLL */
241 pmic_reg_read(p, REG_MODE_0, &val);
242 val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN;
243 pmic_reg_write(p, REG_MODE_0, val);
244
Marek Vasutd5914012011-01-19 04:40:37 +0000245 /* Configure VGEN3 and VCAM regulators to use external PNP */
246 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200247 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000248 udelay(200);
249
250 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
251 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
Marek Vasut55723952011-09-28 02:19:57 +0000252 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200253 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000254
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200255 pmic_reg_read(p, REG_POWER_CTL2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000256 val |= WDIRESET;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200257 pmic_reg_write(p, REG_POWER_CTL2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000258
259 udelay(2500);
260}
261#else
262static inline void power_init(void) { }
263#endif
264
265/*
266 * MMC configuration
267 */
268#ifdef CONFIG_FSL_ESDHC
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000269
Marek Vasutd5914012011-01-19 04:40:37 +0000270struct fsl_esdhc_cfg esdhc_cfg[2] = {
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000271 {MMC_SDHC1_BASE_ADDR},
272 {MMC_SDHC2_BASE_ADDR},
Marek Vasutd5914012011-01-19 04:40:37 +0000273};
274
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000275static iomux_v3_cfg_t efikamx_sdhc1_pads[] = {
276 MX51_PAD_SD1_CMD__SD1_CMD,
277 MX51_PAD_SD1_CLK__SD1_CLK,
278 MX51_PAD_SD1_DATA0__SD1_DATA0,
279 MX51_PAD_SD1_DATA1__SD1_DATA1,
280 MX51_PAD_SD1_DATA2__SD1_DATA2,
281 MX51_PAD_SD1_DATA3__SD1_DATA3,
282 MX51_PAD_GPIO1_1__SD1_WP,
283};
284
Stefano Babicac966aa2012-08-28 03:10:51 +0000285#define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000286
287static iomux_v3_cfg_t efikamx_sdhc1_cd_pads[] = {
288 MX51_PAD_GPIO1_0__SD1_CD,
289 MX51_PAD_EIM_CS2__SD1_CD,
290};
291
Stefano Babicac966aa2012-08-28 03:10:51 +0000292#define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0)
293#define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000294
295static iomux_v3_cfg_t efikasb_sdhc2_pads[] = {
296 MX51_PAD_SD2_CMD__SD2_CMD,
297 MX51_PAD_SD2_CLK__SD2_CLK,
298 MX51_PAD_SD2_DATA0__SD2_DATA0,
299 MX51_PAD_SD2_DATA1__SD2_DATA1,
300 MX51_PAD_SD2_DATA2__SD2_DATA2,
301 MX51_PAD_SD2_DATA3__SD2_DATA3,
302 MX51_PAD_GPIO1_7__SD2_WP,
303 MX51_PAD_GPIO1_8__SD2_CD,
304};
305
Stefano Babicac966aa2012-08-28 03:10:51 +0000306#define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8)
307#define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000308
309static inline uint32_t efikamx_mmc_getcd(u32 base)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000310{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000311 if (base == MMC_SDHC1_BASE_ADDR)
312 if (machine_is_efikamx())
313 return EFIKAMX_SDHC1_CD;
314 else
315 return EFIKASB_SDHC1_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000316 else
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000317 return EFIKASB_SDHC2_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000318}
319
Thierry Reding314284b2012-01-02 01:15:36 +0000320int board_mmc_getcd(struct mmc *mmc)
Marek Vasutd5914012011-01-19 04:40:37 +0000321{
322 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000323 uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base);
324 int ret = !gpio_get_value(cd);
Marek Vasutd5914012011-01-19 04:40:37 +0000325
Thierry Reding314284b2012-01-02 01:15:36 +0000326 return ret;
Marek Vasutd5914012011-01-19 04:40:37 +0000327}
Marek Vasutaf708cb2011-09-25 09:55:43 +0000328
Marek Vasutd5914012011-01-19 04:40:37 +0000329int board_mmc_init(bd_t *bis)
330{
331 int ret;
332
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000333 /*
334 * All Efika MX boards use eSDHC1 with a common write-protect GPIO
335 */
336 imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads,
337 ARRAY_SIZE(efikamx_sdhc1_pads));
338 gpio_direction_input(EFIKAMX_SDHC1_WP);
Marek Vasutd5914012011-01-19 04:40:37 +0000339
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000340 /*
341 * Smartbook and Smarttop differ on the location of eSDHC1
342 * carrier-detect GPIO
343 */
344 if (machine_is_efikamx()) {
345 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]);
346 gpio_direction_input(EFIKAMX_SDHC1_CD);
347 } else if (machine_is_efikasb()) {
348 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]);
349 gpio_direction_input(EFIKASB_SDHC1_CD);
350 }
Marek Vasutd5914012011-01-19 04:40:37 +0000351
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000352 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
Marek Vasutd5914012011-01-19 04:40:37 +0000353
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000354 if (machine_is_efikasb()) {
Marek Vasutd5914012011-01-19 04:40:37 +0000355
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000356 imx_iomux_v3_setup_multiple_pads(efikasb_sdhc2_pads,
357 ARRAY_SIZE(efikasb_sdhc2_pads));
358 gpio_direction_input(EFIKASB_SDHC2_CD);
359 gpio_direction_input(EFIKASB_SDHC2_WP);
Marek Vasutd5914012011-01-19 04:40:37 +0000360 if (!ret)
361 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]);
Marek Vasutd5914012011-01-19 04:40:37 +0000362 }
Marek Vasutaf708cb2011-09-25 09:55:43 +0000363
Marek Vasutd5914012011-01-19 04:40:37 +0000364 return ret;
365}
366#endif
367
368/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000369 * PATA
Marek Vasutd5914012011-01-19 04:40:37 +0000370 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000371static iomux_v3_cfg_t efikamx_pata_pads[] = {
372 MX51_PAD_NANDF_WE_B__PATA_DIOW,
373 MX51_PAD_NANDF_RE_B__PATA_DIOR,
374 MX51_PAD_NANDF_ALE__PATA_BUFFER_EN,
375 MX51_PAD_NANDF_CLE__PATA_RESET_B,
376 MX51_PAD_NANDF_WP_B__PATA_DMACK,
377 MX51_PAD_NANDF_RB0__PATA_DMARQ,
378 MX51_PAD_NANDF_RB1__PATA_IORDY,
379 MX51_PAD_GPIO_NAND__PATA_INTRQ,
380 MX51_PAD_NANDF_CS2__PATA_CS_0,
381 MX51_PAD_NANDF_CS3__PATA_CS_1,
382 MX51_PAD_NANDF_CS4__PATA_DA_0,
383 MX51_PAD_NANDF_CS5__PATA_DA_1,
384 MX51_PAD_NANDF_CS6__PATA_DA_2,
385 MX51_PAD_NANDF_D15__PATA_DATA15,
386 MX51_PAD_NANDF_D14__PATA_DATA14,
387 MX51_PAD_NANDF_D13__PATA_DATA13,
388 MX51_PAD_NANDF_D12__PATA_DATA12,
389 MX51_PAD_NANDF_D11__PATA_DATA11,
390 MX51_PAD_NANDF_D10__PATA_DATA10,
391 MX51_PAD_NANDF_D9__PATA_DATA9,
392 MX51_PAD_NANDF_D8__PATA_DATA8,
393 MX51_PAD_NANDF_D7__PATA_DATA7,
394 MX51_PAD_NANDF_D6__PATA_DATA6,
395 MX51_PAD_NANDF_D5__PATA_DATA5,
396 MX51_PAD_NANDF_D4__PATA_DATA4,
397 MX51_PAD_NANDF_D3__PATA_DATA3,
398 MX51_PAD_NANDF_D2__PATA_DATA2,
399 MX51_PAD_NANDF_D1__PATA_DATA1,
400 MX51_PAD_NANDF_D0__PATA_DATA0,
401};
Marek Vasutd5914012011-01-19 04:40:37 +0000402
403/*
Marek Vasutd98d8bc2011-06-24 21:46:07 +0200404 * EHCI USB
405 */
406#ifdef CONFIG_CMD_USB
407extern void setup_iomux_usb(void);
408#else
409static inline void setup_iomux_usb(void) { }
410#endif
411
412/*
Marek Vasutd5914012011-01-19 04:40:37 +0000413 * LED configuration
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000414 *
415 * Smarttop LED pad config is done in the DCD
416 *
Marek Vasutd5914012011-01-19 04:40:37 +0000417 */
Stefano Babicac966aa2012-08-28 03:10:51 +0000418#define EFIKAMX_LED_BLUE IMX_GPIO_NR(3, 13)
419#define EFIKAMX_LED_GREEN IMX_GPIO_NR(3, 14)
420#define EFIKAMX_LED_RED IMX_GPIO_NR(3, 15)
Stefano Babice70a1062011-08-21 10:53:32 +0200421
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000422static iomux_v3_cfg_t efikasb_led_pads[] = {
423 MX51_PAD_GPIO1_3__GPIO1_3,
424 MX51_PAD_EIM_CS0__GPIO2_25,
425};
Stefano Babice70a1062011-08-21 10:53:32 +0200426
Stefano Babicac966aa2012-08-28 03:10:51 +0000427#define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25)
428#define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */
Marek Vasutd5914012011-01-19 04:40:37 +0000429
430/*
431 * Board initialization
432 */
Marek Vasutd5914012011-01-19 04:40:37 +0000433int board_early_init_f(void)
434{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000435 if (machine_is_efikasb()) {
436 imx_iomux_v3_setup_multiple_pads(efikasb_led_pads,
437 ARRAY_SIZE(efikasb_led_pads));
438 gpio_direction_output(EFIKASB_CAPSLOCK_LED, 0);
439 gpio_direction_output(EFIKASB_MESSAGE_LED, 1);
440 } else if (machine_is_efikamx()) {
441 /*
442 * Set up GPIO directions for LEDs.
443 * IOMUX has been done in the DCD already.
444 * Turn the red LED on for pre-relocation code.
445 */
446 gpio_direction_output(EFIKAMX_LED_BLUE, 0);
447 gpio_direction_output(EFIKAMX_LED_GREEN, 0);
448 gpio_direction_output(EFIKAMX_LED_RED, 1);
449 }
450
451 /*
452 * Both these pad configurations for UART and SPI are kind of redundant
453 * since they are the Power-On Defaults for the i.MX51. But, it seems we
454 * should make absolutely sure that they are set up correctly.
455 */
456 imx_iomux_v3_setup_multiple_pads(efikamx_uart_pads,
457 ARRAY_SIZE(efikamx_uart_pads));
458 imx_iomux_v3_setup_multiple_pads(efikamx_spi_pads,
459 ARRAY_SIZE(efikamx_spi_pads));
460
461 /* not technically required for U-Boot operation but do it anyway. */
462 gpio_direction_input(EFIKAMX_PMIC_IRQ);
463 /* Deselect both CS for now, otherwise NOR doesn't probe properly. */
464 gpio_direction_output(EFIKAMX_SPI_SS0, 0);
465 gpio_direction_output(EFIKAMX_SPI_SS1, 1);
Marek Vasutd5914012011-01-19 04:40:37 +0000466
467 return 0;
468}
469
470int board_init(void)
471{
Marek Vasutd5914012011-01-19 04:40:37 +0000472 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
473
474 return 0;
475}
476
477int board_late_init(void)
478{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000479 if (machine_is_efikamx()) {
480 /*
481 * Set up Blue LED for "In U-Boot" status.
482 * We're all relocated and ready to U-Boot!
483 */
484 gpio_set_value(EFIKAMX_LED_RED, 0);
485 gpio_set_value(EFIKAMX_LED_GREEN, 0);
486 gpio_set_value(EFIKAMX_LED_BLUE, 1);
487 }
Marek Vasutd5914012011-01-19 04:40:37 +0000488
489 power_init();
490
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000491 imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads,
492 ARRAY_SIZE(efikamx_pata_pads));
Marek Vasutd98d8bc2011-06-24 21:46:07 +0200493 setup_iomux_usb();
494
495 if (machine_is_efikasb())
496 setenv("preboot", "usb reset ; setenv stdin usbkbd\0");
497
Marek Vasutd5914012011-01-19 04:40:37 +0000498 return 0;
499}
500
501int checkboard(void)
502{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000503 u32 rev = get_efikamx_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000504
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000505 printf("Board: Genesi Efika MX ");
506 if (machine_is_efikamx())
507 printf("Smarttop (1.%i)\n", rev & 0xf);
508 else if (machine_is_efikasb())
509 printf("Smartbook\n");
Marek Vasutd5914012011-01-19 04:40:37 +0000510
511 return 0;
512}