blob: bdc7769d9e35208ddfcb25dd93fe4139f93ee44d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Max Krummenachereeb16b22016-11-30 19:43:09 +01002/*
3 * Copyright (C) 2010-2013 Freescale Semiconductor, Inc.
4 * Copyright (C) 2013, Boundary Devices <info@boundarydevices.com>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +01005 * Copyright (C) 2014-2019, Toradex AG
Max Krummenachereeb16b22016-11-30 19:43:09 +01006 * copied from nitrogen6x
Max Krummenachereeb16b22016-11-30 19:43:09 +01007 */
8
9#include <common.h>
Simon Glass11c89f32017-05-17 17:18:03 -060010#include <dm.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010011
Max Krummenachereeb16b22016-11-30 19:43:09 +010012#include <asm/arch/clock.h>
13#include <asm/arch/crm_regs.h>
14#include <asm/arch/imx-regs.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010015#include <asm/arch/mx6-ddr.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010016#include <asm/arch/mx6-pins.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010017#include <asm/arch/mxc_hdmi.h>
18#include <asm/arch/sys_proto.h>
19#include <asm/bootm.h>
20#include <asm/gpio.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010021#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020022#include <asm/mach-imx/iomux-v3.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020023#include <asm/mach-imx/sata.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020024#include <asm/mach-imx/video.h>
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +010025#include <cpu.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010026#include <dm/platform_data/serial_mxc.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010027#include <environment.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010028#include <fsl_esdhc.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010029#include <imx_thermal.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010030#include <micrel.h>
31#include <miiphy.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010032#include <netdev.h>
33
34#include "../common/tdx-cfg-block.h"
35#ifdef CONFIG_TDX_CMD_IMX_MFGR
36#include "pf0100.h"
37#endif
38
39DECLARE_GLOBAL_DATA_PTR;
40
41#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
42 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
43 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
44
45#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
Max Krummenachera0f4d792019-02-08 18:42:19 +010046 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_40ohm | \
47 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
48
49#define USDHC_EMMC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
Max Krummenachereeb16b22016-11-30 19:43:09 +010050 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
51 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
52
53#define ENET_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
54 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS)
55
Max Krummenachereeb16b22016-11-30 19:43:09 +010056#define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \
57 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
58 PAD_CTL_SRE_SLOW)
59
60#define NO_PULLUP ( \
61 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
62 PAD_CTL_SRE_SLOW)
63
64#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
65 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
66 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
67
Max Krummenachereeb16b22016-11-30 19:43:09 +010068#define OUTPUT_RGB (PAD_CTL_SPEED_MED|PAD_CTL_DSE_60ohm|PAD_CTL_SRE_FAST)
69
70int dram_init(void)
71{
72 /* use the DDR controllers configured size */
73 gd->ram_size = get_ram_size((void *)CONFIG_SYS_SDRAM_BASE,
74 (ulong)imx_ddr_size());
75
76 return 0;
77}
78
79/* Colibri UARTA */
80iomux_v3_cfg_t const uart1_pads[] = {
81 MX6_PAD_CSI0_DAT10__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
82 MX6_PAD_CSI0_DAT11__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
83};
84
Marcel Ziswiler8871aba2019-02-08 18:42:14 +010085#if defined(CONFIG_FSL_ESDHC) && defined(CONFIG_SPL_BUILD)
Marcel Ziswilerc882cfb2019-02-08 18:42:12 +010086/* Colibri MMC */
Max Krummenachereeb16b22016-11-30 19:43:09 +010087iomux_v3_cfg_t const usdhc1_pads[] = {
88 MX6_PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
89 MX6_PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
90 MX6_PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
91 MX6_PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
92 MX6_PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93 MX6_PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
95# define GPIO_MMC_CD IMX_GPIO_NR(2, 5)
96};
97
98/* eMMC */
99iomux_v3_cfg_t const usdhc3_pads[] = {
Max Krummenachera0f4d792019-02-08 18:42:19 +0100100 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
101 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
102 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
103 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
104 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
105 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
106 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
107 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
108 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
109 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
Max Krummenachereeb16b22016-11-30 19:43:09 +0100110 MX6_PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL),
111};
Marcel Ziswiler8871aba2019-02-08 18:42:14 +0100112#endif /* CONFIG_FSL_ESDHC & CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100113
114iomux_v3_cfg_t const enet_pads[] = {
115 MX6_PAD_ENET_MDC__ENET_MDC | MUX_PAD_CTRL(ENET_PAD_CTRL),
116 MX6_PAD_ENET_MDIO__ENET_MDIO | MUX_PAD_CTRL(ENET_PAD_CTRL),
117 MX6_PAD_ENET_RXD0__ENET_RX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
118 MX6_PAD_ENET_RXD1__ENET_RX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
119 MX6_PAD_ENET_RX_ER__ENET_RX_ER | MUX_PAD_CTRL(ENET_PAD_CTRL),
120 MX6_PAD_ENET_TX_EN__ENET_TX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
121 MX6_PAD_ENET_TXD0__ENET_TX_DATA0 | MUX_PAD_CTRL(ENET_PAD_CTRL),
122 MX6_PAD_ENET_TXD1__ENET_TX_DATA1 | MUX_PAD_CTRL(ENET_PAD_CTRL),
123 MX6_PAD_ENET_CRS_DV__ENET_RX_EN | MUX_PAD_CTRL(ENET_PAD_CTRL),
124 MX6_PAD_GPIO_16__ENET_REF_CLK | MUX_PAD_CTRL(ENET_PAD_CTRL),
125};
126
127static void setup_iomux_enet(void)
128{
129 imx_iomux_v3_setup_multiple_pads(enet_pads, ARRAY_SIZE(enet_pads));
130}
131
132/* mux auxiliary pins to GPIO, so they can be used from the U-Boot cmdline */
133iomux_v3_cfg_t const gpio_pads[] = {
134 /* ADDRESS[17:18] [25] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100135 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
136 MUX_MODE_SION,
137 MX6_PAD_KEY_COL2__GPIO4_IO10 | MUX_PAD_CTRL(WEAK_PULLUP) |
138 MUX_MODE_SION,
139 MX6_PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(WEAK_PULLUP) |
140 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100141 /* ADDRESS[19:24] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100142 MX6_PAD_DISP0_DAT23__GPIO5_IO17 | MUX_PAD_CTRL(WEAK_PULLUP) |
143 MUX_MODE_SION,
144 MX6_PAD_DISP0_DAT22__GPIO5_IO16 | MUX_PAD_CTRL(WEAK_PULLUP) |
145 MUX_MODE_SION,
146 MX6_PAD_DISP0_DAT21__GPIO5_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
147 MUX_MODE_SION,
148 MX6_PAD_DISP0_DAT20__GPIO5_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
149 MUX_MODE_SION,
150 MX6_PAD_DISP0_DAT19__GPIO5_IO13 | MUX_PAD_CTRL(WEAK_PULLUP) |
151 MUX_MODE_SION,
152 MX6_PAD_DISP0_DAT18__GPIO5_IO12 | MUX_PAD_CTRL(WEAK_PULLUP) |
153 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100154 /* DATA[16:29] [31] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100155 MX6_PAD_EIM_LBA__GPIO2_IO27 | MUX_PAD_CTRL(WEAK_PULLUP) |
156 MUX_MODE_SION,
157 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(WEAK_PULLUP) |
158 MUX_MODE_SION,
159 MX6_PAD_NANDF_CS3__GPIO6_IO16 | MUX_PAD_CTRL(WEAK_PULLUP) |
160 MUX_MODE_SION,
161 MX6_PAD_NANDF_CS1__GPIO6_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
162 MUX_MODE_SION,
163 MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(WEAK_PULLUP) |
164 MUX_MODE_SION,
165 MX6_PAD_NANDF_ALE__GPIO6_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
166 MUX_MODE_SION,
167 MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(WEAK_PULLUP) |
168 MUX_MODE_SION,
169 MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
170 MUX_MODE_SION,
171 MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(WEAK_PULLUP) |
172 MUX_MODE_SION,
173 MX6_PAD_GPIO_19__GPIO4_IO05 | MUX_PAD_CTRL(WEAK_PULLUP) |
174 MUX_MODE_SION,
175 MX6_PAD_CSI0_MCLK__GPIO5_IO19 | MUX_PAD_CTRL(WEAK_PULLUP) |
176 MUX_MODE_SION,
177 MX6_PAD_CSI0_PIXCLK__GPIO5_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
178 MUX_MODE_SION,
179 MX6_PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
180 MUX_MODE_SION,
181 MX6_PAD_GPIO_5__GPIO1_IO05 | MUX_PAD_CTRL(WEAK_PULLUP) |
182 MUX_MODE_SION,
183 MX6_PAD_GPIO_2__GPIO1_IO02 | MUX_PAD_CTRL(WEAK_PULLUP) |
184 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100185 /* DQM[0:3] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100186 MX6_PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(WEAK_PULLUP) |
187 MUX_MODE_SION,
188 MX6_PAD_EIM_EB1__GPIO2_IO29 | MUX_PAD_CTRL(WEAK_PULLUP) |
189 MUX_MODE_SION,
190 MX6_PAD_SD2_DAT2__GPIO1_IO13 | MUX_PAD_CTRL(WEAK_PULLUP) |
191 MUX_MODE_SION,
192 MX6_PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(WEAK_PULLUP) |
193 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100194 /* RDY used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100195 MX6_PAD_EIM_WAIT__GPIO5_IO00 | MUX_PAD_CTRL(WEAK_PULLUP) |
196 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100197 /* ADDRESS[16] DATA[30] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100198 MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(WEAK_PULLDOWN) |
199 MUX_MODE_SION,
200 MX6_PAD_KEY_COL4__GPIO4_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
201 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100202 /* CSI pins used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100203 MX6_PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
204 MUX_MODE_SION,
205 MX6_PAD_SD2_CMD__GPIO1_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
206 MUX_MODE_SION,
207 MX6_PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
208 MUX_MODE_SION,
209 MX6_PAD_EIM_D18__GPIO3_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
210 MUX_MODE_SION,
211 MX6_PAD_EIM_A19__GPIO2_IO19 | MUX_PAD_CTRL(WEAK_PULLUP) |
212 MUX_MODE_SION,
213 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(WEAK_PULLDOWN) |
214 MUX_MODE_SION,
215 MX6_PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) |
216 MUX_MODE_SION,
217 MX6_PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
218 MUX_MODE_SION,
219 MX6_PAD_EIM_A17__GPIO2_IO21 | MUX_PAD_CTRL(WEAK_PULLUP) |
220 MUX_MODE_SION,
221 MX6_PAD_EIM_A18__GPIO2_IO20 | MUX_PAD_CTRL(WEAK_PULLUP) |
222 MUX_MODE_SION,
223 MX6_PAD_EIM_EB3__GPIO2_IO31 | MUX_PAD_CTRL(WEAK_PULLUP) |
224 MUX_MODE_SION,
225 MX6_PAD_EIM_D17__GPIO3_IO17 | MUX_PAD_CTRL(WEAK_PULLUP) |
226 MUX_MODE_SION,
227 MX6_PAD_SD2_DAT0__GPIO1_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
228 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100229 /* GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100230 MX6_PAD_EIM_D26__GPIO3_IO26 | MUX_PAD_CTRL(WEAK_PULLUP) |
231 MUX_MODE_SION,
232 MX6_PAD_EIM_D27__GPIO3_IO27 | MUX_PAD_CTRL(WEAK_PULLUP) |
233 MUX_MODE_SION,
234 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) |
235 MUX_MODE_SION,
236 MX6_PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(WEAK_PULLUP) |
237 MUX_MODE_SION,
238 MX6_PAD_ENET_REF_CLK__GPIO1_IO23 | MUX_PAD_CTRL(WEAK_PULLUP) |
239 MUX_MODE_SION,
240 MX6_PAD_DI0_PIN4__GPIO4_IO20 | MUX_PAD_CTRL(WEAK_PULLUP) |
241 MUX_MODE_SION,
242 MX6_PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
243 MUX_MODE_SION,
244 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
245 MUX_MODE_SION,
246 MX6_PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
247 MUX_MODE_SION,
248 MX6_PAD_GPIO_7__GPIO1_IO07 | MUX_PAD_CTRL(WEAK_PULLUP) |
249 MUX_MODE_SION,
250 MX6_PAD_GPIO_8__GPIO1_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
251 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100252 /* USBH_OC */
253 MX6_PAD_EIM_D30__GPIO3_IO30 | MUX_PAD_CTRL(WEAK_PULLUP),
254 /* USBC_ID */
255 MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(WEAK_PULLUP),
256 /* USBC_DET */
257 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(WEAK_PULLUP),
258};
259
260static void setup_iomux_gpio(void)
261{
262 imx_iomux_v3_setup_multiple_pads(gpio_pads, ARRAY_SIZE(gpio_pads));
263}
264
265iomux_v3_cfg_t const usb_pads[] = {
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100266 /* USBH_PEN */
267 MX6_PAD_EIM_D31__GPIO3_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100268# define GPIO_USBH_EN IMX_GPIO_NR(3, 31)
269};
270
271/*
272 * UARTs are used in DTE mode, switch the mode on all UARTs before
273 * any pinmuxing connects a (DCE) output to a transceiver output.
274 */
Max Krummenacher003bc132019-02-08 18:42:21 +0100275#define UCR3 0x88 /* FIFO Control Register */
276#define UCR3_RI BIT(8) /* RIDELT DTE mode */
277#define UCR3_DCD BIT(9) /* DCDDELT DTE mode */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100278#define UFCR 0x90 /* FIFO Control Register */
Max Krummenacher003bc132019-02-08 18:42:21 +0100279#define UFCR_DCEDTE BIT(6) /* DCE=0 */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100280
281static void setup_dtemode_uart(void)
282{
283 setbits_le32((u32 *)(UART1_BASE + UFCR), UFCR_DCEDTE);
284 setbits_le32((u32 *)(UART2_BASE + UFCR), UFCR_DCEDTE);
285 setbits_le32((u32 *)(UART3_BASE + UFCR), UFCR_DCEDTE);
Max Krummenacher003bc132019-02-08 18:42:21 +0100286
287 clrbits_le32((u32 *)(UART1_BASE + UCR3), UCR3_DCD | UCR3_RI);
288 clrbits_le32((u32 *)(UART2_BASE + UCR3), UCR3_DCD | UCR3_RI);
289 clrbits_le32((u32 *)(UART3_BASE + UCR3), UCR3_DCD | UCR3_RI);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100290}
291
292static void setup_iomux_uart(void)
293{
294 setup_dtemode_uart();
295 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
296}
297
298#ifdef CONFIG_USB_EHCI_MX6
299int board_ehci_hcd_init(int port)
300{
301 imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads));
302 return 0;
303}
Marcel Ziswilerf2839442019-02-08 18:42:15 +0100304#endif
Max Krummenachereeb16b22016-11-30 19:43:09 +0100305
Marcel Ziswiler8871aba2019-02-08 18:42:14 +0100306#if defined(CONFIG_FSL_ESDHC) && defined(CONFIG_SPL_BUILD)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100307/* use the following sequence: eMMC, MMC */
308struct fsl_esdhc_cfg usdhc_cfg[CONFIG_SYS_FSL_USDHC_NUM] = {
309 {USDHC3_BASE_ADDR},
310 {USDHC1_BASE_ADDR},
311};
312
313int board_mmc_getcd(struct mmc *mmc)
314{
315 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
316 int ret = true; /* default: assume inserted */
317
318 switch (cfg->esdhc_base) {
319 case USDHC1_BASE_ADDR:
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100320 gpio_request(GPIO_MMC_CD, "MMC_CD");
Max Krummenachereeb16b22016-11-30 19:43:09 +0100321 gpio_direction_input(GPIO_MMC_CD);
322 ret = !gpio_get_value(GPIO_MMC_CD);
323 break;
324 }
325
326 return ret;
327}
328
329int board_mmc_init(bd_t *bis)
330{
Max Krummenachereeb16b22016-11-30 19:43:09 +0100331 struct src *psrc = (struct src *)SRC_BASE_ADDR;
332 unsigned reg = readl(&psrc->sbmr1) >> 11;
333 /*
334 * Upon reading BOOT_CFG register the following map is done:
335 * Bit 11 and 12 of BOOT_CFG register can determine the current
336 * mmc port
337 * 0x1 SD1
338 * 0x2 SD2
339 * 0x3 SD4
340 */
341
342 switch (reg & 0x3) {
343 case 0x0:
344 imx_iomux_v3_setup_multiple_pads(
345 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
346 usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
347 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
348 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
349 break;
350 case 0x2:
351 imx_iomux_v3_setup_multiple_pads(
352 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
353 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
354 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
355 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
356 break;
357 default:
358 puts("MMC boot device not available");
359 }
360
361 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100362}
Marcel Ziswiler8871aba2019-02-08 18:42:14 +0100363#endif /* CONFIG_FSL_ESDHC & CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100364
365int board_phy_config(struct phy_device *phydev)
366{
367 if (phydev->drv->config)
368 phydev->drv->config(phydev);
369
370 return 0;
371}
372
373int board_eth_init(bd_t *bis)
374{
375 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
376 uint32_t base = IMX_FEC_BASE;
377 struct mii_dev *bus = NULL;
378 struct phy_device *phydev = NULL;
379 int ret;
380
381 /* provide the PHY clock from the i.MX 6 */
382 ret = enable_fec_anatop_clock(0, ENET_50MHZ);
383 if (ret)
384 return ret;
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100385
Max Krummenachereeb16b22016-11-30 19:43:09 +0100386 /* set gpr1[ENET_CLK_SEL] */
387 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
388
389 setup_iomux_enet();
390
391#ifdef CONFIG_FEC_MXC
392 bus = fec_get_miibus(base, -1);
393 if (!bus)
394 return 0;
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100395
Max Krummenachereeb16b22016-11-30 19:43:09 +0100396 /* scan PHY 1..7 */
397 phydev = phy_find_by_mask(bus, 0xff, PHY_INTERFACE_MODE_RMII);
398 if (!phydev) {
399 free(bus);
400 puts("no PHY found\n");
401 return 0;
402 }
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100403
Max Krummenachereeb16b22016-11-30 19:43:09 +0100404 phy_reset(phydev);
405 printf("using PHY at %d\n", phydev->addr);
406 ret = fec_probe(bis, -1, base, bus, phydev);
407 if (ret) {
408 printf("FEC MXC: %s:failed\n", __func__);
409 free(phydev);
410 free(bus);
411 }
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100412#endif /* CONFIG_FEC_MXC */
413
Max Krummenachereeb16b22016-11-30 19:43:09 +0100414 return 0;
415}
416
417static iomux_v3_cfg_t const pwr_intb_pads[] = {
418 /*
419 * the bootrom sets the iomux to vselect, potentially connecting
420 * two outputs. Set this back to GPIO
421 */
422 MX6_PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)
423};
424
425#if defined(CONFIG_VIDEO_IPUV3)
426
427static iomux_v3_cfg_t const backlight_pads[] = {
428 /* Backlight On */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100429 MX6_PAD_EIM_D26__GPIO3_IO26 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100430#define RGB_BACKLIGHT_GP IMX_GPIO_NR(3, 26)
431 /* Backlight PWM, used as GPIO in U-Boot */
432 MX6_PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PULLUP),
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100433 MX6_PAD_SD4_DAT1__GPIO2_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL) |
434 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100435#define RGB_BACKLIGHTPWM_GP IMX_GPIO_NR(2, 9)
436};
437
438static iomux_v3_cfg_t const rgb_pads[] = {
439 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK | MUX_PAD_CTRL(OUTPUT_RGB),
440 MX6_PAD_DI0_PIN15__IPU1_DI0_PIN15 | MUX_PAD_CTRL(OUTPUT_RGB),
441 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN02 | MUX_PAD_CTRL(OUTPUT_RGB),
442 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN03 | MUX_PAD_CTRL(OUTPUT_RGB),
443 MX6_PAD_DISP0_DAT0__IPU1_DISP0_DATA00 | MUX_PAD_CTRL(OUTPUT_RGB),
444 MX6_PAD_DISP0_DAT1__IPU1_DISP0_DATA01 | MUX_PAD_CTRL(OUTPUT_RGB),
445 MX6_PAD_DISP0_DAT2__IPU1_DISP0_DATA02 | MUX_PAD_CTRL(OUTPUT_RGB),
446 MX6_PAD_DISP0_DAT3__IPU1_DISP0_DATA03 | MUX_PAD_CTRL(OUTPUT_RGB),
447 MX6_PAD_DISP0_DAT4__IPU1_DISP0_DATA04 | MUX_PAD_CTRL(OUTPUT_RGB),
448 MX6_PAD_DISP0_DAT5__IPU1_DISP0_DATA05 | MUX_PAD_CTRL(OUTPUT_RGB),
449 MX6_PAD_DISP0_DAT6__IPU1_DISP0_DATA06 | MUX_PAD_CTRL(OUTPUT_RGB),
450 MX6_PAD_DISP0_DAT7__IPU1_DISP0_DATA07 | MUX_PAD_CTRL(OUTPUT_RGB),
451 MX6_PAD_DISP0_DAT8__IPU1_DISP0_DATA08 | MUX_PAD_CTRL(OUTPUT_RGB),
452 MX6_PAD_DISP0_DAT9__IPU1_DISP0_DATA09 | MUX_PAD_CTRL(OUTPUT_RGB),
453 MX6_PAD_DISP0_DAT10__IPU1_DISP0_DATA10 | MUX_PAD_CTRL(OUTPUT_RGB),
454 MX6_PAD_DISP0_DAT11__IPU1_DISP0_DATA11 | MUX_PAD_CTRL(OUTPUT_RGB),
455 MX6_PAD_DISP0_DAT12__IPU1_DISP0_DATA12 | MUX_PAD_CTRL(OUTPUT_RGB),
456 MX6_PAD_DISP0_DAT13__IPU1_DISP0_DATA13 | MUX_PAD_CTRL(OUTPUT_RGB),
457 MX6_PAD_DISP0_DAT14__IPU1_DISP0_DATA14 | MUX_PAD_CTRL(OUTPUT_RGB),
458 MX6_PAD_DISP0_DAT15__IPU1_DISP0_DATA15 | MUX_PAD_CTRL(OUTPUT_RGB),
459 MX6_PAD_DISP0_DAT16__IPU1_DISP0_DATA16 | MUX_PAD_CTRL(OUTPUT_RGB),
460 MX6_PAD_DISP0_DAT17__IPU1_DISP0_DATA17 | MUX_PAD_CTRL(OUTPUT_RGB),
461};
462
463static void do_enable_hdmi(struct display_info_t const *dev)
464{
465 imx_enable_hdmi_phy();
466}
467
468static void enable_rgb(struct display_info_t const *dev)
469{
470 imx_iomux_v3_setup_multiple_pads(
471 rgb_pads,
472 ARRAY_SIZE(rgb_pads));
473 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
474 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0);
475}
476
477static int detect_default(struct display_info_t const *dev)
478{
479 (void) dev;
480 return 1;
481}
482
483struct display_info_t const displays[] = {{
484 .bus = -1,
485 .addr = 0,
486 .pixfmt = IPU_PIX_FMT_RGB24,
487 .detect = detect_hdmi,
488 .enable = do_enable_hdmi,
489 .mode = {
490 .name = "HDMI",
491 .refresh = 60,
492 .xres = 1024,
493 .yres = 768,
494 .pixclock = 15385,
495 .left_margin = 220,
496 .right_margin = 40,
497 .upper_margin = 21,
498 .lower_margin = 7,
499 .hsync_len = 60,
500 .vsync_len = 10,
501 .sync = FB_SYNC_EXT,
502 .vmode = FB_VMODE_NONINTERLACED
503} }, {
504 .bus = -1,
505 .addr = 0,
506 .pixfmt = IPU_PIX_FMT_RGB666,
507 .detect = detect_default,
508 .enable = enable_rgb,
509 .mode = {
510 .name = "vga-rgb",
511 .refresh = 60,
512 .xres = 640,
513 .yres = 480,
514 .pixclock = 33000,
515 .left_margin = 48,
516 .right_margin = 16,
517 .upper_margin = 31,
518 .lower_margin = 11,
519 .hsync_len = 96,
520 .vsync_len = 2,
521 .sync = 0,
522 .vmode = FB_VMODE_NONINTERLACED
523} }, {
524 .bus = -1,
525 .addr = 0,
526 .pixfmt = IPU_PIX_FMT_RGB666,
527 .enable = enable_rgb,
528 .mode = {
529 .name = "wvga-rgb",
530 .refresh = 60,
531 .xres = 800,
532 .yres = 480,
533 .pixclock = 25000,
534 .left_margin = 40,
535 .right_margin = 88,
536 .upper_margin = 33,
537 .lower_margin = 10,
538 .hsync_len = 128,
539 .vsync_len = 2,
540 .sync = 0,
541 .vmode = FB_VMODE_NONINTERLACED
542} } };
543size_t display_count = ARRAY_SIZE(displays);
544
545static void setup_display(void)
546{
547 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
548 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
549 int reg;
550
551 enable_ipu_clock();
552 imx_setup_hdmi();
553 /* Turn on LDB0,IPU,IPU DI0 clocks */
554 reg = __raw_readl(&mxc_ccm->CCGR3);
555 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
556 writel(reg, &mxc_ccm->CCGR3);
557
558 /* set LDB0, LDB1 clk select to 011/011 */
559 reg = readl(&mxc_ccm->cs2cdr);
560 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
561 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
562 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
563 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
564 writel(reg, &mxc_ccm->cs2cdr);
565
566 reg = readl(&mxc_ccm->cscmr2);
567 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
568 writel(reg, &mxc_ccm->cscmr2);
569
570 reg = readl(&mxc_ccm->chsccdr);
571 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
572 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
573 writel(reg, &mxc_ccm->chsccdr);
574
575 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
576 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
577 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
578 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
579 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
580 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
581 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
582 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
583 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
584 writel(reg, &iomux->gpr[2]);
585
586 reg = readl(&iomux->gpr[3]);
587 reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK
588 |IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
589 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
590 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
591 writel(reg, &iomux->gpr[3]);
592
593 /* backlight unconditionally on for now */
594 imx_iomux_v3_setup_multiple_pads(backlight_pads,
595 ARRAY_SIZE(backlight_pads));
596 /* use 0 for EDT 7", use 1 for LG fullHD panel */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100597 gpio_request(RGB_BACKLIGHTPWM_GP, "PWM<A>");
598 gpio_request(RGB_BACKLIGHT_GP, "BL_ON");
Max Krummenachereeb16b22016-11-30 19:43:09 +0100599 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0);
600 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
601}
Gerard Salvatella108d7392018-11-19 15:54:10 +0100602
603/*
604 * Backlight off before OS handover
605 */
606void board_preboot_os(void)
607{
608 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 1);
609 gpio_direction_output(RGB_BACKLIGHT_GP, 0);
610}
Max Krummenachereeb16b22016-11-30 19:43:09 +0100611#endif /* defined(CONFIG_VIDEO_IPUV3) */
612
613int board_early_init_f(void)
614{
615 imx_iomux_v3_setup_multiple_pads(pwr_intb_pads,
616 ARRAY_SIZE(pwr_intb_pads));
617 setup_iomux_uart();
618
Max Krummenachereeb16b22016-11-30 19:43:09 +0100619 return 0;
620}
621
622/*
623 * Do not overwrite the console
624 * Use always serial for U-Boot console
625 */
626int overwrite_console(void)
627{
628 return 1;
629}
630
631int board_init(void)
632{
633 /* address of boot parameters */
634 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
635
Fabio Estevamfd2525a2017-09-22 23:45:33 -0300636#if defined(CONFIG_VIDEO_IPUV3)
637 setup_display();
638#endif
639
Max Krummenachereeb16b22016-11-30 19:43:09 +0100640#ifdef CONFIG_TDX_CMD_IMX_MFGR
641 (void) pmic_init();
642#endif
643
Simon Glassab3055a2017-06-14 21:28:25 -0600644#ifdef CONFIG_SATA
Max Krummenachereeb16b22016-11-30 19:43:09 +0100645 setup_sata();
646#endif
647
648 setup_iomux_gpio();
649
650 return 0;
651}
652
653#ifdef CONFIG_BOARD_LATE_INIT
654int board_late_init(void)
655{
656#if defined(CONFIG_REVISION_TAG) && \
657 defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
658 char env_str[256];
659 u32 rev;
660
661 rev = get_board_rev();
662 snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
Simon Glass6a38e412017-08-03 12:22:09 -0600663 env_set("board_rev", env_str);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100664#endif
665
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100666#ifdef CONFIG_CMD_USB_SDP
667 if (is_boot_from_usb()) {
668 printf("Serial Downloader recovery mode, using sdp command\n");
669 env_set("bootdelay", "0");
670 env_set("bootcmd", "sdp 0");
671 }
672#endif /* CONFIG_CMD_USB_SDP */
673
Max Krummenachereeb16b22016-11-30 19:43:09 +0100674 return 0;
675}
676#endif /* CONFIG_BOARD_LATE_INIT */
677
Max Krummenachereeb16b22016-11-30 19:43:09 +0100678int checkboard(void)
679{
680 char it[] = " IT";
681 int minc, maxc;
682
683 switch (get_cpu_temp_grade(&minc, &maxc)) {
684 case TEMP_AUTOMOTIVE:
685 case TEMP_INDUSTRIAL:
686 break;
687 case TEMP_EXTCOMMERCIAL:
688 default:
689 it[0] = 0;
690 };
691 printf("Model: Toradex Colibri iMX6 %s %sMB%s\n",
692 is_cpu_type(MXC_CPU_MX6DL) ? "DualLite" : "Solo",
693 (gd->ram_size == 0x20000000) ? "512" : "256", it);
694 return 0;
695}
696
697#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
698int ft_board_setup(void *blob, bd_t *bd)
699{
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +0100700 u32 cma_size;
701
702 ft_common_board_setup(blob, bd);
703
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100704 cma_size = env_get_ulong("cma-size", 10, 320 * 1024 * 1024);
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +0100705 cma_size = min((u32)(gd->ram_size >> 1), cma_size);
706
707 fdt_setprop_u32(blob,
708 fdt_path_offset(blob, "/reserved-memory/linux,cma"),
709 "size",
710 cma_size);
711 return 0;
Max Krummenachereeb16b22016-11-30 19:43:09 +0100712}
713#endif
714
715#ifdef CONFIG_CMD_BMODE
716static const struct boot_mode board_boot_modes[] = {
717 {"mmc", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
718 {NULL, 0},
719};
720#endif
721
722int misc_init_r(void)
723{
724#ifdef CONFIG_CMD_BMODE
725 add_board_boot_modes(board_boot_modes);
726#endif
727 return 0;
728}
729
730#ifdef CONFIG_LDO_BYPASS_CHECK
731/* TODO, use external pmic, for now always ldo_enable */
732void ldo_mode_set(int ldo_bypass)
733{
734 return;
735}
736#endif
737
738#ifdef CONFIG_SPL_BUILD
739#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900740#include <linux/libfdt.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +0100741#include "asm/arch/mx6dl-ddr.h"
742#include "asm/arch/iomux.h"
743#include "asm/arch/crm_regs.h"
744
745static int mx6s_dcd_table[] = {
746/* ddr-setup.cfg */
747
748MX6_IOM_DRAM_SDQS0, 0x00000030,
749MX6_IOM_DRAM_SDQS1, 0x00000030,
750MX6_IOM_DRAM_SDQS2, 0x00000030,
751MX6_IOM_DRAM_SDQS3, 0x00000030,
752MX6_IOM_DRAM_SDQS4, 0x00000030,
753MX6_IOM_DRAM_SDQS5, 0x00000030,
754MX6_IOM_DRAM_SDQS6, 0x00000030,
755MX6_IOM_DRAM_SDQS7, 0x00000030,
756
757MX6_IOM_GRP_B0DS, 0x00000030,
758MX6_IOM_GRP_B1DS, 0x00000030,
759MX6_IOM_GRP_B2DS, 0x00000030,
760MX6_IOM_GRP_B3DS, 0x00000030,
761MX6_IOM_GRP_B4DS, 0x00000030,
762MX6_IOM_GRP_B5DS, 0x00000030,
763MX6_IOM_GRP_B6DS, 0x00000030,
764MX6_IOM_GRP_B7DS, 0x00000030,
765MX6_IOM_GRP_ADDDS, 0x00000030,
766/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
767MX6_IOM_GRP_CTLDS, 0x00000030,
768
769MX6_IOM_DRAM_DQM0, 0x00020030,
770MX6_IOM_DRAM_DQM1, 0x00020030,
771MX6_IOM_DRAM_DQM2, 0x00020030,
772MX6_IOM_DRAM_DQM3, 0x00020030,
773MX6_IOM_DRAM_DQM4, 0x00020030,
774MX6_IOM_DRAM_DQM5, 0x00020030,
775MX6_IOM_DRAM_DQM6, 0x00020030,
776MX6_IOM_DRAM_DQM7, 0x00020030,
777
778MX6_IOM_DRAM_CAS, 0x00020030,
779MX6_IOM_DRAM_RAS, 0x00020030,
780MX6_IOM_DRAM_SDCLK_0, 0x00020030,
781MX6_IOM_DRAM_SDCLK_1, 0x00020030,
782
783MX6_IOM_DRAM_RESET, 0x00020030,
784MX6_IOM_DRAM_SDCKE0, 0x00003000,
785MX6_IOM_DRAM_SDCKE1, 0x00003000,
786
787MX6_IOM_DRAM_SDODT0, 0x00003030,
788MX6_IOM_DRAM_SDODT1, 0x00003030,
789
790/* (differential input) */
791MX6_IOM_DDRMODE_CTL, 0x00020000,
792/* (differential input) */
793MX6_IOM_GRP_DDRMODE, 0x00020000,
794/* disable ddr pullups */
795MX6_IOM_GRP_DDRPKE, 0x00000000,
796MX6_IOM_DRAM_SDBA2, 0x00000000,
797/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
798MX6_IOM_GRP_DDR_TYPE, 0x000C0000,
799
800/* Read data DQ Byte0-3 delay */
801MX6_MMDC_P0_MPRDDQBY0DL, 0x33333333,
802MX6_MMDC_P0_MPRDDQBY1DL, 0x33333333,
803MX6_MMDC_P0_MPRDDQBY2DL, 0x33333333,
804MX6_MMDC_P0_MPRDDQBY3DL, 0x33333333,
805MX6_MMDC_P1_MPRDDQBY0DL, 0x33333333,
806MX6_MMDC_P1_MPRDDQBY1DL, 0x33333333,
807MX6_MMDC_P1_MPRDDQBY2DL, 0x33333333,
808MX6_MMDC_P1_MPRDDQBY3DL, 0x33333333,
809
810/*
811 * MDMISC mirroring interleaved (row/bank/col)
812 */
813/* TODO: check what the RALAT field does */
814MX6_MMDC_P0_MDMISC, 0x00081740,
815
816/*
817 * MDSCR con_req
818 */
819MX6_MMDC_P0_MDSCR, 0x00008000,
820
821
822/* 800mhz_2x64mx16.cfg */
823
824MX6_MMDC_P0_MDPDC, 0x0002002D,
825MX6_MMDC_P0_MDCFG0, 0x2C305503,
826MX6_MMDC_P0_MDCFG1, 0xB66D8D63,
827MX6_MMDC_P0_MDCFG2, 0x01FF00DB,
828MX6_MMDC_P0_MDRWD, 0x000026D2,
829MX6_MMDC_P0_MDOR, 0x00301023,
830MX6_MMDC_P0_MDOTC, 0x00333030,
831MX6_MMDC_P0_MDPDC, 0x0002556D,
832/* CS0 End: 7MSB of ((0x10000000, + 512M) -1) >> 25 */
833MX6_MMDC_P0_MDASP, 0x00000017,
834/* DDR3 DATA BUS SIZE: 64BIT */
835/* MX6_MMDC_P0_MDCTL, 0x821A0000, */
836/* DDR3 DATA BUS SIZE: 32BIT */
837MX6_MMDC_P0_MDCTL, 0x82190000,
838
839/* Write commands to DDR */
840/* Load Mode Registers */
841/* TODO Use Auto Self-Refresh mode (Extended Temperature)*/
842/* MX6_MMDC_P0_MDSCR, 0x04408032, */
843MX6_MMDC_P0_MDSCR, 0x04008032,
844MX6_MMDC_P0_MDSCR, 0x00008033,
845MX6_MMDC_P0_MDSCR, 0x00048031,
846MX6_MMDC_P0_MDSCR, 0x13208030,
847/* ZQ calibration */
848MX6_MMDC_P0_MDSCR, 0x04008040,
849
850MX6_MMDC_P0_MPZQHWCTRL, 0xA1390003,
851MX6_MMDC_P1_MPZQHWCTRL, 0xA1390003,
852MX6_MMDC_P0_MDREF, 0x00005800,
853
854MX6_MMDC_P0_MPODTCTRL, 0x00000000,
855MX6_MMDC_P1_MPODTCTRL, 0x00000000,
856
857MX6_MMDC_P0_MPDGCTRL0, 0x42360232,
858MX6_MMDC_P0_MPDGCTRL1, 0x021F022A,
859MX6_MMDC_P1_MPDGCTRL0, 0x421E0224,
860MX6_MMDC_P1_MPDGCTRL1, 0x02110218,
861
862MX6_MMDC_P0_MPRDDLCTL, 0x41434344,
863MX6_MMDC_P1_MPRDDLCTL, 0x4345423E,
864MX6_MMDC_P0_MPWRDLCTL, 0x39383339,
865MX6_MMDC_P1_MPWRDLCTL, 0x3E363930,
866
867MX6_MMDC_P0_MPWLDECTRL0, 0x00340039,
868MX6_MMDC_P0_MPWLDECTRL1, 0x002C002D,
869MX6_MMDC_P1_MPWLDECTRL0, 0x00120019,
870MX6_MMDC_P1_MPWLDECTRL1, 0x0012002D,
871
872MX6_MMDC_P0_MPMUR0, 0x00000800,
873MX6_MMDC_P1_MPMUR0, 0x00000800,
874MX6_MMDC_P0_MDSCR, 0x00000000,
875MX6_MMDC_P0_MAPSR, 0x00011006,
876};
877
878static int mx6dl_dcd_table[] = {
879/* ddr-setup.cfg */
880
881MX6_IOM_DRAM_SDQS0, 0x00000030,
882MX6_IOM_DRAM_SDQS1, 0x00000030,
883MX6_IOM_DRAM_SDQS2, 0x00000030,
884MX6_IOM_DRAM_SDQS3, 0x00000030,
885MX6_IOM_DRAM_SDQS4, 0x00000030,
886MX6_IOM_DRAM_SDQS5, 0x00000030,
887MX6_IOM_DRAM_SDQS6, 0x00000030,
888MX6_IOM_DRAM_SDQS7, 0x00000030,
889
890MX6_IOM_GRP_B0DS, 0x00000030,
891MX6_IOM_GRP_B1DS, 0x00000030,
892MX6_IOM_GRP_B2DS, 0x00000030,
893MX6_IOM_GRP_B3DS, 0x00000030,
894MX6_IOM_GRP_B4DS, 0x00000030,
895MX6_IOM_GRP_B5DS, 0x00000030,
896MX6_IOM_GRP_B6DS, 0x00000030,
897MX6_IOM_GRP_B7DS, 0x00000030,
898MX6_IOM_GRP_ADDDS, 0x00000030,
899/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
900MX6_IOM_GRP_CTLDS, 0x00000030,
901
902MX6_IOM_DRAM_DQM0, 0x00020030,
903MX6_IOM_DRAM_DQM1, 0x00020030,
904MX6_IOM_DRAM_DQM2, 0x00020030,
905MX6_IOM_DRAM_DQM3, 0x00020030,
906MX6_IOM_DRAM_DQM4, 0x00020030,
907MX6_IOM_DRAM_DQM5, 0x00020030,
908MX6_IOM_DRAM_DQM6, 0x00020030,
909MX6_IOM_DRAM_DQM7, 0x00020030,
910
911MX6_IOM_DRAM_CAS, 0x00020030,
912MX6_IOM_DRAM_RAS, 0x00020030,
913MX6_IOM_DRAM_SDCLK_0, 0x00020030,
914MX6_IOM_DRAM_SDCLK_1, 0x00020030,
915
916MX6_IOM_DRAM_RESET, 0x00020030,
917MX6_IOM_DRAM_SDCKE0, 0x00003000,
918MX6_IOM_DRAM_SDCKE1, 0x00003000,
919
920MX6_IOM_DRAM_SDODT0, 0x00003030,
921MX6_IOM_DRAM_SDODT1, 0x00003030,
922
923/* (differential input) */
924MX6_IOM_DDRMODE_CTL, 0x00020000,
925/* (differential input) */
926MX6_IOM_GRP_DDRMODE, 0x00020000,
927/* disable ddr pullups */
928MX6_IOM_GRP_DDRPKE, 0x00000000,
929MX6_IOM_DRAM_SDBA2, 0x00000000,
930/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
931MX6_IOM_GRP_DDR_TYPE, 0x000C0000,
932
933/* Read data DQ Byte0-3 delay */
934MX6_MMDC_P0_MPRDDQBY0DL, 0x33333333,
935MX6_MMDC_P0_MPRDDQBY1DL, 0x33333333,
936MX6_MMDC_P0_MPRDDQBY2DL, 0x33333333,
937MX6_MMDC_P0_MPRDDQBY3DL, 0x33333333,
938MX6_MMDC_P1_MPRDDQBY0DL, 0x33333333,
939MX6_MMDC_P1_MPRDDQBY1DL, 0x33333333,
940MX6_MMDC_P1_MPRDDQBY2DL, 0x33333333,
941MX6_MMDC_P1_MPRDDQBY3DL, 0x33333333,
942
943/*
944 * MDMISC mirroring interleaved (row/bank/col)
945 */
946/* TODO: check what the RALAT field does */
947MX6_MMDC_P0_MDMISC, 0x00081740,
948
949/*
950 * MDSCR con_req
951 */
952MX6_MMDC_P0_MDSCR, 0x00008000,
953
954
955/* 800mhz_2x64mx16.cfg */
956
957MX6_MMDC_P0_MDPDC, 0x0002002D,
958MX6_MMDC_P0_MDCFG0, 0x2C305503,
959MX6_MMDC_P0_MDCFG1, 0xB66D8D63,
960MX6_MMDC_P0_MDCFG2, 0x01FF00DB,
961MX6_MMDC_P0_MDRWD, 0x000026D2,
962MX6_MMDC_P0_MDOR, 0x00301023,
963MX6_MMDC_P0_MDOTC, 0x00333030,
964MX6_MMDC_P0_MDPDC, 0x0002556D,
965/* CS0 End: 7MSB of ((0x10000000, + 512M) -1) >> 25 */
966MX6_MMDC_P0_MDASP, 0x00000017,
967/* DDR3 DATA BUS SIZE: 64BIT */
968MX6_MMDC_P0_MDCTL, 0x821A0000,
969/* DDR3 DATA BUS SIZE: 32BIT */
970/* MX6_MMDC_P0_MDCTL, 0x82190000, */
971
972/* Write commands to DDR */
973/* Load Mode Registers */
974/* TODO Use Auto Self-Refresh mode (Extended Temperature)*/
975/* MX6_MMDC_P0_MDSCR, 0x04408032, */
976MX6_MMDC_P0_MDSCR, 0x04008032,
977MX6_MMDC_P0_MDSCR, 0x00008033,
978MX6_MMDC_P0_MDSCR, 0x00048031,
979MX6_MMDC_P0_MDSCR, 0x13208030,
980/* ZQ calibration */
981MX6_MMDC_P0_MDSCR, 0x04008040,
982
983MX6_MMDC_P0_MPZQHWCTRL, 0xA1390003,
984MX6_MMDC_P1_MPZQHWCTRL, 0xA1390003,
985MX6_MMDC_P0_MDREF, 0x00005800,
986
987MX6_MMDC_P0_MPODTCTRL, 0x00000000,
988MX6_MMDC_P1_MPODTCTRL, 0x00000000,
989
990MX6_MMDC_P0_MPDGCTRL0, 0x42360232,
991MX6_MMDC_P0_MPDGCTRL1, 0x021F022A,
992MX6_MMDC_P1_MPDGCTRL0, 0x421E0224,
993MX6_MMDC_P1_MPDGCTRL1, 0x02110218,
994
995MX6_MMDC_P0_MPRDDLCTL, 0x41434344,
996MX6_MMDC_P1_MPRDDLCTL, 0x4345423E,
997MX6_MMDC_P0_MPWRDLCTL, 0x39383339,
998MX6_MMDC_P1_MPWRDLCTL, 0x3E363930,
999
1000MX6_MMDC_P0_MPWLDECTRL0, 0x00340039,
1001MX6_MMDC_P0_MPWLDECTRL1, 0x002C002D,
1002MX6_MMDC_P1_MPWLDECTRL0, 0x00120019,
1003MX6_MMDC_P1_MPWLDECTRL1, 0x0012002D,
1004
1005MX6_MMDC_P0_MPMUR0, 0x00000800,
1006MX6_MMDC_P1_MPMUR0, 0x00000800,
1007MX6_MMDC_P0_MDSCR, 0x00000000,
1008MX6_MMDC_P0_MAPSR, 0x00011006,
1009};
1010
1011static void ccgr_init(void)
1012{
1013 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
1014
1015 writel(0x00C03F3F, &ccm->CCGR0);
1016 writel(0x0030FC03, &ccm->CCGR1);
1017 writel(0x0FFFFFF3, &ccm->CCGR2);
1018 writel(0x3FF0300F, &ccm->CCGR3);
1019 writel(0x00FFF300, &ccm->CCGR4);
1020 writel(0x0F0000F3, &ccm->CCGR5);
1021 writel(0x000003FF, &ccm->CCGR6);
1022
1023/*
1024 * Setup CCM_CCOSR register as follows:
1025 *
1026 * cko1_en = 1 --> CKO1 enabled
1027 * cko1_div = 111 --> divide by 8
1028 * cko1_sel = 1011 --> ahb_clk_root
1029 *
1030 * This sets CKO1 at ahb_clk_root/8 = 132/8 = 16.5 MHz
1031 */
1032 writel(0x000000FB, &ccm->ccosr);
1033}
1034
Max Krummenachereeb16b22016-11-30 19:43:09 +01001035static void ddr_init(int *table, int size)
1036{
1037 int i;
1038
1039 for (i = 0; i < size / 2 ; i++)
1040 writel(table[2 * i + 1], table[2 * i]);
1041}
1042
1043static void spl_dram_init(void)
1044{
1045 int minc, maxc;
1046
1047 switch (get_cpu_temp_grade(&minc, &maxc)) {
1048 case TEMP_COMMERCIAL:
1049 case TEMP_EXTCOMMERCIAL:
1050 if (is_cpu_type(MXC_CPU_MX6DL)) {
1051 puts("Commercial temperature grade DDR3 timings, 64bit bus width.\n");
1052 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
1053 } else {
1054 puts("Commercial temperature grade DDR3 timings, 32bit bus width.\n");
1055 ddr_init(mx6s_dcd_table, ARRAY_SIZE(mx6s_dcd_table));
1056 }
1057 break;
1058 case TEMP_INDUSTRIAL:
1059 case TEMP_AUTOMOTIVE:
1060 default:
1061 if (is_cpu_type(MXC_CPU_MX6DL)) {
Max Krummenacherc1ce7cb2019-02-08 18:42:17 +01001062 puts("Industrial temperature grade DDR3 timings, 64bit bus width.\n");
Max Krummenachereeb16b22016-11-30 19:43:09 +01001063 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
1064 } else {
1065 puts("Industrial temperature grade DDR3 timings, 32bit bus width.\n");
1066 ddr_init(mx6s_dcd_table, ARRAY_SIZE(mx6s_dcd_table));
1067 }
1068 break;
1069 };
1070 udelay(100);
1071}
1072
1073void board_init_f(ulong dummy)
1074{
1075 /* setup AIPS and disable watchdog */
1076 arch_cpu_init();
1077
1078 ccgr_init();
1079 gpr_init();
1080
Marcel Ziswilerc882cfb2019-02-08 18:42:12 +01001081 /* iomux */
Max Krummenachereeb16b22016-11-30 19:43:09 +01001082 board_early_init_f();
1083
1084 /* setup GP timer */
1085 timer_init();
1086
1087 /* UART clocks enabled and gd valid - init serial console */
1088 preloader_console_init();
1089
1090 /* Make sure we use dte mode */
1091 setup_dtemode_uart();
1092
1093 /* DDR initialization */
1094 spl_dram_init();
1095
1096 /* Clear the BSS. */
1097 memset(__bss_start, 0, __bss_end - __bss_start);
1098
1099 /* load/boot image from boot device */
1100 board_init_r(NULL, 0);
1101}
1102
1103void reset_cpu(ulong addr)
1104{
1105}
1106
Marcel Ziswiler3e43a502019-02-08 18:42:10 +01001107#endif /* CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +01001108
1109static struct mxc_serial_platdata mxc_serial_plat = {
1110 .reg = (struct mxc_uart *)UART1_BASE,
1111 .use_dte = true,
1112};
1113
1114U_BOOT_DEVICE(mxc_serial) = {
1115 .name = "serial_mxc",
1116 .platdata = &mxc_serial_plat,
1117};