2 * Copyright (C) 2009 Freescale Semiconductor, Inc.
3 * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com>
4 * Copyright (C) 2009-2012 Genesi USA, Inc.
6 * SPDX-License-Identifier: GPL-2.0+
11 #include <asm/arch/iomux-mx51.h>
13 #include <asm/errno.h>
14 #include <asm/arch/sys_proto.h>
15 #include <asm/arch/crm_regs.h>
16 #include <asm/arch/clock.h>
19 #include <fsl_esdhc.h>
20 #include <power/pmic.h>
24 DECLARE_GLOBAL_DATA_PTR;
27 * Compile-time error checking
29 #ifndef CONFIG_MXC_SPI
30 #error "CONFIG_MXC_SPI not set, this is essential for board's operation!"
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).
40 #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
45 #define EFIKASB_BOARD_REV_13 0x1
46 #define EFIKASB_BOARD_REV_20 0x2
49 * Board identification
51 static u32 get_mx_rev(void)
64 * + note: r1.1 does not strap this pin properly so it needs to
65 * be hacked or ignored.
68 /* set to 1 in order to get correct value on board rev 1.1 */
69 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));
74 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;
78 return (~rev & 0x7) + 1;
81 static iomux_v3_cfg_t const efikasb_revision_pads[] = {
82 MX51_PAD_EIM_CS3__GPIO2_28,
83 MX51_PAD_EIM_CS4__GPIO2_29,
86 static inline u32 get_sb_rev(void)
90 imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads,
91 ARRAY_SIZE(efikasb_revision_pads));
92 gpio_direction_input(IMX_GPIO_NR(2, 28));
93 gpio_direction_input(IMX_GPIO_NR(2, 29));
95 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0;
96 rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1;
101 inline uint32_t get_efikamx_rev(void)
103 if (machine_is_efikamx())
105 else if (machine_is_efikasb())
109 u32 get_board_rev(void)
111 return get_cpu_rev() | (get_efikamx_rev() << 8);
115 * DRAM initialization
119 /* dram_init must store complete ramsize in gd->ram_size */
120 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
128 static iomux_v3_cfg_t const efikamx_uart_pads[] = {
129 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,
138 static iomux_v3_cfg_t const efikamx_spi_pads[] = {
139 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,
147 #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)
154 #ifdef CONFIG_MXC_SPI
155 static void power_init(void)
158 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE;
162 ret = pmic_init(CONFIG_FSL_PMIC_BUS);
166 p = pmic_get("FSL_PMIC");
170 /* Write needed to Power Gate 2 register */
171 pmic_reg_read(p, REG_POWER_MISC, &val);
173 pmic_reg_write(p, REG_POWER_MISC, val);
175 /* Externally powered */
176 pmic_reg_read(p, REG_CHARGE, &val);
177 val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB;
178 pmic_reg_write(p, REG_CHARGE, val);
180 /* power up the system first */
181 pmic_reg_write(p, REG_POWER_MISC, PWUP);
183 /* Set core voltage to 1.1V */
184 pmic_reg_read(p, REG_SW_0, &val);
185 val = (val & ~SWx_VOLT_MASK) | SWx_1_100V;
186 pmic_reg_write(p, REG_SW_0, val);
188 /* Setup VCC (SW2) to 1.25 */
189 pmic_reg_read(p, REG_SW_1, &val);
190 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
191 pmic_reg_write(p, REG_SW_1, val);
193 /* Setup 1V2_DIG1 (SW3) to 1.25 */
194 pmic_reg_read(p, REG_SW_2, &val);
195 val = (val & ~SWx_VOLT_MASK) | SWx_1_250V;
196 pmic_reg_write(p, REG_SW_2, val);
199 /* Raise the core frequency to 800MHz */
200 writel(0x0, &mxc_ccm->cacrr);
202 /* Set switchers in Auto in NORMAL mode & STANDBY mode */
203 /* Setup the switcher mode for SW1 & SW2*/
204 pmic_reg_read(p, REG_SW_4, &val);
205 val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) |
206 (SWMODE_MASK << SWMODE2_SHIFT)));
207 val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) |
208 (SWMODE_AUTO_AUTO << SWMODE2_SHIFT);
209 pmic_reg_write(p, REG_SW_4, val);
211 /* Setup the switcher mode for SW3 & SW4 */
212 pmic_reg_read(p, REG_SW_5, &val);
213 val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) |
214 (SWMODE_MASK << SWMODE4_SHIFT)));
215 val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) |
216 (SWMODE_AUTO_AUTO << SWMODE4_SHIFT);
217 pmic_reg_write(p, REG_SW_5, val);
219 /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */
220 pmic_reg_read(p, REG_SETTING_0, &val);
221 val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK);
222 val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6;
223 pmic_reg_write(p, REG_SETTING_0, val);
225 /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */
226 pmic_reg_read(p, REG_SETTING_1, &val);
227 val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK);
228 val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15;
229 pmic_reg_write(p, REG_SETTING_1, val);
231 /* Enable VGEN1, VGEN2, VDIG, VPLL */
232 pmic_reg_read(p, REG_MODE_0, &val);
233 val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN;
234 pmic_reg_write(p, REG_MODE_0, val);
236 /* Configure VGEN3 and VCAM regulators to use external PNP */
237 val = VGEN3CONFIG | VCAMCONFIG;
238 pmic_reg_write(p, REG_MODE_1, val);
241 /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */
242 val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG |
243 VVIDEOEN | VAUDIOEN | VSDEN;
244 pmic_reg_write(p, REG_MODE_1, val);
246 pmic_reg_read(p, REG_POWER_CTL2, &val);
248 pmic_reg_write(p, REG_POWER_CTL2, val);
253 static inline void power_init(void) { }
259 #ifdef CONFIG_FSL_ESDHC
261 struct fsl_esdhc_cfg esdhc_cfg[2] = {
262 {MMC_SDHC1_BASE_ADDR},
263 {MMC_SDHC2_BASE_ADDR},
266 static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = {
267 MX51_PAD_SD1_CMD__SD1_CMD,
268 MX51_PAD_SD1_CLK__SD1_CLK,
269 MX51_PAD_SD1_DATA0__SD1_DATA0,
270 MX51_PAD_SD1_DATA1__SD1_DATA1,
271 MX51_PAD_SD1_DATA2__SD1_DATA2,
272 MX51_PAD_SD1_DATA3__SD1_DATA3,
273 MX51_PAD_GPIO1_1__SD1_WP,
276 #define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1)
278 static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = {
279 MX51_PAD_GPIO1_0__SD1_CD,
280 NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, MX51_ESDHC_PAD_CTRL),
283 #define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0)
284 #define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27)
286 static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = {
287 MX51_PAD_SD2_CMD__SD2_CMD,
288 MX51_PAD_SD2_CLK__SD2_CLK,
289 MX51_PAD_SD2_DATA0__SD2_DATA0,
290 MX51_PAD_SD2_DATA1__SD2_DATA1,
291 MX51_PAD_SD2_DATA2__SD2_DATA2,
292 MX51_PAD_SD2_DATA3__SD2_DATA3,
293 MX51_PAD_GPIO1_7__SD2_WP,
294 MX51_PAD_GPIO1_8__SD2_CD,
297 #define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8)
298 #define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7)
300 static inline uint32_t efikamx_mmc_getcd(u32 base)
302 if (base == MMC_SDHC1_BASE_ADDR)
303 if (machine_is_efikamx())
304 return EFIKAMX_SDHC1_CD;
306 return EFIKASB_SDHC1_CD;
308 return EFIKASB_SDHC2_CD;
311 int board_mmc_getcd(struct mmc *mmc)
313 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
314 uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base);
315 int ret = !gpio_get_value(cd);
320 int board_mmc_init(bd_t *bis)
325 * All Efika MX boards use eSDHC1 with a common write-protect GPIO
327 imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads,
328 ARRAY_SIZE(efikamx_sdhc1_pads));
329 gpio_direction_input(EFIKAMX_SDHC1_WP);
332 * Smartbook and Smarttop differ on the location of eSDHC1
333 * carrier-detect GPIO
335 if (machine_is_efikamx()) {
336 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]);
337 gpio_direction_input(EFIKAMX_SDHC1_CD);
338 } else if (machine_is_efikasb()) {
339 imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]);
340 gpio_direction_input(EFIKASB_SDHC1_CD);
343 esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
344 esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
346 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]);
348 if (machine_is_efikasb()) {
350 imx_iomux_v3_setup_multiple_pads(efikasb_sdhc2_pads,
351 ARRAY_SIZE(efikasb_sdhc2_pads));
352 gpio_direction_input(EFIKASB_SDHC2_CD);
353 gpio_direction_input(EFIKASB_SDHC2_WP);
355 ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]);
365 static iomux_v3_cfg_t const efikamx_pata_pads[] = {
366 MX51_PAD_NANDF_WE_B__PATA_DIOW,
367 MX51_PAD_NANDF_RE_B__PATA_DIOR,
368 MX51_PAD_NANDF_ALE__PATA_BUFFER_EN,
369 MX51_PAD_NANDF_CLE__PATA_RESET_B,
370 MX51_PAD_NANDF_WP_B__PATA_DMACK,
371 MX51_PAD_NANDF_RB0__PATA_DMARQ,
372 MX51_PAD_NANDF_RB1__PATA_IORDY,
373 MX51_PAD_GPIO_NAND__PATA_INTRQ,
374 MX51_PAD_NANDF_CS2__PATA_CS_0,
375 MX51_PAD_NANDF_CS3__PATA_CS_1,
376 MX51_PAD_NANDF_CS4__PATA_DA_0,
377 MX51_PAD_NANDF_CS5__PATA_DA_1,
378 MX51_PAD_NANDF_CS6__PATA_DA_2,
379 MX51_PAD_NANDF_D15__PATA_DATA15,
380 MX51_PAD_NANDF_D14__PATA_DATA14,
381 MX51_PAD_NANDF_D13__PATA_DATA13,
382 MX51_PAD_NANDF_D12__PATA_DATA12,
383 MX51_PAD_NANDF_D11__PATA_DATA11,
384 MX51_PAD_NANDF_D10__PATA_DATA10,
385 MX51_PAD_NANDF_D9__PATA_DATA9,
386 MX51_PAD_NANDF_D8__PATA_DATA8,
387 MX51_PAD_NANDF_D7__PATA_DATA7,
388 MX51_PAD_NANDF_D6__PATA_DATA6,
389 MX51_PAD_NANDF_D5__PATA_DATA5,
390 MX51_PAD_NANDF_D4__PATA_DATA4,
391 MX51_PAD_NANDF_D3__PATA_DATA3,
392 MX51_PAD_NANDF_D2__PATA_DATA2,
393 MX51_PAD_NANDF_D1__PATA_DATA1,
394 MX51_PAD_NANDF_D0__PATA_DATA0,
400 #ifdef CONFIG_CMD_USB
401 extern void setup_iomux_usb(void);
403 static inline void setup_iomux_usb(void) { }
409 * Smarttop LED pad config is done in the DCD
412 #define EFIKAMX_LED_BLUE IMX_GPIO_NR(3, 13)
413 #define EFIKAMX_LED_GREEN IMX_GPIO_NR(3, 14)
414 #define EFIKAMX_LED_RED IMX_GPIO_NR(3, 15)
416 static iomux_v3_cfg_t const efikasb_led_pads[] = {
417 MX51_PAD_GPIO1_3__GPIO1_3,
418 MX51_PAD_EIM_CS0__GPIO2_25,
421 #define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25)
422 #define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */
425 * Board initialization
427 int board_early_init_f(void)
429 if (machine_is_efikasb()) {
430 imx_iomux_v3_setup_multiple_pads(efikasb_led_pads,
431 ARRAY_SIZE(efikasb_led_pads));
432 gpio_direction_output(EFIKASB_CAPSLOCK_LED, 0);
433 gpio_direction_output(EFIKASB_MESSAGE_LED, 1);
434 } else if (machine_is_efikamx()) {
436 * Set up GPIO directions for LEDs.
437 * IOMUX has been done in the DCD already.
438 * Turn the red LED on for pre-relocation code.
440 gpio_direction_output(EFIKAMX_LED_BLUE, 0);
441 gpio_direction_output(EFIKAMX_LED_GREEN, 0);
442 gpio_direction_output(EFIKAMX_LED_RED, 1);
446 * Both these pad configurations for UART and SPI are kind of redundant
447 * since they are the Power-On Defaults for the i.MX51. But, it seems we
448 * should make absolutely sure that they are set up correctly.
450 imx_iomux_v3_setup_multiple_pads(efikamx_uart_pads,
451 ARRAY_SIZE(efikamx_uart_pads));
452 imx_iomux_v3_setup_multiple_pads(efikamx_spi_pads,
453 ARRAY_SIZE(efikamx_spi_pads));
455 /* not technically required for U-Boot operation but do it anyway. */
456 gpio_direction_input(EFIKAMX_PMIC_IRQ);
457 /* Deselect both CS for now, otherwise NOR doesn't probe properly. */
458 gpio_direction_output(EFIKAMX_SPI_SS0, 0);
459 gpio_direction_output(EFIKAMX_SPI_SS1, 1);
466 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
471 int board_late_init(void)
473 if (machine_is_efikamx()) {
475 * Set up Blue LED for "In U-Boot" status.
476 * We're all relocated and ready to U-Boot!
478 gpio_set_value(EFIKAMX_LED_RED, 0);
479 gpio_set_value(EFIKAMX_LED_GREEN, 0);
480 gpio_set_value(EFIKAMX_LED_BLUE, 1);
485 imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads,
486 ARRAY_SIZE(efikamx_pata_pads));
494 u32 rev = get_efikamx_rev();
496 printf("Board: Genesi Efika MX ");
497 if (machine_is_efikamx())
498 printf("Smarttop (1.%i)\n", rev & 0xf);
499 else if (machine_is_efikasb())
500 printf("Smartbook\n");