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 | * |
| 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 Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 27 | #include <asm/arch/iomux-mx51.h> |
Stefano Babic | a3b1edd | 2011-08-21 10:53:32 +0200 | [diff] [blame] | 28 | #include <asm/gpio.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 29 | #include <asm/errno.h> |
| 30 | #include <asm/arch/sys_proto.h> |
| 31 | #include <asm/arch/crm_regs.h> |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 32 | #include <asm/arch/clock.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 33 | #include <i2c.h> |
| 34 | #include <mmc.h> |
| 35 | #include <fsl_esdhc.h> |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 36 | #include <power/pmic.h> |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 37 | #include <fsl_pmic.h> |
| 38 | #include <mc13892.h> |
| 39 | |
| 40 | DECLARE_GLOBAL_DATA_PTR; |
| 41 | |
| 42 | /* |
| 43 | * Compile-time error checking |
| 44 | */ |
| 45 | #ifndef CONFIG_MXC_SPI |
| 46 | #error "CONFIG_MXC_SPI not set, this is essential for board's operation!" |
| 47 | #endif |
| 48 | |
| 49 | /* |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 50 | * Board revisions |
| 51 | * |
| 52 | * Note that we get these revisions here for convenience, but we only set |
| 53 | * up for the production model Smarttop (1.3) and Smartbook (2.0). |
| 54 | * |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 55 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 56 | #define EFIKAMX_BOARD_REV_11 0x1 |
| 57 | #define EFIKAMX_BOARD_REV_12 0x2 |
| 58 | #define EFIKAMX_BOARD_REV_13 0x3 |
| 59 | #define EFIKAMX_BOARD_REV_14 0x4 |
| 60 | |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 61 | #define EFIKASB_BOARD_REV_13 0x1 |
| 62 | #define EFIKASB_BOARD_REV_20 0x2 |
| 63 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 64 | /* |
| 65 | * Board identification |
| 66 | */ |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 67 | static u32 get_mx_rev(void) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 68 | { |
| 69 | u32 rev = 0; |
| 70 | /* |
| 71 | * Retrieve board ID: |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 72 | * |
| 73 | * gpio: 16 17 11 |
| 74 | * ============== |
| 75 | * r1.1: 1+ 1 1 |
| 76 | * r1.2: 1 1 0 |
| 77 | * r1.3: 1 0 1 |
| 78 | * r1.4: 1 0 0 |
| 79 | * |
| 80 | * + note: r1.1 does not strap this pin properly so it needs to |
| 81 | * be hacked or ignored. |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 82 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 83 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 84 | /* 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] | 85 | gpio_direction_output(IMX_GPIO_NR(3, 16), 1); |
| 86 | gpio_direction_input(IMX_GPIO_NR(3, 11)); |
| 87 | gpio_direction_input(IMX_GPIO_NR(3, 16)); |
| 88 | gpio_direction_input(IMX_GPIO_NR(3, 17)); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 89 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 90 | rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 16))) << 0; |
| 91 | rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 17))) << 1; |
| 92 | rev |= (!!gpio_get_value(IMX_GPIO_NR(3, 11))) << 2; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 93 | |
| 94 | return (~rev & 0x7) + 1; |
| 95 | } |
| 96 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 97 | static iomux_v3_cfg_t const efikasb_revision_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 98 | MX51_PAD_EIM_CS3__GPIO2_28, |
| 99 | MX51_PAD_EIM_CS4__GPIO2_29, |
| 100 | }; |
| 101 | |
| 102 | static inline u32 get_sb_rev(void) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 103 | { |
| 104 | u32 rev = 0; |
| 105 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 106 | imx_iomux_v3_setup_multiple_pads(efikasb_revision_pads, |
| 107 | ARRAY_SIZE(efikasb_revision_pads)); |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 108 | gpio_direction_input(IMX_GPIO_NR(2, 28)); |
| 109 | gpio_direction_input(IMX_GPIO_NR(2, 29)); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 110 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 111 | rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 28))) << 0; |
| 112 | rev |= (!!gpio_get_value(IMX_GPIO_NR(2, 29))) << 1; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 113 | |
| 114 | return rev; |
| 115 | } |
| 116 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 117 | inline uint32_t get_efikamx_rev(void) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 118 | { |
| 119 | if (machine_is_efikamx()) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 120 | return get_mx_rev(); |
| 121 | else if (machine_is_efikasb()) |
| 122 | return get_sb_rev(); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 125 | u32 get_board_rev(void) |
| 126 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 127 | return get_cpu_rev() | (get_efikamx_rev() << 8); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * DRAM initialization |
| 132 | */ |
| 133 | int dram_init(void) |
| 134 | { |
| 135 | /* dram_init must store complete ramsize in gd->ram_size */ |
Albert ARIBAUD | a960673 | 2011-07-03 05:55:33 +0000 | [diff] [blame] | 136 | gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE, |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 137 | PHYS_SDRAM_1_SIZE); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
| 141 | /* |
| 142 | * UART configuration |
| 143 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 144 | static iomux_v3_cfg_t const efikamx_uart_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 145 | MX51_PAD_UART1_RXD__UART1_RXD, |
| 146 | MX51_PAD_UART1_TXD__UART1_TXD, |
| 147 | MX51_PAD_UART1_RTS__UART1_RTS, |
| 148 | MX51_PAD_UART1_CTS__UART1_CTS, |
| 149 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 150 | |
| 151 | /* |
| 152 | * SPI configuration |
| 153 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 154 | static iomux_v3_cfg_t const efikamx_spi_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 155 | MX51_PAD_CSPI1_MOSI__ECSPI1_MOSI, |
| 156 | MX51_PAD_CSPI1_MISO__ECSPI1_MISO, |
| 157 | MX51_PAD_CSPI1_SCLK__ECSPI1_SCLK, |
| 158 | MX51_PAD_CSPI1_SS0__GPIO4_24, |
| 159 | MX51_PAD_CSPI1_SS1__GPIO4_25, |
| 160 | MX51_PAD_GPIO1_6__GPIO1_6, |
| 161 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 162 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 163 | #define EFIKAMX_SPI_SS0 IMX_GPIO_NR(4, 24) |
| 164 | #define EFIKAMX_SPI_SS1 IMX_GPIO_NR(4, 25) |
| 165 | #define EFIKAMX_PMIC_IRQ IMX_GPIO_NR(1, 6) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 166 | |
| 167 | /* |
| 168 | * PMIC configuration |
| 169 | */ |
| 170 | #ifdef CONFIG_MXC_SPI |
| 171 | static void power_init(void) |
| 172 | { |
| 173 | unsigned int val; |
| 174 | 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] | 175 | struct pmic *p; |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 176 | int ret; |
| 177 | |
| 178 | ret = pmic_init(I2C_PMIC); |
| 179 | if (ret) |
| 180 | return; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 181 | |
Łukasz Majewski | 1c6dba1 | 2012-11-13 03:21:55 +0000 | [diff] [blame] | 182 | p = pmic_get("FSL_PMIC"); |
| 183 | if (!p) |
| 184 | return; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 185 | |
| 186 | /* Write needed to Power Gate 2 register */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 187 | pmic_reg_read(p, REG_POWER_MISC, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 188 | val &= ~PWGT2SPIEN; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 189 | pmic_reg_write(p, REG_POWER_MISC, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 190 | |
| 191 | /* Externally powered */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 192 | pmic_reg_read(p, REG_CHARGE, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 193 | val |= ICHRG0 | ICHRG1 | ICHRG2 | ICHRG3 | CHGAUTOB; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 194 | pmic_reg_write(p, REG_CHARGE, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 195 | |
| 196 | /* power up the system first */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 197 | pmic_reg_write(p, REG_POWER_MISC, PWUP); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 198 | |
| 199 | /* Set core voltage to 1.1V */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 200 | pmic_reg_read(p, REG_SW_0, &val); |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 201 | val = (val & ~SWx_VOLT_MASK) | SWx_1_100V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 202 | pmic_reg_write(p, REG_SW_0, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 203 | |
| 204 | /* Setup VCC (SW2) to 1.25 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 205 | pmic_reg_read(p, REG_SW_1, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 206 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 207 | pmic_reg_write(p, REG_SW_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 208 | |
| 209 | /* Setup 1V2_DIG1 (SW3) to 1.25 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 210 | pmic_reg_read(p, REG_SW_2, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 211 | val = (val & ~SWx_VOLT_MASK) | SWx_1_250V; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 212 | pmic_reg_write(p, REG_SW_2, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 213 | udelay(50); |
| 214 | |
| 215 | /* Raise the core frequency to 800MHz */ |
| 216 | writel(0x0, &mxc_ccm->cacrr); |
| 217 | |
| 218 | /* Set switchers in Auto in NORMAL mode & STANDBY mode */ |
| 219 | /* Setup the switcher mode for SW1 & SW2*/ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 220 | pmic_reg_read(p, REG_SW_4, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 221 | val = (val & ~((SWMODE_MASK << SWMODE1_SHIFT) | |
| 222 | (SWMODE_MASK << SWMODE2_SHIFT))); |
| 223 | val |= (SWMODE_AUTO_AUTO << SWMODE1_SHIFT) | |
| 224 | (SWMODE_AUTO_AUTO << SWMODE2_SHIFT); |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 225 | pmic_reg_write(p, REG_SW_4, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 226 | |
| 227 | /* Setup the switcher mode for SW3 & SW4 */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 228 | pmic_reg_read(p, REG_SW_5, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 229 | val = (val & ~((SWMODE_MASK << SWMODE3_SHIFT) | |
| 230 | (SWMODE_MASK << SWMODE4_SHIFT))); |
| 231 | val |= (SWMODE_AUTO_AUTO << SWMODE3_SHIFT) | |
| 232 | (SWMODE_AUTO_AUTO << SWMODE4_SHIFT); |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 233 | pmic_reg_write(p, REG_SW_5, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 234 | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 235 | /* 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] | 236 | pmic_reg_read(p, REG_SETTING_0, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 237 | val &= ~(VCAM_MASK | VGEN3_MASK | VDIG_MASK); |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 238 | val |= VDIG_1_8 | VGEN3_1_8 | VCAM_2_6; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 239 | pmic_reg_write(p, REG_SETTING_0, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 240 | |
| 241 | /* Set VVIDEO to 2.775V, VAUDIO to 3V, VSD to 3.15V */ |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 242 | pmic_reg_read(p, REG_SETTING_1, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 243 | val &= ~(VVIDEO_MASK | VSD_MASK | VAUDIO_MASK); |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 244 | 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] | 245 | pmic_reg_write(p, REG_SETTING_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 246 | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 247 | /* Enable VGEN1, VGEN2, VDIG, VPLL */ |
| 248 | pmic_reg_read(p, REG_MODE_0, &val); |
| 249 | val |= VGEN1EN | VDIGEN | VGEN2EN | VPLLEN; |
| 250 | pmic_reg_write(p, REG_MODE_0, val); |
| 251 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 252 | /* Configure VGEN3 and VCAM regulators to use external PNP */ |
| 253 | val = VGEN3CONFIG | VCAMCONFIG; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 254 | pmic_reg_write(p, REG_MODE_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 255 | udelay(200); |
| 256 | |
| 257 | /* Enable VGEN3, VCAM, VAUDIO, VVIDEO, VSD regulators */ |
| 258 | val = VGEN3EN | VGEN3CONFIG | VCAMEN | VCAMCONFIG | |
Marek Vasut | 9f1cbd3 | 2011-09-28 02:19:57 +0000 | [diff] [blame] | 259 | VVIDEOEN | VAUDIOEN | VSDEN; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 260 | pmic_reg_write(p, REG_MODE_1, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 261 | |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 262 | pmic_reg_read(p, REG_POWER_CTL2, &val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 263 | val |= WDIRESET; |
Stefano Babic | 11bbd71 | 2011-10-06 11:44:26 +0200 | [diff] [blame] | 264 | pmic_reg_write(p, REG_POWER_CTL2, val); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 265 | |
| 266 | udelay(2500); |
| 267 | } |
| 268 | #else |
| 269 | static inline void power_init(void) { } |
| 270 | #endif |
| 271 | |
| 272 | /* |
| 273 | * MMC configuration |
| 274 | */ |
| 275 | #ifdef CONFIG_FSL_ESDHC |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 276 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 277 | struct fsl_esdhc_cfg esdhc_cfg[2] = { |
Benoît Thébaudeau | c08d11c | 2012-08-13 07:28:16 +0000 | [diff] [blame] | 278 | {MMC_SDHC1_BASE_ADDR}, |
| 279 | {MMC_SDHC2_BASE_ADDR}, |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 280 | }; |
| 281 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 282 | static iomux_v3_cfg_t const efikamx_sdhc1_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 283 | MX51_PAD_SD1_CMD__SD1_CMD, |
| 284 | MX51_PAD_SD1_CLK__SD1_CLK, |
| 285 | MX51_PAD_SD1_DATA0__SD1_DATA0, |
| 286 | MX51_PAD_SD1_DATA1__SD1_DATA1, |
| 287 | MX51_PAD_SD1_DATA2__SD1_DATA2, |
| 288 | MX51_PAD_SD1_DATA3__SD1_DATA3, |
| 289 | MX51_PAD_GPIO1_1__SD1_WP, |
| 290 | }; |
| 291 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 292 | #define EFIKAMX_SDHC1_WP IMX_GPIO_NR(1, 1) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 293 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 294 | static iomux_v3_cfg_t const efikamx_sdhc1_cd_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 295 | MX51_PAD_GPIO1_0__SD1_CD, |
| 296 | MX51_PAD_EIM_CS2__SD1_CD, |
| 297 | }; |
| 298 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 299 | #define EFIKAMX_SDHC1_CD IMX_GPIO_NR(1, 0) |
| 300 | #define EFIKASB_SDHC1_CD IMX_GPIO_NR(2, 27) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 301 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 302 | static iomux_v3_cfg_t const efikasb_sdhc2_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 303 | MX51_PAD_SD2_CMD__SD2_CMD, |
| 304 | MX51_PAD_SD2_CLK__SD2_CLK, |
| 305 | MX51_PAD_SD2_DATA0__SD2_DATA0, |
| 306 | MX51_PAD_SD2_DATA1__SD2_DATA1, |
| 307 | MX51_PAD_SD2_DATA2__SD2_DATA2, |
| 308 | MX51_PAD_SD2_DATA3__SD2_DATA3, |
| 309 | MX51_PAD_GPIO1_7__SD2_WP, |
| 310 | MX51_PAD_GPIO1_8__SD2_CD, |
| 311 | }; |
| 312 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 313 | #define EFIKASB_SDHC2_CD IMX_GPIO_NR(1, 8) |
| 314 | #define EFIKASB_SDHC2_WP IMX_GPIO_NR(1, 7) |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 315 | |
| 316 | static inline uint32_t efikamx_mmc_getcd(u32 base) |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 317 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 318 | if (base == MMC_SDHC1_BASE_ADDR) |
| 319 | if (machine_is_efikamx()) |
| 320 | return EFIKAMX_SDHC1_CD; |
| 321 | else |
| 322 | return EFIKASB_SDHC1_CD; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 323 | else |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 324 | return EFIKASB_SDHC2_CD; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 325 | } |
| 326 | |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 327 | int board_mmc_getcd(struct mmc *mmc) |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 328 | { |
| 329 | struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv; |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 330 | uint32_t cd = efikamx_mmc_getcd(cfg->esdhc_base); |
| 331 | int ret = !gpio_get_value(cd); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 332 | |
Thierry Reding | d7aebf4 | 2012-01-02 01:15:36 +0000 | [diff] [blame] | 333 | return ret; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 334 | } |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 335 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 336 | int board_mmc_init(bd_t *bis) |
| 337 | { |
| 338 | int ret; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 339 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 340 | /* |
| 341 | * All Efika MX boards use eSDHC1 with a common write-protect GPIO |
| 342 | */ |
| 343 | imx_iomux_v3_setup_multiple_pads(efikamx_sdhc1_pads, |
| 344 | ARRAY_SIZE(efikamx_sdhc1_pads)); |
| 345 | gpio_direction_input(EFIKAMX_SDHC1_WP); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 346 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 347 | /* |
| 348 | * Smartbook and Smarttop differ on the location of eSDHC1 |
| 349 | * carrier-detect GPIO |
| 350 | */ |
| 351 | if (machine_is_efikamx()) { |
| 352 | imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[0]); |
| 353 | gpio_direction_input(EFIKAMX_SDHC1_CD); |
| 354 | } else if (machine_is_efikasb()) { |
| 355 | imx_iomux_v3_setup_pad(efikamx_sdhc1_cd_pads[1]); |
| 356 | gpio_direction_input(EFIKASB_SDHC1_CD); |
| 357 | } |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 358 | |
Benoît Thébaudeau | c58ff34 | 2012-10-01 08:36:25 +0000 | [diff] [blame] | 359 | esdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK); |
| 360 | esdhc_cfg[1].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK); |
| 361 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 362 | ret = fsl_esdhc_initialize(bis, &esdhc_cfg[0]); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 363 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 364 | if (machine_is_efikasb()) { |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 365 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 366 | imx_iomux_v3_setup_multiple_pads(efikasb_sdhc2_pads, |
| 367 | ARRAY_SIZE(efikasb_sdhc2_pads)); |
| 368 | gpio_direction_input(EFIKASB_SDHC2_CD); |
| 369 | gpio_direction_input(EFIKASB_SDHC2_WP); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 370 | if (!ret) |
| 371 | ret = fsl_esdhc_initialize(bis, &esdhc_cfg[1]); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 372 | } |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 373 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 374 | return ret; |
| 375 | } |
| 376 | #endif |
| 377 | |
| 378 | /* |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 379 | * PATA |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 380 | */ |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 381 | static iomux_v3_cfg_t const efikamx_pata_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 382 | MX51_PAD_NANDF_WE_B__PATA_DIOW, |
| 383 | MX51_PAD_NANDF_RE_B__PATA_DIOR, |
| 384 | MX51_PAD_NANDF_ALE__PATA_BUFFER_EN, |
| 385 | MX51_PAD_NANDF_CLE__PATA_RESET_B, |
| 386 | MX51_PAD_NANDF_WP_B__PATA_DMACK, |
| 387 | MX51_PAD_NANDF_RB0__PATA_DMARQ, |
| 388 | MX51_PAD_NANDF_RB1__PATA_IORDY, |
| 389 | MX51_PAD_GPIO_NAND__PATA_INTRQ, |
| 390 | MX51_PAD_NANDF_CS2__PATA_CS_0, |
| 391 | MX51_PAD_NANDF_CS3__PATA_CS_1, |
| 392 | MX51_PAD_NANDF_CS4__PATA_DA_0, |
| 393 | MX51_PAD_NANDF_CS5__PATA_DA_1, |
| 394 | MX51_PAD_NANDF_CS6__PATA_DA_2, |
| 395 | MX51_PAD_NANDF_D15__PATA_DATA15, |
| 396 | MX51_PAD_NANDF_D14__PATA_DATA14, |
| 397 | MX51_PAD_NANDF_D13__PATA_DATA13, |
| 398 | MX51_PAD_NANDF_D12__PATA_DATA12, |
| 399 | MX51_PAD_NANDF_D11__PATA_DATA11, |
| 400 | MX51_PAD_NANDF_D10__PATA_DATA10, |
| 401 | MX51_PAD_NANDF_D9__PATA_DATA9, |
| 402 | MX51_PAD_NANDF_D8__PATA_DATA8, |
| 403 | MX51_PAD_NANDF_D7__PATA_DATA7, |
| 404 | MX51_PAD_NANDF_D6__PATA_DATA6, |
| 405 | MX51_PAD_NANDF_D5__PATA_DATA5, |
| 406 | MX51_PAD_NANDF_D4__PATA_DATA4, |
| 407 | MX51_PAD_NANDF_D3__PATA_DATA3, |
| 408 | MX51_PAD_NANDF_D2__PATA_DATA2, |
| 409 | MX51_PAD_NANDF_D1__PATA_DATA1, |
| 410 | MX51_PAD_NANDF_D0__PATA_DATA0, |
| 411 | }; |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 412 | |
| 413 | /* |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 414 | * EHCI USB |
| 415 | */ |
| 416 | #ifdef CONFIG_CMD_USB |
| 417 | extern void setup_iomux_usb(void); |
| 418 | #else |
| 419 | static inline void setup_iomux_usb(void) { } |
| 420 | #endif |
| 421 | |
| 422 | /* |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 423 | * LED configuration |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 424 | * |
| 425 | * Smarttop LED pad config is done in the DCD |
| 426 | * |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 427 | */ |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 428 | #define EFIKAMX_LED_BLUE IMX_GPIO_NR(3, 13) |
| 429 | #define EFIKAMX_LED_GREEN IMX_GPIO_NR(3, 14) |
| 430 | #define EFIKAMX_LED_RED IMX_GPIO_NR(3, 15) |
Stefano Babic | a3b1edd | 2011-08-21 10:53:32 +0200 | [diff] [blame] | 431 | |
Eric Nelson | 1680209 | 2012-10-03 07:26:38 +0000 | [diff] [blame] | 432 | static iomux_v3_cfg_t const efikasb_led_pads[] = { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 433 | MX51_PAD_GPIO1_3__GPIO1_3, |
| 434 | MX51_PAD_EIM_CS0__GPIO2_25, |
| 435 | }; |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 436 | |
Stefano Babic | 68fc638 | 2012-08-28 03:10:51 +0000 | [diff] [blame] | 437 | #define EFIKASB_CAPSLOCK_LED IMX_GPIO_NR(2, 25) |
| 438 | #define EFIKASB_MESSAGE_LED IMX_GPIO_NR(1, 3) /* Note: active low */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 439 | |
| 440 | /* |
| 441 | * Board initialization |
| 442 | */ |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 443 | int board_early_init_f(void) |
| 444 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 445 | if (machine_is_efikasb()) { |
| 446 | imx_iomux_v3_setup_multiple_pads(efikasb_led_pads, |
| 447 | ARRAY_SIZE(efikasb_led_pads)); |
| 448 | gpio_direction_output(EFIKASB_CAPSLOCK_LED, 0); |
| 449 | gpio_direction_output(EFIKASB_MESSAGE_LED, 1); |
| 450 | } else if (machine_is_efikamx()) { |
| 451 | /* |
| 452 | * Set up GPIO directions for LEDs. |
| 453 | * IOMUX has been done in the DCD already. |
| 454 | * Turn the red LED on for pre-relocation code. |
| 455 | */ |
| 456 | gpio_direction_output(EFIKAMX_LED_BLUE, 0); |
| 457 | gpio_direction_output(EFIKAMX_LED_GREEN, 0); |
| 458 | gpio_direction_output(EFIKAMX_LED_RED, 1); |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Both these pad configurations for UART and SPI are kind of redundant |
| 463 | * since they are the Power-On Defaults for the i.MX51. But, it seems we |
| 464 | * should make absolutely sure that they are set up correctly. |
| 465 | */ |
| 466 | imx_iomux_v3_setup_multiple_pads(efikamx_uart_pads, |
| 467 | ARRAY_SIZE(efikamx_uart_pads)); |
| 468 | imx_iomux_v3_setup_multiple_pads(efikamx_spi_pads, |
| 469 | ARRAY_SIZE(efikamx_spi_pads)); |
| 470 | |
| 471 | /* not technically required for U-Boot operation but do it anyway. */ |
| 472 | gpio_direction_input(EFIKAMX_PMIC_IRQ); |
| 473 | /* Deselect both CS for now, otherwise NOR doesn't probe properly. */ |
| 474 | gpio_direction_output(EFIKAMX_SPI_SS0, 0); |
| 475 | gpio_direction_output(EFIKAMX_SPI_SS1, 1); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 476 | |
| 477 | return 0; |
| 478 | } |
| 479 | |
| 480 | int board_init(void) |
| 481 | { |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 482 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 483 | |
| 484 | return 0; |
| 485 | } |
| 486 | |
| 487 | int board_late_init(void) |
| 488 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 489 | if (machine_is_efikamx()) { |
| 490 | /* |
| 491 | * Set up Blue LED for "In U-Boot" status. |
| 492 | * We're all relocated and ready to U-Boot! |
| 493 | */ |
| 494 | gpio_set_value(EFIKAMX_LED_RED, 0); |
| 495 | gpio_set_value(EFIKAMX_LED_GREEN, 0); |
| 496 | gpio_set_value(EFIKAMX_LED_BLUE, 1); |
| 497 | } |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 498 | |
| 499 | power_init(); |
| 500 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 501 | imx_iomux_v3_setup_multiple_pads(efikamx_pata_pads, |
| 502 | ARRAY_SIZE(efikamx_pata_pads)); |
Marek Vasut | f2ebfeb | 2011-06-24 21:46:07 +0200 | [diff] [blame] | 503 | setup_iomux_usb(); |
| 504 | |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 505 | return 0; |
| 506 | } |
| 507 | |
| 508 | int checkboard(void) |
| 509 | { |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 510 | u32 rev = get_efikamx_rev(); |
Marek Vasut | 3cc35cc | 2011-09-25 09:55:43 +0000 | [diff] [blame] | 511 | |
Matt Sealey | ed95f61 | 2012-08-27 05:58:30 +0000 | [diff] [blame] | 512 | printf("Board: Genesi Efika MX "); |
| 513 | if (machine_is_efikamx()) |
| 514 | printf("Smarttop (1.%i)\n", rev & 0xf); |
| 515 | else if (machine_is_efikasb()) |
| 516 | printf("Smartbook\n"); |
Marek Vasut | 92c3483 | 2011-01-19 04:40:37 +0000 | [diff] [blame] | 517 | |
| 518 | return 0; |
| 519 | } |