Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 1 | /* |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 2 | * Copyright (C) 2009 Freescale Semiconductor, Inc. |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 3 | * Copyright (C) 2010 Marek Vasut <marek.vasut@gmail.com> |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009-2012 Genesi USA, Inc. |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 5 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 6 | * SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <asm/io.h> |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 11 | #include <asm/arch/iomux-mx51.h> |
Stefano Babic | a3b1edd | 2011-08-21 10:53:32 +0200 | [diff] [blame] | 12 | #include <asm/gpio.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 13 | #include <asm/errno.h> |
| 14 | #include <asm/arch/sys_proto.h> |
| 15 | #include <asm/arch/crm_regs.h> |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 16 | #include <asm/arch/clock.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 17 | #include <i2c.h> |
| 18 | #include <mmc.h> |
| 19 | #include <fsl_esdhc.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 20 | #include <power/pmic.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 21 | #include <fsl_pmic.h> |
| 22 | #include <mc13892.h> |
| 23 | |
| 24 | DECLARE_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 Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 34 | * 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 Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 39 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 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 |
| 44 | |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 45 | #define EFIKASB_BOARD_REV_13 0x1 |
| 46 | #define EFIKASB_BOARD_REV_20 0x2 |
| 47 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 48 | /* |
| 49 | * Board identification |
| 50 | */ |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 51 | static u32 get_mx_rev(void) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 52 | { |
| 53 | u32 rev = 0; |
| 54 | /* |
| 55 | * Retrieve board ID: |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 56 | * |
| 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 Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 66 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 67 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 68 | /* set to 1 in order to get correct value on board rev 1.1 */ |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 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)); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 73 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 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; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 77 | |
| 78 | return (~rev & 0x7) + 1; |
| 79 | } |
| 80 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 81 | static iomux_v3_cfg_t const efikasb_revision_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 82 | MX51_PAD_EIM_CS3__GPIO2_28, |
| 83 | MX51_PAD_EIM_CS4__GPIO2_29, |
| 84 | }; |
| 85 | |
| 86 | static inline u32 get_sb_rev(void) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 87 | { |
| 88 | u32 rev = 0; |
| 89 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 90 | imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads, |
| 91 | ARRAY_SIZE(efikasb_revision_pads)); |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 92 | gpio_direction_input(IMX_GPIO_NR(2, 28)); |
| 93 | gpio_direction_input(IMX_GPIO_NR(2, 29)); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 94 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 95 | rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0; |
| 96 | rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 97 | |
| 98 | return rev; |
| 99 | } |
| 100 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 101 | inline uint32_t get_efikamx_rev(void) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 102 | { |
| 103 | if (machine_is_efikamx()) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 104 | return get_mx_rev(); |
| 105 | else if (machine_is_efikasb()) |
| 106 | return get_sb_rev(); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 109 | u32 get_board_rev(void) |
| 110 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 111 | return get_cpu_rev() | (get_efikamx_rev() << 8); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 112 | } |
| 113 | |
| 114 | /* |
| 115 | * DRAM initialization |
| 116 | */ |
| 117 | int dram_init(void) |
| 118 | { |
| 119 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 120 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 121 | PHYS_SDRAM_1_SIZE); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
| 125 | /* |
| 126 | * UART configuration |
| 127 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 128 | static iomux_v3_cfg_t const efikamx_uart_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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, |
| 133 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * SPI configuration |
| 137 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 138 | static iomux_v3_cfg_t const efikamx_spi_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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, |
| 145 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 146 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 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) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * PMIC configuration |
| 153 | */ |
| 154 | #ifdef CONFIG_MXC_SPI |
| 155 | static void power_init(void) |
| 156 | { |
| 157 | unsigned int val; |
| 158 | struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)MXC_CCM_BASE; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 159 | struct pmic *p; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 160 | int ret; |
| 161 | |
Fabio Estevam | 6d24073 | 2013-11-20 20:26:05 -0200 | [diff] [blame] | 162 | ret = pmic_init(CONFIG_FSL_PMIC_BUS); |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 163 | if (ret) |
| 164 | return; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 165 | |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 166 | p = pmic_get("FSL_PMIC"); |
| 167 | if (!p) |
| 168 | return; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 169 | |
| 170 | /* Write needed to Power Gate 2 register */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 171 | pmic_reg_read(p, REG_POWER_MISC, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 172 | val &= ~PWGT2SPIEN; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 173 | pmic_reg_write(p, REG_POWER_MISC, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 174 | |
| 175 | /* Externally powered */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 176 | pmic_reg_read(p, REG_CHARGE, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 177 | val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 178 | pmic_reg_write(p, REG_CHARGE, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 179 | |
| 180 | /* power up the system first */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 181 | pmic_reg_write(p, REG_POWER_MISC, PWUP); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 182 | |
| 183 | /* Set core voltage to 1.1V */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 184 | pmic_reg_read(p, REG_SW_0, &val); |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 185 | val = (val & ~SWx_VOLT_MASK) | SWx_1_100V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 186 | pmic_reg_write(p, REG_SW_0, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 187 | |
| 188 | /* Setup VCC (SW2) to 1.25 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 189 | pmic_reg_read(p, REG_SW_1, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 190 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 191 | pmic_reg_write(p, REG_SW_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 192 | |
| 193 | /* Setup 1V2_DIG1 (SW3) to 1.25 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 194 | pmic_reg_read(p, REG_SW_2, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 195 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 196 | pmic_reg_write(p, REG_SW_2, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 197 | udelay(50); |
| 198 | |
| 199 | /* Raise the core frequency to 800MHz */ |
| 200 | writel(0x0, &mxc_ccm->cacrr); |
| 201 | |
| 202 | /* Set switchers in Auto in NORMAL mode & STANDBY mode */ |
| 203 | /* Setup the switcher mode for SW1 & SW2*/ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 204 | pmic_reg_read(p, REG_SW_4, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 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); |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 209 | pmic_reg_write(p, REG_SW_4, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 210 | |
| 211 | /* Setup the switcher mode for SW3 & SW4 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 212 | pmic_reg_read(p, REG_SW_5, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 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); |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 217 | pmic_reg_write(p, REG_SW_5, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 218 | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 219 | /* Set VDIG to 1.8V, VGEN3 to 1.8V, VCAM to 2.6V */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 220 | pmic_reg_read(p, REG_SETTING_0, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 221 | val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK); |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 222 | val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 223 | pmic_reg_write(p, REG_SETTING_0, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 224 | |
| 225 | /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 226 | pmic_reg_read(p, REG_SETTING_1, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 227 | val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK); |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 228 | val |= VSD_3_15 | VAUDIO_3_0 | VVIDEO_2_775 | VGEN1_1_2 | VGEN2_3_15; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 229 | pmic_reg_write(p, REG_SETTING_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 230 | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 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); |
| 235 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 236 | /* Configure VGEN3 and VCAM regulators to use external PNP */ |
| 237 | val = VGEN3CONFIG | VCAMCONFIG; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 238 | pmic_reg_write(p, REG_MODE_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 239 | udelay(200); |
| 240 | |
| 241 | /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */ |
| 242 | val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 243 | VVIDEOEN | VAUDIOEN | VSDEN; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 244 | pmic_reg_write(p, REG_MODE_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 245 | |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 246 | pmic_reg_read(p, REG_POWER_CTL2, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 247 | val |= WDIRESET; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 248 | pmic_reg_write(p, REG_POWER_CTL2, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 249 | |
| 250 | udelay(2500); |
| 251 | } |
| 252 | #else |
| 253 | static inline void power_init(void) { } |
| 254 | #endif |
| 255 | |
| 256 | /* |
| 257 | * MMC configuration |
| 258 | */ |
| 259 | #ifdef CONFIG_FSL_ESDHC |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 260 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 261 | struct fsl_esdhc_cfg esdhc_cfg[2] = { |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 262 | {MMC_SDHC1_BASE_ADDR}, |
| 263 | {MMC_SDHC2_BASE_ADDR}, |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 264 | }; |
| 265 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 266 | static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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, |
| 274 | }; |
| 275 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 276 | #define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 277 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 278 | static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 279 | MX51_PAD_GPIO1_0__SD1_CD, |
Benoît Thébaudeau | 9c8801b | 2013-05-03 10:32:25 +0000 | [diff] [blame] | 280 | NEW_PAD_CTRL(MX51_PAD_EIM_CS2__GPIO2_27, MX51_ESDHC_PAD_CTRL), |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 281 | }; |
| 282 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 283 | #define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0) |
| 284 | #define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 285 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 286 | static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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, |
| 295 | }; |
| 296 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 297 | #define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8) |
| 298 | #define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 299 | |
| 300 | static inline uint32_t efikamx_mmc_getcd(u32 base) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 301 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 302 | if (base == MMC_SDHC1_BASE_ADDR) |
| 303 | if (machine_is_efikamx()) |
| 304 | return EFIKAMX_SDHC1_CD; |
| 305 | else |
| 306 | return EFIKASB_SDHC1_CD; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 307 | else |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 308 | return EFIKASB_SDHC2_CD; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 309 | } |
| 310 | |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 311 | int board_mmc_getcd(struct mmc *mmc) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 312 | { |
| 313 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 314 | uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base); |
| 315 | int ret = !gpio_get_value(cd); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 316 | |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 317 | return ret; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 318 | } |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 319 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 320 | int board_mmc_init(bd_t *bis) |
| 321 | { |
| 322 | int ret; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 323 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 324 | /* |
| 325 | * All Efika MX boards use eSDHC1 with a common write-protect GPIO |
| 326 | */ |
| 327 | imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads, |
| 328 | ARRAY_SIZE(efikamx_sdhc1_pads)); |
| 329 | gpio_direction_input(EFIKAMX_SDHC1_WP); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 330 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 331 | /* |
| 332 | * Smartbook and Smarttop differ on the location of eSDHC1 |
| 333 | * carrier-detect GPIO |
| 334 | */ |
| 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); |
| 341 | } |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 342 | |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 343 | esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 344 | esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 345 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 346 | ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 347 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 348 | if (machine_is_efikasb()) { |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 349 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 354 | if (!ret) |
| 355 | ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 356 | } |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 357 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 358 | return ret; |
| 359 | } |
| 360 | #endif |
| 361 | |
| 362 | /* |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 363 | * PATA |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 364 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 365 | static iomux_v3_cfg_t const efikamx_pata_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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, |
| 395 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 396 | |
| 397 | /* |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 398 | * EHCI USB |
| 399 | */ |
| 400 | #ifdef CONFIG_CMD_USB |
| 401 | extern void setup_iomux_usb(void); |
| 402 | #else |
| 403 | static inline void setup_iomux_usb(void) { } |
| 404 | #endif |
| 405 | |
| 406 | /* |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 407 | * LED configuration |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 408 | * |
| 409 | * Smarttop LED pad config is done in the DCD |
| 410 | * |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 411 | */ |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 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) |
Stefano Babic | a3b1edd | 2011-08-21 10:53:32 +0200 | [diff] [blame] | 415 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 416 | static iomux_v3_cfg_t const efikasb_led_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 417 | MX51_PAD_GPIO1_3__GPIO1_3, |
| 418 | MX51_PAD_EIM_CS0__GPIO2_25, |
| 419 | }; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 420 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 421 | #define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25) |
| 422 | #define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 423 | |
| 424 | /* |
| 425 | * Board initialization |
| 426 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 427 | int board_early_init_f(void) |
| 428 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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()) { |
| 435 | /* |
| 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. |
| 439 | */ |
| 440 | gpio_direction_output(EFIKAMX_LED_BLUE, 0); |
| 441 | gpio_direction_output(EFIKAMX_LED_GREEN, 0); |
| 442 | gpio_direction_output(EFIKAMX_LED_RED, 1); |
| 443 | } |
| 444 | |
| 445 | /* |
| 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. |
| 449 | */ |
| 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)); |
| 454 | |
| 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); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 460 | |
| 461 | return 0; |
| 462 | } |
| 463 | |
| 464 | int board_init(void) |
| 465 | { |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 466 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 467 | |
| 468 | return 0; |
| 469 | } |
| 470 | |
| 471 | int board_late_init(void) |
| 472 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 473 | if (machine_is_efikamx()) { |
| 474 | /* |
| 475 | * Set up Blue LED for "In U-Boot" status. |
| 476 | * We're all relocated and ready to U-Boot! |
| 477 | */ |
| 478 | gpio_set_value(EFIKAMX_LED_RED, 0); |
| 479 | gpio_set_value(EFIKAMX_LED_GREEN, 0); |
| 480 | gpio_set_value(EFIKAMX_LED_BLUE, 1); |
| 481 | } |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 482 | |
| 483 | power_init(); |
| 484 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 485 | imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads, |
| 486 | ARRAY_SIZE(efikamx_pata_pads)); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 487 | setup_iomux_usb(); |
| 488 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | int checkboard(void) |
| 493 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 494 | u32 rev = get_efikamx_rev(); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 495 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 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"); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 501 | |
| 502 | return 0; |
| 503 | } |