blob: 12c5ac331f9729a3b2d6f6e19f5cac0c08cfee79 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babicdeb53482011-10-23 23:58:20 +00002/*
3 * Copyright (C) 2007, Guennadi Liakhovetski <lg@denx.de>
4 *
5 * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
6 *
7 * Copyright (C) 2011, Stefano Babic <sbabic@denx.de>
Stefano Babicdeb53482011-10-23 23:58:20 +00008 */
9
10#include <common.h>
Simon Glass9b4a2052019-12-28 10:45:05 -070011#include <init.h>
Simon Glass401d1c42020-10-30 21:38:53 -060012#include <asm/global_data.h>
Stefano Babicdeb53482011-10-23 23:58:20 +000013#include <asm/io.h>
Simon Glass7b51b572019-08-01 09:46:52 -060014#include <env.h>
Simon Glassc05ed002020-05-10 11:40:11 -060015#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090016#include <linux/errno.h>
Stefano Babicdeb53482011-10-23 23:58:20 +000017#include <asm/arch/imx-regs.h>
18#include <asm/arch/crm_regs.h>
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000019#include <asm/arch/iomux-mx35.h>
Stefano Babicdeb53482011-10-23 23:58:20 +000020#include <i2c.h>
21#include <linux/types.h>
22#include <asm/gpio.h>
23#include <asm/arch/sys_proto.h>
24#include <netdev.h>
Heiko Schocher72c10152016-10-17 15:51:32 +020025#include <fdt_support.h>
26#include <mtd_node.h>
27#include <jffs2/load_kernel.h>
Stefano Babicdeb53482011-10-23 23:58:20 +000028
29#ifndef CONFIG_BOARD_EARLY_INIT_F
30#error "CONFIG_BOARD_EARLY_INIT_F must be set for this board"
31#endif
32
33#define CCM_CCMR_CONFIG 0x003F4208
34
35#define ESDCTL_DDR2_CONFIG 0x007FFC3F
Stefano Babicdeb53482011-10-23 23:58:20 +000036
37static inline void dram_wait(unsigned int count)
38{
39 volatile unsigned int wait = count;
40
41 while (wait--)
42 ;
43}
44
45DECLARE_GLOBAL_DATA_PTR;
46
47int dram_init(void)
48{
49 gd->ram_size = get_ram_size((long *)PHYS_SDRAM_1,
50 PHYS_SDRAM_1_SIZE);
51
52 return 0;
53}
54
Stefano Babicdeb53482011-10-23 23:58:20 +000055static void board_setup_sdram(void)
56{
57 struct esdc_regs *esdc = (struct esdc_regs *)ESDCTL_BASE_ADDR;
58
59 /* Initialize with default values both CSD0/1 */
60 writel(0x2000, &esdc->esdctl0);
61 writel(0x2000, &esdc->esdctl1);
62
Stefano Babic146fff32016-10-17 15:51:33 +020063
64 mx3_setup_sdram_bank(CSD0_BASE_ADDR, ESDCTL_DDR2_CONFIG,
65 13, 10, 2, 0x8080);
Stefano Babicdeb53482011-10-23 23:58:20 +000066}
67
68static void setup_iomux_uart3(void)
69{
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000070 static const iomux_v3_cfg_t uart3_pads[] = {
71 MX35_PAD_RTS2__UART3_RXD_MUX,
72 MX35_PAD_CTS2__UART3_TXD_MUX,
73 };
74
75 imx_iomux_v3_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads));
Stefano Babicdeb53482011-10-23 23:58:20 +000076}
77
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000078#define I2C_PAD_CTRL (PAD_CTL_HYS | PAD_CTL_PUS_100K_DOWN | PAD_CTL_ODE)
79
Stefano Babicdeb53482011-10-23 23:58:20 +000080static void setup_iomux_i2c(void)
81{
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000082 static const iomux_v3_cfg_t i2c_pads[] = {
83 NEW_PAD_CTRL(MX35_PAD_I2C1_CLK__I2C1_SCL, I2C_PAD_CTRL),
84 NEW_PAD_CTRL(MX35_PAD_I2C1_DAT__I2C1_SDA, I2C_PAD_CTRL),
Stefano Babicdeb53482011-10-23 23:58:20 +000085
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000086 NEW_PAD_CTRL(MX35_PAD_TX3_RX2__I2C3_SCL, I2C_PAD_CTRL),
87 NEW_PAD_CTRL(MX35_PAD_TX2_RX3__I2C3_SDA, I2C_PAD_CTRL),
88 };
Stefano Babicdeb53482011-10-23 23:58:20 +000089
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000090 imx_iomux_v3_setup_multiple_pads(i2c_pads, ARRAY_SIZE(i2c_pads));
Stefano Babicdeb53482011-10-23 23:58:20 +000091}
92
93
94static void setup_iomux_spi(void)
95{
Benoît Thébaudeau686e1442013-05-03 10:32:20 +000096 static const iomux_v3_cfg_t spi_pads[] = {
97 MX35_PAD_CSPI1_MOSI__CSPI1_MOSI,
98 MX35_PAD_CSPI1_MISO__CSPI1_MISO,
99 MX35_PAD_CSPI1_SS0__CSPI1_SS0,
100 MX35_PAD_CSPI1_SS1__CSPI1_SS1,
101 MX35_PAD_CSPI1_SCLK__CSPI1_SCLK,
102 };
103
104 imx_iomux_v3_setup_multiple_pads(spi_pads, ARRAY_SIZE(spi_pads));
Stefano Babicdeb53482011-10-23 23:58:20 +0000105}
106
107static void setup_iomux_fec(void)
108{
Benoît Thébaudeau686e1442013-05-03 10:32:20 +0000109 static const iomux_v3_cfg_t fec_pads[] = {
110 MX35_PAD_FEC_TX_CLK__FEC_TX_CLK,
111 MX35_PAD_FEC_RX_CLK__FEC_RX_CLK,
112 MX35_PAD_FEC_RX_DV__FEC_RX_DV,
113 MX35_PAD_FEC_COL__FEC_COL,
114 MX35_PAD_FEC_RDATA0__FEC_RDATA_0,
115 MX35_PAD_FEC_TDATA0__FEC_TDATA_0,
116 MX35_PAD_FEC_TX_EN__FEC_TX_EN,
117 MX35_PAD_FEC_MDC__FEC_MDC,
118 MX35_PAD_FEC_MDIO__FEC_MDIO,
119 MX35_PAD_FEC_TX_ERR__FEC_TX_ERR,
120 MX35_PAD_FEC_RX_ERR__FEC_RX_ERR,
121 MX35_PAD_FEC_CRS__FEC_CRS,
122 MX35_PAD_FEC_RDATA1__FEC_RDATA_1,
123 MX35_PAD_FEC_TDATA1__FEC_TDATA_1,
124 MX35_PAD_FEC_RDATA2__FEC_RDATA_2,
125 MX35_PAD_FEC_TDATA2__FEC_TDATA_2,
126 MX35_PAD_FEC_RDATA3__FEC_RDATA_3,
127 MX35_PAD_FEC_TDATA3__FEC_TDATA_3,
Stefano Babic322ac5f2016-10-17 15:51:34 +0200128 /* GPIO used to power off ethernet */
129 MX35_PAD_STXFS4__GPIO2_31,
Benoît Thébaudeau686e1442013-05-03 10:32:20 +0000130 };
Stefano Babicdeb53482011-10-23 23:58:20 +0000131
Benoît Thébaudeau686e1442013-05-03 10:32:20 +0000132 /* setup pins for FEC */
133 imx_iomux_v3_setup_multiple_pads(fec_pads, ARRAY_SIZE(fec_pads));
Stefano Babicdeb53482011-10-23 23:58:20 +0000134}
135
136int board_early_init_f(void)
137{
138 struct ccm_regs *ccm =
139 (struct ccm_regs *)IMX_CCM_BASE;
140
141 /* setup GPIO3_1 to set HighVCore signal */
Benoît Thébaudeau686e1442013-05-03 10:32:20 +0000142 imx_iomux_v3_setup_pad(MX35_PAD_ATA_DA1__GPIO3_1);
Stefano Babicdeb53482011-10-23 23:58:20 +0000143 gpio_direction_output(65, 1);
144
145 /* initialize PLL and clock configuration */
146 writel(CCM_CCMR_CONFIG, &ccm->ccmr);
147
148 writel(CCM_MPLL_532_HZ, &ccm->mpctl);
149 writel(CCM_PPLL_300_HZ, &ccm->ppctl);
150
151 /* Set the core to run at 532 Mhz */
152 writel(0x00001000, &ccm->pdr0);
153
154 /* Set-up RAM */
155 board_setup_sdram();
156
157 /* enable clocks */
158 writel(readl(&ccm->cgr0) |
159 MXC_CCM_CGR0_EMI_MASK |
Benoît Thébaudeau34a31bf2012-08-14 03:28:24 +0000160 MXC_CCM_CGR0_EDIO_MASK |
Stefano Babicdeb53482011-10-23 23:58:20 +0000161 MXC_CCM_CGR0_EPIT1_MASK,
162 &ccm->cgr0);
163
164 writel(readl(&ccm->cgr1) |
165 MXC_CCM_CGR1_FEC_MASK |
166 MXC_CCM_CGR1_GPIO1_MASK |
167 MXC_CCM_CGR1_GPIO2_MASK |
168 MXC_CCM_CGR1_GPIO3_MASK |
169 MXC_CCM_CGR1_I2C1_MASK |
170 MXC_CCM_CGR1_I2C2_MASK |
171 MXC_CCM_CGR1_I2C3_MASK,
172 &ccm->cgr1);
173
174 /* Set-up NAND */
175 __raw_writel(readl(&ccm->rcsr) | MXC_CCM_RCSR_NFC_FMS, &ccm->rcsr);
176
177 /* Set pinmux for the required peripherals */
178 setup_iomux_uart3();
179 setup_iomux_i2c();
180 setup_iomux_fec();
181 setup_iomux_spi();
182
183 return 0;
184}
185
186int board_init(void)
187{
188 /* address of boot parameters */
189 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
190
Stefano Babic322ac5f2016-10-17 15:51:34 +0200191 /* Enable power for ethernet */
192 gpio_direction_output(63, 0);
193
194 udelay(2000);
195
Stefano Babicdeb53482011-10-23 23:58:20 +0000196 return 0;
197}
198
199u32 get_board_rev(void)
200{
201 int rev = 0;
202
203 return (get_cpu_rev() & ~(0xF << 8)) | (rev & 0xF) << 8;
204}
Heiko Schocher72c10152016-10-17 15:51:32 +0200205
206/*
207 * called prior to booting kernel or by 'fdt boardsetup' command
208 *
209 */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900210int ft_board_setup(void *blob, struct bd_info *bd)
Heiko Schocher72c10152016-10-17 15:51:32 +0200211{
Masahiro Yamadab35fb6a2018-07-19 16:28:23 +0900212 static const struct node_info nodes[] = {
Heiko Schocher72c10152016-10-17 15:51:32 +0200213 { "physmap-flash.0", MTD_DEV_TYPE_NOR, }, /* NOR flash */
214 { "mxc_nand", MTD_DEV_TYPE_NAND, }, /* NAND flash */
215 };
216
Simon Glass00caae62017-08-03 12:22:12 -0600217 if (env_get("fdt_noauto")) {
Heiko Schocher72c10152016-10-17 15:51:32 +0200218 puts(" Skiping ft_board_setup (fdt_noauto defined)\n");
219 return 0;
220 }
221
222 fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes));
223
224 return 0;
225}