blob: 00e63659f4a4f0f176bb96d062d03aafae5044af [file] [log] [blame]
Frieder Schrempf199dfd92021-09-29 16:42:42 +02001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019 Kontron Electronics GmbH
4 */
5
6#include <asm/arch/imx8mm_pins.h>
7#include <asm/arch/clock.h>
8#include <asm/arch/ddr.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/sys_proto.h>
11#include <asm/global_data.h>
12#include <asm/gpio.h>
13#include <asm/mach-imx/boot_mode.h>
14#include <asm/mach-imx/iomux-v3.h>
15#include <dm/uclass.h>
Fabio Estevam75aad882022-06-09 17:13:31 -030016#include <dm/device.h>
17#include <dm/uclass-internal.h>
18#include <dm/device-internal.h>
Frieder Schrempf199dfd92021-09-29 16:42:42 +020019#include <hang.h>
20#include <i2c.h>
21#include <init.h>
22#include <linux/errno.h>
23#include <linux/delay.h>
24#include <power/pca9450.h>
25#include <power/pmic.h>
26#include <spl.h>
27
28DECLARE_GLOBAL_DATA_PTR;
29
30enum {
31 BOARD_TYPE_KTN_N801X,
Frieder Schrempf199dfd92021-09-29 16:42:42 +020032 BOARD_TYPE_MAX
33};
34
Frieder Schrempf199dfd92021-09-29 16:42:42 +020035#define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE)
Frieder Schrempf199dfd92021-09-29 16:42:42 +020036
Frieder Schrempf199dfd92021-09-29 16:42:42 +020037static iomux_v3_cfg_t const i2c1_pads[] = {
38 IMX8MM_PAD_I2C1_SCL_I2C1_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL) | MUX_MODE_SION,
39 IMX8MM_PAD_I2C1_SDA_I2C1_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL) | MUX_MODE_SION
40};
41
42static iomux_v3_cfg_t const i2c2_pads[] = {
43 IMX8MM_PAD_I2C2_SCL_I2C2_SCL | MUX_PAD_CTRL(I2C_PAD_CTRL) | MUX_MODE_SION,
44 IMX8MM_PAD_I2C2_SDA_I2C2_SDA | MUX_PAD_CTRL(I2C_PAD_CTRL) | MUX_MODE_SION
45};
46
Frieder Schrempf199dfd92021-09-29 16:42:42 +020047int spl_board_boot_device(enum boot_device boot_dev_spl)
48{
49 switch (boot_dev_spl) {
50 case USB_BOOT:
51 return BOOT_DEVICE_BOARD;
52 case SPI_NOR_BOOT:
53 return BOOT_DEVICE_SPI;
54 case SD1_BOOT:
55 case MMC1_BOOT:
56 return BOOT_DEVICE_MMC1;
57 case SD2_BOOT:
58 case MMC2_BOOT:
59 return BOOT_DEVICE_MMC2;
60 default:
61 return BOOT_DEVICE_NONE;
62 }
63}
64
65bool check_ram_available(long size)
66{
67 long sz = get_ram_size((long *)PHYS_SDRAM, size);
68
69 if (sz == size)
70 return true;
71
72 return false;
73}
74
75static void spl_dram_init(void)
76{
77 u32 size = 0;
78
79 /*
80 * Try the default DDR settings in lpddr4_timing.c to
81 * comply with the Micron 4GB DDR.
82 */
83 if (!ddr_init(&dram_timing) && check_ram_available(SZ_4G)) {
84 size = 4;
85 } else {
86 /*
87 * Overwrite some values to comply with the Micron 1GB/2GB DDRs.
88 */
89 dram_timing.ddrc_cfg[2].val = 0xa1080020;
90 dram_timing.ddrc_cfg[37].val = 0x1f;
91
Frieder Schrempf6d6eced2022-08-24 15:59:13 +020092 dram_timing.fsp_msg[0].fsp_cfg[8].val = 0x110;
93 dram_timing.fsp_msg[0].fsp_cfg[20].val = 0x1;
94 dram_timing.fsp_msg[1].fsp_cfg[9].val = 0x110;
95 dram_timing.fsp_msg[1].fsp_cfg[21].val = 0x1;
Frieder Schrempf199dfd92021-09-29 16:42:42 +020096 dram_timing.fsp_msg[2].fsp_cfg[10].val = 0x110;
97 dram_timing.fsp_msg[2].fsp_cfg[22].val = 0x1;
Frieder Schrempf199dfd92021-09-29 16:42:42 +020098
99 if (!ddr_init(&dram_timing)) {
100 if (check_ram_available(SZ_2G))
101 size = 2;
102 else if (check_ram_available(SZ_1G))
103 size = 1;
104 }
105 }
106
107 if (size == 0) {
108 printf("Failed to initialize DDR RAM!\n");
109 size = 1;
110 }
111
112 printf("Kontron SL i.MX8MM (N801X) module, %u GB RAM detected\n", size);
113 writel(size, M4_BOOTROM_BASE_ADDR);
114}
115
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200116static int i2c_detect(u8 bus, u16 addr)
117{
118 struct udevice *udev;
119 int ret;
120
121 /*
122 * Try to probe the touch controller to check if an LVDS panel is
123 * connected.
124 */
125 ret = i2c_get_chip_for_busnum(bus, addr, 0, &udev);
126 if (ret == 0)
127 return 0;
128
129 return 1;
130}
131
132int do_board_detect(void)
133{
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200134 /*
135 * Check the I2C PMIC to detect the deprecated SoM with DA9063.
136 */
137 imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads));
138
139 if (i2c_detect(0, 0x58) == 0) {
140 printf("### ATTENTION: DEPRECATED SOM REVISION (N8010 Rev0) DETECTED! ###\n");
Frieder Schrempfa9f81852022-08-24 15:52:23 +0200141 printf("### THIS HW IS NOT SUPPORTED AND BOOTING WILL PROBABLY FAIL ###\n");
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200142 printf("### PLEASE UPGRADE TO LATEST MODULE ###\n");
143 }
144
Frieder Schrempfa9f81852022-08-24 15:52:23 +0200145 gd->board_type = BOARD_TYPE_KTN_N801X;
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200146
147 return 0;
148}
149
150int board_fit_config_name_match(const char *name)
151{
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200152 if (gd->board_type == BOARD_TYPE_KTN_N801X && is_imx8mm() &&
Frieder Schrempf5375c8a2022-08-24 15:59:15 +0200153 (!strcmp(name, "imx8mm-kontron-n801x-s") ||
154 !strcmp(name, "imx8mm-kontron-bl")))
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200155 return 0;
156
157 return -1;
158}
159
160void spl_board_init(void)
161{
162 struct udevice *dev;
163 int ret;
164
Fabio Estevam75aad882022-06-09 17:13:31 -0300165 if (IS_ENABLED(CONFIG_FSL_CAAM)) {
166 ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev);
167 if (ret)
168 printf("Failed to initialize %s: %d\n", dev->name, ret);
169 }
170
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200171 puts("Normal Boot\n");
172
173 ret = uclass_get_device_by_name(UCLASS_CLK,
174 "clock-controller@30380000",
175 &dev);
176 if (ret < 0)
177 printf("Failed to find clock node. Check device tree\n");
178}
179
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200180static int power_init_board(void)
181{
182 struct udevice *dev;
183 int ret = pmic_get("pmic@25", &dev);
184
185 if (ret == -ENODEV)
186 puts("No pmic found\n");
187
188 if (ret)
189 return ret;
190
191 /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */
192 pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29);
193
194 /* increase VDD_DRAM to 0.95V for 1.5GHz DDR */
195 pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c);
196
197 /* set VDD_SNVS_0V8 from default 0.85V to 0.8V */
198 pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0);
199
200 /* set WDOG_B_CFG to cold reset */
201 pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1);
202
203 return 0;
204}
205
206void board_init_f(ulong dummy)
207{
208 int ret;
209
210 arch_cpu_init();
211
212 init_uart_clk(2);
213
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200214 timer_init();
215
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200216 /* Clear the BSS. */
217 memset(__bss_start, 0, __bss_end - __bss_start);
218
219 ret = spl_init();
220 if (ret) {
221 debug("spl_init() failed: %d\n", ret);
222 hang();
223 }
224
Peng Fan8f525782022-06-11 20:21:00 +0800225 preloader_console_init();
226
Frieder Schrempf199dfd92021-09-29 16:42:42 +0200227 enable_tzc380();
228
229 /* PMIC initialization */
230 power_init_board();
231
232 /* DDR initialization */
233 spl_dram_init();
234
235 /* Detect the board type */
236 do_board_detect();
237
238 board_init_r(NULL, 0);
239}