Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 1 | // 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 Estevam | 75aad88 | 2022-06-09 17:13:31 -0300 | [diff] [blame] | 16 | #include <dm/device.h> |
| 17 | #include <dm/uclass-internal.h> |
| 18 | #include <dm/device-internal.h> |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 19 | #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 | |
| 28 | DECLARE_GLOBAL_DATA_PTR; |
| 29 | |
| 30 | enum { |
| 31 | BOARD_TYPE_KTN_N801X, |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 32 | BOARD_TYPE_MAX |
| 33 | }; |
| 34 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 35 | #define I2C_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_HYS | PAD_CTL_PUE) |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 36 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 37 | static 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 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 42 | int spl_board_boot_device(enum boot_device boot_dev_spl) |
| 43 | { |
| 44 | switch (boot_dev_spl) { |
| 45 | case USB_BOOT: |
| 46 | return BOOT_DEVICE_BOARD; |
| 47 | case SPI_NOR_BOOT: |
| 48 | return BOOT_DEVICE_SPI; |
| 49 | case SD1_BOOT: |
| 50 | case MMC1_BOOT: |
| 51 | return BOOT_DEVICE_MMC1; |
| 52 | case SD2_BOOT: |
| 53 | case MMC2_BOOT: |
| 54 | return BOOT_DEVICE_MMC2; |
| 55 | default: |
| 56 | return BOOT_DEVICE_NONE; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | bool check_ram_available(long size) |
| 61 | { |
| 62 | long sz = get_ram_size((long *)PHYS_SDRAM, size); |
| 63 | |
| 64 | if (sz == size) |
| 65 | return true; |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | static void spl_dram_init(void) |
| 71 | { |
| 72 | u32 size = 0; |
| 73 | |
| 74 | /* |
| 75 | * Try the default DDR settings in lpddr4_timing.c to |
| 76 | * comply with the Micron 4GB DDR. |
| 77 | */ |
| 78 | if (!ddr_init(&dram_timing) && check_ram_available(SZ_4G)) { |
| 79 | size = 4; |
| 80 | } else { |
| 81 | /* |
| 82 | * Overwrite some values to comply with the Micron 1GB/2GB DDRs. |
| 83 | */ |
| 84 | dram_timing.ddrc_cfg[2].val = 0xa1080020; |
| 85 | dram_timing.ddrc_cfg[37].val = 0x1f; |
| 86 | |
Frieder Schrempf | 6d6eced | 2022-08-24 15:59:13 +0200 | [diff] [blame] | 87 | dram_timing.fsp_msg[0].fsp_cfg[8].val = 0x110; |
| 88 | dram_timing.fsp_msg[0].fsp_cfg[20].val = 0x1; |
| 89 | dram_timing.fsp_msg[1].fsp_cfg[9].val = 0x110; |
| 90 | dram_timing.fsp_msg[1].fsp_cfg[21].val = 0x1; |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 91 | dram_timing.fsp_msg[2].fsp_cfg[10].val = 0x110; |
| 92 | dram_timing.fsp_msg[2].fsp_cfg[22].val = 0x1; |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 93 | |
| 94 | if (!ddr_init(&dram_timing)) { |
| 95 | if (check_ram_available(SZ_2G)) |
| 96 | size = 2; |
| 97 | else if (check_ram_available(SZ_1G)) |
| 98 | size = 1; |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | if (size == 0) { |
| 103 | printf("Failed to initialize DDR RAM!\n"); |
| 104 | size = 1; |
| 105 | } |
| 106 | |
Frieder Schrempf | b296c0e | 2022-08-24 15:59:18 +0200 | [diff] [blame^] | 107 | gd->ram_size = size; |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 108 | writel(size, M4_BOOTROM_BASE_ADDR); |
| 109 | } |
| 110 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 111 | int do_board_detect(void) |
| 112 | { |
Frieder Schrempf | b296c0e | 2022-08-24 15:59:18 +0200 | [diff] [blame^] | 113 | gd->board_type = BOARD_TYPE_KTN_N801X; |
| 114 | printf("Kontron SL i.MX8MM (N801X) module, %u GB RAM detected\n", |
| 115 | (unsigned int)gd->ram_size); |
| 116 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 117 | /* |
| 118 | * Check the I2C PMIC to detect the deprecated SoM with DA9063. |
| 119 | */ |
| 120 | imx_iomux_v3_setup_multiple_pads(i2c1_pads, ARRAY_SIZE(i2c1_pads)); |
| 121 | |
Frieder Schrempf | b296c0e | 2022-08-24 15:59:18 +0200 | [diff] [blame^] | 122 | if (i2c_get_chip_for_busnum(0, 0x58, 0, &udev) == 0) { |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 123 | printf("### ATTENTION: DEPRECATED SOM REVISION (N8010 Rev0) DETECTED! ###\n"); |
Frieder Schrempf | a9f8185 | 2022-08-24 15:52:23 +0200 | [diff] [blame] | 124 | printf("### THIS HW IS NOT SUPPORTED AND BOOTING WILL PROBABLY FAIL ###\n"); |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 125 | printf("### PLEASE UPGRADE TO LATEST MODULE ###\n"); |
| 126 | } |
| 127 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 128 | return 0; |
| 129 | } |
| 130 | |
| 131 | int board_fit_config_name_match(const char *name) |
| 132 | { |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 133 | if (gd->board_type == BOARD_TYPE_KTN_N801X && is_imx8mm() && |
Frieder Schrempf | 5375c8a | 2022-08-24 15:59:15 +0200 | [diff] [blame] | 134 | (!strcmp(name, "imx8mm-kontron-n801x-s") || |
| 135 | !strcmp(name, "imx8mm-kontron-bl"))) |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 136 | return 0; |
| 137 | |
| 138 | return -1; |
| 139 | } |
| 140 | |
| 141 | void spl_board_init(void) |
| 142 | { |
| 143 | struct udevice *dev; |
| 144 | int ret; |
| 145 | |
Fabio Estevam | 75aad88 | 2022-06-09 17:13:31 -0300 | [diff] [blame] | 146 | if (IS_ENABLED(CONFIG_FSL_CAAM)) { |
| 147 | ret = uclass_get_device_by_driver(UCLASS_MISC, DM_DRIVER_GET(caam_jr), &dev); |
| 148 | if (ret) |
| 149 | printf("Failed to initialize %s: %d\n", dev->name, ret); |
| 150 | } |
| 151 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 152 | puts("Normal Boot\n"); |
| 153 | |
| 154 | ret = uclass_get_device_by_name(UCLASS_CLK, |
| 155 | "clock-controller@30380000", |
| 156 | &dev); |
| 157 | if (ret < 0) |
| 158 | printf("Failed to find clock node. Check device tree\n"); |
| 159 | } |
| 160 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 161 | static int power_init_board(void) |
| 162 | { |
| 163 | struct udevice *dev; |
| 164 | int ret = pmic_get("pmic@25", &dev); |
| 165 | |
| 166 | if (ret == -ENODEV) |
| 167 | puts("No pmic found\n"); |
| 168 | |
| 169 | if (ret) |
| 170 | return ret; |
| 171 | |
| 172 | /* BUCKxOUT_DVS0/1 control BUCK123 output, clear PRESET_EN */ |
| 173 | pmic_reg_write(dev, PCA9450_BUCK123_DVS, 0x29); |
| 174 | |
| 175 | /* increase VDD_DRAM to 0.95V for 1.5GHz DDR */ |
| 176 | pmic_reg_write(dev, PCA9450_BUCK3OUT_DVS0, 0x1c); |
| 177 | |
| 178 | /* set VDD_SNVS_0V8 from default 0.85V to 0.8V */ |
| 179 | pmic_reg_write(dev, PCA9450_LDO2CTRL, 0xC0); |
| 180 | |
| 181 | /* set WDOG_B_CFG to cold reset */ |
| 182 | pmic_reg_write(dev, PCA9450_RESET_CTRL, 0xA1); |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | void board_init_f(ulong dummy) |
| 188 | { |
| 189 | int ret; |
| 190 | |
| 191 | arch_cpu_init(); |
| 192 | |
| 193 | init_uart_clk(2); |
| 194 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 195 | timer_init(); |
| 196 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 197 | /* Clear the BSS. */ |
| 198 | memset(__bss_start, 0, __bss_end - __bss_start); |
| 199 | |
| 200 | ret = spl_init(); |
| 201 | if (ret) { |
| 202 | debug("spl_init() failed: %d\n", ret); |
| 203 | hang(); |
| 204 | } |
| 205 | |
Peng Fan | 8f52578 | 2022-06-11 20:21:00 +0800 | [diff] [blame] | 206 | preloader_console_init(); |
| 207 | |
Frieder Schrempf | 199dfd9 | 2021-09-29 16:42:42 +0200 | [diff] [blame] | 208 | enable_tzc380(); |
| 209 | |
| 210 | /* PMIC initialization */ |
| 211 | power_init_board(); |
| 212 | |
| 213 | /* DDR initialization */ |
| 214 | spl_dram_init(); |
| 215 | |
| 216 | /* Detect the board type */ |
| 217 | do_board_detect(); |
| 218 | |
| 219 | board_init_r(NULL, 0); |
| 220 | } |