blob: 6ba55cd08a82f62a5cd420b024ff68cdb0cc171a [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 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Marek Vasutd5914012011-01-19 04:40:37 +00007 */
8
9#include <common.h>
10#include <asm/io.h>
Matt Sealeyfdd63c92012-08-27 05:58:30 +000011#include <asm/arch/iomux-mx51.h>
Stefano Babice70a1062011-08-21 10:53:32 +020012#include <asm/gpio.h>
Marek Vasutd5914012011-01-19 04:40:37 +000013#include <asm/errno.h>
14#include <asm/arch/sys_proto.h>
15#include <asm/arch/crm_regs.h>
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +000016#include <asm/arch/clock.h>
Eric Nelson3acb0112014-09-30 15:40:03 -070017#include <asm/imx-common/spi.h>
Marek Vasutd5914012011-01-19 04:40:37 +000018#include <i2c.h>
19#include <mmc.h>
20#include <fsl_esdhc.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000021#include <power/pmic.h>
Marek Vasutd5914012011-01-19 04:40:37 +000022#include <fsl_pmic.h>
23#include <mc13892.h>
24
25DECLARE_GLOBAL_DATA_PTR;
26
27/*
28 * Compile-time error checking
29 */
30#ifndef CONFIG_MXC_SPI
31#error "CONFIG_MXC_SPI not set, this is essential for board's operation!"
32#endif
33
34/*
Matt Sealeyfdd63c92012-08-27 05:58:30 +000035 * Board revisions
36 *
37 * Note that we get these revisions here for convenience, but we only set
38 * up for the production model Smarttop (1.3) and Smartbook (2.0).
39 *
Marek Vasutd5914012011-01-19 04:40:37 +000040 */
Marek Vasutd5914012011-01-19 04:40:37 +000041#define EFIKAMX_BOARD_REV_11 0x1
42#define EFIKAMX_BOARD_REV_12 0x2
43#define EFIKAMX_BOARD_REV_13 0x3
44#define EFIKAMX_BOARD_REV_14 0x4
45
Marek Vasutaf708cb2011-09-25 09:55:43 +000046#define EFIKASB_BOARD_REV_13 0x1
47#define EFIKASB_BOARD_REV_20 0x2
48
Marek Vasutd5914012011-01-19 04:40:37 +000049/*
50 * Board identification
51 */
Matt Sealeyfdd63c92012-08-27 05:58:30 +000052static u32 get_mx_rev(void)
Marek Vasutd5914012011-01-19 04:40:37 +000053{
54 u32 rev = 0;
55 /*
56 * Retrieve board ID:
Matt Sealeyfdd63c92012-08-27 05:58:30 +000057 *
58 * gpio: 16 17 11
59 * ==============
60 * r1.1: 1+ 1 1
61 * r1.2: 1 1 0
62 * r1.3: 1 0 1
63 * r1.4: 1 0 0
64 *
65 * + note: r1.1 does not strap this pin properly so it needs to
66 * be hacked or ignored.
Marek Vasutd5914012011-01-19 04:40:37 +000067 */
Marek Vasutd5914012011-01-19 04:40:37 +000068
Matt Sealeyfdd63c92012-08-27 05:58:30 +000069 /* set to 1 in order to get correct value on board rev 1.1 */
Stefano Babicac966aa2012-08-28 03:10:51 +000070 gpio_direction_output(IMX_GPIO_NR(3, 16), 1);
71 gpio_direction_input(IMX_GPIO_NR(3, 11));
72 gpio_direction_input(IMX_GPIO_NR(3, 16));
73 gpio_direction_input(IMX_GPIO_NR(3, 17));
Marek Vasutd5914012011-01-19 04:40:37 +000074
Stefano Babicac966aa2012-08-28 03:10:51 +000075 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 16))) << 0;
76 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 17))) << 1;
77 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 11))) << 2;
Marek Vasutd5914012011-01-19 04:40:37 +000078
79 return (~rev & 0x7) + 1;
80}
81
Eric Nelson6e142322012-10-03 07:26:38 +000082static iomux_v3_cfg_t const efikasb_revision_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +000083 MX51_PAD_EIM_CS3__GPIO2_28,
84 MX51_PAD_EIM_CS4__GPIO2_29,
85};
86
87static inline u32 get_sb_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +000088{
89 u32 rev = 0;
90
Matt Sealeyfdd63c92012-08-27 05:58:30 +000091 imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads,
92 ARRAY_SIZE(efikasb_revision_pads));
Stefano Babicac966aa2012-08-28 03:10:51 +000093 gpio_direction_input(IMX_GPIO_NR(2, 28));
94 gpio_direction_input(IMX_GPIO_NR(2, 29));
Marek Vasutaf708cb2011-09-25 09:55:43 +000095
Stefano Babicac966aa2012-08-28 03:10:51 +000096 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0;
97 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1;
Marek Vasutaf708cb2011-09-25 09:55:43 +000098
99 return rev;
100}
101
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000102inline uint32_t get_efikamx_rev(void)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000103{
104 if (machine_is_efikamx())
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000105 return get_mx_rev();
106 else if (machine_is_efikasb())
107 return get_sb_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000108}
109
Marek Vasutd5914012011-01-19 04:40:37 +0000110u32 get_board_rev(void)
111{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000112 return get_cpu_rev() | (get_efikamx_rev() << 8);
Marek Vasutd5914012011-01-19 04:40:37 +0000113}
114
115/*
116 * DRAM initialization
117 */
118int dram_init(void)
119{
120 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa55d23c2011-07-03 05:55:33 +0000121 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000122 PHYS_SDRAM_1_SIZE);
Marek Vasutd5914012011-01-19 04:40:37 +0000123 return 0;
124}
125
126/*
127 * UART configuration
128 */
Eric Nelson6e142322012-10-03 07:26:38 +0000129static iomux_v3_cfg_t const efikamx_uart_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000130 MX51_PAD_UART1_RXD__UART1_RXD,
131 MX51_PAD_UART1_TXD__UART1_TXD,
132 MX51_PAD_UART1_RTS__UART1_RTS,
133 MX51_PAD_UART1_CTS__UART1_CTS,
134};
Marek Vasutd5914012011-01-19 04:40:37 +0000135
136/*
137 * SPI configuration
138 */
Eric Nelson6e142322012-10-03 07:26:38 +0000139static iomux_v3_cfg_t const efikamx_spi_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000140 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
141 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
142 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
143 MX51_PAD_CSPI1_SS0__GPIO4_24,
144 MX51_PAD_CSPI1_SS1__GPIO4_25,
145 MX51_PAD_GPIO1_6__GPIO1_6,
146};
Marek Vasutd5914012011-01-19 04:40:37 +0000147
Stefano Babicac966aa2012-08-28 03:10:51 +0000148#define EFIKAMX_SPI_SS0 IMX_GPIO_NR(4, 24)
149#define EFIKAMX_SPI_SS1 IMX_GPIO_NR(4, 25)
150#define EFIKAMX_PMIC_IRQ IMX_GPIO_NR(1, 6)
Marek Vasutd5914012011-01-19 04:40:37 +0000151
152/*
153 * PMIC configuration
154 */
155#ifdef CONFIG_MXC_SPI
Nikita Kiryanov155fa9a2014-08-20 15:08:50 +0300156int board_spi_cs_gpio(unsigned bus, unsigned cs)
157{
158 return (bus == 0 && cs == 1) ? 121 : -1;
159}
160
Marek Vasutd5914012011-01-19 04:40:37 +0000161static void power_init(void)
162{
163 unsigned int val;
164 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200165 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000166 int ret;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200167
Fabio Estevamd74b3312013-11-20 20:26:05 -0200168 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewskic7336812012-11-13 03:21:55 +0000169 if (ret)
170 return;
171
172 p = pmic_get("FSL_PMIC");
173 if (!p)
174 return;
Marek Vasutd5914012011-01-19 04:40:37 +0000175
176 /* Write needed to Power Gate 2 register */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200177 pmic_reg_read(p, REG_POWER_MISC, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000178 val &= ~PWGT2SPIEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200179 pmic_reg_write(p, REG_POWER_MISC, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000180
181 /* Externally powered */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200182 pmic_reg_read(p, REG_CHARGE, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000183 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200184 pmic_reg_write(p, REG_CHARGE, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000185
186 /* power up the system first */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200187 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Marek Vasutd5914012011-01-19 04:40:37 +0000188
189 /* Set core voltage to 1.1V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200190 pmic_reg_read(p, REG_SW_0, &val);
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000191 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200192 pmic_reg_write(p, REG_SW_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000193
194 /* Setup VCC (SW2) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200195 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000196 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200197 pmic_reg_write(p, REG_SW_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000198
199 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200200 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000201 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200202 pmic_reg_write(p, REG_SW_2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000203 udelay(50);
204
205 /* Raise the core frequency to 800MHz */
206 writel(0x0, &mxc_ccm->cacrr);
207
208 /* Set switchers in Auto in NORMAL mode & STANDBY mode */
209 /* Setup the switcher mode for SW1 & SW2*/
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200210 pmic_reg_read(p, REG_SW_4, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000211 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
212 (SWMODE_MASK << SWMODE2_SHIFT)));
213 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
214 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200215 pmic_reg_write(p, REG_SW_4, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000216
217 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200218 pmic_reg_read(p, REG_SW_5, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000219 val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
220 (SWMODE_MASK << SWMODE4_SHIFT)));
221 val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
222 (SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200223 pmic_reg_write(p, REG_SW_5, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000224
Marek Vasut55723952011-09-28 02:19:57 +0000225 /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200226 pmic_reg_read(p, REG_SETTING_0, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000227 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000228 val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200229 pmic_reg_write(p, REG_SETTING_0, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000230
231 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200232 pmic_reg_read(p, REG_SETTING_1, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000233 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
Marek Vasut55723952011-09-28 02:19:57 +0000234 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200235 pmic_reg_write(p, REG_SETTING_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000236
Marek Vasut55723952011-09-28 02:19:57 +0000237 /* Enable VGEN1, VGEN2, VDIG, VPLL */
238 pmic_reg_read(p, REG_MODE_0, &val);
239 val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN;
240 pmic_reg_write(p, REG_MODE_0, val);
241
Marek Vasutd5914012011-01-19 04:40:37 +0000242 /* Configure VGEN3 and VCAM regulators to use external PNP */
243 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200244 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000245 udelay(200);
246
247 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
248 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
Marek Vasut55723952011-09-28 02:19:57 +0000249 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200250 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000251
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200252 pmic_reg_read(p, REG_POWER_CTL2, &val);
Marek Vasutd5914012011-01-19 04:40:37 +0000253 val |= WDIRESET;
Stefano Babic9c38f7d2011-10-06 11:44:26 +0200254 pmic_reg_write(p, REG_POWER_CTL2, val);
Marek Vasutd5914012011-01-19 04:40:37 +0000255
256 udelay(2500);
257}
258#else
259static inline void power_init(void) { }
260#endif
261
262/*
263 * MMC configuration
264 */
265#ifdef CONFIG_FSL_ESDHC
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000266
Marek Vasutd5914012011-01-19 04:40:37 +0000267struct fsl_esdhc_cfg esdhc_cfg[2] = {
Benoît Thébaudeau16e43f32012-08-13 07:28:16 +0000268 {MMC_SDHC1_BASE_ADDR},
269 {MMC_SDHC2_BASE_ADDR},
Marek Vasutd5914012011-01-19 04:40:37 +0000270};
271
Eric Nelson6e142322012-10-03 07:26:38 +0000272static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000273 MX51_PAD_SD1_CMD__SD1_CMD,
274 MX51_PAD_SD1_CLK__SD1_CLK,
275 MX51_PAD_SD1_DATA0__SD1_DATA0,
276 MX51_PAD_SD1_DATA1__SD1_DATA1,
277 MX51_PAD_SD1_DATA2__SD1_DATA2,
278 MX51_PAD_SD1_DATA3__SD1_DATA3,
279 MX51_PAD_GPIO1_1__SD1_WP,
280};
281
Stefano Babicac966aa2012-08-28 03:10:51 +0000282#define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000283
Eric Nelson6e142322012-10-03 07:26:38 +0000284static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000285 MX51_PAD_GPIO1_0__SD1_CD,
Benoît Thébaudeauf49d92a2013-05-03 10:32:25 +0000286 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, MX51_ESDHC_PAD_CTRL),
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000287};
288
Stefano Babicac966aa2012-08-28 03:10:51 +0000289#define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0)
290#define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000291
Eric Nelson6e142322012-10-03 07:26:38 +0000292static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000293 MX51_PAD_SD2_CMD__SD2_CMD,
294 MX51_PAD_SD2_CLK__SD2_CLK,
295 MX51_PAD_SD2_DATA0__SD2_DATA0,
296 MX51_PAD_SD2_DATA1__SD2_DATA1,
297 MX51_PAD_SD2_DATA2__SD2_DATA2,
298 MX51_PAD_SD2_DATA3__SD2_DATA3,
299 MX51_PAD_GPIO1_7__SD2_WP,
300 MX51_PAD_GPIO1_8__SD2_CD,
301};
302
Stefano Babicac966aa2012-08-28 03:10:51 +0000303#define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8)
304#define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7)
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000305
306static inline uint32_t efikamx_mmc_getcd(u32 base)
Marek Vasutaf708cb2011-09-25 09:55:43 +0000307{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000308 if (base == MMC_SDHC1_BASE_ADDR)
309 if (machine_is_efikamx())
310 return EFIKAMX_SDHC1_CD;
311 else
312 return EFIKASB_SDHC1_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000313 else
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000314 return EFIKASB_SDHC2_CD;
Marek Vasutaf708cb2011-09-25 09:55:43 +0000315}
316
Thierry Reding314284b2012-01-02 01:15:36 +0000317int board_mmc_getcd(struct mmc *mmc)
Marek Vasutd5914012011-01-19 04:40:37 +0000318{
319 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000320 uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base);
321 int ret = !gpio_get_value(cd);
Marek Vasutd5914012011-01-19 04:40:37 +0000322
Thierry Reding314284b2012-01-02 01:15:36 +0000323 return ret;
Marek Vasutd5914012011-01-19 04:40:37 +0000324}
Marek Vasutaf708cb2011-09-25 09:55:43 +0000325
Marek Vasutd5914012011-01-19 04:40:37 +0000326int board_mmc_init(bd_t *bis)
327{
328 int ret;
329
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000330 /*
331 * All Efika MX boards use eSDHC1 with a common write-protect GPIO
332 */
333 imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads,
334 ARRAY_SIZE(efikamx_sdhc1_pads));
335 gpio_direction_input(EFIKAMX_SDHC1_WP);
Marek Vasutd5914012011-01-19 04:40:37 +0000336
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000337 /*
338 * Smartbook and Smarttop differ on the location of eSDHC1
339 * carrier-detect GPIO
340 */
341 if (machine_is_efikamx()) {
342 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]);
343 gpio_direction_input(EFIKAMX_SDHC1_CD);
344 } else if (machine_is_efikasb()) {
345 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]);
346 gpio_direction_input(EFIKASB_SDHC1_CD);
347 }
Marek Vasutd5914012011-01-19 04:40:37 +0000348
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000349 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
350 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
351
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 */
Eric Nelson6e142322012-10-03 07:26:38 +0000371static iomux_v3_cfg_t const efikamx_pata_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000372 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
Eric Nelson6e142322012-10-03 07:26:38 +0000422static iomux_v3_cfg_t const efikasb_led_pads[] = {
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000423 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
Marek Vasutd5914012011-01-19 04:40:37 +0000495 return 0;
496}
497
498int checkboard(void)
499{
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000500 u32 rev = get_efikamx_rev();
Marek Vasutaf708cb2011-09-25 09:55:43 +0000501
Matt Sealeyfdd63c92012-08-27 05:58:30 +0000502 printf("Board: Genesi Efika MX ");
503 if (machine_is_efikamx())
504 printf("Smarttop (1.%i)\n", rev & 0xf);
505 else if (machine_is_efikasb())
506 printf("Smartbook\n");
Marek Vasutd5914012011-01-19 04:40:37 +0000507
508 return 0;
509}