blob: 7c49b206c1526d99d860b2a6252defebc3aa8c6c [file] [log] [blame]
Philip Oberfichtner9d680d12022-05-19 13:52:48 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2017 DENX Software Engineering GmbH, Heiko Schocher <hs@denx.de>
4 * Copyright (c) 2019 Bosch Thermotechnik GmbH
5 * Copyright (c) 2022 DENX Software Engineering GmbH, Philip Oberfichtner <pro@denx.de>
6 */
7
8#include <common.h>
Tom Rinie3b32642023-03-09 11:22:07 -05009#include <cpu_func.h>
Philip Oberfichtner9d680d12022-05-19 13:52:48 +020010#include <bootstage.h>
11#include <dm.h>
12#include <dm/platform_data/serial_mxc.h>
13#include <dm/device-internal.h>
14#include <env.h>
Philip Oberfichtner9d680d12022-05-19 13:52:48 +020015#include <hang.h>
16#include <init.h>
17#include <linux/delay.h>
18#include <mmc.h>
19
20#include <asm/io.h>
21#include <asm/gpio.h>
22#include <linux/sizes.h>
23
24#include <asm/arch/clock.h>
25#include <asm/arch/crm_regs.h>
26#include <asm/arch/iomux.h>
27#include <asm/arch/mx6-pins.h>
28#include <asm/arch/sys_proto.h>
29#include <asm/mach-imx/iomux-v3.h>
30#include <usb.h>
31#include <usb/ehci-ci.h>
32#include <fuse.h>
33
34#include <watchdog.h>
35
36DECLARE_GLOBAL_DATA_PTR;
37
38#define GPIO_ACC_PLAT_DETECT IMX_GPIO_NR(5, 9)
39#define GPIO_ACC_RAM_VOLT_DETECT IMX_GPIO_NR(5, 0)
40#define GPIO_BUZZER IMX_GPIO_NR(1, 18)
41#define GPIO_LAN1_RESET IMX_GPIO_NR(4, 27)
42#define GPIO_LAN2_RESET IMX_GPIO_NR(4, 19)
43#define GPIO_LAN3_RESET IMX_GPIO_NR(4, 18)
44#define GPIO_USB_HUB_RESET IMX_GPIO_NR(5, 5)
45#define GPIO_EXP_RS485_RESET IMX_GPIO_NR(4, 16)
46#define GPIO_TOUCH_RESET IMX_GPIO_NR(1, 20)
47
48#define BOARD_INFO_MAGIC 0x19730517
49
50struct board_info {
51 int magic;
52 int board;
53 int rev;
54};
55
56static struct board_info *detect_board(void);
57
58#define PFID_BOARD_ACC 0xe
59
60static const char * const name_board[] = {
61 [PFID_BOARD_ACC] = "ACC",
62};
63
64#define PFID_REV_22 0x8
65#define PFID_REV_21 0x9
66#define PFID_REV_20 0xa
67#define PFID_REV_14 0xb
68#define PFID_REV_13 0xc
69#define PFID_REV_12 0xd
70#define PFID_REV_11 0xe
71#define PFID_REV_10 0xf
72
73static const char * const name_revision[] = {
74 [0 ... PFID_REV_10] = "Unknown",
75 [PFID_REV_10] = "1.0",
76 [PFID_REV_11] = "1.1",
77 [PFID_REV_12] = "1.2",
78 [PFID_REV_13] = "1.3",
79 [PFID_REV_14] = "1.4",
80 [PFID_REV_20] = "2.0",
81 [PFID_REV_21] = "2.1",
82 [PFID_REV_22] = "2.2",
83};
84
85/*
86 * NXP Reset Default: 0x0001B0B0
87 * - Schmitt trigger input (PAD_CTL_HYS)
88 * - 100K Ohm Pull Up (PAD_CTL_PUS_100K_UP)
89 * - Pull Enabled (PAD_CTL_PUE)
90 * - Pull/Keeper Enabled (PAD_CTL_PKE)
91 * - CMOS output (No PAD_CTL_ODE)
92 * - Medium Speed (PAD_CTL_SPEED_MED)
93 * - 40 Ohm drive strength (PAD_CTL_DSE_40ohm)
94 * - Slow (PAD_CTL_SRE_SLOW)
95 */
96
97/* Input, no pull up/down: 0x0x000100B0 */
98#define GPIN_PAD_CTRL (PAD_CTL_HYS \
99 | PAD_CTL_SPEED_MED \
100 | PAD_CTL_DSE_40ohm \
101 | PAD_CTL_SRE_SLOW)
102
103/* Input, pull up: 0x0x0001B0B0 */
104#define GPIN_PU_PAD_CTRL (PAD_CTL_HYS \
105 | PAD_CTL_PUS_100K_UP \
106 | PAD_CTL_PUE \
107 | PAD_CTL_PKE \
108 | PAD_CTL_SPEED_MED \
109 | PAD_CTL_DSE_40ohm \
110 | PAD_CTL_SRE_SLOW)
111
112/* Input, pull down: 0x0x000130B0 */
113#define GPIN_PD_PAD_CTRL (PAD_CTL_HYS \
114 | PAD_CTL_PUS_100K_DOWN \
115 | PAD_CTL_PUE \
116 | PAD_CTL_PKE \
117 | PAD_CTL_SPEED_MED \
118 | PAD_CTL_DSE_40ohm \
119 | PAD_CTL_SRE_SLOW)
120
121static const iomux_v3_cfg_t board_detect_pads[] = {
122 /* Platform detect */
123 IOMUX_PADS(PAD_DISP0_DAT15__GPIO5_IO09 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
124 /* RAM Volt detect */
125 IOMUX_PADS(PAD_EIM_WAIT__GPIO5_IO00 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
126 /* PFID 0..9 */
127 IOMUX_PADS(PAD_NANDF_D0__GPIO2_IO00 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
128 IOMUX_PADS(PAD_NANDF_D1__GPIO2_IO01 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
129 IOMUX_PADS(PAD_NANDF_D2__GPIO2_IO02 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
130 IOMUX_PADS(PAD_NANDF_D3__GPIO2_IO03 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
131 IOMUX_PADS(PAD_NANDF_D4__GPIO2_IO04 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
132 IOMUX_PADS(PAD_NANDF_D5__GPIO2_IO05 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
133 IOMUX_PADS(PAD_NANDF_D6__GPIO2_IO06 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
134 IOMUX_PADS(PAD_NANDF_D7__GPIO2_IO07 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
135 IOMUX_PADS(PAD_NANDF_CS3__GPIO6_IO16 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
136 IOMUX_PADS(PAD_NANDF_CS1__GPIO6_IO14 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
137 /* Manufacturer */
138 IOMUX_PADS(PAD_EIM_A24__GPIO5_IO04 | MUX_PAD_CTRL(GPIN_PAD_CTRL)),
139 /* Redundant */
140 IOMUX_PADS(PAD_NANDF_CS2__GPIO6_IO15 | MUX_PAD_CTRL(GPIN_PU_PAD_CTRL))
141};
142
143static int gpio_acc_pfid[] = {
144 IMX_GPIO_NR(2, 0),
145 IMX_GPIO_NR(2, 1),
146 IMX_GPIO_NR(2, 2),
147 IMX_GPIO_NR(2, 3),
148 IMX_GPIO_NR(2, 4),
149 IMX_GPIO_NR(6, 14),
150 IMX_GPIO_NR(6, 15),
151 IMX_GPIO_NR(2, 5),
152 IMX_GPIO_NR(2, 6),
153 IMX_GPIO_NR(2, 7),
154 IMX_GPIO_NR(6, 16),
155 IMX_GPIO_NR(5, 4),
156};
157
158static int init_gpio(int nr)
159{
160 int ret;
161
162 ret = gpio_request(nr, "");
163 if (ret != 0) {
164 printf("Could not request gpio nr: %d\n", nr);
165 hang();
166 }
167 ret = gpio_direction_input(nr);
168 if (ret != 0) {
169 printf("Could not set gpio nr: %d to input\n", nr);
170 hang();
171 }
172 return 0;
173}
174
175/*
176 * We want to detect the board type only once in SPL,
177 * so we store the board_info struct at beginning in IRAM.
178 *
179 * U-Boot itself can read it also, and do not need again
180 * to detect board type.
181 *
182 */
183static struct board_info *detect_board(void)
184{
185 struct board_info *binfo = (struct board_info *)IRAM_BASE_ADDR;
186 int i;
187
188 if (binfo->magic == BOARD_INFO_MAGIC)
189 return binfo;
190
191 puts("Board: ");
192 SETUP_IOMUX_PADS(board_detect_pads);
193 init_gpio(GPIO_ACC_PLAT_DETECT);
194 if (gpio_get_value(GPIO_ACC_PLAT_DETECT)) {
195 puts("not supported");
196 hang();
197 } else {
198 puts("Bosch ");
199 }
200
201 for (i = 0; i < sizeof(gpio_acc_pfid) / sizeof(int); i++)
202 init_gpio(gpio_acc_pfid[i]);
203
204 binfo->board = gpio_get_value(gpio_acc_pfid[0]) << 0 |
205 gpio_get_value(gpio_acc_pfid[1]) << 1 |
206 gpio_get_value(gpio_acc_pfid[2]) << 2 |
207 gpio_get_value(gpio_acc_pfid[11]) << 3;
208 printf("%s ", name_board[binfo->board]);
209
210 binfo->rev = gpio_get_value(gpio_acc_pfid[7]) << 0 |
211 gpio_get_value(gpio_acc_pfid[8]) << 1 |
212 gpio_get_value(gpio_acc_pfid[9]) << 2 |
213 gpio_get_value(gpio_acc_pfid[10]) << 3;
214 printf("rev: %s\n", name_revision[binfo->rev]);
215
216 binfo->magic = BOARD_INFO_MAGIC;
217
218 return binfo;
219}
220
221static void unset_early_gpio(void)
222{
223 init_gpio(GPIO_LAN1_RESET);
224 init_gpio(GPIO_LAN2_RESET);
225 init_gpio(GPIO_LAN3_RESET);
226 init_gpio(GPIO_USB_HUB_RESET);
227 init_gpio(GPIO_EXP_RS485_RESET);
228 init_gpio(GPIO_TOUCH_RESET);
229
230 gpio_set_value(GPIO_LAN1_RESET, 1);
231 gpio_set_value(GPIO_LAN2_RESET, 1);
232 gpio_set_value(GPIO_LAN3_RESET, 1);
233 gpio_set_value(GPIO_USB_HUB_RESET, 1);
234 gpio_set_value(GPIO_EXP_RS485_RESET, 1);
235 gpio_set_value(GPIO_TOUCH_RESET, 1);
236}
237
Philip Oberfichtner9d680d12022-05-19 13:52:48 +0200238int board_late_init(void)
239{
240 struct board_info *binfo = detect_board();
241
242 switch (binfo->board) {
243 case PFID_BOARD_ACC:
244 env_set("bootconf", "conf-imx6q-bosch-acc.dtb");
245 break;
246 default:
247 printf("Unknown board %d\n", binfo->board);
248 break;
249 }
250
251 unset_early_gpio();
252
253 return 0;
254}
255
256int board_init(void)
257{
258 /* Address of boot parameters */
259 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
260
261 return 0;
262}
263
264int dram_init(void)
265{
266 gd->ram_size = imx_ddr_size();
267
268 return 0;
269}
270
271#if IS_ENABLED(CONFIG_SPL_BUILD)
272#include <asm/arch/crm_regs.h>
273#include <asm/arch/imx-regs.h>
274#include <asm/arch/iomux.h>
275#include <asm/arch/mx6-ddr.h>
276#include <asm/arch/mx6-pins.h>
277#include <asm/arch/sys_proto.h>
278#include <spl.h>
279
280/* Early
281 * - Buzzer -> GPIO IN, Pull-Down (PWM enabled by Kernel later-on, lacks of an
282 * external pull-down resistor)
283 * - Touch clean reset on every boot
284 * - Ethernet(s), USB Hub, Expansion RS485 -> Clean reset on each u-boot init
285 */
286static const iomux_v3_cfg_t early_pads[] = {
287 IOMUX_PADS(PAD_SD1_CMD__GPIO1_IO18 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* Buzzer PWM */
288 IOMUX_PADS(PAD_DISP0_DAT6__GPIO4_IO27 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #FEC_RESET_B */
289 IOMUX_PADS(PAD_DI0_PIN2__GPIO4_IO18 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #ETH1_RESET */
290 IOMUX_PADS(PAD_DI0_PIN3__GPIO4_IO19 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #ETH2_RESET */
291 IOMUX_PADS(PAD_DISP0_DAT11__GPIO5_IO05 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #USB Reset */
292 IOMUX_PADS(PAD_DI0_DISP_CLK__GPIO4_IO16 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #UART_RESET */
293 IOMUX_PADS(PAD_SD1_CLK__GPIO1_IO20 | MUX_PAD_CTRL(GPIN_PD_PAD_CTRL)), /* #CTOUCH_RESET */
294};
295
296static void setup_iomux_early(void)
297{
298 SETUP_IOMUX_PADS(early_pads);
299}
300
301static void set_early_gpio(void)
302{
303 init_gpio(GPIO_BUZZER);
304 init_gpio(GPIO_LAN1_RESET);
305 init_gpio(GPIO_LAN2_RESET);
306 init_gpio(GPIO_LAN3_RESET);
307 init_gpio(GPIO_USB_HUB_RESET);
308 init_gpio(GPIO_EXP_RS485_RESET);
309 init_gpio(GPIO_TOUCH_RESET);
310
311 /* Reset signals are active low */
312 gpio_set_value(GPIO_BUZZER, 0);
313 gpio_set_value(GPIO_LAN1_RESET, 0);
314 gpio_set_value(GPIO_LAN2_RESET, 0);
315 gpio_set_value(GPIO_LAN3_RESET, 0);
316 gpio_set_value(GPIO_USB_HUB_RESET, 0);
317 gpio_set_value(GPIO_EXP_RS485_RESET, 0);
318 gpio_set_value(GPIO_TOUCH_RESET, 0);
319}
320
321/* UART */
322#define UART_PAD_CTRL \
323 (PAD_CTL_PUS_100K_UP | PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
324 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
325
326#undef UART_PAD_CTRL
327#define UART_PAD_CTRL 0x1b0b1
328static const iomux_v3_cfg_t uart2_pads[] = {
329 IOMUX_PADS(PAD_SD3_DAT4__UART2_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
330 IOMUX_PADS(PAD_SD3_DAT5__UART2_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
331 IOMUX_PADS(PAD_SD3_CMD__UART2_CTS_B | MUX_PAD_CTRL(UART_PAD_CTRL)),
332 IOMUX_PADS(PAD_SD3_CLK__UART2_RTS_B | MUX_PAD_CTRL(UART_PAD_CTRL)),
333};
334
335static void setup_iomux_uart(void)
336{
337 SETUP_IOMUX_PADS(uart2_pads);
338}
339
340void spl_board_init(void)
341{
342}
343
344static const struct mx6dq_iomux_ddr_regs acc_mx6d_ddr_ioregs = {
345 .dram_sdclk_0 = 0x00008038,
346 .dram_sdclk_1 = 0x00008038,
347 .dram_cas = 0x00008028,
348 .dram_ras = 0x00008028,
349 .dram_reset = 0x00000028,
350 .dram_sdcke0 = 0x00003000,
351 .dram_sdcke1 = 0x00003000,
352 .dram_sdba2 = 0x00008000,
353 .dram_sdodt0 = 0x00000028,
354 .dram_sdodt1 = 0x00000028,
355 .dram_sdqs0 = 0x00008038,
356 .dram_sdqs1 = 0x00008038,
357 .dram_sdqs2 = 0x00008038,
358 .dram_sdqs3 = 0x00008038,
359 .dram_sdqs4 = 0x00008038,
360 .dram_sdqs5 = 0x00008038,
361 .dram_sdqs6 = 0x00008038,
362 .dram_sdqs7 = 0x00008038,
363 .dram_dqm0 = 0x00008038,
364 .dram_dqm1 = 0x00008038,
365 .dram_dqm2 = 0x00008038,
366 .dram_dqm3 = 0x00008038,
367 .dram_dqm4 = 0x00008038,
368 .dram_dqm5 = 0x00008038,
369 .dram_dqm6 = 0x00008038,
370 .dram_dqm7 = 0x00008038,
371};
372
373static const struct mx6dq_iomux_grp_regs acc_mx6d_grp_ioregs = {
374 .grp_ddr_type = 0x000C0000,
375 .grp_ddrmode_ctl = 0x00020000,
376 .grp_ddrpke = 0x00000000,
377 .grp_addds = 0x00000030,
378 .grp_ctlds = 0x00000028,
379 .grp_ddrmode = 0x00020000,
380 .grp_b0ds = 0x00000038,
381 .grp_b1ds = 0x00000038,
382 .grp_b2ds = 0x00000038,
383 .grp_b3ds = 0x00000038,
384 .grp_b4ds = 0x00000038,
385 .grp_b5ds = 0x00000038,
386 .grp_b6ds = 0x00000038,
387 .grp_b7ds = 0x00000038,
388};
389
390static const struct mx6_mmdc_calibration acc_mx6d_mmdc_calib = {
391 .p0_mpwldectrl0 = 0x0020001F,
392 .p0_mpwldectrl1 = 0x00280021,
393 .p1_mpwldectrl0 = 0x00120028,
394 .p1_mpwldectrl1 = 0x000D001F,
395 .p0_mpdgctrl0 = 0x43340342,
396 .p0_mpdgctrl1 = 0x03300325,
397 .p1_mpdgctrl0 = 0x4334033E,
398 .p1_mpdgctrl1 = 0x03280270,
399 .p0_mprddlctl = 0x46373B3E,
400 .p1_mprddlctl = 0x3B383544,
401 .p0_mpwrdlctl = 0x36383E40,
402 .p1_mpwrdlctl = 0x4030433A,
403};
404
405/* Micron MT41K128M16JT-125 (standard - 1600,CL=11)
406 * !!! i.MX6 does NOT support data rates higher than DDR3-1066 !!!
407 * So this setting is actually invalid!
408 *
409static const struct mx6_ddr3_cfg acc_mx6d_mem_ddr3_1600 = {
410 .mem_speed = 1600,
411 .density = 2,
412 .width = 16,
413 .banks = 8,
414 .rowaddr = 14,
415 .coladdr = 10,
416 .pagesz = 2,
417 .trcd = 1375,
418 .trcmin = 4875,
419 .trasmin = 3500,
420 .SRT = 0,
421};
422 */
423
424/* Micron MT41K128M16JT-125 is backward-compatible with 1333,CL=9 (-15E) and 1066,CL=7 (-187E)
425 * Lowering to 1066 saves on ACC ~0.25 Watt at DC In with negligible performance loss
426 * width set to 64, as four chips are used on acc (4 * 16 = 64)
427 */
428static const struct mx6_ddr3_cfg acc_mx6d_mem_ddr3_1066 = {
429 .mem_speed = 1066,
430 .density = 2,
431 .width = 64,
432 .banks = 8,
433 .rowaddr = 14,
434 .coladdr = 10,
435 .pagesz = 2,
436 .trcd = 1313, // 13.125ns
437 .trcmin = 5063, // 50.625ns
438 .trasmin = 3750, // 37.5ns
439 .SRT = 0, // Set to 1 for temperatures above 85°C
440};
441
442static const struct mx6_ddr_sysinfo acc_mx6d_ddr_info = {
443 .ddr_type = DDR_TYPE_DDR3,
444 /* width of data bus:0=16,1=32,2=64 */
445 .dsize = 2,
446 .cs_density = 32, /* 32Gb per CS */
447 .ncs = 1, /* single chip select */
448 .cs1_mirror = 0,
449 .rtt_wr = 1, /* DDR3_RTT_60_OHM, RTT_Wr = RZQ/4 */
450 .rtt_nom = 1, /* DDR3_RTT_60_OHM, RTT_Nom = RZQ/4 */
451 .walat = 0, /* Write additional latency */
452 .ralat = 5, /* Read additional latency */
453 .mif3_mode = 3, /* Command prediction working mode */
454 .bi_on = 1, /* Bank interleaving enabled */
455 .sde_to_rst = 0x33, /* 14 cycles, 200us (JEDEC default) */
456 .rst_to_cke = 0x33, /* 33 cycles, 500us (JEDEC default) */
457};
458
459#define ACC_SPREAD_SPECTRUM_STOP 0x0fa
460#define ACC_SPREAD_SPECTRUM_STEP 0x001
461#define ACC_SPREAD_SPECTRUM_DENOM 0x190
462
463static void ccgr_init(void)
464{
465 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
466
467 /* Turn clocks on/off */
468 writel(0x00C0000F, &ccm->CCGR0);
469 writel(0x0030FC00, &ccm->CCGR1);
470 writel(0x03FF0033, &ccm->CCGR2);
471 writel(0x3FF3300F, &ccm->CCGR3);
472 writel(0x0003C300, &ccm->CCGR4);
473 writel(0x0F3000C3, &ccm->CCGR5);
474 writel(0x00000FFF, &ccm->CCGR6);
475
476 /* Enable spread spectrum */
477 writel(BM_ANADIG_PLL_528_SS_ENABLE |
478 BF_ANADIG_PLL_528_SS_STOP(ACC_SPREAD_SPECTRUM_STOP) |
479 BF_ANADIG_PLL_528_SS_STEP(ACC_SPREAD_SPECTRUM_STEP),
480 &ccm->analog_pll_528_ss);
481
482 writel(BF_ANADIG_PLL_528_DENOM_B(ACC_SPREAD_SPECTRUM_DENOM),
483 &ccm->analog_pll_528_denom);
484}
485
486/* MMC board initialization is needed till adding DM support in SPL */
487#if IS_ENABLED(CONFIG_FSL_ESDHC_IMX) && !IS_ENABLED(CONFIG_DM_MMC)
488#include <mmc.h>
489#include <fsl_esdhc_imx.h>
490
491static const iomux_v3_cfg_t usdhc2_pads[] = {
492 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(0x00017069)),
493 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(0x00010038)),
494 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(0x00017069)),
495 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(0x00017069)),
496 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(0x00017069)),
497 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(0x00017069)),
498 IOMUX_PADS(PAD_GPIO_4__GPIO1_IO04 | MUX_PAD_CTRL(0x0001B0B0)), /* CD */
499};
500
501static const iomux_v3_cfg_t usdhc4_pads[] = {
502 IOMUX_PADS(PAD_SD4_CMD__SD4_CMD | MUX_PAD_CTRL(0x00017059)),
503 IOMUX_PADS(PAD_SD4_CLK__SD4_CLK | MUX_PAD_CTRL(0x00010059)),
504 IOMUX_PADS(PAD_SD4_DAT0__SD4_DATA0 | MUX_PAD_CTRL(0x00017059)),
505 IOMUX_PADS(PAD_SD4_DAT1__SD4_DATA1 | MUX_PAD_CTRL(0x00017059)),
506 IOMUX_PADS(PAD_SD4_DAT2__SD4_DATA2 | MUX_PAD_CTRL(0x00017059)),
507 IOMUX_PADS(PAD_SD4_DAT3__SD4_DATA3 | MUX_PAD_CTRL(0x00017059)),
508 IOMUX_PADS(PAD_SD4_DAT4__SD4_DATA4 | MUX_PAD_CTRL(0x00017059)),
509 IOMUX_PADS(PAD_SD4_DAT5__SD4_DATA5 | MUX_PAD_CTRL(0x00017059)),
510 IOMUX_PADS(PAD_SD4_DAT6__SD4_DATA6 | MUX_PAD_CTRL(0x00017059)),
511 IOMUX_PADS(PAD_SD4_DAT7__SD4_DATA7 | MUX_PAD_CTRL(0x00017059)),
512};
513
514struct fsl_esdhc_cfg usdhc_cfg[2] = {
515 {USDHC2_BASE_ADDR, 1, 4},
516 {USDHC4_BASE_ADDR, 1, 8},
517};
518
519#define USDHC2_CD_GPIO IMX_GPIO_NR(1, 4)
520
521int board_mmc_getcd(struct mmc *mmc)
522{
523 struct fsl_esdhc_cfg *cfg = (struct fsl_esdhc_cfg *)mmc->priv;
524 int ret = 0;
525
526 detect_board();
527
528 switch (cfg->esdhc_base) {
529 case USDHC2_BASE_ADDR:
530 return !gpio_get_value(USDHC2_CD_GPIO);
531 case USDHC4_BASE_ADDR:
532 return 1; /* eMMC always present */
533 }
534
535 return ret;
536}
537
538int board_mmc_init(struct bd_info *bis)
539{
540 int i, ret;
541
542 gpio_direction_input(USDHC2_CD_GPIO);
543 /*
544 * According to the board_mmc_init() the following map is done:
Michal Simek50fa1182023-05-17 09:17:16 +0200545 * (U-Boot device node) (Physical Port)
Philip Oberfichtner9d680d12022-05-19 13:52:48 +0200546 * mmc0 USDHC2
547 * mmc1 USDHC4
548 */
Tom Rini376b88a2022-10-28 20:27:13 -0400549 for (i = 0; i < CFG_SYS_FSL_USDHC_NUM; i++) {
Philip Oberfichtner9d680d12022-05-19 13:52:48 +0200550 switch (i) {
551 case 0:
552 SETUP_IOMUX_PADS(usdhc2_pads);
553 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
554 break;
555 case 1:
556 SETUP_IOMUX_PADS(usdhc4_pads);
557 usdhc_cfg[i].sdhc_clk = mxc_get_clock(MXC_ESDHC4_CLK);
558 break;
559 default:
560 printf("Warning - USDHC%d controller not supporting\n",
561 i + 1);
562 return 0;
563 }
564
565 ret = fsl_esdhc_initialize(bis, &usdhc_cfg[i]);
566 if (ret) {
567 printf("Warning: failed to initialize mmc dev %d\n", i);
568 return ret;
569 }
570 }
571
572 return 0;
573}
574#endif
575
576void board_boot_order(u32 *spl_boot_list)
577{
578 u32 bmode = imx6_src_get_boot_mode();
579 u8 boot_dev = BOOT_DEVICE_MMC1;
580
581 detect_board();
582
583 switch ((bmode & IMX6_BMODE_MASK) >> IMX6_BMODE_SHIFT) {
584 case IMX6_BMODE_SD:
585 case IMX6_BMODE_ESD:
586 /* SD/eSD - BOOT_DEVICE_MMC1 */
587 if (IS_ENABLED(CONFIG_SYS_BOOT_EMMC)) {
588 /*
589 * boot from SD is not allowed, if boot from eMMC is
590 * configured.
591 */
592 puts("SD boot not allowed\n");
593 spl_boot_list[0] = BOOT_DEVICE_NONE;
594 return;
595 }
596
597 boot_dev = BOOT_DEVICE_MMC1;
598 break;
599
600 case IMX6_BMODE_MMC:
601 case IMX6_BMODE_EMMC:
602 /* MMC/eMMC */
603 boot_dev = BOOT_DEVICE_MMC2;
604 break;
605 default:
606 /* Default - BOOT_DEVICE_MMC1 */
607 printf("Wrong board boot order\n");
608 break;
609 }
610
611 spl_boot_list[0] = boot_dev;
612}
613
614static void setup_ddr(void)
615{
616 struct board_info *binfo = detect_board();
617
618 switch (binfo->rev) {
619 case PFID_REV_20:
620 case PFID_REV_21:
621 case PFID_REV_22:
622 default:
623 /* Rev 2 board has i.MX6 Dual with 64-bit RAM */
624 mx6dq_dram_iocfg(acc_mx6d_mem_ddr3_1066.width,
625 &acc_mx6d_ddr_ioregs,
626 &acc_mx6d_grp_ioregs);
627 mx6_dram_cfg(&acc_mx6d_ddr_info, &acc_mx6d_mmdc_calib,
628 &acc_mx6d_mem_ddr3_1066);
629 /* Perform DDR DRAM calibration */
630 udelay(100);
631 mmdc_do_write_level_calibration(&acc_mx6d_ddr_info);
632 mmdc_do_dqs_calibration(&acc_mx6d_ddr_info);
633 break;
634 }
635}
636
637void board_init_f(ulong dummy)
638{
639 /* setup AIPS and disable watchdog power-down counter (only enabled after reset) */
640 arch_cpu_init();
641
642 ccgr_init();
643 gpr_init();
644
645 /* setup GP timer */
646 timer_init();
647
648 /* Enable device tree and early DM support*/
649 spl_early_init();
650
651 /* Setup early required pinmuxes */
652 setup_iomux_early();
653 set_early_gpio();
654
655 /* Setup UART pinmux */
656 setup_iomux_uart();
657
658 /* UART clocks enabled and gd valid - init serial console */
659 preloader_console_init();
660
661 setup_ddr();
662
663 /* Clear the BSS. */
664 memset(__bss_start, 0, __bss_end - __bss_start);
665
666 /* load/boot image from boot device */
667 board_init_r(NULL, 0);
668}
669#endif
670
671#if IS_ENABLED(CONFIG_USB_EHCI_MX6)
672#define USB_OTHERREGS_OFFSET 0x800
673#define UCTRL_PWR_POL BIT(9)
674
675int board_usb_phy_mode(int port)
676{
677 if (port == 1)
678 return USB_INIT_HOST;
679 else
680 return usb_phy_mode(port);
681}
682
683int board_ehci_hcd_init(int port)
684{
685 u32 *usbnc_usb_ctrl;
686
687 if (port > 1)
688 return -EINVAL;
689
690 usbnc_usb_ctrl = (u32 *)(USB_BASE_ADDR + USB_OTHERREGS_OFFSET +
691 port * 4);
692
693 /* Set Power polarity */
694 setbits_le32(usbnc_usb_ctrl, UCTRL_PWR_POL);
695
696 return 0;
697}
698#endif
699
700int board_fit_config_name_match(const char *name)
701{
702 if (!strcmp(name, "imx6q-bosch-acc"))
703 return 0;
704 return -1;
705}
706
Tom Rinie3b32642023-03-09 11:22:07 -0500707void reset_cpu(void)
Philip Oberfichtner9d680d12022-05-19 13:52:48 +0200708{
709 puts("Hanging CPU for watchdog reset!\n");
710 hang();
711}
712
713#if CONFIG_IS_ENABLED(SHOW_BOOT_PROGRESS)
714void show_boot_progress(int val)
715{
716 u32 fuseval;
717 int ret;
718
719 if (val < 0)
720 val *= -1;
721
722 switch (val) {
723 case BOOTSTAGE_ID_ENTER_CLI_LOOP:
724 printf("autoboot failed, check fuse\n");
725 ret = fuse_read(0, 6, &fuseval);
726 if (ret == 0 && (fuseval & 0x2) == 0x0) {
727 printf("Enter cmdline, as device not closed\n");
728 return;
729 }
730 ret = fuse_read(5, 7, &fuseval);
731 if (ret == 0 && fuseval == 0x0) {
732 printf("Enter cmdline, as it is a Development device\n");
733 return;
734 }
735 panic("do not enter cmdline");
736 break;
737 }
738}
739#endif