Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de> |
| 3 | * |
| 4 | * (C) Copyright 2008-2010 Freescale Semiconductor, Inc. |
| 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> |
| 27 | #include <asm/errno.h> |
| 28 | #include <asm/arch/imx-regs.h> |
| 29 | #include <asm/arch/crm_regs.h> |
| 30 | #include <asm/arch/mx35_pins.h> |
| 31 | #include <asm/arch/iomux.h> |
| 32 | #include <i2c.h> |
| 33 | #include <fsl_pmic.h> |
| 34 | #include <mc9sdz60.h> |
| 35 | #include <mc13892.h> |
| 36 | #include <linux/types.h> |
Stefano Babic | 560c1bc | 2011-08-21 11:00:32 +0200 | [diff] [blame] | 37 | #include <asm/gpio.h> |
Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 38 | #include <asm/arch/sys_proto.h> |
| 39 | #include <netdev.h> |
| 40 | |
| 41 | #ifndef BOARD_LATE_INIT |
| 42 | #error "BOARD_LATE_INIT must be set for this board" |
| 43 | #endif |
| 44 | |
| 45 | #ifndef CONFIG_BOARD_EARLY_INIT_F |
| 46 | #error "CONFIG_BOARD_EARLY_INIT_F must be set for this board" |
| 47 | #endif |
| 48 | |
Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 49 | DECLARE_GLOBAL_DATA_PTR; |
| 50 | |
| 51 | int dram_init(void) |
| 52 | { |
Stefano Babic | 19edc94 | 2011-08-02 14:42:36 +0200 | [diff] [blame] | 53 | u32 size1, size2; |
| 54 | |
| 55 | size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE); |
| 56 | size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE); |
| 57 | |
| 58 | gd->ram_size = size1 + size2; |
Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
Stefano Babic | 19edc94 | 2011-08-02 14:42:36 +0200 | [diff] [blame] | 63 | void dram_init_banksize(void) |
| 64 | { |
| 65 | gd->bd->bi_dram[0].start = PHYS_SDRAM_1; |
| 66 | gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE; |
| 67 | |
| 68 | gd->bd->bi_dram[1].start = PHYS_SDRAM_2; |
| 69 | gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE; |
| 70 | } |
| 71 | |
Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 72 | static void setup_iomux_i2c(void) |
| 73 | { |
| 74 | int pad; |
| 75 | |
| 76 | /* setup pins for I2C1 */ |
| 77 | mxc_request_iomux(MX35_PIN_I2C1_CLK, MUX_CONFIG_SION); |
| 78 | mxc_request_iomux(MX35_PIN_I2C1_DAT, MUX_CONFIG_SION); |
| 79 | |
| 80 | pad = (PAD_CTL_HYS_SCHMITZ | PAD_CTL_PKE_ENABLE \ |
| 81 | | PAD_CTL_PUE_PUD | PAD_CTL_ODE_OpenDrain); |
| 82 | |
| 83 | mxc_iomux_set_pad(MX35_PIN_I2C1_CLK, pad); |
| 84 | mxc_iomux_set_pad(MX35_PIN_I2C1_DAT, pad); |
| 85 | } |
| 86 | |
| 87 | |
| 88 | static void setup_iomux_spi(void) |
| 89 | { |
| 90 | mxc_request_iomux(MX35_PIN_CSPI1_MOSI, MUX_CONFIG_SION); |
| 91 | mxc_request_iomux(MX35_PIN_CSPI1_MISO, MUX_CONFIG_SION); |
| 92 | mxc_request_iomux(MX35_PIN_CSPI1_SS0, MUX_CONFIG_SION); |
| 93 | mxc_request_iomux(MX35_PIN_CSPI1_SS1, MUX_CONFIG_SION); |
| 94 | mxc_request_iomux(MX35_PIN_CSPI1_SCLK, MUX_CONFIG_SION); |
| 95 | } |
| 96 | |
| 97 | static void setup_iomux_fec(void) |
| 98 | { |
| 99 | int pad; |
| 100 | |
| 101 | /* setup pins for FEC */ |
| 102 | mxc_request_iomux(MX35_PIN_FEC_TX_CLK, MUX_CONFIG_FUNC); |
| 103 | mxc_request_iomux(MX35_PIN_FEC_RX_CLK, MUX_CONFIG_FUNC); |
| 104 | mxc_request_iomux(MX35_PIN_FEC_RX_DV, MUX_CONFIG_FUNC); |
| 105 | mxc_request_iomux(MX35_PIN_FEC_COL, MUX_CONFIG_FUNC); |
| 106 | mxc_request_iomux(MX35_PIN_FEC_RDATA0, MUX_CONFIG_FUNC); |
| 107 | mxc_request_iomux(MX35_PIN_FEC_TDATA0, MUX_CONFIG_FUNC); |
| 108 | mxc_request_iomux(MX35_PIN_FEC_TX_EN, MUX_CONFIG_FUNC); |
| 109 | mxc_request_iomux(MX35_PIN_FEC_MDC, MUX_CONFIG_FUNC); |
| 110 | mxc_request_iomux(MX35_PIN_FEC_MDIO, MUX_CONFIG_FUNC); |
| 111 | mxc_request_iomux(MX35_PIN_FEC_TX_ERR, MUX_CONFIG_FUNC); |
| 112 | mxc_request_iomux(MX35_PIN_FEC_RX_ERR, MUX_CONFIG_FUNC); |
| 113 | mxc_request_iomux(MX35_PIN_FEC_CRS, MUX_CONFIG_FUNC); |
| 114 | mxc_request_iomux(MX35_PIN_FEC_RDATA1, MUX_CONFIG_FUNC); |
| 115 | mxc_request_iomux(MX35_PIN_FEC_TDATA1, MUX_CONFIG_FUNC); |
| 116 | mxc_request_iomux(MX35_PIN_FEC_RDATA2, MUX_CONFIG_FUNC); |
| 117 | mxc_request_iomux(MX35_PIN_FEC_TDATA2, MUX_CONFIG_FUNC); |
| 118 | mxc_request_iomux(MX35_PIN_FEC_RDATA3, MUX_CONFIG_FUNC); |
| 119 | mxc_request_iomux(MX35_PIN_FEC_TDATA3, MUX_CONFIG_FUNC); |
| 120 | |
| 121 | pad = (PAD_CTL_DRV_3_3V | PAD_CTL_PUE_PUD | PAD_CTL_ODE_CMOS | \ |
| 122 | PAD_CTL_DRV_NORMAL | PAD_CTL_SRE_SLOW); |
| 123 | |
| 124 | mxc_iomux_set_pad(MX35_PIN_FEC_TX_CLK, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 125 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 126 | mxc_iomux_set_pad(MX35_PIN_FEC_RX_CLK, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 127 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 128 | mxc_iomux_set_pad(MX35_PIN_FEC_RX_DV, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 129 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 130 | mxc_iomux_set_pad(MX35_PIN_FEC_COL, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 131 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 132 | mxc_iomux_set_pad(MX35_PIN_FEC_RDATA0, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 133 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 134 | mxc_iomux_set_pad(MX35_PIN_FEC_TDATA0, pad | PAD_CTL_HYS_CMOS | \ |
| 135 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 136 | mxc_iomux_set_pad(MX35_PIN_FEC_TX_EN, pad | PAD_CTL_HYS_CMOS | \ |
| 137 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 138 | mxc_iomux_set_pad(MX35_PIN_FEC_MDC, pad | PAD_CTL_HYS_CMOS | \ |
| 139 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 140 | mxc_iomux_set_pad(MX35_PIN_FEC_MDIO, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 141 | PAD_CTL_PKE_ENABLE | PAD_CTL_22K_PU); |
| 142 | mxc_iomux_set_pad(MX35_PIN_FEC_TX_ERR, pad | PAD_CTL_HYS_CMOS | \ |
| 143 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 144 | mxc_iomux_set_pad(MX35_PIN_FEC_RX_ERR, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 145 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 146 | mxc_iomux_set_pad(MX35_PIN_FEC_CRS, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 147 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 148 | mxc_iomux_set_pad(MX35_PIN_FEC_RDATA1, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 149 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 150 | mxc_iomux_set_pad(MX35_PIN_FEC_TDATA1, pad | PAD_CTL_HYS_CMOS | \ |
| 151 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 152 | mxc_iomux_set_pad(MX35_PIN_FEC_RDATA2, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 153 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 154 | mxc_iomux_set_pad(MX35_PIN_FEC_TDATA2, pad | PAD_CTL_HYS_CMOS | \ |
| 155 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 156 | mxc_iomux_set_pad(MX35_PIN_FEC_RDATA3, pad | PAD_CTL_HYS_SCHMITZ | \ |
| 157 | PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD); |
| 158 | mxc_iomux_set_pad(MX35_PIN_FEC_TDATA3, pad | PAD_CTL_HYS_CMOS | \ |
| 159 | PAD_CTL_PKE_NONE | PAD_CTL_100K_PD); |
| 160 | } |
| 161 | |
| 162 | int board_early_init_f(void) |
| 163 | { |
| 164 | struct ccm_regs *ccm = |
| 165 | (struct ccm_regs *)IMX_CCM_BASE; |
| 166 | |
| 167 | /* enable clocks */ |
| 168 | writel(readl(&ccm->cgr0) | |
| 169 | MXC_CCM_CGR0_EMI_MASK | |
| 170 | MXC_CCM_CGR0_EDI0_MASK | |
| 171 | MXC_CCM_CGR0_EPIT1_MASK, |
| 172 | &ccm->cgr0); |
| 173 | |
| 174 | writel(readl(&ccm->cgr1) | |
| 175 | MXC_CCM_CGR1_FEC_MASK | |
| 176 | MXC_CCM_CGR1_GPIO1_MASK | |
| 177 | MXC_CCM_CGR1_GPIO2_MASK | |
| 178 | MXC_CCM_CGR1_GPIO3_MASK | |
| 179 | MXC_CCM_CGR1_I2C1_MASK | |
| 180 | MXC_CCM_CGR1_I2C2_MASK | |
| 181 | MXC_CCM_CGR1_IPU_MASK, |
| 182 | &ccm->cgr1); |
| 183 | |
| 184 | /* Setup NAND */ |
| 185 | __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr); |
| 186 | |
| 187 | setup_iomux_i2c(); |
| 188 | setup_iomux_fec(); |
| 189 | setup_iomux_spi(); |
| 190 | |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | int board_init(void) |
| 195 | { |
| 196 | gd->bd->bi_arch_number = MACH_TYPE_MX35_3DS; /* board id for linux */ |
| 197 | /* address of boot parameters */ |
| 198 | gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100; |
| 199 | |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | static inline int pmic_detect(void) |
| 204 | { |
| 205 | int id; |
| 206 | |
| 207 | id = pmic_reg_read(REG_IDENTIFICATION); |
| 208 | |
| 209 | id = (id >> 6) & 0x7; |
| 210 | if (id == 0x7) |
| 211 | return 1; |
| 212 | return 0; |
| 213 | } |
| 214 | |
| 215 | u32 get_board_rev(void) |
| 216 | { |
| 217 | int rev; |
| 218 | |
| 219 | rev = pmic_detect(); |
| 220 | |
| 221 | return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8; |
| 222 | } |
| 223 | |
| 224 | int board_late_init(void) |
| 225 | { |
| 226 | u8 val; |
| 227 | u32 pmic_val; |
| 228 | |
| 229 | if (pmic_detect()) { |
| 230 | mxc_request_iomux(MX35_PIN_WATCHDOG_RST, MUX_CONFIG_SION | |
| 231 | MUX_CONFIG_ALT1); |
| 232 | |
| 233 | pmic_val = pmic_reg_read(REG_SETTING_0); |
| 234 | pmic_reg_write(REG_SETTING_0, pmic_val | VO_1_30V | VO_1_50V); |
| 235 | pmic_val = pmic_reg_read(REG_MODE_0); |
| 236 | pmic_reg_write(REG_MODE_0, pmic_val | VGEN3EN); |
| 237 | |
| 238 | mxc_request_iomux(MX35_PIN_COMPARE, MUX_CONFIG_GPIO); |
| 239 | mxc_iomux_set_input(MUX_IN_GPIO1_IN_5, INPUT_CTL_PATH0); |
| 240 | |
Stefano Babic | 560c1bc | 2011-08-21 11:00:32 +0200 | [diff] [blame] | 241 | gpio_direction_output(37, 1); |
Stefano Babic | f02e697 | 2011-01-20 08:05:15 +0000 | [diff] [blame] | 242 | } |
| 243 | |
| 244 | val = mc9sdz60_reg_read(MC9SDZ60_REG_GPIO_1) | 0x04; |
| 245 | mc9sdz60_reg_write(MC9SDZ60_REG_GPIO_1, val); |
| 246 | mdelay(200); |
| 247 | |
| 248 | val = mc9sdz60_reg_read(MC9SDZ60_REG_RESET_1) & 0x7F; |
| 249 | mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val); |
| 250 | mdelay(200); |
| 251 | |
| 252 | val |= 0x80; |
| 253 | mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val); |
| 254 | |
| 255 | return 0; |
| 256 | } |
| 257 | |
| 258 | int checkboard(void) |
| 259 | { |
| 260 | struct ccm_regs *ccm = |
| 261 | (struct ccm_regs *)IMX_CCM_BASE; |
| 262 | u32 cpu_rev = get_cpu_rev(); |
| 263 | |
| 264 | /* |
| 265 | * Be sure that I2C is initialized to check |
| 266 | * the board revision |
| 267 | */ |
| 268 | i2c_init(CONFIG_SYS_I2C_SPEED, CONFIG_SYS_I2C_SLAVE); |
| 269 | |
| 270 | /* Print board revision */ |
| 271 | printf("Board: MX35 PDK %d.0 ", ((get_board_rev() >> 8) + 1) & 0x0F); |
| 272 | |
| 273 | /* Print CPU revision */ |
| 274 | printf("i.MX35 %d.%d [", (cpu_rev & 0xF0) >> 4, cpu_rev & 0x0F); |
| 275 | |
| 276 | switch (readl(&ccm->rcsr) & 0x0F) { |
| 277 | case 0x0000: |
| 278 | puts("POR"); |
| 279 | break; |
| 280 | case 0x0002: |
| 281 | puts("JTAG"); |
| 282 | break; |
| 283 | case 0x0004: |
| 284 | puts("RST"); |
| 285 | break; |
| 286 | case 0x0008: |
| 287 | puts("WDT"); |
| 288 | break; |
| 289 | default: |
| 290 | puts("unknown"); |
| 291 | } |
| 292 | puts("]\n"); |
| 293 | |
| 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | int board_eth_init(bd_t *bis) |
| 298 | { |
| 299 | int rc = -ENODEV; |
| 300 | #if defined(CONFIG_SMC911X) |
| 301 | rc = smc911x_initialize(0, CONFIG_SMC911X_BASE); |
| 302 | #endif |
| 303 | |
| 304 | cpu_eth_init(bis); |
| 305 | |
| 306 | return rc; |
| 307 | } |