blob: 4039d9f049a6656111a2874ce00564044bdeb7c1 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babiceae49882011-01-20 08:05:15 +00002/*
3 * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
4 *
5 * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
Stefano Babiceae49882011-01-20 08:05:15 +00006 */
7
8#include <common.h>
Simon Glass52559322019-11-14 12:57:46 -07009#include <init.h>
Simon Glass90526e92020-05-10 11:39:56 -060010#include <net.h>
Simon Glass401d1c42020-10-30 21:38:53 -060011#include <asm/global_data.h>
Stefano Babiceae49882011-01-20 08:05:15 +000012#include <asm/io.h>
Simon Glassc05ed002020-05-10 11:40:11 -060013#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090014#include <linux/errno.h>
Stefano Babiceae49882011-01-20 08:05:15 +000015#include <asm/arch/imx-regs.h>
16#include <asm/arch/crm_regs.h>
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +000017#include <asm/arch/clock.h>
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000018#include <asm/arch/iomux-mx35.h>
Stefano Babiceae49882011-01-20 08:05:15 +000019#include <i2c.h>
Łukasz Majewskic7336812012-11-13 03:21:55 +000020#include <power/pmic.h>
Stefano Babiceae49882011-01-20 08:05:15 +000021#include <fsl_pmic.h>
Stefano Babic32925392012-09-05 21:47:42 +000022#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080023#include <fsl_esdhc_imx.h>
Stefano Babiceae49882011-01-20 08:05:15 +000024#include <mc9sdz60.h>
25#include <mc13892.h>
26#include <linux/types.h>
Stefano Babica4adedd2011-08-21 11:00:32 +020027#include <asm/gpio.h>
Stefano Babiceae49882011-01-20 08:05:15 +000028#include <asm/arch/sys_proto.h>
29#include <netdev.h>
Simon Glassc62db352017-05-31 19:47:48 -060030#include <asm/mach-types.h>
Stefano Babiceae49882011-01-20 08:05:15 +000031
Helmut Raiger9660e442011-10-20 04:19:47 +000032#ifndef CONFIG_BOARD_LATE_INIT
33#error "CONFIG_BOARD_LATE_INIT must be set for this board"
Stefano Babiceae49882011-01-20 08:05:15 +000034#endif
35
36#ifndef CONFIG_BOARD_EARLY_INIT_F
37#error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
38#endif
39
Stefano Babiceae49882011-01-20 08:05:15 +000040DECLARE_GLOBAL_DATA_PTR;
41
42int dram_init(void)
43{
Stefano Babic6b5acfc2011-08-02 14:42:36 +020044 u32 size1, size2;
45
46 size1 = get_ram_size((void *)PHYS_SDRAM_1, PHYS_SDRAM_1_SIZE);
47 size2 = get_ram_size((void *)PHYS_SDRAM_2, PHYS_SDRAM_2_SIZE);
48
49 gd->ram_size = size1 + size2;
Stefano Babiceae49882011-01-20 08:05:15 +000050
51 return 0;
52}
53
Simon Glass76b00ac2017-03-31 08:40:32 -060054int dram_init_banksize(void)
Stefano Babic6b5acfc2011-08-02 14:42:36 +020055{
56 gd->bd->bi_dram[0].start = PHYS_SDRAM_1;
57 gd->bd->bi_dram[0].size = PHYS_SDRAM_1_SIZE;
58
59 gd->bd->bi_dram[1].start = PHYS_SDRAM_2;
60 gd->bd->bi_dram[1].size = PHYS_SDRAM_2_SIZE;
Simon Glass76b00ac2017-03-31 08:40:32 -060061
62 return 0;
Stefano Babic6b5acfc2011-08-02 14:42:36 +020063}
64
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000065#define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_ODE)
66
Stefano Babiceae49882011-01-20 08:05:15 +000067static void setup_iomux_i2c(void)
68{
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000069 static const iomux_v3_cfg_t i2c1_pads[] = {
70 NEW_PAD_CTRL(MX35_PAD_I2C1_CLK__I2C1_SCL, I2C_PAD_CTRL),
71 NEW_PAD_CTRL(MX35_PAD_I2C1_DAT__I2C1_SDA, I2C_PAD_CTRL),
72 };
Stefano Babiceae49882011-01-20 08:05:15 +000073
74 /* setup pins for I2C1 */
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000075 imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
Stefano Babiceae49882011-01-20 08:05:15 +000076}
77
78
79static void setup_iomux_spi(void)
80{
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000081 static const iomux_v3_cfg_t spi_pads[] = {
82 MX35_PAD_CSPI1_MOSI__CSPI1_MOSI,
83 MX35_PAD_CSPI1_MISO__CSPI1_MISO,
84 MX35_PAD_CSPI1_SS0__CSPI1_SS0,
85 MX35_PAD_CSPI1_SS1__CSPI1_SS1,
86 MX35_PAD_CSPI1_SCLK__CSPI1_SCLK,
87 };
88
89 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babiceae49882011-01-20 08:05:15 +000090}
91
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000092#define USBOTG_IN_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | \
93 PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
94#define USBOTG_OUT_PAD_CTRL (PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
95
Benoît Thébaudeau961a7622012-11-13 09:58:25 +000096static void setup_iomux_usbotg(void)
97{
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +000098 static const iomux_v3_cfg_t usbotg_pads[] = {
99 NEW_PAD_CTRL(MX35_PAD_USBOTG_PWR__USB_TOP_USBOTG_PWR,
100 USBOTG_OUT_PAD_CTRL),
101 NEW_PAD_CTRL(MX35_PAD_USBOTG_OC__USB_TOP_USBOTG_OC,
102 USBOTG_IN_PAD_CTRL),
103 };
Benoît Thébaudeau961a7622012-11-13 09:58:25 +0000104
105 /* Set up pins for USBOTG. */
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000106 imx_iomux_v3_setup_multiple_pads(usbotg_pads, ARRAY_SIZE(usbotg_pads));
Benoît Thébaudeau961a7622012-11-13 09:58:25 +0000107}
108
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000109#define FEC_PAD_CTRL (PAD_CTL_DSE_LOW | PAD_CTL_SRE_SLOW)
110
Stefano Babiceae49882011-01-20 08:05:15 +0000111static void setup_iomux_fec(void)
112{
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000113 static const iomux_v3_cfg_t fec_pads[] = {
114 NEW_PAD_CTRL(MX35_PAD_FEC_TX_CLK__FEC_TX_CLK, FEC_PAD_CTRL |
115 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
116 NEW_PAD_CTRL(MX35_PAD_FEC_RX_CLK__FEC_RX_CLK, FEC_PAD_CTRL |
117 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
118 NEW_PAD_CTRL(MX35_PAD_FEC_RX_DV__FEC_RX_DV, FEC_PAD_CTRL |
119 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
120 NEW_PAD_CTRL(MX35_PAD_FEC_COL__FEC_COL, FEC_PAD_CTRL |
121 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
122 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA0__FEC_RDATA_0, FEC_PAD_CTRL |
123 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
124 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA0__FEC_TDATA_0, FEC_PAD_CTRL),
125 NEW_PAD_CTRL(MX35_PAD_FEC_TX_EN__FEC_TX_EN, FEC_PAD_CTRL),
126 NEW_PAD_CTRL(MX35_PAD_FEC_MDC__FEC_MDC, FEC_PAD_CTRL),
127 NEW_PAD_CTRL(MX35_PAD_FEC_MDIO__FEC_MDIO, FEC_PAD_CTRL |
128 PAD_CTL_HYS | PAD_CTL_PUS_22K_UP),
129 NEW_PAD_CTRL(MX35_PAD_FEC_TX_ERR__FEC_TX_ERR, FEC_PAD_CTRL),
130 NEW_PAD_CTRL(MX35_PAD_FEC_RX_ERR__FEC_RX_ERR, FEC_PAD_CTRL |
131 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
132 NEW_PAD_CTRL(MX35_PAD_FEC_CRS__FEC_CRS, FEC_PAD_CTRL |
133 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
134 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA1__FEC_RDATA_1, FEC_PAD_CTRL |
135 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
136 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA1__FEC_TDATA_1, FEC_PAD_CTRL),
137 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA2__FEC_RDATA_2, FEC_PAD_CTRL |
138 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
139 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA2__FEC_TDATA_2, FEC_PAD_CTRL),
140 NEW_PAD_CTRL(MX35_PAD_FEC_RDATA3__FEC_RDATA_3, FEC_PAD_CTRL |
141 PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN),
142 NEW_PAD_CTRL(MX35_PAD_FEC_TDATA3__FEC_TDATA_3, FEC_PAD_CTRL),
143 };
Stefano Babiceae49882011-01-20 08:05:15 +0000144
145 /* setup pins for FEC */
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000146 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Stefano Babiceae49882011-01-20 08:05:15 +0000147}
148
149int board_early_init_f(void)
150{
151 struct ccm_regs *ccm =
152 (struct ccm_regs *)IMX_CCM_BASE;
153
154 /* enable clocks */
155 writel(readl(&ccm->cgr0) |
156 MXC_CCM_CGR0_EMI_MASK |
Benoît Thébaudeau34a31bf2012-08-14 03:28:24 +0000157 MXC_CCM_CGR0_EDIO_MASK |
Stefano Babiceae49882011-01-20 08:05:15 +0000158 MXC_CCM_CGR0_EPIT1_MASK,
159 &ccm->cgr0);
160
161 writel(readl(&ccm->cgr1) |
162 MXC_CCM_CGR1_FEC_MASK |
163 MXC_CCM_CGR1_GPIO1_MASK |
164 MXC_CCM_CGR1_GPIO2_MASK |
165 MXC_CCM_CGR1_GPIO3_MASK |
166 MXC_CCM_CGR1_I2C1_MASK |
167 MXC_CCM_CGR1_I2C2_MASK |
168 MXC_CCM_CGR1_IPU_MASK,
169 &ccm->cgr1);
170
171 /* Setup NAND */
172 __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
173
174 setup_iomux_i2c();
Benoît Thébaudeau961a7622012-11-13 09:58:25 +0000175 setup_iomux_usbotg();
Stefano Babiceae49882011-01-20 08:05:15 +0000176 setup_iomux_fec();
177 setup_iomux_spi();
178
179 return 0;
180}
181
182int board_init(void)
183{
184 gd->bd->bi_arch_number = MACH_TYPE_MX35_3DS; /* board id for linux */
185 /* address of boot parameters */
186 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
187
188 return 0;
189}
190
191static inline int pmic_detect(void)
192{
Stefano Babic5213d6e2011-10-06 21:07:42 +0200193 unsigned int id;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000194 struct pmic *p = pmic_get("FSL_PMIC");
195 if (!p)
196 return -ENODEV;
Stefano Babiceae49882011-01-20 08:05:15 +0000197
Stefano Babic5213d6e2011-10-06 21:07:42 +0200198 pmic_reg_read(p, REG_IDENTIFICATION, &id);
Stefano Babiceae49882011-01-20 08:05:15 +0000199
200 id = (id >> 6) & 0x7;
201 if (id == 0x7)
202 return 1;
203 return 0;
204}
205
206u32 get_board_rev(void)
207{
208 int rev;
209
210 rev = pmic_detect();
211
212 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
213}
214
215int board_late_init(void)
216{
217 u8 val;
218 u32 pmic_val;
Stefano Babic5213d6e2011-10-06 21:07:42 +0200219 struct pmic *p;
Łukasz Majewskic7336812012-11-13 03:21:55 +0000220 int ret;
Stefano Babiceae49882011-01-20 08:05:15 +0000221
Fabio Estevam570aa2f2013-11-20 21:17:36 -0200222 ret = pmic_init(I2C_0);
Łukasz Majewskic7336812012-11-13 03:21:55 +0000223 if (ret)
224 return ret;
225
Stefano Babiceae49882011-01-20 08:05:15 +0000226 if (pmic_detect()) {
Łukasz Majewskic7336812012-11-13 03:21:55 +0000227 p = pmic_get("FSL_PMIC");
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000228 imx_iomux_v3_setup_pad(MX35_PAD_WDOG_RST__WDOG_WDOG_B);
Stefano Babiceae49882011-01-20 08:05:15 +0000229
Stefano Babic5213d6e2011-10-06 21:07:42 +0200230 pmic_reg_read(p, REG_SETTING_0, &pmic_val);
231 pmic_reg_write(p, REG_SETTING_0,
232 pmic_val | VO_1_30V | VO_1_50V);
233 pmic_reg_read(p, REG_MODE_0, &pmic_val);
234 pmic_reg_write(p, REG_MODE_0, pmic_val | VGEN3EN);
Stefano Babiceae49882011-01-20 08:05:15 +0000235
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000236 imx_iomux_v3_setup_pad(MX35_PAD_COMPARE__GPIO1_5);
Stefano Babiceae49882011-01-20 08:05:15 +0000237
Benoît Thébaudeau68088ce2013-05-06 01:33:51 +0000238 gpio_direction_output(IMX_GPIO_NR(1, 5), 1);
Stefano Babiceae49882011-01-20 08:05:15 +0000239 }
240
241 val = mc9sdz60_reg_read(MC9SDZ60_REG_GPIO_1) | 0x04;
242 mc9sdz60_reg_write(MC9SDZ60_REG_GPIO_1, val);
243 mdelay(200);
244
245 val = mc9sdz60_reg_read(MC9SDZ60_REG_RESET_1) & 0x7F;
246 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
247 mdelay(200);
248
249 val |= 0x80;
250 mc9sdz60_reg_write(MC9SDZ60_REG_RESET_1, val);
251
Stefano Babiceae49882011-01-20 08:05:15 +0000252 /* Print board revision */
Fabio Estevamba901df2012-02-10 06:29:15 +0000253 printf("Board: MX35 PDK %d.0\n", ((get_board_rev() >> 8) + 1) & 0x0F);
Stefano Babiceae49882011-01-20 08:05:15 +0000254
255 return 0;
256}
257
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900258int board_eth_init(struct bd_info *bis)
Stefano Babiceae49882011-01-20 08:05:15 +0000259{
Stefano Babiceae49882011-01-20 08:05:15 +0000260#if defined(CONFIG_SMC911X)
Fabio Estevama05f4ab2013-09-20 16:30:50 -0300261 int rc = smc911x_initialize(0, CONFIG_SMC911X_BASE);
262 if (rc)
263 return rc;
Stefano Babiceae49882011-01-20 08:05:15 +0000264#endif
Fabio Estevama05f4ab2013-09-20 16:30:50 -0300265 return cpu_eth_init(bis);
Stefano Babiceae49882011-01-20 08:05:15 +0000266}
Stefano Babic32925392012-09-05 21:47:42 +0000267
Yangbo Lue37ac712019-06-21 11:42:28 +0800268#if defined(CONFIG_FSL_ESDHC_IMX)
Stefano Babic32925392012-09-05 21:47:42 +0000269
270struct fsl_esdhc_cfg esdhc_cfg = {MMC_SDHC1_BASE_ADDR};
271
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900272int board_mmc_init(struct bd_info *bis)
Stefano Babic32925392012-09-05 21:47:42 +0000273{
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000274 static const iomux_v3_cfg_t sdhc1_pads[] = {
275 MX35_PAD_SD1_CMD__ESDHC1_CMD,
276 MX35_PAD_SD1_CLK__ESDHC1_CLK,
277 MX35_PAD_SD1_DATA0__ESDHC1_DAT0,
278 MX35_PAD_SD1_DATA1__ESDHC1_DAT1,
279 MX35_PAD_SD1_DATA2__ESDHC1_DAT2,
280 MX35_PAD_SD1_DATA3__ESDHC1_DAT3,
281 };
282
Stefano Babic32925392012-09-05 21:47:42 +0000283 /* configure pins for SDHC1 only */
Benoît Thébaudeau105c9ea2013-05-03 10:32:22 +0000284 imx_iomux_v3_setup_multiple_pads(sdhc1_pads, ARRAY_SIZE(sdhc1_pads));
Stefano Babic32925392012-09-05 21:47:42 +0000285
Benoît Thébaudeaua2ac1b32012-10-01 08:36:25 +0000286 esdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
Stefano Babic32925392012-09-05 21:47:42 +0000287 return fsl_esdhc_initialize(bis, &esdhc_cfg);
288}
289
290int board_mmc_getcd(struct mmc *mmc)
291{
292 return !(mc9sdz60_reg_read(MC9SDZ60_REG_DES_FLAG) & 0x4);
293}
294#endif