blob: ea0bd8f30a316dd7f4b73645196e4737028ef4b8 [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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02006 * SPDX-License-Identifier: GPL-2.0+
Stefano Babicf02e6972011-01-20 08:05:15 +00007 */
8
9#include <common.h>
10#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090011#include <linux/errno.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000012#include <asm/arch/imx-regs.h>
13#include <asm/arch/crm_regs.h>
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +000014#include <asm/arch/clock.h>
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000015#include <asm/arch/iomux-mx35.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000016#include <i2c.h>
Łukasz Majewski1c6dba12012-11-13 03:21:55 +000017#include <power/pmic.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000018#include <fsl_pmic.h>
Stefano Babic9dd9d0f2012-09-05 21:47:42 +000019#include <mmc.h>
20#include <fsl_esdhc.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000021#include <mc9sdz60.h>
22#include <mc13892.h>
23#include <linux/types.h>
Stefano Babic560c1bc2011-08-21 11:00:32 +020024#include <asm/gpio.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000025#include <asm/arch/sys_proto.h>
26#include <netdev.h>
Simon Glass0ffb9d62017-05-31 19:47:48 -060027#include <asm/mach-types.h>
Stefano Babicf02e6972011-01-20 08:05:15 +000028
Helmut Raigerd5a184b2011-10-20 04:19:47 +000029#ifndef CONFIG_BOARD_LATE_INIT
30#error "CONFIG_BOARD_LATE_INIT must be set for this board"
Stefano Babicf02e6972011-01-20 08:05:15 +000031#endif
32
33#ifndef CONFIG_BOARD_EARLY_INIT_F
34#error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
35#endif
36
Stefano Babicf02e6972011-01-20 08:05:15 +000037DECLARE_GLOBAL_DATA_PTR;
38
39int dram_init(void)
40{
Stefano Babic19edc942011-08-02 14:42:36 +020041 u32 size1, size2;
42
43 size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
44 size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
45
46 gd->ram_size = size1 + size2;
Stefano Babicf02e6972011-01-20 08:05:15 +000047
48 return 0;
49}
50
Simon Glass2f949c32017-03-31 08:40:32 -060051int dram_init_banksize(void)
Stefano Babic19edc942011-08-02 14:42:36 +020052{
53 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
54 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
55
56 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
57 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Simon Glass2f949c32017-03-31 08:40:32 -060058
59 return 0;
Stefano Babic19edc942011-08-02 14:42:36 +020060}
61
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000062#define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_ODE)
63
Stefano Babicf02e6972011-01-20 08:05:15 +000064static void setup_iomux_i2c(void)
65{
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000066 static const iomux_v3_cfg_t i2c1_pads[] = {
67 NEW_PAD_CTRL(MX35_PAD_I2C1_CLK__I2C1_SCL, I2C_PAD_CTRL),
68 NEW_PAD_CTRL(MX35_PAD_I2C1_DAT__I2C1_SDA, I2C_PAD_CTRL),
69 };
Stefano Babicf02e6972011-01-20 08:05:15 +000070
71 /* setup pins for I2C1 */
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000072 imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
Stefano Babicf02e6972011-01-20 08:05:15 +000073}
74
75
76static void setup_iomux_spi(void)
77{
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000078 static const iomux_v3_cfg_t spi_pads[] = {
79 MX35_PAD_CSPI1_MOSI__CSPI1_MOSI,
80 MX35_PAD_CSPI1_MISO__CSPI1_MISO,
81 MX35_PAD_CSPI1_SS0__CSPI1_SS0,
82 MX35_PAD_CSPI1_SS1__CSPI1_SS1,
83 MX35_PAD_CSPI1_SCLK__CSPI1_SCLK,
84 };
85
86 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babicf02e6972011-01-20 08:05:15 +000087}
88
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000089#define USBOTG_IN_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | \
90 PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
91#define USBOTG_OUT_PAD_CTRL (PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
92
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +000093static void setup_iomux_usbotg(void)
94{
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +000095 static const iomux_v3_cfg_t usbotg_pads[] = {
96 NEW_PAD_CTRL(MX35_PAD_USBOTG_PWR__USB_TOP_USBOTG_PWR,
97 USBOTG_OUT_PAD_CTRL),
98 NEW_PAD_CTRL(MX35_PAD_USBOTG_OC__USB_TOP_USBOTG_OC,
99 USBOTG_IN_PAD_CTRL),
100 };
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +0000101
102 /* Set up pins for USBOTG. */
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000103 imx_iomux_v3_setup_multiple_pads(usbotg_pads, ARRAY_SIZE(usbotg_pads));
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +0000104}
105
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000106#define FEC_PAD_CTRL (PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
107
Stefano Babicf02e6972011-01-20 08:05:15 +0000108static void setup_iomux_fec(void)
109{
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000110 static const iomux_v3_cfg_t fec_pads[] = {
111 NEW_PAD_CTRL(MX35_PAD_FEC_TX_CLK__FEC_TX_CLK, FEC_PAD_CTRL |
112 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
113 NEW_PAD_CTRL(MX35_PAD_FEC_RX_CLK__FEC_RX_CLK, FEC_PAD_CTRL |
114 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
115 NEW_PAD_CTRL(MX35_PAD_FEC_RX_DV__FEC_RX_DV, FEC_PAD_CTRL |
116 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
117 NEW_PAD_CTRL(MX35_PAD_FEC_COL__FEC_COL, FEC_PAD_CTRL |
118 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
119 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA0__FEC_RDATA_0, FEC_PAD_CTRL |
120 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
121 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA0__FEC_TDATA_0, FEC_PAD_CTRL),
122 NEW_PAD_CTRL(MX35_PAD_FEC_TX_EN__FEC_TX_EN, FEC_PAD_CTRL),
123 NEW_PAD_CTRL(MX35_PAD_FEC_MDC__FEC_MDC, FEC_PAD_CTRL),
124 NEW_PAD_CTRL(MX35_PAD_FEC_MDIO__FEC_MDIO, FEC_PAD_CTRL |
125 PAD_CTL_HYS | PAD_CTL_PUS_22K_UP),
126 NEW_PAD_CTRL(MX35_PAD_FEC_TX_ERR__FEC_TX_ERR, FEC_PAD_CTRL),
127 NEW_PAD_CTRL(MX35_PAD_FEC_RX_ERR__FEC_RX_ERR, FEC_PAD_CTRL |
128 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
129 NEW_PAD_CTRL(MX35_PAD_FEC_CRS__FEC_CRS, FEC_PAD_CTRL |
130 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
131 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA1__FEC_RDATA_1, FEC_PAD_CTRL |
132 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
133 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA1__FEC_TDATA_1, FEC_PAD_CTRL),
134 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA2__FEC_RDATA_2, FEC_PAD_CTRL |
135 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
136 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA2__FEC_TDATA_2, FEC_PAD_CTRL),
137 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA3__FEC_RDATA_3, FEC_PAD_CTRL |
138 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
139 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA3__FEC_TDATA_3, FEC_PAD_CTRL),
140 };
Stefano Babicf02e6972011-01-20 08:05:15 +0000141
142 /* setup pins for FEC */
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000143 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Stefano Babicf02e6972011-01-20 08:05:15 +0000144}
145
146int board_early_init_f(void)
147{
148 struct ccm_regs *ccm =
149 (struct ccm_regs *)IMX_CCM_BASE;
150
151 /* enable clocks */
152 writel(readl(&ccm->cgr0) |
153 MXC_CCM_CGR0_EMI_MASK |
Benoît Thébaudeau8ce87772012-08-14 03:28:24 +0000154 MXC_CCM_CGR0_EDIO_MASK |
Stefano Babicf02e6972011-01-20 08:05:15 +0000155 MXC_CCM_CGR0_EPIT1_MASK,
156 &ccm->cgr0);
157
158 writel(readl(&ccm->cgr1) |
159 MXC_CCM_CGR1_FEC_MASK |
160 MXC_CCM_CGR1_GPIO1_MASK |
161 MXC_CCM_CGR1_GPIO2_MASK |
162 MXC_CCM_CGR1_GPIO3_MASK |
163 MXC_CCM_CGR1_I2C1_MASK |
164 MXC_CCM_CGR1_I2C2_MASK |
165 MXC_CCM_CGR1_IPU_MASK,
166 &ccm->cgr1);
167
168 /* Setup NAND */
169 __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
170
171 setup_iomux_i2c();
Benoît Thébaudeau50af5db2012-11-13 09:58:25 +0000172 setup_iomux_usbotg();
Stefano Babicf02e6972011-01-20 08:05:15 +0000173 setup_iomux_fec();
174 setup_iomux_spi();
175
176 return 0;
177}
178
179int board_init(void)
180{
181 gd->bd->bi_arch_number = MACH_TYPE_MX35_3DS; /* board id for linux */
182 /* address of boot parameters */
183 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
184
185 return 0;
186}
187
188static inline int pmic_detect(void)
189{
Stefano Babic55615742011-10-06 21:07:42 +0200190 unsigned int id;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000191 struct pmic *p = pmic_get("FSL_PMIC");
192 if (!p)
193 return -ENODEV;
Stefano Babicf02e6972011-01-20 08:05:15 +0000194
Stefano Babic55615742011-10-06 21:07:42 +0200195 pmic_reg_read(p, REG_IDENTIFICATION, &id);
Stefano Babicf02e6972011-01-20 08:05:15 +0000196
197 id = (id >> 6) & 0x7;
198 if (id == 0x7)
199 return 1;
200 return 0;
201}
202
203u32 get_board_rev(void)
204{
205 int rev;
206
207 rev = pmic_detect();
208
209 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
210}
211
212int board_late_init(void)
213{
214 u8 val;
215 u32 pmic_val;
Stefano Babic55615742011-10-06 21:07:42 +0200216 struct pmic *p;
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000217 int ret;
Stefano Babicf02e6972011-01-20 08:05:15 +0000218
Fabio Estevamf330cec2013-11-20 21:17:36 -0200219 ret = pmic_init(I2C_0);
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000220 if (ret)
221 return ret;
222
Stefano Babicf02e6972011-01-20 08:05:15 +0000223 if (pmic_detect()) {
Łukasz Majewski1c6dba12012-11-13 03:21:55 +0000224 p = pmic_get("FSL_PMIC");
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000225 imx_iomux_v3_setup_pad(MX35_PAD_WDOG_RST__WDOG_WDOG_B);
Stefano Babicf02e6972011-01-20 08:05:15 +0000226
Stefano Babic55615742011-10-06 21:07:42 +0200227 pmic_reg_read(p, REG_SETTING_0, &pmic_val);
228 pmic_reg_write(p, REG_SETTING_0,
229 pmic_val | VO_1_30V | VO_1_50V);
230 pmic_reg_read(p, REG_MODE_0, &pmic_val);
231 pmic_reg_write(p, REG_MODE_0, pmic_val | VGEN3EN);
Stefano Babicf02e6972011-01-20 08:05:15 +0000232
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000233 imx_iomux_v3_setup_pad(MX35_PAD_COMPARE__GPIO1_5);
Stefano Babicf02e6972011-01-20 08:05:15 +0000234
Benoît Thébaudeaue79a5fd2013-05-06 01:33:51 +0000235 gpio_direction_output(IMX_GPIO_NR(1, 5), 1);
Stefano Babicf02e6972011-01-20 08:05:15 +0000236 }
237
238 val = mc9sdz60_reg_read(MC9SDZ60_REG_GPIO_1) | 0x04;
239 mc9sdz60_reg_write(MC9SDZ60_REG_GPIO_1, val);
240 mdelay(200);
241
242 val = mc9sdz60_reg_read(MC9SDZ60_REG_RESET_1) & 0x7F;
243 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
244 mdelay(200);
245
246 val |= 0x80;
247 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
248
Stefano Babicf02e6972011-01-20 08:05:15 +0000249 /* Print board revision */
Fabio Estevam772ec152012-02-10 06:29:15 +0000250 printf("Board: MX35 PDK %d.0\n", ((get_board_rev() >> 8) + 1) & 0x0F);
Stefano Babicf02e6972011-01-20 08:05:15 +0000251
252 return 0;
253}
254
255int board_eth_init(bd_t *bis)
256{
Stefano Babicf02e6972011-01-20 08:05:15 +0000257#if defined(CONFIG_SMC911X)
Fabio Estevamc58c8a42013-09-20 16:30:50 -0300258 int rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
259 if (rc)
260 return rc;
Stefano Babicf02e6972011-01-20 08:05:15 +0000261#endif
Fabio Estevamc58c8a42013-09-20 16:30:50 -0300262 return cpu_eth_init(bis);
Stefano Babicf02e6972011-01-20 08:05:15 +0000263}
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000264
265#if defined(CONFIG_FSL_ESDHC)
266
267struct fsl_esdhc_cfg esdhc_cfg = {MMC_SDHC1_BASE_ADDR};
268
269int board_mmc_init(bd_t *bis)
270{
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000271 static const iomux_v3_cfg_t sdhc1_pads[] = {
272 MX35_PAD_SD1_CMD__ESDHC1_CMD,
273 MX35_PAD_SD1_CLK__ESDHC1_CLK,
274 MX35_PAD_SD1_DATA0__ESDHC1_DAT0,
275 MX35_PAD_SD1_DATA1__ESDHC1_DAT1,
276 MX35_PAD_SD1_DATA2__ESDHC1_DAT2,
277 MX35_PAD_SD1_DATA3__ESDHC1_DAT3,
278 };
279
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000280 /* configure pins for SDHC1 only */
Benoît Thébaudeau4951a2c2013-05-03 10:32:22 +0000281 imx_iomux_v3_setup_multiple_pads(sdhc1_pads, ARRAY_SIZE(sdhc1_pads));
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000282
Benoît Thébaudeauc58ff342012-10-01 08:36:25 +0000283 esdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
Stefano Babic9dd9d0f2012-09-05 21:47:42 +0000284 return fsl_esdhc_initialize(bis, &esdhc_cfg);
285}
286
287int board_mmc_getcd(struct mmc *mmc)
288{
289 return !(mc9sdz60_reg_read(MC9SDZ60_REG_DES_FLAG) & 0x4);
290}
291#endif