blob: 137e4ed661030b9ede7f194f2f7f865429ebce1d [file] [log] [blame]
Marek Vasut92c34832011-01-19 04:40:37 +00001/*
Matt Sealeyed95f612012-08-27 05:58:30 +00002 * Copyright (C) 2009 Freescale Semiconductor, Inc.
Marek Vasut92c34832011-01-19 04:40:37 +00003 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
Matt Sealeyed95f612012-08-27 05:58:30 +00004 * Copyright (C) 2009-2012 Genesi USA, Inc.
Marek Vasut92c34832011-01-19 04:40:37 +00005 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Marek Vasut92c34832011-01-19 04:40:37 +00007 */
8
9#include <common.h>
10#include <asm/io.h>
Matt Sealeyed95f612012-08-27 05:58:30 +000011#include <asm/arch/iomux-mx51.h>
Stefano Babica3b1edd2011-08-21 10:53:32 +020012#include <asm/gpio.h>
Marek Vasut92c34832011-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ébaudeauc58ff342012-10-01 08:36:25 +000016#include <asm/arch/clock.h>
Marek Vasut92c34832011-01-19 04:40:37 +000017#include <i2c.h>
18#include <mmc.h>
19#include <fsl_esdhc.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000020#include <power/pmic.h>
Marek Vasut92c34832011-01-19 04:40:37 +000021#include <fsl_pmic.h>
22#include <mc13892.h>
23
24DECLARE_GLOBAL_DATA_PTR;
25
26/*
27 * Compile-time error checking
28 */
29#ifndef CONFIG_MXC_SPI
30#error "CONFIG_MXC_SPI not set, this is essential for board's operation!"
31#endif
32
33/*
Matt Sealeyed95f612012-08-27 05:58:30 +000034 * Board revisions
35 *
36 * Note that we get these revisions here for convenience, but we only set
37 * up for the production model Smarttop (1.3) and Smartbook (2.0).
38 *
Marek Vasut92c34832011-01-19 04:40:37 +000039 */
Marek Vasut92c34832011-01-19 04:40:37 +000040#define EFIKAMX_BOARD_REV_11 0x1
41#define EFIKAMX_BOARD_REV_12 0x2
42#define EFIKAMX_BOARD_REV_13 0x3
43#define EFIKAMX_BOARD_REV_14 0x4
44
Marek Vasut3cc35cc2011-09-25 09:55:43 +000045#define EFIKASB_BOARD_REV_13 0x1
46#define EFIKASB_BOARD_REV_20 0x2
47
Marek Vasut92c34832011-01-19 04:40:37 +000048/*
49 * Board identification
50 */
Matt Sealeyed95f612012-08-27 05:58:30 +000051static u32 get_mx_rev(void)
Marek Vasut92c34832011-01-19 04:40:37 +000052{
53 u32 rev = 0;
54 /*
55 * Retrieve board ID:
Matt Sealeyed95f612012-08-27 05:58:30 +000056 *
57 * gpio: 16 17 11
58 * ==============
59 * r1.1: 1+ 1 1
60 * r1.2: 1 1 0
61 * r1.3: 1 0 1
62 * r1.4: 1 0 0
63 *
64 * + note: r1.1 does not strap this pin properly so it needs to
65 * be hacked or ignored.
Marek Vasut92c34832011-01-19 04:40:37 +000066 */
Marek Vasut92c34832011-01-19 04:40:37 +000067
Matt Sealeyed95f612012-08-27 05:58:30 +000068 /* set to 1 in order to get correct value on board rev 1.1 */
Stefano Babic68fc6382012-08-28 03:10:51 +000069 gpio_direction_output(IMX_GPIO_NR(3, 16), 1);
70 gpio_direction_input(IMX_GPIO_NR(3, 11));
71 gpio_direction_input(IMX_GPIO_NR(3, 16));
72 gpio_direction_input(IMX_GPIO_NR(3, 17));
Marek Vasut92c34832011-01-19 04:40:37 +000073
Stefano Babic68fc6382012-08-28 03:10:51 +000074 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 16))) << 0;
75 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 17))) << 1;
76 rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 11))) << 2;
Marek Vasut92c34832011-01-19 04:40:37 +000077
78 return (~rev & 0x7) + 1;
79}
80
Eric Nelson16802092012-10-03 07:26:38 +000081static iomux_v3_cfg_t const efikasb_revision_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +000082 MX51_PAD_EIM_CS3__GPIO2_28,
83 MX51_PAD_EIM_CS4__GPIO2_29,
84};
85
86static inline u32 get_sb_rev(void)
Marek Vasut3cc35cc2011-09-25 09:55:43 +000087{
88 u32 rev = 0;
89
Matt Sealeyed95f612012-08-27 05:58:30 +000090 imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads,
91 ARRAY_SIZE(efikasb_revision_pads));
Stefano Babic68fc6382012-08-28 03:10:51 +000092 gpio_direction_input(IMX_GPIO_NR(2, 28));
93 gpio_direction_input(IMX_GPIO_NR(2, 29));
Marek Vasut3cc35cc2011-09-25 09:55:43 +000094
Stefano Babic68fc6382012-08-28 03:10:51 +000095 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0;
96 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1;
Marek Vasut3cc35cc2011-09-25 09:55:43 +000097
98 return rev;
99}
100
Matt Sealeyed95f612012-08-27 05:58:30 +0000101inline uint32_t get_efikamx_rev(void)
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000102{
103 if (machine_is_efikamx())
Matt Sealeyed95f612012-08-27 05:58:30 +0000104 return get_mx_rev();
105 else if (machine_is_efikasb())
106 return get_sb_rev();
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000107}
108
Marek Vasut92c34832011-01-19 04:40:37 +0000109u32 get_board_rev(void)
110{
Matt Sealeyed95f612012-08-27 05:58:30 +0000111 return get_cpu_rev() | (get_efikamx_rev() << 8);
Marek Vasut92c34832011-01-19 04:40:37 +0000112}
113
114/*
115 * DRAM initialization
116 */
117int dram_init(void)
118{
119 /* dram_init must store complete ramsize in gd->ram_size */
Albert ARIBAUDa9606732011-07-03 05:55:33 +0000120 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
Matt Sealeyed95f612012-08-27 05:58:30 +0000121 PHYS_SDRAM_1_SIZE);
Marek Vasut92c34832011-01-19 04:40:37 +0000122 return 0;
123}
124
125/*
126 * UART configuration
127 */
Eric Nelson16802092012-10-03 07:26:38 +0000128static iomux_v3_cfg_t const efikamx_uart_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000129 MX51_PAD_UART1_RXD__UART1_RXD,
130 MX51_PAD_UART1_TXD__UART1_TXD,
131 MX51_PAD_UART1_RTS__UART1_RTS,
132 MX51_PAD_UART1_CTS__UART1_CTS,
133};
Marek Vasut92c34832011-01-19 04:40:37 +0000134
135/*
136 * SPI configuration
137 */
Eric Nelson16802092012-10-03 07:26:38 +0000138static iomux_v3_cfg_t const efikamx_spi_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000139 MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI,
140 MX51_PAD_CSPI1_MISO__ECSPI1_MISO,
141 MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK,
142 MX51_PAD_CSPI1_SS0__GPIO4_24,
143 MX51_PAD_CSPI1_SS1__GPIO4_25,
144 MX51_PAD_GPIO1_6__GPIO1_6,
145};
Marek Vasut92c34832011-01-19 04:40:37 +0000146
Stefano Babic68fc6382012-08-28 03:10:51 +0000147#define EFIKAMX_SPI_SS0 IMX_GPIO_NR(4, 24)
148#define EFIKAMX_SPI_SS1 IMX_GPIO_NR(4, 25)
149#define EFIKAMX_PMIC_IRQ IMX_GPIO_NR(1, 6)
Marek Vasut92c34832011-01-19 04:40:37 +0000150
151/*
152 * PMIC configuration
153 */
154#ifdef CONFIG_MXC_SPI
Nikita Kiryanov00cd7382014-08-20 15:08:50 +0300155int board_spi_cs_gpio(unsigned bus, unsigned cs)
156{
157 return (bus == 0 && cs == 1) ? 121 : -1;
158}
159
Marek Vasut92c34832011-01-19 04:40:37 +0000160static void power_init(void)
161{
162 unsigned int val;
163 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
Stefano Babic11bbd712011-10-06 11:44:26 +0200164 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000165 int ret;
166
Fabio Estevam6d240732013-11-20 20:26:05 -0200167 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000168 if (ret)
169 return;
Stefano Babic11bbd712011-10-06 11:44:26 +0200170
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000171 p = pmic_get("FSL_PMIC");
172 if (!p)
173 return;
Marek Vasut92c34832011-01-19 04:40:37 +0000174
175 /* Write needed to Power Gate 2 register */
Stefano Babic11bbd712011-10-06 11:44:26 +0200176 pmic_reg_read(p, REG_POWER_MISC, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000177 val &= ~PWGT2SPIEN;
Stefano Babic11bbd712011-10-06 11:44:26 +0200178 pmic_reg_write(p, REG_POWER_MISC, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000179
180 /* Externally powered */
Stefano Babic11bbd712011-10-06 11:44:26 +0200181 pmic_reg_read(p, REG_CHARGE, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000182 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
Stefano Babic11bbd712011-10-06 11:44:26 +0200183 pmic_reg_write(p, REG_CHARGE, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000184
185 /* power up the system first */
Stefano Babic11bbd712011-10-06 11:44:26 +0200186 pmic_reg_write(p, REG_POWER_MISC, PWUP);
Marek Vasut92c34832011-01-19 04:40:37 +0000187
188 /* Set core voltage to 1.1V */
Stefano Babic11bbd712011-10-06 11:44:26 +0200189 pmic_reg_read(p, REG_SW_0, &val);
Matt Sealeyed95f612012-08-27 05:58:30 +0000190 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
Stefano Babic11bbd712011-10-06 11:44:26 +0200191 pmic_reg_write(p, REG_SW_0, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000192
193 /* Setup VCC (SW2) to 1.25 */
Stefano Babic11bbd712011-10-06 11:44:26 +0200194 pmic_reg_read(p, REG_SW_1, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000195 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic11bbd712011-10-06 11:44:26 +0200196 pmic_reg_write(p, REG_SW_1, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000197
198 /* Setup 1V2_DIG1 (SW3) to 1.25 */
Stefano Babic11bbd712011-10-06 11:44:26 +0200199 pmic_reg_read(p, REG_SW_2, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000200 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
Stefano Babic11bbd712011-10-06 11:44:26 +0200201 pmic_reg_write(p, REG_SW_2, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000202 udelay(50);
203
204 /* Raise the core frequency to 800MHz */
205 writel(0x0, &mxc_ccm->cacrr);
206
207 /* Set switchers in Auto in NORMAL mode & STANDBY mode */
208 /* Setup the switcher mode for SW1 & SW2*/
Stefano Babic11bbd712011-10-06 11:44:26 +0200209 pmic_reg_read(p, REG_SW_4, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000210 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
211 (SWMODE_MASK << SWMODE2_SHIFT)));
212 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
213 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
Stefano Babic11bbd712011-10-06 11:44:26 +0200214 pmic_reg_write(p, REG_SW_4, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000215
216 /* Setup the switcher mode for SW3 & SW4 */
Stefano Babic11bbd712011-10-06 11:44:26 +0200217 pmic_reg_read(p, REG_SW_5, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000218 val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
219 (SWMODE_MASK << SWMODE4_SHIFT)));
220 val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
221 (SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
Stefano Babic11bbd712011-10-06 11:44:26 +0200222 pmic_reg_write(p, REG_SW_5, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000223
Marek Vasut9f1cbd32011-09-28 02:19:57 +0000224 /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */
Stefano Babic11bbd712011-10-06 11:44:26 +0200225 pmic_reg_read(p, REG_SETTING_0, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000226 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
Marek Vasut9f1cbd32011-09-28 02:19:57 +0000227 val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6;
Stefano Babic11bbd712011-10-06 11:44:26 +0200228 pmic_reg_write(p, REG_SETTING_0, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000229
230 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
Stefano Babic11bbd712011-10-06 11:44:26 +0200231 pmic_reg_read(p, REG_SETTING_1, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000232 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
Marek Vasut9f1cbd32011-09-28 02:19:57 +0000233 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15;
Stefano Babic11bbd712011-10-06 11:44:26 +0200234 pmic_reg_write(p, REG_SETTING_1, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000235
Marek Vasut9f1cbd32011-09-28 02:19:57 +0000236 /* Enable VGEN1, VGEN2, VDIG, VPLL */
237 pmic_reg_read(p, REG_MODE_0, &val);
238 val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN;
239 pmic_reg_write(p, REG_MODE_0, val);
240
Marek Vasut92c34832011-01-19 04:40:37 +0000241 /* Configure VGEN3 and VCAM regulators to use external PNP */
242 val = VGEN3CONFIG | VCAMCONFIG;
Stefano Babic11bbd712011-10-06 11:44:26 +0200243 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000244 udelay(200);
245
246 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
247 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
Marek Vasut9f1cbd32011-09-28 02:19:57 +0000248 VVIDEOEN | VAUDIOEN | VSDEN;
Stefano Babic11bbd712011-10-06 11:44:26 +0200249 pmic_reg_write(p, REG_MODE_1, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000250
Stefano Babic11bbd712011-10-06 11:44:26 +0200251 pmic_reg_read(p, REG_POWER_CTL2, &val);
Marek Vasut92c34832011-01-19 04:40:37 +0000252 val |= WDIRESET;
Stefano Babic11bbd712011-10-06 11:44:26 +0200253 pmic_reg_write(p, REG_POWER_CTL2, val);
Marek Vasut92c34832011-01-19 04:40:37 +0000254
255 udelay(2500);
256}
257#else
258static inline void power_init(void) { }
259#endif
260
261/*
262 * MMC configuration
263 */
264#ifdef CONFIG_FSL_ESDHC
Matt Sealeyed95f612012-08-27 05:58:30 +0000265
Marek Vasut92c34832011-01-19 04:40:37 +0000266struct fsl_esdhc_cfg esdhc_cfg[2] = {
Benoît Thébaudeauc08d11c2012-08-13 07:28:16 +0000267 {MMC_SDHC1_BASE_ADDR},
268 {MMC_SDHC2_BASE_ADDR},
Marek Vasut92c34832011-01-19 04:40:37 +0000269};
270
Eric Nelson16802092012-10-03 07:26:38 +0000271static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000272 MX51_PAD_SD1_CMD__SD1_CMD,
273 MX51_PAD_SD1_CLK__SD1_CLK,
274 MX51_PAD_SD1_DATA0__SD1_DATA0,
275 MX51_PAD_SD1_DATA1__SD1_DATA1,
276 MX51_PAD_SD1_DATA2__SD1_DATA2,
277 MX51_PAD_SD1_DATA3__SD1_DATA3,
278 MX51_PAD_GPIO1_1__SD1_WP,
279};
280
Stefano Babic68fc6382012-08-28 03:10:51 +0000281#define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1)
Matt Sealeyed95f612012-08-27 05:58:30 +0000282
Eric Nelson16802092012-10-03 07:26:38 +0000283static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000284 MX51_PAD_GPIO1_0__SD1_CD,
Benoît Thébaudeau9c8801b2013-05-03 10:32:25 +0000285 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, MX51_ESDHC_PAD_CTRL),
Matt Sealeyed95f612012-08-27 05:58:30 +0000286};
287
Stefano Babic68fc6382012-08-28 03:10:51 +0000288#define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0)
289#define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27)
Matt Sealeyed95f612012-08-27 05:58:30 +0000290
Eric Nelson16802092012-10-03 07:26:38 +0000291static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000292 MX51_PAD_SD2_CMD__SD2_CMD,
293 MX51_PAD_SD2_CLK__SD2_CLK,
294 MX51_PAD_SD2_DATA0__SD2_DATA0,
295 MX51_PAD_SD2_DATA1__SD2_DATA1,
296 MX51_PAD_SD2_DATA2__SD2_DATA2,
297 MX51_PAD_SD2_DATA3__SD2_DATA3,
298 MX51_PAD_GPIO1_7__SD2_WP,
299 MX51_PAD_GPIO1_8__SD2_CD,
300};
301
Stefano Babic68fc6382012-08-28 03:10:51 +0000302#define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8)
303#define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7)
Matt Sealeyed95f612012-08-27 05:58:30 +0000304
305static inline uint32_t efikamx_mmc_getcd(u32 base)
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000306{
Matt Sealeyed95f612012-08-27 05:58:30 +0000307 if (base == MMC_SDHC1_BASE_ADDR)
308 if (machine_is_efikamx())
309 return EFIKAMX_SDHC1_CD;
310 else
311 return EFIKASB_SDHC1_CD;
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000312 else
Matt Sealeyed95f612012-08-27 05:58:30 +0000313 return EFIKASB_SDHC2_CD;
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000314}
315
Thierry Redingd7aebf42012-01-02 01:15:36 +0000316int board_mmc_getcd(struct mmc *mmc)
Marek Vasut92c34832011-01-19 04:40:37 +0000317{
318 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
Matt Sealeyed95f612012-08-27 05:58:30 +0000319 uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base);
320 int ret = !gpio_get_value(cd);
Marek Vasut92c34832011-01-19 04:40:37 +0000321
Thierry Redingd7aebf42012-01-02 01:15:36 +0000322 return ret;
Marek Vasut92c34832011-01-19 04:40:37 +0000323}
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000324
Marek Vasut92c34832011-01-19 04:40:37 +0000325int board_mmc_init(bd_t *bis)
326{
327 int ret;
Marek Vasut92c34832011-01-19 04:40:37 +0000328
Matt Sealeyed95f612012-08-27 05:58:30 +0000329 /*
330 * All Efika MX boards use eSDHC1 with a common write-protect GPIO
331 */
332 imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads,
333 ARRAY_SIZE(efikamx_sdhc1_pads));
334 gpio_direction_input(EFIKAMX_SDHC1_WP);
Marek Vasut92c34832011-01-19 04:40:37 +0000335
Matt Sealeyed95f612012-08-27 05:58:30 +0000336 /*
337 * Smartbook and Smarttop differ on the location of eSDHC1
338 * carrier-detect GPIO
339 */
340 if (machine_is_efikamx()) {
341 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]);
342 gpio_direction_input(EFIKAMX_SDHC1_CD);
343 } else if (machine_is_efikasb()) {
344 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]);
345 gpio_direction_input(EFIKASB_SDHC1_CD);
346 }
Marek Vasut92c34832011-01-19 04:40:37 +0000347
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000348 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
349 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
350
Matt Sealeyed95f612012-08-27 05:58:30 +0000351 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
Marek Vasut92c34832011-01-19 04:40:37 +0000352
Matt Sealeyed95f612012-08-27 05:58:30 +0000353 if (machine_is_efikasb()) {
Marek Vasut92c34832011-01-19 04:40:37 +0000354
Matt Sealeyed95f612012-08-27 05:58:30 +0000355 imx_iomux_v3_setup_multiple_pads(efikasb_sdhc2_pads,
356 ARRAY_SIZE(efikasb_sdhc2_pads));
357 gpio_direction_input(EFIKASB_SDHC2_CD);
358 gpio_direction_input(EFIKASB_SDHC2_WP);
Marek Vasut92c34832011-01-19 04:40:37 +0000359 if (!ret)
360 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]);
Marek Vasut92c34832011-01-19 04:40:37 +0000361 }
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000362
Marek Vasut92c34832011-01-19 04:40:37 +0000363 return ret;
364}
365#endif
366
367/*
Matt Sealeyed95f612012-08-27 05:58:30 +0000368 * PATA
Marek Vasut92c34832011-01-19 04:40:37 +0000369 */
Eric Nelson16802092012-10-03 07:26:38 +0000370static iomux_v3_cfg_t const efikamx_pata_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000371 MX51_PAD_NANDF_WE_B__PATA_DIOW,
372 MX51_PAD_NANDF_RE_B__PATA_DIOR,
373 MX51_PAD_NANDF_ALE__PATA_BUFFER_EN,
374 MX51_PAD_NANDF_CLE__PATA_RESET_B,
375 MX51_PAD_NANDF_WP_B__PATA_DMACK,
376 MX51_PAD_NANDF_RB0__PATA_DMARQ,
377 MX51_PAD_NANDF_RB1__PATA_IORDY,
378 MX51_PAD_GPIO_NAND__PATA_INTRQ,
379 MX51_PAD_NANDF_CS2__PATA_CS_0,
380 MX51_PAD_NANDF_CS3__PATA_CS_1,
381 MX51_PAD_NANDF_CS4__PATA_DA_0,
382 MX51_PAD_NANDF_CS5__PATA_DA_1,
383 MX51_PAD_NANDF_CS6__PATA_DA_2,
384 MX51_PAD_NANDF_D15__PATA_DATA15,
385 MX51_PAD_NANDF_D14__PATA_DATA14,
386 MX51_PAD_NANDF_D13__PATA_DATA13,
387 MX51_PAD_NANDF_D12__PATA_DATA12,
388 MX51_PAD_NANDF_D11__PATA_DATA11,
389 MX51_PAD_NANDF_D10__PATA_DATA10,
390 MX51_PAD_NANDF_D9__PATA_DATA9,
391 MX51_PAD_NANDF_D8__PATA_DATA8,
392 MX51_PAD_NANDF_D7__PATA_DATA7,
393 MX51_PAD_NANDF_D6__PATA_DATA6,
394 MX51_PAD_NANDF_D5__PATA_DATA5,
395 MX51_PAD_NANDF_D4__PATA_DATA4,
396 MX51_PAD_NANDF_D3__PATA_DATA3,
397 MX51_PAD_NANDF_D2__PATA_DATA2,
398 MX51_PAD_NANDF_D1__PATA_DATA1,
399 MX51_PAD_NANDF_D0__PATA_DATA0,
400};
Marek Vasut92c34832011-01-19 04:40:37 +0000401
402/*
Marek Vasutf2ebfeb2011-06-24 21:46:07 +0200403 * EHCI USB
404 */
405#ifdef CONFIG_CMD_USB
406extern void setup_iomux_usb(void);
407#else
408static inline void setup_iomux_usb(void) { }
409#endif
410
411/*
Marek Vasut92c34832011-01-19 04:40:37 +0000412 * LED configuration
Matt Sealeyed95f612012-08-27 05:58:30 +0000413 *
414 * Smarttop LED pad config is done in the DCD
415 *
Marek Vasut92c34832011-01-19 04:40:37 +0000416 */
Stefano Babic68fc6382012-08-28 03:10:51 +0000417#define EFIKAMX_LED_BLUE IMX_GPIO_NR(3, 13)
418#define EFIKAMX_LED_GREEN IMX_GPIO_NR(3, 14)
419#define EFIKAMX_LED_RED IMX_GPIO_NR(3, 15)
Stefano Babica3b1edd2011-08-21 10:53:32 +0200420
Eric Nelson16802092012-10-03 07:26:38 +0000421static iomux_v3_cfg_t const efikasb_led_pads[] = {
Matt Sealeyed95f612012-08-27 05:58:30 +0000422 MX51_PAD_GPIO1_3__GPIO1_3,
423 MX51_PAD_EIM_CS0__GPIO2_25,
424};
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000425
Stefano Babic68fc6382012-08-28 03:10:51 +0000426#define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25)
427#define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */
Marek Vasut92c34832011-01-19 04:40:37 +0000428
429/*
430 * Board initialization
431 */
Marek Vasut92c34832011-01-19 04:40:37 +0000432int board_early_init_f(void)
433{
Matt Sealeyed95f612012-08-27 05:58:30 +0000434 if (machine_is_efikasb()) {
435 imx_iomux_v3_setup_multiple_pads(efikasb_led_pads,
436 ARRAY_SIZE(efikasb_led_pads));
437 gpio_direction_output(EFIKASB_CAPSLOCK_LED, 0);
438 gpio_direction_output(EFIKASB_MESSAGE_LED, 1);
439 } else if (machine_is_efikamx()) {
440 /*
441 * Set up GPIO directions for LEDs.
442 * IOMUX has been done in the DCD already.
443 * Turn the red LED on for pre-relocation code.
444 */
445 gpio_direction_output(EFIKAMX_LED_BLUE, 0);
446 gpio_direction_output(EFIKAMX_LED_GREEN, 0);
447 gpio_direction_output(EFIKAMX_LED_RED, 1);
448 }
449
450 /*
451 * Both these pad configurations for UART and SPI are kind of redundant
452 * since they are the Power-On Defaults for the i.MX51. But, it seems we
453 * should make absolutely sure that they are set up correctly.
454 */
455 imx_iomux_v3_setup_multiple_pads(efikamx_uart_pads,
456 ARRAY_SIZE(efikamx_uart_pads));
457 imx_iomux_v3_setup_multiple_pads(efikamx_spi_pads,
458 ARRAY_SIZE(efikamx_spi_pads));
459
460 /* not technically required for U-Boot operation but do it anyway. */
461 gpio_direction_input(EFIKAMX_PMIC_IRQ);
462 /* Deselect both CS for now, otherwise NOR doesn't probe properly. */
463 gpio_direction_output(EFIKAMX_SPI_SS0, 0);
464 gpio_direction_output(EFIKAMX_SPI_SS1, 1);
Marek Vasut92c34832011-01-19 04:40:37 +0000465
466 return 0;
467}
468
469int board_init(void)
470{
Marek Vasut92c34832011-01-19 04:40:37 +0000471 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
472
473 return 0;
474}
475
476int board_late_init(void)
477{
Matt Sealeyed95f612012-08-27 05:58:30 +0000478 if (machine_is_efikamx()) {
479 /*
480 * Set up Blue LED for "In U-Boot" status.
481 * We're all relocated and ready to U-Boot!
482 */
483 gpio_set_value(EFIKAMX_LED_RED, 0);
484 gpio_set_value(EFIKAMX_LED_GREEN, 0);
485 gpio_set_value(EFIKAMX_LED_BLUE, 1);
486 }
Marek Vasut92c34832011-01-19 04:40:37 +0000487
488 power_init();
489
Matt Sealeyed95f612012-08-27 05:58:30 +0000490 imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads,
491 ARRAY_SIZE(efikamx_pata_pads));
Marek Vasutf2ebfeb2011-06-24 21:46:07 +0200492 setup_iomux_usb();
493
Marek Vasut92c34832011-01-19 04:40:37 +0000494 return 0;
495}
496
497int checkboard(void)
498{
Matt Sealeyed95f612012-08-27 05:58:30 +0000499 u32 rev = get_efikamx_rev();
Marek Vasut3cc35cc2011-09-25 09:55:43 +0000500
Matt Sealeyed95f612012-08-27 05:58:30 +0000501 printf("Board: Genesi Efika MX ");
502 if (machine_is_efikamx())
503 printf("Smarttop (1.%i)\n", rev & 0xf);
504 else if (machine_is_efikasb())
505 printf("Smartbook\n");
Marek Vasut92c34832011-01-19 04:40:37 +0000506
507 return 0;
508}