blob: 4d8f2f5eea34c1f2c37cd3ab73e62dcabdcf78c2 [file] [log] [blame]
Stefano Babicf02e6972011-01-20 08:05:15 +00001/*
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>
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +000030#include <asm/arch/clock.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000031#include <asm/arch/mx35_pins.h>
32#include <asm/arch/iomux.h>
33#include <i2c.h>
Stefano Babic55615742011-10-06 21:07:42 +020034#include <pmic.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000035#include <fsl_pmic.h>
Stefano Babic9dd9d0f2012-09-05 21:47:42 +000036#include <mmc.h>
37#include <fsl_esdhc.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000038#include <mc9sdz60.h>
39#include <mc13892.h>
40#include <linux/types.h>
Stefano Babic560c1bc2011-08-21 11:00:32 +020041#include <asm/gpio.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000042#include <asm/arch/sys_proto.h>
43#include <netdev.h>
44
Helmut Raigerd5a184b2011-10-20 04:19:47 +000045#ifndef CONFIG_BOARD_LATE_INIT
46#error "CONFIG_BOARD_LATE_INIT must be set for this board"
Stefano Babicf02e6972011-01-20 08:05:15 +000047#endif
48
49#ifndef CONFIG_BOARD_EARLY_INIT_F
50#error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
51#endif
52
Stefano Babicf02e6972011-01-20 08:05:15 +000053DECLARE_GLOBAL_DATA_PTR;
54
55int dram_init(void)
56{
Stefano Babic19edc942011-08-02 14:42:36 +020057 u32 size1, size2;
58
59 size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
60 size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
61
62 gd->ram_size = size1 + size2;
Stefano Babicf02e6972011-01-20 08:05:15 +000063
64 return 0;
65}
66
Stefano Babic19edc942011-08-02 14:42:36 +020067void dram_init_banksize(void)
68{
69 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
70 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
71
72 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
73 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
74}
75
Stefano Babicf02e6972011-01-20 08:05:15 +000076static void setup_iomux_i2c(void)
77{
78 int pad;
79
80 /* setup pins for I2C1 */
81 mxc_request_iomux(MX35_PIN_I2C1_CLK, MUX_CONFIG_SION);
82 mxc_request_iomux(MX35_PIN_I2C1_DAT, MUX_CONFIG_SION);
83
84 pad = (PAD_CTL_HYS_SCHMITZ | PAD_CTL_PKE_ENABLE \
85 | PAD_CTL_PUE_PUD | PAD_CTL_ODE_OpenDrain);
86
87 mxc_iomux_set_pad(MX35_PIN_I2C1_CLK, pad);
88 mxc_iomux_set_pad(MX35_PIN_I2C1_DAT, pad);
89}
90
91
92static void setup_iomux_spi(void)
93{
94 mxc_request_iomux(MX35_PIN_CSPI1_MOSI, MUX_CONFIG_SION);
95 mxc_request_iomux(MX35_PIN_CSPI1_MISO, MUX_CONFIG_SION);
96 mxc_request_iomux(MX35_PIN_CSPI1_SS0, MUX_CONFIG_SION);
97 mxc_request_iomux(MX35_PIN_CSPI1_SS1, MUX_CONFIG_SION);
98 mxc_request_iomux(MX35_PIN_CSPI1_SCLK, MUX_CONFIG_SION);
99}
100
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +0000101static void setup_iomux_usbotg(void)
102{
103 int in_pad, out_pad;
104
105 /* Set up pins for USBOTG. */
106 mxc_request_iomux(MX35_PIN_USBOTG_PWR,
107 MUX_CONFIG_SION | MUX_CONFIG_FUNC);
108 mxc_request_iomux(MX35_PIN_USBOTG_OC,
109 MUX_CONFIG_SION | MUX_CONFIG_FUNC);
110
111 in_pad = PAD_CTL_DRV_3_3V | PAD_CTL_HYS_SCHMITZ | PAD_CTL_PKE_ENABLE |
112 PAD_CTL_PUE_PUD | PAD_CTL_100K_PD | PAD_CTL_ODE_CMOS |
113 PAD_CTL_DRV_NORMAL | PAD_CTL_SRE_SLOW;
114 out_pad = PAD_CTL_DRV_3_3V | PAD_CTL_HYS_CMOS | PAD_CTL_PKE_NONE |
115 PAD_CTL_ODE_CMOS | PAD_CTL_DRV_NORMAL | PAD_CTL_SRE_SLOW;
116
117 mxc_iomux_set_pad(MX35_PIN_USBOTG_PWR, out_pad);
118 mxc_iomux_set_pad(MX35_PIN_USBOTG_OC, in_pad);
119}
120
Stefano Babicf02e6972011-01-20 08:05:15 +0000121static void setup_iomux_fec(void)
122{
123 int pad;
124
125 /* setup pins for FEC */
126 mxc_request_iomux(MX35_PIN_FEC_TX_CLK, MUX_CONFIG_FUNC);
127 mxc_request_iomux(MX35_PIN_FEC_RX_CLK, MUX_CONFIG_FUNC);
128 mxc_request_iomux(MX35_PIN_FEC_RX_DV, MUX_CONFIG_FUNC);
129 mxc_request_iomux(MX35_PIN_FEC_COL, MUX_CONFIG_FUNC);
130 mxc_request_iomux(MX35_PIN_FEC_RDATA0, MUX_CONFIG_FUNC);
131 mxc_request_iomux(MX35_PIN_FEC_TDATA0, MUX_CONFIG_FUNC);
132 mxc_request_iomux(MX35_PIN_FEC_TX_EN, MUX_CONFIG_FUNC);
133 mxc_request_iomux(MX35_PIN_FEC_MDC, MUX_CONFIG_FUNC);
134 mxc_request_iomux(MX35_PIN_FEC_MDIO, MUX_CONFIG_FUNC);
135 mxc_request_iomux(MX35_PIN_FEC_TX_ERR, MUX_CONFIG_FUNC);
136 mxc_request_iomux(MX35_PIN_FEC_RX_ERR, MUX_CONFIG_FUNC);
137 mxc_request_iomux(MX35_PIN_FEC_CRS, MUX_CONFIG_FUNC);
138 mxc_request_iomux(MX35_PIN_FEC_RDATA1, MUX_CONFIG_FUNC);
139 mxc_request_iomux(MX35_PIN_FEC_TDATA1, MUX_CONFIG_FUNC);
140 mxc_request_iomux(MX35_PIN_FEC_RDATA2, MUX_CONFIG_FUNC);
141 mxc_request_iomux(MX35_PIN_FEC_TDATA2, MUX_CONFIG_FUNC);
142 mxc_request_iomux(MX35_PIN_FEC_RDATA3, MUX_CONFIG_FUNC);
143 mxc_request_iomux(MX35_PIN_FEC_TDATA3, MUX_CONFIG_FUNC);
144
145 pad = (PAD_CTL_DRV_3_3V | PAD_CTL_PUE_PUD | PAD_CTL_ODE_CMOS | \
146 PAD_CTL_DRV_NORMAL | PAD_CTL_SRE_SLOW);
147
148 mxc_iomux_set_pad(MX35_PIN_FEC_TX_CLK, pad | PAD_CTL_HYS_SCHMITZ | \
149 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
150 mxc_iomux_set_pad(MX35_PIN_FEC_RX_CLK, pad | PAD_CTL_HYS_SCHMITZ | \
151 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
152 mxc_iomux_set_pad(MX35_PIN_FEC_RX_DV, pad | PAD_CTL_HYS_SCHMITZ | \
153 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
154 mxc_iomux_set_pad(MX35_PIN_FEC_COL, pad | PAD_CTL_HYS_SCHMITZ | \
155 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
156 mxc_iomux_set_pad(MX35_PIN_FEC_RDATA0, pad | PAD_CTL_HYS_SCHMITZ | \
157 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
158 mxc_iomux_set_pad(MX35_PIN_FEC_TDATA0, pad | PAD_CTL_HYS_CMOS | \
159 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
160 mxc_iomux_set_pad(MX35_PIN_FEC_TX_EN, pad | PAD_CTL_HYS_CMOS | \
161 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
162 mxc_iomux_set_pad(MX35_PIN_FEC_MDC, pad | PAD_CTL_HYS_CMOS | \
163 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
164 mxc_iomux_set_pad(MX35_PIN_FEC_MDIO, pad | PAD_CTL_HYS_SCHMITZ | \
165 PAD_CTL_PKE_ENABLE | PAD_CTL_22K_PU);
166 mxc_iomux_set_pad(MX35_PIN_FEC_TX_ERR, pad | PAD_CTL_HYS_CMOS | \
167 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
168 mxc_iomux_set_pad(MX35_PIN_FEC_RX_ERR, pad | PAD_CTL_HYS_SCHMITZ | \
169 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
170 mxc_iomux_set_pad(MX35_PIN_FEC_CRS, pad | PAD_CTL_HYS_SCHMITZ | \
171 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
172 mxc_iomux_set_pad(MX35_PIN_FEC_RDATA1, pad | PAD_CTL_HYS_SCHMITZ | \
173 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
174 mxc_iomux_set_pad(MX35_PIN_FEC_TDATA1, pad | PAD_CTL_HYS_CMOS | \
175 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
176 mxc_iomux_set_pad(MX35_PIN_FEC_RDATA2, pad | PAD_CTL_HYS_SCHMITZ | \
177 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
178 mxc_iomux_set_pad(MX35_PIN_FEC_TDATA2, pad | PAD_CTL_HYS_CMOS | \
179 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
180 mxc_iomux_set_pad(MX35_PIN_FEC_RDATA3, pad | PAD_CTL_HYS_SCHMITZ | \
181 PAD_CTL_PKE_ENABLE | PAD_CTL_100K_PD);
182 mxc_iomux_set_pad(MX35_PIN_FEC_TDATA3, pad | PAD_CTL_HYS_CMOS | \
183 PAD_CTL_PKE_NONE | PAD_CTL_100K_PD);
184}
185
186int board_early_init_f(void)
187{
188 struct ccm_regs *ccm =
189 (struct ccm_regs *)IMX_CCM_BASE;
190
191 /* enable clocks */
192 writel(readl(&ccm->cgr0) |
193 MXC_CCM_CGR0_EMI_MASK |
Benoît Thébaudeau8ce87772012-08-14 03:28:24 +0000194 MXC_CCM_CGR0_EDIO_MASK |
Stefano Babicf02e6972011-01-20 08:05:15 +0000195 MXC_CCM_CGR0_EPIT1_MASK,
196 &ccm->cgr0);
197
198 writel(readl(&ccm->cgr1) |
199 MXC_CCM_CGR1_FEC_MASK |
200 MXC_CCM_CGR1_GPIO1_MASK |
201 MXC_CCM_CGR1_GPIO2_MASK |
202 MXC_CCM_CGR1_GPIO3_MASK |
203 MXC_CCM_CGR1_I2C1_MASK |
204 MXC_CCM_CGR1_I2C2_MASK |
205 MXC_CCM_CGR1_IPU_MASK,
206 &ccm->cgr1);
207
208 /* Setup NAND */
209 __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
210
211 setup_iomux_i2c();
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +0000212 setup_iomux_usbotg();
Stefano Babicf02e6972011-01-20 08:05:15 +0000213 setup_iomux_fec();
214 setup_iomux_spi();
215
216 return 0;
217}
218
219int board_init(void)
220{
221 gd->bd->bi_arch_number = MACH_TYPE_MX35_3DS; /* board id for linux */
222 /* address of boot parameters */
223 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
224
225 return 0;
226}
227
228static inline int pmic_detect(void)
229{
Stefano Babic55615742011-10-06 21:07:42 +0200230 unsigned int id;
231 struct pmic *p = get_pmic();
Stefano Babicf02e6972011-01-20 08:05:15 +0000232
Stefano Babic55615742011-10-06 21:07:42 +0200233 pmic_reg_read(p, REG_IDENTIFICATION, &id);
Stefano Babicf02e6972011-01-20 08:05:15 +0000234
235 id = (id >> 6) & 0x7;
236 if (id == 0x7)
237 return 1;
238 return 0;
239}
240
241u32 get_board_rev(void)
242{
243 int rev;
244
245 rev = pmic_detect();
246
247 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
248}
249
250int board_late_init(void)
251{
252 u8 val;
253 u32 pmic_val;
Stefano Babic55615742011-10-06 21:07:42 +0200254 struct pmic *p;
Stefano Babicf02e6972011-01-20 08:05:15 +0000255
Stefano Babic55615742011-10-06 21:07:42 +0200256 pmic_init();
Stefano Babicf02e6972011-01-20 08:05:15 +0000257 if (pmic_detect()) {
Stefano Babic55615742011-10-06 21:07:42 +0200258 p = get_pmic();
Stefano Babicf02e6972011-01-20 08:05:15 +0000259 mxc_request_iomux(MX35_PIN_WATCHDOG_RST, MUX_CONFIG_SION |
260 MUX_CONFIG_ALT1);
261
Stefano Babic55615742011-10-06 21:07:42 +0200262 pmic_reg_read(p, REG_SETTING_0, &pmic_val);
263 pmic_reg_write(p, REG_SETTING_0,
264 pmic_val | VO_1_30V | VO_1_50V);
265 pmic_reg_read(p, REG_MODE_0, &pmic_val);
266 pmic_reg_write(p, REG_MODE_0, pmic_val | VGEN3EN);
Stefano Babicf02e6972011-01-20 08:05:15 +0000267
268 mxc_request_iomux(MX35_PIN_COMPARE, MUX_CONFIG_GPIO);
269 mxc_iomux_set_input(MUX_IN_GPIO1_IN_5, INPUT_CTL_PATH0);
270
Stefano Babic560c1bc2011-08-21 11:00:32 +0200271 gpio_direction_output(37, 1);
Stefano Babicf02e6972011-01-20 08:05:15 +0000272 }
273
274 val = mc9sdz60_reg_read(MC9SDZ60_REG_GPIO_1) | 0x04;
275 mc9sdz60_reg_write(MC9SDZ60_REG_GPIO_1, val);
276 mdelay(200);
277
278 val = mc9sdz60_reg_read(MC9SDZ60_REG_RESET_1) & 0x7F;
279 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
280 mdelay(200);
281
282 val |= 0x80;
283 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
284
Stefano Babicf02e6972011-01-20 08:05:15 +0000285 /* Print board revision */
Fabio Estevam772ec152012-02-10 06:29:15 +0000286 printf("Board: MX35 PDK %d.0\n", ((get_board_rev() >> 8) + 1) & 0x0F);
Stefano Babicf02e6972011-01-20 08:05:15 +0000287
288 return 0;
289}
290
291int board_eth_init(bd_t *bis)
292{
293 int rc = -ENODEV;
294#if defined(CONFIG_SMC911X)
295 rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
296#endif
297
298 cpu_eth_init(bis);
299
300 return rc;
301}
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000302
303#if defined(CONFIG_FSL_ESDHC)
304
305struct fsl_esdhc_cfg esdhc_cfg = {MMC_SDHC1_BASE_ADDR};
306
307int board_mmc_init(bd_t *bis)
308{
309 /* configure pins for SDHC1 only */
310 mxc_request_iomux(MX35_PIN_SD1_CMD, MUX_CONFIG_FUNC);
311 mxc_request_iomux(MX35_PIN_SD1_CLK, MUX_CONFIG_FUNC);
312 mxc_request_iomux(MX35_PIN_SD1_DATA0, MUX_CONFIG_FUNC);
313 mxc_request_iomux(MX35_PIN_SD1_DATA1, MUX_CONFIG_FUNC);
314 mxc_request_iomux(MX35_PIN_SD1_DATA2, MUX_CONFIG_FUNC);
315 mxc_request_iomux(MX35_PIN_SD1_DATA3, MUX_CONFIG_FUNC);
316
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000317 esdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000318 return fsl_esdhc_initialize(bis, &esdhc_cfg);
319}
320
321int board_mmc_getcd(struct mmc *mmc)
322{
323 return !(mc9sdz60_reg_read(MC9SDZ60_REG_DES_FLAG) & 0x4);
324}
325#endif