blob: 784ca7f65f7bc6ea55c00fcb14c9ea4c764407aa [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 Glassafb02152019-12-28 10:45:01 -070010#include <cpu_func.h>
Simon Glass11c89f32017-05-17 17:18:03 -060011#include <dm.h>
Simon Glass6eaea252019-08-01 09:46:48 -060012#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070013#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060016#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060017#include <linux/delay.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010018
Max Krummenachereeb16b22016-11-30 19:43:09 +010019#include <asm/arch/clock.h>
20#include <asm/arch/crm_regs.h>
21#include <asm/arch/imx-regs.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010022#include <asm/arch/mx6-ddr.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010023#include <asm/arch/mx6-pins.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010024#include <asm/arch/mxc_hdmi.h>
25#include <asm/arch/sys_proto.h>
26#include <asm/bootm.h>
27#include <asm/gpio.h>
Marcel Ziswiler3e43a502019-02-08 18:42:10 +010028#include <asm/mach-imx/boot_mode.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020029#include <asm/mach-imx/iomux-v3.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020030#include <asm/mach-imx/sata.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020031#include <asm/mach-imx/video.h>
Shiji Yangbb112342023-08-03 09:47:16 +080032#include <asm/sections.h>
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +010033#include <cpu.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010034#include <dm/platform_data/serial_mxc.h>
Yangbo Lu73340382019-06-21 11:42:28 +080035#include <fsl_esdhc_imx.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010036#include <imx_thermal.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010037#include <miiphy.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010038#include <netdev.h>
Gerard Salvatella7fba5092019-02-08 18:42:28 +010039#include <cpu.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +010040
41#include "../common/tdx-cfg-block.h"
42#ifdef CONFIG_TDX_CMD_IMX_MFGR
43#include "pf0100.h"
44#endif
45
46DECLARE_GLOBAL_DATA_PTR;
47
48#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
49 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
50 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
51
52#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
Max Krummenachera0f4d792019-02-08 18:42:19 +010053 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_40ohm | \
54 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
55
56#define USDHC_EMMC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
Max Krummenachereeb16b22016-11-30 19:43:09 +010057 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
58 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
59
Max Krummenachereeb16b22016-11-30 19:43:09 +010060#define WEAK_PULLUP (PAD_CTL_PUS_100K_UP | \
61 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
62 PAD_CTL_SRE_SLOW)
63
64#define NO_PULLUP ( \
65 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | PAD_CTL_HYS | \
66 PAD_CTL_SRE_SLOW)
67
68#define WEAK_PULLDOWN (PAD_CTL_PUS_100K_DOWN | \
69 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
70 PAD_CTL_HYS | PAD_CTL_SRE_SLOW)
71
Max Krummenachereeb16b22016-11-30 19:43:09 +010072#define OUTPUT_RGB (PAD_CTL_SPEED_MED|PAD_CTL_DSE_60ohm|PAD_CTL_SRE_FAST)
73
74int dram_init(void)
75{
76 /* use the DDR controllers configured size */
Tom Rinibb4dd962022-11-16 13:10:37 -050077 gd->ram_size = get_ram_size((void *)CFG_SYS_SDRAM_BASE,
Max Krummenachereeb16b22016-11-30 19:43:09 +010078 (ulong)imx_ddr_size());
79
80 return 0;
81}
82
83/* Colibri UARTA */
84iomux_v3_cfg_t const uart1_pads[] = {
85 MX6_PAD_CSI0_DAT10__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
86 MX6_PAD_CSI0_DAT11__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL),
87};
88
Igor Opaniuk6c6a9862019-12-06 18:24:16 +020089#if defined(CONFIG_FSL_ESDHC_IMX) && defined(CONFIG_SPL_BUILD)
Marcel Ziswilerc882cfb2019-02-08 18:42:12 +010090/* Colibri MMC */
Max Krummenachereeb16b22016-11-30 19:43:09 +010091iomux_v3_cfg_t const usdhc1_pads[] = {
92 MX6_PAD_SD1_CLK__SD1_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL),
93 MX6_PAD_SD1_CMD__SD1_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL),
94 MX6_PAD_SD1_DAT0__SD1_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
95 MX6_PAD_SD1_DAT1__SD1_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
96 MX6_PAD_SD1_DAT2__SD1_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
97 MX6_PAD_SD1_DAT3__SD1_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL),
98 MX6_PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(NO_PAD_CTRL), /* CD */
99# define GPIO_MMC_CD IMX_GPIO_NR(2, 5)
100};
101
102/* eMMC */
103iomux_v3_cfg_t const usdhc3_pads[] = {
Max Krummenachera0f4d792019-02-08 18:42:19 +0100104 MX6_PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
105 MX6_PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
106 MX6_PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
107 MX6_PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
108 MX6_PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
109 MX6_PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
110 MX6_PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
111 MX6_PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
112 MX6_PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
113 MX6_PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_EMMC_PAD_CTRL),
Max Krummenachereeb16b22016-11-30 19:43:09 +0100114 MX6_PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL),
115};
Yangbo Lu73340382019-06-21 11:42:28 +0800116#endif /* CONFIG_FSL_ESDHC_IMX & CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100117
Max Krummenachereeb16b22016-11-30 19:43:09 +0100118/* mux auxiliary pins to GPIO, so they can be used from the U-Boot cmdline */
119iomux_v3_cfg_t const gpio_pads[] = {
120 /* ADDRESS[17:18] [25] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100121 MX6_PAD_KEY_ROW2__GPIO4_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
122 MUX_MODE_SION,
123 MX6_PAD_KEY_COL2__GPIO4_IO10 | MUX_PAD_CTRL(WEAK_PULLUP) |
124 MUX_MODE_SION,
125 MX6_PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(WEAK_PULLUP) |
126 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100127 /* ADDRESS[19:24] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100128 MX6_PAD_DISP0_DAT23__GPIO5_IO17 | MUX_PAD_CTRL(WEAK_PULLUP) |
129 MUX_MODE_SION,
130 MX6_PAD_DISP0_DAT22__GPIO5_IO16 | MUX_PAD_CTRL(WEAK_PULLUP) |
131 MUX_MODE_SION,
132 MX6_PAD_DISP0_DAT21__GPIO5_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
133 MUX_MODE_SION,
134 MX6_PAD_DISP0_DAT20__GPIO5_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
135 MUX_MODE_SION,
136 MX6_PAD_DISP0_DAT19__GPIO5_IO13 | MUX_PAD_CTRL(WEAK_PULLUP) |
137 MUX_MODE_SION,
138 MX6_PAD_DISP0_DAT18__GPIO5_IO12 | MUX_PAD_CTRL(WEAK_PULLUP) |
139 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100140 /* DATA[16:29] [31] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100141 MX6_PAD_EIM_LBA__GPIO2_IO27 | MUX_PAD_CTRL(WEAK_PULLUP) |
142 MUX_MODE_SION,
143 MX6_PAD_EIM_BCLK__GPIO6_IO31 | MUX_PAD_CTRL(WEAK_PULLUP) |
144 MUX_MODE_SION,
145 MX6_PAD_NANDF_CS3__GPIO6_IO16 | MUX_PAD_CTRL(WEAK_PULLUP) |
146 MUX_MODE_SION,
147 MX6_PAD_NANDF_CS1__GPIO6_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
148 MUX_MODE_SION,
149 MX6_PAD_NANDF_RB0__GPIO6_IO10 | MUX_PAD_CTRL(WEAK_PULLUP) |
150 MUX_MODE_SION,
151 MX6_PAD_NANDF_ALE__GPIO6_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
152 MUX_MODE_SION,
153 MX6_PAD_NANDF_WP_B__GPIO6_IO09 | MUX_PAD_CTRL(WEAK_PULLUP) |
154 MUX_MODE_SION,
155 MX6_PAD_NANDF_CS0__GPIO6_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
156 MUX_MODE_SION,
157 MX6_PAD_NANDF_CLE__GPIO6_IO07 | MUX_PAD_CTRL(WEAK_PULLUP) |
158 MUX_MODE_SION,
159 MX6_PAD_GPIO_19__GPIO4_IO05 | MUX_PAD_CTRL(WEAK_PULLUP) |
160 MUX_MODE_SION,
161 MX6_PAD_CSI0_MCLK__GPIO5_IO19 | MUX_PAD_CTRL(WEAK_PULLUP) |
162 MUX_MODE_SION,
163 MX6_PAD_CSI0_PIXCLK__GPIO5_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
164 MUX_MODE_SION,
165 MX6_PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
166 MUX_MODE_SION,
167 MX6_PAD_GPIO_5__GPIO1_IO05 | MUX_PAD_CTRL(WEAK_PULLUP) |
168 MUX_MODE_SION,
169 MX6_PAD_GPIO_2__GPIO1_IO02 | MUX_PAD_CTRL(WEAK_PULLUP) |
170 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100171 /* DQM[0:3] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100172 MX6_PAD_EIM_EB0__GPIO2_IO28 | MUX_PAD_CTRL(WEAK_PULLUP) |
173 MUX_MODE_SION,
174 MX6_PAD_EIM_EB1__GPIO2_IO29 | MUX_PAD_CTRL(WEAK_PULLUP) |
175 MUX_MODE_SION,
176 MX6_PAD_SD2_DAT2__GPIO1_IO13 | MUX_PAD_CTRL(WEAK_PULLUP) |
177 MUX_MODE_SION,
178 MX6_PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(WEAK_PULLUP) |
179 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100180 /* RDY used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100181 MX6_PAD_EIM_WAIT__GPIO5_IO00 | MUX_PAD_CTRL(WEAK_PULLUP) |
182 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100183 /* ADDRESS[16] DATA[30] used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100184 MX6_PAD_KEY_ROW4__GPIO4_IO15 | MUX_PAD_CTRL(WEAK_PULLDOWN) |
185 MUX_MODE_SION,
186 MX6_PAD_KEY_COL4__GPIO4_IO14 | MUX_PAD_CTRL(WEAK_PULLUP) |
187 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100188 /* CSI pins used as GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100189 MX6_PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
190 MUX_MODE_SION,
191 MX6_PAD_SD2_CMD__GPIO1_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
192 MUX_MODE_SION,
193 MX6_PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
194 MUX_MODE_SION,
195 MX6_PAD_EIM_D18__GPIO3_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
196 MUX_MODE_SION,
197 MX6_PAD_EIM_A19__GPIO2_IO19 | MUX_PAD_CTRL(WEAK_PULLUP) |
198 MUX_MODE_SION,
199 MX6_PAD_EIM_D29__GPIO3_IO29 | MUX_PAD_CTRL(WEAK_PULLDOWN) |
200 MUX_MODE_SION,
201 MX6_PAD_EIM_A23__GPIO6_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) |
202 MUX_MODE_SION,
203 MX6_PAD_EIM_A20__GPIO2_IO18 | MUX_PAD_CTRL(WEAK_PULLUP) |
204 MUX_MODE_SION,
205 MX6_PAD_EIM_A17__GPIO2_IO21 | MUX_PAD_CTRL(WEAK_PULLUP) |
206 MUX_MODE_SION,
207 MX6_PAD_EIM_A18__GPIO2_IO20 | MUX_PAD_CTRL(WEAK_PULLUP) |
208 MUX_MODE_SION,
209 MX6_PAD_EIM_EB3__GPIO2_IO31 | MUX_PAD_CTRL(WEAK_PULLUP) |
210 MUX_MODE_SION,
211 MX6_PAD_EIM_D17__GPIO3_IO17 | MUX_PAD_CTRL(WEAK_PULLUP) |
212 MUX_MODE_SION,
213 MX6_PAD_SD2_DAT0__GPIO1_IO15 | MUX_PAD_CTRL(WEAK_PULLUP) |
214 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100215 /* GPIO */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100216 MX6_PAD_EIM_D26__GPIO3_IO26 | MUX_PAD_CTRL(WEAK_PULLUP) |
217 MUX_MODE_SION,
218 MX6_PAD_EIM_D27__GPIO3_IO27 | MUX_PAD_CTRL(WEAK_PULLUP) |
219 MUX_MODE_SION,
220 MX6_PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(WEAK_PULLUP) |
221 MUX_MODE_SION,
222 MX6_PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(WEAK_PULLUP) |
223 MUX_MODE_SION,
224 MX6_PAD_ENET_REF_CLK__GPIO1_IO23 | MUX_PAD_CTRL(WEAK_PULLUP) |
225 MUX_MODE_SION,
226 MX6_PAD_DI0_PIN4__GPIO4_IO20 | MUX_PAD_CTRL(WEAK_PULLUP) |
227 MUX_MODE_SION,
228 MX6_PAD_SD4_DAT3__GPIO2_IO11 | MUX_PAD_CTRL(WEAK_PULLUP) |
229 MUX_MODE_SION,
230 MX6_PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(WEAK_PULLUP) |
231 MUX_MODE_SION,
232 MX6_PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
233 MUX_MODE_SION,
234 MX6_PAD_GPIO_7__GPIO1_IO07 | MUX_PAD_CTRL(WEAK_PULLUP) |
235 MUX_MODE_SION,
236 MX6_PAD_GPIO_8__GPIO1_IO08 | MUX_PAD_CTRL(WEAK_PULLUP) |
237 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100238 /* USBH_OC */
239 MX6_PAD_EIM_D30__GPIO3_IO30 | MUX_PAD_CTRL(WEAK_PULLUP),
240 /* USBC_ID */
241 MX6_PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(WEAK_PULLUP),
242 /* USBC_DET */
243 MX6_PAD_GPIO_17__GPIO7_IO12 | MUX_PAD_CTRL(WEAK_PULLUP),
244};
245
246static void setup_iomux_gpio(void)
247{
248 imx_iomux_v3_setup_multiple_pads(gpio_pads, ARRAY_SIZE(gpio_pads));
249}
250
251iomux_v3_cfg_t const usb_pads[] = {
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100252 /* USBH_PEN */
253 MX6_PAD_EIM_D31__GPIO3_IO31 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100254# define GPIO_USBH_EN IMX_GPIO_NR(3, 31)
255};
256
257/*
258 * UARTs are used in DTE mode, switch the mode on all UARTs before
259 * any pinmuxing connects a (DCE) output to a transceiver output.
260 */
Max Krummenacher003bc132019-02-08 18:42:21 +0100261#define UCR3 0x88 /* FIFO Control Register */
262#define UCR3_RI BIT(8) /* RIDELT DTE mode */
263#define UCR3_DCD BIT(9) /* DCDDELT DTE mode */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100264#define UFCR 0x90 /* FIFO Control Register */
Max Krummenacher003bc132019-02-08 18:42:21 +0100265#define UFCR_DCEDTE BIT(6) /* DCE=0 */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100266
267static void setup_dtemode_uart(void)
268{
269 setbits_le32((u32 *)(UART1_BASE + UFCR), UFCR_DCEDTE);
270 setbits_le32((u32 *)(UART2_BASE + UFCR), UFCR_DCEDTE);
271 setbits_le32((u32 *)(UART3_BASE + UFCR), UFCR_DCEDTE);
Max Krummenacher003bc132019-02-08 18:42:21 +0100272
273 clrbits_le32((u32 *)(UART1_BASE + UCR3), UCR3_DCD | UCR3_RI);
274 clrbits_le32((u32 *)(UART2_BASE + UCR3), UCR3_DCD | UCR3_RI);
275 clrbits_le32((u32 *)(UART3_BASE + UCR3), UCR3_DCD | UCR3_RI);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100276}
277
278static void setup_iomux_uart(void)
279{
280 setup_dtemode_uart();
281 imx_iomux_v3_setup_multiple_pads(uart1_pads, ARRAY_SIZE(uart1_pads));
282}
283
284#ifdef CONFIG_USB_EHCI_MX6
285int board_ehci_hcd_init(int port)
286{
287 imx_iomux_v3_setup_multiple_pads(usb_pads, ARRAY_SIZE(usb_pads));
288 return 0;
289}
Marcel Ziswilerf2839442019-02-08 18:42:15 +0100290#endif
Max Krummenachereeb16b22016-11-30 19:43:09 +0100291
Igor Opaniuk6c6a9862019-12-06 18:24:16 +0200292#if defined(CONFIG_FSL_ESDHC_IMX) && defined(CONFIG_SPL_BUILD)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100293/* use the following sequence: eMMC, MMC */
Tom Rini376b88a2022-10-28 20:27:13 -0400294struct fsl_esdhc_cfg usdhc_cfg[CFG_SYS_FSL_USDHC_NUM] = {
Max Krummenachereeb16b22016-11-30 19:43:09 +0100295 {USDHC3_BASE_ADDR},
296 {USDHC1_BASE_ADDR},
297};
298
299int board_mmc_getcd(struct mmc *mmc)
300{
301 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
302 int ret = true; /* default: assume inserted */
303
304 switch (cfg->esdhc_base) {
305 case USDHC1_BASE_ADDR:
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100306 gpio_request(GPIO_MMC_CD, "MMC_CD");
Max Krummenachereeb16b22016-11-30 19:43:09 +0100307 gpio_direction_input(GPIO_MMC_CD);
308 ret = !gpio_get_value(GPIO_MMC_CD);
309 break;
310 }
311
312 return ret;
313}
314
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900315int board_mmc_init(struct bd_info *bis)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100316{
Max Krummenachereeb16b22016-11-30 19:43:09 +0100317 struct src *psrc = (struct src *)SRC_BASE_ADDR;
318 unsigned reg = readl(&psrc->sbmr1) >> 11;
319 /*
320 * Upon reading BOOT_CFG register the following map is done:
321 * Bit 11 and 12 of BOOT_CFG register can determine the current
322 * mmc port
323 * 0x1 SD1
324 * 0x2 SD2
325 * 0x3 SD4
326 */
327
328 switch (reg & 0x3) {
329 case 0x0:
330 imx_iomux_v3_setup_multiple_pads(
331 usdhc1_pads, ARRAY_SIZE(usdhc1_pads));
332 usdhc_cfg[0].esdhc_base = USDHC1_BASE_ADDR;
333 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
334 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
335 break;
336 case 0x2:
337 imx_iomux_v3_setup_multiple_pads(
338 usdhc3_pads, ARRAY_SIZE(usdhc3_pads));
339 usdhc_cfg[0].esdhc_base = USDHC3_BASE_ADDR;
340 usdhc_cfg[0].sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
341 gd->arch.sdhc_clk = usdhc_cfg[0].sdhc_clk;
342 break;
343 default:
344 puts("MMC boot device not available");
345 }
346
347 return fsl_esdhc_initialize(bis, &usdhc_cfg[0]);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100348}
Yangbo Lu73340382019-06-21 11:42:28 +0800349#endif /* CONFIG_FSL_ESDHC_IMX & CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +0100350
351int board_phy_config(struct phy_device *phydev)
352{
353 if (phydev->drv->config)
354 phydev->drv->config(phydev);
355
356 return 0;
357}
358
Igor Opaniuk03e68cd2019-11-04 11:12:00 +0100359int setup_fec(void)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100360{
Max Krummenachereeb16b22016-11-30 19:43:09 +0100361 int ret;
Igor Opaniuka022ba32020-03-27 12:28:17 +0200362 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
Max Krummenachereeb16b22016-11-30 19:43:09 +0100363
364 /* provide the PHY clock from the i.MX 6 */
365 ret = enable_fec_anatop_clock(0, ENET_50MHZ);
366 if (ret)
367 return ret;
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100368
Igor Opaniuka022ba32020-03-27 12:28:17 +0200369 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
370
Max Krummenachereeb16b22016-11-30 19:43:09 +0100371 return 0;
372}
373
374static iomux_v3_cfg_t const pwr_intb_pads[] = {
375 /*
376 * the bootrom sets the iomux to vselect, potentially connecting
377 * two outputs. Set this back to GPIO
378 */
379 MX6_PAD_GPIO_18__GPIO7_IO13 | MUX_PAD_CTRL(NO_PAD_CTRL)
380};
381
382#if defined(CONFIG_VIDEO_IPUV3)
383
384static iomux_v3_cfg_t const backlight_pads[] = {
385 /* Backlight On */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100386 MX6_PAD_EIM_D26__GPIO3_IO26 | MUX_PAD_CTRL(NO_PAD_CTRL) | MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100387#define RGB_BACKLIGHT_GP IMX_GPIO_NR(3, 26)
388 /* Backlight PWM, used as GPIO in U-Boot */
389 MX6_PAD_EIM_A22__GPIO2_IO16 | MUX_PAD_CTRL(NO_PULLUP),
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100390 MX6_PAD_SD4_DAT1__GPIO2_IO09 | MUX_PAD_CTRL(NO_PAD_CTRL) |
391 MUX_MODE_SION,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100392#define RGB_BACKLIGHTPWM_GP IMX_GPIO_NR(2, 9)
393};
394
395static iomux_v3_cfg_t const rgb_pads[] = {
396 MX6_PAD_DI0_DISP_CLK__IPU1_DI0_DISP_CLK | MUX_PAD_CTRL(OUTPUT_RGB),
397 MX6_PAD_DI0_PIN15__IPU1_DI0_PIN15 | MUX_PAD_CTRL(OUTPUT_RGB),
398 MX6_PAD_DI0_PIN2__IPU1_DI0_PIN02 | MUX_PAD_CTRL(OUTPUT_RGB),
399 MX6_PAD_DI0_PIN3__IPU1_DI0_PIN03 | MUX_PAD_CTRL(OUTPUT_RGB),
400 MX6_PAD_DISP0_DAT0__IPU1_DISP0_DATA00 | MUX_PAD_CTRL(OUTPUT_RGB),
401 MX6_PAD_DISP0_DAT1__IPU1_DISP0_DATA01 | MUX_PAD_CTRL(OUTPUT_RGB),
402 MX6_PAD_DISP0_DAT2__IPU1_DISP0_DATA02 | MUX_PAD_CTRL(OUTPUT_RGB),
403 MX6_PAD_DISP0_DAT3__IPU1_DISP0_DATA03 | MUX_PAD_CTRL(OUTPUT_RGB),
404 MX6_PAD_DISP0_DAT4__IPU1_DISP0_DATA04 | MUX_PAD_CTRL(OUTPUT_RGB),
405 MX6_PAD_DISP0_DAT5__IPU1_DISP0_DATA05 | MUX_PAD_CTRL(OUTPUT_RGB),
406 MX6_PAD_DISP0_DAT6__IPU1_DISP0_DATA06 | MUX_PAD_CTRL(OUTPUT_RGB),
407 MX6_PAD_DISP0_DAT7__IPU1_DISP0_DATA07 | MUX_PAD_CTRL(OUTPUT_RGB),
408 MX6_PAD_DISP0_DAT8__IPU1_DISP0_DATA08 | MUX_PAD_CTRL(OUTPUT_RGB),
409 MX6_PAD_DISP0_DAT9__IPU1_DISP0_DATA09 | MUX_PAD_CTRL(OUTPUT_RGB),
410 MX6_PAD_DISP0_DAT10__IPU1_DISP0_DATA10 | MUX_PAD_CTRL(OUTPUT_RGB),
411 MX6_PAD_DISP0_DAT11__IPU1_DISP0_DATA11 | MUX_PAD_CTRL(OUTPUT_RGB),
412 MX6_PAD_DISP0_DAT12__IPU1_DISP0_DATA12 | MUX_PAD_CTRL(OUTPUT_RGB),
413 MX6_PAD_DISP0_DAT13__IPU1_DISP0_DATA13 | MUX_PAD_CTRL(OUTPUT_RGB),
414 MX6_PAD_DISP0_DAT14__IPU1_DISP0_DATA14 | MUX_PAD_CTRL(OUTPUT_RGB),
415 MX6_PAD_DISP0_DAT15__IPU1_DISP0_DATA15 | MUX_PAD_CTRL(OUTPUT_RGB),
416 MX6_PAD_DISP0_DAT16__IPU1_DISP0_DATA16 | MUX_PAD_CTRL(OUTPUT_RGB),
417 MX6_PAD_DISP0_DAT17__IPU1_DISP0_DATA17 | MUX_PAD_CTRL(OUTPUT_RGB),
418};
419
420static void do_enable_hdmi(struct display_info_t const *dev)
421{
422 imx_enable_hdmi_phy();
423}
424
425static void enable_rgb(struct display_info_t const *dev)
426{
427 imx_iomux_v3_setup_multiple_pads(
428 rgb_pads,
429 ARRAY_SIZE(rgb_pads));
430 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
431 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0);
432}
433
434static int detect_default(struct display_info_t const *dev)
435{
436 (void) dev;
437 return 1;
438}
439
440struct display_info_t const displays[] = {{
441 .bus = -1,
442 .addr = 0,
443 .pixfmt = IPU_PIX_FMT_RGB24,
444 .detect = detect_hdmi,
445 .enable = do_enable_hdmi,
446 .mode = {
447 .name = "HDMI",
448 .refresh = 60,
449 .xres = 1024,
450 .yres = 768,
451 .pixclock = 15385,
452 .left_margin = 220,
453 .right_margin = 40,
454 .upper_margin = 21,
455 .lower_margin = 7,
456 .hsync_len = 60,
457 .vsync_len = 10,
458 .sync = FB_SYNC_EXT,
459 .vmode = FB_VMODE_NONINTERLACED
460} }, {
461 .bus = -1,
462 .addr = 0,
463 .pixfmt = IPU_PIX_FMT_RGB666,
464 .detect = detect_default,
465 .enable = enable_rgb,
466 .mode = {
467 .name = "vga-rgb",
468 .refresh = 60,
469 .xres = 640,
470 .yres = 480,
471 .pixclock = 33000,
472 .left_margin = 48,
473 .right_margin = 16,
474 .upper_margin = 31,
475 .lower_margin = 11,
476 .hsync_len = 96,
477 .vsync_len = 2,
478 .sync = 0,
479 .vmode = FB_VMODE_NONINTERLACED
480} }, {
481 .bus = -1,
482 .addr = 0,
483 .pixfmt = IPU_PIX_FMT_RGB666,
484 .enable = enable_rgb,
485 .mode = {
486 .name = "wvga-rgb",
487 .refresh = 60,
488 .xres = 800,
489 .yres = 480,
490 .pixclock = 25000,
491 .left_margin = 40,
492 .right_margin = 88,
493 .upper_margin = 33,
494 .lower_margin = 10,
495 .hsync_len = 128,
496 .vsync_len = 2,
497 .sync = 0,
498 .vmode = FB_VMODE_NONINTERLACED
499} } };
500size_t display_count = ARRAY_SIZE(displays);
501
502static void setup_display(void)
503{
504 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
505 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
506 int reg;
507
508 enable_ipu_clock();
509 imx_setup_hdmi();
510 /* Turn on LDB0,IPU,IPU DI0 clocks */
511 reg = __raw_readl(&mxc_ccm->CCGR3);
512 reg |= MXC_CCM_CCGR3_LDB_DI0_MASK;
513 writel(reg, &mxc_ccm->CCGR3);
514
515 /* set LDB0, LDB1 clk select to 011/011 */
516 reg = readl(&mxc_ccm->cs2cdr);
517 reg &= ~(MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_MASK
518 |MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_MASK);
519 reg |= (3<<MXC_CCM_CS2CDR_LDB_DI0_CLK_SEL_OFFSET)
520 |(3<<MXC_CCM_CS2CDR_LDB_DI1_CLK_SEL_OFFSET);
521 writel(reg, &mxc_ccm->cs2cdr);
522
523 reg = readl(&mxc_ccm->cscmr2);
524 reg |= MXC_CCM_CSCMR2_LDB_DI0_IPU_DIV;
525 writel(reg, &mxc_ccm->cscmr2);
526
527 reg = readl(&mxc_ccm->chsccdr);
528 reg |= (CHSCCDR_CLK_SEL_LDB_DI0
529 <<MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
530 writel(reg, &mxc_ccm->chsccdr);
531
532 reg = IOMUXC_GPR2_BGREF_RRMODE_EXTERNAL_RES
533 |IOMUXC_GPR2_DI1_VS_POLARITY_ACTIVE_HIGH
534 |IOMUXC_GPR2_DI0_VS_POLARITY_ACTIVE_LOW
535 |IOMUXC_GPR2_BIT_MAPPING_CH1_SPWG
536 |IOMUXC_GPR2_DATA_WIDTH_CH1_18BIT
537 |IOMUXC_GPR2_BIT_MAPPING_CH0_SPWG
538 |IOMUXC_GPR2_DATA_WIDTH_CH0_18BIT
539 |IOMUXC_GPR2_LVDS_CH1_MODE_DISABLED
540 |IOMUXC_GPR2_LVDS_CH0_MODE_ENABLED_DI0;
541 writel(reg, &iomux->gpr[2]);
542
543 reg = readl(&iomux->gpr[3]);
544 reg = (reg & ~(IOMUXC_GPR3_LVDS0_MUX_CTL_MASK
545 |IOMUXC_GPR3_HDMI_MUX_CTL_MASK))
546 | (IOMUXC_GPR3_MUX_SRC_IPU1_DI0
547 <<IOMUXC_GPR3_LVDS0_MUX_CTL_OFFSET);
548 writel(reg, &iomux->gpr[3]);
549
550 /* backlight unconditionally on for now */
551 imx_iomux_v3_setup_multiple_pads(backlight_pads,
552 ARRAY_SIZE(backlight_pads));
553 /* use 0 for EDT 7", use 1 for LG fullHD panel */
Marcel Ziswiler3e43a502019-02-08 18:42:10 +0100554 gpio_request(RGB_BACKLIGHTPWM_GP, "PWM<A>");
555 gpio_request(RGB_BACKLIGHT_GP, "BL_ON");
Max Krummenachereeb16b22016-11-30 19:43:09 +0100556 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 0);
557 gpio_direction_output(RGB_BACKLIGHT_GP, 1);
558}
Gerard Salvatella108d7392018-11-19 15:54:10 +0100559
560/*
561 * Backlight off before OS handover
562 */
563void board_preboot_os(void)
564{
565 gpio_direction_output(RGB_BACKLIGHTPWM_GP, 1);
566 gpio_direction_output(RGB_BACKLIGHT_GP, 0);
567}
Max Krummenachereeb16b22016-11-30 19:43:09 +0100568#endif /* defined(CONFIG_VIDEO_IPUV3) */
569
570int board_early_init_f(void)
571{
572 imx_iomux_v3_setup_multiple_pads(pwr_intb_pads,
573 ARRAY_SIZE(pwr_intb_pads));
574 setup_iomux_uart();
575
Max Krummenachereeb16b22016-11-30 19:43:09 +0100576 return 0;
577}
578
579/*
580 * Do not overwrite the console
581 * Use always serial for U-Boot console
582 */
583int overwrite_console(void)
584{
585 return 1;
586}
587
588int board_init(void)
589{
590 /* address of boot parameters */
591 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
Igor Opaniuk03e68cd2019-11-04 11:12:00 +0100592#if defined(CONFIG_FEC_MXC)
593 setup_fec();
594#endif
Fabio Estevamfd2525a2017-09-22 23:45:33 -0300595#if defined(CONFIG_VIDEO_IPUV3)
596 setup_display();
597#endif
598
Max Krummenachereeb16b22016-11-30 19:43:09 +0100599#ifdef CONFIG_TDX_CMD_IMX_MFGR
600 (void) pmic_init();
601#endif
602
Simon Glassab3055a2017-06-14 21:28:25 -0600603#ifdef CONFIG_SATA
Max Krummenachereeb16b22016-11-30 19:43:09 +0100604 setup_sata();
605#endif
606
607 setup_iomux_gpio();
608
609 return 0;
610}
611
612#ifdef CONFIG_BOARD_LATE_INIT
613int board_late_init(void)
614{
Tom Rini4cc38852021-08-30 09:16:30 -0400615#if defined(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100616 char env_str[256];
617 u32 rev;
618
Tom Rini4cc38852021-08-30 09:16:30 -0400619 rev = get_board_revision();
Max Krummenachereeb16b22016-11-30 19:43:09 +0100620 snprintf(env_str, ARRAY_SIZE(env_str), "%.4x", rev);
Simon Glass6a38e412017-08-03 12:22:09 -0600621 env_set("board_rev", env_str);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100622#endif
623
Hiago De Francoc3615822023-11-09 13:24:01 -0300624 if (IS_ENABLED(CONFIG_USB) && is_boot_from_usb()) {
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100625 env_set("bootdelay", "0");
Hiago De Francoc3615822023-11-09 13:24:01 -0300626 if (IS_ENABLED(CONFIG_CMD_USB_SDP)) {
627 printf("Serial Downloader recovery mode, using sdp command\n");
628 env_set("bootcmd", "sdp 0");
629 } else if (IS_ENABLED(CONFIG_CMD_FASTBOOT)) {
630 printf("Fastboot recovery mode, using fastboot command\n");
631 env_set("bootcmd", "fastboot usb 0");
632 }
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100633 }
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100634
Max Krummenachereeb16b22016-11-30 19:43:09 +0100635 return 0;
636}
637#endif /* CONFIG_BOARD_LATE_INIT */
638
Max Krummenachereeb16b22016-11-30 19:43:09 +0100639int checkboard(void)
640{
641 char it[] = " IT";
642 int minc, maxc;
643
644 switch (get_cpu_temp_grade(&minc, &maxc)) {
645 case TEMP_AUTOMOTIVE:
646 case TEMP_INDUSTRIAL:
647 break;
648 case TEMP_EXTCOMMERCIAL:
649 default:
650 it[0] = 0;
651 };
652 printf("Model: Toradex Colibri iMX6 %s %sMB%s\n",
653 is_cpu_type(MXC_CPU_MX6DL) ? "DualLite" : "Solo",
654 (gd->ram_size == 0x20000000) ? "512" : "256", it);
Simon Glassd44a1102023-11-12 19:58:25 -0700655
656 return tdx_checkboard();
Max Krummenachereeb16b22016-11-30 19:43:09 +0100657}
658
659#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900660int ft_board_setup(void *blob, struct bd_info *bd)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100661{
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +0100662 u32 cma_size;
663
664 ft_common_board_setup(blob, bd);
665
Stefan Agnerea8e2e92019-02-08 18:42:26 +0100666 cma_size = env_get_ulong("cma-size", 10, 320 * 1024 * 1024);
Bhuvanchandra DVcd6072c2019-02-08 18:42:24 +0100667 cma_size = min((u32)(gd->ram_size >> 1), cma_size);
668
669 fdt_setprop_u32(blob,
670 fdt_path_offset(blob, "/reserved-memory/linux,cma"),
671 "size",
672 cma_size);
673 return 0;
Max Krummenachereeb16b22016-11-30 19:43:09 +0100674}
675#endif
676
677#ifdef CONFIG_CMD_BMODE
678static const struct boot_mode board_boot_modes[] = {
679 {"mmc", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
680 {NULL, 0},
681};
682#endif
683
684int misc_init_r(void)
685{
686#ifdef CONFIG_CMD_BMODE
687 add_board_boot_modes(board_boot_modes);
688#endif
689 return 0;
690}
691
692#ifdef CONFIG_LDO_BYPASS_CHECK
693/* TODO, use external pmic, for now always ldo_enable */
694void ldo_mode_set(int ldo_bypass)
695{
696 return;
697}
698#endif
699
700#ifdef CONFIG_SPL_BUILD
701#include <spl.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +0900702#include <linux/libfdt.h>
Max Krummenachereeb16b22016-11-30 19:43:09 +0100703#include "asm/arch/mx6dl-ddr.h"
704#include "asm/arch/iomux.h"
705#include "asm/arch/crm_regs.h"
706
707static int mx6s_dcd_table[] = {
708/* ddr-setup.cfg */
709
710MX6_IOM_DRAM_SDQS0, 0x00000030,
711MX6_IOM_DRAM_SDQS1, 0x00000030,
712MX6_IOM_DRAM_SDQS2, 0x00000030,
713MX6_IOM_DRAM_SDQS3, 0x00000030,
714MX6_IOM_DRAM_SDQS4, 0x00000030,
715MX6_IOM_DRAM_SDQS5, 0x00000030,
716MX6_IOM_DRAM_SDQS6, 0x00000030,
717MX6_IOM_DRAM_SDQS7, 0x00000030,
718
719MX6_IOM_GRP_B0DS, 0x00000030,
720MX6_IOM_GRP_B1DS, 0x00000030,
721MX6_IOM_GRP_B2DS, 0x00000030,
722MX6_IOM_GRP_B3DS, 0x00000030,
723MX6_IOM_GRP_B4DS, 0x00000030,
724MX6_IOM_GRP_B5DS, 0x00000030,
725MX6_IOM_GRP_B6DS, 0x00000030,
726MX6_IOM_GRP_B7DS, 0x00000030,
727MX6_IOM_GRP_ADDDS, 0x00000030,
728/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
729MX6_IOM_GRP_CTLDS, 0x00000030,
730
731MX6_IOM_DRAM_DQM0, 0x00020030,
732MX6_IOM_DRAM_DQM1, 0x00020030,
733MX6_IOM_DRAM_DQM2, 0x00020030,
734MX6_IOM_DRAM_DQM3, 0x00020030,
735MX6_IOM_DRAM_DQM4, 0x00020030,
736MX6_IOM_DRAM_DQM5, 0x00020030,
737MX6_IOM_DRAM_DQM6, 0x00020030,
738MX6_IOM_DRAM_DQM7, 0x00020030,
739
740MX6_IOM_DRAM_CAS, 0x00020030,
741MX6_IOM_DRAM_RAS, 0x00020030,
742MX6_IOM_DRAM_SDCLK_0, 0x00020030,
743MX6_IOM_DRAM_SDCLK_1, 0x00020030,
744
745MX6_IOM_DRAM_RESET, 0x00020030,
746MX6_IOM_DRAM_SDCKE0, 0x00003000,
747MX6_IOM_DRAM_SDCKE1, 0x00003000,
748
749MX6_IOM_DRAM_SDODT0, 0x00003030,
750MX6_IOM_DRAM_SDODT1, 0x00003030,
751
752/* (differential input) */
753MX6_IOM_DDRMODE_CTL, 0x00020000,
754/* (differential input) */
755MX6_IOM_GRP_DDRMODE, 0x00020000,
756/* disable ddr pullups */
757MX6_IOM_GRP_DDRPKE, 0x00000000,
758MX6_IOM_DRAM_SDBA2, 0x00000000,
759/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
760MX6_IOM_GRP_DDR_TYPE, 0x000C0000,
761
762/* Read data DQ Byte0-3 delay */
763MX6_MMDC_P0_MPRDDQBY0DL, 0x33333333,
764MX6_MMDC_P0_MPRDDQBY1DL, 0x33333333,
765MX6_MMDC_P0_MPRDDQBY2DL, 0x33333333,
766MX6_MMDC_P0_MPRDDQBY3DL, 0x33333333,
767MX6_MMDC_P1_MPRDDQBY0DL, 0x33333333,
768MX6_MMDC_P1_MPRDDQBY1DL, 0x33333333,
769MX6_MMDC_P1_MPRDDQBY2DL, 0x33333333,
770MX6_MMDC_P1_MPRDDQBY3DL, 0x33333333,
771
772/*
773 * MDMISC mirroring interleaved (row/bank/col)
774 */
Stefan Eichenbergera817bcb2023-06-14 11:01:37 +0200775MX6_MMDC_P0_MDMISC, 0x000b17c0,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100776
777/*
778 * MDSCR con_req
779 */
780MX6_MMDC_P0_MDSCR, 0x00008000,
781
782
783/* 800mhz_2x64mx16.cfg */
784
785MX6_MMDC_P0_MDPDC, 0x0002002D,
786MX6_MMDC_P0_MDCFG0, 0x2C305503,
787MX6_MMDC_P0_MDCFG1, 0xB66D8D63,
788MX6_MMDC_P0_MDCFG2, 0x01FF00DB,
789MX6_MMDC_P0_MDRWD, 0x000026D2,
790MX6_MMDC_P0_MDOR, 0x00301023,
791MX6_MMDC_P0_MDOTC, 0x00333030,
792MX6_MMDC_P0_MDPDC, 0x0002556D,
793/* CS0 End: 7MSB of ((0x10000000, + 512M) -1) >> 25 */
794MX6_MMDC_P0_MDASP, 0x00000017,
795/* DDR3 DATA BUS SIZE: 64BIT */
796/* MX6_MMDC_P0_MDCTL, 0x821A0000, */
797/* DDR3 DATA BUS SIZE: 32BIT */
798MX6_MMDC_P0_MDCTL, 0x82190000,
799
800/* Write commands to DDR */
801/* Load Mode Registers */
802/* TODO Use Auto Self-Refresh mode (Extended Temperature)*/
803/* MX6_MMDC_P0_MDSCR, 0x04408032, */
804MX6_MMDC_P0_MDSCR, 0x04008032,
805MX6_MMDC_P0_MDSCR, 0x00008033,
806MX6_MMDC_P0_MDSCR, 0x00048031,
807MX6_MMDC_P0_MDSCR, 0x13208030,
808/* ZQ calibration */
809MX6_MMDC_P0_MDSCR, 0x04008040,
810
811MX6_MMDC_P0_MPZQHWCTRL, 0xA1390003,
812MX6_MMDC_P1_MPZQHWCTRL, 0xA1390003,
813MX6_MMDC_P0_MDREF, 0x00005800,
814
815MX6_MMDC_P0_MPODTCTRL, 0x00000000,
816MX6_MMDC_P1_MPODTCTRL, 0x00000000,
817
818MX6_MMDC_P0_MPDGCTRL0, 0x42360232,
819MX6_MMDC_P0_MPDGCTRL1, 0x021F022A,
820MX6_MMDC_P1_MPDGCTRL0, 0x421E0224,
821MX6_MMDC_P1_MPDGCTRL1, 0x02110218,
822
823MX6_MMDC_P0_MPRDDLCTL, 0x41434344,
824MX6_MMDC_P1_MPRDDLCTL, 0x4345423E,
825MX6_MMDC_P0_MPWRDLCTL, 0x39383339,
826MX6_MMDC_P1_MPWRDLCTL, 0x3E363930,
827
828MX6_MMDC_P0_MPWLDECTRL0, 0x00340039,
829MX6_MMDC_P0_MPWLDECTRL1, 0x002C002D,
830MX6_MMDC_P1_MPWLDECTRL0, 0x00120019,
831MX6_MMDC_P1_MPWLDECTRL1, 0x0012002D,
832
833MX6_MMDC_P0_MPMUR0, 0x00000800,
834MX6_MMDC_P1_MPMUR0, 0x00000800,
835MX6_MMDC_P0_MDSCR, 0x00000000,
836MX6_MMDC_P0_MAPSR, 0x00011006,
837};
838
839static int mx6dl_dcd_table[] = {
840/* ddr-setup.cfg */
841
842MX6_IOM_DRAM_SDQS0, 0x00000030,
843MX6_IOM_DRAM_SDQS1, 0x00000030,
844MX6_IOM_DRAM_SDQS2, 0x00000030,
845MX6_IOM_DRAM_SDQS3, 0x00000030,
846MX6_IOM_DRAM_SDQS4, 0x00000030,
847MX6_IOM_DRAM_SDQS5, 0x00000030,
848MX6_IOM_DRAM_SDQS6, 0x00000030,
849MX6_IOM_DRAM_SDQS7, 0x00000030,
850
851MX6_IOM_GRP_B0DS, 0x00000030,
852MX6_IOM_GRP_B1DS, 0x00000030,
853MX6_IOM_GRP_B2DS, 0x00000030,
854MX6_IOM_GRP_B3DS, 0x00000030,
855MX6_IOM_GRP_B4DS, 0x00000030,
856MX6_IOM_GRP_B5DS, 0x00000030,
857MX6_IOM_GRP_B6DS, 0x00000030,
858MX6_IOM_GRP_B7DS, 0x00000030,
859MX6_IOM_GRP_ADDDS, 0x00000030,
860/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
861MX6_IOM_GRP_CTLDS, 0x00000030,
862
863MX6_IOM_DRAM_DQM0, 0x00020030,
864MX6_IOM_DRAM_DQM1, 0x00020030,
865MX6_IOM_DRAM_DQM2, 0x00020030,
866MX6_IOM_DRAM_DQM3, 0x00020030,
867MX6_IOM_DRAM_DQM4, 0x00020030,
868MX6_IOM_DRAM_DQM5, 0x00020030,
869MX6_IOM_DRAM_DQM6, 0x00020030,
870MX6_IOM_DRAM_DQM7, 0x00020030,
871
872MX6_IOM_DRAM_CAS, 0x00020030,
873MX6_IOM_DRAM_RAS, 0x00020030,
874MX6_IOM_DRAM_SDCLK_0, 0x00020030,
875MX6_IOM_DRAM_SDCLK_1, 0x00020030,
876
877MX6_IOM_DRAM_RESET, 0x00020030,
878MX6_IOM_DRAM_SDCKE0, 0x00003000,
879MX6_IOM_DRAM_SDCKE1, 0x00003000,
880
881MX6_IOM_DRAM_SDODT0, 0x00003030,
882MX6_IOM_DRAM_SDODT1, 0x00003030,
883
884/* (differential input) */
885MX6_IOM_DDRMODE_CTL, 0x00020000,
886/* (differential input) */
887MX6_IOM_GRP_DDRMODE, 0x00020000,
888/* disable ddr pullups */
889MX6_IOM_GRP_DDRPKE, 0x00000000,
890MX6_IOM_DRAM_SDBA2, 0x00000000,
891/* 40 Ohm drive strength for cs0/1,sdba2,cke0/1,sdwe */
892MX6_IOM_GRP_DDR_TYPE, 0x000C0000,
893
894/* Read data DQ Byte0-3 delay */
895MX6_MMDC_P0_MPRDDQBY0DL, 0x33333333,
896MX6_MMDC_P0_MPRDDQBY1DL, 0x33333333,
897MX6_MMDC_P0_MPRDDQBY2DL, 0x33333333,
898MX6_MMDC_P0_MPRDDQBY3DL, 0x33333333,
899MX6_MMDC_P1_MPRDDQBY0DL, 0x33333333,
900MX6_MMDC_P1_MPRDDQBY1DL, 0x33333333,
901MX6_MMDC_P1_MPRDDQBY2DL, 0x33333333,
902MX6_MMDC_P1_MPRDDQBY3DL, 0x33333333,
903
904/*
905 * MDMISC mirroring interleaved (row/bank/col)
906 */
Stefan Eichenbergera817bcb2023-06-14 11:01:37 +0200907MX6_MMDC_P0_MDMISC, 0x000b17c0,
Max Krummenachereeb16b22016-11-30 19:43:09 +0100908
909/*
910 * MDSCR con_req
911 */
912MX6_MMDC_P0_MDSCR, 0x00008000,
913
914
915/* 800mhz_2x64mx16.cfg */
916
917MX6_MMDC_P0_MDPDC, 0x0002002D,
918MX6_MMDC_P0_MDCFG0, 0x2C305503,
919MX6_MMDC_P0_MDCFG1, 0xB66D8D63,
920MX6_MMDC_P0_MDCFG2, 0x01FF00DB,
921MX6_MMDC_P0_MDRWD, 0x000026D2,
922MX6_MMDC_P0_MDOR, 0x00301023,
923MX6_MMDC_P0_MDOTC, 0x00333030,
924MX6_MMDC_P0_MDPDC, 0x0002556D,
925/* CS0 End: 7MSB of ((0x10000000, + 512M) -1) >> 25 */
926MX6_MMDC_P0_MDASP, 0x00000017,
927/* DDR3 DATA BUS SIZE: 64BIT */
928MX6_MMDC_P0_MDCTL, 0x821A0000,
929/* DDR3 DATA BUS SIZE: 32BIT */
930/* MX6_MMDC_P0_MDCTL, 0x82190000, */
931
932/* Write commands to DDR */
933/* Load Mode Registers */
934/* TODO Use Auto Self-Refresh mode (Extended Temperature)*/
935/* MX6_MMDC_P0_MDSCR, 0x04408032, */
936MX6_MMDC_P0_MDSCR, 0x04008032,
937MX6_MMDC_P0_MDSCR, 0x00008033,
938MX6_MMDC_P0_MDSCR, 0x00048031,
939MX6_MMDC_P0_MDSCR, 0x13208030,
940/* ZQ calibration */
941MX6_MMDC_P0_MDSCR, 0x04008040,
942
943MX6_MMDC_P0_MPZQHWCTRL, 0xA1390003,
944MX6_MMDC_P1_MPZQHWCTRL, 0xA1390003,
945MX6_MMDC_P0_MDREF, 0x00005800,
946
947MX6_MMDC_P0_MPODTCTRL, 0x00000000,
948MX6_MMDC_P1_MPODTCTRL, 0x00000000,
949
950MX6_MMDC_P0_MPDGCTRL0, 0x42360232,
951MX6_MMDC_P0_MPDGCTRL1, 0x021F022A,
952MX6_MMDC_P1_MPDGCTRL0, 0x421E0224,
953MX6_MMDC_P1_MPDGCTRL1, 0x02110218,
954
955MX6_MMDC_P0_MPRDDLCTL, 0x41434344,
956MX6_MMDC_P1_MPRDDLCTL, 0x4345423E,
957MX6_MMDC_P0_MPWRDLCTL, 0x39383339,
958MX6_MMDC_P1_MPWRDLCTL, 0x3E363930,
959
960MX6_MMDC_P0_MPWLDECTRL0, 0x00340039,
961MX6_MMDC_P0_MPWLDECTRL1, 0x002C002D,
962MX6_MMDC_P1_MPWLDECTRL0, 0x00120019,
963MX6_MMDC_P1_MPWLDECTRL1, 0x0012002D,
964
965MX6_MMDC_P0_MPMUR0, 0x00000800,
966MX6_MMDC_P1_MPMUR0, 0x00000800,
967MX6_MMDC_P0_MDSCR, 0x00000000,
968MX6_MMDC_P0_MAPSR, 0x00011006,
969};
970
971static void ccgr_init(void)
972{
973 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
974
975 writel(0x00C03F3F, &ccm->CCGR0);
976 writel(0x0030FC03, &ccm->CCGR1);
977 writel(0x0FFFFFF3, &ccm->CCGR2);
978 writel(0x3FF0300F, &ccm->CCGR3);
979 writel(0x00FFF300, &ccm->CCGR4);
980 writel(0x0F0000F3, &ccm->CCGR5);
981 writel(0x000003FF, &ccm->CCGR6);
982
983/*
984 * Setup CCM_CCOSR register as follows:
985 *
Francesco Dolcini1fb07132022-06-24 11:52:19 +0200986 * clko2_en = 1 --> CKO2 enabled
987 * clko2_div = 000 --> divide by 1
988 * clko2_sel = 01110 --> osc_clk (24MHz)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100989 *
Francesco Dolcini1fb07132022-06-24 11:52:19 +0200990 * clk_out_sel = 1 --> Output CKO2 to CKO1
991 *
992 * This sets both CLKO2/CLKO1 output to 24MHz,
993 * CLKO1 configuration not relevant because of clk_out_sel
994 * (CLKO1 set to default)
Max Krummenachereeb16b22016-11-30 19:43:09 +0100995 */
Francesco Dolcini1fb07132022-06-24 11:52:19 +0200996 writel(0x010E0101, &ccm->ccosr);
Max Krummenachereeb16b22016-11-30 19:43:09 +0100997}
998
Max Krummenachereeb16b22016-11-30 19:43:09 +0100999static void ddr_init(int *table, int size)
1000{
1001 int i;
1002
1003 for (i = 0; i < size / 2 ; i++)
1004 writel(table[2 * i + 1], table[2 * i]);
1005}
1006
Francesco Dolcinie1e30b22021-08-31 11:46:05 +02001007/* Perform DDR DRAM calibration */
1008static void spl_dram_perform_cal(u8 dsize)
1009{
1010#ifdef CONFIG_MX6_DDRCAL
1011 int err;
1012 struct mx6_ddr_sysinfo ddr_sysinfo = {
1013 .dsize = dsize,
1014 };
1015
1016 err = mmdc_do_write_level_calibration(&ddr_sysinfo);
1017 if (err)
1018 printf("error %d from write level calibration\n", err);
1019 err = mmdc_do_dqs_calibration(&ddr_sysinfo);
1020 if (err)
1021 printf("error %d from dqs calibration\n", err);
1022#endif
1023}
1024
Max Krummenachereeb16b22016-11-30 19:43:09 +01001025static void spl_dram_init(void)
1026{
1027 int minc, maxc;
Francesco Dolcinie1e30b22021-08-31 11:46:05 +02001028 u8 dsize = 2;
Max Krummenachereeb16b22016-11-30 19:43:09 +01001029
1030 switch (get_cpu_temp_grade(&minc, &maxc)) {
1031 case TEMP_COMMERCIAL:
1032 case TEMP_EXTCOMMERCIAL:
1033 if (is_cpu_type(MXC_CPU_MX6DL)) {
1034 puts("Commercial temperature grade DDR3 timings, 64bit bus width.\n");
1035 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
1036 } else {
1037 puts("Commercial temperature grade DDR3 timings, 32bit bus width.\n");
Francesco Dolcinie1e30b22021-08-31 11:46:05 +02001038 dsize = 1;
Max Krummenachereeb16b22016-11-30 19:43:09 +01001039 ddr_init(mx6s_dcd_table, ARRAY_SIZE(mx6s_dcd_table));
1040 }
1041 break;
1042 case TEMP_INDUSTRIAL:
1043 case TEMP_AUTOMOTIVE:
1044 default:
1045 if (is_cpu_type(MXC_CPU_MX6DL)) {
Max Krummenacherc1ce7cb2019-02-08 18:42:17 +01001046 puts("Industrial temperature grade DDR3 timings, 64bit bus width.\n");
Max Krummenachereeb16b22016-11-30 19:43:09 +01001047 ddr_init(mx6dl_dcd_table, ARRAY_SIZE(mx6dl_dcd_table));
1048 } else {
1049 puts("Industrial temperature grade DDR3 timings, 32bit bus width.\n");
Francesco Dolcinie1e30b22021-08-31 11:46:05 +02001050 dsize = 1;
Max Krummenachereeb16b22016-11-30 19:43:09 +01001051 ddr_init(mx6s_dcd_table, ARRAY_SIZE(mx6s_dcd_table));
1052 }
1053 break;
1054 };
1055 udelay(100);
Francesco Dolcinie1e30b22021-08-31 11:46:05 +02001056 spl_dram_perform_cal(dsize);
Max Krummenachereeb16b22016-11-30 19:43:09 +01001057}
1058
Gerard Salvatella7fba5092019-02-08 18:42:28 +01001059static iomux_v3_cfg_t const gpio_reset_pad[] = {
1060 MX6_PAD_RGMII_RD1__GPIO6_IO27 | MUX_PAD_CTRL(NO_PAD_CTRL) |
1061 MUX_MODE_SION
1062#define GPIO_NRESET IMX_GPIO_NR(6, 27)
1063};
1064
1065#define IMX_RESET_CAUSE_POR 0x00011
1066static void nreset_out(void)
1067{
1068 int reset_cause = get_imx_reset_cause();
1069
1070 if (reset_cause != IMX_RESET_CAUSE_POR) {
1071 imx_iomux_v3_setup_multiple_pads(gpio_reset_pad,
1072 ARRAY_SIZE(gpio_reset_pad));
1073 gpio_direction_output(GPIO_NRESET, 1);
1074 udelay(100);
1075 gpio_direction_output(GPIO_NRESET, 0);
1076 }
1077}
1078
Max Krummenachereeb16b22016-11-30 19:43:09 +01001079void board_init_f(ulong dummy)
1080{
1081 /* setup AIPS and disable watchdog */
1082 arch_cpu_init();
1083
1084 ccgr_init();
1085 gpr_init();
1086
Marcel Ziswilerc882cfb2019-02-08 18:42:12 +01001087 /* iomux */
Max Krummenachereeb16b22016-11-30 19:43:09 +01001088 board_early_init_f();
1089
1090 /* setup GP timer */
1091 timer_init();
1092
1093 /* UART clocks enabled and gd valid - init serial console */
1094 preloader_console_init();
1095
1096 /* Make sure we use dte mode */
1097 setup_dtemode_uart();
1098
1099 /* DDR initialization */
1100 spl_dram_init();
1101
1102 /* Clear the BSS. */
1103 memset(__bss_start, 0, __bss_end - __bss_start);
1104
Gerard Salvatella7fba5092019-02-08 18:42:28 +01001105 /* Assert nReset_Out */
1106 nreset_out();
1107
Max Krummenachereeb16b22016-11-30 19:43:09 +01001108 /* load/boot image from boot device */
1109 board_init_r(NULL, 0);
1110}
1111
Ming Liuc5c904c2021-07-23 09:39:48 +03001112#ifdef CONFIG_SPL_LOAD_FIT
1113int board_fit_config_name_match(const char *name)
1114{
1115 if (!strcmp(name, "imx6-colibri"))
1116 return 0;
1117
1118 return -1;
1119}
1120#endif
1121
Harald Seiler6f14d5f2020-12-15 16:47:52 +01001122void reset_cpu(void)
Max Krummenachereeb16b22016-11-30 19:43:09 +01001123{
1124}
1125
Marcel Ziswiler3e43a502019-02-08 18:42:10 +01001126#endif /* CONFIG_SPL_BUILD */
Max Krummenachereeb16b22016-11-30 19:43:09 +01001127
Simon Glassb75b15b2020-12-03 16:55:23 -07001128static struct mxc_serial_plat mxc_serial_plat = {
Max Krummenachereeb16b22016-11-30 19:43:09 +01001129 .reg = (struct mxc_uart *)UART1_BASE,
1130 .use_dte = true,
1131};
1132
Simon Glass1d8364a2020-12-28 20:34:54 -07001133U_BOOT_DRVINFO(mxc_serial) = {
Max Krummenachereeb16b22016-11-30 19:43:09 +01001134 .name = "serial_mxc",
Simon Glass71fa5b42020-12-03 16:55:18 -07001135 .plat = &mxc_serial_plat,
Max Krummenachereeb16b22016-11-30 19:43:09 +01001136};